Example #1
0
  @Override
  @SuppressWarnings("deprecation")
  public void onDropItem(LWCDropItemEvent event) {
    Player bPlayer = event.getPlayer();
    Item item = event.getEvent().getItemDrop();
    ItemStack itemStack = item.getItemStack();

    LWCPlayer player = lwc.wrapPlayer(bPlayer);
    int protectionId = getPlayerDropTransferTarget(player);

    if (protectionId == -1) {
      return;
    }

    if (!isPlayerDropTransferring(player)) {
      return;
    }

    Protection protection = lwc.getPhysicalDatabase().loadProtection(protectionId);

    if (protection == null) {
      lwc.sendLocale(player, "lwc.nolongerexists");
      player.disableMode(player.getMode("dropTransfer"));
      return;
    }

    // load the world and the inventory
    World world = player.getServer().getWorld(protection.getWorld());

    if (world == null) {
      lwc.sendLocale(player, "lwc.invalidworld");
      player.disableMode(player.getMode("dropTransfer"));
      return;
    }

    // Don't allow them to transfer items across worlds
    if (bPlayer.getWorld() != world
        && !lwc.getConfiguration().getBoolean("modes.droptransfer.crossWorld", false)) {
      lwc.sendLocale(player, "lwc.dropxfer.acrossworlds");
      player.disableMode(player.getMode("dropTransfer"));
      return;
    }

    Block block = world.getBlockAt(protection.getX(), protection.getY(), protection.getZ());
    Map<Integer, ItemStack> remaining = lwc.depositItems(block, itemStack);

    if (remaining.size() > 0) {
      lwc.sendLocale(player, "lwc.dropxfer.chestfull");

      for (ItemStack temp : remaining.values()) {
        bPlayer.getInventory().addItem(temp);
      }
    }

    bPlayer.updateInventory(); // if they're in the chest and dropping items, this is required
    item.remove();
  }
Example #2
0
  @Override
  public void onCommand(LWCCommandEvent event) {
    if (event.isCancelled()) {
      return;
    }

    if (!event.hasFlag("i", "info")) {
      return;
    }

    LWC lwc = event.getLWC();
    CommandSender sender = event.getSender();
    String[] args = event.getArgs();

    if (!(sender instanceof Player)) {
      return;
    }

    event.setCancelled(true);

    if (!lwc.hasPlayerPermission(sender, "lwc.info")) {
      lwc.sendLocale(sender, "protection.accessdenied");
      return;
    }

    LWCPlayer player = lwc.wrapPlayer(sender);
    String type = "info";

    if (args.length > 0) {
      type = args[0].toLowerCase();
    }

    if (type.equals("info")) {
      Action action = new Action();
      action.setName("info");
      action.setPlayer(player);

      player.removeAllActions();
      player.addAction(action);

      lwc.sendLocale(player, "protection.info.finalize");
    }
  }
Example #3
0
  @Override
  public void onProtectionInteract(LWCProtectionInteractEvent event) {
    LWC lwc = event.getLWC();
    Protection protection = event.getProtection();
    Set<String> actions = event.getActions();
    boolean canAccess = event.canAccess();

    Player bPlayer = event.getPlayer();
    LWCPlayer player = lwc.wrapPlayer(bPlayer);

    if (!actions.contains("dropTransferSelect")) {
      return;
    }

    if (!canAccess) {
      lwc.sendLocale(player, "protection.interact.dropxfer.noaccess");
    } else {
      if (protection.getBlockId() != Material.CHEST.getId()) {
        lwc.sendLocale(player, "protection.interact.dropxfer.notchest");
        player.removeAllActions();
        event.setResult(Result.CANCEL);

        return;
      }

      Mode mode = new Mode();
      mode.setName("dropTransfer");
      mode.setData(protection.getId() + "");
      mode.setPlayer(bPlayer);
      player.enableMode(mode);
      mode = new Mode();
      mode.setName("+dropTransfer");
      mode.setPlayer(bPlayer);
      player.enableMode(mode);

      lwc.sendLocale(player, "protection.interact.dropxfer.finalize");
    }

    player.removeAllActions(); // ignore the persist mode
  }
