Esempio n. 1
0
 public void setReply(Player pl) {
   reply = pl.getUniqueId();
   JsonConfig conf = getPlayerConfig();
   conf.set("reply", pl.getUniqueId().toString());
   conf.save();
   save();
 }
  public void toggleNotifications(Player player) {
    boolean notify =
        accountConfig.getNode(player.getUniqueId().toString(), "jobnotifications").getBoolean();

    if (notify == true) {
      accountConfig.getNode(player.getUniqueId().toString(), "jobnotifications").setValue(false);
      notify = false;
    } else {
      accountConfig.getNode(player.getUniqueId().toString(), "jobnotifications").setValue(true);
      notify = true;
    }

    try {
      configManager.save(accountConfig);

      if (notify == true)
        player.sendMessage(
            Texts.of(TextColors.GRAY, "Notifications are now ", TextColors.GREEN, "ON"));
      else
        player.sendMessage(
            Texts.of(TextColors.GRAY, "Notifications are now ", TextColors.RED, "OFF"));
    } catch (IOException e) {
      player.sendMessage(
          Texts.of(
              TextColors.RED,
              "Error toggling notifications! Try again. If this keeps showing up, notify the server owner or plugin developer."));
      logger.warn("Could not save notification change!");
    }
  }
Esempio n. 3
0
  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();
  }
Esempio n. 4
0
 @Listener
 public void onInventoryClose(InteractInventoryEvent.Close event, @First Player player) {
   if ((event.getTargetInventory().equals(this.container))) {
     if (this.users.contains(player.getUniqueId())) {
       this.users.remove(player.getUniqueId());
       if (this.users.isEmpty()) {
         em.removeListener(owner, this); // no user left to check
       }
       this.onClose.forEach(Runnable::run);
     }
   }
 }
Esempio n. 5
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;
                  }
                }
              });
    }
  }
 @Listener
 public void onPlayerDeath(DestructEntityEvent event) {
   if (event.getTargetEntity() instanceof Player) {
     Player died = (Player) event.getTargetEntity();
     Utils.setLastDeathLocation(died.getUniqueId(), died.getLocation());
   }
 }
 @Listener
 public void onPlayerChat(MessageChannelEvent.Chat event) {
   Optional<Player> playerOptional = event.getCause().first(Player.class);
   if (!playerOptional.isPresent()) return;
   Player player = playerOptional.get();
   if (JobsLite.optionEnabled("chatPrefixes")) {
     String uuid = player.getUniqueId().toString();
     if (playerManager.playerExists(uuid)) {
       String currentJob = playerManager.getCurrentJob(uuid).trim();
       if (!currentJob.isEmpty()) {
         String displayName = jobManager.getDisplayName(currentJob);
         if (!displayName.isEmpty()) {
           if (JobsLite.optionEnabled("displayLevel")) {
             event.setMessage(
                 TextUtils.chatMessage(
                     player.getName(),
                     displayName,
                     playerManager.getCurrentLevel(uuid, currentJob),
                     jobManager.getColor(currentJob),
                     event.getRawMessage().toPlain()));
           } else {
             event.setMessage(
                 TextUtils.chatMessage(
                     player.getName(),
                     displayName,
                     jobManager.getColor(currentJob),
                     event.getRawMessage().toPlain()));
           }
         }
       }
     }
   }
 }
Esempio n. 8
0
 @Override
 public Optional<Text> getValue(@Nullable Object player) {
   if (player == null) return Optional.empty();
   if (player instanceof Player) {
     Player p = (Player) player;
     if (Sponge.getServiceManager().provide(EconomyService.class).isPresent()) {
       EconomyService es = Sponge.getServiceManager().provide(EconomyService.class).get();
       if (es.getOrCreateAccount(p.getUniqueId()).isPresent()) {
         BigDecimal balance =
             es.getOrCreateAccount(p.getUniqueId()).get().getBalance(es.getDefaultCurrency());
         return Optional.of(Text.of(balance.toString()));
       }
     }
     return Optional.empty();
   }
   return Optional.empty();
 }
Esempio n. 9
0
  public void createBlockBag(Player creator, BlockBag blockBag) {
    if (getBlockBag(creator.getUniqueId(), blockBag.simpleName) != null) {
      creator.sendMessage(Text.of(TextColors.RED, "A blockbag with this name already exists!"));
      return;
    }

    blockBag.blockBagId = getUnusedID();

    blockBags = Arrays.copyOf(blockBags, blockBags.length + 1);
    blockBags[blockBags.length - 1] = blockBag;
  }
Esempio n. 10
0
 @Listener(order = Order.FIRST)
 public void onPlayerChat(MessageChannelEvent.Chat event, @First Player player) {
   String message = event.getRawMessage().toPlain();
   if (player.getUniqueId().equals(uuid)) {
     if (message.equalsIgnoreCase("[cancel]")) {
       // Cancel the creation
       cancel();
       player.sendMessage(messages.getMessage("creation.cancelled"));
     }
   }
 }
