Пример #1
0
  @Override
  public void onProtectionInteract(LWCProtectionInteractEvent event) {
    if (event.getResult() != Result.DEFAULT) {
      return;
    }

    if (!event.hasAction("create")) {
      return;
    }

    LWC lwc = event.getLWC();
    Protection protection = event.getProtection();
    Player player = event.getPlayer();

    if (protection.isOwner(player)) {
      lwc.sendLocale(
          player,
          "protection.interact.error.alreadyregistered",
          "block",
          LWC.materialToString(protection.getBlockId()));
    } else {
      lwc.sendLocale(
          player,
          "protection.interact.error.notowner",
          "block",
          LWC.materialToString(protection.getBlockId()));
    }

    lwc.removeModes(player);
    event.setResult(Result.CANCEL);
  }
Пример #2
0
  @Override
  public void onBlockInteract(LWCBlockInteractEvent event) {
    if (event.getResult() != Result.DEFAULT) {
      return;
    }

    if (!event.hasAction("info")) {
      return;
    }

    LWC lwc = event.getLWC();
    Block block = event.getBlock();
    Player player = event.getPlayer();
    event.setResult(Result.CANCEL);

    lwc.sendLocale(
        player, "protection.interact.error.notregistered", "block", LWC.materialToString(block));
    lwc.removeModes(player);
  }
Пример #3
0
  /**
   * Sends the list of limits to the player
   *
   * @param sender the commandsender to send the limits to
   * @param target the player limits are being shown for, can be null
   * @param limits
   */
  public void sendLimits(CommandSender sender, Player target, List<Limit> limits) {
    LWC lwc = LWC.getInstance();

    for (Limit limit : limits) {
      if (limit == null) {
        continue;
      }

      String stringLimit =
          limit.getLimit() == UNLIMITED ? "Unlimited" : Integer.toString(limit.getLimit());
      String colour = Colors.Yellow;

      if (target != null) {
        boolean reachedLimit =
            hasReachedLimit(
                target,
                ((limit instanceof BlockLimit) ? ((BlockLimit) limit).getMaterial() : null));
        colour = reachedLimit ? Colors.Red : Colors.Green;
      }

      if (limit instanceof DefaultLimit) {
        String currentProtected =
            target != null ? (Integer.toString(limit.getProtectionCount(target, null)) + "/") : "";
        sender.sendMessage("Default: " + colour + currentProtected + stringLimit);
      } else if (limit instanceof BlockLimit) {
        BlockLimit blockLimit = (BlockLimit) limit;
        String currentProtected =
            target != null
                ? (Integer.toString(limit.getProtectionCount(target, blockLimit.getMaterial()))
                    + "/")
                : "";
        sender.sendMessage(
            lwc.materialToString(blockLimit.getMaterial())
                + ": "
                + colour
                + currentProtected
                + stringLimit);
      } else {
        sender.sendMessage(limit.getClass().getSimpleName() + ": " + Colors.Yellow + stringLimit);
      }
    }
  }
Пример #4
0
  @Override
  public Result onDestroyProtection(
      LWC lwc,
      Player player,
      Protection protection,
      Block block,
      boolean canAccess,
      boolean canAdmin) {
    boolean isOwner = protection.isOwner(player);

    if (isOwner) {
      protection.remove();
      lwc.sendLocale(
          player,
          "protection.unregistered",
          "block",
          LWC.materialToString(protection.getBlockId()));
      return ALLOW;
    }

    return CANCEL;
  }
Пример #5
0
  public void onDestroyProtection(LWCProtectionDestroyEvent event) {
    if (event.isCancelled()) {
      return;
    }

    LWC lwc = event.getLWC();
    Protection protection = event.getProtection();
    Player player = event.getPlayer();

    boolean isOwner = protection.isOwner(player);

    if (isOwner) {
      protection.remove();
      lwc.sendLocale(
          player,
          "protection.unregistered",
          "block",
          LWC.materialToString(protection.getBlockId()));
      return;
    }

    event.setCancelled(true);
    return;
  }