|
| 1 | + |
| 2 | + |
| 3 | + |
| 4 | + |
| 5 | +package com.gamesense.client.command.commands; |
| 6 | + |
| 7 | +import com.gamesense.client.command.*; |
| 8 | +import com.gamesense.api.util.misc.*; |
| 9 | +import com.google.gson.*; |
| 10 | +import com.gamesense.client.module.modules.combat.*; |
| 11 | +import net.minecraft.item.*; |
| 12 | +import java.util.*; |
| 13 | +import java.io.*; |
| 14 | + |
| 15 | +public class AutoGearCommand extends Command |
| 16 | +{ |
| 17 | + private static final String pathSave = "KiefSense/Misc/AutoGear.json"; |
| 18 | + private static final HashMap<String, String> errorMessage; |
| 19 | + |
| 20 | + public AutoGearCommand() { |
| 21 | + super("AutoGear"); |
| 22 | + this.setCommandSyntax(Command.getCommandPrefix() + "gear set/save/del/list [name]"); |
| 23 | + this.setCommandAlias(new String[] { "gear", "gr", "kit" }); |
| 24 | + } |
| 25 | + |
| 26 | + public void onCommand(final String command, final String[] message) throws Exception { |
| 27 | + final String lowerCase = message[0].toLowerCase(); |
| 28 | + switch (lowerCase) { |
| 29 | + case "list": { |
| 30 | + if (message.length == 1) { |
| 31 | + this.listMessage(); |
| 32 | + break; |
| 33 | + } |
| 34 | + errorMessage("NoPar"); |
| 35 | + break; |
| 36 | + } |
| 37 | + case "set": { |
| 38 | + if (message.length == 2) { |
| 39 | + this.set(message[1]); |
| 40 | + break; |
| 41 | + } |
| 42 | + errorMessage("NoPar"); |
| 43 | + break; |
| 44 | + } |
| 45 | + case "save": |
| 46 | + case "add": |
| 47 | + case "create": { |
| 48 | + if (message.length == 2) { |
| 49 | + this.save(message[1]); |
| 50 | + break; |
| 51 | + } |
| 52 | + errorMessage("NoPar"); |
| 53 | + break; |
| 54 | + } |
| 55 | + case "del": { |
| 56 | + if (message.length == 2) { |
| 57 | + this.delete(message[1]); |
| 58 | + break; |
| 59 | + } |
| 60 | + errorMessage("NoPar"); |
| 61 | + break; |
| 62 | + } |
| 63 | + default: { |
| 64 | + MessageBus.sendCommandMessage("AutoGear message is: gear set/save/del/list [name]", true); |
| 65 | + break; |
| 66 | + } |
| 67 | + } |
| 68 | + } |
| 69 | + |
| 70 | + private void listMessage() { |
| 71 | + JsonObject completeJson = new JsonObject(); |
| 72 | + try { |
| 73 | + completeJson = new JsonParser().parse((Reader)new FileReader("KiefSense/Misc/AutoGear.json")).getAsJsonObject(); |
| 74 | + for (int lenghtJson = completeJson.entrySet().size(), i = 0; i < lenghtJson; ++i) { |
| 75 | + final String item = new JsonParser().parse((Reader)new FileReader("KiefSense/Misc/AutoGear.json")).getAsJsonObject().entrySet().toArray()[i].toString().split("=")[0]; |
| 76 | + if (!item.equals("pointer")) { |
| 77 | + PistonCrystal.printChat("Kit avaible: " + item, false); |
| 78 | + } |
| 79 | + } |
| 80 | + } |
| 81 | + catch (IOException e) { |
| 82 | + errorMessage("NoEx"); |
| 83 | + } |
| 84 | + } |
| 85 | + |
| 86 | + private void delete(final String name) { |
| 87 | + JsonObject completeJson = new JsonObject(); |
| 88 | + try { |
| 89 | + completeJson = new JsonParser().parse((Reader)new FileReader("KiefSense/Misc/AutoGear.json")).getAsJsonObject(); |
| 90 | + if (completeJson.get(name) != null && !name.equals("pointer")) { |
| 91 | + completeJson.remove(name); |
| 92 | + if (completeJson.get("pointer").getAsString().equals(name)) { |
| 93 | + completeJson.addProperty("pointer", "none"); |
| 94 | + } |
| 95 | + this.saveFile(completeJson, name, "deleted"); |
| 96 | + } |
| 97 | + else { |
| 98 | + errorMessage("NoEx"); |
| 99 | + } |
| 100 | + } |
| 101 | + catch (IOException e) { |
| 102 | + errorMessage("NoEx"); |
| 103 | + } |
| 104 | + } |
| 105 | + |
| 106 | + private void set(final String name) { |
| 107 | + JsonObject completeJson = new JsonObject(); |
| 108 | + try { |
| 109 | + completeJson = new JsonParser().parse((Reader)new FileReader("KiefSense/Misc/AutoGear.json")).getAsJsonObject(); |
| 110 | + if (completeJson.get(name) != null && !name.equals("pointer")) { |
| 111 | + completeJson.addProperty("pointer", name); |
| 112 | + this.saveFile(completeJson, name, "selected"); |
| 113 | + } |
| 114 | + else { |
| 115 | + errorMessage("NoEx"); |
| 116 | + } |
| 117 | + } |
| 118 | + catch (IOException e) { |
| 119 | + errorMessage("NoEx"); |
| 120 | + } |
| 121 | + } |
| 122 | + |
| 123 | + private void save(final String name) { |
| 124 | + JsonObject completeJson = new JsonObject(); |
| 125 | + try { |
| 126 | + completeJson = new JsonParser().parse((Reader)new FileReader("KiefSense/Misc/AutoGear.json")).getAsJsonObject(); |
| 127 | + if (completeJson.get(name) != null && !name.equals("pointer")) { |
| 128 | + errorMessage("Exist"); |
| 129 | + return; |
| 130 | + } |
| 131 | + } |
| 132 | + catch (IOException e) { |
| 133 | + completeJson.addProperty("pointer", "none"); |
| 134 | + } |
| 135 | + final StringBuilder jsonInventory = new StringBuilder(); |
| 136 | + for (final ItemStack item : AutoGearCommand.mc.player.inventory.mainInventory) { |
| 137 | + jsonInventory.append(item.getItem().getRegistryName().toString() + item.getMetadata()).append(" "); |
| 138 | + } |
| 139 | + completeJson.addProperty(name, jsonInventory.toString()); |
| 140 | + this.saveFile(completeJson, name, "saved"); |
| 141 | + } |
| 142 | + |
| 143 | + private void saveFile(final JsonObject completeJson, final String name, final String operation) { |
| 144 | + try { |
| 145 | + final BufferedWriter bw = new BufferedWriter(new FileWriter("KiefSense/Misc/AutoGear.json")); |
| 146 | + bw.write(completeJson.toString()); |
| 147 | + bw.close(); |
| 148 | + PistonCrystal.printChat("Kit " + name + " " + operation, false); |
| 149 | + } |
| 150 | + catch (IOException e) { |
| 151 | + errorMessage("Saving"); |
| 152 | + } |
| 153 | + } |
| 154 | + |
| 155 | + private static void errorMessage(final String e) { |
| 156 | + PistonCrystal.printChat("Error: " + AutoGearCommand.errorMessage.get(e), true); |
| 157 | + } |
| 158 | + |
| 159 | + public static String getCurrentSet() { |
| 160 | + JsonObject completeJson = new JsonObject(); |
| 161 | + try { |
| 162 | + completeJson = new JsonParser().parse((Reader)new FileReader("KiefSense/Misc/AutoGear.json")).getAsJsonObject(); |
| 163 | + if (!completeJson.get("pointer").getAsString().equals("none")) { |
| 164 | + return completeJson.get("pointer").getAsString(); |
| 165 | + } |
| 166 | + } |
| 167 | + catch (IOException ex) {} |
| 168 | + errorMessage("NoEx"); |
| 169 | + return ""; |
| 170 | + } |
| 171 | + |
| 172 | + public static String getInventoryKit(final String kit) { |
| 173 | + JsonObject completeJson = new JsonObject(); |
| 174 | + try { |
| 175 | + completeJson = new JsonParser().parse((Reader)new FileReader("KiefSense/Misc/AutoGear.json")).getAsJsonObject(); |
| 176 | + return completeJson.get(kit).getAsString(); |
| 177 | + } |
| 178 | + catch (IOException ex) { |
| 179 | + errorMessage("NoEx"); |
| 180 | + return ""; |
| 181 | + } |
| 182 | + } |
| 183 | + |
| 184 | + static { |
| 185 | + errorMessage = new HashMap<String, String>() { |
| 186 | + { |
| 187 | + this.put("NoPar", "Not enough parameters"); |
| 188 | + this.put("Exist", "This kit arleady exist"); |
| 189 | + this.put("Saving", "Error saving the file"); |
| 190 | + this.put("NoEx", "Kit not found"); |
| 191 | + } |
| 192 | + }; |
| 193 | + } |
| 194 | +} |
0 commit comments