com.velocitypowered.api.plugin.PluginContainer Java Examples

The following examples show how to use com.velocitypowered.api.plugin.PluginContainer. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JavaPluginLoader.java    From Velocity with MIT License 6 votes vote down vote up
@Override
public PluginContainer createPlugin(PluginDescription description) throws Exception {
  if (!(description instanceof JavaVelocityPluginDescription)) {
    throw new IllegalArgumentException("Description provided isn't of the Java plugin loader");
  }

  JavaVelocityPluginDescription javaDescription = (JavaVelocityPluginDescription) description;
  Optional<Path> source = javaDescription.getSource();

  if (!source.isPresent()) {
    throw new IllegalArgumentException("No path in plugin description");
  }

  Injector injector = Guice
      .createInjector(new VelocityPluginModule(server, javaDescription, baseDirectory));
  Object instance = injector.getInstance(javaDescription.getMainClass());

  if (instance == null) {
    throw new IllegalStateException(
        "Got nothing from injector for plugin " + javaDescription.getId());
  }

  return new VelocityPluginContainer(description, instance);
}
 
Example #2
Source File: GS4QueryHandler.java    From Velocity with MIT License 6 votes vote down vote up
private List<QueryResponse.PluginInformation> getRealPluginInformation() {
  // Effective Java, Third Edition; Item 83: Use lazy initialization judiciously
  List<QueryResponse.PluginInformation> res = pluginInformationList;
  if (res == null) {
    synchronized (this) {
      if (pluginInformationList == null) {
        pluginInformationList = res = server.getPluginManager().getPlugins().stream()
            .map(PluginContainer::getDescription)
            .map(desc -> QueryResponse.PluginInformation
                .of(desc.getName().orElse(desc.getId()), desc.getVersion().orElse(null)))
            .collect(Collectors.toList());
      }
    }
  }
  return res;
}
 
Example #3
Source File: VelocityCommand.java    From Velocity with MIT License 6 votes vote down vote up
@Override
public void execute(CommandSource source, String @NonNull [] args) {
  if (args.length != 0) {
    source.sendMessage(TextComponent.of("/velocity plugins", TextColor.RED));
    return;
  }

  List<PluginContainer> plugins = ImmutableList.copyOf(server.getPluginManager().getPlugins());
  int pluginCount = plugins.size();

  if (pluginCount == 0) {
    source.sendMessage(TextComponent.of("No plugins installed.", TextColor.YELLOW));
    return;
  }

  TextComponent.Builder output = TextComponent.builder("Plugins: ")
      .color(TextColor.YELLOW);
  for (int i = 0; i < pluginCount; i++) {
    PluginContainer plugin = plugins.get(i);
    output.append(componentForPlugin(plugin.getDescription()));
    if (i + 1 < pluginCount) {
      output.append(TextComponent.of(", "));
    }
  }

  source.sendMessage(output.build());
}
 
Example #4
Source File: VelocityViaLoader.java    From ViaVersion with MIT License 6 votes vote down vote up
@Override
public void load() {
    Object plugin = VelocityPlugin.PROXY.getPluginManager()
            .getPlugin("viaversion").flatMap(PluginContainer::getInstance).get();

    if (ProtocolRegistry.SERVER_PROTOCOL < ProtocolVersion.v1_9.getId()) {
        Via.getManager().getProviders().use(MovementTransmitterProvider.class, new VelocityMovementTransmitter());
        Via.getManager().getProviders().use(BossBarProvider.class, new VelocityBossBarProvider());
        VelocityPlugin.PROXY.getEventManager().register(plugin, new ElytraPatch());
    }

    Via.getManager().getProviders().use(VersionProvider.class, new VelocityVersionProvider());
    // We probably don't need a EntityIdProvider because velocity sends a Join packet on server change
    // We don't need main hand patch because Join Game packet makes client send hand data again

    VelocityPlugin.PROXY.getEventManager().register(plugin, new UpdateListener());
    VelocityPlugin.PROXY.getEventManager().register(plugin, new VelocityServerHandler());

    int pingInterval = ((VelocityViaConfig) Via.getPlatform().getConf()).getVelocityPingInterval();
    if (pingInterval > 0) {
        Via.getPlatform().runRepeatingSync(
                new ProtocolDetectorService(),
                pingInterval * 20L);
    }
}
 
