Estou desenvolvendo um plugin de skywars para o minecraft, para quem não sabe existem modificações feitas para o minecraft do lado do servidor que se chamam plugin, esta é a minha implementação do state, este código poderia ser considerado o padrão state ???? tem algo que eu possa fazer para melhorar ?
@Getter
@RequiredArgsConstructor
public enum SkyGameState {
LOBBY(true,false,120,false){
@Override
public void nextState(SkyGame game) throws NextGameStateException {
if(game.getPlayers().size() < game.getArena().getMinPlayers())
throw new NextGameStateException(Messages.InsuficientPlayers.getMessage());
game.setState(SkyGameState.GAME);
}
@Override
public void begin(SkyGame skyGame) {
skyGame.resetTimer();
}
@Override
public void tick(SkyGame game, int timer) {
if((timer % 10 == 0 && timer>0) || (timer <= 10 && timer > 0)){
game.broadcast(Messages.GameStarting.getMessage().replace(":timer",""+timer));
}
if(timer <= 10 && timer > 0){
game.broadcastTitle(ChatColor.GOLD + "" + timer);
game.broadcastSound(Sound.ORB_PICKUP);
}
}
},GAME(false,true,60*10,true){
@Override
public void nextState(SkyGame game) throws NextGameStateException {
game.setState(SkyGameState.FINAL);
}
@Override
public void begin(SkyGame skyGame) {
skyGame.setInicio(LocalDateTime.now());
skyGame.getPlayers().keySet().forEach(skyPlayer -> TitleAPI.sendTitle(skyPlayer.getSpigotPlayer(),5,10,5,ChatColor.GOLD + "START!"));
skyGame.broadcastSound(Sound.LEVEL_UP);
skyGame.getPlayers().keySet().forEach((p)->{
FallDamageListener.noFall.add(p.getSpigotPlayer().getUniqueId().toString());
p.renew();
});
skyGame.getArena().getSpawns().forEach((vector)-> skyGame.getGameMode().breakJails(vector.toLocation(skyGame.getBukkitWorld())));
Bukkit.getScheduler().runTaskLater(XPSkywars.getPlugin(),()->
skyGame.getPlayers().keySet().forEach(
(p)->FallDamageListener.noFall.remove(p.getSpigotPlayer().getUniqueId().toString())
)
,5*20);
skyGame.getArena().getChests().forEach((lootChest -> lootChest.addChest(skyGame.getBukkitWorld())));
skyGame.getPlayers().keySet().forEach(SkyPlayer::giveKit);
}
@Override
public void tick(SkyGame game, int timer) {
if(game.getGameMode().isWin())
game.setTimer(0);
}
},FINAL(false,false,6,false){
@Override
public void nextState(SkyGame game) throws NextGameStateException {
game.setRunning(false);
try {
game.getLogService().saveLog(game);
} catch (Exception e) {
Bukkit.getConsoleSender().sendMessage(ChatColor.DARK_RED+"ERRO: AO LOGAR PARTIDA: " + e.getMessage());
}
game.getPlayers().keySet().forEach(game::teleportToSpawn);
game.getPlayers().keySet().forEach(SkyPlayer::resetScoreboard);
game.getPlayers().clear();
}
@Override
public void begin(SkyGame skyGame) {
skyGame.finish();
}
@Override
public void tick(SkyGame game, int timer) {
}
};
@NonNull
private final boolean acceptNewPlayers;
@NonNull
private final boolean canBreakBlock;
@NonNull
private final int timer;
@NonNull
private final boolean pvp;
public abstract void nextState(SkyGame game) throws NextGameStateException;
public abstract void begin(SkyGame skyGame);
public abstract void tick(SkyGame game, int timer);
}