Esempio n. 1
0
 /**
  * Gets the configuration for a specified player.
  *
  * @param player the player
  * @return the configuration
  */
 public static BlockPlaceConfig getConfig(final Player player) {
   if (!worldsMap.containsKey(player.getWorld().getName()))
     worldsMap.put(
         player.getWorld().getName(),
         new BlockPlaceConfig(ConfigManager.getConfigFile(player.getWorld().getName())));
   return worldsMap.get(player.getWorld().getName());
 }
Esempio n. 2
0
  /**
   * Handle the '/nocheatplus reload' command.
   *
   * @param sender the sender
   * @return true, if successful
   */
  private void handleReloadCommand(final CommandSender sender) {
    final LogManager logManager = NCPAPIProvider.getNoCheatPlusAPI().getLogManager();
    if (!sender.equals(Bukkit.getConsoleSender())) {
      sender.sendMessage(TAG + "Reloading configuration...");
    }
    logManager.info(Streams.INIT, TAG + "Reloading configuration...");

    // Do the actual reload.
    ConfigManager.cleanup();
    ConfigManager.init(access);
    if (logManager instanceof INotifyReload) { // TODO: This is a band-aid.
      ((INotifyReload) logManager).onReload();
    }

    // Remove all cached configs.
    DataManager.clearConfigs(); // There you have to add XConfig.clear() form now on.

    // Remove some checks data.
    // TODO: Better concept (INotifyReload).
    for (final CheckType checkType :
        new CheckType[] {
          CheckType.BLOCKBREAK, CheckType.FIGHT,
        }) {
      DataManager.clearData(checkType);
    }

    // Reset debug flags to default (temp, heavy).
    DataManager.restoreDefaultDebugFlags();

    // Tell the registered listeners to adapt to new config, first sort them (!).
    Collections.sort(notifyReload, Order.cmpSetupOrder);
    for (final INotifyReload component : notifyReload) {
      component.onReload();
    }

    // Say to the other plugins that we've reloaded the configuration.
    Bukkit.getPluginManager().callEvent(new NCPReloadEvent());

    // Log reloading done.
    if (!sender.equals(Bukkit.getConsoleSender())) {
      sender.sendMessage(TAG + "Configuration reloaded!");
    }
    logManager.info(Streams.INIT, TAG + "Configuration reloaded.");
    logManager.info(
        Streams.DEFAULT_FILE,
        StringUtil.join(VersionCommand.getVersionInfo(), "\n")); // Queued (!).
  }
Esempio n. 3
0
 /** Fetch settings from the current default config. */
 private void adjustSettings() {
   final ConfigFile config = ConfigManager.getConfigFile();
   doExpireData = config.getBoolean(ConfPaths.DATA_EXPIRATION_ACTIVE);
   durExpireData =
       config.getLong(ConfPaths.DATA_EXPIRATION_DURATION, 1, 1000000, 60) * 60000L; // in minutes
   deleteData = config.getBoolean(ConfPaths.DATA_EXPIRATION_DATA, true); // hidden.
   deleteHistory = config.getBoolean(ConfPaths.DATA_EXPIRATION_HISTORY);
 }
Esempio n. 4
0
 public ReflectBlock(ReflectBase base, ReflectBlockPosition blockPosition)
     throws ClassNotFoundException {
   final Class<?> clazz = Class.forName(base.nmsPackageName + ".Block");
   // byID (static)
   nmsGetById = ReflectionUtil.getMethod(clazz, "getById", int.class);
   // getMaterial
   nmsGetMaterial = ReflectionUtil.getMethodNoArgs(clazz, "getMaterial");
   // updateShape
   Method method = null;
   Class<?> clazzIBlockAccess = Class.forName(base.nmsPackageName + ".IBlockAccess");
   if (blockPosition != null) {
     method =
         ReflectionUtil.getMethod(clazz, "updateShape", clazzIBlockAccess, blockPosition.nmsClass);
   }
   if (method == null) {
     method =
         ReflectionUtil.getMethod(
             clazz, "updateShape", clazzIBlockAccess, int.class, int.class, int.class);
     useBlockPosition = false;
   } else {
     useBlockPosition = true;
   }
   nmsUpdateShape = method;
   // Block bounds fetching. The array uses the order the methods (used to) appear in the nms
   // class.
   String[] names =
       new String[] {
         "getMinX", "getMaxX", "getMinY", "getMaxY", "getMinZ", "getMaxZ"
       }; // FUTURE GUESS.
   Method[] methods = tryBoundsMethods(clazz, names);
   if (methods == null) {
     names = guessBoundsMethodNames(clazz);
     if (names != null) {
       methods = tryBoundsMethods(clazz, names);
     }
     if (methods == null) {
       methods = new Method[] {null, null, null, null, null, null};
     }
   }
   // TODO: Test which is which [ALLOW to configure and also save used ones to config, by mc
   // version].
   // TODO: Dynamically test these ? [needs an extra world/space to place blocks inside of...]
   if (ConfigManager.getConfigFile().getBoolean(ConfPaths.LOGGING_EXTENDED_STATUS)) {
     NCPAPIProvider.getNoCheatPlusAPI()
         .getLogManager()
         .debug(
             Streams.INIT,
             "[NoCheatPlus] ReflectBlock: Use methods for shape: "
                 + StringUtil.join(Arrays.asList(names), ", "));
   }
   this.nmsGetMinX = methods[0];
   this.nmsGetMaxX = methods[1];
   this.nmsGetMinY = methods[2];
   this.nmsGetMaxY = methods[3];
   this.nmsGetMinZ = methods[4];
   this.nmsGetMaxZ = methods[5];
 }
