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.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");
        }
      }
    }
  }