blob: d093f2f6b1cb89f4f9d4df6899f509822447bf64 (
plain)
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
|
package net.uomc.mineshaft.resources.market;
import java.util.function.Consumer;
import org.json.JSONObject;
import net.dv8tion.jda.api.JDA;
import net.dv8tion.jda.api.entities.Guild;
import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.api.entities.User;
import net.uomc.mineshaft.resources.Resource;
import net.uomc.mineshaft.resources.ResourceManager;
public class Offer extends JSONObject {
private static final String ID = "id";
private static final String BUYING_QUANTITY = "buying_quantity";
private static final String SELLING_QUANTITY = "selling_quantity";
private static final String BUYING_RESOURCE = "buying_resource";
private static final String SELLING_RESOURCE = "selling_resource";
private static final String USERID = "userid";
public static int highest = 0;
public Offer() {
super();
}
public Offer(JSONObject jsonObject) {
super();
jsonObject.keySet().forEach(k -> put(k, jsonObject.get(k)));
if (has(ID)) {
if (getID() >= highest) {
highest = getID();
}
}
}
public int getID() {
return getInt(ID);
}
public void setID(int id) {
put(ID, id);
if (getID() >= highest) {
highest = getID();
}
}
public String getUserID() {
return getString(USERID);
}
public void getMember(Guild guild, Consumer<Member> c) {
guild.retrieveMemberById(getUserID()).queue(c);
}
public Member getMember(Guild guild) {
return guild.getMemberById(getUserID());
}
public void setUserID(String userid) {
put(USERID, userid);
}
public Resource getSellingResource(ResourceManager resourceManager) {
String string = getString(SELLING_RESOURCE);
return resourceManager.getResource(string);
}
public void setSellingResource(Resource resource) {
put(SELLING_RESOURCE, resource.getName());
}
public Resource getBuyingResource(ResourceManager resourceManager) {
String string = getString(BUYING_RESOURCE);
return resourceManager.getResource(string);
}
public void setBuyingResource(Resource resource) {
put(BUYING_RESOURCE, resource.getName());
}
public long getSellingQuantity() {
return getLong(SELLING_QUANTITY);
}
public void setSellingQuantity(long q) {
put(SELLING_QUANTITY, q);
}
public long getBuyingQuantity() {
return getLong(BUYING_QUANTITY);
}
public void setBuyingQuantity(long q) {
put(BUYING_QUANTITY, q);
}
public String getAsString(ResourceManager resourceManager) {
return getSellingResource(resourceManager).prettyValue(getSellingQuantity()) + " for " + getBuyingResource(resourceManager).prettyValue(getBuyingQuantity());
}
}
|