Example #5
Source File: VelocityPlugin.java    From ViaVersion with MIT License 6 votes vote down vote up
@Override
public JsonObject getDump() {
    JsonObject extra = new JsonObject();
    List<PluginInfo> plugins = new ArrayList<>();
    for (PluginContainer p : PROXY.getPluginManager().getPlugins()) {
        plugins.add(new PluginInfo(
                true,
                p.getDescription().getName().orElse(p.getDescription().getId()),
                p.getDescription().getVersion().orElse("Unknown Version"),
                p.getInstance().isPresent() ? p.getInstance().get().getClass().getCanonicalName() : "Unknown",
                p.getDescription().getAuthors()
        ));
    }
    extra.add("plugins", GsonUtil.getGson().toJsonTree(plugins));
    extra.add("servers", GsonUtil.getGson().toJsonTree(ProtocolDetectorService.getDetectedIds()));
    return extra;
}
 
Example #6
Source File: VelocityPluginManager.java    From Velocity with MIT License 5 votes vote down vote up
@Override
public Optional<PluginContainer> fromInstance(Object instance) {
  checkNotNull(instance, "instance");

  if (instance instanceof PluginContainer) {
    return Optional.of((PluginContainer) instance);
  }

  return Optional.ofNullable(pluginInstances.get(instance));
}
 
Example #7
Source File: FakePluginManager.java    From Velocity with MIT License 5 votes vote down vote up
@Override
public @NonNull Optional<PluginContainer> fromInstance(@NonNull Object instance) {
  if (instance == PLUGIN_A) {
    return Optional.of(PC_A);
  } else if (instance == PLUGIN_B) {
    return Optional.of(PC_B);
  } else {
    return Optional.empty();
  }
}
 
Example #8
Source File: FakePluginManager.java    From Velocity with MIT License 5 votes vote down vote up
@Override
public @NonNull Optional<PluginContainer> getPlugin(@NonNull String id) {
  switch (id) {
    case "a":
      return Optional.of(PC_A);
    case "b":
      return Optional.of(PC_B);
    default:
      return Optional.empty();
  }
}
 
Example #9
Source File: VelocityEventBus.java    From LuckPerms with MIT License 5 votes vote down vote up
@Override
protected PluginContainer checkPlugin(Object plugin) throws IllegalArgumentException {
    if (plugin instanceof PluginContainer) {
        return (PluginContainer) plugin;
    }

    PluginContainer pluginContainer = this.plugin.getBootstrap().getProxy().getPluginManager().fromInstance(plugin).orElse(null);
    if (pluginContainer != null) {
        return pluginContainer;
    }

    throw new IllegalArgumentException("Object " + plugin + " (" + plugin.getClass().getName() + ") is not a plugin.");
}
 
Example #10
Source File: GeyserVelocityConfiguration.java    From Geyser with MIT License 4 votes vote down vote up
public void loadFloodgate(GeyserVelocityPlugin plugin, ProxyServer proxyServer, File dataFolder) {
    Optional<PluginContainer> floodgate = proxyServer.getPluginManager().getPlugin("floodgate");
    floodgate.ifPresent(it -> floodgateKey = FloodgateKeyLoader.getKey(plugin.getGeyserLogger(), this, Paths.get(dataFolder.toString(), floodgateKeyFile.isEmpty() ? floodgateKeyFile : "public-key.pem"), it, Paths.get("plugins/floodgate/")));
}
 
Example #11
Source File: VelocityPluginManager.java    From Velocity with MIT License 4 votes vote down vote up
private void registerPlugin(PluginContainer plugin) {
  plugins.put(plugin.getDescription().getId(), plugin);
  Optional<?> instance = plugin.getInstance();
  instance.ifPresent(o -> pluginInstances.put(o, plugin));
}
 
Example #12
Source File: VelocityPluginManager.java    From Velocity with MIT License 4 votes vote down vote up
@Override
public Optional<PluginContainer> getPlugin(String id) {
  checkNotNull(id, "id");
  return Optional.ofNullable(plugins.get(id));
}
 
Example #13
Source File: VelocityPluginManager.java    From Velocity with MIT License 4 votes vote down vote up
@Override
public Collection<PluginContainer> getPlugins() {
  return Collections.unmodifiableCollection(plugins.values());
}
 
Example #14
Source File: FakePluginManager.java    From Velocity with MIT License 4 votes vote down vote up
@Override
public @NonNull Collection<PluginContainer> getPlugins() {
  return ImmutableList.of(PC_A, PC_B);
}
 
Example #15
Source File: SkinsRestorer.java    From SkinsRestorerX with GNU General Public License v3.0 3 votes vote down vote up
public String getVersion() {
    Optional<PluginContainer> plugin = this.getProxy().getPluginManager().getPlugin("skinsrestorer");

    if (!plugin.isPresent())
        return "";

    Optional<String> version = plugin.get().getDescription().getVersion();

    return version.orElse("");
}
 
Example #16
Source File: PluginLoader.java    From Velocity with MIT License votes vote down vote up
PluginContainer createPlugin(PluginDescription plugin) throws Exception;