Esempio n. 11
0
 public CreatingJob(UUID uuid) {
   this.uuid = uuid;
   // Add tasks
   addTasks(
       new NameTask(this),
       new MaxLevelTask(this),
       new ColorTask(this),
       new BlockDataTask(this),
       new BreakTask(this),
       new PlaceTask(this),
       new KillTask(this),
       new SilkTouchTask(this),
       new WorldGenTask(this),
       new FinalTask(this));
   // Send cancel message
   for (Player player : Sponge.getServer().getOnlinePlayers()) {
     if (player.getUniqueId().equals(uuid))
       player.sendMessage(messages.getMessage("creation.cancel"));
   }
   // Register listener
   Sponge.getEventManager().registerListeners(JobsLite.getInstance(), this);
   // Start task
   nextTask();
 }
  @Override
  public CommandResult execute(CommandSource src, CommandContext ctx) {
    Player player;
    try {
      player = GriefPrevention.checkPlayer(src);
    } catch (CommandException e) {
      src.sendMessage(e.getText());
      return CommandResult.success();
    }
    // which claim is being abandoned?
    PlayerData playerData =
        GriefPrevention.instance.dataStore.getOrCreatePlayerData(
            player.getWorld(), player.getUniqueId());
    Claim claim =
        GriefPrevention.instance.dataStore.getClaimAtPlayer(playerData, player.getLocation(), true);
    UUID ownerId = claim.ownerID;
    if (claim.parent != null) {
      ownerId = claim.parent.ownerID;
    }
    if (claim.isWildernessClaim()) {
      GriefPrevention.sendMessage(player, TextMode.Instr, Messages.AbandonClaimMissing);
      return CommandResult.success();
    } else if (claim.allowEdit(player) != null
        || (!claim.isAdminClaim() && !player.getUniqueId().equals(ownerId))) {
      // verify ownership
      GriefPrevention.sendMessage(player, TextMode.Err, Messages.NotYourClaim);
      return CommandResult.success();
    }

    // warn if has children and we're not explicitly deleting a top level claim
    else if (claim.children.size() > 0 && !deleteTopLevelClaim) {
      GriefPrevention.sendMessage(player, TextMode.Instr, Messages.DeleteTopLevelClaim);
      return CommandResult.empty();
    } else {
      // delete it
      claim.removeSurfaceFluids(null);
      // remove all context permissions
      player.getSubjectData().clearPermissions(ImmutableSet.of(claim.getContext()));
      GriefPrevention.GLOBAL_SUBJECT
          .getSubjectData()
          .clearPermissions(ImmutableSet.of(claim.getContext()));
      GriefPrevention.instance.dataStore.deleteClaim(claim, true);

      // if in a creative mode world, restore the claim area
      if (GriefPrevention.instance.claimModeIsActive(
          claim.getLesserBoundaryCorner().getExtent().getProperties(), ClaimsMode.Creative)) {
        GriefPrevention.addLogEntry(
            player.getName()
                + " abandoned a claim @ "
                + GriefPrevention.getfriendlyLocationString(claim.getLesserBoundaryCorner()));
        GriefPrevention.sendMessage(player, TextMode.Warn, Messages.UnclaimCleanupWarning);
        GriefPrevention.instance.restoreClaim(claim, 20L * 60 * 2);
      }

      // this prevents blocks being gained without spending adjust claim blocks when abandoning a
      // top level claim
      if (!claim.isSubdivision() && !claim.isAdminClaim()) {
        int newAccruedClaimCount =
            playerData.getAccruedClaimBlocks()
                - ((int) Math.ceil(claim.getArea() * (1 - playerData.optionAbandonReturnRatio)));
        playerData.setAccruedClaimBlocks(newAccruedClaimCount);
      }

      // tell the player how many claim blocks he has left
      int remainingBlocks = playerData.getRemainingClaimBlocks();
      GriefPrevention.sendMessage(
          player, TextMode.Success, Messages.AbandonSuccess, String.valueOf(remainingBlocks));
      // revert any current visualization
      playerData.revertActiveVisual(player);
      playerData.warnedAboutMajorDeletion = false;
    }

    return CommandResult.success();
  }
