コード例 #1
0
  private void registerSpigot(DelayedPacketManager delayed) {
    // Use netty if we have a non-standard ServerConnection class
    nettyEnabled =
        !MinecraftReflection.isMinecraftObject(
            InjectedServerConnection.getServerConnection(reporter, server));

    // Switch to the standard manager
    delayed.setDelegate(buildInternal());
  }
コード例 #2
0
  /**
   * Create a new packet filter manager.
   *
   * @return A new packet filter manager.
   */
  public InternalManager build() {
    if (reporter == null) throw new IllegalArgumentException("reporter cannot be NULL.");
    if (classLoader == null) throw new IllegalArgumentException("classLoader cannot be NULL.");

    asyncManager = new AsyncFilterManager(reporter, server.getScheduler());
    nettyEnabled = false;

    // Spigot
    if (SpigotPacketInjector.canUseSpigotListener()) {
      // If the server hasn't loaded yet - wait
      if (InjectedServerConnection.getServerConnection(reporter, server) == null) {
        // We need to delay this until we know if Netty is enabled
        final DelayedPacketManager delayed = new DelayedPacketManager(reporter, mcVersion);

        // They must reference each other
        delayed.setAsynchronousManager(asyncManager);
        asyncManager.setManager(delayed);

        Futures.addCallback(
            BukkitFutures.nextEvent(library, WorldInitEvent.class),
            new FutureCallback<WorldInitEvent>() {
              @Override
              public void onSuccess(WorldInitEvent event) {
                // Nevermind
                if (delayed.isClosed()) return;

                try {
                  registerSpigot(delayed);
                } catch (Exception e) {
                  onFailure(e);
                }
              }

              @Override
              public void onFailure(Throwable error) {
                reporter.reportWarning(
                    PacketFilterBuilder.this,
                    Report.newBuilder(REPORT_TEMPORARY_EVENT_ERROR).error(error));
              }
            });

        System.out.println("Delaying due to Spigot");

        // Let plugins use this version instead
        return delayed;
      } else {
        nettyEnabled =
            !MinecraftReflection.isMinecraftObject(
                InjectedServerConnection.getServerConnection(reporter, server));
      }
    }

    // Otherwise - construct the packet filter manager right away
    return buildInternal();
  }