예제 #1
0
  @Listener(order = Order.POST)
  public void onAffectSlotEvent(AffectSlotEvent event, @Root Player player) {
    for (SlotTransaction transaction : event.getTransactions()) {
      ItemStack itemStack = transaction.getFinal().createStack();

      BigDecimal amount = WalletDrop.getValue(itemStack);

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

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

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

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

      WalletPickupEvent moneyPickupEvent =
          new WalletPickupEvent(itemStack, amount, Cause.of(NamedCause.source(player)));

      if (!Sponge.getEventManager().post(moneyPickupEvent)) {
        Sponge.getScheduler()
            .createTaskBuilder()
            .delayTicks(2)
            .execute(
                c -> {
                  player.getInventory().query(itemStack).clear();
                })
            .submit(Main.getPlugin());

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

        WalletDrop.sendPickupMessage(player, amount);
      }
    }
  }
예제 #2
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());
      }
    }
  }