Esempio n. 13
0
  public CommandTicketCreate(CommandSource sender, String[] args) {

    if (sender instanceof Player == false) {
      sender.sendMessage(
          Texts.builder("Cannot be run by the console!").color(TextColors.RED).build());
      return;
    }

    if (args.length < 2) {
      sender.sendMessage(
          Texts.of(TextColors.YELLOW, "Usage: ", TextColors.GRAY, "/ticket create <message>"));
      return;
    }

    Player player = (Player) sender;
    String message = CommandUtils.combineArgs(1, args);

    int tickets = 0;
    for (Entry<Integer, CoreTicket> e : CoreDatabase.getTickets().entrySet()) {
      CoreTicket ticket = e.getValue();
      if (!ticket.getStatus().equalsIgnoreCase("open")) continue;
      if (!ticket.getUUID().equalsIgnoreCase(player.getUniqueId().toString())) continue;
      tickets += 1;
    }

    int possible = 0;
    for (int i = 1; i <= 100; i++) {
      if (PermissionsUtils.has(player, "core.ticket.create." + i)) possible = i;
    }

    if (!PermissionsUtils.has(player, "core.ticket.create-unlimited") && possible <= tickets) {
      if (possible == 1)
        sender.sendMessage(
            Texts.builder("You are only allowed to own " + possible + " open tickets!")
                .color(TextColors.RED)
                .build());
      else
        sender.sendMessage(
            Texts.builder("You are only allowed to own " + possible + " open tickets!")
                .color(TextColors.RED)
                .build());
      return;
    }

    int id = CoreDatabase.getTickets().size() + 1;

    String world = player.getWorld().getName();

    double x = player.getLocation().getX();
    double y = player.getLocation().getY();
    double z = player.getLocation().getZ();
    double yaw = player.getRotation().getX();
    double pitch = player.getRotation().getY();

    double time = System.currentTimeMillis();

    CoreTicket ticket =
        new CoreTicket(
            id,
            player.getUniqueId().toString(),
            message,
            time,
            new ArrayList<String>(),
            world,
            x,
            y,
            z,
            yaw,
            pitch,
            "",
            "medium",
            "open");
    ticket.insert();

    sender.sendMessage(
        Texts.of(
            TextColors.GRAY,
            "Ticket ",
            TextColors.GREEN,
            "#",
            id,
            TextColors.GRAY,
            " has been created!"));
  }
Esempio n. 14
0
  @Override
  public CommandResult process(CommandSource sender, String arguments) throws CommandException {

    String[] args = arguments.split(" ");

    if (sender instanceof Player == false) {
      sender.sendMessage(
          Texts.builder("Cannot be run by the console!").color(TextColors.RED).build());
      return CommandResult.success();
    }

    if (!PermissionsUtils.has(sender, "core.tpa")) {
      sender.sendMessage(
          Texts.builder("You do not have permissions!").color(TextColors.RED).build());
      return CommandResult.success();
    }

    if (arguments.equalsIgnoreCase("")) {
      sender.sendMessage(Texts.of(TextColors.YELLOW, "Usage: ", TextColors.GRAY, "/tpa <player>"));
      return CommandResult.success();
    }
    if (args.length < 1 || args.length > 1) {
      sender.sendMessage(Texts.of(TextColors.YELLOW, "Usage: ", TextColors.GRAY, "/tpa <player>"));
      return CommandResult.success();
    }

    Player s = (Player) sender;
    String uuid = s.getUniqueId().toString();

    Player player = CoreServer.getPlayer(args[0]);

    if (player == null) {
      sender.sendMessage(Texts.builder("Player not found!").color(TextColors.RED).build());
      return CommandResult.success();
    }

    CorePlayer p = CoreDatabase.getPlayer(player.getUniqueId().toString());
    HashMap<String, Double> tpa = p.getTPA();
    HashMap<String, Double> tpahere = p.getTPAHere();

    double duration = 0;
    if (tpa.containsKey(uuid)) duration = tpa.get(uuid);
    if (duration != 0) {
      if (duration <= System.currentTimeMillis()) {
        tpa.remove(uuid);
        p.setTPA(tpa);
      } else {
        sender.sendMessage(
            Texts.builder("You already requested a teleport from that player!")
                .color(TextColors.RED)
                .build());
        return CommandResult.success();
      }
    }

    duration = 0;

    if (tpahere.containsKey(uuid)) duration = tpahere.get(uuid);
    if (duration != 0) {
      if (duration <= System.currentTimeMillis()) {
        tpahere.remove(uuid);
        p.setTPAHere(tpahere);
      } else {
        sender.sendMessage(
            Texts.builder("You already requested a teleport from that player!")
                .color(TextColors.RED)
                .build());
        return CommandResult.success();
      }
    }

    duration = System.currentTimeMillis() + 30 * 1000;

    tpa.put(uuid, duration);
    p.setTPA(tpa);

    sender.sendMessage(
        Texts.of(
            TextColors.GRAY,
            "Teleport request has been sent to ",
            TextColors.YELLOW,
            player.getName()));
    player.sendMessage(
        Texts.of(
            TextColors.YELLOW,
            sender.getName(),
            TextColors.GRAY,
            " requested to teleport to you."));
    player.sendMessage(
        Texts.of(
            TextColors.GRAY,
            "Type ",
            TextColors.YELLOW,
            "/tpaccept ",
            sender.getName(),
            TextColors.GRAY,
            " or",
            TextColors.YELLOW,
            " /tpdeny ",
            sender.getName()));
    player.sendMessage(Texts.of(TextColors.GRAY, "to accept/decline the request."));

    return CommandResult.success();
  }
Esempio n. 15
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());
    }
  }