Oh man.. There's a slew of ways you could have done this better.
It's better than some of the atrocities I've seen for Mystery Boxes though.
I plan on re-writing almost everything in the server I'm currently working on, I don't have Mystery Boxes but..
I wrote this in about 5 minutes, obviously I've only tested it a bit, but something like this would be 1000x better.
Class; MysteryBox
Code:
package server.model.minigames;
import server.util.Misc;
public class MysteryBox {
public enum MysteryReward {
COMMON {
public void getReward() {
Misc.println("Returned "+getRarity());
}
}, UNCOMMON {
public void getReward() {
Misc.println("Returned "+getRarity());
}
}, RARE {
public void getReward() {
Misc.println("Returned "+getRarity());
}
}, LEGENDARY {
public void getReward() {
Misc.println("Returned "+getRarity());
}
};
public abstract void getReward();
public String getRarity() {
return name().charAt(0) + name().substring(1).toLowerCase();
}
}
}
For testing; in the Commands class
Code:
if (playerCommand.equalsIgnoreCase("testbox")) {
for (MysteryBox.MysteryReward mystery : MysteryBox.MysteryReward.values()) {
int chances = Misc.randomWithRange(0, 48);
/*if (chances <= 24) {
mystery.COMMON.getReward();
} else if (chances >= 24 && chances <= 36) {
mystery.UNCOMMON.getReward();
} else if (chances >= 36 && chances <= 42) {
mystery.RARE.getReward();
} else if (chances >= 42) {
mystery.LEGENDARY.getReward();
}*/
if (chances >= 0) {
mystery.getReward();
}
}
}
Really haven't done anything with it though, just wrote the class and made sure the basis of it works.
EDIT: I have a thing for Enums.