Esempio n. 5
0
 /**
  * Get a per-world config.
  *
  * @param worldName Exact case world name.
  * @return
  */
 public static MovingConfig getConfig(final String worldName) {
   final MovingConfig cc = worldsMap.get(worldName);
   if (cc != null) {
     return cc;
   }
   final MovingConfig ccNew = new MovingConfig(ConfigManager.getConfigFile(worldName));
   worldsMap.put(worldName, ccNew);
   return ccNew;
 }
Esempio n. 6
0
  /**
   * Handle the '/nocheatplus reload' command.
   *
   * @param sender the sender
   * @return true, if successful
   */
  private void handleReloadCommand(final CommandSender sender) {
    sender.sendMessage(TAG + "Reloading configuration...");

    // Do the actual reload.
    ConfigManager.cleanup();
    ConfigManager.init(plugin);
    BlockBreakConfig.clear();
    BlockInteractConfig.clear();
    BlockPlaceConfig.clear();
    ChatConfig.clear();
    FightConfig.clear();
    InventoryConfig.clear();
    MovingConfig.clear();

    // Say to the other plugins that we've reloaded the configuration.
    Bukkit.getPluginManager().callEvent(new NCPReloadEvent());

    sender.sendMessage(TAG + "Configuration reloaded!");
  }
Esempio n. 7
0
  /* (non-Javadoc)
   * @see org.bukkit.command.CommandExecutor#onCommand(org.bukkit.command.CommandSender, org.bukkit.command.Command,
   * java.lang.String, java.lang.String[])
   */
  @Override
  public boolean onCommand(
      final CommandSender sender,
      final Command command,
      final String commandLabel,
      final String[] args) {
    /*
     *   ____                                          _
     *  / ___|___  _ __ ___  _ __ ___   __ _ _ __   __| |
     * | |   / _ \| '_ ` _ \| '_ ` _ \ / _` | '_ \ / _` |
     * | |__| (_) | | | | | | | | | | | (_| | | | | (_| |
     *  \____\___/|_| |_| |_|_| |_| |_|\__,_|_| |_|\__,_|
     */
    // Not our command, how did it get here?
    if (!command.getName().equalsIgnoreCase("nocheatplus")) return false;

    final boolean protectPlugins =
        ConfigManager.getConfigFile().getBoolean(ConfPaths.MISCELLANEOUS_PROTECTPLUGINS);

    if (args.length == 2
        && args[0].equalsIgnoreCase("info")
        && sender.hasPermission(Permissions.ADMINISTRATION_INFO))
      // Info command was used.
      handleInfoCommand(sender, args[1]);
    else if (args.length == 1
        && args[0].equalsIgnoreCase("reload")
        && sender.hasPermission(Permissions.ADMINISTRATION_RELOAD))
      // Reload command was used.
      handleReloadCommand(sender);
    else if (protectPlugins
        && !sender.hasPermission(Permissions.ADMINISTRATION_INFO)
        && !sender.hasPermission(Permissions.ADMINISTRATION_RELOAD))
      sender.sendMessage("Unknown command. Type \"help\" for help.");
    else return false;
    return true;
  }
  /**
   * 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;
  }