Search in sources :

Example 1 with PluginContainer

use of com.velocitypowered.api.plugin.PluginContainer in project LibertyBans by A248.

the class VelocityLauncherTest method allBindings.

@Test
public void allBindings() {
    ProxyServer proxyServer = mock(ProxyServer.class);
    PluginContainer pluginContainer = mock(PluginContainer.class);
    assertNotNull(new VelocityLauncher(Map.entry(pluginContainer, proxyServer), tempDir).launch());
}
Also used : PluginContainer(com.velocitypowered.api.plugin.PluginContainer) ProxyServer(com.velocitypowered.api.proxy.ProxyServer) Test(org.junit.jupiter.api.Test)

Example 2 with PluginContainer

use of com.velocitypowered.api.plugin.PluginContainer in project LibertyBans by A248.

the class VelocityInitializer method initialize.

BaseFoundation initialize() {
    Platform platform = detectPlatform();
    ProxyServer server = velocityPlugin.server;
    Path folder = velocityPlugin.folder;
    Logger logger = velocityPlugin.logger;
    PluginContainer plugin = server.getPluginManager().fromInstance(velocityPlugin).get();
    Scheduler scheduler = server.getScheduler();
    Executor executor = (cmd) -> scheduler.buildTask(plugin, cmd).schedule();
    Path jarFile = plugin.getDescription().getSource().get();
    LibertyBansLauncher launcher = new LibertyBansLauncher(new Slf4jBootstrapLogger(velocityPlugin.logger), platform, velocityPlugin.folder, executor, jarFile, new VelocityCulpritFinder(server));
    ClassLoader launchLoader = launcher.attemptLaunch().join();
    if (launchLoader == null) {
        logger.warn("Failed to launch LibertyBans");
        return null;
    }
    BaseFoundation base;
    try {
        base = new Instantiator("space.arim.libertybans.env.velocity.VelocityLauncher", launchLoader).invoke(Map.Entry.class, Map.entry(plugin, server), folder);
    } catch (IllegalArgumentException | SecurityException | ReflectiveOperationException ex) {
        logger.warn("Failed to launch LibertyBans", ex);
        return null;
    }
    base.startup();
    return base;
}
Also used : Path(java.nio.file.Path) Platforms(space.arim.libertybans.bootstrap.Platforms) Logger(org.slf4j.Logger) Executor(java.util.concurrent.Executor) LibertyBansLauncher(space.arim.libertybans.bootstrap.LibertyBansLauncher) BaseFoundation(space.arim.libertybans.bootstrap.BaseFoundation) Platform(space.arim.libertybans.bootstrap.Platform) Slf4jBootstrapLogger(space.arim.libertybans.bootstrap.logger.Slf4jBootstrapLogger) Scheduler(com.velocitypowered.api.scheduler.Scheduler) ProxyServer(com.velocitypowered.api.proxy.ProxyServer) Map(java.util.Map) Instantiator(space.arim.libertybans.bootstrap.Instantiator) PluginContainer(com.velocitypowered.api.plugin.PluginContainer) Path(java.nio.file.Path) LibertyBansLauncher(space.arim.libertybans.bootstrap.LibertyBansLauncher) BaseFoundation(space.arim.libertybans.bootstrap.BaseFoundation) PluginContainer(com.velocitypowered.api.plugin.PluginContainer) Platform(space.arim.libertybans.bootstrap.Platform) Scheduler(com.velocitypowered.api.scheduler.Scheduler) Slf4jBootstrapLogger(space.arim.libertybans.bootstrap.logger.Slf4jBootstrapLogger) Instantiator(space.arim.libertybans.bootstrap.Instantiator) Logger(org.slf4j.Logger) Slf4jBootstrapLogger(space.arim.libertybans.bootstrap.logger.Slf4jBootstrapLogger) ProxyServer(com.velocitypowered.api.proxy.ProxyServer) Executor(java.util.concurrent.Executor)

Example 3 with PluginContainer

use of com.velocitypowered.api.plugin.PluginContainer in project HuskChat by WiIIiam278.

the class HuskChatVelocity method onProxyInitialization.

@Subscribe
public void onProxyInitialization(ProxyInitializeEvent event) {
    instance = this;
    // Load config
    reloadSettings();
    // Load messages
    reloadMessages();
    // Setup player data getter
    Optional<PluginContainer> luckPerms = getProxyServer().getPluginManager().getPlugin("luckperms");
    if (luckPerms.isPresent()) {
        playerDataGetter = new LuckPermsDataGetter();
    } else {
        playerDataGetter = new DefaultDataGetter();
    }
    // Register events
    getProxyServer().getEventManager().register(this, new VelocityListener());
    // Register commands
    new VelocityCommand(new HuskChatCommand(this));
    new VelocityCommand(new ChannelCommand(this));
    if (Settings.doMessageCommand) {
        new VelocityCommand(new MsgCommand(this));
        new VelocityCommand(new ReplyCommand(this));
    }
    if (Settings.doBroadcastCommand) {
        new VelocityCommand(new BroadcastCommand(this));
    }
    if (Settings.doSocialSpyCommand) {
        new VelocityCommand(new SocialSpyCommand(this));
    }
    if (Settings.doLocalSpyCommand) {
        new VelocityCommand(new LocalSpyCommand(this));
    }
    // Register shortcut commands
    for (Channel channel : Settings.channels) {
        for (String command : channel.shortcutCommands) {
            new VelocityCommand(new ShortcutCommand(command, channel.id, this));
        }
    }
    // Initialise metrics
    metricsFactory.make(this, METRICS_ID);
    // Plugin startup logic
    getLoggingAdapter().info("Enabled HuskChat version " + getMetaVersion());
}
Also used : PluginContainer(com.velocitypowered.api.plugin.PluginContainer) Channel(net.william278.huskchat.channel.Channel) VelocityCommand(net.william278.huskchat.velocity.command.VelocityCommand) DefaultDataGetter(net.william278.huskchat.getter.DefaultDataGetter) LuckPermsDataGetter(net.william278.huskchat.getter.LuckPermsDataGetter) VelocityListener(net.william278.huskchat.velocity.listener.VelocityListener) Subscribe(com.velocitypowered.api.event.Subscribe)

