PageRenderTime 148ms CodeModel.GetById 29ms RepoModel.GetById 0ms app.codeStats 0ms

/Minecraft Plugins hMod/CommandOn/src/CommandOn.java

https://github.com/Vandolis/Minecraft-Plugins
Java | 1406 lines | 1293 code | 41 blank | 72 comment | 534 complexity | ea88ef277bb7e6152be9fd133034b1d1 MD5 | raw file
  1. /*
  2. * Minecraft plugin that allows commands to be ran on events. Copyright (C) 2010 Michael Robinette
  3. *
  4. * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by
  5. * the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
  6. *
  7. * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
  8. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  9. *
  10. * You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>
  11. */
  12. import java.io.BufferedReader;
  13. import java.io.BufferedWriter;
  14. import java.io.File;
  15. import java.io.FileReader;
  16. import java.io.FileWriter;
  17. import java.util.ArrayList;
  18. import java.util.logging.Level;
  19. import java.util.logging.Logger;
  20. /*
  21. * 12/01/2010 Mind the idiot style of programming, as this is what a program that is not planned out looks like. Pretty much all of it was
  22. * added on as I went, so it is NOT the best solution and I plan on rewritting it for Bukkit. If this code helps you in any way be sure to
  23. * let me know!
  24. */
  25. /**
  26. * @author Vandolis
  27. */
  28. public class CommandOn extends Plugin {
  29. private Listener l = new Listener(this);
  30. protected static final Logger log = Logger.getLogger("Minecraft");
  31. private static final String name = "CommandOn";
  32. private static final String version = "v1.1.7";
  33. private static final String[] COMMAND_TEMPLATE = {
  34. "## OnLogin", "default:", "## OnLogout", "default:", "## OnDeath", "default:", "## OnRespawn", "default:"
  35. };
  36. private static final String[] PLAYERS_TEMPLATE = {
  37. "## PlayerName", "OnLogin:", "OnLogout:", "OnDeath:", "OnRespawn:"
  38. };
  39. private static final String TAGS[] = {
  40. "OnLogin", "OnLogout", "OnDeath", "OnDeathFall", "OnDeathCactus", "OnDeathWater", "OnDeathMob", "OnDeathFire", "OnDeathLava",
  41. "OnDeathCreeper", "OnDeathExplosion", "OnRespawn", "OnServerStart", "OnPvPKill", "OnPvPDeath", "OnPvPEnd", "OnPvPStart",
  42. "OnDeathZombie", "OnDeathSpider", "OnDeathSkeleton", "OnDeathPigZombie", "OnDeathGhast", "OnDeathSlime", "OnDeathOther",
  43. "OnDeathSuicide"
  44. };
  45. private static final String SECTIONS[] = {
  46. "Group", "Name", "Default", "All", "NoGroup"
  47. };
  48. private static final String VARS[] = {
  49. "[NAME]", "[PLAYERX]", "[PLAYERY]", "[PLAYERZ]", "[ATTACKER]", "[DEFENDER]", "[WINNER]", "[LOSER]", "[CAUSE]"
  50. };
  51. private static PropertiesFile props = new PropertiesFile("CommandOn.properties");
  52. private static File command_file = new File("CommandOn.txt");
  53. private static File player_file = new File("CommandOnPlayers.txt");
  54. private static int gCdim[] = {
  55. 1, 1, 1
  56. };
  57. private static String gC[][][] = new String[gCdim[0]][gCdim[1]][gCdim[2]];
  58. private static int pIdim[] = {
  59. 1, 1, 1
  60. };
  61. private static String pI[][][] = new String[pIdim[0]][pIdim[1]][pIdim[2]];
  62. private static boolean debug = false;
  63. private static String editListGroups[] = null;
  64. private static String editIgnoreGroups[] = null;
  65. private static String[] startCommandQue = null;
  66. private static ArrayList<Death> deaths = new ArrayList<Death>();
  67. // Hacked vars
  68. private static String login = "";
  69. private static ArrayList<Battle> currentBattles = new ArrayList<Battle>();
  70. public void enable() {
  71. etc.getInstance().addCommand("/co", "- CommandOn");
  72. }
  73. public void disable() {
  74. etc.getInstance().removeCommand("/co");
  75. }
  76. public void initialize() {
  77. log.info(name + " " + version + " initialized");
  78. etc.getLoader().addListener(PluginLoader.Hook.LOGIN, l, this, PluginListener.Priority.MEDIUM);
  79. etc.getLoader().addListener(PluginLoader.Hook.HEALTH_CHANGE, l, this, PluginListener.Priority.MEDIUM);
  80. etc.getLoader().addListener(PluginLoader.Hook.DISCONNECT, l, this, PluginListener.Priority.MEDIUM);
  81. etc.getLoader().addListener(PluginLoader.Hook.COMMAND, l, this, PluginListener.Priority.MEDIUM);
  82. etc.getLoader().addListener(PluginLoader.Hook.DAMAGE, l, this, PluginListener.Priority.MEDIUM);
  83. readFiles();
  84. checkCommands(new Player(), "onserverstart", "", null);
  85. }
  86. public void readFiles() {
  87. try {
  88. gC = new String[gCdim[0]][gCdim[1]][gCdim[2]];
  89. pI = new String[pIdim[0]][pIdim[1]][pIdim[2]];
  90. BufferedReader command_reader = null;
  91. BufferedReader player_reader = null;
  92. BufferedWriter command_writer = null;
  93. BufferedWriter player_writer = null;
  94. if (!command_file.exists()) {
  95. command_file = new File("/Plugins/CommandOn.txt");
  96. if (!command_file.exists()) {
  97. log.log(Level.INFO, "No CommandOn.txt found, creating file.");
  98. command_file = new File("CommandOn.txt");
  99. command_writer = new BufferedWriter(new FileWriter(command_file));
  100. for (int wl = 0; wl < COMMAND_TEMPLATE.length; wl++) {
  101. command_writer.write(COMMAND_TEMPLATE[wl]);
  102. command_writer.newLine();
  103. }
  104. command_writer.close();
  105. }
  106. }
  107. if (!player_file.exists()) {
  108. player_file = new File("/Plugins/CommandOnPlayers.txt");
  109. if (!player_file.exists()) {
  110. log.log(Level.INFO, "No CommandOnPlayers.txt found, creating file.");
  111. player_file = new File("CommandOnPlayers.txt");
  112. player_writer = new BufferedWriter(new FileWriter(player_file));
  113. for (int wl = 0; wl < PLAYERS_TEMPLATE.length; wl++) {
  114. player_writer.write(PLAYERS_TEMPLATE[wl]);
  115. player_writer.newLine();
  116. }
  117. player_writer.close();
  118. }
  119. }
  120. player_reader = new BufferedReader(new FileReader(player_file));
  121. command_reader = new BufferedReader(new FileReader(command_file));
  122. String raw = "";
  123. int count = -1;
  124. int count2 = 0;
  125. while ((raw = command_reader.readLine()) != null && !raw.equalsIgnoreCase("") && !raw.equalsIgnoreCase(" ")) {
  126. if (raw != null) {
  127. // log.log(Level.INFO, raw);
  128. if (raw.contains("##")) {
  129. String temp[] = raw.split(" ");
  130. if (temp.length >= 2) {
  131. if (insideArr(TAGS, temp[1])) {
  132. count++;
  133. if (count == gC.length) {
  134. gCdim[0]++;
  135. }
  136. String tgC[][][] = new String[gCdim[0]][gCdim[1]][gCdim[2]];
  137. copyArray(gC, tgC);
  138. gC = tgC;
  139. gC[count][0][0] = temp[1];
  140. count2 = 0;
  141. }
  142. }
  143. }
  144. else if (count2 != -1) {
  145. String split[] = raw.split(":");
  146. count2++;
  147. if (count2 >= gC[count].length) {
  148. gCdim[1]++;
  149. }
  150. while (gCdim[2] < split.length) {
  151. gCdim[2]++;
  152. }
  153. String tgC[][][] = new String[gCdim[0]][gCdim[1]][gCdim[2]];
  154. copyArray(gC, tgC);
  155. for (int a = 0; a < split.length; a++) {
  156. tgC[count][count2][a] = split[a];
  157. }
  158. gC = tgC;
  159. }
  160. }
  161. }
  162. command_reader.close();
  163. count = -1;
  164. count2 = 0;
  165. while ((raw = player_reader.readLine()) != null && !raw.equalsIgnoreCase("") && !raw.equalsIgnoreCase(" ")) {
  166. if (raw != null) {
  167. // log.log(Level.INFO, raw);
  168. if (raw.contains("##")) {
  169. String temp[] = raw.split(" ");
  170. if (temp.length >= 2) {
  171. count++;
  172. if (count == pI.length) {
  173. pIdim[0]++;
  174. }
  175. String tpI[][][] = new String[pIdim[0]][pIdim[1]][pIdim[2]];
  176. copyArray(pI, tpI);
  177. pI = tpI;
  178. pI[count][0][0] = temp[1];
  179. count2 = 0;
  180. }
  181. }
  182. else if (count2 != -1) {
  183. String split[] = raw.split(":");
  184. count2++;
  185. if (count2 >= pI[count].length) {
  186. pIdim[1]++;
  187. }
  188. while (pIdim[2] < split.length) {
  189. pIdim[2]++;
  190. }
  191. String tpI[][][] = new String[pIdim[0]][pIdim[1]][pIdim[2]];
  192. copyArray(pI, tpI);
  193. for (int a = 0; a < split.length; a++) {
  194. tpI[count][count2][a] = split[a];
  195. }
  196. pI = tpI;
  197. }
  198. }
  199. }
  200. player_reader.close();
  201. removeNull(gC);
  202. removeNull(pI);
  203. // Read from properties file
  204. if (!props.containsKey("editlistgroups")) {
  205. props.setString("editlistgroups", "admins");
  206. props.save();
  207. }
  208. if (!props.containsKey("editignoregroups")) {
  209. props.setString("editignoregroups", "all");
  210. props.save();
  211. }
  212. /*
  213. * if (!props.containsKey("debug")) { props.setBoolean("debug", false); props.setString("destroygroups", "admins");
  214. * props.save(); }
  215. */
  216. editListGroups = props.getString("editlistgroups").split(",");
  217. editIgnoreGroups = props.getString("editignoregroups").split(",");
  218. debug = props.getBoolean("debug");
  219. // Trim data
  220. for (int x = 0; x < editListGroups.length; x++) {
  221. editListGroups[x] = editListGroups[x].trim();
  222. }
  223. for (int x = 0; x < editIgnoreGroups.length; x++) {
  224. editIgnoreGroups[x] = editIgnoreGroups[x].trim();
  225. }
  226. }
  227. catch (Exception e) {
  228. e.printStackTrace();
  229. }
  230. }
  231. public void runServerCommands(String[] commands) {
  232. for (int x = 0; x < commands.length; x++) {
  233. if (commands[x].length() >= 1) {
  234. if (commands[x].charAt(0) == '#') {
  235. String serverCommand = commands[x];
  236. serverCommand = serverCommand.replaceFirst("#", "");
  237. if (!serverCommand.equalsIgnoreCase("")) {
  238. log.log(Level.INFO, "CommandOn running server start command: " + serverCommand);
  239. etc.getServer().useConsoleCommand(serverCommand);
  240. }
  241. }
  242. else {
  243. // log.log(Level.INFO, "Adding " + commands[x] + " to the que.");
  244. // Add to que
  245. if (startCommandQue != null) {
  246. String temp[] = new String[startCommandQue.length + 1];
  247. System.arraycopy(startCommandQue, 0, temp, 0, startCommandQue.length);
  248. temp[temp.length - 1] = commands[x];
  249. startCommandQue = temp;
  250. }
  251. else {
  252. startCommandQue = new String[1];
  253. startCommandQue[0] = commands[x];
  254. }
  255. }
  256. }
  257. }
  258. }
  259. public void copyArray(final String[][][] src, String[][][] dest) {
  260. for (int x = 0; x < src.length; x++) {
  261. for (int y = 0; y < src[x].length; y++) {
  262. System.arraycopy(src[x][y], 0, dest[x][y], 0, src[x][y].length);
  263. }
  264. }
  265. }
  266. public void printArray(final String[][][] arr) {
  267. log.log(Level.INFO, "Dims x: " + arr.length + " y:" + arr[0].length + " z:" + arr[0][0].length);
  268. String message = "";
  269. for (int x = 0; x < arr.length; x++) {
  270. if (arr[x][0][0] != "") {
  271. message += arr[x][0][0] + " - ";
  272. }
  273. for (int y = 0; y < arr[x].length; y++) {
  274. if ((arr[x][y][0] != "") && (!arr[x][y][0].equalsIgnoreCase(arr[x][0][0]))) {
  275. message += arr[x][y][0] + " - ";
  276. }
  277. for (int z = 0; z < arr[x][y].length; z++) {
  278. if ((arr[x][y][z] != "") && (!arr[x][y][z].equalsIgnoreCase(arr[x][y][0]))) {
  279. log.log(Level.INFO, message + arr[x][y][z]);
  280. }
  281. else {
  282. log.log(Level.INFO, message);
  283. }
  284. }
  285. message = arr[x][0][0] + " - ";
  286. }
  287. message = "";
  288. }
  289. }
  290. public void printArray(final String[] arr) {
  291. for (int x = 0; x < arr.length; x++) {
  292. log.log(Level.INFO, "String at x: " + x + " " + arr[x]);
  293. }
  294. }
  295. public void removeNull(String[][][] arr) {
  296. for (int x = 0; x < arr.length; x++) {
  297. for (int y = 0; y < arr[x].length; y++) {
  298. for (int z = 0; z < arr[x][y].length; z++) {
  299. if (arr[x][y][z] == null) {
  300. arr[x][y][z] = "";
  301. }
  302. }
  303. }
  304. }
  305. }
  306. public boolean insideArr(final String[] arr, final String s) {
  307. for (int x = 0; x < arr.length; x++) {
  308. if (s.equalsIgnoreCase(arr[x])) {
  309. return true;
  310. }
  311. }
  312. return false;
  313. }
  314. public boolean canEditIgnore(Player player) {
  315. if (isAdmin(player)) {
  316. return true;
  317. }
  318. for (int x = 0; x < editIgnoreGroups.length; x++) {
  319. if (player.isInGroup(editIgnoreGroups[x])) {
  320. return true;
  321. }
  322. else if (editIgnoreGroups[x].equalsIgnoreCase("all")) {
  323. return true;
  324. }
  325. }
  326. return false;
  327. }
  328. public boolean canEditList(Player player) {
  329. if (isAdmin(player)) {
  330. return true;
  331. }
  332. for (int x = 0; x < editListGroups.length; x++) {
  333. if (player.isInGroup(editListGroups[x])) {
  334. return true;
  335. }
  336. else if (editListGroups[x].equalsIgnoreCase("all")) {
  337. return true;
  338. }
  339. }
  340. return false;
  341. }
  342. public boolean isAdmin(Player player) {
  343. if (!player.hasNoGroups()) {
  344. String groups[] = player.getGroups();
  345. for (int x = 0; x < groups.length; x++) {
  346. if (groups[x].contains("admin")) {
  347. return true;
  348. }
  349. }
  350. }
  351. if (player.isAdmin()) {
  352. return true;
  353. }
  354. return false;
  355. }
  356. public void broadcast(final String[] tempMessage, final Player player, Battle batt) {
  357. String message = "";
  358. message = "";
  359. for (int m = 1; m < tempMessage.length; m++) {
  360. message += tempMessage[m];
  361. if ((m + 1) < tempMessage.length) {
  362. message += " ";
  363. }
  364. }
  365. // Insert variables
  366. message = message.replace("[NAME]", player.getName());
  367. message = message.replace("[PLAYERX]", Double.toString(player.getX()));
  368. message = message.replace("[PLAYERY]", Double.toString(player.getY()));
  369. message = message.replace("[PLAYERZ]", Double.toString(player.getZ()));
  370. if (batt != null) {
  371. message = message.replace("[ATTACKER]", batt.getAtt());
  372. message = message.replace("[DEFENDER]", batt.getDef());
  373. message = message.replace("[WINNER]", batt.getWin());
  374. message = message.replace("[LOSER]", batt.getLooser());
  375. message = message.replace("[CAUSE]", batt.getCause());
  376. }
  377. if (tempMessage[0].equalsIgnoreCase("%BLACK")) {
  378. etc.getServer().messageAll(Colors.Black + message);
  379. }
  380. else if (tempMessage[0].equalsIgnoreCase("%BLUE")) {
  381. etc.getServer().messageAll(Colors.Blue + message);
  382. }
  383. else if (tempMessage[0].equalsIgnoreCase("%DARKPURPLE")) {
  384. etc.getServer().messageAll(Colors.DarkPurple + message);
  385. }
  386. else if (tempMessage[0].equalsIgnoreCase("%GOLD")) {
  387. etc.getServer().messageAll(Colors.Gold + message);
  388. }
  389. else if (tempMessage[0].equalsIgnoreCase("%GRAY")) {
  390. etc.getServer().messageAll(Colors.Gray + message);
  391. }
  392. else if (tempMessage[0].equalsIgnoreCase("%GREEN")) {
  393. etc.getServer().messageAll(Colors.Green + message);
  394. }
  395. else if (tempMessage[0].equalsIgnoreCase("%LIGHTBLUE")) {
  396. etc.getServer().messageAll(Colors.LightBlue + message);
  397. }
  398. else if (tempMessage[0].equalsIgnoreCase("%LIGHTGRAY")) {
  399. etc.getServer().messageAll(Colors.LightGray + message);
  400. }
  401. else if (tempMessage[0].equalsIgnoreCase("%LIGHTGREEN")) {
  402. etc.getServer().messageAll(Colors.LightGreen + message);
  403. }
  404. else if (tempMessage[0].equalsIgnoreCase("%LIGHTPURPLE")) {
  405. etc.getServer().messageAll(Colors.LightPurple + message);
  406. }
  407. else if (tempMessage[0].equalsIgnoreCase("%NAVY")) {
  408. etc.getServer().messageAll(Colors.Navy + message);
  409. }
  410. else if (tempMessage[0].equalsIgnoreCase("%PURPLE")) {
  411. etc.getServer().messageAll(Colors.Purple + message);
  412. }
  413. else if (tempMessage[0].equalsIgnoreCase("%RED")) {
  414. etc.getServer().messageAll(Colors.Red + message);
  415. }
  416. else if (tempMessage[0].equalsIgnoreCase("%ROSE")) {
  417. etc.getServer().messageAll(Colors.Rose + message);
  418. }
  419. else if (tempMessage[0].equalsIgnoreCase("%WHITE")) {
  420. etc.getServer().messageAll(Colors.White + message);
  421. }
  422. else if (tempMessage[0].equalsIgnoreCase("%YELLOW")) {
  423. etc.getServer().messageAll(Colors.Yellow + message);
  424. }
  425. else {
  426. message = "";
  427. for (int m = 0; m < tempMessage.length; m++) {
  428. message += tempMessage[m];
  429. if ((m + 1) < tempMessage.length) {
  430. message += " ";
  431. }
  432. }
  433. // Insert variables
  434. message = message.replace("[NAME]", player.getName());
  435. message = message.replace("[PLAYERX]", Double.toString(player.getX()));
  436. message = message.replace("[PLAYERY]", Double.toString(player.getY()));
  437. message = message.replace("[PLAYERZ]", Double.toString(player.getZ()));
  438. if (batt != null) {
  439. message = message.replace("[ATTACKER]", batt.getAtt());
  440. message = message.replace("[DEFENDER]", batt.getDef());
  441. message = message.replace("[WINNER]", batt.getWin());
  442. message = message.replace("[LOSER]", batt.getLooser());
  443. message = message.replace("[CAUSE]", batt.getCause());
  444. }
  445. message = message.replaceFirst("%", ""); // Removes the % from the
  446. // beginning of the
  447. // string
  448. etc.getServer().messageAll(message);
  449. }
  450. }
  451. public void runCommands(Player player, final String[] commandList, Battle batt) {
  452. for (int x = 1; x < commandList.length; x++) {
  453. String playersCommands[] = player.getCommands();
  454. boolean couldBuild = player.canBuild();
  455. String tempCommand[] = null;
  456. tempCommand = commandList[x].split(" ");
  457. if ((tempCommand.length >= 1) && (tempCommand[0] != "")) {
  458. if ((tempCommand.length > 1) && !(tempCommand[0].charAt(0) == '@') && !(tempCommand[0].charAt(0) == '%')) {
  459. player.setCommands(new String[] {
  460. tempCommand[0]
  461. });
  462. String command = "";
  463. for (int e = 0; e < tempCommand.length; e++) {
  464. command += tempCommand[e];
  465. if ((e + 1) < tempCommand.length) {
  466. command += " ";
  467. }
  468. }
  469. // Insert variables
  470. command = command.replace("[NAME]", player.getName());
  471. command = command.replace("[PLAYERX]", Double.toString(player.getX()));
  472. command = command.replace("[PLAYERY]", Double.toString(player.getY()));
  473. command = command.replace("[PLAYERZ]", Double.toString(player.getZ()));
  474. if (batt != null) {
  475. command = command.replace("[ATTACKER]", batt.getAtt());
  476. command = command.replace("[DEFENDER]", batt.getDef());
  477. command = command.replace("[WINNER]", batt.getWin());
  478. command = command.replace("[LOSER]", batt.getLooser());
  479. command = command.replace("[CAUSE]", batt.getCause());
  480. }
  481. // log.log(Level.INFO, "Running: " + command);
  482. player.command(command);
  483. }
  484. else if (tempCommand[0].charAt(0) == '#') {
  485. String serverCommand = "";
  486. for (int loop = 0; loop < tempCommand.length; loop++) {
  487. serverCommand += tempCommand[loop] + " ";
  488. }
  489. serverCommand = serverCommand.replaceFirst("#", "");
  490. if (!serverCommand.equalsIgnoreCase("")) {
  491. log.log(Level.INFO, "CommandOn running server start command: " + serverCommand);
  492. etc.getServer().useConsoleCommand(serverCommand);
  493. }
  494. }
  495. else if (tempCommand[0].charAt(0) == '@') {
  496. String message = "";
  497. for (int m = 1; m < tempCommand.length; m++) {
  498. message += tempCommand[m];
  499. if ((m + 1) < tempCommand.length) {
  500. message += " ";
  501. }
  502. }
  503. // Insert variables
  504. message = message.replace("[NAME]", player.getName());
  505. message = message.replace("[PLAYERX]", Double.toString(player.getX()));
  506. message = message.replace("[PLAYERY]", Double.toString(player.getY()));
  507. message = message.replace("[PLAYERZ]", Double.toString(player.getZ()));
  508. if (batt != null) {
  509. message = message.replace("[ATTACKER]", batt.getAtt());
  510. message = message.replace("[DEFENDER]", batt.getDef());
  511. message = message.replace("[WINNER]", batt.getWin());
  512. message = message.replace("[LOSER]", batt.getLooser());
  513. message = message.replace("[CAUSE]", batt.getCause());
  514. }
  515. if (tempCommand[0].equalsIgnoreCase("@BLACK")) {
  516. player.sendMessage(Colors.Black + message);
  517. }
  518. else if (tempCommand[0].equalsIgnoreCase("@BLUE")) {
  519. player.sendMessage(Colors.Blue + message);
  520. }
  521. else if (tempCommand[0].equalsIgnoreCase("@DARKPURPLE")) {
  522. player.sendMessage(Colors.DarkPurple + message);
  523. }
  524. else if (tempCommand[0].equalsIgnoreCase("@GOLD")) {
  525. player.sendMessage(Colors.Gold + message);
  526. }
  527. else if (tempCommand[0].equalsIgnoreCase("@GRAY")) {
  528. player.sendMessage(Colors.Gray + message);
  529. }
  530. else if (tempCommand[0].equalsIgnoreCase("@GREEN")) {
  531. player.sendMessage(Colors.Green + message);
  532. }
  533. else if (tempCommand[0].equalsIgnoreCase("@LIGHTBLUE")) {
  534. player.sendMessage(Colors.LightBlue + message);
  535. }
  536. else if (tempCommand[0].equalsIgnoreCase("@LIGHTGRAY")) {
  537. player.sendMessage(Colors.LightGray + message);
  538. }
  539. else if (tempCommand[0].equalsIgnoreCase("@LIGHTGREEN")) {
  540. player.sendMessage(Colors.LightGreen + message);
  541. }
  542. else if (tempCommand[0].equalsIgnoreCase("@LIGHTPURPLE")) {
  543. player.sendMessage(Colors.LightPurple + message);
  544. }
  545. else if (tempCommand[0].equalsIgnoreCase("@NAVY")) {
  546. player.sendMessage(Colors.Navy + message);
  547. }
  548. else if (tempCommand[0].equalsIgnoreCase("@PURPLE")) {
  549. player.sendMessage(Colors.Purple + message);
  550. }
  551. else if (tempCommand[0].equalsIgnoreCase("@RED")) {
  552. player.sendMessage(Colors.Red + message);
  553. }
  554. else if (tempCommand[0].equalsIgnoreCase("@ROSE")) {
  555. player.sendMessage(Colors.Rose + message);
  556. }
  557. else if (tempCommand[0].equalsIgnoreCase("@WHITE")) {
  558. player.sendMessage(Colors.White + message);
  559. }
  560. else if (tempCommand[0].equalsIgnoreCase("@YELLOW")) {
  561. player.sendMessage(Colors.Yellow + message);
  562. }
  563. else {
  564. message = "";
  565. for (int m = 0; m < tempCommand.length; m++) {
  566. message += tempCommand[m];
  567. if ((m + 1) < tempCommand.length) {
  568. message += " ";
  569. }
  570. }
  571. // Insert variables
  572. message = message.replace("[NAME]", player.getName());
  573. message = message.replace("[PLAYERX]", Double.toString(player.getX()));
  574. message = message.replace("[PLAYERY]", Double.toString(player.getY()));
  575. message = message.replace("[PLAYERZ]", Double.toString(player.getZ()));
  576. if (batt != null) {
  577. message = message.replace("[ATTACKER]", batt.getAtt());
  578. message = message.replace("[DEFENDER]", batt.getDef());
  579. message = message.replace("[WINNER]", batt.getWin());
  580. message = message.replace("[LOSER]", batt.getLooser());
  581. message = message.replace("[CAUSE]", batt.getCause());
  582. }
  583. message = message.replaceFirst("@", "");
  584. player.sendMessage(message);
  585. }
  586. }
  587. else if (tempCommand[0].charAt(0) == '%') {
  588. broadcast(tempCommand, player, batt);
  589. }
  590. else if ((tempCommand.length == 1) && !(tempCommand[0].charAt(0) == '@') && !(tempCommand[0].charAt(0) == '%')) {
  591. player.setCommands(new String[] {
  592. tempCommand[0]
  593. });
  594. player.command(tempCommand[0]);
  595. }
  596. }
  597. player.setCommands(playersCommands); // Return old commands
  598. player.setCanModifyWorld(couldBuild); // Just in case!
  599. }
  600. }
  601. public String[][][] shrink(String[][][] arr) {
  602. int ax = arr.length;
  603. int ay = arr[0].length;
  604. int az = arr[0][0].length;
  605. // Check x values
  606. for (int x = 0; x < ax; x++) {
  607. if (arr[x][0][0].equalsIgnoreCase("") || arr[x][0][0].trim().equalsIgnoreCase("##")) {
  608. if (x + 1 == ax) {
  609. if (ax == 1) {
  610. arr = new String[1][1][1];
  611. removeNull(arr);
  612. }
  613. else {
  614. ax--;
  615. String[][][] tarr = new String[ax][ay][az];
  616. for (int loopx = 0; loopx < tarr.length; loopx++) {
  617. for (int loopy = 0; loopy < tarr[0].length; loopy++) {
  618. for (int loopz = 0; loopz < tarr[0][0].length; loopz++) {
  619. tarr[loopx][loopy][loopz] = arr[loopx][loopy][loopz];
  620. }
  621. }
  622. }
  623. arr = tarr;
  624. removeNull(arr);
  625. }
  626. }
  627. else {
  628. ax--;
  629. String[][][] tarr = new String[ax][ay][az];
  630. int mod = 0;
  631. for (int loopx = 0; loopx < tarr.length; loopx++) {
  632. for (int loopy = 0; loopy < tarr[0].length; loopy++) {
  633. for (int loopz = 0; loopz < tarr[0][0].length; loopz++) {
  634. if (loopx == x) {
  635. mod = 1;
  636. }
  637. tarr[loopx][loopy][loopz] = arr[loopx + mod][loopy][loopz];
  638. }
  639. }
  640. }
  641. arr = tarr;
  642. removeNull(arr);
  643. }
  644. }
  645. }
  646. // Move data down if needed
  647. // log.log(Level.INFO, "arr before y switch");
  648. // printArray(arr);
  649. for (int x = 0; x < ax; x++) {
  650. for (int y = 0; y < ay; y++) {
  651. if (arr[x][y][0].equalsIgnoreCase("")) {
  652. if ((y + 1) != ay) {
  653. int mod = 0;
  654. String[][][] tarr = new String[ax][ay][az];
  655. for (int loopx = 0; loopx < tarr.length; loopx++) {
  656. for (int loopy = 0; (loopy + mod) < tarr[0].length; loopy++) {
  657. for (int loopz = 0; loopz < tarr[0][0].length; loopz++) {
  658. if ((loopy == y) && (loopx == x)) {
  659. mod = 1;
  660. }
  661. if ((mod == 1) && (loopx != x)) {
  662. mod = 0;
  663. }
  664. tarr[loopx][loopy][loopz] = arr[loopx][loopy + mod][loopz];
  665. }
  666. }
  667. }
  668. arr = tarr;
  669. removeNull(arr);
  670. }
  671. }
  672. }
  673. }
  674. // log.log(Level.INFO, "arr before z switch");
  675. // printArray(arr);
  676. for (int x = 0; x < ax; x++) {
  677. for (int y = 0; y < ay; y++) {
  678. for (int z = 0; z < az; z++) {
  679. if (arr[x][y][z].equalsIgnoreCase("")) {
  680. if ((z + 1) != az) {
  681. int mod = 0;
  682. String[][][] tarr = new String[ax][ay][az];
  683. for (int loopx = 0; loopx < tarr.length; loopx++) {
  684. for (int loopy = 0; loopy < tarr[0].length; loopy++) {
  685. for (int loopz = 0; (loopz + mod) < tarr[0][0].length; loopz++) {
  686. if ((loopz == z) && (loopy == y) && (loopx == x)) {
  687. mod = 1;
  688. }
  689. if ((mod == 1) && (loopy != y)) {
  690. mod = 0;
  691. }
  692. tarr[loopx][loopy][loopz] = arr[loopx][loopy][loopz + mod];
  693. }
  694. }
  695. }
  696. arr = tarr;
  697. removeNull(arr);
  698. }
  699. }
  700. }
  701. }
  702. }
  703. // log.log(Level.INFO, "arr before y resize");
  704. // printArray(arr);
  705. // Check y values
  706. int largeY = 0;
  707. int emptyY = 0;
  708. for (int x = 0; x < arr.length; x++) {
  709. emptyY = 0;
  710. for (int y = 0; y < arr[0].length; y++) {
  711. if (!arr[x][y][0].equalsIgnoreCase("") && ((y + 1) > largeY)) {
  712. largeY = y + 1;
  713. }
  714. else if (arr[x][y][0].equalsIgnoreCase("")) {
  715. emptyY++;
  716. }
  717. if ((emptyY == (arr[0].length - 1)) && !arr[x][0][0].equalsIgnoreCase("")) {
  718. arr = removeYZ(arr[x][0][0], "all", "", arr);
  719. ax = arr.length;
  720. if (arr.length >= 1) {
  721. ay = arr[0].length;
  722. if (arr[0].length >= 1) {
  723. az = arr[0][0].length;
  724. }
  725. else {
  726. az = 0;
  727. }
  728. }
  729. else {
  730. ay = 0;
  731. }
  732. emptyY = 0;
  733. }
  734. }
  735. }
  736. if (ay > largeY) {
  737. ay = largeY;
  738. if (ay < 1) {
  739. ay = 1;
  740. }
  741. String tarr[][][] = new String[ax][ay][az];
  742. for (int loopx = 0; loopx < tarr.length; loopx++) {
  743. for (int loopy = 0; loopy < tarr[0].length; loopy++) {
  744. for (int loopz = 0; loopz < tarr[0][0].length; loopz++) {
  745. tarr[loopx][loopy][loopz] = arr[loopx][loopy][loopz];
  746. }
  747. }
  748. }
  749. arr = tarr;
  750. removeNull(arr);
  751. }
  752. // Check z values
  753. // log.log(Level.INFO, "arr before z resize");
  754. // printArray(arr);
  755. int largeZ = 0;
  756. int emptyZ = 0;
  757. for (int x = 0; x < arr.length; x++) {
  758. emptyZ = 0;
  759. for (int y = 0; y < arr[0].length; y++) {
  760. emptyZ = 0;
  761. for (int z = 0; z < arr[0][0].length; z++) {
  762. // log.log(Level.INFO, "X: " + x + " Y:" + y + " Z:" + z);
  763. if (!arr[x][y][z].equalsIgnoreCase("") && ((z + 1) > largeZ)) {
  764. largeZ = z + 1;
  765. }
  766. else if (arr[x][y][z].equalsIgnoreCase("")) {
  767. emptyZ++;
  768. }
  769. boolean file = false; // False = Ignore, True = Command
  770. if (insideArr(TAGS, arr[x][0][0])) {
  771. file = true;
  772. }
  773. if ((emptyZ == (arr[0][0].length - 1)) && (y != 0) && !arr[x][y][0].equalsIgnoreCase("")
  774. && (!insideArr(SECTIONS, arr[x][y][0]) || file)) {
  775. // log.log(Level.INFO, "688 removing x:" + arr[x][0][0]
  776. // + " y:" + arr[x][y][0]);
  777. arr = removeYZ(arr[x][0][0], arr[x][y][0], "", arr);
  778. ax = arr.length;
  779. if (arr.length >= 1) {
  780. ay = arr[0].length;
  781. if (arr[0].length >= 1) {
  782. az = arr[0][0].length;
  783. }
  784. else {
  785. az = 0;
  786. }
  787. }
  788. else {
  789. ay = 0;
  790. }
  791. emptyZ = 0;
  792. }
  793. }
  794. }
  795. }
  796. if (az > largeZ) {
  797. az = largeZ;
  798. if (az < 1) {
  799. az = 1;
  800. }
  801. String tarr[][][] = new String[ax][ay][az];
  802. for (int loopx = 0; loopx < tarr.length; loopx++) {
  803. for (int loopy = 0; loopy < tarr[0].length; loopy++) {
  804. for (int loopz = 0; loopz < tarr[0][0].length; loopz++) {
  805. tarr[loopx][loopy][loopz] = arr[loopx][loopy][loopz];
  806. }
  807. }
  808. }
  809. arr = tarr;
  810. removeNull(arr);
  811. }
  812. // log.log(Level.INFO, "arr after z resize");
  813. // printArray(arr);
  814. return arr;
  815. }
  816. public boolean checkIgnore(Player player, final String tag, final String section) {
  817. for (int ix = 0; ix < pI.length; ix++) {
  818. if (pI[ix][0][0].equalsIgnoreCase(player.getName())) {
  819. for (int iy = 0; iy < pI[ix].length; iy++) {
  820. if (pI[ix][iy][0].equalsIgnoreCase(tag) && (!tag.equalsIgnoreCase(""))) {
  821. for (int iz = 0; iz < pI[ix][iy].length; iz++) {
  822. if (pI[ix][iy][iz].equalsIgnoreCase(section) && (!section.equalsIgnoreCase(""))) {
  823. return true;
  824. }
  825. else if (pI[ix][iy][iz].equalsIgnoreCase("all")) {
  826. return true;
  827. }
  828. else if (pI[ix][iy][iz].equalsIgnoreCase("") && insideArr(SECTIONS, pI[ix][iy][0])) {
  829. return true;
  830. }
  831. }
  832. }
  833. else if (pI[ix][iy][0].equalsIgnoreCase(section) && (!section.equalsIgnoreCase(""))) {
  834. return true;
  835. }
  836. else if (pI[ix][iy][0].equalsIgnoreCase("all")) {
  837. return true;
  838. }
  839. }
  840. }
  841. }
  842. return false;
  843. }
  844. public String[][][] removeYZ(final String x, final String y, final String z, String[][][] arr) {
  845. for (int ix = 0; ix < arr.length; ix++) {
  846. if (arr[ix][0][0].equalsIgnoreCase(x)) {
  847. for (int iy = 0; iy < arr[ix].length; iy++) {
  848. if (arr[ix][iy][0].equalsIgnoreCase(y)) {
  849. // log.log(Level.INFO, "751");
  850. if (z.equalsIgnoreCase("") || y.equalsIgnoreCase("all")) {
  851. // log.log(Level.INFO, "753");
  852. arr[ix][iy][0] = "";
  853. }
  854. else {
  855. // log.log(Level.INFO, "757");
  856. for (int iz = 0; iz < arr[ix][iy].length; iz++) {
  857. if (arr[ix][iy][iz].equalsIgnoreCase(z) || y.equalsIgnoreCase("all")) {
  858. arr[ix][iy][iz] = "";
  859. }
  860. }
  861. }
  862. }
  863. else if (arr[ix][iy][0].equalsIgnoreCase(z) || y.equalsIgnoreCase("all")) {
  864. // log.log(Level.INFO, "766");
  865. arr[ix][iy][0] = "";
  866. }
  867. if (z.equalsIgnoreCase("") && !insideArr(TAGS, y)) {
  868. // log.log(Level.INFO, "770");
  869. for (int iz = 0; iz < arr[ix][iy].length; iz++) {
  870. if (arr[ix][iy][iz].equalsIgnoreCase(y) || y.equalsIgnoreCase("all")) {
  871. arr[ix][iy][iz] = "";
  872. }
  873. }
  874. }
  875. }
  876. }
  877. }
  878. return shrink(arr);
  879. }
  880. public boolean printCommands(Player player, final String tag, final String section, String[] arr) {
  881. boolean isCom = false;
  882. String msg = "";
  883. if (arr.length >= 2) {
  884. for (int x = 1; x < arr.length; x++) {
  885. msg += arr[x];
  886. if ((x + 1) != arr.length) {
  887. if (!arr[x + 1].equalsIgnoreCase("")) {
  888. msg += ":";
  889. }
  890. }
  891. }
  892. }
  893. if (section.equalsIgnoreCase("name") && !msg.equalsIgnoreCase("")) {
  894. isCom = true;
  895. if (tag.equalsIgnoreCase("onlogin")) {
  896. player.sendMessage("[" + Colors.Yellow + "CommandOn" + Colors.White + "] OnLogin: " + msg);
  897. }
  898. else if (tag.equalsIgnoreCase("onlogout")) {
  899. player.sendMessage("[" + Colors.Yellow + "CommandOn" + Colors.White + "] OnLogout: " + msg);
  900. }
  901. else if (tag.equalsIgnoreCase("ondeath")) {
  902. player.sendMessage("[" + Colors.Yellow + "CommandOn" + Colors.White + "] OnDeath: " + msg);
  903. }
  904. else if (tag.equalsIgnoreCase("onrespawn")) {
  905. player.sendMessage("[" + Colors.Yellow + "CommandOn" + Colors.White + "] OnRespawn: " + msg);
  906. }
  907. }
  908. else if (!msg.equalsIgnoreCase("")) {
  909. isCom = true;
  910. if (insideArr(TAGS, tag)) {
  911. player.sendMessage("[" + Colors.Red + "CommandOnAdmin" + Colors.White + "] " + arr[0] + ":" + msg);
  912. }
  913. }
  914. return isCom;
  915. }
  916. public void test(Player p) {
  917. for (String s : p.getGroups()) {
  918. p.sendMessage("Testing, " + s);
  919. }
  920. }
  921. public boolean checkCommands(Player player, final String tag, final String list, final Battle batt) {
  922. boolean isCom = false;
  923. try {
  924. for (int x = 0; x < gC.length; x++) {
  925. if (gC[x][0][0].equalsIgnoreCase(tag)) {
  926. for (int y = 0; y < gC[x].length; y++) {
  927. if (tag.equalsIgnoreCase("onserverstart")) {
  928. if (gC[x][y][0].equalsIgnoreCase("default") && (!list.equalsIgnoreCase("all"))) {
  929. runServerCommands(gC[x][y]);
  930. }
  931. else if (list.equalsIgnoreCase("all")) {
  932. printCommands(player, tag, "all", gC[x][y]);
  933. }
  934. else if (!list.equalsIgnoreCase("")) {
  935. log
  936. .log(
  937. Level.INFO,
  938. ("[" + Colors.Yellow + "CommandOn" + Colors.White + "] Invalid section for OnServerStart, only use default."));
  939. }
  940. }
  941. else {
  942. if (player.getGroups().length >= 1) {
  943. if ((player.getGroups()[0].equalsIgnoreCase(gC[x][y][0]) && (!gC[x][y][0].equalsIgnoreCase("default")) && !list
  944. .equalsIgnoreCase("name"))
  945. || (list.equalsIgnoreCase("all"))) {
  946. if (list.equalsIgnoreCase("all")) {
  947. printCommands(player, tag, "all", gC[x][y]);
  948. }
  949. else if (!checkIgnore(player, tag, "group")) {
  950. runCommands(player, gC[x][y], batt);
  951. }
  952. }
  953. }
  954. else {
  955. if ((gC[x][y][0].equalsIgnoreCase("nogroup") && !list.equalsIgnoreCase("all") && !list
  956. .equalsIgnoreCase("name"))) {
  957. if (list.equalsIgnoreCase("nogroup")) {
  958. printCommands(player, tag, "nogroup", gC[x][y]);
  959. }
  960. else {
  961. runCommands(player, gC[x][y], batt);
  962. }
  963. }
  964. }
  965. if ((gC[x][y][0].equalsIgnoreCase("default") && !list.equalsIgnoreCase("all") && !list.equalsIgnoreCase("name"))) {
  966. if (list.equalsIgnoreCase("default")) {
  967. printCommands(player, tag, "default", gC[x][y]);
  968. }
  969. else if (!checkIgnore(player, tag, "default")) {
  970. runCommands(player, gC[x][y], batt);
  971. }
  972. }
  973. if ((gC[x][y][0].equalsIgnoreCase(player.getName())
  974. && ((list.equalsIgnoreCase("name")) || (list.equalsIgnoreCase(""))) && !list.equalsIgnoreCase("all"))) {
  975. if (list.equalsIgnoreCase("name") || list.equalsIgnoreCase("pname")) {
  976. isCom = printCommands(player, tag, "name", gC[x][y]);
  977. }
  978. else if (!checkIgnore(player, tag, "name")) {
  979. runCommands(player, gC[x][y], batt);
  980. }
  981. }
  982. }
  983. }
  984. }
  985. }
  986. }
  987. catch (Exception e) {
  988. e.printStackTrace();
  989. }
  990. return isCom;
  991. }
  992. public void list(Player player, final String tag) {
  993. // List the commands for each tag
  994. if (tag.equalsIgnoreCase("all")) {
  995. for (String tagIter : TAGS) {
  996. player.sendMessage("[" + Colors.Red + "CommandOnAdmin" + Colors.White + "] Listing commands for " + tagIter);
  997. checkCommands(player, tagIter, "all", null);
  998. }
  999. }
  1000. else if (insideArr(TAGS, tag)) {
  1001. for (int i = 0; i < TAGS.length; i++) {
  1002. if (TAGS[i].equalsIgnoreCase(tag)) {
  1003. player.sendMessage("[" + Colors.Red + "CommandOnAdmin" + Colors.White + "] Listing commands for " + TAGS[i]);
  1004. checkCommands(player, tag, "all", null);
  1005. }
  1006. }
  1007. }
  1008. else {
  1009. help(player, "coa list");
  1010. }
  1011. }
  1012. public void help(Player player, final String command) {
  1013. if (command.equalsIgnoreCase("general")) {
  1014. player.sendMessage("[" + Colors.Yellow + "CommandOn" + Colors.White + "] Usage is: \"/co [me,ignore,allow,help]\"");
  1015. }
  1016. else if (command.equalsIgnoreCase("help")) {
  1017. player.sendMessage("[" + Colors.Yellow + "CommandOn" + Colors.White + "] Usage is: \"/co help [tag,section,ignore,allow,me]");
  1018. }
  1019. else if (command.equalsIgnoreCase("tag") || command.equalsIgnoreCase("tags")) {
  1020. player.sendMessage("[" + Colors.Yellow + "CommandOn" + Colors.White + "] A tag relates to an event's commands");
  1021. String t = "";
  1022. for (int i = 0; i < TAGS.length; i++) {
  1023. t += TAGS[i];
  1024. if (i + 1 < TAGS.length) {
  1025. t += ", ";
  1026. }
  1027. }
  1028. player.sendMessage("[" + Colors.Yellow + "CommandOn" + Colors.White + "] Valid tags are: " + t);
  1029. }
  1030. else if (command.equalsIgnoreCase("section")) {
  1031. player.sendMessage("[" + Colors.Yellow + "CommandOn" + Colors.White + "] A section is a group, or a player name.");
  1032. String t = "";
  1033. for (int i = 0; i < TAGS.length; i++) {
  1034. t += SECTIONS[i];
  1035. if (i + 1 < SECTIONS.length) {
  1036. t += ", ";
  1037. }
  1038. }
  1039. player.sendMessage("[" + Colors.Yellow + "CommandOn" + Colors.White + "] Valid sections are: " + t);
  1040. }
  1041. else if (command.equalsIgnoreCase("ignore")) {
  1042. player.sendMessage("[" + Colors.Yellow + "CommandOn" + Colors.White + "] Ignores commands from a given tag and section.");
  1043. player.sendMessage("[" + Colors.Yellow + "CommandOn" + Colors.White + "] Useage is \"/co ignore [tag] [section]\"");
  1044. player.sendMessage("[" + Colors.Yellow + "CommandOn" + Colors.White
  1045. + "] For a list of tags or sections \"/co help [tag,section]");
  1046. }
  1047. else if (command.equalsIgnoreCase("allow")) {
  1048. player.sendMessage("[" + Colors.Yellow + "CommandOn" + Colors.White + "] Allows commands from a given tag and section to run.");
  1049. player.sendMessage("[" + Colors.Yellow + "CommandOn" + Colors.White + "] Useage is \"/co allow [tag] [section]\"");
  1050. player.sendMessage("[" + Colors.Yellow + "CommandOn" + Colors.White
  1051. + "] For a list of tags or sections \"/co help [tag,section]");
  1052. }
  1053. else if (command.equalsIgnoreCase("me")) {
  1054. player.sendMessage("[" + Colors.Yellow + "CommandOn" + Colors.White
  1055. + "] Displays the plugins info on you. This includes ignored commands, and any name commands.");
  1056. player.sendMessage("[" + Colors.Yellow + "CommandOn" + Colors.White + "] Useage is \"/co me [ignore,command]\"");
  1057. }
  1058. else if (command.equalsIgnoreCase("admin")) {
  1059. player.sendMessage("[" + Colors.Red + "CommandOnAdmin" + Colors.White + "] /co admin [add,remove,list]");
  1060. }
  1061. else if (command.equalsIgnoreCase("vars")) {
  1062. player.sendMessage("[" + Colors.Red + "CommandOnAdmin" + Colors.White
  1063. + "] Variables are for use in commands and are case sensitive.");
  1064. player.sendMessage("[" + Colors.Red + "CommandOnAdmin" + Colors.White + "] Valid variables for commands are:");
  1065. String temp = "";
  1066. for (int i = 0; i < VARS.length; i++) {
  1067. temp += VARS[i];
  1068. if (i + 1 < VARS.length) {
  1069. temp += ", ";
  1070. }
  1071. }
  1072. player.sendMessage("[" + Colors.Red + "CommandOnAdmin" + Colors.White + "] " + temp);
  1073. }
  1074. else if (command.equalsIgnoreCase("coa wipe") || command.equalsIgnoreCase("wipe")) {
  1075. player.sendMessage("[" + Colors.Red + "CommandOnAdmin" + Colors.White + "] Clears the file specified.");
  1076. player.sendMessage("[" + Colors.Red + "CommandOnAdmin" + Colors.White + "] Usage \"/co admin wipe [ignore,command]\"");
  1077. }
  1078. else if (command.equalsIgnoreCase("coa list") || command.equalsIgnoreCase("list")) {
  1079. player.sendMessage("[" + Colors.Red + "CommandOnAdmin" + Colors.White + "] Lists the command sections for a given tag.");
  1080. player.sendMessage("[" + Colors.Red + "CommandOnAdmin" + Colors.White + "] Usage is \"/co admin list [tag,all]\"");
  1081. player.sendMessage("[" + Colors.Yellow + "CommandOn" + Colors.White + "] For a list of tags \"/co help tag");
  1082. }
  1083. else if (command.equalsIgnoreCase("coa add") || command.equalsIgnoreCase("add")) {
  1084. player.sendMessage("[" + Colors.Red + "CommandOnAdmin" + Colors.White + "] Adds the given command to the command list.");
  1085. player.sendMessage("[" + Colors.Red + "CommandOnAdmin" + Colors.White
  1086. + "] Usage is \"/co admin add [tag] [section] [command]\"");
  1087. player.sendMessage("[" + Colors.Red + "CommandOnAdmin" + Colors.White
  1088. + "] For a list of tags or sections \"/co help [tag,section]");
  1089. player.sendMessage("[" + Colors.Red + "CommandOnAdmin" + Colors.White + "] For a list of useable variables \"/co help vars\"");
  1090. }
  1091. else if (command.equalsIgnoreCase("coa remove") || command.equalsIgnoreCase("remove")) {
  1092. player.sendMessage("[" + Colors.Red + "CommandOnAdmin" + Colors.White
  1093. + "] Removes the given command from the command list. Spell exactly.");
  1094. player.sendMessage("[" + Colors.Red + "CommandOnAdmin" + Colors.White
  1095. + "] Usage is \"/co admin remove [tag] [section] [command]\"");
  1096. player.sendMessage("[" + Colors.Yellow + "CommandOn" + Colors.White
  1097. + "] For a list of tags or sections \"/co help [tag,section]");
  1098. }
  1099. else if (command.equalsIgnoreCase("coa read") || command.equalsIgnoreCase("read")) {
  1100. player.sendMessage("[" + Colors.Red + "CommandOnAdmin" + Colors.White + "] Reads the array data from the file.");
  1101. }
  1102. else if (command.equalsIgnoreCase("coa write") || command.equalsIgnoreCase("write")) {
  1103. player.sendMessage("[" + Colors.Red + "CommandOnAdmin" + Colors.White + "] Writes the array data to the file.");
  1104. }
  1105. else {
  1106. help(player, "general");
  1107. }
  1108. }
  1109. public String[][][] addYZ(final String x, final String y, final String z, String[][][] arr) {
  1110. int xpos = -1;
  1111. int ypos = -1;
  1112. int zpos = -1;
  1113. int xdim = arr.length;
  1114. int ydim = arr[0].length;
  1115. int zdim = arr[0][0].length;
  1116. for (int xl = 0; xl < arr.length; xl++) {
  1117. if (arr[xl][0][0].equalsIgnoreCase(x)) {
  1118. xpos = xl;
  1119. if (debug)
  1120. log.log(Level.INFO, "Xpos is: " + xpos);
  1121. for (int yl = 0; yl < arr[xl].length; yl++) {
  1122. if (arr[xl][yl][0].equalsIgnoreCase(y) && (ypos == -1)) {
  1123. ypos = yl;
  1124. if (debug)
  1125. log.log(Level.INFO, "990 Ypos is: " + ypos);
  1126. for (int zl = 0; zl < arr[xl][yl].length; zl++) {
  1127. if (arr[xl][yl][zl].equalsIgnoreCase("")) {
  1128. zpos = zl;
  1129. }
  1130. }
  1131. if (zpos == -1) {
  1132. zpos = zdim;
  1133. zdim++;
  1134. }
  1135. }
  1136. else if (arr[xl][yl][0].equalsIgnoreCase("") && (ypos == -1)) {
  1137. ypos = yl;
  1138. if (debug)
  1139. log.log(Level.INFO, "1003 Ypos is: " + ypos);
  1140. for (int zl = 0; zl < arr[xl][yl].length; zl++) {
  1141. if (arr[xl][yl][zl].equalsIgnoreCase("")) {
  1142. zpos = zl;
  1143. }
  1144. }
  1145. if (zpos == -1) {
  1146. zpos = zdim;
  1147. zdim++;
  1148. }
  1149. }
  1150. else if ((yl == arr[xl].length - 1) && (ypos == -1)) {
  1151. ypos = ydim;
  1152. if (debug)
  1153. log.log(Level.INFO, "1016 Ypos is: " + ypos);
  1154. ydim++;
  1155. if (zdim < 2) {
  1156. zdim++;
  1157. }
  1158. zpos = 1;
  1159. }
  1160. }
  1161. }
  1162. else if ((xpos == -1) && (xl == arr.length - 1)) {
  1163. xpos = xdim;
  1164. xdim++;
  1165. if (ydim < 2) {
  1166. ydim++;
  1167. }
  1168. if ((zdim < 2) && ((z != "") || (zdim == 1))) {
  1169. zdim++;
  1170. }
  1171. ypos = 1;
  1172. // log.log(Level.INFO, "1038 Ypos is: " + ypos);
  1173. zpos = 1;
  1174. }
  1175. }
  1176. String[][][] tarr = new String[xdim][ydim][zdim];
  1177. copyArray(arr, tarr);
  1178. tarr[xpos][0][0] = x;
  1179. tarr[xpos][ypos][0] = y;
  1180. tarr[xpos][ypos][zpos] = z;
  1181. removeNull(tarr);
  1182. // printArray(tarr);
  1183. arr = tarr;
  1184. if (debug)
  1185. printArray(arr);
  1186. return shrink(arr);
  1187. }
  1188. public void ignore(Player player, final String tag, final String section) {
  1189. if (insideArr(SECTIONS, tag)) {
  1190. if (tag.equalsIgnoreCase("all")) {
  1191. if (!checkIgnore(player, "", "")) {
  1192. player.sendMessage("[" + Colors.Yellow + "CommandOn" + Colors.White + "] You are now set to ignore all sections.");
  1193. pI = addYZ(player.getName(), tag, "", pI);
  1194. // printArray(pI);
  1195. writeToFile(pI, player_file);
  1196. }
  1197. else {
  1198. player.sendMessage("[" + Colors.Yellow + "CommandOn" + Colors.White + "] You are already set to ignore all sections.");
  1199. }
  1200. }
  1201. else {
  1202. if (!checkIgnore(player, tag, "")) {
  1203. player.sendMessage("[" + Colors.Yellow + "CommandOn" + Colors.White + "] You are now set to ignore all " + tag
  1204. + " sections.");
  1205. // printArray(pI);
  1206. pI = addYZ(player.getName(), tag, "", pI);
  1207. writeToFile(pI, player_file);
  1208. }
  1209. else {
  1210. player.sendMessage("[" + Colors.Yellow + "CommandOn" + Colors.White + "] You are lready set to ignore this section.");
  1211. }
  1212. }
  1213. }
  1214. else if (insideArr(TAGS, tag)) {
  1215. if (insideArr(SECTIONS, section)) {
  1216. if (section.equalsIgnoreCase("all")) {
  1217. if (!checkIgnore(player, tag, section)) {
  1218. player.sendMessage("[" + Colors.Yellow + "CommandOn" + Colors.White + "] You are now set to ignore the " + tag
  1219. + " tag.");
  1220. // printArray(pI);
  1221. pI = addYZ(player.getName(), tag, section, pI);
  1222. writeToFile(pI, player_file);
  1223. }
  1224. else {
  1225. player.sendMessage("[" + Colors.Yellow + "CommandOn" + Colors.White + "] You are already set to ignore this tag.");
  1226. }
  1227. }
  1228. else {
  1229. if (!checkIgnore(player, tag, section)) {
  1230. player.sendMessage("[" + Colors.Yellow + "CommandOn" + Colors.White + "] You are now set to ignore the " + section
  1231. + " section for " + tag + ".");
  1232. // printArray(pI);
  1233. pI = addYZ(player.getName(), tag, section, pI);
  1234. writeToFile(pI, player_file);
  1235. }
  1236. else {
  1237. player.sendMessage("[" + Colors.Yellow + "CommandOn" + Colors.White
  1238. + "] You are already set to ignore this section.");
  1239. }
  1240. }
  1241. }
  1242. else {
  1243. help(player, "ignore");
  1244. }
  1245. }
  1246. else {
  1247. help(player, "ignore");
  1248. }
  1249. // printArray(pI);
  1250. }
  1251. public void allow(Player player, final String tag, final String section) {
  1252. if (!checkIgnore(player, tag, section) && !tag.equalsIgnoreCase("all")) {
  1253. player.sendMessage("[" + Colors.Yellow + "CommandOn" + Colors.White + "] You already allow this.");
  1254. }
  1255. else {
  1256. pI = removeYZ(player.getName(), tag, section, pI);
  1257. // pI = shrink(pI);
  1258. if (section.equalsIgnoreCase("")) {
  1259. player.sendMessage("[" + Colors.Yellow + "CommandOn" + Colors.White + "] You have allowed " + tag + " commands.");
  1260. }
  1261. else {
  1262. player.sendMessage("[" + Colors.Yellow + "CommandOn" + Colors.White + "] You have allowed the " + section + " section of "
  1263. + tag + ".");
  1264. }
  1265. // printArray(pI);
  1266. writeToFile(pI, player_file);
  1267. }
  1268. }
  1269. public void writeToFile(String[][][] arr, File file) {
  1270. BufferedWriter file_writer = null;
  1271. try {
  1272. if (file.exists()) {
  1273. file_writer = new BufferedWriter(new FileWriter(file));
  1274. for (int x = 0; x < arr.length; x++) {
  1275. file_writer.write("## " + arr[x][0][0]);
  1276. for (int y = 0; y < arr[x].length; y++) {
  1277. if (!arr[x][y][0].equalsIgnoreCase("")) {
  1278. for (int z = 0; z < arr[x][y].length; z++) {
  1279. if (!arr[x][y][z].equalsIgnoreCase("") && (z == 0) && (!arr[x][y][z].equalsIgnoreCase(arr[x][0][0]))) {
  1280. file_writer.newLine();
  1281. file_writer.write(arr[x][y][z]);
  1282. }
  1283. else if (!arr[x][y][z].equalsIgnoreCase("") && (!arr[x][y][z].equalsIgnoreCase(arr[x][0][0]))) {
  1284. file_writer.write(":" + arr[x][y][z]);
  1285. }
  1286. }
  1287. }
  1288. }
  1289. file_writer.newLine();
  1290. }
  1291. file_writer.close();
  1292. }
  1293. }
  1294. catch (Exception e) {
  1295. e.printStackTrace();
  1296. }
  1297. }
  1298. public void me(Player player, final String com) {
  1299. if (com.equalsIgnoreCase("")) {
  1300. player.sendMessage("[" + Colors.Yellow + "CommandOn" + Colors.White
  1301. + "] Use \"/co me ignore\" to list your ignored command lists.");
  1302. player.sendMessage("[" + Colors.Yellow + "CommandOn" + Colors.White
  1303. + "] Use \"/co me command\" to list your name command lists.");
  1304. }
  1305. else if (com.equalsIgnoreCase("command")) {
  1306. player.sendMessage("[" + Colors.Yellow + "CommandOn" + Colors.White + "] Your name specific commands are: ");
  1307. // List name commands
  1308. boolean has = false;
  1309. for (String temp : TAGS) {
  1310. if (!temp.equalsIgnoreCase("onserverstart")) {
  1311. if (checkCommands(player, temp, "name", null)) {
  1312. has = true;
  1313. }
  1314. }
  1315. }
  1316. if (!has) {
  1317. player.sendMessage("[" + Colors.Yellow + "CommandOn" + Colors.White + "] No commands found.");
  1318. }
  1319. }
  1320. else if (com.equalsIgnoreCase("ignore")) {
  1321. // New way
  1322. boolean first = true;
  1323. boolean isIgnore = false;
  1324. for (String tagIter : TAGS) {
  1325. if (!tagIter.equalsIgnoreCase("onserverstart")) {
  1326. String tempMsg = "";
  1327. for (String sectionIter : SECTIONS) {
  1328. if (checkIgnore(player, tagIter, sectionIter)) {
  1329. if (tempMsg.equalsIgnoreCase("")) {
  1330. tempMsg += " " + sectionIter;
  1331. }
  1332. else {
  1333. tempMsg += ", " + sectionIter;
  1334. }
  1335. }
  1336. }
  1337. if (!tempMsg.equalsIgnoreCase("")) {
  1338. if (first) {
  1339. player.sendMessage("[" + Colors.Yellow + "CommandOn" + Colors.White + "] You are set to ignore:");
  1340. first = false;
  1341. }
  1342. isIgnore = true;
  1343. player.sendMessage("[" + Colors.Yellow + "CommandOn" + Colors.White + "] " + tagIter + ":" + tempMsg);
  1344. }
  1345. }
  1346. }
  1347. if (!isIgnore) {
  1348. player.sendMessage("[" + Colors.Yellow + "CommandOn" + Colors.White + "] You are not set to ignore anything.");
  1349. }
  1350. }
  1351. }
  1352. public boolean isAbb(final String s) {
  1353. if (s.equalsIgnoreCase("/co")) {
  1354. return true;
  1355. }
  1356. else if (s.equalsIgnoreCase("/commandon")) {
  1357. return true;
  1358. }
  1359. else if (s.equalsIgnoreCase("/con")) {
  1360. return true;
  1361. }
  1362. return false;
  1363. }
  1364. public void removeFromList(final String tag, final String section, final String command) {
  1365. gC =