コード例 #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
ファイル: DropTransferModule.java プロジェクト: Carpeeet/LWC
  @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();
  }
コード例 #3
0
ファイル: InfoModule.java プロジェクト: pyrodogg/LWC
  @Override
  public void onProtectionInteract(LWCProtectionInteractEvent event) {
    if (event.getResult() != Result.DEFAULT) {
      return;
    }

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

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

    String type =
        lwc.getPlugin().getMessageParser().parseMessage(protection.typeToString().toLowerCase());
    lwc.sendLocale(player, "lwc.info", "owner", protection.getOwner(), "type", type);

    if (event.canAdmin()) {
      if (protection.getType() == Protection.Type.PRIVATE
          || protection.getType() == Protection.Type.DONATION) {
        lwc.sendLocale(player, "lwc.acl", "size", protection.getPermissions().size());
        int index = 0;
        for (Permission permission : protection.getPermissions()) {
          if (index >= 9) {
            break;
          }

          player.sendMessage(permission.toString());
          index++;
        }

        if (index == 0) {
          lwc.sendLocale(player, "lwc.acl.empty");
        } else if (index >= 9) {
          lwc.sendLocale(player, "lwc.acl.limitreached");
        }

        player.sendMessage("");
      }
    }

    if (lwc.isAdmin(player)) {
      lwc.sendLocale(player, "protection.interact.info.raw", "raw", protection.toString());
    }

    lwc.removeModes(player);
  }
コード例 #4
0
ファイル: AdminForceOwner.java プロジェクト: epuidokas/LWC
  @Override
  public void onProtectionInteract(LWCProtectionInteractEvent event) {
    if (event.getResult() != Result.DEFAULT) {
      return;
    }

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

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

    Action action = lwc.getMemoryDatabase().getAction("forceowner", player.getName());
    String newOwner = action.getData();

    protection.setOwner(newOwner);
    protection.save();

    lwc.sendLocale(player, "protection.interact.forceowner.finalize", "player", newOwner);
    lwc.removeModes(player);
    event.setResult(Result.CANCEL);

    return;
  }
コード例 #5
0
ファイル: InfoModule.java プロジェクト: pyrodogg/LWC
  @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");
    }
  }
コード例 #6
0
ファイル: DropTransferModule.java プロジェクト: Carpeeet/LWC
  @Override
  public void onBlockInteract(LWCBlockInteractEvent event) {
    Player player = event.getPlayer();
    Set<String> actions = event.getActions();

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

    lwc.sendLocale(player, "protection.interact.dropxfer.notprotected");
    lwc.removeModes(player);
  }
コード例 #7
0
ファイル: DropTransferModule.java プロジェクト: Carpeeet/LWC
  @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
  }
コード例 #8
0
ファイル: AdminForceOwner.java プロジェクト: epuidokas/LWC
  @Override
  public void onCommand(LWCCommandEvent event) {
    if (event.isCancelled()) {
      return;
    }

    if (!event.hasFlag("a", "admin")) {
      return;
    }

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

    if (!args[0].equals("forceowner")) {
      return;
    }

    // we have the right command
    event.setCancelled(true);

    if (args.length < 2) {
      lwc.sendSimpleUsage(sender, "/lwc admin forceowner <player>");
      return;
    }

    if (!(sender instanceof Player)) {
      lwc.sendLocale(sender, "protection.admin.noconsole");
      return;
    }

    Player player = (Player) sender;
    String newOwner = args[1];

    lwc.getMemoryDatabase().registerAction("forceowner", player.getName(), newOwner);
    lwc.sendLocale(sender, "protection.admin.forceowner.finalize", "player", newOwner);

    return;
  }
コード例 #9
0
ファイル: Unlock.java プロジェクト: AaronW/LWC
  @Override
  public void execute(LWC lwc, CommandSender sender, String[] args) {
    if (args.length < 2) {
      lwc.sendSimpleUsage(sender, "/lwc -u <Password>");
      return;
    }

    Player player = (Player) sender;
    String password = join(args, 1);
    password = encrypt(password);

    if (!lwc.getMemoryDatabase().hasPendingUnlock(player.getName())) {
      player.sendMessage(Colors.Red + "Nothing selected. Open a locked protection first.");
      return;
    } else {
      int chestID = lwc.getMemoryDatabase().getUnlockID(player.getName());

      if (chestID == -1) {
        lwc.sendLocale(player, "protection.internalerror", "id", "ulock");
        return;
      }

      Protection entity = lwc.getPhysicalDatabase().loadProtection(chestID);

      if (entity.getType() != ProtectionTypes.PASSWORD) {
        lwc.sendLocale(player, "protection.unlock.notpassword");
        return;
      }

      if (entity.getData().equals(password)) {
        lwc.getMemoryDatabase().unregisterUnlock(player.getName());
        lwc.getMemoryDatabase().registerPlayer(player.getName(), chestID);
        lwc.sendLocale(player, "protection.unlock.password.valid");
      } else {
        lwc.sendLocale(player, "protection.unlock.password.invalid");
      }
    }
  }
