Facebook
From Keven, 9 Months ago, written in Java.
Embed
Download Paste or View Raw
Hits: 97
  1. package torneio.torneiopokemon;
  2.  
  3.  
  4. import com.flowpowered.math.vector.Vector3d;
  5. import com.pixelmonmod.pixelmon.api.events.BattleStartedEvent;
  6. import com.pixelmonmod.pixelmon.api.events.battles.BattleEndEvent;
  7. import io.github.nucleuspowered.nucleus.api.NucleusAPI;
  8. import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
  9. import org.spongepowered.api.Sponge;
  10. import org.spongepowered.api.entity.living.player.Player;
  11. import org.spongepowered.api.scheduler.Task;
  12. import org.spongepowered.api.text.Text;
  13. import org.spongepowered.api.text.channel.MessageChannel;
  14. import org.spongepowered.api.world.Location;
  15. import org.spongepowered.api.world.World;
  16.  
  17. import java.util.HashMap;
  18. import java.util.Random;
  19.  
  20. import java.util.concurrent.TimeUnit;
  21. import java.util.concurrent.atomic.AtomicInteger;
  22. import java.util.function.Consumer;
  23.  
  24. public class EventoBatalha {
  25.  
  26.     Configura configs = new Configura();
  27.  
  28.     Vector3d coordsPlayer1 = new Vector3d(configs.getNodes().getNode("Arena", "local1", "x").getDouble(),
  29.             configs.getNodes().getNode("Arena", "local1", "y").getDouble(),
  30.             configs.getNodes().getNode("Arena", "local1", "z").getDouble());
  31.     Location<World> coordMundoPlayer1 = new Location<World>(NucleusAPI.getWarpService()
  32.             .get().getWarp("evento").get().getLocation().get().getExtent(),coordsPlayer1);
  33.  
  34.  
  35.     Vector3d coordsPlayer2 = new Vector3d(configs.getNodes().getNode("Arena", "local2", "x").getDouble(),
  36.             configs.getNodes().getNode("Arena", "local2", "y").getDouble(),
  37.             configs.getNodes().getNode("Arena", "local2", "z").getDouble());
  38.     Location<World> coordMundoPlayer2 = new Location<World>(NucleusAPI.getWarpService()
  39.             .get().getWarp("evento").get().getLocation().get().getExtent(),coordsPlayer1);
  40.  
  41.  
  42.  
  43.     private class CancellingTimerTask2 implements Consumer<Task> {
  44.         private int seconds = 5;
  45.         @Override
  46.         public void accept(Task task) {
  47.  
  48.  
  49.             if(seconds == 5) {
  50.                 MessageChannel.world(NucleusAPI.getWarpService().get().getWarp("evento").get().getLocation().get().getExtent())
  51.                         .send(Text.of("Duelo iniciado\n" + getSorteado1().getName() + " vs " + getSorteado2()
  52.                                 + "\n" + "5 segundos para iniciar a batalha"));
  53.             }
  54.  
  55.             seconds--;
  56.  
  57.             if(seconds == 0){
  58.                getSorteado1().setLocation(coordMundoPlayer1);
  59.                getSorteado2().setLocation(coordMundoPlayer2);
  60.  
  61.                task.cancel();
  62.             }
  63.  
  64.         }
  65.     }
  66.  
  67.     private static boolean eventoiniciado = false;
  68.  
  69.     private static boolean camaroteDisponivel = false;
  70.  
  71.     public static void setCamaroteDisponivel(boolean camaroteDisponivel1){
  72.         camaroteDisponivel = camaroteDisponivel1;
  73.     }
  74.  
  75.     public int valorPlayers = 1;
  76.  
  77.     public static void setEventoIniciado(boolean eventoiniciado1){
  78.         eventoiniciado = eventoiniciado1;
  79.     }
  80.  
  81.     private static Boolean getEventoIniciado(){
  82.         return eventoiniciado;
  83.     }
  84.  
  85.     public static HashMap<Integer, TorneioPlayers> playersbata = new HashMap<>();
  86.  
  87.     EventoEntrar eventoEntrar = new EventoEntrar();
  88.  
  89.     private Random r1 = new Random();
  90.     int varivalRandom = r1.nextInt(eventoEntrar.getQuantia())+1;
  91.  
  92.     private Player sorteado1;
  93.     private Player sorteado2;
  94.     private Player vencendor;
  95.  
  96.     public Player getSorteado1() {
  97.         return sorteado1;
  98.     }
  99.  
  100.     public void setSorteado1(Player sorteado1) {
  101.         this.sorteado1 = sorteado1;
  102.     }
  103.  
  104.     public Player getSorteado2() {
  105.         return sorteado2;
  106.     }
  107.  
  108.     public void setSorteado2(Player sorteado2) {
  109.         this.sorteado2 = sorteado2;
  110.     }
  111.  
  112.  
  113.     public void setVencendor(Player venceu){
  114.         this.vencendor = venceu;
  115.     }
  116.  
  117.     public Player getVencendor(){
  118.  
  119.  
  120.         return this.vencendor;
  121.     }
  122.  
  123.  
  124.  
  125.  
  126.  
  127.     public Boolean seTemPlayers(){
  128.         int playersRestantes = 0;
  129.  
  130.         for (int n6 = 1;n6<=eventoEntrar.getQuantia();n6++){
  131.              if(playersbata.get(n6).isParticipanteArena() == true){
  132.                  playersRestantes = playersRestantes +1;
  133.              }
  134.         }
  135.         if(playersRestantes>=2){
  136.             return true;
  137.         }else{
  138.             return false;
  139.         }
  140.  
  141.  
  142.  
  143.     }
  144.  
  145.  
  146.     public void sortear(){
  147.         verificarPlayers();
  148.         boolean playerPronto = false;
  149.         AtomicInteger playerSelection = new AtomicInteger();
  150.         while (playerPronto = false){
  151.             if(playersbata.get(varivalRandom).isParticipanteArena() == false){
  152.                 varivalRandom = r1.nextInt(eventoEntrar.getQuantia())+1;
  153.             }else{
  154.                 playerSelection.set(varivalRandom);
  155.                 setSorteado1(playersbata.get(playerSelection).getParticipante());
  156.             }
  157.         }
  158.     }
  159.  
  160.     public void sortear2(){
  161.         boolean playerPronto2 = false;
  162.         AtomicInteger playerSelection2 = new AtomicInteger();
  163.         while (playerPronto2 = false){
  164.             if(playersbata.get(varivalRandom).isParticipanteArena() == false){
  165.                 varivalRandom = r1.nextInt(eventoEntrar.getQuantia())+1;
  166.             }else{
  167.                 playerSelection2.set(varivalRandom);
  168.                 setSorteado2(playersbata.get(playerSelection2).getParticipante());
  169.             }
  170.         }
  171.     }
  172.  
  173.     private void verificarPlayers(){
  174.        for(Player player : Sponge.getServer().getWorld("evento").get().getPlayers()){
  175.            valorPlayers++;
  176.            TorneioPlayers torneioPlayers = new TorneioPlayers(player,true);
  177.            playersbata.put(valorPlayers,torneioPlayers);
  178.            setCamaroteDisponivel(true);
  179.        }
  180.     }
  181.  
  182.  
  183.     public void IniciarBatalha(Player vencendor){
  184.         if(seTemPlayers() == true) {
  185.             sortear();
  186.             sortear2();
  187.             Task task = Task.builder().execute(new EventoBatalha.CancellingTimerTask2())
  188.                     .interval(1, TimeUnit.SECONDS)
  189.                     .name("Task do evento").submit(TorneioPokemon.getInstance());
  190.             Sponge.getCommandManager().process(Sponge.getServer().getConsole(),
  191.                     "/pokebattle " + getSorteado1() + " " + getSorteado2());
  192.  
  193.             MessageChannel.TO_PLAYERS.send(Text.of(""+getSorteado1().getName() + " vs " + getSorteado2().getName()));
  194.         }else{
  195.  
  196.         }
  197.  
  198.  
  199.     }
  200.  
  201.  
  202.  
  203.  
  204.     @SubscribeEvent
  205.     public void fimBatalha(BattleStartedEvent event, BattleEndEvent event2){
  206.         if(event.participant1[0].getDisplayName() == getSorteado1().getName() || event.participant2[0].getDisplayName() == getSorteado2().getName()){
  207.             setVencendor(event2.bc.get);
  208.         }
  209.     }
  210.  
  211.  
  212.  
  213.  
  214.  
  215.     public void batalhaInicia(){
  216.          if(getEventoIniciado() == true){
  217.              IniciarBatalha(getVencendor());
  218.  
  219.          }
  220.     }
  221.  
  222.  
  223. }