1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
|
package rosegoldaddons.commands;
import com.google.gson.Gson;
import net.minecraft.client.Minecraft;
import net.minecraft.command.CommandException;
import net.minecraft.command.ICommand;
import net.minecraft.command.ICommandSender;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.BlockPos;
import org.jetbrains.annotations.NotNull;
import rosegoldaddons.utils.ChatUtils;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
public class UseCooldown implements ICommand {
public static HashMap<String, Integer> RCitems = new HashMap<String, Integer>();
public static HashMap<String, Integer> LCitems = new HashMap<String, Integer>();
@Override
public String getCommandName() {
return "usecooldown";
}
@Override
public String getCommandUsage(ICommandSender sender) {
return "/" + getCommandName();
}
@Override
public List<String> getCommandAliases() {
return new ArrayList<>();
}
@Override
public void processCommand(ICommandSender sender, String[] args) throws CommandException {
if (args.length == 0) {
for (String i : RCitems.keySet()) {
ChatUtils.sendMessage("§7Right click macro set on " + i + " §7with cooldown of " + RCitems.get(i) + " ms.");
}
for (String i : LCitems.keySet()) {
ChatUtils.sendMessage("§7Left click macro set on " + i + " §7with cooldown of " + LCitems.get(i) + " ms.");
}
saveMacros();
return;
}
if (args.length == 1 && isNumeric(args[0])) {
InventoryPlayer inv = Minecraft.getMinecraft().thePlayer.inventory;
ItemStack curStack = inv.getStackInSlot(Minecraft.getMinecraft().thePlayer.inventory.currentItem);
if (curStack != null) {
int cd = Integer.parseInt(args[0]);
if (cd == 0) {
RCitems.remove(curStack.getDisplayName());
ChatUtils.sendMessage("§aSuccessfully Removed " + curStack.getDisplayName() + "§a.");
saveMacros();
return;
}
if (cd < 100) {
ChatUtils.sendMessage("§cInvalid Miliseconds, Minimum delay 100 Milisecond.");
saveMacros();
return;
}
RCitems.put(curStack.getDisplayName(), cd);
ChatUtils.sendMessage("§aSuccessfully Added " + curStack.getDisplayName() + "§a to right click with a delay of " + cd + " ms.");
saveMacros();
} else {
ChatUtils.sendMessage("§cError getting current held item.");
}
} else if (args.length == 2 && isNumeric(args[0]) && args[1].equalsIgnoreCase("left")) {
InventoryPlayer inv = Minecraft.getMinecraft().thePlayer.inventory;
ItemStack curStack = inv.getStackInSlot(Minecraft.getMinecraft().thePlayer.inventory.currentItem);
if (curStack != null) {
int cd = Integer.parseInt(args[0]);
if (cd == 0) {
LCitems.remove(curStack.getDisplayName());
ChatUtils.sendMessage("§aSuccessfully Removed " + curStack.getDisplayName() + "§a.");
saveMacros();
return;
}
if (cd < 100) {
ChatUtils.sendMessage("§cInvalid Miliseconds, Minimum delay 100 Milisecond.");
saveMacros();
return;
}
ChatUtils.sendMessage("§aSuccessfully Added " + curStack.getDisplayName() + "§a to left click with a delay of " + cd + " ms.");
LCitems.put(curStack.getDisplayName(), cd);
saveMacros();
} else {
ChatUtils.sendMessage("§cError getting current held item.");
}
} else {
ChatUtils.sendMessage("§cInvalid Arguments.");
}
}
@Override
public boolean canCommandSenderUseCommand(ICommandSender sender) {
return true;
}
@Override
public List<String> addTabCompletionOptions(ICommandSender sender, String[] args, BlockPos pos) {
return new ArrayList<>();
}
@Override
public boolean isUsernameIndex(String[] args, int index) {
return false;
}
private boolean isNumeric(String str) {
try {
Double.parseDouble(str);
return true;
} catch (NumberFormatException e) {
return false;
}
}
private void saveMacros() {
try {
String rcjson = new Gson().toJson(RCitems);
Files.write(Paths.get("./config/rosegoldaddons/rcmacros.json"), rcjson.getBytes(StandardCharsets.UTF_8));
String lcjson = new Gson().toJson(LCitems);
Files.write(Paths.get("./config/rosegoldaddons/lcmacros.json"), lcjson.getBytes(StandardCharsets.UTF_8));
} catch(Exception error) {
System.out.println("Error saving config file");
error.printStackTrace();
}
/*File rcfile = new File("./config/rosegoldaddons/rcmacro.txt");
BufferedWriter bf = null;
try {
bf = new BufferedWriter(new FileWriter(rcfile));
for (HashMap.Entry<String, Integer> entry : RCitems.entrySet()) {
bf.write(entry.getKey() + ":" + entry.getValue());
bf.newLine();
}
bf.flush();
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
bf.close();
} catch (Exception e) {
}
}
File lcfile = new File("./config/rosegoldaddons/lcmacro.txt");
BufferedWriter bf2 = null;
try {
bf2 = new BufferedWriter(new FileWriter(lcfile));
for (HashMap.Entry<String, Integer> entry : LCitems.entrySet()) {
bf2.write(entry.getKey() + ":" + entry.getValue());
bf2.newLine();
}
bf2.flush();
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
bf2.close();
} catch (Exception e) {
}
}*/
}
@Override
public int compareTo(@NotNull ICommand o) {
return 0;
}
}
|