com.velocitypowered.api.event.proxy.ProxyInitializeEvent Java Examples

The following examples show how to use com.velocitypowered.api.event.proxy.ProxyInitializeEvent. 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: VelocityPlugin.java    From ViaVersion with MIT License 6 votes vote down vote up
@Subscribe
public void onProxyInit(ProxyInitializeEvent e) {
    PROXY = proxy;
    VelocityCommandHandler commandHandler = new VelocityCommandHandler();
    PROXY.getCommandManager().register(commandHandler, "viaver", "vvvelocity", "viaversion");
    api = new VelocityViaAPI();
    conf = new VelocityViaConfig(configDir.toFile());
    logger = new LoggerWrapper(loggerslf4j);
    connectionManager = new ViaConnectionManager();
    Via.init(ViaManager.builder()
            .platform(this)
            .commandHandler(commandHandler)
            .loader(new VelocityViaLoader())
            .injector(new VelocityViaInjector()).build());

    if (proxy.getPluginManager().getPlugin("ViaBackwards").isPresent()) {
        MappingDataLoader.enableMappingsCache();
    }
}
 
Example #2
Source File: VelocityBootstrap.java    From AntiVPN with MIT License 5 votes vote down vote up
@Subscribe(order = PostOrder.EARLY)
public void onEnable(ProxyInitializeEvent event) {
    try {
        concreteClass.getMethod("onEnable").invoke(concrete);
    } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException ex) {
        logger.error(ex.getMessage(), ex);
        throw new RuntimeException("Could not invoke onEnable.");
    }

    if (ExternalAPI.getInstance() == null) {
        ExternalAPI.setInstance(proxiedClassLoader);
    }
}
 
Example #3
Source File: VelocityPlugin.java    From ViaRewind with MIT License 5 votes vote down vote up
@Subscribe(order = PostOrder.LATE)
public void onProxyStart(ProxyInitializeEvent e) {
	// Setup Logger
	this.logger = new LoggerWrapper(loggerSlf4j);
	// Init!
	ViaRewindConfigImpl conf = new ViaRewindConfigImpl(configDir.resolve("config.yml").toFile());
	conf.reloadConfig();
	this.init(conf);
}
 
Example #4
Source File: LPVelocityBootstrap.java    From LuckPerms with MIT License 5 votes vote down vote up
@Subscribe(order = PostOrder.FIRST)
public void onEnable(ProxyInitializeEvent e) {
    this.startTime = Instant.now();
    try {
        this.plugin.load();
    } finally {
        this.loadLatch.countDown();
    }

    try {
        this.plugin.enable();
    } finally {
        this.enableLatch.countDown();
    }
}
 
Example #5
Source File: VotifierPlugin.java    From NuVotifier with GNU General Public License v3.0 5 votes vote down vote up
@Subscribe
public void onServerStart(ProxyInitializeEvent event) {
    this.scheduler = new VelocityScheduler(server, this);
    this.loggingAdapter = new SLF4JLogger(logger);

    this.getServer().getCommandManager().register(new NVReloadCmd(this), "pnvreload");
    this.getServer().getCommandManager().register(new TestVoteCmd(this), "ptestvote");

    if (!loadAndBind())
        gracefulExit();
}
 
Example #6
Source File: GeyserVelocityPlugin.java    From Geyser with MIT License 4 votes vote down vote up
@Subscribe
public void onInit(ProxyInitializeEvent event) {
    onEnable();
}
 
