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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
|
package net.uomc.mineshaft;
import net.uomc.mineshaft.crafting.Crafting;
import net.uomc.mineshaft.farm.CompostCommand;
import net.uomc.mineshaft.farm.FarmCommand;
import net.uomc.mineshaft.farm.TradeCommand;
import net.uomc.mineshaft.resources.Resource;
import java.io.IOException;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.stream.Collectors;
import javax.security.auth.login.LoginException;
import org.apache.commons.collections4.map.LinkedMap;
import org.json.JSONException;
import org.json.JSONObject;
import com.mouldycheerio.dbot.CustomBot;
import com.mouldycheerio.dbot.commands.AvatarCommand;
import com.mouldycheerio.dbot.commands.CommandDetails;
import com.mouldycheerio.dbot.commands.DetailedCommand;
import com.mouldycheerio.dbot.commands.ProfileCommand;
import com.mouldycheerio.dbot.commands.ServerInfoCommand;
import com.mouldycheerio.dbot.commands.cooldowns.CooldownCommand;
import com.mouldycheerio.dbot.logging.FullLogger;
import com.mouldycheerio.dbot.starboard.StarboardController;
import com.mouldycheerio.dbot.util.PeelingUtils;
import net.dv8tion.jda.api.entities.Member;
import net.uomc.mineshaft.resources.ResourceManager;
import net.uomc.mineshaft.resources.market.MarketCommand;
public class Mineshaft extends CustomBot {
private StarboardController starboardController;
private FullLogger logger;
private ResourceManager resourceManager;
private Pickaxes pickaxes;
private Crafting crafting;
private MineCommand mineCommand;
private EnchantCommand enchantCommand;
public Mineshaft(JSONObject config) throws LoginException, JSONException, IOException, InterruptedException {
super(config);
pickaxes = new Pickaxes(this);
crafting = new Crafting(this);
getCommandController().addCommand(crafting);
getCommandController().addCommand(new ProfileCommand());
getCommandController().addCommand(new AvatarCommand());
getCommandController().addCommand(new ServerInfoCommand());
starboardController = new StarboardController(this);
resourceManager = new ResourceManager(this);
getCommandController().addCommand(new MarketCommand(resourceManager.getMarketManager()));
getCommandController().addCommand(new DailyCommand(this));
enchantCommand = new EnchantCommand(this);
getCommandController().addCommand(enchantCommand);
getCommandController().addCommand(new FurnaceCommand(this));
getCommandController().addCommand(new PickaxeCommand(this));
getCommandController().addCommand(new Portal(this));
mineCommand = new MineCommand(this);
getCommandController().addCommand(mineCommand);
getCommandController().addCommand(new FishCommand(this));
getCommandController().addCommand(new RobCommand(this));
getCommandController().addCommand(new TradeCommand(this));
getCommandController().removeCommand("help");
getCommandController().addCommand(CommandDetails.from("help"), (e, b, args) -> {
String title = "Mineshaft";
StringBuilder notes = new StringBuilder();
notes.append("It's time to go mining!\n\n");
notes.append("**Mine** ores with `m!mine`, or **fish** with `m!fish`\n");
notes.append("Upgrade your **pickaxe** and find new ores `m!pickaxe`\n");
notes.append("**Craft** new items `m!craft`\n");
notes.append("Fight other players! `m!pvp`\n");
notes.append("Trade your resources `m!market` and `m!give`\n");
notes.append("Become the **top** valuable player `m!top`\n");
notes.append("\nGet free **daily** ores with `m!daily`\n");
sendMessage(e, title, notes.toString());
});
getCommandController().addCommand(CommandDetails.from("patchnotes,changelog"), (e, b, args) -> {
// TODO update when changes
String title = "Patch Notes";
StringBuilder notes = new StringBuilder();
notes.append("### v0.5.2\n");
notes.append("- Fix trader giving impossible item prices\n");
notes.append("- Items can only be given to players who are in the same dimension\n");
notes.append("### v0.5.1\n");
notes.append("- Kill only works if you are in the same dimension as the other player\n");
notes.append("- Farm cannot be accessed from the nether\n");
notes.append("- Added `m!top pickaxes`\n");
notes.append("### v0.5\n");
notes.append("- Added compostor\n");
notes.append(" - compost items with `m!compost`\n");
notes.append(" - The more compostors you own, the more items you can compost at a time\n");
notes.append("- Added farming `m!farm`\n");
notes.append(" - Crops can be planted and harvested\n");
notes.append(" - Size of farm can be expanded with bone meal\n");
notes.append("- Added villager item\n");
notes.append(" - Villagers allow you to trade with the wandering trader `m!trade`\n");
notes.append("- Added Carrots, Potatos and Sugar cane\n");
notes.append("- Added `m!top [item]` to list who has the most of an item\n");
notes.append("- Fixed `m!daily`\n");
notes.append("- Fixed typos\n");
notes.append("### v0.4\n");
notes.append("- Added nether\n");
notes.append(" - 10 obsidian can now be used to craft a portal\n");
notes.append(" - Nether spawns new ores \n");
notes.append("- Netherite pickaxe is now achievable\n");
notes.append("- Fishing will have a chance to give you string\n");
notes.append("- String can be crafted into wool and beds\n");
notes.append("- Added Efficiency enchantment\n");
notes.append(" - Further increases spawn rates of rarer ores\n");
notes.append("- Enchantments are now applied to `m!daily`'s loot\n");
notes.append("- Furnace can now be accessed every 30 minutes\n");
notes.append("- Added `m!market` for trading items\n");
notes.append("- Fix `m!give` to work properly\n");
//notes.append("### v0.3.1\n");
//notes.append("- Added furnace crafting recipe\n");
//notes.append("- Added `m!daily` to get daily commands\n");
//notes.append("- Balanced amount of ores needed to upgrade pickaxe\n");
//notes.append("- Fix obsidian not spawning\n");
//notes.append("- Added `m!cooldowns`\n");
//notes.append("### v0.3\n");
//notes.append("- Added items for all ores `m!inventory`\n");
//notes.append("- Added pickaxe levels `m!pickaxe`\n");
//notes.append(" - Pickaxe can be upgraded, giving access to better ores (`m!pickaxe upgrade`)\n");
//notes.append("- Added enchanting `m!enchant`\n");
//notes.append(" - Your pickaxe can be enchanted by spending lapis and xp\n");
//notes.append(" - Owning bookshelves gives you a discount on the amount of levels it costs to enchant\n");
//notes.append("- Added crafting `m!craft`\n");
//notes.append(" - Enchanting table and books can now be crafted!\n");
//notes.append("- Fishing now drops books\n");
//notes.append("- Rob has been relaced with `m!kill`\n");
//notes.append(" - Killing a player will drop some of their items\n");
//notes.append("- Added obsidian\n");
//notes.append("- Removed `m!flip`, this will be added in a future update (with a new mechanic)\n");
sendMessage(e, title, notes.toString());
});
getCommandController().addCommand(CommandDetails.from("cooldowns,cd"), (e, b, args) -> {
StringBuilder cooldowns = new StringBuilder();
b.getCommandController().getCommands().entrySet().stream().map((x) -> x.getValue())
.filter(c -> c instanceof CooldownCommand)
.map(c -> (CooldownCommand) c)
.sorted((c1, c2) -> {
return Long.compareUnsigned(c1.getCooldownController().getNextTime(e.getMember(), c1.getName()),
c2.getCooldownController().getNextTime(e.getMember(), c2.getName()));
})
.forEach(c -> {
long nextCooldownTime = ((CooldownCommand) c).getCooldownController()
.getNextTime(e.getMember(), ((CooldownCommand) c).getName());
if (nextCooldownTime == 0)
return;
String timeLeft = PeelingUtils.formatTimeRelative(nextCooldownTime);
if (System.currentTimeMillis() > nextCooldownTime) {
return;
}
cooldowns.append("**");
cooldowns.append(((CooldownCommand) c).getName());
cooldowns.append("**\t");
cooldowns.append(timeLeft);
cooldowns.append("\n");
});
if (cooldowns.length() == 0) {
cooldowns.append("You have no active cooldowns");
}
b.sendMessage(e, "Active cooldowns", cooldowns.toString());
});
getCommandController().removeCommand("top");
getCommandController().addCommand(new MineshaftLeaderBoardCommand(this));
getCommandController().removeCommand("give");
getCommandController().addCommand(new MineshaftGiveResourcesCommand(this));
getCommandController().addCommand(new FarmCommand(this));
getCommandController().addCommand(new CompostCommand(this));
logger = new FullLogger(this);
}
public StarboardController getStarboardController() {
return starboardController;
}
public FullLogger getLogger() {
return logger;
}
public ResourceManager getResourceManager() {
return resourceManager;
}
public long getItem(Member member, MineshaftItem item) {
return resourceManager.getResource(member, item.toString());
}
public Resource getItem(MineshaftItem item) {
return resourceManager.getResource(item.toString());
}
public void setItem(Member member, MineshaftItem item, long amount) {
resourceManager.setResource(member, item.toString(), amount);
}
public void addItem(Member member, MineshaftItem item, long amount){
resourceManager.addResource(member, item.toString(), amount);
}
public void addItems(Member member, Map<MineshaftItem, Long> items) {
resourceManager.addResources(member, items.entrySet().stream()
.collect(Collectors.toMap(
e -> e.getKey().toString(),
Map.Entry::getValue
))
);
}
public Map<MineshaftItem, Long> sumItems(Map<MineshaftItem, Long> items1, Map<MineshaftItem, Long> items2) {
Map<MineshaftItem, Long> items = new HashMap<>(items1);
items2.forEach((k, v) -> {
if (items.containsKey(k)) {
items.put(k, items.get(k) + v);
} else {
items.put(k, v);
}
});
return items;
}
public void removeItem(Member member, MineshaftItem item, long amount) {
resourceManager.addResource(member, getItem(item).getName(), -amount);
}
public void removeItems(Member member, Map<MineshaftItem, Long> items) {
addItems(member, items.entrySet().stream().collect(Collectors.toMap(
Map.Entry::getKey,
e -> -e.getValue()
)));
}
public String createItemList(Map<MineshaftItem, Long> items) {
LinkedHashMap<MineshaftItem, Long> itemsLinked = new LinkedHashMap<>(items);
return resourceManager.createResourceList(itemsLinked.entrySet().stream()
.collect(Collectors.toMap(
e -> e.getKey().toString(),
Map.Entry::getValue
))
);
}
public String createItemList(Map<MineshaftItem, Long> items, String format) {
return Arrays.asList(
createItemList(items).split("\n")).stream()
.map(s -> String.format(format, s)).collect(Collectors.joining("\n"));
}
public String createItemList(Map<MineshaftItem, Long> items, String format, String join) {
return Arrays.asList(
createItemList(items).split("\n")).stream()
.map(s -> String.format(format, s)).collect(Collectors.joining(join));
}
public Map<MineshaftItem, Long> multiply(Map<MineshaftItem, Long> items, double amount) {
return items.entrySet().stream().collect(Collectors.toMap(
e -> e.getKey(),
e -> (long) Math.floor(e.getValue() * amount)
));
}
public Map<MineshaftItem, Long> getInventory(Member member) {
Map<MineshaftItem, Long> inv = new HashMap<>();
resourceManager.getResources().forEach(r -> {
MineshaftItem item = MineshaftItem.valueOf(r.getName().toUpperCase());
inv.put(item, r.get(member));
});
return inv;
}
public boolean hasItems(Member member, Map<MineshaftItem, Long> items) {
return items.entrySet().stream().map(e -> {
long a = getItem(member, e.getKey());
return a >= e.getValue();
}).reduce(Boolean.TRUE, Boolean::logicalAnd);
}
public Pickaxes getPickaxes() {
return pickaxes;
}
public MineCommand getMineCommand() {
return mineCommand;
}
public Map<MineshaftItem, Long> getMissingIngredients(Member member, Map<MineshaftItem, Long> items) {
Map<MineshaftItem, Long> lacking = new HashMap<MineshaftItem, Long>();
items.forEach((item, q) -> {
if (getItem(member, item) < q) {
lacking.put(item, q - getItem(member, item));
}
});
return Collections.unmodifiableMap(lacking);
}
public Crafting getCrafting() {
return crafting;
}
public EnchantCommand getEnchantCommand() {
return enchantCommand;
}
}
|