use of net.md_5.bungee.api.plugin.Listener in project BungeeCord by SpigotMC.
the class BungeeCord method startListeners.
public void startListeners() {
for (final ListenerInfo info : config.getListeners()) {
if (info.isProxyProtocol()) {
getLogger().log(Level.WARNING, "Using PROXY protocol for listener {0}, please ensure this listener is adequately firewalled.", info.getSocketAddress());
if (connectionThrottle != null) {
connectionThrottle = null;
getLogger().log(Level.WARNING, "Since PROXY protocol is in use, internal connection throttle has been disabled.");
}
}
ChannelFutureListener listener = new ChannelFutureListener() {
@Override
public void operationComplete(ChannelFuture future) throws Exception {
if (future.isSuccess()) {
listeners.add(future.channel());
getLogger().log(Level.INFO, "Listening on {0}", info.getSocketAddress());
} else {
getLogger().log(Level.WARNING, "Could not bind to host " + info.getSocketAddress(), future.cause());
}
}
};
new ServerBootstrap().channel(PipelineUtils.getServerChannel(info.getSocketAddress())).option(ChannelOption.SO_REUSEADDR, // TODO: Move this elsewhere!
true).childAttr(PipelineUtils.LISTENER, info).childHandler(PipelineUtils.SERVER_CHILD).group(eventLoops).localAddress(info.getSocketAddress()).bind().addListener(listener);
if (info.isQueryEnabled()) {
Preconditions.checkArgument(info.getSocketAddress() instanceof InetSocketAddress, "Can only create query listener on UDP address");
ChannelFutureListener bindListener = new ChannelFutureListener() {
@Override
public void operationComplete(ChannelFuture future) throws Exception {
if (future.isSuccess()) {
listeners.add(future.channel());
getLogger().log(Level.INFO, "Started query on {0}", future.channel().localAddress());
} else {
getLogger().log(Level.WARNING, "Could not bind to host " + info.getSocketAddress(), future.cause());
}
}
};
new RemoteQuery(this, info).start(PipelineUtils.getDatagramChannel(), new InetSocketAddress(info.getHost().getAddress(), info.getQueryPort()), eventLoops, bindListener);
}
}
}
use of net.md_5.bungee.api.plugin.Listener in project SubServers-2 by ME1312.
the class ExProxy method stopListeners.
/**
* Reset all changes made by startListeners
*
* @see ExProxy#startListeners()
*/
@Override
public void stopListeners() {
try {
Logger.get("SubServers").info("Removing synced data");
servers.clear();
reconnect = false;
ArrayList<SubDataClient> tmp = new ArrayList<SubDataClient>();
tmp.addAll(subdata.values());
for (SubDataClient client : tmp) if (client != null) {
client.close();
Try.all.run(client::waitFor);
}
subdata.clear();
subdata.put(0, null);
if (UPnP.isUPnPAvailable()) {
for (ListenerInfo listener : getConfig().getListeners()) {
if (UPnP.isMappedTCP(listener.getHost().getPort()))
UPnP.closePortTCP(listener.getHost().getPort());
}
}
rPlayerLinkS.clear();
rPlayerLinkP.clear();
rPlayers.clear();
} catch (Exception e) {
e.printStackTrace();
}
super.stopListeners();
}
use of net.md_5.bungee.api.plugin.Listener in project ZEnchantmentCore by zivoric.
the class EnchantmentCore method onEnable.
@Override
public void onEnable() {
PluginManager m = getServer().getPluginManager();
switch(VersionUtils.SERVER_VERSION) {
case 18:
case 17:
case 16:
enchLimit = 37;
break;
case 15:
case 14:
enchLimit = 36;
break;
case 13:
enchLimit = 33;
break;
default:
getLogger().log(Level.WARNING, "Version incompatible. Exiting plugin.");
m.disablePlugin(this);
return;
}
getLogger().info("Running ZEnchantmentCore on environment " + VersionUtils.BUKKIT_TYPE + " 1." + VersionUtils.SERVER_VERSION);
getLogger().info("Currently using listener " + autoEnchListener.getClass().getSimpleName());
coreGenerator = new EnchantmentGenerator();
instance = getPlugin(this.getClass());
CustomEnch.loadEnchants();
reloadableEnable();
ItemEnchantListener itemEnchantListener = new ItemEnchantListener(this, coreGenerator);
m.registerEvents(itemEnchantListener, this);
autoEnchListener.setup();
customEnchListener.register();
if (VersionUtils.SERVER_VERSION >= 15) {
LootGenerateListener lootGenerateListener = new LootGenerateListener(coreGenerator);
m.registerEvents(lootGenerateListener, this);
} else {
LegacyLootGenerateListener legacyLootGenerateListener = new LegacyLootGenerateListener(coreGenerator);
m.registerEvents(legacyLootGenerateListener, this);
}
new UpdateChecker(this, 88310).getVersion(version -> {
if (!this.getDescription().getVersion().equalsIgnoreCase(version.substring(1))) {
String str = PREFIX + "There is an update to version " + ChatColor.DARK_AQUA + version + ChatColor.GRAY + " available for ZEnchantmentCore! (Current version: " + ChatColor.DARK_AQUA + "v" + this.getDescription().getVersion() + ChatColor.GRAY + ")";
Bukkit.getConsoleSender().sendMessage(str);
Bukkit.getConsoleSender().sendMessage(ChatColor.GRAY + "You can download it at " + ChatColor.DARK_AQUA + "https://www.spigotmc.org/resources/zenchantmentcore.88310/");
for (Player p : Bukkit.getOnlinePlayers()) {
if (p.hasPermission("zenchantmentcore.util")) {
p.sendMessage(str);
TextComponent tc = new TextComponent("You can download it ");
tc.setColor(net.md_5.bungee.api.ChatColor.GRAY);
TextComponent clickable = new TextComponent("here");
clickable.setColor(net.md_5.bungee.api.ChatColor.DARK_AQUA);
clickable.setUnderlined(true);
clickable.setClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, "https://www.spigotmc.org/resources/zenchantmentcore.88310/"));
tc.addExtra(clickable);
TextComponent period = new TextComponent(".");
period.setColor(net.md_5.bungee.api.ChatColor.GRAY);
tc.addExtra(period);
p.spigot().sendMessage(tc);
}
}
}
});
}
use of net.md_5.bungee.api.plugin.Listener in project ViaVersion by ViaVersion.
the class BungeeViaLoader method unload.
@Override
public void unload() {
for (Listener listener : listeners) {
ProxyServer.getInstance().getPluginManager().unregisterListener(listener);
}
listeners.clear();
for (ScheduledTask task : tasks) {
task.cancel();
}
tasks.clear();
}
use of net.md_5.bungee.api.plugin.Listener in project Nexus by ProjectEdenGG.
the class SmartInventory method open.
public Inventory open(Player player, int page, Map<String, Object> properties) {
Optional<SmartInventory> oldInv = this.manager.getInventory(player);
oldInv.ifPresent(inv -> {
inv.getListeners().stream().filter(listener -> listener.getType() == InventoryCloseEvent.class).forEach(listener -> ((InventoryListener<InventoryCloseEvent>) listener).accept(new InventoryCloseEvent(player.getOpenInventory())));
this.manager.setInventory(player, null);
});
InventoryContents contents = new InventoryContents.Impl(this, player);
contents.pagination().page(page);
properties.forEach(contents::setProperty);
this.manager.setContents(player, contents);
try {
this.provider.setContents(contents);
this.provider.init();
} catch (Exception ex) {
ex.printStackTrace();
player.closeInventory();
player.sendMessage(ChatColor.RED + "An unknown error occurred while trying to open the menu");
return null;
}
InventoryOpener opener = this.manager.findOpener(type).orElseThrow(() -> new IllegalStateException("No opener found for the inventory type " + type.name()));
Inventory handle = opener.open(this, player);
this.manager.setInventory(player, this);
this.manager.scheduleUpdateTask(player, this);
return handle;
}
Aggregations