コード例 #10
0
ファイル: LimitsV2.java プロジェクト: Kainzo/LWC
  @Override
  public void onRegisterProtection(LWCProtectionRegisterEvent event) {
    if (event.isCancelled()) {
      return;
    }

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

    if (hasReachedLimit(player, block.getType())) {
      lwc.sendLocale(player, "protection.exceeded");
      event.setCancelled(true);
    }
  }
コード例 #11
0
ファイル: InfoModule.java プロジェクト: pyrodogg/LWC
  @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);
  }
コード例 #12
0
ファイル: LimitsV2.java プロジェクト: Kainzo/LWC
  @Override
  public void onCommand(LWCCommandEvent event) {
    if (event.isCancelled()) {
      return;
    }

    if (!event.hasFlag("limits")) {
      return;
    }

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

    if (args.length == 0 && !(sender instanceof Player)) {
      sender.sendMessage(Colors.Red + "Unsupported");
      return;
    }

    String playerName;

    if (args.length == 0) {
      playerName = sender.getName();
    } else {
      if (lwc.isAdmin(sender)) {
        playerName = args[0];
      } else {
        lwc.sendLocale(sender, "protection.accessdenied");
        return;
      }
    }

    Player player = lwc.getPlugin().getServer().getPlayer(playerName);

    if (player == null) {
      return;
    }

    // send their limits to them
    sendLimits(player, player, getPlayerLimits(player));
  }
コード例 #13
0
ファイル: BaseAdminModule.java プロジェクト: andune/LWC
  @Override
  public Result onCommand(LWC lwc, CommandSender sender, String command, String[] args) {
    if (!StringUtils.hasFlag(command, "a") && !StringUtils.hasFlag(command, "admin")) {
      return DEFAULT;
    }

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

      return CANCEL;
    } else if (args.length > 0) {
      // check for permissions
      if (!lwc.hasAdminPermission(sender, "lwc.admin." + args[0])) {
        return CANCEL;
      }
    }

    return DEFAULT;
  }
コード例 #14
0
ファイル: DestroyModule.java プロジェクト: nikkirae/LWC
  @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;
  }
コード例 #15
0
ファイル: DestroyModule.java プロジェクト: Joannou1/LWC
  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;
  }
コード例 #16
0
ファイル: AdminView.java プロジェクト: Joannou1/LWC
  @Override
  public void onCommand(LWCCommandEvent event) {
    if (event.isCancelled()) {
      return;
    }

    if (!event.hasFlag("a", "admin")) {
      return;
    }

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

    if (!args[0].equals("view")) {
      return;
    }

    // we have the right command
    event.setCancelled(true);

    if (!(sender instanceof Player)) {
      lwc.sendLocale(sender, "protection.admin.noconsole");
      return;
    }

    Player player = (Player) sender;
    World world = player.getWorld();

    if (args.length < 2) {
      lwc.sendSimpleUsage(sender, "/lwc admin view <id>");
      return;
    }

    int protectionId = Integer.parseInt(args[1]);
    Protection protection = lwc.getPhysicalDatabase().loadProtection(protectionId);

    if (protection == null) {
      lwc.sendLocale(sender, "protection.admin.view.noexist");
      return;
    }

    Block block = world.getBlockAt(protection.getX(), protection.getY(), protection.getZ());

    if (!(block.getState() instanceof ContainerBlock)) {
      lwc.sendLocale(sender, "protection.admin.view.noinventory");
      return;
    }

    net.minecraft.server.World handle = ((CraftWorld) block.getWorld()).getHandle();
    EntityHuman human = ((CraftHumanEntity) player).getHandle();
    int x = block.getX();
    int y = block.getY();
    int z = block.getZ();

    switch (block.getType()) {
      case CHEST:
        net.minecraft.server.Block.CHEST.a(handle, x, y, z, human);
        break;

      case FURNACE:
        net.minecraft.server.Block.FURNACE.a(handle, x, y, z, human);
        break;

      case DISPENSER:
        net.minecraft.server.Block.DISPENSER.a(handle, x, y, z, human);
        break;
    }

    lwc.sendLocale(sender, "protection.admin.view.viewing", "id", protectionId);
    return;
  }
コード例 #17
0
ファイル: DropTransferModule.java プロジェクト: Carpeeet/LWC
  @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");
        }
      }
    }
  }
コード例 #18
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);
  }
コード例 #19
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));
  }