Esempio n. 1
0
  @Listener
  public void onSpawnEntityEvent(SpawnEntityEvent event, @Root SpawnCause cause) {
    WorldSettings settings = WorldSettings.get(event.getTargetWorld());

    if (!settings.isVanillaSpawnerAllowed() && cause.getType().equals(SpawnTypes.MOB_SPAWNER)) {
      return;
    } else if (!settings.isModSpawnerAllowed() && cause.getType().equals(SpawnTypes.CUSTOM)) {
      return;
    } else if (!settings.isPluginSpawnerAllowed() && cause.getType().equals(SpawnTypes.PLUGIN)) {
      return;
    } else if (!settings.isEggSpawnerAllowed() && cause.getType().equals(SpawnTypes.SPAWN_EGG)) {
      return;
    }

    for (Entity entity : event.getEntities()) {
      entity.offer(Sponge.getDataManager().getManipulatorBuilder(MoneyData.class).get().create());
    }
  }
Esempio n. 2
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);
      }
    }
  }
Esempio n. 3
0
  @Listener
  public void onInteractInventoryEvent(InteractInventoryEvent.Open event, @Root Player player) {
    if (!event.getTargetInventory().getArchetype().getId().equals("minecraft:player")) {
      WorldSettings settings = WorldSettings.get(player.getWorld());

      if (settings.isNonPlayerPickupAllowed()) {
        return;
      }

      Iterable<Inventory> iterable;

      try {
        iterable = event.getTargetInventory().slots();
      } catch (Exception e) {
        return;
      }

      for (Inventory inventory : iterable) {
        Slot slot = (Slot) inventory;

        Optional<ItemStack> optionalItemStack = slot.peek();

        if (!optionalItemStack.isPresent()) {
          continue;
        }
        ItemStack itemStack = optionalItemStack.get();

        BigDecimal amount = WalletDrop.getValue(itemStack);

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

        slot.clear();
      }
    }
  }
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());
      }
    }
  }