Example #7
Source File: Main.java    From TAB with Apache License 2.0 4 votes vote down vote up
@Subscribe
	public void onProxyInitialization(ProxyInitializeEvent event) {
		try {
			Class.forName("org.yaml.snakeyaml.Yaml");
			me.neznamy.tab.shared.ProtocolVersion.SERVER_VERSION = me.neznamy.tab.shared.ProtocolVersion.values()[1];
			Shared.mainClass = this;
			Shared.separatorType = "server";
			Shared.command = new TabCommand();
			server.getCommandManager().register("btab", new Command() {
				public void execute(CommandSource sender, String[] args) {
					if (Shared.disabled) {
						if (args.length == 1 && args[0].toLowerCase().equals("reload")) {
							if (sender.hasPermission("tab.reload")) {
								Shared.unload();
								Shared.load(false);
								if (Shared.disabled) {
									if (sender instanceof Player) {
										sender.sendMessage(TextComponent.of(Placeholders.color(Configs.reloadFailed.replace("%file%", Shared.brokenFile))));
									}
								} else {
									sender.sendMessage(TextComponent.of(Placeholders.color(Configs.reloaded)));
								}
							} else {
								sender.sendMessage(TextComponent.of(Placeholders.color(Configs.no_perm)));
							}
						} else {
							if (sender.hasPermission("tab.admin")) {
								sender.sendMessage(TextComponent.of(Placeholders.color("&m                                                                                ")));
								sender.sendMessage(TextComponent.of(Placeholders.color(" &c&lPlugin is disabled due to a broken configuration file (" + Shared.brokenFile + ")")));
								sender.sendMessage(TextComponent.of(Placeholders.color(" &8>> &3&l/tab reload")));
								sender.sendMessage(TextComponent.of(Placeholders.color("      - &7Reloads plugin and config")));
								sender.sendMessage(TextComponent.of(Placeholders.color("&m                                                                                ")));
							}
						}
					} else {
						Shared.command.execute(sender instanceof Player ? Shared.getPlayer(((Player)sender).getUniqueId()) : null, args);
					}
				}
/*				public List<String> suggest(CommandSource sender, String[] args) {
					List<String> sug = command.complete(sender instanceof Player ? Shared.getPlayer(((Player)sender).getUniqueId()) : null, args);
					if (sug == null) {
						sug = new ArrayList<String>();
						for (Player p : server.getAllPlayers()) {
							sug.add(p.getUsername());
						}
					}
					return sug;
				}*/
			});
			registerPackets();
			plm = new PluginMessenger(this);
			Shared.load(true);
		} catch (ClassNotFoundException e) {
			sendConsoleMessage("&c[TAB] The plugin requires Velocity 1.1.0 and up to work ! Get it at https://ci.velocitypowered.com/job/velocity-1.1.0/");
		}
	}
 
Example #8
Source File: VelocitySparkPlugin.java    From spark with GNU General Public License v3.0 4 votes vote down vote up
@Subscribe(order = PostOrder.FIRST)
public void onEnable(ProxyInitializeEvent e) {
    this.platform = new SparkPlatform(this);
    this.platform.enable();
    this.proxy.getCommandManager().register(this, "sparkv", "sparkvelocity");
}
 
Example #9
Source File: VelocityServer.java    From Velocity with MIT License 4 votes vote down vote up
@EnsuresNonNull({"serverKeyPair", "servers", "pluginManager", "eventManager", "scheduler",
    "console", "cm", "configuration"})
