示例#1
0
  @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;
  }
示例#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");
    }
  }
示例#3
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);
  }
示例#4
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));
  }
示例#5
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");
        }
      }
    }
  }