public static boolean protectBlock(Block block, String name) {
   boolean protect = false;
   if (lwc != null) {
     lwc.getPhysicalDatabase()
         .registerProtection(
             block.getTypeId(),
             ProtectionTypes.PRIVATE,
             block.getWorld().getName(),
             name,
             "",
             block.getX(),
             block.getY(),
             block.getZ());
     protect = true;
     TDebug.debug(
         DebugDetailLevel.EVERYTHING,
         block.getType().name()
             + " block protected for "
             + name
             + ". ("
             + block.getX()
             + ", "
             + block.getY()
             + ", "
             + block.getZ()
             + ")");
   }
   return protect;
 }
Exemplo n.º 2
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();
  }
Exemplo n.º 3
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");
      }
    }
  }
Exemplo n.º 4
0
  public static List<Protection> loadProtections(
      String arg0, int arg1, int arg2, int arg3, int arg4, int arg5, int arg6) {
    if (lwcPlugin == null) {
      loadPlugin();
    }

    if (lwcPlugin != null) {
      List<com.griefcraft.model.Protection> loadProtections =
          lwcPlugin.getPhysicalDatabase().loadProtections(arg0, arg1, arg2, arg3, arg4, arg5, arg6);

      List<Protection> protections = null;

      if (loadProtections != null) {
        protections = new ArrayList<Protection>();
        for (com.griefcraft.model.Protection loadProtection : loadProtections) {
          protections.add(new Protection(loadProtection));
        }
      }

      return protections;
    }
    return null;
  }
Exemplo n.º 5
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);
  }
Exemplo n.º 6
0
  /**
   * Send a performance report to a Console Sender
   *
   * @param sender
   */
  public static void sendReport(CommandSender sender) {
    LWC lwc = LWC.getInstance();

    sender.sendMessage(" ");
    sender.sendMessage(Colors.Red + "LWC Report");
    sender.sendMessage("  Version: " + Colors.Green + LWCInfo.FULL_VERSION);
    sender.sendMessage(
        "  Running time: " + Colors.Green + TimeUtil.timeToString(getTimeRunningSeconds()));
    sender.sendMessage(
        "  Players: "
            + Colors.Green
            + Bukkit.getServer().getOnlinePlayers().length
            + "/"
            + Bukkit.getServer().getMaxPlayers());
    sender.sendMessage(
        "  Item entities: "
            + Colors.Green
            + getEntityCount(Item.class)
            + "/"
            + getEntityCount(null));
    sender.sendMessage(" ");
    sender.sendMessage(Colors.Red + " ==== Modules ====");

    for (Map.Entry<Plugin, List<MetaData>> entry :
        lwc.getModuleLoader().getRegisteredModules().entrySet()) {
      Plugin plugin = entry.getKey();
      List<MetaData> modules = entry.getValue();

      // Why?
      if (plugin == null) {
        continue;
      }

      sender.sendMessage(
          "  "
              + Colors.Green
              + plugin.getDescription().getName()
              + " v"
              + plugin.getDescription().getVersion()
              + Colors.Yellow
              + " -> "
              + Colors.Green
              + modules.size()
              + Colors.Yellow
              + " registered modules");
    }
    sender.sendMessage(" ");

    sender.sendMessage(Colors.Red + " ==== Database ====");
    sender.sendMessage("  Engine: " + Colors.Green + Database.DefaultType);
    sender.sendMessage(
        "  Protections: "
            + Colors.Green
            + formatNumber(lwc.getPhysicalDatabase().getProtectionCount()));
    sender.sendMessage(
        "  Queries: "
            + Colors.Green
            + formatNumber(queries)
            + " | "
            + String.format("%.2f", getAverage(queries))
            + " / second");
    sender.sendMessage(" ");

    sender.sendMessage(Colors.Red + " ==== Cache ==== ");
    ProtectionCache cache = lwc.getProtectionCache();
    sender.sendMessage("  Refs: " + cache.size() + "/" + cache.capacity());
    sender.sendMessage(
        "  Reads: "
            + formatNumber(cache.getReads())
            + " | "
            + String.format("%.2f", getAverage(cache.getReads()))
            + " / second");
    sender.sendMessage(
        "  Writes: "
            + formatNumber(cache.getWrites())
            + " | "
            + String.format("%.2f", getAverage(cache.getWrites()))
            + " / second");
  }
Exemplo n.º 7
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;
  }