Esempio n. 1
0
  // Récupération de l'évènement lorsqu'une entité meurt
  public void handle(DestructEntityEvent.Death event) throws Exception {
    String cause = event.getCause().toString();

    // Si la mort a été causée par un joueur grâce à une arme
    if (cause.contains("Name=player, Type=attack")) {
      // On récupère l'id de l'entité morte
      String mobId = event.getTargetEntity().getType().getId();

      // Achievement KillMob
      Iterator iterator = this.core.getMobs().iterator();
      // On parcoure la liste des achievements de type KillMob et on vérifie si l'id de l'entité
      // tuée
      // correspond à l'id enregistrée dans l'achievement
      // Ensuite on vérifie que le bon nombre d'entité de ce type ont été tuées
      // Si oui, on valide l'achievement
      while (iterator.hasNext()) {
        AchievementKillMob achiev = (AchievementKillMob) iterator.next();
        if (mobId.equals(achiev.getMobId())) {

          String causePlayer = getPlayerFromCause(event.getCause().toString());
          String userUUID =
              core.getGame().getServer().getPlayer(causePlayer).get().getUniqueId().toString();
          if (!playerHasAchievment(userUUID, achiev.getName())) {
            // Récupérer le nombre de mobs tués par le joueur
            int mobToKill = getMobToKill(achiev, causePlayer);
            addKilledMob(userUUID, achiev.getBadgeID(), mobToKill - 1);
            if (mobToKill == 0) {
              validAchievement(achiev, cause);
              break;
            }
          }
        }
      }
    }
  }
  public static LivingDeathEvent createLivingDeathEvent(Event event) {
    if (!(event instanceof DestructEntityEvent.Death)) {
      throw new IllegalArgumentException("Event is not a valid DestructEntityEvent.Death event.");
    }

    DestructEntityEvent.Death spongeEvent = (DestructEntityEvent.Death) event;
    Optional<DamageSource> source = spongeEvent.getCause().first(DamageSource.class);
    if (!source.isPresent()) {
      return null;
    }

    LivingDeathEvent forgeEvent =
        new LivingDeathEvent(
            (EntityLivingBase) spongeEvent.getTargetEntity(),
            (net.minecraft.util.DamageSource) source.get());
    return forgeEvent;
  }
  @Listener
  public void onPlayerKilled(DestructEntityEvent.Death event) {
    if (event.getCause().first(DamageSource.class).isPresent()) {
      DamageSource dmgSource = event.getCause().first(DamageSource.class).get();

      if (dmgSource instanceof EntityDamageSource) {
        EntityDamageSource entityDmgSource = (EntityDamageSource) dmgSource;
        Entity entity = entityDmgSource.getSource();
        Living entityTarget = event.getTargetEntity();

        if (entity instanceof Player && entityTarget instanceof Player) {
          Player player = (Player) entity;
          Player target = (Player) entityTarget;

          if (this.teamA.contains(player) && this.teamB.contains(target)) {
            this.teamAPoints++;
          } else if (this.teamB.contains(player) && this.teamA.contains(target)) {
            this.teamBPoints++;
          }
        }
      }
    }
  }