void start() {
  logger.info("Booting up {} {}...", getVersion().getName(), getVersion().getVersion());
  console.setupStreams();

  serverKeyPair = EncryptionUtils.createRsaKeyPair(1024);

  cm.logChannelInformation();

  // Initialize commands first
  commandManager.register(new VelocityCommand(this), "velocity");
  commandManager.register(new ServerCommand(this), "server");
  commandManager.register(new ShutdownCommand(this), "shutdown", "end");
  commandManager.register(new GlistCommand(this), "glist");

  try {
    Path configPath = Paths.get("velocity.toml");
    configuration = VelocityConfiguration.read(configPath);

    // Resave config to add new values
    AnnotatedConfig.saveConfig(configuration.dumpConfig(), configPath);

    if (!configuration.validate()) {
      logger.error("Your configuration is invalid. Velocity will not start up until the errors "
          + "are resolved.");
      LogManager.shutdown();
      System.exit(1);
    }
  } catch (Exception e) {
    logger.error("Unable to read/load/save your velocity.toml. The server will shut down.", e);
    LogManager.shutdown();
    System.exit(1);
  }

  for (Map.Entry<String, String> entry : configuration.getServers().entrySet()) {
    servers.register(new ServerInfo(entry.getKey(), AddressUtil.parseAddress(entry.getValue())));
  }

  ipAttemptLimiter = Ratelimiters.createWithMilliseconds(configuration.getLoginRatelimit());
  httpClient = new NettyHttpClient(this);
  loadPlugins();

  // Go ahead and fire the proxy initialization event. We block since plugins should have a chance
  // to fully initialize before we accept any connections to the server.
  eventManager.fire(new ProxyInitializeEvent()).join();

  // init console permissions after plugins are loaded
  console.setupPermissions();

  final Integer port = this.options.getPort();
  if (port != null) {
    logger.debug("Overriding bind port to {} from command line option", port);
    this.cm.bind(new InetSocketAddress(configuration.getBind().getHostString(), port));
  } else {
    this.cm.bind(configuration.getBind());
  }

  if (configuration.isQueryEnabled()) {
    this.cm.queryBind(configuration.getBind().getHostString(), configuration.getQueryPort());
  }

  Metrics.VelocityMetrics.startMetrics(this, configuration.getMetrics());
}
 
Example #10
Source File: SkinsRestorer.java    From SkinsRestorerX with GNU General Public License v3.0 4 votes vote down vote up
@Subscribe
public void onProxyInitialize(ProxyInitializeEvent e) {
    logger.logAlways("Enabling SkinsRestorer v" + getVersion());
    console = this.proxy.getConsoleCommandSource();

    // Check for updates
    if (Config.UPDATER_ENABLED) {
        this.updateChecker = new UpdateCheckerGitHub(2124, this.getVersion(), this.getLogger(), "SkinsRestorerUpdater/Velocity");
        this.checkUpdate(true);

        if (Config.UPDATER_PERIODIC)
            this.getProxy().getScheduler().buildTask(this, this::checkUpdate).repeat(10, TimeUnit.MINUTES).delay(10, TimeUnit.MINUTES).schedule();
    }

    this.skinStorage = new SkinStorage();

    // Init config files
    Config.load(configPath, getClass().getClassLoader().getResourceAsStream("config.yml"));
    Locale.load(configPath);

    this.mojangAPI = new MojangAPI(this.logger);
    this.mineSkinAPI = new MineSkinAPI(this.logger);

    this.skinStorage.setMojangAPI(mojangAPI);
    // Init storage
    if (!this.initStorage())
        return;

    this.mojangAPI.setSkinStorage(this.skinStorage);
    this.mineSkinAPI.setSkinStorage(this.skinStorage);

    // Init listener
    proxy.getEventManager().register(this, new GameProfileRequest(this));

    // Init commands
    this.initCommands();

    // Init SkinApplier
    this.skinApplier = new SkinApplier(this);

    // Init API
    this.skinsRestorerVelocityAPI = new SkinsRestorerVelocityAPI(this, this.mojangAPI, this.skinStorage);

    logger.logAlways("Enabled SkinsRestorer v" + getVersion());
}
 
Example #11
Source File: PlanVelocity.java    From Plan with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Subscribe
public void onProxyStart(ProxyInitializeEvent event) {
    onEnable();
}
 
Example #12
Source File: VelocityPlugin.java    From ViaVersion with MIT License 4 votes vote down vote up
@Subscribe(order = PostOrder.LAST)
public void onProxyLateInit(ProxyInitializeEvent e) {
    Via.getManager().init();
}
 
Example #13
Source File: VelocityPlugin.java    From ViaBackwards with MIT License 4 votes vote down vote up
@Subscribe(order = PostOrder.LATE)
public void onProxyStart(ProxyInitializeEvent e) {
    // Setup Logger
    this.logger = new LoggerWrapper(loggerSlf4j);
    Via.getManager().addEnableListener(() -> this.init(configPath.resolve("config.yml").toFile()));
}