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 [] getRareItems();
|
||||
|
||||
public int[] getItems(int tier) {
|
||||
if (tier == 0){
|
||||
return getCommonItems();
|
||||
} else if (tier == 1){
|
||||
return getUncommonItems();
|
||||
} else if (tier == 2){
|
||||
return getRareItems();
|
||||
private final int [] commonItems;
|
||||
private final int [] uncommonItems;
|
||||
private final int [] rareItems;
|
||||
|
||||
public GachaponItems() {
|
||||
this.commonItems = getCommonItems();
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -49,6 +49,8 @@ public class MapleGachapon {
|
||||
NEW_LEAF_CITY(9100109, 90, 8, 2, new NewLeafCity()),
|
||||
NAUTILUS_HARBOR(9100117, 90, 8, 2, new NautilusHarbor());
|
||||
|
||||
private static final Gachapon[] values = Gachapon.values();
|
||||
|
||||
private GachaponItems gachapon;
|
||||
private int npcId;
|
||||
private int common;
|
||||
@@ -56,11 +58,11 @@ public class MapleGachapon {
|
||||
private int rare;
|
||||
|
||||
private Gachapon(int npcid, int c, int u, int r, GachaponItems g) {
|
||||
npcId = npcid;
|
||||
gachapon = g;
|
||||
common = c;
|
||||
uncommon = u;
|
||||
rare = r;
|
||||
this.npcId = npcid;
|
||||
this.gachapon = g;
|
||||
this.common = c;
|
||||
this.uncommon = u;
|
||||
this.rare = r;
|
||||
}
|
||||
|
||||
private int getTier() {
|
||||
@@ -85,7 +87,7 @@ public class MapleGachapon {
|
||||
}
|
||||
|
||||
public static Gachapon getByNpcId(int npcId) {
|
||||
for (Gachapon gacha : Gachapon.values()) {
|
||||
for (Gachapon gacha : values) {
|
||||
if (npcId == gacha.npcId) {
|
||||
return gacha;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user