Example #4
0
  /**
   * Get the drop transfer target for a player
   *
   * @param player
   * @return
   */
  private int getPlayerDropTransferTarget(LWCPlayer player) {
    Mode mode = player.getMode("dropTransfer");

    if (mode == null) {
      return -1;
    }

    String target = mode.getData();

    try {
      return Integer.parseInt(target);
    } catch (NumberFormatException e) {
    }

    return -1;
  }
Example #5
0
  @Override
  public void onBlockInteract(LWCBlockInteractEvent event) {
    if (event.getResult() != Result.DEFAULT) {
      return;
    }

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

    LWC lwc = event.getLWC();
    Block block = event.getBlock();
    LWCPlayer player = lwc.wrapPlayer(event.getPlayer());

    if (!lwc.isProtectable(block)) {
      return;
    }

    PhysDB physDb = lwc.getPhysicalDatabase();

    Action action = player.getAction("create");
    String actionData = action.getData();
    String[] split = actionData.split(" ");
    String protectionType = split[0].toLowerCase();
    String protectionData = StringUtil.join(split, 1);

    // check permissions again (DID THE LITTLE SHIT MOVE WORLDS??!?!?!?!?!?)
    if (!lwc.hasPermission(
        event.getPlayer(), "lwc.create." + protectionType, "lwc.create", "lwc.protect")) {
      lwc.sendLocale(player, "protection.accessdenied");
      lwc.removeModes(player);
      event.setResult(Result.CANCEL);
      return;
    }

    // misc data we'll use later
    String playerName = player.getName();
    String worldName = block.getWorld().getName();
    int blockX = block.getX();
    int blockY = block.getY();
    int blockZ = block.getZ();

    lwc.removeModes(player);
    LWCProtectionRegisterEvent evt =
        new LWCProtectionRegisterEvent(player.getBukkitPlayer(), block);
    lwc.getModuleLoader().dispatchEvent(evt);

    // another plugin cancelled the registration
    if (evt.isCancelled()) {
      return;
    }

    // The created protection
    Protection protection = null;

    if (protectionType.equals("public")) {
      protection =
          physDb.registerProtection(
              block.getTypeId(),
              Protection.Type.PUBLIC,
              worldName,
              player.getUniqueId().toString(),
              "",
              blockX,
              blockY,
              blockZ);
      lwc.sendLocale(player, "protection.interact.create.finalize");
    } else if (protectionType.equals("password")) {
      String password = lwc.encrypt(protectionData);

      protection =
          physDb.registerProtection(
              block.getTypeId(),
              Protection.Type.PASSWORD,
              worldName,
              player.getUniqueId().toString(),
              password,
              blockX,
              blockY,
              blockZ);
      player.addAccessibleProtection(protection);

      lwc.sendLocale(player, "protection.interact.create.finalize");
      lwc.sendLocale(player, "protection.interact.create.password");
    } else if (protectionType.equals("private") || protectionType.equals("donation")) {
      String[] rights = protectionData.split(" ");

      protection =
          physDb.registerProtection(
              block.getTypeId(),
              Protection.Type.matchType(protectionType),
              worldName,
              player.getUniqueId().toString(),
              "",
              blockX,
              blockY,
              blockZ);

      lwc.sendLocale(player, "protection.interact.create.finalize");
      lwc.processRightsModifications(player, protection, rights);
    }

    // tell the modules that a protection was registered
    if (protection != null) {
      // Fix the blocks that match it
      protection.removeCache();
      LWC.getInstance().getProtectionCache().addProtection(protection);

      lwc.getModuleLoader().dispatchEvent(new LWCProtectionRegistrationPostEvent(protection));
    }

    event.setResult(Result.CANCEL);
  }
