Events no-load

Discussion in 'Plugin Development' started by Batman500, Apr 11, 2014.

Thread Status:
Not open for further replies.
  1. Offline

    Batman500

    Because the event does not load?
    Class Main
    Code:
    public class Main extends JavaPlugin
      implements Listener
    {
        MC1v1 MC1v1 = new MC1v1(this);
     
    public void onEnable()
      {
    Bukkit.getServer().getPluginManager().registerEvents(this.MC1v1, this);
    getCommand("x1").setExecutor((CommandExecutor) new MC1v1(this));
    }
    }
    Class plugin
    Code:
    public class MC1v1 implements CommandExecutor, Listener{
       
          public Main plugin;
     
          public MC1v1(Main plugin)
          {
              this.plugin = plugin;
          }
         
         
         
         
          @EventHandler(priority=EventPriority.LOWEST)
          public void playerDeath(PlayerDeathEvent event)
          {
                if(event.getEntity() instanceof Player)  {
                    if(event.getEntity() != null) { 
          if(lutadores.contains(event.getEntity())) {
                final Player lu2;
                if(event.getEntity() == lutadores.get(0))
                    {
                        lu2 = lutadores.get(1);
                    }
                else {
                    lu2 = lutadores.get(0);
                }
                   
                    acabou = true;
                        Bukkit.broadcastMessage("§d[X1] " + lu2.getName() + " venceu o x1");
                        Bukkit.broadcastMessage("§d[X1] Vencedor tem 20 segundos para pegar itens do chao");
                    Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(this.plugin, new Runnable() {
                      public void run() {
                        int X = plugin.config.getInt("1v1locationexitX");
                        int Y = plugin.config.getInt("1v1locationexitY");
                        int Z = plugin.config.getInt("1v1locationexitZ");
                          lu2.teleport(new Location(Bukkit.getWorld("world"), X, Y, Z));
                          uso = false;
                          acabou = false;
                          pluginEnabled.clear();
                          podeusar = true;
                        antigolutador1 = lutadores.get(0);
                        antigolutador2 = lutadores.get(1);
                            lutadores.remove(0);
                        lutadores.remove(0);                       
                               
                       
                      }
                    }
                    , 400L);
               
            }
          }
                }
          }
         
         
         
         
         
         
          @EventHandler(priority=EventPriority.LOWEST)
          public void onPlayerQuit(PlayerQuitEvent e) {
              Player player22 = e.getPlayer();
                if(lutadores.contains(player22)) {
                    if(acabou == false) {
                    for(Player f : lutadores) {
                        if(f != player22) {
                            f.sendMessage("§6[CraftWorld] Jogador offline, luta cancelada");
                            int X = plugin.config.getInt("1v1locationexitX");
                            int Y = plugin.config.getInt("1v1locationexitY");
                            int Z = plugin.config.getInt("1v1locationexitZ");
                            f.teleport(new Location(Bukkit.getWorld("world"), X, Y, Z));
                        }
                        else {
                            int X = plugin.config.getInt("1v1locationexitX");
                            int Y = plugin.config.getInt("1v1locationexitY");
                            int Z = plugin.config.getInt("1v1locationexitZ");
                            f.teleport(new Location(Bukkit.getWorld("world"), X, Y, Z));
                        }
                    }
                   
                      uso = false;
                      acabou = false;
                      pluginEnabled.clear();
                      podeusar = true;
                    antigolutador1 = lutadores.get(0);
                    antigolutador2 = lutadores.get(1);
                    lutadores.remove(0);
                    lutadores.remove(0);
     
                      }
                }
          }
         
         
         
         
         
         
         
         
         
         
         
         
          public void setloc1(Player p) {
              if (p.hasPermission("craftworld.x1local")) {
                    p.sendMessage("§2Voce setou o 1 local");
                    Location location = p.getLocation();
                    int X = location.getBlockX();
                    int Y = location.getBlockY();
                    int Z = location.getBlockZ();
                    plugin.config.set("1v1location1X", Integer.valueOf(X));
                    plugin.config.set("1v1location1Y", Integer.valueOf(Y));
                    plugin.config.set("1v1location1Z", Integer.valueOf(Z));
                    plugin.saveConfig();
                  }
                }
          public void setloc2(Player p) {
              if (p.hasPermission("craftworld.x1local")) {
                    p.sendMessage("§2Voce setou o 2 local");
                    Location location = p.getLocation();
                    int X = location.getBlockX();
                    int Y = location.getBlockY();
                    int Z = location.getBlockZ();
                    plugin.config.set("1v1location2X", Integer.valueOf(X));
                    plugin.config.set("1v1location2Y", Integer.valueOf(Y));
                    plugin.config.set("1v1location2Z", Integer.valueOf(Z));
                    plugin.saveConfig();
                  }
                }
          public void setlocexit(Player p) {
              if (p.hasPermission("craftworld.x1local")) {
                    p.sendMessage("§2Voce setou o exit local");
                    Location location = p.getLocation();
                    int X = location.getBlockX();
                    int Y = location.getBlockY();
                    int Z = location.getBlockZ();
                    plugin.config.set("1v1locationexitX", Integer.valueOf(X));
                    plugin.config.set("1v1locationexitY", Integer.valueOf(Y));
                    plugin.config.set("1v1locationexitZ", Integer.valueOf(Z));
                    plugin.saveConfig();
                  }
                }
          public void setloccamarote(Player p) {
              if (p.hasPermission("craftworld.x1local")) {
                    p.sendMessage("§2Voce setou o camarote local");
                    Location location = p.getLocation();
                    int X = location.getBlockX();
                    int Y = location.getBlockY();
                    int Z = location.getBlockZ();
                    plugin.config.set("1v1locationcamaroteX", Integer.valueOf(X));
                    plugin.config.set("1v1locationcamaroteY", Integer.valueOf(Y));
                    plugin.config.set("1v1locationcamaroteZ", Integer.valueOf(Z));
                    plugin.saveConfig();
                  }
                }
         
         
         
         
         
     
         
         
         
         
         
         
         
         
         
         
         
         
         
         
         
         
         
         
         
         
         
        ArrayList<Player> comandotempo = new ArrayList<Player>(); 
        Player antigolutador1;
        Player antigolutador2;
        Boolean acabou = false;
        ArrayList<Player> lutadores = new ArrayList<>();
        public boolean uso = false;
        public Map<String, String> pluginEnabled = new HashMap<String,String>();
        boolean podeusar = true;
        boolean aceitou = false;
       
       
        public void desafiar(Player player, Player player2) {
           
            if (uso == true) {
                player.sendMessage("§6[CraftWorld] Esta em uso, tentei ir x1 depois");
            }
            else {
                if (player2 != null) {
                if(player != player2) {
                    final Player player22 = player2;
                    final Player player1 = player;
                    comandotempo.add(player);
                      Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(this.plugin, new Runnable() {
                          public void run() {
                              comandotempo.removeAll(comandotempo);
                          if(!aceitou) {
                          pluginEnabled.clear();
                          Bukkit.broadcastMessage("§d[X1] " + player22.getName() + "arregou x1 contra " + player1.getName());
                          }
                          }
                      }, 1200L);   
                String p = player.getName();
                String p2 = player2.getName();
                pluginEnabled.put(p, p2);
                Bukkit.broadcastMessage("§d[X1] " + player.getName() + " desafiou " + player2.getName() + " para um x1 e tem 60 segundos para aceitar \"/x1 aceitar\"");
                player2.sendMessage("§6[CraftWorld] Foi enviado um pedido de x1 de " + player.getName() + " Para aceitar digite /x1 aceitar [player]");
                player.sendMessage("§6[CraftWorld] Voce pediu x1 para " + player2.getName());       
                }
                else {
                    player.sendMessage("§6[CraftWorld] Voce nao pode pedir x1 para voce mesmo");
                }
                }
                else {
                    player.sendMessage("§6[CraftWorld] Voce nao pode pedir x1 para um jogador offline");
                }
               
            }
        }
       
        public void aceitar(Player player2, Player player) {
            String p = player.getName();
            if(pluginEnabled.containsKey(p)){
                String p2 = pluginEnabled.get(p);
                if(player2.getName() == p2){
                    if(uso == false) {
                    uso = true;
                    int X = plugin.config.getInt("1v1location1X");
                    int Y = plugin.config.getInt("1v1location1Y");
                    int Z = plugin.config.getInt("1v1location1Z");
                    int X2 = plugin.config.getInt("1v1location2X");
                    int Y2 = plugin.config.getInt("1v1location2Y");
                    int Z2 = plugin.config.getInt("1v1location2Z");
                    player.teleport(new Location(Bukkit.getWorld("world"), X, Y, Z));
                    player2.teleport(new Location(Bukkit.getWorld("world"), X2, Y2, Z2));
                    player2.sendMessage("§6[CraftWorld] Voce aceitou pedido de x1 de " + player.getName());
                    player.sendMessage("§6[CraftWorld] " + player2.getName() + " aceitou seu pedido de x1");       
                    lutadores.add(player);
                    lutadores.add(player2);
                    aceitou = true;
     
                   
                }
                    else {
                        player.sendMessage("§6[CraftWorld] A arena de x1 esta em uso, tente mais tarde");
                    }
                   
                }
                else {
                    player2.sendMessage("§6[CraftWorld] Esse jogador nao pediu x1 para voce");
                }
            }
            else {
                player2.sendMessage("§6[CraftWorld] Esse jogador nao pediu x1 para voce");
            }
           
        }
       
       
       
       
       
       
       
       
       
       
     
        @Override
        public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
             
                  Player p = (Player)sender;
                  if(args.length == 2 || args.length == 1) {
                      if (args[0].equalsIgnoreCase("aceitar")){
                          if(args.length == 2) {
                              Player target = (Bukkit.getServer().getPlayer(args[1]));
                              if(target != null) {
                          aceitar(p, target);
                          if (lutadores.contains(p)) {
                              if(podeusar) {
                              Bukkit.broadcastMessage("§d[X1] " + p.getName() + " aceitou o x1 contra " + target.getName() + "e todos podem assistir em \"/x1 camarote\"");     
                              podeusar = false;
                              final Player pp = p;
                              final Player pp2 = target;
                             
                              pp.sendMessage("§6[CraftWorld] Luta encerra em 10min");
                              pp2.sendMessage("§6[CraftWorld] Luta encerra em 10min");
                              Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(this.plugin, new Runnable() {
                                    public void run() {
                                        if(antigolutador1 != lutadores.get(0) && antigolutador1 != lutadores.get(1) && antigolutador2 != lutadores.get(0) && antigolutador2 != lutadores.get(1)) {
                                        if(uso == true) {
                                            if(acabou == false) {
                                            if(lutadores.contains(pp) && lutadores.contains(pp2)) {
                                                for(Player ff : lutadores) {
                                                ff.sendMessage("§6[CraftWorld] Tempo encerrado, EMPATE");
                                                int X = plugin.config.getInt("1v1locationexitX");
                                                int Y = plugin.config.getInt("1v1locationexitY");
                                                int Z = plugin.config.getInt("1v1locationexitZ");
                                                ff.teleport(new Location(Bukkit.getWorld("world"), X, Y, Z));
                                                uso = false;
                                                pluginEnabled.clear();
                                                podeusar = true;
                                               
                                                }
                                                antigolutador1 = lutadores.get(0);
                                                antigolutador2 = lutadores.get(1);
                                                lutadores.remove(0);
                                                lutadores.remove(0);
                                            }
                                               
                                     
                                    }
                                    }
                                        }
                                        else {
                                            antigolutador1 = null;
                                            antigolutador2 = null;
                                        }
                                  }
                                   
                              }, 12000L);
                          }
                              else {
                                  p.sendMessage("§6[CraftWorld] A arena de x1 esta em uso");
                              }
                          }
                              }
                              else {
                                  p.sendMessage("§6[CraftWorld] Jogador offline");
                              }
                      }
                          else {
                              p.sendMessage("§4Comando invalido use:");
                              p.sendMessage("§2/x1 desafiar [jogador]");
                              p.sendMessage("§2/x1 aceitar [jogador]");
                              p.sendMessage("§2/x1 camarote");
                          }
                      }
                 
     
                      else if(args[0].equalsIgnoreCase("desafiar")) {
                          if(args.length == 2) {
                  if(comandotempo.contains(p)) {
                      p.sendMessage("§4Aguarde 60 segundos para usar o comando novamente");
                  }
                  else {
                      if(pluginEnabled.size() < 1) {
                  comandotempo.add(p);
                      Player target = (Bukkit.getServer().getPlayer(args[1]));
                      if(target != null) {
                          desafiar(p, target);
                         
                      }
                      else {
                          p.sendMessage("§6[CraftWorld] Jogador offline");
                      }
              }
                      else {
                          p.sendMessage("§4Aguarde para pedir x1 pois tem um x1 pendente ou um pedido de x1 pendente");
                      }
                  }
     
                 
                      }
                          else {
                              p.sendMessage("§4Comando invalido use:");
                              p.sendMessage("§2/x1 desafiar [jogador]");
                              p.sendMessage("§2/x1 aceitar [jogador]");
                              p.sendMessage("§2/x1 camarote");
                          }
                      }
                      else if(args[0].equalsIgnoreCase("setloc1")) {
                      setloc1(p);
                      }
                      else if(args[0].equalsIgnoreCase("setloc2")) {
                          setloc2(p); 
                      }
                      else if(args[0].equalsIgnoreCase("setexit")) {
                          setlocexit(p); 
                      }
                      else if(args[0].equalsIgnoreCase("setcamarote")) {
                          setloccamarote(p); 
                      }
                      else if(args[0].equalsIgnoreCase("camarote")) {
                            int X = plugin.config.getInt("1v1locationcamaroteX");
                            int Y = plugin.config.getInt("1v1locationcamaroteY");
                            int Z = plugin.config.getInt("1v1locationcamaroteZ");
                              p.teleport(new Location(Bukkit.getWorld("world"), X, Y, Z));
                      }
                     
                      else {
                          p.sendMessage("§4Comando invalido use:");
                          p.sendMessage("§2/x1 desafiar [jogador]");
                          p.sendMessage("§2/x1 aceitar [jogador]");
                          p.sendMessage("§2/x1 camarote");
                      }
                  }
                  else {
                      p.sendMessage("§4Comando invalido use:");
                      p.sendMessage("§2/x1 desafiar [jogador]");
                      p.sendMessage("§2/x1 aceitar [jogador]");
                      p.sendMessage("§2/x1 camarote");
                  }
             
            return false;
        }
     
    }
    

     
  2. Offline

    FabeGabeMC

    This:
    Code:java
    1. public class Main extends JavaPlugin
    2. implements Listener
    3. {
    4. MC1v1 MC1v1 = new MC1v1(this);
    5.  
    6. public void onEnable()
    7. {
    8. Bukkit.getServer().getPluginManager().registerEvents(this.MC1v1, this);
    9. getCommand("x1").setExecutor((CommandExecutor) new MC1v1(this));
    10. }
    11. }

    should be this:
    Code:java
    1. public class Main extends JavaPlugin
    2. implements Listener
    3. {
    4. public void onEnable()
    5. {
    6. Bukkit.getServer().getPluginManager().registerEvents(this, this);
    7. getCommand("x1").setExecutor(new MC1v1());
    8. }
    9. }


    Also, you would need to run the scheduler in your main class.

    Hope this helps :)
     
Thread Status:
Not open for further replies.

Share This Page