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