Example #6
0
  @Override
  public void onCommand(LWCCommandEvent event) {
    if (event.isCancelled()) {
      return;
    }

    if (!event.hasFlag("c", "create")) {
      return;
    }

    LWC lwc = event.getLWC();
    CommandSender sender = event.getSender();
    String[] args = event.getArgs();

    if (!(sender instanceof Player)) {
      return;
    }

    if (args.length == 0) {
      lwc.sendLocale(sender, "help.creation");
      return;
    }

    LWCPlayer player = lwc.wrapPlayer(sender);

    String full = StringUtil.join(args, 0).trim();
    String type = args[0].toLowerCase();
    String data = StringUtil.join(args, 1);
    event.setCancelled(true);

    /**
     * Allow individual enforcements with e.g lwc.create.private, or just the umbrella lwc.create
     * for all
     */
    if (!lwc.hasPermission(sender, "lwc.create." + type, "lwc.create", "lwc.protect")) {
      lwc.sendLocale(sender, "protection.accessdenied");
      return;
    }

    try {
      switch (Protection.Type.matchType(type)) {
        case PASSWORD:
          if (args.length < 2) {
            lwc.sendSimpleUsage(player, "/lwc -c password <Password>");
            return;
          }

          String hiddenPass = StringUtil.transform(data, '*');
          lwc.sendLocale(player, "protection.create.password", "password", hiddenPass);
          break;
      }
    } catch (IllegalArgumentException e) {
      // Invalid protection type!
      lwc.sendLocale(player, "help.creation");
      return;
    }

    Action action = new Action();
    action.setName("create");
    action.setPlayer(player);
    action.setData(full);

    player.removeAllActions();
    player.addAction(action);

    lwc.sendLocale(
        player,
        "protection.create.finalize",
        "type",
        lwc.getPlugin().getMessageParser().parseMessage(type));
  }
Example #7
0
 /**
  * Check if the player is currently drop transferring
  *
  * @param player
  * @return
  */
 private boolean isPlayerDropTransferring(LWCPlayer player) {
   return player.hasMode("+dropTransfer");
 }
Example #8
0
  @Override
  public void onCommand(LWCCommandEvent event) {
    if (!event.hasFlag("p", "mode")) {
      return;
    }

    if (event.isCancelled()) {
      return;
    }

    LWC lwc = event.getLWC();
    CommandSender sender = event.getSender();
    String[] args = event.getArgs();

    LWCPlayer player = lwc.wrapPlayer(sender);
    String mode = args[0].toLowerCase();

    if (!mode.equals("droptransfer")) {
      return;
    }

    event.setCancelled(true);

    // internal name
    mode = "dropTransfer";

    if (args.length < 2) {
      lwc.sendLocale(player, "protection.modes.dropxfer.help");
      return;
    }

    String action = args[1].toLowerCase();
    String playerName = player.getName();

    if (action.equals("select")) {
      if (isPlayerDropTransferring(player)) {
        lwc.sendLocale(player, "protection.modes.dropxfer.select.error");
        return;
      }

      player.disableMode(player.getMode(mode));

      Action temp = new Action();
      temp.setName("dropTransferSelect");
      temp.setPlayer(player);

      player.addAction(temp);
      lwc.sendLocale(player, "protection.modes.dropxfer.select.finalize");
    } else if (action.equals("on")) {
      int target = getPlayerDropTransferTarget(player);

      if (target == -1) {
        lwc.sendLocale(player, "protection.modes.dropxfer.selectchest");
        return;
      }

      Mode temp = new Mode();
      temp.setName("+dropTransfer");
      temp.setPlayer(player.getBukkitPlayer());

      player.enableMode(temp);
      lwc.sendLocale(player, "protection.modes.dropxfer.on.finalize");
    } else if (action.equals("off")) {
      int target = getPlayerDropTransferTarget(player);

      if (target == -1) {
        lwc.sendLocale(player, "protection.modes.dropxfer.selectchest");
        return;
      }

      player.disableMode(player.getMode("+dropTransfer"));
      lwc.sendLocale(player, "protection.modes.dropxfer.off.finalize");
    } else if (action.equals("status")) {
      if (getPlayerDropTransferTarget(player) == -1) {
        lwc.sendLocale(player, "protection.modes.dropxfer.status.off");
      } else {
        if (isPlayerDropTransferring(player)) {
          lwc.sendLocale(player, "protection.modes.dropxfer.status.active");
        } else {
          lwc.sendLocale(player, "protection.modes.dropxfer.status.inactive");
        }
      }
    }
  }