It's never too late to fix old code boys! (#268)
* It's never too late to fix old code boys! Cache items so the array isn't returned multiple times and cache Gachapon.values() for maximum performance and stability * Java 7 memes
This commit is contained in:
@@ -33,13 +33,23 @@ public abstract class GachaponItems {
|
|||||||
public abstract int [] getUncommonItems();
|
public abstract int [] getUncommonItems();
|
||||||
public abstract int [] getRareItems();
|
public abstract int [] getRareItems();
|
||||||
|
|
||||||
public int[] getItems(int tier) {
|
private final int [] commonItems;
|
||||||
if (tier == 0){
|
private final int [] uncommonItems;
|
||||||
return getCommonItems();
|
private final int [] rareItems;
|
||||||
} else if (tier == 1){
|
|
||||||
return getUncommonItems();
|
public GachaponItems() {
|
||||||
} else if (tier == 2){
|
this.commonItems = getCommonItems();
|
||||||
return getRareItems();
|
this.uncommonItems = getUncommonItems();
|
||||||
|
this.rareItems = getRareItems();
|
||||||
|
}
|
||||||
|
|
||||||
|
public final int[] getItems(int tier) {
|
||||||
|
if (tier == 0) {
|
||||||
|
return commonItems;
|
||||||
|
} else if (tier == 1) {
|
||||||
|
return uncommonItems;
|
||||||
|
} else if (tier == 2) {
|
||||||
|
return rareItems;
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -49,6 +49,8 @@ public class MapleGachapon {
|
|||||||
NEW_LEAF_CITY(9100109, 90, 8, 2, new NewLeafCity()),
|
NEW_LEAF_CITY(9100109, 90, 8, 2, new NewLeafCity()),
|
||||||
NAUTILUS_HARBOR(9100117, 90, 8, 2, new NautilusHarbor());
|
NAUTILUS_HARBOR(9100117, 90, 8, 2, new NautilusHarbor());
|
||||||
|
|
||||||
|
private static final Gachapon[] values = Gachapon.values();
|
||||||
|
|
||||||
private GachaponItems gachapon;
|
private GachaponItems gachapon;
|
||||||
private int npcId;
|
private int npcId;
|
||||||
private int common;
|
private int common;
|
||||||
@@ -56,11 +58,11 @@ public class MapleGachapon {
|
|||||||
private int rare;
|
private int rare;
|
||||||
|
|
||||||
private Gachapon(int npcid, int c, int u, int r, GachaponItems g) {
|
private Gachapon(int npcid, int c, int u, int r, GachaponItems g) {
|
||||||
npcId = npcid;
|
this.npcId = npcid;
|
||||||
gachapon = g;
|
this.gachapon = g;
|
||||||
common = c;
|
this.common = c;
|
||||||
uncommon = u;
|
this.uncommon = u;
|
||||||
rare = r;
|
this.rare = r;
|
||||||
}
|
}
|
||||||
|
|
||||||
private int getTier() {
|
private int getTier() {
|
||||||
@@ -85,7 +87,7 @@ public class MapleGachapon {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static Gachapon getByNpcId(int npcId) {
|
public static Gachapon getByNpcId(int npcId) {
|
||||||
for (Gachapon gacha : Gachapon.values()) {
|
for (Gachapon gacha : values) {
|
||||||
if (npcId == gacha.npcId) {
|
if (npcId == gacha.npcId) {
|
||||||
return gacha;
|
return gacha;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user