Beispiel #1
0
  @Listener
  public void onPlayerDropItem(DropItemEvent.Dispense event, @Root Player player) {
    if (!ConfigManager.canPlayersDropItems()) {
      final String playerPolisName = ConfigManager.getTeam(player.getUniqueId());
      event
          .getEntities()
          .forEach(
              e -> {
                String isClaimed = ConfigManager.isClaimed(e.getLocation());

                if (!isClaimed.equals("false")) {
                  if (playerPolisName == null || !playerPolisName.equals(isClaimed)) {
                    player.sendMessage(
                        Text.of(
                            TextColors.DARK_RED,
                            "Error! ",
                            TextColors.RED,
                            "You cannot drop items in claimed areas."));
                    event.setCancelled(true);
                    return;
                  }
                }
              });
    }
  }
  public CommandResult execute(CommandSource src, CommandContext ctx) throws CommandException {
    if (src instanceof Player) {
      Player player = (Player) src;
      String playerTeamName = ConfigManager.getTeam(player.getUniqueId());

      if (playerTeamName != null
          && !ConfigManager.getMembers(playerTeamName).contains(player.getUniqueId().toString())) {
        BigDecimal money =
            ConfigManager.getClaimCost()
                .multiply(new BigDecimal(ConfigManager.getClaims(playerTeamName)));
        Polis.economyService
            .getOrCreateAccount(playerTeamName)
            .get()
            .deposit(
                Polis.economyService.getDefaultCurrency(),
                money,
                Cause.of(NamedCause.source(player)));
        ConfigManager.depositToTownBank(money, playerTeamName);
        ConfigManager.removeClaims(playerTeamName);
        player.sendMessage(
            Text.of(
                TextColors.GREEN,
                "[Polis]: ",
                TextColors.GOLD,
                "Successfully removed all claims!"));
      } else if (playerTeamName != null) {
        player.sendMessage(
            Text.of(
                TextColors.GREEN,
                "[Polis]: ",
                TextColors.DARK_RED,
                "Error! ",
                TextColors.RED,
                "Ask your leader to remove all claims!"));
      } else {
        player.sendMessage(
            Text.of(
                TextColors.GREEN,
                "[Polis]: ",
                TextColors.DARK_RED,
                "Error! ",
                TextColors.RED,
                "You're not part of a town!"));
      }
    } else {
      src.sendMessage(
          Text.of(
              TextColors.DARK_RED,
              "Error! ",
              TextColors.RED,
              "Must be an in-game player to use /polis unclaimall!"));
    }

    return CommandResult.success();
  }