From 68325bdd5f07c2a3b4ef6bf59f48259075d1e3b3 Mon Sep 17 00:00:00 2001 From: NorbiPeti Date: Mon, 10 Aug 2015 00:28:15 +0200 Subject: [PATCH] Lot of admin commands, bug fixes, and custom flairs - Added many admin commands (see /u admin) - Probably fixed the flairs for some players - Added support for custom flairs, also used when deciding unknown flair types --- .metadata/.log | 47 ++ .metadata/.mylyn/.tasks.xml.zip | Bin 250 -> 250 bytes .metadata/.mylyn/tasks.xml.zip | Bin 250 -> 250 bytes .../0/3027b10cd93e001517108d149b613203 | 226 +++++++++ .../1/601f8274873e00151ce8ff6d4f74dabd | 144 ------ .../1/90ea77eee43e001517108d149b613203 | 425 +++++++++++++++++ .../1/a0191b15d23e001518fa86d7ae2a1cf8 | 374 +++++++++++++++ .../1/d071b8d5873e00151ce8ff6d4f74dabd | 152 ------ .../1/d0997b1b023e00151c31fb33fff4337f | 125 ----- .../1/f03cfc260d3e00151089cca86c5b1a99 | 434 ----------------- .../10/80fad266df3e001517108d149b613203 | 252 ++++++++++ .../10/d069a424873e00151ce8ff6d4f74dabd | 136 ------ .../11/e02f8f8d083e00151c31fb33fff4337f | 126 ----- .../12/10177772dd3e001517108d149b613203 | 409 ++++++++++++++++ .../12/900059d3e03e001517108d149b613203 | 264 +++++++++++ .../12/90d09f90df3e001517108d149b613203 | 421 +++++++++++++++++ .../12/b09714c2cf3e001518fa86d7ae2a1cf8 | 362 ++++++++++++++ .../13/903ca4bcde3e001517108d149b613203 | 436 +++++++++++++++++ .../14/20b7f4c2d23e001518fa86d7ae2a1cf8 | 215 +++++++++ .../15/a0689143d43e001518fa86d7ae2a1cf8 | 221 +++++++++ .../15/d05be66e043e00151c31fb33fff4337f | 126 ----- .../16/90523966df3e001517108d149b613203 | 252 ++++++++++ .../17/101a2f29df3e001517108d149b613203 | 251 ++++++++++ .../19/c0e42302ce3e001518fa86d7ae2a1cf8 | 354 ++++++++++++++ .../1a/101bc97ade3e001517108d149b613203 | 430 +++++++++++++++++ .../1a/308e38e1de3e001517108d149b613203 | 440 ++++++++++++++++++ .../1b/f0c4a095083e00151c31fb33fff4337f | 126 ----- .../1c/50b35f3bd23e001518fa86d7ae2a1cf8 | 376 +++++++++++++++ .../1c/609377ad0d3e00151089cca86c5b1a99 | 437 ----------------- .../1c/a0ecf93ad23e001518fa86d7ae2a1cf8 | 376 +++++++++++++++ .../1e/20ce3447d43e001518fa86d7ae2a1cf8 | 224 +++++++++ .../1e/a0477e13d43e001518fa86d7ae2a1cf8 | 220 +++++++++ .../1e/b057e861ce3e001518fa86d7ae2a1cf8 | 31 ++ .../1f/203f7772d23e001518fa86d7ae2a1cf8 | 380 +++++++++++++++ .../1f/604b1a15873e00151ce8ff6d4f74dabd | 135 ------ .../2/00863467e03e001517108d149b613203 | 260 +++++++++++ .../2/a06adb06d43e001518fa86d7ae2a1cf8 | 219 +++++++++ .../20/b08b3094cf3e001518fa86d7ae2a1cf8 | 364 +++++++++++++++ .../21/509f004a873e00151ce8ff6d4f74dabd | 138 ------ .../21/a0775b0ee03e001517108d149b613203 | 259 +++++++++++ .../22/50fe465a863e00151ce8ff6d4f74dabd | 131 ------ .../22/8052bd83df3e001517108d149b613203 | 252 ++++++++++ .../22/a091cfc4d23e001518fa86d7ae2a1cf8 | 215 +++++++++ .../23/a0c7c72cd33e001518fa86d7ae2a1cf8 | 216 +++++++++ .../24/d0c95a0cd93e001517108d149b613203 | 224 +++++++++ .../25/3067ea8bd13e001518fa86d7ae2a1cf8 | 326 +++++++++++++ .../25/902f77f1de3e001517108d149b613203 | 250 ++++++++++ .../26/00298c12e03e001517108d149b613203 | 260 +++++++++++ .../26/108127addd3e001517108d149b613203 | 403 ++++++++++++++++ .../20fee89fce3e001518fa86d7ae2a1cf8} | 130 ++---- .../26/a0111a40d33e001518fa86d7ae2a1cf8 | 215 +++++++++ .../27/9011edbed23e001518fa86d7ae2a1cf8 | 215 +++++++++ .../27/d0c61635023e00151c31fb33fff4337f | 125 ----- .../27/f08a8910cf3e001518fa86d7ae2a1cf8 | 362 ++++++++++++++ .../28/309e6352d33e001518fa86d7ae2a1cf8 | 216 +++++++++ .../29/4085cc81fe3d00151c31fb33fff4337f | 122 ----- .../29/50dd5657043e00151c31fb33fff4337f | 125 ----- .../2a/001db465df3e001517108d149b613203 | 252 ++++++++++ .../2a/00a6389de03e001517108d149b613203 | 260 +++++++++++ .../2a/20868515d03e001518fa86d7ae2a1cf8 | 363 +++++++++++++++ .../2a/20a4e0af0d3e00151089cca86c5b1a99 | 434 ----------------- .../2a/50ddd938863e00151ce8ff6d4f74dabd | 131 ------ .../2a/d0123229883e00151ce8ff6d4f74dabd | 163 ------- .../2c/10b26929df3e001517108d149b613203 | 251 ++++++++++ .../2d/00c8dce1df3e001517108d149b613203 | 255 ++++++++++ .../2d/c0b10f0c023e00151c31fb33fff4337f | 124 ----- .../2e/003fe9fade3e001517108d149b613203 | 250 ++++++++++ .../2e/807b35a8dd3e001517108d149b613203 | 408 ++++++++++++++++ .../2e/90fc2ebfd23e001518fa86d7ae2a1cf8 | 215 +++++++++ .../2f/1089a9abdc3e001517108d149b613203 | 394 ++++++++++++++++ .../2f/6035f831893e00151ce8ff6d4f74dabd | 169 ------- .../30/10d5c0cc303e00151cbdba8b5f0a340e | 424 ----------------- .../30/20a0c374d23e001518fa86d7ae2a1cf8 | 345 ++++++++++++++ .../30/706b3ad0303e00151cbdba8b5f0a340e | 422 ----------------- .../31/808be1e8e03e001517108d149b613203 | 265 +++++++++++ .../31/c0e1dbcdcf3e001518fa86d7ae2a1cf8 | 363 +++++++++++++++ .../33/608c284a083e00151c31fb33fff4337f | 126 ----- .../33/60a1e0d1303e00151cbdba8b5f0a340e | 421 ----------------- .../33/90a26f4bdd3e001517108d149b613203 | 398 ++++++++++++++++ .../34/b097b71bce3e001518fa86d7ae2a1cf8 | 354 ++++++++++++++ .../36/407f1825013e00151c31fb33fff4337f | 124 ----- .../37/20e61fc4d13e001518fa86d7ae2a1cf8 | 370 +++++++++++++++ .../37/5064f5c0883e00151ce8ff6d4f74dabd | 173 ------- .../a0f3a0e9cf3e001518fa86d7ae2a1cf8} | 35 +- .../38/e086e0cc843e00151ce8ff6d4f74dabd | 119 ----- .../39/2006034ad03e001518fa86d7ae2a1cf8 | 201 ++++++++ .../3a/705720220d3e00151089cca86c5b1a99 | 433 ----------------- .../3a/909349e2df3e001517108d149b613203 | 255 ++++++++++ .../3a/d0b0a0be863e00151ce8ff6d4f74dabd | 132 ------ .../3b/30bdb825cd3e001518fa86d7ae2a1cf8 | 25 + .../3b/a0a30729d93e001517108d149b613203 | 227 +++++++++ .../3c/205637bed23e001518fa86d7ae2a1cf8 | 215 +++++++++ .../3c/60d8cd51873e00151ce8ff6d4f74dabd | 139 ------ .../3d/007663b2df3e001517108d149b613203 | 421 +++++++++++++++++ .../3d/00f95890de3e001517108d149b613203 | 435 +++++++++++++++++ .../3d/6051d217853e00151ce8ff6d4f74dabd | 121 ----- .../3d/c0b328b0883e00151ce8ff6d4f74dabd | 176 ------- .../3e/00fa721adf3e001517108d149b613203 | 250 ++++++++++ .../3e/509fad42873e00151ce8ff6d4f74dabd | 136 ------ .../3e/90e3e69bde3e001517108d149b613203 | 435 +++++++++++++++++ .../3e/e0d118c0863e00151ce8ff6d4f74dabd | 135 ------ .../3f/70140e5a0c3e00151089cca86c5b1a99 | 432 ----------------- .../3f/a0709f19cf3e001518fa86d7ae2a1cf8 | 362 ++++++++++++++ .../3f/d0bd9472043e00151c31fb33fff4337f | 126 ----- .../4/b030d637cd3e001518fa86d7ae2a1cf8 | 29 ++ .../40/607238ae0d3e00151089cca86c5b1a99 | 434 ----------------- .../40/900a4bdce03e001517108d149b613203 | 265 +++++++++++ .../41/50a33590fe3d00151c31fb33fff4337f | 123 ----- .../43/90a95fb5e03e001517108d149b613203 | 263 +++++++++++ .../43/d0b51c31023e00151c31fb33fff4337f | 125 ----- .../44/3078a0bed23e001518fa86d7ae2a1cf8 | 215 +++++++++ .../44/c0bce577873e00151ce8ff6d4f74dabd | 145 ------ .../46/a01312cb303e00151cbdba8b5f0a340e | 425 ----------------- .../46/a0e24f1ad43e001518fa86d7ae2a1cf8 | 221 +++++++++ .../47/209354bad13e001518fa86d7ae2a1cf8 | 370 +++++++++++++++ .../47/20a74d8ad13e001518fa86d7ae2a1cf8 | 368 +++++++++++++++ .../48/00204eb0de3e001517108d149b613203 | 436 +++++++++++++++++ .../48/10d650b8e03e001517108d149b613203 | 264 +++++++++++ .../48/60516d96843e00151ce8ff6d4f74dabd | 117 ----- .../49/203c0b4ad33e001518fa86d7ae2a1cf8 | 215 +++++++++ .../49/a04d8dc3d23e001518fa86d7ae2a1cf8 | 215 +++++++++ .../49/b0556e29ce3e001518fa86d7ae2a1cf8 | 355 ++++++++++++++ .../4a/202fd432d93e001517108d149b613203 | 228 +++++++++ .../4a/20662b05d33e001518fa86d7ae2a1cf8 | 215 +++++++++ .../4a/50f7fce0873e00151ce8ff6d4f74dabd | 152 ------ .../203dd097ce3e001518fa86d7ae2a1cf8} | 130 ++---- .../4c/d0831972873e00151ce8ff6d4f74dabd | 144 ------ .../4d/80b8c135e13e001517108d149b613203 | 265 +++++++++++ .../4d/a0ee15dcd13e001518fa86d7ae2a1cf8 | 373 +++++++++++++++ .../4e/e0491f86883e00151ce8ff6d4f74dabd | 173 ------- .../4f/50e0ec42893e00151ce8ff6d4f74dabd | 171 ------- .../5/9071ec23e13e001517108d149b613203 | 265 +++++++++++ .../5/908d0453dd3e001517108d149b613203 | 398 ++++++++++++++++ .../50/506a31a2883e00151ce8ff6d4f74dabd | 173 ------- .../51/50cc60cf883e00151ce8ff6d4f74dabd | 170 ------- .../53/d0e8e8e2873e00151ce8ff6d4f74dabd | 156 ------- .../55/c0fc6b25cd3e001518fa86d7ae2a1cf8 | 24 + .../56/10a840c1de3e001517108d149b613203 | 437 +++++++++++++++++ .../56/205a1cf9d13e001518fa86d7ae2a1cf8 | 374 +++++++++++++++ .../56/d0b1ba48873e00151ce8ff6d4f74dabd | 137 ------ .../58/107b898edc3e001517108d149b613203 | 394 ++++++++++++++++ .../59/90935a89dc3e001517108d149b613203 | 394 ++++++++++++++++ .../59/d0ec3c3e893e00151ce8ff6d4f74dabd | 170 ------- .../5a/0031cee5e03e001517108d149b613203 | 265 +++++++++++ .../5a/109a5eedde3e001517108d149b613203 | 250 ++++++++++ .../5a/80e572e0e43e001517108d149b613203 | 424 +++++++++++++++++ .../5a/d014d921873e00151ce8ff6d4f74dabd | 135 ------ .../5c/004c7803e03e001517108d149b613203 | 255 ++++++++++ .../5c/a03b3ea1d33e001518fa86d7ae2a1cf8 | 219 +++++++++ .../5d/a0a6c2d0d23e001518fa86d7ae2a1cf8 | 215 +++++++++ .../5d/a0befd81d33e001518fa86d7ae2a1cf8 | 216 +++++++++ .../5f/2061341bd23e001518fa86d7ae2a1cf8 | 375 +++++++++++++++ .../5f/60d7f94a0e3e00151089cca86c5b1a99 | 434 ----------------- .../5f/c0841a72043e00151c31fb33fff4337f | 126 ----- .../5f/c0b28923ce3e001518fa86d7ae2a1cf8 | 355 ++++++++++++++ .../6/2029114dd33e001518fa86d7ae2a1cf8 | 216 +++++++++ .../6/208a8252ce3e001518fa86d7ae2a1cf8 | 31 ++ .../6/a032431fd23e001518fa86d7ae2a1cf8 | 375 +++++++++++++++ .../60/104f566fdd3e001517108d149b613203 | 400 ++++++++++++++++ .../60/808a5063df3e001517108d149b613203 | 252 ++++++++++ .../61/0023220fe03e001517108d149b613203 | 260 +++++++++++ .../61/20e39728df3e001517108d149b613203 | 251 ++++++++++ .../61/b0779e98d03e001518fa86d7ae2a1cf8 | 205 ++++++++ .../62/00fd4080df3e001517108d149b613203 | 252 ++++++++++ .../62/502ee671043e00151c31fb33fff4337f | 126 ----- .../62/8065dabd843e00151ce8ff6d4f74dabd | 119 ----- .../206c2677ce3e001518fa86d7ae2a1cf8} | 136 ++---- .../64/202fdd3acd3e001518fa86d7ae2a1cf8 | 31 ++ .../64/20a74791d03e001518fa86d7ae2a1cf8 | 205 ++++++++ .../64/50d16a24893e00151ce8ff6d4f74dabd | 167 ------- .../64/8096a0dee43e001517108d149b613203 | 425 +++++++++++++++++ .../65/50973663863e00151ce8ff6d4f74dabd | 131 ------ .../66/d0650077873e00151ce8ff6d4f74dabd | 145 ------ .../69/90750be4e43e001517108d149b613203 | 422 +++++++++++++++++ .../6a/20a2e34ad03e001518fa86d7ae2a1cf8 | 201 ++++++++ .../6c/20b08dced03e001518fa86d7ae2a1cf8 | 211 +++++++++ .../6c/500072fecd3e001518fa86d7ae2a1cf8 | 351 ++++++++++++++ .../6d/30dfaa0fd93e001517108d149b613203 | 227 +++++++++ .../6e/a01e1adad13e001518fa86d7ae2a1cf8 | 373 +++++++++++++++ .../6e/b0802cf3de3e001517108d149b613203 | 250 ++++++++++ .../6e/e0394523853e00151ce8ff6d4f74dabd | 122 ----- .../6f/004f0f0ae03e001517108d149b613203 | 259 +++++++++++ .../6f/308fe70ed93e001517108d149b613203 | 227 +++++++++ .../7/d0a7c5c8ce3e001518fa86d7ae2a1cf8 | 361 ++++++++++++++ .../70/90557930e13e001517108d149b613203 | 265 +++++++++++ .../71/b09765e7d13e001518fa86d7ae2a1cf8 | 373 +++++++++++++++ .../71/c0147a73043e00151c31fb33fff4337f | 126 ----- .../72/60069e3b863e00151ce8ff6d4f74dabd | 131 ------ .../72/601fd2f0013e00151c31fb33fff4337f | 124 ----- .../72/6080d12b893e00151ce8ff6d4f74dabd | 168 ------- .../73/005a2e08e03e001517108d149b613203 | 259 +++++++++++ .../73/40821671043e00151c31fb33fff4337f | 126 ----- .../73/50eccfd4e43e001517108d149b613203 | 421 +++++++++++++++++ .../73/809dfb8ddd3e001517108d149b613203 | 408 ++++++++++++++++ .../73/a095babcdc3e001517108d149b613203 | 394 ++++++++++++++++ .../74/008b13dedf3e001517108d149b613203 | 255 ++++++++++ .../74/10419116e13e001517108d149b613203 | 265 +++++++++++ .../74/8080bcd3e43e001517108d149b613203 | 422 +++++++++++++++++ .../75/200e61c5d03e001518fa86d7ae2a1cf8 | 209 +++++++++ .../75/20bc5301d13e001518fa86d7ae2a1cf8 | 222 +++++++++ .../75/a0acffa2d13e001518fa86d7ae2a1cf8 | 368 +++++++++++++++ .../77/00ad7695df3e001517108d149b613203 | 421 +++++++++++++++++ .../77/10dec4cbce3e001518fa86d7ae2a1cf8 | 360 ++++++++++++++ .../77/50df6a0f313e00151cbdba8b5f0a340e | 126 ----- .../78/40118f77873e00151ce8ff6d4f74dabd | 145 ------ .../78/804750c0843e00151ce8ff6d4f74dabd | 119 ----- .../78/a0991cb7d13e001518fa86d7ae2a1cf8 | 370 +++++++++++++++ .../79/106a6cf8dc3e001517108d149b613203 | 394 ++++++++++++++++ .../7a/4046a21a013e00151c31fb33fff4337f | 123 ----- .../7b/c081221f023e00151c31fb33fff4337f | 125 ----- .../7c/3014764dcd3e001518fa86d7ae2a1cf8 | 31 ++ .../7c/a0934f14cf3e001518fa86d7ae2a1cf8 | 362 ++++++++++++++ .../7d/10c43d1bdf3e001517108d149b613203 | 250 ++++++++++ .../7d/a005617fd13e001518fa86d7ae2a1cf8 | 363 +++++++++++++++ .../7e/001a1675df3e001517108d149b613203 | 252 ++++++++++ .../7e/2093d427df3e001517108d149b613203 | 250 ++++++++++ .../7f/9025b8a1de3e001517108d149b613203 | 435 +++++++++++++++++ .../8/e0936b2f853e00151ce8ff6d4f74dabd | 129 ----- .../80/00713b62df3e001517108d149b613203 | 252 ++++++++++ .../80/4075d399d03e001518fa86d7ae2a1cf8 | 206 ++++++++ .../80/50a96102873e00151ce8ff6d4f74dabd | 135 ------ .../81/b0e3d39bd13e001518fa86d7ae2a1cf8 | 326 +++++++++++++ .../82/00f1d2ebde3e001517108d149b613203 | 228 +++++++++ .../82/201f90d5d03e001518fa86d7ae2a1cf8 | 211 +++++++++ .../82/80cc011bdf3e001517108d149b613203 | 250 ++++++++++ .../83/20a1e315cf3e001518fa86d7ae2a1cf8 | 362 ++++++++++++++ .../83/90fff2badd3e001517108d149b613203 | 411 ++++++++++++++++ .../84/a0c00f13cf3e001518fa86d7ae2a1cf8 | 362 ++++++++++++++ .../85/f037c8f6843e00151ce8ff6d4f74dabd | 119 ----- .../86/e024da2a853e00151ce8ff6d4f74dabd | 129 ----- .../88/101b2028df3e001517108d149b613203 | 251 ++++++++++ .../88/e001984d0e3e00151089cca86c5b1a99 | 434 ----------------- .../89/80137592e43e001517108d149b613203 | 263 +++++++++++ .../8b/00d17baede3e001517108d149b613203 | 435 +++++++++++++++++ .../8c/60d47714883e00151ce8ff6d4f74dabd | 162 ------- .../8c/a0ea662dcf3e001518fa86d7ae2a1cf8 | 362 ++++++++++++++ .../8c/d09f3274873e00151ce8ff6d4f74dabd | 145 ------ .../8d/00c5f1e2e03e001517108d149b613203 | 265 +++++++++++ .../8d/20aae3d4de3e001517108d149b613203 | 440 ++++++++++++++++++ .../8d/8048b1b4dd3e001517108d149b613203 | 403 ++++++++++++++++ .../8d/90fd528ee33e001517108d149b613203 | 265 +++++++++++ .../8d/d0631404023e00151c31fb33fff4337f | 125 ----- .../8f/9034fdd8df3e001517108d149b613203 | 255 ++++++++++ .../9/10ab8866df3e001517108d149b613203 | 252 ++++++++++ .../91/0009f78bdf3e001517108d149b613203 | 421 +++++++++++++++++ .../c01c0d9ecf3e001518fa86d7ae2a1cf8} | 37 +- .../92/d0efd7c1fe3d00151c31fb33fff4337f | 122 ----- .../93/10f3fc0acf3e001518fa86d7ae2a1cf8 | 361 ++++++++++++++ .../93/d0f07864d23e001518fa86d7ae2a1cf8 | 376 +++++++++++++++ .../94/2033b6d6d13e001518fa86d7ae2a1cf8 | 373 +++++++++++++++ .../94/602d1cd1873e00151ce8ff6d4f74dabd | 152 ------ .../95/605f63960d3e00151089cca86c5b1a99 | 436 ----------------- .../95/70d8d329853e00151ce8ff6d4f74dabd | 127 ----- .../96/20ba5e09d43e001518fa86d7ae2a1cf8 | 219 +++++++++ .../96/90d42e62e43e001517108d149b613203 | 265 +++++++++++ .../97/20ad60e0d03e001518fa86d7ae2a1cf8 | 211 +++++++++ .../97/8035b5d5df3e001517108d149b613203 | 253 ++++++++++ .../97/a0aae0bdd23e001518fa86d7ae2a1cf8 | 223 +++++++++ .../97/c0e2ad6fce3e001518fa86d7ae2a1cf8 | 357 ++++++++++++++ .../98/201af098d03e001518fa86d7ae2a1cf8 | 205 ++++++++ .../99/308353a4d93e001517108d149b613203 | 228 +++++++++ .../9a/802cbb44dd3e001517108d149b613203 | 394 ++++++++++++++++ .../9a/90dce6d5ce3e001518fa86d7ae2a1cf8 | 361 ++++++++++++++ .../9a/a0aebdacd03e001518fa86d7ae2a1cf8 | 206 ++++++++ .../9b/0068cab7e03e001517108d149b613203 | 263 +++++++++++ .../9c/30bb8899d13e001518fa86d7ae2a1cf8 | 326 +++++++++++++ .../9d/50e1b4b6883e00151ce8ff6d4f74dabd | 173 ------- .../a/705c51af0d3e00151089cca86c5b1a99 | 434 ----------------- .../a/c0191a3f023e00151c31fb33fff4337f | 125 ----- .../a0/f08cfd11853e00151ce8ff6d4f74dabd | 120 ----- .../a1/009afe94e33e001517108d149b613203 | 422 +++++++++++++++++ .../a1/1035b42cd23e001518fa86d7ae2a1cf8 | 376 +++++++++++++++ .../a1/1076adccde3e001517108d149b613203 | 436 +++++++++++++++++ .../a1/a05e6526d23e001518fa86d7ae2a1cf8 | 375 +++++++++++++++ .../a2/206c0ba2d23e001518fa86d7ae2a1cf8 | 222 +++++++++ .../a2/20ecb1f0d03e001518fa86d7ae2a1cf8 | 211 +++++++++ .../a2/900097abde3e001517108d149b613203 | 435 +++++++++++++++++ .../a3/00bc291adf3e001517108d149b613203 | 250 ++++++++++ .../a3/e09f3eb6883e00151ce8ff6d4f74dabd | 177 ------- .../a4/901a3493e03e001517108d149b613203 | 260 +++++++++++ .../a4/a0f428a3d33e001518fa86d7ae2a1cf8 | 219 +++++++++ .../a5/80c576a3de3e001517108d149b613203 | 435 +++++++++++++++++ .../a6/20f25379dc3e001517108d149b613203 | 382 +++++++++++++++ .../a8/006bbef3df3e001517108d149b613203 | 255 ++++++++++ .../a8/10465292e03e001517108d149b613203 | 260 +++++++++++ .../a8/a053b075de3e001517108d149b613203 | 429 +++++++++++++++++ .../a9/40e5b0ce303e00151cbdba8b5f0a340e | 423 ----------------- .../a9/60ef3b14313e00151cbdba8b5f0a340e | 118 ----- .../aa/40db9018d93e001517108d149b613203 | 227 +++++++++ .../aa/a076f09ad33e001518fa86d7ae2a1cf8 | 218 +++++++++ .../ac/5065ec8ffe3d00151c31fb33fff4337f | 122 ----- .../ac/f0586fbb843e00151ce8ff6d4f74dabd | 117 ----- .../ad/00f387b8dd3e001517108d149b613203 | 409 ++++++++++++++++ .../ad/60b39408d43e001518fa86d7ae2a1cf8 | 220 +++++++++ .../c0954ebcce3e001518fa86d7ae2a1cf8} | 132 ++---- .../ad/d05bdac3883e00151ce8ff6d4f74dabd | 170 ------- .../1023a9f9cc3e001518fa86d7ae2a1cf8} | 33 +- .../ae/80773b20e13e001517108d149b613203 | 265 +++++++++++ .../af/80d63604df3e001517108d149b613203 | 250 ++++++++++ .../b/301da326cd3e001518fa86d7ae2a1cf8 | 25 + .../b1/20248930cd3e001518fa86d7ae2a1cf8 | 25 + .../b1/30440676d03e001518fa86d7ae2a1cf8 | 201 ++++++++ .../b3/100a9853d43e001518fa86d7ae2a1cf8 | 224 +++++++++ .../b3/c04f9e03ce3e001518fa86d7ae2a1cf8 | 354 ++++++++++++++ .../b4/90dba275dd3e001517108d149b613203 | 408 ++++++++++++++++ .../b5/202ce194d13e001518fa86d7ae2a1cf8 | 326 +++++++++++++ .../b5/40ecd766ce3e001518fa86d7ae2a1cf8 | 31 ++ .../b5/c0ca4f18013e00151c31fb33fff4337f | 122 ----- .../20667af5cf3e001518fa86d7ae2a1cf8} | 37 +- .../b6/504cf350863e00151ce8ff6d4f74dabd | 131 ------ .../b6/90a348520c3e00151089cca86c5b1a99 | 432 ----------------- .../b7/20f6378ed03e001518fa86d7ae2a1cf8 | 204 ++++++++ .../b7/b048b351cd3e001518fa86d7ae2a1cf8 | 31 ++ .../b8/5051ef26e13e001517108d149b613203 | 265 +++++++++++ .../b9/0096b9fee03e001517108d149b613203 | 265 +++++++++++ .../b9/409c8390fe3d00151c31fb33fff4337f | 122 ----- .../b9/50eb23fc013e00151c31fb33fff4337f | 125 ----- .../ba/10207fd7df3e001517108d149b613203 | 254 ++++++++++ .../ba/70faf280883e00151ce8ff6d4f74dabd | 172 ------- .../bb/60b5d072043e00151c31fb33fff4337f | 126 ----- .../bc/30916f57cf3e001518fa86d7ae2a1cf8 | 362 ++++++++++++++ .../bc/a0204038ce3e001518fa86d7ae2a1cf8 | 355 ++++++++++++++ .../bc/a099c9afd13e001518fa86d7ae2a1cf8 | 368 +++++++++++++++ .../bd/907ef589dd3e001517108d149b613203 | 408 ++++++++++++++++ .../bd/90d57cb4de3e001517108d149b613203 | 436 +++++++++++++++++ .../bd/90d70867df3e001517108d149b613203 | 252 ++++++++++ .../bd/d02b22e3883e00151ce8ff6d4f74dabd | 167 ------- .../be/d0face78043e00151c31fb33fff4337f | 126 ----- .../bf/60a98f74863e00151ce8ff6d4f74dabd | 131 ------ .../bf/a056849fd33e001518fa86d7ae2a1cf8 | 219 +++++++++ .../bf/a0d1b862cf3e001518fa86d7ae2a1cf8 | 364 +++++++++++++++ .../c/00f451f0df3e001517108d149b613203 | 255 ++++++++++ .../c/b06ccd99ce3e001518fa86d7ae2a1cf8 | 358 ++++++++++++++ .../c0/804c83d7e43e001517108d149b613203 | 422 +++++++++++++++++ .../c2/20d96d9ad33e001518fa86d7ae2a1cf8 | 216 +++++++++ .../c2/30656a8fdc3e001517108d149b613203 | 394 ++++++++++++++++ .../c3/103cea7ede3e001517108d149b613203 | 430 +++++++++++++++++ .../c3/50421721013e00151c31fb33fff4337f | 123 ----- .../c4/c0d4e9c9873e00151ce8ff6d4f74dabd | 148 ------ .../c5/30315643d03e001518fa86d7ae2a1cf8 | 198 ++++++++ .../c5/9087c2e9de3e001517108d149b613203 | 440 ++++++++++++++++++ .../c5/e0bc896e043e00151c31fb33fff4337f | 126 ----- .../c6/50d2a147883e00151ce8ff6d4f74dabd | 172 ------- .../c6/c0dc5f8ffe3d00151c31fb33fff4337f | 122 ----- .../c6/d022346e043e00151c31fb33fff4337f | 126 ----- .../c7/20873c35da3e001517108d149b613203 | 380 +++++++++++++++ .../c7/30e525880d3e00151089cca86c5b1a99 | 435 ----------------- .../c7/d05586b7fe3d00151c31fb33fff4337f | 122 ----- .../c7/e0273ad2843e00151ce8ff6d4f74dabd | 119 ----- .../c7/f00aad3f023e00151c31fb33fff4337f | 125 ----- .../c8/00d17cf2e43e001517108d149b613203 | 425 +++++++++++++++++ .../c9/005c8f6bdd3e001517108d149b613203 | 399 ++++++++++++++++ .../c9/d0b1d9a5883e00151ce8ff6d4f74dabd | 177 ------- .../ca/00f60a63df3e001517108d149b613203 | 252 ++++++++++ .../cb/d058f890873e00151ce8ff6d4f74dabd | 145 ------ .../cc/10d57c5c0d3e00151089cca86c5b1a99 | 434 ----------------- .../cc/b08607c4d23e001518fa86d7ae2a1cf8 | 215 +++++++++ .../cd/804ab462df3e001517108d149b613203 | 252 ++++++++++ .../cd/90837b3cd23e001518fa86d7ae2a1cf8 | 377 +++++++++++++++ .../ce/000b95b8e03e001517108d149b613203 | 264 +++++++++++ .../ce/d00a337efe3d00151c31fb33fff4337f | 122 ----- .../cf/00fa3acadf3e001517108d149b613203 | 252 ++++++++++ .../cf/10d8879fde3e001517108d149b613203 | 435 +++++++++++++++++ .../cf/509e01bffe3d00151c31fb33fff4337f | 122 ----- .../d2/204ad69bd03e001518fa86d7ae2a1cf8 | 206 ++++++++ .../d2/d0f664fd013e00151c31fb33fff4337f | 125 ----- .../d3/00e70d14e03e001517108d149b613203 | 260 +++++++++++ .../d5/008e353cdf3e001517108d149b613203 | 251 ++++++++++ .../d5/50049d01883e00151ce8ff6d4f74dabd | 162 ------- .../d5/9032a867e43e001517108d149b613203 | 263 +++++++++++ .../d6/0038bc1adf3e001517108d149b613203 | 250 ++++++++++ .../d6/80ae4e03e13e001517108d149b613203 | 265 +++++++++++ .../d6/a08b7a0ed03e001518fa86d7ae2a1cf8 | 198 ++++++++ .../d6/e0a5b112313e00151cbdba8b5f0a340e | 120 ----- .../d7/5064fb90fe3d00151c31fb33fff4337f | 123 ----- .../d7/a0f61d9bd03e001518fa86d7ae2a1cf8 | 206 ++++++++ .../d7/c0293873043e00151c31fb33fff4337f | 126 ----- .../d8/e0a05c04853e00151ce8ff6d4f74dabd | 119 ----- .../d8/f0762d6f043e00151c31fb33fff4337f | 126 ----- .../da/a0d614ced03e001518fa86d7ae2a1cf8 | 210 +++++++++ .../da/f088765c0c3e00151089cca86c5b1a99 | 433 ----------------- .../db/600bbc16013e00151c31fb33fff4337f | 122 ----- .../dd/80ebea64dd3e001517108d149b613203 | 398 ++++++++++++++++ .../df/9064eb98e33e001517108d149b613203 | 265 +++++++++++ .../df/c06a7eb00d3e00151089cca86c5b1a99 | 434 ----------------- .../e/a0795133d23e001518fa86d7ae2a1cf8 | 376 +++++++++++++++ .../a07905a5cf3e001518fa86d7ae2a1cf8} | 37 +- .../e3/20517c59cf3e001518fa86d7ae2a1cf8 | 364 +++++++++++++++ .../e3/80cfda10e03e001517108d149b613203 | 260 +++++++++++ .../e3/905afa0fe03e001517108d149b613203 | 259 +++++++++++ .../e4/3060bf8dcf3e001518fa86d7ae2a1cf8 | 364 +++++++++++++++ .../e5/a0c874c7303e00151cbdba8b5f0a340e | 434 ----------------- .../e6/c0b7626f043e00151c31fb33fff4337f | 126 ----- .../e6/d0c6108f083e00151c31fb33fff4337f | 126 ----- .../e8/90448e80dd3e001517108d149b613203 | 408 ++++++++++++++++ .../ea/40a8228bfe3d00151c31fb33fff4337f | 122 ----- .../eb/3086890bd03e001518fa86d7ae2a1cf8 | 198 ++++++++ .../eb/803bcb6fde3e001517108d149b613203 | 409 ++++++++++++++++ .../eb/80c8e1dade3e001517108d149b613203 | 228 +++++++++ .../eb/e0406b19853e00151ce8ff6d4f74dabd | 122 ----- .../ec/d0870f36883e00151ce8ff6d4f74dabd | 163 ------- .../ec/d0cc5971043e00151c31fb33fff4337f | 126 ----- .../ed/d09b59ba873e00151ce8ff6d4f74dabd | 148 ------ .../ee/500395f1873e00151ce8ff6d4f74dabd | 157 ------- .../206bbc9acf3e001518fa86d7ae2a1cf8} | 37 +- .../ef/50b12f8f883e00151ce8ff6d4f74dabd | 177 ------- .../ef/d0a65f54873e00151ce8ff6d4f74dabd | 140 ------ .../f/90af968ede3e001517108d149b613203 | 430 +++++++++++++++++ .../f/a0d81438d33e001518fa86d7ae2a1cf8 | 216 +++++++++ .../f/b08c4dd3d13e001518fa86d7ae2a1cf8 | 372 +++++++++++++++ .../f/e0df3528853e00151ce8ff6d4f74dabd | 126 ----- .../f1/808b0319df3e001517108d149b613203 | 250 ++++++++++ .../f2/205fa4c2d03e001518fa86d7ae2a1cf8 | 209 +++++++++ .../f2/a0380b49d03e001518fa86d7ae2a1cf8 | 200 ++++++++ .../f3/203061bfd23e001518fa86d7ae2a1cf8 | 215 +++++++++ .../f3/50ae2f61873e00151ce8ff6d4f74dabd | 140 ------ .../f3/a09a2529d33e001518fa86d7ae2a1cf8 | 215 +++++++++ .../f4/206dc8d8d83e001517108d149b613203 | 224 +++++++++ .../f4/20d00369d23e001518fa86d7ae2a1cf8 | 380 +++++++++++++++ .../f4/5072900e883e00151ce8ff6d4f74dabd | 162 ------- .../f4/80e28d69e43e001517108d149b613203 | 263 +++++++++++ .../f5/9050bb87de3e001517108d149b613203 | 430 +++++++++++++++++ .../f8/108fca500c3e00151089cca86c5b1a99 | 432 ----------------- .../f9/a01791b5d13e001518fa86d7ae2a1cf8 | 369 +++++++++++++++ .../fa/90ef83b4e03e001517108d149b613203 | 263 +++++++++++ .../fb/307961d7cf3e001518fa86d7ae2a1cf8 | 363 +++++++++++++++ .../fb/503cf63d883e00151ce8ff6d4f74dabd | 167 ------- .../fc/0072fbdce43e001517108d149b613203 | 424 +++++++++++++++++ .../fc/50e6e65e043e00151c31fb33fff4337f | 125 ----- .../fc/8023f1ece43e001517108d149b613203 | 422 +++++++++++++++++ .../fd/80351029e13e001517108d149b613203 | 265 +++++++++++ .../fe/204112ead13e001518fa86d7ae2a1cf8 | 374 +++++++++++++++ .../a0790ee2cf3e001518fa86d7ae2a1cf8} | 34 +- .../RemoteSystemsTempFiles/.markers.snap | Bin 240 -> 336 bytes .../RemoteSystemsTempFiles/.syncinfo.snap | Bin 240 -> 336 bytes .../.indexes/e4/77/69/e/history.index | Bin 7854 -> 5214 bytes .../.projects/TheButtonAutoFlair/.markers | Bin 2981 -> 2018 bytes .../TheButtonAutoFlair/.markers.snap | Bin 14962 -> 32782 bytes .../TheButtonAutoFlair/.syncinfo.snap | Bin 240 -> 336 bytes .../.root/.markers.snap | Bin 240 -> 336 bytes .../org.eclipse.core.resources/.root/7.tree | Bin 4581 -> 0 bytes .../org.eclipse.core.resources/.root/8.tree | Bin 0 -> 5884 bytes .../.safetable/org.eclipse.core.resources | Bin 13824 -> 18933 bytes .../.plugins/org.eclipse.core.resources/.snap | Bin 10748 -> 13162 bytes .../org.eclipse.e4.workbench/workbench.xmi | 126 ++--- .../org.eclipse.jdt.core/1508644233.index | Bin 16849 -> 17197 bytes .../org.eclipse.jdt.core/savedIndexNames.txt | 4 +- .../QualifiedTypeNameHistory.xml | 2 +- .../org.eclipse.jdt.ui/jdt-images/0.png | Bin 238 -> 210 bytes .../org.eclipse.jdt.ui/jdt-images/1.png | Bin 283 -> 159 bytes .../org.eclipse.jdt.ui/jdt-images/2.png | Bin 210 -> 509 bytes .../org.eclipse.jdt.ui/jdt-images/4.png | Bin 490 -> 194 bytes .../org.eclipse.jdt.ui/jdt-images/5.png | Bin 222 -> 283 bytes .../org.eclipse.jdt.ui/jdt-images/6.png | Bin 509 -> 238 bytes .../org.eclipse.jdt.ui/jdt-images/7.png | Bin 147 -> 0 bytes .../org.eclipse.jdt.ui/jdt-images/8.png | Bin 194 -> 0 bytes .../dialog_settings.xml | 23 + .../org.eclipse.ui.workbench/workingsets.xml | 2 + .../tk/sznp/thebuttonautoflair/Commands.class | Bin 5788 -> 7596 bytes .../MaybeOfflinePlayer.class | Bin 1182 -> 1205 bytes .../thebuttonautoflair/PlayerListener.class | Bin 4777 -> 4760 bytes .../thebuttonautoflair/PluginMain$1.class | Bin 675 -> 675 bytes .../sznp/thebuttonautoflair/PluginMain.class | Bin 13121 -> 14629 bytes .../tk/sznp/thebuttonautoflair/Commands.java | 151 ++++-- .../MaybeOfflinePlayer.java | 7 + .../thebuttonautoflair/PlayerListener.java | 2 +- .../sznp/thebuttonautoflair/PluginMain.java | 254 ++++++---- 467 files changed, 82050 insertions(+), 26885 deletions(-) create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/0/3027b10cd93e001517108d149b613203 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/1/601f8274873e00151ce8ff6d4f74dabd create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/1/90ea77eee43e001517108d149b613203 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/1/a0191b15d23e001518fa86d7ae2a1cf8 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/1/d071b8d5873e00151ce8ff6d4f74dabd delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/1/d0997b1b023e00151c31fb33fff4337f delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/1/f03cfc260d3e00151089cca86c5b1a99 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/10/80fad266df3e001517108d149b613203 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/10/d069a424873e00151ce8ff6d4f74dabd delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/11/e02f8f8d083e00151c31fb33fff4337f create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/12/10177772dd3e001517108d149b613203 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/12/900059d3e03e001517108d149b613203 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/12/90d09f90df3e001517108d149b613203 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/12/b09714c2cf3e001518fa86d7ae2a1cf8 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/13/903ca4bcde3e001517108d149b613203 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/14/20b7f4c2d23e001518fa86d7ae2a1cf8 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/15/a0689143d43e001518fa86d7ae2a1cf8 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/15/d05be66e043e00151c31fb33fff4337f create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/16/90523966df3e001517108d149b613203 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/17/101a2f29df3e001517108d149b613203 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/19/c0e42302ce3e001518fa86d7ae2a1cf8 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/1a/101bc97ade3e001517108d149b613203 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/1a/308e38e1de3e001517108d149b613203 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/1b/f0c4a095083e00151c31fb33fff4337f create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/1c/50b35f3bd23e001518fa86d7ae2a1cf8 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/1c/609377ad0d3e00151089cca86c5b1a99 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/1c/a0ecf93ad23e001518fa86d7ae2a1cf8 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/1e/20ce3447d43e001518fa86d7ae2a1cf8 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/1e/a0477e13d43e001518fa86d7ae2a1cf8 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/1e/b057e861ce3e001518fa86d7ae2a1cf8 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/1f/203f7772d23e001518fa86d7ae2a1cf8 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/1f/604b1a15873e00151ce8ff6d4f74dabd create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/2/00863467e03e001517108d149b613203 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/2/a06adb06d43e001518fa86d7ae2a1cf8 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/20/b08b3094cf3e001518fa86d7ae2a1cf8 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/21/509f004a873e00151ce8ff6d4f74dabd create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/21/a0775b0ee03e001517108d149b613203 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/22/50fe465a863e00151ce8ff6d4f74dabd create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/22/8052bd83df3e001517108d149b613203 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/22/a091cfc4d23e001518fa86d7ae2a1cf8 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/23/a0c7c72cd33e001518fa86d7ae2a1cf8 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/24/d0c95a0cd93e001517108d149b613203 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/25/3067ea8bd13e001518fa86d7ae2a1cf8 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/25/902f77f1de3e001517108d149b613203 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/26/00298c12e03e001517108d149b613203 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/26/108127addd3e001517108d149b613203 rename .metadata/.plugins/org.eclipse.core.resources/.history/{f8/e04b0add303e00151cbdba8b5f0a340e => 26/20fee89fce3e001518fa86d7ae2a1cf8} (70%) create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/26/a0111a40d33e001518fa86d7ae2a1cf8 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/27/9011edbed23e001518fa86d7ae2a1cf8 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/27/d0c61635023e00151c31fb33fff4337f create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/27/f08a8910cf3e001518fa86d7ae2a1cf8 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/28/309e6352d33e001518fa86d7ae2a1cf8 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/29/4085cc81fe3d00151c31fb33fff4337f delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/29/50dd5657043e00151c31fb33fff4337f create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/2a/001db465df3e001517108d149b613203 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/2a/00a6389de03e001517108d149b613203 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/2a/20868515d03e001518fa86d7ae2a1cf8 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/2a/20a4e0af0d3e00151089cca86c5b1a99 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/2a/50ddd938863e00151ce8ff6d4f74dabd delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/2a/d0123229883e00151ce8ff6d4f74dabd create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/2c/10b26929df3e001517108d149b613203 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/2d/00c8dce1df3e001517108d149b613203 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/2d/c0b10f0c023e00151c31fb33fff4337f create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/2e/003fe9fade3e001517108d149b613203 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/2e/807b35a8dd3e001517108d149b613203 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/2e/90fc2ebfd23e001518fa86d7ae2a1cf8 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/2f/1089a9abdc3e001517108d149b613203 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/2f/6035f831893e00151ce8ff6d4f74dabd delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/30/10d5c0cc303e00151cbdba8b5f0a340e create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/30/20a0c374d23e001518fa86d7ae2a1cf8 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/30/706b3ad0303e00151cbdba8b5f0a340e create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/31/808be1e8e03e001517108d149b613203 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/31/c0e1dbcdcf3e001518fa86d7ae2a1cf8 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/33/608c284a083e00151c31fb33fff4337f delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/33/60a1e0d1303e00151cbdba8b5f0a340e create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/33/90a26f4bdd3e001517108d149b613203 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/34/b097b71bce3e001518fa86d7ae2a1cf8 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/36/407f1825013e00151c31fb33fff4337f create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/37/20e61fc4d13e001518fa86d7ae2a1cf8 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/37/5064f5c0883e00151ce8ff6d4f74dabd rename .metadata/.plugins/org.eclipse.core.resources/.history/{14/d0544e5b893e00151ce8ff6d4f74dabd => 38/a0f3a0e9cf3e001518fa86d7ae2a1cf8} (83%) delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/38/e086e0cc843e00151ce8ff6d4f74dabd create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/39/2006034ad03e001518fa86d7ae2a1cf8 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/3a/705720220d3e00151089cca86c5b1a99 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/3a/909349e2df3e001517108d149b613203 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/3a/d0b0a0be863e00151ce8ff6d4f74dabd create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/3b/30bdb825cd3e001518fa86d7ae2a1cf8 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/3b/a0a30729d93e001517108d149b613203 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/3c/205637bed23e001518fa86d7ae2a1cf8 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/3c/60d8cd51873e00151ce8ff6d4f74dabd create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/3d/007663b2df3e001517108d149b613203 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/3d/00f95890de3e001517108d149b613203 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/3d/6051d217853e00151ce8ff6d4f74dabd delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/3d/c0b328b0883e00151ce8ff6d4f74dabd create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/3e/00fa721adf3e001517108d149b613203 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/3e/509fad42873e00151ce8ff6d4f74dabd create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/3e/90e3e69bde3e001517108d149b613203 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/3e/e0d118c0863e00151ce8ff6d4f74dabd delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/3f/70140e5a0c3e00151089cca86c5b1a99 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/3f/a0709f19cf3e001518fa86d7ae2a1cf8 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/3f/d0bd9472043e00151c31fb33fff4337f create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/4/b030d637cd3e001518fa86d7ae2a1cf8 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/40/607238ae0d3e00151089cca86c5b1a99 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/40/900a4bdce03e001517108d149b613203 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/41/50a33590fe3d00151c31fb33fff4337f create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/43/90a95fb5e03e001517108d149b613203 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/43/d0b51c31023e00151c31fb33fff4337f create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/44/3078a0bed23e001518fa86d7ae2a1cf8 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/44/c0bce577873e00151ce8ff6d4f74dabd delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/46/a01312cb303e00151cbdba8b5f0a340e create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/46/a0e24f1ad43e001518fa86d7ae2a1cf8 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/47/209354bad13e001518fa86d7ae2a1cf8 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/47/20a74d8ad13e001518fa86d7ae2a1cf8 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/48/00204eb0de3e001517108d149b613203 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/48/10d650b8e03e001517108d149b613203 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/48/60516d96843e00151ce8ff6d4f74dabd create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/49/203c0b4ad33e001518fa86d7ae2a1cf8 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/49/a04d8dc3d23e001518fa86d7ae2a1cf8 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/49/b0556e29ce3e001518fa86d7ae2a1cf8 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/4a/202fd432d93e001517108d149b613203 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/4a/20662b05d33e001518fa86d7ae2a1cf8 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/4a/50f7fce0873e00151ce8ff6d4f74dabd rename .metadata/.plugins/org.eclipse.core.resources/.history/{4/70e5ccd7303e00151cbdba8b5f0a340e => 4b/203dd097ce3e001518fa86d7ae2a1cf8} (70%) delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/4c/d0831972873e00151ce8ff6d4f74dabd create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/4d/80b8c135e13e001517108d149b613203 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/4d/a0ee15dcd13e001518fa86d7ae2a1cf8 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/4e/e0491f86883e00151ce8ff6d4f74dabd delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/4f/50e0ec42893e00151ce8ff6d4f74dabd create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/5/9071ec23e13e001517108d149b613203 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/5/908d0453dd3e001517108d149b613203 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/50/506a31a2883e00151ce8ff6d4f74dabd delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/51/50cc60cf883e00151ce8ff6d4f74dabd delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/53/d0e8e8e2873e00151ce8ff6d4f74dabd create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/55/c0fc6b25cd3e001518fa86d7ae2a1cf8 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/56/10a840c1de3e001517108d149b613203 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/56/205a1cf9d13e001518fa86d7ae2a1cf8 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/56/d0b1ba48873e00151ce8ff6d4f74dabd create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/58/107b898edc3e001517108d149b613203 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/59/90935a89dc3e001517108d149b613203 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/59/d0ec3c3e893e00151ce8ff6d4f74dabd create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/5a/0031cee5e03e001517108d149b613203 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/5a/109a5eedde3e001517108d149b613203 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/5a/80e572e0e43e001517108d149b613203 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/5a/d014d921873e00151ce8ff6d4f74dabd create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/5c/004c7803e03e001517108d149b613203 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/5c/a03b3ea1d33e001518fa86d7ae2a1cf8 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/5d/a0a6c2d0d23e001518fa86d7ae2a1cf8 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/5d/a0befd81d33e001518fa86d7ae2a1cf8 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/5f/2061341bd23e001518fa86d7ae2a1cf8 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/5f/60d7f94a0e3e00151089cca86c5b1a99 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/5f/c0841a72043e00151c31fb33fff4337f create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/5f/c0b28923ce3e001518fa86d7ae2a1cf8 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/6/2029114dd33e001518fa86d7ae2a1cf8 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/6/208a8252ce3e001518fa86d7ae2a1cf8 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/6/a032431fd23e001518fa86d7ae2a1cf8 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/60/104f566fdd3e001517108d149b613203 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/60/808a5063df3e001517108d149b613203 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/61/0023220fe03e001517108d149b613203 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/61/20e39728df3e001517108d149b613203 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/61/b0779e98d03e001518fa86d7ae2a1cf8 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/62/00fd4080df3e001517108d149b613203 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/62/502ee671043e00151c31fb33fff4337f delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/62/8065dabd843e00151ce8ff6d4f74dabd rename .metadata/.plugins/org.eclipse.core.resources/.history/{97/f0d392d5303e00151cbdba8b5f0a340e => 63/206c2677ce3e001518fa86d7ae2a1cf8} (69%) create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/64/202fdd3acd3e001518fa86d7ae2a1cf8 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/64/20a74791d03e001518fa86d7ae2a1cf8 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/64/50d16a24893e00151ce8ff6d4f74dabd create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/64/8096a0dee43e001517108d149b613203 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/65/50973663863e00151ce8ff6d4f74dabd delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/66/d0650077873e00151ce8ff6d4f74dabd create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/69/90750be4e43e001517108d149b613203 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/6a/20a2e34ad03e001518fa86d7ae2a1cf8 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/6c/20b08dced03e001518fa86d7ae2a1cf8 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/6c/500072fecd3e001518fa86d7ae2a1cf8 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/6d/30dfaa0fd93e001517108d149b613203 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/6e/a01e1adad13e001518fa86d7ae2a1cf8 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/6e/b0802cf3de3e001517108d149b613203 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/6e/e0394523853e00151ce8ff6d4f74dabd create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/6f/004f0f0ae03e001517108d149b613203 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/6f/308fe70ed93e001517108d149b613203 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/7/d0a7c5c8ce3e001518fa86d7ae2a1cf8 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/70/90557930e13e001517108d149b613203 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/71/b09765e7d13e001518fa86d7ae2a1cf8 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/71/c0147a73043e00151c31fb33fff4337f delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/72/60069e3b863e00151ce8ff6d4f74dabd delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/72/601fd2f0013e00151c31fb33fff4337f delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/72/6080d12b893e00151ce8ff6d4f74dabd create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/73/005a2e08e03e001517108d149b613203 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/73/40821671043e00151c31fb33fff4337f create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/73/50eccfd4e43e001517108d149b613203 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/73/809dfb8ddd3e001517108d149b613203 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/73/a095babcdc3e001517108d149b613203 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/74/008b13dedf3e001517108d149b613203 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/74/10419116e13e001517108d149b613203 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/74/8080bcd3e43e001517108d149b613203 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/75/200e61c5d03e001518fa86d7ae2a1cf8 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/75/20bc5301d13e001518fa86d7ae2a1cf8 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/75/a0acffa2d13e001518fa86d7ae2a1cf8 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/77/00ad7695df3e001517108d149b613203 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/77/10dec4cbce3e001518fa86d7ae2a1cf8 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/77/50df6a0f313e00151cbdba8b5f0a340e delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/78/40118f77873e00151ce8ff6d4f74dabd delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/78/804750c0843e00151ce8ff6d4f74dabd create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/78/a0991cb7d13e001518fa86d7ae2a1cf8 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/79/106a6cf8dc3e001517108d149b613203 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/7a/4046a21a013e00151c31fb33fff4337f delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/7b/c081221f023e00151c31fb33fff4337f create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/7c/3014764dcd3e001518fa86d7ae2a1cf8 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/7c/a0934f14cf3e001518fa86d7ae2a1cf8 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/7d/10c43d1bdf3e001517108d149b613203 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/7d/a005617fd13e001518fa86d7ae2a1cf8 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/7e/001a1675df3e001517108d149b613203 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/7e/2093d427df3e001517108d149b613203 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/7f/9025b8a1de3e001517108d149b613203 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/8/e0936b2f853e00151ce8ff6d4f74dabd create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/80/00713b62df3e001517108d149b613203 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/80/4075d399d03e001518fa86d7ae2a1cf8 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/80/50a96102873e00151ce8ff6d4f74dabd create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/81/b0e3d39bd13e001518fa86d7ae2a1cf8 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/82/00f1d2ebde3e001517108d149b613203 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/82/201f90d5d03e001518fa86d7ae2a1cf8 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/82/80cc011bdf3e001517108d149b613203 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/83/20a1e315cf3e001518fa86d7ae2a1cf8 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/83/90fff2badd3e001517108d149b613203 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/84/a0c00f13cf3e001518fa86d7ae2a1cf8 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/85/f037c8f6843e00151ce8ff6d4f74dabd delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/86/e024da2a853e00151ce8ff6d4f74dabd create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/88/101b2028df3e001517108d149b613203 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/88/e001984d0e3e00151089cca86c5b1a99 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/89/80137592e43e001517108d149b613203 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/8b/00d17baede3e001517108d149b613203 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/8c/60d47714883e00151ce8ff6d4f74dabd create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/8c/a0ea662dcf3e001518fa86d7ae2a1cf8 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/8c/d09f3274873e00151ce8ff6d4f74dabd create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/8d/00c5f1e2e03e001517108d149b613203 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/8d/20aae3d4de3e001517108d149b613203 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/8d/8048b1b4dd3e001517108d149b613203 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/8d/90fd528ee33e001517108d149b613203 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/8d/d0631404023e00151c31fb33fff4337f create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/8f/9034fdd8df3e001517108d149b613203 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/9/10ab8866df3e001517108d149b613203 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/91/0009f78bdf3e001517108d149b613203 rename .metadata/.plugins/org.eclipse.core.resources/.history/{3b/d0078548033e00151c31fb33fff4337f => 91/c01c0d9ecf3e001518fa86d7ae2a1cf8} (67%) delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/92/d0efd7c1fe3d00151c31fb33fff4337f create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/93/10f3fc0acf3e001518fa86d7ae2a1cf8 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/93/d0f07864d23e001518fa86d7ae2a1cf8 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/94/2033b6d6d13e001518fa86d7ae2a1cf8 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/94/602d1cd1873e00151ce8ff6d4f74dabd delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/95/605f63960d3e00151089cca86c5b1a99 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/95/70d8d329853e00151ce8ff6d4f74dabd create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/96/20ba5e09d43e001518fa86d7ae2a1cf8 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/96/90d42e62e43e001517108d149b613203 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/97/20ad60e0d03e001518fa86d7ae2a1cf8 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/97/8035b5d5df3e001517108d149b613203 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/97/a0aae0bdd23e001518fa86d7ae2a1cf8 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/97/c0e2ad6fce3e001518fa86d7ae2a1cf8 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/98/201af098d03e001518fa86d7ae2a1cf8 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/99/308353a4d93e001517108d149b613203 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/9a/802cbb44dd3e001517108d149b613203 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/9a/90dce6d5ce3e001518fa86d7ae2a1cf8 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/9a/a0aebdacd03e001518fa86d7ae2a1cf8 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/9b/0068cab7e03e001517108d149b613203 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/9c/30bb8899d13e001518fa86d7ae2a1cf8 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/9d/50e1b4b6883e00151ce8ff6d4f74dabd delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/a/705c51af0d3e00151089cca86c5b1a99 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/a/c0191a3f023e00151c31fb33fff4337f delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/a0/f08cfd11853e00151ce8ff6d4f74dabd create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/a1/009afe94e33e001517108d149b613203 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/a1/1035b42cd23e001518fa86d7ae2a1cf8 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/a1/1076adccde3e001517108d149b613203 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/a1/a05e6526d23e001518fa86d7ae2a1cf8 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/a2/206c0ba2d23e001518fa86d7ae2a1cf8 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/a2/20ecb1f0d03e001518fa86d7ae2a1cf8 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/a2/900097abde3e001517108d149b613203 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/a3/00bc291adf3e001517108d149b613203 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/a3/e09f3eb6883e00151ce8ff6d4f74dabd create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/a4/901a3493e03e001517108d149b613203 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/a4/a0f428a3d33e001518fa86d7ae2a1cf8 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/a5/80c576a3de3e001517108d149b613203 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/a6/20f25379dc3e001517108d149b613203 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/a8/006bbef3df3e001517108d149b613203 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/a8/10465292e03e001517108d149b613203 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/a8/a053b075de3e001517108d149b613203 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/a9/40e5b0ce303e00151cbdba8b5f0a340e delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/a9/60ef3b14313e00151cbdba8b5f0a340e create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/aa/40db9018d93e001517108d149b613203 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/aa/a076f09ad33e001518fa86d7ae2a1cf8 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/ac/5065ec8ffe3d00151c31fb33fff4337f delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/ac/f0586fbb843e00151ce8ff6d4f74dabd create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/ad/00f387b8dd3e001517108d149b613203 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/ad/60b39408d43e001518fa86d7ae2a1cf8 rename .metadata/.plugins/org.eclipse.core.resources/.history/{13/602947d9303e00151cbdba8b5f0a340e => ad/c0954ebcce3e001518fa86d7ae2a1cf8} (70%) delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/ad/d05bdac3883e00151ce8ff6d4f74dabd rename .metadata/.plugins/org.eclipse.core.resources/.history/{9e/d0a0364f893e00151ce8ff6d4f74dabd => ae/1023a9f9cc3e001518fa86d7ae2a1cf8} (86%) create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/ae/80773b20e13e001517108d149b613203 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/af/80d63604df3e001517108d149b613203 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/b/301da326cd3e001518fa86d7ae2a1cf8 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/b1/20248930cd3e001518fa86d7ae2a1cf8 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/b1/30440676d03e001518fa86d7ae2a1cf8 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/b3/100a9853d43e001518fa86d7ae2a1cf8 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/b3/c04f9e03ce3e001518fa86d7ae2a1cf8 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/b4/90dba275dd3e001517108d149b613203 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/b5/202ce194d13e001518fa86d7ae2a1cf8 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/b5/40ecd766ce3e001518fa86d7ae2a1cf8 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/b5/c0ca4f18013e00151c31fb33fff4337f rename .metadata/.plugins/org.eclipse.core.resources/.history/{c5/703eba51893e00151ce8ff6d4f74dabd => b6/20667af5cf3e001518fa86d7ae2a1cf8} (83%) delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/b6/504cf350863e00151ce8ff6d4f74dabd delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/b6/90a348520c3e00151089cca86c5b1a99 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/b7/20f6378ed03e001518fa86d7ae2a1cf8 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/b7/b048b351cd3e001518fa86d7ae2a1cf8 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/b8/5051ef26e13e001517108d149b613203 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/b9/0096b9fee03e001517108d149b613203 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/b9/409c8390fe3d00151c31fb33fff4337f delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/b9/50eb23fc013e00151c31fb33fff4337f create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/ba/10207fd7df3e001517108d149b613203 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/ba/70faf280883e00151ce8ff6d4f74dabd delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/bb/60b5d072043e00151c31fb33fff4337f create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/bc/30916f57cf3e001518fa86d7ae2a1cf8 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/bc/a0204038ce3e001518fa86d7ae2a1cf8 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/bc/a099c9afd13e001518fa86d7ae2a1cf8 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/bd/907ef589dd3e001517108d149b613203 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/bd/90d57cb4de3e001517108d149b613203 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/bd/90d70867df3e001517108d149b613203 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/bd/d02b22e3883e00151ce8ff6d4f74dabd delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/be/d0face78043e00151c31fb33fff4337f delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/bf/60a98f74863e00151ce8ff6d4f74dabd create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/bf/a056849fd33e001518fa86d7ae2a1cf8 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/bf/a0d1b862cf3e001518fa86d7ae2a1cf8 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/c/00f451f0df3e001517108d149b613203 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/c/b06ccd99ce3e001518fa86d7ae2a1cf8 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/c0/804c83d7e43e001517108d149b613203 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/c2/20d96d9ad33e001518fa86d7ae2a1cf8 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/c2/30656a8fdc3e001517108d149b613203 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/c3/103cea7ede3e001517108d149b613203 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/c3/50421721013e00151c31fb33fff4337f delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/c4/c0d4e9c9873e00151ce8ff6d4f74dabd create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/c5/30315643d03e001518fa86d7ae2a1cf8 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/c5/9087c2e9de3e001517108d149b613203 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/c5/e0bc896e043e00151c31fb33fff4337f delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/c6/50d2a147883e00151ce8ff6d4f74dabd delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/c6/c0dc5f8ffe3d00151c31fb33fff4337f delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/c6/d022346e043e00151c31fb33fff4337f create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/c7/20873c35da3e001517108d149b613203 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/c7/30e525880d3e00151089cca86c5b1a99 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/c7/d05586b7fe3d00151c31fb33fff4337f delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/c7/e0273ad2843e00151ce8ff6d4f74dabd delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/c7/f00aad3f023e00151c31fb33fff4337f create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/c8/00d17cf2e43e001517108d149b613203 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/c9/005c8f6bdd3e001517108d149b613203 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/c9/d0b1d9a5883e00151ce8ff6d4f74dabd create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/ca/00f60a63df3e001517108d149b613203 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/cb/d058f890873e00151ce8ff6d4f74dabd delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/cc/10d57c5c0d3e00151089cca86c5b1a99 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/cc/b08607c4d23e001518fa86d7ae2a1cf8 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/cd/804ab462df3e001517108d149b613203 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/cd/90837b3cd23e001518fa86d7ae2a1cf8 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/ce/000b95b8e03e001517108d149b613203 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/ce/d00a337efe3d00151c31fb33fff4337f create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/cf/00fa3acadf3e001517108d149b613203 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/cf/10d8879fde3e001517108d149b613203 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/cf/509e01bffe3d00151c31fb33fff4337f create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/d2/204ad69bd03e001518fa86d7ae2a1cf8 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/d2/d0f664fd013e00151c31fb33fff4337f create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/d3/00e70d14e03e001517108d149b613203 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/d5/008e353cdf3e001517108d149b613203 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/d5/50049d01883e00151ce8ff6d4f74dabd create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/d5/9032a867e43e001517108d149b613203 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/d6/0038bc1adf3e001517108d149b613203 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/d6/80ae4e03e13e001517108d149b613203 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/d6/a08b7a0ed03e001518fa86d7ae2a1cf8 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/d6/e0a5b112313e00151cbdba8b5f0a340e delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/d7/5064fb90fe3d00151c31fb33fff4337f create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/d7/a0f61d9bd03e001518fa86d7ae2a1cf8 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/d7/c0293873043e00151c31fb33fff4337f delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/d8/e0a05c04853e00151ce8ff6d4f74dabd delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/d8/f0762d6f043e00151c31fb33fff4337f create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/da/a0d614ced03e001518fa86d7ae2a1cf8 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/da/f088765c0c3e00151089cca86c5b1a99 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/db/600bbc16013e00151c31fb33fff4337f create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/dd/80ebea64dd3e001517108d149b613203 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/df/9064eb98e33e001517108d149b613203 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/df/c06a7eb00d3e00151089cca86c5b1a99 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/e/a0795133d23e001518fa86d7ae2a1cf8 rename .metadata/.plugins/org.eclipse.core.resources/.history/{9d/e0ffd477033e00151c31fb33fff4337f => e0/a07905a5cf3e001518fa86d7ae2a1cf8} (67%) create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/e3/20517c59cf3e001518fa86d7ae2a1cf8 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/e3/80cfda10e03e001517108d149b613203 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/e3/905afa0fe03e001517108d149b613203 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/e4/3060bf8dcf3e001518fa86d7ae2a1cf8 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/e5/a0c874c7303e00151cbdba8b5f0a340e delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/e6/c0b7626f043e00151c31fb33fff4337f delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/e6/d0c6108f083e00151c31fb33fff4337f create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/e8/90448e80dd3e001517108d149b613203 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/ea/40a8228bfe3d00151c31fb33fff4337f create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/eb/3086890bd03e001518fa86d7ae2a1cf8 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/eb/803bcb6fde3e001517108d149b613203 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/eb/80c8e1dade3e001517108d149b613203 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/eb/e0406b19853e00151ce8ff6d4f74dabd delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/ec/d0870f36883e00151ce8ff6d4f74dabd delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/ec/d0cc5971043e00151c31fb33fff4337f delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/ed/d09b59ba873e00151ce8ff6d4f74dabd delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/ee/500395f1873e00151ce8ff6d4f74dabd rename .metadata/.plugins/org.eclipse.core.resources/.history/{c/40594044033e00151c31fb33fff4337f => ef/206bbc9acf3e001518fa86d7ae2a1cf8} (67%) delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/ef/50b12f8f883e00151ce8ff6d4f74dabd delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/ef/d0a65f54873e00151ce8ff6d4f74dabd create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/f/90af968ede3e001517108d149b613203 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/f/a0d81438d33e001518fa86d7ae2a1cf8 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/f/b08c4dd3d13e001518fa86d7ae2a1cf8 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/f/e0df3528853e00151ce8ff6d4f74dabd create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/f1/808b0319df3e001517108d149b613203 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/f2/205fa4c2d03e001518fa86d7ae2a1cf8 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/f2/a0380b49d03e001518fa86d7ae2a1cf8 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/f3/203061bfd23e001518fa86d7ae2a1cf8 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/f3/50ae2f61873e00151ce8ff6d4f74dabd create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/f3/a09a2529d33e001518fa86d7ae2a1cf8 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/f4/206dc8d8d83e001517108d149b613203 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/f4/20d00369d23e001518fa86d7ae2a1cf8 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/f4/5072900e883e00151ce8ff6d4f74dabd create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/f4/80e28d69e43e001517108d149b613203 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/f5/9050bb87de3e001517108d149b613203 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/f8/108fca500c3e00151089cca86c5b1a99 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/f9/a01791b5d13e001518fa86d7ae2a1cf8 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/fa/90ef83b4e03e001517108d149b613203 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/fb/307961d7cf3e001518fa86d7ae2a1cf8 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/fb/503cf63d883e00151ce8ff6d4f74dabd create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/fc/0072fbdce43e001517108d149b613203 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/fc/50e6e65e043e00151c31fb33fff4337f create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/fc/8023f1ece43e001517108d149b613203 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/fd/80351029e13e001517108d149b613203 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/fe/204112ead13e001518fa86d7ae2a1cf8 rename .metadata/.plugins/org.eclipse.core.resources/.history/{a0/d0bbb843893e00151ce8ff6d4f74dabd => ff/a0790ee2cf3e001518fa86d7ae2a1cf8} (85%) delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.root/7.tree create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.root/8.tree 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 create mode 100644 .metadata/.plugins/org.eclipse.ui.workbench.texteditor/dialog_settings.xml diff --git a/.metadata/.log b/.metadata/.log index 9e28562..bda18fc 100644 --- a/.metadata/.log +++ b/.metadata/.log @@ -745,3 +745,50 @@ Contains: Could not delete: D:\Z - Norbi cucca\0 Projektek\TheButtonMCAutoFlairP !MESSAGE Could not delete: D:\Z - Norbi cucca\0 Projektek\TheButtonMCAutoFlairProto\Spigot plugin\TheButtonAutoFlair\bin\tk\sznp. !SUBENTRY 5 org.eclipse.core.filesystem 4 273 2015-08-09 16:10:11.010 !MESSAGE Could not delete: D:\Z - Norbi cucca\0 Projektek\TheButtonMCAutoFlairProto\Spigot plugin\TheButtonAutoFlair\bin\tk. +!SESSION 2015-08-09 20:56:55.150 ----------------------------------------------- +eclipse.buildId=M20130204-1200 +java.version=1.8.0_45 +java.vendor=Oracle Corporation +BootLoader constants: OS=win32, ARCH=x86_64, WS=win32, NL=hu_HU +Framework arguments: -product org.eclipse.epp.package.jee.product +Command-line arguments: -os win32 -ws win32 -arch x86_64 -product org.eclipse.epp.package.jee.product + +!ENTRY org.eclipse.egit.ui 2 0 2015-08-09 20:58:12.223 +!MESSAGE Warning: EGit couldn't detect the installation path "gitPrefix" of native Git. Hence EGit can't respect system level +Git settings which might be configured in ${gitPrefix}/etc/gitconfig under the native Git installation directory. +The most important of these settings is core.autocrlf. Git for Windows by default sets this parameter to true in +this system level configuration. The Git installation location can be configured on the +Team > Git > Configuration preference page's 'System Settings' tab. +This warning can be switched off on the Team > Git > Confirmations and Warnings preference page. + +!ENTRY org.eclipse.egit.ui 2 0 2015-08-09 20:58:12.224 +!MESSAGE Warning: The environment variable HOME is not set. The following directory will be used to store the Git +user global configuration and to define the default location to store repositories: 'C:\Users\Norbi'. If this is +not correct please set the HOME environment variable and restart Eclipse. Otherwise Git for Windows and +EGit might behave differently since they see different configuration options. +This warning can be switched off on the Team > Git > Confirmations and Warnings preference page. +!SESSION 2015-08-09 22:48:23.020 ----------------------------------------------- +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.core.resources 2 10035 2015-08-09 22:49:53.071 +!MESSAGE The workspace exited with unsaved changes in the previous session; refreshing workspace to recover changes. + +!ENTRY org.eclipse.egit.ui 2 0 2015-08-09 22:53:15.430 +!MESSAGE Warning: EGit couldn't detect the installation path "gitPrefix" of native Git. Hence EGit can't respect system level +Git settings which might be configured in ${gitPrefix}/etc/gitconfig under the native Git installation directory. +The most important of these settings is core.autocrlf. Git for Windows by default sets this parameter to true in +this system level configuration. The Git installation location can be configured on the +Team > Git > Configuration preference page's 'System Settings' tab. +This warning can be switched off on the Team > Git > Confirmations and Warnings preference page. + +!ENTRY org.eclipse.egit.ui 2 0 2015-08-09 22:53:15.431 +!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 6b1586551e1b2843915adaef519b0957c1d80657..0bf1e7ee9eca3ba09bd37a6a48e8760eeeae09a7 100644 GIT binary patch delta 28 hcmeyx_=}M@z?+#xgn@&DgJClR*F@fx%phu~BLHMF2O$6e delta 28 hcmeyx_=}M@z?+#xgn@&DgTbqjb0Y6bW)QX05ddWA2TuS1 diff --git a/.metadata/.mylyn/tasks.xml.zip b/.metadata/.mylyn/tasks.xml.zip index 1fcc9a722624e75b3418c642f8e3437513dcb80b..aaeae30096ab3351f6ba3757b2671e0f83bf9562 100644 GIT binary patch delta 28 hcmeyx_=}M@z?+#xgn@&DgF%^@Ya;JTW)QX05dc}W1_uBD delta 28 hcmeyx_=}M@z?+#xgn@&DgJD-Q=S1F>%phu~BLHn%2r~cx diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/0/3027b10cd93e001517108d149b613203 b/.metadata/.plugins/org.eclipse.core.resources/.history/0/3027b10cd93e001517108d149b613203 new file mode 100644 index 0000000..8131160 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/0/3027b10cd93e001517108d149b613203 @@ -0,0 +1,226 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; + +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class Commands implements CommandExecutor { + // This method is called, when somebody uses our command + @Override + public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { + if (sender instanceof Player) { + Player player = (Player) sender; + if(args.length<1) + return false; + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. + //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) + if(p.Flair==null) + { + player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); + return true; + } + switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. + { + case "accept": + { + if(p.IgnoredFlair) + p.IgnoredFlair=false; //2015.08.08. + if(!p.AcceptedFlair) + { + String flair=p.Flair; //2015.08.08. + //PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + PluginMain.AppendPlayerDisplayFlair(p, player); + p.AcceptedFlair=true; //2015.08.08. + player.sendMessage("§6Your flair has been set:§r "+flair); + } + else + player.sendMessage("§cYou already have this user's flair.§r"); + break; + } + case "ignore": + { + if(p.AcceptedFlair) + p.AcceptedFlair=false; //2015.08.08. + if(!p.IgnoredFlair) + { + p.IgnoredFlair=true; + String flair=p.Flair; //2015.08.08. + PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. + player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); + } + else + player.sendMessage("§cYou already ignored this request.§r"); + break; + } + /*case "reload": //2015.07.20. + DoReload(player); + break;*/ + case "admin": //2015.08.09. + DoAdmin(player, args); + break; + case "nonpresser": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§7(non-pr.)§r"; + break; + case "cantpress": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§r(can't press)§r"; + break; + default: + return false; + } + return true; + } + /*if(args[0].toLowerCase()=="reload") + DoReload(null); //2015.07.20.*/ + else if(args.length>0 && args[0].toLowerCase().equals("admin")) //2015.08.09. + { + DoAdmin(null, args); //2015.08.09. + return true; //2015.08.09. + } + return false; + } + private static void DoReload(Player player) + { //2015.07.20. + //if(player==null || player.isOp() || player.getName()=="NorbiPeti") + //{ + try + { + File file=new File("autoflairconfig.txt"); + if(file.exists()) + { + PluginMain.LoadFiles(true); //2015.08.09. + for(Player p : PluginMain.GetPlayers()) + { + MaybeOfflinePlayer mp = MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName()); + if(mp.Flair!=null) + { + String flair=mp.Flair; + PluginMain.RemovePlayerDisplayFlairFinal(p, flair); + //PluginMain.AppendPlayerDisplayFlairFinal(p, flair); + PluginMain.AppendPlayerDisplayFlair(mp, p); //2015.08.09. + } + String msg="§6Note: The auto-flair plugin has been reloaded. You might need to wait 10s to have your flair.§r"; //2015.08.09. + p.sendMessage(msg); //2015.08.09. + } + //String msg="§6Reloaded config file.§r"; + //SendMessage(player, msg); //2015.08.09. + } + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + if(player!=null) + player.sendMessage("§cAn error occured. See console for details.§r"); + PluginMain.LastException=e; //2015.08.09. + } + //} + //else + //player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static Player ReloadPlayer; //2015.08.09. + private static void DoAdmin(Player player, String[] args) + { //2015.08.09. + if(player==null || player.isOp() || player.getName()=="NorbiPeti") + { + //System.out.println("Args length: " + args.length); + if(args.length==1) + { + String message="§cUsage: /u admin reload|playerinfo§r"; + SendMessage(player, message); + return; + } + //args[0] is "admin" + switch(args[1].toLowerCase()) + { + case "reload": + ReloadPlayer=player; //2015.08.09. + SendMessage(player, "§6Make sure to save the current settings before you modify and reload them! Type /u admin confirm when done.§r"); + break; + case "playerinfo": + DoPlayerInfo(player, args); + break; + case "getlasterror": + DoGetLastError(player, args); + case "confirm": + if(ReloadPlayer!=null && ReloadPlayer.equals(player)) + DoReload(player); //2015.08.09. + else + SendMessage(player, "§cYou need to do /u admin reload first.§r"); + break; + case "save": + break; + default: + String message="§cUsage: /u admin reload|playerinfo|getlasterror§r"; + SendMessage(player, message); + return; + } + } + else + player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static void DoPlayerInfo(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "playerinfo" + if(args.length==2) + { + String message="§cUsage: /u admin playerinfo §r"; + SendMessage(player, message); + return; + } + if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2])) + { + String message="§cPlayer not found: "+args[2]+"§r"; + SendMessage(player, message); + return; + } + MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]); + SendMessage(player, "Player name: "+p.PlayerName); + SendMessage(player, "User flair: "+p.Flair); + SendMessage(player, "Username: "+p.UserName); + SendMessage(player, "Flair accepted: "+p.AcceptedFlair); + SendMessage(player, "Flair ignored: "+p.IgnoredFlair); + } + private static void SendMessage(Player player, String message) + { //2015.08.09. + if(player==null) + System.out.println(message); + else + player.sendMessage(message); + } + private static void DoGetLastError(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "getlasterror" + if(PluginMain.LastException!=null) + { + SendMessage(player, "Last error:"); + SendMessage(player, PluginMain.LastException.toString()); + PluginMain.LastException=null; + } + else + SendMessage(player, "There were no exceptions."); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/1/601f8274873e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/1/601f8274873e00151ce8ff6d4f74dabd deleted file mode 100644 index aaa641d..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/1/601f8274873e00151ce8ff6d4f74dabd +++ /dev/null @@ -1,144 +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; - MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. - //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - if(p.Flair==null) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. - { - case "accept": - { - if(p.IgnoredFlair) - p.IgnoredFlair=false; //2015.08.08. - if(!p.AcceptedFlair) - { - String flair=p.Flair; //2015.08.08. - PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. - p.AcceptedFlair=true; //2015.08.08. - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("§cYou already have this user's flair.§r"); - break; - } - case "ignore": - { - if(p.AcceptedFlair) - p.AcceptedFlair=false; //2015.08.08. - if(!p.IgnoredFlair) - { - p.IgnoredFlair=true; - String flair=p.Flair; //2015.08.08. - PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. - player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); - } - else - player.sendMessage("§cYou already ignored this request.§r"); - break; - } - /*case "reload": //2015.07.20. - DoReload(player); - break;*/ - case "admin": //2015.08.09. - DoAdmin(player, args); - break; - default: - return false; - } - return true; - } - - /*if(args[0].toLowerCase()=="reload") - DoReload(null); //2015.07.20.*/ - else if(args[0].toLowerCase()=="admin") - DoAdmin(null, args); //2015.08.09. - return false; - } - private static void DoReload(Player player) - { //2015.07.20. - //if(player==null || player.isOp() || player.getName()=="NorbiPeti") - //{ - try - { - File file=new File("autoflairconfig.txt"); - if(file.exists()) - { - PluginMain.TownColors.clear(); - BufferedReader br=new BufferedReader(new FileReader(file)); - String line; - while((line=br.readLine())!=null) - { - String[] s=line.split(" "); - PluginMain.TownColors.put(s[0], s[1]); - } - br.close(); - for(Player p : PluginMain.GetPlayers()) - { - MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName()); - if(mp.Flair!=null) - { - String flair=mp.Flair; - PluginMain.RemovePlayerDisplayFlairFinal(p, flair); - PluginMain.AppendPlayerDisplayFlairFinal(p, flair); - } - } - String msg="§6Reloaded config file.§r"; - if(player!=null) - player.sendMessage(msg); - else - System.out.println(msg); - } - } - catch(Exception e) - { - System.out.println("Error!\n"+e); - if(player!=null) - player.sendMessage("§cAn error occured. See console for details.§r"); - } - //} - //else - //player.sendMessage("§cYou need to be OP to use this command.§r"); - } - private static void DoAdmin(Player player, String[] args) - { - if(player==null || player.isOp() || player.getName()=="NorbiPeti") - { - //args[0] is "admin" - switch(args[1].toLowerCase()) - { - case "reload": - DoReload(player); - break; - case "playerinfo": - DoPlayerInfo(player, args); - break; - } - } - else - player.sendMessage("§cYou need to be OP to use this command.§r"); - } - private static void DoPlayerInfo(Player player, String[] args) - { - //args[0] is "admin" - args[1] is "playerinfo" - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/1/90ea77eee43e001517108d149b613203 b/.metadata/.plugins/org.eclipse.core.resources/.history/1/90ea77eee43e001517108d149b613203 new file mode 100644 index 0000000..67c0651 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/1/90ea77eee43e001517108d149b613203 @@ -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.Collection; +import java.util.HashMap; +import java.util.Map; + +import org.apache.commons.io.IOUtils; +import org.bukkit.entity.Player; +import org.bukkit.plugin.java.JavaPlugin; +import org.json.JSONArray; +import org.json.JSONObject; + +import com.palmergames.bukkit.towny.object.Town; +import com.palmergames.bukkit.towny.object.WorldCoord; + +public class PluginMain extends JavaPlugin +{ //Translated to Java: 2015.07.15. + //A user, which flair isn't obtainable: + //https://www.reddit.com/r/thebutton/comments/31c32v/i_pressed_the_button_without_really_thinking/ + private static PluginMain Instance; + // Fired when plugin is first enabled + @Override + public void onEnable() + { + System.out.println("The Button Auto-flair Plugin by NorbiPeti (:P)"); + getServer().getPluginManager().registerEvents(new PlayerListener(), this); + this.getCommand("u").setExecutor(new Commands()); + this.getCommand("u").setUsage(this.getCommand("u").getUsage().replace('&', '§')); + Instance=this; //2015.08.08. + LoadFiles(false); //2015.08.09. + Runnable r=new Runnable(){public void run(){ThreadMethod();}}; + Thread t=new Thread(r); + t.start(); + } + Boolean stop=false; + // Fired when plugin is disabled + @Override + public void onDisable() + { + SaveFiles(); //2015.08.09. + stop=true; + } + + public void ThreadMethod() //<-- 2015.07.16. + { + while(!stop) + { + try + { + String body=DownloadString("https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/autoflair_system_comment_your_minecraft_name_and/.json?limit=1000"); + JSONArray json=new JSONArray(body).getJSONObject(1).getJSONObject("data").getJSONArray("children"); + for(Object obj : json) + { + JSONObject item = (JSONObject)obj; + String author=item.getJSONObject("data").getString("author"); + String ign=item.getJSONObject("data").getString("body"); + int start = ign.indexOf("IGN:") + "IGN:".length(); + if(start==-1) + continue; //2015.08.09. + int end = ign.indexOf(' ', start); + if (end == -1 || end == start) + end=ign.indexOf('\n', start); //2015.07.15. + if (end == -1 || end == start) + ign = ign.substring(start); + else + ign = ign.substring(start, end); + ign = ign.trim(); + if(HasIGFlair(ign)) + continue; + try { + Thread.sleep(10); + } catch(InterruptedException ex) { + Thread.currentThread().interrupt(); + } + String[] flairdata = DownloadString("http://karmadecay.com/thebutton-data.php?users=" + author).replace("\"", "").split(":"); + String flair; + if(flairdata.length > 1) //2015.07.15. + flair = flairdata[1]; + else + flair=""; + if (flair != "-1") + flair = flair + "s"; + else + flair = "non-presser"; + String flairclass; + if(flairdata.length>2) + flairclass = flairdata[2]; + else + flairclass="unknown"; + SetFlair(ign, flair, flairclass, author); + } + Thread.sleep(10000); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + } + + public static Exception LastException; //2015.08.09. + + public String DownloadString(String urlstr) throws MalformedURLException, IOException + { + URL url = new URL(urlstr); + URLConnection con = url.openConnection(); + con.setRequestProperty("User-Agent", "TheButtonAutoFlair"); + InputStream in = con.getInputStream(); + String encoding = con.getContentEncoding(); + encoding = encoding == null ? "UTF-8" : encoding; + String body = IOUtils.toString(in, encoding); + in.close(); + return body; + } + + public static Map TownColors=new HashMap(); //2015.07.20. + public Boolean HasIGFlair(String playername) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + return p.Flair!=null; //2015.08.08. + } + + public void SetFlair(String playername, String text, String flairclass, String username) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + String finalflair; + p.FlairDecided=true; + switch(flairclass) + { + case "press-1": + finalflair="§c("+text+")§r"; + break; + case "press-2": + finalflair="§6("+text+")§r"; + break; + case "press-3": + finalflair="§e("+text+")§r"; + break; + case "press-4": + finalflair="§a("+text+")§r"; + break; + case "press-5": + finalflair="§9("+text+")§r"; + break; + 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; + case "undecided": //2015.08.09. + p.FlairDecided=false; + finalflair=""; + break; + default: + finalflair=""; + break; + } + if(finalflair.length()==0) //<-- 2015.07.20. + return; + p.Flair=finalflair; //2015.08.08. + p.UserName=username; //2015.08.08. + System.out.println("Added new flair to "+playername+": "+finalflair); + for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08. + { + if(player.getName().equals(playername)) + { + //AppendPlayerDisplayFlair(player, username, finalflair); + AppendPlayerDisplayFlair(p, player); + break; + } + } + } + + public static String GetFlair(Player player) + { //2015.07.16. + String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08. + return flair==null ? "" : flair; + } + + //public static void AppendPlayerDisplayFlair(Player player, String username, String flair) + public static void AppendPlayerDisplayFlair(MaybeOfflinePlayer player, Player p) //<-- 2015.08.09. + { + + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).IgnoredFlair) + return; + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).AcceptedFlair) + { + AppendPlayerDisplayFlairFinal(p, player.Flair); //2015.07.20. + if(!player.FlairDecided) + p.sendMessage("§9Your flair type is unknown. Are you a non-presser or a can't press? (/u nonpresser or /u cantpress)§r"); //2015.08.09. + } + else + p.sendMessage("§9Are you Reddit user "+player.UserName+"?§r §6Type /u accept or /u ignore§r"); + } + + private static void AppendPlayerDisplayFlairFinal(Player player, String flair) + { //2015.07.20. + String color = GetColorForTown(GetPlayerTown(player)); //TO!DO: Multiple colors put on first capital letters + String[] colors = color.substring(1).split("§"); + String displayname=player.getName(); //2015.08.08. + ArrayList Positions=new ArrayList<>(); + for(int i=0; i=colors.length) + { + int x=0; + for(int i=0; i GetPlayers() + { + return Instance.getServer().getOnlinePlayers(); + } + + public static void LoadFiles(boolean reload) //<-- 2015.08.09. + { + if(reload) + { //2015.08.09. + System.out.println("Auto-flair plugin cleanup for reloading..."); + MaybeOfflinePlayer.AllPlayers.clear(); + TownColors.clear(); + } + System.out.println("Loading files for auto-flair plugin..."); //2015.08.09. + try { + File file=new File("flairsaccepted.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + //System.out.println("Name: " + name); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("flairsignored.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsignored.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("autoflairconfig.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + TownColors.put(s[0], s[1]); + } + br.close(); + } + file=new File("customflairs.txt"); //2015.08.09. + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + MaybeOfflinePlayer.AddPlayerIfNeeded(s[0]).Flair=s[1]; //2015.08.09. + } + br.close(); + } + //throw new IOException("Test"); //2015.08.09. + System.out.println("Auto-flair plugin loaded files!"); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + public static void SaveFiles() //<-- 2015.08.09. + { + try + { + FileWriter fw; + fw = new FileWriter("flairsaccepted.txt"); + fw.close(); + fw = new FileWriter("flairsignored.txt"); + fw.close(); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + try { + File file=new File("flairsaccepted.txt"); + BufferedWriter bw=new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.AcceptedFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + file=new File("flairsignored.txt"); + bw = new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.IgnoredFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + public static boolean RemoveLineFromFile(String file, String line) + { //2015.08.09. + File inputFile = new File(file); + File tempFile = new File("_temp.txt"); + + if(!inputFile.exists()) + return true; + + try { + BufferedReader reader = new BufferedReader(new FileReader(inputFile)); + BufferedWriter writer = new BufferedWriter(new FileWriter(tempFile)); + + String lineToRemove = line; + String currentLine; + + while((currentLine = reader.readLine()) != null) { + // trim newline when comparing with lineToRemove + String trimmedLine = currentLine.trim(); + //if(trimmedLine.equals(lineToRemove)) continue; + if(trimmedLine.contains(lineToRemove)) continue; //2015.08.09. + writer.write(currentLine + System.getProperty("line.separator")); + } + writer.close(); + reader.close(); + return tempFile.renameTo(inputFile); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + return false; + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/1/a0191b15d23e001518fa86d7ae2a1cf8 b/.metadata/.plugins/org.eclipse.core.resources/.history/1/a0191b15d23e001518fa86d7ae2a1cf8 new file mode 100644 index 0000000..85f16ce --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/1/a0191b15d23e001518fa86d7ae2a1cf8 @@ -0,0 +1,374 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStream; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLConnection; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + +import org.apache.commons.io.IOUtils; +import org.bukkit.entity.Player; +import org.bukkit.plugin.java.JavaPlugin; +import org.json.JSONArray; +import org.json.JSONObject; + +import com.palmergames.bukkit.towny.object.Town; +import com.palmergames.bukkit.towny.object.WorldCoord; + +public class PluginMain extends JavaPlugin +{ //Translated to Java: 2015.07.15. + //A user, which flair isn't obtainable: + //https://www.reddit.com/r/thebutton/comments/31c32v/i_pressed_the_button_without_really_thinking/ + private static PluginMain Instance; + // Fired when plugin is first enabled + @Override + public void onEnable() + { + System.out.println("The Button Auto-flair Plugin by NorbiPeti (:P)"); + getServer().getPluginManager().registerEvents(new PlayerListener(), this); + this.getCommand("u").setExecutor(new Commands()); + this.getCommand("u").setUsage(this.getCommand("u").getUsage().replace('&', '§')); + Instance=this; //2015.08.08. + LoadFiles(false); //2015.08.09. + Runnable r=new Runnable(){public void run(){ThreadMethod();}}; + Thread t=new Thread(r); + t.start(); + } + Boolean stop=false; + // Fired when plugin is disabled + @Override + public void onDisable() + { + try + { + FileWriter fw; + fw = new FileWriter("flairsaccepted.txt"); + fw.close(); + fw = new FileWriter("flairsignored.txt"); + fw.close(); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + try { + File file=new File("flairsaccepted.txt"); + BufferedWriter bw=new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.AcceptedFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + file=new File("flairsignored.txt"); + bw = new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.IgnoredFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + stop=true; + } + + public void ThreadMethod() //<-- 2015.07.16. + { + while(!stop) + { + try + { + String body=DownloadString("https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/autoflair_system_comment_your_minecraft_name_and/.json?limit=1000"); + JSONArray json=new JSONArray(body).getJSONObject(1).getJSONObject("data").getJSONArray("children"); + for(Object obj : json) + { + JSONObject item = (JSONObject)obj; + String author=item.getJSONObject("data").getString("author"); + String ign=item.getJSONObject("data").getString("body"); + int start = ign.indexOf("IGN:") + "IGN:".length(); + int end = ign.indexOf(' ', start); + if (end == -1 || end == start) + end=ign.indexOf('\n', start); //2015.07.15. + if (end == -1 || end == start) + ign = ign.substring(start); + else + ign = ign.substring(start, end); + ign = ign.trim(); + if(HasIGFlair(ign)) + continue; + try { + Thread.sleep(10); + } catch(InterruptedException ex) { + Thread.currentThread().interrupt(); + } + String[] flairdata = DownloadString("http://karmadecay.com/thebutton-data.php?users=" + author).replace("\"", "").split(":"); + String flair; + if(flairdata.length > 1) //2015.07.15. + flair = flairdata[1]; + else + flair=""; + if (flair != "-1") + flair = flair + "s"; + else + flair = "non-presser"; + String flairclass; + if(flairdata.length>2) + flairclass = flairdata[2]; + else + flairclass="unknown"; + SetFlair(ign, flair, flairclass, author); + } + Thread.sleep(10000); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + } + + public static Exception LastException; //2015.08.09. + + public String DownloadString(String urlstr) throws MalformedURLException, IOException + { + URL url = new URL(urlstr); + URLConnection con = url.openConnection(); + con.setRequestProperty("User-Agent", "TheButtonAutoFlair"); + InputStream in = con.getInputStream(); + String encoding = con.getContentEncoding(); + encoding = encoding == null ? "UTF-8" : encoding; + String body = IOUtils.toString(in, encoding); + in.close(); + return body; + } + + public static Map TownColors=new HashMap(); //2015.07.20. + public Boolean HasIGFlair(String playername) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + return p.Flair!=null; //2015.08.08. + } + + public void SetFlair(String playername, String text, String flairclass, String username) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + String finalflair; + p.FlairDecided=true; + switch(flairclass) + { + case "press-1": + finalflair="§c("+text+")§r"; + break; + case "press-2": + finalflair="§6("+text+")§r"; + break; + case "press-3": + finalflair="§e("+text+")§r"; + break; + case "press-4": + finalflair="§a("+text+")§r"; + break; + case "press-5": + finalflair="§9("+text+")§r"; + break; + 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; + case "undecided": //2015.08.09. + p.FlairDecided=false; + finalflair=""; + break; + default: + finalflair=""; + break; + } + if(finalflair.length()==0) //<-- 2015.07.20. + return; + p.Flair=finalflair; //2015.08.08. + p.UserName=username; //2015.08.08. + System.out.println("Added new flair to "+playername+": "+finalflair); + for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08. + { + if(player.getName().equals(playername)) + { + //AppendPlayerDisplayFlair(player, username, finalflair); + AppendPlayerDisplayFlair(p, player); + break; + } + } + } + + public static String GetFlair(Player player) + { //2015.07.16. + String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08. + return flair==null ? "" : flair; + } + + //public static void AppendPlayerDisplayFlair(Player player, String username, String flair) + public static void AppendPlayerDisplayFlair(MaybeOfflinePlayer player, Player p) //<-- 2015.08.09. + { + + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).IgnoredFlair) + return; + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).AcceptedFlair) + { + AppendPlayerDisplayFlairFinal(p, player.Flair); //2015.07.20. + if(!player.FlairDecided) + p.sendMessage("§9Your flair type is unknown. Are you a non-presser or a can't press? (/u nonpresser or /u cantpress)§r"); //2015.08.09. + } + else + p.sendMessage("§9Are you Reddit user "+player.UserName+"?§r §6Type /u accept or /u ignore§r"); + } + + private static void AppendPlayerDisplayFlairFinal(Player player, String flair) + { //2015.07.20. + String color = GetColorForTown(GetPlayerTown(player)); //TO!DO: Multiple colors put on first capital letters + String[] colors = color.substring(1).split("§"); + String displayname=player.getName(); //2015.08.08. + ArrayList Positions=new ArrayList<>(); + for(int i=0; i=colors.length) + { + int x=0; + for(int i=0; i GetPlayers() + { + return Instance.getServer().getOnlinePlayers(); + } + + public static void LoadFiles(boolean reload) //<-- 2015.08.09. + { + if(reload) + { + System.out.println("Auto-flair plugin cleanup for reloading..."); //2015.08.09. + MaybeOfflinePlayer.AllPlayers.clear(); //2015.08.09. + } + System.out.println("Loading files for auto-flair plugin..."); //2015.08.09. + try { + File file=new File("flairsaccepted.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + //System.out.println("Name: " + name); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("flairsignored.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsignored.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("autoflairconfig.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + TownColors.put(s[0], s[1]); + } + br.close(); + } + //throw new IOException("Test"); //2015.08.09. + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/1/d071b8d5873e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/1/d071b8d5873e00151ce8ff6d4f74dabd deleted file mode 100644 index aab975f..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/1/d071b8d5873e00151ce8ff6d4f74dabd +++ /dev/null @@ -1,152 +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; - MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. - //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - if(p.Flair==null) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. - { - case "accept": - { - if(p.IgnoredFlair) - p.IgnoredFlair=false; //2015.08.08. - if(!p.AcceptedFlair) - { - String flair=p.Flair; //2015.08.08. - PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. - p.AcceptedFlair=true; //2015.08.08. - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("§cYou already have this user's flair.§r"); - break; - } - case "ignore": - { - if(p.AcceptedFlair) - p.AcceptedFlair=false; //2015.08.08. - if(!p.IgnoredFlair) - { - p.IgnoredFlair=true; - String flair=p.Flair; //2015.08.08. - PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. - player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); - } - else - player.sendMessage("§cYou already ignored this request.§r"); - break; - } - /*case "reload": //2015.07.20. - DoReload(player); - break;*/ - case "admin": //2015.08.09. - DoAdmin(player, args); - break; - default: - return false; - } - return true; - } - - /*if(args[0].toLowerCase()=="reload") - DoReload(null); //2015.07.20.*/ - else if(args[0].toLowerCase()=="admin") - DoAdmin(null, args); //2015.08.09. - return false; - } - private static void DoReload(Player player) - { //2015.07.20. - //if(player==null || player.isOp() || player.getName()=="NorbiPeti") - //{ - try - { - File file=new File("autoflairconfig.txt"); - if(file.exists()) - { - PluginMain.TownColors.clear(); - BufferedReader br=new BufferedReader(new FileReader(file)); - String line; - while((line=br.readLine())!=null) - { - String[] s=line.split(" "); - PluginMain.TownColors.put(s[0], s[1]); - } - br.close(); - for(Player p : PluginMain.GetPlayers()) - { - MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName()); - if(mp.Flair!=null) - { - String flair=mp.Flair; - PluginMain.RemovePlayerDisplayFlairFinal(p, flair); - PluginMain.AppendPlayerDisplayFlairFinal(p, flair); - } - } - String msg="§6Reloaded config file.§r"; - if(player!=null) - player.sendMessage(msg); - else - System.out.println(msg); - } - } - catch(Exception e) - { - System.out.println("Error!\n"+e); - if(player!=null) - player.sendMessage("§cAn error occured. See console for details.§r"); - } - //} - //else - //player.sendMessage("§cYou need to be OP to use this command.§r"); - } - private static void DoAdmin(Player player, String[] args) - { //2015.08.09. - if(player==null || player.isOp() || player.getName()=="NorbiPeti") - { - //args[0] is "admin" - switch(args[1].toLowerCase()) - { - case "reload": - DoReload(player); - break; - case "playerinfo": - DoPlayerInfo(player, args); - break; - } - } - else - player.sendMessage("§cYou need to be OP to use this command.§r"); - } - private static void DoPlayerInfo(Player player, String[] args) - { //2015.08.09. - //args[0] is "admin" - args[1] is "playerinfo" - if(args.length==args[2]) - { - String message="§cUsage: /u admin playerinfo §r"; - if(player==null) - System.out.println(message); - else - player.sendMessage(message); - } - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/1/d0997b1b023e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/1/d0997b1b023e00151c31fb33fff4337f deleted file mode 100644 index 2650c6f..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/1/d0997b1b023e00151c31fb33fff4337f +++ /dev/null @@ -1,125 +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; - 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 deleted file mode 100644 index ee35a22..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/1/f03cfc260d3e00151089cca86c5b1a99 +++ /dev/null @@ -1,434 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import java.io.BufferedReader; -import java.io.BufferedWriter; -import java.io.File; -import java.io.FileReader; -import java.io.FileWriter; -import java.io.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/80fad266df3e001517108d149b613203 b/.metadata/.plugins/org.eclipse.core.resources/.history/10/80fad266df3e001517108d149b613203 new file mode 100644 index 0000000..2a1ad93 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/10/80fad266df3e001517108d149b613203 @@ -0,0 +1,252 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +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; + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. + //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) + if(p.Flair==null) + { + player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); + return true; + } + switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. + { + case "accept": + { + if(p.IgnoredFlair) + p.IgnoredFlair=false; //2015.08.08. + if(!p.AcceptedFlair) + { + String flair=p.Flair; //2015.08.08. + //PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + PluginMain.AppendPlayerDisplayFlair(p, player); + p.AcceptedFlair=true; //2015.08.08. + player.sendMessage("§6Your flair has been set:§r "+flair); + } + else + player.sendMessage("§cYou already have this user's flair.§r"); + break; + } + case "ignore": + { + if(p.AcceptedFlair) + p.AcceptedFlair=false; //2015.08.08. + if(!p.IgnoredFlair) + { + p.IgnoredFlair=true; + String flair=p.Flair; //2015.08.08. + PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. + player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); + } + else + player.sendMessage("§cYou already ignored this request.§r"); + break; + } + /*case "reload": //2015.07.20. + DoReload(player); + break;*/ + case "admin": //2015.08.09. + DoAdmin(player, args); + break; + case "nonpresser": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§7(non-pr.)§r"; + break; + case "cantpress": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§r(can't press)§r"; + break; + default: + return false; + } + return true; + } + /*if(args[0].toLowerCase()=="reload") + DoReload(null); //2015.07.20.*/ + else if(args.length>0 && args[0].toLowerCase().equals("admin")) //2015.08.09. + { + DoAdmin(null, args); //2015.08.09. + return true; //2015.08.09. + } + return false; + } + private static void DoReload(Player player) + { //2015.07.20. + //if(player==null || player.isOp() || player.getName()=="NorbiPeti") + //{ + try + { + File file=new File("autoflairconfig.txt"); + if(file.exists()) + { + PluginMain.LoadFiles(true); //2015.08.09. + for(Player p : PluginMain.GetPlayers()) + { + MaybeOfflinePlayer mp = MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName()); + if(mp.Flair!=null) + { + String flair=mp.Flair; + PluginMain.RemovePlayerDisplayFlairFinal(p, flair); + //PluginMain.AppendPlayerDisplayFlairFinal(p, flair); + PluginMain.AppendPlayerDisplayFlair(mp, p); //2015.08.09. + } + String msg="§6Note: The auto-flair plugin has been reloaded. You might need to wait 10s to have your flair.§r"; //2015.08.09. + p.sendMessage(msg); //2015.08.09. + } + //String msg="§6Reloaded config file.§r"; + //SendMessage(player, msg); //2015.08.09. + } + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + if(player!=null) + player.sendMessage("§cAn error occured. See console for details.§r"); + PluginMain.LastException=e; //2015.08.09. + } + //} + //else + //player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static Player ReloadPlayer; //2015.08.09. + private static void DoAdmin(Player player, String[] args) + { //2015.08.09. + if(player==null || player.isOp() || player.getName()=="NorbiPeti") + { + //System.out.println("Args length: " + args.length); + if(args.length==1) + { + String message="§cUsage: /u admin reload|playerinfo§r"; + SendMessage(player, message); + return; + } + //args[0] is "admin" + switch(args[1].toLowerCase()) + { + case "reload": + ReloadPlayer=player; //2015.08.09. + SendMessage(player, "§6Make sure to save the current settings before you modify and reload them! Type /u admin confirm when done.§r"); + break; + case "playerinfo": + DoPlayerInfo(player, args); + break; + case "getlasterror": + DoGetLastError(player, args); + case "confirm": + if(ReloadPlayer==player) + DoReload(player); //2015.08.09. + else + SendMessage(player, "§cYou need to do /u admin reload first.§r"); + break; + case "save": + PluginMain.SaveFiles(); //2015.08.09. + SendMessage(player, "§6Saved files. Now you can edit them and reload if you want.§r"); + break; + default: + String message="§cUsage: /u admin reload|playerinfo|getlasterror§r"; + SendMessage(player, message); + return; + } + } + else + player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static void DoPlayerInfo(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "playerinfo" + if(args.length==2) + { + String message="§cUsage: /u admin playerinfo §r"; + SendMessage(player, message); + return; + } + if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2])) + { + String message="§cPlayer not found: "+args[2]+"§r"; + SendMessage(player, message); + return; + } + MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]); + SendMessage(player, "Player name: "+p.PlayerName); + SendMessage(player, "User flair: "+p.Flair); + SendMessage(player, "Username: "+p.UserName); + SendMessage(player, "Flair accepted: "+p.AcceptedFlair); + SendMessage(player, "Flair ignored: "+p.IgnoredFlair); + } + private static void SendMessage(Player player, String message) + { //2015.08.09. + if(player==null) + System.out.println(message); + else + player.sendMessage(message); + } + private static void DoGetLastError(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "getlasterror" + if(PluginMain.LastException!=null) + { + SendMessage(player, "Last error:"); + SendMessage(player, PluginMain.LastException.toString()); + PluginMain.LastException=null; + } + else + SendMessage(player, "There were no exceptions."); + } + private static void SetPlayerFlair(Player player, String flair) + { //2015.08.09. + flair=flair.replace('&', '§'); + MaybeOfflinePlayer.AddPlayerIfNeeded(player.getName()).Flair=flair; + if(!PluginMain.RemoveLineFromFile("customflairs.txt")) + { + SendMessage(player, "§cError removing previous custom flair!§r"); + return; + } + File file=new File("customflairs.txt"); + try { + BufferedWriter bw; + bw = new BufferedWriter(new FileWriter(file, true)); + bw.write(player.getName()+"\n"); + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + PluginMain.LastException=e; //2015.08.09. + } + SendMessage(player, "§6The flair has been set. Player: "+player.getName()+" Flair: "+flair+"§r"); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/10/d069a424873e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/10/d069a424873e00151ce8ff6d4f74dabd deleted file mode 100644 index f0c8ce6..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/10/d069a424873e00151ce8ff6d4f74dabd +++ /dev/null @@ -1,136 +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; - MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. - //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - if(p.Flair==null) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. - { - case "accept": - { - if(p.IgnoredFlair) - p.IgnoredFlair=false; //2015.08.08. - if(!p.AcceptedFlair) - { - String flair=p.Flair; //2015.08.08. - PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. - p.AcceptedFlair=true; //2015.08.08. - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("§cYou already have this user's flair.§r"); - break; - } - case "ignore": - { - if(p.AcceptedFlair) - p.AcceptedFlair=false; //2015.08.08. - if(!p.IgnoredFlair) - { - p.IgnoredFlair=true; - String flair=p.Flair; //2015.08.08. - PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. - player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); - } - else - player.sendMessage("§cYou already ignored this request.§r"); - break; - } - /*case "reload": //2015.07.20. - DoReload(player); - break;*/ - case "admin": //2015.08.09. - DoAdmin(player, args); - break; - default: - return false; - } - return true; - } - - /*if(args[0].toLowerCase()=="reload") - DoReload(null); //2015.07.20.*/ - else if(args[0].toLowerCase()=="admin") - DoAdmin(null, args); //2015.08.09. - return false; - } - private static void DoReload(Player player) - { //2015.07.20. - //if(player==null || player.isOp() || player.getName()=="NorbiPeti") - //{ - try - { - File file=new File("autoflairconfig.txt"); - if(file.exists()) - { - PluginMain.TownColors.clear(); - BufferedReader br=new BufferedReader(new FileReader(file)); - String line; - while((line=br.readLine())!=null) - { - String[] s=line.split(" "); - PluginMain.TownColors.put(s[0], s[1]); - } - br.close(); - for(Player p : PluginMain.GetPlayers()) - { - MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName()); - if(mp.Flair!=null) - { - String flair=mp.Flair; - PluginMain.RemovePlayerDisplayFlairFinal(p, flair); - PluginMain.AppendPlayerDisplayFlairFinal(p, flair); - } - } - String msg="§6Reloaded config file.§r"; - if(player!=null) - player.sendMessage(msg); - else - System.out.println(msg); - } - } - catch(Exception e) - { - System.out.println("Error!\n"+e); - if(player!=null) - player.sendMessage("§cAn error occured. See console for details.§r"); - } - //} - //else - //player.sendMessage("§cYou need to be OP to use this command.§r"); - } - private static void DoAdmin(Player player, String[] args) - { - if(player==null || player.isOp() || player.getName()=="NorbiPeti") - { - //args[0] is "admin" - switch(args[1].toLowerCase()) - { - case "reload": - DoReload(); - } - } - else - player.sendMessage("§cYou need to be OP to use this command.§r"); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/11/e02f8f8d083e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/11/e02f8f8d083e00151c31fb33fff4337f deleted file mode 100644 index 4b994f9..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/11/e02f8f8d083e00151c31fb33fff4337f +++ /dev/null @@ -1,126 +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; - 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/10177772dd3e001517108d149b613203 b/.metadata/.plugins/org.eclipse.core.resources/.history/12/10177772dd3e001517108d149b613203 new file mode 100644 index 0000000..9bd5a8e --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/12/10177772dd3e001517108d149b613203 @@ -0,0 +1,409 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStream; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLConnection; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + +import org.apache.commons.io.IOUtils; +import org.bukkit.entity.Player; +import org.bukkit.plugin.java.JavaPlugin; +import org.json.JSONArray; +import org.json.JSONObject; + +import com.palmergames.bukkit.towny.object.Town; +import com.palmergames.bukkit.towny.object.WorldCoord; + +public class PluginMain extends JavaPlugin +{ //Translated to Java: 2015.07.15. + //A user, which flair isn't obtainable: + //https://www.reddit.com/r/thebutton/comments/31c32v/i_pressed_the_button_without_really_thinking/ + private static PluginMain Instance; + // Fired when plugin is first enabled + @Override + public void onEnable() + { + System.out.println("The Button Auto-flair Plugin by NorbiPeti (:P)"); + getServer().getPluginManager().registerEvents(new PlayerListener(), this); + this.getCommand("u").setExecutor(new Commands()); + this.getCommand("u").setUsage(this.getCommand("u").getUsage().replace('&', '§')); + Instance=this; //2015.08.08. + LoadFiles(false); //2015.08.09. + Runnable r=new Runnable(){public void run(){ThreadMethod();}}; + Thread t=new Thread(r); + t.start(); + } + Boolean stop=false; + // Fired when plugin is disabled + @Override + public void onDisable() + { + SaveFiles(); //2015.08.09. + stop=true; + } + + public void ThreadMethod() //<-- 2015.07.16. + { + while(!stop) + { + try + { + String body=DownloadString("https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/autoflair_system_comment_your_minecraft_name_and/.json?limit=1000"); + JSONArray json=new JSONArray(body).getJSONObject(1).getJSONObject("data").getJSONArray("children"); + for(Object obj : json) + { + JSONObject item = (JSONObject)obj; + String author=item.getJSONObject("data").getString("author"); + String ign=item.getJSONObject("data").getString("body"); + int start = ign.indexOf("IGN:") + "IGN:".length(); + if(start==-1) + continue; //2015.08.09. + int end = ign.indexOf(' ', start); + if (end == -1 || end == start) + end=ign.indexOf('\n', start); //2015.07.15. + if (end == -1 || end == start) + ign = ign.substring(start); + else + ign = ign.substring(start, end); + ign = ign.trim(); + if(HasIGFlair(ign)) + continue; + try { + Thread.sleep(10); + } catch(InterruptedException ex) { + Thread.currentThread().interrupt(); + } + String[] flairdata = DownloadString("http://karmadecay.com/thebutton-data.php?users=" + author).replace("\"", "").split(":"); + String flair; + if(flairdata.length > 1) //2015.07.15. + flair = flairdata[1]; + else + flair=""; + if (flair != "-1") + flair = flair + "s"; + else + flair = "non-presser"; + String flairclass; + if(flairdata.length>2) + flairclass = flairdata[2]; + else + flairclass="unknown"; + SetFlair(ign, flair, flairclass, author); + } + Thread.sleep(10000); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + } + + public static Exception LastException; //2015.08.09. + + public String DownloadString(String urlstr) throws MalformedURLException, IOException + { + URL url = new URL(urlstr); + URLConnection con = url.openConnection(); + con.setRequestProperty("User-Agent", "TheButtonAutoFlair"); + InputStream in = con.getInputStream(); + String encoding = con.getContentEncoding(); + encoding = encoding == null ? "UTF-8" : encoding; + String body = IOUtils.toString(in, encoding); + in.close(); + return body; + } + + public static Map TownColors=new HashMap(); //2015.07.20. + public Boolean HasIGFlair(String playername) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + return p.Flair!=null; //2015.08.08. + } + + public void SetFlair(String playername, String text, String flairclass, String username) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + String finalflair; + p.FlairDecided=true; + switch(flairclass) + { + case "press-1": + finalflair="§c("+text+")§r"; + break; + case "press-2": + finalflair="§6("+text+")§r"; + break; + case "press-3": + finalflair="§e("+text+")§r"; + break; + case "press-4": + finalflair="§a("+text+")§r"; + break; + case "press-5": + finalflair="§9("+text+")§r"; + break; + 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; + case "undecided": //2015.08.09. + p.FlairDecided=false; + finalflair=""; + break; + default: + finalflair=""; + break; + } + if(finalflair.length()==0) //<-- 2015.07.20. + return; + p.Flair=finalflair; //2015.08.08. + p.UserName=username; //2015.08.08. + System.out.println("Added new flair to "+playername+": "+finalflair); + for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08. + { + if(player.getName().equals(playername)) + { + //AppendPlayerDisplayFlair(player, username, finalflair); + AppendPlayerDisplayFlair(p, player); + break; + } + } + } + + public static String GetFlair(Player player) + { //2015.07.16. + String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08. + return flair==null ? "" : flair; + } + + //public static void AppendPlayerDisplayFlair(Player player, String username, String flair) + public static void AppendPlayerDisplayFlair(MaybeOfflinePlayer player, Player p) //<-- 2015.08.09. + { + + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).IgnoredFlair) + return; + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).AcceptedFlair) + { + AppendPlayerDisplayFlairFinal(p, player.Flair); //2015.07.20. + if(!player.FlairDecided) + p.sendMessage("§9Your flair type is unknown. Are you a non-presser or a can't press? (/u nonpresser or /u cantpress)§r"); //2015.08.09. + } + else + p.sendMessage("§9Are you Reddit user "+player.UserName+"?§r §6Type /u accept or /u ignore§r"); + } + + private static void AppendPlayerDisplayFlairFinal(Player player, String flair) + { //2015.07.20. + String color = GetColorForTown(GetPlayerTown(player)); //TO!DO: Multiple colors put on first capital letters + String[] colors = color.substring(1).split("§"); + String displayname=player.getName(); //2015.08.08. + ArrayList Positions=new ArrayList<>(); + for(int i=0; i=colors.length) + { + int x=0; + for(int i=0; i GetPlayers() + { + return Instance.getServer().getOnlinePlayers(); + } + + public static void LoadFiles(boolean reload) //<-- 2015.08.09. + { + if(reload) + { //2015.08.09. + System.out.println("Auto-flair plugin cleanup for reloading..."); + MaybeOfflinePlayer.AllPlayers.clear(); + TownColors.clear(); + } + System.out.println("Loading files for auto-flair plugin..."); //2015.08.09. + try { + File file=new File("flairsaccepted.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + //System.out.println("Name: " + name); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("flairsignored.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsignored.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("autoflairconfig.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + TownColors.put(s[0], s[1]); + } + br.close(); + } + file=new File("autoflairdecisions.txt"); //2015.08.09. + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + MaybeOfflinePlayer.AddPlayerIfNeeded(s[0]).Flair=s[1]; //2015.08.09. + } + br.close(); + } + //throw new IOException("Test"); //2015.08.09. + System.out.println("Auto-flair plugin loaded files!"); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + public static void SaveFiles() //<-- 2015.08.09. + { + try + { + FileWriter fw; + fw = new FileWriter("flairsaccepted.txt"); + fw.close(); + fw = new FileWriter("flairsignored.txt"); + fw.close(); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + try { + File file=new File("flairsaccepted.txt"); + BufferedWriter bw=new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.AcceptedFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + file=new File("flairsignored.txt"); + bw = new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.IgnoredFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + public static void SetPlayerFlair(Player + File file=new File("flairsaccepted.txt"); + BufferedWriter bw=new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.AcceptedFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close();, String flair) + { //2015.08.09. + flair=flair.replace('&', '§'); + MaybeOfflinePlayer.AddPlayerIfNeeded(player.getName()).Flair=flair; + + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/12/900059d3e03e001517108d149b613203 b/.metadata/.plugins/org.eclipse.core.resources/.history/12/900059d3e03e001517108d149b613203 new file mode 100644 index 0000000..6ad1625 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/12/900059d3e03e001517108d149b613203 @@ -0,0 +1,264 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +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; + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. + //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) + if(p.Flair==null) + { + player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); + return true; + } + switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. + { + case "accept": + { + if(p.IgnoredFlair) + p.IgnoredFlair=false; //2015.08.08. + if(!p.AcceptedFlair) + { + String flair=p.Flair; //2015.08.08. + //PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + PluginMain.AppendPlayerDisplayFlair(p, player); + p.AcceptedFlair=true; //2015.08.08. + player.sendMessage("§6Your flair has been set:§r "+flair); + } + else + player.sendMessage("§cYou already have this user's flair.§r"); + break; + } + case "ignore": + { + if(p.AcceptedFlair) + p.AcceptedFlair=false; //2015.08.08. + if(!p.IgnoredFlair) + { + p.IgnoredFlair=true; + String flair=p.Flair; //2015.08.08. + PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. + player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); + } + else + player.sendMessage("§cYou already ignored this request.§r"); + break; + } + /*case "reload": //2015.07.20. + DoReload(player); + break;*/ + case "admin": //2015.08.09. + DoAdmin(player, args); + break; + case "nonpresser": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§7(non-pr.)§r"; + break; + case "cantpress": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§r(can't press)§r"; + break; + default: + return false; + } + return true; + } + /*if(args[0].toLowerCase()=="reload") + DoReload(null); //2015.07.20.*/ + else if(args.length>0 && args[0].toLowerCase().equals("admin")) //2015.08.09. + { + DoAdmin(null, args); //2015.08.09. + return true; //2015.08.09. + } + return false; + } + private static void DoReload(Player player) + { //2015.07.20. + //if(player==null || player.isOp() || player.getName()=="NorbiPeti") + //{ + try + { + File file=new File("autoflairconfig.txt"); + if(file.exists()) + { + PluginMain.LoadFiles(true); //2015.08.09. + for(Player p : PluginMain.GetPlayers()) + { + MaybeOfflinePlayer mp = MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName()); + if(mp.Flair!=null) + { + String flair=mp.Flair; + PluginMain.RemovePlayerDisplayFlairFinal(p, flair); + //PluginMain.AppendPlayerDisplayFlairFinal(p, flair); + PluginMain.AppendPlayerDisplayFlair(mp, p); //2015.08.09. + } + String msg="§6Note: The auto-flair plugin has been reloaded. You might need to wait 10s to have your flair.§r"; //2015.08.09. + p.sendMessage(msg); //2015.08.09. + } + //String msg="§6Reloaded config file.§r"; + //SendMessage(player, msg); //2015.08.09. + } + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + if(player!=null) + player.sendMessage("§cAn error occured. See console for details.§r"); + PluginMain.LastException=e; //2015.08.09. + } + //} + //else + //player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static Player ReloadPlayer; //2015.08.09. + private static void DoAdmin(Player player, String[] args) + { //2015.08.09. + if(player==null || player.isOp() || player.getName()=="NorbiPeti") + { + //System.out.println("Args length: " + args.length); + if(args.length==1) + { + String message="§cUsage: /u admin reload|playerinfo§r"; + SendMessage(player, message); + return; + } + //args[0] is "admin" + switch(args[1].toLowerCase()) + { + case "reload": + ReloadPlayer=player; //2015.08.09. + SendMessage(player, "§6Make sure to save the current settings before you modify and reload them! Type /u admin confirm when done.§r"); + break; + case "playerinfo": + DoPlayerInfo(player, args); + break; + case "getlasterror": + DoGetLastError(player, args); + case "confirm": + if(ReloadPlayer==player) + DoReload(player); //2015.08.09. + else + SendMessage(player, "§cYou need to do /u admin reload first.§r"); + break; + case "save": + PluginMain.SaveFiles(); //2015.08.09. + SendMessage(player, "§6Saved files. Now you can edit them and reload if you want.§r"); + break; + case "setflair": + + break; + default: + String message="§cUsage: /u admin reload|playerinfo|getlasterror|save§r"; + SendMessage(player, message); + return; + } + } + else + player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static void DoPlayerInfo(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "playerinfo" + if(args.length==2) + { + String message="§cUsage: /u admin playerinfo §r"; + SendMessage(player, message); + return; + } + if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2])) + { + String message="§cPlayer not found: "+args[2]+"§r"; + SendMessage(player, message); + return; + } + MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]); + SendMessage(player, "Player name: "+p.PlayerName); + SendMessage(player, "User flair: "+p.Flair); + SendMessage(player, "Username: "+p.UserName); + SendMessage(player, "Flair accepted: "+p.AcceptedFlair); + SendMessage(player, "Flair ignored: "+p.IgnoredFlair); + } + private static void SendMessage(Player player, String message) + { //2015.08.09. + if(player==null) + System.out.println(message); + else + player.sendMessage(message); + } + private static void DoGetLastError(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "getlasterror" + if(PluginMain.LastException!=null) + { + SendMessage(player, "Last error:"); + SendMessage(player, PluginMain.LastException.toString()); + PluginMain.LastException=null; + } + else + SendMessage(player, "There were no exceptions."); + } + private static void SetPlayerFlair(Player player, Player targetplayer, String flair) + { //2015.08.09. + flair=flair.replace('&', '§'); + MaybeOfflinePlayer.AddPlayerIfNeeded(player.getName()).Flair=flair; + if(!PluginMain.RemoveLineFromFile("customflairs.txt", targetplayer.getName())) + { + SendMessage(player, "§cError removing previous custom flair!§r"); + return; + } + File file=new File("customflairs.txt"); + try { + BufferedWriter bw; + bw = new BufferedWriter(new FileWriter(file, true)); + bw.write(targetplayer.getName()+"\n"); + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + PluginMain.LastException=e; //2015.08.09. + } + SendMessage(player, "§6The flair has been set. Player: "+targetplayer.getName()+" Flair: "+flair+"§r"); + } + private static void DoSetFlair(Player player, String args) + { + //args[0] is "admin" - args[1] is "setflair" + if(args.length()<4) + { + SendMessage(player, "§cUsage: /u admin setflair "); + return; + } + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/12/90d09f90df3e001517108d149b613203 b/.metadata/.plugins/org.eclipse.core.resources/.history/12/90d09f90df3e001517108d149b613203 new file mode 100644 index 0000000..423d0b9 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/12/90d09f90df3e001517108d149b613203 @@ -0,0 +1,421 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStream; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLConnection; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + +import org.apache.commons.io.IOUtils; +import org.bukkit.entity.Player; +import org.bukkit.plugin.java.JavaPlugin; +import org.json.JSONArray; +import org.json.JSONObject; + +import com.palmergames.bukkit.towny.object.Town; +import com.palmergames.bukkit.towny.object.WorldCoord; + +public class PluginMain extends JavaPlugin +{ //Translated to Java: 2015.07.15. + //A user, which flair isn't obtainable: + //https://www.reddit.com/r/thebutton/comments/31c32v/i_pressed_the_button_without_really_thinking/ + private static PluginMain Instance; + // Fired when plugin is first enabled + @Override + public void onEnable() + { + System.out.println("The Button Auto-flair Plugin by NorbiPeti (:P)"); + getServer().getPluginManager().registerEvents(new PlayerListener(), this); + this.getCommand("u").setExecutor(new Commands()); + this.getCommand("u").setUsage(this.getCommand("u").getUsage().replace('&', '§')); + Instance=this; //2015.08.08. + LoadFiles(false); //2015.08.09. + Runnable r=new Runnable(){public void run(){ThreadMethod();}}; + Thread t=new Thread(r); + t.start(); + } + Boolean stop=false; + // Fired when plugin is disabled + @Override + public void onDisable() + { + SaveFiles(); //2015.08.09. + stop=true; + } + + public void ThreadMethod() //<-- 2015.07.16. + { + while(!stop) + { + try + { + String body=DownloadString("https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/autoflair_system_comment_your_minecraft_name_and/.json?limit=1000"); + JSONArray json=new JSONArray(body).getJSONObject(1).getJSONObject("data").getJSONArray("children"); + for(Object obj : json) + { + JSONObject item = (JSONObject)obj; + String author=item.getJSONObject("data").getString("author"); + String ign=item.getJSONObject("data").getString("body"); + int start = ign.indexOf("IGN:") + "IGN:".length(); + if(start==-1) + continue; //2015.08.09. + int end = ign.indexOf(' ', start); + if (end == -1 || end == start) + end=ign.indexOf('\n', start); //2015.07.15. + if (end == -1 || end == start) + ign = ign.substring(start); + else + ign = ign.substring(start, end); + ign = ign.trim(); + if(HasIGFlair(ign)) + continue; + try { + Thread.sleep(10); + } catch(InterruptedException ex) { + Thread.currentThread().interrupt(); + } + String[] flairdata = DownloadString("http://karmadecay.com/thebutton-data.php?users=" + author).replace("\"", "").split(":"); + String flair; + if(flairdata.length > 1) //2015.07.15. + flair = flairdata[1]; + else + flair=""; + if (flair != "-1") + flair = flair + "s"; + else + flair = "non-presser"; + String flairclass; + if(flairdata.length>2) + flairclass = flairdata[2]; + else + flairclass="unknown"; + SetFlair(ign, flair, flairclass, author); + } + Thread.sleep(10000); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + } + + public static Exception LastException; //2015.08.09. + + public String DownloadString(String urlstr) throws MalformedURLException, IOException + { + URL url = new URL(urlstr); + URLConnection con = url.openConnection(); + con.setRequestProperty("User-Agent", "TheButtonAutoFlair"); + InputStream in = con.getInputStream(); + String encoding = con.getContentEncoding(); + encoding = encoding == null ? "UTF-8" : encoding; + String body = IOUtils.toString(in, encoding); + in.close(); + return body; + } + + public static Map TownColors=new HashMap(); //2015.07.20. + public Boolean HasIGFlair(String playername) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + return p.Flair!=null; //2015.08.08. + } + + public void SetFlair(String playername, String text, String flairclass, String username) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + String finalflair; + p.FlairDecided=true; + switch(flairclass) + { + case "press-1": + finalflair="§c("+text+")§r"; + break; + case "press-2": + finalflair="§6("+text+")§r"; + break; + case "press-3": + finalflair="§e("+text+")§r"; + break; + case "press-4": + finalflair="§a("+text+")§r"; + break; + case "press-5": + finalflair="§9("+text+")§r"; + break; + 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; + case "undecided": //2015.08.09. + p.FlairDecided=false; + finalflair=""; + break; + default: + finalflair=""; + break; + } + if(finalflair.length()==0) //<-- 2015.07.20. + return; + p.Flair=finalflair; //2015.08.08. + p.UserName=username; //2015.08.08. + System.out.println("Added new flair to "+playername+": "+finalflair); + for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08. + { + if(player.getName().equals(playername)) + { + //AppendPlayerDisplayFlair(player, username, finalflair); + AppendPlayerDisplayFlair(p, player); + break; + } + } + } + + public static String GetFlair(Player player) + { //2015.07.16. + String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08. + return flair==null ? "" : flair; + } + + //public static void AppendPlayerDisplayFlair(Player player, String username, String flair) + public static void AppendPlayerDisplayFlair(MaybeOfflinePlayer player, Player p) //<-- 2015.08.09. + { + + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).IgnoredFlair) + return; + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).AcceptedFlair) + { + AppendPlayerDisplayFlairFinal(p, player.Flair); //2015.07.20. + if(!player.FlairDecided) + p.sendMessage("§9Your flair type is unknown. Are you a non-presser or a can't press? (/u nonpresser or /u cantpress)§r"); //2015.08.09. + } + else + p.sendMessage("§9Are you Reddit user "+player.UserName+"?§r §6Type /u accept or /u ignore§r"); + } + + private static void AppendPlayerDisplayFlairFinal(Player player, String flair) + { //2015.07.20. + String color = GetColorForTown(GetPlayerTown(player)); //TO!DO: Multiple colors put on first capital letters + String[] colors = color.substring(1).split("§"); + String displayname=player.getName(); //2015.08.08. + ArrayList Positions=new ArrayList<>(); + for(int i=0; i=colors.length) + { + int x=0; + for(int i=0; i GetPlayers() + { + return Instance.getServer().getOnlinePlayers(); + } + + public static void LoadFiles(boolean reload) //<-- 2015.08.09. + { + if(reload) + { //2015.08.09. + System.out.println("Auto-flair plugin cleanup for reloading..."); + MaybeOfflinePlayer.AllPlayers.clear(); + TownColors.clear(); + } + System.out.println("Loading files for auto-flair plugin..."); //2015.08.09. + try { + File file=new File("flairsaccepted.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + //System.out.println("Name: " + name); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("flairsignored.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsignored.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("autoflairconfig.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + TownColors.put(s[0], s[1]); + } + br.close(); + } + file=new File("customflairs.txt"); //2015.08.09. + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + MaybeOfflinePlayer.AddPlayerIfNeeded(s[0]).Flair=s[1]; //2015.08.09. + } + br.close(); + } + //throw new IOException("Test"); //2015.08.09. + System.out.println("Auto-flair plugin loaded files!"); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + public static void SaveFiles() //<-- 2015.08.09. + { + try + { + FileWriter fw; + fw = new FileWriter("flairsaccepted.txt"); + fw.close(); + fw = new FileWriter("flairsignored.txt"); + fw.close(); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + try { + File file=new File("flairsaccepted.txt"); + BufferedWriter bw=new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.AcceptedFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + file=new File("flairsignored.txt"); + bw = new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.IgnoredFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + public static boolean RemoveLineFromFile(String file, String line) + { + File inputFile = new File(file); + File tempFile = new File("_temp.txt"); + + try { + BufferedReader reader = new BufferedReader(new FileReader(inputFile)); + BufferedWriter writer = new BufferedWriter(new FileWriter(tempFile)); + + String lineToRemove = "bbb"; + String currentLine; + + while((currentLine = reader.readLine()) != null) { + // trim newline when comparing with lineToRemove + String trimmedLine = currentLine.trim(); + if(trimmedLine.equals(lineToRemove)) continue; + writer.write(currentLine + System.getProperty("line.separator")); + } + writer.close(); + reader.close(); + return tempFile.renameTo(inputFile); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + return false; + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/12/b09714c2cf3e001518fa86d7ae2a1cf8 b/.metadata/.plugins/org.eclipse.core.resources/.history/12/b09714c2cf3e001518fa86d7ae2a1cf8 new file mode 100644 index 0000000..206b53a --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/12/b09714c2cf3e001518fa86d7ae2a1cf8 @@ -0,0 +1,362 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStream; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLConnection; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + +import org.apache.commons.io.IOUtils; +import org.bukkit.entity.Player; +import org.bukkit.plugin.java.JavaPlugin; +import org.json.JSONArray; +import org.json.JSONObject; + +import com.palmergames.bukkit.towny.object.Town; +import com.palmergames.bukkit.towny.object.WorldCoord; + +public class PluginMain extends JavaPlugin +{ //Translated to Java: 2015.07.15. + //A user, which flair isn't obtainable: + //https://www.reddit.com/r/thebutton/comments/31c32v/i_pressed_the_button_without_really_thinking/ + private static PluginMain Instance; + // Fired when plugin is first enabled + @Override + public void onEnable() + { + System.out.println("The Button Auto-flair Plugin by NorbiPeti (:P)"); + getServer().getPluginManager().registerEvents(new PlayerListener(), this); + this.getCommand("u").setExecutor(new Commands()); + this.getCommand("u").setUsage(this.getCommand("u").getUsage().replace('&', '§')); + Instance=this; //2015.08.08. + try { + File file=new File("flairsaccepted.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + //System.out.println("Name: " + name); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("flairsignored.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsignored.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("autoflairconfig.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + TownColors.put(s[0], s[1]); + } + br.close(); + } + //throw new IOException("Test"); //2015.08.09. + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + Runnable r=new Runnable(){public void run(){ThreadMethod();}}; + Thread t=new Thread(r); + t.start(); + } + Boolean stop=false; + // Fired when plugin is disabled + @Override + public void onDisable() + { + try + { + FileWriter fw; + fw = new FileWriter("flairsaccepted.txt"); + fw.close(); + fw = new FileWriter("flairsignored.txt"); + fw.close(); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + try { + File file=new File("flairsaccepted.txt"); + BufferedWriter bw=new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.AcceptedFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + file=new File("flairsignored.txt"); + bw = new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.IgnoredFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + stop=true; + } + + public void ThreadMethod() //<-- 2015.07.16. + { + while(!stop) + { + try + { + String body=DownloadString("https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/autoflair_system_comment_your_minecraft_name_and/.json?limit=1000"); + JSONArray json=new JSONArray(body).getJSONObject(1).getJSONObject("data").getJSONArray("children"); + for(Object obj : json) + { + JSONObject item = (JSONObject)obj; + String author=item.getJSONObject("data").getString("author"); + String ign=item.getJSONObject("data").getString("body"); + int start = ign.indexOf("IGN:") + "IGN:".length(); + int end = ign.indexOf(' ', start); + if (end == -1 || end == start) + end=ign.indexOf('\n', start); //2015.07.15. + if (end == -1 || end == start) + ign = ign.substring(start); + else + ign = ign.substring(start, end); + ign = ign.trim(); + if(HasIGFlair(ign)) + continue; + try { + Thread.sleep(10); + } catch(InterruptedException ex) { + Thread.currentThread().interrupt(); + } + String[] flairdata = DownloadString("http://karmadecay.com/thebutton-data.php?users=" + author).replace("\"", "").split(":"); + String flair; + if(flairdata.length > 1) //2015.07.15. + flair = flairdata[1]; + else + flair=""; + if (flair != "-1") + flair = flair + "s"; + else + flair = "non-presser"; + String flairclass; + if(flairdata.length>2) + flairclass = flairdata[2]; + else + flairclass="unknown"; + SetFlair(ign, flair, flairclass, author); + } + Thread.sleep(10000); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + } + + public static Exception LastException; //2015.08.09. + + public String DownloadString(String urlstr) throws MalformedURLException, IOException + { + URL url = new URL(urlstr); + URLConnection con = url.openConnection(); + con.setRequestProperty("User-Agent", "TheButtonAutoFlair"); + InputStream in = con.getInputStream(); + String encoding = con.getContentEncoding(); + encoding = encoding == null ? "UTF-8" : encoding; + String body = IOUtils.toString(in, encoding); + in.close(); + return body; + } + + public static Map TownColors=new HashMap(); //2015.07.20. + public Boolean HasIGFlair(String playername) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + return p.Flair!=null; //2015.08.08. + } + + public void SetFlair(String playername, String text, String flairclass, String username) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + String finalflair; + p.FlairDecided=true; + switch(flairclass) + { + case "press-1": + finalflair="§c("+text+")§r"; + break; + case "press-2": + finalflair="§6("+text+")§r"; + break; + case "press-3": + finalflair="§e("+text+")§r"; + break; + case "press-4": + finalflair="§a("+text+")§r"; + break; + case "press-5": + finalflair="§9("+text+")§r"; + break; + 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; + case "undecided": //2015.08.09. + p.FlairDecided=false; + finalflair=""; + break; + default: + finalflair=""; + break; + } + if(finalflair.length()==0) //<-- 2015.07.20. + return; + p.Flair=finalflair; //2015.08.08. + p.UserName=username; //2015.08.08. + System.out.println("Added new flair to "+playername+": "+finalflair); + for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08. + { + if(player.getName().equals(playername)) + { + AppendPlayerDisplayFlair(player, username, finalflair); + break; + } + } + } + + public static String GetFlair(Player player) + { //2015.07.16. + String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08. + return flair==null ? "" : flair; + } + + //public static void AppendPlayerDisplayFlair(Player player, String username, String flair) + public static void AppendPlayerDisplayFlair(MaybeOfflinePlayer player, Player p) //<-- 2015.08.09. + { + + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).IgnoredFlair) + return; + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).AcceptedFlair) + { + AppendPlayerDisplayFlairFinal(p, player.Flair); //2015.07.20. + if(!player.FlairDecided) + p.sendMessage("§9Your flair type is unknown. Are you a non-presser or a can't press? (/u nonpresser or /u cantpress)§r"); //2015.08.09. + } + else + player.sendMessage("§9Are you Reddit user "+player.UserName+"?§r §6Type /u accept or /u ignore§r"); + } + + private static void AppendPlayerDisplayFlairFinal(Player player, String flair) + { //2015.07.20. + String color = GetColorForTown(GetPlayerTown(player)); //TO!DO: Multiple colors put on first capital letters + String[] colors = color.substring(1).split("§"); + String displayname=player.getName(); //2015.08.08. + ArrayList Positions=new ArrayList<>(); + for(int i=0; i=colors.length) + { + int x=0; + for(int i=0; i GetPlayers() + { + return Instance.getServer().getOnlinePlayers(); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/13/903ca4bcde3e001517108d149b613203 b/.metadata/.plugins/org.eclipse.core.resources/.history/13/903ca4bcde3e001517108d149b613203 new file mode 100644 index 0000000..697a10d --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/13/903ca4bcde3e001517108d149b613203 @@ -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.WorldCoord; + +public class PluginMain extends JavaPlugin +{ //Translated to Java: 2015.07.15. + //A user, which flair isn't obtainable: + //https://www.reddit.com/r/thebutton/comments/31c32v/i_pressed_the_button_without_really_thinking/ + private static PluginMain Instance; + // Fired when plugin is first enabled + @Override + public void onEnable() + { + System.out.println("The Button Auto-flair Plugin by NorbiPeti (:P)"); + getServer().getPluginManager().registerEvents(new PlayerListener(), this); + this.getCommand("u").setExecutor(new Commands()); + this.getCommand("u").setUsage(this.getCommand("u").getUsage().replace('&', '§')); + Instance=this; //2015.08.08. + LoadFiles(false); //2015.08.09. + Runnable r=new Runnable(){public void run(){ThreadMethod();}}; + Thread t=new Thread(r); + t.start(); + } + Boolean stop=false; + // Fired when plugin is disabled + @Override + public void onDisable() + { + SaveFiles(); //2015.08.09. + stop=true; + } + + public void ThreadMethod() //<-- 2015.07.16. + { + while(!stop) + { + try + { + String body=DownloadString("https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/autoflair_system_comment_your_minecraft_name_and/.json?limit=1000"); + JSONArray json=new JSONArray(body).getJSONObject(1).getJSONObject("data").getJSONArray("children"); + for(Object obj : json) + { + JSONObject item = (JSONObject)obj; + String author=item.getJSONObject("data").getString("author"); + String ign=item.getJSONObject("data").getString("body"); + int start = ign.indexOf("IGN:") + "IGN:".length(); + if(start==-1) + continue; //2015.08.09. + int end = ign.indexOf(' ', start); + if (end == -1 || end == start) + end=ign.indexOf('\n', start); //2015.07.15. + if (end == -1 || end == start) + ign = ign.substring(start); + else + ign = ign.substring(start, end); + ign = ign.trim(); + if(HasIGFlair(ign)) + continue; + try { + Thread.sleep(10); + } catch(InterruptedException ex) { + Thread.currentThread().interrupt(); + } + String[] flairdata = DownloadString("http://karmadecay.com/thebutton-data.php?users=" + author).replace("\"", "").split(":"); + String flair; + if(flairdata.length > 1) //2015.07.15. + flair = flairdata[1]; + else + flair=""; + if (flair != "-1") + flair = flair + "s"; + else + flair = "non-presser"; + String flairclass; + if(flairdata.length>2) + flairclass = flairdata[2]; + else + flairclass="unknown"; + SetFlair(ign, flair, flairclass, author); + } + Thread.sleep(10000); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + } + + public static Exception LastException; //2015.08.09. + + public String DownloadString(String urlstr) throws MalformedURLException, IOException + { + URL url = new URL(urlstr); + URLConnection con = url.openConnection(); + con.setRequestProperty("User-Agent", "TheButtonAutoFlair"); + InputStream in = con.getInputStream(); + String encoding = con.getContentEncoding(); + encoding = encoding == null ? "UTF-8" : encoding; + String body = IOUtils.toString(in, encoding); + in.close(); + return body; + } + + public static Map TownColors=new HashMap(); //2015.07.20. + public Boolean HasIGFlair(String playername) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + return p.Flair!=null; //2015.08.08. + } + + public void SetFlair(String playername, String text, String flairclass, String username) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + String finalflair; + p.FlairDecided=true; + switch(flairclass) + { + case "press-1": + finalflair="§c("+text+")§r"; + break; + case "press-2": + finalflair="§6("+text+")§r"; + break; + case "press-3": + finalflair="§e("+text+")§r"; + break; + case "press-4": + finalflair="§a("+text+")§r"; + break; + case "press-5": + finalflair="§9("+text+")§r"; + break; + 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; + case "undecided": //2015.08.09. + p.FlairDecided=false; + finalflair=""; + break; + default: + finalflair=""; + break; + } + if(finalflair.length()==0) //<-- 2015.07.20. + return; + p.Flair=finalflair; //2015.08.08. + p.UserName=username; //2015.08.08. + System.out.println("Added new flair to "+playername+": "+finalflair); + for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08. + { + if(player.getName().equals(playername)) + { + //AppendPlayerDisplayFlair(player, username, finalflair); + AppendPlayerDisplayFlair(p, player); + break; + } + } + } + + public static String GetFlair(Player player) + { //2015.07.16. + String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08. + return flair==null ? "" : flair; + } + + //public static void AppendPlayerDisplayFlair(Player player, String username, String flair) + public static void AppendPlayerDisplayFlair(MaybeOfflinePlayer player, Player p) //<-- 2015.08.09. + { + + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).IgnoredFlair) + return; + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).AcceptedFlair) + { + AppendPlayerDisplayFlairFinal(p, player.Flair); //2015.07.20. + if(!player.FlairDecided) + p.sendMessage("§9Your flair type is unknown. Are you a non-presser or a can't press? (/u nonpresser or /u cantpress)§r"); //2015.08.09. + } + else + p.sendMessage("§9Are you Reddit user "+player.UserName+"?§r §6Type /u accept or /u ignore§r"); + } + + private static void AppendPlayerDisplayFlairFinal(Player player, String flair) + { //2015.07.20. + String color = GetColorForTown(GetPlayerTown(player)); //TO!DO: Multiple colors put on first capital letters + String[] colors = color.substring(1).split("§"); + String displayname=player.getName(); //2015.08.08. + ArrayList Positions=new ArrayList<>(); + for(int i=0; i=colors.length) + { + int x=0; + for(int i=0; i GetPlayers() + { + return Instance.getServer().getOnlinePlayers(); + } + + public static void LoadFiles(boolean reload) //<-- 2015.08.09. + { + if(reload) + { //2015.08.09. + System.out.println("Auto-flair plugin cleanup for reloading..."); + MaybeOfflinePlayer.AllPlayers.clear(); + TownColors.clear(); + } + System.out.println("Loading files for auto-flair plugin..."); //2015.08.09. + try { + File file=new File("flairsaccepted.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + //System.out.println("Name: " + name); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("flairsignored.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsignored.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("autoflairconfig.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + TownColors.put(s[0], s[1]); + } + br.close(); + } + file=new File("customflairs.txt"); //2015.08.09. + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + MaybeOfflinePlayer.AddPlayerIfNeeded(s[0]).Flair=s[1]; //2015.08.09. + } + br.close(); + } + //throw new IOException("Test"); //2015.08.09. + System.out.println("Auto-flair plugin loaded files!"); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + public static void SaveFiles() //<-- 2015.08.09. + { + try + { + FileWriter fw; + fw = new FileWriter("flairsaccepted.txt"); + fw.close(); + fw = new FileWriter("flairsignored.txt"); + fw.close(); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + try { + File file=new File("flairsaccepted.txt"); + BufferedWriter bw=new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.AcceptedFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + file=new File("flairsignored.txt"); + bw = new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.IgnoredFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + public static void SetPlayerFlair(Player player, String flair) + { //2015.08.09. + flair=flair.replace('&', '§'); + MaybeOfflinePlayer.AddPlayerIfNeeded(player.getName()).Flair=flair; + File file=new File("customflairs.txt"); + try { + BufferedWriter bw; + bw = new BufferedWriter(new FileWriter(file, true)); + bw.write(player.getName()+"\n"); + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + public static boolean RemoveLineFromFile(String file) + { + File inputFile = new File(file); + File tempFile = new File("_temp.txt"); + + try { + BufferedReader reader = new BufferedReader(new FileReader(inputFile)); + BufferedWriter writer = new BufferedWriter(new FileWriter(tempFile)); + + String lineToRemove = "bbb"; + String currentLine; + + while((currentLine = reader.readLine()) != null) { + // trim newline when comparing with lineToRemove + String trimmedLine = currentLine.trim(); + if(trimmedLine.equals(lineToRemove)) continue; + writer.write(currentLine + System.getProperty("line.separator")); + } + writer.close(); + reader.close(); + return tempFile.renameTo(inputFile); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + return false; + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/14/20b7f4c2d23e001518fa86d7ae2a1cf8 b/.metadata/.plugins/org.eclipse.core.resources/.history/14/20b7f4c2d23e001518fa86d7ae2a1cf8 new file mode 100644 index 0000000..5cf5c6e --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/14/20b7f4c2d23e001518fa86d7ae2a1cf8 @@ -0,0 +1,215 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; + +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class Commands implements CommandExecutor { + // This method is called, when somebody uses our command + @Override + public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { + if (sender instanceof Player) { + Player player = (Player) sender; + if(args.length<1) + return false; + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. + //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) + if(p.Flair==null) + { + player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); + return true; + } + switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. + { + case "accept": + { + if(p.IgnoredFlair) + p.IgnoredFlair=false; //2015.08.08. + if(!p.AcceptedFlair) + { + String flair=p.Flair; //2015.08.08. + //PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + PluginMain.AppendPlayerDisplayFlair(p, player); + p.AcceptedFlair=true; //2015.08.08. + player.sendMessage("§6Your flair has been set:§r "+flair); + } + else + player.sendMessage("§cYou already have this user's flair.§r"); + break; + } + case "ignore": + { + if(p.AcceptedFlair) + p.AcceptedFlair=false; //2015.08.08. + if(!p.IgnoredFlair) + { + p.IgnoredFlair=true; + String flair=p.Flair; //2015.08.08. + PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. + player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); + } + else + player.sendMessage("§cYou already ignored this request.§r"); + break; + } + /*case "reload": //2015.07.20. + DoReload(player); + break;*/ + case "admin": //2015.08.09. + DoAdmin(player, args); + break; + case "nonpresser": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§7(non-pr.)§r"; + break; + case "cantpress": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§r(can't press)§r"; + break; + default: + return false; + } + return true; + } + /*if(args[0].toLowerCase()=="reload") + DoReload(null); //2015.07.20.*/ + else if(args.length>0 && args[0].toLowerCase().equals("admin")) //2015.08.09. + { + DoAdmin(null, args); //2015.08.09. + return true; //2015.08.09. + } + return false; + } + private static void DoReload(Player player) + { //2015.07.20. + //if(player==null || player.isOp() || player.getName()=="NorbiPeti") + //{ + try + { + File file=new File("autoflairconfig.txt"); + if(file.exists()) + { + PluginMain.LoadFiles(true; + 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); + PluginMain.AppendPlayerDisplayFlair(mp, p); //2015.08.09. + } + } + //String msg="§6Reloaded config file.§r"; + String msg="§6Reloaded all files.§r"; + SendMessage(player, msg); //2015.08.09. + } + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + if(player!=null) + player.sendMessage("§cAn error occured. See console for details.§r"); + PluginMain.LastException=e; //2015.08.09. + } + //} + //else + //player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static void DoAdmin(Player player, String[] args) + { //2015.08.09. + if(player==null || player.isOp() || player.getName()=="NorbiPeti") + { + //System.out.println("Args length: " + args.length); + if(args.length==1) + { + String message="§cUsage: /u admin reload|playerinfo§r"; + SendMessage(player, message); + return; + } + //args[0] is "admin" + switch(args[1].toLowerCase()) + { + case "reload": + DoReload(player); + break; + case "playerinfo": + DoPlayerInfo(player, args); + break; + case "getlasterror": + DoGetLastError(player, args); + default: + String message="§cUsage: /u admin reload|playerinfo§r"; + SendMessage(player, message); + return; + } + } + else + player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static void DoPlayerInfo(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "playerinfo" + if(args.length==2) + { + String message="§cUsage: /u admin playerinfo §r"; + SendMessage(player, message); + return; + } + if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2])) + { + String message="§cPlayer not found: "+args[2]+"§r"; + SendMessage(player, message); + return; + } + MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]); + SendMessage(player, "Player name: "+p.PlayerName); + SendMessage(player, "User flair: "+p.Flair); + SendMessage(player, "Username: "+p.UserName); + SendMessage(player, "Flair accepted: "+p.AcceptedFlair); + SendMessage(player, "Flair ignored: "+p.IgnoredFlair); + } + private static void SendMessage(Player player, String message) + { //2015.08.09. + if(player==null) + System.out.println(message); + else + player.sendMessage(message); + } + private static void DoGetLastError(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "getlasterror" + if(PluginMain.LastException!=null) + { + SendMessage(player, "Last error:"); + SendMessage(player, PluginMain.LastException.toString()); + PluginMain.LastException=null; + } + else + SendMessage(player, "There were no exceptions."); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/15/a0689143d43e001518fa86d7ae2a1cf8 b/.metadata/.plugins/org.eclipse.core.resources/.history/15/a0689143d43e001518fa86d7ae2a1cf8 new file mode 100644 index 0000000..b72f226 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/15/a0689143d43e001518fa86d7ae2a1cf8 @@ -0,0 +1,221 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; + +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class Commands implements CommandExecutor { + // This method is called, when somebody uses our command + @Override + public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { + if (sender instanceof Player) { + Player player = (Player) sender; + if(args.length<1) + return false; + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. + //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) + if(p.Flair==null) + { + player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); + return true; + } + switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. + { + case "accept": + { + if(p.IgnoredFlair) + p.IgnoredFlair=false; //2015.08.08. + if(!p.AcceptedFlair) + { + String flair=p.Flair; //2015.08.08. + //PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + PluginMain.AppendPlayerDisplayFlair(p, player); + p.AcceptedFlair=true; //2015.08.08. + player.sendMessage("§6Your flair has been set:§r "+flair); + } + else + player.sendMessage("§cYou already have this user's flair.§r"); + break; + } + case "ignore": + { + if(p.AcceptedFlair) + p.AcceptedFlair=false; //2015.08.08. + if(!p.IgnoredFlair) + { + p.IgnoredFlair=true; + String flair=p.Flair; //2015.08.08. + PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. + player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); + } + else + player.sendMessage("§cYou already ignored this request.§r"); + break; + } + /*case "reload": //2015.07.20. + DoReload(player); + break;*/ + case "admin": //2015.08.09. + DoAdmin(player, args); + break; + case "nonpresser": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§7(non-pr.)§r"; + break; + case "cantpress": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§r(can't press)§r"; + break; + default: + return false; + } + return true; + } + /*if(args[0].toLowerCase()=="reload") + DoReload(null); //2015.07.20.*/ + else if(args.length>0 && args[0].toLowerCase().equals("admin")) //2015.08.09. + { + DoAdmin(null, args); //2015.08.09. + return true; //2015.08.09. + } + return false; + } + private static void DoReload(Player player) + { //2015.07.20. + //if(player==null || player.isOp() || player.getName()=="NorbiPeti") + //{ + try + { + File file=new File("autoflairconfig.txt"); + if(file.exists()) + { + PluginMain.LoadFiles(true); //2015.08.09. + for(Player p : PluginMain.GetPlayers()) + { + MaybeOfflinePlayer mp = MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName()); + if(mp.Flair!=null) + { + String flair=mp.Flair; + PluginMain.RemovePlayerDisplayFlairFinal(p, flair); + //PluginMain.AppendPlayerDisplayFlairFinal(p, flair); + PluginMain.AppendPlayerDisplayFlair(mp, p); //2015.08.09. + } + String msg="§6Note: The auto-flair plugin has been reloaded. You might need to wait 10s to have your flair.§r"; //2015.08.09. + p.sendMessage(msg); //2015.08.09. + } + //String msg="§6Reloaded config file.§r"; + //SendMessage(player, msg); //2015.08.09. + } + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + if(player!=null) + player.sendMessage("§cAn error occured. See console for details.§r"); + PluginMain.LastException=e; //2015.08.09. + } + //} + //else + //player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static Player ReloadPlayer; //2015.08.09. + private static void DoAdmin(Player player, String[] args) + { //2015.08.09. + if(player==null || player.isOp() || player.getName()=="NorbiPeti") + { + //System.out.println("Args length: " + args.length); + if(args.length==1) + { + String message="§cUsage: /u admin reload|playerinfo§r"; + SendMessage(player, message); + return; + } + //args[0] is "admin" + switch(args[1].toLowerCase()) + { + case "reload": + ReloadPlayer=player; //2015.08.09. + SendMessage(player, "§6Make sure to save the current settings before you modify and reload them! Type /u admin confirm when done."); + break; + case "playerinfo": + DoPlayerInfo(player, args); + break; + case "getlasterror": + DoGetLastError(player, args); + case "confirm": + DoReload(player); //2015.08.09. + break; + default: + String message="§cUsage: /u admin reload|playerinfo§r"; + SendMessage(player, message); + return; + } + } + else + player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static void DoPlayerInfo(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "playerinfo" + if(args.length==2) + { + String message="§cUsage: /u admin playerinfo §r"; + SendMessage(player, message); + return; + } + if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2])) + { + String message="§cPlayer not found: "+args[2]+"§r"; + SendMessage(player, message); + return; + } + MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]); + SendMessage(player, "Player name: "+p.PlayerName); + SendMessage(player, "User flair: "+p.Flair); + SendMessage(player, "Username: "+p.UserName); + SendMessage(player, "Flair accepted: "+p.AcceptedFlair); + SendMessage(player, "Flair ignored: "+p.IgnoredFlair); + } + private static void SendMessage(Player player, String message) + { //2015.08.09. + if(player==null) + System.out.println(message); + else + player.sendMessage(message); + } + private static void DoGetLastError(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "getlasterror" + if(PluginMain.LastException!=null) + { + SendMessage(player, "Last error:"); + SendMessage(player, PluginMain.LastException.toString()); + PluginMain.LastException=null; + } + else + SendMessage(player, "There were no exceptions."); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/15/d05be66e043e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/15/d05be66e043e00151c31fb33fff4337f deleted file mode 100644 index 87c0c13..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/15/d05be66e043e00151c31fb33fff4337f +++ /dev/null @@ -1,126 +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; - 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/90523966df3e001517108d149b613203 b/.metadata/.plugins/org.eclipse.core.resources/.history/16/90523966df3e001517108d149b613203 new file mode 100644 index 0000000..2a1ad93 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/16/90523966df3e001517108d149b613203 @@ -0,0 +1,252 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +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; + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. + //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) + if(p.Flair==null) + { + player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); + return true; + } + switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. + { + case "accept": + { + if(p.IgnoredFlair) + p.IgnoredFlair=false; //2015.08.08. + if(!p.AcceptedFlair) + { + String flair=p.Flair; //2015.08.08. + //PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + PluginMain.AppendPlayerDisplayFlair(p, player); + p.AcceptedFlair=true; //2015.08.08. + player.sendMessage("§6Your flair has been set:§r "+flair); + } + else + player.sendMessage("§cYou already have this user's flair.§r"); + break; + } + case "ignore": + { + if(p.AcceptedFlair) + p.AcceptedFlair=false; //2015.08.08. + if(!p.IgnoredFlair) + { + p.IgnoredFlair=true; + String flair=p.Flair; //2015.08.08. + PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. + player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); + } + else + player.sendMessage("§cYou already ignored this request.§r"); + break; + } + /*case "reload": //2015.07.20. + DoReload(player); + break;*/ + case "admin": //2015.08.09. + DoAdmin(player, args); + break; + case "nonpresser": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§7(non-pr.)§r"; + break; + case "cantpress": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§r(can't press)§r"; + break; + default: + return false; + } + return true; + } + /*if(args[0].toLowerCase()=="reload") + DoReload(null); //2015.07.20.*/ + else if(args.length>0 && args[0].toLowerCase().equals("admin")) //2015.08.09. + { + DoAdmin(null, args); //2015.08.09. + return true; //2015.08.09. + } + return false; + } + private static void DoReload(Player player) + { //2015.07.20. + //if(player==null || player.isOp() || player.getName()=="NorbiPeti") + //{ + try + { + File file=new File("autoflairconfig.txt"); + if(file.exists()) + { + PluginMain.LoadFiles(true); //2015.08.09. + for(Player p : PluginMain.GetPlayers()) + { + MaybeOfflinePlayer mp = MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName()); + if(mp.Flair!=null) + { + String flair=mp.Flair; + PluginMain.RemovePlayerDisplayFlairFinal(p, flair); + //PluginMain.AppendPlayerDisplayFlairFinal(p, flair); + PluginMain.AppendPlayerDisplayFlair(mp, p); //2015.08.09. + } + String msg="§6Note: The auto-flair plugin has been reloaded. You might need to wait 10s to have your flair.§r"; //2015.08.09. + p.sendMessage(msg); //2015.08.09. + } + //String msg="§6Reloaded config file.§r"; + //SendMessage(player, msg); //2015.08.09. + } + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + if(player!=null) + player.sendMessage("§cAn error occured. See console for details.§r"); + PluginMain.LastException=e; //2015.08.09. + } + //} + //else + //player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static Player ReloadPlayer; //2015.08.09. + private static void DoAdmin(Player player, String[] args) + { //2015.08.09. + if(player==null || player.isOp() || player.getName()=="NorbiPeti") + { + //System.out.println("Args length: " + args.length); + if(args.length==1) + { + String message="§cUsage: /u admin reload|playerinfo§r"; + SendMessage(player, message); + return; + } + //args[0] is "admin" + switch(args[1].toLowerCase()) + { + case "reload": + ReloadPlayer=player; //2015.08.09. + SendMessage(player, "§6Make sure to save the current settings before you modify and reload them! Type /u admin confirm when done.§r"); + break; + case "playerinfo": + DoPlayerInfo(player, args); + break; + case "getlasterror": + DoGetLastError(player, args); + case "confirm": + if(ReloadPlayer==player) + DoReload(player); //2015.08.09. + else + SendMessage(player, "§cYou need to do /u admin reload first.§r"); + break; + case "save": + PluginMain.SaveFiles(); //2015.08.09. + SendMessage(player, "§6Saved files. Now you can edit them and reload if you want.§r"); + break; + default: + String message="§cUsage: /u admin reload|playerinfo|getlasterror§r"; + SendMessage(player, message); + return; + } + } + else + player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static void DoPlayerInfo(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "playerinfo" + if(args.length==2) + { + String message="§cUsage: /u admin playerinfo §r"; + SendMessage(player, message); + return; + } + if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2])) + { + String message="§cPlayer not found: "+args[2]+"§r"; + SendMessage(player, message); + return; + } + MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]); + SendMessage(player, "Player name: "+p.PlayerName); + SendMessage(player, "User flair: "+p.Flair); + SendMessage(player, "Username: "+p.UserName); + SendMessage(player, "Flair accepted: "+p.AcceptedFlair); + SendMessage(player, "Flair ignored: "+p.IgnoredFlair); + } + private static void SendMessage(Player player, String message) + { //2015.08.09. + if(player==null) + System.out.println(message); + else + player.sendMessage(message); + } + private static void DoGetLastError(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "getlasterror" + if(PluginMain.LastException!=null) + { + SendMessage(player, "Last error:"); + SendMessage(player, PluginMain.LastException.toString()); + PluginMain.LastException=null; + } + else + SendMessage(player, "There were no exceptions."); + } + private static void SetPlayerFlair(Player player, String flair) + { //2015.08.09. + flair=flair.replace('&', '§'); + MaybeOfflinePlayer.AddPlayerIfNeeded(player.getName()).Flair=flair; + if(!PluginMain.RemoveLineFromFile("customflairs.txt")) + { + SendMessage(player, "§cError removing previous custom flair!§r"); + return; + } + File file=new File("customflairs.txt"); + try { + BufferedWriter bw; + bw = new BufferedWriter(new FileWriter(file, true)); + bw.write(player.getName()+"\n"); + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + PluginMain.LastException=e; //2015.08.09. + } + SendMessage(player, "§6The flair has been set. Player: "+player.getName()+" Flair: "+flair+"§r"); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/17/101a2f29df3e001517108d149b613203 b/.metadata/.plugins/org.eclipse.core.resources/.history/17/101a2f29df3e001517108d149b613203 new file mode 100644 index 0000000..6b55eb2 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/17/101a2f29df3e001517108d149b613203 @@ -0,0 +1,251 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +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; + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. + //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) + if(p.Flair==null) + { + player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); + return true; + } + switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. + { + case "accept": + { + if(p.IgnoredFlair) + p.IgnoredFlair=false; //2015.08.08. + if(!p.AcceptedFlair) + { + String flair=p.Flair; //2015.08.08. + //PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + PluginMain.AppendPlayerDisplayFlair(p, player); + p.AcceptedFlair=true; //2015.08.08. + player.sendMessage("§6Your flair has been set:§r "+flair); + } + else + player.sendMessage("§cYou already have this user's flair.§r"); + break; + } + case "ignore": + { + if(p.AcceptedFlair) + p.AcceptedFlair=false; //2015.08.08. + if(!p.IgnoredFlair) + { + p.IgnoredFlair=true; + String flair=p.Flair; //2015.08.08. + PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. + player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); + } + else + player.sendMessage("§cYou already ignored this request.§r"); + break; + } + /*case "reload": //2015.07.20. + DoReload(player); + break;*/ + case "admin": //2015.08.09. + DoAdmin(player, args); + break; + case "nonpresser": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§7(non-pr.)§r"; + break; + case "cantpress": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§r(can't press)§r"; + break; + default: + return false; + } + return true; + } + /*if(args[0].toLowerCase()=="reload") + DoReload(null); //2015.07.20.*/ + else if(args.length>0 && args[0].toLowerCase().equals("admin")) //2015.08.09. + { + DoAdmin(null, args); //2015.08.09. + return true; //2015.08.09. + } + return false; + } + private static void DoReload(Player player) + { //2015.07.20. + //if(player==null || player.isOp() || player.getName()=="NorbiPeti") + //{ + try + { + File file=new File("autoflairconfig.txt"); + if(file.exists()) + { + PluginMain.LoadFiles(true); //2015.08.09. + for(Player p : PluginMain.GetPlayers()) + { + MaybeOfflinePlayer mp = MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName()); + if(mp.Flair!=null) + { + String flair=mp.Flair; + PluginMain.RemovePlayerDisplayFlairFinal(p, flair); + //PluginMain.AppendPlayerDisplayFlairFinal(p, flair); + PluginMain.AppendPlayerDisplayFlair(mp, p); //2015.08.09. + } + String msg="§6Note: The auto-flair plugin has been reloaded. You might need to wait 10s to have your flair.§r"; //2015.08.09. + p.sendMessage(msg); //2015.08.09. + } + //String msg="§6Reloaded config file.§r"; + //SendMessage(player, msg); //2015.08.09. + } + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + if(player!=null) + player.sendMessage("§cAn error occured. See console for details.§r"); + PluginMain.LastException=e; //2015.08.09. + } + //} + //else + //player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static Player ReloadPlayer; //2015.08.09. + private static void DoAdmin(Player player, String[] args) + { //2015.08.09. + if(player==null || player.isOp() || player.getName()=="NorbiPeti") + { + //System.out.println("Args length: " + args.length); + if(args.length==1) + { + String message="§cUsage: /u admin reload|playerinfo§r"; + SendMessage(player, message); + return; + } + //args[0] is "admin" + switch(args[1].toLowerCase()) + { + case "reload": + ReloadPlayer=player; //2015.08.09. + SendMessage(player, "§6Make sure to save the current settings before you modify and reload them! Type /u admin confirm when done.§r"); + break; + case "playerinfo": + DoPlayerInfo(player, args); + break; + case "getlasterror": + DoGetLastError(player, args); + case "confirm": + if(ReloadPlayer==player) + DoReload(player); //2015.08.09. + else + SendMessage(player, "§cYou need to do /u admin reload first.§r"); + break; + case "save": + PluginMain.SaveFiles(); //2015.08.09. + SendMessage(player, "§6Saved files. Now you can edit them and reload if you want.§r"); + break; + default: + String message="§cUsage: /u admin reload|playerinfo|getlasterror§r"; + SendMessage(player, message); + return; + } + } + else + player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static void DoPlayerInfo(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "playerinfo" + if(args.length==2) + { + String message="§cUsage: /u admin playerinfo §r"; + SendMessage(player, message); + return; + } + if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2])) + { + String message="§cPlayer not found: "+args[2]+"§r"; + SendMessage(player, message); + return; + } + MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]); + SendMessage(player, "Player name: "+p.PlayerName); + SendMessage(player, "User flair: "+p.Flair); + SendMessage(player, "Username: "+p.UserName); + SendMessage(player, "Flair accepted: "+p.AcceptedFlair); + SendMessage(player, "Flair ignored: "+p.IgnoredFlair); + } + private static void SendMessage(Player player, String message) + { //2015.08.09. + if(player==null) + System.out.println(message); + else + player.sendMessage(message); + } + private static void DoGetLastError(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "getlasterror" + if(PluginMain.LastException!=null) + { + SendMessage(player, "Last error:"); + SendMessage(player, PluginMain.LastException.toString()); + PluginMain.LastException=null; + } + else + SendMessage(player, "There were no exceptions."); + } + private static void SetPlayerFlair(Player player, String flair) + { //2015.08.09. + flair=flair.replace('&', '§'); + MaybeOfflinePlayer.AddPlayerIfNeeded(player.getName()).Flair=flair; + if(!PluginMain.RemoveLineFromFile("customflairs.txt")) + { + SendMessage(player, "Error removing previous custom flair!"); + return; + } + File file=new File("customflairs.txt"); + try { + BufferedWriter bw; + bw = new BufferedWriter(new FileWriter(file, true)); + bw.write(player.getName()+"\n"); + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + PluginMain.LastException=e; //2015.08.09. + } + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/19/c0e42302ce3e001518fa86d7ae2a1cf8 b/.metadata/.plugins/org.eclipse.core.resources/.history/19/c0e42302ce3e001518fa86d7ae2a1cf8 new file mode 100644 index 0000000..84912b7 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/19/c0e42302ce3e001518fa86d7ae2a1cf8 @@ -0,0 +1,354 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStream; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLConnection; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + +import org.apache.commons.io.IOUtils; +import org.bukkit.entity.Player; +import org.bukkit.plugin.java.JavaPlugin; +import org.json.JSONArray; +import org.json.JSONObject; + +import com.palmergames.bukkit.towny.object.Town; +import com.palmergames.bukkit.towny.object.WorldCoord; + +public class PluginMain extends JavaPlugin +{ //Translated to Java: 2015.07.15. + //A user, which flair isn't obtainable: + //https://www.reddit.com/r/thebutton/comments/31c32v/i_pressed_the_button_without_really_thinking/ + private static PluginMain Instance; + // Fired when plugin is first enabled + @Override + public void onEnable() + { + System.out.println("The Button Auto-flair Plugin by NorbiPeti (:P)"); + getServer().getPluginManager().registerEvents(new PlayerListener(), this); + this.getCommand("u").setExecutor(new Commands()); + this.getCommand("u").setUsage(this.getCommand("u").getUsage().replace('&', '§')); + Instance=this; //2015.08.08. + try { + File file=new File("flairsaccepted.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + //System.out.println("Name: " + name); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("flairsignored.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsignored.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("autoflairconfig.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + TownColors.put(s[0], s[1]); + } + br.close(); + } + //throw new IOException("Test"); //2015.08.09. + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + Runnable r=new Runnable(){public void run(){ThreadMethod();}}; + Thread t=new Thread(r); + t.start(); + } + Boolean stop=false; + // Fired when plugin is disabled + @Override + public void onDisable() + { + try + { + FileWriter fw; + fw = new FileWriter("flairsaccepted.txt"); + fw.close(); + fw = new FileWriter("flairsignored.txt"); + fw.close(); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + try { + File file=new File("flairsaccepted.txt"); + BufferedWriter bw=new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.AcceptedFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + file=new File("flairsignored.txt"); + bw = new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.IgnoredFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + stop=true; + } + + public void ThreadMethod() //<-- 2015.07.16. + { + while(!stop) + { + try + { + String body=DownloadString("https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/autoflair_system_comment_your_minecraft_name_and/.json?limit=1000"); + JSONArray json=new JSONArray(body).getJSONObject(1).getJSONObject("data").getJSONArray("children"); + for(Object obj : json) + { + JSONObject item = (JSONObject)obj; + String author=item.getJSONObject("data").getString("author"); + String ign=item.getJSONObject("data").getString("body"); + int start = ign.indexOf("IGN:") + "IGN:".length(); + int end = ign.indexOf(' ', start); + if (end == -1 || end == start) + end=ign.indexOf('\n', start); //2015.07.15. + if (end == -1 || end == start) + ign = ign.substring(start); + else + ign = ign.substring(start, end); + ign = ign.trim(); + if(HasIGFlair(ign)) + continue; + try { + Thread.sleep(10); + } catch(InterruptedException ex) { + Thread.currentThread().interrupt(); + } + String[] flairdata = DownloadString("http://karmadecay.com/thebutton-data.php?users=" + author).replace("\"", "").split(":"); + String flair; + if(flairdata.length > 1) //2015.07.15. + flair = flairdata[1]; + else + flair=""; + if (flair != "-1") + flair = flair + "s"; + else + flair = "non-presser"; + String flairclass; + if(flairdata.length>2) + flairclass = flairdata[2]; + else + flairclass="unknown"; + SetFlair(ign, flair, flairclass, author); + } + Thread.sleep(10000); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + } + + public static Exception LastException; //2015.08.09. + + public String DownloadString(String urlstr) throws MalformedURLException, IOException + { + URL url = new URL(urlstr); + URLConnection con = url.openConnection(); + con.setRequestProperty("User-Agent", "TheButtonAutoFlair"); + InputStream in = con.getInputStream(); + String encoding = con.getContentEncoding(); + encoding = encoding == null ? "UTF-8" : encoding; + String body = IOUtils.toString(in, encoding); + in.close(); + return body; + } + + public static Map TownColors=new HashMap(); //2015.07.20. + public Boolean HasIGFlair(String playername) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + return p.Flair!=null; //2015.08.08. + } + + public void SetFlair(String playername, String text, String flairclass, String username) + { + String finalflair; + switch(flairclass) + { + case "press-1": + finalflair="§c("+text+")§r"; + break; + case "press-2": + finalflair="§6("+text+")§r"; + break; + case "press-3": + finalflair="§e("+text+")§r"; + break; + case "press-4": + finalflair="§a("+text+")§r"; + break; + case "press-5": + finalflair="§9("+text+")§r"; + break; + case "press-6": + finalflair="§5("+text+")§r"; + break; + case "no-press": + finalflair="§7(non-pr.)§r"; + break; + case "cheater": + finalflair="§5("+text+")§r"; + break; + case "cant-press": //2015.08.08. + finalflair="§r(can't press)§r"; + break; + case "undecided": + finalflair=""; //2015.08.09. + break; + default: + finalflair=""; + break; + } + if(finalflair.length()==0) //<-- 2015.07.20. + return; + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + p.Flair=finalflair; //2015.08.08. + p.UserName=username; //2015.08.08. + System.out.println("Added new flair to "+playername+": "+finalflair); + for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08. + { + if(player.getName().equals(playername)) + { + AppendPlayerDisplayFlair(player, username, finalflair); + break; + } + } + } + + public static String GetFlair(Player player) + { //2015.07.16. + String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08. + return flair==null ? "" : flair; + } + + public static void AppendPlayerDisplayFlair(Player player, String username, String flair) + { + if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).IgnoredFlair) + return; + if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).AcceptedFlair) + AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + else + player.sendMessage("§9Are you Reddit user "+username+"?§r §6Type /u accept or /u ignore§r"); + } + + public static void AppendPlayerDisplayFlairFinal(Player player, String flair) + { //2015.07.20. + String color = GetColorForTown(GetPlayerTown(player)); //TO!DO: Multiple colors put on first capital letters + String[] colors = color.substring(1).split("§"); + String displayname=player.getName(); //2015.08.08. + ArrayList Positions=new ArrayList<>(); + for(int i=0; i=colors.length) + { + int x=0; + for(int i=0; i GetPlayers() + { + return Instance.getServer().getOnlinePlayers(); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/1a/101bc97ade3e001517108d149b613203 b/.metadata/.plugins/org.eclipse.core.resources/.history/1a/101bc97ade3e001517108d149b613203 new file mode 100644 index 0000000..1398adf --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/1a/101bc97ade3e001517108d149b613203 @@ -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)"); + getServer().getPluginManager().registerEvents(new PlayerListener(), this); + this.getCommand("u").setExecutor(new Commands()); + this.getCommand("u").setUsage(this.getCommand("u").getUsage().replace('&', '§')); + Instance=this; //2015.08.08. + LoadFiles(false); //2015.08.09. + Runnable r=new Runnable(){public void run(){ThreadMethod();}}; + Thread t=new Thread(r); + t.start(); + } + Boolean stop=false; + // Fired when plugin is disabled + @Override + public void onDisable() + { + SaveFiles(); //2015.08.09. + stop=true; + } + + public void ThreadMethod() //<-- 2015.07.16. + { + while(!stop) + { + try + { + String body=DownloadString("https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/autoflair_system_comment_your_minecraft_name_and/.json?limit=1000"); + JSONArray json=new JSONArray(body).getJSONObject(1).getJSONObject("data").getJSONArray("children"); + for(Object obj : json) + { + JSONObject item = (JSONObject)obj; + String author=item.getJSONObject("data").getString("author"); + String ign=item.getJSONObject("data").getString("body"); + int start = ign.indexOf("IGN:") + "IGN:".length(); + if(start==-1) + continue; //2015.08.09. + int end = ign.indexOf(' ', start); + if (end == -1 || end == start) + end=ign.indexOf('\n', start); //2015.07.15. + if (end == -1 || end == start) + ign = ign.substring(start); + else + ign = ign.substring(start, end); + ign = ign.trim(); + if(HasIGFlair(ign)) + continue; + try { + Thread.sleep(10); + } catch(InterruptedException ex) { + Thread.currentThread().interrupt(); + } + String[] flairdata = DownloadString("http://karmadecay.com/thebutton-data.php?users=" + author).replace("\"", "").split(":"); + String flair; + if(flairdata.length > 1) //2015.07.15. + flair = flairdata[1]; + else + flair=""; + if (flair != "-1") + flair = flair + "s"; + else + flair = "non-presser"; + String flairclass; + if(flairdata.length>2) + flairclass = flairdata[2]; + else + flairclass="unknown"; + SetFlair(ign, flair, flairclass, author); + } + Thread.sleep(10000); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + } + + public static Exception LastException; //2015.08.09. + + public String DownloadString(String urlstr) throws MalformedURLException, IOException + { + URL url = new URL(urlstr); + URLConnection con = url.openConnection(); + con.setRequestProperty("User-Agent", "TheButtonAutoFlair"); + InputStream in = con.getInputStream(); + String encoding = con.getContentEncoding(); + encoding = encoding == null ? "UTF-8" : encoding; + String body = IOUtils.toString(in, encoding); + in.close(); + return body; + } + + public static Map TownColors=new HashMap(); //2015.07.20. + public Boolean HasIGFlair(String playername) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + return p.Flair!=null; //2015.08.08. + } + + public void SetFlair(String playername, String text, String flairclass, String username) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + String finalflair; + p.FlairDecided=true; + switch(flairclass) + { + case "press-1": + finalflair="§c("+text+")§r"; + break; + case "press-2": + finalflair="§6("+text+")§r"; + break; + case "press-3": + finalflair="§e("+text+")§r"; + break; + case "press-4": + finalflair="§a("+text+")§r"; + break; + case "press-5": + finalflair="§9("+text+")§r"; + break; + 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; + case "undecided": //2015.08.09. + p.FlairDecided=false; + finalflair=""; + break; + default: + finalflair=""; + break; + } + if(finalflair.length()==0) //<-- 2015.07.20. + return; + p.Flair=finalflair; //2015.08.08. + p.UserName=username; //2015.08.08. + System.out.println("Added new flair to "+playername+": "+finalflair); + for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08. + { + if(player.getName().equals(playername)) + { + //AppendPlayerDisplayFlair(player, username, finalflair); + AppendPlayerDisplayFlair(p, player); + break; + } + } + } + + public static String GetFlair(Player player) + { //2015.07.16. + String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08. + return flair==null ? "" : flair; + } + + //public static void AppendPlayerDisplayFlair(Player player, String username, String flair) + public static void AppendPlayerDisplayFlair(MaybeOfflinePlayer player, Player p) //<-- 2015.08.09. + { + + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).IgnoredFlair) + return; + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).AcceptedFlair) + { + AppendPlayerDisplayFlairFinal(p, player.Flair); //2015.07.20. + if(!player.FlairDecided) + p.sendMessage("§9Your flair type is unknown. Are you a non-presser or a can't press? (/u nonpresser or /u cantpress)§r"); //2015.08.09. + } + else + p.sendMessage("§9Are you Reddit user "+player.UserName+"?§r §6Type /u accept or /u ignore§r"); + } + + private static void AppendPlayerDisplayFlairFinal(Player player, String flair) + { //2015.07.20. + String color = GetColorForTown(GetPlayerTown(player)); //TO!DO: Multiple colors put on first capital letters + String[] colors = color.substring(1).split("§"); + String displayname=player.getName(); //2015.08.08. + ArrayList Positions=new ArrayList<>(); + for(int i=0; i=colors.length) + { + int x=0; + for(int i=0; i GetPlayers() + { + return Instance.getServer().getOnlinePlayers(); + } + + public static void LoadFiles(boolean reload) //<-- 2015.08.09. + { + if(reload) + { //2015.08.09. + System.out.println("Auto-flair plugin cleanup for reloading..."); + MaybeOfflinePlayer.AllPlayers.clear(); + TownColors.clear(); + } + System.out.println("Loading files for auto-flair plugin..."); //2015.08.09. + try { + File file=new File("flairsaccepted.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + //System.out.println("Name: " + name); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("flairsignored.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsignored.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("autoflairconfig.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + TownColors.put(s[0], s[1]); + } + br.close(); + } + file=new File("customflairs.txt"); //2015.08.09. + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + MaybeOfflinePlayer.AddPlayerIfNeeded(s[0]).Flair=s[1]; //2015.08.09. + } + br.close(); + } + //throw new IOException("Test"); //2015.08.09. + System.out.println("Auto-flair plugin loaded files!"); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + public static void SaveFiles() //<-- 2015.08.09. + { + try + { + FileWriter fw; + fw = new FileWriter("flairsaccepted.txt"); + fw.close(); + fw = new FileWriter("flairsignored.txt"); + fw.close(); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + try { + File file=new File("flairsaccepted.txt"); + BufferedWriter bw=new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.AcceptedFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + file=new File("flairsignored.txt"); + bw = new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.IgnoredFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + public static void SetPlayerFlair(Player player, String flair) + { //2015.08.09. + flair=flair.replace('&', '§'); + MaybeOfflinePlayer.AddPlayerIfNeeded(player.getName()).Flair=flair; + File file=new File("customflairs.txt"); + BufferedWriter bw; + try { + bw = new BufferedWriter(new FileWriter(file, true)); + bw.write(player.getName()+"\n"); + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + public static void RemoveLineFromFile(String file) + { + File inputFile = new File("myFile.txt"); + File tempFile = new File("myTempFile.txt"); + + BufferedReader reader = new BufferedReader(new FileReader(inputFile)); + BufferedWriter writer = new BufferedWriter(new FileWriter(tempFile)); + + String lineToRemove = "bbb"; + String currentLine; + + while((currentLine = reader.readLine()) != null) { + // trim newline when comparing with lineToRemove + String trimmedLine = currentLine.trim(); + if(trimmedLine.equals(lineToRemove)) continue; + writer.write(currentLine + System.getProperty("line.separator")); + } + writer.close(); + reader.close(); + boolean successful = tempFile.renameTo(inputFile); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/1a/308e38e1de3e001517108d149b613203 b/.metadata/.plugins/org.eclipse.core.resources/.history/1a/308e38e1de3e001517108d149b613203 new file mode 100644 index 0000000..9e4d66d --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/1a/308e38e1de3e001517108d149b613203 @@ -0,0 +1,440 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStream; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLConnection; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + +import org.apache.commons.io.IOUtils; +import org.bukkit.entity.Player; +import org.bukkit.plugin.java.JavaPlugin; +import org.json.JSONArray; +import org.json.JSONObject; + +import com.palmergames.bukkit.towny.object.Town; +import com.palmergames.bukkit.towny.object.WorldCoord; + +public class PluginMain extends JavaPlugin +{ //Translated to Java: 2015.07.15. + //A user, which flair isn't obtainable: + //https://www.reddit.com/r/thebutton/comments/31c32v/i_pressed_the_button_without_really_thinking/ + private static PluginMain Instance; + // Fired when plugin is first enabled + @Override + public void onEnable() + { + System.out.println("The Button Auto-flair Plugin by NorbiPeti (:P)"); + getServer().getPluginManager().registerEvents(new PlayerListener(), this); + this.getCommand("u").setExecutor(new Commands()); + this.getCommand("u").setUsage(this.getCommand("u").getUsage().replace('&', '§')); + Instance=this; //2015.08.08. + LoadFiles(false); //2015.08.09. + Runnable r=new Runnable(){public void run(){ThreadMethod();}}; + Thread t=new Thread(r); + t.start(); + } + Boolean stop=false; + // Fired when plugin is disabled + @Override + public void onDisable() + { + SaveFiles(); //2015.08.09. + stop=true; + } + + public void ThreadMethod() //<-- 2015.07.16. + { + while(!stop) + { + try + { + String body=DownloadString("https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/autoflair_system_comment_your_minecraft_name_and/.json?limit=1000"); + JSONArray json=new JSONArray(body).getJSONObject(1).getJSONObject("data").getJSONArray("children"); + for(Object obj : json) + { + JSONObject item = (JSONObject)obj; + String author=item.getJSONObject("data").getString("author"); + String ign=item.getJSONObject("data").getString("body"); + int start = ign.indexOf("IGN:") + "IGN:".length(); + if(start==-1) + continue; //2015.08.09. + int end = ign.indexOf(' ', start); + if (end == -1 || end == start) + end=ign.indexOf('\n', start); //2015.07.15. + if (end == -1 || end == start) + ign = ign.substring(start); + else + ign = ign.substring(start, end); + ign = ign.trim(); + if(HasIGFlair(ign)) + continue; + try { + Thread.sleep(10); + } catch(InterruptedException ex) { + Thread.currentThread().interrupt(); + } + String[] flairdata = DownloadString("http://karmadecay.com/thebutton-data.php?users=" + author).replace("\"", "").split(":"); + String flair; + if(flairdata.length > 1) //2015.07.15. + flair = flairdata[1]; + else + flair=""; + if (flair != "-1") + flair = flair + "s"; + else + flair = "non-presser"; + String flairclass; + if(flairdata.length>2) + flairclass = flairdata[2]; + else + flairclass="unknown"; + SetFlair(ign, flair, flairclass, author); + } + Thread.sleep(10000); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + } + + public static Exception LastException; //2015.08.09. + + public String DownloadString(String urlstr) throws MalformedURLException, IOException + { + URL url = new URL(urlstr); + URLConnection con = url.openConnection(); + con.setRequestProperty("User-Agent", "TheButtonAutoFlair"); + InputStream in = con.getInputStream(); + String encoding = con.getContentEncoding(); + encoding = encoding == null ? "UTF-8" : encoding; + String body = IOUtils.toString(in, encoding); + in.close(); + return body; + } + + public static Map TownColors=new HashMap(); //2015.07.20. + public Boolean HasIGFlair(String playername) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + return p.Flair!=null; //2015.08.08. + } + + public void SetFlair(String playername, String text, String flairclass, String username) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + String finalflair; + p.FlairDecided=true; + switch(flairclass) + { + case "press-1": + finalflair="§c("+text+")§r"; + break; + case "press-2": + finalflair="§6("+text+")§r"; + break; + case "press-3": + finalflair="§e("+text+")§r"; + break; + case "press-4": + finalflair="§a("+text+")§r"; + break; + case "press-5": + finalflair="§9("+text+")§r"; + break; + 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; + case "undecided": //2015.08.09. + p.FlairDecided=false; + finalflair=""; + break; + default: + finalflair=""; + break; + } + if(finalflair.length()==0) //<-- 2015.07.20. + return; + p.Flair=finalflair; //2015.08.08. + p.UserName=username; //2015.08.08. + System.out.println("Added new flair to "+playername+": "+finalflair); + for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08. + { + if(player.getName().equals(playername)) + { + //AppendPlayerDisplayFlair(player, username, finalflair); + AppendPlayerDisplayFlair(p, player); + break; + } + } + } + + public static String GetFlair(Player player) + { //2015.07.16. + String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08. + return flair==null ? "" : flair; + } + + //public static void AppendPlayerDisplayFlair(Player player, String username, String flair) + public static void AppendPlayerDisplayFlair(MaybeOfflinePlayer player, Player p) //<-- 2015.08.09. + { + + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).IgnoredFlair) + return; + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).AcceptedFlair) + { + AppendPlayerDisplayFlairFinal(p, player.Flair); //2015.07.20. + if(!player.FlairDecided) + p.sendMessage("§9Your flair type is unknown. Are you a non-presser or a can't press? (/u nonpresser or /u cantpress)§r"); //2015.08.09. + } + else + p.sendMessage("§9Are you Reddit user "+player.UserName+"?§r §6Type /u accept or /u ignore§r"); + } + + private static void AppendPlayerDisplayFlairFinal(Player player, String flair) + { //2015.07.20. + String color = GetColorForTown(GetPlayerTown(player)); //TO!DO: Multiple colors put on first capital letters + String[] colors = color.substring(1).split("§"); + String displayname=player.getName(); //2015.08.08. + ArrayList Positions=new ArrayList<>(); + for(int i=0; i=colors.length) + { + int x=0; + for(int i=0; i GetPlayers() + { + return Instance.getServer().getOnlinePlayers(); + } + + public static void LoadFiles(boolean reload) //<-- 2015.08.09. + { + if(reload) + { //2015.08.09. + System.out.println("Auto-flair plugin cleanup for reloading..."); + MaybeOfflinePlayer.AllPlayers.clear(); + TownColors.clear(); + } + System.out.println("Loading files for auto-flair plugin..."); //2015.08.09. + try { + File file=new File("flairsaccepted.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + //System.out.println("Name: " + name); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("flairsignored.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsignored.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("autoflairconfig.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + TownColors.put(s[0], s[1]); + } + br.close(); + } + file=new File("customflairs.txt"); //2015.08.09. + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + MaybeOfflinePlayer.AddPlayerIfNeeded(s[0]).Flair=s[1]; //2015.08.09. + } + br.close(); + } + //throw new IOException("Test"); //2015.08.09. + System.out.println("Auto-flair plugin loaded files!"); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + public static void SaveFiles() //<-- 2015.08.09. + { + try + { + FileWriter fw; + fw = new FileWriter("flairsaccepted.txt"); + fw.close(); + fw = new FileWriter("flairsignored.txt"); + fw.close(); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + try { + File file=new File("flairsaccepted.txt"); + BufferedWriter bw=new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.AcceptedFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + file=new File("flairsignored.txt"); + bw = new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.IgnoredFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + public static void SetPlayerFlair(Player player, String flair) + { //2015.08.09. + flair=flair.replace('&', '§'); + MaybeOfflinePlayer.AddPlayerIfNeeded(player.getName()).Flair=flair; + if(!RemoveLineFromFile("customflairs.txt")) + { + Commands + } + File file=new File("customflairs.txt"); + try { + BufferedWriter bw; + bw = new BufferedWriter(new FileWriter(file, true)); + bw.write(player.getName()+"\n"); + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + public static boolean RemoveLineFromFile(String file) + { + File inputFile = new File(file); + File tempFile = new File("_temp.txt"); + + try { + BufferedReader reader = new BufferedReader(new FileReader(inputFile)); + BufferedWriter writer = new BufferedWriter(new FileWriter(tempFile)); + + String lineToRemove = "bbb"; + String currentLine; + + while((currentLine = reader.readLine()) != null) { + // trim newline when comparing with lineToRemove + String trimmedLine = currentLine.trim(); + if(trimmedLine.equals(lineToRemove)) continue; + writer.write(currentLine + System.getProperty("line.separator")); + } + writer.close(); + reader.close(); + return tempFile.renameTo(inputFile); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + return false; + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/1b/f0c4a095083e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/1b/f0c4a095083e00151c31fb33fff4337f deleted file mode 100644 index f174b9f..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/1b/f0c4a095083e00151c31fb33fff4337f +++ /dev/null @@ -1,126 +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; - 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/50b35f3bd23e001518fa86d7ae2a1cf8 b/.metadata/.plugins/org.eclipse.core.resources/.history/1c/50b35f3bd23e001518fa86d7ae2a1cf8 new file mode 100644 index 0000000..f15dd12 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/1c/50b35f3bd23e001518fa86d7ae2a1cf8 @@ -0,0 +1,376 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStream; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLConnection; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + +import org.apache.commons.io.IOUtils; +import org.bukkit.entity.Player; +import org.bukkit.plugin.java.JavaPlugin; +import org.json.JSONArray; +import org.json.JSONObject; + +import com.palmergames.bukkit.towny.object.Town; +import com.palmergames.bukkit.towny.object.WorldCoord; + +public class PluginMain extends JavaPlugin +{ //Translated to Java: 2015.07.15. + //A user, which flair isn't obtainable: + //https://www.reddit.com/r/thebutton/comments/31c32v/i_pressed_the_button_without_really_thinking/ + private static PluginMain Instance; + // Fired when plugin is first enabled + @Override + public void onEnable() + { + System.out.println("The Button Auto-flair Plugin by NorbiPeti (:P)"); + getServer().getPluginManager().registerEvents(new PlayerListener(), this); + this.getCommand("u").setExecutor(new Commands()); + this.getCommand("u").setUsage(this.getCommand("u").getUsage().replace('&', '§')); + Instance=this; //2015.08.08. + LoadFiles(false); //2015.08.09. + Runnable r=new Runnable(){public void run(){ThreadMethod();}}; + Thread t=new Thread(r); + t.start(); + } + Boolean stop=false; + // Fired when plugin is disabled + @Override + public void onDisable() + { + try + { + FileWriter fw; + fw = new FileWriter("flairsaccepted.txt"); + fw.close(); + fw = new FileWriter("flairsignored.txt"); + fw.close(); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + try { + File file=new File("flairsaccepted.txt"); + BufferedWriter bw=new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.AcceptedFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + file=new File("flairsignored.txt"); + bw = new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.IgnoredFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + stop=true; + } + + public void ThreadMethod() //<-- 2015.07.16. + { + while(!stop) + { + try + { + String body=DownloadString("https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/autoflair_system_comment_your_minecraft_name_and/.json?limit=1000"); + JSONArray json=new JSONArray(body).getJSONObject(1).getJSONObject("data").getJSONArray("children"); + for(Object obj : json) + { + JSONObject item = (JSONObject)obj; + String author=item.getJSONObject("data").getString("author"); + String ign=item.getJSONObject("data").getString("body"); + int start = ign.indexOf("IGN:") + "IGN:".length(); + int end = ign.indexOf(' ', start); + if (end == -1 || end == start) + end=ign.indexOf('\n', start); //2015.07.15. + if (end == -1 || end == start) + ign = ign.substring(start); + else + ign = ign.substring(start, end); + ign = ign.trim(); + if(HasIGFlair(ign)) + continue; + try { + Thread.sleep(10); + } catch(InterruptedException ex) { + Thread.currentThread().interrupt(); + } + String[] flairdata = DownloadString("http://karmadecay.com/thebutton-data.php?users=" + author).replace("\"", "").split(":"); + String flair; + if(flairdata.length > 1) //2015.07.15. + flair = flairdata[1]; + else + flair=""; + if (flair != "-1") + flair = flair + "s"; + else + flair = "non-presser"; + String flairclass; + if(flairdata.length>2) + flairclass = flairdata[2]; + else + flairclass="unknown"; + SetFlair(ign, flair, flairclass, author); + } + Thread.sleep(10000); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + } + + public static Exception LastException; //2015.08.09. + + public String DownloadString(String urlstr) throws MalformedURLException, IOException + { + URL url = new URL(urlstr); + URLConnection con = url.openConnection(); + con.setRequestProperty("User-Agent", "TheButtonAutoFlair"); + InputStream in = con.getInputStream(); + String encoding = con.getContentEncoding(); + encoding = encoding == null ? "UTF-8" : encoding; + String body = IOUtils.toString(in, encoding); + in.close(); + return body; + } + + public static Map TownColors=new HashMap(); //2015.07.20. + public Boolean HasIGFlair(String playername) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + return p.Flair!=null; //2015.08.08. + } + + public void SetFlair(String playername, String text, String flairclass, String username) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + String finalflair; + p.FlairDecided=true; + switch(flairclass) + { + case "press-1": + finalflair="§c("+text+")§r"; + break; + case "press-2": + finalflair="§6("+text+")§r"; + break; + case "press-3": + finalflair="§e("+text+")§r"; + break; + case "press-4": + finalflair="§a("+text+")§r"; + break; + case "press-5": + finalflair="§9("+text+")§r"; + break; + 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; + case "undecided": //2015.08.09. + p.FlairDecided=false; + finalflair=""; + break; + default: + finalflair=""; + break; + } + if(finalflair.length()==0) //<-- 2015.07.20. + return; + p.Flair=finalflair; //2015.08.08. + p.UserName=username; //2015.08.08. + System.out.println("Added new flair to "+playername+": "+finalflair); + for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08. + { + if(player.getName().equals(playername)) + { + //AppendPlayerDisplayFlair(player, username, finalflair); + AppendPlayerDisplayFlair(p, player); + break; + } + } + } + + public static String GetFlair(Player player) + { //2015.07.16. + String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08. + return flair==null ? "" : flair; + } + + //public static void AppendPlayerDisplayFlair(Player player, String username, String flair) + public static void AppendPlayerDisplayFlair(MaybeOfflinePlayer player, Player p) //<-- 2015.08.09. + { + + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).IgnoredFlair) + return; + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).AcceptedFlair) + { + AppendPlayerDisplayFlairFinal(p, player.Flair); //2015.07.20. + if(!player.FlairDecided) + p.sendMessage("§9Your flair type is unknown. Are you a non-presser or a can't press? (/u nonpresser or /u cantpress)§r"); //2015.08.09. + } + else + p.sendMessage("§9Are you Reddit user "+player.UserName+"?§r §6Type /u accept or /u ignore§r"); + } + + private static void AppendPlayerDisplayFlairFinal(Player player, String flair) + { //2015.07.20. + String color = GetColorForTown(GetPlayerTown(player)); //TO!DO: Multiple colors put on first capital letters + String[] colors = color.substring(1).split("§"); + String displayname=player.getName(); //2015.08.08. + ArrayList Positions=new ArrayList<>(); + for(int i=0; i=colors.length) + { + int x=0; + for(int i=0; i GetPlayers() + { + return Instance.getServer().getOnlinePlayers(); + } + + public static void LoadFiles(boolean reload) //<-- 2015.08.09. + { + if(reload) + { //2015.08.09. + System.out.println("Auto-flair plugin cleanup for reloading..."); + MaybeOfflinePlayer.AllPlayers.clear(); + TownColors.clear(); + } + System.out.println("Loading files for auto-flair plugin..."); //2015.08.09. + try { + File file=new File("flairsaccepted.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + //System.out.println("Name: " + name); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("flairsignored.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsignored.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("autoflairconfig.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + TownColors.put(s[0], s[1]); + } + br.close(); + } + //throw new IOException("Test"); //2015.08.09. + System.out.println("Auto-flair plugin loaded files!"); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/1c/609377ad0d3e00151089cca86c5b1a99 b/.metadata/.plugins/org.eclipse.core.resources/.history/1c/609377ad0d3e00151089cca86c5b1a99 deleted file mode 100644 index 752fdf8..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/1c/609377ad0d3e00151089cca86c5b1a99 +++ /dev/null @@ -1,437 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import java.io.BufferedReader; -import java.io.BufferedWriter; -import java.io.File; -import java.io.FileReader; -import java.io.FileWriter; -import java.io.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/a0ecf93ad23e001518fa86d7ae2a1cf8 b/.metadata/.plugins/org.eclipse.core.resources/.history/1c/a0ecf93ad23e001518fa86d7ae2a1cf8 new file mode 100644 index 0000000..f15dd12 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/1c/a0ecf93ad23e001518fa86d7ae2a1cf8 @@ -0,0 +1,376 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStream; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLConnection; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + +import org.apache.commons.io.IOUtils; +import org.bukkit.entity.Player; +import org.bukkit.plugin.java.JavaPlugin; +import org.json.JSONArray; +import org.json.JSONObject; + +import com.palmergames.bukkit.towny.object.Town; +import com.palmergames.bukkit.towny.object.WorldCoord; + +public class PluginMain extends JavaPlugin +{ //Translated to Java: 2015.07.15. + //A user, which flair isn't obtainable: + //https://www.reddit.com/r/thebutton/comments/31c32v/i_pressed_the_button_without_really_thinking/ + private static PluginMain Instance; + // Fired when plugin is first enabled + @Override + public void onEnable() + { + System.out.println("The Button Auto-flair Plugin by NorbiPeti (:P)"); + getServer().getPluginManager().registerEvents(new PlayerListener(), this); + this.getCommand("u").setExecutor(new Commands()); + this.getCommand("u").setUsage(this.getCommand("u").getUsage().replace('&', '§')); + Instance=this; //2015.08.08. + LoadFiles(false); //2015.08.09. + Runnable r=new Runnable(){public void run(){ThreadMethod();}}; + Thread t=new Thread(r); + t.start(); + } + Boolean stop=false; + // Fired when plugin is disabled + @Override + public void onDisable() + { + try + { + FileWriter fw; + fw = new FileWriter("flairsaccepted.txt"); + fw.close(); + fw = new FileWriter("flairsignored.txt"); + fw.close(); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + try { + File file=new File("flairsaccepted.txt"); + BufferedWriter bw=new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.AcceptedFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + file=new File("flairsignored.txt"); + bw = new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.IgnoredFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + stop=true; + } + + public void ThreadMethod() //<-- 2015.07.16. + { + while(!stop) + { + try + { + String body=DownloadString("https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/autoflair_system_comment_your_minecraft_name_and/.json?limit=1000"); + JSONArray json=new JSONArray(body).getJSONObject(1).getJSONObject("data").getJSONArray("children"); + for(Object obj : json) + { + JSONObject item = (JSONObject)obj; + String author=item.getJSONObject("data").getString("author"); + String ign=item.getJSONObject("data").getString("body"); + int start = ign.indexOf("IGN:") + "IGN:".length(); + int end = ign.indexOf(' ', start); + if (end == -1 || end == start) + end=ign.indexOf('\n', start); //2015.07.15. + if (end == -1 || end == start) + ign = ign.substring(start); + else + ign = ign.substring(start, end); + ign = ign.trim(); + if(HasIGFlair(ign)) + continue; + try { + Thread.sleep(10); + } catch(InterruptedException ex) { + Thread.currentThread().interrupt(); + } + String[] flairdata = DownloadString("http://karmadecay.com/thebutton-data.php?users=" + author).replace("\"", "").split(":"); + String flair; + if(flairdata.length > 1) //2015.07.15. + flair = flairdata[1]; + else + flair=""; + if (flair != "-1") + flair = flair + "s"; + else + flair = "non-presser"; + String flairclass; + if(flairdata.length>2) + flairclass = flairdata[2]; + else + flairclass="unknown"; + SetFlair(ign, flair, flairclass, author); + } + Thread.sleep(10000); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + } + + public static Exception LastException; //2015.08.09. + + public String DownloadString(String urlstr) throws MalformedURLException, IOException + { + URL url = new URL(urlstr); + URLConnection con = url.openConnection(); + con.setRequestProperty("User-Agent", "TheButtonAutoFlair"); + InputStream in = con.getInputStream(); + String encoding = con.getContentEncoding(); + encoding = encoding == null ? "UTF-8" : encoding; + String body = IOUtils.toString(in, encoding); + in.close(); + return body; + } + + public static Map TownColors=new HashMap(); //2015.07.20. + public Boolean HasIGFlair(String playername) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + return p.Flair!=null; //2015.08.08. + } + + public void SetFlair(String playername, String text, String flairclass, String username) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + String finalflair; + p.FlairDecided=true; + switch(flairclass) + { + case "press-1": + finalflair="§c("+text+")§r"; + break; + case "press-2": + finalflair="§6("+text+")§r"; + break; + case "press-3": + finalflair="§e("+text+")§r"; + break; + case "press-4": + finalflair="§a("+text+")§r"; + break; + case "press-5": + finalflair="§9("+text+")§r"; + break; + 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; + case "undecided": //2015.08.09. + p.FlairDecided=false; + finalflair=""; + break; + default: + finalflair=""; + break; + } + if(finalflair.length()==0) //<-- 2015.07.20. + return; + p.Flair=finalflair; //2015.08.08. + p.UserName=username; //2015.08.08. + System.out.println("Added new flair to "+playername+": "+finalflair); + for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08. + { + if(player.getName().equals(playername)) + { + //AppendPlayerDisplayFlair(player, username, finalflair); + AppendPlayerDisplayFlair(p, player); + break; + } + } + } + + public static String GetFlair(Player player) + { //2015.07.16. + String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08. + return flair==null ? "" : flair; + } + + //public static void AppendPlayerDisplayFlair(Player player, String username, String flair) + public static void AppendPlayerDisplayFlair(MaybeOfflinePlayer player, Player p) //<-- 2015.08.09. + { + + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).IgnoredFlair) + return; + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).AcceptedFlair) + { + AppendPlayerDisplayFlairFinal(p, player.Flair); //2015.07.20. + if(!player.FlairDecided) + p.sendMessage("§9Your flair type is unknown. Are you a non-presser or a can't press? (/u nonpresser or /u cantpress)§r"); //2015.08.09. + } + else + p.sendMessage("§9Are you Reddit user "+player.UserName+"?§r §6Type /u accept or /u ignore§r"); + } + + private static void AppendPlayerDisplayFlairFinal(Player player, String flair) + { //2015.07.20. + String color = GetColorForTown(GetPlayerTown(player)); //TO!DO: Multiple colors put on first capital letters + String[] colors = color.substring(1).split("§"); + String displayname=player.getName(); //2015.08.08. + ArrayList Positions=new ArrayList<>(); + for(int i=0; i=colors.length) + { + int x=0; + for(int i=0; i GetPlayers() + { + return Instance.getServer().getOnlinePlayers(); + } + + public static void LoadFiles(boolean reload) //<-- 2015.08.09. + { + if(reload) + { //2015.08.09. + System.out.println("Auto-flair plugin cleanup for reloading..."); + MaybeOfflinePlayer.AllPlayers.clear(); + TownColors.clear(); + } + System.out.println("Loading files for auto-flair plugin..."); //2015.08.09. + try { + File file=new File("flairsaccepted.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + //System.out.println("Name: " + name); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("flairsignored.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsignored.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("autoflairconfig.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + TownColors.put(s[0], s[1]); + } + br.close(); + } + //throw new IOException("Test"); //2015.08.09. + System.out.println("Auto-flair plugin loaded files!"); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/1e/20ce3447d43e001518fa86d7ae2a1cf8 b/.metadata/.plugins/org.eclipse.core.resources/.history/1e/20ce3447d43e001518fa86d7ae2a1cf8 new file mode 100644 index 0000000..869953e --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/1e/20ce3447d43e001518fa86d7ae2a1cf8 @@ -0,0 +1,224 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; + +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class Commands implements CommandExecutor { + // This method is called, when somebody uses our command + @Override + public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { + if (sender instanceof Player) { + Player player = (Player) sender; + if(args.length<1) + return false; + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. + //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) + if(p.Flair==null) + { + player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); + return true; + } + switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. + { + case "accept": + { + if(p.IgnoredFlair) + p.IgnoredFlair=false; //2015.08.08. + if(!p.AcceptedFlair) + { + String flair=p.Flair; //2015.08.08. + //PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + PluginMain.AppendPlayerDisplayFlair(p, player); + p.AcceptedFlair=true; //2015.08.08. + player.sendMessage("§6Your flair has been set:§r "+flair); + } + else + player.sendMessage("§cYou already have this user's flair.§r"); + break; + } + case "ignore": + { + if(p.AcceptedFlair) + p.AcceptedFlair=false; //2015.08.08. + if(!p.IgnoredFlair) + { + p.IgnoredFlair=true; + String flair=p.Flair; //2015.08.08. + PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. + player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); + } + else + player.sendMessage("§cYou already ignored this request.§r"); + break; + } + /*case "reload": //2015.07.20. + DoReload(player); + break;*/ + case "admin": //2015.08.09. + DoAdmin(player, args); + break; + case "nonpresser": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§7(non-pr.)§r"; + break; + case "cantpress": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§r(can't press)§r"; + break; + default: + return false; + } + return true; + } + /*if(args[0].toLowerCase()=="reload") + DoReload(null); //2015.07.20.*/ + else if(args.length>0 && args[0].toLowerCase().equals("admin")) //2015.08.09. + { + DoAdmin(null, args); //2015.08.09. + return true; //2015.08.09. + } + return false; + } + private static void DoReload(Player player) + { //2015.07.20. + //if(player==null || player.isOp() || player.getName()=="NorbiPeti") + //{ + try + { + File file=new File("autoflairconfig.txt"); + if(file.exists()) + { + PluginMain.LoadFiles(true); //2015.08.09. + for(Player p : PluginMain.GetPlayers()) + { + MaybeOfflinePlayer mp = MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName()); + if(mp.Flair!=null) + { + String flair=mp.Flair; + PluginMain.RemovePlayerDisplayFlairFinal(p, flair); + //PluginMain.AppendPlayerDisplayFlairFinal(p, flair); + PluginMain.AppendPlayerDisplayFlair(mp, p); //2015.08.09. + } + String msg="§6Note: The auto-flair plugin has been reloaded. You might need to wait 10s to have your flair.§r"; //2015.08.09. + p.sendMessage(msg); //2015.08.09. + } + //String msg="§6Reloaded config file.§r"; + //SendMessage(player, msg); //2015.08.09. + } + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + if(player!=null) + player.sendMessage("§cAn error occured. See console for details.§r"); + PluginMain.LastException=e; //2015.08.09. + } + //} + //else + //player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static Player ReloadPlayer; //2015.08.09. + private static void DoAdmin(Player player, String[] args) + { //2015.08.09. + if(player==null || player.isOp() || player.getName()=="NorbiPeti") + { + //System.out.println("Args length: " + args.length); + if(args.length==1) + { + String message="§cUsage: /u admin reload|playerinfo§r"; + SendMessage(player, message); + return; + } + //args[0] is "admin" + switch(args[1].toLowerCase()) + { + case "reload": + ReloadPlayer=player; //2015.08.09. + SendMessage(player, "§6Make sure to save the current settings before you modify and reload them! Type /u admin confirm when done."); + break; + case "playerinfo": + DoPlayerInfo(player, args); + break; + case "getlasterror": + DoGetLastError(player, args); + case "confirm": + if(ReloadPlayer.equals(player)) + DoReload(player); //2015.08.09. + else + SendMessage(player, "§cYou need to do /u admin reload first.§r"); + break; + default: + String message="§cUsage: /u admin reload|playerinfo§r"; + SendMessage(player, message); + return; + } + } + else + player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static void DoPlayerInfo(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "playerinfo" + if(args.length==2) + { + String message="§cUsage: /u admin playerinfo §r"; + SendMessage(player, message); + return; + } + if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2])) + { + String message="§cPlayer not found: "+args[2]+"§r"; + SendMessage(player, message); + return; + } + MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]); + SendMessage(player, "Player name: "+p.PlayerName); + SendMessage(player, "User flair: "+p.Flair); + SendMessage(player, "Username: "+p.UserName); + SendMessage(player, "Flair accepted: "+p.AcceptedFlair); + SendMessage(player, "Flair ignored: "+p.IgnoredFlair); + } + private static void SendMessage(Player player, String message) + { //2015.08.09. + if(player==null) + System.out.println(message); + else + player.sendMessage(message); + } + private static void DoGetLastError(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "getlasterror" + if(PluginMain.LastException!=null) + { + SendMessage(player, "Last error:"); + SendMessage(player, PluginMain.LastException.toString()); + PluginMain.LastException=null; + } + else + SendMessage(player, "There were no exceptions."); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/1e/a0477e13d43e001518fa86d7ae2a1cf8 b/.metadata/.plugins/org.eclipse.core.resources/.history/1e/a0477e13d43e001518fa86d7ae2a1cf8 new file mode 100644 index 0000000..f26d723 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/1e/a0477e13d43e001518fa86d7ae2a1cf8 @@ -0,0 +1,220 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; + +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class Commands implements CommandExecutor { + // This method is called, when somebody uses our command + @Override + public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { + if (sender instanceof Player) { + Player player = (Player) sender; + if(args.length<1) + return false; + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. + //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) + if(p.Flair==null) + { + player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); + return true; + } + switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. + { + case "accept": + { + if(p.IgnoredFlair) + p.IgnoredFlair=false; //2015.08.08. + if(!p.AcceptedFlair) + { + String flair=p.Flair; //2015.08.08. + //PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + PluginMain.AppendPlayerDisplayFlair(p, player); + p.AcceptedFlair=true; //2015.08.08. + player.sendMessage("§6Your flair has been set:§r "+flair); + } + else + player.sendMessage("§cYou already have this user's flair.§r"); + break; + } + case "ignore": + { + if(p.AcceptedFlair) + p.AcceptedFlair=false; //2015.08.08. + if(!p.IgnoredFlair) + { + p.IgnoredFlair=true; + String flair=p.Flair; //2015.08.08. + PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. + player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); + } + else + player.sendMessage("§cYou already ignored this request.§r"); + break; + } + /*case "reload": //2015.07.20. + DoReload(player); + break;*/ + case "admin": //2015.08.09. + DoAdmin(player, args); + break; + case "nonpresser": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§7(non-pr.)§r"; + break; + case "cantpress": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§r(can't press)§r"; + break; + default: + return false; + } + return true; + } + /*if(args[0].toLowerCase()=="reload") + DoReload(null); //2015.07.20.*/ + else if(args.length>0 && args[0].toLowerCase().equals("admin")) //2015.08.09. + { + DoAdmin(null, args); //2015.08.09. + return true; //2015.08.09. + } + return false; + } + private static void DoReload(Player player) + { //2015.07.20. + //if(player==null || player.isOp() || player.getName()=="NorbiPeti") + //{ + try + { + File file=new File("autoflairconfig.txt"); + if(file.exists()) + { + PluginMain.LoadFiles(true); //2015.08.09. + for(Player p : PluginMain.GetPlayers()) + { + MaybeOfflinePlayer mp = MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName()); + if(mp.Flair!=null) + { + String flair=mp.Flair; + PluginMain.RemovePlayerDisplayFlairFinal(p, flair); + //PluginMain.AppendPlayerDisplayFlairFinal(p, flair); + PluginMain.AppendPlayerDisplayFlair(mp, p); //2015.08.09. + } + String msg="§6Note: The auto-flair plugin has been reloaded. You might need to wait 10s to have your flair.§r"; //2015.08.09. + p.sendMessage(msg); //2015.08.09. + } + //String msg="§6Reloaded config file.§r"; + //SendMessage(player, msg); //2015.08.09. + } + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + if(player!=null) + player.sendMessage("§cAn error occured. See console for details.§r"); + PluginMain.LastException=e; //2015.08.09. + } + //} + //else + //player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static Player ReloadPlayer; //2015.08.09. + private static void DoAdmin(Player player, String[] args) + { //2015.08.09. + if(player==null || player.isOp() || player.getName()=="NorbiPeti") + { + //System.out.println("Args length: " + args.length); + if(args.length==1) + { + String message="§cUsage: /u admin reload|playerinfo§r"; + SendMessage(player, message); + return; + } + //args[0] is "admin" + switch(args[1].toLowerCase()) + { + case "reload": + SendMessage(player, "§6Make sure to save the current settings before you modify and reload them! Type /u admin confirm when done."); + break; + case "playerinfo": + DoPlayerInfo(player, args); + break; + case "getlasterror": + DoGetLastError(player, args); + case "confirm": + DoReload(player); //2015.08.09. + break; + default: + String message="§cUsage: /u admin reload|playerinfo§r"; + SendMessage(player, message); + return; + } + } + else + player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static void DoPlayerInfo(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "playerinfo" + if(args.length==2) + { + String message="§cUsage: /u admin playerinfo §r"; + SendMessage(player, message); + return; + } + if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2])) + { + String message="§cPlayer not found: "+args[2]+"§r"; + SendMessage(player, message); + return; + } + MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]); + SendMessage(player, "Player name: "+p.PlayerName); + SendMessage(player, "User flair: "+p.Flair); + SendMessage(player, "Username: "+p.UserName); + SendMessage(player, "Flair accepted: "+p.AcceptedFlair); + SendMessage(player, "Flair ignored: "+p.IgnoredFlair); + } + private static void SendMessage(Player player, String message) + { //2015.08.09. + if(player==null) + System.out.println(message); + else + player.sendMessage(message); + } + private static void DoGetLastError(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "getlasterror" + if(PluginMain.LastException!=null) + { + SendMessage(player, "Last error:"); + SendMessage(player, PluginMain.LastException.toString()); + PluginMain.LastException=null; + } + else + SendMessage(player, "There were no exceptions."); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/1e/b057e861ce3e001518fa86d7ae2a1cf8 b/.metadata/.plugins/org.eclipse.core.resources/.history/1e/b057e861ce3e001518fa86d7ae2a1cf8 new file mode 100644 index 0000000..4343f31 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/1e/b057e861ce3e001518fa86d7ae2a1cf8 @@ -0,0 +1,31 @@ +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 FlairClassType FlairType; //2015.08.09. + 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); + } + /*public enum FlairClassType + { //2015.08.09. + NonPresser, + CantPress, + Undecided + }*/ +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/1f/203f7772d23e001518fa86d7ae2a1cf8 b/.metadata/.plugins/org.eclipse.core.resources/.history/1f/203f7772d23e001518fa86d7ae2a1cf8 new file mode 100644 index 0000000..efbed4c --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/1f/203f7772d23e001518fa86d7ae2a1cf8 @@ -0,0 +1,380 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStream; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLConnection; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + +import org.apache.commons.io.IOUtils; +import org.bukkit.entity.Player; +import org.bukkit.plugin.java.JavaPlugin; +import org.json.JSONArray; +import org.json.JSONObject; + +import com.palmergames.bukkit.towny.object.Town; +import com.palmergames.bukkit.towny.object.WorldCoord; + +public class PluginMain extends JavaPlugin +{ //Translated to Java: 2015.07.15. + //A user, which flair isn't obtainable: + //https://www.reddit.com/r/thebutton/comments/31c32v/i_pressed_the_button_without_really_thinking/ + private static PluginMain Instance; + // Fired when plugin is first enabled + @Override + public void onEnable() + { + System.out.println("The Button Auto-flair Plugin by NorbiPeti (:P)"); + getServer().getPluginManager().registerEvents(new PlayerListener(), this); + this.getCommand("u").setExecutor(new Commands()); + this.getCommand("u").setUsage(this.getCommand("u").getUsage().replace('&', '§')); + Instance=this; //2015.08.08. + LoadFiles(false); //2015.08.09. + Runnable r=new Runnable(){public void run(){ThreadMethod();}}; + Thread t=new Thread(r); + t.start(); + } + Boolean stop=false; + // Fired when plugin is disabled + @Override + public void onDisable() + { + try + { + FileWriter fw; + fw = new FileWriter("flairsaccepted.txt"); + fw.close(); + fw = new FileWriter("flairsignored.txt"); + fw.close(); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + try { + File file=new File("flairsaccepted.txt"); + BufferedWriter bw=new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.AcceptedFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + file=new File("flairsignored.txt"); + bw = new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.IgnoredFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + stop=true; + } + + public void ThreadMethod() //<-- 2015.07.16. + { + while(!stop) + { + try + { + String body=DownloadString("https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/autoflair_system_comment_your_minecraft_name_and/.json?limit=1000"); + JSONArray json=new JSONArray(body).getJSONObject(1).getJSONObject("data").getJSONArray("children"); + for(Object obj : json) + { + JSONObject item = (JSONObject)obj; + String author=item.getJSONObject("data").getString("author"); + String ign=item.getJSONObject("data").getString("body"); + int start = ign.indexOf("IGN:") + "IGN:".length(); + int end = ign.indexOf(' ', start); + if (end == -1 || end == start) + end=ign.indexOf('\n', start); //2015.07.15. + if (end == -1 || end == start) + ign = ign.substring(start); + else + ign = ign.substring(start, end); + ign = ign.trim(); + if(HasIGFlair(ign)) + continue; + try { + Thread.sleep(10); + } catch(InterruptedException ex) { + Thread.currentThread().interrupt(); + } + String[] flairdata = DownloadString("http://karmadecay.com/thebutton-data.php?users=" + author).replace("\"", "").split(":"); + String flair; + if(flairdata.length > 1) //2015.07.15. + flair = flairdata[1]; + else + flair=""; + if (flair != "-1") + flair = flair + "s"; + else + flair = "non-presser"; + String flairclass; + if(flairdata.length>2) + flairclass = flairdata[2]; + else + flairclass="unknown"; + SetFlair(ign, flair, flairclass, author); + } + Thread.sleep(10000); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + } + + public static Exception LastException; //2015.08.09. + + public String DownloadString(String urlstr) throws MalformedURLException, IOException + { + URL url = new URL(urlstr); + URLConnection con = url.openConnection(); + con.setRequestProperty("User-Agent", "TheButtonAutoFlair"); + InputStream in = con.getInputStream(); + String encoding = con.getContentEncoding(); + encoding = encoding == null ? "UTF-8" : encoding; + String body = IOUtils.toString(in, encoding); + in.close(); + return body; + } + + public static Map TownColors=new HashMap(); //2015.07.20. + public Boolean HasIGFlair(String playername) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + return p.Flair!=null; //2015.08.08. + } + + public void SetFlair(String playername, String text, String flairclass, String username) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + String finalflair; + p.FlairDecided=true; + switch(flairclass) + { + case "press-1": + finalflair="§c("+text+")§r"; + break; + case "press-2": + finalflair="§6("+text+")§r"; + break; + case "press-3": + finalflair="§e("+text+")§r"; + break; + case "press-4": + finalflair="§a("+text+")§r"; + break; + case "press-5": + finalflair="§9("+text+")§r"; + break; + 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; + case "undecided": //2015.08.09. + p.FlairDecided=false; + finalflair=""; + break; + default: + finalflair=""; + break; + } + if(finalflair.length()==0) //<-- 2015.07.20. + return; + p.Flair=finalflair; //2015.08.08. + p.UserName=username; //2015.08.08. + System.out.println("Added new flair to "+playername+": "+finalflair); + for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08. + { + if(player.getName().equals(playername)) + { + //AppendPlayerDisplayFlair(player, username, finalflair); + AppendPlayerDisplayFlair(p, player); + break; + } + } + } + + public static String GetFlair(Player player) + { //2015.07.16. + String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08. + return flair==null ? "" : flair; + } + + //public static void AppendPlayerDisplayFlair(Player player, String username, String flair) + public static void AppendPlayerDisplayFlair(MaybeOfflinePlayer player, Player p) //<-- 2015.08.09. + { + + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).IgnoredFlair) + return; + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).AcceptedFlair) + { + AppendPlayerDisplayFlairFinal(p, player.Flair); //2015.07.20. + if(!player.FlairDecided) + p.sendMessage("§9Your flair type is unknown. Are you a non-presser or a can't press? (/u nonpresser or /u cantpress)§r"); //2015.08.09. + } + else + p.sendMessage("§9Are you Reddit user "+player.UserName+"?§r §6Type /u accept or /u ignore§r"); + } + + private static void AppendPlayerDisplayFlairFinal(Player player, String flair) + { //2015.07.20. + String color = GetColorForTown(GetPlayerTown(player)); //TO!DO: Multiple colors put on first capital letters + String[] colors = color.substring(1).split("§"); + String displayname=player.getName(); //2015.08.08. + ArrayList Positions=new ArrayList<>(); + for(int i=0; i=colors.length) + { + int x=0; + for(int i=0; i GetPlayers() + { + return Instance.getServer().getOnlinePlayers(); + } + + public static void LoadFiles(boolean reload) //<-- 2015.08.09. + { + if(reload) + { //2015.08.09. + System.out.println("Auto-flair plugin cleanup for reloading..."); + MaybeOfflinePlayer.AllPlayers.clear(); + TownColors.clear(); + } + System.out.println("Loading files for auto-flair plugin..."); //2015.08.09. + try { + File file=new File("flairsaccepted.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + //System.out.println("Name: " + name); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("flairsignored.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsignored.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("autoflairconfig.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + TownColors.put(s[0], s[1]); + } + br.close(); + } + //throw new IOException("Test"); //2015.08.09. + System.out.println("Auto-flair plugin loaded files!"); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + public static void SaveFiles() //<-- 2015.08.09. + { + + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/1f/604b1a15873e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/1f/604b1a15873e00151ce8ff6d4f74dabd deleted file mode 100644 index 2b6fbe4..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/1f/604b1a15873e00151ce8ff6d4f74dabd +++ /dev/null @@ -1,135 +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; - MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. - //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - if(p.Flair==null) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. - { - case "accept": - { - if(p.IgnoredFlair) - p.IgnoredFlair=false; //2015.08.08. - if(!p.AcceptedFlair) - { - String flair=p.Flair; //2015.08.08. - PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. - p.AcceptedFlair=true; //2015.08.08. - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("§cYou already have this user's flair.§r"); - break; - } - case "ignore": - { - if(p.AcceptedFlair) - p.AcceptedFlair=false; //2015.08.08. - if(!p.IgnoredFlair) - { - p.IgnoredFlair=true; - String flair=p.Flair; //2015.08.08. - PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. - player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); - } - else - player.sendMessage("§cYou already ignored this request.§r"); - break; - } - case "reload": //2015.07.20. - DoReload(player); - break; - case "admin": //2015.08.09. - DoAdmin(player, args); - break; - default: - return false; - } - return true; - } - - if(args[0].toLowerCase()=="reload") - DoReload(null); //2015.07.20. - else if(args[0].toLowerCase()=="admin") - DoAdmin(null, args); //2015.08.09. - return false; - } - private static void DoReload(Player player) - { //2015.07.20. - //if(player==null || player.isOp() || player.getName()=="NorbiPeti") - //{ - try - { - File file=new File("autoflairconfig.txt"); - if(file.exists()) - { - PluginMain.TownColors.clear(); - BufferedReader br=new BufferedReader(new FileReader(file)); - String line; - while((line=br.readLine())!=null) - { - String[] s=line.split(" "); - PluginMain.TownColors.put(s[0], s[1]); - } - br.close(); - for(Player p : PluginMain.GetPlayers()) - { - MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName()); - if(mp.Flair!=null) - { - String flair=mp.Flair; - PluginMain.RemovePlayerDisplayFlairFinal(p, flair); - PluginMain.AppendPlayerDisplayFlairFinal(p, flair); - } - } - String msg="§6Reloaded config file.§r"; - if(player!=null) - player.sendMessage(msg); - else - System.out.println(msg); - } - } - catch(Exception e) - { - System.out.println("Error!\n"+e); - if(player!=null) - player.sendMessage("§cAn error occured. See console for details.§r"); - } - //} - //else - //player.sendMessage("§cYou need to be OP to use this command.§r"); - } - private static void DoAdmin(Player player, String[] args) - { - if(player==null || player.isOp() || player.getName()=="NorbiPeti") - { - //args[0] is "admin" - switch(args[1].toLowerCase()) - { - case " - } - } - else - player.sendMessage("§cYou need to be OP to use this command.§r"); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/2/00863467e03e001517108d149b613203 b/.metadata/.plugins/org.eclipse.core.resources/.history/2/00863467e03e001517108d149b613203 new file mode 100644 index 0000000..0ccc23b --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/2/00863467e03e001517108d149b613203 @@ -0,0 +1,260 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +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; + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. + //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) + if(p.Flair==null) + { + player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); + return true; + } + switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. + { + case "accept": + { + if(p.IgnoredFlair) + p.IgnoredFlair=false; //2015.08.08. + if(!p.AcceptedFlair) + { + String flair=p.Flair; //2015.08.08. + //PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + PluginMain.AppendPlayerDisplayFlair(p, player); + p.AcceptedFlair=true; //2015.08.08. + player.sendMessage("§6Your flair has been set:§r "+flair); + } + else + player.sendMessage("§cYou already have this user's flair.§r"); + break; + } + case "ignore": + { + if(p.AcceptedFlair) + p.AcceptedFlair=false; //2015.08.08. + if(!p.IgnoredFlair) + { + p.IgnoredFlair=true; + String flair=p.Flair; //2015.08.08. + PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. + player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); + } + else + player.sendMessage("§cYou already ignored this request.§r"); + break; + } + /*case "reload": //2015.07.20. + DoReload(player); + break;*/ + case "admin": //2015.08.09. + DoAdmin(player, args); + break; + case "nonpresser": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§7(non-pr.)§r"; + break; + case "cantpress": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§r(can't press)§r"; + break; + default: + return false; + } + return true; + } + /*if(args[0].toLowerCase()=="reload") + DoReload(null); //2015.07.20.*/ + else if(args.length>0 && args[0].toLowerCase().equals("admin")) //2015.08.09. + { + DoAdmin(null, args); //2015.08.09. + return true; //2015.08.09. + } + return false; + } + private static void DoReload(Player player) + { //2015.07.20. + //if(player==null || player.isOp() || player.getName()=="NorbiPeti") + //{ + try + { + File file=new File("autoflairconfig.txt"); + if(file.exists()) + { + PluginMain.LoadFiles(true); //2015.08.09. + for(Player p : PluginMain.GetPlayers()) + { + MaybeOfflinePlayer mp = MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName()); + if(mp.Flair!=null) + { + String flair=mp.Flair; + PluginMain.RemovePlayerDisplayFlairFinal(p, flair); + //PluginMain.AppendPlayerDisplayFlairFinal(p, flair); + PluginMain.AppendPlayerDisplayFlair(mp, p); //2015.08.09. + } + String msg="§6Note: The auto-flair plugin has been reloaded. You might need to wait 10s to have your flair.§r"; //2015.08.09. + p.sendMessage(msg); //2015.08.09. + } + //String msg="§6Reloaded config file.§r"; + //SendMessage(player, msg); //2015.08.09. + } + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + if(player!=null) + player.sendMessage("§cAn error occured. See console for details.§r"); + PluginMain.LastException=e; //2015.08.09. + } + //} + //else + //player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static Player ReloadPlayer; //2015.08.09. + private static void DoAdmin(Player player, String[] args) + { //2015.08.09. + if(player==null || player.isOp() || player.getName()=="NorbiPeti") + { + //System.out.println("Args length: " + args.length); + if(args.length==1) + { + String message="§cUsage: /u admin reload|playerinfo§r"; + SendMessage(player, message); + return; + } + //args[0] is "admin" + switch(args[1].toLowerCase()) + { + case "reload": + ReloadPlayer=player; //2015.08.09. + SendMessage(player, "§6Make sure to save the current settings before you modify and reload them! Type /u admin confirm when done.§r"); + break; + case "playerinfo": + DoPlayerInfo(player, args); + break; + case "getlasterror": + DoGetLastError(player, args); + case "confirm": + if(ReloadPlayer==player) + DoReload(player); //2015.08.09. + else + SendMessage(player, "§cYou need to do /u admin reload first.§r"); + break; + case "save": + PluginMain.SaveFiles(); //2015.08.09. + SendMessage(player, "§6Saved files. Now you can edit them and reload if you want.§r"); + break; + case "setflair": + + break; + default: + String message="§cUsage: /u admin reload|playerinfo|getlasterror|save§r"; + SendMessage(player, message); + return; + } + } + else + player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static void DoPlayerInfo(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "playerinfo" + if(args.length==2) + { + String message="§cUsage: /u admin playerinfo §r"; + SendMessage(player, message); + return; + } + if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2])) + { + String message="§cPlayer not found: "+args[2]+"§r"; + SendMessage(player, message); + return; + } + MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]); + SendMessage(player, "Player name: "+p.PlayerName); + SendMessage(player, "User flair: "+p.Flair); + SendMessage(player, "Username: "+p.UserName); + SendMessage(player, "Flair accepted: "+p.AcceptedFlair); + SendMessage(player, "Flair ignored: "+p.IgnoredFlair); + } + private static void SendMessage(Player player, String message) + { //2015.08.09. + if(player==null) + System.out.println(message); + else + player.sendMessage(message); + } + private static void DoGetLastError(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "getlasterror" + if(PluginMain.LastException!=null) + { + SendMessage(player, "Last error:"); + SendMessage(player, PluginMain.LastException.toString()); + PluginMain.LastException=null; + } + else + SendMessage(player, "There were no exceptions."); + } + private static void SetPlayerFlair(Player player, Player targetplayer, String flair) + { //2015.08.09. + flair=flair.replace('&', '§'); + MaybeOfflinePlayer.AddPlayerIfNeeded(player.getName()).Flair=flair; + if(!PluginMain.RemoveLineFromFile("customflairs.txt", targetplayer.getName())) + { + SendMessage(player, "§cError removing previous custom flair!§r"); + return; + } + File file=new File("customflairs.txt"); + try { + BufferedWriter bw; + bw = new BufferedWriter(new FileWriter(file, true)); + bw.write(targetplayer.getName()+"\n"); + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + PluginMain.LastException=e; //2015.08.09. + } + SendMessage(player, "§6The flair has been set. Player: "+targetplayer.getName()+" Flair: "+flair+"§r"); + } + private static void DoSetFlair(Player player, String args) + { + //args[0] is "admin" - args[1] is "setflair" + + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/2/a06adb06d43e001518fa86d7ae2a1cf8 b/.metadata/.plugins/org.eclipse.core.resources/.history/2/a06adb06d43e001518fa86d7ae2a1cf8 new file mode 100644 index 0000000..2ccf0cc --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/2/a06adb06d43e001518fa86d7ae2a1cf8 @@ -0,0 +1,219 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; + +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class Commands implements CommandExecutor { + // This method is called, when somebody uses our command + @Override + public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { + if (sender instanceof Player) { + Player player = (Player) sender; + if(args.length<1) + return false; + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. + //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) + if(p.Flair==null) + { + player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); + return true; + } + switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. + { + case "accept": + { + if(p.IgnoredFlair) + p.IgnoredFlair=false; //2015.08.08. + if(!p.AcceptedFlair) + { + String flair=p.Flair; //2015.08.08. + //PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + PluginMain.AppendPlayerDisplayFlair(p, player); + p.AcceptedFlair=true; //2015.08.08. + player.sendMessage("§6Your flair has been set:§r "+flair); + } + else + player.sendMessage("§cYou already have this user's flair.§r"); + break; + } + case "ignore": + { + if(p.AcceptedFlair) + p.AcceptedFlair=false; //2015.08.08. + if(!p.IgnoredFlair) + { + p.IgnoredFlair=true; + String flair=p.Flair; //2015.08.08. + PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. + player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); + } + else + player.sendMessage("§cYou already ignored this request.§r"); + break; + } + /*case "reload": //2015.07.20. + DoReload(player); + break;*/ + case "admin": //2015.08.09. + DoAdmin(player, args); + break; + case "nonpresser": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§7(non-pr.)§r"; + break; + case "cantpress": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§r(can't press)§r"; + break; + default: + return false; + } + return true; + } + /*if(args[0].toLowerCase()=="reload") + DoReload(null); //2015.07.20.*/ + else if(args.length>0 && args[0].toLowerCase().equals("admin")) //2015.08.09. + { + DoAdmin(null, args); //2015.08.09. + return true; //2015.08.09. + } + return false; + } + private static void DoReload(Player player) + { //2015.07.20. + //if(player==null || player.isOp() || player.getName()=="NorbiPeti") + //{ + try + { + File file=new File("autoflairconfig.txt"); + if(file.exists()) + { + PluginMain.LoadFiles(true); //2015.08.09. + for(Player p : PluginMain.GetPlayers()) + { + MaybeOfflinePlayer mp = MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName()); + if(mp.Flair!=null) + { + String flair=mp.Flair; + PluginMain.RemovePlayerDisplayFlairFinal(p, flair); + //PluginMain.AppendPlayerDisplayFlairFinal(p, flair); + PluginMain.AppendPlayerDisplayFlair(mp, p); //2015.08.09. + } + String msg="§6Note: The auto-flair plugin has been reloaded. You might need to wait 10s to have your flair.§r"; //2015.08.09. + p.sendMessage(msg); //2015.08.09. + } + //String msg="§6Reloaded config file.§r"; + //SendMessage(player, msg); //2015.08.09. + } + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + if(player!=null) + player.sendMessage("§cAn error occured. See console for details.§r"); + PluginMain.LastException=e; //2015.08.09. + } + //} + //else + //player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static void DoAdmin(Player player, String[] args) + { //2015.08.09. + if(player==null || player.isOp() || player.getName()=="NorbiPeti") + { + //System.out.println("Args length: " + args.length); + if(args.length==1) + { + String message="§cUsage: /u admin reload|playerinfo§r"; + SendMessage(player, message); + return; + } + //args[0] is "admin" + switch(args[1].toLowerCase()) + { + case "reload": + DoReload(player); + break; + case "playerinfo": + DoPlayerInfo(player, args); + break; + case "getlasterror": + DoGetLastError(player, args); + case "confirm": + DoReload(player); //2015.08.09. + break; + default: + String message="§cUsage: /u admin reload|playerinfo§r"; + SendMessage(player, message); + return; + } + } + else + player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static void DoPlayerInfo(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "playerinfo" + if(args.length==2) + { + String message="§cUsage: /u admin playerinfo §r"; + SendMessage(player, message); + return; + } + if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2])) + { + String message="§cPlayer not found: "+args[2]+"§r"; + SendMessage(player, message); + return; + } + MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]); + SendMessage(player, "Player name: "+p.PlayerName); + SendMessage(player, "User flair: "+p.Flair); + SendMessage(player, "Username: "+p.UserName); + SendMessage(player, "Flair accepted: "+p.AcceptedFlair); + SendMessage(player, "Flair ignored: "+p.IgnoredFlair); + } + private static void SendMessage(Player player, String message) + { //2015.08.09. + if(player==null) + System.out.println(message); + else + player.sendMessage(message); + } + private static void DoGetLastError(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "getlasterror" + if(PluginMain.LastException!=null) + { + SendMessage(player, "Last error:"); + SendMessage(player, PluginMain.LastException.toString()); + PluginMain.LastException=null; + } + else + SendMessage(player, "There were no exceptions."); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/20/b08b3094cf3e001518fa86d7ae2a1cf8 b/.metadata/.plugins/org.eclipse.core.resources/.history/20/b08b3094cf3e001518fa86d7ae2a1cf8 new file mode 100644 index 0000000..50ac8ec --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/20/b08b3094cf3e001518fa86d7ae2a1cf8 @@ -0,0 +1,364 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.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 tk.sznp.thebuttonautoflair.MaybeOfflinePlayer.FlairClassType; + +import com.palmergames.bukkit.towny.object.Town; +import com.palmergames.bukkit.towny.object.WorldCoord; + +public class PluginMain extends JavaPlugin +{ //Translated to Java: 2015.07.15. + //A user, which flair isn't obtainable: + //https://www.reddit.com/r/thebutton/comments/31c32v/i_pressed_the_button_without_really_thinking/ + private static PluginMain Instance; + // Fired when plugin is first enabled + @Override + public void onEnable() + { + System.out.println("The Button Auto-flair Plugin by NorbiPeti (:P)"); + getServer().getPluginManager().registerEvents(new PlayerListener(), this); + this.getCommand("u").setExecutor(new Commands()); + this.getCommand("u").setUsage(this.getCommand("u").getUsage().replace('&', '§')); + Instance=this; //2015.08.08. + try { + File file=new File("flairsaccepted.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + //System.out.println("Name: " + name); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("flairsignored.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsignored.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("autoflairconfig.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + TownColors.put(s[0], s[1]); + } + br.close(); + } + //throw new IOException("Test"); //2015.08.09. + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + Runnable r=new Runnable(){public void run(){ThreadMethod();}}; + Thread t=new Thread(r); + t.start(); + } + Boolean stop=false; + // Fired when plugin is disabled + @Override + public void onDisable() + { + try + { + FileWriter fw; + fw = new FileWriter("flairsaccepted.txt"); + fw.close(); + fw = new FileWriter("flairsignored.txt"); + fw.close(); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + try { + File file=new File("flairsaccepted.txt"); + BufferedWriter bw=new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.AcceptedFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + file=new File("flairsignored.txt"); + bw = new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.IgnoredFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + stop=true; + } + + public void ThreadMethod() //<-- 2015.07.16. + { + while(!stop) + { + try + { + String body=DownloadString("https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/autoflair_system_comment_your_minecraft_name_and/.json?limit=1000"); + JSONArray json=new JSONArray(body).getJSONObject(1).getJSONObject("data").getJSONArray("children"); + for(Object obj : json) + { + JSONObject item = (JSONObject)obj; + String author=item.getJSONObject("data").getString("author"); + String ign=item.getJSONObject("data").getString("body"); + int start = ign.indexOf("IGN:") + "IGN:".length(); + int end = ign.indexOf(' ', start); + if (end == -1 || end == start) + end=ign.indexOf('\n', start); //2015.07.15. + if (end == -1 || end == start) + ign = ign.substring(start); + else + ign = ign.substring(start, end); + ign = ign.trim(); + if(HasIGFlair(ign)) + continue; + try { + Thread.sleep(10); + } catch(InterruptedException ex) { + Thread.currentThread().interrupt(); + } + String[] flairdata = DownloadString("http://karmadecay.com/thebutton-data.php?users=" + author).replace("\"", "").split(":"); + String flair; + if(flairdata.length > 1) //2015.07.15. + flair = flairdata[1]; + else + flair=""; + if (flair != "-1") + flair = flair + "s"; + else + flair = "non-presser"; + String flairclass; + if(flairdata.length>2) + flairclass = flairdata[2]; + else + flairclass="unknown"; + SetFlair(ign, flair, flairclass, author); + } + Thread.sleep(10000); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + } + + public static Exception LastException; //2015.08.09. + + public String DownloadString(String urlstr) throws MalformedURLException, IOException + { + URL url = new URL(urlstr); + URLConnection con = url.openConnection(); + con.setRequestProperty("User-Agent", "TheButtonAutoFlair"); + InputStream in = con.getInputStream(); + String encoding = con.getContentEncoding(); + encoding = encoding == null ? "UTF-8" : encoding; + String body = IOUtils.toString(in, encoding); + in.close(); + return body; + } + + public static Map TownColors=new HashMap(); //2015.07.20. + public Boolean HasIGFlair(String playername) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + return p.Flair!=null; //2015.08.08. + } + + public void SetFlair(String playername, String text, String flairclass, String username) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + String finalflair; + p.FlairDecided=true; + switch(flairclass) + { + case "press-1": + finalflair="§c("+text+")§r"; + break; + case "press-2": + finalflair="§6("+text+")§r"; + break; + case "press-3": + finalflair="§e("+text+")§r"; + break; + case "press-4": + finalflair="§a("+text+")§r"; + break; + case "press-5": + finalflair="§9("+text+")§r"; + break; + 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; + case "undecided": //2015.08.09. + p.FlairDecided=false; + finalflair=""; + break; + default: + finalflair=""; + break; + } + if(finalflair.length()==0) //<-- 2015.07.20. + return; + p.Flair=finalflair; //2015.08.08. + p.UserName=username; //2015.08.08. + System.out.println("Added new flair to "+playername+": "+finalflair); + for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08. + { + if(player.getName().equals(playername)) + { + AppendPlayerDisplayFlair(player, username, finalflair); + break; + } + } + } + + public static String GetFlair(Player player) + { //2015.07.16. + String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08. + return flair==null ? "" : flair; + } + + //public static void AppendPlayerDisplayFlair(Player player, String username, String flair) + public static void AppendPlayerDisplayFlair(MaybeOfflinePlayer player, Player p) //<-- 2015.08.09. + { + + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).IgnoredFlair) + return; + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).AcceptedFlair) + { + AppendPlayerDisplayFlairFinal(p, player.Flair); //2015.07.20. + if(!player.FlairDecided) + p.sendMessage("§9Your flair type is unknown. Are you a non-presser or a can't press? (/u nonpresser or /u cantpress)§r"); //2015.08.09. + } + else + player.sendMessage("§9Are you Reddit user "+player.UserName+"?§r §6Type /u accept or /u ignore§r"); + } + + private static void AppendPlayerDisplayFlairFinal(Player player, String flair) + { //2015.07.20. + String color = GetColorForTown(GetPlayerTown(player)); //TO!DO: Multiple colors put on first capital letters + String[] colors = color.substring(1).split("§"); + String displayname=player.getName(); //2015.08.08. + ArrayList Positions=new ArrayList<>(); + for(int i=0; i=colors.length) + { + int x=0; + for(int i=0; i GetPlayers() + { + return Instance.getServer().getOnlinePlayers(); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/21/509f004a873e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/21/509f004a873e00151ce8ff6d4f74dabd deleted file mode 100644 index 7947b97..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/21/509f004a873e00151ce8ff6d4f74dabd +++ /dev/null @@ -1,138 +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; - MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. - //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - if(p.Flair==null) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. - { - case "accept": - { - if(p.IgnoredFlair) - p.IgnoredFlair=false; //2015.08.08. - if(!p.AcceptedFlair) - { - String flair=p.Flair; //2015.08.08. - PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. - p.AcceptedFlair=true; //2015.08.08. - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("§cYou already have this user's flair.§r"); - break; - } - case "ignore": - { - if(p.AcceptedFlair) - p.AcceptedFlair=false; //2015.08.08. - if(!p.IgnoredFlair) - { - p.IgnoredFlair=true; - String flair=p.Flair; //2015.08.08. - PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. - player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); - } - else - player.sendMessage("§cYou already ignored this request.§r"); - break; - } - /*case "reload": //2015.07.20. - DoReload(player); - break;*/ - case "admin": //2015.08.09. - DoAdmin(player, args); - break; - default: - return false; - } - return true; - } - - /*if(args[0].toLowerCase()=="reload") - DoReload(null); //2015.07.20.*/ - else if(args[0].toLowerCase()=="admin") - DoAdmin(null, args); //2015.08.09. - return false; - } - private static void DoReload(Player player) - { //2015.07.20. - //if(player==null || player.isOp() || player.getName()=="NorbiPeti") - //{ - try - { - File file=new File("autoflairconfig.txt"); - if(file.exists()) - { - PluginMain.TownColors.clear(); - BufferedReader br=new BufferedReader(new FileReader(file)); - String line; - while((line=br.readLine())!=null) - { - String[] s=line.split(" "); - PluginMain.TownColors.put(s[0], s[1]); - } - br.close(); - for(Player p : PluginMain.GetPlayers()) - { - MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName()); - if(mp.Flair!=null) - { - String flair=mp.Flair; - PluginMain.RemovePlayerDisplayFlairFinal(p, flair); - PluginMain.AppendPlayerDisplayFlairFinal(p, flair); - } - } - String msg="§6Reloaded config file.§r"; - if(player!=null) - player.sendMessage(msg); - else - System.out.println(msg); - } - } - catch(Exception e) - { - System.out.println("Error!\n"+e); - if(player!=null) - player.sendMessage("§cAn error occured. See console for details.§r"); - } - //} - //else - //player.sendMessage("§cYou need to be OP to use this command.§r"); - } - private static void DoAdmin(Player player, String[] args) - { - if(player==null || player.isOp() || player.getName()=="NorbiPeti") - { - //args[0] is "admin" - switch(args[1].toLowerCase()) - { - case "reload": - DoReload(player); - case "playerinfo": - break; - } - } - else - player.sendMessage("§cYou need to be OP to use this command.§r"); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/21/a0775b0ee03e001517108d149b613203 b/.metadata/.plugins/org.eclipse.core.resources/.history/21/a0775b0ee03e001517108d149b613203 new file mode 100644 index 0000000..e6e7dea --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/21/a0775b0ee03e001517108d149b613203 @@ -0,0 +1,259 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +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; + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. + //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) + if(p.Flair==null) + { + player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); + return true; + } + switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. + { + case "accept": + { + if(p.IgnoredFlair) + p.IgnoredFlair=false; //2015.08.08. + if(!p.AcceptedFlair) + { + String flair=p.Flair; //2015.08.08. + //PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + PluginMain.AppendPlayerDisplayFlair(p, player); + p.AcceptedFlair=true; //2015.08.08. + player.sendMessage("§6Your flair has been set:§r "+flair); + } + else + player.sendMessage("§cYou already have this user's flair.§r"); + break; + } + case "ignore": + { + if(p.AcceptedFlair) + p.AcceptedFlair=false; //2015.08.08. + if(!p.IgnoredFlair) + { + p.IgnoredFlair=true; + String flair=p.Flair; //2015.08.08. + PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. + player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); + } + else + player.sendMessage("§cYou already ignored this request.§r"); + break; + } + /*case "reload": //2015.07.20. + DoReload(player); + break;*/ + case "admin": //2015.08.09. + DoAdmin(player, args); + break; + case "nonpresser": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§7(non-pr.)§r"; + break; + case "cantpress": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§r(can't press)§r"; + break; + default: + return false; + } + return true; + } + /*if(args[0].toLowerCase()=="reload") + DoReload(null); //2015.07.20.*/ + else if(args.length>0 && args[0].toLowerCase().equals("admin")) //2015.08.09. + { + DoAdmin(null, args); //2015.08.09. + return true; //2015.08.09. + } + return false; + } + private static void DoReload(Player player) + { //2015.07.20. + //if(player==null || player.isOp() || player.getName()=="NorbiPeti") + //{ + try + { + File file=new File("autoflairconfig.txt"); + if(file.exists()) + { + PluginMain.LoadFiles(true); //2015.08.09. + for(Player p : PluginMain.GetPlayers()) + { + MaybeOfflinePlayer mp = MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName()); + if(mp.Flair!=null) + { + String flair=mp.Flair; + PluginMain.RemovePlayerDisplayFlairFinal(p, flair); + //PluginMain.AppendPlayerDisplayFlairFinal(p, flair); + PluginMain.AppendPlayerDisplayFlair(mp, p); //2015.08.09. + } + String msg="§6Note: The auto-flair plugin has been reloaded. You might need to wait 10s to have your flair.§r"; //2015.08.09. + p.sendMessage(msg); //2015.08.09. + } + //String msg="§6Reloaded config file.§r"; + //SendMessage(player, msg); //2015.08.09. + } + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + if(player!=null) + player.sendMessage("§cAn error occured. See console for details.§r"); + PluginMain.LastException=e; //2015.08.09. + } + //} + //else + //player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static Player ReloadPlayer; //2015.08.09. + private static void DoAdmin(Player player, String[] args) + { //2015.08.09. + if(player==null || player.isOp() || player.getName()=="NorbiPeti") + { + //System.out.println("Args length: " + args.length); + if(args.length==1) + { + String message="§cUsage: /u admin reload|playerinfo§r"; + SendMessage(player, message); + return; + } + //args[0] is "admin" + switch(args[1].toLowerCase()) + { + case "reload": + ReloadPlayer=player; //2015.08.09. + SendMessage(player, "§6Make sure to save the current settings before you modify and reload them! Type /u admin confirm when done.§r"); + break; + case "playerinfo": + DoPlayerInfo(player, args); + break; + case "getlasterror": + DoGetLastError(player, args); + case "confirm": + if(ReloadPlayer==player) + DoReload(player); //2015.08.09. + else + SendMessage(player, "§cYou need to do /u admin reload first.§r"); + break; + case "save": + PluginMain.SaveFiles(); //2015.08.09. + SendMessage(player, "§6Saved files. Now you can edit them and reload if you want.§r"); + break; + case "setflair": + + break; + default: + String message="§cUsage: /u admin reload|playerinfo|getlasterror|save§r"; + SendMessage(player, message); + return; + } + } + else + player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static void DoPlayerInfo(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "playerinfo" + if(args.length==2) + { + String message="§cUsage: /u admin playerinfo §r"; + SendMessage(player, message); + return; + } + if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2])) + { + String message="§cPlayer not found: "+args[2]+"§r"; + SendMessage(player, message); + return; + } + MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]); + SendMessage(player, "Player name: "+p.PlayerName); + SendMessage(player, "User flair: "+p.Flair); + SendMessage(player, "Username: "+p.UserName); + SendMessage(player, "Flair accepted: "+p.AcceptedFlair); + SendMessage(player, "Flair ignored: "+p.IgnoredFlair); + } + private static void SendMessage(Player player, String message) + { //2015.08.09. + if(player==null) + System.out.println(message); + else + player.sendMessage(message); + } + private static void DoGetLastError(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "getlasterror" + if(PluginMain.LastException!=null) + { + SendMessage(player, "Last error:"); + SendMessage(player, PluginMain.LastException.toString()); + PluginMain.LastException=null; + } + else + SendMessage(player, "There were no exceptions."); + } + private static void SetPlayerFlair(Player player, Player targetplayer, String flair) + { //2015.08.09. + flair=flair.replace('&', '§'); + MaybeOfflinePlayer.AddPlayerIfNeeded(player.getName()).Flair=flair; + if(!PluginMain.RemoveLineFromFile("customflairs.txt", targetplayer.getName())) + { + SendMessage(player, "§cError removing previous custom flair!§r"); + return; + } + File file=new File("customflairs.txt"); + try { + BufferedWriter bw; + bw = new BufferedWriter(new FileWriter(file, true)); + bw.write(targetplayer.getName()+"\n"); + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + PluginMain.LastException=e; //2015.08.09. + } + SendMessage(player, "§6The flair has been set. Player: "+targetplayer.getName()+" Flair: "+flair+"§r"); + } + private static void DoSetFlair(Player player, String args) + { + //args[0] is "admin" - args[1] is "setflair" + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/22/50fe465a863e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/22/50fe465a863e00151ce8ff6d4f74dabd deleted file mode 100644 index 4e09c08..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/22/50fe465a863e00151ce8ff6d4f74dabd +++ /dev/null @@ -1,131 +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; - MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. - //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - if(p.Flair==null) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. - { - case "accept": - { - if(p.IgnoredFlair) - p.IgnoredFlair=false; //2015.08.08. - if(!p.AcceptedFlair) - { - String flair=p.Flair; //2015.08.08. - PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. - p.AcceptedFlair=true; //2015.08.08. - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("§cYou already have this user's flair.§r"); - break; - } - case "ignore": - { - if(p.AcceptedFlair) - p.AcceptedFlair=false; //2015.08.08. - if(!p.IgnoredFlair) - { - p.IgnoredFlair=true; - String flair=p.Flair; //2015.08.08. - PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. - player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); - } - else - player.sendMessage("§cYou already ignored this request.§r"); - break; - } - case "reload": //2015.07.20. - DoReload(player); - break; - case "admin": //2015.08.09. - DoAdmin(player); - break; - default: - return false; - } - return true; - } - - if(args[0].toLowerCase()=="reload") - DoReload(null); //2015.07.20. - else if(args[0].toLowerCase()=="admin") - DoAdmin(null); //2015.08.09. - return false; - } - private static void DoReload(Player player) - { //2015.07.20. - if(player==null || player.isOp() || player.getName()=="NorbiPeti") - { - try - { - File file=new File("autoflairconfig.txt"); - if(file.exists()) - { - PluginMain.TownColors.clear(); - BufferedReader br=new BufferedReader(new FileReader(file)); - String line; - while((line=br.readLine())!=null) - { - String[] s=line.split(" "); - PluginMain.TownColors.put(s[0], s[1]); - } - br.close(); - for(Player p : PluginMain.GetPlayers()) - { - MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName()); - if(mp.Flair!=null) - { - String flair=mp.Flair; - PluginMain.RemovePlayerDisplayFlairFinal(p, flair); - PluginMain.AppendPlayerDisplayFlairFinal(p, flair); - } - } - String msg="§6Reloaded config file.§r"; - if(player!=null) - player.sendMessage(msg); - else - System.out.println(msg); - } - } - catch(Exception e) - { - System.out.println("Error!\n"+e); - if(player!=null) - player.sendMessage("§cAn error occured. See console for details.§r"); - } - } - else - player.sendMessage("§cYou need to be OP to use this command.§r"); - } - private static void DoAdmin(Player player) - { - if(player==null || player.isOp() || player.getName()=="NorbiPeti") - { - - } - else - player.sendMessage("§cYou need to be OP to use this command.§r"); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/22/8052bd83df3e001517108d149b613203 b/.metadata/.plugins/org.eclipse.core.resources/.history/22/8052bd83df3e001517108d149b613203 new file mode 100644 index 0000000..2bbf620 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/22/8052bd83df3e001517108d149b613203 @@ -0,0 +1,252 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +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; + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. + //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) + if(p.Flair==null) + { + player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); + return true; + } + switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. + { + case "accept": + { + if(p.IgnoredFlair) + p.IgnoredFlair=false; //2015.08.08. + if(!p.AcceptedFlair) + { + String flair=p.Flair; //2015.08.08. + //PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + PluginMain.AppendPlayerDisplayFlair(p, player); + p.AcceptedFlair=true; //2015.08.08. + player.sendMessage("§6Your flair has been set:§r "+flair); + } + else + player.sendMessage("§cYou already have this user's flair.§r"); + break; + } + case "ignore": + { + if(p.AcceptedFlair) + p.AcceptedFlair=false; //2015.08.08. + if(!p.IgnoredFlair) + { + p.IgnoredFlair=true; + String flair=p.Flair; //2015.08.08. + PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. + player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); + } + else + player.sendMessage("§cYou already ignored this request.§r"); + break; + } + /*case "reload": //2015.07.20. + DoReload(player); + break;*/ + case "admin": //2015.08.09. + DoAdmin(player, args); + break; + case "nonpresser": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§7(non-pr.)§r"; + break; + case "cantpress": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§r(can't press)§r"; + break; + default: + return false; + } + return true; + } + /*if(args[0].toLowerCase()=="reload") + DoReload(null); //2015.07.20.*/ + else if(args.length>0 && args[0].toLowerCase().equals("admin")) //2015.08.09. + { + DoAdmin(null, args); //2015.08.09. + return true; //2015.08.09. + } + return false; + } + private static void DoReload(Player player) + { //2015.07.20. + //if(player==null || player.isOp() || player.getName()=="NorbiPeti") + //{ + try + { + File file=new File("autoflairconfig.txt"); + if(file.exists()) + { + PluginMain.LoadFiles(true); //2015.08.09. + for(Player p : PluginMain.GetPlayers()) + { + MaybeOfflinePlayer mp = MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName()); + if(mp.Flair!=null) + { + String flair=mp.Flair; + PluginMain.RemovePlayerDisplayFlairFinal(p, flair); + //PluginMain.AppendPlayerDisplayFlairFinal(p, flair); + PluginMain.AppendPlayerDisplayFlair(mp, p); //2015.08.09. + } + String msg="§6Note: The auto-flair plugin has been reloaded. You might need to wait 10s to have your flair.§r"; //2015.08.09. + p.sendMessage(msg); //2015.08.09. + } + //String msg="§6Reloaded config file.§r"; + //SendMessage(player, msg); //2015.08.09. + } + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + if(player!=null) + player.sendMessage("§cAn error occured. See console for details.§r"); + PluginMain.LastException=e; //2015.08.09. + } + //} + //else + //player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static Player ReloadPlayer; //2015.08.09. + private static void DoAdmin(Player player, String[] args) + { //2015.08.09. + if(player==null || player.isOp() || player.getName()=="NorbiPeti") + { + //System.out.println("Args length: " + args.length); + if(args.length==1) + { + String message="§cUsage: /u admin reload|playerinfo§r"; + SendMessage(player, message); + return; + } + //args[0] is "admin" + switch(args[1].toLowerCase()) + { + case "reload": + ReloadPlayer=player; //2015.08.09. + SendMessage(player, "§6Make sure to save the current settings before you modify and reload them! Type /u admin confirm when done.§r"); + break; + case "playerinfo": + DoPlayerInfo(player, args); + break; + case "getlasterror": + DoGetLastError(player, args); + case "confirm": + if(ReloadPlayer==player) + DoReload(player); //2015.08.09. + else + SendMessage(player, "§cYou need to do /u admin reload first.§r"); + break; + case "save": + PluginMain.SaveFiles(); //2015.08.09. + SendMessage(player, "§6Saved files. Now you can edit them and reload if you want.§r"); + break; + default: + String message="§cUsage: /u admin reload|playerinfo|getlasterror§r"; + SendMessage(player, message); + return; + } + } + else + player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static void DoPlayerInfo(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "playerinfo" + if(args.length==2) + { + String message="§cUsage: /u admin playerinfo §r"; + SendMessage(player, message); + return; + } + if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2])) + { + String message="§cPlayer not found: "+args[2]+"§r"; + SendMessage(player, message); + return; + } + MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]); + SendMessage(player, "Player name: "+p.PlayerName); + SendMessage(player, "User flair: "+p.Flair); + SendMessage(player, "Username: "+p.UserName); + SendMessage(player, "Flair accepted: "+p.AcceptedFlair); + SendMessage(player, "Flair ignored: "+p.IgnoredFlair); + } + private static void SendMessage(Player player, String message) + { //2015.08.09. + if(player==null) + System.out.println(message); + else + player.sendMessage(message); + } + private static void DoGetLastError(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "getlasterror" + if(PluginMain.LastException!=null) + { + SendMessage(player, "Last error:"); + SendMessage(player, PluginMain.LastException.toString()); + PluginMain.LastException=null; + } + else + SendMessage(player, "There were no exceptions."); + } + private static void SetPlayerFlair(Player player, Player targetplayer, String flair) + { //2015.08.09. + flair=flair.replace('&', '§'); + MaybeOfflinePlayer.AddPlayerIfNeeded(player.getName()).Flair=flair; + if(!PluginMain.RemoveLineFromFile("customflairs.txt", targetplayer.getName())) + { + SendMessage(player, "§cError removing previous custom flair!§r"); + return; + } + File file=new File("customflairs.txt"); + try { + BufferedWriter bw; + bw = new BufferedWriter(new FileWriter(file, true)); + bw.write(player.getName()+"\n"); + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + PluginMain.LastException=e; //2015.08.09. + } + SendMessage(player, "§6The flair has been set. Player: "+targetplayer.getName()+" Flair: "+flair+"§r"); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/22/a091cfc4d23e001518fa86d7ae2a1cf8 b/.metadata/.plugins/org.eclipse.core.resources/.history/22/a091cfc4d23e001518fa86d7ae2a1cf8 new file mode 100644 index 0000000..5d7321f --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/22/a091cfc4d23e001518fa86d7ae2a1cf8 @@ -0,0 +1,215 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; + +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class Commands implements CommandExecutor { + // This method is called, when somebody uses our command + @Override + public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { + if (sender instanceof Player) { + Player player = (Player) sender; + if(args.length<1) + return false; + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. + //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) + if(p.Flair==null) + { + player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); + return true; + } + switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. + { + case "accept": + { + if(p.IgnoredFlair) + p.IgnoredFlair=false; //2015.08.08. + if(!p.AcceptedFlair) + { + String flair=p.Flair; //2015.08.08. + //PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + PluginMain.AppendPlayerDisplayFlair(p, player); + p.AcceptedFlair=true; //2015.08.08. + player.sendMessage("§6Your flair has been set:§r "+flair); + } + else + player.sendMessage("§cYou already have this user's flair.§r"); + break; + } + case "ignore": + { + if(p.AcceptedFlair) + p.AcceptedFlair=false; //2015.08.08. + if(!p.IgnoredFlair) + { + p.IgnoredFlair=true; + String flair=p.Flair; //2015.08.08. + PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. + player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); + } + else + player.sendMessage("§cYou already ignored this request.§r"); + break; + } + /*case "reload": //2015.07.20. + DoReload(player); + break;*/ + case "admin": //2015.08.09. + DoAdmin(player, args); + break; + case "nonpresser": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§7(non-pr.)§r"; + break; + case "cantpress": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§r(can't press)§r"; + break; + default: + return false; + } + return true; + } + /*if(args[0].toLowerCase()=="reload") + DoReload(null); //2015.07.20.*/ + else if(args.length>0 && args[0].toLowerCase().equals("admin")) //2015.08.09. + { + DoAdmin(null, args); //2015.08.09. + return true; //2015.08.09. + } + return false; + } + private static void DoReload(Player player) + { //2015.07.20. + //if(player==null || player.isOp() || player.getName()=="NorbiPeti") + //{ + try + { + File file=new File("autoflairconfig.txt"); + if(file.exists()) + { + PluginMain.LoadFiles(true); //2015.08.09. + 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); + PluginMain.AppendPlayerDisplayFlair(mp, p); //2015.08.09. + } + } + //String msg="§6Reloaded config file.§r"; + String msg="§6Reloaded all files.§r"; + SendMessage(player, msg); //2015.08.09. + } + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + if(player!=null) + player.sendMessage("§cAn error occured. See console for details.§r"); + PluginMain.LastException=e; //2015.08.09. + } + //} + //else + //player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static void DoAdmin(Player player, String[] args) + { //2015.08.09. + if(player==null || player.isOp() || player.getName()=="NorbiPeti") + { + //System.out.println("Args length: " + args.length); + if(args.length==1) + { + String message="§cUsage: /u admin reload|playerinfo§r"; + SendMessage(player, message); + return; + } + //args[0] is "admin" + switch(args[1].toLowerCase()) + { + case "reload": + DoReload(player); + break; + case "playerinfo": + DoPlayerInfo(player, args); + break; + case "getlasterror": + DoGetLastError(player, args); + default: + String message="§cUsage: /u admin reload|playerinfo§r"; + SendMessage(player, message); + return; + } + } + else + player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static void DoPlayerInfo(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "playerinfo" + if(args.length==2) + { + String message="§cUsage: /u admin playerinfo §r"; + SendMessage(player, message); + return; + } + if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2])) + { + String message="§cPlayer not found: "+args[2]+"§r"; + SendMessage(player, message); + return; + } + MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]); + SendMessage(player, "Player name: "+p.PlayerName); + SendMessage(player, "User flair: "+p.Flair); + SendMessage(player, "Username: "+p.UserName); + SendMessage(player, "Flair accepted: "+p.AcceptedFlair); + SendMessage(player, "Flair ignored: "+p.IgnoredFlair); + } + private static void SendMessage(Player player, String message) + { //2015.08.09. + if(player==null) + System.out.println(message); + else + player.sendMessage(message); + } + private static void DoGetLastError(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "getlasterror" + if(PluginMain.LastException!=null) + { + SendMessage(player, "Last error:"); + SendMessage(player, PluginMain.LastException.toString()); + PluginMain.LastException=null; + } + else + SendMessage(player, "There were no exceptions."); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/23/a0c7c72cd33e001518fa86d7ae2a1cf8 b/.metadata/.plugins/org.eclipse.core.resources/.history/23/a0c7c72cd33e001518fa86d7ae2a1cf8 new file mode 100644 index 0000000..f17161d --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/23/a0c7c72cd33e001518fa86d7ae2a1cf8 @@ -0,0 +1,216 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; + +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class Commands implements CommandExecutor { + // This method is called, when somebody uses our command + @Override + public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { + if (sender instanceof Player) { + Player player = (Player) sender; + if(args.length<1) + return false; + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. + //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) + if(p.Flair==null) + { + player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); + return true; + } + switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. + { + case "accept": + { + if(p.IgnoredFlair) + p.IgnoredFlair=false; //2015.08.08. + if(!p.AcceptedFlair) + { + String flair=p.Flair; //2015.08.08. + //PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + PluginMain.AppendPlayerDisplayFlair(p, player); + p.AcceptedFlair=true; //2015.08.08. + player.sendMessage("§6Your flair has been set:§r "+flair); + } + else + player.sendMessage("§cYou already have this user's flair.§r"); + break; + } + case "ignore": + { + if(p.AcceptedFlair) + p.AcceptedFlair=false; //2015.08.08. + if(!p.IgnoredFlair) + { + p.IgnoredFlair=true; + String flair=p.Flair; //2015.08.08. + PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. + player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); + } + else + player.sendMessage("§cYou already ignored this request.§r"); + break; + } + /*case "reload": //2015.07.20. + DoReload(player); + break;*/ + case "admin": //2015.08.09. + DoAdmin(player, args); + break; + case "nonpresser": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§7(non-pr.)§r"; + break; + case "cantpress": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§r(can't press)§r"; + break; + default: + return false; + } + return true; + } + /*if(args[0].toLowerCase()=="reload") + DoReload(null); //2015.07.20.*/ + else if(args.length>0 && args[0].toLowerCase().equals("admin")) //2015.08.09. + { + DoAdmin(null, args); //2015.08.09. + return true; //2015.08.09. + } + return false; + } + private static void DoReload(Player player) + { //2015.07.20. + //if(player==null || player.isOp() || player.getName()=="NorbiPeti") + //{ + try + { + File file=new File("autoflairconfig.txt"); + if(file.exists()) + { + PluginMain.LoadFiles(true); //2015.08.09. + for(Player p : PluginMain.GetPlayers()) + { + MaybeOfflinePlayer mp = MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName()); + if(mp.Flair!=null) + { + String flair=mp.Flair; + PluginMain.RemovePlayerDisplayFlairFinal(p, flair); + //PluginMain.AppendPlayerDisplayFlairFinal(p, flair); + PluginMain.AppendPlayerDisplayFlair(mp, p); //2015.08.09. + } + } + //String msg="§6Reloaded config file.§r"; + String msg="§6Note: The auto-flair plugin has been reloaded. You might need to wait 10s to have your flair.§r"; + //SendMessage(player, msg); //2015.08.09. + + } + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + if(player!=null) + player.sendMessage("§cAn error occured. See console for details.§r"); + PluginMain.LastException=e; //2015.08.09. + } + //} + //else + //player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static void DoAdmin(Player player, String[] args) + { //2015.08.09. + if(player==null || player.isOp() || player.getName()=="NorbiPeti") + { + //System.out.println("Args length: " + args.length); + if(args.length==1) + { + String message="§cUsage: /u admin reload|playerinfo§r"; + SendMessage(player, message); + return; + } + //args[0] is "admin" + switch(args[1].toLowerCase()) + { + case "reload": + DoReload(player); + break; + case "playerinfo": + DoPlayerInfo(player, args); + break; + case "getlasterror": + DoGetLastError(player, args); + default: + String message="§cUsage: /u admin reload|playerinfo§r"; + SendMessage(player, message); + return; + } + } + else + player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static void DoPlayerInfo(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "playerinfo" + if(args.length==2) + { + String message="§cUsage: /u admin playerinfo §r"; + SendMessage(player, message); + return; + } + if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2])) + { + String message="§cPlayer not found: "+args[2]+"§r"; + SendMessage(player, message); + return; + } + MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]); + SendMessage(player, "Player name: "+p.PlayerName); + SendMessage(player, "User flair: "+p.Flair); + SendMessage(player, "Username: "+p.UserName); + SendMessage(player, "Flair accepted: "+p.AcceptedFlair); + SendMessage(player, "Flair ignored: "+p.IgnoredFlair); + } + private static void SendMessage(Player player, String message) + { //2015.08.09. + if(player==null) + System.out.println(message); + else + player.sendMessage(message); + } + private static void DoGetLastError(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "getlasterror" + if(PluginMain.LastException!=null) + { + SendMessage(player, "Last error:"); + SendMessage(player, PluginMain.LastException.toString()); + PluginMain.LastException=null; + } + else + SendMessage(player, "There were no exceptions."); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/24/d0c95a0cd93e001517108d149b613203 b/.metadata/.plugins/org.eclipse.core.resources/.history/24/d0c95a0cd93e001517108d149b613203 new file mode 100644 index 0000000..b9d957a --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/24/d0c95a0cd93e001517108d149b613203 @@ -0,0 +1,224 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; + +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class Commands implements CommandExecutor { + // This method is called, when somebody uses our command + @Override + public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { + if (sender instanceof Player) { + Player player = (Player) sender; + if(args.length<1) + return false; + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. + //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) + if(p.Flair==null) + { + player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); + return true; + } + switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. + { + case "accept": + { + if(p.IgnoredFlair) + p.IgnoredFlair=false; //2015.08.08. + if(!p.AcceptedFlair) + { + String flair=p.Flair; //2015.08.08. + //PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + PluginMain.AppendPlayerDisplayFlair(p, player); + p.AcceptedFlair=true; //2015.08.08. + player.sendMessage("§6Your flair has been set:§r "+flair); + } + else + player.sendMessage("§cYou already have this user's flair.§r"); + break; + } + case "ignore": + { + if(p.AcceptedFlair) + p.AcceptedFlair=false; //2015.08.08. + if(!p.IgnoredFlair) + { + p.IgnoredFlair=true; + String flair=p.Flair; //2015.08.08. + PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. + player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); + } + else + player.sendMessage("§cYou already ignored this request.§r"); + break; + } + /*case "reload": //2015.07.20. + DoReload(player); + break;*/ + case "admin": //2015.08.09. + DoAdmin(player, args); + break; + case "nonpresser": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§7(non-pr.)§r"; + break; + case "cantpress": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§r(can't press)§r"; + break; + default: + return false; + } + return true; + } + /*if(args[0].toLowerCase()=="reload") + DoReload(null); //2015.07.20.*/ + else if(args.length>0 && args[0].toLowerCase().equals("admin")) //2015.08.09. + { + DoAdmin(null, args); //2015.08.09. + return true; //2015.08.09. + } + return false; + } + private static void DoReload(Player player) + { //2015.07.20. + //if(player==null || player.isOp() || player.getName()=="NorbiPeti") + //{ + try + { + File file=new File("autoflairconfig.txt"); + if(file.exists()) + { + PluginMain.LoadFiles(true); //2015.08.09. + for(Player p : PluginMain.GetPlayers()) + { + MaybeOfflinePlayer mp = MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName()); + if(mp.Flair!=null) + { + String flair=mp.Flair; + PluginMain.RemovePlayerDisplayFlairFinal(p, flair); + //PluginMain.AppendPlayerDisplayFlairFinal(p, flair); + PluginMain.AppendPlayerDisplayFlair(mp, p); //2015.08.09. + } + String msg="§6Note: The auto-flair plugin has been reloaded. You might need to wait 10s to have your flair.§r"; //2015.08.09. + p.sendMessage(msg); //2015.08.09. + } + //String msg="§6Reloaded config file.§r"; + //SendMessage(player, msg); //2015.08.09. + } + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + if(player!=null) + player.sendMessage("§cAn error occured. See console for details.§r"); + PluginMain.LastException=e; //2015.08.09. + } + //} + //else + //player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static Player ReloadPlayer; //2015.08.09. + private static void DoAdmin(Player player, String[] args) + { //2015.08.09. + if(player==null || player.isOp() || player.getName()=="NorbiPeti") + { + //System.out.println("Args length: " + args.length); + if(args.length==1) + { + String message="§cUsage: /u admin reload|playerinfo§r"; + SendMessage(player, message); + return; + } + //args[0] is "admin" + switch(args[1].toLowerCase()) + { + case "reload": + ReloadPlayer=player; //2015.08.09. + SendMessage(player, "§6Make sure to save the current settings before you modify and reload them! Type /u admin confirm when done.§r"); + break; + case "playerinfo": + DoPlayerInfo(player, args); + break; + case "getlasterror": + DoGetLastError(player, args); + case "confirm": + if(ReloadPlayer!=null && ReloadPlayer.equals(player)) + DoReload(player); //2015.08.09. + else + SendMessage(player, "§cYou need to do /u admin reload first.§r"); + break; + default: + String message="§cUsage: /u admin reload|playerinfo|getlasterror§r"; + SendMessage(player, message); + return; + } + } + else + player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static void DoPlayerInfo(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "playerinfo" + if(args.length==2) + { + String message="§cUsage: /u admin playerinfo §r"; + SendMessage(player, message); + return; + } + if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2])) + { + String message="§cPlayer not found: "+args[2]+"§r"; + SendMessage(player, message); + return; + } + MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]); + SendMessage(player, "Player name: "+p.PlayerName); + SendMessage(player, "User flair: "+p.Flair); + SendMessage(player, "Username: "+p.UserName); + SendMessage(player, "Flair accepted: "+p.AcceptedFlair); + SendMessage(player, "Flair ignored: "+p.IgnoredFlair); + } + private static void SendMessage(Player player, String message) + { //2015.08.09. + if(player==null) + System.out.println(message); + else + player.sendMessage(message); + } + private static void DoGetLastError(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "getlasterror" + if(PluginMain.LastException!=null) + { + SendMessage(player, "Last error:"); + SendMessage(player, PluginMain.LastException.toString()); + PluginMain.LastException=null; + } + else + SendMessage(player, "There were no exceptions."); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/25/3067ea8bd13e001518fa86d7ae2a1cf8 b/.metadata/.plugins/org.eclipse.core.resources/.history/25/3067ea8bd13e001518fa86d7ae2a1cf8 new file mode 100644 index 0000000..c1c6d6a --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/25/3067ea8bd13e001518fa86d7ae2a1cf8 @@ -0,0 +1,326 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStream; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLConnection; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + +import org.apache.commons.io.IOUtils; +import org.bukkit.entity.Player; +import org.bukkit.plugin.java.JavaPlugin; +import org.json.JSONArray; +import org.json.JSONObject; + +import com.palmergames.bukkit.towny.object.Town; +import com.palmergames.bukkit.towny.object.WorldCoord; + +public class PluginMain extends JavaPlugin +{ //Translated to Java: 2015.07.15. + //A user, which flair isn't obtainable: + //https://www.reddit.com/r/thebutton/comments/31c32v/i_pressed_the_button_without_really_thinking/ + private static PluginMain Instance; + // Fired when plugin is first enabled + @Override + public void onEnable() + { + System.out.println("The Button Auto-flair Plugin by NorbiPeti (:P)"); + getServer().getPluginManager().registerEvents(new PlayerListener(), this); + this.getCommand("u").setExecutor(new Commands()); + this.getCommand("u").setUsage(this.getCommand("u").getUsage().replace('&', '§')); + Instance=this; //2015.08.08. + Load(false); + Runnable r=new Runnable(){public void run(){ThreadMethod();}}; + Thread t=new Thread(r); + t.start(); + } + Boolean stop=false; + // Fired when plugin is disabled + @Override + public void onDisable() + { + try + { + FileWriter fw; + fw = new FileWriter("flairsaccepted.txt"); + fw.close(); + fw = new FileWriter("flairsignored.txt"); + fw.close(); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + try { + File file=new File("flairsaccepted.txt"); + BufferedWriter bw=new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.AcceptedFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + file=new File("flairsignored.txt"); + bw = new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.IgnoredFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + stop=true; + } + + public void ThreadMethod() //<-- 2015.07.16. + { + while(!stop) + { + try + { + String body=DownloadString("https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/autoflair_system_comment_your_minecraft_name_and/.json?limit=1000"); + JSONArray json=new JSONArray(body).getJSONObject(1).getJSONObject("data").getJSONArray("children"); + for(Object obj : json) + { + JSONObject item = (JSONObject)obj; + String author=item.getJSONObject("data").getString("author"); + String ign=item.getJSONObject("data").getString("body"); + int start = ign.indexOf("IGN:") + "IGN:".length(); + int end = ign.indexOf(' ', start); + if (end == -1 || end == start) + end=ign.indexOf('\n', start); //2015.07.15. + if (end == -1 || end == start) + ign = ign.substring(start); + else + ign = ign.substring(start, end); + ign = ign.trim(); + if(HasIGFlair(ign)) + continue; + try { + Thread.sleep(10); + } catch(InterruptedException ex) { + Thread.currentThread().interrupt(); + } + String[] flairdata = DownloadString("http://karmadecay.com/thebutton-data.php?users=" + author).replace("\"", "").split(":"); + String flair; + if(flairdata.length > 1) //2015.07.15. + flair = flairdata[1]; + else + flair=""; + if (flair != "-1") + flair = flair + "s"; + else + flair = "non-presser"; + String flairclass; + if(flairdata.length>2) + flairclass = flairdata[2]; + else + flairclass="unknown"; + SetFlair(ign, flair, flairclass, author); + } + Thread.sleep(10000); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + } + + public static Exception LastException; //2015.08.09. + + public String DownloadString(String urlstr) throws MalformedURLException, IOException + { + URL url = new URL(urlstr); + URLConnection con = url.openConnection(); + con.setRequestProperty("User-Agent", "TheButtonAutoFlair"); + InputStream in = con.getInputStream(); + String encoding = con.getContentEncoding(); + encoding = encoding == null ? "UTF-8" : encoding; + String body = IOUtils.toString(in, encoding); + in.close(); + return body; + } + + public static Map TownColors=new HashMap(); //2015.07.20. + public Boolean HasIGFlair(String playername) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + return p.Flair!=null; //2015.08.08. + } + + public void SetFlair(String playername, String text, String flairclass, String username) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + String finalflair; + p.FlairDecided=true; + switch(flairclass) + { + case "press-1": + finalflair="§c("+text+")§r"; + break; + case "press-2": + finalflair="§6("+text+")§r"; + break; + case "press-3": + finalflair="§e("+text+")§r"; + break; + case "press-4": + finalflair="§a("+text+")§r"; + break; + case "press-5": + finalflair="§9("+text+")§r"; + break; + 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; + case "undecided": //2015.08.09. + p.FlairDecided=false; + finalflair=""; + break; + default: + finalflair=""; + break; + } + if(finalflair.length()==0) //<-- 2015.07.20. + return; + p.Flair=finalflair; //2015.08.08. + p.UserName=username; //2015.08.08. + System.out.println("Added new flair to "+playername+": "+finalflair); + for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08. + { + if(player.getName().equals(playername)) + { + //AppendPlayerDisplayFlair(player, username, finalflair); + AppendPlayerDisplayFlair(p, player); + break; + } + } + } + + public static String GetFlair(Player player) + { //2015.07.16. + String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08. + return flair==null ? "" : flair; + } + + //public static void AppendPlayerDisplayFlair(Player player, String username, String flair) + public static void AppendPlayerDisplayFlair(MaybeOfflinePlayer player, Player p) //<-- 2015.08.09. + { + + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).IgnoredFlair) + return; + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).AcceptedFlair) + { + AppendPlayerDisplayFlairFinal(p, player.Flair); //2015.07.20. + if(!player.FlairDecided) + p.sendMessage("§9Your flair type is unknown. Are you a non-presser or a can't press? (/u nonpresser or /u cantpress)§r"); //2015.08.09. + } + else + p.sendMessage("§9Are you Reddit user "+player.UserName+"?§r §6Type /u accept or /u ignore§r"); + } + + private static void AppendPlayerDisplayFlairFinal(Player player, String flair) + { //2015.07.20. + String color = GetColorForTown(GetPlayerTown(player)); //TO!DO: Multiple colors put on first capital letters + String[] colors = color.substring(1).split("§"); + String displayname=player.getName(); //2015.08.08. + ArrayList Positions=new ArrayList<>(); + for(int i=0; i=colors.length) + { + int x=0; + for(int i=0; i GetPlayers() + { + return Instance.getServer().getOnlinePlayers(); + } + + public static void LoadFiles(boolean reload) + { + + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/25/902f77f1de3e001517108d149b613203 b/.metadata/.plugins/org.eclipse.core.resources/.history/25/902f77f1de3e001517108d149b613203 new file mode 100644 index 0000000..74f21a1 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/25/902f77f1de3e001517108d149b613203 @@ -0,0 +1,250 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +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; + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. + //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) + if(p.Flair==null) + { + player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); + return true; + } + switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. + { + case "accept": + { + if(p.IgnoredFlair) + p.IgnoredFlair=false; //2015.08.08. + if(!p.AcceptedFlair) + { + String flair=p.Flair; //2015.08.08. + //PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + PluginMain.AppendPlayerDisplayFlair(p, player); + p.AcceptedFlair=true; //2015.08.08. + player.sendMessage("§6Your flair has been set:§r "+flair); + } + else + player.sendMessage("§cYou already have this user's flair.§r"); + break; + } + case "ignore": + { + if(p.AcceptedFlair) + p.AcceptedFlair=false; //2015.08.08. + if(!p.IgnoredFlair) + { + p.IgnoredFlair=true; + String flair=p.Flair; //2015.08.08. + PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. + player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); + } + else + player.sendMessage("§cYou already ignored this request.§r"); + break; + } + /*case "reload": //2015.07.20. + DoReload(player); + break;*/ + case "admin": //2015.08.09. + DoAdmin(player, args); + break; + case "nonpresser": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§7(non-pr.)§r"; + break; + case "cantpress": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§r(can't press)§r"; + break; + default: + return false; + } + return true; + } + /*if(args[0].toLowerCase()=="reload") + DoReload(null); //2015.07.20.*/ + else if(args.length>0 && args[0].toLowerCase().equals("admin")) //2015.08.09. + { + DoAdmin(null, args); //2015.08.09. + return true; //2015.08.09. + } + return false; + } + private static void DoReload(Player player) + { //2015.07.20. + //if(player==null || player.isOp() || player.getName()=="NorbiPeti") + //{ + try + { + File file=new File("autoflairconfig.txt"); + if(file.exists()) + { + PluginMain.LoadFiles(true); //2015.08.09. + for(Player p : PluginMain.GetPlayers()) + { + MaybeOfflinePlayer mp = MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName()); + if(mp.Flair!=null) + { + String flair=mp.Flair; + PluginMain.RemovePlayerDisplayFlairFinal(p, flair); + //PluginMain.AppendPlayerDisplayFlairFinal(p, flair); + PluginMain.AppendPlayerDisplayFlair(mp, p); //2015.08.09. + } + String msg="§6Note: The auto-flair plugin has been reloaded. You might need to wait 10s to have your flair.§r"; //2015.08.09. + p.sendMessage(msg); //2015.08.09. + } + //String msg="§6Reloaded config file.§r"; + //SendMessage(player, msg); //2015.08.09. + } + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + if(player!=null) + player.sendMessage("§cAn error occured. See console for details.§r"); + PluginMain.LastException=e; //2015.08.09. + } + //} + //else + //player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static Player ReloadPlayer; //2015.08.09. + private static void DoAdmin(Player player, String[] args) + { //2015.08.09. + if(player==null || player.isOp() || player.getName()=="NorbiPeti") + { + //System.out.println("Args length: " + args.length); + if(args.length==1) + { + String message="§cUsage: /u admin reload|playerinfo§r"; + SendMessage(player, message); + return; + } + //args[0] is "admin" + switch(args[1].toLowerCase()) + { + case "reload": + ReloadPlayer=player; //2015.08.09. + SendMessage(player, "§6Make sure to save the current settings before you modify and reload them! Type /u admin confirm when done.§r"); + break; + case "playerinfo": + DoPlayerInfo(player, args); + break; + case "getlasterror": + DoGetLastError(player, args); + case "confirm": + if(ReloadPlayer==player) + DoReload(player); //2015.08.09. + else + SendMessage(player, "§cYou need to do /u admin reload first.§r"); + break; + case "save": + PluginMain.SaveFiles(); //2015.08.09. + SendMessage(player, "§6Saved files. Now you can edit them and reload if you want.§r"); + break; + default: + String message="§cUsage: /u admin reload|playerinfo|getlasterror§r"; + SendMessage(player, message); + return; + } + } + else + player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static void DoPlayerInfo(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "playerinfo" + if(args.length==2) + { + String message="§cUsage: /u admin playerinfo §r"; + SendMessage(player, message); + return; + } + if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2])) + { + String message="§cPlayer not found: "+args[2]+"§r"; + SendMessage(player, message); + return; + } + MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]); + SendMessage(player, "Player name: "+p.PlayerName); + SendMessage(player, "User flair: "+p.Flair); + SendMessage(player, "Username: "+p.UserName); + SendMessage(player, "Flair accepted: "+p.AcceptedFlair); + SendMessage(player, "Flair ignored: "+p.IgnoredFlair); + } + public static void SendMessage(Player player, String message) + { //2015.08.09. + if(player==null) + System.out.println(message); + else + player.sendMessage(message); + } + private static void DoGetLastError(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "getlasterror" + if(PluginMain.LastException!=null) + { + SendMessage(player, "Last error:"); + SendMessage(player, PluginMain.LastException.toString()); + PluginMain.LastException=null; + } + else + SendMessage(player, "There were no exceptions."); + } + private static void SetPlayerFlair(Player player, String flair) + { //2015.08.09. + flair=flair.replace('&', '§'); + MaybeOfflinePlayer.AddPlayerIfNeeded(player.getName()).Flair=flair; + if(!RemoveLineFromFile("customflairs.txt")) + { + Commands.SendMessage(player, "") + } + File file=new File("customflairs.txt"); + try { + BufferedWriter bw; + bw = new BufferedWriter(new FileWriter(file, true)); + bw.write(player.getName()+"\n"); + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/26/00298c12e03e001517108d149b613203 b/.metadata/.plugins/org.eclipse.core.resources/.history/26/00298c12e03e001517108d149b613203 new file mode 100644 index 0000000..2b242de --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/26/00298c12e03e001517108d149b613203 @@ -0,0 +1,260 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +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; + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. + //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) + if(p.Flair==null) + { + player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); + return true; + } + switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. + { + case "accept": + { + if(p.IgnoredFlair) + p.IgnoredFlair=false; //2015.08.08. + if(!p.AcceptedFlair) + { + String flair=p.Flair; //2015.08.08. + //PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + PluginMain.AppendPlayerDisplayFlair(p, player); + p.AcceptedFlair=true; //2015.08.08. + player.sendMessage("§6Your flair has been set:§r "+flair); + } + else + player.sendMessage("§cYou already have this user's flair.§r"); + break; + } + case "ignore": + { + if(p.AcceptedFlair) + p.AcceptedFlair=false; //2015.08.08. + if(!p.IgnoredFlair) + { + p.IgnoredFlair=true; + String flair=p.Flair; //2015.08.08. + PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. + player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); + } + else + player.sendMessage("§cYou already ignored this request.§r"); + break; + } + /*case "reload": //2015.07.20. + DoReload(player); + break;*/ + case "admin": //2015.08.09. + DoAdmin(player, args); + break; + case "nonpresser": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§7(non-pr.)§r"; + break; + case "cantpress": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§r(can't press)§r"; + break; + default: + return false; + } + return true; + } + /*if(args[0].toLowerCase()=="reload") + DoReload(null); //2015.07.20.*/ + else if(args.length>0 && args[0].toLowerCase().equals("admin")) //2015.08.09. + { + DoAdmin(null, args); //2015.08.09. + return true; //2015.08.09. + } + return false; + } + private static void DoReload(Player player) + { //2015.07.20. + //if(player==null || player.isOp() || player.getName()=="NorbiPeti") + //{ + try + { + File file=new File("autoflairconfig.txt"); + if(file.exists()) + { + PluginMain.LoadFiles(true); //2015.08.09. + for(Player p : PluginMain.GetPlayers()) + { + MaybeOfflinePlayer mp = MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName()); + if(mp.Flair!=null) + { + String flair=mp.Flair; + PluginMain.RemovePlayerDisplayFlairFinal(p, flair); + //PluginMain.AppendPlayerDisplayFlairFinal(p, flair); + PluginMain.AppendPlayerDisplayFlair(mp, p); //2015.08.09. + } + String msg="§6Note: The auto-flair plugin has been reloaded. You might need to wait 10s to have your flair.§r"; //2015.08.09. + p.sendMessage(msg); //2015.08.09. + } + //String msg="§6Reloaded config file.§r"; + //SendMessage(player, msg); //2015.08.09. + } + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + if(player!=null) + player.sendMessage("§cAn error occured. See console for details.§r"); + PluginMain.LastException=e; //2015.08.09. + } + //} + //else + //player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static Player ReloadPlayer; //2015.08.09. + private static void DoAdmin(Player player, String[] args) + { //2015.08.09. + if(player==null || player.isOp() || player.getName()=="NorbiPeti") + { + //System.out.println("Args length: " + args.length); + if(args.length==1) + { + String message="§cUsage: /u admin reload|playerinfo§r"; + SendMessage(player, message); + return; + } + //args[0] is "admin" + switch(args[1].toLowerCase()) + { + case "reload": + ReloadPlayer=player; //2015.08.09. + SendMessage(player, "§6Make sure to save the current settings before you modify and reload them! Type /u admin confirm when done.§r"); + break; + case "playerinfo": + DoPlayerInfo(player, args); + break; + case "getlasterror": + DoGetLastError(player, args); + case "confirm": + if(ReloadPlayer==player) + DoReload(player); //2015.08.09. + else + SendMessage(player, "§cYou need to do /u admin reload first.§r"); + break; + case "save": + PluginMain.SaveFiles(); //2015.08.09. + SendMessage(player, "§6Saved files. Now you can edit them and reload if you want.§r"); + break; + case "setflair": + + break; + default: + String message="§cUsage: /u admin reload|playerinfo|getlasterror|save§r"; + SendMessage(player, message); + return; + } + } + else + player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static void DoPlayerInfo(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "playerinfo" + if(args.length==2) + { + String message="§cUsage: /u admin playerinfo §r"; + SendMessage(player, message); + return; + } + if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2])) + { + String message="§cPlayer not found: "+args[2]+"§r"; + SendMessage(player, message); + return; + } + MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]); + SendMessage(player, "Player name: "+p.PlayerName); + SendMessage(player, "User flair: "+p.Flair); + SendMessage(player, "Username: "+p.UserName); + SendMessage(player, "Flair accepted: "+p.AcceptedFlair); + SendMessage(player, "Flair ignored: "+p.IgnoredFlair); + } + private static void SendMessage(Player player, String message) + { //2015.08.09. + if(player==null) + System.out.println(message); + else + player.sendMessage(message); + } + private static void DoGetLastError(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "getlasterror" + if(PluginMain.LastException!=null) + { + SendMessage(player, "Last error:"); + SendMessage(player, PluginMain.LastException.toString()); + PluginMain.LastException=null; + } + else + SendMessage(player, "There were no exceptions."); + } + private static void SetPlayerFlair(Player player, Player targetplayer, String flair) + { //2015.08.09. + flair=flair.replace('&', '§'); + MaybeOfflinePlayer.AddPlayerIfNeeded(player.getName()).Flair=flair; + if(!PluginMain.RemoveLineFromFile("customflairs.txt", targetplayer.getName())) + { + SendMessage(player, "§cError removing previous custom flair!§r"); + return; + } + File file=new File("customflairs.txt"); + try { + BufferedWriter bw; + bw = new BufferedWriter(new FileWriter(file, true)); + bw.write(targetplayer.getName()+"\n"); + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + PluginMain.LastException=e; //2015.08.09. + } + SendMessage(player, "§6The flair has been set. Player: "+targetplayer.getName()+" Flair: "+flair+"§r"); + } + private static void DoSetFlair(Player player, String args) + { + //args[0] is "admin" - args[1] is "setflair" + s + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/26/108127addd3e001517108d149b613203 b/.metadata/.plugins/org.eclipse.core.resources/.history/26/108127addd3e001517108d149b613203 new file mode 100644 index 0000000..3da8073 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/26/108127addd3e001517108d149b613203 @@ -0,0 +1,403 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStream; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLConnection; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + +import org.apache.commons.io.IOUtils; +import org.bukkit.entity.Player; +import org.bukkit.plugin.java.JavaPlugin; +import org.json.JSONArray; +import org.json.JSONObject; + +import com.palmergames.bukkit.towny.object.Town; +import com.palmergames.bukkit.towny.object.WorldCoord; + +public class PluginMain extends JavaPlugin +{ //Translated to Java: 2015.07.15. + //A user, which flair isn't obtainable: + //https://www.reddit.com/r/thebutton/comments/31c32v/i_pressed_the_button_without_really_thinking/ + private static PluginMain Instance; + // Fired when plugin is first enabled + @Override + public void onEnable() + { + System.out.println("The Button Auto-flair Plugin by NorbiPeti (:P)"); + getServer().getPluginManager().registerEvents(new PlayerListener(), this); + this.getCommand("u").setExecutor(new Commands()); + this.getCommand("u").setUsage(this.getCommand("u").getUsage().replace('&', '§')); + Instance=this; //2015.08.08. + LoadFiles(false); //2015.08.09. + Runnable r=new Runnable(){public void run(){ThreadMethod();}}; + Thread t=new Thread(r); + t.start(); + } + Boolean stop=false; + // Fired when plugin is disabled + @Override + public void onDisable() + { + SaveFiles(); //2015.08.09. + stop=true; + } + + public void ThreadMethod() //<-- 2015.07.16. + { + while(!stop) + { + try + { + String body=DownloadString("https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/autoflair_system_comment_your_minecraft_name_and/.json?limit=1000"); + JSONArray json=new JSONArray(body).getJSONObject(1).getJSONObject("data").getJSONArray("children"); + for(Object obj : json) + { + JSONObject item = (JSONObject)obj; + String author=item.getJSONObject("data").getString("author"); + String ign=item.getJSONObject("data").getString("body"); + int start = ign.indexOf("IGN:") + "IGN:".length(); + if(start==-1) + continue; //2015.08.09. + int end = ign.indexOf(' ', start); + if (end == -1 || end == start) + end=ign.indexOf('\n', start); //2015.07.15. + if (end == -1 || end == start) + ign = ign.substring(start); + else + ign = ign.substring(start, end); + ign = ign.trim(); + if(HasIGFlair(ign)) + continue; + try { + Thread.sleep(10); + } catch(InterruptedException ex) { + Thread.currentThread().interrupt(); + } + String[] flairdata = DownloadString("http://karmadecay.com/thebutton-data.php?users=" + author).replace("\"", "").split(":"); + String flair; + if(flairdata.length > 1) //2015.07.15. + flair = flairdata[1]; + else + flair=""; + if (flair != "-1") + flair = flair + "s"; + else + flair = "non-presser"; + String flairclass; + if(flairdata.length>2) + flairclass = flairdata[2]; + else + flairclass="unknown"; + SetFlair(ign, flair, flairclass, author); + } + Thread.sleep(10000); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + } + + public static Exception LastException; //2015.08.09. + + public String DownloadString(String urlstr) throws MalformedURLException, IOException + { + URL url = new URL(urlstr); + URLConnection con = url.openConnection(); + con.setRequestProperty("User-Agent", "TheButtonAutoFlair"); + InputStream in = con.getInputStream(); + String encoding = con.getContentEncoding(); + encoding = encoding == null ? "UTF-8" : encoding; + String body = IOUtils.toString(in, encoding); + in.close(); + return body; + } + + public static Map TownColors=new HashMap(); //2015.07.20. + public Boolean HasIGFlair(String playername) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + return p.Flair!=null; //2015.08.08. + } + + public void SetFlair(String playername, String text, String flairclass, String username) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + String finalflair; + p.FlairDecided=true; + switch(flairclass) + { + case "press-1": + finalflair="§c("+text+")§r"; + break; + case "press-2": + finalflair="§6("+text+")§r"; + break; + case "press-3": + finalflair="§e("+text+")§r"; + break; + case "press-4": + finalflair="§a("+text+")§r"; + break; + case "press-5": + finalflair="§9("+text+")§r"; + break; + 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; + case "undecided": //2015.08.09. + p.FlairDecided=false; + finalflair=""; + break; + default: + finalflair=""; + break; + } + if(finalflair.length()==0) //<-- 2015.07.20. + return; + p.Flair=finalflair; //2015.08.08. + p.UserName=username; //2015.08.08. + System.out.println("Added new flair to "+playername+": "+finalflair); + for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08. + { + if(player.getName().equals(playername)) + { + //AppendPlayerDisplayFlair(player, username, finalflair); + AppendPlayerDisplayFlair(p, player); + break; + } + } + } + + public static String GetFlair(Player player) + { //2015.07.16. + String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08. + return flair==null ? "" : flair; + } + + //public static void AppendPlayerDisplayFlair(Player player, String username, String flair) + public static void AppendPlayerDisplayFlair(MaybeOfflinePlayer player, Player p) //<-- 2015.08.09. + { + + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).IgnoredFlair) + return; + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).AcceptedFlair) + { + AppendPlayerDisplayFlairFinal(p, player.Flair); //2015.07.20. + if(!player.FlairDecided) + p.sendMessage("§9Your flair type is unknown. Are you a non-presser or a can't press? (/u nonpresser or /u cantpress)§r"); //2015.08.09. + } + else + p.sendMessage("§9Are you Reddit user "+player.UserName+"?§r §6Type /u accept or /u ignore§r"); + } + + private static void AppendPlayerDisplayFlairFinal(Player player, String flair) + { //2015.07.20. + String color = GetColorForTown(GetPlayerTown(player)); //TO!DO: Multiple colors put on first capital letters + String[] colors = color.substring(1).split("§"); + String displayname=player.getName(); //2015.08.08. + ArrayList Positions=new ArrayList<>(); + for(int i=0; i=colors.length) + { + int x=0; + for(int i=0; i GetPlayers() + { + return Instance.getServer().getOnlinePlayers(); + } + + public static void LoadFiles(boolean reload) //<-- 2015.08.09. + { + if(reload) + { //2015.08.09. + System.out.println("Auto-flair plugin cleanup for reloading..."); + MaybeOfflinePlayer.AllPlayers.clear(); + TownColors.clear(); + } + System.out.println("Loading files for auto-flair plugin..."); //2015.08.09. + try { + File file=new File("flairsaccepted.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + //System.out.println("Name: " + name); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("flairsignored.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsignored.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("autoflairconfig.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + TownColors.put(s[0], s[1]); + } + br.close(); + } + file=new File("customflairs.txt"); //2015.08.09. + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + MaybeOfflinePlayer.AddPlayerIfNeeded(s[0]).Flair=s[1]; //2015.08.09. + } + br.close(); + } + //throw new IOException("Test"); //2015.08.09. + System.out.println("Auto-flair plugin loaded files!"); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + public static void SaveFiles() //<-- 2015.08.09. + { + try + { + FileWriter fw; + fw = new FileWriter("flairsaccepted.txt"); + fw.close(); + fw = new FileWriter("flairsignored.txt"); + fw.close(); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + try { + File file=new File("flairsaccepted.txt"); + BufferedWriter bw=new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.AcceptedFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + file=new File("flairsignored.txt"); + bw = new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.IgnoredFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + public static void SetPlayerFlair(Player player, String flair) + { //2015.08.09. + flair=flair.replace('&', '§'); + MaybeOfflinePlayer.AddPlayerIfNeeded(player.getName()).Flair=flair; + File file=new File("customflairs.txt"); + BufferedWriter bw=new BufferedWriter(new FileWriter(file, true)); + bw.write(player.PlayerName+"\n"); + bw.close(); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/f8/e04b0add303e00151cbdba8b5f0a340e b/.metadata/.plugins/org.eclipse.core.resources/.history/26/20fee89fce3e001518fa86d7ae2a1cf8 similarity index 70% rename from .metadata/.plugins/org.eclipse.core.resources/.history/f8/e04b0add303e00151cbdba8b5f0a340e rename to .metadata/.plugins/org.eclipse.core.resources/.history/26/20fee89fce3e001518fa86d7ae2a1cf8 index cf8ca2c..ab06769 100644 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/f8/e04b0add303e00151cbdba8b5f0a340e +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/26/20fee89fce3e001518fa86d7ae2a1cf8 @@ -21,8 +21,9 @@ import org.bukkit.plugin.java.JavaPlugin; import org.json.JSONArray; import org.json.JSONObject; +import tk.sznp.thebuttonautoflair.MaybeOfflinePlayer.FlairClassType; + 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 @@ -48,7 +49,7 @@ public class PluginMain extends JavaPlugin while ((line = br.readLine()) != null) { String name=line.replace("\n", ""); - System.out.println("Name: " + name); + //System.out.println("Name: " + name); MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08. } br.close(); @@ -77,8 +78,10 @@ public class PluginMain extends JavaPlugin } br.close(); } + //throw new IOException("Test"); //2015.08.09. } catch (IOException e) { System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. } Runnable r=new Runnable(){public void run(){ThreadMethod();}}; Thread t=new Thread(r); @@ -100,33 +103,31 @@ public class PluginMain extends JavaPlugin catch(Exception e) { System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. } - for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. - { - if(!player.AcceptedFlair) - continue; //2015.08.08. - File file=new File("flairsaccepted.txt"); - try { - BufferedWriter bw=new BufferedWriter(new FileWriter(file, true)); + try { + File file=new File("flairsaccepted.txt"); + BufferedWriter bw=new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.AcceptedFlair) + continue; //2015.08.08. bw.write(player.PlayerName+"\n"); - bw.close(); - } catch (IOException e) { - System.out.println("Error!\n"+e); - } - } - for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. - { - if(!player.IgnoredFlair) - continue; //2015.08.08. - File file=new File("flairsignored.txt"); - try { - BufferedWriter bw = new BufferedWriter(new FileWriter(file, true)); + } + bw.close(); + file=new File("flairsignored.txt"); + bw = new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.IgnoredFlair) + continue; //2015.08.08. bw.write(player.PlayerName+"\n"); - bw.close(); - } catch (IOException e) { - System.out.println("Error!\n"+e); - } - } + } + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } stop=true; } @@ -181,10 +182,13 @@ public class PluginMain extends JavaPlugin catch(Exception e) { System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. } } } + public static Exception LastException; //2015.08.09. + public String DownloadString(String urlstr) throws MalformedURLException, IOException { URL url = new URL(urlstr); @@ -198,37 +202,18 @@ public class PluginMain extends JavaPlugin return body; } - //It has to store offline player flairs too, therefore it can't use Player object - /*public static Map PlayerFlairs=new HashMap(); - public static Map PlayerUserNames=new HashMap(); - //public Map PlayerFlairs=new HashMap(); - public static ArrayList Players=new ArrayList(); - public static ArrayList AcceptedPlayers=new ArrayList(); //2015.07.16. - public static ArrayList IgnoredPlayers=new ArrayList(); //2015.07.16. - //public static Map PlayerTowns=new HashMap(); //2015.07.20.*/ public static Map TownColors=new HashMap(); //2015.07.20. public Boolean HasIGFlair(String playername) { - /*Player player=null; - for(Player p : Players) - { - if(p.getName()==playername) - { - player=p; - break; - } - } - if(player==null) - return false;*/ - //return PlayerFlairs.containsKey(playername); - //return MaybeOfflinePlayer.AllPlayers.containsKey(playername); MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. return p.Flair!=null; //2015.08.08. } public void SetFlair(String playername, String text, String flairclass, String username) { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. String finalflair; + p.FlairDecided=true; switch(flairclass) { case "press-1": @@ -258,38 +243,24 @@ public class PluginMain extends JavaPlugin case "cant-press": //2015.08.08. finalflair="§r(can't press)§r"; break; + case "undecided": //2015.08.09. + p.FlairDecided=false; + finalflair=""; + 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; } } @@ -297,43 +268,36 @@ public class PluginMain extends JavaPlugin public static String GetFlair(Player player) { //2015.07.16. - //String flair=PlayerFlairs.get(player.getName()); String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08. return flair==null ? "" : flair; } public static void AppendPlayerDisplayFlair(Player player, String username, String flair) { - //if(IgnoredPlayers.contains(player.getName())) if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).IgnoredFlair) return; - //if(AcceptedPlayers.contains(player.getName())) if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).AcceptedFlair) - //player.setDisplayName(player.getDisplayName()+flair); + { AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + } else player.sendMessage("§9Are you Reddit user "+username+"?§r §6Type /u accept or /u ignore§r"); } 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(); @@ -398,10 +350,6 @@ public class PluginMain extends JavaPlugin public static void RemovePlayerDisplayFlairFinal(Player player, String flair) { //2015.07.20. - //String color = GetColorForTown(GetPlayerTown(player)); - //String dname=player.getDisplayName(); - //player.setDisplayName(dname.substring(dname.indexOf(color)+3, dname.indexOf(flair))); - //MaybeOfflinePlayer.AllPlayers.get(player.getName()).DisplayName=null; //2015.08.08. MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair=null; //2015.08.08. } diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/26/a0111a40d33e001518fa86d7ae2a1cf8 b/.metadata/.plugins/org.eclipse.core.resources/.history/26/a0111a40d33e001518fa86d7ae2a1cf8 new file mode 100644 index 0000000..61ec61c --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/26/a0111a40d33e001518fa86d7ae2a1cf8 @@ -0,0 +1,215 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; + +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class Commands implements CommandExecutor { + // This method is called, when somebody uses our command + @Override + public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { + if (sender instanceof Player) { + Player player = (Player) sender; + if(args.length<1) + return false; + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. + //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) + if(p.Flair==null) + { + player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); + return true; + } + switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. + { + case "accept": + { + if(p.IgnoredFlair) + p.IgnoredFlair=false; //2015.08.08. + if(!p.AcceptedFlair) + { + String flair=p.Flair; //2015.08.08. + //PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + PluginMain.AppendPlayerDisplayFlair(p, player); + p.AcceptedFlair=true; //2015.08.08. + player.sendMessage("§6Your flair has been set:§r "+flair); + } + else + player.sendMessage("§cYou already have this user's flair.§r"); + break; + } + case "ignore": + { + if(p.AcceptedFlair) + p.AcceptedFlair=false; //2015.08.08. + if(!p.IgnoredFlair) + { + p.IgnoredFlair=true; + String flair=p.Flair; //2015.08.08. + PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. + player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); + } + else + player.sendMessage("§cYou already ignored this request.§r"); + break; + } + /*case "reload": //2015.07.20. + DoReload(player); + break;*/ + case "admin": //2015.08.09. + DoAdmin(player, args); + break; + case "nonpresser": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§7(non-pr.)§r"; + break; + case "cantpress": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§r(can't press)§r"; + break; + default: + return false; + } + return true; + } + /*if(args[0].toLowerCase()=="reload") + DoReload(null); //2015.07.20.*/ + else if(args.length>0 && args[0].toLowerCase().equals("admin")) //2015.08.09. + { + DoAdmin(null, args); //2015.08.09. + return true; //2015.08.09. + } + return false; + } + private static void DoReload(Player player) + { //2015.07.20. + //if(player==null || player.isOp() || player.getName()=="NorbiPeti") + //{ + try + { + File file=new File("autoflairconfig.txt"); + if(file.exists()) + { + PluginMain.LoadFiles(true); //2015.08.09. + for(Player p : PluginMain.GetPlayers()) + { + MaybeOfflinePlayer mp = MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName()); + if(mp.Flair!=null) + { + String flair=mp.Flair; + PluginMain.RemovePlayerDisplayFlairFinal(p, flair); + //PluginMain.AppendPlayerDisplayFlairFinal(p, flair); + PluginMain.AppendPlayerDisplayFlair(mp, p); //2015.08.09. + } + } + //String msg="§6Reloaded config file.§r"; + String msg="§6Note: The auto-flair plugin has been reloaded. You might need to wait 10s to have your flair.§r"; + //SendMessage(player, msg); //2015.08.09. + } + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + if(player!=null) + player.sendMessage("§cAn error occured. See console for details.§r"); + PluginMain.LastException=e; //2015.08.09. + } + //} + //else + //player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static void DoAdmin(Player player, String[] args) + { //2015.08.09. + if(player==null || player.isOp() || player.getName()=="NorbiPeti") + { + //System.out.println("Args length: " + args.length); + if(args.length==1) + { + String message="§cUsage: /u admin reload|playerinfo§r"; + SendMessage(player, message); + return; + } + //args[0] is "admin" + switch(args[1].toLowerCase()) + { + case "reload": + DoReload(player); + break; + case "playerinfo": + DoPlayerInfo(player, args); + break; + case "getlasterror": + DoGetLastError(player, args); + default: + String message="§cUsage: /u admin reload|playerinfo§r"; + SendMessage(player, message); + return; + } + } + else + player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static void DoPlayerInfo(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "playerinfo" + if(args.length==2) + { + String message="§cUsage: /u admin playerinfo §r"; + SendMessage(player, message); + return; + } + if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2])) + { + String message="§cPlayer not found: "+args[2]+"§r"; + SendMessage(player, message); + return; + } + MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]); + SendMessage(player, "Player name: "+p.PlayerName); + SendMessage(player, "User flair: "+p.Flair); + SendMessage(player, "Username: "+p.UserName); + SendMessage(player, "Flair accepted: "+p.AcceptedFlair); + SendMessage(player, "Flair ignored: "+p.IgnoredFlair); + } + private static void SendMessage(Player player, String message) + { //2015.08.09. + if(player==null) + System.out.println(message); + else + player.sendMessage(message); + } + private static void DoGetLastError(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "getlasterror" + if(PluginMain.LastException!=null) + { + SendMessage(player, "Last error:"); + SendMessage(player, PluginMain.LastException.toString()); + PluginMain.LastException=null; + } + else + SendMessage(player, "There were no exceptions."); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/27/9011edbed23e001518fa86d7ae2a1cf8 b/.metadata/.plugins/org.eclipse.core.resources/.history/27/9011edbed23e001518fa86d7ae2a1cf8 new file mode 100644 index 0000000..717cff8 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/27/9011edbed23e001518fa86d7ae2a1cf8 @@ -0,0 +1,215 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; + +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class Commands implements CommandExecutor { + // This method is called, when somebody uses our command + @Override + public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { + if (sender instanceof Player) { + Player player = (Player) sender; + if(args.length<1) + return false; + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. + //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) + if(p.Flair==null) + { + player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); + return true; + } + switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. + { + case "accept": + { + if(p.IgnoredFlair) + p.IgnoredFlair=false; //2015.08.08. + if(!p.AcceptedFlair) + { + String flair=p.Flair; //2015.08.08. + //PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + PluginMain.AppendPlayerDisplayFlair(p, player); + p.AcceptedFlair=true; //2015.08.08. + player.sendMessage("§6Your flair has been set:§r "+flair); + } + else + player.sendMessage("§cYou already have this user's flair.§r"); + break; + } + case "ignore": + { + if(p.AcceptedFlair) + p.AcceptedFlair=false; //2015.08.08. + if(!p.IgnoredFlair) + { + p.IgnoredFlair=true; + String flair=p.Flair; //2015.08.08. + PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. + player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); + } + else + player.sendMessage("§cYou already ignored this request.§r"); + break; + } + /*case "reload": //2015.07.20. + DoReload(player); + break;*/ + case "admin": //2015.08.09. + DoAdmin(player, args); + break; + case "nonpresser": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§7(non-pr.)§r"; + break; + case "cantpress": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§r(can't press)§r"; + break; + default: + return false; + } + return true; + } + /*if(args[0].toLowerCase()=="reload") + DoReload(null); //2015.07.20.*/ + else if(args.length>0 && args[0].toLowerCase().equals("admin")) //2015.08.09. + { + DoAdmin(null, args); //2015.08.09. + return true; //2015.08.09. + } + return false; + } + private static void DoReload(Player player) + { //2015.07.20. + //if(player==null || player.isOp() || player.getName()=="NorbiPeti") + //{ + try + { + File file=new File("autoflairconfig.txt"); + if(file.exists()) + { + PluginMain.LoadFiles(true); + 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); + PluginMain.AppendPlayerDisplayFlair(mp, p); //2015.08.09. + } + } + //String msg="§6Reloaded config file.§r"; + String msg="§6Reloaded all files.§r"; + SendMessage(player, msg); //2015.08.09. + } + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + if(player!=null) + player.sendMessage("§cAn error occured. See console for details.§r"); + PluginMain.LastException=e; //2015.08.09. + } + //} + //else + //player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static void DoAdmin(Player player, String[] args) + { //2015.08.09. + if(player==null || player.isOp() || player.getName()=="NorbiPeti") + { + //System.out.println("Args length: " + args.length); + if(args.length==1) + { + String message="§cUsage: /u admin reload|playerinfo§r"; + SendMessage(player, message); + return; + } + //args[0] is "admin" + switch(args[1].toLowerCase()) + { + case "reload": + DoReload(player); + break; + case "playerinfo": + DoPlayerInfo(player, args); + break; + case "getlasterror": + DoGetLastError(player, args); + default: + String message="§cUsage: /u admin reload|playerinfo§r"; + SendMessage(player, message); + return; + } + } + else + player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static void DoPlayerInfo(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "playerinfo" + if(args.length==2) + { + String message="§cUsage: /u admin playerinfo §r"; + SendMessage(player, message); + return; + } + if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2])) + { + String message="§cPlayer not found: "+args[2]+"§r"; + SendMessage(player, message); + return; + } + MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]); + SendMessage(player, "Player name: "+p.PlayerName); + SendMessage(player, "User flair: "+p.Flair); + SendMessage(player, "Username: "+p.UserName); + SendMessage(player, "Flair accepted: "+p.AcceptedFlair); + SendMessage(player, "Flair ignored: "+p.IgnoredFlair); + } + private static void SendMessage(Player player, String message) + { //2015.08.09. + if(player==null) + System.out.println(message); + else + player.sendMessage(message); + } + private static void DoGetLastError(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "getlasterror" + if(PluginMain.LastException!=null) + { + SendMessage(player, "Last error:"); + SendMessage(player, PluginMain.LastException.toString()); + PluginMain.LastException=null; + } + else + SendMessage(player, "There were no exceptions."); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/27/d0c61635023e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/27/d0c61635023e00151c31fb33fff4337f deleted file mode 100644 index e00eae6..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/27/d0c61635023e00151c31fb33fff4337f +++ /dev/null @@ -1,125 +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; - 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/27/f08a8910cf3e001518fa86d7ae2a1cf8 b/.metadata/.plugins/org.eclipse.core.resources/.history/27/f08a8910cf3e001518fa86d7ae2a1cf8 new file mode 100644 index 0000000..999a5ae --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/27/f08a8910cf3e001518fa86d7ae2a1cf8 @@ -0,0 +1,362 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStream; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLConnection; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + +import org.apache.commons.io.IOUtils; +import org.bukkit.entity.Player; +import org.bukkit.plugin.java.JavaPlugin; +import org.json.JSONArray; +import org.json.JSONObject; + +import tk.sznp.thebuttonautoflair.MaybeOfflinePlayer.FlairClassType; + +import com.palmergames.bukkit.towny.object.Town; +import com.palmergames.bukkit.towny.object.WorldCoord; + +public class PluginMain extends JavaPlugin +{ //Translated to Java: 2015.07.15. + //A user, which flair isn't obtainable: + //https://www.reddit.com/r/thebutton/comments/31c32v/i_pressed_the_button_without_really_thinking/ + private static PluginMain Instance; + // Fired when plugin is first enabled + @Override + public void onEnable() + { + System.out.println("The Button Auto-flair Plugin by NorbiPeti (:P)"); + getServer().getPluginManager().registerEvents(new PlayerListener(), this); + this.getCommand("u").setExecutor(new Commands()); + this.getCommand("u").setUsage(this.getCommand("u").getUsage().replace('&', '§')); + Instance=this; //2015.08.08. + try { + File file=new File("flairsaccepted.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + //System.out.println("Name: " + name); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("flairsignored.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsignored.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("autoflairconfig.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + TownColors.put(s[0], s[1]); + } + br.close(); + } + //throw new IOException("Test"); //2015.08.09. + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + Runnable r=new Runnable(){public void run(){ThreadMethod();}}; + Thread t=new Thread(r); + t.start(); + } + Boolean stop=false; + // Fired when plugin is disabled + @Override + public void onDisable() + { + try + { + FileWriter fw; + fw = new FileWriter("flairsaccepted.txt"); + fw.close(); + fw = new FileWriter("flairsignored.txt"); + fw.close(); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + try { + File file=new File("flairsaccepted.txt"); + BufferedWriter bw=new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.AcceptedFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + file=new File("flairsignored.txt"); + bw = new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.IgnoredFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + stop=true; + } + + public void ThreadMethod() //<-- 2015.07.16. + { + while(!stop) + { + try + { + String body=DownloadString("https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/autoflair_system_comment_your_minecraft_name_and/.json?limit=1000"); + JSONArray json=new JSONArray(body).getJSONObject(1).getJSONObject("data").getJSONArray("children"); + for(Object obj : json) + { + JSONObject item = (JSONObject)obj; + String author=item.getJSONObject("data").getString("author"); + String ign=item.getJSONObject("data").getString("body"); + int start = ign.indexOf("IGN:") + "IGN:".length(); + int end = ign.indexOf(' ', start); + if (end == -1 || end == start) + end=ign.indexOf('\n', start); //2015.07.15. + if (end == -1 || end == start) + ign = ign.substring(start); + else + ign = ign.substring(start, end); + ign = ign.trim(); + if(HasIGFlair(ign)) + continue; + try { + Thread.sleep(10); + } catch(InterruptedException ex) { + Thread.currentThread().interrupt(); + } + String[] flairdata = DownloadString("http://karmadecay.com/thebutton-data.php?users=" + author).replace("\"", "").split(":"); + String flair; + if(flairdata.length > 1) //2015.07.15. + flair = flairdata[1]; + else + flair=""; + if (flair != "-1") + flair = flair + "s"; + else + flair = "non-presser"; + String flairclass; + if(flairdata.length>2) + flairclass = flairdata[2]; + else + flairclass="unknown"; + SetFlair(ign, flair, flairclass, author); + } + Thread.sleep(10000); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + } + + public static Exception LastException; //2015.08.09. + + public String DownloadString(String urlstr) throws MalformedURLException, IOException + { + URL url = new URL(urlstr); + URLConnection con = url.openConnection(); + con.setRequestProperty("User-Agent", "TheButtonAutoFlair"); + InputStream in = con.getInputStream(); + String encoding = con.getContentEncoding(); + encoding = encoding == null ? "UTF-8" : encoding; + String body = IOUtils.toString(in, encoding); + in.close(); + return body; + } + + public static Map TownColors=new HashMap(); //2015.07.20. + public Boolean HasIGFlair(String playername) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + return p.Flair!=null; //2015.08.08. + } + + public void SetFlair(String playername, String text, String flairclass, String username) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + String finalflair; + p.FlairDecided=true; + switch(flairclass) + { + case "press-1": + finalflair="§c("+text+")§r"; + break; + case "press-2": + finalflair="§6("+text+")§r"; + break; + case "press-3": + finalflair="§e("+text+")§r"; + break; + case "press-4": + finalflair="§a("+text+")§r"; + break; + case "press-5": + finalflair="§9("+text+")§r"; + break; + 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; + case "undecided": //2015.08.09. + p.FlairDecided=false; + finalflair=""; + break; + default: + finalflair=""; + break; + } + if(finalflair.length()==0) //<-- 2015.07.20. + return; + p.Flair=finalflair; //2015.08.08. + p.UserName=username; //2015.08.08. + System.out.println("Added new flair to "+playername+": "+finalflair); + for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08. + { + if(player.getName().equals(playername)) + { + AppendPlayerDisplayFlair(player, username, finalflair); + break; + } + } + } + + public static String GetFlair(Player player) + { //2015.07.16. + String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08. + return flair==null ? "" : flair; + } + + //public static void AppendPlayerDisplayFlair(Player player, String username, String flair) + public static void AppendPlayerDisplayFlair(MaybeOfflinePlayer player, Player p) + { + + if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).IgnoredFlair) + return; + if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).AcceptedFlair) + { + AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + } + else + player.sendMessage("§9Are you Reddit user "+username+"?§r §6Type /u accept or /u ignore§r"); + } + + private static void AppendPlayerDisplayFlairFinal(Player player, String flair) + { //2015.07.20. + String color = GetColorForTown(GetPlayerTown(player)); //TO!DO: Multiple colors put on first capital letters + String[] colors = color.substring(1).split("§"); + String displayname=player.getName(); //2015.08.08. + ArrayList Positions=new ArrayList<>(); + for(int i=0; i=colors.length) + { + int x=0; + for(int i=0; i GetPlayers() + { + return Instance.getServer().getOnlinePlayers(); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/28/309e6352d33e001518fa86d7ae2a1cf8 b/.metadata/.plugins/org.eclipse.core.resources/.history/28/309e6352d33e001518fa86d7ae2a1cf8 new file mode 100644 index 0000000..d073151 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/28/309e6352d33e001518fa86d7ae2a1cf8 @@ -0,0 +1,216 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; + +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class Commands implements CommandExecutor { + // This method is called, when somebody uses our command + @Override + public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { + if (sender instanceof Player) { + Player player = (Player) sender; + if(args.length<1) + return false; + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. + //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) + if(p.Flair==null) + { + player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); + return true; + } + switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. + { + case "accept": + { + if(p.IgnoredFlair) + p.IgnoredFlair=false; //2015.08.08. + if(!p.AcceptedFlair) + { + String flair=p.Flair; //2015.08.08. + //PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + PluginMain.AppendPlayerDisplayFlair(p, player); + p.AcceptedFlair=true; //2015.08.08. + player.sendMessage("§6Your flair has been set:§r "+flair); + } + else + player.sendMessage("§cYou already have this user's flair.§r"); + break; + } + case "ignore": + { + if(p.AcceptedFlair) + p.AcceptedFlair=false; //2015.08.08. + if(!p.IgnoredFlair) + { + p.IgnoredFlair=true; + String flair=p.Flair; //2015.08.08. + PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. + player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); + } + else + player.sendMessage("§cYou already ignored this request.§r"); + break; + } + /*case "reload": //2015.07.20. + DoReload(player); + break;*/ + case "admin": //2015.08.09. + DoAdmin(player, args); + break; + case "nonpresser": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§7(non-pr.)§r"; + break; + case "cantpress": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§r(can't press)§r"; + break; + default: + return false; + } + return true; + } + /*if(args[0].toLowerCase()=="reload") + DoReload(null); //2015.07.20.*/ + else if(args.length>0 && args[0].toLowerCase().equals("admin")) //2015.08.09. + { + DoAdmin(null, args); //2015.08.09. + return true; //2015.08.09. + } + return false; + } + private static void DoReload(Player player) + { //2015.07.20. + //if(player==null || player.isOp() || player.getName()=="NorbiPeti") + //{ + try + { + File file=new File("autoflairconfig.txt"); + if(file.exists()) + { + PluginMain.LoadFiles(true); //2015.08.09. + for(Player p : PluginMain.GetPlayers()) + { + MaybeOfflinePlayer mp = MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName()); + if(mp.Flair!=null) + { + String flair=mp.Flair; + PluginMain.RemovePlayerDisplayFlairFinal(p, flair); + //PluginMain.AppendPlayerDisplayFlairFinal(p, flair); + PluginMain.AppendPlayerDisplayFlair(mp, p); //2015.08.09. + } + String msg="§6Note: The auto-flair plugin has been reloaded. You might need to wait 10s to have your flair.§r"; //2015.08.09. + p.sendMessage(msg); + } + //String msg="§6Reloaded config file.§r"; + //SendMessage(player, msg); //2015.08.09. + } + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + if(player!=null) + player.sendMessage("§cAn error occured. See console for details.§r"); + PluginMain.LastException=e; //2015.08.09. + } + //} + //else + //player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static void DoAdmin(Player player, String[] args) + { //2015.08.09. + if(player==null || player.isOp() || player.getName()=="NorbiPeti") + { + //System.out.println("Args length: " + args.length); + if(args.length==1) + { + String message="§cUsage: /u admin reload|playerinfo§r"; + SendMessage(player, message); + return; + } + //args[0] is "admin" + switch(args[1].toLowerCase()) + { + case "reload": + DoReload(player); + break; + case "playerinfo": + DoPlayerInfo(player, args); + break; + case "getlasterror": + DoGetLastError(player, args); + default: + String message="§cUsage: /u admin reload|playerinfo§r"; + SendMessage(player, message); + return; + } + } + else + player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static void DoPlayerInfo(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "playerinfo" + if(args.length==2) + { + String message="§cUsage: /u admin playerinfo §r"; + SendMessage(player, message); + return; + } + if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2])) + { + String message="§cPlayer not found: "+args[2]+"§r"; + SendMessage(player, message); + return; + } + MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]); + SendMessage(player, "Player name: "+p.PlayerName); + SendMessage(player, "User flair: "+p.Flair); + SendMessage(player, "Username: "+p.UserName); + SendMessage(player, "Flair accepted: "+p.AcceptedFlair); + SendMessage(player, "Flair ignored: "+p.IgnoredFlair); + } + private static void SendMessage(Player player, String message) + { //2015.08.09. + if(player==null) + System.out.println(message); + else + player.sendMessage(message); + } + private static void DoGetLastError(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "getlasterror" + if(PluginMain.LastException!=null) + { + SendMessage(player, "Last error:"); + SendMessage(player, PluginMain.LastException.toString()); + PluginMain.LastException=null; + } + else + SendMessage(player, "There were no exceptions."); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/29/4085cc81fe3d00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/29/4085cc81fe3d00151c31fb33fff4337f deleted file mode 100644 index 77b05cb..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/29/4085cc81fe3d00151c31fb33fff4337f +++ /dev/null @@ -1,122 +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()); - 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/50dd5657043e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/29/50dd5657043e00151c31fb33fff4337f deleted file mode 100644 index 772f7ef..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/29/50dd5657043e00151c31fb33fff4337f +++ /dev/null @@ -1,125 +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; - 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/001db465df3e001517108d149b613203 b/.metadata/.plugins/org.eclipse.core.resources/.history/2a/001db465df3e001517108d149b613203 new file mode 100644 index 0000000..df11079 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/2a/001db465df3e001517108d149b613203 @@ -0,0 +1,252 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +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; + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. + //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) + if(p.Flair==null) + { + player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); + return true; + } + switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. + { + case "accept": + { + if(p.IgnoredFlair) + p.IgnoredFlair=false; //2015.08.08. + if(!p.AcceptedFlair) + { + String flair=p.Flair; //2015.08.08. + //PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + PluginMain.AppendPlayerDisplayFlair(p, player); + p.AcceptedFlair=true; //2015.08.08. + player.sendMessage("§6Your flair has been set:§r "+flair); + } + else + player.sendMessage("§cYou already have this user's flair.§r"); + break; + } + case "ignore": + { + if(p.AcceptedFlair) + p.AcceptedFlair=false; //2015.08.08. + if(!p.IgnoredFlair) + { + p.IgnoredFlair=true; + String flair=p.Flair; //2015.08.08. + PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. + player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); + } + else + player.sendMessage("§cYou already ignored this request.§r"); + break; + } + /*case "reload": //2015.07.20. + DoReload(player); + break;*/ + case "admin": //2015.08.09. + DoAdmin(player, args); + break; + case "nonpresser": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§7(non-pr.)§r"; + break; + case "cantpress": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§r(can't press)§r"; + break; + default: + return false; + } + return true; + } + /*if(args[0].toLowerCase()=="reload") + DoReload(null); //2015.07.20.*/ + else if(args.length>0 && args[0].toLowerCase().equals("admin")) //2015.08.09. + { + DoAdmin(null, args); //2015.08.09. + return true; //2015.08.09. + } + return false; + } + private static void DoReload(Player player) + { //2015.07.20. + //if(player==null || player.isOp() || player.getName()=="NorbiPeti") + //{ + try + { + File file=new File("autoflairconfig.txt"); + if(file.exists()) + { + PluginMain.LoadFiles(true); //2015.08.09. + for(Player p : PluginMain.GetPlayers()) + { + MaybeOfflinePlayer mp = MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName()); + if(mp.Flair!=null) + { + String flair=mp.Flair; + PluginMain.RemovePlayerDisplayFlairFinal(p, flair); + //PluginMain.AppendPlayerDisplayFlairFinal(p, flair); + PluginMain.AppendPlayerDisplayFlair(mp, p); //2015.08.09. + } + String msg="§6Note: The auto-flair plugin has been reloaded. You might need to wait 10s to have your flair.§r"; //2015.08.09. + p.sendMessage(msg); //2015.08.09. + } + //String msg="§6Reloaded config file.§r"; + //SendMessage(player, msg); //2015.08.09. + } + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + if(player!=null) + player.sendMessage("§cAn error occured. See console for details.§r"); + PluginMain.LastException=e; //2015.08.09. + } + //} + //else + //player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static Player ReloadPlayer; //2015.08.09. + private static void DoAdmin(Player player, String[] args) + { //2015.08.09. + if(player==null || player.isOp() || player.getName()=="NorbiPeti") + { + //System.out.println("Args length: " + args.length); + if(args.length==1) + { + String message="§cUsage: /u admin reload|playerinfo§r"; + SendMessage(player, message); + return; + } + //args[0] is "admin" + switch(args[1].toLowerCase()) + { + case "reload": + ReloadPlayer=player; //2015.08.09. + SendMessage(player, "§6Make sure to save the current settings before you modify and reload them! Type /u admin confirm when done.§r"); + break; + case "playerinfo": + DoPlayerInfo(player, args); + break; + case "getlasterror": + DoGetLastError(player, args); + case "confirm": + if(ReloadPlayer==player) + DoReload(player); //2015.08.09. + else + SendMessage(player, "§cYou need to do /u admin reload first.§r"); + break; + case "save": + PluginMain.SaveFiles(); //2015.08.09. + SendMessage(player, "§6Saved files. Now you can edit them and reload if you want.§r"); + break; + default: + String message="§cUsage: /u admin reload|playerinfo|getlasterror§r"; + SendMessage(player, message); + return; + } + } + else + player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static void DoPlayerInfo(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "playerinfo" + if(args.length==2) + { + String message="§cUsage: /u admin playerinfo §r"; + SendMessage(player, message); + return; + } + if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2])) + { + String message="§cPlayer not found: "+args[2]+"§r"; + SendMessage(player, message); + return; + } + MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]); + SendMessage(player, "Player name: "+p.PlayerName); + SendMessage(player, "User flair: "+p.Flair); + SendMessage(player, "Username: "+p.UserName); + SendMessage(player, "Flair accepted: "+p.AcceptedFlair); + SendMessage(player, "Flair ignored: "+p.IgnoredFlair); + } + private static void SendMessage(Player player, String message) + { //2015.08.09. + if(player==null) + System.out.println(message); + else + player.sendMessage(message); + } + private static void DoGetLastError(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "getlasterror" + if(PluginMain.LastException!=null) + { + SendMessage(player, "Last error:"); + SendMessage(player, PluginMain.LastException.toString()); + PluginMain.LastException=null; + } + else + SendMessage(player, "There were no exceptions."); + } + private static void SetPlayerFlair(Player player, String flair) + { //2015.08.09. + flair=flair.replace('&', '§'); + MaybeOfflinePlayer.AddPlayerIfNeeded(player.getName()).Flair=flair; + if(!PluginMain.RemoveLineFromFile("customflairs.txt")) + { + SendMessage(player, "§cError removing previous custom flair!§r"); + return; + } + File file=new File("customflairs.txt"); + try { + BufferedWriter bw; + bw = new BufferedWriter(new FileWriter(file, true)); + bw.write(player.getName()+"\n"); + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + PluginMain.LastException=e; //2015.08.09. + } + SendMessage(player, "§6The flair has been set. Player: "+player.getName()+" Flair: "+flair); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/2a/00a6389de03e001517108d149b613203 b/.metadata/.plugins/org.eclipse.core.resources/.history/2a/00a6389de03e001517108d149b613203 new file mode 100644 index 0000000..0ccc23b --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/2a/00a6389de03e001517108d149b613203 @@ -0,0 +1,260 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +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; + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. + //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) + if(p.Flair==null) + { + player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); + return true; + } + switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. + { + case "accept": + { + if(p.IgnoredFlair) + p.IgnoredFlair=false; //2015.08.08. + if(!p.AcceptedFlair) + { + String flair=p.Flair; //2015.08.08. + //PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + PluginMain.AppendPlayerDisplayFlair(p, player); + p.AcceptedFlair=true; //2015.08.08. + player.sendMessage("§6Your flair has been set:§r "+flair); + } + else + player.sendMessage("§cYou already have this user's flair.§r"); + break; + } + case "ignore": + { + if(p.AcceptedFlair) + p.AcceptedFlair=false; //2015.08.08. + if(!p.IgnoredFlair) + { + p.IgnoredFlair=true; + String flair=p.Flair; //2015.08.08. + PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. + player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); + } + else + player.sendMessage("§cYou already ignored this request.§r"); + break; + } + /*case "reload": //2015.07.20. + DoReload(player); + break;*/ + case "admin": //2015.08.09. + DoAdmin(player, args); + break; + case "nonpresser": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§7(non-pr.)§r"; + break; + case "cantpress": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§r(can't press)§r"; + break; + default: + return false; + } + return true; + } + /*if(args[0].toLowerCase()=="reload") + DoReload(null); //2015.07.20.*/ + else if(args.length>0 && args[0].toLowerCase().equals("admin")) //2015.08.09. + { + DoAdmin(null, args); //2015.08.09. + return true; //2015.08.09. + } + return false; + } + private static void DoReload(Player player) + { //2015.07.20. + //if(player==null || player.isOp() || player.getName()=="NorbiPeti") + //{ + try + { + File file=new File("autoflairconfig.txt"); + if(file.exists()) + { + PluginMain.LoadFiles(true); //2015.08.09. + for(Player p : PluginMain.GetPlayers()) + { + MaybeOfflinePlayer mp = MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName()); + if(mp.Flair!=null) + { + String flair=mp.Flair; + PluginMain.RemovePlayerDisplayFlairFinal(p, flair); + //PluginMain.AppendPlayerDisplayFlairFinal(p, flair); + PluginMain.AppendPlayerDisplayFlair(mp, p); //2015.08.09. + } + String msg="§6Note: The auto-flair plugin has been reloaded. You might need to wait 10s to have your flair.§r"; //2015.08.09. + p.sendMessage(msg); //2015.08.09. + } + //String msg="§6Reloaded config file.§r"; + //SendMessage(player, msg); //2015.08.09. + } + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + if(player!=null) + player.sendMessage("§cAn error occured. See console for details.§r"); + PluginMain.LastException=e; //2015.08.09. + } + //} + //else + //player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static Player ReloadPlayer; //2015.08.09. + private static void DoAdmin(Player player, String[] args) + { //2015.08.09. + if(player==null || player.isOp() || player.getName()=="NorbiPeti") + { + //System.out.println("Args length: " + args.length); + if(args.length==1) + { + String message="§cUsage: /u admin reload|playerinfo§r"; + SendMessage(player, message); + return; + } + //args[0] is "admin" + switch(args[1].toLowerCase()) + { + case "reload": + ReloadPlayer=player; //2015.08.09. + SendMessage(player, "§6Make sure to save the current settings before you modify and reload them! Type /u admin confirm when done.§r"); + break; + case "playerinfo": + DoPlayerInfo(player, args); + break; + case "getlasterror": + DoGetLastError(player, args); + case "confirm": + if(ReloadPlayer==player) + DoReload(player); //2015.08.09. + else + SendMessage(player, "§cYou need to do /u admin reload first.§r"); + break; + case "save": + PluginMain.SaveFiles(); //2015.08.09. + SendMessage(player, "§6Saved files. Now you can edit them and reload if you want.§r"); + break; + case "setflair": + + break; + default: + String message="§cUsage: /u admin reload|playerinfo|getlasterror|save§r"; + SendMessage(player, message); + return; + } + } + else + player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static void DoPlayerInfo(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "playerinfo" + if(args.length==2) + { + String message="§cUsage: /u admin playerinfo §r"; + SendMessage(player, message); + return; + } + if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2])) + { + String message="§cPlayer not found: "+args[2]+"§r"; + SendMessage(player, message); + return; + } + MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]); + SendMessage(player, "Player name: "+p.PlayerName); + SendMessage(player, "User flair: "+p.Flair); + SendMessage(player, "Username: "+p.UserName); + SendMessage(player, "Flair accepted: "+p.AcceptedFlair); + SendMessage(player, "Flair ignored: "+p.IgnoredFlair); + } + private static void SendMessage(Player player, String message) + { //2015.08.09. + if(player==null) + System.out.println(message); + else + player.sendMessage(message); + } + private static void DoGetLastError(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "getlasterror" + if(PluginMain.LastException!=null) + { + SendMessage(player, "Last error:"); + SendMessage(player, PluginMain.LastException.toString()); + PluginMain.LastException=null; + } + else + SendMessage(player, "There were no exceptions."); + } + private static void SetPlayerFlair(Player player, Player targetplayer, String flair) + { //2015.08.09. + flair=flair.replace('&', '§'); + MaybeOfflinePlayer.AddPlayerIfNeeded(player.getName()).Flair=flair; + if(!PluginMain.RemoveLineFromFile("customflairs.txt", targetplayer.getName())) + { + SendMessage(player, "§cError removing previous custom flair!§r"); + return; + } + File file=new File("customflairs.txt"); + try { + BufferedWriter bw; + bw = new BufferedWriter(new FileWriter(file, true)); + bw.write(targetplayer.getName()+"\n"); + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + PluginMain.LastException=e; //2015.08.09. + } + SendMessage(player, "§6The flair has been set. Player: "+targetplayer.getName()+" Flair: "+flair+"§r"); + } + private static void DoSetFlair(Player player, String args) + { + //args[0] is "admin" - args[1] is "setflair" + + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/2a/20868515d03e001518fa86d7ae2a1cf8 b/.metadata/.plugins/org.eclipse.core.resources/.history/2a/20868515d03e001518fa86d7ae2a1cf8 new file mode 100644 index 0000000..ccaedeb --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/2a/20868515d03e001518fa86d7ae2a1cf8 @@ -0,0 +1,363 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStream; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLConnection; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + +import org.apache.commons.io.IOUtils; +import org.bukkit.entity.Player; +import org.bukkit.plugin.java.JavaPlugin; +import org.json.JSONArray; +import org.json.JSONObject; + +import com.palmergames.bukkit.towny.object.Town; +import com.palmergames.bukkit.towny.object.WorldCoord; + +public class PluginMain extends JavaPlugin +{ //Translated to Java: 2015.07.15. + //A user, which flair isn't obtainable: + //https://www.reddit.com/r/thebutton/comments/31c32v/i_pressed_the_button_without_really_thinking/ + private static PluginMain Instance; + // Fired when plugin is first enabled + @Override + public void onEnable() + { + System.out.println("The Button Auto-flair Plugin by NorbiPeti (:P)"); + getServer().getPluginManager().registerEvents(new PlayerListener(), this); + this.getCommand("u").setExecutor(new Commands()); + this.getCommand("u").setUsage(this.getCommand("u").getUsage().replace('&', '§')); + Instance=this; //2015.08.08. + try { + File file=new File("flairsaccepted.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + //System.out.println("Name: " + name); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("flairsignored.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsignored.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("autoflairconfig.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + TownColors.put(s[0], s[1]); + } + br.close(); + } + //throw new IOException("Test"); //2015.08.09. + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + Runnable r=new Runnable(){public void run(){ThreadMethod();}}; + Thread t=new Thread(r); + t.start(); + } + Boolean stop=false; + // Fired when plugin is disabled + @Override + public void onDisable() + { + try + { + FileWriter fw; + fw = new FileWriter("flairsaccepted.txt"); + fw.close(); + fw = new FileWriter("flairsignored.txt"); + fw.close(); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + try { + File file=new File("flairsaccepted.txt"); + BufferedWriter bw=new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.AcceptedFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + file=new File("flairsignored.txt"); + bw = new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.IgnoredFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + stop=true; + } + + public void ThreadMethod() //<-- 2015.07.16. + { + while(!stop) + { + try + { + String body=DownloadString("https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/autoflair_system_comment_your_minecraft_name_and/.json?limit=1000"); + JSONArray json=new JSONArray(body).getJSONObject(1).getJSONObject("data").getJSONArray("children"); + for(Object obj : json) + { + JSONObject item = (JSONObject)obj; + String author=item.getJSONObject("data").getString("author"); + String ign=item.getJSONObject("data").getString("body"); + int start = ign.indexOf("IGN:") + "IGN:".length(); + int end = ign.indexOf(' ', start); + if (end == -1 || end == start) + end=ign.indexOf('\n', start); //2015.07.15. + if (end == -1 || end == start) + ign = ign.substring(start); + else + ign = ign.substring(start, end); + ign = ign.trim(); + if(HasIGFlair(ign)) + continue; + try { + Thread.sleep(10); + } catch(InterruptedException ex) { + Thread.currentThread().interrupt(); + } + String[] flairdata = DownloadString("http://karmadecay.com/thebutton-data.php?users=" + author).replace("\"", "").split(":"); + String flair; + if(flairdata.length > 1) //2015.07.15. + flair = flairdata[1]; + else + flair=""; + if (flair != "-1") + flair = flair + "s"; + else + flair = "non-presser"; + String flairclass; + if(flairdata.length>2) + flairclass = flairdata[2]; + else + flairclass="unknown"; + SetFlair(ign, flair, flairclass, author); + } + Thread.sleep(10000); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + } + + public static Exception LastException; //2015.08.09. + + public String DownloadString(String urlstr) throws MalformedURLException, IOException + { + URL url = new URL(urlstr); + URLConnection con = url.openConnection(); + con.setRequestProperty("User-Agent", "TheButtonAutoFlair"); + InputStream in = con.getInputStream(); + String encoding = con.getContentEncoding(); + encoding = encoding == null ? "UTF-8" : encoding; + String body = IOUtils.toString(in, encoding); + in.close(); + return body; + } + + public static Map TownColors=new HashMap(); //2015.07.20. + public Boolean HasIGFlair(String playername) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + return p.Flair!=null; //2015.08.08. + } + + public void SetFlair(String playername, String text, String flairclass, String username) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + String finalflair; + p.FlairDecided=true; + switch(flairclass) + { + case "press-1": + finalflair="§c("+text+")§r"; + break; + case "press-2": + finalflair="§6("+text+")§r"; + break; + case "press-3": + finalflair="§e("+text+")§r"; + break; + case "press-4": + finalflair="§a("+text+")§r"; + break; + case "press-5": + finalflair="§9("+text+")§r"; + break; + 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; + case "undecided": //2015.08.09. + p.FlairDecided=false; + finalflair=""; + break; + default: + finalflair=""; + break; + } + if(finalflair.length()==0) //<-- 2015.07.20. + return; + p.Flair=finalflair; //2015.08.08. + p.UserName=username; //2015.08.08. + System.out.println("Added new flair to "+playername+": "+finalflair); + for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08. + { + if(player.getName().equals(playername)) + { + //AppendPlayerDisplayFlair(player, username, finalflair); + AppendPlayerDisplayFlair(p, player); + break; + } + } + } + + public static String GetFlair(Player player) + { //2015.07.16. + String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08. + return flair==null ? "" : flair; + } + + //public static void AppendPlayerDisplayFlair(Player player, String username, String flair) + public static void AppendPlayerDisplayFlair(MaybeOfflinePlayer player, Player p) //<-- 2015.08.09. + { + + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).IgnoredFlair) + return; + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).AcceptedFlair) + { + AppendPlayerDisplayFlairFinal(p, player.Flair); //2015.07.20. + if(!player.FlairDecided) + p.sendMessage("§9Your flair type is unknown. Are you a non-presser or a can't press? (/u nonpresser or /u cantpress)§r"); //2015.08.09. + } + else + player.sendMessage("§9Are you Reddit user "+player.UserName+"?§r §6Type /u accept or /u ignore§r"); + } + + private static void AppendPlayerDisplayFlairFinal(Player player, String flair) + { //2015.07.20. + String color = GetColorForTown(GetPlayerTown(player)); //TO!DO: Multiple colors put on first capital letters + String[] colors = color.substring(1).split("§"); + String displayname=player.getName(); //2015.08.08. + ArrayList Positions=new ArrayList<>(); + for(int i=0; i=colors.length) + { + int x=0; + for(int i=0; i GetPlayers() + { + return Instance.getServer().getOnlinePlayers(); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/2a/20a4e0af0d3e00151089cca86c5b1a99 b/.metadata/.plugins/org.eclipse.core.resources/.history/2a/20a4e0af0d3e00151089cca86c5b1a99 deleted file mode 100644 index efac5c3..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/2a/20a4e0af0d3e00151089cca86c5b1a99 +++ /dev/null @@ -1,434 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import java.io.BufferedReader; -import java.io.BufferedWriter; -import java.io.File; -import java.io.FileReader; -import java.io.FileWriter; -import java.io.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/50ddd938863e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/2a/50ddd938863e00151ce8ff6d4f74dabd deleted file mode 100644 index 8cba558..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/2a/50ddd938863e00151ce8ff6d4f74dabd +++ /dev/null @@ -1,131 +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; - MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. - //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - if(p.Flair==null) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. - { - case "accept": - { - if(p.IgnoredFlair) - p.IgnoredFlair=false; //2015.08.08. - if(!p.AcceptedFlair) - { - String flair=p.Flair; //2015.08.08. - PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. - p.AcceptedFlair=true; //2015.08.08. - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("§cYou already have this user's flair.§r"); - break; - } - case "ignore": - { - if(p.AcceptedFlair) - p.AcceptedFlair=false; //2015.08.08. - if(!p.IgnoredFlair) - { - p.IgnoredFlair=true; - String flair=p.Flair; //2015.08.08. - PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. - player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); - } - else - player.sendMessage("§cYou already ignored this request.§r"); - break; - } - case "reload": //2015.07.20. - DoReload(player); - break; - case "showerrors": //2015.08.09. - DoShowErrors(player); - break; - default: - return false; - } - return true; - } - - if(args[0].toLowerCase()=="reload") - DoReload(null); //2015.07.20. - else if(args[0].toLowerCase()=="showerrors") - DoShowErrors(null); //2015.08.09. - return false; - } - private static void DoReload(Player player) - { //2015.07.20. - if(player==null || player.isOp() || player.getName()=="NorbiPeti") - { - try - { - File file=new File("autoflairconfig.txt"); - if(file.exists()) - { - PluginMain.TownColors.clear(); - BufferedReader br=new BufferedReader(new FileReader(file)); - String line; - while((line=br.readLine())!=null) - { - String[] s=line.split(" "); - PluginMain.TownColors.put(s[0], s[1]); - } - br.close(); - for(Player p : PluginMain.GetPlayers()) - { - MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName()); - if(mp.Flair!=null) - { - String flair=mp.Flair; - PluginMain.RemovePlayerDisplayFlairFinal(p, flair); - PluginMain.AppendPlayerDisplayFlairFinal(p, flair); - } - } - String msg="§6Reloaded config file.§r"; - if(player!=null) - player.sendMessage(msg); - else - System.out.println(msg); - } - } - catch(Exception e) - { - System.out.println("Error!\n"+e); - if(player!=null) - player.sendMessage("§cAn error occured. See console for details.§r"); - } - } - else - player.sendMessage("§cYou need to be OP to use this command.§r"); - } - private static void DoShowErrors(Player player) - { - if(player==null || player.isOp() || player.getName()=="NorbiPeti") - { - - } - else - player.sendMessage("§cYou need to be OP to use this command.§r"); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/2a/d0123229883e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/2a/d0123229883e00151ce8ff6d4f74dabd deleted file mode 100644 index 2fca4b8..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/2a/d0123229883e00151ce8ff6d4f74dabd +++ /dev/null @@ -1,163 +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; - MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. - //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - if(p.Flair==null) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. - { - case "accept": - { - if(p.IgnoredFlair) - p.IgnoredFlair=false; //2015.08.08. - if(!p.AcceptedFlair) - { - String flair=p.Flair; //2015.08.08. - PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. - p.AcceptedFlair=true; //2015.08.08. - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("§cYou already have this user's flair.§r"); - break; - } - case "ignore": - { - if(p.AcceptedFlair) - p.AcceptedFlair=false; //2015.08.08. - if(!p.IgnoredFlair) - { - p.IgnoredFlair=true; - String flair=p.Flair; //2015.08.08. - PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. - player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); - } - else - player.sendMessage("§cYou already ignored this request.§r"); - break; - } - /*case "reload": //2015.07.20. - DoReload(player); - break;*/ - case "admin": //2015.08.09. - DoAdmin(player, args); - break; - default: - return false; - } - return true; - } - - /*if(args[0].toLowerCase()=="reload") - DoReload(null); //2015.07.20.*/ - else if(args[0].toLowerCase()=="admin") - DoAdmin(null, args); //2015.08.09. - return false; - } - private static void DoReload(Player player) - { //2015.07.20. - //if(player==null || player.isOp() || player.getName()=="NorbiPeti") - //{ - try - { - File file=new File("autoflairconfig.txt"); - if(file.exists()) - { - PluginMain.TownColors.clear(); - BufferedReader br=new BufferedReader(new FileReader(file)); - String line; - while((line=br.readLine())!=null) - { - String[] s=line.split(" "); - PluginMain.TownColors.put(s[0], s[1]); - } - br.close(); - for(Player p : PluginMain.GetPlayers()) - { - MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName()); - if(mp.Flair!=null) - { - String flair=mp.Flair; - PluginMain.RemovePlayerDisplayFlairFinal(p, flair); - PluginMain.AppendPlayerDisplayFlairFinal(p, flair); - } - } - String msg="§6Reloaded config file.§r"; - if(player!=null) - player.sendMessage(msg); - else - System.out.println(msg); - } - } - catch(Exception e) - { - System.out.println("Error!\n"+e); - if(player!=null) - player.sendMessage("§cAn error occured. See console for details.§r"); - } - //} - //else - //player.sendMessage("§cYou need to be OP to use this command.§r"); - } - private static void DoAdmin(Player player, String[] args) - { //2015.08.09. - if(player==null || player.isOp() || player.getName()=="NorbiPeti") - { - if(args.length==1) - { - String message="§cUsage: /u admin reload|playerinfo§r"; - if(player==null) - System.out.println(message); - else - player.sendMessage(message); - return; - } - //args[0] is "admin" - switch(args[1].toLowerCase()) - { - case "reload": - DoReload(player); - break; - case "playerinfo": - DoPlayerInfo(player, args); - break; - } - } - else - player.sendMessage("§cYou need to be OP to use this command.§r"); - } - private static void DoPlayerInfo(Player player, String[] args) - { //2015.08.09. - //args[0] is "admin" - args[1] is "playerinfo" - if(args.length==2) - { - String message="§cUsage: /u admin playerinfo §r"; - if(player==null) - System.out.println(message); - else - player.sendMessage(message); - return; - } - - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/2c/10b26929df3e001517108d149b613203 b/.metadata/.plugins/org.eclipse.core.resources/.history/2c/10b26929df3e001517108d149b613203 new file mode 100644 index 0000000..5f009d8 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/2c/10b26929df3e001517108d149b613203 @@ -0,0 +1,251 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +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; + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. + //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) + if(p.Flair==null) + { + player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); + return true; + } + switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. + { + case "accept": + { + if(p.IgnoredFlair) + p.IgnoredFlair=false; //2015.08.08. + if(!p.AcceptedFlair) + { + String flair=p.Flair; //2015.08.08. + //PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + PluginMain.AppendPlayerDisplayFlair(p, player); + p.AcceptedFlair=true; //2015.08.08. + player.sendMessage("§6Your flair has been set:§r "+flair); + } + else + player.sendMessage("§cYou already have this user's flair.§r"); + break; + } + case "ignore": + { + if(p.AcceptedFlair) + p.AcceptedFlair=false; //2015.08.08. + if(!p.IgnoredFlair) + { + p.IgnoredFlair=true; + String flair=p.Flair; //2015.08.08. + PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. + player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); + } + else + player.sendMessage("§cYou already ignored this request.§r"); + break; + } + /*case "reload": //2015.07.20. + DoReload(player); + break;*/ + case "admin": //2015.08.09. + DoAdmin(player, args); + break; + case "nonpresser": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§7(non-pr.)§r"; + break; + case "cantpress": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§r(can't press)§r"; + break; + default: + return false; + } + return true; + } + /*if(args[0].toLowerCase()=="reload") + DoReload(null); //2015.07.20.*/ + else if(args.length>0 && args[0].toLowerCase().equals("admin")) //2015.08.09. + { + DoAdmin(null, args); //2015.08.09. + return true; //2015.08.09. + } + return false; + } + private static void DoReload(Player player) + { //2015.07.20. + //if(player==null || player.isOp() || player.getName()=="NorbiPeti") + //{ + try + { + File file=new File("autoflairconfig.txt"); + if(file.exists()) + { + PluginMain.LoadFiles(true); //2015.08.09. + for(Player p : PluginMain.GetPlayers()) + { + MaybeOfflinePlayer mp = MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName()); + if(mp.Flair!=null) + { + String flair=mp.Flair; + PluginMain.RemovePlayerDisplayFlairFinal(p, flair); + //PluginMain.AppendPlayerDisplayFlairFinal(p, flair); + PluginMain.AppendPlayerDisplayFlair(mp, p); //2015.08.09. + } + String msg="§6Note: The auto-flair plugin has been reloaded. You might need to wait 10s to have your flair.§r"; //2015.08.09. + p.sendMessage(msg); //2015.08.09. + } + //String msg="§6Reloaded config file.§r"; + //SendMessage(player, msg); //2015.08.09. + } + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + if(player!=null) + player.sendMessage("§cAn error occured. See console for details.§r"); + PluginMain.LastException=e; //2015.08.09. + } + //} + //else + //player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static Player ReloadPlayer; //2015.08.09. + private static void DoAdmin(Player player, String[] args) + { //2015.08.09. + if(player==null || player.isOp() || player.getName()=="NorbiPeti") + { + //System.out.println("Args length: " + args.length); + if(args.length==1) + { + String message="§cUsage: /u admin reload|playerinfo§r"; + SendMessage(player, message); + return; + } + //args[0] is "admin" + switch(args[1].toLowerCase()) + { + case "reload": + ReloadPlayer=player; //2015.08.09. + SendMessage(player, "§6Make sure to save the current settings before you modify and reload them! Type /u admin confirm when done.§r"); + break; + case "playerinfo": + DoPlayerInfo(player, args); + break; + case "getlasterror": + DoGetLastError(player, args); + case "confirm": + if(ReloadPlayer==player) + DoReload(player); //2015.08.09. + else + SendMessage(player, "§cYou need to do /u admin reload first.§r"); + break; + case "save": + PluginMain.SaveFiles(); //2015.08.09. + SendMessage(player, "§6Saved files. Now you can edit them and reload if you want.§r"); + break; + default: + String message="§cUsage: /u admin reload|playerinfo|getlasterror§r"; + SendMessage(player, message); + return; + } + } + else + player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static void DoPlayerInfo(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "playerinfo" + if(args.length==2) + { + String message="§cUsage: /u admin playerinfo §r"; + SendMessage(player, message); + return; + } + if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2])) + { + String message="§cPlayer not found: "+args[2]+"§r"; + SendMessage(player, message); + return; + } + MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]); + SendMessage(player, "Player name: "+p.PlayerName); + SendMessage(player, "User flair: "+p.Flair); + SendMessage(player, "Username: "+p.UserName); + SendMessage(player, "Flair accepted: "+p.AcceptedFlair); + SendMessage(player, "Flair ignored: "+p.IgnoredFlair); + } + private static void SendMessage(Player player, String message) + { //2015.08.09. + if(player==null) + System.out.println(message); + else + player.sendMessage(message); + } + private static void DoGetLastError(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "getlasterror" + if(PluginMain.LastException!=null) + { + SendMessage(player, "Last error:"); + SendMessage(player, PluginMain.LastException.toString()); + PluginMain.LastException=null; + } + else + SendMessage(player, "There were no exceptions."); + } + private static void SetPlayerFlair(Player player, String flair) + { //2015.08.09. + flair=flair.replace('&', '§'); + MaybeOfflinePlayer.AddPlayerIfNeeded(player.getName()).Flair=flair; + if(!PluginMain.RemoveLineFromFile("customflairs.txt")) + { + SendMessage(player, "Error removing previous custom flair!"); + return + } + File file=new File("customflairs.txt"); + try { + BufferedWriter bw; + bw = new BufferedWriter(new FileWriter(file, true)); + bw.write(player.getName()+"\n"); + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + PluginMain.LastException=e; //2015.08.09. + } + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/2d/00c8dce1df3e001517108d149b613203 b/.metadata/.plugins/org.eclipse.core.resources/.history/2d/00c8dce1df3e001517108d149b613203 new file mode 100644 index 0000000..ac8d077 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/2d/00c8dce1df3e001517108d149b613203 @@ -0,0 +1,255 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +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; + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. + //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) + if(p.Flair==null) + { + player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); + return true; + } + switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. + { + case "accept": + { + if(p.IgnoredFlair) + p.IgnoredFlair=false; //2015.08.08. + if(!p.AcceptedFlair) + { + String flair=p.Flair; //2015.08.08. + //PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + PluginMain.AppendPlayerDisplayFlair(p, player); + p.AcceptedFlair=true; //2015.08.08. + player.sendMessage("§6Your flair has been set:§r "+flair); + } + else + player.sendMessage("§cYou already have this user's flair.§r"); + break; + } + case "ignore": + { + if(p.AcceptedFlair) + p.AcceptedFlair=false; //2015.08.08. + if(!p.IgnoredFlair) + { + p.IgnoredFlair=true; + String flair=p.Flair; //2015.08.08. + PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. + player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); + } + else + player.sendMessage("§cYou already ignored this request.§r"); + break; + } + /*case "reload": //2015.07.20. + DoReload(player); + break;*/ + case "admin": //2015.08.09. + DoAdmin(player, args); + break; + case "nonpresser": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§7(non-pr.)§r"; + break; + case "cantpress": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§r(can't press)§r"; + break; + default: + return false; + } + return true; + } + /*if(args[0].toLowerCase()=="reload") + DoReload(null); //2015.07.20.*/ + else if(args.length>0 && args[0].toLowerCase().equals("admin")) //2015.08.09. + { + DoAdmin(null, args); //2015.08.09. + return true; //2015.08.09. + } + return false; + } + private static void DoReload(Player player) + { //2015.07.20. + //if(player==null || player.isOp() || player.getName()=="NorbiPeti") + //{ + try + { + File file=new File("autoflairconfig.txt"); + if(file.exists()) + { + PluginMain.LoadFiles(true); //2015.08.09. + for(Player p : PluginMain.GetPlayers()) + { + MaybeOfflinePlayer mp = MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName()); + if(mp.Flair!=null) + { + String flair=mp.Flair; + PluginMain.RemovePlayerDisplayFlairFinal(p, flair); + //PluginMain.AppendPlayerDisplayFlairFinal(p, flair); + PluginMain.AppendPlayerDisplayFlair(mp, p); //2015.08.09. + } + String msg="§6Note: The auto-flair plugin has been reloaded. You might need to wait 10s to have your flair.§r"; //2015.08.09. + p.sendMessage(msg); //2015.08.09. + } + //String msg="§6Reloaded config file.§r"; + //SendMessage(player, msg); //2015.08.09. + } + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + if(player!=null) + player.sendMessage("§cAn error occured. See console for details.§r"); + PluginMain.LastException=e; //2015.08.09. + } + //} + //else + //player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static Player ReloadPlayer; //2015.08.09. + private static void DoAdmin(Player player, String[] args) + { //2015.08.09. + if(player==null || player.isOp() || player.getName()=="NorbiPeti") + { + //System.out.println("Args length: " + args.length); + if(args.length==1) + { + String message="§cUsage: /u admin reload|playerinfo§r"; + SendMessage(player, message); + return; + } + //args[0] is "admin" + switch(args[1].toLowerCase()) + { + case "reload": + ReloadPlayer=player; //2015.08.09. + SendMessage(player, "§6Make sure to save the current settings before you modify and reload them! Type /u admin confirm when done.§r"); + break; + case "playerinfo": + DoPlayerInfo(player, args); + break; + case "getlasterror": + DoGetLastError(player, args); + case "confirm": + if(ReloadPlayer==player) + DoReload(player); //2015.08.09. + else + SendMessage(player, "§cYou need to do /u admin reload first.§r"); + break; + case "save": + PluginMain.SaveFiles(); //2015.08.09. + SendMessage(player, "§6Saved files. Now you can edit them and reload if you want.§r"); + break; + case "setflair": + + break; + default: + String message="§cUsage: /u admin reload|playerinfo|getlasterror|save§r"; + SendMessage(player, message); + return; + } + } + else + player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static void DoPlayerInfo(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "playerinfo" + if(args.length==2) + { + String message="§cUsage: /u admin playerinfo §r"; + SendMessage(player, message); + return; + } + if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2])) + { + String message="§cPlayer not found: "+args[2]+"§r"; + SendMessage(player, message); + return; + } + MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]); + SendMessage(player, "Player name: "+p.PlayerName); + SendMessage(player, "User flair: "+p.Flair); + SendMessage(player, "Username: "+p.UserName); + SendMessage(player, "Flair accepted: "+p.AcceptedFlair); + SendMessage(player, "Flair ignored: "+p.IgnoredFlair); + } + private static void SendMessage(Player player, String message) + { //2015.08.09. + if(player==null) + System.out.println(message); + else + player.sendMessage(message); + } + private static void DoGetLastError(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "getlasterror" + if(PluginMain.LastException!=null) + { + SendMessage(player, "Last error:"); + SendMessage(player, PluginMain.LastException.toString()); + PluginMain.LastException=null; + } + else + SendMessage(player, "There were no exceptions."); + } + private static void DoSetPlayerFlair(Player player, Player targetplayer, String flair) + { //2015.08.09. + flair=flair.replace('&', '§'); + MaybeOfflinePlayer.AddPlayerIfNeeded(player.getName()).Flair=flair; + if(!PluginMain.RemoveLineFromFile("customflairs.txt", targetplayer.getName())) + { + SendMessage(player, "§cError removing previous custom flair!§r"); + return; + } + File file=new File("customflairs.txt"); + try { + BufferedWriter bw; + bw = new BufferedWriter(new FileWriter(file, true)); + bw.write(targetplayer.getName()+"\n"); + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + PluginMain.LastException=e; //2015.08.09. + } + SendMessage(player, "§6The flair has been set. Player: "+targetplayer.getName()+" Flair: "+flair+"§r"); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/2d/c0b10f0c023e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/2d/c0b10f0c023e00151c31fb33fff4337f deleted file mode 100644 index 1174627..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/2d/c0b10f0c023e00151c31fb33fff4337f +++ /dev/null @@ -1,124 +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; - 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/003fe9fade3e001517108d149b613203 b/.metadata/.plugins/org.eclipse.core.resources/.history/2e/003fe9fade3e001517108d149b613203 new file mode 100644 index 0000000..99a2079 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/2e/003fe9fade3e001517108d149b613203 @@ -0,0 +1,250 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +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; + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. + //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) + if(p.Flair==null) + { + player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); + return true; + } + switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. + { + case "accept": + { + if(p.IgnoredFlair) + p.IgnoredFlair=false; //2015.08.08. + if(!p.AcceptedFlair) + { + String flair=p.Flair; //2015.08.08. + //PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + PluginMain.AppendPlayerDisplayFlair(p, player); + p.AcceptedFlair=true; //2015.08.08. + player.sendMessage("§6Your flair has been set:§r "+flair); + } + else + player.sendMessage("§cYou already have this user's flair.§r"); + break; + } + case "ignore": + { + if(p.AcceptedFlair) + p.AcceptedFlair=false; //2015.08.08. + if(!p.IgnoredFlair) + { + p.IgnoredFlair=true; + String flair=p.Flair; //2015.08.08. + PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. + player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); + } + else + player.sendMessage("§cYou already ignored this request.§r"); + break; + } + /*case "reload": //2015.07.20. + DoReload(player); + break;*/ + case "admin": //2015.08.09. + DoAdmin(player, args); + break; + case "nonpresser": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§7(non-pr.)§r"; + break; + case "cantpress": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§r(can't press)§r"; + break; + default: + return false; + } + return true; + } + /*if(args[0].toLowerCase()=="reload") + DoReload(null); //2015.07.20.*/ + else if(args.length>0 && args[0].toLowerCase().equals("admin")) //2015.08.09. + { + DoAdmin(null, args); //2015.08.09. + return true; //2015.08.09. + } + return false; + } + private static void DoReload(Player player) + { //2015.07.20. + //if(player==null || player.isOp() || player.getName()=="NorbiPeti") + //{ + try + { + File file=new File("autoflairconfig.txt"); + if(file.exists()) + { + PluginMain.LoadFiles(true); //2015.08.09. + for(Player p : PluginMain.GetPlayers()) + { + MaybeOfflinePlayer mp = MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName()); + if(mp.Flair!=null) + { + String flair=mp.Flair; + PluginMain.RemovePlayerDisplayFlairFinal(p, flair); + //PluginMain.AppendPlayerDisplayFlairFinal(p, flair); + PluginMain.AppendPlayerDisplayFlair(mp, p); //2015.08.09. + } + String msg="§6Note: The auto-flair plugin has been reloaded. You might need to wait 10s to have your flair.§r"; //2015.08.09. + p.sendMessage(msg); //2015.08.09. + } + //String msg="§6Reloaded config file.§r"; + //SendMessage(player, msg); //2015.08.09. + } + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + if(player!=null) + player.sendMessage("§cAn error occured. See console for details.§r"); + PluginMain.LastException=e; //2015.08.09. + } + //} + //else + //player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static Player ReloadPlayer; //2015.08.09. + private static void DoAdmin(Player player, String[] args) + { //2015.08.09. + if(player==null || player.isOp() || player.getName()=="NorbiPeti") + { + //System.out.println("Args length: " + args.length); + if(args.length==1) + { + String message="§cUsage: /u admin reload|playerinfo§r"; + SendMessage(player, message); + return; + } + //args[0] is "admin" + switch(args[1].toLowerCase()) + { + case "reload": + ReloadPlayer=player; //2015.08.09. + SendMessage(player, "§6Make sure to save the current settings before you modify and reload them! Type /u admin confirm when done.§r"); + break; + case "playerinfo": + DoPlayerInfo(player, args); + break; + case "getlasterror": + DoGetLastError(player, args); + case "confirm": + if(ReloadPlayer==player) + DoReload(player); //2015.08.09. + else + SendMessage(player, "§cYou need to do /u admin reload first.§r"); + break; + case "save": + PluginMain.SaveFiles(); //2015.08.09. + SendMessage(player, "§6Saved files. Now you can edit them and reload if you want.§r"); + break; + default: + String message="§cUsage: /u admin reload|playerinfo|getlasterror§r"; + SendMessage(player, message); + return; + } + } + else + player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static void DoPlayerInfo(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "playerinfo" + if(args.length==2) + { + String message="§cUsage: /u admin playerinfo §r"; + SendMessage(player, message); + return; + } + if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2])) + { + String message="§cPlayer not found: "+args[2]+"§r"; + SendMessage(player, message); + return; + } + MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]); + SendMessage(player, "Player name: "+p.PlayerName); + SendMessage(player, "User flair: "+p.Flair); + SendMessage(player, "Username: "+p.UserName); + SendMessage(player, "Flair accepted: "+p.AcceptedFlair); + SendMessage(player, "Flair ignored: "+p.IgnoredFlair); + } + public static void SendMessage(Player player, String message) + { //2015.08.09. + if(player==null) + System.out.println(message); + else + player.sendMessage(message); + } + private static void DoGetLastError(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "getlasterror" + if(PluginMain.LastException!=null) + { + SendMessage(player, "Last error:"); + SendMessage(player, PluginMain.LastException.toString()); + PluginMain.LastException=null; + } + else + SendMessage(player, "There were no exceptions."); + } + private static void SetPlayerFlair(Player player, String flair) + { //2015.08.09. + flair=flair.replace('&', '§'); + MaybeOfflinePlayer.AddPlayerIfNeeded(player.getName()).Flair=flair; + if(!PluginMain.RemoveLineFromFile("customflairs.txt")) + { + Commands.SendMessage(player, "") + } + File file=new File("customflairs.txt"); + try { + BufferedWriter bw; + bw = new BufferedWriter(new FileWriter(file, true)); + bw.write(player.getName()+"\n"); + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + PluginMain.LastException=e; //2015.08.09. + } + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/2e/807b35a8dd3e001517108d149b613203 b/.metadata/.plugins/org.eclipse.core.resources/.history/2e/807b35a8dd3e001517108d149b613203 new file mode 100644 index 0000000..9eedbdb --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/2e/807b35a8dd3e001517108d149b613203 @@ -0,0 +1,408 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStream; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLConnection; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + +import org.apache.commons.io.IOUtils; +import org.bukkit.entity.Player; +import org.bukkit.plugin.java.JavaPlugin; +import org.json.JSONArray; +import org.json.JSONObject; + +import com.palmergames.bukkit.towny.object.Town; +import com.palmergames.bukkit.towny.object.WorldCoord; + +public class PluginMain extends JavaPlugin +{ //Translated to Java: 2015.07.15. + //A user, which flair isn't obtainable: + //https://www.reddit.com/r/thebutton/comments/31c32v/i_pressed_the_button_without_really_thinking/ + private static PluginMain Instance; + // Fired when plugin is first enabled + @Override + public void onEnable() + { + System.out.println("The Button Auto-flair Plugin by NorbiPeti (:P)"); + getServer().getPluginManager().registerEvents(new PlayerListener(), this); + this.getCommand("u").setExecutor(new Commands()); + this.getCommand("u").setUsage(this.getCommand("u").getUsage().replace('&', '§')); + Instance=this; //2015.08.08. + LoadFiles(false); //2015.08.09. + Runnable r=new Runnable(){public void run(){ThreadMethod();}}; + Thread t=new Thread(r); + t.start(); + } + Boolean stop=false; + // Fired when plugin is disabled + @Override + public void onDisable() + { + SaveFiles(); //2015.08.09. + stop=true; + } + + public void ThreadMethod() //<-- 2015.07.16. + { + while(!stop) + { + try + { + String body=DownloadString("https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/autoflair_system_comment_your_minecraft_name_and/.json?limit=1000"); + JSONArray json=new JSONArray(body).getJSONObject(1).getJSONObject("data").getJSONArray("children"); + for(Object obj : json) + { + JSONObject item = (JSONObject)obj; + String author=item.getJSONObject("data").getString("author"); + String ign=item.getJSONObject("data").getString("body"); + int start = ign.indexOf("IGN:") + "IGN:".length(); + if(start==-1) + continue; //2015.08.09. + int end = ign.indexOf(' ', start); + if (end == -1 || end == start) + end=ign.indexOf('\n', start); //2015.07.15. + if (end == -1 || end == start) + ign = ign.substring(start); + else + ign = ign.substring(start, end); + ign = ign.trim(); + if(HasIGFlair(ign)) + continue; + try { + Thread.sleep(10); + } catch(InterruptedException ex) { + Thread.currentThread().interrupt(); + } + String[] flairdata = DownloadString("http://karmadecay.com/thebutton-data.php?users=" + author).replace("\"", "").split(":"); + String flair; + if(flairdata.length > 1) //2015.07.15. + flair = flairdata[1]; + else + flair=""; + if (flair != "-1") + flair = flair + "s"; + else + flair = "non-presser"; + String flairclass; + if(flairdata.length>2) + flairclass = flairdata[2]; + else + flairclass="unknown"; + SetFlair(ign, flair, flairclass, author); + } + Thread.sleep(10000); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + } + + public static Exception LastException; //2015.08.09. + + public String DownloadString(String urlstr) throws MalformedURLException, IOException + { + URL url = new URL(urlstr); + URLConnection con = url.openConnection(); + con.setRequestProperty("User-Agent", "TheButtonAutoFlair"); + InputStream in = con.getInputStream(); + String encoding = con.getContentEncoding(); + encoding = encoding == null ? "UTF-8" : encoding; + String body = IOUtils.toString(in, encoding); + in.close(); + return body; + } + + public static Map TownColors=new HashMap(); //2015.07.20. + public Boolean HasIGFlair(String playername) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + return p.Flair!=null; //2015.08.08. + } + + public void SetFlair(String playername, String text, String flairclass, String username) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + String finalflair; + p.FlairDecided=true; + switch(flairclass) + { + case "press-1": + finalflair="§c("+text+")§r"; + break; + case "press-2": + finalflair="§6("+text+")§r"; + break; + case "press-3": + finalflair="§e("+text+")§r"; + break; + case "press-4": + finalflair="§a("+text+")§r"; + break; + case "press-5": + finalflair="§9("+text+")§r"; + break; + 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; + case "undecided": //2015.08.09. + p.FlairDecided=false; + finalflair=""; + break; + default: + finalflair=""; + break; + } + if(finalflair.length()==0) //<-- 2015.07.20. + return; + p.Flair=finalflair; //2015.08.08. + p.UserName=username; //2015.08.08. + System.out.println("Added new flair to "+playername+": "+finalflair); + for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08. + { + if(player.getName().equals(playername)) + { + //AppendPlayerDisplayFlair(player, username, finalflair); + AppendPlayerDisplayFlair(p, player); + break; + } + } + } + + public static String GetFlair(Player player) + { //2015.07.16. + String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08. + return flair==null ? "" : flair; + } + + //public static void AppendPlayerDisplayFlair(Player player, String username, String flair) + public static void AppendPlayerDisplayFlair(MaybeOfflinePlayer player, Player p) //<-- 2015.08.09. + { + + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).IgnoredFlair) + return; + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).AcceptedFlair) + { + AppendPlayerDisplayFlairFinal(p, player.Flair); //2015.07.20. + if(!player.FlairDecided) + p.sendMessage("§9Your flair type is unknown. Are you a non-presser or a can't press? (/u nonpresser or /u cantpress)§r"); //2015.08.09. + } + else + p.sendMessage("§9Are you Reddit user "+player.UserName+"?§r §6Type /u accept or /u ignore§r"); + } + + private static void AppendPlayerDisplayFlairFinal(Player player, String flair) + { //2015.07.20. + String color = GetColorForTown(GetPlayerTown(player)); //TO!DO: Multiple colors put on first capital letters + String[] colors = color.substring(1).split("§"); + String displayname=player.getName(); //2015.08.08. + ArrayList Positions=new ArrayList<>(); + for(int i=0; i=colors.length) + { + int x=0; + for(int i=0; i GetPlayers() + { + return Instance.getServer().getOnlinePlayers(); + } + + public static void LoadFiles(boolean reload) //<-- 2015.08.09. + { + if(reload) + { //2015.08.09. + System.out.println("Auto-flair plugin cleanup for reloading..."); + MaybeOfflinePlayer.AllPlayers.clear(); + TownColors.clear(); + } + System.out.println("Loading files for auto-flair plugin..."); //2015.08.09. + try { + File file=new File("flairsaccepted.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + //System.out.println("Name: " + name); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("flairsignored.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsignored.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("autoflairconfig.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + TownColors.put(s[0], s[1]); + } + br.close(); + } + file=new File("customflairs.txt"); //2015.08.09. + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + MaybeOfflinePlayer.AddPlayerIfNeeded(s[0]).Flair=s[1]; //2015.08.09. + } + br.close(); + } + //throw new IOException("Test"); //2015.08.09. + System.out.println("Auto-flair plugin loaded files!"); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + public static void SaveFiles() //<-- 2015.08.09. + { + try + { + FileWriter fw; + fw = new FileWriter("flairsaccepted.txt"); + fw.close(); + fw = new FileWriter("flairsignored.txt"); + fw.close(); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + try { + File file=new File("flairsaccepted.txt"); + BufferedWriter bw=new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.AcceptedFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + file=new File("flairsignored.txt"); + bw = new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.IgnoredFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + public static void SetPlayerFlair(Player player, String flair) + { //2015.08.09. + flair=flair.replace('&', '§'); + MaybeOfflinePlayer.AddPlayerIfNeeded(player.getName()).Flair=flair; + File file=new File("customflairs.txt"); + BufferedWriter bw=new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) + { + if(!player.AcceptedFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/2e/90fc2ebfd23e001518fa86d7ae2a1cf8 b/.metadata/.plugins/org.eclipse.core.resources/.history/2e/90fc2ebfd23e001518fa86d7ae2a1cf8 new file mode 100644 index 0000000..717cff8 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/2e/90fc2ebfd23e001518fa86d7ae2a1cf8 @@ -0,0 +1,215 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; + +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class Commands implements CommandExecutor { + // This method is called, when somebody uses our command + @Override + public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { + if (sender instanceof Player) { + Player player = (Player) sender; + if(args.length<1) + return false; + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. + //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) + if(p.Flair==null) + { + player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); + return true; + } + switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. + { + case "accept": + { + if(p.IgnoredFlair) + p.IgnoredFlair=false; //2015.08.08. + if(!p.AcceptedFlair) + { + String flair=p.Flair; //2015.08.08. + //PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + PluginMain.AppendPlayerDisplayFlair(p, player); + p.AcceptedFlair=true; //2015.08.08. + player.sendMessage("§6Your flair has been set:§r "+flair); + } + else + player.sendMessage("§cYou already have this user's flair.§r"); + break; + } + case "ignore": + { + if(p.AcceptedFlair) + p.AcceptedFlair=false; //2015.08.08. + if(!p.IgnoredFlair) + { + p.IgnoredFlair=true; + String flair=p.Flair; //2015.08.08. + PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. + player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); + } + else + player.sendMessage("§cYou already ignored this request.§r"); + break; + } + /*case "reload": //2015.07.20. + DoReload(player); + break;*/ + case "admin": //2015.08.09. + DoAdmin(player, args); + break; + case "nonpresser": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§7(non-pr.)§r"; + break; + case "cantpress": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§r(can't press)§r"; + break; + default: + return false; + } + return true; + } + /*if(args[0].toLowerCase()=="reload") + DoReload(null); //2015.07.20.*/ + else if(args.length>0 && args[0].toLowerCase().equals("admin")) //2015.08.09. + { + DoAdmin(null, args); //2015.08.09. + return true; //2015.08.09. + } + return false; + } + private static void DoReload(Player player) + { //2015.07.20. + //if(player==null || player.isOp() || player.getName()=="NorbiPeti") + //{ + try + { + File file=new File("autoflairconfig.txt"); + if(file.exists()) + { + PluginMain.LoadFiles(true); + 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); + PluginMain.AppendPlayerDisplayFlair(mp, p); //2015.08.09. + } + } + //String msg="§6Reloaded config file.§r"; + String msg="§6Reloaded all files.§r"; + SendMessage(player, msg); //2015.08.09. + } + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + if(player!=null) + player.sendMessage("§cAn error occured. See console for details.§r"); + PluginMain.LastException=e; //2015.08.09. + } + //} + //else + //player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static void DoAdmin(Player player, String[] args) + { //2015.08.09. + if(player==null || player.isOp() || player.getName()=="NorbiPeti") + { + //System.out.println("Args length: " + args.length); + if(args.length==1) + { + String message="§cUsage: /u admin reload|playerinfo§r"; + SendMessage(player, message); + return; + } + //args[0] is "admin" + switch(args[1].toLowerCase()) + { + case "reload": + DoReload(player); + break; + case "playerinfo": + DoPlayerInfo(player, args); + break; + case "getlasterror": + DoGetLastError(player, args); + default: + String message="§cUsage: /u admin reload|playerinfo§r"; + SendMessage(player, message); + return; + } + } + else + player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static void DoPlayerInfo(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "playerinfo" + if(args.length==2) + { + String message="§cUsage: /u admin playerinfo §r"; + SendMessage(player, message); + return; + } + if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2])) + { + String message="§cPlayer not found: "+args[2]+"§r"; + SendMessage(player, message); + return; + } + MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]); + SendMessage(player, "Player name: "+p.PlayerName); + SendMessage(player, "User flair: "+p.Flair); + SendMessage(player, "Username: "+p.UserName); + SendMessage(player, "Flair accepted: "+p.AcceptedFlair); + SendMessage(player, "Flair ignored: "+p.IgnoredFlair); + } + private static void SendMessage(Player player, String message) + { //2015.08.09. + if(player==null) + System.out.println(message); + else + player.sendMessage(message); + } + private static void DoGetLastError(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "getlasterror" + if(PluginMain.LastException!=null) + { + SendMessage(player, "Last error:"); + SendMessage(player, PluginMain.LastException.toString()); + PluginMain.LastException=null; + } + else + SendMessage(player, "There were no exceptions."); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/2f/1089a9abdc3e001517108d149b613203 b/.metadata/.plugins/org.eclipse.core.resources/.history/2f/1089a9abdc3e001517108d149b613203 new file mode 100644 index 0000000..2c1a551 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/2f/1089a9abdc3e001517108d149b613203 @@ -0,0 +1,394 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStream; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLConnection; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + +import org.apache.commons.io.IOUtils; +import org.bukkit.entity.Player; +import org.bukkit.plugin.java.JavaPlugin; +import org.json.JSONArray; +import org.json.JSONObject; + +import com.palmergames.bukkit.towny.object.Town; +import com.palmergames.bukkit.towny.object.WorldCoord; + +public class PluginMain extends JavaPlugin +{ //Translated to Java: 2015.07.15. + //A user, which flair isn't obtainable: + //https://www.reddit.com/r/thebutton/comments/31c32v/i_pressed_the_button_without_really_thinking/ + private static PluginMain Instance; + // Fired when plugin is first enabled + @Override + public void onEnable() + { + System.out.println("The Button Auto-flair Plugin by NorbiPeti (:P)"); + getServer().getPluginManager().registerEvents(new PlayerListener(), this); + this.getCommand("u").setExecutor(new Commands()); + this.getCommand("u").setUsage(this.getCommand("u").getUsage().replace('&', '§')); + Instance=this; //2015.08.08. + LoadFiles(false); //2015.08.09. + Runnable r=new Runnable(){public void run(){ThreadMethod();}}; + Thread t=new Thread(r); + t.start(); + } + Boolean stop=false; + // Fired when plugin is disabled + @Override + public void onDisable() + { + SaveFiles(); //2015.08.09. + stop=true; + } + + public void ThreadMethod() //<-- 2015.07.16. + { + while(!stop) + { + try + { + String body=DownloadString("https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/autoflair_system_comment_your_minecraft_name_and/.json?limit=1000"); + JSONArray json=new JSONArray(body).getJSONObject(1).getJSONObject("data").getJSONArray("children"); + for(Object obj : json) + { + JSONObject item = (JSONObject)obj; + String author=item.getJSONObject("data").getString("author"); + String ign=item.getJSONObject("data").getString("body"); + int start = ign.indexOf("IGN:") + "IGN:".length(); + if(start==-1) + continue; //2015.08.09. + int end = ign.indexOf(' ', start); + if (end == -1 || end == start) + end=ign.indexOf('\n', start); //2015.07.15. + if (end == -1 || end == start) + ign = ign.substring(start); + else + ign = ign.substring(start, end); + ign = ign.trim(); + if(HasIGFlair(ign)) + continue; + try { + Thread.sleep(10); + } catch(InterruptedException ex) { + Thread.currentThread().interrupt(); + } + String[] flairdata = DownloadString("http://karmadecay.com/thebutton-data.php?users=" + author).replace("\"", "").split(":"); + String flair; + if(flairdata.length > 1) //2015.07.15. + flair = flairdata[1]; + else + flair=""; + if (flair != "-1") + flair = flair + "s"; + else + flair = "non-presser"; + String flairclass; + if(flairdata.length>2) + flairclass = flairdata[2]; + else + flairclass="unknown"; + SetFlair(ign, flair, flairclass, author); + } + Thread.sleep(10000); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + } + + public static Exception LastException; //2015.08.09. + + public String DownloadString(String urlstr) throws MalformedURLException, IOException + { + URL url = new URL(urlstr); + URLConnection con = url.openConnection(); + con.setRequestProperty("User-Agent", "TheButtonAutoFlair"); + InputStream in = con.getInputStream(); + String encoding = con.getContentEncoding(); + encoding = encoding == null ? "UTF-8" : encoding; + String body = IOUtils.toString(in, encoding); + in.close(); + return body; + } + + public static Map TownColors=new HashMap(); //2015.07.20. + public Boolean HasIGFlair(String playername) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + return p.Flair!=null; //2015.08.08. + } + + public void SetFlair(String playername, String text, String flairclass, String username) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + String finalflair; + p.FlairDecided=true; + switch(flairclass) + { + case "press-1": + finalflair="§c("+text+")§r"; + break; + case "press-2": + finalflair="§6("+text+")§r"; + break; + case "press-3": + finalflair="§e("+text+")§r"; + break; + case "press-4": + finalflair="§a("+text+")§r"; + break; + case "press-5": + finalflair="§9("+text+")§r"; + break; + 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; + case "undecided": //2015.08.09. + p.FlairDecided=false; + finalflair=""; + break; + default: + finalflair=""; + break; + } + if(finalflair.length()==0) //<-- 2015.07.20. + return; + p.Flair=finalflair; //2015.08.08. + p.UserName=username; //2015.08.08. + System.out.println("Added new flair to "+playername+": "+finalflair); + for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08. + { + if(player.getName().equals(playername)) + { + //AppendPlayerDisplayFlair(player, username, finalflair); + AppendPlayerDisplayFlair(p, player); + break; + } + } + } + + public static String GetFlair(Player player) + { //2015.07.16. + String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08. + return flair==null ? "" : flair; + } + + //public static void AppendPlayerDisplayFlair(Player player, String username, String flair) + public static void AppendPlayerDisplayFlair(MaybeOfflinePlayer player, Player p) //<-- 2015.08.09. + { + + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).IgnoredFlair) + return; + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).AcceptedFlair) + { + AppendPlayerDisplayFlairFinal(p, player.Flair); //2015.07.20. + if(!player.FlairDecided) + p.sendMessage("§9Your flair type is unknown. Are you a non-presser or a can't press? (/u nonpresser or /u cantpress)§r"); //2015.08.09. + } + else + p.sendMessage("§9Are you Reddit user "+player.UserName+"?§r §6Type /u accept or /u ignore§r"); + } + + private static void AppendPlayerDisplayFlairFinal(Player player, String flair) + { //2015.07.20. + String color = GetColorForTown(GetPlayerTown(player)); //TO!DO: Multiple colors put on first capital letters + String[] colors = color.substring(1).split("§"); + String displayname=player.getName(); //2015.08.08. + ArrayList Positions=new ArrayList<>(); + for(int i=0; i=colors.length) + { + int x=0; + for(int i=0; i GetPlayers() + { + return Instance.getServer().getOnlinePlayers(); + } + + public static void LoadFiles(boolean reload) //<-- 2015.08.09. + { + if(reload) + { //2015.08.09. + System.out.println("Auto-flair plugin cleanup for reloading..."); + MaybeOfflinePlayer.AllPlayers.clear(); + TownColors.clear(); + } + System.out.println("Loading files for auto-flair plugin..."); //2015.08.09. + try { + File file=new File("flairsaccepted.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + //System.out.println("Name: " + name); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("flairsignored.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsignored.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("autoflairconfig.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + TownColors.put(s[0], s[1]); + } + br.close(); + } + file=new File("autoflairdecisions.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + + } + br.close(); + } + //throw new IOException("Test"); //2015.08.09. + System.out.println("Auto-flair plugin loaded files!"); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + public static void SaveFiles() //<-- 2015.08.09. + { + try + { + FileWriter fw; + fw = new FileWriter("flairsaccepted.txt"); + fw.close(); + fw = new FileWriter("flairsignored.txt"); + fw.close(); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + try { + File file=new File("flairsaccepted.txt"); + BufferedWriter bw=new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.AcceptedFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + file=new File("flairsignored.txt"); + bw = new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.IgnoredFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/2f/6035f831893e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/2f/6035f831893e00151ce8ff6d4f74dabd deleted file mode 100644 index e2107b1..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/2f/6035f831893e00151ce8ff6d4f74dabd +++ /dev/null @@ -1,169 +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; - MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. - //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - if(p.Flair==null) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. - { - case "accept": - { - if(p.IgnoredFlair) - p.IgnoredFlair=false; //2015.08.08. - if(!p.AcceptedFlair) - { - String flair=p.Flair; //2015.08.08. - PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. - p.AcceptedFlair=true; //2015.08.08. - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("§cYou already have this user's flair.§r"); - break; - } - case "ignore": - { - if(p.AcceptedFlair) - p.AcceptedFlair=false; //2015.08.08. - if(!p.IgnoredFlair) - { - p.IgnoredFlair=true; - String flair=p.Flair; //2015.08.08. - PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. - player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); - } - else - player.sendMessage("§cYou already ignored this request.§r"); - break; - } - /*case "reload": //2015.07.20. - DoReload(player); - break;*/ - case "admin": //2015.08.09. - DoAdmin(player, args); - break; - default: - return false; - } - return true; - } - - /*if(args[0].toLowerCase()=="reload") - DoReload(null); //2015.07.20.*/ - else if(args[0].toLowerCase()=="admin") - DoAdmin(null, args); //2015.08.09. - return false; - } - private static void DoReload(Player player) - { //2015.07.20. - //if(player==null || player.isOp() || player.getName()=="NorbiPeti") - //{ - try - { - File file=new File("autoflairconfig.txt"); - if(file.exists()) - { - PluginMain.TownColors.clear(); - BufferedReader br=new BufferedReader(new FileReader(file)); - String line; - while((line=br.readLine())!=null) - { - String[] s=line.split(" "); - PluginMain.TownColors.put(s[0], s[1]); - } - br.close(); - for(Player p : PluginMain.GetPlayers()) - { - MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName()); - if(mp.Flair!=null) - { - String flair=mp.Flair; - PluginMain.RemovePlayerDisplayFlairFinal(p, flair); - PluginMain.AppendPlayerDisplayFlairFinal(p, flair); - } - } - String msg="§6Reloaded config file.§r"; - SendMessage(player, msg); //2015.08.09. - } - } - catch(Exception e) - { - System.out.println("Error!\n"+e); - if(player!=null) - player.sendMessage("§cAn error occured. See console for details.§r"); - } - //} - //else - //player.sendMessage("§cYou need to be OP to use this command.§r"); - } - private static void DoAdmin(Player player, String[] args) - { //2015.08.09. - if(player==null || player.isOp() || player.getName()=="NorbiPeti") - { - if(args.length==1) - { - String message="§cUsage: /u admin reload|playerinfo§r"; - SendMessage(player, message); - return; - } - //args[0] is "admin" - switch(args[1].toLowerCase()) - { - case "reload": - DoReload(player); - break; - case "playerinfo": - DoPlayerInfo(player, args); - break; - } - } - else - player.sendMessage("§cYou need to be OP to use this command.§r"); - } - private static void DoPlayerInfo(Player player, String[] args) - { //2015.08.09. - //args[0] is "admin" - args[1] is "playerinfo" - if(args.length==2) - { - String message="§cUsage: /u admin playerinfo §r"; - SendMessage(player, message); - } - if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2])) - { - String message="§cPlayer not found: "+args[2]+"§r"; - SendMessage(player, message); - } - MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]); - SendMessage(player, "User flair: "+p.Flair); - SendMessage(player, "Player name: "+p.PlayerName); - return; - } - private static void SendMessage(Player player, String message) - { //2015.08.09. - if(player==null) - System.out.println(message); - else - player.sendMessage(message); - return; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/30/10d5c0cc303e00151cbdba8b5f0a340e b/.metadata/.plugins/org.eclipse.core.resources/.history/30/10d5c0cc303e00151cbdba8b5f0a340e deleted file mode 100644 index 8f610fd..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/30/10d5c0cc303e00151cbdba8b5f0a340e +++ /dev/null @@ -1,424 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import java.io.BufferedReader; -import java.io.BufferedWriter; -import java.io.File; -import java.io.FileReader; -import java.io.FileWriter; -import java.io.IOException; -import java.io.InputStream; -import java.net.MalformedURLException; -import java.net.URL; -import java.net.URLConnection; -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; -import java.util.Map; - -import org.apache.commons.io.IOUtils; -import org.bukkit.entity.Player; -import org.bukkit.plugin.java.JavaPlugin; -import org.json.JSONArray; -import org.json.JSONObject; - -import com.palmergames.bukkit.towny.object.Town; -import com.palmergames.bukkit.towny.object.TownyUniverse; -import com.palmergames.bukkit.towny.object.WorldCoord; - -public class PluginMain extends JavaPlugin -{ //Translated to Java: 2015.07.15. - //A user, which flair isn't obtainable: - //https://www.reddit.com/r/thebutton/comments/31c32v/i_pressed_the_button_without_really_thinking/ - private static PluginMain Instance; - // Fired when plugin is first enabled - @Override - public void onEnable() - { - System.out.println("The Button Auto-flair Plugin by NorbiPeti (:P)"); - getServer().getPluginManager().registerEvents(new PlayerListener(), this); - this.getCommand("u").setExecutor(new Commands()); - this.getCommand("u").setUsage(this.getCommand("u").getUsage().replace('&', '§')); - Instance=this; //2015.08.08. - try { - File file=new File("flairsaccepted.txt"); - if(file.exists()) - { - BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt")); - String line; - while ((line = br.readLine()) != null) - { - //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.PlayerName+"\n"); - bw.close(); - } catch (IOException e) { - System.out.println("Error!\n"+e); - } - } - stop=true; - } - - public void ThreadMethod() //<-- 2015.07.16. - { - /*System.out.println("Sleeping for 5 seconds..."); //2015.07.20. - try { - Thread.sleep(5000); - } catch (InterruptedException e1) { - e1.printStackTrace(); - } //2015.07.20.*/ - while(!stop) - { - try - { - String body=DownloadString("https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/autoflair_system_comment_your_minecraft_name_and/.json?limit=1000"); - JSONArray json=new JSONArray(body).getJSONObject(1).getJSONObject("data").getJSONArray("children"); - for(Object obj : json) - { - JSONObject item = (JSONObject)obj; - String author=item.getJSONObject("data").getString("author"); - String ign=item.getJSONObject("data").getString("body"); - int start = ign.indexOf("IGN:") + "IGN:".length(); - int end = ign.indexOf(' ', start); - if (end == -1 || end == start) - end=ign.indexOf('\n', start); //2015.07.15. - if (end == -1 || end == start) - ign = ign.substring(start); - else - ign = ign.substring(start, end); - ign = ign.trim(); - if(HasIGFlair(ign)) - continue; - //System.out.println("Author: "+author); - try { - Thread.sleep(10); - } catch(InterruptedException ex) { - Thread.currentThread().interrupt(); - } - String[] flairdata = DownloadString("http://karmadecay.com/thebutton-data.php?users=" + author).replace("\"", "").split(":"); - String flair; - if(flairdata.length > 1) //2015.07.15. - flair = flairdata[1]; - else - flair=""; - if (flair != "-1") - flair = flair + "s"; - else - flair = "non-presser"; - String flairclass; - //System.out.println("flairdata.length:"+flairdata.length); - if(flairdata.length>2) - flairclass = flairdata[2]; - else - flairclass="unknown"; - SetFlair(ign, flair, flairclass, author); - } - Thread.sleep(10000); - } - catch(Exception e) - { - System.out.println("Error!\n"+e); - } - } - } - - public String DownloadString(String urlstr) throws MalformedURLException, IOException - { - URL url = new URL(urlstr); - URLConnection con = url.openConnection(); - con.setRequestProperty("User-Agent", "TheButtonAutoFlair"); - InputStream in = con.getInputStream(); - String encoding = con.getContentEncoding(); - encoding = encoding == null ? "UTF-8" : encoding; - String body = IOUtils.toString(in, encoding); - in.close(); - return body; - } - - //It has to store offline player flairs too, therefore it can't use Player object - /*public static Map PlayerFlairs=new HashMap(); - public static Map PlayerUserNames=new HashMap(); - //public Map PlayerFlairs=new HashMap(); - public static ArrayList Players=new ArrayList(); - public static ArrayList AcceptedPlayers=new ArrayList(); //2015.07.16. - public static ArrayList IgnoredPlayers=new ArrayList(); //2015.07.16. - //public static Map PlayerTowns=new HashMap(); //2015.07.20.*/ - public static Map TownColors=new HashMap(); //2015.07.20. - public Boolean HasIGFlair(String playername) - { - /*Player player=null; - for(Player p : Players) - { - if(p.getName()==playername) - { - player=p; - break; - } - } - if(player==null) - return false;*/ - //return PlayerFlairs.containsKey(playername); - //return MaybeOfflinePlayer.AllPlayers.containsKey(playername); - MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. - return p.Flair!=null; //2015.08.08. - } - - public void SetFlair(String playername, String text, String flairclass, String username) - { - String finalflair; - switch(flairclass) - { - case "press-1": - finalflair="§c("+text+")§r"; - break; - case "press-2": - finalflair="§6("+text+")§r"; - break; - case "press-3": - finalflair="§e("+text+")§r"; - break; - case "press-4": - finalflair="§a("+text+")§r"; - break; - case "press-5": - finalflair="§9("+text+")§r"; - break; - case "press-6": - finalflair="§5("+text+")§r"; - break; - case "no-press": - finalflair="§7(non-pr.)§r"; - break; - case "cheater": - finalflair="§5("+text+")§r"; - break; - case "cant-press": //2015.08.08. - finalflair="§r(can't press)§r"; - break; - default: - finalflair=""; - break; - } - if(finalflair.length()==0) //<-- 2015.07.20. - return; - //PlayerFlairs.put(playername, finalflair); - //PlayerUserNames.put(playername, username); - MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. - p.Flair=finalflair; //2015.08.08. - p.UserName=username; //2015.08.08. - /*for(Player player : Players) - { - if(player.getName()==playername) - { - PlayerFlairs.put(player, finalflair); - break; - } - }*/ - //System.out.println("SetFlair - playername: "+playername+" text: "+text+" flairclass: "+flairclass); - System.out.println("Added new flair to "+playername+": "+finalflair); - //for(Player player : Players) - for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08. - { - //System.out.println("Online player: "+player.getName()); - //System.out.println("player.getName ("+player.getName()+") == playername ("+playername+"): "+(player.getName()==playername)); - if(player.getName().equals(playername)) - { - //System.out.println("DisplayName: "+player.getDisplayName()); - //player.setDisplayName(player.getDisplayName()+finalflair); - AppendPlayerDisplayFlair(player, username, finalflair); - //System.out.println("DisplayName: "+player.getDisplayName()); - break; - } - } - } - - public static String GetFlair(Player player) - { //2015.07.16. - //String flair=PlayerFlairs.get(player.getName()); - String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08. - return flair==null ? "" : flair; - } - - public static void AppendPlayerDisplayFlair(Player player, String username, String flair) - { - //if(IgnoredPlayers.contains(player.getName())) - if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).IgnoredFlair) - return; - //if(AcceptedPlayers.contains(player.getName())) - if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).AcceptedFlair) - //player.setDisplayName(player.getDisplayName()+flair); - AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. - else - player.sendMessage("§9Are you Reddit user "+username+"?§r §6Type /u accept or /u ignore§r"); - } - - public static void AppendPlayerDisplayFlairFinal(Player player, String flair) - { //2015.07.20. - //System.out.println("A"); - String color = GetColorForTown(GetPlayerTown(player)); //TO!DO: Multiple colors put on first capital letters - String[] colors = color.substring(1).split("§"); - //String displayname=player.getDisplayName(); - String displayname=player.getName(); //2015.08.08. - ArrayList Positions=new ArrayList<>(); - //System.out.println("B"); - for(int i=0; i=colors.length) - { - //System.out.println("D"); - int x=0; - for(int i=0; i towns = TownyUniverse.getDataSource().getTowns(); - try { - Town town = WorldCoord.parseWorldCoord(player).getTownBlock().getTown(); //TODO - return town.getName(); - } catch (Exception e) { - return ""; - } - } - - public static void RemovePlayerDisplayFlairFinal(Player player, String flair) - { //2015.07.20. - //String color = GetColorForTown(GetPlayerTown(player)); - //String dname=player.getDisplayName(); - //player.setDisplayName(dname.substring(dname.indexOf(color)+3, dname.indexOf(flair))); - //MaybeOfflinePlayer.AllPlayers.get(player.getName()).DisplayName=null; //2015.08.08. - MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair=null; //2015.08.08. - } - - public static Collection GetPlayers() - { - return Instance.getServer().getOnlinePlayers(); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/30/20a0c374d23e001518fa86d7ae2a1cf8 b/.metadata/.plugins/org.eclipse.core.resources/.history/30/20a0c374d23e001518fa86d7ae2a1cf8 new file mode 100644 index 0000000..641be01 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/30/20a0c374d23e001518fa86d7ae2a1cf8 @@ -0,0 +1,345 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStream; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLConnection; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + +import org.apache.commons.io.IOUtils; +import org.bukkit.entity.Player; +import org.bukkit.plugin.java.JavaPlugin; +import org.json.JSONArray; +import org.json.JSONObject; + +import com.palmergames.bukkit.towny.object.Town; +import com.palmergames.bukkit.towny.object.WorldCoord; + +public class PluginMain extends JavaPlugin +{ //Translated to Java: 2015.07.15. + //A user, which flair isn't obtainable: + //https://www.reddit.com/r/thebutton/comments/31c32v/i_pressed_the_button_without_really_thinking/ + private static PluginMain Instance; + // Fired when plugin is first enabled + @Override + public void onEnable() + { + System.out.println("The Button Auto-flair Plugin by NorbiPeti (:P)"); + getServer().getPluginManager().registerEvents(new PlayerListener(), this); + this.getCommand("u").setExecutor(new Commands()); + this.getCommand("u").setUsage(this.getCommand("u").getUsage().replace('&', '§')); + Instance=this; //2015.08.08. + LoadFiles(false); //2015.08.09. + Runnable r=new Runnable(){public void run(){ThreadMethod();}}; + Thread t=new Thread(r); + t.start(); + } + Boolean stop=false; + // Fired when plugin is disabled + @Override + public void onDisable() + { + SaveFiles(); //2015.08.09. + stop=true; + } + + public void ThreadMethod() //<-- 2015.07.16. + { + while(!stop) + { + try + { + String body=DownloadString("https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/autoflair_system_comment_your_minecraft_name_and/.json?limit=1000"); + JSONArray json=new JSONArray(body).getJSONObject(1).getJSONObject("data").getJSONArray("children"); + for(Object obj : json) + { + JSONObject item = (JSONObject)obj; + String author=item.getJSONObject("data").getString("author"); + String ign=item.getJSONObject("data").getString("body"); + int start = ign.indexOf("IGN:") + "IGN:".length(); + int end = ign.indexOf(' ', start); + if (end == -1 || end == start) + end=ign.indexOf('\n', start); //2015.07.15. + if (end == -1 || end == start) + ign = ign.substring(start); + else + ign = ign.substring(start, end); + ign = ign.trim(); + if(HasIGFlair(ign)) + continue; + try { + Thread.sleep(10); + } catch(InterruptedException ex) { + Thread.currentThread().interrupt(); + } + String[] flairdata = DownloadString("http://karmadecay.com/thebutton-data.php?users=" + author).replace("\"", "").split(":"); + String flair; + if(flairdata.length > 1) //2015.07.15. + flair = flairdata[1]; + else + flair=""; + if (flair != "-1") + flair = flair + "s"; + else + flair = "non-presser"; + String flairclass; + if(flairdata.length>2) + flairclass = flairdata[2]; + else + flairclass="unknown"; + SetFlair(ign, flair, flairclass, author); + } + Thread.sleep(10000); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + } + + public static Exception LastException; //2015.08.09. + + public String DownloadString(String urlstr) throws MalformedURLException, IOException + { + URL url = new URL(urlstr); + URLConnection con = url.openConnection(); + con.setRequestProperty("User-Agent", "TheButtonAutoFlair"); + InputStream in = con.getInputStream(); + String encoding = con.getContentEncoding(); + encoding = encoding == null ? "UTF-8" : encoding; + String body = IOUtils.toString(in, encoding); + in.close(); + return body; + } + + public static Map TownColors=new HashMap(); //2015.07.20. + public Boolean HasIGFlair(String playername) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + return p.Flair!=null; //2015.08.08. + } + + public void SetFlair(String playername, String text, String flairclass, String username) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + String finalflair; + p.FlairDecided=true; + switch(flairclass) + { + case "press-1": + finalflair="§c("+text+")§r"; + break; + case "press-2": + finalflair="§6("+text+")§r"; + break; + case "press-3": + finalflair="§e("+text+")§r"; + break; + case "press-4": + finalflair="§a("+text+")§r"; + break; + case "press-5": + finalflair="§9("+text+")§r"; + break; + 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; + case "undecided": //2015.08.09. + p.FlairDecided=false; + finalflair=""; + break; + default: + finalflair=""; + break; + } + if(finalflair.length()==0) //<-- 2015.07.20. + return; + p.Flair=finalflair; //2015.08.08. + p.UserName=username; //2015.08.08. + System.out.println("Added new flair to "+playername+": "+finalflair); + for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08. + { + if(player.getName().equals(playername)) + { + //AppendPlayerDisplayFlair(player, username, finalflair); + AppendPlayerDisplayFlair(p, player); + break; + } + } + } + + public static String GetFlair(Player player) + { //2015.07.16. + String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08. + return flair==null ? "" : flair; + } + + //public static void AppendPlayerDisplayFlair(Player player, String username, String flair) + public static void AppendPlayerDisplayFlair(MaybeOfflinePlayer player, Player p) //<-- 2015.08.09. + { + + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).IgnoredFlair) + return; + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).AcceptedFlair) + { + AppendPlayerDisplayFlairFinal(p, player.Flair); //2015.07.20. + if(!player.FlairDecided) + p.sendMessage("§9Your flair type is unknown. Are you a non-presser or a can't press? (/u nonpresser or /u cantpress)§r"); //2015.08.09. + } + else + p.sendMessage("§9Are you Reddit user "+player.UserName+"?§r §6Type /u accept or /u ignore§r"); + } + + private static void AppendPlayerDisplayFlairFinal(Player player, String flair) + { //2015.07.20. + String color = GetColorForTown(GetPlayerTown(player)); //TO!DO: Multiple colors put on first capital letters + String[] colors = color.substring(1).split("§"); + String displayname=player.getName(); //2015.08.08. + ArrayList Positions=new ArrayList<>(); + for(int i=0; i=colors.length) + { + int x=0; + for(int i=0; i GetPlayers() + { + return Instance.getServer().getOnlinePlayers(); + } + + public static void LoadFiles(boolean reload) //<-- 2015.08.09. + { + if(reload) + { //2015.08.09. + System.out.println("Auto-flair plugin cleanup for reloading..."); + MaybeOfflinePlayer.AllPlayers.clear(); + TownColors.clear(); + } + System.out.println("Loading files for auto-flair plugin..."); //2015.08.09. + try { + File file=new File("flairsaccepted.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + //System.out.println("Name: " + name); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("flairsignored.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsignored.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("autoflairconfig.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + TownColors.put(s[0], s[1]); + } + br.close(); + } + //throw new IOException("Test"); //2015.08.09. + System.out.println("Auto-flair plugin loaded files!"); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + public static void SaveFiles() //<-- 2015.08.09. + { + + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/30/706b3ad0303e00151cbdba8b5f0a340e b/.metadata/.plugins/org.eclipse.core.resources/.history/30/706b3ad0303e00151cbdba8b5f0a340e deleted file mode 100644 index 206493e..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/30/706b3ad0303e00151cbdba8b5f0a340e +++ /dev/null @@ -1,422 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import java.io.BufferedReader; -import java.io.BufferedWriter; -import java.io.File; -import java.io.FileReader; -import java.io.FileWriter; -import java.io.IOException; -import java.io.InputStream; -import java.net.MalformedURLException; -import java.net.URL; -import java.net.URLConnection; -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; -import java.util.Map; - -import org.apache.commons.io.IOUtils; -import org.bukkit.entity.Player; -import org.bukkit.plugin.java.JavaPlugin; -import org.json.JSONArray; -import org.json.JSONObject; - -import com.palmergames.bukkit.towny.object.Town; -import com.palmergames.bukkit.towny.object.TownyUniverse; -import com.palmergames.bukkit.towny.object.WorldCoord; - -public class PluginMain extends JavaPlugin -{ //Translated to Java: 2015.07.15. - //A user, which flair isn't obtainable: - //https://www.reddit.com/r/thebutton/comments/31c32v/i_pressed_the_button_without_really_thinking/ - private static PluginMain Instance; - // Fired when plugin is first enabled - @Override - public void onEnable() - { - System.out.println("The Button Auto-flair Plugin by NorbiPeti (:P)"); - getServer().getPluginManager().registerEvents(new PlayerListener(), this); - this.getCommand("u").setExecutor(new Commands()); - this.getCommand("u").setUsage(this.getCommand("u").getUsage().replace('&', '§')); - Instance=this; //2015.08.08. - try { - File file=new File("flairsaccepted.txt"); - if(file.exists()) - { - BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt")); - String line; - while ((line = br.readLine()) != null) - { - String name=line.replace("\n", ""); - System.out.println("Name: " + name); - MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08. - } - br.close(); - } - file=new File("flairsignored.txt"); - if(file.exists()) - { - BufferedReader br=new BufferedReader(new FileReader("flairsignored.txt")); - String line; - while ((line = br.readLine()) != null) - { - String name=line.replace("\n", ""); - MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08. - } - br.close(); - } - file=new File("autoflairconfig.txt"); - if(file.exists()) - { - BufferedReader br=new BufferedReader(new FileReader(file)); - String line; - while((line=br.readLine())!=null) - { - String[] s=line.split(" "); - TownColors.put(s[0], s[1]); - } - br.close(); - } - } catch (IOException e) { - System.out.println("Error!\n"+e); - } - //System.out.println("Registering done."); - Runnable r=new Runnable(){public void run(){ThreadMethod();}}; - Thread t=new Thread(r); - t.start(); - } - Boolean stop=false; - // Fired when plugin is disabled - @Override - public void onDisable() - { - try - { - FileWriter fw; - fw = new FileWriter("flairsaccepted.txt"); - fw.close(); - fw = new FileWriter("flairsignored.txt"); - fw.close(); - } - catch(Exception e) - { - System.out.println("Error!\n"+e); - } - //for(String player : AcceptedPlayers) - for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. - { - if(!player.AcceptedFlair) - continue; //2015.08.08. - File file=new File("flairsaccepted.txt"); - try { - BufferedWriter bw=new BufferedWriter(new FileWriter(file, true)); - bw.write(player.PlayerName+"\n"); - bw.close(); - } catch (IOException e) { - System.out.println("Error!\n"+e); - } - } - for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. - { - if(!player.IgnoredFlair) - continue; //2015.08.08. - File file=new File("flairsignored.txt"); - try { - BufferedWriter bw = new BufferedWriter(new FileWriter(file, true)); - bw.write(player.PlayerName+"\n"); - bw.close(); - } catch (IOException e) { - System.out.println("Error!\n"+e); - } - } - stop=true; - } - - public void ThreadMethod() //<-- 2015.07.16. - { - /*System.out.println("Sleeping for 5 seconds..."); //2015.07.20. - try { - Thread.sleep(5000); - } catch (InterruptedException e1) { - e1.printStackTrace(); - } //2015.07.20.*/ - while(!stop) - { - try - { - String body=DownloadString("https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/autoflair_system_comment_your_minecraft_name_and/.json?limit=1000"); - JSONArray json=new JSONArray(body).getJSONObject(1).getJSONObject("data").getJSONArray("children"); - for(Object obj : json) - { - JSONObject item = (JSONObject)obj; - String author=item.getJSONObject("data").getString("author"); - String ign=item.getJSONObject("data").getString("body"); - int start = ign.indexOf("IGN:") + "IGN:".length(); - int end = ign.indexOf(' ', start); - if (end == -1 || end == start) - end=ign.indexOf('\n', start); //2015.07.15. - if (end == -1 || end == start) - ign = ign.substring(start); - else - ign = ign.substring(start, end); - ign = ign.trim(); - if(HasIGFlair(ign)) - continue; - //System.out.println("Author: "+author); - try { - Thread.sleep(10); - } catch(InterruptedException ex) { - Thread.currentThread().interrupt(); - } - String[] flairdata = DownloadString("http://karmadecay.com/thebutton-data.php?users=" + author).replace("\"", "").split(":"); - String flair; - if(flairdata.length > 1) //2015.07.15. - flair = flairdata[1]; - else - flair=""; - if (flair != "-1") - flair = flair + "s"; - else - flair = "non-presser"; - String flairclass; - //System.out.println("flairdata.length:"+flairdata.length); - if(flairdata.length>2) - flairclass = flairdata[2]; - else - flairclass="unknown"; - SetFlair(ign, flair, flairclass, author); - } - Thread.sleep(10000); - } - catch(Exception e) - { - System.out.println("Error!\n"+e); - } - } - } - - public String DownloadString(String urlstr) throws MalformedURLException, IOException - { - URL url = new URL(urlstr); - URLConnection con = url.openConnection(); - con.setRequestProperty("User-Agent", "TheButtonAutoFlair"); - InputStream in = con.getInputStream(); - String encoding = con.getContentEncoding(); - encoding = encoding == null ? "UTF-8" : encoding; - String body = IOUtils.toString(in, encoding); - in.close(); - return body; - } - - //It has to store offline player flairs too, therefore it can't use Player object - /*public static Map PlayerFlairs=new HashMap(); - public static Map PlayerUserNames=new HashMap(); - //public Map PlayerFlairs=new HashMap(); - public static ArrayList Players=new ArrayList(); - public static ArrayList AcceptedPlayers=new ArrayList(); //2015.07.16. - public static ArrayList IgnoredPlayers=new ArrayList(); //2015.07.16. - //public static Map PlayerTowns=new HashMap(); //2015.07.20.*/ - public static Map TownColors=new HashMap(); //2015.07.20. - public Boolean HasIGFlair(String playername) - { - /*Player player=null; - for(Player p : Players) - { - if(p.getName()==playername) - { - player=p; - break; - } - } - if(player==null) - return false;*/ - //return PlayerFlairs.containsKey(playername); - //return MaybeOfflinePlayer.AllPlayers.containsKey(playername); - MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. - return p.Flair!=null; //2015.08.08. - } - - public void SetFlair(String playername, String text, String flairclass, String username) - { - String finalflair; - switch(flairclass) - { - case "press-1": - finalflair="§c("+text+")§r"; - break; - case "press-2": - finalflair="§6("+text+")§r"; - break; - case "press-3": - finalflair="§e("+text+")§r"; - break; - case "press-4": - finalflair="§a("+text+")§r"; - break; - case "press-5": - finalflair="§9("+text+")§r"; - break; - case "press-6": - finalflair="§5("+text+")§r"; - break; - case "no-press": - finalflair="§7(non-pr.)§r"; - break; - case "cheater": - finalflair="§5("+text+")§r"; - break; - case "cant-press": //2015.08.08. - finalflair="§r(can't press)§r"; - break; - default: - finalflair=""; - break; - } - if(finalflair.length()==0) //<-- 2015.07.20. - return; - //PlayerFlairs.put(playername, finalflair); - //PlayerUserNames.put(playername, username); - MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. - p.Flair=finalflair; //2015.08.08. - p.UserName=username; //2015.08.08. - /*for(Player player : Players) - { - if(player.getName()==playername) - { - PlayerFlairs.put(player, finalflair); - break; - } - }*/ - //System.out.println("SetFlair - playername: "+playername+" text: "+text+" flairclass: "+flairclass); - System.out.println("Added new flair to "+playername+": "+finalflair); - //for(Player player : Players) - for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08. - { - //System.out.println("Online player: "+player.getName()); - //System.out.println("player.getName ("+player.getName()+") == playername ("+playername+"): "+(player.getName()==playername)); - if(player.getName().equals(playername)) - { - //System.out.println("DisplayName: "+player.getDisplayName()); - //player.setDisplayName(player.getDisplayName()+finalflair); - AppendPlayerDisplayFlair(player, username, finalflair); - //System.out.println("DisplayName: "+player.getDisplayName()); - break; - } - } - } - - public static String GetFlair(Player player) - { //2015.07.16. - //String flair=PlayerFlairs.get(player.getName()); - String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08. - return flair==null ? "" : flair; - } - - public static void AppendPlayerDisplayFlair(Player player, String username, String flair) - { - //if(IgnoredPlayers.contains(player.getName())) - if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).IgnoredFlair) - return; - //if(AcceptedPlayers.contains(player.getName())) - if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).AcceptedFlair) - //player.setDisplayName(player.getDisplayName()+flair); - AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. - else - player.sendMessage("§9Are you Reddit user "+username+"?§r §6Type /u accept or /u ignore§r"); - } - - public static void AppendPlayerDisplayFlairFinal(Player player, String flair) - { //2015.07.20. - //System.out.println("A"); - String color = GetColorForTown(GetPlayerTown(player)); //TO!DO: Multiple colors put on first capital letters - String[] colors = color.substring(1).split("§"); - //String displayname=player.getDisplayName(); - String displayname=player.getName(); //2015.08.08. - ArrayList Positions=new ArrayList<>(); - //System.out.println("B"); - for(int i=0; i=colors.length) - { - //System.out.println("D"); - int x=0; - for(int i=0; i towns = TownyUniverse.getDataSource().getTowns(); - try { - Town town = WorldCoord.parseWorldCoord(player).getTownBlock().getTown(); //TODO - return town.getName(); - } catch (Exception e) { - return ""; - } - } - - public static void RemovePlayerDisplayFlairFinal(Player player, String flair) - { //2015.07.20. - //String color = GetColorForTown(GetPlayerTown(player)); - //String dname=player.getDisplayName(); - //player.setDisplayName(dname.substring(dname.indexOf(color)+3, dname.indexOf(flair))); - //MaybeOfflinePlayer.AllPlayers.get(player.getName()).DisplayName=null; //2015.08.08. - MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair=null; //2015.08.08. - } - - public static Collection GetPlayers() - { - return Instance.getServer().getOnlinePlayers(); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/31/808be1e8e03e001517108d149b613203 b/.metadata/.plugins/org.eclipse.core.resources/.history/31/808be1e8e03e001517108d149b613203 new file mode 100644 index 0000000..42ec92d --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/31/808be1e8e03e001517108d149b613203 @@ -0,0 +1,265 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +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; + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. + //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) + if(p.Flair==null) + { + player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); + return true; + } + switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. + { + case "accept": + { + if(p.IgnoredFlair) + p.IgnoredFlair=false; //2015.08.08. + if(!p.AcceptedFlair) + { + String flair=p.Flair; //2015.08.08. + //PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + PluginMain.AppendPlayerDisplayFlair(p, player); + p.AcceptedFlair=true; //2015.08.08. + player.sendMessage("§6Your flair has been set:§r "+flair); + } + else + player.sendMessage("§cYou already have this user's flair.§r"); + break; + } + case "ignore": + { + if(p.AcceptedFlair) + p.AcceptedFlair=false; //2015.08.08. + if(!p.IgnoredFlair) + { + p.IgnoredFlair=true; + String flair=p.Flair; //2015.08.08. + PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. + player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); + } + else + player.sendMessage("§cYou already ignored this request.§r"); + break; + } + /*case "reload": //2015.07.20. + DoReload(player); + break;*/ + case "admin": //2015.08.09. + DoAdmin(player, args); + break; + case "nonpresser": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§7(non-pr.)§r"; + break; + case "cantpress": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§r(can't press)§r"; + break; + default: + return false; + } + return true; + } + /*if(args[0].toLowerCase()=="reload") + DoReload(null); //2015.07.20.*/ + else if(args.length>0 && args[0].toLowerCase().equals("admin")) //2015.08.09. + { + DoAdmin(null, args); //2015.08.09. + return true; //2015.08.09. + } + return false; + } + private static void DoReload(Player player) + { //2015.07.20. + //if(player==null || player.isOp() || player.getName()=="NorbiPeti") + //{ + try + { + File file=new File("autoflairconfig.txt"); + if(file.exists()) + { + PluginMain.LoadFiles(true); //2015.08.09. + for(Player p : PluginMain.GetPlayers()) + { + MaybeOfflinePlayer mp = MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName()); + if(mp.Flair!=null) + { + String flair=mp.Flair; + PluginMain.RemovePlayerDisplayFlairFinal(p, flair); + //PluginMain.AppendPlayerDisplayFlairFinal(p, flair); + PluginMain.AppendPlayerDisplayFlair(mp, p); //2015.08.09. + } + String msg="§6Note: The auto-flair plugin has been reloaded. You might need to wait 10s to have your flair.§r"; //2015.08.09. + p.sendMessage(msg); //2015.08.09. + } + //String msg="§6Reloaded config file.§r"; + //SendMessage(player, msg); //2015.08.09. + } + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + if(player!=null) + player.sendMessage("§cAn error occured. See console for details.§r"); + PluginMain.LastException=e; //2015.08.09. + } + //} + //else + //player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static Player ReloadPlayer; //2015.08.09. + private static void DoAdmin(Player player, String[] args) + { //2015.08.09. + if(player==null || player.isOp() || player.getName()=="NorbiPeti") + { + //System.out.println("Args length: " + args.length); + if(args.length==1) + { + String message="§cUsage: /u admin reload|playerinfo§r"; + SendMessage(player, message); + return; + } + //args[0] is "admin" + switch(args[1].toLowerCase()) + { + case "reload": + ReloadPlayer=player; //2015.08.09. + SendMessage(player, "§6Make sure to save the current settings before you modify and reload them! Type /u admin confirm when done.§r"); + break; + case "playerinfo": + DoPlayerInfo(player, args); + break; + case "getlasterror": + DoGetLastError(player, args); + case "confirm": + if(ReloadPlayer==player) + DoReload(player); //2015.08.09. + else + SendMessage(player, "§cYou need to do /u admin reload first.§r"); + break; + case "save": + PluginMain.SaveFiles(); //2015.08.09. + SendMessage(player, "§6Saved files. Now you can edit them and reload if you want.§r"); + break; + case "setflair": + + break; + default: + String message="§cUsage: /u admin reload|playerinfo|getlasterror|save§r"; + SendMessage(player, message); + return; + } + } + else + player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static void DoPlayerInfo(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "playerinfo" + if(args.length==2) + { + String message="§cUsage: /u admin playerinfo §r"; + SendMessage(player, message); + return; + } + if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2])) + { + String message="§cPlayer not found: "+args[2]+"§r"; + SendMessage(player, message); + return; + } + MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]); + SendMessage(player, "Player name: "+p.PlayerName); + SendMessage(player, "User flair: "+p.Flair); + SendMessage(player, "Username: "+p.UserName); + SendMessage(player, "Flair accepted: "+p.AcceptedFlair); + SendMessage(player, "Flair ignored: "+p.IgnoredFlair); + } + private static void SendMessage(Player player, String message) + { //2015.08.09. + if(player==null) + System.out.println(message); + else + player.sendMessage(message); + } + private static void DoGetLastError(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "getlasterror" + if(PluginMain.LastException!=null) + { + SendMessage(player, "Last error:"); + SendMessage(player, PluginMain.LastException.toString()); + PluginMain.LastException=null; + } + else + SendMessage(player, "There were no exceptions."); + } + private static void SetPlayerFlair(Player player, MaybeOfflinePlayer targetplayer, String flair) + { //2015.08.09. + flair=flair.replace('&', '§'); + targetplayer.Flair=flair; + if(!PluginMain.RemoveLineFromFile("customflairs.txt", targetplayer.PlayerName)) + { + SendMessage(player, "§cError removing previous custom flair!§r"); + return; + } + File file=new File("customflairs.txt"); + try { + BufferedWriter bw; + bw = new BufferedWriter(new FileWriter(file, true)); + bw.write(targetplayer.getName()+"\n"); + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + PluginMain.LastException=e; //2015.08.09. + } + SendMessage(player, "§6The flair has been set. Player: "+targetplayer.PlayerName+" Flair: "+flair+"§r"); + } + private static void DoSetFlair(Player player, String args) + { + //args[0] is "admin" - args[1] is "setflair" + if(args.length()<4) + { + SendMessage(player, "§cUsage: /u admin setflair "); + return; + } + SetPlayerFlair(player, MaybeOfflinePlayer.AddPlayerIfNeeded(player.getName())) + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/31/c0e1dbcdcf3e001518fa86d7ae2a1cf8 b/.metadata/.plugins/org.eclipse.core.resources/.history/31/c0e1dbcdcf3e001518fa86d7ae2a1cf8 new file mode 100644 index 0000000..276d1df --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/31/c0e1dbcdcf3e001518fa86d7ae2a1cf8 @@ -0,0 +1,363 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStream; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLConnection; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + +import org.apache.commons.io.IOUtils; +import org.bukkit.entity.Player; +import org.bukkit.plugin.java.JavaPlugin; +import org.json.JSONArray; +import org.json.JSONObject; + +import com.palmergames.bukkit.towny.object.Town; +import com.palmergames.bukkit.towny.object.WorldCoord; + +public class PluginMain extends JavaPlugin +{ //Translated to Java: 2015.07.15. + //A user, which flair isn't obtainable: + //https://www.reddit.com/r/thebutton/comments/31c32v/i_pressed_the_button_without_really_thinking/ + private static PluginMain Instance; + // Fired when plugin is first enabled + @Override + public void onEnable() + { + System.out.println("The Button Auto-flair Plugin by NorbiPeti (:P)"); + getServer().getPluginManager().registerEvents(new PlayerListener(), this); + this.getCommand("u").setExecutor(new Commands()); + this.getCommand("u").setUsage(this.getCommand("u").getUsage().replace('&', '§')); + Instance=this; //2015.08.08. + try { + File file=new File("flairsaccepted.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + //System.out.println("Name: " + name); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("flairsignored.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsignored.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("autoflairconfig.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + TownColors.put(s[0], s[1]); + } + br.close(); + } + //throw new IOException("Test"); //2015.08.09. + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + Runnable r=new Runnable(){public void run(){ThreadMethod();}}; + Thread t=new Thread(r); + t.start(); + } + Boolean stop=false; + // Fired when plugin is disabled + @Override + public void onDisable() + { + try + { + FileWriter fw; + fw = new FileWriter("flairsaccepted.txt"); + fw.close(); + fw = new FileWriter("flairsignored.txt"); + fw.close(); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + try { + File file=new File("flairsaccepted.txt"); + BufferedWriter bw=new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.AcceptedFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + file=new File("flairsignored.txt"); + bw = new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.IgnoredFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + stop=true; + } + + public void ThreadMethod() //<-- 2015.07.16. + { + while(!stop) + { + try + { + String body=DownloadString("https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/autoflair_system_comment_your_minecraft_name_and/.json?limit=1000"); + JSONArray json=new JSONArray(body).getJSONObject(1).getJSONObject("data").getJSONArray("children"); + for(Object obj : json) + { + JSONObject item = (JSONObject)obj; + String author=item.getJSONObject("data").getString("author"); + String ign=item.getJSONObject("data").getString("body"); + int start = ign.indexOf("IGN:") + "IGN:".length(); + int end = ign.indexOf(' ', start); + if (end == -1 || end == start) + end=ign.indexOf('\n', start); //2015.07.15. + if (end == -1 || end == start) + ign = ign.substring(start); + else + ign = ign.substring(start, end); + ign = ign.trim(); + if(HasIGFlair(ign)) + continue; + try { + Thread.sleep(10); + } catch(InterruptedException ex) { + Thread.currentThread().interrupt(); + } + String[] flairdata = DownloadString("http://karmadecay.com/thebutton-data.php?users=" + author).replace("\"", "").split(":"); + String flair; + if(flairdata.length > 1) //2015.07.15. + flair = flairdata[1]; + else + flair=""; + if (flair != "-1") + flair = flair + "s"; + else + flair = "non-presser"; + String flairclass; + if(flairdata.length>2) + flairclass = flairdata[2]; + else + flairclass="unknown"; + SetFlair(ign, flair, flairclass, author); + } + Thread.sleep(10000); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + } + + public static Exception LastException; //2015.08.09. + + public String DownloadString(String urlstr) throws MalformedURLException, IOException + { + URL url = new URL(urlstr); + URLConnection con = url.openConnection(); + con.setRequestProperty("User-Agent", "TheButtonAutoFlair"); + InputStream in = con.getInputStream(); + String encoding = con.getContentEncoding(); + encoding = encoding == null ? "UTF-8" : encoding; + String body = IOUtils.toString(in, encoding); + in.close(); + return body; + } + + public static Map TownColors=new HashMap(); //2015.07.20. + public Boolean HasIGFlair(String playername) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + return p.Flair!=null; //2015.08.08. + } + + public void SetFlair(String playername, String text, String flairclass, String username) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + String finalflair; + p.FlairDecided=true; + switch(flairclass) + { + case "press-1": + finalflair="§c("+text+")§r"; + break; + case "press-2": + finalflair="§6("+text+")§r"; + break; + case "press-3": + finalflair="§e("+text+")§r"; + break; + case "press-4": + finalflair="§a("+text+")§r"; + break; + case "press-5": + finalflair="§9("+text+")§r"; + break; + 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; + case "undecided": //2015.08.09. + p.FlairDecided=false; + finalflair=""; + break; + default: + finalflair=""; + break; + } + if(finalflair.length()==0) //<-- 2015.07.20. + return; + p.Flair=finalflair; //2015.08.08. + p.UserName=username; //2015.08.08. + System.out.println("Added new flair to "+playername+": "+finalflair); + for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08. + { + if(player.getName().equals(playername)) + { + //AppendPlayerDisplayFlair(player, username, finalflair); + AppendPlayerDisplayFlair(player, p); + break; + } + } + } + + public static String GetFlair(Player player) + { //2015.07.16. + String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08. + return flair==null ? "" : flair; + } + + //public static void AppendPlayerDisplayFlair(Player player, String username, String flair) + public static void AppendPlayerDisplayFlair(MaybeOfflinePlayer player, Player p) //<-- 2015.08.09. + { + + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).IgnoredFlair) + return; + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).AcceptedFlair) + { + AppendPlayerDisplayFlairFinal(p, player.Flair); //2015.07.20. + if(!player.FlairDecided) + p.sendMessage("§9Your flair type is unknown. Are you a non-presser or a can't press? (/u nonpresser or /u cantpress)§r"); //2015.08.09. + } + else + player.sendMessage("§9Are you Reddit user "+player.UserName+"?§r §6Type /u accept or /u ignore§r"); + } + + private static void AppendPlayerDisplayFlairFinal(Player player, String flair) + { //2015.07.20. + String color = GetColorForTown(GetPlayerTown(player)); //TO!DO: Multiple colors put on first capital letters + String[] colors = color.substring(1).split("§"); + String displayname=player.getName(); //2015.08.08. + ArrayList Positions=new ArrayList<>(); + for(int i=0; i=colors.length) + { + int x=0; + for(int i=0; i GetPlayers() + { + return Instance.getServer().getOnlinePlayers(); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/33/608c284a083e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/33/608c284a083e00151c31fb33fff4337f deleted file mode 100644 index 1cd84d0..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/33/608c284a083e00151c31fb33fff4337f +++ /dev/null @@ -1,126 +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; - 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/60a1e0d1303e00151cbdba8b5f0a340e b/.metadata/.plugins/org.eclipse.core.resources/.history/33/60a1e0d1303e00151cbdba8b5f0a340e deleted file mode 100644 index f5d4fd5..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/33/60a1e0d1303e00151cbdba8b5f0a340e +++ /dev/null @@ -1,421 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import java.io.BufferedReader; -import java.io.BufferedWriter; -import java.io.File; -import java.io.FileReader; -import java.io.FileWriter; -import java.io.IOException; -import java.io.InputStream; -import java.net.MalformedURLException; -import java.net.URL; -import java.net.URLConnection; -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; -import java.util.Map; - -import org.apache.commons.io.IOUtils; -import org.bukkit.entity.Player; -import org.bukkit.plugin.java.JavaPlugin; -import org.json.JSONArray; -import org.json.JSONObject; - -import com.palmergames.bukkit.towny.object.Town; -import com.palmergames.bukkit.towny.object.TownyUniverse; -import com.palmergames.bukkit.towny.object.WorldCoord; - -public class PluginMain extends JavaPlugin -{ //Translated to Java: 2015.07.15. - //A user, which flair isn't obtainable: - //https://www.reddit.com/r/thebutton/comments/31c32v/i_pressed_the_button_without_really_thinking/ - private static PluginMain Instance; - // Fired when plugin is first enabled - @Override - public void onEnable() - { - System.out.println("The Button Auto-flair Plugin by NorbiPeti (:P)"); - getServer().getPluginManager().registerEvents(new PlayerListener(), this); - this.getCommand("u").setExecutor(new Commands()); - this.getCommand("u").setUsage(this.getCommand("u").getUsage().replace('&', '§')); - Instance=this; //2015.08.08. - try { - File file=new File("flairsaccepted.txt"); - if(file.exists()) - { - BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt")); - String line; - while ((line = br.readLine()) != null) - { - String name=line.replace("\n", ""); - System.out.println("Name: " + name); - MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08. - } - br.close(); - } - file=new File("flairsignored.txt"); - if(file.exists()) - { - BufferedReader br=new BufferedReader(new FileReader("flairsignored.txt")); - String line; - while ((line = br.readLine()) != null) - { - String name=line.replace("\n", ""); - MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08. - } - br.close(); - } - file=new File("autoflairconfig.txt"); - if(file.exists()) - { - BufferedReader br=new BufferedReader(new FileReader(file)); - String line; - while((line=br.readLine())!=null) - { - String[] s=line.split(" "); - TownColors.put(s[0], s[1]); - } - br.close(); - } - } catch (IOException e) { - System.out.println("Error!\n"+e); - } - Runnable r=new Runnable(){public void run(){ThreadMethod();}}; - Thread t=new Thread(r); - t.start(); - } - Boolean stop=false; - // Fired when plugin is disabled - @Override - public void onDisable() - { - try - { - FileWriter fw; - fw = new FileWriter("flairsaccepted.txt"); - fw.close(); - fw = new FileWriter("flairsignored.txt"); - fw.close(); - } - catch(Exception e) - { - System.out.println("Error!\n"+e); - } - //for(String player : AcceptedPlayers) - for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. - { - if(!player.AcceptedFlair) - continue; //2015.08.08. - File file=new File("flairsaccepted.txt"); - try { - BufferedWriter bw=new BufferedWriter(new FileWriter(file, true)); - bw.write(player.PlayerName+"\n"); - bw.close(); - } catch (IOException e) { - System.out.println("Error!\n"+e); - } - } - for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. - { - if(!player.IgnoredFlair) - continue; //2015.08.08. - File file=new File("flairsignored.txt"); - try { - BufferedWriter bw = new BufferedWriter(new FileWriter(file, true)); - bw.write(player.PlayerName+"\n"); - bw.close(); - } catch (IOException e) { - System.out.println("Error!\n"+e); - } - } - stop=true; - } - - public void ThreadMethod() //<-- 2015.07.16. - { - /*System.out.println("Sleeping for 5 seconds..."); //2015.07.20. - try { - Thread.sleep(5000); - } catch (InterruptedException e1) { - e1.printStackTrace(); - } //2015.07.20.*/ - while(!stop) - { - try - { - String body=DownloadString("https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/autoflair_system_comment_your_minecraft_name_and/.json?limit=1000"); - JSONArray json=new JSONArray(body).getJSONObject(1).getJSONObject("data").getJSONArray("children"); - for(Object obj : json) - { - JSONObject item = (JSONObject)obj; - String author=item.getJSONObject("data").getString("author"); - String ign=item.getJSONObject("data").getString("body"); - int start = ign.indexOf("IGN:") + "IGN:".length(); - int end = ign.indexOf(' ', start); - if (end == -1 || end == start) - end=ign.indexOf('\n', start); //2015.07.15. - if (end == -1 || end == start) - ign = ign.substring(start); - else - ign = ign.substring(start, end); - ign = ign.trim(); - if(HasIGFlair(ign)) - continue; - //System.out.println("Author: "+author); - try { - Thread.sleep(10); - } catch(InterruptedException ex) { - Thread.currentThread().interrupt(); - } - String[] flairdata = DownloadString("http://karmadecay.com/thebutton-data.php?users=" + author).replace("\"", "").split(":"); - String flair; - if(flairdata.length > 1) //2015.07.15. - flair = flairdata[1]; - else - flair=""; - if (flair != "-1") - flair = flair + "s"; - else - flair = "non-presser"; - String flairclass; - //System.out.println("flairdata.length:"+flairdata.length); - if(flairdata.length>2) - flairclass = flairdata[2]; - else - flairclass="unknown"; - SetFlair(ign, flair, flairclass, author); - } - Thread.sleep(10000); - } - catch(Exception e) - { - System.out.println("Error!\n"+e); - } - } - } - - public String DownloadString(String urlstr) throws MalformedURLException, IOException - { - URL url = new URL(urlstr); - URLConnection con = url.openConnection(); - con.setRequestProperty("User-Agent", "TheButtonAutoFlair"); - InputStream in = con.getInputStream(); - String encoding = con.getContentEncoding(); - encoding = encoding == null ? "UTF-8" : encoding; - String body = IOUtils.toString(in, encoding); - in.close(); - return body; - } - - //It has to store offline player flairs too, therefore it can't use Player object - /*public static Map PlayerFlairs=new HashMap(); - public static Map PlayerUserNames=new HashMap(); - //public Map PlayerFlairs=new HashMap(); - public static ArrayList Players=new ArrayList(); - public static ArrayList AcceptedPlayers=new ArrayList(); //2015.07.16. - public static ArrayList IgnoredPlayers=new ArrayList(); //2015.07.16. - //public static Map PlayerTowns=new HashMap(); //2015.07.20.*/ - public static Map TownColors=new HashMap(); //2015.07.20. - public Boolean HasIGFlair(String playername) - { - /*Player player=null; - for(Player p : Players) - { - if(p.getName()==playername) - { - player=p; - break; - } - } - if(player==null) - return false;*/ - //return PlayerFlairs.containsKey(playername); - //return MaybeOfflinePlayer.AllPlayers.containsKey(playername); - MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. - return p.Flair!=null; //2015.08.08. - } - - public void SetFlair(String playername, String text, String flairclass, String username) - { - String finalflair; - switch(flairclass) - { - case "press-1": - finalflair="§c("+text+")§r"; - break; - case "press-2": - finalflair="§6("+text+")§r"; - break; - case "press-3": - finalflair="§e("+text+")§r"; - break; - case "press-4": - finalflair="§a("+text+")§r"; - break; - case "press-5": - finalflair="§9("+text+")§r"; - break; - case "press-6": - finalflair="§5("+text+")§r"; - break; - case "no-press": - finalflair="§7(non-pr.)§r"; - break; - case "cheater": - finalflair="§5("+text+")§r"; - break; - case "cant-press": //2015.08.08. - finalflair="§r(can't press)§r"; - break; - default: - finalflair=""; - break; - } - if(finalflair.length()==0) //<-- 2015.07.20. - return; - //PlayerFlairs.put(playername, finalflair); - //PlayerUserNames.put(playername, username); - MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. - p.Flair=finalflair; //2015.08.08. - p.UserName=username; //2015.08.08. - /*for(Player player : Players) - { - if(player.getName()==playername) - { - PlayerFlairs.put(player, finalflair); - break; - } - }*/ - //System.out.println("SetFlair - playername: "+playername+" text: "+text+" flairclass: "+flairclass); - System.out.println("Added new flair to "+playername+": "+finalflair); - //for(Player player : Players) - for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08. - { - //System.out.println("Online player: "+player.getName()); - //System.out.println("player.getName ("+player.getName()+") == playername ("+playername+"): "+(player.getName()==playername)); - if(player.getName().equals(playername)) - { - //System.out.println("DisplayName: "+player.getDisplayName()); - //player.setDisplayName(player.getDisplayName()+finalflair); - AppendPlayerDisplayFlair(player, username, finalflair); - //System.out.println("DisplayName: "+player.getDisplayName()); - break; - } - } - } - - public static String GetFlair(Player player) - { //2015.07.16. - //String flair=PlayerFlairs.get(player.getName()); - String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08. - return flair==null ? "" : flair; - } - - public static void AppendPlayerDisplayFlair(Player player, String username, String flair) - { - //if(IgnoredPlayers.contains(player.getName())) - if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).IgnoredFlair) - return; - //if(AcceptedPlayers.contains(player.getName())) - if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).AcceptedFlair) - //player.setDisplayName(player.getDisplayName()+flair); - AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. - else - player.sendMessage("§9Are you Reddit user "+username+"?§r §6Type /u accept or /u ignore§r"); - } - - public static void AppendPlayerDisplayFlairFinal(Player player, String flair) - { //2015.07.20. - //System.out.println("A"); - String color = GetColorForTown(GetPlayerTown(player)); //TO!DO: Multiple colors put on first capital letters - String[] colors = color.substring(1).split("§"); - //String displayname=player.getDisplayName(); - String displayname=player.getName(); //2015.08.08. - ArrayList Positions=new ArrayList<>(); - //System.out.println("B"); - for(int i=0; i=colors.length) - { - //System.out.println("D"); - int x=0; - for(int i=0; i towns = TownyUniverse.getDataSource().getTowns(); - try { - Town town = WorldCoord.parseWorldCoord(player).getTownBlock().getTown(); //TODO - return town.getName(); - } catch (Exception e) { - return ""; - } - } - - public static void RemovePlayerDisplayFlairFinal(Player player, String flair) - { //2015.07.20. - //String color = GetColorForTown(GetPlayerTown(player)); - //String dname=player.getDisplayName(); - //player.setDisplayName(dname.substring(dname.indexOf(color)+3, dname.indexOf(flair))); - //MaybeOfflinePlayer.AllPlayers.get(player.getName()).DisplayName=null; //2015.08.08. - MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair=null; //2015.08.08. - } - - public static Collection GetPlayers() - { - return Instance.getServer().getOnlinePlayers(); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/33/90a26f4bdd3e001517108d149b613203 b/.metadata/.plugins/org.eclipse.core.resources/.history/33/90a26f4bdd3e001517108d149b613203 new file mode 100644 index 0000000..45d12d5 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/33/90a26f4bdd3e001517108d149b613203 @@ -0,0 +1,398 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStream; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLConnection; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + +import org.apache.commons.io.IOUtils; +import org.bukkit.entity.Player; +import org.bukkit.plugin.java.JavaPlugin; +import org.json.JSONArray; +import org.json.JSONObject; + +import com.palmergames.bukkit.towny.object.Town; +import com.palmergames.bukkit.towny.object.WorldCoord; + +public class PluginMain extends JavaPlugin +{ //Translated to Java: 2015.07.15. + //A user, which flair isn't obtainable: + //https://www.reddit.com/r/thebutton/comments/31c32v/i_pressed_the_button_without_really_thinking/ + private static PluginMain Instance; + // Fired when plugin is first enabled + @Override + public void onEnable() + { + System.out.println("The Button Auto-flair Plugin by NorbiPeti (:P)"); + getServer().getPluginManager().registerEvents(new PlayerListener(), this); + this.getCommand("u").setExecutor(new Commands()); + this.getCommand("u").setUsage(this.getCommand("u").getUsage().replace('&', '§')); + Instance=this; //2015.08.08. + LoadFiles(false); //2015.08.09. + Runnable r=new Runnable(){public void run(){ThreadMethod();}}; + Thread t=new Thread(r); + t.start(); + } + Boolean stop=false; + // Fired when plugin is disabled + @Override + public void onDisable() + { + SaveFiles(); //2015.08.09. + stop=true; + } + + public void ThreadMethod() //<-- 2015.07.16. + { + while(!stop) + { + try + { + String body=DownloadString("https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/autoflair_system_comment_your_minecraft_name_and/.json?limit=1000"); + JSONArray json=new JSONArray(body).getJSONObject(1).getJSONObject("data").getJSONArray("children"); + for(Object obj : json) + { + JSONObject item = (JSONObject)obj; + String author=item.getJSONObject("data").getString("author"); + String ign=item.getJSONObject("data").getString("body"); + int start = ign.indexOf("IGN:") + "IGN:".length(); + if(start==-1) + continue; //2015.08.09. + int end = ign.indexOf(' ', start); + if (end == -1 || end == start) + end=ign.indexOf('\n', start); //2015.07.15. + if (end == -1 || end == start) + ign = ign.substring(start); + else + ign = ign.substring(start, end); + ign = ign.trim(); + if(HasIGFlair(ign)) + continue; + try { + Thread.sleep(10); + } catch(InterruptedException ex) { + Thread.currentThread().interrupt(); + } + String[] flairdata = DownloadString("http://karmadecay.com/thebutton-data.php?users=" + author).replace("\"", "").split(":"); + String flair; + if(flairdata.length > 1) //2015.07.15. + flair = flairdata[1]; + else + flair=""; + if (flair != "-1") + flair = flair + "s"; + else + flair = "non-presser"; + String flairclass; + if(flairdata.length>2) + flairclass = flairdata[2]; + else + flairclass="unknown"; + SetFlair(ign, flair, flairclass, author); + } + Thread.sleep(10000); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + } + + public static Exception LastException; //2015.08.09. + + public String DownloadString(String urlstr) throws MalformedURLException, IOException + { + URL url = new URL(urlstr); + URLConnection con = url.openConnection(); + con.setRequestProperty("User-Agent", "TheButtonAutoFlair"); + InputStream in = con.getInputStream(); + String encoding = con.getContentEncoding(); + encoding = encoding == null ? "UTF-8" : encoding; + String body = IOUtils.toString(in, encoding); + in.close(); + return body; + } + + public static Map TownColors=new HashMap(); //2015.07.20. + public Boolean HasIGFlair(String playername) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + return p.Flair!=null; //2015.08.08. + } + + public void SetFlair(String playername, String text, String flairclass, String username) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + String finalflair; + p.FlairDecided=true; + switch(flairclass) + { + case "press-1": + finalflair="§c("+text+")§r"; + break; + case "press-2": + finalflair="§6("+text+")§r"; + break; + case "press-3": + finalflair="§e("+text+")§r"; + break; + case "press-4": + finalflair="§a("+text+")§r"; + break; + case "press-5": + finalflair="§9("+text+")§r"; + break; + 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; + case "undecided": //2015.08.09. + p.FlairDecided=false; + finalflair=""; + break; + default: + finalflair=""; + break; + } + if(finalflair.length()==0) //<-- 2015.07.20. + return; + p.Flair=finalflair; //2015.08.08. + p.UserName=username; //2015.08.08. + System.out.println("Added new flair to "+playername+": "+finalflair); + for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08. + { + if(player.getName().equals(playername)) + { + //AppendPlayerDisplayFlair(player, username, finalflair); + AppendPlayerDisplayFlair(p, player); + break; + } + } + } + + public static String GetFlair(Player player) + { //2015.07.16. + String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08. + return flair==null ? "" : flair; + } + + //public static void AppendPlayerDisplayFlair(Player player, String username, String flair) + public static void AppendPlayerDisplayFlair(MaybeOfflinePlayer player, Player p) //<-- 2015.08.09. + { + + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).IgnoredFlair) + return; + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).AcceptedFlair) + { + AppendPlayerDisplayFlairFinal(p, player.Flair); //2015.07.20. + if(!player.FlairDecided) + p.sendMessage("§9Your flair type is unknown. Are you a non-presser or a can't press? (/u nonpresser or /u cantpress)§r"); //2015.08.09. + } + else + p.sendMessage("§9Are you Reddit user "+player.UserName+"?§r §6Type /u accept or /u ignore§r"); + } + + private static void AppendPlayerDisplayFlairFinal(Player player, String flair) + { //2015.07.20. + String color = GetColorForTown(GetPlayerTown(player)); //TO!DO: Multiple colors put on first capital letters + String[] colors = color.substring(1).split("§"); + String displayname=player.getName(); //2015.08.08. + ArrayList Positions=new ArrayList<>(); + for(int i=0; i=colors.length) + { + int x=0; + for(int i=0; i GetPlayers() + { + return Instance.getServer().getOnlinePlayers(); + } + + public static void LoadFiles(boolean reload) //<-- 2015.08.09. + { + if(reload) + { //2015.08.09. + System.out.println("Auto-flair plugin cleanup for reloading..."); + MaybeOfflinePlayer.AllPlayers.clear(); + TownColors.clear(); + } + System.out.println("Loading files for auto-flair plugin..."); //2015.08.09. + try { + File file=new File("flairsaccepted.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + //System.out.println("Name: " + name); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("flairsignored.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsignored.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("autoflairconfig.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + TownColors.put(s[0], s[1]); + } + br.close(); + } + file=new File("autoflairdecisions.txt"); //2015.08.09. + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + MaybeOfflinePlayer.AddPlayerIfNeeded(s[0]).Flair=s[1]; //2015.08.09. + } + br.close(); + } + //throw new IOException("Test"); //2015.08.09. + System.out.println("Auto-flair plugin loaded files!"); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + public static void SaveFiles() //<-- 2015.08.09. + { + try + { + FileWriter fw; + fw = new FileWriter("flairsaccepted.txt"); + fw.close(); + fw = new FileWriter("flairsignored.txt"); + fw.close(); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + try { + File file=new File("flairsaccepted.txt"); + BufferedWriter bw=new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.AcceptedFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + file=new File("flairsignored.txt"); + bw = new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.IgnoredFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + public static void SetPlayerFlair(Player player, String flair) + { + + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/34/b097b71bce3e001518fa86d7ae2a1cf8 b/.metadata/.plugins/org.eclipse.core.resources/.history/34/b097b71bce3e001518fa86d7ae2a1cf8 new file mode 100644 index 0000000..1f5948c --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/34/b097b71bce3e001518fa86d7ae2a1cf8 @@ -0,0 +1,354 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStream; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLConnection; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + +import org.apache.commons.io.IOUtils; +import org.bukkit.entity.Player; +import org.bukkit.plugin.java.JavaPlugin; +import org.json.JSONArray; +import org.json.JSONObject; + +import com.palmergames.bukkit.towny.object.Town; +import com.palmergames.bukkit.towny.object.WorldCoord; + +public class PluginMain extends JavaPlugin +{ //Translated to Java: 2015.07.15. + //A user, which flair isn't obtainable: + //https://www.reddit.com/r/thebutton/comments/31c32v/i_pressed_the_button_without_really_thinking/ + private static PluginMain Instance; + // Fired when plugin is first enabled + @Override + public void onEnable() + { + System.out.println("The Button Auto-flair Plugin by NorbiPeti (:P)"); + getServer().getPluginManager().registerEvents(new PlayerListener(), this); + this.getCommand("u").setExecutor(new Commands()); + this.getCommand("u").setUsage(this.getCommand("u").getUsage().replace('&', '§')); + Instance=this; //2015.08.08. + try { + File file=new File("flairsaccepted.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + //System.out.println("Name: " + name); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("flairsignored.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsignored.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("autoflairconfig.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + TownColors.put(s[0], s[1]); + } + br.close(); + } + //throw new IOException("Test"); //2015.08.09. + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + Runnable r=new Runnable(){public void run(){ThreadMethod();}}; + Thread t=new Thread(r); + t.start(); + } + Boolean stop=false; + // Fired when plugin is disabled + @Override + public void onDisable() + { + try + { + FileWriter fw; + fw = new FileWriter("flairsaccepted.txt"); + fw.close(); + fw = new FileWriter("flairsignored.txt"); + fw.close(); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + try { + File file=new File("flairsaccepted.txt"); + BufferedWriter bw=new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.AcceptedFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + file=new File("flairsignored.txt"); + bw = new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.IgnoredFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + stop=true; + } + + public void ThreadMethod() //<-- 2015.07.16. + { + while(!stop) + { + try + { + String body=DownloadString("https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/autoflair_system_comment_your_minecraft_name_and/.json?limit=1000"); + JSONArray json=new JSONArray(body).getJSONObject(1).getJSONObject("data").getJSONArray("children"); + for(Object obj : json) + { + JSONObject item = (JSONObject)obj; + String author=item.getJSONObject("data").getString("author"); + String ign=item.getJSONObject("data").getString("body"); + int start = ign.indexOf("IGN:") + "IGN:".length(); + int end = ign.indexOf(' ', start); + if (end == -1 || end == start) + end=ign.indexOf('\n', start); //2015.07.15. + if (end == -1 || end == start) + ign = ign.substring(start); + else + ign = ign.substring(start, end); + ign = ign.trim(); + if(HasIGFlair(ign)) + continue; + try { + Thread.sleep(10); + } catch(InterruptedException ex) { + Thread.currentThread().interrupt(); + } + String[] flairdata = DownloadString("http://karmadecay.com/thebutton-data.php?users=" + author).replace("\"", "").split(":"); + String flair; + if(flairdata.length > 1) //2015.07.15. + flair = flairdata[1]; + else + flair=""; + if (flair != "-1") + flair = flair + "s"; + else + flair = "non-presser"; + String flairclass; + if(flairdata.length>2) + flairclass = flairdata[2]; + else + flairclass="unknown"; + SetFlair(ign, flair, flairclass, author); + } + Thread.sleep(10000); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + } + + public static Exception LastException; //2015.08.09. + + public String DownloadString(String urlstr) throws MalformedURLException, IOException + { + URL url = new URL(urlstr); + URLConnection con = url.openConnection(); + con.setRequestProperty("User-Agent", "TheButtonAutoFlair"); + InputStream in = con.getInputStream(); + String encoding = con.getContentEncoding(); + encoding = encoding == null ? "UTF-8" : encoding; + String body = IOUtils.toString(in, encoding); + in.close(); + return body; + } + + public static Map TownColors=new HashMap(); //2015.07.20. + public Boolean HasIGFlair(String playername) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + return p.Flair!=null; //2015.08.08. + } + + public void SetFlair(String playername, String text, String flairclass, String username) + { + String finalflair; + switch(flairclass) + { + case "press-1": + finalflair="§c("+text+")§r"; + break; + case "press-2": + finalflair="§6("+text+")§r"; + break; + case "press-3": + finalflair="§e("+text+")§r"; + break; + case "press-4": + finalflair="§a("+text+")§r"; + break; + case "press-5": + finalflair="§9("+text+")§r"; + break; + case "press-6": + finalflair="§5("+text+")§r"; + break; + case "no-press": + finalflair="§7(non-pr.)§r"; + break; + case "cheater": + finalflair="§5("+text+")§r"; + break; + case "cant-press": //2015.08.08. + finalflair="§r(can't press)§r"; + break; + case "undecided": //2015.08.09. + finalflair=""; + break; + default: + finalflair=""; + break; + } + if(finalflair.length()==0) //<-- 2015.07.20. + return; + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + p.Flair=finalflair; //2015.08.08. + p.UserName=username; //2015.08.08. + System.out.println("Added new flair to "+playername+": "+finalflair); + for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08. + { + if(player.getName().equals(playername)) + { + AppendPlayerDisplayFlair(player, username, finalflair); + break; + } + } + } + + public static String GetFlair(Player player) + { //2015.07.16. + String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08. + return flair==null ? "" : flair; + } + + public static void AppendPlayerDisplayFlair(Player player, String username, String flair) + { + if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).IgnoredFlair) + return; + if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).AcceptedFlair) + AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + else + player.sendMessage("§9Are you Reddit user "+username+"?§r §6Type /u accept or /u ignore§r"); + } + + public static void AppendPlayerDisplayFlairFinal(Player player, String flair) + { //2015.07.20. + String color = GetColorForTown(GetPlayerTown(player)); //TO!DO: Multiple colors put on first capital letters + String[] colors = color.substring(1).split("§"); + String displayname=player.getName(); //2015.08.08. + ArrayList Positions=new ArrayList<>(); + for(int i=0; i=colors.length) + { + int x=0; + for(int i=0; i GetPlayers() + { + return Instance.getServer().getOnlinePlayers(); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/36/407f1825013e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/36/407f1825013e00151c31fb33fff4337f deleted file mode 100644 index d5af4e4..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/36/407f1825013e00151c31fb33fff4337f +++ /dev/null @@ -1,124 +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": - { - 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/20e61fc4d13e001518fa86d7ae2a1cf8 b/.metadata/.plugins/org.eclipse.core.resources/.history/37/20e61fc4d13e001518fa86d7ae2a1cf8 new file mode 100644 index 0000000..39f0d07 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/37/20e61fc4d13e001518fa86d7ae2a1cf8 @@ -0,0 +1,370 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStream; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLConnection; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + +import org.apache.commons.io.IOUtils; +import org.bukkit.entity.Player; +import org.bukkit.plugin.java.JavaPlugin; +import org.json.JSONArray; +import org.json.JSONObject; + +import com.palmergames.bukkit.towny.object.Town; +import com.palmergames.bukkit.towny.object.WorldCoord; + +public class PluginMain extends JavaPlugin +{ //Translated to Java: 2015.07.15. + //A user, which flair isn't obtainable: + //https://www.reddit.com/r/thebutton/comments/31c32v/i_pressed_the_button_without_really_thinking/ + private static PluginMain Instance; + // Fired when plugin is first enabled + @Override + public void onEnable() + { + System.out.println("The Button Auto-flair Plugin by NorbiPeti (:P)"); + getServer().getPluginManager().registerEvents(new PlayerListener(), this); + this.getCommand("u").setExecutor(new Commands()); + this.getCommand("u").setUsage(this.getCommand("u").getUsage().replace('&', '§')); + Instance=this; //2015.08.08. + LoadFiles(false); //2015.08.09. + Runnable r=new Runnable(){public void run(){ThreadMethod();}}; + Thread t=new Thread(r); + t.start(); + } + Boolean stop=false; + // Fired when plugin is disabled + @Override + public void onDisable() + { + try + { + FileWriter fw; + fw = new FileWriter("flairsaccepted.txt"); + fw.close(); + fw = new FileWriter("flairsignored.txt"); + fw.close(); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + try { + File file=new File("flairsaccepted.txt"); + BufferedWriter bw=new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.AcceptedFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + file=new File("flairsignored.txt"); + bw = new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.IgnoredFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + stop=true; + } + + public void ThreadMethod() //<-- 2015.07.16. + { + while(!stop) + { + try + { + String body=DownloadString("https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/autoflair_system_comment_your_minecraft_name_and/.json?limit=1000"); + JSONArray json=new JSONArray(body).getJSONObject(1).getJSONObject("data").getJSONArray("children"); + for(Object obj : json) + { + JSONObject item = (JSONObject)obj; + String author=item.getJSONObject("data").getString("author"); + String ign=item.getJSONObject("data").getString("body"); + int start = ign.indexOf("IGN:") + "IGN:".length(); + int end = ign.indexOf(' ', start); + if (end == -1 || end == start) + end=ign.indexOf('\n', start); //2015.07.15. + if (end == -1 || end == start) + ign = ign.substring(start); + else + ign = ign.substring(start, end); + ign = ign.trim(); + if(HasIGFlair(ign)) + continue; + try { + Thread.sleep(10); + } catch(InterruptedException ex) { + Thread.currentThread().interrupt(); + } + String[] flairdata = DownloadString("http://karmadecay.com/thebutton-data.php?users=" + author).replace("\"", "").split(":"); + String flair; + if(flairdata.length > 1) //2015.07.15. + flair = flairdata[1]; + else + flair=""; + if (flair != "-1") + flair = flair + "s"; + else + flair = "non-presser"; + String flairclass; + if(flairdata.length>2) + flairclass = flairdata[2]; + else + flairclass="unknown"; + SetFlair(ign, flair, flairclass, author); + } + Thread.sleep(10000); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + } + + public static Exception LastException; //2015.08.09. + + public String DownloadString(String urlstr) throws MalformedURLException, IOException + { + URL url = new URL(urlstr); + URLConnection con = url.openConnection(); + con.setRequestProperty("User-Agent", "TheButtonAutoFlair"); + InputStream in = con.getInputStream(); + String encoding = con.getContentEncoding(); + encoding = encoding == null ? "UTF-8" : encoding; + String body = IOUtils.toString(in, encoding); + in.close(); + return body; + } + + public static Map TownColors=new HashMap(); //2015.07.20. + public Boolean HasIGFlair(String playername) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + return p.Flair!=null; //2015.08.08. + } + + public void SetFlair(String playername, String text, String flairclass, String username) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + String finalflair; + p.FlairDecided=true; + switch(flairclass) + { + case "press-1": + finalflair="§c("+text+")§r"; + break; + case "press-2": + finalflair="§6("+text+")§r"; + break; + case "press-3": + finalflair="§e("+text+")§r"; + break; + case "press-4": + finalflair="§a("+text+")§r"; + break; + case "press-5": + finalflair="§9("+text+")§r"; + break; + 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; + case "undecided": //2015.08.09. + p.FlairDecided=false; + finalflair=""; + break; + default: + finalflair=""; + break; + } + if(finalflair.length()==0) //<-- 2015.07.20. + return; + p.Flair=finalflair; //2015.08.08. + p.UserName=username; //2015.08.08. + System.out.println("Added new flair to "+playername+": "+finalflair); + for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08. + { + if(player.getName().equals(playername)) + { + //AppendPlayerDisplayFlair(player, username, finalflair); + AppendPlayerDisplayFlair(p, player); + break; + } + } + } + + public static String GetFlair(Player player) + { //2015.07.16. + String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08. + return flair==null ? "" : flair; + } + + //public static void AppendPlayerDisplayFlair(Player player, String username, String flair) + public static void AppendPlayerDisplayFlair(MaybeOfflinePlayer player, Player p) //<-- 2015.08.09. + { + + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).IgnoredFlair) + return; + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).AcceptedFlair) + { + AppendPlayerDisplayFlairFinal(p, player.Flair); //2015.07.20. + if(!player.FlairDecided) + p.sendMessage("§9Your flair type is unknown. Are you a non-presser or a can't press? (/u nonpresser or /u cantpress)§r"); //2015.08.09. + } + else + p.sendMessage("§9Are you Reddit user "+player.UserName+"?§r §6Type /u accept or /u ignore§r"); + } + + private static void AppendPlayerDisplayFlairFinal(Player player, String flair) + { //2015.07.20. + String color = GetColorForTown(GetPlayerTown(player)); //TO!DO: Multiple colors put on first capital letters + String[] colors = color.substring(1).split("§"); + String displayname=player.getName(); //2015.08.08. + ArrayList Positions=new ArrayList<>(); + for(int i=0; i=colors.length) + { + int x=0; + for(int i=0; i GetPlayers() + { + return Instance.getServer().getOnlinePlayers(); + } + + public static void LoadFiles(boolean reload) //<-- 2015.08.09. + { + if(reload) + MaybeOfflinePlayer.AllPlayers.clear(); //2015.08.09. + try { + File file=new File("flairsaccepted.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + //System.out.println("Name: " + name); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("flairsignored.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsignored.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("autoflairconfig.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + TownColors.put(s[0], s[1]); + } + br.close(); + } + //throw new IOException("Test"); //2015.08.09. + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/37/5064f5c0883e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/37/5064f5c0883e00151ce8ff6d4f74dabd deleted file mode 100644 index ac79356..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/37/5064f5c0883e00151ce8ff6d4f74dabd +++ /dev/null @@ -1,173 +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; - MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. - //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - if(p.Flair==null) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. - { - case "accept": - { - if(p.IgnoredFlair) - p.IgnoredFlair=false; //2015.08.08. - if(!p.AcceptedFlair) - { - String flair=p.Flair; //2015.08.08. - PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. - p.AcceptedFlair=true; //2015.08.08. - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("§cYou already have this user's flair.§r"); - break; - } - case "ignore": - { - if(p.AcceptedFlair) - p.AcceptedFlair=false; //2015.08.08. - if(!p.IgnoredFlair) - { - p.IgnoredFlair=true; - String flair=p.Flair; //2015.08.08. - PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. - player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); - } - else - player.sendMessage("§cYou already ignored this request.§r"); - break; - } - /*case "reload": //2015.07.20. - DoReload(player); - break;*/ - case "admin": //2015.08.09. - DoAdmin(player, args); - break; - default: - return false; - } - return true; - } - - /*if(args[0].toLowerCase()=="reload") - DoReload(null); //2015.07.20.*/ - else if(args[0].toLowerCase()=="admin") - DoAdmin(null, args); //2015.08.09. - return false; - } - private static void DoReload(Player player) - { //2015.07.20. - //if(player==null || player.isOp() || player.getName()=="NorbiPeti") - //{ - try - { - File file=new File("autoflairconfig.txt"); - if(file.exists()) - { - PluginMain.TownColors.clear(); - BufferedReader br=new BufferedReader(new FileReader(file)); - String line; - while((line=br.readLine())!=null) - { - String[] s=line.split(" "); - PluginMain.TownColors.put(s[0], s[1]); - } - br.close(); - for(Player p : PluginMain.GetPlayers()) - { - MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName()); - if(mp.Flair!=null) - { - String flair=mp.Flair; - PluginMain.RemovePlayerDisplayFlairFinal(p, flair); - PluginMain.AppendPlayerDisplayFlairFinal(p, flair); - } - } - String msg="§6Reloaded config file.§r"; - if(player!=null) - player.sendMessage(msg); - else - System.out.println(msg); - } - } - catch(Exception e) - { - System.out.println("Error!\n"+e); - if(player!=null) - player.sendMessage("§cAn error occured. See console for details.§r"); - } - //} - //else - //player.sendMessage("§cYou need to be OP to use this command.§r"); - } - private static void DoAdmin(Player player, String[] args) - { //2015.08.09. - if(player==null || player.isOp() || player.getName()=="NorbiPeti") - { - if(args.length==1) - { - String message="§cUsage: /u admin reload|playerinfo§r"; - if(player==null) - System.out.println(message); - else - player.sendMessage(message); - return; - } - //args[0] is "admin" - switch(args[1].toLowerCase()) - { - case "reload": - DoReload(player); - break; - case "playerinfo": - DoPlayerInfo(player, args); - break; - } - } - else - player.sendMessage("§cYou need to be OP to use this command.§r"); - } - private static void DoPlayerInfo(Player player, String[] args) - { //2015.08.09. - //args[0] is "admin" - args[1] is "playerinfo" - if(args.length==2) - { - String message="§cUsage: /u admin playerinfo §r"; - SendMessage(player, message); - } - if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2])) - { - String message="§cPlayer not found: "+args[2]+"§r"; - SendMessage(player, message); - } - MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]); - return; - } - private static void SendMessage(Player player, String message) - { - if(player==null) - System.out.println(message); - else - player.sendMessage(message); - return; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/14/d0544e5b893e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/38/a0f3a0e9cf3e001518fa86d7ae2a1cf8 similarity index 83% rename from .metadata/.plugins/org.eclipse.core.resources/.history/14/d0544e5b893e00151ce8ff6d4f74dabd rename to .metadata/.plugins/org.eclipse.core.resources/.history/38/a0f3a0e9cf3e001518fa86d7ae2a1cf8 index e8f0509..327e9f3 100644 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/14/d0544e5b893e00151ce8ff6d4f74dabd +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/38/a0f3a0e9cf3e001518fa86d7ae2a1cf8 @@ -33,7 +33,8 @@ public class Commands implements CommandExecutor { if(!p.AcceptedFlair) { String flair=p.Flair; //2015.08.08. - PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + //PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + PluginMain.AppendPlayerDisplayFlair(player, p); p.AcceptedFlair=true; //2015.08.08. player.sendMessage("§6Your flair has been set:§r "+flair); } @@ -62,16 +63,20 @@ public class Commands implements CommandExecutor { case "admin": //2015.08.09. DoAdmin(player, args); break; + case "nonpresser": //2015.08.09. + break; default: return false; } return true; } - /*if(args[0].toLowerCase()=="reload") DoReload(null); //2015.07.20.*/ - else if(args[0].toLowerCase()=="admin") + else if(args.length>0 && args[0].toLowerCase().equals("admin")) //2015.08.09. + { DoAdmin(null, args); //2015.08.09. + return true; //2015.08.09. + } return false; } private static void DoReload(Player player) @@ -111,6 +116,7 @@ public class Commands implements CommandExecutor { System.out.println("Error!\n"+e); if(player!=null) player.sendMessage("§cAn error occured. See console for details.§r"); + PluginMain.LastException=e; //2015.08.09. } //} //else @@ -120,6 +126,7 @@ public class Commands implements CommandExecutor { { //2015.08.09. if(player==null || player.isOp() || player.getName()=="NorbiPeti") { + //System.out.println("Args length: " + args.length); if(args.length==1) { String message="§cUsage: /u admin reload|playerinfo§r"; @@ -135,6 +142,12 @@ public class Commands implements CommandExecutor { case "playerinfo": DoPlayerInfo(player, args); break; + case "getlasterror": + DoGetLastError(player, args); + default: + String message="§cUsage: /u admin reload|playerinfo§r"; + SendMessage(player, message); + return; } } else @@ -147,11 +160,13 @@ public class Commands implements CommandExecutor { { String message="§cUsage: /u admin playerinfo §r"; SendMessage(player, message); + return; } if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2])) { String message="§cPlayer not found: "+args[2]+"§r"; SendMessage(player, message); + return; } MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]); SendMessage(player, "Player name: "+p.PlayerName); @@ -159,7 +174,6 @@ public class Commands implements CommandExecutor { SendMessage(player, "Username: "+p.UserName); SendMessage(player, "Flair accepted: "+p.AcceptedFlair); SendMessage(player, "Flair ignored: "+p.IgnoredFlair); - return; } private static void SendMessage(Player player, String message) { //2015.08.09. @@ -167,6 +181,17 @@ public class Commands implements CommandExecutor { System.out.println(message); else player.sendMessage(message); - return; + } + private static void DoGetLastError(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "getlasterror" + if(PluginMain.LastException!=null) + { + SendMessage(player, "Last error:"); + SendMessage(player, PluginMain.LastException.toString()); + PluginMain.LastException=null; + } + else + SendMessage(player, "There were no exceptions."); } } diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/38/e086e0cc843e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/38/e086e0cc843e00151ce8ff6d4f74dabd deleted file mode 100644 index a8e5994..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/38/e086e0cc843e00151ce8ff6d4f74dabd +++ /dev/null @@ -1,119 +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; - MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. - //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - if(p.Flair==null) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - { - if(p.IgnoredFlair) - p.IgnoredFlair=false; //2015.08.08. - if(!p.AcceptedFlair) - { - String flair=p.Flair; //2015.08.08. - PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. - p.AcceptedFlair=true; //2015.08.08. - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("§cYou already have this user's flair.§r"); - break; - } - case "ignore": - { - if(p.AcceptedFlair) - p.AcceptedFlair=false; //2015.08.08. - if(!p.IgnoredFlair) - { - p.IgnoredFlair=true; - String flair=p.Flair; //2015.08.08. - PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. - player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); - } - else - player.sendMessage("§cYou already ignored this request.§r"); - break; - } - case "reload": //2015.07.20. - DoReload(player); - break; - case "showerrors": //2015.08.09. - break; - default: - return false; - } - return true; - } - - if(args[0]=="reload") - DoReload(null); //2015.07.20. - return false; - } - private static void DoReload(Player player) - { //2015.07.20. - if(player==null || player.isOp() || player.getName()=="NorbiPeti") - { - try - { - File file=new File("autoflairconfig.txt"); - if(file.exists()) - { - PluginMain.TownColors.clear(); - BufferedReader br=new BufferedReader(new FileReader(file)); - String line; - while((line=br.readLine())!=null) - { - String[] s=line.split(" "); - PluginMain.TownColors.put(s[0], s[1]); - } - br.close(); - for(Player p : PluginMain.GetPlayers()) - { - MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName()); - if(mp.Flair!=null) - { - String flair=mp.Flair; - PluginMain.RemovePlayerDisplayFlairFinal(p, flair); - PluginMain.AppendPlayerDisplayFlairFinal(p, flair); - } - } - String msg="§6Reloaded config file.§r"; - if(player!=null) - player.sendMessage(msg); - else - System.out.println(msg); - } - } - catch(Exception e) - { - System.out.println("Error!\n"+e); - if(player!=null) - player.sendMessage("§cAn error occured. See console for details.§r"); - } - } - else - player.sendMessage("§cYou need to be OP to use this command.§r"); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/39/2006034ad03e001518fa86d7ae2a1cf8 b/.metadata/.plugins/org.eclipse.core.resources/.history/39/2006034ad03e001518fa86d7ae2a1cf8 new file mode 100644 index 0000000..c6af7c6 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/39/2006034ad03e001518fa86d7ae2a1cf8 @@ -0,0 +1,201 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; + +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class Commands implements CommandExecutor { + // This method is called, when somebody uses our command + @Override + public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { + if (sender instanceof Player) { + Player player = (Player) sender; + if(args.length<1) + return false; + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. + //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) + if(p.Flair==null) + { + player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); + return true; + } + switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. + { + case "accept": + { + if(p.IgnoredFlair) + p.IgnoredFlair=false; //2015.08.08. + if(!p.AcceptedFlair) + { + String flair=p.Flair; //2015.08.08. + //PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + PluginMain.AppendPlayerDisplayFlair(p, player); + p.AcceptedFlair=true; //2015.08.08. + player.sendMessage("§6Your flair has been set:§r "+flair); + } + else + player.sendMessage("§cYou already have this user's flair.§r"); + break; + } + case "ignore": + { + if(p.AcceptedFlair) + p.AcceptedFlair=false; //2015.08.08. + if(!p.IgnoredFlair) + { + p.IgnoredFlair=true; + String flair=p.Flair; //2015.08.08. + PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. + player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); + } + else + player.sendMessage("§cYou already ignored this request.§r"); + break; + } + /*case "reload": //2015.07.20. + DoReload(player); + break;*/ + case "admin": //2015.08.09. + DoAdmin(player, args); + break; + case "nonpresser": //2015.08.09. + + break; + case "cantpress": //2015.08.09. + break; + default: + return false; + } + return true; + } + /*if(args[0].toLowerCase()=="reload") + DoReload(null); //2015.07.20.*/ + else if(args.length>0 && args[0].toLowerCase().equals("admin")) //2015.08.09. + { + DoAdmin(null, args); //2015.08.09. + return true; //2015.08.09. + } + return false; + } + private static void DoReload(Player player) + { //2015.07.20. + //if(player==null || player.isOp() || player.getName()=="NorbiPeti") + //{ + try + { + File file=new File("autoflairconfig.txt"); + if(file.exists()) + { + PluginMain.TownColors.clear(); + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + PluginMain.TownColors.put(s[0], s[1]); + } + br.close(); + for(Player p : PluginMain.GetPlayers()) + { + MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName()); + if(mp.Flair!=null) + { + String flair=mp.Flair; + PluginMain.RemovePlayerDisplayFlairFinal(p, flair); + //PluginMain.AppendPlayerDisplayFlairFinal(p, flair); + PluginMain.AppendPlayerDisplayFlair(mp, p); //2015.08.09. + } + } + String msg="§6Reloaded config file.§r"; + SendMessage(player, msg); //2015.08.09. + } + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + if(player!=null) + player.sendMessage("§cAn error occured. See console for details.§r"); + PluginMain.LastException=e; //2015.08.09. + } + //} + //else + //player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static void DoAdmin(Player player, String[] args) + { //2015.08.09. + if(player==null || player.isOp() || player.getName()=="NorbiPeti") + { + //System.out.println("Args length: " + args.length); + if(args.length==1) + { + String message="§cUsage: /u admin reload|playerinfo§r"; + SendMessage(player, message); + return; + } + //args[0] is "admin" + switch(args[1].toLowerCase()) + { + case "reload": + DoReload(player); + break; + case "playerinfo": + DoPlayerInfo(player, args); + break; + case "getlasterror": + DoGetLastError(player, args); + default: + String message="§cUsage: /u admin reload|playerinfo§r"; + SendMessage(player, message); + return; + } + } + else + player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static void DoPlayerInfo(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "playerinfo" + if(args.length==2) + { + String message="§cUsage: /u admin playerinfo §r"; + SendMessage(player, message); + return; + } + if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2])) + { + String message="§cPlayer not found: "+args[2]+"§r"; + SendMessage(player, message); + return; + } + MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]); + SendMessage(player, "Player name: "+p.PlayerName); + SendMessage(player, "User flair: "+p.Flair); + SendMessage(player, "Username: "+p.UserName); + SendMessage(player, "Flair accepted: "+p.AcceptedFlair); + SendMessage(player, "Flair ignored: "+p.IgnoredFlair); + } + private static void SendMessage(Player player, String message) + { //2015.08.09. + if(player==null) + System.out.println(message); + else + player.sendMessage(message); + } + private static void DoGetLastError(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "getlasterror" + if(PluginMain.LastException!=null) + { + SendMessage(player, "Last error:"); + SendMessage(player, PluginMain.LastException.toString()); + PluginMain.LastException=null; + } + else + SendMessage(player, "There were no exceptions."); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/3a/705720220d3e00151089cca86c5b1a99 b/.metadata/.plugins/org.eclipse.core.resources/.history/3a/705720220d3e00151089cca86c5b1a99 deleted file mode 100644 index ad07236..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/3a/705720220d3e00151089cca86c5b1a99 +++ /dev/null @@ -1,433 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import java.io.BufferedReader; -import java.io.BufferedWriter; -import java.io.File; -import java.io.FileReader; -import java.io.FileWriter; -import java.io.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/909349e2df3e001517108d149b613203 b/.metadata/.plugins/org.eclipse.core.resources/.history/3a/909349e2df3e001517108d149b613203 new file mode 100644 index 0000000..403b6bc --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/3a/909349e2df3e001517108d149b613203 @@ -0,0 +1,255 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +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; + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. + //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) + if(p.Flair==null) + { + player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); + return true; + } + switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. + { + case "accept": + { + if(p.IgnoredFlair) + p.IgnoredFlair=false; //2015.08.08. + if(!p.AcceptedFlair) + { + String flair=p.Flair; //2015.08.08. + //PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + PluginMain.AppendPlayerDisplayFlair(p, player); + p.AcceptedFlair=true; //2015.08.08. + player.sendMessage("§6Your flair has been set:§r "+flair); + } + else + player.sendMessage("§cYou already have this user's flair.§r"); + break; + } + case "ignore": + { + if(p.AcceptedFlair) + p.AcceptedFlair=false; //2015.08.08. + if(!p.IgnoredFlair) + { + p.IgnoredFlair=true; + String flair=p.Flair; //2015.08.08. + PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. + player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); + } + else + player.sendMessage("§cYou already ignored this request.§r"); + break; + } + /*case "reload": //2015.07.20. + DoReload(player); + break;*/ + case "admin": //2015.08.09. + DoAdmin(player, args); + break; + case "nonpresser": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§7(non-pr.)§r"; + break; + case "cantpress": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§r(can't press)§r"; + break; + default: + return false; + } + return true; + } + /*if(args[0].toLowerCase()=="reload") + DoReload(null); //2015.07.20.*/ + else if(args.length>0 && args[0].toLowerCase().equals("admin")) //2015.08.09. + { + DoAdmin(null, args); //2015.08.09. + return true; //2015.08.09. + } + return false; + } + private static void DoReload(Player player) + { //2015.07.20. + //if(player==null || player.isOp() || player.getName()=="NorbiPeti") + //{ + try + { + File file=new File("autoflairconfig.txt"); + if(file.exists()) + { + PluginMain.LoadFiles(true); //2015.08.09. + for(Player p : PluginMain.GetPlayers()) + { + MaybeOfflinePlayer mp = MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName()); + if(mp.Flair!=null) + { + String flair=mp.Flair; + PluginMain.RemovePlayerDisplayFlairFinal(p, flair); + //PluginMain.AppendPlayerDisplayFlairFinal(p, flair); + PluginMain.AppendPlayerDisplayFlair(mp, p); //2015.08.09. + } + String msg="§6Note: The auto-flair plugin has been reloaded. You might need to wait 10s to have your flair.§r"; //2015.08.09. + p.sendMessage(msg); //2015.08.09. + } + //String msg="§6Reloaded config file.§r"; + //SendMessage(player, msg); //2015.08.09. + } + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + if(player!=null) + player.sendMessage("§cAn error occured. See console for details.§r"); + PluginMain.LastException=e; //2015.08.09. + } + //} + //else + //player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static Player ReloadPlayer; //2015.08.09. + private static void DoAdmin(Player player, String[] args) + { //2015.08.09. + if(player==null || player.isOp() || player.getName()=="NorbiPeti") + { + //System.out.println("Args length: " + args.length); + if(args.length==1) + { + String message="§cUsage: /u admin reload|playerinfo§r"; + SendMessage(player, message); + return; + } + //args[0] is "admin" + switch(args[1].toLowerCase()) + { + case "reload": + ReloadPlayer=player; //2015.08.09. + SendMessage(player, "§6Make sure to save the current settings before you modify and reload them! Type /u admin confirm when done.§r"); + break; + case "playerinfo": + DoPlayerInfo(player, args); + break; + case "getlasterror": + DoGetLastError(player, args); + case "confirm": + if(ReloadPlayer==player) + DoReload(player); //2015.08.09. + else + SendMessage(player, "§cYou need to do /u admin reload first.§r"); + break; + case "save": + PluginMain.SaveFiles(); //2015.08.09. + SendMessage(player, "§6Saved files. Now you can edit them and reload if you want.§r"); + break; + case "setflair": + + break; + default: + String message="§cUsage: /u admin reload|playerinfo|getlasterror|save§r"; + SendMessage(player, message); + return; + } + } + else + player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static void DoPlayerInfo(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "playerinfo" + if(args.length==2) + { + String message="§cUsage: /u admin playerinfo §r"; + SendMessage(player, message); + return; + } + if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2])) + { + String message="§cPlayer not found: "+args[2]+"§r"; + SendMessage(player, message); + return; + } + MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]); + SendMessage(player, "Player name: "+p.PlayerName); + SendMessage(player, "User flair: "+p.Flair); + SendMessage(player, "Username: "+p.UserName); + SendMessage(player, "Flair accepted: "+p.AcceptedFlair); + SendMessage(player, "Flair ignored: "+p.IgnoredFlair); + } + private static void SendMessage(Player player, String message) + { //2015.08.09. + if(player==null) + System.out.println(message); + else + player.sendMessage(message); + } + private static void DoGetLastError(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "getlasterror" + if(PluginMain.LastException!=null) + { + SendMessage(player, "Last error:"); + SendMessage(player, PluginMain.LastException.toString()); + PluginMain.LastException=null; + } + else + SendMessage(player, "There were no exceptions."); + } + private static void DoSetrFlair(Player player, Player targetplayer, String flair) + { //2015.08.09. + flair=flair.replace('&', '§'); + MaybeOfflinePlayer.AddPlayerIfNeeded(player.getName()).Flair=flair; + if(!PluginMain.RemoveLineFromFile("customflairs.txt", targetplayer.getName())) + { + SendMessage(player, "§cError removing previous custom flair!§r"); + return; + } + File file=new File("customflairs.txt"); + try { + BufferedWriter bw; + bw = new BufferedWriter(new FileWriter(file, true)); + bw.write(targetplayer.getName()+"\n"); + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + PluginMain.LastException=e; //2015.08.09. + } + SendMessage(player, "§6The flair has been set. Player: "+targetplayer.getName()+" Flair: "+flair+"§r"); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/3a/d0b0a0be863e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/3a/d0b0a0be863e00151ce8ff6d4f74dabd deleted file mode 100644 index cacc30e..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/3a/d0b0a0be863e00151ce8ff6d4f74dabd +++ /dev/null @@ -1,132 +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; - MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. - //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - if(p.Flair==null) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. - { - case "accept": - { - if(p.IgnoredFlair) - p.IgnoredFlair=false; //2015.08.08. - if(!p.AcceptedFlair) - { - String flair=p.Flair; //2015.08.08. - PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. - p.AcceptedFlair=true; //2015.08.08. - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("§cYou already have this user's flair.§r"); - break; - } - case "ignore": - { - if(p.AcceptedFlair) - p.AcceptedFlair=false; //2015.08.08. - if(!p.IgnoredFlair) - { - p.IgnoredFlair=true; - String flair=p.Flair; //2015.08.08. - PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. - player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); - } - else - player.sendMessage("§cYou already ignored this request.§r"); - break; - } - case "reload": //2015.07.20. - DoReload(player); - break; - case "admin": //2015.08.09. - DoAdmin(player, args); - break; - default: - return false; - } - return true; - } - - if(args[0].toLowerCase()=="reload") - DoReload(null); //2015.07.20. - else if(args[0].toLowerCase()=="admin") - DoAdmin(null, args); //2015.08.09. - return false; - } - private static void DoReload(Player player) - { //2015.07.20. - if(player==null || player.isOp() || player.getName()=="NorbiPeti") - { - try - { - File file=new File("autoflairconfig.txt"); - if(file.exists()) - { - PluginMain.TownColors.clear(); - BufferedReader br=new BufferedReader(new FileReader(file)); - String line; - while((line=br.readLine())!=null) - { - String[] s=line.split(" "); - PluginMain.TownColors.put(s[0], s[1]); - } - br.close(); - for(Player p : PluginMain.GetPlayers()) - { - MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName()); - if(mp.Flair!=null) - { - String flair=mp.Flair; - PluginMain.RemovePlayerDisplayFlairFinal(p, flair); - PluginMain.AppendPlayerDisplayFlairFinal(p, flair); - } - } - String msg="§6Reloaded config file.§r"; - if(player!=null) - player.sendMessage(msg); - else - System.out.println(msg); - } - } - catch(Exception e) - { - System.out.println("Error!\n"+e); - if(player!=null) - player.sendMessage("§cAn error occured. See console for details.§r"); - } - } - else - player.sendMessage("§cYou need to be OP to use this command.§r"); - } - private static void DoAdmin(Player player, String[] args) - { - if(player==null || player.isOp() || player.getName()=="NorbiPeti") - { - //args[0] is "admin" - - } - else - player.sendMessage("§cYou need to be OP to use this command.§r"); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/3b/30bdb825cd3e001518fa86d7ae2a1cf8 b/.metadata/.plugins/org.eclipse.core.resources/.history/3b/30bdb825cd3e001518fa86d7ae2a1cf8 new file mode 100644 index 0000000..a9fdf9d --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/3b/30bdb825cd3e001518fa86d7ae2a1cf8 @@ -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 + 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/3b/a0a30729d93e001517108d149b613203 b/.metadata/.plugins/org.eclipse.core.resources/.history/3b/a0a30729d93e001517108d149b613203 new file mode 100644 index 0000000..46801eb --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/3b/a0a30729d93e001517108d149b613203 @@ -0,0 +1,227 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; + +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class Commands implements CommandExecutor { + // This method is called, when somebody uses our command + @Override + public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { + if (sender instanceof Player) { + Player player = (Player) sender; + if(args.length<1) + return false; + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. + //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) + if(p.Flair==null) + { + player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); + return true; + } + switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. + { + case "accept": + { + if(p.IgnoredFlair) + p.IgnoredFlair=false; //2015.08.08. + if(!p.AcceptedFlair) + { + String flair=p.Flair; //2015.08.08. + //PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + PluginMain.AppendPlayerDisplayFlair(p, player); + p.AcceptedFlair=true; //2015.08.08. + player.sendMessage("§6Your flair has been set:§r "+flair); + } + else + player.sendMessage("§cYou already have this user's flair.§r"); + break; + } + case "ignore": + { + if(p.AcceptedFlair) + p.AcceptedFlair=false; //2015.08.08. + if(!p.IgnoredFlair) + { + p.IgnoredFlair=true; + String flair=p.Flair; //2015.08.08. + PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. + player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); + } + else + player.sendMessage("§cYou already ignored this request.§r"); + break; + } + /*case "reload": //2015.07.20. + DoReload(player); + break;*/ + case "admin": //2015.08.09. + DoAdmin(player, args); + break; + case "nonpresser": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§7(non-pr.)§r"; + break; + case "cantpress": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§r(can't press)§r"; + break; + default: + return false; + } + return true; + } + /*if(args[0].toLowerCase()=="reload") + DoReload(null); //2015.07.20.*/ + else if(args.length>0 && args[0].toLowerCase().equals("admin")) //2015.08.09. + { + DoAdmin(null, args); //2015.08.09. + return true; //2015.08.09. + } + return false; + } + private static void DoReload(Player player) + { //2015.07.20. + //if(player==null || player.isOp() || player.getName()=="NorbiPeti") + //{ + try + { + File file=new File("autoflairconfig.txt"); + if(file.exists()) + { + PluginMain.LoadFiles(true); //2015.08.09. + for(Player p : PluginMain.GetPlayers()) + { + MaybeOfflinePlayer mp = MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName()); + if(mp.Flair!=null) + { + String flair=mp.Flair; + PluginMain.RemovePlayerDisplayFlairFinal(p, flair); + //PluginMain.AppendPlayerDisplayFlairFinal(p, flair); + PluginMain.AppendPlayerDisplayFlair(mp, p); //2015.08.09. + } + String msg="§6Note: The auto-flair plugin has been reloaded. You might need to wait 10s to have your flair.§r"; //2015.08.09. + p.sendMessage(msg); //2015.08.09. + } + //String msg="§6Reloaded config file.§r"; + //SendMessage(player, msg); //2015.08.09. + } + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + if(player!=null) + player.sendMessage("§cAn error occured. See console for details.§r"); + PluginMain.LastException=e; //2015.08.09. + } + //} + //else + //player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static Player ReloadPlayer; //2015.08.09. + private static void DoAdmin(Player player, String[] args) + { //2015.08.09. + if(player==null || player.isOp() || player.getName()=="NorbiPeti") + { + //System.out.println("Args length: " + args.length); + if(args.length==1) + { + String message="§cUsage: /u admin reload|playerinfo§r"; + SendMessage(player, message); + return; + } + //args[0] is "admin" + switch(args[1].toLowerCase()) + { + case "reload": + ReloadPlayer=player; //2015.08.09. + SendMessage(player, "§6Make sure to save the current settings before you modify and reload them! Type /u admin confirm when done.§r"); + break; + case "playerinfo": + DoPlayerInfo(player, args); + break; + case "getlasterror": + DoGetLastError(player, args); + case "confirm": + if(ReloadPlayer!=null && ReloadPlayer.equals(player)) + DoReload(player); //2015.08.09. + else + SendMessage(player, "§cYou need to do /u admin reload first.§r"); + break; + case "save": + PluginMain.SaveFiles(); //2015.08.09. + break; + default: + String message="§cUsage: /u admin reload|playerinfo|getlasterror§r"; + SendMessage(player, message); + return; + } + } + else + player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static void DoPlayerInfo(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "playerinfo" + if(args.length==2) + { + String message="§cUsage: /u admin playerinfo §r"; + SendMessage(player, message); + return; + } + if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2])) + { + String message="§cPlayer not found: "+args[2]+"§r"; + SendMessage(player, message); + return; + } + MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]); + SendMessage(player, "Player name: "+p.PlayerName); + SendMessage(player, "User flair: "+p.Flair); + SendMessage(player, "Username: "+p.UserName); + SendMessage(player, "Flair accepted: "+p.AcceptedFlair); + SendMessage(player, "Flair ignored: "+p.IgnoredFlair); + } + private static void SendMessage(Player player, String message) + { //2015.08.09. + if(player==null) + System.out.println(message); + else + player.sendMessage(message); + } + private static void DoGetLastError(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "getlasterror" + if(PluginMain.LastException!=null) + { + SendMessage(player, "Last error:"); + SendMessage(player, PluginMain.LastException.toString()); + PluginMain.LastException=null; + } + else + SendMessage(player, "There were no exceptions."); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/3c/205637bed23e001518fa86d7ae2a1cf8 b/.metadata/.plugins/org.eclipse.core.resources/.history/3c/205637bed23e001518fa86d7ae2a1cf8 new file mode 100644 index 0000000..19e20e0 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/3c/205637bed23e001518fa86d7ae2a1cf8 @@ -0,0 +1,215 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; + +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class Commands implements CommandExecutor { + // This method is called, when somebody uses our command + @Override + public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { + if (sender instanceof Player) { + Player player = (Player) sender; + if(args.length<1) + return false; + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. + //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) + if(p.Flair==null) + { + player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); + return true; + } + switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. + { + case "accept": + { + if(p.IgnoredFlair) + p.IgnoredFlair=false; //2015.08.08. + if(!p.AcceptedFlair) + { + String flair=p.Flair; //2015.08.08. + //PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + PluginMain.AppendPlayerDisplayFlair(p, player); + p.AcceptedFlair=true; //2015.08.08. + player.sendMessage("§6Your flair has been set:§r "+flair); + } + else + player.sendMessage("§cYou already have this user's flair.§r"); + break; + } + case "ignore": + { + if(p.AcceptedFlair) + p.AcceptedFlair=false; //2015.08.08. + if(!p.IgnoredFlair) + { + p.IgnoredFlair=true; + String flair=p.Flair; //2015.08.08. + PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. + player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); + } + else + player.sendMessage("§cYou already ignored this request.§r"); + break; + } + /*case "reload": //2015.07.20. + DoReload(player); + break;*/ + case "admin": //2015.08.09. + DoAdmin(player, args); + break; + case "nonpresser": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§7(non-pr.)§r"; + break; + case "cantpress": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§r(can't press)§r"; + break; + default: + return false; + } + return true; + } + /*if(args[0].toLowerCase()=="reload") + DoReload(null); //2015.07.20.*/ + else if(args.length>0 && args[0].toLowerCase().equals("admin")) //2015.08.09. + { + DoAdmin(null, args); //2015.08.09. + return true; //2015.08.09. + } + return false; + } + private static void DoReload(Player player) + { //2015.07.20. + //if(player==null || player.isOp() || player.getName()=="NorbiPeti") + //{ + try + { + File file=new File("autoflairconfig.txt"); + if(file.exists()) + { + PluginMain.LoadFiles(true) + 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); + PluginMain.AppendPlayerDisplayFlair(mp, p); //2015.08.09. + } + } + //String msg="§6Reloaded config file.§r"; + String msg="§6Reloaded all files.§r"; + SendMessage(player, msg); //2015.08.09. + } + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + if(player!=null) + player.sendMessage("§cAn error occured. See console for details.§r"); + PluginMain.LastException=e; //2015.08.09. + } + //} + //else + //player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static void DoAdmin(Player player, String[] args) + { //2015.08.09. + if(player==null || player.isOp() || player.getName()=="NorbiPeti") + { + //System.out.println("Args length: " + args.length); + if(args.length==1) + { + String message="§cUsage: /u admin reload|playerinfo§r"; + SendMessage(player, message); + return; + } + //args[0] is "admin" + switch(args[1].toLowerCase()) + { + case "reload": + DoReload(player); + break; + case "playerinfo": + DoPlayerInfo(player, args); + break; + case "getlasterror": + DoGetLastError(player, args); + default: + String message="§cUsage: /u admin reload|playerinfo§r"; + SendMessage(player, message); + return; + } + } + else + player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static void DoPlayerInfo(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "playerinfo" + if(args.length==2) + { + String message="§cUsage: /u admin playerinfo §r"; + SendMessage(player, message); + return; + } + if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2])) + { + String message="§cPlayer not found: "+args[2]+"§r"; + SendMessage(player, message); + return; + } + MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]); + SendMessage(player, "Player name: "+p.PlayerName); + SendMessage(player, "User flair: "+p.Flair); + SendMessage(player, "Username: "+p.UserName); + SendMessage(player, "Flair accepted: "+p.AcceptedFlair); + SendMessage(player, "Flair ignored: "+p.IgnoredFlair); + } + private static void SendMessage(Player player, String message) + { //2015.08.09. + if(player==null) + System.out.println(message); + else + player.sendMessage(message); + } + private static void DoGetLastError(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "getlasterror" + if(PluginMain.LastException!=null) + { + SendMessage(player, "Last error:"); + SendMessage(player, PluginMain.LastException.toString()); + PluginMain.LastException=null; + } + else + SendMessage(player, "There were no exceptions."); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/3c/60d8cd51873e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/3c/60d8cd51873e00151ce8ff6d4f74dabd deleted file mode 100644 index 01037e0..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/3c/60d8cd51873e00151ce8ff6d4f74dabd +++ /dev/null @@ -1,139 +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; - MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. - //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - if(p.Flair==null) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. - { - case "accept": - { - if(p.IgnoredFlair) - p.IgnoredFlair=false; //2015.08.08. - if(!p.AcceptedFlair) - { - String flair=p.Flair; //2015.08.08. - PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. - p.AcceptedFlair=true; //2015.08.08. - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("§cYou already have this user's flair.§r"); - break; - } - case "ignore": - { - if(p.AcceptedFlair) - p.AcceptedFlair=false; //2015.08.08. - if(!p.IgnoredFlair) - { - p.IgnoredFlair=true; - String flair=p.Flair; //2015.08.08. - PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. - player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); - } - else - player.sendMessage("§cYou already ignored this request.§r"); - break; - } - /*case "reload": //2015.07.20. - DoReload(player); - break;*/ - case "admin": //2015.08.09. - DoAdmin(player, args); - break; - default: - return false; - } - return true; - } - - /*if(args[0].toLowerCase()=="reload") - DoReload(null); //2015.07.20.*/ - else if(args[0].toLowerCase()=="admin") - DoAdmin(null, args); //2015.08.09. - return false; - } - private static void DoReload(Player player) - { //2015.07.20. - //if(player==null || player.isOp() || player.getName()=="NorbiPeti") - //{ - try - { - File file=new File("autoflairconfig.txt"); - if(file.exists()) - { - PluginMain.TownColors.clear(); - BufferedReader br=new BufferedReader(new FileReader(file)); - String line; - while((line=br.readLine())!=null) - { - String[] s=line.split(" "); - PluginMain.TownColors.put(s[0], s[1]); - } - br.close(); - for(Player p : PluginMain.GetPlayers()) - { - MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName()); - if(mp.Flair!=null) - { - String flair=mp.Flair; - PluginMain.RemovePlayerDisplayFlairFinal(p, flair); - PluginMain.AppendPlayerDisplayFlairFinal(p, flair); - } - } - String msg="§6Reloaded config file.§r"; - if(player!=null) - player.sendMessage(msg); - else - System.out.println(msg); - } - } - catch(Exception e) - { - System.out.println("Error!\n"+e); - if(player!=null) - player.sendMessage("§cAn error occured. See console for details.§r"); - } - //} - //else - //player.sendMessage("§cYou need to be OP to use this command.§r"); - } - private static void DoAdmin(Player player, String[] args) - { - if(player==null || player.isOp() || player.getName()=="NorbiPeti") - { - //args[0] is "admin" - switch(args[1].toLowerCase()) - { - case "reload": - DoReload(player); - break; - case "playerinfo": - break; - } - } - else - player.sendMessage("§cYou need to be OP to use this command.§r"); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/3d/007663b2df3e001517108d149b613203 b/.metadata/.plugins/org.eclipse.core.resources/.history/3d/007663b2df3e001517108d149b613203 new file mode 100644 index 0000000..f08a770 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/3d/007663b2df3e001517108d149b613203 @@ -0,0 +1,421 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStream; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLConnection; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + +import org.apache.commons.io.IOUtils; +import org.bukkit.entity.Player; +import org.bukkit.plugin.java.JavaPlugin; +import org.json.JSONArray; +import org.json.JSONObject; + +import com.palmergames.bukkit.towny.object.Town; +import com.palmergames.bukkit.towny.object.WorldCoord; + +public class PluginMain extends JavaPlugin +{ //Translated to Java: 2015.07.15. + //A user, which flair isn't obtainable: + //https://www.reddit.com/r/thebutton/comments/31c32v/i_pressed_the_button_without_really_thinking/ + private static PluginMain Instance; + // Fired when plugin is first enabled + @Override + public void onEnable() + { + System.out.println("The Button Auto-flair Plugin by NorbiPeti (:P)"); + getServer().getPluginManager().registerEvents(new PlayerListener(), this); + this.getCommand("u").setExecutor(new Commands()); + this.getCommand("u").setUsage(this.getCommand("u").getUsage().replace('&', '§')); + Instance=this; //2015.08.08. + LoadFiles(false); //2015.08.09. + Runnable r=new Runnable(){public void run(){ThreadMethod();}}; + Thread t=new Thread(r); + t.start(); + } + Boolean stop=false; + // Fired when plugin is disabled + @Override + public void onDisable() + { + SaveFiles(); //2015.08.09. + stop=true; + } + + public void ThreadMethod() //<-- 2015.07.16. + { + while(!stop) + { + try + { + String body=DownloadString("https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/autoflair_system_comment_your_minecraft_name_and/.json?limit=1000"); + JSONArray json=new JSONArray(body).getJSONObject(1).getJSONObject("data").getJSONArray("children"); + for(Object obj : json) + { + JSONObject item = (JSONObject)obj; + String author=item.getJSONObject("data").getString("author"); + String ign=item.getJSONObject("data").getString("body"); + int start = ign.indexOf("IGN:") + "IGN:".length(); + if(start==-1) + continue; //2015.08.09. + int end = ign.indexOf(' ', start); + if (end == -1 || end == start) + end=ign.indexOf('\n', start); //2015.07.15. + if (end == -1 || end == start) + ign = ign.substring(start); + else + ign = ign.substring(start, end); + ign = ign.trim(); + if(HasIGFlair(ign)) + continue; + try { + Thread.sleep(10); + } catch(InterruptedException ex) { + Thread.currentThread().interrupt(); + } + String[] flairdata = DownloadString("http://karmadecay.com/thebutton-data.php?users=" + author).replace("\"", "").split(":"); + String flair; + if(flairdata.length > 1) //2015.07.15. + flair = flairdata[1]; + else + flair=""; + if (flair != "-1") + flair = flair + "s"; + else + flair = "non-presser"; + String flairclass; + if(flairdata.length>2) + flairclass = flairdata[2]; + else + flairclass="unknown"; + SetFlair(ign, flair, flairclass, author); + } + Thread.sleep(10000); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + } + + public static Exception LastException; //2015.08.09. + + public String DownloadString(String urlstr) throws MalformedURLException, IOException + { + URL url = new URL(urlstr); + URLConnection con = url.openConnection(); + con.setRequestProperty("User-Agent", "TheButtonAutoFlair"); + InputStream in = con.getInputStream(); + String encoding = con.getContentEncoding(); + encoding = encoding == null ? "UTF-8" : encoding; + String body = IOUtils.toString(in, encoding); + in.close(); + return body; + } + + public static Map TownColors=new HashMap(); //2015.07.20. + public Boolean HasIGFlair(String playername) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + return p.Flair!=null; //2015.08.08. + } + + public void SetFlair(String playername, String text, String flairclass, String username) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + String finalflair; + p.FlairDecided=true; + switch(flairclass) + { + case "press-1": + finalflair="§c("+text+")§r"; + break; + case "press-2": + finalflair="§6("+text+")§r"; + break; + case "press-3": + finalflair="§e("+text+")§r"; + break; + case "press-4": + finalflair="§a("+text+")§r"; + break; + case "press-5": + finalflair="§9("+text+")§r"; + break; + 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; + case "undecided": //2015.08.09. + p.FlairDecided=false; + finalflair=""; + break; + default: + finalflair=""; + break; + } + if(finalflair.length()==0) //<-- 2015.07.20. + return; + p.Flair=finalflair; //2015.08.08. + p.UserName=username; //2015.08.08. + System.out.println("Added new flair to "+playername+": "+finalflair); + for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08. + { + if(player.getName().equals(playername)) + { + //AppendPlayerDisplayFlair(player, username, finalflair); + AppendPlayerDisplayFlair(p, player); + break; + } + } + } + + public static String GetFlair(Player player) + { //2015.07.16. + String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08. + return flair==null ? "" : flair; + } + + //public static void AppendPlayerDisplayFlair(Player player, String username, String flair) + public static void AppendPlayerDisplayFlair(MaybeOfflinePlayer player, Player p) //<-- 2015.08.09. + { + + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).IgnoredFlair) + return; + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).AcceptedFlair) + { + AppendPlayerDisplayFlairFinal(p, player.Flair); //2015.07.20. + if(!player.FlairDecided) + p.sendMessage("§9Your flair type is unknown. Are you a non-presser or a can't press? (/u nonpresser or /u cantpress)§r"); //2015.08.09. + } + else + p.sendMessage("§9Are you Reddit user "+player.UserName+"?§r §6Type /u accept or /u ignore§r"); + } + + private static void AppendPlayerDisplayFlairFinal(Player player, String flair) + { //2015.07.20. + String color = GetColorForTown(GetPlayerTown(player)); //TO!DO: Multiple colors put on first capital letters + String[] colors = color.substring(1).split("§"); + String displayname=player.getName(); //2015.08.08. + ArrayList Positions=new ArrayList<>(); + for(int i=0; i=colors.length) + { + int x=0; + for(int i=0; i GetPlayers() + { + return Instance.getServer().getOnlinePlayers(); + } + + public static void LoadFiles(boolean reload) //<-- 2015.08.09. + { + if(reload) + { //2015.08.09. + System.out.println("Auto-flair plugin cleanup for reloading..."); + MaybeOfflinePlayer.AllPlayers.clear(); + TownColors.clear(); + } + System.out.println("Loading files for auto-flair plugin..."); //2015.08.09. + try { + File file=new File("flairsaccepted.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + //System.out.println("Name: " + name); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("flairsignored.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsignored.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("autoflairconfig.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + TownColors.put(s[0], s[1]); + } + br.close(); + } + file=new File("customflairs.txt"); //2015.08.09. + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + MaybeOfflinePlayer.AddPlayerIfNeeded(s[0]).Flair=s[1]; //2015.08.09. + } + br.close(); + } + //throw new IOException("Test"); //2015.08.09. + System.out.println("Auto-flair plugin loaded files!"); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + public static void SaveFiles() //<-- 2015.08.09. + { + try + { + FileWriter fw; + fw = new FileWriter("flairsaccepted.txt"); + fw.close(); + fw = new FileWriter("flairsignored.txt"); + fw.close(); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + try { + File file=new File("flairsaccepted.txt"); + BufferedWriter bw=new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.AcceptedFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + file=new File("flairsignored.txt"); + bw = new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.IgnoredFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + public static boolean RemoveLineFromFile(String file, String line) + { //2015.08.09. + File inputFile = new File(file); + File tempFile = new File("_temp.txt"); + + try { + BufferedReader reader = new BufferedReader(new FileReader(inputFile)); + BufferedWriter writer = new BufferedWriter(new FileWriter(tempFile)); + + String lineToRemove = line; + String currentLine; + + while((currentLine = reader.readLine()) != null) { + // trim newline when comparing with lineToRemove + String trimmedLine = currentLine.trim(); + if(trimmedLine.equals(lineToRemove)) continue; + writer.write(currentLine + System.getProperty("line.separator")); + } + writer.close(); + reader.close(); + return tempFile.renameTo(inputFile); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + return false; + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/3d/00f95890de3e001517108d149b613203 b/.metadata/.plugins/org.eclipse.core.resources/.history/3d/00f95890de3e001517108d149b613203 new file mode 100644 index 0000000..60a390b --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/3d/00f95890de3e001517108d149b613203 @@ -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.WorldCoord; + +public class PluginMain extends JavaPlugin +{ //Translated to Java: 2015.07.15. + //A user, which flair isn't obtainable: + //https://www.reddit.com/r/thebutton/comments/31c32v/i_pressed_the_button_without_really_thinking/ + private static PluginMain Instance; + // Fired when plugin is first enabled + @Override + public void onEnable() + { + System.out.println("The Button Auto-flair Plugin by NorbiPeti (:P)"); + getServer().getPluginManager().registerEvents(new PlayerListener(), this); + this.getCommand("u").setExecutor(new Commands()); + this.getCommand("u").setUsage(this.getCommand("u").getUsage().replace('&', '§')); + Instance=this; //2015.08.08. + LoadFiles(false); //2015.08.09. + Runnable r=new Runnable(){public void run(){ThreadMethod();}}; + Thread t=new Thread(r); + t.start(); + } + Boolean stop=false; + // Fired when plugin is disabled + @Override + public void onDisable() + { + SaveFiles(); //2015.08.09. + stop=true; + } + + public void ThreadMethod() //<-- 2015.07.16. + { + while(!stop) + { + try + { + String body=DownloadString("https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/autoflair_system_comment_your_minecraft_name_and/.json?limit=1000"); + JSONArray json=new JSONArray(body).getJSONObject(1).getJSONObject("data").getJSONArray("children"); + for(Object obj : json) + { + JSONObject item = (JSONObject)obj; + String author=item.getJSONObject("data").getString("author"); + String ign=item.getJSONObject("data").getString("body"); + int start = ign.indexOf("IGN:") + "IGN:".length(); + if(start==-1) + continue; //2015.08.09. + int end = ign.indexOf(' ', start); + if (end == -1 || end == start) + end=ign.indexOf('\n', start); //2015.07.15. + if (end == -1 || end == start) + ign = ign.substring(start); + else + ign = ign.substring(start, end); + ign = ign.trim(); + if(HasIGFlair(ign)) + continue; + try { + Thread.sleep(10); + } catch(InterruptedException ex) { + Thread.currentThread().interrupt(); + } + String[] flairdata = DownloadString("http://karmadecay.com/thebutton-data.php?users=" + author).replace("\"", "").split(":"); + String flair; + if(flairdata.length > 1) //2015.07.15. + flair = flairdata[1]; + else + flair=""; + if (flair != "-1") + flair = flair + "s"; + else + flair = "non-presser"; + String flairclass; + if(flairdata.length>2) + flairclass = flairdata[2]; + else + flairclass="unknown"; + SetFlair(ign, flair, flairclass, author); + } + Thread.sleep(10000); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + } + + public static Exception LastException; //2015.08.09. + + public String DownloadString(String urlstr) throws MalformedURLException, IOException + { + URL url = new URL(urlstr); + URLConnection con = url.openConnection(); + con.setRequestProperty("User-Agent", "TheButtonAutoFlair"); + InputStream in = con.getInputStream(); + String encoding = con.getContentEncoding(); + encoding = encoding == null ? "UTF-8" : encoding; + String body = IOUtils.toString(in, encoding); + in.close(); + return body; + } + + public static Map TownColors=new HashMap(); //2015.07.20. + public Boolean HasIGFlair(String playername) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + return p.Flair!=null; //2015.08.08. + } + + public void SetFlair(String playername, String text, String flairclass, String username) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + String finalflair; + p.FlairDecided=true; + switch(flairclass) + { + case "press-1": + finalflair="§c("+text+")§r"; + break; + case "press-2": + finalflair="§6("+text+")§r"; + break; + case "press-3": + finalflair="§e("+text+")§r"; + break; + case "press-4": + finalflair="§a("+text+")§r"; + break; + case "press-5": + finalflair="§9("+text+")§r"; + break; + 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; + case "undecided": //2015.08.09. + p.FlairDecided=false; + finalflair=""; + break; + default: + finalflair=""; + break; + } + if(finalflair.length()==0) //<-- 2015.07.20. + return; + p.Flair=finalflair; //2015.08.08. + p.UserName=username; //2015.08.08. + System.out.println("Added new flair to "+playername+": "+finalflair); + for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08. + { + if(player.getName().equals(playername)) + { + //AppendPlayerDisplayFlair(player, username, finalflair); + AppendPlayerDisplayFlair(p, player); + break; + } + } + } + + public static String GetFlair(Player player) + { //2015.07.16. + String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08. + return flair==null ? "" : flair; + } + + //public static void AppendPlayerDisplayFlair(Player player, String username, String flair) + public static void AppendPlayerDisplayFlair(MaybeOfflinePlayer player, Player p) //<-- 2015.08.09. + { + + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).IgnoredFlair) + return; + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).AcceptedFlair) + { + AppendPlayerDisplayFlairFinal(p, player.Flair); //2015.07.20. + if(!player.FlairDecided) + p.sendMessage("§9Your flair type is unknown. Are you a non-presser or a can't press? (/u nonpresser or /u cantpress)§r"); //2015.08.09. + } + else + p.sendMessage("§9Are you Reddit user "+player.UserName+"?§r §6Type /u accept or /u ignore§r"); + } + + private static void AppendPlayerDisplayFlairFinal(Player player, String flair) + { //2015.07.20. + String color = GetColorForTown(GetPlayerTown(player)); //TO!DO: Multiple colors put on first capital letters + String[] colors = color.substring(1).split("§"); + String displayname=player.getName(); //2015.08.08. + ArrayList Positions=new ArrayList<>(); + for(int i=0; i=colors.length) + { + int x=0; + for(int i=0; i GetPlayers() + { + return Instance.getServer().getOnlinePlayers(); + } + + public static void LoadFiles(boolean reload) //<-- 2015.08.09. + { + if(reload) + { //2015.08.09. + System.out.println("Auto-flair plugin cleanup for reloading..."); + MaybeOfflinePlayer.AllPlayers.clear(); + TownColors.clear(); + } + System.out.println("Loading files for auto-flair plugin..."); //2015.08.09. + try { + File file=new File("flairsaccepted.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + //System.out.println("Name: " + name); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("flairsignored.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsignored.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("autoflairconfig.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + TownColors.put(s[0], s[1]); + } + br.close(); + } + file=new File("customflairs.txt"); //2015.08.09. + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + MaybeOfflinePlayer.AddPlayerIfNeeded(s[0]).Flair=s[1]; //2015.08.09. + } + br.close(); + } + //throw new IOException("Test"); //2015.08.09. + System.out.println("Auto-flair plugin loaded files!"); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + public static void SaveFiles() //<-- 2015.08.09. + { + try + { + FileWriter fw; + fw = new FileWriter("flairsaccepted.txt"); + fw.close(); + fw = new FileWriter("flairsignored.txt"); + fw.close(); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + try { + File file=new File("flairsaccepted.txt"); + BufferedWriter bw=new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.AcceptedFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + file=new File("flairsignored.txt"); + bw = new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.IgnoredFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + public static void SetPlayerFlair(Player player, String flair) + { //2015.08.09. + flair=flair.replace('&', '§'); + MaybeOfflinePlayer.AddPlayerIfNeeded(player.getName()).Flair=flair; + File file=new File("customflairs.txt"); + try { + BufferedWriter bw; + bw = new BufferedWriter(new FileWriter(file, true)); + bw.write(player.getName()+"\n"); + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + public static void RemoveLineFromFile(String file) + { + File inputFile = new File(file); + File tempFile = new File("_temp.txt"); + + try { + BufferedReader reader = new BufferedReader(new FileReader(inputFile)); + BufferedWriter writer = new BufferedWriter(new FileWriter(tempFile)); + + String lineToRemove = "bbb"; + String currentLine; + + while((currentLine = reader.readLine()) != null) { + // trim newline when comparing with lineToRemove + String trimmedLine = currentLine.trim(); + if(trimmedLine.equals(lineToRemove)) continue; + writer.write(currentLine + System.getProperty("line.separator")); + } + writer.close(); + reader.close(); + boolean successful = tempFile.renameTo(inputFile); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/3d/6051d217853e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/3d/6051d217853e00151ce8ff6d4f74dabd deleted file mode 100644 index e292615..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/3d/6051d217853e00151ce8ff6d4f74dabd +++ /dev/null @@ -1,121 +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; - MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. - //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - if(p.Flair==null) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. - { - case "accept": - { - if(p.IgnoredFlair) - p.IgnoredFlair=false; //2015.08.08. - if(!p.AcceptedFlair) - { - String flair=p.Flair; //2015.08.08. - PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. - p.AcceptedFlair=true; //2015.08.08. - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("§cYou already have this user's flair.§r"); - break; - } - case "ignore": - { - if(p.AcceptedFlair) - p.AcceptedFlair=false; //2015.08.08. - if(!p.IgnoredFlair) - { - p.IgnoredFlair=true; - String flair=p.Flair; //2015.08.08. - PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. - player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); - } - else - player.sendMessage("§cYou already ignored this request.§r"); - break; - } - case "reload": //2015.07.20. - DoReload(player); - break; - case "showerrors": //2015.08.09. - DoShowErrors(player); - break; - default: - return false; - } - return true; - } - - if(args[0].toLowerCase()=="reload") - DoReload(null); //2015.07.20. - else if(args[0].toLowerCase()=="showerrors") - return false; - } - private static void DoReload(Player player) - { //2015.07.20. - if(player==null || player.isOp() || player.getName()=="NorbiPeti") - { - try - { - File file=new File("autoflairconfig.txt"); - if(file.exists()) - { - PluginMain.TownColors.clear(); - BufferedReader br=new BufferedReader(new FileReader(file)); - String line; - while((line=br.readLine())!=null) - { - String[] s=line.split(" "); - PluginMain.TownColors.put(s[0], s[1]); - } - br.close(); - for(Player p : PluginMain.GetPlayers()) - { - MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName()); - if(mp.Flair!=null) - { - String flair=mp.Flair; - PluginMain.RemovePlayerDisplayFlairFinal(p, flair); - PluginMain.AppendPlayerDisplayFlairFinal(p, flair); - } - } - String msg="§6Reloaded config file.§r"; - if(player!=null) - player.sendMessage(msg); - else - System.out.println(msg); - } - } - catch(Exception e) - { - System.out.println("Error!\n"+e); - if(player!=null) - player.sendMessage("§cAn error occured. See console for details.§r"); - } - } - else - player.sendMessage("§cYou need to be OP to use this command.§r"); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/3d/c0b328b0883e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/3d/c0b328b0883e00151ce8ff6d4f74dabd deleted file mode 100644 index fade14e..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/3d/c0b328b0883e00151ce8ff6d4f74dabd +++ /dev/null @@ -1,176 +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; - MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. - //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - if(p.Flair==null) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. - { - case "accept": - { - if(p.IgnoredFlair) - p.IgnoredFlair=false; //2015.08.08. - if(!p.AcceptedFlair) - { - String flair=p.Flair; //2015.08.08. - PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. - p.AcceptedFlair=true; //2015.08.08. - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("§cYou already have this user's flair.§r"); - break; - } - case "ignore": - { - if(p.AcceptedFlair) - p.AcceptedFlair=false; //2015.08.08. - if(!p.IgnoredFlair) - { - p.IgnoredFlair=true; - String flair=p.Flair; //2015.08.08. - PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. - player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); - } - else - player.sendMessage("§cYou already ignored this request.§r"); - break; - } - /*case "reload": //2015.07.20. - DoReload(player); - break;*/ - case "admin": //2015.08.09. - DoAdmin(player, args); - break; - default: - return false; - } - return true; - } - - /*if(args[0].toLowerCase()=="reload") - DoReload(null); //2015.07.20.*/ - else if(args[0].toLowerCase()=="admin") - DoAdmin(null, args); //2015.08.09. - return false; - } - private static void DoReload(Player player) - { //2015.07.20. - //if(player==null || player.isOp() || player.getName()=="NorbiPeti") - //{ - try - { - File file=new File("autoflairconfig.txt"); - if(file.exists()) - { - PluginMain.TownColors.clear(); - BufferedReader br=new BufferedReader(new FileReader(file)); - String line; - while((line=br.readLine())!=null) - { - String[] s=line.split(" "); - PluginMain.TownColors.put(s[0], s[1]); - } - br.close(); - for(Player p : PluginMain.GetPlayers()) - { - MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName()); - if(mp.Flair!=null) - { - String flair=mp.Flair; - PluginMain.RemovePlayerDisplayFlairFinal(p, flair); - PluginMain.AppendPlayerDisplayFlairFinal(p, flair); - } - } - String msg="§6Reloaded config file.§r"; - if(player!=null) - player.sendMessage(msg); - else - System.out.println(msg); - } - } - catch(Exception e) - { - System.out.println("Error!\n"+e); - if(player!=null) - player.sendMessage("§cAn error occured. See console for details.§r"); - } - //} - //else - //player.sendMessage("§cYou need to be OP to use this command.§r"); - } - private static void DoAdmin(Player player, String[] args) - { //2015.08.09. - if(player==null || player.isOp() || player.getName()=="NorbiPeti") - { - if(args.length==1) - { - String message="§cUsage: /u admin reload|playerinfo§r"; - if(player==null) - System.out.println(message); - else - player.sendMessage(message); - return; - } - //args[0] is "admin" - switch(args[1].toLowerCase()) - { - case "reload": - DoReload(player); - break; - case "playerinfo": - DoPlayerInfo(player, args); - break; - } - } - else - player.sendMessage("§cYou need to be OP to use this command.§r"); - } - private static void DoPlayerInfo(Player player, String[] args) - { //2015.08.09. - //args[0] is "admin" - args[1] is "playerinfo" - if(args.length==2) - { - String message="§cUsage: /u admin playerinfo §r"; - if(player==null) - System.out.println(message); - else - player.sendMessage(message); - return; - } - if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2])) - { - String message="§cPlayer not found: "+args[2]+"§r"; - } - MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]); - return; - } - private static void SendMessage(Player player, String message) - { - if(player==null) - System.out.println(message); - else - player.sendMessage(message); - return; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/3e/00fa721adf3e001517108d149b613203 b/.metadata/.plugins/org.eclipse.core.resources/.history/3e/00fa721adf3e001517108d149b613203 new file mode 100644 index 0000000..eac777b --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/3e/00fa721adf3e001517108d149b613203 @@ -0,0 +1,250 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +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; + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. + //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) + if(p.Flair==null) + { + player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); + return true; + } + switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. + { + case "accept": + { + if(p.IgnoredFlair) + p.IgnoredFlair=false; //2015.08.08. + if(!p.AcceptedFlair) + { + String flair=p.Flair; //2015.08.08. + //PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + PluginMain.AppendPlayerDisplayFlair(p, player); + p.AcceptedFlair=true; //2015.08.08. + player.sendMessage("§6Your flair has been set:§r "+flair); + } + else + player.sendMessage("§cYou already have this user's flair.§r"); + break; + } + case "ignore": + { + if(p.AcceptedFlair) + p.AcceptedFlair=false; //2015.08.08. + if(!p.IgnoredFlair) + { + p.IgnoredFlair=true; + String flair=p.Flair; //2015.08.08. + PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. + player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); + } + else + player.sendMessage("§cYou already ignored this request.§r"); + break; + } + /*case "reload": //2015.07.20. + DoReload(player); + break;*/ + case "admin": //2015.08.09. + DoAdmin(player, args); + break; + case "nonpresser": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§7(non-pr.)§r"; + break; + case "cantpress": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§r(can't press)§r"; + break; + default: + return false; + } + return true; + } + /*if(args[0].toLowerCase()=="reload") + DoReload(null); //2015.07.20.*/ + else if(args.length>0 && args[0].toLowerCase().equals("admin")) //2015.08.09. + { + DoAdmin(null, args); //2015.08.09. + return true; //2015.08.09. + } + return false; + } + private static void DoReload(Player player) + { //2015.07.20. + //if(player==null || player.isOp() || player.getName()=="NorbiPeti") + //{ + try + { + File file=new File("autoflairconfig.txt"); + if(file.exists()) + { + PluginMain.LoadFiles(true); //2015.08.09. + for(Player p : PluginMain.GetPlayers()) + { + MaybeOfflinePlayer mp = MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName()); + if(mp.Flair!=null) + { + String flair=mp.Flair; + PluginMain.RemovePlayerDisplayFlairFinal(p, flair); + //PluginMain.AppendPlayerDisplayFlairFinal(p, flair); + PluginMain.AppendPlayerDisplayFlair(mp, p); //2015.08.09. + } + String msg="§6Note: The auto-flair plugin has been reloaded. You might need to wait 10s to have your flair.§r"; //2015.08.09. + p.sendMessage(msg); //2015.08.09. + } + //String msg="§6Reloaded config file.§r"; + //SendMessage(player, msg); //2015.08.09. + } + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + if(player!=null) + player.sendMessage("§cAn error occured. See console for details.§r"); + PluginMain.LastException=e; //2015.08.09. + } + //} + //else + //player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static Player ReloadPlayer; //2015.08.09. + private static void DoAdmin(Player player, String[] args) + { //2015.08.09. + if(player==null || player.isOp() || player.getName()=="NorbiPeti") + { + //System.out.println("Args length: " + args.length); + if(args.length==1) + { + String message="§cUsage: /u admin reload|playerinfo§r"; + SendMessage(player, message); + return; + } + //args[0] is "admin" + switch(args[1].toLowerCase()) + { + case "reload": + ReloadPlayer=player; //2015.08.09. + SendMessage(player, "§6Make sure to save the current settings before you modify and reload them! Type /u admin confirm when done.§r"); + break; + case "playerinfo": + DoPlayerInfo(player, args); + break; + case "getlasterror": + DoGetLastError(player, args); + case "confirm": + if(ReloadPlayer==player) + DoReload(player); //2015.08.09. + else + SendMessage(player, "§cYou need to do /u admin reload first.§r"); + break; + case "save": + PluginMain.SaveFiles(); //2015.08.09. + SendMessage(player, "§6Saved files. Now you can edit them and reload if you want.§r"); + break; + default: + String message="§cUsage: /u admin reload|playerinfo|getlasterror§r"; + SendMessage(player, message); + return; + } + } + else + player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static void DoPlayerInfo(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "playerinfo" + if(args.length==2) + { + String message="§cUsage: /u admin playerinfo §r"; + SendMessage(player, message); + return; + } + if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2])) + { + String message="§cPlayer not found: "+args[2]+"§r"; + SendMessage(player, message); + return; + } + MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]); + SendMessage(player, "Player name: "+p.PlayerName); + SendMessage(player, "User flair: "+p.Flair); + SendMessage(player, "Username: "+p.UserName); + SendMessage(player, "Flair accepted: "+p.AcceptedFlair); + SendMessage(player, "Flair ignored: "+p.IgnoredFlair); + } + private static void SendMessage(Player player, String message) + { //2015.08.09. + if(player==null) + System.out.println(message); + else + player.sendMessage(message); + } + private static void DoGetLastError(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "getlasterror" + if(PluginMain.LastException!=null) + { + SendMessage(player, "Last error:"); + SendMessage(player, PluginMain.LastException.toString()); + PluginMain.LastException=null; + } + else + SendMessage(player, "There were no exceptions."); + } + private static void SetPlayerFlair(Player player, String flair) + { //2015.08.09. + flair=flair.replace('&', '§'); + MaybeOfflinePlayer.AddPlayerIfNeeded(player.getName()).Flair=flair; + if(!PluginMain.RemoveLineFromFile("customflairs.txt")) + { + SendMessage(player, "Error removing previous custom flair!"); + } + File file=new File("customflairs.txt"); + try { + BufferedWriter bw; + bw = new BufferedWriter(new FileWriter(file, true)); + bw.write(player.getName()+"\n"); + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + PluginMain.LastException=e; //2015.08.09. + } + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/3e/509fad42873e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/3e/509fad42873e00151ce8ff6d4f74dabd deleted file mode 100644 index c25a794..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/3e/509fad42873e00151ce8ff6d4f74dabd +++ /dev/null @@ -1,136 +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; - MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. - //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - if(p.Flair==null) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. - { - case "accept": - { - if(p.IgnoredFlair) - p.IgnoredFlair=false; //2015.08.08. - if(!p.AcceptedFlair) - { - String flair=p.Flair; //2015.08.08. - PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. - p.AcceptedFlair=true; //2015.08.08. - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("§cYou already have this user's flair.§r"); - break; - } - case "ignore": - { - if(p.AcceptedFlair) - p.AcceptedFlair=false; //2015.08.08. - if(!p.IgnoredFlair) - { - p.IgnoredFlair=true; - String flair=p.Flair; //2015.08.08. - PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. - player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); - } - else - player.sendMessage("§cYou already ignored this request.§r"); - break; - } - /*case "reload": //2015.07.20. - DoReload(player); - break;*/ - case "admin": //2015.08.09. - DoAdmin(player, args); - break; - default: - return false; - } - return true; - } - - /*if(args[0].toLowerCase()=="reload") - DoReload(null); //2015.07.20.*/ - else if(args[0].toLowerCase()=="admin") - DoAdmin(null, args); //2015.08.09. - return false; - } - private static void DoReload(Player player) - { //2015.07.20. - //if(player==null || player.isOp() || player.getName()=="NorbiPeti") - //{ - try - { - File file=new File("autoflairconfig.txt"); - if(file.exists()) - { - PluginMain.TownColors.clear(); - BufferedReader br=new BufferedReader(new FileReader(file)); - String line; - while((line=br.readLine())!=null) - { - String[] s=line.split(" "); - PluginMain.TownColors.put(s[0], s[1]); - } - br.close(); - for(Player p : PluginMain.GetPlayers()) - { - MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName()); - if(mp.Flair!=null) - { - String flair=mp.Flair; - PluginMain.RemovePlayerDisplayFlairFinal(p, flair); - PluginMain.AppendPlayerDisplayFlairFinal(p, flair); - } - } - String msg="§6Reloaded config file.§r"; - if(player!=null) - player.sendMessage(msg); - else - System.out.println(msg); - } - } - catch(Exception e) - { - System.out.println("Error!\n"+e); - if(player!=null) - player.sendMessage("§cAn error occured. See console for details.§r"); - } - //} - //else - //player.sendMessage("§cYou need to be OP to use this command.§r"); - } - private static void DoAdmin(Player player, String[] args) - { - if(player==null || player.isOp() || player.getName()=="NorbiPeti") - { - //args[0] is "admin" - switch(args[1].toLowerCase()) - { - case "reload": - DoReload(player); - } - } - else - player.sendMessage("§cYou need to be OP to use this command.§r"); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/3e/90e3e69bde3e001517108d149b613203 b/.metadata/.plugins/org.eclipse.core.resources/.history/3e/90e3e69bde3e001517108d149b613203 new file mode 100644 index 0000000..9c0f686 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/3e/90e3e69bde3e001517108d149b613203 @@ -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.WorldCoord; + +public class PluginMain extends JavaPlugin +{ //Translated to Java: 2015.07.15. + //A user, which flair isn't obtainable: + //https://www.reddit.com/r/thebutton/comments/31c32v/i_pressed_the_button_without_really_thinking/ + private static PluginMain Instance; + // Fired when plugin is first enabled + @Override + public void onEnable() + { + System.out.println("The Button Auto-flair Plugin by NorbiPeti (:P)"); + getServer().getPluginManager().registerEvents(new PlayerListener(), this); + this.getCommand("u").setExecutor(new Commands()); + this.getCommand("u").setUsage(this.getCommand("u").getUsage().replace('&', '§')); + Instance=this; //2015.08.08. + LoadFiles(false); //2015.08.09. + Runnable r=new Runnable(){public void run(){ThreadMethod();}}; + Thread t=new Thread(r); + t.start(); + } + Boolean stop=false; + // Fired when plugin is disabled + @Override + public void onDisable() + { + SaveFiles(); //2015.08.09. + stop=true; + } + + public void ThreadMethod() //<-- 2015.07.16. + { + while(!stop) + { + try + { + String body=DownloadString("https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/autoflair_system_comment_your_minecraft_name_and/.json?limit=1000"); + JSONArray json=new JSONArray(body).getJSONObject(1).getJSONObject("data").getJSONArray("children"); + for(Object obj : json) + { + JSONObject item = (JSONObject)obj; + String author=item.getJSONObject("data").getString("author"); + String ign=item.getJSONObject("data").getString("body"); + int start = ign.indexOf("IGN:") + "IGN:".length(); + if(start==-1) + continue; //2015.08.09. + int end = ign.indexOf(' ', start); + if (end == -1 || end == start) + end=ign.indexOf('\n', start); //2015.07.15. + if (end == -1 || end == start) + ign = ign.substring(start); + else + ign = ign.substring(start, end); + ign = ign.trim(); + if(HasIGFlair(ign)) + continue; + try { + Thread.sleep(10); + } catch(InterruptedException ex) { + Thread.currentThread().interrupt(); + } + String[] flairdata = DownloadString("http://karmadecay.com/thebutton-data.php?users=" + author).replace("\"", "").split(":"); + String flair; + if(flairdata.length > 1) //2015.07.15. + flair = flairdata[1]; + else + flair=""; + if (flair != "-1") + flair = flair + "s"; + else + flair = "non-presser"; + String flairclass; + if(flairdata.length>2) + flairclass = flairdata[2]; + else + flairclass="unknown"; + SetFlair(ign, flair, flairclass, author); + } + Thread.sleep(10000); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + } + + public static Exception LastException; //2015.08.09. + + public String DownloadString(String urlstr) throws MalformedURLException, IOException + { + URL url = new URL(urlstr); + URLConnection con = url.openConnection(); + con.setRequestProperty("User-Agent", "TheButtonAutoFlair"); + InputStream in = con.getInputStream(); + String encoding = con.getContentEncoding(); + encoding = encoding == null ? "UTF-8" : encoding; + String body = IOUtils.toString(in, encoding); + in.close(); + return body; + } + + public static Map TownColors=new HashMap(); //2015.07.20. + public Boolean HasIGFlair(String playername) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + return p.Flair!=null; //2015.08.08. + } + + public void SetFlair(String playername, String text, String flairclass, String username) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + String finalflair; + p.FlairDecided=true; + switch(flairclass) + { + case "press-1": + finalflair="§c("+text+")§r"; + break; + case "press-2": + finalflair="§6("+text+")§r"; + break; + case "press-3": + finalflair="§e("+text+")§r"; + break; + case "press-4": + finalflair="§a("+text+")§r"; + break; + case "press-5": + finalflair="§9("+text+")§r"; + break; + 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; + case "undecided": //2015.08.09. + p.FlairDecided=false; + finalflair=""; + break; + default: + finalflair=""; + break; + } + if(finalflair.length()==0) //<-- 2015.07.20. + return; + p.Flair=finalflair; //2015.08.08. + p.UserName=username; //2015.08.08. + System.out.println("Added new flair to "+playername+": "+finalflair); + for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08. + { + if(player.getName().equals(playername)) + { + //AppendPlayerDisplayFlair(player, username, finalflair); + AppendPlayerDisplayFlair(p, player); + break; + } + } + } + + public static String GetFlair(Player player) + { //2015.07.16. + String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08. + return flair==null ? "" : flair; + } + + //public static void AppendPlayerDisplayFlair(Player player, String username, String flair) + public static void AppendPlayerDisplayFlair(MaybeOfflinePlayer player, Player p) //<-- 2015.08.09. + { + + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).IgnoredFlair) + return; + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).AcceptedFlair) + { + AppendPlayerDisplayFlairFinal(p, player.Flair); //2015.07.20. + if(!player.FlairDecided) + p.sendMessage("§9Your flair type is unknown. Are you a non-presser or a can't press? (/u nonpresser or /u cantpress)§r"); //2015.08.09. + } + else + p.sendMessage("§9Are you Reddit user "+player.UserName+"?§r §6Type /u accept or /u ignore§r"); + } + + private static void AppendPlayerDisplayFlairFinal(Player player, String flair) + { //2015.07.20. + String color = GetColorForTown(GetPlayerTown(player)); //TO!DO: Multiple colors put on first capital letters + String[] colors = color.substring(1).split("§"); + String displayname=player.getName(); //2015.08.08. + ArrayList Positions=new ArrayList<>(); + for(int i=0; i=colors.length) + { + int x=0; + for(int i=0; i GetPlayers() + { + return Instance.getServer().getOnlinePlayers(); + } + + public static void LoadFiles(boolean reload) //<-- 2015.08.09. + { + if(reload) + { //2015.08.09. + System.out.println("Auto-flair plugin cleanup for reloading..."); + MaybeOfflinePlayer.AllPlayers.clear(); + TownColors.clear(); + } + System.out.println("Loading files for auto-flair plugin..."); //2015.08.09. + try { + File file=new File("flairsaccepted.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + //System.out.println("Name: " + name); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("flairsignored.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsignored.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("autoflairconfig.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + TownColors.put(s[0], s[1]); + } + br.close(); + } + file=new File("customflairs.txt"); //2015.08.09. + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + MaybeOfflinePlayer.AddPlayerIfNeeded(s[0]).Flair=s[1]; //2015.08.09. + } + br.close(); + } + //throw new IOException("Test"); //2015.08.09. + System.out.println("Auto-flair plugin loaded files!"); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + public static void SaveFiles() //<-- 2015.08.09. + { + try + { + FileWriter fw; + fw = new FileWriter("flairsaccepted.txt"); + fw.close(); + fw = new FileWriter("flairsignored.txt"); + fw.close(); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + try { + File file=new File("flairsaccepted.txt"); + BufferedWriter bw=new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.AcceptedFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + file=new File("flairsignored.txt"); + bw = new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.IgnoredFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + public static void SetPlayerFlair(Player player, String flair) + { //2015.08.09. + flair=flair.replace('&', '§'); + MaybeOfflinePlayer.AddPlayerIfNeeded(player.getName()).Flair=flair; + File file=new File("customflairs.txt"); + try { + BufferedWriter bw; + bw = new BufferedWriter(new FileWriter(file, true)); + bw.write(player.getName()+"\n"); + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + public static void RemoveLineFromFile(String file) + { + File inputFile = new File(file); + File tempFile = new File("_temp.txt"); + + try { + BufferedReader reader = new BufferedReader(new FileReader(inputFile)); + BufferedWriter writer = new BufferedWriter(new FileWriter(tempFile)); + + String lineToRemove = "bbb"; + String currentLine; + + while((currentLine = reader.readLine()) != null) { + // trim newline when comparing with lineToRemove + String trimmedLine = currentLine.trim(); + if(trimmedLine.equals(lineToRemove)) continue; + writer.write(currentLine + System.getProperty("line.separator")); + } + writer.close(); + reader.close(); + boolean successful = tempFile.renameTo(inputFile); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/3e/e0d118c0863e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/3e/e0d118c0863e00151ce8ff6d4f74dabd deleted file mode 100644 index a8ddfb3..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/3e/e0d118c0863e00151ce8ff6d4f74dabd +++ /dev/null @@ -1,135 +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; - MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. - //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - if(p.Flair==null) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. - { - case "accept": - { - if(p.IgnoredFlair) - p.IgnoredFlair=false; //2015.08.08. - if(!p.AcceptedFlair) - { - String flair=p.Flair; //2015.08.08. - PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. - p.AcceptedFlair=true; //2015.08.08. - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("§cYou already have this user's flair.§r"); - break; - } - case "ignore": - { - if(p.AcceptedFlair) - p.AcceptedFlair=false; //2015.08.08. - if(!p.IgnoredFlair) - { - p.IgnoredFlair=true; - String flair=p.Flair; //2015.08.08. - PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. - player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); - } - else - player.sendMessage("§cYou already ignored this request.§r"); - break; - } - case "reload": //2015.07.20. - DoReload(player); - break; - case "admin": //2015.08.09. - DoAdmin(player, args); - break; - default: - return false; - } - return true; - } - - if(args[0].toLowerCase()=="reload") - DoReload(null); //2015.07.20. - else if(args[0].toLowerCase()=="admin") - DoAdmin(null, args); //2015.08.09. - return false; - } - private static void DoReload(Player player) - { //2015.07.20. - if(player==null || player.isOp() || player.getName()=="NorbiPeti") - { - try - { - File file=new File("autoflairconfig.txt"); - if(file.exists()) - { - PluginMain.TownColors.clear(); - BufferedReader br=new BufferedReader(new FileReader(file)); - String line; - while((line=br.readLine())!=null) - { - String[] s=line.split(" "); - PluginMain.TownColors.put(s[0], s[1]); - } - br.close(); - for(Player p : PluginMain.GetPlayers()) - { - MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName()); - if(mp.Flair!=null) - { - String flair=mp.Flair; - PluginMain.RemovePlayerDisplayFlairFinal(p, flair); - PluginMain.AppendPlayerDisplayFlairFinal(p, flair); - } - } - String msg="§6Reloaded config file.§r"; - if(player!=null) - player.sendMessage(msg); - else - System.out.println(msg); - } - } - catch(Exception e) - { - System.out.println("Error!\n"+e); - if(player!=null) - player.sendMessage("§cAn error occured. See console for details.§r"); - } - } - else - player.sendMessage("§cYou need to be OP to use this command.§r"); - } - private static void DoAdmin(Player player, String[] args) - { - if(player==null || player.isOp() || player.getName()=="NorbiPeti") - { - //args[0] is "admin" - swithc(args[1].toLowerCase()) - { - - } - } - else - player.sendMessage("§cYou need to be OP to use this command.§r"); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/3f/70140e5a0c3e00151089cca86c5b1a99 b/.metadata/.plugins/org.eclipse.core.resources/.history/3f/70140e5a0c3e00151089cca86c5b1a99 deleted file mode 100644 index 090b35d..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/3f/70140e5a0c3e00151089cca86c5b1a99 +++ /dev/null @@ -1,432 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import java.io.BufferedReader; -import java.io.BufferedWriter; -import java.io.File; -import java.io.FileReader; -import java.io.FileWriter; -import java.io.IOException; -import java.io.InputStream; -import java.net.MalformedURLException; -import java.net.URL; -import java.net.URLConnection; -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; -import java.util.Map; - -import org.apache.commons.io.IOUtils; -import org.bukkit.entity.Player; -import org.bukkit.plugin.java.JavaPlugin; -import org.json.JSONArray; -import org.json.JSONObject; - -import com.palmergames.bukkit.towny.object.Town; -import com.palmergames.bukkit.towny.object.WorldCoord; - -public class PluginMain extends JavaPlugin -{ //Translated to Java: 2015.07.15. - //A user, which flair isn't obtainable: - //https://www.reddit.com/r/thebutton/comments/31c32v/i_pressed_the_button_without_really_thinking/ - private static PluginMain Instance; - // Fired when plugin is first enabled - @Override - public void onEnable() - { - System.out.println("The Button Auto-flair Plugin by NorbiPeti (:P)"); - //System.out.println("Original C# version: http://pastebin.com/tX8xCPbp"); - //System.out.println("The Java version is... Also made by the same person."); - //System.out.println("With the help of StackOverflow and similar."); - /*catch(MalformedURLException e) - { - } - catch(IOException e) - { - }*/ - getServer().getPluginManager().registerEvents(new PlayerListener(), this); - //System.out.println("Registering commands..."); - this.getCommand("u").setExecutor(new Commands()); - this.getCommand("u").setUsage(this.getCommand("u").getUsage().replace('&', '§')); - Instance=this; //2015.08.08. - try { - File file=new File("flairsaccepted.txt"); - if(file.exists()) - { - BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt")); - String line; - while ((line = br.readLine()) != null) - { - //AcceptedPlayers.add(line.replace("\n", "")); - String name=line.replace("\n", ""); - System.out.println("Name: " + name); - 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/a0709f19cf3e001518fa86d7ae2a1cf8 b/.metadata/.plugins/org.eclipse.core.resources/.history/3f/a0709f19cf3e001518fa86d7ae2a1cf8 new file mode 100644 index 0000000..9476659 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/3f/a0709f19cf3e001518fa86d7ae2a1cf8 @@ -0,0 +1,362 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStream; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLConnection; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + +import org.apache.commons.io.IOUtils; +import org.bukkit.entity.Player; +import org.bukkit.plugin.java.JavaPlugin; +import org.json.JSONArray; +import org.json.JSONObject; + +import tk.sznp.thebuttonautoflair.MaybeOfflinePlayer.FlairClassType; + +import com.palmergames.bukkit.towny.object.Town; +import com.palmergames.bukkit.towny.object.WorldCoord; + +public class PluginMain extends JavaPlugin +{ //Translated to Java: 2015.07.15. + //A user, which flair isn't obtainable: + //https://www.reddit.com/r/thebutton/comments/31c32v/i_pressed_the_button_without_really_thinking/ + private static PluginMain Instance; + // Fired when plugin is first enabled + @Override + public void onEnable() + { + System.out.println("The Button Auto-flair Plugin by NorbiPeti (:P)"); + getServer().getPluginManager().registerEvents(new PlayerListener(), this); + this.getCommand("u").setExecutor(new Commands()); + this.getCommand("u").setUsage(this.getCommand("u").getUsage().replace('&', '§')); + Instance=this; //2015.08.08. + try { + File file=new File("flairsaccepted.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + //System.out.println("Name: " + name); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("flairsignored.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsignored.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("autoflairconfig.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + TownColors.put(s[0], s[1]); + } + br.close(); + } + //throw new IOException("Test"); //2015.08.09. + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + Runnable r=new Runnable(){public void run(){ThreadMethod();}}; + Thread t=new Thread(r); + t.start(); + } + Boolean stop=false; + // Fired when plugin is disabled + @Override + public void onDisable() + { + try + { + FileWriter fw; + fw = new FileWriter("flairsaccepted.txt"); + fw.close(); + fw = new FileWriter("flairsignored.txt"); + fw.close(); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + try { + File file=new File("flairsaccepted.txt"); + BufferedWriter bw=new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.AcceptedFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + file=new File("flairsignored.txt"); + bw = new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.IgnoredFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + stop=true; + } + + public void ThreadMethod() //<-- 2015.07.16. + { + while(!stop) + { + try + { + String body=DownloadString("https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/autoflair_system_comment_your_minecraft_name_and/.json?limit=1000"); + JSONArray json=new JSONArray(body).getJSONObject(1).getJSONObject("data").getJSONArray("children"); + for(Object obj : json) + { + JSONObject item = (JSONObject)obj; + String author=item.getJSONObject("data").getString("author"); + String ign=item.getJSONObject("data").getString("body"); + int start = ign.indexOf("IGN:") + "IGN:".length(); + int end = ign.indexOf(' ', start); + if (end == -1 || end == start) + end=ign.indexOf('\n', start); //2015.07.15. + if (end == -1 || end == start) + ign = ign.substring(start); + else + ign = ign.substring(start, end); + ign = ign.trim(); + if(HasIGFlair(ign)) + continue; + try { + Thread.sleep(10); + } catch(InterruptedException ex) { + Thread.currentThread().interrupt(); + } + String[] flairdata = DownloadString("http://karmadecay.com/thebutton-data.php?users=" + author).replace("\"", "").split(":"); + String flair; + if(flairdata.length > 1) //2015.07.15. + flair = flairdata[1]; + else + flair=""; + if (flair != "-1") + flair = flair + "s"; + else + flair = "non-presser"; + String flairclass; + if(flairdata.length>2) + flairclass = flairdata[2]; + else + flairclass="unknown"; + SetFlair(ign, flair, flairclass, author); + } + Thread.sleep(10000); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + } + + public static Exception LastException; //2015.08.09. + + public String DownloadString(String urlstr) throws MalformedURLException, IOException + { + URL url = new URL(urlstr); + URLConnection con = url.openConnection(); + con.setRequestProperty("User-Agent", "TheButtonAutoFlair"); + InputStream in = con.getInputStream(); + String encoding = con.getContentEncoding(); + encoding = encoding == null ? "UTF-8" : encoding; + String body = IOUtils.toString(in, encoding); + in.close(); + return body; + } + + public static Map TownColors=new HashMap(); //2015.07.20. + public Boolean HasIGFlair(String playername) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + return p.Flair!=null; //2015.08.08. + } + + public void SetFlair(String playername, String text, String flairclass, String username) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + String finalflair; + p.FlairDecided=true; + switch(flairclass) + { + case "press-1": + finalflair="§c("+text+")§r"; + break; + case "press-2": + finalflair="§6("+text+")§r"; + break; + case "press-3": + finalflair="§e("+text+")§r"; + break; + case "press-4": + finalflair="§a("+text+")§r"; + break; + case "press-5": + finalflair="§9("+text+")§r"; + break; + 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; + case "undecided": //2015.08.09. + p.FlairDecided=false; + finalflair=""; + break; + default: + finalflair=""; + break; + } + if(finalflair.length()==0) //<-- 2015.07.20. + return; + p.Flair=finalflair; //2015.08.08. + p.UserName=username; //2015.08.08. + System.out.println("Added new flair to "+playername+": "+finalflair); + for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08. + { + if(player.getName().equals(playername)) + { + AppendPlayerDisplayFlair(player, username, finalflair); + break; + } + } + } + + public static String GetFlair(Player player) + { //2015.07.16. + String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08. + return flair==null ? "" : flair; + } + + //public static void AppendPlayerDisplayFlair(Player player, String username, String flair) + public static void AppendPlayerDisplayFlair(MaybeOfflinePlayer player, Player p) + { + + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).IgnoredFlair) + return; + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).AcceptedFlair) + { + AppendPlayerDisplayFlairFinal(p, flair); //2015.07.20. + } + else + player.sendMessage("§9Are you Reddit user "+username+"?§r §6Type /u accept or /u ignore§r"); + } + + private static void AppendPlayerDisplayFlairFinal(Player player, String flair) + { //2015.07.20. + String color = GetColorForTown(GetPlayerTown(player)); //TO!DO: Multiple colors put on first capital letters + String[] colors = color.substring(1).split("§"); + String displayname=player.getName(); //2015.08.08. + ArrayList Positions=new ArrayList<>(); + for(int i=0; i=colors.length) + { + int x=0; + for(int i=0; i GetPlayers() + { + return Instance.getServer().getOnlinePlayers(); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/3f/d0bd9472043e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/3f/d0bd9472043e00151c31fb33fff4337f deleted file mode 100644 index 87c0c13..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/3f/d0bd9472043e00151c31fb33fff4337f +++ /dev/null @@ -1,126 +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; - 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/4/b030d637cd3e001518fa86d7ae2a1cf8 b/.metadata/.plugins/org.eclipse.core.resources/.history/4/b030d637cd3e001518fa86d7ae2a1cf8 new file mode 100644 index 0000000..587e2b6 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/4/b030d637cd3e001518fa86d7ae2a1cf8 @@ -0,0 +1,29 @@ +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 + 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); + } + public enum FlairClassType + { + + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/40/607238ae0d3e00151089cca86c5b1a99 b/.metadata/.plugins/org.eclipse.core.resources/.history/40/607238ae0d3e00151089cca86c5b1a99 deleted file mode 100644 index efac5c3..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/40/607238ae0d3e00151089cca86c5b1a99 +++ /dev/null @@ -1,434 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import java.io.BufferedReader; -import java.io.BufferedWriter; -import java.io.File; -import java.io.FileReader; -import java.io.FileWriter; -import java.io.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/900a4bdce03e001517108d149b613203 b/.metadata/.plugins/org.eclipse.core.resources/.history/40/900a4bdce03e001517108d149b613203 new file mode 100644 index 0000000..848fea5 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/40/900a4bdce03e001517108d149b613203 @@ -0,0 +1,265 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +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; + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. + //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) + if(p.Flair==null) + { + player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); + return true; + } + switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. + { + case "accept": + { + if(p.IgnoredFlair) + p.IgnoredFlair=false; //2015.08.08. + if(!p.AcceptedFlair) + { + String flair=p.Flair; //2015.08.08. + //PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + PluginMain.AppendPlayerDisplayFlair(p, player); + p.AcceptedFlair=true; //2015.08.08. + player.sendMessage("§6Your flair has been set:§r "+flair); + } + else + player.sendMessage("§cYou already have this user's flair.§r"); + break; + } + case "ignore": + { + if(p.AcceptedFlair) + p.AcceptedFlair=false; //2015.08.08. + if(!p.IgnoredFlair) + { + p.IgnoredFlair=true; + String flair=p.Flair; //2015.08.08. + PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. + player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); + } + else + player.sendMessage("§cYou already ignored this request.§r"); + break; + } + /*case "reload": //2015.07.20. + DoReload(player); + break;*/ + case "admin": //2015.08.09. + DoAdmin(player, args); + break; + case "nonpresser": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§7(non-pr.)§r"; + break; + case "cantpress": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§r(can't press)§r"; + break; + default: + return false; + } + return true; + } + /*if(args[0].toLowerCase()=="reload") + DoReload(null); //2015.07.20.*/ + else if(args.length>0 && args[0].toLowerCase().equals("admin")) //2015.08.09. + { + DoAdmin(null, args); //2015.08.09. + return true; //2015.08.09. + } + return false; + } + private static void DoReload(Player player) + { //2015.07.20. + //if(player==null || player.isOp() || player.getName()=="NorbiPeti") + //{ + try + { + File file=new File("autoflairconfig.txt"); + if(file.exists()) + { + PluginMain.LoadFiles(true); //2015.08.09. + for(Player p : PluginMain.GetPlayers()) + { + MaybeOfflinePlayer mp = MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName()); + if(mp.Flair!=null) + { + String flair=mp.Flair; + PluginMain.RemovePlayerDisplayFlairFinal(p, flair); + //PluginMain.AppendPlayerDisplayFlairFinal(p, flair); + PluginMain.AppendPlayerDisplayFlair(mp, p); //2015.08.09. + } + String msg="§6Note: The auto-flair plugin has been reloaded. You might need to wait 10s to have your flair.§r"; //2015.08.09. + p.sendMessage(msg); //2015.08.09. + } + //String msg="§6Reloaded config file.§r"; + //SendMessage(player, msg); //2015.08.09. + } + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + if(player!=null) + player.sendMessage("§cAn error occured. See console for details.§r"); + PluginMain.LastException=e; //2015.08.09. + } + //} + //else + //player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static Player ReloadPlayer; //2015.08.09. + private static void DoAdmin(Player player, String[] args) + { //2015.08.09. + if(player==null || player.isOp() || player.getName()=="NorbiPeti") + { + //System.out.println("Args length: " + args.length); + if(args.length==1) + { + String message="§cUsage: /u admin reload|playerinfo§r"; + SendMessage(player, message); + return; + } + //args[0] is "admin" + switch(args[1].toLowerCase()) + { + case "reload": + ReloadPlayer=player; //2015.08.09. + SendMessage(player, "§6Make sure to save the current settings before you modify and reload them! Type /u admin confirm when done.§r"); + break; + case "playerinfo": + DoPlayerInfo(player, args); + break; + case "getlasterror": + DoGetLastError(player, args); + case "confirm": + if(ReloadPlayer==player) + DoReload(player); //2015.08.09. + else + SendMessage(player, "§cYou need to do /u admin reload first.§r"); + break; + case "save": + PluginMain.SaveFiles(); //2015.08.09. + SendMessage(player, "§6Saved files. Now you can edit them and reload if you want.§r"); + break; + case "setflair": + + break; + default: + String message="§cUsage: /u admin reload|playerinfo|getlasterror|save§r"; + SendMessage(player, message); + return; + } + } + else + player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static void DoPlayerInfo(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "playerinfo" + if(args.length==2) + { + String message="§cUsage: /u admin playerinfo §r"; + SendMessage(player, message); + return; + } + if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2])) + { + String message="§cPlayer not found: "+args[2]+"§r"; + SendMessage(player, message); + return; + } + MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]); + SendMessage(player, "Player name: "+p.PlayerName); + SendMessage(player, "User flair: "+p.Flair); + SendMessage(player, "Username: "+p.UserName); + SendMessage(player, "Flair accepted: "+p.AcceptedFlair); + SendMessage(player, "Flair ignored: "+p.IgnoredFlair); + } + private static void SendMessage(Player player, String message) + { //2015.08.09. + if(player==null) + System.out.println(message); + else + player.sendMessage(message); + } + private static void DoGetLastError(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "getlasterror" + if(PluginMain.LastException!=null) + { + SendMessage(player, "Last error:"); + SendMessage(player, PluginMain.LastException.toString()); + PluginMain.LastException=null; + } + else + SendMessage(player, "There were no exceptions."); + } + private static void SetPlayerFlair(Player player, MaybeOfflinePlayer targetplayer, String flair) + { //2015.08.09. + flair=flair.replace('&', '§'); + MaybeOfflinePlayer.AddPlayerIfNeeded(player.getName()).Flair=flair; + if(!PluginMain.RemoveLineFromFile("customflairs.txt", targetplayer.getName())) + { + SendMessage(player, "§cError removing previous custom flair!§r"); + return; + } + File file=new File("customflairs.txt"); + try { + BufferedWriter bw; + bw = new BufferedWriter(new FileWriter(file, true)); + bw.write(targetplayer.getName()+"\n"); + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + PluginMain.LastException=e; //2015.08.09. + } + SendMessage(player, "§6The flair has been set. Player: "+targetplayer.getName()+" Flair: "+flair+"§r"); + } + private static void DoSetFlair(Player player, String args) + { + //args[0] is "admin" - args[1] is "setflair" + if(args.length()<4) + { + SendMessage(player, "§cUsage: /u admin setflair "); + return; + } + SetPlayerFlair(player, ) + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/41/50a33590fe3d00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/41/50a33590fe3d00151c31fb33fff4337f deleted file mode 100644 index e66301f..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/41/50a33590fe3d00151c31fb33fff4337f +++ /dev/null @@ -1,123 +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()); - 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/43/90a95fb5e03e001517108d149b613203 b/.metadata/.plugins/org.eclipse.core.resources/.history/43/90a95fb5e03e001517108d149b613203 new file mode 100644 index 0000000..af05fcf --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/43/90a95fb5e03e001517108d149b613203 @@ -0,0 +1,263 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +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; + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. + //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) + if(p.Flair==null) + { + player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); + return true; + } + switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. + { + case "accept": + { + if(p.IgnoredFlair) + p.IgnoredFlair=false; //2015.08.08. + if(!p.AcceptedFlair) + { + String flair=p.Flair; //2015.08.08. + //PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + PluginMain.AppendPlayerDisplayFlair(p, player); + p.AcceptedFlair=true; //2015.08.08. + player.sendMessage("§6Your flair has been set:§r "+flair); + } + else + player.sendMessage("§cYou already have this user's flair.§r"); + break; + } + case "ignore": + { + if(p.AcceptedFlair) + p.AcceptedFlair=false; //2015.08.08. + if(!p.IgnoredFlair) + { + p.IgnoredFlair=true; + String flair=p.Flair; //2015.08.08. + PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. + player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); + } + else + player.sendMessage("§cYou already ignored this request.§r"); + break; + } + /*case "reload": //2015.07.20. + DoReload(player); + break;*/ + case "admin": //2015.08.09. + DoAdmin(player, args); + break; + case "nonpresser": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§7(non-pr.)§r"; + break; + case "cantpress": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§r(can't press)§r"; + break; + default: + return false; + } + return true; + } + /*if(args[0].toLowerCase()=="reload") + DoReload(null); //2015.07.20.*/ + else if(args.length>0 && args[0].toLowerCase().equals("admin")) //2015.08.09. + { + DoAdmin(null, args); //2015.08.09. + return true; //2015.08.09. + } + return false; + } + private static void DoReload(Player player) + { //2015.07.20. + //if(player==null || player.isOp() || player.getName()=="NorbiPeti") + //{ + try + { + File file=new File("autoflairconfig.txt"); + if(file.exists()) + { + PluginMain.LoadFiles(true); //2015.08.09. + for(Player p : PluginMain.GetPlayers()) + { + MaybeOfflinePlayer mp = MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName()); + if(mp.Flair!=null) + { + String flair=mp.Flair; + PluginMain.RemovePlayerDisplayFlairFinal(p, flair); + //PluginMain.AppendPlayerDisplayFlairFinal(p, flair); + PluginMain.AppendPlayerDisplayFlair(mp, p); //2015.08.09. + } + String msg="§6Note: The auto-flair plugin has been reloaded. You might need to wait 10s to have your flair.§r"; //2015.08.09. + p.sendMessage(msg); //2015.08.09. + } + //String msg="§6Reloaded config file.§r"; + //SendMessage(player, msg); //2015.08.09. + } + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + if(player!=null) + player.sendMessage("§cAn error occured. See console for details.§r"); + PluginMain.LastException=e; //2015.08.09. + } + //} + //else + //player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static Player ReloadPlayer; //2015.08.09. + private static void DoAdmin(Player player, String[] args) + { //2015.08.09. + if(player==null || player.isOp() || player.getName()=="NorbiPeti") + { + //System.out.println("Args length: " + args.length); + if(args.length==1) + { + String message="§cUsage: /u admin reload|playerinfo§r"; + SendMessage(player, message); + return; + } + //args[0] is "admin" + switch(args[1].toLowerCase()) + { + case "reload": + ReloadPlayer=player; //2015.08.09. + SendMessage(player, "§6Make sure to save the current settings before you modify and reload them! Type /u admin confirm when done.§r"); + break; + case "playerinfo": + DoPlayerInfo(player, args); + break; + case "getlasterror": + DoGetLastError(player, args); + case "confirm": + if(ReloadPlayer==player) + DoReload(player); //2015.08.09. + else + SendMessage(player, "§cYou need to do /u admin reload first.§r"); + break; + case "save": + PluginMain.SaveFiles(); //2015.08.09. + SendMessage(player, "§6Saved files. Now you can edit them and reload if you want.§r"); + break; + case "setflair": + + break; + default: + String message="§cUsage: /u admin reload|playerinfo|getlasterror|save§r"; + SendMessage(player, message); + return; + } + } + else + player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static void DoPlayerInfo(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "playerinfo" + if(args.length==2) + { + String message="§cUsage: /u admin playerinfo §r"; + SendMessage(player, message); + return; + } + if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2])) + { + String message="§cPlayer not found: "+args[2]+"§r"; + SendMessage(player, message); + return; + } + MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]); + SendMessage(player, "Player name: "+p.PlayerName); + SendMessage(player, "User flair: "+p.Flair); + SendMessage(player, "Username: "+p.UserName); + SendMessage(player, "Flair accepted: "+p.AcceptedFlair); + SendMessage(player, "Flair ignored: "+p.IgnoredFlair); + } + private static void SendMessage(Player player, String message) + { //2015.08.09. + if(player==null) + System.out.println(message); + else + player.sendMessage(message); + } + private static void DoGetLastError(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "getlasterror" + if(PluginMain.LastException!=null) + { + SendMessage(player, "Last error:"); + SendMessage(player, PluginMain.LastException.toString()); + PluginMain.LastException=null; + } + else + SendMessage(player, "There were no exceptions."); + } + private static void SetPlayerFlair(Player player, Player targetplayer, String flair) + { //2015.08.09. + flair=flair.replace('&', '§'); + MaybeOfflinePlayer.AddPlayerIfNeeded(player.getName()).Flair=flair; + if(!PluginMain.RemoveLineFromFile("customflairs.txt", targetplayer.getName())) + { + SendMessage(player, "§cError removing previous custom flair!§r"); + return; + } + File file=new File("customflairs.txt"); + try { + BufferedWriter bw; + bw = new BufferedWriter(new FileWriter(file, true)); + bw.write(targetplayer.getName()+"\n"); + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + PluginMain.LastException=e; //2015.08.09. + } + SendMessage(player, "§6The flair has been set. Player: "+targetplayer.getName()+" Flair: "+flair+"§r"); + } + private static void DoSetFlair(Player player, String args) + { + //args[0] is "admin" - args[1] is "setflair" + if(args.length()<4) + { + SendMessage(player, "§cUsage: /u admin setflair ") + } + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/43/d0b51c31023e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/43/d0b51c31023e00151c31fb33fff4337f deleted file mode 100644 index 73c56cf..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/43/d0b51c31023e00151c31fb33fff4337f +++ /dev/null @@ -1,125 +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; - 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(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/44/3078a0bed23e001518fa86d7ae2a1cf8 b/.metadata/.plugins/org.eclipse.core.resources/.history/44/3078a0bed23e001518fa86d7ae2a1cf8 new file mode 100644 index 0000000..717cff8 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/44/3078a0bed23e001518fa86d7ae2a1cf8 @@ -0,0 +1,215 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; + +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class Commands implements CommandExecutor { + // This method is called, when somebody uses our command + @Override + public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { + if (sender instanceof Player) { + Player player = (Player) sender; + if(args.length<1) + return false; + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. + //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) + if(p.Flair==null) + { + player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); + return true; + } + switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. + { + case "accept": + { + if(p.IgnoredFlair) + p.IgnoredFlair=false; //2015.08.08. + if(!p.AcceptedFlair) + { + String flair=p.Flair; //2015.08.08. + //PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + PluginMain.AppendPlayerDisplayFlair(p, player); + p.AcceptedFlair=true; //2015.08.08. + player.sendMessage("§6Your flair has been set:§r "+flair); + } + else + player.sendMessage("§cYou already have this user's flair.§r"); + break; + } + case "ignore": + { + if(p.AcceptedFlair) + p.AcceptedFlair=false; //2015.08.08. + if(!p.IgnoredFlair) + { + p.IgnoredFlair=true; + String flair=p.Flair; //2015.08.08. + PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. + player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); + } + else + player.sendMessage("§cYou already ignored this request.§r"); + break; + } + /*case "reload": //2015.07.20. + DoReload(player); + break;*/ + case "admin": //2015.08.09. + DoAdmin(player, args); + break; + case "nonpresser": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§7(non-pr.)§r"; + break; + case "cantpress": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§r(can't press)§r"; + break; + default: + return false; + } + return true; + } + /*if(args[0].toLowerCase()=="reload") + DoReload(null); //2015.07.20.*/ + else if(args.length>0 && args[0].toLowerCase().equals("admin")) //2015.08.09. + { + DoAdmin(null, args); //2015.08.09. + return true; //2015.08.09. + } + return false; + } + private static void DoReload(Player player) + { //2015.07.20. + //if(player==null || player.isOp() || player.getName()=="NorbiPeti") + //{ + try + { + File file=new File("autoflairconfig.txt"); + if(file.exists()) + { + PluginMain.LoadFiles(true); + 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); + PluginMain.AppendPlayerDisplayFlair(mp, p); //2015.08.09. + } + } + //String msg="§6Reloaded config file.§r"; + String msg="§6Reloaded all files.§r"; + SendMessage(player, msg); //2015.08.09. + } + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + if(player!=null) + player.sendMessage("§cAn error occured. See console for details.§r"); + PluginMain.LastException=e; //2015.08.09. + } + //} + //else + //player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static void DoAdmin(Player player, String[] args) + { //2015.08.09. + if(player==null || player.isOp() || player.getName()=="NorbiPeti") + { + //System.out.println("Args length: " + args.length); + if(args.length==1) + { + String message="§cUsage: /u admin reload|playerinfo§r"; + SendMessage(player, message); + return; + } + //args[0] is "admin" + switch(args[1].toLowerCase()) + { + case "reload": + DoReload(player); + break; + case "playerinfo": + DoPlayerInfo(player, args); + break; + case "getlasterror": + DoGetLastError(player, args); + default: + String message="§cUsage: /u admin reload|playerinfo§r"; + SendMessage(player, message); + return; + } + } + else + player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static void DoPlayerInfo(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "playerinfo" + if(args.length==2) + { + String message="§cUsage: /u admin playerinfo §r"; + SendMessage(player, message); + return; + } + if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2])) + { + String message="§cPlayer not found: "+args[2]+"§r"; + SendMessage(player, message); + return; + } + MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]); + SendMessage(player, "Player name: "+p.PlayerName); + SendMessage(player, "User flair: "+p.Flair); + SendMessage(player, "Username: "+p.UserName); + SendMessage(player, "Flair accepted: "+p.AcceptedFlair); + SendMessage(player, "Flair ignored: "+p.IgnoredFlair); + } + private static void SendMessage(Player player, String message) + { //2015.08.09. + if(player==null) + System.out.println(message); + else + player.sendMessage(message); + } + private static void DoGetLastError(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "getlasterror" + if(PluginMain.LastException!=null) + { + SendMessage(player, "Last error:"); + SendMessage(player, PluginMain.LastException.toString()); + PluginMain.LastException=null; + } + else + SendMessage(player, "There were no exceptions."); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/44/c0bce577873e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/44/c0bce577873e00151ce8ff6d4f74dabd deleted file mode 100644 index 40b9c4f..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/44/c0bce577873e00151ce8ff6d4f74dabd +++ /dev/null @@ -1,145 +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; - MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. - //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - if(p.Flair==null) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. - { - case "accept": - { - if(p.IgnoredFlair) - p.IgnoredFlair=false; //2015.08.08. - if(!p.AcceptedFlair) - { - String flair=p.Flair; //2015.08.08. - PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. - p.AcceptedFlair=true; //2015.08.08. - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("§cYou already have this user's flair.§r"); - break; - } - case "ignore": - { - if(p.AcceptedFlair) - p.AcceptedFlair=false; //2015.08.08. - if(!p.IgnoredFlair) - { - p.IgnoredFlair=true; - String flair=p.Flair; //2015.08.08. - PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. - player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); - } - else - player.sendMessage("§cYou already ignored this request.§r"); - break; - } - /*case "reload": //2015.07.20. - DoReload(player); - break;*/ - case "admin": //2015.08.09. - DoAdmin(player, args); - break; - default: - return false; - } - return true; - } - - /*if(args[0].toLowerCase()=="reload") - DoReload(null); //2015.07.20.*/ - else if(args[0].toLowerCase()=="admin") - DoAdmin(null, args); //2015.08.09. - return false; - } - private static void DoReload(Player player) - { //2015.07.20. - //if(player==null || player.isOp() || player.getName()=="NorbiPeti") - //{ - try - { - File file=new File("autoflairconfig.txt"); - if(file.exists()) - { - PluginMain.TownColors.clear(); - BufferedReader br=new BufferedReader(new FileReader(file)); - String line; - while((line=br.readLine())!=null) - { - String[] s=line.split(" "); - PluginMain.TownColors.put(s[0], s[1]); - } - br.close(); - for(Player p : PluginMain.GetPlayers()) - { - MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName()); - if(mp.Flair!=null) - { - String flair=mp.Flair; - PluginMain.RemovePlayerDisplayFlairFinal(p, flair); - PluginMain.AppendPlayerDisplayFlairFinal(p, flair); - } - } - String msg="§6Reloaded config file.§r"; - if(player!=null) - player.sendMessage(msg); - else - System.out.println(msg); - } - } - catch(Exception e) - { - System.out.println("Error!\n"+e); - if(player!=null) - player.sendMessage("§cAn error occured. See console for details.§r"); - } - //} - //else - //player.sendMessage("§cYou need to be OP to use this command.§r"); - } - private static void DoAdmin(Player player, String[] args) - { - if(player==null || player.isOp() || player.getName()=="NorbiPeti") - { - //args[0] is "admin" - switch(args[1].toLowerCase()) - { - case "reload": - DoReload(player); - break; - case "playerinfo": - DoPlayerInfo(player, args); - break; - } - } - else - player.sendMessage("§cYou need to be OP to use this command.§r"); - } - private static void DoPlayerInfo(Player player, String[] args) - { - //args[0] is "admin" - args[1] is "playerinfo" - s - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/46/a01312cb303e00151cbdba8b5f0a340e b/.metadata/.plugins/org.eclipse.core.resources/.history/46/a01312cb303e00151cbdba8b5f0a340e deleted file mode 100644 index b75c29b..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/46/a01312cb303e00151cbdba8b5f0a340e +++ /dev/null @@ -1,425 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import java.io.BufferedReader; -import java.io.BufferedWriter; -import java.io.File; -import java.io.FileReader; -import java.io.FileWriter; -import java.io.IOException; -import java.io.InputStream; -import java.net.MalformedURLException; -import java.net.URL; -import java.net.URLConnection; -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; -import java.util.Map; - -import org.apache.commons.io.IOUtils; -import org.bukkit.entity.Player; -import org.bukkit.plugin.java.JavaPlugin; -import org.json.JSONArray; -import org.json.JSONObject; - -import com.palmergames.bukkit.towny.object.Town; -import com.palmergames.bukkit.towny.object.TownyUniverse; -import com.palmergames.bukkit.towny.object.WorldCoord; - -public class PluginMain extends JavaPlugin -{ //Translated to Java: 2015.07.15. - //A user, which flair isn't obtainable: - //https://www.reddit.com/r/thebutton/comments/31c32v/i_pressed_the_button_without_really_thinking/ - private static PluginMain Instance; - // Fired when plugin is first enabled - @Override - public void onEnable() - { - System.out.println("The Button Auto-flair Plugin by NorbiPeti (:P)"); - getServer().getPluginManager().registerEvents(new PlayerListener(), this); - //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.PlayerName+"\n"); - bw.close(); - } catch (IOException e) { - System.out.println("Error!\n"+e); - } - } - stop=true; - } - - public void ThreadMethod() //<-- 2015.07.16. - { - /*System.out.println("Sleeping for 5 seconds..."); //2015.07.20. - try { - Thread.sleep(5000); - } catch (InterruptedException e1) { - e1.printStackTrace(); - } //2015.07.20.*/ - while(!stop) - { - try - { - String body=DownloadString("https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/autoflair_system_comment_your_minecraft_name_and/.json?limit=1000"); - JSONArray json=new JSONArray(body).getJSONObject(1).getJSONObject("data").getJSONArray("children"); - for(Object obj : json) - { - JSONObject item = (JSONObject)obj; - String author=item.getJSONObject("data").getString("author"); - String ign=item.getJSONObject("data").getString("body"); - int start = ign.indexOf("IGN:") + "IGN:".length(); - int end = ign.indexOf(' ', start); - if (end == -1 || end == start) - end=ign.indexOf('\n', start); //2015.07.15. - if (end == -1 || end == start) - ign = ign.substring(start); - else - ign = ign.substring(start, end); - ign = ign.trim(); - if(HasIGFlair(ign)) - continue; - //System.out.println("Author: "+author); - try { - Thread.sleep(10); - } catch(InterruptedException ex) { - Thread.currentThread().interrupt(); - } - String[] flairdata = DownloadString("http://karmadecay.com/thebutton-data.php?users=" + author).replace("\"", "").split(":"); - String flair; - if(flairdata.length > 1) //2015.07.15. - flair = flairdata[1]; - else - flair=""; - if (flair != "-1") - flair = flair + "s"; - else - flair = "non-presser"; - String flairclass; - //System.out.println("flairdata.length:"+flairdata.length); - if(flairdata.length>2) - flairclass = flairdata[2]; - else - flairclass="unknown"; - SetFlair(ign, flair, flairclass, author); - } - Thread.sleep(10000); - } - catch(Exception e) - { - System.out.println("Error!\n"+e); - } - } - } - - public String DownloadString(String urlstr) throws MalformedURLException, IOException - { - URL url = new URL(urlstr); - URLConnection con = url.openConnection(); - con.setRequestProperty("User-Agent", "TheButtonAutoFlair"); - InputStream in = con.getInputStream(); - String encoding = con.getContentEncoding(); - encoding = encoding == null ? "UTF-8" : encoding; - String body = IOUtils.toString(in, encoding); - in.close(); - return body; - } - - //It has to store offline player flairs too, therefore it can't use Player object - /*public static Map PlayerFlairs=new HashMap(); - public static Map PlayerUserNames=new HashMap(); - //public Map PlayerFlairs=new HashMap(); - public static ArrayList Players=new ArrayList(); - public static ArrayList AcceptedPlayers=new ArrayList(); //2015.07.16. - public static ArrayList IgnoredPlayers=new ArrayList(); //2015.07.16. - //public static Map PlayerTowns=new HashMap(); //2015.07.20.*/ - public static Map TownColors=new HashMap(); //2015.07.20. - public Boolean HasIGFlair(String playername) - { - /*Player player=null; - for(Player p : Players) - { - if(p.getName()==playername) - { - player=p; - break; - } - } - if(player==null) - return false;*/ - //return PlayerFlairs.containsKey(playername); - //return MaybeOfflinePlayer.AllPlayers.containsKey(playername); - MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. - return p.Flair!=null; //2015.08.08. - } - - public void SetFlair(String playername, String text, String flairclass, String username) - { - String finalflair; - switch(flairclass) - { - case "press-1": - finalflair="§c("+text+")§r"; - break; - case "press-2": - finalflair="§6("+text+")§r"; - break; - case "press-3": - finalflair="§e("+text+")§r"; - break; - case "press-4": - finalflair="§a("+text+")§r"; - break; - case "press-5": - finalflair="§9("+text+")§r"; - break; - case "press-6": - finalflair="§5("+text+")§r"; - break; - case "no-press": - finalflair="§7(non-pr.)§r"; - break; - case "cheater": - finalflair="§5("+text+")§r"; - break; - case "cant-press": //2015.08.08. - finalflair="§r(can't press)§r"; - break; - default: - finalflair=""; - break; - } - if(finalflair.length()==0) //<-- 2015.07.20. - return; - //PlayerFlairs.put(playername, finalflair); - //PlayerUserNames.put(playername, username); - MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. - p.Flair=finalflair; //2015.08.08. - p.UserName=username; //2015.08.08. - /*for(Player player : Players) - { - if(player.getName()==playername) - { - PlayerFlairs.put(player, finalflair); - break; - } - }*/ - //System.out.println("SetFlair - playername: "+playername+" text: "+text+" flairclass: "+flairclass); - System.out.println("Added new flair to "+playername+": "+finalflair); - //for(Player player : Players) - for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08. - { - //System.out.println("Online player: "+player.getName()); - //System.out.println("player.getName ("+player.getName()+") == playername ("+playername+"): "+(player.getName()==playername)); - if(player.getName().equals(playername)) - { - //System.out.println("DisplayName: "+player.getDisplayName()); - //player.setDisplayName(player.getDisplayName()+finalflair); - AppendPlayerDisplayFlair(player, username, finalflair); - //System.out.println("DisplayName: "+player.getDisplayName()); - break; - } - } - } - - public static String GetFlair(Player player) - { //2015.07.16. - //String flair=PlayerFlairs.get(player.getName()); - String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08. - return flair==null ? "" : flair; - } - - public static void AppendPlayerDisplayFlair(Player player, String username, String flair) - { - //if(IgnoredPlayers.contains(player.getName())) - if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).IgnoredFlair) - return; - //if(AcceptedPlayers.contains(player.getName())) - if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).AcceptedFlair) - //player.setDisplayName(player.getDisplayName()+flair); - AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. - else - player.sendMessage("§9Are you Reddit user "+username+"?§r §6Type /u accept or /u ignore§r"); - } - - public static void AppendPlayerDisplayFlairFinal(Player player, String flair) - { //2015.07.20. - //System.out.println("A"); - String color = GetColorForTown(GetPlayerTown(player)); //TO!DO: Multiple colors put on first capital letters - String[] colors = color.substring(1).split("§"); - //String displayname=player.getDisplayName(); - String displayname=player.getName(); //2015.08.08. - ArrayList Positions=new ArrayList<>(); - //System.out.println("B"); - for(int i=0; i=colors.length) - { - //System.out.println("D"); - int x=0; - for(int i=0; i towns = TownyUniverse.getDataSource().getTowns(); - try { - Town town = WorldCoord.parseWorldCoord(player).getTownBlock().getTown(); //TODO - return town.getName(); - } catch (Exception e) { - return ""; - } - } - - public static void RemovePlayerDisplayFlairFinal(Player player, String flair) - { //2015.07.20. - //String color = GetColorForTown(GetPlayerTown(player)); - //String dname=player.getDisplayName(); - //player.setDisplayName(dname.substring(dname.indexOf(color)+3, dname.indexOf(flair))); - //MaybeOfflinePlayer.AllPlayers.get(player.getName()).DisplayName=null; //2015.08.08. - MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair=null; //2015.08.08. - } - - public static Collection GetPlayers() - { - return Instance.getServer().getOnlinePlayers(); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/46/a0e24f1ad43e001518fa86d7ae2a1cf8 b/.metadata/.plugins/org.eclipse.core.resources/.history/46/a0e24f1ad43e001518fa86d7ae2a1cf8 new file mode 100644 index 0000000..678f6a5 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/46/a0e24f1ad43e001518fa86d7ae2a1cf8 @@ -0,0 +1,221 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; + +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class Commands implements CommandExecutor { + // This method is called, when somebody uses our command + @Override + public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { + if (sender instanceof Player) { + Player player = (Player) sender; + if(args.length<1) + return false; + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. + //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) + if(p.Flair==null) + { + player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); + return true; + } + switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. + { + case "accept": + { + if(p.IgnoredFlair) + p.IgnoredFlair=false; //2015.08.08. + if(!p.AcceptedFlair) + { + String flair=p.Flair; //2015.08.08. + //PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + PluginMain.AppendPlayerDisplayFlair(p, player); + p.AcceptedFlair=true; //2015.08.08. + player.sendMessage("§6Your flair has been set:§r "+flair); + } + else + player.sendMessage("§cYou already have this user's flair.§r"); + break; + } + case "ignore": + { + if(p.AcceptedFlair) + p.AcceptedFlair=false; //2015.08.08. + if(!p.IgnoredFlair) + { + p.IgnoredFlair=true; + String flair=p.Flair; //2015.08.08. + PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. + player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); + } + else + player.sendMessage("§cYou already ignored this request.§r"); + break; + } + /*case "reload": //2015.07.20. + DoReload(player); + break;*/ + case "admin": //2015.08.09. + DoAdmin(player, args); + break; + case "nonpresser": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§7(non-pr.)§r"; + break; + case "cantpress": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§r(can't press)§r"; + break; + default: + return false; + } + return true; + } + /*if(args[0].toLowerCase()=="reload") + DoReload(null); //2015.07.20.*/ + else if(args.length>0 && args[0].toLowerCase().equals("admin")) //2015.08.09. + { + DoAdmin(null, args); //2015.08.09. + return true; //2015.08.09. + } + return false; + } + private static void DoReload(Player player) + { //2015.07.20. + //if(player==null || player.isOp() || player.getName()=="NorbiPeti") + //{ + try + { + File file=new File("autoflairconfig.txt"); + if(file.exists()) + { + PluginMain.LoadFiles(true); //2015.08.09. + for(Player p : PluginMain.GetPlayers()) + { + MaybeOfflinePlayer mp = MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName()); + if(mp.Flair!=null) + { + String flair=mp.Flair; + PluginMain.RemovePlayerDisplayFlairFinal(p, flair); + //PluginMain.AppendPlayerDisplayFlairFinal(p, flair); + PluginMain.AppendPlayerDisplayFlair(mp, p); //2015.08.09. + } + String msg="§6Note: The auto-flair plugin has been reloaded. You might need to wait 10s to have your flair.§r"; //2015.08.09. + p.sendMessage(msg); //2015.08.09. + } + //String msg="§6Reloaded config file.§r"; + //SendMessage(player, msg); //2015.08.09. + } + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + if(player!=null) + player.sendMessage("§cAn error occured. See console for details.§r"); + PluginMain.LastException=e; //2015.08.09. + } + //} + //else + //player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static Player ReloadPlayer; //2015.08.09. + private static void DoAdmin(Player player, String[] args) + { //2015.08.09. + if(player==null || player.isOp() || player.getName()=="NorbiPeti") + { + //System.out.println("Args length: " + args.length); + if(args.length==1) + { + String message="§cUsage: /u admin reload|playerinfo§r"; + SendMessage(player, message); + return; + } + //args[0] is "admin" + switch(args[1].toLowerCase()) + { + case "reload": + + SendMessage(player, "§6Make sure to save the current settings before you modify and reload them! Type /u admin confirm when done."); + break; + case "playerinfo": + DoPlayerInfo(player, args); + break; + case "getlasterror": + DoGetLastError(player, args); + case "confirm": + DoReload(player); //2015.08.09. + break; + default: + String message="§cUsage: /u admin reload|playerinfo§r"; + SendMessage(player, message); + return; + } + } + else + player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static void DoPlayerInfo(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "playerinfo" + if(args.length==2) + { + String message="§cUsage: /u admin playerinfo §r"; + SendMessage(player, message); + return; + } + if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2])) + { + String message="§cPlayer not found: "+args[2]+"§r"; + SendMessage(player, message); + return; + } + MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]); + SendMessage(player, "Player name: "+p.PlayerName); + SendMessage(player, "User flair: "+p.Flair); + SendMessage(player, "Username: "+p.UserName); + SendMessage(player, "Flair accepted: "+p.AcceptedFlair); + SendMessage(player, "Flair ignored: "+p.IgnoredFlair); + } + private static void SendMessage(Player player, String message) + { //2015.08.09. + if(player==null) + System.out.println(message); + else + player.sendMessage(message); + } + private static void DoGetLastError(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "getlasterror" + if(PluginMain.LastException!=null) + { + SendMessage(player, "Last error:"); + SendMessage(player, PluginMain.LastException.toString()); + PluginMain.LastException=null; + } + else + SendMessage(player, "There were no exceptions."); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/47/209354bad13e001518fa86d7ae2a1cf8 b/.metadata/.plugins/org.eclipse.core.resources/.history/47/209354bad13e001518fa86d7ae2a1cf8 new file mode 100644 index 0000000..1a55983 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/47/209354bad13e001518fa86d7ae2a1cf8 @@ -0,0 +1,370 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStream; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLConnection; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + +import org.apache.commons.io.IOUtils; +import org.bukkit.entity.Player; +import org.bukkit.plugin.java.JavaPlugin; +import org.json.JSONArray; +import org.json.JSONObject; + +import com.palmergames.bukkit.towny.object.Town; +import com.palmergames.bukkit.towny.object.WorldCoord; + +public class PluginMain extends JavaPlugin +{ //Translated to Java: 2015.07.15. + //A user, which flair isn't obtainable: + //https://www.reddit.com/r/thebutton/comments/31c32v/i_pressed_the_button_without_really_thinking/ + private static PluginMain Instance; + // Fired when plugin is first enabled + @Override + public void onEnable() + { + System.out.println("The Button Auto-flair Plugin by NorbiPeti (:P)"); + getServer().getPluginManager().registerEvents(new PlayerListener(), this); + this.getCommand("u").setExecutor(new Commands()); + this.getCommand("u").setUsage(this.getCommand("u").getUsage().replace('&', '§')); + Instance=this; //2015.08.08. + LoadFiles(false); //2015.08.09. + Runnable r=new Runnable(){public void run(){ThreadMethod();}}; + Thread t=new Thread(r); + t.start(); + } + Boolean stop=false; + // Fired when plugin is disabled + @Override + public void onDisable() + { + try + { + FileWriter fw; + fw = new FileWriter("flairsaccepted.txt"); + fw.close(); + fw = new FileWriter("flairsignored.txt"); + fw.close(); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + try { + File file=new File("flairsaccepted.txt"); + BufferedWriter bw=new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.AcceptedFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + file=new File("flairsignored.txt"); + bw = new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.IgnoredFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + stop=true; + } + + public void ThreadMethod() //<-- 2015.07.16. + { + while(!stop) + { + try + { + String body=DownloadString("https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/autoflair_system_comment_your_minecraft_name_and/.json?limit=1000"); + JSONArray json=new JSONArray(body).getJSONObject(1).getJSONObject("data").getJSONArray("children"); + for(Object obj : json) + { + JSONObject item = (JSONObject)obj; + String author=item.getJSONObject("data").getString("author"); + String ign=item.getJSONObject("data").getString("body"); + int start = ign.indexOf("IGN:") + "IGN:".length(); + int end = ign.indexOf(' ', start); + if (end == -1 || end == start) + end=ign.indexOf('\n', start); //2015.07.15. + if (end == -1 || end == start) + ign = ign.substring(start); + else + ign = ign.substring(start, end); + ign = ign.trim(); + if(HasIGFlair(ign)) + continue; + try { + Thread.sleep(10); + } catch(InterruptedException ex) { + Thread.currentThread().interrupt(); + } + String[] flairdata = DownloadString("http://karmadecay.com/thebutton-data.php?users=" + author).replace("\"", "").split(":"); + String flair; + if(flairdata.length > 1) //2015.07.15. + flair = flairdata[1]; + else + flair=""; + if (flair != "-1") + flair = flair + "s"; + else + flair = "non-presser"; + String flairclass; + if(flairdata.length>2) + flairclass = flairdata[2]; + else + flairclass="unknown"; + SetFlair(ign, flair, flairclass, author); + } + Thread.sleep(10000); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + } + + public static Exception LastException; //2015.08.09. + + public String DownloadString(String urlstr) throws MalformedURLException, IOException + { + URL url = new URL(urlstr); + URLConnection con = url.openConnection(); + con.setRequestProperty("User-Agent", "TheButtonAutoFlair"); + InputStream in = con.getInputStream(); + String encoding = con.getContentEncoding(); + encoding = encoding == null ? "UTF-8" : encoding; + String body = IOUtils.toString(in, encoding); + in.close(); + return body; + } + + public static Map TownColors=new HashMap(); //2015.07.20. + public Boolean HasIGFlair(String playername) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + return p.Flair!=null; //2015.08.08. + } + + public void SetFlair(String playername, String text, String flairclass, String username) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + String finalflair; + p.FlairDecided=true; + switch(flairclass) + { + case "press-1": + finalflair="§c("+text+")§r"; + break; + case "press-2": + finalflair="§6("+text+")§r"; + break; + case "press-3": + finalflair="§e("+text+")§r"; + break; + case "press-4": + finalflair="§a("+text+")§r"; + break; + case "press-5": + finalflair="§9("+text+")§r"; + break; + 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; + case "undecided": //2015.08.09. + p.FlairDecided=false; + finalflair=""; + break; + default: + finalflair=""; + break; + } + if(finalflair.length()==0) //<-- 2015.07.20. + return; + p.Flair=finalflair; //2015.08.08. + p.UserName=username; //2015.08.08. + System.out.println("Added new flair to "+playername+": "+finalflair); + for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08. + { + if(player.getName().equals(playername)) + { + //AppendPlayerDisplayFlair(player, username, finalflair); + AppendPlayerDisplayFlair(p, player); + break; + } + } + } + + public static String GetFlair(Player player) + { //2015.07.16. + String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08. + return flair==null ? "" : flair; + } + + //public static void AppendPlayerDisplayFlair(Player player, String username, String flair) + public static void AppendPlayerDisplayFlair(MaybeOfflinePlayer player, Player p) //<-- 2015.08.09. + { + + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).IgnoredFlair) + return; + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).AcceptedFlair) + { + AppendPlayerDisplayFlairFinal(p, player.Flair); //2015.07.20. + if(!player.FlairDecided) + p.sendMessage("§9Your flair type is unknown. Are you a non-presser or a can't press? (/u nonpresser or /u cantpress)§r"); //2015.08.09. + } + else + p.sendMessage("§9Are you Reddit user "+player.UserName+"?§r §6Type /u accept or /u ignore§r"); + } + + private static void AppendPlayerDisplayFlairFinal(Player player, String flair) + { //2015.07.20. + String color = GetColorForTown(GetPlayerTown(player)); //TO!DO: Multiple colors put on first capital letters + String[] colors = color.substring(1).split("§"); + String displayname=player.getName(); //2015.08.08. + ArrayList Positions=new ArrayList<>(); + for(int i=0; i=colors.length) + { + int x=0; + for(int i=0; i GetPlayers() + { + return Instance.getServer().getOnlinePlayers(); + } + + public static void LoadFiles(boolean reload) + { + if(reload) + MaybeOfflinePlayer.AllPlayers.clear(); //2015.08.09. + try { + File file=new File("flairsaccepted.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + //System.out.println("Name: " + name); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("flairsignored.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsignored.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("autoflairconfig.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + TownColors.put(s[0], s[1]); + } + br.close(); + } + //throw new IOException("Test"); //2015.08.09. + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/47/20a74d8ad13e001518fa86d7ae2a1cf8 b/.metadata/.plugins/org.eclipse.core.resources/.history/47/20a74d8ad13e001518fa86d7ae2a1cf8 new file mode 100644 index 0000000..c0e1cef --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/47/20a74d8ad13e001518fa86d7ae2a1cf8 @@ -0,0 +1,368 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStream; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLConnection; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + +import org.apache.commons.io.IOUtils; +import org.bukkit.entity.Player; +import org.bukkit.plugin.java.JavaPlugin; +import org.json.JSONArray; +import org.json.JSONObject; + +import com.palmergames.bukkit.towny.object.Town; +import com.palmergames.bukkit.towny.object.WorldCoord; + +public class PluginMain extends JavaPlugin +{ //Translated to Java: 2015.07.15. + //A user, which flair isn't obtainable: + //https://www.reddit.com/r/thebutton/comments/31c32v/i_pressed_the_button_without_really_thinking/ + private static PluginMain Instance; + // Fired when plugin is first enabled + @Override + public void onEnable() + { + System.out.println("The Button Auto-flair Plugin by NorbiPeti (:P)"); + getServer().getPluginManager().registerEvents(new PlayerListener(), this); + this.getCommand("u").setExecutor(new Commands()); + this.getCommand("u").setUsage(this.getCommand("u").getUsage().replace('&', '§')); + Instance=this; //2015.08.08. + try { + File file=new File("flairsaccepted.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + //System.out.println("Name: " + name); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("flairsignored.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsignored.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("autoflairconfig.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + TownColors.put(s[0], s[1]); + } + br.close(); + } + //throw new IOException("Test"); //2015.08.09. + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + Runnable r=new Runnable(){public void run(){ThreadMethod();}}; + Thread t=new Thread(r); + t.start(); + } + Boolean stop=false; + // Fired when plugin is disabled + @Override + public void onDisable() + { + try + { + FileWriter fw; + fw = new FileWriter("flairsaccepted.txt"); + fw.close(); + fw = new FileWriter("flairsignored.txt"); + fw.close(); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + try { + File file=new File("flairsaccepted.txt"); + BufferedWriter bw=new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.AcceptedFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + file=new File("flairsignored.txt"); + bw = new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.IgnoredFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + stop=true; + } + + public void ThreadMethod() //<-- 2015.07.16. + { + while(!stop) + { + try + { + String body=DownloadString("https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/autoflair_system_comment_your_minecraft_name_and/.json?limit=1000"); + JSONArray json=new JSONArray(body).getJSONObject(1).getJSONObject("data").getJSONArray("children"); + for(Object obj : json) + { + JSONObject item = (JSONObject)obj; + String author=item.getJSONObject("data").getString("author"); + String ign=item.getJSONObject("data").getString("body"); + int start = ign.indexOf("IGN:") + "IGN:".length(); + int end = ign.indexOf(' ', start); + if (end == -1 || end == start) + end=ign.indexOf('\n', start); //2015.07.15. + if (end == -1 || end == start) + ign = ign.substring(start); + else + ign = ign.substring(start, end); + ign = ign.trim(); + if(HasIGFlair(ign)) + continue; + try { + Thread.sleep(10); + } catch(InterruptedException ex) { + Thread.currentThread().interrupt(); + } + String[] flairdata = DownloadString("http://karmadecay.com/thebutton-data.php?users=" + author).replace("\"", "").split(":"); + String flair; + if(flairdata.length > 1) //2015.07.15. + flair = flairdata[1]; + else + flair=""; + if (flair != "-1") + flair = flair + "s"; + else + flair = "non-presser"; + String flairclass; + if(flairdata.length>2) + flairclass = flairdata[2]; + else + flairclass="unknown"; + SetFlair(ign, flair, flairclass, author); + } + Thread.sleep(10000); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + } + + public static Exception LastException; //2015.08.09. + + public String DownloadString(String urlstr) throws MalformedURLException, IOException + { + URL url = new URL(urlstr); + URLConnection con = url.openConnection(); + con.setRequestProperty("User-Agent", "TheButtonAutoFlair"); + InputStream in = con.getInputStream(); + String encoding = con.getContentEncoding(); + encoding = encoding == null ? "UTF-8" : encoding; + String body = IOUtils.toString(in, encoding); + in.close(); + return body; + } + + public static Map TownColors=new HashMap(); //2015.07.20. + public Boolean HasIGFlair(String playername) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + return p.Flair!=null; //2015.08.08. + } + + public void SetFlair(String playername, String text, String flairclass, String username) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + String finalflair; + p.FlairDecided=true; + switch(flairclass) + { + case "press-1": + finalflair="§c("+text+")§r"; + break; + case "press-2": + finalflair="§6("+text+")§r"; + break; + case "press-3": + finalflair="§e("+text+")§r"; + break; + case "press-4": + finalflair="§a("+text+")§r"; + break; + case "press-5": + finalflair="§9("+text+")§r"; + break; + 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; + case "undecided": //2015.08.09. + p.FlairDecided=false; + finalflair=""; + break; + default: + finalflair=""; + break; + } + if(finalflair.length()==0) //<-- 2015.07.20. + return; + p.Flair=finalflair; //2015.08.08. + p.UserName=username; //2015.08.08. + System.out.println("Added new flair to "+playername+": "+finalflair); + for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08. + { + if(player.getName().equals(playername)) + { + //AppendPlayerDisplayFlair(player, username, finalflair); + AppendPlayerDisplayFlair(p, player); + break; + } + } + } + + public static String GetFlair(Player player) + { //2015.07.16. + String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08. + return flair==null ? "" : flair; + } + + //public static void AppendPlayerDisplayFlair(Player player, String username, String flair) + public static void AppendPlayerDisplayFlair(MaybeOfflinePlayer player, Player p) //<-- 2015.08.09. + { + + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).IgnoredFlair) + return; + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).AcceptedFlair) + { + AppendPlayerDisplayFlairFinal(p, player.Flair); //2015.07.20. + if(!player.FlairDecided) + p.sendMessage("§9Your flair type is unknown. Are you a non-presser or a can't press? (/u nonpresser or /u cantpress)§r"); //2015.08.09. + } + else + p.sendMessage("§9Are you Reddit user "+player.UserName+"?§r §6Type /u accept or /u ignore§r"); + } + + private static void AppendPlayerDisplayFlairFinal(Player player, String flair) + { //2015.07.20. + String color = GetColorForTown(GetPlayerTown(player)); //TO!DO: Multiple colors put on first capital letters + String[] colors = color.substring(1).split("§"); + String displayname=player.getName(); //2015.08.08. + ArrayList Positions=new ArrayList<>(); + for(int i=0; i=colors.length) + { + int x=0; + for(int i=0; i GetPlayers() + { + return Instance.getServer().getOnlinePlayers(); + } + + public static void LoadFiles(boolean reload) + { + + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/48/00204eb0de3e001517108d149b613203 b/.metadata/.plugins/org.eclipse.core.resources/.history/48/00204eb0de3e001517108d149b613203 new file mode 100644 index 0000000..8f9b87a --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/48/00204eb0de3e001517108d149b613203 @@ -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.WorldCoord; + +public class PluginMain extends JavaPlugin +{ //Translated to Java: 2015.07.15. + //A user, which flair isn't obtainable: + //https://www.reddit.com/r/thebutton/comments/31c32v/i_pressed_the_button_without_really_thinking/ + private static PluginMain Instance; + // Fired when plugin is first enabled + @Override + public void onEnable() + { + System.out.println("The Button Auto-flair Plugin by NorbiPeti (:P)"); + getServer().getPluginManager().registerEvents(new PlayerListener(), this); + this.getCommand("u").setExecutor(new Commands()); + this.getCommand("u").setUsage(this.getCommand("u").getUsage().replace('&', '§')); + Instance=this; //2015.08.08. + LoadFiles(false); //2015.08.09. + Runnable r=new Runnable(){public void run(){ThreadMethod();}}; + Thread t=new Thread(r); + t.start(); + } + Boolean stop=false; + // Fired when plugin is disabled + @Override + public void onDisable() + { + SaveFiles(); //2015.08.09. + stop=true; + } + + public void ThreadMethod() //<-- 2015.07.16. + { + while(!stop) + { + try + { + String body=DownloadString("https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/autoflair_system_comment_your_minecraft_name_and/.json?limit=1000"); + JSONArray json=new JSONArray(body).getJSONObject(1).getJSONObject("data").getJSONArray("children"); + for(Object obj : json) + { + JSONObject item = (JSONObject)obj; + String author=item.getJSONObject("data").getString("author"); + String ign=item.getJSONObject("data").getString("body"); + int start = ign.indexOf("IGN:") + "IGN:".length(); + if(start==-1) + continue; //2015.08.09. + int end = ign.indexOf(' ', start); + if (end == -1 || end == start) + end=ign.indexOf('\n', start); //2015.07.15. + if (end == -1 || end == start) + ign = ign.substring(start); + else + ign = ign.substring(start, end); + ign = ign.trim(); + if(HasIGFlair(ign)) + continue; + try { + Thread.sleep(10); + } catch(InterruptedException ex) { + Thread.currentThread().interrupt(); + } + String[] flairdata = DownloadString("http://karmadecay.com/thebutton-data.php?users=" + author).replace("\"", "").split(":"); + String flair; + if(flairdata.length > 1) //2015.07.15. + flair = flairdata[1]; + else + flair=""; + if (flair != "-1") + flair = flair + "s"; + else + flair = "non-presser"; + String flairclass; + if(flairdata.length>2) + flairclass = flairdata[2]; + else + flairclass="unknown"; + SetFlair(ign, flair, flairclass, author); + } + Thread.sleep(10000); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + } + + public static Exception LastException; //2015.08.09. + + public String DownloadString(String urlstr) throws MalformedURLException, IOException + { + URL url = new URL(urlstr); + URLConnection con = url.openConnection(); + con.setRequestProperty("User-Agent", "TheButtonAutoFlair"); + InputStream in = con.getInputStream(); + String encoding = con.getContentEncoding(); + encoding = encoding == null ? "UTF-8" : encoding; + String body = IOUtils.toString(in, encoding); + in.close(); + return body; + } + + public static Map TownColors=new HashMap(); //2015.07.20. + public Boolean HasIGFlair(String playername) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + return p.Flair!=null; //2015.08.08. + } + + public void SetFlair(String playername, String text, String flairclass, String username) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + String finalflair; + p.FlairDecided=true; + switch(flairclass) + { + case "press-1": + finalflair="§c("+text+")§r"; + break; + case "press-2": + finalflair="§6("+text+")§r"; + break; + case "press-3": + finalflair="§e("+text+")§r"; + break; + case "press-4": + finalflair="§a("+text+")§r"; + break; + case "press-5": + finalflair="§9("+text+")§r"; + break; + 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; + case "undecided": //2015.08.09. + p.FlairDecided=false; + finalflair=""; + break; + default: + finalflair=""; + break; + } + if(finalflair.length()==0) //<-- 2015.07.20. + return; + p.Flair=finalflair; //2015.08.08. + p.UserName=username; //2015.08.08. + System.out.println("Added new flair to "+playername+": "+finalflair); + for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08. + { + if(player.getName().equals(playername)) + { + //AppendPlayerDisplayFlair(player, username, finalflair); + AppendPlayerDisplayFlair(p, player); + break; + } + } + } + + public static String GetFlair(Player player) + { //2015.07.16. + String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08. + return flair==null ? "" : flair; + } + + //public static void AppendPlayerDisplayFlair(Player player, String username, String flair) + public static void AppendPlayerDisplayFlair(MaybeOfflinePlayer player, Player p) //<-- 2015.08.09. + { + + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).IgnoredFlair) + return; + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).AcceptedFlair) + { + AppendPlayerDisplayFlairFinal(p, player.Flair); //2015.07.20. + if(!player.FlairDecided) + p.sendMessage("§9Your flair type is unknown. Are you a non-presser or a can't press? (/u nonpresser or /u cantpress)§r"); //2015.08.09. + } + else + p.sendMessage("§9Are you Reddit user "+player.UserName+"?§r §6Type /u accept or /u ignore§r"); + } + + private static void AppendPlayerDisplayFlairFinal(Player player, String flair) + { //2015.07.20. + String color = GetColorForTown(GetPlayerTown(player)); //TO!DO: Multiple colors put on first capital letters + String[] colors = color.substring(1).split("§"); + String displayname=player.getName(); //2015.08.08. + ArrayList Positions=new ArrayList<>(); + for(int i=0; i=colors.length) + { + int x=0; + for(int i=0; i GetPlayers() + { + return Instance.getServer().getOnlinePlayers(); + } + + public static void LoadFiles(boolean reload) //<-- 2015.08.09. + { + if(reload) + { //2015.08.09. + System.out.println("Auto-flair plugin cleanup for reloading..."); + MaybeOfflinePlayer.AllPlayers.clear(); + TownColors.clear(); + } + System.out.println("Loading files for auto-flair plugin..."); //2015.08.09. + try { + File file=new File("flairsaccepted.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + //System.out.println("Name: " + name); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("flairsignored.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsignored.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("autoflairconfig.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + TownColors.put(s[0], s[1]); + } + br.close(); + } + file=new File("customflairs.txt"); //2015.08.09. + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + MaybeOfflinePlayer.AddPlayerIfNeeded(s[0]).Flair=s[1]; //2015.08.09. + } + br.close(); + } + //throw new IOException("Test"); //2015.08.09. + System.out.println("Auto-flair plugin loaded files!"); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + public static void SaveFiles() //<-- 2015.08.09. + { + try + { + FileWriter fw; + fw = new FileWriter("flairsaccepted.txt"); + fw.close(); + fw = new FileWriter("flairsignored.txt"); + fw.close(); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + try { + File file=new File("flairsaccepted.txt"); + BufferedWriter bw=new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.AcceptedFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + file=new File("flairsignored.txt"); + bw = new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.IgnoredFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + public static void SetPlayerFlair(Player player, String flair) + { //2015.08.09. + flair=flair.replace('&', '§'); + MaybeOfflinePlayer.AddPlayerIfNeeded(player.getName()).Flair=flair; + File file=new File("customflairs.txt"); + try { + BufferedWriter bw; + bw = new BufferedWriter(new FileWriter(file, true)); + bw.write(player.getName()+"\n"); + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + public static bool RemoveLineFromFile(String file) + { + File inputFile = new File(file); + File tempFile = new File("_temp.txt"); + + try { + BufferedReader reader = new BufferedReader(new FileReader(inputFile)); + BufferedWriter writer = new BufferedWriter(new FileWriter(tempFile)); + + String lineToRemove = "bbb"; + String currentLine; + + while((currentLine = reader.readLine()) != null) { + // trim newline when comparing with lineToRemove + String trimmedLine = currentLine.trim(); + if(trimmedLine.equals(lineToRemove)) continue; + writer.write(currentLine + System.getProperty("line.separator")); + } + writer.close(); + reader.close(); + tempFile.renameTo(inputFile); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + return false; + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/48/10d650b8e03e001517108d149b613203 b/.metadata/.plugins/org.eclipse.core.resources/.history/48/10d650b8e03e001517108d149b613203 new file mode 100644 index 0000000..6ad1625 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/48/10d650b8e03e001517108d149b613203 @@ -0,0 +1,264 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +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; + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. + //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) + if(p.Flair==null) + { + player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); + return true; + } + switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. + { + case "accept": + { + if(p.IgnoredFlair) + p.IgnoredFlair=false; //2015.08.08. + if(!p.AcceptedFlair) + { + String flair=p.Flair; //2015.08.08. + //PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + PluginMain.AppendPlayerDisplayFlair(p, player); + p.AcceptedFlair=true; //2015.08.08. + player.sendMessage("§6Your flair has been set:§r "+flair); + } + else + player.sendMessage("§cYou already have this user's flair.§r"); + break; + } + case "ignore": + { + if(p.AcceptedFlair) + p.AcceptedFlair=false; //2015.08.08. + if(!p.IgnoredFlair) + { + p.IgnoredFlair=true; + String flair=p.Flair; //2015.08.08. + PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. + player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); + } + else + player.sendMessage("§cYou already ignored this request.§r"); + break; + } + /*case "reload": //2015.07.20. + DoReload(player); + break;*/ + case "admin": //2015.08.09. + DoAdmin(player, args); + break; + case "nonpresser": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§7(non-pr.)§r"; + break; + case "cantpress": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§r(can't press)§r"; + break; + default: + return false; + } + return true; + } + /*if(args[0].toLowerCase()=="reload") + DoReload(null); //2015.07.20.*/ + else if(args.length>0 && args[0].toLowerCase().equals("admin")) //2015.08.09. + { + DoAdmin(null, args); //2015.08.09. + return true; //2015.08.09. + } + return false; + } + private static void DoReload(Player player) + { //2015.07.20. + //if(player==null || player.isOp() || player.getName()=="NorbiPeti") + //{ + try + { + File file=new File("autoflairconfig.txt"); + if(file.exists()) + { + PluginMain.LoadFiles(true); //2015.08.09. + for(Player p : PluginMain.GetPlayers()) + { + MaybeOfflinePlayer mp = MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName()); + if(mp.Flair!=null) + { + String flair=mp.Flair; + PluginMain.RemovePlayerDisplayFlairFinal(p, flair); + //PluginMain.AppendPlayerDisplayFlairFinal(p, flair); + PluginMain.AppendPlayerDisplayFlair(mp, p); //2015.08.09. + } + String msg="§6Note: The auto-flair plugin has been reloaded. You might need to wait 10s to have your flair.§r"; //2015.08.09. + p.sendMessage(msg); //2015.08.09. + } + //String msg="§6Reloaded config file.§r"; + //SendMessage(player, msg); //2015.08.09. + } + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + if(player!=null) + player.sendMessage("§cAn error occured. See console for details.§r"); + PluginMain.LastException=e; //2015.08.09. + } + //} + //else + //player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static Player ReloadPlayer; //2015.08.09. + private static void DoAdmin(Player player, String[] args) + { //2015.08.09. + if(player==null || player.isOp() || player.getName()=="NorbiPeti") + { + //System.out.println("Args length: " + args.length); + if(args.length==1) + { + String message="§cUsage: /u admin reload|playerinfo§r"; + SendMessage(player, message); + return; + } + //args[0] is "admin" + switch(args[1].toLowerCase()) + { + case "reload": + ReloadPlayer=player; //2015.08.09. + SendMessage(player, "§6Make sure to save the current settings before you modify and reload them! Type /u admin confirm when done.§r"); + break; + case "playerinfo": + DoPlayerInfo(player, args); + break; + case "getlasterror": + DoGetLastError(player, args); + case "confirm": + if(ReloadPlayer==player) + DoReload(player); //2015.08.09. + else + SendMessage(player, "§cYou need to do /u admin reload first.§r"); + break; + case "save": + PluginMain.SaveFiles(); //2015.08.09. + SendMessage(player, "§6Saved files. Now you can edit them and reload if you want.§r"); + break; + case "setflair": + + break; + default: + String message="§cUsage: /u admin reload|playerinfo|getlasterror|save§r"; + SendMessage(player, message); + return; + } + } + else + player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static void DoPlayerInfo(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "playerinfo" + if(args.length==2) + { + String message="§cUsage: /u admin playerinfo §r"; + SendMessage(player, message); + return; + } + if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2])) + { + String message="§cPlayer not found: "+args[2]+"§r"; + SendMessage(player, message); + return; + } + MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]); + SendMessage(player, "Player name: "+p.PlayerName); + SendMessage(player, "User flair: "+p.Flair); + SendMessage(player, "Username: "+p.UserName); + SendMessage(player, "Flair accepted: "+p.AcceptedFlair); + SendMessage(player, "Flair ignored: "+p.IgnoredFlair); + } + private static void SendMessage(Player player, String message) + { //2015.08.09. + if(player==null) + System.out.println(message); + else + player.sendMessage(message); + } + private static void DoGetLastError(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "getlasterror" + if(PluginMain.LastException!=null) + { + SendMessage(player, "Last error:"); + SendMessage(player, PluginMain.LastException.toString()); + PluginMain.LastException=null; + } + else + SendMessage(player, "There were no exceptions."); + } + private static void SetPlayerFlair(Player player, Player targetplayer, String flair) + { //2015.08.09. + flair=flair.replace('&', '§'); + MaybeOfflinePlayer.AddPlayerIfNeeded(player.getName()).Flair=flair; + if(!PluginMain.RemoveLineFromFile("customflairs.txt", targetplayer.getName())) + { + SendMessage(player, "§cError removing previous custom flair!§r"); + return; + } + File file=new File("customflairs.txt"); + try { + BufferedWriter bw; + bw = new BufferedWriter(new FileWriter(file, true)); + bw.write(targetplayer.getName()+"\n"); + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + PluginMain.LastException=e; //2015.08.09. + } + SendMessage(player, "§6The flair has been set. Player: "+targetplayer.getName()+" Flair: "+flair+"§r"); + } + private static void DoSetFlair(Player player, String args) + { + //args[0] is "admin" - args[1] is "setflair" + if(args.length()<4) + { + SendMessage(player, "§cUsage: /u admin setflair "); + return; + } + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/48/60516d96843e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/48/60516d96843e00151ce8ff6d4f74dabd deleted file mode 100644 index 55d1b29..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/48/60516d96843e00151ce8ff6d4f74dabd +++ /dev/null @@ -1,117 +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; - MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. - //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - if(p.Flair==null) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - { - if(p.IgnoredFlair) - p.IgnoredFlair=false; //2015.08.08. - if(!p.AcceptedFlair) - { - String flair=p.Flair; //2015.08.08. - PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. - p.AcceptedFlair=true; //2015.08.08. - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("§cYou already have this user's flair.§r"); - break; - } - case "ignore": - { - if(p.AcceptedFlair) - p.AcceptedFlair=false; //2015.08.08. - if(!p.IgnoredFlair) - { - p.IgnoredFlair=true; - String flair=p.Flair; //2015.08.08. - PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. - player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); - } - else - player.sendMessage("§cYou already ignored this request.§r"); - break; - } - case "reload": //2015.07.20. - DoReload(player); - break; - default: - return false; - } - return true; - } - - if(args[0]=="reload") - DoReload(null); //2015.07.20. - return false; - } - private static void DoReload(Player player) - { //2015.07.20. - if(player==null || player.isOp()) - { - try - { - File file=new File("autoflairconfig.txt"); - if(file.exists()) - { - PluginMain.TownColors.clear(); - BufferedReader br=new BufferedReader(new FileReader(file)); - String line; - while((line=br.readLine())!=null) - { - String[] s=line.split(" "); - PluginMain.TownColors.put(s[0], s[1]); - } - br.close(); - for(Player p : PluginMain.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/49/203c0b4ad33e001518fa86d7ae2a1cf8 b/.metadata/.plugins/org.eclipse.core.resources/.history/49/203c0b4ad33e001518fa86d7ae2a1cf8 new file mode 100644 index 0000000..1cec033 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/49/203c0b4ad33e001518fa86d7ae2a1cf8 @@ -0,0 +1,215 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; + +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class Commands implements CommandExecutor { + // This method is called, when somebody uses our command + @Override + public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { + if (sender instanceof Player) { + Player player = (Player) sender; + if(args.length<1) + return false; + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. + //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) + if(p.Flair==null) + { + player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); + return true; + } + switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. + { + case "accept": + { + if(p.IgnoredFlair) + p.IgnoredFlair=false; //2015.08.08. + if(!p.AcceptedFlair) + { + String flair=p.Flair; //2015.08.08. + //PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + PluginMain.AppendPlayerDisplayFlair(p, player); + p.AcceptedFlair=true; //2015.08.08. + player.sendMessage("§6Your flair has been set:§r "+flair); + } + else + player.sendMessage("§cYou already have this user's flair.§r"); + break; + } + case "ignore": + { + if(p.AcceptedFlair) + p.AcceptedFlair=false; //2015.08.08. + if(!p.IgnoredFlair) + { + p.IgnoredFlair=true; + String flair=p.Flair; //2015.08.08. + PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. + player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); + } + else + player.sendMessage("§cYou already ignored this request.§r"); + break; + } + /*case "reload": //2015.07.20. + DoReload(player); + break;*/ + case "admin": //2015.08.09. + DoAdmin(player, args); + break; + case "nonpresser": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§7(non-pr.)§r"; + break; + case "cantpress": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§r(can't press)§r"; + break; + default: + return false; + } + return true; + } + /*if(args[0].toLowerCase()=="reload") + DoReload(null); //2015.07.20.*/ + else if(args.length>0 && args[0].toLowerCase().equals("admin")) //2015.08.09. + { + DoAdmin(null, args); //2015.08.09. + return true; //2015.08.09. + } + return false; + } + private static void DoReload(Player player) + { //2015.07.20. + //if(player==null || player.isOp() || player.getName()=="NorbiPeti") + //{ + try + { + File file=new File("autoflairconfig.txt"); + if(file.exists()) + { + PluginMain.LoadFiles(true); //2015.08.09. + for(Player p : PluginMain.GetPlayers()) + { + MaybeOfflinePlayer mp = MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName()); + if(mp.Flair!=null) + { + String flair=mp.Flair; + PluginMain.RemovePlayerDisplayFlairFinal(p, flair); + //PluginMain.AppendPlayerDisplayFlairFinal(p, flair); + PluginMain.AppendPlayerDisplayFlair(mp, p); //2015.08.09. + } + String msg="§6Note: The auto-flair plugin has been reloaded. You might need to wait 10s to have your flair.§r"; + } + //String msg="§6Reloaded config file.§r"; + //SendMessage(player, msg); //2015.08.09. + } + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + if(player!=null) + player.sendMessage("§cAn error occured. See console for details.§r"); + PluginMain.LastException=e; //2015.08.09. + } + //} + //else + //player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static void DoAdmin(Player player, String[] args) + { //2015.08.09. + if(player==null || player.isOp() || player.getName()=="NorbiPeti") + { + //System.out.println("Args length: " + args.length); + if(args.length==1) + { + String message="§cUsage: /u admin reload|playerinfo§r"; + SendMessage(player, message); + return; + } + //args[0] is "admin" + switch(args[1].toLowerCase()) + { + case "reload": + DoReload(player); + break; + case "playerinfo": + DoPlayerInfo(player, args); + break; + case "getlasterror": + DoGetLastError(player, args); + default: + String message="§cUsage: /u admin reload|playerinfo§r"; + SendMessage(player, message); + return; + } + } + else + player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static void DoPlayerInfo(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "playerinfo" + if(args.length==2) + { + String message="§cUsage: /u admin playerinfo §r"; + SendMessage(player, message); + return; + } + if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2])) + { + String message="§cPlayer not found: "+args[2]+"§r"; + SendMessage(player, message); + return; + } + MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]); + SendMessage(player, "Player name: "+p.PlayerName); + SendMessage(player, "User flair: "+p.Flair); + SendMessage(player, "Username: "+p.UserName); + SendMessage(player, "Flair accepted: "+p.AcceptedFlair); + SendMessage(player, "Flair ignored: "+p.IgnoredFlair); + } + private static void SendMessage(Player player, String message) + { //2015.08.09. + if(player==null) + System.out.println(message); + else + player.sendMessage(message); + } + private static void DoGetLastError(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "getlasterror" + if(PluginMain.LastException!=null) + { + SendMessage(player, "Last error:"); + SendMessage(player, PluginMain.LastException.toString()); + PluginMain.LastException=null; + } + else + SendMessage(player, "There were no exceptions."); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/49/a04d8dc3d23e001518fa86d7ae2a1cf8 b/.metadata/.plugins/org.eclipse.core.resources/.history/49/a04d8dc3d23e001518fa86d7ae2a1cf8 new file mode 100644 index 0000000..5d7321f --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/49/a04d8dc3d23e001518fa86d7ae2a1cf8 @@ -0,0 +1,215 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; + +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class Commands implements CommandExecutor { + // This method is called, when somebody uses our command + @Override + public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { + if (sender instanceof Player) { + Player player = (Player) sender; + if(args.length<1) + return false; + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. + //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) + if(p.Flair==null) + { + player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); + return true; + } + switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. + { + case "accept": + { + if(p.IgnoredFlair) + p.IgnoredFlair=false; //2015.08.08. + if(!p.AcceptedFlair) + { + String flair=p.Flair; //2015.08.08. + //PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + PluginMain.AppendPlayerDisplayFlair(p, player); + p.AcceptedFlair=true; //2015.08.08. + player.sendMessage("§6Your flair has been set:§r "+flair); + } + else + player.sendMessage("§cYou already have this user's flair.§r"); + break; + } + case "ignore": + { + if(p.AcceptedFlair) + p.AcceptedFlair=false; //2015.08.08. + if(!p.IgnoredFlair) + { + p.IgnoredFlair=true; + String flair=p.Flair; //2015.08.08. + PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. + player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); + } + else + player.sendMessage("§cYou already ignored this request.§r"); + break; + } + /*case "reload": //2015.07.20. + DoReload(player); + break;*/ + case "admin": //2015.08.09. + DoAdmin(player, args); + break; + case "nonpresser": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§7(non-pr.)§r"; + break; + case "cantpress": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§r(can't press)§r"; + break; + default: + return false; + } + return true; + } + /*if(args[0].toLowerCase()=="reload") + DoReload(null); //2015.07.20.*/ + else if(args.length>0 && args[0].toLowerCase().equals("admin")) //2015.08.09. + { + DoAdmin(null, args); //2015.08.09. + return true; //2015.08.09. + } + return false; + } + private static void DoReload(Player player) + { //2015.07.20. + //if(player==null || player.isOp() || player.getName()=="NorbiPeti") + //{ + try + { + File file=new File("autoflairconfig.txt"); + if(file.exists()) + { + PluginMain.LoadFiles(true); //2015.08.09. + 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); + PluginMain.AppendPlayerDisplayFlair(mp, p); //2015.08.09. + } + } + //String msg="§6Reloaded config file.§r"; + String msg="§6Reloaded all files.§r"; + SendMessage(player, msg); //2015.08.09. + } + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + if(player!=null) + player.sendMessage("§cAn error occured. See console for details.§r"); + PluginMain.LastException=e; //2015.08.09. + } + //} + //else + //player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static void DoAdmin(Player player, String[] args) + { //2015.08.09. + if(player==null || player.isOp() || player.getName()=="NorbiPeti") + { + //System.out.println("Args length: " + args.length); + if(args.length==1) + { + String message="§cUsage: /u admin reload|playerinfo§r"; + SendMessage(player, message); + return; + } + //args[0] is "admin" + switch(args[1].toLowerCase()) + { + case "reload": + DoReload(player); + break; + case "playerinfo": + DoPlayerInfo(player, args); + break; + case "getlasterror": + DoGetLastError(player, args); + default: + String message="§cUsage: /u admin reload|playerinfo§r"; + SendMessage(player, message); + return; + } + } + else + player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static void DoPlayerInfo(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "playerinfo" + if(args.length==2) + { + String message="§cUsage: /u admin playerinfo §r"; + SendMessage(player, message); + return; + } + if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2])) + { + String message="§cPlayer not found: "+args[2]+"§r"; + SendMessage(player, message); + return; + } + MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]); + SendMessage(player, "Player name: "+p.PlayerName); + SendMessage(player, "User flair: "+p.Flair); + SendMessage(player, "Username: "+p.UserName); + SendMessage(player, "Flair accepted: "+p.AcceptedFlair); + SendMessage(player, "Flair ignored: "+p.IgnoredFlair); + } + private static void SendMessage(Player player, String message) + { //2015.08.09. + if(player==null) + System.out.println(message); + else + player.sendMessage(message); + } + private static void DoGetLastError(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "getlasterror" + if(PluginMain.LastException!=null) + { + SendMessage(player, "Last error:"); + SendMessage(player, PluginMain.LastException.toString()); + PluginMain.LastException=null; + } + else + SendMessage(player, "There were no exceptions."); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/49/b0556e29ce3e001518fa86d7ae2a1cf8 b/.metadata/.plugins/org.eclipse.core.resources/.history/49/b0556e29ce3e001518fa86d7ae2a1cf8 new file mode 100644 index 0000000..26a60f9 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/49/b0556e29ce3e001518fa86d7ae2a1cf8 @@ -0,0 +1,355 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStream; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLConnection; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + +import org.apache.commons.io.IOUtils; +import org.bukkit.entity.Player; +import org.bukkit.plugin.java.JavaPlugin; +import org.json.JSONArray; +import org.json.JSONObject; + +import com.palmergames.bukkit.towny.object.Town; +import com.palmergames.bukkit.towny.object.WorldCoord; + +public class PluginMain extends JavaPlugin +{ //Translated to Java: 2015.07.15. + //A user, which flair isn't obtainable: + //https://www.reddit.com/r/thebutton/comments/31c32v/i_pressed_the_button_without_really_thinking/ + private static PluginMain Instance; + // Fired when plugin is first enabled + @Override + public void onEnable() + { + System.out.println("The Button Auto-flair Plugin by NorbiPeti (:P)"); + getServer().getPluginManager().registerEvents(new PlayerListener(), this); + this.getCommand("u").setExecutor(new Commands()); + this.getCommand("u").setUsage(this.getCommand("u").getUsage().replace('&', '§')); + Instance=this; //2015.08.08. + try { + File file=new File("flairsaccepted.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + //System.out.println("Name: " + name); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("flairsignored.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsignored.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("autoflairconfig.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + TownColors.put(s[0], s[1]); + } + br.close(); + } + //throw new IOException("Test"); //2015.08.09. + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + Runnable r=new Runnable(){public void run(){ThreadMethod();}}; + Thread t=new Thread(r); + t.start(); + } + Boolean stop=false; + // Fired when plugin is disabled + @Override + public void onDisable() + { + try + { + FileWriter fw; + fw = new FileWriter("flairsaccepted.txt"); + fw.close(); + fw = new FileWriter("flairsignored.txt"); + fw.close(); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + try { + File file=new File("flairsaccepted.txt"); + BufferedWriter bw=new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.AcceptedFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + file=new File("flairsignored.txt"); + bw = new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.IgnoredFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + stop=true; + } + + public void ThreadMethod() //<-- 2015.07.16. + { + while(!stop) + { + try + { + String body=DownloadString("https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/autoflair_system_comment_your_minecraft_name_and/.json?limit=1000"); + JSONArray json=new JSONArray(body).getJSONObject(1).getJSONObject("data").getJSONArray("children"); + for(Object obj : json) + { + JSONObject item = (JSONObject)obj; + String author=item.getJSONObject("data").getString("author"); + String ign=item.getJSONObject("data").getString("body"); + int start = ign.indexOf("IGN:") + "IGN:".length(); + int end = ign.indexOf(' ', start); + if (end == -1 || end == start) + end=ign.indexOf('\n', start); //2015.07.15. + if (end == -1 || end == start) + ign = ign.substring(start); + else + ign = ign.substring(start, end); + ign = ign.trim(); + if(HasIGFlair(ign)) + continue; + try { + Thread.sleep(10); + } catch(InterruptedException ex) { + Thread.currentThread().interrupt(); + } + String[] flairdata = DownloadString("http://karmadecay.com/thebutton-data.php?users=" + author).replace("\"", "").split(":"); + String flair; + if(flairdata.length > 1) //2015.07.15. + flair = flairdata[1]; + else + flair=""; + if (flair != "-1") + flair = flair + "s"; + else + flair = "non-presser"; + String flairclass; + if(flairdata.length>2) + flairclass = flairdata[2]; + else + flairclass="unknown"; + SetFlair(ign, flair, flairclass, author); + } + Thread.sleep(10000); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + } + + public static Exception LastException; //2015.08.09. + + public String DownloadString(String urlstr) throws MalformedURLException, IOException + { + URL url = new URL(urlstr); + URLConnection con = url.openConnection(); + con.setRequestProperty("User-Agent", "TheButtonAutoFlair"); + InputStream in = con.getInputStream(); + String encoding = con.getContentEncoding(); + encoding = encoding == null ? "UTF-8" : encoding; + String body = IOUtils.toString(in, encoding); + in.close(); + return body; + } + + public static Map TownColors=new HashMap(); //2015.07.20. + public Boolean HasIGFlair(String playername) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + return p.Flair!=null; //2015.08.08. + } + + public void SetFlair(String playername, String text, String flairclass, String username) + { + String finalflair; + switch(flairclass) + { + case "press-1": + finalflair="§c("+text+")§r"; + break; + case "press-2": + finalflair="§6("+text+")§r"; + break; + case "press-3": + finalflair="§e("+text+")§r"; + break; + case "press-4": + finalflair="§a("+text+")§r"; + break; + case "press-5": + finalflair="§9("+text+")§r"; + break; + case "press-6": + finalflair="§5("+text+")§r"; + break; + case "no-press": + finalflair="§7(non-pr.)§r"; + break; + case "cheater": + finalflair="§5("+text+")§r"; + break; + case "cant-press": //2015.08.08. + finalflair="§r(can't press)§r"; + break; + case "undecided": //2015.08.09. + + finalflair=""; + break; + default: + finalflair=""; + break; + } + if(finalflair.length()==0) //<-- 2015.07.20. + return; + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + p.Flair=finalflair; //2015.08.08. + p.UserName=username; //2015.08.08. + System.out.println("Added new flair to "+playername+": "+finalflair); + for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08. + { + if(player.getName().equals(playername)) + { + AppendPlayerDisplayFlair(player, username, finalflair); + break; + } + } + } + + public static String GetFlair(Player player) + { //2015.07.16. + String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08. + return flair==null ? "" : flair; + } + + public static void AppendPlayerDisplayFlair(Player player, String username, String flair) + { + if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).IgnoredFlair) + return; + if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).AcceptedFlair) + AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + else + player.sendMessage("§9Are you Reddit user "+username+"?§r §6Type /u accept or /u ignore§r"); + } + + public static void AppendPlayerDisplayFlairFinal(Player player, String flair) + { //2015.07.20. + String color = GetColorForTown(GetPlayerTown(player)); //TO!DO: Multiple colors put on first capital letters + String[] colors = color.substring(1).split("§"); + String displayname=player.getName(); //2015.08.08. + ArrayList Positions=new ArrayList<>(); + for(int i=0; i=colors.length) + { + int x=0; + for(int i=0; i GetPlayers() + { + return Instance.getServer().getOnlinePlayers(); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/4a/202fd432d93e001517108d149b613203 b/.metadata/.plugins/org.eclipse.core.resources/.history/4a/202fd432d93e001517108d149b613203 new file mode 100644 index 0000000..a463049 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/4a/202fd432d93e001517108d149b613203 @@ -0,0 +1,228 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; + +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class Commands implements CommandExecutor { + // This method is called, when somebody uses our command + @Override + public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { + if (sender instanceof Player) { + Player player = (Player) sender; + if(args.length<1) + return false; + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. + //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) + if(p.Flair==null) + { + player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); + return true; + } + switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. + { + case "accept": + { + if(p.IgnoredFlair) + p.IgnoredFlair=false; //2015.08.08. + if(!p.AcceptedFlair) + { + String flair=p.Flair; //2015.08.08. + //PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + PluginMain.AppendPlayerDisplayFlair(p, player); + p.AcceptedFlair=true; //2015.08.08. + player.sendMessage("§6Your flair has been set:§r "+flair); + } + else + player.sendMessage("§cYou already have this user's flair.§r"); + break; + } + case "ignore": + { + if(p.AcceptedFlair) + p.AcceptedFlair=false; //2015.08.08. + if(!p.IgnoredFlair) + { + p.IgnoredFlair=true; + String flair=p.Flair; //2015.08.08. + PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. + player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); + } + else + player.sendMessage("§cYou already ignored this request.§r"); + break; + } + /*case "reload": //2015.07.20. + DoReload(player); + break;*/ + case "admin": //2015.08.09. + DoAdmin(player, args); + break; + case "nonpresser": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§7(non-pr.)§r"; + break; + case "cantpress": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§r(can't press)§r"; + break; + default: + return false; + } + return true; + } + /*if(args[0].toLowerCase()=="reload") + DoReload(null); //2015.07.20.*/ + else if(args.length>0 && args[0].toLowerCase().equals("admin")) //2015.08.09. + { + DoAdmin(null, args); //2015.08.09. + return true; //2015.08.09. + } + return false; + } + private static void DoReload(Player player) + { //2015.07.20. + //if(player==null || player.isOp() || player.getName()=="NorbiPeti") + //{ + try + { + File file=new File("autoflairconfig.txt"); + if(file.exists()) + { + PluginMain.LoadFiles(true); //2015.08.09. + for(Player p : PluginMain.GetPlayers()) + { + MaybeOfflinePlayer mp = MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName()); + if(mp.Flair!=null) + { + String flair=mp.Flair; + PluginMain.RemovePlayerDisplayFlairFinal(p, flair); + //PluginMain.AppendPlayerDisplayFlairFinal(p, flair); + PluginMain.AppendPlayerDisplayFlair(mp, p); //2015.08.09. + } + String msg="§6Note: The auto-flair plugin has been reloaded. You might need to wait 10s to have your flair.§r"; //2015.08.09. + p.sendMessage(msg); //2015.08.09. + } + //String msg="§6Reloaded config file.§r"; + //SendMessage(player, msg); //2015.08.09. + } + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + if(player!=null) + player.sendMessage("§cAn error occured. See console for details.§r"); + PluginMain.LastException=e; //2015.08.09. + } + //} + //else + //player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static Player ReloadPlayer; //2015.08.09. + private static void DoAdmin(Player player, String[] args) + { //2015.08.09. + if(player==null || player.isOp() || player.getName()=="NorbiPeti") + { + //System.out.println("Args length: " + args.length); + if(args.length==1) + { + String message="§cUsage: /u admin reload|playerinfo§r"; + SendMessage(player, message); + return; + } + //args[0] is "admin" + switch(args[1].toLowerCase()) + { + case "reload": + ReloadPlayer=player; //2015.08.09. + SendMessage(player, "§6Make sure to save the current settings before you modify and reload them! Type /u admin confirm when done.§r"); + break; + case "playerinfo": + DoPlayerInfo(player, args); + break; + case "getlasterror": + DoGetLastError(player, args); + case "confirm": + if(ReloadPlayer!=null && ReloadPlayer.equals(player)) + DoReload(player); //2015.08.09. + else + SendMessage(player, "§cYou need to do /u admin reload first.§r"); + break; + case "save": + PluginMain.SaveFiles(); //2015.08.09. + SendMessage(player, "§6Saved files.§r"); + break; + default: + String message="§cUsage: /u admin reload|playerinfo|getlasterror§r"; + SendMessage(player, message); + return; + } + } + else + player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static void DoPlayerInfo(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "playerinfo" + if(args.length==2) + { + String message="§cUsage: /u admin playerinfo §r"; + SendMessage(player, message); + return; + } + if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2])) + { + String message="§cPlayer not found: "+args[2]+"§r"; + SendMessage(player, message); + return; + } + MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]); + SendMessage(player, "Player name: "+p.PlayerName); + SendMessage(player, "User flair: "+p.Flair); + SendMessage(player, "Username: "+p.UserName); + SendMessage(player, "Flair accepted: "+p.AcceptedFlair); + SendMessage(player, "Flair ignored: "+p.IgnoredFlair); + } + private static void SendMessage(Player player, String message) + { //2015.08.09. + if(player==null) + System.out.println(message); + else + player.sendMessage(message); + } + private static void DoGetLastError(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "getlasterror" + if(PluginMain.LastException!=null) + { + SendMessage(player, "Last error:"); + SendMessage(player, PluginMain.LastException.toString()); + PluginMain.LastException=null; + } + else + SendMessage(player, "There were no exceptions."); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/4a/20662b05d33e001518fa86d7ae2a1cf8 b/.metadata/.plugins/org.eclipse.core.resources/.history/4a/20662b05d33e001518fa86d7ae2a1cf8 new file mode 100644 index 0000000..63c2d54 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/4a/20662b05d33e001518fa86d7ae2a1cf8 @@ -0,0 +1,215 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; + +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class Commands implements CommandExecutor { + // This method is called, when somebody uses our command + @Override + public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { + if (sender instanceof Player) { + Player player = (Player) sender; + if(args.length<1) + return false; + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. + //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) + if(p.Flair==null) + { + player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); + return true; + } + switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. + { + case "accept": + { + if(p.IgnoredFlair) + p.IgnoredFlair=false; //2015.08.08. + if(!p.AcceptedFlair) + { + String flair=p.Flair; //2015.08.08. + //PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + PluginMain.AppendPlayerDisplayFlair(p, player); + p.AcceptedFlair=true; //2015.08.08. + player.sendMessage("§6Your flair has been set:§r "+flair); + } + else + player.sendMessage("§cYou already have this user's flair.§r"); + break; + } + case "ignore": + { + if(p.AcceptedFlair) + p.AcceptedFlair=false; //2015.08.08. + if(!p.IgnoredFlair) + { + p.IgnoredFlair=true; + String flair=p.Flair; //2015.08.08. + PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. + player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); + } + else + player.sendMessage("§cYou already ignored this request.§r"); + break; + } + /*case "reload": //2015.07.20. + DoReload(player); + break;*/ + case "admin": //2015.08.09. + DoAdmin(player, args); + break; + case "nonpresser": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§7(non-pr.)§r"; + break; + case "cantpress": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§r(can't press)§r"; + break; + default: + return false; + } + return true; + } + /*if(args[0].toLowerCase()=="reload") + DoReload(null); //2015.07.20.*/ + else if(args.length>0 && args[0].toLowerCase().equals("admin")) //2015.08.09. + { + DoAdmin(null, args); //2015.08.09. + return true; //2015.08.09. + } + return false; + } + private static void DoReload(Player player) + { //2015.07.20. + //if(player==null || player.isOp() || player.getName()=="NorbiPeti") + //{ + try + { + File file=new File("autoflairconfig.txt"); + if(file.exists()) + { + PluginMain.LoadFiles(true); //2015.08.09. + for(Player p : PluginMain.GetPlayers()) + { + MaybeOfflinePlayer mp = MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName()); + if(mp.Flair!=null) + { + String flair=mp.Flair; + PluginMain.RemovePlayerDisplayFlairFinal(p, flair); + //PluginMain.AppendPlayerDisplayFlairFinal(p, flair); + PluginMain.AppendPlayerDisplayFlair(mp, p); //2015.08.09. + } + } + //String msg="§6Reloaded config file.§r"; + String msg="§6Reloaded all files.§r"; + SendMessage(player, msg); //2015.08.09. + } + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + if(player!=null) + player.sendMessage("§cAn error occured. See console for details.§r"); + PluginMain.LastException=e; //2015.08.09. + } + //} + //else + //player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static void DoAdmin(Player player, String[] args) + { //2015.08.09. + if(player==null || player.isOp() || player.getName()=="NorbiPeti") + { + //System.out.println("Args length: " + args.length); + if(args.length==1) + { + String message="§cUsage: /u admin reload|playerinfo§r"; + SendMessage(player, message); + return; + } + //args[0] is "admin" + switch(args[1].toLowerCase()) + { + case "reload": + DoReload(player); + break; + case "playerinfo": + DoPlayerInfo(player, args); + break; + case "getlasterror": + DoGetLastError(player, args); + default: + String message="§cUsage: /u admin reload|playerinfo§r"; + SendMessage(player, message); + return; + } + } + else + player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static void DoPlayerInfo(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "playerinfo" + if(args.length==2) + { + String message="§cUsage: /u admin playerinfo §r"; + SendMessage(player, message); + return; + } + if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2])) + { + String message="§cPlayer not found: "+args[2]+"§r"; + SendMessage(player, message); + return; + } + MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]); + SendMessage(player, "Player name: "+p.PlayerName); + SendMessage(player, "User flair: "+p.Flair); + SendMessage(player, "Username: "+p.UserName); + SendMessage(player, "Flair accepted: "+p.AcceptedFlair); + SendMessage(player, "Flair ignored: "+p.IgnoredFlair); + } + private static void SendMessage(Player player, String message) + { //2015.08.09. + if(player==null) + System.out.println(message); + else + player.sendMessage(message); + } + private static void DoGetLastError(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "getlasterror" + if(PluginMain.LastException!=null) + { + SendMessage(player, "Last error:"); + SendMessage(player, PluginMain.LastException.toString()); + PluginMain.LastException=null; + } + else + SendMessage(player, "There were no exceptions."); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/4a/50f7fce0873e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/4a/50f7fce0873e00151ce8ff6d4f74dabd deleted file mode 100644 index a0eb8d2..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/4a/50f7fce0873e00151ce8ff6d4f74dabd +++ /dev/null @@ -1,152 +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; - MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. - //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - if(p.Flair==null) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. - { - case "accept": - { - if(p.IgnoredFlair) - p.IgnoredFlair=false; //2015.08.08. - if(!p.AcceptedFlair) - { - String flair=p.Flair; //2015.08.08. - PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. - p.AcceptedFlair=true; //2015.08.08. - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("§cYou already have this user's flair.§r"); - break; - } - case "ignore": - { - if(p.AcceptedFlair) - p.AcceptedFlair=false; //2015.08.08. - if(!p.IgnoredFlair) - { - p.IgnoredFlair=true; - String flair=p.Flair; //2015.08.08. - PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. - player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); - } - else - player.sendMessage("§cYou already ignored this request.§r"); - break; - } - /*case "reload": //2015.07.20. - DoReload(player); - break;*/ - case "admin": //2015.08.09. - DoAdmin(player, args); - break; - default: - return false; - } - return true; - } - - /*if(args[0].toLowerCase()=="reload") - DoReload(null); //2015.07.20.*/ - else if(args[0].toLowerCase()=="admin") - DoAdmin(null, args); //2015.08.09. - return false; - } - private static void DoReload(Player player) - { //2015.07.20. - //if(player==null || player.isOp() || player.getName()=="NorbiPeti") - //{ - try - { - File file=new File("autoflairconfig.txt"); - if(file.exists()) - { - PluginMain.TownColors.clear(); - BufferedReader br=new BufferedReader(new FileReader(file)); - String line; - while((line=br.readLine())!=null) - { - String[] s=line.split(" "); - PluginMain.TownColors.put(s[0], s[1]); - } - br.close(); - for(Player p : PluginMain.GetPlayers()) - { - MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName()); - if(mp.Flair!=null) - { - String flair=mp.Flair; - PluginMain.RemovePlayerDisplayFlairFinal(p, flair); - PluginMain.AppendPlayerDisplayFlairFinal(p, flair); - } - } - String msg="§6Reloaded config file.§r"; - if(player!=null) - player.sendMessage(msg); - else - System.out.println(msg); - } - } - catch(Exception e) - { - System.out.println("Error!\n"+e); - if(player!=null) - player.sendMessage("§cAn error occured. See console for details.§r"); - } - //} - //else - //player.sendMessage("§cYou need to be OP to use this command.§r"); - } - private static void DoAdmin(Player player, String[] args) - { //2015.08.09. - if(player==null || player.isOp() || player.getName()=="NorbiPeti") - { - //args[0] is "admin" - switch(args[1].toLowerCase()) - { - case "reload": - DoReload(player); - break; - case "playerinfo": - DoPlayerInfo(player, args); - break; - } - } - else - player.sendMessage("§cYou need to be OP to use this command.§r"); - } - private static void DoPlayerInfo(Player player, String[] args) - { //2015.08.09. - //args[0] is "admin" - args[1] is "playerinfo" - if(args.length==2) - { - String message="§cUsage: /u admin playerinfo §r"; - if(player==null) - System.out.println(message); - else - player.sendMessage(message); - } - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/4/70e5ccd7303e00151cbdba8b5f0a340e b/.metadata/.plugins/org.eclipse.core.resources/.history/4b/203dd097ce3e001518fa86d7ae2a1cf8 similarity index 70% rename from .metadata/.plugins/org.eclipse.core.resources/.history/4/70e5ccd7303e00151cbdba8b5f0a340e rename to .metadata/.plugins/org.eclipse.core.resources/.history/4b/203dd097ce3e001518fa86d7ae2a1cf8 index 06839a7..4e85b74 100644 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/4/70e5ccd7303e00151cbdba8b5f0a340e +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/4b/203dd097ce3e001518fa86d7ae2a1cf8 @@ -21,8 +21,9 @@ import org.bukkit.plugin.java.JavaPlugin; import org.json.JSONArray; import org.json.JSONObject; +import tk.sznp.thebuttonautoflair.MaybeOfflinePlayer.FlairClassType; + 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 @@ -48,7 +49,7 @@ public class PluginMain extends JavaPlugin while ((line = br.readLine()) != null) { String name=line.replace("\n", ""); - System.out.println("Name: " + name); + //System.out.println("Name: " + name); MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08. } br.close(); @@ -77,8 +78,10 @@ public class PluginMain extends JavaPlugin } br.close(); } + //throw new IOException("Test"); //2015.08.09. } catch (IOException e) { System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. } Runnable r=new Runnable(){public void run(){ThreadMethod();}}; Thread t=new Thread(r); @@ -100,33 +103,31 @@ public class PluginMain extends JavaPlugin catch(Exception e) { System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. } - for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. - { - if(!player.AcceptedFlair) - continue; //2015.08.08. - File file=new File("flairsaccepted.txt"); - try { - BufferedWriter bw=new BufferedWriter(new FileWriter(file, true)); + try { + File file=new File("flairsaccepted.txt"); + BufferedWriter bw=new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.AcceptedFlair) + continue; //2015.08.08. bw.write(player.PlayerName+"\n"); - bw.close(); - } catch (IOException e) { - System.out.println("Error!\n"+e); - } - } - for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. - { - if(!player.IgnoredFlair) - continue; //2015.08.08. - File file=new File("flairsignored.txt"); - try { - BufferedWriter bw = new BufferedWriter(new FileWriter(file, true)); + } + bw.close(); + file=new File("flairsignored.txt"); + bw = new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.IgnoredFlair) + continue; //2015.08.08. bw.write(player.PlayerName+"\n"); - bw.close(); - } catch (IOException e) { - System.out.println("Error!\n"+e); - } - } + } + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } stop=true; } @@ -154,7 +155,6 @@ public class PluginMain extends JavaPlugin ign = ign.trim(); if(HasIGFlair(ign)) continue; - //System.out.println("Author: "+author); try { Thread.sleep(10); } catch(InterruptedException ex) { @@ -171,7 +171,6 @@ public class PluginMain extends JavaPlugin else flair = "non-presser"; String flairclass; - //System.out.println("flairdata.length:"+flairdata.length); if(flairdata.length>2) flairclass = flairdata[2]; else @@ -183,10 +182,13 @@ public class PluginMain extends JavaPlugin catch(Exception e) { System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. } } } + public static Exception LastException; //2015.08.09. + public String DownloadString(String urlstr) throws MalformedURLException, IOException { URL url = new URL(urlstr); @@ -200,37 +202,18 @@ public class PluginMain extends JavaPlugin return body; } - //It has to store offline player flairs too, therefore it can't use Player object - /*public static Map PlayerFlairs=new HashMap(); - public static Map PlayerUserNames=new HashMap(); - //public Map PlayerFlairs=new HashMap(); - public static ArrayList Players=new ArrayList(); - public static ArrayList AcceptedPlayers=new ArrayList(); //2015.07.16. - public static ArrayList IgnoredPlayers=new ArrayList(); //2015.07.16. - //public static Map PlayerTowns=new HashMap(); //2015.07.20.*/ public static Map TownColors=new HashMap(); //2015.07.20. public Boolean HasIGFlair(String playername) { - /*Player player=null; - for(Player p : Players) - { - if(p.getName()==playername) - { - player=p; - break; - } - } - if(player==null) - return false;*/ - //return PlayerFlairs.containsKey(playername); - //return MaybeOfflinePlayer.AllPlayers.containsKey(playername); MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. return p.Flair!=null; //2015.08.08. } public void SetFlair(String playername, String text, String flairclass, String username) { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. String finalflair; + p.FlairDecided=true; switch(flairclass) { case "press-1": @@ -260,38 +243,24 @@ public class PluginMain extends JavaPlugin case "cant-press": //2015.08.08. finalflair="§r(can't press)§r"; break; + case "undecided": //2015.08.09. + p.FlairDecided=false; + finalflair=""; + 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; } } @@ -299,19 +268,15 @@ public class PluginMain extends JavaPlugin public static String GetFlair(Player player) { //2015.07.16. - //String flair=PlayerFlairs.get(player.getName()); String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08. return flair==null ? "" : flair; } public static void AppendPlayerDisplayFlair(Player player, String username, String flair) { - //if(IgnoredPlayers.contains(player.getName())) if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).IgnoredFlair) return; - //if(AcceptedPlayers.contains(player.getName())) if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).AcceptedFlair) - //player.setDisplayName(player.getDisplayName()+flair); AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. else player.sendMessage("§9Are you Reddit user "+username+"?§r §6Type /u accept or /u ignore§r"); @@ -319,23 +284,18 @@ public class PluginMain extends JavaPlugin public static void AppendPlayerDisplayFlairFinal(Player player, String flair) { //2015.07.20. - //System.out.println("A"); String color = GetColorForTown(GetPlayerTown(player)); //TO!DO: Multiple colors put on first capital letters String[] colors = color.substring(1).split("§"); - //String displayname=player.getDisplayName(); String displayname=player.getName(); //2015.08.08. ArrayList Positions=new ArrayList<>(); - //System.out.println("B"); for(int i=0; i=colors.length) { - //System.out.println("D"); int x=0; for(int i=0; i towns = TownyUniverse.getDataSource().getTowns(); try { Town town = WorldCoord.parseWorldCoord(player).getTownBlock().getTown(); //TODO return town.getName(); @@ -400,10 +348,6 @@ public class PluginMain extends JavaPlugin public static void RemovePlayerDisplayFlairFinal(Player player, String flair) { //2015.07.20. - //String color = GetColorForTown(GetPlayerTown(player)); - //String dname=player.getDisplayName(); - //player.setDisplayName(dname.substring(dname.indexOf(color)+3, dname.indexOf(flair))); - //MaybeOfflinePlayer.AllPlayers.get(player.getName()).DisplayName=null; //2015.08.08. MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair=null; //2015.08.08. } diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/4c/d0831972873e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/4c/d0831972873e00151ce8ff6d4f74dabd deleted file mode 100644 index 568b3d5..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/4c/d0831972873e00151ce8ff6d4f74dabd +++ /dev/null @@ -1,144 +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; - MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. - //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - if(p.Flair==null) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. - { - case "accept": - { - if(p.IgnoredFlair) - p.IgnoredFlair=false; //2015.08.08. - if(!p.AcceptedFlair) - { - String flair=p.Flair; //2015.08.08. - PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. - p.AcceptedFlair=true; //2015.08.08. - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("§cYou already have this user's flair.§r"); - break; - } - case "ignore": - { - if(p.AcceptedFlair) - p.AcceptedFlair=false; //2015.08.08. - if(!p.IgnoredFlair) - { - p.IgnoredFlair=true; - String flair=p.Flair; //2015.08.08. - PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. - player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); - } - else - player.sendMessage("§cYou already ignored this request.§r"); - break; - } - /*case "reload": //2015.07.20. - DoReload(player); - break;*/ - case "admin": //2015.08.09. - DoAdmin(player, args); - break; - default: - return false; - } - return true; - } - - /*if(args[0].toLowerCase()=="reload") - DoReload(null); //2015.07.20.*/ - else if(args[0].toLowerCase()=="admin") - DoAdmin(null, args); //2015.08.09. - return false; - } - private static void DoReload(Player player) - { //2015.07.20. - //if(player==null || player.isOp() || player.getName()=="NorbiPeti") - //{ - try - { - File file=new File("autoflairconfig.txt"); - if(file.exists()) - { - PluginMain.TownColors.clear(); - BufferedReader br=new BufferedReader(new FileReader(file)); - String line; - while((line=br.readLine())!=null) - { - String[] s=line.split(" "); - PluginMain.TownColors.put(s[0], s[1]); - } - br.close(); - for(Player p : PluginMain.GetPlayers()) - { - MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName()); - if(mp.Flair!=null) - { - String flair=mp.Flair; - PluginMain.RemovePlayerDisplayFlairFinal(p, flair); - PluginMain.AppendPlayerDisplayFlairFinal(p, flair); - } - } - String msg="§6Reloaded config file.§r"; - if(player!=null) - player.sendMessage(msg); - else - System.out.println(msg); - } - } - catch(Exception e) - { - System.out.println("Error!\n"+e); - if(player!=null) - player.sendMessage("§cAn error occured. See console for details.§r"); - } - //} - //else - //player.sendMessage("§cYou need to be OP to use this command.§r"); - } - private static void DoAdmin(Player player, String[] args) - { - if(player==null || player.isOp() || player.getName()=="NorbiPeti") - { - //args[0] is "admin" - switch(args[1].toLowerCase()) - { - case "reload": - DoReload(player); - break; - case "playerinfo": - DoPlayerInfo(player, args); - break; - } - } - else - player.sendMessage("§cYou need to be OP to use this command.§r"); - } - private static void DoPlayerInfo(Player player, String[] args) - { - - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/4d/80b8c135e13e001517108d149b613203 b/.metadata/.plugins/org.eclipse.core.resources/.history/4d/80b8c135e13e001517108d149b613203 new file mode 100644 index 0000000..29ccded --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/4d/80b8c135e13e001517108d149b613203 @@ -0,0 +1,265 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +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; + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. + //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) + if(p.Flair==null) + { + player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); + return true; + } + switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. + { + case "accept": + { + if(p.IgnoredFlair) + p.IgnoredFlair=false; //2015.08.08. + if(!p.AcceptedFlair) + { + String flair=p.Flair; //2015.08.08. + //PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + PluginMain.AppendPlayerDisplayFlair(p, player); + p.AcceptedFlair=true; //2015.08.08. + player.sendMessage("§6Your flair has been set:§r "+flair); + } + else + player.sendMessage("§cYou already have this user's flair.§r"); + break; + } + case "ignore": + { + if(p.AcceptedFlair) + p.AcceptedFlair=false; //2015.08.08. + if(!p.IgnoredFlair) + { + p.IgnoredFlair=true; + String flair=p.Flair; //2015.08.08. + PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. + player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); + } + else + player.sendMessage("§cYou already ignored this request.§r"); + break; + } + /*case "reload": //2015.07.20. + DoReload(player); + break;*/ + case "admin": //2015.08.09. + DoAdmin(player, args); + break; + case "nonpresser": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§7(non-pr.)§r"; + break; + case "cantpress": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§r(can't press)§r"; + break; + default: + return false; + } + return true; + } + /*if(args[0].toLowerCase()=="reload") + DoReload(null); //2015.07.20.*/ + else if(args.length>0 && args[0].toLowerCase().equals("admin")) //2015.08.09. + { + DoAdmin(null, args); //2015.08.09. + return true; //2015.08.09. + } + return false; + } + private static void DoReload(Player player) + { //2015.07.20. + //if(player==null || player.isOp() || player.getName()=="NorbiPeti") + //{ + try + { + File file=new File("autoflairconfig.txt"); + if(file.exists()) + { + PluginMain.LoadFiles(true); //2015.08.09. + for(Player p : PluginMain.GetPlayers()) + { + MaybeOfflinePlayer mp = MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName()); + if(mp.Flair!=null) + { + String flair=mp.Flair; + PluginMain.RemovePlayerDisplayFlairFinal(p, flair); + //PluginMain.AppendPlayerDisplayFlairFinal(p, flair); + PluginMain.AppendPlayerDisplayFlair(mp, p); //2015.08.09. + } + String msg="§6Note: The auto-flair plugin has been reloaded. You might need to wait 10s to have your flair.§r"; //2015.08.09. + p.sendMessage(msg); //2015.08.09. + } + //String msg="§6Reloaded config file.§r"; + //SendMessage(player, msg); //2015.08.09. + } + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + if(player!=null) + player.sendMessage("§cAn error occured. See console for details.§r"); + PluginMain.LastException=e; //2015.08.09. + } + //} + //else + //player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static Player ReloadPlayer; //2015.08.09. + private static void DoAdmin(Player player, String[] args) + { //2015.08.09. + if(player==null || player.isOp() || player.getName()=="NorbiPeti") + { + //System.out.println("Args length: " + args.length); + if(args.length==1) + { + String message="§cUsage: /u admin reload|playerinfo§r"; + SendMessage(player, message); + return; + } + //args[0] is "admin" + switch(args[1].toLowerCase()) + { + case "reload": + ReloadPlayer=player; //2015.08.09. + SendMessage(player, "§6Make sure to save the current settings before you modify and reload them! Type /u admin confirm when done.§r"); + break; + case "playerinfo": + DoPlayerInfo(player, args); + break; + case "getlasterror": + DoGetLastError(player, args); + case "confirm": + if(ReloadPlayer==player) + DoReload(player); //2015.08.09. + else + SendMessage(player, "§cYou need to do /u admin reload first.§r"); + break; + case "save": + PluginMain.SaveFiles(); //2015.08.09. + SendMessage(player, "§6Saved files. Now you can edit them and reload if you want.§r"); + break; + case "setflair": + DoSetFlair(player, args); + break; + default: + String message="§cUsage: /u admin reload|playerinfo|getlasterror|save§r"; + SendMessage(player, message); + return; + } + } + else + player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static void DoPlayerInfo(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "playerinfo" + if(args.length==2) + { + String message="§cUsage: /u admin playerinfo §r"; + SendMessage(player, message); + return; + } + if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2])) + { + String message="§cPlayer not found: "+args[2]+"§r"; + SendMessage(player, message); + return; + } + MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]); + SendMessage(player, "Player name: "+p.PlayerName); + SendMessage(player, "User flair: "+p.Flair); + SendMessage(player, "Username: "+p.UserName); + SendMessage(player, "Flair accepted: "+p.AcceptedFlair); + SendMessage(player, "Flair ignored: "+p.IgnoredFlair); + } + private static void SendMessage(Player player, String message) + { //2015.08.09. + if(player==null) + System.out.println(message); + else + player.sendMessage(message); + } + private static void DoGetLastError(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "getlasterror" + if(PluginMain.LastException!=null) + { + SendMessage(player, "Last error:"); + SendMessage(player, PluginMain.LastException.toString()); + PluginMain.LastException=null; + } + else + SendMessage(player, "There were no exceptions."); + } + private static void SetPlayerFlair(Player player, MaybeOfflinePlayer targetplayer, String flair) + { //2015.08.09. + flair=flair.replace('&', '§'); + targetplayer.Flair=flair; + if(!PluginMain.RemoveLineFromFile("customflairs.txt", targetplayer.PlayerName)) + { + SendMessage(player, "§cError removing previous custom flair!§r"); + return; + } + File file=new File("customflairs.txt"); + try { + BufferedWriter bw; + bw = new BufferedWriter(new FileWriter(file, true)); + bw.write(targetplayer.PlayerName+"\n"); + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + PluginMain.LastException=e; //2015.08.09. + } + SendMessage(player, "§6The flair has been set. Player: "+targetplayer.PlayerName+" Flair: "+flair+"§r"); + } + private static void DoSetFlair(Player player, String[] args) + { + //args[0] is "admin" - args[1] is "setflair" + if(args.length<4) + { + SendMessage(player, "§cUsage: /u admin setflair "); + return; + } + SetPlayerFlair(player, MaybeOfflinePlayer.AddPlayerIfNeeded(args[2]), args[3]); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/4d/a0ee15dcd13e001518fa86d7ae2a1cf8 b/.metadata/.plugins/org.eclipse.core.resources/.history/4d/a0ee15dcd13e001518fa86d7ae2a1cf8 new file mode 100644 index 0000000..fb29d4f --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/4d/a0ee15dcd13e001518fa86d7ae2a1cf8 @@ -0,0 +1,373 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStream; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLConnection; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + +import org.apache.commons.io.IOUtils; +import org.bukkit.entity.Player; +import org.bukkit.plugin.java.JavaPlugin; +import org.json.JSONArray; +import org.json.JSONObject; + +import com.palmergames.bukkit.towny.object.Town; +import com.palmergames.bukkit.towny.object.WorldCoord; + +public class PluginMain extends JavaPlugin +{ //Translated to Java: 2015.07.15. + //A user, which flair isn't obtainable: + //https://www.reddit.com/r/thebutton/comments/31c32v/i_pressed_the_button_without_really_thinking/ + private static PluginMain Instance; + // Fired when plugin is first enabled + @Override + public void onEnable() + { + System.out.println("The Button Auto-flair Plugin by NorbiPeti (:P)"); + getServer().getPluginManager().registerEvents(new PlayerListener(), this); + this.getCommand("u").setExecutor(new Commands()); + this.getCommand("u").setUsage(this.getCommand("u").getUsage().replace('&', '§')); + Instance=this; //2015.08.08. + LoadFiles(false); //2015.08.09. + Runnable r=new Runnable(){public void run(){ThreadMethod();}}; + Thread t=new Thread(r); + t.start(); + } + Boolean stop=false; + // Fired when plugin is disabled + @Override + public void onDisable() + { + try + { + FileWriter fw; + fw = new FileWriter("flairsaccepted.txt"); + fw.close(); + fw = new FileWriter("flairsignored.txt"); + fw.close(); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + try { + File file=new File("flairsaccepted.txt"); + BufferedWriter bw=new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.AcceptedFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + file=new File("flairsignored.txt"); + bw = new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.IgnoredFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + stop=true; + } + + public void ThreadMethod() //<-- 2015.07.16. + { + while(!stop) + { + try + { + String body=DownloadString("https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/autoflair_system_comment_your_minecraft_name_and/.json?limit=1000"); + JSONArray json=new JSONArray(body).getJSONObject(1).getJSONObject("data").getJSONArray("children"); + for(Object obj : json) + { + JSONObject item = (JSONObject)obj; + String author=item.getJSONObject("data").getString("author"); + String ign=item.getJSONObject("data").getString("body"); + int start = ign.indexOf("IGN:") + "IGN:".length(); + int end = ign.indexOf(' ', start); + if (end == -1 || end == start) + end=ign.indexOf('\n', start); //2015.07.15. + if (end == -1 || end == start) + ign = ign.substring(start); + else + ign = ign.substring(start, end); + ign = ign.trim(); + if(HasIGFlair(ign)) + continue; + try { + Thread.sleep(10); + } catch(InterruptedException ex) { + Thread.currentThread().interrupt(); + } + String[] flairdata = DownloadString("http://karmadecay.com/thebutton-data.php?users=" + author).replace("\"", "").split(":"); + String flair; + if(flairdata.length > 1) //2015.07.15. + flair = flairdata[1]; + else + flair=""; + if (flair != "-1") + flair = flair + "s"; + else + flair = "non-presser"; + String flairclass; + if(flairdata.length>2) + flairclass = flairdata[2]; + else + flairclass="unknown"; + SetFlair(ign, flair, flairclass, author); + } + Thread.sleep(10000); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + } + + public static Exception LastException; //2015.08.09. + + public String DownloadString(String urlstr) throws MalformedURLException, IOException + { + URL url = new URL(urlstr); + URLConnection con = url.openConnection(); + con.setRequestProperty("User-Agent", "TheButtonAutoFlair"); + InputStream in = con.getInputStream(); + String encoding = con.getContentEncoding(); + encoding = encoding == null ? "UTF-8" : encoding; + String body = IOUtils.toString(in, encoding); + in.close(); + return body; + } + + public static Map TownColors=new HashMap(); //2015.07.20. + public Boolean HasIGFlair(String playername) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + return p.Flair!=null; //2015.08.08. + } + + public void SetFlair(String playername, String text, String flairclass, String username) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + String finalflair; + p.FlairDecided=true; + switch(flairclass) + { + case "press-1": + finalflair="§c("+text+")§r"; + break; + case "press-2": + finalflair="§6("+text+")§r"; + break; + case "press-3": + finalflair="§e("+text+")§r"; + break; + case "press-4": + finalflair="§a("+text+")§r"; + break; + case "press-5": + finalflair="§9("+text+")§r"; + break; + 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; + case "undecided": //2015.08.09. + p.FlairDecided=false; + finalflair=""; + break; + default: + finalflair=""; + break; + } + if(finalflair.length()==0) //<-- 2015.07.20. + return; + p.Flair=finalflair; //2015.08.08. + p.UserName=username; //2015.08.08. + System.out.println("Added new flair to "+playername+": "+finalflair); + for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08. + { + if(player.getName().equals(playername)) + { + //AppendPlayerDisplayFlair(player, username, finalflair); + AppendPlayerDisplayFlair(p, player); + break; + } + } + } + + public static String GetFlair(Player player) + { //2015.07.16. + String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08. + return flair==null ? "" : flair; + } + + //public static void AppendPlayerDisplayFlair(Player player, String username, String flair) + public static void AppendPlayerDisplayFlair(MaybeOfflinePlayer player, Player p) //<-- 2015.08.09. + { + + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).IgnoredFlair) + return; + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).AcceptedFlair) + { + AppendPlayerDisplayFlairFinal(p, player.Flair); //2015.07.20. + if(!player.FlairDecided) + p.sendMessage("§9Your flair type is unknown. Are you a non-presser or a can't press? (/u nonpresser or /u cantpress)§r"); //2015.08.09. + } + else + p.sendMessage("§9Are you Reddit user "+player.UserName+"?§r §6Type /u accept or /u ignore§r"); + } + + private static void AppendPlayerDisplayFlairFinal(Player player, String flair) + { //2015.07.20. + String color = GetColorForTown(GetPlayerTown(player)); //TO!DO: Multiple colors put on first capital letters + String[] colors = color.substring(1).split("§"); + String displayname=player.getName(); //2015.08.08. + ArrayList Positions=new ArrayList<>(); + for(int i=0; i=colors.length) + { + int x=0; + for(int i=0; i GetPlayers() + { + return Instance.getServer().getOnlinePlayers(); + } + + public static void LoadFiles(boolean reload) //<-- 2015.08.09. + { + System.out.println("Loading files for auto-flair plugin..."); //2015.08.09. + if(reload) + { + MaybeOfflinePlayer.AllPlayers.clear(); //2015.08.09. + } + try { + File file=new File("flairsaccepted.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + //System.out.println("Name: " + name); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("flairsignored.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsignored.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("autoflairconfig.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + TownColors.put(s[0], s[1]); + } + br.close(); + } + //throw new IOException("Test"); //2015.08.09. + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/4e/e0491f86883e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/4e/e0491f86883e00151ce8ff6d4f74dabd deleted file mode 100644 index 010c5a2..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/4e/e0491f86883e00151ce8ff6d4f74dabd +++ /dev/null @@ -1,173 +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; - MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. - //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - if(p.Flair==null) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. - { - case "accept": - { - if(p.IgnoredFlair) - p.IgnoredFlair=false; //2015.08.08. - if(!p.AcceptedFlair) - { - String flair=p.Flair; //2015.08.08. - PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. - p.AcceptedFlair=true; //2015.08.08. - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("§cYou already have this user's flair.§r"); - break; - } - case "ignore": - { - if(p.AcceptedFlair) - p.AcceptedFlair=false; //2015.08.08. - if(!p.IgnoredFlair) - { - p.IgnoredFlair=true; - String flair=p.Flair; //2015.08.08. - PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. - player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); - } - else - player.sendMessage("§cYou already ignored this request.§r"); - break; - } - /*case "reload": //2015.07.20. - DoReload(player); - break;*/ - case "admin": //2015.08.09. - DoAdmin(player, args); - break; - default: - return false; - } - return true; - } - - /*if(args[0].toLowerCase()=="reload") - DoReload(null); //2015.07.20.*/ - else if(args[0].toLowerCase()=="admin") - DoAdmin(null, args); //2015.08.09. - return false; - } - private static void DoReload(Player player) - { //2015.07.20. - //if(player==null || player.isOp() || player.getName()=="NorbiPeti") - //{ - try - { - File file=new File("autoflairconfig.txt"); - if(file.exists()) - { - PluginMain.TownColors.clear(); - BufferedReader br=new BufferedReader(new FileReader(file)); - String line; - while((line=br.readLine())!=null) - { - String[] s=line.split(" "); - PluginMain.TownColors.put(s[0], s[1]); - } - br.close(); - for(Player p : PluginMain.GetPlayers()) - { - MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName()); - if(mp.Flair!=null) - { - String flair=mp.Flair; - PluginMain.RemovePlayerDisplayFlairFinal(p, flair); - PluginMain.AppendPlayerDisplayFlairFinal(p, flair); - } - } - String msg="§6Reloaded config file.§r"; - if(player!=null) - player.sendMessage(msg); - else - System.out.println(msg); - } - } - catch(Exception e) - { - System.out.println("Error!\n"+e); - if(player!=null) - player.sendMessage("§cAn error occured. See console for details.§r"); - } - //} - //else - //player.sendMessage("§cYou need to be OP to use this command.§r"); - } - private static void DoAdmin(Player player, String[] args) - { //2015.08.09. - if(player==null || player.isOp() || player.getName()=="NorbiPeti") - { - if(args.length==1) - { - String message="§cUsage: /u admin reload|playerinfo§r"; - if(player==null) - System.out.println(message); - else - player.sendMessage(message); - return; - } - //args[0] is "admin" - switch(args[1].toLowerCase()) - { - case "reload": - DoReload(player); - break; - case "playerinfo": - DoPlayerInfo(player, args); - break; - } - } - else - player.sendMessage("§cYou need to be OP to use this command.§r"); - } - private static void DoPlayerInfo(Player player, String[] args) - { //2015.08.09. - //args[0] is "admin" - args[1] is "playerinfo" - if(args.length==2) - { - String message="§cUsage: /u admin playerinfo §r"; - if(player==null) - System.out.println(message); - else - player.sendMessage(message); - return; - } - if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2])) - { - String message="§cPlayer not found: "+args[2]+"§r"; - if(player==null) - System.out.println(message); - else - player.sendMessage(message); - return; - } - MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]); - - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/4f/50e0ec42893e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/4f/50e0ec42893e00151ce8ff6d4f74dabd deleted file mode 100644 index 4e90cb1..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/4f/50e0ec42893e00151ce8ff6d4f74dabd +++ /dev/null @@ -1,171 +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; - MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. - //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - if(p.Flair==null) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. - { - case "accept": - { - if(p.IgnoredFlair) - p.IgnoredFlair=false; //2015.08.08. - if(!p.AcceptedFlair) - { - String flair=p.Flair; //2015.08.08. - PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. - p.AcceptedFlair=true; //2015.08.08. - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("§cYou already have this user's flair.§r"); - break; - } - case "ignore": - { - if(p.AcceptedFlair) - p.AcceptedFlair=false; //2015.08.08. - if(!p.IgnoredFlair) - { - p.IgnoredFlair=true; - String flair=p.Flair; //2015.08.08. - PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. - player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); - } - else - player.sendMessage("§cYou already ignored this request.§r"); - break; - } - /*case "reload": //2015.07.20. - DoReload(player); - break;*/ - case "admin": //2015.08.09. - DoAdmin(player, args); - break; - default: - return false; - } - return true; - } - - /*if(args[0].toLowerCase()=="reload") - DoReload(null); //2015.07.20.*/ - else if(args[0].toLowerCase()=="admin") - DoAdmin(null, args); //2015.08.09. - return false; - } - private static void DoReload(Player player) - { //2015.07.20. - //if(player==null || player.isOp() || player.getName()=="NorbiPeti") - //{ - try - { - File file=new File("autoflairconfig.txt"); - if(file.exists()) - { - PluginMain.TownColors.clear(); - BufferedReader br=new BufferedReader(new FileReader(file)); - String line; - while((line=br.readLine())!=null) - { - String[] s=line.split(" "); - PluginMain.TownColors.put(s[0], s[1]); - } - br.close(); - for(Player p : PluginMain.GetPlayers()) - { - MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName()); - if(mp.Flair!=null) - { - String flair=mp.Flair; - PluginMain.RemovePlayerDisplayFlairFinal(p, flair); - PluginMain.AppendPlayerDisplayFlairFinal(p, flair); - } - } - String msg="§6Reloaded config file.§r"; - SendMessage(player, msg); //2015.08.09. - } - } - catch(Exception e) - { - System.out.println("Error!\n"+e); - if(player!=null) - player.sendMessage("§cAn error occured. See console for details.§r"); - } - //} - //else - //player.sendMessage("§cYou need to be OP to use this command.§r"); - } - private static void DoAdmin(Player player, String[] args) - { //2015.08.09. - if(player==null || player.isOp() || player.getName()=="NorbiPeti") - { - if(args.length==1) - { - String message="§cUsage: /u admin reload|playerinfo§r"; - SendMessage(player, message); - return; - } - //args[0] is "admin" - switch(args[1].toLowerCase()) - { - case "reload": - DoReload(player); - break; - case "playerinfo": - DoPlayerInfo(player, args); - break; - } - } - else - player.sendMessage("§cYou need to be OP to use this command.§r"); - } - private static void DoPlayerInfo(Player player, String[] args) - { //2015.08.09. - //args[0] is "admin" - args[1] is "playerinfo" - if(args.length==2) - { - String message="§cUsage: /u admin playerinfo §r"; - SendMessage(player, message); - } - if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2])) - { - String message="§cPlayer not found: "+args[2]+"§r"; - SendMessage(player, message); - } - MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]); - SendMessage(player, "User flair: "+p.Flair); - SendMessage(player, "Player name: "+p.PlayerName); - SendMessage(player, "Username: "+p.UserName); - SendMessage(player, "Flair accepted: "+p.AcceptedFlair); - return; - } - private static void SendMessage(Player player, String message) - { //2015.08.09. - if(player==null) - System.out.println(message); - else - player.sendMessage(message); - return; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/5/9071ec23e13e001517108d149b613203 b/.metadata/.plugins/org.eclipse.core.resources/.history/5/9071ec23e13e001517108d149b613203 new file mode 100644 index 0000000..29ccded --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/5/9071ec23e13e001517108d149b613203 @@ -0,0 +1,265 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +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; + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. + //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) + if(p.Flair==null) + { + player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); + return true; + } + switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. + { + case "accept": + { + if(p.IgnoredFlair) + p.IgnoredFlair=false; //2015.08.08. + if(!p.AcceptedFlair) + { + String flair=p.Flair; //2015.08.08. + //PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + PluginMain.AppendPlayerDisplayFlair(p, player); + p.AcceptedFlair=true; //2015.08.08. + player.sendMessage("§6Your flair has been set:§r "+flair); + } + else + player.sendMessage("§cYou already have this user's flair.§r"); + break; + } + case "ignore": + { + if(p.AcceptedFlair) + p.AcceptedFlair=false; //2015.08.08. + if(!p.IgnoredFlair) + { + p.IgnoredFlair=true; + String flair=p.Flair; //2015.08.08. + PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. + player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); + } + else + player.sendMessage("§cYou already ignored this request.§r"); + break; + } + /*case "reload": //2015.07.20. + DoReload(player); + break;*/ + case "admin": //2015.08.09. + DoAdmin(player, args); + break; + case "nonpresser": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§7(non-pr.)§r"; + break; + case "cantpress": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§r(can't press)§r"; + break; + default: + return false; + } + return true; + } + /*if(args[0].toLowerCase()=="reload") + DoReload(null); //2015.07.20.*/ + else if(args.length>0 && args[0].toLowerCase().equals("admin")) //2015.08.09. + { + DoAdmin(null, args); //2015.08.09. + return true; //2015.08.09. + } + return false; + } + private static void DoReload(Player player) + { //2015.07.20. + //if(player==null || player.isOp() || player.getName()=="NorbiPeti") + //{ + try + { + File file=new File("autoflairconfig.txt"); + if(file.exists()) + { + PluginMain.LoadFiles(true); //2015.08.09. + for(Player p : PluginMain.GetPlayers()) + { + MaybeOfflinePlayer mp = MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName()); + if(mp.Flair!=null) + { + String flair=mp.Flair; + PluginMain.RemovePlayerDisplayFlairFinal(p, flair); + //PluginMain.AppendPlayerDisplayFlairFinal(p, flair); + PluginMain.AppendPlayerDisplayFlair(mp, p); //2015.08.09. + } + String msg="§6Note: The auto-flair plugin has been reloaded. You might need to wait 10s to have your flair.§r"; //2015.08.09. + p.sendMessage(msg); //2015.08.09. + } + //String msg="§6Reloaded config file.§r"; + //SendMessage(player, msg); //2015.08.09. + } + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + if(player!=null) + player.sendMessage("§cAn error occured. See console for details.§r"); + PluginMain.LastException=e; //2015.08.09. + } + //} + //else + //player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static Player ReloadPlayer; //2015.08.09. + private static void DoAdmin(Player player, String[] args) + { //2015.08.09. + if(player==null || player.isOp() || player.getName()=="NorbiPeti") + { + //System.out.println("Args length: " + args.length); + if(args.length==1) + { + String message="§cUsage: /u admin reload|playerinfo§r"; + SendMessage(player, message); + return; + } + //args[0] is "admin" + switch(args[1].toLowerCase()) + { + case "reload": + ReloadPlayer=player; //2015.08.09. + SendMessage(player, "§6Make sure to save the current settings before you modify and reload them! Type /u admin confirm when done.§r"); + break; + case "playerinfo": + DoPlayerInfo(player, args); + break; + case "getlasterror": + DoGetLastError(player, args); + case "confirm": + if(ReloadPlayer==player) + DoReload(player); //2015.08.09. + else + SendMessage(player, "§cYou need to do /u admin reload first.§r"); + break; + case "save": + PluginMain.SaveFiles(); //2015.08.09. + SendMessage(player, "§6Saved files. Now you can edit them and reload if you want.§r"); + break; + case "setflair": + DoSetFlair(player, args); + break; + default: + String message="§cUsage: /u admin reload|playerinfo|getlasterror|save§r"; + SendMessage(player, message); + return; + } + } + else + player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static void DoPlayerInfo(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "playerinfo" + if(args.length==2) + { + String message="§cUsage: /u admin playerinfo §r"; + SendMessage(player, message); + return; + } + if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2])) + { + String message="§cPlayer not found: "+args[2]+"§r"; + SendMessage(player, message); + return; + } + MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]); + SendMessage(player, "Player name: "+p.PlayerName); + SendMessage(player, "User flair: "+p.Flair); + SendMessage(player, "Username: "+p.UserName); + SendMessage(player, "Flair accepted: "+p.AcceptedFlair); + SendMessage(player, "Flair ignored: "+p.IgnoredFlair); + } + private static void SendMessage(Player player, String message) + { //2015.08.09. + if(player==null) + System.out.println(message); + else + player.sendMessage(message); + } + private static void DoGetLastError(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "getlasterror" + if(PluginMain.LastException!=null) + { + SendMessage(player, "Last error:"); + SendMessage(player, PluginMain.LastException.toString()); + PluginMain.LastException=null; + } + else + SendMessage(player, "There were no exceptions."); + } + private static void SetPlayerFlair(Player player, MaybeOfflinePlayer targetplayer, String flair) + { //2015.08.09. + flair=flair.replace('&', '§'); + targetplayer.Flair=flair; + if(!PluginMain.RemoveLineFromFile("customflairs.txt", targetplayer.PlayerName)) + { + SendMessage(player, "§cError removing previous custom flair!§r"); + return; + } + File file=new File("customflairs.txt"); + try { + BufferedWriter bw; + bw = new BufferedWriter(new FileWriter(file, true)); + bw.write(targetplayer.PlayerName+"\n"); + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + PluginMain.LastException=e; //2015.08.09. + } + SendMessage(player, "§6The flair has been set. Player: "+targetplayer.PlayerName+" Flair: "+flair+"§r"); + } + private static void DoSetFlair(Player player, String[] args) + { + //args[0] is "admin" - args[1] is "setflair" + if(args.length<4) + { + SendMessage(player, "§cUsage: /u admin setflair "); + return; + } + SetPlayerFlair(player, MaybeOfflinePlayer.AddPlayerIfNeeded(args[2]), args[3]); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/5/908d0453dd3e001517108d149b613203 b/.metadata/.plugins/org.eclipse.core.resources/.history/5/908d0453dd3e001517108d149b613203 new file mode 100644 index 0000000..b2f66e5 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/5/908d0453dd3e001517108d149b613203 @@ -0,0 +1,398 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStream; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLConnection; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + +import org.apache.commons.io.IOUtils; +import org.bukkit.entity.Player; +import org.bukkit.plugin.java.JavaPlugin; +import org.json.JSONArray; +import org.json.JSONObject; + +import com.palmergames.bukkit.towny.object.Town; +import com.palmergames.bukkit.towny.object.WorldCoord; + +public class PluginMain extends JavaPlugin +{ //Translated to Java: 2015.07.15. + //A user, which flair isn't obtainable: + //https://www.reddit.com/r/thebutton/comments/31c32v/i_pressed_the_button_without_really_thinking/ + private static PluginMain Instance; + // Fired when plugin is first enabled + @Override + public void onEnable() + { + System.out.println("The Button Auto-flair Plugin by NorbiPeti (:P)"); + getServer().getPluginManager().registerEvents(new PlayerListener(), this); + this.getCommand("u").setExecutor(new Commands()); + this.getCommand("u").setUsage(this.getCommand("u").getUsage().replace('&', '§')); + Instance=this; //2015.08.08. + LoadFiles(false); //2015.08.09. + Runnable r=new Runnable(){public void run(){ThreadMethod();}}; + Thread t=new Thread(r); + t.start(); + } + Boolean stop=false; + // Fired when plugin is disabled + @Override + public void onDisable() + { + SaveFiles(); //2015.08.09. + stop=true; + } + + public void ThreadMethod() //<-- 2015.07.16. + { + while(!stop) + { + try + { + String body=DownloadString("https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/autoflair_system_comment_your_minecraft_name_and/.json?limit=1000"); + JSONArray json=new JSONArray(body).getJSONObject(1).getJSONObject("data").getJSONArray("children"); + for(Object obj : json) + { + JSONObject item = (JSONObject)obj; + String author=item.getJSONObject("data").getString("author"); + String ign=item.getJSONObject("data").getString("body"); + int start = ign.indexOf("IGN:") + "IGN:".length(); + if(start==-1) + continue; //2015.08.09. + int end = ign.indexOf(' ', start); + if (end == -1 || end == start) + end=ign.indexOf('\n', start); //2015.07.15. + if (end == -1 || end == start) + ign = ign.substring(start); + else + ign = ign.substring(start, end); + ign = ign.trim(); + if(HasIGFlair(ign)) + continue; + try { + Thread.sleep(10); + } catch(InterruptedException ex) { + Thread.currentThread().interrupt(); + } + String[] flairdata = DownloadString("http://karmadecay.com/thebutton-data.php?users=" + author).replace("\"", "").split(":"); + String flair; + if(flairdata.length > 1) //2015.07.15. + flair = flairdata[1]; + else + flair=""; + if (flair != "-1") + flair = flair + "s"; + else + flair = "non-presser"; + String flairclass; + if(flairdata.length>2) + flairclass = flairdata[2]; + else + flairclass="unknown"; + SetFlair(ign, flair, flairclass, author); + } + Thread.sleep(10000); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + } + + public static Exception LastException; //2015.08.09. + + public String DownloadString(String urlstr) throws MalformedURLException, IOException + { + URL url = new URL(urlstr); + URLConnection con = url.openConnection(); + con.setRequestProperty("User-Agent", "TheButtonAutoFlair"); + InputStream in = con.getInputStream(); + String encoding = con.getContentEncoding(); + encoding = encoding == null ? "UTF-8" : encoding; + String body = IOUtils.toString(in, encoding); + in.close(); + return body; + } + + public static Map TownColors=new HashMap(); //2015.07.20. + public Boolean HasIGFlair(String playername) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + return p.Flair!=null; //2015.08.08. + } + + public void SetFlair(String playername, String text, String flairclass, String username) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + String finalflair; + p.FlairDecided=true; + switch(flairclass) + { + case "press-1": + finalflair="§c("+text+")§r"; + break; + case "press-2": + finalflair="§6("+text+")§r"; + break; + case "press-3": + finalflair="§e("+text+")§r"; + break; + case "press-4": + finalflair="§a("+text+")§r"; + break; + case "press-5": + finalflair="§9("+text+")§r"; + break; + 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; + case "undecided": //2015.08.09. + p.FlairDecided=false; + finalflair=""; + break; + default: + finalflair=""; + break; + } + if(finalflair.length()==0) //<-- 2015.07.20. + return; + p.Flair=finalflair; //2015.08.08. + p.UserName=username; //2015.08.08. + System.out.println("Added new flair to "+playername+": "+finalflair); + for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08. + { + if(player.getName().equals(playername)) + { + //AppendPlayerDisplayFlair(player, username, finalflair); + AppendPlayerDisplayFlair(p, player); + break; + } + } + } + + public static String GetFlair(Player player) + { //2015.07.16. + String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08. + return flair==null ? "" : flair; + } + + //public static void AppendPlayerDisplayFlair(Player player, String username, String flair) + public static void AppendPlayerDisplayFlair(MaybeOfflinePlayer player, Player p) //<-- 2015.08.09. + { + + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).IgnoredFlair) + return; + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).AcceptedFlair) + { + AppendPlayerDisplayFlairFinal(p, player.Flair); //2015.07.20. + if(!player.FlairDecided) + p.sendMessage("§9Your flair type is unknown. Are you a non-presser or a can't press? (/u nonpresser or /u cantpress)§r"); //2015.08.09. + } + else + p.sendMessage("§9Are you Reddit user "+player.UserName+"?§r §6Type /u accept or /u ignore§r"); + } + + private static void AppendPlayerDisplayFlairFinal(Player player, String flair) + { //2015.07.20. + String color = GetColorForTown(GetPlayerTown(player)); //TO!DO: Multiple colors put on first capital letters + String[] colors = color.substring(1).split("§"); + String displayname=player.getName(); //2015.08.08. + ArrayList Positions=new ArrayList<>(); + for(int i=0; i=colors.length) + { + int x=0; + for(int i=0; i GetPlayers() + { + return Instance.getServer().getOnlinePlayers(); + } + + public static void LoadFiles(boolean reload) //<-- 2015.08.09. + { + if(reload) + { //2015.08.09. + System.out.println("Auto-flair plugin cleanup for reloading..."); + MaybeOfflinePlayer.AllPlayers.clear(); + TownColors.clear(); + } + System.out.println("Loading files for auto-flair plugin..."); //2015.08.09. + try { + File file=new File("flairsaccepted.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + //System.out.println("Name: " + name); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("flairsignored.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsignored.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("autoflairconfig.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + TownColors.put(s[0], s[1]); + } + br.close(); + } + file=new File("autoflairdecisions.txt"); //2015.08.09. + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + MaybeOfflinePlayer.AddPlayerIfNeeded(s[0]).Flair=s[1]; //2015.08.09. + } + br.close(); + } + //throw new IOException("Test"); //2015.08.09. + System.out.println("Auto-flair plugin loaded files!"); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + public static void SaveFiles() //<-- 2015.08.09. + { + try + { + FileWriter fw; + fw = new FileWriter("flairsaccepted.txt"); + fw.close(); + fw = new FileWriter("flairsignored.txt"); + fw.close(); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + try { + File file=new File("flairsaccepted.txt"); + BufferedWriter bw=new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.AcceptedFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + file=new File("flairsignored.txt"); + bw = new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.IgnoredFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + public static void SetPlayerFlair(Player player, String flair) + { //2015.08.09. + + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/50/506a31a2883e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/50/506a31a2883e00151ce8ff6d4f74dabd deleted file mode 100644 index f163736..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/50/506a31a2883e00151ce8ff6d4f74dabd +++ /dev/null @@ -1,173 +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; - MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. - //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - if(p.Flair==null) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. - { - case "accept": - { - if(p.IgnoredFlair) - p.IgnoredFlair=false; //2015.08.08. - if(!p.AcceptedFlair) - { - String flair=p.Flair; //2015.08.08. - PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. - p.AcceptedFlair=true; //2015.08.08. - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("§cYou already have this user's flair.§r"); - break; - } - case "ignore": - { - if(p.AcceptedFlair) - p.AcceptedFlair=false; //2015.08.08. - if(!p.IgnoredFlair) - { - p.IgnoredFlair=true; - String flair=p.Flair; //2015.08.08. - PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. - player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); - } - else - player.sendMessage("§cYou already ignored this request.§r"); - break; - } - /*case "reload": //2015.07.20. - DoReload(player); - break;*/ - case "admin": //2015.08.09. - DoAdmin(player, args); - break; - default: - return false; - } - return true; - } - - /*if(args[0].toLowerCase()=="reload") - DoReload(null); //2015.07.20.*/ - else if(args[0].toLowerCase()=="admin") - DoAdmin(null, args); //2015.08.09. - return false; - } - private static void DoReload(Player player) - { //2015.07.20. - //if(player==null || player.isOp() || player.getName()=="NorbiPeti") - //{ - try - { - File file=new File("autoflairconfig.txt"); - if(file.exists()) - { - PluginMain.TownColors.clear(); - BufferedReader br=new BufferedReader(new FileReader(file)); - String line; - while((line=br.readLine())!=null) - { - String[] s=line.split(" "); - PluginMain.TownColors.put(s[0], s[1]); - } - br.close(); - for(Player p : PluginMain.GetPlayers()) - { - MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName()); - if(mp.Flair!=null) - { - String flair=mp.Flair; - PluginMain.RemovePlayerDisplayFlairFinal(p, flair); - PluginMain.AppendPlayerDisplayFlairFinal(p, flair); - } - } - String msg="§6Reloaded config file.§r"; - if(player!=null) - player.sendMessage(msg); - else - System.out.println(msg); - } - } - catch(Exception e) - { - System.out.println("Error!\n"+e); - if(player!=null) - player.sendMessage("§cAn error occured. See console for details.§r"); - } - //} - //else - //player.sendMessage("§cYou need to be OP to use this command.§r"); - } - private static void DoAdmin(Player player, String[] args) - { //2015.08.09. - if(player==null || player.isOp() || player.getName()=="NorbiPeti") - { - if(args.length==1) - { - String message="§cUsage: /u admin reload|playerinfo§r"; - if(player==null) - System.out.println(message); - else - player.sendMessage(message); - return; - } - //args[0] is "admin" - switch(args[1].toLowerCase()) - { - case "reload": - DoReload(player); - break; - case "playerinfo": - DoPlayerInfo(player, args); - break; - } - } - else - player.sendMessage("§cYou need to be OP to use this command.§r"); - } - private static void DoPlayerInfo(Player player, String[] args) - { //2015.08.09. - //args[0] is "admin" - args[1] is "playerinfo" - if(args.length==2) - { - String message="§cUsage: /u admin playerinfo §r"; - if(player==null) - System.out.println(message); - else - player.sendMessage(message); - return; - } - if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2])) - { - String message="§cPlayer not found: "+args[2]+"§r"; - if(player==null) - System.out.println(message); - else - player.sendMessage(message); - return; - } - MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]); - return; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/51/50cc60cf883e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/51/50cc60cf883e00151ce8ff6d4f74dabd deleted file mode 100644 index b8cf010..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/51/50cc60cf883e00151ce8ff6d4f74dabd +++ /dev/null @@ -1,170 +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; - MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. - //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - if(p.Flair==null) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. - { - case "accept": - { - if(p.IgnoredFlair) - p.IgnoredFlair=false; //2015.08.08. - if(!p.AcceptedFlair) - { - String flair=p.Flair; //2015.08.08. - PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. - p.AcceptedFlair=true; //2015.08.08. - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("§cYou already have this user's flair.§r"); - break; - } - case "ignore": - { - if(p.AcceptedFlair) - p.AcceptedFlair=false; //2015.08.08. - if(!p.IgnoredFlair) - { - p.IgnoredFlair=true; - String flair=p.Flair; //2015.08.08. - PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. - player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); - } - else - player.sendMessage("§cYou already ignored this request.§r"); - break; - } - /*case "reload": //2015.07.20. - DoReload(player); - break;*/ - case "admin": //2015.08.09. - DoAdmin(player, args); - break; - default: - return false; - } - return true; - } - - /*if(args[0].toLowerCase()=="reload") - DoReload(null); //2015.07.20.*/ - else if(args[0].toLowerCase()=="admin") - DoAdmin(null, args); //2015.08.09. - return false; - } - private static void DoReload(Player player) - { //2015.07.20. - //if(player==null || player.isOp() || player.getName()=="NorbiPeti") - //{ - try - { - File file=new File("autoflairconfig.txt"); - if(file.exists()) - { - PluginMain.TownColors.clear(); - BufferedReader br=new BufferedReader(new FileReader(file)); - String line; - while((line=br.readLine())!=null) - { - String[] s=line.split(" "); - PluginMain.TownColors.put(s[0], s[1]); - } - br.close(); - for(Player p : PluginMain.GetPlayers()) - { - MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName()); - if(mp.Flair!=null) - { - String flair=mp.Flair; - PluginMain.RemovePlayerDisplayFlairFinal(p, flair); - PluginMain.AppendPlayerDisplayFlairFinal(p, flair); - } - } - String msg="§6Reloaded config file.§r"; - if(player!=null) - player.sendMessage(msg); - else - System.out.println(msg); - } - } - catch(Exception e) - { - System.out.println("Error!\n"+e); - if(player!=null) - player.sendMessage("§cAn error occured. See console for details.§r"); - } - //} - //else - //player.sendMessage("§cYou need to be OP to use this command.§r"); - } - private static void DoAdmin(Player player, String[] args) - { //2015.08.09. - if(player==null || player.isOp() || player.getName()=="NorbiPeti") - { - if(args.length==1) - { - String message="§cUsage: /u admin reload|playerinfo§r"; - SendMessage(player, message); - return; - } - //args[0] is "admin" - switch(args[1].toLowerCase()) - { - case "reload": - DoReload(player); - break; - case "playerinfo": - DoPlayerInfo(player, args); - break; - } - } - else - player.sendMessage("§cYou need to be OP to use this command.§r"); - } - private static void DoPlayerInfo(Player player, String[] args) - { //2015.08.09. - //args[0] is "admin" - args[1] is "playerinfo" - if(args.length==2) - { - String message="§cUsage: /u admin playerinfo §r"; - SendMessage(player, message); - } - if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2])) - { - String message="§cPlayer not found: "+args[2]+"§r"; - SendMessage(player, message); - } - MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]); - return; - } - private static void SendMessage(Player player, String message) - { //2015.08.09. - if(player==null) - System.out.println(message); - else - player.sendMessage(message); - return; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/53/d0e8e8e2873e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/53/d0e8e8e2873e00151ce8ff6d4f74dabd deleted file mode 100644 index 2de7e2d..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/53/d0e8e8e2873e00151ce8ff6d4f74dabd +++ /dev/null @@ -1,156 +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; - MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. - //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - if(p.Flair==null) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. - { - case "accept": - { - if(p.IgnoredFlair) - p.IgnoredFlair=false; //2015.08.08. - if(!p.AcceptedFlair) - { - String flair=p.Flair; //2015.08.08. - PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. - p.AcceptedFlair=true; //2015.08.08. - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("§cYou already have this user's flair.§r"); - break; - } - case "ignore": - { - if(p.AcceptedFlair) - p.AcceptedFlair=false; //2015.08.08. - if(!p.IgnoredFlair) - { - p.IgnoredFlair=true; - String flair=p.Flair; //2015.08.08. - PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. - player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); - } - else - player.sendMessage("§cYou already ignored this request.§r"); - break; - } - /*case "reload": //2015.07.20. - DoReload(player); - break;*/ - case "admin": //2015.08.09. - DoAdmin(player, args); - break; - default: - return false; - } - return true; - } - - /*if(args[0].toLowerCase()=="reload") - DoReload(null); //2015.07.20.*/ - else if(args[0].toLowerCase()=="admin") - DoAdmin(null, args); //2015.08.09. - return false; - } - private static void DoReload(Player player) - { //2015.07.20. - //if(player==null || player.isOp() || player.getName()=="NorbiPeti") - //{ - try - { - File file=new File("autoflairconfig.txt"); - if(file.exists()) - { - PluginMain.TownColors.clear(); - BufferedReader br=new BufferedReader(new FileReader(file)); - String line; - while((line=br.readLine())!=null) - { - String[] s=line.split(" "); - PluginMain.TownColors.put(s[0], s[1]); - } - br.close(); - for(Player p : PluginMain.GetPlayers()) - { - MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName()); - if(mp.Flair!=null) - { - String flair=mp.Flair; - PluginMain.RemovePlayerDisplayFlairFinal(p, flair); - PluginMain.AppendPlayerDisplayFlairFinal(p, flair); - } - } - String msg="§6Reloaded config file.§r"; - if(player!=null) - player.sendMessage(msg); - else - System.out.println(msg); - } - } - catch(Exception e) - { - System.out.println("Error!\n"+e); - if(player!=null) - player.sendMessage("§cAn error occured. See console for details.§r"); - } - //} - //else - //player.sendMessage("§cYou need to be OP to use this command.§r"); - } - private static void DoAdmin(Player player, String[] args) - { //2015.08.09. - if(player==null || player.isOp() || player.getName()=="NorbiPeti") - { - if(args.length==1) - { - - } - //args[0] is "admin" - switch(args[1].toLowerCase()) - { - case "reload": - DoReload(player); - break; - case "playerinfo": - DoPlayerInfo(player, args); - break; - } - } - else - player.sendMessage("§cYou need to be OP to use this command.§r"); - } - private static void DoPlayerInfo(Player player, String[] args) - { //2015.08.09. - //args[0] is "admin" - args[1] is "playerinfo" - if(args.length==2) - { - String message="§cUsage: /u admin playerinfo §r"; - if(player==null) - System.out.println(message); - else - player.sendMessage(message); - } - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/55/c0fc6b25cd3e001518fa86d7ae2a1cf8 b/.metadata/.plugins/org.eclipse.core.resources/.history/55/c0fc6b25cd3e001518fa86d7ae2a1cf8 new file mode 100644 index 0000000..6549d0e --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/55/c0fc6b25cd3e001518fa86d7ae2a1cf8 @@ -0,0 +1,24 @@ +package tk.sznp.thebuttonautoflair; + +import java.util.HashMap; + +public class MaybeOfflinePlayer +{ //2015.08.08. + public String PlayerName; + public String UserName; + public String Flair; //If the user comments their name, it gets set, it doesn't matter if they accepted it or not + public boolean AcceptedFlair; + public boolean IgnoredFlair; + public static HashMap AllPlayers=new HashMap<>(); //2015.08.08. + public static MaybeOfflinePlayer AddPlayerIfNeeded(String playername) + { + if(!AllPlayers.containsKey(playername)) + { + MaybeOfflinePlayer player=new MaybeOfflinePlayer(); + player.PlayerName=playername; + AllPlayers.put(playername, player); + return player; + } + return AllPlayers.get(playername); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/56/10a840c1de3e001517108d149b613203 b/.metadata/.plugins/org.eclipse.core.resources/.history/56/10a840c1de3e001517108d149b613203 new file mode 100644 index 0000000..587bd04 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/56/10a840c1de3e001517108d149b613203 @@ -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.WorldCoord; + +public class PluginMain extends JavaPlugin +{ //Translated to Java: 2015.07.15. + //A user, which flair isn't obtainable: + //https://www.reddit.com/r/thebutton/comments/31c32v/i_pressed_the_button_without_really_thinking/ + private static PluginMain Instance; + // Fired when plugin is first enabled + @Override + public void onEnable() + { + System.out.println("The Button Auto-flair Plugin by NorbiPeti (:P)"); + getServer().getPluginManager().registerEvents(new PlayerListener(), this); + this.getCommand("u").setExecutor(new Commands()); + this.getCommand("u").setUsage(this.getCommand("u").getUsage().replace('&', '§')); + Instance=this; //2015.08.08. + LoadFiles(false); //2015.08.09. + Runnable r=new Runnable(){public void run(){ThreadMethod();}}; + Thread t=new Thread(r); + t.start(); + } + Boolean stop=false; + // Fired when plugin is disabled + @Override + public void onDisable() + { + SaveFiles(); //2015.08.09. + stop=true; + } + + public void ThreadMethod() //<-- 2015.07.16. + { + while(!stop) + { + try + { + String body=DownloadString("https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/autoflair_system_comment_your_minecraft_name_and/.json?limit=1000"); + JSONArray json=new JSONArray(body).getJSONObject(1).getJSONObject("data").getJSONArray("children"); + for(Object obj : json) + { + JSONObject item = (JSONObject)obj; + String author=item.getJSONObject("data").getString("author"); + String ign=item.getJSONObject("data").getString("body"); + int start = ign.indexOf("IGN:") + "IGN:".length(); + if(start==-1) + continue; //2015.08.09. + int end = ign.indexOf(' ', start); + if (end == -1 || end == start) + end=ign.indexOf('\n', start); //2015.07.15. + if (end == -1 || end == start) + ign = ign.substring(start); + else + ign = ign.substring(start, end); + ign = ign.trim(); + if(HasIGFlair(ign)) + continue; + try { + Thread.sleep(10); + } catch(InterruptedException ex) { + Thread.currentThread().interrupt(); + } + String[] flairdata = DownloadString("http://karmadecay.com/thebutton-data.php?users=" + author).replace("\"", "").split(":"); + String flair; + if(flairdata.length > 1) //2015.07.15. + flair = flairdata[1]; + else + flair=""; + if (flair != "-1") + flair = flair + "s"; + else + flair = "non-presser"; + String flairclass; + if(flairdata.length>2) + flairclass = flairdata[2]; + else + flairclass="unknown"; + SetFlair(ign, flair, flairclass, author); + } + Thread.sleep(10000); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + } + + public static Exception LastException; //2015.08.09. + + public String DownloadString(String urlstr) throws MalformedURLException, IOException + { + URL url = new URL(urlstr); + URLConnection con = url.openConnection(); + con.setRequestProperty("User-Agent", "TheButtonAutoFlair"); + InputStream in = con.getInputStream(); + String encoding = con.getContentEncoding(); + encoding = encoding == null ? "UTF-8" : encoding; + String body = IOUtils.toString(in, encoding); + in.close(); + return body; + } + + public static Map TownColors=new HashMap(); //2015.07.20. + public Boolean HasIGFlair(String playername) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + return p.Flair!=null; //2015.08.08. + } + + public void SetFlair(String playername, String text, String flairclass, String username) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + String finalflair; + p.FlairDecided=true; + switch(flairclass) + { + case "press-1": + finalflair="§c("+text+")§r"; + break; + case "press-2": + finalflair="§6("+text+")§r"; + break; + case "press-3": + finalflair="§e("+text+")§r"; + break; + case "press-4": + finalflair="§a("+text+")§r"; + break; + case "press-5": + finalflair="§9("+text+")§r"; + break; + 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; + case "undecided": //2015.08.09. + p.FlairDecided=false; + finalflair=""; + break; + default: + finalflair=""; + break; + } + if(finalflair.length()==0) //<-- 2015.07.20. + return; + p.Flair=finalflair; //2015.08.08. + p.UserName=username; //2015.08.08. + System.out.println("Added new flair to "+playername+": "+finalflair); + for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08. + { + if(player.getName().equals(playername)) + { + //AppendPlayerDisplayFlair(player, username, finalflair); + AppendPlayerDisplayFlair(p, player); + break; + } + } + } + + public static String GetFlair(Player player) + { //2015.07.16. + String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08. + return flair==null ? "" : flair; + } + + //public static void AppendPlayerDisplayFlair(Player player, String username, String flair) + public static void AppendPlayerDisplayFlair(MaybeOfflinePlayer player, Player p) //<-- 2015.08.09. + { + + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).IgnoredFlair) + return; + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).AcceptedFlair) + { + AppendPlayerDisplayFlairFinal(p, player.Flair); //2015.07.20. + if(!player.FlairDecided) + p.sendMessage("§9Your flair type is unknown. Are you a non-presser or a can't press? (/u nonpresser or /u cantpress)§r"); //2015.08.09. + } + else + p.sendMessage("§9Are you Reddit user "+player.UserName+"?§r §6Type /u accept or /u ignore§r"); + } + + private static void AppendPlayerDisplayFlairFinal(Player player, String flair) + { //2015.07.20. + String color = GetColorForTown(GetPlayerTown(player)); //TO!DO: Multiple colors put on first capital letters + String[] colors = color.substring(1).split("§"); + String displayname=player.getName(); //2015.08.08. + ArrayList Positions=new ArrayList<>(); + for(int i=0; i=colors.length) + { + int x=0; + for(int i=0; i GetPlayers() + { + return Instance.getServer().getOnlinePlayers(); + } + + public static void LoadFiles(boolean reload) //<-- 2015.08.09. + { + if(reload) + { //2015.08.09. + System.out.println("Auto-flair plugin cleanup for reloading..."); + MaybeOfflinePlayer.AllPlayers.clear(); + TownColors.clear(); + } + System.out.println("Loading files for auto-flair plugin..."); //2015.08.09. + try { + File file=new File("flairsaccepted.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + //System.out.println("Name: " + name); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("flairsignored.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsignored.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("autoflairconfig.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + TownColors.put(s[0], s[1]); + } + br.close(); + } + file=new File("customflairs.txt"); //2015.08.09. + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + MaybeOfflinePlayer.AddPlayerIfNeeded(s[0]).Flair=s[1]; //2015.08.09. + } + br.close(); + } + //throw new IOException("Test"); //2015.08.09. + System.out.println("Auto-flair plugin loaded files!"); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + public static void SaveFiles() //<-- 2015.08.09. + { + try + { + FileWriter fw; + fw = new FileWriter("flairsaccepted.txt"); + fw.close(); + fw = new FileWriter("flairsignored.txt"); + fw.close(); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + try { + File file=new File("flairsaccepted.txt"); + BufferedWriter bw=new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.AcceptedFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + file=new File("flairsignored.txt"); + bw = new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.IgnoredFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + public static void SetPlayerFlair(Player player, String flair) + { //2015.08.09. + flair=flair.replace('&', '§'); + MaybeOfflinePlayer.AddPlayerIfNeeded(player.getName()).Flair=flair; + File file=new File("customflairs.txt"); + if() + try { + BufferedWriter bw; + bw = new BufferedWriter(new FileWriter(file, true)); + bw.write(player.getName()+"\n"); + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + public static boolean RemoveLineFromFile(String file) + { + File inputFile = new File(file); + File tempFile = new File("_temp.txt"); + + try { + BufferedReader reader = new BufferedReader(new FileReader(inputFile)); + BufferedWriter writer = new BufferedWriter(new FileWriter(tempFile)); + + String lineToRemove = "bbb"; + String currentLine; + + while((currentLine = reader.readLine()) != null) { + // trim newline when comparing with lineToRemove + String trimmedLine = currentLine.trim(); + if(trimmedLine.equals(lineToRemove)) continue; + writer.write(currentLine + System.getProperty("line.separator")); + } + writer.close(); + reader.close(); + return tempFile.renameTo(inputFile); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + return false; + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/56/205a1cf9d13e001518fa86d7ae2a1cf8 b/.metadata/.plugins/org.eclipse.core.resources/.history/56/205a1cf9d13e001518fa86d7ae2a1cf8 new file mode 100644 index 0000000..d7286f9 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/56/205a1cf9d13e001518fa86d7ae2a1cf8 @@ -0,0 +1,374 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStream; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLConnection; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + +import org.apache.commons.io.IOUtils; +import org.bukkit.entity.Player; +import org.bukkit.plugin.java.JavaPlugin; +import org.json.JSONArray; +import org.json.JSONObject; + +import com.palmergames.bukkit.towny.object.Town; +import com.palmergames.bukkit.towny.object.WorldCoord; + +public class PluginMain extends JavaPlugin +{ //Translated to Java: 2015.07.15. + //A user, which flair isn't obtainable: + //https://www.reddit.com/r/thebutton/comments/31c32v/i_pressed_the_button_without_really_thinking/ + private static PluginMain Instance; + // Fired when plugin is first enabled + @Override + public void onEnable() + { + System.out.println("The Button Auto-flair Plugin by NorbiPeti (:P)"); + getServer().getPluginManager().registerEvents(new PlayerListener(), this); + this.getCommand("u").setExecutor(new Commands()); + this.getCommand("u").setUsage(this.getCommand("u").getUsage().replace('&', '§')); + Instance=this; //2015.08.08. + LoadFiles(false); //2015.08.09. + Runnable r=new Runnable(){public void run(){ThreadMethod();}}; + Thread t=new Thread(r); + t.start(); + } + Boolean stop=false; + // Fired when plugin is disabled + @Override + public void onDisable() + { + try + { + FileWriter fw; + fw = new FileWriter("flairsaccepted.txt"); + fw.close(); + fw = new FileWriter("flairsignored.txt"); + fw.close(); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + try { + File file=new File("flairsaccepted.txt"); + BufferedWriter bw=new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.AcceptedFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + file=new File("flairsignored.txt"); + bw = new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.IgnoredFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + stop=true; + } + + public void ThreadMethod() //<-- 2015.07.16. + { + while(!stop) + { + try + { + String body=DownloadString("https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/autoflair_system_comment_your_minecraft_name_and/.json?limit=1000"); + JSONArray json=new JSONArray(body).getJSONObject(1).getJSONObject("data").getJSONArray("children"); + for(Object obj : json) + { + JSONObject item = (JSONObject)obj; + String author=item.getJSONObject("data").getString("author"); + String ign=item.getJSONObject("data").getString("body"); + int start = ign.indexOf("IGN:") + "IGN:".length(); + int end = ign.indexOf(' ', start); + if (end == -1 || end == start) + end=ign.indexOf('\n', start); //2015.07.15. + if (end == -1 || end == start) + ign = ign.substring(start); + else + ign = ign.substring(start, end); + ign = ign.trim(); + if(HasIGFlair(ign)) + continue; + try { + Thread.sleep(10); + } catch(InterruptedException ex) { + Thread.currentThread().interrupt(); + } + String[] flairdata = DownloadString("http://karmadecay.com/thebutton-data.php?users=" + author).replace("\"", "").split(":"); + String flair; + if(flairdata.length > 1) //2015.07.15. + flair = flairdata[1]; + else + flair=""; + if (flair != "-1") + flair = flair + "s"; + else + flair = "non-presser"; + String flairclass; + if(flairdata.length>2) + flairclass = flairdata[2]; + else + flairclass="unknown"; + SetFlair(ign, flair, flairclass, author); + } + Thread.sleep(10000); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + } + + public static Exception LastException; //2015.08.09. + + public String DownloadString(String urlstr) throws MalformedURLException, IOException + { + URL url = new URL(urlstr); + URLConnection con = url.openConnection(); + con.setRequestProperty("User-Agent", "TheButtonAutoFlair"); + InputStream in = con.getInputStream(); + String encoding = con.getContentEncoding(); + encoding = encoding == null ? "UTF-8" : encoding; + String body = IOUtils.toString(in, encoding); + in.close(); + return body; + } + + public static Map TownColors=new HashMap(); //2015.07.20. + public Boolean HasIGFlair(String playername) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + return p.Flair!=null; //2015.08.08. + } + + public void SetFlair(String playername, String text, String flairclass, String username) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + String finalflair; + p.FlairDecided=true; + switch(flairclass) + { + case "press-1": + finalflair="§c("+text+")§r"; + break; + case "press-2": + finalflair="§6("+text+")§r"; + break; + case "press-3": + finalflair="§e("+text+")§r"; + break; + case "press-4": + finalflair="§a("+text+")§r"; + break; + case "press-5": + finalflair="§9("+text+")§r"; + break; + 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; + case "undecided": //2015.08.09. + p.FlairDecided=false; + finalflair=""; + break; + default: + finalflair=""; + break; + } + if(finalflair.length()==0) //<-- 2015.07.20. + return; + p.Flair=finalflair; //2015.08.08. + p.UserName=username; //2015.08.08. + System.out.println("Added new flair to "+playername+": "+finalflair); + for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08. + { + if(player.getName().equals(playername)) + { + //AppendPlayerDisplayFlair(player, username, finalflair); + AppendPlayerDisplayFlair(p, player); + break; + } + } + } + + public static String GetFlair(Player player) + { //2015.07.16. + String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08. + return flair==null ? "" : flair; + } + + //public static void AppendPlayerDisplayFlair(Player player, String username, String flair) + public static void AppendPlayerDisplayFlair(MaybeOfflinePlayer player, Player p) //<-- 2015.08.09. + { + + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).IgnoredFlair) + return; + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).AcceptedFlair) + { + AppendPlayerDisplayFlairFinal(p, player.Flair); //2015.07.20. + if(!player.FlairDecided) + p.sendMessage("§9Your flair type is unknown. Are you a non-presser or a can't press? (/u nonpresser or /u cantpress)§r"); //2015.08.09. + } + else + p.sendMessage("§9Are you Reddit user "+player.UserName+"?§r §6Type /u accept or /u ignore§r"); + } + + private static void AppendPlayerDisplayFlairFinal(Player player, String flair) + { //2015.07.20. + String color = GetColorForTown(GetPlayerTown(player)); //TO!DO: Multiple colors put on first capital letters + String[] colors = color.substring(1).split("§"); + String displayname=player.getName(); //2015.08.08. + ArrayList Positions=new ArrayList<>(); + for(int i=0; i=colors.length) + { + int x=0; + for(int i=0; i GetPlayers() + { + return Instance.getServer().getOnlinePlayers(); + } + + public static void LoadFiles(boolean reload) //<-- 2015.08.09. + { + if(reload) + { + System.out.println("Reloading files for auto-flair plugin..."); //2015.08.09. + MaybeOfflinePlayer.AllPlayers.clear(); //2015.08.09. + } + System.out.println("Loading files for auto-flair plugin..."); //2015.08.09. + try { + File file=new File("flairsaccepted.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + //System.out.println("Name: " + name); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("flairsignored.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsignored.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("autoflairconfig.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + TownColors.put(s[0], s[1]); + } + br.close(); + } + //throw new IOException("Test"); //2015.08.09. + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/56/d0b1ba48873e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/56/d0b1ba48873e00151ce8ff6d4f74dabd deleted file mode 100644 index 2c6aa0e..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/56/d0b1ba48873e00151ce8ff6d4f74dabd +++ /dev/null @@ -1,137 +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; - MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. - //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - if(p.Flair==null) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. - { - case "accept": - { - if(p.IgnoredFlair) - p.IgnoredFlair=false; //2015.08.08. - if(!p.AcceptedFlair) - { - String flair=p.Flair; //2015.08.08. - PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. - p.AcceptedFlair=true; //2015.08.08. - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("§cYou already have this user's flair.§r"); - break; - } - case "ignore": - { - if(p.AcceptedFlair) - p.AcceptedFlair=false; //2015.08.08. - if(!p.IgnoredFlair) - { - p.IgnoredFlair=true; - String flair=p.Flair; //2015.08.08. - PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. - player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); - } - else - player.sendMessage("§cYou already ignored this request.§r"); - break; - } - /*case "reload": //2015.07.20. - DoReload(player); - break;*/ - case "admin": //2015.08.09. - DoAdmin(player, args); - break; - default: - return false; - } - return true; - } - - /*if(args[0].toLowerCase()=="reload") - DoReload(null); //2015.07.20.*/ - else if(args[0].toLowerCase()=="admin") - DoAdmin(null, args); //2015.08.09. - return false; - } - private static void DoReload(Player player) - { //2015.07.20. - //if(player==null || player.isOp() || player.getName()=="NorbiPeti") - //{ - try - { - File file=new File("autoflairconfig.txt"); - if(file.exists()) - { - PluginMain.TownColors.clear(); - BufferedReader br=new BufferedReader(new FileReader(file)); - String line; - while((line=br.readLine())!=null) - { - String[] s=line.split(" "); - PluginMain.TownColors.put(s[0], s[1]); - } - br.close(); - for(Player p : PluginMain.GetPlayers()) - { - MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName()); - if(mp.Flair!=null) - { - String flair=mp.Flair; - PluginMain.RemovePlayerDisplayFlairFinal(p, flair); - PluginMain.AppendPlayerDisplayFlairFinal(p, flair); - } - } - String msg="§6Reloaded config file.§r"; - if(player!=null) - player.sendMessage(msg); - else - System.out.println(msg); - } - } - catch(Exception e) - { - System.out.println("Error!\n"+e); - if(player!=null) - player.sendMessage("§cAn error occured. See console for details.§r"); - } - //} - //else - //player.sendMessage("§cYou need to be OP to use this command.§r"); - } - private static void DoAdmin(Player player, String[] args) - { - if(player==null || player.isOp() || player.getName()=="NorbiPeti") - { - //args[0] is "admin" - switch(args[1].toLowerCase()) - { - case "reload": - DoReload(player); - case " - } - } - else - player.sendMessage("§cYou need to be OP to use this command.§r"); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/58/107b898edc3e001517108d149b613203 b/.metadata/.plugins/org.eclipse.core.resources/.history/58/107b898edc3e001517108d149b613203 new file mode 100644 index 0000000..3a0c2b0 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/58/107b898edc3e001517108d149b613203 @@ -0,0 +1,394 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStream; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLConnection; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + +import org.apache.commons.io.IOUtils; +import org.bukkit.entity.Player; +import org.bukkit.plugin.java.JavaPlugin; +import org.json.JSONArray; +import org.json.JSONObject; + +import com.palmergames.bukkit.towny.object.Town; +import com.palmergames.bukkit.towny.object.WorldCoord; + +public class PluginMain extends JavaPlugin +{ //Translated to Java: 2015.07.15. + //A user, which flair isn't obtainable: + //https://www.reddit.com/r/thebutton/comments/31c32v/i_pressed_the_button_without_really_thinking/ + private static PluginMain Instance; + // Fired when plugin is first enabled + @Override + public void onEnable() + { + System.out.println("The Button Auto-flair Plugin by NorbiPeti (:P)"); + getServer().getPluginManager().registerEvents(new PlayerListener(), this); + this.getCommand("u").setExecutor(new Commands()); + this.getCommand("u").setUsage(this.getCommand("u").getUsage().replace('&', '§')); + Instance=this; //2015.08.08. + LoadFiles(false); //2015.08.09. + Runnable r=new Runnable(){public void run(){ThreadMethod();}}; + Thread t=new Thread(r); + t.start(); + } + Boolean stop=false; + // Fired when plugin is disabled + @Override + public void onDisable() + { + SaveFiles(); //2015.08.09. + stop=true; + } + + public void ThreadMethod() //<-- 2015.07.16. + { + while(!stop) + { + try + { + String body=DownloadString("https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/autoflair_system_comment_your_minecraft_name_and/.json?limit=1000"); + JSONArray json=new JSONArray(body).getJSONObject(1).getJSONObject("data").getJSONArray("children"); + for(Object obj : json) + { + JSONObject item = (JSONObject)obj; + String author=item.getJSONObject("data").getString("author"); + String ign=item.getJSONObject("data").getString("body"); + int start = ign.indexOf("IGN:") + "IGN:".length(); + if(start==-1) + continue; //2015.08.09. + int end = ign.indexOf(' ', start); + if (end == -1 || end == start) + end=ign.indexOf('\n', start); //2015.07.15. + if (end == -1 || end == start) + ign = ign.substring(start); + else + ign = ign.substring(start, end); + ign = ign.trim(); + if(HasIGFlair(ign)) + continue; + try { + Thread.sleep(10); + } catch(InterruptedException ex) { + Thread.currentThread().interrupt(); + } + String[] flairdata = DownloadString("http://karmadecay.com/thebutton-data.php?users=" + author).replace("\"", "").split(":"); + String flair; + if(flairdata.length > 1) //2015.07.15. + flair = flairdata[1]; + else + flair=""; + if (flair != "-1") + flair = flair + "s"; + else + flair = "non-presser"; + String flairclass; + if(flairdata.length>2) + flairclass = flairdata[2]; + else + flairclass="unknown"; + SetFlair(ign, flair, flairclass, author); + } + Thread.sleep(10000); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + } + + public static Exception LastException; //2015.08.09. + + public String DownloadString(String urlstr) throws MalformedURLException, IOException + { + URL url = new URL(urlstr); + URLConnection con = url.openConnection(); + con.setRequestProperty("User-Agent", "TheButtonAutoFlair"); + InputStream in = con.getInputStream(); + String encoding = con.getContentEncoding(); + encoding = encoding == null ? "UTF-8" : encoding; + String body = IOUtils.toString(in, encoding); + in.close(); + return body; + } + + public static Map TownColors=new HashMap(); //2015.07.20. + public Boolean HasIGFlair(String playername) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + return p.Flair!=null; //2015.08.08. + } + + public void SetFlair(String playername, String text, String flairclass, String username) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + String finalflair; + p.FlairDecided=true; + switch(flairclass) + { + case "press-1": + finalflair="§c("+text+")§r"; + break; + case "press-2": + finalflair="§6("+text+")§r"; + break; + case "press-3": + finalflair="§e("+text+")§r"; + break; + case "press-4": + finalflair="§a("+text+")§r"; + break; + case "press-5": + finalflair="§9("+text+")§r"; + break; + 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; + case "undecided": //2015.08.09. + p.FlairDecided=false; + finalflair=""; + break; + default: + finalflair=""; + break; + } + if(finalflair.length()==0) //<-- 2015.07.20. + return; + p.Flair=finalflair; //2015.08.08. + p.UserName=username; //2015.08.08. + System.out.println("Added new flair to "+playername+": "+finalflair); + for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08. + { + if(player.getName().equals(playername)) + { + //AppendPlayerDisplayFlair(player, username, finalflair); + AppendPlayerDisplayFlair(p, player); + break; + } + } + } + + public static String GetFlair(Player player) + { //2015.07.16. + String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08. + return flair==null ? "" : flair; + } + + //public static void AppendPlayerDisplayFlair(Player player, String username, String flair) + public static void AppendPlayerDisplayFlair(MaybeOfflinePlayer player, Player p) //<-- 2015.08.09. + { + + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).IgnoredFlair) + return; + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).AcceptedFlair) + { + AppendPlayerDisplayFlairFinal(p, player.Flair); //2015.07.20. + if(!player.FlairDecided) + p.sendMessage("§9Your flair type is unknown. Are you a non-presser or a can't press? (/u nonpresser or /u cantpress)§r"); //2015.08.09. + } + else + p.sendMessage("§9Are you Reddit user "+player.UserName+"?§r §6Type /u accept or /u ignore§r"); + } + + private static void AppendPlayerDisplayFlairFinal(Player player, String flair) + { //2015.07.20. + String color = GetColorForTown(GetPlayerTown(player)); //TO!DO: Multiple colors put on first capital letters + String[] colors = color.substring(1).split("§"); + String displayname=player.getName(); //2015.08.08. + ArrayList Positions=new ArrayList<>(); + for(int i=0; i=colors.length) + { + int x=0; + for(int i=0; i GetPlayers() + { + return Instance.getServer().getOnlinePlayers(); + } + + public static void LoadFiles(boolean reload) //<-- 2015.08.09. + { + if(reload) + { //2015.08.09. + System.out.println("Auto-flair plugin cleanup for reloading..."); + MaybeOfflinePlayer.AllPlayers.clear(); + TownColors.clear(); + } + System.out.println("Loading files for auto-flair plugin..."); //2015.08.09. + try { + File file=new File("flairsaccepted.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + //System.out.println("Name: " + name); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("flairsignored.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsignored.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("autoflairconfig.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + TownColors.put(s[0], s[1]); + } + br.close(); + } + file=new File("autoflairdecisions.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + TownColors.put(s[0], s[1]); + } + br.close(); + } + //throw new IOException("Test"); //2015.08.09. + System.out.println("Auto-flair plugin loaded files!"); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + public static void SaveFiles() //<-- 2015.08.09. + { + try + { + FileWriter fw; + fw = new FileWriter("flairsaccepted.txt"); + fw.close(); + fw = new FileWriter("flairsignored.txt"); + fw.close(); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + try { + File file=new File("flairsaccepted.txt"); + BufferedWriter bw=new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.AcceptedFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + file=new File("flairsignored.txt"); + bw = new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.IgnoredFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/59/90935a89dc3e001517108d149b613203 b/.metadata/.plugins/org.eclipse.core.resources/.history/59/90935a89dc3e001517108d149b613203 new file mode 100644 index 0000000..abf639b --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/59/90935a89dc3e001517108d149b613203 @@ -0,0 +1,394 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStream; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLConnection; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + +import org.apache.commons.io.IOUtils; +import org.bukkit.entity.Player; +import org.bukkit.plugin.java.JavaPlugin; +import org.json.JSONArray; +import org.json.JSONObject; + +import com.palmergames.bukkit.towny.object.Town; +import com.palmergames.bukkit.towny.object.WorldCoord; + +public class PluginMain extends JavaPlugin +{ //Translated to Java: 2015.07.15. + //A user, which flair isn't obtainable: + //https://www.reddit.com/r/thebutton/comments/31c32v/i_pressed_the_button_without_really_thinking/ + private static PluginMain Instance; + // Fired when plugin is first enabled + @Override + public void onEnable() + { + System.out.println("The Button Auto-flair Plugin by NorbiPeti (:P)"); + getServer().getPluginManager().registerEvents(new PlayerListener(), this); + this.getCommand("u").setExecutor(new Commands()); + this.getCommand("u").setUsage(this.getCommand("u").getUsage().replace('&', '§')); + Instance=this; //2015.08.08. + LoadFiles(false); //2015.08.09. + Runnable r=new Runnable(){public void run(){ThreadMethod();}}; + Thread t=new Thread(r); + t.start(); + } + Boolean stop=false; + // Fired when plugin is disabled + @Override + public void onDisable() + { + SaveFiles(); //2015.08.09. + stop=true; + } + + public void ThreadMethod() //<-- 2015.07.16. + { + while(!stop) + { + try + { + String body=DownloadString("https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/autoflair_system_comment_your_minecraft_name_and/.json?limit=1000"); + JSONArray json=new JSONArray(body).getJSONObject(1).getJSONObject("data").getJSONArray("children"); + for(Object obj : json) + { + JSONObject item = (JSONObject)obj; + String author=item.getJSONObject("data").getString("author"); + String ign=item.getJSONObject("data").getString("body"); + int start = ign.indexOf("IGN:") + "IGN:".length(); + if(start==-1) + continue; //2015.08.09. + int end = ign.indexOf(' ', start); + if (end == -1 || end == start) + end=ign.indexOf('\n', start); //2015.07.15. + if (end == -1 || end == start) + ign = ign.substring(start); + else + ign = ign.substring(start, end); + ign = ign.trim(); + if(HasIGFlair(ign)) + continue; + try { + Thread.sleep(10); + } catch(InterruptedException ex) { + Thread.currentThread().interrupt(); + } + String[] flairdata = DownloadString("http://karmadecay.com/thebutton-data.php?users=" + author).replace("\"", "").split(":"); + String flair; + if(flairdata.length > 1) //2015.07.15. + flair = flairdata[1]; + else + flair=""; + if (flair != "-1") + flair = flair + "s"; + else + flair = "non-presser"; + String flairclass; + if(flairdata.length>2) + flairclass = flairdata[2]; + else + flairclass="unknown"; + SetFlair(ign, flair, flairclass, author); + } + Thread.sleep(10000); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + } + + public static Exception LastException; //2015.08.09. + + public String DownloadString(String urlstr) throws MalformedURLException, IOException + { + URL url = new URL(urlstr); + URLConnection con = url.openConnection(); + con.setRequestProperty("User-Agent", "TheButtonAutoFlair"); + InputStream in = con.getInputStream(); + String encoding = con.getContentEncoding(); + encoding = encoding == null ? "UTF-8" : encoding; + String body = IOUtils.toString(in, encoding); + in.close(); + return body; + } + + public static Map TownColors=new HashMap(); //2015.07.20. + public Boolean HasIGFlair(String playername) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + return p.Flair!=null; //2015.08.08. + } + + public void SetFlair(String playername, String text, String flairclass, String username) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + String finalflair; + p.FlairDecided=true; + switch(flairclass) + { + case "press-1": + finalflair="§c("+text+")§r"; + break; + case "press-2": + finalflair="§6("+text+")§r"; + break; + case "press-3": + finalflair="§e("+text+")§r"; + break; + case "press-4": + finalflair="§a("+text+")§r"; + break; + case "press-5": + finalflair="§9("+text+")§r"; + break; + 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; + case "undecided": //2015.08.09. + p.FlairDecided=false; + finalflair=""; + break; + default: + finalflair=""; + break; + } + if(finalflair.length()==0) //<-- 2015.07.20. + return; + p.Flair=finalflair; //2015.08.08. + p.UserName=username; //2015.08.08. + System.out.println("Added new flair to "+playername+": "+finalflair); + for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08. + { + if(player.getName().equals(playername)) + { + //AppendPlayerDisplayFlair(player, username, finalflair); + AppendPlayerDisplayFlair(p, player); + break; + } + } + } + + public static String GetFlair(Player player) + { //2015.07.16. + String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08. + return flair==null ? "" : flair; + } + + //public static void AppendPlayerDisplayFlair(Player player, String username, String flair) + public static void AppendPlayerDisplayFlair(MaybeOfflinePlayer player, Player p) //<-- 2015.08.09. + { + + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).IgnoredFlair) + return; + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).AcceptedFlair) + { + AppendPlayerDisplayFlairFinal(p, player.Flair); //2015.07.20. + if(!player.FlairDecided) + p.sendMessage("§9Your flair type is unknown. Are you a non-presser or a can't press? (/u nonpresser or /u cantpress)§r"); //2015.08.09. + } + else + p.sendMessage("§9Are you Reddit user "+player.UserName+"?§r §6Type /u accept or /u ignore§r"); + } + + private static void AppendPlayerDisplayFlairFinal(Player player, String flair) + { //2015.07.20. + String color = GetColorForTown(GetPlayerTown(player)); //TO!DO: Multiple colors put on first capital letters + String[] colors = color.substring(1).split("§"); + String displayname=player.getName(); //2015.08.08. + ArrayList Positions=new ArrayList<>(); + for(int i=0; i=colors.length) + { + int x=0; + for(int i=0; i GetPlayers() + { + return Instance.getServer().getOnlinePlayers(); + } + + public static void LoadFiles(boolean reload) //<-- 2015.08.09. + { + if(reload) + { //2015.08.09. + System.out.println("Auto-flair plugin cleanup for reloading..."); + MaybeOfflinePlayer.AllPlayers.clear(); + TownColors.clear(); + } + System.out.println("Loading files for auto-flair plugin..."); //2015.08.09. + try { + File file=new File("flairsaccepted.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + //System.out.println("Name: " + name); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("flairsignored.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsignored.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("autoflairconfig.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + TownColors.put(s[0], s[1]); + } + br.close(); + } + file=new File("autoflairconfig.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + TownColors.put(s[0], s[1]); + } + br.close(); + } + //throw new IOException("Test"); //2015.08.09. + System.out.println("Auto-flair plugin loaded files!"); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + public static void SaveFiles() //<-- 2015.08.09. + { + try + { + FileWriter fw; + fw = new FileWriter("flairsaccepted.txt"); + fw.close(); + fw = new FileWriter("flairsignored.txt"); + fw.close(); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + try { + File file=new File("flairsaccepted.txt"); + BufferedWriter bw=new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.AcceptedFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + file=new File("flairsignored.txt"); + bw = new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.IgnoredFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/59/d0ec3c3e893e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/59/d0ec3c3e893e00151ce8ff6d4f74dabd deleted file mode 100644 index f7f1828..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/59/d0ec3c3e893e00151ce8ff6d4f74dabd +++ /dev/null @@ -1,170 +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; - MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. - //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - if(p.Flair==null) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. - { - case "accept": - { - if(p.IgnoredFlair) - p.IgnoredFlair=false; //2015.08.08. - if(!p.AcceptedFlair) - { - String flair=p.Flair; //2015.08.08. - PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. - p.AcceptedFlair=true; //2015.08.08. - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("§cYou already have this user's flair.§r"); - break; - } - case "ignore": - { - if(p.AcceptedFlair) - p.AcceptedFlair=false; //2015.08.08. - if(!p.IgnoredFlair) - { - p.IgnoredFlair=true; - String flair=p.Flair; //2015.08.08. - PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. - player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); - } - else - player.sendMessage("§cYou already ignored this request.§r"); - break; - } - /*case "reload": //2015.07.20. - DoReload(player); - break;*/ - case "admin": //2015.08.09. - DoAdmin(player, args); - break; - default: - return false; - } - return true; - } - - /*if(args[0].toLowerCase()=="reload") - DoReload(null); //2015.07.20.*/ - else if(args[0].toLowerCase()=="admin") - DoAdmin(null, args); //2015.08.09. - return false; - } - private static void DoReload(Player player) - { //2015.07.20. - //if(player==null || player.isOp() || player.getName()=="NorbiPeti") - //{ - try - { - File file=new File("autoflairconfig.txt"); - if(file.exists()) - { - PluginMain.TownColors.clear(); - BufferedReader br=new BufferedReader(new FileReader(file)); - String line; - while((line=br.readLine())!=null) - { - String[] s=line.split(" "); - PluginMain.TownColors.put(s[0], s[1]); - } - br.close(); - for(Player p : PluginMain.GetPlayers()) - { - MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName()); - if(mp.Flair!=null) - { - String flair=mp.Flair; - PluginMain.RemovePlayerDisplayFlairFinal(p, flair); - PluginMain.AppendPlayerDisplayFlairFinal(p, flair); - } - } - String msg="§6Reloaded config file.§r"; - SendMessage(player, msg); //2015.08.09. - } - } - catch(Exception e) - { - System.out.println("Error!\n"+e); - if(player!=null) - player.sendMessage("§cAn error occured. See console for details.§r"); - } - //} - //else - //player.sendMessage("§cYou need to be OP to use this command.§r"); - } - private static void DoAdmin(Player player, String[] args) - { //2015.08.09. - if(player==null || player.isOp() || player.getName()=="NorbiPeti") - { - if(args.length==1) - { - String message="§cUsage: /u admin reload|playerinfo§r"; - SendMessage(player, message); - return; - } - //args[0] is "admin" - switch(args[1].toLowerCase()) - { - case "reload": - DoReload(player); - break; - case "playerinfo": - DoPlayerInfo(player, args); - break; - } - } - else - player.sendMessage("§cYou need to be OP to use this command.§r"); - } - private static void DoPlayerInfo(Player player, String[] args) - { //2015.08.09. - //args[0] is "admin" - args[1] is "playerinfo" - if(args.length==2) - { - String message="§cUsage: /u admin playerinfo §r"; - SendMessage(player, message); - } - if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2])) - { - String message="§cPlayer not found: "+args[2]+"§r"; - SendMessage(player, message); - } - MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]); - SendMessage(player, "User flair: "+p.Flair); - SendMessage(player, "Player name: "+p.PlayerName); - SendMessage(player, "Username: "+p.UserName); - return; - } - private static void SendMessage(Player player, String message) - { //2015.08.09. - if(player==null) - System.out.println(message); - else - player.sendMessage(message); - return; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/5a/0031cee5e03e001517108d149b613203 b/.metadata/.plugins/org.eclipse.core.resources/.history/5a/0031cee5e03e001517108d149b613203 new file mode 100644 index 0000000..b3a3e05 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/5a/0031cee5e03e001517108d149b613203 @@ -0,0 +1,265 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +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; + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. + //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) + if(p.Flair==null) + { + player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); + return true; + } + switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. + { + case "accept": + { + if(p.IgnoredFlair) + p.IgnoredFlair=false; //2015.08.08. + if(!p.AcceptedFlair) + { + String flair=p.Flair; //2015.08.08. + //PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + PluginMain.AppendPlayerDisplayFlair(p, player); + p.AcceptedFlair=true; //2015.08.08. + player.sendMessage("§6Your flair has been set:§r "+flair); + } + else + player.sendMessage("§cYou already have this user's flair.§r"); + break; + } + case "ignore": + { + if(p.AcceptedFlair) + p.AcceptedFlair=false; //2015.08.08. + if(!p.IgnoredFlair) + { + p.IgnoredFlair=true; + String flair=p.Flair; //2015.08.08. + PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. + player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); + } + else + player.sendMessage("§cYou already ignored this request.§r"); + break; + } + /*case "reload": //2015.07.20. + DoReload(player); + break;*/ + case "admin": //2015.08.09. + DoAdmin(player, args); + break; + case "nonpresser": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§7(non-pr.)§r"; + break; + case "cantpress": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§r(can't press)§r"; + break; + default: + return false; + } + return true; + } + /*if(args[0].toLowerCase()=="reload") + DoReload(null); //2015.07.20.*/ + else if(args.length>0 && args[0].toLowerCase().equals("admin")) //2015.08.09. + { + DoAdmin(null, args); //2015.08.09. + return true; //2015.08.09. + } + return false; + } + private static void DoReload(Player player) + { //2015.07.20. + //if(player==null || player.isOp() || player.getName()=="NorbiPeti") + //{ + try + { + File file=new File("autoflairconfig.txt"); + if(file.exists()) + { + PluginMain.LoadFiles(true); //2015.08.09. + for(Player p : PluginMain.GetPlayers()) + { + MaybeOfflinePlayer mp = MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName()); + if(mp.Flair!=null) + { + String flair=mp.Flair; + PluginMain.RemovePlayerDisplayFlairFinal(p, flair); + //PluginMain.AppendPlayerDisplayFlairFinal(p, flair); + PluginMain.AppendPlayerDisplayFlair(mp, p); //2015.08.09. + } + String msg="§6Note: The auto-flair plugin has been reloaded. You might need to wait 10s to have your flair.§r"; //2015.08.09. + p.sendMessage(msg); //2015.08.09. + } + //String msg="§6Reloaded config file.§r"; + //SendMessage(player, msg); //2015.08.09. + } + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + if(player!=null) + player.sendMessage("§cAn error occured. See console for details.§r"); + PluginMain.LastException=e; //2015.08.09. + } + //} + //else + //player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static Player ReloadPlayer; //2015.08.09. + private static void DoAdmin(Player player, String[] args) + { //2015.08.09. + if(player==null || player.isOp() || player.getName()=="NorbiPeti") + { + //System.out.println("Args length: " + args.length); + if(args.length==1) + { + String message="§cUsage: /u admin reload|playerinfo§r"; + SendMessage(player, message); + return; + } + //args[0] is "admin" + switch(args[1].toLowerCase()) + { + case "reload": + ReloadPlayer=player; //2015.08.09. + SendMessage(player, "§6Make sure to save the current settings before you modify and reload them! Type /u admin confirm when done.§r"); + break; + case "playerinfo": + DoPlayerInfo(player, args); + break; + case "getlasterror": + DoGetLastError(player, args); + case "confirm": + if(ReloadPlayer==player) + DoReload(player); //2015.08.09. + else + SendMessage(player, "§cYou need to do /u admin reload first.§r"); + break; + case "save": + PluginMain.SaveFiles(); //2015.08.09. + SendMessage(player, "§6Saved files. Now you can edit them and reload if you want.§r"); + break; + case "setflair": + + break; + default: + String message="§cUsage: /u admin reload|playerinfo|getlasterror|save§r"; + SendMessage(player, message); + return; + } + } + else + player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static void DoPlayerInfo(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "playerinfo" + if(args.length==2) + { + String message="§cUsage: /u admin playerinfo §r"; + SendMessage(player, message); + return; + } + if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2])) + { + String message="§cPlayer not found: "+args[2]+"§r"; + SendMessage(player, message); + return; + } + MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]); + SendMessage(player, "Player name: "+p.PlayerName); + SendMessage(player, "User flair: "+p.Flair); + SendMessage(player, "Username: "+p.UserName); + SendMessage(player, "Flair accepted: "+p.AcceptedFlair); + SendMessage(player, "Flair ignored: "+p.IgnoredFlair); + } + private static void SendMessage(Player player, String message) + { //2015.08.09. + if(player==null) + System.out.println(message); + else + player.sendMessage(message); + } + private static void DoGetLastError(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "getlasterror" + if(PluginMain.LastException!=null) + { + SendMessage(player, "Last error:"); + SendMessage(player, PluginMain.LastException.toString()); + PluginMain.LastException=null; + } + else + SendMessage(player, "There were no exceptions."); + } + private static void SetPlayerFlair(Player player, MaybeOfflinePlayer targetplayer, String flair) + { //2015.08.09. + flair=flair.replace('&', '§'); + targetplayer.Flair=flair; + if(!PluginMain.RemoveLineFromFile("customflairs.txt", targetplayer.PlayerName)) + { + SendMessage(player, "§cError removing previous custom flair!§r"); + return; + } + File file=new File("customflairs.txt"); + try { + BufferedWriter bw; + bw = new BufferedWriter(new FileWriter(file, true)); + bw.write(targetplayer.getName()+"\n"); + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + PluginMain.LastException=e; //2015.08.09. + } + SendMessage(player, "§6The flair has been set. Player: "+targetplayer.getName()+" Flair: "+flair+"§r"); + } + private static void DoSetFlair(Player player, String args) + { + //args[0] is "admin" - args[1] is "setflair" + if(args.length()<4) + { + SendMessage(player, "§cUsage: /u admin setflair "); + return; + } + SetPlayerFlair(player, MaybeOfflinePlayer.AddPlayerIfNeeded(player.getName())) + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/5a/109a5eedde3e001517108d149b613203 b/.metadata/.plugins/org.eclipse.core.resources/.history/5a/109a5eedde3e001517108d149b613203 new file mode 100644 index 0000000..fdf80ca --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/5a/109a5eedde3e001517108d149b613203 @@ -0,0 +1,250 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +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; + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. + //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) + if(p.Flair==null) + { + player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); + return true; + } + switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. + { + case "accept": + { + if(p.IgnoredFlair) + p.IgnoredFlair=false; //2015.08.08. + if(!p.AcceptedFlair) + { + String flair=p.Flair; //2015.08.08. + //PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + PluginMain.AppendPlayerDisplayFlair(p, player); + p.AcceptedFlair=true; //2015.08.08. + player.sendMessage("§6Your flair has been set:§r "+flair); + } + else + player.sendMessage("§cYou already have this user's flair.§r"); + break; + } + case "ignore": + { + if(p.AcceptedFlair) + p.AcceptedFlair=false; //2015.08.08. + if(!p.IgnoredFlair) + { + p.IgnoredFlair=true; + String flair=p.Flair; //2015.08.08. + PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. + player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); + } + else + player.sendMessage("§cYou already ignored this request.§r"); + break; + } + /*case "reload": //2015.07.20. + DoReload(player); + break;*/ + case "admin": //2015.08.09. + DoAdmin(player, args); + break; + case "nonpresser": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§7(non-pr.)§r"; + break; + case "cantpress": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§r(can't press)§r"; + break; + default: + return false; + } + return true; + } + /*if(args[0].toLowerCase()=="reload") + DoReload(null); //2015.07.20.*/ + else if(args.length>0 && args[0].toLowerCase().equals("admin")) //2015.08.09. + { + DoAdmin(null, args); //2015.08.09. + return true; //2015.08.09. + } + return false; + } + private static void DoReload(Player player) + { //2015.07.20. + //if(player==null || player.isOp() || player.getName()=="NorbiPeti") + //{ + try + { + File file=new File("autoflairconfig.txt"); + if(file.exists()) + { + PluginMain.LoadFiles(true); //2015.08.09. + for(Player p : PluginMain.GetPlayers()) + { + MaybeOfflinePlayer mp = MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName()); + if(mp.Flair!=null) + { + String flair=mp.Flair; + PluginMain.RemovePlayerDisplayFlairFinal(p, flair); + //PluginMain.AppendPlayerDisplayFlairFinal(p, flair); + PluginMain.AppendPlayerDisplayFlair(mp, p); //2015.08.09. + } + String msg="§6Note: The auto-flair plugin has been reloaded. You might need to wait 10s to have your flair.§r"; //2015.08.09. + p.sendMessage(msg); //2015.08.09. + } + //String msg="§6Reloaded config file.§r"; + //SendMessage(player, msg); //2015.08.09. + } + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + if(player!=null) + player.sendMessage("§cAn error occured. See console for details.§r"); + PluginMain.LastException=e; //2015.08.09. + } + //} + //else + //player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static Player ReloadPlayer; //2015.08.09. + private static void DoAdmin(Player player, String[] args) + { //2015.08.09. + if(player==null || player.isOp() || player.getName()=="NorbiPeti") + { + //System.out.println("Args length: " + args.length); + if(args.length==1) + { + String message="§cUsage: /u admin reload|playerinfo§r"; + SendMessage(player, message); + return; + } + //args[0] is "admin" + switch(args[1].toLowerCase()) + { + case "reload": + ReloadPlayer=player; //2015.08.09. + SendMessage(player, "§6Make sure to save the current settings before you modify and reload them! Type /u admin confirm when done.§r"); + break; + case "playerinfo": + DoPlayerInfo(player, args); + break; + case "getlasterror": + DoGetLastError(player, args); + case "confirm": + if(ReloadPlayer==player) + DoReload(player); //2015.08.09. + else + SendMessage(player, "§cYou need to do /u admin reload first.§r"); + break; + case "save": + PluginMain.SaveFiles(); //2015.08.09. + SendMessage(player, "§6Saved files. Now you can edit them and reload if you want.§r"); + break; + default: + String message="§cUsage: /u admin reload|playerinfo|getlasterror§r"; + SendMessage(player, message); + return; + } + } + else + player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static void DoPlayerInfo(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "playerinfo" + if(args.length==2) + { + String message="§cUsage: /u admin playerinfo §r"; + SendMessage(player, message); + return; + } + if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2])) + { + String message="§cPlayer not found: "+args[2]+"§r"; + SendMessage(player, message); + return; + } + MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]); + SendMessage(player, "Player name: "+p.PlayerName); + SendMessage(player, "User flair: "+p.Flair); + SendMessage(player, "Username: "+p.UserName); + SendMessage(player, "Flair accepted: "+p.AcceptedFlair); + SendMessage(player, "Flair ignored: "+p.IgnoredFlair); + } + public static void SendMessage(Player player, String message) + { //2015.08.09. + if(player==null) + System.out.println(message); + else + player.sendMessage(message); + } + private static void DoGetLastError(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "getlasterror" + if(PluginMain.LastException!=null) + { + SendMessage(player, "Last error:"); + SendMessage(player, PluginMain.LastException.toString()); + PluginMain.LastException=null; + } + else + SendMessage(player, "There were no exceptions."); + } + public static void SetPlayerFlair(Player player, String flair) + { //2015.08.09. + flair=flair.replace('&', '§'); + MaybeOfflinePlayer.AddPlayerIfNeeded(player.getName()).Flair=flair; + if(!RemoveLineFromFile("customflairs.txt")) + { + Commands.SendMessage(player, "") + } + File file=new File("customflairs.txt"); + try { + BufferedWriter bw; + bw = new BufferedWriter(new FileWriter(file, true)); + bw.write(player.getName()+"\n"); + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/5a/80e572e0e43e001517108d149b613203 b/.metadata/.plugins/org.eclipse.core.resources/.history/5a/80e572e0e43e001517108d149b613203 new file mode 100644 index 0000000..f7e15aa --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/5a/80e572e0e43e001517108d149b613203 @@ -0,0 +1,424 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStream; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLConnection; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + +import org.apache.commons.io.IOUtils; +import org.bukkit.entity.Player; +import org.bukkit.plugin.java.JavaPlugin; +import org.json.JSONArray; +import org.json.JSONObject; + +import com.palmergames.bukkit.towny.object.Town; +import com.palmergames.bukkit.towny.object.WorldCoord; + +public class PluginMain extends JavaPlugin +{ //Translated to Java: 2015.07.15. + //A user, which flair isn't obtainable: + //https://www.reddit.com/r/thebutton/comments/31c32v/i_pressed_the_button_without_really_thinking/ + private static PluginMain Instance; + // Fired when plugin is first enabled + @Override + public void onEnable() + { + System.out.println("The Button Auto-flair Plugin by NorbiPeti (:P)"); + getServer().getPluginManager().registerEvents(new PlayerListener(), this); + this.getCommand("u").setExecutor(new Commands()); + this.getCommand("u").setUsage(this.getCommand("u").getUsage().replace('&', '§')); + Instance=this; //2015.08.08. + LoadFiles(false); //2015.08.09. + Runnable r=new Runnable(){public void run(){ThreadMethod();}}; + Thread t=new Thread(r); + t.start(); + } + Boolean stop=false; + // Fired when plugin is disabled + @Override + public void onDisable() + { + SaveFiles(); //2015.08.09. + stop=true; + } + + public void ThreadMethod() //<-- 2015.07.16. + { + while(!stop) + { + try + { + String body=DownloadString("https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/autoflair_system_comment_your_minecraft_name_and/.json?limit=1000"); + JSONArray json=new JSONArray(body).getJSONObject(1).getJSONObject("data").getJSONArray("children"); + for(Object obj : json) + { + JSONObject item = (JSONObject)obj; + String author=item.getJSONObject("data").getString("author"); + String ign=item.getJSONObject("data").getString("body"); + int start = ign.indexOf("IGN:") + "IGN:".length(); + if(start==-1) + continue; //2015.08.09. + int end = ign.indexOf(' ', start); + if (end == -1 || end == start) + end=ign.indexOf('\n', start); //2015.07.15. + if (end == -1 || end == start) + ign = ign.substring(start); + else + ign = ign.substring(start, end); + ign = ign.trim(); + if(HasIGFlair(ign)) + continue; + try { + Thread.sleep(10); + } catch(InterruptedException ex) { + Thread.currentThread().interrupt(); + } + String[] flairdata = DownloadString("http://karmadecay.com/thebutton-data.php?users=" + author).replace("\"", "").split(":"); + String flair; + if(flairdata.length > 1) //2015.07.15. + flair = flairdata[1]; + else + flair=""; + if (flair != "-1") + flair = flair + "s"; + else + flair = "non-presser"; + String flairclass; + if(flairdata.length>2) + flairclass = flairdata[2]; + else + flairclass="unknown"; + SetFlair(ign, flair, flairclass, author); + } + Thread.sleep(10000); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + } + + public static Exception LastException; //2015.08.09. + + public String DownloadString(String urlstr) throws MalformedURLException, IOException + { + URL url = new URL(urlstr); + URLConnection con = url.openConnection(); + con.setRequestProperty("User-Agent", "TheButtonAutoFlair"); + InputStream in = con.getInputStream(); + String encoding = con.getContentEncoding(); + encoding = encoding == null ? "UTF-8" : encoding; + String body = IOUtils.toString(in, encoding); + in.close(); + return body; + } + + public static Map TownColors=new HashMap(); //2015.07.20. + public Boolean HasIGFlair(String playername) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + return p.Flair!=null; //2015.08.08. + } + + public void SetFlair(String playername, String text, String flairclass, String username) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + String finalflair; + p.FlairDecided=true; + switch(flairclass) + { + case "press-1": + finalflair="§c("+text+")§r"; + break; + case "press-2": + finalflair="§6("+text+")§r"; + break; + case "press-3": + finalflair="§e("+text+")§r"; + break; + case "press-4": + finalflair="§a("+text+")§r"; + break; + case "press-5": + finalflair="§9("+text+")§r"; + break; + 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; + case "undecided": //2015.08.09. + p.FlairDecided=false; + finalflair=""; + break; + default: + finalflair=""; + break; + } + if(finalflair.length()==0) //<-- 2015.07.20. + return; + p.Flair=finalflair; //2015.08.08. + p.UserName=username; //2015.08.08. + System.out.println("Added new flair to "+playername+": "+finalflair); + for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08. + { + if(player.getName().equals(playername)) + { + //AppendPlayerDisplayFlair(player, username, finalflair); + AppendPlayerDisplayFlair(p, player); + break; + } + } + } + + public static String GetFlair(Player player) + { //2015.07.16. + String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08. + return flair==null ? "" : flair; + } + + //public static void AppendPlayerDisplayFlair(Player player, String username, String flair) + public static void AppendPlayerDisplayFlair(MaybeOfflinePlayer player, Player p) //<-- 2015.08.09. + { + + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).IgnoredFlair) + return; + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).AcceptedFlair) + { + AppendPlayerDisplayFlairFinal(p, player.Flair); //2015.07.20. + if(!player.FlairDecided) + p.sendMessage("§9Your flair type is unknown. Are you a non-presser or a can't press? (/u nonpresser or /u cantpress)§r"); //2015.08.09. + } + else + p.sendMessage("§9Are you Reddit user "+player.UserName+"?§r §6Type /u accept or /u ignore§r"); + } + + private static void AppendPlayerDisplayFlairFinal(Player player, String flair) + { //2015.07.20. + String color = GetColorForTown(GetPlayerTown(player)); //TO!DO: Multiple colors put on first capital letters + String[] colors = color.substring(1).split("§"); + String displayname=player.getName(); //2015.08.08. + ArrayList Positions=new ArrayList<>(); + for(int i=0; i=colors.length) + { + int x=0; + for(int i=0; i GetPlayers() + { + return Instance.getServer().getOnlinePlayers(); + } + + public static void LoadFiles(boolean reload) //<-- 2015.08.09. + { + if(reload) + { //2015.08.09. + System.out.println("Auto-flair plugin cleanup for reloading..."); + MaybeOfflinePlayer.AllPlayers.clear(); + TownColors.clear(); + } + System.out.println("Loading files for auto-flair plugin..."); //2015.08.09. + try { + File file=new File("flairsaccepted.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + //System.out.println("Name: " + name); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("flairsignored.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsignored.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("autoflairconfig.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + TownColors.put(s[0], s[1]); + } + br.close(); + } + file=new File("customflairs.txt"); //2015.08.09. + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + MaybeOfflinePlayer.AddPlayerIfNeeded(s[0]).Flair=s[1]; //2015.08.09. + } + br.close(); + } + //throw new IOException("Test"); //2015.08.09. + System.out.println("Auto-flair plugin loaded files!"); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + public static void SaveFiles() //<-- 2015.08.09. + { + try + { + FileWriter fw; + fw = new FileWriter("flairsaccepted.txt"); + fw.close(); + fw = new FileWriter("flairsignored.txt"); + fw.close(); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + try { + File file=new File("flairsaccepted.txt"); + BufferedWriter bw=new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.AcceptedFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + file=new File("flairsignored.txt"); + bw = new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.IgnoredFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + public static boolean RemoveLineFromFile(String file, String line) + { //2015.08.09. + File inputFile = new File(file); + File tempFile = new File("_temp.txt"); + + if(!inputFile.exists()) + + try { + BufferedReader reader = new BufferedReader(new FileReader(inputFile)); + BufferedWriter writer = new BufferedWriter(new FileWriter(tempFile)); + + String lineToRemove = line; + String currentLine; + + while((currentLine = reader.readLine()) != null) { + // trim newline when comparing with lineToRemove + String trimmedLine = currentLine.trim(); + //if(trimmedLine.equals(lineToRemove)) continue; + if(trimmedLine.contains(lineToRemove)) continue; //2015.08.09. + writer.write(currentLine + System.getProperty("line.separator")); + } + writer.close(); + reader.close(); + return tempFile.renameTo(inputFile); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + return false; + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/5a/d014d921873e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/5a/d014d921873e00151ce8ff6d4f74dabd deleted file mode 100644 index dc43ad6..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/5a/d014d921873e00151ce8ff6d4f74dabd +++ /dev/null @@ -1,135 +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; - MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. - //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - if(p.Flair==null) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. - { - case "accept": - { - if(p.IgnoredFlair) - p.IgnoredFlair=false; //2015.08.08. - if(!p.AcceptedFlair) - { - String flair=p.Flair; //2015.08.08. - PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. - p.AcceptedFlair=true; //2015.08.08. - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("§cYou already have this user's flair.§r"); - break; - } - case "ignore": - { - if(p.AcceptedFlair) - p.AcceptedFlair=false; //2015.08.08. - if(!p.IgnoredFlair) - { - p.IgnoredFlair=true; - String flair=p.Flair; //2015.08.08. - PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. - player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); - } - else - player.sendMessage("§cYou already ignored this request.§r"); - break; - } - /*case "reload": //2015.07.20. - DoReload(player); - break;*/ - case "admin": //2015.08.09. - DoAdmin(player, args); - break; - default: - return false; - } - return true; - } - - /*if(args[0].toLowerCase()=="reload") - DoReload(null); //2015.07.20.*/ - else if(args[0].toLowerCase()=="admin") - DoAdmin(null, args); //2015.08.09. - return false; - } - private static void DoReload(Player player) - { //2015.07.20. - //if(player==null || player.isOp() || player.getName()=="NorbiPeti") - //{ - try - { - File file=new File("autoflairconfig.txt"); - if(file.exists()) - { - PluginMain.TownColors.clear(); - BufferedReader br=new BufferedReader(new FileReader(file)); - String line; - while((line=br.readLine())!=null) - { - String[] s=line.split(" "); - PluginMain.TownColors.put(s[0], s[1]); - } - br.close(); - for(Player p : PluginMain.GetPlayers()) - { - MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName()); - if(mp.Flair!=null) - { - String flair=mp.Flair; - PluginMain.RemovePlayerDisplayFlairFinal(p, flair); - PluginMain.AppendPlayerDisplayFlairFinal(p, flair); - } - } - String msg="§6Reloaded config file.§r"; - if(player!=null) - player.sendMessage(msg); - else - System.out.println(msg); - } - } - catch(Exception e) - { - System.out.println("Error!\n"+e); - if(player!=null) - player.sendMessage("§cAn error occured. See console for details.§r"); - } - //} - //else - //player.sendMessage("§cYou need to be OP to use this command.§r"); - } - private static void DoAdmin(Player player, String[] args) - { - if(player==null || player.isOp() || player.getName()=="NorbiPeti") - { - //args[0] is "admin" - switch(args[1].toLowerCase()) - { - case "" - } - } - else - player.sendMessage("§cYou need to be OP to use this command.§r"); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/5c/004c7803e03e001517108d149b613203 b/.metadata/.plugins/org.eclipse.core.resources/.history/5c/004c7803e03e001517108d149b613203 new file mode 100644 index 0000000..490906a --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/5c/004c7803e03e001517108d149b613203 @@ -0,0 +1,255 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +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; + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. + //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) + if(p.Flair==null) + { + player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); + return true; + } + switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. + { + case "accept": + { + if(p.IgnoredFlair) + p.IgnoredFlair=false; //2015.08.08. + if(!p.AcceptedFlair) + { + String flair=p.Flair; //2015.08.08. + //PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + PluginMain.AppendPlayerDisplayFlair(p, player); + p.AcceptedFlair=true; //2015.08.08. + player.sendMessage("§6Your flair has been set:§r "+flair); + } + else + player.sendMessage("§cYou already have this user's flair.§r"); + break; + } + case "ignore": + { + if(p.AcceptedFlair) + p.AcceptedFlair=false; //2015.08.08. + if(!p.IgnoredFlair) + { + p.IgnoredFlair=true; + String flair=p.Flair; //2015.08.08. + PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. + player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); + } + else + player.sendMessage("§cYou already ignored this request.§r"); + break; + } + /*case "reload": //2015.07.20. + DoReload(player); + break;*/ + case "admin": //2015.08.09. + DoAdmin(player, args); + break; + case "nonpresser": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§7(non-pr.)§r"; + break; + case "cantpress": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§r(can't press)§r"; + break; + default: + return false; + } + return true; + } + /*if(args[0].toLowerCase()=="reload") + DoReload(null); //2015.07.20.*/ + else if(args.length>0 && args[0].toLowerCase().equals("admin")) //2015.08.09. + { + DoAdmin(null, args); //2015.08.09. + return true; //2015.08.09. + } + return false; + } + private static void DoReload(Player player) + { //2015.07.20. + //if(player==null || player.isOp() || player.getName()=="NorbiPeti") + //{ + try + { + File file=new File("autoflairconfig.txt"); + if(file.exists()) + { + PluginMain.LoadFiles(true); //2015.08.09. + for(Player p : PluginMain.GetPlayers()) + { + MaybeOfflinePlayer mp = MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName()); + if(mp.Flair!=null) + { + String flair=mp.Flair; + PluginMain.RemovePlayerDisplayFlairFinal(p, flair); + //PluginMain.AppendPlayerDisplayFlairFinal(p, flair); + PluginMain.AppendPlayerDisplayFlair(mp, p); //2015.08.09. + } + String msg="§6Note: The auto-flair plugin has been reloaded. You might need to wait 10s to have your flair.§r"; //2015.08.09. + p.sendMessage(msg); //2015.08.09. + } + //String msg="§6Reloaded config file.§r"; + //SendMessage(player, msg); //2015.08.09. + } + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + if(player!=null) + player.sendMessage("§cAn error occured. See console for details.§r"); + PluginMain.LastException=e; //2015.08.09. + } + //} + //else + //player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static Player ReloadPlayer; //2015.08.09. + private static void DoAdmin(Player player, String[] args) + { //2015.08.09. + if(player==null || player.isOp() || player.getName()=="NorbiPeti") + { + //System.out.println("Args length: " + args.length); + if(args.length==1) + { + String message="§cUsage: /u admin reload|playerinfo§r"; + SendMessage(player, message); + return; + } + //args[0] is "admin" + switch(args[1].toLowerCase()) + { + case "reload": + ReloadPlayer=player; //2015.08.09. + SendMessage(player, "§6Make sure to save the current settings before you modify and reload them! Type /u admin confirm when done.§r"); + break; + case "playerinfo": + DoPlayerInfo(player, args); + break; + case "getlasterror": + DoGetLastError(player, args); + case "confirm": + if(ReloadPlayer==player) + DoReload(player); //2015.08.09. + else + SendMessage(player, "§cYou need to do /u admin reload first.§r"); + break; + case "save": + PluginMain.SaveFiles(); //2015.08.09. + SendMessage(player, "§6Saved files. Now you can edit them and reload if you want.§r"); + break; + case "setflair": + + break; + default: + String message="§cUsage: /u admin reload|playerinfo|getlasterror|save§r"; + SendMessage(player, message); + return; + } + } + else + player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static void DoPlayerInfo(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "playerinfo" + if(args.length==2) + { + String message="§cUsage: /u admin playerinfo §r"; + SendMessage(player, message); + return; + } + if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2])) + { + String message="§cPlayer not found: "+args[2]+"§r"; + SendMessage(player, message); + return; + } + MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]); + SendMessage(player, "Player name: "+p.PlayerName); + SendMessage(player, "User flair: "+p.Flair); + SendMessage(player, "Username: "+p.UserName); + SendMessage(player, "Flair accepted: "+p.AcceptedFlair); + SendMessage(player, "Flair ignored: "+p.IgnoredFlair); + } + private static void SendMessage(Player player, String message) + { //2015.08.09. + if(player==null) + System.out.println(message); + else + player.sendMessage(message); + } + private static void DoGetLastError(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "getlasterror" + if(PluginMain.LastException!=null) + { + SendMessage(player, "Last error:"); + SendMessage(player, PluginMain.LastException.toString()); + PluginMain.LastException=null; + } + else + SendMessage(player, "There were no exceptions."); + } + private static void SetPlayerFlair(Player player, Player targetplayer, String flair) + { //2015.08.09. + flair=flair.replace('&', '§'); + MaybeOfflinePlayer.AddPlayerIfNeeded(player.getName()).Flair=flair; + if(!PluginMain.RemoveLineFromFile("customflairs.txt", targetplayer.getName())) + { + SendMessage(player, "§cError removing previous custom flair!§r"); + return; + } + File file=new File("customflairs.txt"); + try { + BufferedWriter bw; + bw = new BufferedWriter(new FileWriter(file, true)); + bw.write(targetplayer.getName()+"\n"); + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + PluginMain.LastException=e; //2015.08.09. + } + SendMessage(player, "§6The flair has been set. Player: "+targetplayer.getName()+" Flair: "+flair+"§r"); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/5c/a03b3ea1d33e001518fa86d7ae2a1cf8 b/.metadata/.plugins/org.eclipse.core.resources/.history/5c/a03b3ea1d33e001518fa86d7ae2a1cf8 new file mode 100644 index 0000000..3d0defb --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/5c/a03b3ea1d33e001518fa86d7ae2a1cf8 @@ -0,0 +1,219 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; + +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class Commands implements CommandExecutor { + // This method is called, when somebody uses our command + @Override + public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { + if (sender instanceof Player) { + Player player = (Player) sender; + if(args.length<1) + return false; + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. + //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) + if(p.Flair==null) + { + player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); + return true; + } + switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. + { + case "accept": + { + if(p.IgnoredFlair) + p.IgnoredFlair=false; //2015.08.08. + if(!p.AcceptedFlair) + { + String flair=p.Flair; //2015.08.08. + //PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + PluginMain.AppendPlayerDisplayFlair(p, player); + p.AcceptedFlair=true; //2015.08.08. + player.sendMessage("§6Your flair has been set:§r "+flair); + } + else + player.sendMessage("§cYou already have this user's flair.§r"); + break; + } + case "ignore": + { + if(p.AcceptedFlair) + p.AcceptedFlair=false; //2015.08.08. + if(!p.IgnoredFlair) + { + p.IgnoredFlair=true; + String flair=p.Flair; //2015.08.08. + PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. + player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); + } + else + player.sendMessage("§cYou already ignored this request.§r"); + break; + } + /*case "reload": //2015.07.20. + DoReload(player); + break;*/ + case "admin": //2015.08.09. + DoAdmin(player, args); + break; + case "nonpresser": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§7(non-pr.)§r"; + break; + case "cantpress": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§r(can't press)§r"; + break; + default: + return false; + } + return true; + } + /*if(args[0].toLowerCase()=="reload") + DoReload(null); //2015.07.20.*/ + else if(args.length>0 && args[0].toLowerCase().equals("admin")) //2015.08.09. + { + DoAdmin(null, args); //2015.08.09. + return true; //2015.08.09. + } + return false; + } + private static void DoReload(Player player) + { //2015.07.20. + //if(player==null || player.isOp() || player.getName()=="NorbiPeti") + //{ + try + { + File file=new File("autoflairconfig.txt"); + if(file.exists()) + { + PluginMain.LoadFiles(true); //2015.08.09. + for(Player p : PluginMain.GetPlayers()) + { + MaybeOfflinePlayer mp = MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName()); + if(mp.Flair!=null) + { + String flair=mp.Flair; + PluginMain.RemovePlayerDisplayFlairFinal(p, flair); + //PluginMain.AppendPlayerDisplayFlairFinal(p, flair); + PluginMain.AppendPlayerDisplayFlair(mp, p); //2015.08.09. + } + String msg="§6Note: The auto-flair plugin has been reloaded. You might need to wait 10s to have your flair.§r"; //2015.08.09. + p.sendMessage(msg); //2015.08.09. + } + //String msg="§6Reloaded config file.§r"; + //SendMessage(player, msg); //2015.08.09. + } + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + if(player!=null) + player.sendMessage("§cAn error occured. See console for details.§r"); + PluginMain.LastException=e; //2015.08.09. + } + //} + //else + //player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static void DoAdmin(Player player, String[] args) + { //2015.08.09. + if(player==null || player.isOp() || player.getName()=="NorbiPeti") + { + //System.out.println("Args length: " + args.length); + if(args.length==1) + { + String message="§cUsage: /u admin reload|playerinfo§r"; + SendMessage(player, message); + return; + } + //args[0] is "admin" + switch(args[1].toLowerCase()) + { + case "reload": + DoReload(player); + break; + case "playerinfo": + DoPlayerInfo(player, args); + break; + case "getlasterror": + DoGetLastError(player, args); + case "confirm": + DoReload(); + break; + default: + String message="§cUsage: /u admin reload|playerinfo§r"; + SendMessage(player, message); + return; + } + } + else + player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static void DoPlayerInfo(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "playerinfo" + if(args.length==2) + { + String message="§cUsage: /u admin playerinfo §r"; + SendMessage(player, message); + return; + } + if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2])) + { + String message="§cPlayer not found: "+args[2]+"§r"; + SendMessage(player, message); + return; + } + MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]); + SendMessage(player, "Player name: "+p.PlayerName); + SendMessage(player, "User flair: "+p.Flair); + SendMessage(player, "Username: "+p.UserName); + SendMessage(player, "Flair accepted: "+p.AcceptedFlair); + SendMessage(player, "Flair ignored: "+p.IgnoredFlair); + } + private static void SendMessage(Player player, String message) + { //2015.08.09. + if(player==null) + System.out.println(message); + else + player.sendMessage(message); + } + private static void DoGetLastError(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "getlasterror" + if(PluginMain.LastException!=null) + { + SendMessage(player, "Last error:"); + SendMessage(player, PluginMain.LastException.toString()); + PluginMain.LastException=null; + } + else + SendMessage(player, "There were no exceptions."); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/5d/a0a6c2d0d23e001518fa86d7ae2a1cf8 b/.metadata/.plugins/org.eclipse.core.resources/.history/5d/a0a6c2d0d23e001518fa86d7ae2a1cf8 new file mode 100644 index 0000000..5d7321f --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/5d/a0a6c2d0d23e001518fa86d7ae2a1cf8 @@ -0,0 +1,215 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; + +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class Commands implements CommandExecutor { + // This method is called, when somebody uses our command + @Override + public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { + if (sender instanceof Player) { + Player player = (Player) sender; + if(args.length<1) + return false; + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. + //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) + if(p.Flair==null) + { + player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); + return true; + } + switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. + { + case "accept": + { + if(p.IgnoredFlair) + p.IgnoredFlair=false; //2015.08.08. + if(!p.AcceptedFlair) + { + String flair=p.Flair; //2015.08.08. + //PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + PluginMain.AppendPlayerDisplayFlair(p, player); + p.AcceptedFlair=true; //2015.08.08. + player.sendMessage("§6Your flair has been set:§r "+flair); + } + else + player.sendMessage("§cYou already have this user's flair.§r"); + break; + } + case "ignore": + { + if(p.AcceptedFlair) + p.AcceptedFlair=false; //2015.08.08. + if(!p.IgnoredFlair) + { + p.IgnoredFlair=true; + String flair=p.Flair; //2015.08.08. + PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. + player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); + } + else + player.sendMessage("§cYou already ignored this request.§r"); + break; + } + /*case "reload": //2015.07.20. + DoReload(player); + break;*/ + case "admin": //2015.08.09. + DoAdmin(player, args); + break; + case "nonpresser": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§7(non-pr.)§r"; + break; + case "cantpress": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§r(can't press)§r"; + break; + default: + return false; + } + return true; + } + /*if(args[0].toLowerCase()=="reload") + DoReload(null); //2015.07.20.*/ + else if(args.length>0 && args[0].toLowerCase().equals("admin")) //2015.08.09. + { + DoAdmin(null, args); //2015.08.09. + return true; //2015.08.09. + } + return false; + } + private static void DoReload(Player player) + { //2015.07.20. + //if(player==null || player.isOp() || player.getName()=="NorbiPeti") + //{ + try + { + File file=new File("autoflairconfig.txt"); + if(file.exists()) + { + PluginMain.LoadFiles(true); //2015.08.09. + 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); + PluginMain.AppendPlayerDisplayFlair(mp, p); //2015.08.09. + } + } + //String msg="§6Reloaded config file.§r"; + String msg="§6Reloaded all files.§r"; + SendMessage(player, msg); //2015.08.09. + } + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + if(player!=null) + player.sendMessage("§cAn error occured. See console for details.§r"); + PluginMain.LastException=e; //2015.08.09. + } + //} + //else + //player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static void DoAdmin(Player player, String[] args) + { //2015.08.09. + if(player==null || player.isOp() || player.getName()=="NorbiPeti") + { + //System.out.println("Args length: " + args.length); + if(args.length==1) + { + String message="§cUsage: /u admin reload|playerinfo§r"; + SendMessage(player, message); + return; + } + //args[0] is "admin" + switch(args[1].toLowerCase()) + { + case "reload": + DoReload(player); + break; + case "playerinfo": + DoPlayerInfo(player, args); + break; + case "getlasterror": + DoGetLastError(player, args); + default: + String message="§cUsage: /u admin reload|playerinfo§r"; + SendMessage(player, message); + return; + } + } + else + player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static void DoPlayerInfo(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "playerinfo" + if(args.length==2) + { + String message="§cUsage: /u admin playerinfo §r"; + SendMessage(player, message); + return; + } + if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2])) + { + String message="§cPlayer not found: "+args[2]+"§r"; + SendMessage(player, message); + return; + } + MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]); + SendMessage(player, "Player name: "+p.PlayerName); + SendMessage(player, "User flair: "+p.Flair); + SendMessage(player, "Username: "+p.UserName); + SendMessage(player, "Flair accepted: "+p.AcceptedFlair); + SendMessage(player, "Flair ignored: "+p.IgnoredFlair); + } + private static void SendMessage(Player player, String message) + { //2015.08.09. + if(player==null) + System.out.println(message); + else + player.sendMessage(message); + } + private static void DoGetLastError(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "getlasterror" + if(PluginMain.LastException!=null) + { + SendMessage(player, "Last error:"); + SendMessage(player, PluginMain.LastException.toString()); + PluginMain.LastException=null; + } + else + SendMessage(player, "There were no exceptions."); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/5d/a0befd81d33e001518fa86d7ae2a1cf8 b/.metadata/.plugins/org.eclipse.core.resources/.history/5d/a0befd81d33e001518fa86d7ae2a1cf8 new file mode 100644 index 0000000..3318744 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/5d/a0befd81d33e001518fa86d7ae2a1cf8 @@ -0,0 +1,216 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; + +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class Commands implements CommandExecutor { + // This method is called, when somebody uses our command + @Override + public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { + if (sender instanceof Player) { + Player player = (Player) sender; + if(args.length<1) + return false; + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. + //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) + if(p.Flair==null) + { + player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); + return true; + } + switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. + { + case "accept": + { + if(p.IgnoredFlair) + p.IgnoredFlair=false; //2015.08.08. + if(!p.AcceptedFlair) + { + String flair=p.Flair; //2015.08.08. + //PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + PluginMain.AppendPlayerDisplayFlair(p, player); + p.AcceptedFlair=true; //2015.08.08. + player.sendMessage("§6Your flair has been set:§r "+flair); + } + else + player.sendMessage("§cYou already have this user's flair.§r"); + break; + } + case "ignore": + { + if(p.AcceptedFlair) + p.AcceptedFlair=false; //2015.08.08. + if(!p.IgnoredFlair) + { + p.IgnoredFlair=true; + String flair=p.Flair; //2015.08.08. + PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. + player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); + } + else + player.sendMessage("§cYou already ignored this request.§r"); + break; + } + /*case "reload": //2015.07.20. + DoReload(player); + break;*/ + case "admin": //2015.08.09. + DoAdmin(player, args); + break; + case "nonpresser": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§7(non-pr.)§r"; + break; + case "cantpress": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§r(can't press)§r"; + break; + default: + return false; + } + return true; + } + /*if(args[0].toLowerCase()=="reload") + DoReload(null); //2015.07.20.*/ + else if(args.length>0 && args[0].toLowerCase().equals("admin")) //2015.08.09. + { + DoAdmin(null, args); //2015.08.09. + return true; //2015.08.09. + } + return false; + } + private static void DoReload(Player player) + { //2015.07.20. + //if(player==null || player.isOp() || player.getName()=="NorbiPeti") + //{ + try + { + File file=new File("autoflairconfig.txt"); + if(file.exists()) + { + PluginMain.LoadFiles(true); //2015.08.09. + for(Player p : PluginMain.GetPlayers()) + { + MaybeOfflinePlayer mp = MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName()); + if(mp.Flair!=null) + { + String flair=mp.Flair; + PluginMain.RemovePlayerDisplayFlairFinal(p, flair); + //PluginMain.AppendPlayerDisplayFlairFinal(p, flair); + PluginMain.AppendPlayerDisplayFlair(mp, p); //2015.08.09. + } + String msg="§6Note: The auto-flair plugin has been reloaded. You might need to wait 10s to have your flair.§r"; //2015.08.09. + p.sendMessage(msg); //2015.08.09. + } + //String msg="§6Reloaded config file.§r"; + //SendMessage(player, msg); //2015.08.09. + } + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + if(player!=null) + player.sendMessage("§cAn error occured. See console for details.§r"); + PluginMain.LastException=e; //2015.08.09. + } + //} + //else + //player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static void DoAdmin(Player player, String[] args) + { //2015.08.09. + if(player==null || player.isOp() || player.getName()=="NorbiPeti") + { + //System.out.println("Args length: " + args.length); + if(args.length==1) + { + String message="§cUsage: /u admin reload|playerinfo§r"; + SendMessage(player, message); + return; + } + //args[0] is "admin" + switch(args[1].toLowerCase()) + { + case "reload": + DoReload(player); + break; + case "playerinfo": + DoPlayerInfo(player, args); + break; + case "getlasterror": + DoGetLastError(player, args); + default: + String message="§cUsage: /u admin reload|playerinfo§r"; + SendMessage(player, message); + return; + } + } + else + player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static void DoPlayerInfo(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "playerinfo" + if(args.length==2) + { + String message="§cUsage: /u admin playerinfo §r"; + SendMessage(player, message); + return; + } + if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2])) + { + String message="§cPlayer not found: "+args[2]+"§r"; + SendMessage(player, message); + return; + } + MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]); + SendMessage(player, "Player name: "+p.PlayerName); + SendMessage(player, "User flair: "+p.Flair); + SendMessage(player, "Username: "+p.UserName); + SendMessage(player, "Flair accepted: "+p.AcceptedFlair); + SendMessage(player, "Flair ignored: "+p.IgnoredFlair); + } + private static void SendMessage(Player player, String message) + { //2015.08.09. + if(player==null) + System.out.println(message); + else + player.sendMessage(message); + } + private static void DoGetLastError(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "getlasterror" + if(PluginMain.LastException!=null) + { + SendMessage(player, "Last error:"); + SendMessage(player, PluginMain.LastException.toString()); + PluginMain.LastException=null; + } + else + SendMessage(player, "There were no exceptions."); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/5f/2061341bd23e001518fa86d7ae2a1cf8 b/.metadata/.plugins/org.eclipse.core.resources/.history/5f/2061341bd23e001518fa86d7ae2a1cf8 new file mode 100644 index 0000000..ff39b38 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/5f/2061341bd23e001518fa86d7ae2a1cf8 @@ -0,0 +1,375 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStream; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLConnection; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + +import org.apache.commons.io.IOUtils; +import org.bukkit.entity.Player; +import org.bukkit.plugin.java.JavaPlugin; +import org.json.JSONArray; +import org.json.JSONObject; + +import com.palmergames.bukkit.towny.object.Town; +import com.palmergames.bukkit.towny.object.WorldCoord; + +public class PluginMain extends JavaPlugin +{ //Translated to Java: 2015.07.15. + //A user, which flair isn't obtainable: + //https://www.reddit.com/r/thebutton/comments/31c32v/i_pressed_the_button_without_really_thinking/ + private static PluginMain Instance; + // Fired when plugin is first enabled + @Override + public void onEnable() + { + System.out.println("The Button Auto-flair Plugin by NorbiPeti (:P)"); + getServer().getPluginManager().registerEvents(new PlayerListener(), this); + this.getCommand("u").setExecutor(new Commands()); + this.getCommand("u").setUsage(this.getCommand("u").getUsage().replace('&', '§')); + Instance=this; //2015.08.08. + LoadFiles(false); //2015.08.09. + Runnable r=new Runnable(){public void run(){ThreadMethod();}}; + Thread t=new Thread(r); + t.start(); + } + Boolean stop=false; + // Fired when plugin is disabled + @Override + public void onDisable() + { + try + { + FileWriter fw; + fw = new FileWriter("flairsaccepted.txt"); + fw.close(); + fw = new FileWriter("flairsignored.txt"); + fw.close(); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + try { + File file=new File("flairsaccepted.txt"); + BufferedWriter bw=new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.AcceptedFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + file=new File("flairsignored.txt"); + bw = new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.IgnoredFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + stop=true; + } + + public void ThreadMethod() //<-- 2015.07.16. + { + while(!stop) + { + try + { + String body=DownloadString("https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/autoflair_system_comment_your_minecraft_name_and/.json?limit=1000"); + JSONArray json=new JSONArray(body).getJSONObject(1).getJSONObject("data").getJSONArray("children"); + for(Object obj : json) + { + JSONObject item = (JSONObject)obj; + String author=item.getJSONObject("data").getString("author"); + String ign=item.getJSONObject("data").getString("body"); + int start = ign.indexOf("IGN:") + "IGN:".length(); + int end = ign.indexOf(' ', start); + if (end == -1 || end == start) + end=ign.indexOf('\n', start); //2015.07.15. + if (end == -1 || end == start) + ign = ign.substring(start); + else + ign = ign.substring(start, end); + ign = ign.trim(); + if(HasIGFlair(ign)) + continue; + try { + Thread.sleep(10); + } catch(InterruptedException ex) { + Thread.currentThread().interrupt(); + } + String[] flairdata = DownloadString("http://karmadecay.com/thebutton-data.php?users=" + author).replace("\"", "").split(":"); + String flair; + if(flairdata.length > 1) //2015.07.15. + flair = flairdata[1]; + else + flair=""; + if (flair != "-1") + flair = flair + "s"; + else + flair = "non-presser"; + String flairclass; + if(flairdata.length>2) + flairclass = flairdata[2]; + else + flairclass="unknown"; + SetFlair(ign, flair, flairclass, author); + } + Thread.sleep(10000); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + } + + public static Exception LastException; //2015.08.09. + + public String DownloadString(String urlstr) throws MalformedURLException, IOException + { + URL url = new URL(urlstr); + URLConnection con = url.openConnection(); + con.setRequestProperty("User-Agent", "TheButtonAutoFlair"); + InputStream in = con.getInputStream(); + String encoding = con.getContentEncoding(); + encoding = encoding == null ? "UTF-8" : encoding; + String body = IOUtils.toString(in, encoding); + in.close(); + return body; + } + + public static Map TownColors=new HashMap(); //2015.07.20. + public Boolean HasIGFlair(String playername) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + return p.Flair!=null; //2015.08.08. + } + + public void SetFlair(String playername, String text, String flairclass, String username) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + String finalflair; + p.FlairDecided=true; + switch(flairclass) + { + case "press-1": + finalflair="§c("+text+")§r"; + break; + case "press-2": + finalflair="§6("+text+")§r"; + break; + case "press-3": + finalflair="§e("+text+")§r"; + break; + case "press-4": + finalflair="§a("+text+")§r"; + break; + case "press-5": + finalflair="§9("+text+")§r"; + break; + 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; + case "undecided": //2015.08.09. + p.FlairDecided=false; + finalflair=""; + break; + default: + finalflair=""; + break; + } + if(finalflair.length()==0) //<-- 2015.07.20. + return; + p.Flair=finalflair; //2015.08.08. + p.UserName=username; //2015.08.08. + System.out.println("Added new flair to "+playername+": "+finalflair); + for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08. + { + if(player.getName().equals(playername)) + { + //AppendPlayerDisplayFlair(player, username, finalflair); + AppendPlayerDisplayFlair(p, player); + break; + } + } + } + + public static String GetFlair(Player player) + { //2015.07.16. + String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08. + return flair==null ? "" : flair; + } + + //public static void AppendPlayerDisplayFlair(Player player, String username, String flair) + public static void AppendPlayerDisplayFlair(MaybeOfflinePlayer player, Player p) //<-- 2015.08.09. + { + + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).IgnoredFlair) + return; + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).AcceptedFlair) + { + AppendPlayerDisplayFlairFinal(p, player.Flair); //2015.07.20. + if(!player.FlairDecided) + p.sendMessage("§9Your flair type is unknown. Are you a non-presser or a can't press? (/u nonpresser or /u cantpress)§r"); //2015.08.09. + } + else + p.sendMessage("§9Are you Reddit user "+player.UserName+"?§r §6Type /u accept or /u ignore§r"); + } + + private static void AppendPlayerDisplayFlairFinal(Player player, String flair) + { //2015.07.20. + String color = GetColorForTown(GetPlayerTown(player)); //TO!DO: Multiple colors put on first capital letters + String[] colors = color.substring(1).split("§"); + String displayname=player.getName(); //2015.08.08. + ArrayList Positions=new ArrayList<>(); + for(int i=0; i=colors.length) + { + int x=0; + for(int i=0; i GetPlayers() + { + return Instance.getServer().getOnlinePlayers(); + } + + public static void LoadFiles(boolean reload) //<-- 2015.08.09. + { + if(reload) + { //2015.08.09. + System.out.println("Auto-flair plugin cleanup for reloading..."); + MaybeOfflinePlayer.AllPlayers.clear(); + TownColors.clear(); + } + System.out.println("Loading files for auto-flair plugin..."); //2015.08.09. + try { + File file=new File("flairsaccepted.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + //System.out.println("Name: " + name); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("flairsignored.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsignored.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("autoflairconfig.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + TownColors.put(s[0], s[1]); + } + br.close(); + } + //throw new IOException("Test"); //2015.08.09. + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/5f/60d7f94a0e3e00151089cca86c5b1a99 b/.metadata/.plugins/org.eclipse.core.resources/.history/5f/60d7f94a0e3e00151089cca86c5b1a99 deleted file mode 100644 index efac5c3..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/5f/60d7f94a0e3e00151089cca86c5b1a99 +++ /dev/null @@ -1,434 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import java.io.BufferedReader; -import java.io.BufferedWriter; -import java.io.File; -import java.io.FileReader; -import java.io.FileWriter; -import java.io.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 deleted file mode 100644 index 87c0c13..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/5f/c0841a72043e00151c31fb33fff4337f +++ /dev/null @@ -1,126 +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; - 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/c0b28923ce3e001518fa86d7ae2a1cf8 b/.metadata/.plugins/org.eclipse.core.resources/.history/5f/c0b28923ce3e001518fa86d7ae2a1cf8 new file mode 100644 index 0000000..26a60f9 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/5f/c0b28923ce3e001518fa86d7ae2a1cf8 @@ -0,0 +1,355 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStream; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLConnection; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + +import org.apache.commons.io.IOUtils; +import org.bukkit.entity.Player; +import org.bukkit.plugin.java.JavaPlugin; +import org.json.JSONArray; +import org.json.JSONObject; + +import com.palmergames.bukkit.towny.object.Town; +import com.palmergames.bukkit.towny.object.WorldCoord; + +public class PluginMain extends JavaPlugin +{ //Translated to Java: 2015.07.15. + //A user, which flair isn't obtainable: + //https://www.reddit.com/r/thebutton/comments/31c32v/i_pressed_the_button_without_really_thinking/ + private static PluginMain Instance; + // Fired when plugin is first enabled + @Override + public void onEnable() + { + System.out.println("The Button Auto-flair Plugin by NorbiPeti (:P)"); + getServer().getPluginManager().registerEvents(new PlayerListener(), this); + this.getCommand("u").setExecutor(new Commands()); + this.getCommand("u").setUsage(this.getCommand("u").getUsage().replace('&', '§')); + Instance=this; //2015.08.08. + try { + File file=new File("flairsaccepted.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + //System.out.println("Name: " + name); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("flairsignored.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsignored.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("autoflairconfig.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + TownColors.put(s[0], s[1]); + } + br.close(); + } + //throw new IOException("Test"); //2015.08.09. + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + Runnable r=new Runnable(){public void run(){ThreadMethod();}}; + Thread t=new Thread(r); + t.start(); + } + Boolean stop=false; + // Fired when plugin is disabled + @Override + public void onDisable() + { + try + { + FileWriter fw; + fw = new FileWriter("flairsaccepted.txt"); + fw.close(); + fw = new FileWriter("flairsignored.txt"); + fw.close(); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + try { + File file=new File("flairsaccepted.txt"); + BufferedWriter bw=new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.AcceptedFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + file=new File("flairsignored.txt"); + bw = new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.IgnoredFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + stop=true; + } + + public void ThreadMethod() //<-- 2015.07.16. + { + while(!stop) + { + try + { + String body=DownloadString("https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/autoflair_system_comment_your_minecraft_name_and/.json?limit=1000"); + JSONArray json=new JSONArray(body).getJSONObject(1).getJSONObject("data").getJSONArray("children"); + for(Object obj : json) + { + JSONObject item = (JSONObject)obj; + String author=item.getJSONObject("data").getString("author"); + String ign=item.getJSONObject("data").getString("body"); + int start = ign.indexOf("IGN:") + "IGN:".length(); + int end = ign.indexOf(' ', start); + if (end == -1 || end == start) + end=ign.indexOf('\n', start); //2015.07.15. + if (end == -1 || end == start) + ign = ign.substring(start); + else + ign = ign.substring(start, end); + ign = ign.trim(); + if(HasIGFlair(ign)) + continue; + try { + Thread.sleep(10); + } catch(InterruptedException ex) { + Thread.currentThread().interrupt(); + } + String[] flairdata = DownloadString("http://karmadecay.com/thebutton-data.php?users=" + author).replace("\"", "").split(":"); + String flair; + if(flairdata.length > 1) //2015.07.15. + flair = flairdata[1]; + else + flair=""; + if (flair != "-1") + flair = flair + "s"; + else + flair = "non-presser"; + String flairclass; + if(flairdata.length>2) + flairclass = flairdata[2]; + else + flairclass="unknown"; + SetFlair(ign, flair, flairclass, author); + } + Thread.sleep(10000); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + } + + public static Exception LastException; //2015.08.09. + + public String DownloadString(String urlstr) throws MalformedURLException, IOException + { + URL url = new URL(urlstr); + URLConnection con = url.openConnection(); + con.setRequestProperty("User-Agent", "TheButtonAutoFlair"); + InputStream in = con.getInputStream(); + String encoding = con.getContentEncoding(); + encoding = encoding == null ? "UTF-8" : encoding; + String body = IOUtils.toString(in, encoding); + in.close(); + return body; + } + + public static Map TownColors=new HashMap(); //2015.07.20. + public Boolean HasIGFlair(String playername) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + return p.Flair!=null; //2015.08.08. + } + + public void SetFlair(String playername, String text, String flairclass, String username) + { + String finalflair; + switch(flairclass) + { + case "press-1": + finalflair="§c("+text+")§r"; + break; + case "press-2": + finalflair="§6("+text+")§r"; + break; + case "press-3": + finalflair="§e("+text+")§r"; + break; + case "press-4": + finalflair="§a("+text+")§r"; + break; + case "press-5": + finalflair="§9("+text+")§r"; + break; + case "press-6": + finalflair="§5("+text+")§r"; + break; + case "no-press": + finalflair="§7(non-pr.)§r"; + break; + case "cheater": + finalflair="§5("+text+")§r"; + break; + case "cant-press": //2015.08.08. + finalflair="§r(can't press)§r"; + break; + case "undecided": //2015.08.09. + + finalflair=""; + break; + default: + finalflair=""; + break; + } + if(finalflair.length()==0) //<-- 2015.07.20. + return; + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + p.Flair=finalflair; //2015.08.08. + p.UserName=username; //2015.08.08. + System.out.println("Added new flair to "+playername+": "+finalflair); + for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08. + { + if(player.getName().equals(playername)) + { + AppendPlayerDisplayFlair(player, username, finalflair); + break; + } + } + } + + public static String GetFlair(Player player) + { //2015.07.16. + String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08. + return flair==null ? "" : flair; + } + + public static void AppendPlayerDisplayFlair(Player player, String username, String flair) + { + if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).IgnoredFlair) + return; + if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).AcceptedFlair) + AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + else + player.sendMessage("§9Are you Reddit user "+username+"?§r §6Type /u accept or /u ignore§r"); + } + + public static void AppendPlayerDisplayFlairFinal(Player player, String flair) + { //2015.07.20. + String color = GetColorForTown(GetPlayerTown(player)); //TO!DO: Multiple colors put on first capital letters + String[] colors = color.substring(1).split("§"); + String displayname=player.getName(); //2015.08.08. + ArrayList Positions=new ArrayList<>(); + for(int i=0; i=colors.length) + { + int x=0; + for(int i=0; i GetPlayers() + { + return Instance.getServer().getOnlinePlayers(); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/6/2029114dd33e001518fa86d7ae2a1cf8 b/.metadata/.plugins/org.eclipse.core.resources/.history/6/2029114dd33e001518fa86d7ae2a1cf8 new file mode 100644 index 0000000..14132d5 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/6/2029114dd33e001518fa86d7ae2a1cf8 @@ -0,0 +1,216 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; + +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class Commands implements CommandExecutor { + // This method is called, when somebody uses our command + @Override + public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { + if (sender instanceof Player) { + Player player = (Player) sender; + if(args.length<1) + return false; + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. + //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) + if(p.Flair==null) + { + player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); + return true; + } + switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. + { + case "accept": + { + if(p.IgnoredFlair) + p.IgnoredFlair=false; //2015.08.08. + if(!p.AcceptedFlair) + { + String flair=p.Flair; //2015.08.08. + //PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + PluginMain.AppendPlayerDisplayFlair(p, player); + p.AcceptedFlair=true; //2015.08.08. + player.sendMessage("§6Your flair has been set:§r "+flair); + } + else + player.sendMessage("§cYou already have this user's flair.§r"); + break; + } + case "ignore": + { + if(p.AcceptedFlair) + p.AcceptedFlair=false; //2015.08.08. + if(!p.IgnoredFlair) + { + p.IgnoredFlair=true; + String flair=p.Flair; //2015.08.08. + PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. + player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); + } + else + player.sendMessage("§cYou already ignored this request.§r"); + break; + } + /*case "reload": //2015.07.20. + DoReload(player); + break;*/ + case "admin": //2015.08.09. + DoAdmin(player, args); + break; + case "nonpresser": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§7(non-pr.)§r"; + break; + case "cantpress": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§r(can't press)§r"; + break; + default: + return false; + } + return true; + } + /*if(args[0].toLowerCase()=="reload") + DoReload(null); //2015.07.20.*/ + else if(args.length>0 && args[0].toLowerCase().equals("admin")) //2015.08.09. + { + DoAdmin(null, args); //2015.08.09. + return true; //2015.08.09. + } + return false; + } + private static void DoReload(Player player) + { //2015.07.20. + //if(player==null || player.isOp() || player.getName()=="NorbiPeti") + //{ + try + { + File file=new File("autoflairconfig.txt"); + if(file.exists()) + { + PluginMain.LoadFiles(true); //2015.08.09. + for(Player p : PluginMain.GetPlayers()) + { + MaybeOfflinePlayer mp = MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName()); + if(mp.Flair!=null) + { + String flair=mp.Flair; + PluginMain.RemovePlayerDisplayFlairFinal(p, flair); + //PluginMain.AppendPlayerDisplayFlairFinal(p, flair); + PluginMain.AppendPlayerDisplayFlair(mp, p); //2015.08.09. + } + String msg="§6Note: The auto-flair plugin has been reloaded. You might need to wait 10s to have your flair.§r"; + p.sendMessage(msg); + } + //String msg="§6Reloaded config file.§r"; + //SendMessage(player, msg); //2015.08.09. + } + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + if(player!=null) + player.sendMessage("§cAn error occured. See console for details.§r"); + PluginMain.LastException=e; //2015.08.09. + } + //} + //else + //player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static void DoAdmin(Player player, String[] args) + { //2015.08.09. + if(player==null || player.isOp() || player.getName()=="NorbiPeti") + { + //System.out.println("Args length: " + args.length); + if(args.length==1) + { + String message="§cUsage: /u admin reload|playerinfo§r"; + SendMessage(player, message); + return; + } + //args[0] is "admin" + switch(args[1].toLowerCase()) + { + case "reload": + DoReload(player); + break; + case "playerinfo": + DoPlayerInfo(player, args); + break; + case "getlasterror": + DoGetLastError(player, args); + default: + String message="§cUsage: /u admin reload|playerinfo§r"; + SendMessage(player, message); + return; + } + } + else + player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static void DoPlayerInfo(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "playerinfo" + if(args.length==2) + { + String message="§cUsage: /u admin playerinfo §r"; + SendMessage(player, message); + return; + } + if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2])) + { + String message="§cPlayer not found: "+args[2]+"§r"; + SendMessage(player, message); + return; + } + MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]); + SendMessage(player, "Player name: "+p.PlayerName); + SendMessage(player, "User flair: "+p.Flair); + SendMessage(player, "Username: "+p.UserName); + SendMessage(player, "Flair accepted: "+p.AcceptedFlair); + SendMessage(player, "Flair ignored: "+p.IgnoredFlair); + } + private static void SendMessage(Player player, String message) + { //2015.08.09. + if(player==null) + System.out.println(message); + else + player.sendMessage(message); + } + private static void DoGetLastError(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "getlasterror" + if(PluginMain.LastException!=null) + { + SendMessage(player, "Last error:"); + SendMessage(player, PluginMain.LastException.toString()); + PluginMain.LastException=null; + } + else + SendMessage(player, "There were no exceptions."); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/6/208a8252ce3e001518fa86d7ae2a1cf8 b/.metadata/.plugins/org.eclipse.core.resources/.history/6/208a8252ce3e001518fa86d7ae2a1cf8 new file mode 100644 index 0000000..7477f60 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/6/208a8252ce3e001518fa86d7ae2a1cf8 @@ -0,0 +1,31 @@ +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 FlairClassType FlairType; //2015.08.09. + 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); + } + public enum FlairClassType + { //2015.08.09. + NonPresser, + CantPress, + Undecided + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/6/a032431fd23e001518fa86d7ae2a1cf8 b/.metadata/.plugins/org.eclipse.core.resources/.history/6/a032431fd23e001518fa86d7ae2a1cf8 new file mode 100644 index 0000000..b21f1ef --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/6/a032431fd23e001518fa86d7ae2a1cf8 @@ -0,0 +1,375 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStream; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLConnection; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + +import org.apache.commons.io.IOUtils; +import org.bukkit.entity.Player; +import org.bukkit.plugin.java.JavaPlugin; +import org.json.JSONArray; +import org.json.JSONObject; + +import com.palmergames.bukkit.towny.object.Town; +import com.palmergames.bukkit.towny.object.WorldCoord; + +public class PluginMain extends JavaPlugin +{ //Translated to Java: 2015.07.15. + //A user, which flair isn't obtainable: + //https://www.reddit.com/r/thebutton/comments/31c32v/i_pressed_the_button_without_really_thinking/ + private static PluginMain Instance; + // Fired when plugin is first enabled + @Override + public void onEnable() + { + System.out.println("The Button Auto-flair Plugin by NorbiPeti (:P)"); + getServer().getPluginManager().registerEvents(new PlayerListener(), this); + this.getCommand("u").setExecutor(new Commands()); + this.getCommand("u").setUsage(this.getCommand("u").getUsage().replace('&', '§')); + Instance=this; //2015.08.08. + LoadFiles(false); //2015.08.09. + Runnable r=new Runnable(){public void run(){ThreadMethod();}}; + Thread t=new Thread(r); + t.start(); + } + Boolean stop=false; + // Fired when plugin is disabled + @Override + public void onDisable() + { + try + { + FileWriter fw; + fw = new FileWriter("flairsaccepted.txt"); + fw.close(); + fw = new FileWriter("flairsignored.txt"); + fw.close(); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + try { + File file=new File("flairsaccepted.txt"); + BufferedWriter bw=new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.AcceptedFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + file=new File("flairsignored.txt"); + bw = new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.IgnoredFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + stop=true; + } + + public void ThreadMethod() //<-- 2015.07.16. + { + while(!stop) + { + try + { + String body=DownloadString("https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/autoflair_system_comment_your_minecraft_name_and/.json?limit=1000"); + JSONArray json=new JSONArray(body).getJSONObject(1).getJSONObject("data").getJSONArray("children"); + for(Object obj : json) + { + JSONObject item = (JSONObject)obj; + String author=item.getJSONObject("data").getString("author"); + String ign=item.getJSONObject("data").getString("body"); + int start = ign.indexOf("IGN:") + "IGN:".length(); + int end = ign.indexOf(' ', start); + if (end == -1 || end == start) + end=ign.indexOf('\n', start); //2015.07.15. + if (end == -1 || end == start) + ign = ign.substring(start); + else + ign = ign.substring(start, end); + ign = ign.trim(); + if(HasIGFlair(ign)) + continue; + try { + Thread.sleep(10); + } catch(InterruptedException ex) { + Thread.currentThread().interrupt(); + } + String[] flairdata = DownloadString("http://karmadecay.com/thebutton-data.php?users=" + author).replace("\"", "").split(":"); + String flair; + if(flairdata.length > 1) //2015.07.15. + flair = flairdata[1]; + else + flair=""; + if (flair != "-1") + flair = flair + "s"; + else + flair = "non-presser"; + String flairclass; + if(flairdata.length>2) + flairclass = flairdata[2]; + else + flairclass="unknown"; + SetFlair(ign, flair, flairclass, author); + } + Thread.sleep(10000); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + } + + public static Exception LastException; //2015.08.09. + + public String DownloadString(String urlstr) throws MalformedURLException, IOException + { + URL url = new URL(urlstr); + URLConnection con = url.openConnection(); + con.setRequestProperty("User-Agent", "TheButtonAutoFlair"); + InputStream in = con.getInputStream(); + String encoding = con.getContentEncoding(); + encoding = encoding == null ? "UTF-8" : encoding; + String body = IOUtils.toString(in, encoding); + in.close(); + return body; + } + + public static Map TownColors=new HashMap(); //2015.07.20. + public Boolean HasIGFlair(String playername) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + return p.Flair!=null; //2015.08.08. + } + + public void SetFlair(String playername, String text, String flairclass, String username) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + String finalflair; + p.FlairDecided=true; + switch(flairclass) + { + case "press-1": + finalflair="§c("+text+")§r"; + break; + case "press-2": + finalflair="§6("+text+")§r"; + break; + case "press-3": + finalflair="§e("+text+")§r"; + break; + case "press-4": + finalflair="§a("+text+")§r"; + break; + case "press-5": + finalflair="§9("+text+")§r"; + break; + 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; + case "undecided": //2015.08.09. + p.FlairDecided=false; + finalflair=""; + break; + default: + finalflair=""; + break; + } + if(finalflair.length()==0) //<-- 2015.07.20. + return; + p.Flair=finalflair; //2015.08.08. + p.UserName=username; //2015.08.08. + System.out.println("Added new flair to "+playername+": "+finalflair); + for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08. + { + if(player.getName().equals(playername)) + { + //AppendPlayerDisplayFlair(player, username, finalflair); + AppendPlayerDisplayFlair(p, player); + break; + } + } + } + + public static String GetFlair(Player player) + { //2015.07.16. + String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08. + return flair==null ? "" : flair; + } + + //public static void AppendPlayerDisplayFlair(Player player, String username, String flair) + public static void AppendPlayerDisplayFlair(MaybeOfflinePlayer player, Player p) //<-- 2015.08.09. + { + + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).IgnoredFlair) + return; + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).AcceptedFlair) + { + AppendPlayerDisplayFlairFinal(p, player.Flair); //2015.07.20. + if(!player.FlairDecided) + p.sendMessage("§9Your flair type is unknown. Are you a non-presser or a can't press? (/u nonpresser or /u cantpress)§r"); //2015.08.09. + } + else + p.sendMessage("§9Are you Reddit user "+player.UserName+"?§r §6Type /u accept or /u ignore§r"); + } + + private static void AppendPlayerDisplayFlairFinal(Player player, String flair) + { //2015.07.20. + String color = GetColorForTown(GetPlayerTown(player)); //TO!DO: Multiple colors put on first capital letters + String[] colors = color.substring(1).split("§"); + String displayname=player.getName(); //2015.08.08. + ArrayList Positions=new ArrayList<>(); + for(int i=0; i=colors.length) + { + int x=0; + for(int i=0; i GetPlayers() + { + return Instance.getServer().getOnlinePlayers(); + } + + public static void LoadFiles(boolean reload) //<-- 2015.08.09. + { + if(reload) + { //2015.08.09. + System.out.println("Auto-flair plugin cleanup for reloading..."); + MaybeOfflinePlayer.AllPlayers.clear(); + TownColors.clear(); + } + System.out.println("Loading files for auto-flair plugin..."); //2015.08.09. + try { + File file=new File("flairsaccepted.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + //System.out.println("Name: " + name); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("flairsignored.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsignored.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("autoflairconfig.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + TownColors.put(s[0], s[1]); + } + br.close(); + } + //throw new IOException("Test"); //2015.08.09. + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/60/104f566fdd3e001517108d149b613203 b/.metadata/.plugins/org.eclipse.core.resources/.history/60/104f566fdd3e001517108d149b613203 new file mode 100644 index 0000000..d462046 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/60/104f566fdd3e001517108d149b613203 @@ -0,0 +1,400 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStream; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLConnection; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + +import org.apache.commons.io.IOUtils; +import org.bukkit.entity.Player; +import org.bukkit.plugin.java.JavaPlugin; +import org.json.JSONArray; +import org.json.JSONObject; + +import com.palmergames.bukkit.towny.object.Town; +import com.palmergames.bukkit.towny.object.WorldCoord; + +public class PluginMain extends JavaPlugin +{ //Translated to Java: 2015.07.15. + //A user, which flair isn't obtainable: + //https://www.reddit.com/r/thebutton/comments/31c32v/i_pressed_the_button_without_really_thinking/ + private static PluginMain Instance; + // Fired when plugin is first enabled + @Override + public void onEnable() + { + System.out.println("The Button Auto-flair Plugin by NorbiPeti (:P)"); + getServer().getPluginManager().registerEvents(new PlayerListener(), this); + this.getCommand("u").setExecutor(new Commands()); + this.getCommand("u").setUsage(this.getCommand("u").getUsage().replace('&', '§')); + Instance=this; //2015.08.08. + LoadFiles(false); //2015.08.09. + Runnable r=new Runnable(){public void run(){ThreadMethod();}}; + Thread t=new Thread(r); + t.start(); + } + Boolean stop=false; + // Fired when plugin is disabled + @Override + public void onDisable() + { + SaveFiles(); //2015.08.09. + stop=true; + } + + public void ThreadMethod() //<-- 2015.07.16. + { + while(!stop) + { + try + { + String body=DownloadString("https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/autoflair_system_comment_your_minecraft_name_and/.json?limit=1000"); + JSONArray json=new JSONArray(body).getJSONObject(1).getJSONObject("data").getJSONArray("children"); + for(Object obj : json) + { + JSONObject item = (JSONObject)obj; + String author=item.getJSONObject("data").getString("author"); + String ign=item.getJSONObject("data").getString("body"); + int start = ign.indexOf("IGN:") + "IGN:".length(); + if(start==-1) + continue; //2015.08.09. + int end = ign.indexOf(' ', start); + if (end == -1 || end == start) + end=ign.indexOf('\n', start); //2015.07.15. + if (end == -1 || end == start) + ign = ign.substring(start); + else + ign = ign.substring(start, end); + ign = ign.trim(); + if(HasIGFlair(ign)) + continue; + try { + Thread.sleep(10); + } catch(InterruptedException ex) { + Thread.currentThread().interrupt(); + } + String[] flairdata = DownloadString("http://karmadecay.com/thebutton-data.php?users=" + author).replace("\"", "").split(":"); + String flair; + if(flairdata.length > 1) //2015.07.15. + flair = flairdata[1]; + else + flair=""; + if (flair != "-1") + flair = flair + "s"; + else + flair = "non-presser"; + String flairclass; + if(flairdata.length>2) + flairclass = flairdata[2]; + else + flairclass="unknown"; + SetFlair(ign, flair, flairclass, author); + } + Thread.sleep(10000); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + } + + public static Exception LastException; //2015.08.09. + + public String DownloadString(String urlstr) throws MalformedURLException, IOException + { + URL url = new URL(urlstr); + URLConnection con = url.openConnection(); + con.setRequestProperty("User-Agent", "TheButtonAutoFlair"); + InputStream in = con.getInputStream(); + String encoding = con.getContentEncoding(); + encoding = encoding == null ? "UTF-8" : encoding; + String body = IOUtils.toString(in, encoding); + in.close(); + return body; + } + + public static Map TownColors=new HashMap(); //2015.07.20. + public Boolean HasIGFlair(String playername) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + return p.Flair!=null; //2015.08.08. + } + + public void SetFlair(String playername, String text, String flairclass, String username) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + String finalflair; + p.FlairDecided=true; + switch(flairclass) + { + case "press-1": + finalflair="§c("+text+")§r"; + break; + case "press-2": + finalflair="§6("+text+")§r"; + break; + case "press-3": + finalflair="§e("+text+")§r"; + break; + case "press-4": + finalflair="§a("+text+")§r"; + break; + case "press-5": + finalflair="§9("+text+")§r"; + break; + 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; + case "undecided": //2015.08.09. + p.FlairDecided=false; + finalflair=""; + break; + default: + finalflair=""; + break; + } + if(finalflair.length()==0) //<-- 2015.07.20. + return; + p.Flair=finalflair; //2015.08.08. + p.UserName=username; //2015.08.08. + System.out.println("Added new flair to "+playername+": "+finalflair); + for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08. + { + if(player.getName().equals(playername)) + { + //AppendPlayerDisplayFlair(player, username, finalflair); + AppendPlayerDisplayFlair(p, player); + break; + } + } + } + + public static String GetFlair(Player player) + { //2015.07.16. + String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08. + return flair==null ? "" : flair; + } + + //public static void AppendPlayerDisplayFlair(Player player, String username, String flair) + public static void AppendPlayerDisplayFlair(MaybeOfflinePlayer player, Player p) //<-- 2015.08.09. + { + + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).IgnoredFlair) + return; + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).AcceptedFlair) + { + AppendPlayerDisplayFlairFinal(p, player.Flair); //2015.07.20. + if(!player.FlairDecided) + p.sendMessage("§9Your flair type is unknown. Are you a non-presser or a can't press? (/u nonpresser or /u cantpress)§r"); //2015.08.09. + } + else + p.sendMessage("§9Are you Reddit user "+player.UserName+"?§r §6Type /u accept or /u ignore§r"); + } + + private static void AppendPlayerDisplayFlairFinal(Player player, String flair) + { //2015.07.20. + String color = GetColorForTown(GetPlayerTown(player)); //TO!DO: Multiple colors put on first capital letters + String[] colors = color.substring(1).split("§"); + String displayname=player.getName(); //2015.08.08. + ArrayList Positions=new ArrayList<>(); + for(int i=0; i=colors.length) + { + int x=0; + for(int i=0; i GetPlayers() + { + return Instance.getServer().getOnlinePlayers(); + } + + public static void LoadFiles(boolean reload) //<-- 2015.08.09. + { + if(reload) + { //2015.08.09. + System.out.println("Auto-flair plugin cleanup for reloading..."); + MaybeOfflinePlayer.AllPlayers.clear(); + TownColors.clear(); + } + System.out.println("Loading files for auto-flair plugin..."); //2015.08.09. + try { + File file=new File("flairsaccepted.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + //System.out.println("Name: " + name); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("flairsignored.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsignored.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("autoflairconfig.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + TownColors.put(s[0], s[1]); + } + br.close(); + } + file=new File("autoflairdecisions.txt"); //2015.08.09. + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + MaybeOfflinePlayer.AddPlayerIfNeeded(s[0]).Flair=s[1]; //2015.08.09. + } + br.close(); + } + //throw new IOException("Test"); //2015.08.09. + System.out.println("Auto-flair plugin loaded files!"); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + public static void SaveFiles() //<-- 2015.08.09. + { + try + { + FileWriter fw; + fw = new FileWriter("flairsaccepted.txt"); + fw.close(); + fw = new FileWriter("flairsignored.txt"); + fw.close(); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + try { + File file=new File("flairsaccepted.txt"); + BufferedWriter bw=new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.AcceptedFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + file=new File("flairsignored.txt"); + bw = new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.IgnoredFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + public static void SetPlayerFlair(Player player, String flair) + { //2015.08.09. + flair=flair.replace('&', '§'); + MaybeOfflinePlayer.AddPlayerIfNeeded(player.getName()).Flair=flair; + + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/60/808a5063df3e001517108d149b613203 b/.metadata/.plugins/org.eclipse.core.resources/.history/60/808a5063df3e001517108d149b613203 new file mode 100644 index 0000000..df11079 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/60/808a5063df3e001517108d149b613203 @@ -0,0 +1,252 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +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; + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. + //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) + if(p.Flair==null) + { + player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); + return true; + } + switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. + { + case "accept": + { + if(p.IgnoredFlair) + p.IgnoredFlair=false; //2015.08.08. + if(!p.AcceptedFlair) + { + String flair=p.Flair; //2015.08.08. + //PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + PluginMain.AppendPlayerDisplayFlair(p, player); + p.AcceptedFlair=true; //2015.08.08. + player.sendMessage("§6Your flair has been set:§r "+flair); + } + else + player.sendMessage("§cYou already have this user's flair.§r"); + break; + } + case "ignore": + { + if(p.AcceptedFlair) + p.AcceptedFlair=false; //2015.08.08. + if(!p.IgnoredFlair) + { + p.IgnoredFlair=true; + String flair=p.Flair; //2015.08.08. + PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. + player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); + } + else + player.sendMessage("§cYou already ignored this request.§r"); + break; + } + /*case "reload": //2015.07.20. + DoReload(player); + break;*/ + case "admin": //2015.08.09. + DoAdmin(player, args); + break; + case "nonpresser": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§7(non-pr.)§r"; + break; + case "cantpress": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§r(can't press)§r"; + break; + default: + return false; + } + return true; + } + /*if(args[0].toLowerCase()=="reload") + DoReload(null); //2015.07.20.*/ + else if(args.length>0 && args[0].toLowerCase().equals("admin")) //2015.08.09. + { + DoAdmin(null, args); //2015.08.09. + return true; //2015.08.09. + } + return false; + } + private static void DoReload(Player player) + { //2015.07.20. + //if(player==null || player.isOp() || player.getName()=="NorbiPeti") + //{ + try + { + File file=new File("autoflairconfig.txt"); + if(file.exists()) + { + PluginMain.LoadFiles(true); //2015.08.09. + for(Player p : PluginMain.GetPlayers()) + { + MaybeOfflinePlayer mp = MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName()); + if(mp.Flair!=null) + { + String flair=mp.Flair; + PluginMain.RemovePlayerDisplayFlairFinal(p, flair); + //PluginMain.AppendPlayerDisplayFlairFinal(p, flair); + PluginMain.AppendPlayerDisplayFlair(mp, p); //2015.08.09. + } + String msg="§6Note: The auto-flair plugin has been reloaded. You might need to wait 10s to have your flair.§r"; //2015.08.09. + p.sendMessage(msg); //2015.08.09. + } + //String msg="§6Reloaded config file.§r"; + //SendMessage(player, msg); //2015.08.09. + } + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + if(player!=null) + player.sendMessage("§cAn error occured. See console for details.§r"); + PluginMain.LastException=e; //2015.08.09. + } + //} + //else + //player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static Player ReloadPlayer; //2015.08.09. + private static void DoAdmin(Player player, String[] args) + { //2015.08.09. + if(player==null || player.isOp() || player.getName()=="NorbiPeti") + { + //System.out.println("Args length: " + args.length); + if(args.length==1) + { + String message="§cUsage: /u admin reload|playerinfo§r"; + SendMessage(player, message); + return; + } + //args[0] is "admin" + switch(args[1].toLowerCase()) + { + case "reload": + ReloadPlayer=player; //2015.08.09. + SendMessage(player, "§6Make sure to save the current settings before you modify and reload them! Type /u admin confirm when done.§r"); + break; + case "playerinfo": + DoPlayerInfo(player, args); + break; + case "getlasterror": + DoGetLastError(player, args); + case "confirm": + if(ReloadPlayer==player) + DoReload(player); //2015.08.09. + else + SendMessage(player, "§cYou need to do /u admin reload first.§r"); + break; + case "save": + PluginMain.SaveFiles(); //2015.08.09. + SendMessage(player, "§6Saved files. Now you can edit them and reload if you want.§r"); + break; + default: + String message="§cUsage: /u admin reload|playerinfo|getlasterror§r"; + SendMessage(player, message); + return; + } + } + else + player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static void DoPlayerInfo(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "playerinfo" + if(args.length==2) + { + String message="§cUsage: /u admin playerinfo §r"; + SendMessage(player, message); + return; + } + if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2])) + { + String message="§cPlayer not found: "+args[2]+"§r"; + SendMessage(player, message); + return; + } + MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]); + SendMessage(player, "Player name: "+p.PlayerName); + SendMessage(player, "User flair: "+p.Flair); + SendMessage(player, "Username: "+p.UserName); + SendMessage(player, "Flair accepted: "+p.AcceptedFlair); + SendMessage(player, "Flair ignored: "+p.IgnoredFlair); + } + private static void SendMessage(Player player, String message) + { //2015.08.09. + if(player==null) + System.out.println(message); + else + player.sendMessage(message); + } + private static void DoGetLastError(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "getlasterror" + if(PluginMain.LastException!=null) + { + SendMessage(player, "Last error:"); + SendMessage(player, PluginMain.LastException.toString()); + PluginMain.LastException=null; + } + else + SendMessage(player, "There were no exceptions."); + } + private static void SetPlayerFlair(Player player, String flair) + { //2015.08.09. + flair=flair.replace('&', '§'); + MaybeOfflinePlayer.AddPlayerIfNeeded(player.getName()).Flair=flair; + if(!PluginMain.RemoveLineFromFile("customflairs.txt")) + { + SendMessage(player, "§cError removing previous custom flair!§r"); + return; + } + File file=new File("customflairs.txt"); + try { + BufferedWriter bw; + bw = new BufferedWriter(new FileWriter(file, true)); + bw.write(player.getName()+"\n"); + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + PluginMain.LastException=e; //2015.08.09. + } + SendMessage(player, "§6The flair has been set. Player: "+player.getName()+" Flair: "+flair); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/61/0023220fe03e001517108d149b613203 b/.metadata/.plugins/org.eclipse.core.resources/.history/61/0023220fe03e001517108d149b613203 new file mode 100644 index 0000000..0ccc23b --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/61/0023220fe03e001517108d149b613203 @@ -0,0 +1,260 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +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; + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. + //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) + if(p.Flair==null) + { + player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); + return true; + } + switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. + { + case "accept": + { + if(p.IgnoredFlair) + p.IgnoredFlair=false; //2015.08.08. + if(!p.AcceptedFlair) + { + String flair=p.Flair; //2015.08.08. + //PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + PluginMain.AppendPlayerDisplayFlair(p, player); + p.AcceptedFlair=true; //2015.08.08. + player.sendMessage("§6Your flair has been set:§r "+flair); + } + else + player.sendMessage("§cYou already have this user's flair.§r"); + break; + } + case "ignore": + { + if(p.AcceptedFlair) + p.AcceptedFlair=false; //2015.08.08. + if(!p.IgnoredFlair) + { + p.IgnoredFlair=true; + String flair=p.Flair; //2015.08.08. + PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. + player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); + } + else + player.sendMessage("§cYou already ignored this request.§r"); + break; + } + /*case "reload": //2015.07.20. + DoReload(player); + break;*/ + case "admin": //2015.08.09. + DoAdmin(player, args); + break; + case "nonpresser": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§7(non-pr.)§r"; + break; + case "cantpress": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§r(can't press)§r"; + break; + default: + return false; + } + return true; + } + /*if(args[0].toLowerCase()=="reload") + DoReload(null); //2015.07.20.*/ + else if(args.length>0 && args[0].toLowerCase().equals("admin")) //2015.08.09. + { + DoAdmin(null, args); //2015.08.09. + return true; //2015.08.09. + } + return false; + } + private static void DoReload(Player player) + { //2015.07.20. + //if(player==null || player.isOp() || player.getName()=="NorbiPeti") + //{ + try + { + File file=new File("autoflairconfig.txt"); + if(file.exists()) + { + PluginMain.LoadFiles(true); //2015.08.09. + for(Player p : PluginMain.GetPlayers()) + { + MaybeOfflinePlayer mp = MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName()); + if(mp.Flair!=null) + { + String flair=mp.Flair; + PluginMain.RemovePlayerDisplayFlairFinal(p, flair); + //PluginMain.AppendPlayerDisplayFlairFinal(p, flair); + PluginMain.AppendPlayerDisplayFlair(mp, p); //2015.08.09. + } + String msg="§6Note: The auto-flair plugin has been reloaded. You might need to wait 10s to have your flair.§r"; //2015.08.09. + p.sendMessage(msg); //2015.08.09. + } + //String msg="§6Reloaded config file.§r"; + //SendMessage(player, msg); //2015.08.09. + } + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + if(player!=null) + player.sendMessage("§cAn error occured. See console for details.§r"); + PluginMain.LastException=e; //2015.08.09. + } + //} + //else + //player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static Player ReloadPlayer; //2015.08.09. + private static void DoAdmin(Player player, String[] args) + { //2015.08.09. + if(player==null || player.isOp() || player.getName()=="NorbiPeti") + { + //System.out.println("Args length: " + args.length); + if(args.length==1) + { + String message="§cUsage: /u admin reload|playerinfo§r"; + SendMessage(player, message); + return; + } + //args[0] is "admin" + switch(args[1].toLowerCase()) + { + case "reload": + ReloadPlayer=player; //2015.08.09. + SendMessage(player, "§6Make sure to save the current settings before you modify and reload them! Type /u admin confirm when done.§r"); + break; + case "playerinfo": + DoPlayerInfo(player, args); + break; + case "getlasterror": + DoGetLastError(player, args); + case "confirm": + if(ReloadPlayer==player) + DoReload(player); //2015.08.09. + else + SendMessage(player, "§cYou need to do /u admin reload first.§r"); + break; + case "save": + PluginMain.SaveFiles(); //2015.08.09. + SendMessage(player, "§6Saved files. Now you can edit them and reload if you want.§r"); + break; + case "setflair": + + break; + default: + String message="§cUsage: /u admin reload|playerinfo|getlasterror|save§r"; + SendMessage(player, message); + return; + } + } + else + player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static void DoPlayerInfo(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "playerinfo" + if(args.length==2) + { + String message="§cUsage: /u admin playerinfo §r"; + SendMessage(player, message); + return; + } + if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2])) + { + String message="§cPlayer not found: "+args[2]+"§r"; + SendMessage(player, message); + return; + } + MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]); + SendMessage(player, "Player name: "+p.PlayerName); + SendMessage(player, "User flair: "+p.Flair); + SendMessage(player, "Username: "+p.UserName); + SendMessage(player, "Flair accepted: "+p.AcceptedFlair); + SendMessage(player, "Flair ignored: "+p.IgnoredFlair); + } + private static void SendMessage(Player player, String message) + { //2015.08.09. + if(player==null) + System.out.println(message); + else + player.sendMessage(message); + } + private static void DoGetLastError(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "getlasterror" + if(PluginMain.LastException!=null) + { + SendMessage(player, "Last error:"); + SendMessage(player, PluginMain.LastException.toString()); + PluginMain.LastException=null; + } + else + SendMessage(player, "There were no exceptions."); + } + private static void SetPlayerFlair(Player player, Player targetplayer, String flair) + { //2015.08.09. + flair=flair.replace('&', '§'); + MaybeOfflinePlayer.AddPlayerIfNeeded(player.getName()).Flair=flair; + if(!PluginMain.RemoveLineFromFile("customflairs.txt", targetplayer.getName())) + { + SendMessage(player, "§cError removing previous custom flair!§r"); + return; + } + File file=new File("customflairs.txt"); + try { + BufferedWriter bw; + bw = new BufferedWriter(new FileWriter(file, true)); + bw.write(targetplayer.getName()+"\n"); + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + PluginMain.LastException=e; //2015.08.09. + } + SendMessage(player, "§6The flair has been set. Player: "+targetplayer.getName()+" Flair: "+flair+"§r"); + } + private static void DoSetFlair(Player player, String args) + { + //args[0] is "admin" - args[1] is "setflair" + + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/61/20e39728df3e001517108d149b613203 b/.metadata/.plugins/org.eclipse.core.resources/.history/61/20e39728df3e001517108d149b613203 new file mode 100644 index 0000000..6b55eb2 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/61/20e39728df3e001517108d149b613203 @@ -0,0 +1,251 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +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; + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. + //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) + if(p.Flair==null) + { + player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); + return true; + } + switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. + { + case "accept": + { + if(p.IgnoredFlair) + p.IgnoredFlair=false; //2015.08.08. + if(!p.AcceptedFlair) + { + String flair=p.Flair; //2015.08.08. + //PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + PluginMain.AppendPlayerDisplayFlair(p, player); + p.AcceptedFlair=true; //2015.08.08. + player.sendMessage("§6Your flair has been set:§r "+flair); + } + else + player.sendMessage("§cYou already have this user's flair.§r"); + break; + } + case "ignore": + { + if(p.AcceptedFlair) + p.AcceptedFlair=false; //2015.08.08. + if(!p.IgnoredFlair) + { + p.IgnoredFlair=true; + String flair=p.Flair; //2015.08.08. + PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. + player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); + } + else + player.sendMessage("§cYou already ignored this request.§r"); + break; + } + /*case "reload": //2015.07.20. + DoReload(player); + break;*/ + case "admin": //2015.08.09. + DoAdmin(player, args); + break; + case "nonpresser": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§7(non-pr.)§r"; + break; + case "cantpress": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§r(can't press)§r"; + break; + default: + return false; + } + return true; + } + /*if(args[0].toLowerCase()=="reload") + DoReload(null); //2015.07.20.*/ + else if(args.length>0 && args[0].toLowerCase().equals("admin")) //2015.08.09. + { + DoAdmin(null, args); //2015.08.09. + return true; //2015.08.09. + } + return false; + } + private static void DoReload(Player player) + { //2015.07.20. + //if(player==null || player.isOp() || player.getName()=="NorbiPeti") + //{ + try + { + File file=new File("autoflairconfig.txt"); + if(file.exists()) + { + PluginMain.LoadFiles(true); //2015.08.09. + for(Player p : PluginMain.GetPlayers()) + { + MaybeOfflinePlayer mp = MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName()); + if(mp.Flair!=null) + { + String flair=mp.Flair; + PluginMain.RemovePlayerDisplayFlairFinal(p, flair); + //PluginMain.AppendPlayerDisplayFlairFinal(p, flair); + PluginMain.AppendPlayerDisplayFlair(mp, p); //2015.08.09. + } + String msg="§6Note: The auto-flair plugin has been reloaded. You might need to wait 10s to have your flair.§r"; //2015.08.09. + p.sendMessage(msg); //2015.08.09. + } + //String msg="§6Reloaded config file.§r"; + //SendMessage(player, msg); //2015.08.09. + } + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + if(player!=null) + player.sendMessage("§cAn error occured. See console for details.§r"); + PluginMain.LastException=e; //2015.08.09. + } + //} + //else + //player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static Player ReloadPlayer; //2015.08.09. + private static void DoAdmin(Player player, String[] args) + { //2015.08.09. + if(player==null || player.isOp() || player.getName()=="NorbiPeti") + { + //System.out.println("Args length: " + args.length); + if(args.length==1) + { + String message="§cUsage: /u admin reload|playerinfo§r"; + SendMessage(player, message); + return; + } + //args[0] is "admin" + switch(args[1].toLowerCase()) + { + case "reload": + ReloadPlayer=player; //2015.08.09. + SendMessage(player, "§6Make sure to save the current settings before you modify and reload them! Type /u admin confirm when done.§r"); + break; + case "playerinfo": + DoPlayerInfo(player, args); + break; + case "getlasterror": + DoGetLastError(player, args); + case "confirm": + if(ReloadPlayer==player) + DoReload(player); //2015.08.09. + else + SendMessage(player, "§cYou need to do /u admin reload first.§r"); + break; + case "save": + PluginMain.SaveFiles(); //2015.08.09. + SendMessage(player, "§6Saved files. Now you can edit them and reload if you want.§r"); + break; + default: + String message="§cUsage: /u admin reload|playerinfo|getlasterror§r"; + SendMessage(player, message); + return; + } + } + else + player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static void DoPlayerInfo(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "playerinfo" + if(args.length==2) + { + String message="§cUsage: /u admin playerinfo §r"; + SendMessage(player, message); + return; + } + if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2])) + { + String message="§cPlayer not found: "+args[2]+"§r"; + SendMessage(player, message); + return; + } + MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]); + SendMessage(player, "Player name: "+p.PlayerName); + SendMessage(player, "User flair: "+p.Flair); + SendMessage(player, "Username: "+p.UserName); + SendMessage(player, "Flair accepted: "+p.AcceptedFlair); + SendMessage(player, "Flair ignored: "+p.IgnoredFlair); + } + private static void SendMessage(Player player, String message) + { //2015.08.09. + if(player==null) + System.out.println(message); + else + player.sendMessage(message); + } + private static void DoGetLastError(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "getlasterror" + if(PluginMain.LastException!=null) + { + SendMessage(player, "Last error:"); + SendMessage(player, PluginMain.LastException.toString()); + PluginMain.LastException=null; + } + else + SendMessage(player, "There were no exceptions."); + } + private static void SetPlayerFlair(Player player, String flair) + { //2015.08.09. + flair=flair.replace('&', '§'); + MaybeOfflinePlayer.AddPlayerIfNeeded(player.getName()).Flair=flair; + if(!PluginMain.RemoveLineFromFile("customflairs.txt")) + { + SendMessage(player, "Error removing previous custom flair!"); + return; + } + File file=new File("customflairs.txt"); + try { + BufferedWriter bw; + bw = new BufferedWriter(new FileWriter(file, true)); + bw.write(player.getName()+"\n"); + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + PluginMain.LastException=e; //2015.08.09. + } + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/61/b0779e98d03e001518fa86d7ae2a1cf8 b/.metadata/.plugins/org.eclipse.core.resources/.history/61/b0779e98d03e001518fa86d7ae2a1cf8 new file mode 100644 index 0000000..f7dee03 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/61/b0779e98d03e001518fa86d7ae2a1cf8 @@ -0,0 +1,205 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; + +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class Commands implements CommandExecutor { + // This method is called, when somebody uses our command + @Override + public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { + if (sender instanceof Player) { + Player player = (Player) sender; + if(args.length<1) + return false; + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. + //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) + if(p.Flair==null) + { + player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); + return true; + } + switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. + { + case "accept": + { + if(p.IgnoredFlair) + p.IgnoredFlair=false; //2015.08.08. + if(!p.AcceptedFlair) + { + String flair=p.Flair; //2015.08.08. + //PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + PluginMain.AppendPlayerDisplayFlair(p, player); + p.AcceptedFlair=true; //2015.08.08. + player.sendMessage("§6Your flair has been set:§r "+flair); + } + else + player.sendMessage("§cYou already have this user's flair.§r"); + break; + } + case "ignore": + { + if(p.AcceptedFlair) + p.AcceptedFlair=false; //2015.08.08. + if(!p.IgnoredFlair) + { + p.IgnoredFlair=true; + String flair=p.Flair; //2015.08.08. + PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. + player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); + } + else + player.sendMessage("§cYou already ignored this request.§r"); + break; + } + /*case "reload": //2015.07.20. + DoReload(player); + break;*/ + case "admin": //2015.08.09. + DoAdmin(player, args); + break; + case "nonpresser": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + break; + case "cantpress": //2015.08.09. + break; + default: + return false; + } + return true; + } + /*if(args[0].toLowerCase()=="reload") + DoReload(null); //2015.07.20.*/ + else if(args.length>0 && args[0].toLowerCase().equals("admin")) //2015.08.09. + { + DoAdmin(null, args); //2015.08.09. + return true; //2015.08.09. + } + return false; + } + private static void DoReload(Player player) + { //2015.07.20. + //if(player==null || player.isOp() || player.getName()=="NorbiPeti") + //{ + try + { + File file=new File("autoflairconfig.txt"); + if(file.exists()) + { + PluginMain.TownColors.clear(); + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + PluginMain.TownColors.put(s[0], s[1]); + } + br.close(); + for(Player p : PluginMain.GetPlayers()) + { + MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName()); + if(mp.Flair!=null) + { + String flair=mp.Flair; + PluginMain.RemovePlayerDisplayFlairFinal(p, flair); + //PluginMain.AppendPlayerDisplayFlairFinal(p, flair); + PluginMain.AppendPlayerDisplayFlair(mp, p); //2015.08.09. + } + } + String msg="§6Reloaded config file.§r"; + SendMessage(player, msg); //2015.08.09. + } + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + if(player!=null) + player.sendMessage("§cAn error occured. See console for details.§r"); + PluginMain.LastException=e; //2015.08.09. + } + //} + //else + //player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static void DoAdmin(Player player, String[] args) + { //2015.08.09. + if(player==null || player.isOp() || player.getName()=="NorbiPeti") + { + //System.out.println("Args length: " + args.length); + if(args.length==1) + { + String message="§cUsage: /u admin reload|playerinfo§r"; + SendMessage(player, message); + return; + } + //args[0] is "admin" + switch(args[1].toLowerCase()) + { + case "reload": + DoReload(player); + break; + case "playerinfo": + DoPlayerInfo(player, args); + break; + case "getlasterror": + DoGetLastError(player, args); + default: + String message="§cUsage: /u admin reload|playerinfo§r"; + SendMessage(player, message); + return; + } + } + else + player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static void DoPlayerInfo(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "playerinfo" + if(args.length==2) + { + String message="§cUsage: /u admin playerinfo §r"; + SendMessage(player, message); + return; + } + if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2])) + { + String message="§cPlayer not found: "+args[2]+"§r"; + SendMessage(player, message); + return; + } + MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]); + SendMessage(player, "Player name: "+p.PlayerName); + SendMessage(player, "User flair: "+p.Flair); + SendMessage(player, "Username: "+p.UserName); + SendMessage(player, "Flair accepted: "+p.AcceptedFlair); + SendMessage(player, "Flair ignored: "+p.IgnoredFlair); + } + private static void SendMessage(Player player, String message) + { //2015.08.09. + if(player==null) + System.out.println(message); + else + player.sendMessage(message); + } + private static void DoGetLastError(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "getlasterror" + if(PluginMain.LastException!=null) + { + SendMessage(player, "Last error:"); + SendMessage(player, PluginMain.LastException.toString()); + PluginMain.LastException=null; + } + else + SendMessage(player, "There were no exceptions."); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/62/00fd4080df3e001517108d149b613203 b/.metadata/.plugins/org.eclipse.core.resources/.history/62/00fd4080df3e001517108d149b613203 new file mode 100644 index 0000000..a2babdc --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/62/00fd4080df3e001517108d149b613203 @@ -0,0 +1,252 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +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; + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. + //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) + if(p.Flair==null) + { + player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); + return true; + } + switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. + { + case "accept": + { + if(p.IgnoredFlair) + p.IgnoredFlair=false; //2015.08.08. + if(!p.AcceptedFlair) + { + String flair=p.Flair; //2015.08.08. + //PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + PluginMain.AppendPlayerDisplayFlair(p, player); + p.AcceptedFlair=true; //2015.08.08. + player.sendMessage("§6Your flair has been set:§r "+flair); + } + else + player.sendMessage("§cYou already have this user's flair.§r"); + break; + } + case "ignore": + { + if(p.AcceptedFlair) + p.AcceptedFlair=false; //2015.08.08. + if(!p.IgnoredFlair) + { + p.IgnoredFlair=true; + String flair=p.Flair; //2015.08.08. + PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. + player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); + } + else + player.sendMessage("§cYou already ignored this request.§r"); + break; + } + /*case "reload": //2015.07.20. + DoReload(player); + break;*/ + case "admin": //2015.08.09. + DoAdmin(player, args); + break; + case "nonpresser": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§7(non-pr.)§r"; + break; + case "cantpress": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§r(can't press)§r"; + break; + default: + return false; + } + return true; + } + /*if(args[0].toLowerCase()=="reload") + DoReload(null); //2015.07.20.*/ + else if(args.length>0 && args[0].toLowerCase().equals("admin")) //2015.08.09. + { + DoAdmin(null, args); //2015.08.09. + return true; //2015.08.09. + } + return false; + } + private static void DoReload(Player player) + { //2015.07.20. + //if(player==null || player.isOp() || player.getName()=="NorbiPeti") + //{ + try + { + File file=new File("autoflairconfig.txt"); + if(file.exists()) + { + PluginMain.LoadFiles(true); //2015.08.09. + for(Player p : PluginMain.GetPlayers()) + { + MaybeOfflinePlayer mp = MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName()); + if(mp.Flair!=null) + { + String flair=mp.Flair; + PluginMain.RemovePlayerDisplayFlairFinal(p, flair); + //PluginMain.AppendPlayerDisplayFlairFinal(p, flair); + PluginMain.AppendPlayerDisplayFlair(mp, p); //2015.08.09. + } + String msg="§6Note: The auto-flair plugin has been reloaded. You might need to wait 10s to have your flair.§r"; //2015.08.09. + p.sendMessage(msg); //2015.08.09. + } + //String msg="§6Reloaded config file.§r"; + //SendMessage(player, msg); //2015.08.09. + } + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + if(player!=null) + player.sendMessage("§cAn error occured. See console for details.§r"); + PluginMain.LastException=e; //2015.08.09. + } + //} + //else + //player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static Player ReloadPlayer; //2015.08.09. + private static void DoAdmin(Player player, String[] args) + { //2015.08.09. + if(player==null || player.isOp() || player.getName()=="NorbiPeti") + { + //System.out.println("Args length: " + args.length); + if(args.length==1) + { + String message="§cUsage: /u admin reload|playerinfo§r"; + SendMessage(player, message); + return; + } + //args[0] is "admin" + switch(args[1].toLowerCase()) + { + case "reload": + ReloadPlayer=player; //2015.08.09. + SendMessage(player, "§6Make sure to save the current settings before you modify and reload them! Type /u admin confirm when done.§r"); + break; + case "playerinfo": + DoPlayerInfo(player, args); + break; + case "getlasterror": + DoGetLastError(player, args); + case "confirm": + if(ReloadPlayer==player) + DoReload(player); //2015.08.09. + else + SendMessage(player, "§cYou need to do /u admin reload first.§r"); + break; + case "save": + PluginMain.SaveFiles(); //2015.08.09. + SendMessage(player, "§6Saved files. Now you can edit them and reload if you want.§r"); + break; + default: + String message="§cUsage: /u admin reload|playerinfo|getlasterror§r"; + SendMessage(player, message); + return; + } + } + else + player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static void DoPlayerInfo(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "playerinfo" + if(args.length==2) + { + String message="§cUsage: /u admin playerinfo §r"; + SendMessage(player, message); + return; + } + if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2])) + { + String message="§cPlayer not found: "+args[2]+"§r"; + SendMessage(player, message); + return; + } + MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]); + SendMessage(player, "Player name: "+p.PlayerName); + SendMessage(player, "User flair: "+p.Flair); + SendMessage(player, "Username: "+p.UserName); + SendMessage(player, "Flair accepted: "+p.AcceptedFlair); + SendMessage(player, "Flair ignored: "+p.IgnoredFlair); + } + private static void SendMessage(Player player, String message) + { //2015.08.09. + if(player==null) + System.out.println(message); + else + player.sendMessage(message); + } + private static void DoGetLastError(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "getlasterror" + if(PluginMain.LastException!=null) + { + SendMessage(player, "Last error:"); + SendMessage(player, PluginMain.LastException.toString()); + PluginMain.LastException=null; + } + else + SendMessage(player, "There were no exceptions."); + } + private static void SetPlayerFlair(Player player, Player targetplayer, String flair) + { //2015.08.09. + flair=flair.replace('&', '§'); + MaybeOfflinePlayer.AddPlayerIfNeeded(player.getName()).Flair=flair; + if(!PluginMain.RemoveLineFromFile("customflairs.txt")) + { + SendMessage(player, "§cError removing previous custom flair!§r"); + return; + } + File file=new File("customflairs.txt"); + try { + BufferedWriter bw; + bw = new BufferedWriter(new FileWriter(file, true)); + bw.write(player.getName()+"\n"); + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + PluginMain.LastException=e; //2015.08.09. + } + SendMessage(player, "§6The flair has been set. Player: "+targetplayer.getName()+" Flair: "+flair+"§r"); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/62/502ee671043e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/62/502ee671043e00151c31fb33fff4337f deleted file mode 100644 index 87c0c13..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/62/502ee671043e00151c31fb33fff4337f +++ /dev/null @@ -1,126 +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; - 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/8065dabd843e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/62/8065dabd843e00151ce8ff6d4f74dabd deleted file mode 100644 index 1b10b37..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/62/8065dabd843e00151ce8ff6d4f74dabd +++ /dev/null @@ -1,119 +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; - MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. - //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - if(p.Flair==null) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - { - if(p.IgnoredFlair) - p.IgnoredFlair=false; //2015.08.08. - if(!p.AcceptedFlair) - { - String flair=p.Flair; //2015.08.08. - PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. - p.AcceptedFlair=true; //2015.08.08. - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("§cYou already have this user's flair.§r"); - break; - } - case "ignore": - { - if(p.AcceptedFlair) - p.AcceptedFlair=false; //2015.08.08. - if(!p.IgnoredFlair) - { - p.IgnoredFlair=true; - String flair=p.Flair; //2015.08.08. - PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. - player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); - } - else - player.sendMessage("§cYou already ignored this request.§r"); - break; - } - case "reload": //2015.07.20. - DoReload(player); - break; - case "showerrors": - break; - default: - return false; - } - return true; - } - - if(args[0]=="reload") - DoReload(null); //2015.07.20. - return false; - } - private static void DoReload(Player player) - { //2015.07.20. - if(player==null || player.isOp() || player.getName()=="NorbiPeti") - { - try - { - File file=new File("autoflairconfig.txt"); - if(file.exists()) - { - PluginMain.TownColors.clear(); - BufferedReader br=new BufferedReader(new FileReader(file)); - String line; - while((line=br.readLine())!=null) - { - String[] s=line.split(" "); - PluginMain.TownColors.put(s[0], s[1]); - } - br.close(); - for(Player p : PluginMain.GetPlayers()) - { - MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName()); - if(mp.Flair!=null) - { - String flair=mp.Flair; - PluginMain.RemovePlayerDisplayFlairFinal(p, flair); - PluginMain.AppendPlayerDisplayFlairFinal(p, flair); - } - } - String msg="§6Reloaded config file.§r"; - if(player!=null) - player.sendMessage(msg); - else - System.out.println(msg); - } - } - catch(Exception e) - { - System.out.println("Error!\n"+e); - if(player!=null) - player.sendMessage("§cAn error occured. See console for details.§r"); - } - } - else - player.sendMessage("§cYou need to be OP to use this command.§r"); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/97/f0d392d5303e00151cbdba8b5f0a340e b/.metadata/.plugins/org.eclipse.core.resources/.history/63/206c2677ce3e001518fa86d7ae2a1cf8 similarity index 69% rename from .metadata/.plugins/org.eclipse.core.resources/.history/97/f0d392d5303e00151cbdba8b5f0a340e rename to .metadata/.plugins/org.eclipse.core.resources/.history/63/206c2677ce3e001518fa86d7ae2a1cf8 index e143040..c13bb09 100644 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/97/f0d392d5303e00151cbdba8b5f0a340e +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/63/206c2677ce3e001518fa86d7ae2a1cf8 @@ -21,8 +21,9 @@ import org.bukkit.plugin.java.JavaPlugin; import org.json.JSONArray; import org.json.JSONObject; +import tk.sznp.thebuttonautoflair.MaybeOfflinePlayer.FlairClassType; + 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 @@ -48,7 +49,7 @@ public class PluginMain extends JavaPlugin while ((line = br.readLine()) != null) { String name=line.replace("\n", ""); - System.out.println("Name: " + name); + //System.out.println("Name: " + name); MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08. } br.close(); @@ -77,8 +78,10 @@ public class PluginMain extends JavaPlugin } br.close(); } + //throw new IOException("Test"); //2015.08.09. } catch (IOException e) { System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. } Runnable r=new Runnable(){public void run(){ThreadMethod();}}; Thread t=new Thread(r); @@ -100,44 +103,36 @@ public class PluginMain extends JavaPlugin catch(Exception e) { System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. } - for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. - { - if(!player.AcceptedFlair) - continue; //2015.08.08. - File file=new File("flairsaccepted.txt"); - try { - BufferedWriter bw=new BufferedWriter(new FileWriter(file, true)); + try { + File file=new File("flairsaccepted.txt"); + BufferedWriter bw=new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.AcceptedFlair) + continue; //2015.08.08. bw.write(player.PlayerName+"\n"); - bw.close(); - } catch (IOException e) { - System.out.println("Error!\n"+e); - } - } - for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. - { - if(!player.IgnoredFlair) - continue; //2015.08.08. - File file=new File("flairsignored.txt"); - try { - BufferedWriter bw = new BufferedWriter(new FileWriter(file, true)); + } + bw.close(); + file=new File("flairsignored.txt"); + bw = new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.IgnoredFlair) + continue; //2015.08.08. bw.write(player.PlayerName+"\n"); - bw.close(); - } catch (IOException e) { - System.out.println("Error!\n"+e); - } - } + } + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } stop=true; } public void ThreadMethod() //<-- 2015.07.16. { - /*System.out.println("Sleeping for 5 seconds..."); //2015.07.20. - try { - Thread.sleep(5000); - } catch (InterruptedException e1) { - e1.printStackTrace(); - } //2015.07.20.*/ while(!stop) { try @@ -160,7 +155,6 @@ public class PluginMain extends JavaPlugin ign = ign.trim(); if(HasIGFlair(ign)) continue; - //System.out.println("Author: "+author); try { Thread.sleep(10); } catch(InterruptedException ex) { @@ -177,7 +171,6 @@ public class PluginMain extends JavaPlugin else flair = "non-presser"; String flairclass; - //System.out.println("flairdata.length:"+flairdata.length); if(flairdata.length>2) flairclass = flairdata[2]; else @@ -189,10 +182,13 @@ public class PluginMain extends JavaPlugin catch(Exception e) { System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. } } } + public static Exception LastException; //2015.08.09. + public String DownloadString(String urlstr) throws MalformedURLException, IOException { URL url = new URL(urlstr); @@ -206,37 +202,18 @@ public class PluginMain extends JavaPlugin return body; } - //It has to store offline player flairs too, therefore it can't use Player object - /*public static Map PlayerFlairs=new HashMap(); - public static Map PlayerUserNames=new HashMap(); - //public Map PlayerFlairs=new HashMap(); - public static ArrayList Players=new ArrayList(); - public static ArrayList AcceptedPlayers=new ArrayList(); //2015.07.16. - public static ArrayList IgnoredPlayers=new ArrayList(); //2015.07.16. - //public static Map PlayerTowns=new HashMap(); //2015.07.20.*/ public static Map TownColors=new HashMap(); //2015.07.20. public Boolean HasIGFlair(String playername) { - /*Player player=null; - for(Player p : Players) - { - if(p.getName()==playername) - { - player=p; - break; - } - } - if(player==null) - return false;*/ - //return PlayerFlairs.containsKey(playername); - //return MaybeOfflinePlayer.AllPlayers.containsKey(playername); MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. return p.Flair!=null; //2015.08.08. } public void SetFlair(String playername, String text, String flairclass, String username) { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. String finalflair; + p.FlairDecided=true; switch(flairclass) { case "press-1": @@ -266,38 +243,24 @@ public class PluginMain extends JavaPlugin case "cant-press": //2015.08.08. finalflair="§r(can't press)§r"; break; + case "undecided": //2015.08.09. + p.FlairType=FlairClassType.Undecided; + finalflair=""; + 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; } } @@ -305,19 +268,15 @@ public class PluginMain extends JavaPlugin public static String GetFlair(Player player) { //2015.07.16. - //String flair=PlayerFlairs.get(player.getName()); String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08. return flair==null ? "" : flair; } public static void AppendPlayerDisplayFlair(Player player, String username, String flair) { - //if(IgnoredPlayers.contains(player.getName())) if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).IgnoredFlair) return; - //if(AcceptedPlayers.contains(player.getName())) if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).AcceptedFlair) - //player.setDisplayName(player.getDisplayName()+flair); AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. else player.sendMessage("§9Are you Reddit user "+username+"?§r §6Type /u accept or /u ignore§r"); @@ -325,23 +284,18 @@ public class PluginMain extends JavaPlugin public static void AppendPlayerDisplayFlairFinal(Player player, String flair) { //2015.07.20. - //System.out.println("A"); String color = GetColorForTown(GetPlayerTown(player)); //TO!DO: Multiple colors put on first capital letters String[] colors = color.substring(1).split("§"); - //String displayname=player.getDisplayName(); String displayname=player.getName(); //2015.08.08. ArrayList Positions=new ArrayList<>(); - //System.out.println("B"); for(int i=0; i=colors.length) { - //System.out.println("D"); int x=0; for(int i=0; i towns = TownyUniverse.getDataSource().getTowns(); try { Town town = WorldCoord.parseWorldCoord(player).getTownBlock().getTown(); //TODO return town.getName(); @@ -406,10 +348,6 @@ public class PluginMain extends JavaPlugin public static void RemovePlayerDisplayFlairFinal(Player player, String flair) { //2015.07.20. - //String color = GetColorForTown(GetPlayerTown(player)); - //String dname=player.getDisplayName(); - //player.setDisplayName(dname.substring(dname.indexOf(color)+3, dname.indexOf(flair))); - //MaybeOfflinePlayer.AllPlayers.get(player.getName()).DisplayName=null; //2015.08.08. MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair=null; //2015.08.08. } diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/64/202fdd3acd3e001518fa86d7ae2a1cf8 b/.metadata/.plugins/org.eclipse.core.resources/.history/64/202fdd3acd3e001518fa86d7ae2a1cf8 new file mode 100644 index 0000000..d2a8475 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/64/202fdd3acd3e001518fa86d7ae2a1cf8 @@ -0,0 +1,31 @@ +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 + 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); + } + public enum FlairClassType + { + NonPresser, + CantPress, + Undecided + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/64/20a74791d03e001518fa86d7ae2a1cf8 b/.metadata/.plugins/org.eclipse.core.resources/.history/64/20a74791d03e001518fa86d7ae2a1cf8 new file mode 100644 index 0000000..5a05c55 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/64/20a74791d03e001518fa86d7ae2a1cf8 @@ -0,0 +1,205 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; + +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class Commands implements CommandExecutor { + // This method is called, when somebody uses our command + @Override + public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { + if (sender instanceof Player) { + Player player = (Player) sender; + if(args.length<1) + return false; + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. + //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) + if(p.Flair==null) + { + player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); + return true; + } + switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. + { + case "accept": + { + if(p.IgnoredFlair) + p.IgnoredFlair=false; //2015.08.08. + if(!p.AcceptedFlair) + { + String flair=p.Flair; //2015.08.08. + //PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + PluginMain.AppendPlayerDisplayFlair(p, player); + p.AcceptedFlair=true; //2015.08.08. + player.sendMessage("§6Your flair has been set:§r "+flair); + } + else + player.sendMessage("§cYou already have this user's flair.§r"); + break; + } + case "ignore": + { + if(p.AcceptedFlair) + p.AcceptedFlair=false; //2015.08.08. + if(!p.IgnoredFlair) + { + p.IgnoredFlair=true; + String flair=p.Flair; //2015.08.08. + PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. + player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); + } + else + player.sendMessage("§cYou already ignored this request.§r"); + break; + } + /*case "reload": //2015.07.20. + DoReload(player); + break;*/ + case "admin": //2015.08.09. + DoAdmin(player, args); + break; + case "nonpresser": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + return; + } + break; + case "cantpress": //2015.08.09. + break; + default: + return false; + } + return true; + } + /*if(args[0].toLowerCase()=="reload") + DoReload(null); //2015.07.20.*/ + else if(args.length>0 && args[0].toLowerCase().equals("admin")) //2015.08.09. + { + DoAdmin(null, args); //2015.08.09. + return true; //2015.08.09. + } + return false; + } + private static void DoReload(Player player) + { //2015.07.20. + //if(player==null || player.isOp() || player.getName()=="NorbiPeti") + //{ + try + { + File file=new File("autoflairconfig.txt"); + if(file.exists()) + { + PluginMain.TownColors.clear(); + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + PluginMain.TownColors.put(s[0], s[1]); + } + br.close(); + for(Player p : PluginMain.GetPlayers()) + { + MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName()); + if(mp.Flair!=null) + { + String flair=mp.Flair; + PluginMain.RemovePlayerDisplayFlairFinal(p, flair); + //PluginMain.AppendPlayerDisplayFlairFinal(p, flair); + PluginMain.AppendPlayerDisplayFlair(mp, p); //2015.08.09. + } + } + String msg="§6Reloaded config file.§r"; + SendMessage(player, msg); //2015.08.09. + } + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + if(player!=null) + player.sendMessage("§cAn error occured. See console for details.§r"); + PluginMain.LastException=e; //2015.08.09. + } + //} + //else + //player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static void DoAdmin(Player player, String[] args) + { //2015.08.09. + if(player==null || player.isOp() || player.getName()=="NorbiPeti") + { + //System.out.println("Args length: " + args.length); + if(args.length==1) + { + String message="§cUsage: /u admin reload|playerinfo§r"; + SendMessage(player, message); + return; + } + //args[0] is "admin" + switch(args[1].toLowerCase()) + { + case "reload": + DoReload(player); + break; + case "playerinfo": + DoPlayerInfo(player, args); + break; + case "getlasterror": + DoGetLastError(player, args); + default: + String message="§cUsage: /u admin reload|playerinfo§r"; + SendMessage(player, message); + return; + } + } + else + player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static void DoPlayerInfo(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "playerinfo" + if(args.length==2) + { + String message="§cUsage: /u admin playerinfo §r"; + SendMessage(player, message); + return; + } + if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2])) + { + String message="§cPlayer not found: "+args[2]+"§r"; + SendMessage(player, message); + return; + } + MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]); + SendMessage(player, "Player name: "+p.PlayerName); + SendMessage(player, "User flair: "+p.Flair); + SendMessage(player, "Username: "+p.UserName); + SendMessage(player, "Flair accepted: "+p.AcceptedFlair); + SendMessage(player, "Flair ignored: "+p.IgnoredFlair); + } + private static void SendMessage(Player player, String message) + { //2015.08.09. + if(player==null) + System.out.println(message); + else + player.sendMessage(message); + } + private static void DoGetLastError(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "getlasterror" + if(PluginMain.LastException!=null) + { + SendMessage(player, "Last error:"); + SendMessage(player, PluginMain.LastException.toString()); + PluginMain.LastException=null; + } + else + SendMessage(player, "There were no exceptions."); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/64/50d16a24893e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/64/50d16a24893e00151ce8ff6d4f74dabd deleted file mode 100644 index 80c391c..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/64/50d16a24893e00151ce8ff6d4f74dabd +++ /dev/null @@ -1,167 +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; - MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. - //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - if(p.Flair==null) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. - { - case "accept": - { - if(p.IgnoredFlair) - p.IgnoredFlair=false; //2015.08.08. - if(!p.AcceptedFlair) - { - String flair=p.Flair; //2015.08.08. - PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. - p.AcceptedFlair=true; //2015.08.08. - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("§cYou already have this user's flair.§r"); - break; - } - case "ignore": - { - if(p.AcceptedFlair) - p.AcceptedFlair=false; //2015.08.08. - if(!p.IgnoredFlair) - { - p.IgnoredFlair=true; - String flair=p.Flair; //2015.08.08. - PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. - player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); - } - else - player.sendMessage("§cYou already ignored this request.§r"); - break; - } - /*case "reload": //2015.07.20. - DoReload(player); - break;*/ - case "admin": //2015.08.09. - DoAdmin(player, args); - break; - default: - return false; - } - return true; - } - - /*if(args[0].toLowerCase()=="reload") - DoReload(null); //2015.07.20.*/ - else if(args[0].toLowerCase()=="admin") - DoAdmin(null, args); //2015.08.09. - return false; - } - private static void DoReload(Player player) - { //2015.07.20. - //if(player==null || player.isOp() || player.getName()=="NorbiPeti") - //{ - try - { - File file=new File("autoflairconfig.txt"); - if(file.exists()) - { - PluginMain.TownColors.clear(); - BufferedReader br=new BufferedReader(new FileReader(file)); - String line; - while((line=br.readLine())!=null) - { - String[] s=line.split(" "); - PluginMain.TownColors.put(s[0], s[1]); - } - br.close(); - for(Player p : PluginMain.GetPlayers()) - { - MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName()); - if(mp.Flair!=null) - { - String flair=mp.Flair; - PluginMain.RemovePlayerDisplayFlairFinal(p, flair); - PluginMain.AppendPlayerDisplayFlairFinal(p, flair); - } - } - String msg="§6Reloaded config file.§r"; - SendMessage(player, msg); //2015.08.09. - } - } - catch(Exception e) - { - System.out.println("Error!\n"+e); - if(player!=null) - player.sendMessage("§cAn error occured. See console for details.§r"); - } - //} - //else - //player.sendMessage("§cYou need to be OP to use this command.§r"); - } - private static void DoAdmin(Player player, String[] args) - { //2015.08.09. - if(player==null || player.isOp() || player.getName()=="NorbiPeti") - { - if(args.length==1) - { - String message="§cUsage: /u admin reload|playerinfo§r"; - SendMessage(player, message); - return; - } - //args[0] is "admin" - switch(args[1].toLowerCase()) - { - case "reload": - DoReload(player); - break; - case "playerinfo": - DoPlayerInfo(player, args); - break; - } - } - else - player.sendMessage("§cYou need to be OP to use this command.§r"); - } - private static void DoPlayerInfo(Player player, String[] args) - { //2015.08.09. - //args[0] is "admin" - args[1] is "playerinfo" - if(args.length==2) - { - String message="§cUsage: /u admin playerinfo §r"; - SendMessage(player, message); - } - if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2])) - { - String message="§cPlayer not found: "+args[2]+"§r"; - SendMessage(player, message); - } - MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]); - return; - } - private static void SendMessage(Player player, String message) - { //2015.08.09. - if(player==null) - System.out.println(message); - else - player.sendMessage(message); - return; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/64/8096a0dee43e001517108d149b613203 b/.metadata/.plugins/org.eclipse.core.resources/.history/64/8096a0dee43e001517108d149b613203 new file mode 100644 index 0000000..67c0651 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/64/8096a0dee43e001517108d149b613203 @@ -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.Collection; +import java.util.HashMap; +import java.util.Map; + +import org.apache.commons.io.IOUtils; +import org.bukkit.entity.Player; +import org.bukkit.plugin.java.JavaPlugin; +import org.json.JSONArray; +import org.json.JSONObject; + +import com.palmergames.bukkit.towny.object.Town; +import com.palmergames.bukkit.towny.object.WorldCoord; + +public class PluginMain extends JavaPlugin +{ //Translated to Java: 2015.07.15. + //A user, which flair isn't obtainable: + //https://www.reddit.com/r/thebutton/comments/31c32v/i_pressed_the_button_without_really_thinking/ + private static PluginMain Instance; + // Fired when plugin is first enabled + @Override + public void onEnable() + { + System.out.println("The Button Auto-flair Plugin by NorbiPeti (:P)"); + getServer().getPluginManager().registerEvents(new PlayerListener(), this); + this.getCommand("u").setExecutor(new Commands()); + this.getCommand("u").setUsage(this.getCommand("u").getUsage().replace('&', '§')); + Instance=this; //2015.08.08. + LoadFiles(false); //2015.08.09. + Runnable r=new Runnable(){public void run(){ThreadMethod();}}; + Thread t=new Thread(r); + t.start(); + } + Boolean stop=false; + // Fired when plugin is disabled + @Override + public void onDisable() + { + SaveFiles(); //2015.08.09. + stop=true; + } + + public void ThreadMethod() //<-- 2015.07.16. + { + while(!stop) + { + try + { + String body=DownloadString("https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/autoflair_system_comment_your_minecraft_name_and/.json?limit=1000"); + JSONArray json=new JSONArray(body).getJSONObject(1).getJSONObject("data").getJSONArray("children"); + for(Object obj : json) + { + JSONObject item = (JSONObject)obj; + String author=item.getJSONObject("data").getString("author"); + String ign=item.getJSONObject("data").getString("body"); + int start = ign.indexOf("IGN:") + "IGN:".length(); + if(start==-1) + continue; //2015.08.09. + int end = ign.indexOf(' ', start); + if (end == -1 || end == start) + end=ign.indexOf('\n', start); //2015.07.15. + if (end == -1 || end == start) + ign = ign.substring(start); + else + ign = ign.substring(start, end); + ign = ign.trim(); + if(HasIGFlair(ign)) + continue; + try { + Thread.sleep(10); + } catch(InterruptedException ex) { + Thread.currentThread().interrupt(); + } + String[] flairdata = DownloadString("http://karmadecay.com/thebutton-data.php?users=" + author).replace("\"", "").split(":"); + String flair; + if(flairdata.length > 1) //2015.07.15. + flair = flairdata[1]; + else + flair=""; + if (flair != "-1") + flair = flair + "s"; + else + flair = "non-presser"; + String flairclass; + if(flairdata.length>2) + flairclass = flairdata[2]; + else + flairclass="unknown"; + SetFlair(ign, flair, flairclass, author); + } + Thread.sleep(10000); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + } + + public static Exception LastException; //2015.08.09. + + public String DownloadString(String urlstr) throws MalformedURLException, IOException + { + URL url = new URL(urlstr); + URLConnection con = url.openConnection(); + con.setRequestProperty("User-Agent", "TheButtonAutoFlair"); + InputStream in = con.getInputStream(); + String encoding = con.getContentEncoding(); + encoding = encoding == null ? "UTF-8" : encoding; + String body = IOUtils.toString(in, encoding); + in.close(); + return body; + } + + public static Map TownColors=new HashMap(); //2015.07.20. + public Boolean HasIGFlair(String playername) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + return p.Flair!=null; //2015.08.08. + } + + public void SetFlair(String playername, String text, String flairclass, String username) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + String finalflair; + p.FlairDecided=true; + switch(flairclass) + { + case "press-1": + finalflair="§c("+text+")§r"; + break; + case "press-2": + finalflair="§6("+text+")§r"; + break; + case "press-3": + finalflair="§e("+text+")§r"; + break; + case "press-4": + finalflair="§a("+text+")§r"; + break; + case "press-5": + finalflair="§9("+text+")§r"; + break; + 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; + case "undecided": //2015.08.09. + p.FlairDecided=false; + finalflair=""; + break; + default: + finalflair=""; + break; + } + if(finalflair.length()==0) //<-- 2015.07.20. + return; + p.Flair=finalflair; //2015.08.08. + p.UserName=username; //2015.08.08. + System.out.println("Added new flair to "+playername+": "+finalflair); + for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08. + { + if(player.getName().equals(playername)) + { + //AppendPlayerDisplayFlair(player, username, finalflair); + AppendPlayerDisplayFlair(p, player); + break; + } + } + } + + public static String GetFlair(Player player) + { //2015.07.16. + String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08. + return flair==null ? "" : flair; + } + + //public static void AppendPlayerDisplayFlair(Player player, String username, String flair) + public static void AppendPlayerDisplayFlair(MaybeOfflinePlayer player, Player p) //<-- 2015.08.09. + { + + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).IgnoredFlair) + return; + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).AcceptedFlair) + { + AppendPlayerDisplayFlairFinal(p, player.Flair); //2015.07.20. + if(!player.FlairDecided) + p.sendMessage("§9Your flair type is unknown. Are you a non-presser or a can't press? (/u nonpresser or /u cantpress)§r"); //2015.08.09. + } + else + p.sendMessage("§9Are you Reddit user "+player.UserName+"?§r §6Type /u accept or /u ignore§r"); + } + + private static void AppendPlayerDisplayFlairFinal(Player player, String flair) + { //2015.07.20. + String color = GetColorForTown(GetPlayerTown(player)); //TO!DO: Multiple colors put on first capital letters + String[] colors = color.substring(1).split("§"); + String displayname=player.getName(); //2015.08.08. + ArrayList Positions=new ArrayList<>(); + for(int i=0; i=colors.length) + { + int x=0; + for(int i=0; i GetPlayers() + { + return Instance.getServer().getOnlinePlayers(); + } + + public static void LoadFiles(boolean reload) //<-- 2015.08.09. + { + if(reload) + { //2015.08.09. + System.out.println("Auto-flair plugin cleanup for reloading..."); + MaybeOfflinePlayer.AllPlayers.clear(); + TownColors.clear(); + } + System.out.println("Loading files for auto-flair plugin..."); //2015.08.09. + try { + File file=new File("flairsaccepted.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + //System.out.println("Name: " + name); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("flairsignored.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsignored.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("autoflairconfig.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + TownColors.put(s[0], s[1]); + } + br.close(); + } + file=new File("customflairs.txt"); //2015.08.09. + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + MaybeOfflinePlayer.AddPlayerIfNeeded(s[0]).Flair=s[1]; //2015.08.09. + } + br.close(); + } + //throw new IOException("Test"); //2015.08.09. + System.out.println("Auto-flair plugin loaded files!"); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + public static void SaveFiles() //<-- 2015.08.09. + { + try + { + FileWriter fw; + fw = new FileWriter("flairsaccepted.txt"); + fw.close(); + fw = new FileWriter("flairsignored.txt"); + fw.close(); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + try { + File file=new File("flairsaccepted.txt"); + BufferedWriter bw=new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.AcceptedFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + file=new File("flairsignored.txt"); + bw = new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.IgnoredFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + public static boolean RemoveLineFromFile(String file, String line) + { //2015.08.09. + File inputFile = new File(file); + File tempFile = new File("_temp.txt"); + + if(!inputFile.exists()) + return true; + + try { + BufferedReader reader = new BufferedReader(new FileReader(inputFile)); + BufferedWriter writer = new BufferedWriter(new FileWriter(tempFile)); + + String lineToRemove = line; + String currentLine; + + while((currentLine = reader.readLine()) != null) { + // trim newline when comparing with lineToRemove + String trimmedLine = currentLine.trim(); + //if(trimmedLine.equals(lineToRemove)) continue; + if(trimmedLine.contains(lineToRemove)) continue; //2015.08.09. + writer.write(currentLine + System.getProperty("line.separator")); + } + writer.close(); + reader.close(); + return tempFile.renameTo(inputFile); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + return false; + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/65/50973663863e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/65/50973663863e00151ce8ff6d4f74dabd deleted file mode 100644 index 1cce5d8..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/65/50973663863e00151ce8ff6d4f74dabd +++ /dev/null @@ -1,131 +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; - MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. - //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - if(p.Flair==null) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. - { - case "accept": - { - if(p.IgnoredFlair) - p.IgnoredFlair=false; //2015.08.08. - if(!p.AcceptedFlair) - { - String flair=p.Flair; //2015.08.08. - PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. - p.AcceptedFlair=true; //2015.08.08. - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("§cYou already have this user's flair.§r"); - break; - } - case "ignore": - { - if(p.AcceptedFlair) - p.AcceptedFlair=false; //2015.08.08. - if(!p.IgnoredFlair) - { - p.IgnoredFlair=true; - String flair=p.Flair; //2015.08.08. - PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. - player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); - } - else - player.sendMessage("§cYou already ignored this request.§r"); - break; - } - case "reload": //2015.07.20. - DoReload(player); - break; - case "admin": //2015.08.09. - DoAdmin(player); - break; - default: - return false; - } - return true; - } - - if(args[0].toLowerCase()=="reload") - DoReload(null); //2015.07.20. - else if(args[0].toLowerCase()=="admin") - DoAdmin(null); //2015.08.09. - return false; - } - private static void DoReload(Player player) - { //2015.07.20. - if(player==null || player.isOp() || player.getName()=="NorbiPeti") - { - try - { - File file=new File("autoflairconfig.txt"); - if(file.exists()) - { - PluginMain.TownColors.clear(); - BufferedReader br=new BufferedReader(new FileReader(file)); - String line; - while((line=br.readLine())!=null) - { - String[] s=line.split(" "); - PluginMain.TownColors.put(s[0], s[1]); - } - br.close(); - for(Player p : PluginMain.GetPlayers()) - { - MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName()); - if(mp.Flair!=null) - { - String flair=mp.Flair; - PluginMain.RemovePlayerDisplayFlairFinal(p, flair); - PluginMain.AppendPlayerDisplayFlairFinal(p, flair); - } - } - String msg="§6Reloaded config file.§r"; - if(player!=null) - player.sendMessage(msg); - else - System.out.println(msg); - } - } - catch(Exception e) - { - System.out.println("Error!\n"+e); - if(player!=null) - player.sendMessage("§cAn error occured. See console for details.§r"); - } - } - else - player.sendMessage("§cYou need to be OP to use this command.§r"); - } - private static void DoAdmin(Player player, String[] args) - { - if(player==null || player.isOp() || player.getName()=="NorbiPeti") - { - - } - else - player.sendMessage("§cYou need to be OP to use this command.§r"); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/66/d0650077873e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/66/d0650077873e00151ce8ff6d4f74dabd deleted file mode 100644 index 1e3d1d3..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/66/d0650077873e00151ce8ff6d4f74dabd +++ /dev/null @@ -1,145 +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; - MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. - //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - if(p.Flair==null) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. - { - case "accept": - { - if(p.IgnoredFlair) - p.IgnoredFlair=false; //2015.08.08. - if(!p.AcceptedFlair) - { - String flair=p.Flair; //2015.08.08. - PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. - p.AcceptedFlair=true; //2015.08.08. - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("§cYou already have this user's flair.§r"); - break; - } - case "ignore": - { - if(p.AcceptedFlair) - p.AcceptedFlair=false; //2015.08.08. - if(!p.IgnoredFlair) - { - p.IgnoredFlair=true; - String flair=p.Flair; //2015.08.08. - PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. - player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); - } - else - player.sendMessage("§cYou already ignored this request.§r"); - break; - } - /*case "reload": //2015.07.20. - DoReload(player); - break;*/ - case "admin": //2015.08.09. - DoAdmin(player, args); - break; - default: - return false; - } - return true; - } - - /*if(args[0].toLowerCase()=="reload") - DoReload(null); //2015.07.20.*/ - else if(args[0].toLowerCase()=="admin") - DoAdmin(null, args); //2015.08.09. - return false; - } - private static void DoReload(Player player) - { //2015.07.20. - //if(player==null || player.isOp() || player.getName()=="NorbiPeti") - //{ - try - { - File file=new File("autoflairconfig.txt"); - if(file.exists()) - { - PluginMain.TownColors.clear(); - BufferedReader br=new BufferedReader(new FileReader(file)); - String line; - while((line=br.readLine())!=null) - { - String[] s=line.split(" "); - PluginMain.TownColors.put(s[0], s[1]); - } - br.close(); - for(Player p : PluginMain.GetPlayers()) - { - MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName()); - if(mp.Flair!=null) - { - String flair=mp.Flair; - PluginMain.RemovePlayerDisplayFlairFinal(p, flair); - PluginMain.AppendPlayerDisplayFlairFinal(p, flair); - } - } - String msg="§6Reloaded config file.§r"; - if(player!=null) - player.sendMessage(msg); - else - System.out.println(msg); - } - } - catch(Exception e) - { - System.out.println("Error!\n"+e); - if(player!=null) - player.sendMessage("§cAn error occured. See console for details.§r"); - } - //} - //else - //player.sendMessage("§cYou need to be OP to use this command.§r"); - } - private static void DoAdmin(Player player, String[] args) - { - if(player==null || player.isOp() || player.getName()=="NorbiPeti") - { - //args[0] is "admin" - switch(args[1].toLowerCase()) - { - case "reload": - DoReload(player); - break; - case "playerinfo": - DoPlayerInfo(player, args); - break; - } - } - else - player.sendMessage("§cYou need to be OP to use this command.§r"); - } - private static void DoPlayerInfo(Player player, String[] args) - { - //args[0] is "admin" - args[1] is "playerinfo" - - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/69/90750be4e43e001517108d149b613203 b/.metadata/.plugins/org.eclipse.core.resources/.history/69/90750be4e43e001517108d149b613203 new file mode 100644 index 0000000..45eac34 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/69/90750be4e43e001517108d149b613203 @@ -0,0 +1,422 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStream; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLConnection; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + +import org.apache.commons.io.IOUtils; +import org.bukkit.entity.Player; +import org.bukkit.plugin.java.JavaPlugin; +import org.json.JSONArray; +import org.json.JSONObject; + +import com.palmergames.bukkit.towny.object.Town; +import com.palmergames.bukkit.towny.object.WorldCoord; + +public class PluginMain extends JavaPlugin +{ //Translated to Java: 2015.07.15. + //A user, which flair isn't obtainable: + //https://www.reddit.com/r/thebutton/comments/31c32v/i_pressed_the_button_without_really_thinking/ + private static PluginMain Instance; + // Fired when plugin is first enabled + @Override + public void onEnable() + { + System.out.println("The Button Auto-flair Plugin by NorbiPeti (:P)"); + getServer().getPluginManager().registerEvents(new PlayerListener(), this); + this.getCommand("u").setExecutor(new Commands()); + this.getCommand("u").setUsage(this.getCommand("u").getUsage().replace('&', '§')); + Instance=this; //2015.08.08. + LoadFiles(false); //2015.08.09. + Runnable r=new Runnable(){public void run(){ThreadMethod();}}; + Thread t=new Thread(r); + t.start(); + } + Boolean stop=false; + // Fired when plugin is disabled + @Override + public void onDisable() + { + SaveFiles(); //2015.08.09. + stop=true; + } + + public void ThreadMethod() //<-- 2015.07.16. + { + while(!stop) + { + try + { + String body=DownloadString("https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/autoflair_system_comment_your_minecraft_name_and/.json?limit=1000"); + JSONArray json=new JSONArray(body).getJSONObject(1).getJSONObject("data").getJSONArray("children"); + for(Object obj : json) + { + JSONObject item = (JSONObject)obj; + String author=item.getJSONObject("data").getString("author"); + String ign=item.getJSONObject("data").getString("body"); + int start = ign.indexOf("IGN:") + "IGN:".length(); + if(start==-1) + continue; //2015.08.09. + int end = ign.indexOf(' ', start); + if (end == -1 || end == start) + end=ign.indexOf('\n', start); //2015.07.15. + if (end == -1 || end == start) + ign = ign.substring(start); + else + ign = ign.substring(start, end); + ign = ign.trim(); + if(HasIGFlair(ign)) + continue; + try { + Thread.sleep(10); + } catch(InterruptedException ex) { + Thread.currentThread().interrupt(); + } + String[] flairdata = DownloadString("http://karmadecay.com/thebutton-data.php?users=" + author).replace("\"", "").split(":"); + String flair; + if(flairdata.length > 1) //2015.07.15. + flair = flairdata[1]; + else + flair=""; + if (flair != "-1") + flair = flair + "s"; + else + flair = "non-presser"; + String flairclass; + if(flairdata.length>2) + flairclass = flairdata[2]; + else + flairclass="unknown"; + SetFlair(ign, flair, flairclass, author); + } + Thread.sleep(10000); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + } + + public static Exception LastException; //2015.08.09. + + public String DownloadString(String urlstr) throws MalformedURLException, IOException + { + URL url = new URL(urlstr); + URLConnection con = url.openConnection(); + con.setRequestProperty("User-Agent", "TheButtonAutoFlair"); + InputStream in = con.getInputStream(); + String encoding = con.getContentEncoding(); + encoding = encoding == null ? "UTF-8" : encoding; + String body = IOUtils.toString(in, encoding); + in.close(); + return body; + } + + public static Map TownColors=new HashMap(); //2015.07.20. + public Boolean HasIGFlair(String playername) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + return p.Flair!=null; //2015.08.08. + } + + public void SetFlair(String playername, String text, String flairclass, String username) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + String finalflair; + p.FlairDecided=true; + switch(flairclass) + { + case "press-1": + finalflair="§c("+text+")§r"; + break; + case "press-2": + finalflair="§6("+text+")§r"; + break; + case "press-3": + finalflair="§e("+text+")§r"; + break; + case "press-4": + finalflair="§a("+text+")§r"; + break; + case "press-5": + finalflair="§9("+text+")§r"; + break; + 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; + case "undecided": //2015.08.09. + p.FlairDecided=false; + finalflair=""; + break; + default: + finalflair=""; + break; + } + if(finalflair.length()==0) //<-- 2015.07.20. + return; + p.Flair=finalflair; //2015.08.08. + p.UserName=username; //2015.08.08. + System.out.println("Added new flair to "+playername+": "+finalflair); + for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08. + { + if(player.getName().equals(playername)) + { + //AppendPlayerDisplayFlair(player, username, finalflair); + AppendPlayerDisplayFlair(p, player); + break; + } + } + } + + public static String GetFlair(Player player) + { //2015.07.16. + String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08. + return flair==null ? "" : flair; + } + + //public static void AppendPlayerDisplayFlair(Player player, String username, String flair) + public static void AppendPlayerDisplayFlair(MaybeOfflinePlayer player, Player p) //<-- 2015.08.09. + { + + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).IgnoredFlair) + return; + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).AcceptedFlair) + { + AppendPlayerDisplayFlairFinal(p, player.Flair); //2015.07.20. + if(!player.FlairDecided) + p.sendMessage("§9Your flair type is unknown. Are you a non-presser or a can't press? (/u nonpresser or /u cantpress)§r"); //2015.08.09. + } + else + p.sendMessage("§9Are you Reddit user "+player.UserName+"?§r §6Type /u accept or /u ignore§r"); + } + + private static void AppendPlayerDisplayFlairFinal(Player player, String flair) + { //2015.07.20. + String color = GetColorForTown(GetPlayerTown(player)); //TO!DO: Multiple colors put on first capital letters + String[] colors = color.substring(1).split("§"); + String displayname=player.getName(); //2015.08.08. + ArrayList Positions=new ArrayList<>(); + for(int i=0; i=colors.length) + { + int x=0; + for(int i=0; i GetPlayers() + { + return Instance.getServer().getOnlinePlayers(); + } + + public static void LoadFiles(boolean reload) //<-- 2015.08.09. + { + if(reload) + { //2015.08.09. + System.out.println("Auto-flair plugin cleanup for reloading..."); + MaybeOfflinePlayer.AllPlayers.clear(); + TownColors.clear(); + } + System.out.println("Loading files for auto-flair plugin..."); //2015.08.09. + try { + File file=new File("flairsaccepted.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + //System.out.println("Name: " + name); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("flairsignored.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsignored.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("autoflairconfig.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + TownColors.put(s[0], s[1]); + } + br.close(); + } + file=new File("customflairs.txt"); //2015.08.09. + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + MaybeOfflinePlayer.AddPlayerIfNeeded(s[0]).Flair=s[1]; //2015.08.09. + } + br.close(); + } + //throw new IOException("Test"); //2015.08.09. + System.out.println("Auto-flair plugin loaded files!"); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + public static void SaveFiles() //<-- 2015.08.09. + { + try + { + FileWriter fw; + fw = new FileWriter("flairsaccepted.txt"); + fw.close(); + fw = new FileWriter("flairsignored.txt"); + fw.close(); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + try { + File file=new File("flairsaccepted.txt"); + BufferedWriter bw=new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.AcceptedFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + file=new File("flairsignored.txt"); + bw = new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.IgnoredFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + public static boolean RemoveLineFromFile(String file, String line) + { //2015.08.09. + File inputFile = new File(file); + File tempFile = new File("_temp.txt"); + + try { + BufferedReader reader = new BufferedReader(new FileReader(inputFile)); + BufferedWriter writer = new BufferedWriter(new FileWriter(tempFile)); + + String lineToRemove = line; + String currentLine; + + while((currentLine = reader.readLine()) != null) { + // trim newline when comparing with lineToRemove + String trimmedLine = currentLine.trim(); + //if(trimmedLine.equals(lineToRemove)) continue; + if(trimmedLine.contains(lineToRemove)) continue; //2015.08.09. + writer.write(currentLine + System.getProperty("line.separator")); + } + writer.close(); + reader.close(); + return tempFile.renameTo(inputFile); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + return false; + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/6a/20a2e34ad03e001518fa86d7ae2a1cf8 b/.metadata/.plugins/org.eclipse.core.resources/.history/6a/20a2e34ad03e001518fa86d7ae2a1cf8 new file mode 100644 index 0000000..330b73a --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/6a/20a2e34ad03e001518fa86d7ae2a1cf8 @@ -0,0 +1,201 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; + +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class Commands implements CommandExecutor { + // This method is called, when somebody uses our command + @Override + public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { + if (sender instanceof Player) { + Player player = (Player) sender; + if(args.length<1) + return false; + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. + //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) + if(p.Flair==null) + { + player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); + return true; + } + switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. + { + case "accept": + { + if(p.IgnoredFlair) + p.IgnoredFlair=false; //2015.08.08. + if(!p.AcceptedFlair) + { + String flair=p.Flair; //2015.08.08. + //PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + PluginMain.AppendPlayerDisplayFlair(p, player); + p.AcceptedFlair=true; //2015.08.08. + player.sendMessage("§6Your flair has been set:§r "+flair); + } + else + player.sendMessage("§cYou already have this user's flair.§r"); + break; + } + case "ignore": + { + if(p.AcceptedFlair) + p.AcceptedFlair=false; //2015.08.08. + if(!p.IgnoredFlair) + { + p.IgnoredFlair=true; + String flair=p.Flair; //2015.08.08. + PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. + player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); + } + else + player.sendMessage("§cYou already ignored this request.§r"); + break; + } + /*case "reload": //2015.07.20. + DoReload(player); + break;*/ + case "admin": //2015.08.09. + DoAdmin(player, args); + break; + case "nonpresser": //2015.08.09. + s + break; + case "cantpress": //2015.08.09. + break; + default: + return false; + } + return true; + } + /*if(args[0].toLowerCase()=="reload") + DoReload(null); //2015.07.20.*/ + else if(args.length>0 && args[0].toLowerCase().equals("admin")) //2015.08.09. + { + DoAdmin(null, args); //2015.08.09. + return true; //2015.08.09. + } + return false; + } + private static void DoReload(Player player) + { //2015.07.20. + //if(player==null || player.isOp() || player.getName()=="NorbiPeti") + //{ + try + { + File file=new File("autoflairconfig.txt"); + if(file.exists()) + { + PluginMain.TownColors.clear(); + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + PluginMain.TownColors.put(s[0], s[1]); + } + br.close(); + for(Player p : PluginMain.GetPlayers()) + { + MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName()); + if(mp.Flair!=null) + { + String flair=mp.Flair; + PluginMain.RemovePlayerDisplayFlairFinal(p, flair); + //PluginMain.AppendPlayerDisplayFlairFinal(p, flair); + PluginMain.AppendPlayerDisplayFlair(mp, p); //2015.08.09. + } + } + String msg="§6Reloaded config file.§r"; + SendMessage(player, msg); //2015.08.09. + } + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + if(player!=null) + player.sendMessage("§cAn error occured. See console for details.§r"); + PluginMain.LastException=e; //2015.08.09. + } + //} + //else + //player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static void DoAdmin(Player player, String[] args) + { //2015.08.09. + if(player==null || player.isOp() || player.getName()=="NorbiPeti") + { + //System.out.println("Args length: " + args.length); + if(args.length==1) + { + String message="§cUsage: /u admin reload|playerinfo§r"; + SendMessage(player, message); + return; + } + //args[0] is "admin" + switch(args[1].toLowerCase()) + { + case "reload": + DoReload(player); + break; + case "playerinfo": + DoPlayerInfo(player, args); + break; + case "getlasterror": + DoGetLastError(player, args); + default: + String message="§cUsage: /u admin reload|playerinfo§r"; + SendMessage(player, message); + return; + } + } + else + player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static void DoPlayerInfo(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "playerinfo" + if(args.length==2) + { + String message="§cUsage: /u admin playerinfo §r"; + SendMessage(player, message); + return; + } + if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2])) + { + String message="§cPlayer not found: "+args[2]+"§r"; + SendMessage(player, message); + return; + } + MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]); + SendMessage(player, "Player name: "+p.PlayerName); + SendMessage(player, "User flair: "+p.Flair); + SendMessage(player, "Username: "+p.UserName); + SendMessage(player, "Flair accepted: "+p.AcceptedFlair); + SendMessage(player, "Flair ignored: "+p.IgnoredFlair); + } + private static void SendMessage(Player player, String message) + { //2015.08.09. + if(player==null) + System.out.println(message); + else + player.sendMessage(message); + } + private static void DoGetLastError(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "getlasterror" + if(PluginMain.LastException!=null) + { + SendMessage(player, "Last error:"); + SendMessage(player, PluginMain.LastException.toString()); + PluginMain.LastException=null; + } + else + SendMessage(player, "There were no exceptions."); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/6c/20b08dced03e001518fa86d7ae2a1cf8 b/.metadata/.plugins/org.eclipse.core.resources/.history/6c/20b08dced03e001518fa86d7ae2a1cf8 new file mode 100644 index 0000000..0384150 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/6c/20b08dced03e001518fa86d7ae2a1cf8 @@ -0,0 +1,211 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; + +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class Commands implements CommandExecutor { + // This method is called, when somebody uses our command + @Override + public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { + if (sender instanceof Player) { + Player player = (Player) sender; + if(args.length<1) + return false; + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. + //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) + if(p.Flair==null) + { + player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); + return true; + } + switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. + { + case "accept": + { + if(p.IgnoredFlair) + p.IgnoredFlair=false; //2015.08.08. + if(!p.AcceptedFlair) + { + String flair=p.Flair; //2015.08.08. + //PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + PluginMain.AppendPlayerDisplayFlair(p, player); + p.AcceptedFlair=true; //2015.08.08. + player.sendMessage("§6Your flair has been set:§r "+flair); + } + else + player.sendMessage("§cYou already have this user's flair.§r"); + break; + } + case "ignore": + { + if(p.AcceptedFlair) + p.AcceptedFlair=false; //2015.08.08. + if(!p.IgnoredFlair) + { + p.IgnoredFlair=true; + String flair=p.Flair; //2015.08.08. + PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. + player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); + } + else + player.sendMessage("§cYou already ignored this request.§r"); + break; + } + /*case "reload": //2015.07.20. + DoReload(player); + break;*/ + case "admin": //2015.08.09. + DoAdmin(player, args); + break; + case "nonpresser": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + + break; + case "cantpress": //2015.08.09. + break; + default: + return false; + } + return true; + } + /*if(args[0].toLowerCase()=="reload") + DoReload(null); //2015.07.20.*/ + else if(args.length>0 && args[0].toLowerCase().equals("admin")) //2015.08.09. + { + DoAdmin(null, args); //2015.08.09. + return true; //2015.08.09. + } + return false; + } + private static void DoReload(Player player) + { //2015.07.20. + //if(player==null || player.isOp() || player.getName()=="NorbiPeti") + //{ + try + { + File file=new File("autoflairconfig.txt"); + if(file.exists()) + { + PluginMain.TownColors.clear(); + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + PluginMain.TownColors.put(s[0], s[1]); + } + br.close(); + for(Player p : PluginMain.GetPlayers()) + { + MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName()); + if(mp.Flair!=null) + { + String flair=mp.Flair; + PluginMain.RemovePlayerDisplayFlairFinal(p, flair); + //PluginMain.AppendPlayerDisplayFlairFinal(p, flair); + PluginMain.AppendPlayerDisplayFlair(mp, p); //2015.08.09. + } + } + String msg="§6Reloaded config file.§r"; + SendMessage(player, msg); //2015.08.09. + } + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + if(player!=null) + player.sendMessage("§cAn error occured. See console for details.§r"); + PluginMain.LastException=e; //2015.08.09. + } + //} + //else + //player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static void DoAdmin(Player player, String[] args) + { //2015.08.09. + if(player==null || player.isOp() || player.getName()=="NorbiPeti") + { + //System.out.println("Args length: " + args.length); + if(args.length==1) + { + String message="§cUsage: /u admin reload|playerinfo§r"; + SendMessage(player, message); + return; + } + //args[0] is "admin" + switch(args[1].toLowerCase()) + { + case "reload": + DoReload(player); + break; + case "playerinfo": + DoPlayerInfo(player, args); + break; + case "getlasterror": + DoGetLastError(player, args); + default: + String message="§cUsage: /u admin reload|playerinfo§r"; + SendMessage(player, message); + return; + } + } + else + player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static void DoPlayerInfo(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "playerinfo" + if(args.length==2) + { + String message="§cUsage: /u admin playerinfo §r"; + SendMessage(player, message); + return; + } + if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2])) + { + String message="§cPlayer not found: "+args[2]+"§r"; + SendMessage(player, message); + return; + } + MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]); + SendMessage(player, "Player name: "+p.PlayerName); + SendMessage(player, "User flair: "+p.Flair); + SendMessage(player, "Username: "+p.UserName); + SendMessage(player, "Flair accepted: "+p.AcceptedFlair); + SendMessage(player, "Flair ignored: "+p.IgnoredFlair); + } + private static void SendMessage(Player player, String message) + { //2015.08.09. + if(player==null) + System.out.println(message); + else + player.sendMessage(message); + } + private static void DoGetLastError(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "getlasterror" + if(PluginMain.LastException!=null) + { + SendMessage(player, "Last error:"); + SendMessage(player, PluginMain.LastException.toString()); + PluginMain.LastException=null; + } + else + SendMessage(player, "There were no exceptions."); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/6c/500072fecd3e001518fa86d7ae2a1cf8 b/.metadata/.plugins/org.eclipse.core.resources/.history/6c/500072fecd3e001518fa86d7ae2a1cf8 new file mode 100644 index 0000000..5740654 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/6c/500072fecd3e001518fa86d7ae2a1cf8 @@ -0,0 +1,351 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStream; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLConnection; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + +import org.apache.commons.io.IOUtils; +import org.bukkit.entity.Player; +import org.bukkit.plugin.java.JavaPlugin; +import org.json.JSONArray; +import org.json.JSONObject; + +import com.palmergames.bukkit.towny.object.Town; +import com.palmergames.bukkit.towny.object.WorldCoord; + +public class PluginMain extends JavaPlugin +{ //Translated to Java: 2015.07.15. + //A user, which flair isn't obtainable: + //https://www.reddit.com/r/thebutton/comments/31c32v/i_pressed_the_button_without_really_thinking/ + private static PluginMain Instance; + // Fired when plugin is first enabled + @Override + public void onEnable() + { + System.out.println("The Button Auto-flair Plugin by NorbiPeti (:P)"); + getServer().getPluginManager().registerEvents(new PlayerListener(), this); + this.getCommand("u").setExecutor(new Commands()); + this.getCommand("u").setUsage(this.getCommand("u").getUsage().replace('&', '§')); + Instance=this; //2015.08.08. + try { + File file=new File("flairsaccepted.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + //System.out.println("Name: " + name); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("flairsignored.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsignored.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("autoflairconfig.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + TownColors.put(s[0], s[1]); + } + br.close(); + } + //throw new IOException("Test"); //2015.08.09. + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + Runnable r=new Runnable(){public void run(){ThreadMethod();}}; + Thread t=new Thread(r); + t.start(); + } + Boolean stop=false; + // Fired when plugin is disabled + @Override + public void onDisable() + { + try + { + FileWriter fw; + fw = new FileWriter("flairsaccepted.txt"); + fw.close(); + fw = new FileWriter("flairsignored.txt"); + fw.close(); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + try { + File file=new File("flairsaccepted.txt"); + BufferedWriter bw=new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.AcceptedFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + file=new File("flairsignored.txt"); + bw = new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.IgnoredFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + stop=true; + } + + public void ThreadMethod() //<-- 2015.07.16. + { + while(!stop) + { + try + { + String body=DownloadString("https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/autoflair_system_comment_your_minecraft_name_and/.json?limit=1000"); + JSONArray json=new JSONArray(body).getJSONObject(1).getJSONObject("data").getJSONArray("children"); + for(Object obj : json) + { + JSONObject item = (JSONObject)obj; + String author=item.getJSONObject("data").getString("author"); + String ign=item.getJSONObject("data").getString("body"); + int start = ign.indexOf("IGN:") + "IGN:".length(); + int end = ign.indexOf(' ', start); + if (end == -1 || end == start) + end=ign.indexOf('\n', start); //2015.07.15. + if (end == -1 || end == start) + ign = ign.substring(start); + else + ign = ign.substring(start, end); + ign = ign.trim(); + if(HasIGFlair(ign)) + continue; + try { + Thread.sleep(10); + } catch(InterruptedException ex) { + Thread.currentThread().interrupt(); + } + String[] flairdata = DownloadString("http://karmadecay.com/thebutton-data.php?users=" + author).replace("\"", "").split(":"); + String flair; + if(flairdata.length > 1) //2015.07.15. + flair = flairdata[1]; + else + flair=""; + if (flair != "-1") + flair = flair + "s"; + else + flair = "non-presser"; + String flairclass; + if(flairdata.length>2) + flairclass = flairdata[2]; + else + flairclass="unknown"; + SetFlair(ign, flair, flairclass, author); + } + Thread.sleep(10000); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + } + + public static Exception LastException; //2015.08.09. + + public String DownloadString(String urlstr) throws MalformedURLException, IOException + { + URL url = new URL(urlstr); + URLConnection con = url.openConnection(); + con.setRequestProperty("User-Agent", "TheButtonAutoFlair"); + InputStream in = con.getInputStream(); + String encoding = con.getContentEncoding(); + encoding = encoding == null ? "UTF-8" : encoding; + String body = IOUtils.toString(in, encoding); + in.close(); + return body; + } + + public static Map TownColors=new HashMap(); //2015.07.20. + public Boolean HasIGFlair(String playername) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + return p.Flair!=null; //2015.08.08. + } + + public void SetFlair(String playername, String text, String flairclass, String username) + { + String finalflair; + switch(flairclass) + { + case "press-1": + finalflair="§c("+text+")§r"; + break; + case "press-2": + finalflair="§6("+text+")§r"; + break; + case "press-3": + finalflair="§e("+text+")§r"; + break; + case "press-4": + finalflair="§a("+text+")§r"; + break; + case "press-5": + finalflair="§9("+text+")§r"; + break; + case "press-6": + finalflair="§5("+text+")§r"; + break; + case "no-press": + finalflair="§7(non-pr.)§r"; + break; + case "cheater": + finalflair="§5("+text+")§r"; + break; + case "cant-press": //2015.08.08. + finalflair="§r(can't press)§r"; + break; + default: + finalflair=""; + break; + } + if(finalflair.length()==0) //<-- 2015.07.20. + return; + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + p.Flair=finalflair; //2015.08.08. + p.UserName=username; //2015.08.08. + System.out.println("Added new flair to "+playername+": "+finalflair); + for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08. + { + if(player.getName().equals(playername)) + { + AppendPlayerDisplayFlair(player, username, finalflair); + break; + } + } + } + + public static String GetFlair(Player player) + { //2015.07.16. + String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08. + return flair==null ? "" : flair; + } + + public static void AppendPlayerDisplayFlair(Player player, String username, String flair) + { + if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).IgnoredFlair) + return; + if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).AcceptedFlair) + AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + else + player.sendMessage("§9Are you Reddit user "+username+"?§r §6Type /u accept or /u ignore§r"); + } + + public static void AppendPlayerDisplayFlairFinal(Player player, String flair) + { //2015.07.20. + String color = GetColorForTown(GetPlayerTown(player)); //TO!DO: Multiple colors put on first capital letters + String[] colors = color.substring(1).split("§"); + String displayname=player.getName(); //2015.08.08. + ArrayList Positions=new ArrayList<>(); + for(int i=0; i=colors.length) + { + int x=0; + for(int i=0; i GetPlayers() + { + return Instance.getServer().getOnlinePlayers(); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/6d/30dfaa0fd93e001517108d149b613203 b/.metadata/.plugins/org.eclipse.core.resources/.history/6d/30dfaa0fd93e001517108d149b613203 new file mode 100644 index 0000000..c2af90a --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/6d/30dfaa0fd93e001517108d149b613203 @@ -0,0 +1,227 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; + +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class Commands implements CommandExecutor { + // This method is called, when somebody uses our command + @Override + public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { + if (sender instanceof Player) { + Player player = (Player) sender; + if(args.length<1) + return false; + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. + //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) + if(p.Flair==null) + { + player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); + return true; + } + switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. + { + case "accept": + { + if(p.IgnoredFlair) + p.IgnoredFlair=false; //2015.08.08. + if(!p.AcceptedFlair) + { + String flair=p.Flair; //2015.08.08. + //PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + PluginMain.AppendPlayerDisplayFlair(p, player); + p.AcceptedFlair=true; //2015.08.08. + player.sendMessage("§6Your flair has been set:§r "+flair); + } + else + player.sendMessage("§cYou already have this user's flair.§r"); + break; + } + case "ignore": + { + if(p.AcceptedFlair) + p.AcceptedFlair=false; //2015.08.08. + if(!p.IgnoredFlair) + { + p.IgnoredFlair=true; + String flair=p.Flair; //2015.08.08. + PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. + player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); + } + else + player.sendMessage("§cYou already ignored this request.§r"); + break; + } + /*case "reload": //2015.07.20. + DoReload(player); + break;*/ + case "admin": //2015.08.09. + DoAdmin(player, args); + break; + case "nonpresser": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§7(non-pr.)§r"; + break; + case "cantpress": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§r(can't press)§r"; + break; + default: + return false; + } + return true; + } + /*if(args[0].toLowerCase()=="reload") + DoReload(null); //2015.07.20.*/ + else if(args.length>0 && args[0].toLowerCase().equals("admin")) //2015.08.09. + { + DoAdmin(null, args); //2015.08.09. + return true; //2015.08.09. + } + return false; + } + private static void DoReload(Player player) + { //2015.07.20. + //if(player==null || player.isOp() || player.getName()=="NorbiPeti") + //{ + try + { + File file=new File("autoflairconfig.txt"); + if(file.exists()) + { + PluginMain.LoadFiles(true); //2015.08.09. + for(Player p : PluginMain.GetPlayers()) + { + MaybeOfflinePlayer mp = MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName()); + if(mp.Flair!=null) + { + String flair=mp.Flair; + PluginMain.RemovePlayerDisplayFlairFinal(p, flair); + //PluginMain.AppendPlayerDisplayFlairFinal(p, flair); + PluginMain.AppendPlayerDisplayFlair(mp, p); //2015.08.09. + } + String msg="§6Note: The auto-flair plugin has been reloaded. You might need to wait 10s to have your flair.§r"; //2015.08.09. + p.sendMessage(msg); //2015.08.09. + } + //String msg="§6Reloaded config file.§r"; + //SendMessage(player, msg); //2015.08.09. + } + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + if(player!=null) + player.sendMessage("§cAn error occured. See console for details.§r"); + PluginMain.LastException=e; //2015.08.09. + } + //} + //else + //player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static Player ReloadPlayer; //2015.08.09. + private static void DoAdmin(Player player, String[] args) + { //2015.08.09. + if(player==null || player.isOp() || player.getName()=="NorbiPeti") + { + //System.out.println("Args length: " + args.length); + if(args.length==1) + { + String message="§cUsage: /u admin reload|playerinfo§r"; + SendMessage(player, message); + return; + } + //args[0] is "admin" + switch(args[1].toLowerCase()) + { + case "reload": + ReloadPlayer=player; //2015.08.09. + SendMessage(player, "§6Make sure to save the current settings before you modify and reload them! Type /u admin confirm when done.§r"); + break; + case "playerinfo": + DoPlayerInfo(player, args); + break; + case "getlasterror": + DoGetLastError(player, args); + case "confirm": + if(ReloadPlayer!=null && ReloadPlayer.equals(player)) + DoReload(player); //2015.08.09. + else + SendMessage(player, "§cYou need to do /u admin reload first.§r"); + break; + case "save": + + break; + default: + String message="§cUsage: /u admin reload|playerinfo|getlasterror§r"; + SendMessage(player, message); + return; + } + } + else + player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static void DoPlayerInfo(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "playerinfo" + if(args.length==2) + { + String message="§cUsage: /u admin playerinfo §r"; + SendMessage(player, message); + return; + } + if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2])) + { + String message="§cPlayer not found: "+args[2]+"§r"; + SendMessage(player, message); + return; + } + MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]); + SendMessage(player, "Player name: "+p.PlayerName); + SendMessage(player, "User flair: "+p.Flair); + SendMessage(player, "Username: "+p.UserName); + SendMessage(player, "Flair accepted: "+p.AcceptedFlair); + SendMessage(player, "Flair ignored: "+p.IgnoredFlair); + } + private static void SendMessage(Player player, String message) + { //2015.08.09. + if(player==null) + System.out.println(message); + else + player.sendMessage(message); + } + private static void DoGetLastError(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "getlasterror" + if(PluginMain.LastException!=null) + { + SendMessage(player, "Last error:"); + SendMessage(player, PluginMain.LastException.toString()); + PluginMain.LastException=null; + } + else + SendMessage(player, "There were no exceptions."); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/6e/a01e1adad13e001518fa86d7ae2a1cf8 b/.metadata/.plugins/org.eclipse.core.resources/.history/6e/a01e1adad13e001518fa86d7ae2a1cf8 new file mode 100644 index 0000000..fb29d4f --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/6e/a01e1adad13e001518fa86d7ae2a1cf8 @@ -0,0 +1,373 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStream; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLConnection; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + +import org.apache.commons.io.IOUtils; +import org.bukkit.entity.Player; +import org.bukkit.plugin.java.JavaPlugin; +import org.json.JSONArray; +import org.json.JSONObject; + +import com.palmergames.bukkit.towny.object.Town; +import com.palmergames.bukkit.towny.object.WorldCoord; + +public class PluginMain extends JavaPlugin +{ //Translated to Java: 2015.07.15. + //A user, which flair isn't obtainable: + //https://www.reddit.com/r/thebutton/comments/31c32v/i_pressed_the_button_without_really_thinking/ + private static PluginMain Instance; + // Fired when plugin is first enabled + @Override + public void onEnable() + { + System.out.println("The Button Auto-flair Plugin by NorbiPeti (:P)"); + getServer().getPluginManager().registerEvents(new PlayerListener(), this); + this.getCommand("u").setExecutor(new Commands()); + this.getCommand("u").setUsage(this.getCommand("u").getUsage().replace('&', '§')); + Instance=this; //2015.08.08. + LoadFiles(false); //2015.08.09. + Runnable r=new Runnable(){public void run(){ThreadMethod();}}; + Thread t=new Thread(r); + t.start(); + } + Boolean stop=false; + // Fired when plugin is disabled + @Override + public void onDisable() + { + try + { + FileWriter fw; + fw = new FileWriter("flairsaccepted.txt"); + fw.close(); + fw = new FileWriter("flairsignored.txt"); + fw.close(); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + try { + File file=new File("flairsaccepted.txt"); + BufferedWriter bw=new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.AcceptedFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + file=new File("flairsignored.txt"); + bw = new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.IgnoredFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + stop=true; + } + + public void ThreadMethod() //<-- 2015.07.16. + { + while(!stop) + { + try + { + String body=DownloadString("https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/autoflair_system_comment_your_minecraft_name_and/.json?limit=1000"); + JSONArray json=new JSONArray(body).getJSONObject(1).getJSONObject("data").getJSONArray("children"); + for(Object obj : json) + { + JSONObject item = (JSONObject)obj; + String author=item.getJSONObject("data").getString("author"); + String ign=item.getJSONObject("data").getString("body"); + int start = ign.indexOf("IGN:") + "IGN:".length(); + int end = ign.indexOf(' ', start); + if (end == -1 || end == start) + end=ign.indexOf('\n', start); //2015.07.15. + if (end == -1 || end == start) + ign = ign.substring(start); + else + ign = ign.substring(start, end); + ign = ign.trim(); + if(HasIGFlair(ign)) + continue; + try { + Thread.sleep(10); + } catch(InterruptedException ex) { + Thread.currentThread().interrupt(); + } + String[] flairdata = DownloadString("http://karmadecay.com/thebutton-data.php?users=" + author).replace("\"", "").split(":"); + String flair; + if(flairdata.length > 1) //2015.07.15. + flair = flairdata[1]; + else + flair=""; + if (flair != "-1") + flair = flair + "s"; + else + flair = "non-presser"; + String flairclass; + if(flairdata.length>2) + flairclass = flairdata[2]; + else + flairclass="unknown"; + SetFlair(ign, flair, flairclass, author); + } + Thread.sleep(10000); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + } + + public static Exception LastException; //2015.08.09. + + public String DownloadString(String urlstr) throws MalformedURLException, IOException + { + URL url = new URL(urlstr); + URLConnection con = url.openConnection(); + con.setRequestProperty("User-Agent", "TheButtonAutoFlair"); + InputStream in = con.getInputStream(); + String encoding = con.getContentEncoding(); + encoding = encoding == null ? "UTF-8" : encoding; + String body = IOUtils.toString(in, encoding); + in.close(); + return body; + } + + public static Map TownColors=new HashMap(); //2015.07.20. + public Boolean HasIGFlair(String playername) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + return p.Flair!=null; //2015.08.08. + } + + public void SetFlair(String playername, String text, String flairclass, String username) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + String finalflair; + p.FlairDecided=true; + switch(flairclass) + { + case "press-1": + finalflair="§c("+text+")§r"; + break; + case "press-2": + finalflair="§6("+text+")§r"; + break; + case "press-3": + finalflair="§e("+text+")§r"; + break; + case "press-4": + finalflair="§a("+text+")§r"; + break; + case "press-5": + finalflair="§9("+text+")§r"; + break; + 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; + case "undecided": //2015.08.09. + p.FlairDecided=false; + finalflair=""; + break; + default: + finalflair=""; + break; + } + if(finalflair.length()==0) //<-- 2015.07.20. + return; + p.Flair=finalflair; //2015.08.08. + p.UserName=username; //2015.08.08. + System.out.println("Added new flair to "+playername+": "+finalflair); + for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08. + { + if(player.getName().equals(playername)) + { + //AppendPlayerDisplayFlair(player, username, finalflair); + AppendPlayerDisplayFlair(p, player); + break; + } + } + } + + public static String GetFlair(Player player) + { //2015.07.16. + String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08. + return flair==null ? "" : flair; + } + + //public static void AppendPlayerDisplayFlair(Player player, String username, String flair) + public static void AppendPlayerDisplayFlair(MaybeOfflinePlayer player, Player p) //<-- 2015.08.09. + { + + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).IgnoredFlair) + return; + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).AcceptedFlair) + { + AppendPlayerDisplayFlairFinal(p, player.Flair); //2015.07.20. + if(!player.FlairDecided) + p.sendMessage("§9Your flair type is unknown. Are you a non-presser or a can't press? (/u nonpresser or /u cantpress)§r"); //2015.08.09. + } + else + p.sendMessage("§9Are you Reddit user "+player.UserName+"?§r §6Type /u accept or /u ignore§r"); + } + + private static void AppendPlayerDisplayFlairFinal(Player player, String flair) + { //2015.07.20. + String color = GetColorForTown(GetPlayerTown(player)); //TO!DO: Multiple colors put on first capital letters + String[] colors = color.substring(1).split("§"); + String displayname=player.getName(); //2015.08.08. + ArrayList Positions=new ArrayList<>(); + for(int i=0; i=colors.length) + { + int x=0; + for(int i=0; i GetPlayers() + { + return Instance.getServer().getOnlinePlayers(); + } + + public static void LoadFiles(boolean reload) //<-- 2015.08.09. + { + System.out.println("Loading files for auto-flair plugin..."); //2015.08.09. + if(reload) + { + MaybeOfflinePlayer.AllPlayers.clear(); //2015.08.09. + } + try { + File file=new File("flairsaccepted.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + //System.out.println("Name: " + name); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("flairsignored.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsignored.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("autoflairconfig.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + TownColors.put(s[0], s[1]); + } + br.close(); + } + //throw new IOException("Test"); //2015.08.09. + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/6e/b0802cf3de3e001517108d149b613203 b/.metadata/.plugins/org.eclipse.core.resources/.history/6e/b0802cf3de3e001517108d149b613203 new file mode 100644 index 0000000..e679de8 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/6e/b0802cf3de3e001517108d149b613203 @@ -0,0 +1,250 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +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; + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. + //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) + if(p.Flair==null) + { + player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); + return true; + } + switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. + { + case "accept": + { + if(p.IgnoredFlair) + p.IgnoredFlair=false; //2015.08.08. + if(!p.AcceptedFlair) + { + String flair=p.Flair; //2015.08.08. + //PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + PluginMain.AppendPlayerDisplayFlair(p, player); + p.AcceptedFlair=true; //2015.08.08. + player.sendMessage("§6Your flair has been set:§r "+flair); + } + else + player.sendMessage("§cYou already have this user's flair.§r"); + break; + } + case "ignore": + { + if(p.AcceptedFlair) + p.AcceptedFlair=false; //2015.08.08. + if(!p.IgnoredFlair) + { + p.IgnoredFlair=true; + String flair=p.Flair; //2015.08.08. + PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. + player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); + } + else + player.sendMessage("§cYou already ignored this request.§r"); + break; + } + /*case "reload": //2015.07.20. + DoReload(player); + break;*/ + case "admin": //2015.08.09. + DoAdmin(player, args); + break; + case "nonpresser": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§7(non-pr.)§r"; + break; + case "cantpress": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§r(can't press)§r"; + break; + default: + return false; + } + return true; + } + /*if(args[0].toLowerCase()=="reload") + DoReload(null); //2015.07.20.*/ + else if(args.length>0 && args[0].toLowerCase().equals("admin")) //2015.08.09. + { + DoAdmin(null, args); //2015.08.09. + return true; //2015.08.09. + } + return false; + } + private static void DoReload(Player player) + { //2015.07.20. + //if(player==null || player.isOp() || player.getName()=="NorbiPeti") + //{ + try + { + File file=new File("autoflairconfig.txt"); + if(file.exists()) + { + PluginMain.LoadFiles(true); //2015.08.09. + for(Player p : PluginMain.GetPlayers()) + { + MaybeOfflinePlayer mp = MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName()); + if(mp.Flair!=null) + { + String flair=mp.Flair; + PluginMain.RemovePlayerDisplayFlairFinal(p, flair); + //PluginMain.AppendPlayerDisplayFlairFinal(p, flair); + PluginMain.AppendPlayerDisplayFlair(mp, p); //2015.08.09. + } + String msg="§6Note: The auto-flair plugin has been reloaded. You might need to wait 10s to have your flair.§r"; //2015.08.09. + p.sendMessage(msg); //2015.08.09. + } + //String msg="§6Reloaded config file.§r"; + //SendMessage(player, msg); //2015.08.09. + } + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + if(player!=null) + player.sendMessage("§cAn error occured. See console for details.§r"); + PluginMain.LastException=e; //2015.08.09. + } + //} + //else + //player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static Player ReloadPlayer; //2015.08.09. + private static void DoAdmin(Player player, String[] args) + { //2015.08.09. + if(player==null || player.isOp() || player.getName()=="NorbiPeti") + { + //System.out.println("Args length: " + args.length); + if(args.length==1) + { + String message="§cUsage: /u admin reload|playerinfo§r"; + SendMessage(player, message); + return; + } + //args[0] is "admin" + switch(args[1].toLowerCase()) + { + case "reload": + ReloadPlayer=player; //2015.08.09. + SendMessage(player, "§6Make sure to save the current settings before you modify and reload them! Type /u admin confirm when done.§r"); + break; + case "playerinfo": + DoPlayerInfo(player, args); + break; + case "getlasterror": + DoGetLastError(player, args); + case "confirm": + if(ReloadPlayer==player) + DoReload(player); //2015.08.09. + else + SendMessage(player, "§cYou need to do /u admin reload first.§r"); + break; + case "save": + PluginMain.SaveFiles(); //2015.08.09. + SendMessage(player, "§6Saved files. Now you can edit them and reload if you want.§r"); + break; + default: + String message="§cUsage: /u admin reload|playerinfo|getlasterror§r"; + SendMessage(player, message); + return; + } + } + else + player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static void DoPlayerInfo(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "playerinfo" + if(args.length==2) + { + String message="§cUsage: /u admin playerinfo §r"; + SendMessage(player, message); + return; + } + if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2])) + { + String message="§cPlayer not found: "+args[2]+"§r"; + SendMessage(player, message); + return; + } + MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]); + SendMessage(player, "Player name: "+p.PlayerName); + SendMessage(player, "User flair: "+p.Flair); + SendMessage(player, "Username: "+p.UserName); + SendMessage(player, "Flair accepted: "+p.AcceptedFlair); + SendMessage(player, "Flair ignored: "+p.IgnoredFlair); + } + public static void SendMessage(Player player, String message) + { //2015.08.09. + if(player==null) + System.out.println(message); + else + player.sendMessage(message); + } + private static void DoGetLastError(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "getlasterror" + if(PluginMain.LastException!=null) + { + SendMessage(player, "Last error:"); + SendMessage(player, PluginMain.LastException.toString()); + PluginMain.LastException=null; + } + else + SendMessage(player, "There were no exceptions."); + } + private static void SetPlayerFlair(Player player, String flair) + { //2015.08.09. + flair=flair.replace('&', '§'); + MaybeOfflinePlayer.AddPlayerIfNeeded(player.getName()).Flair=flair; + if(!PluginMain.RemoveLineFromFile("customflairs.txt")) + { + Commands.SendMessage(player, "") + } + File file=new File("customflairs.txt"); + try { + BufferedWriter bw; + bw = new BufferedWriter(new FileWriter(file, true)); + bw.write(player.getName()+"\n"); + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/6e/e0394523853e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/6e/e0394523853e00151ce8ff6d4f74dabd deleted file mode 100644 index bf1b322..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/6e/e0394523853e00151ce8ff6d4f74dabd +++ /dev/null @@ -1,122 +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; - MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. - //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - if(p.Flair==null) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. - { - case "accept": - { - if(p.IgnoredFlair) - p.IgnoredFlair=false; //2015.08.08. - if(!p.AcceptedFlair) - { - String flair=p.Flair; //2015.08.08. - PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. - p.AcceptedFlair=true; //2015.08.08. - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("§cYou already have this user's flair.§r"); - break; - } - case "ignore": - { - if(p.AcceptedFlair) - p.AcceptedFlair=false; //2015.08.08. - if(!p.IgnoredFlair) - { - p.IgnoredFlair=true; - String flair=p.Flair; //2015.08.08. - PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. - player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); - } - else - player.sendMessage("§cYou already ignored this request.§r"); - break; - } - case "reload": //2015.07.20. - DoReload(player); - break; - case "showerrors": //2015.08.09. - DoShowErrors(player); - break; - default: - return false; - } - return true; - } - - if(args[0].toLowerCase()=="reload") - DoReload(null); //2015.07.20. - else if(args[0].toLowerCase()=="showerrors") - DoShowErrors(null); //2015.08.09. - return false; - } - private static void DoReload(Player player) - { //2015.07.20. - if(player==null || player.isOp() || player.getName()=="NorbiPeti") - { - try - { - File file=new File("autoflairconfig.txt"); - if(file.exists()) - { - PluginMain.TownColors.clear(); - BufferedReader br=new BufferedReader(new FileReader(file)); - String line; - while((line=br.readLine())!=null) - { - String[] s=line.split(" "); - PluginMain.TownColors.put(s[0], s[1]); - } - br.close(); - for(Player p : PluginMain.GetPlayers()) - { - MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName()); - if(mp.Flair!=null) - { - String flair=mp.Flair; - PluginMain.RemovePlayerDisplayFlairFinal(p, flair); - PluginMain.AppendPlayerDisplayFlairFinal(p, flair); - } - } - String msg="§6Reloaded config file.§r"; - if(player!=null) - player.sendMessage(msg); - else - System.out.println(msg); - } - } - catch(Exception e) - { - System.out.println("Error!\n"+e); - if(player!=null) - player.sendMessage("§cAn error occured. See console for details.§r"); - } - } - else - player.sendMessage("§cYou need to be OP to use this command.§r"); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/6f/004f0f0ae03e001517108d149b613203 b/.metadata/.plugins/org.eclipse.core.resources/.history/6f/004f0f0ae03e001517108d149b613203 new file mode 100644 index 0000000..b0c7144 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/6f/004f0f0ae03e001517108d149b613203 @@ -0,0 +1,259 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +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; + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. + //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) + if(p.Flair==null) + { + player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); + return true; + } + switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. + { + case "accept": + { + if(p.IgnoredFlair) + p.IgnoredFlair=false; //2015.08.08. + if(!p.AcceptedFlair) + { + String flair=p.Flair; //2015.08.08. + //PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + PluginMain.AppendPlayerDisplayFlair(p, player); + p.AcceptedFlair=true; //2015.08.08. + player.sendMessage("§6Your flair has been set:§r "+flair); + } + else + player.sendMessage("§cYou already have this user's flair.§r"); + break; + } + case "ignore": + { + if(p.AcceptedFlair) + p.AcceptedFlair=false; //2015.08.08. + if(!p.IgnoredFlair) + { + p.IgnoredFlair=true; + String flair=p.Flair; //2015.08.08. + PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. + player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); + } + else + player.sendMessage("§cYou already ignored this request.§r"); + break; + } + /*case "reload": //2015.07.20. + DoReload(player); + break;*/ + case "admin": //2015.08.09. + DoAdmin(player, args); + break; + case "nonpresser": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§7(non-pr.)§r"; + break; + case "cantpress": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§r(can't press)§r"; + break; + default: + return false; + } + return true; + } + /*if(args[0].toLowerCase()=="reload") + DoReload(null); //2015.07.20.*/ + else if(args.length>0 && args[0].toLowerCase().equals("admin")) //2015.08.09. + { + DoAdmin(null, args); //2015.08.09. + return true; //2015.08.09. + } + return false; + } + private static void DoReload(Player player) + { //2015.07.20. + //if(player==null || player.isOp() || player.getName()=="NorbiPeti") + //{ + try + { + File file=new File("autoflairconfig.txt"); + if(file.exists()) + { + PluginMain.LoadFiles(true); //2015.08.09. + for(Player p : PluginMain.GetPlayers()) + { + MaybeOfflinePlayer mp = MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName()); + if(mp.Flair!=null) + { + String flair=mp.Flair; + PluginMain.RemovePlayerDisplayFlairFinal(p, flair); + //PluginMain.AppendPlayerDisplayFlairFinal(p, flair); + PluginMain.AppendPlayerDisplayFlair(mp, p); //2015.08.09. + } + String msg="§6Note: The auto-flair plugin has been reloaded. You might need to wait 10s to have your flair.§r"; //2015.08.09. + p.sendMessage(msg); //2015.08.09. + } + //String msg="§6Reloaded config file.§r"; + //SendMessage(player, msg); //2015.08.09. + } + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + if(player!=null) + player.sendMessage("§cAn error occured. See console for details.§r"); + PluginMain.LastException=e; //2015.08.09. + } + //} + //else + //player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static Player ReloadPlayer; //2015.08.09. + private static void DoAdmin(Player player, String[] args) + { //2015.08.09. + if(player==null || player.isOp() || player.getName()=="NorbiPeti") + { + //System.out.println("Args length: " + args.length); + if(args.length==1) + { + String message="§cUsage: /u admin reload|playerinfo§r"; + SendMessage(player, message); + return; + } + //args[0] is "admin" + switch(args[1].toLowerCase()) + { + case "reload": + ReloadPlayer=player; //2015.08.09. + SendMessage(player, "§6Make sure to save the current settings before you modify and reload them! Type /u admin confirm when done.§r"); + break; + case "playerinfo": + DoPlayerInfo(player, args); + break; + case "getlasterror": + DoGetLastError(player, args); + case "confirm": + if(ReloadPlayer==player) + DoReload(player); //2015.08.09. + else + SendMessage(player, "§cYou need to do /u admin reload first.§r"); + break; + case "save": + PluginMain.SaveFiles(); //2015.08.09. + SendMessage(player, "§6Saved files. Now you can edit them and reload if you want.§r"); + break; + case "setflair": + + break; + default: + String message="§cUsage: /u admin reload|playerinfo|getlasterror|save§r"; + SendMessage(player, message); + return; + } + } + else + player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static void DoPlayerInfo(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "playerinfo" + if(args.length==2) + { + String message="§cUsage: /u admin playerinfo §r"; + SendMessage(player, message); + return; + } + if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2])) + { + String message="§cPlayer not found: "+args[2]+"§r"; + SendMessage(player, message); + return; + } + MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]); + SendMessage(player, "Player name: "+p.PlayerName); + SendMessage(player, "User flair: "+p.Flair); + SendMessage(player, "Username: "+p.UserName); + SendMessage(player, "Flair accepted: "+p.AcceptedFlair); + SendMessage(player, "Flair ignored: "+p.IgnoredFlair); + } + private static void SendMessage(Player player, String message) + { //2015.08.09. + if(player==null) + System.out.println(message); + else + player.sendMessage(message); + } + private static void DoGetLastError(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "getlasterror" + if(PluginMain.LastException!=null) + { + SendMessage(player, "Last error:"); + SendMessage(player, PluginMain.LastException.toString()); + PluginMain.LastException=null; + } + else + SendMessage(player, "There were no exceptions."); + } + private static void SetPlayerFlair(Player player, Player targetplayer, String flair) + { //2015.08.09. + flair=flair.replace('&', '§'); + MaybeOfflinePlayer.AddPlayerIfNeeded(player.getName()).Flair=flair; + if(!PluginMain.RemoveLineFromFile("customflairs.txt", targetplayer.getName())) + { + SendMessage(player, "§cError removing previous custom flair!§r"); + return; + } + File file=new File("customflairs.txt"); + try { + BufferedWriter bw; + bw = new BufferedWriter(new FileWriter(file, true)); + bw.write(targetplayer.getName()+"\n"); + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + PluginMain.LastException=e; //2015.08.09. + } + SendMessage(player, "§6The flair has been set. Player: "+targetplayer.getName()+" Flair: "+flair+"§r"); + } + private static void DoSetFlair(Player player, String args) + { + //args[0] is "admin" - args[1] is "playerinfo" + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/6f/308fe70ed93e001517108d149b613203 b/.metadata/.plugins/org.eclipse.core.resources/.history/6f/308fe70ed93e001517108d149b613203 new file mode 100644 index 0000000..c2af90a --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/6f/308fe70ed93e001517108d149b613203 @@ -0,0 +1,227 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; + +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class Commands implements CommandExecutor { + // This method is called, when somebody uses our command + @Override + public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { + if (sender instanceof Player) { + Player player = (Player) sender; + if(args.length<1) + return false; + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. + //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) + if(p.Flair==null) + { + player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); + return true; + } + switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. + { + case "accept": + { + if(p.IgnoredFlair) + p.IgnoredFlair=false; //2015.08.08. + if(!p.AcceptedFlair) + { + String flair=p.Flair; //2015.08.08. + //PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + PluginMain.AppendPlayerDisplayFlair(p, player); + p.AcceptedFlair=true; //2015.08.08. + player.sendMessage("§6Your flair has been set:§r "+flair); + } + else + player.sendMessage("§cYou already have this user's flair.§r"); + break; + } + case "ignore": + { + if(p.AcceptedFlair) + p.AcceptedFlair=false; //2015.08.08. + if(!p.IgnoredFlair) + { + p.IgnoredFlair=true; + String flair=p.Flair; //2015.08.08. + PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. + player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); + } + else + player.sendMessage("§cYou already ignored this request.§r"); + break; + } + /*case "reload": //2015.07.20. + DoReload(player); + break;*/ + case "admin": //2015.08.09. + DoAdmin(player, args); + break; + case "nonpresser": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§7(non-pr.)§r"; + break; + case "cantpress": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§r(can't press)§r"; + break; + default: + return false; + } + return true; + } + /*if(args[0].toLowerCase()=="reload") + DoReload(null); //2015.07.20.*/ + else if(args.length>0 && args[0].toLowerCase().equals("admin")) //2015.08.09. + { + DoAdmin(null, args); //2015.08.09. + return true; //2015.08.09. + } + return false; + } + private static void DoReload(Player player) + { //2015.07.20. + //if(player==null || player.isOp() || player.getName()=="NorbiPeti") + //{ + try + { + File file=new File("autoflairconfig.txt"); + if(file.exists()) + { + PluginMain.LoadFiles(true); //2015.08.09. + for(Player p : PluginMain.GetPlayers()) + { + MaybeOfflinePlayer mp = MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName()); + if(mp.Flair!=null) + { + String flair=mp.Flair; + PluginMain.RemovePlayerDisplayFlairFinal(p, flair); + //PluginMain.AppendPlayerDisplayFlairFinal(p, flair); + PluginMain.AppendPlayerDisplayFlair(mp, p); //2015.08.09. + } + String msg="§6Note: The auto-flair plugin has been reloaded. You might need to wait 10s to have your flair.§r"; //2015.08.09. + p.sendMessage(msg); //2015.08.09. + } + //String msg="§6Reloaded config file.§r"; + //SendMessage(player, msg); //2015.08.09. + } + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + if(player!=null) + player.sendMessage("§cAn error occured. See console for details.§r"); + PluginMain.LastException=e; //2015.08.09. + } + //} + //else + //player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static Player ReloadPlayer; //2015.08.09. + private static void DoAdmin(Player player, String[] args) + { //2015.08.09. + if(player==null || player.isOp() || player.getName()=="NorbiPeti") + { + //System.out.println("Args length: " + args.length); + if(args.length==1) + { + String message="§cUsage: /u admin reload|playerinfo§r"; + SendMessage(player, message); + return; + } + //args[0] is "admin" + switch(args[1].toLowerCase()) + { + case "reload": + ReloadPlayer=player; //2015.08.09. + SendMessage(player, "§6Make sure to save the current settings before you modify and reload them! Type /u admin confirm when done.§r"); + break; + case "playerinfo": + DoPlayerInfo(player, args); + break; + case "getlasterror": + DoGetLastError(player, args); + case "confirm": + if(ReloadPlayer!=null && ReloadPlayer.equals(player)) + DoReload(player); //2015.08.09. + else + SendMessage(player, "§cYou need to do /u admin reload first.§r"); + break; + case "save": + + break; + default: + String message="§cUsage: /u admin reload|playerinfo|getlasterror§r"; + SendMessage(player, message); + return; + } + } + else + player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static void DoPlayerInfo(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "playerinfo" + if(args.length==2) + { + String message="§cUsage: /u admin playerinfo §r"; + SendMessage(player, message); + return; + } + if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2])) + { + String message="§cPlayer not found: "+args[2]+"§r"; + SendMessage(player, message); + return; + } + MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]); + SendMessage(player, "Player name: "+p.PlayerName); + SendMessage(player, "User flair: "+p.Flair); + SendMessage(player, "Username: "+p.UserName); + SendMessage(player, "Flair accepted: "+p.AcceptedFlair); + SendMessage(player, "Flair ignored: "+p.IgnoredFlair); + } + private static void SendMessage(Player player, String message) + { //2015.08.09. + if(player==null) + System.out.println(message); + else + player.sendMessage(message); + } + private static void DoGetLastError(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "getlasterror" + if(PluginMain.LastException!=null) + { + SendMessage(player, "Last error:"); + SendMessage(player, PluginMain.LastException.toString()); + PluginMain.LastException=null; + } + else + SendMessage(player, "There were no exceptions."); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/7/d0a7c5c8ce3e001518fa86d7ae2a1cf8 b/.metadata/.plugins/org.eclipse.core.resources/.history/7/d0a7c5c8ce3e001518fa86d7ae2a1cf8 new file mode 100644 index 0000000..752a73d --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/7/d0a7c5c8ce3e001518fa86d7ae2a1cf8 @@ -0,0 +1,361 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStream; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLConnection; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + +import org.apache.commons.io.IOUtils; +import org.bukkit.entity.Player; +import org.bukkit.plugin.java.JavaPlugin; +import org.json.JSONArray; +import org.json.JSONObject; + +import tk.sznp.thebuttonautoflair.MaybeOfflinePlayer.FlairClassType; + +import com.palmergames.bukkit.towny.object.Town; +import com.palmergames.bukkit.towny.object.WorldCoord; + +public class PluginMain extends JavaPlugin +{ //Translated to Java: 2015.07.15. + //A user, which flair isn't obtainable: + //https://www.reddit.com/r/thebutton/comments/31c32v/i_pressed_the_button_without_really_thinking/ + private static PluginMain Instance; + // Fired when plugin is first enabled + @Override + public void onEnable() + { + System.out.println("The Button Auto-flair Plugin by NorbiPeti (:P)"); + getServer().getPluginManager().registerEvents(new PlayerListener(), this); + this.getCommand("u").setExecutor(new Commands()); + this.getCommand("u").setUsage(this.getCommand("u").getUsage().replace('&', '§')); + Instance=this; //2015.08.08. + try { + File file=new File("flairsaccepted.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + //System.out.println("Name: " + name); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("flairsignored.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsignored.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("autoflairconfig.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + TownColors.put(s[0], s[1]); + } + br.close(); + } + //throw new IOException("Test"); //2015.08.09. + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + Runnable r=new Runnable(){public void run(){ThreadMethod();}}; + Thread t=new Thread(r); + t.start(); + } + Boolean stop=false; + // Fired when plugin is disabled + @Override + public void onDisable() + { + try + { + FileWriter fw; + fw = new FileWriter("flairsaccepted.txt"); + fw.close(); + fw = new FileWriter("flairsignored.txt"); + fw.close(); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + try { + File file=new File("flairsaccepted.txt"); + BufferedWriter bw=new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.AcceptedFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + file=new File("flairsignored.txt"); + bw = new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.IgnoredFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + stop=true; + } + + public void ThreadMethod() //<-- 2015.07.16. + { + while(!stop) + { + try + { + String body=DownloadString("https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/autoflair_system_comment_your_minecraft_name_and/.json?limit=1000"); + JSONArray json=new JSONArray(body).getJSONObject(1).getJSONObject("data").getJSONArray("children"); + for(Object obj : json) + { + JSONObject item = (JSONObject)obj; + String author=item.getJSONObject("data").getString("author"); + String ign=item.getJSONObject("data").getString("body"); + int start = ign.indexOf("IGN:") + "IGN:".length(); + int end = ign.indexOf(' ', start); + if (end == -1 || end == start) + end=ign.indexOf('\n', start); //2015.07.15. + if (end == -1 || end == start) + ign = ign.substring(start); + else + ign = ign.substring(start, end); + ign = ign.trim(); + if(HasIGFlair(ign)) + continue; + try { + Thread.sleep(10); + } catch(InterruptedException ex) { + Thread.currentThread().interrupt(); + } + String[] flairdata = DownloadString("http://karmadecay.com/thebutton-data.php?users=" + author).replace("\"", "").split(":"); + String flair; + if(flairdata.length > 1) //2015.07.15. + flair = flairdata[1]; + else + flair=""; + if (flair != "-1") + flair = flair + "s"; + else + flair = "non-presser"; + String flairclass; + if(flairdata.length>2) + flairclass = flairdata[2]; + else + flairclass="unknown"; + SetFlair(ign, flair, flairclass, author); + } + Thread.sleep(10000); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + } + + public static Exception LastException; //2015.08.09. + + public String DownloadString(String urlstr) throws MalformedURLException, IOException + { + URL url = new URL(urlstr); + URLConnection con = url.openConnection(); + con.setRequestProperty("User-Agent", "TheButtonAutoFlair"); + InputStream in = con.getInputStream(); + String encoding = con.getContentEncoding(); + encoding = encoding == null ? "UTF-8" : encoding; + String body = IOUtils.toString(in, encoding); + in.close(); + return body; + } + + public static Map TownColors=new HashMap(); //2015.07.20. + public Boolean HasIGFlair(String playername) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + return p.Flair!=null; //2015.08.08. + } + + public void SetFlair(String playername, String text, String flairclass, String username) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + String finalflair; + p.FlairDecided=true; + switch(flairclass) + { + case "press-1": + finalflair="§c("+text+")§r"; + break; + case "press-2": + finalflair="§6("+text+")§r"; + break; + case "press-3": + finalflair="§e("+text+")§r"; + break; + case "press-4": + finalflair="§a("+text+")§r"; + break; + case "press-5": + finalflair="§9("+text+")§r"; + break; + 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; + case "undecided": //2015.08.09. + p.FlairDecided=false; + finalflair=""; + break; + default: + finalflair=""; + break; + } + if(finalflair.length()==0) //<-- 2015.07.20. + return; + p.Flair=finalflair; //2015.08.08. + p.UserName=username; //2015.08.08. + System.out.println("Added new flair to "+playername+": "+finalflair); + for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08. + { + if(player.getName().equals(playername)) + { + AppendPlayerDisplayFlair(player, username, finalflair); + break; + } + } + } + + public static String GetFlair(Player player) + { //2015.07.16. + String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08. + return flair==null ? "" : flair; + } + + public static void AppendPlayerDisplayFlair(Player player, String username, String flair) + { + if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).IgnoredFlair) + return; + if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).AcceptedFlair) + { + AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + + } + else + player.sendMessage("§9Are you Reddit user "+username+"?§r §6Type /u accept or /u ignore§r"); + } + + private static void AppendPlayerDisplayFlairFinal(Player player, String flair) + { //2015.07.20. + String color = GetColorForTown(GetPlayerTown(player)); //TO!DO: Multiple colors put on first capital letters + String[] colors = color.substring(1).split("§"); + String displayname=player.getName(); //2015.08.08. + ArrayList Positions=new ArrayList<>(); + for(int i=0; i=colors.length) + { + int x=0; + for(int i=0; i GetPlayers() + { + return Instance.getServer().getOnlinePlayers(); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/70/90557930e13e001517108d149b613203 b/.metadata/.plugins/org.eclipse.core.resources/.history/70/90557930e13e001517108d149b613203 new file mode 100644 index 0000000..e7f90ce --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/70/90557930e13e001517108d149b613203 @@ -0,0 +1,265 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +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; + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. + //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) + if(p.Flair==null) + { + player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); + return true; + } + switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. + { + case "accept": + { + if(p.IgnoredFlair) + p.IgnoredFlair=false; //2015.08.08. + if(!p.AcceptedFlair) + { + String flair=p.Flair; //2015.08.08. + //PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + PluginMain.AppendPlayerDisplayFlair(p, player); + p.AcceptedFlair=true; //2015.08.08. + player.sendMessage("§6Your flair has been set:§r "+flair); + } + else + player.sendMessage("§cYou already have this user's flair.§r"); + break; + } + case "ignore": + { + if(p.AcceptedFlair) + p.AcceptedFlair=false; //2015.08.08. + if(!p.IgnoredFlair) + { + p.IgnoredFlair=true; + String flair=p.Flair; //2015.08.08. + PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. + player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); + } + else + player.sendMessage("§cYou already ignored this request.§r"); + break; + } + /*case "reload": //2015.07.20. + DoReload(player); + break;*/ + case "admin": //2015.08.09. + DoAdmin(player, args); + break; + case "nonpresser": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§7(non-pr.)§r"; + break; + case "cantpress": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§r(can't press)§r"; + break; + default: + return false; + } + return true; + } + /*if(args[0].toLowerCase()=="reload") + DoReload(null); //2015.07.20.*/ + else if(args.length>0 && args[0].toLowerCase().equals("admin")) //2015.08.09. + { + DoAdmin(null, args); //2015.08.09. + return true; //2015.08.09. + } + return false; + } + private static void DoReload(Player player) + { //2015.07.20. + //if(player==null || player.isOp() || player.getName()=="NorbiPeti") + //{ + try + { + File file=new File("autoflairconfig.txt"); + if(file.exists()) + { + PluginMain.LoadFiles(true); //2015.08.09. + for(Player p : PluginMain.GetPlayers()) + { + MaybeOfflinePlayer mp = MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName()); + if(mp.Flair!=null) + { + String flair=mp.Flair; + PluginMain.RemovePlayerDisplayFlairFinal(p, flair); + //PluginMain.AppendPlayerDisplayFlairFinal(p, flair); + PluginMain.AppendPlayerDisplayFlair(mp, p); //2015.08.09. + } + String msg="§6Note: The auto-flair plugin has been reloaded. You might need to wait 10s to have your flair.§r"; //2015.08.09. + p.sendMessage(msg); //2015.08.09. + } + //String msg="§6Reloaded config file.§r"; + //SendMessage(player, msg); //2015.08.09. + } + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + if(player!=null) + player.sendMessage("§cAn error occured. See console for details.§r"); + PluginMain.LastException=e; //2015.08.09. + } + //} + //else + //player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static Player ReloadPlayer; //2015.08.09. + private static void DoAdmin(Player player, String[] args) + { //2015.08.09. + if(player==null || player.isOp() || player.getName()=="NorbiPeti") + { + //System.out.println("Args length: " + args.length); + if(args.length==1) + { + String message="§cUsage: /u admin reload|playerinfo§r"; + SendMessage(player, message); + return; + } + //args[0] is "admin" + switch(args[1].toLowerCase()) + { + case "reload": + ReloadPlayer=player; //2015.08.09. + SendMessage(player, "§6Make sure to save the current settings before you modify and reload them! Type /u admin confirm when done.§r"); + break; + case "playerinfo": + DoPlayerInfo(player, args); + break; + case "getlasterror": + DoGetLastError(player, args); + case "confirm": //2015.08.09. + if(ReloadPlayer==player) + DoReload(player); //2015.08.09. + else + SendMessage(player, "§cYou need to do /u admin reload first.§r"); + break; + case "save": //2015.08.09. + PluginMain.SaveFiles(); //2015.08.09. + SendMessage(player, "§6Saved files. Now you can edit them and reload if you want.§r"); + break; + case "setflair": //2015.08.09. + DoSetFlair(player, args); + break; + default: + String message="§cUsage: /u admin reload|playerinfo|getlasterror|save§r"; + SendMessage(player, message); + return; + } + } + else + player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static void DoPlayerInfo(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "playerinfo" + if(args.length==2) + { + String message="§cUsage: /u admin playerinfo §r"; + SendMessage(player, message); + return; + } + if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2])) + { + String message="§cPlayer not found: "+args[2]+"§r"; + SendMessage(player, message); + return; + } + MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]); + SendMessage(player, "Player name: "+p.PlayerName); + SendMessage(player, "User flair: "+p.Flair); + SendMessage(player, "Username: "+p.UserName); + SendMessage(player, "Flair accepted: "+p.AcceptedFlair); + SendMessage(player, "Flair ignored: "+p.IgnoredFlair); + } + private static void SendMessage(Player player, String message) + { //2015.08.09. + if(player==null) + System.out.println(message); + else + player.sendMessage(message); + } + private static void DoGetLastError(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "getlasterror" + if(PluginMain.LastException!=null) + { + SendMessage(player, "Last error:"); + SendMessage(player, PluginMain.LastException.toString()); + PluginMain.LastException=null; + } + else + SendMessage(player, "There were no exceptions."); + } + private static void SetPlayerFlair(Player player, MaybeOfflinePlayer targetplayer, String flair) + { //2015.08.09. + flair=flair.replace('&', '§'); + targetplayer.Flair=flair; + if(!PluginMain.RemoveLineFromFile("customflairs.txt", targetplayer.PlayerName)) + { + SendMessage(player, "§cError removing previous custom flair!§r"); + return; + } + File file=new File("customflairs.txt"); + try { + BufferedWriter bw; + bw = new BufferedWriter(new FileWriter(file, true)); + bw.write(targetplayer.PlayerName+"\n"); + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + PluginMain.LastException=e; //2015.08.09. + } + SendMessage(player, "§6The flair has been set. Player: "+targetplayer.PlayerName+" Flair: "+flair+"§r"); + } + private static void DoSetFlair(Player player, String[] args) + { + //args[0] is "admin" - args[1] is "setflair" + if(args.length<4) + { + SendMessage(player, "§cUsage: /u admin setflair "); + return; + } + SetPlayerFlair(player, MaybeOfflinePlayer.AddPlayerIfNeeded(args[2]), args[3]); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/71/b09765e7d13e001518fa86d7ae2a1cf8 b/.metadata/.plugins/org.eclipse.core.resources/.history/71/b09765e7d13e001518fa86d7ae2a1cf8 new file mode 100644 index 0000000..738511a --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/71/b09765e7d13e001518fa86d7ae2a1cf8 @@ -0,0 +1,373 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStream; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLConnection; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + +import org.apache.commons.io.IOUtils; +import org.bukkit.entity.Player; +import org.bukkit.plugin.java.JavaPlugin; +import org.json.JSONArray; +import org.json.JSONObject; + +import com.palmergames.bukkit.towny.object.Town; +import com.palmergames.bukkit.towny.object.WorldCoord; + +public class PluginMain extends JavaPlugin +{ //Translated to Java: 2015.07.15. + //A user, which flair isn't obtainable: + //https://www.reddit.com/r/thebutton/comments/31c32v/i_pressed_the_button_without_really_thinking/ + private static PluginMain Instance; + // Fired when plugin is first enabled + @Override + public void onEnable() + { + System.out.println("The Button Auto-flair Plugin by NorbiPeti (:P)"); + getServer().getPluginManager().registerEvents(new PlayerListener(), this); + this.getCommand("u").setExecutor(new Commands()); + this.getCommand("u").setUsage(this.getCommand("u").getUsage().replace('&', '§')); + Instance=this; //2015.08.08. + LoadFiles(false); //2015.08.09. + Runnable r=new Runnable(){public void run(){ThreadMethod();}}; + Thread t=new Thread(r); + t.start(); + } + Boolean stop=false; + // Fired when plugin is disabled + @Override + public void onDisable() + { + try + { + FileWriter fw; + fw = new FileWriter("flairsaccepted.txt"); + fw.close(); + fw = new FileWriter("flairsignored.txt"); + fw.close(); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + try { + File file=new File("flairsaccepted.txt"); + BufferedWriter bw=new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.AcceptedFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + file=new File("flairsignored.txt"); + bw = new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.IgnoredFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + stop=true; + } + + public void ThreadMethod() //<-- 2015.07.16. + { + while(!stop) + { + try + { + String body=DownloadString("https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/autoflair_system_comment_your_minecraft_name_and/.json?limit=1000"); + JSONArray json=new JSONArray(body).getJSONObject(1).getJSONObject("data").getJSONArray("children"); + for(Object obj : json) + { + JSONObject item = (JSONObject)obj; + String author=item.getJSONObject("data").getString("author"); + String ign=item.getJSONObject("data").getString("body"); + int start = ign.indexOf("IGN:") + "IGN:".length(); + int end = ign.indexOf(' ', start); + if (end == -1 || end == start) + end=ign.indexOf('\n', start); //2015.07.15. + if (end == -1 || end == start) + ign = ign.substring(start); + else + ign = ign.substring(start, end); + ign = ign.trim(); + if(HasIGFlair(ign)) + continue; + try { + Thread.sleep(10); + } catch(InterruptedException ex) { + Thread.currentThread().interrupt(); + } + String[] flairdata = DownloadString("http://karmadecay.com/thebutton-data.php?users=" + author).replace("\"", "").split(":"); + String flair; + if(flairdata.length > 1) //2015.07.15. + flair = flairdata[1]; + else + flair=""; + if (flair != "-1") + flair = flair + "s"; + else + flair = "non-presser"; + String flairclass; + if(flairdata.length>2) + flairclass = flairdata[2]; + else + flairclass="unknown"; + SetFlair(ign, flair, flairclass, author); + } + Thread.sleep(10000); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + } + + public static Exception LastException; //2015.08.09. + + public String DownloadString(String urlstr) throws MalformedURLException, IOException + { + URL url = new URL(urlstr); + URLConnection con = url.openConnection(); + con.setRequestProperty("User-Agent", "TheButtonAutoFlair"); + InputStream in = con.getInputStream(); + String encoding = con.getContentEncoding(); + encoding = encoding == null ? "UTF-8" : encoding; + String body = IOUtils.toString(in, encoding); + in.close(); + return body; + } + + public static Map TownColors=new HashMap(); //2015.07.20. + public Boolean HasIGFlair(String playername) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + return p.Flair!=null; //2015.08.08. + } + + public void SetFlair(String playername, String text, String flairclass, String username) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + String finalflair; + p.FlairDecided=true; + switch(flairclass) + { + case "press-1": + finalflair="§c("+text+")§r"; + break; + case "press-2": + finalflair="§6("+text+")§r"; + break; + case "press-3": + finalflair="§e("+text+")§r"; + break; + case "press-4": + finalflair="§a("+text+")§r"; + break; + case "press-5": + finalflair="§9("+text+")§r"; + break; + 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; + case "undecided": //2015.08.09. + p.FlairDecided=false; + finalflair=""; + break; + default: + finalflair=""; + break; + } + if(finalflair.length()==0) //<-- 2015.07.20. + return; + p.Flair=finalflair; //2015.08.08. + p.UserName=username; //2015.08.08. + System.out.println("Added new flair to "+playername+": "+finalflair); + for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08. + { + if(player.getName().equals(playername)) + { + //AppendPlayerDisplayFlair(player, username, finalflair); + AppendPlayerDisplayFlair(p, player); + break; + } + } + } + + public static String GetFlair(Player player) + { //2015.07.16. + String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08. + return flair==null ? "" : flair; + } + + //public static void AppendPlayerDisplayFlair(Player player, String username, String flair) + public static void AppendPlayerDisplayFlair(MaybeOfflinePlayer player, Player p) //<-- 2015.08.09. + { + + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).IgnoredFlair) + return; + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).AcceptedFlair) + { + AppendPlayerDisplayFlairFinal(p, player.Flair); //2015.07.20. + if(!player.FlairDecided) + p.sendMessage("§9Your flair type is unknown. Are you a non-presser or a can't press? (/u nonpresser or /u cantpress)§r"); //2015.08.09. + } + else + p.sendMessage("§9Are you Reddit user "+player.UserName+"?§r §6Type /u accept or /u ignore§r"); + } + + private static void AppendPlayerDisplayFlairFinal(Player player, String flair) + { //2015.07.20. + String color = GetColorForTown(GetPlayerTown(player)); //TO!DO: Multiple colors put on first capital letters + String[] colors = color.substring(1).split("§"); + String displayname=player.getName(); //2015.08.08. + ArrayList Positions=new ArrayList<>(); + for(int i=0; i=colors.length) + { + int x=0; + for(int i=0; i GetPlayers() + { + return Instance.getServer().getOnlinePlayers(); + } + + public static void LoadFiles(boolean reload) //<-- 2015.08.09. + { + if(reload) + { + MaybeOfflinePlayer.AllPlayers.clear(); //2015.08.09. + } + System.out.println("Loading files for auto-flair plugin..."); //2015.08.09. + try { + File file=new File("flairsaccepted.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + //System.out.println("Name: " + name); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("flairsignored.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsignored.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("autoflairconfig.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + TownColors.put(s[0], s[1]); + } + br.close(); + } + //throw new IOException("Test"); //2015.08.09. + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/71/c0147a73043e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/71/c0147a73043e00151c31fb33fff4337f deleted file mode 100644 index 87c0c13..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/71/c0147a73043e00151c31fb33fff4337f +++ /dev/null @@ -1,126 +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; - 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/72/60069e3b863e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/72/60069e3b863e00151ce8ff6d4f74dabd deleted file mode 100644 index 2b45c26..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/72/60069e3b863e00151ce8ff6d4f74dabd +++ /dev/null @@ -1,131 +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; - MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. - //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - if(p.Flair==null) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. - { - case "accept": - { - if(p.IgnoredFlair) - p.IgnoredFlair=false; //2015.08.08. - if(!p.AcceptedFlair) - { - String flair=p.Flair; //2015.08.08. - PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. - p.AcceptedFlair=true; //2015.08.08. - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("§cYou already have this user's flair.§r"); - break; - } - case "ignore": - { - if(p.AcceptedFlair) - p.AcceptedFlair=false; //2015.08.08. - if(!p.IgnoredFlair) - { - p.IgnoredFlair=true; - String flair=p.Flair; //2015.08.08. - PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. - player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); - } - else - player.sendMessage("§cYou already ignored this request.§r"); - break; - } - case "reload": //2015.07.20. - DoReload(player); - break; - case "admin": //2015.08.09. - DoAdmin(player); - break; - default: - return false; - } - return true; - } - - if(args[0].toLowerCase()=="reload") - DoReload(null); //2015.07.20. - else if(args[0].toLowerCase()=="showerrors") - DoShowErrors(null); //2015.08.09. - return false; - } - private static void DoReload(Player player) - { //2015.07.20. - if(player==null || player.isOp() || player.getName()=="NorbiPeti") - { - try - { - File file=new File("autoflairconfig.txt"); - if(file.exists()) - { - PluginMain.TownColors.clear(); - BufferedReader br=new BufferedReader(new FileReader(file)); - String line; - while((line=br.readLine())!=null) - { - String[] s=line.split(" "); - PluginMain.TownColors.put(s[0], s[1]); - } - br.close(); - for(Player p : PluginMain.GetPlayers()) - { - MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName()); - if(mp.Flair!=null) - { - String flair=mp.Flair; - PluginMain.RemovePlayerDisplayFlairFinal(p, flair); - PluginMain.AppendPlayerDisplayFlairFinal(p, flair); - } - } - String msg="§6Reloaded config file.§r"; - if(player!=null) - player.sendMessage(msg); - else - System.out.println(msg); - } - } - catch(Exception e) - { - System.out.println("Error!\n"+e); - if(player!=null) - player.sendMessage("§cAn error occured. See console for details.§r"); - } - } - else - player.sendMessage("§cYou need to be OP to use this command.§r"); - } - private static void DoAdmin(Player player) - { - if(player==null || player.isOp() || player.getName()=="NorbiPeti") - { - - } - else - player.sendMessage("§cYou need to be OP to use this command.§r"); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/72/601fd2f0013e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/72/601fd2f0013e00151c31fb33fff4337f deleted file mode 100644 index 0f9b45b..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/72/601fd2f0013e00151c31fb33fff4337f +++ /dev/null @@ -1,124 +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": - { - 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/72/6080d12b893e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/72/6080d12b893e00151ce8ff6d4f74dabd deleted file mode 100644 index 9d9d757..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/72/6080d12b893e00151ce8ff6d4f74dabd +++ /dev/null @@ -1,168 +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; - MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. - //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - if(p.Flair==null) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. - { - case "accept": - { - if(p.IgnoredFlair) - p.IgnoredFlair=false; //2015.08.08. - if(!p.AcceptedFlair) - { - String flair=p.Flair; //2015.08.08. - PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. - p.AcceptedFlair=true; //2015.08.08. - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("§cYou already have this user's flair.§r"); - break; - } - case "ignore": - { - if(p.AcceptedFlair) - p.AcceptedFlair=false; //2015.08.08. - if(!p.IgnoredFlair) - { - p.IgnoredFlair=true; - String flair=p.Flair; //2015.08.08. - PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. - player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); - } - else - player.sendMessage("§cYou already ignored this request.§r"); - break; - } - /*case "reload": //2015.07.20. - DoReload(player); - break;*/ - case "admin": //2015.08.09. - DoAdmin(player, args); - break; - default: - return false; - } - return true; - } - - /*if(args[0].toLowerCase()=="reload") - DoReload(null); //2015.07.20.*/ - else if(args[0].toLowerCase()=="admin") - DoAdmin(null, args); //2015.08.09. - return false; - } - private static void DoReload(Player player) - { //2015.07.20. - //if(player==null || player.isOp() || player.getName()=="NorbiPeti") - //{ - try - { - File file=new File("autoflairconfig.txt"); - if(file.exists()) - { - PluginMain.TownColors.clear(); - BufferedReader br=new BufferedReader(new FileReader(file)); - String line; - while((line=br.readLine())!=null) - { - String[] s=line.split(" "); - PluginMain.TownColors.put(s[0], s[1]); - } - br.close(); - for(Player p : PluginMain.GetPlayers()) - { - MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName()); - if(mp.Flair!=null) - { - String flair=mp.Flair; - PluginMain.RemovePlayerDisplayFlairFinal(p, flair); - PluginMain.AppendPlayerDisplayFlairFinal(p, flair); - } - } - String msg="§6Reloaded config file.§r"; - SendMessage(player, msg); //2015.08.09. - } - } - catch(Exception e) - { - System.out.println("Error!\n"+e); - if(player!=null) - player.sendMessage("§cAn error occured. See console for details.§r"); - } - //} - //else - //player.sendMessage("§cYou need to be OP to use this command.§r"); - } - private static void DoAdmin(Player player, String[] args) - { //2015.08.09. - if(player==null || player.isOp() || player.getName()=="NorbiPeti") - { - if(args.length==1) - { - String message="§cUsage: /u admin reload|playerinfo§r"; - SendMessage(player, message); - return; - } - //args[0] is "admin" - switch(args[1].toLowerCase()) - { - case "reload": - DoReload(player); - break; - case "playerinfo": - DoPlayerInfo(player, args); - break; - } - } - else - player.sendMessage("§cYou need to be OP to use this command.§r"); - } - private static void DoPlayerInfo(Player player, String[] args) - { //2015.08.09. - //args[0] is "admin" - args[1] is "playerinfo" - if(args.length==2) - { - String message="§cUsage: /u admin playerinfo §r"; - SendMessage(player, message); - } - if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2])) - { - String message="§cPlayer not found: "+args[2]+"§r"; - SendMessage(player, message); - } - MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]); - SendMessage(player, "User flair: "+p.Flair); - return; - } - private static void SendMessage(Player player, String message) - { //2015.08.09. - if(player==null) - System.out.println(message); - else - player.sendMessage(message); - return; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/73/005a2e08e03e001517108d149b613203 b/.metadata/.plugins/org.eclipse.core.resources/.history/73/005a2e08e03e001517108d149b613203 new file mode 100644 index 0000000..49c6680 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/73/005a2e08e03e001517108d149b613203 @@ -0,0 +1,259 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +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; + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. + //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) + if(p.Flair==null) + { + player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); + return true; + } + switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. + { + case "accept": + { + if(p.IgnoredFlair) + p.IgnoredFlair=false; //2015.08.08. + if(!p.AcceptedFlair) + { + String flair=p.Flair; //2015.08.08. + //PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + PluginMain.AppendPlayerDisplayFlair(p, player); + p.AcceptedFlair=true; //2015.08.08. + player.sendMessage("§6Your flair has been set:§r "+flair); + } + else + player.sendMessage("§cYou already have this user's flair.§r"); + break; + } + case "ignore": + { + if(p.AcceptedFlair) + p.AcceptedFlair=false; //2015.08.08. + if(!p.IgnoredFlair) + { + p.IgnoredFlair=true; + String flair=p.Flair; //2015.08.08. + PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. + player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); + } + else + player.sendMessage("§cYou already ignored this request.§r"); + break; + } + /*case "reload": //2015.07.20. + DoReload(player); + break;*/ + case "admin": //2015.08.09. + DoAdmin(player, args); + break; + case "nonpresser": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§7(non-pr.)§r"; + break; + case "cantpress": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§r(can't press)§r"; + break; + default: + return false; + } + return true; + } + /*if(args[0].toLowerCase()=="reload") + DoReload(null); //2015.07.20.*/ + else if(args.length>0 && args[0].toLowerCase().equals("admin")) //2015.08.09. + { + DoAdmin(null, args); //2015.08.09. + return true; //2015.08.09. + } + return false; + } + private static void DoReload(Player player) + { //2015.07.20. + //if(player==null || player.isOp() || player.getName()=="NorbiPeti") + //{ + try + { + File file=new File("autoflairconfig.txt"); + if(file.exists()) + { + PluginMain.LoadFiles(true); //2015.08.09. + for(Player p : PluginMain.GetPlayers()) + { + MaybeOfflinePlayer mp = MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName()); + if(mp.Flair!=null) + { + String flair=mp.Flair; + PluginMain.RemovePlayerDisplayFlairFinal(p, flair); + //PluginMain.AppendPlayerDisplayFlairFinal(p, flair); + PluginMain.AppendPlayerDisplayFlair(mp, p); //2015.08.09. + } + String msg="§6Note: The auto-flair plugin has been reloaded. You might need to wait 10s to have your flair.§r"; //2015.08.09. + p.sendMessage(msg); //2015.08.09. + } + //String msg="§6Reloaded config file.§r"; + //SendMessage(player, msg); //2015.08.09. + } + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + if(player!=null) + player.sendMessage("§cAn error occured. See console for details.§r"); + PluginMain.LastException=e; //2015.08.09. + } + //} + //else + //player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static Player ReloadPlayer; //2015.08.09. + private static void DoAdmin(Player player, String[] args) + { //2015.08.09. + if(player==null || player.isOp() || player.getName()=="NorbiPeti") + { + //System.out.println("Args length: " + args.length); + if(args.length==1) + { + String message="§cUsage: /u admin reload|playerinfo§r"; + SendMessage(player, message); + return; + } + //args[0] is "admin" + switch(args[1].toLowerCase()) + { + case "reload": + ReloadPlayer=player; //2015.08.09. + SendMessage(player, "§6Make sure to save the current settings before you modify and reload them! Type /u admin confirm when done.§r"); + break; + case "playerinfo": + DoPlayerInfo(player, args); + break; + case "getlasterror": + DoGetLastError(player, args); + case "confirm": + if(ReloadPlayer==player) + DoReload(player); //2015.08.09. + else + SendMessage(player, "§cYou need to do /u admin reload first.§r"); + break; + case "save": + PluginMain.SaveFiles(); //2015.08.09. + SendMessage(player, "§6Saved files. Now you can edit them and reload if you want.§r"); + break; + case "setflair": + + break; + default: + String message="§cUsage: /u admin reload|playerinfo|getlasterror|save§r"; + SendMessage(player, message); + return; + } + } + else + player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static void DoPlayerInfo(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "playerinfo" + if(args.length==2) + { + String message="§cUsage: /u admin playerinfo §r"; + SendMessage(player, message); + return; + } + if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2])) + { + String message="§cPlayer not found: "+args[2]+"§r"; + SendMessage(player, message); + return; + } + MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]); + SendMessage(player, "Player name: "+p.PlayerName); + SendMessage(player, "User flair: "+p.Flair); + SendMessage(player, "Username: "+p.UserName); + SendMessage(player, "Flair accepted: "+p.AcceptedFlair); + SendMessage(player, "Flair ignored: "+p.IgnoredFlair); + } + private static void SendMessage(Player player, String message) + { //2015.08.09. + if(player==null) + System.out.println(message); + else + player.sendMessage(message); + } + private static void DoGetLastError(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "getlasterror" + if(PluginMain.LastException!=null) + { + SendMessage(player, "Last error:"); + SendMessage(player, PluginMain.LastException.toString()); + PluginMain.LastException=null; + } + else + SendMessage(player, "There were no exceptions."); + } + private static void SetPlayerFlair(Player player, Player targetplayer, String flair) + { //2015.08.09. + flair=flair.replace('&', '§'); + MaybeOfflinePlayer.AddPlayerIfNeeded(player.getName()).Flair=flair; + if(!PluginMain.RemoveLineFromFile("customflairs.txt", targetplayer.getName())) + { + SendMessage(player, "§cError removing previous custom flair!§r"); + return; + } + File file=new File("customflairs.txt"); + try { + BufferedWriter bw; + bw = new BufferedWriter(new FileWriter(file, true)); + bw.write(targetplayer.getName()+"\n"); + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + PluginMain.LastException=e; //2015.08.09. + } + SendMessage(player, "§6The flair has been set. Player: "+targetplayer.getName()+" Flair: "+flair+"§r"); + } + private static void DoSetFlair(Player player, String args) + { + + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/73/40821671043e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/73/40821671043e00151c31fb33fff4337f deleted file mode 100644 index 87c0c13..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/73/40821671043e00151c31fb33fff4337f +++ /dev/null @@ -1,126 +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; - 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/50eccfd4e43e001517108d149b613203 b/.metadata/.plugins/org.eclipse.core.resources/.history/73/50eccfd4e43e001517108d149b613203 new file mode 100644 index 0000000..188ed19 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/73/50eccfd4e43e001517108d149b613203 @@ -0,0 +1,421 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStream; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLConnection; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + +import org.apache.commons.io.IOUtils; +import org.bukkit.entity.Player; +import org.bukkit.plugin.java.JavaPlugin; +import org.json.JSONArray; +import org.json.JSONObject; + +import com.palmergames.bukkit.towny.object.Town; +import com.palmergames.bukkit.towny.object.WorldCoord; + +public class PluginMain extends JavaPlugin +{ //Translated to Java: 2015.07.15. + //A user, which flair isn't obtainable: + //https://www.reddit.com/r/thebutton/comments/31c32v/i_pressed_the_button_without_really_thinking/ + private static PluginMain Instance; + // Fired when plugin is first enabled + @Override + public void onEnable() + { + System.out.println("The Button Auto-flair Plugin by NorbiPeti (:P)"); + getServer().getPluginManager().registerEvents(new PlayerListener(), this); + this.getCommand("u").setExecutor(new Commands()); + this.getCommand("u").setUsage(this.getCommand("u").getUsage().replace('&', '§')); + Instance=this; //2015.08.08. + LoadFiles(false); //2015.08.09. + Runnable r=new Runnable(){public void run(){ThreadMethod();}}; + Thread t=new Thread(r); + t.start(); + } + Boolean stop=false; + // Fired when plugin is disabled + @Override + public void onDisable() + { + SaveFiles(); //2015.08.09. + stop=true; + } + + public void ThreadMethod() //<-- 2015.07.16. + { + while(!stop) + { + try + { + String body=DownloadString("https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/autoflair_system_comment_your_minecraft_name_and/.json?limit=1000"); + JSONArray json=new JSONArray(body).getJSONObject(1).getJSONObject("data").getJSONArray("children"); + for(Object obj : json) + { + JSONObject item = (JSONObject)obj; + String author=item.getJSONObject("data").getString("author"); + String ign=item.getJSONObject("data").getString("body"); + int start = ign.indexOf("IGN:") + "IGN:".length(); + if(start==-1) + continue; //2015.08.09. + int end = ign.indexOf(' ', start); + if (end == -1 || end == start) + end=ign.indexOf('\n', start); //2015.07.15. + if (end == -1 || end == start) + ign = ign.substring(start); + else + ign = ign.substring(start, end); + ign = ign.trim(); + if(HasIGFlair(ign)) + continue; + try { + Thread.sleep(10); + } catch(InterruptedException ex) { + Thread.currentThread().interrupt(); + } + String[] flairdata = DownloadString("http://karmadecay.com/thebutton-data.php?users=" + author).replace("\"", "").split(":"); + String flair; + if(flairdata.length > 1) //2015.07.15. + flair = flairdata[1]; + else + flair=""; + if (flair != "-1") + flair = flair + "s"; + else + flair = "non-presser"; + String flairclass; + if(flairdata.length>2) + flairclass = flairdata[2]; + else + flairclass="unknown"; + SetFlair(ign, flair, flairclass, author); + } + Thread.sleep(10000); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + } + + public static Exception LastException; //2015.08.09. + + public String DownloadString(String urlstr) throws MalformedURLException, IOException + { + URL url = new URL(urlstr); + URLConnection con = url.openConnection(); + con.setRequestProperty("User-Agent", "TheButtonAutoFlair"); + InputStream in = con.getInputStream(); + String encoding = con.getContentEncoding(); + encoding = encoding == null ? "UTF-8" : encoding; + String body = IOUtils.toString(in, encoding); + in.close(); + return body; + } + + public static Map TownColors=new HashMap(); //2015.07.20. + public Boolean HasIGFlair(String playername) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + return p.Flair!=null; //2015.08.08. + } + + public void SetFlair(String playername, String text, String flairclass, String username) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + String finalflair; + p.FlairDecided=true; + switch(flairclass) + { + case "press-1": + finalflair="§c("+text+")§r"; + break; + case "press-2": + finalflair="§6("+text+")§r"; + break; + case "press-3": + finalflair="§e("+text+")§r"; + break; + case "press-4": + finalflair="§a("+text+")§r"; + break; + case "press-5": + finalflair="§9("+text+")§r"; + break; + 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; + case "undecided": //2015.08.09. + p.FlairDecided=false; + finalflair=""; + break; + default: + finalflair=""; + break; + } + if(finalflair.length()==0) //<-- 2015.07.20. + return; + p.Flair=finalflair; //2015.08.08. + p.UserName=username; //2015.08.08. + System.out.println("Added new flair to "+playername+": "+finalflair); + for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08. + { + if(player.getName().equals(playername)) + { + //AppendPlayerDisplayFlair(player, username, finalflair); + AppendPlayerDisplayFlair(p, player); + break; + } + } + } + + public static String GetFlair(Player player) + { //2015.07.16. + String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08. + return flair==null ? "" : flair; + } + + //public static void AppendPlayerDisplayFlair(Player player, String username, String flair) + public static void AppendPlayerDisplayFlair(MaybeOfflinePlayer player, Player p) //<-- 2015.08.09. + { + + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).IgnoredFlair) + return; + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).AcceptedFlair) + { + AppendPlayerDisplayFlairFinal(p, player.Flair); //2015.07.20. + if(!player.FlairDecided) + p.sendMessage("§9Your flair type is unknown. Are you a non-presser or a can't press? (/u nonpresser or /u cantpress)§r"); //2015.08.09. + } + else + p.sendMessage("§9Are you Reddit user "+player.UserName+"?§r §6Type /u accept or /u ignore§r"); + } + + private static void AppendPlayerDisplayFlairFinal(Player player, String flair) + { //2015.07.20. + String color = GetColorForTown(GetPlayerTown(player)); //TO!DO: Multiple colors put on first capital letters + String[] colors = color.substring(1).split("§"); + String displayname=player.getName(); //2015.08.08. + ArrayList Positions=new ArrayList<>(); + for(int i=0; i=colors.length) + { + int x=0; + for(int i=0; i GetPlayers() + { + return Instance.getServer().getOnlinePlayers(); + } + + public static void LoadFiles(boolean reload) //<-- 2015.08.09. + { + if(reload) + { //2015.08.09. + System.out.println("Auto-flair plugin cleanup for reloading..."); + MaybeOfflinePlayer.AllPlayers.clear(); + TownColors.clear(); + } + System.out.println("Loading files for auto-flair plugin..."); //2015.08.09. + try { + File file=new File("flairsaccepted.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + //System.out.println("Name: " + name); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("flairsignored.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsignored.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("autoflairconfig.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + TownColors.put(s[0], s[1]); + } + br.close(); + } + file=new File("customflairs.txt"); //2015.08.09. + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + MaybeOfflinePlayer.AddPlayerIfNeeded(s[0]).Flair=s[1]; //2015.08.09. + } + br.close(); + } + //throw new IOException("Test"); //2015.08.09. + System.out.println("Auto-flair plugin loaded files!"); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + public static void SaveFiles() //<-- 2015.08.09. + { + try + { + FileWriter fw; + fw = new FileWriter("flairsaccepted.txt"); + fw.close(); + fw = new FileWriter("flairsignored.txt"); + fw.close(); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + try { + File file=new File("flairsaccepted.txt"); + BufferedWriter bw=new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.AcceptedFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + file=new File("flairsignored.txt"); + bw = new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.IgnoredFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + public static boolean RemoveLineFromFile(String file, String line) + { //2015.08.09. + File inputFile = new File(file); + File tempFile = new File("_temp.txt"); + try { + BufferedReader reader = new BufferedReader(new FileReader(inputFile)); + BufferedWriter writer = new BufferedWriter(new FileWriter(tempFile)); + + String lineToRemove = line; + String currentLine; + + while((currentLine = reader.readLine()) != null) { + // trim newline when comparing with lineToRemove + String trimmedLine = currentLine.trim(); + //if(trimmedLine.equals(lineToRemove)) continue; + if(trimmedLine.contains(lineToRemove)) continue; //2015.08.09. + writer.write(currentLine + System.getProperty("line.separator")); + } + writer.close(); + reader.close(); + return tempFile.renameTo(inputFile); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + return false; + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/73/809dfb8ddd3e001517108d149b613203 b/.metadata/.plugins/org.eclipse.core.resources/.history/73/809dfb8ddd3e001517108d149b613203 new file mode 100644 index 0000000..7349211 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/73/809dfb8ddd3e001517108d149b613203 @@ -0,0 +1,408 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStream; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLConnection; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + +import org.apache.commons.io.IOUtils; +import org.bukkit.entity.Player; +import org.bukkit.plugin.java.JavaPlugin; +import org.json.JSONArray; +import org.json.JSONObject; + +import com.palmergames.bukkit.towny.object.Town; +import com.palmergames.bukkit.towny.object.WorldCoord; + +public class PluginMain extends JavaPlugin +{ //Translated to Java: 2015.07.15. + //A user, which flair isn't obtainable: + //https://www.reddit.com/r/thebutton/comments/31c32v/i_pressed_the_button_without_really_thinking/ + private static PluginMain Instance; + // Fired when plugin is first enabled + @Override + public void onEnable() + { + System.out.println("The Button Auto-flair Plugin by NorbiPeti (:P)"); + getServer().getPluginManager().registerEvents(new PlayerListener(), this); + this.getCommand("u").setExecutor(new Commands()); + this.getCommand("u").setUsage(this.getCommand("u").getUsage().replace('&', '§')); + Instance=this; //2015.08.08. + LoadFiles(false); //2015.08.09. + Runnable r=new Runnable(){public void run(){ThreadMethod();}}; + Thread t=new Thread(r); + t.start(); + } + Boolean stop=false; + // Fired when plugin is disabled + @Override + public void onDisable() + { + SaveFiles(); //2015.08.09. + stop=true; + } + + public void ThreadMethod() //<-- 2015.07.16. + { + while(!stop) + { + try + { + String body=DownloadString("https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/autoflair_system_comment_your_minecraft_name_and/.json?limit=1000"); + JSONArray json=new JSONArray(body).getJSONObject(1).getJSONObject("data").getJSONArray("children"); + for(Object obj : json) + { + JSONObject item = (JSONObject)obj; + String author=item.getJSONObject("data").getString("author"); + String ign=item.getJSONObject("data").getString("body"); + int start = ign.indexOf("IGN:") + "IGN:".length(); + if(start==-1) + continue; //2015.08.09. + int end = ign.indexOf(' ', start); + if (end == -1 || end == start) + end=ign.indexOf('\n', start); //2015.07.15. + if (end == -1 || end == start) + ign = ign.substring(start); + else + ign = ign.substring(start, end); + ign = ign.trim(); + if(HasIGFlair(ign)) + continue; + try { + Thread.sleep(10); + } catch(InterruptedException ex) { + Thread.currentThread().interrupt(); + } + String[] flairdata = DownloadString("http://karmadecay.com/thebutton-data.php?users=" + author).replace("\"", "").split(":"); + String flair; + if(flairdata.length > 1) //2015.07.15. + flair = flairdata[1]; + else + flair=""; + if (flair != "-1") + flair = flair + "s"; + else + flair = "non-presser"; + String flairclass; + if(flairdata.length>2) + flairclass = flairdata[2]; + else + flairclass="unknown"; + SetFlair(ign, flair, flairclass, author); + } + Thread.sleep(10000); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + } + + public static Exception LastException; //2015.08.09. + + public String DownloadString(String urlstr) throws MalformedURLException, IOException + { + URL url = new URL(urlstr); + URLConnection con = url.openConnection(); + con.setRequestProperty("User-Agent", "TheButtonAutoFlair"); + InputStream in = con.getInputStream(); + String encoding = con.getContentEncoding(); + encoding = encoding == null ? "UTF-8" : encoding; + String body = IOUtils.toString(in, encoding); + in.close(); + return body; + } + + public static Map TownColors=new HashMap(); //2015.07.20. + public Boolean HasIGFlair(String playername) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + return p.Flair!=null; //2015.08.08. + } + + public void SetFlair(String playername, String text, String flairclass, String username) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + String finalflair; + p.FlairDecided=true; + switch(flairclass) + { + case "press-1": + finalflair="§c("+text+")§r"; + break; + case "press-2": + finalflair="§6("+text+")§r"; + break; + case "press-3": + finalflair="§e("+text+")§r"; + break; + case "press-4": + finalflair="§a("+text+")§r"; + break; + case "press-5": + finalflair="§9("+text+")§r"; + break; + 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; + case "undecided": //2015.08.09. + p.FlairDecided=false; + finalflair=""; + break; + default: + finalflair=""; + break; + } + if(finalflair.length()==0) //<-- 2015.07.20. + return; + p.Flair=finalflair; //2015.08.08. + p.UserName=username; //2015.08.08. + System.out.println("Added new flair to "+playername+": "+finalflair); + for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08. + { + if(player.getName().equals(playername)) + { + //AppendPlayerDisplayFlair(player, username, finalflair); + AppendPlayerDisplayFlair(p, player); + break; + } + } + } + + public static String GetFlair(Player player) + { //2015.07.16. + String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08. + return flair==null ? "" : flair; + } + + //public static void AppendPlayerDisplayFlair(Player player, String username, String flair) + public static void AppendPlayerDisplayFlair(MaybeOfflinePlayer player, Player p) //<-- 2015.08.09. + { + + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).IgnoredFlair) + return; + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).AcceptedFlair) + { + AppendPlayerDisplayFlairFinal(p, player.Flair); //2015.07.20. + if(!player.FlairDecided) + p.sendMessage("§9Your flair type is unknown. Are you a non-presser or a can't press? (/u nonpresser or /u cantpress)§r"); //2015.08.09. + } + else + p.sendMessage("§9Are you Reddit user "+player.UserName+"?§r §6Type /u accept or /u ignore§r"); + } + + private static void AppendPlayerDisplayFlairFinal(Player player, String flair) + { //2015.07.20. + String color = GetColorForTown(GetPlayerTown(player)); //TO!DO: Multiple colors put on first capital letters + String[] colors = color.substring(1).split("§"); + String displayname=player.getName(); //2015.08.08. + ArrayList Positions=new ArrayList<>(); + for(int i=0; i=colors.length) + { + int x=0; + for(int i=0; i GetPlayers() + { + return Instance.getServer().getOnlinePlayers(); + } + + public static void LoadFiles(boolean reload) //<-- 2015.08.09. + { + if(reload) + { //2015.08.09. + System.out.println("Auto-flair plugin cleanup for reloading..."); + MaybeOfflinePlayer.AllPlayers.clear(); + TownColors.clear(); + } + System.out.println("Loading files for auto-flair plugin..."); //2015.08.09. + try { + File file=new File("flairsaccepted.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + //System.out.println("Name: " + name); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("flairsignored.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsignored.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("autoflairconfig.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + TownColors.put(s[0], s[1]); + } + br.close(); + } + file=new File("customflairs.txt"); //2015.08.09. + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + MaybeOfflinePlayer.AddPlayerIfNeeded(s[0]).Flair=s[1]; //2015.08.09. + } + br.close(); + } + //throw new IOException("Test"); //2015.08.09. + System.out.println("Auto-flair plugin loaded files!"); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + public static void SaveFiles() //<-- 2015.08.09. + { + try + { + FileWriter fw; + fw = new FileWriter("flairsaccepted.txt"); + fw.close(); + fw = new FileWriter("flairsignored.txt"); + fw.close(); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + try { + File file=new File("flairsaccepted.txt"); + BufferedWriter bw=new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.AcceptedFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + file=new File("flairsignored.txt"); + bw = new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.IgnoredFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + public static void SetPlayerFlair(Player player, String flair) + { //2015.08.09. + flair=flair.replace('&', '§'); + MaybeOfflinePlayer.AddPlayerIfNeeded(player.getName()).Flair=flair; + File file=new File("autoflairdecisions.txt"); + BufferedWriter bw=new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) + { + if(!player.AcceptedFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/73/a095babcdc3e001517108d149b613203 b/.metadata/.plugins/org.eclipse.core.resources/.history/73/a095babcdc3e001517108d149b613203 new file mode 100644 index 0000000..9c88529 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/73/a095babcdc3e001517108d149b613203 @@ -0,0 +1,394 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStream; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLConnection; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + +import org.apache.commons.io.IOUtils; +import org.bukkit.entity.Player; +import org.bukkit.plugin.java.JavaPlugin; +import org.json.JSONArray; +import org.json.JSONObject; + +import com.palmergames.bukkit.towny.object.Town; +import com.palmergames.bukkit.towny.object.WorldCoord; + +public class PluginMain extends JavaPlugin +{ //Translated to Java: 2015.07.15. + //A user, which flair isn't obtainable: + //https://www.reddit.com/r/thebutton/comments/31c32v/i_pressed_the_button_without_really_thinking/ + private static PluginMain Instance; + // Fired when plugin is first enabled + @Override + public void onEnable() + { + System.out.println("The Button Auto-flair Plugin by NorbiPeti (:P)"); + getServer().getPluginManager().registerEvents(new PlayerListener(), this); + this.getCommand("u").setExecutor(new Commands()); + this.getCommand("u").setUsage(this.getCommand("u").getUsage().replace('&', '§')); + Instance=this; //2015.08.08. + LoadFiles(false); //2015.08.09. + Runnable r=new Runnable(){public void run(){ThreadMethod();}}; + Thread t=new Thread(r); + t.start(); + } + Boolean stop=false; + // Fired when plugin is disabled + @Override + public void onDisable() + { + SaveFiles(); //2015.08.09. + stop=true; + } + + public void ThreadMethod() //<-- 2015.07.16. + { + while(!stop) + { + try + { + String body=DownloadString("https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/autoflair_system_comment_your_minecraft_name_and/.json?limit=1000"); + JSONArray json=new JSONArray(body).getJSONObject(1).getJSONObject("data").getJSONArray("children"); + for(Object obj : json) + { + JSONObject item = (JSONObject)obj; + String author=item.getJSONObject("data").getString("author"); + String ign=item.getJSONObject("data").getString("body"); + int start = ign.indexOf("IGN:") + "IGN:".length(); + if(start==-1) + continue; //2015.08.09. + int end = ign.indexOf(' ', start); + if (end == -1 || end == start) + end=ign.indexOf('\n', start); //2015.07.15. + if (end == -1 || end == start) + ign = ign.substring(start); + else + ign = ign.substring(start, end); + ign = ign.trim(); + if(HasIGFlair(ign)) + continue; + try { + Thread.sleep(10); + } catch(InterruptedException ex) { + Thread.currentThread().interrupt(); + } + String[] flairdata = DownloadString("http://karmadecay.com/thebutton-data.php?users=" + author).replace("\"", "").split(":"); + String flair; + if(flairdata.length > 1) //2015.07.15. + flair = flairdata[1]; + else + flair=""; + if (flair != "-1") + flair = flair + "s"; + else + flair = "non-presser"; + String flairclass; + if(flairdata.length>2) + flairclass = flairdata[2]; + else + flairclass="unknown"; + SetFlair(ign, flair, flairclass, author); + } + Thread.sleep(10000); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + } + + public static Exception LastException; //2015.08.09. + + public String DownloadString(String urlstr) throws MalformedURLException, IOException + { + URL url = new URL(urlstr); + URLConnection con = url.openConnection(); + con.setRequestProperty("User-Agent", "TheButtonAutoFlair"); + InputStream in = con.getInputStream(); + String encoding = con.getContentEncoding(); + encoding = encoding == null ? "UTF-8" : encoding; + String body = IOUtils.toString(in, encoding); + in.close(); + return body; + } + + public static Map TownColors=new HashMap(); //2015.07.20. + public Boolean HasIGFlair(String playername) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + return p.Flair!=null; //2015.08.08. + } + + public void SetFlair(String playername, String text, String flairclass, String username) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + String finalflair; + p.FlairDecided=true; + switch(flairclass) + { + case "press-1": + finalflair="§c("+text+")§r"; + break; + case "press-2": + finalflair="§6("+text+")§r"; + break; + case "press-3": + finalflair="§e("+text+")§r"; + break; + case "press-4": + finalflair="§a("+text+")§r"; + break; + case "press-5": + finalflair="§9("+text+")§r"; + break; + 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; + case "undecided": //2015.08.09. + p.FlairDecided=false; + finalflair=""; + break; + default: + finalflair=""; + break; + } + if(finalflair.length()==0) //<-- 2015.07.20. + return; + p.Flair=finalflair; //2015.08.08. + p.UserName=username; //2015.08.08. + System.out.println("Added new flair to "+playername+": "+finalflair); + for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08. + { + if(player.getName().equals(playername)) + { + //AppendPlayerDisplayFlair(player, username, finalflair); + AppendPlayerDisplayFlair(p, player); + break; + } + } + } + + public static String GetFlair(Player player) + { //2015.07.16. + String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08. + return flair==null ? "" : flair; + } + + //public static void AppendPlayerDisplayFlair(Player player, String username, String flair) + public static void AppendPlayerDisplayFlair(MaybeOfflinePlayer player, Player p) //<-- 2015.08.09. + { + + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).IgnoredFlair) + return; + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).AcceptedFlair) + { + AppendPlayerDisplayFlairFinal(p, player.Flair); //2015.07.20. + if(!player.FlairDecided) + p.sendMessage("§9Your flair type is unknown. Are you a non-presser or a can't press? (/u nonpresser or /u cantpress)§r"); //2015.08.09. + } + else + p.sendMessage("§9Are you Reddit user "+player.UserName+"?§r §6Type /u accept or /u ignore§r"); + } + + private static void AppendPlayerDisplayFlairFinal(Player player, String flair) + { //2015.07.20. + String color = GetColorForTown(GetPlayerTown(player)); //TO!DO: Multiple colors put on first capital letters + String[] colors = color.substring(1).split("§"); + String displayname=player.getName(); //2015.08.08. + ArrayList Positions=new ArrayList<>(); + for(int i=0; i=colors.length) + { + int x=0; + for(int i=0; i GetPlayers() + { + return Instance.getServer().getOnlinePlayers(); + } + + public static void LoadFiles(boolean reload) //<-- 2015.08.09. + { + if(reload) + { //2015.08.09. + System.out.println("Auto-flair plugin cleanup for reloading..."); + MaybeOfflinePlayer.AllPlayers.clear(); + TownColors.clear(); + } + System.out.println("Loading files for auto-flair plugin..."); //2015.08.09. + try { + File file=new File("flairsaccepted.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + //System.out.println("Name: " + name); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("flairsignored.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsignored.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("autoflairconfig.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + TownColors.put(s[0], s[1]); + } + br.close(); + } + file=new File("autoflairdecisions.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + MaybeOfflinePlayer.AddPlayerIfNeeded(s[0]).Flair= + } + br.close(); + } + //throw new IOException("Test"); //2015.08.09. + System.out.println("Auto-flair plugin loaded files!"); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + public static void SaveFiles() //<-- 2015.08.09. + { + try + { + FileWriter fw; + fw = new FileWriter("flairsaccepted.txt"); + fw.close(); + fw = new FileWriter("flairsignored.txt"); + fw.close(); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + try { + File file=new File("flairsaccepted.txt"); + BufferedWriter bw=new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.AcceptedFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + file=new File("flairsignored.txt"); + bw = new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.IgnoredFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/74/008b13dedf3e001517108d149b613203 b/.metadata/.plugins/org.eclipse.core.resources/.history/74/008b13dedf3e001517108d149b613203 new file mode 100644 index 0000000..65911d6 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/74/008b13dedf3e001517108d149b613203 @@ -0,0 +1,255 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +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; + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. + //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) + if(p.Flair==null) + { + player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); + return true; + } + switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. + { + case "accept": + { + if(p.IgnoredFlair) + p.IgnoredFlair=false; //2015.08.08. + if(!p.AcceptedFlair) + { + String flair=p.Flair; //2015.08.08. + //PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + PluginMain.AppendPlayerDisplayFlair(p, player); + p.AcceptedFlair=true; //2015.08.08. + player.sendMessage("§6Your flair has been set:§r "+flair); + } + else + player.sendMessage("§cYou already have this user's flair.§r"); + break; + } + case "ignore": + { + if(p.AcceptedFlair) + p.AcceptedFlair=false; //2015.08.08. + if(!p.IgnoredFlair) + { + p.IgnoredFlair=true; + String flair=p.Flair; //2015.08.08. + PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. + player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); + } + else + player.sendMessage("§cYou already ignored this request.§r"); + break; + } + /*case "reload": //2015.07.20. + DoReload(player); + break;*/ + case "admin": //2015.08.09. + DoAdmin(player, args); + break; + case "nonpresser": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§7(non-pr.)§r"; + break; + case "cantpress": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§r(can't press)§r"; + break; + default: + return false; + } + return true; + } + /*if(args[0].toLowerCase()=="reload") + DoReload(null); //2015.07.20.*/ + else if(args.length>0 && args[0].toLowerCase().equals("admin")) //2015.08.09. + { + DoAdmin(null, args); //2015.08.09. + return true; //2015.08.09. + } + return false; + } + private static void DoReload(Player player) + { //2015.07.20. + //if(player==null || player.isOp() || player.getName()=="NorbiPeti") + //{ + try + { + File file=new File("autoflairconfig.txt"); + if(file.exists()) + { + PluginMain.LoadFiles(true); //2015.08.09. + for(Player p : PluginMain.GetPlayers()) + { + MaybeOfflinePlayer mp = MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName()); + if(mp.Flair!=null) + { + String flair=mp.Flair; + PluginMain.RemovePlayerDisplayFlairFinal(p, flair); + //PluginMain.AppendPlayerDisplayFlairFinal(p, flair); + PluginMain.AppendPlayerDisplayFlair(mp, p); //2015.08.09. + } + String msg="§6Note: The auto-flair plugin has been reloaded. You might need to wait 10s to have your flair.§r"; //2015.08.09. + p.sendMessage(msg); //2015.08.09. + } + //String msg="§6Reloaded config file.§r"; + //SendMessage(player, msg); //2015.08.09. + } + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + if(player!=null) + player.sendMessage("§cAn error occured. See console for details.§r"); + PluginMain.LastException=e; //2015.08.09. + } + //} + //else + //player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static Player ReloadPlayer; //2015.08.09. + private static void DoAdmin(Player player, String[] args) + { //2015.08.09. + if(player==null || player.isOp() || player.getName()=="NorbiPeti") + { + //System.out.println("Args length: " + args.length); + if(args.length==1) + { + String message="§cUsage: /u admin reload|playerinfo§r"; + SendMessage(player, message); + return; + } + //args[0] is "admin" + switch(args[1].toLowerCase()) + { + case "reload": + ReloadPlayer=player; //2015.08.09. + SendMessage(player, "§6Make sure to save the current settings before you modify and reload them! Type /u admin confirm when done.§r"); + break; + case "playerinfo": + DoPlayerInfo(player, args); + break; + case "getlasterror": + DoGetLastError(player, args); + case "confirm": + if(ReloadPlayer==player) + DoReload(player); //2015.08.09. + else + SendMessage(player, "§cYou need to do /u admin reload first.§r"); + break; + case "save": + PluginMain.SaveFiles(); //2015.08.09. + SendMessage(player, "§6Saved files. Now you can edit them and reload if you want.§r"); + break; + case "setflair": + + break; + default: + String message="§cUsage: /u admin reload|playerinfo|getlasterror|save§r"; + SendMessage(player, message); + return; + } + } + else + player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static void DoPlayerInfo(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "playerinfo" + if(args.length==2) + { + String message="§cUsage: /u admin playerinfo §r"; + SendMessage(player, message); + return; + } + if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2])) + { + String message="§cPlayer not found: "+args[2]+"§r"; + SendMessage(player, message); + return; + } + MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]); + SendMessage(player, "Player name: "+p.PlayerName); + SendMessage(player, "User flair: "+p.Flair); + SendMessage(player, "Username: "+p.UserName); + SendMessage(player, "Flair accepted: "+p.AcceptedFlair); + SendMessage(player, "Flair ignored: "+p.IgnoredFlair); + } + private static void SendMessage(Player player, String message) + { //2015.08.09. + if(player==null) + System.out.println(message); + else + player.sendMessage(message); + } + private static void DoGetLastError(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "getlasterror" + if(PluginMain.LastException!=null) + { + SendMessage(player, "Last error:"); + SendMessage(player, PluginMain.LastException.toString()); + PluginMain.LastException=null; + } + else + SendMessage(player, "There were no exceptions."); + } + private static void SetPlayerFlair(Player player, Player targetplayer, String flair) + { //2015.08.09. + flair=flair.replace('&', '§'); + MaybeOfflinePlayer.AddPlayerIfNeeded(player.getName()).Flair=flair; + if(!PluginMain.RemoveLineFromFile("customflairs.txt", targetplayer.getName())) + { + SendMessage(player, "§cError removing previous custom flair!§r"); + return; + } + File file=new File("customflairs.txt"); + try { + BufferedWriter bw; + bw = new BufferedWriter(new FileWriter(file, true)); + bw.write(targetplayer.getName()+"\n"); + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + PluginMain.LastException=e; //2015.08.09. + } + SendMessage(player, "§6The flair has been set. Player: "+targetplayer.getName()+" Flair: "+flair+"§r"); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/74/10419116e13e001517108d149b613203 b/.metadata/.plugins/org.eclipse.core.resources/.history/74/10419116e13e001517108d149b613203 new file mode 100644 index 0000000..6e1da0e --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/74/10419116e13e001517108d149b613203 @@ -0,0 +1,265 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +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; + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. + //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) + if(p.Flair==null) + { + player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); + return true; + } + switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. + { + case "accept": + { + if(p.IgnoredFlair) + p.IgnoredFlair=false; //2015.08.08. + if(!p.AcceptedFlair) + { + String flair=p.Flair; //2015.08.08. + //PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + PluginMain.AppendPlayerDisplayFlair(p, player); + p.AcceptedFlair=true; //2015.08.08. + player.sendMessage("§6Your flair has been set:§r "+flair); + } + else + player.sendMessage("§cYou already have this user's flair.§r"); + break; + } + case "ignore": + { + if(p.AcceptedFlair) + p.AcceptedFlair=false; //2015.08.08. + if(!p.IgnoredFlair) + { + p.IgnoredFlair=true; + String flair=p.Flair; //2015.08.08. + PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. + player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); + } + else + player.sendMessage("§cYou already ignored this request.§r"); + break; + } + /*case "reload": //2015.07.20. + DoReload(player); + break;*/ + case "admin": //2015.08.09. + DoAdmin(player, args); + break; + case "nonpresser": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§7(non-pr.)§r"; + break; + case "cantpress": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§r(can't press)§r"; + break; + default: + return false; + } + return true; + } + /*if(args[0].toLowerCase()=="reload") + DoReload(null); //2015.07.20.*/ + else if(args.length>0 && args[0].toLowerCase().equals("admin")) //2015.08.09. + { + DoAdmin(null, args); //2015.08.09. + return true; //2015.08.09. + } + return false; + } + private static void DoReload(Player player) + { //2015.07.20. + //if(player==null || player.isOp() || player.getName()=="NorbiPeti") + //{ + try + { + File file=new File("autoflairconfig.txt"); + if(file.exists()) + { + PluginMain.LoadFiles(true); //2015.08.09. + for(Player p : PluginMain.GetPlayers()) + { + MaybeOfflinePlayer mp = MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName()); + if(mp.Flair!=null) + { + String flair=mp.Flair; + PluginMain.RemovePlayerDisplayFlairFinal(p, flair); + //PluginMain.AppendPlayerDisplayFlairFinal(p, flair); + PluginMain.AppendPlayerDisplayFlair(mp, p); //2015.08.09. + } + String msg="§6Note: The auto-flair plugin has been reloaded. You might need to wait 10s to have your flair.§r"; //2015.08.09. + p.sendMessage(msg); //2015.08.09. + } + //String msg="§6Reloaded config file.§r"; + //SendMessage(player, msg); //2015.08.09. + } + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + if(player!=null) + player.sendMessage("§cAn error occured. See console for details.§r"); + PluginMain.LastException=e; //2015.08.09. + } + //} + //else + //player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static Player ReloadPlayer; //2015.08.09. + private static void DoAdmin(Player player, String[] args) + { //2015.08.09. + if(player==null || player.isOp() || player.getName()=="NorbiPeti") + { + //System.out.println("Args length: " + args.length); + if(args.length==1) + { + String message="§cUsage: /u admin reload|playerinfo§r"; + SendMessage(player, message); + return; + } + //args[0] is "admin" + switch(args[1].toLowerCase()) + { + case "reload": + ReloadPlayer=player; //2015.08.09. + SendMessage(player, "§6Make sure to save the current settings before you modify and reload them! Type /u admin confirm when done.§r"); + break; + case "playerinfo": + DoPlayerInfo(player, args); + break; + case "getlasterror": + DoGetLastError(player, args); + case "confirm": + if(ReloadPlayer==player) + DoReload(player); //2015.08.09. + else + SendMessage(player, "§cYou need to do /u admin reload first.§r"); + break; + case "save": + PluginMain.SaveFiles(); //2015.08.09. + SendMessage(player, "§6Saved files. Now you can edit them and reload if you want.§r"); + break; + case "setflair": + + break; + default: + String message="§cUsage: /u admin reload|playerinfo|getlasterror|save§r"; + SendMessage(player, message); + return; + } + } + else + player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static void DoPlayerInfo(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "playerinfo" + if(args.length==2) + { + String message="§cUsage: /u admin playerinfo §r"; + SendMessage(player, message); + return; + } + if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2])) + { + String message="§cPlayer not found: "+args[2]+"§r"; + SendMessage(player, message); + return; + } + MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]); + SendMessage(player, "Player name: "+p.PlayerName); + SendMessage(player, "User flair: "+p.Flair); + SendMessage(player, "Username: "+p.UserName); + SendMessage(player, "Flair accepted: "+p.AcceptedFlair); + SendMessage(player, "Flair ignored: "+p.IgnoredFlair); + } + private static void SendMessage(Player player, String message) + { //2015.08.09. + if(player==null) + System.out.println(message); + else + player.sendMessage(message); + } + private static void DoGetLastError(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "getlasterror" + if(PluginMain.LastException!=null) + { + SendMessage(player, "Last error:"); + SendMessage(player, PluginMain.LastException.toString()); + PluginMain.LastException=null; + } + else + SendMessage(player, "There were no exceptions."); + } + private static void SetPlayerFlair(Player player, MaybeOfflinePlayer targetplayer, String flair) + { //2015.08.09. + flair=flair.replace('&', '§'); + targetplayer.Flair=flair; + if(!PluginMain.RemoveLineFromFile("customflairs.txt", targetplayer.PlayerName)) + { + SendMessage(player, "§cError removing previous custom flair!§r"); + return; + } + File file=new File("customflairs.txt"); + try { + BufferedWriter bw; + bw = new BufferedWriter(new FileWriter(file, true)); + bw.write(targetplayer.PlayerName+"\n"); + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + PluginMain.LastException=e; //2015.08.09. + } + SendMessage(player, "§6The flair has been set. Player: "+targetplayer.PlayerName+" Flair: "+flair+"§r"); + } + private static void DoSetFlair(Player player, String[] args) + { + //args[0] is "admin" - args[1] is "setflair" + if(args.length()<4) + { + SendMessage(player, "§cUsage: /u admin setflair "); + return; + } + SetPlayerFlair(player, MaybeOfflinePlayer.AddPlayerIfNeeded(args[2]), args[3]); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/74/8080bcd3e43e001517108d149b613203 b/.metadata/.plugins/org.eclipse.core.resources/.history/74/8080bcd3e43e001517108d149b613203 new file mode 100644 index 0000000..eee5b38 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/74/8080bcd3e43e001517108d149b613203 @@ -0,0 +1,422 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStream; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLConnection; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + +import org.apache.commons.io.IOUtils; +import org.bukkit.entity.Player; +import org.bukkit.plugin.java.JavaPlugin; +import org.json.JSONArray; +import org.json.JSONObject; + +import com.palmergames.bukkit.towny.object.Town; +import com.palmergames.bukkit.towny.object.WorldCoord; + +public class PluginMain extends JavaPlugin +{ //Translated to Java: 2015.07.15. + //A user, which flair isn't obtainable: + //https://www.reddit.com/r/thebutton/comments/31c32v/i_pressed_the_button_without_really_thinking/ + private static PluginMain Instance; + // Fired when plugin is first enabled + @Override + public void onEnable() + { + System.out.println("The Button Auto-flair Plugin by NorbiPeti (:P)"); + getServer().getPluginManager().registerEvents(new PlayerListener(), this); + this.getCommand("u").setExecutor(new Commands()); + this.getCommand("u").setUsage(this.getCommand("u").getUsage().replace('&', '§')); + Instance=this; //2015.08.08. + LoadFiles(false); //2015.08.09. + Runnable r=new Runnable(){public void run(){ThreadMethod();}}; + Thread t=new Thread(r); + t.start(); + } + Boolean stop=false; + // Fired when plugin is disabled + @Override + public void onDisable() + { + SaveFiles(); //2015.08.09. + stop=true; + } + + public void ThreadMethod() //<-- 2015.07.16. + { + while(!stop) + { + try + { + String body=DownloadString("https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/autoflair_system_comment_your_minecraft_name_and/.json?limit=1000"); + JSONArray json=new JSONArray(body).getJSONObject(1).getJSONObject("data").getJSONArray("children"); + for(Object obj : json) + { + JSONObject item = (JSONObject)obj; + String author=item.getJSONObject("data").getString("author"); + String ign=item.getJSONObject("data").getString("body"); + int start = ign.indexOf("IGN:") + "IGN:".length(); + if(start==-1) + continue; //2015.08.09. + int end = ign.indexOf(' ', start); + if (end == -1 || end == start) + end=ign.indexOf('\n', start); //2015.07.15. + if (end == -1 || end == start) + ign = ign.substring(start); + else + ign = ign.substring(start, end); + ign = ign.trim(); + if(HasIGFlair(ign)) + continue; + try { + Thread.sleep(10); + } catch(InterruptedException ex) { + Thread.currentThread().interrupt(); + } + String[] flairdata = DownloadString("http://karmadecay.com/thebutton-data.php?users=" + author).replace("\"", "").split(":"); + String flair; + if(flairdata.length > 1) //2015.07.15. + flair = flairdata[1]; + else + flair=""; + if (flair != "-1") + flair = flair + "s"; + else + flair = "non-presser"; + String flairclass; + if(flairdata.length>2) + flairclass = flairdata[2]; + else + flairclass="unknown"; + SetFlair(ign, flair, flairclass, author); + } + Thread.sleep(10000); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + } + + public static Exception LastException; //2015.08.09. + + public String DownloadString(String urlstr) throws MalformedURLException, IOException + { + URL url = new URL(urlstr); + URLConnection con = url.openConnection(); + con.setRequestProperty("User-Agent", "TheButtonAutoFlair"); + InputStream in = con.getInputStream(); + String encoding = con.getContentEncoding(); + encoding = encoding == null ? "UTF-8" : encoding; + String body = IOUtils.toString(in, encoding); + in.close(); + return body; + } + + public static Map TownColors=new HashMap(); //2015.07.20. + public Boolean HasIGFlair(String playername) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + return p.Flair!=null; //2015.08.08. + } + + public void SetFlair(String playername, String text, String flairclass, String username) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + String finalflair; + p.FlairDecided=true; + switch(flairclass) + { + case "press-1": + finalflair="§c("+text+")§r"; + break; + case "press-2": + finalflair="§6("+text+")§r"; + break; + case "press-3": + finalflair="§e("+text+")§r"; + break; + case "press-4": + finalflair="§a("+text+")§r"; + break; + case "press-5": + finalflair="§9("+text+")§r"; + break; + 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; + case "undecided": //2015.08.09. + p.FlairDecided=false; + finalflair=""; + break; + default: + finalflair=""; + break; + } + if(finalflair.length()==0) //<-- 2015.07.20. + return; + p.Flair=finalflair; //2015.08.08. + p.UserName=username; //2015.08.08. + System.out.println("Added new flair to "+playername+": "+finalflair); + for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08. + { + if(player.getName().equals(playername)) + { + //AppendPlayerDisplayFlair(player, username, finalflair); + AppendPlayerDisplayFlair(p, player); + break; + } + } + } + + public static String GetFlair(Player player) + { //2015.07.16. + String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08. + return flair==null ? "" : flair; + } + + //public static void AppendPlayerDisplayFlair(Player player, String username, String flair) + public static void AppendPlayerDisplayFlair(MaybeOfflinePlayer player, Player p) //<-- 2015.08.09. + { + + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).IgnoredFlair) + return; + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).AcceptedFlair) + { + AppendPlayerDisplayFlairFinal(p, player.Flair); //2015.07.20. + if(!player.FlairDecided) + p.sendMessage("§9Your flair type is unknown. Are you a non-presser or a can't press? (/u nonpresser or /u cantpress)§r"); //2015.08.09. + } + else + p.sendMessage("§9Are you Reddit user "+player.UserName+"?§r §6Type /u accept or /u ignore§r"); + } + + private static void AppendPlayerDisplayFlairFinal(Player player, String flair) + { //2015.07.20. + String color = GetColorForTown(GetPlayerTown(player)); //TO!DO: Multiple colors put on first capital letters + String[] colors = color.substring(1).split("§"); + String displayname=player.getName(); //2015.08.08. + ArrayList Positions=new ArrayList<>(); + for(int i=0; i=colors.length) + { + int x=0; + for(int i=0; i GetPlayers() + { + return Instance.getServer().getOnlinePlayers(); + } + + public static void LoadFiles(boolean reload) //<-- 2015.08.09. + { + if(reload) + { //2015.08.09. + System.out.println("Auto-flair plugin cleanup for reloading..."); + MaybeOfflinePlayer.AllPlayers.clear(); + TownColors.clear(); + } + System.out.println("Loading files for auto-flair plugin..."); //2015.08.09. + try { + File file=new File("flairsaccepted.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + //System.out.println("Name: " + name); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("flairsignored.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsignored.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("autoflairconfig.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + TownColors.put(s[0], s[1]); + } + br.close(); + } + file=new File("customflairs.txt"); //2015.08.09. + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + MaybeOfflinePlayer.AddPlayerIfNeeded(s[0]).Flair=s[1]; //2015.08.09. + } + br.close(); + } + //throw new IOException("Test"); //2015.08.09. + System.out.println("Auto-flair plugin loaded files!"); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + public static void SaveFiles() //<-- 2015.08.09. + { + try + { + FileWriter fw; + fw = new FileWriter("flairsaccepted.txt"); + fw.close(); + fw = new FileWriter("flairsignored.txt"); + fw.close(); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + try { + File file=new File("flairsaccepted.txt"); + BufferedWriter bw=new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.AcceptedFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + file=new File("flairsignored.txt"); + bw = new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.IgnoredFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + public static boolean RemoveLineFromFile(String file, String line) + { //2015.08.09. + File inputFile = new File(file); + File tempFile = new File("_temp.txt"); + + try { + BufferedReader reader = new BufferedReader(new FileReader(inputFile)); + BufferedWriter writer = new BufferedWriter(new FileWriter(tempFile)); + + String lineToRemove = line; + String currentLine; + + while((currentLine = reader.readLine()) != null) { + // trim newline when comparing with lineToRemove + String trimmedLine = currentLine.trim(); + //if(trimmedLine.equals(lineToRemove)) continue; + if(trimmedLine.contains(lineToRemove)) continue; //2015.08.09. + writer.write(currentLine + System.getProperty("line.separator")); + } + writer.close(); + reader.close(); + return tempFile.renameTo(inputFile); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + return false; + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/75/200e61c5d03e001518fa86d7ae2a1cf8 b/.metadata/.plugins/org.eclipse.core.resources/.history/75/200e61c5d03e001518fa86d7ae2a1cf8 new file mode 100644 index 0000000..03f8e7b --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/75/200e61c5d03e001518fa86d7ae2a1cf8 @@ -0,0 +1,209 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; + +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class Commands implements CommandExecutor { + // This method is called, when somebody uses our command + @Override + public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { + if (sender instanceof Player) { + Player player = (Player) sender; + if(args.length<1) + return false; + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. + //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) + if(p.Flair==null) + { + player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); + return true; + } + switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. + { + case "accept": + { + if(p.IgnoredFlair) + p.IgnoredFlair=false; //2015.08.08. + if(!p.AcceptedFlair) + { + String flair=p.Flair; //2015.08.08. + //PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + PluginMain.AppendPlayerDisplayFlair(p, player); + p.AcceptedFlair=true; //2015.08.08. + player.sendMessage("§6Your flair has been set:§r "+flair); + } + else + player.sendMessage("§cYou already have this user's flair.§r"); + break; + } + case "ignore": + { + if(p.AcceptedFlair) + p.AcceptedFlair=false; //2015.08.08. + if(!p.IgnoredFlair) + { + p.IgnoredFlair=true; + String flair=p.Flair; //2015.08.08. + PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. + player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); + } + else + player.sendMessage("§cYou already ignored this request.§r"); + break; + } + /*case "reload": //2015.07.20. + DoReload(player); + break;*/ + case "admin": //2015.08.09. + DoAdmin(player, args); + break; + case "nonpresser": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + } + break; + case "cantpress": //2015.08.09. + break; + default: + return false; + } + return true; + } + /*if(args[0].toLowerCase()=="reload") + DoReload(null); //2015.07.20.*/ + else if(args.length>0 && args[0].toLowerCase().equals("admin")) //2015.08.09. + { + DoAdmin(null, args); //2015.08.09. + return true; //2015.08.09. + } + return false; + } + private static void DoReload(Player player) + { //2015.07.20. + //if(player==null || player.isOp() || player.getName()=="NorbiPeti") + //{ + try + { + File file=new File("autoflairconfig.txt"); + if(file.exists()) + { + PluginMain.TownColors.clear(); + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + PluginMain.TownColors.put(s[0], s[1]); + } + br.close(); + for(Player p : PluginMain.GetPlayers()) + { + MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName()); + if(mp.Flair!=null) + { + String flair=mp.Flair; + PluginMain.RemovePlayerDisplayFlairFinal(p, flair); + //PluginMain.AppendPlayerDisplayFlairFinal(p, flair); + PluginMain.AppendPlayerDisplayFlair(mp, p); //2015.08.09. + } + } + String msg="§6Reloaded config file.§r"; + SendMessage(player, msg); //2015.08.09. + } + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + if(player!=null) + player.sendMessage("§cAn error occured. See console for details.§r"); + PluginMain.LastException=e; //2015.08.09. + } + //} + //else + //player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static void DoAdmin(Player player, String[] args) + { //2015.08.09. + if(player==null || player.isOp() || player.getName()=="NorbiPeti") + { + //System.out.println("Args length: " + args.length); + if(args.length==1) + { + String message="§cUsage: /u admin reload|playerinfo§r"; + SendMessage(player, message); + return; + } + //args[0] is "admin" + switch(args[1].toLowerCase()) + { + case "reload": + DoReload(player); + break; + case "playerinfo": + DoPlayerInfo(player, args); + break; + case "getlasterror": + DoGetLastError(player, args); + default: + String message="§cUsage: /u admin reload|playerinfo§r"; + SendMessage(player, message); + return; + } + } + else + player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static void DoPlayerInfo(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "playerinfo" + if(args.length==2) + { + String message="§cUsage: /u admin playerinfo §r"; + SendMessage(player, message); + return; + } + if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2])) + { + String message="§cPlayer not found: "+args[2]+"§r"; + SendMessage(player, message); + return; + } + MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]); + SendMessage(player, "Player name: "+p.PlayerName); + SendMessage(player, "User flair: "+p.Flair); + SendMessage(player, "Username: "+p.UserName); + SendMessage(player, "Flair accepted: "+p.AcceptedFlair); + SendMessage(player, "Flair ignored: "+p.IgnoredFlair); + } + private static void SendMessage(Player player, String message) + { //2015.08.09. + if(player==null) + System.out.println(message); + else + player.sendMessage(message); + } + private static void DoGetLastError(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "getlasterror" + if(PluginMain.LastException!=null) + { + SendMessage(player, "Last error:"); + SendMessage(player, PluginMain.LastException.toString()); + PluginMain.LastException=null; + } + else + SendMessage(player, "There were no exceptions."); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/75/20bc5301d13e001518fa86d7ae2a1cf8 b/.metadata/.plugins/org.eclipse.core.resources/.history/75/20bc5301d13e001518fa86d7ae2a1cf8 new file mode 100644 index 0000000..7e0571a --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/75/20bc5301d13e001518fa86d7ae2a1cf8 @@ -0,0 +1,222 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; + +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class Commands implements CommandExecutor { + // This method is called, when somebody uses our command + @Override + public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { + if (sender instanceof Player) { + Player player = (Player) sender; + if(args.length<1) + return false; + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. + //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) + if(p.Flair==null) + { + player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); + return true; + } + switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. + { + case "accept": + { + if(p.IgnoredFlair) + p.IgnoredFlair=false; //2015.08.08. + if(!p.AcceptedFlair) + { + String flair=p.Flair; //2015.08.08. + //PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + PluginMain.AppendPlayerDisplayFlair(p, player); + p.AcceptedFlair=true; //2015.08.08. + player.sendMessage("§6Your flair has been set:§r "+flair); + } + else + player.sendMessage("§cYou already have this user's flair.§r"); + break; + } + case "ignore": + { + if(p.AcceptedFlair) + p.AcceptedFlair=false; //2015.08.08. + if(!p.IgnoredFlair) + { + p.IgnoredFlair=true; + String flair=p.Flair; //2015.08.08. + PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. + player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); + } + else + player.sendMessage("§cYou already ignored this request.§r"); + break; + } + /*case "reload": //2015.07.20. + DoReload(player); + break;*/ + case "admin": //2015.08.09. + DoAdmin(player, args); + break; + case "nonpresser": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§7(non-pr.)§r"; + break; + case "cantpress": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§7(non-pr.)§r"; + break; + default: + return false; + } + return true; + } + /*if(args[0].toLowerCase()=="reload") + DoReload(null); //2015.07.20.*/ + else if(args.length>0 && args[0].toLowerCase().equals("admin")) //2015.08.09. + { + DoAdmin(null, args); //2015.08.09. + return true; //2015.08.09. + } + return false; + } + private static void DoReload(Player player) + { //2015.07.20. + //if(player==null || player.isOp() || player.getName()=="NorbiPeti") + //{ + try + { + File file=new File("autoflairconfig.txt"); + if(file.exists()) + { + PluginMain.TownColors.clear(); + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + PluginMain.TownColors.put(s[0], s[1]); + } + br.close(); + for(Player p : PluginMain.GetPlayers()) + { + MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName()); + if(mp.Flair!=null) + { + String flair=mp.Flair; + PluginMain.RemovePlayerDisplayFlairFinal(p, flair); + //PluginMain.AppendPlayerDisplayFlairFinal(p, flair); + PluginMain.AppendPlayerDisplayFlair(mp, p); //2015.08.09. + } + } + String msg="§6Reloaded config file.§r"; + SendMessage(player, msg); //2015.08.09. + } + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + if(player!=null) + player.sendMessage("§cAn error occured. See console for details.§r"); + PluginMain.LastException=e; //2015.08.09. + } + //} + //else + //player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static void DoAdmin(Player player, String[] args) + { //2015.08.09. + if(player==null || player.isOp() || player.getName()=="NorbiPeti") + { + //System.out.println("Args length: " + args.length); + if(args.length==1) + { + String message="§cUsage: /u admin reload|playerinfo§r"; + SendMessage(player, message); + return; + } + //args[0] is "admin" + switch(args[1].toLowerCase()) + { + case "reload": + DoReload(player); + break; + case "playerinfo": + DoPlayerInfo(player, args); + break; + case "getlasterror": + DoGetLastError(player, args); + default: + String message="§cUsage: /u admin reload|playerinfo§r"; + SendMessage(player, message); + return; + } + } + else + player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static void DoPlayerInfo(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "playerinfo" + if(args.length==2) + { + String message="§cUsage: /u admin playerinfo §r"; + SendMessage(player, message); + return; + } + if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2])) + { + String message="§cPlayer not found: "+args[2]+"§r"; + SendMessage(player, message); + return; + } + MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]); + SendMessage(player, "Player name: "+p.PlayerName); + SendMessage(player, "User flair: "+p.Flair); + SendMessage(player, "Username: "+p.UserName); + SendMessage(player, "Flair accepted: "+p.AcceptedFlair); + SendMessage(player, "Flair ignored: "+p.IgnoredFlair); + } + private static void SendMessage(Player player, String message) + { //2015.08.09. + if(player==null) + System.out.println(message); + else + player.sendMessage(message); + } + private static void DoGetLastError(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "getlasterror" + if(PluginMain.LastException!=null) + { + SendMessage(player, "Last error:"); + SendMessage(player, PluginMain.LastException.toString()); + PluginMain.LastException=null; + } + else + SendMessage(player, "There were no exceptions."); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/75/a0acffa2d13e001518fa86d7ae2a1cf8 b/.metadata/.plugins/org.eclipse.core.resources/.history/75/a0acffa2d13e001518fa86d7ae2a1cf8 new file mode 100644 index 0000000..2b15b31 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/75/a0acffa2d13e001518fa86d7ae2a1cf8 @@ -0,0 +1,368 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStream; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLConnection; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + +import org.apache.commons.io.IOUtils; +import org.bukkit.entity.Player; +import org.bukkit.plugin.java.JavaPlugin; +import org.json.JSONArray; +import org.json.JSONObject; + +import com.palmergames.bukkit.towny.object.Town; +import com.palmergames.bukkit.towny.object.WorldCoord; + +public class PluginMain extends JavaPlugin +{ //Translated to Java: 2015.07.15. + //A user, which flair isn't obtainable: + //https://www.reddit.com/r/thebutton/comments/31c32v/i_pressed_the_button_without_really_thinking/ + private static PluginMain Instance; + // Fired when plugin is first enabled + @Override + public void onEnable() + { + System.out.println("The Button Auto-flair Plugin by NorbiPeti (:P)"); + getServer().getPluginManager().registerEvents(new PlayerListener(), this); + this.getCommand("u").setExecutor(new Commands()); + this.getCommand("u").setUsage(this.getCommand("u").getUsage().replace('&', '§')); + Instance=this; //2015.08.08. + LoadFiles(false); //2015.08.09. + Runnable r=new Runnable(){public void run(){ThreadMethod();}}; + Thread t=new Thread(r); + t.start(); + } + Boolean stop=false; + // Fired when plugin is disabled + @Override + public void onDisable() + { + try + { + FileWriter fw; + fw = new FileWriter("flairsaccepted.txt"); + fw.close(); + fw = new FileWriter("flairsignored.txt"); + fw.close(); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + try { + File file=new File("flairsaccepted.txt"); + BufferedWriter bw=new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.AcceptedFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + file=new File("flairsignored.txt"); + bw = new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.IgnoredFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + stop=true; + } + + public void ThreadMethod() //<-- 2015.07.16. + { + while(!stop) + { + try + { + String body=DownloadString("https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/autoflair_system_comment_your_minecraft_name_and/.json?limit=1000"); + JSONArray json=new JSONArray(body).getJSONObject(1).getJSONObject("data").getJSONArray("children"); + for(Object obj : json) + { + JSONObject item = (JSONObject)obj; + String author=item.getJSONObject("data").getString("author"); + String ign=item.getJSONObject("data").getString("body"); + int start = ign.indexOf("IGN:") + "IGN:".length(); + int end = ign.indexOf(' ', start); + if (end == -1 || end == start) + end=ign.indexOf('\n', start); //2015.07.15. + if (end == -1 || end == start) + ign = ign.substring(start); + else + ign = ign.substring(start, end); + ign = ign.trim(); + if(HasIGFlair(ign)) + continue; + try { + Thread.sleep(10); + } catch(InterruptedException ex) { + Thread.currentThread().interrupt(); + } + String[] flairdata = DownloadString("http://karmadecay.com/thebutton-data.php?users=" + author).replace("\"", "").split(":"); + String flair; + if(flairdata.length > 1) //2015.07.15. + flair = flairdata[1]; + else + flair=""; + if (flair != "-1") + flair = flair + "s"; + else + flair = "non-presser"; + String flairclass; + if(flairdata.length>2) + flairclass = flairdata[2]; + else + flairclass="unknown"; + SetFlair(ign, flair, flairclass, author); + } + Thread.sleep(10000); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + } + + public static Exception LastException; //2015.08.09. + + public String DownloadString(String urlstr) throws MalformedURLException, IOException + { + URL url = new URL(urlstr); + URLConnection con = url.openConnection(); + con.setRequestProperty("User-Agent", "TheButtonAutoFlair"); + InputStream in = con.getInputStream(); + String encoding = con.getContentEncoding(); + encoding = encoding == null ? "UTF-8" : encoding; + String body = IOUtils.toString(in, encoding); + in.close(); + return body; + } + + public static Map TownColors=new HashMap(); //2015.07.20. + public Boolean HasIGFlair(String playername) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + return p.Flair!=null; //2015.08.08. + } + + public void SetFlair(String playername, String text, String flairclass, String username) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + String finalflair; + p.FlairDecided=true; + switch(flairclass) + { + case "press-1": + finalflair="§c("+text+")§r"; + break; + case "press-2": + finalflair="§6("+text+")§r"; + break; + case "press-3": + finalflair="§e("+text+")§r"; + break; + case "press-4": + finalflair="§a("+text+")§r"; + break; + case "press-5": + finalflair="§9("+text+")§r"; + break; + 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; + case "undecided": //2015.08.09. + p.FlairDecided=false; + finalflair=""; + break; + default: + finalflair=""; + break; + } + if(finalflair.length()==0) //<-- 2015.07.20. + return; + p.Flair=finalflair; //2015.08.08. + p.UserName=username; //2015.08.08. + System.out.println("Added new flair to "+playername+": "+finalflair); + for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08. + { + if(player.getName().equals(playername)) + { + //AppendPlayerDisplayFlair(player, username, finalflair); + AppendPlayerDisplayFlair(p, player); + break; + } + } + } + + public static String GetFlair(Player player) + { //2015.07.16. + String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08. + return flair==null ? "" : flair; + } + + //public static void AppendPlayerDisplayFlair(Player player, String username, String flair) + public static void AppendPlayerDisplayFlair(MaybeOfflinePlayer player, Player p) //<-- 2015.08.09. + { + + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).IgnoredFlair) + return; + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).AcceptedFlair) + { + AppendPlayerDisplayFlairFinal(p, player.Flair); //2015.07.20. + if(!player.FlairDecided) + p.sendMessage("§9Your flair type is unknown. Are you a non-presser or a can't press? (/u nonpresser or /u cantpress)§r"); //2015.08.09. + } + else + p.sendMessage("§9Are you Reddit user "+player.UserName+"?§r §6Type /u accept or /u ignore§r"); + } + + private static void AppendPlayerDisplayFlairFinal(Player player, String flair) + { //2015.07.20. + String color = GetColorForTown(GetPlayerTown(player)); //TO!DO: Multiple colors put on first capital letters + String[] colors = color.substring(1).split("§"); + String displayname=player.getName(); //2015.08.08. + ArrayList Positions=new ArrayList<>(); + for(int i=0; i=colors.length) + { + int x=0; + for(int i=0; i GetPlayers() + { + return Instance.getServer().getOnlinePlayers(); + } + + public static void LoadFiles(boolean reload) + + try { + File file=new File("flairsaccepted.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + //System.out.println("Name: " + name); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("flairsignored.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsignored.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("autoflairconfig.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + TownColors.put(s[0], s[1]); + } + br.close(); + } + //throw new IOException("Test"); //2015.08.09. + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/77/00ad7695df3e001517108d149b613203 b/.metadata/.plugins/org.eclipse.core.resources/.history/77/00ad7695df3e001517108d149b613203 new file mode 100644 index 0000000..e36fb60 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/77/00ad7695df3e001517108d149b613203 @@ -0,0 +1,421 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStream; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLConnection; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + +import org.apache.commons.io.IOUtils; +import org.bukkit.entity.Player; +import org.bukkit.plugin.java.JavaPlugin; +import org.json.JSONArray; +import org.json.JSONObject; + +import com.palmergames.bukkit.towny.object.Town; +import com.palmergames.bukkit.towny.object.WorldCoord; + +public class PluginMain extends JavaPlugin +{ //Translated to Java: 2015.07.15. + //A user, which flair isn't obtainable: + //https://www.reddit.com/r/thebutton/comments/31c32v/i_pressed_the_button_without_really_thinking/ + private static PluginMain Instance; + // Fired when plugin is first enabled + @Override + public void onEnable() + { + System.out.println("The Button Auto-flair Plugin by NorbiPeti (:P)"); + getServer().getPluginManager().registerEvents(new PlayerListener(), this); + this.getCommand("u").setExecutor(new Commands()); + this.getCommand("u").setUsage(this.getCommand("u").getUsage().replace('&', '§')); + Instance=this; //2015.08.08. + LoadFiles(false); //2015.08.09. + Runnable r=new Runnable(){public void run(){ThreadMethod();}}; + Thread t=new Thread(r); + t.start(); + } + Boolean stop=false; + // Fired when plugin is disabled + @Override + public void onDisable() + { + SaveFiles(); //2015.08.09. + stop=true; + } + + public void ThreadMethod() //<-- 2015.07.16. + { + while(!stop) + { + try + { + String body=DownloadString("https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/autoflair_system_comment_your_minecraft_name_and/.json?limit=1000"); + JSONArray json=new JSONArray(body).getJSONObject(1).getJSONObject("data").getJSONArray("children"); + for(Object obj : json) + { + JSONObject item = (JSONObject)obj; + String author=item.getJSONObject("data").getString("author"); + String ign=item.getJSONObject("data").getString("body"); + int start = ign.indexOf("IGN:") + "IGN:".length(); + if(start==-1) + continue; //2015.08.09. + int end = ign.indexOf(' ', start); + if (end == -1 || end == start) + end=ign.indexOf('\n', start); //2015.07.15. + if (end == -1 || end == start) + ign = ign.substring(start); + else + ign = ign.substring(start, end); + ign = ign.trim(); + if(HasIGFlair(ign)) + continue; + try { + Thread.sleep(10); + } catch(InterruptedException ex) { + Thread.currentThread().interrupt(); + } + String[] flairdata = DownloadString("http://karmadecay.com/thebutton-data.php?users=" + author).replace("\"", "").split(":"); + String flair; + if(flairdata.length > 1) //2015.07.15. + flair = flairdata[1]; + else + flair=""; + if (flair != "-1") + flair = flair + "s"; + else + flair = "non-presser"; + String flairclass; + if(flairdata.length>2) + flairclass = flairdata[2]; + else + flairclass="unknown"; + SetFlair(ign, flair, flairclass, author); + } + Thread.sleep(10000); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + } + + public static Exception LastException; //2015.08.09. + + public String DownloadString(String urlstr) throws MalformedURLException, IOException + { + URL url = new URL(urlstr); + URLConnection con = url.openConnection(); + con.setRequestProperty("User-Agent", "TheButtonAutoFlair"); + InputStream in = con.getInputStream(); + String encoding = con.getContentEncoding(); + encoding = encoding == null ? "UTF-8" : encoding; + String body = IOUtils.toString(in, encoding); + in.close(); + return body; + } + + public static Map TownColors=new HashMap(); //2015.07.20. + public Boolean HasIGFlair(String playername) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + return p.Flair!=null; //2015.08.08. + } + + public void SetFlair(String playername, String text, String flairclass, String username) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + String finalflair; + p.FlairDecided=true; + switch(flairclass) + { + case "press-1": + finalflair="§c("+text+")§r"; + break; + case "press-2": + finalflair="§6("+text+")§r"; + break; + case "press-3": + finalflair="§e("+text+")§r"; + break; + case "press-4": + finalflair="§a("+text+")§r"; + break; + case "press-5": + finalflair="§9("+text+")§r"; + break; + 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; + case "undecided": //2015.08.09. + p.FlairDecided=false; + finalflair=""; + break; + default: + finalflair=""; + break; + } + if(finalflair.length()==0) //<-- 2015.07.20. + return; + p.Flair=finalflair; //2015.08.08. + p.UserName=username; //2015.08.08. + System.out.println("Added new flair to "+playername+": "+finalflair); + for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08. + { + if(player.getName().equals(playername)) + { + //AppendPlayerDisplayFlair(player, username, finalflair); + AppendPlayerDisplayFlair(p, player); + break; + } + } + } + + public static String GetFlair(Player player) + { //2015.07.16. + String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08. + return flair==null ? "" : flair; + } + + //public static void AppendPlayerDisplayFlair(Player player, String username, String flair) + public static void AppendPlayerDisplayFlair(MaybeOfflinePlayer player, Player p) //<-- 2015.08.09. + { + + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).IgnoredFlair) + return; + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).AcceptedFlair) + { + AppendPlayerDisplayFlairFinal(p, player.Flair); //2015.07.20. + if(!player.FlairDecided) + p.sendMessage("§9Your flair type is unknown. Are you a non-presser or a can't press? (/u nonpresser or /u cantpress)§r"); //2015.08.09. + } + else + p.sendMessage("§9Are you Reddit user "+player.UserName+"?§r §6Type /u accept or /u ignore§r"); + } + + private static void AppendPlayerDisplayFlairFinal(Player player, String flair) + { //2015.07.20. + String color = GetColorForTown(GetPlayerTown(player)); //TO!DO: Multiple colors put on first capital letters + String[] colors = color.substring(1).split("§"); + String displayname=player.getName(); //2015.08.08. + ArrayList Positions=new ArrayList<>(); + for(int i=0; i=colors.length) + { + int x=0; + for(int i=0; i GetPlayers() + { + return Instance.getServer().getOnlinePlayers(); + } + + public static void LoadFiles(boolean reload) //<-- 2015.08.09. + { + if(reload) + { //2015.08.09. + System.out.println("Auto-flair plugin cleanup for reloading..."); + MaybeOfflinePlayer.AllPlayers.clear(); + TownColors.clear(); + } + System.out.println("Loading files for auto-flair plugin..."); //2015.08.09. + try { + File file=new File("flairsaccepted.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + //System.out.println("Name: " + name); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("flairsignored.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsignored.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("autoflairconfig.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + TownColors.put(s[0], s[1]); + } + br.close(); + } + file=new File("customflairs.txt"); //2015.08.09. + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + MaybeOfflinePlayer.AddPlayerIfNeeded(s[0]).Flair=s[1]; //2015.08.09. + } + br.close(); + } + //throw new IOException("Test"); //2015.08.09. + System.out.println("Auto-flair plugin loaded files!"); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + public static void SaveFiles() //<-- 2015.08.09. + { + try + { + FileWriter fw; + fw = new FileWriter("flairsaccepted.txt"); + fw.close(); + fw = new FileWriter("flairsignored.txt"); + fw.close(); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + try { + File file=new File("flairsaccepted.txt"); + BufferedWriter bw=new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.AcceptedFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + file=new File("flairsignored.txt"); + bw = new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.IgnoredFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + public static boolean RemoveLineFromFile(String file, String line) + { + File inputFile = new File(file); + File tempFile = new File("_temp.txt"); + + try { + BufferedReader reader = new BufferedReader(new FileReader(inputFile)); + BufferedWriter writer = new BufferedWriter(new FileWriter(tempFile)); + + String lineToRemove = line; + String currentLine; + + while((currentLine = reader.readLine()) != null) { + // trim newline when comparing with lineToRemove + String trimmedLine = currentLine.trim(); + if(trimmedLine.equals(lineToRemove)) continue; + writer.write(currentLine + System.getProperty("line.separator")); + } + writer.close(); + reader.close(); + return tempFile.renameTo(inputFile); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + return false; + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/77/10dec4cbce3e001518fa86d7ae2a1cf8 b/.metadata/.plugins/org.eclipse.core.resources/.history/77/10dec4cbce3e001518fa86d7ae2a1cf8 new file mode 100644 index 0000000..5908a1d --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/77/10dec4cbce3e001518fa86d7ae2a1cf8 @@ -0,0 +1,360 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStream; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLConnection; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + +import org.apache.commons.io.IOUtils; +import org.bukkit.entity.Player; +import org.bukkit.plugin.java.JavaPlugin; +import org.json.JSONArray; +import org.json.JSONObject; + +import tk.sznp.thebuttonautoflair.MaybeOfflinePlayer.FlairClassType; + +import com.palmergames.bukkit.towny.object.Town; +import com.palmergames.bukkit.towny.object.WorldCoord; + +public class PluginMain extends JavaPlugin +{ //Translated to Java: 2015.07.15. + //A user, which flair isn't obtainable: + //https://www.reddit.com/r/thebutton/comments/31c32v/i_pressed_the_button_without_really_thinking/ + private static PluginMain Instance; + // Fired when plugin is first enabled + @Override + public void onEnable() + { + System.out.println("The Button Auto-flair Plugin by NorbiPeti (:P)"); + getServer().getPluginManager().registerEvents(new PlayerListener(), this); + this.getCommand("u").setExecutor(new Commands()); + this.getCommand("u").setUsage(this.getCommand("u").getUsage().replace('&', '§')); + Instance=this; //2015.08.08. + try { + File file=new File("flairsaccepted.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + //System.out.println("Name: " + name); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("flairsignored.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsignored.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("autoflairconfig.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + TownColors.put(s[0], s[1]); + } + br.close(); + } + //throw new IOException("Test"); //2015.08.09. + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + Runnable r=new Runnable(){public void run(){ThreadMethod();}}; + Thread t=new Thread(r); + t.start(); + } + Boolean stop=false; + // Fired when plugin is disabled + @Override + public void onDisable() + { + try + { + FileWriter fw; + fw = new FileWriter("flairsaccepted.txt"); + fw.close(); + fw = new FileWriter("flairsignored.txt"); + fw.close(); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + try { + File file=new File("flairsaccepted.txt"); + BufferedWriter bw=new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.AcceptedFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + file=new File("flairsignored.txt"); + bw = new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.IgnoredFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + stop=true; + } + + public void ThreadMethod() //<-- 2015.07.16. + { + while(!stop) + { + try + { + String body=DownloadString("https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/autoflair_system_comment_your_minecraft_name_and/.json?limit=1000"); + JSONArray json=new JSONArray(body).getJSONObject(1).getJSONObject("data").getJSONArray("children"); + for(Object obj : json) + { + JSONObject item = (JSONObject)obj; + String author=item.getJSONObject("data").getString("author"); + String ign=item.getJSONObject("data").getString("body"); + int start = ign.indexOf("IGN:") + "IGN:".length(); + int end = ign.indexOf(' ', start); + if (end == -1 || end == start) + end=ign.indexOf('\n', start); //2015.07.15. + if (end == -1 || end == start) + ign = ign.substring(start); + else + ign = ign.substring(start, end); + ign = ign.trim(); + if(HasIGFlair(ign)) + continue; + try { + Thread.sleep(10); + } catch(InterruptedException ex) { + Thread.currentThread().interrupt(); + } + String[] flairdata = DownloadString("http://karmadecay.com/thebutton-data.php?users=" + author).replace("\"", "").split(":"); + String flair; + if(flairdata.length > 1) //2015.07.15. + flair = flairdata[1]; + else + flair=""; + if (flair != "-1") + flair = flair + "s"; + else + flair = "non-presser"; + String flairclass; + if(flairdata.length>2) + flairclass = flairdata[2]; + else + flairclass="unknown"; + SetFlair(ign, flair, flairclass, author); + } + Thread.sleep(10000); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + } + + public static Exception LastException; //2015.08.09. + + public String DownloadString(String urlstr) throws MalformedURLException, IOException + { + URL url = new URL(urlstr); + URLConnection con = url.openConnection(); + con.setRequestProperty("User-Agent", "TheButtonAutoFlair"); + InputStream in = con.getInputStream(); + String encoding = con.getContentEncoding(); + encoding = encoding == null ? "UTF-8" : encoding; + String body = IOUtils.toString(in, encoding); + in.close(); + return body; + } + + public static Map TownColors=new HashMap(); //2015.07.20. + public Boolean HasIGFlair(String playername) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + return p.Flair!=null; //2015.08.08. + } + + public void SetFlair(String playername, String text, String flairclass, String username) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + String finalflair; + p.FlairDecided=true; + switch(flairclass) + { + case "press-1": + finalflair="§c("+text+")§r"; + break; + case "press-2": + finalflair="§6("+text+")§r"; + break; + case "press-3": + finalflair="§e("+text+")§r"; + break; + case "press-4": + finalflair="§a("+text+")§r"; + break; + case "press-5": + finalflair="§9("+text+")§r"; + break; + 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; + case "undecided": //2015.08.09. + p.FlairDecided=false; + finalflair=""; + break; + default: + finalflair=""; + break; + } + if(finalflair.length()==0) //<-- 2015.07.20. + return; + p.Flair=finalflair; //2015.08.08. + p.UserName=username; //2015.08.08. + System.out.println("Added new flair to "+playername+": "+finalflair); + for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08. + { + if(player.getName().equals(playername)) + { + AppendPlayerDisplayFlair(player, username, finalflair); + break; + } + } + } + + public static String GetFlair(Player player) + { //2015.07.16. + String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08. + return flair==null ? "" : flair; + } + + public static void AppendPlayerDisplayFlair(Player player, String username, String flair) + { + if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).IgnoredFlair) + return; + if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).AcceptedFlair) + { + AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + } + else + player.sendMessage("§9Are you Reddit user "+username+"?§r §6Type /u accept or /u ignore§r"); + } + + private static void AppendPlayerDisplayFlairFinal(Player player, String flair) + { //2015.07.20. + String color = GetColorForTown(GetPlayerTown(player)); //TO!DO: Multiple colors put on first capital letters + String[] colors = color.substring(1).split("§"); + String displayname=player.getName(); //2015.08.08. + ArrayList Positions=new ArrayList<>(); + for(int i=0; i=colors.length) + { + int x=0; + for(int i=0; i GetPlayers() + { + return Instance.getServer().getOnlinePlayers(); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/77/50df6a0f313e00151cbdba8b5f0a340e b/.metadata/.plugins/org.eclipse.core.resources/.history/77/50df6a0f313e00151cbdba8b5f0a340e deleted file mode 100644 index 1cd84d0..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/77/50df6a0f313e00151cbdba8b5f0a340e +++ /dev/null @@ -1,126 +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; - 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/78/40118f77873e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/78/40118f77873e00151ce8ff6d4f74dabd deleted file mode 100644 index 68ec621..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/78/40118f77873e00151ce8ff6d4f74dabd +++ /dev/null @@ -1,145 +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; - MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. - //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - if(p.Flair==null) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. - { - case "accept": - { - if(p.IgnoredFlair) - p.IgnoredFlair=false; //2015.08.08. - if(!p.AcceptedFlair) - { - String flair=p.Flair; //2015.08.08. - PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. - p.AcceptedFlair=true; //2015.08.08. - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("§cYou already have this user's flair.§r"); - break; - } - case "ignore": - { - if(p.AcceptedFlair) - p.AcceptedFlair=false; //2015.08.08. - if(!p.IgnoredFlair) - { - p.IgnoredFlair=true; - String flair=p.Flair; //2015.08.08. - PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. - player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); - } - else - player.sendMessage("§cYou already ignored this request.§r"); - break; - } - /*case "reload": //2015.07.20. - DoReload(player); - break;*/ - case "admin": //2015.08.09. - DoAdmin(player, args); - break; - default: - return false; - } - return true; - } - - /*if(args[0].toLowerCase()=="reload") - DoReload(null); //2015.07.20.*/ - else if(args[0].toLowerCase()=="admin") - DoAdmin(null, args); //2015.08.09. - return false; - } - private static void DoReload(Player player) - { //2015.07.20. - //if(player==null || player.isOp() || player.getName()=="NorbiPeti") - //{ - try - { - File file=new File("autoflairconfig.txt"); - if(file.exists()) - { - PluginMain.TownColors.clear(); - BufferedReader br=new BufferedReader(new FileReader(file)); - String line; - while((line=br.readLine())!=null) - { - String[] s=line.split(" "); - PluginMain.TownColors.put(s[0], s[1]); - } - br.close(); - for(Player p : PluginMain.GetPlayers()) - { - MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName()); - if(mp.Flair!=null) - { - String flair=mp.Flair; - PluginMain.RemovePlayerDisplayFlairFinal(p, flair); - PluginMain.AppendPlayerDisplayFlairFinal(p, flair); - } - } - String msg="§6Reloaded config file.§r"; - if(player!=null) - player.sendMessage(msg); - else - System.out.println(msg); - } - } - catch(Exception e) - { - System.out.println("Error!\n"+e); - if(player!=null) - player.sendMessage("§cAn error occured. See console for details.§r"); - } - //} - //else - //player.sendMessage("§cYou need to be OP to use this command.§r"); - } - private static void DoAdmin(Player player, String[] args) - { - if(player==null || player.isOp() || player.getName()=="NorbiPeti") - { - //args[0] is "admin" - switch(args[1].toLowerCase()) - { - case "reload": - DoReload(player); - break; - case "playerinfo": - DoPlayerInfo(player, args); - break; - } - } - else - player.sendMessage("§cYou need to be OP to use this command.§r"); - } - private static void DoPlayerInfo(Player player, String[] args) - { - //args[0] is "admin" - args[1] is "playerinfo" - w - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/78/804750c0843e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/78/804750c0843e00151ce8ff6d4f74dabd deleted file mode 100644 index cf9d482..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/78/804750c0843e00151ce8ff6d4f74dabd +++ /dev/null @@ -1,119 +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; - MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. - //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - if(p.Flair==null) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - { - if(p.IgnoredFlair) - p.IgnoredFlair=false; //2015.08.08. - if(!p.AcceptedFlair) - { - String flair=p.Flair; //2015.08.08. - PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. - p.AcceptedFlair=true; //2015.08.08. - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("§cYou already have this user's flair.§r"); - break; - } - case "ignore": - { - if(p.AcceptedFlair) - p.AcceptedFlair=false; //2015.08.08. - if(!p.IgnoredFlair) - { - p.IgnoredFlair=true; - String flair=p.Flair; //2015.08.08. - PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. - player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); - } - else - player.sendMessage("§cYou already ignored this request.§r"); - break; - } - case "reload": //2015.07.20. - DoReload(player); - break; - case "showerrors": //2015.08.08. - break; - default: - return false; - } - return true; - } - - if(args[0]=="reload") - DoReload(null); //2015.07.20. - return false; - } - private static void DoReload(Player player) - { //2015.07.20. - if(player==null || player.isOp() || player.getName()=="NorbiPeti") - { - try - { - File file=new File("autoflairconfig.txt"); - if(file.exists()) - { - PluginMain.TownColors.clear(); - BufferedReader br=new BufferedReader(new FileReader(file)); - String line; - while((line=br.readLine())!=null) - { - String[] s=line.split(" "); - PluginMain.TownColors.put(s[0], s[1]); - } - br.close(); - for(Player p : PluginMain.GetPlayers()) - { - MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName()); - if(mp.Flair!=null) - { - String flair=mp.Flair; - PluginMain.RemovePlayerDisplayFlairFinal(p, flair); - PluginMain.AppendPlayerDisplayFlairFinal(p, flair); - } - } - String msg="§6Reloaded config file.§r"; - if(player!=null) - player.sendMessage(msg); - else - System.out.println(msg); - } - } - catch(Exception e) - { - System.out.println("Error!\n"+e); - if(player!=null) - player.sendMessage("§cAn error occured. See console for details.§r"); - } - } - else - player.sendMessage("§cYou need to be OP to use this command.§r"); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/78/a0991cb7d13e001518fa86d7ae2a1cf8 b/.metadata/.plugins/org.eclipse.core.resources/.history/78/a0991cb7d13e001518fa86d7ae2a1cf8 new file mode 100644 index 0000000..2a4b609 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/78/a0991cb7d13e001518fa86d7ae2a1cf8 @@ -0,0 +1,370 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStream; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLConnection; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + +import org.apache.commons.io.IOUtils; +import org.bukkit.entity.Player; +import org.bukkit.plugin.java.JavaPlugin; +import org.json.JSONArray; +import org.json.JSONObject; + +import com.palmergames.bukkit.towny.object.Town; +import com.palmergames.bukkit.towny.object.WorldCoord; + +public class PluginMain extends JavaPlugin +{ //Translated to Java: 2015.07.15. + //A user, which flair isn't obtainable: + //https://www.reddit.com/r/thebutton/comments/31c32v/i_pressed_the_button_without_really_thinking/ + private static PluginMain Instance; + // Fired when plugin is first enabled + @Override + public void onEnable() + { + System.out.println("The Button Auto-flair Plugin by NorbiPeti (:P)"); + getServer().getPluginManager().registerEvents(new PlayerListener(), this); + this.getCommand("u").setExecutor(new Commands()); + this.getCommand("u").setUsage(this.getCommand("u").getUsage().replace('&', '§')); + Instance=this; //2015.08.08. + LoadFiles(false); //2015.08.09. + Runnable r=new Runnable(){public void run(){ThreadMethod();}}; + Thread t=new Thread(r); + t.start(); + } + Boolean stop=false; + // Fired when plugin is disabled + @Override + public void onDisable() + { + try + { + FileWriter fw; + fw = new FileWriter("flairsaccepted.txt"); + fw.close(); + fw = new FileWriter("flairsignored.txt"); + fw.close(); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + try { + File file=new File("flairsaccepted.txt"); + BufferedWriter bw=new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.AcceptedFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + file=new File("flairsignored.txt"); + bw = new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.IgnoredFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + stop=true; + } + + public void ThreadMethod() //<-- 2015.07.16. + { + while(!stop) + { + try + { + String body=DownloadString("https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/autoflair_system_comment_your_minecraft_name_and/.json?limit=1000"); + JSONArray json=new JSONArray(body).getJSONObject(1).getJSONObject("data").getJSONArray("children"); + for(Object obj : json) + { + JSONObject item = (JSONObject)obj; + String author=item.getJSONObject("data").getString("author"); + String ign=item.getJSONObject("data").getString("body"); + int start = ign.indexOf("IGN:") + "IGN:".length(); + int end = ign.indexOf(' ', start); + if (end == -1 || end == start) + end=ign.indexOf('\n', start); //2015.07.15. + if (end == -1 || end == start) + ign = ign.substring(start); + else + ign = ign.substring(start, end); + ign = ign.trim(); + if(HasIGFlair(ign)) + continue; + try { + Thread.sleep(10); + } catch(InterruptedException ex) { + Thread.currentThread().interrupt(); + } + String[] flairdata = DownloadString("http://karmadecay.com/thebutton-data.php?users=" + author).replace("\"", "").split(":"); + String flair; + if(flairdata.length > 1) //2015.07.15. + flair = flairdata[1]; + else + flair=""; + if (flair != "-1") + flair = flair + "s"; + else + flair = "non-presser"; + String flairclass; + if(flairdata.length>2) + flairclass = flairdata[2]; + else + flairclass="unknown"; + SetFlair(ign, flair, flairclass, author); + } + Thread.sleep(10000); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + } + + public static Exception LastException; //2015.08.09. + + public String DownloadString(String urlstr) throws MalformedURLException, IOException + { + URL url = new URL(urlstr); + URLConnection con = url.openConnection(); + con.setRequestProperty("User-Agent", "TheButtonAutoFlair"); + InputStream in = con.getInputStream(); + String encoding = con.getContentEncoding(); + encoding = encoding == null ? "UTF-8" : encoding; + String body = IOUtils.toString(in, encoding); + in.close(); + return body; + } + + public static Map TownColors=new HashMap(); //2015.07.20. + public Boolean HasIGFlair(String playername) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + return p.Flair!=null; //2015.08.08. + } + + public void SetFlair(String playername, String text, String flairclass, String username) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + String finalflair; + p.FlairDecided=true; + switch(flairclass) + { + case "press-1": + finalflair="§c("+text+")§r"; + break; + case "press-2": + finalflair="§6("+text+")§r"; + break; + case "press-3": + finalflair="§e("+text+")§r"; + break; + case "press-4": + finalflair="§a("+text+")§r"; + break; + case "press-5": + finalflair="§9("+text+")§r"; + break; + 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; + case "undecided": //2015.08.09. + p.FlairDecided=false; + finalflair=""; + break; + default: + finalflair=""; + break; + } + if(finalflair.length()==0) //<-- 2015.07.20. + return; + p.Flair=finalflair; //2015.08.08. + p.UserName=username; //2015.08.08. + System.out.println("Added new flair to "+playername+": "+finalflair); + for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08. + { + if(player.getName().equals(playername)) + { + //AppendPlayerDisplayFlair(player, username, finalflair); + AppendPlayerDisplayFlair(p, player); + break; + } + } + } + + public static String GetFlair(Player player) + { //2015.07.16. + String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08. + return flair==null ? "" : flair; + } + + //public static void AppendPlayerDisplayFlair(Player player, String username, String flair) + public static void AppendPlayerDisplayFlair(MaybeOfflinePlayer player, Player p) //<-- 2015.08.09. + { + + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).IgnoredFlair) + return; + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).AcceptedFlair) + { + AppendPlayerDisplayFlairFinal(p, player.Flair); //2015.07.20. + if(!player.FlairDecided) + p.sendMessage("§9Your flair type is unknown. Are you a non-presser or a can't press? (/u nonpresser or /u cantpress)§r"); //2015.08.09. + } + else + p.sendMessage("§9Are you Reddit user "+player.UserName+"?§r §6Type /u accept or /u ignore§r"); + } + + private static void AppendPlayerDisplayFlairFinal(Player player, String flair) + { //2015.07.20. + String color = GetColorForTown(GetPlayerTown(player)); //TO!DO: Multiple colors put on first capital letters + String[] colors = color.substring(1).split("§"); + String displayname=player.getName(); //2015.08.08. + ArrayList Positions=new ArrayList<>(); + for(int i=0; i=colors.length) + { + int x=0; + for(int i=0; i GetPlayers() + { + return Instance.getServer().getOnlinePlayers(); + } + + public static void LoadFiles(boolean reload) + { + if(reload) + MaybeOfflinePlayer.AllPlayers.clear(); + try { + File file=new File("flairsaccepted.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + //System.out.println("Name: " + name); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("flairsignored.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsignored.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("autoflairconfig.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + TownColors.put(s[0], s[1]); + } + br.close(); + } + //throw new IOException("Test"); //2015.08.09. + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/79/106a6cf8dc3e001517108d149b613203 b/.metadata/.plugins/org.eclipse.core.resources/.history/79/106a6cf8dc3e001517108d149b613203 new file mode 100644 index 0000000..56c16c3 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/79/106a6cf8dc3e001517108d149b613203 @@ -0,0 +1,394 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStream; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLConnection; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + +import org.apache.commons.io.IOUtils; +import org.bukkit.entity.Player; +import org.bukkit.plugin.java.JavaPlugin; +import org.json.JSONArray; +import org.json.JSONObject; + +import com.palmergames.bukkit.towny.object.Town; +import com.palmergames.bukkit.towny.object.WorldCoord; + +public class PluginMain extends JavaPlugin +{ //Translated to Java: 2015.07.15. + //A user, which flair isn't obtainable: + //https://www.reddit.com/r/thebutton/comments/31c32v/i_pressed_the_button_without_really_thinking/ + private static PluginMain Instance; + // Fired when plugin is first enabled + @Override + public void onEnable() + { + System.out.println("The Button Auto-flair Plugin by NorbiPeti (:P)"); + getServer().getPluginManager().registerEvents(new PlayerListener(), this); + this.getCommand("u").setExecutor(new Commands()); + this.getCommand("u").setUsage(this.getCommand("u").getUsage().replace('&', '§')); + Instance=this; //2015.08.08. + LoadFiles(false); //2015.08.09. + Runnable r=new Runnable(){public void run(){ThreadMethod();}}; + Thread t=new Thread(r); + t.start(); + } + Boolean stop=false; + // Fired when plugin is disabled + @Override + public void onDisable() + { + SaveFiles(); //2015.08.09. + stop=true; + } + + public void ThreadMethod() //<-- 2015.07.16. + { + while(!stop) + { + try + { + String body=DownloadString("https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/autoflair_system_comment_your_minecraft_name_and/.json?limit=1000"); + JSONArray json=new JSONArray(body).getJSONObject(1).getJSONObject("data").getJSONArray("children"); + for(Object obj : json) + { + JSONObject item = (JSONObject)obj; + String author=item.getJSONObject("data").getString("author"); + String ign=item.getJSONObject("data").getString("body"); + int start = ign.indexOf("IGN:") + "IGN:".length(); + if(start==-1) + continue; //2015.08.09. + int end = ign.indexOf(' ', start); + if (end == -1 || end == start) + end=ign.indexOf('\n', start); //2015.07.15. + if (end == -1 || end == start) + ign = ign.substring(start); + else + ign = ign.substring(start, end); + ign = ign.trim(); + if(HasIGFlair(ign)) + continue; + try { + Thread.sleep(10); + } catch(InterruptedException ex) { + Thread.currentThread().interrupt(); + } + String[] flairdata = DownloadString("http://karmadecay.com/thebutton-data.php?users=" + author).replace("\"", "").split(":"); + String flair; + if(flairdata.length > 1) //2015.07.15. + flair = flairdata[1]; + else + flair=""; + if (flair != "-1") + flair = flair + "s"; + else + flair = "non-presser"; + String flairclass; + if(flairdata.length>2) + flairclass = flairdata[2]; + else + flairclass="unknown"; + SetFlair(ign, flair, flairclass, author); + } + Thread.sleep(10000); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + } + + public static Exception LastException; //2015.08.09. + + public String DownloadString(String urlstr) throws MalformedURLException, IOException + { + URL url = new URL(urlstr); + URLConnection con = url.openConnection(); + con.setRequestProperty("User-Agent", "TheButtonAutoFlair"); + InputStream in = con.getInputStream(); + String encoding = con.getContentEncoding(); + encoding = encoding == null ? "UTF-8" : encoding; + String body = IOUtils.toString(in, encoding); + in.close(); + return body; + } + + public static Map TownColors=new HashMap(); //2015.07.20. + public Boolean HasIGFlair(String playername) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + return p.Flair!=null; //2015.08.08. + } + + public void SetFlair(String playername, String text, String flairclass, String username) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + String finalflair; + p.FlairDecided=true; + switch(flairclass) + { + case "press-1": + finalflair="§c("+text+")§r"; + break; + case "press-2": + finalflair="§6("+text+")§r"; + break; + case "press-3": + finalflair="§e("+text+")§r"; + break; + case "press-4": + finalflair="§a("+text+")§r"; + break; + case "press-5": + finalflair="§9("+text+")§r"; + break; + 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; + case "undecided": //2015.08.09. + p.FlairDecided=false; + finalflair=""; + break; + default: + finalflair=""; + break; + } + if(finalflair.length()==0) //<-- 2015.07.20. + return; + p.Flair=finalflair; //2015.08.08. + p.UserName=username; //2015.08.08. + System.out.println("Added new flair to "+playername+": "+finalflair); + for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08. + { + if(player.getName().equals(playername)) + { + //AppendPlayerDisplayFlair(player, username, finalflair); + AppendPlayerDisplayFlair(p, player); + break; + } + } + } + + public static String GetFlair(Player player) + { //2015.07.16. + String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08. + return flair==null ? "" : flair; + } + + //public static void AppendPlayerDisplayFlair(Player player, String username, String flair) + public static void AppendPlayerDisplayFlair(MaybeOfflinePlayer player, Player p) //<-- 2015.08.09. + { + + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).IgnoredFlair) + return; + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).AcceptedFlair) + { + AppendPlayerDisplayFlairFinal(p, player.Flair); //2015.07.20. + if(!player.FlairDecided) + p.sendMessage("§9Your flair type is unknown. Are you a non-presser or a can't press? (/u nonpresser or /u cantpress)§r"); //2015.08.09. + } + else + p.sendMessage("§9Are you Reddit user "+player.UserName+"?§r §6Type /u accept or /u ignore§r"); + } + + private static void AppendPlayerDisplayFlairFinal(Player player, String flair) + { //2015.07.20. + String color = GetColorForTown(GetPlayerTown(player)); //TO!DO: Multiple colors put on first capital letters + String[] colors = color.substring(1).split("§"); + String displayname=player.getName(); //2015.08.08. + ArrayList Positions=new ArrayList<>(); + for(int i=0; i=colors.length) + { + int x=0; + for(int i=0; i GetPlayers() + { + return Instance.getServer().getOnlinePlayers(); + } + + public static void LoadFiles(boolean reload) //<-- 2015.08.09. + { + if(reload) + { //2015.08.09. + System.out.println("Auto-flair plugin cleanup for reloading..."); + MaybeOfflinePlayer.AllPlayers.clear(); + TownColors.clear(); + } + System.out.println("Loading files for auto-flair plugin..."); //2015.08.09. + try { + File file=new File("flairsaccepted.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + //System.out.println("Name: " + name); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("flairsignored.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsignored.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("autoflairconfig.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + TownColors.put(s[0], s[1]); + } + br.close(); + } + file=new File("autoflairdecisions.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + MaybeOfflinePlayer.AddPlayerIfNeeded(s[0]).Flair=s[1]; + } + br.close(); + } + //throw new IOException("Test"); //2015.08.09. + System.out.println("Auto-flair plugin loaded files!"); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + public static void SaveFiles() //<-- 2015.08.09. + { + try + { + FileWriter fw; + fw = new FileWriter("flairsaccepted.txt"); + fw.close(); + fw = new FileWriter("flairsignored.txt"); + fw.close(); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + try { + File file=new File("flairsaccepted.txt"); + BufferedWriter bw=new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.AcceptedFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + file=new File("flairsignored.txt"); + bw = new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.IgnoredFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/7a/4046a21a013e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/7a/4046a21a013e00151c31fb33fff4337f deleted file mode 100644 index c604fd3..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/7a/4046a21a013e00151c31fb33fff4337f +++ /dev/null @@ -1,123 +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": - { - 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/7b/c081221f023e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/7b/c081221f023e00151c31fb33fff4337f deleted file mode 100644 index 7a8d627..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/7b/c081221f023e00151c31fb33fff4337f +++ /dev/null @@ -1,125 +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; - 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/7c/3014764dcd3e001518fa86d7ae2a1cf8 b/.metadata/.plugins/org.eclipse.core.resources/.history/7c/3014764dcd3e001518fa86d7ae2a1cf8 new file mode 100644 index 0000000..c8a5a26 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/7c/3014764dcd3e001518fa86d7ae2a1cf8 @@ -0,0 +1,31 @@ +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 + 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); + } + public enum FlairClassType + { //2015.08.09. + NonPresser, + CantPress, + Undecided + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/7c/a0934f14cf3e001518fa86d7ae2a1cf8 b/.metadata/.plugins/org.eclipse.core.resources/.history/7c/a0934f14cf3e001518fa86d7ae2a1cf8 new file mode 100644 index 0000000..ad8a270 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/7c/a0934f14cf3e001518fa86d7ae2a1cf8 @@ -0,0 +1,362 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStream; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLConnection; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + +import org.apache.commons.io.IOUtils; +import org.bukkit.entity.Player; +import org.bukkit.plugin.java.JavaPlugin; +import org.json.JSONArray; +import org.json.JSONObject; + +import tk.sznp.thebuttonautoflair.MaybeOfflinePlayer.FlairClassType; + +import com.palmergames.bukkit.towny.object.Town; +import com.palmergames.bukkit.towny.object.WorldCoord; + +public class PluginMain extends JavaPlugin +{ //Translated to Java: 2015.07.15. + //A user, which flair isn't obtainable: + //https://www.reddit.com/r/thebutton/comments/31c32v/i_pressed_the_button_without_really_thinking/ + private static PluginMain Instance; + // Fired when plugin is first enabled + @Override + public void onEnable() + { + System.out.println("The Button Auto-flair Plugin by NorbiPeti (:P)"); + getServer().getPluginManager().registerEvents(new PlayerListener(), this); + this.getCommand("u").setExecutor(new Commands()); + this.getCommand("u").setUsage(this.getCommand("u").getUsage().replace('&', '§')); + Instance=this; //2015.08.08. + try { + File file=new File("flairsaccepted.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + //System.out.println("Name: " + name); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("flairsignored.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsignored.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("autoflairconfig.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + TownColors.put(s[0], s[1]); + } + br.close(); + } + //throw new IOException("Test"); //2015.08.09. + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + Runnable r=new Runnable(){public void run(){ThreadMethod();}}; + Thread t=new Thread(r); + t.start(); + } + Boolean stop=false; + // Fired when plugin is disabled + @Override + public void onDisable() + { + try + { + FileWriter fw; + fw = new FileWriter("flairsaccepted.txt"); + fw.close(); + fw = new FileWriter("flairsignored.txt"); + fw.close(); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + try { + File file=new File("flairsaccepted.txt"); + BufferedWriter bw=new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.AcceptedFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + file=new File("flairsignored.txt"); + bw = new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.IgnoredFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + stop=true; + } + + public void ThreadMethod() //<-- 2015.07.16. + { + while(!stop) + { + try + { + String body=DownloadString("https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/autoflair_system_comment_your_minecraft_name_and/.json?limit=1000"); + JSONArray json=new JSONArray(body).getJSONObject(1).getJSONObject("data").getJSONArray("children"); + for(Object obj : json) + { + JSONObject item = (JSONObject)obj; + String author=item.getJSONObject("data").getString("author"); + String ign=item.getJSONObject("data").getString("body"); + int start = ign.indexOf("IGN:") + "IGN:".length(); + int end = ign.indexOf(' ', start); + if (end == -1 || end == start) + end=ign.indexOf('\n', start); //2015.07.15. + if (end == -1 || end == start) + ign = ign.substring(start); + else + ign = ign.substring(start, end); + ign = ign.trim(); + if(HasIGFlair(ign)) + continue; + try { + Thread.sleep(10); + } catch(InterruptedException ex) { + Thread.currentThread().interrupt(); + } + String[] flairdata = DownloadString("http://karmadecay.com/thebutton-data.php?users=" + author).replace("\"", "").split(":"); + String flair; + if(flairdata.length > 1) //2015.07.15. + flair = flairdata[1]; + else + flair=""; + if (flair != "-1") + flair = flair + "s"; + else + flair = "non-presser"; + String flairclass; + if(flairdata.length>2) + flairclass = flairdata[2]; + else + flairclass="unknown"; + SetFlair(ign, flair, flairclass, author); + } + Thread.sleep(10000); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + } + + public static Exception LastException; //2015.08.09. + + public String DownloadString(String urlstr) throws MalformedURLException, IOException + { + URL url = new URL(urlstr); + URLConnection con = url.openConnection(); + con.setRequestProperty("User-Agent", "TheButtonAutoFlair"); + InputStream in = con.getInputStream(); + String encoding = con.getContentEncoding(); + encoding = encoding == null ? "UTF-8" : encoding; + String body = IOUtils.toString(in, encoding); + in.close(); + return body; + } + + public static Map TownColors=new HashMap(); //2015.07.20. + public Boolean HasIGFlair(String playername) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + return p.Flair!=null; //2015.08.08. + } + + public void SetFlair(String playername, String text, String flairclass, String username) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + String finalflair; + p.FlairDecided=true; + switch(flairclass) + { + case "press-1": + finalflair="§c("+text+")§r"; + break; + case "press-2": + finalflair="§6("+text+")§r"; + break; + case "press-3": + finalflair="§e("+text+")§r"; + break; + case "press-4": + finalflair="§a("+text+")§r"; + break; + case "press-5": + finalflair="§9("+text+")§r"; + break; + 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; + case "undecided": //2015.08.09. + p.FlairDecided=false; + finalflair=""; + break; + default: + finalflair=""; + break; + } + if(finalflair.length()==0) //<-- 2015.07.20. + return; + p.Flair=finalflair; //2015.08.08. + p.UserName=username; //2015.08.08. + System.out.println("Added new flair to "+playername+": "+finalflair); + for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08. + { + if(player.getName().equals(playername)) + { + AppendPlayerDisplayFlair(player, username, finalflair); + break; + } + } + } + + public static String GetFlair(Player player) + { //2015.07.16. + String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08. + return flair==null ? "" : flair; + } + + //public static void AppendPlayerDisplayFlair(Player player, String username, String flair) + public static void AppendPlayerDisplayFlair(MaybeOfflinePlayer player, Player p) + { + + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).IgnoredFlair) + return; + if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).AcceptedFlair) + { + AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + } + else + player.sendMessage("§9Are you Reddit user "+username+"?§r §6Type /u accept or /u ignore§r"); + } + + private static void AppendPlayerDisplayFlairFinal(Player player, String flair) + { //2015.07.20. + String color = GetColorForTown(GetPlayerTown(player)); //TO!DO: Multiple colors put on first capital letters + String[] colors = color.substring(1).split("§"); + String displayname=player.getName(); //2015.08.08. + ArrayList Positions=new ArrayList<>(); + for(int i=0; i=colors.length) + { + int x=0; + for(int i=0; i GetPlayers() + { + return Instance.getServer().getOnlinePlayers(); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/7d/10c43d1bdf3e001517108d149b613203 b/.metadata/.plugins/org.eclipse.core.resources/.history/7d/10c43d1bdf3e001517108d149b613203 new file mode 100644 index 0000000..eac777b --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/7d/10c43d1bdf3e001517108d149b613203 @@ -0,0 +1,250 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +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; + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. + //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) + if(p.Flair==null) + { + player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); + return true; + } + switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. + { + case "accept": + { + if(p.IgnoredFlair) + p.IgnoredFlair=false; //2015.08.08. + if(!p.AcceptedFlair) + { + String flair=p.Flair; //2015.08.08. + //PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + PluginMain.AppendPlayerDisplayFlair(p, player); + p.AcceptedFlair=true; //2015.08.08. + player.sendMessage("§6Your flair has been set:§r "+flair); + } + else + player.sendMessage("§cYou already have this user's flair.§r"); + break; + } + case "ignore": + { + if(p.AcceptedFlair) + p.AcceptedFlair=false; //2015.08.08. + if(!p.IgnoredFlair) + { + p.IgnoredFlair=true; + String flair=p.Flair; //2015.08.08. + PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. + player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); + } + else + player.sendMessage("§cYou already ignored this request.§r"); + break; + } + /*case "reload": //2015.07.20. + DoReload(player); + break;*/ + case "admin": //2015.08.09. + DoAdmin(player, args); + break; + case "nonpresser": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§7(non-pr.)§r"; + break; + case "cantpress": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§r(can't press)§r"; + break; + default: + return false; + } + return true; + } + /*if(args[0].toLowerCase()=="reload") + DoReload(null); //2015.07.20.*/ + else if(args.length>0 && args[0].toLowerCase().equals("admin")) //2015.08.09. + { + DoAdmin(null, args); //2015.08.09. + return true; //2015.08.09. + } + return false; + } + private static void DoReload(Player player) + { //2015.07.20. + //if(player==null || player.isOp() || player.getName()=="NorbiPeti") + //{ + try + { + File file=new File("autoflairconfig.txt"); + if(file.exists()) + { + PluginMain.LoadFiles(true); //2015.08.09. + for(Player p : PluginMain.GetPlayers()) + { + MaybeOfflinePlayer mp = MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName()); + if(mp.Flair!=null) + { + String flair=mp.Flair; + PluginMain.RemovePlayerDisplayFlairFinal(p, flair); + //PluginMain.AppendPlayerDisplayFlairFinal(p, flair); + PluginMain.AppendPlayerDisplayFlair(mp, p); //2015.08.09. + } + String msg="§6Note: The auto-flair plugin has been reloaded. You might need to wait 10s to have your flair.§r"; //2015.08.09. + p.sendMessage(msg); //2015.08.09. + } + //String msg="§6Reloaded config file.§r"; + //SendMessage(player, msg); //2015.08.09. + } + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + if(player!=null) + player.sendMessage("§cAn error occured. See console for details.§r"); + PluginMain.LastException=e; //2015.08.09. + } + //} + //else + //player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static Player ReloadPlayer; //2015.08.09. + private static void DoAdmin(Player player, String[] args) + { //2015.08.09. + if(player==null || player.isOp() || player.getName()=="NorbiPeti") + { + //System.out.println("Args length: " + args.length); + if(args.length==1) + { + String message="§cUsage: /u admin reload|playerinfo§r"; + SendMessage(player, message); + return; + } + //args[0] is "admin" + switch(args[1].toLowerCase()) + { + case "reload": + ReloadPlayer=player; //2015.08.09. + SendMessage(player, "§6Make sure to save the current settings before you modify and reload them! Type /u admin confirm when done.§r"); + break; + case "playerinfo": + DoPlayerInfo(player, args); + break; + case "getlasterror": + DoGetLastError(player, args); + case "confirm": + if(ReloadPlayer==player) + DoReload(player); //2015.08.09. + else + SendMessage(player, "§cYou need to do /u admin reload first.§r"); + break; + case "save": + PluginMain.SaveFiles(); //2015.08.09. + SendMessage(player, "§6Saved files. Now you can edit them and reload if you want.§r"); + break; + default: + String message="§cUsage: /u admin reload|playerinfo|getlasterror§r"; + SendMessage(player, message); + return; + } + } + else + player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static void DoPlayerInfo(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "playerinfo" + if(args.length==2) + { + String message="§cUsage: /u admin playerinfo §r"; + SendMessage(player, message); + return; + } + if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2])) + { + String message="§cPlayer not found: "+args[2]+"§r"; + SendMessage(player, message); + return; + } + MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]); + SendMessage(player, "Player name: "+p.PlayerName); + SendMessage(player, "User flair: "+p.Flair); + SendMessage(player, "Username: "+p.UserName); + SendMessage(player, "Flair accepted: "+p.AcceptedFlair); + SendMessage(player, "Flair ignored: "+p.IgnoredFlair); + } + private static void SendMessage(Player player, String message) + { //2015.08.09. + if(player==null) + System.out.println(message); + else + player.sendMessage(message); + } + private static void DoGetLastError(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "getlasterror" + if(PluginMain.LastException!=null) + { + SendMessage(player, "Last error:"); + SendMessage(player, PluginMain.LastException.toString()); + PluginMain.LastException=null; + } + else + SendMessage(player, "There were no exceptions."); + } + private static void SetPlayerFlair(Player player, String flair) + { //2015.08.09. + flair=flair.replace('&', '§'); + MaybeOfflinePlayer.AddPlayerIfNeeded(player.getName()).Flair=flair; + if(!PluginMain.RemoveLineFromFile("customflairs.txt")) + { + SendMessage(player, "Error removing previous custom flair!"); + } + File file=new File("customflairs.txt"); + try { + BufferedWriter bw; + bw = new BufferedWriter(new FileWriter(file, true)); + bw.write(player.getName()+"\n"); + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + PluginMain.LastException=e; //2015.08.09. + } + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/7d/a005617fd13e001518fa86d7ae2a1cf8 b/.metadata/.plugins/org.eclipse.core.resources/.history/7d/a005617fd13e001518fa86d7ae2a1cf8 new file mode 100644 index 0000000..dbcf375 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/7d/a005617fd13e001518fa86d7ae2a1cf8 @@ -0,0 +1,363 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStream; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLConnection; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + +import org.apache.commons.io.IOUtils; +import org.bukkit.entity.Player; +import org.bukkit.plugin.java.JavaPlugin; +import org.json.JSONArray; +import org.json.JSONObject; + +import com.palmergames.bukkit.towny.object.Town; +import com.palmergames.bukkit.towny.object.WorldCoord; + +public class PluginMain extends JavaPlugin +{ //Translated to Java: 2015.07.15. + //A user, which flair isn't obtainable: + //https://www.reddit.com/r/thebutton/comments/31c32v/i_pressed_the_button_without_really_thinking/ + private static PluginMain Instance; + // Fired when plugin is first enabled + @Override + public void onEnable() + { + System.out.println("The Button Auto-flair Plugin by NorbiPeti (:P)"); + getServer().getPluginManager().registerEvents(new PlayerListener(), this); + this.getCommand("u").setExecutor(new Commands()); + this.getCommand("u").setUsage(this.getCommand("u").getUsage().replace('&', '§')); + Instance=this; //2015.08.08. + try { + File file=new File("flairsaccepted.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + //System.out.println("Name: " + name); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("flairsignored.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsignored.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("autoflairconfig.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + TownColors.put(s[0], s[1]); + } + br.close(); + } + //throw new IOException("Test"); //2015.08.09. + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + Runnable r=new Runnable(){public void run(){ThreadMethod();}}; + Thread t=new Thread(r); + t.start(); + } + Boolean stop=false; + // Fired when plugin is disabled + @Override + public void onDisable() + { + try + { + FileWriter fw; + fw = new FileWriter("flairsaccepted.txt"); + fw.close(); + fw = new FileWriter("flairsignored.txt"); + fw.close(); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + try { + File file=new File("flairsaccepted.txt"); + BufferedWriter bw=new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.AcceptedFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + file=new File("flairsignored.txt"); + bw = new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.IgnoredFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + stop=true; + } + + public void ThreadMethod() //<-- 2015.07.16. + { + while(!stop) + { + try + { + String body=DownloadString("https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/autoflair_system_comment_your_minecraft_name_and/.json?limit=1000"); + JSONArray json=new JSONArray(body).getJSONObject(1).getJSONObject("data").getJSONArray("children"); + for(Object obj : json) + { + JSONObject item = (JSONObject)obj; + String author=item.getJSONObject("data").getString("author"); + String ign=item.getJSONObject("data").getString("body"); + int start = ign.indexOf("IGN:") + "IGN:".length(); + int end = ign.indexOf(' ', start); + if (end == -1 || end == start) + end=ign.indexOf('\n', start); //2015.07.15. + if (end == -1 || end == start) + ign = ign.substring(start); + else + ign = ign.substring(start, end); + ign = ign.trim(); + if(HasIGFlair(ign)) + continue; + try { + Thread.sleep(10); + } catch(InterruptedException ex) { + Thread.currentThread().interrupt(); + } + String[] flairdata = DownloadString("http://karmadecay.com/thebutton-data.php?users=" + author).replace("\"", "").split(":"); + String flair; + if(flairdata.length > 1) //2015.07.15. + flair = flairdata[1]; + else + flair=""; + if (flair != "-1") + flair = flair + "s"; + else + flair = "non-presser"; + String flairclass; + if(flairdata.length>2) + flairclass = flairdata[2]; + else + flairclass="unknown"; + SetFlair(ign, flair, flairclass, author); + } + Thread.sleep(10000); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + } + + public static Exception LastException; //2015.08.09. + + public String DownloadString(String urlstr) throws MalformedURLException, IOException + { + URL url = new URL(urlstr); + URLConnection con = url.openConnection(); + con.setRequestProperty("User-Agent", "TheButtonAutoFlair"); + InputStream in = con.getInputStream(); + String encoding = con.getContentEncoding(); + encoding = encoding == null ? "UTF-8" : encoding; + String body = IOUtils.toString(in, encoding); + in.close(); + return body; + } + + public static Map TownColors=new HashMap(); //2015.07.20. + public Boolean HasIGFlair(String playername) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + return p.Flair!=null; //2015.08.08. + } + + public void SetFlair(String playername, String text, String flairclass, String username) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + String finalflair; + p.FlairDecided=true; + switch(flairclass) + { + case "press-1": + finalflair="§c("+text+")§r"; + break; + case "press-2": + finalflair="§6("+text+")§r"; + break; + case "press-3": + finalflair="§e("+text+")§r"; + break; + case "press-4": + finalflair="§a("+text+")§r"; + break; + case "press-5": + finalflair="§9("+text+")§r"; + break; + 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; + case "undecided": //2015.08.09. + p.FlairDecided=false; + finalflair=""; + break; + default: + finalflair=""; + break; + } + if(finalflair.length()==0) //<-- 2015.07.20. + return; + p.Flair=finalflair; //2015.08.08. + p.UserName=username; //2015.08.08. + System.out.println("Added new flair to "+playername+": "+finalflair); + for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08. + { + if(player.getName().equals(playername)) + { + //AppendPlayerDisplayFlair(player, username, finalflair); + AppendPlayerDisplayFlair(p, player); + break; + } + } + } + + public static String GetFlair(Player player) + { //2015.07.16. + String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08. + return flair==null ? "" : flair; + } + + //public static void AppendPlayerDisplayFlair(Player player, String username, String flair) + public static void AppendPlayerDisplayFlair(MaybeOfflinePlayer player, Player p) //<-- 2015.08.09. + { + + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).IgnoredFlair) + return; + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).AcceptedFlair) + { + AppendPlayerDisplayFlairFinal(p, player.Flair); //2015.07.20. + if(!player.FlairDecided) + p.sendMessage("§9Your flair type is unknown. Are you a non-presser or a can't press? (/u nonpresser or /u cantpress)§r"); //2015.08.09. + } + else + p.sendMessage("§9Are you Reddit user "+player.UserName+"?§r §6Type /u accept or /u ignore§r"); + } + + private static void AppendPlayerDisplayFlairFinal(Player player, String flair) + { //2015.07.20. + String color = GetColorForTown(GetPlayerTown(player)); //TO!DO: Multiple colors put on first capital letters + String[] colors = color.substring(1).split("§"); + String displayname=player.getName(); //2015.08.08. + ArrayList Positions=new ArrayList<>(); + for(int i=0; i=colors.length) + { + int x=0; + for(int i=0; i GetPlayers() + { + return Instance.getServer().getOnlinePlayers(); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/7e/001a1675df3e001517108d149b613203 b/.metadata/.plugins/org.eclipse.core.resources/.history/7e/001a1675df3e001517108d149b613203 new file mode 100644 index 0000000..2a1ad93 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/7e/001a1675df3e001517108d149b613203 @@ -0,0 +1,252 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +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; + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. + //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) + if(p.Flair==null) + { + player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); + return true; + } + switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. + { + case "accept": + { + if(p.IgnoredFlair) + p.IgnoredFlair=false; //2015.08.08. + if(!p.AcceptedFlair) + { + String flair=p.Flair; //2015.08.08. + //PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + PluginMain.AppendPlayerDisplayFlair(p, player); + p.AcceptedFlair=true; //2015.08.08. + player.sendMessage("§6Your flair has been set:§r "+flair); + } + else + player.sendMessage("§cYou already have this user's flair.§r"); + break; + } + case "ignore": + { + if(p.AcceptedFlair) + p.AcceptedFlair=false; //2015.08.08. + if(!p.IgnoredFlair) + { + p.IgnoredFlair=true; + String flair=p.Flair; //2015.08.08. + PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. + player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); + } + else + player.sendMessage("§cYou already ignored this request.§r"); + break; + } + /*case "reload": //2015.07.20. + DoReload(player); + break;*/ + case "admin": //2015.08.09. + DoAdmin(player, args); + break; + case "nonpresser": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§7(non-pr.)§r"; + break; + case "cantpress": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§r(can't press)§r"; + break; + default: + return false; + } + return true; + } + /*if(args[0].toLowerCase()=="reload") + DoReload(null); //2015.07.20.*/ + else if(args.length>0 && args[0].toLowerCase().equals("admin")) //2015.08.09. + { + DoAdmin(null, args); //2015.08.09. + return true; //2015.08.09. + } + return false; + } + private static void DoReload(Player player) + { //2015.07.20. + //if(player==null || player.isOp() || player.getName()=="NorbiPeti") + //{ + try + { + File file=new File("autoflairconfig.txt"); + if(file.exists()) + { + PluginMain.LoadFiles(true); //2015.08.09. + for(Player p : PluginMain.GetPlayers()) + { + MaybeOfflinePlayer mp = MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName()); + if(mp.Flair!=null) + { + String flair=mp.Flair; + PluginMain.RemovePlayerDisplayFlairFinal(p, flair); + //PluginMain.AppendPlayerDisplayFlairFinal(p, flair); + PluginMain.AppendPlayerDisplayFlair(mp, p); //2015.08.09. + } + String msg="§6Note: The auto-flair plugin has been reloaded. You might need to wait 10s to have your flair.§r"; //2015.08.09. + p.sendMessage(msg); //2015.08.09. + } + //String msg="§6Reloaded config file.§r"; + //SendMessage(player, msg); //2015.08.09. + } + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + if(player!=null) + player.sendMessage("§cAn error occured. See console for details.§r"); + PluginMain.LastException=e; //2015.08.09. + } + //} + //else + //player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static Player ReloadPlayer; //2015.08.09. + private static void DoAdmin(Player player, String[] args) + { //2015.08.09. + if(player==null || player.isOp() || player.getName()=="NorbiPeti") + { + //System.out.println("Args length: " + args.length); + if(args.length==1) + { + String message="§cUsage: /u admin reload|playerinfo§r"; + SendMessage(player, message); + return; + } + //args[0] is "admin" + switch(args[1].toLowerCase()) + { + case "reload": + ReloadPlayer=player; //2015.08.09. + SendMessage(player, "§6Make sure to save the current settings before you modify and reload them! Type /u admin confirm when done.§r"); + break; + case "playerinfo": + DoPlayerInfo(player, args); + break; + case "getlasterror": + DoGetLastError(player, args); + case "confirm": + if(ReloadPlayer==player) + DoReload(player); //2015.08.09. + else + SendMessage(player, "§cYou need to do /u admin reload first.§r"); + break; + case "save": + PluginMain.SaveFiles(); //2015.08.09. + SendMessage(player, "§6Saved files. Now you can edit them and reload if you want.§r"); + break; + default: + String message="§cUsage: /u admin reload|playerinfo|getlasterror§r"; + SendMessage(player, message); + return; + } + } + else + player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static void DoPlayerInfo(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "playerinfo" + if(args.length==2) + { + String message="§cUsage: /u admin playerinfo §r"; + SendMessage(player, message); + return; + } + if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2])) + { + String message="§cPlayer not found: "+args[2]+"§r"; + SendMessage(player, message); + return; + } + MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]); + SendMessage(player, "Player name: "+p.PlayerName); + SendMessage(player, "User flair: "+p.Flair); + SendMessage(player, "Username: "+p.UserName); + SendMessage(player, "Flair accepted: "+p.AcceptedFlair); + SendMessage(player, "Flair ignored: "+p.IgnoredFlair); + } + private static void SendMessage(Player player, String message) + { //2015.08.09. + if(player==null) + System.out.println(message); + else + player.sendMessage(message); + } + private static void DoGetLastError(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "getlasterror" + if(PluginMain.LastException!=null) + { + SendMessage(player, "Last error:"); + SendMessage(player, PluginMain.LastException.toString()); + PluginMain.LastException=null; + } + else + SendMessage(player, "There were no exceptions."); + } + private static void SetPlayerFlair(Player player, String flair) + { //2015.08.09. + flair=flair.replace('&', '§'); + MaybeOfflinePlayer.AddPlayerIfNeeded(player.getName()).Flair=flair; + if(!PluginMain.RemoveLineFromFile("customflairs.txt")) + { + SendMessage(player, "§cError removing previous custom flair!§r"); + return; + } + File file=new File("customflairs.txt"); + try { + BufferedWriter bw; + bw = new BufferedWriter(new FileWriter(file, true)); + bw.write(player.getName()+"\n"); + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + PluginMain.LastException=e; //2015.08.09. + } + SendMessage(player, "§6The flair has been set. Player: "+player.getName()+" Flair: "+flair+"§r"); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/7e/2093d427df3e001517108d149b613203 b/.metadata/.plugins/org.eclipse.core.resources/.history/7e/2093d427df3e001517108d149b613203 new file mode 100644 index 0000000..eac777b --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/7e/2093d427df3e001517108d149b613203 @@ -0,0 +1,250 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +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; + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. + //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) + if(p.Flair==null) + { + player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); + return true; + } + switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. + { + case "accept": + { + if(p.IgnoredFlair) + p.IgnoredFlair=false; //2015.08.08. + if(!p.AcceptedFlair) + { + String flair=p.Flair; //2015.08.08. + //PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + PluginMain.AppendPlayerDisplayFlair(p, player); + p.AcceptedFlair=true; //2015.08.08. + player.sendMessage("§6Your flair has been set:§r "+flair); + } + else + player.sendMessage("§cYou already have this user's flair.§r"); + break; + } + case "ignore": + { + if(p.AcceptedFlair) + p.AcceptedFlair=false; //2015.08.08. + if(!p.IgnoredFlair) + { + p.IgnoredFlair=true; + String flair=p.Flair; //2015.08.08. + PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. + player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); + } + else + player.sendMessage("§cYou already ignored this request.§r"); + break; + } + /*case "reload": //2015.07.20. + DoReload(player); + break;*/ + case "admin": //2015.08.09. + DoAdmin(player, args); + break; + case "nonpresser": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§7(non-pr.)§r"; + break; + case "cantpress": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§r(can't press)§r"; + break; + default: + return false; + } + return true; + } + /*if(args[0].toLowerCase()=="reload") + DoReload(null); //2015.07.20.*/ + else if(args.length>0 && args[0].toLowerCase().equals("admin")) //2015.08.09. + { + DoAdmin(null, args); //2015.08.09. + return true; //2015.08.09. + } + return false; + } + private static void DoReload(Player player) + { //2015.07.20. + //if(player==null || player.isOp() || player.getName()=="NorbiPeti") + //{ + try + { + File file=new File("autoflairconfig.txt"); + if(file.exists()) + { + PluginMain.LoadFiles(true); //2015.08.09. + for(Player p : PluginMain.GetPlayers()) + { + MaybeOfflinePlayer mp = MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName()); + if(mp.Flair!=null) + { + String flair=mp.Flair; + PluginMain.RemovePlayerDisplayFlairFinal(p, flair); + //PluginMain.AppendPlayerDisplayFlairFinal(p, flair); + PluginMain.AppendPlayerDisplayFlair(mp, p); //2015.08.09. + } + String msg="§6Note: The auto-flair plugin has been reloaded. You might need to wait 10s to have your flair.§r"; //2015.08.09. + p.sendMessage(msg); //2015.08.09. + } + //String msg="§6Reloaded config file.§r"; + //SendMessage(player, msg); //2015.08.09. + } + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + if(player!=null) + player.sendMessage("§cAn error occured. See console for details.§r"); + PluginMain.LastException=e; //2015.08.09. + } + //} + //else + //player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static Player ReloadPlayer; //2015.08.09. + private static void DoAdmin(Player player, String[] args) + { //2015.08.09. + if(player==null || player.isOp() || player.getName()=="NorbiPeti") + { + //System.out.println("Args length: " + args.length); + if(args.length==1) + { + String message="§cUsage: /u admin reload|playerinfo§r"; + SendMessage(player, message); + return; + } + //args[0] is "admin" + switch(args[1].toLowerCase()) + { + case "reload": + ReloadPlayer=player; //2015.08.09. + SendMessage(player, "§6Make sure to save the current settings before you modify and reload them! Type /u admin confirm when done.§r"); + break; + case "playerinfo": + DoPlayerInfo(player, args); + break; + case "getlasterror": + DoGetLastError(player, args); + case "confirm": + if(ReloadPlayer==player) + DoReload(player); //2015.08.09. + else + SendMessage(player, "§cYou need to do /u admin reload first.§r"); + break; + case "save": + PluginMain.SaveFiles(); //2015.08.09. + SendMessage(player, "§6Saved files. Now you can edit them and reload if you want.§r"); + break; + default: + String message="§cUsage: /u admin reload|playerinfo|getlasterror§r"; + SendMessage(player, message); + return; + } + } + else + player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static void DoPlayerInfo(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "playerinfo" + if(args.length==2) + { + String message="§cUsage: /u admin playerinfo §r"; + SendMessage(player, message); + return; + } + if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2])) + { + String message="§cPlayer not found: "+args[2]+"§r"; + SendMessage(player, message); + return; + } + MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]); + SendMessage(player, "Player name: "+p.PlayerName); + SendMessage(player, "User flair: "+p.Flair); + SendMessage(player, "Username: "+p.UserName); + SendMessage(player, "Flair accepted: "+p.AcceptedFlair); + SendMessage(player, "Flair ignored: "+p.IgnoredFlair); + } + private static void SendMessage(Player player, String message) + { //2015.08.09. + if(player==null) + System.out.println(message); + else + player.sendMessage(message); + } + private static void DoGetLastError(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "getlasterror" + if(PluginMain.LastException!=null) + { + SendMessage(player, "Last error:"); + SendMessage(player, PluginMain.LastException.toString()); + PluginMain.LastException=null; + } + else + SendMessage(player, "There were no exceptions."); + } + private static void SetPlayerFlair(Player player, String flair) + { //2015.08.09. + flair=flair.replace('&', '§'); + MaybeOfflinePlayer.AddPlayerIfNeeded(player.getName()).Flair=flair; + if(!PluginMain.RemoveLineFromFile("customflairs.txt")) + { + SendMessage(player, "Error removing previous custom flair!"); + } + File file=new File("customflairs.txt"); + try { + BufferedWriter bw; + bw = new BufferedWriter(new FileWriter(file, true)); + bw.write(player.getName()+"\n"); + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + PluginMain.LastException=e; //2015.08.09. + } + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/7f/9025b8a1de3e001517108d149b613203 b/.metadata/.plugins/org.eclipse.core.resources/.history/7f/9025b8a1de3e001517108d149b613203 new file mode 100644 index 0000000..f0d5af2 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/7f/9025b8a1de3e001517108d149b613203 @@ -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.WorldCoord; + +public class PluginMain extends JavaPlugin +{ //Translated to Java: 2015.07.15. + //A user, which flair isn't obtainable: + //https://www.reddit.com/r/thebutton/comments/31c32v/i_pressed_the_button_without_really_thinking/ + private static PluginMain Instance; + // Fired when plugin is first enabled + @Override + public void onEnable() + { + System.out.println("The Button Auto-flair Plugin by NorbiPeti (:P)"); + getServer().getPluginManager().registerEvents(new PlayerListener(), this); + this.getCommand("u").setExecutor(new Commands()); + this.getCommand("u").setUsage(this.getCommand("u").getUsage().replace('&', '§')); + Instance=this; //2015.08.08. + LoadFiles(false); //2015.08.09. + Runnable r=new Runnable(){public void run(){ThreadMethod();}}; + Thread t=new Thread(r); + t.start(); + } + Boolean stop=false; + // Fired when plugin is disabled + @Override + public void onDisable() + { + SaveFiles(); //2015.08.09. + stop=true; + } + + public void ThreadMethod() //<-- 2015.07.16. + { + while(!stop) + { + try + { + String body=DownloadString("https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/autoflair_system_comment_your_minecraft_name_and/.json?limit=1000"); + JSONArray json=new JSONArray(body).getJSONObject(1).getJSONObject("data").getJSONArray("children"); + for(Object obj : json) + { + JSONObject item = (JSONObject)obj; + String author=item.getJSONObject("data").getString("author"); + String ign=item.getJSONObject("data").getString("body"); + int start = ign.indexOf("IGN:") + "IGN:".length(); + if(start==-1) + continue; //2015.08.09. + int end = ign.indexOf(' ', start); + if (end == -1 || end == start) + end=ign.indexOf('\n', start); //2015.07.15. + if (end == -1 || end == start) + ign = ign.substring(start); + else + ign = ign.substring(start, end); + ign = ign.trim(); + if(HasIGFlair(ign)) + continue; + try { + Thread.sleep(10); + } catch(InterruptedException ex) { + Thread.currentThread().interrupt(); + } + String[] flairdata = DownloadString("http://karmadecay.com/thebutton-data.php?users=" + author).replace("\"", "").split(":"); + String flair; + if(flairdata.length > 1) //2015.07.15. + flair = flairdata[1]; + else + flair=""; + if (flair != "-1") + flair = flair + "s"; + else + flair = "non-presser"; + String flairclass; + if(flairdata.length>2) + flairclass = flairdata[2]; + else + flairclass="unknown"; + SetFlair(ign, flair, flairclass, author); + } + Thread.sleep(10000); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + } + + public static Exception LastException; //2015.08.09. + + public String DownloadString(String urlstr) throws MalformedURLException, IOException + { + URL url = new URL(urlstr); + URLConnection con = url.openConnection(); + con.setRequestProperty("User-Agent", "TheButtonAutoFlair"); + InputStream in = con.getInputStream(); + String encoding = con.getContentEncoding(); + encoding = encoding == null ? "UTF-8" : encoding; + String body = IOUtils.toString(in, encoding); + in.close(); + return body; + } + + public static Map TownColors=new HashMap(); //2015.07.20. + public Boolean HasIGFlair(String playername) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + return p.Flair!=null; //2015.08.08. + } + + public void SetFlair(String playername, String text, String flairclass, String username) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + String finalflair; + p.FlairDecided=true; + switch(flairclass) + { + case "press-1": + finalflair="§c("+text+")§r"; + break; + case "press-2": + finalflair="§6("+text+")§r"; + break; + case "press-3": + finalflair="§e("+text+")§r"; + break; + case "press-4": + finalflair="§a("+text+")§r"; + break; + case "press-5": + finalflair="§9("+text+")§r"; + break; + 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; + case "undecided": //2015.08.09. + p.FlairDecided=false; + finalflair=""; + break; + default: + finalflair=""; + break; + } + if(finalflair.length()==0) //<-- 2015.07.20. + return; + p.Flair=finalflair; //2015.08.08. + p.UserName=username; //2015.08.08. + System.out.println("Added new flair to "+playername+": "+finalflair); + for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08. + { + if(player.getName().equals(playername)) + { + //AppendPlayerDisplayFlair(player, username, finalflair); + AppendPlayerDisplayFlair(p, player); + break; + } + } + } + + public static String GetFlair(Player player) + { //2015.07.16. + String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08. + return flair==null ? "" : flair; + } + + //public static void AppendPlayerDisplayFlair(Player player, String username, String flair) + public static void AppendPlayerDisplayFlair(MaybeOfflinePlayer player, Player p) //<-- 2015.08.09. + { + + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).IgnoredFlair) + return; + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).AcceptedFlair) + { + AppendPlayerDisplayFlairFinal(p, player.Flair); //2015.07.20. + if(!player.FlairDecided) + p.sendMessage("§9Your flair type is unknown. Are you a non-presser or a can't press? (/u nonpresser or /u cantpress)§r"); //2015.08.09. + } + else + p.sendMessage("§9Are you Reddit user "+player.UserName+"?§r §6Type /u accept or /u ignore§r"); + } + + private static void AppendPlayerDisplayFlairFinal(Player player, String flair) + { //2015.07.20. + String color = GetColorForTown(GetPlayerTown(player)); //TO!DO: Multiple colors put on first capital letters + String[] colors = color.substring(1).split("§"); + String displayname=player.getName(); //2015.08.08. + ArrayList Positions=new ArrayList<>(); + for(int i=0; i=colors.length) + { + int x=0; + for(int i=0; i GetPlayers() + { + return Instance.getServer().getOnlinePlayers(); + } + + public static void LoadFiles(boolean reload) //<-- 2015.08.09. + { + if(reload) + { //2015.08.09. + System.out.println("Auto-flair plugin cleanup for reloading..."); + MaybeOfflinePlayer.AllPlayers.clear(); + TownColors.clear(); + } + System.out.println("Loading files for auto-flair plugin..."); //2015.08.09. + try { + File file=new File("flairsaccepted.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + //System.out.println("Name: " + name); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("flairsignored.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsignored.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("autoflairconfig.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + TownColors.put(s[0], s[1]); + } + br.close(); + } + file=new File("customflairs.txt"); //2015.08.09. + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + MaybeOfflinePlayer.AddPlayerIfNeeded(s[0]).Flair=s[1]; //2015.08.09. + } + br.close(); + } + //throw new IOException("Test"); //2015.08.09. + System.out.println("Auto-flair plugin loaded files!"); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + public static void SaveFiles() //<-- 2015.08.09. + { + try + { + FileWriter fw; + fw = new FileWriter("flairsaccepted.txt"); + fw.close(); + fw = new FileWriter("flairsignored.txt"); + fw.close(); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + try { + File file=new File("flairsaccepted.txt"); + BufferedWriter bw=new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.AcceptedFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + file=new File("flairsignored.txt"); + bw = new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.IgnoredFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + public static void SetPlayerFlair(Player player, String flair) + { //2015.08.09. + flair=flair.replace('&', '§'); + MaybeOfflinePlayer.AddPlayerIfNeeded(player.getName()).Flair=flair; + File file=new File("customflairs.txt"); + try { + BufferedWriter bw; + bw = new BufferedWriter(new FileWriter(file, true)); + bw.write(player.getName()+"\n"); + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + public static bool RemoveLineFromFile(String file) + { + File inputFile = new File(file); + File tempFile = new File("_temp.txt"); + + try { + BufferedReader reader = new BufferedReader(new FileReader(inputFile)); + BufferedWriter writer = new BufferedWriter(new FileWriter(tempFile)); + + String lineToRemove = "bbb"; + String currentLine; + + while((currentLine = reader.readLine()) != null) { + // trim newline when comparing with lineToRemove + String trimmedLine = currentLine.trim(); + if(trimmedLine.equals(lineToRemove)) continue; + writer.write(currentLine + System.getProperty("line.separator")); + } + writer.close(); + reader.close(); + boolean successful = tempFile.renameTo(inputFile); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/8/e0936b2f853e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/8/e0936b2f853e00151ce8ff6d4f74dabd deleted file mode 100644 index 4fc0380..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/8/e0936b2f853e00151ce8ff6d4f74dabd +++ /dev/null @@ -1,129 +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; - MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. - //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - if(p.Flair==null) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. - { - case "accept": - { - if(p.IgnoredFlair) - p.IgnoredFlair=false; //2015.08.08. - if(!p.AcceptedFlair) - { - String flair=p.Flair; //2015.08.08. - PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. - p.AcceptedFlair=true; //2015.08.08. - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("§cYou already have this user's flair.§r"); - break; - } - case "ignore": - { - if(p.AcceptedFlair) - p.AcceptedFlair=false; //2015.08.08. - if(!p.IgnoredFlair) - { - p.IgnoredFlair=true; - String flair=p.Flair; //2015.08.08. - PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. - player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); - } - else - player.sendMessage("§cYou already ignored this request.§r"); - break; - } - case "reload": //2015.07.20. - DoReload(player); - break; - case "showerrors": //2015.08.09. - DoShowErrors(player); - break; - default: - return false; - } - return true; - } - - if(args[0].toLowerCase()=="reload") - DoReload(null); //2015.07.20. - else if(args[0].toLowerCase()=="showerrors") - DoShowErrors(null); //2015.08.09. - return false; - } - private static void DoReload(Player player) - { //2015.07.20. - if(player==null || player.isOp() || player.getName()=="NorbiPeti") - { - try - { - File file=new File("autoflairconfig.txt"); - if(file.exists()) - { - PluginMain.TownColors.clear(); - BufferedReader br=new BufferedReader(new FileReader(file)); - String line; - while((line=br.readLine())!=null) - { - String[] s=line.split(" "); - PluginMain.TownColors.put(s[0], s[1]); - } - br.close(); - for(Player p : PluginMain.GetPlayers()) - { - MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName()); - if(mp.Flair!=null) - { - String flair=mp.Flair; - PluginMain.RemovePlayerDisplayFlairFinal(p, flair); - PluginMain.AppendPlayerDisplayFlairFinal(p, flair); - } - } - String msg="§6Reloaded config file.§r"; - if(player!=null) - player.sendMessage(msg); - else - System.out.println(msg); - } - } - catch(Exception e) - { - System.out.println("Error!\n"+e); - if(player!=null) - player.sendMessage("§cAn error occured. See console for details.§r"); - } - } - else - player.sendMessage("§cYou need to be OP to use this command.§r"); - } - private static void DoShowErrors(Player player) - { - if(player==null || player.isOp() || player.getName()=="NorbiPeti") - { - - } - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/80/00713b62df3e001517108d149b613203 b/.metadata/.plugins/org.eclipse.core.resources/.history/80/00713b62df3e001517108d149b613203 new file mode 100644 index 0000000..bfee7cd --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/80/00713b62df3e001517108d149b613203 @@ -0,0 +1,252 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +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; + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. + //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) + if(p.Flair==null) + { + player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); + return true; + } + switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. + { + case "accept": + { + if(p.IgnoredFlair) + p.IgnoredFlair=false; //2015.08.08. + if(!p.AcceptedFlair) + { + String flair=p.Flair; //2015.08.08. + //PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + PluginMain.AppendPlayerDisplayFlair(p, player); + p.AcceptedFlair=true; //2015.08.08. + player.sendMessage("§6Your flair has been set:§r "+flair); + } + else + player.sendMessage("§cYou already have this user's flair.§r"); + break; + } + case "ignore": + { + if(p.AcceptedFlair) + p.AcceptedFlair=false; //2015.08.08. + if(!p.IgnoredFlair) + { + p.IgnoredFlair=true; + String flair=p.Flair; //2015.08.08. + PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. + player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); + } + else + player.sendMessage("§cYou already ignored this request.§r"); + break; + } + /*case "reload": //2015.07.20. + DoReload(player); + break;*/ + case "admin": //2015.08.09. + DoAdmin(player, args); + break; + case "nonpresser": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§7(non-pr.)§r"; + break; + case "cantpress": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§r(can't press)§r"; + break; + default: + return false; + } + return true; + } + /*if(args[0].toLowerCase()=="reload") + DoReload(null); //2015.07.20.*/ + else if(args.length>0 && args[0].toLowerCase().equals("admin")) //2015.08.09. + { + DoAdmin(null, args); //2015.08.09. + return true; //2015.08.09. + } + return false; + } + private static void DoReload(Player player) + { //2015.07.20. + //if(player==null || player.isOp() || player.getName()=="NorbiPeti") + //{ + try + { + File file=new File("autoflairconfig.txt"); + if(file.exists()) + { + PluginMain.LoadFiles(true); //2015.08.09. + for(Player p : PluginMain.GetPlayers()) + { + MaybeOfflinePlayer mp = MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName()); + if(mp.Flair!=null) + { + String flair=mp.Flair; + PluginMain.RemovePlayerDisplayFlairFinal(p, flair); + //PluginMain.AppendPlayerDisplayFlairFinal(p, flair); + PluginMain.AppendPlayerDisplayFlair(mp, p); //2015.08.09. + } + String msg="§6Note: The auto-flair plugin has been reloaded. You might need to wait 10s to have your flair.§r"; //2015.08.09. + p.sendMessage(msg); //2015.08.09. + } + //String msg="§6Reloaded config file.§r"; + //SendMessage(player, msg); //2015.08.09. + } + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + if(player!=null) + player.sendMessage("§cAn error occured. See console for details.§r"); + PluginMain.LastException=e; //2015.08.09. + } + //} + //else + //player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static Player ReloadPlayer; //2015.08.09. + private static void DoAdmin(Player player, String[] args) + { //2015.08.09. + if(player==null || player.isOp() || player.getName()=="NorbiPeti") + { + //System.out.println("Args length: " + args.length); + if(args.length==1) + { + String message="§cUsage: /u admin reload|playerinfo§r"; + SendMessage(player, message); + return; + } + //args[0] is "admin" + switch(args[1].toLowerCase()) + { + case "reload": + ReloadPlayer=player; //2015.08.09. + SendMessage(player, "§6Make sure to save the current settings before you modify and reload them! Type /u admin confirm when done.§r"); + break; + case "playerinfo": + DoPlayerInfo(player, args); + break; + case "getlasterror": + DoGetLastError(player, args); + case "confirm": + if(ReloadPlayer==player) + DoReload(player); //2015.08.09. + else + SendMessage(player, "§cYou need to do /u admin reload first.§r"); + break; + case "save": + PluginMain.SaveFiles(); //2015.08.09. + SendMessage(player, "§6Saved files. Now you can edit them and reload if you want.§r"); + break; + default: + String message="§cUsage: /u admin reload|playerinfo|getlasterror§r"; + SendMessage(player, message); + return; + } + } + else + player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static void DoPlayerInfo(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "playerinfo" + if(args.length==2) + { + String message="§cUsage: /u admin playerinfo §r"; + SendMessage(player, message); + return; + } + if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2])) + { + String message="§cPlayer not found: "+args[2]+"§r"; + SendMessage(player, message); + return; + } + MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]); + SendMessage(player, "Player name: "+p.PlayerName); + SendMessage(player, "User flair: "+p.Flair); + SendMessage(player, "Username: "+p.UserName); + SendMessage(player, "Flair accepted: "+p.AcceptedFlair); + SendMessage(player, "Flair ignored: "+p.IgnoredFlair); + } + private static void SendMessage(Player player, String message) + { //2015.08.09. + if(player==null) + System.out.println(message); + else + player.sendMessage(message); + } + private static void DoGetLastError(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "getlasterror" + if(PluginMain.LastException!=null) + { + SendMessage(player, "Last error:"); + SendMessage(player, PluginMain.LastException.toString()); + PluginMain.LastException=null; + } + else + SendMessage(player, "There were no exceptions."); + } + private static void SetPlayerFlair(Player player, String flair) + { //2015.08.09. + flair=flair.replace('&', '§'); + MaybeOfflinePlayer.AddPlayerIfNeeded(player.getName()).Flair=flair; + if(!PluginMain.RemoveLineFromFile("customflairs.txt")) + { + SendMessage(player, "§cError removing previous custom flair!§r"); + return; + } + File file=new File("customflairs.txt"); + try { + BufferedWriter bw; + bw = new BufferedWriter(new FileWriter(file, true)); + bw.write(player.getName()+"\n"); + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + PluginMain.LastException=e; //2015.08.09. + } + SendMessage(player, "") + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/80/4075d399d03e001518fa86d7ae2a1cf8 b/.metadata/.plugins/org.eclipse.core.resources/.history/80/4075d399d03e001518fa86d7ae2a1cf8 new file mode 100644 index 0000000..8abed8b --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/80/4075d399d03e001518fa86d7ae2a1cf8 @@ -0,0 +1,206 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; + +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class Commands implements CommandExecutor { + // This method is called, when somebody uses our command + @Override + public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { + if (sender instanceof Player) { + Player player = (Player) sender; + if(args.length<1) + return false; + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. + //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) + if(p.Flair==null) + { + player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); + return true; + } + switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. + { + case "accept": + { + if(p.IgnoredFlair) + p.IgnoredFlair=false; //2015.08.08. + if(!p.AcceptedFlair) + { + String flair=p.Flair; //2015.08.08. + //PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + PluginMain.AppendPlayerDisplayFlair(p, player); + p.AcceptedFlair=true; //2015.08.08. + player.sendMessage("§6Your flair has been set:§r "+flair); + } + else + player.sendMessage("§cYou already have this user's flair.§r"); + break; + } + case "ignore": + { + if(p.AcceptedFlair) + p.AcceptedFlair=false; //2015.08.08. + if(!p.IgnoredFlair) + { + p.IgnoredFlair=true; + String flair=p.Flair; //2015.08.08. + PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. + player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); + } + else + player.sendMessage("§cYou already ignored this request.§r"); + break; + } + /*case "reload": //2015.07.20. + DoReload(player); + break;*/ + case "admin": //2015.08.09. + DoAdmin(player, args); + break; + case "nonpresser": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + + break; + case "cantpress": //2015.08.09. + break; + default: + return false; + } + return true; + } + /*if(args[0].toLowerCase()=="reload") + DoReload(null); //2015.07.20.*/ + else if(args.length>0 && args[0].toLowerCase().equals("admin")) //2015.08.09. + { + DoAdmin(null, args); //2015.08.09. + return true; //2015.08.09. + } + return false; + } + private static void DoReload(Player player) + { //2015.07.20. + //if(player==null || player.isOp() || player.getName()=="NorbiPeti") + //{ + try + { + File file=new File("autoflairconfig.txt"); + if(file.exists()) + { + PluginMain.TownColors.clear(); + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + PluginMain.TownColors.put(s[0], s[1]); + } + br.close(); + for(Player p : PluginMain.GetPlayers()) + { + MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName()); + if(mp.Flair!=null) + { + String flair=mp.Flair; + PluginMain.RemovePlayerDisplayFlairFinal(p, flair); + //PluginMain.AppendPlayerDisplayFlairFinal(p, flair); + PluginMain.AppendPlayerDisplayFlair(mp, p); //2015.08.09. + } + } + String msg="§6Reloaded config file.§r"; + SendMessage(player, msg); //2015.08.09. + } + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + if(player!=null) + player.sendMessage("§cAn error occured. See console for details.§r"); + PluginMain.LastException=e; //2015.08.09. + } + //} + //else + //player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static void DoAdmin(Player player, String[] args) + { //2015.08.09. + if(player==null || player.isOp() || player.getName()=="NorbiPeti") + { + //System.out.println("Args length: " + args.length); + if(args.length==1) + { + String message="§cUsage: /u admin reload|playerinfo§r"; + SendMessage(player, message); + return; + } + //args[0] is "admin" + switch(args[1].toLowerCase()) + { + case "reload": + DoReload(player); + break; + case "playerinfo": + DoPlayerInfo(player, args); + break; + case "getlasterror": + DoGetLastError(player, args); + default: + String message="§cUsage: /u admin reload|playerinfo§r"; + SendMessage(player, message); + return; + } + } + else + player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static void DoPlayerInfo(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "playerinfo" + if(args.length==2) + { + String message="§cUsage: /u admin playerinfo §r"; + SendMessage(player, message); + return; + } + if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2])) + { + String message="§cPlayer not found: "+args[2]+"§r"; + SendMessage(player, message); + return; + } + MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]); + SendMessage(player, "Player name: "+p.PlayerName); + SendMessage(player, "User flair: "+p.Flair); + SendMessage(player, "Username: "+p.UserName); + SendMessage(player, "Flair accepted: "+p.AcceptedFlair); + SendMessage(player, "Flair ignored: "+p.IgnoredFlair); + } + private static void SendMessage(Player player, String message) + { //2015.08.09. + if(player==null) + System.out.println(message); + else + player.sendMessage(message); + } + private static void DoGetLastError(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "getlasterror" + if(PluginMain.LastException!=null) + { + SendMessage(player, "Last error:"); + SendMessage(player, PluginMain.LastException.toString()); + PluginMain.LastException=null; + } + else + SendMessage(player, "There were no exceptions."); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/80/50a96102873e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/80/50a96102873e00151ce8ff6d4f74dabd deleted file mode 100644 index 2290b1a..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/80/50a96102873e00151ce8ff6d4f74dabd +++ /dev/null @@ -1,135 +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; - MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. - //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - if(p.Flair==null) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. - { - case "accept": - { - if(p.IgnoredFlair) - p.IgnoredFlair=false; //2015.08.08. - if(!p.AcceptedFlair) - { - String flair=p.Flair; //2015.08.08. - PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. - p.AcceptedFlair=true; //2015.08.08. - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("§cYou already have this user's flair.§r"); - break; - } - case "ignore": - { - if(p.AcceptedFlair) - p.AcceptedFlair=false; //2015.08.08. - if(!p.IgnoredFlair) - { - p.IgnoredFlair=true; - String flair=p.Flair; //2015.08.08. - PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. - player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); - } - else - player.sendMessage("§cYou already ignored this request.§r"); - break; - } - case "reload": //2015.07.20. - DoReload(player); - break; - case "admin": //2015.08.09. - DoAdmin(player, args); - break; - default: - return false; - } - return true; - } - - if(args[0].toLowerCase()=="reload") - DoReload(null); //2015.07.20. - else if(args[0].toLowerCase()=="admin") - DoAdmin(null, args); //2015.08.09. - return false; - } - private static void DoReload(Player player) - { //2015.07.20. - if(player==null || player.isOp() || player.getName()=="NorbiPeti") - { - try - { - File file=new File("autoflairconfig.txt"); - if(file.exists()) - { - PluginMain.TownColors.clear(); - BufferedReader br=new BufferedReader(new FileReader(file)); - String line; - while((line=br.readLine())!=null) - { - String[] s=line.split(" "); - PluginMain.TownColors.put(s[0], s[1]); - } - br.close(); - for(Player p : PluginMain.GetPlayers()) - { - MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName()); - if(mp.Flair!=null) - { - String flair=mp.Flair; - PluginMain.RemovePlayerDisplayFlairFinal(p, flair); - PluginMain.AppendPlayerDisplayFlairFinal(p, flair); - } - } - String msg="§6Reloaded config file.§r"; - if(player!=null) - player.sendMessage(msg); - else - System.out.println(msg); - } - } - catch(Exception e) - { - System.out.println("Error!\n"+e); - if(player!=null) - player.sendMessage("§cAn error occured. See console for details.§r"); - } - } - else - player.sendMessage("§cYou need to be OP to use this command.§r"); - } - private static void DoAdmin(Player player, String[] args) - { - if(player==null || player.isOp() || player.getName()=="NorbiPeti") - { - //args[0] is "admin" - switch(args[1].toLowerCase()) - { - - } - } - else - player.sendMessage("§cYou need to be OP to use this command.§r"); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/81/b0e3d39bd13e001518fa86d7ae2a1cf8 b/.metadata/.plugins/org.eclipse.core.resources/.history/81/b0e3d39bd13e001518fa86d7ae2a1cf8 new file mode 100644 index 0000000..81f3985 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/81/b0e3d39bd13e001518fa86d7ae2a1cf8 @@ -0,0 +1,326 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStream; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLConnection; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + +import org.apache.commons.io.IOUtils; +import org.bukkit.entity.Player; +import org.bukkit.plugin.java.JavaPlugin; +import org.json.JSONArray; +import org.json.JSONObject; + +import com.palmergames.bukkit.towny.object.Town; +import com.palmergames.bukkit.towny.object.WorldCoord; + +public class PluginMain extends JavaPlugin +{ //Translated to Java: 2015.07.15. + //A user, which flair isn't obtainable: + //https://www.reddit.com/r/thebutton/comments/31c32v/i_pressed_the_button_without_really_thinking/ + private static PluginMain Instance; + // Fired when plugin is first enabled + @Override + public void onEnable() + { + System.out.println("The Button Auto-flair Plugin by NorbiPeti (:P)"); + getServer().getPluginManager().registerEvents(new PlayerListener(), this); + this.getCommand("u").setExecutor(new Commands()); + this.getCommand("u").setUsage(this.getCommand("u").getUsage().replace('&', '§')); + Instance=this; //2015.08.08. + LoadFiles(false); //2015.08.09. + Runnable r=new Runnable(){public void run(){ThreadMethod();}}; + Thread t=new Thread(r); + t.start(); + } + Boolean stop=false; + // Fired when plugin is disabled + @Override + public void onDisable() + { + try + { + FileWriter fw; + fw = new FileWriter("flairsaccepted.txt"); + fw.close(); + fw = new FileWriter("flairsignored.txt"); + fw.close(); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + try { + File file=new File("flairsaccepted.txt"); + BufferedWriter bw=new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.AcceptedFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + file=new File("flairsignored.txt"); + bw = new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.IgnoredFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + stop=true; + } + + public void ThreadMethod() //<-- 2015.07.16. + { + while(!stop) + { + try + { + String body=DownloadString("https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/autoflair_system_comment_your_minecraft_name_and/.json?limit=1000"); + JSONArray json=new JSONArray(body).getJSONObject(1).getJSONObject("data").getJSONArray("children"); + for(Object obj : json) + { + JSONObject item = (JSONObject)obj; + String author=item.getJSONObject("data").getString("author"); + String ign=item.getJSONObject("data").getString("body"); + int start = ign.indexOf("IGN:") + "IGN:".length(); + int end = ign.indexOf(' ', start); + if (end == -1 || end == start) + end=ign.indexOf('\n', start); //2015.07.15. + if (end == -1 || end == start) + ign = ign.substring(start); + else + ign = ign.substring(start, end); + ign = ign.trim(); + if(HasIGFlair(ign)) + continue; + try { + Thread.sleep(10); + } catch(InterruptedException ex) { + Thread.currentThread().interrupt(); + } + String[] flairdata = DownloadString("http://karmadecay.com/thebutton-data.php?users=" + author).replace("\"", "").split(":"); + String flair; + if(flairdata.length > 1) //2015.07.15. + flair = flairdata[1]; + else + flair=""; + if (flair != "-1") + flair = flair + "s"; + else + flair = "non-presser"; + String flairclass; + if(flairdata.length>2) + flairclass = flairdata[2]; + else + flairclass="unknown"; + SetFlair(ign, flair, flairclass, author); + } + Thread.sleep(10000); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + } + + public static Exception LastException; //2015.08.09. + + public String DownloadString(String urlstr) throws MalformedURLException, IOException + { + URL url = new URL(urlstr); + URLConnection con = url.openConnection(); + con.setRequestProperty("User-Agent", "TheButtonAutoFlair"); + InputStream in = con.getInputStream(); + String encoding = con.getContentEncoding(); + encoding = encoding == null ? "UTF-8" : encoding; + String body = IOUtils.toString(in, encoding); + in.close(); + return body; + } + + public static Map TownColors=new HashMap(); //2015.07.20. + public Boolean HasIGFlair(String playername) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + return p.Flair!=null; //2015.08.08. + } + + public void SetFlair(String playername, String text, String flairclass, String username) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + String finalflair; + p.FlairDecided=true; + switch(flairclass) + { + case "press-1": + finalflair="§c("+text+")§r"; + break; + case "press-2": + finalflair="§6("+text+")§r"; + break; + case "press-3": + finalflair="§e("+text+")§r"; + break; + case "press-4": + finalflair="§a("+text+")§r"; + break; + case "press-5": + finalflair="§9("+text+")§r"; + break; + 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; + case "undecided": //2015.08.09. + p.FlairDecided=false; + finalflair=""; + break; + default: + finalflair=""; + break; + } + if(finalflair.length()==0) //<-- 2015.07.20. + return; + p.Flair=finalflair; //2015.08.08. + p.UserName=username; //2015.08.08. + System.out.println("Added new flair to "+playername+": "+finalflair); + for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08. + { + if(player.getName().equals(playername)) + { + //AppendPlayerDisplayFlair(player, username, finalflair); + AppendPlayerDisplayFlair(p, player); + break; + } + } + } + + public static String GetFlair(Player player) + { //2015.07.16. + String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08. + return flair==null ? "" : flair; + } + + //public static void AppendPlayerDisplayFlair(Player player, String username, String flair) + public static void AppendPlayerDisplayFlair(MaybeOfflinePlayer player, Player p) //<-- 2015.08.09. + { + + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).IgnoredFlair) + return; + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).AcceptedFlair) + { + AppendPlayerDisplayFlairFinal(p, player.Flair); //2015.07.20. + if(!player.FlairDecided) + p.sendMessage("§9Your flair type is unknown. Are you a non-presser or a can't press? (/u nonpresser or /u cantpress)§r"); //2015.08.09. + } + else + p.sendMessage("§9Are you Reddit user "+player.UserName+"?§r §6Type /u accept or /u ignore§r"); + } + + private static void AppendPlayerDisplayFlairFinal(Player player, String flair) + { //2015.07.20. + String color = GetColorForTown(GetPlayerTown(player)); //TO!DO: Multiple colors put on first capital letters + String[] colors = color.substring(1).split("§"); + String displayname=player.getName(); //2015.08.08. + ArrayList Positions=new ArrayList<>(); + for(int i=0; i=colors.length) + { + int x=0; + for(int i=0; i GetPlayers() + { + return Instance.getServer().getOnlinePlayers(); + } + + public static void LoadFiles(boolean reload) + { + + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/82/00f1d2ebde3e001517108d149b613203 b/.metadata/.plugins/org.eclipse.core.resources/.history/82/00f1d2ebde3e001517108d149b613203 new file mode 100644 index 0000000..f007b97 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/82/00f1d2ebde3e001517108d149b613203 @@ -0,0 +1,228 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; + +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class Commands implements CommandExecutor { + // This method is called, when somebody uses our command + @Override + public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { + if (sender instanceof Player) { + Player player = (Player) sender; + if(args.length<1) + return false; + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. + //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) + if(p.Flair==null) + { + player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); + return true; + } + switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. + { + case "accept": + { + if(p.IgnoredFlair) + p.IgnoredFlair=false; //2015.08.08. + if(!p.AcceptedFlair) + { + String flair=p.Flair; //2015.08.08. + //PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + PluginMain.AppendPlayerDisplayFlair(p, player); + p.AcceptedFlair=true; //2015.08.08. + player.sendMessage("§6Your flair has been set:§r "+flair); + } + else + player.sendMessage("§cYou already have this user's flair.§r"); + break; + } + case "ignore": + { + if(p.AcceptedFlair) + p.AcceptedFlair=false; //2015.08.08. + if(!p.IgnoredFlair) + { + p.IgnoredFlair=true; + String flair=p.Flair; //2015.08.08. + PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. + player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); + } + else + player.sendMessage("§cYou already ignored this request.§r"); + break; + } + /*case "reload": //2015.07.20. + DoReload(player); + break;*/ + case "admin": //2015.08.09. + DoAdmin(player, args); + break; + case "nonpresser": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§7(non-pr.)§r"; + break; + case "cantpress": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§r(can't press)§r"; + break; + default: + return false; + } + return true; + } + /*if(args[0].toLowerCase()=="reload") + DoReload(null); //2015.07.20.*/ + else if(args.length>0 && args[0].toLowerCase().equals("admin")) //2015.08.09. + { + DoAdmin(null, args); //2015.08.09. + return true; //2015.08.09. + } + return false; + } + private static void DoReload(Player player) + { //2015.07.20. + //if(player==null || player.isOp() || player.getName()=="NorbiPeti") + //{ + try + { + File file=new File("autoflairconfig.txt"); + if(file.exists()) + { + PluginMain.LoadFiles(true); //2015.08.09. + for(Player p : PluginMain.GetPlayers()) + { + MaybeOfflinePlayer mp = MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName()); + if(mp.Flair!=null) + { + String flair=mp.Flair; + PluginMain.RemovePlayerDisplayFlairFinal(p, flair); + //PluginMain.AppendPlayerDisplayFlairFinal(p, flair); + PluginMain.AppendPlayerDisplayFlair(mp, p); //2015.08.09. + } + String msg="§6Note: The auto-flair plugin has been reloaded. You might need to wait 10s to have your flair.§r"; //2015.08.09. + p.sendMessage(msg); //2015.08.09. + } + //String msg="§6Reloaded config file.§r"; + //SendMessage(player, msg); //2015.08.09. + } + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + if(player!=null) + player.sendMessage("§cAn error occured. See console for details.§r"); + PluginMain.LastException=e; //2015.08.09. + } + //} + //else + //player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static Player ReloadPlayer; //2015.08.09. + private static void DoAdmin(Player player, String[] args) + { //2015.08.09. + if(player==null || player.isOp() || player.getName()=="NorbiPeti") + { + //System.out.println("Args length: " + args.length); + if(args.length==1) + { + String message="§cUsage: /u admin reload|playerinfo§r"; + SendMessage(player, message); + return; + } + //args[0] is "admin" + switch(args[1].toLowerCase()) + { + case "reload": + ReloadPlayer=player; //2015.08.09. + SendMessage(player, "§6Make sure to save the current settings before you modify and reload them! Type /u admin confirm when done.§r"); + break; + case "playerinfo": + DoPlayerInfo(player, args); + break; + case "getlasterror": + DoGetLastError(player, args); + case "confirm": + if(ReloadPlayer==player) + DoReload(player); //2015.08.09. + else + SendMessage(player, "§cYou need to do /u admin reload first.§r"); + break; + case "save": + PluginMain.SaveFiles(); //2015.08.09. + SendMessage(player, "§6Saved files. Now you can edit them and reload if you want.§r"); + break; + default: + String message="§cUsage: /u admin reload|playerinfo|getlasterror§r"; + SendMessage(player, message); + return; + } + } + else + player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static void DoPlayerInfo(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "playerinfo" + if(args.length==2) + { + String message="§cUsage: /u admin playerinfo §r"; + SendMessage(player, message); + return; + } + if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2])) + { + String message="§cPlayer not found: "+args[2]+"§r"; + SendMessage(player, message); + return; + } + MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]); + SendMessage(player, "Player name: "+p.PlayerName); + SendMessage(player, "User flair: "+p.Flair); + SendMessage(player, "Username: "+p.UserName); + SendMessage(player, "Flair accepted: "+p.AcceptedFlair); + SendMessage(player, "Flair ignored: "+p.IgnoredFlair); + } + public static void SendMessage(Player player, String message) + { //2015.08.09. + if(player==null) + System.out.println(message); + else + player.sendMessage(message); + } + private static void DoGetLastError(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "getlasterror" + if(PluginMain.LastException!=null) + { + SendMessage(player, "Last error:"); + SendMessage(player, PluginMain.LastException.toString()); + PluginMain.LastException=null; + } + else + SendMessage(player, "There were no exceptions."); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/82/201f90d5d03e001518fa86d7ae2a1cf8 b/.metadata/.plugins/org.eclipse.core.resources/.history/82/201f90d5d03e001518fa86d7ae2a1cf8 new file mode 100644 index 0000000..0384150 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/82/201f90d5d03e001518fa86d7ae2a1cf8 @@ -0,0 +1,211 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; + +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class Commands implements CommandExecutor { + // This method is called, when somebody uses our command + @Override + public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { + if (sender instanceof Player) { + Player player = (Player) sender; + if(args.length<1) + return false; + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. + //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) + if(p.Flair==null) + { + player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); + return true; + } + switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. + { + case "accept": + { + if(p.IgnoredFlair) + p.IgnoredFlair=false; //2015.08.08. + if(!p.AcceptedFlair) + { + String flair=p.Flair; //2015.08.08. + //PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + PluginMain.AppendPlayerDisplayFlair(p, player); + p.AcceptedFlair=true; //2015.08.08. + player.sendMessage("§6Your flair has been set:§r "+flair); + } + else + player.sendMessage("§cYou already have this user's flair.§r"); + break; + } + case "ignore": + { + if(p.AcceptedFlair) + p.AcceptedFlair=false; //2015.08.08. + if(!p.IgnoredFlair) + { + p.IgnoredFlair=true; + String flair=p.Flair; //2015.08.08. + PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. + player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); + } + else + player.sendMessage("§cYou already ignored this request.§r"); + break; + } + /*case "reload": //2015.07.20. + DoReload(player); + break;*/ + case "admin": //2015.08.09. + DoAdmin(player, args); + break; + case "nonpresser": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + + break; + case "cantpress": //2015.08.09. + break; + default: + return false; + } + return true; + } + /*if(args[0].toLowerCase()=="reload") + DoReload(null); //2015.07.20.*/ + else if(args.length>0 && args[0].toLowerCase().equals("admin")) //2015.08.09. + { + DoAdmin(null, args); //2015.08.09. + return true; //2015.08.09. + } + return false; + } + private static void DoReload(Player player) + { //2015.07.20. + //if(player==null || player.isOp() || player.getName()=="NorbiPeti") + //{ + try + { + File file=new File("autoflairconfig.txt"); + if(file.exists()) + { + PluginMain.TownColors.clear(); + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + PluginMain.TownColors.put(s[0], s[1]); + } + br.close(); + for(Player p : PluginMain.GetPlayers()) + { + MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName()); + if(mp.Flair!=null) + { + String flair=mp.Flair; + PluginMain.RemovePlayerDisplayFlairFinal(p, flair); + //PluginMain.AppendPlayerDisplayFlairFinal(p, flair); + PluginMain.AppendPlayerDisplayFlair(mp, p); //2015.08.09. + } + } + String msg="§6Reloaded config file.§r"; + SendMessage(player, msg); //2015.08.09. + } + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + if(player!=null) + player.sendMessage("§cAn error occured. See console for details.§r"); + PluginMain.LastException=e; //2015.08.09. + } + //} + //else + //player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static void DoAdmin(Player player, String[] args) + { //2015.08.09. + if(player==null || player.isOp() || player.getName()=="NorbiPeti") + { + //System.out.println("Args length: " + args.length); + if(args.length==1) + { + String message="§cUsage: /u admin reload|playerinfo§r"; + SendMessage(player, message); + return; + } + //args[0] is "admin" + switch(args[1].toLowerCase()) + { + case "reload": + DoReload(player); + break; + case "playerinfo": + DoPlayerInfo(player, args); + break; + case "getlasterror": + DoGetLastError(player, args); + default: + String message="§cUsage: /u admin reload|playerinfo§r"; + SendMessage(player, message); + return; + } + } + else + player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static void DoPlayerInfo(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "playerinfo" + if(args.length==2) + { + String message="§cUsage: /u admin playerinfo §r"; + SendMessage(player, message); + return; + } + if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2])) + { + String message="§cPlayer not found: "+args[2]+"§r"; + SendMessage(player, message); + return; + } + MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]); + SendMessage(player, "Player name: "+p.PlayerName); + SendMessage(player, "User flair: "+p.Flair); + SendMessage(player, "Username: "+p.UserName); + SendMessage(player, "Flair accepted: "+p.AcceptedFlair); + SendMessage(player, "Flair ignored: "+p.IgnoredFlair); + } + private static void SendMessage(Player player, String message) + { //2015.08.09. + if(player==null) + System.out.println(message); + else + player.sendMessage(message); + } + private static void DoGetLastError(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "getlasterror" + if(PluginMain.LastException!=null) + { + SendMessage(player, "Last error:"); + SendMessage(player, PluginMain.LastException.toString()); + PluginMain.LastException=null; + } + else + SendMessage(player, "There were no exceptions."); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/82/80cc011bdf3e001517108d149b613203 b/.metadata/.plugins/org.eclipse.core.resources/.history/82/80cc011bdf3e001517108d149b613203 new file mode 100644 index 0000000..eac777b --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/82/80cc011bdf3e001517108d149b613203 @@ -0,0 +1,250 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +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; + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. + //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) + if(p.Flair==null) + { + player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); + return true; + } + switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. + { + case "accept": + { + if(p.IgnoredFlair) + p.IgnoredFlair=false; //2015.08.08. + if(!p.AcceptedFlair) + { + String flair=p.Flair; //2015.08.08. + //PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + PluginMain.AppendPlayerDisplayFlair(p, player); + p.AcceptedFlair=true; //2015.08.08. + player.sendMessage("§6Your flair has been set:§r "+flair); + } + else + player.sendMessage("§cYou already have this user's flair.§r"); + break; + } + case "ignore": + { + if(p.AcceptedFlair) + p.AcceptedFlair=false; //2015.08.08. + if(!p.IgnoredFlair) + { + p.IgnoredFlair=true; + String flair=p.Flair; //2015.08.08. + PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. + player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); + } + else + player.sendMessage("§cYou already ignored this request.§r"); + break; + } + /*case "reload": //2015.07.20. + DoReload(player); + break;*/ + case "admin": //2015.08.09. + DoAdmin(player, args); + break; + case "nonpresser": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§7(non-pr.)§r"; + break; + case "cantpress": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§r(can't press)§r"; + break; + default: + return false; + } + return true; + } + /*if(args[0].toLowerCase()=="reload") + DoReload(null); //2015.07.20.*/ + else if(args.length>0 && args[0].toLowerCase().equals("admin")) //2015.08.09. + { + DoAdmin(null, args); //2015.08.09. + return true; //2015.08.09. + } + return false; + } + private static void DoReload(Player player) + { //2015.07.20. + //if(player==null || player.isOp() || player.getName()=="NorbiPeti") + //{ + try + { + File file=new File("autoflairconfig.txt"); + if(file.exists()) + { + PluginMain.LoadFiles(true); //2015.08.09. + for(Player p : PluginMain.GetPlayers()) + { + MaybeOfflinePlayer mp = MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName()); + if(mp.Flair!=null) + { + String flair=mp.Flair; + PluginMain.RemovePlayerDisplayFlairFinal(p, flair); + //PluginMain.AppendPlayerDisplayFlairFinal(p, flair); + PluginMain.AppendPlayerDisplayFlair(mp, p); //2015.08.09. + } + String msg="§6Note: The auto-flair plugin has been reloaded. You might need to wait 10s to have your flair.§r"; //2015.08.09. + p.sendMessage(msg); //2015.08.09. + } + //String msg="§6Reloaded config file.§r"; + //SendMessage(player, msg); //2015.08.09. + } + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + if(player!=null) + player.sendMessage("§cAn error occured. See console for details.§r"); + PluginMain.LastException=e; //2015.08.09. + } + //} + //else + //player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static Player ReloadPlayer; //2015.08.09. + private static void DoAdmin(Player player, String[] args) + { //2015.08.09. + if(player==null || player.isOp() || player.getName()=="NorbiPeti") + { + //System.out.println("Args length: " + args.length); + if(args.length==1) + { + String message="§cUsage: /u admin reload|playerinfo§r"; + SendMessage(player, message); + return; + } + //args[0] is "admin" + switch(args[1].toLowerCase()) + { + case "reload": + ReloadPlayer=player; //2015.08.09. + SendMessage(player, "§6Make sure to save the current settings before you modify and reload them! Type /u admin confirm when done.§r"); + break; + case "playerinfo": + DoPlayerInfo(player, args); + break; + case "getlasterror": + DoGetLastError(player, args); + case "confirm": + if(ReloadPlayer==player) + DoReload(player); //2015.08.09. + else + SendMessage(player, "§cYou need to do /u admin reload first.§r"); + break; + case "save": + PluginMain.SaveFiles(); //2015.08.09. + SendMessage(player, "§6Saved files. Now you can edit them and reload if you want.§r"); + break; + default: + String message="§cUsage: /u admin reload|playerinfo|getlasterror§r"; + SendMessage(player, message); + return; + } + } + else + player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static void DoPlayerInfo(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "playerinfo" + if(args.length==2) + { + String message="§cUsage: /u admin playerinfo §r"; + SendMessage(player, message); + return; + } + if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2])) + { + String message="§cPlayer not found: "+args[2]+"§r"; + SendMessage(player, message); + return; + } + MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]); + SendMessage(player, "Player name: "+p.PlayerName); + SendMessage(player, "User flair: "+p.Flair); + SendMessage(player, "Username: "+p.UserName); + SendMessage(player, "Flair accepted: "+p.AcceptedFlair); + SendMessage(player, "Flair ignored: "+p.IgnoredFlair); + } + private static void SendMessage(Player player, String message) + { //2015.08.09. + if(player==null) + System.out.println(message); + else + player.sendMessage(message); + } + private static void DoGetLastError(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "getlasterror" + if(PluginMain.LastException!=null) + { + SendMessage(player, "Last error:"); + SendMessage(player, PluginMain.LastException.toString()); + PluginMain.LastException=null; + } + else + SendMessage(player, "There were no exceptions."); + } + private static void SetPlayerFlair(Player player, String flair) + { //2015.08.09. + flair=flair.replace('&', '§'); + MaybeOfflinePlayer.AddPlayerIfNeeded(player.getName()).Flair=flair; + if(!PluginMain.RemoveLineFromFile("customflairs.txt")) + { + SendMessage(player, "Error removing previous custom flair!"); + } + File file=new File("customflairs.txt"); + try { + BufferedWriter bw; + bw = new BufferedWriter(new FileWriter(file, true)); + bw.write(player.getName()+"\n"); + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + PluginMain.LastException=e; //2015.08.09. + } + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/83/20a1e315cf3e001518fa86d7ae2a1cf8 b/.metadata/.plugins/org.eclipse.core.resources/.history/83/20a1e315cf3e001518fa86d7ae2a1cf8 new file mode 100644 index 0000000..72f8cf3 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/83/20a1e315cf3e001518fa86d7ae2a1cf8 @@ -0,0 +1,362 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStream; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLConnection; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + +import org.apache.commons.io.IOUtils; +import org.bukkit.entity.Player; +import org.bukkit.plugin.java.JavaPlugin; +import org.json.JSONArray; +import org.json.JSONObject; + +import tk.sznp.thebuttonautoflair.MaybeOfflinePlayer.FlairClassType; + +import com.palmergames.bukkit.towny.object.Town; +import com.palmergames.bukkit.towny.object.WorldCoord; + +public class PluginMain extends JavaPlugin +{ //Translated to Java: 2015.07.15. + //A user, which flair isn't obtainable: + //https://www.reddit.com/r/thebutton/comments/31c32v/i_pressed_the_button_without_really_thinking/ + private static PluginMain Instance; + // Fired when plugin is first enabled + @Override + public void onEnable() + { + System.out.println("The Button Auto-flair Plugin by NorbiPeti (:P)"); + getServer().getPluginManager().registerEvents(new PlayerListener(), this); + this.getCommand("u").setExecutor(new Commands()); + this.getCommand("u").setUsage(this.getCommand("u").getUsage().replace('&', '§')); + Instance=this; //2015.08.08. + try { + File file=new File("flairsaccepted.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + //System.out.println("Name: " + name); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("flairsignored.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsignored.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("autoflairconfig.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + TownColors.put(s[0], s[1]); + } + br.close(); + } + //throw new IOException("Test"); //2015.08.09. + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + Runnable r=new Runnable(){public void run(){ThreadMethod();}}; + Thread t=new Thread(r); + t.start(); + } + Boolean stop=false; + // Fired when plugin is disabled + @Override + public void onDisable() + { + try + { + FileWriter fw; + fw = new FileWriter("flairsaccepted.txt"); + fw.close(); + fw = new FileWriter("flairsignored.txt"); + fw.close(); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + try { + File file=new File("flairsaccepted.txt"); + BufferedWriter bw=new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.AcceptedFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + file=new File("flairsignored.txt"); + bw = new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.IgnoredFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + stop=true; + } + + public void ThreadMethod() //<-- 2015.07.16. + { + while(!stop) + { + try + { + String body=DownloadString("https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/autoflair_system_comment_your_minecraft_name_and/.json?limit=1000"); + JSONArray json=new JSONArray(body).getJSONObject(1).getJSONObject("data").getJSONArray("children"); + for(Object obj : json) + { + JSONObject item = (JSONObject)obj; + String author=item.getJSONObject("data").getString("author"); + String ign=item.getJSONObject("data").getString("body"); + int start = ign.indexOf("IGN:") + "IGN:".length(); + int end = ign.indexOf(' ', start); + if (end == -1 || end == start) + end=ign.indexOf('\n', start); //2015.07.15. + if (end == -1 || end == start) + ign = ign.substring(start); + else + ign = ign.substring(start, end); + ign = ign.trim(); + if(HasIGFlair(ign)) + continue; + try { + Thread.sleep(10); + } catch(InterruptedException ex) { + Thread.currentThread().interrupt(); + } + String[] flairdata = DownloadString("http://karmadecay.com/thebutton-data.php?users=" + author).replace("\"", "").split(":"); + String flair; + if(flairdata.length > 1) //2015.07.15. + flair = flairdata[1]; + else + flair=""; + if (flair != "-1") + flair = flair + "s"; + else + flair = "non-presser"; + String flairclass; + if(flairdata.length>2) + flairclass = flairdata[2]; + else + flairclass="unknown"; + SetFlair(ign, flair, flairclass, author); + } + Thread.sleep(10000); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + } + + public static Exception LastException; //2015.08.09. + + public String DownloadString(String urlstr) throws MalformedURLException, IOException + { + URL url = new URL(urlstr); + URLConnection con = url.openConnection(); + con.setRequestProperty("User-Agent", "TheButtonAutoFlair"); + InputStream in = con.getInputStream(); + String encoding = con.getContentEncoding(); + encoding = encoding == null ? "UTF-8" : encoding; + String body = IOUtils.toString(in, encoding); + in.close(); + return body; + } + + public static Map TownColors=new HashMap(); //2015.07.20. + public Boolean HasIGFlair(String playername) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + return p.Flair!=null; //2015.08.08. + } + + public void SetFlair(String playername, String text, String flairclass, String username) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + String finalflair; + p.FlairDecided=true; + switch(flairclass) + { + case "press-1": + finalflair="§c("+text+")§r"; + break; + case "press-2": + finalflair="§6("+text+")§r"; + break; + case "press-3": + finalflair="§e("+text+")§r"; + break; + case "press-4": + finalflair="§a("+text+")§r"; + break; + case "press-5": + finalflair="§9("+text+")§r"; + break; + 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; + case "undecided": //2015.08.09. + p.FlairDecided=false; + finalflair=""; + break; + default: + finalflair=""; + break; + } + if(finalflair.length()==0) //<-- 2015.07.20. + return; + p.Flair=finalflair; //2015.08.08. + p.UserName=username; //2015.08.08. + System.out.println("Added new flair to "+playername+": "+finalflair); + for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08. + { + if(player.getName().equals(playername)) + { + AppendPlayerDisplayFlair(player, username, finalflair); + break; + } + } + } + + public static String GetFlair(Player player) + { //2015.07.16. + String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08. + return flair==null ? "" : flair; + } + + //public static void AppendPlayerDisplayFlair(Player player, String username, String flair) + public static void AppendPlayerDisplayFlair(MaybeOfflinePlayer player, Player p) + { + + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).IgnoredFlair) + return; + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).AcceptedFlair) + { + AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + } + else + player.sendMessage("§9Are you Reddit user "+username+"?§r §6Type /u accept or /u ignore§r"); + } + + private static void AppendPlayerDisplayFlairFinal(Player player, String flair) + { //2015.07.20. + String color = GetColorForTown(GetPlayerTown(player)); //TO!DO: Multiple colors put on first capital letters + String[] colors = color.substring(1).split("§"); + String displayname=player.getName(); //2015.08.08. + ArrayList Positions=new ArrayList<>(); + for(int i=0; i=colors.length) + { + int x=0; + for(int i=0; i GetPlayers() + { + return Instance.getServer().getOnlinePlayers(); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/83/90fff2badd3e001517108d149b613203 b/.metadata/.plugins/org.eclipse.core.resources/.history/83/90fff2badd3e001517108d149b613203 new file mode 100644 index 0000000..777c16f --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/83/90fff2badd3e001517108d149b613203 @@ -0,0 +1,411 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStream; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLConnection; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + +import org.apache.commons.io.IOUtils; +import org.bukkit.entity.Player; +import org.bukkit.plugin.java.JavaPlugin; +import org.json.JSONArray; +import org.json.JSONObject; + +import com.palmergames.bukkit.towny.object.Town; +import com.palmergames.bukkit.towny.object.WorldCoord; + +public class PluginMain extends JavaPlugin +{ //Translated to Java: 2015.07.15. + //A user, which flair isn't obtainable: + //https://www.reddit.com/r/thebutton/comments/31c32v/i_pressed_the_button_without_really_thinking/ + private static PluginMain Instance; + // Fired when plugin is first enabled + @Override + public void onEnable() + { + System.out.println("The Button Auto-flair Plugin by NorbiPeti (:P)"); + getServer().getPluginManager().registerEvents(new PlayerListener(), this); + this.getCommand("u").setExecutor(new Commands()); + this.getCommand("u").setUsage(this.getCommand("u").getUsage().replace('&', '§')); + Instance=this; //2015.08.08. + LoadFiles(false); //2015.08.09. + Runnable r=new Runnable(){public void run(){ThreadMethod();}}; + Thread t=new Thread(r); + t.start(); + } + Boolean stop=false; + // Fired when plugin is disabled + @Override + public void onDisable() + { + SaveFiles(); //2015.08.09. + stop=true; + } + + public void ThreadMethod() //<-- 2015.07.16. + { + while(!stop) + { + try + { + String body=DownloadString("https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/autoflair_system_comment_your_minecraft_name_and/.json?limit=1000"); + JSONArray json=new JSONArray(body).getJSONObject(1).getJSONObject("data").getJSONArray("children"); + for(Object obj : json) + { + JSONObject item = (JSONObject)obj; + String author=item.getJSONObject("data").getString("author"); + String ign=item.getJSONObject("data").getString("body"); + int start = ign.indexOf("IGN:") + "IGN:".length(); + if(start==-1) + continue; //2015.08.09. + int end = ign.indexOf(' ', start); + if (end == -1 || end == start) + end=ign.indexOf('\n', start); //2015.07.15. + if (end == -1 || end == start) + ign = ign.substring(start); + else + ign = ign.substring(start, end); + ign = ign.trim(); + if(HasIGFlair(ign)) + continue; + try { + Thread.sleep(10); + } catch(InterruptedException ex) { + Thread.currentThread().interrupt(); + } + String[] flairdata = DownloadString("http://karmadecay.com/thebutton-data.php?users=" + author).replace("\"", "").split(":"); + String flair; + if(flairdata.length > 1) //2015.07.15. + flair = flairdata[1]; + else + flair=""; + if (flair != "-1") + flair = flair + "s"; + else + flair = "non-presser"; + String flairclass; + if(flairdata.length>2) + flairclass = flairdata[2]; + else + flairclass="unknown"; + SetFlair(ign, flair, flairclass, author); + } + Thread.sleep(10000); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + } + + public static Exception LastException; //2015.08.09. + + public String DownloadString(String urlstr) throws MalformedURLException, IOException + { + URL url = new URL(urlstr); + URLConnection con = url.openConnection(); + con.setRequestProperty("User-Agent", "TheButtonAutoFlair"); + InputStream in = con.getInputStream(); + String encoding = con.getContentEncoding(); + encoding = encoding == null ? "UTF-8" : encoding; + String body = IOUtils.toString(in, encoding); + in.close(); + return body; + } + + public static Map TownColors=new HashMap(); //2015.07.20. + public Boolean HasIGFlair(String playername) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + return p.Flair!=null; //2015.08.08. + } + + public void SetFlair(String playername, String text, String flairclass, String username) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + String finalflair; + p.FlairDecided=true; + switch(flairclass) + { + case "press-1": + finalflair="§c("+text+")§r"; + break; + case "press-2": + finalflair="§6("+text+")§r"; + break; + case "press-3": + finalflair="§e("+text+")§r"; + break; + case "press-4": + finalflair="§a("+text+")§r"; + break; + case "press-5": + finalflair="§9("+text+")§r"; + break; + 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; + case "undecided": //2015.08.09. + p.FlairDecided=false; + finalflair=""; + break; + default: + finalflair=""; + break; + } + if(finalflair.length()==0) //<-- 2015.07.20. + return; + p.Flair=finalflair; //2015.08.08. + p.UserName=username; //2015.08.08. + System.out.println("Added new flair to "+playername+": "+finalflair); + for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08. + { + if(player.getName().equals(playername)) + { + //AppendPlayerDisplayFlair(player, username, finalflair); + AppendPlayerDisplayFlair(p, player); + break; + } + } + } + + public static String GetFlair(Player player) + { //2015.07.16. + String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08. + return flair==null ? "" : flair; + } + + //public static void AppendPlayerDisplayFlair(Player player, String username, String flair) + public static void AppendPlayerDisplayFlair(MaybeOfflinePlayer player, Player p) //<-- 2015.08.09. + { + + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).IgnoredFlair) + return; + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).AcceptedFlair) + { + AppendPlayerDisplayFlairFinal(p, player.Flair); //2015.07.20. + if(!player.FlairDecided) + p.sendMessage("§9Your flair type is unknown. Are you a non-presser or a can't press? (/u nonpresser or /u cantpress)§r"); //2015.08.09. + } + else + p.sendMessage("§9Are you Reddit user "+player.UserName+"?§r §6Type /u accept or /u ignore§r"); + } + + private static void AppendPlayerDisplayFlairFinal(Player player, String flair) + { //2015.07.20. + String color = GetColorForTown(GetPlayerTown(player)); //TO!DO: Multiple colors put on first capital letters + String[] colors = color.substring(1).split("§"); + String displayname=player.getName(); //2015.08.08. + ArrayList Positions=new ArrayList<>(); + for(int i=0; i=colors.length) + { + int x=0; + for(int i=0; i GetPlayers() + { + return Instance.getServer().getOnlinePlayers(); + } + + public static void LoadFiles(boolean reload) //<-- 2015.08.09. + { + if(reload) + { //2015.08.09. + System.out.println("Auto-flair plugin cleanup for reloading..."); + MaybeOfflinePlayer.AllPlayers.clear(); + TownColors.clear(); + } + System.out.println("Loading files for auto-flair plugin..."); //2015.08.09. + try { + File file=new File("flairsaccepted.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + //System.out.println("Name: " + name); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("flairsignored.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsignored.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("autoflairconfig.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + TownColors.put(s[0], s[1]); + } + br.close(); + } + file=new File("customflairs.txt"); //2015.08.09. + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + MaybeOfflinePlayer.AddPlayerIfNeeded(s[0]).Flair=s[1]; //2015.08.09. + } + br.close(); + } + //throw new IOException("Test"); //2015.08.09. + System.out.println("Auto-flair plugin loaded files!"); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + public static void SaveFiles() //<-- 2015.08.09. + { + try + { + FileWriter fw; + fw = new FileWriter("flairsaccepted.txt"); + fw.close(); + fw = new FileWriter("flairsignored.txt"); + fw.close(); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + try { + File file=new File("flairsaccepted.txt"); + BufferedWriter bw=new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.AcceptedFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + file=new File("flairsignored.txt"); + bw = new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.IgnoredFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + public static void SetPlayerFlair(Player + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09., String flair) + { //2015.08.09. + flair=flair.replace('&', '§'); + MaybeOfflinePlayer.AddPlayerIfNeeded(player.getName()).Flair=flair; + File file=new File("customflairs.txt"); + BufferedWriter bw; + try { + bw = new BufferedWriter(new FileWriter(file, true)); + bw.write(player.getName()+"\n"); + bw.close(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/84/a0c00f13cf3e001518fa86d7ae2a1cf8 b/.metadata/.plugins/org.eclipse.core.resources/.history/84/a0c00f13cf3e001518fa86d7ae2a1cf8 new file mode 100644 index 0000000..999a5ae --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/84/a0c00f13cf3e001518fa86d7ae2a1cf8 @@ -0,0 +1,362 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStream; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLConnection; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + +import org.apache.commons.io.IOUtils; +import org.bukkit.entity.Player; +import org.bukkit.plugin.java.JavaPlugin; +import org.json.JSONArray; +import org.json.JSONObject; + +import tk.sznp.thebuttonautoflair.MaybeOfflinePlayer.FlairClassType; + +import com.palmergames.bukkit.towny.object.Town; +import com.palmergames.bukkit.towny.object.WorldCoord; + +public class PluginMain extends JavaPlugin +{ //Translated to Java: 2015.07.15. + //A user, which flair isn't obtainable: + //https://www.reddit.com/r/thebutton/comments/31c32v/i_pressed_the_button_without_really_thinking/ + private static PluginMain Instance; + // Fired when plugin is first enabled + @Override + public void onEnable() + { + System.out.println("The Button Auto-flair Plugin by NorbiPeti (:P)"); + getServer().getPluginManager().registerEvents(new PlayerListener(), this); + this.getCommand("u").setExecutor(new Commands()); + this.getCommand("u").setUsage(this.getCommand("u").getUsage().replace('&', '§')); + Instance=this; //2015.08.08. + try { + File file=new File("flairsaccepted.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + //System.out.println("Name: " + name); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("flairsignored.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsignored.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("autoflairconfig.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + TownColors.put(s[0], s[1]); + } + br.close(); + } + //throw new IOException("Test"); //2015.08.09. + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + Runnable r=new Runnable(){public void run(){ThreadMethod();}}; + Thread t=new Thread(r); + t.start(); + } + Boolean stop=false; + // Fired when plugin is disabled + @Override + public void onDisable() + { + try + { + FileWriter fw; + fw = new FileWriter("flairsaccepted.txt"); + fw.close(); + fw = new FileWriter("flairsignored.txt"); + fw.close(); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + try { + File file=new File("flairsaccepted.txt"); + BufferedWriter bw=new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.AcceptedFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + file=new File("flairsignored.txt"); + bw = new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.IgnoredFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + stop=true; + } + + public void ThreadMethod() //<-- 2015.07.16. + { + while(!stop) + { + try + { + String body=DownloadString("https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/autoflair_system_comment_your_minecraft_name_and/.json?limit=1000"); + JSONArray json=new JSONArray(body).getJSONObject(1).getJSONObject("data").getJSONArray("children"); + for(Object obj : json) + { + JSONObject item = (JSONObject)obj; + String author=item.getJSONObject("data").getString("author"); + String ign=item.getJSONObject("data").getString("body"); + int start = ign.indexOf("IGN:") + "IGN:".length(); + int end = ign.indexOf(' ', start); + if (end == -1 || end == start) + end=ign.indexOf('\n', start); //2015.07.15. + if (end == -1 || end == start) + ign = ign.substring(start); + else + ign = ign.substring(start, end); + ign = ign.trim(); + if(HasIGFlair(ign)) + continue; + try { + Thread.sleep(10); + } catch(InterruptedException ex) { + Thread.currentThread().interrupt(); + } + String[] flairdata = DownloadString("http://karmadecay.com/thebutton-data.php?users=" + author).replace("\"", "").split(":"); + String flair; + if(flairdata.length > 1) //2015.07.15. + flair = flairdata[1]; + else + flair=""; + if (flair != "-1") + flair = flair + "s"; + else + flair = "non-presser"; + String flairclass; + if(flairdata.length>2) + flairclass = flairdata[2]; + else + flairclass="unknown"; + SetFlair(ign, flair, flairclass, author); + } + Thread.sleep(10000); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + } + + public static Exception LastException; //2015.08.09. + + public String DownloadString(String urlstr) throws MalformedURLException, IOException + { + URL url = new URL(urlstr); + URLConnection con = url.openConnection(); + con.setRequestProperty("User-Agent", "TheButtonAutoFlair"); + InputStream in = con.getInputStream(); + String encoding = con.getContentEncoding(); + encoding = encoding == null ? "UTF-8" : encoding; + String body = IOUtils.toString(in, encoding); + in.close(); + return body; + } + + public static Map TownColors=new HashMap(); //2015.07.20. + public Boolean HasIGFlair(String playername) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + return p.Flair!=null; //2015.08.08. + } + + public void SetFlair(String playername, String text, String flairclass, String username) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + String finalflair; + p.FlairDecided=true; + switch(flairclass) + { + case "press-1": + finalflair="§c("+text+")§r"; + break; + case "press-2": + finalflair="§6("+text+")§r"; + break; + case "press-3": + finalflair="§e("+text+")§r"; + break; + case "press-4": + finalflair="§a("+text+")§r"; + break; + case "press-5": + finalflair="§9("+text+")§r"; + break; + 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; + case "undecided": //2015.08.09. + p.FlairDecided=false; + finalflair=""; + break; + default: + finalflair=""; + break; + } + if(finalflair.length()==0) //<-- 2015.07.20. + return; + p.Flair=finalflair; //2015.08.08. + p.UserName=username; //2015.08.08. + System.out.println("Added new flair to "+playername+": "+finalflair); + for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08. + { + if(player.getName().equals(playername)) + { + AppendPlayerDisplayFlair(player, username, finalflair); + break; + } + } + } + + public static String GetFlair(Player player) + { //2015.07.16. + String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08. + return flair==null ? "" : flair; + } + + //public static void AppendPlayerDisplayFlair(Player player, String username, String flair) + public static void AppendPlayerDisplayFlair(MaybeOfflinePlayer player, Player p) + { + + if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).IgnoredFlair) + return; + if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).AcceptedFlair) + { + AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + } + else + player.sendMessage("§9Are you Reddit user "+username+"?§r §6Type /u accept or /u ignore§r"); + } + + private static void AppendPlayerDisplayFlairFinal(Player player, String flair) + { //2015.07.20. + String color = GetColorForTown(GetPlayerTown(player)); //TO!DO: Multiple colors put on first capital letters + String[] colors = color.substring(1).split("§"); + String displayname=player.getName(); //2015.08.08. + ArrayList Positions=new ArrayList<>(); + for(int i=0; i=colors.length) + { + int x=0; + for(int i=0; i GetPlayers() + { + return Instance.getServer().getOnlinePlayers(); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/85/f037c8f6843e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/85/f037c8f6843e00151ce8ff6d4f74dabd deleted file mode 100644 index 9f42545..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/85/f037c8f6843e00151ce8ff6d4f74dabd +++ /dev/null @@ -1,119 +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; - MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. - //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - if(p.Flair==null) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. - { - case "accept": - { - if(p.IgnoredFlair) - p.IgnoredFlair=false; //2015.08.08. - if(!p.AcceptedFlair) - { - String flair=p.Flair; //2015.08.08. - PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. - p.AcceptedFlair=true; //2015.08.08. - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("§cYou already have this user's flair.§r"); - break; - } - case "ignore": - { - if(p.AcceptedFlair) - p.AcceptedFlair=false; //2015.08.08. - if(!p.IgnoredFlair) - { - p.IgnoredFlair=true; - String flair=p.Flair; //2015.08.08. - PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. - player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); - } - else - player.sendMessage("§cYou already ignored this request.§r"); - break; - } - case "reload": //2015.07.20. - DoReload(player); - break; - case "showerrors": //2015.08.09. - break; - default: - return false; - } - return true; - } - - if(args[0]=="reload") - DoReload(null); //2015.07.20. - return false; - } - private static void DoReload(Player player) - { //2015.07.20. - if(player==null || player.isOp() || player.getName()=="NorbiPeti") - { - try - { - File file=new File("autoflairconfig.txt"); - if(file.exists()) - { - PluginMain.TownColors.clear(); - BufferedReader br=new BufferedReader(new FileReader(file)); - String line; - while((line=br.readLine())!=null) - { - String[] s=line.split(" "); - PluginMain.TownColors.put(s[0], s[1]); - } - br.close(); - for(Player p : PluginMain.GetPlayers()) - { - MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName()); - if(mp.Flair!=null) - { - String flair=mp.Flair; - PluginMain.RemovePlayerDisplayFlairFinal(p, flair); - PluginMain.AppendPlayerDisplayFlairFinal(p, flair); - } - } - String msg="§6Reloaded config file.§r"; - if(player!=null) - player.sendMessage(msg); - else - System.out.println(msg); - } - } - catch(Exception e) - { - System.out.println("Error!\n"+e); - if(player!=null) - player.sendMessage("§cAn error occured. See console for details.§r"); - } - } - else - player.sendMessage("§cYou need to be OP to use this command.§r"); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/86/e024da2a853e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/86/e024da2a853e00151ce8ff6d4f74dabd deleted file mode 100644 index 2e97c39..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/86/e024da2a853e00151ce8ff6d4f74dabd +++ /dev/null @@ -1,129 +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; - MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. - //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - if(p.Flair==null) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. - { - case "accept": - { - if(p.IgnoredFlair) - p.IgnoredFlair=false; //2015.08.08. - if(!p.AcceptedFlair) - { - String flair=p.Flair; //2015.08.08. - PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. - p.AcceptedFlair=true; //2015.08.08. - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("§cYou already have this user's flair.§r"); - break; - } - case "ignore": - { - if(p.AcceptedFlair) - p.AcceptedFlair=false; //2015.08.08. - if(!p.IgnoredFlair) - { - p.IgnoredFlair=true; - String flair=p.Flair; //2015.08.08. - PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. - player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); - } - else - player.sendMessage("§cYou already ignored this request.§r"); - break; - } - case "reload": //2015.07.20. - DoReload(player); - break; - case "showerrors": //2015.08.09. - DoShowErrors(player); - break; - default: - return false; - } - return true; - } - - if(args[0].toLowerCase()=="reload") - DoReload(null); //2015.07.20. - else if(args[0].toLowerCase()=="showerrors") - DoShowErrors(null); //2015.08.09. - return false; - } - private static void DoReload(Player player) - { //2015.07.20. - if(player==null || player.isOp() || player.getName()=="NorbiPeti") - { - try - { - File file=new File("autoflairconfig.txt"); - if(file.exists()) - { - PluginMain.TownColors.clear(); - BufferedReader br=new BufferedReader(new FileReader(file)); - String line; - while((line=br.readLine())!=null) - { - String[] s=line.split(" "); - PluginMain.TownColors.put(s[0], s[1]); - } - br.close(); - for(Player p : PluginMain.GetPlayers()) - { - MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName()); - if(mp.Flair!=null) - { - String flair=mp.Flair; - PluginMain.RemovePlayerDisplayFlairFinal(p, flair); - PluginMain.AppendPlayerDisplayFlairFinal(p, flair); - } - } - String msg="§6Reloaded config file.§r"; - if(player!=null) - player.sendMessage(msg); - else - System.out.println(msg); - } - } - catch(Exception e) - { - System.out.println("Error!\n"+e); - if(player!=null) - player.sendMessage("§cAn error occured. See console for details.§r"); - } - } - else - player.sendMessage("§cYou need to be OP to use this command.§r"); - } - private static void DoShowErrors(Player player) - { - if(player==null || player.isOp() || player.getName()=="NorbiPeti") - { - - } - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/88/101b2028df3e001517108d149b613203 b/.metadata/.plugins/org.eclipse.core.resources/.history/88/101b2028df3e001517108d149b613203 new file mode 100644 index 0000000..5f009d8 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/88/101b2028df3e001517108d149b613203 @@ -0,0 +1,251 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +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; + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. + //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) + if(p.Flair==null) + { + player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); + return true; + } + switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. + { + case "accept": + { + if(p.IgnoredFlair) + p.IgnoredFlair=false; //2015.08.08. + if(!p.AcceptedFlair) + { + String flair=p.Flair; //2015.08.08. + //PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + PluginMain.AppendPlayerDisplayFlair(p, player); + p.AcceptedFlair=true; //2015.08.08. + player.sendMessage("§6Your flair has been set:§r "+flair); + } + else + player.sendMessage("§cYou already have this user's flair.§r"); + break; + } + case "ignore": + { + if(p.AcceptedFlair) + p.AcceptedFlair=false; //2015.08.08. + if(!p.IgnoredFlair) + { + p.IgnoredFlair=true; + String flair=p.Flair; //2015.08.08. + PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. + player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); + } + else + player.sendMessage("§cYou already ignored this request.§r"); + break; + } + /*case "reload": //2015.07.20. + DoReload(player); + break;*/ + case "admin": //2015.08.09. + DoAdmin(player, args); + break; + case "nonpresser": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§7(non-pr.)§r"; + break; + case "cantpress": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§r(can't press)§r"; + break; + default: + return false; + } + return true; + } + /*if(args[0].toLowerCase()=="reload") + DoReload(null); //2015.07.20.*/ + else if(args.length>0 && args[0].toLowerCase().equals("admin")) //2015.08.09. + { + DoAdmin(null, args); //2015.08.09. + return true; //2015.08.09. + } + return false; + } + private static void DoReload(Player player) + { //2015.07.20. + //if(player==null || player.isOp() || player.getName()=="NorbiPeti") + //{ + try + { + File file=new File("autoflairconfig.txt"); + if(file.exists()) + { + PluginMain.LoadFiles(true); //2015.08.09. + for(Player p : PluginMain.GetPlayers()) + { + MaybeOfflinePlayer mp = MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName()); + if(mp.Flair!=null) + { + String flair=mp.Flair; + PluginMain.RemovePlayerDisplayFlairFinal(p, flair); + //PluginMain.AppendPlayerDisplayFlairFinal(p, flair); + PluginMain.AppendPlayerDisplayFlair(mp, p); //2015.08.09. + } + String msg="§6Note: The auto-flair plugin has been reloaded. You might need to wait 10s to have your flair.§r"; //2015.08.09. + p.sendMessage(msg); //2015.08.09. + } + //String msg="§6Reloaded config file.§r"; + //SendMessage(player, msg); //2015.08.09. + } + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + if(player!=null) + player.sendMessage("§cAn error occured. See console for details.§r"); + PluginMain.LastException=e; //2015.08.09. + } + //} + //else + //player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static Player ReloadPlayer; //2015.08.09. + private static void DoAdmin(Player player, String[] args) + { //2015.08.09. + if(player==null || player.isOp() || player.getName()=="NorbiPeti") + { + //System.out.println("Args length: " + args.length); + if(args.length==1) + { + String message="§cUsage: /u admin reload|playerinfo§r"; + SendMessage(player, message); + return; + } + //args[0] is "admin" + switch(args[1].toLowerCase()) + { + case "reload": + ReloadPlayer=player; //2015.08.09. + SendMessage(player, "§6Make sure to save the current settings before you modify and reload them! Type /u admin confirm when done.§r"); + break; + case "playerinfo": + DoPlayerInfo(player, args); + break; + case "getlasterror": + DoGetLastError(player, args); + case "confirm": + if(ReloadPlayer==player) + DoReload(player); //2015.08.09. + else + SendMessage(player, "§cYou need to do /u admin reload first.§r"); + break; + case "save": + PluginMain.SaveFiles(); //2015.08.09. + SendMessage(player, "§6Saved files. Now you can edit them and reload if you want.§r"); + break; + default: + String message="§cUsage: /u admin reload|playerinfo|getlasterror§r"; + SendMessage(player, message); + return; + } + } + else + player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static void DoPlayerInfo(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "playerinfo" + if(args.length==2) + { + String message="§cUsage: /u admin playerinfo §r"; + SendMessage(player, message); + return; + } + if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2])) + { + String message="§cPlayer not found: "+args[2]+"§r"; + SendMessage(player, message); + return; + } + MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]); + SendMessage(player, "Player name: "+p.PlayerName); + SendMessage(player, "User flair: "+p.Flair); + SendMessage(player, "Username: "+p.UserName); + SendMessage(player, "Flair accepted: "+p.AcceptedFlair); + SendMessage(player, "Flair ignored: "+p.IgnoredFlair); + } + private static void SendMessage(Player player, String message) + { //2015.08.09. + if(player==null) + System.out.println(message); + else + player.sendMessage(message); + } + private static void DoGetLastError(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "getlasterror" + if(PluginMain.LastException!=null) + { + SendMessage(player, "Last error:"); + SendMessage(player, PluginMain.LastException.toString()); + PluginMain.LastException=null; + } + else + SendMessage(player, "There were no exceptions."); + } + private static void SetPlayerFlair(Player player, String flair) + { //2015.08.09. + flair=flair.replace('&', '§'); + MaybeOfflinePlayer.AddPlayerIfNeeded(player.getName()).Flair=flair; + if(!PluginMain.RemoveLineFromFile("customflairs.txt")) + { + SendMessage(player, "Error removing previous custom flair!"); + return + } + File file=new File("customflairs.txt"); + try { + BufferedWriter bw; + bw = new BufferedWriter(new FileWriter(file, true)); + bw.write(player.getName()+"\n"); + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + PluginMain.LastException=e; //2015.08.09. + } + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/88/e001984d0e3e00151089cca86c5b1a99 b/.metadata/.plugins/org.eclipse.core.resources/.history/88/e001984d0e3e00151089cca86c5b1a99 deleted file mode 100644 index e7381d7..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/88/e001984d0e3e00151089cca86c5b1a99 +++ /dev/null @@ -1,434 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import java.io.BufferedReader; -import java.io.BufferedWriter; -import java.io.File; -import java.io.FileReader; -import java.io.FileWriter; -import java.io.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/80137592e43e001517108d149b613203 b/.metadata/.plugins/org.eclipse.core.resources/.history/89/80137592e43e001517108d149b613203 new file mode 100644 index 0000000..69b0f0a --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/89/80137592e43e001517108d149b613203 @@ -0,0 +1,263 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedWriter; +import java.io.File; +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; + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. + //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) + if(p.Flair==null) + { + player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); + return true; + } + switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. + { + case "accept": + { + if(p.IgnoredFlair) + p.IgnoredFlair=false; //2015.08.08. + if(!p.AcceptedFlair) + { + String flair=p.Flair; //2015.08.08. + //PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + PluginMain.AppendPlayerDisplayFlair(p, player); + p.AcceptedFlair=true; //2015.08.08. + player.sendMessage("§6Your flair has been set:§r "+flair); + } + else + player.sendMessage("§cYou already have this user's flair.§r"); + break; + } + case "ignore": + { + if(p.AcceptedFlair) + p.AcceptedFlair=false; //2015.08.08. + if(!p.IgnoredFlair) + { + p.IgnoredFlair=true; + //String flair=p.Flair; //2015.08.08. + //PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. + player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); + } + else + player.sendMessage("§cYou already ignored this request.§r"); + break; + } + /*case "reload": //2015.07.20. + DoReload(player); + break;*/ + case "admin": //2015.08.09. + DoAdmin(player, args); + break; + case "nonpresser": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§7(non-pr.)§r"; + break; + case "cantpress": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§r(can't press)§r"; + break; + default: + return false; + } + return true; + } + /*if(args[0].toLowerCase()=="reload") + DoReload(null); //2015.07.20.*/ + else if(args.length>0 && args[0].toLowerCase().equals("admin")) //2015.08.09. + { + DoAdmin(null, args); //2015.08.09. + return true; //2015.08.09. + } + return false; + } + private static void DoReload(Player player) + { //2015.07.20. + //if(player==null || player.isOp() || player.getName()=="NorbiPeti") + //{ + try + { + File file=new File("autoflairconfig.txt"); + if(file.exists()) + { + PluginMain.LoadFiles(true); //2015.08.09. + for(Player p : PluginMain.GetPlayers()) + { + MaybeOfflinePlayer mp = MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName()); + if(mp.Flair!=null) + { + //String flair=mp.Flair; + //PluginMain.RemovePlayerDisplayFlairFinal(p, flair); + //PluginMain.AppendPlayerDisplayFlairFinal(p, flair); + PluginMain.AppendPlayerDisplayFlair(mp, p); //2015.08.09. + } + String msg="§6Note: The auto-flair plugin has been reloaded. You might need to wait 10s to have your flair.§r"; //2015.08.09. + p.sendMessage(msg); //2015.08.09. + } + //String msg="§6Reloaded config file.§r"; + //SendMessage(player, msg); //2015.08.09. + } + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + if(player!=null) + player.sendMessage("§cAn error occured. See console for details.§r"); + PluginMain.LastException=e; //2015.08.09. + } + //} + //else + //player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static Player ReloadPlayer; //2015.08.09. + private static void DoAdmin(Player player, String[] args) + { //2015.08.09. + if(player==null || player.isOp() || player.getName()=="NorbiPeti") + { + //System.out.println("Args length: " + args.length); + if(args.length==1) + { + String message="§cUsage: /u admin reload|playerinfo§r"; + SendMessage(player, message); + return; + } + //args[0] is "admin" + switch(args[1].toLowerCase()) + { + case "reload": + ReloadPlayer=player; //2015.08.09. + SendMessage(player, "§6Make sure to save the current settings before you modify and reload them! Type /u admin confirm when done.§r"); + break; + case "playerinfo": + DoPlayerInfo(player, args); + break; + case "getlasterror": + DoGetLastError(player, args); + case "confirm": + if(ReloadPlayer==player) + DoReload(player); //2015.08.09. + else + SendMessage(player, "§cYou need to do /u admin reload first.§r"); + break; + case "save": + PluginMain.SaveFiles(); //2015.08.09. + SendMessage(player, "§6Saved files. Now you can edit them and reload if you want.§r"); + break; + case "setflair": + DoSetFlair(player, args); + break; + default: + String message="§cUsage: /u admin reload|playerinfo|getlasterror|save|setflair§r"; + SendMessage(player, message); + return; + } + } + else + player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static void DoPlayerInfo(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "playerinfo" + if(args.length==2) + { + String message="§cUsage: /u admin playerinfo §r"; + SendMessage(player, message); + return; + } + if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2])) + { + String message="§cPlayer not found: "+args[2]+"§r"; + SendMessage(player, message); + return; + } + MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]); + SendMessage(player, "Player name: "+p.PlayerName); + SendMessage(player, "User flair: "+p.Flair); + SendMessage(player, "Username: "+p.UserName); + SendMessage(player, "Flair accepted: "+p.AcceptedFlair); + SendMessage(player, "Flair ignored: "+p.IgnoredFlair); + } + private static void SendMessage(Player player, String message) + { //2015.08.09. + if(player==null) + System.out.println(message); + else + player.sendMessage(message); + } + private static void DoGetLastError(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "getlasterror" + if(PluginMain.LastException!=null) + { + SendMessage(player, "Last error:"); + SendMessage(player, PluginMain.LastException.toString()); + PluginMain.LastException=null; + } + else + SendMessage(player, "There were no exceptions."); + } + private static void SetPlayerFlair(Player player, MaybeOfflinePlayer targetplayer, String flair) + { //2015.08.09. + flair=flair.replace('&', '§'); + targetplayer.Flair=flair; + if(!PluginMain.RemoveLineFromFile("customflairs.txt", targetplayer.PlayerName)) + { + SendMessage(player, "§cError removing previous custom flair!§r"); + return; + } + File file=new File("customflairs.txt"); + try { + BufferedWriter bw; + bw = new BufferedWriter(new FileWriter(file, true)); + bw.write(targetplayer.PlayerName+"\n"); + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + PluginMain.LastException=e; //2015.08.09. + } + SendMessage(player, "§6The flair has been set. Player: "+targetplayer.PlayerName+" Flair: "+flair+"§r"); + } + private static void DoSetFlair(Player player, String[] args) + { + //args[0] is "admin" - args[1] is "setflair" + if(args.length<4) + { + SendMessage(player, "§cUsage: /u admin setflair "); + return; + } + SetPlayerFlair(player, MaybeOfflinePlayer.AddPlayerIfNeeded(args[2]), args[3]); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/8b/00d17baede3e001517108d149b613203 b/.metadata/.plugins/org.eclipse.core.resources/.history/8b/00d17baede3e001517108d149b613203 new file mode 100644 index 0000000..fe096bd --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/8b/00d17baede3e001517108d149b613203 @@ -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.WorldCoord; + +public class PluginMain extends JavaPlugin +{ //Translated to Java: 2015.07.15. + //A user, which flair isn't obtainable: + //https://www.reddit.com/r/thebutton/comments/31c32v/i_pressed_the_button_without_really_thinking/ + private static PluginMain Instance; + // Fired when plugin is first enabled + @Override + public void onEnable() + { + System.out.println("The Button Auto-flair Plugin by NorbiPeti (:P)"); + getServer().getPluginManager().registerEvents(new PlayerListener(), this); + this.getCommand("u").setExecutor(new Commands()); + this.getCommand("u").setUsage(this.getCommand("u").getUsage().replace('&', '§')); + Instance=this; //2015.08.08. + LoadFiles(false); //2015.08.09. + Runnable r=new Runnable(){public void run(){ThreadMethod();}}; + Thread t=new Thread(r); + t.start(); + } + Boolean stop=false; + // Fired when plugin is disabled + @Override + public void onDisable() + { + SaveFiles(); //2015.08.09. + stop=true; + } + + public void ThreadMethod() //<-- 2015.07.16. + { + while(!stop) + { + try + { + String body=DownloadString("https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/autoflair_system_comment_your_minecraft_name_and/.json?limit=1000"); + JSONArray json=new JSONArray(body).getJSONObject(1).getJSONObject("data").getJSONArray("children"); + for(Object obj : json) + { + JSONObject item = (JSONObject)obj; + String author=item.getJSONObject("data").getString("author"); + String ign=item.getJSONObject("data").getString("body"); + int start = ign.indexOf("IGN:") + "IGN:".length(); + if(start==-1) + continue; //2015.08.09. + int end = ign.indexOf(' ', start); + if (end == -1 || end == start) + end=ign.indexOf('\n', start); //2015.07.15. + if (end == -1 || end == start) + ign = ign.substring(start); + else + ign = ign.substring(start, end); + ign = ign.trim(); + if(HasIGFlair(ign)) + continue; + try { + Thread.sleep(10); + } catch(InterruptedException ex) { + Thread.currentThread().interrupt(); + } + String[] flairdata = DownloadString("http://karmadecay.com/thebutton-data.php?users=" + author).replace("\"", "").split(":"); + String flair; + if(flairdata.length > 1) //2015.07.15. + flair = flairdata[1]; + else + flair=""; + if (flair != "-1") + flair = flair + "s"; + else + flair = "non-presser"; + String flairclass; + if(flairdata.length>2) + flairclass = flairdata[2]; + else + flairclass="unknown"; + SetFlair(ign, flair, flairclass, author); + } + Thread.sleep(10000); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + } + + public static Exception LastException; //2015.08.09. + + public String DownloadString(String urlstr) throws MalformedURLException, IOException + { + URL url = new URL(urlstr); + URLConnection con = url.openConnection(); + con.setRequestProperty("User-Agent", "TheButtonAutoFlair"); + InputStream in = con.getInputStream(); + String encoding = con.getContentEncoding(); + encoding = encoding == null ? "UTF-8" : encoding; + String body = IOUtils.toString(in, encoding); + in.close(); + return body; + } + + public static Map TownColors=new HashMap(); //2015.07.20. + public Boolean HasIGFlair(String playername) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + return p.Flair!=null; //2015.08.08. + } + + public void SetFlair(String playername, String text, String flairclass, String username) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + String finalflair; + p.FlairDecided=true; + switch(flairclass) + { + case "press-1": + finalflair="§c("+text+")§r"; + break; + case "press-2": + finalflair="§6("+text+")§r"; + break; + case "press-3": + finalflair="§e("+text+")§r"; + break; + case "press-4": + finalflair="§a("+text+")§r"; + break; + case "press-5": + finalflair="§9("+text+")§r"; + break; + 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; + case "undecided": //2015.08.09. + p.FlairDecided=false; + finalflair=""; + break; + default: + finalflair=""; + break; + } + if(finalflair.length()==0) //<-- 2015.07.20. + return; + p.Flair=finalflair; //2015.08.08. + p.UserName=username; //2015.08.08. + System.out.println("Added new flair to "+playername+": "+finalflair); + for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08. + { + if(player.getName().equals(playername)) + { + //AppendPlayerDisplayFlair(player, username, finalflair); + AppendPlayerDisplayFlair(p, player); + break; + } + } + } + + public static String GetFlair(Player player) + { //2015.07.16. + String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08. + return flair==null ? "" : flair; + } + + //public static void AppendPlayerDisplayFlair(Player player, String username, String flair) + public static void AppendPlayerDisplayFlair(MaybeOfflinePlayer player, Player p) //<-- 2015.08.09. + { + + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).IgnoredFlair) + return; + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).AcceptedFlair) + { + AppendPlayerDisplayFlairFinal(p, player.Flair); //2015.07.20. + if(!player.FlairDecided) + p.sendMessage("§9Your flair type is unknown. Are you a non-presser or a can't press? (/u nonpresser or /u cantpress)§r"); //2015.08.09. + } + else + p.sendMessage("§9Are you Reddit user "+player.UserName+"?§r §6Type /u accept or /u ignore§r"); + } + + private static void AppendPlayerDisplayFlairFinal(Player player, String flair) + { //2015.07.20. + String color = GetColorForTown(GetPlayerTown(player)); //TO!DO: Multiple colors put on first capital letters + String[] colors = color.substring(1).split("§"); + String displayname=player.getName(); //2015.08.08. + ArrayList Positions=new ArrayList<>(); + for(int i=0; i=colors.length) + { + int x=0; + for(int i=0; i GetPlayers() + { + return Instance.getServer().getOnlinePlayers(); + } + + public static void LoadFiles(boolean reload) //<-- 2015.08.09. + { + if(reload) + { //2015.08.09. + System.out.println("Auto-flair plugin cleanup for reloading..."); + MaybeOfflinePlayer.AllPlayers.clear(); + TownColors.clear(); + } + System.out.println("Loading files for auto-flair plugin..."); //2015.08.09. + try { + File file=new File("flairsaccepted.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + //System.out.println("Name: " + name); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("flairsignored.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsignored.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("autoflairconfig.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + TownColors.put(s[0], s[1]); + } + br.close(); + } + file=new File("customflairs.txt"); //2015.08.09. + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + MaybeOfflinePlayer.AddPlayerIfNeeded(s[0]).Flair=s[1]; //2015.08.09. + } + br.close(); + } + //throw new IOException("Test"); //2015.08.09. + System.out.println("Auto-flair plugin loaded files!"); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + public static void SaveFiles() //<-- 2015.08.09. + { + try + { + FileWriter fw; + fw = new FileWriter("flairsaccepted.txt"); + fw.close(); + fw = new FileWriter("flairsignored.txt"); + fw.close(); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + try { + File file=new File("flairsaccepted.txt"); + BufferedWriter bw=new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.AcceptedFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + file=new File("flairsignored.txt"); + bw = new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.IgnoredFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + public static void SetPlayerFlair(Player player, String flair) + { //2015.08.09. + flair=flair.replace('&', '§'); + MaybeOfflinePlayer.AddPlayerIfNeeded(player.getName()).Flair=flair; + File file=new File("customflairs.txt"); + try { + BufferedWriter bw; + bw = new BufferedWriter(new FileWriter(file, true)); + bw.write(player.getName()+"\n"); + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + public static bool RemoveLineFromFile(String file) + { + File inputFile = new File(file); + File tempFile = new File("_temp.txt"); + + try { + BufferedReader reader = new BufferedReader(new FileReader(inputFile)); + BufferedWriter writer = new BufferedWriter(new FileWriter(tempFile)); + + String lineToRemove = "bbb"; + String currentLine; + + while((currentLine = reader.readLine()) != null) { + // trim newline when comparing with lineToRemove + String trimmedLine = currentLine.trim(); + if(trimmedLine.equals(lineToRemove)) continue; + writer.write(currentLine + System.getProperty("line.separator")); + } + writer.close(); + reader.close(); + tempFile.renameTo(inputFile); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/8c/60d47714883e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/8c/60d47714883e00151ce8ff6d4f74dabd deleted file mode 100644 index 31f7f4b..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/8c/60d47714883e00151ce8ff6d4f74dabd +++ /dev/null @@ -1,162 +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; - MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. - //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - if(p.Flair==null) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. - { - case "accept": - { - if(p.IgnoredFlair) - p.IgnoredFlair=false; //2015.08.08. - if(!p.AcceptedFlair) - { - String flair=p.Flair; //2015.08.08. - PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. - p.AcceptedFlair=true; //2015.08.08. - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("§cYou already have this user's flair.§r"); - break; - } - case "ignore": - { - if(p.AcceptedFlair) - p.AcceptedFlair=false; //2015.08.08. - if(!p.IgnoredFlair) - { - p.IgnoredFlair=true; - String flair=p.Flair; //2015.08.08. - PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. - player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); - } - else - player.sendMessage("§cYou already ignored this request.§r"); - break; - } - /*case "reload": //2015.07.20. - DoReload(player); - break;*/ - case "admin": //2015.08.09. - DoAdmin(player, args); - break; - default: - return false; - } - return true; - } - - /*if(args[0].toLowerCase()=="reload") - DoReload(null); //2015.07.20.*/ - else if(args[0].toLowerCase()=="admin") - DoAdmin(null, args); //2015.08.09. - return false; - } - private static void DoReload(Player player) - { //2015.07.20. - //if(player==null || player.isOp() || player.getName()=="NorbiPeti") - //{ - try - { - File file=new File("autoflairconfig.txt"); - if(file.exists()) - { - PluginMain.TownColors.clear(); - BufferedReader br=new BufferedReader(new FileReader(file)); - String line; - while((line=br.readLine())!=null) - { - String[] s=line.split(" "); - PluginMain.TownColors.put(s[0], s[1]); - } - br.close(); - for(Player p : PluginMain.GetPlayers()) - { - MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName()); - if(mp.Flair!=null) - { - String flair=mp.Flair; - PluginMain.RemovePlayerDisplayFlairFinal(p, flair); - PluginMain.AppendPlayerDisplayFlairFinal(p, flair); - } - } - String msg="§6Reloaded config file.§r"; - if(player!=null) - player.sendMessage(msg); - else - System.out.println(msg); - } - } - catch(Exception e) - { - System.out.println("Error!\n"+e); - if(player!=null) - player.sendMessage("§cAn error occured. See console for details.§r"); - } - //} - //else - //player.sendMessage("§cYou need to be OP to use this command.§r"); - } - private static void DoAdmin(Player player, String[] args) - { //2015.08.09. - if(player==null || player.isOp() || player.getName()=="NorbiPeti") - { - if(args.length==1) - { - String message="§cUsage: /u admin reload|playerinfo§r"; - if(player==null) - System.out.println(message); - else - player.sendMessage(message); - return; - } - //args[0] is "admin" - switch(args[1].toLowerCase()) - { - case "reload": - DoReload(player); - break; - case "playerinfo": - DoPlayerInfo(player, args); - break; - } - } - else - player.sendMessage("§cYou need to be OP to use this command.§r"); - } - private static void DoPlayerInfo(Player player, String[] args) - { //2015.08.09. - //args[0] is "admin" - args[1] is "playerinfo" - if(args.length==2) - { - String message="§cUsage: /u admin playerinfo §r"; - if(player==null) - System.out.println(message); - else - player.sendMessage(message); - return; - } - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/8c/a0ea662dcf3e001518fa86d7ae2a1cf8 b/.metadata/.plugins/org.eclipse.core.resources/.history/8c/a0ea662dcf3e001518fa86d7ae2a1cf8 new file mode 100644 index 0000000..1213563 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/8c/a0ea662dcf3e001518fa86d7ae2a1cf8 @@ -0,0 +1,362 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStream; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLConnection; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + +import org.apache.commons.io.IOUtils; +import org.bukkit.entity.Player; +import org.bukkit.plugin.java.JavaPlugin; +import org.json.JSONArray; +import org.json.JSONObject; + +import tk.sznp.thebuttonautoflair.MaybeOfflinePlayer.FlairClassType; + +import com.palmergames.bukkit.towny.object.Town; +import com.palmergames.bukkit.towny.object.WorldCoord; + +public class PluginMain extends JavaPlugin +{ //Translated to Java: 2015.07.15. + //A user, which flair isn't obtainable: + //https://www.reddit.com/r/thebutton/comments/31c32v/i_pressed_the_button_without_really_thinking/ + private static PluginMain Instance; + // Fired when plugin is first enabled + @Override + public void onEnable() + { + System.out.println("The Button Auto-flair Plugin by NorbiPeti (:P)"); + getServer().getPluginManager().registerEvents(new PlayerListener(), this); + this.getCommand("u").setExecutor(new Commands()); + this.getCommand("u").setUsage(this.getCommand("u").getUsage().replace('&', '§')); + Instance=this; //2015.08.08. + try { + File file=new File("flairsaccepted.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + //System.out.println("Name: " + name); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("flairsignored.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsignored.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("autoflairconfig.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + TownColors.put(s[0], s[1]); + } + br.close(); + } + //throw new IOException("Test"); //2015.08.09. + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + Runnable r=new Runnable(){public void run(){ThreadMethod();}}; + Thread t=new Thread(r); + t.start(); + } + Boolean stop=false; + // Fired when plugin is disabled + @Override + public void onDisable() + { + try + { + FileWriter fw; + fw = new FileWriter("flairsaccepted.txt"); + fw.close(); + fw = new FileWriter("flairsignored.txt"); + fw.close(); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + try { + File file=new File("flairsaccepted.txt"); + BufferedWriter bw=new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.AcceptedFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + file=new File("flairsignored.txt"); + bw = new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.IgnoredFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + stop=true; + } + + public void ThreadMethod() //<-- 2015.07.16. + { + while(!stop) + { + try + { + String body=DownloadString("https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/autoflair_system_comment_your_minecraft_name_and/.json?limit=1000"); + JSONArray json=new JSONArray(body).getJSONObject(1).getJSONObject("data").getJSONArray("children"); + for(Object obj : json) + { + JSONObject item = (JSONObject)obj; + String author=item.getJSONObject("data").getString("author"); + String ign=item.getJSONObject("data").getString("body"); + int start = ign.indexOf("IGN:") + "IGN:".length(); + int end = ign.indexOf(' ', start); + if (end == -1 || end == start) + end=ign.indexOf('\n', start); //2015.07.15. + if (end == -1 || end == start) + ign = ign.substring(start); + else + ign = ign.substring(start, end); + ign = ign.trim(); + if(HasIGFlair(ign)) + continue; + try { + Thread.sleep(10); + } catch(InterruptedException ex) { + Thread.currentThread().interrupt(); + } + String[] flairdata = DownloadString("http://karmadecay.com/thebutton-data.php?users=" + author).replace("\"", "").split(":"); + String flair; + if(flairdata.length > 1) //2015.07.15. + flair = flairdata[1]; + else + flair=""; + if (flair != "-1") + flair = flair + "s"; + else + flair = "non-presser"; + String flairclass; + if(flairdata.length>2) + flairclass = flairdata[2]; + else + flairclass="unknown"; + SetFlair(ign, flair, flairclass, author); + } + Thread.sleep(10000); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + } + + public static Exception LastException; //2015.08.09. + + public String DownloadString(String urlstr) throws MalformedURLException, IOException + { + URL url = new URL(urlstr); + URLConnection con = url.openConnection(); + con.setRequestProperty("User-Agent", "TheButtonAutoFlair"); + InputStream in = con.getInputStream(); + String encoding = con.getContentEncoding(); + encoding = encoding == null ? "UTF-8" : encoding; + String body = IOUtils.toString(in, encoding); + in.close(); + return body; + } + + public static Map TownColors=new HashMap(); //2015.07.20. + public Boolean HasIGFlair(String playername) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + return p.Flair!=null; //2015.08.08. + } + + public void SetFlair(String playername, String text, String flairclass, String username) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + String finalflair; + p.FlairDecided=true; + switch(flairclass) + { + case "press-1": + finalflair="§c("+text+")§r"; + break; + case "press-2": + finalflair="§6("+text+")§r"; + break; + case "press-3": + finalflair="§e("+text+")§r"; + break; + case "press-4": + finalflair="§a("+text+")§r"; + break; + case "press-5": + finalflair="§9("+text+")§r"; + break; + 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; + case "undecided": //2015.08.09. + p.FlairDecided=false; + finalflair=""; + break; + default: + finalflair=""; + break; + } + if(finalflair.length()==0) //<-- 2015.07.20. + return; + p.Flair=finalflair; //2015.08.08. + p.UserName=username; //2015.08.08. + System.out.println("Added new flair to "+playername+": "+finalflair); + for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08. + { + if(player.getName().equals(playername)) + { + AppendPlayerDisplayFlair(player, username, finalflair); + break; + } + } + } + + public static String GetFlair(Player player) + { //2015.07.16. + String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08. + return flair==null ? "" : flair; + } + + //public static void AppendPlayerDisplayFlair(Player player, String username, String flair) + public static void AppendPlayerDisplayFlair(MaybeOfflinePlayer player, Player p) + { + + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).IgnoredFlair) + return; + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).AcceptedFlair) + { + AppendPlayerDisplayFlairFinal(p, player.Flair); //2015.07.20. + } + else + player.sendMessage("§9Are you Reddit user "+username+"?§r §6Type /u accept or /u ignore§r"); + } + + private static void AppendPlayerDisplayFlairFinal(Player player, String flair) + { //2015.07.20. + String color = GetColorForTown(GetPlayerTown(player)); //TO!DO: Multiple colors put on first capital letters + String[] colors = color.substring(1).split("§"); + String displayname=player.getName(); //2015.08.08. + ArrayList Positions=new ArrayList<>(); + for(int i=0; i=colors.length) + { + int x=0; + for(int i=0; i GetPlayers() + { + return Instance.getServer().getOnlinePlayers(); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/8c/d09f3274873e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/8c/d09f3274873e00151ce8ff6d4f74dabd deleted file mode 100644 index 1e3d1d3..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/8c/d09f3274873e00151ce8ff6d4f74dabd +++ /dev/null @@ -1,145 +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; - MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. - //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - if(p.Flair==null) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. - { - case "accept": - { - if(p.IgnoredFlair) - p.IgnoredFlair=false; //2015.08.08. - if(!p.AcceptedFlair) - { - String flair=p.Flair; //2015.08.08. - PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. - p.AcceptedFlair=true; //2015.08.08. - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("§cYou already have this user's flair.§r"); - break; - } - case "ignore": - { - if(p.AcceptedFlair) - p.AcceptedFlair=false; //2015.08.08. - if(!p.IgnoredFlair) - { - p.IgnoredFlair=true; - String flair=p.Flair; //2015.08.08. - PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. - player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); - } - else - player.sendMessage("§cYou already ignored this request.§r"); - break; - } - /*case "reload": //2015.07.20. - DoReload(player); - break;*/ - case "admin": //2015.08.09. - DoAdmin(player, args); - break; - default: - return false; - } - return true; - } - - /*if(args[0].toLowerCase()=="reload") - DoReload(null); //2015.07.20.*/ - else if(args[0].toLowerCase()=="admin") - DoAdmin(null, args); //2015.08.09. - return false; - } - private static void DoReload(Player player) - { //2015.07.20. - //if(player==null || player.isOp() || player.getName()=="NorbiPeti") - //{ - try - { - File file=new File("autoflairconfig.txt"); - if(file.exists()) - { - PluginMain.TownColors.clear(); - BufferedReader br=new BufferedReader(new FileReader(file)); - String line; - while((line=br.readLine())!=null) - { - String[] s=line.split(" "); - PluginMain.TownColors.put(s[0], s[1]); - } - br.close(); - for(Player p : PluginMain.GetPlayers()) - { - MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName()); - if(mp.Flair!=null) - { - String flair=mp.Flair; - PluginMain.RemovePlayerDisplayFlairFinal(p, flair); - PluginMain.AppendPlayerDisplayFlairFinal(p, flair); - } - } - String msg="§6Reloaded config file.§r"; - if(player!=null) - player.sendMessage(msg); - else - System.out.println(msg); - } - } - catch(Exception e) - { - System.out.println("Error!\n"+e); - if(player!=null) - player.sendMessage("§cAn error occured. See console for details.§r"); - } - //} - //else - //player.sendMessage("§cYou need to be OP to use this command.§r"); - } - private static void DoAdmin(Player player, String[] args) - { - if(player==null || player.isOp() || player.getName()=="NorbiPeti") - { - //args[0] is "admin" - switch(args[1].toLowerCase()) - { - case "reload": - DoReload(player); - break; - case "playerinfo": - DoPlayerInfo(player, args); - break; - } - } - else - player.sendMessage("§cYou need to be OP to use this command.§r"); - } - private static void DoPlayerInfo(Player player, String[] args) - { - //args[0] is "admin" - args[1] is "playerinfo" - - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/8d/00c5f1e2e03e001517108d149b613203 b/.metadata/.plugins/org.eclipse.core.resources/.history/8d/00c5f1e2e03e001517108d149b613203 new file mode 100644 index 0000000..897aaab --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/8d/00c5f1e2e03e001517108d149b613203 @@ -0,0 +1,265 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +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; + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. + //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) + if(p.Flair==null) + { + player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); + return true; + } + switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. + { + case "accept": + { + if(p.IgnoredFlair) + p.IgnoredFlair=false; //2015.08.08. + if(!p.AcceptedFlair) + { + String flair=p.Flair; //2015.08.08. + //PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + PluginMain.AppendPlayerDisplayFlair(p, player); + p.AcceptedFlair=true; //2015.08.08. + player.sendMessage("§6Your flair has been set:§r "+flair); + } + else + player.sendMessage("§cYou already have this user's flair.§r"); + break; + } + case "ignore": + { + if(p.AcceptedFlair) + p.AcceptedFlair=false; //2015.08.08. + if(!p.IgnoredFlair) + { + p.IgnoredFlair=true; + String flair=p.Flair; //2015.08.08. + PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. + player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); + } + else + player.sendMessage("§cYou already ignored this request.§r"); + break; + } + /*case "reload": //2015.07.20. + DoReload(player); + break;*/ + case "admin": //2015.08.09. + DoAdmin(player, args); + break; + case "nonpresser": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§7(non-pr.)§r"; + break; + case "cantpress": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§r(can't press)§r"; + break; + default: + return false; + } + return true; + } + /*if(args[0].toLowerCase()=="reload") + DoReload(null); //2015.07.20.*/ + else if(args.length>0 && args[0].toLowerCase().equals("admin")) //2015.08.09. + { + DoAdmin(null, args); //2015.08.09. + return true; //2015.08.09. + } + return false; + } + private static void DoReload(Player player) + { //2015.07.20. + //if(player==null || player.isOp() || player.getName()=="NorbiPeti") + //{ + try + { + File file=new File("autoflairconfig.txt"); + if(file.exists()) + { + PluginMain.LoadFiles(true); //2015.08.09. + for(Player p : PluginMain.GetPlayers()) + { + MaybeOfflinePlayer mp = MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName()); + if(mp.Flair!=null) + { + String flair=mp.Flair; + PluginMain.RemovePlayerDisplayFlairFinal(p, flair); + //PluginMain.AppendPlayerDisplayFlairFinal(p, flair); + PluginMain.AppendPlayerDisplayFlair(mp, p); //2015.08.09. + } + String msg="§6Note: The auto-flair plugin has been reloaded. You might need to wait 10s to have your flair.§r"; //2015.08.09. + p.sendMessage(msg); //2015.08.09. + } + //String msg="§6Reloaded config file.§r"; + //SendMessage(player, msg); //2015.08.09. + } + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + if(player!=null) + player.sendMessage("§cAn error occured. See console for details.§r"); + PluginMain.LastException=e; //2015.08.09. + } + //} + //else + //player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static Player ReloadPlayer; //2015.08.09. + private static void DoAdmin(Player player, String[] args) + { //2015.08.09. + if(player==null || player.isOp() || player.getName()=="NorbiPeti") + { + //System.out.println("Args length: " + args.length); + if(args.length==1) + { + String message="§cUsage: /u admin reload|playerinfo§r"; + SendMessage(player, message); + return; + } + //args[0] is "admin" + switch(args[1].toLowerCase()) + { + case "reload": + ReloadPlayer=player; //2015.08.09. + SendMessage(player, "§6Make sure to save the current settings before you modify and reload them! Type /u admin confirm when done.§r"); + break; + case "playerinfo": + DoPlayerInfo(player, args); + break; + case "getlasterror": + DoGetLastError(player, args); + case "confirm": + if(ReloadPlayer==player) + DoReload(player); //2015.08.09. + else + SendMessage(player, "§cYou need to do /u admin reload first.§r"); + break; + case "save": + PluginMain.SaveFiles(); //2015.08.09. + SendMessage(player, "§6Saved files. Now you can edit them and reload if you want.§r"); + break; + case "setflair": + + break; + default: + String message="§cUsage: /u admin reload|playerinfo|getlasterror|save§r"; + SendMessage(player, message); + return; + } + } + else + player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static void DoPlayerInfo(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "playerinfo" + if(args.length==2) + { + String message="§cUsage: /u admin playerinfo §r"; + SendMessage(player, message); + return; + } + if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2])) + { + String message="§cPlayer not found: "+args[2]+"§r"; + SendMessage(player, message); + return; + } + MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]); + SendMessage(player, "Player name: "+p.PlayerName); + SendMessage(player, "User flair: "+p.Flair); + SendMessage(player, "Username: "+p.UserName); + SendMessage(player, "Flair accepted: "+p.AcceptedFlair); + SendMessage(player, "Flair ignored: "+p.IgnoredFlair); + } + private static void SendMessage(Player player, String message) + { //2015.08.09. + if(player==null) + System.out.println(message); + else + player.sendMessage(message); + } + private static void DoGetLastError(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "getlasterror" + if(PluginMain.LastException!=null) + { + SendMessage(player, "Last error:"); + SendMessage(player, PluginMain.LastException.toString()); + PluginMain.LastException=null; + } + else + SendMessage(player, "There were no exceptions."); + } + private static void SetPlayerFlair(Player player, MaybeOfflinePlayer targetplayer, String flair) + { //2015.08.09. + flair=flair.replace('&', '§'); + targetplayer.Flair=flair; + if(!PluginMain.RemoveLineFromFile("customflairs.txt", targetplayer.getName())) + { + SendMessage(player, "§cError removing previous custom flair!§r"); + return; + } + File file=new File("customflairs.txt"); + try { + BufferedWriter bw; + bw = new BufferedWriter(new FileWriter(file, true)); + bw.write(targetplayer.getName()+"\n"); + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + PluginMain.LastException=e; //2015.08.09. + } + SendMessage(player, "§6The flair has been set. Player: "+targetplayer.getName()+" Flair: "+flair+"§r"); + } + private static void DoSetFlair(Player player, String args) + { + //args[0] is "admin" - args[1] is "setflair" + if(args.length()<4) + { + SendMessage(player, "§cUsage: /u admin setflair "); + return; + } + SetPlayerFlair(player, MaybeOfflinePlayer.AddPlayerIfNeeded(player.getName())) + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/8d/20aae3d4de3e001517108d149b613203 b/.metadata/.plugins/org.eclipse.core.resources/.history/8d/20aae3d4de3e001517108d149b613203 new file mode 100644 index 0000000..4d9e4b8 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/8d/20aae3d4de3e001517108d149b613203 @@ -0,0 +1,440 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStream; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLConnection; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + +import org.apache.commons.io.IOUtils; +import org.bukkit.entity.Player; +import org.bukkit.plugin.java.JavaPlugin; +import org.json.JSONArray; +import org.json.JSONObject; + +import com.palmergames.bukkit.towny.object.Town; +import com.palmergames.bukkit.towny.object.WorldCoord; + +public class PluginMain extends JavaPlugin +{ //Translated to Java: 2015.07.15. + //A user, which flair isn't obtainable: + //https://www.reddit.com/r/thebutton/comments/31c32v/i_pressed_the_button_without_really_thinking/ + private static PluginMain Instance; + // Fired when plugin is first enabled + @Override + public void onEnable() + { + System.out.println("The Button Auto-flair Plugin by NorbiPeti (:P)"); + getServer().getPluginManager().registerEvents(new PlayerListener(), this); + this.getCommand("u").setExecutor(new Commands()); + this.getCommand("u").setUsage(this.getCommand("u").getUsage().replace('&', '§')); + Instance=this; //2015.08.08. + LoadFiles(false); //2015.08.09. + Runnable r=new Runnable(){public void run(){ThreadMethod();}}; + Thread t=new Thread(r); + t.start(); + } + Boolean stop=false; + // Fired when plugin is disabled + @Override + public void onDisable() + { + SaveFiles(); //2015.08.09. + stop=true; + } + + public void ThreadMethod() //<-- 2015.07.16. + { + while(!stop) + { + try + { + String body=DownloadString("https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/autoflair_system_comment_your_minecraft_name_and/.json?limit=1000"); + JSONArray json=new JSONArray(body).getJSONObject(1).getJSONObject("data").getJSONArray("children"); + for(Object obj : json) + { + JSONObject item = (JSONObject)obj; + String author=item.getJSONObject("data").getString("author"); + String ign=item.getJSONObject("data").getString("body"); + int start = ign.indexOf("IGN:") + "IGN:".length(); + if(start==-1) + continue; //2015.08.09. + int end = ign.indexOf(' ', start); + if (end == -1 || end == start) + end=ign.indexOf('\n', start); //2015.07.15. + if (end == -1 || end == start) + ign = ign.substring(start); + else + ign = ign.substring(start, end); + ign = ign.trim(); + if(HasIGFlair(ign)) + continue; + try { + Thread.sleep(10); + } catch(InterruptedException ex) { + Thread.currentThread().interrupt(); + } + String[] flairdata = DownloadString("http://karmadecay.com/thebutton-data.php?users=" + author).replace("\"", "").split(":"); + String flair; + if(flairdata.length > 1) //2015.07.15. + flair = flairdata[1]; + else + flair=""; + if (flair != "-1") + flair = flair + "s"; + else + flair = "non-presser"; + String flairclass; + if(flairdata.length>2) + flairclass = flairdata[2]; + else + flairclass="unknown"; + SetFlair(ign, flair, flairclass, author); + } + Thread.sleep(10000); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + } + + public static Exception LastException; //2015.08.09. + + public String DownloadString(String urlstr) throws MalformedURLException, IOException + { + URL url = new URL(urlstr); + URLConnection con = url.openConnection(); + con.setRequestProperty("User-Agent", "TheButtonAutoFlair"); + InputStream in = con.getInputStream(); + String encoding = con.getContentEncoding(); + encoding = encoding == null ? "UTF-8" : encoding; + String body = IOUtils.toString(in, encoding); + in.close(); + return body; + } + + public static Map TownColors=new HashMap(); //2015.07.20. + public Boolean HasIGFlair(String playername) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + return p.Flair!=null; //2015.08.08. + } + + public void SetFlair(String playername, String text, String flairclass, String username) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + String finalflair; + p.FlairDecided=true; + switch(flairclass) + { + case "press-1": + finalflair="§c("+text+")§r"; + break; + case "press-2": + finalflair="§6("+text+")§r"; + break; + case "press-3": + finalflair="§e("+text+")§r"; + break; + case "press-4": + finalflair="§a("+text+")§r"; + break; + case "press-5": + finalflair="§9("+text+")§r"; + break; + 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; + case "undecided": //2015.08.09. + p.FlairDecided=false; + finalflair=""; + break; + default: + finalflair=""; + break; + } + if(finalflair.length()==0) //<-- 2015.07.20. + return; + p.Flair=finalflair; //2015.08.08. + p.UserName=username; //2015.08.08. + System.out.println("Added new flair to "+playername+": "+finalflair); + for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08. + { + if(player.getName().equals(playername)) + { + //AppendPlayerDisplayFlair(player, username, finalflair); + AppendPlayerDisplayFlair(p, player); + break; + } + } + } + + public static String GetFlair(Player player) + { //2015.07.16. + String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08. + return flair==null ? "" : flair; + } + + //public static void AppendPlayerDisplayFlair(Player player, String username, String flair) + public static void AppendPlayerDisplayFlair(MaybeOfflinePlayer player, Player p) //<-- 2015.08.09. + { + + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).IgnoredFlair) + return; + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).AcceptedFlair) + { + AppendPlayerDisplayFlairFinal(p, player.Flair); //2015.07.20. + if(!player.FlairDecided) + p.sendMessage("§9Your flair type is unknown. Are you a non-presser or a can't press? (/u nonpresser or /u cantpress)§r"); //2015.08.09. + } + else + p.sendMessage("§9Are you Reddit user "+player.UserName+"?§r §6Type /u accept or /u ignore§r"); + } + + private static void AppendPlayerDisplayFlairFinal(Player player, String flair) + { //2015.07.20. + String color = GetColorForTown(GetPlayerTown(player)); //TO!DO: Multiple colors put on first capital letters + String[] colors = color.substring(1).split("§"); + String displayname=player.getName(); //2015.08.08. + ArrayList Positions=new ArrayList<>(); + for(int i=0; i=colors.length) + { + int x=0; + for(int i=0; i GetPlayers() + { + return Instance.getServer().getOnlinePlayers(); + } + + public static void LoadFiles(boolean reload) //<-- 2015.08.09. + { + if(reload) + { //2015.08.09. + System.out.println("Auto-flair plugin cleanup for reloading..."); + MaybeOfflinePlayer.AllPlayers.clear(); + TownColors.clear(); + } + System.out.println("Loading files for auto-flair plugin..."); //2015.08.09. + try { + File file=new File("flairsaccepted.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + //System.out.println("Name: " + name); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("flairsignored.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsignored.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("autoflairconfig.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + TownColors.put(s[0], s[1]); + } + br.close(); + } + file=new File("customflairs.txt"); //2015.08.09. + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + MaybeOfflinePlayer.AddPlayerIfNeeded(s[0]).Flair=s[1]; //2015.08.09. + } + br.close(); + } + //throw new IOException("Test"); //2015.08.09. + System.out.println("Auto-flair plugin loaded files!"); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + public static void SaveFiles() //<-- 2015.08.09. + { + try + { + FileWriter fw; + fw = new FileWriter("flairsaccepted.txt"); + fw.close(); + fw = new FileWriter("flairsignored.txt"); + fw.close(); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + try { + File file=new File("flairsaccepted.txt"); + BufferedWriter bw=new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.AcceptedFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + file=new File("flairsignored.txt"); + bw = new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.IgnoredFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + public static void SetPlayerFlair(Player player, String flair) + { //2015.08.09. + flair=flair.replace('&', '§'); + MaybeOfflinePlayer.AddPlayerIfNeeded(player.getName()).Flair=flair; + if(!RemoveLineFromFile("customflairs.txt")) + { + + } + File file=new File("customflairs.txt"); + try { + BufferedWriter bw; + bw = new BufferedWriter(new FileWriter(file, true)); + bw.write(player.getName()+"\n"); + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + public static boolean RemoveLineFromFile(String file) + { + File inputFile = new File(file); + File tempFile = new File("_temp.txt"); + + try { + BufferedReader reader = new BufferedReader(new FileReader(inputFile)); + BufferedWriter writer = new BufferedWriter(new FileWriter(tempFile)); + + String lineToRemove = "bbb"; + String currentLine; + + while((currentLine = reader.readLine()) != null) { + // trim newline when comparing with lineToRemove + String trimmedLine = currentLine.trim(); + if(trimmedLine.equals(lineToRemove)) continue; + writer.write(currentLine + System.getProperty("line.separator")); + } + writer.close(); + reader.close(); + return tempFile.renameTo(inputFile); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + return false; + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/8d/8048b1b4dd3e001517108d149b613203 b/.metadata/.plugins/org.eclipse.core.resources/.history/8d/8048b1b4dd3e001517108d149b613203 new file mode 100644 index 0000000..8e05cb9 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/8d/8048b1b4dd3e001517108d149b613203 @@ -0,0 +1,403 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStream; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLConnection; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + +import org.apache.commons.io.IOUtils; +import org.bukkit.entity.Player; +import org.bukkit.plugin.java.JavaPlugin; +import org.json.JSONArray; +import org.json.JSONObject; + +import com.palmergames.bukkit.towny.object.Town; +import com.palmergames.bukkit.towny.object.WorldCoord; + +public class PluginMain extends JavaPlugin +{ //Translated to Java: 2015.07.15. + //A user, which flair isn't obtainable: + //https://www.reddit.com/r/thebutton/comments/31c32v/i_pressed_the_button_without_really_thinking/ + private static PluginMain Instance; + // Fired when plugin is first enabled + @Override + public void onEnable() + { + System.out.println("The Button Auto-flair Plugin by NorbiPeti (:P)"); + getServer().getPluginManager().registerEvents(new PlayerListener(), this); + this.getCommand("u").setExecutor(new Commands()); + this.getCommand("u").setUsage(this.getCommand("u").getUsage().replace('&', '§')); + Instance=this; //2015.08.08. + LoadFiles(false); //2015.08.09. + Runnable r=new Runnable(){public void run(){ThreadMethod();}}; + Thread t=new Thread(r); + t.start(); + } + Boolean stop=false; + // Fired when plugin is disabled + @Override + public void onDisable() + { + SaveFiles(); //2015.08.09. + stop=true; + } + + public void ThreadMethod() //<-- 2015.07.16. + { + while(!stop) + { + try + { + String body=DownloadString("https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/autoflair_system_comment_your_minecraft_name_and/.json?limit=1000"); + JSONArray json=new JSONArray(body).getJSONObject(1).getJSONObject("data").getJSONArray("children"); + for(Object obj : json) + { + JSONObject item = (JSONObject)obj; + String author=item.getJSONObject("data").getString("author"); + String ign=item.getJSONObject("data").getString("body"); + int start = ign.indexOf("IGN:") + "IGN:".length(); + if(start==-1) + continue; //2015.08.09. + int end = ign.indexOf(' ', start); + if (end == -1 || end == start) + end=ign.indexOf('\n', start); //2015.07.15. + if (end == -1 || end == start) + ign = ign.substring(start); + else + ign = ign.substring(start, end); + ign = ign.trim(); + if(HasIGFlair(ign)) + continue; + try { + Thread.sleep(10); + } catch(InterruptedException ex) { + Thread.currentThread().interrupt(); + } + String[] flairdata = DownloadString("http://karmadecay.com/thebutton-data.php?users=" + author).replace("\"", "").split(":"); + String flair; + if(flairdata.length > 1) //2015.07.15. + flair = flairdata[1]; + else + flair=""; + if (flair != "-1") + flair = flair + "s"; + else + flair = "non-presser"; + String flairclass; + if(flairdata.length>2) + flairclass = flairdata[2]; + else + flairclass="unknown"; + SetFlair(ign, flair, flairclass, author); + } + Thread.sleep(10000); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + } + + public static Exception LastException; //2015.08.09. + + public String DownloadString(String urlstr) throws MalformedURLException, IOException + { + URL url = new URL(urlstr); + URLConnection con = url.openConnection(); + con.setRequestProperty("User-Agent", "TheButtonAutoFlair"); + InputStream in = con.getInputStream(); + String encoding = con.getContentEncoding(); + encoding = encoding == null ? "UTF-8" : encoding; + String body = IOUtils.toString(in, encoding); + in.close(); + return body; + } + + public static Map TownColors=new HashMap(); //2015.07.20. + public Boolean HasIGFlair(String playername) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + return p.Flair!=null; //2015.08.08. + } + + public void SetFlair(String playername, String text, String flairclass, String username) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + String finalflair; + p.FlairDecided=true; + switch(flairclass) + { + case "press-1": + finalflair="§c("+text+")§r"; + break; + case "press-2": + finalflair="§6("+text+")§r"; + break; + case "press-3": + finalflair="§e("+text+")§r"; + break; + case "press-4": + finalflair="§a("+text+")§r"; + break; + case "press-5": + finalflair="§9("+text+")§r"; + break; + 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; + case "undecided": //2015.08.09. + p.FlairDecided=false; + finalflair=""; + break; + default: + finalflair=""; + break; + } + if(finalflair.length()==0) //<-- 2015.07.20. + return; + p.Flair=finalflair; //2015.08.08. + p.UserName=username; //2015.08.08. + System.out.println("Added new flair to "+playername+": "+finalflair); + for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08. + { + if(player.getName().equals(playername)) + { + //AppendPlayerDisplayFlair(player, username, finalflair); + AppendPlayerDisplayFlair(p, player); + break; + } + } + } + + public static String GetFlair(Player player) + { //2015.07.16. + String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08. + return flair==null ? "" : flair; + } + + //public static void AppendPlayerDisplayFlair(Player player, String username, String flair) + public static void AppendPlayerDisplayFlair(MaybeOfflinePlayer player, Player p) //<-- 2015.08.09. + { + + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).IgnoredFlair) + return; + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).AcceptedFlair) + { + AppendPlayerDisplayFlairFinal(p, player.Flair); //2015.07.20. + if(!player.FlairDecided) + p.sendMessage("§9Your flair type is unknown. Are you a non-presser or a can't press? (/u nonpresser or /u cantpress)§r"); //2015.08.09. + } + else + p.sendMessage("§9Are you Reddit user "+player.UserName+"?§r §6Type /u accept or /u ignore§r"); + } + + private static void AppendPlayerDisplayFlairFinal(Player player, String flair) + { //2015.07.20. + String color = GetColorForTown(GetPlayerTown(player)); //TO!DO: Multiple colors put on first capital letters + String[] colors = color.substring(1).split("§"); + String displayname=player.getName(); //2015.08.08. + ArrayList Positions=new ArrayList<>(); + for(int i=0; i=colors.length) + { + int x=0; + for(int i=0; i GetPlayers() + { + return Instance.getServer().getOnlinePlayers(); + } + + public static void LoadFiles(boolean reload) //<-- 2015.08.09. + { + if(reload) + { //2015.08.09. + System.out.println("Auto-flair plugin cleanup for reloading..."); + MaybeOfflinePlayer.AllPlayers.clear(); + TownColors.clear(); + } + System.out.println("Loading files for auto-flair plugin..."); //2015.08.09. + try { + File file=new File("flairsaccepted.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + //System.out.println("Name: " + name); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("flairsignored.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsignored.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("autoflairconfig.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + TownColors.put(s[0], s[1]); + } + br.close(); + } + file=new File("customflairs.txt"); //2015.08.09. + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + MaybeOfflinePlayer.AddPlayerIfNeeded(s[0]).Flair=s[1]; //2015.08.09. + } + br.close(); + } + //throw new IOException("Test"); //2015.08.09. + System.out.println("Auto-flair plugin loaded files!"); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + public static void SaveFiles() //<-- 2015.08.09. + { + try + { + FileWriter fw; + fw = new FileWriter("flairsaccepted.txt"); + fw.close(); + fw = new FileWriter("flairsignored.txt"); + fw.close(); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + try { + File file=new File("flairsaccepted.txt"); + BufferedWriter bw=new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.AcceptedFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + file=new File("flairsignored.txt"); + bw = new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.IgnoredFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + public static void SetPlayerFlair(Player player, String flair) + { //2015.08.09. + flair=flair.replace('&', '§'); + MaybeOfflinePlayer.AddPlayerIfNeeded(player.getName()).Flair=flair; + File file=new File("customflairs.txt"); + BufferedWriter bw=new BufferedWriter(new FileWriter(file, true)); + bw.write(player.getName()+"\n"); + bw.close(); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/8d/90fd528ee33e001517108d149b613203 b/.metadata/.plugins/org.eclipse.core.resources/.history/8d/90fd528ee33e001517108d149b613203 new file mode 100644 index 0000000..2a14b51 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/8d/90fd528ee33e001517108d149b613203 @@ -0,0 +1,265 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +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; + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. + //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) + if(p.Flair==null) + { + player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); + return true; + } + switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. + { + case "accept": + { + if(p.IgnoredFlair) + p.IgnoredFlair=false; //2015.08.08. + if(!p.AcceptedFlair) + { + String flair=p.Flair; //2015.08.08. + //PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + PluginMain.AppendPlayerDisplayFlair(p, player); + p.AcceptedFlair=true; //2015.08.08. + player.sendMessage("§6Your flair has been set:§r "+flair); + } + else + player.sendMessage("§cYou already have this user's flair.§r"); + break; + } + case "ignore": + { + if(p.AcceptedFlair) + p.AcceptedFlair=false; //2015.08.08. + if(!p.IgnoredFlair) + { + p.IgnoredFlair=true; + String flair=p.Flair; //2015.08.08. + PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. + player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); + } + else + player.sendMessage("§cYou already ignored this request.§r"); + break; + } + /*case "reload": //2015.07.20. + DoReload(player); + break;*/ + case "admin": //2015.08.09. + DoAdmin(player, args); + break; + case "nonpresser": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§7(non-pr.)§r"; + break; + case "cantpress": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§r(can't press)§r"; + break; + default: + return false; + } + return true; + } + /*if(args[0].toLowerCase()=="reload") + DoReload(null); //2015.07.20.*/ + else if(args.length>0 && args[0].toLowerCase().equals("admin")) //2015.08.09. + { + DoAdmin(null, args); //2015.08.09. + return true; //2015.08.09. + } + return false; + } + private static void DoReload(Player player) + { //2015.07.20. + //if(player==null || player.isOp() || player.getName()=="NorbiPeti") + //{ + try + { + File file=new File("autoflairconfig.txt"); + if(file.exists()) + { + PluginMain.LoadFiles(true); //2015.08.09. + for(Player p : PluginMain.GetPlayers()) + { + MaybeOfflinePlayer mp = MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName()); + if(mp.Flair!=null) + { + String flair=mp.Flair; + PluginMain.RemovePlayerDisplayFlairFinal(p, flair); + //PluginMain.AppendPlayerDisplayFlairFinal(p, flair); + PluginMain.AppendPlayerDisplayFlair(mp, p); //2015.08.09. + } + String msg="§6Note: The auto-flair plugin has been reloaded. You might need to wait 10s to have your flair.§r"; //2015.08.09. + p.sendMessage(msg); //2015.08.09. + } + //String msg="§6Reloaded config file.§r"; + //SendMessage(player, msg); //2015.08.09. + } + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + if(player!=null) + player.sendMessage("§cAn error occured. See console for details.§r"); + PluginMain.LastException=e; //2015.08.09. + } + //} + //else + //player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static Player ReloadPlayer; //2015.08.09. + private static void DoAdmin(Player player, String[] args) + { //2015.08.09. + if(player==null || player.isOp() || player.getName()=="NorbiPeti") + { + //System.out.println("Args length: " + args.length); + if(args.length==1) + { + String message="§cUsage: /u admin reload|playerinfo§r"; + SendMessage(player, message); + return; + } + //args[0] is "admin" + switch(args[1].toLowerCase()) + { + case "reload": + ReloadPlayer=player; //2015.08.09. + SendMessage(player, "§6Make sure to save the current settings before you modify and reload them! Type /u admin confirm when done.§r"); + break; + case "playerinfo": + DoPlayerInfo(player, args); + break; + case "getlasterror": + DoGetLastError(player, args); + case "confirm": + if(ReloadPlayer==player) + DoReload(player); //2015.08.09. + else + SendMessage(player, "§cYou need to do /u admin reload first.§r"); + break; + case "save": + PluginMain.SaveFiles(); //2015.08.09. + SendMessage(player, "§6Saved files. Now you can edit them and reload if you want.§r"); + break; + case "setflair": + DoSetFlair(player, args); + break; + default: + String message="§cUsage: /u admin reload|playerinfo|getlasterror|save|setflair§r"; + SendMessage(player, message); + return; + } + } + else + player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static void DoPlayerInfo(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "playerinfo" + if(args.length==2) + { + String message="§cUsage: /u admin playerinfo §r"; + SendMessage(player, message); + return; + } + if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2])) + { + String message="§cPlayer not found: "+args[2]+"§r"; + SendMessage(player, message); + return; + } + MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]); + SendMessage(player, "Player name: "+p.PlayerName); + SendMessage(player, "User flair: "+p.Flair); + SendMessage(player, "Username: "+p.UserName); + SendMessage(player, "Flair accepted: "+p.AcceptedFlair); + SendMessage(player, "Flair ignored: "+p.IgnoredFlair); + } + private static void SendMessage(Player player, String message) + { //2015.08.09. + if(player==null) + System.out.println(message); + else + player.sendMessage(message); + } + private static void DoGetLastError(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "getlasterror" + if(PluginMain.LastException!=null) + { + SendMessage(player, "Last error:"); + SendMessage(player, PluginMain.LastException.toString()); + PluginMain.LastException=null; + } + else + SendMessage(player, "There were no exceptions."); + } + private static void SetPlayerFlair(Player player, MaybeOfflinePlayer targetplayer, String flair) + { //2015.08.09. + flair=flair.replace('&', '§'); + targetplayer.Flair=flair; + if(!PluginMain.RemoveLineFromFile("customflairs.txt", targetplayer.PlayerName)) + { + SendMessage(player, "§cError removing previous custom flair!§r"); + return; + } + File file=new File("customflairs.txt"); + try { + BufferedWriter bw; + bw = new BufferedWriter(new FileWriter(file, true)); + bw.write(targetplayer.PlayerName+"\n"); + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + PluginMain.LastException=e; //2015.08.09. + } + SendMessage(player, "§6The flair has been set. Player: "+targetplayer.PlayerName+" Flair: "+flair+"§r"); + } + private static void DoSetFlair(Player player, String[] args) + { + //args[0] is "admin" - args[1] is "setflair" + if(args.length<4) + { + SendMessage(player, "§cUsage: /u admin setflair "); + return; + } + SetPlayerFlair(player, MaybeOfflinePlayer.AddPlayerIfNeeded(args[2]), args[3]); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/8d/d0631404023e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/8d/d0631404023e00151c31fb33fff4337f deleted file mode 100644 index ab9966d..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/8d/d0631404023e00151c31fb33fff4337f +++ /dev/null @@ -1,125 +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; - 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/8f/9034fdd8df3e001517108d149b613203 b/.metadata/.plugins/org.eclipse.core.resources/.history/8f/9034fdd8df3e001517108d149b613203 new file mode 100644 index 0000000..a3f007b --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/8f/9034fdd8df3e001517108d149b613203 @@ -0,0 +1,255 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +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; + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. + //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) + if(p.Flair==null) + { + player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); + return true; + } + switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. + { + case "accept": + { + if(p.IgnoredFlair) + p.IgnoredFlair=false; //2015.08.08. + if(!p.AcceptedFlair) + { + String flair=p.Flair; //2015.08.08. + //PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + PluginMain.AppendPlayerDisplayFlair(p, player); + p.AcceptedFlair=true; //2015.08.08. + player.sendMessage("§6Your flair has been set:§r "+flair); + } + else + player.sendMessage("§cYou already have this user's flair.§r"); + break; + } + case "ignore": + { + if(p.AcceptedFlair) + p.AcceptedFlair=false; //2015.08.08. + if(!p.IgnoredFlair) + { + p.IgnoredFlair=true; + String flair=p.Flair; //2015.08.08. + PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. + player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); + } + else + player.sendMessage("§cYou already ignored this request.§r"); + break; + } + /*case "reload": //2015.07.20. + DoReload(player); + break;*/ + case "admin": //2015.08.09. + DoAdmin(player, args); + break; + case "nonpresser": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§7(non-pr.)§r"; + break; + case "cantpress": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§r(can't press)§r"; + break; + default: + return false; + } + return true; + } + /*if(args[0].toLowerCase()=="reload") + DoReload(null); //2015.07.20.*/ + else if(args.length>0 && args[0].toLowerCase().equals("admin")) //2015.08.09. + { + DoAdmin(null, args); //2015.08.09. + return true; //2015.08.09. + } + return false; + } + private static void DoReload(Player player) + { //2015.07.20. + //if(player==null || player.isOp() || player.getName()=="NorbiPeti") + //{ + try + { + File file=new File("autoflairconfig.txt"); + if(file.exists()) + { + PluginMain.LoadFiles(true); //2015.08.09. + for(Player p : PluginMain.GetPlayers()) + { + MaybeOfflinePlayer mp = MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName()); + if(mp.Flair!=null) + { + String flair=mp.Flair; + PluginMain.RemovePlayerDisplayFlairFinal(p, flair); + //PluginMain.AppendPlayerDisplayFlairFinal(p, flair); + PluginMain.AppendPlayerDisplayFlair(mp, p); //2015.08.09. + } + String msg="§6Note: The auto-flair plugin has been reloaded. You might need to wait 10s to have your flair.§r"; //2015.08.09. + p.sendMessage(msg); //2015.08.09. + } + //String msg="§6Reloaded config file.§r"; + //SendMessage(player, msg); //2015.08.09. + } + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + if(player!=null) + player.sendMessage("§cAn error occured. See console for details.§r"); + PluginMain.LastException=e; //2015.08.09. + } + //} + //else + //player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static Player ReloadPlayer; //2015.08.09. + private static void DoAdmin(Player player, String[] args) + { //2015.08.09. + if(player==null || player.isOp() || player.getName()=="NorbiPeti") + { + //System.out.println("Args length: " + args.length); + if(args.length==1) + { + String message="§cUsage: /u admin reload|playerinfo§r"; + SendMessage(player, message); + return; + } + //args[0] is "admin" + switch(args[1].toLowerCase()) + { + case "reload": + ReloadPlayer=player; //2015.08.09. + SendMessage(player, "§6Make sure to save the current settings before you modify and reload them! Type /u admin confirm when done.§r"); + break; + case "playerinfo": + DoPlayerInfo(player, args); + break; + case "getlasterror": + DoGetLastError(player, args); + case "confirm": + if(ReloadPlayer==player) + DoReload(player); //2015.08.09. + else + SendMessage(player, "§cYou need to do /u admin reload first.§r"); + break; + case "save": + PluginMain.SaveFiles(); //2015.08.09. + SendMessage(player, "§6Saved files. Now you can edit them and reload if you want.§r"); + break; + case "setflair": + SetFlair() + break; + default: + String message="§cUsage: /u admin reload|playerinfo|getlasterror|save§r"; + SendMessage(player, message); + return; + } + } + else + player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static void DoPlayerInfo(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "playerinfo" + if(args.length==2) + { + String message="§cUsage: /u admin playerinfo §r"; + SendMessage(player, message); + return; + } + if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2])) + { + String message="§cPlayer not found: "+args[2]+"§r"; + SendMessage(player, message); + return; + } + MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]); + SendMessage(player, "Player name: "+p.PlayerName); + SendMessage(player, "User flair: "+p.Flair); + SendMessage(player, "Username: "+p.UserName); + SendMessage(player, "Flair accepted: "+p.AcceptedFlair); + SendMessage(player, "Flair ignored: "+p.IgnoredFlair); + } + private static void SendMessage(Player player, String message) + { //2015.08.09. + if(player==null) + System.out.println(message); + else + player.sendMessage(message); + } + private static void DoGetLastError(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "getlasterror" + if(PluginMain.LastException!=null) + { + SendMessage(player, "Last error:"); + SendMessage(player, PluginMain.LastException.toString()); + PluginMain.LastException=null; + } + else + SendMessage(player, "There were no exceptions."); + } + private static void SetPlayerFlair(Player player, Player targetplayer, String flair) + { //2015.08.09. + flair=flair.replace('&', '§'); + MaybeOfflinePlayer.AddPlayerIfNeeded(player.getName()).Flair=flair; + if(!PluginMain.RemoveLineFromFile("customflairs.txt", targetplayer.getName())) + { + SendMessage(player, "§cError removing previous custom flair!§r"); + return; + } + File file=new File("customflairs.txt"); + try { + BufferedWriter bw; + bw = new BufferedWriter(new FileWriter(file, true)); + bw.write(targetplayer.getName()+"\n"); + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + PluginMain.LastException=e; //2015.08.09. + } + SendMessage(player, "§6The flair has been set. Player: "+targetplayer.getName()+" Flair: "+flair+"§r"); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/9/10ab8866df3e001517108d149b613203 b/.metadata/.plugins/org.eclipse.core.resources/.history/9/10ab8866df3e001517108d149b613203 new file mode 100644 index 0000000..2a1ad93 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/9/10ab8866df3e001517108d149b613203 @@ -0,0 +1,252 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +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; + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. + //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) + if(p.Flair==null) + { + player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); + return true; + } + switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. + { + case "accept": + { + if(p.IgnoredFlair) + p.IgnoredFlair=false; //2015.08.08. + if(!p.AcceptedFlair) + { + String flair=p.Flair; //2015.08.08. + //PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + PluginMain.AppendPlayerDisplayFlair(p, player); + p.AcceptedFlair=true; //2015.08.08. + player.sendMessage("§6Your flair has been set:§r "+flair); + } + else + player.sendMessage("§cYou already have this user's flair.§r"); + break; + } + case "ignore": + { + if(p.AcceptedFlair) + p.AcceptedFlair=false; //2015.08.08. + if(!p.IgnoredFlair) + { + p.IgnoredFlair=true; + String flair=p.Flair; //2015.08.08. + PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. + player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); + } + else + player.sendMessage("§cYou already ignored this request.§r"); + break; + } + /*case "reload": //2015.07.20. + DoReload(player); + break;*/ + case "admin": //2015.08.09. + DoAdmin(player, args); + break; + case "nonpresser": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§7(non-pr.)§r"; + break; + case "cantpress": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§r(can't press)§r"; + break; + default: + return false; + } + return true; + } + /*if(args[0].toLowerCase()=="reload") + DoReload(null); //2015.07.20.*/ + else if(args.length>0 && args[0].toLowerCase().equals("admin")) //2015.08.09. + { + DoAdmin(null, args); //2015.08.09. + return true; //2015.08.09. + } + return false; + } + private static void DoReload(Player player) + { //2015.07.20. + //if(player==null || player.isOp() || player.getName()=="NorbiPeti") + //{ + try + { + File file=new File("autoflairconfig.txt"); + if(file.exists()) + { + PluginMain.LoadFiles(true); //2015.08.09. + for(Player p : PluginMain.GetPlayers()) + { + MaybeOfflinePlayer mp = MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName()); + if(mp.Flair!=null) + { + String flair=mp.Flair; + PluginMain.RemovePlayerDisplayFlairFinal(p, flair); + //PluginMain.AppendPlayerDisplayFlairFinal(p, flair); + PluginMain.AppendPlayerDisplayFlair(mp, p); //2015.08.09. + } + String msg="§6Note: The auto-flair plugin has been reloaded. You might need to wait 10s to have your flair.§r"; //2015.08.09. + p.sendMessage(msg); //2015.08.09. + } + //String msg="§6Reloaded config file.§r"; + //SendMessage(player, msg); //2015.08.09. + } + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + if(player!=null) + player.sendMessage("§cAn error occured. See console for details.§r"); + PluginMain.LastException=e; //2015.08.09. + } + //} + //else + //player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static Player ReloadPlayer; //2015.08.09. + private static void DoAdmin(Player player, String[] args) + { //2015.08.09. + if(player==null || player.isOp() || player.getName()=="NorbiPeti") + { + //System.out.println("Args length: " + args.length); + if(args.length==1) + { + String message="§cUsage: /u admin reload|playerinfo§r"; + SendMessage(player, message); + return; + } + //args[0] is "admin" + switch(args[1].toLowerCase()) + { + case "reload": + ReloadPlayer=player; //2015.08.09. + SendMessage(player, "§6Make sure to save the current settings before you modify and reload them! Type /u admin confirm when done.§r"); + break; + case "playerinfo": + DoPlayerInfo(player, args); + break; + case "getlasterror": + DoGetLastError(player, args); + case "confirm": + if(ReloadPlayer==player) + DoReload(player); //2015.08.09. + else + SendMessage(player, "§cYou need to do /u admin reload first.§r"); + break; + case "save": + PluginMain.SaveFiles(); //2015.08.09. + SendMessage(player, "§6Saved files. Now you can edit them and reload if you want.§r"); + break; + default: + String message="§cUsage: /u admin reload|playerinfo|getlasterror§r"; + SendMessage(player, message); + return; + } + } + else + player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static void DoPlayerInfo(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "playerinfo" + if(args.length==2) + { + String message="§cUsage: /u admin playerinfo §r"; + SendMessage(player, message); + return; + } + if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2])) + { + String message="§cPlayer not found: "+args[2]+"§r"; + SendMessage(player, message); + return; + } + MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]); + SendMessage(player, "Player name: "+p.PlayerName); + SendMessage(player, "User flair: "+p.Flair); + SendMessage(player, "Username: "+p.UserName); + SendMessage(player, "Flair accepted: "+p.AcceptedFlair); + SendMessage(player, "Flair ignored: "+p.IgnoredFlair); + } + private static void SendMessage(Player player, String message) + { //2015.08.09. + if(player==null) + System.out.println(message); + else + player.sendMessage(message); + } + private static void DoGetLastError(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "getlasterror" + if(PluginMain.LastException!=null) + { + SendMessage(player, "Last error:"); + SendMessage(player, PluginMain.LastException.toString()); + PluginMain.LastException=null; + } + else + SendMessage(player, "There were no exceptions."); + } + private static void SetPlayerFlair(Player player, String flair) + { //2015.08.09. + flair=flair.replace('&', '§'); + MaybeOfflinePlayer.AddPlayerIfNeeded(player.getName()).Flair=flair; + if(!PluginMain.RemoveLineFromFile("customflairs.txt")) + { + SendMessage(player, "§cError removing previous custom flair!§r"); + return; + } + File file=new File("customflairs.txt"); + try { + BufferedWriter bw; + bw = new BufferedWriter(new FileWriter(file, true)); + bw.write(player.getName()+"\n"); + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + PluginMain.LastException=e; //2015.08.09. + } + SendMessage(player, "§6The flair has been set. Player: "+player.getName()+" Flair: "+flair+"§r"); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/91/0009f78bdf3e001517108d149b613203 b/.metadata/.plugins/org.eclipse.core.resources/.history/91/0009f78bdf3e001517108d149b613203 new file mode 100644 index 0000000..c9f322f --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/91/0009f78bdf3e001517108d149b613203 @@ -0,0 +1,421 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStream; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLConnection; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + +import org.apache.commons.io.IOUtils; +import org.bukkit.entity.Player; +import org.bukkit.plugin.java.JavaPlugin; +import org.json.JSONArray; +import org.json.JSONObject; + +import com.palmergames.bukkit.towny.object.Town; +import com.palmergames.bukkit.towny.object.WorldCoord; + +public class PluginMain extends JavaPlugin +{ //Translated to Java: 2015.07.15. + //A user, which flair isn't obtainable: + //https://www.reddit.com/r/thebutton/comments/31c32v/i_pressed_the_button_without_really_thinking/ + private static PluginMain Instance; + // Fired when plugin is first enabled + @Override + public void onEnable() + { + System.out.println("The Button Auto-flair Plugin by NorbiPeti (:P)"); + getServer().getPluginManager().registerEvents(new PlayerListener(), this); + this.getCommand("u").setExecutor(new Commands()); + this.getCommand("u").setUsage(this.getCommand("u").getUsage().replace('&', '§')); + Instance=this; //2015.08.08. + LoadFiles(false); //2015.08.09. + Runnable r=new Runnable(){public void run(){ThreadMethod();}}; + Thread t=new Thread(r); + t.start(); + } + Boolean stop=false; + // Fired when plugin is disabled + @Override + public void onDisable() + { + SaveFiles(); //2015.08.09. + stop=true; + } + + public void ThreadMethod() //<-- 2015.07.16. + { + while(!stop) + { + try + { + String body=DownloadString("https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/autoflair_system_comment_your_minecraft_name_and/.json?limit=1000"); + JSONArray json=new JSONArray(body).getJSONObject(1).getJSONObject("data").getJSONArray("children"); + for(Object obj : json) + { + JSONObject item = (JSONObject)obj; + String author=item.getJSONObject("data").getString("author"); + String ign=item.getJSONObject("data").getString("body"); + int start = ign.indexOf("IGN:") + "IGN:".length(); + if(start==-1) + continue; //2015.08.09. + int end = ign.indexOf(' ', start); + if (end == -1 || end == start) + end=ign.indexOf('\n', start); //2015.07.15. + if (end == -1 || end == start) + ign = ign.substring(start); + else + ign = ign.substring(start, end); + ign = ign.trim(); + if(HasIGFlair(ign)) + continue; + try { + Thread.sleep(10); + } catch(InterruptedException ex) { + Thread.currentThread().interrupt(); + } + String[] flairdata = DownloadString("http://karmadecay.com/thebutton-data.php?users=" + author).replace("\"", "").split(":"); + String flair; + if(flairdata.length > 1) //2015.07.15. + flair = flairdata[1]; + else + flair=""; + if (flair != "-1") + flair = flair + "s"; + else + flair = "non-presser"; + String flairclass; + if(flairdata.length>2) + flairclass = flairdata[2]; + else + flairclass="unknown"; + SetFlair(ign, flair, flairclass, author); + } + Thread.sleep(10000); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + } + + public static Exception LastException; //2015.08.09. + + public String DownloadString(String urlstr) throws MalformedURLException, IOException + { + URL url = new URL(urlstr); + URLConnection con = url.openConnection(); + con.setRequestProperty("User-Agent", "TheButtonAutoFlair"); + InputStream in = con.getInputStream(); + String encoding = con.getContentEncoding(); + encoding = encoding == null ? "UTF-8" : encoding; + String body = IOUtils.toString(in, encoding); + in.close(); + return body; + } + + public static Map TownColors=new HashMap(); //2015.07.20. + public Boolean HasIGFlair(String playername) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + return p.Flair!=null; //2015.08.08. + } + + public void SetFlair(String playername, String text, String flairclass, String username) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + String finalflair; + p.FlairDecided=true; + switch(flairclass) + { + case "press-1": + finalflair="§c("+text+")§r"; + break; + case "press-2": + finalflair="§6("+text+")§r"; + break; + case "press-3": + finalflair="§e("+text+")§r"; + break; + case "press-4": + finalflair="§a("+text+")§r"; + break; + case "press-5": + finalflair="§9("+text+")§r"; + break; + 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; + case "undecided": //2015.08.09. + p.FlairDecided=false; + finalflair=""; + break; + default: + finalflair=""; + break; + } + if(finalflair.length()==0) //<-- 2015.07.20. + return; + p.Flair=finalflair; //2015.08.08. + p.UserName=username; //2015.08.08. + System.out.println("Added new flair to "+playername+": "+finalflair); + for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08. + { + if(player.getName().equals(playername)) + { + //AppendPlayerDisplayFlair(player, username, finalflair); + AppendPlayerDisplayFlair(p, player); + break; + } + } + } + + public static String GetFlair(Player player) + { //2015.07.16. + String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08. + return flair==null ? "" : flair; + } + + //public static void AppendPlayerDisplayFlair(Player player, String username, String flair) + public static void AppendPlayerDisplayFlair(MaybeOfflinePlayer player, Player p) //<-- 2015.08.09. + { + + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).IgnoredFlair) + return; + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).AcceptedFlair) + { + AppendPlayerDisplayFlairFinal(p, player.Flair); //2015.07.20. + if(!player.FlairDecided) + p.sendMessage("§9Your flair type is unknown. Are you a non-presser or a can't press? (/u nonpresser or /u cantpress)§r"); //2015.08.09. + } + else + p.sendMessage("§9Are you Reddit user "+player.UserName+"?§r §6Type /u accept or /u ignore§r"); + } + + private static void AppendPlayerDisplayFlairFinal(Player player, String flair) + { //2015.07.20. + String color = GetColorForTown(GetPlayerTown(player)); //TO!DO: Multiple colors put on first capital letters + String[] colors = color.substring(1).split("§"); + String displayname=player.getName(); //2015.08.08. + ArrayList Positions=new ArrayList<>(); + for(int i=0; i=colors.length) + { + int x=0; + for(int i=0; i GetPlayers() + { + return Instance.getServer().getOnlinePlayers(); + } + + public static void LoadFiles(boolean reload) //<-- 2015.08.09. + { + if(reload) + { //2015.08.09. + System.out.println("Auto-flair plugin cleanup for reloading..."); + MaybeOfflinePlayer.AllPlayers.clear(); + TownColors.clear(); + } + System.out.println("Loading files for auto-flair plugin..."); //2015.08.09. + try { + File file=new File("flairsaccepted.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + //System.out.println("Name: " + name); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("flairsignored.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsignored.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("autoflairconfig.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + TownColors.put(s[0], s[1]); + } + br.close(); + } + file=new File("customflairs.txt"); //2015.08.09. + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + MaybeOfflinePlayer.AddPlayerIfNeeded(s[0]).Flair=s[1]; //2015.08.09. + } + br.close(); + } + //throw new IOException("Test"); //2015.08.09. + System.out.println("Auto-flair plugin loaded files!"); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + public static void SaveFiles() //<-- 2015.08.09. + { + try + { + FileWriter fw; + fw = new FileWriter("flairsaccepted.txt"); + fw.close(); + fw = new FileWriter("flairsignored.txt"); + fw.close(); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + try { + File file=new File("flairsaccepted.txt"); + BufferedWriter bw=new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.AcceptedFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + file=new File("flairsignored.txt"); + bw = new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.IgnoredFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + public static boolean RemoveLineFromFile(String file) + { + File inputFile = new File(file); + File tempFile = new File("_temp.txt"); + + try { + BufferedReader reader = new BufferedReader(new FileReader(inputFile)); + BufferedWriter writer = new BufferedWriter(new FileWriter(tempFile)); + + String lineToRemove = "bbb"; + String currentLine; + + while((currentLine = reader.readLine()) != null) { + // trim newline when comparing with lineToRemove + String trimmedLine = currentLine.trim(); + if(trimmedLine.equals(lineToRemove)) continue; + writer.write(currentLine + System.getProperty("line.separator")); + } + writer.close(); + reader.close(); + return tempFile.renameTo(inputFile); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + return false; + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/3b/d0078548033e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/91/c01c0d9ecf3e001518fa86d7ae2a1cf8 similarity index 67% rename from .metadata/.plugins/org.eclipse.core.resources/.history/3b/d0078548033e00151c31fb33fff4337f rename to .metadata/.plugins/org.eclipse.core.resources/.history/91/c01c0d9ecf3e001518fa86d7ae2a1cf8 index e51b439..a085586 100644 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/3b/d0078548033e00151c31fb33fff4337f +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/91/c01c0d9ecf3e001518fa86d7ae2a1cf8 @@ -15,43 +15,35 @@ public class PlayerListener implements Listener public void onPlayerJoin(PlayerJoinEvent event) { Player p=event.getPlayer(); - //PluginMain.Players.add(p); - //event.getPlayer().setDisplayName(p.getDisplayName()+PluginMain.GetFlair(p)); - //if(PluginMain.PlayerUserNames.containsKey(p.getName())) //<-- 2015.07.20. - //PluginMain.AppendPlayerDisplayFlair(p, PluginMain.PlayerUserNames.get(p.getName()), PluginMain.GetFlair(p)); - 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, 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. + MaybeOfflinePlayer player = MaybeOfflinePlayer.AllPlayers.get(event.getPlayer().getName()); + String flair=player.Flair; //2015.08.08. + if(flair==null || !player.AcceptedFlair) + flair=""; //2015.08.08. + String message=event.getMessage(); //2015.08.08. + /*for(Player p : PluginMain.GetPlayers()) + { //2015.08.08. + message.replaceAll(p.getName(), ) + }*/ + event.setFormat(event.getFormat().substring(0, event.getFormat().indexOf(">"))+flair+"> "+message); //2015.08.08. } private static Class nmsChatSerializer = Reflection.getNMSClass("IChatBaseComponent$ChatSerializer"); @@ -72,6 +64,7 @@ public class PlayerListener implements Listener System.out.println("6"); } catch (Exception e) { e.printStackTrace(); + PluginMain.LastException=e; //2015.08.09. } } diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/92/d0efd7c1fe3d00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/92/d0efd7c1fe3d00151c31fb33fff4337f deleted file mode 100644 index 36d406a..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/92/d0efd7c1fe3d00151c31fb33fff4337f +++ /dev/null @@ -1,122 +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()); - 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; - 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/93/10f3fc0acf3e001518fa86d7ae2a1cf8 b/.metadata/.plugins/org.eclipse.core.resources/.history/93/10f3fc0acf3e001518fa86d7ae2a1cf8 new file mode 100644 index 0000000..a62c891 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/93/10f3fc0acf3e001518fa86d7ae2a1cf8 @@ -0,0 +1,361 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStream; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLConnection; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + +import org.apache.commons.io.IOUtils; +import org.bukkit.entity.Player; +import org.bukkit.plugin.java.JavaPlugin; +import org.json.JSONArray; +import org.json.JSONObject; + +import tk.sznp.thebuttonautoflair.MaybeOfflinePlayer.FlairClassType; + +import com.palmergames.bukkit.towny.object.Town; +import com.palmergames.bukkit.towny.object.WorldCoord; + +public class PluginMain extends JavaPlugin +{ //Translated to Java: 2015.07.15. + //A user, which flair isn't obtainable: + //https://www.reddit.com/r/thebutton/comments/31c32v/i_pressed_the_button_without_really_thinking/ + private static PluginMain Instance; + // Fired when plugin is first enabled + @Override + public void onEnable() + { + System.out.println("The Button Auto-flair Plugin by NorbiPeti (:P)"); + getServer().getPluginManager().registerEvents(new PlayerListener(), this); + this.getCommand("u").setExecutor(new Commands()); + this.getCommand("u").setUsage(this.getCommand("u").getUsage().replace('&', '§')); + Instance=this; //2015.08.08. + try { + File file=new File("flairsaccepted.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + //System.out.println("Name: " + name); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("flairsignored.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsignored.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("autoflairconfig.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + TownColors.put(s[0], s[1]); + } + br.close(); + } + //throw new IOException("Test"); //2015.08.09. + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + Runnable r=new Runnable(){public void run(){ThreadMethod();}}; + Thread t=new Thread(r); + t.start(); + } + Boolean stop=false; + // Fired when plugin is disabled + @Override + public void onDisable() + { + try + { + FileWriter fw; + fw = new FileWriter("flairsaccepted.txt"); + fw.close(); + fw = new FileWriter("flairsignored.txt"); + fw.close(); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + try { + File file=new File("flairsaccepted.txt"); + BufferedWriter bw=new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.AcceptedFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + file=new File("flairsignored.txt"); + bw = new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.IgnoredFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + stop=true; + } + + public void ThreadMethod() //<-- 2015.07.16. + { + while(!stop) + { + try + { + String body=DownloadString("https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/autoflair_system_comment_your_minecraft_name_and/.json?limit=1000"); + JSONArray json=new JSONArray(body).getJSONObject(1).getJSONObject("data").getJSONArray("children"); + for(Object obj : json) + { + JSONObject item = (JSONObject)obj; + String author=item.getJSONObject("data").getString("author"); + String ign=item.getJSONObject("data").getString("body"); + int start = ign.indexOf("IGN:") + "IGN:".length(); + int end = ign.indexOf(' ', start); + if (end == -1 || end == start) + end=ign.indexOf('\n', start); //2015.07.15. + if (end == -1 || end == start) + ign = ign.substring(start); + else + ign = ign.substring(start, end); + ign = ign.trim(); + if(HasIGFlair(ign)) + continue; + try { + Thread.sleep(10); + } catch(InterruptedException ex) { + Thread.currentThread().interrupt(); + } + String[] flairdata = DownloadString("http://karmadecay.com/thebutton-data.php?users=" + author).replace("\"", "").split(":"); + String flair; + if(flairdata.length > 1) //2015.07.15. + flair = flairdata[1]; + else + flair=""; + if (flair != "-1") + flair = flair + "s"; + else + flair = "non-presser"; + String flairclass; + if(flairdata.length>2) + flairclass = flairdata[2]; + else + flairclass="unknown"; + SetFlair(ign, flair, flairclass, author); + } + Thread.sleep(10000); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + } + + public static Exception LastException; //2015.08.09. + + public String DownloadString(String urlstr) throws MalformedURLException, IOException + { + URL url = new URL(urlstr); + URLConnection con = url.openConnection(); + con.setRequestProperty("User-Agent", "TheButtonAutoFlair"); + InputStream in = con.getInputStream(); + String encoding = con.getContentEncoding(); + encoding = encoding == null ? "UTF-8" : encoding; + String body = IOUtils.toString(in, encoding); + in.close(); + return body; + } + + public static Map TownColors=new HashMap(); //2015.07.20. + public Boolean HasIGFlair(String playername) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + return p.Flair!=null; //2015.08.08. + } + + public void SetFlair(String playername, String text, String flairclass, String username) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + String finalflair; + p.FlairDecided=true; + switch(flairclass) + { + case "press-1": + finalflair="§c("+text+")§r"; + break; + case "press-2": + finalflair="§6("+text+")§r"; + break; + case "press-3": + finalflair="§e("+text+")§r"; + break; + case "press-4": + finalflair="§a("+text+")§r"; + break; + case "press-5": + finalflair="§9("+text+")§r"; + break; + 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; + case "undecided": //2015.08.09. + p.FlairDecided=false; + finalflair=""; + break; + default: + finalflair=""; + break; + } + if(finalflair.length()==0) //<-- 2015.07.20. + return; + p.Flair=finalflair; //2015.08.08. + p.UserName=username; //2015.08.08. + System.out.println("Added new flair to "+playername+": "+finalflair); + for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08. + { + if(player.getName().equals(playername)) + { + AppendPlayerDisplayFlair(player, username, finalflair); + break; + } + } + } + + public static String GetFlair(Player player) + { //2015.07.16. + String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08. + return flair==null ? "" : flair; + } + + //public static void AppendPlayerDisplayFlair(Player player, String username, String flair) + public static void AppendPlayerDisplayFlair(MaybeOfflinePlayer player) + { + if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).IgnoredFlair) + return; + if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).AcceptedFlair) + { + AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + } + else + player.sendMessage("§9Are you Reddit user "+username+"?§r §6Type /u accept or /u ignore§r"); + } + + private static void AppendPlayerDisplayFlairFinal(Player player, String flair) + { //2015.07.20. + String color = GetColorForTown(GetPlayerTown(player)); //TO!DO: Multiple colors put on first capital letters + String[] colors = color.substring(1).split("§"); + String displayname=player.getName(); //2015.08.08. + ArrayList Positions=new ArrayList<>(); + for(int i=0; i=colors.length) + { + int x=0; + for(int i=0; i GetPlayers() + { + return Instance.getServer().getOnlinePlayers(); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/93/d0f07864d23e001518fa86d7ae2a1cf8 b/.metadata/.plugins/org.eclipse.core.resources/.history/93/d0f07864d23e001518fa86d7ae2a1cf8 new file mode 100644 index 0000000..f15dd12 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/93/d0f07864d23e001518fa86d7ae2a1cf8 @@ -0,0 +1,376 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStream; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLConnection; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + +import org.apache.commons.io.IOUtils; +import org.bukkit.entity.Player; +import org.bukkit.plugin.java.JavaPlugin; +import org.json.JSONArray; +import org.json.JSONObject; + +import com.palmergames.bukkit.towny.object.Town; +import com.palmergames.bukkit.towny.object.WorldCoord; + +public class PluginMain extends JavaPlugin +{ //Translated to Java: 2015.07.15. + //A user, which flair isn't obtainable: + //https://www.reddit.com/r/thebutton/comments/31c32v/i_pressed_the_button_without_really_thinking/ + private static PluginMain Instance; + // Fired when plugin is first enabled + @Override + public void onEnable() + { + System.out.println("The Button Auto-flair Plugin by NorbiPeti (:P)"); + getServer().getPluginManager().registerEvents(new PlayerListener(), this); + this.getCommand("u").setExecutor(new Commands()); + this.getCommand("u").setUsage(this.getCommand("u").getUsage().replace('&', '§')); + Instance=this; //2015.08.08. + LoadFiles(false); //2015.08.09. + Runnable r=new Runnable(){public void run(){ThreadMethod();}}; + Thread t=new Thread(r); + t.start(); + } + Boolean stop=false; + // Fired when plugin is disabled + @Override + public void onDisable() + { + try + { + FileWriter fw; + fw = new FileWriter("flairsaccepted.txt"); + fw.close(); + fw = new FileWriter("flairsignored.txt"); + fw.close(); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + try { + File file=new File("flairsaccepted.txt"); + BufferedWriter bw=new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.AcceptedFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + file=new File("flairsignored.txt"); + bw = new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.IgnoredFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + stop=true; + } + + public void ThreadMethod() //<-- 2015.07.16. + { + while(!stop) + { + try + { + String body=DownloadString("https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/autoflair_system_comment_your_minecraft_name_and/.json?limit=1000"); + JSONArray json=new JSONArray(body).getJSONObject(1).getJSONObject("data").getJSONArray("children"); + for(Object obj : json) + { + JSONObject item = (JSONObject)obj; + String author=item.getJSONObject("data").getString("author"); + String ign=item.getJSONObject("data").getString("body"); + int start = ign.indexOf("IGN:") + "IGN:".length(); + int end = ign.indexOf(' ', start); + if (end == -1 || end == start) + end=ign.indexOf('\n', start); //2015.07.15. + if (end == -1 || end == start) + ign = ign.substring(start); + else + ign = ign.substring(start, end); + ign = ign.trim(); + if(HasIGFlair(ign)) + continue; + try { + Thread.sleep(10); + } catch(InterruptedException ex) { + Thread.currentThread().interrupt(); + } + String[] flairdata = DownloadString("http://karmadecay.com/thebutton-data.php?users=" + author).replace("\"", "").split(":"); + String flair; + if(flairdata.length > 1) //2015.07.15. + flair = flairdata[1]; + else + flair=""; + if (flair != "-1") + flair = flair + "s"; + else + flair = "non-presser"; + String flairclass; + if(flairdata.length>2) + flairclass = flairdata[2]; + else + flairclass="unknown"; + SetFlair(ign, flair, flairclass, author); + } + Thread.sleep(10000); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + } + + public static Exception LastException; //2015.08.09. + + public String DownloadString(String urlstr) throws MalformedURLException, IOException + { + URL url = new URL(urlstr); + URLConnection con = url.openConnection(); + con.setRequestProperty("User-Agent", "TheButtonAutoFlair"); + InputStream in = con.getInputStream(); + String encoding = con.getContentEncoding(); + encoding = encoding == null ? "UTF-8" : encoding; + String body = IOUtils.toString(in, encoding); + in.close(); + return body; + } + + public static Map TownColors=new HashMap(); //2015.07.20. + public Boolean HasIGFlair(String playername) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + return p.Flair!=null; //2015.08.08. + } + + public void SetFlair(String playername, String text, String flairclass, String username) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + String finalflair; + p.FlairDecided=true; + switch(flairclass) + { + case "press-1": + finalflair="§c("+text+")§r"; + break; + case "press-2": + finalflair="§6("+text+")§r"; + break; + case "press-3": + finalflair="§e("+text+")§r"; + break; + case "press-4": + finalflair="§a("+text+")§r"; + break; + case "press-5": + finalflair="§9("+text+")§r"; + break; + 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; + case "undecided": //2015.08.09. + p.FlairDecided=false; + finalflair=""; + break; + default: + finalflair=""; + break; + } + if(finalflair.length()==0) //<-- 2015.07.20. + return; + p.Flair=finalflair; //2015.08.08. + p.UserName=username; //2015.08.08. + System.out.println("Added new flair to "+playername+": "+finalflair); + for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08. + { + if(player.getName().equals(playername)) + { + //AppendPlayerDisplayFlair(player, username, finalflair); + AppendPlayerDisplayFlair(p, player); + break; + } + } + } + + public static String GetFlair(Player player) + { //2015.07.16. + String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08. + return flair==null ? "" : flair; + } + + //public static void AppendPlayerDisplayFlair(Player player, String username, String flair) + public static void AppendPlayerDisplayFlair(MaybeOfflinePlayer player, Player p) //<-- 2015.08.09. + { + + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).IgnoredFlair) + return; + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).AcceptedFlair) + { + AppendPlayerDisplayFlairFinal(p, player.Flair); //2015.07.20. + if(!player.FlairDecided) + p.sendMessage("§9Your flair type is unknown. Are you a non-presser or a can't press? (/u nonpresser or /u cantpress)§r"); //2015.08.09. + } + else + p.sendMessage("§9Are you Reddit user "+player.UserName+"?§r §6Type /u accept or /u ignore§r"); + } + + private static void AppendPlayerDisplayFlairFinal(Player player, String flair) + { //2015.07.20. + String color = GetColorForTown(GetPlayerTown(player)); //TO!DO: Multiple colors put on first capital letters + String[] colors = color.substring(1).split("§"); + String displayname=player.getName(); //2015.08.08. + ArrayList Positions=new ArrayList<>(); + for(int i=0; i=colors.length) + { + int x=0; + for(int i=0; i GetPlayers() + { + return Instance.getServer().getOnlinePlayers(); + } + + public static void LoadFiles(boolean reload) //<-- 2015.08.09. + { + if(reload) + { //2015.08.09. + System.out.println("Auto-flair plugin cleanup for reloading..."); + MaybeOfflinePlayer.AllPlayers.clear(); + TownColors.clear(); + } + System.out.println("Loading files for auto-flair plugin..."); //2015.08.09. + try { + File file=new File("flairsaccepted.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + //System.out.println("Name: " + name); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("flairsignored.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsignored.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("autoflairconfig.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + TownColors.put(s[0], s[1]); + } + br.close(); + } + //throw new IOException("Test"); //2015.08.09. + System.out.println("Auto-flair plugin loaded files!"); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/94/2033b6d6d13e001518fa86d7ae2a1cf8 b/.metadata/.plugins/org.eclipse.core.resources/.history/94/2033b6d6d13e001518fa86d7ae2a1cf8 new file mode 100644 index 0000000..6ac02e4 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/94/2033b6d6d13e001518fa86d7ae2a1cf8 @@ -0,0 +1,373 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStream; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLConnection; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + +import org.apache.commons.io.IOUtils; +import org.bukkit.entity.Player; +import org.bukkit.plugin.java.JavaPlugin; +import org.json.JSONArray; +import org.json.JSONObject; + +import com.palmergames.bukkit.towny.object.Town; +import com.palmergames.bukkit.towny.object.WorldCoord; + +public class PluginMain extends JavaPlugin +{ //Translated to Java: 2015.07.15. + //A user, which flair isn't obtainable: + //https://www.reddit.com/r/thebutton/comments/31c32v/i_pressed_the_button_without_really_thinking/ + private static PluginMain Instance; + // Fired when plugin is first enabled + @Override + public void onEnable() + { + System.out.println("The Button Auto-flair Plugin by NorbiPeti (:P)"); + getServer().getPluginManager().registerEvents(new PlayerListener(), this); + this.getCommand("u").setExecutor(new Commands()); + this.getCommand("u").setUsage(this.getCommand("u").getUsage().replace('&', '§')); + Instance=this; //2015.08.08. + LoadFiles(false); //2015.08.09. + Runnable r=new Runnable(){public void run(){ThreadMethod();}}; + Thread t=new Thread(r); + t.start(); + } + Boolean stop=false; + // Fired when plugin is disabled + @Override + public void onDisable() + { + try + { + FileWriter fw; + fw = new FileWriter("flairsaccepted.txt"); + fw.close(); + fw = new FileWriter("flairsignored.txt"); + fw.close(); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + try { + File file=new File("flairsaccepted.txt"); + BufferedWriter bw=new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.AcceptedFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + file=new File("flairsignored.txt"); + bw = new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.IgnoredFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + stop=true; + } + + public void ThreadMethod() //<-- 2015.07.16. + { + while(!stop) + { + try + { + String body=DownloadString("https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/autoflair_system_comment_your_minecraft_name_and/.json?limit=1000"); + JSONArray json=new JSONArray(body).getJSONObject(1).getJSONObject("data").getJSONArray("children"); + for(Object obj : json) + { + JSONObject item = (JSONObject)obj; + String author=item.getJSONObject("data").getString("author"); + String ign=item.getJSONObject("data").getString("body"); + int start = ign.indexOf("IGN:") + "IGN:".length(); + int end = ign.indexOf(' ', start); + if (end == -1 || end == start) + end=ign.indexOf('\n', start); //2015.07.15. + if (end == -1 || end == start) + ign = ign.substring(start); + else + ign = ign.substring(start, end); + ign = ign.trim(); + if(HasIGFlair(ign)) + continue; + try { + Thread.sleep(10); + } catch(InterruptedException ex) { + Thread.currentThread().interrupt(); + } + String[] flairdata = DownloadString("http://karmadecay.com/thebutton-data.php?users=" + author).replace("\"", "").split(":"); + String flair; + if(flairdata.length > 1) //2015.07.15. + flair = flairdata[1]; + else + flair=""; + if (flair != "-1") + flair = flair + "s"; + else + flair = "non-presser"; + String flairclass; + if(flairdata.length>2) + flairclass = flairdata[2]; + else + flairclass="unknown"; + SetFlair(ign, flair, flairclass, author); + } + Thread.sleep(10000); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + } + + public static Exception LastException; //2015.08.09. + + public String DownloadString(String urlstr) throws MalformedURLException, IOException + { + URL url = new URL(urlstr); + URLConnection con = url.openConnection(); + con.setRequestProperty("User-Agent", "TheButtonAutoFlair"); + InputStream in = con.getInputStream(); + String encoding = con.getContentEncoding(); + encoding = encoding == null ? "UTF-8" : encoding; + String body = IOUtils.toString(in, encoding); + in.close(); + return body; + } + + public static Map TownColors=new HashMap(); //2015.07.20. + public Boolean HasIGFlair(String playername) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + return p.Flair!=null; //2015.08.08. + } + + public void SetFlair(String playername, String text, String flairclass, String username) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + String finalflair; + p.FlairDecided=true; + switch(flairclass) + { + case "press-1": + finalflair="§c("+text+")§r"; + break; + case "press-2": + finalflair="§6("+text+")§r"; + break; + case "press-3": + finalflair="§e("+text+")§r"; + break; + case "press-4": + finalflair="§a("+text+")§r"; + break; + case "press-5": + finalflair="§9("+text+")§r"; + break; + 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; + case "undecided": //2015.08.09. + p.FlairDecided=false; + finalflair=""; + break; + default: + finalflair=""; + break; + } + if(finalflair.length()==0) //<-- 2015.07.20. + return; + p.Flair=finalflair; //2015.08.08. + p.UserName=username; //2015.08.08. + System.out.println("Added new flair to "+playername+": "+finalflair); + for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08. + { + if(player.getName().equals(playername)) + { + //AppendPlayerDisplayFlair(player, username, finalflair); + AppendPlayerDisplayFlair(p, player); + break; + } + } + } + + public static String GetFlair(Player player) + { //2015.07.16. + String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08. + return flair==null ? "" : flair; + } + + //public static void AppendPlayerDisplayFlair(Player player, String username, String flair) + public static void AppendPlayerDisplayFlair(MaybeOfflinePlayer player, Player p) //<-- 2015.08.09. + { + + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).IgnoredFlair) + return; + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).AcceptedFlair) + { + AppendPlayerDisplayFlairFinal(p, player.Flair); //2015.07.20. + if(!player.FlairDecided) + p.sendMessage("§9Your flair type is unknown. Are you a non-presser or a can't press? (/u nonpresser or /u cantpress)§r"); //2015.08.09. + } + else + p.sendMessage("§9Are you Reddit user "+player.UserName+"?§r §6Type /u accept or /u ignore§r"); + } + + private static void AppendPlayerDisplayFlairFinal(Player player, String flair) + { //2015.07.20. + String color = GetColorForTown(GetPlayerTown(player)); //TO!DO: Multiple colors put on first capital letters + String[] colors = color.substring(1).split("§"); + String displayname=player.getName(); //2015.08.08. + ArrayList Positions=new ArrayList<>(); + for(int i=0; i=colors.length) + { + int x=0; + for(int i=0; i GetPlayers() + { + return Instance.getServer().getOnlinePlayers(); + } + + public static void LoadFiles(boolean reload) //<-- 2015.08.09. + { + System.out.println("Loading files for auto-flair plugin..."); + if(reload) + { + MaybeOfflinePlayer.AllPlayers.clear(); //2015.08.09. + } + try { + File file=new File("flairsaccepted.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + //System.out.println("Name: " + name); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("flairsignored.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsignored.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("autoflairconfig.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + TownColors.put(s[0], s[1]); + } + br.close(); + } + //throw new IOException("Test"); //2015.08.09. + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/94/602d1cd1873e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/94/602d1cd1873e00151ce8ff6d4f74dabd deleted file mode 100644 index 1ecfa95..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/94/602d1cd1873e00151ce8ff6d4f74dabd +++ /dev/null @@ -1,152 +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; - MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. - //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - if(p.Flair==null) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. - { - case "accept": - { - if(p.IgnoredFlair) - p.IgnoredFlair=false; //2015.08.08. - if(!p.AcceptedFlair) - { - String flair=p.Flair; //2015.08.08. - PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. - p.AcceptedFlair=true; //2015.08.08. - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("§cYou already have this user's flair.§r"); - break; - } - case "ignore": - { - if(p.AcceptedFlair) - p.AcceptedFlair=false; //2015.08.08. - if(!p.IgnoredFlair) - { - p.IgnoredFlair=true; - String flair=p.Flair; //2015.08.08. - PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. - player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); - } - else - player.sendMessage("§cYou already ignored this request.§r"); - break; - } - /*case "reload": //2015.07.20. - DoReload(player); - break;*/ - case "admin": //2015.08.09. - DoAdmin(player, args); - break; - default: - return false; - } - return true; - } - - /*if(args[0].toLowerCase()=="reload") - DoReload(null); //2015.07.20.*/ - else if(args[0].toLowerCase()=="admin") - DoAdmin(null, args); //2015.08.09. - return false; - } - private static void DoReload(Player player) - { //2015.07.20. - //if(player==null || player.isOp() || player.getName()=="NorbiPeti") - //{ - try - { - File file=new File("autoflairconfig.txt"); - if(file.exists()) - { - PluginMain.TownColors.clear(); - BufferedReader br=new BufferedReader(new FileReader(file)); - String line; - while((line=br.readLine())!=null) - { - String[] s=line.split(" "); - PluginMain.TownColors.put(s[0], s[1]); - } - br.close(); - for(Player p : PluginMain.GetPlayers()) - { - MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName()); - if(mp.Flair!=null) - { - String flair=mp.Flair; - PluginMain.RemovePlayerDisplayFlairFinal(p, flair); - PluginMain.AppendPlayerDisplayFlairFinal(p, flair); - } - } - String msg="§6Reloaded config file.§r"; - if(player!=null) - player.sendMessage(msg); - else - System.out.println(msg); - } - } - catch(Exception e) - { - System.out.println("Error!\n"+e); - if(player!=null) - player.sendMessage("§cAn error occured. See console for details.§r"); - } - //} - //else - //player.sendMessage("§cYou need to be OP to use this command.§r"); - } - private static void DoAdmin(Player player, String[] args) - { - if(player==null || player.isOp() || player.getName()=="NorbiPeti") - { - //args[0] is "admin" - switch(args[1].toLowerCase()) - { - case "reload": - DoReload(player); - break; - case "playerinfo": - DoPlayerInfo(player, args); - break; - } - } - else - player.sendMessage("§cYou need to be OP to use this command.§r"); - } - private static void DoPlayerInfo(Player player, String[] args) - { - //args[0] is "admin" - args[1] is "playerinfo" - if(args.length==args[2]) - { - String message="§cUsage: /u admin playerinfo §r"; - if(player==null) - System.out.println(message); - else - player.sendMessage(message); - } - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/95/605f63960d3e00151089cca86c5b1a99 b/.metadata/.plugins/org.eclipse.core.resources/.history/95/605f63960d3e00151089cca86c5b1a99 deleted file mode 100644 index 9aaee42..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/95/605f63960d3e00151089cca86c5b1a99 +++ /dev/null @@ -1,436 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import java.io.BufferedReader; -import java.io.BufferedWriter; -import java.io.File; -import java.io.FileReader; -import java.io.FileWriter; -import java.io.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/70d8d329853e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/95/70d8d329853e00151ce8ff6d4f74dabd deleted file mode 100644 index b0f40f6..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/95/70d8d329853e00151ce8ff6d4f74dabd +++ /dev/null @@ -1,127 +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; - MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. - //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - if(p.Flair==null) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. - { - case "accept": - { - if(p.IgnoredFlair) - p.IgnoredFlair=false; //2015.08.08. - if(!p.AcceptedFlair) - { - String flair=p.Flair; //2015.08.08. - PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. - p.AcceptedFlair=true; //2015.08.08. - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("§cYou already have this user's flair.§r"); - break; - } - case "ignore": - { - if(p.AcceptedFlair) - p.AcceptedFlair=false; //2015.08.08. - if(!p.IgnoredFlair) - { - p.IgnoredFlair=true; - String flair=p.Flair; //2015.08.08. - PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. - player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); - } - else - player.sendMessage("§cYou already ignored this request.§r"); - break; - } - case "reload": //2015.07.20. - DoReload(player); - break; - case "showerrors": //2015.08.09. - DoShowErrors(player); - break; - default: - return false; - } - return true; - } - - if(args[0].toLowerCase()=="reload") - DoReload(null); //2015.07.20. - else if(args[0].toLowerCase()=="showerrors") - DoShowErrors(null); //2015.08.09. - return false; - } - private static void DoReload(Player player) - { //2015.07.20. - if(player==null || player.isOp() || player.getName()=="NorbiPeti") - { - try - { - File file=new File("autoflairconfig.txt"); - if(file.exists()) - { - PluginMain.TownColors.clear(); - BufferedReader br=new BufferedReader(new FileReader(file)); - String line; - while((line=br.readLine())!=null) - { - String[] s=line.split(" "); - PluginMain.TownColors.put(s[0], s[1]); - } - br.close(); - for(Player p : PluginMain.GetPlayers()) - { - MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName()); - if(mp.Flair!=null) - { - String flair=mp.Flair; - PluginMain.RemovePlayerDisplayFlairFinal(p, flair); - PluginMain.AppendPlayerDisplayFlairFinal(p, flair); - } - } - String msg="§6Reloaded config file.§r"; - if(player!=null) - player.sendMessage(msg); - else - System.out.println(msg); - } - } - catch(Exception e) - { - System.out.println("Error!\n"+e); - if(player!=null) - player.sendMessage("§cAn error occured. See console for details.§r"); - } - } - else - player.sendMessage("§cYou need to be OP to use this command.§r"); - } - private static void DoShowErrors(Player player) - { - if(player==null || player.isOp() || player.getName()=="NorbiPeti") - { - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/96/20ba5e09d43e001518fa86d7ae2a1cf8 b/.metadata/.plugins/org.eclipse.core.resources/.history/96/20ba5e09d43e001518fa86d7ae2a1cf8 new file mode 100644 index 0000000..6a40e1a --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/96/20ba5e09d43e001518fa86d7ae2a1cf8 @@ -0,0 +1,219 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; + +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class Commands implements CommandExecutor { + // This method is called, when somebody uses our command + @Override + public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { + if (sender instanceof Player) { + Player player = (Player) sender; + if(args.length<1) + return false; + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. + //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) + if(p.Flair==null) + { + player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); + return true; + } + switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. + { + case "accept": + { + if(p.IgnoredFlair) + p.IgnoredFlair=false; //2015.08.08. + if(!p.AcceptedFlair) + { + String flair=p.Flair; //2015.08.08. + //PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + PluginMain.AppendPlayerDisplayFlair(p, player); + p.AcceptedFlair=true; //2015.08.08. + player.sendMessage("§6Your flair has been set:§r "+flair); + } + else + player.sendMessage("§cYou already have this user's flair.§r"); + break; + } + case "ignore": + { + if(p.AcceptedFlair) + p.AcceptedFlair=false; //2015.08.08. + if(!p.IgnoredFlair) + { + p.IgnoredFlair=true; + String flair=p.Flair; //2015.08.08. + PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. + player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); + } + else + player.sendMessage("§cYou already ignored this request.§r"); + break; + } + /*case "reload": //2015.07.20. + DoReload(player); + break;*/ + case "admin": //2015.08.09. + DoAdmin(player, args); + break; + case "nonpresser": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§7(non-pr.)§r"; + break; + case "cantpress": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§r(can't press)§r"; + break; + default: + return false; + } + return true; + } + /*if(args[0].toLowerCase()=="reload") + DoReload(null); //2015.07.20.*/ + else if(args.length>0 && args[0].toLowerCase().equals("admin")) //2015.08.09. + { + DoAdmin(null, args); //2015.08.09. + return true; //2015.08.09. + } + return false; + } + private static void DoReload(Player player) + { //2015.07.20. + //if(player==null || player.isOp() || player.getName()=="NorbiPeti") + //{ + try + { + File file=new File("autoflairconfig.txt"); + if(file.exists()) + { + PluginMain.LoadFiles(true); //2015.08.09. + for(Player p : PluginMain.GetPlayers()) + { + MaybeOfflinePlayer mp = MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName()); + if(mp.Flair!=null) + { + String flair=mp.Flair; + PluginMain.RemovePlayerDisplayFlairFinal(p, flair); + //PluginMain.AppendPlayerDisplayFlairFinal(p, flair); + PluginMain.AppendPlayerDisplayFlair(mp, p); //2015.08.09. + } + String msg="§6Note: The auto-flair plugin has been reloaded. You might need to wait 10s to have your flair.§r"; //2015.08.09. + p.sendMessage(msg); //2015.08.09. + } + //String msg="§6Reloaded config file.§r"; + //SendMessage(player, msg); //2015.08.09. + } + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + if(player!=null) + player.sendMessage("§cAn error occured. See console for details.§r"); + PluginMain.LastException=e; //2015.08.09. + } + //} + //else + //player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static void DoAdmin(Player player, String[] args) + { //2015.08.09. + if(player==null || player.isOp() || player.getName()=="NorbiPeti") + { + //System.out.println("Args length: " + args.length); + if(args.length==1) + { + String message="§cUsage: /u admin reload|playerinfo§r"; + SendMessage(player, message); + return; + } + //args[0] is "admin" + switch(args[1].toLowerCase()) + { + case "reload": + SendMessage(player, "§6Make sure to save the current settings before you modify and reload them! Type /u admin confirm when done."); + break; + case "playerinfo": + DoPlayerInfo(player, args); + break; + case "getlasterror": + DoGetLastError(player, args); + case "confirm": + DoReload(player); //2015.08.09. + break; + default: + String message="§cUsage: /u admin reload|playerinfo§r"; + SendMessage(player, message); + return; + } + } + else + player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static void DoPlayerInfo(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "playerinfo" + if(args.length==2) + { + String message="§cUsage: /u admin playerinfo §r"; + SendMessage(player, message); + return; + } + if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2])) + { + String message="§cPlayer not found: "+args[2]+"§r"; + SendMessage(player, message); + return; + } + MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]); + SendMessage(player, "Player name: "+p.PlayerName); + SendMessage(player, "User flair: "+p.Flair); + SendMessage(player, "Username: "+p.UserName); + SendMessage(player, "Flair accepted: "+p.AcceptedFlair); + SendMessage(player, "Flair ignored: "+p.IgnoredFlair); + } + private static void SendMessage(Player player, String message) + { //2015.08.09. + if(player==null) + System.out.println(message); + else + player.sendMessage(message); + } + private static void DoGetLastError(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "getlasterror" + if(PluginMain.LastException!=null) + { + SendMessage(player, "Last error:"); + SendMessage(player, PluginMain.LastException.toString()); + PluginMain.LastException=null; + } + else + SendMessage(player, "There were no exceptions."); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/96/90d42e62e43e001517108d149b613203 b/.metadata/.plugins/org.eclipse.core.resources/.history/96/90d42e62e43e001517108d149b613203 new file mode 100644 index 0000000..e7b6525 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/96/90d42e62e43e001517108d149b613203 @@ -0,0 +1,265 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +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; + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. + //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) + if(p.Flair==null) + { + player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); + return true; + } + switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. + { + case "accept": + { + if(p.IgnoredFlair) + p.IgnoredFlair=false; //2015.08.08. + if(!p.AcceptedFlair) + { + String flair=p.Flair; //2015.08.08. + //PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + PluginMain.AppendPlayerDisplayFlair(p, player); + p.AcceptedFlair=true; //2015.08.08. + player.sendMessage("§6Your flair has been set:§r "+flair); + } + else + player.sendMessage("§cYou already have this user's flair.§r"); + break; + } + case "ignore": + { + if(p.AcceptedFlair) + p.AcceptedFlair=false; //2015.08.08. + if(!p.IgnoredFlair) + { + p.IgnoredFlair=true; + String flair=p.Flair; //2015.08.08. + //PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. + player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); + } + else + player.sendMessage("§cYou already ignored this request.§r"); + break; + } + /*case "reload": //2015.07.20. + DoReload(player); + break;*/ + case "admin": //2015.08.09. + DoAdmin(player, args); + break; + case "nonpresser": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§7(non-pr.)§r"; + break; + case "cantpress": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§r(can't press)§r"; + break; + default: + return false; + } + return true; + } + /*if(args[0].toLowerCase()=="reload") + DoReload(null); //2015.07.20.*/ + else if(args.length>0 && args[0].toLowerCase().equals("admin")) //2015.08.09. + { + DoAdmin(null, args); //2015.08.09. + return true; //2015.08.09. + } + return false; + } + private static void DoReload(Player player) + { //2015.07.20. + //if(player==null || player.isOp() || player.getName()=="NorbiPeti") + //{ + try + { + File file=new File("autoflairconfig.txt"); + if(file.exists()) + { + PluginMain.LoadFiles(true); //2015.08.09. + for(Player p : PluginMain.GetPlayers()) + { + MaybeOfflinePlayer mp = MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName()); + if(mp.Flair!=null) + { + String flair=mp.Flair; + //PluginMain.RemovePlayerDisplayFlairFinal(p, flair); + //PluginMain.AppendPlayerDisplayFlairFinal(p, flair); + PluginMain.AppendPlayerDisplayFlair(mp, p); //2015.08.09. + } + String msg="§6Note: The auto-flair plugin has been reloaded. You might need to wait 10s to have your flair.§r"; //2015.08.09. + p.sendMessage(msg); //2015.08.09. + } + //String msg="§6Reloaded config file.§r"; + //SendMessage(player, msg); //2015.08.09. + } + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + if(player!=null) + player.sendMessage("§cAn error occured. See console for details.§r"); + PluginMain.LastException=e; //2015.08.09. + } + //} + //else + //player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static Player ReloadPlayer; //2015.08.09. + private static void DoAdmin(Player player, String[] args) + { //2015.08.09. + if(player==null || player.isOp() || player.getName()=="NorbiPeti") + { + //System.out.println("Args length: " + args.length); + if(args.length==1) + { + String message="§cUsage: /u admin reload|playerinfo§r"; + SendMessage(player, message); + return; + } + //args[0] is "admin" + switch(args[1].toLowerCase()) + { + case "reload": + ReloadPlayer=player; //2015.08.09. + SendMessage(player, "§6Make sure to save the current settings before you modify and reload them! Type /u admin confirm when done.§r"); + break; + case "playerinfo": + DoPlayerInfo(player, args); + break; + case "getlasterror": + DoGetLastError(player, args); + case "confirm": + if(ReloadPlayer==player) + DoReload(player); //2015.08.09. + else + SendMessage(player, "§cYou need to do /u admin reload first.§r"); + break; + case "save": + PluginMain.SaveFiles(); //2015.08.09. + SendMessage(player, "§6Saved files. Now you can edit them and reload if you want.§r"); + break; + case "setflair": + DoSetFlair(player, args); + break; + default: + String message="§cUsage: /u admin reload|playerinfo|getlasterror|save|setflair§r"; + SendMessage(player, message); + return; + } + } + else + player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static void DoPlayerInfo(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "playerinfo" + if(args.length==2) + { + String message="§cUsage: /u admin playerinfo §r"; + SendMessage(player, message); + return; + } + if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2])) + { + String message="§cPlayer not found: "+args[2]+"§r"; + SendMessage(player, message); + return; + } + MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]); + SendMessage(player, "Player name: "+p.PlayerName); + SendMessage(player, "User flair: "+p.Flair); + SendMessage(player, "Username: "+p.UserName); + SendMessage(player, "Flair accepted: "+p.AcceptedFlair); + SendMessage(player, "Flair ignored: "+p.IgnoredFlair); + } + private static void SendMessage(Player player, String message) + { //2015.08.09. + if(player==null) + System.out.println(message); + else + player.sendMessage(message); + } + private static void DoGetLastError(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "getlasterror" + if(PluginMain.LastException!=null) + { + SendMessage(player, "Last error:"); + SendMessage(player, PluginMain.LastException.toString()); + PluginMain.LastException=null; + } + else + SendMessage(player, "There were no exceptions."); + } + private static void SetPlayerFlair(Player player, MaybeOfflinePlayer targetplayer, String flair) + { //2015.08.09. + flair=flair.replace('&', '§'); + targetplayer.Flair=flair; + if(!PluginMain.RemoveLineFromFile("customflairs.txt", targetplayer.PlayerName)) + { + SendMessage(player, "§cError removing previous custom flair!§r"); + return; + } + File file=new File("customflairs.txt"); + try { + BufferedWriter bw; + bw = new BufferedWriter(new FileWriter(file, true)); + bw.write(targetplayer.PlayerName+"\n"); + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + PluginMain.LastException=e; //2015.08.09. + } + SendMessage(player, "§6The flair has been set. Player: "+targetplayer.PlayerName+" Flair: "+flair+"§r"); + } + private static void DoSetFlair(Player player, String[] args) + { + //args[0] is "admin" - args[1] is "setflair" + if(args.length<4) + { + SendMessage(player, "§cUsage: /u admin setflair "); + return; + } + SetPlayerFlair(player, MaybeOfflinePlayer.AddPlayerIfNeeded(args[2]), args[3]); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/97/20ad60e0d03e001518fa86d7ae2a1cf8 b/.metadata/.plugins/org.eclipse.core.resources/.history/97/20ad60e0d03e001518fa86d7ae2a1cf8 new file mode 100644 index 0000000..4c2bf02 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/97/20ad60e0d03e001518fa86d7ae2a1cf8 @@ -0,0 +1,211 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; + +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class Commands implements CommandExecutor { + // This method is called, when somebody uses our command + @Override + public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { + if (sender instanceof Player) { + Player player = (Player) sender; + if(args.length<1) + return false; + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. + //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) + if(p.Flair==null) + { + player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); + return true; + } + switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. + { + case "accept": + { + if(p.IgnoredFlair) + p.IgnoredFlair=false; //2015.08.08. + if(!p.AcceptedFlair) + { + String flair=p.Flair; //2015.08.08. + //PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + PluginMain.AppendPlayerDisplayFlair(p, player); + p.AcceptedFlair=true; //2015.08.08. + player.sendMessage("§6Your flair has been set:§r "+flair); + } + else + player.sendMessage("§cYou already have this user's flair.§r"); + break; + } + case "ignore": + { + if(p.AcceptedFlair) + p.AcceptedFlair=false; //2015.08.08. + if(!p.IgnoredFlair) + { + p.IgnoredFlair=true; + String flair=p.Flair; //2015.08.08. + PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. + player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); + } + else + player.sendMessage("§cYou already ignored this request.§r"); + break; + } + /*case "reload": //2015.07.20. + DoReload(player); + break;*/ + case "admin": //2015.08.09. + DoAdmin(player, args); + break; + case "nonpresser": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="" + break; + case "cantpress": //2015.08.09. + break; + default: + return false; + } + return true; + } + /*if(args[0].toLowerCase()=="reload") + DoReload(null); //2015.07.20.*/ + else if(args.length>0 && args[0].toLowerCase().equals("admin")) //2015.08.09. + { + DoAdmin(null, args); //2015.08.09. + return true; //2015.08.09. + } + return false; + } + private static void DoReload(Player player) + { //2015.07.20. + //if(player==null || player.isOp() || player.getName()=="NorbiPeti") + //{ + try + { + File file=new File("autoflairconfig.txt"); + if(file.exists()) + { + PluginMain.TownColors.clear(); + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + PluginMain.TownColors.put(s[0], s[1]); + } + br.close(); + for(Player p : PluginMain.GetPlayers()) + { + MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName()); + if(mp.Flair!=null) + { + String flair=mp.Flair; + PluginMain.RemovePlayerDisplayFlairFinal(p, flair); + //PluginMain.AppendPlayerDisplayFlairFinal(p, flair); + PluginMain.AppendPlayerDisplayFlair(mp, p); //2015.08.09. + } + } + String msg="§6Reloaded config file.§r"; + SendMessage(player, msg); //2015.08.09. + } + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + if(player!=null) + player.sendMessage("§cAn error occured. See console for details.§r"); + PluginMain.LastException=e; //2015.08.09. + } + //} + //else + //player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static void DoAdmin(Player player, String[] args) + { //2015.08.09. + if(player==null || player.isOp() || player.getName()=="NorbiPeti") + { + //System.out.println("Args length: " + args.length); + if(args.length==1) + { + String message="§cUsage: /u admin reload|playerinfo§r"; + SendMessage(player, message); + return; + } + //args[0] is "admin" + switch(args[1].toLowerCase()) + { + case "reload": + DoReload(player); + break; + case "playerinfo": + DoPlayerInfo(player, args); + break; + case "getlasterror": + DoGetLastError(player, args); + default: + String message="§cUsage: /u admin reload|playerinfo§r"; + SendMessage(player, message); + return; + } + } + else + player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static void DoPlayerInfo(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "playerinfo" + if(args.length==2) + { + String message="§cUsage: /u admin playerinfo §r"; + SendMessage(player, message); + return; + } + if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2])) + { + String message="§cPlayer not found: "+args[2]+"§r"; + SendMessage(player, message); + return; + } + MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]); + SendMessage(player, "Player name: "+p.PlayerName); + SendMessage(player, "User flair: "+p.Flair); + SendMessage(player, "Username: "+p.UserName); + SendMessage(player, "Flair accepted: "+p.AcceptedFlair); + SendMessage(player, "Flair ignored: "+p.IgnoredFlair); + } + private static void SendMessage(Player player, String message) + { //2015.08.09. + if(player==null) + System.out.println(message); + else + player.sendMessage(message); + } + private static void DoGetLastError(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "getlasterror" + if(PluginMain.LastException!=null) + { + SendMessage(player, "Last error:"); + SendMessage(player, PluginMain.LastException.toString()); + PluginMain.LastException=null; + } + else + SendMessage(player, "There were no exceptions."); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/97/8035b5d5df3e001517108d149b613203 b/.metadata/.plugins/org.eclipse.core.resources/.history/97/8035b5d5df3e001517108d149b613203 new file mode 100644 index 0000000..2377b00 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/97/8035b5d5df3e001517108d149b613203 @@ -0,0 +1,253 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +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; + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. + //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) + if(p.Flair==null) + { + player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); + return true; + } + switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. + { + case "accept": + { + if(p.IgnoredFlair) + p.IgnoredFlair=false; //2015.08.08. + if(!p.AcceptedFlair) + { + String flair=p.Flair; //2015.08.08. + //PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + PluginMain.AppendPlayerDisplayFlair(p, player); + p.AcceptedFlair=true; //2015.08.08. + player.sendMessage("§6Your flair has been set:§r "+flair); + } + else + player.sendMessage("§cYou already have this user's flair.§r"); + break; + } + case "ignore": + { + if(p.AcceptedFlair) + p.AcceptedFlair=false; //2015.08.08. + if(!p.IgnoredFlair) + { + p.IgnoredFlair=true; + String flair=p.Flair; //2015.08.08. + PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. + player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); + } + else + player.sendMessage("§cYou already ignored this request.§r"); + break; + } + /*case "reload": //2015.07.20. + DoReload(player); + break;*/ + case "admin": //2015.08.09. + DoAdmin(player, args); + break; + case "nonpresser": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§7(non-pr.)§r"; + break; + case "cantpress": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§r(can't press)§r"; + break; + default: + return false; + } + return true; + } + /*if(args[0].toLowerCase()=="reload") + DoReload(null); //2015.07.20.*/ + else if(args.length>0 && args[0].toLowerCase().equals("admin")) //2015.08.09. + { + DoAdmin(null, args); //2015.08.09. + return true; //2015.08.09. + } + return false; + } + private static void DoReload(Player player) + { //2015.07.20. + //if(player==null || player.isOp() || player.getName()=="NorbiPeti") + //{ + try + { + File file=new File("autoflairconfig.txt"); + if(file.exists()) + { + PluginMain.LoadFiles(true); //2015.08.09. + for(Player p : PluginMain.GetPlayers()) + { + MaybeOfflinePlayer mp = MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName()); + if(mp.Flair!=null) + { + String flair=mp.Flair; + PluginMain.RemovePlayerDisplayFlairFinal(p, flair); + //PluginMain.AppendPlayerDisplayFlairFinal(p, flair); + PluginMain.AppendPlayerDisplayFlair(mp, p); //2015.08.09. + } + String msg="§6Note: The auto-flair plugin has been reloaded. You might need to wait 10s to have your flair.§r"; //2015.08.09. + p.sendMessage(msg); //2015.08.09. + } + //String msg="§6Reloaded config file.§r"; + //SendMessage(player, msg); //2015.08.09. + } + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + if(player!=null) + player.sendMessage("§cAn error occured. See console for details.§r"); + PluginMain.LastException=e; //2015.08.09. + } + //} + //else + //player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static Player ReloadPlayer; //2015.08.09. + private static void DoAdmin(Player player, String[] args) + { //2015.08.09. + if(player==null || player.isOp() || player.getName()=="NorbiPeti") + { + //System.out.println("Args length: " + args.length); + if(args.length==1) + { + String message="§cUsage: /u admin reload|playerinfo§r"; + SendMessage(player, message); + return; + } + //args[0] is "admin" + switch(args[1].toLowerCase()) + { + case "reload": + ReloadPlayer=player; //2015.08.09. + SendMessage(player, "§6Make sure to save the current settings before you modify and reload them! Type /u admin confirm when done.§r"); + break; + case "playerinfo": + DoPlayerInfo(player, args); + break; + case "getlasterror": + DoGetLastError(player, args); + case "confirm": + if(ReloadPlayer==player) + DoReload(player); //2015.08.09. + else + SendMessage(player, "§cYou need to do /u admin reload first.§r"); + break; + case "save": + PluginMain.SaveFiles(); //2015.08.09. + SendMessage(player, "§6Saved files. Now you can edit them and reload if you want.§r"); + break; + case " + default: + String message="§cUsage: /u admin reload|playerinfo|getlasterror|save§r"; + SendMessage(player, message); + return; + } + } + else + player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static void DoPlayerInfo(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "playerinfo" + if(args.length==2) + { + String message="§cUsage: /u admin playerinfo §r"; + SendMessage(player, message); + return; + } + if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2])) + { + String message="§cPlayer not found: "+args[2]+"§r"; + SendMessage(player, message); + return; + } + MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]); + SendMessage(player, "Player name: "+p.PlayerName); + SendMessage(player, "User flair: "+p.Flair); + SendMessage(player, "Username: "+p.UserName); + SendMessage(player, "Flair accepted: "+p.AcceptedFlair); + SendMessage(player, "Flair ignored: "+p.IgnoredFlair); + } + private static void SendMessage(Player player, String message) + { //2015.08.09. + if(player==null) + System.out.println(message); + else + player.sendMessage(message); + } + private static void DoGetLastError(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "getlasterror" + if(PluginMain.LastException!=null) + { + SendMessage(player, "Last error:"); + SendMessage(player, PluginMain.LastException.toString()); + PluginMain.LastException=null; + } + else + SendMessage(player, "There were no exceptions."); + } + private static void SetPlayerFlair(Player player, Player targetplayer, String flair) + { //2015.08.09. + flair=flair.replace('&', '§'); + MaybeOfflinePlayer.AddPlayerIfNeeded(player.getName()).Flair=flair; + if(!PluginMain.RemoveLineFromFile("customflairs.txt", targetplayer.getName())) + { + SendMessage(player, "§cError removing previous custom flair!§r"); + return; + } + File file=new File("customflairs.txt"); + try { + BufferedWriter bw; + bw = new BufferedWriter(new FileWriter(file, true)); + bw.write(targetplayer.getName()+"\n"); + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + PluginMain.LastException=e; //2015.08.09. + } + SendMessage(player, "§6The flair has been set. Player: "+targetplayer.getName()+" Flair: "+flair+"§r"); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/97/a0aae0bdd23e001518fa86d7ae2a1cf8 b/.metadata/.plugins/org.eclipse.core.resources/.history/97/a0aae0bdd23e001518fa86d7ae2a1cf8 new file mode 100644 index 0000000..229de7d --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/97/a0aae0bdd23e001518fa86d7ae2a1cf8 @@ -0,0 +1,223 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; + +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class Commands implements CommandExecutor { + // This method is called, when somebody uses our command + @Override + public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { + if (sender instanceof Player) { + Player player = (Player) sender; + if(args.length<1) + return false; + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. + //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) + if(p.Flair==null) + { + player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); + return true; + } + switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. + { + case "accept": + { + if(p.IgnoredFlair) + p.IgnoredFlair=false; //2015.08.08. + if(!p.AcceptedFlair) + { + String flair=p.Flair; //2015.08.08. + //PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + PluginMain.AppendPlayerDisplayFlair(p, player); + p.AcceptedFlair=true; //2015.08.08. + player.sendMessage("§6Your flair has been set:§r "+flair); + } + else + player.sendMessage("§cYou already have this user's flair.§r"); + break; + } + case "ignore": + { + if(p.AcceptedFlair) + p.AcceptedFlair=false; //2015.08.08. + if(!p.IgnoredFlair) + { + p.IgnoredFlair=true; + String flair=p.Flair; //2015.08.08. + PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. + player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); + } + else + player.sendMessage("§cYou already ignored this request.§r"); + break; + } + /*case "reload": //2015.07.20. + DoReload(player); + break;*/ + case "admin": //2015.08.09. + DoAdmin(player, args); + break; + case "nonpresser": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§7(non-pr.)§r"; + break; + case "cantpress": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§r(can't press)§r"; + break; + default: + return false; + } + return true; + } + /*if(args[0].toLowerCase()=="reload") + DoReload(null); //2015.07.20.*/ + else if(args.length>0 && args[0].toLowerCase().equals("admin")) //2015.08.09. + { + DoAdmin(null, args); //2015.08.09. + return true; //2015.08.09. + } + return false; + } + private static void DoReload(Player player) + { //2015.07.20. + //if(player==null || player.isOp() || player.getName()=="NorbiPeti") + //{ + try + { + File file=new File("autoflairconfig.txt"); + if(file.exists()) + { + PluginMain.TownColors.clear(); + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + PluginMain.TownColors.put(s[0], s[1]); + } + br.close(); + for(Player p : PluginMain.GetPlayers()) + { + MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName()); + if(mp.Flair!=null) + { + String flair=mp.Flair; + PluginMain.RemovePlayerDisplayFlairFinal(p, flair); + //PluginMain.AppendPlayerDisplayFlairFinal(p, flair); + PluginMain.AppendPlayerDisplayFlair(mp, p); //2015.08.09. + } + } + //String msg="§6Reloaded config file.§r"; + String msg="§6Reloaded all files.§r"; + SendMessage(player, msg); //2015.08.09. + } + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + if(player!=null) + player.sendMessage("§cAn error occured. See console for details.§r"); + PluginMain.LastException=e; //2015.08.09. + } + //} + //else + //player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static void DoAdmin(Player player, String[] args) + { //2015.08.09. + if(player==null || player.isOp() || player.getName()=="NorbiPeti") + { + //System.out.println("Args length: " + args.length); + if(args.length==1) + { + String message="§cUsage: /u admin reload|playerinfo§r"; + SendMessage(player, message); + return; + } + //args[0] is "admin" + switch(args[1].toLowerCase()) + { + case "reload": + DoReload(player); + break; + case "playerinfo": + DoPlayerInfo(player, args); + break; + case "getlasterror": + DoGetLastError(player, args); + default: + String message="§cUsage: /u admin reload|playerinfo§r"; + SendMessage(player, message); + return; + } + } + else + player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static void DoPlayerInfo(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "playerinfo" + if(args.length==2) + { + String message="§cUsage: /u admin playerinfo §r"; + SendMessage(player, message); + return; + } + if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2])) + { + String message="§cPlayer not found: "+args[2]+"§r"; + SendMessage(player, message); + return; + } + MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]); + SendMessage(player, "Player name: "+p.PlayerName); + SendMessage(player, "User flair: "+p.Flair); + SendMessage(player, "Username: "+p.UserName); + SendMessage(player, "Flair accepted: "+p.AcceptedFlair); + SendMessage(player, "Flair ignored: "+p.IgnoredFlair); + } + private static void SendMessage(Player player, String message) + { //2015.08.09. + if(player==null) + System.out.println(message); + else + player.sendMessage(message); + } + private static void DoGetLastError(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "getlasterror" + if(PluginMain.LastException!=null) + { + SendMessage(player, "Last error:"); + SendMessage(player, PluginMain.LastException.toString()); + PluginMain.LastException=null; + } + else + SendMessage(player, "There were no exceptions."); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/97/c0e2ad6fce3e001518fa86d7ae2a1cf8 b/.metadata/.plugins/org.eclipse.core.resources/.history/97/c0e2ad6fce3e001518fa86d7ae2a1cf8 new file mode 100644 index 0000000..28be51a --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/97/c0e2ad6fce3e001518fa86d7ae2a1cf8 @@ -0,0 +1,357 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStream; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLConnection; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + +import org.apache.commons.io.IOUtils; +import org.bukkit.entity.Player; +import org.bukkit.plugin.java.JavaPlugin; +import org.json.JSONArray; +import org.json.JSONObject; + +import tk.sznp.thebuttonautoflair.MaybeOfflinePlayer.FlairClassType; + +import com.palmergames.bukkit.towny.object.Town; +import com.palmergames.bukkit.towny.object.WorldCoord; + +public class PluginMain extends JavaPlugin +{ //Translated to Java: 2015.07.15. + //A user, which flair isn't obtainable: + //https://www.reddit.com/r/thebutton/comments/31c32v/i_pressed_the_button_without_really_thinking/ + private static PluginMain Instance; + // Fired when plugin is first enabled + @Override + public void onEnable() + { + System.out.println("The Button Auto-flair Plugin by NorbiPeti (:P)"); + getServer().getPluginManager().registerEvents(new PlayerListener(), this); + this.getCommand("u").setExecutor(new Commands()); + this.getCommand("u").setUsage(this.getCommand("u").getUsage().replace('&', '§')); + Instance=this; //2015.08.08. + try { + File file=new File("flairsaccepted.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + //System.out.println("Name: " + name); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("flairsignored.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsignored.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("autoflairconfig.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + TownColors.put(s[0], s[1]); + } + br.close(); + } + //throw new IOException("Test"); //2015.08.09. + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + Runnable r=new Runnable(){public void run(){ThreadMethod();}}; + Thread t=new Thread(r); + t.start(); + } + Boolean stop=false; + // Fired when plugin is disabled + @Override + public void onDisable() + { + try + { + FileWriter fw; + fw = new FileWriter("flairsaccepted.txt"); + fw.close(); + fw = new FileWriter("flairsignored.txt"); + fw.close(); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + try { + File file=new File("flairsaccepted.txt"); + BufferedWriter bw=new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.AcceptedFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + file=new File("flairsignored.txt"); + bw = new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.IgnoredFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + stop=true; + } + + public void ThreadMethod() //<-- 2015.07.16. + { + while(!stop) + { + try + { + String body=DownloadString("https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/autoflair_system_comment_your_minecraft_name_and/.json?limit=1000"); + JSONArray json=new JSONArray(body).getJSONObject(1).getJSONObject("data").getJSONArray("children"); + for(Object obj : json) + { + JSONObject item = (JSONObject)obj; + String author=item.getJSONObject("data").getString("author"); + String ign=item.getJSONObject("data").getString("body"); + int start = ign.indexOf("IGN:") + "IGN:".length(); + int end = ign.indexOf(' ', start); + if (end == -1 || end == start) + end=ign.indexOf('\n', start); //2015.07.15. + if (end == -1 || end == start) + ign = ign.substring(start); + else + ign = ign.substring(start, end); + ign = ign.trim(); + if(HasIGFlair(ign)) + continue; + try { + Thread.sleep(10); + } catch(InterruptedException ex) { + Thread.currentThread().interrupt(); + } + String[] flairdata = DownloadString("http://karmadecay.com/thebutton-data.php?users=" + author).replace("\"", "").split(":"); + String flair; + if(flairdata.length > 1) //2015.07.15. + flair = flairdata[1]; + else + flair=""; + if (flair != "-1") + flair = flair + "s"; + else + flair = "non-presser"; + String flairclass; + if(flairdata.length>2) + flairclass = flairdata[2]; + else + flairclass="unknown"; + SetFlair(ign, flair, flairclass, author); + } + Thread.sleep(10000); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + } + + public static Exception LastException; //2015.08.09. + + public String DownloadString(String urlstr) throws MalformedURLException, IOException + { + URL url = new URL(urlstr); + URLConnection con = url.openConnection(); + con.setRequestProperty("User-Agent", "TheButtonAutoFlair"); + InputStream in = con.getInputStream(); + String encoding = con.getContentEncoding(); + encoding = encoding == null ? "UTF-8" : encoding; + String body = IOUtils.toString(in, encoding); + in.close(); + return body; + } + + public static Map TownColors=new HashMap(); //2015.07.20. + public Boolean HasIGFlair(String playername) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + return p.Flair!=null; //2015.08.08. + } + + public void SetFlair(String playername, String text, String flairclass, String username) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + String finalflair; + switch(flairclass) + { + case "press-1": + finalflair="§c("+text+")§r"; + break; + case "press-2": + finalflair="§6("+text+")§r"; + break; + case "press-3": + finalflair="§e("+text+")§r"; + break; + case "press-4": + finalflair="§a("+text+")§r"; + break; + case "press-5": + finalflair="§9("+text+")§r"; + break; + 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; + case "undecided": //2015.08.09. + p.FlairType=FlairClassType.Undecided; + finalflair=""; + break; + default: + finalflair=""; + break; + } + if(finalflair.length()==0) //<-- 2015.07.20. + return; + p.Flair=finalflair; //2015.08.08. + p.UserName=username; //2015.08.08. + System.out.println("Added new flair to "+playername+": "+finalflair); + for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08. + { + if(player.getName().equals(playername)) + { + AppendPlayerDisplayFlair(player, username, finalflair); + break; + } + } + } + + public static String GetFlair(Player player) + { //2015.07.16. + String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08. + return flair==null ? "" : flair; + } + + public static void AppendPlayerDisplayFlair(Player player, String username, String flair) + { + if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).IgnoredFlair) + return; + if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).AcceptedFlair) + AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + else + player.sendMessage("§9Are you Reddit user "+username+"?§r §6Type /u accept or /u ignore§r"); + } + + public static void AppendPlayerDisplayFlairFinal(Player player, String flair) + { //2015.07.20. + String color = GetColorForTown(GetPlayerTown(player)); //TO!DO: Multiple colors put on first capital letters + String[] colors = color.substring(1).split("§"); + String displayname=player.getName(); //2015.08.08. + ArrayList Positions=new ArrayList<>(); + for(int i=0; i=colors.length) + { + int x=0; + for(int i=0; i GetPlayers() + { + return Instance.getServer().getOnlinePlayers(); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/98/201af098d03e001518fa86d7ae2a1cf8 b/.metadata/.plugins/org.eclipse.core.resources/.history/98/201af098d03e001518fa86d7ae2a1cf8 new file mode 100644 index 0000000..f7dee03 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/98/201af098d03e001518fa86d7ae2a1cf8 @@ -0,0 +1,205 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; + +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class Commands implements CommandExecutor { + // This method is called, when somebody uses our command + @Override + public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { + if (sender instanceof Player) { + Player player = (Player) sender; + if(args.length<1) + return false; + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. + //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) + if(p.Flair==null) + { + player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); + return true; + } + switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. + { + case "accept": + { + if(p.IgnoredFlair) + p.IgnoredFlair=false; //2015.08.08. + if(!p.AcceptedFlair) + { + String flair=p.Flair; //2015.08.08. + //PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + PluginMain.AppendPlayerDisplayFlair(p, player); + p.AcceptedFlair=true; //2015.08.08. + player.sendMessage("§6Your flair has been set:§r "+flair); + } + else + player.sendMessage("§cYou already have this user's flair.§r"); + break; + } + case "ignore": + { + if(p.AcceptedFlair) + p.AcceptedFlair=false; //2015.08.08. + if(!p.IgnoredFlair) + { + p.IgnoredFlair=true; + String flair=p.Flair; //2015.08.08. + PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. + player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); + } + else + player.sendMessage("§cYou already ignored this request.§r"); + break; + } + /*case "reload": //2015.07.20. + DoReload(player); + break;*/ + case "admin": //2015.08.09. + DoAdmin(player, args); + break; + case "nonpresser": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + break; + case "cantpress": //2015.08.09. + break; + default: + return false; + } + return true; + } + /*if(args[0].toLowerCase()=="reload") + DoReload(null); //2015.07.20.*/ + else if(args.length>0 && args[0].toLowerCase().equals("admin")) //2015.08.09. + { + DoAdmin(null, args); //2015.08.09. + return true; //2015.08.09. + } + return false; + } + private static void DoReload(Player player) + { //2015.07.20. + //if(player==null || player.isOp() || player.getName()=="NorbiPeti") + //{ + try + { + File file=new File("autoflairconfig.txt"); + if(file.exists()) + { + PluginMain.TownColors.clear(); + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + PluginMain.TownColors.put(s[0], s[1]); + } + br.close(); + for(Player p : PluginMain.GetPlayers()) + { + MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName()); + if(mp.Flair!=null) + { + String flair=mp.Flair; + PluginMain.RemovePlayerDisplayFlairFinal(p, flair); + //PluginMain.AppendPlayerDisplayFlairFinal(p, flair); + PluginMain.AppendPlayerDisplayFlair(mp, p); //2015.08.09. + } + } + String msg="§6Reloaded config file.§r"; + SendMessage(player, msg); //2015.08.09. + } + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + if(player!=null) + player.sendMessage("§cAn error occured. See console for details.§r"); + PluginMain.LastException=e; //2015.08.09. + } + //} + //else + //player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static void DoAdmin(Player player, String[] args) + { //2015.08.09. + if(player==null || player.isOp() || player.getName()=="NorbiPeti") + { + //System.out.println("Args length: " + args.length); + if(args.length==1) + { + String message="§cUsage: /u admin reload|playerinfo§r"; + SendMessage(player, message); + return; + } + //args[0] is "admin" + switch(args[1].toLowerCase()) + { + case "reload": + DoReload(player); + break; + case "playerinfo": + DoPlayerInfo(player, args); + break; + case "getlasterror": + DoGetLastError(player, args); + default: + String message="§cUsage: /u admin reload|playerinfo§r"; + SendMessage(player, message); + return; + } + } + else + player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static void DoPlayerInfo(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "playerinfo" + if(args.length==2) + { + String message="§cUsage: /u admin playerinfo §r"; + SendMessage(player, message); + return; + } + if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2])) + { + String message="§cPlayer not found: "+args[2]+"§r"; + SendMessage(player, message); + return; + } + MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]); + SendMessage(player, "Player name: "+p.PlayerName); + SendMessage(player, "User flair: "+p.Flair); + SendMessage(player, "Username: "+p.UserName); + SendMessage(player, "Flair accepted: "+p.AcceptedFlair); + SendMessage(player, "Flair ignored: "+p.IgnoredFlair); + } + private static void SendMessage(Player player, String message) + { //2015.08.09. + if(player==null) + System.out.println(message); + else + player.sendMessage(message); + } + private static void DoGetLastError(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "getlasterror" + if(PluginMain.LastException!=null) + { + SendMessage(player, "Last error:"); + SendMessage(player, PluginMain.LastException.toString()); + PluginMain.LastException=null; + } + else + SendMessage(player, "There were no exceptions."); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/99/308353a4d93e001517108d149b613203 b/.metadata/.plugins/org.eclipse.core.resources/.history/99/308353a4d93e001517108d149b613203 new file mode 100644 index 0000000..4ad7ffc --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/99/308353a4d93e001517108d149b613203 @@ -0,0 +1,228 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; + +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class Commands implements CommandExecutor { + // This method is called, when somebody uses our command + @Override + public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { + if (sender instanceof Player) { + Player player = (Player) sender; + if(args.length<1) + return false; + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. + //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) + if(p.Flair==null) + { + player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); + return true; + } + switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. + { + case "accept": + { + if(p.IgnoredFlair) + p.IgnoredFlair=false; //2015.08.08. + if(!p.AcceptedFlair) + { + String flair=p.Flair; //2015.08.08. + //PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + PluginMain.AppendPlayerDisplayFlair(p, player); + p.AcceptedFlair=true; //2015.08.08. + player.sendMessage("§6Your flair has been set:§r "+flair); + } + else + player.sendMessage("§cYou already have this user's flair.§r"); + break; + } + case "ignore": + { + if(p.AcceptedFlair) + p.AcceptedFlair=false; //2015.08.08. + if(!p.IgnoredFlair) + { + p.IgnoredFlair=true; + String flair=p.Flair; //2015.08.08. + PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. + player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); + } + else + player.sendMessage("§cYou already ignored this request.§r"); + break; + } + /*case "reload": //2015.07.20. + DoReload(player); + break;*/ + case "admin": //2015.08.09. + DoAdmin(player, args); + break; + case "nonpresser": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§7(non-pr.)§r"; + break; + case "cantpress": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§r(can't press)§r"; + break; + default: + return false; + } + return true; + } + /*if(args[0].toLowerCase()=="reload") + DoReload(null); //2015.07.20.*/ + else if(args.length>0 && args[0].toLowerCase().equals("admin")) //2015.08.09. + { + DoAdmin(null, args); //2015.08.09. + return true; //2015.08.09. + } + return false; + } + private static void DoReload(Player player) + { //2015.07.20. + //if(player==null || player.isOp() || player.getName()=="NorbiPeti") + //{ + try + { + File file=new File("autoflairconfig.txt"); + if(file.exists()) + { + PluginMain.LoadFiles(true); //2015.08.09. + for(Player p : PluginMain.GetPlayers()) + { + MaybeOfflinePlayer mp = MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName()); + if(mp.Flair!=null) + { + String flair=mp.Flair; + PluginMain.RemovePlayerDisplayFlairFinal(p, flair); + //PluginMain.AppendPlayerDisplayFlairFinal(p, flair); + PluginMain.AppendPlayerDisplayFlair(mp, p); //2015.08.09. + } + String msg="§6Note: The auto-flair plugin has been reloaded. You might need to wait 10s to have your flair.§r"; //2015.08.09. + p.sendMessage(msg); //2015.08.09. + } + //String msg="§6Reloaded config file.§r"; + //SendMessage(player, msg); //2015.08.09. + } + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + if(player!=null) + player.sendMessage("§cAn error occured. See console for details.§r"); + PluginMain.LastException=e; //2015.08.09. + } + //} + //else + //player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static Player ReloadPlayer; //2015.08.09. + private static void DoAdmin(Player player, String[] args) + { //2015.08.09. + if(player==null || player.isOp() || player.getName()=="NorbiPeti") + { + //System.out.println("Args length: " + args.length); + if(args.length==1) + { + String message="§cUsage: /u admin reload|playerinfo§r"; + SendMessage(player, message); + return; + } + //args[0] is "admin" + switch(args[1].toLowerCase()) + { + case "reload": + ReloadPlayer=player; //2015.08.09. + SendMessage(player, "§6Make sure to save the current settings before you modify and reload them! Type /u admin confirm when done.§r"); + break; + case "playerinfo": + DoPlayerInfo(player, args); + break; + case "getlasterror": + DoGetLastError(player, args); + case "confirm": + if(ReloadPlayer!=null && ReloadPlayer.equals(player)) + DoReload(player); //2015.08.09. + else + SendMessage(player, "§cYou need to do /u admin reload first.§r"); + break; + case "save": + PluginMain.SaveFiles(); //2015.08.09. + SendMessage(player, "§6Saved files. Now you can edit them and reload if you want.§r"); + break; + default: + String message="§cUsage: /u admin reload|playerinfo|getlasterror§r"; + SendMessage(player, message); + return; + } + } + else + player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static void DoPlayerInfo(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "playerinfo" + if(args.length==2) + { + String message="§cUsage: /u admin playerinfo §r"; + SendMessage(player, message); + return; + } + if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2])) + { + String message="§cPlayer not found: "+args[2]+"§r"; + SendMessage(player, message); + return; + } + MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]); + SendMessage(player, "Player name: "+p.PlayerName); + SendMessage(player, "User flair: "+p.Flair); + SendMessage(player, "Username: "+p.UserName); + SendMessage(player, "Flair accepted: "+p.AcceptedFlair); + SendMessage(player, "Flair ignored: "+p.IgnoredFlair); + } + private static void SendMessage(Player player, String message) + { //2015.08.09. + if(player==null) + System.out.println(message); + else + player.sendMessage(message); + } + private static void DoGetLastError(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "getlasterror" + if(PluginMain.LastException!=null) + { + SendMessage(player, "Last error:"); + SendMessage(player, PluginMain.LastException.toString()); + PluginMain.LastException=null; + } + else + SendMessage(player, "There were no exceptions."); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/9a/802cbb44dd3e001517108d149b613203 b/.metadata/.plugins/org.eclipse.core.resources/.history/9a/802cbb44dd3e001517108d149b613203 new file mode 100644 index 0000000..2d5bf44 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/9a/802cbb44dd3e001517108d149b613203 @@ -0,0 +1,394 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStream; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLConnection; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + +import org.apache.commons.io.IOUtils; +import org.bukkit.entity.Player; +import org.bukkit.plugin.java.JavaPlugin; +import org.json.JSONArray; +import org.json.JSONObject; + +import com.palmergames.bukkit.towny.object.Town; +import com.palmergames.bukkit.towny.object.WorldCoord; + +public class PluginMain extends JavaPlugin +{ //Translated to Java: 2015.07.15. + //A user, which flair isn't obtainable: + //https://www.reddit.com/r/thebutton/comments/31c32v/i_pressed_the_button_without_really_thinking/ + private static PluginMain Instance; + // Fired when plugin is first enabled + @Override + public void onEnable() + { + System.out.println("The Button Auto-flair Plugin by NorbiPeti (:P)"); + getServer().getPluginManager().registerEvents(new PlayerListener(), this); + this.getCommand("u").setExecutor(new Commands()); + this.getCommand("u").setUsage(this.getCommand("u").getUsage().replace('&', '§')); + Instance=this; //2015.08.08. + LoadFiles(false); //2015.08.09. + Runnable r=new Runnable(){public void run(){ThreadMethod();}}; + Thread t=new Thread(r); + t.start(); + } + Boolean stop=false; + // Fired when plugin is disabled + @Override + public void onDisable() + { + SaveFiles(); //2015.08.09. + stop=true; + } + + public void ThreadMethod() //<-- 2015.07.16. + { + while(!stop) + { + try + { + String body=DownloadString("https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/autoflair_system_comment_your_minecraft_name_and/.json?limit=1000"); + JSONArray json=new JSONArray(body).getJSONObject(1).getJSONObject("data").getJSONArray("children"); + for(Object obj : json) + { + JSONObject item = (JSONObject)obj; + String author=item.getJSONObject("data").getString("author"); + String ign=item.getJSONObject("data").getString("body"); + int start = ign.indexOf("IGN:") + "IGN:".length(); + if(start==-1) + continue; //2015.08.09. + int end = ign.indexOf(' ', start); + if (end == -1 || end == start) + end=ign.indexOf('\n', start); //2015.07.15. + if (end == -1 || end == start) + ign = ign.substring(start); + else + ign = ign.substring(start, end); + ign = ign.trim(); + if(HasIGFlair(ign)) + continue; + try { + Thread.sleep(10); + } catch(InterruptedException ex) { + Thread.currentThread().interrupt(); + } + String[] flairdata = DownloadString("http://karmadecay.com/thebutton-data.php?users=" + author).replace("\"", "").split(":"); + String flair; + if(flairdata.length > 1) //2015.07.15. + flair = flairdata[1]; + else + flair=""; + if (flair != "-1") + flair = flair + "s"; + else + flair = "non-presser"; + String flairclass; + if(flairdata.length>2) + flairclass = flairdata[2]; + else + flairclass="unknown"; + SetFlair(ign, flair, flairclass, author); + } + Thread.sleep(10000); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + } + + public static Exception LastException; //2015.08.09. + + public String DownloadString(String urlstr) throws MalformedURLException, IOException + { + URL url = new URL(urlstr); + URLConnection con = url.openConnection(); + con.setRequestProperty("User-Agent", "TheButtonAutoFlair"); + InputStream in = con.getInputStream(); + String encoding = con.getContentEncoding(); + encoding = encoding == null ? "UTF-8" : encoding; + String body = IOUtils.toString(in, encoding); + in.close(); + return body; + } + + public static Map TownColors=new HashMap(); //2015.07.20. + public Boolean HasIGFlair(String playername) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + return p.Flair!=null; //2015.08.08. + } + + public void SetFlair(String playername, String text, String flairclass, String username) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + String finalflair; + p.FlairDecided=true; + switch(flairclass) + { + case "press-1": + finalflair="§c("+text+")§r"; + break; + case "press-2": + finalflair="§6("+text+")§r"; + break; + case "press-3": + finalflair="§e("+text+")§r"; + break; + case "press-4": + finalflair="§a("+text+")§r"; + break; + case "press-5": + finalflair="§9("+text+")§r"; + break; + 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; + case "undecided": //2015.08.09. + p.FlairDecided=false; + finalflair=""; + break; + default: + finalflair=""; + break; + } + if(finalflair.length()==0) //<-- 2015.07.20. + return; + p.Flair=finalflair; //2015.08.08. + p.UserName=username; //2015.08.08. + System.out.println("Added new flair to "+playername+": "+finalflair); + for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08. + { + if(player.getName().equals(playername)) + { + //AppendPlayerDisplayFlair(player, username, finalflair); + AppendPlayerDisplayFlair(p, player); + break; + } + } + } + + public static String GetFlair(Player player) + { //2015.07.16. + String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08. + return flair==null ? "" : flair; + } + + //public static void AppendPlayerDisplayFlair(Player player, String username, String flair) + public static void AppendPlayerDisplayFlair(MaybeOfflinePlayer player, Player p) //<-- 2015.08.09. + { + + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).IgnoredFlair) + return; + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).AcceptedFlair) + { + AppendPlayerDisplayFlairFinal(p, player.Flair); //2015.07.20. + if(!player.FlairDecided) + p.sendMessage("§9Your flair type is unknown. Are you a non-presser or a can't press? (/u nonpresser or /u cantpress)§r"); //2015.08.09. + } + else + p.sendMessage("§9Are you Reddit user "+player.UserName+"?§r §6Type /u accept or /u ignore§r"); + } + + private static void AppendPlayerDisplayFlairFinal(Player player, String flair) + { //2015.07.20. + String color = GetColorForTown(GetPlayerTown(player)); //TO!DO: Multiple colors put on first capital letters + String[] colors = color.substring(1).split("§"); + String displayname=player.getName(); //2015.08.08. + ArrayList Positions=new ArrayList<>(); + for(int i=0; i=colors.length) + { + int x=0; + for(int i=0; i GetPlayers() + { + return Instance.getServer().getOnlinePlayers(); + } + + public static void LoadFiles(boolean reload) //<-- 2015.08.09. + { + if(reload) + { //2015.08.09. + System.out.println("Auto-flair plugin cleanup for reloading..."); + MaybeOfflinePlayer.AllPlayers.clear(); + TownColors.clear(); + } + System.out.println("Loading files for auto-flair plugin..."); //2015.08.09. + try { + File file=new File("flairsaccepted.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + //System.out.println("Name: " + name); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("flairsignored.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsignored.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("autoflairconfig.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + TownColors.put(s[0], s[1]); + } + br.close(); + } + file=new File("autoflairdecisions.txt"); //2015.08.09. + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + MaybeOfflinePlayer.AddPlayerIfNeeded(s[0]).Flair=s[1]; //2015.08.09. + } + br.close(); + } + //throw new IOException("Test"); //2015.08.09. + System.out.println("Auto-flair plugin loaded files!"); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + public static void SaveFiles() //<-- 2015.08.09. + { + try + { + FileWriter fw; + fw = new FileWriter("flairsaccepted.txt"); + fw.close(); + fw = new FileWriter("flairsignored.txt"); + fw.close(); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + try { + File file=new File("flairsaccepted.txt"); + BufferedWriter bw=new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.AcceptedFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + file=new File("flairsignored.txt"); + bw = new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.IgnoredFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/9a/90dce6d5ce3e001518fa86d7ae2a1cf8 b/.metadata/.plugins/org.eclipse.core.resources/.history/9a/90dce6d5ce3e001518fa86d7ae2a1cf8 new file mode 100644 index 0000000..f48f1b4 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/9a/90dce6d5ce3e001518fa86d7ae2a1cf8 @@ -0,0 +1,361 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStream; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLConnection; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + +import org.apache.commons.io.IOUtils; +import org.bukkit.entity.Player; +import org.bukkit.plugin.java.JavaPlugin; +import org.json.JSONArray; +import org.json.JSONObject; + +import tk.sznp.thebuttonautoflair.MaybeOfflinePlayer.FlairClassType; + +import com.palmergames.bukkit.towny.object.Town; +import com.palmergames.bukkit.towny.object.WorldCoord; + +public class PluginMain extends JavaPlugin +{ //Translated to Java: 2015.07.15. + //A user, which flair isn't obtainable: + //https://www.reddit.com/r/thebutton/comments/31c32v/i_pressed_the_button_without_really_thinking/ + private static PluginMain Instance; + // Fired when plugin is first enabled + @Override + public void onEnable() + { + System.out.println("The Button Auto-flair Plugin by NorbiPeti (:P)"); + getServer().getPluginManager().registerEvents(new PlayerListener(), this); + this.getCommand("u").setExecutor(new Commands()); + this.getCommand("u").setUsage(this.getCommand("u").getUsage().replace('&', '§')); + Instance=this; //2015.08.08. + try { + File file=new File("flairsaccepted.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + //System.out.println("Name: " + name); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("flairsignored.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsignored.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("autoflairconfig.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + TownColors.put(s[0], s[1]); + } + br.close(); + } + //throw new IOException("Test"); //2015.08.09. + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + Runnable r=new Runnable(){public void run(){ThreadMethod();}}; + Thread t=new Thread(r); + t.start(); + } + Boolean stop=false; + // Fired when plugin is disabled + @Override + public void onDisable() + { + try + { + FileWriter fw; + fw = new FileWriter("flairsaccepted.txt"); + fw.close(); + fw = new FileWriter("flairsignored.txt"); + fw.close(); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + try { + File file=new File("flairsaccepted.txt"); + BufferedWriter bw=new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.AcceptedFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + file=new File("flairsignored.txt"); + bw = new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.IgnoredFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + stop=true; + } + + public void ThreadMethod() //<-- 2015.07.16. + { + while(!stop) + { + try + { + String body=DownloadString("https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/autoflair_system_comment_your_minecraft_name_and/.json?limit=1000"); + JSONArray json=new JSONArray(body).getJSONObject(1).getJSONObject("data").getJSONArray("children"); + for(Object obj : json) + { + JSONObject item = (JSONObject)obj; + String author=item.getJSONObject("data").getString("author"); + String ign=item.getJSONObject("data").getString("body"); + int start = ign.indexOf("IGN:") + "IGN:".length(); + int end = ign.indexOf(' ', start); + if (end == -1 || end == start) + end=ign.indexOf('\n', start); //2015.07.15. + if (end == -1 || end == start) + ign = ign.substring(start); + else + ign = ign.substring(start, end); + ign = ign.trim(); + if(HasIGFlair(ign)) + continue; + try { + Thread.sleep(10); + } catch(InterruptedException ex) { + Thread.currentThread().interrupt(); + } + String[] flairdata = DownloadString("http://karmadecay.com/thebutton-data.php?users=" + author).replace("\"", "").split(":"); + String flair; + if(flairdata.length > 1) //2015.07.15. + flair = flairdata[1]; + else + flair=""; + if (flair != "-1") + flair = flair + "s"; + else + flair = "non-presser"; + String flairclass; + if(flairdata.length>2) + flairclass = flairdata[2]; + else + flairclass="unknown"; + SetFlair(ign, flair, flairclass, author); + } + Thread.sleep(10000); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + } + + public static Exception LastException; //2015.08.09. + + public String DownloadString(String urlstr) throws MalformedURLException, IOException + { + URL url = new URL(urlstr); + URLConnection con = url.openConnection(); + con.setRequestProperty("User-Agent", "TheButtonAutoFlair"); + InputStream in = con.getInputStream(); + String encoding = con.getContentEncoding(); + encoding = encoding == null ? "UTF-8" : encoding; + String body = IOUtils.toString(in, encoding); + in.close(); + return body; + } + + public static Map TownColors=new HashMap(); //2015.07.20. + public Boolean HasIGFlair(String playername) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + return p.Flair!=null; //2015.08.08. + } + + public void SetFlair(String playername, String text, String flairclass, String username) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + String finalflair; + p.FlairDecided=true; + switch(flairclass) + { + case "press-1": + finalflair="§c("+text+")§r"; + break; + case "press-2": + finalflair="§6("+text+")§r"; + break; + case "press-3": + finalflair="§e("+text+")§r"; + break; + case "press-4": + finalflair="§a("+text+")§r"; + break; + case "press-5": + finalflair="§9("+text+")§r"; + break; + 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; + case "undecided": //2015.08.09. + p.FlairDecided=false; + finalflair=""; + break; + default: + finalflair=""; + break; + } + if(finalflair.length()==0) //<-- 2015.07.20. + return; + p.Flair=finalflair; //2015.08.08. + p.UserName=username; //2015.08.08. + System.out.println("Added new flair to "+playername+": "+finalflair); + for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08. + { + if(player.getName().equals(playername)) + { + AppendPlayerDisplayFlair(player, username, finalflair); + break; + } + } + } + + public static String GetFlair(Player player) + { //2015.07.16. + String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08. + return flair==null ? "" : flair; + } + + //public static void AppendPlayerDisplayFlair(Player player, String username, String flair) + public static void AppendPlayerDisplayFlair(Player player, String username, String flair) + { + if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).IgnoredFlair) + return; + if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).AcceptedFlair) + { + AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + } + else + player.sendMessage("§9Are you Reddit user "+username+"?§r §6Type /u accept or /u ignore§r"); + } + + private static void AppendPlayerDisplayFlairFinal(Player player, String flair) + { //2015.07.20. + String color = GetColorForTown(GetPlayerTown(player)); //TO!DO: Multiple colors put on first capital letters + String[] colors = color.substring(1).split("§"); + String displayname=player.getName(); //2015.08.08. + ArrayList Positions=new ArrayList<>(); + for(int i=0; i=colors.length) + { + int x=0; + for(int i=0; i GetPlayers() + { + return Instance.getServer().getOnlinePlayers(); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/9a/a0aebdacd03e001518fa86d7ae2a1cf8 b/.metadata/.plugins/org.eclipse.core.resources/.history/9a/a0aebdacd03e001518fa86d7ae2a1cf8 new file mode 100644 index 0000000..8abed8b --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/9a/a0aebdacd03e001518fa86d7ae2a1cf8 @@ -0,0 +1,206 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; + +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class Commands implements CommandExecutor { + // This method is called, when somebody uses our command + @Override + public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { + if (sender instanceof Player) { + Player player = (Player) sender; + if(args.length<1) + return false; + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. + //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) + if(p.Flair==null) + { + player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); + return true; + } + switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. + { + case "accept": + { + if(p.IgnoredFlair) + p.IgnoredFlair=false; //2015.08.08. + if(!p.AcceptedFlair) + { + String flair=p.Flair; //2015.08.08. + //PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + PluginMain.AppendPlayerDisplayFlair(p, player); + p.AcceptedFlair=true; //2015.08.08. + player.sendMessage("§6Your flair has been set:§r "+flair); + } + else + player.sendMessage("§cYou already have this user's flair.§r"); + break; + } + case "ignore": + { + if(p.AcceptedFlair) + p.AcceptedFlair=false; //2015.08.08. + if(!p.IgnoredFlair) + { + p.IgnoredFlair=true; + String flair=p.Flair; //2015.08.08. + PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. + player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); + } + else + player.sendMessage("§cYou already ignored this request.§r"); + break; + } + /*case "reload": //2015.07.20. + DoReload(player); + break;*/ + case "admin": //2015.08.09. + DoAdmin(player, args); + break; + case "nonpresser": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + + break; + case "cantpress": //2015.08.09. + break; + default: + return false; + } + return true; + } + /*if(args[0].toLowerCase()=="reload") + DoReload(null); //2015.07.20.*/ + else if(args.length>0 && args[0].toLowerCase().equals("admin")) //2015.08.09. + { + DoAdmin(null, args); //2015.08.09. + return true; //2015.08.09. + } + return false; + } + private static void DoReload(Player player) + { //2015.07.20. + //if(player==null || player.isOp() || player.getName()=="NorbiPeti") + //{ + try + { + File file=new File("autoflairconfig.txt"); + if(file.exists()) + { + PluginMain.TownColors.clear(); + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + PluginMain.TownColors.put(s[0], s[1]); + } + br.close(); + for(Player p : PluginMain.GetPlayers()) + { + MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName()); + if(mp.Flair!=null) + { + String flair=mp.Flair; + PluginMain.RemovePlayerDisplayFlairFinal(p, flair); + //PluginMain.AppendPlayerDisplayFlairFinal(p, flair); + PluginMain.AppendPlayerDisplayFlair(mp, p); //2015.08.09. + } + } + String msg="§6Reloaded config file.§r"; + SendMessage(player, msg); //2015.08.09. + } + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + if(player!=null) + player.sendMessage("§cAn error occured. See console for details.§r"); + PluginMain.LastException=e; //2015.08.09. + } + //} + //else + //player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static void DoAdmin(Player player, String[] args) + { //2015.08.09. + if(player==null || player.isOp() || player.getName()=="NorbiPeti") + { + //System.out.println("Args length: " + args.length); + if(args.length==1) + { + String message="§cUsage: /u admin reload|playerinfo§r"; + SendMessage(player, message); + return; + } + //args[0] is "admin" + switch(args[1].toLowerCase()) + { + case "reload": + DoReload(player); + break; + case "playerinfo": + DoPlayerInfo(player, args); + break; + case "getlasterror": + DoGetLastError(player, args); + default: + String message="§cUsage: /u admin reload|playerinfo§r"; + SendMessage(player, message); + return; + } + } + else + player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static void DoPlayerInfo(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "playerinfo" + if(args.length==2) + { + String message="§cUsage: /u admin playerinfo §r"; + SendMessage(player, message); + return; + } + if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2])) + { + String message="§cPlayer not found: "+args[2]+"§r"; + SendMessage(player, message); + return; + } + MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]); + SendMessage(player, "Player name: "+p.PlayerName); + SendMessage(player, "User flair: "+p.Flair); + SendMessage(player, "Username: "+p.UserName); + SendMessage(player, "Flair accepted: "+p.AcceptedFlair); + SendMessage(player, "Flair ignored: "+p.IgnoredFlair); + } + private static void SendMessage(Player player, String message) + { //2015.08.09. + if(player==null) + System.out.println(message); + else + player.sendMessage(message); + } + private static void DoGetLastError(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "getlasterror" + if(PluginMain.LastException!=null) + { + SendMessage(player, "Last error:"); + SendMessage(player, PluginMain.LastException.toString()); + PluginMain.LastException=null; + } + else + SendMessage(player, "There were no exceptions."); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/9b/0068cab7e03e001517108d149b613203 b/.metadata/.plugins/org.eclipse.core.resources/.history/9b/0068cab7e03e001517108d149b613203 new file mode 100644 index 0000000..1a68137 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/9b/0068cab7e03e001517108d149b613203 @@ -0,0 +1,263 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +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; + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. + //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) + if(p.Flair==null) + { + player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); + return true; + } + switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. + { + case "accept": + { + if(p.IgnoredFlair) + p.IgnoredFlair=false; //2015.08.08. + if(!p.AcceptedFlair) + { + String flair=p.Flair; //2015.08.08. + //PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + PluginMain.AppendPlayerDisplayFlair(p, player); + p.AcceptedFlair=true; //2015.08.08. + player.sendMessage("§6Your flair has been set:§r "+flair); + } + else + player.sendMessage("§cYou already have this user's flair.§r"); + break; + } + case "ignore": + { + if(p.AcceptedFlair) + p.AcceptedFlair=false; //2015.08.08. + if(!p.IgnoredFlair) + { + p.IgnoredFlair=true; + String flair=p.Flair; //2015.08.08. + PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. + player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); + } + else + player.sendMessage("§cYou already ignored this request.§r"); + break; + } + /*case "reload": //2015.07.20. + DoReload(player); + break;*/ + case "admin": //2015.08.09. + DoAdmin(player, args); + break; + case "nonpresser": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§7(non-pr.)§r"; + break; + case "cantpress": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§r(can't press)§r"; + break; + default: + return false; + } + return true; + } + /*if(args[0].toLowerCase()=="reload") + DoReload(null); //2015.07.20.*/ + else if(args.length>0 && args[0].toLowerCase().equals("admin")) //2015.08.09. + { + DoAdmin(null, args); //2015.08.09. + return true; //2015.08.09. + } + return false; + } + private static void DoReload(Player player) + { //2015.07.20. + //if(player==null || player.isOp() || player.getName()=="NorbiPeti") + //{ + try + { + File file=new File("autoflairconfig.txt"); + if(file.exists()) + { + PluginMain.LoadFiles(true); //2015.08.09. + for(Player p : PluginMain.GetPlayers()) + { + MaybeOfflinePlayer mp = MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName()); + if(mp.Flair!=null) + { + String flair=mp.Flair; + PluginMain.RemovePlayerDisplayFlairFinal(p, flair); + //PluginMain.AppendPlayerDisplayFlairFinal(p, flair); + PluginMain.AppendPlayerDisplayFlair(mp, p); //2015.08.09. + } + String msg="§6Note: The auto-flair plugin has been reloaded. You might need to wait 10s to have your flair.§r"; //2015.08.09. + p.sendMessage(msg); //2015.08.09. + } + //String msg="§6Reloaded config file.§r"; + //SendMessage(player, msg); //2015.08.09. + } + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + if(player!=null) + player.sendMessage("§cAn error occured. See console for details.§r"); + PluginMain.LastException=e; //2015.08.09. + } + //} + //else + //player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static Player ReloadPlayer; //2015.08.09. + private static void DoAdmin(Player player, String[] args) + { //2015.08.09. + if(player==null || player.isOp() || player.getName()=="NorbiPeti") + { + //System.out.println("Args length: " + args.length); + if(args.length==1) + { + String message="§cUsage: /u admin reload|playerinfo§r"; + SendMessage(player, message); + return; + } + //args[0] is "admin" + switch(args[1].toLowerCase()) + { + case "reload": + ReloadPlayer=player; //2015.08.09. + SendMessage(player, "§6Make sure to save the current settings before you modify and reload them! Type /u admin confirm when done.§r"); + break; + case "playerinfo": + DoPlayerInfo(player, args); + break; + case "getlasterror": + DoGetLastError(player, args); + case "confirm": + if(ReloadPlayer==player) + DoReload(player); //2015.08.09. + else + SendMessage(player, "§cYou need to do /u admin reload first.§r"); + break; + case "save": + PluginMain.SaveFiles(); //2015.08.09. + SendMessage(player, "§6Saved files. Now you can edit them and reload if you want.§r"); + break; + case "setflair": + + break; + default: + String message="§cUsage: /u admin reload|playerinfo|getlasterror|save§r"; + SendMessage(player, message); + return; + } + } + else + player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static void DoPlayerInfo(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "playerinfo" + if(args.length==2) + { + String message="§cUsage: /u admin playerinfo §r"; + SendMessage(player, message); + return; + } + if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2])) + { + String message="§cPlayer not found: "+args[2]+"§r"; + SendMessage(player, message); + return; + } + MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]); + SendMessage(player, "Player name: "+p.PlayerName); + SendMessage(player, "User flair: "+p.Flair); + SendMessage(player, "Username: "+p.UserName); + SendMessage(player, "Flair accepted: "+p.AcceptedFlair); + SendMessage(player, "Flair ignored: "+p.IgnoredFlair); + } + private static void SendMessage(Player player, String message) + { //2015.08.09. + if(player==null) + System.out.println(message); + else + player.sendMessage(message); + } + private static void DoGetLastError(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "getlasterror" + if(PluginMain.LastException!=null) + { + SendMessage(player, "Last error:"); + SendMessage(player, PluginMain.LastException.toString()); + PluginMain.LastException=null; + } + else + SendMessage(player, "There were no exceptions."); + } + private static void SetPlayerFlair(Player player, Player targetplayer, String flair) + { //2015.08.09. + flair=flair.replace('&', '§'); + MaybeOfflinePlayer.AddPlayerIfNeeded(player.getName()).Flair=flair; + if(!PluginMain.RemoveLineFromFile("customflairs.txt", targetplayer.getName())) + { + SendMessage(player, "§cError removing previous custom flair!§r"); + return; + } + File file=new File("customflairs.txt"); + try { + BufferedWriter bw; + bw = new BufferedWriter(new FileWriter(file, true)); + bw.write(targetplayer.getName()+"\n"); + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + PluginMain.LastException=e; //2015.08.09. + } + SendMessage(player, "§6The flair has been set. Player: "+targetplayer.getName()+" Flair: "+flair+"§r"); + } + private static void DoSetFlair(Player player, String args) + { + //args[0] is "admin" - args[1] is "setflair" + if(args.length()<4) + { + SendMessage(player, "§cUsage: /u admin setflair "); + } + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/9c/30bb8899d13e001518fa86d7ae2a1cf8 b/.metadata/.plugins/org.eclipse.core.resources/.history/9c/30bb8899d13e001518fa86d7ae2a1cf8 new file mode 100644 index 0000000..2e695ac --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/9c/30bb8899d13e001518fa86d7ae2a1cf8 @@ -0,0 +1,326 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStream; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLConnection; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + +import org.apache.commons.io.IOUtils; +import org.bukkit.entity.Player; +import org.bukkit.plugin.java.JavaPlugin; +import org.json.JSONArray; +import org.json.JSONObject; + +import com.palmergames.bukkit.towny.object.Town; +import com.palmergames.bukkit.towny.object.WorldCoord; + +public class PluginMain extends JavaPlugin +{ //Translated to Java: 2015.07.15. + //A user, which flair isn't obtainable: + //https://www.reddit.com/r/thebutton/comments/31c32v/i_pressed_the_button_without_really_thinking/ + private static PluginMain Instance; + // Fired when plugin is first enabled + @Override + public void onEnable() + { + System.out.println("The Button Auto-flair Plugin by NorbiPeti (:P)"); + getServer().getPluginManager().registerEvents(new PlayerListener(), this); + this.getCommand("u").setExecutor(new Commands()); + this.getCommand("u").setUsage(this.getCommand("u").getUsage().replace('&', '§')); + Instance=this; //2015.08.08. + Load(false); //2015.08.09. + Runnable r=new Runnable(){public void run(){ThreadMethod();}}; + Thread t=new Thread(r); + t.start(); + } + Boolean stop=false; + // Fired when plugin is disabled + @Override + public void onDisable() + { + try + { + FileWriter fw; + fw = new FileWriter("flairsaccepted.txt"); + fw.close(); + fw = new FileWriter("flairsignored.txt"); + fw.close(); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + try { + File file=new File("flairsaccepted.txt"); + BufferedWriter bw=new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.AcceptedFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + file=new File("flairsignored.txt"); + bw = new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.IgnoredFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + stop=true; + } + + public void ThreadMethod() //<-- 2015.07.16. + { + while(!stop) + { + try + { + String body=DownloadString("https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/autoflair_system_comment_your_minecraft_name_and/.json?limit=1000"); + JSONArray json=new JSONArray(body).getJSONObject(1).getJSONObject("data").getJSONArray("children"); + for(Object obj : json) + { + JSONObject item = (JSONObject)obj; + String author=item.getJSONObject("data").getString("author"); + String ign=item.getJSONObject("data").getString("body"); + int start = ign.indexOf("IGN:") + "IGN:".length(); + int end = ign.indexOf(' ', start); + if (end == -1 || end == start) + end=ign.indexOf('\n', start); //2015.07.15. + if (end == -1 || end == start) + ign = ign.substring(start); + else + ign = ign.substring(start, end); + ign = ign.trim(); + if(HasIGFlair(ign)) + continue; + try { + Thread.sleep(10); + } catch(InterruptedException ex) { + Thread.currentThread().interrupt(); + } + String[] flairdata = DownloadString("http://karmadecay.com/thebutton-data.php?users=" + author).replace("\"", "").split(":"); + String flair; + if(flairdata.length > 1) //2015.07.15. + flair = flairdata[1]; + else + flair=""; + if (flair != "-1") + flair = flair + "s"; + else + flair = "non-presser"; + String flairclass; + if(flairdata.length>2) + flairclass = flairdata[2]; + else + flairclass="unknown"; + SetFlair(ign, flair, flairclass, author); + } + Thread.sleep(10000); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + } + + public static Exception LastException; //2015.08.09. + + public String DownloadString(String urlstr) throws MalformedURLException, IOException + { + URL url = new URL(urlstr); + URLConnection con = url.openConnection(); + con.setRequestProperty("User-Agent", "TheButtonAutoFlair"); + InputStream in = con.getInputStream(); + String encoding = con.getContentEncoding(); + encoding = encoding == null ? "UTF-8" : encoding; + String body = IOUtils.toString(in, encoding); + in.close(); + return body; + } + + public static Map TownColors=new HashMap(); //2015.07.20. + public Boolean HasIGFlair(String playername) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + return p.Flair!=null; //2015.08.08. + } + + public void SetFlair(String playername, String text, String flairclass, String username) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + String finalflair; + p.FlairDecided=true; + switch(flairclass) + { + case "press-1": + finalflair="§c("+text+")§r"; + break; + case "press-2": + finalflair="§6("+text+")§r"; + break; + case "press-3": + finalflair="§e("+text+")§r"; + break; + case "press-4": + finalflair="§a("+text+")§r"; + break; + case "press-5": + finalflair="§9("+text+")§r"; + break; + 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; + case "undecided": //2015.08.09. + p.FlairDecided=false; + finalflair=""; + break; + default: + finalflair=""; + break; + } + if(finalflair.length()==0) //<-- 2015.07.20. + return; + p.Flair=finalflair; //2015.08.08. + p.UserName=username; //2015.08.08. + System.out.println("Added new flair to "+playername+": "+finalflair); + for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08. + { + if(player.getName().equals(playername)) + { + //AppendPlayerDisplayFlair(player, username, finalflair); + AppendPlayerDisplayFlair(p, player); + break; + } + } + } + + public static String GetFlair(Player player) + { //2015.07.16. + String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08. + return flair==null ? "" : flair; + } + + //public static void AppendPlayerDisplayFlair(Player player, String username, String flair) + public static void AppendPlayerDisplayFlair(MaybeOfflinePlayer player, Player p) //<-- 2015.08.09. + { + + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).IgnoredFlair) + return; + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).AcceptedFlair) + { + AppendPlayerDisplayFlairFinal(p, player.Flair); //2015.07.20. + if(!player.FlairDecided) + p.sendMessage("§9Your flair type is unknown. Are you a non-presser or a can't press? (/u nonpresser or /u cantpress)§r"); //2015.08.09. + } + else + p.sendMessage("§9Are you Reddit user "+player.UserName+"?§r §6Type /u accept or /u ignore§r"); + } + + private static void AppendPlayerDisplayFlairFinal(Player player, String flair) + { //2015.07.20. + String color = GetColorForTown(GetPlayerTown(player)); //TO!DO: Multiple colors put on first capital letters + String[] colors = color.substring(1).split("§"); + String displayname=player.getName(); //2015.08.08. + ArrayList Positions=new ArrayList<>(); + for(int i=0; i=colors.length) + { + int x=0; + for(int i=0; i GetPlayers() + { + return Instance.getServer().getOnlinePlayers(); + } + + public static void LoadFiles(boolean reload) + { + + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/9d/50e1b4b6883e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/9d/50e1b4b6883e00151ce8ff6d4f74dabd deleted file mode 100644 index 6c54b93..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/9d/50e1b4b6883e00151ce8ff6d4f74dabd +++ /dev/null @@ -1,173 +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; - MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. - //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - if(p.Flair==null) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. - { - case "accept": - { - if(p.IgnoredFlair) - p.IgnoredFlair=false; //2015.08.08. - if(!p.AcceptedFlair) - { - String flair=p.Flair; //2015.08.08. - PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. - p.AcceptedFlair=true; //2015.08.08. - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("§cYou already have this user's flair.§r"); - break; - } - case "ignore": - { - if(p.AcceptedFlair) - p.AcceptedFlair=false; //2015.08.08. - if(!p.IgnoredFlair) - { - p.IgnoredFlair=true; - String flair=p.Flair; //2015.08.08. - PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. - player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); - } - else - player.sendMessage("§cYou already ignored this request.§r"); - break; - } - /*case "reload": //2015.07.20. - DoReload(player); - break;*/ - case "admin": //2015.08.09. - DoAdmin(player, args); - break; - default: - return false; - } - return true; - } - - /*if(args[0].toLowerCase()=="reload") - DoReload(null); //2015.07.20.*/ - else if(args[0].toLowerCase()=="admin") - DoAdmin(null, args); //2015.08.09. - return false; - } - private static void DoReload(Player player) - { //2015.07.20. - //if(player==null || player.isOp() || player.getName()=="NorbiPeti") - //{ - try - { - File file=new File("autoflairconfig.txt"); - if(file.exists()) - { - PluginMain.TownColors.clear(); - BufferedReader br=new BufferedReader(new FileReader(file)); - String line; - while((line=br.readLine())!=null) - { - String[] s=line.split(" "); - PluginMain.TownColors.put(s[0], s[1]); - } - br.close(); - for(Player p : PluginMain.GetPlayers()) - { - MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName()); - if(mp.Flair!=null) - { - String flair=mp.Flair; - PluginMain.RemovePlayerDisplayFlairFinal(p, flair); - PluginMain.AppendPlayerDisplayFlairFinal(p, flair); - } - } - String msg="§6Reloaded config file.§r"; - if(player!=null) - player.sendMessage(msg); - else - System.out.println(msg); - } - } - catch(Exception e) - { - System.out.println("Error!\n"+e); - if(player!=null) - player.sendMessage("§cAn error occured. See console for details.§r"); - } - //} - //else - //player.sendMessage("§cYou need to be OP to use this command.§r"); - } - private static void DoAdmin(Player player, String[] args) - { //2015.08.09. - if(player==null || player.isOp() || player.getName()=="NorbiPeti") - { - if(args.length==1) - { - String message="§cUsage: /u admin reload|playerinfo§r"; - if(player==null) - System.out.println(message); - else - player.sendMessage(message); - return; - } - //args[0] is "admin" - switch(args[1].toLowerCase()) - { - case "reload": - DoReload(player); - break; - case "playerinfo": - DoPlayerInfo(player, args); - break; - } - } - else - player.sendMessage("§cYou need to be OP to use this command.§r"); - } - private static void DoPlayerInfo(Player player, String[] args) - { //2015.08.09. - //args[0] is "admin" - args[1] is "playerinfo" - if(args.length==2) - { - String message="§cUsage: /u admin playerinfo §r"; -SendMessage(player, message); - } - if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2])) - { - String message="§cPlayer not found: "+args[2]+"§r"; - SendMessage(player, message); - } - MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]); - return; - } - private static void SendMessage(Player player, String message) - { - if(player==null) - System.out.println(message); - else - player.sendMessage(message); - return; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/a/705c51af0d3e00151089cca86c5b1a99 b/.metadata/.plugins/org.eclipse.core.resources/.history/a/705c51af0d3e00151089cca86c5b1a99 deleted file mode 100644 index efac5c3..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/a/705c51af0d3e00151089cca86c5b1a99 +++ /dev/null @@ -1,434 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import java.io.BufferedReader; -import java.io.BufferedWriter; -import java.io.File; -import java.io.FileReader; -import java.io.FileWriter; -import java.io.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/a/c0191a3f023e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/a/c0191a3f023e00151c31fb33fff4337f deleted file mode 100644 index 772f7ef..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/a/c0191a3f023e00151c31fb33fff4337f +++ /dev/null @@ -1,125 +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; - 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/a0/f08cfd11853e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/a0/f08cfd11853e00151ce8ff6d4f74dabd deleted file mode 100644 index abbb5cd..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/a0/f08cfd11853e00151ce8ff6d4f74dabd +++ /dev/null @@ -1,120 +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; - MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. - //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - if(p.Flair==null) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. - { - case "accept": - { - if(p.IgnoredFlair) - p.IgnoredFlair=false; //2015.08.08. - if(!p.AcceptedFlair) - { - String flair=p.Flair; //2015.08.08. - PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. - p.AcceptedFlair=true; //2015.08.08. - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("§cYou already have this user's flair.§r"); - break; - } - case "ignore": - { - if(p.AcceptedFlair) - p.AcceptedFlair=false; //2015.08.08. - if(!p.IgnoredFlair) - { - p.IgnoredFlair=true; - String flair=p.Flair; //2015.08.08. - PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. - player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); - } - else - player.sendMessage("§cYou already ignored this request.§r"); - break; - } - case "reload": //2015.07.20. - DoReload(player); - break; - case "showerrors": //2015.08.09. - DoShowErrors(player); - break; - default: - return false; - } - return true; - } - - if(args[0]=="reload") - DoReload(null); //2015.07.20. - return false; - } - private static void DoReload(Player player) - { //2015.07.20. - if(player==null || player.isOp() || player.getName()=="NorbiPeti") - { - try - { - File file=new File("autoflairconfig.txt"); - if(file.exists()) - { - PluginMain.TownColors.clear(); - BufferedReader br=new BufferedReader(new FileReader(file)); - String line; - while((line=br.readLine())!=null) - { - String[] s=line.split(" "); - PluginMain.TownColors.put(s[0], s[1]); - } - br.close(); - for(Player p : PluginMain.GetPlayers()) - { - MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName()); - if(mp.Flair!=null) - { - String flair=mp.Flair; - PluginMain.RemovePlayerDisplayFlairFinal(p, flair); - PluginMain.AppendPlayerDisplayFlairFinal(p, flair); - } - } - String msg="§6Reloaded config file.§r"; - if(player!=null) - player.sendMessage(msg); - else - System.out.println(msg); - } - } - catch(Exception e) - { - System.out.println("Error!\n"+e); - if(player!=null) - player.sendMessage("§cAn error occured. See console for details.§r"); - } - } - else - player.sendMessage("§cYou need to be OP to use this command.§r"); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/a1/009afe94e33e001517108d149b613203 b/.metadata/.plugins/org.eclipse.core.resources/.history/a1/009afe94e33e001517108d149b613203 new file mode 100644 index 0000000..c4b45ca --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/a1/009afe94e33e001517108d149b613203 @@ -0,0 +1,422 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStream; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLConnection; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + +import org.apache.commons.io.IOUtils; +import org.bukkit.entity.Player; +import org.bukkit.plugin.java.JavaPlugin; +import org.json.JSONArray; +import org.json.JSONObject; + +import com.palmergames.bukkit.towny.object.Town; +import com.palmergames.bukkit.towny.object.WorldCoord; + +public class PluginMain extends JavaPlugin +{ //Translated to Java: 2015.07.15. + //A user, which flair isn't obtainable: + //https://www.reddit.com/r/thebutton/comments/31c32v/i_pressed_the_button_without_really_thinking/ + private static PluginMain Instance; + // Fired when plugin is first enabled + @Override + public void onEnable() + { + System.out.println("The Button Auto-flair Plugin by NorbiPeti (:P)"); + getServer().getPluginManager().registerEvents(new PlayerListener(), this); + this.getCommand("u").setExecutor(new Commands()); + this.getCommand("u").setUsage(this.getCommand("u").getUsage().replace('&', '§')); + Instance=this; //2015.08.08. + LoadFiles(false); //2015.08.09. + Runnable r=new Runnable(){public void run(){ThreadMethod();}}; + Thread t=new Thread(r); + t.start(); + } + Boolean stop=false; + // Fired when plugin is disabled + @Override + public void onDisable() + { + SaveFiles(); //2015.08.09. + stop=true; + } + + public void ThreadMethod() //<-- 2015.07.16. + { + while(!stop) + { + try + { + String body=DownloadString("https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/autoflair_system_comment_your_minecraft_name_and/.json?limit=1000"); + JSONArray json=new JSONArray(body).getJSONObject(1).getJSONObject("data").getJSONArray("children"); + for(Object obj : json) + { + JSONObject item = (JSONObject)obj; + String author=item.getJSONObject("data").getString("author"); + String ign=item.getJSONObject("data").getString("body"); + int start = ign.indexOf("IGN:") + "IGN:".length(); + if(start==-1) + continue; //2015.08.09. + int end = ign.indexOf(' ', start); + if (end == -1 || end == start) + end=ign.indexOf('\n', start); //2015.07.15. + if (end == -1 || end == start) + ign = ign.substring(start); + else + ign = ign.substring(start, end); + ign = ign.trim(); + if(HasIGFlair(ign)) + continue; + try { + Thread.sleep(10); + } catch(InterruptedException ex) { + Thread.currentThread().interrupt(); + } + String[] flairdata = DownloadString("http://karmadecay.com/thebutton-data.php?users=" + author).replace("\"", "").split(":"); + String flair; + if(flairdata.length > 1) //2015.07.15. + flair = flairdata[1]; + else + flair=""; + if (flair != "-1") + flair = flair + "s"; + else + flair = "non-presser"; + String flairclass; + if(flairdata.length>2) + flairclass = flairdata[2]; + else + flairclass="unknown"; + SetFlair(ign, flair, flairclass, author); + } + Thread.sleep(10000); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + } + + public static Exception LastException; //2015.08.09. + + public String DownloadString(String urlstr) throws MalformedURLException, IOException + { + URL url = new URL(urlstr); + URLConnection con = url.openConnection(); + con.setRequestProperty("User-Agent", "TheButtonAutoFlair"); + InputStream in = con.getInputStream(); + String encoding = con.getContentEncoding(); + encoding = encoding == null ? "UTF-8" : encoding; + String body = IOUtils.toString(in, encoding); + in.close(); + return body; + } + + public static Map TownColors=new HashMap(); //2015.07.20. + public Boolean HasIGFlair(String playername) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + return p.Flair!=null; //2015.08.08. + } + + public void SetFlair(String playername, String text, String flairclass, String username) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + String finalflair; + p.FlairDecided=true; + switch(flairclass) + { + case "press-1": + finalflair="§c("+text+")§r"; + break; + case "press-2": + finalflair="§6("+text+")§r"; + break; + case "press-3": + finalflair="§e("+text+")§r"; + break; + case "press-4": + finalflair="§a("+text+")§r"; + break; + case "press-5": + finalflair="§9("+text+")§r"; + break; + 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; + case "undecided": //2015.08.09. + p.FlairDecided=false; + finalflair=""; + break; + default: + finalflair=""; + break; + } + if(finalflair.length()==0) //<-- 2015.07.20. + return; + p.Flair=finalflair; //2015.08.08. + p.UserName=username; //2015.08.08. + System.out.println("Added new flair to "+playername+": "+finalflair); + for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08. + { + if(player.getName().equals(playername)) + { + //AppendPlayerDisplayFlair(player, username, finalflair); + AppendPlayerDisplayFlair(p, player); + break; + } + } + } + + public static String GetFlair(Player player) + { //2015.07.16. + String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08. + return flair==null ? "" : flair; + } + + //public static void AppendPlayerDisplayFlair(Player player, String username, String flair) + public static void AppendPlayerDisplayFlair(MaybeOfflinePlayer player, Player p) //<-- 2015.08.09. + { + + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).IgnoredFlair) + return; + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).AcceptedFlair) + { + AppendPlayerDisplayFlairFinal(p, player.Flair); //2015.07.20. + if(!player.FlairDecided) + p.sendMessage("§9Your flair type is unknown. Are you a non-presser or a can't press? (/u nonpresser or /u cantpress)§r"); //2015.08.09. + } + else + p.sendMessage("§9Are you Reddit user "+player.UserName+"?§r §6Type /u accept or /u ignore§r"); + } + + private static void AppendPlayerDisplayFlairFinal(Player player, String flair) + { //2015.07.20. + String color = GetColorForTown(GetPlayerTown(player)); //TO!DO: Multiple colors put on first capital letters + String[] colors = color.substring(1).split("§"); + String displayname=player.getName(); //2015.08.08. + ArrayList Positions=new ArrayList<>(); + for(int i=0; i=colors.length) + { + int x=0; + for(int i=0; i GetPlayers() + { + return Instance.getServer().getOnlinePlayers(); + } + + public static void LoadFiles(boolean reload) //<-- 2015.08.09. + { + if(reload) + { //2015.08.09. + System.out.println("Auto-flair plugin cleanup for reloading..."); + MaybeOfflinePlayer.AllPlayers.clear(); + TownColors.clear(); + } + System.out.println("Loading files for auto-flair plugin..."); //2015.08.09. + try { + File file=new File("flairsaccepted.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + //System.out.println("Name: " + name); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("flairsignored.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsignored.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("autoflairconfig.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + TownColors.put(s[0], s[1]); + } + br.close(); + } + file=new File("customflairs.txt"); //2015.08.09. + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + MaybeOfflinePlayer.AddPlayerIfNeeded(s[0]).Flair=s[1]; //2015.08.09. + } + br.close(); + } + //throw new IOException("Test"); //2015.08.09. + System.out.println("Auto-flair plugin loaded files!"); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + public static void SaveFiles() //<-- 2015.08.09. + { + try + { + FileWriter fw; + fw = new FileWriter("flairsaccepted.txt"); + fw.close(); + fw = new FileWriter("flairsignored.txt"); + fw.close(); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + try { + File file=new File("flairsaccepted.txt"); + BufferedWriter bw=new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.AcceptedFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + file=new File("flairsignored.txt"); + bw = new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.IgnoredFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + public static boolean RemoveLineFromFile(String file, String line) + { //2015.08.09. + File inputFile = new File(file); + File tempFile = new File("_temp.txt"); + + try { + BufferedReader reader = new BufferedReader(new FileReader(inputFile)); + BufferedWriter writer = new BufferedWriter(new FileWriter(tempFile)); + + String lineToRemove = line; + String currentLine; + + while((currentLine = reader.readLine()) != null) { + // trim newline when comparing with lineToRemove + String trimmedLine = currentLine.trim(); + //if(trimmedLine.equals(lineToRemove)) continue; + if(trimmedLine.contains(lineToRemove)) continue; //2015.08.09. + writer.write(currentLine + System.getProperty("line.separator")); + } + writer.close(); + reader.close(); + return tempFile.renameTo(inputFile); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + return false; + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/a1/1035b42cd23e001518fa86d7ae2a1cf8 b/.metadata/.plugins/org.eclipse.core.resources/.history/a1/1035b42cd23e001518fa86d7ae2a1cf8 new file mode 100644 index 0000000..3051444 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/a1/1035b42cd23e001518fa86d7ae2a1cf8 @@ -0,0 +1,376 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStream; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLConnection; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + +import org.apache.commons.io.IOUtils; +import org.bukkit.entity.Player; +import org.bukkit.plugin.java.JavaPlugin; +import org.json.JSONArray; +import org.json.JSONObject; + +import com.palmergames.bukkit.towny.object.Town; +import com.palmergames.bukkit.towny.object.WorldCoord; + +public class PluginMain extends JavaPlugin +{ //Translated to Java: 2015.07.15. + //A user, which flair isn't obtainable: + //https://www.reddit.com/r/thebutton/comments/31c32v/i_pressed_the_button_without_really_thinking/ + private static PluginMain Instance; + // Fired when plugin is first enabled + @Override + public void onEnable() + { + System.out.println("The Button Auto-flair Plugin by NorbiPeti (:P)"); + getServer().getPluginManager().registerEvents(new PlayerListener(), this); + this.getCommand("u").setExecutor(new Commands()); + this.getCommand("u").setUsage(this.getCommand("u").getUsage().replace('&', '§')); + Instance=this; //2015.08.08. + LoadFiles(false); //2015.08.09. + Runnable r=new Runnable(){public void run(){ThreadMethod();}}; + Thread t=new Thread(r); + t.start(); + } + Boolean stop=false; + // Fired when plugin is disabled + @Override + public void onDisable() + { + try + { + FileWriter fw; + fw = new FileWriter("flairsaccepted.txt"); + fw.close(); + fw = new FileWriter("flairsignored.txt"); + fw.close(); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + try { + File file=new File("flairsaccepted.txt"); + BufferedWriter bw=new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.AcceptedFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + file=new File("flairsignored.txt"); + bw = new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.IgnoredFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + stop=true; + } + + public void ThreadMethod() //<-- 2015.07.16. + { + while(!stop) + { + try + { + String body=DownloadString("https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/autoflair_system_comment_your_minecraft_name_and/.json?limit=1000"); + JSONArray json=new JSONArray(body).getJSONObject(1).getJSONObject("data").getJSONArray("children"); + for(Object obj : json) + { + JSONObject item = (JSONObject)obj; + String author=item.getJSONObject("data").getString("author"); + String ign=item.getJSONObject("data").getString("body"); + int start = ign.indexOf("IGN:") + "IGN:".length(); + int end = ign.indexOf(' ', start); + if (end == -1 || end == start) + end=ign.indexOf('\n', start); //2015.07.15. + if (end == -1 || end == start) + ign = ign.substring(start); + else + ign = ign.substring(start, end); + ign = ign.trim(); + if(HasIGFlair(ign)) + continue; + try { + Thread.sleep(10); + } catch(InterruptedException ex) { + Thread.currentThread().interrupt(); + } + String[] flairdata = DownloadString("http://karmadecay.com/thebutton-data.php?users=" + author).replace("\"", "").split(":"); + String flair; + if(flairdata.length > 1) //2015.07.15. + flair = flairdata[1]; + else + flair=""; + if (flair != "-1") + flair = flair + "s"; + else + flair = "non-presser"; + String flairclass; + if(flairdata.length>2) + flairclass = flairdata[2]; + else + flairclass="unknown"; + SetFlair(ign, flair, flairclass, author); + } + Thread.sleep(10000); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + } + + public static Exception LastException; //2015.08.09. + + public String DownloadString(String urlstr) throws MalformedURLException, IOException + { + URL url = new URL(urlstr); + URLConnection con = url.openConnection(); + con.setRequestProperty("User-Agent", "TheButtonAutoFlair"); + InputStream in = con.getInputStream(); + String encoding = con.getContentEncoding(); + encoding = encoding == null ? "UTF-8" : encoding; + String body = IOUtils.toString(in, encoding); + in.close(); + return body; + } + + public static Map TownColors=new HashMap(); //2015.07.20. + public Boolean HasIGFlair(String playername) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + return p.Flair!=null; //2015.08.08. + } + + public void SetFlair(String playername, String text, String flairclass, String username) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + String finalflair; + p.FlairDecided=true; + switch(flairclass) + { + case "press-1": + finalflair="§c("+text+")§r"; + break; + case "press-2": + finalflair="§6("+text+")§r"; + break; + case "press-3": + finalflair="§e("+text+")§r"; + break; + case "press-4": + finalflair="§a("+text+")§r"; + break; + case "press-5": + finalflair="§9("+text+")§r"; + break; + 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; + case "undecided": //2015.08.09. + p.FlairDecided=false; + finalflair=""; + break; + default: + finalflair=""; + break; + } + if(finalflair.length()==0) //<-- 2015.07.20. + return; + p.Flair=finalflair; //2015.08.08. + p.UserName=username; //2015.08.08. + System.out.println("Added new flair to "+playername+": "+finalflair); + for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08. + { + if(player.getName().equals(playername)) + { + //AppendPlayerDisplayFlair(player, username, finalflair); + AppendPlayerDisplayFlair(p, player); + break; + } + } + } + + public static String GetFlair(Player player) + { //2015.07.16. + String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08. + return flair==null ? "" : flair; + } + + //public static void AppendPlayerDisplayFlair(Player player, String username, String flair) + public static void AppendPlayerDisplayFlair(MaybeOfflinePlayer player, Player p) //<-- 2015.08.09. + { + + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).IgnoredFlair) + return; + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).AcceptedFlair) + { + AppendPlayerDisplayFlairFinal(p, player.Flair); //2015.07.20. + if(!player.FlairDecided) + p.sendMessage("§9Your flair type is unknown. Are you a non-presser or a can't press? (/u nonpresser or /u cantpress)§r"); //2015.08.09. + } + else + p.sendMessage("§9Are you Reddit user "+player.UserName+"?§r §6Type /u accept or /u ignore§r"); + } + + private static void AppendPlayerDisplayFlairFinal(Player player, String flair) + { //2015.07.20. + String color = GetColorForTown(GetPlayerTown(player)); //TO!DO: Multiple colors put on first capital letters + String[] colors = color.substring(1).split("§"); + String displayname=player.getName(); //2015.08.08. + ArrayList Positions=new ArrayList<>(); + for(int i=0; i=colors.length) + { + int x=0; + for(int i=0; i GetPlayers() + { + return Instance.getServer().getOnlinePlayers(); + } + + public static void LoadFiles(boolean reload) //<-- 2015.08.09. + { + if(reload) + { //2015.08.09. + System.out.println("Auto-flair plugin cleanup for reloading..."); + MaybeOfflinePlayer.AllPlayers.clear(); + TownColors.clear(); + } + System.out.println("Loading files for auto-flair plugin..."); //2015.08.09. + try { + File file=new File("flairsaccepted.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + //System.out.println("Name: " + name); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("flairsignored.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsignored.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("autoflairconfig.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + TownColors.put(s[0], s[1]); + } + br.close(); + } + //throw new IOException("Test"); //2015.08.09. + + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/a1/1076adccde3e001517108d149b613203 b/.metadata/.plugins/org.eclipse.core.resources/.history/a1/1076adccde3e001517108d149b613203 new file mode 100644 index 0000000..697a10d --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/a1/1076adccde3e001517108d149b613203 @@ -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.WorldCoord; + +public class PluginMain extends JavaPlugin +{ //Translated to Java: 2015.07.15. + //A user, which flair isn't obtainable: + //https://www.reddit.com/r/thebutton/comments/31c32v/i_pressed_the_button_without_really_thinking/ + private static PluginMain Instance; + // Fired when plugin is first enabled + @Override + public void onEnable() + { + System.out.println("The Button Auto-flair Plugin by NorbiPeti (:P)"); + getServer().getPluginManager().registerEvents(new PlayerListener(), this); + this.getCommand("u").setExecutor(new Commands()); + this.getCommand("u").setUsage(this.getCommand("u").getUsage().replace('&', '§')); + Instance=this; //2015.08.08. + LoadFiles(false); //2015.08.09. + Runnable r=new Runnable(){public void run(){ThreadMethod();}}; + Thread t=new Thread(r); + t.start(); + } + Boolean stop=false; + // Fired when plugin is disabled + @Override + public void onDisable() + { + SaveFiles(); //2015.08.09. + stop=true; + } + + public void ThreadMethod() //<-- 2015.07.16. + { + while(!stop) + { + try + { + String body=DownloadString("https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/autoflair_system_comment_your_minecraft_name_and/.json?limit=1000"); + JSONArray json=new JSONArray(body).getJSONObject(1).getJSONObject("data").getJSONArray("children"); + for(Object obj : json) + { + JSONObject item = (JSONObject)obj; + String author=item.getJSONObject("data").getString("author"); + String ign=item.getJSONObject("data").getString("body"); + int start = ign.indexOf("IGN:") + "IGN:".length(); + if(start==-1) + continue; //2015.08.09. + int end = ign.indexOf(' ', start); + if (end == -1 || end == start) + end=ign.indexOf('\n', start); //2015.07.15. + if (end == -1 || end == start) + ign = ign.substring(start); + else + ign = ign.substring(start, end); + ign = ign.trim(); + if(HasIGFlair(ign)) + continue; + try { + Thread.sleep(10); + } catch(InterruptedException ex) { + Thread.currentThread().interrupt(); + } + String[] flairdata = DownloadString("http://karmadecay.com/thebutton-data.php?users=" + author).replace("\"", "").split(":"); + String flair; + if(flairdata.length > 1) //2015.07.15. + flair = flairdata[1]; + else + flair=""; + if (flair != "-1") + flair = flair + "s"; + else + flair = "non-presser"; + String flairclass; + if(flairdata.length>2) + flairclass = flairdata[2]; + else + flairclass="unknown"; + SetFlair(ign, flair, flairclass, author); + } + Thread.sleep(10000); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + } + + public static Exception LastException; //2015.08.09. + + public String DownloadString(String urlstr) throws MalformedURLException, IOException + { + URL url = new URL(urlstr); + URLConnection con = url.openConnection(); + con.setRequestProperty("User-Agent", "TheButtonAutoFlair"); + InputStream in = con.getInputStream(); + String encoding = con.getContentEncoding(); + encoding = encoding == null ? "UTF-8" : encoding; + String body = IOUtils.toString(in, encoding); + in.close(); + return body; + } + + public static Map TownColors=new HashMap(); //2015.07.20. + public Boolean HasIGFlair(String playername) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + return p.Flair!=null; //2015.08.08. + } + + public void SetFlair(String playername, String text, String flairclass, String username) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + String finalflair; + p.FlairDecided=true; + switch(flairclass) + { + case "press-1": + finalflair="§c("+text+")§r"; + break; + case "press-2": + finalflair="§6("+text+")§r"; + break; + case "press-3": + finalflair="§e("+text+")§r"; + break; + case "press-4": + finalflair="§a("+text+")§r"; + break; + case "press-5": + finalflair="§9("+text+")§r"; + break; + 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; + case "undecided": //2015.08.09. + p.FlairDecided=false; + finalflair=""; + break; + default: + finalflair=""; + break; + } + if(finalflair.length()==0) //<-- 2015.07.20. + return; + p.Flair=finalflair; //2015.08.08. + p.UserName=username; //2015.08.08. + System.out.println("Added new flair to "+playername+": "+finalflair); + for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08. + { + if(player.getName().equals(playername)) + { + //AppendPlayerDisplayFlair(player, username, finalflair); + AppendPlayerDisplayFlair(p, player); + break; + } + } + } + + public static String GetFlair(Player player) + { //2015.07.16. + String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08. + return flair==null ? "" : flair; + } + + //public static void AppendPlayerDisplayFlair(Player player, String username, String flair) + public static void AppendPlayerDisplayFlair(MaybeOfflinePlayer player, Player p) //<-- 2015.08.09. + { + + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).IgnoredFlair) + return; + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).AcceptedFlair) + { + AppendPlayerDisplayFlairFinal(p, player.Flair); //2015.07.20. + if(!player.FlairDecided) + p.sendMessage("§9Your flair type is unknown. Are you a non-presser or a can't press? (/u nonpresser or /u cantpress)§r"); //2015.08.09. + } + else + p.sendMessage("§9Are you Reddit user "+player.UserName+"?§r §6Type /u accept or /u ignore§r"); + } + + private static void AppendPlayerDisplayFlairFinal(Player player, String flair) + { //2015.07.20. + String color = GetColorForTown(GetPlayerTown(player)); //TO!DO: Multiple colors put on first capital letters + String[] colors = color.substring(1).split("§"); + String displayname=player.getName(); //2015.08.08. + ArrayList Positions=new ArrayList<>(); + for(int i=0; i=colors.length) + { + int x=0; + for(int i=0; i GetPlayers() + { + return Instance.getServer().getOnlinePlayers(); + } + + public static void LoadFiles(boolean reload) //<-- 2015.08.09. + { + if(reload) + { //2015.08.09. + System.out.println("Auto-flair plugin cleanup for reloading..."); + MaybeOfflinePlayer.AllPlayers.clear(); + TownColors.clear(); + } + System.out.println("Loading files for auto-flair plugin..."); //2015.08.09. + try { + File file=new File("flairsaccepted.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + //System.out.println("Name: " + name); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("flairsignored.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsignored.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("autoflairconfig.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + TownColors.put(s[0], s[1]); + } + br.close(); + } + file=new File("customflairs.txt"); //2015.08.09. + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + MaybeOfflinePlayer.AddPlayerIfNeeded(s[0]).Flair=s[1]; //2015.08.09. + } + br.close(); + } + //throw new IOException("Test"); //2015.08.09. + System.out.println("Auto-flair plugin loaded files!"); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + public static void SaveFiles() //<-- 2015.08.09. + { + try + { + FileWriter fw; + fw = new FileWriter("flairsaccepted.txt"); + fw.close(); + fw = new FileWriter("flairsignored.txt"); + fw.close(); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + try { + File file=new File("flairsaccepted.txt"); + BufferedWriter bw=new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.AcceptedFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + file=new File("flairsignored.txt"); + bw = new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.IgnoredFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + public static void SetPlayerFlair(Player player, String flair) + { //2015.08.09. + flair=flair.replace('&', '§'); + MaybeOfflinePlayer.AddPlayerIfNeeded(player.getName()).Flair=flair; + File file=new File("customflairs.txt"); + try { + BufferedWriter bw; + bw = new BufferedWriter(new FileWriter(file, true)); + bw.write(player.getName()+"\n"); + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + public static boolean RemoveLineFromFile(String file) + { + File inputFile = new File(file); + File tempFile = new File("_temp.txt"); + + try { + BufferedReader reader = new BufferedReader(new FileReader(inputFile)); + BufferedWriter writer = new BufferedWriter(new FileWriter(tempFile)); + + String lineToRemove = "bbb"; + String currentLine; + + while((currentLine = reader.readLine()) != null) { + // trim newline when comparing with lineToRemove + String trimmedLine = currentLine.trim(); + if(trimmedLine.equals(lineToRemove)) continue; + writer.write(currentLine + System.getProperty("line.separator")); + } + writer.close(); + reader.close(); + return tempFile.renameTo(inputFile); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + return false; + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/a1/a05e6526d23e001518fa86d7ae2a1cf8 b/.metadata/.plugins/org.eclipse.core.resources/.history/a1/a05e6526d23e001518fa86d7ae2a1cf8 new file mode 100644 index 0000000..7d30f89 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/a1/a05e6526d23e001518fa86d7ae2a1cf8 @@ -0,0 +1,375 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStream; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLConnection; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + +import org.apache.commons.io.IOUtils; +import org.bukkit.entity.Player; +import org.bukkit.plugin.java.JavaPlugin; +import org.json.JSONArray; +import org.json.JSONObject; + +import com.palmergames.bukkit.towny.object.Town; +import com.palmergames.bukkit.towny.object.WorldCoord; + +public class PluginMain extends JavaPlugin +{ //Translated to Java: 2015.07.15. + //A user, which flair isn't obtainable: + //https://www.reddit.com/r/thebutton/comments/31c32v/i_pressed_the_button_without_really_thinking/ + private static PluginMain Instance; + // Fired when plugin is first enabled + @Override + public void onEnable() + { + System.out.println("The Button Auto-flair Plugin by NorbiPeti (:P)"); + getServer().getPluginManager().registerEvents(new PlayerListener(), this); + this.getCommand("u").setExecutor(new Commands()); + this.getCommand("u").setUsage(this.getCommand("u").getUsage().replace('&', '§')); + Instance=this; //2015.08.08. + LoadFiles(false); //2015.08.09. + Runnable r=new Runnable(){public void run(){ThreadMethod();}}; + Thread t=new Thread(r); + t.start(); + } + Boolean stop=false; + // Fired when plugin is disabled + @Override + public void onDisable() + { + try + { + FileWriter fw; + fw = new FileWriter("flairsaccepted.txt"); + fw.close(); + fw = new FileWriter("flairsignored.txt"); + fw.close(); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + try { + File file=new File("flairsaccepted.txt"); + BufferedWriter bw=new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.AcceptedFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + file=new File("flairsignored.txt"); + bw = new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.IgnoredFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + stop=true; + } + + public void ThreadMethod() //<-- 2015.07.16. + { + while(!stop) + { + try + { + String body=DownloadString("https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/autoflair_system_comment_your_minecraft_name_and/.json?limit=1000"); + JSONArray json=new JSONArray(body).getJSONObject(1).getJSONObject("data").getJSONArray("children"); + for(Object obj : json) + { + JSONObject item = (JSONObject)obj; + String author=item.getJSONObject("data").getString("author"); + String ign=item.getJSONObject("data").getString("body"); + int start = ign.indexOf("IGN:") + "IGN:".length(); + int end = ign.indexOf(' ', start); + if (end == -1 || end == start) + end=ign.indexOf('\n', start); //2015.07.15. + if (end == -1 || end == start) + ign = ign.substring(start); + else + ign = ign.substring(start, end); + ign = ign.trim(); + if(HasIGFlair(ign)) + continue; + try { + Thread.sleep(10); + } catch(InterruptedException ex) { + Thread.currentThread().interrupt(); + } + String[] flairdata = DownloadString("http://karmadecay.com/thebutton-data.php?users=" + author).replace("\"", "").split(":"); + String flair; + if(flairdata.length > 1) //2015.07.15. + flair = flairdata[1]; + else + flair=""; + if (flair != "-1") + flair = flair + "s"; + else + flair = "non-presser"; + String flairclass; + if(flairdata.length>2) + flairclass = flairdata[2]; + else + flairclass="unknown"; + SetFlair(ign, flair, flairclass, author); + } + Thread.sleep(10000); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + } + + public static Exception LastException; //2015.08.09. + + public String DownloadString(String urlstr) throws MalformedURLException, IOException + { + URL url = new URL(urlstr); + URLConnection con = url.openConnection(); + con.setRequestProperty("User-Agent", "TheButtonAutoFlair"); + InputStream in = con.getInputStream(); + String encoding = con.getContentEncoding(); + encoding = encoding == null ? "UTF-8" : encoding; + String body = IOUtils.toString(in, encoding); + in.close(); + return body; + } + + public static Map TownColors=new HashMap(); //2015.07.20. + public Boolean HasIGFlair(String playername) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + return p.Flair!=null; //2015.08.08. + } + + public void SetFlair(String playername, String text, String flairclass, String username) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + String finalflair; + p.FlairDecided=true; + switch(flairclass) + { + case "press-1": + finalflair="§c("+text+")§r"; + break; + case "press-2": + finalflair="§6("+text+")§r"; + break; + case "press-3": + finalflair="§e("+text+")§r"; + break; + case "press-4": + finalflair="§a("+text+")§r"; + break; + case "press-5": + finalflair="§9("+text+")§r"; + break; + 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; + case "undecided": //2015.08.09. + p.FlairDecided=false; + finalflair=""; + break; + default: + finalflair=""; + break; + } + if(finalflair.length()==0) //<-- 2015.07.20. + return; + p.Flair=finalflair; //2015.08.08. + p.UserName=username; //2015.08.08. + System.out.println("Added new flair to "+playername+": "+finalflair); + for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08. + { + if(player.getName().equals(playername)) + { + //AppendPlayerDisplayFlair(player, username, finalflair); + AppendPlayerDisplayFlair(p, player); + break; + } + } + } + + public static String GetFlair(Player player) + { //2015.07.16. + String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08. + return flair==null ? "" : flair; + } + + //public static void AppendPlayerDisplayFlair(Player player, String username, String flair) + public static void AppendPlayerDisplayFlair(MaybeOfflinePlayer player, Player p) //<-- 2015.08.09. + { + + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).IgnoredFlair) + return; + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).AcceptedFlair) + { + AppendPlayerDisplayFlairFinal(p, player.Flair); //2015.07.20. + if(!player.FlairDecided) + p.sendMessage("§9Your flair type is unknown. Are you a non-presser or a can't press? (/u nonpresser or /u cantpress)§r"); //2015.08.09. + } + else + p.sendMessage("§9Are you Reddit user "+player.UserName+"?§r §6Type /u accept or /u ignore§r"); + } + + private static void AppendPlayerDisplayFlairFinal(Player player, String flair) + { //2015.07.20. + String color = GetColorForTown(GetPlayerTown(player)); //TO!DO: Multiple colors put on first capital letters + String[] colors = color.substring(1).split("§"); + String displayname=player.getName(); //2015.08.08. + ArrayList Positions=new ArrayList<>(); + for(int i=0; i=colors.length) + { + int x=0; + for(int i=0; i GetPlayers() + { + return Instance.getServer().getOnlinePlayers(); + } + + public static void LoadFiles(boolean reload) //<-- 2015.08.09. + { + if(reload) + { //2015.08.09. + System.out.println("Auto-flair plugin cleanup for reloading..."); + MaybeOfflinePlayer.AllPlayers.clear(); + TownColors.clear(); + } + System.out.println("Loading files for auto-flair plugin..."); //2015.08.09. + try { + File file=new File("flairsaccepted.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + //System.out.println("Name: " + name); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("flairsignored.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsignored.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("autoflairconfig.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + TownColors.put(s[0], s[1]); + } + br.close(); + } + //throw new IOException("Test"); //2015.08.09. + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/a2/206c0ba2d23e001518fa86d7ae2a1cf8 b/.metadata/.plugins/org.eclipse.core.resources/.history/a2/206c0ba2d23e001518fa86d7ae2a1cf8 new file mode 100644 index 0000000..23364ef --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/a2/206c0ba2d23e001518fa86d7ae2a1cf8 @@ -0,0 +1,222 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; + +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class Commands implements CommandExecutor { + // This method is called, when somebody uses our command + @Override + public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { + if (sender instanceof Player) { + Player player = (Player) sender; + if(args.length<1) + return false; + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. + //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) + if(p.Flair==null) + { + player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); + return true; + } + switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. + { + case "accept": + { + if(p.IgnoredFlair) + p.IgnoredFlair=false; //2015.08.08. + if(!p.AcceptedFlair) + { + String flair=p.Flair; //2015.08.08. + //PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + PluginMain.AppendPlayerDisplayFlair(p, player); + p.AcceptedFlair=true; //2015.08.08. + player.sendMessage("§6Your flair has been set:§r "+flair); + } + else + player.sendMessage("§cYou already have this user's flair.§r"); + break; + } + case "ignore": + { + if(p.AcceptedFlair) + p.AcceptedFlair=false; //2015.08.08. + if(!p.IgnoredFlair) + { + p.IgnoredFlair=true; + String flair=p.Flair; //2015.08.08. + PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. + player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); + } + else + player.sendMessage("§cYou already ignored this request.§r"); + break; + } + /*case "reload": //2015.07.20. + DoReload(player); + break;*/ + case "admin": //2015.08.09. + DoAdmin(player, args); + break; + case "nonpresser": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§7(non-pr.)§r"; + break; + case "cantpress": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§r(can't press)§r"; + break; + default: + return false; + } + return true; + } + /*if(args[0].toLowerCase()=="reload") + DoReload(null); //2015.07.20.*/ + else if(args.length>0 && args[0].toLowerCase().equals("admin")) //2015.08.09. + { + DoAdmin(null, args); //2015.08.09. + return true; //2015.08.09. + } + return false; + } + private static void DoReload(Player player) + { //2015.07.20. + //if(player==null || player.isOp() || player.getName()=="NorbiPeti") + //{ + try + { + File file=new File("autoflairconfig.txt"); + if(file.exists()) + { + PluginMain.TownColors.clear(); + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + PluginMain.TownColors.put(s[0], s[1]); + } + br.close(); + for(Player p : PluginMain.GetPlayers()) + { + MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName()); + if(mp.Flair!=null) + { + String flair=mp.Flair; + PluginMain.RemovePlayerDisplayFlairFinal(p, flair); + //PluginMain.AppendPlayerDisplayFlairFinal(p, flair); + PluginMain.AppendPlayerDisplayFlair(mp, p); //2015.08.09. + } + } + String msg="§6Reloaded config file.§r"; + SendMessage(player, msg); //2015.08.09. + } + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + if(player!=null) + player.sendMessage("§cAn error occured. See console for details.§r"); + PluginMain.LastException=e; //2015.08.09. + } + //} + //else + //player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static void DoAdmin(Player player, String[] args) + { //2015.08.09. + if(player==null || player.isOp() || player.getName()=="NorbiPeti") + { + //System.out.println("Args length: " + args.length); + if(args.length==1) + { + String message="§cUsage: /u admin reload|playerinfo§r"; + SendMessage(player, message); + return; + } + //args[0] is "admin" + switch(args[1].toLowerCase()) + { + case "reload": + DoReload(player); + break; + case "playerinfo": + DoPlayerInfo(player, args); + break; + case "getlasterror": + DoGetLastError(player, args); + default: + String message="§cUsage: /u admin reload|playerinfo§r"; + SendMessage(player, message); + return; + } + } + else + player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static void DoPlayerInfo(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "playerinfo" + if(args.length==2) + { + String message="§cUsage: /u admin playerinfo §r"; + SendMessage(player, message); + return; + } + if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2])) + { + String message="§cPlayer not found: "+args[2]+"§r"; + SendMessage(player, message); + return; + } + MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]); + SendMessage(player, "Player name: "+p.PlayerName); + SendMessage(player, "User flair: "+p.Flair); + SendMessage(player, "Username: "+p.UserName); + SendMessage(player, "Flair accepted: "+p.AcceptedFlair); + SendMessage(player, "Flair ignored: "+p.IgnoredFlair); + } + private static void SendMessage(Player player, String message) + { //2015.08.09. + if(player==null) + System.out.println(message); + else + player.sendMessage(message); + } + private static void DoGetLastError(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "getlasterror" + if(PluginMain.LastException!=null) + { + SendMessage(player, "Last error:"); + SendMessage(player, PluginMain.LastException.toString()); + PluginMain.LastException=null; + } + else + SendMessage(player, "There were no exceptions."); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/a2/20ecb1f0d03e001518fa86d7ae2a1cf8 b/.metadata/.plugins/org.eclipse.core.resources/.history/a2/20ecb1f0d03e001518fa86d7ae2a1cf8 new file mode 100644 index 0000000..41fefc9 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/a2/20ecb1f0d03e001518fa86d7ae2a1cf8 @@ -0,0 +1,211 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; + +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class Commands implements CommandExecutor { + // This method is called, when somebody uses our command + @Override + public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { + if (sender instanceof Player) { + Player player = (Player) sender; + if(args.length<1) + return false; + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. + //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) + if(p.Flair==null) + { + player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); + return true; + } + switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. + { + case "accept": + { + if(p.IgnoredFlair) + p.IgnoredFlair=false; //2015.08.08. + if(!p.AcceptedFlair) + { + String flair=p.Flair; //2015.08.08. + //PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + PluginMain.AppendPlayerDisplayFlair(p, player); + p.AcceptedFlair=true; //2015.08.08. + player.sendMessage("§6Your flair has been set:§r "+flair); + } + else + player.sendMessage("§cYou already have this user's flair.§r"); + break; + } + case "ignore": + { + if(p.AcceptedFlair) + p.AcceptedFlair=false; //2015.08.08. + if(!p.IgnoredFlair) + { + p.IgnoredFlair=true; + String flair=p.Flair; //2015.08.08. + PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. + player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); + } + else + player.sendMessage("§cYou already ignored this request.§r"); + break; + } + /*case "reload": //2015.07.20. + DoReload(player); + break;*/ + case "admin": //2015.08.09. + DoAdmin(player, args); + break; + case "nonpresser": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§7(non-pr.)§r"; + break; + case "cantpress": //2015.08.09. + break; + default: + return false; + } + return true; + } + /*if(args[0].toLowerCase()=="reload") + DoReload(null); //2015.07.20.*/ + else if(args.length>0 && args[0].toLowerCase().equals("admin")) //2015.08.09. + { + DoAdmin(null, args); //2015.08.09. + return true; //2015.08.09. + } + return false; + } + private static void DoReload(Player player) + { //2015.07.20. + //if(player==null || player.isOp() || player.getName()=="NorbiPeti") + //{ + try + { + File file=new File("autoflairconfig.txt"); + if(file.exists()) + { + PluginMain.TownColors.clear(); + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + PluginMain.TownColors.put(s[0], s[1]); + } + br.close(); + for(Player p : PluginMain.GetPlayers()) + { + MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName()); + if(mp.Flair!=null) + { + String flair=mp.Flair; + PluginMain.RemovePlayerDisplayFlairFinal(p, flair); + //PluginMain.AppendPlayerDisplayFlairFinal(p, flair); + PluginMain.AppendPlayerDisplayFlair(mp, p); //2015.08.09. + } + } + String msg="§6Reloaded config file.§r"; + SendMessage(player, msg); //2015.08.09. + } + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + if(player!=null) + player.sendMessage("§cAn error occured. See console for details.§r"); + PluginMain.LastException=e; //2015.08.09. + } + //} + //else + //player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static void DoAdmin(Player player, String[] args) + { //2015.08.09. + if(player==null || player.isOp() || player.getName()=="NorbiPeti") + { + //System.out.println("Args length: " + args.length); + if(args.length==1) + { + String message="§cUsage: /u admin reload|playerinfo§r"; + SendMessage(player, message); + return; + } + //args[0] is "admin" + switch(args[1].toLowerCase()) + { + case "reload": + DoReload(player); + break; + case "playerinfo": + DoPlayerInfo(player, args); + break; + case "getlasterror": + DoGetLastError(player, args); + default: + String message="§cUsage: /u admin reload|playerinfo§r"; + SendMessage(player, message); + return; + } + } + else + player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static void DoPlayerInfo(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "playerinfo" + if(args.length==2) + { + String message="§cUsage: /u admin playerinfo §r"; + SendMessage(player, message); + return; + } + if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2])) + { + String message="§cPlayer not found: "+args[2]+"§r"; + SendMessage(player, message); + return; + } + MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]); + SendMessage(player, "Player name: "+p.PlayerName); + SendMessage(player, "User flair: "+p.Flair); + SendMessage(player, "Username: "+p.UserName); + SendMessage(player, "Flair accepted: "+p.AcceptedFlair); + SendMessage(player, "Flair ignored: "+p.IgnoredFlair); + } + private static void SendMessage(Player player, String message) + { //2015.08.09. + if(player==null) + System.out.println(message); + else + player.sendMessage(message); + } + private static void DoGetLastError(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "getlasterror" + if(PluginMain.LastException!=null) + { + SendMessage(player, "Last error:"); + SendMessage(player, PluginMain.LastException.toString()); + PluginMain.LastException=null; + } + else + SendMessage(player, "There were no exceptions."); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/a2/900097abde3e001517108d149b613203 b/.metadata/.plugins/org.eclipse.core.resources/.history/a2/900097abde3e001517108d149b613203 new file mode 100644 index 0000000..e1431c6 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/a2/900097abde3e001517108d149b613203 @@ -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.WorldCoord; + +public class PluginMain extends JavaPlugin +{ //Translated to Java: 2015.07.15. + //A user, which flair isn't obtainable: + //https://www.reddit.com/r/thebutton/comments/31c32v/i_pressed_the_button_without_really_thinking/ + private static PluginMain Instance; + // Fired when plugin is first enabled + @Override + public void onEnable() + { + System.out.println("The Button Auto-flair Plugin by NorbiPeti (:P)"); + getServer().getPluginManager().registerEvents(new PlayerListener(), this); + this.getCommand("u").setExecutor(new Commands()); + this.getCommand("u").setUsage(this.getCommand("u").getUsage().replace('&', '§')); + Instance=this; //2015.08.08. + LoadFiles(false); //2015.08.09. + Runnable r=new Runnable(){public void run(){ThreadMethod();}}; + Thread t=new Thread(r); + t.start(); + } + Boolean stop=false; + // Fired when plugin is disabled + @Override + public void onDisable() + { + SaveFiles(); //2015.08.09. + stop=true; + } + + public void ThreadMethod() //<-- 2015.07.16. + { + while(!stop) + { + try + { + String body=DownloadString("https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/autoflair_system_comment_your_minecraft_name_and/.json?limit=1000"); + JSONArray json=new JSONArray(body).getJSONObject(1).getJSONObject("data").getJSONArray("children"); + for(Object obj : json) + { + JSONObject item = (JSONObject)obj; + String author=item.getJSONObject("data").getString("author"); + String ign=item.getJSONObject("data").getString("body"); + int start = ign.indexOf("IGN:") + "IGN:".length(); + if(start==-1) + continue; //2015.08.09. + int end = ign.indexOf(' ', start); + if (end == -1 || end == start) + end=ign.indexOf('\n', start); //2015.07.15. + if (end == -1 || end == start) + ign = ign.substring(start); + else + ign = ign.substring(start, end); + ign = ign.trim(); + if(HasIGFlair(ign)) + continue; + try { + Thread.sleep(10); + } catch(InterruptedException ex) { + Thread.currentThread().interrupt(); + } + String[] flairdata = DownloadString("http://karmadecay.com/thebutton-data.php?users=" + author).replace("\"", "").split(":"); + String flair; + if(flairdata.length > 1) //2015.07.15. + flair = flairdata[1]; + else + flair=""; + if (flair != "-1") + flair = flair + "s"; + else + flair = "non-presser"; + String flairclass; + if(flairdata.length>2) + flairclass = flairdata[2]; + else + flairclass="unknown"; + SetFlair(ign, flair, flairclass, author); + } + Thread.sleep(10000); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + } + + public static Exception LastException; //2015.08.09. + + public String DownloadString(String urlstr) throws MalformedURLException, IOException + { + URL url = new URL(urlstr); + URLConnection con = url.openConnection(); + con.setRequestProperty("User-Agent", "TheButtonAutoFlair"); + InputStream in = con.getInputStream(); + String encoding = con.getContentEncoding(); + encoding = encoding == null ? "UTF-8" : encoding; + String body = IOUtils.toString(in, encoding); + in.close(); + return body; + } + + public static Map TownColors=new HashMap(); //2015.07.20. + public Boolean HasIGFlair(String playername) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + return p.Flair!=null; //2015.08.08. + } + + public void SetFlair(String playername, String text, String flairclass, String username) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + String finalflair; + p.FlairDecided=true; + switch(flairclass) + { + case "press-1": + finalflair="§c("+text+")§r"; + break; + case "press-2": + finalflair="§6("+text+")§r"; + break; + case "press-3": + finalflair="§e("+text+")§r"; + break; + case "press-4": + finalflair="§a("+text+")§r"; + break; + case "press-5": + finalflair="§9("+text+")§r"; + break; + 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; + case "undecided": //2015.08.09. + p.FlairDecided=false; + finalflair=""; + break; + default: + finalflair=""; + break; + } + if(finalflair.length()==0) //<-- 2015.07.20. + return; + p.Flair=finalflair; //2015.08.08. + p.UserName=username; //2015.08.08. + System.out.println("Added new flair to "+playername+": "+finalflair); + for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08. + { + if(player.getName().equals(playername)) + { + //AppendPlayerDisplayFlair(player, username, finalflair); + AppendPlayerDisplayFlair(p, player); + break; + } + } + } + + public static String GetFlair(Player player) + { //2015.07.16. + String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08. + return flair==null ? "" : flair; + } + + //public static void AppendPlayerDisplayFlair(Player player, String username, String flair) + public static void AppendPlayerDisplayFlair(MaybeOfflinePlayer player, Player p) //<-- 2015.08.09. + { + + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).IgnoredFlair) + return; + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).AcceptedFlair) + { + AppendPlayerDisplayFlairFinal(p, player.Flair); //2015.07.20. + if(!player.FlairDecided) + p.sendMessage("§9Your flair type is unknown. Are you a non-presser or a can't press? (/u nonpresser or /u cantpress)§r"); //2015.08.09. + } + else + p.sendMessage("§9Are you Reddit user "+player.UserName+"?§r §6Type /u accept or /u ignore§r"); + } + + private static void AppendPlayerDisplayFlairFinal(Player player, String flair) + { //2015.07.20. + String color = GetColorForTown(GetPlayerTown(player)); //TO!DO: Multiple colors put on first capital letters + String[] colors = color.substring(1).split("§"); + String displayname=player.getName(); //2015.08.08. + ArrayList Positions=new ArrayList<>(); + for(int i=0; i=colors.length) + { + int x=0; + for(int i=0; i GetPlayers() + { + return Instance.getServer().getOnlinePlayers(); + } + + public static void LoadFiles(boolean reload) //<-- 2015.08.09. + { + if(reload) + { //2015.08.09. + System.out.println("Auto-flair plugin cleanup for reloading..."); + MaybeOfflinePlayer.AllPlayers.clear(); + TownColors.clear(); + } + System.out.println("Loading files for auto-flair plugin..."); //2015.08.09. + try { + File file=new File("flairsaccepted.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + //System.out.println("Name: " + name); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("flairsignored.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsignored.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("autoflairconfig.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + TownColors.put(s[0], s[1]); + } + br.close(); + } + file=new File("customflairs.txt"); //2015.08.09. + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + MaybeOfflinePlayer.AddPlayerIfNeeded(s[0]).Flair=s[1]; //2015.08.09. + } + br.close(); + } + //throw new IOException("Test"); //2015.08.09. + System.out.println("Auto-flair plugin loaded files!"); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + public static void SaveFiles() //<-- 2015.08.09. + { + try + { + FileWriter fw; + fw = new FileWriter("flairsaccepted.txt"); + fw.close(); + fw = new FileWriter("flairsignored.txt"); + fw.close(); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + try { + File file=new File("flairsaccepted.txt"); + BufferedWriter bw=new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.AcceptedFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + file=new File("flairsignored.txt"); + bw = new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.IgnoredFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + public static void SetPlayerFlair(Player player, String flair) + { //2015.08.09. + flair=flair.replace('&', '§'); + MaybeOfflinePlayer.AddPlayerIfNeeded(player.getName()).Flair=flair; + File file=new File("customflairs.txt"); + try { + BufferedWriter bw; + bw = new BufferedWriter(new FileWriter(file, true)); + bw.write(player.getName()+"\n"); + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + public static void RemoveLineFromFile(String file) + { + File inputFile = new File(file); + File tempFile = new File("_temp.txt"); + + try { + BufferedReader reader = new BufferedReader(new FileReader(inputFile)); + BufferedWriter writer = new BufferedWriter(new FileWriter(tempFile)); + + String lineToRemove = "bbb"; + String currentLine; + + while((currentLine = reader.readLine()) != null) { + // trim newline when comparing with lineToRemove + String trimmedLine = currentLine.trim(); + if(trimmedLine.equals(lineToRemove)) continue; + writer.write(currentLine + System.getProperty("line.separator")); + } + writer.close(); + reader.close(); + tempFile.renameTo(inputFile); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/a3/00bc291adf3e001517108d149b613203 b/.metadata/.plugins/org.eclipse.core.resources/.history/a3/00bc291adf3e001517108d149b613203 new file mode 100644 index 0000000..eac777b --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/a3/00bc291adf3e001517108d149b613203 @@ -0,0 +1,250 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +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; + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. + //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) + if(p.Flair==null) + { + player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); + return true; + } + switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. + { + case "accept": + { + if(p.IgnoredFlair) + p.IgnoredFlair=false; //2015.08.08. + if(!p.AcceptedFlair) + { + String flair=p.Flair; //2015.08.08. + //PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + PluginMain.AppendPlayerDisplayFlair(p, player); + p.AcceptedFlair=true; //2015.08.08. + player.sendMessage("§6Your flair has been set:§r "+flair); + } + else + player.sendMessage("§cYou already have this user's flair.§r"); + break; + } + case "ignore": + { + if(p.AcceptedFlair) + p.AcceptedFlair=false; //2015.08.08. + if(!p.IgnoredFlair) + { + p.IgnoredFlair=true; + String flair=p.Flair; //2015.08.08. + PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. + player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); + } + else + player.sendMessage("§cYou already ignored this request.§r"); + break; + } + /*case "reload": //2015.07.20. + DoReload(player); + break;*/ + case "admin": //2015.08.09. + DoAdmin(player, args); + break; + case "nonpresser": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§7(non-pr.)§r"; + break; + case "cantpress": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§r(can't press)§r"; + break; + default: + return false; + } + return true; + } + /*if(args[0].toLowerCase()=="reload") + DoReload(null); //2015.07.20.*/ + else if(args.length>0 && args[0].toLowerCase().equals("admin")) //2015.08.09. + { + DoAdmin(null, args); //2015.08.09. + return true; //2015.08.09. + } + return false; + } + private static void DoReload(Player player) + { //2015.07.20. + //if(player==null || player.isOp() || player.getName()=="NorbiPeti") + //{ + try + { + File file=new File("autoflairconfig.txt"); + if(file.exists()) + { + PluginMain.LoadFiles(true); //2015.08.09. + for(Player p : PluginMain.GetPlayers()) + { + MaybeOfflinePlayer mp = MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName()); + if(mp.Flair!=null) + { + String flair=mp.Flair; + PluginMain.RemovePlayerDisplayFlairFinal(p, flair); + //PluginMain.AppendPlayerDisplayFlairFinal(p, flair); + PluginMain.AppendPlayerDisplayFlair(mp, p); //2015.08.09. + } + String msg="§6Note: The auto-flair plugin has been reloaded. You might need to wait 10s to have your flair.§r"; //2015.08.09. + p.sendMessage(msg); //2015.08.09. + } + //String msg="§6Reloaded config file.§r"; + //SendMessage(player, msg); //2015.08.09. + } + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + if(player!=null) + player.sendMessage("§cAn error occured. See console for details.§r"); + PluginMain.LastException=e; //2015.08.09. + } + //} + //else + //player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static Player ReloadPlayer; //2015.08.09. + private static void DoAdmin(Player player, String[] args) + { //2015.08.09. + if(player==null || player.isOp() || player.getName()=="NorbiPeti") + { + //System.out.println("Args length: " + args.length); + if(args.length==1) + { + String message="§cUsage: /u admin reload|playerinfo§r"; + SendMessage(player, message); + return; + } + //args[0] is "admin" + switch(args[1].toLowerCase()) + { + case "reload": + ReloadPlayer=player; //2015.08.09. + SendMessage(player, "§6Make sure to save the current settings before you modify and reload them! Type /u admin confirm when done.§r"); + break; + case "playerinfo": + DoPlayerInfo(player, args); + break; + case "getlasterror": + DoGetLastError(player, args); + case "confirm": + if(ReloadPlayer==player) + DoReload(player); //2015.08.09. + else + SendMessage(player, "§cYou need to do /u admin reload first.§r"); + break; + case "save": + PluginMain.SaveFiles(); //2015.08.09. + SendMessage(player, "§6Saved files. Now you can edit them and reload if you want.§r"); + break; + default: + String message="§cUsage: /u admin reload|playerinfo|getlasterror§r"; + SendMessage(player, message); + return; + } + } + else + player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static void DoPlayerInfo(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "playerinfo" + if(args.length==2) + { + String message="§cUsage: /u admin playerinfo §r"; + SendMessage(player, message); + return; + } + if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2])) + { + String message="§cPlayer not found: "+args[2]+"§r"; + SendMessage(player, message); + return; + } + MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]); + SendMessage(player, "Player name: "+p.PlayerName); + SendMessage(player, "User flair: "+p.Flair); + SendMessage(player, "Username: "+p.UserName); + SendMessage(player, "Flair accepted: "+p.AcceptedFlair); + SendMessage(player, "Flair ignored: "+p.IgnoredFlair); + } + private static void SendMessage(Player player, String message) + { //2015.08.09. + if(player==null) + System.out.println(message); + else + player.sendMessage(message); + } + private static void DoGetLastError(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "getlasterror" + if(PluginMain.LastException!=null) + { + SendMessage(player, "Last error:"); + SendMessage(player, PluginMain.LastException.toString()); + PluginMain.LastException=null; + } + else + SendMessage(player, "There were no exceptions."); + } + private static void SetPlayerFlair(Player player, String flair) + { //2015.08.09. + flair=flair.replace('&', '§'); + MaybeOfflinePlayer.AddPlayerIfNeeded(player.getName()).Flair=flair; + if(!PluginMain.RemoveLineFromFile("customflairs.txt")) + { + SendMessage(player, "Error removing previous custom flair!"); + } + File file=new File("customflairs.txt"); + try { + BufferedWriter bw; + bw = new BufferedWriter(new FileWriter(file, true)); + bw.write(player.getName()+"\n"); + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + PluginMain.LastException=e; //2015.08.09. + } + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/a3/e09f3eb6883e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/a3/e09f3eb6883e00151ce8ff6d4f74dabd deleted file mode 100644 index f48b09f..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/a3/e09f3eb6883e00151ce8ff6d4f74dabd +++ /dev/null @@ -1,177 +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; - MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. - //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - if(p.Flair==null) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. - { - case "accept": - { - if(p.IgnoredFlair) - p.IgnoredFlair=false; //2015.08.08. - if(!p.AcceptedFlair) - { - String flair=p.Flair; //2015.08.08. - PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. - p.AcceptedFlair=true; //2015.08.08. - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("§cYou already have this user's flair.§r"); - break; - } - case "ignore": - { - if(p.AcceptedFlair) - p.AcceptedFlair=false; //2015.08.08. - if(!p.IgnoredFlair) - { - p.IgnoredFlair=true; - String flair=p.Flair; //2015.08.08. - PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. - player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); - } - else - player.sendMessage("§cYou already ignored this request.§r"); - break; - } - /*case "reload": //2015.07.20. - DoReload(player); - break;*/ - case "admin": //2015.08.09. - DoAdmin(player, args); - break; - default: - return false; - } - return true; - } - - /*if(args[0].toLowerCase()=="reload") - DoReload(null); //2015.07.20.*/ - else if(args[0].toLowerCase()=="admin") - DoAdmin(null, args); //2015.08.09. - return false; - } - private static void DoReload(Player player) - { //2015.07.20. - //if(player==null || player.isOp() || player.getName()=="NorbiPeti") - //{ - try - { - File file=new File("autoflairconfig.txt"); - if(file.exists()) - { - PluginMain.TownColors.clear(); - BufferedReader br=new BufferedReader(new FileReader(file)); - String line; - while((line=br.readLine())!=null) - { - String[] s=line.split(" "); - PluginMain.TownColors.put(s[0], s[1]); - } - br.close(); - for(Player p : PluginMain.GetPlayers()) - { - MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName()); - if(mp.Flair!=null) - { - String flair=mp.Flair; - PluginMain.RemovePlayerDisplayFlairFinal(p, flair); - PluginMain.AppendPlayerDisplayFlairFinal(p, flair); - } - } - String msg="§6Reloaded config file.§r"; - if(player!=null) - player.sendMessage(msg); - else - System.out.println(msg); - } - } - catch(Exception e) - { - System.out.println("Error!\n"+e); - if(player!=null) - player.sendMessage("§cAn error occured. See console for details.§r"); - } - //} - //else - //player.sendMessage("§cYou need to be OP to use this command.§r"); - } - private static void DoAdmin(Player player, String[] args) - { //2015.08.09. - if(player==null || player.isOp() || player.getName()=="NorbiPeti") - { - if(args.length==1) - { - String message="§cUsage: /u admin reload|playerinfo§r"; - if(player==null) - System.out.println(message); - else - player.sendMessage(message); - return; - } - //args[0] is "admin" - switch(args[1].toLowerCase()) - { - case "reload": - DoReload(player); - break; - case "playerinfo": - DoPlayerInfo(player, args); - break; - } - } - else - player.sendMessage("§cYou need to be OP to use this command.§r"); - } - private static void DoPlayerInfo(Player player, String[] args) - { //2015.08.09. - //args[0] is "admin" - args[1] is "playerinfo" - if(args.length==2) - { - String message="§cUsage: /u admin playerinfo §r"; - if(player==null) - System.out.println(message); - else - player.sendMessage(message); - return; - } - if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2])) - { - String message="§cPlayer not found: "+args[2]+"§r"; - SendMessage(player, message); - } - MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]); - return; - } - private static void SendMessage(Player player, String message) - { - if(player==null) - System.out.println(message); - else - player.sendMessage(message); - return; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/a4/901a3493e03e001517108d149b613203 b/.metadata/.plugins/org.eclipse.core.resources/.history/a4/901a3493e03e001517108d149b613203 new file mode 100644 index 0000000..0ccc23b --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/a4/901a3493e03e001517108d149b613203 @@ -0,0 +1,260 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +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; + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. + //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) + if(p.Flair==null) + { + player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); + return true; + } + switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. + { + case "accept": + { + if(p.IgnoredFlair) + p.IgnoredFlair=false; //2015.08.08. + if(!p.AcceptedFlair) + { + String flair=p.Flair; //2015.08.08. + //PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + PluginMain.AppendPlayerDisplayFlair(p, player); + p.AcceptedFlair=true; //2015.08.08. + player.sendMessage("§6Your flair has been set:§r "+flair); + } + else + player.sendMessage("§cYou already have this user's flair.§r"); + break; + } + case "ignore": + { + if(p.AcceptedFlair) + p.AcceptedFlair=false; //2015.08.08. + if(!p.IgnoredFlair) + { + p.IgnoredFlair=true; + String flair=p.Flair; //2015.08.08. + PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. + player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); + } + else + player.sendMessage("§cYou already ignored this request.§r"); + break; + } + /*case "reload": //2015.07.20. + DoReload(player); + break;*/ + case "admin": //2015.08.09. + DoAdmin(player, args); + break; + case "nonpresser": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§7(non-pr.)§r"; + break; + case "cantpress": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§r(can't press)§r"; + break; + default: + return false; + } + return true; + } + /*if(args[0].toLowerCase()=="reload") + DoReload(null); //2015.07.20.*/ + else if(args.length>0 && args[0].toLowerCase().equals("admin")) //2015.08.09. + { + DoAdmin(null, args); //2015.08.09. + return true; //2015.08.09. + } + return false; + } + private static void DoReload(Player player) + { //2015.07.20. + //if(player==null || player.isOp() || player.getName()=="NorbiPeti") + //{ + try + { + File file=new File("autoflairconfig.txt"); + if(file.exists()) + { + PluginMain.LoadFiles(true); //2015.08.09. + for(Player p : PluginMain.GetPlayers()) + { + MaybeOfflinePlayer mp = MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName()); + if(mp.Flair!=null) + { + String flair=mp.Flair; + PluginMain.RemovePlayerDisplayFlairFinal(p, flair); + //PluginMain.AppendPlayerDisplayFlairFinal(p, flair); + PluginMain.AppendPlayerDisplayFlair(mp, p); //2015.08.09. + } + String msg="§6Note: The auto-flair plugin has been reloaded. You might need to wait 10s to have your flair.§r"; //2015.08.09. + p.sendMessage(msg); //2015.08.09. + } + //String msg="§6Reloaded config file.§r"; + //SendMessage(player, msg); //2015.08.09. + } + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + if(player!=null) + player.sendMessage("§cAn error occured. See console for details.§r"); + PluginMain.LastException=e; //2015.08.09. + } + //} + //else + //player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static Player ReloadPlayer; //2015.08.09. + private static void DoAdmin(Player player, String[] args) + { //2015.08.09. + if(player==null || player.isOp() || player.getName()=="NorbiPeti") + { + //System.out.println("Args length: " + args.length); + if(args.length==1) + { + String message="§cUsage: /u admin reload|playerinfo§r"; + SendMessage(player, message); + return; + } + //args[0] is "admin" + switch(args[1].toLowerCase()) + { + case "reload": + ReloadPlayer=player; //2015.08.09. + SendMessage(player, "§6Make sure to save the current settings before you modify and reload them! Type /u admin confirm when done.§r"); + break; + case "playerinfo": + DoPlayerInfo(player, args); + break; + case "getlasterror": + DoGetLastError(player, args); + case "confirm": + if(ReloadPlayer==player) + DoReload(player); //2015.08.09. + else + SendMessage(player, "§cYou need to do /u admin reload first.§r"); + break; + case "save": + PluginMain.SaveFiles(); //2015.08.09. + SendMessage(player, "§6Saved files. Now you can edit them and reload if you want.§r"); + break; + case "setflair": + + break; + default: + String message="§cUsage: /u admin reload|playerinfo|getlasterror|save§r"; + SendMessage(player, message); + return; + } + } + else + player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static void DoPlayerInfo(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "playerinfo" + if(args.length==2) + { + String message="§cUsage: /u admin playerinfo §r"; + SendMessage(player, message); + return; + } + if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2])) + { + String message="§cPlayer not found: "+args[2]+"§r"; + SendMessage(player, message); + return; + } + MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]); + SendMessage(player, "Player name: "+p.PlayerName); + SendMessage(player, "User flair: "+p.Flair); + SendMessage(player, "Username: "+p.UserName); + SendMessage(player, "Flair accepted: "+p.AcceptedFlair); + SendMessage(player, "Flair ignored: "+p.IgnoredFlair); + } + private static void SendMessage(Player player, String message) + { //2015.08.09. + if(player==null) + System.out.println(message); + else + player.sendMessage(message); + } + private static void DoGetLastError(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "getlasterror" + if(PluginMain.LastException!=null) + { + SendMessage(player, "Last error:"); + SendMessage(player, PluginMain.LastException.toString()); + PluginMain.LastException=null; + } + else + SendMessage(player, "There were no exceptions."); + } + private static void SetPlayerFlair(Player player, Player targetplayer, String flair) + { //2015.08.09. + flair=flair.replace('&', '§'); + MaybeOfflinePlayer.AddPlayerIfNeeded(player.getName()).Flair=flair; + if(!PluginMain.RemoveLineFromFile("customflairs.txt", targetplayer.getName())) + { + SendMessage(player, "§cError removing previous custom flair!§r"); + return; + } + File file=new File("customflairs.txt"); + try { + BufferedWriter bw; + bw = new BufferedWriter(new FileWriter(file, true)); + bw.write(targetplayer.getName()+"\n"); + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + PluginMain.LastException=e; //2015.08.09. + } + SendMessage(player, "§6The flair has been set. Player: "+targetplayer.getName()+" Flair: "+flair+"§r"); + } + private static void DoSetFlair(Player player, String args) + { + //args[0] is "admin" - args[1] is "setflair" + + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/a4/a0f428a3d33e001518fa86d7ae2a1cf8 b/.metadata/.plugins/org.eclipse.core.resources/.history/a4/a0f428a3d33e001518fa86d7ae2a1cf8 new file mode 100644 index 0000000..72b38bc --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/a4/a0f428a3d33e001518fa86d7ae2a1cf8 @@ -0,0 +1,219 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; + +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class Commands implements CommandExecutor { + // This method is called, when somebody uses our command + @Override + public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { + if (sender instanceof Player) { + Player player = (Player) sender; + if(args.length<1) + return false; + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. + //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) + if(p.Flair==null) + { + player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); + return true; + } + switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. + { + case "accept": + { + if(p.IgnoredFlair) + p.IgnoredFlair=false; //2015.08.08. + if(!p.AcceptedFlair) + { + String flair=p.Flair; //2015.08.08. + //PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + PluginMain.AppendPlayerDisplayFlair(p, player); + p.AcceptedFlair=true; //2015.08.08. + player.sendMessage("§6Your flair has been set:§r "+flair); + } + else + player.sendMessage("§cYou already have this user's flair.§r"); + break; + } + case "ignore": + { + if(p.AcceptedFlair) + p.AcceptedFlair=false; //2015.08.08. + if(!p.IgnoredFlair) + { + p.IgnoredFlair=true; + String flair=p.Flair; //2015.08.08. + PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. + player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); + } + else + player.sendMessage("§cYou already ignored this request.§r"); + break; + } + /*case "reload": //2015.07.20. + DoReload(player); + break;*/ + case "admin": //2015.08.09. + DoAdmin(player, args); + break; + case "nonpresser": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§7(non-pr.)§r"; + break; + case "cantpress": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§r(can't press)§r"; + break; + default: + return false; + } + return true; + } + /*if(args[0].toLowerCase()=="reload") + DoReload(null); //2015.07.20.*/ + else if(args.length>0 && args[0].toLowerCase().equals("admin")) //2015.08.09. + { + DoAdmin(null, args); //2015.08.09. + return true; //2015.08.09. + } + return false; + } + private static void DoReload(Player player) + { //2015.07.20. + //if(player==null || player.isOp() || player.getName()=="NorbiPeti") + //{ + try + { + File file=new File("autoflairconfig.txt"); + if(file.exists()) + { + PluginMain.LoadFiles(true); //2015.08.09. + for(Player p : PluginMain.GetPlayers()) + { + MaybeOfflinePlayer mp = MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName()); + if(mp.Flair!=null) + { + String flair=mp.Flair; + PluginMain.RemovePlayerDisplayFlairFinal(p, flair); + //PluginMain.AppendPlayerDisplayFlairFinal(p, flair); + PluginMain.AppendPlayerDisplayFlair(mp, p); //2015.08.09. + } + String msg="§6Note: The auto-flair plugin has been reloaded. You might need to wait 10s to have your flair.§r"; //2015.08.09. + p.sendMessage(msg); //2015.08.09. + } + //String msg="§6Reloaded config file.§r"; + //SendMessage(player, msg); //2015.08.09. + } + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + if(player!=null) + player.sendMessage("§cAn error occured. See console for details.§r"); + PluginMain.LastException=e; //2015.08.09. + } + //} + //else + //player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static void DoAdmin(Player player, String[] args) + { //2015.08.09. + if(player==null || player.isOp() || player.getName()=="NorbiPeti") + { + //System.out.println("Args length: " + args.length); + if(args.length==1) + { + String message="§cUsage: /u admin reload|playerinfo§r"; + SendMessage(player, message); + return; + } + //args[0] is "admin" + switch(args[1].toLowerCase()) + { + case "reload": + DoReload(player); + break; + case "playerinfo": + DoPlayerInfo(player, args); + break; + case "getlasterror": + DoGetLastError(player, args); + case "confirm": + DoReload(player); + break; + default: + String message="§cUsage: /u admin reload|playerinfo§r"; + SendMessage(player, message); + return; + } + } + else + player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static void DoPlayerInfo(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "playerinfo" + if(args.length==2) + { + String message="§cUsage: /u admin playerinfo §r"; + SendMessage(player, message); + return; + } + if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2])) + { + String message="§cPlayer not found: "+args[2]+"§r"; + SendMessage(player, message); + return; + } + MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]); + SendMessage(player, "Player name: "+p.PlayerName); + SendMessage(player, "User flair: "+p.Flair); + SendMessage(player, "Username: "+p.UserName); + SendMessage(player, "Flair accepted: "+p.AcceptedFlair); + SendMessage(player, "Flair ignored: "+p.IgnoredFlair); + } + private static void SendMessage(Player player, String message) + { //2015.08.09. + if(player==null) + System.out.println(message); + else + player.sendMessage(message); + } + private static void DoGetLastError(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "getlasterror" + if(PluginMain.LastException!=null) + { + SendMessage(player, "Last error:"); + SendMessage(player, PluginMain.LastException.toString()); + PluginMain.LastException=null; + } + else + SendMessage(player, "There were no exceptions."); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/a5/80c576a3de3e001517108d149b613203 b/.metadata/.plugins/org.eclipse.core.resources/.history/a5/80c576a3de3e001517108d149b613203 new file mode 100644 index 0000000..fe096bd --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/a5/80c576a3de3e001517108d149b613203 @@ -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.WorldCoord; + +public class PluginMain extends JavaPlugin +{ //Translated to Java: 2015.07.15. + //A user, which flair isn't obtainable: + //https://www.reddit.com/r/thebutton/comments/31c32v/i_pressed_the_button_without_really_thinking/ + private static PluginMain Instance; + // Fired when plugin is first enabled + @Override + public void onEnable() + { + System.out.println("The Button Auto-flair Plugin by NorbiPeti (:P)"); + getServer().getPluginManager().registerEvents(new PlayerListener(), this); + this.getCommand("u").setExecutor(new Commands()); + this.getCommand("u").setUsage(this.getCommand("u").getUsage().replace('&', '§')); + Instance=this; //2015.08.08. + LoadFiles(false); //2015.08.09. + Runnable r=new Runnable(){public void run(){ThreadMethod();}}; + Thread t=new Thread(r); + t.start(); + } + Boolean stop=false; + // Fired when plugin is disabled + @Override + public void onDisable() + { + SaveFiles(); //2015.08.09. + stop=true; + } + + public void ThreadMethod() //<-- 2015.07.16. + { + while(!stop) + { + try + { + String body=DownloadString("https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/autoflair_system_comment_your_minecraft_name_and/.json?limit=1000"); + JSONArray json=new JSONArray(body).getJSONObject(1).getJSONObject("data").getJSONArray("children"); + for(Object obj : json) + { + JSONObject item = (JSONObject)obj; + String author=item.getJSONObject("data").getString("author"); + String ign=item.getJSONObject("data").getString("body"); + int start = ign.indexOf("IGN:") + "IGN:".length(); + if(start==-1) + continue; //2015.08.09. + int end = ign.indexOf(' ', start); + if (end == -1 || end == start) + end=ign.indexOf('\n', start); //2015.07.15. + if (end == -1 || end == start) + ign = ign.substring(start); + else + ign = ign.substring(start, end); + ign = ign.trim(); + if(HasIGFlair(ign)) + continue; + try { + Thread.sleep(10); + } catch(InterruptedException ex) { + Thread.currentThread().interrupt(); + } + String[] flairdata = DownloadString("http://karmadecay.com/thebutton-data.php?users=" + author).replace("\"", "").split(":"); + String flair; + if(flairdata.length > 1) //2015.07.15. + flair = flairdata[1]; + else + flair=""; + if (flair != "-1") + flair = flair + "s"; + else + flair = "non-presser"; + String flairclass; + if(flairdata.length>2) + flairclass = flairdata[2]; + else + flairclass="unknown"; + SetFlair(ign, flair, flairclass, author); + } + Thread.sleep(10000); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + } + + public static Exception LastException; //2015.08.09. + + public String DownloadString(String urlstr) throws MalformedURLException, IOException + { + URL url = new URL(urlstr); + URLConnection con = url.openConnection(); + con.setRequestProperty("User-Agent", "TheButtonAutoFlair"); + InputStream in = con.getInputStream(); + String encoding = con.getContentEncoding(); + encoding = encoding == null ? "UTF-8" : encoding; + String body = IOUtils.toString(in, encoding); + in.close(); + return body; + } + + public static Map TownColors=new HashMap(); //2015.07.20. + public Boolean HasIGFlair(String playername) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + return p.Flair!=null; //2015.08.08. + } + + public void SetFlair(String playername, String text, String flairclass, String username) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + String finalflair; + p.FlairDecided=true; + switch(flairclass) + { + case "press-1": + finalflair="§c("+text+")§r"; + break; + case "press-2": + finalflair="§6("+text+")§r"; + break; + case "press-3": + finalflair="§e("+text+")§r"; + break; + case "press-4": + finalflair="§a("+text+")§r"; + break; + case "press-5": + finalflair="§9("+text+")§r"; + break; + 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; + case "undecided": //2015.08.09. + p.FlairDecided=false; + finalflair=""; + break; + default: + finalflair=""; + break; + } + if(finalflair.length()==0) //<-- 2015.07.20. + return; + p.Flair=finalflair; //2015.08.08. + p.UserName=username; //2015.08.08. + System.out.println("Added new flair to "+playername+": "+finalflair); + for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08. + { + if(player.getName().equals(playername)) + { + //AppendPlayerDisplayFlair(player, username, finalflair); + AppendPlayerDisplayFlair(p, player); + break; + } + } + } + + public static String GetFlair(Player player) + { //2015.07.16. + String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08. + return flair==null ? "" : flair; + } + + //public static void AppendPlayerDisplayFlair(Player player, String username, String flair) + public static void AppendPlayerDisplayFlair(MaybeOfflinePlayer player, Player p) //<-- 2015.08.09. + { + + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).IgnoredFlair) + return; + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).AcceptedFlair) + { + AppendPlayerDisplayFlairFinal(p, player.Flair); //2015.07.20. + if(!player.FlairDecided) + p.sendMessage("§9Your flair type is unknown. Are you a non-presser or a can't press? (/u nonpresser or /u cantpress)§r"); //2015.08.09. + } + else + p.sendMessage("§9Are you Reddit user "+player.UserName+"?§r §6Type /u accept or /u ignore§r"); + } + + private static void AppendPlayerDisplayFlairFinal(Player player, String flair) + { //2015.07.20. + String color = GetColorForTown(GetPlayerTown(player)); //TO!DO: Multiple colors put on first capital letters + String[] colors = color.substring(1).split("§"); + String displayname=player.getName(); //2015.08.08. + ArrayList Positions=new ArrayList<>(); + for(int i=0; i=colors.length) + { + int x=0; + for(int i=0; i GetPlayers() + { + return Instance.getServer().getOnlinePlayers(); + } + + public static void LoadFiles(boolean reload) //<-- 2015.08.09. + { + if(reload) + { //2015.08.09. + System.out.println("Auto-flair plugin cleanup for reloading..."); + MaybeOfflinePlayer.AllPlayers.clear(); + TownColors.clear(); + } + System.out.println("Loading files for auto-flair plugin..."); //2015.08.09. + try { + File file=new File("flairsaccepted.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + //System.out.println("Name: " + name); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("flairsignored.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsignored.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("autoflairconfig.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + TownColors.put(s[0], s[1]); + } + br.close(); + } + file=new File("customflairs.txt"); //2015.08.09. + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + MaybeOfflinePlayer.AddPlayerIfNeeded(s[0]).Flair=s[1]; //2015.08.09. + } + br.close(); + } + //throw new IOException("Test"); //2015.08.09. + System.out.println("Auto-flair plugin loaded files!"); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + public static void SaveFiles() //<-- 2015.08.09. + { + try + { + FileWriter fw; + fw = new FileWriter("flairsaccepted.txt"); + fw.close(); + fw = new FileWriter("flairsignored.txt"); + fw.close(); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + try { + File file=new File("flairsaccepted.txt"); + BufferedWriter bw=new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.AcceptedFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + file=new File("flairsignored.txt"); + bw = new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.IgnoredFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + public static void SetPlayerFlair(Player player, String flair) + { //2015.08.09. + flair=flair.replace('&', '§'); + MaybeOfflinePlayer.AddPlayerIfNeeded(player.getName()).Flair=flair; + File file=new File("customflairs.txt"); + try { + BufferedWriter bw; + bw = new BufferedWriter(new FileWriter(file, true)); + bw.write(player.getName()+"\n"); + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + public static bool RemoveLineFromFile(String file) + { + File inputFile = new File(file); + File tempFile = new File("_temp.txt"); + + try { + BufferedReader reader = new BufferedReader(new FileReader(inputFile)); + BufferedWriter writer = new BufferedWriter(new FileWriter(tempFile)); + + String lineToRemove = "bbb"; + String currentLine; + + while((currentLine = reader.readLine()) != null) { + // trim newline when comparing with lineToRemove + String trimmedLine = currentLine.trim(); + if(trimmedLine.equals(lineToRemove)) continue; + writer.write(currentLine + System.getProperty("line.separator")); + } + writer.close(); + reader.close(); + tempFile.renameTo(inputFile); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/a6/20f25379dc3e001517108d149b613203 b/.metadata/.plugins/org.eclipse.core.resources/.history/a6/20f25379dc3e001517108d149b613203 new file mode 100644 index 0000000..4d40cf6 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/a6/20f25379dc3e001517108d149b613203 @@ -0,0 +1,382 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStream; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLConnection; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + +import org.apache.commons.io.IOUtils; +import org.bukkit.entity.Player; +import org.bukkit.plugin.java.JavaPlugin; +import org.json.JSONArray; +import org.json.JSONObject; + +import com.palmergames.bukkit.towny.object.Town; +import com.palmergames.bukkit.towny.object.WorldCoord; + +public class PluginMain extends JavaPlugin +{ //Translated to Java: 2015.07.15. + //A user, which flair isn't obtainable: + //https://www.reddit.com/r/thebutton/comments/31c32v/i_pressed_the_button_without_really_thinking/ + private static PluginMain Instance; + // Fired when plugin is first enabled + @Override + public void onEnable() + { + System.out.println("The Button Auto-flair Plugin by NorbiPeti (:P)"); + getServer().getPluginManager().registerEvents(new PlayerListener(), this); + this.getCommand("u").setExecutor(new Commands()); + this.getCommand("u").setUsage(this.getCommand("u").getUsage().replace('&', '§')); + Instance=this; //2015.08.08. + LoadFiles(false); //2015.08.09. + Runnable r=new Runnable(){public void run(){ThreadMethod();}}; + Thread t=new Thread(r); + t.start(); + } + Boolean stop=false; + // Fired when plugin is disabled + @Override + public void onDisable() + { + SaveFiles(); //2015.08.09. + stop=true; + } + + public void ThreadMethod() //<-- 2015.07.16. + { + while(!stop) + { + try + { + String body=DownloadString("https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/autoflair_system_comment_your_minecraft_name_and/.json?limit=1000"); + JSONArray json=new JSONArray(body).getJSONObject(1).getJSONObject("data").getJSONArray("children"); + for(Object obj : json) + { + JSONObject item = (JSONObject)obj; + String author=item.getJSONObject("data").getString("author"); + String ign=item.getJSONObject("data").getString("body"); + int start = ign.indexOf("IGN:") + "IGN:".length(); + if(start==-1) + continue; //2015.08.09. + int end = ign.indexOf(' ', start); + if (end == -1 || end == start) + end=ign.indexOf('\n', start); //2015.07.15. + if (end == -1 || end == start) + ign = ign.substring(start); + else + ign = ign.substring(start, end); + ign = ign.trim(); + if(HasIGFlair(ign)) + continue; + try { + Thread.sleep(10); + } catch(InterruptedException ex) { + Thread.currentThread().interrupt(); + } + String[] flairdata = DownloadString("http://karmadecay.com/thebutton-data.php?users=" + author).replace("\"", "").split(":"); + String flair; + if(flairdata.length > 1) //2015.07.15. + flair = flairdata[1]; + else + flair=""; + if (flair != "-1") + flair = flair + "s"; + else + flair = "non-presser"; + String flairclass; + if(flairdata.length>2) + flairclass = flairdata[2]; + else + flairclass="unknown"; + SetFlair(ign, flair, flairclass, author); + } + Thread.sleep(10000); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + } + + public static Exception LastException; //2015.08.09. + + public String DownloadString(String urlstr) throws MalformedURLException, IOException + { + URL url = new URL(urlstr); + URLConnection con = url.openConnection(); + con.setRequestProperty("User-Agent", "TheButtonAutoFlair"); + InputStream in = con.getInputStream(); + String encoding = con.getContentEncoding(); + encoding = encoding == null ? "UTF-8" : encoding; + String body = IOUtils.toString(in, encoding); + in.close(); + return body; + } + + public static Map TownColors=new HashMap(); //2015.07.20. + public Boolean HasIGFlair(String playername) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + return p.Flair!=null; //2015.08.08. + } + + public void SetFlair(String playername, String text, String flairclass, String username) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + String finalflair; + p.FlairDecided=true; + switch(flairclass) + { + case "press-1": + finalflair="§c("+text+")§r"; + break; + case "press-2": + finalflair="§6("+text+")§r"; + break; + case "press-3": + finalflair="§e("+text+")§r"; + break; + case "press-4": + finalflair="§a("+text+")§r"; + break; + case "press-5": + finalflair="§9("+text+")§r"; + break; + 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; + case "undecided": //2015.08.09. + p.FlairDecided=false; + finalflair=""; + break; + default: + finalflair=""; + break; + } + if(finalflair.length()==0) //<-- 2015.07.20. + return; + p.Flair=finalflair; //2015.08.08. + p.UserName=username; //2015.08.08. + System.out.println("Added new flair to "+playername+": "+finalflair); + for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08. + { + if(player.getName().equals(playername)) + { + //AppendPlayerDisplayFlair(player, username, finalflair); + AppendPlayerDisplayFlair(p, player); + break; + } + } + } + + public static String GetFlair(Player player) + { //2015.07.16. + String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08. + return flair==null ? "" : flair; + } + + //public static void AppendPlayerDisplayFlair(Player player, String username, String flair) + public static void AppendPlayerDisplayFlair(MaybeOfflinePlayer player, Player p) //<-- 2015.08.09. + { + + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).IgnoredFlair) + return; + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).AcceptedFlair) + { + AppendPlayerDisplayFlairFinal(p, player.Flair); //2015.07.20. + if(!player.FlairDecided) + p.sendMessage("§9Your flair type is unknown. Are you a non-presser or a can't press? (/u nonpresser or /u cantpress)§r"); //2015.08.09. + } + else + p.sendMessage("§9Are you Reddit user "+player.UserName+"?§r §6Type /u accept or /u ignore§r"); + } + + private static void AppendPlayerDisplayFlairFinal(Player player, String flair) + { //2015.07.20. + String color = GetColorForTown(GetPlayerTown(player)); //TO!DO: Multiple colors put on first capital letters + String[] colors = color.substring(1).split("§"); + String displayname=player.getName(); //2015.08.08. + ArrayList Positions=new ArrayList<>(); + for(int i=0; i=colors.length) + { + int x=0; + for(int i=0; i GetPlayers() + { + return Instance.getServer().getOnlinePlayers(); + } + + public static void LoadFiles(boolean reload) //<-- 2015.08.09. + { + if(reload) + { //2015.08.09. + System.out.println("Auto-flair plugin cleanup for reloading..."); + MaybeOfflinePlayer.AllPlayers.clear(); + TownColors.clear(); + } + System.out.println("Loading files for auto-flair plugin..."); //2015.08.09. + try { + File file=new File("flairsaccepted.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + //System.out.println("Name: " + name); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("flairsignored.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsignored.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("autoflairconfig.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + TownColors.put(s[0], s[1]); + } + br.close(); + } + //throw new IOException("Test"); //2015.08.09. + System.out.println("Auto-flair plugin loaded files!"); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + public static void SaveFiles() //<-- 2015.08.09. + { + try + { + FileWriter fw; + fw = new FileWriter("flairsaccepted.txt"); + fw.close(); + fw = new FileWriter("flairsignored.txt"); + fw.close(); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + try { + File file=new File("flairsaccepted.txt"); + BufferedWriter bw=new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.AcceptedFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + file=new File("flairsignored.txt"); + bw = new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.IgnoredFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/a8/006bbef3df3e001517108d149b613203 b/.metadata/.plugins/org.eclipse.core.resources/.history/a8/006bbef3df3e001517108d149b613203 new file mode 100644 index 0000000..88ceb0a --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/a8/006bbef3df3e001517108d149b613203 @@ -0,0 +1,255 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +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; + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. + //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) + if(p.Flair==null) + { + player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); + return true; + } + switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. + { + case "accept": + { + if(p.IgnoredFlair) + p.IgnoredFlair=false; //2015.08.08. + if(!p.AcceptedFlair) + { + String flair=p.Flair; //2015.08.08. + //PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + PluginMain.AppendPlayerDisplayFlair(p, player); + p.AcceptedFlair=true; //2015.08.08. + player.sendMessage("§6Your flair has been set:§r "+flair); + } + else + player.sendMessage("§cYou already have this user's flair.§r"); + break; + } + case "ignore": + { + if(p.AcceptedFlair) + p.AcceptedFlair=false; //2015.08.08. + if(!p.IgnoredFlair) + { + p.IgnoredFlair=true; + String flair=p.Flair; //2015.08.08. + PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. + player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); + } + else + player.sendMessage("§cYou already ignored this request.§r"); + break; + } + /*case "reload": //2015.07.20. + DoReload(player); + break;*/ + case "admin": //2015.08.09. + DoAdmin(player, args); + break; + case "nonpresser": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§7(non-pr.)§r"; + break; + case "cantpress": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§r(can't press)§r"; + break; + default: + return false; + } + return true; + } + /*if(args[0].toLowerCase()=="reload") + DoReload(null); //2015.07.20.*/ + else if(args.length>0 && args[0].toLowerCase().equals("admin")) //2015.08.09. + { + DoAdmin(null, args); //2015.08.09. + return true; //2015.08.09. + } + return false; + } + private static void DoReload(Player player) + { //2015.07.20. + //if(player==null || player.isOp() || player.getName()=="NorbiPeti") + //{ + try + { + File file=new File("autoflairconfig.txt"); + if(file.exists()) + { + PluginMain.LoadFiles(true); //2015.08.09. + for(Player p : PluginMain.GetPlayers()) + { + MaybeOfflinePlayer mp = MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName()); + if(mp.Flair!=null) + { + String flair=mp.Flair; + PluginMain.RemovePlayerDisplayFlairFinal(p, flair); + //PluginMain.AppendPlayerDisplayFlairFinal(p, flair); + PluginMain.AppendPlayerDisplayFlair(mp, p); //2015.08.09. + } + String msg="§6Note: The auto-flair plugin has been reloaded. You might need to wait 10s to have your flair.§r"; //2015.08.09. + p.sendMessage(msg); //2015.08.09. + } + //String msg="§6Reloaded config file.§r"; + //SendMessage(player, msg); //2015.08.09. + } + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + if(player!=null) + player.sendMessage("§cAn error occured. See console for details.§r"); + PluginMain.LastException=e; //2015.08.09. + } + //} + //else + //player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static Player ReloadPlayer; //2015.08.09. + private static void DoAdmin(Player player, String[] args) + { //2015.08.09. + if(player==null || player.isOp() || player.getName()=="NorbiPeti") + { + //System.out.println("Args length: " + args.length); + if(args.length==1) + { + String message="§cUsage: /u admin reload|playerinfo§r"; + SendMessage(player, message); + return; + } + //args[0] is "admin" + switch(args[1].toLowerCase()) + { + case "reload": + ReloadPlayer=player; //2015.08.09. + SendMessage(player, "§6Make sure to save the current settings before you modify and reload them! Type /u admin confirm when done.§r"); + break; + case "playerinfo": + DoPlayerInfo(player, args); + break; + case "getlasterror": + DoGetLastError(player, args); + case "confirm": + if(ReloadPlayer==player) + DoReload(player); //2015.08.09. + else + SendMessage(player, "§cYou need to do /u admin reload first.§r"); + break; + case "save": + PluginMain.SaveFiles(); //2015.08.09. + SendMessage(player, "§6Saved files. Now you can edit them and reload if you want.§r"); + break; + case "setflair": + + break; + default: + String message="§cUsage: /u admin reload|playerinfo|getlasterror|save§r"; + SendMessage(player, message); + return; + } + } + else + player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static void DoPlayerInfo(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "playerinfo" + if(args.length==2) + { + String message="§cUsage: /u admin playerinfo §r"; + SendMessage(player, message); + return; + } + if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2])) + { + String message="§cPlayer not found: "+args[2]+"§r"; + SendMessage(player, message); + return; + } + MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]); + SendMessage(player, "Player name: "+p.PlayerName); + SendMessage(player, "User flair: "+p.Flair); + SendMessage(player, "Username: "+p.UserName); + SendMessage(player, "Flair accepted: "+p.AcceptedFlair); + SendMessage(player, "Flair ignored: "+p.IgnoredFlair); + } + private static void SendMessage(Player player, String message) + { //2015.08.09. + if(player==null) + System.out.println(message); + else + player.sendMessage(message); + } + private static void DoGetLastError(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "getlasterror" + if(PluginMain.LastException!=null) + { + SendMessage(player, "Last error:"); + SendMessage(player, PluginMain.LastException.toString()); + PluginMain.LastException=null; + } + else + SendMessage(player, "There were no exceptions."); + } + private static void DoSetFlair(Player player, Player targetplayer, String flair) + { //2015.08.09. + flair=flair.replace('&', '§'); + MaybeOfflinePlayer.AddPlayerIfNeeded(player.getName()).Flair=flair; + if(!PluginMain.RemoveLineFromFile("customflairs.txt", targetplayer.getName())) + { + SendMessage(player, "§cError removing previous custom flair!§r"); + return; + } + File file=new File("customflairs.txt"); + try { + BufferedWriter bw; + bw = new BufferedWriter(new FileWriter(file, true)); + bw.write(targetplayer.getName()+"\n"); + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + PluginMain.LastException=e; //2015.08.09. + } + SendMessage(player, "§6The flair has been set. Player: "+targetplayer.getName()+" Flair: "+flair+"§r"); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/a8/10465292e03e001517108d149b613203 b/.metadata/.plugins/org.eclipse.core.resources/.history/a8/10465292e03e001517108d149b613203 new file mode 100644 index 0000000..0ccc23b --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/a8/10465292e03e001517108d149b613203 @@ -0,0 +1,260 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +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; + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. + //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) + if(p.Flair==null) + { + player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); + return true; + } + switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. + { + case "accept": + { + if(p.IgnoredFlair) + p.IgnoredFlair=false; //2015.08.08. + if(!p.AcceptedFlair) + { + String flair=p.Flair; //2015.08.08. + //PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + PluginMain.AppendPlayerDisplayFlair(p, player); + p.AcceptedFlair=true; //2015.08.08. + player.sendMessage("§6Your flair has been set:§r "+flair); + } + else + player.sendMessage("§cYou already have this user's flair.§r"); + break; + } + case "ignore": + { + if(p.AcceptedFlair) + p.AcceptedFlair=false; //2015.08.08. + if(!p.IgnoredFlair) + { + p.IgnoredFlair=true; + String flair=p.Flair; //2015.08.08. + PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. + player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); + } + else + player.sendMessage("§cYou already ignored this request.§r"); + break; + } + /*case "reload": //2015.07.20. + DoReload(player); + break;*/ + case "admin": //2015.08.09. + DoAdmin(player, args); + break; + case "nonpresser": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§7(non-pr.)§r"; + break; + case "cantpress": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§r(can't press)§r"; + break; + default: + return false; + } + return true; + } + /*if(args[0].toLowerCase()=="reload") + DoReload(null); //2015.07.20.*/ + else if(args.length>0 && args[0].toLowerCase().equals("admin")) //2015.08.09. + { + DoAdmin(null, args); //2015.08.09. + return true; //2015.08.09. + } + return false; + } + private static void DoReload(Player player) + { //2015.07.20. + //if(player==null || player.isOp() || player.getName()=="NorbiPeti") + //{ + try + { + File file=new File("autoflairconfig.txt"); + if(file.exists()) + { + PluginMain.LoadFiles(true); //2015.08.09. + for(Player p : PluginMain.GetPlayers()) + { + MaybeOfflinePlayer mp = MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName()); + if(mp.Flair!=null) + { + String flair=mp.Flair; + PluginMain.RemovePlayerDisplayFlairFinal(p, flair); + //PluginMain.AppendPlayerDisplayFlairFinal(p, flair); + PluginMain.AppendPlayerDisplayFlair(mp, p); //2015.08.09. + } + String msg="§6Note: The auto-flair plugin has been reloaded. You might need to wait 10s to have your flair.§r"; //2015.08.09. + p.sendMessage(msg); //2015.08.09. + } + //String msg="§6Reloaded config file.§r"; + //SendMessage(player, msg); //2015.08.09. + } + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + if(player!=null) + player.sendMessage("§cAn error occured. See console for details.§r"); + PluginMain.LastException=e; //2015.08.09. + } + //} + //else + //player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static Player ReloadPlayer; //2015.08.09. + private static void DoAdmin(Player player, String[] args) + { //2015.08.09. + if(player==null || player.isOp() || player.getName()=="NorbiPeti") + { + //System.out.println("Args length: " + args.length); + if(args.length==1) + { + String message="§cUsage: /u admin reload|playerinfo§r"; + SendMessage(player, message); + return; + } + //args[0] is "admin" + switch(args[1].toLowerCase()) + { + case "reload": + ReloadPlayer=player; //2015.08.09. + SendMessage(player, "§6Make sure to save the current settings before you modify and reload them! Type /u admin confirm when done.§r"); + break; + case "playerinfo": + DoPlayerInfo(player, args); + break; + case "getlasterror": + DoGetLastError(player, args); + case "confirm": + if(ReloadPlayer==player) + DoReload(player); //2015.08.09. + else + SendMessage(player, "§cYou need to do /u admin reload first.§r"); + break; + case "save": + PluginMain.SaveFiles(); //2015.08.09. + SendMessage(player, "§6Saved files. Now you can edit them and reload if you want.§r"); + break; + case "setflair": + + break; + default: + String message="§cUsage: /u admin reload|playerinfo|getlasterror|save§r"; + SendMessage(player, message); + return; + } + } + else + player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static void DoPlayerInfo(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "playerinfo" + if(args.length==2) + { + String message="§cUsage: /u admin playerinfo §r"; + SendMessage(player, message); + return; + } + if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2])) + { + String message="§cPlayer not found: "+args[2]+"§r"; + SendMessage(player, message); + return; + } + MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]); + SendMessage(player, "Player name: "+p.PlayerName); + SendMessage(player, "User flair: "+p.Flair); + SendMessage(player, "Username: "+p.UserName); + SendMessage(player, "Flair accepted: "+p.AcceptedFlair); + SendMessage(player, "Flair ignored: "+p.IgnoredFlair); + } + private static void SendMessage(Player player, String message) + { //2015.08.09. + if(player==null) + System.out.println(message); + else + player.sendMessage(message); + } + private static void DoGetLastError(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "getlasterror" + if(PluginMain.LastException!=null) + { + SendMessage(player, "Last error:"); + SendMessage(player, PluginMain.LastException.toString()); + PluginMain.LastException=null; + } + else + SendMessage(player, "There were no exceptions."); + } + private static void SetPlayerFlair(Player player, Player targetplayer, String flair) + { //2015.08.09. + flair=flair.replace('&', '§'); + MaybeOfflinePlayer.AddPlayerIfNeeded(player.getName()).Flair=flair; + if(!PluginMain.RemoveLineFromFile("customflairs.txt", targetplayer.getName())) + { + SendMessage(player, "§cError removing previous custom flair!§r"); + return; + } + File file=new File("customflairs.txt"); + try { + BufferedWriter bw; + bw = new BufferedWriter(new FileWriter(file, true)); + bw.write(targetplayer.getName()+"\n"); + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + PluginMain.LastException=e; //2015.08.09. + } + SendMessage(player, "§6The flair has been set. Player: "+targetplayer.getName()+" Flair: "+flair+"§r"); + } + private static void DoSetFlair(Player player, String args) + { + //args[0] is "admin" - args[1] is "setflair" + + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/a8/a053b075de3e001517108d149b613203 b/.metadata/.plugins/org.eclipse.core.resources/.history/a8/a053b075de3e001517108d149b613203 new file mode 100644 index 0000000..592cb5a --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/a8/a053b075de3e001517108d149b613203 @@ -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)"); + getServer().getPluginManager().registerEvents(new PlayerListener(), this); + this.getCommand("u").setExecutor(new Commands()); + this.getCommand("u").setUsage(this.getCommand("u").getUsage().replace('&', '§')); + Instance=this; //2015.08.08. + LoadFiles(false); //2015.08.09. + Runnable r=new Runnable(){public void run(){ThreadMethod();}}; + Thread t=new Thread(r); + t.start(); + } + Boolean stop=false; + // Fired when plugin is disabled + @Override + public void onDisable() + { + SaveFiles(); //2015.08.09. + stop=true; + } + + public void ThreadMethod() //<-- 2015.07.16. + { + while(!stop) + { + try + { + String body=DownloadString("https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/autoflair_system_comment_your_minecraft_name_and/.json?limit=1000"); + JSONArray json=new JSONArray(body).getJSONObject(1).getJSONObject("data").getJSONArray("children"); + for(Object obj : json) + { + JSONObject item = (JSONObject)obj; + String author=item.getJSONObject("data").getString("author"); + String ign=item.getJSONObject("data").getString("body"); + int start = ign.indexOf("IGN:") + "IGN:".length(); + if(start==-1) + continue; //2015.08.09. + int end = ign.indexOf(' ', start); + if (end == -1 || end == start) + end=ign.indexOf('\n', start); //2015.07.15. + if (end == -1 || end == start) + ign = ign.substring(start); + else + ign = ign.substring(start, end); + ign = ign.trim(); + if(HasIGFlair(ign)) + continue; + try { + Thread.sleep(10); + } catch(InterruptedException ex) { + Thread.currentThread().interrupt(); + } + String[] flairdata = DownloadString("http://karmadecay.com/thebutton-data.php?users=" + author).replace("\"", "").split(":"); + String flair; + if(flairdata.length > 1) //2015.07.15. + flair = flairdata[1]; + else + flair=""; + if (flair != "-1") + flair = flair + "s"; + else + flair = "non-presser"; + String flairclass; + if(flairdata.length>2) + flairclass = flairdata[2]; + else + flairclass="unknown"; + SetFlair(ign, flair, flairclass, author); + } + Thread.sleep(10000); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + } + + public static Exception LastException; //2015.08.09. + + public String DownloadString(String urlstr) throws MalformedURLException, IOException + { + URL url = new URL(urlstr); + URLConnection con = url.openConnection(); + con.setRequestProperty("User-Agent", "TheButtonAutoFlair"); + InputStream in = con.getInputStream(); + String encoding = con.getContentEncoding(); + encoding = encoding == null ? "UTF-8" : encoding; + String body = IOUtils.toString(in, encoding); + in.close(); + return body; + } + + public static Map TownColors=new HashMap(); //2015.07.20. + public Boolean HasIGFlair(String playername) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + return p.Flair!=null; //2015.08.08. + } + + public void SetFlair(String playername, String text, String flairclass, String username) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + String finalflair; + p.FlairDecided=true; + switch(flairclass) + { + case "press-1": + finalflair="§c("+text+")§r"; + break; + case "press-2": + finalflair="§6("+text+")§r"; + break; + case "press-3": + finalflair="§e("+text+")§r"; + break; + case "press-4": + finalflair="§a("+text+")§r"; + break; + case "press-5": + finalflair="§9("+text+")§r"; + break; + 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; + case "undecided": //2015.08.09. + p.FlairDecided=false; + finalflair=""; + break; + default: + finalflair=""; + break; + } + if(finalflair.length()==0) //<-- 2015.07.20. + return; + p.Flair=finalflair; //2015.08.08. + p.UserName=username; //2015.08.08. + System.out.println("Added new flair to "+playername+": "+finalflair); + for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08. + { + if(player.getName().equals(playername)) + { + //AppendPlayerDisplayFlair(player, username, finalflair); + AppendPlayerDisplayFlair(p, player); + break; + } + } + } + + public static String GetFlair(Player player) + { //2015.07.16. + String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08. + return flair==null ? "" : flair; + } + + //public static void AppendPlayerDisplayFlair(Player player, String username, String flair) + public static void AppendPlayerDisplayFlair(MaybeOfflinePlayer player, Player p) //<-- 2015.08.09. + { + + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).IgnoredFlair) + return; + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).AcceptedFlair) + { + AppendPlayerDisplayFlairFinal(p, player.Flair); //2015.07.20. + if(!player.FlairDecided) + p.sendMessage("§9Your flair type is unknown. Are you a non-presser or a can't press? (/u nonpresser or /u cantpress)§r"); //2015.08.09. + } + else + p.sendMessage("§9Are you Reddit user "+player.UserName+"?§r §6Type /u accept or /u ignore§r"); + } + + private static void AppendPlayerDisplayFlairFinal(Player player, String flair) + { //2015.07.20. + String color = GetColorForTown(GetPlayerTown(player)); //TO!DO: Multiple colors put on first capital letters + String[] colors = color.substring(1).split("§"); + String displayname=player.getName(); //2015.08.08. + ArrayList Positions=new ArrayList<>(); + for(int i=0; i=colors.length) + { + int x=0; + for(int i=0; i GetPlayers() + { + return Instance.getServer().getOnlinePlayers(); + } + + public static void LoadFiles(boolean reload) //<-- 2015.08.09. + { + if(reload) + { //2015.08.09. + System.out.println("Auto-flair plugin cleanup for reloading..."); + MaybeOfflinePlayer.AllPlayers.clear(); + TownColors.clear(); + } + System.out.println("Loading files for auto-flair plugin..."); //2015.08.09. + try { + File file=new File("flairsaccepted.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + //System.out.println("Name: " + name); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("flairsignored.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsignored.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("autoflairconfig.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + TownColors.put(s[0], s[1]); + } + br.close(); + } + file=new File("customflairs.txt"); //2015.08.09. + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + MaybeOfflinePlayer.AddPlayerIfNeeded(s[0]).Flair=s[1]; //2015.08.09. + } + br.close(); + } + //throw new IOException("Test"); //2015.08.09. + System.out.println("Auto-flair plugin loaded files!"); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + public static void SaveFiles() //<-- 2015.08.09. + { + try + { + FileWriter fw; + fw = new FileWriter("flairsaccepted.txt"); + fw.close(); + fw = new FileWriter("flairsignored.txt"); + fw.close(); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + try { + File file=new File("flairsaccepted.txt"); + BufferedWriter bw=new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.AcceptedFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + file=new File("flairsignored.txt"); + bw = new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.IgnoredFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + public static void SetPlayerFlair(Player player, String flair) + { //2015.08.09. + flair=flair.replace('&', '§'); + MaybeOfflinePlayer.AddPlayerIfNeeded(player.getName()).Flair=flair; + File file=new File("customflairs.txt"); + BufferedWriter bw; + try { + bw = new BufferedWriter(new FileWriter(file, true)); + bw.write(player.getName()+"\n"); + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + public static void RemoveLineFromFile(String file) + {File inputFile = new File("myFile.txt"); + File tempFile = new File("myTempFile.txt"); + + BufferedReader reader = new BufferedReader(new FileReader(inputFile)); + BufferedWriter writer = new BufferedWriter(new FileWriter(tempFile)); + + String lineToRemove = "bbb"; + String currentLine; + + while((currentLine = reader.readLine()) != null) { + // trim newline when comparing with lineToRemove + String trimmedLine = currentLine.trim(); + if(trimmedLine.equals(lineToRemove)) continue; + writer.write(currentLine + System.getProperty("line.separator")); + } + writer.close(); + reader.close(); + boolean successful = tempFile.renameTo(inputFile); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/a9/40e5b0ce303e00151cbdba8b5f0a340e b/.metadata/.plugins/org.eclipse.core.resources/.history/a9/40e5b0ce303e00151cbdba8b5f0a340e deleted file mode 100644 index abca588..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/a9/40e5b0ce303e00151cbdba8b5f0a340e +++ /dev/null @@ -1,423 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import java.io.BufferedReader; -import java.io.BufferedWriter; -import java.io.File; -import java.io.FileReader; -import java.io.FileWriter; -import java.io.IOException; -import java.io.InputStream; -import java.net.MalformedURLException; -import java.net.URL; -import java.net.URLConnection; -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; -import java.util.Map; - -import org.apache.commons.io.IOUtils; -import org.bukkit.entity.Player; -import org.bukkit.plugin.java.JavaPlugin; -import org.json.JSONArray; -import org.json.JSONObject; - -import com.palmergames.bukkit.towny.object.Town; -import com.palmergames.bukkit.towny.object.TownyUniverse; -import com.palmergames.bukkit.towny.object.WorldCoord; - -public class PluginMain extends JavaPlugin -{ //Translated to Java: 2015.07.15. - //A user, which flair isn't obtainable: - //https://www.reddit.com/r/thebutton/comments/31c32v/i_pressed_the_button_without_really_thinking/ - private static PluginMain Instance; - // Fired when plugin is first enabled - @Override - public void onEnable() - { - System.out.println("The Button Auto-flair Plugin by NorbiPeti (:P)"); - getServer().getPluginManager().registerEvents(new PlayerListener(), this); - this.getCommand("u").setExecutor(new Commands()); - this.getCommand("u").setUsage(this.getCommand("u").getUsage().replace('&', '§')); - Instance=this; //2015.08.08. - try { - File file=new File("flairsaccepted.txt"); - if(file.exists()) - { - BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt")); - String line; - while ((line = br.readLine()) != null) - { - String name=line.replace("\n", ""); - System.out.println("Name: " + name); - MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08. - } - br.close(); - } - file=new File("flairsignored.txt"); - if(file.exists()) - { - BufferedReader br=new BufferedReader(new FileReader("flairsignored.txt")); - String line; - while ((line = br.readLine()) != null) - { - //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.PlayerName+"\n"); - bw.close(); - } catch (IOException e) { - System.out.println("Error!\n"+e); - } - } - stop=true; - } - - public void ThreadMethod() //<-- 2015.07.16. - { - /*System.out.println("Sleeping for 5 seconds..."); //2015.07.20. - try { - Thread.sleep(5000); - } catch (InterruptedException e1) { - e1.printStackTrace(); - } //2015.07.20.*/ - while(!stop) - { - try - { - String body=DownloadString("https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/autoflair_system_comment_your_minecraft_name_and/.json?limit=1000"); - JSONArray json=new JSONArray(body).getJSONObject(1).getJSONObject("data").getJSONArray("children"); - for(Object obj : json) - { - JSONObject item = (JSONObject)obj; - String author=item.getJSONObject("data").getString("author"); - String ign=item.getJSONObject("data").getString("body"); - int start = ign.indexOf("IGN:") + "IGN:".length(); - int end = ign.indexOf(' ', start); - if (end == -1 || end == start) - end=ign.indexOf('\n', start); //2015.07.15. - if (end == -1 || end == start) - ign = ign.substring(start); - else - ign = ign.substring(start, end); - ign = ign.trim(); - if(HasIGFlair(ign)) - continue; - //System.out.println("Author: "+author); - try { - Thread.sleep(10); - } catch(InterruptedException ex) { - Thread.currentThread().interrupt(); - } - String[] flairdata = DownloadString("http://karmadecay.com/thebutton-data.php?users=" + author).replace("\"", "").split(":"); - String flair; - if(flairdata.length > 1) //2015.07.15. - flair = flairdata[1]; - else - flair=""; - if (flair != "-1") - flair = flair + "s"; - else - flair = "non-presser"; - String flairclass; - //System.out.println("flairdata.length:"+flairdata.length); - if(flairdata.length>2) - flairclass = flairdata[2]; - else - flairclass="unknown"; - SetFlair(ign, flair, flairclass, author); - } - Thread.sleep(10000); - } - catch(Exception e) - { - System.out.println("Error!\n"+e); - } - } - } - - public String DownloadString(String urlstr) throws MalformedURLException, IOException - { - URL url = new URL(urlstr); - URLConnection con = url.openConnection(); - con.setRequestProperty("User-Agent", "TheButtonAutoFlair"); - InputStream in = con.getInputStream(); - String encoding = con.getContentEncoding(); - encoding = encoding == null ? "UTF-8" : encoding; - String body = IOUtils.toString(in, encoding); - in.close(); - return body; - } - - //It has to store offline player flairs too, therefore it can't use Player object - /*public static Map PlayerFlairs=new HashMap(); - public static Map PlayerUserNames=new HashMap(); - //public Map PlayerFlairs=new HashMap(); - public static ArrayList Players=new ArrayList(); - public static ArrayList AcceptedPlayers=new ArrayList(); //2015.07.16. - public static ArrayList IgnoredPlayers=new ArrayList(); //2015.07.16. - //public static Map PlayerTowns=new HashMap(); //2015.07.20.*/ - public static Map TownColors=new HashMap(); //2015.07.20. - public Boolean HasIGFlair(String playername) - { - /*Player player=null; - for(Player p : Players) - { - if(p.getName()==playername) - { - player=p; - break; - } - } - if(player==null) - return false;*/ - //return PlayerFlairs.containsKey(playername); - //return MaybeOfflinePlayer.AllPlayers.containsKey(playername); - MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. - return p.Flair!=null; //2015.08.08. - } - - public void SetFlair(String playername, String text, String flairclass, String username) - { - String finalflair; - switch(flairclass) - { - case "press-1": - finalflair="§c("+text+")§r"; - break; - case "press-2": - finalflair="§6("+text+")§r"; - break; - case "press-3": - finalflair="§e("+text+")§r"; - break; - case "press-4": - finalflair="§a("+text+")§r"; - break; - case "press-5": - finalflair="§9("+text+")§r"; - break; - case "press-6": - finalflair="§5("+text+")§r"; - break; - case "no-press": - finalflair="§7(non-pr.)§r"; - break; - case "cheater": - finalflair="§5("+text+")§r"; - break; - case "cant-press": //2015.08.08. - finalflair="§r(can't press)§r"; - break; - default: - finalflair=""; - break; - } - if(finalflair.length()==0) //<-- 2015.07.20. - return; - //PlayerFlairs.put(playername, finalflair); - //PlayerUserNames.put(playername, username); - MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. - p.Flair=finalflair; //2015.08.08. - p.UserName=username; //2015.08.08. - /*for(Player player : Players) - { - if(player.getName()==playername) - { - PlayerFlairs.put(player, finalflair); - break; - } - }*/ - //System.out.println("SetFlair - playername: "+playername+" text: "+text+" flairclass: "+flairclass); - System.out.println("Added new flair to "+playername+": "+finalflair); - //for(Player player : Players) - for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08. - { - //System.out.println("Online player: "+player.getName()); - //System.out.println("player.getName ("+player.getName()+") == playername ("+playername+"): "+(player.getName()==playername)); - if(player.getName().equals(playername)) - { - //System.out.println("DisplayName: "+player.getDisplayName()); - //player.setDisplayName(player.getDisplayName()+finalflair); - AppendPlayerDisplayFlair(player, username, finalflair); - //System.out.println("DisplayName: "+player.getDisplayName()); - break; - } - } - } - - public static String GetFlair(Player player) - { //2015.07.16. - //String flair=PlayerFlairs.get(player.getName()); - String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08. - return flair==null ? "" : flair; - } - - public static void AppendPlayerDisplayFlair(Player player, String username, String flair) - { - //if(IgnoredPlayers.contains(player.getName())) - if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).IgnoredFlair) - return; - //if(AcceptedPlayers.contains(player.getName())) - if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).AcceptedFlair) - //player.setDisplayName(player.getDisplayName()+flair); - AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. - else - player.sendMessage("§9Are you Reddit user "+username+"?§r §6Type /u accept or /u ignore§r"); - } - - public static void AppendPlayerDisplayFlairFinal(Player player, String flair) - { //2015.07.20. - //System.out.println("A"); - String color = GetColorForTown(GetPlayerTown(player)); //TO!DO: Multiple colors put on first capital letters - String[] colors = color.substring(1).split("§"); - //String displayname=player.getDisplayName(); - String displayname=player.getName(); //2015.08.08. - ArrayList Positions=new ArrayList<>(); - //System.out.println("B"); - for(int i=0; i=colors.length) - { - //System.out.println("D"); - int x=0; - for(int i=0; i towns = TownyUniverse.getDataSource().getTowns(); - try { - Town town = WorldCoord.parseWorldCoord(player).getTownBlock().getTown(); //TODO - return town.getName(); - } catch (Exception e) { - return ""; - } - } - - public static void RemovePlayerDisplayFlairFinal(Player player, String flair) - { //2015.07.20. - //String color = GetColorForTown(GetPlayerTown(player)); - //String dname=player.getDisplayName(); - //player.setDisplayName(dname.substring(dname.indexOf(color)+3, dname.indexOf(flair))); - //MaybeOfflinePlayer.AllPlayers.get(player.getName()).DisplayName=null; //2015.08.08. - MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair=null; //2015.08.08. - } - - public static Collection GetPlayers() - { - return Instance.getServer().getOnlinePlayers(); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/a9/60ef3b14313e00151cbdba8b5f0a340e b/.metadata/.plugins/org.eclipse.core.resources/.history/a9/60ef3b14313e00151cbdba8b5f0a340e deleted file mode 100644 index d63a548..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/a9/60ef3b14313e00151cbdba8b5f0a340e +++ /dev/null @@ -1,118 +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; - MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. - //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - if(p.Flair==null) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - { - if(p.IgnoredFlair) - p.IgnoredFlair=false; //2015.08.08. - if(!p.AcceptedFlair) - { - String flair=p.Flair; //2015.08.08. - PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. - p.AcceptedFlair=true; //2015.08.08. - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("§cYou already have this user's flair.§r"); - break; - } - case "ignore": - { - if(p.AcceptedFlair) - p.AcceptedFlair=false; //2015.08.08. - if(!p.IgnoredFlair) - { - p.IgnoredFlair=true; - String flair=p.Flair; //2015.08.08. - PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. - player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); - } - else - player.sendMessage("§cYou already ignored this request.§r"); - break; - } - case "reload": //2015.07.20. - DoReload(player); - break; - default: - return false; - } - return true; - } - - if(args[0]=="reload") - DoReload(null); //2015.07.20. - return false; - } - private static void DoReload(Player player) - { //2015.07.20. - if(player==null || player.isOp()) - { - try - { - File file=new File("autoflairconfig.txt"); - if(file.exists()) - { - PluginMain.TownColors.clear(); - BufferedReader br=new BufferedReader(new FileReader(file)); - String line; - while((line=br.readLine())!=null) - { - String[] s=line.split(" "); - PluginMain.TownColors.put(s[0], s[1]); - } - br.close(); - //for(Player p : PluginMain.Players) - for(Player p : PluginMain.GetPlayers()) - { - MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName()); - if(mp.Flair!=null) - { - String flair=mp.Flair; - PluginMain.RemovePlayerDisplayFlairFinal(p, flair); - PluginMain.AppendPlayerDisplayFlairFinal(p, flair); - } - } - String msg="§6Reloaded config file.§r"; - if(player!=null) - player.sendMessage(msg); - else - System.out.println(msg); - } - } - catch(Exception e) - { - System.out.println("Error!\n"+e); - if(player!=null) - player.sendMessage("§cAn error occured. See console for details.§r"); - } - } - else - player.sendMessage("§cYou need to be OP to use this command.§r"); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/aa/40db9018d93e001517108d149b613203 b/.metadata/.plugins/org.eclipse.core.resources/.history/aa/40db9018d93e001517108d149b613203 new file mode 100644 index 0000000..c2af90a --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/aa/40db9018d93e001517108d149b613203 @@ -0,0 +1,227 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; + +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class Commands implements CommandExecutor { + // This method is called, when somebody uses our command + @Override + public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { + if (sender instanceof Player) { + Player player = (Player) sender; + if(args.length<1) + return false; + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. + //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) + if(p.Flair==null) + { + player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); + return true; + } + switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. + { + case "accept": + { + if(p.IgnoredFlair) + p.IgnoredFlair=false; //2015.08.08. + if(!p.AcceptedFlair) + { + String flair=p.Flair; //2015.08.08. + //PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + PluginMain.AppendPlayerDisplayFlair(p, player); + p.AcceptedFlair=true; //2015.08.08. + player.sendMessage("§6Your flair has been set:§r "+flair); + } + else + player.sendMessage("§cYou already have this user's flair.§r"); + break; + } + case "ignore": + { + if(p.AcceptedFlair) + p.AcceptedFlair=false; //2015.08.08. + if(!p.IgnoredFlair) + { + p.IgnoredFlair=true; + String flair=p.Flair; //2015.08.08. + PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. + player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); + } + else + player.sendMessage("§cYou already ignored this request.§r"); + break; + } + /*case "reload": //2015.07.20. + DoReload(player); + break;*/ + case "admin": //2015.08.09. + DoAdmin(player, args); + break; + case "nonpresser": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§7(non-pr.)§r"; + break; + case "cantpress": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§r(can't press)§r"; + break; + default: + return false; + } + return true; + } + /*if(args[0].toLowerCase()=="reload") + DoReload(null); //2015.07.20.*/ + else if(args.length>0 && args[0].toLowerCase().equals("admin")) //2015.08.09. + { + DoAdmin(null, args); //2015.08.09. + return true; //2015.08.09. + } + return false; + } + private static void DoReload(Player player) + { //2015.07.20. + //if(player==null || player.isOp() || player.getName()=="NorbiPeti") + //{ + try + { + File file=new File("autoflairconfig.txt"); + if(file.exists()) + { + PluginMain.LoadFiles(true); //2015.08.09. + for(Player p : PluginMain.GetPlayers()) + { + MaybeOfflinePlayer mp = MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName()); + if(mp.Flair!=null) + { + String flair=mp.Flair; + PluginMain.RemovePlayerDisplayFlairFinal(p, flair); + //PluginMain.AppendPlayerDisplayFlairFinal(p, flair); + PluginMain.AppendPlayerDisplayFlair(mp, p); //2015.08.09. + } + String msg="§6Note: The auto-flair plugin has been reloaded. You might need to wait 10s to have your flair.§r"; //2015.08.09. + p.sendMessage(msg); //2015.08.09. + } + //String msg="§6Reloaded config file.§r"; + //SendMessage(player, msg); //2015.08.09. + } + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + if(player!=null) + player.sendMessage("§cAn error occured. See console for details.§r"); + PluginMain.LastException=e; //2015.08.09. + } + //} + //else + //player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static Player ReloadPlayer; //2015.08.09. + private static void DoAdmin(Player player, String[] args) + { //2015.08.09. + if(player==null || player.isOp() || player.getName()=="NorbiPeti") + { + //System.out.println("Args length: " + args.length); + if(args.length==1) + { + String message="§cUsage: /u admin reload|playerinfo§r"; + SendMessage(player, message); + return; + } + //args[0] is "admin" + switch(args[1].toLowerCase()) + { + case "reload": + ReloadPlayer=player; //2015.08.09. + SendMessage(player, "§6Make sure to save the current settings before you modify and reload them! Type /u admin confirm when done.§r"); + break; + case "playerinfo": + DoPlayerInfo(player, args); + break; + case "getlasterror": + DoGetLastError(player, args); + case "confirm": + if(ReloadPlayer!=null && ReloadPlayer.equals(player)) + DoReload(player); //2015.08.09. + else + SendMessage(player, "§cYou need to do /u admin reload first.§r"); + break; + case "save": + + break; + default: + String message="§cUsage: /u admin reload|playerinfo|getlasterror§r"; + SendMessage(player, message); + return; + } + } + else + player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static void DoPlayerInfo(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "playerinfo" + if(args.length==2) + { + String message="§cUsage: /u admin playerinfo §r"; + SendMessage(player, message); + return; + } + if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2])) + { + String message="§cPlayer not found: "+args[2]+"§r"; + SendMessage(player, message); + return; + } + MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]); + SendMessage(player, "Player name: "+p.PlayerName); + SendMessage(player, "User flair: "+p.Flair); + SendMessage(player, "Username: "+p.UserName); + SendMessage(player, "Flair accepted: "+p.AcceptedFlair); + SendMessage(player, "Flair ignored: "+p.IgnoredFlair); + } + private static void SendMessage(Player player, String message) + { //2015.08.09. + if(player==null) + System.out.println(message); + else + player.sendMessage(message); + } + private static void DoGetLastError(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "getlasterror" + if(PluginMain.LastException!=null) + { + SendMessage(player, "Last error:"); + SendMessage(player, PluginMain.LastException.toString()); + PluginMain.LastException=null; + } + else + SendMessage(player, "There were no exceptions."); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/aa/a076f09ad33e001518fa86d7ae2a1cf8 b/.metadata/.plugins/org.eclipse.core.resources/.history/aa/a076f09ad33e001518fa86d7ae2a1cf8 new file mode 100644 index 0000000..cb3725d --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/aa/a076f09ad33e001518fa86d7ae2a1cf8 @@ -0,0 +1,218 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; + +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class Commands implements CommandExecutor { + // This method is called, when somebody uses our command + @Override + public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { + if (sender instanceof Player) { + Player player = (Player) sender; + if(args.length<1) + return false; + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. + //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) + if(p.Flair==null) + { + player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); + return true; + } + switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. + { + case "accept": + { + if(p.IgnoredFlair) + p.IgnoredFlair=false; //2015.08.08. + if(!p.AcceptedFlair) + { + String flair=p.Flair; //2015.08.08. + //PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + PluginMain.AppendPlayerDisplayFlair(p, player); + p.AcceptedFlair=true; //2015.08.08. + player.sendMessage("§6Your flair has been set:§r "+flair); + } + else + player.sendMessage("§cYou already have this user's flair.§r"); + break; + } + case "ignore": + { + if(p.AcceptedFlair) + p.AcceptedFlair=false; //2015.08.08. + if(!p.IgnoredFlair) + { + p.IgnoredFlair=true; + String flair=p.Flair; //2015.08.08. + PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. + player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); + } + else + player.sendMessage("§cYou already ignored this request.§r"); + break; + } + /*case "reload": //2015.07.20. + DoReload(player); + break;*/ + case "admin": //2015.08.09. + DoAdmin(player, args); + break; + case "nonpresser": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§7(non-pr.)§r"; + break; + case "cantpress": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§r(can't press)§r"; + break; + default: + return false; + } + return true; + } + /*if(args[0].toLowerCase()=="reload") + DoReload(null); //2015.07.20.*/ + else if(args.length>0 && args[0].toLowerCase().equals("admin")) //2015.08.09. + { + DoAdmin(null, args); //2015.08.09. + return true; //2015.08.09. + } + return false; + } + private static void DoReload(Player player) + { //2015.07.20. + //if(player==null || player.isOp() || player.getName()=="NorbiPeti") + //{ + try + { + File file=new File("autoflairconfig.txt"); + if(file.exists()) + { + PluginMain.LoadFiles(true); //2015.08.09. + for(Player p : PluginMain.GetPlayers()) + { + MaybeOfflinePlayer mp = MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName()); + if(mp.Flair!=null) + { + String flair=mp.Flair; + PluginMain.RemovePlayerDisplayFlairFinal(p, flair); + //PluginMain.AppendPlayerDisplayFlairFinal(p, flair); + PluginMain.AppendPlayerDisplayFlair(mp, p); //2015.08.09. + } + String msg="§6Note: The auto-flair plugin has been reloaded. You might need to wait 10s to have your flair.§r"; //2015.08.09. + p.sendMessage(msg); //2015.08.09. + } + //String msg="§6Reloaded config file.§r"; + //SendMessage(player, msg); //2015.08.09. + } + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + if(player!=null) + player.sendMessage("§cAn error occured. See console for details.§r"); + PluginMain.LastException=e; //2015.08.09. + } + //} + //else + //player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static void DoAdmin(Player player, String[] args) + { //2015.08.09. + if(player==null || player.isOp() || player.getName()=="NorbiPeti") + { + //System.out.println("Args length: " + args.length); + if(args.length==1) + { + String message="§cUsage: /u admin reload|playerinfo§r"; + SendMessage(player, message); + return; + } + //args[0] is "admin" + switch(args[1].toLowerCase()) + { + case "reload": + DoReload(player); + break; + case "playerinfo": + DoPlayerInfo(player, args); + break; + case "getlasterror": + DoGetLastError(player, args); + case "confirm": + break; + default: + String message="§cUsage: /u admin reload|playerinfo§r"; + SendMessage(player, message); + return; + } + } + else + player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static void DoPlayerInfo(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "playerinfo" + if(args.length==2) + { + String message="§cUsage: /u admin playerinfo §r"; + SendMessage(player, message); + return; + } + if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2])) + { + String message="§cPlayer not found: "+args[2]+"§r"; + SendMessage(player, message); + return; + } + MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]); + SendMessage(player, "Player name: "+p.PlayerName); + SendMessage(player, "User flair: "+p.Flair); + SendMessage(player, "Username: "+p.UserName); + SendMessage(player, "Flair accepted: "+p.AcceptedFlair); + SendMessage(player, "Flair ignored: "+p.IgnoredFlair); + } + private static void SendMessage(Player player, String message) + { //2015.08.09. + if(player==null) + System.out.println(message); + else + player.sendMessage(message); + } + private static void DoGetLastError(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "getlasterror" + if(PluginMain.LastException!=null) + { + SendMessage(player, "Last error:"); + SendMessage(player, PluginMain.LastException.toString()); + PluginMain.LastException=null; + } + else + SendMessage(player, "There were no exceptions."); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/ac/5065ec8ffe3d00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/ac/5065ec8ffe3d00151c31fb33fff4337f deleted file mode 100644 index 51a39bf..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/ac/5065ec8ffe3d00151c31fb33fff4337f +++ /dev/null @@ -1,122 +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()); - 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/f0586fbb843e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/ac/f0586fbb843e00151ce8ff6d4f74dabd deleted file mode 100644 index 4138abb..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/ac/f0586fbb843e00151ce8ff6d4f74dabd +++ /dev/null @@ -1,117 +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; - MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. - //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - if(p.Flair==null) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - { - if(p.IgnoredFlair) - p.IgnoredFlair=false; //2015.08.08. - if(!p.AcceptedFlair) - { - String flair=p.Flair; //2015.08.08. - PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. - p.AcceptedFlair=true; //2015.08.08. - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("§cYou already have this user's flair.§r"); - break; - } - case "ignore": - { - if(p.AcceptedFlair) - p.AcceptedFlair=false; //2015.08.08. - if(!p.IgnoredFlair) - { - p.IgnoredFlair=true; - String flair=p.Flair; //2015.08.08. - PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. - player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); - } - else - player.sendMessage("§cYou already ignored this request.§r"); - break; - } - case "reload": //2015.07.20. - DoReload(player); - break; - default: - return false; - } - return true; - } - - if(args[0]=="reload") - DoReload(null); //2015.07.20. - return false; - } - private static void DoReload(Player player) - { //2015.07.20. - if(player==null || player.isOp() || player.getName()=="NorbiPeti") - { - try - { - File file=new File("autoflairconfig.txt"); - if(file.exists()) - { - PluginMain.TownColors.clear(); - BufferedReader br=new BufferedReader(new FileReader(file)); - String line; - while((line=br.readLine())!=null) - { - String[] s=line.split(" "); - PluginMain.TownColors.put(s[0], s[1]); - } - br.close(); - for(Player p : PluginMain.GetPlayers()) - { - MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName()); - if(mp.Flair!=null) - { - String flair=mp.Flair; - PluginMain.RemovePlayerDisplayFlairFinal(p, flair); - PluginMain.AppendPlayerDisplayFlairFinal(p, flair); - } - } - String msg="§6Reloaded config file.§r"; - if(player!=null) - player.sendMessage(msg); - else - System.out.println(msg); - } - } - catch(Exception e) - { - System.out.println("Error!\n"+e); - if(player!=null) - player.sendMessage("§cAn error occured. See console for details.§r"); - } - } - else - player.sendMessage("§cYou need to be OP to use this command.§r"); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/ad/00f387b8dd3e001517108d149b613203 b/.metadata/.plugins/org.eclipse.core.resources/.history/ad/00f387b8dd3e001517108d149b613203 new file mode 100644 index 0000000..2f2582c --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/ad/00f387b8dd3e001517108d149b613203 @@ -0,0 +1,409 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStream; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLConnection; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + +import org.apache.commons.io.IOUtils; +import org.bukkit.entity.Player; +import org.bukkit.plugin.java.JavaPlugin; +import org.json.JSONArray; +import org.json.JSONObject; + +import com.palmergames.bukkit.towny.object.Town; +import com.palmergames.bukkit.towny.object.WorldCoord; + +public class PluginMain extends JavaPlugin +{ //Translated to Java: 2015.07.15. + //A user, which flair isn't obtainable: + //https://www.reddit.com/r/thebutton/comments/31c32v/i_pressed_the_button_without_really_thinking/ + private static PluginMain Instance; + // Fired when plugin is first enabled + @Override + public void onEnable() + { + System.out.println("The Button Auto-flair Plugin by NorbiPeti (:P)"); + getServer().getPluginManager().registerEvents(new PlayerListener(), this); + this.getCommand("u").setExecutor(new Commands()); + this.getCommand("u").setUsage(this.getCommand("u").getUsage().replace('&', '§')); + Instance=this; //2015.08.08. + LoadFiles(false); //2015.08.09. + Runnable r=new Runnable(){public void run(){ThreadMethod();}}; + Thread t=new Thread(r); + t.start(); + } + Boolean stop=false; + // Fired when plugin is disabled + @Override + public void onDisable() + { + SaveFiles(); //2015.08.09. + stop=true; + } + + public void ThreadMethod() //<-- 2015.07.16. + { + while(!stop) + { + try + { + String body=DownloadString("https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/autoflair_system_comment_your_minecraft_name_and/.json?limit=1000"); + JSONArray json=new JSONArray(body).getJSONObject(1).getJSONObject("data").getJSONArray("children"); + for(Object obj : json) + { + JSONObject item = (JSONObject)obj; + String author=item.getJSONObject("data").getString("author"); + String ign=item.getJSONObject("data").getString("body"); + int start = ign.indexOf("IGN:") + "IGN:".length(); + if(start==-1) + continue; //2015.08.09. + int end = ign.indexOf(' ', start); + if (end == -1 || end == start) + end=ign.indexOf('\n', start); //2015.07.15. + if (end == -1 || end == start) + ign = ign.substring(start); + else + ign = ign.substring(start, end); + ign = ign.trim(); + if(HasIGFlair(ign)) + continue; + try { + Thread.sleep(10); + } catch(InterruptedException ex) { + Thread.currentThread().interrupt(); + } + String[] flairdata = DownloadString("http://karmadecay.com/thebutton-data.php?users=" + author).replace("\"", "").split(":"); + String flair; + if(flairdata.length > 1) //2015.07.15. + flair = flairdata[1]; + else + flair=""; + if (flair != "-1") + flair = flair + "s"; + else + flair = "non-presser"; + String flairclass; + if(flairdata.length>2) + flairclass = flairdata[2]; + else + flairclass="unknown"; + SetFlair(ign, flair, flairclass, author); + } + Thread.sleep(10000); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + } + + public static Exception LastException; //2015.08.09. + + public String DownloadString(String urlstr) throws MalformedURLException, IOException + { + URL url = new URL(urlstr); + URLConnection con = url.openConnection(); + con.setRequestProperty("User-Agent", "TheButtonAutoFlair"); + InputStream in = con.getInputStream(); + String encoding = con.getContentEncoding(); + encoding = encoding == null ? "UTF-8" : encoding; + String body = IOUtils.toString(in, encoding); + in.close(); + return body; + } + + public static Map TownColors=new HashMap(); //2015.07.20. + public Boolean HasIGFlair(String playername) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + return p.Flair!=null; //2015.08.08. + } + + public void SetFlair(String playername, String text, String flairclass, String username) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + String finalflair; + p.FlairDecided=true; + switch(flairclass) + { + case "press-1": + finalflair="§c("+text+")§r"; + break; + case "press-2": + finalflair="§6("+text+")§r"; + break; + case "press-3": + finalflair="§e("+text+")§r"; + break; + case "press-4": + finalflair="§a("+text+")§r"; + break; + case "press-5": + finalflair="§9("+text+")§r"; + break; + 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; + case "undecided": //2015.08.09. + p.FlairDecided=false; + finalflair=""; + break; + default: + finalflair=""; + break; + } + if(finalflair.length()==0) //<-- 2015.07.20. + return; + p.Flair=finalflair; //2015.08.08. + p.UserName=username; //2015.08.08. + System.out.println("Added new flair to "+playername+": "+finalflair); + for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08. + { + if(player.getName().equals(playername)) + { + //AppendPlayerDisplayFlair(player, username, finalflair); + AppendPlayerDisplayFlair(p, player); + break; + } + } + } + + public static String GetFlair(Player player) + { //2015.07.16. + String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08. + return flair==null ? "" : flair; + } + + //public static void AppendPlayerDisplayFlair(Player player, String username, String flair) + public static void AppendPlayerDisplayFlair(MaybeOfflinePlayer player, Player p) //<-- 2015.08.09. + { + + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).IgnoredFlair) + return; + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).AcceptedFlair) + { + AppendPlayerDisplayFlairFinal(p, player.Flair); //2015.07.20. + if(!player.FlairDecided) + p.sendMessage("§9Your flair type is unknown. Are you a non-presser or a can't press? (/u nonpresser or /u cantpress)§r"); //2015.08.09. + } + else + p.sendMessage("§9Are you Reddit user "+player.UserName+"?§r §6Type /u accept or /u ignore§r"); + } + + private static void AppendPlayerDisplayFlairFinal(Player player, String flair) + { //2015.07.20. + String color = GetColorForTown(GetPlayerTown(player)); //TO!DO: Multiple colors put on first capital letters + String[] colors = color.substring(1).split("§"); + String displayname=player.getName(); //2015.08.08. + ArrayList Positions=new ArrayList<>(); + for(int i=0; i=colors.length) + { + int x=0; + for(int i=0; i GetPlayers() + { + return Instance.getServer().getOnlinePlayers(); + } + + public static void LoadFiles(boolean reload) //<-- 2015.08.09. + { + if(reload) + { //2015.08.09. + System.out.println("Auto-flair plugin cleanup for reloading..."); + MaybeOfflinePlayer.AllPlayers.clear(); + TownColors.clear(); + } + System.out.println("Loading files for auto-flair plugin..."); //2015.08.09. + try { + File file=new File("flairsaccepted.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + //System.out.println("Name: " + name); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("flairsignored.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsignored.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("autoflairconfig.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + TownColors.put(s[0], s[1]); + } + br.close(); + } + file=new File("customflairs.txt"); //2015.08.09. + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + MaybeOfflinePlayer.AddPlayerIfNeeded(s[0]).Flair=s[1]; //2015.08.09. + } + br.close(); + } + //throw new IOException("Test"); //2015.08.09. + System.out.println("Auto-flair plugin loaded files!"); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + public static void SaveFiles() //<-- 2015.08.09. + { + try + { + FileWriter fw; + fw = new FileWriter("flairsaccepted.txt"); + fw.close(); + fw = new FileWriter("flairsignored.txt"); + fw.close(); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + try { + File file=new File("flairsaccepted.txt"); + BufferedWriter bw=new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.AcceptedFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + file=new File("flairsignored.txt"); + bw = new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.IgnoredFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + public static void SetPlayerFlair(Player player, String flair) + { //2015.08.09. + flair=flair.replace('&', '§'); + MaybeOfflinePlayer.AddPlayerIfNeeded(player.getName()).Flair=flair; + File file=new File("customflairs.txt"); + BufferedWriter bw; + try { + bw = new BufferedWriter(new FileWriter(file, true)); + bw.write(player.getName()+"\n"); + bw.close(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/ad/60b39408d43e001518fa86d7ae2a1cf8 b/.metadata/.plugins/org.eclipse.core.resources/.history/ad/60b39408d43e001518fa86d7ae2a1cf8 new file mode 100644 index 0000000..05f66ff --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/ad/60b39408d43e001518fa86d7ae2a1cf8 @@ -0,0 +1,220 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; + +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class Commands implements CommandExecutor { + // This method is called, when somebody uses our command + @Override + public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { + if (sender instanceof Player) { + Player player = (Player) sender; + if(args.length<1) + return false; + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. + //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) + if(p.Flair==null) + { + player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); + return true; + } + switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. + { + case "accept": + { + if(p.IgnoredFlair) + p.IgnoredFlair=false; //2015.08.08. + if(!p.AcceptedFlair) + { + String flair=p.Flair; //2015.08.08. + //PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + PluginMain.AppendPlayerDisplayFlair(p, player); + p.AcceptedFlair=true; //2015.08.08. + player.sendMessage("§6Your flair has been set:§r "+flair); + } + else + player.sendMessage("§cYou already have this user's flair.§r"); + break; + } + case "ignore": + { + if(p.AcceptedFlair) + p.AcceptedFlair=false; //2015.08.08. + if(!p.IgnoredFlair) + { + p.IgnoredFlair=true; + String flair=p.Flair; //2015.08.08. + PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. + player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); + } + else + player.sendMessage("§cYou already ignored this request.§r"); + break; + } + /*case "reload": //2015.07.20. + DoReload(player); + break;*/ + case "admin": //2015.08.09. + DoAdmin(player, args); + break; + case "nonpresser": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§7(non-pr.)§r"; + break; + case "cantpress": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§r(can't press)§r"; + break; + default: + return false; + } + return true; + } + /*if(args[0].toLowerCase()=="reload") + DoReload(null); //2015.07.20.*/ + else if(args.length>0 && args[0].toLowerCase().equals("admin")) //2015.08.09. + { + DoAdmin(null, args); //2015.08.09. + return true; //2015.08.09. + } + return false; + } + private static void DoReload(Player player) + { //2015.07.20. + //if(player==null || player.isOp() || player.getName()=="NorbiPeti") + //{ + try + { + File file=new File("autoflairconfig.txt"); + if(file.exists()) + { + PluginMain.LoadFiles(true); //2015.08.09. + for(Player p : PluginMain.GetPlayers()) + { + MaybeOfflinePlayer mp = MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName()); + if(mp.Flair!=null) + { + String flair=mp.Flair; + PluginMain.RemovePlayerDisplayFlairFinal(p, flair); + //PluginMain.AppendPlayerDisplayFlairFinal(p, flair); + PluginMain.AppendPlayerDisplayFlair(mp, p); //2015.08.09. + } + String msg="§6Note: The auto-flair plugin has been reloaded. You might need to wait 10s to have your flair.§r"; //2015.08.09. + p.sendMessage(msg); //2015.08.09. + } + //String msg="§6Reloaded config file.§r"; + //SendMessage(player, msg); //2015.08.09. + } + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + if(player!=null) + player.sendMessage("§cAn error occured. See console for details.§r"); + PluginMain.LastException=e; //2015.08.09. + } + //} + //else + //player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static Player ReloadPlayer; + private static void DoAdmin(Player player, String[] args) + { //2015.08.09. + if(player==null || player.isOp() || player.getName()=="NorbiPeti") + { + //System.out.println("Args length: " + args.length); + if(args.length==1) + { + String message="§cUsage: /u admin reload|playerinfo§r"; + SendMessage(player, message); + return; + } + //args[0] is "admin" + switch(args[1].toLowerCase()) + { + case "reload": + SendMessage(player, "§6Make sure to save the current settings before you modify and reload them! Type /u admin confirm when done."); + break; + case "playerinfo": + DoPlayerInfo(player, args); + break; + case "getlasterror": + DoGetLastError(player, args); + case "confirm": + DoReload(player); //2015.08.09. + break; + default: + String message="§cUsage: /u admin reload|playerinfo§r"; + SendMessage(player, message); + return; + } + } + else + player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static void DoPlayerInfo(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "playerinfo" + if(args.length==2) + { + String message="§cUsage: /u admin playerinfo §r"; + SendMessage(player, message); + return; + } + if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2])) + { + String message="§cPlayer not found: "+args[2]+"§r"; + SendMessage(player, message); + return; + } + MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]); + SendMessage(player, "Player name: "+p.PlayerName); + SendMessage(player, "User flair: "+p.Flair); + SendMessage(player, "Username: "+p.UserName); + SendMessage(player, "Flair accepted: "+p.AcceptedFlair); + SendMessage(player, "Flair ignored: "+p.IgnoredFlair); + } + private static void SendMessage(Player player, String message) + { //2015.08.09. + if(player==null) + System.out.println(message); + else + player.sendMessage(message); + } + private static void DoGetLastError(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "getlasterror" + if(PluginMain.LastException!=null) + { + SendMessage(player, "Last error:"); + SendMessage(player, PluginMain.LastException.toString()); + PluginMain.LastException=null; + } + else + SendMessage(player, "There were no exceptions."); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/13/602947d9303e00151cbdba8b5f0a340e b/.metadata/.plugins/org.eclipse.core.resources/.history/ad/c0954ebcce3e001518fa86d7ae2a1cf8 similarity index 70% rename from .metadata/.plugins/org.eclipse.core.resources/.history/13/602947d9303e00151cbdba8b5f0a340e rename to .metadata/.plugins/org.eclipse.core.resources/.history/ad/c0954ebcce3e001518fa86d7ae2a1cf8 index 29ec32a..2284d68 100644 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/13/602947d9303e00151cbdba8b5f0a340e +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/ad/c0954ebcce3e001518fa86d7ae2a1cf8 @@ -21,8 +21,9 @@ import org.bukkit.plugin.java.JavaPlugin; import org.json.JSONArray; import org.json.JSONObject; +import tk.sznp.thebuttonautoflair.MaybeOfflinePlayer.FlairClassType; + 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 @@ -48,7 +49,7 @@ public class PluginMain extends JavaPlugin while ((line = br.readLine()) != null) { String name=line.replace("\n", ""); - System.out.println("Name: " + name); + //System.out.println("Name: " + name); MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08. } br.close(); @@ -77,8 +78,10 @@ public class PluginMain extends JavaPlugin } br.close(); } + //throw new IOException("Test"); //2015.08.09. } catch (IOException e) { System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. } Runnable r=new Runnable(){public void run(){ThreadMethod();}}; Thread t=new Thread(r); @@ -100,33 +103,31 @@ public class PluginMain extends JavaPlugin catch(Exception e) { System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. } - for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. - { - if(!player.AcceptedFlair) - continue; //2015.08.08. - File file=new File("flairsaccepted.txt"); - try { - BufferedWriter bw=new BufferedWriter(new FileWriter(file, true)); + try { + File file=new File("flairsaccepted.txt"); + BufferedWriter bw=new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.AcceptedFlair) + continue; //2015.08.08. bw.write(player.PlayerName+"\n"); - bw.close(); - } catch (IOException e) { - System.out.println("Error!\n"+e); - } - } - for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. - { - if(!player.IgnoredFlair) - continue; //2015.08.08. - File file=new File("flairsignored.txt"); - try { - BufferedWriter bw = new BufferedWriter(new FileWriter(file, true)); + } + bw.close(); + file=new File("flairsignored.txt"); + bw = new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.IgnoredFlair) + continue; //2015.08.08. bw.write(player.PlayerName+"\n"); - bw.close(); - } catch (IOException e) { - System.out.println("Error!\n"+e); - } - } + } + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } stop=true; } @@ -170,7 +171,6 @@ public class PluginMain extends JavaPlugin else flair = "non-presser"; String flairclass; - //System.out.println("flairdata.length:"+flairdata.length); if(flairdata.length>2) flairclass = flairdata[2]; else @@ -182,10 +182,13 @@ public class PluginMain extends JavaPlugin catch(Exception e) { System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. } } } + public static Exception LastException; //2015.08.09. + public String DownloadString(String urlstr) throws MalformedURLException, IOException { URL url = new URL(urlstr); @@ -199,37 +202,18 @@ public class PluginMain extends JavaPlugin return body; } - //It has to store offline player flairs too, therefore it can't use Player object - /*public static Map PlayerFlairs=new HashMap(); - public static Map PlayerUserNames=new HashMap(); - //public Map PlayerFlairs=new HashMap(); - public static ArrayList Players=new ArrayList(); - public static ArrayList AcceptedPlayers=new ArrayList(); //2015.07.16. - public static ArrayList IgnoredPlayers=new ArrayList(); //2015.07.16. - //public static Map PlayerTowns=new HashMap(); //2015.07.20.*/ public static Map TownColors=new HashMap(); //2015.07.20. public Boolean HasIGFlair(String playername) { - /*Player player=null; - for(Player p : Players) - { - if(p.getName()==playername) - { - player=p; - break; - } - } - if(player==null) - return false;*/ - //return PlayerFlairs.containsKey(playername); - //return MaybeOfflinePlayer.AllPlayers.containsKey(playername); MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. return p.Flair!=null; //2015.08.08. } public void SetFlair(String playername, String text, String flairclass, String username) { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. String finalflair; + p.FlairDecided=true; switch(flairclass) { case "press-1": @@ -259,38 +243,24 @@ public class PluginMain extends JavaPlugin case "cant-press": //2015.08.08. finalflair="§r(can't press)§r"; break; + case "undecided": //2015.08.09. + p.FlairDecided=false; + finalflair=""; + 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; } } @@ -298,43 +268,37 @@ public class PluginMain extends JavaPlugin public static String GetFlair(Player player) { //2015.07.16. - //String flair=PlayerFlairs.get(player.getName()); String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08. return flair==null ? "" : flair; } public static void AppendPlayerDisplayFlair(Player player, String username, String flair) { - //if(IgnoredPlayers.contains(player.getName())) if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).IgnoredFlair) return; - //if(AcceptedPlayers.contains(player.getName())) if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).AcceptedFlair) - //player.setDisplayName(player.getDisplayName()+flair); + { AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + + } else player.sendMessage("§9Are you Reddit user "+username+"?§r §6Type /u accept or /u ignore§r"); } 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(); @@ -399,10 +351,6 @@ public class PluginMain extends JavaPlugin public static void RemovePlayerDisplayFlairFinal(Player player, String flair) { //2015.07.20. - //String color = GetColorForTown(GetPlayerTown(player)); - //String dname=player.getDisplayName(); - //player.setDisplayName(dname.substring(dname.indexOf(color)+3, dname.indexOf(flair))); - //MaybeOfflinePlayer.AllPlayers.get(player.getName()).DisplayName=null; //2015.08.08. MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair=null; //2015.08.08. } diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/ad/d05bdac3883e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/ad/d05bdac3883e00151ce8ff6d4f74dabd deleted file mode 100644 index b1f2c2b..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/ad/d05bdac3883e00151ce8ff6d4f74dabd +++ /dev/null @@ -1,170 +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; - MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. - //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - if(p.Flair==null) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. - { - case "accept": - { - if(p.IgnoredFlair) - p.IgnoredFlair=false; //2015.08.08. - if(!p.AcceptedFlair) - { - String flair=p.Flair; //2015.08.08. - PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. - p.AcceptedFlair=true; //2015.08.08. - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("§cYou already have this user's flair.§r"); - break; - } - case "ignore": - { - if(p.AcceptedFlair) - p.AcceptedFlair=false; //2015.08.08. - if(!p.IgnoredFlair) - { - p.IgnoredFlair=true; - String flair=p.Flair; //2015.08.08. - PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. - player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); - } - else - player.sendMessage("§cYou already ignored this request.§r"); - break; - } - /*case "reload": //2015.07.20. - DoReload(player); - break;*/ - case "admin": //2015.08.09. - DoAdmin(player, args); - break; - default: - return false; - } - return true; - } - - /*if(args[0].toLowerCase()=="reload") - DoReload(null); //2015.07.20.*/ - else if(args[0].toLowerCase()=="admin") - DoAdmin(null, args); //2015.08.09. - return false; - } - private static void DoReload(Player player) - { //2015.07.20. - //if(player==null || player.isOp() || player.getName()=="NorbiPeti") - //{ - try - { - File file=new File("autoflairconfig.txt"); - if(file.exists()) - { - PluginMain.TownColors.clear(); - BufferedReader br=new BufferedReader(new FileReader(file)); - String line; - while((line=br.readLine())!=null) - { - String[] s=line.split(" "); - PluginMain.TownColors.put(s[0], s[1]); - } - br.close(); - for(Player p : PluginMain.GetPlayers()) - { - MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName()); - if(mp.Flair!=null) - { - String flair=mp.Flair; - PluginMain.RemovePlayerDisplayFlairFinal(p, flair); - PluginMain.AppendPlayerDisplayFlairFinal(p, flair); - } - } - String msg="§6Reloaded config file.§r"; - if(player!=null) - player.sendMessage(msg); - else - System.out.println(msg); - } - } - catch(Exception e) - { - System.out.println("Error!\n"+e); - if(player!=null) - player.sendMessage("§cAn error occured. See console for details.§r"); - } - //} - //else - //player.sendMessage("§cYou need to be OP to use this command.§r"); - } - private static void DoAdmin(Player player, String[] args) - { //2015.08.09. - if(player==null || player.isOp() || player.getName()=="NorbiPeti") - { - if(args.length==1) - { - String message="§cUsage: /u admin reload|playerinfo§r"; - SendMessage(player, message); - return; - } - //args[0] is "admin" - switch(args[1].toLowerCase()) - { - case "reload": - DoReload(player); - break; - case "playerinfo": - DoPlayerInfo(player, args); - break; - } - } - else - player.sendMessage("§cYou need to be OP to use this command.§r"); - } - private static void DoPlayerInfo(Player player, String[] args) - { //2015.08.09. - //args[0] is "admin" - args[1] is "playerinfo" - if(args.length==2) - { - String message="§cUsage: /u admin playerinfo §r"; - SendMessage(player, message); - } - if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2])) - { - String message="§cPlayer not found: "+args[2]+"§r"; - SendMessage(player, message); - } - MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]); - return; - } - private static void SendMessage(Player player, String message) - { - if(player==null) - System.out.println(message); - else - player.sendMessage(message); - return; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/9e/d0a0364f893e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/ae/1023a9f9cc3e001518fa86d7ae2a1cf8 similarity index 86% rename from .metadata/.plugins/org.eclipse.core.resources/.history/9e/d0a0364f893e00151ce8ff6d4f74dabd rename to .metadata/.plugins/org.eclipse.core.resources/.history/ae/1023a9f9cc3e001518fa86d7ae2a1cf8 index 95365e7..21abae7 100644 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/9e/d0a0364f893e00151ce8ff6d4f74dabd +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/ae/1023a9f9cc3e001518fa86d7ae2a1cf8 @@ -67,11 +67,13 @@ public class Commands implements CommandExecutor { } return true; } - /*if(args[0].toLowerCase()=="reload") DoReload(null); //2015.07.20.*/ - else if(args[0].toLowerCase()=="admin") + else if(args.length>0 && args[0].toLowerCase().equals("admin")) //2015.08.09. + { DoAdmin(null, args); //2015.08.09. + return true; //2015.08.09. + } return false; } private static void DoReload(Player player) @@ -111,6 +113,7 @@ public class Commands implements CommandExecutor { System.out.println("Error!\n"+e); if(player!=null) player.sendMessage("§cAn error occured. See console for details.§r"); + PluginMain.LastException=e; //2015.08.09. } //} //else @@ -120,6 +123,7 @@ public class Commands implements CommandExecutor { { //2015.08.09. if(player==null || player.isOp() || player.getName()=="NorbiPeti") { + //System.out.println("Args length: " + args.length); if(args.length==1) { String message="§cUsage: /u admin reload|playerinfo§r"; @@ -135,6 +139,12 @@ public class Commands implements CommandExecutor { case "playerinfo": DoPlayerInfo(player, args); break; + case "getlasterror": + DoGetLastError(player, args); + default: + String message="§cUsage: /u admin reload|playerinfo§r"; + SendMessage(player, message); + return; } } else @@ -147,20 +157,20 @@ public class Commands implements CommandExecutor { { String message="§cUsage: /u admin playerinfo §r"; SendMessage(player, message); + return; } if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2])) { String message="§cPlayer not found: "+args[2]+"§r"; SendMessage(player, message); + return; } MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]); - SendMessage(player, "User flair: "+p.Flair); SendMessage(player, "Player name: "+p.PlayerName); + SendMessage(player, "User flair: "+p.Flair); SendMessage(player, "Username: "+p.UserName); SendMessage(player, "Flair accepted: "+p.AcceptedFlair); SendMessage(player, "Flair ignored: "+p.IgnoredFlair); - SendMessage(player, "Flair accepted: "+p.AcceptedFlair); - return; } private static void SendMessage(Player player, String message) { //2015.08.09. @@ -168,6 +178,17 @@ public class Commands implements CommandExecutor { System.out.println(message); else player.sendMessage(message); - return; + } + private static void DoGetLastError(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "getlasterror" + if(PluginMain.LastException!=null) + { + SendMessage(player, "Last error:"); + SendMessage(player, PluginMain.LastException.toString()); + PluginMain.LastException=null; + } + else + SendMessage(player, "There were no exceptions."); } } diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/ae/80773b20e13e001517108d149b613203 b/.metadata/.plugins/org.eclipse.core.resources/.history/ae/80773b20e13e001517108d149b613203 new file mode 100644 index 0000000..c4f42b9 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/ae/80773b20e13e001517108d149b613203 @@ -0,0 +1,265 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +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; + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. + //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) + if(p.Flair==null) + { + player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); + return true; + } + switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. + { + case "accept": + { + if(p.IgnoredFlair) + p.IgnoredFlair=false; //2015.08.08. + if(!p.AcceptedFlair) + { + String flair=p.Flair; //2015.08.08. + //PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + PluginMain.AppendPlayerDisplayFlair(p, player); + p.AcceptedFlair=true; //2015.08.08. + player.sendMessage("§6Your flair has been set:§r "+flair); + } + else + player.sendMessage("§cYou already have this user's flair.§r"); + break; + } + case "ignore": + { + if(p.AcceptedFlair) + p.AcceptedFlair=false; //2015.08.08. + if(!p.IgnoredFlair) + { + p.IgnoredFlair=true; + String flair=p.Flair; //2015.08.08. + PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. + player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); + } + else + player.sendMessage("§cYou already ignored this request.§r"); + break; + } + /*case "reload": //2015.07.20. + DoReload(player); + break;*/ + case "admin": //2015.08.09. + DoAdmin(player, args); + break; + case "nonpresser": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§7(non-pr.)§r"; + break; + case "cantpress": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§r(can't press)§r"; + break; + default: + return false; + } + return true; + } + /*if(args[0].toLowerCase()=="reload") + DoReload(null); //2015.07.20.*/ + else if(args.length>0 && args[0].toLowerCase().equals("admin")) //2015.08.09. + { + DoAdmin(null, args); //2015.08.09. + return true; //2015.08.09. + } + return false; + } + private static void DoReload(Player player) + { //2015.07.20. + //if(player==null || player.isOp() || player.getName()=="NorbiPeti") + //{ + try + { + File file=new File("autoflairconfig.txt"); + if(file.exists()) + { + PluginMain.LoadFiles(true); //2015.08.09. + for(Player p : PluginMain.GetPlayers()) + { + MaybeOfflinePlayer mp = MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName()); + if(mp.Flair!=null) + { + String flair=mp.Flair; + PluginMain.RemovePlayerDisplayFlairFinal(p, flair); + //PluginMain.AppendPlayerDisplayFlairFinal(p, flair); + PluginMain.AppendPlayerDisplayFlair(mp, p); //2015.08.09. + } + String msg="§6Note: The auto-flair plugin has been reloaded. You might need to wait 10s to have your flair.§r"; //2015.08.09. + p.sendMessage(msg); //2015.08.09. + } + //String msg="§6Reloaded config file.§r"; + //SendMessage(player, msg); //2015.08.09. + } + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + if(player!=null) + player.sendMessage("§cAn error occured. See console for details.§r"); + PluginMain.LastException=e; //2015.08.09. + } + //} + //else + //player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static Player ReloadPlayer; //2015.08.09. + private static void DoAdmin(Player player, String[] args) + { //2015.08.09. + if(player==null || player.isOp() || player.getName()=="NorbiPeti") + { + //System.out.println("Args length: " + args.length); + if(args.length==1) + { + String message="§cUsage: /u admin reload|playerinfo§r"; + SendMessage(player, message); + return; + } + //args[0] is "admin" + switch(args[1].toLowerCase()) + { + case "reload": + ReloadPlayer=player; //2015.08.09. + SendMessage(player, "§6Make sure to save the current settings before you modify and reload them! Type /u admin confirm when done.§r"); + break; + case "playerinfo": + DoPlayerInfo(player, args); + break; + case "getlasterror": + DoGetLastError(player, args); + case "confirm": + if(ReloadPlayer==player) + DoReload(player); //2015.08.09. + else + SendMessage(player, "§cYou need to do /u admin reload first.§r"); + break; + case "save": + PluginMain.SaveFiles(); //2015.08.09. + SendMessage(player, "§6Saved files. Now you can edit them and reload if you want.§r"); + break; + case "setflair": + + break; + default: + String message="§cUsage: /u admin reload|playerinfo|getlasterror|save§r"; + SendMessage(player, message); + return; + } + } + else + player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static void DoPlayerInfo(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "playerinfo" + if(args.length==2) + { + String message="§cUsage: /u admin playerinfo §r"; + SendMessage(player, message); + return; + } + if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2])) + { + String message="§cPlayer not found: "+args[2]+"§r"; + SendMessage(player, message); + return; + } + MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]); + SendMessage(player, "Player name: "+p.PlayerName); + SendMessage(player, "User flair: "+p.Flair); + SendMessage(player, "Username: "+p.UserName); + SendMessage(player, "Flair accepted: "+p.AcceptedFlair); + SendMessage(player, "Flair ignored: "+p.IgnoredFlair); + } + private static void SendMessage(Player player, String message) + { //2015.08.09. + if(player==null) + System.out.println(message); + else + player.sendMessage(message); + } + private static void DoGetLastError(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "getlasterror" + if(PluginMain.LastException!=null) + { + SendMessage(player, "Last error:"); + SendMessage(player, PluginMain.LastException.toString()); + PluginMain.LastException=null; + } + else + SendMessage(player, "There were no exceptions."); + } + private static void SetPlayerFlair(Player player, MaybeOfflinePlayer targetplayer, String flair) + { //2015.08.09. + flair=flair.replace('&', '§'); + targetplayer.Flair=flair; + if(!PluginMain.RemoveLineFromFile("customflairs.txt", targetplayer.PlayerName)) + { + SendMessage(player, "§cError removing previous custom flair!§r"); + return; + } + File file=new File("customflairs.txt"); + try { + BufferedWriter bw; + bw = new BufferedWriter(new FileWriter(file, true)); + bw.write(targetplayer.PlayerName+"\n"); + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + PluginMain.LastException=e; //2015.08.09. + } + SendMessage(player, "§6The flair has been set. Player: "+targetplayer.PlayerName+" Flair: "+flair+"§r"); + } + private static void DoSetFlair(Player player, String[] args) + { + //args[0] is "admin" - args[1] is "setflair" + if(args.length<4) + { + SendMessage(player, "§cUsage: /u admin setflair "); + return; + } + SetPlayerFlair(player, MaybeOfflinePlayer.AddPlayerIfNeeded(args[2]), args[3]); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/af/80d63604df3e001517108d149b613203 b/.metadata/.plugins/org.eclipse.core.resources/.history/af/80d63604df3e001517108d149b613203 new file mode 100644 index 0000000..9e33acb --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/af/80d63604df3e001517108d149b613203 @@ -0,0 +1,250 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +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; + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. + //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) + if(p.Flair==null) + { + player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); + return true; + } + switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. + { + case "accept": + { + if(p.IgnoredFlair) + p.IgnoredFlair=false; //2015.08.08. + if(!p.AcceptedFlair) + { + String flair=p.Flair; //2015.08.08. + //PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + PluginMain.AppendPlayerDisplayFlair(p, player); + p.AcceptedFlair=true; //2015.08.08. + player.sendMessage("§6Your flair has been set:§r "+flair); + } + else + player.sendMessage("§cYou already have this user's flair.§r"); + break; + } + case "ignore": + { + if(p.AcceptedFlair) + p.AcceptedFlair=false; //2015.08.08. + if(!p.IgnoredFlair) + { + p.IgnoredFlair=true; + String flair=p.Flair; //2015.08.08. + PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. + player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); + } + else + player.sendMessage("§cYou already ignored this request.§r"); + break; + } + /*case "reload": //2015.07.20. + DoReload(player); + break;*/ + case "admin": //2015.08.09. + DoAdmin(player, args); + break; + case "nonpresser": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§7(non-pr.)§r"; + break; + case "cantpress": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§r(can't press)§r"; + break; + default: + return false; + } + return true; + } + /*if(args[0].toLowerCase()=="reload") + DoReload(null); //2015.07.20.*/ + else if(args.length>0 && args[0].toLowerCase().equals("admin")) //2015.08.09. + { + DoAdmin(null, args); //2015.08.09. + return true; //2015.08.09. + } + return false; + } + private static void DoReload(Player player) + { //2015.07.20. + //if(player==null || player.isOp() || player.getName()=="NorbiPeti") + //{ + try + { + File file=new File("autoflairconfig.txt"); + if(file.exists()) + { + PluginMain.LoadFiles(true); //2015.08.09. + for(Player p : PluginMain.GetPlayers()) + { + MaybeOfflinePlayer mp = MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName()); + if(mp.Flair!=null) + { + String flair=mp.Flair; + PluginMain.RemovePlayerDisplayFlairFinal(p, flair); + //PluginMain.AppendPlayerDisplayFlairFinal(p, flair); + PluginMain.AppendPlayerDisplayFlair(mp, p); //2015.08.09. + } + String msg="§6Note: The auto-flair plugin has been reloaded. You might need to wait 10s to have your flair.§r"; //2015.08.09. + p.sendMessage(msg); //2015.08.09. + } + //String msg="§6Reloaded config file.§r"; + //SendMessage(player, msg); //2015.08.09. + } + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + if(player!=null) + player.sendMessage("§cAn error occured. See console for details.§r"); + PluginMain.LastException=e; //2015.08.09. + } + //} + //else + //player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static Player ReloadPlayer; //2015.08.09. + private static void DoAdmin(Player player, String[] args) + { //2015.08.09. + if(player==null || player.isOp() || player.getName()=="NorbiPeti") + { + //System.out.println("Args length: " + args.length); + if(args.length==1) + { + String message="§cUsage: /u admin reload|playerinfo§r"; + SendMessage(player, message); + return; + } + //args[0] is "admin" + switch(args[1].toLowerCase()) + { + case "reload": + ReloadPlayer=player; //2015.08.09. + SendMessage(player, "§6Make sure to save the current settings before you modify and reload them! Type /u admin confirm when done.§r"); + break; + case "playerinfo": + DoPlayerInfo(player, args); + break; + case "getlasterror": + DoGetLastError(player, args); + case "confirm": + if(ReloadPlayer==player) + DoReload(player); //2015.08.09. + else + SendMessage(player, "§cYou need to do /u admin reload first.§r"); + break; + case "save": + PluginMain.SaveFiles(); //2015.08.09. + SendMessage(player, "§6Saved files. Now you can edit them and reload if you want.§r"); + break; + default: + String message="§cUsage: /u admin reload|playerinfo|getlasterror§r"; + SendMessage(player, message); + return; + } + } + else + player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static void DoPlayerInfo(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "playerinfo" + if(args.length==2) + { + String message="§cUsage: /u admin playerinfo §r"; + SendMessage(player, message); + return; + } + if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2])) + { + String message="§cPlayer not found: "+args[2]+"§r"; + SendMessage(player, message); + return; + } + MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]); + SendMessage(player, "Player name: "+p.PlayerName); + SendMessage(player, "User flair: "+p.Flair); + SendMessage(player, "Username: "+p.UserName); + SendMessage(player, "Flair accepted: "+p.AcceptedFlair); + SendMessage(player, "Flair ignored: "+p.IgnoredFlair); + } + public static void SendMessage(Player player, String message) + { //2015.08.09. + if(player==null) + System.out.println(message); + else + player.sendMessage(message); + } + private static void DoGetLastError(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "getlasterror" + if(PluginMain.LastException!=null) + { + SendMessage(player, "Last error:"); + SendMessage(player, PluginMain.LastException.toString()); + PluginMain.LastException=null; + } + else + SendMessage(player, "There were no exceptions."); + } + private static void SetPlayerFlair(Player player, String flair) + { //2015.08.09. + flair=flair.replace('&', '§'); + MaybeOfflinePlayer.AddPlayerIfNeeded(player.getName()).Flair=flair; + if(!PluginMain.RemoveLineFromFile("customflairs.txt")) + { + SendMessage(player, "") + } + File file=new File("customflairs.txt"); + try { + BufferedWriter bw; + bw = new BufferedWriter(new FileWriter(file, true)); + bw.write(player.getName()+"\n"); + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + PluginMain.LastException=e; //2015.08.09. + } + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/b/301da326cd3e001518fa86d7ae2a1cf8 b/.metadata/.plugins/org.eclipse.core.resources/.history/b/301da326cd3e001518fa86d7ae2a1cf8 new file mode 100644 index 0000000..3d05e25 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/b/301da326cd3e001518fa86d7ae2a1cf8 @@ -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 + 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/b1/20248930cd3e001518fa86d7ae2a1cf8 b/.metadata/.plugins/org.eclipse.core.resources/.history/b1/20248930cd3e001518fa86d7ae2a1cf8 new file mode 100644 index 0000000..a73501d --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/b1/20248930cd3e001518fa86d7ae2a1cf8 @@ -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 + 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/b1/30440676d03e001518fa86d7ae2a1cf8 b/.metadata/.plugins/org.eclipse.core.resources/.history/b1/30440676d03e001518fa86d7ae2a1cf8 new file mode 100644 index 0000000..c6af7c6 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/b1/30440676d03e001518fa86d7ae2a1cf8 @@ -0,0 +1,201 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; + +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class Commands implements CommandExecutor { + // This method is called, when somebody uses our command + @Override + public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { + if (sender instanceof Player) { + Player player = (Player) sender; + if(args.length<1) + return false; + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. + //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) + if(p.Flair==null) + { + player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); + return true; + } + switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. + { + case "accept": + { + if(p.IgnoredFlair) + p.IgnoredFlair=false; //2015.08.08. + if(!p.AcceptedFlair) + { + String flair=p.Flair; //2015.08.08. + //PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + PluginMain.AppendPlayerDisplayFlair(p, player); + p.AcceptedFlair=true; //2015.08.08. + player.sendMessage("§6Your flair has been set:§r "+flair); + } + else + player.sendMessage("§cYou already have this user's flair.§r"); + break; + } + case "ignore": + { + if(p.AcceptedFlair) + p.AcceptedFlair=false; //2015.08.08. + if(!p.IgnoredFlair) + { + p.IgnoredFlair=true; + String flair=p.Flair; //2015.08.08. + PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. + player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); + } + else + player.sendMessage("§cYou already ignored this request.§r"); + break; + } + /*case "reload": //2015.07.20. + DoReload(player); + break;*/ + case "admin": //2015.08.09. + DoAdmin(player, args); + break; + case "nonpresser": //2015.08.09. + + break; + case "cantpress": //2015.08.09. + break; + default: + return false; + } + return true; + } + /*if(args[0].toLowerCase()=="reload") + DoReload(null); //2015.07.20.*/ + else if(args.length>0 && args[0].toLowerCase().equals("admin")) //2015.08.09. + { + DoAdmin(null, args); //2015.08.09. + return true; //2015.08.09. + } + return false; + } + private static void DoReload(Player player) + { //2015.07.20. + //if(player==null || player.isOp() || player.getName()=="NorbiPeti") + //{ + try + { + File file=new File("autoflairconfig.txt"); + if(file.exists()) + { + PluginMain.TownColors.clear(); + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + PluginMain.TownColors.put(s[0], s[1]); + } + br.close(); + for(Player p : PluginMain.GetPlayers()) + { + MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName()); + if(mp.Flair!=null) + { + String flair=mp.Flair; + PluginMain.RemovePlayerDisplayFlairFinal(p, flair); + //PluginMain.AppendPlayerDisplayFlairFinal(p, flair); + PluginMain.AppendPlayerDisplayFlair(mp, p); //2015.08.09. + } + } + String msg="§6Reloaded config file.§r"; + SendMessage(player, msg); //2015.08.09. + } + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + if(player!=null) + player.sendMessage("§cAn error occured. See console for details.§r"); + PluginMain.LastException=e; //2015.08.09. + } + //} + //else + //player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static void DoAdmin(Player player, String[] args) + { //2015.08.09. + if(player==null || player.isOp() || player.getName()=="NorbiPeti") + { + //System.out.println("Args length: " + args.length); + if(args.length==1) + { + String message="§cUsage: /u admin reload|playerinfo§r"; + SendMessage(player, message); + return; + } + //args[0] is "admin" + switch(args[1].toLowerCase()) + { + case "reload": + DoReload(player); + break; + case "playerinfo": + DoPlayerInfo(player, args); + break; + case "getlasterror": + DoGetLastError(player, args); + default: + String message="§cUsage: /u admin reload|playerinfo§r"; + SendMessage(player, message); + return; + } + } + else + player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static void DoPlayerInfo(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "playerinfo" + if(args.length==2) + { + String message="§cUsage: /u admin playerinfo §r"; + SendMessage(player, message); + return; + } + if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2])) + { + String message="§cPlayer not found: "+args[2]+"§r"; + SendMessage(player, message); + return; + } + MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]); + SendMessage(player, "Player name: "+p.PlayerName); + SendMessage(player, "User flair: "+p.Flair); + SendMessage(player, "Username: "+p.UserName); + SendMessage(player, "Flair accepted: "+p.AcceptedFlair); + SendMessage(player, "Flair ignored: "+p.IgnoredFlair); + } + private static void SendMessage(Player player, String message) + { //2015.08.09. + if(player==null) + System.out.println(message); + else + player.sendMessage(message); + } + private static void DoGetLastError(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "getlasterror" + if(PluginMain.LastException!=null) + { + SendMessage(player, "Last error:"); + SendMessage(player, PluginMain.LastException.toString()); + PluginMain.LastException=null; + } + else + SendMessage(player, "There were no exceptions."); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/b3/100a9853d43e001518fa86d7ae2a1cf8 b/.metadata/.plugins/org.eclipse.core.resources/.history/b3/100a9853d43e001518fa86d7ae2a1cf8 new file mode 100644 index 0000000..9a2577a --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/b3/100a9853d43e001518fa86d7ae2a1cf8 @@ -0,0 +1,224 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; + +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class Commands implements CommandExecutor { + // This method is called, when somebody uses our command + @Override + public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { + if (sender instanceof Player) { + Player player = (Player) sender; + if(args.length<1) + return false; + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. + //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) + if(p.Flair==null) + { + player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); + return true; + } + switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. + { + case "accept": + { + if(p.IgnoredFlair) + p.IgnoredFlair=false; //2015.08.08. + if(!p.AcceptedFlair) + { + String flair=p.Flair; //2015.08.08. + //PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + PluginMain.AppendPlayerDisplayFlair(p, player); + p.AcceptedFlair=true; //2015.08.08. + player.sendMessage("§6Your flair has been set:§r "+flair); + } + else + player.sendMessage("§cYou already have this user's flair.§r"); + break; + } + case "ignore": + { + if(p.AcceptedFlair) + p.AcceptedFlair=false; //2015.08.08. + if(!p.IgnoredFlair) + { + p.IgnoredFlair=true; + String flair=p.Flair; //2015.08.08. + PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. + player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); + } + else + player.sendMessage("§cYou already ignored this request.§r"); + break; + } + /*case "reload": //2015.07.20. + DoReload(player); + break;*/ + case "admin": //2015.08.09. + DoAdmin(player, args); + break; + case "nonpresser": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§7(non-pr.)§r"; + break; + case "cantpress": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§r(can't press)§r"; + break; + default: + return false; + } + return true; + } + /*if(args[0].toLowerCase()=="reload") + DoReload(null); //2015.07.20.*/ + else if(args.length>0 && args[0].toLowerCase().equals("admin")) //2015.08.09. + { + DoAdmin(null, args); //2015.08.09. + return true; //2015.08.09. + } + return false; + } + private static void DoReload(Player player) + { //2015.07.20. + //if(player==null || player.isOp() || player.getName()=="NorbiPeti") + //{ + try + { + File file=new File("autoflairconfig.txt"); + if(file.exists()) + { + PluginMain.LoadFiles(true); //2015.08.09. + for(Player p : PluginMain.GetPlayers()) + { + MaybeOfflinePlayer mp = MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName()); + if(mp.Flair!=null) + { + String flair=mp.Flair; + PluginMain.RemovePlayerDisplayFlairFinal(p, flair); + //PluginMain.AppendPlayerDisplayFlairFinal(p, flair); + PluginMain.AppendPlayerDisplayFlair(mp, p); //2015.08.09. + } + String msg="§6Note: The auto-flair plugin has been reloaded. You might need to wait 10s to have your flair.§r"; //2015.08.09. + p.sendMessage(msg); //2015.08.09. + } + //String msg="§6Reloaded config file.§r"; + //SendMessage(player, msg); //2015.08.09. + } + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + if(player!=null) + player.sendMessage("§cAn error occured. See console for details.§r"); + PluginMain.LastException=e; //2015.08.09. + } + //} + //else + //player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static Player ReloadPlayer; //2015.08.09. + private static void DoAdmin(Player player, String[] args) + { //2015.08.09. + if(player==null || player.isOp() || player.getName()=="NorbiPeti") + { + //System.out.println("Args length: " + args.length); + if(args.length==1) + { + String message="§cUsage: /u admin reload|playerinfo§r"; + SendMessage(player, message); + return; + } + //args[0] is "admin" + switch(args[1].toLowerCase()) + { + case "reload": + ReloadPlayer=player; //2015.08.09. + SendMessage(player, "§6Make sure to save the current settings before you modify and reload them! Type /u admin confirm when done.§r"); + break; + case "playerinfo": + DoPlayerInfo(player, args); + break; + case "getlasterror": + DoGetLastError(player, args); + case "confirm": + if(ReloadPlayer.equals(player)) + DoReload(player); //2015.08.09. + else + SendMessage(player, "§cYou need to do /u admin reload first.§r"); + break; + default: + String message="§cUsage: /u admin reload|playerinfo§r"; + SendMessage(player, message); + return; + } + } + else + player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static void DoPlayerInfo(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "playerinfo" + if(args.length==2) + { + String message="§cUsage: /u admin playerinfo §r"; + SendMessage(player, message); + return; + } + if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2])) + { + String message="§cPlayer not found: "+args[2]+"§r"; + SendMessage(player, message); + return; + } + MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]); + SendMessage(player, "Player name: "+p.PlayerName); + SendMessage(player, "User flair: "+p.Flair); + SendMessage(player, "Username: "+p.UserName); + SendMessage(player, "Flair accepted: "+p.AcceptedFlair); + SendMessage(player, "Flair ignored: "+p.IgnoredFlair); + } + private static void SendMessage(Player player, String message) + { //2015.08.09. + if(player==null) + System.out.println(message); + else + player.sendMessage(message); + } + private static void DoGetLastError(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "getlasterror" + if(PluginMain.LastException!=null) + { + SendMessage(player, "Last error:"); + SendMessage(player, PluginMain.LastException.toString()); + PluginMain.LastException=null; + } + else + SendMessage(player, "There were no exceptions."); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/b3/c04f9e03ce3e001518fa86d7ae2a1cf8 b/.metadata/.plugins/org.eclipse.core.resources/.history/b3/c04f9e03ce3e001518fa86d7ae2a1cf8 new file mode 100644 index 0000000..68717ab --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/b3/c04f9e03ce3e001518fa86d7ae2a1cf8 @@ -0,0 +1,354 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStream; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLConnection; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + +import org.apache.commons.io.IOUtils; +import org.bukkit.entity.Player; +import org.bukkit.plugin.java.JavaPlugin; +import org.json.JSONArray; +import org.json.JSONObject; + +import com.palmergames.bukkit.towny.object.Town; +import com.palmergames.bukkit.towny.object.WorldCoord; + +public class PluginMain extends JavaPlugin +{ //Translated to Java: 2015.07.15. + //A user, which flair isn't obtainable: + //https://www.reddit.com/r/thebutton/comments/31c32v/i_pressed_the_button_without_really_thinking/ + private static PluginMain Instance; + // Fired when plugin is first enabled + @Override + public void onEnable() + { + System.out.println("The Button Auto-flair Plugin by NorbiPeti (:P)"); + getServer().getPluginManager().registerEvents(new PlayerListener(), this); + this.getCommand("u").setExecutor(new Commands()); + this.getCommand("u").setUsage(this.getCommand("u").getUsage().replace('&', '§')); + Instance=this; //2015.08.08. + try { + File file=new File("flairsaccepted.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + //System.out.println("Name: " + name); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("flairsignored.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsignored.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("autoflairconfig.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + TownColors.put(s[0], s[1]); + } + br.close(); + } + //throw new IOException("Test"); //2015.08.09. + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + Runnable r=new Runnable(){public void run(){ThreadMethod();}}; + Thread t=new Thread(r); + t.start(); + } + Boolean stop=false; + // Fired when plugin is disabled + @Override + public void onDisable() + { + try + { + FileWriter fw; + fw = new FileWriter("flairsaccepted.txt"); + fw.close(); + fw = new FileWriter("flairsignored.txt"); + fw.close(); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + try { + File file=new File("flairsaccepted.txt"); + BufferedWriter bw=new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.AcceptedFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + file=new File("flairsignored.txt"); + bw = new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.IgnoredFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + stop=true; + } + + public void ThreadMethod() //<-- 2015.07.16. + { + while(!stop) + { + try + { + String body=DownloadString("https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/autoflair_system_comment_your_minecraft_name_and/.json?limit=1000"); + JSONArray json=new JSONArray(body).getJSONObject(1).getJSONObject("data").getJSONArray("children"); + for(Object obj : json) + { + JSONObject item = (JSONObject)obj; + String author=item.getJSONObject("data").getString("author"); + String ign=item.getJSONObject("data").getString("body"); + int start = ign.indexOf("IGN:") + "IGN:".length(); + int end = ign.indexOf(' ', start); + if (end == -1 || end == start) + end=ign.indexOf('\n', start); //2015.07.15. + if (end == -1 || end == start) + ign = ign.substring(start); + else + ign = ign.substring(start, end); + ign = ign.trim(); + if(HasIGFlair(ign)) + continue; + try { + Thread.sleep(10); + } catch(InterruptedException ex) { + Thread.currentThread().interrupt(); + } + String[] flairdata = DownloadString("http://karmadecay.com/thebutton-data.php?users=" + author).replace("\"", "").split(":"); + String flair; + if(flairdata.length > 1) //2015.07.15. + flair = flairdata[1]; + else + flair=""; + if (flair != "-1") + flair = flair + "s"; + else + flair = "non-presser"; + String flairclass; + if(flairdata.length>2) + flairclass = flairdata[2]; + else + flairclass="unknown"; + SetFlair(ign, flair, flairclass, author); + } + Thread.sleep(10000); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + } + + public static Exception LastException; //2015.08.09. + + public String DownloadString(String urlstr) throws MalformedURLException, IOException + { + URL url = new URL(urlstr); + URLConnection con = url.openConnection(); + con.setRequestProperty("User-Agent", "TheButtonAutoFlair"); + InputStream in = con.getInputStream(); + String encoding = con.getContentEncoding(); + encoding = encoding == null ? "UTF-8" : encoding; + String body = IOUtils.toString(in, encoding); + in.close(); + return body; + } + + public static Map TownColors=new HashMap(); //2015.07.20. + public Boolean HasIGFlair(String playername) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + return p.Flair!=null; //2015.08.08. + } + + public void SetFlair(String playername, String text, String flairclass, String username) + { + String finalflair; + switch(flairclass) + { + case "press-1": + finalflair="§c("+text+")§r"; + break; + case "press-2": + finalflair="§6("+text+")§r"; + break; + case "press-3": + finalflair="§e("+text+")§r"; + break; + case "press-4": + finalflair="§a("+text+")§r"; + break; + case "press-5": + finalflair="§9("+text+")§r"; + break; + case "press-6": + finalflair="§5("+text+")§r"; + break; + case "no-press": + finalflair="§7(non-pr.)§r"; + break; + case "cheater": + finalflair="§5("+text+")§r"; + break; + case "cant-press": //2015.08.08. + finalflair="§r(can't press)§r"; + break; + case "undecided":; //2015.08.09. + finalflair="" + break; + default: + finalflair=""; + break; + } + if(finalflair.length()==0) //<-- 2015.07.20. + return; + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + p.Flair=finalflair; //2015.08.08. + p.UserName=username; //2015.08.08. + System.out.println("Added new flair to "+playername+": "+finalflair); + for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08. + { + if(player.getName().equals(playername)) + { + AppendPlayerDisplayFlair(player, username, finalflair); + break; + } + } + } + + public static String GetFlair(Player player) + { //2015.07.16. + String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08. + return flair==null ? "" : flair; + } + + public static void AppendPlayerDisplayFlair(Player player, String username, String flair) + { + if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).IgnoredFlair) + return; + if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).AcceptedFlair) + AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + else + player.sendMessage("§9Are you Reddit user "+username+"?§r §6Type /u accept or /u ignore§r"); + } + + public static void AppendPlayerDisplayFlairFinal(Player player, String flair) + { //2015.07.20. + String color = GetColorForTown(GetPlayerTown(player)); //TO!DO: Multiple colors put on first capital letters + String[] colors = color.substring(1).split("§"); + String displayname=player.getName(); //2015.08.08. + ArrayList Positions=new ArrayList<>(); + for(int i=0; i=colors.length) + { + int x=0; + for(int i=0; i GetPlayers() + { + return Instance.getServer().getOnlinePlayers(); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/b4/90dba275dd3e001517108d149b613203 b/.metadata/.plugins/org.eclipse.core.resources/.history/b4/90dba275dd3e001517108d149b613203 new file mode 100644 index 0000000..88d98b0 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/b4/90dba275dd3e001517108d149b613203 @@ -0,0 +1,408 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStream; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLConnection; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + +import org.apache.commons.io.IOUtils; +import org.bukkit.entity.Player; +import org.bukkit.plugin.java.JavaPlugin; +import org.json.JSONArray; +import org.json.JSONObject; + +import com.palmergames.bukkit.towny.object.Town; +import com.palmergames.bukkit.towny.object.WorldCoord; + +public class PluginMain extends JavaPlugin +{ //Translated to Java: 2015.07.15. + //A user, which flair isn't obtainable: + //https://www.reddit.com/r/thebutton/comments/31c32v/i_pressed_the_button_without_really_thinking/ + private static PluginMain Instance; + // Fired when plugin is first enabled + @Override + public void onEnable() + { + System.out.println("The Button Auto-flair Plugin by NorbiPeti (:P)"); + getServer().getPluginManager().registerEvents(new PlayerListener(), this); + this.getCommand("u").setExecutor(new Commands()); + this.getCommand("u").setUsage(this.getCommand("u").getUsage().replace('&', '§')); + Instance=this; //2015.08.08. + LoadFiles(false); //2015.08.09. + Runnable r=new Runnable(){public void run(){ThreadMethod();}}; + Thread t=new Thread(r); + t.start(); + } + Boolean stop=false; + // Fired when plugin is disabled + @Override + public void onDisable() + { + SaveFiles(); //2015.08.09. + stop=true; + } + + public void ThreadMethod() //<-- 2015.07.16. + { + while(!stop) + { + try + { + String body=DownloadString("https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/autoflair_system_comment_your_minecraft_name_and/.json?limit=1000"); + JSONArray json=new JSONArray(body).getJSONObject(1).getJSONObject("data").getJSONArray("children"); + for(Object obj : json) + { + JSONObject item = (JSONObject)obj; + String author=item.getJSONObject("data").getString("author"); + String ign=item.getJSONObject("data").getString("body"); + int start = ign.indexOf("IGN:") + "IGN:".length(); + if(start==-1) + continue; //2015.08.09. + int end = ign.indexOf(' ', start); + if (end == -1 || end == start) + end=ign.indexOf('\n', start); //2015.07.15. + if (end == -1 || end == start) + ign = ign.substring(start); + else + ign = ign.substring(start, end); + ign = ign.trim(); + if(HasIGFlair(ign)) + continue; + try { + Thread.sleep(10); + } catch(InterruptedException ex) { + Thread.currentThread().interrupt(); + } + String[] flairdata = DownloadString("http://karmadecay.com/thebutton-data.php?users=" + author).replace("\"", "").split(":"); + String flair; + if(flairdata.length > 1) //2015.07.15. + flair = flairdata[1]; + else + flair=""; + if (flair != "-1") + flair = flair + "s"; + else + flair = "non-presser"; + String flairclass; + if(flairdata.length>2) + flairclass = flairdata[2]; + else + flairclass="unknown"; + SetFlair(ign, flair, flairclass, author); + } + Thread.sleep(10000); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + } + + public static Exception LastException; //2015.08.09. + + public String DownloadString(String urlstr) throws MalformedURLException, IOException + { + URL url = new URL(urlstr); + URLConnection con = url.openConnection(); + con.setRequestProperty("User-Agent", "TheButtonAutoFlair"); + InputStream in = con.getInputStream(); + String encoding = con.getContentEncoding(); + encoding = encoding == null ? "UTF-8" : encoding; + String body = IOUtils.toString(in, encoding); + in.close(); + return body; + } + + public static Map TownColors=new HashMap(); //2015.07.20. + public Boolean HasIGFlair(String playername) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + return p.Flair!=null; //2015.08.08. + } + + public void SetFlair(String playername, String text, String flairclass, String username) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + String finalflair; + p.FlairDecided=true; + switch(flairclass) + { + case "press-1": + finalflair="§c("+text+")§r"; + break; + case "press-2": + finalflair="§6("+text+")§r"; + break; + case "press-3": + finalflair="§e("+text+")§r"; + break; + case "press-4": + finalflair="§a("+text+")§r"; + break; + case "press-5": + finalflair="§9("+text+")§r"; + break; + 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; + case "undecided": //2015.08.09. + p.FlairDecided=false; + finalflair=""; + break; + default: + finalflair=""; + break; + } + if(finalflair.length()==0) //<-- 2015.07.20. + return; + p.Flair=finalflair; //2015.08.08. + p.UserName=username; //2015.08.08. + System.out.println("Added new flair to "+playername+": "+finalflair); + for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08. + { + if(player.getName().equals(playername)) + { + //AppendPlayerDisplayFlair(player, username, finalflair); + AppendPlayerDisplayFlair(p, player); + break; + } + } + } + + public static String GetFlair(Player player) + { //2015.07.16. + String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08. + return flair==null ? "" : flair; + } + + //public static void AppendPlayerDisplayFlair(Player player, String username, String flair) + public static void AppendPlayerDisplayFlair(MaybeOfflinePlayer player, Player p) //<-- 2015.08.09. + { + + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).IgnoredFlair) + return; + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).AcceptedFlair) + { + AppendPlayerDisplayFlairFinal(p, player.Flair); //2015.07.20. + if(!player.FlairDecided) + p.sendMessage("§9Your flair type is unknown. Are you a non-presser or a can't press? (/u nonpresser or /u cantpress)§r"); //2015.08.09. + } + else + p.sendMessage("§9Are you Reddit user "+player.UserName+"?§r §6Type /u accept or /u ignore§r"); + } + + private static void AppendPlayerDisplayFlairFinal(Player player, String flair) + { //2015.07.20. + String color = GetColorForTown(GetPlayerTown(player)); //TO!DO: Multiple colors put on first capital letters + String[] colors = color.substring(1).split("§"); + String displayname=player.getName(); //2015.08.08. + ArrayList Positions=new ArrayList<>(); + for(int i=0; i=colors.length) + { + int x=0; + for(int i=0; i GetPlayers() + { + return Instance.getServer().getOnlinePlayers(); + } + + public static void LoadFiles(boolean reload) //<-- 2015.08.09. + { + if(reload) + { //2015.08.09. + System.out.println("Auto-flair plugin cleanup for reloading..."); + MaybeOfflinePlayer.AllPlayers.clear(); + TownColors.clear(); + } + System.out.println("Loading files for auto-flair plugin..."); //2015.08.09. + try { + File file=new File("flairsaccepted.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + //System.out.println("Name: " + name); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("flairsignored.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsignored.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("autoflairconfig.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + TownColors.put(s[0], s[1]); + } + br.close(); + } + file=new File("autoflairdecisions.txt"); //2015.08.09. + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + MaybeOfflinePlayer.AddPlayerIfNeeded(s[0]).Flair=s[1]; //2015.08.09. + } + br.close(); + } + //throw new IOException("Test"); //2015.08.09. + System.out.println("Auto-flair plugin loaded files!"); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + public static void SaveFiles() //<-- 2015.08.09. + { + try + { + FileWriter fw; + fw = new FileWriter("flairsaccepted.txt"); + fw.close(); + fw = new FileWriter("flairsignored.txt"); + fw.close(); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + try { + File file=new File("flairsaccepted.txt"); + BufferedWriter bw=new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.AcceptedFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + file=new File("flairsignored.txt"); + bw = new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.IgnoredFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + public static void SetPlayerFlair(Player player, String flair) + { //2015.08.09. + flair=flair.replace('&', '§'); + MaybeOfflinePlayer.AddPlayerIfNeeded(player.getName()).Flair=flair; + File file=new File("flairsaccepted.txt"); + BufferedWriter bw=new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.AcceptedFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/b5/202ce194d13e001518fa86d7ae2a1cf8 b/.metadata/.plugins/org.eclipse.core.resources/.history/b5/202ce194d13e001518fa86d7ae2a1cf8 new file mode 100644 index 0000000..2e695ac --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/b5/202ce194d13e001518fa86d7ae2a1cf8 @@ -0,0 +1,326 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStream; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLConnection; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + +import org.apache.commons.io.IOUtils; +import org.bukkit.entity.Player; +import org.bukkit.plugin.java.JavaPlugin; +import org.json.JSONArray; +import org.json.JSONObject; + +import com.palmergames.bukkit.towny.object.Town; +import com.palmergames.bukkit.towny.object.WorldCoord; + +public class PluginMain extends JavaPlugin +{ //Translated to Java: 2015.07.15. + //A user, which flair isn't obtainable: + //https://www.reddit.com/r/thebutton/comments/31c32v/i_pressed_the_button_without_really_thinking/ + private static PluginMain Instance; + // Fired when plugin is first enabled + @Override + public void onEnable() + { + System.out.println("The Button Auto-flair Plugin by NorbiPeti (:P)"); + getServer().getPluginManager().registerEvents(new PlayerListener(), this); + this.getCommand("u").setExecutor(new Commands()); + this.getCommand("u").setUsage(this.getCommand("u").getUsage().replace('&', '§')); + Instance=this; //2015.08.08. + Load(false); //2015.08.09. + Runnable r=new Runnable(){public void run(){ThreadMethod();}}; + Thread t=new Thread(r); + t.start(); + } + Boolean stop=false; + // Fired when plugin is disabled + @Override + public void onDisable() + { + try + { + FileWriter fw; + fw = new FileWriter("flairsaccepted.txt"); + fw.close(); + fw = new FileWriter("flairsignored.txt"); + fw.close(); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + try { + File file=new File("flairsaccepted.txt"); + BufferedWriter bw=new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.AcceptedFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + file=new File("flairsignored.txt"); + bw = new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.IgnoredFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + stop=true; + } + + public void ThreadMethod() //<-- 2015.07.16. + { + while(!stop) + { + try + { + String body=DownloadString("https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/autoflair_system_comment_your_minecraft_name_and/.json?limit=1000"); + JSONArray json=new JSONArray(body).getJSONObject(1).getJSONObject("data").getJSONArray("children"); + for(Object obj : json) + { + JSONObject item = (JSONObject)obj; + String author=item.getJSONObject("data").getString("author"); + String ign=item.getJSONObject("data").getString("body"); + int start = ign.indexOf("IGN:") + "IGN:".length(); + int end = ign.indexOf(' ', start); + if (end == -1 || end == start) + end=ign.indexOf('\n', start); //2015.07.15. + if (end == -1 || end == start) + ign = ign.substring(start); + else + ign = ign.substring(start, end); + ign = ign.trim(); + if(HasIGFlair(ign)) + continue; + try { + Thread.sleep(10); + } catch(InterruptedException ex) { + Thread.currentThread().interrupt(); + } + String[] flairdata = DownloadString("http://karmadecay.com/thebutton-data.php?users=" + author).replace("\"", "").split(":"); + String flair; + if(flairdata.length > 1) //2015.07.15. + flair = flairdata[1]; + else + flair=""; + if (flair != "-1") + flair = flair + "s"; + else + flair = "non-presser"; + String flairclass; + if(flairdata.length>2) + flairclass = flairdata[2]; + else + flairclass="unknown"; + SetFlair(ign, flair, flairclass, author); + } + Thread.sleep(10000); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + } + + public static Exception LastException; //2015.08.09. + + public String DownloadString(String urlstr) throws MalformedURLException, IOException + { + URL url = new URL(urlstr); + URLConnection con = url.openConnection(); + con.setRequestProperty("User-Agent", "TheButtonAutoFlair"); + InputStream in = con.getInputStream(); + String encoding = con.getContentEncoding(); + encoding = encoding == null ? "UTF-8" : encoding; + String body = IOUtils.toString(in, encoding); + in.close(); + return body; + } + + public static Map TownColors=new HashMap(); //2015.07.20. + public Boolean HasIGFlair(String playername) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + return p.Flair!=null; //2015.08.08. + } + + public void SetFlair(String playername, String text, String flairclass, String username) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + String finalflair; + p.FlairDecided=true; + switch(flairclass) + { + case "press-1": + finalflair="§c("+text+")§r"; + break; + case "press-2": + finalflair="§6("+text+")§r"; + break; + case "press-3": + finalflair="§e("+text+")§r"; + break; + case "press-4": + finalflair="§a("+text+")§r"; + break; + case "press-5": + finalflair="§9("+text+")§r"; + break; + 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; + case "undecided": //2015.08.09. + p.FlairDecided=false; + finalflair=""; + break; + default: + finalflair=""; + break; + } + if(finalflair.length()==0) //<-- 2015.07.20. + return; + p.Flair=finalflair; //2015.08.08. + p.UserName=username; //2015.08.08. + System.out.println("Added new flair to "+playername+": "+finalflair); + for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08. + { + if(player.getName().equals(playername)) + { + //AppendPlayerDisplayFlair(player, username, finalflair); + AppendPlayerDisplayFlair(p, player); + break; + } + } + } + + public static String GetFlair(Player player) + { //2015.07.16. + String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08. + return flair==null ? "" : flair; + } + + //public static void AppendPlayerDisplayFlair(Player player, String username, String flair) + public static void AppendPlayerDisplayFlair(MaybeOfflinePlayer player, Player p) //<-- 2015.08.09. + { + + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).IgnoredFlair) + return; + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).AcceptedFlair) + { + AppendPlayerDisplayFlairFinal(p, player.Flair); //2015.07.20. + if(!player.FlairDecided) + p.sendMessage("§9Your flair type is unknown. Are you a non-presser or a can't press? (/u nonpresser or /u cantpress)§r"); //2015.08.09. + } + else + p.sendMessage("§9Are you Reddit user "+player.UserName+"?§r §6Type /u accept or /u ignore§r"); + } + + private static void AppendPlayerDisplayFlairFinal(Player player, String flair) + { //2015.07.20. + String color = GetColorForTown(GetPlayerTown(player)); //TO!DO: Multiple colors put on first capital letters + String[] colors = color.substring(1).split("§"); + String displayname=player.getName(); //2015.08.08. + ArrayList Positions=new ArrayList<>(); + for(int i=0; i=colors.length) + { + int x=0; + for(int i=0; i GetPlayers() + { + return Instance.getServer().getOnlinePlayers(); + } + + public static void LoadFiles(boolean reload) + { + + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/b5/40ecd766ce3e001518fa86d7ae2a1cf8 b/.metadata/.plugins/org.eclipse.core.resources/.history/b5/40ecd766ce3e001518fa86d7ae2a1cf8 new file mode 100644 index 0000000..39e5134 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/b5/40ecd766ce3e001518fa86d7ae2a1cf8 @@ -0,0 +1,31 @@ +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 boolean FlairSet; //2015.08.09. + 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); + } + /*public enum FlairClassType + { //2015.08.09. + NonPresser, + CantPress, + Undecided + }*/ +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/b5/c0ca4f18013e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/b5/c0ca4f18013e00151c31fb33fff4337f deleted file mode 100644 index 664f96d..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/b5/c0ca4f18013e00151c31fb33fff4337f +++ /dev/null @@ -1,122 +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": - { - 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/c5/703eba51893e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/b6/20667af5cf3e001518fa86d7ae2a1cf8 similarity index 83% rename from .metadata/.plugins/org.eclipse.core.resources/.history/c5/703eba51893e00151ce8ff6d4f74dabd rename to .metadata/.plugins/org.eclipse.core.resources/.history/b6/20667af5cf3e001518fa86d7ae2a1cf8 index cbeaea2..eab3194 100644 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/c5/703eba51893e00151ce8ff6d4f74dabd +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/b6/20667af5cf3e001518fa86d7ae2a1cf8 @@ -33,7 +33,8 @@ public class Commands implements CommandExecutor { if(!p.AcceptedFlair) { String flair=p.Flair; //2015.08.08. - PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + //PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + PluginMain.AppendPlayerDisplayFlair(p, player); p.AcceptedFlair=true; //2015.08.08. player.sendMessage("§6Your flair has been set:§r "+flair); } @@ -62,16 +63,20 @@ public class Commands implements CommandExecutor { case "admin": //2015.08.09. DoAdmin(player, args); break; + case "nonpresser": //2015.08.09. + break; default: return false; } return true; } - /*if(args[0].toLowerCase()=="reload") DoReload(null); //2015.07.20.*/ - else if(args[0].toLowerCase()=="admin") + else if(args.length>0 && args[0].toLowerCase().equals("admin")) //2015.08.09. + { DoAdmin(null, args); //2015.08.09. + return true; //2015.08.09. + } return false; } private static void DoReload(Player player) @@ -111,6 +116,7 @@ public class Commands implements CommandExecutor { System.out.println("Error!\n"+e); if(player!=null) player.sendMessage("§cAn error occured. See console for details.§r"); + PluginMain.LastException=e; //2015.08.09. } //} //else @@ -120,6 +126,7 @@ public class Commands implements CommandExecutor { { //2015.08.09. if(player==null || player.isOp() || player.getName()=="NorbiPeti") { + //System.out.println("Args length: " + args.length); if(args.length==1) { String message="§cUsage: /u admin reload|playerinfo§r"; @@ -135,6 +142,12 @@ public class Commands implements CommandExecutor { case "playerinfo": DoPlayerInfo(player, args); break; + case "getlasterror": + DoGetLastError(player, args); + default: + String message="§cUsage: /u admin reload|playerinfo§r"; + SendMessage(player, message); + return; } } else @@ -147,19 +160,20 @@ public class Commands implements CommandExecutor { { String message="§cUsage: /u admin playerinfo §r"; SendMessage(player, message); + return; } if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2])) { String message="§cPlayer not found: "+args[2]+"§r"; SendMessage(player, message); + return; } MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]); - SendMessage(player, "User flair: "+p.Flair); SendMessage(player, "Player name: "+p.PlayerName); + SendMessage(player, "User flair: "+p.Flair); SendMessage(player, "Username: "+p.UserName); SendMessage(player, "Flair accepted: "+p.AcceptedFlair); SendMessage(player, "Flair ignored: "+p.IgnoredFlair); - return; } private static void SendMessage(Player player, String message) { //2015.08.09. @@ -167,6 +181,17 @@ public class Commands implements CommandExecutor { System.out.println(message); else player.sendMessage(message); - return; + } + private static void DoGetLastError(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "getlasterror" + if(PluginMain.LastException!=null) + { + SendMessage(player, "Last error:"); + SendMessage(player, PluginMain.LastException.toString()); + PluginMain.LastException=null; + } + else + SendMessage(player, "There were no exceptions."); } } diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/b6/504cf350863e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/b6/504cf350863e00151ce8ff6d4f74dabd deleted file mode 100644 index 677ad35..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/b6/504cf350863e00151ce8ff6d4f74dabd +++ /dev/null @@ -1,131 +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; - MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. - //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - if(p.Flair==null) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. - { - case "accept": - { - if(p.IgnoredFlair) - p.IgnoredFlair=false; //2015.08.08. - if(!p.AcceptedFlair) - { - String flair=p.Flair; //2015.08.08. - PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. - p.AcceptedFlair=true; //2015.08.08. - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("§cYou already have this user's flair.§r"); - break; - } - case "ignore": - { - if(p.AcceptedFlair) - p.AcceptedFlair=false; //2015.08.08. - if(!p.IgnoredFlair) - { - p.IgnoredFlair=true; - String flair=p.Flair; //2015.08.08. - PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. - player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); - } - else - player.sendMessage("§cYou already ignored this request.§r"); - break; - } - case "reload": //2015.07.20. - DoReload(player); - break; - case "admin": //2015.08.09. - DoAdmin(player); - break; - default: - return false; - } - return true; - } - - if(args[0].toLowerCase()=="reload") - DoReload(null); //2015.07.20. - else if(args[0].toLowerCase()=="showerrors") - DoAdmin(null); //2015.08.09. - return false; - } - private static void DoReload(Player player) - { //2015.07.20. - if(player==null || player.isOp() || player.getName()=="NorbiPeti") - { - try - { - File file=new File("autoflairconfig.txt"); - if(file.exists()) - { - PluginMain.TownColors.clear(); - BufferedReader br=new BufferedReader(new FileReader(file)); - String line; - while((line=br.readLine())!=null) - { - String[] s=line.split(" "); - PluginMain.TownColors.put(s[0], s[1]); - } - br.close(); - for(Player p : PluginMain.GetPlayers()) - { - MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName()); - if(mp.Flair!=null) - { - String flair=mp.Flair; - PluginMain.RemovePlayerDisplayFlairFinal(p, flair); - PluginMain.AppendPlayerDisplayFlairFinal(p, flair); - } - } - String msg="§6Reloaded config file.§r"; - if(player!=null) - player.sendMessage(msg); - else - System.out.println(msg); - } - } - catch(Exception e) - { - System.out.println("Error!\n"+e); - if(player!=null) - player.sendMessage("§cAn error occured. See console for details.§r"); - } - } - else - player.sendMessage("§cYou need to be OP to use this command.§r"); - } - private static void DoAdmin(Player player) - { - if(player==null || player.isOp() || player.getName()=="NorbiPeti") - { - - } - else - player.sendMessage("§cYou need to be OP to use this command.§r"); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/b6/90a348520c3e00151089cca86c5b1a99 b/.metadata/.plugins/org.eclipse.core.resources/.history/b6/90a348520c3e00151089cca86c5b1a99 deleted file mode 100644 index 87c9d49..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/b6/90a348520c3e00151089cca86c5b1a99 +++ /dev/null @@ -1,432 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import java.io.BufferedReader; -import java.io.BufferedWriter; -import java.io.File; -import java.io.FileReader; -import java.io.FileWriter; -import java.io.IOException; -import java.io.InputStream; -import java.net.MalformedURLException; -import java.net.URL; -import java.net.URLConnection; -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; -import java.util.Map; - -import org.apache.commons.io.IOUtils; -import org.bukkit.entity.Player; -import org.bukkit.plugin.java.JavaPlugin; -import org.json.JSONArray; -import org.json.JSONObject; - -import com.palmergames.bukkit.towny.object.Town; -import com.palmergames.bukkit.towny.object.WorldCoord; - -public class PluginMain extends JavaPlugin -{ //Translated to Java: 2015.07.15. - //A user, which flair isn't obtainable: - //https://www.reddit.com/r/thebutton/comments/31c32v/i_pressed_the_button_without_really_thinking/ - private static PluginMain Instance; - // Fired when plugin is first enabled - @Override - public void onEnable() - { - System.out.println("The Button Auto-flair Plugin by NorbiPeti (:P)"); - //System.out.println("Original C# version: http://pastebin.com/tX8xCPbp"); - //System.out.println("The Java version is... Also made by the same person."); - //System.out.println("With the help of StackOverflow and similar."); - /*catch(MalformedURLException e) - { - } - catch(IOException e) - { - }*/ - getServer().getPluginManager().registerEvents(new PlayerListener(), this); - //System.out.println("Registering commands..."); - this.getCommand("u").setExecutor(new Commands()); - this.getCommand("u").setUsage(this.getCommand("u").getUsage().replace('&', '§')); - Instance=this; //2015.08.08. - try { - File file=new File("flairsaccepted.txt"); - if(file.exists()) - { - BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt")); - String line; - while ((line = br.readLine()) != null) - { - //AcceptedPlayers.add(line.replace("\n", "")); - String name=line.replace("\n", ""); - System.out.println("Name: " + name); - 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/b7/20f6378ed03e001518fa86d7ae2a1cf8 b/.metadata/.plugins/org.eclipse.core.resources/.history/b7/20f6378ed03e001518fa86d7ae2a1cf8 new file mode 100644 index 0000000..d6e50b3 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/b7/20f6378ed03e001518fa86d7ae2a1cf8 @@ -0,0 +1,204 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; + +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class Commands implements CommandExecutor { + // This method is called, when somebody uses our command + @Override + public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { + if (sender instanceof Player) { + Player player = (Player) sender; + if(args.length<1) + return false; + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. + //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) + if(p.Flair==null) + { + player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); + return true; + } + switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. + { + case "accept": + { + if(p.IgnoredFlair) + p.IgnoredFlair=false; //2015.08.08. + if(!p.AcceptedFlair) + { + String flair=p.Flair; //2015.08.08. + //PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + PluginMain.AppendPlayerDisplayFlair(p, player); + p.AcceptedFlair=true; //2015.08.08. + player.sendMessage("§6Your flair has been set:§r "+flair); + } + else + player.sendMessage("§cYou already have this user's flair.§r"); + break; + } + case "ignore": + { + if(p.AcceptedFlair) + p.AcceptedFlair=false; //2015.08.08. + if(!p.IgnoredFlair) + { + p.IgnoredFlair=true; + String flair=p.Flair; //2015.08.08. + PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. + player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); + } + else + player.sendMessage("§cYou already ignored this request.§r"); + break; + } + /*case "reload": //2015.07.20. + DoReload(player); + break;*/ + case "admin": //2015.08.09. + DoAdmin(player, args); + break; + case "nonpresser": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + } + break; + case "cantpress": //2015.08.09. + break; + default: + return false; + } + return true; + } + /*if(args[0].toLowerCase()=="reload") + DoReload(null); //2015.07.20.*/ + else if(args.length>0 && args[0].toLowerCase().equals("admin")) //2015.08.09. + { + DoAdmin(null, args); //2015.08.09. + return true; //2015.08.09. + } + return false; + } + private static void DoReload(Player player) + { //2015.07.20. + //if(player==null || player.isOp() || player.getName()=="NorbiPeti") + //{ + try + { + File file=new File("autoflairconfig.txt"); + if(file.exists()) + { + PluginMain.TownColors.clear(); + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + PluginMain.TownColors.put(s[0], s[1]); + } + br.close(); + for(Player p : PluginMain.GetPlayers()) + { + MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName()); + if(mp.Flair!=null) + { + String flair=mp.Flair; + PluginMain.RemovePlayerDisplayFlairFinal(p, flair); + //PluginMain.AppendPlayerDisplayFlairFinal(p, flair); + PluginMain.AppendPlayerDisplayFlair(mp, p); //2015.08.09. + } + } + String msg="§6Reloaded config file.§r"; + SendMessage(player, msg); //2015.08.09. + } + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + if(player!=null) + player.sendMessage("§cAn error occured. See console for details.§r"); + PluginMain.LastException=e; //2015.08.09. + } + //} + //else + //player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static void DoAdmin(Player player, String[] args) + { //2015.08.09. + if(player==null || player.isOp() || player.getName()=="NorbiPeti") + { + //System.out.println("Args length: " + args.length); + if(args.length==1) + { + String message="§cUsage: /u admin reload|playerinfo§r"; + SendMessage(player, message); + return; + } + //args[0] is "admin" + switch(args[1].toLowerCase()) + { + case "reload": + DoReload(player); + break; + case "playerinfo": + DoPlayerInfo(player, args); + break; + case "getlasterror": + DoGetLastError(player, args); + default: + String message="§cUsage: /u admin reload|playerinfo§r"; + SendMessage(player, message); + return; + } + } + else + player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static void DoPlayerInfo(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "playerinfo" + if(args.length==2) + { + String message="§cUsage: /u admin playerinfo §r"; + SendMessage(player, message); + return; + } + if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2])) + { + String message="§cPlayer not found: "+args[2]+"§r"; + SendMessage(player, message); + return; + } + MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]); + SendMessage(player, "Player name: "+p.PlayerName); + SendMessage(player, "User flair: "+p.Flair); + SendMessage(player, "Username: "+p.UserName); + SendMessage(player, "Flair accepted: "+p.AcceptedFlair); + SendMessage(player, "Flair ignored: "+p.IgnoredFlair); + } + private static void SendMessage(Player player, String message) + { //2015.08.09. + if(player==null) + System.out.println(message); + else + player.sendMessage(message); + } + private static void DoGetLastError(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "getlasterror" + if(PluginMain.LastException!=null) + { + SendMessage(player, "Last error:"); + SendMessage(player, PluginMain.LastException.toString()); + PluginMain.LastException=null; + } + else + SendMessage(player, "There were no exceptions."); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/b7/b048b351cd3e001518fa86d7ae2a1cf8 b/.metadata/.plugins/org.eclipse.core.resources/.history/b7/b048b351cd3e001518fa86d7ae2a1cf8 new file mode 100644 index 0000000..4b9e4c5 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/b7/b048b351cd3e001518fa86d7ae2a1cf8 @@ -0,0 +1,31 @@ +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 FlairClassType FlairType; + 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); + } + public enum FlairClassType + { //2015.08.09. + NonPresser, + CantPress, + Undecided + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/b8/5051ef26e13e001517108d149b613203 b/.metadata/.plugins/org.eclipse.core.resources/.history/b8/5051ef26e13e001517108d149b613203 new file mode 100644 index 0000000..f0829ec --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/b8/5051ef26e13e001517108d149b613203 @@ -0,0 +1,265 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +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; + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. + //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) + if(p.Flair==null) + { + player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); + return true; + } + switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. + { + case "accept": + { + if(p.IgnoredFlair) + p.IgnoredFlair=false; //2015.08.08. + if(!p.AcceptedFlair) + { + String flair=p.Flair; //2015.08.08. + //PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + PluginMain.AppendPlayerDisplayFlair(p, player); + p.AcceptedFlair=true; //2015.08.08. + player.sendMessage("§6Your flair has been set:§r "+flair); + } + else + player.sendMessage("§cYou already have this user's flair.§r"); + break; + } + case "ignore": + { + if(p.AcceptedFlair) + p.AcceptedFlair=false; //2015.08.08. + if(!p.IgnoredFlair) + { + p.IgnoredFlair=true; + String flair=p.Flair; //2015.08.08. + PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. + player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); + } + else + player.sendMessage("§cYou already ignored this request.§r"); + break; + } + /*case "reload": //2015.07.20. + DoReload(player); + break;*/ + case "admin": //2015.08.09. + DoAdmin(player, args); + break; + case "nonpresser": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§7(non-pr.)§r"; + break; + case "cantpress": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§r(can't press)§r"; + break; + default: + return false; + } + return true; + } + /*if(args[0].toLowerCase()=="reload") + DoReload(null); //2015.07.20.*/ + else if(args.length>0 && args[0].toLowerCase().equals("admin")) //2015.08.09. + { + DoAdmin(null, args); //2015.08.09. + return true; //2015.08.09. + } + return false; + } + private static void DoReload(Player player) + { //2015.07.20. + //if(player==null || player.isOp() || player.getName()=="NorbiPeti") + //{ + try + { + File file=new File("autoflairconfig.txt"); + if(file.exists()) + { + PluginMain.LoadFiles(true); //2015.08.09. + for(Player p : PluginMain.GetPlayers()) + { + MaybeOfflinePlayer mp = MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName()); + if(mp.Flair!=null) + { + String flair=mp.Flair; + PluginMain.RemovePlayerDisplayFlairFinal(p, flair); + //PluginMain.AppendPlayerDisplayFlairFinal(p, flair); + PluginMain.AppendPlayerDisplayFlair(mp, p); //2015.08.09. + } + String msg="§6Note: The auto-flair plugin has been reloaded. You might need to wait 10s to have your flair.§r"; //2015.08.09. + p.sendMessage(msg); //2015.08.09. + } + //String msg="§6Reloaded config file.§r"; + //SendMessage(player, msg); //2015.08.09. + } + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + if(player!=null) + player.sendMessage("§cAn error occured. See console for details.§r"); + PluginMain.LastException=e; //2015.08.09. + } + //} + //else + //player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static Player ReloadPlayer; //2015.08.09. + private static void DoAdmin(Player player, String[] args) + { //2015.08.09. + if(player==null || player.isOp() || player.getName()=="NorbiPeti") + { + //System.out.println("Args length: " + args.length); + if(args.length==1) + { + String message="§cUsage: /u admin reload|playerinfo§r"; + SendMessage(player, message); + return; + } + //args[0] is "admin" + switch(args[1].toLowerCase()) + { + case "reload": + ReloadPlayer=player; //2015.08.09. + SendMessage(player, "§6Make sure to save the current settings before you modify and reload them! Type /u admin confirm when done.§r"); + break; + case "playerinfo": + DoPlayerInfo(player, args); + break; + case "getlasterror": + DoGetLastError(player, args); + case "confirm": + if(ReloadPlayer==player) + DoReload(player); //2015.08.09. + else + SendMessage(player, "§cYou need to do /u admin reload first.§r"); + break; + case "save": + PluginMain.SaveFiles(); //2015.08.09. + SendMessage(player, "§6Saved files. Now you can edit them and reload if you want.§r"); + break; + case "setflair": //2015.08.09. + DoSetFlair(player, args); + break; + default: + String message="§cUsage: /u admin reload|playerinfo|getlasterror|save§r"; + SendMessage(player, message); + return; + } + } + else + player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static void DoPlayerInfo(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "playerinfo" + if(args.length==2) + { + String message="§cUsage: /u admin playerinfo §r"; + SendMessage(player, message); + return; + } + if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2])) + { + String message="§cPlayer not found: "+args[2]+"§r"; + SendMessage(player, message); + return; + } + MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]); + SendMessage(player, "Player name: "+p.PlayerName); + SendMessage(player, "User flair: "+p.Flair); + SendMessage(player, "Username: "+p.UserName); + SendMessage(player, "Flair accepted: "+p.AcceptedFlair); + SendMessage(player, "Flair ignored: "+p.IgnoredFlair); + } + private static void SendMessage(Player player, String message) + { //2015.08.09. + if(player==null) + System.out.println(message); + else + player.sendMessage(message); + } + private static void DoGetLastError(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "getlasterror" + if(PluginMain.LastException!=null) + { + SendMessage(player, "Last error:"); + SendMessage(player, PluginMain.LastException.toString()); + PluginMain.LastException=null; + } + else + SendMessage(player, "There were no exceptions."); + } + private static void SetPlayerFlair(Player player, MaybeOfflinePlayer targetplayer, String flair) + { //2015.08.09. + flair=flair.replace('&', '§'); + targetplayer.Flair=flair; + if(!PluginMain.RemoveLineFromFile("customflairs.txt", targetplayer.PlayerName)) + { + SendMessage(player, "§cError removing previous custom flair!§r"); + return; + } + File file=new File("customflairs.txt"); + try { + BufferedWriter bw; + bw = new BufferedWriter(new FileWriter(file, true)); + bw.write(targetplayer.PlayerName+"\n"); + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + PluginMain.LastException=e; //2015.08.09. + } + SendMessage(player, "§6The flair has been set. Player: "+targetplayer.PlayerName+" Flair: "+flair+"§r"); + } + private static void DoSetFlair(Player player, String[] args) + { + //args[0] is "admin" - args[1] is "setflair" + if(args.length<4) + { + SendMessage(player, "§cUsage: /u admin setflair "); + return; + } + SetPlayerFlair(player, MaybeOfflinePlayer.AddPlayerIfNeeded(args[2]), args[3]); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/b9/0096b9fee03e001517108d149b613203 b/.metadata/.plugins/org.eclipse.core.resources/.history/b9/0096b9fee03e001517108d149b613203 new file mode 100644 index 0000000..8b30515 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/b9/0096b9fee03e001517108d149b613203 @@ -0,0 +1,265 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +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; + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. + //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) + if(p.Flair==null) + { + player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); + return true; + } + switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. + { + case "accept": + { + if(p.IgnoredFlair) + p.IgnoredFlair=false; //2015.08.08. + if(!p.AcceptedFlair) + { + String flair=p.Flair; //2015.08.08. + //PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + PluginMain.AppendPlayerDisplayFlair(p, player); + p.AcceptedFlair=true; //2015.08.08. + player.sendMessage("§6Your flair has been set:§r "+flair); + } + else + player.sendMessage("§cYou already have this user's flair.§r"); + break; + } + case "ignore": + { + if(p.AcceptedFlair) + p.AcceptedFlair=false; //2015.08.08. + if(!p.IgnoredFlair) + { + p.IgnoredFlair=true; + String flair=p.Flair; //2015.08.08. + PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. + player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); + } + else + player.sendMessage("§cYou already ignored this request.§r"); + break; + } + /*case "reload": //2015.07.20. + DoReload(player); + break;*/ + case "admin": //2015.08.09. + DoAdmin(player, args); + break; + case "nonpresser": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§7(non-pr.)§r"; + break; + case "cantpress": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§r(can't press)§r"; + break; + default: + return false; + } + return true; + } + /*if(args[0].toLowerCase()=="reload") + DoReload(null); //2015.07.20.*/ + else if(args.length>0 && args[0].toLowerCase().equals("admin")) //2015.08.09. + { + DoAdmin(null, args); //2015.08.09. + return true; //2015.08.09. + } + return false; + } + private static void DoReload(Player player) + { //2015.07.20. + //if(player==null || player.isOp() || player.getName()=="NorbiPeti") + //{ + try + { + File file=new File("autoflairconfig.txt"); + if(file.exists()) + { + PluginMain.LoadFiles(true); //2015.08.09. + for(Player p : PluginMain.GetPlayers()) + { + MaybeOfflinePlayer mp = MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName()); + if(mp.Flair!=null) + { + String flair=mp.Flair; + PluginMain.RemovePlayerDisplayFlairFinal(p, flair); + //PluginMain.AppendPlayerDisplayFlairFinal(p, flair); + PluginMain.AppendPlayerDisplayFlair(mp, p); //2015.08.09. + } + String msg="§6Note: The auto-flair plugin has been reloaded. You might need to wait 10s to have your flair.§r"; //2015.08.09. + p.sendMessage(msg); //2015.08.09. + } + //String msg="§6Reloaded config file.§r"; + //SendMessage(player, msg); //2015.08.09. + } + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + if(player!=null) + player.sendMessage("§cAn error occured. See console for details.§r"); + PluginMain.LastException=e; //2015.08.09. + } + //} + //else + //player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static Player ReloadPlayer; //2015.08.09. + private static void DoAdmin(Player player, String[] args) + { //2015.08.09. + if(player==null || player.isOp() || player.getName()=="NorbiPeti") + { + //System.out.println("Args length: " + args.length); + if(args.length==1) + { + String message="§cUsage: /u admin reload|playerinfo§r"; + SendMessage(player, message); + return; + } + //args[0] is "admin" + switch(args[1].toLowerCase()) + { + case "reload": + ReloadPlayer=player; //2015.08.09. + SendMessage(player, "§6Make sure to save the current settings before you modify and reload them! Type /u admin confirm when done.§r"); + break; + case "playerinfo": + DoPlayerInfo(player, args); + break; + case "getlasterror": + DoGetLastError(player, args); + case "confirm": + if(ReloadPlayer==player) + DoReload(player); //2015.08.09. + else + SendMessage(player, "§cYou need to do /u admin reload first.§r"); + break; + case "save": + PluginMain.SaveFiles(); //2015.08.09. + SendMessage(player, "§6Saved files. Now you can edit them and reload if you want.§r"); + break; + case "setflair": + + break; + default: + String message="§cUsage: /u admin reload|playerinfo|getlasterror|save§r"; + SendMessage(player, message); + return; + } + } + else + player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static void DoPlayerInfo(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "playerinfo" + if(args.length==2) + { + String message="§cUsage: /u admin playerinfo §r"; + SendMessage(player, message); + return; + } + if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2])) + { + String message="§cPlayer not found: "+args[2]+"§r"; + SendMessage(player, message); + return; + } + MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]); + SendMessage(player, "Player name: "+p.PlayerName); + SendMessage(player, "User flair: "+p.Flair); + SendMessage(player, "Username: "+p.UserName); + SendMessage(player, "Flair accepted: "+p.AcceptedFlair); + SendMessage(player, "Flair ignored: "+p.IgnoredFlair); + } + private static void SendMessage(Player player, String message) + { //2015.08.09. + if(player==null) + System.out.println(message); + else + player.sendMessage(message); + } + private static void DoGetLastError(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "getlasterror" + if(PluginMain.LastException!=null) + { + SendMessage(player, "Last error:"); + SendMessage(player, PluginMain.LastException.toString()); + PluginMain.LastException=null; + } + else + SendMessage(player, "There were no exceptions."); + } + private static void SetPlayerFlair(Player player, MaybeOfflinePlayer targetplayer, String flair) + { //2015.08.09. + flair=flair.replace('&', '§'); + targetplayer.Flair=flair; + if(!PluginMain.RemoveLineFromFile("customflairs.txt", targetplayer.PlayerName)) + { + SendMessage(player, "§cError removing previous custom flair!§r"); + return; + } + File file=new File("customflairs.txt"); + try { + BufferedWriter bw; + bw = new BufferedWriter(new FileWriter(file, true)); + bw.write(targetplayer.PlayerName+"\n"); + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + PluginMain.LastException=e; //2015.08.09. + } + SendMessage(player, "§6The flair has been set. Player: "+targetplayer.PlayerName+" Flair: "+flair+"§r"); + } + private static void DoSetFlair(Player player, String args) + { + //args[0] is "admin" - args[1] is "setflair" + if(args.length()<4) + { + SendMessage(player, "§cUsage: /u admin setflair "); + return; + } + SetPlayerFlair(player, MaybeOfflinePlayer.AddPlayerIfNeeded(player.getName())) + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/b9/409c8390fe3d00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/b9/409c8390fe3d00151c31fb33fff4337f deleted file mode 100644 index 51a39bf..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/b9/409c8390fe3d00151c31fb33fff4337f +++ /dev/null @@ -1,122 +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()); - 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/50eb23fc013e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/b9/50eb23fc013e00151c31fb33fff4337f deleted file mode 100644 index 89e8084..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/b9/50eb23fc013e00151c31fb33fff4337f +++ /dev/null @@ -1,125 +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; - 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/ba/10207fd7df3e001517108d149b613203 b/.metadata/.plugins/org.eclipse.core.resources/.history/ba/10207fd7df3e001517108d149b613203 new file mode 100644 index 0000000..2e8d713 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/ba/10207fd7df3e001517108d149b613203 @@ -0,0 +1,254 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +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; + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. + //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) + if(p.Flair==null) + { + player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); + return true; + } + switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. + { + case "accept": + { + if(p.IgnoredFlair) + p.IgnoredFlair=false; //2015.08.08. + if(!p.AcceptedFlair) + { + String flair=p.Flair; //2015.08.08. + //PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + PluginMain.AppendPlayerDisplayFlair(p, player); + p.AcceptedFlair=true; //2015.08.08. + player.sendMessage("§6Your flair has been set:§r "+flair); + } + else + player.sendMessage("§cYou already have this user's flair.§r"); + break; + } + case "ignore": + { + if(p.AcceptedFlair) + p.AcceptedFlair=false; //2015.08.08. + if(!p.IgnoredFlair) + { + p.IgnoredFlair=true; + String flair=p.Flair; //2015.08.08. + PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. + player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); + } + else + player.sendMessage("§cYou already ignored this request.§r"); + break; + } + /*case "reload": //2015.07.20. + DoReload(player); + break;*/ + case "admin": //2015.08.09. + DoAdmin(player, args); + break; + case "nonpresser": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§7(non-pr.)§r"; + break; + case "cantpress": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§r(can't press)§r"; + break; + default: + return false; + } + return true; + } + /*if(args[0].toLowerCase()=="reload") + DoReload(null); //2015.07.20.*/ + else if(args.length>0 && args[0].toLowerCase().equals("admin")) //2015.08.09. + { + DoAdmin(null, args); //2015.08.09. + return true; //2015.08.09. + } + return false; + } + private static void DoReload(Player player) + { //2015.07.20. + //if(player==null || player.isOp() || player.getName()=="NorbiPeti") + //{ + try + { + File file=new File("autoflairconfig.txt"); + if(file.exists()) + { + PluginMain.LoadFiles(true); //2015.08.09. + for(Player p : PluginMain.GetPlayers()) + { + MaybeOfflinePlayer mp = MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName()); + if(mp.Flair!=null) + { + String flair=mp.Flair; + PluginMain.RemovePlayerDisplayFlairFinal(p, flair); + //PluginMain.AppendPlayerDisplayFlairFinal(p, flair); + PluginMain.AppendPlayerDisplayFlair(mp, p); //2015.08.09. + } + String msg="§6Note: The auto-flair plugin has been reloaded. You might need to wait 10s to have your flair.§r"; //2015.08.09. + p.sendMessage(msg); //2015.08.09. + } + //String msg="§6Reloaded config file.§r"; + //SendMessage(player, msg); //2015.08.09. + } + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + if(player!=null) + player.sendMessage("§cAn error occured. See console for details.§r"); + PluginMain.LastException=e; //2015.08.09. + } + //} + //else + //player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static Player ReloadPlayer; //2015.08.09. + private static void DoAdmin(Player player, String[] args) + { //2015.08.09. + if(player==null || player.isOp() || player.getName()=="NorbiPeti") + { + //System.out.println("Args length: " + args.length); + if(args.length==1) + { + String message="§cUsage: /u admin reload|playerinfo§r"; + SendMessage(player, message); + return; + } + //args[0] is "admin" + switch(args[1].toLowerCase()) + { + case "reload": + ReloadPlayer=player; //2015.08.09. + SendMessage(player, "§6Make sure to save the current settings before you modify and reload them! Type /u admin confirm when done.§r"); + break; + case "playerinfo": + DoPlayerInfo(player, args); + break; + case "getlasterror": + DoGetLastError(player, args); + case "confirm": + if(ReloadPlayer==player) + DoReload(player); //2015.08.09. + else + SendMessage(player, "§cYou need to do /u admin reload first.§r"); + break; + case "save": + PluginMain.SaveFiles(); //2015.08.09. + SendMessage(player, "§6Saved files. Now you can edit them and reload if you want.§r"); + break; + case "setflair": + break; + default: + String message="§cUsage: /u admin reload|playerinfo|getlasterror|save§r"; + SendMessage(player, message); + return; + } + } + else + player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static void DoPlayerInfo(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "playerinfo" + if(args.length==2) + { + String message="§cUsage: /u admin playerinfo §r"; + SendMessage(player, message); + return; + } + if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2])) + { + String message="§cPlayer not found: "+args[2]+"§r"; + SendMessage(player, message); + return; + } + MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]); + SendMessage(player, "Player name: "+p.PlayerName); + SendMessage(player, "User flair: "+p.Flair); + SendMessage(player, "Username: "+p.UserName); + SendMessage(player, "Flair accepted: "+p.AcceptedFlair); + SendMessage(player, "Flair ignored: "+p.IgnoredFlair); + } + private static void SendMessage(Player player, String message) + { //2015.08.09. + if(player==null) + System.out.println(message); + else + player.sendMessage(message); + } + private static void DoGetLastError(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "getlasterror" + if(PluginMain.LastException!=null) + { + SendMessage(player, "Last error:"); + SendMessage(player, PluginMain.LastException.toString()); + PluginMain.LastException=null; + } + else + SendMessage(player, "There were no exceptions."); + } + private static void SetPlayerFlair(Player player, Player targetplayer, String flair) + { //2015.08.09. + flair=flair.replace('&', '§'); + MaybeOfflinePlayer.AddPlayerIfNeeded(player.getName()).Flair=flair; + if(!PluginMain.RemoveLineFromFile("customflairs.txt", targetplayer.getName())) + { + SendMessage(player, "§cError removing previous custom flair!§r"); + return; + } + File file=new File("customflairs.txt"); + try { + BufferedWriter bw; + bw = new BufferedWriter(new FileWriter(file, true)); + bw.write(targetplayer.getName()+"\n"); + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + PluginMain.LastException=e; //2015.08.09. + } + SendMessage(player, "§6The flair has been set. Player: "+targetplayer.getName()+" Flair: "+flair+"§r"); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/ba/70faf280883e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/ba/70faf280883e00151ce8ff6d4f74dabd deleted file mode 100644 index dc9734e..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/ba/70faf280883e00151ce8ff6d4f74dabd +++ /dev/null @@ -1,172 +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; - MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. - //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - if(p.Flair==null) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. - { - case "accept": - { - if(p.IgnoredFlair) - p.IgnoredFlair=false; //2015.08.08. - if(!p.AcceptedFlair) - { - String flair=p.Flair; //2015.08.08. - PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. - p.AcceptedFlair=true; //2015.08.08. - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("§cYou already have this user's flair.§r"); - break; - } - case "ignore": - { - if(p.AcceptedFlair) - p.AcceptedFlair=false; //2015.08.08. - if(!p.IgnoredFlair) - { - p.IgnoredFlair=true; - String flair=p.Flair; //2015.08.08. - PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. - player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); - } - else - player.sendMessage("§cYou already ignored this request.§r"); - break; - } - /*case "reload": //2015.07.20. - DoReload(player); - break;*/ - case "admin": //2015.08.09. - DoAdmin(player, args); - break; - default: - return false; - } - return true; - } - - /*if(args[0].toLowerCase()=="reload") - DoReload(null); //2015.07.20.*/ - else if(args[0].toLowerCase()=="admin") - DoAdmin(null, args); //2015.08.09. - return false; - } - private static void DoReload(Player player) - { //2015.07.20. - //if(player==null || player.isOp() || player.getName()=="NorbiPeti") - //{ - try - { - File file=new File("autoflairconfig.txt"); - if(file.exists()) - { - PluginMain.TownColors.clear(); - BufferedReader br=new BufferedReader(new FileReader(file)); - String line; - while((line=br.readLine())!=null) - { - String[] s=line.split(" "); - PluginMain.TownColors.put(s[0], s[1]); - } - br.close(); - for(Player p : PluginMain.GetPlayers()) - { - MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName()); - if(mp.Flair!=null) - { - String flair=mp.Flair; - PluginMain.RemovePlayerDisplayFlairFinal(p, flair); - PluginMain.AppendPlayerDisplayFlairFinal(p, flair); - } - } - String msg="§6Reloaded config file.§r"; - if(player!=null) - player.sendMessage(msg); - else - System.out.println(msg); - } - } - catch(Exception e) - { - System.out.println("Error!\n"+e); - if(player!=null) - player.sendMessage("§cAn error occured. See console for details.§r"); - } - //} - //else - //player.sendMessage("§cYou need to be OP to use this command.§r"); - } - private static void DoAdmin(Player player, String[] args) - { //2015.08.09. - if(player==null || player.isOp() || player.getName()=="NorbiPeti") - { - if(args.length==1) - { - String message="§cUsage: /u admin reload|playerinfo§r"; - if(player==null) - System.out.println(message); - else - player.sendMessage(message); - return; - } - //args[0] is "admin" - switch(args[1].toLowerCase()) - { - case "reload": - DoReload(player); - break; - case "playerinfo": - DoPlayerInfo(player, args); - break; - } - } - else - player.sendMessage("§cYou need to be OP to use this command.§r"); - } - private static void DoPlayerInfo(Player player, String[] args) - { //2015.08.09. - //args[0] is "admin" - args[1] is "playerinfo" - if(args.length==2) - { - String message="§cUsage: /u admin playerinfo §r"; - if(player==null) - System.out.println(message); - else - player.sendMessage(message); - return; - } - if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2])) - { - String message="§cPlayer not found: "+args[2]+"§r"; - if(player==null) - System.out.println(message); - else - player.sendMessage(message); - return; - } - MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/bb/60b5d072043e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/bb/60b5d072043e00151c31fb33fff4337f deleted file mode 100644 index cd04256..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/bb/60b5d072043e00151c31fb33fff4337f +++ /dev/null @@ -1,126 +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; - 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/bc/30916f57cf3e001518fa86d7ae2a1cf8 b/.metadata/.plugins/org.eclipse.core.resources/.history/bc/30916f57cf3e001518fa86d7ae2a1cf8 new file mode 100644 index 0000000..262b029 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/bc/30916f57cf3e001518fa86d7ae2a1cf8 @@ -0,0 +1,362 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStream; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLConnection; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + +import org.apache.commons.io.IOUtils; +import org.bukkit.entity.Player; +import org.bukkit.plugin.java.JavaPlugin; +import org.json.JSONArray; +import org.json.JSONObject; + +import tk.sznp.thebuttonautoflair.MaybeOfflinePlayer.FlairClassType; + +import com.palmergames.bukkit.towny.object.Town; +import com.palmergames.bukkit.towny.object.WorldCoord; + +public class PluginMain extends JavaPlugin +{ //Translated to Java: 2015.07.15. + //A user, which flair isn't obtainable: + //https://www.reddit.com/r/thebutton/comments/31c32v/i_pressed_the_button_without_really_thinking/ + private static PluginMain Instance; + // Fired when plugin is first enabled + @Override + public void onEnable() + { + System.out.println("The Button Auto-flair Plugin by NorbiPeti (:P)"); + getServer().getPluginManager().registerEvents(new PlayerListener(), this); + this.getCommand("u").setExecutor(new Commands()); + this.getCommand("u").setUsage(this.getCommand("u").getUsage().replace('&', '§')); + Instance=this; //2015.08.08. + try { + File file=new File("flairsaccepted.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + //System.out.println("Name: " + name); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("flairsignored.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsignored.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("autoflairconfig.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + TownColors.put(s[0], s[1]); + } + br.close(); + } + //throw new IOException("Test"); //2015.08.09. + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + Runnable r=new Runnable(){public void run(){ThreadMethod();}}; + Thread t=new Thread(r); + t.start(); + } + Boolean stop=false; + // Fired when plugin is disabled + @Override + public void onDisable() + { + try + { + FileWriter fw; + fw = new FileWriter("flairsaccepted.txt"); + fw.close(); + fw = new FileWriter("flairsignored.txt"); + fw.close(); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + try { + File file=new File("flairsaccepted.txt"); + BufferedWriter bw=new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.AcceptedFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + file=new File("flairsignored.txt"); + bw = new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.IgnoredFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + stop=true; + } + + public void ThreadMethod() //<-- 2015.07.16. + { + while(!stop) + { + try + { + String body=DownloadString("https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/autoflair_system_comment_your_minecraft_name_and/.json?limit=1000"); + JSONArray json=new JSONArray(body).getJSONObject(1).getJSONObject("data").getJSONArray("children"); + for(Object obj : json) + { + JSONObject item = (JSONObject)obj; + String author=item.getJSONObject("data").getString("author"); + String ign=item.getJSONObject("data").getString("body"); + int start = ign.indexOf("IGN:") + "IGN:".length(); + int end = ign.indexOf(' ', start); + if (end == -1 || end == start) + end=ign.indexOf('\n', start); //2015.07.15. + if (end == -1 || end == start) + ign = ign.substring(start); + else + ign = ign.substring(start, end); + ign = ign.trim(); + if(HasIGFlair(ign)) + continue; + try { + Thread.sleep(10); + } catch(InterruptedException ex) { + Thread.currentThread().interrupt(); + } + String[] flairdata = DownloadString("http://karmadecay.com/thebutton-data.php?users=" + author).replace("\"", "").split(":"); + String flair; + if(flairdata.length > 1) //2015.07.15. + flair = flairdata[1]; + else + flair=""; + if (flair != "-1") + flair = flair + "s"; + else + flair = "non-presser"; + String flairclass; + if(flairdata.length>2) + flairclass = flairdata[2]; + else + flairclass="unknown"; + SetFlair(ign, flair, flairclass, author); + } + Thread.sleep(10000); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + } + + public static Exception LastException; //2015.08.09. + + public String DownloadString(String urlstr) throws MalformedURLException, IOException + { + URL url = new URL(urlstr); + URLConnection con = url.openConnection(); + con.setRequestProperty("User-Agent", "TheButtonAutoFlair"); + InputStream in = con.getInputStream(); + String encoding = con.getContentEncoding(); + encoding = encoding == null ? "UTF-8" : encoding; + String body = IOUtils.toString(in, encoding); + in.close(); + return body; + } + + public static Map TownColors=new HashMap(); //2015.07.20. + public Boolean HasIGFlair(String playername) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + return p.Flair!=null; //2015.08.08. + } + + public void SetFlair(String playername, String text, String flairclass, String username) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + String finalflair; + p.FlairDecided=true; + switch(flairclass) + { + case "press-1": + finalflair="§c("+text+")§r"; + break; + case "press-2": + finalflair="§6("+text+")§r"; + break; + case "press-3": + finalflair="§e("+text+")§r"; + break; + case "press-4": + finalflair="§a("+text+")§r"; + break; + case "press-5": + finalflair="§9("+text+")§r"; + break; + 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; + case "undecided": //2015.08.09. + p.FlairDecided=false; + finalflair=""; + break; + default: + finalflair=""; + break; + } + if(finalflair.length()==0) //<-- 2015.07.20. + return; + p.Flair=finalflair; //2015.08.08. + p.UserName=username; //2015.08.08. + System.out.println("Added new flair to "+playername+": "+finalflair); + for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08. + { + if(player.getName().equals(playername)) + { + AppendPlayerDisplayFlair(player, username, finalflair); + break; + } + } + } + + public static String GetFlair(Player player) + { //2015.07.16. + String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08. + return flair==null ? "" : flair; + } + + //public static void AppendPlayerDisplayFlair(Player player, String username, String flair) + public static void AppendPlayerDisplayFlair(MaybeOfflinePlayer player, Player p) //<-- 2015.08.09. + { + + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).IgnoredFlair) + return; + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).AcceptedFlair) + { + AppendPlayerDisplayFlairFinal(p, player.Flair); //2015.07.20. + } + else + player.sendMessage("§9Are you Reddit user "+username+"?§r §6Type /u accept or /u ignore§r"); + } + + private static void AppendPlayerDisplayFlairFinal(Player player, String flair) + { //2015.07.20. + String color = GetColorForTown(GetPlayerTown(player)); //TO!DO: Multiple colors put on first capital letters + String[] colors = color.substring(1).split("§"); + String displayname=player.getName(); //2015.08.08. + ArrayList Positions=new ArrayList<>(); + for(int i=0; i=colors.length) + { + int x=0; + for(int i=0; i GetPlayers() + { + return Instance.getServer().getOnlinePlayers(); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/bc/a0204038ce3e001518fa86d7ae2a1cf8 b/.metadata/.plugins/org.eclipse.core.resources/.history/bc/a0204038ce3e001518fa86d7ae2a1cf8 new file mode 100644 index 0000000..d838749 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/bc/a0204038ce3e001518fa86d7ae2a1cf8 @@ -0,0 +1,355 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStream; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLConnection; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + +import org.apache.commons.io.IOUtils; +import org.bukkit.entity.Player; +import org.bukkit.plugin.java.JavaPlugin; +import org.json.JSONArray; +import org.json.JSONObject; + +import com.palmergames.bukkit.towny.object.Town; +import com.palmergames.bukkit.towny.object.WorldCoord; + +public class PluginMain extends JavaPlugin +{ //Translated to Java: 2015.07.15. + //A user, which flair isn't obtainable: + //https://www.reddit.com/r/thebutton/comments/31c32v/i_pressed_the_button_without_really_thinking/ + private static PluginMain Instance; + // Fired when plugin is first enabled + @Override + public void onEnable() + { + System.out.println("The Button Auto-flair Plugin by NorbiPeti (:P)"); + getServer().getPluginManager().registerEvents(new PlayerListener(), this); + this.getCommand("u").setExecutor(new Commands()); + this.getCommand("u").setUsage(this.getCommand("u").getUsage().replace('&', '§')); + Instance=this; //2015.08.08. + try { + File file=new File("flairsaccepted.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + //System.out.println("Name: " + name); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("flairsignored.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsignored.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("autoflairconfig.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + TownColors.put(s[0], s[1]); + } + br.close(); + } + //throw new IOException("Test"); //2015.08.09. + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + Runnable r=new Runnable(){public void run(){ThreadMethod();}}; + Thread t=new Thread(r); + t.start(); + } + Boolean stop=false; + // Fired when plugin is disabled + @Override + public void onDisable() + { + try + { + FileWriter fw; + fw = new FileWriter("flairsaccepted.txt"); + fw.close(); + fw = new FileWriter("flairsignored.txt"); + fw.close(); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + try { + File file=new File("flairsaccepted.txt"); + BufferedWriter bw=new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.AcceptedFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + file=new File("flairsignored.txt"); + bw = new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.IgnoredFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + stop=true; + } + + public void ThreadMethod() //<-- 2015.07.16. + { + while(!stop) + { + try + { + String body=DownloadString("https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/autoflair_system_comment_your_minecraft_name_and/.json?limit=1000"); + JSONArray json=new JSONArray(body).getJSONObject(1).getJSONObject("data").getJSONArray("children"); + for(Object obj : json) + { + JSONObject item = (JSONObject)obj; + String author=item.getJSONObject("data").getString("author"); + String ign=item.getJSONObject("data").getString("body"); + int start = ign.indexOf("IGN:") + "IGN:".length(); + int end = ign.indexOf(' ', start); + if (end == -1 || end == start) + end=ign.indexOf('\n', start); //2015.07.15. + if (end == -1 || end == start) + ign = ign.substring(start); + else + ign = ign.substring(start, end); + ign = ign.trim(); + if(HasIGFlair(ign)) + continue; + try { + Thread.sleep(10); + } catch(InterruptedException ex) { + Thread.currentThread().interrupt(); + } + String[] flairdata = DownloadString("http://karmadecay.com/thebutton-data.php?users=" + author).replace("\"", "").split(":"); + String flair; + if(flairdata.length > 1) //2015.07.15. + flair = flairdata[1]; + else + flair=""; + if (flair != "-1") + flair = flair + "s"; + else + flair = "non-presser"; + String flairclass; + if(flairdata.length>2) + flairclass = flairdata[2]; + else + flairclass="unknown"; + SetFlair(ign, flair, flairclass, author); + } + Thread.sleep(10000); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + } + + public static Exception LastException; //2015.08.09. + + public String DownloadString(String urlstr) throws MalformedURLException, IOException + { + URL url = new URL(urlstr); + URLConnection con = url.openConnection(); + con.setRequestProperty("User-Agent", "TheButtonAutoFlair"); + InputStream in = con.getInputStream(); + String encoding = con.getContentEncoding(); + encoding = encoding == null ? "UTF-8" : encoding; + String body = IOUtils.toString(in, encoding); + in.close(); + return body; + } + + public static Map TownColors=new HashMap(); //2015.07.20. + public Boolean HasIGFlair(String playername) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + return p.Flair!=null; //2015.08.08. + } + + public void SetFlair(String playername, String text, String flairclass, String username) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + String finalflair; + switch(flairclass) + { + case "press-1": + finalflair="§c("+text+")§r"; + break; + case "press-2": + finalflair="§6("+text+")§r"; + break; + case "press-3": + finalflair="§e("+text+")§r"; + break; + case "press-4": + finalflair="§a("+text+")§r"; + break; + case "press-5": + finalflair="§9("+text+")§r"; + break; + 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; + case "undecided": //2015.08.09. + + finalflair=""; + break; + default: + finalflair=""; + break; + } + if(finalflair.length()==0) //<-- 2015.07.20. + return; + p.Flair=finalflair; //2015.08.08. + p.UserName=username; //2015.08.08. + System.out.println("Added new flair to "+playername+": "+finalflair); + for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08. + { + if(player.getName().equals(playername)) + { + AppendPlayerDisplayFlair(player, username, finalflair); + break; + } + } + } + + public static String GetFlair(Player player) + { //2015.07.16. + String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08. + return flair==null ? "" : flair; + } + + public static void AppendPlayerDisplayFlair(Player player, String username, String flair) + { + if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).IgnoredFlair) + return; + if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).AcceptedFlair) + AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + else + player.sendMessage("§9Are you Reddit user "+username+"?§r §6Type /u accept or /u ignore§r"); + } + + public static void AppendPlayerDisplayFlairFinal(Player player, String flair) + { //2015.07.20. + String color = GetColorForTown(GetPlayerTown(player)); //TO!DO: Multiple colors put on first capital letters + String[] colors = color.substring(1).split("§"); + String displayname=player.getName(); //2015.08.08. + ArrayList Positions=new ArrayList<>(); + for(int i=0; i=colors.length) + { + int x=0; + for(int i=0; i GetPlayers() + { + return Instance.getServer().getOnlinePlayers(); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/bc/a099c9afd13e001518fa86d7ae2a1cf8 b/.metadata/.plugins/org.eclipse.core.resources/.history/bc/a099c9afd13e001518fa86d7ae2a1cf8 new file mode 100644 index 0000000..3926be9 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/bc/a099c9afd13e001518fa86d7ae2a1cf8 @@ -0,0 +1,368 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStream; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLConnection; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + +import org.apache.commons.io.IOUtils; +import org.bukkit.entity.Player; +import org.bukkit.plugin.java.JavaPlugin; +import org.json.JSONArray; +import org.json.JSONObject; + +import com.palmergames.bukkit.towny.object.Town; +import com.palmergames.bukkit.towny.object.WorldCoord; + +public class PluginMain extends JavaPlugin +{ //Translated to Java: 2015.07.15. + //A user, which flair isn't obtainable: + //https://www.reddit.com/r/thebutton/comments/31c32v/i_pressed_the_button_without_really_thinking/ + private static PluginMain Instance; + // Fired when plugin is first enabled + @Override + public void onEnable() + { + System.out.println("The Button Auto-flair Plugin by NorbiPeti (:P)"); + getServer().getPluginManager().registerEvents(new PlayerListener(), this); + this.getCommand("u").setExecutor(new Commands()); + this.getCommand("u").setUsage(this.getCommand("u").getUsage().replace('&', '§')); + Instance=this; //2015.08.08. + LoadFiles(false); //2015.08.09. + Runnable r=new Runnable(){public void run(){ThreadMethod();}}; + Thread t=new Thread(r); + t.start(); + } + Boolean stop=false; + // Fired when plugin is disabled + @Override + public void onDisable() + { + try + { + FileWriter fw; + fw = new FileWriter("flairsaccepted.txt"); + fw.close(); + fw = new FileWriter("flairsignored.txt"); + fw.close(); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + try { + File file=new File("flairsaccepted.txt"); + BufferedWriter bw=new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.AcceptedFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + file=new File("flairsignored.txt"); + bw = new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.IgnoredFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + stop=true; + } + + public void ThreadMethod() //<-- 2015.07.16. + { + while(!stop) + { + try + { + String body=DownloadString("https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/autoflair_system_comment_your_minecraft_name_and/.json?limit=1000"); + JSONArray json=new JSONArray(body).getJSONObject(1).getJSONObject("data").getJSONArray("children"); + for(Object obj : json) + { + JSONObject item = (JSONObject)obj; + String author=item.getJSONObject("data").getString("author"); + String ign=item.getJSONObject("data").getString("body"); + int start = ign.indexOf("IGN:") + "IGN:".length(); + int end = ign.indexOf(' ', start); + if (end == -1 || end == start) + end=ign.indexOf('\n', start); //2015.07.15. + if (end == -1 || end == start) + ign = ign.substring(start); + else + ign = ign.substring(start, end); + ign = ign.trim(); + if(HasIGFlair(ign)) + continue; + try { + Thread.sleep(10); + } catch(InterruptedException ex) { + Thread.currentThread().interrupt(); + } + String[] flairdata = DownloadString("http://karmadecay.com/thebutton-data.php?users=" + author).replace("\"", "").split(":"); + String flair; + if(flairdata.length > 1) //2015.07.15. + flair = flairdata[1]; + else + flair=""; + if (flair != "-1") + flair = flair + "s"; + else + flair = "non-presser"; + String flairclass; + if(flairdata.length>2) + flairclass = flairdata[2]; + else + flairclass="unknown"; + SetFlair(ign, flair, flairclass, author); + } + Thread.sleep(10000); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + } + + public static Exception LastException; //2015.08.09. + + public String DownloadString(String urlstr) throws MalformedURLException, IOException + { + URL url = new URL(urlstr); + URLConnection con = url.openConnection(); + con.setRequestProperty("User-Agent", "TheButtonAutoFlair"); + InputStream in = con.getInputStream(); + String encoding = con.getContentEncoding(); + encoding = encoding == null ? "UTF-8" : encoding; + String body = IOUtils.toString(in, encoding); + in.close(); + return body; + } + + public static Map TownColors=new HashMap(); //2015.07.20. + public Boolean HasIGFlair(String playername) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + return p.Flair!=null; //2015.08.08. + } + + public void SetFlair(String playername, String text, String flairclass, String username) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + String finalflair; + p.FlairDecided=true; + switch(flairclass) + { + case "press-1": + finalflair="§c("+text+")§r"; + break; + case "press-2": + finalflair="§6("+text+")§r"; + break; + case "press-3": + finalflair="§e("+text+")§r"; + break; + case "press-4": + finalflair="§a("+text+")§r"; + break; + case "press-5": + finalflair="§9("+text+")§r"; + break; + 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; + case "undecided": //2015.08.09. + p.FlairDecided=false; + finalflair=""; + break; + default: + finalflair=""; + break; + } + if(finalflair.length()==0) //<-- 2015.07.20. + return; + p.Flair=finalflair; //2015.08.08. + p.UserName=username; //2015.08.08. + System.out.println("Added new flair to "+playername+": "+finalflair); + for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08. + { + if(player.getName().equals(playername)) + { + //AppendPlayerDisplayFlair(player, username, finalflair); + AppendPlayerDisplayFlair(p, player); + break; + } + } + } + + public static String GetFlair(Player player) + { //2015.07.16. + String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08. + return flair==null ? "" : flair; + } + + //public static void AppendPlayerDisplayFlair(Player player, String username, String flair) + public static void AppendPlayerDisplayFlair(MaybeOfflinePlayer player, Player p) //<-- 2015.08.09. + { + + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).IgnoredFlair) + return; + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).AcceptedFlair) + { + AppendPlayerDisplayFlairFinal(p, player.Flair); //2015.07.20. + if(!player.FlairDecided) + p.sendMessage("§9Your flair type is unknown. Are you a non-presser or a can't press? (/u nonpresser or /u cantpress)§r"); //2015.08.09. + } + else + p.sendMessage("§9Are you Reddit user "+player.UserName+"?§r §6Type /u accept or /u ignore§r"); + } + + private static void AppendPlayerDisplayFlairFinal(Player player, String flair) + { //2015.07.20. + String color = GetColorForTown(GetPlayerTown(player)); //TO!DO: Multiple colors put on first capital letters + String[] colors = color.substring(1).split("§"); + String displayname=player.getName(); //2015.08.08. + ArrayList Positions=new ArrayList<>(); + for(int i=0; i=colors.length) + { + int x=0; + for(int i=0; i GetPlayers() + { + return Instance.getServer().getOnlinePlayers(); + } + + public static void LoadFiles(boolean reload) + { + try { + File file=new File("flairsaccepted.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + //System.out.println("Name: " + name); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("flairsignored.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsignored.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("autoflairconfig.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + TownColors.put(s[0], s[1]); + } + br.close(); + } + //throw new IOException("Test"); //2015.08.09. + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/bd/907ef589dd3e001517108d149b613203 b/.metadata/.plugins/org.eclipse.core.resources/.history/bd/907ef589dd3e001517108d149b613203 new file mode 100644 index 0000000..6d2cbea --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/bd/907ef589dd3e001517108d149b613203 @@ -0,0 +1,408 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStream; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLConnection; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + +import org.apache.commons.io.IOUtils; +import org.bukkit.entity.Player; +import org.bukkit.plugin.java.JavaPlugin; +import org.json.JSONArray; +import org.json.JSONObject; + +import com.palmergames.bukkit.towny.object.Town; +import com.palmergames.bukkit.towny.object.WorldCoord; + +public class PluginMain extends JavaPlugin +{ //Translated to Java: 2015.07.15. + //A user, which flair isn't obtainable: + //https://www.reddit.com/r/thebutton/comments/31c32v/i_pressed_the_button_without_really_thinking/ + private static PluginMain Instance; + // Fired when plugin is first enabled + @Override + public void onEnable() + { + System.out.println("The Button Auto-flair Plugin by NorbiPeti (:P)"); + getServer().getPluginManager().registerEvents(new PlayerListener(), this); + this.getCommand("u").setExecutor(new Commands()); + this.getCommand("u").setUsage(this.getCommand("u").getUsage().replace('&', '§')); + Instance=this; //2015.08.08. + LoadFiles(false); //2015.08.09. + Runnable r=new Runnable(){public void run(){ThreadMethod();}}; + Thread t=new Thread(r); + t.start(); + } + Boolean stop=false; + // Fired when plugin is disabled + @Override + public void onDisable() + { + SaveFiles(); //2015.08.09. + stop=true; + } + + public void ThreadMethod() //<-- 2015.07.16. + { + while(!stop) + { + try + { + String body=DownloadString("https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/autoflair_system_comment_your_minecraft_name_and/.json?limit=1000"); + JSONArray json=new JSONArray(body).getJSONObject(1).getJSONObject("data").getJSONArray("children"); + for(Object obj : json) + { + JSONObject item = (JSONObject)obj; + String author=item.getJSONObject("data").getString("author"); + String ign=item.getJSONObject("data").getString("body"); + int start = ign.indexOf("IGN:") + "IGN:".length(); + if(start==-1) + continue; //2015.08.09. + int end = ign.indexOf(' ', start); + if (end == -1 || end == start) + end=ign.indexOf('\n', start); //2015.07.15. + if (end == -1 || end == start) + ign = ign.substring(start); + else + ign = ign.substring(start, end); + ign = ign.trim(); + if(HasIGFlair(ign)) + continue; + try { + Thread.sleep(10); + } catch(InterruptedException ex) { + Thread.currentThread().interrupt(); + } + String[] flairdata = DownloadString("http://karmadecay.com/thebutton-data.php?users=" + author).replace("\"", "").split(":"); + String flair; + if(flairdata.length > 1) //2015.07.15. + flair = flairdata[1]; + else + flair=""; + if (flair != "-1") + flair = flair + "s"; + else + flair = "non-presser"; + String flairclass; + if(flairdata.length>2) + flairclass = flairdata[2]; + else + flairclass="unknown"; + SetFlair(ign, flair, flairclass, author); + } + Thread.sleep(10000); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + } + + public static Exception LastException; //2015.08.09. + + public String DownloadString(String urlstr) throws MalformedURLException, IOException + { + URL url = new URL(urlstr); + URLConnection con = url.openConnection(); + con.setRequestProperty("User-Agent", "TheButtonAutoFlair"); + InputStream in = con.getInputStream(); + String encoding = con.getContentEncoding(); + encoding = encoding == null ? "UTF-8" : encoding; + String body = IOUtils.toString(in, encoding); + in.close(); + return body; + } + + public static Map TownColors=new HashMap(); //2015.07.20. + public Boolean HasIGFlair(String playername) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + return p.Flair!=null; //2015.08.08. + } + + public void SetFlair(String playername, String text, String flairclass, String username) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + String finalflair; + p.FlairDecided=true; + switch(flairclass) + { + case "press-1": + finalflair="§c("+text+")§r"; + break; + case "press-2": + finalflair="§6("+text+")§r"; + break; + case "press-3": + finalflair="§e("+text+")§r"; + break; + case "press-4": + finalflair="§a("+text+")§r"; + break; + case "press-5": + finalflair="§9("+text+")§r"; + break; + 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; + case "undecided": //2015.08.09. + p.FlairDecided=false; + finalflair=""; + break; + default: + finalflair=""; + break; + } + if(finalflair.length()==0) //<-- 2015.07.20. + return; + p.Flair=finalflair; //2015.08.08. + p.UserName=username; //2015.08.08. + System.out.println("Added new flair to "+playername+": "+finalflair); + for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08. + { + if(player.getName().equals(playername)) + { + //AppendPlayerDisplayFlair(player, username, finalflair); + AppendPlayerDisplayFlair(p, player); + break; + } + } + } + + public static String GetFlair(Player player) + { //2015.07.16. + String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08. + return flair==null ? "" : flair; + } + + //public static void AppendPlayerDisplayFlair(Player player, String username, String flair) + public static void AppendPlayerDisplayFlair(MaybeOfflinePlayer player, Player p) //<-- 2015.08.09. + { + + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).IgnoredFlair) + return; + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).AcceptedFlair) + { + AppendPlayerDisplayFlairFinal(p, player.Flair); //2015.07.20. + if(!player.FlairDecided) + p.sendMessage("§9Your flair type is unknown. Are you a non-presser or a can't press? (/u nonpresser or /u cantpress)§r"); //2015.08.09. + } + else + p.sendMessage("§9Are you Reddit user "+player.UserName+"?§r §6Type /u accept or /u ignore§r"); + } + + private static void AppendPlayerDisplayFlairFinal(Player player, String flair) + { //2015.07.20. + String color = GetColorForTown(GetPlayerTown(player)); //TO!DO: Multiple colors put on first capital letters + String[] colors = color.substring(1).split("§"); + String displayname=player.getName(); //2015.08.08. + ArrayList Positions=new ArrayList<>(); + for(int i=0; i=colors.length) + { + int x=0; + for(int i=0; i GetPlayers() + { + return Instance.getServer().getOnlinePlayers(); + } + + public static void LoadFiles(boolean reload) //<-- 2015.08.09. + { + if(reload) + { //2015.08.09. + System.out.println("Auto-flair plugin cleanup for reloading..."); + MaybeOfflinePlayer.AllPlayers.clear(); + TownColors.clear(); + } + System.out.println("Loading files for auto-flair plugin..."); //2015.08.09. + try { + File file=new File("flairsaccepted.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + //System.out.println("Name: " + name); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("flairsignored.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsignored.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("autoflairconfig.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + TownColors.put(s[0], s[1]); + } + br.close(); + } + file=new File("autoflairdecisions.txt"); //2015.08.09. + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + MaybeOfflinePlayer.AddPlayerIfNeeded(s[0]).Flair=s[1]; //2015.08.09. + } + br.close(); + } + //throw new IOException("Test"); //2015.08.09. + System.out.println("Auto-flair plugin loaded files!"); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + public static void SaveFiles() //<-- 2015.08.09. + { + try + { + FileWriter fw; + fw = new FileWriter("flairsaccepted.txt"); + fw.close(); + fw = new FileWriter("flairsignored.txt"); + fw.close(); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + try { + File file=new File("flairsaccepted.txt"); + BufferedWriter bw=new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.AcceptedFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + file=new File("flairsignored.txt"); + bw = new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.IgnoredFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + public static void SetPlayerFlair(Player player, String flair) + { //2015.08.09. + flair=flair.replace('&', '§'); + MaybeOfflinePlayer.AddPlayerIfNeeded(player.getName()).Flair=flair; + File file=new File("autoflairdecisions.txt"); + BufferedWriter bw=new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) + { + if(!player.AcceptedFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/bd/90d57cb4de3e001517108d149b613203 b/.metadata/.plugins/org.eclipse.core.resources/.history/bd/90d57cb4de3e001517108d149b613203 new file mode 100644 index 0000000..9b5ff96 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/bd/90d57cb4de3e001517108d149b613203 @@ -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.WorldCoord; + +public class PluginMain extends JavaPlugin +{ //Translated to Java: 2015.07.15. + //A user, which flair isn't obtainable: + //https://www.reddit.com/r/thebutton/comments/31c32v/i_pressed_the_button_without_really_thinking/ + private static PluginMain Instance; + // Fired when plugin is first enabled + @Override + public void onEnable() + { + System.out.println("The Button Auto-flair Plugin by NorbiPeti (:P)"); + getServer().getPluginManager().registerEvents(new PlayerListener(), this); + this.getCommand("u").setExecutor(new Commands()); + this.getCommand("u").setUsage(this.getCommand("u").getUsage().replace('&', '§')); + Instance=this; //2015.08.08. + LoadFiles(false); //2015.08.09. + Runnable r=new Runnable(){public void run(){ThreadMethod();}}; + Thread t=new Thread(r); + t.start(); + } + Boolean stop=false; + // Fired when plugin is disabled + @Override + public void onDisable() + { + SaveFiles(); //2015.08.09. + stop=true; + } + + public void ThreadMethod() //<-- 2015.07.16. + { + while(!stop) + { + try + { + String body=DownloadString("https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/autoflair_system_comment_your_minecraft_name_and/.json?limit=1000"); + JSONArray json=new JSONArray(body).getJSONObject(1).getJSONObject("data").getJSONArray("children"); + for(Object obj : json) + { + JSONObject item = (JSONObject)obj; + String author=item.getJSONObject("data").getString("author"); + String ign=item.getJSONObject("data").getString("body"); + int start = ign.indexOf("IGN:") + "IGN:".length(); + if(start==-1) + continue; //2015.08.09. + int end = ign.indexOf(' ', start); + if (end == -1 || end == start) + end=ign.indexOf('\n', start); //2015.07.15. + if (end == -1 || end == start) + ign = ign.substring(start); + else + ign = ign.substring(start, end); + ign = ign.trim(); + if(HasIGFlair(ign)) + continue; + try { + Thread.sleep(10); + } catch(InterruptedException ex) { + Thread.currentThread().interrupt(); + } + String[] flairdata = DownloadString("http://karmadecay.com/thebutton-data.php?users=" + author).replace("\"", "").split(":"); + String flair; + if(flairdata.length > 1) //2015.07.15. + flair = flairdata[1]; + else + flair=""; + if (flair != "-1") + flair = flair + "s"; + else + flair = "non-presser"; + String flairclass; + if(flairdata.length>2) + flairclass = flairdata[2]; + else + flairclass="unknown"; + SetFlair(ign, flair, flairclass, author); + } + Thread.sleep(10000); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + } + + public static Exception LastException; //2015.08.09. + + public String DownloadString(String urlstr) throws MalformedURLException, IOException + { + URL url = new URL(urlstr); + URLConnection con = url.openConnection(); + con.setRequestProperty("User-Agent", "TheButtonAutoFlair"); + InputStream in = con.getInputStream(); + String encoding = con.getContentEncoding(); + encoding = encoding == null ? "UTF-8" : encoding; + String body = IOUtils.toString(in, encoding); + in.close(); + return body; + } + + public static Map TownColors=new HashMap(); //2015.07.20. + public Boolean HasIGFlair(String playername) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + return p.Flair!=null; //2015.08.08. + } + + public void SetFlair(String playername, String text, String flairclass, String username) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + String finalflair; + p.FlairDecided=true; + switch(flairclass) + { + case "press-1": + finalflair="§c("+text+")§r"; + break; + case "press-2": + finalflair="§6("+text+")§r"; + break; + case "press-3": + finalflair="§e("+text+")§r"; + break; + case "press-4": + finalflair="§a("+text+")§r"; + break; + case "press-5": + finalflair="§9("+text+")§r"; + break; + 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; + case "undecided": //2015.08.09. + p.FlairDecided=false; + finalflair=""; + break; + default: + finalflair=""; + break; + } + if(finalflair.length()==0) //<-- 2015.07.20. + return; + p.Flair=finalflair; //2015.08.08. + p.UserName=username; //2015.08.08. + System.out.println("Added new flair to "+playername+": "+finalflair); + for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08. + { + if(player.getName().equals(playername)) + { + //AppendPlayerDisplayFlair(player, username, finalflair); + AppendPlayerDisplayFlair(p, player); + break; + } + } + } + + public static String GetFlair(Player player) + { //2015.07.16. + String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08. + return flair==null ? "" : flair; + } + + //public static void AppendPlayerDisplayFlair(Player player, String username, String flair) + public static void AppendPlayerDisplayFlair(MaybeOfflinePlayer player, Player p) //<-- 2015.08.09. + { + + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).IgnoredFlair) + return; + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).AcceptedFlair) + { + AppendPlayerDisplayFlairFinal(p, player.Flair); //2015.07.20. + if(!player.FlairDecided) + p.sendMessage("§9Your flair type is unknown. Are you a non-presser or a can't press? (/u nonpresser or /u cantpress)§r"); //2015.08.09. + } + else + p.sendMessage("§9Are you Reddit user "+player.UserName+"?§r §6Type /u accept or /u ignore§r"); + } + + private static void AppendPlayerDisplayFlairFinal(Player player, String flair) + { //2015.07.20. + String color = GetColorForTown(GetPlayerTown(player)); //TO!DO: Multiple colors put on first capital letters + String[] colors = color.substring(1).split("§"); + String displayname=player.getName(); //2015.08.08. + ArrayList Positions=new ArrayList<>(); + for(int i=0; i=colors.length) + { + int x=0; + for(int i=0; i GetPlayers() + { + return Instance.getServer().getOnlinePlayers(); + } + + public static void LoadFiles(boolean reload) //<-- 2015.08.09. + { + if(reload) + { //2015.08.09. + System.out.println("Auto-flair plugin cleanup for reloading..."); + MaybeOfflinePlayer.AllPlayers.clear(); + TownColors.clear(); + } + System.out.println("Loading files for auto-flair plugin..."); //2015.08.09. + try { + File file=new File("flairsaccepted.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + //System.out.println("Name: " + name); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("flairsignored.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsignored.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("autoflairconfig.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + TownColors.put(s[0], s[1]); + } + br.close(); + } + file=new File("customflairs.txt"); //2015.08.09. + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + MaybeOfflinePlayer.AddPlayerIfNeeded(s[0]).Flair=s[1]; //2015.08.09. + } + br.close(); + } + //throw new IOException("Test"); //2015.08.09. + System.out.println("Auto-flair plugin loaded files!"); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + public static void SaveFiles() //<-- 2015.08.09. + { + try + { + FileWriter fw; + fw = new FileWriter("flairsaccepted.txt"); + fw.close(); + fw = new FileWriter("flairsignored.txt"); + fw.close(); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + try { + File file=new File("flairsaccepted.txt"); + BufferedWriter bw=new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.AcceptedFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + file=new File("flairsignored.txt"); + bw = new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.IgnoredFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + public static void SetPlayerFlair(Player player, String flair) + { //2015.08.09. + flair=flair.replace('&', '§'); + MaybeOfflinePlayer.AddPlayerIfNeeded(player.getName()).Flair=flair; + File file=new File("customflairs.txt"); + try { + BufferedWriter bw; + bw = new BufferedWriter(new FileWriter(file, true)); + bw.write(player.getName()+"\n"); + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + public static bool RemoveLineFromFile(String file) + { + File inputFile = new File(file); + File tempFile = new File("_temp.txt"); + + try { + BufferedReader reader = new BufferedReader(new FileReader(inputFile)); + BufferedWriter writer = new BufferedWriter(new FileWriter(tempFile)); + + String lineToRemove = "bbb"; + String currentLine; + + while((currentLine = reader.readLine()) != null) { + // trim newline when comparing with lineToRemove + String trimmedLine = currentLine.trim(); + if(trimmedLine.equals(lineToRemove)) continue; + writer.write(currentLine + System.getProperty("line.separator")); + } + writer.close(); + reader.close(); + return tempFile.renameTo(inputFile); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + return false; + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/bd/90d70867df3e001517108d149b613203 b/.metadata/.plugins/org.eclipse.core.resources/.history/bd/90d70867df3e001517108d149b613203 new file mode 100644 index 0000000..2a1ad93 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/bd/90d70867df3e001517108d149b613203 @@ -0,0 +1,252 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +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; + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. + //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) + if(p.Flair==null) + { + player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); + return true; + } + switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. + { + case "accept": + { + if(p.IgnoredFlair) + p.IgnoredFlair=false; //2015.08.08. + if(!p.AcceptedFlair) + { + String flair=p.Flair; //2015.08.08. + //PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + PluginMain.AppendPlayerDisplayFlair(p, player); + p.AcceptedFlair=true; //2015.08.08. + player.sendMessage("§6Your flair has been set:§r "+flair); + } + else + player.sendMessage("§cYou already have this user's flair.§r"); + break; + } + case "ignore": + { + if(p.AcceptedFlair) + p.AcceptedFlair=false; //2015.08.08. + if(!p.IgnoredFlair) + { + p.IgnoredFlair=true; + String flair=p.Flair; //2015.08.08. + PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. + player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); + } + else + player.sendMessage("§cYou already ignored this request.§r"); + break; + } + /*case "reload": //2015.07.20. + DoReload(player); + break;*/ + case "admin": //2015.08.09. + DoAdmin(player, args); + break; + case "nonpresser": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§7(non-pr.)§r"; + break; + case "cantpress": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§r(can't press)§r"; + break; + default: + return false; + } + return true; + } + /*if(args[0].toLowerCase()=="reload") + DoReload(null); //2015.07.20.*/ + else if(args.length>0 && args[0].toLowerCase().equals("admin")) //2015.08.09. + { + DoAdmin(null, args); //2015.08.09. + return true; //2015.08.09. + } + return false; + } + private static void DoReload(Player player) + { //2015.07.20. + //if(player==null || player.isOp() || player.getName()=="NorbiPeti") + //{ + try + { + File file=new File("autoflairconfig.txt"); + if(file.exists()) + { + PluginMain.LoadFiles(true); //2015.08.09. + for(Player p : PluginMain.GetPlayers()) + { + MaybeOfflinePlayer mp = MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName()); + if(mp.Flair!=null) + { + String flair=mp.Flair; + PluginMain.RemovePlayerDisplayFlairFinal(p, flair); + //PluginMain.AppendPlayerDisplayFlairFinal(p, flair); + PluginMain.AppendPlayerDisplayFlair(mp, p); //2015.08.09. + } + String msg="§6Note: The auto-flair plugin has been reloaded. You might need to wait 10s to have your flair.§r"; //2015.08.09. + p.sendMessage(msg); //2015.08.09. + } + //String msg="§6Reloaded config file.§r"; + //SendMessage(player, msg); //2015.08.09. + } + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + if(player!=null) + player.sendMessage("§cAn error occured. See console for details.§r"); + PluginMain.LastException=e; //2015.08.09. + } + //} + //else + //player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static Player ReloadPlayer; //2015.08.09. + private static void DoAdmin(Player player, String[] args) + { //2015.08.09. + if(player==null || player.isOp() || player.getName()=="NorbiPeti") + { + //System.out.println("Args length: " + args.length); + if(args.length==1) + { + String message="§cUsage: /u admin reload|playerinfo§r"; + SendMessage(player, message); + return; + } + //args[0] is "admin" + switch(args[1].toLowerCase()) + { + case "reload": + ReloadPlayer=player; //2015.08.09. + SendMessage(player, "§6Make sure to save the current settings before you modify and reload them! Type /u admin confirm when done.§r"); + break; + case "playerinfo": + DoPlayerInfo(player, args); + break; + case "getlasterror": + DoGetLastError(player, args); + case "confirm": + if(ReloadPlayer==player) + DoReload(player); //2015.08.09. + else + SendMessage(player, "§cYou need to do /u admin reload first.§r"); + break; + case "save": + PluginMain.SaveFiles(); //2015.08.09. + SendMessage(player, "§6Saved files. Now you can edit them and reload if you want.§r"); + break; + default: + String message="§cUsage: /u admin reload|playerinfo|getlasterror§r"; + SendMessage(player, message); + return; + } + } + else + player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static void DoPlayerInfo(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "playerinfo" + if(args.length==2) + { + String message="§cUsage: /u admin playerinfo §r"; + SendMessage(player, message); + return; + } + if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2])) + { + String message="§cPlayer not found: "+args[2]+"§r"; + SendMessage(player, message); + return; + } + MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]); + SendMessage(player, "Player name: "+p.PlayerName); + SendMessage(player, "User flair: "+p.Flair); + SendMessage(player, "Username: "+p.UserName); + SendMessage(player, "Flair accepted: "+p.AcceptedFlair); + SendMessage(player, "Flair ignored: "+p.IgnoredFlair); + } + private static void SendMessage(Player player, String message) + { //2015.08.09. + if(player==null) + System.out.println(message); + else + player.sendMessage(message); + } + private static void DoGetLastError(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "getlasterror" + if(PluginMain.LastException!=null) + { + SendMessage(player, "Last error:"); + SendMessage(player, PluginMain.LastException.toString()); + PluginMain.LastException=null; + } + else + SendMessage(player, "There were no exceptions."); + } + private static void SetPlayerFlair(Player player, String flair) + { //2015.08.09. + flair=flair.replace('&', '§'); + MaybeOfflinePlayer.AddPlayerIfNeeded(player.getName()).Flair=flair; + if(!PluginMain.RemoveLineFromFile("customflairs.txt")) + { + SendMessage(player, "§cError removing previous custom flair!§r"); + return; + } + File file=new File("customflairs.txt"); + try { + BufferedWriter bw; + bw = new BufferedWriter(new FileWriter(file, true)); + bw.write(player.getName()+"\n"); + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + PluginMain.LastException=e; //2015.08.09. + } + SendMessage(player, "§6The flair has been set. Player: "+player.getName()+" Flair: "+flair+"§r"); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/bd/d02b22e3883e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/bd/d02b22e3883e00151ce8ff6d4f74dabd deleted file mode 100644 index 80c391c..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/bd/d02b22e3883e00151ce8ff6d4f74dabd +++ /dev/null @@ -1,167 +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; - MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. - //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - if(p.Flair==null) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. - { - case "accept": - { - if(p.IgnoredFlair) - p.IgnoredFlair=false; //2015.08.08. - if(!p.AcceptedFlair) - { - String flair=p.Flair; //2015.08.08. - PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. - p.AcceptedFlair=true; //2015.08.08. - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("§cYou already have this user's flair.§r"); - break; - } - case "ignore": - { - if(p.AcceptedFlair) - p.AcceptedFlair=false; //2015.08.08. - if(!p.IgnoredFlair) - { - p.IgnoredFlair=true; - String flair=p.Flair; //2015.08.08. - PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. - player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); - } - else - player.sendMessage("§cYou already ignored this request.§r"); - break; - } - /*case "reload": //2015.07.20. - DoReload(player); - break;*/ - case "admin": //2015.08.09. - DoAdmin(player, args); - break; - default: - return false; - } - return true; - } - - /*if(args[0].toLowerCase()=="reload") - DoReload(null); //2015.07.20.*/ - else if(args[0].toLowerCase()=="admin") - DoAdmin(null, args); //2015.08.09. - return false; - } - private static void DoReload(Player player) - { //2015.07.20. - //if(player==null || player.isOp() || player.getName()=="NorbiPeti") - //{ - try - { - File file=new File("autoflairconfig.txt"); - if(file.exists()) - { - PluginMain.TownColors.clear(); - BufferedReader br=new BufferedReader(new FileReader(file)); - String line; - while((line=br.readLine())!=null) - { - String[] s=line.split(" "); - PluginMain.TownColors.put(s[0], s[1]); - } - br.close(); - for(Player p : PluginMain.GetPlayers()) - { - MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName()); - if(mp.Flair!=null) - { - String flair=mp.Flair; - PluginMain.RemovePlayerDisplayFlairFinal(p, flair); - PluginMain.AppendPlayerDisplayFlairFinal(p, flair); - } - } - String msg="§6Reloaded config file.§r"; - SendMessage(player, msg); //2015.08.09. - } - } - catch(Exception e) - { - System.out.println("Error!\n"+e); - if(player!=null) - player.sendMessage("§cAn error occured. See console for details.§r"); - } - //} - //else - //player.sendMessage("§cYou need to be OP to use this command.§r"); - } - private static void DoAdmin(Player player, String[] args) - { //2015.08.09. - if(player==null || player.isOp() || player.getName()=="NorbiPeti") - { - if(args.length==1) - { - String message="§cUsage: /u admin reload|playerinfo§r"; - SendMessage(player, message); - return; - } - //args[0] is "admin" - switch(args[1].toLowerCase()) - { - case "reload": - DoReload(player); - break; - case "playerinfo": - DoPlayerInfo(player, args); - break; - } - } - else - player.sendMessage("§cYou need to be OP to use this command.§r"); - } - private static void DoPlayerInfo(Player player, String[] args) - { //2015.08.09. - //args[0] is "admin" - args[1] is "playerinfo" - if(args.length==2) - { - String message="§cUsage: /u admin playerinfo §r"; - SendMessage(player, message); - } - if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2])) - { - String message="§cPlayer not found: "+args[2]+"§r"; - SendMessage(player, message); - } - MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]); - return; - } - private static void SendMessage(Player player, String message) - { //2015.08.09. - if(player==null) - System.out.println(message); - else - player.sendMessage(message); - return; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/be/d0face78043e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/be/d0face78043e00151c31fb33fff4337f deleted file mode 100644 index 87c0c13..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/be/d0face78043e00151c31fb33fff4337f +++ /dev/null @@ -1,126 +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; - 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/60a98f74863e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/bf/60a98f74863e00151ce8ff6d4f74dabd deleted file mode 100644 index a18a6c0..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/bf/60a98f74863e00151ce8ff6d4f74dabd +++ /dev/null @@ -1,131 +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; - MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. - //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - if(p.Flair==null) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. - { - case "accept": - { - if(p.IgnoredFlair) - p.IgnoredFlair=false; //2015.08.08. - if(!p.AcceptedFlair) - { - String flair=p.Flair; //2015.08.08. - PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. - p.AcceptedFlair=true; //2015.08.08. - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("§cYou already have this user's flair.§r"); - break; - } - case "ignore": - { - if(p.AcceptedFlair) - p.AcceptedFlair=false; //2015.08.08. - if(!p.IgnoredFlair) - { - p.IgnoredFlair=true; - String flair=p.Flair; //2015.08.08. - PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. - player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); - } - else - player.sendMessage("§cYou already ignored this request.§r"); - break; - } - case "reload": //2015.07.20. - DoReload(player); - break; - case "admin": //2015.08.09. - DoAdmin(player, args); - break; - default: - return false; - } - return true; - } - - if(args[0].toLowerCase()=="reload") - DoReload(null); //2015.07.20. - else if(args[0].toLowerCase()=="admin") - DoAdmin(null, args); //2015.08.09. - return false; - } - private static void DoReload(Player player) - { //2015.07.20. - if(player==null || player.isOp() || player.getName()=="NorbiPeti") - { - try - { - File file=new File("autoflairconfig.txt"); - if(file.exists()) - { - PluginMain.TownColors.clear(); - BufferedReader br=new BufferedReader(new FileReader(file)); - String line; - while((line=br.readLine())!=null) - { - String[] s=line.split(" "); - PluginMain.TownColors.put(s[0], s[1]); - } - br.close(); - for(Player p : PluginMain.GetPlayers()) - { - MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName()); - if(mp.Flair!=null) - { - String flair=mp.Flair; - PluginMain.RemovePlayerDisplayFlairFinal(p, flair); - PluginMain.AppendPlayerDisplayFlairFinal(p, flair); - } - } - String msg="§6Reloaded config file.§r"; - if(player!=null) - player.sendMessage(msg); - else - System.out.println(msg); - } - } - catch(Exception e) - { - System.out.println("Error!\n"+e); - if(player!=null) - player.sendMessage("§cAn error occured. See console for details.§r"); - } - } - else - player.sendMessage("§cYou need to be OP to use this command.§r"); - } - private static void DoAdmin(Player player, String[] args) - { - if(player==null || player.isOp() || player.getName()=="NorbiPeti") - { - - } - else - player.sendMessage("§cYou need to be OP to use this command.§r"); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/bf/a056849fd33e001518fa86d7ae2a1cf8 b/.metadata/.plugins/org.eclipse.core.resources/.history/bf/a056849fd33e001518fa86d7ae2a1cf8 new file mode 100644 index 0000000..ef4123d --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/bf/a056849fd33e001518fa86d7ae2a1cf8 @@ -0,0 +1,219 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; + +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class Commands implements CommandExecutor { + // This method is called, when somebody uses our command + @Override + public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { + if (sender instanceof Player) { + Player player = (Player) sender; + if(args.length<1) + return false; + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. + //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) + if(p.Flair==null) + { + player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); + return true; + } + switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. + { + case "accept": + { + if(p.IgnoredFlair) + p.IgnoredFlair=false; //2015.08.08. + if(!p.AcceptedFlair) + { + String flair=p.Flair; //2015.08.08. + //PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + PluginMain.AppendPlayerDisplayFlair(p, player); + p.AcceptedFlair=true; //2015.08.08. + player.sendMessage("§6Your flair has been set:§r "+flair); + } + else + player.sendMessage("§cYou already have this user's flair.§r"); + break; + } + case "ignore": + { + if(p.AcceptedFlair) + p.AcceptedFlair=false; //2015.08.08. + if(!p.IgnoredFlair) + { + p.IgnoredFlair=true; + String flair=p.Flair; //2015.08.08. + PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. + player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); + } + else + player.sendMessage("§cYou already ignored this request.§r"); + break; + } + /*case "reload": //2015.07.20. + DoReload(player); + break;*/ + case "admin": //2015.08.09. + DoAdmin(player, args); + break; + case "nonpresser": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§7(non-pr.)§r"; + break; + case "cantpress": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§r(can't press)§r"; + break; + default: + return false; + } + return true; + } + /*if(args[0].toLowerCase()=="reload") + DoReload(null); //2015.07.20.*/ + else if(args.length>0 && args[0].toLowerCase().equals("admin")) //2015.08.09. + { + DoAdmin(null, args); //2015.08.09. + return true; //2015.08.09. + } + return false; + } + private static void DoReload(Player player) + { //2015.07.20. + //if(player==null || player.isOp() || player.getName()=="NorbiPeti") + //{ + try + { + File file=new File("autoflairconfig.txt"); + if(file.exists()) + { + PluginMain.LoadFiles(true); //2015.08.09. + for(Player p : PluginMain.GetPlayers()) + { + MaybeOfflinePlayer mp = MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName()); + if(mp.Flair!=null) + { + String flair=mp.Flair; + PluginMain.RemovePlayerDisplayFlairFinal(p, flair); + //PluginMain.AppendPlayerDisplayFlairFinal(p, flair); + PluginMain.AppendPlayerDisplayFlair(mp, p); //2015.08.09. + } + String msg="§6Note: The auto-flair plugin has been reloaded. You might need to wait 10s to have your flair.§r"; //2015.08.09. + p.sendMessage(msg); //2015.08.09. + } + //String msg="§6Reloaded config file.§r"; + //SendMessage(player, msg); //2015.08.09. + } + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + if(player!=null) + player.sendMessage("§cAn error occured. See console for details.§r"); + PluginMain.LastException=e; //2015.08.09. + } + //} + //else + //player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static void DoAdmin(Player player, String[] args) + { //2015.08.09. + if(player==null || player.isOp() || player.getName()=="NorbiPeti") + { + //System.out.println("Args length: " + args.length); + if(args.length==1) + { + String message="§cUsage: /u admin reload|playerinfo§r"; + SendMessage(player, message); + return; + } + //args[0] is "admin" + switch(args[1].toLowerCase()) + { + case "reload": + DoReload(player); + break; + case "playerinfo": + DoPlayerInfo(player, args); + break; + case "getlasterror": + DoGetLastError(player, args); + case "confirm": + + break; + default: + String message="§cUsage: /u admin reload|playerinfo§r"; + SendMessage(player, message); + return; + } + } + else + player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static void DoPlayerInfo(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "playerinfo" + if(args.length==2) + { + String message="§cUsage: /u admin playerinfo §r"; + SendMessage(player, message); + return; + } + if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2])) + { + String message="§cPlayer not found: "+args[2]+"§r"; + SendMessage(player, message); + return; + } + MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]); + SendMessage(player, "Player name: "+p.PlayerName); + SendMessage(player, "User flair: "+p.Flair); + SendMessage(player, "Username: "+p.UserName); + SendMessage(player, "Flair accepted: "+p.AcceptedFlair); + SendMessage(player, "Flair ignored: "+p.IgnoredFlair); + } + private static void SendMessage(Player player, String message) + { //2015.08.09. + if(player==null) + System.out.println(message); + else + player.sendMessage(message); + } + private static void DoGetLastError(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "getlasterror" + if(PluginMain.LastException!=null) + { + SendMessage(player, "Last error:"); + SendMessage(player, PluginMain.LastException.toString()); + PluginMain.LastException=null; + } + else + SendMessage(player, "There were no exceptions."); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/bf/a0d1b862cf3e001518fa86d7ae2a1cf8 b/.metadata/.plugins/org.eclipse.core.resources/.history/bf/a0d1b862cf3e001518fa86d7ae2a1cf8 new file mode 100644 index 0000000..0fdd3aa --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/bf/a0d1b862cf3e001518fa86d7ae2a1cf8 @@ -0,0 +1,364 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.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 tk.sznp.thebuttonautoflair.MaybeOfflinePlayer.FlairClassType; + +import com.palmergames.bukkit.towny.object.Town; +import com.palmergames.bukkit.towny.object.WorldCoord; + +public class PluginMain extends JavaPlugin +{ //Translated to Java: 2015.07.15. + //A user, which flair isn't obtainable: + //https://www.reddit.com/r/thebutton/comments/31c32v/i_pressed_the_button_without_really_thinking/ + private static PluginMain Instance; + // Fired when plugin is first enabled + @Override + public void onEnable() + { + System.out.println("The Button Auto-flair Plugin by NorbiPeti (:P)"); + getServer().getPluginManager().registerEvents(new PlayerListener(), this); + this.getCommand("u").setExecutor(new Commands()); + this.getCommand("u").setUsage(this.getCommand("u").getUsage().replace('&', '§')); + Instance=this; //2015.08.08. + try { + File file=new File("flairsaccepted.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + //System.out.println("Name: " + name); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("flairsignored.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsignored.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("autoflairconfig.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + TownColors.put(s[0], s[1]); + } + br.close(); + } + //throw new IOException("Test"); //2015.08.09. + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + Runnable r=new Runnable(){public void run(){ThreadMethod();}}; + Thread t=new Thread(r); + t.start(); + } + Boolean stop=false; + // Fired when plugin is disabled + @Override + public void onDisable() + { + try + { + FileWriter fw; + fw = new FileWriter("flairsaccepted.txt"); + fw.close(); + fw = new FileWriter("flairsignored.txt"); + fw.close(); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + try { + File file=new File("flairsaccepted.txt"); + BufferedWriter bw=new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.AcceptedFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + file=new File("flairsignored.txt"); + bw = new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.IgnoredFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + stop=true; + } + + public void ThreadMethod() //<-- 2015.07.16. + { + while(!stop) + { + try + { + String body=DownloadString("https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/autoflair_system_comment_your_minecraft_name_and/.json?limit=1000"); + JSONArray json=new JSONArray(body).getJSONObject(1).getJSONObject("data").getJSONArray("children"); + for(Object obj : json) + { + JSONObject item = (JSONObject)obj; + String author=item.getJSONObject("data").getString("author"); + String ign=item.getJSONObject("data").getString("body"); + int start = ign.indexOf("IGN:") + "IGN:".length(); + int end = ign.indexOf(' ', start); + if (end == -1 || end == start) + end=ign.indexOf('\n', start); //2015.07.15. + if (end == -1 || end == start) + ign = ign.substring(start); + else + ign = ign.substring(start, end); + ign = ign.trim(); + if(HasIGFlair(ign)) + continue; + try { + Thread.sleep(10); + } catch(InterruptedException ex) { + Thread.currentThread().interrupt(); + } + String[] flairdata = DownloadString("http://karmadecay.com/thebutton-data.php?users=" + author).replace("\"", "").split(":"); + String flair; + if(flairdata.length > 1) //2015.07.15. + flair = flairdata[1]; + else + flair=""; + if (flair != "-1") + flair = flair + "s"; + else + flair = "non-presser"; + String flairclass; + if(flairdata.length>2) + flairclass = flairdata[2]; + else + flairclass="unknown"; + SetFlair(ign, flair, flairclass, author); + } + Thread.sleep(10000); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + } + + public static Exception LastException; //2015.08.09. + + public String DownloadString(String urlstr) throws MalformedURLException, IOException + { + URL url = new URL(urlstr); + URLConnection con = url.openConnection(); + con.setRequestProperty("User-Agent", "TheButtonAutoFlair"); + InputStream in = con.getInputStream(); + String encoding = con.getContentEncoding(); + encoding = encoding == null ? "UTF-8" : encoding; + String body = IOUtils.toString(in, encoding); + in.close(); + return body; + } + + public static Map TownColors=new HashMap(); //2015.07.20. + public Boolean HasIGFlair(String playername) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + return p.Flair!=null; //2015.08.08. + } + + public void SetFlair(String playername, String text, String flairclass, String username) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + String finalflair; + p.FlairDecided=true; + switch(flairclass) + { + case "press-1": + finalflair="§c("+text+")§r"; + break; + case "press-2": + finalflair="§6("+text+")§r"; + break; + case "press-3": + finalflair="§e("+text+")§r"; + break; + case "press-4": + finalflair="§a("+text+")§r"; + break; + case "press-5": + finalflair="§9("+text+")§r"; + break; + 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; + case "undecided": //2015.08.09. + p.FlairDecided=false; + finalflair=""; + break; + default: + finalflair=""; + break; + } + if(finalflair.length()==0) //<-- 2015.07.20. + return; + p.Flair=finalflair; //2015.08.08. + p.UserName=username; //2015.08.08. + System.out.println("Added new flair to "+playername+": "+finalflair); + for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08. + { + if(player.getName().equals(playername)) + { + AppendPlayerDisplayFlair(player, username, finalflair); + break; + } + } + } + + public static String GetFlair(Player player) + { //2015.07.16. + String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08. + return flair==null ? "" : flair; + } + + //public static void AppendPlayerDisplayFlair(Player player, String username, String flair) + public static void AppendPlayerDisplayFlair(MaybeOfflinePlayer player, Player p) //<-- 2015.08.09. + { + + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).IgnoredFlair) + return; + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).AcceptedFlair) + { + AppendPlayerDisplayFlairFinal(p, player.Flair); //2015.07.20. + if(!player.FlairDecided) + p.sendMessage("§9Your flair type is unknown. Are you a non-presser or a can't press?§r"); //2015.08.09. + } + else + player.sendMessage("§9Are you Reddit user "+username+"?§r §6Type /u accept or /u ignore§r"); + } + + private static void AppendPlayerDisplayFlairFinal(Player player, String flair) + { //2015.07.20. + String color = GetColorForTown(GetPlayerTown(player)); //TO!DO: Multiple colors put on first capital letters + String[] colors = color.substring(1).split("§"); + String displayname=player.getName(); //2015.08.08. + ArrayList Positions=new ArrayList<>(); + for(int i=0; i=colors.length) + { + int x=0; + for(int i=0; i GetPlayers() + { + return Instance.getServer().getOnlinePlayers(); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/c/00f451f0df3e001517108d149b613203 b/.metadata/.plugins/org.eclipse.core.resources/.history/c/00f451f0df3e001517108d149b613203 new file mode 100644 index 0000000..6f03003 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/c/00f451f0df3e001517108d149b613203 @@ -0,0 +1,255 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +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; + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. + //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) + if(p.Flair==null) + { + player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); + return true; + } + switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. + { + case "accept": + { + if(p.IgnoredFlair) + p.IgnoredFlair=false; //2015.08.08. + if(!p.AcceptedFlair) + { + String flair=p.Flair; //2015.08.08. + //PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + PluginMain.AppendPlayerDisplayFlair(p, player); + p.AcceptedFlair=true; //2015.08.08. + player.sendMessage("§6Your flair has been set:§r "+flair); + } + else + player.sendMessage("§cYou already have this user's flair.§r"); + break; + } + case "ignore": + { + if(p.AcceptedFlair) + p.AcceptedFlair=false; //2015.08.08. + if(!p.IgnoredFlair) + { + p.IgnoredFlair=true; + String flair=p.Flair; //2015.08.08. + PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. + player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); + } + else + player.sendMessage("§cYou already ignored this request.§r"); + break; + } + /*case "reload": //2015.07.20. + DoReload(player); + break;*/ + case "admin": //2015.08.09. + DoAdmin(player, args); + break; + case "nonpresser": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§7(non-pr.)§r"; + break; + case "cantpress": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§r(can't press)§r"; + break; + default: + return false; + } + return true; + } + /*if(args[0].toLowerCase()=="reload") + DoReload(null); //2015.07.20.*/ + else if(args.length>0 && args[0].toLowerCase().equals("admin")) //2015.08.09. + { + DoAdmin(null, args); //2015.08.09. + return true; //2015.08.09. + } + return false; + } + private static void DoReload(Player player) + { //2015.07.20. + //if(player==null || player.isOp() || player.getName()=="NorbiPeti") + //{ + try + { + File file=new File("autoflairconfig.txt"); + if(file.exists()) + { + PluginMain.LoadFiles(true); //2015.08.09. + for(Player p : PluginMain.GetPlayers()) + { + MaybeOfflinePlayer mp = MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName()); + if(mp.Flair!=null) + { + String flair=mp.Flair; + PluginMain.RemovePlayerDisplayFlairFinal(p, flair); + //PluginMain.AppendPlayerDisplayFlairFinal(p, flair); + PluginMain.AppendPlayerDisplayFlair(mp, p); //2015.08.09. + } + String msg="§6Note: The auto-flair plugin has been reloaded. You might need to wait 10s to have your flair.§r"; //2015.08.09. + p.sendMessage(msg); //2015.08.09. + } + //String msg="§6Reloaded config file.§r"; + //SendMessage(player, msg); //2015.08.09. + } + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + if(player!=null) + player.sendMessage("§cAn error occured. See console for details.§r"); + PluginMain.LastException=e; //2015.08.09. + } + //} + //else + //player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static Player ReloadPlayer; //2015.08.09. + private static void DoAdmin(Player player, String[] args) + { //2015.08.09. + if(player==null || player.isOp() || player.getName()=="NorbiPeti") + { + //System.out.println("Args length: " + args.length); + if(args.length==1) + { + String message="§cUsage: /u admin reload|playerinfo§r"; + SendMessage(player, message); + return; + } + //args[0] is "admin" + switch(args[1].toLowerCase()) + { + case "reload": + ReloadPlayer=player; //2015.08.09. + SendMessage(player, "§6Make sure to save the current settings before you modify and reload them! Type /u admin confirm when done.§r"); + break; + case "playerinfo": + DoPlayerInfo(player, args); + break; + case "getlasterror": + DoGetLastError(player, args); + case "confirm": + if(ReloadPlayer==player) + DoReload(player); //2015.08.09. + else + SendMessage(player, "§cYou need to do /u admin reload first.§r"); + break; + case "save": + PluginMain.SaveFiles(); //2015.08.09. + SendMessage(player, "§6Saved files. Now you can edit them and reload if you want.§r"); + break; + case "setflair": + + break; + default: + String message="§cUsage: /u admin reload|playerinfo|getlasterror|save§r"; + SendMessage(player, message); + return; + } + } + else + player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static void DoPlayerInfo(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "playerinfo" + if(args.length==2) + { + String message="§cUsage: /u admin playerinfo §r"; + SendMessage(player, message); + return; + } + if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2])) + { + String message="§cPlayer not found: "+args[2]+"§r"; + SendMessage(player, message); + return; + } + MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]); + SendMessage(player, "Player name: "+p.PlayerName); + SendMessage(player, "User flair: "+p.Flair); + SendMessage(player, "Username: "+p.UserName); + SendMessage(player, "Flair accepted: "+p.AcceptedFlair); + SendMessage(player, "Flair ignored: "+p.IgnoredFlair); + } + private static void SendMessage(Player player, String message) + { //2015.08.09. + if(player==null) + System.out.println(message); + else + player.sendMessage(message); + } + private static void DoGetLastError(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "getlasterror" + if(PluginMain.LastException!=null) + { + SendMessage(player, "Last error:"); + SendMessage(player, PluginMain.LastException.toString()); + PluginMain.LastException=null; + } + else + SendMessage(player, "There were no exceptions."); + } + private static void DoSetFlair(Player player, Player targetplayer, String flair) + { //2015.08.09. + flair=flair.replace('&', '§'); + MaybeOfflinePlayer.AddPlayerIfNeeded(player.getName()).Flair=flair; + if(!PluginMain.RemoveLineFromFile("customflairs.txt", targetplayer.getName())) + { + SendMessage(player, "§cError removing previous custom flair!§r"); + return; + } + File file=new File("customflairs.txt"); + try { + BufferedWriter bw; + bw = new BufferedWriter(new FileWriter(file, true)); + bw.write(targetplayer.getName()+"\n"); + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + PluginMain.LastException=e; //2015.08.09. + } + SendMessage(player, "§6The flair has been set. Player: "+targetplayer.getName()+" Flair: "+flair+"§r"); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/c/b06ccd99ce3e001518fa86d7ae2a1cf8 b/.metadata/.plugins/org.eclipse.core.resources/.history/c/b06ccd99ce3e001518fa86d7ae2a1cf8 new file mode 100644 index 0000000..4e85b74 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/c/b06ccd99ce3e001518fa86d7ae2a1cf8 @@ -0,0 +1,358 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStream; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLConnection; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + +import org.apache.commons.io.IOUtils; +import org.bukkit.entity.Player; +import org.bukkit.plugin.java.JavaPlugin; +import org.json.JSONArray; +import org.json.JSONObject; + +import tk.sznp.thebuttonautoflair.MaybeOfflinePlayer.FlairClassType; + +import com.palmergames.bukkit.towny.object.Town; +import com.palmergames.bukkit.towny.object.WorldCoord; + +public class PluginMain extends JavaPlugin +{ //Translated to Java: 2015.07.15. + //A user, which flair isn't obtainable: + //https://www.reddit.com/r/thebutton/comments/31c32v/i_pressed_the_button_without_really_thinking/ + private static PluginMain Instance; + // Fired when plugin is first enabled + @Override + public void onEnable() + { + System.out.println("The Button Auto-flair Plugin by NorbiPeti (:P)"); + getServer().getPluginManager().registerEvents(new PlayerListener(), this); + this.getCommand("u").setExecutor(new Commands()); + this.getCommand("u").setUsage(this.getCommand("u").getUsage().replace('&', '§')); + Instance=this; //2015.08.08. + try { + File file=new File("flairsaccepted.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + //System.out.println("Name: " + name); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("flairsignored.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsignored.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("autoflairconfig.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + TownColors.put(s[0], s[1]); + } + br.close(); + } + //throw new IOException("Test"); //2015.08.09. + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + Runnable r=new Runnable(){public void run(){ThreadMethod();}}; + Thread t=new Thread(r); + t.start(); + } + Boolean stop=false; + // Fired when plugin is disabled + @Override + public void onDisable() + { + try + { + FileWriter fw; + fw = new FileWriter("flairsaccepted.txt"); + fw.close(); + fw = new FileWriter("flairsignored.txt"); + fw.close(); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + try { + File file=new File("flairsaccepted.txt"); + BufferedWriter bw=new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.AcceptedFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + file=new File("flairsignored.txt"); + bw = new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.IgnoredFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + stop=true; + } + + public void ThreadMethod() //<-- 2015.07.16. + { + while(!stop) + { + try + { + String body=DownloadString("https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/autoflair_system_comment_your_minecraft_name_and/.json?limit=1000"); + JSONArray json=new JSONArray(body).getJSONObject(1).getJSONObject("data").getJSONArray("children"); + for(Object obj : json) + { + JSONObject item = (JSONObject)obj; + String author=item.getJSONObject("data").getString("author"); + String ign=item.getJSONObject("data").getString("body"); + int start = ign.indexOf("IGN:") + "IGN:".length(); + int end = ign.indexOf(' ', start); + if (end == -1 || end == start) + end=ign.indexOf('\n', start); //2015.07.15. + if (end == -1 || end == start) + ign = ign.substring(start); + else + ign = ign.substring(start, end); + ign = ign.trim(); + if(HasIGFlair(ign)) + continue; + try { + Thread.sleep(10); + } catch(InterruptedException ex) { + Thread.currentThread().interrupt(); + } + String[] flairdata = DownloadString("http://karmadecay.com/thebutton-data.php?users=" + author).replace("\"", "").split(":"); + String flair; + if(flairdata.length > 1) //2015.07.15. + flair = flairdata[1]; + else + flair=""; + if (flair != "-1") + flair = flair + "s"; + else + flair = "non-presser"; + String flairclass; + if(flairdata.length>2) + flairclass = flairdata[2]; + else + flairclass="unknown"; + SetFlair(ign, flair, flairclass, author); + } + Thread.sleep(10000); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + } + + public static Exception LastException; //2015.08.09. + + public String DownloadString(String urlstr) throws MalformedURLException, IOException + { + URL url = new URL(urlstr); + URLConnection con = url.openConnection(); + con.setRequestProperty("User-Agent", "TheButtonAutoFlair"); + InputStream in = con.getInputStream(); + String encoding = con.getContentEncoding(); + encoding = encoding == null ? "UTF-8" : encoding; + String body = IOUtils.toString(in, encoding); + in.close(); + return body; + } + + public static Map TownColors=new HashMap(); //2015.07.20. + public Boolean HasIGFlair(String playername) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + return p.Flair!=null; //2015.08.08. + } + + public void SetFlair(String playername, String text, String flairclass, String username) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + String finalflair; + p.FlairDecided=true; + switch(flairclass) + { + case "press-1": + finalflair="§c("+text+")§r"; + break; + case "press-2": + finalflair="§6("+text+")§r"; + break; + case "press-3": + finalflair="§e("+text+")§r"; + break; + case "press-4": + finalflair="§a("+text+")§r"; + break; + case "press-5": + finalflair="§9("+text+")§r"; + break; + 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; + case "undecided": //2015.08.09. + p.FlairDecided=false; + finalflair=""; + break; + default: + finalflair=""; + break; + } + if(finalflair.length()==0) //<-- 2015.07.20. + return; + p.Flair=finalflair; //2015.08.08. + p.UserName=username; //2015.08.08. + System.out.println("Added new flair to "+playername+": "+finalflair); + for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08. + { + if(player.getName().equals(playername)) + { + AppendPlayerDisplayFlair(player, username, finalflair); + break; + } + } + } + + public static String GetFlair(Player player) + { //2015.07.16. + String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08. + return flair==null ? "" : flair; + } + + public static void AppendPlayerDisplayFlair(Player player, String username, String flair) + { + if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).IgnoredFlair) + return; + if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).AcceptedFlair) + AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + else + player.sendMessage("§9Are you Reddit user "+username+"?§r §6Type /u accept or /u ignore§r"); + } + + public static void AppendPlayerDisplayFlairFinal(Player player, String flair) + { //2015.07.20. + String color = GetColorForTown(GetPlayerTown(player)); //TO!DO: Multiple colors put on first capital letters + String[] colors = color.substring(1).split("§"); + String displayname=player.getName(); //2015.08.08. + ArrayList Positions=new ArrayList<>(); + for(int i=0; i=colors.length) + { + int x=0; + for(int i=0; i GetPlayers() + { + return Instance.getServer().getOnlinePlayers(); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/c0/804c83d7e43e001517108d149b613203 b/.metadata/.plugins/org.eclipse.core.resources/.history/c0/804c83d7e43e001517108d149b613203 new file mode 100644 index 0000000..45eac34 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/c0/804c83d7e43e001517108d149b613203 @@ -0,0 +1,422 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStream; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLConnection; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + +import org.apache.commons.io.IOUtils; +import org.bukkit.entity.Player; +import org.bukkit.plugin.java.JavaPlugin; +import org.json.JSONArray; +import org.json.JSONObject; + +import com.palmergames.bukkit.towny.object.Town; +import com.palmergames.bukkit.towny.object.WorldCoord; + +public class PluginMain extends JavaPlugin +{ //Translated to Java: 2015.07.15. + //A user, which flair isn't obtainable: + //https://www.reddit.com/r/thebutton/comments/31c32v/i_pressed_the_button_without_really_thinking/ + private static PluginMain Instance; + // Fired when plugin is first enabled + @Override + public void onEnable() + { + System.out.println("The Button Auto-flair Plugin by NorbiPeti (:P)"); + getServer().getPluginManager().registerEvents(new PlayerListener(), this); + this.getCommand("u").setExecutor(new Commands()); + this.getCommand("u").setUsage(this.getCommand("u").getUsage().replace('&', '§')); + Instance=this; //2015.08.08. + LoadFiles(false); //2015.08.09. + Runnable r=new Runnable(){public void run(){ThreadMethod();}}; + Thread t=new Thread(r); + t.start(); + } + Boolean stop=false; + // Fired when plugin is disabled + @Override + public void onDisable() + { + SaveFiles(); //2015.08.09. + stop=true; + } + + public void ThreadMethod() //<-- 2015.07.16. + { + while(!stop) + { + try + { + String body=DownloadString("https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/autoflair_system_comment_your_minecraft_name_and/.json?limit=1000"); + JSONArray json=new JSONArray(body).getJSONObject(1).getJSONObject("data").getJSONArray("children"); + for(Object obj : json) + { + JSONObject item = (JSONObject)obj; + String author=item.getJSONObject("data").getString("author"); + String ign=item.getJSONObject("data").getString("body"); + int start = ign.indexOf("IGN:") + "IGN:".length(); + if(start==-1) + continue; //2015.08.09. + int end = ign.indexOf(' ', start); + if (end == -1 || end == start) + end=ign.indexOf('\n', start); //2015.07.15. + if (end == -1 || end == start) + ign = ign.substring(start); + else + ign = ign.substring(start, end); + ign = ign.trim(); + if(HasIGFlair(ign)) + continue; + try { + Thread.sleep(10); + } catch(InterruptedException ex) { + Thread.currentThread().interrupt(); + } + String[] flairdata = DownloadString("http://karmadecay.com/thebutton-data.php?users=" + author).replace("\"", "").split(":"); + String flair; + if(flairdata.length > 1) //2015.07.15. + flair = flairdata[1]; + else + flair=""; + if (flair != "-1") + flair = flair + "s"; + else + flair = "non-presser"; + String flairclass; + if(flairdata.length>2) + flairclass = flairdata[2]; + else + flairclass="unknown"; + SetFlair(ign, flair, flairclass, author); + } + Thread.sleep(10000); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + } + + public static Exception LastException; //2015.08.09. + + public String DownloadString(String urlstr) throws MalformedURLException, IOException + { + URL url = new URL(urlstr); + URLConnection con = url.openConnection(); + con.setRequestProperty("User-Agent", "TheButtonAutoFlair"); + InputStream in = con.getInputStream(); + String encoding = con.getContentEncoding(); + encoding = encoding == null ? "UTF-8" : encoding; + String body = IOUtils.toString(in, encoding); + in.close(); + return body; + } + + public static Map TownColors=new HashMap(); //2015.07.20. + public Boolean HasIGFlair(String playername) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + return p.Flair!=null; //2015.08.08. + } + + public void SetFlair(String playername, String text, String flairclass, String username) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + String finalflair; + p.FlairDecided=true; + switch(flairclass) + { + case "press-1": + finalflair="§c("+text+")§r"; + break; + case "press-2": + finalflair="§6("+text+")§r"; + break; + case "press-3": + finalflair="§e("+text+")§r"; + break; + case "press-4": + finalflair="§a("+text+")§r"; + break; + case "press-5": + finalflair="§9("+text+")§r"; + break; + 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; + case "undecided": //2015.08.09. + p.FlairDecided=false; + finalflair=""; + break; + default: + finalflair=""; + break; + } + if(finalflair.length()==0) //<-- 2015.07.20. + return; + p.Flair=finalflair; //2015.08.08. + p.UserName=username; //2015.08.08. + System.out.println("Added new flair to "+playername+": "+finalflair); + for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08. + { + if(player.getName().equals(playername)) + { + //AppendPlayerDisplayFlair(player, username, finalflair); + AppendPlayerDisplayFlair(p, player); + break; + } + } + } + + public static String GetFlair(Player player) + { //2015.07.16. + String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08. + return flair==null ? "" : flair; + } + + //public static void AppendPlayerDisplayFlair(Player player, String username, String flair) + public static void AppendPlayerDisplayFlair(MaybeOfflinePlayer player, Player p) //<-- 2015.08.09. + { + + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).IgnoredFlair) + return; + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).AcceptedFlair) + { + AppendPlayerDisplayFlairFinal(p, player.Flair); //2015.07.20. + if(!player.FlairDecided) + p.sendMessage("§9Your flair type is unknown. Are you a non-presser or a can't press? (/u nonpresser or /u cantpress)§r"); //2015.08.09. + } + else + p.sendMessage("§9Are you Reddit user "+player.UserName+"?§r §6Type /u accept or /u ignore§r"); + } + + private static void AppendPlayerDisplayFlairFinal(Player player, String flair) + { //2015.07.20. + String color = GetColorForTown(GetPlayerTown(player)); //TO!DO: Multiple colors put on first capital letters + String[] colors = color.substring(1).split("§"); + String displayname=player.getName(); //2015.08.08. + ArrayList Positions=new ArrayList<>(); + for(int i=0; i=colors.length) + { + int x=0; + for(int i=0; i GetPlayers() + { + return Instance.getServer().getOnlinePlayers(); + } + + public static void LoadFiles(boolean reload) //<-- 2015.08.09. + { + if(reload) + { //2015.08.09. + System.out.println("Auto-flair plugin cleanup for reloading..."); + MaybeOfflinePlayer.AllPlayers.clear(); + TownColors.clear(); + } + System.out.println("Loading files for auto-flair plugin..."); //2015.08.09. + try { + File file=new File("flairsaccepted.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + //System.out.println("Name: " + name); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("flairsignored.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsignored.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("autoflairconfig.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + TownColors.put(s[0], s[1]); + } + br.close(); + } + file=new File("customflairs.txt"); //2015.08.09. + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + MaybeOfflinePlayer.AddPlayerIfNeeded(s[0]).Flair=s[1]; //2015.08.09. + } + br.close(); + } + //throw new IOException("Test"); //2015.08.09. + System.out.println("Auto-flair plugin loaded files!"); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + public static void SaveFiles() //<-- 2015.08.09. + { + try + { + FileWriter fw; + fw = new FileWriter("flairsaccepted.txt"); + fw.close(); + fw = new FileWriter("flairsignored.txt"); + fw.close(); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + try { + File file=new File("flairsaccepted.txt"); + BufferedWriter bw=new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.AcceptedFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + file=new File("flairsignored.txt"); + bw = new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.IgnoredFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + public static boolean RemoveLineFromFile(String file, String line) + { //2015.08.09. + File inputFile = new File(file); + File tempFile = new File("_temp.txt"); + + try { + BufferedReader reader = new BufferedReader(new FileReader(inputFile)); + BufferedWriter writer = new BufferedWriter(new FileWriter(tempFile)); + + String lineToRemove = line; + String currentLine; + + while((currentLine = reader.readLine()) != null) { + // trim newline when comparing with lineToRemove + String trimmedLine = currentLine.trim(); + //if(trimmedLine.equals(lineToRemove)) continue; + if(trimmedLine.contains(lineToRemove)) continue; //2015.08.09. + writer.write(currentLine + System.getProperty("line.separator")); + } + writer.close(); + reader.close(); + return tempFile.renameTo(inputFile); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + return false; + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/c2/20d96d9ad33e001518fa86d7ae2a1cf8 b/.metadata/.plugins/org.eclipse.core.resources/.history/c2/20d96d9ad33e001518fa86d7ae2a1cf8 new file mode 100644 index 0000000..843f877 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/c2/20d96d9ad33e001518fa86d7ae2a1cf8 @@ -0,0 +1,216 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; + +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class Commands implements CommandExecutor { + // This method is called, when somebody uses our command + @Override + public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { + if (sender instanceof Player) { + Player player = (Player) sender; + if(args.length<1) + return false; + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. + //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) + if(p.Flair==null) + { + player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); + return true; + } + switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. + { + case "accept": + { + if(p.IgnoredFlair) + p.IgnoredFlair=false; //2015.08.08. + if(!p.AcceptedFlair) + { + String flair=p.Flair; //2015.08.08. + //PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + PluginMain.AppendPlayerDisplayFlair(p, player); + p.AcceptedFlair=true; //2015.08.08. + player.sendMessage("§6Your flair has been set:§r "+flair); + } + else + player.sendMessage("§cYou already have this user's flair.§r"); + break; + } + case "ignore": + { + if(p.AcceptedFlair) + p.AcceptedFlair=false; //2015.08.08. + if(!p.IgnoredFlair) + { + p.IgnoredFlair=true; + String flair=p.Flair; //2015.08.08. + PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. + player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); + } + else + player.sendMessage("§cYou already ignored this request.§r"); + break; + } + /*case "reload": //2015.07.20. + DoReload(player); + break;*/ + case "admin": //2015.08.09. + DoAdmin(player, args); + break; + case "nonpresser": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§7(non-pr.)§r"; + break; + case "cantpress": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§r(can't press)§r"; + break; + default: + return false; + } + return true; + } + /*if(args[0].toLowerCase()=="reload") + DoReload(null); //2015.07.20.*/ + else if(args.length>0 && args[0].toLowerCase().equals("admin")) //2015.08.09. + { + DoAdmin(null, args); //2015.08.09. + return true; //2015.08.09. + } + return false; + } + private static void DoReload(Player player) + { //2015.07.20. + //if(player==null || player.isOp() || player.getName()=="NorbiPeti") + //{ + try + { + File file=new File("autoflairconfig.txt"); + if(file.exists()) + { + PluginMain.LoadFiles(true); //2015.08.09. + for(Player p : PluginMain.GetPlayers()) + { + MaybeOfflinePlayer mp = MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName()); + if(mp.Flair!=null) + { + String flair=mp.Flair; + PluginMain.RemovePlayerDisplayFlairFinal(p, flair); + //PluginMain.AppendPlayerDisplayFlairFinal(p, flair); + PluginMain.AppendPlayerDisplayFlair(mp, p); //2015.08.09. + } + String msg="§6Note: The auto-flair plugin has been reloaded. You might need to wait 10s to have your flair.§r"; //2015.08.09. + p.sendMessage(msg); //2015.08.09. + } + //String msg="§6Reloaded config file.§r"; + //SendMessage(player, msg); //2015.08.09. + } + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + if(player!=null) + player.sendMessage("§cAn error occured. See console for details.§r"); + PluginMain.LastException=e; //2015.08.09. + } + //} + //else + //player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static void DoAdmin(Player player, String[] args) + { //2015.08.09. + if(player==null || player.isOp() || player.getName()=="NorbiPeti") + { + //System.out.println("Args length: " + args.length); + if(args.length==1) + { + String message="§cUsage: /u admin reload|playerinfo§r"; + SendMessage(player, message); + return; + } + //args[0] is "admin" + switch(args[1].toLowerCase()) + { + case "reload": + DoReload(player); + break; + case "playerinfo": + DoPlayerInfo(player, args); + break; + case "getlasterror": + DoGetLastError(player, args); + default: + String message="§cUsage: /u admin reload|playerinfo§r"; + SendMessage(player, message); + return; + } + } + else + player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static void DoPlayerInfo(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "playerinfo" + if(args.length==2) + { + String message="§cUsage: /u admin playerinfo §r"; + SendMessage(player, message); + return; + } + if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2])) + { + String message="§cPlayer not found: "+args[2]+"§r"; + SendMessage(player, message); + return; + } + MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]); + SendMessage(player, "Player name: "+p.PlayerName); + SendMessage(player, "User flair: "+p.Flair); + SendMessage(player, "Username: "+p.UserName); + SendMessage(player, "Flair accepted: "+p.AcceptedFlair); + SendMessage(player, "Flair ignored: "+p.IgnoredFlair); + } + private static void SendMessage(Player player, String message) + { //2015.08.09. + if(player==null) + System.out.println(message); + else + player.sendMessage(message); + } + private static void DoGetLastError(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "getlasterror" + if(PluginMain.LastException!=null) + { + SendMessage(player, "Last error:"); + SendMessage(player, PluginMain.LastException.toString()); + PluginMain.LastException=null; + } + else + SendMessage(player, "There were no exceptions."); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/c2/30656a8fdc3e001517108d149b613203 b/.metadata/.plugins/org.eclipse.core.resources/.history/c2/30656a8fdc3e001517108d149b613203 new file mode 100644 index 0000000..ee5ce1b --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/c2/30656a8fdc3e001517108d149b613203 @@ -0,0 +1,394 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStream; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLConnection; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + +import org.apache.commons.io.IOUtils; +import org.bukkit.entity.Player; +import org.bukkit.plugin.java.JavaPlugin; +import org.json.JSONArray; +import org.json.JSONObject; + +import com.palmergames.bukkit.towny.object.Town; +import com.palmergames.bukkit.towny.object.WorldCoord; + +public class PluginMain extends JavaPlugin +{ //Translated to Java: 2015.07.15. + //A user, which flair isn't obtainable: + //https://www.reddit.com/r/thebutton/comments/31c32v/i_pressed_the_button_without_really_thinking/ + private static PluginMain Instance; + // Fired when plugin is first enabled + @Override + public void onEnable() + { + System.out.println("The Button Auto-flair Plugin by NorbiPeti (:P)"); + getServer().getPluginManager().registerEvents(new PlayerListener(), this); + this.getCommand("u").setExecutor(new Commands()); + this.getCommand("u").setUsage(this.getCommand("u").getUsage().replace('&', '§')); + Instance=this; //2015.08.08. + LoadFiles(false); //2015.08.09. + Runnable r=new Runnable(){public void run(){ThreadMethod();}}; + Thread t=new Thread(r); + t.start(); + } + Boolean stop=false; + // Fired when plugin is disabled + @Override + public void onDisable() + { + SaveFiles(); //2015.08.09. + stop=true; + } + + public void ThreadMethod() //<-- 2015.07.16. + { + while(!stop) + { + try + { + String body=DownloadString("https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/autoflair_system_comment_your_minecraft_name_and/.json?limit=1000"); + JSONArray json=new JSONArray(body).getJSONObject(1).getJSONObject("data").getJSONArray("children"); + for(Object obj : json) + { + JSONObject item = (JSONObject)obj; + String author=item.getJSONObject("data").getString("author"); + String ign=item.getJSONObject("data").getString("body"); + int start = ign.indexOf("IGN:") + "IGN:".length(); + if(start==-1) + continue; //2015.08.09. + int end = ign.indexOf(' ', start); + if (end == -1 || end == start) + end=ign.indexOf('\n', start); //2015.07.15. + if (end == -1 || end == start) + ign = ign.substring(start); + else + ign = ign.substring(start, end); + ign = ign.trim(); + if(HasIGFlair(ign)) + continue; + try { + Thread.sleep(10); + } catch(InterruptedException ex) { + Thread.currentThread().interrupt(); + } + String[] flairdata = DownloadString("http://karmadecay.com/thebutton-data.php?users=" + author).replace("\"", "").split(":"); + String flair; + if(flairdata.length > 1) //2015.07.15. + flair = flairdata[1]; + else + flair=""; + if (flair != "-1") + flair = flair + "s"; + else + flair = "non-presser"; + String flairclass; + if(flairdata.length>2) + flairclass = flairdata[2]; + else + flairclass="unknown"; + SetFlair(ign, flair, flairclass, author); + } + Thread.sleep(10000); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + } + + public static Exception LastException; //2015.08.09. + + public String DownloadString(String urlstr) throws MalformedURLException, IOException + { + URL url = new URL(urlstr); + URLConnection con = url.openConnection(); + con.setRequestProperty("User-Agent", "TheButtonAutoFlair"); + InputStream in = con.getInputStream(); + String encoding = con.getContentEncoding(); + encoding = encoding == null ? "UTF-8" : encoding; + String body = IOUtils.toString(in, encoding); + in.close(); + return body; + } + + public static Map TownColors=new HashMap(); //2015.07.20. + public Boolean HasIGFlair(String playername) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + return p.Flair!=null; //2015.08.08. + } + + public void SetFlair(String playername, String text, String flairclass, String username) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + String finalflair; + p.FlairDecided=true; + switch(flairclass) + { + case "press-1": + finalflair="§c("+text+")§r"; + break; + case "press-2": + finalflair="§6("+text+")§r"; + break; + case "press-3": + finalflair="§e("+text+")§r"; + break; + case "press-4": + finalflair="§a("+text+")§r"; + break; + case "press-5": + finalflair="§9("+text+")§r"; + break; + 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; + case "undecided": //2015.08.09. + p.FlairDecided=false; + finalflair=""; + break; + default: + finalflair=""; + break; + } + if(finalflair.length()==0) //<-- 2015.07.20. + return; + p.Flair=finalflair; //2015.08.08. + p.UserName=username; //2015.08.08. + System.out.println("Added new flair to "+playername+": "+finalflair); + for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08. + { + if(player.getName().equals(playername)) + { + //AppendPlayerDisplayFlair(player, username, finalflair); + AppendPlayerDisplayFlair(p, player); + break; + } + } + } + + public static String GetFlair(Player player) + { //2015.07.16. + String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08. + return flair==null ? "" : flair; + } + + //public static void AppendPlayerDisplayFlair(Player player, String username, String flair) + public static void AppendPlayerDisplayFlair(MaybeOfflinePlayer player, Player p) //<-- 2015.08.09. + { + + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).IgnoredFlair) + return; + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).AcceptedFlair) + { + AppendPlayerDisplayFlairFinal(p, player.Flair); //2015.07.20. + if(!player.FlairDecided) + p.sendMessage("§9Your flair type is unknown. Are you a non-presser or a can't press? (/u nonpresser or /u cantpress)§r"); //2015.08.09. + } + else + p.sendMessage("§9Are you Reddit user "+player.UserName+"?§r §6Type /u accept or /u ignore§r"); + } + + private static void AppendPlayerDisplayFlairFinal(Player player, String flair) + { //2015.07.20. + String color = GetColorForTown(GetPlayerTown(player)); //TO!DO: Multiple colors put on first capital letters + String[] colors = color.substring(1).split("§"); + String displayname=player.getName(); //2015.08.08. + ArrayList Positions=new ArrayList<>(); + for(int i=0; i=colors.length) + { + int x=0; + for(int i=0; i GetPlayers() + { + return Instance.getServer().getOnlinePlayers(); + } + + public static void LoadFiles(boolean reload) //<-- 2015.08.09. + { + if(reload) + { //2015.08.09. + System.out.println("Auto-flair plugin cleanup for reloading..."); + MaybeOfflinePlayer.AllPlayers.clear(); + TownColors.clear(); + } + System.out.println("Loading files for auto-flair plugin..."); //2015.08.09. + try { + File file=new File("flairsaccepted.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + //System.out.println("Name: " + name); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("flairsignored.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsignored.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("autoflairconfig.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + TownColors.put(s[0], s[1]); + } + br.close(); + } + file=new File("autoflairdecisions.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + + } + br.close(); + } + //throw new IOException("Test"); //2015.08.09. + System.out.println("Auto-flair plugin loaded files!"); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + public static void SaveFiles() //<-- 2015.08.09. + { + try + { + FileWriter fw; + fw = new FileWriter("flairsaccepted.txt"); + fw.close(); + fw = new FileWriter("flairsignored.txt"); + fw.close(); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + try { + File file=new File("flairsaccepted.txt"); + BufferedWriter bw=new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.AcceptedFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + file=new File("flairsignored.txt"); + bw = new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.IgnoredFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/c3/103cea7ede3e001517108d149b613203 b/.metadata/.plugins/org.eclipse.core.resources/.history/c3/103cea7ede3e001517108d149b613203 new file mode 100644 index 0000000..e1f9c1a --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/c3/103cea7ede3e001517108d149b613203 @@ -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)"); + getServer().getPluginManager().registerEvents(new PlayerListener(), this); + this.getCommand("u").setExecutor(new Commands()); + this.getCommand("u").setUsage(this.getCommand("u").getUsage().replace('&', '§')); + Instance=this; //2015.08.08. + LoadFiles(false); //2015.08.09. + Runnable r=new Runnable(){public void run(){ThreadMethod();}}; + Thread t=new Thread(r); + t.start(); + } + Boolean stop=false; + // Fired when plugin is disabled + @Override + public void onDisable() + { + SaveFiles(); //2015.08.09. + stop=true; + } + + public void ThreadMethod() //<-- 2015.07.16. + { + while(!stop) + { + try + { + String body=DownloadString("https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/autoflair_system_comment_your_minecraft_name_and/.json?limit=1000"); + JSONArray json=new JSONArray(body).getJSONObject(1).getJSONObject("data").getJSONArray("children"); + for(Object obj : json) + { + JSONObject item = (JSONObject)obj; + String author=item.getJSONObject("data").getString("author"); + String ign=item.getJSONObject("data").getString("body"); + int start = ign.indexOf("IGN:") + "IGN:".length(); + if(start==-1) + continue; //2015.08.09. + int end = ign.indexOf(' ', start); + if (end == -1 || end == start) + end=ign.indexOf('\n', start); //2015.07.15. + if (end == -1 || end == start) + ign = ign.substring(start); + else + ign = ign.substring(start, end); + ign = ign.trim(); + if(HasIGFlair(ign)) + continue; + try { + Thread.sleep(10); + } catch(InterruptedException ex) { + Thread.currentThread().interrupt(); + } + String[] flairdata = DownloadString("http://karmadecay.com/thebutton-data.php?users=" + author).replace("\"", "").split(":"); + String flair; + if(flairdata.length > 1) //2015.07.15. + flair = flairdata[1]; + else + flair=""; + if (flair != "-1") + flair = flair + "s"; + else + flair = "non-presser"; + String flairclass; + if(flairdata.length>2) + flairclass = flairdata[2]; + else + flairclass="unknown"; + SetFlair(ign, flair, flairclass, author); + } + Thread.sleep(10000); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + } + + public static Exception LastException; //2015.08.09. + + public String DownloadString(String urlstr) throws MalformedURLException, IOException + { + URL url = new URL(urlstr); + URLConnection con = url.openConnection(); + con.setRequestProperty("User-Agent", "TheButtonAutoFlair"); + InputStream in = con.getInputStream(); + String encoding = con.getContentEncoding(); + encoding = encoding == null ? "UTF-8" : encoding; + String body = IOUtils.toString(in, encoding); + in.close(); + return body; + } + + public static Map TownColors=new HashMap(); //2015.07.20. + public Boolean HasIGFlair(String playername) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + return p.Flair!=null; //2015.08.08. + } + + public void SetFlair(String playername, String text, String flairclass, String username) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + String finalflair; + p.FlairDecided=true; + switch(flairclass) + { + case "press-1": + finalflair="§c("+text+")§r"; + break; + case "press-2": + finalflair="§6("+text+")§r"; + break; + case "press-3": + finalflair="§e("+text+")§r"; + break; + case "press-4": + finalflair="§a("+text+")§r"; + break; + case "press-5": + finalflair="§9("+text+")§r"; + break; + 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; + case "undecided": //2015.08.09. + p.FlairDecided=false; + finalflair=""; + break; + default: + finalflair=""; + break; + } + if(finalflair.length()==0) //<-- 2015.07.20. + return; + p.Flair=finalflair; //2015.08.08. + p.UserName=username; //2015.08.08. + System.out.println("Added new flair to "+playername+": "+finalflair); + for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08. + { + if(player.getName().equals(playername)) + { + //AppendPlayerDisplayFlair(player, username, finalflair); + AppendPlayerDisplayFlair(p, player); + break; + } + } + } + + public static String GetFlair(Player player) + { //2015.07.16. + String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08. + return flair==null ? "" : flair; + } + + //public static void AppendPlayerDisplayFlair(Player player, String username, String flair) + public static void AppendPlayerDisplayFlair(MaybeOfflinePlayer player, Player p) //<-- 2015.08.09. + { + + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).IgnoredFlair) + return; + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).AcceptedFlair) + { + AppendPlayerDisplayFlairFinal(p, player.Flair); //2015.07.20. + if(!player.FlairDecided) + p.sendMessage("§9Your flair type is unknown. Are you a non-presser or a can't press? (/u nonpresser or /u cantpress)§r"); //2015.08.09. + } + else + p.sendMessage("§9Are you Reddit user "+player.UserName+"?§r §6Type /u accept or /u ignore§r"); + } + + private static void AppendPlayerDisplayFlairFinal(Player player, String flair) + { //2015.07.20. + String color = GetColorForTown(GetPlayerTown(player)); //TO!DO: Multiple colors put on first capital letters + String[] colors = color.substring(1).split("§"); + String displayname=player.getName(); //2015.08.08. + ArrayList Positions=new ArrayList<>(); + for(int i=0; i=colors.length) + { + int x=0; + for(int i=0; i GetPlayers() + { + return Instance.getServer().getOnlinePlayers(); + } + + public static void LoadFiles(boolean reload) //<-- 2015.08.09. + { + if(reload) + { //2015.08.09. + System.out.println("Auto-flair plugin cleanup for reloading..."); + MaybeOfflinePlayer.AllPlayers.clear(); + TownColors.clear(); + } + System.out.println("Loading files for auto-flair plugin..."); //2015.08.09. + try { + File file=new File("flairsaccepted.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + //System.out.println("Name: " + name); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("flairsignored.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsignored.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("autoflairconfig.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + TownColors.put(s[0], s[1]); + } + br.close(); + } + file=new File("customflairs.txt"); //2015.08.09. + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + MaybeOfflinePlayer.AddPlayerIfNeeded(s[0]).Flair=s[1]; //2015.08.09. + } + br.close(); + } + //throw new IOException("Test"); //2015.08.09. + System.out.println("Auto-flair plugin loaded files!"); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + public static void SaveFiles() //<-- 2015.08.09. + { + try + { + FileWriter fw; + fw = new FileWriter("flairsaccepted.txt"); + fw.close(); + fw = new FileWriter("flairsignored.txt"); + fw.close(); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + try { + File file=new File("flairsaccepted.txt"); + BufferedWriter bw=new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.AcceptedFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + file=new File("flairsignored.txt"); + bw = new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.IgnoredFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + public static void SetPlayerFlair(Player player, String flair) + { //2015.08.09. + flair=flair.replace('&', '§'); + MaybeOfflinePlayer.AddPlayerIfNeeded(player.getName()).Flair=flair; + File file=new File("customflairs.txt"); + BufferedWriter bw; + try { + bw = new BufferedWriter(new FileWriter(file, true)); + bw.write(player.getName()+"\n"); + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + public static void RemoveLineFromFile(String file) + { + File inputFile = new File(file); + File tempFile = new File("myTempFile.txt"); + + BufferedReader reader = new BufferedReader(new FileReader(inputFile)); + BufferedWriter writer = new BufferedWriter(new FileWriter(tempFile)); + + String lineToRemove = "bbb"; + String currentLine; + + while((currentLine = reader.readLine()) != null) { + // trim newline when comparing with lineToRemove + String trimmedLine = currentLine.trim(); + if(trimmedLine.equals(lineToRemove)) continue; + writer.write(currentLine + System.getProperty("line.separator")); + } + writer.close(); + reader.close(); + boolean successful = tempFile.renameTo(inputFile); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/c3/50421721013e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/c3/50421721013e00151c31fb33fff4337f deleted file mode 100644 index da1f3aa..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/c3/50421721013e00151c31fb33fff4337f +++ /dev/null @@ -1,123 +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": - { - 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/c4/c0d4e9c9873e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/c4/c0d4e9c9873e00151ce8ff6d4f74dabd deleted file mode 100644 index 007de20..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/c4/c0d4e9c9873e00151ce8ff6d4f74dabd +++ /dev/null @@ -1,148 +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; - MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. - //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - if(p.Flair==null) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. - { - case "accept": - { - if(p.IgnoredFlair) - p.IgnoredFlair=false; //2015.08.08. - if(!p.AcceptedFlair) - { - String flair=p.Flair; //2015.08.08. - PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. - p.AcceptedFlair=true; //2015.08.08. - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("§cYou already have this user's flair.§r"); - break; - } - case "ignore": - { - if(p.AcceptedFlair) - p.AcceptedFlair=false; //2015.08.08. - if(!p.IgnoredFlair) - { - p.IgnoredFlair=true; - String flair=p.Flair; //2015.08.08. - PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. - player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); - } - else - player.sendMessage("§cYou already ignored this request.§r"); - break; - } - /*case "reload": //2015.07.20. - DoReload(player); - break;*/ - case "admin": //2015.08.09. - DoAdmin(player, args); - break; - default: - return false; - } - return true; - } - - /*if(args[0].toLowerCase()=="reload") - DoReload(null); //2015.07.20.*/ - else if(args[0].toLowerCase()=="admin") - DoAdmin(null, args); //2015.08.09. - return false; - } - private static void DoReload(Player player) - { //2015.07.20. - //if(player==null || player.isOp() || player.getName()=="NorbiPeti") - //{ - try - { - File file=new File("autoflairconfig.txt"); - if(file.exists()) - { - PluginMain.TownColors.clear(); - BufferedReader br=new BufferedReader(new FileReader(file)); - String line; - while((line=br.readLine())!=null) - { - String[] s=line.split(" "); - PluginMain.TownColors.put(s[0], s[1]); - } - br.close(); - for(Player p : PluginMain.GetPlayers()) - { - MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName()); - if(mp.Flair!=null) - { - String flair=mp.Flair; - PluginMain.RemovePlayerDisplayFlairFinal(p, flair); - PluginMain.AppendPlayerDisplayFlairFinal(p, flair); - } - } - String msg="§6Reloaded config file.§r"; - if(player!=null) - player.sendMessage(msg); - else - System.out.println(msg); - } - } - catch(Exception e) - { - System.out.println("Error!\n"+e); - if(player!=null) - player.sendMessage("§cAn error occured. See console for details.§r"); - } - //} - //else - //player.sendMessage("§cYou need to be OP to use this command.§r"); - } - private static void DoAdmin(Player player, String[] args) - { - if(player==null || player.isOp() || player.getName()=="NorbiPeti") - { - //args[0] is "admin" - switch(args[1].toLowerCase()) - { - case "reload": - DoReload(player); - break; - case "playerinfo": - DoPlayerInfo(player, args); - break; - } - } - else - player.sendMessage("§cYou need to be OP to use this command.§r"); - } - private static void DoPlayerInfo(Player player, String[] args) - { - //args[0] is "admin" - args[1] is "playerinfo" - if(args.length==args[2]) - { - String message="§cUsage: /u admin playerinfo §r"; - } - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/c5/30315643d03e001518fa86d7ae2a1cf8 b/.metadata/.plugins/org.eclipse.core.resources/.history/c5/30315643d03e001518fa86d7ae2a1cf8 new file mode 100644 index 0000000..a8dea0e --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/c5/30315643d03e001518fa86d7ae2a1cf8 @@ -0,0 +1,198 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; + +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class Commands implements CommandExecutor { + // This method is called, when somebody uses our command + @Override + public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { + if (sender instanceof Player) { + Player player = (Player) sender; + if(args.length<1) + return false; + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. + //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) + if(p.Flair==null) + { + player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); + return true; + } + switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. + { + case "accept": + { + if(p.IgnoredFlair) + p.IgnoredFlair=false; //2015.08.08. + if(!p.AcceptedFlair) + { + String flair=p.Flair; //2015.08.08. + //PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + PluginMain.AppendPlayerDisplayFlair(p, player); + p.AcceptedFlair=true; //2015.08.08. + player.sendMessage("§6Your flair has been set:§r "+flair); + } + else + player.sendMessage("§cYou already have this user's flair.§r"); + break; + } + case "ignore": + { + if(p.AcceptedFlair) + p.AcceptedFlair=false; //2015.08.08. + if(!p.IgnoredFlair) + { + p.IgnoredFlair=true; + String flair=p.Flair; //2015.08.08. + PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. + player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); + } + else + player.sendMessage("§cYou already ignored this request.§r"); + break; + } + /*case "reload": //2015.07.20. + DoReload(player); + break;*/ + case "admin": //2015.08.09. + DoAdmin(player, args); + break; + case "nonpresser": //2015.08.09. + break; + default: + return false; + } + return true; + } + /*if(args[0].toLowerCase()=="reload") + DoReload(null); //2015.07.20.*/ + else if(args.length>0 && args[0].toLowerCase().equals("admin")) //2015.08.09. + { + DoAdmin(null, args); //2015.08.09. + return true; //2015.08.09. + } + return false; + } + private static void DoReload(Player player) + { //2015.07.20. + //if(player==null || player.isOp() || player.getName()=="NorbiPeti") + //{ + try + { + File file=new File("autoflairconfig.txt"); + if(file.exists()) + { + PluginMain.TownColors.clear(); + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + PluginMain.TownColors.put(s[0], s[1]); + } + br.close(); + for(Player p : PluginMain.GetPlayers()) + { + MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName()); + if(mp.Flair!=null) + { + String flair=mp.Flair; + PluginMain.RemovePlayerDisplayFlairFinal(p, flair); + //PluginMain.AppendPlayerDisplayFlairFinal(p, flair); + PluginMain.AppendPlayerDisplayFlair(mp, p); //2015.08.09. + } + } + String msg="§6Reloaded config file.§r"; + SendMessage(player, msg); //2015.08.09. + } + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + if(player!=null) + player.sendMessage("§cAn error occured. See console for details.§r"); + PluginMain.LastException=e; //2015.08.09. + } + //} + //else + //player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static void DoAdmin(Player player, String[] args) + { //2015.08.09. + if(player==null || player.isOp() || player.getName()=="NorbiPeti") + { + //System.out.println("Args length: " + args.length); + if(args.length==1) + { + String message="§cUsage: /u admin reload|playerinfo§r"; + SendMessage(player, message); + return; + } + //args[0] is "admin" + switch(args[1].toLowerCase()) + { + case "reload": + DoReload(player); + break; + case "playerinfo": + DoPlayerInfo(player, args); + break; + case "getlasterror": + DoGetLastError(player, args); + default: + String message="§cUsage: /u admin reload|playerinfo§r"; + SendMessage(player, message); + return; + } + } + else + player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static void DoPlayerInfo(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "playerinfo" + if(args.length==2) + { + String message="§cUsage: /u admin playerinfo §r"; + SendMessage(player, message); + return; + } + if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2])) + { + String message="§cPlayer not found: "+args[2]+"§r"; + SendMessage(player, message); + return; + } + MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]); + SendMessage(player, "Player name: "+p.PlayerName); + SendMessage(player, "User flair: "+p.Flair); + SendMessage(player, "Username: "+p.UserName); + SendMessage(player, "Flair accepted: "+p.AcceptedFlair); + SendMessage(player, "Flair ignored: "+p.IgnoredFlair); + } + private static void SendMessage(Player player, String message) + { //2015.08.09. + if(player==null) + System.out.println(message); + else + player.sendMessage(message); + } + private static void DoGetLastError(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "getlasterror" + if(PluginMain.LastException!=null) + { + SendMessage(player, "Last error:"); + SendMessage(player, PluginMain.LastException.toString()); + PluginMain.LastException=null; + } + else + SendMessage(player, "There were no exceptions."); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/c5/9087c2e9de3e001517108d149b613203 b/.metadata/.plugins/org.eclipse.core.resources/.history/c5/9087c2e9de3e001517108d149b613203 new file mode 100644 index 0000000..9ee3630 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/c5/9087c2e9de3e001517108d149b613203 @@ -0,0 +1,440 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStream; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLConnection; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + +import org.apache.commons.io.IOUtils; +import org.bukkit.entity.Player; +import org.bukkit.plugin.java.JavaPlugin; +import org.json.JSONArray; +import org.json.JSONObject; + +import com.palmergames.bukkit.towny.object.Town; +import com.palmergames.bukkit.towny.object.WorldCoord; + +public class PluginMain extends JavaPlugin +{ //Translated to Java: 2015.07.15. + //A user, which flair isn't obtainable: + //https://www.reddit.com/r/thebutton/comments/31c32v/i_pressed_the_button_without_really_thinking/ + private static PluginMain Instance; + // Fired when plugin is first enabled + @Override + public void onEnable() + { + System.out.println("The Button Auto-flair Plugin by NorbiPeti (:P)"); + getServer().getPluginManager().registerEvents(new PlayerListener(), this); + this.getCommand("u").setExecutor(new Commands()); + this.getCommand("u").setUsage(this.getCommand("u").getUsage().replace('&', '§')); + Instance=this; //2015.08.08. + LoadFiles(false); //2015.08.09. + Runnable r=new Runnable(){public void run(){ThreadMethod();}}; + Thread t=new Thread(r); + t.start(); + } + Boolean stop=false; + // Fired when plugin is disabled + @Override + public void onDisable() + { + SaveFiles(); //2015.08.09. + stop=true; + } + + public void ThreadMethod() //<-- 2015.07.16. + { + while(!stop) + { + try + { + String body=DownloadString("https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/autoflair_system_comment_your_minecraft_name_and/.json?limit=1000"); + JSONArray json=new JSONArray(body).getJSONObject(1).getJSONObject("data").getJSONArray("children"); + for(Object obj : json) + { + JSONObject item = (JSONObject)obj; + String author=item.getJSONObject("data").getString("author"); + String ign=item.getJSONObject("data").getString("body"); + int start = ign.indexOf("IGN:") + "IGN:".length(); + if(start==-1) + continue; //2015.08.09. + int end = ign.indexOf(' ', start); + if (end == -1 || end == start) + end=ign.indexOf('\n', start); //2015.07.15. + if (end == -1 || end == start) + ign = ign.substring(start); + else + ign = ign.substring(start, end); + ign = ign.trim(); + if(HasIGFlair(ign)) + continue; + try { + Thread.sleep(10); + } catch(InterruptedException ex) { + Thread.currentThread().interrupt(); + } + String[] flairdata = DownloadString("http://karmadecay.com/thebutton-data.php?users=" + author).replace("\"", "").split(":"); + String flair; + if(flairdata.length > 1) //2015.07.15. + flair = flairdata[1]; + else + flair=""; + if (flair != "-1") + flair = flair + "s"; + else + flair = "non-presser"; + String flairclass; + if(flairdata.length>2) + flairclass = flairdata[2]; + else + flairclass="unknown"; + SetFlair(ign, flair, flairclass, author); + } + Thread.sleep(10000); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + } + + public static Exception LastException; //2015.08.09. + + public String DownloadString(String urlstr) throws MalformedURLException, IOException + { + URL url = new URL(urlstr); + URLConnection con = url.openConnection(); + con.setRequestProperty("User-Agent", "TheButtonAutoFlair"); + InputStream in = con.getInputStream(); + String encoding = con.getContentEncoding(); + encoding = encoding == null ? "UTF-8" : encoding; + String body = IOUtils.toString(in, encoding); + in.close(); + return body; + } + + public static Map TownColors=new HashMap(); //2015.07.20. + public Boolean HasIGFlair(String playername) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + return p.Flair!=null; //2015.08.08. + } + + public void SetFlair(String playername, String text, String flairclass, String username) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + String finalflair; + p.FlairDecided=true; + switch(flairclass) + { + case "press-1": + finalflair="§c("+text+")§r"; + break; + case "press-2": + finalflair="§6("+text+")§r"; + break; + case "press-3": + finalflair="§e("+text+")§r"; + break; + case "press-4": + finalflair="§a("+text+")§r"; + break; + case "press-5": + finalflair="§9("+text+")§r"; + break; + 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; + case "undecided": //2015.08.09. + p.FlairDecided=false; + finalflair=""; + break; + default: + finalflair=""; + break; + } + if(finalflair.length()==0) //<-- 2015.07.20. + return; + p.Flair=finalflair; //2015.08.08. + p.UserName=username; //2015.08.08. + System.out.println("Added new flair to "+playername+": "+finalflair); + for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08. + { + if(player.getName().equals(playername)) + { + //AppendPlayerDisplayFlair(player, username, finalflair); + AppendPlayerDisplayFlair(p, player); + break; + } + } + } + + public static String GetFlair(Player player) + { //2015.07.16. + String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08. + return flair==null ? "" : flair; + } + + //public static void AppendPlayerDisplayFlair(Player player, String username, String flair) + public static void AppendPlayerDisplayFlair(MaybeOfflinePlayer player, Player p) //<-- 2015.08.09. + { + + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).IgnoredFlair) + return; + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).AcceptedFlair) + { + AppendPlayerDisplayFlairFinal(p, player.Flair); //2015.07.20. + if(!player.FlairDecided) + p.sendMessage("§9Your flair type is unknown. Are you a non-presser or a can't press? (/u nonpresser or /u cantpress)§r"); //2015.08.09. + } + else + p.sendMessage("§9Are you Reddit user "+player.UserName+"?§r §6Type /u accept or /u ignore§r"); + } + + private static void AppendPlayerDisplayFlairFinal(Player player, String flair) + { //2015.07.20. + String color = GetColorForTown(GetPlayerTown(player)); //TO!DO: Multiple colors put on first capital letters + String[] colors = color.substring(1).split("§"); + String displayname=player.getName(); //2015.08.08. + ArrayList Positions=new ArrayList<>(); + for(int i=0; i=colors.length) + { + int x=0; + for(int i=0; i GetPlayers() + { + return Instance.getServer().getOnlinePlayers(); + } + + public static void LoadFiles(boolean reload) //<-- 2015.08.09. + { + if(reload) + { //2015.08.09. + System.out.println("Auto-flair plugin cleanup for reloading..."); + MaybeOfflinePlayer.AllPlayers.clear(); + TownColors.clear(); + } + System.out.println("Loading files for auto-flair plugin..."); //2015.08.09. + try { + File file=new File("flairsaccepted.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + //System.out.println("Name: " + name); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("flairsignored.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsignored.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("autoflairconfig.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + TownColors.put(s[0], s[1]); + } + br.close(); + } + file=new File("customflairs.txt"); //2015.08.09. + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + MaybeOfflinePlayer.AddPlayerIfNeeded(s[0]).Flair=s[1]; //2015.08.09. + } + br.close(); + } + //throw new IOException("Test"); //2015.08.09. + System.out.println("Auto-flair plugin loaded files!"); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + public static void SaveFiles() //<-- 2015.08.09. + { + try + { + FileWriter fw; + fw = new FileWriter("flairsaccepted.txt"); + fw.close(); + fw = new FileWriter("flairsignored.txt"); + fw.close(); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + try { + File file=new File("flairsaccepted.txt"); + BufferedWriter bw=new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.AcceptedFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + file=new File("flairsignored.txt"); + bw = new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.IgnoredFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + public static void SetPlayerFlair(Player player, String flair) + { //2015.08.09. + flair=flair.replace('&', '§'); + MaybeOfflinePlayer.AddPlayerIfNeeded(player.getName()).Flair=flair; + if(!RemoveLineFromFile("customflairs.txt")) + { + Commands.SendMessage(player, "") + } + File file=new File("customflairs.txt"); + try { + BufferedWriter bw; + bw = new BufferedWriter(new FileWriter(file, true)); + bw.write(player.getName()+"\n"); + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + public static boolean RemoveLineFromFile(String file) + { + File inputFile = new File(file); + File tempFile = new File("_temp.txt"); + + try { + BufferedReader reader = new BufferedReader(new FileReader(inputFile)); + BufferedWriter writer = new BufferedWriter(new FileWriter(tempFile)); + + String lineToRemove = "bbb"; + String currentLine; + + while((currentLine = reader.readLine()) != null) { + // trim newline when comparing with lineToRemove + String trimmedLine = currentLine.trim(); + if(trimmedLine.equals(lineToRemove)) continue; + writer.write(currentLine + System.getProperty("line.separator")); + } + writer.close(); + reader.close(); + return tempFile.renameTo(inputFile); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + return false; + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/c5/e0bc896e043e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/c5/e0bc896e043e00151c31fb33fff4337f deleted file mode 100644 index 5cd2e80..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/c5/e0bc896e043e00151c31fb33fff4337f +++ /dev/null @@ -1,126 +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; - 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/50d2a147883e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/c6/50d2a147883e00151ce8ff6d4f74dabd deleted file mode 100644 index 9f90e23..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/c6/50d2a147883e00151ce8ff6d4f74dabd +++ /dev/null @@ -1,172 +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; - MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. - //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - if(p.Flair==null) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. - { - case "accept": - { - if(p.IgnoredFlair) - p.IgnoredFlair=false; //2015.08.08. - if(!p.AcceptedFlair) - { - String flair=p.Flair; //2015.08.08. - PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. - p.AcceptedFlair=true; //2015.08.08. - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("§cYou already have this user's flair.§r"); - break; - } - case "ignore": - { - if(p.AcceptedFlair) - p.AcceptedFlair=false; //2015.08.08. - if(!p.IgnoredFlair) - { - p.IgnoredFlair=true; - String flair=p.Flair; //2015.08.08. - PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. - player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); - } - else - player.sendMessage("§cYou already ignored this request.§r"); - break; - } - /*case "reload": //2015.07.20. - DoReload(player); - break;*/ - case "admin": //2015.08.09. - DoAdmin(player, args); - break; - default: - return false; - } - return true; - } - - /*if(args[0].toLowerCase()=="reload") - DoReload(null); //2015.07.20.*/ - else if(args[0].toLowerCase()=="admin") - DoAdmin(null, args); //2015.08.09. - return false; - } - private static void DoReload(Player player) - { //2015.07.20. - //if(player==null || player.isOp() || player.getName()=="NorbiPeti") - //{ - try - { - File file=new File("autoflairconfig.txt"); - if(file.exists()) - { - PluginMain.TownColors.clear(); - BufferedReader br=new BufferedReader(new FileReader(file)); - String line; - while((line=br.readLine())!=null) - { - String[] s=line.split(" "); - PluginMain.TownColors.put(s[0], s[1]); - } - br.close(); - for(Player p : PluginMain.GetPlayers()) - { - MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName()); - if(mp.Flair!=null) - { - String flair=mp.Flair; - PluginMain.RemovePlayerDisplayFlairFinal(p, flair); - PluginMain.AppendPlayerDisplayFlairFinal(p, flair); - } - } - String msg="§6Reloaded config file.§r"; - if(player!=null) - player.sendMessage(msg); - else - System.out.println(msg); - } - } - catch(Exception e) - { - System.out.println("Error!\n"+e); - if(player!=null) - player.sendMessage("§cAn error occured. See console for details.§r"); - } - //} - //else - //player.sendMessage("§cYou need to be OP to use this command.§r"); - } - private static void DoAdmin(Player player, String[] args) - { //2015.08.09. - if(player==null || player.isOp() || player.getName()=="NorbiPeti") - { - if(args.length==1) - { - String message="§cUsage: /u admin reload|playerinfo§r"; - if(player==null) - System.out.println(message); - else - player.sendMessage(message); - return; - } - //args[0] is "admin" - switch(args[1].toLowerCase()) - { - case "reload": - DoReload(player); - break; - case "playerinfo": - DoPlayerInfo(player, args); - break; - } - } - else - player.sendMessage("§cYou need to be OP to use this command.§r"); - } - private static void DoPlayerInfo(Player player, String[] args) - { //2015.08.09. - //args[0] is "admin" - args[1] is "playerinfo" - if(args.length==2) - { - String message="§cUsage: /u admin playerinfo §r"; - if(player==null) - System.out.println(message); - else - player.sendMessage(message); - return; - } - if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2])) - { - String message="§cUsage: /u admin playerinfo §r"; - if(player==null) - System.out.println(message); - else - player.sendMessage(message); - return; - } - MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/c6/c0dc5f8ffe3d00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/c6/c0dc5f8ffe3d00151c31fb33fff4337f deleted file mode 100644 index 02d5705..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/c6/c0dc5f8ffe3d00151c31fb33fff4337f +++ /dev/null @@ -1,122 +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()); - 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 deleted file mode 100644 index 8ca009c..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/c6/d022346e043e00151c31fb33fff4337f +++ /dev/null @@ -1,126 +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; - 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/c7/20873c35da3e001517108d149b613203 b/.metadata/.plugins/org.eclipse.core.resources/.history/c7/20873c35da3e001517108d149b613203 new file mode 100644 index 0000000..e279910 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/c7/20873c35da3e001517108d149b613203 @@ -0,0 +1,380 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStream; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLConnection; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + +import org.apache.commons.io.IOUtils; +import org.bukkit.entity.Player; +import org.bukkit.plugin.java.JavaPlugin; +import org.json.JSONArray; +import org.json.JSONObject; + +import com.palmergames.bukkit.towny.object.Town; +import com.palmergames.bukkit.towny.object.WorldCoord; + +public class PluginMain extends JavaPlugin +{ //Translated to Java: 2015.07.15. + //A user, which flair isn't obtainable: + //https://www.reddit.com/r/thebutton/comments/31c32v/i_pressed_the_button_without_really_thinking/ + private static PluginMain Instance; + // Fired when plugin is first enabled + @Override + public void onEnable() + { + System.out.println("The Button Auto-flair Plugin by NorbiPeti (:P)"); + getServer().getPluginManager().registerEvents(new PlayerListener(), this); + this.getCommand("u").setExecutor(new Commands()); + this.getCommand("u").setUsage(this.getCommand("u").getUsage().replace('&', '§')); + Instance=this; //2015.08.08. + LoadFiles(false); //2015.08.09. + Runnable r=new Runnable(){public void run(){ThreadMethod();}}; + Thread t=new Thread(r); + t.start(); + } + Boolean stop=false; + // Fired when plugin is disabled + @Override + public void onDisable() + { + SaveFiles(); //2015.08.09. + stop=true; + } + + public void ThreadMethod() //<-- 2015.07.16. + { + while(!stop) + { + try + { + String body=DownloadString("https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/autoflair_system_comment_your_minecraft_name_and/.json?limit=1000"); + JSONArray json=new JSONArray(body).getJSONObject(1).getJSONObject("data").getJSONArray("children"); + for(Object obj : json) + { + JSONObject item = (JSONObject)obj; + String author=item.getJSONObject("data").getString("author"); + String ign=item.getJSONObject("data").getString("body"); + int start = ign.indexOf("IGN:") + "IGN:".length(); + int end = ign.indexOf(' ', start); + if (end == -1 || end == start) + end=ign.indexOf('\n', start); //2015.07.15. + if (end == -1 || end == start) + ign = ign.substring(start); + else + ign = ign.substring(start, end); + ign = ign.trim(); + if(HasIGFlair(ign)) + continue; + try { + Thread.sleep(10); + } catch(InterruptedException ex) { + Thread.currentThread().interrupt(); + } + String[] flairdata = DownloadString("http://karmadecay.com/thebutton-data.php?users=" + author).replace("\"", "").split(":"); + String flair; + if(flairdata.length > 1) //2015.07.15. + flair = flairdata[1]; + else + flair=""; + if (flair != "-1") + flair = flair + "s"; + else + flair = "non-presser"; + String flairclass; + if(flairdata.length>2) + flairclass = flairdata[2]; + else + flairclass="unknown"; + SetFlair(ign, flair, flairclass, author); + } + Thread.sleep(10000); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + } + + public static Exception LastException; //2015.08.09. + + public String DownloadString(String urlstr) throws MalformedURLException, IOException + { + URL url = new URL(urlstr); + URLConnection con = url.openConnection(); + con.setRequestProperty("User-Agent", "TheButtonAutoFlair"); + InputStream in = con.getInputStream(); + String encoding = con.getContentEncoding(); + encoding = encoding == null ? "UTF-8" : encoding; + String body = IOUtils.toString(in, encoding); + in.close(); + return body; + } + + public static Map TownColors=new HashMap(); //2015.07.20. + public Boolean HasIGFlair(String playername) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + return p.Flair!=null; //2015.08.08. + } + + public void SetFlair(String playername, String text, String flairclass, String username) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + String finalflair; + p.FlairDecided=true; + switch(flairclass) + { + case "press-1": + finalflair="§c("+text+")§r"; + break; + case "press-2": + finalflair="§6("+text+")§r"; + break; + case "press-3": + finalflair="§e("+text+")§r"; + break; + case "press-4": + finalflair="§a("+text+")§r"; + break; + case "press-5": + finalflair="§9("+text+")§r"; + break; + 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; + case "undecided": //2015.08.09. + p.FlairDecided=false; + finalflair=""; + break; + default: + finalflair=""; + break; + } + if(finalflair.length()==0) //<-- 2015.07.20. + return; + p.Flair=finalflair; //2015.08.08. + p.UserName=username; //2015.08.08. + System.out.println("Added new flair to "+playername+": "+finalflair); + for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08. + { + if(player.getName().equals(playername)) + { + //AppendPlayerDisplayFlair(player, username, finalflair); + AppendPlayerDisplayFlair(p, player); + break; + } + } + } + + public static String GetFlair(Player player) + { //2015.07.16. + String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08. + return flair==null ? "" : flair; + } + + //public static void AppendPlayerDisplayFlair(Player player, String username, String flair) + public static void AppendPlayerDisplayFlair(MaybeOfflinePlayer player, Player p) //<-- 2015.08.09. + { + + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).IgnoredFlair) + return; + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).AcceptedFlair) + { + AppendPlayerDisplayFlairFinal(p, player.Flair); //2015.07.20. + if(!player.FlairDecided) + p.sendMessage("§9Your flair type is unknown. Are you a non-presser or a can't press? (/u nonpresser or /u cantpress)§r"); //2015.08.09. + } + else + p.sendMessage("§9Are you Reddit user "+player.UserName+"?§r §6Type /u accept or /u ignore§r"); + } + + private static void AppendPlayerDisplayFlairFinal(Player player, String flair) + { //2015.07.20. + String color = GetColorForTown(GetPlayerTown(player)); //TO!DO: Multiple colors put on first capital letters + String[] colors = color.substring(1).split("§"); + String displayname=player.getName(); //2015.08.08. + ArrayList Positions=new ArrayList<>(); + for(int i=0; i=colors.length) + { + int x=0; + for(int i=0; i GetPlayers() + { + return Instance.getServer().getOnlinePlayers(); + } + + public static void LoadFiles(boolean reload) //<-- 2015.08.09. + { + if(reload) + { //2015.08.09. + System.out.println("Auto-flair plugin cleanup for reloading..."); + MaybeOfflinePlayer.AllPlayers.clear(); + TownColors.clear(); + } + System.out.println("Loading files for auto-flair plugin..."); //2015.08.09. + try { + File file=new File("flairsaccepted.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + //System.out.println("Name: " + name); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("flairsignored.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsignored.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("autoflairconfig.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + TownColors.put(s[0], s[1]); + } + br.close(); + } + //throw new IOException("Test"); //2015.08.09. + System.out.println("Auto-flair plugin loaded files!"); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + public static void SaveFiles() //<-- 2015.08.09. + { + try + { + FileWriter fw; + fw = new FileWriter("flairsaccepted.txt"); + fw.close(); + fw = new FileWriter("flairsignored.txt"); + fw.close(); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + try { + File file=new File("flairsaccepted.txt"); + BufferedWriter bw=new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.AcceptedFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + file=new File("flairsignored.txt"); + bw = new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.IgnoredFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/c7/30e525880d3e00151089cca86c5b1a99 b/.metadata/.plugins/org.eclipse.core.resources/.history/c7/30e525880d3e00151089cca86c5b1a99 deleted file mode 100644 index 2c323a3..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/c7/30e525880d3e00151089cca86c5b1a99 +++ /dev/null @@ -1,435 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import java.io.BufferedReader; -import java.io.BufferedWriter; -import java.io.File; -import java.io.FileReader; -import java.io.FileWriter; -import java.io.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/d05586b7fe3d00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/c7/d05586b7fe3d00151c31fb33fff4337f deleted file mode 100644 index 51a39bf..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/c7/d05586b7fe3d00151c31fb33fff4337f +++ /dev/null @@ -1,122 +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()); - 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/e0273ad2843e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/c7/e0273ad2843e00151ce8ff6d4f74dabd deleted file mode 100644 index 8f8c62d..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/c7/e0273ad2843e00151ce8ff6d4f74dabd +++ /dev/null @@ -1,119 +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; - MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. - //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - if(p.Flair==null) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0].toLowerCase()) - { - case "accept": - { - if(p.IgnoredFlair) - p.IgnoredFlair=false; //2015.08.08. - if(!p.AcceptedFlair) - { - String flair=p.Flair; //2015.08.08. - PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. - p.AcceptedFlair=true; //2015.08.08. - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("§cYou already have this user's flair.§r"); - break; - } - case "ignore": - { - if(p.AcceptedFlair) - p.AcceptedFlair=false; //2015.08.08. - if(!p.IgnoredFlair) - { - p.IgnoredFlair=true; - String flair=p.Flair; //2015.08.08. - PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. - player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); - } - else - player.sendMessage("§cYou already ignored this request.§r"); - break; - } - case "reload": //2015.07.20. - DoReload(player); - break; - case "showerrors": //2015.08.09. - break; - default: - return false; - } - return true; - } - - if(args[0]=="reload") - DoReload(null); //2015.07.20. - return false; - } - private static void DoReload(Player player) - { //2015.07.20. - if(player==null || player.isOp() || player.getName()=="NorbiPeti") - { - try - { - File file=new File("autoflairconfig.txt"); - if(file.exists()) - { - PluginMain.TownColors.clear(); - BufferedReader br=new BufferedReader(new FileReader(file)); - String line; - while((line=br.readLine())!=null) - { - String[] s=line.split(" "); - PluginMain.TownColors.put(s[0], s[1]); - } - br.close(); - for(Player p : PluginMain.GetPlayers()) - { - MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName()); - if(mp.Flair!=null) - { - String flair=mp.Flair; - PluginMain.RemovePlayerDisplayFlairFinal(p, flair); - PluginMain.AppendPlayerDisplayFlairFinal(p, flair); - } - } - String msg="§6Reloaded config file.§r"; - if(player!=null) - player.sendMessage(msg); - else - System.out.println(msg); - } - } - catch(Exception e) - { - System.out.println("Error!\n"+e); - if(player!=null) - player.sendMessage("§cAn error occured. See console for details.§r"); - } - } - else - player.sendMessage("§cYou need to be OP to use this command.§r"); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/c7/f00aad3f023e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/c7/f00aad3f023e00151c31fb33fff4337f deleted file mode 100644 index 02b2d98..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/c7/f00aad3f023e00151c31fb33fff4337f +++ /dev/null @@ -1,125 +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; - 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/c8/00d17cf2e43e001517108d149b613203 b/.metadata/.plugins/org.eclipse.core.resources/.history/c8/00d17cf2e43e001517108d149b613203 new file mode 100644 index 0000000..650e18a --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/c8/00d17cf2e43e001517108d149b613203 @@ -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.Collection; +import java.util.HashMap; +import java.util.Map; + +import org.apache.commons.io.IOUtils; +import org.bukkit.entity.Player; +import org.bukkit.plugin.java.JavaPlugin; +import org.json.JSONArray; +import org.json.JSONObject; + +import com.palmergames.bukkit.towny.object.Town; +import com.palmergames.bukkit.towny.object.WorldCoord; + +public class PluginMain extends JavaPlugin +{ //Translated to Java: 2015.07.15. + //A user, which flair isn't obtainable: + //https://www.reddit.com/r/thebutton/comments/31c32v/i_pressed_the_button_without_really_thinking/ + private static PluginMain Instance; + // Fired when plugin is first enabled + @Override + public void onEnable() + { + System.out.println("The Button Auto-flair Plugin by NorbiPeti (:P)"); + getServer().getPluginManager().registerEvents(new PlayerListener(), this); + this.getCommand("u").setExecutor(new Commands()); + this.getCommand("u").setUsage(this.getCommand("u").getUsage().replace('&', '§')); + Instance=this; //2015.08.08. + LoadFiles(false); //2015.08.09. + Runnable r=new Runnable(){public void run(){ThreadMethod();}}; + Thread t=new Thread(r); + t.start(); + } + Boolean stop=false; + // Fired when plugin is disabled + @Override + public void onDisable() + { + SaveFiles(); //2015.08.09. + stop=true; + } + + public void ThreadMethod() //<-- 2015.07.16. + { + while(!stop) + { + try + { + String body=DownloadString("https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/autoflair_system_comment_your_minecraft_name_and/.json?limit=1000"); + JSONArray json=new JSONArray(body).getJSONObject(1).getJSONObject("data").getJSONArray("children"); + for(Object obj : json) + { + JSONObject item = (JSONObject)obj; + String author=item.getJSONObject("data").getString("author"); + String ign=item.getJSONObject("data").getString("body"); + int start = ign.indexOf("IGN:") + "IGN:".length(); + if(start==-1) + continue; //2015.08.09. + int end = ign.indexOf(' ', start); + if (end == -1 || end == start) + end=ign.indexOf('\n', start); //2015.07.15. + if (end == -1 || end == start) + ign = ign.substring(start); + else + ign = ign.substring(start, end); + ign = ign.trim(); + if(HasIGFlair(ign)) + continue; + try { + Thread.sleep(10); + } catch(InterruptedException ex) { + Thread.currentThread().interrupt(); + } + String[] flairdata = DownloadString("http://karmadecay.com/thebutton-data.php?users=" + author).replace("\"", "").split(":"); + String flair; + if(flairdata.length > 1) //2015.07.15. + flair = flairdata[1]; + else + flair=""; + if (flair != "-1") + flair = flair + "s"; + else + flair = "non-presser"; + String flairclass; + if(flairdata.length>2) + flairclass = flairdata[2]; + else + flairclass="unknown"; + SetFlair(ign, flair, flairclass, author); + } + Thread.sleep(10000); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + } + + public static Exception LastException; //2015.08.09. + + public String DownloadString(String urlstr) throws MalformedURLException, IOException + { + URL url = new URL(urlstr); + URLConnection con = url.openConnection(); + con.setRequestProperty("User-Agent", "TheButtonAutoFlair"); + InputStream in = con.getInputStream(); + String encoding = con.getContentEncoding(); + encoding = encoding == null ? "UTF-8" : encoding; + String body = IOUtils.toString(in, encoding); + in.close(); + return body; + } + + public static Map TownColors=new HashMap(); //2015.07.20. + public Boolean HasIGFlair(String playername) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + return p.Flair!=null; //2015.08.08. + } + + public void SetFlair(String playername, String text, String flairclass, String username) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + String finalflair; + p.FlairDecided=true; + switch(flairclass) + { + case "press-1": + finalflair="§c("+text+")§r"; + break; + case "press-2": + finalflair="§6("+text+")§r"; + break; + case "press-3": + finalflair="§e("+text+")§r"; + break; + case "press-4": + finalflair="§a("+text+")§r"; + break; + case "press-5": + finalflair="§9("+text+")§r"; + break; + 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; + case "undecided": //2015.08.09. + p.FlairDecided=false; + finalflair=""; + break; + default: + finalflair=""; + break; + } + if(finalflair.length()==0) //<-- 2015.07.20. + return; + p.Flair=finalflair; //2015.08.08. + p.UserName=username; //2015.08.08. + System.out.println("Added new flair to "+playername+": "+finalflair); + for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08. + { + if(player.getName().equals(playername)) + { + //AppendPlayerDisplayFlair(player, username, finalflair); + AppendPlayerDisplayFlair(p, player); + break; + } + } + } + + public static String GetFlair(Player player) + { //2015.07.16. + String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08. + return flair==null ? "" : flair; + } + + //public static void AppendPlayerDisplayFlair(Player player, String username, String flair) + public static void AppendPlayerDisplayFlair(MaybeOfflinePlayer player, Player p) //<-- 2015.08.09. + { + + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).IgnoredFlair) + return; + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).AcceptedFlair) + { + AppendPlayerDisplayFlairFinal(p, player.Flair); //2015.07.20. + if(!player.FlairDecided) + p.sendMessage("§9Your flair type is unknown. Are you a non-presser or a can't press? (/u nonpresser or /u cantpress)§r"); //2015.08.09. + } + else + p.sendMessage("§9Are you Reddit user "+player.UserName+"?§r §6Type /u accept or /u ignore§r"); + } + + private static void AppendPlayerDisplayFlairFinal(Player player, String flair) + { //2015.07.20. + String color = GetColorForTown(GetPlayerTown(player)); //TO!DO: Multiple colors put on first capital letters + String[] colors = color.substring(1).split("§"); + String displayname=player.getName(); //2015.08.08. + ArrayList Positions=new ArrayList<>(); + for(int i=0; i=colors.length) + { + int x=0; + for(int i=0; i GetPlayers() + { + return Instance.getServer().getOnlinePlayers(); + } + + public static void LoadFiles(boolean reload) //<-- 2015.08.09. + { + if(reload) + { //2015.08.09. + System.out.println("Auto-flair plugin cleanup for reloading..."); + MaybeOfflinePlayer.AllPlayers.clear(); + TownColors.clear(); + } + System.out.println("Loading files for auto-flair plugin..."); //2015.08.09. + try { + File file=new File("flairsaccepted.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + //System.out.println("Name: " + name); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("flairsignored.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsignored.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("autoflairconfig.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + TownColors.put(s[0], s[1]); + } + br.close(); + } + file=new File("customflairs.txt"); //2015.08.09. + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + MaybeOfflinePlayer.AddPlayerIfNeeded(s[0]).Flair=s[1]; //2015.08.09. + } + br.close(); + } + //throw new IOException("Test"); //2015.08.09. + System.out.println("Auto-flair plugin loaded files!"); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + public static void SaveFiles() //<-- 2015.08.09. + { + try + { + FileWriter fw; + fw = new FileWriter("flairsaccepted.txt"); + fw.close(); + fw = new FileWriter("flairsignored.txt"); + fw.close(); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + try { + File file=new File("flairsaccepted.txt"); + BufferedWriter bw=new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.AcceptedFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + file=new File("flairsignored.txt"); + bw = new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.IgnoredFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + public static boolean RemoveLineFromFile(String file, String line) + { //2015.08.09. + File inputFile = new File(file); + File tempFile = new File("_temp.txt"); + + if(!inputFile.exists()) + return true; //2015.08.09. + + try { + BufferedReader reader = new BufferedReader(new FileReader(inputFile)); + BufferedWriter writer = new BufferedWriter(new FileWriter(tempFile)); + + String lineToRemove = line; + String currentLine; + + while((currentLine = reader.readLine()) != null) { + // trim newline when comparing with lineToRemove + String trimmedLine = currentLine.trim(); + //if(trimmedLine.equals(lineToRemove)) continue; + if(trimmedLine.contains(lineToRemove)) continue; //2015.08.09. + writer.write(currentLine + System.getProperty("line.separator")); + } + writer.close(); + reader.close(); + return tempFile.renameTo(inputFile); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + return false; + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/c9/005c8f6bdd3e001517108d149b613203 b/.metadata/.plugins/org.eclipse.core.resources/.history/c9/005c8f6bdd3e001517108d149b613203 new file mode 100644 index 0000000..a826a4b --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/c9/005c8f6bdd3e001517108d149b613203 @@ -0,0 +1,399 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStream; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLConnection; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + +import org.apache.commons.io.IOUtils; +import org.bukkit.entity.Player; +import org.bukkit.plugin.java.JavaPlugin; +import org.json.JSONArray; +import org.json.JSONObject; + +import com.palmergames.bukkit.towny.object.Town; +import com.palmergames.bukkit.towny.object.WorldCoord; + +public class PluginMain extends JavaPlugin +{ //Translated to Java: 2015.07.15. + //A user, which flair isn't obtainable: + //https://www.reddit.com/r/thebutton/comments/31c32v/i_pressed_the_button_without_really_thinking/ + private static PluginMain Instance; + // Fired when plugin is first enabled + @Override + public void onEnable() + { + System.out.println("The Button Auto-flair Plugin by NorbiPeti (:P)"); + getServer().getPluginManager().registerEvents(new PlayerListener(), this); + this.getCommand("u").setExecutor(new Commands()); + this.getCommand("u").setUsage(this.getCommand("u").getUsage().replace('&', '§')); + Instance=this; //2015.08.08. + LoadFiles(false); //2015.08.09. + Runnable r=new Runnable(){public void run(){ThreadMethod();}}; + Thread t=new Thread(r); + t.start(); + } + Boolean stop=false; + // Fired when plugin is disabled + @Override + public void onDisable() + { + SaveFiles(); //2015.08.09. + stop=true; + } + + public void ThreadMethod() //<-- 2015.07.16. + { + while(!stop) + { + try + { + String body=DownloadString("https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/autoflair_system_comment_your_minecraft_name_and/.json?limit=1000"); + JSONArray json=new JSONArray(body).getJSONObject(1).getJSONObject("data").getJSONArray("children"); + for(Object obj : json) + { + JSONObject item = (JSONObject)obj; + String author=item.getJSONObject("data").getString("author"); + String ign=item.getJSONObject("data").getString("body"); + int start = ign.indexOf("IGN:") + "IGN:".length(); + if(start==-1) + continue; //2015.08.09. + int end = ign.indexOf(' ', start); + if (end == -1 || end == start) + end=ign.indexOf('\n', start); //2015.07.15. + if (end == -1 || end == start) + ign = ign.substring(start); + else + ign = ign.substring(start, end); + ign = ign.trim(); + if(HasIGFlair(ign)) + continue; + try { + Thread.sleep(10); + } catch(InterruptedException ex) { + Thread.currentThread().interrupt(); + } + String[] flairdata = DownloadString("http://karmadecay.com/thebutton-data.php?users=" + author).replace("\"", "").split(":"); + String flair; + if(flairdata.length > 1) //2015.07.15. + flair = flairdata[1]; + else + flair=""; + if (flair != "-1") + flair = flair + "s"; + else + flair = "non-presser"; + String flairclass; + if(flairdata.length>2) + flairclass = flairdata[2]; + else + flairclass="unknown"; + SetFlair(ign, flair, flairclass, author); + } + Thread.sleep(10000); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + } + + public static Exception LastException; //2015.08.09. + + public String DownloadString(String urlstr) throws MalformedURLException, IOException + { + URL url = new URL(urlstr); + URLConnection con = url.openConnection(); + con.setRequestProperty("User-Agent", "TheButtonAutoFlair"); + InputStream in = con.getInputStream(); + String encoding = con.getContentEncoding(); + encoding = encoding == null ? "UTF-8" : encoding; + String body = IOUtils.toString(in, encoding); + in.close(); + return body; + } + + public static Map TownColors=new HashMap(); //2015.07.20. + public Boolean HasIGFlair(String playername) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + return p.Flair!=null; //2015.08.08. + } + + public void SetFlair(String playername, String text, String flairclass, String username) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + String finalflair; + p.FlairDecided=true; + switch(flairclass) + { + case "press-1": + finalflair="§c("+text+")§r"; + break; + case "press-2": + finalflair="§6("+text+")§r"; + break; + case "press-3": + finalflair="§e("+text+")§r"; + break; + case "press-4": + finalflair="§a("+text+")§r"; + break; + case "press-5": + finalflair="§9("+text+")§r"; + break; + 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; + case "undecided": //2015.08.09. + p.FlairDecided=false; + finalflair=""; + break; + default: + finalflair=""; + break; + } + if(finalflair.length()==0) //<-- 2015.07.20. + return; + p.Flair=finalflair; //2015.08.08. + p.UserName=username; //2015.08.08. + System.out.println("Added new flair to "+playername+": "+finalflair); + for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08. + { + if(player.getName().equals(playername)) + { + //AppendPlayerDisplayFlair(player, username, finalflair); + AppendPlayerDisplayFlair(p, player); + break; + } + } + } + + public static String GetFlair(Player player) + { //2015.07.16. + String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08. + return flair==null ? "" : flair; + } + + //public static void AppendPlayerDisplayFlair(Player player, String username, String flair) + public static void AppendPlayerDisplayFlair(MaybeOfflinePlayer player, Player p) //<-- 2015.08.09. + { + + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).IgnoredFlair) + return; + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).AcceptedFlair) + { + AppendPlayerDisplayFlairFinal(p, player.Flair); //2015.07.20. + if(!player.FlairDecided) + p.sendMessage("§9Your flair type is unknown. Are you a non-presser or a can't press? (/u nonpresser or /u cantpress)§r"); //2015.08.09. + } + else + p.sendMessage("§9Are you Reddit user "+player.UserName+"?§r §6Type /u accept or /u ignore§r"); + } + + private static void AppendPlayerDisplayFlairFinal(Player player, String flair) + { //2015.07.20. + String color = GetColorForTown(GetPlayerTown(player)); //TO!DO: Multiple colors put on first capital letters + String[] colors = color.substring(1).split("§"); + String displayname=player.getName(); //2015.08.08. + ArrayList Positions=new ArrayList<>(); + for(int i=0; i=colors.length) + { + int x=0; + for(int i=0; i GetPlayers() + { + return Instance.getServer().getOnlinePlayers(); + } + + public static void LoadFiles(boolean reload) //<-- 2015.08.09. + { + if(reload) + { //2015.08.09. + System.out.println("Auto-flair plugin cleanup for reloading..."); + MaybeOfflinePlayer.AllPlayers.clear(); + TownColors.clear(); + } + System.out.println("Loading files for auto-flair plugin..."); //2015.08.09. + try { + File file=new File("flairsaccepted.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + //System.out.println("Name: " + name); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("flairsignored.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsignored.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("autoflairconfig.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + TownColors.put(s[0], s[1]); + } + br.close(); + } + file=new File("autoflairdecisions.txt"); //2015.08.09. + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + MaybeOfflinePlayer.AddPlayerIfNeeded(s[0]).Flair=s[1]; //2015.08.09. + } + br.close(); + } + //throw new IOException("Test"); //2015.08.09. + System.out.println("Auto-flair plugin loaded files!"); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + public static void SaveFiles() //<-- 2015.08.09. + { + try + { + FileWriter fw; + fw = new FileWriter("flairsaccepted.txt"); + fw.close(); + fw = new FileWriter("flairsignored.txt"); + fw.close(); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + try { + File file=new File("flairsaccepted.txt"); + BufferedWriter bw=new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.AcceptedFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + file=new File("flairsignored.txt"); + bw = new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.IgnoredFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + public static void SetPlayerFlair(Player player, String flair) + { //2015.08.09. + flair=flair.replace('&', '§'); + MaybeOfflinePlayer.AddPlayerIfNeeded(player.getName()).Flair=flair; + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/c9/d0b1d9a5883e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/c9/d0b1d9a5883e00151ce8ff6d4f74dabd deleted file mode 100644 index cb9cbd5..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/c9/d0b1d9a5883e00151ce8ff6d4f74dabd +++ /dev/null @@ -1,177 +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; - MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. - //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - if(p.Flair==null) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. - { - case "accept": - { - if(p.IgnoredFlair) - p.IgnoredFlair=false; //2015.08.08. - if(!p.AcceptedFlair) - { - String flair=p.Flair; //2015.08.08. - PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. - p.AcceptedFlair=true; //2015.08.08. - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("§cYou already have this user's flair.§r"); - break; - } - case "ignore": - { - if(p.AcceptedFlair) - p.AcceptedFlair=false; //2015.08.08. - if(!p.IgnoredFlair) - { - p.IgnoredFlair=true; - String flair=p.Flair; //2015.08.08. - PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. - player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); - } - else - player.sendMessage("§cYou already ignored this request.§r"); - break; - } - /*case "reload": //2015.07.20. - DoReload(player); - break;*/ - case "admin": //2015.08.09. - DoAdmin(player, args); - break; - default: - return false; - } - return true; - } - - /*if(args[0].toLowerCase()=="reload") - DoReload(null); //2015.07.20.*/ - else if(args[0].toLowerCase()=="admin") - DoAdmin(null, args); //2015.08.09. - return false; - } - private static void DoReload(Player player) - { //2015.07.20. - //if(player==null || player.isOp() || player.getName()=="NorbiPeti") - //{ - try - { - File file=new File("autoflairconfig.txt"); - if(file.exists()) - { - PluginMain.TownColors.clear(); - BufferedReader br=new BufferedReader(new FileReader(file)); - String line; - while((line=br.readLine())!=null) - { - String[] s=line.split(" "); - PluginMain.TownColors.put(s[0], s[1]); - } - br.close(); - for(Player p : PluginMain.GetPlayers()) - { - MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName()); - if(mp.Flair!=null) - { - String flair=mp.Flair; - PluginMain.RemovePlayerDisplayFlairFinal(p, flair); - PluginMain.AppendPlayerDisplayFlairFinal(p, flair); - } - } - String msg="§6Reloaded config file.§r"; - if(player!=null) - player.sendMessage(msg); - else - System.out.println(msg); - } - } - catch(Exception e) - { - System.out.println("Error!\n"+e); - if(player!=null) - player.sendMessage("§cAn error occured. See console for details.§r"); - } - //} - //else - //player.sendMessage("§cYou need to be OP to use this command.§r"); - } - private static void DoAdmin(Player player, String[] args) - { //2015.08.09. - if(player==null || player.isOp() || player.getName()=="NorbiPeti") - { - if(args.length==1) - { - String message="§cUsage: /u admin reload|playerinfo§r"; - if(player==null) - System.out.println(message); - else - player.sendMessage(message); - return; - } - //args[0] is "admin" - switch(args[1].toLowerCase()) - { - case "reload": - DoReload(player); - break; - case "playerinfo": - DoPlayerInfo(player, args); - break; - } - } - else - player.sendMessage("§cYou need to be OP to use this command.§r"); - } - private static void DoPlayerInfo(Player player, String[] args) - { //2015.08.09. - //args[0] is "admin" - args[1] is "playerinfo" - if(args.length==2) - { - String message="§cUsage: /u admin playerinfo §r"; - if(player==null) - System.out.println(message); - else - player.sendMessage(message); - return; - } - if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2])) - { - String message="§cPlayer not found: "+args[2]+"§r"; - if(player==null) - System.out.println(message); - else - player.sendMessage(message); - return; - } - MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]); - return; - } - private static void SendMessage(Player player, String message) - { - - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/ca/00f60a63df3e001517108d149b613203 b/.metadata/.plugins/org.eclipse.core.resources/.history/ca/00f60a63df3e001517108d149b613203 new file mode 100644 index 0000000..df11079 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/ca/00f60a63df3e001517108d149b613203 @@ -0,0 +1,252 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +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; + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. + //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) + if(p.Flair==null) + { + player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); + return true; + } + switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. + { + case "accept": + { + if(p.IgnoredFlair) + p.IgnoredFlair=false; //2015.08.08. + if(!p.AcceptedFlair) + { + String flair=p.Flair; //2015.08.08. + //PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + PluginMain.AppendPlayerDisplayFlair(p, player); + p.AcceptedFlair=true; //2015.08.08. + player.sendMessage("§6Your flair has been set:§r "+flair); + } + else + player.sendMessage("§cYou already have this user's flair.§r"); + break; + } + case "ignore": + { + if(p.AcceptedFlair) + p.AcceptedFlair=false; //2015.08.08. + if(!p.IgnoredFlair) + { + p.IgnoredFlair=true; + String flair=p.Flair; //2015.08.08. + PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. + player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); + } + else + player.sendMessage("§cYou already ignored this request.§r"); + break; + } + /*case "reload": //2015.07.20. + DoReload(player); + break;*/ + case "admin": //2015.08.09. + DoAdmin(player, args); + break; + case "nonpresser": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§7(non-pr.)§r"; + break; + case "cantpress": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§r(can't press)§r"; + break; + default: + return false; + } + return true; + } + /*if(args[0].toLowerCase()=="reload") + DoReload(null); //2015.07.20.*/ + else if(args.length>0 && args[0].toLowerCase().equals("admin")) //2015.08.09. + { + DoAdmin(null, args); //2015.08.09. + return true; //2015.08.09. + } + return false; + } + private static void DoReload(Player player) + { //2015.07.20. + //if(player==null || player.isOp() || player.getName()=="NorbiPeti") + //{ + try + { + File file=new File("autoflairconfig.txt"); + if(file.exists()) + { + PluginMain.LoadFiles(true); //2015.08.09. + for(Player p : PluginMain.GetPlayers()) + { + MaybeOfflinePlayer mp = MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName()); + if(mp.Flair!=null) + { + String flair=mp.Flair; + PluginMain.RemovePlayerDisplayFlairFinal(p, flair); + //PluginMain.AppendPlayerDisplayFlairFinal(p, flair); + PluginMain.AppendPlayerDisplayFlair(mp, p); //2015.08.09. + } + String msg="§6Note: The auto-flair plugin has been reloaded. You might need to wait 10s to have your flair.§r"; //2015.08.09. + p.sendMessage(msg); //2015.08.09. + } + //String msg="§6Reloaded config file.§r"; + //SendMessage(player, msg); //2015.08.09. + } + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + if(player!=null) + player.sendMessage("§cAn error occured. See console for details.§r"); + PluginMain.LastException=e; //2015.08.09. + } + //} + //else + //player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static Player ReloadPlayer; //2015.08.09. + private static void DoAdmin(Player player, String[] args) + { //2015.08.09. + if(player==null || player.isOp() || player.getName()=="NorbiPeti") + { + //System.out.println("Args length: " + args.length); + if(args.length==1) + { + String message="§cUsage: /u admin reload|playerinfo§r"; + SendMessage(player, message); + return; + } + //args[0] is "admin" + switch(args[1].toLowerCase()) + { + case "reload": + ReloadPlayer=player; //2015.08.09. + SendMessage(player, "§6Make sure to save the current settings before you modify and reload them! Type /u admin confirm when done.§r"); + break; + case "playerinfo": + DoPlayerInfo(player, args); + break; + case "getlasterror": + DoGetLastError(player, args); + case "confirm": + if(ReloadPlayer==player) + DoReload(player); //2015.08.09. + else + SendMessage(player, "§cYou need to do /u admin reload first.§r"); + break; + case "save": + PluginMain.SaveFiles(); //2015.08.09. + SendMessage(player, "§6Saved files. Now you can edit them and reload if you want.§r"); + break; + default: + String message="§cUsage: /u admin reload|playerinfo|getlasterror§r"; + SendMessage(player, message); + return; + } + } + else + player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static void DoPlayerInfo(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "playerinfo" + if(args.length==2) + { + String message="§cUsage: /u admin playerinfo §r"; + SendMessage(player, message); + return; + } + if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2])) + { + String message="§cPlayer not found: "+args[2]+"§r"; + SendMessage(player, message); + return; + } + MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]); + SendMessage(player, "Player name: "+p.PlayerName); + SendMessage(player, "User flair: "+p.Flair); + SendMessage(player, "Username: "+p.UserName); + SendMessage(player, "Flair accepted: "+p.AcceptedFlair); + SendMessage(player, "Flair ignored: "+p.IgnoredFlair); + } + private static void SendMessage(Player player, String message) + { //2015.08.09. + if(player==null) + System.out.println(message); + else + player.sendMessage(message); + } + private static void DoGetLastError(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "getlasterror" + if(PluginMain.LastException!=null) + { + SendMessage(player, "Last error:"); + SendMessage(player, PluginMain.LastException.toString()); + PluginMain.LastException=null; + } + else + SendMessage(player, "There were no exceptions."); + } + private static void SetPlayerFlair(Player player, String flair) + { //2015.08.09. + flair=flair.replace('&', '§'); + MaybeOfflinePlayer.AddPlayerIfNeeded(player.getName()).Flair=flair; + if(!PluginMain.RemoveLineFromFile("customflairs.txt")) + { + SendMessage(player, "§cError removing previous custom flair!§r"); + return; + } + File file=new File("customflairs.txt"); + try { + BufferedWriter bw; + bw = new BufferedWriter(new FileWriter(file, true)); + bw.write(player.getName()+"\n"); + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + PluginMain.LastException=e; //2015.08.09. + } + SendMessage(player, "§6The flair has been set. Player: "+player.getName()+" Flair: "+flair); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/cb/d058f890873e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/cb/d058f890873e00151ce8ff6d4f74dabd deleted file mode 100644 index 1e3d1d3..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/cb/d058f890873e00151ce8ff6d4f74dabd +++ /dev/null @@ -1,145 +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; - MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. - //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - if(p.Flair==null) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. - { - case "accept": - { - if(p.IgnoredFlair) - p.IgnoredFlair=false; //2015.08.08. - if(!p.AcceptedFlair) - { - String flair=p.Flair; //2015.08.08. - PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. - p.AcceptedFlair=true; //2015.08.08. - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("§cYou already have this user's flair.§r"); - break; - } - case "ignore": - { - if(p.AcceptedFlair) - p.AcceptedFlair=false; //2015.08.08. - if(!p.IgnoredFlair) - { - p.IgnoredFlair=true; - String flair=p.Flair; //2015.08.08. - PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. - player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); - } - else - player.sendMessage("§cYou already ignored this request.§r"); - break; - } - /*case "reload": //2015.07.20. - DoReload(player); - break;*/ - case "admin": //2015.08.09. - DoAdmin(player, args); - break; - default: - return false; - } - return true; - } - - /*if(args[0].toLowerCase()=="reload") - DoReload(null); //2015.07.20.*/ - else if(args[0].toLowerCase()=="admin") - DoAdmin(null, args); //2015.08.09. - return false; - } - private static void DoReload(Player player) - { //2015.07.20. - //if(player==null || player.isOp() || player.getName()=="NorbiPeti") - //{ - try - { - File file=new File("autoflairconfig.txt"); - if(file.exists()) - { - PluginMain.TownColors.clear(); - BufferedReader br=new BufferedReader(new FileReader(file)); - String line; - while((line=br.readLine())!=null) - { - String[] s=line.split(" "); - PluginMain.TownColors.put(s[0], s[1]); - } - br.close(); - for(Player p : PluginMain.GetPlayers()) - { - MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName()); - if(mp.Flair!=null) - { - String flair=mp.Flair; - PluginMain.RemovePlayerDisplayFlairFinal(p, flair); - PluginMain.AppendPlayerDisplayFlairFinal(p, flair); - } - } - String msg="§6Reloaded config file.§r"; - if(player!=null) - player.sendMessage(msg); - else - System.out.println(msg); - } - } - catch(Exception e) - { - System.out.println("Error!\n"+e); - if(player!=null) - player.sendMessage("§cAn error occured. See console for details.§r"); - } - //} - //else - //player.sendMessage("§cYou need to be OP to use this command.§r"); - } - private static void DoAdmin(Player player, String[] args) - { - if(player==null || player.isOp() || player.getName()=="NorbiPeti") - { - //args[0] is "admin" - switch(args[1].toLowerCase()) - { - case "reload": - DoReload(player); - break; - case "playerinfo": - DoPlayerInfo(player, args); - break; - } - } - else - player.sendMessage("§cYou need to be OP to use this command.§r"); - } - private static void DoPlayerInfo(Player player, String[] args) - { - //args[0] is "admin" - args[1] is "playerinfo" - - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/cc/10d57c5c0d3e00151089cca86c5b1a99 b/.metadata/.plugins/org.eclipse.core.resources/.history/cc/10d57c5c0d3e00151089cca86c5b1a99 deleted file mode 100644 index efac5c3..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/cc/10d57c5c0d3e00151089cca86c5b1a99 +++ /dev/null @@ -1,434 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import java.io.BufferedReader; -import java.io.BufferedWriter; -import java.io.File; -import java.io.FileReader; -import java.io.FileWriter; -import java.io.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/b08607c4d23e001518fa86d7ae2a1cf8 b/.metadata/.plugins/org.eclipse.core.resources/.history/cc/b08607c4d23e001518fa86d7ae2a1cf8 new file mode 100644 index 0000000..5d7321f --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/cc/b08607c4d23e001518fa86d7ae2a1cf8 @@ -0,0 +1,215 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; + +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class Commands implements CommandExecutor { + // This method is called, when somebody uses our command + @Override + public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { + if (sender instanceof Player) { + Player player = (Player) sender; + if(args.length<1) + return false; + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. + //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) + if(p.Flair==null) + { + player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); + return true; + } + switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. + { + case "accept": + { + if(p.IgnoredFlair) + p.IgnoredFlair=false; //2015.08.08. + if(!p.AcceptedFlair) + { + String flair=p.Flair; //2015.08.08. + //PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + PluginMain.AppendPlayerDisplayFlair(p, player); + p.AcceptedFlair=true; //2015.08.08. + player.sendMessage("§6Your flair has been set:§r "+flair); + } + else + player.sendMessage("§cYou already have this user's flair.§r"); + break; + } + case "ignore": + { + if(p.AcceptedFlair) + p.AcceptedFlair=false; //2015.08.08. + if(!p.IgnoredFlair) + { + p.IgnoredFlair=true; + String flair=p.Flair; //2015.08.08. + PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. + player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); + } + else + player.sendMessage("§cYou already ignored this request.§r"); + break; + } + /*case "reload": //2015.07.20. + DoReload(player); + break;*/ + case "admin": //2015.08.09. + DoAdmin(player, args); + break; + case "nonpresser": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§7(non-pr.)§r"; + break; + case "cantpress": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§r(can't press)§r"; + break; + default: + return false; + } + return true; + } + /*if(args[0].toLowerCase()=="reload") + DoReload(null); //2015.07.20.*/ + else if(args.length>0 && args[0].toLowerCase().equals("admin")) //2015.08.09. + { + DoAdmin(null, args); //2015.08.09. + return true; //2015.08.09. + } + return false; + } + private static void DoReload(Player player) + { //2015.07.20. + //if(player==null || player.isOp() || player.getName()=="NorbiPeti") + //{ + try + { + File file=new File("autoflairconfig.txt"); + if(file.exists()) + { + PluginMain.LoadFiles(true); //2015.08.09. + 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); + PluginMain.AppendPlayerDisplayFlair(mp, p); //2015.08.09. + } + } + //String msg="§6Reloaded config file.§r"; + String msg="§6Reloaded all files.§r"; + SendMessage(player, msg); //2015.08.09. + } + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + if(player!=null) + player.sendMessage("§cAn error occured. See console for details.§r"); + PluginMain.LastException=e; //2015.08.09. + } + //} + //else + //player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static void DoAdmin(Player player, String[] args) + { //2015.08.09. + if(player==null || player.isOp() || player.getName()=="NorbiPeti") + { + //System.out.println("Args length: " + args.length); + if(args.length==1) + { + String message="§cUsage: /u admin reload|playerinfo§r"; + SendMessage(player, message); + return; + } + //args[0] is "admin" + switch(args[1].toLowerCase()) + { + case "reload": + DoReload(player); + break; + case "playerinfo": + DoPlayerInfo(player, args); + break; + case "getlasterror": + DoGetLastError(player, args); + default: + String message="§cUsage: /u admin reload|playerinfo§r"; + SendMessage(player, message); + return; + } + } + else + player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static void DoPlayerInfo(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "playerinfo" + if(args.length==2) + { + String message="§cUsage: /u admin playerinfo §r"; + SendMessage(player, message); + return; + } + if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2])) + { + String message="§cPlayer not found: "+args[2]+"§r"; + SendMessage(player, message); + return; + } + MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]); + SendMessage(player, "Player name: "+p.PlayerName); + SendMessage(player, "User flair: "+p.Flair); + SendMessage(player, "Username: "+p.UserName); + SendMessage(player, "Flair accepted: "+p.AcceptedFlair); + SendMessage(player, "Flair ignored: "+p.IgnoredFlair); + } + private static void SendMessage(Player player, String message) + { //2015.08.09. + if(player==null) + System.out.println(message); + else + player.sendMessage(message); + } + private static void DoGetLastError(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "getlasterror" + if(PluginMain.LastException!=null) + { + SendMessage(player, "Last error:"); + SendMessage(player, PluginMain.LastException.toString()); + PluginMain.LastException=null; + } + else + SendMessage(player, "There were no exceptions."); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/cd/804ab462df3e001517108d149b613203 b/.metadata/.plugins/org.eclipse.core.resources/.history/cd/804ab462df3e001517108d149b613203 new file mode 100644 index 0000000..df11079 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/cd/804ab462df3e001517108d149b613203 @@ -0,0 +1,252 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +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; + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. + //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) + if(p.Flair==null) + { + player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); + return true; + } + switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. + { + case "accept": + { + if(p.IgnoredFlair) + p.IgnoredFlair=false; //2015.08.08. + if(!p.AcceptedFlair) + { + String flair=p.Flair; //2015.08.08. + //PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + PluginMain.AppendPlayerDisplayFlair(p, player); + p.AcceptedFlair=true; //2015.08.08. + player.sendMessage("§6Your flair has been set:§r "+flair); + } + else + player.sendMessage("§cYou already have this user's flair.§r"); + break; + } + case "ignore": + { + if(p.AcceptedFlair) + p.AcceptedFlair=false; //2015.08.08. + if(!p.IgnoredFlair) + { + p.IgnoredFlair=true; + String flair=p.Flair; //2015.08.08. + PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. + player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); + } + else + player.sendMessage("§cYou already ignored this request.§r"); + break; + } + /*case "reload": //2015.07.20. + DoReload(player); + break;*/ + case "admin": //2015.08.09. + DoAdmin(player, args); + break; + case "nonpresser": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§7(non-pr.)§r"; + break; + case "cantpress": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§r(can't press)§r"; + break; + default: + return false; + } + return true; + } + /*if(args[0].toLowerCase()=="reload") + DoReload(null); //2015.07.20.*/ + else if(args.length>0 && args[0].toLowerCase().equals("admin")) //2015.08.09. + { + DoAdmin(null, args); //2015.08.09. + return true; //2015.08.09. + } + return false; + } + private static void DoReload(Player player) + { //2015.07.20. + //if(player==null || player.isOp() || player.getName()=="NorbiPeti") + //{ + try + { + File file=new File("autoflairconfig.txt"); + if(file.exists()) + { + PluginMain.LoadFiles(true); //2015.08.09. + for(Player p : PluginMain.GetPlayers()) + { + MaybeOfflinePlayer mp = MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName()); + if(mp.Flair!=null) + { + String flair=mp.Flair; + PluginMain.RemovePlayerDisplayFlairFinal(p, flair); + //PluginMain.AppendPlayerDisplayFlairFinal(p, flair); + PluginMain.AppendPlayerDisplayFlair(mp, p); //2015.08.09. + } + String msg="§6Note: The auto-flair plugin has been reloaded. You might need to wait 10s to have your flair.§r"; //2015.08.09. + p.sendMessage(msg); //2015.08.09. + } + //String msg="§6Reloaded config file.§r"; + //SendMessage(player, msg); //2015.08.09. + } + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + if(player!=null) + player.sendMessage("§cAn error occured. See console for details.§r"); + PluginMain.LastException=e; //2015.08.09. + } + //} + //else + //player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static Player ReloadPlayer; //2015.08.09. + private static void DoAdmin(Player player, String[] args) + { //2015.08.09. + if(player==null || player.isOp() || player.getName()=="NorbiPeti") + { + //System.out.println("Args length: " + args.length); + if(args.length==1) + { + String message="§cUsage: /u admin reload|playerinfo§r"; + SendMessage(player, message); + return; + } + //args[0] is "admin" + switch(args[1].toLowerCase()) + { + case "reload": + ReloadPlayer=player; //2015.08.09. + SendMessage(player, "§6Make sure to save the current settings before you modify and reload them! Type /u admin confirm when done.§r"); + break; + case "playerinfo": + DoPlayerInfo(player, args); + break; + case "getlasterror": + DoGetLastError(player, args); + case "confirm": + if(ReloadPlayer==player) + DoReload(player); //2015.08.09. + else + SendMessage(player, "§cYou need to do /u admin reload first.§r"); + break; + case "save": + PluginMain.SaveFiles(); //2015.08.09. + SendMessage(player, "§6Saved files. Now you can edit them and reload if you want.§r"); + break; + default: + String message="§cUsage: /u admin reload|playerinfo|getlasterror§r"; + SendMessage(player, message); + return; + } + } + else + player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static void DoPlayerInfo(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "playerinfo" + if(args.length==2) + { + String message="§cUsage: /u admin playerinfo §r"; + SendMessage(player, message); + return; + } + if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2])) + { + String message="§cPlayer not found: "+args[2]+"§r"; + SendMessage(player, message); + return; + } + MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]); + SendMessage(player, "Player name: "+p.PlayerName); + SendMessage(player, "User flair: "+p.Flair); + SendMessage(player, "Username: "+p.UserName); + SendMessage(player, "Flair accepted: "+p.AcceptedFlair); + SendMessage(player, "Flair ignored: "+p.IgnoredFlair); + } + private static void SendMessage(Player player, String message) + { //2015.08.09. + if(player==null) + System.out.println(message); + else + player.sendMessage(message); + } + private static void DoGetLastError(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "getlasterror" + if(PluginMain.LastException!=null) + { + SendMessage(player, "Last error:"); + SendMessage(player, PluginMain.LastException.toString()); + PluginMain.LastException=null; + } + else + SendMessage(player, "There were no exceptions."); + } + private static void SetPlayerFlair(Player player, String flair) + { //2015.08.09. + flair=flair.replace('&', '§'); + MaybeOfflinePlayer.AddPlayerIfNeeded(player.getName()).Flair=flair; + if(!PluginMain.RemoveLineFromFile("customflairs.txt")) + { + SendMessage(player, "§cError removing previous custom flair!§r"); + return; + } + File file=new File("customflairs.txt"); + try { + BufferedWriter bw; + bw = new BufferedWriter(new FileWriter(file, true)); + bw.write(player.getName()+"\n"); + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + PluginMain.LastException=e; //2015.08.09. + } + SendMessage(player, "§6The flair has been set. Player: "+player.getName()+" Flair: "+flair); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/cd/90837b3cd23e001518fa86d7ae2a1cf8 b/.metadata/.plugins/org.eclipse.core.resources/.history/cd/90837b3cd23e001518fa86d7ae2a1cf8 new file mode 100644 index 0000000..e95109b --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/cd/90837b3cd23e001518fa86d7ae2a1cf8 @@ -0,0 +1,377 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStream; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLConnection; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + +import org.apache.commons.io.IOUtils; +import org.bukkit.entity.Player; +import org.bukkit.plugin.java.JavaPlugin; +import org.json.JSONArray; +import org.json.JSONObject; + +import com.palmergames.bukkit.towny.object.Town; +import com.palmergames.bukkit.towny.object.WorldCoord; + +public class PluginMain extends JavaPlugin +{ //Translated to Java: 2015.07.15. + //A user, which flair isn't obtainable: + //https://www.reddit.com/r/thebutton/comments/31c32v/i_pressed_the_button_without_really_thinking/ + private static PluginMain Instance; + // Fired when plugin is first enabled + @Override + public void onEnable() + { + System.out.println("The Button Auto-flair Plugin by NorbiPeti (:P)"); + getServer().getPluginManager().registerEvents(new PlayerListener(), this); + this.getCommand("u").setExecutor(new Commands()); + this.getCommand("u").setUsage(this.getCommand("u").getUsage().replace('&', '§')); + Instance=this; //2015.08.08. + LoadFiles(false); //2015.08.09. + Runnable r=new Runnable(){public void run(){ThreadMethod();}}; + Thread t=new Thread(r); + t.start(); + } + Boolean stop=false; + // Fired when plugin is disabled + @Override + public void onDisable() + { + try + { + FileWriter fw; + fw = new FileWriter("flairsaccepted.txt"); + fw.close(); + fw = new FileWriter("flairsignored.txt"); + fw.close(); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + try { + File file=new File("flairsaccepted.txt"); + BufferedWriter bw=new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.AcceptedFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + file=new File("flairsignored.txt"); + bw = new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.IgnoredFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + stop=true; + } + + public void ThreadMethod() //<-- 2015.07.16. + { + while(!stop) + { + try + { + String body=DownloadString("https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/autoflair_system_comment_your_minecraft_name_and/.json?limit=1000"); + JSONArray json=new JSONArray(body).getJSONObject(1).getJSONObject("data").getJSONArray("children"); + for(Object obj : json) + { + JSONObject item = (JSONObject)obj; + String author=item.getJSONObject("data").getString("author"); + String ign=item.getJSONObject("data").getString("body"); + int start = ign.indexOf("IGN:") + "IGN:".length(); + int end = ign.indexOf(' ', start); + if (end == -1 || end == start) + end=ign.indexOf('\n', start); //2015.07.15. + if (end == -1 || end == start) + ign = ign.substring(start); + else + ign = ign.substring(start, end); + ign = ign.trim(); + if(HasIGFlair(ign)) + continue; + try { + Thread.sleep(10); + } catch(InterruptedException ex) { + Thread.currentThread().interrupt(); + } + String[] flairdata = DownloadString("http://karmadecay.com/thebutton-data.php?users=" + author).replace("\"", "").split(":"); + String flair; + if(flairdata.length > 1) //2015.07.15. + flair = flairdata[1]; + else + flair=""; + if (flair != "-1") + flair = flair + "s"; + else + flair = "non-presser"; + String flairclass; + if(flairdata.length>2) + flairclass = flairdata[2]; + else + flairclass="unknown"; + SetFlair(ign, flair, flairclass, author); + } + Thread.sleep(10000); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + } + + public static Exception LastException; //2015.08.09. + + public String DownloadString(String urlstr) throws MalformedURLException, IOException + { + URL url = new URL(urlstr); + URLConnection con = url.openConnection(); + con.setRequestProperty("User-Agent", "TheButtonAutoFlair"); + InputStream in = con.getInputStream(); + String encoding = con.getContentEncoding(); + encoding = encoding == null ? "UTF-8" : encoding; + String body = IOUtils.toString(in, encoding); + in.close(); + return body; + } + + public static Map TownColors=new HashMap(); //2015.07.20. + public Boolean HasIGFlair(String playername) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + return p.Flair!=null; //2015.08.08. + } + + public void SetFlair(String playername, String text, String flairclass, String username) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + String finalflair; + p.FlairDecided=true; + switch(flairclass) + { + case "press-1": + finalflair="§c("+text+")§r"; + break; + case "press-2": + finalflair="§6("+text+")§r"; + break; + case "press-3": + finalflair="§e("+text+")§r"; + break; + case "press-4": + finalflair="§a("+text+")§r"; + break; + case "press-5": + finalflair="§9("+text+")§r"; + break; + 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; + case "undecided": //2015.08.09. + p.FlairDecided=false; + finalflair=""; + break; + default: + finalflair=""; + break; + } + if(finalflair.length()==0) //<-- 2015.07.20. + return; + p.Flair=finalflair; //2015.08.08. + p.UserName=username; //2015.08.08. + System.out.println("Added new flair to "+playername+": "+finalflair); + for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08. + { + if(player.getName().equals(playername)) + { + //AppendPlayerDisplayFlair(player, username, finalflair); + AppendPlayerDisplayFlair(p, player); + break; + } + } + } + + public static String GetFlair(Player player) + { //2015.07.16. + String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08. + return flair==null ? "" : flair; + } + + //public static void AppendPlayerDisplayFlair(Player player, String username, String flair) + public static void AppendPlayerDisplayFlair(MaybeOfflinePlayer player, Player p) //<-- 2015.08.09. + { + + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).IgnoredFlair) + return; + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).AcceptedFlair) + { + AppendPlayerDisplayFlairFinal(p, player.Flair); //2015.07.20. + if(!player.FlairDecided) + p.sendMessage("§9Your flair type is unknown. Are you a non-presser or a can't press? (/u nonpresser or /u cantpress)§r"); //2015.08.09. + } + else + p.sendMessage("§9Are you Reddit user "+player.UserName+"?§r §6Type /u accept or /u ignore§r"); + } + + private static void AppendPlayerDisplayFlairFinal(Player player, String flair) + { //2015.07.20. + String color = GetColorForTown(GetPlayerTown(player)); //TO!DO: Multiple colors put on first capital letters + String[] colors = color.substring(1).split("§"); + String displayname=player.getName(); //2015.08.08. + ArrayList Positions=new ArrayList<>(); + for(int i=0; i=colors.length) + { + int x=0; + for(int i=0; i GetPlayers() + { + return Instance.getServer().getOnlinePlayers(); + } + + public static void LoadFiles(boolean reload) //<-- 2015.08.09. + { + if(reload) + { //2015.08.09. + System.out.println("Auto-flair plugin cleanup for reloading..."); + MaybeOfflinePlayer.AllPlayers.clear(); + TownColors.clear(); + } + System.out.println("Loading files for auto-flair plugin..."); //2015.08.09. + try { + File file=new File("flairsaccepted.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + //System.out.println("Name: " + name); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("flairsignored.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsignored.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("autoflairconfig.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + TownColors.put(s[0], s[1]); + } + br.close(); + } + //throw new IOException("Test"); //2015.08.09. + System.out.println("Auto-flair plugin loaded files!"); + + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/ce/000b95b8e03e001517108d149b613203 b/.metadata/.plugins/org.eclipse.core.resources/.history/ce/000b95b8e03e001517108d149b613203 new file mode 100644 index 0000000..6ad1625 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/ce/000b95b8e03e001517108d149b613203 @@ -0,0 +1,264 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +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; + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. + //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) + if(p.Flair==null) + { + player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); + return true; + } + switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. + { + case "accept": + { + if(p.IgnoredFlair) + p.IgnoredFlair=false; //2015.08.08. + if(!p.AcceptedFlair) + { + String flair=p.Flair; //2015.08.08. + //PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + PluginMain.AppendPlayerDisplayFlair(p, player); + p.AcceptedFlair=true; //2015.08.08. + player.sendMessage("§6Your flair has been set:§r "+flair); + } + else + player.sendMessage("§cYou already have this user's flair.§r"); + break; + } + case "ignore": + { + if(p.AcceptedFlair) + p.AcceptedFlair=false; //2015.08.08. + if(!p.IgnoredFlair) + { + p.IgnoredFlair=true; + String flair=p.Flair; //2015.08.08. + PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. + player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); + } + else + player.sendMessage("§cYou already ignored this request.§r"); + break; + } + /*case "reload": //2015.07.20. + DoReload(player); + break;*/ + case "admin": //2015.08.09. + DoAdmin(player, args); + break; + case "nonpresser": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§7(non-pr.)§r"; + break; + case "cantpress": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§r(can't press)§r"; + break; + default: + return false; + } + return true; + } + /*if(args[0].toLowerCase()=="reload") + DoReload(null); //2015.07.20.*/ + else if(args.length>0 && args[0].toLowerCase().equals("admin")) //2015.08.09. + { + DoAdmin(null, args); //2015.08.09. + return true; //2015.08.09. + } + return false; + } + private static void DoReload(Player player) + { //2015.07.20. + //if(player==null || player.isOp() || player.getName()=="NorbiPeti") + //{ + try + { + File file=new File("autoflairconfig.txt"); + if(file.exists()) + { + PluginMain.LoadFiles(true); //2015.08.09. + for(Player p : PluginMain.GetPlayers()) + { + MaybeOfflinePlayer mp = MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName()); + if(mp.Flair!=null) + { + String flair=mp.Flair; + PluginMain.RemovePlayerDisplayFlairFinal(p, flair); + //PluginMain.AppendPlayerDisplayFlairFinal(p, flair); + PluginMain.AppendPlayerDisplayFlair(mp, p); //2015.08.09. + } + String msg="§6Note: The auto-flair plugin has been reloaded. You might need to wait 10s to have your flair.§r"; //2015.08.09. + p.sendMessage(msg); //2015.08.09. + } + //String msg="§6Reloaded config file.§r"; + //SendMessage(player, msg); //2015.08.09. + } + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + if(player!=null) + player.sendMessage("§cAn error occured. See console for details.§r"); + PluginMain.LastException=e; //2015.08.09. + } + //} + //else + //player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static Player ReloadPlayer; //2015.08.09. + private static void DoAdmin(Player player, String[] args) + { //2015.08.09. + if(player==null || player.isOp() || player.getName()=="NorbiPeti") + { + //System.out.println("Args length: " + args.length); + if(args.length==1) + { + String message="§cUsage: /u admin reload|playerinfo§r"; + SendMessage(player, message); + return; + } + //args[0] is "admin" + switch(args[1].toLowerCase()) + { + case "reload": + ReloadPlayer=player; //2015.08.09. + SendMessage(player, "§6Make sure to save the current settings before you modify and reload them! Type /u admin confirm when done.§r"); + break; + case "playerinfo": + DoPlayerInfo(player, args); + break; + case "getlasterror": + DoGetLastError(player, args); + case "confirm": + if(ReloadPlayer==player) + DoReload(player); //2015.08.09. + else + SendMessage(player, "§cYou need to do /u admin reload first.§r"); + break; + case "save": + PluginMain.SaveFiles(); //2015.08.09. + SendMessage(player, "§6Saved files. Now you can edit them and reload if you want.§r"); + break; + case "setflair": + + break; + default: + String message="§cUsage: /u admin reload|playerinfo|getlasterror|save§r"; + SendMessage(player, message); + return; + } + } + else + player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static void DoPlayerInfo(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "playerinfo" + if(args.length==2) + { + String message="§cUsage: /u admin playerinfo §r"; + SendMessage(player, message); + return; + } + if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2])) + { + String message="§cPlayer not found: "+args[2]+"§r"; + SendMessage(player, message); + return; + } + MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]); + SendMessage(player, "Player name: "+p.PlayerName); + SendMessage(player, "User flair: "+p.Flair); + SendMessage(player, "Username: "+p.UserName); + SendMessage(player, "Flair accepted: "+p.AcceptedFlair); + SendMessage(player, "Flair ignored: "+p.IgnoredFlair); + } + private static void SendMessage(Player player, String message) + { //2015.08.09. + if(player==null) + System.out.println(message); + else + player.sendMessage(message); + } + private static void DoGetLastError(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "getlasterror" + if(PluginMain.LastException!=null) + { + SendMessage(player, "Last error:"); + SendMessage(player, PluginMain.LastException.toString()); + PluginMain.LastException=null; + } + else + SendMessage(player, "There were no exceptions."); + } + private static void SetPlayerFlair(Player player, Player targetplayer, String flair) + { //2015.08.09. + flair=flair.replace('&', '§'); + MaybeOfflinePlayer.AddPlayerIfNeeded(player.getName()).Flair=flair; + if(!PluginMain.RemoveLineFromFile("customflairs.txt", targetplayer.getName())) + { + SendMessage(player, "§cError removing previous custom flair!§r"); + return; + } + File file=new File("customflairs.txt"); + try { + BufferedWriter bw; + bw = new BufferedWriter(new FileWriter(file, true)); + bw.write(targetplayer.getName()+"\n"); + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + PluginMain.LastException=e; //2015.08.09. + } + SendMessage(player, "§6The flair has been set. Player: "+targetplayer.getName()+" Flair: "+flair+"§r"); + } + private static void DoSetFlair(Player player, String args) + { + //args[0] is "admin" - args[1] is "setflair" + if(args.length()<4) + { + SendMessage(player, "§cUsage: /u admin setflair "); + return; + } + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/ce/d00a337efe3d00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/ce/d00a337efe3d00151c31fb33fff4337f deleted file mode 100644 index 5660588..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/ce/d00a337efe3d00151c31fb33fff4337f +++ /dev/null @@ -1,122 +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()); - 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/cf/00fa3acadf3e001517108d149b613203 b/.metadata/.plugins/org.eclipse.core.resources/.history/cf/00fa3acadf3e001517108d149b613203 new file mode 100644 index 0000000..60eeadd --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/cf/00fa3acadf3e001517108d149b613203 @@ -0,0 +1,252 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +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; + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. + //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) + if(p.Flair==null) + { + player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); + return true; + } + switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. + { + case "accept": + { + if(p.IgnoredFlair) + p.IgnoredFlair=false; //2015.08.08. + if(!p.AcceptedFlair) + { + String flair=p.Flair; //2015.08.08. + //PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + PluginMain.AppendPlayerDisplayFlair(p, player); + p.AcceptedFlair=true; //2015.08.08. + player.sendMessage("§6Your flair has been set:§r "+flair); + } + else + player.sendMessage("§cYou already have this user's flair.§r"); + break; + } + case "ignore": + { + if(p.AcceptedFlair) + p.AcceptedFlair=false; //2015.08.08. + if(!p.IgnoredFlair) + { + p.IgnoredFlair=true; + String flair=p.Flair; //2015.08.08. + PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. + player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); + } + else + player.sendMessage("§cYou already ignored this request.§r"); + break; + } + /*case "reload": //2015.07.20. + DoReload(player); + break;*/ + case "admin": //2015.08.09. + DoAdmin(player, args); + break; + case "nonpresser": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§7(non-pr.)§r"; + break; + case "cantpress": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§r(can't press)§r"; + break; + default: + return false; + } + return true; + } + /*if(args[0].toLowerCase()=="reload") + DoReload(null); //2015.07.20.*/ + else if(args.length>0 && args[0].toLowerCase().equals("admin")) //2015.08.09. + { + DoAdmin(null, args); //2015.08.09. + return true; //2015.08.09. + } + return false; + } + private static void DoReload(Player player) + { //2015.07.20. + //if(player==null || player.isOp() || player.getName()=="NorbiPeti") + //{ + try + { + File file=new File("autoflairconfig.txt"); + if(file.exists()) + { + PluginMain.LoadFiles(true); //2015.08.09. + for(Player p : PluginMain.GetPlayers()) + { + MaybeOfflinePlayer mp = MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName()); + if(mp.Flair!=null) + { + String flair=mp.Flair; + PluginMain.RemovePlayerDisplayFlairFinal(p, flair); + //PluginMain.AppendPlayerDisplayFlairFinal(p, flair); + PluginMain.AppendPlayerDisplayFlair(mp, p); //2015.08.09. + } + String msg="§6Note: The auto-flair plugin has been reloaded. You might need to wait 10s to have your flair.§r"; //2015.08.09. + p.sendMessage(msg); //2015.08.09. + } + //String msg="§6Reloaded config file.§r"; + //SendMessage(player, msg); //2015.08.09. + } + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + if(player!=null) + player.sendMessage("§cAn error occured. See console for details.§r"); + PluginMain.LastException=e; //2015.08.09. + } + //} + //else + //player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static Player ReloadPlayer; //2015.08.09. + private static void DoAdmin(Player player, String[] args) + { //2015.08.09. + if(player==null || player.isOp() || player.getName()=="NorbiPeti") + { + //System.out.println("Args length: " + args.length); + if(args.length==1) + { + String message="§cUsage: /u admin reload|playerinfo§r"; + SendMessage(player, message); + return; + } + //args[0] is "admin" + switch(args[1].toLowerCase()) + { + case "reload": + ReloadPlayer=player; //2015.08.09. + SendMessage(player, "§6Make sure to save the current settings before you modify and reload them! Type /u admin confirm when done.§r"); + break; + case "playerinfo": + DoPlayerInfo(player, args); + break; + case "getlasterror": + DoGetLastError(player, args); + case "confirm": + if(ReloadPlayer==player) + DoReload(player); //2015.08.09. + else + SendMessage(player, "§cYou need to do /u admin reload first.§r"); + break; + case "save": + PluginMain.SaveFiles(); //2015.08.09. + SendMessage(player, "§6Saved files. Now you can edit them and reload if you want.§r"); + break; + default: + String message="§cUsage: /u admin reload|playerinfo|getlasterror§r"; + SendMessage(player, message); + return; + } + } + else + player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static void DoPlayerInfo(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "playerinfo" + if(args.length==2) + { + String message="§cUsage: /u admin playerinfo §r"; + SendMessage(player, message); + return; + } + if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2])) + { + String message="§cPlayer not found: "+args[2]+"§r"; + SendMessage(player, message); + return; + } + MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]); + SendMessage(player, "Player name: "+p.PlayerName); + SendMessage(player, "User flair: "+p.Flair); + SendMessage(player, "Username: "+p.UserName); + SendMessage(player, "Flair accepted: "+p.AcceptedFlair); + SendMessage(player, "Flair ignored: "+p.IgnoredFlair); + } + private static void SendMessage(Player player, String message) + { //2015.08.09. + if(player==null) + System.out.println(message); + else + player.sendMessage(message); + } + private static void DoGetLastError(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "getlasterror" + if(PluginMain.LastException!=null) + { + SendMessage(player, "Last error:"); + SendMessage(player, PluginMain.LastException.toString()); + PluginMain.LastException=null; + } + else + SendMessage(player, "There were no exceptions."); + } + private static void SetPlayerFlair(Player player, Player targetplayer, String flair) + { //2015.08.09. + flair=flair.replace('&', '§'); + MaybeOfflinePlayer.AddPlayerIfNeeded(player.getName()).Flair=flair; + if(!PluginMain.RemoveLineFromFile("customflairs.txt", targetplayer.getName())) + { + SendMessage(player, "§cError removing previous custom flair!§r"); + return; + } + File file=new File("customflairs.txt"); + try { + BufferedWriter bw; + bw = new BufferedWriter(new FileWriter(file, true)); + bw.write(targetplayer.getName()+"\n"); + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + PluginMain.LastException=e; //2015.08.09. + } + SendMessage(player, "§6The flair has been set. Player: "+targetplayer.getName()+" Flair: "+flair+"§r"); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/cf/10d8879fde3e001517108d149b613203 b/.metadata/.plugins/org.eclipse.core.resources/.history/cf/10d8879fde3e001517108d149b613203 new file mode 100644 index 0000000..f0d5af2 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/cf/10d8879fde3e001517108d149b613203 @@ -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.WorldCoord; + +public class PluginMain extends JavaPlugin +{ //Translated to Java: 2015.07.15. + //A user, which flair isn't obtainable: + //https://www.reddit.com/r/thebutton/comments/31c32v/i_pressed_the_button_without_really_thinking/ + private static PluginMain Instance; + // Fired when plugin is first enabled + @Override + public void onEnable() + { + System.out.println("The Button Auto-flair Plugin by NorbiPeti (:P)"); + getServer().getPluginManager().registerEvents(new PlayerListener(), this); + this.getCommand("u").setExecutor(new Commands()); + this.getCommand("u").setUsage(this.getCommand("u").getUsage().replace('&', '§')); + Instance=this; //2015.08.08. + LoadFiles(false); //2015.08.09. + Runnable r=new Runnable(){public void run(){ThreadMethod();}}; + Thread t=new Thread(r); + t.start(); + } + Boolean stop=false; + // Fired when plugin is disabled + @Override + public void onDisable() + { + SaveFiles(); //2015.08.09. + stop=true; + } + + public void ThreadMethod() //<-- 2015.07.16. + { + while(!stop) + { + try + { + String body=DownloadString("https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/autoflair_system_comment_your_minecraft_name_and/.json?limit=1000"); + JSONArray json=new JSONArray(body).getJSONObject(1).getJSONObject("data").getJSONArray("children"); + for(Object obj : json) + { + JSONObject item = (JSONObject)obj; + String author=item.getJSONObject("data").getString("author"); + String ign=item.getJSONObject("data").getString("body"); + int start = ign.indexOf("IGN:") + "IGN:".length(); + if(start==-1) + continue; //2015.08.09. + int end = ign.indexOf(' ', start); + if (end == -1 || end == start) + end=ign.indexOf('\n', start); //2015.07.15. + if (end == -1 || end == start) + ign = ign.substring(start); + else + ign = ign.substring(start, end); + ign = ign.trim(); + if(HasIGFlair(ign)) + continue; + try { + Thread.sleep(10); + } catch(InterruptedException ex) { + Thread.currentThread().interrupt(); + } + String[] flairdata = DownloadString("http://karmadecay.com/thebutton-data.php?users=" + author).replace("\"", "").split(":"); + String flair; + if(flairdata.length > 1) //2015.07.15. + flair = flairdata[1]; + else + flair=""; + if (flair != "-1") + flair = flair + "s"; + else + flair = "non-presser"; + String flairclass; + if(flairdata.length>2) + flairclass = flairdata[2]; + else + flairclass="unknown"; + SetFlair(ign, flair, flairclass, author); + } + Thread.sleep(10000); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + } + + public static Exception LastException; //2015.08.09. + + public String DownloadString(String urlstr) throws MalformedURLException, IOException + { + URL url = new URL(urlstr); + URLConnection con = url.openConnection(); + con.setRequestProperty("User-Agent", "TheButtonAutoFlair"); + InputStream in = con.getInputStream(); + String encoding = con.getContentEncoding(); + encoding = encoding == null ? "UTF-8" : encoding; + String body = IOUtils.toString(in, encoding); + in.close(); + return body; + } + + public static Map TownColors=new HashMap(); //2015.07.20. + public Boolean HasIGFlair(String playername) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + return p.Flair!=null; //2015.08.08. + } + + public void SetFlair(String playername, String text, String flairclass, String username) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + String finalflair; + p.FlairDecided=true; + switch(flairclass) + { + case "press-1": + finalflair="§c("+text+")§r"; + break; + case "press-2": + finalflair="§6("+text+")§r"; + break; + case "press-3": + finalflair="§e("+text+")§r"; + break; + case "press-4": + finalflair="§a("+text+")§r"; + break; + case "press-5": + finalflair="§9("+text+")§r"; + break; + 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; + case "undecided": //2015.08.09. + p.FlairDecided=false; + finalflair=""; + break; + default: + finalflair=""; + break; + } + if(finalflair.length()==0) //<-- 2015.07.20. + return; + p.Flair=finalflair; //2015.08.08. + p.UserName=username; //2015.08.08. + System.out.println("Added new flair to "+playername+": "+finalflair); + for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08. + { + if(player.getName().equals(playername)) + { + //AppendPlayerDisplayFlair(player, username, finalflair); + AppendPlayerDisplayFlair(p, player); + break; + } + } + } + + public static String GetFlair(Player player) + { //2015.07.16. + String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08. + return flair==null ? "" : flair; + } + + //public static void AppendPlayerDisplayFlair(Player player, String username, String flair) + public static void AppendPlayerDisplayFlair(MaybeOfflinePlayer player, Player p) //<-- 2015.08.09. + { + + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).IgnoredFlair) + return; + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).AcceptedFlair) + { + AppendPlayerDisplayFlairFinal(p, player.Flair); //2015.07.20. + if(!player.FlairDecided) + p.sendMessage("§9Your flair type is unknown. Are you a non-presser or a can't press? (/u nonpresser or /u cantpress)§r"); //2015.08.09. + } + else + p.sendMessage("§9Are you Reddit user "+player.UserName+"?§r §6Type /u accept or /u ignore§r"); + } + + private static void AppendPlayerDisplayFlairFinal(Player player, String flair) + { //2015.07.20. + String color = GetColorForTown(GetPlayerTown(player)); //TO!DO: Multiple colors put on first capital letters + String[] colors = color.substring(1).split("§"); + String displayname=player.getName(); //2015.08.08. + ArrayList Positions=new ArrayList<>(); + for(int i=0; i=colors.length) + { + int x=0; + for(int i=0; i GetPlayers() + { + return Instance.getServer().getOnlinePlayers(); + } + + public static void LoadFiles(boolean reload) //<-- 2015.08.09. + { + if(reload) + { //2015.08.09. + System.out.println("Auto-flair plugin cleanup for reloading..."); + MaybeOfflinePlayer.AllPlayers.clear(); + TownColors.clear(); + } + System.out.println("Loading files for auto-flair plugin..."); //2015.08.09. + try { + File file=new File("flairsaccepted.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + //System.out.println("Name: " + name); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("flairsignored.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsignored.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("autoflairconfig.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + TownColors.put(s[0], s[1]); + } + br.close(); + } + file=new File("customflairs.txt"); //2015.08.09. + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + MaybeOfflinePlayer.AddPlayerIfNeeded(s[0]).Flair=s[1]; //2015.08.09. + } + br.close(); + } + //throw new IOException("Test"); //2015.08.09. + System.out.println("Auto-flair plugin loaded files!"); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + public static void SaveFiles() //<-- 2015.08.09. + { + try + { + FileWriter fw; + fw = new FileWriter("flairsaccepted.txt"); + fw.close(); + fw = new FileWriter("flairsignored.txt"); + fw.close(); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + try { + File file=new File("flairsaccepted.txt"); + BufferedWriter bw=new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.AcceptedFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + file=new File("flairsignored.txt"); + bw = new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.IgnoredFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + public static void SetPlayerFlair(Player player, String flair) + { //2015.08.09. + flair=flair.replace('&', '§'); + MaybeOfflinePlayer.AddPlayerIfNeeded(player.getName()).Flair=flair; + File file=new File("customflairs.txt"); + try { + BufferedWriter bw; + bw = new BufferedWriter(new FileWriter(file, true)); + bw.write(player.getName()+"\n"); + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + public static bool RemoveLineFromFile(String file) + { + File inputFile = new File(file); + File tempFile = new File("_temp.txt"); + + try { + BufferedReader reader = new BufferedReader(new FileReader(inputFile)); + BufferedWriter writer = new BufferedWriter(new FileWriter(tempFile)); + + String lineToRemove = "bbb"; + String currentLine; + + while((currentLine = reader.readLine()) != null) { + // trim newline when comparing with lineToRemove + String trimmedLine = currentLine.trim(); + if(trimmedLine.equals(lineToRemove)) continue; + writer.write(currentLine + System.getProperty("line.separator")); + } + writer.close(); + reader.close(); + boolean successful = tempFile.renameTo(inputFile); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/cf/509e01bffe3d00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/cf/509e01bffe3d00151c31fb33fff4337f deleted file mode 100644 index 6224020..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/cf/509e01bffe3d00151c31fb33fff4337f +++ /dev/null @@ -1,122 +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()); - 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/d2/204ad69bd03e001518fa86d7ae2a1cf8 b/.metadata/.plugins/org.eclipse.core.resources/.history/d2/204ad69bd03e001518fa86d7ae2a1cf8 new file mode 100644 index 0000000..331b6b5 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/d2/204ad69bd03e001518fa86d7ae2a1cf8 @@ -0,0 +1,206 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; + +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class Commands implements CommandExecutor { + // This method is called, when somebody uses our command + @Override + public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { + if (sender instanceof Player) { + Player player = (Player) sender; + if(args.length<1) + return false; + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. + //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) + if(p.Flair==null) + { + player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); + return true; + } + switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. + { + case "accept": + { + if(p.IgnoredFlair) + p.IgnoredFlair=false; //2015.08.08. + if(!p.AcceptedFlair) + { + String flair=p.Flair; //2015.08.08. + //PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + PluginMain.AppendPlayerDisplayFlair(p, player); + p.AcceptedFlair=true; //2015.08.08. + player.sendMessage("§6Your flair has been set:§r "+flair); + } + else + player.sendMessage("§cYou already have this user's flair.§r"); + break; + } + case "ignore": + { + if(p.AcceptedFlair) + p.AcceptedFlair=false; //2015.08.08. + if(!p.IgnoredFlair) + { + p.IgnoredFlair=true; + String flair=p.Flair; //2015.08.08. + PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. + player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); + } + else + player.sendMessage("§cYou already ignored this request.§r"); + break; + } + /*case "reload": //2015.07.20. + DoReload(player); + break;*/ + case "admin": //2015.08.09. + DoAdmin(player, args); + break; + case "nonpresser": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + w + break; + case "cantpress": //2015.08.09. + break; + default: + return false; + } + return true; + } + /*if(args[0].toLowerCase()=="reload") + DoReload(null); //2015.07.20.*/ + else if(args.length>0 && args[0].toLowerCase().equals("admin")) //2015.08.09. + { + DoAdmin(null, args); //2015.08.09. + return true; //2015.08.09. + } + return false; + } + private static void DoReload(Player player) + { //2015.07.20. + //if(player==null || player.isOp() || player.getName()=="NorbiPeti") + //{ + try + { + File file=new File("autoflairconfig.txt"); + if(file.exists()) + { + PluginMain.TownColors.clear(); + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + PluginMain.TownColors.put(s[0], s[1]); + } + br.close(); + for(Player p : PluginMain.GetPlayers()) + { + MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName()); + if(mp.Flair!=null) + { + String flair=mp.Flair; + PluginMain.RemovePlayerDisplayFlairFinal(p, flair); + //PluginMain.AppendPlayerDisplayFlairFinal(p, flair); + PluginMain.AppendPlayerDisplayFlair(mp, p); //2015.08.09. + } + } + String msg="§6Reloaded config file.§r"; + SendMessage(player, msg); //2015.08.09. + } + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + if(player!=null) + player.sendMessage("§cAn error occured. See console for details.§r"); + PluginMain.LastException=e; //2015.08.09. + } + //} + //else + //player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static void DoAdmin(Player player, String[] args) + { //2015.08.09. + if(player==null || player.isOp() || player.getName()=="NorbiPeti") + { + //System.out.println("Args length: " + args.length); + if(args.length==1) + { + String message="§cUsage: /u admin reload|playerinfo§r"; + SendMessage(player, message); + return; + } + //args[0] is "admin" + switch(args[1].toLowerCase()) + { + case "reload": + DoReload(player); + break; + case "playerinfo": + DoPlayerInfo(player, args); + break; + case "getlasterror": + DoGetLastError(player, args); + default: + String message="§cUsage: /u admin reload|playerinfo§r"; + SendMessage(player, message); + return; + } + } + else + player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static void DoPlayerInfo(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "playerinfo" + if(args.length==2) + { + String message="§cUsage: /u admin playerinfo §r"; + SendMessage(player, message); + return; + } + if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2])) + { + String message="§cPlayer not found: "+args[2]+"§r"; + SendMessage(player, message); + return; + } + MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]); + SendMessage(player, "Player name: "+p.PlayerName); + SendMessage(player, "User flair: "+p.Flair); + SendMessage(player, "Username: "+p.UserName); + SendMessage(player, "Flair accepted: "+p.AcceptedFlair); + SendMessage(player, "Flair ignored: "+p.IgnoredFlair); + } + private static void SendMessage(Player player, String message) + { //2015.08.09. + if(player==null) + System.out.println(message); + else + player.sendMessage(message); + } + private static void DoGetLastError(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "getlasterror" + if(PluginMain.LastException!=null) + { + SendMessage(player, "Last error:"); + SendMessage(player, PluginMain.LastException.toString()); + PluginMain.LastException=null; + } + else + SendMessage(player, "There were no exceptions."); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/d2/d0f664fd013e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/d2/d0f664fd013e00151c31fb33fff4337f deleted file mode 100644 index b72a527..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/d2/d0f664fd013e00151c31fb33fff4337f +++ /dev/null @@ -1,125 +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; - 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/d3/00e70d14e03e001517108d149b613203 b/.metadata/.plugins/org.eclipse.core.resources/.history/d3/00e70d14e03e001517108d149b613203 new file mode 100644 index 0000000..0ccc23b --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/d3/00e70d14e03e001517108d149b613203 @@ -0,0 +1,260 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +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; + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. + //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) + if(p.Flair==null) + { + player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); + return true; + } + switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. + { + case "accept": + { + if(p.IgnoredFlair) + p.IgnoredFlair=false; //2015.08.08. + if(!p.AcceptedFlair) + { + String flair=p.Flair; //2015.08.08. + //PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + PluginMain.AppendPlayerDisplayFlair(p, player); + p.AcceptedFlair=true; //2015.08.08. + player.sendMessage("§6Your flair has been set:§r "+flair); + } + else + player.sendMessage("§cYou already have this user's flair.§r"); + break; + } + case "ignore": + { + if(p.AcceptedFlair) + p.AcceptedFlair=false; //2015.08.08. + if(!p.IgnoredFlair) + { + p.IgnoredFlair=true; + String flair=p.Flair; //2015.08.08. + PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. + player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); + } + else + player.sendMessage("§cYou already ignored this request.§r"); + break; + } + /*case "reload": //2015.07.20. + DoReload(player); + break;*/ + case "admin": //2015.08.09. + DoAdmin(player, args); + break; + case "nonpresser": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§7(non-pr.)§r"; + break; + case "cantpress": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§r(can't press)§r"; + break; + default: + return false; + } + return true; + } + /*if(args[0].toLowerCase()=="reload") + DoReload(null); //2015.07.20.*/ + else if(args.length>0 && args[0].toLowerCase().equals("admin")) //2015.08.09. + { + DoAdmin(null, args); //2015.08.09. + return true; //2015.08.09. + } + return false; + } + private static void DoReload(Player player) + { //2015.07.20. + //if(player==null || player.isOp() || player.getName()=="NorbiPeti") + //{ + try + { + File file=new File("autoflairconfig.txt"); + if(file.exists()) + { + PluginMain.LoadFiles(true); //2015.08.09. + for(Player p : PluginMain.GetPlayers()) + { + MaybeOfflinePlayer mp = MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName()); + if(mp.Flair!=null) + { + String flair=mp.Flair; + PluginMain.RemovePlayerDisplayFlairFinal(p, flair); + //PluginMain.AppendPlayerDisplayFlairFinal(p, flair); + PluginMain.AppendPlayerDisplayFlair(mp, p); //2015.08.09. + } + String msg="§6Note: The auto-flair plugin has been reloaded. You might need to wait 10s to have your flair.§r"; //2015.08.09. + p.sendMessage(msg); //2015.08.09. + } + //String msg="§6Reloaded config file.§r"; + //SendMessage(player, msg); //2015.08.09. + } + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + if(player!=null) + player.sendMessage("§cAn error occured. See console for details.§r"); + PluginMain.LastException=e; //2015.08.09. + } + //} + //else + //player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static Player ReloadPlayer; //2015.08.09. + private static void DoAdmin(Player player, String[] args) + { //2015.08.09. + if(player==null || player.isOp() || player.getName()=="NorbiPeti") + { + //System.out.println("Args length: " + args.length); + if(args.length==1) + { + String message="§cUsage: /u admin reload|playerinfo§r"; + SendMessage(player, message); + return; + } + //args[0] is "admin" + switch(args[1].toLowerCase()) + { + case "reload": + ReloadPlayer=player; //2015.08.09. + SendMessage(player, "§6Make sure to save the current settings before you modify and reload them! Type /u admin confirm when done.§r"); + break; + case "playerinfo": + DoPlayerInfo(player, args); + break; + case "getlasterror": + DoGetLastError(player, args); + case "confirm": + if(ReloadPlayer==player) + DoReload(player); //2015.08.09. + else + SendMessage(player, "§cYou need to do /u admin reload first.§r"); + break; + case "save": + PluginMain.SaveFiles(); //2015.08.09. + SendMessage(player, "§6Saved files. Now you can edit them and reload if you want.§r"); + break; + case "setflair": + + break; + default: + String message="§cUsage: /u admin reload|playerinfo|getlasterror|save§r"; + SendMessage(player, message); + return; + } + } + else + player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static void DoPlayerInfo(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "playerinfo" + if(args.length==2) + { + String message="§cUsage: /u admin playerinfo §r"; + SendMessage(player, message); + return; + } + if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2])) + { + String message="§cPlayer not found: "+args[2]+"§r"; + SendMessage(player, message); + return; + } + MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]); + SendMessage(player, "Player name: "+p.PlayerName); + SendMessage(player, "User flair: "+p.Flair); + SendMessage(player, "Username: "+p.UserName); + SendMessage(player, "Flair accepted: "+p.AcceptedFlair); + SendMessage(player, "Flair ignored: "+p.IgnoredFlair); + } + private static void SendMessage(Player player, String message) + { //2015.08.09. + if(player==null) + System.out.println(message); + else + player.sendMessage(message); + } + private static void DoGetLastError(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "getlasterror" + if(PluginMain.LastException!=null) + { + SendMessage(player, "Last error:"); + SendMessage(player, PluginMain.LastException.toString()); + PluginMain.LastException=null; + } + else + SendMessage(player, "There were no exceptions."); + } + private static void SetPlayerFlair(Player player, Player targetplayer, String flair) + { //2015.08.09. + flair=flair.replace('&', '§'); + MaybeOfflinePlayer.AddPlayerIfNeeded(player.getName()).Flair=flair; + if(!PluginMain.RemoveLineFromFile("customflairs.txt", targetplayer.getName())) + { + SendMessage(player, "§cError removing previous custom flair!§r"); + return; + } + File file=new File("customflairs.txt"); + try { + BufferedWriter bw; + bw = new BufferedWriter(new FileWriter(file, true)); + bw.write(targetplayer.getName()+"\n"); + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + PluginMain.LastException=e; //2015.08.09. + } + SendMessage(player, "§6The flair has been set. Player: "+targetplayer.getName()+" Flair: "+flair+"§r"); + } + private static void DoSetFlair(Player player, String args) + { + //args[0] is "admin" - args[1] is "setflair" + + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/d5/008e353cdf3e001517108d149b613203 b/.metadata/.plugins/org.eclipse.core.resources/.history/d5/008e353cdf3e001517108d149b613203 new file mode 100644 index 0000000..6b55eb2 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/d5/008e353cdf3e001517108d149b613203 @@ -0,0 +1,251 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +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; + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. + //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) + if(p.Flair==null) + { + player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); + return true; + } + switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. + { + case "accept": + { + if(p.IgnoredFlair) + p.IgnoredFlair=false; //2015.08.08. + if(!p.AcceptedFlair) + { + String flair=p.Flair; //2015.08.08. + //PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + PluginMain.AppendPlayerDisplayFlair(p, player); + p.AcceptedFlair=true; //2015.08.08. + player.sendMessage("§6Your flair has been set:§r "+flair); + } + else + player.sendMessage("§cYou already have this user's flair.§r"); + break; + } + case "ignore": + { + if(p.AcceptedFlair) + p.AcceptedFlair=false; //2015.08.08. + if(!p.IgnoredFlair) + { + p.IgnoredFlair=true; + String flair=p.Flair; //2015.08.08. + PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. + player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); + } + else + player.sendMessage("§cYou already ignored this request.§r"); + break; + } + /*case "reload": //2015.07.20. + DoReload(player); + break;*/ + case "admin": //2015.08.09. + DoAdmin(player, args); + break; + case "nonpresser": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§7(non-pr.)§r"; + break; + case "cantpress": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§r(can't press)§r"; + break; + default: + return false; + } + return true; + } + /*if(args[0].toLowerCase()=="reload") + DoReload(null); //2015.07.20.*/ + else if(args.length>0 && args[0].toLowerCase().equals("admin")) //2015.08.09. + { + DoAdmin(null, args); //2015.08.09. + return true; //2015.08.09. + } + return false; + } + private static void DoReload(Player player) + { //2015.07.20. + //if(player==null || player.isOp() || player.getName()=="NorbiPeti") + //{ + try + { + File file=new File("autoflairconfig.txt"); + if(file.exists()) + { + PluginMain.LoadFiles(true); //2015.08.09. + for(Player p : PluginMain.GetPlayers()) + { + MaybeOfflinePlayer mp = MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName()); + if(mp.Flair!=null) + { + String flair=mp.Flair; + PluginMain.RemovePlayerDisplayFlairFinal(p, flair); + //PluginMain.AppendPlayerDisplayFlairFinal(p, flair); + PluginMain.AppendPlayerDisplayFlair(mp, p); //2015.08.09. + } + String msg="§6Note: The auto-flair plugin has been reloaded. You might need to wait 10s to have your flair.§r"; //2015.08.09. + p.sendMessage(msg); //2015.08.09. + } + //String msg="§6Reloaded config file.§r"; + //SendMessage(player, msg); //2015.08.09. + } + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + if(player!=null) + player.sendMessage("§cAn error occured. See console for details.§r"); + PluginMain.LastException=e; //2015.08.09. + } + //} + //else + //player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static Player ReloadPlayer; //2015.08.09. + private static void DoAdmin(Player player, String[] args) + { //2015.08.09. + if(player==null || player.isOp() || player.getName()=="NorbiPeti") + { + //System.out.println("Args length: " + args.length); + if(args.length==1) + { + String message="§cUsage: /u admin reload|playerinfo§r"; + SendMessage(player, message); + return; + } + //args[0] is "admin" + switch(args[1].toLowerCase()) + { + case "reload": + ReloadPlayer=player; //2015.08.09. + SendMessage(player, "§6Make sure to save the current settings before you modify and reload them! Type /u admin confirm when done.§r"); + break; + case "playerinfo": + DoPlayerInfo(player, args); + break; + case "getlasterror": + DoGetLastError(player, args); + case "confirm": + if(ReloadPlayer==player) + DoReload(player); //2015.08.09. + else + SendMessage(player, "§cYou need to do /u admin reload first.§r"); + break; + case "save": + PluginMain.SaveFiles(); //2015.08.09. + SendMessage(player, "§6Saved files. Now you can edit them and reload if you want.§r"); + break; + default: + String message="§cUsage: /u admin reload|playerinfo|getlasterror§r"; + SendMessage(player, message); + return; + } + } + else + player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static void DoPlayerInfo(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "playerinfo" + if(args.length==2) + { + String message="§cUsage: /u admin playerinfo §r"; + SendMessage(player, message); + return; + } + if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2])) + { + String message="§cPlayer not found: "+args[2]+"§r"; + SendMessage(player, message); + return; + } + MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]); + SendMessage(player, "Player name: "+p.PlayerName); + SendMessage(player, "User flair: "+p.Flair); + SendMessage(player, "Username: "+p.UserName); + SendMessage(player, "Flair accepted: "+p.AcceptedFlair); + SendMessage(player, "Flair ignored: "+p.IgnoredFlair); + } + private static void SendMessage(Player player, String message) + { //2015.08.09. + if(player==null) + System.out.println(message); + else + player.sendMessage(message); + } + private static void DoGetLastError(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "getlasterror" + if(PluginMain.LastException!=null) + { + SendMessage(player, "Last error:"); + SendMessage(player, PluginMain.LastException.toString()); + PluginMain.LastException=null; + } + else + SendMessage(player, "There were no exceptions."); + } + private static void SetPlayerFlair(Player player, String flair) + { //2015.08.09. + flair=flair.replace('&', '§'); + MaybeOfflinePlayer.AddPlayerIfNeeded(player.getName()).Flair=flair; + if(!PluginMain.RemoveLineFromFile("customflairs.txt")) + { + SendMessage(player, "Error removing previous custom flair!"); + return; + } + File file=new File("customflairs.txt"); + try { + BufferedWriter bw; + bw = new BufferedWriter(new FileWriter(file, true)); + bw.write(player.getName()+"\n"); + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + PluginMain.LastException=e; //2015.08.09. + } + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/d5/50049d01883e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/d5/50049d01883e00151ce8ff6d4f74dabd deleted file mode 100644 index ef471ff..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/d5/50049d01883e00151ce8ff6d4f74dabd +++ /dev/null @@ -1,162 +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; - MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. - //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - if(p.Flair==null) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. - { - case "accept": - { - if(p.IgnoredFlair) - p.IgnoredFlair=false; //2015.08.08. - if(!p.AcceptedFlair) - { - String flair=p.Flair; //2015.08.08. - PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. - p.AcceptedFlair=true; //2015.08.08. - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("§cYou already have this user's flair.§r"); - break; - } - case "ignore": - { - if(p.AcceptedFlair) - p.AcceptedFlair=false; //2015.08.08. - if(!p.IgnoredFlair) - { - p.IgnoredFlair=true; - String flair=p.Flair; //2015.08.08. - PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. - player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); - } - else - player.sendMessage("§cYou already ignored this request.§r"); - break; - } - /*case "reload": //2015.07.20. - DoReload(player); - break;*/ - case "admin": //2015.08.09. - DoAdmin(player, args); - break; - default: - return false; - } - return true; - } - - /*if(args[0].toLowerCase()=="reload") - DoReload(null); //2015.07.20.*/ - else if(args[0].toLowerCase()=="admin") - DoAdmin(null, args); //2015.08.09. - return false; - } - private static void DoReload(Player player) - { //2015.07.20. - //if(player==null || player.isOp() || player.getName()=="NorbiPeti") - //{ - try - { - File file=new File("autoflairconfig.txt"); - if(file.exists()) - { - PluginMain.TownColors.clear(); - BufferedReader br=new BufferedReader(new FileReader(file)); - String line; - while((line=br.readLine())!=null) - { - String[] s=line.split(" "); - PluginMain.TownColors.put(s[0], s[1]); - } - br.close(); - for(Player p : PluginMain.GetPlayers()) - { - MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName()); - if(mp.Flair!=null) - { - String flair=mp.Flair; - PluginMain.RemovePlayerDisplayFlairFinal(p, flair); - PluginMain.AppendPlayerDisplayFlairFinal(p, flair); - } - } - String msg="§6Reloaded config file.§r"; - if(player!=null) - player.sendMessage(msg); - else - System.out.println(msg); - } - } - catch(Exception e) - { - System.out.println("Error!\n"+e); - if(player!=null) - player.sendMessage("§cAn error occured. See console for details.§r"); - } - //} - //else - //player.sendMessage("§cYou need to be OP to use this command.§r"); - } - private static void DoAdmin(Player player, String[] args) - { //2015.08.09. - if(player==null || player.isOp() || player.getName()=="NorbiPeti") - { - if(args.length==1) - { - String message="§cUsage: /u admin playerinfo §r"; - if(player==null) - System.out.println(message); - else - player.sendMessage(message); - return; - } - //args[0] is "admin" - switch(args[1].toLowerCase()) - { - case "reload": - DoReload(player); - break; - case "playerinfo": - DoPlayerInfo(player, args); - break; - } - } - else - player.sendMessage("§cYou need to be OP to use this command.§r"); - } - private static void DoPlayerInfo(Player player, String[] args) - { //2015.08.09. - //args[0] is "admin" - args[1] is "playerinfo" - if(args.length==2) - { - String message="§cUsage: /u admin playerinfo §r"; - if(player==null) - System.out.println(message); - else - player.sendMessage(message); - return; - } - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/d5/9032a867e43e001517108d149b613203 b/.metadata/.plugins/org.eclipse.core.resources/.history/d5/9032a867e43e001517108d149b613203 new file mode 100644 index 0000000..0ed8dd4 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/d5/9032a867e43e001517108d149b613203 @@ -0,0 +1,263 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedWriter; +import java.io.File; +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; + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. + //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) + if(p.Flair==null) + { + player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); + return true; + } + switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. + { + case "accept": + { + if(p.IgnoredFlair) + p.IgnoredFlair=false; //2015.08.08. + if(!p.AcceptedFlair) + { + String flair=p.Flair; //2015.08.08. + //PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + PluginMain.AppendPlayerDisplayFlair(p, player); + p.AcceptedFlair=true; //2015.08.08. + player.sendMessage("§6Your flair has been set:§r "+flair); + } + else + player.sendMessage("§cYou already have this user's flair.§r"); + break; + } + case "ignore": + { + if(p.AcceptedFlair) + p.AcceptedFlair=false; //2015.08.08. + if(!p.IgnoredFlair) + { + p.IgnoredFlair=true; + String flair=p.Flair; //2015.08.08. + //PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. + player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); + } + else + player.sendMessage("§cYou already ignored this request.§r"); + break; + } + /*case "reload": //2015.07.20. + DoReload(player); + break;*/ + case "admin": //2015.08.09. + DoAdmin(player, args); + break; + case "nonpresser": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§7(non-pr.)§r"; + break; + case "cantpress": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§r(can't press)§r"; + break; + default: + return false; + } + return true; + } + /*if(args[0].toLowerCase()=="reload") + DoReload(null); //2015.07.20.*/ + else if(args.length>0 && args[0].toLowerCase().equals("admin")) //2015.08.09. + { + DoAdmin(null, args); //2015.08.09. + return true; //2015.08.09. + } + return false; + } + private static void DoReload(Player player) + { //2015.07.20. + //if(player==null || player.isOp() || player.getName()=="NorbiPeti") + //{ + try + { + File file=new File("autoflairconfig.txt"); + if(file.exists()) + { + PluginMain.LoadFiles(true); //2015.08.09. + for(Player p : PluginMain.GetPlayers()) + { + MaybeOfflinePlayer mp = MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName()); + if(mp.Flair!=null) + { + String flair=mp.Flair; + //PluginMain.RemovePlayerDisplayFlairFinal(p, flair); + //PluginMain.AppendPlayerDisplayFlairFinal(p, flair); + PluginMain.AppendPlayerDisplayFlair(mp, p); //2015.08.09. + } + String msg="§6Note: The auto-flair plugin has been reloaded. You might need to wait 10s to have your flair.§r"; //2015.08.09. + p.sendMessage(msg); //2015.08.09. + } + //String msg="§6Reloaded config file.§r"; + //SendMessage(player, msg); //2015.08.09. + } + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + if(player!=null) + player.sendMessage("§cAn error occured. See console for details.§r"); + PluginMain.LastException=e; //2015.08.09. + } + //} + //else + //player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static Player ReloadPlayer; //2015.08.09. + private static void DoAdmin(Player player, String[] args) + { //2015.08.09. + if(player==null || player.isOp() || player.getName()=="NorbiPeti") + { + //System.out.println("Args length: " + args.length); + if(args.length==1) + { + String message="§cUsage: /u admin reload|playerinfo§r"; + SendMessage(player, message); + return; + } + //args[0] is "admin" + switch(args[1].toLowerCase()) + { + case "reload": + ReloadPlayer=player; //2015.08.09. + SendMessage(player, "§6Make sure to save the current settings before you modify and reload them! Type /u admin confirm when done.§r"); + break; + case "playerinfo": + DoPlayerInfo(player, args); + break; + case "getlasterror": + DoGetLastError(player, args); + case "confirm": + if(ReloadPlayer==player) + DoReload(player); //2015.08.09. + else + SendMessage(player, "§cYou need to do /u admin reload first.§r"); + break; + case "save": + PluginMain.SaveFiles(); //2015.08.09. + SendMessage(player, "§6Saved files. Now you can edit them and reload if you want.§r"); + break; + case "setflair": + DoSetFlair(player, args); + break; + default: + String message="§cUsage: /u admin reload|playerinfo|getlasterror|save|setflair§r"; + SendMessage(player, message); + return; + } + } + else + player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static void DoPlayerInfo(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "playerinfo" + if(args.length==2) + { + String message="§cUsage: /u admin playerinfo §r"; + SendMessage(player, message); + return; + } + if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2])) + { + String message="§cPlayer not found: "+args[2]+"§r"; + SendMessage(player, message); + return; + } + MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]); + SendMessage(player, "Player name: "+p.PlayerName); + SendMessage(player, "User flair: "+p.Flair); + SendMessage(player, "Username: "+p.UserName); + SendMessage(player, "Flair accepted: "+p.AcceptedFlair); + SendMessage(player, "Flair ignored: "+p.IgnoredFlair); + } + private static void SendMessage(Player player, String message) + { //2015.08.09. + if(player==null) + System.out.println(message); + else + player.sendMessage(message); + } + private static void DoGetLastError(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "getlasterror" + if(PluginMain.LastException!=null) + { + SendMessage(player, "Last error:"); + SendMessage(player, PluginMain.LastException.toString()); + PluginMain.LastException=null; + } + else + SendMessage(player, "There were no exceptions."); + } + private static void SetPlayerFlair(Player player, MaybeOfflinePlayer targetplayer, String flair) + { //2015.08.09. + flair=flair.replace('&', '§'); + targetplayer.Flair=flair; + if(!PluginMain.RemoveLineFromFile("customflairs.txt", targetplayer.PlayerName)) + { + SendMessage(player, "§cError removing previous custom flair!§r"); + return; + } + File file=new File("customflairs.txt"); + try { + BufferedWriter bw; + bw = new BufferedWriter(new FileWriter(file, true)); + bw.write(targetplayer.PlayerName+"\n"); + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + PluginMain.LastException=e; //2015.08.09. + } + SendMessage(player, "§6The flair has been set. Player: "+targetplayer.PlayerName+" Flair: "+flair+"§r"); + } + private static void DoSetFlair(Player player, String[] args) + { + //args[0] is "admin" - args[1] is "setflair" + if(args.length<4) + { + SendMessage(player, "§cUsage: /u admin setflair "); + return; + } + SetPlayerFlair(player, MaybeOfflinePlayer.AddPlayerIfNeeded(args[2]), args[3]); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/d6/0038bc1adf3e001517108d149b613203 b/.metadata/.plugins/org.eclipse.core.resources/.history/d6/0038bc1adf3e001517108d149b613203 new file mode 100644 index 0000000..eac777b --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/d6/0038bc1adf3e001517108d149b613203 @@ -0,0 +1,250 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +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; + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. + //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) + if(p.Flair==null) + { + player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); + return true; + } + switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. + { + case "accept": + { + if(p.IgnoredFlair) + p.IgnoredFlair=false; //2015.08.08. + if(!p.AcceptedFlair) + { + String flair=p.Flair; //2015.08.08. + //PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + PluginMain.AppendPlayerDisplayFlair(p, player); + p.AcceptedFlair=true; //2015.08.08. + player.sendMessage("§6Your flair has been set:§r "+flair); + } + else + player.sendMessage("§cYou already have this user's flair.§r"); + break; + } + case "ignore": + { + if(p.AcceptedFlair) + p.AcceptedFlair=false; //2015.08.08. + if(!p.IgnoredFlair) + { + p.IgnoredFlair=true; + String flair=p.Flair; //2015.08.08. + PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. + player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); + } + else + player.sendMessage("§cYou already ignored this request.§r"); + break; + } + /*case "reload": //2015.07.20. + DoReload(player); + break;*/ + case "admin": //2015.08.09. + DoAdmin(player, args); + break; + case "nonpresser": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§7(non-pr.)§r"; + break; + case "cantpress": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§r(can't press)§r"; + break; + default: + return false; + } + return true; + } + /*if(args[0].toLowerCase()=="reload") + DoReload(null); //2015.07.20.*/ + else if(args.length>0 && args[0].toLowerCase().equals("admin")) //2015.08.09. + { + DoAdmin(null, args); //2015.08.09. + return true; //2015.08.09. + } + return false; + } + private static void DoReload(Player player) + { //2015.07.20. + //if(player==null || player.isOp() || player.getName()=="NorbiPeti") + //{ + try + { + File file=new File("autoflairconfig.txt"); + if(file.exists()) + { + PluginMain.LoadFiles(true); //2015.08.09. + for(Player p : PluginMain.GetPlayers()) + { + MaybeOfflinePlayer mp = MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName()); + if(mp.Flair!=null) + { + String flair=mp.Flair; + PluginMain.RemovePlayerDisplayFlairFinal(p, flair); + //PluginMain.AppendPlayerDisplayFlairFinal(p, flair); + PluginMain.AppendPlayerDisplayFlair(mp, p); //2015.08.09. + } + String msg="§6Note: The auto-flair plugin has been reloaded. You might need to wait 10s to have your flair.§r"; //2015.08.09. + p.sendMessage(msg); //2015.08.09. + } + //String msg="§6Reloaded config file.§r"; + //SendMessage(player, msg); //2015.08.09. + } + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + if(player!=null) + player.sendMessage("§cAn error occured. See console for details.§r"); + PluginMain.LastException=e; //2015.08.09. + } + //} + //else + //player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static Player ReloadPlayer; //2015.08.09. + private static void DoAdmin(Player player, String[] args) + { //2015.08.09. + if(player==null || player.isOp() || player.getName()=="NorbiPeti") + { + //System.out.println("Args length: " + args.length); + if(args.length==1) + { + String message="§cUsage: /u admin reload|playerinfo§r"; + SendMessage(player, message); + return; + } + //args[0] is "admin" + switch(args[1].toLowerCase()) + { + case "reload": + ReloadPlayer=player; //2015.08.09. + SendMessage(player, "§6Make sure to save the current settings before you modify and reload them! Type /u admin confirm when done.§r"); + break; + case "playerinfo": + DoPlayerInfo(player, args); + break; + case "getlasterror": + DoGetLastError(player, args); + case "confirm": + if(ReloadPlayer==player) + DoReload(player); //2015.08.09. + else + SendMessage(player, "§cYou need to do /u admin reload first.§r"); + break; + case "save": + PluginMain.SaveFiles(); //2015.08.09. + SendMessage(player, "§6Saved files. Now you can edit them and reload if you want.§r"); + break; + default: + String message="§cUsage: /u admin reload|playerinfo|getlasterror§r"; + SendMessage(player, message); + return; + } + } + else + player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static void DoPlayerInfo(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "playerinfo" + if(args.length==2) + { + String message="§cUsage: /u admin playerinfo §r"; + SendMessage(player, message); + return; + } + if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2])) + { + String message="§cPlayer not found: "+args[2]+"§r"; + SendMessage(player, message); + return; + } + MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]); + SendMessage(player, "Player name: "+p.PlayerName); + SendMessage(player, "User flair: "+p.Flair); + SendMessage(player, "Username: "+p.UserName); + SendMessage(player, "Flair accepted: "+p.AcceptedFlair); + SendMessage(player, "Flair ignored: "+p.IgnoredFlair); + } + private static void SendMessage(Player player, String message) + { //2015.08.09. + if(player==null) + System.out.println(message); + else + player.sendMessage(message); + } + private static void DoGetLastError(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "getlasterror" + if(PluginMain.LastException!=null) + { + SendMessage(player, "Last error:"); + SendMessage(player, PluginMain.LastException.toString()); + PluginMain.LastException=null; + } + else + SendMessage(player, "There were no exceptions."); + } + private static void SetPlayerFlair(Player player, String flair) + { //2015.08.09. + flair=flair.replace('&', '§'); + MaybeOfflinePlayer.AddPlayerIfNeeded(player.getName()).Flair=flair; + if(!PluginMain.RemoveLineFromFile("customflairs.txt")) + { + SendMessage(player, "Error removing previous custom flair!"); + } + File file=new File("customflairs.txt"); + try { + BufferedWriter bw; + bw = new BufferedWriter(new FileWriter(file, true)); + bw.write(player.getName()+"\n"); + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + PluginMain.LastException=e; //2015.08.09. + } + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/d6/80ae4e03e13e001517108d149b613203 b/.metadata/.plugins/org.eclipse.core.resources/.history/d6/80ae4e03e13e001517108d149b613203 new file mode 100644 index 0000000..9e49651 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/d6/80ae4e03e13e001517108d149b613203 @@ -0,0 +1,265 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +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; + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. + //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) + if(p.Flair==null) + { + player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); + return true; + } + switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. + { + case "accept": + { + if(p.IgnoredFlair) + p.IgnoredFlair=false; //2015.08.08. + if(!p.AcceptedFlair) + { + String flair=p.Flair; //2015.08.08. + //PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + PluginMain.AppendPlayerDisplayFlair(p, player); + p.AcceptedFlair=true; //2015.08.08. + player.sendMessage("§6Your flair has been set:§r "+flair); + } + else + player.sendMessage("§cYou already have this user's flair.§r"); + break; + } + case "ignore": + { + if(p.AcceptedFlair) + p.AcceptedFlair=false; //2015.08.08. + if(!p.IgnoredFlair) + { + p.IgnoredFlair=true; + String flair=p.Flair; //2015.08.08. + PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. + player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); + } + else + player.sendMessage("§cYou already ignored this request.§r"); + break; + } + /*case "reload": //2015.07.20. + DoReload(player); + break;*/ + case "admin": //2015.08.09. + DoAdmin(player, args); + break; + case "nonpresser": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§7(non-pr.)§r"; + break; + case "cantpress": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§r(can't press)§r"; + break; + default: + return false; + } + return true; + } + /*if(args[0].toLowerCase()=="reload") + DoReload(null); //2015.07.20.*/ + else if(args.length>0 && args[0].toLowerCase().equals("admin")) //2015.08.09. + { + DoAdmin(null, args); //2015.08.09. + return true; //2015.08.09. + } + return false; + } + private static void DoReload(Player player) + { //2015.07.20. + //if(player==null || player.isOp() || player.getName()=="NorbiPeti") + //{ + try + { + File file=new File("autoflairconfig.txt"); + if(file.exists()) + { + PluginMain.LoadFiles(true); //2015.08.09. + for(Player p : PluginMain.GetPlayers()) + { + MaybeOfflinePlayer mp = MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName()); + if(mp.Flair!=null) + { + String flair=mp.Flair; + PluginMain.RemovePlayerDisplayFlairFinal(p, flair); + //PluginMain.AppendPlayerDisplayFlairFinal(p, flair); + PluginMain.AppendPlayerDisplayFlair(mp, p); //2015.08.09. + } + String msg="§6Note: The auto-flair plugin has been reloaded. You might need to wait 10s to have your flair.§r"; //2015.08.09. + p.sendMessage(msg); //2015.08.09. + } + //String msg="§6Reloaded config file.§r"; + //SendMessage(player, msg); //2015.08.09. + } + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + if(player!=null) + player.sendMessage("§cAn error occured. See console for details.§r"); + PluginMain.LastException=e; //2015.08.09. + } + //} + //else + //player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static Player ReloadPlayer; //2015.08.09. + private static void DoAdmin(Player player, String[] args) + { //2015.08.09. + if(player==null || player.isOp() || player.getName()=="NorbiPeti") + { + //System.out.println("Args length: " + args.length); + if(args.length==1) + { + String message="§cUsage: /u admin reload|playerinfo§r"; + SendMessage(player, message); + return; + } + //args[0] is "admin" + switch(args[1].toLowerCase()) + { + case "reload": + ReloadPlayer=player; //2015.08.09. + SendMessage(player, "§6Make sure to save the current settings before you modify and reload them! Type /u admin confirm when done.§r"); + break; + case "playerinfo": + DoPlayerInfo(player, args); + break; + case "getlasterror": + DoGetLastError(player, args); + case "confirm": + if(ReloadPlayer==player) + DoReload(player); //2015.08.09. + else + SendMessage(player, "§cYou need to do /u admin reload first.§r"); + break; + case "save": + PluginMain.SaveFiles(); //2015.08.09. + SendMessage(player, "§6Saved files. Now you can edit them and reload if you want.§r"); + break; + case "setflair": + + break; + default: + String message="§cUsage: /u admin reload|playerinfo|getlasterror|save§r"; + SendMessage(player, message); + return; + } + } + else + player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static void DoPlayerInfo(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "playerinfo" + if(args.length==2) + { + String message="§cUsage: /u admin playerinfo §r"; + SendMessage(player, message); + return; + } + if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2])) + { + String message="§cPlayer not found: "+args[2]+"§r"; + SendMessage(player, message); + return; + } + MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]); + SendMessage(player, "Player name: "+p.PlayerName); + SendMessage(player, "User flair: "+p.Flair); + SendMessage(player, "Username: "+p.UserName); + SendMessage(player, "Flair accepted: "+p.AcceptedFlair); + SendMessage(player, "Flair ignored: "+p.IgnoredFlair); + } + private static void SendMessage(Player player, String message) + { //2015.08.09. + if(player==null) + System.out.println(message); + else + player.sendMessage(message); + } + private static void DoGetLastError(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "getlasterror" + if(PluginMain.LastException!=null) + { + SendMessage(player, "Last error:"); + SendMessage(player, PluginMain.LastException.toString()); + PluginMain.LastException=null; + } + else + SendMessage(player, "There were no exceptions."); + } + private static void SetPlayerFlair(Player player, MaybeOfflinePlayer targetplayer, String flair) + { //2015.08.09. + flair=flair.replace('&', '§'); + targetplayer.Flair=flair; + if(!PluginMain.RemoveLineFromFile("customflairs.txt", targetplayer.PlayerName)) + { + SendMessage(player, "§cError removing previous custom flair!§r"); + return; + } + File file=new File("customflairs.txt"); + try { + BufferedWriter bw; + bw = new BufferedWriter(new FileWriter(file, true)); + bw.write(targetplayer.PlayerName+"\n"); + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + PluginMain.LastException=e; //2015.08.09. + } + SendMessage(player, "§6The flair has been set. Player: "+targetplayer.PlayerName+" Flair: "+flair+"§r"); + } + private static void DoSetFlair(Player player, String args) + { + //args[0] is "admin" - args[1] is "setflair" + if(args.length()<4) + { + SendMessage(player, "§cUsage: /u admin setflair "); + return; + } + SetPlayerFlair(player, MaybeOfflinePlayer.AddPlayerIfNeeded(args[2]), args[3]); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/d6/a08b7a0ed03e001518fa86d7ae2a1cf8 b/.metadata/.plugins/org.eclipse.core.resources/.history/d6/a08b7a0ed03e001518fa86d7ae2a1cf8 new file mode 100644 index 0000000..5d70e40 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/d6/a08b7a0ed03e001518fa86d7ae2a1cf8 @@ -0,0 +1,198 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; + +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class Commands implements CommandExecutor { + // This method is called, when somebody uses our command + @Override + public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { + if (sender instanceof Player) { + Player player = (Player) sender; + if(args.length<1) + return false; + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. + //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) + if(p.Flair==null) + { + player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); + return true; + } + switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. + { + case "accept": + { + if(p.IgnoredFlair) + p.IgnoredFlair=false; //2015.08.08. + if(!p.AcceptedFlair) + { + String flair=p.Flair; //2015.08.08. + //PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + PluginMain.AppendPlayerDisplayFlair(p, player); + p.AcceptedFlair=true; //2015.08.08. + player.sendMessage("§6Your flair has been set:§r "+flair); + } + else + player.sendMessage("§cYou already have this user's flair.§r"); + break; + } + case "ignore": + { + if(p.AcceptedFlair) + p.AcceptedFlair=false; //2015.08.08. + if(!p.IgnoredFlair) + { + p.IgnoredFlair=true; + String flair=p.Flair; //2015.08.08. + PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. + player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); + } + else + player.sendMessage("§cYou already ignored this request.§r"); + break; + } + /*case "reload": //2015.07.20. + DoReload(player); + break;*/ + case "admin": //2015.08.09. + DoAdmin(player, args); + break; + case "nonpresser": //2015.08.09. + break; + default: + return false; + } + return true; + } + /*if(args[0].toLowerCase()=="reload") + DoReload(null); //2015.07.20.*/ + else if(args.length>0 && args[0].toLowerCase().equals("admin")) //2015.08.09. + { + DoAdmin(null, args); //2015.08.09. + return true; //2015.08.09. + } + return false; + } + private static void DoReload(Player player) + { //2015.07.20. + //if(player==null || player.isOp() || player.getName()=="NorbiPeti") + //{ + try + { + File file=new File("autoflairconfig.txt"); + if(file.exists()) + { + PluginMain.TownColors.clear(); + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + PluginMain.TownColors.put(s[0], s[1]); + } + br.close(); + for(Player p : PluginMain.GetPlayers()) + { + MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName()); + if(mp.Flair!=null) + { + String flair=mp.Flair; + PluginMain.RemovePlayerDisplayFlairFinal(p, flair); + //PluginMain.AppendPlayerDisplayFlairFinal(p, flair); + PluginMain.AppendPlayerDisplayFlair(mp, p); + } + } + String msg="§6Reloaded config file.§r"; + SendMessage(player, msg); //2015.08.09. + } + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + if(player!=null) + player.sendMessage("§cAn error occured. See console for details.§r"); + PluginMain.LastException=e; //2015.08.09. + } + //} + //else + //player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static void DoAdmin(Player player, String[] args) + { //2015.08.09. + if(player==null || player.isOp() || player.getName()=="NorbiPeti") + { + //System.out.println("Args length: " + args.length); + if(args.length==1) + { + String message="§cUsage: /u admin reload|playerinfo§r"; + SendMessage(player, message); + return; + } + //args[0] is "admin" + switch(args[1].toLowerCase()) + { + case "reload": + DoReload(player); + break; + case "playerinfo": + DoPlayerInfo(player, args); + break; + case "getlasterror": + DoGetLastError(player, args); + default: + String message="§cUsage: /u admin reload|playerinfo§r"; + SendMessage(player, message); + return; + } + } + else + player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static void DoPlayerInfo(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "playerinfo" + if(args.length==2) + { + String message="§cUsage: /u admin playerinfo §r"; + SendMessage(player, message); + return; + } + if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2])) + { + String message="§cPlayer not found: "+args[2]+"§r"; + SendMessage(player, message); + return; + } + MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]); + SendMessage(player, "Player name: "+p.PlayerName); + SendMessage(player, "User flair: "+p.Flair); + SendMessage(player, "Username: "+p.UserName); + SendMessage(player, "Flair accepted: "+p.AcceptedFlair); + SendMessage(player, "Flair ignored: "+p.IgnoredFlair); + } + private static void SendMessage(Player player, String message) + { //2015.08.09. + if(player==null) + System.out.println(message); + else + player.sendMessage(message); + } + private static void DoGetLastError(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "getlasterror" + if(PluginMain.LastException!=null) + { + SendMessage(player, "Last error:"); + SendMessage(player, PluginMain.LastException.toString()); + PluginMain.LastException=null; + } + else + SendMessage(player, "There were no exceptions."); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/d6/e0a5b112313e00151cbdba8b5f0a340e b/.metadata/.plugins/org.eclipse.core.resources/.history/d6/e0a5b112313e00151cbdba8b5f0a340e deleted file mode 100644 index afdf0ca..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/d6/e0a5b112313e00151cbdba8b5f0a340e +++ /dev/null @@ -1,120 +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; - MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. - //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - if(p.Flair==null) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - { - if(p.IgnoredFlair) - p.IgnoredFlair=false; //2015.08.08. - if(!p.AcceptedFlair) - { - String flair=p.Flair; //2015.08.08. - PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. - p.AcceptedFlair=true; //2015.08.08. - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("§cYou already have this user's flair.§r"); - break; - } - case "ignore": - { - if(p.AcceptedFlair) - p.AcceptedFlair=false; //2015.08.08. - if(!p.IgnoredFlair) - { - p.IgnoredFlair=true; - //String 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/d7/5064fb90fe3d00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/d7/5064fb90fe3d00151c31fb33fff4337f deleted file mode 100644 index e66301f..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/d7/5064fb90fe3d00151c31fb33fff4337f +++ /dev/null @@ -1,123 +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()); - 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/d7/a0f61d9bd03e001518fa86d7ae2a1cf8 b/.metadata/.plugins/org.eclipse.core.resources/.history/d7/a0f61d9bd03e001518fa86d7ae2a1cf8 new file mode 100644 index 0000000..8abed8b --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/d7/a0f61d9bd03e001518fa86d7ae2a1cf8 @@ -0,0 +1,206 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; + +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class Commands implements CommandExecutor { + // This method is called, when somebody uses our command + @Override + public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { + if (sender instanceof Player) { + Player player = (Player) sender; + if(args.length<1) + return false; + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. + //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) + if(p.Flair==null) + { + player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); + return true; + } + switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. + { + case "accept": + { + if(p.IgnoredFlair) + p.IgnoredFlair=false; //2015.08.08. + if(!p.AcceptedFlair) + { + String flair=p.Flair; //2015.08.08. + //PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + PluginMain.AppendPlayerDisplayFlair(p, player); + p.AcceptedFlair=true; //2015.08.08. + player.sendMessage("§6Your flair has been set:§r "+flair); + } + else + player.sendMessage("§cYou already have this user's flair.§r"); + break; + } + case "ignore": + { + if(p.AcceptedFlair) + p.AcceptedFlair=false; //2015.08.08. + if(!p.IgnoredFlair) + { + p.IgnoredFlair=true; + String flair=p.Flair; //2015.08.08. + PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. + player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); + } + else + player.sendMessage("§cYou already ignored this request.§r"); + break; + } + /*case "reload": //2015.07.20. + DoReload(player); + break;*/ + case "admin": //2015.08.09. + DoAdmin(player, args); + break; + case "nonpresser": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + + break; + case "cantpress": //2015.08.09. + break; + default: + return false; + } + return true; + } + /*if(args[0].toLowerCase()=="reload") + DoReload(null); //2015.07.20.*/ + else if(args.length>0 && args[0].toLowerCase().equals("admin")) //2015.08.09. + { + DoAdmin(null, args); //2015.08.09. + return true; //2015.08.09. + } + return false; + } + private static void DoReload(Player player) + { //2015.07.20. + //if(player==null || player.isOp() || player.getName()=="NorbiPeti") + //{ + try + { + File file=new File("autoflairconfig.txt"); + if(file.exists()) + { + PluginMain.TownColors.clear(); + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + PluginMain.TownColors.put(s[0], s[1]); + } + br.close(); + for(Player p : PluginMain.GetPlayers()) + { + MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName()); + if(mp.Flair!=null) + { + String flair=mp.Flair; + PluginMain.RemovePlayerDisplayFlairFinal(p, flair); + //PluginMain.AppendPlayerDisplayFlairFinal(p, flair); + PluginMain.AppendPlayerDisplayFlair(mp, p); //2015.08.09. + } + } + String msg="§6Reloaded config file.§r"; + SendMessage(player, msg); //2015.08.09. + } + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + if(player!=null) + player.sendMessage("§cAn error occured. See console for details.§r"); + PluginMain.LastException=e; //2015.08.09. + } + //} + //else + //player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static void DoAdmin(Player player, String[] args) + { //2015.08.09. + if(player==null || player.isOp() || player.getName()=="NorbiPeti") + { + //System.out.println("Args length: " + args.length); + if(args.length==1) + { + String message="§cUsage: /u admin reload|playerinfo§r"; + SendMessage(player, message); + return; + } + //args[0] is "admin" + switch(args[1].toLowerCase()) + { + case "reload": + DoReload(player); + break; + case "playerinfo": + DoPlayerInfo(player, args); + break; + case "getlasterror": + DoGetLastError(player, args); + default: + String message="§cUsage: /u admin reload|playerinfo§r"; + SendMessage(player, message); + return; + } + } + else + player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static void DoPlayerInfo(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "playerinfo" + if(args.length==2) + { + String message="§cUsage: /u admin playerinfo §r"; + SendMessage(player, message); + return; + } + if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2])) + { + String message="§cPlayer not found: "+args[2]+"§r"; + SendMessage(player, message); + return; + } + MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]); + SendMessage(player, "Player name: "+p.PlayerName); + SendMessage(player, "User flair: "+p.Flair); + SendMessage(player, "Username: "+p.UserName); + SendMessage(player, "Flair accepted: "+p.AcceptedFlair); + SendMessage(player, "Flair ignored: "+p.IgnoredFlair); + } + private static void SendMessage(Player player, String message) + { //2015.08.09. + if(player==null) + System.out.println(message); + else + player.sendMessage(message); + } + private static void DoGetLastError(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "getlasterror" + if(PluginMain.LastException!=null) + { + SendMessage(player, "Last error:"); + SendMessage(player, PluginMain.LastException.toString()); + PluginMain.LastException=null; + } + else + SendMessage(player, "There were no exceptions."); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/d7/c0293873043e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/d7/c0293873043e00151c31fb33fff4337f deleted file mode 100644 index cd04256..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/d7/c0293873043e00151c31fb33fff4337f +++ /dev/null @@ -1,126 +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; - 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/d8/e0a05c04853e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/d8/e0a05c04853e00151ce8ff6d4f74dabd deleted file mode 100644 index 9f42545..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/d8/e0a05c04853e00151ce8ff6d4f74dabd +++ /dev/null @@ -1,119 +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; - MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. - //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - if(p.Flair==null) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. - { - case "accept": - { - if(p.IgnoredFlair) - p.IgnoredFlair=false; //2015.08.08. - if(!p.AcceptedFlair) - { - String flair=p.Flair; //2015.08.08. - PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. - p.AcceptedFlair=true; //2015.08.08. - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("§cYou already have this user's flair.§r"); - break; - } - case "ignore": - { - if(p.AcceptedFlair) - p.AcceptedFlair=false; //2015.08.08. - if(!p.IgnoredFlair) - { - p.IgnoredFlair=true; - String flair=p.Flair; //2015.08.08. - PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. - player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); - } - else - player.sendMessage("§cYou already ignored this request.§r"); - break; - } - case "reload": //2015.07.20. - DoReload(player); - break; - case "showerrors": //2015.08.09. - break; - default: - return false; - } - return true; - } - - if(args[0]=="reload") - DoReload(null); //2015.07.20. - return false; - } - private static void DoReload(Player player) - { //2015.07.20. - if(player==null || player.isOp() || player.getName()=="NorbiPeti") - { - try - { - File file=new File("autoflairconfig.txt"); - if(file.exists()) - { - PluginMain.TownColors.clear(); - BufferedReader br=new BufferedReader(new FileReader(file)); - String line; - while((line=br.readLine())!=null) - { - String[] s=line.split(" "); - PluginMain.TownColors.put(s[0], s[1]); - } - br.close(); - for(Player p : PluginMain.GetPlayers()) - { - MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName()); - if(mp.Flair!=null) - { - String flair=mp.Flair; - PluginMain.RemovePlayerDisplayFlairFinal(p, flair); - PluginMain.AppendPlayerDisplayFlairFinal(p, flair); - } - } - String msg="§6Reloaded config file.§r"; - if(player!=null) - player.sendMessage(msg); - else - System.out.println(msg); - } - } - catch(Exception e) - { - System.out.println("Error!\n"+e); - if(player!=null) - player.sendMessage("§cAn error occured. See console for details.§r"); - } - } - else - player.sendMessage("§cYou need to be OP to use this command.§r"); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/d8/f0762d6f043e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/d8/f0762d6f043e00151c31fb33fff4337f deleted file mode 100644 index 87c0c13..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/d8/f0762d6f043e00151c31fb33fff4337f +++ /dev/null @@ -1,126 +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; - 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/da/a0d614ced03e001518fa86d7ae2a1cf8 b/.metadata/.plugins/org.eclipse.core.resources/.history/da/a0d614ced03e001518fa86d7ae2a1cf8 new file mode 100644 index 0000000..a8b8f80 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/da/a0d614ced03e001518fa86d7ae2a1cf8 @@ -0,0 +1,210 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; + +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class Commands implements CommandExecutor { + // This method is called, when somebody uses our command + @Override + public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { + if (sender instanceof Player) { + Player player = (Player) sender; + if(args.length<1) + return false; + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. + //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) + if(p.Flair==null) + { + player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); + return true; + } + switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. + { + case "accept": + { + if(p.IgnoredFlair) + p.IgnoredFlair=false; //2015.08.08. + if(!p.AcceptedFlair) + { + String flair=p.Flair; //2015.08.08. + //PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + PluginMain.AppendPlayerDisplayFlair(p, player); + p.AcceptedFlair=true; //2015.08.08. + player.sendMessage("§6Your flair has been set:§r "+flair); + } + else + player.sendMessage("§cYou already have this user's flair.§r"); + break; + } + case "ignore": + { + if(p.AcceptedFlair) + p.AcceptedFlair=false; //2015.08.08. + if(!p.IgnoredFlair) + { + p.IgnoredFlair=true; + String flair=p.Flair; //2015.08.08. + PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. + player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); + } + else + player.sendMessage("§cYou already ignored this request.§r"); + break; + } + /*case "reload": //2015.07.20. + DoReload(player); + break;*/ + case "admin": //2015.08.09. + DoAdmin(player, args); + break; + case "nonpresser": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + break; + case "cantpress": //2015.08.09. + break; + default: + return false; + } + return true; + } + /*if(args[0].toLowerCase()=="reload") + DoReload(null); //2015.07.20.*/ + else if(args.length>0 && args[0].toLowerCase().equals("admin")) //2015.08.09. + { + DoAdmin(null, args); //2015.08.09. + return true; //2015.08.09. + } + return false; + } + private static void DoReload(Player player) + { //2015.07.20. + //if(player==null || player.isOp() || player.getName()=="NorbiPeti") + //{ + try + { + File file=new File("autoflairconfig.txt"); + if(file.exists()) + { + PluginMain.TownColors.clear(); + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + PluginMain.TownColors.put(s[0], s[1]); + } + br.close(); + for(Player p : PluginMain.GetPlayers()) + { + MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName()); + if(mp.Flair!=null) + { + String flair=mp.Flair; + PluginMain.RemovePlayerDisplayFlairFinal(p, flair); + //PluginMain.AppendPlayerDisplayFlairFinal(p, flair); + PluginMain.AppendPlayerDisplayFlair(mp, p); //2015.08.09. + } + } + String msg="§6Reloaded config file.§r"; + SendMessage(player, msg); //2015.08.09. + } + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + if(player!=null) + player.sendMessage("§cAn error occured. See console for details.§r"); + PluginMain.LastException=e; //2015.08.09. + } + //} + //else + //player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static void DoAdmin(Player player, String[] args) + { //2015.08.09. + if(player==null || player.isOp() || player.getName()=="NorbiPeti") + { + //System.out.println("Args length: " + args.length); + if(args.length==1) + { + String message="§cUsage: /u admin reload|playerinfo§r"; + SendMessage(player, message); + return; + } + //args[0] is "admin" + switch(args[1].toLowerCase()) + { + case "reload": + DoReload(player); + break; + case "playerinfo": + DoPlayerInfo(player, args); + break; + case "getlasterror": + DoGetLastError(player, args); + default: + String message="§cUsage: /u admin reload|playerinfo§r"; + SendMessage(player, message); + return; + } + } + else + player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static void DoPlayerInfo(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "playerinfo" + if(args.length==2) + { + String message="§cUsage: /u admin playerinfo §r"; + SendMessage(player, message); + return; + } + if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2])) + { + String message="§cPlayer not found: "+args[2]+"§r"; + SendMessage(player, message); + return; + } + MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]); + SendMessage(player, "Player name: "+p.PlayerName); + SendMessage(player, "User flair: "+p.Flair); + SendMessage(player, "Username: "+p.UserName); + SendMessage(player, "Flair accepted: "+p.AcceptedFlair); + SendMessage(player, "Flair ignored: "+p.IgnoredFlair); + } + private static void SendMessage(Player player, String message) + { //2015.08.09. + if(player==null) + System.out.println(message); + else + player.sendMessage(message); + } + private static void DoGetLastError(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "getlasterror" + if(PluginMain.LastException!=null) + { + SendMessage(player, "Last error:"); + SendMessage(player, PluginMain.LastException.toString()); + PluginMain.LastException=null; + } + else + SendMessage(player, "There were no exceptions."); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/da/f088765c0c3e00151089cca86c5b1a99 b/.metadata/.plugins/org.eclipse.core.resources/.history/da/f088765c0c3e00151089cca86c5b1a99 deleted file mode 100644 index f058cfe..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/da/f088765c0c3e00151089cca86c5b1a99 +++ /dev/null @@ -1,433 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import java.io.BufferedReader; -import java.io.BufferedWriter; -import java.io.File; -import java.io.FileReader; -import java.io.FileWriter; -import java.io.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 deleted file mode 100644 index b00988e..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/db/600bbc16013e00151c31fb33fff4337f +++ /dev/null @@ -1,122 +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()); - 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/dd/80ebea64dd3e001517108d149b613203 b/.metadata/.plugins/org.eclipse.core.resources/.history/dd/80ebea64dd3e001517108d149b613203 new file mode 100644 index 0000000..2441bac --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/dd/80ebea64dd3e001517108d149b613203 @@ -0,0 +1,398 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStream; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLConnection; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + +import org.apache.commons.io.IOUtils; +import org.bukkit.entity.Player; +import org.bukkit.plugin.java.JavaPlugin; +import org.json.JSONArray; +import org.json.JSONObject; + +import com.palmergames.bukkit.towny.object.Town; +import com.palmergames.bukkit.towny.object.WorldCoord; + +public class PluginMain extends JavaPlugin +{ //Translated to Java: 2015.07.15. + //A user, which flair isn't obtainable: + //https://www.reddit.com/r/thebutton/comments/31c32v/i_pressed_the_button_without_really_thinking/ + private static PluginMain Instance; + // Fired when plugin is first enabled + @Override + public void onEnable() + { + System.out.println("The Button Auto-flair Plugin by NorbiPeti (:P)"); + getServer().getPluginManager().registerEvents(new PlayerListener(), this); + this.getCommand("u").setExecutor(new Commands()); + this.getCommand("u").setUsage(this.getCommand("u").getUsage().replace('&', '§')); + Instance=this; //2015.08.08. + LoadFiles(false); //2015.08.09. + Runnable r=new Runnable(){public void run(){ThreadMethod();}}; + Thread t=new Thread(r); + t.start(); + } + Boolean stop=false; + // Fired when plugin is disabled + @Override + public void onDisable() + { + SaveFiles(); //2015.08.09. + stop=true; + } + + public void ThreadMethod() //<-- 2015.07.16. + { + while(!stop) + { + try + { + String body=DownloadString("https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/autoflair_system_comment_your_minecraft_name_and/.json?limit=1000"); + JSONArray json=new JSONArray(body).getJSONObject(1).getJSONObject("data").getJSONArray("children"); + for(Object obj : json) + { + JSONObject item = (JSONObject)obj; + String author=item.getJSONObject("data").getString("author"); + String ign=item.getJSONObject("data").getString("body"); + int start = ign.indexOf("IGN:") + "IGN:".length(); + if(start==-1) + continue; //2015.08.09. + int end = ign.indexOf(' ', start); + if (end == -1 || end == start) + end=ign.indexOf('\n', start); //2015.07.15. + if (end == -1 || end == start) + ign = ign.substring(start); + else + ign = ign.substring(start, end); + ign = ign.trim(); + if(HasIGFlair(ign)) + continue; + try { + Thread.sleep(10); + } catch(InterruptedException ex) { + Thread.currentThread().interrupt(); + } + String[] flairdata = DownloadString("http://karmadecay.com/thebutton-data.php?users=" + author).replace("\"", "").split(":"); + String flair; + if(flairdata.length > 1) //2015.07.15. + flair = flairdata[1]; + else + flair=""; + if (flair != "-1") + flair = flair + "s"; + else + flair = "non-presser"; + String flairclass; + if(flairdata.length>2) + flairclass = flairdata[2]; + else + flairclass="unknown"; + SetFlair(ign, flair, flairclass, author); + } + Thread.sleep(10000); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + } + + public static Exception LastException; //2015.08.09. + + public String DownloadString(String urlstr) throws MalformedURLException, IOException + { + URL url = new URL(urlstr); + URLConnection con = url.openConnection(); + con.setRequestProperty("User-Agent", "TheButtonAutoFlair"); + InputStream in = con.getInputStream(); + String encoding = con.getContentEncoding(); + encoding = encoding == null ? "UTF-8" : encoding; + String body = IOUtils.toString(in, encoding); + in.close(); + return body; + } + + public static Map TownColors=new HashMap(); //2015.07.20. + public Boolean HasIGFlair(String playername) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + return p.Flair!=null; //2015.08.08. + } + + public void SetFlair(String playername, String text, String flairclass, String username) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + String finalflair; + p.FlairDecided=true; + switch(flairclass) + { + case "press-1": + finalflair="§c("+text+")§r"; + break; + case "press-2": + finalflair="§6("+text+")§r"; + break; + case "press-3": + finalflair="§e("+text+")§r"; + break; + case "press-4": + finalflair="§a("+text+")§r"; + break; + case "press-5": + finalflair="§9("+text+")§r"; + break; + 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; + case "undecided": //2015.08.09. + p.FlairDecided=false; + finalflair=""; + break; + default: + finalflair=""; + break; + } + if(finalflair.length()==0) //<-- 2015.07.20. + return; + p.Flair=finalflair; //2015.08.08. + p.UserName=username; //2015.08.08. + System.out.println("Added new flair to "+playername+": "+finalflair); + for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08. + { + if(player.getName().equals(playername)) + { + //AppendPlayerDisplayFlair(player, username, finalflair); + AppendPlayerDisplayFlair(p, player); + break; + } + } + } + + public static String GetFlair(Player player) + { //2015.07.16. + String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08. + return flair==null ? "" : flair; + } + + //public static void AppendPlayerDisplayFlair(Player player, String username, String flair) + public static void AppendPlayerDisplayFlair(MaybeOfflinePlayer player, Player p) //<-- 2015.08.09. + { + + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).IgnoredFlair) + return; + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).AcceptedFlair) + { + AppendPlayerDisplayFlairFinal(p, player.Flair); //2015.07.20. + if(!player.FlairDecided) + p.sendMessage("§9Your flair type is unknown. Are you a non-presser or a can't press? (/u nonpresser or /u cantpress)§r"); //2015.08.09. + } + else + p.sendMessage("§9Are you Reddit user "+player.UserName+"?§r §6Type /u accept or /u ignore§r"); + } + + private static void AppendPlayerDisplayFlairFinal(Player player, String flair) + { //2015.07.20. + String color = GetColorForTown(GetPlayerTown(player)); //TO!DO: Multiple colors put on first capital letters + String[] colors = color.substring(1).split("§"); + String displayname=player.getName(); //2015.08.08. + ArrayList Positions=new ArrayList<>(); + for(int i=0; i=colors.length) + { + int x=0; + for(int i=0; i GetPlayers() + { + return Instance.getServer().getOnlinePlayers(); + } + + public static void LoadFiles(boolean reload) //<-- 2015.08.09. + { + if(reload) + { //2015.08.09. + System.out.println("Auto-flair plugin cleanup for reloading..."); + MaybeOfflinePlayer.AllPlayers.clear(); + TownColors.clear(); + } + System.out.println("Loading files for auto-flair plugin..."); //2015.08.09. + try { + File file=new File("flairsaccepted.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + //System.out.println("Name: " + name); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("flairsignored.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsignored.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("autoflairconfig.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + TownColors.put(s[0], s[1]); + } + br.close(); + } + file=new File("autoflairdecisions.txt"); //2015.08.09. + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + MaybeOfflinePlayer.AddPlayerIfNeeded(s[0]).Flair=s[1]; //2015.08.09. + } + br.close(); + } + //throw new IOException("Test"); //2015.08.09. + System.out.println("Auto-flair plugin loaded files!"); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + public static void SaveFiles() //<-- 2015.08.09. + { + try + { + FileWriter fw; + fw = new FileWriter("flairsaccepted.txt"); + fw.close(); + fw = new FileWriter("flairsignored.txt"); + fw.close(); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + try { + File file=new File("flairsaccepted.txt"); + BufferedWriter bw=new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.AcceptedFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + file=new File("flairsignored.txt"); + bw = new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.IgnoredFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + public static void SetPlayerFlair(Player player, String flair) + { //2015.08.09. + flair=flair.replace('&', '§'); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/df/9064eb98e33e001517108d149b613203 b/.metadata/.plugins/org.eclipse.core.resources/.history/df/9064eb98e33e001517108d149b613203 new file mode 100644 index 0000000..2b462b5 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/df/9064eb98e33e001517108d149b613203 @@ -0,0 +1,265 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +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; + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. + //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) + if(p.Flair==null) + { + player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); + return true; + } + switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. + { + case "accept": + { + if(p.IgnoredFlair) + p.IgnoredFlair=false; //2015.08.08. + if(!p.AcceptedFlair) + { + String flair=p.Flair; //2015.08.08. + //PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + PluginMain.AppendPlayerDisplayFlair(p, player); + p.AcceptedFlair=true; //2015.08.08. + player.sendMessage("§6Your flair has been set:§r "+flair); + } + else + player.sendMessage("§cYou already have this user's flair.§r"); + break; + } + case "ignore": + { + if(p.AcceptedFlair) + p.AcceptedFlair=false; //2015.08.08. + if(!p.IgnoredFlair) + { + p.IgnoredFlair=true; + String flair=p.Flair; //2015.08.08. + PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. + player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); + } + else + player.sendMessage("§cYou already ignored this request.§r"); + break; + } + /*case "reload": //2015.07.20. + DoReload(player); + break;*/ + case "admin": //2015.08.09. + DoAdmin(player, args); + break; + case "nonpresser": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§7(non-pr.)§r"; + break; + case "cantpress": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§r(can't press)§r"; + break; + default: + return false; + } + return true; + } + /*if(args[0].toLowerCase()=="reload") + DoReload(null); //2015.07.20.*/ + else if(args.length>0 && args[0].toLowerCase().equals("admin")) //2015.08.09. + { + DoAdmin(null, args); //2015.08.09. + return true; //2015.08.09. + } + return false; + } + private static void DoReload(Player player) + { //2015.07.20. + //if(player==null || player.isOp() || player.getName()=="NorbiPeti") + //{ + try + { + File file=new File("autoflairconfig.txt"); + if(file.exists()) + { + PluginMain.LoadFiles(true); //2015.08.09. + for(Player p : PluginMain.GetPlayers()) + { + MaybeOfflinePlayer mp = MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName()); + if(mp.Flair!=null) + { + String flair=mp.Flair; + //PluginMain.RemovePlayerDisplayFlairFinal(p, flair); + //PluginMain.AppendPlayerDisplayFlairFinal(p, flair); + PluginMain.AppendPlayerDisplayFlair(mp, p); //2015.08.09. + } + String msg="§6Note: The auto-flair plugin has been reloaded. You might need to wait 10s to have your flair.§r"; //2015.08.09. + p.sendMessage(msg); //2015.08.09. + } + //String msg="§6Reloaded config file.§r"; + //SendMessage(player, msg); //2015.08.09. + } + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + if(player!=null) + player.sendMessage("§cAn error occured. See console for details.§r"); + PluginMain.LastException=e; //2015.08.09. + } + //} + //else + //player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static Player ReloadPlayer; //2015.08.09. + private static void DoAdmin(Player player, String[] args) + { //2015.08.09. + if(player==null || player.isOp() || player.getName()=="NorbiPeti") + { + //System.out.println("Args length: " + args.length); + if(args.length==1) + { + String message="§cUsage: /u admin reload|playerinfo§r"; + SendMessage(player, message); + return; + } + //args[0] is "admin" + switch(args[1].toLowerCase()) + { + case "reload": + ReloadPlayer=player; //2015.08.09. + SendMessage(player, "§6Make sure to save the current settings before you modify and reload them! Type /u admin confirm when done.§r"); + break; + case "playerinfo": + DoPlayerInfo(player, args); + break; + case "getlasterror": + DoGetLastError(player, args); + case "confirm": + if(ReloadPlayer==player) + DoReload(player); //2015.08.09. + else + SendMessage(player, "§cYou need to do /u admin reload first.§r"); + break; + case "save": + PluginMain.SaveFiles(); //2015.08.09. + SendMessage(player, "§6Saved files. Now you can edit them and reload if you want.§r"); + break; + case "setflair": + DoSetFlair(player, args); + break; + default: + String message="§cUsage: /u admin reload|playerinfo|getlasterror|save|setflair§r"; + SendMessage(player, message); + return; + } + } + else + player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static void DoPlayerInfo(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "playerinfo" + if(args.length==2) + { + String message="§cUsage: /u admin playerinfo §r"; + SendMessage(player, message); + return; + } + if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2])) + { + String message="§cPlayer not found: "+args[2]+"§r"; + SendMessage(player, message); + return; + } + MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]); + SendMessage(player, "Player name: "+p.PlayerName); + SendMessage(player, "User flair: "+p.Flair); + SendMessage(player, "Username: "+p.UserName); + SendMessage(player, "Flair accepted: "+p.AcceptedFlair); + SendMessage(player, "Flair ignored: "+p.IgnoredFlair); + } + private static void SendMessage(Player player, String message) + { //2015.08.09. + if(player==null) + System.out.println(message); + else + player.sendMessage(message); + } + private static void DoGetLastError(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "getlasterror" + if(PluginMain.LastException!=null) + { + SendMessage(player, "Last error:"); + SendMessage(player, PluginMain.LastException.toString()); + PluginMain.LastException=null; + } + else + SendMessage(player, "There were no exceptions."); + } + private static void SetPlayerFlair(Player player, MaybeOfflinePlayer targetplayer, String flair) + { //2015.08.09. + flair=flair.replace('&', '§'); + targetplayer.Flair=flair; + if(!PluginMain.RemoveLineFromFile("customflairs.txt", targetplayer.PlayerName)) + { + SendMessage(player, "§cError removing previous custom flair!§r"); + return; + } + File file=new File("customflairs.txt"); + try { + BufferedWriter bw; + bw = new BufferedWriter(new FileWriter(file, true)); + bw.write(targetplayer.PlayerName+"\n"); + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + PluginMain.LastException=e; //2015.08.09. + } + SendMessage(player, "§6The flair has been set. Player: "+targetplayer.PlayerName+" Flair: "+flair+"§r"); + } + private static void DoSetFlair(Player player, String[] args) + { + //args[0] is "admin" - args[1] is "setflair" + if(args.length<4) + { + SendMessage(player, "§cUsage: /u admin setflair "); + return; + } + SetPlayerFlair(player, MaybeOfflinePlayer.AddPlayerIfNeeded(args[2]), args[3]); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/df/c06a7eb00d3e00151089cca86c5b1a99 b/.metadata/.plugins/org.eclipse.core.resources/.history/df/c06a7eb00d3e00151089cca86c5b1a99 deleted file mode 100644 index efac5c3..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/df/c06a7eb00d3e00151089cca86c5b1a99 +++ /dev/null @@ -1,434 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import java.io.BufferedReader; -import java.io.BufferedWriter; -import java.io.File; -import java.io.FileReader; -import java.io.FileWriter; -import java.io.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/e/a0795133d23e001518fa86d7ae2a1cf8 b/.metadata/.plugins/org.eclipse.core.resources/.history/e/a0795133d23e001518fa86d7ae2a1cf8 new file mode 100644 index 0000000..be2f453 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/e/a0795133d23e001518fa86d7ae2a1cf8 @@ -0,0 +1,376 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStream; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLConnection; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + +import org.apache.commons.io.IOUtils; +import org.bukkit.entity.Player; +import org.bukkit.plugin.java.JavaPlugin; +import org.json.JSONArray; +import org.json.JSONObject; + +import com.palmergames.bukkit.towny.object.Town; +import com.palmergames.bukkit.towny.object.WorldCoord; + +public class PluginMain extends JavaPlugin +{ //Translated to Java: 2015.07.15. + //A user, which flair isn't obtainable: + //https://www.reddit.com/r/thebutton/comments/31c32v/i_pressed_the_button_without_really_thinking/ + private static PluginMain Instance; + // Fired when plugin is first enabled + @Override + public void onEnable() + { + System.out.println("The Button Auto-flair Plugin by NorbiPeti (:P)"); + getServer().getPluginManager().registerEvents(new PlayerListener(), this); + this.getCommand("u").setExecutor(new Commands()); + this.getCommand("u").setUsage(this.getCommand("u").getUsage().replace('&', '§')); + Instance=this; //2015.08.08. + LoadFiles(false); //2015.08.09. + Runnable r=new Runnable(){public void run(){ThreadMethod();}}; + Thread t=new Thread(r); + t.start(); + } + Boolean stop=false; + // Fired when plugin is disabled + @Override + public void onDisable() + { + try + { + FileWriter fw; + fw = new FileWriter("flairsaccepted.txt"); + fw.close(); + fw = new FileWriter("flairsignored.txt"); + fw.close(); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + try { + File file=new File("flairsaccepted.txt"); + BufferedWriter bw=new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.AcceptedFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + file=new File("flairsignored.txt"); + bw = new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.IgnoredFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + stop=true; + } + + public void ThreadMethod() //<-- 2015.07.16. + { + while(!stop) + { + try + { + String body=DownloadString("https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/autoflair_system_comment_your_minecraft_name_and/.json?limit=1000"); + JSONArray json=new JSONArray(body).getJSONObject(1).getJSONObject("data").getJSONArray("children"); + for(Object obj : json) + { + JSONObject item = (JSONObject)obj; + String author=item.getJSONObject("data").getString("author"); + String ign=item.getJSONObject("data").getString("body"); + int start = ign.indexOf("IGN:") + "IGN:".length(); + int end = ign.indexOf(' ', start); + if (end == -1 || end == start) + end=ign.indexOf('\n', start); //2015.07.15. + if (end == -1 || end == start) + ign = ign.substring(start); + else + ign = ign.substring(start, end); + ign = ign.trim(); + if(HasIGFlair(ign)) + continue; + try { + Thread.sleep(10); + } catch(InterruptedException ex) { + Thread.currentThread().interrupt(); + } + String[] flairdata = DownloadString("http://karmadecay.com/thebutton-data.php?users=" + author).replace("\"", "").split(":"); + String flair; + if(flairdata.length > 1) //2015.07.15. + flair = flairdata[1]; + else + flair=""; + if (flair != "-1") + flair = flair + "s"; + else + flair = "non-presser"; + String flairclass; + if(flairdata.length>2) + flairclass = flairdata[2]; + else + flairclass="unknown"; + SetFlair(ign, flair, flairclass, author); + } + Thread.sleep(10000); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + } + + public static Exception LastException; //2015.08.09. + + public String DownloadString(String urlstr) throws MalformedURLException, IOException + { + URL url = new URL(urlstr); + URLConnection con = url.openConnection(); + con.setRequestProperty("User-Agent", "TheButtonAutoFlair"); + InputStream in = con.getInputStream(); + String encoding = con.getContentEncoding(); + encoding = encoding == null ? "UTF-8" : encoding; + String body = IOUtils.toString(in, encoding); + in.close(); + return body; + } + + public static Map TownColors=new HashMap(); //2015.07.20. + public Boolean HasIGFlair(String playername) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + return p.Flair!=null; //2015.08.08. + } + + public void SetFlair(String playername, String text, String flairclass, String username) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + String finalflair; + p.FlairDecided=true; + switch(flairclass) + { + case "press-1": + finalflair="§c("+text+")§r"; + break; + case "press-2": + finalflair="§6("+text+")§r"; + break; + case "press-3": + finalflair="§e("+text+")§r"; + break; + case "press-4": + finalflair="§a("+text+")§r"; + break; + case "press-5": + finalflair="§9("+text+")§r"; + break; + 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; + case "undecided": //2015.08.09. + p.FlairDecided=false; + finalflair=""; + break; + default: + finalflair=""; + break; + } + if(finalflair.length()==0) //<-- 2015.07.20. + return; + p.Flair=finalflair; //2015.08.08. + p.UserName=username; //2015.08.08. + System.out.println("Added new flair to "+playername+": "+finalflair); + for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08. + { + if(player.getName().equals(playername)) + { + //AppendPlayerDisplayFlair(player, username, finalflair); + AppendPlayerDisplayFlair(p, player); + break; + } + } + } + + public static String GetFlair(Player player) + { //2015.07.16. + String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08. + return flair==null ? "" : flair; + } + + //public static void AppendPlayerDisplayFlair(Player player, String username, String flair) + public static void AppendPlayerDisplayFlair(MaybeOfflinePlayer player, Player p) //<-- 2015.08.09. + { + + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).IgnoredFlair) + return; + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).AcceptedFlair) + { + AppendPlayerDisplayFlairFinal(p, player.Flair); //2015.07.20. + if(!player.FlairDecided) + p.sendMessage("§9Your flair type is unknown. Are you a non-presser or a can't press? (/u nonpresser or /u cantpress)§r"); //2015.08.09. + } + else + p.sendMessage("§9Are you Reddit user "+player.UserName+"?§r §6Type /u accept or /u ignore§r"); + } + + private static void AppendPlayerDisplayFlairFinal(Player player, String flair) + { //2015.07.20. + String color = GetColorForTown(GetPlayerTown(player)); //TO!DO: Multiple colors put on first capital letters + String[] colors = color.substring(1).split("§"); + String displayname=player.getName(); //2015.08.08. + ArrayList Positions=new ArrayList<>(); + for(int i=0; i=colors.length) + { + int x=0; + for(int i=0; i GetPlayers() + { + return Instance.getServer().getOnlinePlayers(); + } + + public static void LoadFiles(boolean reload) //<-- 2015.08.09. + { + if(reload) + { //2015.08.09. + System.out.println("Auto-flair plugin cleanup for reloading..."); + MaybeOfflinePlayer.AllPlayers.clear(); + TownColors.clear(); + } + System.out.println("Loading files for auto-flair plugin..."); //2015.08.09. + try { + File file=new File("flairsaccepted.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + //System.out.println("Name: " + name); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("flairsignored.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsignored.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("autoflairconfig.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + TownColors.put(s[0], s[1]); + } + br.close(); + } + //throw new IOException("Test"); //2015.08.09. + System.out.println("Auto-flair plugin loaded!"); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/9d/e0ffd477033e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/e0/a07905a5cf3e001518fa86d7ae2a1cf8 similarity index 67% rename from .metadata/.plugins/org.eclipse.core.resources/.history/9d/e0ffd477033e00151c31fb33fff4337f rename to .metadata/.plugins/org.eclipse.core.resources/.history/e0/a07905a5cf3e001518fa86d7ae2a1cf8 index 41b903e..d0c7fdd 100644 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/9d/e0ffd477033e00151c31fb33fff4337f +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/e0/a07905a5cf3e001518fa86d7ae2a1cf8 @@ -15,43 +15,35 @@ public class PlayerListener implements Listener public void onPlayerJoin(PlayerJoinEvent event) { Player p=event.getPlayer(); - //PluginMain.Players.add(p); - //event.getPlayer().setDisplayName(p.getDisplayName()+PluginMain.GetFlair(p)); - //if(PluginMain.PlayerUserNames.containsKey(p.getName())) //<-- 2015.07.20. - if(MaybeOfflinePlayer.AllPlayers.containsKey(p.getName())) //<-- 2015.08.08. - //PluginMain.AppendPlayerDisplayFlair(p, PluginMain.PlayerUserNames.get(p.getName()), PluginMain.GetFlair(p)); - + MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName()); //2015.08.08. + MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName()); //2015.08.08. + if(mp.Flair!=null) + PluginMain.AppendPlayerDisplayFlair(mp, 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. + MaybeOfflinePlayer player = MaybeOfflinePlayer.AllPlayers.get(event.getPlayer().getName()); + String flair=player.Flair; //2015.08.08. + if(flair==null || !player.AcceptedFlair) + flair=""; //2015.08.08. + String message=event.getMessage(); //2015.08.08. + /*for(Player p : PluginMain.GetPlayers()) + { //2015.08.08. + message.replaceAll(p.getName(), ) + }*/ + event.setFormat(event.getFormat().substring(0, event.getFormat().indexOf(">"))+flair+"> "+message); //2015.08.08. } private static Class nmsChatSerializer = Reflection.getNMSClass("IChatBaseComponent$ChatSerializer"); @@ -72,6 +64,7 @@ public class PlayerListener implements Listener System.out.println("6"); } catch (Exception e) { e.printStackTrace(); + PluginMain.LastException=e; //2015.08.09. } } diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/e3/20517c59cf3e001518fa86d7ae2a1cf8 b/.metadata/.plugins/org.eclipse.core.resources/.history/e3/20517c59cf3e001518fa86d7ae2a1cf8 new file mode 100644 index 0000000..77a24f3 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/e3/20517c59cf3e001518fa86d7ae2a1cf8 @@ -0,0 +1,364 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.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 tk.sznp.thebuttonautoflair.MaybeOfflinePlayer.FlairClassType; + +import com.palmergames.bukkit.towny.object.Town; +import com.palmergames.bukkit.towny.object.WorldCoord; + +public class PluginMain extends JavaPlugin +{ //Translated to Java: 2015.07.15. + //A user, which flair isn't obtainable: + //https://www.reddit.com/r/thebutton/comments/31c32v/i_pressed_the_button_without_really_thinking/ + private static PluginMain Instance; + // Fired when plugin is first enabled + @Override + public void onEnable() + { + System.out.println("The Button Auto-flair Plugin by NorbiPeti (:P)"); + getServer().getPluginManager().registerEvents(new PlayerListener(), this); + this.getCommand("u").setExecutor(new Commands()); + this.getCommand("u").setUsage(this.getCommand("u").getUsage().replace('&', '§')); + Instance=this; //2015.08.08. + try { + File file=new File("flairsaccepted.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + //System.out.println("Name: " + name); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("flairsignored.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsignored.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("autoflairconfig.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + TownColors.put(s[0], s[1]); + } + br.close(); + } + //throw new IOException("Test"); //2015.08.09. + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + Runnable r=new Runnable(){public void run(){ThreadMethod();}}; + Thread t=new Thread(r); + t.start(); + } + Boolean stop=false; + // Fired when plugin is disabled + @Override + public void onDisable() + { + try + { + FileWriter fw; + fw = new FileWriter("flairsaccepted.txt"); + fw.close(); + fw = new FileWriter("flairsignored.txt"); + fw.close(); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + try { + File file=new File("flairsaccepted.txt"); + BufferedWriter bw=new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.AcceptedFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + file=new File("flairsignored.txt"); + bw = new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.IgnoredFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + stop=true; + } + + public void ThreadMethod() //<-- 2015.07.16. + { + while(!stop) + { + try + { + String body=DownloadString("https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/autoflair_system_comment_your_minecraft_name_and/.json?limit=1000"); + JSONArray json=new JSONArray(body).getJSONObject(1).getJSONObject("data").getJSONArray("children"); + for(Object obj : json) + { + JSONObject item = (JSONObject)obj; + String author=item.getJSONObject("data").getString("author"); + String ign=item.getJSONObject("data").getString("body"); + int start = ign.indexOf("IGN:") + "IGN:".length(); + int end = ign.indexOf(' ', start); + if (end == -1 || end == start) + end=ign.indexOf('\n', start); //2015.07.15. + if (end == -1 || end == start) + ign = ign.substring(start); + else + ign = ign.substring(start, end); + ign = ign.trim(); + if(HasIGFlair(ign)) + continue; + try { + Thread.sleep(10); + } catch(InterruptedException ex) { + Thread.currentThread().interrupt(); + } + String[] flairdata = DownloadString("http://karmadecay.com/thebutton-data.php?users=" + author).replace("\"", "").split(":"); + String flair; + if(flairdata.length > 1) //2015.07.15. + flair = flairdata[1]; + else + flair=""; + if (flair != "-1") + flair = flair + "s"; + else + flair = "non-presser"; + String flairclass; + if(flairdata.length>2) + flairclass = flairdata[2]; + else + flairclass="unknown"; + SetFlair(ign, flair, flairclass, author); + } + Thread.sleep(10000); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + } + + public static Exception LastException; //2015.08.09. + + public String DownloadString(String urlstr) throws MalformedURLException, IOException + { + URL url = new URL(urlstr); + URLConnection con = url.openConnection(); + con.setRequestProperty("User-Agent", "TheButtonAutoFlair"); + InputStream in = con.getInputStream(); + String encoding = con.getContentEncoding(); + encoding = encoding == null ? "UTF-8" : encoding; + String body = IOUtils.toString(in, encoding); + in.close(); + return body; + } + + public static Map TownColors=new HashMap(); //2015.07.20. + public Boolean HasIGFlair(String playername) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + return p.Flair!=null; //2015.08.08. + } + + public void SetFlair(String playername, String text, String flairclass, String username) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + String finalflair; + p.FlairDecided=true; + switch(flairclass) + { + case "press-1": + finalflair="§c("+text+")§r"; + break; + case "press-2": + finalflair="§6("+text+")§r"; + break; + case "press-3": + finalflair="§e("+text+")§r"; + break; + case "press-4": + finalflair="§a("+text+")§r"; + break; + case "press-5": + finalflair="§9("+text+")§r"; + break; + 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; + case "undecided": //2015.08.09. + p.FlairDecided=false; + finalflair=""; + break; + default: + finalflair=""; + break; + } + if(finalflair.length()==0) //<-- 2015.07.20. + return; + p.Flair=finalflair; //2015.08.08. + p.UserName=username; //2015.08.08. + System.out.println("Added new flair to "+playername+": "+finalflair); + for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08. + { + if(player.getName().equals(playername)) + { + AppendPlayerDisplayFlair(player, username, finalflair); + break; + } + } + } + + public static String GetFlair(Player player) + { //2015.07.16. + String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08. + return flair==null ? "" : flair; + } + + //public static void AppendPlayerDisplayFlair(Player player, String username, String flair) + public static void AppendPlayerDisplayFlair(MaybeOfflinePlayer player, Player p) //<-- 2015.08.09. + { + + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).IgnoredFlair) + return; + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).AcceptedFlair) + { + AppendPlayerDisplayFlairFinal(p, player.Flair); //2015.07.20. + if(!player.FlairDecided) + p.sendMessage("§9Your flair type is unknown. Are you a non-presser or a can't press?§r"); + } + else + player.sendMessage("§9Are you Reddit user "+username+"?§r §6Type /u accept or /u ignore§r"); + } + + private static void AppendPlayerDisplayFlairFinal(Player player, String flair) + { //2015.07.20. + String color = GetColorForTown(GetPlayerTown(player)); //TO!DO: Multiple colors put on first capital letters + String[] colors = color.substring(1).split("§"); + String displayname=player.getName(); //2015.08.08. + ArrayList Positions=new ArrayList<>(); + for(int i=0; i=colors.length) + { + int x=0; + for(int i=0; i GetPlayers() + { + return Instance.getServer().getOnlinePlayers(); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/e3/80cfda10e03e001517108d149b613203 b/.metadata/.plugins/org.eclipse.core.resources/.history/e3/80cfda10e03e001517108d149b613203 new file mode 100644 index 0000000..0ccc23b --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/e3/80cfda10e03e001517108d149b613203 @@ -0,0 +1,260 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +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; + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. + //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) + if(p.Flair==null) + { + player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); + return true; + } + switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. + { + case "accept": + { + if(p.IgnoredFlair) + p.IgnoredFlair=false; //2015.08.08. + if(!p.AcceptedFlair) + { + String flair=p.Flair; //2015.08.08. + //PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + PluginMain.AppendPlayerDisplayFlair(p, player); + p.AcceptedFlair=true; //2015.08.08. + player.sendMessage("§6Your flair has been set:§r "+flair); + } + else + player.sendMessage("§cYou already have this user's flair.§r"); + break; + } + case "ignore": + { + if(p.AcceptedFlair) + p.AcceptedFlair=false; //2015.08.08. + if(!p.IgnoredFlair) + { + p.IgnoredFlair=true; + String flair=p.Flair; //2015.08.08. + PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. + player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); + } + else + player.sendMessage("§cYou already ignored this request.§r"); + break; + } + /*case "reload": //2015.07.20. + DoReload(player); + break;*/ + case "admin": //2015.08.09. + DoAdmin(player, args); + break; + case "nonpresser": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§7(non-pr.)§r"; + break; + case "cantpress": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§r(can't press)§r"; + break; + default: + return false; + } + return true; + } + /*if(args[0].toLowerCase()=="reload") + DoReload(null); //2015.07.20.*/ + else if(args.length>0 && args[0].toLowerCase().equals("admin")) //2015.08.09. + { + DoAdmin(null, args); //2015.08.09. + return true; //2015.08.09. + } + return false; + } + private static void DoReload(Player player) + { //2015.07.20. + //if(player==null || player.isOp() || player.getName()=="NorbiPeti") + //{ + try + { + File file=new File("autoflairconfig.txt"); + if(file.exists()) + { + PluginMain.LoadFiles(true); //2015.08.09. + for(Player p : PluginMain.GetPlayers()) + { + MaybeOfflinePlayer mp = MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName()); + if(mp.Flair!=null) + { + String flair=mp.Flair; + PluginMain.RemovePlayerDisplayFlairFinal(p, flair); + //PluginMain.AppendPlayerDisplayFlairFinal(p, flair); + PluginMain.AppendPlayerDisplayFlair(mp, p); //2015.08.09. + } + String msg="§6Note: The auto-flair plugin has been reloaded. You might need to wait 10s to have your flair.§r"; //2015.08.09. + p.sendMessage(msg); //2015.08.09. + } + //String msg="§6Reloaded config file.§r"; + //SendMessage(player, msg); //2015.08.09. + } + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + if(player!=null) + player.sendMessage("§cAn error occured. See console for details.§r"); + PluginMain.LastException=e; //2015.08.09. + } + //} + //else + //player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static Player ReloadPlayer; //2015.08.09. + private static void DoAdmin(Player player, String[] args) + { //2015.08.09. + if(player==null || player.isOp() || player.getName()=="NorbiPeti") + { + //System.out.println("Args length: " + args.length); + if(args.length==1) + { + String message="§cUsage: /u admin reload|playerinfo§r"; + SendMessage(player, message); + return; + } + //args[0] is "admin" + switch(args[1].toLowerCase()) + { + case "reload": + ReloadPlayer=player; //2015.08.09. + SendMessage(player, "§6Make sure to save the current settings before you modify and reload them! Type /u admin confirm when done.§r"); + break; + case "playerinfo": + DoPlayerInfo(player, args); + break; + case "getlasterror": + DoGetLastError(player, args); + case "confirm": + if(ReloadPlayer==player) + DoReload(player); //2015.08.09. + else + SendMessage(player, "§cYou need to do /u admin reload first.§r"); + break; + case "save": + PluginMain.SaveFiles(); //2015.08.09. + SendMessage(player, "§6Saved files. Now you can edit them and reload if you want.§r"); + break; + case "setflair": + + break; + default: + String message="§cUsage: /u admin reload|playerinfo|getlasterror|save§r"; + SendMessage(player, message); + return; + } + } + else + player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static void DoPlayerInfo(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "playerinfo" + if(args.length==2) + { + String message="§cUsage: /u admin playerinfo §r"; + SendMessage(player, message); + return; + } + if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2])) + { + String message="§cPlayer not found: "+args[2]+"§r"; + SendMessage(player, message); + return; + } + MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]); + SendMessage(player, "Player name: "+p.PlayerName); + SendMessage(player, "User flair: "+p.Flair); + SendMessage(player, "Username: "+p.UserName); + SendMessage(player, "Flair accepted: "+p.AcceptedFlair); + SendMessage(player, "Flair ignored: "+p.IgnoredFlair); + } + private static void SendMessage(Player player, String message) + { //2015.08.09. + if(player==null) + System.out.println(message); + else + player.sendMessage(message); + } + private static void DoGetLastError(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "getlasterror" + if(PluginMain.LastException!=null) + { + SendMessage(player, "Last error:"); + SendMessage(player, PluginMain.LastException.toString()); + PluginMain.LastException=null; + } + else + SendMessage(player, "There were no exceptions."); + } + private static void SetPlayerFlair(Player player, Player targetplayer, String flair) + { //2015.08.09. + flair=flair.replace('&', '§'); + MaybeOfflinePlayer.AddPlayerIfNeeded(player.getName()).Flair=flair; + if(!PluginMain.RemoveLineFromFile("customflairs.txt", targetplayer.getName())) + { + SendMessage(player, "§cError removing previous custom flair!§r"); + return; + } + File file=new File("customflairs.txt"); + try { + BufferedWriter bw; + bw = new BufferedWriter(new FileWriter(file, true)); + bw.write(targetplayer.getName()+"\n"); + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + PluginMain.LastException=e; //2015.08.09. + } + SendMessage(player, "§6The flair has been set. Player: "+targetplayer.getName()+" Flair: "+flair+"§r"); + } + private static void DoSetFlair(Player player, String args) + { + //args[0] is "admin" - args[1] is "setflair" + + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/e3/905afa0fe03e001517108d149b613203 b/.metadata/.plugins/org.eclipse.core.resources/.history/e3/905afa0fe03e001517108d149b613203 new file mode 100644 index 0000000..e6e7dea --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/e3/905afa0fe03e001517108d149b613203 @@ -0,0 +1,259 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +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; + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. + //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) + if(p.Flair==null) + { + player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); + return true; + } + switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. + { + case "accept": + { + if(p.IgnoredFlair) + p.IgnoredFlair=false; //2015.08.08. + if(!p.AcceptedFlair) + { + String flair=p.Flair; //2015.08.08. + //PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + PluginMain.AppendPlayerDisplayFlair(p, player); + p.AcceptedFlair=true; //2015.08.08. + player.sendMessage("§6Your flair has been set:§r "+flair); + } + else + player.sendMessage("§cYou already have this user's flair.§r"); + break; + } + case "ignore": + { + if(p.AcceptedFlair) + p.AcceptedFlair=false; //2015.08.08. + if(!p.IgnoredFlair) + { + p.IgnoredFlair=true; + String flair=p.Flair; //2015.08.08. + PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. + player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); + } + else + player.sendMessage("§cYou already ignored this request.§r"); + break; + } + /*case "reload": //2015.07.20. + DoReload(player); + break;*/ + case "admin": //2015.08.09. + DoAdmin(player, args); + break; + case "nonpresser": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§7(non-pr.)§r"; + break; + case "cantpress": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§r(can't press)§r"; + break; + default: + return false; + } + return true; + } + /*if(args[0].toLowerCase()=="reload") + DoReload(null); //2015.07.20.*/ + else if(args.length>0 && args[0].toLowerCase().equals("admin")) //2015.08.09. + { + DoAdmin(null, args); //2015.08.09. + return true; //2015.08.09. + } + return false; + } + private static void DoReload(Player player) + { //2015.07.20. + //if(player==null || player.isOp() || player.getName()=="NorbiPeti") + //{ + try + { + File file=new File("autoflairconfig.txt"); + if(file.exists()) + { + PluginMain.LoadFiles(true); //2015.08.09. + for(Player p : PluginMain.GetPlayers()) + { + MaybeOfflinePlayer mp = MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName()); + if(mp.Flair!=null) + { + String flair=mp.Flair; + PluginMain.RemovePlayerDisplayFlairFinal(p, flair); + //PluginMain.AppendPlayerDisplayFlairFinal(p, flair); + PluginMain.AppendPlayerDisplayFlair(mp, p); //2015.08.09. + } + String msg="§6Note: The auto-flair plugin has been reloaded. You might need to wait 10s to have your flair.§r"; //2015.08.09. + p.sendMessage(msg); //2015.08.09. + } + //String msg="§6Reloaded config file.§r"; + //SendMessage(player, msg); //2015.08.09. + } + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + if(player!=null) + player.sendMessage("§cAn error occured. See console for details.§r"); + PluginMain.LastException=e; //2015.08.09. + } + //} + //else + //player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static Player ReloadPlayer; //2015.08.09. + private static void DoAdmin(Player player, String[] args) + { //2015.08.09. + if(player==null || player.isOp() || player.getName()=="NorbiPeti") + { + //System.out.println("Args length: " + args.length); + if(args.length==1) + { + String message="§cUsage: /u admin reload|playerinfo§r"; + SendMessage(player, message); + return; + } + //args[0] is "admin" + switch(args[1].toLowerCase()) + { + case "reload": + ReloadPlayer=player; //2015.08.09. + SendMessage(player, "§6Make sure to save the current settings before you modify and reload them! Type /u admin confirm when done.§r"); + break; + case "playerinfo": + DoPlayerInfo(player, args); + break; + case "getlasterror": + DoGetLastError(player, args); + case "confirm": + if(ReloadPlayer==player) + DoReload(player); //2015.08.09. + else + SendMessage(player, "§cYou need to do /u admin reload first.§r"); + break; + case "save": + PluginMain.SaveFiles(); //2015.08.09. + SendMessage(player, "§6Saved files. Now you can edit them and reload if you want.§r"); + break; + case "setflair": + + break; + default: + String message="§cUsage: /u admin reload|playerinfo|getlasterror|save§r"; + SendMessage(player, message); + return; + } + } + else + player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static void DoPlayerInfo(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "playerinfo" + if(args.length==2) + { + String message="§cUsage: /u admin playerinfo §r"; + SendMessage(player, message); + return; + } + if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2])) + { + String message="§cPlayer not found: "+args[2]+"§r"; + SendMessage(player, message); + return; + } + MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]); + SendMessage(player, "Player name: "+p.PlayerName); + SendMessage(player, "User flair: "+p.Flair); + SendMessage(player, "Username: "+p.UserName); + SendMessage(player, "Flair accepted: "+p.AcceptedFlair); + SendMessage(player, "Flair ignored: "+p.IgnoredFlair); + } + private static void SendMessage(Player player, String message) + { //2015.08.09. + if(player==null) + System.out.println(message); + else + player.sendMessage(message); + } + private static void DoGetLastError(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "getlasterror" + if(PluginMain.LastException!=null) + { + SendMessage(player, "Last error:"); + SendMessage(player, PluginMain.LastException.toString()); + PluginMain.LastException=null; + } + else + SendMessage(player, "There were no exceptions."); + } + private static void SetPlayerFlair(Player player, Player targetplayer, String flair) + { //2015.08.09. + flair=flair.replace('&', '§'); + MaybeOfflinePlayer.AddPlayerIfNeeded(player.getName()).Flair=flair; + if(!PluginMain.RemoveLineFromFile("customflairs.txt", targetplayer.getName())) + { + SendMessage(player, "§cError removing previous custom flair!§r"); + return; + } + File file=new File("customflairs.txt"); + try { + BufferedWriter bw; + bw = new BufferedWriter(new FileWriter(file, true)); + bw.write(targetplayer.getName()+"\n"); + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + PluginMain.LastException=e; //2015.08.09. + } + SendMessage(player, "§6The flair has been set. Player: "+targetplayer.getName()+" Flair: "+flair+"§r"); + } + private static void DoSetFlair(Player player, String args) + { + //args[0] is "admin" - args[1] is "setflair" + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/e4/3060bf8dcf3e001518fa86d7ae2a1cf8 b/.metadata/.plugins/org.eclipse.core.resources/.history/e4/3060bf8dcf3e001518fa86d7ae2a1cf8 new file mode 100644 index 0000000..620a063 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/e4/3060bf8dcf3e001518fa86d7ae2a1cf8 @@ -0,0 +1,364 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.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 tk.sznp.thebuttonautoflair.MaybeOfflinePlayer.FlairClassType; + +import com.palmergames.bukkit.towny.object.Town; +import com.palmergames.bukkit.towny.object.WorldCoord; + +public class PluginMain extends JavaPlugin +{ //Translated to Java: 2015.07.15. + //A user, which flair isn't obtainable: + //https://www.reddit.com/r/thebutton/comments/31c32v/i_pressed_the_button_without_really_thinking/ + private static PluginMain Instance; + // Fired when plugin is first enabled + @Override + public void onEnable() + { + System.out.println("The Button Auto-flair Plugin by NorbiPeti (:P)"); + getServer().getPluginManager().registerEvents(new PlayerListener(), this); + this.getCommand("u").setExecutor(new Commands()); + this.getCommand("u").setUsage(this.getCommand("u").getUsage().replace('&', '§')); + Instance=this; //2015.08.08. + try { + File file=new File("flairsaccepted.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + //System.out.println("Name: " + name); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("flairsignored.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsignored.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("autoflairconfig.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + TownColors.put(s[0], s[1]); + } + br.close(); + } + //throw new IOException("Test"); //2015.08.09. + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + Runnable r=new Runnable(){public void run(){ThreadMethod();}}; + Thread t=new Thread(r); + t.start(); + } + Boolean stop=false; + // Fired when plugin is disabled + @Override + public void onDisable() + { + try + { + FileWriter fw; + fw = new FileWriter("flairsaccepted.txt"); + fw.close(); + fw = new FileWriter("flairsignored.txt"); + fw.close(); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + try { + File file=new File("flairsaccepted.txt"); + BufferedWriter bw=new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.AcceptedFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + file=new File("flairsignored.txt"); + bw = new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.IgnoredFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + stop=true; + } + + public void ThreadMethod() //<-- 2015.07.16. + { + while(!stop) + { + try + { + String body=DownloadString("https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/autoflair_system_comment_your_minecraft_name_and/.json?limit=1000"); + JSONArray json=new JSONArray(body).getJSONObject(1).getJSONObject("data").getJSONArray("children"); + for(Object obj : json) + { + JSONObject item = (JSONObject)obj; + String author=item.getJSONObject("data").getString("author"); + String ign=item.getJSONObject("data").getString("body"); + int start = ign.indexOf("IGN:") + "IGN:".length(); + int end = ign.indexOf(' ', start); + if (end == -1 || end == start) + end=ign.indexOf('\n', start); //2015.07.15. + if (end == -1 || end == start) + ign = ign.substring(start); + else + ign = ign.substring(start, end); + ign = ign.trim(); + if(HasIGFlair(ign)) + continue; + try { + Thread.sleep(10); + } catch(InterruptedException ex) { + Thread.currentThread().interrupt(); + } + String[] flairdata = DownloadString("http://karmadecay.com/thebutton-data.php?users=" + author).replace("\"", "").split(":"); + String flair; + if(flairdata.length > 1) //2015.07.15. + flair = flairdata[1]; + else + flair=""; + if (flair != "-1") + flair = flair + "s"; + else + flair = "non-presser"; + String flairclass; + if(flairdata.length>2) + flairclass = flairdata[2]; + else + flairclass="unknown"; + SetFlair(ign, flair, flairclass, author); + } + Thread.sleep(10000); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + } + + public static Exception LastException; //2015.08.09. + + public String DownloadString(String urlstr) throws MalformedURLException, IOException + { + URL url = new URL(urlstr); + URLConnection con = url.openConnection(); + con.setRequestProperty("User-Agent", "TheButtonAutoFlair"); + InputStream in = con.getInputStream(); + String encoding = con.getContentEncoding(); + encoding = encoding == null ? "UTF-8" : encoding; + String body = IOUtils.toString(in, encoding); + in.close(); + return body; + } + + public static Map TownColors=new HashMap(); //2015.07.20. + public Boolean HasIGFlair(String playername) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + return p.Flair!=null; //2015.08.08. + } + + public void SetFlair(String playername, String text, String flairclass, String username) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + String finalflair; + p.FlairDecided=true; + switch(flairclass) + { + case "press-1": + finalflair="§c("+text+")§r"; + break; + case "press-2": + finalflair="§6("+text+")§r"; + break; + case "press-3": + finalflair="§e("+text+")§r"; + break; + case "press-4": + finalflair="§a("+text+")§r"; + break; + case "press-5": + finalflair="§9("+text+")§r"; + break; + 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; + case "undecided": //2015.08.09. + p.FlairDecided=false; + finalflair=""; + break; + default: + finalflair=""; + break; + } + if(finalflair.length()==0) //<-- 2015.07.20. + return; + p.Flair=finalflair; //2015.08.08. + p.UserName=username; //2015.08.08. + System.out.println("Added new flair to "+playername+": "+finalflair); + for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08. + { + if(player.getName().equals(playername)) + { + AppendPlayerDisplayFlair(player, username, finalflair); + break; + } + } + } + + public static String GetFlair(Player player) + { //2015.07.16. + String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08. + return flair==null ? "" : flair; + } + + //public static void AppendPlayerDisplayFlair(Player player, String username, String flair) + public static void AppendPlayerDisplayFlair(MaybeOfflinePlayer player, Player p) //<-- 2015.08.09. + { + + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).IgnoredFlair) + return; + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).AcceptedFlair) + { + AppendPlayerDisplayFlairFinal(p, player.Flair); //2015.07.20. + if(!player.FlairDecided) + p.sendMessage("§9Your flair type is unknown. Are you a non-presser or a can't press? (/u nonpresser or /u cantpress)§r"); //2015.08.09. + } + else + player.sendMessage("§9Are you Reddit user "+username+"?§r §6Type /u accept or /u ignore§r"); + } + + private static void AppendPlayerDisplayFlairFinal(Player player, String flair) + { //2015.07.20. + String color = GetColorForTown(GetPlayerTown(player)); //TO!DO: Multiple colors put on first capital letters + String[] colors = color.substring(1).split("§"); + String displayname=player.getName(); //2015.08.08. + ArrayList Positions=new ArrayList<>(); + for(int i=0; i=colors.length) + { + int x=0; + for(int i=0; i GetPlayers() + { + return Instance.getServer().getOnlinePlayers(); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/e5/a0c874c7303e00151cbdba8b5f0a340e b/.metadata/.plugins/org.eclipse.core.resources/.history/e5/a0c874c7303e00151cbdba8b5f0a340e deleted file mode 100644 index ba283d2..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/e5/a0c874c7303e00151cbdba8b5f0a340e +++ /dev/null @@ -1,434 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import java.io.BufferedReader; -import java.io.BufferedWriter; -import java.io.File; -import java.io.FileReader; -import java.io.FileWriter; -import java.io.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.PlayerName+"\n"); - bw.close(); - } catch (IOException e) { - System.out.println("Error!\n"+e); - } - } - stop=true; - } - - public void ThreadMethod() //<-- 2015.07.16. - { - /*System.out.println("Sleeping for 5 seconds..."); //2015.07.20. - try { - Thread.sleep(5000); - } catch (InterruptedException e1) { - e1.printStackTrace(); - } //2015.07.20.*/ - while(!stop) - { - try - { - String body=DownloadString("https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/autoflair_system_comment_your_minecraft_name_and/.json?limit=1000"); - JSONArray json=new JSONArray(body).getJSONObject(1).getJSONObject("data").getJSONArray("children"); - for(Object obj : json) - { - JSONObject item = (JSONObject)obj; - String author=item.getJSONObject("data").getString("author"); - String ign=item.getJSONObject("data").getString("body"); - int start = ign.indexOf("IGN:") + "IGN:".length(); - int end = ign.indexOf(' ', start); - if (end == -1 || end == start) - end=ign.indexOf('\n', start); //2015.07.15. - if (end == -1 || end == start) - ign = ign.substring(start); - else - ign = ign.substring(start, end); - ign = ign.trim(); - if(HasIGFlair(ign)) - continue; - //System.out.println("Author: "+author); - try { - Thread.sleep(10); - } catch(InterruptedException ex) { - Thread.currentThread().interrupt(); - } - String[] flairdata = DownloadString("http://karmadecay.com/thebutton-data.php?users=" + author).replace("\"", "").split(":"); - String flair; - if(flairdata.length > 1) //2015.07.15. - flair = flairdata[1]; - else - flair=""; - if (flair != "-1") - flair = flair + "s"; - else - flair = "non-presser"; - String flairclass; - //System.out.println("flairdata.length:"+flairdata.length); - if(flairdata.length>2) - flairclass = flairdata[2]; - else - flairclass="unknown"; - SetFlair(ign, flair, flairclass, author); - } - Thread.sleep(10000); - } - catch(Exception e) - { - System.out.println("Error!\n"+e); - } - } - } - - public String DownloadString(String urlstr) throws MalformedURLException, IOException - { - URL url = new URL(urlstr); - URLConnection con = url.openConnection(); - con.setRequestProperty("User-Agent", "TheButtonAutoFlair"); - InputStream in = con.getInputStream(); - String encoding = con.getContentEncoding(); - encoding = encoding == null ? "UTF-8" : encoding; - String body = IOUtils.toString(in, encoding); - in.close(); - return body; - } - - //It has to store offline player flairs too, therefore it can't use Player object - /*public static Map PlayerFlairs=new HashMap(); - public static Map PlayerUserNames=new HashMap(); - //public Map PlayerFlairs=new HashMap(); - public static ArrayList Players=new ArrayList(); - public static ArrayList AcceptedPlayers=new ArrayList(); //2015.07.16. - public static ArrayList IgnoredPlayers=new ArrayList(); //2015.07.16. - //public static Map PlayerTowns=new HashMap(); //2015.07.20.*/ - public static Map TownColors=new HashMap(); //2015.07.20. - public Boolean HasIGFlair(String playername) - { - /*Player player=null; - for(Player p : Players) - { - if(p.getName()==playername) - { - player=p; - break; - } - } - if(player==null) - return false;*/ - //return PlayerFlairs.containsKey(playername); - //return MaybeOfflinePlayer.AllPlayers.containsKey(playername); - MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. - return p.Flair!=null; //2015.08.08. - } - - public void SetFlair(String playername, String text, String flairclass, String username) - { - String finalflair; - switch(flairclass) - { - case "press-1": - finalflair="§c("+text+")§r"; - break; - case "press-2": - finalflair="§6("+text+")§r"; - break; - case "press-3": - finalflair="§e("+text+")§r"; - break; - case "press-4": - finalflair="§a("+text+")§r"; - break; - case "press-5": - finalflair="§9("+text+")§r"; - break; - case "press-6": - finalflair="§5("+text+")§r"; - break; - case "no-press": - finalflair="§7(non-pr.)§r"; - break; - case "cheater": - finalflair="§5("+text+")§r"; - break; - case "cant-press": //2015.08.08. - finalflair="§r(can't press)§r"; - break; - default: - finalflair=""; - break; - } - if(finalflair.length()==0) //<-- 2015.07.20. - return; - //PlayerFlairs.put(playername, finalflair); - //PlayerUserNames.put(playername, username); - MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. - p.Flair=finalflair; //2015.08.08. - p.UserName=username; //2015.08.08. - /*for(Player player : Players) - { - if(player.getName()==playername) - { - PlayerFlairs.put(player, finalflair); - break; - } - }*/ - //System.out.println("SetFlair - playername: "+playername+" text: "+text+" flairclass: "+flairclass); - System.out.println("Added new flair to "+playername+": "+finalflair); - //for(Player player : Players) - for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08. - { - //System.out.println("Online player: "+player.getName()); - //System.out.println("player.getName ("+player.getName()+") == playername ("+playername+"): "+(player.getName()==playername)); - if(player.getName().equals(playername)) - { - //System.out.println("DisplayName: "+player.getDisplayName()); - //player.setDisplayName(player.getDisplayName()+finalflair); - AppendPlayerDisplayFlair(player, username, finalflair); - //System.out.println("DisplayName: "+player.getDisplayName()); - break; - } - } - } - - public static String GetFlair(Player player) - { //2015.07.16. - //String flair=PlayerFlairs.get(player.getName()); - String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08. - return flair==null ? "" : flair; - } - - public static void AppendPlayerDisplayFlair(Player player, String username, String flair) - { - //if(IgnoredPlayers.contains(player.getName())) - if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).IgnoredFlair) - return; - //if(AcceptedPlayers.contains(player.getName())) - if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).AcceptedFlair) - //player.setDisplayName(player.getDisplayName()+flair); - AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. - else - player.sendMessage("§9Are you Reddit user "+username+"?§r §6Type /u accept or /u ignore§r"); - } - - public static void AppendPlayerDisplayFlairFinal(Player player, String flair) - { //2015.07.20. - //System.out.println("A"); - String color = GetColorForTown(GetPlayerTown(player)); //TO!DO: Multiple colors put on first capital letters - String[] colors = color.substring(1).split("§"); - //String displayname=player.getDisplayName(); - String displayname=player.getName(); //2015.08.08. - ArrayList Positions=new ArrayList<>(); - //System.out.println("B"); - for(int i=0; i=colors.length) - { - //System.out.println("D"); - int x=0; - for(int i=0; i towns = TownyUniverse.getDataSource().getTowns(); - try { - Town town = WorldCoord.parseWorldCoord(player).getTownBlock().getTown(); //TODO - return town.getName(); - } catch (Exception e) { - return ""; - } - } - - public static void RemovePlayerDisplayFlairFinal(Player player, String flair) - { //2015.07.20. - //String color = GetColorForTown(GetPlayerTown(player)); - //String dname=player.getDisplayName(); - //player.setDisplayName(dname.substring(dname.indexOf(color)+3, dname.indexOf(flair))); - //MaybeOfflinePlayer.AllPlayers.get(player.getName()).DisplayName=null; //2015.08.08. - MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair=null; //2015.08.08. - } - - public static Collection GetPlayers() - { - return Instance.getServer().getOnlinePlayers(); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/e6/c0b7626f043e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/e6/c0b7626f043e00151c31fb33fff4337f deleted file mode 100644 index 87c0c13..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/e6/c0b7626f043e00151c31fb33fff4337f +++ /dev/null @@ -1,126 +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; - 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 deleted file mode 100644 index f174b9f..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/e6/d0c6108f083e00151c31fb33fff4337f +++ /dev/null @@ -1,126 +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; - 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/e8/90448e80dd3e001517108d149b613203 b/.metadata/.plugins/org.eclipse.core.resources/.history/e8/90448e80dd3e001517108d149b613203 new file mode 100644 index 0000000..3aeeb6d --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/e8/90448e80dd3e001517108d149b613203 @@ -0,0 +1,408 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStream; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLConnection; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + +import org.apache.commons.io.IOUtils; +import org.bukkit.entity.Player; +import org.bukkit.plugin.java.JavaPlugin; +import org.json.JSONArray; +import org.json.JSONObject; + +import com.palmergames.bukkit.towny.object.Town; +import com.palmergames.bukkit.towny.object.WorldCoord; + +public class PluginMain extends JavaPlugin +{ //Translated to Java: 2015.07.15. + //A user, which flair isn't obtainable: + //https://www.reddit.com/r/thebutton/comments/31c32v/i_pressed_the_button_without_really_thinking/ + private static PluginMain Instance; + // Fired when plugin is first enabled + @Override + public void onEnable() + { + System.out.println("The Button Auto-flair Plugin by NorbiPeti (:P)"); + getServer().getPluginManager().registerEvents(new PlayerListener(), this); + this.getCommand("u").setExecutor(new Commands()); + this.getCommand("u").setUsage(this.getCommand("u").getUsage().replace('&', '§')); + Instance=this; //2015.08.08. + LoadFiles(false); //2015.08.09. + Runnable r=new Runnable(){public void run(){ThreadMethod();}}; + Thread t=new Thread(r); + t.start(); + } + Boolean stop=false; + // Fired when plugin is disabled + @Override + public void onDisable() + { + SaveFiles(); //2015.08.09. + stop=true; + } + + public void ThreadMethod() //<-- 2015.07.16. + { + while(!stop) + { + try + { + String body=DownloadString("https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/autoflair_system_comment_your_minecraft_name_and/.json?limit=1000"); + JSONArray json=new JSONArray(body).getJSONObject(1).getJSONObject("data").getJSONArray("children"); + for(Object obj : json) + { + JSONObject item = (JSONObject)obj; + String author=item.getJSONObject("data").getString("author"); + String ign=item.getJSONObject("data").getString("body"); + int start = ign.indexOf("IGN:") + "IGN:".length(); + if(start==-1) + continue; //2015.08.09. + int end = ign.indexOf(' ', start); + if (end == -1 || end == start) + end=ign.indexOf('\n', start); //2015.07.15. + if (end == -1 || end == start) + ign = ign.substring(start); + else + ign = ign.substring(start, end); + ign = ign.trim(); + if(HasIGFlair(ign)) + continue; + try { + Thread.sleep(10); + } catch(InterruptedException ex) { + Thread.currentThread().interrupt(); + } + String[] flairdata = DownloadString("http://karmadecay.com/thebutton-data.php?users=" + author).replace("\"", "").split(":"); + String flair; + if(flairdata.length > 1) //2015.07.15. + flair = flairdata[1]; + else + flair=""; + if (flair != "-1") + flair = flair + "s"; + else + flair = "non-presser"; + String flairclass; + if(flairdata.length>2) + flairclass = flairdata[2]; + else + flairclass="unknown"; + SetFlair(ign, flair, flairclass, author); + } + Thread.sleep(10000); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + } + + public static Exception LastException; //2015.08.09. + + public String DownloadString(String urlstr) throws MalformedURLException, IOException + { + URL url = new URL(urlstr); + URLConnection con = url.openConnection(); + con.setRequestProperty("User-Agent", "TheButtonAutoFlair"); + InputStream in = con.getInputStream(); + String encoding = con.getContentEncoding(); + encoding = encoding == null ? "UTF-8" : encoding; + String body = IOUtils.toString(in, encoding); + in.close(); + return body; + } + + public static Map TownColors=new HashMap(); //2015.07.20. + public Boolean HasIGFlair(String playername) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + return p.Flair!=null; //2015.08.08. + } + + public void SetFlair(String playername, String text, String flairclass, String username) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + String finalflair; + p.FlairDecided=true; + switch(flairclass) + { + case "press-1": + finalflair="§c("+text+")§r"; + break; + case "press-2": + finalflair="§6("+text+")§r"; + break; + case "press-3": + finalflair="§e("+text+")§r"; + break; + case "press-4": + finalflair="§a("+text+")§r"; + break; + case "press-5": + finalflair="§9("+text+")§r"; + break; + 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; + case "undecided": //2015.08.09. + p.FlairDecided=false; + finalflair=""; + break; + default: + finalflair=""; + break; + } + if(finalflair.length()==0) //<-- 2015.07.20. + return; + p.Flair=finalflair; //2015.08.08. + p.UserName=username; //2015.08.08. + System.out.println("Added new flair to "+playername+": "+finalflair); + for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08. + { + if(player.getName().equals(playername)) + { + //AppendPlayerDisplayFlair(player, username, finalflair); + AppendPlayerDisplayFlair(p, player); + break; + } + } + } + + public static String GetFlair(Player player) + { //2015.07.16. + String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08. + return flair==null ? "" : flair; + } + + //public static void AppendPlayerDisplayFlair(Player player, String username, String flair) + public static void AppendPlayerDisplayFlair(MaybeOfflinePlayer player, Player p) //<-- 2015.08.09. + { + + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).IgnoredFlair) + return; + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).AcceptedFlair) + { + AppendPlayerDisplayFlairFinal(p, player.Flair); //2015.07.20. + if(!player.FlairDecided) + p.sendMessage("§9Your flair type is unknown. Are you a non-presser or a can't press? (/u nonpresser or /u cantpress)§r"); //2015.08.09. + } + else + p.sendMessage("§9Are you Reddit user "+player.UserName+"?§r §6Type /u accept or /u ignore§r"); + } + + private static void AppendPlayerDisplayFlairFinal(Player player, String flair) + { //2015.07.20. + String color = GetColorForTown(GetPlayerTown(player)); //TO!DO: Multiple colors put on first capital letters + String[] colors = color.substring(1).split("§"); + String displayname=player.getName(); //2015.08.08. + ArrayList Positions=new ArrayList<>(); + for(int i=0; i=colors.length) + { + int x=0; + for(int i=0; i GetPlayers() + { + return Instance.getServer().getOnlinePlayers(); + } + + public static void LoadFiles(boolean reload) //<-- 2015.08.09. + { + if(reload) + { //2015.08.09. + System.out.println("Auto-flair plugin cleanup for reloading..."); + MaybeOfflinePlayer.AllPlayers.clear(); + TownColors.clear(); + } + System.out.println("Loading files for auto-flair plugin..."); //2015.08.09. + try { + File file=new File("flairsaccepted.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + //System.out.println("Name: " + name); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("flairsignored.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsignored.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("autoflairconfig.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + TownColors.put(s[0], s[1]); + } + br.close(); + } + file=new File("autoflairdecisions.txt"); //2015.08.09. + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + MaybeOfflinePlayer.AddPlayerIfNeeded(s[0]).Flair=s[1]; //2015.08.09. + } + br.close(); + } + //throw new IOException("Test"); //2015.08.09. + System.out.println("Auto-flair plugin loaded files!"); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + public static void SaveFiles() //<-- 2015.08.09. + { + try + { + FileWriter fw; + fw = new FileWriter("flairsaccepted.txt"); + fw.close(); + fw = new FileWriter("flairsignored.txt"); + fw.close(); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + try { + File file=new File("flairsaccepted.txt"); + BufferedWriter bw=new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.AcceptedFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + file=new File("flairsignored.txt"); + bw = new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.IgnoredFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + public static void SetPlayerFlair(Player player, String flair) + { //2015.08.09. + flair=flair.replace('&', '§'); + MaybeOfflinePlayer.AddPlayerIfNeeded(player.getName()).Flair=flair; + File file=new File("flairsaccepted.txt"); + BufferedWriter bw=new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) + { + if(!player.AcceptedFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/ea/40a8228bfe3d00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/ea/40a8228bfe3d00151c31fb33fff4337f deleted file mode 100644 index fe7d591..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/ea/40a8228bfe3d00151c31fb33fff4337f +++ /dev/null @@ -1,122 +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()); - 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/eb/3086890bd03e001518fa86d7ae2a1cf8 b/.metadata/.plugins/org.eclipse.core.resources/.history/eb/3086890bd03e001518fa86d7ae2a1cf8 new file mode 100644 index 0000000..ce49e4e --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/eb/3086890bd03e001518fa86d7ae2a1cf8 @@ -0,0 +1,198 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; + +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class Commands implements CommandExecutor { + // This method is called, when somebody uses our command + @Override + public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { + if (sender instanceof Player) { + Player player = (Player) sender; + if(args.length<1) + return false; + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. + //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) + if(p.Flair==null) + { + player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); + return true; + } + switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. + { + case "accept": + { + if(p.IgnoredFlair) + p.IgnoredFlair=false; //2015.08.08. + if(!p.AcceptedFlair) + { + String flair=p.Flair; //2015.08.08. + //PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + PluginMain.AppendPlayerDisplayFlair(p, player); + p.AcceptedFlair=true; //2015.08.08. + player.sendMessage("§6Your flair has been set:§r "+flair); + } + else + player.sendMessage("§cYou already have this user's flair.§r"); + break; + } + case "ignore": + { + if(p.AcceptedFlair) + p.AcceptedFlair=false; //2015.08.08. + if(!p.IgnoredFlair) + { + p.IgnoredFlair=true; + String flair=p.Flair; //2015.08.08. + PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. + player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); + } + else + player.sendMessage("§cYou already ignored this request.§r"); + break; + } + /*case "reload": //2015.07.20. + DoReload(player); + break;*/ + case "admin": //2015.08.09. + DoAdmin(player, args); + break; + case "nonpresser": //2015.08.09. + break; + default: + return false; + } + return true; + } + /*if(args[0].toLowerCase()=="reload") + DoReload(null); //2015.07.20.*/ + else if(args.length>0 && args[0].toLowerCase().equals("admin")) //2015.08.09. + { + DoAdmin(null, args); //2015.08.09. + return true; //2015.08.09. + } + return false; + } + private static void DoReload(Player player) + { //2015.07.20. + //if(player==null || player.isOp() || player.getName()=="NorbiPeti") + //{ + try + { + File file=new File("autoflairconfig.txt"); + if(file.exists()) + { + PluginMain.TownColors.clear(); + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + PluginMain.TownColors.put(s[0], s[1]); + } + br.close(); + for(Player p : PluginMain.GetPlayers()) + { + MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName()); + if(mp.Flair!=null) + { + String flair=mp.Flair; + PluginMain.RemovePlayerDisplayFlairFinal(p, flair); + //PluginMain.AppendPlayerDisplayFlairFinal(p, flair); + PluginMain.AppendPlayerDisplayFlair(player, p); + } + } + String msg="§6Reloaded config file.§r"; + SendMessage(player, msg); //2015.08.09. + } + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + if(player!=null) + player.sendMessage("§cAn error occured. See console for details.§r"); + PluginMain.LastException=e; //2015.08.09. + } + //} + //else + //player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static void DoAdmin(Player player, String[] args) + { //2015.08.09. + if(player==null || player.isOp() || player.getName()=="NorbiPeti") + { + //System.out.println("Args length: " + args.length); + if(args.length==1) + { + String message="§cUsage: /u admin reload|playerinfo§r"; + SendMessage(player, message); + return; + } + //args[0] is "admin" + switch(args[1].toLowerCase()) + { + case "reload": + DoReload(player); + break; + case "playerinfo": + DoPlayerInfo(player, args); + break; + case "getlasterror": + DoGetLastError(player, args); + default: + String message="§cUsage: /u admin reload|playerinfo§r"; + SendMessage(player, message); + return; + } + } + else + player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static void DoPlayerInfo(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "playerinfo" + if(args.length==2) + { + String message="§cUsage: /u admin playerinfo §r"; + SendMessage(player, message); + return; + } + if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2])) + { + String message="§cPlayer not found: "+args[2]+"§r"; + SendMessage(player, message); + return; + } + MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]); + SendMessage(player, "Player name: "+p.PlayerName); + SendMessage(player, "User flair: "+p.Flair); + SendMessage(player, "Username: "+p.UserName); + SendMessage(player, "Flair accepted: "+p.AcceptedFlair); + SendMessage(player, "Flair ignored: "+p.IgnoredFlair); + } + private static void SendMessage(Player player, String message) + { //2015.08.09. + if(player==null) + System.out.println(message); + else + player.sendMessage(message); + } + private static void DoGetLastError(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "getlasterror" + if(PluginMain.LastException!=null) + { + SendMessage(player, "Last error:"); + SendMessage(player, PluginMain.LastException.toString()); + PluginMain.LastException=null; + } + else + SendMessage(player, "There were no exceptions."); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/eb/803bcb6fde3e001517108d149b613203 b/.metadata/.plugins/org.eclipse.core.resources/.history/eb/803bcb6fde3e001517108d149b613203 new file mode 100644 index 0000000..ce1d794 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/eb/803bcb6fde3e001517108d149b613203 @@ -0,0 +1,409 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStream; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLConnection; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + +import org.apache.commons.io.IOUtils; +import org.bukkit.entity.Player; +import org.bukkit.plugin.java.JavaPlugin; +import org.json.JSONArray; +import org.json.JSONObject; + +import com.palmergames.bukkit.towny.object.Town; +import com.palmergames.bukkit.towny.object.WorldCoord; + +public class PluginMain extends JavaPlugin +{ //Translated to Java: 2015.07.15. + //A user, which flair isn't obtainable: + //https://www.reddit.com/r/thebutton/comments/31c32v/i_pressed_the_button_without_really_thinking/ + private static PluginMain Instance; + // Fired when plugin is first enabled + @Override + public void onEnable() + { + System.out.println("The Button Auto-flair Plugin by NorbiPeti (:P)"); + getServer().getPluginManager().registerEvents(new PlayerListener(), this); + this.getCommand("u").setExecutor(new Commands()); + this.getCommand("u").setUsage(this.getCommand("u").getUsage().replace('&', '§')); + Instance=this; //2015.08.08. + LoadFiles(false); //2015.08.09. + Runnable r=new Runnable(){public void run(){ThreadMethod();}}; + Thread t=new Thread(r); + t.start(); + } + Boolean stop=false; + // Fired when plugin is disabled + @Override + public void onDisable() + { + SaveFiles(); //2015.08.09. + stop=true; + } + + public void ThreadMethod() //<-- 2015.07.16. + { + while(!stop) + { + try + { + String body=DownloadString("https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/autoflair_system_comment_your_minecraft_name_and/.json?limit=1000"); + JSONArray json=new JSONArray(body).getJSONObject(1).getJSONObject("data").getJSONArray("children"); + for(Object obj : json) + { + JSONObject item = (JSONObject)obj; + String author=item.getJSONObject("data").getString("author"); + String ign=item.getJSONObject("data").getString("body"); + int start = ign.indexOf("IGN:") + "IGN:".length(); + if(start==-1) + continue; //2015.08.09. + int end = ign.indexOf(' ', start); + if (end == -1 || end == start) + end=ign.indexOf('\n', start); //2015.07.15. + if (end == -1 || end == start) + ign = ign.substring(start); + else + ign = ign.substring(start, end); + ign = ign.trim(); + if(HasIGFlair(ign)) + continue; + try { + Thread.sleep(10); + } catch(InterruptedException ex) { + Thread.currentThread().interrupt(); + } + String[] flairdata = DownloadString("http://karmadecay.com/thebutton-data.php?users=" + author).replace("\"", "").split(":"); + String flair; + if(flairdata.length > 1) //2015.07.15. + flair = flairdata[1]; + else + flair=""; + if (flair != "-1") + flair = flair + "s"; + else + flair = "non-presser"; + String flairclass; + if(flairdata.length>2) + flairclass = flairdata[2]; + else + flairclass="unknown"; + SetFlair(ign, flair, flairclass, author); + } + Thread.sleep(10000); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + } + + public static Exception LastException; //2015.08.09. + + public String DownloadString(String urlstr) throws MalformedURLException, IOException + { + URL url = new URL(urlstr); + URLConnection con = url.openConnection(); + con.setRequestProperty("User-Agent", "TheButtonAutoFlair"); + InputStream in = con.getInputStream(); + String encoding = con.getContentEncoding(); + encoding = encoding == null ? "UTF-8" : encoding; + String body = IOUtils.toString(in, encoding); + in.close(); + return body; + } + + public static Map TownColors=new HashMap(); //2015.07.20. + public Boolean HasIGFlair(String playername) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + return p.Flair!=null; //2015.08.08. + } + + public void SetFlair(String playername, String text, String flairclass, String username) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + String finalflair; + p.FlairDecided=true; + switch(flairclass) + { + case "press-1": + finalflair="§c("+text+")§r"; + break; + case "press-2": + finalflair="§6("+text+")§r"; + break; + case "press-3": + finalflair="§e("+text+")§r"; + break; + case "press-4": + finalflair="§a("+text+")§r"; + break; + case "press-5": + finalflair="§9("+text+")§r"; + break; + 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; + case "undecided": //2015.08.09. + p.FlairDecided=false; + finalflair=""; + break; + default: + finalflair=""; + break; + } + if(finalflair.length()==0) //<-- 2015.07.20. + return; + p.Flair=finalflair; //2015.08.08. + p.UserName=username; //2015.08.08. + System.out.println("Added new flair to "+playername+": "+finalflair); + for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08. + { + if(player.getName().equals(playername)) + { + //AppendPlayerDisplayFlair(player, username, finalflair); + AppendPlayerDisplayFlair(p, player); + break; + } + } + } + + public static String GetFlair(Player player) + { //2015.07.16. + String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08. + return flair==null ? "" : flair; + } + + //public static void AppendPlayerDisplayFlair(Player player, String username, String flair) + public static void AppendPlayerDisplayFlair(MaybeOfflinePlayer player, Player p) //<-- 2015.08.09. + { + + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).IgnoredFlair) + return; + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).AcceptedFlair) + { + AppendPlayerDisplayFlairFinal(p, player.Flair); //2015.07.20. + if(!player.FlairDecided) + p.sendMessage("§9Your flair type is unknown. Are you a non-presser or a can't press? (/u nonpresser or /u cantpress)§r"); //2015.08.09. + } + else + p.sendMessage("§9Are you Reddit user "+player.UserName+"?§r §6Type /u accept or /u ignore§r"); + } + + private static void AppendPlayerDisplayFlairFinal(Player player, String flair) + { //2015.07.20. + String color = GetColorForTown(GetPlayerTown(player)); //TO!DO: Multiple colors put on first capital letters + String[] colors = color.substring(1).split("§"); + String displayname=player.getName(); //2015.08.08. + ArrayList Positions=new ArrayList<>(); + for(int i=0; i=colors.length) + { + int x=0; + for(int i=0; i GetPlayers() + { + return Instance.getServer().getOnlinePlayers(); + } + + public static void LoadFiles(boolean reload) //<-- 2015.08.09. + { + if(reload) + { //2015.08.09. + System.out.println("Auto-flair plugin cleanup for reloading..."); + MaybeOfflinePlayer.AllPlayers.clear(); + TownColors.clear(); + } + System.out.println("Loading files for auto-flair plugin..."); //2015.08.09. + try { + File file=new File("flairsaccepted.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + //System.out.println("Name: " + name); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("flairsignored.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsignored.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("autoflairconfig.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + TownColors.put(s[0], s[1]); + } + br.close(); + } + file=new File("customflairs.txt"); //2015.08.09. + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + MaybeOfflinePlayer.AddPlayerIfNeeded(s[0]).Flair=s[1]; //2015.08.09. + } + br.close(); + } + //throw new IOException("Test"); //2015.08.09. + System.out.println("Auto-flair plugin loaded files!"); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + public static void SaveFiles() //<-- 2015.08.09. + { + try + { + FileWriter fw; + fw = new FileWriter("flairsaccepted.txt"); + fw.close(); + fw = new FileWriter("flairsignored.txt"); + fw.close(); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + try { + File file=new File("flairsaccepted.txt"); + BufferedWriter bw=new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.AcceptedFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + file=new File("flairsignored.txt"); + bw = new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.IgnoredFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + public static void SetPlayerFlair(Player player, String flair) + { //2015.08.09. + flair=flair.replace('&', '§'); + MaybeOfflinePlayer.AddPlayerIfNeeded(player.getName()).Flair=flair; + File file=new File("customflairs.txt"); + BufferedWriter bw; + try { + bw = new BufferedWriter(new FileWriter(file, true)); + bw.write(player.getName()+"\n"); + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/eb/80c8e1dade3e001517108d149b613203 b/.metadata/.plugins/org.eclipse.core.resources/.history/eb/80c8e1dade3e001517108d149b613203 new file mode 100644 index 0000000..bf077b5 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/eb/80c8e1dade3e001517108d149b613203 @@ -0,0 +1,228 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; + +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class Commands implements CommandExecutor { + // This method is called, when somebody uses our command + @Override + public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { + if (sender instanceof Player) { + Player player = (Player) sender; + if(args.length<1) + return false; + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. + //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) + if(p.Flair==null) + { + player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); + return true; + } + switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. + { + case "accept": + { + if(p.IgnoredFlair) + p.IgnoredFlair=false; //2015.08.08. + if(!p.AcceptedFlair) + { + String flair=p.Flair; //2015.08.08. + //PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + PluginMain.AppendPlayerDisplayFlair(p, player); + p.AcceptedFlair=true; //2015.08.08. + player.sendMessage("§6Your flair has been set:§r "+flair); + } + else + player.sendMessage("§cYou already have this user's flair.§r"); + break; + } + case "ignore": + { + if(p.AcceptedFlair) + p.AcceptedFlair=false; //2015.08.08. + if(!p.IgnoredFlair) + { + p.IgnoredFlair=true; + String flair=p.Flair; //2015.08.08. + PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. + player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); + } + else + player.sendMessage("§cYou already ignored this request.§r"); + break; + } + /*case "reload": //2015.07.20. + DoReload(player); + break;*/ + case "admin": //2015.08.09. + DoAdmin(player, args); + break; + case "nonpresser": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§7(non-pr.)§r"; + break; + case "cantpress": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§r(can't press)§r"; + break; + default: + return false; + } + return true; + } + /*if(args[0].toLowerCase()=="reload") + DoReload(null); //2015.07.20.*/ + else if(args.length>0 && args[0].toLowerCase().equals("admin")) //2015.08.09. + { + DoAdmin(null, args); //2015.08.09. + return true; //2015.08.09. + } + return false; + } + private static void DoReload(Player player) + { //2015.07.20. + //if(player==null || player.isOp() || player.getName()=="NorbiPeti") + //{ + try + { + File file=new File("autoflairconfig.txt"); + if(file.exists()) + { + PluginMain.LoadFiles(true); //2015.08.09. + for(Player p : PluginMain.GetPlayers()) + { + MaybeOfflinePlayer mp = MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName()); + if(mp.Flair!=null) + { + String flair=mp.Flair; + PluginMain.RemovePlayerDisplayFlairFinal(p, flair); + //PluginMain.AppendPlayerDisplayFlairFinal(p, flair); + PluginMain.AppendPlayerDisplayFlair(mp, p); //2015.08.09. + } + String msg="§6Note: The auto-flair plugin has been reloaded. You might need to wait 10s to have your flair.§r"; //2015.08.09. + p.sendMessage(msg); //2015.08.09. + } + //String msg="§6Reloaded config file.§r"; + //SendMessage(player, msg); //2015.08.09. + } + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + if(player!=null) + player.sendMessage("§cAn error occured. See console for details.§r"); + PluginMain.LastException=e; //2015.08.09. + } + //} + //else + //player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static Player ReloadPlayer; //2015.08.09. + private static void DoAdmin(Player player, String[] args) + { //2015.08.09. + if(player==null || player.isOp() || player.getName()=="NorbiPeti") + { + //System.out.println("Args length: " + args.length); + if(args.length==1) + { + String message="§cUsage: /u admin reload|playerinfo§r"; + SendMessage(player, message); + return; + } + //args[0] is "admin" + switch(args[1].toLowerCase()) + { + case "reload": + ReloadPlayer=player; //2015.08.09. + SendMessage(player, "§6Make sure to save the current settings before you modify and reload them! Type /u admin confirm when done.§r"); + break; + case "playerinfo": + DoPlayerInfo(player, args); + break; + case "getlasterror": + DoGetLastError(player, args); + case "confirm": + if(ReloadPlayer==player) + DoReload(player); //2015.08.09. + else + SendMessage(player, "§cYou need to do /u admin reload first.§r"); + break; + case "save": + PluginMain.SaveFiles(); //2015.08.09. + SendMessage(player, "§6Saved files. Now you can edit them and reload if you want.§r"); + break; + default: + String message="§cUsage: /u admin reload|playerinfo|getlasterror§r"; + SendMessage(player, message); + return; + } + } + else + player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static void DoPlayerInfo(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "playerinfo" + if(args.length==2) + { + String message="§cUsage: /u admin playerinfo §r"; + SendMessage(player, message); + return; + } + if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2])) + { + String message="§cPlayer not found: "+args[2]+"§r"; + SendMessage(player, message); + return; + } + MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]); + SendMessage(player, "Player name: "+p.PlayerName); + SendMessage(player, "User flair: "+p.Flair); + SendMessage(player, "Username: "+p.UserName); + SendMessage(player, "Flair accepted: "+p.AcceptedFlair); + SendMessage(player, "Flair ignored: "+p.IgnoredFlair); + } + private static void SendMessage(Player player, String message) + { //2015.08.09. + if(player==null) + System.out.println(message); + else + player.sendMessage(message); + } + private static void DoGetLastError(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "getlasterror" + if(PluginMain.LastException!=null) + { + SendMessage(player, "Last error:"); + SendMessage(player, PluginMain.LastException.toString()); + PluginMain.LastException=null; + } + else + SendMessage(player, "There were no exceptions."); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/eb/e0406b19853e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/eb/e0406b19853e00151ce8ff6d4f74dabd deleted file mode 100644 index cf9e3b7..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/eb/e0406b19853e00151ce8ff6d4f74dabd +++ /dev/null @@ -1,122 +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; - MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. - //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - if(p.Flair==null) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. - { - case "accept": - { - if(p.IgnoredFlair) - p.IgnoredFlair=false; //2015.08.08. - if(!p.AcceptedFlair) - { - String flair=p.Flair; //2015.08.08. - PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. - p.AcceptedFlair=true; //2015.08.08. - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("§cYou already have this user's flair.§r"); - break; - } - case "ignore": - { - if(p.AcceptedFlair) - p.AcceptedFlair=false; //2015.08.08. - if(!p.IgnoredFlair) - { - p.IgnoredFlair=true; - String flair=p.Flair; //2015.08.08. - PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. - player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); - } - else - player.sendMessage("§cYou already ignored this request.§r"); - break; - } - case "reload": //2015.07.20. - DoReload(player); - break; - case "showerrors": //2015.08.09. - DoShowErrors(player); - break; - default: - return false; - } - return true; - } - - if(args[0].toLowerCase()=="reload") - DoReload(null); //2015.07.20. - else if(args[0].toLowerCase()=="showerrors") - DoShowErrors(null); - return false; - } - private static void DoReload(Player player) - { //2015.07.20. - if(player==null || player.isOp() || player.getName()=="NorbiPeti") - { - try - { - File file=new File("autoflairconfig.txt"); - if(file.exists()) - { - PluginMain.TownColors.clear(); - BufferedReader br=new BufferedReader(new FileReader(file)); - String line; - while((line=br.readLine())!=null) - { - String[] s=line.split(" "); - PluginMain.TownColors.put(s[0], s[1]); - } - br.close(); - for(Player p : PluginMain.GetPlayers()) - { - MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName()); - if(mp.Flair!=null) - { - String flair=mp.Flair; - PluginMain.RemovePlayerDisplayFlairFinal(p, flair); - PluginMain.AppendPlayerDisplayFlairFinal(p, flair); - } - } - String msg="§6Reloaded config file.§r"; - if(player!=null) - player.sendMessage(msg); - else - System.out.println(msg); - } - } - catch(Exception e) - { - System.out.println("Error!\n"+e); - if(player!=null) - player.sendMessage("§cAn error occured. See console for details.§r"); - } - } - else - player.sendMessage("§cYou need to be OP to use this command.§r"); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/ec/d0870f36883e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/ec/d0870f36883e00151ce8ff6d4f74dabd deleted file mode 100644 index 897b7ad..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/ec/d0870f36883e00151ce8ff6d4f74dabd +++ /dev/null @@ -1,163 +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; - MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. - //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - if(p.Flair==null) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. - { - case "accept": - { - if(p.IgnoredFlair) - p.IgnoredFlair=false; //2015.08.08. - if(!p.AcceptedFlair) - { - String flair=p.Flair; //2015.08.08. - PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. - p.AcceptedFlair=true; //2015.08.08. - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("§cYou already have this user's flair.§r"); - break; - } - case "ignore": - { - if(p.AcceptedFlair) - p.AcceptedFlair=false; //2015.08.08. - if(!p.IgnoredFlair) - { - p.IgnoredFlair=true; - String flair=p.Flair; //2015.08.08. - PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. - player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); - } - else - player.sendMessage("§cYou already ignored this request.§r"); - break; - } - /*case "reload": //2015.07.20. - DoReload(player); - break;*/ - case "admin": //2015.08.09. - DoAdmin(player, args); - break; - default: - return false; - } - return true; - } - - /*if(args[0].toLowerCase()=="reload") - DoReload(null); //2015.07.20.*/ - else if(args[0].toLowerCase()=="admin") - DoAdmin(null, args); //2015.08.09. - return false; - } - private static void DoReload(Player player) - { //2015.07.20. - //if(player==null || player.isOp() || player.getName()=="NorbiPeti") - //{ - try - { - File file=new File("autoflairconfig.txt"); - if(file.exists()) - { - PluginMain.TownColors.clear(); - BufferedReader br=new BufferedReader(new FileReader(file)); - String line; - while((line=br.readLine())!=null) - { - String[] s=line.split(" "); - PluginMain.TownColors.put(s[0], s[1]); - } - br.close(); - for(Player p : PluginMain.GetPlayers()) - { - MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName()); - if(mp.Flair!=null) - { - String flair=mp.Flair; - PluginMain.RemovePlayerDisplayFlairFinal(p, flair); - PluginMain.AppendPlayerDisplayFlairFinal(p, flair); - } - } - String msg="§6Reloaded config file.§r"; - if(player!=null) - player.sendMessage(msg); - else - System.out.println(msg); - } - } - catch(Exception e) - { - System.out.println("Error!\n"+e); - if(player!=null) - player.sendMessage("§cAn error occured. See console for details.§r"); - } - //} - //else - //player.sendMessage("§cYou need to be OP to use this command.§r"); - } - private static void DoAdmin(Player player, String[] args) - { //2015.08.09. - if(player==null || player.isOp() || player.getName()=="NorbiPeti") - { - if(args.length==1) - { - String message="§cUsage: /u admin reload|playerinfo§r"; - if(player==null) - System.out.println(message); - else - player.sendMessage(message); - return; - } - //args[0] is "admin" - switch(args[1].toLowerCase()) - { - case "reload": - DoReload(player); - break; - case "playerinfo": - DoPlayerInfo(player, args); - break; - } - } - else - player.sendMessage("§cYou need to be OP to use this command.§r"); - } - private static void DoPlayerInfo(Player player, String[] args) - { //2015.08.09. - //args[0] is "admin" - args[1] is "playerinfo" - if(args.length==2) - { - String message="§cUsage: /u admin playerinfo §r"; - if(player==null) - System.out.println(message); - else - player.sendMessage(message); - return; - } - MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/ec/d0cc5971043e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/ec/d0cc5971043e00151c31fb33fff4337f deleted file mode 100644 index 87c0c13..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/ec/d0cc5971043e00151c31fb33fff4337f +++ /dev/null @@ -1,126 +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; - 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/d09b59ba873e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/ed/d09b59ba873e00151ce8ff6d4f74dabd deleted file mode 100644 index dce3338..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/ed/d09b59ba873e00151ce8ff6d4f74dabd +++ /dev/null @@ -1,148 +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; - MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. - //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - if(p.Flair==null) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. - { - case "accept": - { - if(p.IgnoredFlair) - p.IgnoredFlair=false; //2015.08.08. - if(!p.AcceptedFlair) - { - String flair=p.Flair; //2015.08.08. - PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. - p.AcceptedFlair=true; //2015.08.08. - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("§cYou already have this user's flair.§r"); - break; - } - case "ignore": - { - if(p.AcceptedFlair) - p.AcceptedFlair=false; //2015.08.08. - if(!p.IgnoredFlair) - { - p.IgnoredFlair=true; - String flair=p.Flair; //2015.08.08. - PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. - player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); - } - else - player.sendMessage("§cYou already ignored this request.§r"); - break; - } - /*case "reload": //2015.07.20. - DoReload(player); - break;*/ - case "admin": //2015.08.09. - DoAdmin(player, args); - break; - default: - return false; - } - return true; - } - - /*if(args[0].toLowerCase()=="reload") - DoReload(null); //2015.07.20.*/ - else if(args[0].toLowerCase()=="admin") - DoAdmin(null, args); //2015.08.09. - return false; - } - private static void DoReload(Player player) - { //2015.07.20. - //if(player==null || player.isOp() || player.getName()=="NorbiPeti") - //{ - try - { - File file=new File("autoflairconfig.txt"); - if(file.exists()) - { - PluginMain.TownColors.clear(); - BufferedReader br=new BufferedReader(new FileReader(file)); - String line; - while((line=br.readLine())!=null) - { - String[] s=line.split(" "); - PluginMain.TownColors.put(s[0], s[1]); - } - br.close(); - for(Player p : PluginMain.GetPlayers()) - { - MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName()); - if(mp.Flair!=null) - { - String flair=mp.Flair; - PluginMain.RemovePlayerDisplayFlairFinal(p, flair); - PluginMain.AppendPlayerDisplayFlairFinal(p, flair); - } - } - String msg="§6Reloaded config file.§r"; - if(player!=null) - player.sendMessage(msg); - else - System.out.println(msg); - } - } - catch(Exception e) - { - System.out.println("Error!\n"+e); - if(player!=null) - player.sendMessage("§cAn error occured. See console for details.§r"); - } - //} - //else - //player.sendMessage("§cYou need to be OP to use this command.§r"); - } - private static void DoAdmin(Player player, String[] args) - { - if(player==null || player.isOp() || player.getName()=="NorbiPeti") - { - //args[0] is "admin" - switch(args[1].toLowerCase()) - { - case "reload": - DoReload(player); - break; - case "playerinfo": - DoPlayerInfo(player, args); - break; - } - } - else - player.sendMessage("§cYou need to be OP to use this command.§r"); - } - private static void DoPlayerInfo(Player player, String[] args) - { - //args[0] is "admin" - args[1] is "playerinfo" - if(args.length==args[2]) - { - - } - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/ee/500395f1873e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/ee/500395f1873e00151ce8ff6d4f74dabd deleted file mode 100644 index 007e8c1..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/ee/500395f1873e00151ce8ff6d4f74dabd +++ /dev/null @@ -1,157 +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; - MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. - //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - if(p.Flair==null) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. - { - case "accept": - { - if(p.IgnoredFlair) - p.IgnoredFlair=false; //2015.08.08. - if(!p.AcceptedFlair) - { - String flair=p.Flair; //2015.08.08. - PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. - p.AcceptedFlair=true; //2015.08.08. - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("§cYou already have this user's flair.§r"); - break; - } - case "ignore": - { - if(p.AcceptedFlair) - p.AcceptedFlair=false; //2015.08.08. - if(!p.IgnoredFlair) - { - p.IgnoredFlair=true; - String flair=p.Flair; //2015.08.08. - PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. - player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); - } - else - player.sendMessage("§cYou already ignored this request.§r"); - break; - } - /*case "reload": //2015.07.20. - DoReload(player); - break;*/ - case "admin": //2015.08.09. - DoAdmin(player, args); - break; - default: - return false; - } - return true; - } - - /*if(args[0].toLowerCase()=="reload") - DoReload(null); //2015.07.20.*/ - else if(args[0].toLowerCase()=="admin") - DoAdmin(null, args); //2015.08.09. - return false; - } - private static void DoReload(Player player) - { //2015.07.20. - //if(player==null || player.isOp() || player.getName()=="NorbiPeti") - //{ - try - { - File file=new File("autoflairconfig.txt"); - if(file.exists()) - { - PluginMain.TownColors.clear(); - BufferedReader br=new BufferedReader(new FileReader(file)); - String line; - while((line=br.readLine())!=null) - { - String[] s=line.split(" "); - PluginMain.TownColors.put(s[0], s[1]); - } - br.close(); - for(Player p : PluginMain.GetPlayers()) - { - MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName()); - if(mp.Flair!=null) - { - String flair=mp.Flair; - PluginMain.RemovePlayerDisplayFlairFinal(p, flair); - PluginMain.AppendPlayerDisplayFlairFinal(p, flair); - } - } - String msg="§6Reloaded config file.§r"; - if(player!=null) - player.sendMessage(msg); - else - System.out.println(msg); - } - } - catch(Exception e) - { - System.out.println("Error!\n"+e); - if(player!=null) - player.sendMessage("§cAn error occured. See console for details.§r"); - } - //} - //else - //player.sendMessage("§cYou need to be OP to use this command.§r"); - } - private static void DoAdmin(Player player, String[] args) - { //2015.08.09. - if(player==null || player.isOp() || player.getName()=="NorbiPeti") - { - if(args.length==1) - { - - } - //args[0] is "admin" - switch(args[1].toLowerCase()) - { - case "reload": - DoReload(player); - break; - case "playerinfo": - DoPlayerInfo(player, args); - break; - } - } - else - player.sendMessage("§cYou need to be OP to use this command.§r"); - } - private static void DoPlayerInfo(Player player, String[] args) - { //2015.08.09. - //args[0] is "admin" - args[1] is "playerinfo" - if(args.length==2) - { - String message="§cUsage: /u admin playerinfo §r"; - if(player==null) - System.out.println(message); - else - player.sendMessage(message); - return; - } - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/c/40594044033e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/ef/206bbc9acf3e001518fa86d7ae2a1cf8 similarity index 67% rename from .metadata/.plugins/org.eclipse.core.resources/.history/c/40594044033e00151c31fb33fff4337f rename to .metadata/.plugins/org.eclipse.core.resources/.history/ef/206bbc9acf3e001518fa86d7ae2a1cf8 index 987dab3..a085586 100644 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/c/40594044033e00151c31fb33fff4337f +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/ef/206bbc9acf3e001518fa86d7ae2a1cf8 @@ -15,43 +15,35 @@ public class PlayerListener implements Listener public void onPlayerJoin(PlayerJoinEvent event) { Player p=event.getPlayer(); - //PluginMain.Players.add(p); - //event.getPlayer().setDisplayName(p.getDisplayName()+PluginMain.GetFlair(p)); - //if(PluginMain.PlayerUserNames.containsKey(p.getName())) //<-- 2015.07.20. - // PluginMain.AppendPlayerDisplayFlair(p, PluginMain.PlayerUserNames.get(p.getName()), PluginMain.GetFlair(p)); - 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, 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. + MaybeOfflinePlayer player = MaybeOfflinePlayer.AllPlayers.get(event.getPlayer().getName()); + String flair=player.Flair; //2015.08.08. + if(flair==null || !player.AcceptedFlair) + flair=""; //2015.08.08. + String message=event.getMessage(); //2015.08.08. + /*for(Player p : PluginMain.GetPlayers()) + { //2015.08.08. + message.replaceAll(p.getName(), ) + }*/ + event.setFormat(event.getFormat().substring(0, event.getFormat().indexOf(">"))+flair+"> "+message); //2015.08.08. } private static Class nmsChatSerializer = Reflection.getNMSClass("IChatBaseComponent$ChatSerializer"); @@ -72,6 +64,7 @@ public class PlayerListener implements Listener System.out.println("6"); } catch (Exception e) { e.printStackTrace(); + PluginMain.LastException=e; //2015.08.09. } } diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/ef/50b12f8f883e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/ef/50b12f8f883e00151ce8ff6d4f74dabd deleted file mode 100644 index 07653a6..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/ef/50b12f8f883e00151ce8ff6d4f74dabd +++ /dev/null @@ -1,177 +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; - MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. - //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - if(p.Flair==null) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. - { - case "accept": - { - if(p.IgnoredFlair) - p.IgnoredFlair=false; //2015.08.08. - if(!p.AcceptedFlair) - { - String flair=p.Flair; //2015.08.08. - PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. - p.AcceptedFlair=true; //2015.08.08. - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("§cYou already have this user's flair.§r"); - break; - } - case "ignore": - { - if(p.AcceptedFlair) - p.AcceptedFlair=false; //2015.08.08. - if(!p.IgnoredFlair) - { - p.IgnoredFlair=true; - String flair=p.Flair; //2015.08.08. - PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. - player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); - } - else - player.sendMessage("§cYou already ignored this request.§r"); - break; - } - /*case "reload": //2015.07.20. - DoReload(player); - break;*/ - case "admin": //2015.08.09. - DoAdmin(player, args); - break; - default: - return false; - } - return true; - } - - /*if(args[0].toLowerCase()=="reload") - DoReload(null); //2015.07.20.*/ - else if(args[0].toLowerCase()=="admin") - DoAdmin(null, args); //2015.08.09. - return false; - } - private static void DoReload(Player player) - { //2015.07.20. - //if(player==null || player.isOp() || player.getName()=="NorbiPeti") - //{ - try - { - File file=new File("autoflairconfig.txt"); - if(file.exists()) - { - PluginMain.TownColors.clear(); - BufferedReader br=new BufferedReader(new FileReader(file)); - String line; - while((line=br.readLine())!=null) - { - String[] s=line.split(" "); - PluginMain.TownColors.put(s[0], s[1]); - } - br.close(); - for(Player p : PluginMain.GetPlayers()) - { - MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName()); - if(mp.Flair!=null) - { - String flair=mp.Flair; - PluginMain.RemovePlayerDisplayFlairFinal(p, flair); - PluginMain.AppendPlayerDisplayFlairFinal(p, flair); - } - } - String msg="§6Reloaded config file.§r"; - if(player!=null) - player.sendMessage(msg); - else - System.out.println(msg); - } - } - catch(Exception e) - { - System.out.println("Error!\n"+e); - if(player!=null) - player.sendMessage("§cAn error occured. See console for details.§r"); - } - //} - //else - //player.sendMessage("§cYou need to be OP to use this command.§r"); - } - private static void DoAdmin(Player player, String[] args) - { //2015.08.09. - if(player==null || player.isOp() || player.getName()=="NorbiPeti") - { - if(args.length==1) - { - String message="§cUsage: /u admin reload|playerinfo§r"; - if(player==null) - System.out.println(message); - else - player.sendMessage(message); - return; - } - //args[0] is "admin" - switch(args[1].toLowerCase()) - { - case "reload": - DoReload(player); - break; - case "playerinfo": - DoPlayerInfo(player, args); - break; - } - } - else - player.sendMessage("§cYou need to be OP to use this command.§r"); - } - private static void DoPlayerInfo(Player player, String[] args) - { //2015.08.09. - //args[0] is "admin" - args[1] is "playerinfo" - if(args.length==2) - { - String message="§cUsage: /u admin playerinfo §r"; - if(player==null) - System.out.println(message); - else - player.sendMessage(message); - return; - } - if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2])) - { - String message="§cPlayer not found: "+args[2]+"§r"; - if(player==null) - System.out.println(message); - else - player.sendMessage(message); - return; - } - MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]); - if(player==null) - System.out.println(message); - else - player.sendMessage(message); - return; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/ef/d0a65f54873e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/ef/d0a65f54873e00151ce8ff6d4f74dabd deleted file mode 100644 index b77e8ab..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/ef/d0a65f54873e00151ce8ff6d4f74dabd +++ /dev/null @@ -1,140 +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; - MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. - //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - if(p.Flair==null) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. - { - case "accept": - { - if(p.IgnoredFlair) - p.IgnoredFlair=false; //2015.08.08. - if(!p.AcceptedFlair) - { - String flair=p.Flair; //2015.08.08. - PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. - p.AcceptedFlair=true; //2015.08.08. - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("§cYou already have this user's flair.§r"); - break; - } - case "ignore": - { - if(p.AcceptedFlair) - p.AcceptedFlair=false; //2015.08.08. - if(!p.IgnoredFlair) - { - p.IgnoredFlair=true; - String flair=p.Flair; //2015.08.08. - PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. - player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); - } - else - player.sendMessage("§cYou already ignored this request.§r"); - break; - } - /*case "reload": //2015.07.20. - DoReload(player); - break;*/ - case "admin": //2015.08.09. - DoAdmin(player, args); - break; - default: - return false; - } - return true; - } - - /*if(args[0].toLowerCase()=="reload") - DoReload(null); //2015.07.20.*/ - else if(args[0].toLowerCase()=="admin") - DoAdmin(null, args); //2015.08.09. - return false; - } - private static void DoReload(Player player) - { //2015.07.20. - //if(player==null || player.isOp() || player.getName()=="NorbiPeti") - //{ - try - { - File file=new File("autoflairconfig.txt"); - if(file.exists()) - { - PluginMain.TownColors.clear(); - BufferedReader br=new BufferedReader(new FileReader(file)); - String line; - while((line=br.readLine())!=null) - { - String[] s=line.split(" "); - PluginMain.TownColors.put(s[0], s[1]); - } - br.close(); - for(Player p : PluginMain.GetPlayers()) - { - MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName()); - if(mp.Flair!=null) - { - String flair=mp.Flair; - PluginMain.RemovePlayerDisplayFlairFinal(p, flair); - PluginMain.AppendPlayerDisplayFlairFinal(p, flair); - } - } - String msg="§6Reloaded config file.§r"; - if(player!=null) - player.sendMessage(msg); - else - System.out.println(msg); - } - } - catch(Exception e) - { - System.out.println("Error!\n"+e); - if(player!=null) - player.sendMessage("§cAn error occured. See console for details.§r"); - } - //} - //else - //player.sendMessage("§cYou need to be OP to use this command.§r"); - } - private static void DoAdmin(Player player, String[] args) - { - if(player==null || player.isOp() || player.getName()=="NorbiPeti") - { - //args[0] is "admin" - switch(args[1].toLowerCase()) - { - case "reload": - DoReload(player); - break; - case "playerinfo": - DoPlayerInfo(player); - break; - } - } - else - player.sendMessage("§cYou need to be OP to use this command.§r"); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/f/90af968ede3e001517108d149b613203 b/.metadata/.plugins/org.eclipse.core.resources/.history/f/90af968ede3e001517108d149b613203 new file mode 100644 index 0000000..f04e2b0 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/f/90af968ede3e001517108d149b613203 @@ -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)"); + getServer().getPluginManager().registerEvents(new PlayerListener(), this); + this.getCommand("u").setExecutor(new Commands()); + this.getCommand("u").setUsage(this.getCommand("u").getUsage().replace('&', '§')); + Instance=this; //2015.08.08. + LoadFiles(false); //2015.08.09. + Runnable r=new Runnable(){public void run(){ThreadMethod();}}; + Thread t=new Thread(r); + t.start(); + } + Boolean stop=false; + // Fired when plugin is disabled + @Override + public void onDisable() + { + SaveFiles(); //2015.08.09. + stop=true; + } + + public void ThreadMethod() //<-- 2015.07.16. + { + while(!stop) + { + try + { + String body=DownloadString("https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/autoflair_system_comment_your_minecraft_name_and/.json?limit=1000"); + JSONArray json=new JSONArray(body).getJSONObject(1).getJSONObject("data").getJSONArray("children"); + for(Object obj : json) + { + JSONObject item = (JSONObject)obj; + String author=item.getJSONObject("data").getString("author"); + String ign=item.getJSONObject("data").getString("body"); + int start = ign.indexOf("IGN:") + "IGN:".length(); + if(start==-1) + continue; //2015.08.09. + int end = ign.indexOf(' ', start); + if (end == -1 || end == start) + end=ign.indexOf('\n', start); //2015.07.15. + if (end == -1 || end == start) + ign = ign.substring(start); + else + ign = ign.substring(start, end); + ign = ign.trim(); + if(HasIGFlair(ign)) + continue; + try { + Thread.sleep(10); + } catch(InterruptedException ex) { + Thread.currentThread().interrupt(); + } + String[] flairdata = DownloadString("http://karmadecay.com/thebutton-data.php?users=" + author).replace("\"", "").split(":"); + String flair; + if(flairdata.length > 1) //2015.07.15. + flair = flairdata[1]; + else + flair=""; + if (flair != "-1") + flair = flair + "s"; + else + flair = "non-presser"; + String flairclass; + if(flairdata.length>2) + flairclass = flairdata[2]; + else + flairclass="unknown"; + SetFlair(ign, flair, flairclass, author); + } + Thread.sleep(10000); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + } + + public static Exception LastException; //2015.08.09. + + public String DownloadString(String urlstr) throws MalformedURLException, IOException + { + URL url = new URL(urlstr); + URLConnection con = url.openConnection(); + con.setRequestProperty("User-Agent", "TheButtonAutoFlair"); + InputStream in = con.getInputStream(); + String encoding = con.getContentEncoding(); + encoding = encoding == null ? "UTF-8" : encoding; + String body = IOUtils.toString(in, encoding); + in.close(); + return body; + } + + public static Map TownColors=new HashMap(); //2015.07.20. + public Boolean HasIGFlair(String playername) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + return p.Flair!=null; //2015.08.08. + } + + public void SetFlair(String playername, String text, String flairclass, String username) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + String finalflair; + p.FlairDecided=true; + switch(flairclass) + { + case "press-1": + finalflair="§c("+text+")§r"; + break; + case "press-2": + finalflair="§6("+text+")§r"; + break; + case "press-3": + finalflair="§e("+text+")§r"; + break; + case "press-4": + finalflair="§a("+text+")§r"; + break; + case "press-5": + finalflair="§9("+text+")§r"; + break; + 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; + case "undecided": //2015.08.09. + p.FlairDecided=false; + finalflair=""; + break; + default: + finalflair=""; + break; + } + if(finalflair.length()==0) //<-- 2015.07.20. + return; + p.Flair=finalflair; //2015.08.08. + p.UserName=username; //2015.08.08. + System.out.println("Added new flair to "+playername+": "+finalflair); + for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08. + { + if(player.getName().equals(playername)) + { + //AppendPlayerDisplayFlair(player, username, finalflair); + AppendPlayerDisplayFlair(p, player); + break; + } + } + } + + public static String GetFlair(Player player) + { //2015.07.16. + String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08. + return flair==null ? "" : flair; + } + + //public static void AppendPlayerDisplayFlair(Player player, String username, String flair) + public static void AppendPlayerDisplayFlair(MaybeOfflinePlayer player, Player p) //<-- 2015.08.09. + { + + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).IgnoredFlair) + return; + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).AcceptedFlair) + { + AppendPlayerDisplayFlairFinal(p, player.Flair); //2015.07.20. + if(!player.FlairDecided) + p.sendMessage("§9Your flair type is unknown. Are you a non-presser or a can't press? (/u nonpresser or /u cantpress)§r"); //2015.08.09. + } + else + p.sendMessage("§9Are you Reddit user "+player.UserName+"?§r §6Type /u accept or /u ignore§r"); + } + + private static void AppendPlayerDisplayFlairFinal(Player player, String flair) + { //2015.07.20. + String color = GetColorForTown(GetPlayerTown(player)); //TO!DO: Multiple colors put on first capital letters + String[] colors = color.substring(1).split("§"); + String displayname=player.getName(); //2015.08.08. + ArrayList Positions=new ArrayList<>(); + for(int i=0; i=colors.length) + { + int x=0; + for(int i=0; i GetPlayers() + { + return Instance.getServer().getOnlinePlayers(); + } + + public static void LoadFiles(boolean reload) //<-- 2015.08.09. + { + if(reload) + { //2015.08.09. + System.out.println("Auto-flair plugin cleanup for reloading..."); + MaybeOfflinePlayer.AllPlayers.clear(); + TownColors.clear(); + } + System.out.println("Loading files for auto-flair plugin..."); //2015.08.09. + try { + File file=new File("flairsaccepted.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + //System.out.println("Name: " + name); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("flairsignored.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsignored.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("autoflairconfig.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + TownColors.put(s[0], s[1]); + } + br.close(); + } + file=new File("customflairs.txt"); //2015.08.09. + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + MaybeOfflinePlayer.AddPlayerIfNeeded(s[0]).Flair=s[1]; //2015.08.09. + } + br.close(); + } + //throw new IOException("Test"); //2015.08.09. + System.out.println("Auto-flair plugin loaded files!"); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + public static void SaveFiles() //<-- 2015.08.09. + { + try + { + FileWriter fw; + fw = new FileWriter("flairsaccepted.txt"); + fw.close(); + fw = new FileWriter("flairsignored.txt"); + fw.close(); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + try { + File file=new File("flairsaccepted.txt"); + BufferedWriter bw=new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.AcceptedFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + file=new File("flairsignored.txt"); + bw = new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.IgnoredFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + public static void SetPlayerFlair(Player player, String flair) + { //2015.08.09. + flair=flair.replace('&', '§'); + MaybeOfflinePlayer.AddPlayerIfNeeded(player.getName()).Flair=flair; + File file=new File("customflairs.txt"); + try { + BufferedWriter bw; + bw = new BufferedWriter(new FileWriter(file, true)); + bw.write(player.getName()+"\n"); + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + public static void RemoveLineFromFile(String file) + { + File inputFile = new File(file); + File tempFile = new File("_temp.txt"); + + BufferedReader reader = new BufferedReader(new FileReader(inputFile)); + BufferedWriter writer = new BufferedWriter(new FileWriter(tempFile)); + + String lineToRemove = "bbb"; + String currentLine; + + while((currentLine = reader.readLine()) != null) { + // trim newline when comparing with lineToRemove + String trimmedLine = currentLine.trim(); + if(trimmedLine.equals(lineToRemove)) continue; + writer.write(currentLine + System.getProperty("line.separator")); + } + writer.close(); + reader.close(); + boolean successful = tempFile.renameTo(inputFile); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/f/a0d81438d33e001518fa86d7ae2a1cf8 b/.metadata/.plugins/org.eclipse.core.resources/.history/f/a0d81438d33e001518fa86d7ae2a1cf8 new file mode 100644 index 0000000..f17161d --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/f/a0d81438d33e001518fa86d7ae2a1cf8 @@ -0,0 +1,216 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; + +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class Commands implements CommandExecutor { + // This method is called, when somebody uses our command + @Override + public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { + if (sender instanceof Player) { + Player player = (Player) sender; + if(args.length<1) + return false; + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. + //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) + if(p.Flair==null) + { + player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); + return true; + } + switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. + { + case "accept": + { + if(p.IgnoredFlair) + p.IgnoredFlair=false; //2015.08.08. + if(!p.AcceptedFlair) + { + String flair=p.Flair; //2015.08.08. + //PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + PluginMain.AppendPlayerDisplayFlair(p, player); + p.AcceptedFlair=true; //2015.08.08. + player.sendMessage("§6Your flair has been set:§r "+flair); + } + else + player.sendMessage("§cYou already have this user's flair.§r"); + break; + } + case "ignore": + { + if(p.AcceptedFlair) + p.AcceptedFlair=false; //2015.08.08. + if(!p.IgnoredFlair) + { + p.IgnoredFlair=true; + String flair=p.Flair; //2015.08.08. + PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. + player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); + } + else + player.sendMessage("§cYou already ignored this request.§r"); + break; + } + /*case "reload": //2015.07.20. + DoReload(player); + break;*/ + case "admin": //2015.08.09. + DoAdmin(player, args); + break; + case "nonpresser": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§7(non-pr.)§r"; + break; + case "cantpress": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§r(can't press)§r"; + break; + default: + return false; + } + return true; + } + /*if(args[0].toLowerCase()=="reload") + DoReload(null); //2015.07.20.*/ + else if(args.length>0 && args[0].toLowerCase().equals("admin")) //2015.08.09. + { + DoAdmin(null, args); //2015.08.09. + return true; //2015.08.09. + } + return false; + } + private static void DoReload(Player player) + { //2015.07.20. + //if(player==null || player.isOp() || player.getName()=="NorbiPeti") + //{ + try + { + File file=new File("autoflairconfig.txt"); + if(file.exists()) + { + PluginMain.LoadFiles(true); //2015.08.09. + for(Player p : PluginMain.GetPlayers()) + { + MaybeOfflinePlayer mp = MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName()); + if(mp.Flair!=null) + { + String flair=mp.Flair; + PluginMain.RemovePlayerDisplayFlairFinal(p, flair); + //PluginMain.AppendPlayerDisplayFlairFinal(p, flair); + PluginMain.AppendPlayerDisplayFlair(mp, p); //2015.08.09. + } + } + //String msg="§6Reloaded config file.§r"; + String msg="§6Note: The auto-flair plugin has been reloaded. You might need to wait 10s to have your flair.§r"; + //SendMessage(player, msg); //2015.08.09. + + } + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + if(player!=null) + player.sendMessage("§cAn error occured. See console for details.§r"); + PluginMain.LastException=e; //2015.08.09. + } + //} + //else + //player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static void DoAdmin(Player player, String[] args) + { //2015.08.09. + if(player==null || player.isOp() || player.getName()=="NorbiPeti") + { + //System.out.println("Args length: " + args.length); + if(args.length==1) + { + String message="§cUsage: /u admin reload|playerinfo§r"; + SendMessage(player, message); + return; + } + //args[0] is "admin" + switch(args[1].toLowerCase()) + { + case "reload": + DoReload(player); + break; + case "playerinfo": + DoPlayerInfo(player, args); + break; + case "getlasterror": + DoGetLastError(player, args); + default: + String message="§cUsage: /u admin reload|playerinfo§r"; + SendMessage(player, message); + return; + } + } + else + player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static void DoPlayerInfo(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "playerinfo" + if(args.length==2) + { + String message="§cUsage: /u admin playerinfo §r"; + SendMessage(player, message); + return; + } + if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2])) + { + String message="§cPlayer not found: "+args[2]+"§r"; + SendMessage(player, message); + return; + } + MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]); + SendMessage(player, "Player name: "+p.PlayerName); + SendMessage(player, "User flair: "+p.Flair); + SendMessage(player, "Username: "+p.UserName); + SendMessage(player, "Flair accepted: "+p.AcceptedFlair); + SendMessage(player, "Flair ignored: "+p.IgnoredFlair); + } + private static void SendMessage(Player player, String message) + { //2015.08.09. + if(player==null) + System.out.println(message); + else + player.sendMessage(message); + } + private static void DoGetLastError(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "getlasterror" + if(PluginMain.LastException!=null) + { + SendMessage(player, "Last error:"); + SendMessage(player, PluginMain.LastException.toString()); + PluginMain.LastException=null; + } + else + SendMessage(player, "There were no exceptions."); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/f/b08c4dd3d13e001518fa86d7ae2a1cf8 b/.metadata/.plugins/org.eclipse.core.resources/.history/f/b08c4dd3d13e001518fa86d7ae2a1cf8 new file mode 100644 index 0000000..fbfb948 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/f/b08c4dd3d13e001518fa86d7ae2a1cf8 @@ -0,0 +1,372 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStream; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLConnection; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + +import org.apache.commons.io.IOUtils; +import org.bukkit.entity.Player; +import org.bukkit.plugin.java.JavaPlugin; +import org.json.JSONArray; +import org.json.JSONObject; + +import com.palmergames.bukkit.towny.object.Town; +import com.palmergames.bukkit.towny.object.WorldCoord; + +public class PluginMain extends JavaPlugin +{ //Translated to Java: 2015.07.15. + //A user, which flair isn't obtainable: + //https://www.reddit.com/r/thebutton/comments/31c32v/i_pressed_the_button_without_really_thinking/ + private static PluginMain Instance; + // Fired when plugin is first enabled + @Override + public void onEnable() + { + System.out.println("The Button Auto-flair Plugin by NorbiPeti (:P)"); + getServer().getPluginManager().registerEvents(new PlayerListener(), this); + this.getCommand("u").setExecutor(new Commands()); + this.getCommand("u").setUsage(this.getCommand("u").getUsage().replace('&', '§')); + Instance=this; //2015.08.08. + LoadFiles(false); //2015.08.09. + Runnable r=new Runnable(){public void run(){ThreadMethod();}}; + Thread t=new Thread(r); + t.start(); + } + Boolean stop=false; + // Fired when plugin is disabled + @Override + public void onDisable() + { + try + { + FileWriter fw; + fw = new FileWriter("flairsaccepted.txt"); + fw.close(); + fw = new FileWriter("flairsignored.txt"); + fw.close(); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + try { + File file=new File("flairsaccepted.txt"); + BufferedWriter bw=new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.AcceptedFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + file=new File("flairsignored.txt"); + bw = new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.IgnoredFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + stop=true; + } + + public void ThreadMethod() //<-- 2015.07.16. + { + while(!stop) + { + try + { + String body=DownloadString("https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/autoflair_system_comment_your_minecraft_name_and/.json?limit=1000"); + JSONArray json=new JSONArray(body).getJSONObject(1).getJSONObject("data").getJSONArray("children"); + for(Object obj : json) + { + JSONObject item = (JSONObject)obj; + String author=item.getJSONObject("data").getString("author"); + String ign=item.getJSONObject("data").getString("body"); + int start = ign.indexOf("IGN:") + "IGN:".length(); + int end = ign.indexOf(' ', start); + if (end == -1 || end == start) + end=ign.indexOf('\n', start); //2015.07.15. + if (end == -1 || end == start) + ign = ign.substring(start); + else + ign = ign.substring(start, end); + ign = ign.trim(); + if(HasIGFlair(ign)) + continue; + try { + Thread.sleep(10); + } catch(InterruptedException ex) { + Thread.currentThread().interrupt(); + } + String[] flairdata = DownloadString("http://karmadecay.com/thebutton-data.php?users=" + author).replace("\"", "").split(":"); + String flair; + if(flairdata.length > 1) //2015.07.15. + flair = flairdata[1]; + else + flair=""; + if (flair != "-1") + flair = flair + "s"; + else + flair = "non-presser"; + String flairclass; + if(flairdata.length>2) + flairclass = flairdata[2]; + else + flairclass="unknown"; + SetFlair(ign, flair, flairclass, author); + } + Thread.sleep(10000); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + } + + public static Exception LastException; //2015.08.09. + + public String DownloadString(String urlstr) throws MalformedURLException, IOException + { + URL url = new URL(urlstr); + URLConnection con = url.openConnection(); + con.setRequestProperty("User-Agent", "TheButtonAutoFlair"); + InputStream in = con.getInputStream(); + String encoding = con.getContentEncoding(); + encoding = encoding == null ? "UTF-8" : encoding; + String body = IOUtils.toString(in, encoding); + in.close(); + return body; + } + + public static Map TownColors=new HashMap(); //2015.07.20. + public Boolean HasIGFlair(String playername) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + return p.Flair!=null; //2015.08.08. + } + + public void SetFlair(String playername, String text, String flairclass, String username) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + String finalflair; + p.FlairDecided=true; + switch(flairclass) + { + case "press-1": + finalflair="§c("+text+")§r"; + break; + case "press-2": + finalflair="§6("+text+")§r"; + break; + case "press-3": + finalflair="§e("+text+")§r"; + break; + case "press-4": + finalflair="§a("+text+")§r"; + break; + case "press-5": + finalflair="§9("+text+")§r"; + break; + 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; + case "undecided": //2015.08.09. + p.FlairDecided=false; + finalflair=""; + break; + default: + finalflair=""; + break; + } + if(finalflair.length()==0) //<-- 2015.07.20. + return; + p.Flair=finalflair; //2015.08.08. + p.UserName=username; //2015.08.08. + System.out.println("Added new flair to "+playername+": "+finalflair); + for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08. + { + if(player.getName().equals(playername)) + { + //AppendPlayerDisplayFlair(player, username, finalflair); + AppendPlayerDisplayFlair(p, player); + break; + } + } + } + + public static String GetFlair(Player player) + { //2015.07.16. + String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08. + return flair==null ? "" : flair; + } + + //public static void AppendPlayerDisplayFlair(Player player, String username, String flair) + public static void AppendPlayerDisplayFlair(MaybeOfflinePlayer player, Player p) //<-- 2015.08.09. + { + + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).IgnoredFlair) + return; + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).AcceptedFlair) + { + AppendPlayerDisplayFlairFinal(p, player.Flair); //2015.07.20. + if(!player.FlairDecided) + p.sendMessage("§9Your flair type is unknown. Are you a non-presser or a can't press? (/u nonpresser or /u cantpress)§r"); //2015.08.09. + } + else + p.sendMessage("§9Are you Reddit user "+player.UserName+"?§r §6Type /u accept or /u ignore§r"); + } + + private static void AppendPlayerDisplayFlairFinal(Player player, String flair) + { //2015.07.20. + String color = GetColorForTown(GetPlayerTown(player)); //TO!DO: Multiple colors put on first capital letters + String[] colors = color.substring(1).split("§"); + String displayname=player.getName(); //2015.08.08. + ArrayList Positions=new ArrayList<>(); + for(int i=0; i=colors.length) + { + int x=0; + for(int i=0; i GetPlayers() + { + return Instance.getServer().getOnlinePlayers(); + } + + public static void LoadFiles(boolean reload) //<-- 2015.08.09. + { + if(reload) + { + MaybeOfflinePlayer.AllPlayers.clear(); //2015.08.09. + } + try { + File file=new File("flairsaccepted.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + //System.out.println("Name: " + name); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("flairsignored.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsignored.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("autoflairconfig.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + TownColors.put(s[0], s[1]); + } + br.close(); + } + //throw new IOException("Test"); //2015.08.09. + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/f/e0df3528853e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/f/e0df3528853e00151ce8ff6d4f74dabd deleted file mode 100644 index 51121d3..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/f/e0df3528853e00151ce8ff6d4f74dabd +++ /dev/null @@ -1,126 +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; - MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. - //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - if(p.Flair==null) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. - { - case "accept": - { - if(p.IgnoredFlair) - p.IgnoredFlair=false; //2015.08.08. - if(!p.AcceptedFlair) - { - String flair=p.Flair; //2015.08.08. - PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. - p.AcceptedFlair=true; //2015.08.08. - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("§cYou already have this user's flair.§r"); - break; - } - case "ignore": - { - if(p.AcceptedFlair) - p.AcceptedFlair=false; //2015.08.08. - if(!p.IgnoredFlair) - { - p.IgnoredFlair=true; - String flair=p.Flair; //2015.08.08. - PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. - player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); - } - else - player.sendMessage("§cYou already ignored this request.§r"); - break; - } - case "reload": //2015.07.20. - DoReload(player); - break; - case "showerrors": //2015.08.09. - DoShowErrors(player); - break; - default: - return false; - } - return true; - } - - if(args[0].toLowerCase()=="reload") - DoReload(null); //2015.07.20. - else if(args[0].toLowerCase()=="showerrors") - DoShowErrors(null); //2015.08.09. - return false; - } - private static void DoReload(Player player) - { //2015.07.20. - if(player==null || player.isOp() || player.getName()=="NorbiPeti") - { - try - { - File file=new File("autoflairconfig.txt"); - if(file.exists()) - { - PluginMain.TownColors.clear(); - BufferedReader br=new BufferedReader(new FileReader(file)); - String line; - while((line=br.readLine())!=null) - { - String[] s=line.split(" "); - PluginMain.TownColors.put(s[0], s[1]); - } - br.close(); - for(Player p : PluginMain.GetPlayers()) - { - MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName()); - if(mp.Flair!=null) - { - String flair=mp.Flair; - PluginMain.RemovePlayerDisplayFlairFinal(p, flair); - PluginMain.AppendPlayerDisplayFlairFinal(p, flair); - } - } - String msg="§6Reloaded config file.§r"; - if(player!=null) - player.sendMessage(msg); - else - System.out.println(msg); - } - } - catch(Exception e) - { - System.out.println("Error!\n"+e); - if(player!=null) - player.sendMessage("§cAn error occured. See console for details.§r"); - } - } - else - player.sendMessage("§cYou need to be OP to use this command.§r"); - } - private static void DoShowErrors(Player player) - { - - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/f1/808b0319df3e001517108d149b613203 b/.metadata/.plugins/org.eclipse.core.resources/.history/f1/808b0319df3e001517108d149b613203 new file mode 100644 index 0000000..3b9f920 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/f1/808b0319df3e001517108d149b613203 @@ -0,0 +1,250 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +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; + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. + //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) + if(p.Flair==null) + { + player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); + return true; + } + switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. + { + case "accept": + { + if(p.IgnoredFlair) + p.IgnoredFlair=false; //2015.08.08. + if(!p.AcceptedFlair) + { + String flair=p.Flair; //2015.08.08. + //PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + PluginMain.AppendPlayerDisplayFlair(p, player); + p.AcceptedFlair=true; //2015.08.08. + player.sendMessage("§6Your flair has been set:§r "+flair); + } + else + player.sendMessage("§cYou already have this user's flair.§r"); + break; + } + case "ignore": + { + if(p.AcceptedFlair) + p.AcceptedFlair=false; //2015.08.08. + if(!p.IgnoredFlair) + { + p.IgnoredFlair=true; + String flair=p.Flair; //2015.08.08. + PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. + player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); + } + else + player.sendMessage("§cYou already ignored this request.§r"); + break; + } + /*case "reload": //2015.07.20. + DoReload(player); + break;*/ + case "admin": //2015.08.09. + DoAdmin(player, args); + break; + case "nonpresser": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§7(non-pr.)§r"; + break; + case "cantpress": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§r(can't press)§r"; + break; + default: + return false; + } + return true; + } + /*if(args[0].toLowerCase()=="reload") + DoReload(null); //2015.07.20.*/ + else if(args.length>0 && args[0].toLowerCase().equals("admin")) //2015.08.09. + { + DoAdmin(null, args); //2015.08.09. + return true; //2015.08.09. + } + return false; + } + private static void DoReload(Player player) + { //2015.07.20. + //if(player==null || player.isOp() || player.getName()=="NorbiPeti") + //{ + try + { + File file=new File("autoflairconfig.txt"); + if(file.exists()) + { + PluginMain.LoadFiles(true); //2015.08.09. + for(Player p : PluginMain.GetPlayers()) + { + MaybeOfflinePlayer mp = MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName()); + if(mp.Flair!=null) + { + String flair=mp.Flair; + PluginMain.RemovePlayerDisplayFlairFinal(p, flair); + //PluginMain.AppendPlayerDisplayFlairFinal(p, flair); + PluginMain.AppendPlayerDisplayFlair(mp, p); //2015.08.09. + } + String msg="§6Note: The auto-flair plugin has been reloaded. You might need to wait 10s to have your flair.§r"; //2015.08.09. + p.sendMessage(msg); //2015.08.09. + } + //String msg="§6Reloaded config file.§r"; + //SendMessage(player, msg); //2015.08.09. + } + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + if(player!=null) + player.sendMessage("§cAn error occured. See console for details.§r"); + PluginMain.LastException=e; //2015.08.09. + } + //} + //else + //player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static Player ReloadPlayer; //2015.08.09. + private static void DoAdmin(Player player, String[] args) + { //2015.08.09. + if(player==null || player.isOp() || player.getName()=="NorbiPeti") + { + //System.out.println("Args length: " + args.length); + if(args.length==1) + { + String message="§cUsage: /u admin reload|playerinfo§r"; + SendMessage(player, message); + return; + } + //args[0] is "admin" + switch(args[1].toLowerCase()) + { + case "reload": + ReloadPlayer=player; //2015.08.09. + SendMessage(player, "§6Make sure to save the current settings before you modify and reload them! Type /u admin confirm when done.§r"); + break; + case "playerinfo": + DoPlayerInfo(player, args); + break; + case "getlasterror": + DoGetLastError(player, args); + case "confirm": + if(ReloadPlayer==player) + DoReload(player); //2015.08.09. + else + SendMessage(player, "§cYou need to do /u admin reload first.§r"); + break; + case "save": + PluginMain.SaveFiles(); //2015.08.09. + SendMessage(player, "§6Saved files. Now you can edit them and reload if you want.§r"); + break; + default: + String message="§cUsage: /u admin reload|playerinfo|getlasterror§r"; + SendMessage(player, message); + return; + } + } + else + player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static void DoPlayerInfo(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "playerinfo" + if(args.length==2) + { + String message="§cUsage: /u admin playerinfo §r"; + SendMessage(player, message); + return; + } + if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2])) + { + String message="§cPlayer not found: "+args[2]+"§r"; + SendMessage(player, message); + return; + } + MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]); + SendMessage(player, "Player name: "+p.PlayerName); + SendMessage(player, "User flair: "+p.Flair); + SendMessage(player, "Username: "+p.UserName); + SendMessage(player, "Flair accepted: "+p.AcceptedFlair); + SendMessage(player, "Flair ignored: "+p.IgnoredFlair); + } + private static void SendMessage(Player player, String message) + { //2015.08.09. + if(player==null) + System.out.println(message); + else + player.sendMessage(message); + } + private static void DoGetLastError(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "getlasterror" + if(PluginMain.LastException!=null) + { + SendMessage(player, "Last error:"); + SendMessage(player, PluginMain.LastException.toString()); + PluginMain.LastException=null; + } + else + SendMessage(player, "There were no exceptions."); + } + private static void SetPlayerFlair(Player player, String flair) + { //2015.08.09. + flair=flair.replace('&', '§'); + MaybeOfflinePlayer.AddPlayerIfNeeded(player.getName()).Flair=flair; + if(!PluginMain.RemoveLineFromFile("customflairs.txt")) + { + SendMessage(player, "") + } + File file=new File("customflairs.txt"); + try { + BufferedWriter bw; + bw = new BufferedWriter(new FileWriter(file, true)); + bw.write(player.getName()+"\n"); + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + PluginMain.LastException=e; //2015.08.09. + } + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/f2/205fa4c2d03e001518fa86d7ae2a1cf8 b/.metadata/.plugins/org.eclipse.core.resources/.history/f2/205fa4c2d03e001518fa86d7ae2a1cf8 new file mode 100644 index 0000000..5dcd8d1 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/f2/205fa4c2d03e001518fa86d7ae2a1cf8 @@ -0,0 +1,209 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; + +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class Commands implements CommandExecutor { + // This method is called, when somebody uses our command + @Override + public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { + if (sender instanceof Player) { + Player player = (Player) sender; + if(args.length<1) + return false; + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. + //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) + if(p.Flair==null) + { + player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); + return true; + } + switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. + { + case "accept": + { + if(p.IgnoredFlair) + p.IgnoredFlair=false; //2015.08.08. + if(!p.AcceptedFlair) + { + String flair=p.Flair; //2015.08.08. + //PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + PluginMain.AppendPlayerDisplayFlair(p, player); + p.AcceptedFlair=true; //2015.08.08. + player.sendMessage("§6Your flair has been set:§r "+flair); + } + else + player.sendMessage("§cYou already have this user's flair.§r"); + break; + } + case "ignore": + { + if(p.AcceptedFlair) + p.AcceptedFlair=false; //2015.08.08. + if(!p.IgnoredFlair) + { + p.IgnoredFlair=true; + String flair=p.Flair; //2015.08.08. + PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. + player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); + } + else + player.sendMessage("§cYou already ignored this request.§r"); + break; + } + /*case "reload": //2015.07.20. + DoReload(player); + break;*/ + case "admin": //2015.08.09. + DoAdmin(player, args); + break; + case "nonpresser": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + + } + break; + case "cantpress": //2015.08.09. + break; + default: + return false; + } + return true; + } + /*if(args[0].toLowerCase()=="reload") + DoReload(null); //2015.07.20.*/ + else if(args.length>0 && args[0].toLowerCase().equals("admin")) //2015.08.09. + { + DoAdmin(null, args); //2015.08.09. + return true; //2015.08.09. + } + return false; + } + private static void DoReload(Player player) + { //2015.07.20. + //if(player==null || player.isOp() || player.getName()=="NorbiPeti") + //{ + try + { + File file=new File("autoflairconfig.txt"); + if(file.exists()) + { + PluginMain.TownColors.clear(); + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + PluginMain.TownColors.put(s[0], s[1]); + } + br.close(); + for(Player p : PluginMain.GetPlayers()) + { + MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName()); + if(mp.Flair!=null) + { + String flair=mp.Flair; + PluginMain.RemovePlayerDisplayFlairFinal(p, flair); + //PluginMain.AppendPlayerDisplayFlairFinal(p, flair); + PluginMain.AppendPlayerDisplayFlair(mp, p); //2015.08.09. + } + } + String msg="§6Reloaded config file.§r"; + SendMessage(player, msg); //2015.08.09. + } + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + if(player!=null) + player.sendMessage("§cAn error occured. See console for details.§r"); + PluginMain.LastException=e; //2015.08.09. + } + //} + //else + //player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static void DoAdmin(Player player, String[] args) + { //2015.08.09. + if(player==null || player.isOp() || player.getName()=="NorbiPeti") + { + //System.out.println("Args length: " + args.length); + if(args.length==1) + { + String message="§cUsage: /u admin reload|playerinfo§r"; + SendMessage(player, message); + return; + } + //args[0] is "admin" + switch(args[1].toLowerCase()) + { + case "reload": + DoReload(player); + break; + case "playerinfo": + DoPlayerInfo(player, args); + break; + case "getlasterror": + DoGetLastError(player, args); + default: + String message="§cUsage: /u admin reload|playerinfo§r"; + SendMessage(player, message); + return; + } + } + else + player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static void DoPlayerInfo(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "playerinfo" + if(args.length==2) + { + String message="§cUsage: /u admin playerinfo §r"; + SendMessage(player, message); + return; + } + if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2])) + { + String message="§cPlayer not found: "+args[2]+"§r"; + SendMessage(player, message); + return; + } + MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]); + SendMessage(player, "Player name: "+p.PlayerName); + SendMessage(player, "User flair: "+p.Flair); + SendMessage(player, "Username: "+p.UserName); + SendMessage(player, "Flair accepted: "+p.AcceptedFlair); + SendMessage(player, "Flair ignored: "+p.IgnoredFlair); + } + private static void SendMessage(Player player, String message) + { //2015.08.09. + if(player==null) + System.out.println(message); + else + player.sendMessage(message); + } + private static void DoGetLastError(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "getlasterror" + if(PluginMain.LastException!=null) + { + SendMessage(player, "Last error:"); + SendMessage(player, PluginMain.LastException.toString()); + PluginMain.LastException=null; + } + else + SendMessage(player, "There were no exceptions."); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/f2/a0380b49d03e001518fa86d7ae2a1cf8 b/.metadata/.plugins/org.eclipse.core.resources/.history/f2/a0380b49d03e001518fa86d7ae2a1cf8 new file mode 100644 index 0000000..c1a5059 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/f2/a0380b49d03e001518fa86d7ae2a1cf8 @@ -0,0 +1,200 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; + +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class Commands implements CommandExecutor { + // This method is called, when somebody uses our command + @Override + public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { + if (sender instanceof Player) { + Player player = (Player) sender; + if(args.length<1) + return false; + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. + //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) + if(p.Flair==null) + { + player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); + return true; + } + switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. + { + case "accept": + { + if(p.IgnoredFlair) + p.IgnoredFlair=false; //2015.08.08. + if(!p.AcceptedFlair) + { + String flair=p.Flair; //2015.08.08. + //PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + PluginMain.AppendPlayerDisplayFlair(p, player); + p.AcceptedFlair=true; //2015.08.08. + player.sendMessage("§6Your flair has been set:§r "+flair); + } + else + player.sendMessage("§cYou already have this user's flair.§r"); + break; + } + case "ignore": + { + if(p.AcceptedFlair) + p.AcceptedFlair=false; //2015.08.08. + if(!p.IgnoredFlair) + { + p.IgnoredFlair=true; + String flair=p.Flair; //2015.08.08. + PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. + player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); + } + else + player.sendMessage("§cYou already ignored this request.§r"); + break; + } + /*case "reload": //2015.07.20. + DoReload(player); + break;*/ + case "admin": //2015.08.09. + DoAdmin(player, args); + break; + case "nonpresser": //2015.08.09. + break; + case "cantpress": //2015.08.09. + break; + default: + return false; + } + return true; + } + /*if(args[0].toLowerCase()=="reload") + DoReload(null); //2015.07.20.*/ + else if(args.length>0 && args[0].toLowerCase().equals("admin")) //2015.08.09. + { + DoAdmin(null, args); //2015.08.09. + return true; //2015.08.09. + } + return false; + } + private static void DoReload(Player player) + { //2015.07.20. + //if(player==null || player.isOp() || player.getName()=="NorbiPeti") + //{ + try + { + File file=new File("autoflairconfig.txt"); + if(file.exists()) + { + PluginMain.TownColors.clear(); + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + PluginMain.TownColors.put(s[0], s[1]); + } + br.close(); + for(Player p : PluginMain.GetPlayers()) + { + MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName()); + if(mp.Flair!=null) + { + String flair=mp.Flair; + PluginMain.RemovePlayerDisplayFlairFinal(p, flair); + //PluginMain.AppendPlayerDisplayFlairFinal(p, flair); + PluginMain.AppendPlayerDisplayFlair(mp, p); //2015.08.09. + } + } + String msg="§6Reloaded config file.§r"; + SendMessage(player, msg); //2015.08.09. + } + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + if(player!=null) + player.sendMessage("§cAn error occured. See console for details.§r"); + PluginMain.LastException=e; //2015.08.09. + } + //} + //else + //player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static void DoAdmin(Player player, String[] args) + { //2015.08.09. + if(player==null || player.isOp() || player.getName()=="NorbiPeti") + { + //System.out.println("Args length: " + args.length); + if(args.length==1) + { + String message="§cUsage: /u admin reload|playerinfo§r"; + SendMessage(player, message); + return; + } + //args[0] is "admin" + switch(args[1].toLowerCase()) + { + case "reload": + DoReload(player); + break; + case "playerinfo": + DoPlayerInfo(player, args); + break; + case "getlasterror": + DoGetLastError(player, args); + default: + String message="§cUsage: /u admin reload|playerinfo§r"; + SendMessage(player, message); + return; + } + } + else + player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static void DoPlayerInfo(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "playerinfo" + if(args.length==2) + { + String message="§cUsage: /u admin playerinfo §r"; + SendMessage(player, message); + return; + } + if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2])) + { + String message="§cPlayer not found: "+args[2]+"§r"; + SendMessage(player, message); + return; + } + MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]); + SendMessage(player, "Player name: "+p.PlayerName); + SendMessage(player, "User flair: "+p.Flair); + SendMessage(player, "Username: "+p.UserName); + SendMessage(player, "Flair accepted: "+p.AcceptedFlair); + SendMessage(player, "Flair ignored: "+p.IgnoredFlair); + } + private static void SendMessage(Player player, String message) + { //2015.08.09. + if(player==null) + System.out.println(message); + else + player.sendMessage(message); + } + private static void DoGetLastError(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "getlasterror" + if(PluginMain.LastException!=null) + { + SendMessage(player, "Last error:"); + SendMessage(player, PluginMain.LastException.toString()); + PluginMain.LastException=null; + } + else + SendMessage(player, "There were no exceptions."); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/f3/203061bfd23e001518fa86d7ae2a1cf8 b/.metadata/.plugins/org.eclipse.core.resources/.history/f3/203061bfd23e001518fa86d7ae2a1cf8 new file mode 100644 index 0000000..717cff8 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/f3/203061bfd23e001518fa86d7ae2a1cf8 @@ -0,0 +1,215 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; + +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class Commands implements CommandExecutor { + // This method is called, when somebody uses our command + @Override + public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { + if (sender instanceof Player) { + Player player = (Player) sender; + if(args.length<1) + return false; + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. + //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) + if(p.Flair==null) + { + player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); + return true; + } + switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. + { + case "accept": + { + if(p.IgnoredFlair) + p.IgnoredFlair=false; //2015.08.08. + if(!p.AcceptedFlair) + { + String flair=p.Flair; //2015.08.08. + //PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + PluginMain.AppendPlayerDisplayFlair(p, player); + p.AcceptedFlair=true; //2015.08.08. + player.sendMessage("§6Your flair has been set:§r "+flair); + } + else + player.sendMessage("§cYou already have this user's flair.§r"); + break; + } + case "ignore": + { + if(p.AcceptedFlair) + p.AcceptedFlair=false; //2015.08.08. + if(!p.IgnoredFlair) + { + p.IgnoredFlair=true; + String flair=p.Flair; //2015.08.08. + PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. + player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); + } + else + player.sendMessage("§cYou already ignored this request.§r"); + break; + } + /*case "reload": //2015.07.20. + DoReload(player); + break;*/ + case "admin": //2015.08.09. + DoAdmin(player, args); + break; + case "nonpresser": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§7(non-pr.)§r"; + break; + case "cantpress": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§r(can't press)§r"; + break; + default: + return false; + } + return true; + } + /*if(args[0].toLowerCase()=="reload") + DoReload(null); //2015.07.20.*/ + else if(args.length>0 && args[0].toLowerCase().equals("admin")) //2015.08.09. + { + DoAdmin(null, args); //2015.08.09. + return true; //2015.08.09. + } + return false; + } + private static void DoReload(Player player) + { //2015.07.20. + //if(player==null || player.isOp() || player.getName()=="NorbiPeti") + //{ + try + { + File file=new File("autoflairconfig.txt"); + if(file.exists()) + { + PluginMain.LoadFiles(true); + 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); + PluginMain.AppendPlayerDisplayFlair(mp, p); //2015.08.09. + } + } + //String msg="§6Reloaded config file.§r"; + String msg="§6Reloaded all files.§r"; + SendMessage(player, msg); //2015.08.09. + } + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + if(player!=null) + player.sendMessage("§cAn error occured. See console for details.§r"); + PluginMain.LastException=e; //2015.08.09. + } + //} + //else + //player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static void DoAdmin(Player player, String[] args) + { //2015.08.09. + if(player==null || player.isOp() || player.getName()=="NorbiPeti") + { + //System.out.println("Args length: " + args.length); + if(args.length==1) + { + String message="§cUsage: /u admin reload|playerinfo§r"; + SendMessage(player, message); + return; + } + //args[0] is "admin" + switch(args[1].toLowerCase()) + { + case "reload": + DoReload(player); + break; + case "playerinfo": + DoPlayerInfo(player, args); + break; + case "getlasterror": + DoGetLastError(player, args); + default: + String message="§cUsage: /u admin reload|playerinfo§r"; + SendMessage(player, message); + return; + } + } + else + player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static void DoPlayerInfo(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "playerinfo" + if(args.length==2) + { + String message="§cUsage: /u admin playerinfo §r"; + SendMessage(player, message); + return; + } + if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2])) + { + String message="§cPlayer not found: "+args[2]+"§r"; + SendMessage(player, message); + return; + } + MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]); + SendMessage(player, "Player name: "+p.PlayerName); + SendMessage(player, "User flair: "+p.Flair); + SendMessage(player, "Username: "+p.UserName); + SendMessage(player, "Flair accepted: "+p.AcceptedFlair); + SendMessage(player, "Flair ignored: "+p.IgnoredFlair); + } + private static void SendMessage(Player player, String message) + { //2015.08.09. + if(player==null) + System.out.println(message); + else + player.sendMessage(message); + } + private static void DoGetLastError(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "getlasterror" + if(PluginMain.LastException!=null) + { + SendMessage(player, "Last error:"); + SendMessage(player, PluginMain.LastException.toString()); + PluginMain.LastException=null; + } + else + SendMessage(player, "There were no exceptions."); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/f3/50ae2f61873e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/f3/50ae2f61873e00151ce8ff6d4f74dabd deleted file mode 100644 index c1f1c9d..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/f3/50ae2f61873e00151ce8ff6d4f74dabd +++ /dev/null @@ -1,140 +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; - MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. - //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - if(p.Flair==null) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. - { - case "accept": - { - if(p.IgnoredFlair) - p.IgnoredFlair=false; //2015.08.08. - if(!p.AcceptedFlair) - { - String flair=p.Flair; //2015.08.08. - PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. - p.AcceptedFlair=true; //2015.08.08. - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("§cYou already have this user's flair.§r"); - break; - } - case "ignore": - { - if(p.AcceptedFlair) - p.AcceptedFlair=false; //2015.08.08. - if(!p.IgnoredFlair) - { - p.IgnoredFlair=true; - String flair=p.Flair; //2015.08.08. - PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. - player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); - } - else - player.sendMessage("§cYou already ignored this request.§r"); - break; - } - /*case "reload": //2015.07.20. - DoReload(player); - break;*/ - case "admin": //2015.08.09. - DoAdmin(player, args); - break; - default: - return false; - } - return true; - } - - /*if(args[0].toLowerCase()=="reload") - DoReload(null); //2015.07.20.*/ - else if(args[0].toLowerCase()=="admin") - DoAdmin(null, args); //2015.08.09. - return false; - } - private static void DoReload(Player player) - { //2015.07.20. - //if(player==null || player.isOp() || player.getName()=="NorbiPeti") - //{ - try - { - File file=new File("autoflairconfig.txt"); - if(file.exists()) - { - PluginMain.TownColors.clear(); - BufferedReader br=new BufferedReader(new FileReader(file)); - String line; - while((line=br.readLine())!=null) - { - String[] s=line.split(" "); - PluginMain.TownColors.put(s[0], s[1]); - } - br.close(); - for(Player p : PluginMain.GetPlayers()) - { - MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName()); - if(mp.Flair!=null) - { - String flair=mp.Flair; - PluginMain.RemovePlayerDisplayFlairFinal(p, flair); - PluginMain.AppendPlayerDisplayFlairFinal(p, flair); - } - } - String msg="§6Reloaded config file.§r"; - if(player!=null) - player.sendMessage(msg); - else - System.out.println(msg); - } - } - catch(Exception e) - { - System.out.println("Error!\n"+e); - if(player!=null) - player.sendMessage("§cAn error occured. See console for details.§r"); - } - //} - //else - //player.sendMessage("§cYou need to be OP to use this command.§r"); - } - private static void DoAdmin(Player player, String[] args) - { - if(player==null || player.isOp() || player.getName()=="NorbiPeti") - { - //args[0] is "admin" - switch(args[1].toLowerCase()) - { - case "reload": - DoReload(player); - break; - case "playerinfo": - DoPlayerInfo(player, args); - break; - } - } - else - player.sendMessage("§cYou need to be OP to use this command.§r"); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/f3/a09a2529d33e001518fa86d7ae2a1cf8 b/.metadata/.plugins/org.eclipse.core.resources/.history/f3/a09a2529d33e001518fa86d7ae2a1cf8 new file mode 100644 index 0000000..2a7e8d7 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/f3/a09a2529d33e001518fa86d7ae2a1cf8 @@ -0,0 +1,215 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; + +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class Commands implements CommandExecutor { + // This method is called, when somebody uses our command + @Override + public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { + if (sender instanceof Player) { + Player player = (Player) sender; + if(args.length<1) + return false; + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. + //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) + if(p.Flair==null) + { + player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); + return true; + } + switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. + { + case "accept": + { + if(p.IgnoredFlair) + p.IgnoredFlair=false; //2015.08.08. + if(!p.AcceptedFlair) + { + String flair=p.Flair; //2015.08.08. + //PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + PluginMain.AppendPlayerDisplayFlair(p, player); + p.AcceptedFlair=true; //2015.08.08. + player.sendMessage("§6Your flair has been set:§r "+flair); + } + else + player.sendMessage("§cYou already have this user's flair.§r"); + break; + } + case "ignore": + { + if(p.AcceptedFlair) + p.AcceptedFlair=false; //2015.08.08. + if(!p.IgnoredFlair) + { + p.IgnoredFlair=true; + String flair=p.Flair; //2015.08.08. + PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. + player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); + } + else + player.sendMessage("§cYou already ignored this request.§r"); + break; + } + /*case "reload": //2015.07.20. + DoReload(player); + break;*/ + case "admin": //2015.08.09. + DoAdmin(player, args); + break; + case "nonpresser": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§7(non-pr.)§r"; + break; + case "cantpress": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§r(can't press)§r"; + break; + default: + return false; + } + return true; + } + /*if(args[0].toLowerCase()=="reload") + DoReload(null); //2015.07.20.*/ + else if(args.length>0 && args[0].toLowerCase().equals("admin")) //2015.08.09. + { + DoAdmin(null, args); //2015.08.09. + return true; //2015.08.09. + } + return false; + } + private static void DoReload(Player player) + { //2015.07.20. + //if(player==null || player.isOp() || player.getName()=="NorbiPeti") + //{ + try + { + File file=new File("autoflairconfig.txt"); + if(file.exists()) + { + PluginMain.LoadFiles(true); //2015.08.09. + for(Player p : PluginMain.GetPlayers()) + { + MaybeOfflinePlayer mp = MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName()); + if(mp.Flair!=null) + { + String flair=mp.Flair; + PluginMain.RemovePlayerDisplayFlairFinal(p, flair); + //PluginMain.AppendPlayerDisplayFlairFinal(p, flair); + PluginMain.AppendPlayerDisplayFlair(mp, p); //2015.08.09. + } + } + //String msg="§6Reloaded config file.§r"; + String msg="§6Note: The auto-flair plugin has been reloaded. You might need to wait 10s to have your flair.§r"; + SendMessage(player, msg); //2015.08.09. + } + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + if(player!=null) + player.sendMessage("§cAn error occured. See console for details.§r"); + PluginMain.LastException=e; //2015.08.09. + } + //} + //else + //player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static void DoAdmin(Player player, String[] args) + { //2015.08.09. + if(player==null || player.isOp() || player.getName()=="NorbiPeti") + { + //System.out.println("Args length: " + args.length); + if(args.length==1) + { + String message="§cUsage: /u admin reload|playerinfo§r"; + SendMessage(player, message); + return; + } + //args[0] is "admin" + switch(args[1].toLowerCase()) + { + case "reload": + DoReload(player); + break; + case "playerinfo": + DoPlayerInfo(player, args); + break; + case "getlasterror": + DoGetLastError(player, args); + default: + String message="§cUsage: /u admin reload|playerinfo§r"; + SendMessage(player, message); + return; + } + } + else + player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static void DoPlayerInfo(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "playerinfo" + if(args.length==2) + { + String message="§cUsage: /u admin playerinfo §r"; + SendMessage(player, message); + return; + } + if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2])) + { + String message="§cPlayer not found: "+args[2]+"§r"; + SendMessage(player, message); + return; + } + MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]); + SendMessage(player, "Player name: "+p.PlayerName); + SendMessage(player, "User flair: "+p.Flair); + SendMessage(player, "Username: "+p.UserName); + SendMessage(player, "Flair accepted: "+p.AcceptedFlair); + SendMessage(player, "Flair ignored: "+p.IgnoredFlair); + } + private static void SendMessage(Player player, String message) + { //2015.08.09. + if(player==null) + System.out.println(message); + else + player.sendMessage(message); + } + private static void DoGetLastError(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "getlasterror" + if(PluginMain.LastException!=null) + { + SendMessage(player, "Last error:"); + SendMessage(player, PluginMain.LastException.toString()); + PluginMain.LastException=null; + } + else + SendMessage(player, "There were no exceptions."); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/f4/206dc8d8d83e001517108d149b613203 b/.metadata/.plugins/org.eclipse.core.resources/.history/f4/206dc8d8d83e001517108d149b613203 new file mode 100644 index 0000000..6d35231 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/f4/206dc8d8d83e001517108d149b613203 @@ -0,0 +1,224 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; + +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class Commands implements CommandExecutor { + // This method is called, when somebody uses our command + @Override + public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { + if (sender instanceof Player) { + Player player = (Player) sender; + if(args.length<1) + return false; + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. + //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) + if(p.Flair==null) + { + player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); + return true; + } + switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. + { + case "accept": + { + if(p.IgnoredFlair) + p.IgnoredFlair=false; //2015.08.08. + if(!p.AcceptedFlair) + { + String flair=p.Flair; //2015.08.08. + //PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + PluginMain.AppendPlayerDisplayFlair(p, player); + p.AcceptedFlair=true; //2015.08.08. + player.sendMessage("§6Your flair has been set:§r "+flair); + } + else + player.sendMessage("§cYou already have this user's flair.§r"); + break; + } + case "ignore": + { + if(p.AcceptedFlair) + p.AcceptedFlair=false; //2015.08.08. + if(!p.IgnoredFlair) + { + p.IgnoredFlair=true; + String flair=p.Flair; //2015.08.08. + PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. + player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); + } + else + player.sendMessage("§cYou already ignored this request.§r"); + break; + } + /*case "reload": //2015.07.20. + DoReload(player); + break;*/ + case "admin": //2015.08.09. + DoAdmin(player, args); + break; + case "nonpresser": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§7(non-pr.)§r"; + break; + case "cantpress": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§r(can't press)§r"; + break; + default: + return false; + } + return true; + } + /*if(args[0].toLowerCase()=="reload") + DoReload(null); //2015.07.20.*/ + else if(args.length>0 && args[0].toLowerCase().equals("admin")) //2015.08.09. + { + DoAdmin(null, args); //2015.08.09. + return true; //2015.08.09. + } + return false; + } + private static void DoReload(Player player) + { //2015.07.20. + //if(player==null || player.isOp() || player.getName()=="NorbiPeti") + //{ + try + { + File file=new File("autoflairconfig.txt"); + if(file.exists()) + { + PluginMain.LoadFiles(true); //2015.08.09. + for(Player p : PluginMain.GetPlayers()) + { + MaybeOfflinePlayer mp = MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName()); + if(mp.Flair!=null) + { + String flair=mp.Flair; + PluginMain.RemovePlayerDisplayFlairFinal(p, flair); + //PluginMain.AppendPlayerDisplayFlairFinal(p, flair); + PluginMain.AppendPlayerDisplayFlair(mp, p); //2015.08.09. + } + String msg="§6Note: The auto-flair plugin has been reloaded. You might need to wait 10s to have your flair.§r"; //2015.08.09. + p.sendMessage(msg); //2015.08.09. + } + //String msg="§6Reloaded config file.§r"; + //SendMessage(player, msg); //2015.08.09. + } + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + if(player!=null) + player.sendMessage("§cAn error occured. See console for details.§r"); + PluginMain.LastException=e; //2015.08.09. + } + //} + //else + //player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static Player ReloadPlayer; //2015.08.09. + private static void DoAdmin(Player player, String[] args) + { //2015.08.09. + if(player==null || player.isOp() || player.getName()=="NorbiPeti") + { + //System.out.println("Args length: " + args.length); + if(args.length==1) + { + String message="§cUsage: /u admin reload|playerinfo§r"; + SendMessage(player, message); + return; + } + //args[0] is "admin" + switch(args[1].toLowerCase()) + { + case "reload": + ReloadPlayer=player; //2015.08.09. + SendMessage(player, "§6Make sure to save the current settings before you modify and reload them! Type /u admin confirm when done.§r"); + break; + case "playerinfo": + DoPlayerInfo(player, args); + break; + case "getlasterror": + DoGetLastError(player, args); + case "confirm": + if(ReloadPlayer.equals(player)) + DoReload(player); //2015.08.09. + else + SendMessage(player, "§cYou need to do /u admin reload first.§r"); + break; + default: + String message="§cUsage: /u admin reload|playerinfo|getlasterror§r"; + SendMessage(player, message); + return; + } + } + else + player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static void DoPlayerInfo(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "playerinfo" + if(args.length==2) + { + String message="§cUsage: /u admin playerinfo §r"; + SendMessage(player, message); + return; + } + if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2])) + { + String message="§cPlayer not found: "+args[2]+"§r"; + SendMessage(player, message); + return; + } + MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]); + SendMessage(player, "Player name: "+p.PlayerName); + SendMessage(player, "User flair: "+p.Flair); + SendMessage(player, "Username: "+p.UserName); + SendMessage(player, "Flair accepted: "+p.AcceptedFlair); + SendMessage(player, "Flair ignored: "+p.IgnoredFlair); + } + private static void SendMessage(Player player, String message) + { //2015.08.09. + if(player==null) + System.out.println(message); + else + player.sendMessage(message); + } + private static void DoGetLastError(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "getlasterror" + if(PluginMain.LastException!=null) + { + SendMessage(player, "Last error:"); + SendMessage(player, PluginMain.LastException.toString()); + PluginMain.LastException=null; + } + else + SendMessage(player, "There were no exceptions."); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/f4/20d00369d23e001518fa86d7ae2a1cf8 b/.metadata/.plugins/org.eclipse.core.resources/.history/f4/20d00369d23e001518fa86d7ae2a1cf8 new file mode 100644 index 0000000..7316b80 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/f4/20d00369d23e001518fa86d7ae2a1cf8 @@ -0,0 +1,380 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStream; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLConnection; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + +import org.apache.commons.io.IOUtils; +import org.bukkit.entity.Player; +import org.bukkit.plugin.java.JavaPlugin; +import org.json.JSONArray; +import org.json.JSONObject; + +import com.palmergames.bukkit.towny.object.Town; +import com.palmergames.bukkit.towny.object.WorldCoord; + +public class PluginMain extends JavaPlugin +{ //Translated to Java: 2015.07.15. + //A user, which flair isn't obtainable: + //https://www.reddit.com/r/thebutton/comments/31c32v/i_pressed_the_button_without_really_thinking/ + private static PluginMain Instance; + // Fired when plugin is first enabled + @Override + public void onEnable() + { + System.out.println("The Button Auto-flair Plugin by NorbiPeti (:P)"); + getServer().getPluginManager().registerEvents(new PlayerListener(), this); + this.getCommand("u").setExecutor(new Commands()); + this.getCommand("u").setUsage(this.getCommand("u").getUsage().replace('&', '§')); + Instance=this; //2015.08.08. + LoadFiles(false); //2015.08.09. + Runnable r=new Runnable(){public void run(){ThreadMethod();}}; + Thread t=new Thread(r); + t.start(); + } + Boolean stop=false; + // Fired when plugin is disabled + @Override + public void onDisable() + { + try + { + FileWriter fw; + fw = new FileWriter("flairsaccepted.txt"); + fw.close(); + fw = new FileWriter("flairsignored.txt"); + fw.close(); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + try { + File file=new File("flairsaccepted.txt"); + BufferedWriter bw=new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.AcceptedFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + file=new File("flairsignored.txt"); + bw = new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.IgnoredFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + stop=true; + } + + public void ThreadMethod() //<-- 2015.07.16. + { + while(!stop) + { + try + { + String body=DownloadString("https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/autoflair_system_comment_your_minecraft_name_and/.json?limit=1000"); + JSONArray json=new JSONArray(body).getJSONObject(1).getJSONObject("data").getJSONArray("children"); + for(Object obj : json) + { + JSONObject item = (JSONObject)obj; + String author=item.getJSONObject("data").getString("author"); + String ign=item.getJSONObject("data").getString("body"); + int start = ign.indexOf("IGN:") + "IGN:".length(); + int end = ign.indexOf(' ', start); + if (end == -1 || end == start) + end=ign.indexOf('\n', start); //2015.07.15. + if (end == -1 || end == start) + ign = ign.substring(start); + else + ign = ign.substring(start, end); + ign = ign.trim(); + if(HasIGFlair(ign)) + continue; + try { + Thread.sleep(10); + } catch(InterruptedException ex) { + Thread.currentThread().interrupt(); + } + String[] flairdata = DownloadString("http://karmadecay.com/thebutton-data.php?users=" + author).replace("\"", "").split(":"); + String flair; + if(flairdata.length > 1) //2015.07.15. + flair = flairdata[1]; + else + flair=""; + if (flair != "-1") + flair = flair + "s"; + else + flair = "non-presser"; + String flairclass; + if(flairdata.length>2) + flairclass = flairdata[2]; + else + flairclass="unknown"; + SetFlair(ign, flair, flairclass, author); + } + Thread.sleep(10000); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + } + + public static Exception LastException; //2015.08.09. + + public String DownloadString(String urlstr) throws MalformedURLException, IOException + { + URL url = new URL(urlstr); + URLConnection con = url.openConnection(); + con.setRequestProperty("User-Agent", "TheButtonAutoFlair"); + InputStream in = con.getInputStream(); + String encoding = con.getContentEncoding(); + encoding = encoding == null ? "UTF-8" : encoding; + String body = IOUtils.toString(in, encoding); + in.close(); + return body; + } + + public static Map TownColors=new HashMap(); //2015.07.20. + public Boolean HasIGFlair(String playername) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + return p.Flair!=null; //2015.08.08. + } + + public void SetFlair(String playername, String text, String flairclass, String username) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + String finalflair; + p.FlairDecided=true; + switch(flairclass) + { + case "press-1": + finalflair="§c("+text+")§r"; + break; + case "press-2": + finalflair="§6("+text+")§r"; + break; + case "press-3": + finalflair="§e("+text+")§r"; + break; + case "press-4": + finalflair="§a("+text+")§r"; + break; + case "press-5": + finalflair="§9("+text+")§r"; + break; + 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; + case "undecided": //2015.08.09. + p.FlairDecided=false; + finalflair=""; + break; + default: + finalflair=""; + break; + } + if(finalflair.length()==0) //<-- 2015.07.20. + return; + p.Flair=finalflair; //2015.08.08. + p.UserName=username; //2015.08.08. + System.out.println("Added new flair to "+playername+": "+finalflair); + for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08. + { + if(player.getName().equals(playername)) + { + //AppendPlayerDisplayFlair(player, username, finalflair); + AppendPlayerDisplayFlair(p, player); + break; + } + } + } + + public static String GetFlair(Player player) + { //2015.07.16. + String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08. + return flair==null ? "" : flair; + } + + //public static void AppendPlayerDisplayFlair(Player player, String username, String flair) + public static void AppendPlayerDisplayFlair(MaybeOfflinePlayer player, Player p) //<-- 2015.08.09. + { + + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).IgnoredFlair) + return; + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).AcceptedFlair) + { + AppendPlayerDisplayFlairFinal(p, player.Flair); //2015.07.20. + if(!player.FlairDecided) + p.sendMessage("§9Your flair type is unknown. Are you a non-presser or a can't press? (/u nonpresser or /u cantpress)§r"); //2015.08.09. + } + else + p.sendMessage("§9Are you Reddit user "+player.UserName+"?§r §6Type /u accept or /u ignore§r"); + } + + private static void AppendPlayerDisplayFlairFinal(Player player, String flair) + { //2015.07.20. + String color = GetColorForTown(GetPlayerTown(player)); //TO!DO: Multiple colors put on first capital letters + String[] colors = color.substring(1).split("§"); + String displayname=player.getName(); //2015.08.08. + ArrayList Positions=new ArrayList<>(); + for(int i=0; i=colors.length) + { + int x=0; + for(int i=0; i GetPlayers() + { + return Instance.getServer().getOnlinePlayers(); + } + + public static void LoadFiles(boolean reload) //<-- 2015.08.09. + { + if(reload) + { //2015.08.09. + System.out.println("Auto-flair plugin cleanup for reloading..."); + MaybeOfflinePlayer.AllPlayers.clear(); + TownColors.clear(); + } + System.out.println("Loading files for auto-flair plugin..."); //2015.08.09. + try { + File file=new File("flairsaccepted.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + //System.out.println("Name: " + name); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("flairsignored.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsignored.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("autoflairconfig.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + TownColors.put(s[0], s[1]); + } + br.close(); + } + //throw new IOException("Test"); //2015.08.09. + System.out.println("Auto-flair plugin loaded files!"); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + public static void SaveFiles() + { + + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/f4/5072900e883e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/f4/5072900e883e00151ce8ff6d4f74dabd deleted file mode 100644 index e500f17..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/f4/5072900e883e00151ce8ff6d4f74dabd +++ /dev/null @@ -1,162 +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; - MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. - //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - if(p.Flair==null) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. - { - case "accept": - { - if(p.IgnoredFlair) - p.IgnoredFlair=false; //2015.08.08. - if(!p.AcceptedFlair) - { - String flair=p.Flair; //2015.08.08. - PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. - p.AcceptedFlair=true; //2015.08.08. - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("§cYou already have this user's flair.§r"); - break; - } - case "ignore": - { - if(p.AcceptedFlair) - p.AcceptedFlair=false; //2015.08.08. - if(!p.IgnoredFlair) - { - p.IgnoredFlair=true; - String flair=p.Flair; //2015.08.08. - PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. - player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); - } - else - player.sendMessage("§cYou already ignored this request.§r"); - break; - } - /*case "reload": //2015.07.20. - DoReload(player); - break;*/ - case "admin": //2015.08.09. - DoAdmin(player, args); - break; - default: - return false; - } - return true; - } - - /*if(args[0].toLowerCase()=="reload") - DoReload(null); //2015.07.20.*/ - else if(args[0].toLowerCase()=="admin") - DoAdmin(null, args); //2015.08.09. - return false; - } - private static void DoReload(Player player) - { //2015.07.20. - //if(player==null || player.isOp() || player.getName()=="NorbiPeti") - //{ - try - { - File file=new File("autoflairconfig.txt"); - if(file.exists()) - { - PluginMain.TownColors.clear(); - BufferedReader br=new BufferedReader(new FileReader(file)); - String line; - while((line=br.readLine())!=null) - { - String[] s=line.split(" "); - PluginMain.TownColors.put(s[0], s[1]); - } - br.close(); - for(Player p : PluginMain.GetPlayers()) - { - MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName()); - if(mp.Flair!=null) - { - String flair=mp.Flair; - PluginMain.RemovePlayerDisplayFlairFinal(p, flair); - PluginMain.AppendPlayerDisplayFlairFinal(p, flair); - } - } - String msg="§6Reloaded config file.§r"; - if(player!=null) - player.sendMessage(msg); - else - System.out.println(msg); - } - } - catch(Exception e) - { - System.out.println("Error!\n"+e); - if(player!=null) - player.sendMessage("§cAn error occured. See console for details.§r"); - } - //} - //else - //player.sendMessage("§cYou need to be OP to use this command.§r"); - } - private static void DoAdmin(Player player, String[] args) - { //2015.08.09. - if(player==null || player.isOp() || player.getName()=="NorbiPeti") - { - if(args.length==1) - { - String message="§cUsage: /u admin playerinfo§r"; - if(player==null) - System.out.println(message); - else - player.sendMessage(message); - return; - } - //args[0] is "admin" - switch(args[1].toLowerCase()) - { - case "reload": - DoReload(player); - break; - case "playerinfo": - DoPlayerInfo(player, args); - break; - } - } - else - player.sendMessage("§cYou need to be OP to use this command.§r"); - } - private static void DoPlayerInfo(Player player, String[] args) - { //2015.08.09. - //args[0] is "admin" - args[1] is "playerinfo" - if(args.length==2) - { - String message="§cUsage: /u admin playerinfo §r"; - if(player==null) - System.out.println(message); - else - player.sendMessage(message); - return; - } - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/f4/80e28d69e43e001517108d149b613203 b/.metadata/.plugins/org.eclipse.core.resources/.history/f4/80e28d69e43e001517108d149b613203 new file mode 100644 index 0000000..12a63df --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/f4/80e28d69e43e001517108d149b613203 @@ -0,0 +1,263 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedWriter; +import java.io.File; +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; + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. + //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) + if(p.Flair==null) + { + player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); + return true; + } + switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. + { + case "accept": + { + if(p.IgnoredFlair) + p.IgnoredFlair=false; //2015.08.08. + if(!p.AcceptedFlair) + { + String flair=p.Flair; //2015.08.08. + //PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + PluginMain.AppendPlayerDisplayFlair(p, player); + p.AcceptedFlair=true; //2015.08.08. + player.sendMessage("§6Your flair has been set:§r "+flair); + } + else + player.sendMessage("§cYou already have this user's flair.§r"); + break; + } + case "ignore": + { + if(p.AcceptedFlair) + p.AcceptedFlair=false; //2015.08.08. + if(!p.IgnoredFlair) + { + p.IgnoredFlair=true; + //String flair=p.Flair; //2015.08.08. + //PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. + player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); + } + else + player.sendMessage("§cYou already ignored this request.§r"); + break; + } + /*case "reload": //2015.07.20. + DoReload(player); + break;*/ + case "admin": //2015.08.09. + DoAdmin(player, args); + break; + case "nonpresser": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§7(non-pr.)§r"; + break; + case "cantpress": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§r(can't press)§r"; + break; + default: + return false; + } + return true; + } + /*if(args[0].toLowerCase()=="reload") + DoReload(null); //2015.07.20.*/ + else if(args.length>0 && args[0].toLowerCase().equals("admin")) //2015.08.09. + { + DoAdmin(null, args); //2015.08.09. + return true; //2015.08.09. + } + return false; + } + private static void DoReload(Player player) + { //2015.07.20. + //if(player==null || player.isOp() || player.getName()=="NorbiPeti") + //{ + try + { + File file=new File("autoflairconfig.txt"); + if(file.exists()) + { + PluginMain.LoadFiles(true); //2015.08.09. + for(Player p : PluginMain.GetPlayers()) + { + MaybeOfflinePlayer mp = MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName()); + if(mp.Flair!=null) + { + String flair=mp.Flair; + //PluginMain.RemovePlayerDisplayFlairFinal(p, flair); + //PluginMain.AppendPlayerDisplayFlairFinal(p, flair); + PluginMain.AppendPlayerDisplayFlair(mp, p); //2015.08.09. + } + String msg="§6Note: The auto-flair plugin has been reloaded. You might need to wait 10s to have your flair.§r"; //2015.08.09. + p.sendMessage(msg); //2015.08.09. + } + //String msg="§6Reloaded config file.§r"; + //SendMessage(player, msg); //2015.08.09. + } + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + if(player!=null) + player.sendMessage("§cAn error occured. See console for details.§r"); + PluginMain.LastException=e; //2015.08.09. + } + //} + //else + //player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static Player ReloadPlayer; //2015.08.09. + private static void DoAdmin(Player player, String[] args) + { //2015.08.09. + if(player==null || player.isOp() || player.getName()=="NorbiPeti") + { + //System.out.println("Args length: " + args.length); + if(args.length==1) + { + String message="§cUsage: /u admin reload|playerinfo§r"; + SendMessage(player, message); + return; + } + //args[0] is "admin" + switch(args[1].toLowerCase()) + { + case "reload": + ReloadPlayer=player; //2015.08.09. + SendMessage(player, "§6Make sure to save the current settings before you modify and reload them! Type /u admin confirm when done.§r"); + break; + case "playerinfo": + DoPlayerInfo(player, args); + break; + case "getlasterror": + DoGetLastError(player, args); + case "confirm": + if(ReloadPlayer==player) + DoReload(player); //2015.08.09. + else + SendMessage(player, "§cYou need to do /u admin reload first.§r"); + break; + case "save": + PluginMain.SaveFiles(); //2015.08.09. + SendMessage(player, "§6Saved files. Now you can edit them and reload if you want.§r"); + break; + case "setflair": + DoSetFlair(player, args); + break; + default: + String message="§cUsage: /u admin reload|playerinfo|getlasterror|save|setflair§r"; + SendMessage(player, message); + return; + } + } + else + player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static void DoPlayerInfo(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "playerinfo" + if(args.length==2) + { + String message="§cUsage: /u admin playerinfo §r"; + SendMessage(player, message); + return; + } + if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2])) + { + String message="§cPlayer not found: "+args[2]+"§r"; + SendMessage(player, message); + return; + } + MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]); + SendMessage(player, "Player name: "+p.PlayerName); + SendMessage(player, "User flair: "+p.Flair); + SendMessage(player, "Username: "+p.UserName); + SendMessage(player, "Flair accepted: "+p.AcceptedFlair); + SendMessage(player, "Flair ignored: "+p.IgnoredFlair); + } + private static void SendMessage(Player player, String message) + { //2015.08.09. + if(player==null) + System.out.println(message); + else + player.sendMessage(message); + } + private static void DoGetLastError(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "getlasterror" + if(PluginMain.LastException!=null) + { + SendMessage(player, "Last error:"); + SendMessage(player, PluginMain.LastException.toString()); + PluginMain.LastException=null; + } + else + SendMessage(player, "There were no exceptions."); + } + private static void SetPlayerFlair(Player player, MaybeOfflinePlayer targetplayer, String flair) + { //2015.08.09. + flair=flair.replace('&', '§'); + targetplayer.Flair=flair; + if(!PluginMain.RemoveLineFromFile("customflairs.txt", targetplayer.PlayerName)) + { + SendMessage(player, "§cError removing previous custom flair!§r"); + return; + } + File file=new File("customflairs.txt"); + try { + BufferedWriter bw; + bw = new BufferedWriter(new FileWriter(file, true)); + bw.write(targetplayer.PlayerName+"\n"); + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + PluginMain.LastException=e; //2015.08.09. + } + SendMessage(player, "§6The flair has been set. Player: "+targetplayer.PlayerName+" Flair: "+flair+"§r"); + } + private static void DoSetFlair(Player player, String[] args) + { + //args[0] is "admin" - args[1] is "setflair" + if(args.length<4) + { + SendMessage(player, "§cUsage: /u admin setflair "); + return; + } + SetPlayerFlair(player, MaybeOfflinePlayer.AddPlayerIfNeeded(args[2]), args[3]); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/f5/9050bb87de3e001517108d149b613203 b/.metadata/.plugins/org.eclipse.core.resources/.history/f5/9050bb87de3e001517108d149b613203 new file mode 100644 index 0000000..454cbb7 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/f5/9050bb87de3e001517108d149b613203 @@ -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)"); + getServer().getPluginManager().registerEvents(new PlayerListener(), this); + this.getCommand("u").setExecutor(new Commands()); + this.getCommand("u").setUsage(this.getCommand("u").getUsage().replace('&', '§')); + Instance=this; //2015.08.08. + LoadFiles(false); //2015.08.09. + Runnable r=new Runnable(){public void run(){ThreadMethod();}}; + Thread t=new Thread(r); + t.start(); + } + Boolean stop=false; + // Fired when plugin is disabled + @Override + public void onDisable() + { + SaveFiles(); //2015.08.09. + stop=true; + } + + public void ThreadMethod() //<-- 2015.07.16. + { + while(!stop) + { + try + { + String body=DownloadString("https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/autoflair_system_comment_your_minecraft_name_and/.json?limit=1000"); + JSONArray json=new JSONArray(body).getJSONObject(1).getJSONObject("data").getJSONArray("children"); + for(Object obj : json) + { + JSONObject item = (JSONObject)obj; + String author=item.getJSONObject("data").getString("author"); + String ign=item.getJSONObject("data").getString("body"); + int start = ign.indexOf("IGN:") + "IGN:".length(); + if(start==-1) + continue; //2015.08.09. + int end = ign.indexOf(' ', start); + if (end == -1 || end == start) + end=ign.indexOf('\n', start); //2015.07.15. + if (end == -1 || end == start) + ign = ign.substring(start); + else + ign = ign.substring(start, end); + ign = ign.trim(); + if(HasIGFlair(ign)) + continue; + try { + Thread.sleep(10); + } catch(InterruptedException ex) { + Thread.currentThread().interrupt(); + } + String[] flairdata = DownloadString("http://karmadecay.com/thebutton-data.php?users=" + author).replace("\"", "").split(":"); + String flair; + if(flairdata.length > 1) //2015.07.15. + flair = flairdata[1]; + else + flair=""; + if (flair != "-1") + flair = flair + "s"; + else + flair = "non-presser"; + String flairclass; + if(flairdata.length>2) + flairclass = flairdata[2]; + else + flairclass="unknown"; + SetFlair(ign, flair, flairclass, author); + } + Thread.sleep(10000); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + } + + public static Exception LastException; //2015.08.09. + + public String DownloadString(String urlstr) throws MalformedURLException, IOException + { + URL url = new URL(urlstr); + URLConnection con = url.openConnection(); + con.setRequestProperty("User-Agent", "TheButtonAutoFlair"); + InputStream in = con.getInputStream(); + String encoding = con.getContentEncoding(); + encoding = encoding == null ? "UTF-8" : encoding; + String body = IOUtils.toString(in, encoding); + in.close(); + return body; + } + + public static Map TownColors=new HashMap(); //2015.07.20. + public Boolean HasIGFlair(String playername) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + return p.Flair!=null; //2015.08.08. + } + + public void SetFlair(String playername, String text, String flairclass, String username) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + String finalflair; + p.FlairDecided=true; + switch(flairclass) + { + case "press-1": + finalflair="§c("+text+")§r"; + break; + case "press-2": + finalflair="§6("+text+")§r"; + break; + case "press-3": + finalflair="§e("+text+")§r"; + break; + case "press-4": + finalflair="§a("+text+")§r"; + break; + case "press-5": + finalflair="§9("+text+")§r"; + break; + 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; + case "undecided": //2015.08.09. + p.FlairDecided=false; + finalflair=""; + break; + default: + finalflair=""; + break; + } + if(finalflair.length()==0) //<-- 2015.07.20. + return; + p.Flair=finalflair; //2015.08.08. + p.UserName=username; //2015.08.08. + System.out.println("Added new flair to "+playername+": "+finalflair); + for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08. + { + if(player.getName().equals(playername)) + { + //AppendPlayerDisplayFlair(player, username, finalflair); + AppendPlayerDisplayFlair(p, player); + break; + } + } + } + + public static String GetFlair(Player player) + { //2015.07.16. + String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08. + return flair==null ? "" : flair; + } + + //public static void AppendPlayerDisplayFlair(Player player, String username, String flair) + public static void AppendPlayerDisplayFlair(MaybeOfflinePlayer player, Player p) //<-- 2015.08.09. + { + + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).IgnoredFlair) + return; + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).AcceptedFlair) + { + AppendPlayerDisplayFlairFinal(p, player.Flair); //2015.07.20. + if(!player.FlairDecided) + p.sendMessage("§9Your flair type is unknown. Are you a non-presser or a can't press? (/u nonpresser or /u cantpress)§r"); //2015.08.09. + } + else + p.sendMessage("§9Are you Reddit user "+player.UserName+"?§r §6Type /u accept or /u ignore§r"); + } + + private static void AppendPlayerDisplayFlairFinal(Player player, String flair) + { //2015.07.20. + String color = GetColorForTown(GetPlayerTown(player)); //TO!DO: Multiple colors put on first capital letters + String[] colors = color.substring(1).split("§"); + String displayname=player.getName(); //2015.08.08. + ArrayList Positions=new ArrayList<>(); + for(int i=0; i=colors.length) + { + int x=0; + for(int i=0; i GetPlayers() + { + return Instance.getServer().getOnlinePlayers(); + } + + public static void LoadFiles(boolean reload) //<-- 2015.08.09. + { + if(reload) + { //2015.08.09. + System.out.println("Auto-flair plugin cleanup for reloading..."); + MaybeOfflinePlayer.AllPlayers.clear(); + TownColors.clear(); + } + System.out.println("Loading files for auto-flair plugin..."); //2015.08.09. + try { + File file=new File("flairsaccepted.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + //System.out.println("Name: " + name); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("flairsignored.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsignored.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("autoflairconfig.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + TownColors.put(s[0], s[1]); + } + br.close(); + } + file=new File("customflairs.txt"); //2015.08.09. + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + MaybeOfflinePlayer.AddPlayerIfNeeded(s[0]).Flair=s[1]; //2015.08.09. + } + br.close(); + } + //throw new IOException("Test"); //2015.08.09. + System.out.println("Auto-flair plugin loaded files!"); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + public static void SaveFiles() //<-- 2015.08.09. + { + try + { + FileWriter fw; + fw = new FileWriter("flairsaccepted.txt"); + fw.close(); + fw = new FileWriter("flairsignored.txt"); + fw.close(); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + try { + File file=new File("flairsaccepted.txt"); + BufferedWriter bw=new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.AcceptedFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + file=new File("flairsignored.txt"); + bw = new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.IgnoredFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + public static void SetPlayerFlair(Player player, String flair) + { //2015.08.09. + flair=flair.replace('&', '§'); + MaybeOfflinePlayer.AddPlayerIfNeeded(player.getName()).Flair=flair; + File file=new File("customflairs.txt"); + BufferedWriter bw; + try { + bw = new BufferedWriter(new FileWriter(file, true)); + bw.write(player.getName()+"\n"); + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + public static void RemoveLineFromFile(String file) + { + File inputFile = new File(file); + File tempFile = new File("_temp.txt"); + + BufferedReader reader = new BufferedReader(new FileReader(inputFile)); + BufferedWriter writer = new BufferedWriter(new FileWriter(tempFile)); + + String lineToRemove = "bbb"; + String currentLine; + + while((currentLine = reader.readLine()) != null) { + // trim newline when comparing with lineToRemove + String trimmedLine = currentLine.trim(); + if(trimmedLine.equals(lineToRemove)) continue; + writer.write(currentLine + System.getProperty("line.separator")); + } + writer.close(); + reader.close(); + boolean successful = tempFile.renameTo(inputFile); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/f8/108fca500c3e00151089cca86c5b1a99 b/.metadata/.plugins/org.eclipse.core.resources/.history/f8/108fca500c3e00151089cca86c5b1a99 deleted file mode 100644 index 4697c6f..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/f8/108fca500c3e00151089cca86c5b1a99 +++ /dev/null @@ -1,432 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import java.io.BufferedReader; -import java.io.BufferedWriter; -import java.io.File; -import java.io.FileReader; -import java.io.FileWriter; -import java.io.IOException; -import java.io.InputStream; -import java.net.MalformedURLException; -import java.net.URL; -import java.net.URLConnection; -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; -import java.util.Map; - -import org.apache.commons.io.IOUtils; -import org.bukkit.entity.Player; -import org.bukkit.plugin.java.JavaPlugin; -import org.json.JSONArray; -import org.json.JSONObject; - -import com.palmergames.bukkit.towny.object.Town; -import com.palmergames.bukkit.towny.object.WorldCoord; - -public class PluginMain extends JavaPlugin -{ //Translated to Java: 2015.07.15. - //A user, which flair isn't obtainable: - //https://www.reddit.com/r/thebutton/comments/31c32v/i_pressed_the_button_without_really_thinking/ - private static PluginMain Instance; - // Fired when plugin is first enabled - @Override - public void onEnable() - { - System.out.println("The Button Auto-flair Plugin by NorbiPeti (:P)"); - //System.out.println("Original C# version: http://pastebin.com/tX8xCPbp"); - //System.out.println("The Java version is... Also made by the same person."); - //System.out.println("With the help of StackOverflow and similar."); - /*catch(MalformedURLException e) - { - } - catch(IOException e) - { - }*/ - getServer().getPluginManager().registerEvents(new PlayerListener(), this); - //System.out.println("Registering commands..."); - this.getCommand("u").setExecutor(new Commands()); - this.getCommand("u").setUsage(this.getCommand("u").getUsage().replace('&', '§')); - Instance=this; //2015.08.08. - try { - File file=new File("flairsaccepted.txt"); - if(file.exists()) - { - BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt")); - String line; - while ((line = br.readLine()) != null) - { - //AcceptedPlayers.add(line.replace("\n", "")); - String name=line.replace("\n", ""); - System.out.println("Name: " + name); - 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/f9/a01791b5d13e001518fa86d7ae2a1cf8 b/.metadata/.plugins/org.eclipse.core.resources/.history/f9/a01791b5d13e001518fa86d7ae2a1cf8 new file mode 100644 index 0000000..6f7db8d --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/f9/a01791b5d13e001518fa86d7ae2a1cf8 @@ -0,0 +1,369 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStream; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLConnection; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + +import org.apache.commons.io.IOUtils; +import org.bukkit.entity.Player; +import org.bukkit.plugin.java.JavaPlugin; +import org.json.JSONArray; +import org.json.JSONObject; + +import com.palmergames.bukkit.towny.object.Town; +import com.palmergames.bukkit.towny.object.WorldCoord; + +public class PluginMain extends JavaPlugin +{ //Translated to Java: 2015.07.15. + //A user, which flair isn't obtainable: + //https://www.reddit.com/r/thebutton/comments/31c32v/i_pressed_the_button_without_really_thinking/ + private static PluginMain Instance; + // Fired when plugin is first enabled + @Override + public void onEnable() + { + System.out.println("The Button Auto-flair Plugin by NorbiPeti (:P)"); + getServer().getPluginManager().registerEvents(new PlayerListener(), this); + this.getCommand("u").setExecutor(new Commands()); + this.getCommand("u").setUsage(this.getCommand("u").getUsage().replace('&', '§')); + Instance=this; //2015.08.08. + LoadFiles(false); //2015.08.09. + Runnable r=new Runnable(){public void run(){ThreadMethod();}}; + Thread t=new Thread(r); + t.start(); + } + Boolean stop=false; + // Fired when plugin is disabled + @Override + public void onDisable() + { + try + { + FileWriter fw; + fw = new FileWriter("flairsaccepted.txt"); + fw.close(); + fw = new FileWriter("flairsignored.txt"); + fw.close(); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + try { + File file=new File("flairsaccepted.txt"); + BufferedWriter bw=new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.AcceptedFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + file=new File("flairsignored.txt"); + bw = new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.IgnoredFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + stop=true; + } + + public void ThreadMethod() //<-- 2015.07.16. + { + while(!stop) + { + try + { + String body=DownloadString("https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/autoflair_system_comment_your_minecraft_name_and/.json?limit=1000"); + JSONArray json=new JSONArray(body).getJSONObject(1).getJSONObject("data").getJSONArray("children"); + for(Object obj : json) + { + JSONObject item = (JSONObject)obj; + String author=item.getJSONObject("data").getString("author"); + String ign=item.getJSONObject("data").getString("body"); + int start = ign.indexOf("IGN:") + "IGN:".length(); + int end = ign.indexOf(' ', start); + if (end == -1 || end == start) + end=ign.indexOf('\n', start); //2015.07.15. + if (end == -1 || end == start) + ign = ign.substring(start); + else + ign = ign.substring(start, end); + ign = ign.trim(); + if(HasIGFlair(ign)) + continue; + try { + Thread.sleep(10); + } catch(InterruptedException ex) { + Thread.currentThread().interrupt(); + } + String[] flairdata = DownloadString("http://karmadecay.com/thebutton-data.php?users=" + author).replace("\"", "").split(":"); + String flair; + if(flairdata.length > 1) //2015.07.15. + flair = flairdata[1]; + else + flair=""; + if (flair != "-1") + flair = flair + "s"; + else + flair = "non-presser"; + String flairclass; + if(flairdata.length>2) + flairclass = flairdata[2]; + else + flairclass="unknown"; + SetFlair(ign, flair, flairclass, author); + } + Thread.sleep(10000); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + } + + public static Exception LastException; //2015.08.09. + + public String DownloadString(String urlstr) throws MalformedURLException, IOException + { + URL url = new URL(urlstr); + URLConnection con = url.openConnection(); + con.setRequestProperty("User-Agent", "TheButtonAutoFlair"); + InputStream in = con.getInputStream(); + String encoding = con.getContentEncoding(); + encoding = encoding == null ? "UTF-8" : encoding; + String body = IOUtils.toString(in, encoding); + in.close(); + return body; + } + + public static Map TownColors=new HashMap(); //2015.07.20. + public Boolean HasIGFlair(String playername) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + return p.Flair!=null; //2015.08.08. + } + + public void SetFlair(String playername, String text, String flairclass, String username) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + String finalflair; + p.FlairDecided=true; + switch(flairclass) + { + case "press-1": + finalflair="§c("+text+")§r"; + break; + case "press-2": + finalflair="§6("+text+")§r"; + break; + case "press-3": + finalflair="§e("+text+")§r"; + break; + case "press-4": + finalflair="§a("+text+")§r"; + break; + case "press-5": + finalflair="§9("+text+")§r"; + break; + 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; + case "undecided": //2015.08.09. + p.FlairDecided=false; + finalflair=""; + break; + default: + finalflair=""; + break; + } + if(finalflair.length()==0) //<-- 2015.07.20. + return; + p.Flair=finalflair; //2015.08.08. + p.UserName=username; //2015.08.08. + System.out.println("Added new flair to "+playername+": "+finalflair); + for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08. + { + if(player.getName().equals(playername)) + { + //AppendPlayerDisplayFlair(player, username, finalflair); + AppendPlayerDisplayFlair(p, player); + break; + } + } + } + + public static String GetFlair(Player player) + { //2015.07.16. + String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08. + return flair==null ? "" : flair; + } + + //public static void AppendPlayerDisplayFlair(Player player, String username, String flair) + public static void AppendPlayerDisplayFlair(MaybeOfflinePlayer player, Player p) //<-- 2015.08.09. + { + + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).IgnoredFlair) + return; + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).AcceptedFlair) + { + AppendPlayerDisplayFlairFinal(p, player.Flair); //2015.07.20. + if(!player.FlairDecided) + p.sendMessage("§9Your flair type is unknown. Are you a non-presser or a can't press? (/u nonpresser or /u cantpress)§r"); //2015.08.09. + } + else + p.sendMessage("§9Are you Reddit user "+player.UserName+"?§r §6Type /u accept or /u ignore§r"); + } + + private static void AppendPlayerDisplayFlairFinal(Player player, String flair) + { //2015.07.20. + String color = GetColorForTown(GetPlayerTown(player)); //TO!DO: Multiple colors put on first capital letters + String[] colors = color.substring(1).split("§"); + String displayname=player.getName(); //2015.08.08. + ArrayList Positions=new ArrayList<>(); + for(int i=0; i=colors.length) + { + int x=0; + for(int i=0; i GetPlayers() + { + return Instance.getServer().getOnlinePlayers(); + } + + public static void LoadFiles(boolean reload) + { + MaybeOfflinePlayer.AllPlayers.clear(); + try { + File file=new File("flairsaccepted.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + //System.out.println("Name: " + name); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("flairsignored.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsignored.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("autoflairconfig.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + TownColors.put(s[0], s[1]); + } + br.close(); + } + //throw new IOException("Test"); //2015.08.09. + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/fa/90ef83b4e03e001517108d149b613203 b/.metadata/.plugins/org.eclipse.core.resources/.history/fa/90ef83b4e03e001517108d149b613203 new file mode 100644 index 0000000..21d2086 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/fa/90ef83b4e03e001517108d149b613203 @@ -0,0 +1,263 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +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; + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. + //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) + if(p.Flair==null) + { + player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); + return true; + } + switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. + { + case "accept": + { + if(p.IgnoredFlair) + p.IgnoredFlair=false; //2015.08.08. + if(!p.AcceptedFlair) + { + String flair=p.Flair; //2015.08.08. + //PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + PluginMain.AppendPlayerDisplayFlair(p, player); + p.AcceptedFlair=true; //2015.08.08. + player.sendMessage("§6Your flair has been set:§r "+flair); + } + else + player.sendMessage("§cYou already have this user's flair.§r"); + break; + } + case "ignore": + { + if(p.AcceptedFlair) + p.AcceptedFlair=false; //2015.08.08. + if(!p.IgnoredFlair) + { + p.IgnoredFlair=true; + String flair=p.Flair; //2015.08.08. + PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. + player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); + } + else + player.sendMessage("§cYou already ignored this request.§r"); + break; + } + /*case "reload": //2015.07.20. + DoReload(player); + break;*/ + case "admin": //2015.08.09. + DoAdmin(player, args); + break; + case "nonpresser": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§7(non-pr.)§r"; + break; + case "cantpress": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§r(can't press)§r"; + break; + default: + return false; + } + return true; + } + /*if(args[0].toLowerCase()=="reload") + DoReload(null); //2015.07.20.*/ + else if(args.length>0 && args[0].toLowerCase().equals("admin")) //2015.08.09. + { + DoAdmin(null, args); //2015.08.09. + return true; //2015.08.09. + } + return false; + } + private static void DoReload(Player player) + { //2015.07.20. + //if(player==null || player.isOp() || player.getName()=="NorbiPeti") + //{ + try + { + File file=new File("autoflairconfig.txt"); + if(file.exists()) + { + PluginMain.LoadFiles(true); //2015.08.09. + for(Player p : PluginMain.GetPlayers()) + { + MaybeOfflinePlayer mp = MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName()); + if(mp.Flair!=null) + { + String flair=mp.Flair; + PluginMain.RemovePlayerDisplayFlairFinal(p, flair); + //PluginMain.AppendPlayerDisplayFlairFinal(p, flair); + PluginMain.AppendPlayerDisplayFlair(mp, p); //2015.08.09. + } + String msg="§6Note: The auto-flair plugin has been reloaded. You might need to wait 10s to have your flair.§r"; //2015.08.09. + p.sendMessage(msg); //2015.08.09. + } + //String msg="§6Reloaded config file.§r"; + //SendMessage(player, msg); //2015.08.09. + } + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + if(player!=null) + player.sendMessage("§cAn error occured. See console for details.§r"); + PluginMain.LastException=e; //2015.08.09. + } + //} + //else + //player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static Player ReloadPlayer; //2015.08.09. + private static void DoAdmin(Player player, String[] args) + { //2015.08.09. + if(player==null || player.isOp() || player.getName()=="NorbiPeti") + { + //System.out.println("Args length: " + args.length); + if(args.length==1) + { + String message="§cUsage: /u admin reload|playerinfo§r"; + SendMessage(player, message); + return; + } + //args[0] is "admin" + switch(args[1].toLowerCase()) + { + case "reload": + ReloadPlayer=player; //2015.08.09. + SendMessage(player, "§6Make sure to save the current settings before you modify and reload them! Type /u admin confirm when done.§r"); + break; + case "playerinfo": + DoPlayerInfo(player, args); + break; + case "getlasterror": + DoGetLastError(player, args); + case "confirm": + if(ReloadPlayer==player) + DoReload(player); //2015.08.09. + else + SendMessage(player, "§cYou need to do /u admin reload first.§r"); + break; + case "save": + PluginMain.SaveFiles(); //2015.08.09. + SendMessage(player, "§6Saved files. Now you can edit them and reload if you want.§r"); + break; + case "setflair": + + break; + default: + String message="§cUsage: /u admin reload|playerinfo|getlasterror|save§r"; + SendMessage(player, message); + return; + } + } + else + player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static void DoPlayerInfo(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "playerinfo" + if(args.length==2) + { + String message="§cUsage: /u admin playerinfo §r"; + SendMessage(player, message); + return; + } + if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2])) + { + String message="§cPlayer not found: "+args[2]+"§r"; + SendMessage(player, message); + return; + } + MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]); + SendMessage(player, "Player name: "+p.PlayerName); + SendMessage(player, "User flair: "+p.Flair); + SendMessage(player, "Username: "+p.UserName); + SendMessage(player, "Flair accepted: "+p.AcceptedFlair); + SendMessage(player, "Flair ignored: "+p.IgnoredFlair); + } + private static void SendMessage(Player player, String message) + { //2015.08.09. + if(player==null) + System.out.println(message); + else + player.sendMessage(message); + } + private static void DoGetLastError(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "getlasterror" + if(PluginMain.LastException!=null) + { + SendMessage(player, "Last error:"); + SendMessage(player, PluginMain.LastException.toString()); + PluginMain.LastException=null; + } + else + SendMessage(player, "There were no exceptions."); + } + private static void SetPlayerFlair(Player player, Player targetplayer, String flair) + { //2015.08.09. + flair=flair.replace('&', '§'); + MaybeOfflinePlayer.AddPlayerIfNeeded(player.getName()).Flair=flair; + if(!PluginMain.RemoveLineFromFile("customflairs.txt", targetplayer.getName())) + { + SendMessage(player, "§cError removing previous custom flair!§r"); + return; + } + File file=new File("customflairs.txt"); + try { + BufferedWriter bw; + bw = new BufferedWriter(new FileWriter(file, true)); + bw.write(targetplayer.getName()+"\n"); + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + PluginMain.LastException=e; //2015.08.09. + } + SendMessage(player, "§6The flair has been set. Player: "+targetplayer.getName()+" Flair: "+flair+"§r"); + } + private static void DoSetFlair(Player player, String args) + { + //args[0] is "admin" - args[1] is "setflair" + if(args.length()<4) + { + + } + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/fb/307961d7cf3e001518fa86d7ae2a1cf8 b/.metadata/.plugins/org.eclipse.core.resources/.history/fb/307961d7cf3e001518fa86d7ae2a1cf8 new file mode 100644 index 0000000..ccaedeb --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/fb/307961d7cf3e001518fa86d7ae2a1cf8 @@ -0,0 +1,363 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStream; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLConnection; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + +import org.apache.commons.io.IOUtils; +import org.bukkit.entity.Player; +import org.bukkit.plugin.java.JavaPlugin; +import org.json.JSONArray; +import org.json.JSONObject; + +import com.palmergames.bukkit.towny.object.Town; +import com.palmergames.bukkit.towny.object.WorldCoord; + +public class PluginMain extends JavaPlugin +{ //Translated to Java: 2015.07.15. + //A user, which flair isn't obtainable: + //https://www.reddit.com/r/thebutton/comments/31c32v/i_pressed_the_button_without_really_thinking/ + private static PluginMain Instance; + // Fired when plugin is first enabled + @Override + public void onEnable() + { + System.out.println("The Button Auto-flair Plugin by NorbiPeti (:P)"); + getServer().getPluginManager().registerEvents(new PlayerListener(), this); + this.getCommand("u").setExecutor(new Commands()); + this.getCommand("u").setUsage(this.getCommand("u").getUsage().replace('&', '§')); + Instance=this; //2015.08.08. + try { + File file=new File("flairsaccepted.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + //System.out.println("Name: " + name); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("flairsignored.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsignored.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("autoflairconfig.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + TownColors.put(s[0], s[1]); + } + br.close(); + } + //throw new IOException("Test"); //2015.08.09. + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + Runnable r=new Runnable(){public void run(){ThreadMethod();}}; + Thread t=new Thread(r); + t.start(); + } + Boolean stop=false; + // Fired when plugin is disabled + @Override + public void onDisable() + { + try + { + FileWriter fw; + fw = new FileWriter("flairsaccepted.txt"); + fw.close(); + fw = new FileWriter("flairsignored.txt"); + fw.close(); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + try { + File file=new File("flairsaccepted.txt"); + BufferedWriter bw=new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.AcceptedFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + file=new File("flairsignored.txt"); + bw = new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.IgnoredFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + stop=true; + } + + public void ThreadMethod() //<-- 2015.07.16. + { + while(!stop) + { + try + { + String body=DownloadString("https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/autoflair_system_comment_your_minecraft_name_and/.json?limit=1000"); + JSONArray json=new JSONArray(body).getJSONObject(1).getJSONObject("data").getJSONArray("children"); + for(Object obj : json) + { + JSONObject item = (JSONObject)obj; + String author=item.getJSONObject("data").getString("author"); + String ign=item.getJSONObject("data").getString("body"); + int start = ign.indexOf("IGN:") + "IGN:".length(); + int end = ign.indexOf(' ', start); + if (end == -1 || end == start) + end=ign.indexOf('\n', start); //2015.07.15. + if (end == -1 || end == start) + ign = ign.substring(start); + else + ign = ign.substring(start, end); + ign = ign.trim(); + if(HasIGFlair(ign)) + continue; + try { + Thread.sleep(10); + } catch(InterruptedException ex) { + Thread.currentThread().interrupt(); + } + String[] flairdata = DownloadString("http://karmadecay.com/thebutton-data.php?users=" + author).replace("\"", "").split(":"); + String flair; + if(flairdata.length > 1) //2015.07.15. + flair = flairdata[1]; + else + flair=""; + if (flair != "-1") + flair = flair + "s"; + else + flair = "non-presser"; + String flairclass; + if(flairdata.length>2) + flairclass = flairdata[2]; + else + flairclass="unknown"; + SetFlair(ign, flair, flairclass, author); + } + Thread.sleep(10000); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + } + + public static Exception LastException; //2015.08.09. + + public String DownloadString(String urlstr) throws MalformedURLException, IOException + { + URL url = new URL(urlstr); + URLConnection con = url.openConnection(); + con.setRequestProperty("User-Agent", "TheButtonAutoFlair"); + InputStream in = con.getInputStream(); + String encoding = con.getContentEncoding(); + encoding = encoding == null ? "UTF-8" : encoding; + String body = IOUtils.toString(in, encoding); + in.close(); + return body; + } + + public static Map TownColors=new HashMap(); //2015.07.20. + public Boolean HasIGFlair(String playername) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + return p.Flair!=null; //2015.08.08. + } + + public void SetFlair(String playername, String text, String flairclass, String username) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + String finalflair; + p.FlairDecided=true; + switch(flairclass) + { + case "press-1": + finalflair="§c("+text+")§r"; + break; + case "press-2": + finalflair="§6("+text+")§r"; + break; + case "press-3": + finalflair="§e("+text+")§r"; + break; + case "press-4": + finalflair="§a("+text+")§r"; + break; + case "press-5": + finalflair="§9("+text+")§r"; + break; + 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; + case "undecided": //2015.08.09. + p.FlairDecided=false; + finalflair=""; + break; + default: + finalflair=""; + break; + } + if(finalflair.length()==0) //<-- 2015.07.20. + return; + p.Flair=finalflair; //2015.08.08. + p.UserName=username; //2015.08.08. + System.out.println("Added new flair to "+playername+": "+finalflair); + for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08. + { + if(player.getName().equals(playername)) + { + //AppendPlayerDisplayFlair(player, username, finalflair); + AppendPlayerDisplayFlair(p, player); + break; + } + } + } + + public static String GetFlair(Player player) + { //2015.07.16. + String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08. + return flair==null ? "" : flair; + } + + //public static void AppendPlayerDisplayFlair(Player player, String username, String flair) + public static void AppendPlayerDisplayFlair(MaybeOfflinePlayer player, Player p) //<-- 2015.08.09. + { + + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).IgnoredFlair) + return; + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).AcceptedFlair) + { + AppendPlayerDisplayFlairFinal(p, player.Flair); //2015.07.20. + if(!player.FlairDecided) + p.sendMessage("§9Your flair type is unknown. Are you a non-presser or a can't press? (/u nonpresser or /u cantpress)§r"); //2015.08.09. + } + else + player.sendMessage("§9Are you Reddit user "+player.UserName+"?§r §6Type /u accept or /u ignore§r"); + } + + private static void AppendPlayerDisplayFlairFinal(Player player, String flair) + { //2015.07.20. + String color = GetColorForTown(GetPlayerTown(player)); //TO!DO: Multiple colors put on first capital letters + String[] colors = color.substring(1).split("§"); + String displayname=player.getName(); //2015.08.08. + ArrayList Positions=new ArrayList<>(); + for(int i=0; i=colors.length) + { + int x=0; + for(int i=0; i GetPlayers() + { + return Instance.getServer().getOnlinePlayers(); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/fb/503cf63d883e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/fb/503cf63d883e00151ce8ff6d4f74dabd deleted file mode 100644 index aeba6ef..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/fb/503cf63d883e00151ce8ff6d4f74dabd +++ /dev/null @@ -1,167 +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; - MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. - //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - if(p.Flair==null) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. - { - case "accept": - { - if(p.IgnoredFlair) - p.IgnoredFlair=false; //2015.08.08. - if(!p.AcceptedFlair) - { - String flair=p.Flair; //2015.08.08. - PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. - p.AcceptedFlair=true; //2015.08.08. - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("§cYou already have this user's flair.§r"); - break; - } - case "ignore": - { - if(p.AcceptedFlair) - p.AcceptedFlair=false; //2015.08.08. - if(!p.IgnoredFlair) - { - p.IgnoredFlair=true; - String flair=p.Flair; //2015.08.08. - PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. - player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); - } - else - player.sendMessage("§cYou already ignored this request.§r"); - break; - } - /*case "reload": //2015.07.20. - DoReload(player); - break;*/ - case "admin": //2015.08.09. - DoAdmin(player, args); - break; - default: - return false; - } - return true; - } - - /*if(args[0].toLowerCase()=="reload") - DoReload(null); //2015.07.20.*/ - else if(args[0].toLowerCase()=="admin") - DoAdmin(null, args); //2015.08.09. - return false; - } - private static void DoReload(Player player) - { //2015.07.20. - //if(player==null || player.isOp() || player.getName()=="NorbiPeti") - //{ - try - { - File file=new File("autoflairconfig.txt"); - if(file.exists()) - { - PluginMain.TownColors.clear(); - BufferedReader br=new BufferedReader(new FileReader(file)); - String line; - while((line=br.readLine())!=null) - { - String[] s=line.split(" "); - PluginMain.TownColors.put(s[0], s[1]); - } - br.close(); - for(Player p : PluginMain.GetPlayers()) - { - MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName()); - if(mp.Flair!=null) - { - String flair=mp.Flair; - PluginMain.RemovePlayerDisplayFlairFinal(p, flair); - PluginMain.AppendPlayerDisplayFlairFinal(p, flair); - } - } - String msg="§6Reloaded config file.§r"; - if(player!=null) - player.sendMessage(msg); - else - System.out.println(msg); - } - } - catch(Exception e) - { - System.out.println("Error!\n"+e); - if(player!=null) - player.sendMessage("§cAn error occured. See console for details.§r"); - } - //} - //else - //player.sendMessage("§cYou need to be OP to use this command.§r"); - } - private static void DoAdmin(Player player, String[] args) - { //2015.08.09. - if(player==null || player.isOp() || player.getName()=="NorbiPeti") - { - if(args.length==1) - { - String message="§cUsage: /u admin reload|playerinfo§r"; - if(player==null) - System.out.println(message); - else - player.sendMessage(message); - return; - } - //args[0] is "admin" - switch(args[1].toLowerCase()) - { - case "reload": - DoReload(player); - break; - case "playerinfo": - DoPlayerInfo(player, args); - break; - } - } - else - player.sendMessage("§cYou need to be OP to use this command.§r"); - } - private static void DoPlayerInfo(Player player, String[] args) - { //2015.08.09. - //args[0] is "admin" - args[1] is "playerinfo" - if(args.length==2) - { - String message="§cUsage: /u admin playerinfo §r"; - if(player==null) - System.out.println(message); - else - player.sendMessage(message); - return; - } - if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2])) - { - - } - MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/fc/0072fbdce43e001517108d149b613203 b/.metadata/.plugins/org.eclipse.core.resources/.history/fc/0072fbdce43e001517108d149b613203 new file mode 100644 index 0000000..dfc7f58 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/fc/0072fbdce43e001517108d149b613203 @@ -0,0 +1,424 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStream; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLConnection; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + +import org.apache.commons.io.IOUtils; +import org.bukkit.entity.Player; +import org.bukkit.plugin.java.JavaPlugin; +import org.json.JSONArray; +import org.json.JSONObject; + +import com.palmergames.bukkit.towny.object.Town; +import com.palmergames.bukkit.towny.object.WorldCoord; + +public class PluginMain extends JavaPlugin +{ //Translated to Java: 2015.07.15. + //A user, which flair isn't obtainable: + //https://www.reddit.com/r/thebutton/comments/31c32v/i_pressed_the_button_without_really_thinking/ + private static PluginMain Instance; + // Fired when plugin is first enabled + @Override + public void onEnable() + { + System.out.println("The Button Auto-flair Plugin by NorbiPeti (:P)"); + getServer().getPluginManager().registerEvents(new PlayerListener(), this); + this.getCommand("u").setExecutor(new Commands()); + this.getCommand("u").setUsage(this.getCommand("u").getUsage().replace('&', '§')); + Instance=this; //2015.08.08. + LoadFiles(false); //2015.08.09. + Runnable r=new Runnable(){public void run(){ThreadMethod();}}; + Thread t=new Thread(r); + t.start(); + } + Boolean stop=false; + // Fired when plugin is disabled + @Override + public void onDisable() + { + SaveFiles(); //2015.08.09. + stop=true; + } + + public void ThreadMethod() //<-- 2015.07.16. + { + while(!stop) + { + try + { + String body=DownloadString("https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/autoflair_system_comment_your_minecraft_name_and/.json?limit=1000"); + JSONArray json=new JSONArray(body).getJSONObject(1).getJSONObject("data").getJSONArray("children"); + for(Object obj : json) + { + JSONObject item = (JSONObject)obj; + String author=item.getJSONObject("data").getString("author"); + String ign=item.getJSONObject("data").getString("body"); + int start = ign.indexOf("IGN:") + "IGN:".length(); + if(start==-1) + continue; //2015.08.09. + int end = ign.indexOf(' ', start); + if (end == -1 || end == start) + end=ign.indexOf('\n', start); //2015.07.15. + if (end == -1 || end == start) + ign = ign.substring(start); + else + ign = ign.substring(start, end); + ign = ign.trim(); + if(HasIGFlair(ign)) + continue; + try { + Thread.sleep(10); + } catch(InterruptedException ex) { + Thread.currentThread().interrupt(); + } + String[] flairdata = DownloadString("http://karmadecay.com/thebutton-data.php?users=" + author).replace("\"", "").split(":"); + String flair; + if(flairdata.length > 1) //2015.07.15. + flair = flairdata[1]; + else + flair=""; + if (flair != "-1") + flair = flair + "s"; + else + flair = "non-presser"; + String flairclass; + if(flairdata.length>2) + flairclass = flairdata[2]; + else + flairclass="unknown"; + SetFlair(ign, flair, flairclass, author); + } + Thread.sleep(10000); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + } + + public static Exception LastException; //2015.08.09. + + public String DownloadString(String urlstr) throws MalformedURLException, IOException + { + URL url = new URL(urlstr); + URLConnection con = url.openConnection(); + con.setRequestProperty("User-Agent", "TheButtonAutoFlair"); + InputStream in = con.getInputStream(); + String encoding = con.getContentEncoding(); + encoding = encoding == null ? "UTF-8" : encoding; + String body = IOUtils.toString(in, encoding); + in.close(); + return body; + } + + public static Map TownColors=new HashMap(); //2015.07.20. + public Boolean HasIGFlair(String playername) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + return p.Flair!=null; //2015.08.08. + } + + public void SetFlair(String playername, String text, String flairclass, String username) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + String finalflair; + p.FlairDecided=true; + switch(flairclass) + { + case "press-1": + finalflair="§c("+text+")§r"; + break; + case "press-2": + finalflair="§6("+text+")§r"; + break; + case "press-3": + finalflair="§e("+text+")§r"; + break; + case "press-4": + finalflair="§a("+text+")§r"; + break; + case "press-5": + finalflair="§9("+text+")§r"; + break; + 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; + case "undecided": //2015.08.09. + p.FlairDecided=false; + finalflair=""; + break; + default: + finalflair=""; + break; + } + if(finalflair.length()==0) //<-- 2015.07.20. + return; + p.Flair=finalflair; //2015.08.08. + p.UserName=username; //2015.08.08. + System.out.println("Added new flair to "+playername+": "+finalflair); + for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08. + { + if(player.getName().equals(playername)) + { + //AppendPlayerDisplayFlair(player, username, finalflair); + AppendPlayerDisplayFlair(p, player); + break; + } + } + } + + public static String GetFlair(Player player) + { //2015.07.16. + String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08. + return flair==null ? "" : flair; + } + + //public static void AppendPlayerDisplayFlair(Player player, String username, String flair) + public static void AppendPlayerDisplayFlair(MaybeOfflinePlayer player, Player p) //<-- 2015.08.09. + { + + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).IgnoredFlair) + return; + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).AcceptedFlair) + { + AppendPlayerDisplayFlairFinal(p, player.Flair); //2015.07.20. + if(!player.FlairDecided) + p.sendMessage("§9Your flair type is unknown. Are you a non-presser or a can't press? (/u nonpresser or /u cantpress)§r"); //2015.08.09. + } + else + p.sendMessage("§9Are you Reddit user "+player.UserName+"?§r §6Type /u accept or /u ignore§r"); + } + + private static void AppendPlayerDisplayFlairFinal(Player player, String flair) + { //2015.07.20. + String color = GetColorForTown(GetPlayerTown(player)); //TO!DO: Multiple colors put on first capital letters + String[] colors = color.substring(1).split("§"); + String displayname=player.getName(); //2015.08.08. + ArrayList Positions=new ArrayList<>(); + for(int i=0; i=colors.length) + { + int x=0; + for(int i=0; i GetPlayers() + { + return Instance.getServer().getOnlinePlayers(); + } + + public static void LoadFiles(boolean reload) //<-- 2015.08.09. + { + if(reload) + { //2015.08.09. + System.out.println("Auto-flair plugin cleanup for reloading..."); + MaybeOfflinePlayer.AllPlayers.clear(); + TownColors.clear(); + } + System.out.println("Loading files for auto-flair plugin..."); //2015.08.09. + try { + File file=new File("flairsaccepted.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + //System.out.println("Name: " + name); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("flairsignored.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsignored.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("autoflairconfig.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + TownColors.put(s[0], s[1]); + } + br.close(); + } + file=new File("customflairs.txt"); //2015.08.09. + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + MaybeOfflinePlayer.AddPlayerIfNeeded(s[0]).Flair=s[1]; //2015.08.09. + } + br.close(); + } + //throw new IOException("Test"); //2015.08.09. + System.out.println("Auto-flair plugin loaded files!"); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + public static void SaveFiles() //<-- 2015.08.09. + { + try + { + FileWriter fw; + fw = new FileWriter("flairsaccepted.txt"); + fw.close(); + fw = new FileWriter("flairsignored.txt"); + fw.close(); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + try { + File file=new File("flairsaccepted.txt"); + BufferedWriter bw=new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.AcceptedFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + file=new File("flairsignored.txt"); + bw = new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.IgnoredFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + public static boolean RemoveLineFromFile(String file, String line) + { //2015.08.09. + File inputFile = new File(file); + File tempFile = new File("_temp.txt"); + + if() + + try { + BufferedReader reader = new BufferedReader(new FileReader(inputFile)); + BufferedWriter writer = new BufferedWriter(new FileWriter(tempFile)); + + String lineToRemove = line; + String currentLine; + + while((currentLine = reader.readLine()) != null) { + // trim newline when comparing with lineToRemove + String trimmedLine = currentLine.trim(); + //if(trimmedLine.equals(lineToRemove)) continue; + if(trimmedLine.contains(lineToRemove)) continue; //2015.08.09. + writer.write(currentLine + System.getProperty("line.separator")); + } + writer.close(); + reader.close(); + return tempFile.renameTo(inputFile); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + return false; + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/fc/50e6e65e043e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/fc/50e6e65e043e00151c31fb33fff4337f deleted file mode 100644 index fb4f19d..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/fc/50e6e65e043e00151c31fb33fff4337f +++ /dev/null @@ -1,125 +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; - 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/fc/8023f1ece43e001517108d149b613203 b/.metadata/.plugins/org.eclipse.core.resources/.history/fc/8023f1ece43e001517108d149b613203 new file mode 100644 index 0000000..45eac34 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/fc/8023f1ece43e001517108d149b613203 @@ -0,0 +1,422 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStream; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLConnection; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + +import org.apache.commons.io.IOUtils; +import org.bukkit.entity.Player; +import org.bukkit.plugin.java.JavaPlugin; +import org.json.JSONArray; +import org.json.JSONObject; + +import com.palmergames.bukkit.towny.object.Town; +import com.palmergames.bukkit.towny.object.WorldCoord; + +public class PluginMain extends JavaPlugin +{ //Translated to Java: 2015.07.15. + //A user, which flair isn't obtainable: + //https://www.reddit.com/r/thebutton/comments/31c32v/i_pressed_the_button_without_really_thinking/ + private static PluginMain Instance; + // Fired when plugin is first enabled + @Override + public void onEnable() + { + System.out.println("The Button Auto-flair Plugin by NorbiPeti (:P)"); + getServer().getPluginManager().registerEvents(new PlayerListener(), this); + this.getCommand("u").setExecutor(new Commands()); + this.getCommand("u").setUsage(this.getCommand("u").getUsage().replace('&', '§')); + Instance=this; //2015.08.08. + LoadFiles(false); //2015.08.09. + Runnable r=new Runnable(){public void run(){ThreadMethod();}}; + Thread t=new Thread(r); + t.start(); + } + Boolean stop=false; + // Fired when plugin is disabled + @Override + public void onDisable() + { + SaveFiles(); //2015.08.09. + stop=true; + } + + public void ThreadMethod() //<-- 2015.07.16. + { + while(!stop) + { + try + { + String body=DownloadString("https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/autoflair_system_comment_your_minecraft_name_and/.json?limit=1000"); + JSONArray json=new JSONArray(body).getJSONObject(1).getJSONObject("data").getJSONArray("children"); + for(Object obj : json) + { + JSONObject item = (JSONObject)obj; + String author=item.getJSONObject("data").getString("author"); + String ign=item.getJSONObject("data").getString("body"); + int start = ign.indexOf("IGN:") + "IGN:".length(); + if(start==-1) + continue; //2015.08.09. + int end = ign.indexOf(' ', start); + if (end == -1 || end == start) + end=ign.indexOf('\n', start); //2015.07.15. + if (end == -1 || end == start) + ign = ign.substring(start); + else + ign = ign.substring(start, end); + ign = ign.trim(); + if(HasIGFlair(ign)) + continue; + try { + Thread.sleep(10); + } catch(InterruptedException ex) { + Thread.currentThread().interrupt(); + } + String[] flairdata = DownloadString("http://karmadecay.com/thebutton-data.php?users=" + author).replace("\"", "").split(":"); + String flair; + if(flairdata.length > 1) //2015.07.15. + flair = flairdata[1]; + else + flair=""; + if (flair != "-1") + flair = flair + "s"; + else + flair = "non-presser"; + String flairclass; + if(flairdata.length>2) + flairclass = flairdata[2]; + else + flairclass="unknown"; + SetFlair(ign, flair, flairclass, author); + } + Thread.sleep(10000); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + } + + public static Exception LastException; //2015.08.09. + + public String DownloadString(String urlstr) throws MalformedURLException, IOException + { + URL url = new URL(urlstr); + URLConnection con = url.openConnection(); + con.setRequestProperty("User-Agent", "TheButtonAutoFlair"); + InputStream in = con.getInputStream(); + String encoding = con.getContentEncoding(); + encoding = encoding == null ? "UTF-8" : encoding; + String body = IOUtils.toString(in, encoding); + in.close(); + return body; + } + + public static Map TownColors=new HashMap(); //2015.07.20. + public Boolean HasIGFlair(String playername) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + return p.Flair!=null; //2015.08.08. + } + + public void SetFlair(String playername, String text, String flairclass, String username) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + String finalflair; + p.FlairDecided=true; + switch(flairclass) + { + case "press-1": + finalflair="§c("+text+")§r"; + break; + case "press-2": + finalflair="§6("+text+")§r"; + break; + case "press-3": + finalflair="§e("+text+")§r"; + break; + case "press-4": + finalflair="§a("+text+")§r"; + break; + case "press-5": + finalflair="§9("+text+")§r"; + break; + 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; + case "undecided": //2015.08.09. + p.FlairDecided=false; + finalflair=""; + break; + default: + finalflair=""; + break; + } + if(finalflair.length()==0) //<-- 2015.07.20. + return; + p.Flair=finalflair; //2015.08.08. + p.UserName=username; //2015.08.08. + System.out.println("Added new flair to "+playername+": "+finalflair); + for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08. + { + if(player.getName().equals(playername)) + { + //AppendPlayerDisplayFlair(player, username, finalflair); + AppendPlayerDisplayFlair(p, player); + break; + } + } + } + + public static String GetFlair(Player player) + { //2015.07.16. + String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08. + return flair==null ? "" : flair; + } + + //public static void AppendPlayerDisplayFlair(Player player, String username, String flair) + public static void AppendPlayerDisplayFlair(MaybeOfflinePlayer player, Player p) //<-- 2015.08.09. + { + + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).IgnoredFlair) + return; + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).AcceptedFlair) + { + AppendPlayerDisplayFlairFinal(p, player.Flair); //2015.07.20. + if(!player.FlairDecided) + p.sendMessage("§9Your flair type is unknown. Are you a non-presser or a can't press? (/u nonpresser or /u cantpress)§r"); //2015.08.09. + } + else + p.sendMessage("§9Are you Reddit user "+player.UserName+"?§r §6Type /u accept or /u ignore§r"); + } + + private static void AppendPlayerDisplayFlairFinal(Player player, String flair) + { //2015.07.20. + String color = GetColorForTown(GetPlayerTown(player)); //TO!DO: Multiple colors put on first capital letters + String[] colors = color.substring(1).split("§"); + String displayname=player.getName(); //2015.08.08. + ArrayList Positions=new ArrayList<>(); + for(int i=0; i=colors.length) + { + int x=0; + for(int i=0; i GetPlayers() + { + return Instance.getServer().getOnlinePlayers(); + } + + public static void LoadFiles(boolean reload) //<-- 2015.08.09. + { + if(reload) + { //2015.08.09. + System.out.println("Auto-flair plugin cleanup for reloading..."); + MaybeOfflinePlayer.AllPlayers.clear(); + TownColors.clear(); + } + System.out.println("Loading files for auto-flair plugin..."); //2015.08.09. + try { + File file=new File("flairsaccepted.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + //System.out.println("Name: " + name); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("flairsignored.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsignored.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("autoflairconfig.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + TownColors.put(s[0], s[1]); + } + br.close(); + } + file=new File("customflairs.txt"); //2015.08.09. + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + MaybeOfflinePlayer.AddPlayerIfNeeded(s[0]).Flair=s[1]; //2015.08.09. + } + br.close(); + } + //throw new IOException("Test"); //2015.08.09. + System.out.println("Auto-flair plugin loaded files!"); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + public static void SaveFiles() //<-- 2015.08.09. + { + try + { + FileWriter fw; + fw = new FileWriter("flairsaccepted.txt"); + fw.close(); + fw = new FileWriter("flairsignored.txt"); + fw.close(); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + try { + File file=new File("flairsaccepted.txt"); + BufferedWriter bw=new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.AcceptedFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + file=new File("flairsignored.txt"); + bw = new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.IgnoredFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + public static boolean RemoveLineFromFile(String file, String line) + { //2015.08.09. + File inputFile = new File(file); + File tempFile = new File("_temp.txt"); + + try { + BufferedReader reader = new BufferedReader(new FileReader(inputFile)); + BufferedWriter writer = new BufferedWriter(new FileWriter(tempFile)); + + String lineToRemove = line; + String currentLine; + + while((currentLine = reader.readLine()) != null) { + // trim newline when comparing with lineToRemove + String trimmedLine = currentLine.trim(); + //if(trimmedLine.equals(lineToRemove)) continue; + if(trimmedLine.contains(lineToRemove)) continue; //2015.08.09. + writer.write(currentLine + System.getProperty("line.separator")); + } + writer.close(); + reader.close(); + return tempFile.renameTo(inputFile); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + return false; + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/fd/80351029e13e001517108d149b613203 b/.metadata/.plugins/org.eclipse.core.resources/.history/fd/80351029e13e001517108d149b613203 new file mode 100644 index 0000000..68a6552 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/fd/80351029e13e001517108d149b613203 @@ -0,0 +1,265 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +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; + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. + //if(!PluginMain.PlayerFlairs.containsKey(player.getName())) + if(p.Flair==null) + { + player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); + return true; + } + switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. + { + case "accept": + { + if(p.IgnoredFlair) + p.IgnoredFlair=false; //2015.08.08. + if(!p.AcceptedFlair) + { + String flair=p.Flair; //2015.08.08. + //PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + PluginMain.AppendPlayerDisplayFlair(p, player); + p.AcceptedFlair=true; //2015.08.08. + player.sendMessage("§6Your flair has been set:§r "+flair); + } + else + player.sendMessage("§cYou already have this user's flair.§r"); + break; + } + case "ignore": + { + if(p.AcceptedFlair) + p.AcceptedFlair=false; //2015.08.08. + if(!p.IgnoredFlair) + { + p.IgnoredFlair=true; + String flair=p.Flair; //2015.08.08. + PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. + player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); + } + else + player.sendMessage("§cYou already ignored this request.§r"); + break; + } + /*case "reload": //2015.07.20. + DoReload(player); + break;*/ + case "admin": //2015.08.09. + DoAdmin(player, args); + break; + case "nonpresser": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§7(non-pr.)§r"; + break; + case "cantpress": //2015.08.09. + if(!p.AcceptedFlair) + { + player.sendMessage("§cYou need to accept the flair first.§r"); + break; + } + if(p.FlairDecided) + { + player.sendMessage("§cYou have already set the flair type.§r"); + break; + } + p.Flair="§r(can't press)§r"; + break; + default: + return false; + } + return true; + } + /*if(args[0].toLowerCase()=="reload") + DoReload(null); //2015.07.20.*/ + else if(args.length>0 && args[0].toLowerCase().equals("admin")) //2015.08.09. + { + DoAdmin(null, args); //2015.08.09. + return true; //2015.08.09. + } + return false; + } + private static void DoReload(Player player) + { //2015.07.20. + //if(player==null || player.isOp() || player.getName()=="NorbiPeti") + //{ + try + { + File file=new File("autoflairconfig.txt"); + if(file.exists()) + { + PluginMain.LoadFiles(true); //2015.08.09. + for(Player p : PluginMain.GetPlayers()) + { + MaybeOfflinePlayer mp = MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName()); + if(mp.Flair!=null) + { + String flair=mp.Flair; + PluginMain.RemovePlayerDisplayFlairFinal(p, flair); + //PluginMain.AppendPlayerDisplayFlairFinal(p, flair); + PluginMain.AppendPlayerDisplayFlair(mp, p); //2015.08.09. + } + String msg="§6Note: The auto-flair plugin has been reloaded. You might need to wait 10s to have your flair.§r"; //2015.08.09. + p.sendMessage(msg); //2015.08.09. + } + //String msg="§6Reloaded config file.§r"; + //SendMessage(player, msg); //2015.08.09. + } + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + if(player!=null) + player.sendMessage("§cAn error occured. See console for details.§r"); + PluginMain.LastException=e; //2015.08.09. + } + //} + //else + //player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static Player ReloadPlayer; //2015.08.09. + private static void DoAdmin(Player player, String[] args) + { //2015.08.09. + if(player==null || player.isOp() || player.getName()=="NorbiPeti") + { + //System.out.println("Args length: " + args.length); + if(args.length==1) + { + String message="§cUsage: /u admin reload|playerinfo§r"; + SendMessage(player, message); + return; + } + //args[0] is "admin" + switch(args[1].toLowerCase()) + { + case "reload": + ReloadPlayer=player; //2015.08.09. + SendMessage(player, "§6Make sure to save the current settings before you modify and reload them! Type /u admin confirm when done.§r"); + break; + case "playerinfo": + DoPlayerInfo(player, args); + break; + case "getlasterror": + DoGetLastError(player, args); + case "confirm": + if(ReloadPlayer==player) + DoReload(player); //2015.08.09. + else + SendMessage(player, "§cYou need to do /u admin reload first.§r"); + break; + case "save": //2015.08.09. + PluginMain.SaveFiles(); //2015.08.09. + SendMessage(player, "§6Saved files. Now you can edit them and reload if you want.§r"); + break; + case "setflair": //2015.08.09. + DoSetFlair(player, args); + break; + default: + String message="§cUsage: /u admin reload|playerinfo|getlasterror|save§r"; + SendMessage(player, message); + return; + } + } + else + player.sendMessage("§cYou need to be OP to use this command.§r"); + } + private static void DoPlayerInfo(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "playerinfo" + if(args.length==2) + { + String message="§cUsage: /u admin playerinfo §r"; + SendMessage(player, message); + return; + } + if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2])) + { + String message="§cPlayer not found: "+args[2]+"§r"; + SendMessage(player, message); + return; + } + MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]); + SendMessage(player, "Player name: "+p.PlayerName); + SendMessage(player, "User flair: "+p.Flair); + SendMessage(player, "Username: "+p.UserName); + SendMessage(player, "Flair accepted: "+p.AcceptedFlair); + SendMessage(player, "Flair ignored: "+p.IgnoredFlair); + } + private static void SendMessage(Player player, String message) + { //2015.08.09. + if(player==null) + System.out.println(message); + else + player.sendMessage(message); + } + private static void DoGetLastError(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "getlasterror" + if(PluginMain.LastException!=null) + { + SendMessage(player, "Last error:"); + SendMessage(player, PluginMain.LastException.toString()); + PluginMain.LastException=null; + } + else + SendMessage(player, "There were no exceptions."); + } + private static void SetPlayerFlair(Player player, MaybeOfflinePlayer targetplayer, String flair) + { //2015.08.09. + flair=flair.replace('&', '§'); + targetplayer.Flair=flair; + if(!PluginMain.RemoveLineFromFile("customflairs.txt", targetplayer.PlayerName)) + { + SendMessage(player, "§cError removing previous custom flair!§r"); + return; + } + File file=new File("customflairs.txt"); + try { + BufferedWriter bw; + bw = new BufferedWriter(new FileWriter(file, true)); + bw.write(targetplayer.PlayerName+"\n"); + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + PluginMain.LastException=e; //2015.08.09. + } + SendMessage(player, "§6The flair has been set. Player: "+targetplayer.PlayerName+" Flair: "+flair+"§r"); + } + private static void DoSetFlair(Player player, String[] args) + { + //args[0] is "admin" - args[1] is "setflair" + if(args.length<4) + { + SendMessage(player, "§cUsage: /u admin setflair "); + return; + } + SetPlayerFlair(player, MaybeOfflinePlayer.AddPlayerIfNeeded(args[2]), args[3]); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/fe/204112ead13e001518fa86d7ae2a1cf8 b/.metadata/.plugins/org.eclipse.core.resources/.history/fe/204112ead13e001518fa86d7ae2a1cf8 new file mode 100644 index 0000000..318be3d --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/fe/204112ead13e001518fa86d7ae2a1cf8 @@ -0,0 +1,374 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStream; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLConnection; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + +import org.apache.commons.io.IOUtils; +import org.bukkit.entity.Player; +import org.bukkit.plugin.java.JavaPlugin; +import org.json.JSONArray; +import org.json.JSONObject; + +import com.palmergames.bukkit.towny.object.Town; +import com.palmergames.bukkit.towny.object.WorldCoord; + +public class PluginMain extends JavaPlugin +{ //Translated to Java: 2015.07.15. + //A user, which flair isn't obtainable: + //https://www.reddit.com/r/thebutton/comments/31c32v/i_pressed_the_button_without_really_thinking/ + private static PluginMain Instance; + // Fired when plugin is first enabled + @Override + public void onEnable() + { + System.out.println("The Button Auto-flair Plugin by NorbiPeti (:P)"); + getServer().getPluginManager().registerEvents(new PlayerListener(), this); + this.getCommand("u").setExecutor(new Commands()); + this.getCommand("u").setUsage(this.getCommand("u").getUsage().replace('&', '§')); + Instance=this; //2015.08.08. + LoadFiles(false); //2015.08.09. + Runnable r=new Runnable(){public void run(){ThreadMethod();}}; + Thread t=new Thread(r); + t.start(); + } + Boolean stop=false; + // Fired when plugin is disabled + @Override + public void onDisable() + { + try + { + FileWriter fw; + fw = new FileWriter("flairsaccepted.txt"); + fw.close(); + fw = new FileWriter("flairsignored.txt"); + fw.close(); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + try { + File file=new File("flairsaccepted.txt"); + BufferedWriter bw=new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.AcceptedFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + file=new File("flairsignored.txt"); + bw = new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.IgnoredFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + stop=true; + } + + public void ThreadMethod() //<-- 2015.07.16. + { + while(!stop) + { + try + { + String body=DownloadString("https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/autoflair_system_comment_your_minecraft_name_and/.json?limit=1000"); + JSONArray json=new JSONArray(body).getJSONObject(1).getJSONObject("data").getJSONArray("children"); + for(Object obj : json) + { + JSONObject item = (JSONObject)obj; + String author=item.getJSONObject("data").getString("author"); + String ign=item.getJSONObject("data").getString("body"); + int start = ign.indexOf("IGN:") + "IGN:".length(); + int end = ign.indexOf(' ', start); + if (end == -1 || end == start) + end=ign.indexOf('\n', start); //2015.07.15. + if (end == -1 || end == start) + ign = ign.substring(start); + else + ign = ign.substring(start, end); + ign = ign.trim(); + if(HasIGFlair(ign)) + continue; + try { + Thread.sleep(10); + } catch(InterruptedException ex) { + Thread.currentThread().interrupt(); + } + String[] flairdata = DownloadString("http://karmadecay.com/thebutton-data.php?users=" + author).replace("\"", "").split(":"); + String flair; + if(flairdata.length > 1) //2015.07.15. + flair = flairdata[1]; + else + flair=""; + if (flair != "-1") + flair = flair + "s"; + else + flair = "non-presser"; + String flairclass; + if(flairdata.length>2) + flairclass = flairdata[2]; + else + flairclass="unknown"; + SetFlair(ign, flair, flairclass, author); + } + Thread.sleep(10000); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + } + + public static Exception LastException; //2015.08.09. + + public String DownloadString(String urlstr) throws MalformedURLException, IOException + { + URL url = new URL(urlstr); + URLConnection con = url.openConnection(); + con.setRequestProperty("User-Agent", "TheButtonAutoFlair"); + InputStream in = con.getInputStream(); + String encoding = con.getContentEncoding(); + encoding = encoding == null ? "UTF-8" : encoding; + String body = IOUtils.toString(in, encoding); + in.close(); + return body; + } + + public static Map TownColors=new HashMap(); //2015.07.20. + public Boolean HasIGFlair(String playername) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + return p.Flair!=null; //2015.08.08. + } + + public void SetFlair(String playername, String text, String flairclass, String username) + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. + String finalflair; + p.FlairDecided=true; + switch(flairclass) + { + case "press-1": + finalflair="§c("+text+")§r"; + break; + case "press-2": + finalflair="§6("+text+")§r"; + break; + case "press-3": + finalflair="§e("+text+")§r"; + break; + case "press-4": + finalflair="§a("+text+")§r"; + break; + case "press-5": + finalflair="§9("+text+")§r"; + break; + 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; + case "undecided": //2015.08.09. + p.FlairDecided=false; + finalflair=""; + break; + default: + finalflair=""; + break; + } + if(finalflair.length()==0) //<-- 2015.07.20. + return; + p.Flair=finalflair; //2015.08.08. + p.UserName=username; //2015.08.08. + System.out.println("Added new flair to "+playername+": "+finalflair); + for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08. + { + if(player.getName().equals(playername)) + { + //AppendPlayerDisplayFlair(player, username, finalflair); + AppendPlayerDisplayFlair(p, player); + break; + } + } + } + + public static String GetFlair(Player player) + { //2015.07.16. + String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08. + return flair==null ? "" : flair; + } + + //public static void AppendPlayerDisplayFlair(Player player, String username, String flair) + public static void AppendPlayerDisplayFlair(MaybeOfflinePlayer player, Player p) //<-- 2015.08.09. + { + + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).IgnoredFlair) + return; + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).AcceptedFlair) + { + AppendPlayerDisplayFlairFinal(p, player.Flair); //2015.07.20. + if(!player.FlairDecided) + p.sendMessage("§9Your flair type is unknown. Are you a non-presser or a can't press? (/u nonpresser or /u cantpress)§r"); //2015.08.09. + } + else + p.sendMessage("§9Are you Reddit user "+player.UserName+"?§r §6Type /u accept or /u ignore§r"); + } + + private static void AppendPlayerDisplayFlairFinal(Player player, String flair) + { //2015.07.20. + String color = GetColorForTown(GetPlayerTown(player)); //TO!DO: Multiple colors put on first capital letters + String[] colors = color.substring(1).split("§"); + String displayname=player.getName(); //2015.08.08. + ArrayList Positions=new ArrayList<>(); + for(int i=0; i=colors.length) + { + int x=0; + for(int i=0; i GetPlayers() + { + return Instance.getServer().getOnlinePlayers(); + } + + public static void LoadFiles(boolean reload) //<-- 2015.08.09. + { + if(reload) + { + System.out.println("Reloading files for auto-flair plugin..."); + MaybeOfflinePlayer.AllPlayers.clear(); //2015.08.09. + } + System.out.println("Loading files for auto-flair plugin..."); //2015.08.09. + try { + File file=new File("flairsaccepted.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + //System.out.println("Name: " + name); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("flairsignored.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsignored.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("autoflairconfig.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + TownColors.put(s[0], s[1]); + } + br.close(); + } + //throw new IOException("Test"); //2015.08.09. + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/a0/d0bbb843893e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/ff/a0790ee2cf3e001518fa86d7ae2a1cf8 similarity index 85% rename from .metadata/.plugins/org.eclipse.core.resources/.history/a0/d0bbb843893e00151ce8ff6d4f74dabd rename to .metadata/.plugins/org.eclipse.core.resources/.history/ff/a0790ee2cf3e001518fa86d7ae2a1cf8 index cbeaea2..38374ce 100644 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/a0/d0bbb843893e00151ce8ff6d4f74dabd +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/ff/a0790ee2cf3e001518fa86d7ae2a1cf8 @@ -62,16 +62,20 @@ public class Commands implements CommandExecutor { case "admin": //2015.08.09. DoAdmin(player, args); break; + case "nonpresser": //2015.08.09. + break; default: return false; } return true; } - /*if(args[0].toLowerCase()=="reload") DoReload(null); //2015.07.20.*/ - else if(args[0].toLowerCase()=="admin") + else if(args.length>0 && args[0].toLowerCase().equals("admin")) //2015.08.09. + { DoAdmin(null, args); //2015.08.09. + return true; //2015.08.09. + } return false; } private static void DoReload(Player player) @@ -111,6 +115,7 @@ public class Commands implements CommandExecutor { System.out.println("Error!\n"+e); if(player!=null) player.sendMessage("§cAn error occured. See console for details.§r"); + PluginMain.LastException=e; //2015.08.09. } //} //else @@ -120,6 +125,7 @@ public class Commands implements CommandExecutor { { //2015.08.09. if(player==null || player.isOp() || player.getName()=="NorbiPeti") { + //System.out.println("Args length: " + args.length); if(args.length==1) { String message="§cUsage: /u admin reload|playerinfo§r"; @@ -135,6 +141,12 @@ public class Commands implements CommandExecutor { case "playerinfo": DoPlayerInfo(player, args); break; + case "getlasterror": + DoGetLastError(player, args); + default: + String message="§cUsage: /u admin reload|playerinfo§r"; + SendMessage(player, message); + return; } } else @@ -147,19 +159,20 @@ public class Commands implements CommandExecutor { { String message="§cUsage: /u admin playerinfo §r"; SendMessage(player, message); + return; } if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2])) { String message="§cPlayer not found: "+args[2]+"§r"; SendMessage(player, message); + return; } MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]); - SendMessage(player, "User flair: "+p.Flair); SendMessage(player, "Player name: "+p.PlayerName); + SendMessage(player, "User flair: "+p.Flair); SendMessage(player, "Username: "+p.UserName); SendMessage(player, "Flair accepted: "+p.AcceptedFlair); SendMessage(player, "Flair ignored: "+p.IgnoredFlair); - return; } private static void SendMessage(Player player, String message) { //2015.08.09. @@ -167,6 +180,17 @@ public class Commands implements CommandExecutor { System.out.println(message); else player.sendMessage(message); - return; + } + private static void DoGetLastError(Player player, String[] args) + { //2015.08.09. + //args[0] is "admin" - args[1] is "getlasterror" + if(PluginMain.LastException!=null) + { + SendMessage(player, "Last error:"); + SendMessage(player, PluginMain.LastException.toString()); + PluginMain.LastException=null; + } + else + SendMessage(player, "There were no exceptions."); } } diff --git a/.metadata/.plugins/org.eclipse.core.resources/.projects/RemoteSystemsTempFiles/.markers.snap b/.metadata/.plugins/org.eclipse.core.resources/.projects/RemoteSystemsTempFiles/.markers.snap index 837b60476c7c17fd611b720e8c7c1a9abf99fc06..ed1969ba2a9b0763e80af86cd347a5fec3eb2aa7 100644 GIT binary patch delta 9 Qcmeysc!6ochlv6S02crRMF0Q* delta 6 Ncmcb>^nr202LKAg14IA- 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 837b60476c7c17fd611b720e8c7c1a9abf99fc06..ed1969ba2a9b0763e80af86cd347a5fec3eb2aa7 100644 GIT binary patch delta 9 Qcmeysc!6ochlv6S02crRMF0Q* delta 6 Ncmcb>^nr202LKAg14IA- 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 283cb9c9fa16a7c5bf0082abdd90b627129e0e19..69932137766e895a2400876262aa9576a1e6acc3 100644 GIT binary patch delta 1135 zcmY+@QAkr!7zgleZ43-XZK$&pmo-{pF!m6uXx2;A!`ul9eJ~wFf~2hIM!m=#B$!ba z3}YzDYzg%uvq9{^Vh=qyZ0)QJ=CE}MB^N8S@S*ll>wbsz@AdcpzH`s{&bhP43yxUP z(BR^0#bCsvscl^UJ>Zk_FXr#=H2bs~P5g@?tk-D{g$Av*P^rcwyO^bPG76Q}Js;Id zHZ<6VE^ii8PaZq!MrUi}+}C{=y)#A578+dWw}*w7O^&EX{N?70-#2^=?kqX$y&xAccp4YMWPTN$_mcC^wq^8iqo|)xr_nbGZ)iei zF1*h`>{rx{y9=cc4ouDT@4$X=GIUo#BD=*A3{ zt!y>ciy32yPL`oeI+)OCxY-V{T`S<<$ygtu!p2KsV`(z}O$y&&K+!Eqv zyJ_aRB`k?kyJ_Y|ge}x)=EtcPYUa<0QANeOO;9C;MFh^76B88|!NsVOBI5f+s}`wb zeRN@?{8EO>I@&#JiVf71omtt`*D_EplZjCie9==nytZg|?$mx8_vZYWlN&?LJlpkB z%Ow|Y9q=>%*A=Nn*)btD+o#!9wQJ5R&ktT}+MIX)=+X4XW5oa&xjH8=8NL0gXHs4W zDUC%>YI-6$XZGg+bX~XGlyA8`s0H*Fy56GvH#7R6D;4CrNLMHHy1?Dk6MUp8m3terGZ+a1N|vd2Hry4||C1^qua$OYSs4D=dP=2goz=;z;VmwLp_=?l;= zx7|w5+wJ4Mk1)^dLEn4fXyM`sTf~=bTPT{h z0)5xgdmiA8A50_{s!rcQ7ktS1CnF2dGwjLr?SDCjp8C{S>fs$)96%pc1?bM#h9n2oCZeBjNQ(sMJFYVOaT$gh6c>h+?V~C6Iy5VaWSo1;Jsrk*tO}K-P z{D)le(bK?Vs>t(>>}$43 zWEFa02Xfxa_yPLEWAEt;6uO}p{pcog?sWJSbWzY<=P}^Z^a;sNZV! zQS{o!|6p`PeV4w3WSxdG_<@5qIm=zi#f){v|JDtASH)q?el+pN)_ozhFs zrJmq)u0Q;@U;iU>-;|T+nJMJS$x{l@^OGuQ{YTf>^@ASk@#d0qjwc?s{ntO8JpLX? z&Oht)5Ph}KM#}58@)Go^F?7OEmdv%o6Gqtm2hxry`j@?F**q>g!9*SA! zL(ZMta14D~++``xS>H`DhCJ7kTnId}9NoSP^TB^CMSs=!JFQRC?L>6p@+HZIR%^$i z-#tLC3|5Xp=XR3I`hIR(963KWRuvb{zBB0@*VS@!^8>IAaaPm>X+sp!!i>@TJB}ou z=^eij@{!kuORhZs{Sfp+XUMsbWq#l7>#tVI1wURdC_21Z{x2Yr-Y~pRuBkP9I zxDI>YZGibieMQcdx|E~y-b1Cl`2IjXdiK>JG;Z4=S?K?LI+*g)w|;Hly_g5|P@$XI zkn>juhN71}7)1T43ODrZ953=s`Lk1D{?2L4?_`IfYvaj zx*~J{&BxW@aSE)%wsLn`pCY~(y>|w=5K?v#z26F!4}Ysef9A*h;jt6wHNNCx=1>D~ zQjqJ8I^|)0+4cT3&-~J#(H9>l=c3(rqd)Uyp6`~1zPiCp>Ji6vTZg{?KDoN?RWf?* z?0&QkH?#cFa~+uvem4ZYN>4vMh4mKR=*c^oTMlqW&$c4xZzo!z+q~#Q`3=+hMB%Jyjne%PG#M92(0qTWgB=ew=a zU{6dPxsW-)z|*UlukI3$`NHMo+#xp=y3U#9_l8bFe``(7-@6`!exU+1G(H~Z`e1(@2`ko@@ z14s8jH`&BoIj;-)l9l9q(9O>1BSOgan;P1q%Z*r%c7_T1$Q)~F{(7Iw@7BO`#r@Km zo~!quo9K~SnXeOz&^<v!~r_Dcwu5<4sjmrncZbc8SdLQKd0hc|=Zbxj zbKxJ;(OdmVuH3oWz)j0oevg-dJKtj-QJsc8>9@&se})?P}&^Et%_LD8uu86k8_#M;GMH6zt zw`mf(%ZqDLUf8rQ2z|JY`8VqV&`*Q~NO@h~zMD6}xTmVeNzV1{yA)ktMlQ5YT8y4w zz`Ub%0{X!W=9AR1=(6?92j$K~pSzHptF4=h?xAA&(~lz1oz@Pdd3uG_;ZKh_Ds~ss zGqo3f0v?TJcQKj84(L}?=#!!Dn%n|CX&L+U$TN-6$ElgWxFAOt!pX%KMl$q)(^R~K@cUB#Guov^gzkWc^@5y@XRPWHm|1fWw@)o^)XXZD1zCqt_ zL9X6!@*2ISu}1m?3*!>?=&5hXc_Y)8=&!2CMf;KepkEPLeo^^z^Z~cX^*gRsp&!3M z&e@H4ivD*2>$$A0L=QShF1|DR3*BZXxq4ODL-g01S^lMW1^Vt4%*UIRqnk&P^UnUI z=m9fXe`V2K^s^Jm^|vzapeK2=o-DBhJ=c}>%o`-2@9R#ktjxQC{+AWG;*PEe{Y`6f zZ3oM1=s~aO4pDnq^EuzlT`uvY(lIx-3qc;7>q-~N>Ow}}VQgE{7*v$vwReBD}_PyfoEDd?5A zO(j>{SvCWG#G+P`>j&5OLXVz8uAXY|fNtb(MER6OGt6Oq2Ktbzt=dgTpI}0szGv*0 T=xgfeufdA6s~q~0!{q-1I-?0q diff --git a/.metadata/.plugins/org.eclipse.core.resources/.projects/TheButtonAutoFlair/.markers b/.metadata/.plugins/org.eclipse.core.resources/.projects/TheButtonAutoFlair/.markers index b420625a526cb85bb423cd20a17adb83a3ef6d9c..779705753ce0737c0ea1abb79a35f99b7e2ae8b2 100644 GIT binary patch delta 259 zcmZ1~{)m5qG84b{MAiRnLTAcfF*r@0&uTh3o>82YL5_(*Z}JBwvB^i6G?)Z*Cck6a z%Xnt<8fF$oCjQ9Dn^^n=RNEQYlQR;FT=Pc9+>{Xbv^S zKR~L3N9oC{2p+|gX9dsVK@Wo1gCg}L=xkzsYzTRWo#pL!-ut}o+b@ad$(=Ncet3NH zZ`8Q;;vp=G-N=Htqa;zhBbasxW&Vhl+HnQMd+ox}6o7Ig@vE{6-H2~1@>Ikl4Wrz$ z)Ez^)tAQ|fy)P7=Qbvh=@mhJKK82L{iIU<8`i|lcL`Pkn&Fq10)(Km3st6#nFFvWh zk`gzyBU;c#Jd0dA5$QEE&IQd>h`|A$wkWfBTV4SqcC=I{`gXKV^c}zz^0r6+=dk5t$K{xKo^6?=VpDw2WnI-^7CfjE^v}YK zZ8>yxqgkj>7MPKT8Iy2Yb6L9_7z)K;53_oCTfWOU_%-klz4{&5Q{*m#Fy^P(`Y~kd z=a8-FY^m$OU4U;eG~o1F+u>vrQ^q8|E9Z0@)baDUN^Q#J$aU(=XE!+*U^0Ie;Ba^V zV_^!dzC22+uY_ogVkw(m+Vq%Ql;t{o@*gAQXGY2Maz#F69M5IvBrP`Grq|^ksnNH; yM}H9t6~5k0;yg;ccHENCvP|qGwi{=RlaLgr3Gpj!tk?;$TL>YK@$OxFva>U* znOUc%4JB0|r7Z|iDIih_p@PJ(qJp4^v?VH};ZZ?TnifG31&I~~D2PHKR0PhQncaDK zcXmB{*E`A1N>RMeIp@r|-}jw+&z;%+_=Cq=pG3{?T7ByEM<0GViVzB+zOJ!J+?P>R zN$kz2(hh;+$1uzNwlztgI_?`!BOSGIIj|$ z>X6Oh(}rJl&shALH@16VH(HpMdC3gp46E%%rr?K3u-&b>`FC#C-24Zx*6g;23`IkT zb%rbsSvH}i(=LdApNzR=TH-}@n3I!OhP<&QMx+z9=l=yQ+mwuw#$tSrB=9jU&qAmx z|Hm^tJJfq;@1en6gTsR(V~1|<9U0g)cxdN97!7aDKQeArlPnn-?97pIw_{}NH=kS2 zYvef;wVI>*u33&nk_Pd*I!7L&2P_$|nS_WL&&8<6JPfm+q;C(?z2TMv%sOUl5cTN$P2(U9Mn3xDYB_+nX4(y6)*SN+F>4)0eyt?HTl)hyYu29kYRx{oH8cQEy_x~9 zv3d4@_mCz1O98x%?+pMCM(6@#l)e=J9syI&fY*%TuNk5I7r_$bl&(b>Vr9h25G&hl z3~_Fw8$+0c+1i`dbc{w51H6)kKQyvvofQdmGK9p(Gsz^cvLK#8d;=>J>e1Le-y59_ zQTD9Bi4*LoD)ZvR%vUsY1m&+-M(V?as8X8VU%+Hl7P)LkgqSldpGf%oQs>E=)qQ&V8Q_Ppk<*;?zNjH9Md(bOCvW|fNrzE!S zyx?X{=S8p9eAI4Dz}7X+)`0aPw8PW92*K1{yrN^))LrhQme0AacMQy50hoJ7-qE)$y~Ji^+Yc$rw&$&p5BD}C&m>A@-&>In^f~}v?kU3TWm>{-cY8r-9hGbXQ4~8Dim8F;&2HnR6CAC zGIlTtSxUJH&?#QwVS>(yPpb-@%n=RyQNy!dB<0c(YoM1VgFvGr1p__zlZugd&T?E8 zS?y>$Y(3p=yzO+)&1%OwXLz;Mj^=rnWj&80%gZV!(ryC2P4z0^*J%RYG;&30<;3^g ztm%B(t2O)W*3c*?g4K?zc(p^Lb9&{3P9#A&kzExIT?xtwv*;w)L&}L_Y*_gvx5x*| zqKconfpgmnUctFr1LuZ&A2;}HD_sh2QLPl-a;ypz9?nnUIhQH$(UR?zpNFX2>id#c zivq@s)pt;4xxSK3Gv^<2)6~Z5`};TfcP+|D{B1gq6zK?QIpH=8TkiKd48z%BSPZ8$ z@}%0M6uGBXhJ5picNi!8SUFH!*&N6j8Q@ZYO9(|iUQ+GWR#ABXIavinhV2vLVGH-_mcK)Xn8zgk=bPZBir(r|65v92x%tI*SL)e)IrNP!E7OUL{94p zcy=A>C~os_%I06Q>E8}sz=eHVo5wfv8}5G1&kw5LS4o^jGk3mAId}XT+naj7V&u#d zo^rmuDR=1BVdv>)kAL+}^tUl1eSYL$y<-~rW0K=V_li_j@8qlr^iH66X!b%x zUZjgUzSld?pfh-G6VTG%2{zu1@Ig*cPu)JX<5oW=MAj}->rg<~0&mqZ4OQ@kvRWWORa1ntzL zgX_B4%`EK70_n?e@K2POp}m6&bUiC7C&0$9Z2$97Nlq$hE{35Qg;TZ9D$s@|4$?C65?y-ouPEMf!?1=sH0#k<=myXC+`cWb%Yd@q zTvOZ*ewD=SG;`T2mLXTNCJ=K<|Lwd4n$OM!#&Go{xUrHa$NlEz~gT9Q!)- z7HSxVbB{}np;`&=KH;>Ea*bjCLh(M~5yQxN1d5B#u~rm{bJhefwTTW zH+%eBsw7_gzL7Tn^e<WX-X6OX}D76{ejRXm~yU ztjvV)h7o6|#>r!r-JpK&>@)p?E6RHC4;pgK>o22IwrrV`Zr23`&)eK9fTs1eq5zUZ zYqV@ZO&k2H08Aq{`al8XtO*oApa7^UfGu=U$M;pMa9fiBKDS;|oMrm8)r()z3sx?E zPos^CrztD9@-*GS;+jqukl9PMI&dj!P-<_s==?-Y$YXs>}jRur`!V8xo zzt**;U&p=p75#}#BPD`J#O#|^N1vK(<)SynTRe2R>uD)%bw7{<_aMts5v&X-jb>eI`Z7%qivrHpj@BwG# ztO+^IBpR-k~^>8<3a&u>6 zdzbA_%H5>0biI=@`DXSWZF%mZj5g;l98HIez4)_hzldzJIuz-jLx=7u=uj0@1+?kW tyz91qRmEq%{c~er!|g4--*vmPm9S}~cH_t@SHd}K0##Als=|p&{|6?-GI;<1 literal 14962 zcmeHNU2GIp6u#XhQoytbMFdTAq1~h{bZSvkXhhr6CGFZDu*DzHG`BOiyO+++Z0^jq zR1%Dd5&uwv3M9rSeK7i9e1QjlVld&sAc+q?h(AFSMTt=o1RgZTGqbbZne8&WJKfE0 z?Kat@yR$pqYkLp$3>BeW;3>#EWn*VUae zVZ2S_Vw*nMrah&^+Vlt=H!l;oJYinmC6gJ-2biW)g>qp(nIdqnDtN))ieG$4PML0je{oDf1mfl~X~B zYcZ-wyHuHpGw^k=qAl~+<4g#3KhixG90(2uhepTxx`%oPf@A%?eza$MX1nj#Ck4Z9 zVXoZ=GuXY)`59Vj*b!7DfaUk2dONIy4@?WFLdIn(fyb81;E$nrbewX-k~L^)lxi9Y zQ$OlAT!qJHebwoF6y9h2v=eV>e-gK1RY_b8fmfSS{|2Y1qBo;;H^IRqKU!nIHoI1+ zA>+q_316Ry(IFBAjLkRqmf(a7@iAO;S-9o1$Ns)*2I20jFCYA9`fOLGpzQG!l<_cA z1_@J=0lCBoM}%q~^f?`17@4qxXp^WKRcmUTi?kn{;ScqWI%Bc%A9QP6qdX`v-B>hO zGus*mAo!T%!>HKJD#XSx}pRcR|-1=&|MylUO~0SjbTB7L%;Y1!$9 zrX}PR4WO{2LG|;_;o57(&*4E&IqV1%$lv69`?{`tBWv!auPA!a76Bb|b2s^zWZt&l zv(-r4(Fi2CG)VP`Dm4``Qv>gNv)ORfghn@hqAO7cX)yE&(x(EEZyFI&|0~rqS{xrWD9MWk5``Xez|C$cYIu z$A`K+v}!xlXp|_DmTc4#tq-bsB2U`!xwmes>g{rK)fR``ynRb2%pV$z*@YkzB`l2S zoGD>bc>;}nri zFffN6pkiESs)DI9#ki^%;v9#-Nh875cA-OneuZ+13A_{)haL_ZF3@x$!#D%}Gj;j2 z$|toL5h=VQ;2!v{2F?|Ac?R1YInChFdIZF}?O6hz(@_{Q-+<&t%Tt(5KMG3^nK4+< zaY2RFDzpYsRr770WCZl~?UdtYJo1(Q!u&3EOifrQl;Es)JNMQZ@l3s|0Uhu+xGlz7ExWB z7g7D|w*4OPdEI_b90o{%yq+6T^|_&G8SsiGaToy5$l#qs^PrO+XcRKt3QFSyw;zMX8lQlG|$^*-D}>o)(y?3JH4XW zl|-{JiD~nKCZ=;0VuDj}j~7^`A9fJa(Gn2ThRnqD&6V92G3}j~Oh4g91%WrcQo#n3 Z3Q{2V^nr202LKAg14IA- diff --git a/.metadata/.plugins/org.eclipse.core.resources/.root/.markers.snap b/.metadata/.plugins/org.eclipse.core.resources/.root/.markers.snap index 837b60476c7c17fd611b720e8c7c1a9abf99fc06..ed1969ba2a9b0763e80af86cd347a5fec3eb2aa7 100644 GIT binary patch delta 9 Qcmeysc!6ochlv6S02crRMF0Q* delta 6 Ncmcb>^nr202LKAg14IA- diff --git a/.metadata/.plugins/org.eclipse.core.resources/.root/7.tree b/.metadata/.plugins/org.eclipse.core.resources/.root/7.tree deleted file mode 100644 index 36110745c09e1becfbd5744b7c04a8528a5229fd..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 4581 zcma)9O^g&p6n@<^u(0e-&+IM&>VX(yqGl)YCwee3EPslyKkSbD$ZyX~?QZY(bdTM= zivuVzF@T94;6S_)j0XdYCZ0Ta@}?dSx7OE}8IkRQyHMa^}Zp(sbfZj@__Aq)nh;YVUP5TU;i)Wq<- zXu+m5Xu0MG0@h9YZe0Y!VauyM47Z7Kbti~g!(n7&jGA4W74?U)`ja%|`~bO5^vN(P z&xQ3!<o}D2Y8XXJK$P5G4l$(J+ zCu$M>h*Ncfa|q&dgw>FmZac=E{V&K_0oI`>Dp_td^pl9U>Ad8t`c9-Zld*^E_UUYpFUOtzcUmW)uHcU{B79eY#4zr)i; z=;QE<0Daqif8G%(gfmPCH3H^dRD`__K4r4tIu?0~N%Z){Q7~ffYn94G3Y@!^`IZL9 zcqM{Y{CVMtAceJ?gETc32DDzE8Xp@80=t#M*})uN<6zW5;_Q68CYtG|cH_?4Ni#>BA2HZz6vGn3{u5{8zfsVKll zwwtsRKPht>38M~BBt=Tw_oZ7L%h6~Uw?wqe(^~qCS+g1o1Ir8#1WuG1>L(^qKaJ}M z!xkn2zbQ~%QWixggl10TM@+$(t0#Ak>=@mdRO#56iTj%gh|ojI%ki7o#|~JmobzfVUZVIELX|N3c^x zv!W`c&Bk6eEu~GLKc*egXh&B;VY}aG*j_zcxsTR^zgBUi8v0jw{0YFuQM*+YEwk`dC1R zv2lk%jgBZ$!;OsVXHTw>$drOD&EI@X{cW6U!;JH(GL=wJuE~t^%FFSEOquGUUC?MB z7+`5KMHe1iM80I=^kbOaErm7SN1x|0)^e;;YVJ$leg75DIl-RXK24>%fcrGyWC_-g zN^$fdwbkth6DBqA6y9`Lq%!e{NvwiOplMVl2XTqLfe*iws7y2>65EdjrYlq?34w{B zoENB3DuK$RXsQn=?6M`d^(m8v(8RE-t)ocT%rfy>=L76LQaY77WplJ11=xlphb1O6 zj@GUKdytfhL}4;nTDJnc%}J?dhYTA+jPcdLn z0}f?sOF}!%@F9)1J`eqgws7LAxr|#6?#5L|&4n9HsSdCqMOs#Hmj}6tnRsUfR^*=N z@dCF(Sz?}SDdWYSR|C$Dvi(+#Exc)2nnHAPtYtgiIqc}UUleESkJRgP$p^mF;dcXF z%G+hm1bT_d8FVK2Ddik}idyHo#2BZHUmEV74^?!N#Q0?%UwMcax5<_f(pI6-TLwHO zhhSa>NEKs^*th2g22+9I9+R1uQ^i=LSvfpP2_-S6cRDl^wWCXnJ4n3Orj6*ck^|;V zrLO;L|5g?pPR<2axO?s!H6c*J;h~e2u(@OvT$^hd%_kLJ793w?dhm*oR&c~q1!wi` f!J?5y1$Rvi`>%HwoW`+mtc(ioYc<^Z8UOYlyhthx diff --git a/.metadata/.plugins/org.eclipse.core.resources/.root/8.tree b/.metadata/.plugins/org.eclipse.core.resources/.root/8.tree new file mode 100644 index 0000000000000000000000000000000000000000..b9e5136806e26fc7e86c22f0729acc9165c76835 GIT binary patch literal 5884 zcmaKwS&SUT8ON);#x}loW@p#f&LKf$DN>>x$syte39&v%K$=X<)1jx}0noDZ_eAM=A8G3#p zWKn%AP8!Scd}7v8xTEFt+g`bpC5jQ5l7m8~F*#6<;y=V>el ztHE49q`Rdj>20X^p2Q5e^u>iU`mr5aixbt3XH~m*W!O?N{ahJ=V)DNCmKF&^(6$gp z;d$bMMlb3vt7bx9VydE8Ld5$hHVWr*^BiXme_zik#8!-iQpk;BOQYEe;+D zch3ICD8w+vEqwhA;apNa_cjRAB~^vk+=x|@gq=lww{+-mw`UGt%F{uSMa>gmb3WT% zq!u)8?*IN@eRY;s10!ieuF=&hA_ScThoT>m8GlV+q(`IILr%W*eGfyP`TOa!{Wzb<(1cuzK~Osmbvu3f3IVN6h@o zVvu!&n1i=9RnNU^t4}lchQ%T8HsU56&l%-ahy14nAn6VQrsk*y?3wJhT8<@ln0(zL zk+znT4yeu0YZipm8ak9jcx4BnKA&4j=QuqJ$XcgN268?3KEEZBUbGZL-eJN@cdMTs zyuVu%66+OS7lny46(4^2Hw!}Aq3NjGQ*al@O+5iALjDyW>FSVk%$p2w)a?Al8V&R`LlF=dPb=}g_ zxf*Nj7S>)jHudW}e*cA$h;Ly`4Rj1h95v}4GdJADy6rsDFqGMpksV)o=j-NY?-#ku zyW43~83Mbe@a{IFzP_i_rUtNkEbNz_s9H8ffAHWYD#Li@-XvCc+GxF>W8^*Y?#0cr zOPRUvf9d5v@|@H8+~Qixr3Qr8TEdxOaRIp$XCF0>I)5<*Z>vVITU*(rO7*;>T0aXX zuso`ifi8<5;pNvBRjP&}i^DizwnLRd5N2^54g(cRV^F0CWLX^HlAQZfDF$g4*W-av zCKR($Jv3R|z}9Kpshoi>iyN6?iz&?mT^2X7Rb&oRN$&1@BEsV#*d%;FYa9{Wov z16>xk3b8%2mr??%ERNdl!u7&B#P~Uj0Do|kyOhogK^AjZy=5+?40Ktb-(znvZ{B?$ zi3R?#o{8}Hj^!vx-;ai8*zh$8K7m)WE zvCgW0tF!nQurrKV2i8C8=urq7$HVoehGriADMNjX_@2T)W~zT-@&^BARV)7pSAVC_ zs!#s)c8^j>e-}@iU`*3vzY9G|0l1Ta*aEQjfgYs*@p1Pf3qnS#M=8iBILD7IIr0tm zC&rg|2IgzI~h0&{?wuEij$t4Fc9hrVR4V{yn^=urv)H$#5g0+7_*qZG(foT_D! zNITG@6reX5TCpIc9_UeQ=y>|3EL#w=I(n1>cA9gA7KXfoJxYOko2ey>LgIlQr2xIb z(4qw)?YbVNfY1&hd@9Z90Y^^mQ8KC3qxhCn`*7gAN6FN9agTpj&ntXoO^kI7^e8s; z;JpmZTM$+TA0gR3E(#C4%QDOV{Ttaw3c~kTXqmo$lha3>nC1HZ%>zA3zVhnlA8z1G za6NH3U;pkrJ&FaN+xZg)P}szGa@g6U$P+CN|6r1l@#bG=#Vej3l6>{^2Z$~Dr)GE?ge-P zY7nC0Rd|3aX|UsbXv2AIC&%f|`gblyv$Ny*dAzf;yZ`m$hwk@#_a8jE`2FSckB8k8 zFN#&ziM^vhwOif8WYT$(j5^Hi@SYSs$(+v9gTt2{lX1J<8U)G&0TGLB+n9L;jA+!8Jq%5vXvnpw?Rnt#b?$(%KgmfFjG6?n;H@W!8vD!gS~ zcV;%W1bB8*!*qKYb$N*qixAJe>y7Vzi&H{#?$j4{J18geS?=oy0$r-Q#Ho&GjHl}1k zn$0Q;U~RKi*&Eo@!p4!pM7BY;0XB88;X(=lY=8~0sfCRrZB)|Gn^3ezk4oAVl{8bD zwq)410XD#T8=68&{er2_V}b+tkW7 z>Dor1O90pan_AciE;&j9zy{dV!^Ume;Q@3Bpi5wWo>Mz$%>}Ila+WBCvRZfF!`*R(&PpF zmXkScWG5fssb@5wd{Ehz6|8Tff#KxS%-4|hsc*i(!psQOlsY+z&0(^Ftm@=noO}?C z9EL_#riNCAmXi~umQ8jSQ=0t1#1d}6W<}HOj2!xUB}J*Jw&s%!b=4=IWOD-RF|#tV zAWo0&y17t`84+fQbu_ype&Gi2*)&Q=n^b%GN)qG z@s9EM?yh!!Wqp6_J!_xuoICe?bIzGN+xE(lZ?63X)9Tkf{q7H*eEkbN6bv#kc(Gsu?DT;`}gp~F@3D!R(={Yx5T zQ*hO~lyAI)vDH2+y9Rsl%vxgzTViv?m(U-Stkc-=y97ekHIaO=0M-Q* z%+Xl%m(rwQPPLS`9WI19J!F8UFy0yE%N#y`LDl$M6>^gVbKF>doRc|PaP>I?B6F@I z`Om&tEL(InekCJSMbqOJ-92i;@hfSvkA!O>`Emh-3(Z?>HGY~ZxhS?VY5d0TGPd%X zduMin(}Fd3NnQ2`%y7%#2v@0+qQ*ZxF7*VpAu;0E_P1iFjXhBLQahlacEwXrp>POl z-zjAdtyc;Zxs^BJ~BX4xDABzjijQyX-fmo$W0QFq}z@| z;_~U3vJVSd<)K$4jQ7F}trQO4ug*1>{wWQLT!VQ7 z#!W|+IivC+qOQmp4FbZp+r=>L5Ev<6rUi4*Mysoon=ELvn&h~eHd@^ZsVHbeO%-2N z0Bw{#kybk>%?lE2mU3sR7!o`WM#`52s&rF(tJ`AWA;S*2*%(W8y3r1&NEOo!J&f_u z9K1Q~NRZ$S^{pH_gHoiM+Rad$#K0o;Z7DYVT$ygPN7oYu7Qt_qa_5hVVH!9rW2UKE zlpET=FE>~ew!Kp3(9-1{eMO6ML)-h(peQ!SrToRGiizZ3z)1P#3{@l>-u$cFU=hg& zq|7&#CXx+r()o*semnAxpudaO6l?0o?O^{ z9@zZ>7VbAXZ~?IPums>y zlaCiVAmFwK1Rg7PL?V52)$2b)58xvSAFdDZSB2^kJK=YhrM1?7B0!9fc~Ic6vTILo zPrKvjlRlm<5ytXh!0SrHY=0#N$#9jnJd(w`XjQfDxyamnf3<$hdXF+q% z5Mkem?i>$KTwma~3Ssj{Yagx9@Sw2EM$|sXO#8a(A`spTt}Af6qR+9%4R~|qb5R`x ziFzR5b8-Ln_HEtUXQ*oYccOVeEtNffp>TCee~XJmf~}yNV|#O_Cl%1s?A0eFOf2Ry*RT&;L(4Ls%J;P=Ca>kmvQUZ!ZR zHIy(p-UcoR7F;pjf@go@jy(#04hOKV^nB;v_fS#B69sp0NY16`-L@F($mA3_qq5TY zjbbYP2Vn4XR`CmXsjTYVI-Yx0ZnmIy1<8IiUb4JOQeVezy(2fQ9vG0kYFG|1w)XaO}g6A zRR{?(66AhX!38alVD>L2JR~?^a=BCZI5ktyC)6Z3U@j&Qk^s)YaBu*Xh6D#<)HMnc zP)oJ*heeQ}I)n>c__f&FUyEsR>q8MfCJOs1k|CDrgWOotR#HXY)Q}8~s498Hns$&P z@}@Zp%9}Te_eSy2x1~YRMEq3B_|pwVx{0knN*Ew9ral~9)5S1t3s_iSn$PbNHLFt- z`zx8&MDk;~n3m|;K&r^JdXgVkGcD2eB~nDD-I4{Bf@#*>STJ$mgU4wpZh#Yf1=A8c zspAqk4bBU2?0T>mracN4%9m-XhZXyLwb)ZlByTRQ|Fe8 z{gwBmdrtOBuIxW`3i2ur(Vwm%`3ZIQpE~s#DPs2jau!sI>_2tZoBgMy@r`g!r^xawyv$)sGtid0bv;EDz7E~51jOtB(Ef@~1 zFf@Nm3$*%!34{4`tu-3cN_EYM#`U09+M>0yA~#llFsf^8d}B1+py{PXdnBmhD+26ldR=nkxH7nm} z+c!URtCmB^Xtru@MYOdw5NR+5*mFwpSMq?pLCiHozc?s+PDo1cXUQqWv!y_`3iCNh z7wjI2C95H1%#v=FEV=W0dBBz>ZzcNm;jv`NomWeNmL>m^w6A?Amb?Q(#w_V($(gS_ zOx6>3vWaK}!a>B?ly`FGt`kzAu%u_aqzk(TW68Hk08P2aL5xgGa^`K&MD{C}smY(U zM{b&L>OBL#*~4-}k%ShBg%Vm*pjERHW)iZOAe$YKEh1HG;qa0`n@H5vnqdT*`f9Ra zTO6>h9+tmEYYc0_SST795X}AK8cCPPpjfsTd^dhjr1aSaIheEj;p>rtmmATDE8}`8 z%o4bvfSq5lpvp!4GRei?z-+63i?N)FXtX7yxd5nu;0RMm0M?!_0ip_V0acNf*Bl^d zyx``#x>^_ZN@9Q2!47>B1$$kz#kI`wk6T2jR~#rP%&T0wxTZ|k1MM!F77}Kc0|Tu- zfmwKWP+O70YDI*5*@1)J9D%ELJLgFRK;4x*HYlAW0E_FF!#zrB;^DB%5_1T-(}9HA z{9dFBh@u2XS&&o*)fQ-JObrTH$SaDCVka27#V;fS@+FR*$aGP>Q>3Y6?M~b3mXod&$DG1=S11&9Um_ zntN+|rW5N1Ig2lUg0b_Lxmh&(LdnIqVYY7$)|C(L)VsEg`K$wkm7&h>bBEs{+0bqe z{vtL-~4vH&Lm$T%6_e?=CUchKoIbENR1C`wdEUg{V9 z=iX0of=$LEj!De?uAz9ENJXR9)9~_3Hoy9}O3Tdi$l@Yq(82Rh24Q_q>KdS|lllTy z%$O$?75y+~$^RqzSCoA1u;fglj|`6`D@rKhTb8_mEO~ASmdq3RY4qMnRrIeu_<+Nb zR}%ecy69gS6wLz+(M(|%SR~``tD}FVU7&Fh{l^msPvGH*{?+dvl>#lVnJ?+0f0WU` zvVIp~MD#x;X}nhl@rM;k86<|~-3V%AdRqV1pJ{w7cg^3kcaKBdr)vH6LQp8$gYQq* z`ZEpW2r>A6Ia~Arb?eV;qwYT!p~~(cd;=kUTYshj2NZ+9EoY1F7})wV4Lm62FXe2} z@1$t`nQeO|7yk;gtsdTzs`Y2Ky-R>E9RRFd)%r6NJp}r~0fI*N)}NX9iP%4PutT4+ z^=Br|5~|yQf&rF;qjJTEd_MtUR>(5M}f)s;)hL4Sd-c+qW6Mu%b21m?F0-!W) z>(5L?2-)R8LanOxXC_(+gk+ag2i2<9pBX2=6}3(h1g+}UpBblH!o@|i&jNattv@qv zJKjeQ6cnpke`cJVpMU58L2c^RpBbmuHb3luK&PtpN5%z!ak#r{>(7i|Cw>o(5Adh||O1d*p1 z^>_H3eJ4#YPmtO;Zb~MtKQo?7fKJTzS>XuM{nx^w%d-f05VQSy15n-iGk0D_umhNF z5rC;4edbQPKtz3z1i`o&r+uEf>_7bT2Du_D?N>>9s*XUT{-26NCEE$N603l;d@PdL%GM30T=>S)llrxaFZsC0&ddr)W!bJvNRoqA>kU(&aY| z#nWzwkTFkl`|pCIXY4{&c-ka+*!)B~PwVbkLaf5mvWfmq?P=XTGwXL|@EJnaujmsbwO(}EB(dOc0m06R8|o=R3syF?x~|8Wr3 XS2Vzm&9Y<0DwG0uN#WD-2Uzl7BsVVb diff --git a/.metadata/.plugins/org.eclipse.e4.workbench/workbench.xmi b/.metadata/.plugins/org.eclipse.e4.workbench/workbench.xmi index 86d712e..faba522 100644 --- a/.metadata/.plugins/org.eclipse.e4.workbench/workbench.xmi +++ b/.metadata/.plugins/org.eclipse.e4.workbench/workbench.xmi @@ -235,31 +235,31 @@ categoryTag:Help - + newtablook org.eclipse.e4.primaryDataStack EditorStack - + Editor org.eclipse.jdt.ui.CompilationUnitEditor removeOnHide - - Editor - org.eclipse.jdt.ui.CompilationUnitEditor - removeOnHide - - - + Editor org.eclipse.jdt.ui.CompilationUnitEditor removeOnHide activeOnClose + + + Editor + org.eclipse.jdt.ui.CompilationUnitEditor + removeOnHide + - + Editor org.eclipse.jdt.ui.CompilationUnitEditor removeOnHide @@ -317,8 +317,8 @@ View categoryTag:General - - + + View categoryTag:General @@ -420,18 +420,18 @@ Draggable - - - - - - - - - - - - + + + + + + + + + + + + toolbarSeparator @@ -439,38 +439,38 @@ Draggable - - - + + + Draggable - - + + Draggable - - + + Draggable - - + + Draggable - - - - + + + + Draggable - - - - + + + + Draggable @@ -480,20 +480,20 @@ Draggable - - - - + + + + Draggable - - - - - - - + + + + + + + Draggable @@ -511,15 +511,15 @@ Draggable - - - - - - - - - + + + + + + + + + toolbarSeparator @@ -531,8 +531,8 @@ Draggable - - + + stretch diff --git a/.metadata/.plugins/org.eclipse.jdt.core/1508644233.index b/.metadata/.plugins/org.eclipse.jdt.core/1508644233.index index 9b7966a1c3e28542fee76f6e66415bcaa0a1e778..2abce784e75af20891a40c9fdc330006ad7feda5 100644 GIT binary patch literal 17197 zcmb7LOLrXCajtn!&jSOHkY&?$L|ayDD>O%>d}1e2>;r<3(ep0W>kw zJ?`!y39XbxR{mF6+iW^2v{QYQibA7Hv zl}&%o@tgon*2f!bs|!J3@1xyXdfagayd*yIcUSO#d2QW>O)%Cz1I6<_J--SQiU71Zc0&s6fd+qRZZ_ti*ovmRM`JN4AwtKc4v={w; z-}buUTP3=5*WTZ9*0#5MuIH@x?0qMAt3nO^#b`L*Pq5W+$Mx>ou17?Fq0+7$wr`xD zpPy3WBRgFF@Q$p?EeF)vaiUx9&axLdJ5JEPff@O-MYRu|C_AjV;dtGcv^O#HD4u!S z>9~Enm&|ND0=mwpc5mpke=VEVZu|F~o^N*rh$EWW+zlKXt3|thxBZ@g(eMY+E#L1s zwwJ6_N1GD0eba!&O}G8wR?kVAW&{7xrk@;>>~T(|VCb2ptAk;*Hi+5`^(oCnP8b0? zx9djxhAQrq@0A^q@ zV7GkFoRDKbbY!tZuw#ny6#U|osN;a*En_NdU=@W|cfGPO7~p(#kK1lI0AuLsG13QA z0tsZ-GqOB?V_T7rgl5xMei0C?7R_!rks_m5ypPF8RKnzBW;5LPBKz@D z5cuF)S$rm@^2fdlE<)QORl_}Zu<4r-<-Q;2Nu5xO$)7TQd;(Q8XCZ73{K2qiN6uY) zAgi2G4g4M05%y)I&Zs;XhP%>t9IqM+MZ9VWt0th=nTr;0FKjNz0#B*Z>G__*b*g6- z&uakXPn{ry%4xqRWS+n0^!%*7>HvLC>m}{;a$|wWP0nK5%MZf0U4RnXk5}8VKzZAV)~Sl6FqD zp%(**&u^*xAm+t0nhik{SgEWU1&7)qyBYprl+>&wJH2(0fZuUF=w6lbsvE8jd#NTi zgiyVAd7*3c!}9j3<8&R>#!sjz+~`C9LoS&{Per;{?`~wJ8~g;ll2LSZ*Xw{BJV_a< z>Wd{b{3n`n2^QKY*{4vvzA=EV(X-EKF45fvUnL@jj?ti!FBHqwnHJTen2m&SayS&% z>oOFIrm!9VJf?=-=?wcKyQZ`1{CQ~iVq0i9P7W6quLMCihhRZkSA1_LA-@Gi8)<0V z_MxIu6?;VBEAY^Y9Y(5>7>1+da22?U2tr1#jMl@@bE@_nZztLnF=q>0?>f8AGmF(PFFV!A>aX zB1a0Y%8@jPi=z;iW~nKsnUSk=n(d0Q9+Q3Rw!hHrLq{u->OjPtKd*gEHD*bGXB&R3 zCA4OTLVcDo24RX-p|mhkCc)Lgai|SZOMbu{$g>Q9ywz8f*o?(pTM2tev%>i7Of50L z7zLS&aDGdu9$TZR~TN|d`pGht*05nvAN4vZ1nPpFIqA#M!Z z?A+yfswyCV{1aO8)*Q{;b3%U@bevm5w&b!_Qy4b(YB8|DGixcCWR!7o(LG0og&NJ7 z*6iFR3~ut^#4*O0CJ!l9xaM;HP3D$e; zCgb~n8am@1+|rnueQ{6G3lE0fRVUzW8}kgQPO7o-O{M?^*JIG?ppjtTnw_Vz`no*T z0>m(*>w)vo^@oi034;WqBOp|ljaPxO71nkZ)Lk9?Y_MS*PAT6X@LF@1sdNWcOes@S z7Gv{{&cfWKd4e8{f_;U4AYlS}igIAJR1Ks5IhBN$1cqD(qpV!M#D~|KrCgV1LAIKd zSxOD2MeYH<^SN0n^urzOcSP1U zn=f`2W&2VG3~dM#!Avv!2bA-98st02s0)MU{>;B}&^b9nyloghgFnFJ$;qnLHitW1 zJL02puq!}pOoI~M53LKk{6`pz=bm9vTtoR+<=!{0!*|vv04x)y#HE@|3jmI$u zSfmlSd>8w^D7SpQNu@oG9MF796~ylxumiASr2)n+4})HeZ2?Bnpi$Y<@DQI3Di{G{ zR)-R1haBxCDCH*9=Di^_Vc$uV688C;iV=(oejSh{dccEEZH?~L_se+YRIn1FyI?U3(bRZg)#)aw9T$Hz5vuxB8kP#d-s>nRAwoH zcoo^Fz&DIZ6Rr&$P_rJ|WEm))5R}I9P=8&g2Om4u_BG+^jv*s_W5f`lvuU$ny`Y&} z!|iP+aJs6VupVo!lK4OP08|}z=`j|B+48$8Y1O-a*9GLvX{R*j^+V>%4JU9BFMlr0 zhm;SQ&ud1>H-JWoMUBOykOM0eS%~qGQ6r#~=V>kmD<4vE0Pd7Ms$yzC`2FuNAy1ca zG$ST0ABq%W)iPq%J>g?m4heMNsWYd(pc*^u;=HR4Du92`0ey@l3qw@}jAivs@mbA* zcR+pUurTrmGBO{Dj%h$OX%hmd<+X%=FsodKMudzNRA0a*sKr3n8zN3H*;T8Sk*MOW zh1Cz^?Hin~*+d$IV>j8-5?^q0*JZ-7Iw)`KBYVR-MO0h?$twIVk{Dz)RVJe&{nftx zxC`cFIv!^-QQrx=$MadUq7`(ikU7bN$XB6nGhq>B4m9TlmmlBH@h!H98HSgD^j6k!un>P8&e=IV zDSSVJ;uD9(>{b&)wG4OvF?vr_le1EXCKq{Ag;HOFC&mG~+M&EPLk;oNIVeZm!>a-D zDVa3%sEI591|CN9)JPr8KmG}Ofz}WTb-OU6!nTr`X->g5*sv+WV6cfgz!(XEZc<_4 z?mF6^QUSgyH)1lCH35T9RRqOd{FB)w$oJ=;qXP`MD()qIG2wrd>WUA3e-(-iE_8TR zZ3#OH2UKK^X10zyxq1RK$#Dt0uQr2JxtJPxv07p_Zd;vG3P=xz~7Px;RAn-irmQxdz zcwOKE9~o2e%>dRsbQT|hy8dfJc9B_q9#T`~_14hssVkS&V6)4{_Zp!|e(4iNm(_>y z4-*36FzZwk5njt|U;5ysmLY;AIxnH&44N$0MHSYZK$+eRR;C0=Ij`MbiyB9 z-tmyC>I&bQB}%d#KFZ=>g0M(mnM4y00s50sMUf?nd!Y_m#(FJ1b~?x{vz9*spCF>d zFC?DsEUav>c>;1Rs<)ynk7lMu&|gA96=?rcUUgXj_me!_JH0o&9mAIg5e-?x{1<95Bwh3cwbyn z{MLY(r$bfF=uv9QT}&e~aIka6%Yg36@F<^Ds#^J^B*aSCiCv=Nt$p$7VCfMv_>VZ( z!h2PqX19mLk{iX{(!dCWe=Dka+hHZ#EA%?2BLP+f-EW@AUnJH za)T~q^oUUh(u4FvXBY$sA~?|~E0s2O{XjXTjH?NJNOQi+-LUD#GeMdw5hfKm4P43! z2*yGwD($e7=oWZ6oRE{{s_;sJL=3>3!d5LYvEuX1w4gw!KCpYx@pAbi^WL~?_qO2? zI9;&7=owZ*XNU7ty7g8X{1%aQWv1n5yV0b2e?QTU7<X!=vfrW++649bd=?n>ZG*6)k4)rjcB}gb`kY z_X#?wTgG$X6fr*t{Fqf?AEyERSrS(X1J3BDW5My{MG_y>6DqhnYSPP^&_E+XhfnUW zZQ>VTGbtwC1&l0?RDSyr`rw0Rq~VYX{*c3AIpTUoccYDsQhp`TDb+1IbXYWHuhPcK z!p28DlQnPE@jCEIJ@#wab!UgyNHLVc)^Kmn^jKi zIDt4+*a*H+>RAARh6z16B!fmnN<{`$@8g_ftpz1kllgF%MVA6^&iLv`7C?g$4h)J* z+lve9Ya18=p95TJh;K=_mxMf3WSP>WMBXGt@-BPD70z_A>kIAH?J0Lj}m5G}d7c`jEv$dCW7I>!1~2%u1((e|!z7uA6M3QUC+l-{<%U3nK0DfCJYe zZW>xtiuiUGpRfq{5}wDPQF$FzW-|_Wc`WUb?{P{Lyx6;`e;+Wm;uUa!faD9&-%&z; z?C^v}oo;cl(2je-3F|(Q>4_!i87Y5b-ZQ=tU?Da)JolGxqxI`iZ&miaAQa1(utJg;P_;nmd`|^7%S~LkzbUlS!zyrmv(^t5Jqm~lh9>zb5UG!%Y zab+fb7|Rp}se(7k3)(Y|e29LPjU6OOZfSOjc}udU#(XCUbj$b%$-P4@j;bW5eL$Bp zYE<0|b2l)f_GzRo6S>HOP+N`Bed9X;bsQS0lac^n)>YLfaEj+!)vTs$4ret@rW!ae zjb~tFBy%=AVzU@uY8;TbF(SgUdXWv6(k&irN2zV7vk-|wFS(HUt-0jpg zPH+)=WH$ej8mSwqqo7ZknWVBn{gPTrToXFzNZdY_85#W&#cYZ+E+he8IDAc(F~dqs z3&wqRG*_c5!ayb?nNqkvi=p7ej%k7H3^J1Hl^ zs?pwcE;_nCrRZo`C~-vB5*^fTzxSFM1lk?Yl^8OVSxrKIp7ulhCi|b!Tk(9u5c`vZ zo~LKXM4GnFi}Z+iNWA9wQJ>O3Bs||9lY!S@%bapJx{G1UiDNjXzhxkjW6CI=iLp=V z=ObgY3Ta~SU+LWhvsa(a;-a38EFQzj8>v7;r%WvVCA||bF1jR3$Be{W5f$^BcOBxhxAYJI{5PibS9FCTODS{pr|)NV$5`)Q>Bbacd+qr@q078GH161X zFX)X#UypS?r=KTc`PvOoO2c+xY>8)}@P8AR!)X={H63W-MBLl}xkubwBAK^|v^>hx zqysr3433=@G*#94ol0riZE~Y7S;H^z^KiT>_Rb@?7*32eF zPbx(0-ksy7KdtFxFyK-qMS~^winVA*Yd6~O%c1KX(%QChpem^UvR94AS9Ko4y)$Iu z#iRrjE31n=y~1+5Qn$&;VYzVOO)wePdZ5FMa4C90 zsWDga#TSop(QUSD4~t6ZGUtXXPJ{%)T5#LlapN+mk$PhW00%g&>P8OrCg^rXuPB%0 z&E&=nm*x@}OZgy)q#LaiA${A?Fls}L6<8b}pNobi);j<{&6>4x`FAQ>zoMW~?>5E!en#_}(a zp5hB|MF2cFt;pOkU|gIl>xg>}MT$z$sgioA;8!NgKDqaErYhDj&dS#fH zaAh}K8weCg7GsR^8iRR2(`(hH)PmRCa2?h5ZYNeTqXn^C2A(K=At%)9c;Ou~d0SA< zaxx|{JxdkTsIv$&6>*?7(9Lj@P}-uVUYw3LB5jGg3!{rlIjh0-XOM#UM$5!_Ei`c^ zHVj?%%XkwoFLL%lwm#4eQIp5FTw2+DI#HZHQb5XJ;kZo+r-`aL%_(?kVbGLE60@KX zZluB}81jXg0Ep6kPFh2)&DL0Y9`=svx`xsf5XYPT9I z7tReEC@-qM7DXUyAJdykNWNYZij2@HsR3qcLUIy5VSNuF#N60Mi7~2Nrq;l`#^KbR z%FOc%ig?G$%w@^R66JiZN^$8qgMr)rhFn5~pSdXO6;3aLuZ47(#0JBgDeX0U#;+4H zUY^X(Au|R{#%p{tk1ft=J|>eFEt!iGL*(&-`x>sx)Q&Qdz7@mHv@on@u@%ge35!xf zg-)i4oe=P{AcV}Nq6loV&uJJPD6Vu6Z+0SJLJi}=fMebP#g@MXQNe9b_C-jc+Q4Nu zE+YY*d7*%tpz#L>Bh~JvFxRj{oiF-EHOWQKD2}uqeyOLW?drPBjJ}$Akv^8d21UNO zk*5fJ`E(1V7WxVXxlM@8iWYS<-#^8pjO1latmAQ!i5CV*c8-~WDQu*T#SfLiW6uu2 z?GJGUV)R;OQQif>#Sah|xI8Y=pdzzxWzfvES)4tEwY9(oa_p)lTOY=b2V-O8I;{m~ zf`YLbM9o?Xx5QA#PlOa|1EpY!;vu$Eact_L;74_c zpXW4>bH0btIwwqxp(-ABII>cV;V4o-6;*skZ|p%SeS0wFz0t@s6V(JzHDS+j^ufY` z&^8t)spm4hF};!SCkWuKs zQ}<=Oafix98$$EAY(t*|G5erILA`r@0L4vUQ9dgZBgRZO`bgk12CU=C7G>E^u(>~A zoy~I*0ZxC?(_)vH3+Pd`fX6NjI9MzDc!^=f-MbrV9LCFOb{t}A6m%@6n786TGG3@E zg*h$&Rma{yoOu_Vd0EV~v@-YQcaS<>gwW#X1*}nXx^<6V62PbcPW~s`Ts70>CBdWWZQC;AUkuaCQ(x z;>wl_9zuyVaQMkkVU8Tq`V;SCM&Dds@XSZwr7~LiBA-l3VWTcbU%-4zb8wySqAbd2 zXTt%g@8kVNUnzTzJ_N}=&#Q<r`t607rybXHqd)$s{lLG*cG}E7rAv~56VT(74)%XZ*EL#6a__Gv z#v#2M+YdY)di{93>f@x?_}1t2F2fzC8b@(AS6%F%!azx8?u35E_JD z-s6!bt1~h%EwgHKVTRU1>#Q^S^~LaHJ$fnG0G&~xuQN~Ror`ChlQ-vZqIU`=+dYc2 zY2+F+T^D!eCfzztyKgm%Y4qg?hC-_|`Y}VKd$Wa~9P%aokcXH}rwlly?`JZh;}Cp9 zbDSLN#D1)#gdNglMIltSN{WV)VVNBzJB(vc)SGXM#ujW?zwIyo!1bxW~S?y51ju4x_;TT literal 16849 zcma)DS$7=Qajw}H%wQoQ%aY?G+VZN%9Fg*g?RYyN2ue^ufFeN4=lJ-XG-evWkb~)Q z_Y4<3DNp$q`3?CQ$v?m}No1)dzl_3mtK+x2{kwjD*uCrTdi#FV+VXq7o8G;p(J;8~ zN0GPdw{H47J-1A@du{`wmJFK=w$#xDG|ISjk~-PiHP z4;Ly@QXu$I{3PrWdi6#a4E%8T0KW@=yuLP{ZUp4s9^Pq1pY{i>;hw)e8V-ZL2V!=5 zUN>wl2mAY8zZ1Pxl5^L+2iyL}&Q7n}_iyyP2Y&cgMH=>tWcdB>VXM(@w}0L1_C@61 zWoFkO8gi{m7|54vQu6zq*5wy3UObiAp&t$Z;Ptwl?(jkD62^|DgcZr$x0VJ2Ot&qr zcB27yy+*vQb^BgVp&Upp7!22f{%-5C+hHc?W3IQ|^IPu$=7G$I!M&{@VW;l&0x}q+ zJCz0_JYe>T)UO6N{a)a8^!ZTcfYFui?rMMN@A_ea+Z>i>hLg?v{{7){&-ePe`H{?C z4GjO){!XAMA4=mMC2cl3m~Qhf0|~A4r*C90dDKpv@pX2$aZJ ztmXY6G=76*yw7mkiDh1FMsIO!RcxBXPWrr^R^9 z-6aRNf()t0QVrBB9371hy=e6VeJ$0V-`^eX8O5+u#}h>zk5$MtyY+m8o#6Mfn>~~T5V0Keg78`Z?%eAu z>;tK&p!DG>bg|!o19c?L27ROYqo8ZkAIkjI0C3j4Xt)xFLFkNT7Q~;TRb~KAdCB)m zzECVzXXm8ymr(%Lkvxz~0p0*eeSRdBzFHCGaIE@8&>1LnRSoPospl~tV%4G0ol28c zB6aXZy|&Z9^1aX-I3#LOcfZ^7GEO8?&%G5m^TPUkEy0`uJeFEN*c^CmBjmAEO*s|f zk(9!bIU3k7B;+h1K`tGNHL@D|`@!8*L#we8aO?b>G@}Rop?BXHPu3mD9E4#q%80ZE zhq=)QR)*wEx8DY2%GLNyzI=$t;fz6~LA*1TdL&IuS--xy-1DMHRa)fyQpb7w)tzV1COM3HCXEG z!|2RUlyAodctQib*JlXK$m;-Z-I?n0o@ZiyC}U_7&0I3|HzzePNt1-w z4yb$^SC+HNmn0JLoGNu3NrG{IA;}_~n=o=qdtQvc(9^47(j4?@Q%M zZDCR7H%Eg(h=lYLFYF^Zj4<(7B==h>spli49DH1P^8qrqeLgOnUz8G^^L;$!%MB?m z-PqW~x<^v{_}0dj{;ISsBgDg@l+E*Ty42(xJip6(e`75AodUup4E#QEJ(7I4kG}`_ z8{ln)a%=+M3UX;C&loFK8Vl#8IPivhm=Us5r;XJ>bimbMuSx4;ci1e*yXi>xeFxJNTWh%HQ^g089@~*o9WSIFurjUZT(d zt_y0Vw8NNA%sG+D>c*{Mw?}LaWU;>=-9U6V*SRqo(rEDJq2zniFR-j<_L{#Lm51+aZ7UbfljMzTWW{5GnibhHNd=ub5gY&U&Z)P%A>G{;H4`XtGj(a0+d`H=uky+ zw>cv>FJ&H`e9i~I0G+U&N{)t-7d(@tN0OuH2r#Fd<;Jqa0sZOET-gA1NGPD1c=J$-4kCD0C_*OS-F~31BtO%X z=2Dvn&s4bTCdyGT3fqbYh==Vmr#CaK0gDj4R^C-8De|>Q{ZiWV`(#xf7GCZJZLdc= zrsGrM@TRzM4qU9>iu`chNYx$dcs9bQ)(>R{S@ez2zuOH)-1kV&wOC%L&dtl>60(@K z88(@s4pW!Sj-TFjtPqTbTuJHGKf;0iMvsSByo02={q7L^;^DCrOe3FyLGVqa0>syD z1QDhLeY5+S)r~}tF{1?WHW#Ia0AR;=uBtV7m>&GbOyphrV-5&;6oL*$d~Y9nBEjqX z_ihLH`Amw}x;$>_oJZ312a}&*!h@l)whnLN+%n#r$oFw1+RJP| zeXJ)cpG)Z)G5}Mq;s|~XyVaf9&O`ZX5wvf(2DgaWN2gT>u)u^_=o_pGLmc@4 z?p3$F$fukEC7WS|%2lVZ{!1xt2OWzT`46_@S!GLs_(-=o z!@Srn!Wc6&TEx7}$H8DMg4Q|R%mG^<25h5_qQB}B>RnZmfAf3IFyy?Hkgtc;cTWa(4jcL#2+;rg%;}2!lLYCjL0D!Rr7rG!LJe>dtJe)b5BI|pA zelAw34EypCxZMTAg@fj2%gF>*g)0O&PX_s4ivAG)%wB9)iLiNj$)5 znZ~`!Tu|5LBaKQhSekGey=cNS9V^WBIh8k`ezxE$6o3}0CFmPA{RmFMQR>^02j8_k(j#_7`eXPJZpxNL) zBX!NAHch4z?(-U570P;lAIwb#rZ8U*4GT>WSRx%pXC2 zC=4@FmiZ{bg5AZfK31C<=pK4b!^nWjMsgmKKFFsM>VP zH)?RxtQINL4y6D!Pzv*FiQA|%Nkw)Zgo+O=qa2O4BbQ&!tRTMew1_B6bZfIHB0&Z` zJ}S>^n)mimDC27oR#RV$A{2K*T-w^lY2NtPiroWU@ChH*Ad)Jtk&7%f|>Ei*Xu zx&(+CiZU0ys^*P&M4_9$GUI{^zzWOr0^xN09S=@LOFJB+Chte|28XzRK%$t?Q(boV z7kCG+Hn3|Dl!);BL<)UPf$@TIb}LP$Yu*r4;4XwF{Y>&5{zVukir6r704a`;9~y9~ zOyXCVI+wJ5f%ziMv6KPxk7Z`y^`O*xiDUqla1zoim^NUUQ!VmQL3Vn6f;iNNV@B0Y z7nI>Waf^iCU%^KuNgfu%ZNZ|weJELk8XRVz+|%)Us6LwO0)K5QC&j`7f@6^`m0L45 zpf(-nA!gF$U}q;%e!-ilUIQ!+y|9ZRxQB7@zOQC3T{ zQDigMQ6@n=FyC3kodBiIx>2Jk^VoCP-S-m~VoP3BqyY}+0%Vg|VeGfM9v)3?>WP|J zhE#wwjEAN?VCK5FPPAdQbq#r%=_q?ELvPn29@CzqUJAFLPW|D!eJ@pAX7iS{;ga6?1iq^?tuDKcls4ze!D;}H_CnoH+& zVxb1_+(=JA3hs%_jk!AAwZgI*az&}fuETAuZqcQ}Ix{_rotw0HUGm&$G~Z+tA;b9A zY2`ZQ2~vIXB$?Sr3n>nTsyQa5Xv!bXB$<-F&zBcvZp^XjaMrb+&v?NYONi+x&OH?? zJh^)Z^42_5Cbv^;5iA>H+Q3Tt7pVmJ_(*1BY*^1!ieAKHu@Yeiz?zZy_yifF#TTp_ z*WAI$m<0cqRU>W#-)!{^r)Co@APu~ubGXFdmFh-%)G_ezpNrF_9mV`}nU*=Xe{Rt; zRukT{@a}tlJb!fJY-Z{Kitd+;)M&#XmU?bV_~0016pFkq=c&2Z*IGC-T-2_ZR!*@0 zGkHHPccazj;&`#{;`E8Vg@yX>LTh;EBAZw)p3=nfUP}o6Kz^F04=xK_c3zI9qvXurn^YXv`jqLrayvc2o#33_5rTbhKs4|noU&`wl)tx}+ zk$guTa59|X$(!61oXF~7GSB4kH@S3*3A|E_pUZ2`**=)W_KEyBaq6#xb13s@_nHLp z0t)-4{3t8HR)zzubpG;k4kSL3A9JpgSBt+B(N0bN!Y0R>(aJJsYVzOY-6Tx3TJN=9 zW)rK+W5d)Yo&Tp{zpq$(DI9vUDL9YiLKcoCG*h!qj1kx5KinRxIG6yYF6BjY5ei26!?7!#t-D@$48pq7{4RQL6(xGd8GGVG~L zpI>f{G^dC1{Z-b%*m9;CHYJNybs;D6+ZdxvfNg!V5DUYz7%TrHbL~+W;_&0L6wMG= zYUoBQ`vWx0Fi}S14N8|*)pof8Ten!@yMh}(>vtP#S7KuDjD2BuanWyWoV>?CyJy#W z-3shz$aIVVAFc9bJENXi3&~2)x{wUDS=4;kfrrE^NxIkyLS!6nXS5*B?R()J_E6w1 z0bNKW>}axOCh1kJA?tQ`NtwPfG)l6rw36*5Lch#fa1XUVTzhHOgv=87#3%B&ZwCxb z&k34LjkmNEayTQL)_a3PHmjc5{+ti}`z~UWx;Q$1$|Tu+R5bz z-?eSV_*L|Nz;SRM)3lbkhK?bZ9OF39jWz~4<4|e?)C7k;^!Gt>S~h5OBlN@aa@E*? z-o|W;YN4pD!jh28-20|xDl>1>^xE^q44uMv9wy% zG_uzI3*_ufhGwLDaj8wE^l-Y%c&ejly1^}#8R^C)5bJ8qZgdO1Y)%8H$uOYP`rh~o z1ug5_vW8*|>1icy3nN%7v*Ln@_c@cj%bDIVn1ggyb~E})_X$ND8NtClS6 zdC_$=bvS#1;IV*}clP3DJQ^Y8bGWwL#=W9Wa+e3Vg@-cUL=DuBhDihT_faQS zYcJGdIyG-GjM(dQM(g#M5gA?!j+kz(ZUy^3d5^(<1(GyShrhJ!<@l2;sS2x z{NXMA(!h>XS!1$N1&ty$df;2Nvd1jo(pt1x(3}CWc9l-s8_h6D-yK%gC9frgIpUOd z43h`>0%qRFF~R8uW@O|_3E(<9)?e#8s%wkIx1IyX{=TiRD7ifBoccsF+3&f^`qU@8u@r}lZzj(@q~@MwaXgbbd0%<%)MRmphKH4s<27^93j60dHxc)y!UoG?pJ%#}DIcA^Qr<7=VwnNy_@RDX< z&VZvLAa{IF$>RD5BYGL7&o9pEf@kBK?&Yqmh1!~9xU?r-PCoad)Ci(ZV8TdsPrjpakGj%1rwVM8ng@U&3TkS%} ztqAUrHnxcewwfdHaHqDNMRAc+$RF9hJDmpm50#3x4XJ1lHa0&Bsw zQ@#e%a|`Lmjk2{rC^TFN=s5<>7tBXgx6!SBkNrg^EnEzcE)8|Xe@-+g3{|{sr#re(LDkw{_de>YX?> zz~?Nlo_`?U&eU%vY5Pjv&IW-obkR23!rf?$>U$Yw9GjPRW3O?L8Mftza zK6^=h2Snkv;!HH0Sy=B`jLc8YLgtj&C-QU7j?2X3GRdZj-Ly@?_BoO>_sK%M9}{~v z5vNQ)mY-+pQ!1Ematj1i75M?-xys-;J#O%xq4ZSV$?iNp)m^F4{UL)=?LD%)7RSW5 zTe$4VTEbtYrbWKDTW|jVXP-fC$MS) z{jPP)+wx=i<(bRV7p}YfPk(OR4&Lo+dZJ{#Y_(yOt_-xJWPJ6vl4JFx{XCJMar?B` zeJT&!=RQWtbGdxVb-=3)`EyxdrF#;C7xGfHhn~4F##W{2_4~n4yEkFos44u1 z6hi&+zsMR`jIgQS{ZE-i`VS2C5TtY8`fq&jg`<+qc>7=RAvRkl_1%x!QnRh}@gLtn Mc{*KgD}G)3JCZU*DgXcg diff --git a/.metadata/.plugins/org.eclipse.jdt.core/savedIndexNames.txt b/.metadata/.plugins/org.eclipse.jdt.core/savedIndexNames.txt index 7741d94..08ab0e4 100644 --- a/.metadata/.plugins/org.eclipse.jdt.core/savedIndexNames.txt +++ b/.metadata/.plugins/org.eclipse.jdt.core/savedIndexNames.txt @@ -1,5 +1,5 @@ INDEX VERSION 1.126+D:\Z - Norbi cucca\0 Projektek\TheButtonMCAutoFlairProto\Spigot plugin\.metadata\.plugins\org.eclipse.jdt.core -3045053200.index +1508644233.index 3089967703.index 2674037006.index 323251068.index @@ -22,5 +22,5 @@ INDEX VERSION 1.126+D:\Z - Norbi cucca\0 Projektek\TheButtonMCAutoFlairProto\Spi 3954291735.index 994834796.index 3604769962.index -1508644233.index +3045053200.index 3656756579.index diff --git a/.metadata/.plugins/org.eclipse.jdt.ui/QualifiedTypeNameHistory.xml b/.metadata/.plugins/org.eclipse.jdt.ui/QualifiedTypeNameHistory.xml index af0e569..a866bad 100644 --- a/.metadata/.plugins/org.eclipse.jdt.ui/QualifiedTypeNameHistory.xml +++ b/.metadata/.plugins/org.eclipse.jdt.ui/QualifiedTypeNameHistory.xml @@ -52,11 +52,11 @@ - + diff --git a/.metadata/.plugins/org.eclipse.jdt.ui/jdt-images/0.png b/.metadata/.plugins/org.eclipse.jdt.ui/jdt-images/0.png index a95f60827ddd5cf84fb7081d4fce1a53aae0d8d0..9abe3c5dfca657aa02d5841c2ea981d4cbd30700 100644 GIT binary patch delta 182 zcmV;n07?Ju0n!1GB!8JnL_t(|ob8ga3WP8aMEzo|`~z)lEbJ@}EQD04(%$8|l=-B{ zTUbb=iKXDcGVCOqnUFNii&MlHleIR@^CC=NJ?y=gA(+9uuX4sUgpdHNgl&{@AcU>GOa=$w-SU@dgkiwV~CBX}+%Iy_qgTDg_xG30IBL-`_Lyx{-p^D~j~46qnTj-Ua|4IclS_BQ=*+1G-=`&+i9;Kn!BrPfz#{ zk|Qb{oaf~H_nMvhfBN2z|4m!#!EBHiQJP^Oe`6Os8bNH5G!HER0JFA(z7z@Ea{vGU M07*qoM6N<$f?ZB&cmMzZ 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 56554ec38d3e023519caa92e643d159bddfcabc5..c1396b16db1400b72dcd2ddb89cd1d8d13a79aec 100644 GIT binary patch delta 88 zcmV-e0H^<(0-phpBmriTB`!?GULa_|4JZHq$QT5k^)7&W0mLR~z~k};up$r*;uGy$ um;uOuECXOJc-}FAJOj`%Nd}Ap;sF5vQ_hyNKgY2E0000VP`fVOQcgW^&!4H5&%5i}rWUF(1Q8S(!+b~gU+*wIP&zY~Z-Z2Rd6 z|3PvD4FCb>IXVBmW~ct2zPICl)7E-08ze@QW*Erd*aeS95St{;Lkj=^7}N}N>&IMg P00000NkvXXu0mjf(#L1! 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 9abe3c5dfca657aa02d5841c2ea981d4cbd30700..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-2Za0000UNGEp(4$wq#`pJ^%{Xe& lqZfzsB*bM9zV#2Dg##v)*A?fRbWi{Q002ovPDHLkV1gj3SA+ln 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 a6abcd86620000924d5b0b0715ce61ac59867f9b..834bd74ebfc616dcd621c0382db635898e71168a 100644 GIT binary patch delta 167 zcmV;Y09gO(1Hu82BYyyiNkl-z(005#V V-TU27pFjWr002ovPDHLkV1h%LKR*Bf delta 465 zcmV;?0WSW+0qO&gBYy$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 Hu0mjf_*~zB diff --git a/.metadata/.plugins/org.eclipse.jdt.ui/jdt-images/5.png b/.metadata/.plugins/org.eclipse.jdt.ui/jdt-images/5.png index c00d1cba651f61219998512cf05bbee8ed9814c4..56554ec38d3e023519caa92e643d159bddfcabc5 100644 GIT binary patch delta 213 zcmV;`04o390hVP`fVOQcgW^&!4H5&%5i}rWUF(1Q8S(!+b~gU+*wIP&zY~Z-Z2Rd6 z|3PvD4FCb>IXVBmW~ct2zPICl)7E-08ze@QW*Erd*aeS95St{;Lkj=^7}N}N>&IMg P00000NkvXXu0mjf2SI2h delta 152 zcmV;J0B8T30^R|TBmt$7B`$x(UchU>Nq4*d=okc^^)7&W0mQ~_fV0j2ZeHg^Z)teZVU_(C(Zy#t^c?%Q3ebx006K81BbKi;cg570000F`_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` N002ovPDHLkV1k4)X{7)F 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-2Za0000FeD9 diff --git a/.metadata/.plugins/org.eclipse.jdt.ui/jdt-images/7.png b/.metadata/.plugins/org.eclipse.jdt.ui/jdt-images/7.png deleted file mode 100644 index d198a93b55b0ac7c6c74129011c31241e49481c0..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 147 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`QJyZ2Ar*6y6C_x-Fbn&y`Tc&= z29_SjoJpp$&z$&if9GOB5Qm2`Q{zs=FL^eHoCy*a**LcRY|3q86p&VN+rqfD`uYEM tNv6v@Ldv%oW+)cTb$pU3$GU`(;n0TApU=N=GcEuC diff --git a/.metadata/.plugins/org.eclipse.jdt.ui/jdt-images/8.png b/.metadata/.plugins/org.eclipse.jdt.ui/jdt-images/8.png deleted file mode 100644 index 834bd74ebfc616dcd621c0382db635898e71168a..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 194 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`ot`d^Ar*6y6BLC0us88n_x-m& zw}ktcf*FUvYWW-n4`rSMH&Ub-m{lYlHi}PRbkz5;+4ye%=|e&WY#Tkfm?yAJmX!Q& zU2f83*ul$mzDoSSUWTN{CJaj!79?xlF%ythaobYQdaLH3* +
+
+ + + + + + + + + + + +
+
+ + + + + +
+
diff --git a/.metadata/.plugins/org.eclipse.ui.workbench/workingsets.xml b/.metadata/.plugins/org.eclipse.ui.workbench/workingsets.xml index 975f072..1ad48d3 100644 --- a/.metadata/.plugins/org.eclipse.ui.workbench/workingsets.xml +++ b/.metadata/.plugins/org.eclipse.ui.workbench/workingsets.xml @@ -8,4 +8,6 @@ + + \ No newline at end of file diff --git a/TheButtonAutoFlair/bin/tk/sznp/thebuttonautoflair/Commands.class b/TheButtonAutoFlair/bin/tk/sznp/thebuttonautoflair/Commands.class index d69dec30918db7e21e5459e687e69de759182dd7..818baec7afc6ca1586bcf1ae86cc97e771247a02 100644 GIT binary patch literal 7596 zcmb7I3t&`Nnf^{PletW80!$zN z14OZ1cWc+TuIsLXZdJN6uFw@IgdmnuRH$vY-4aN?W)m2yRuC2DB_?>g_~nFjehrNS<+7UmH8N&Ap0HWWn9;ZqwT*^M z!}eZtt>SeXL5gLf-L~BOA|3T;5Gc*kp>1Y18|~r#r;pr$>%7_>ek{Q_>FCe&6!y5KU^rWqfsbMX>o3_$@85(V7G&B>%XgrljYuG>{$D(OlwMm#a>1e^N z48RsOIPRh?cFM+99c{9)tVtPUI<0MmfdXblfdTpxKr~ z3JqNXwHNX+$=YaAa>*7lN{X}#vyOT7v`9l-V3T9D)6H=;$u7HRNDeb=*Q*$y zca1FLI4Nf_8aTc39eY~2o?d6RZh?hk79V#)F71avuZ{%np$arxO_D|ei$@9IXb+4h zWjiz^hc{dZ(;>@D*Av}|47b5mCHcr3OEFWCq}hxm;$~dKy#gWEb_G}gJvxtjEX-v0 z_nFRK88eeFsN3vlY&X^0&2d_@t zxf8fd2F<&v0V-$`R>Ouwk}~pFG8M_GCRo$}{>I^K^D&~|fQB5QMN z%*Q*WIDAOQhw%|AO)FEnoQrLqnw?T6JMd8*e}j)vp*EWKQ2v=&$SNvxth16yo*oib znn~#I@ChG2&crjES%%wn9Kb=w73Dq?RR@X6Q8Tr;^_=HZc*uvpXC4`zr_ie7)A$Tc zOq=_dqef>qS7QAnLIyQ`sKIvnkIKPwM!(MB9_dcJyg@nz7MtWx5huOgo|B zp9R)(AGgaBMnp-rR9VWpJQDABlp&Gsw)XQ3m88jPxBIh97yGGt%B}RORO;t+{0pAv zX+uiX(3z!Sg3!Ol7mc+P>&uL4XL$|Zq}g&U4d0?fj5I;RztJ5^88Rsi-(esY?9uS= z4Dn&pC(*d?>F`0*@RC3uS>6`iZ5mlROtMripyZn#%rKwGTx|1TEHg7bs19>R%8Dnt z`wiYVTx{fsRF$!vVm}OHBttc;=jC57(4b^KgjM<#9K-joVz_@%%a zZe7;I*_+B(Z?s!`B*D5$^9B;K~1vt_^Qfuxp|~{L_-fH5*{u^1>iy>tc?WOV?)1zGO5;b*ijcx9-~gHfn+g(kZcA*0xgJ zl0aD}xp#;vUCa~nnJKrLDQk}@Z_^txR!UNs=f-go-8i=F)Wi)=$f%^ic;!@#XL;7z zldy7G!&%vJZ54^(6ANi;LH5_?y1NN!{H^jP$2NM{N!;$~#Hsg-8WH9}UDUDJHO%eM zD32SWTGY#CW{ryBW@oI6*AiVU70Za%o@g@1i}L?}M|CfKnz)hb?w4!aq>Gg@GkMj$ zQ`SUu(I{iz8%tVQGWjk1io&>;DP3VboW`kh^@c+d$+KI?WJ9qfV)#T;A@OiiEgeHC ziD6;$FlpNKusSprb?xQ-%5ej`js}nUXgFz)n1u}3=p@jwQBRv3E8Uov(YD%HrRr8w zeng8dW{MzVaT{+@F(qycYWMR{`c~~UkX3JD9J3qPc-~3=RAkt zEk1ezl|k$AUhd0_ zxqN9-FJH`yDSTO{UOtf*#e7+>UM}VFx-@Fz0Za;(6raLI`L_8WmMT*tTCgPO9YlMu z#B&OpgWj{)-Wk|&8g~S>0qh*WF13q19_5arZaJ@}C``CnO@9#6)f5}qFXr~UpJmf6 zXM==o5IuP$TmvSvb+_AkyR1tcfUN6t>zaZkfy^mX=W)|GBj%4YVlqeAY6N{Ffj{>U zX1VYyY!0AQC@VZii;oi8Vnu~#v5e)ZWKRHPbp15`t;BSG7@C2_2;ydb%4)FuZ`2D0=H>?hUBL>}+tNH1!{2XG(mXPCT*8}R4sr{P_kw*j-RpwfqFSFpf`8CS5z zhb6lFQ?^1YDhp~wlPW6Yzc(S?03qL|zbn^ai-lf3?75(?p;tWeR z36MjWpsgTas|iap;n+kdwy?ev@8-w{aTnf$EZ)mr?_=xxxzmp*_*XmoRA7QLcHjcO z!WF{=^FBgZ#93$Is~qFuoEm9WOVIBkp)TTa_LETG2H#b(%|oz#ya)Suog&TV!Ru70 z-%rs8vbJ<=Hw}UvfVDoHzk+%EeUsbt%P%ahGhU(*9{RqV$jqQtT_S)eXMt)Kc&o6*jE?$S5>|xk7Qlo+p4@WkGtyvFRF4! z9^2~z-&N&`JT`?M#eakX|4F;@=m>=e@p2v;<@1Lp*l-yB&>()C$MR6%C#nxyeijP+ zLY1$V{a(#uM&OzD&?33Dyrjmj6g6ama8x0U*(`qyGx2eLojyQM9He_b$#{PVC-GSf z;t=n5590}Zj!rwwo7d;@EWUtm@{0RiJc5^bpZy_@;m0`66Z#3f%2BW56yCsTT*06a zI77uaE4+A2lyN4BPss6zOB?z|#iiidB^+Bzk6m#~#flPk~6*MyjOVuCU=PC0R zmHOU$MdY{vO(%5?4>A!hElrvn1=b7r%Zyc&0_RngC z*ahP8Ri@~#QOPf|=1F?(DeC#tSczw-+|QDe&tVtut9$S~K7<$OsmnzB8*21&1|18Tp;_tU<^NW<3?|hsUEVV+C@c*5-quo zmdJydORN~@k|-Xjn^HX$`2jJjEnLSWTp_LtlNp1;ILPp-5DTOoQux_G1Rm3w=-dS7F_n?P6cGnFNkiZyPqN7O;!CxrN?gy3gP_CLpb{DMjTRrdT9n(!Lc`E`!@ zHG1$H65$PM{cjoWR}^H9-X9r)>FDbg0K)mCk7?Yp$LwXJ>G+E$9vZ)W%M0Lrh)FT1ldJ2U_J zzVH9dY+m{J`Cb6C#AppU0#lsT;nX#W&akt}YDqheoiNjm-4-`v$?$x;qr*(JrZo5j zhFxW@F~e~)(H?GWxyp(<8uA4u+sXEDOM3O{m=lh=uV=f}th1sVDk+eEZY&XV<_P4L zm9G%+&9_^vLgb>zfCgP)Xk9E}HKaRQtmHDYC2k4$>+Gl*UtuO=^4Y8OIjdqRfz#{$ zkC3Yc3hacp0D-o$y8j($la*+-lGUepqq?qt@l8%LmT0fO^u((2l^R9}j2SSKm2hHC zS9nR>?6Q&t7zKh}A~5|FE2uZSTCB#lwm30y`xzL6fI#8gc-*ZZ2qWC-(@rcNUSy_L z)tjBwMet*sf$^9iptW00gV{kSN0ybJ7-}I-!z2wsf#GUp1IIBi8B@p=M-Z4+HlVZ1 zd-cHayehf0(+x~RsX*RBDIUq;383jH7g$!4Oxnpvu-Q%r6PDE)bnM{TWX!RGU3NMd zOsA}5f|1K=YBHF#T3cfdi%H9D4Vq3coD45pWzADsttUv)q}k@kwO1IZ#B_n86bY@j zQYo{Y>mN061s-|jD+&?D85(8`(zV-aV5UT{$g%6}wN`SznW9+3m~G%poF$;IBHU8J zO3t-9&ZfZ4Xw>R-0|L*}X(Ew{B0wOFj-LMF#4l(i(DZjUAE%~--f9qI)p z%{7Hwpdmon6jM6flM-3hz2xCSC}qK%MGl+#S&f>C-dfHT%I5^Z^CLhM6-dF zl1<&QU3PU`CQyDL6P5Ba<5E;zjAIS;Mt4!_D^0oKRWTxo>=gz+rQlj>b=YgXq&xvG z9j3q{cYW@FF1ysX95_imSShDU$v$dw$xPk2oG%z=Ac{@CX{Xy)$$51|1xk+#^P~f+ zAO$P~ZD?oWFRB4z&v&Ev8 zd}gv;`qoKi=DbpQa^A562OBIn0ntfGp33}Bv`!g-k{UCn$uXm=>66}WqA#$QT5;Rt z5+Zm>pgii!))b;Y#}U$*7%Zi?vrd>u3OL(IhX|8u$#ZMyUYhJpo&7xH{_A2aZ{2a_$WyB1pvd<9Ps^b0JfZwDQd-4_+?q$18UP0UVk z8+{T_Yj}!VXFvM=?FP1D8x4gUR?<|*o035z)q3?DXFHzN@YO66YMyMXfgRY%tVmev z2*Th!+FP^izstaGsUwX}*}zwI>=778lX0cX&C?ZMu#FtMekIUj;Cbm+MKV*peXsy8 zpjX3-gZI0xlw)-m_!{<;4qMVO$_1LDSi)nDL(jC#j%pnT7=zlkClyLt{f2brZysmJ zC*jKV+KuJWsZHvz<2RFlc&y1IW_C#&P-nW)~1fIebv<(-ps}`xP|OU zR0WFrFp-%=OUY@WRgLMZ9h`e?_sO#xQ-!IW(?Qe9?MTs?g(VLuKQr)i$*3=uYV6eU zOP*63>|{%9iRHv}{K_@`Awv8Tb`kc zNHUpCq!wFUI*yP*hTsMqOxO;&PbXRWJiR*%s$#LI{HiA%<`_EL%D7 zcsyADx)@5cce{Igxtw@7S1O@)WgaQS8)(+WNPz&)xk)R?L#V~|2Cb}=Q&kMLiN~m@ zB^AjvXTQ{{WL{wsnat&19>4Q6-uaQmYXP6aybIp*LVHlSgM}OzyymM)14CFg+!s)c zp?u-9a3yxeU&F*1Sp)Q6$tGzHPbNBm|0z2XH#e!^qii(&5KQ zj6eymWxUSdhu}E~@B?EU?q!}lgdiRx+fQK%p2bw`Vc!?|5%v~J@ixkF7$LlaD!fPD z-)HY5m`Uo5B{M{n!bT_6SSAcyjU?svEF(?vJ)N-( zb4zfz?o#-VqC}I|sTxKd#S9H$!!U-NrRNMO)pH7tKzs->9);4%JYA0B&{8`;+K08x z{;oavbX`R^)^EfsJMq~b+$69Mw>9s>9nBScaOWO;p+1B0)BX2$QmEHJKbHkxyhgsOX7hmo{Mj(=xp%kg^X9T3`*==ONccR!2VvMUfE#M1idnqY( zTO_+aC$Q;QufIFu3rX7dW)P~|iG50qFHwz*`Rf#8Hx7mlqA2A5wh~gsb9ils#F(dn z9drg)C2dpzu$(ZgpiVB~Q#1L#l;6LXV>Yfp4a*I<5=&u{mng19D^Ff+*noB_XB9TF zehXWkBwO3b(hf4Tlia*ac3veP-zOVyqf4>gi6RNE;t-s13%F ziuJ{u%Pq}jTyHD>S5tjglYbwhn80x){~M?w$-l-3^6_Jqe4Kw8euCFIvQ)zP&_70{ zhP4`QqXv#(%rVZAPigekvG;Z$a*P=wSP#t8@WxS0=Jg11DwH2Yu0+HFM(N|Ij}h9@ zp&tB{T%ec*x|RPIPvFLiUf*UI{=@a5N>a0`2{%8N;hR}35 zTSn6TH$}JfWS8QF1Q1xyl)nxWaXr)g1_E>=p}Ga@c+6do+u5=KH{nj)io004o7a1A z9|^vnzYp?+zL{6)=^=OV9)*MfGBpLq%*Wq3Vh(${rCbI6C>Udkk4pH%MMXvVn(qko z9F2(b)ZihyltVJh(Oc1*Cz1Pyha3~5B9Gwxa}y>hX@4lCEo+wf|Kr;2ac|1KqCTYF z{fO^Y?!qzmJwl_ZM~ED^e(Le{K2>NwMa-!Faf;pgxqbEhaL-ZO-NS_8 z5xU%?)aPc_JWi+Gf?520I2%vUd!NKYy6xq7n)b7mz;9#AGxXf;3g+2r$L;Ndxz~fa zpbzF*eWisYQF>vH0^En3q2iQBs`mJ&s@n_HZ%IG?lesOQbL-kWXOPP}#y<3c0EFo_zUx`m%5K^Ky< zj}RmH)Q{Rk<{;3+Rqf-fFJLsW7>8a8c0V2dr2&yl>x*QXhl5}698vOL Dn6K!f diff --git a/TheButtonAutoFlair/bin/tk/sznp/thebuttonautoflair/MaybeOfflinePlayer.class b/TheButtonAutoFlair/bin/tk/sznp/thebuttonautoflair/MaybeOfflinePlayer.class index 4d8f97d1f8505dddbd5a60f4edd643e12c2cf0d6..2074d8d81dc55352b83d0912b297335cec48b7c0 100644 GIT binary patch delta 433 zcmZ9JyHCPU7{$-M1f=!iqZTR;73%|OMSM@jMPnR{t2!ECXkr|UvrNXBG%gMfI49a42JXcqj>UaAJdHe(a9L^C6l6h9$6C*5 T(Yj6s!7I@tgv)Z1rNq`Bq!%>P delta 428 zcmZ9IyG{Z@7=_O)VZ*NDg#{J_6~rsM;woroY-}vFCYD<%#uyXPQYu>$veClAnD_#y z0TM9A+PCmUjAs@qXOg*`Ip?2mrei!A=J#*^6F?Q)E%T-I@mxs?#83Te-@9tm&%AyA z^5oFJFp+>Qkw#oV->IM18@mPsrX?iCgFE30JLrr1SOP_f1uOTE4Lc5 z9Cez&crH}H9XUrqkFz?BIz7z%k3_?WRE8!gXE8^ofjkPM^bIl8#pO3-oG#`cksCk| zVClehI#^b++r?_lZ4Vu5Ul45uA|Y6oXy98+;#lly{z3ss6k&%q+r#46fS#w(;)6HI QAW#WQh$5F&E;VfZ0fz)N#{d8T diff --git a/TheButtonAutoFlair/bin/tk/sznp/thebuttonautoflair/PlayerListener.class b/TheButtonAutoFlair/bin/tk/sznp/thebuttonautoflair/PlayerListener.class index 37ef241c55a34ef7efde9136f0ccdd910bb2d2f2..d36288adb1e8b8035c56ccf243a4a4ae911638d8 100644 GIT binary patch delta 1277 zcmY+EYgANK6vzK(?wz@JE@v9N)B-d?Ayy^>EP1qST#FS8Loo)aArQ*yGIOEPVW61- zA3f+n+0%-XW*Q~ENU{>J>!4xU!-^jEPI}tAzV)fTWUGC_wOr1JGyClG+xz_YKIhy$ z1v?6~ss9ch22h4SN3~vA)liGe6|542@?xnD0Wl@dm+BVPi3X{NEfeX=T<1kiDprsC zoYyng6&zP0I6mOo&RlIMR1gxyYMI~UXh#Qwrz#XOyOUin{kWCabKwRppWA=+%5v{3f_r3 zIdai|nm$+4(22V_w%{JI*S)OZJ_bkS0^9ij$Ah*cHQ6=0pIyX591o*kaIH0GJ9a2| z>}*||5=pa@<8ka1{n`T06I8(x4NqdXf~Ul&mQ_Av@2qr_{A4tyLB}&3&!T#^@Rdd^ z95q!uPhq7RB)q_}2P5K?me2Nzg=v|tmpNX+K2e!g9~eWGf^mk-Gi`~R?NKw7EUAf@ z(XfhFDNUJ*1N3Jom|*apL93%iB4O`;h~qU(is`gA*XuZ{;E1T=^QAZNrZD&l^=*nR zSMiS6$1~Lw-s70U`{FpSb$y8A3O*7!o;>Med?Knn{tG@MxI)Djbi@fW7H%*?>rFbw zugHC|hG~4G;A=7D$;$l}9uhOtgkX}W#<&qO-E1Lx3(BrC`C4wVjgmcE}xA-9`b2M(P+d~VB{@F6PhV! zF6LqlTBy6FaG@0|AmeHxIUJ`@te`|eg_|O-!CLXRce%3>*Mf<^yxC$+y0^)gKrw@b z$|I-<`1WIYebF&!WQ2FZrQc9rXkndSE5`0*KN6!|TPbwAkIN-M5BgLHquKcRzW@kf~epBvO4XlHLiYPOLt z2^j_tkcJb!aeOyQ(t$zj2AdZD&Iz^-&>`8sk(r9=i$d@1NBl(n$j4^C jWW-U3U&(S}2r7QVN#g9obi?tF{phAu%Ktk#9QfmZ<)lJ~ delta 1388 zcmY*ZYgANK6#mYTxZvn8GtCS%&;!d# zdPgVCOpBf*Sqa!UN*X=1vV8P@(bFE5t^V|*{?uyU!B#bE&6$1n`Sy3dz4zI(sc>7N zdhoA3`v8>Tml3twmZzWsbsQI>mO)+~H6mWU(@;?luLKW6;Xr1Nv#Y}&^yvN|$1*f9 zWL1a5MzF0Rp!XP&MgC}*j3oixA7Q8#TO36*>sRaDdPzVJc9b;6BK}~<{4<+mTr!q# zznVEN9A|t>66$VI0 z2xSavhY|A_(Wu^GNVrA}$a4w|L^)#Sp+bjCLXl2ACZn5yRjG)hS3-|CDxYe-4%dt0 z@)>d*H*)l0t(c+A)8e?9V;yc`kh=9im$9r}oNdb&Aw`kHxQ$~j){C{utQle4&T$9s zWN_%IN-z|O6>P3Jq+}M}&0wj@QxV3!9QT<@Q_fFWZWF`c8rif1{t<2mu0T9Eq!-EH>Hh}49FL8CS152fNqI7Trh%G11# z7f~%CA^OwiIFrOsCSwo%=n`IH$oN-xO+b%E&8zouyo?EPByFYRRlF|YHE|x#vF^tK z;p4UQ-lW)a83!4(x|&sb>;gS%)Py?2p`a0rsTjvQ9EWgN?B{jLQM@PNU4|U-E6=fW zypIn=WxD(PkBFl}#wXPNsQC!>)-?vT_%m{!t6~ygO8DZRN~K=l;<)*cC^e3+#E$gS z&0cInYg36~tk&gn}5ea;_42-<<(To;Y=*^st%W(x=QV9pHL@jK%ijW+ZKT#o} zL_&okiZipt9~q@-KIjz9uoA7JJTt$kZ8wS;5~!L$g~vszyhR6~lF_jl4sDIsnLwx8 z<{U@3naqgQT(qtPu1(;EByQS;TZ;C$+N=)BMA(imBdpXbMp*sTnP+o z&nK~ijGbQ7yNkS|n5pfy?ZtRsvsH^XCb5^%&f08sHYV_j+h*e4Na1FiC<48e#56j4 zdkU6qBm0QkZsI;99Hlp`eQYHtQ5BuU*i9~<3Hg*DL*O3L@VRRYUyqPn9dB5>k3S$3L889(6|;ml?#u>6ie O36nDM|4a@GPW%nE0cYp{ diff --git a/TheButtonAutoFlair/bin/tk/sznp/thebuttonautoflair/PluginMain$1.class b/TheButtonAutoFlair/bin/tk/sznp/thebuttonautoflair/PluginMain$1.class index c70cdcc178ffd1b113d7cc62c83703964db301a4..7d254d2d5c58ed4d804040229649338c57f1cd8f 100644 GIT binary patch delta 19 ZcmZ3?x|nr?4ilr+WL+kEAeqZ#1^_e`1ikBh8_HcOLqp`j#QXw!wXXYMg3dTY<)70kEBHh5` zO{U_VOr_15Tr?PKt6db2N9|w?okN;~$<&fPA-gjbiN~1A@le6`}fYxqqsJeh{W0&2DZ!x4RdZN8i_?x^O-#5 z6&t{KV?1mdRLV3$v#!^>Aed~&nm#I_GK)shaHhh!dRh@NoncWiS;Ao?X18>8wAzVv z!PY3aDrt^~g3%4ZL`3Sk(MKLC^U-)Z)1V32Me^liQGg~g8M}hfE_>AurcvcvD)N}m zicwZR%OZnJFr8|TKtyIdwj?Gi7130xFsPhqc%S^&b|+JIheefCh0VshQaQm#;C8NC1|x6L5?abMG-0<1fy9zsb}WU{n^T^@Nn2WLvr9DOcl9IMP_e!7^o6w6 zpfyZ^y!{VK*`jr{o~bx#0|e|4lnduFwcqZu^V}t}!?0OdXQM@%XfyO3yIh~dxiXE! zvF53|WAZ-QN*5Wlt-l%QK8rp=+o6#OyE7UTXd6}D*f=PO3n^$(D}}He7p=77PV6ZO5Pj~hL=X7Hjdv5Gv8p)PKe?ZGS4b%BsO`5k1iqD^C*Hr zRhFM7G|L(Q<~&?j*AA->`zTHcAqG}P=kIP!S4?AymVKPMEZQabSAaVq0SIB7-N-!A z=Z2#T-6eTl&O!p*@z~->Qh-W?afL-!3dN$e!Ckg149gk2(oVIT$j-+a!CAEoK0F{GND*?ZuL~uu{R@6s~s&-a*=In61Hh2GRPihd{?he@A z9q&qP@5s*E9t(EZ+hH@cHJ2pgu?5jcM1lQUb}qls+NU`M6laO*U|MN`B_rB!J-@K)3_s{+cIQT>m_yw zf;^+V$pOLKWTyvceKV9N983j$bSv#M=r&+*zg3)pLicvS+Mvu1G9HBQfX;{7Bhhfe zjtTM4S+t+-WU^e|H2X~D|DL2C*&zG7%c8sK9uSTI`hwc@M`dkS-?dF{JMjGg-Dl82 z2(9lX&h}dL1-c*mj@f%4oc`9I6U-NJP2=d>eFY?1@JB|pE9vDh_ zQ&WX*`G!Tu=y5QR>}pMF281wQ;KgnlY0 z5VdWYKy#d)v*%ZId**V3Asoh6JD_B7ux#a8Q6(LS7*wgmjFR0 zv%IJadT1w1`Xy7XU;&_DXE4zb4BMe#w}yh8yIU>RP}AAoxu7d)CzA7g^dem^Kd)N! zYx<37MQ5iiS7Y^{s`~+JLw{eS*DQKn-#w|gW7j6V0jQf~(tk081C97^xm$kEv^bx3 zV|y^M*1ojMh98~piuP;IKNS}=O!_0JYpwi~MSrIM5t(;JBT#zWm?tyZP_cDjn@N9V zQq{OFw$j_;UA}V?WV!Y-=<5H#>PeH{#dRHv$ErIMb`l~r>3?AzU9p`pK%pq!dltP< zy|C)FcFI+|6@#!hkh#-osn`H0V76F^Y8vgqWDBg`)yJvBO)f<1l0+h&mc02F;aRV{t7{$DJI9JvYWM45aJWS{dQB-qg^?BhC~V=!WoQTc24QL^|vM)Xkv zw{VS^b~3d(0X`C`?!k>S?^Im90A^y5xfai31fWB4tv1CvyWBWT{4m!hMIL<}4KnF` zix&zGm0%KBLLib_5(~w{2z5Ah3|`7KUKB6b84R`C+C7TLlC@gQ z>k&{V0cwmOqQSMz3t0m#%jl9|5O~8Uv_|z+d-K~hUcOVg9 zuZ~J&XYm%^inwxNIP5eu?P#&>u#Fp|aS&LmIF;``ka|NA*t*E#kMMAulh!pTB;pXP zEFLJ#3|DIH|AT1A;;@*grHL-KLlMn0Zvpmmo5k(osh9xJcFA&>4AAj~g0Yl?>oO>6 zaR)=Rg;3~V6c*pl^KoIPVv8vp7Incr(o2{U1(>n8L&p@yAF)2Jis~6A@5)tXnhbPu zduEyZ(Ol&mlP}LzW}AFvu2N_6Rj5F1gYXYbz6Ox^R60~{@?MlGo=T(bI^9->womGk zjnb!dDTvaIx^x~&H|f%Blx{(`=Bf0#<<6Z}8d@tQ)@B!Qv8g)+UH~2nG7F%|+cCh=<%)6Ovl0ZdMO&T?uC_ zKEm+UJ&@YJcaK~MC_;!-V6>G-C_Pw4A%VMr34ZjYSCaf_eirvS+x zbQ()VQb2%H?0Mjpkq6@MFh!n9pSKxNZB`?@JMBOu8E}2In!v(@9YE9@2nO=}IizgR zkf-+x0_C+`GQxHEWB?ijD{^)r%J#Iy&q!tuxtv&dB@7l!4Lq*;$JfYh~h|cJxnRl7?j)0Ti#f)#mBGlZw-FEUrtxNFQgse zb@LlKl*@Or-A-KR&+~s-{5!#2PcR&o`tL3NgMhU+8TqI!4R48p{%JtK=xU-Y{y!G~ zMdN!UmeO&X$$tYu5hUinWAWeJ8`us4tqVeuSC`GZ`Ss$kg9nba7OjpaBjQTIX54GG zzZ7u?b42_|(N$-TfV-zNjv0o8<+@bp#Jbo>7qaXSLH~?6&fiUyS2`Nqf06t&epXuZ z8;Vt-G7V)wEBYW3{-~vjM1;lg9a4C~kz8SSV<=|;Bq=C{FzHi6)G$L0MSfe7N1efF zhn;9cM>312GP1iiuCp$+8{>&+xG^42ge^5(jexRs1`|oUubBzBIS`GPXi#pbX#Q}E zGzfd8mKv$boFt3r^P*@xw3BHDE{xNmmYV`%qm|!KXTbUSP!laRMvZmu4go(2MhPTrN%g_2uBoY!i{c$osdr3O4j7Z{EqVewB!jC*OQO+zQ{vFVEJIah z!xwm}lHfGeG&t`1Doi@iXNPN2ds04Cfv`qZs9H-+msq#Z-UGl&8fs=X2mysfT|0Kz zxM|iPYilPAbq;80J8-Ex?LIY2Xw6XPBDJXI0L}V*duN2aIZ%jS*eAp0T56uoYe+I! zUSy$>n@x2-@XX=V!DY>;sTP5tY*u%{;C4jXoE^+ki)FzjnAW$TY+5h349f+?ew!?{ zTp?EQAl%WfKJ*SW*1C|Ecf+|Y`Pk_;nQA56t56r-Hg-5%3KynYh1W0x&s9zm{+d3n ziIA>ywopH5$weWq7@=aS6#(f5Ap-=Dey_N6csTHv7mf7At__BgAT9rVHYOzX=~J8J zd^RCwQWp(!y17wmyU6om5IISncwOLA+f=J`hx(nbGgl|KBShxF)LI zQW5cHeU2rxXkgr?c3LVbmwCZ%;SjXB88Xxbx)mY^GYj)fWAkG&xvF!SHbg24fyGcc zsG6h=^p=#fkEW_CE%h;RABy4dWy5wcy{j#Cjk*@(k-dam*2M==-$!)Q2KMxdn%ZSt@9 z7?o^3LL(oc(GR1l$dBJb3?jOU#^@G84ez|&i3>1BdWTdVp|O>o9vb%;P3oIERC6^J zeAQs}v6_T%feAEO^N9}>a>Txmak7i{!!)I2T83&WGjz^T0$d%V`C#k(%A>T8=hCMw6P%nH0=tfVcFP>7~c8&&H)1ROryJ#2wIches1D+K9x z(?_*XF3as}zAGfFhc2)54lbivpm+|x9GIOaBP%DPk7a3juEq*DL%uo9dn-$>%Fs2~ z({-|^PkJ--sgj#AbW6!+GW1#5;pgkUX|C~mkJ7zNE!D^A*7^c}fivcT45jM}v$Zcv z&F~u~4`t|U@^kp&I1hC_~>A@)kX=ew3!-dS4IyEJHu9JVq~WE_wL~ z{mNgMp;t2WpV(!|Z%f|H(CJ3yjfrDFE07Z12j%1 z`-^+%Z$1HDI^*o(V*2x6EKc)NWDUBol+HhVS&c`mi`5(;w@*}NW~ zF>I$cwy7PNp9n|ra``HX@?NASZo;b76x?R>lyuf)XCC-Pz*!6n$^OeAH2bV#U)co)TgC~RY4GF|BJ`%`kZA zSUmCO7oS$04NeO2oWkWAME?w_7-(C3j4NS~JPjtu)h*SfJfoCnWq5XVh8ya=_+21o z_zV@5@}e}Mh^p6L(8G&iklqY8`3nz$j-x+QAUUEg{O-~)a|VEB0zhUmU}hFwhEH2A z$F8r?=XZg#zI%S)gj*m-+)vcNt9UieZz$FAg}er|0du^T*8y@TQ-IfFTmfjwOHiDo zmhzdTdhsDop({|XG`P;-<&YN9LiuHRzldMCL3ZFN*gdMMhc~R8_9$ z5vlhvZmr&2Z)AAKSD?sGW2W!++tM%Nx%tVr-)Y3N?TsfMJ{Qlfw~Pm-;(0Be<#^tT zrx@zJcvj;1RXnTkJcj2qJfEF5-#m`zFZ@O+M>4$gPF|hnR;k5xZF!p4N$pZy8=mH+ zQcFsWwxoHE)Vg%7JB0KW zFXfx-!PA^mj2TzTx5}82{sIq95rB@0;Ci6|^Wi(m`>?;jU-%er!vp8MF9*waV96@I z{mO{sI#aedm4}0;*;Ye=&_xk#h(1 z{#^V6#|UqOeiB^|bH4$8%#HLQRk!Of9F!)k@Si(zmqrWbh3l^gnAo2p}BmK^uP=b_82PNx&4g ziINz%mkQMyZCeG{gNGkNTOoFlEj8szcCK`Fu5@><^gyokWUlmVuJl5#^a@?(tbtve z!C&RC;TuJ<>6>UwFK#?Di`Rg0{U1iIA!bPK-&p<67;9L)*oQH2f*x=7;zsp-K&QSQ z&gumce$aF(;;-`|2U+kvmeM#i;V?g3snsOIj~(ZYfVJkTXUHshGfm#AlTq#4R7&5` z=Q7Hft#?akE!J0?b9q^$PS7~8e7>+mtmVDGCM8wxV~-_=hXqeQEM(YIQzGRL?zASjM=x4t}i5 zja~v0(%hJ!>~iBP!*cz(vHEdiWw~)E!dcHQbg=jOlT^71P%0YW)n4j#@Joqa!bSTs zjig`FIQkVrp;w>@uhJZRCew)WYI+Sm=j-^M8;o@ML25X?IVvOlziC3LbvoiBvKf2i^2c3O37U8;wnwW zWDi}TsT5&Ht(uCDC%ROMu``ECF>i3GSW28D34Jx6%1Z?pPmtx1UI^JR_#n_g{_|x0 z`#csK4gV_uhju_8MlkwMPz~IoLVlMT-zDpPIJb=Yc(-lYKe1ksycWT#;-YPYiI z9j4KhM^%Bs_j|*gvQN=*+Ipzu%|1xep*x%Kz>CO_T}pi5gzn>1G2}v;e-E)Ai{Pz{ zyGR00!LX5)J<7_cl8hSFT$NGd4mAsLSsq!3TyRtZ^&=57Zld7`Fh+2xUdV~BN4hEi zk6fLp0(u1x_k{sSOss}SPDN@WZdoNTLrP83o1LcD0?UUfELjBc17ve~DGi>W*Ai}v zMVqNu%3)M8`3(erZDN|sc1f?DmIs@sw1jec3HEZ z&O4@NY(A!DIjysgsJfMD8eLtg&eQR0z1Q!BvkC|1@o5>=u({=#-ZxR0@6cH=C>^w( zg3i%F=q&7`GcU^zcx-gI84qrjN*L|McKlw?OuyGV^QgMOLmRWSe$&TOb04kxfwact zXbBk2LRwlakk-Emrys@%Oy)HRM#^E@5RaDE<5X{uzbNA`Af@jhOJ_lj%bQpCV!rD2so6n;wxdC3Agf_Tq^J8#=Qm$_y^$8%af4X)ayci zqn&Zsy}K@CH`E=sLBeZzm5ztfLc_+sPql`sFckibW9z@D^j~DXM^pM&CuggE-J7e9 zLRG?OKokPz^0BZkeA4Y$7t*Y75+I|hV``IQBU@HfX4F=v3RQQi(3BN94_^{5mAS-A zB@!=vX1C&)+6H^uw7JrIM1ACl3N~v?4QrpjB~3G{U5|gG1f`GPN#b8<&uH4Cs?E8@ zVVusznNgQiyUza)V9p(VR{7zUIr`z2`8S)D+!7&Pp9rX%2ellUGmixBX+p43jBL&@ zzJ$i`PW%~B6eBxm633C*>BNjAOeBR2Q5Pk6H+AzKx}3Y|v#1~7%Mg%UPG9FM=r~^q zGq{R=gTUo=z6SU6l{meIX;0;?5@{pE_sGxDpfHR2WOMq+zdg@zpWJ> z;Wiyso$68?dIC3|_=*bNgpeq4%E1eThq1XcCs=1R2ybonjZ<>Rk z@K#-wt3IN3LF4KRsw7xF$4PG@u0#x~cI)J3z+a#pG$X5Mm-VPCa=HfR3|BzC@l5YC za2HjF)aO@Y-K!oFY|cwNq9>bo^n0QIo`!8IwasY}52zHy hcWGQN`1R(G)29t@;0Ca*)Q#%Xcp`m>Ka$b^{twkWzo-BJ literal 13121 zcmb7K34B!5)j#KDlJ_$6*s>sDGbl?IlCTDxAQ-|HNx~iktT@TMBqNiVab^MpH;P-` z>)K-LE}bscis%qbMWwA<_iAfvTdi%it*upSKdTnW_doZ&nM_Ee%1`s|dd|6Lzvs^L z#~wROM67+4DiEpcl?FvPz;vH5?S3DjL`MToawxBN%ty&%IY7c}OeSwfpE~ZK0 zXnR#l*S2kecvVDARh{SC?yEWzf9$19Mtvw2_k~(5rfChI3Um#VD;5t&nDQGGxS%i8 zUbQ$J4qCntCWkfnV)3OrTdhbu5DqaFW~@pNW1V|_ct@x%91KTeOe5??UGYG$s?it0 zbnd!9d&n2>ih{Da17{axKwKA(214yMgGUwuhOwYE7zhR83z@P?N}EA=UD$8wl+QFu zk*@Hq@WncS(@l9)XwqmJ$&|A|ZObL5F(!G)6bb_&tEsEA#fq-?wFE&`UPHLm7i{)L z1JYN6ZpxxUH%*|Eb()w$lF1*FifIy)zTFq>vR1V*jV{?-nn8Suje_}9lXNmbbi5+~ z78&8t(vV=vrD;^EQwh_^e*UlPj>WA`lgg+ZhYfed(~J*QkZgr`T4C;+F2>rf{?+u-b|Tic7q!OWjmOGj*B)kt>V?L7Fs+X5&l| z!4edSmt>sC5m0Hf8%LUJQZ>zkaNDi;IxD)}ipuKJh73iuhig1^8rA6J1rrBNnzVpU z$LRqirSTzOyTCeiAS_4e2P^{6MNFk9RCQms6>SKBp&={kriE1Kp~bXBr#hySGpHE~ zyh%%G8Po8n)h+;{OSfC0IHWhfB=eA#j8>&k)MQQ#09sSpY|siO?h@{uY0^q+faT!e zb>YrVU&zl?JruJu0k+yJ9p~We0~eaWt`l& z6SLq1tX3!&h(WGQ1rTe7s@o>-rY!`Qc=kXu zP;(}oLtCMdQ7aPkiEA5OQdc)5h&ALhsfAjB4g@>sW_((fItQo`Yqd>ox{Lp?G;L=x}j5UgDzkq;p0WZ zv5T3OWS+dP!xvp=o!@04I%GQ70pmk*bvNzN>GMn#C(y4(Uv~>UU>h8?wK^ykXVRr~ z8SK5*@3#l)+nOxPZ$ZiHGU-ZrloN%k!O$V3-E@UXSJD>{qiP*VER(niUThYYU2W1e zO7q|-{o?Lr@H&&OmynR%8VtuE%`bvNTbhVZVaP*-DX?!c>1Kg#*4yI>v_ZE*1nCIf z8VJajkR ztJ6I=tXiK6ttQ<^_d~xT5+dN0`hl%#InQd1XG+=`$&|4(q|?`!PU_!l%Vcp^APC(w z=<6`PrO{|OI?3&(eWH;2=vyW|K;MRn`yvrbJXggK$TLw5fLS9TzGKouNCw zut~Y(*69)O<^=kd3Ic)92Kgwzrpp-oAh`32f~aT)u)2u=mC)GopHeVC%vQ7 z+bJd~JgHfe-lczuIIW%F{J^;An5G=@-zNPZJ%c0K=WBxS#h3g?($5c=re>SkAdAH>ylYpD@5Jv?esjo&(Rly z$3hSNzPQiL<9VXa6ClO`2<(Ld_hcm8nJSm2bBOgd22X;Sw00nrM6HkjKh@;PJOzSr zXj7CkmHcmzYGsWa@=b$FB=&Scs8Io0W^%c3R9!_>)@U$pMy{5yzuVv{wCa~Pd0{m? z)8ttUMb-l$zqL~?Z9`sg>SgU*ldE|i5CyGJd%Q#Cacbf;0fO61c1eAGsTx^e^69(~ z1jM>pVu}C(3~mo{-vamySzRlcEcOq*q|W3e5*=Lt)+tJ}%;e>~0$u<&-1_BCsxxH% zkO44t1H~H`ZBkhgmC!P_YbNIePqQMoOCs4Psgb}|)b02+!M1oT{$ z^a{5jZPkWisc&o07mMk9(SY2@#;4QsSd~5%R((Eo^pF)tr6<@Hj&@r94Qm_Hi*&ve z8mHJJYcS>JJ>sPH@D(Os$zOmM3?qZA3y0uxCG;|lO@&ftNB-md1-;l~Y20=3UM!pGKaZg+;x1v~lbrf_&&2x&NGQJ9hB(J^dE!1^cPzOLslo4i+SI}e+1I8-L$OGB+;KWbkF ze+3fRuzp#^d^g|0cj=7V!UWM8U&PniVX1%=4#lceUbg`iwiwcAzMHAW(eC5$4MF(e zAvfPEvHQMM>>daM4zMd4gja)>p^;8z9i~E^vTzkj2k=3>#sV#X`HYM-gCQ_c+)35p zk?iodO@2_4ooppX2-^<*PR5J6-WGn?CRk( zLAnE=+TiEVfzW*Lfd>B&)_f$XO_tU5IIjkQwHR;Z!-88e9)1^X|++S7`bWjT9xP)3u}rE4L9wni=ZLJ zM-tWRyCYU{RadcH&q7I1I(9h(D@V}83fOob` zx}flF+qbDPN;*L@E+W1=X#YQlQ+TjWo4US|04T z6@{x>Fx7=@s?MzyXrpzlFtu4-GNgp%YlV%O+DRI+UQZyl0eTj#^Tm)9xJv3uH@mg5 z+IU?Xhw{w8P>n(}u2CA&UF2e!!j-^@$r=!(oos5w;!Co8e!uijF|||00l8v7#jV-WAIL>`T*-ZMmG;|v7>PkvB#a%pTsKuK$4*vpkS@HdfCU5JK%f`S zeZOodB$*F4DQ+#qh4*f4p{Xqret8fU;&{J`t+cu^&hNv_;?M%2$gS0BOLc7to-gF` z74Zc-t!O(YVkyreE4!=0s*Y8)F&qv0>%!rv-_(|A%b{5jUo>X*4>L6kWg<(Jd#WjI z_-sfZ_ByTJ)Xvma+BX$Z-o?Ri>o%sDi0q#RT6znBHEOGLtqB+J&$Q9hR%=Md#ghs! zrsR%n879d)!%eL|?(gtb;@c)L^g&GhPy?{cTz1GH~$DlbwR z+h0*xQ2xo@SziC#>u|wtwWN9m;rCbaD#e~5qk80z(K<<9tr$&$f6KzH#)Wz~>iFu0 zgV#5FbEUkfzIX@3s$pnrG@M3Yb_9*Y$S91IV@&>edMR(yK`J;vC+$a9qaysx!6Kp` z(pWV@=;4*o*|-R6WOi8DK^j+<)kEVSrBnL14p&r-16^kU`#1$csK5rAtmwp(a0;0A zE@;O+gPR|wsd>|rR9Tj!IfrOIQ!gz9S!a|TqS`Df%UhnL`d(_p(5fV@w)^(qBsGtm zI*JlW+MJ|wHL>& z@wy(SlZsqfvx;1JZEZUfY^qP>9potA&QZMb>l$SV2-@wVfnWP87vhoA8zn2bd zf;=8==%t=bfc;n__B_5Hd~ZZ`Vlq7msfb{2f(!`%8<4?7no5;;nysf2JeifzM(D&j zR6$`po8wv8-P`m>;ch9Zgwp<}+dJecc0;LA?iP~mtIiH`AgB*U#T9n%hJ+Ogr#*7oAVHpnoUD z=w6CLBfIEv+D^Zwo%AYo(;uNQn7$>Y7*McJuU(~?~3&FSxBL#bCU z((}18$urd7Ip$@P210&Xkdh8}K8kjLxp;k8L_E)$c;XT+Ls6y-SPz{B%-i;5Td z{5f&g?jrYL*ZpJ`xm~loo&@Q6yS$zvPd;zmM-v1KeWR;Q6Em-D0oUOKI z&+?jT(C;-tRgtI21V(O4nclJI3-~-m+=-lj*&}p{oaR_`Kh)_tIH_N7kg_<)VVH;Q z`0u1?FpDeDyBa?ax&|tGE!_I`R6{r5HyU5WTg#0wh?`&vH`8S>gd6BqIQ-k_>-1&3 zJ?^E)=ys^?R{;GEz`v7Tq`T;4d90=TpdXYb5(Msrl0mT?^YO5cE8yH2MzMlJ*rm~2 zp2iVAAE&56Sc`HD%D57juoA4xK}Cc)j+Ty-yhBfL7tC=7z0TXw$_2$ayn}a=8#JHI z-Ei~bHnMmZc6d~vvRf-Kb^*pvD8~PGE0Q)~asAztpVfyzVw>U?9o2fr=$hqS7yOVh zoiD_w&f}#kw4nlRdfbI8bPnoAX|B!}AEhkJOmdAlN-i||Aeq51^HP=w2LMaNs|tQq zcL~VI!FM0RDbkIS&Djtu#}?HUfrR#QNdzTVoKDCnA1MMns+sbyxs4)gl6m z@K)IP9pQlzz8|x=pg~mo_-hc}aH{46e;u%qdGI&*n~2+!shGcob=iQ0=M1!Rl*c=n zv_7OBIVo=L(fN9v@$-N!M78pl<)r}NvkLK?vlCxh_?F@OC49^A-G}dVd=E@t zXgrDUQ$;!X{790MxAWozFPGk9sy8yhr%CU-(xc4@E|=b6)$2&`1nE7gdfO8`LV8D3 z@3I85^uDipHznvj={>D_cPHp|={>7@$ppP*d%)-60g*?3n9o0QTv&F3p0MYBGSu9C z_T0~gn!D1T`^8Xm+w8d)hnibu&;4qsx!L*rYcFUjKf#(2`TVl15eE%@Px74G$+cfp zMFK)m_M`j&KCVakcTRep&#wX(@-UqHHT=aMCnd6PC;TTSJE_V|P-#)FomBA~UZco3 z#D8Tf2OIa&h$6$btiLB{n5C|T-&<#Kmmzm5An|vw#9q#ijz6-C^_tHC@pm$+U@1d^zJ}2ov zd=RhZkJE?zefo%hi0AOP=qRdA$22^FqOQZ*RP<-COPPVny|q-<0+n{mKw59ZAYe3T zi6exOq4f@0F7Y`0E?U{3In|n$Zq=n*Thpxz(ydF=t-I2#M7s4LUFtx7oZ`w5b+~N1B?>?G7)KanbLzK|KF3e8}6u~{24Oxb|uJFew;T# z0+`RaN(`gz-RhWxON>WFCRPVFNjpjsNX`)Ia;4JjV0{px5Z|}vc&v2eUa0w?(aZOe zr)+u;f0&?RC(rpft?hlbq94*&qkcUd3!hBT%0eDNqY>!w3XMu>K5ldc8E$lqLpVrL z8iH_#mV{K>jb>BU=<(x0J8Ho;?MNkEDwVvYtVeV8XnNyx1fZIH&5iu3$!4L~)vKAC z4r;@_*;&;{)+QFY3UiX$h#oC}FH*bg!kiwhD5*`{cv%h?ssJ|Up1xOL>BuRQ+N6rZ z_t4E*)p}O7k)VsP+(>GZpVY=CwQ0yC4YkJQzY7;{Ou5eOpL8e4E#YuZwOhFs%?&11 z6zZ4hJWE`H3kj$jIVIZp8fq4DW%8nwg0wHkPWy^H&S=hM20N(k>ANIBw+hzj3V6lg zprS3S8lEIlm|Km!R!tP@e*AYY4Feke+-f9_4mAn|IHagC0NJ6&UFbQU8gl?OW{Mgc zBGTv-qI>$TI!;T<;SxpsE>$wP0;MM6F$m8^RDjF!cpgVnkmr@-Vn3fJ;y1?Qp$e05 zsXv9z;mPFVDfmt4G+dQRX%C#(Z9JXsKxluKE8*Ctz;Vrh)0z!uHHSXtxwvCga}LkP zCC-aqXw=}B6Q^@IerM3ki;%%q^KM?uH^UK1#D0+qLCY;ERYOY@3?)~-R;yB~R=~Tp z8OZIjK<7?4HE~r_IIPXmW+U#GP>D7N*$IMw(b{R)>!FY7Qq3!Sq3ydB6ayLeMGA^s=~@&NH@IU%@o>2V z#e-sp4aL-Ia55>8*>o-do#N!qp<#Wf$mlx10i&1y_+t61nLu_D(xYO^9Xy8>l4%~L zN|;#=e@JyGJRGBwkQyJw4nPyb2qVQV8jl)O*&*$84H^GPyM2a+ z1aQkkdAs^Omn!k`a%9IVsEF&8Wb6{(c&!$EAw_={L1A*`^~6CE#aA3;0nB}IQd^PK z8c^-f);`oAzy&?3lj#df9t20c3T|*UM%N%ETbto+3LF(c!mMr3niYmD=Z-DR!>xNY zZp^^HG39Qk0oWD( "); + return; + } + SetPlayerFlair(player, MaybeOfflinePlayer.AddPlayerIfNeeded(args[2]), args[3]); + } } diff --git a/TheButtonAutoFlair/src/tk/sznp/thebuttonautoflair/MaybeOfflinePlayer.java b/TheButtonAutoFlair/src/tk/sznp/thebuttonautoflair/MaybeOfflinePlayer.java index 6549d0e..28679fc 100644 --- a/TheButtonAutoFlair/src/tk/sznp/thebuttonautoflair/MaybeOfflinePlayer.java +++ b/TheButtonAutoFlair/src/tk/sznp/thebuttonautoflair/MaybeOfflinePlayer.java @@ -9,6 +9,7 @@ public class MaybeOfflinePlayer public String Flair; //If the user comments their name, it gets set, it doesn't matter if they accepted it or not public boolean AcceptedFlair; public boolean IgnoredFlair; + public boolean FlairDecided; //2015.08.09. public static HashMap AllPlayers=new HashMap<>(); //2015.08.08. public static MaybeOfflinePlayer AddPlayerIfNeeded(String playername) { @@ -21,4 +22,10 @@ public class MaybeOfflinePlayer } return AllPlayers.get(playername); } + /*public enum FlairClassType + { //2015.08.09. + NonPresser, + CantPress, + Undecided + }*/ } diff --git a/TheButtonAutoFlair/src/tk/sznp/thebuttonautoflair/PlayerListener.java b/TheButtonAutoFlair/src/tk/sznp/thebuttonautoflair/PlayerListener.java index a085586..dc0378b 100644 --- a/TheButtonAutoFlair/src/tk/sznp/thebuttonautoflair/PlayerListener.java +++ b/TheButtonAutoFlair/src/tk/sznp/thebuttonautoflair/PlayerListener.java @@ -18,7 +18,7 @@ public class PlayerListener implements Listener MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName()); //2015.08.08. MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName()); //2015.08.08. if(mp.Flair!=null) - PluginMain.AppendPlayerDisplayFlair(p, mp.UserName, mp.Flair); + PluginMain.AppendPlayerDisplayFlair(mp, p); //2015.08.09. 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\"}]}}}]"; diff --git a/TheButtonAutoFlair/src/tk/sznp/thebuttonautoflair/PluginMain.java b/TheButtonAutoFlair/src/tk/sznp/thebuttonautoflair/PluginMain.java index 5740654..ceca4ee 100644 --- a/TheButtonAutoFlair/src/tk/sznp/thebuttonautoflair/PluginMain.java +++ b/TheButtonAutoFlair/src/tk/sznp/thebuttonautoflair/PluginMain.java @@ -38,49 +38,7 @@ public class PluginMain extends JavaPlugin this.getCommand("u").setExecutor(new Commands()); this.getCommand("u").setUsage(this.getCommand("u").getUsage().replace('&', '§')); Instance=this; //2015.08.08. - try { - File file=new File("flairsaccepted.txt"); - if(file.exists()) - { - BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt")); - String line; - while ((line = br.readLine()) != null) - { - String name=line.replace("\n", ""); - //System.out.println("Name: " + name); - MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08. - } - br.close(); - } - file=new File("flairsignored.txt"); - if(file.exists()) - { - BufferedReader br=new BufferedReader(new FileReader("flairsignored.txt")); - String line; - while ((line = br.readLine()) != null) - { - String name=line.replace("\n", ""); - MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08. - } - br.close(); - } - file=new File("autoflairconfig.txt"); - if(file.exists()) - { - BufferedReader br=new BufferedReader(new FileReader(file)); - String line; - while((line=br.readLine())!=null) - { - String[] s=line.split(" "); - TownColors.put(s[0], s[1]); - } - br.close(); - } - //throw new IOException("Test"); //2015.08.09. - } catch (IOException e) { - System.out.println("Error!\n"+e); - LastException=e; //2015.08.09. - } + LoadFiles(false); //2015.08.09. Runnable r=new Runnable(){public void run(){ThreadMethod();}}; Thread t=new Thread(r); t.start(); @@ -90,42 +48,7 @@ public class PluginMain extends JavaPlugin @Override public void onDisable() { - try - { - FileWriter fw; - fw = new FileWriter("flairsaccepted.txt"); - fw.close(); - fw = new FileWriter("flairsignored.txt"); - fw.close(); - } - catch(Exception e) - { - System.out.println("Error!\n"+e); - LastException=e; //2015.08.09. - } - try { - File file=new File("flairsaccepted.txt"); - BufferedWriter bw=new BufferedWriter(new FileWriter(file, true)); - for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. - { - if(!player.AcceptedFlair) - continue; //2015.08.08. - bw.write(player.PlayerName+"\n"); - } - bw.close(); - file=new File("flairsignored.txt"); - bw = new BufferedWriter(new FileWriter(file, true)); - for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. - { - if(!player.IgnoredFlair) - continue; //2015.08.08. - bw.write(player.PlayerName+"\n"); - } - bw.close(); - } catch (IOException e) { - System.out.println("Error!\n"+e); - LastException=e; //2015.08.09. - } + SaveFiles(); //2015.08.09. stop=true; } @@ -143,6 +66,8 @@ public class PluginMain extends JavaPlugin String author=item.getJSONObject("data").getString("author"); String ign=item.getJSONObject("data").getString("body"); int start = ign.indexOf("IGN:") + "IGN:".length(); + if(start==-1) + continue; //2015.08.09. int end = ign.indexOf(' ', start); if (end == -1 || end == start) end=ign.indexOf('\n', start); //2015.07.15. @@ -209,7 +134,9 @@ public class PluginMain extends JavaPlugin public void SetFlair(String playername, String text, String flairclass, String username) { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. String finalflair; + p.FlairDecided=true; switch(flairclass) { case "press-1": @@ -239,13 +166,16 @@ public class PluginMain extends JavaPlugin case "cant-press": //2015.08.08. finalflair="§r(can't press)§r"; break; + case "undecided": //2015.08.09. + p.FlairDecided=false; + finalflair=""; + break; default: finalflair=""; break; } if(finalflair.length()==0) //<-- 2015.07.20. return; - MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08. p.Flair=finalflair; //2015.08.08. p.UserName=username; //2015.08.08. System.out.println("Added new flair to "+playername+": "+finalflair); @@ -253,7 +183,8 @@ public class PluginMain extends JavaPlugin { if(player.getName().equals(playername)) { - AppendPlayerDisplayFlair(player, username, finalflair); + //AppendPlayerDisplayFlair(player, username, finalflair); + AppendPlayerDisplayFlair(p, player); break; } } @@ -264,18 +195,24 @@ public class PluginMain extends JavaPlugin 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) + + //public static void AppendPlayerDisplayFlair(Player player, String username, String flair) + public static void AppendPlayerDisplayFlair(MaybeOfflinePlayer player, Player p) //<-- 2015.08.09. { - if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).IgnoredFlair) + + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).IgnoredFlair) return; - if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).AcceptedFlair) - AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. + if(MaybeOfflinePlayer.AllPlayers.get(p.getName()).AcceptedFlair) + { + AppendPlayerDisplayFlairFinal(p, player.Flair); //2015.07.20. + if(!player.FlairDecided) + p.sendMessage("§9Your flair type is unknown. Are you a non-presser or a can't press? (/u nonpresser or /u cantpress)§r"); //2015.08.09. + } else - player.sendMessage("§9Are you Reddit user "+username+"?§r §6Type /u accept or /u ignore§r"); + p.sendMessage("§9Are you Reddit user "+player.UserName+"?§r §6Type /u accept or /u ignore§r"); } - public static void AppendPlayerDisplayFlairFinal(Player player, String flair) + private static void AppendPlayerDisplayFlairFinal(Player player, String flair) { //2015.07.20. String color = GetColorForTown(GetPlayerTown(player)); //TO!DO: Multiple colors put on first capital letters String[] colors = color.substring(1).split("§"); @@ -339,13 +276,150 @@ public class PluginMain extends JavaPlugin } } - public static void RemovePlayerDisplayFlairFinal(Player player, String flair) + /*public static void RemovePlayerDisplayFlairFinal(Player player, String flair) { //2015.07.20. MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair=null; //2015.08.08. - } + }*/ public static Collection GetPlayers() { return Instance.getServer().getOnlinePlayers(); } + + public static void LoadFiles(boolean reload) //<-- 2015.08.09. + { + if(reload) + { //2015.08.09. + System.out.println("Auto-flair plugin cleanup for reloading..."); + MaybeOfflinePlayer.AllPlayers.clear(); + TownColors.clear(); + } + System.out.println("Loading files for auto-flair plugin..."); //2015.08.09. + try { + File file=new File("flairsaccepted.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + //System.out.println("Name: " + name); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("flairsignored.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader("flairsignored.txt")); + String line; + while ((line = br.readLine()) != null) + { + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08. + } + br.close(); + } + file=new File("autoflairconfig.txt"); + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + TownColors.put(s[0], s[1]); + } + br.close(); + } + file=new File("customflairs.txt"); //2015.08.09. + if(file.exists()) + { + BufferedReader br=new BufferedReader(new FileReader(file)); + String line; + while((line=br.readLine())!=null) + { + String[] s=line.split(" "); + MaybeOfflinePlayer.AddPlayerIfNeeded(s[0]).Flair=s[1]; //2015.08.09. + } + br.close(); + } + //throw new IOException("Test"); //2015.08.09. + System.out.println("Auto-flair plugin loaded files!"); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + public static void SaveFiles() //<-- 2015.08.09. + { + try + { + FileWriter fw; + fw = new FileWriter("flairsaccepted.txt"); + fw.close(); + fw = new FileWriter("flairsignored.txt"); + fw.close(); + } + catch(Exception e) + { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + try { + File file=new File("flairsaccepted.txt"); + BufferedWriter bw=new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.AcceptedFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + file=new File("flairsignored.txt"); + bw = new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.IgnoredFlair) + continue; //2015.08.08. + bw.write(player.PlayerName+"\n"); + } + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + } + public static boolean RemoveLineFromFile(String file, String line) + { //2015.08.09. + File inputFile = new File(file); + File tempFile = new File("_temp.txt"); + + if(!inputFile.exists()) + return true; //2015.08.10. + + try { + BufferedReader reader = new BufferedReader(new FileReader(inputFile)); + BufferedWriter writer = new BufferedWriter(new FileWriter(tempFile)); + + String lineToRemove = line; + String currentLine; + + while((currentLine = reader.readLine()) != null) { + // trim newline when comparing with lineToRemove + String trimmedLine = currentLine.trim(); + //if(trimmedLine.equals(lineToRemove)) continue; + if(trimmedLine.contains(lineToRemove)) continue; //2015.08.09. + writer.write(currentLine + System.getProperty("line.separator")); + } + writer.close(); + reader.close(); + return tempFile.renameTo(inputFile); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } + return false; + } }