Ejemplo n.º 1
0
  @EventHandler(priority = EventPriority.HIGHEST)
  public void onPlayerDie(PlayerDeathEvent pde) {
    final Player player = pde.getEntity();
    Game game = Main.getInstance().getGameManager().getGameOfPlayer(player);

    if (game == null) {
      return;
    }

    if (game.getState() == GameState.RUNNING) {
      pde.setDroppedExp(0);
      pde.setDeathMessage(null);

      if (!Main.getInstance().getBooleanConfig("player-drops", false)) {
        pde.getDrops().clear();
      }

      try {
        if (!Main.getInstance().isSpigot()) {
          Class<?> clazz = null;
          try {
            clazz =
                Class.forName(
                    "io.github.yannici.bedwars.Com."
                        + Main.getInstance().getCurrentVersion()
                        + ".PerformRespawnRunnable");
          } catch (ClassNotFoundException ex) {
            clazz = Class.forName("io.github.yannici.bedwars.Com.Fallback.PerformRespawnRunnable");
          }

          BukkitRunnable respawnRunnable =
              (BukkitRunnable) clazz.getDeclaredConstructor(Player.class).newInstance(player);
          respawnRunnable.runTaskLater(Main.getInstance(), 20L);
        } else {
          new BukkitRunnable() {

            @Override
            public void run() {
              player.spigot().respawn();
            }
          }.runTaskLater(Main.getInstance(), 20L);
        }

      } catch (Exception e) {
        e.printStackTrace();
      }

      try {
        pde.getClass().getMethod("setKeepInventory", new Class<?>[] {boolean.class});
        pde.setKeepInventory(false);
      } catch (Exception ex) {
        player.getInventory().clear();
      }

      Player killer = player.getKiller();
      if (killer == null) {
        killer = game.getPlayerDamager(player);
      }

      game.getCycle().onPlayerDies(player, killer);
    }
  }
Ejemplo n.º 2
0
  @EventHandler
  public void on(PlayerDeathEvent e) {

    final Player toter = e.getEntity();

    e.setDeathMessage("");
    e.setDroppedExp(0);
    e.setKeepInventory(false);

    for (ItemStack stack : e.getDrops()) {

      if (stack.getType() == Material.LEATHER_HELMET
          || stack.getType() == Material.LEATHER_CHESTPLATE
          || stack.getType() == Material.LEATHER_LEGGINGS
          || stack.getType() == Material.LEATHER_BOOTS
          || stack.getType() == Material.NETHER_STAR) {
        e.getDrops().remove(stack.getType());
      }
    }

    PlayerDataClass pDCtoter = Global.re.read(toter.getUniqueId().toString());
    pDCtoter.Tode += 1;
    StatsWriter.write(pDCtoter, toter.getUniqueId().toString());

    if (e.getEntity().getKiller() instanceof Player) {

      Player killer = (Player) e.getEntity().getKiller();
      double dhealth = ((Damageable) killer).getHealth();
      String shealth = String.valueOf(dhealth / 2);
      shealth = shealth.substring(0, shealth.indexOf(".") + 2);

      for (Player all : Bukkit.getOnlinePlayers())
        all.sendMessage(
            Devathlon.prefix
                + toter.getDisplayName()
                + " §7wurde von "
                + killer.getDisplayName()
                + " §7[§e"
                + shealth
                + "❤§7] §7getötet");

      PlayerDataClass pDCkiller = Global.re.read(killer.getUniqueId().toString());
      pDCkiller.Toetungen += 1;
      pDCkiller.Punkte += 25;
      killer.sendMessage(Devathlon.prefix + "§e+ 25 Punkte");
      StatsWriter.write(pDCkiller, killer.getUniqueId().toString());

    } else {

      for (Player all : Bukkit.getOnlinePlayers())
        all.sendMessage(Devathlon.prefix + toter.getDisplayName() + " §7ist gestorben");
    }

    if (Global.team1.contains(toter)) {
      Global.pointsteam1 -= 5;
    } else if (Global.team2.contains(toter)) {
      Global.pointsteam2 -= 5;
    }

    if (Global.team1.contains(toter)) {
      if (Global.pointsteam2 >= Global.points) {
        spec(toter);
        for (Player all : Bukkit.getOnlinePlayers())
          all.sendMessage(
              Devathlon.prefix
                  + "§cTeam Rot §7besitzt noch §e"
                  + Global.team1.size()
                  + " §7Spieler");

        if (Global.team1.size() == 0) {

          for (Player all : Bukkit.getOnlinePlayers())
            all.sendMessage(Devathlon.prefix + "§9Team Blau §ahat gewonnen");

          for (Player t2 : Global.team2) {
            PlayerDataClass pDCt2 = Global.re.read(t2.getUniqueId().toString());
            pDCt2.SpieleGewonnen += 1;
            pDCt2.Punkte += 125;
            StatsWriter.write(pDCt2, t2.getUniqueId().toString());
            t2.sendMessage(Devathlon.prefix + "§e+ 125 Punkte");
          }

          Devathlon.Timer = 16;
          Devathlon.Status = GameStatus.Restarting;
        }
        return;
      }
    }

    if (Global.team2.contains(toter)) {
      if (Global.pointsteam1 >= Global.points) {
        spec(toter);
        for (Player all : Bukkit.getOnlinePlayers())
          all.sendMessage(
              Devathlon.prefix
                  + "§9Team Blau §7besitzt noch §e"
                  + Global.team2.size()
                  + " §7Spieler");

        if (Global.team2.size() == 0) {
          for (Player all : Bukkit.getOnlinePlayers())
            all.sendMessage(Devathlon.prefix + "§cTeam Rot §ahat gewonnen");

          for (Player t1 : Global.team1) {
            PlayerDataClass pDCt1 = Global.re.read(t1.getUniqueId().toString());
            pDCt1.SpieleGewonnen += 1;
            pDCt1.Punkte += 125;
            StatsWriter.write(pDCt1, t1.getUniqueId().toString());
            t1.sendMessage(Devathlon.prefix + "§e+ 125 Punkte");
          }

          Devathlon.Timer = 16;
          Devathlon.Status = GameStatus.Restarting;
        }
        return;
      }
    }

    toter.sendMessage(
        Devathlon.prefix
            + "§3Du konntest respawnen, da das gegnerische Team noch keine "
            + Global.points
            + " Punkte erreicht hat");

    Bukkit.getScheduler()
        .runTaskLater(
            plugin,
            new Runnable() {

              @Override
              public void run() {
                toter.spigot().respawn();
                if (Global.team1.contains(toter)) {
                  toter.teleport(OreBattle_Command.getLocation("spawn1", true));
                  Devathlon.team1(toter);
                } else if (Global.team2.contains(toter)) {
                  toter.teleport(OreBattle_Command.getLocation("spawn2", true));
                  Devathlon.team2(toter);
                }
              }
            },
            30L);

    // Grace
    Global.grace.add(toter);

    if (Global.gracetime != 0) {
      toter.sendMessage(
          Devathlon.prefix
              + "§cDeine Schutzzeit endet in §7[§e"
              + Global.gracetime
              + "§7] §cSekunden");

      Bukkit.getScheduler()
          .runTaskLater(
              plugin,
              new Runnable() {

                @Override
                public void run() {
                  Global.grace.remove(toter);
                  toter.sendMessage(Devathlon.prefix + "§cDeine Schutzzeit ist vorbei!");
                }
              },
              20L * Global.gracetime);
    }
  }