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