Example 4 with PluginContainer

use of com.velocitypowered.api.plugin.PluginContainer in project LimboAPI by Elytrium.

the class EventManagerHook method reloadHandlers.

@SuppressWarnings("rawtypes")
public void reloadHandlers() throws IllegalAccessException {
    ListMultimap<Class<?>, ?> handlersMap = (ListMultimap<Class<?>, ?>) handlersMapField.get(this);
    List disabledHandlers = handlersMap.get(GameProfileRequestEvent.class);
    List preEvents = new ArrayList();
    List newHandlers = new ArrayList(disabledHandlers);
    if (this.handlerRegistrations != null) {
        for (int i = 0; i < Array.getLength(this.handlerRegistrations); i++) {
            preEvents.add(Array.get(this.handlerRegistrations, i));
        }
    }
    for (Object handler : disabledHandlers) {
        PluginContainer pluginContainer = (PluginContainer) pluginField.get(handler);
        String id = pluginContainer.getDescription().getId();
        if (Settings.IMP.MAIN.PRE_LIMBO_PROFILE_REQUEST_PLUGINS.contains(id)) {
            this.plugin.getLogger().info("Hooking all GameProfileRequestEvent events from {} ", id);
            preEvents.add(handler);
            newHandlers.remove(handler);
        }
    }
    handlersMap.replaceValues(GameProfileRequestEvent.class, newHandlers);
    this.handlerRegistrations = Array.newInstance(handlerRegistration, preEvents.size());
    for (int i = 0; i < preEvents.size(); i++) {
        Array.set(this.handlerRegistrations, i, preEvents.get(i));
    }
    this.hasHandlerRegistration = preEvents.size() != 0;
}
Also used : PluginContainer(com.velocitypowered.api.plugin.PluginContainer) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) ListMultimap(com.google.common.collect.ListMultimap)

Example 5 with PluginContainer

use of com.velocitypowered.api.plugin.PluginContainer in project Chocolate by GiansCode.

the class ChocolateInfoCommand method perform.

@Override
public void perform(CommandSource commandSource, String[] args) {
    StringBuilder commandBuilder = new StringBuilder();
    for (ChocolateCommand chocolateCommand : this.chocolatePlugin.getCommandRegister().getChocolateCommands()) {
        commandBuilder.append(StringUtils.getInstance().replacePlaceholders(Lang.COMMAND$CHOCOLATE$COMMAND_FORMAT.getString(), "%usage%", chocolateCommand.usage, "%description%", chocolateCommand.description)).append("\n");
    }
    Optional<PluginContainer> optional = chocolatePlugin.getServer().getPluginManager().getPlugin("chocolate");
    if (!optional.isPresent())
        return;
    PluginDescription pluginDescription = optional.get().getDescription();
    sendMessage(commandSource, StringUtils.getInstance().replacePlaceholders(Lang.COMMAND$CHOCOLATE$MSG.getString(), "%authors%", String.join(", ", pluginDescription.getAuthors()), "%commands%", commandBuilder.toString()));
}
Also used : PluginContainer(com.velocitypowered.api.plugin.PluginContainer) ChocolateCommand(io.alerium.chocolate.command.constructor.ChocolateCommand) PluginDescription(com.velocitypowered.api.plugin.PluginDescription)

Aggregations

PluginContainer (com.velocitypowered.api.plugin.PluginContainer)8 ProxyServer (com.velocitypowered.api.proxy.ProxyServer)3 PluginDescription (com.velocitypowered.api.plugin.PluginDescription)2 Path (java.nio.file.Path)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Test (org.junit.jupiter.api.Test)2 ListMultimap (com.google.common.collect.ListMultimap)1 JsonObject (com.google.gson.JsonObject)1 Subscribe (com.velocitypowered.api.event.Subscribe)1 PluginManager (com.velocitypowered.api.plugin.PluginManager)1 Scheduler (com.velocitypowered.api.scheduler.Scheduler)1 PluginInfo (com.viaversion.viaversion.dump.PluginInfo)1 ChocolateCommand (io.alerium.chocolate.command.constructor.ChocolateCommand)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Executor (java.util.concurrent.Executor)1 Channel (net.william278.huskchat.channel.Channel)1 DefaultDataGetter (net.william278.huskchat.getter.DefaultDataGetter)1 LuckPermsDataGetter (net.william278.huskchat.getter.LuckPermsDataGetter)1