Exemple #1
0
 /**
  * Kick and log.
  *
  * @param player
  */
 public static void kickIllegalMove(final Player player) {
   player.kickPlayer("Illegal move.");
   StaticLog.logWarning("[NCP] Disconnect " + player.getName() + " due to illegal move!");
 }
  /**
   * This will be called from within the plugin in onEnable, after registration of all core
   * listeners and components. After each components addition processQueuedSubComponentHolders()
   * will be called to allow registries for further optional components.
   *
   * @param plugin
   * @return
   */
  public Collection<Object> getAvailableComponentsOnEnable(NoCheatPlus plugin) {
    final List<Object> available = new LinkedList<Object>();

    // Add components (try-catch).
    // TODO: catch ClassNotFound, incompatibleXY rather !?

    // Check: inventory.fastconsume.
    try {
      // TODO: Static test methods !?
      FastConsume.testAvailability();
      available.add(new FastConsume());
      NCPAPIProvider.getNoCheatPlusAPI()
          .addFeatureTags("checks", Arrays.asList(FastConsume.class.getSimpleName()));
    } catch (Throwable t) {
      StaticLog.logInfo("Inventory checks: FastConsume is not available.");
    }

    // Check: inventory.gutenberg.
    try {
      Gutenberg.testAvailability();
      available.add(new Gutenberg());
      NCPAPIProvider.getNoCheatPlusAPI()
          .addFeatureTags("checks", Arrays.asList(Gutenberg.class.getSimpleName()));
    } catch (Throwable t) {
      StaticLog.logInfo("Inventory checks: Gutenberg is not available.");
    }

    // Hot fix: falling block end portal.
    try {
      HotFixFallingBlockPortalEnter.testAvailability();
      available.add(new HotFixFallingBlockPortalEnter());
      NCPAPIProvider.getNoCheatPlusAPI()
          .addFeatureTags(
              "checks", Arrays.asList(HotFixFallingBlockPortalEnter.class.getSimpleName()));
    } catch (RuntimeException e) {
    }

    // ProtocolLib dependencies.
    if (protocolLibPresent.isAvailable()) {
      // Check conditions.
      boolean protocolLibAvailable = false;
      for (final IActivation condition : protocolLibActivation) {
        if (condition.isAvailable()) {
          protocolLibAvailable = true;
          break;
        }
      }
      // Attempt to react.
      if (protocolLibAvailable) {
        try {
          available.add(new ProtocolLibComponent(plugin));
        } catch (Throwable t) {
          StaticLog.logWarning("Failed to set up packet level access with ProtocolLib.");
          if (ConfigManager.getConfigFile().getBoolean(ConfPaths.LOGGING_EXTENDED_STATUS)) {
            NCPAPIProvider.getNoCheatPlusAPI().getLogManager().debug(Streams.INIT, t);
          }
        }
      } else {
        List<String> parts = new LinkedList<String>();
        parts.add("Packet level access via ProtocolLib not available, supported configurations: ");
        for (IDescriptiveActivation cond : protocolLibActivation) {
          parts.add(cond.getNeutralDescription());
        }
        StaticLog.logWarning(StringUtil.join(parts, " | "));
      }
    } else {
      StaticLog.logInfo("Packet level access: ProtocolLib is not available.");
    }

    return available;
  }