Esempio n. 4
0
  @Listener(order = Order.PRE)
  public void onDestructEntityEventDeathPlayer(
      DestructEntityEvent.Death event, @First EntityDamageSource damageSrc) {
    if (!(event.getTargetEntity() instanceof Player)) {
      return;
    }
    Player player = (Player) event.getTargetEntity();

    WorldSettings settings = WorldSettings.get(player.getWorld());

    DeathReason reason = DeathReason.GENERIC;

    Entity src = damageSrc.getSource();

    if (src instanceof Player) {
      reason = DeathReason.PLAYER;
    } else if (src instanceof Projectile) {
      Projectile projectile = (Projectile) src;

      Optional<UUID> optionalUUID = projectile.getCreator();

      if (!optionalUUID.isPresent()) {
        return;
      }

      Optional<Player> optionalPlayer = Sponge.getServer().getPlayer(optionalUUID.get());

      if (optionalPlayer.isPresent()) {
        reason = DeathReason.PLAYER;
      } else {
        reason = DeathReason.PROJECTILE;
      }
    } else {
      DamageType cause = damageSrc.getType();
      reason = DeathReason.valueOf(cause.getName().toUpperCase());
    }

    Optional<EconomyService> optionalEconomy =
        Sponge.getServiceManager().provide(EconomyService.class);

    if (!optionalEconomy.isPresent()) {
      Main.instance().getLog().error("Economy plugin not found");
      return;
    }
    EconomyService economy = optionalEconomy.get();

    BigDecimal balance =
        economy
            .getOrCreateAccount(player.getUniqueId())
            .get()
            .getBalance(WorldSettings.get(player.getWorld()).getCurrency());

    PlayerWallet wallet = settings.getPlayerWallet();

    BigDecimal amount = wallet.getAmount(reason, balance);

    WalletDropEvent walletDropEvent = new WalletDropEvent(amount, player);

    if (walletDropEvent.getAmount().compareTo(BigDecimal.ZERO) != 0
        && (!Sponge.getEventManager().post(walletDropEvent))) {
      WalletDrop.depositOrWithdraw(
          player, walletDropEvent.getAmount().multiply(BigDecimal.valueOf(-1)));

      if (settings.isDropsEnabled()) {
        for (MoneyStack moneyStack : walletDropEvent.getMoneyStacks()) {
          moneyStack.drop(walletDropEvent.getLocation());
        }
      }

      WalletDrop.sendDeathMessage(
          WorldSettings.get(player.getWorld()), player, walletDropEvent.getAmount());
    }
  }
Esempio n. 5
0
  @Listener
  public void onDestructEntityEventDeath(
      DestructEntityEvent.Death event,
      @Getter("getTargetEntity") @Has(MoneyData.class) Living entity) {
    if (entity instanceof Player) {
      return;
    }

    if (entity.getType().equals(EntityTypes.ARMOR_STAND)
        || entity.getType().equals(EntityTypes.HUMAN)) {
      return;
    }

    WorldSettings settings = WorldSettings.get(entity.getWorld());

    if (settings.getDropsPerSecond().isAtDropLimit()) {
      return;
    }

    Optional<MobWallet> optionalWallet = settings.getMobWallet(entity);

    if (!optionalWallet.isPresent()) {
      return;
    }
    MobWallet wallet = optionalWallet.get();

    if (BigDecimal.valueOf(random.nextDouble()).compareTo(wallet.getFrequency()) >= 0) {
      return;
    }

    BigDecimal amount = wallet.getAmount(settings.getPrecision());

    if (amount.compareTo(BigDecimal.ZERO) == 0) {
      return;
    }

    WalletDropEvent walletDropEvent = new WalletDropEvent(amount, entity);

    if (settings.isDropsEnabled()) {
      Optional<Player> optionalPlayer = validPlayer(event.getCause());

      if (optionalPlayer.isPresent()) {
        Player player = optionalPlayer.get();

        if (player.gameMode().get().equals(GameModes.CREATIVE)
            && !settings.isCreativeModeAllowed()) {
          return;
        }

        if (settings.isUsePermissions()) {
          if (!player.hasPermission("walletdrop.enable")) {
            return;
          }
        }
      } else {
        if (settings.isKillOnlyDrops()) {
          return;
        }
      }

      if (!Sponge.getEventManager().post(walletDropEvent)) {
        settings.getDropsPerSecond().add();

        for (MoneyStack moneyStack : walletDropEvent.getMoneyStacks()) {
          moneyStack.drop(walletDropEvent.getLocation());
        }
      }
    } else {
      Optional<Player> optionalPlayer = validPlayer(event.getCause());

      if (!optionalPlayer.isPresent()) {
        return;
      }
      Player player = optionalPlayer.get();

      if (player.gameMode().get().equals(GameModes.CREATIVE) && !settings.isCreativeModeAllowed()) {
        return;
      }

      if (settings.isUsePermissions()) {
        if (!player.hasPermission("walletdrop.enable")) {
          return;
        }
      }

      if (!Sponge.getEventManager().post(walletDropEvent)) {
        settings.getDropsPerSecond().add();

        WalletDrop.depositOrWithdraw(player, walletDropEvent.getAmount());

        WalletDrop.sendPickupMessage(player, walletDropEvent.getAmount());
      }
    }
  }