Пример #1
0
  @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;
  }
Пример #2
0
  @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");
      }
    }
  }
Пример #3
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));
  }
Пример #4
0
  @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;
  }