Skip to content

Commit edaa789

Browse files
committed
fix /give variant
1 parent 6c91a36 commit edaa789

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

src/jfcraft/item/Item.java

+5
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,11 @@ public final void clear() {
6868
public final boolean isEmpty() {
6969
return id == 0;
7070
}
71+
72+
public ItemBase getItemBase() {
73+
return Static.items.items[id];
74+
}
75+
7176
public final String toString() {
7277
return "item:" + (int)id + "," + var + "," + count + "," + dmg;
7378
}

src/jfcraft/server/Server.java

+14-3
Original file line numberDiff line numberDiff line change
@@ -1178,16 +1178,27 @@ public void doCommand(Client client, String cmd) {
11781178
cnt = JF.atoi(p[3]);
11791179
if (cnt < 1 || cnt > 64) cnt = 1;
11801180
}
1181-
int var = 0;
1181+
int var = -1;
11821182
if (p.length >= 5) {
11831183
var = JF.atoi(p[4]);
1184-
if (var < 0 || var > 7) var = 0;
1184+
if (var < 0 || var > 7) var = -1;
11851185
}
11861186
Item item = findItem(p[2], cnt);
11871187
if (item == null) {
11881188
client.serverTransport.sendMsg("Error:Item not found:" + p[2]);
11891189
} else {
1190-
item.var = (byte)var;
1190+
if (var != -1) {
1191+
//validate var
1192+
ItemBase itembase = item.getItemBase();
1193+
if (itembase.isVar) {
1194+
if (var >= itembase.names.length) {
1195+
var = -1;
1196+
}
1197+
if (var != -1) {
1198+
item.var = (byte)var;
1199+
}
1200+
}
1201+
}
11911202
Static.log("give:" + (int)item.id + ":" + cnt);
11921203
client.addItem(item, true);
11931204
}

0 commit comments

Comments
 (0)