Originally Posted by
Linus
Code:
package server.model.players.content;
import server.core.PlayerHandler;
import server.event.CycleEvent;
import server.event.CycleEventContainer;
import server.event.CycleEventHandler;
import server.model.players.Client;
import server.model.players.Player;
import server.util.Misc;
public class DiceManager {
static int rollProcentalDice(){
return Misc.random(100);
}
public static void startRoll(final Client c, final String type){
if(!c.getItems().playerHasItem(10833)){
return;
}
if(c.lastDiceRoll > System.currentTimeMillis()){
c.sendMessage("You need to wait 15 seconds between each dice roll.");
return;
}
c.sendMessage("You roll the dice..");
c.lastDiceRoll = System.currentTimeMillis()+15000;
for(Player p : PlayerHandler.players) {
if (p != null) {
Client c3 = (Client) p;
if(p.distanceToPoint(c.absX, c.absY) <= 10){
c.gfx100(712);
c.startAnimation(859);
c3.sendMessage("<col=800000>[Dices Rolling]: "+Misc.capitalize(c.playerName)+" is rolling the dice..");
}
}
}
CycleEventHandler.getSingleton().addEvent(c, new CycleEvent() {
@Override
public void execute(CycleEventContainer container) {
switch(type){
case "percentile":
int roll = rollProcentalDice();
for(Player p : PlayerHandler.players) {
if (p != null) {
Client c = (Client) p;
if(p.distanceToPoint(c.absX, c.absY) <= 10){
c.sendMessage("<col=800000>[Dices Rolling]: "+Misc.capitalize(c.playerName)+" rolled "+roll+" on the percentile dice.");
}
}
}
c.sendMessage("You rolled "+roll+" on the percentile dice.");
container.stop();
return;
}
}
@Override
public void stop() {
}
}, 4);
}
}
If you're going to provide a static factory class for this, you might as well treat it as such.
Code:
class DiceManagerTwo extends DiceManager {
// this shouldn't be permitted, you can fix this by making DiceManager's class implementation effectively final.
}
Code:
DiceManager anInstance = new DiceManager();
// this should not be possible, you can resolve this by ensuring
// that DiceManager's constructor is private and any instancing
// would result in an error.
Code:
final class DiceManager {
private DiceManager() {
throw new AssertionError("Error, it is illegal to create an instance of the DiceManager static factory class.");
}
}