Search in sources :

Example 6 with Listener

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);
        }
    }
}
Also used : ChannelFuture(io.netty.channel.ChannelFuture) ListenerInfo(net.md_5.bungee.api.config.ListenerInfo) InetSocketAddress(java.net.InetSocketAddress) RemoteQuery(net.md_5.bungee.query.RemoteQuery) ChannelFutureListener(io.netty.channel.ChannelFutureListener) ServerBootstrap(io.netty.bootstrap.ServerBootstrap)

Example 7 with Listener

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();
}
Also used : SubDataClient(net.ME1312.SubData.Client.SubDataClient) ListenerInfo(net.md_5.bungee.api.config.ListenerInfo)

Example 8 with Listener

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);
                }
            }
        }
    });
}
Also used : PluginManager(org.bukkit.plugin.PluginManager) TextComponent(net.md_5.bungee.api.chat.TextComponent) Player(org.bukkit.entity.Player) ClickEvent(net.md_5.bungee.api.chat.ClickEvent) UpdateChecker(io.zivoric.enchantmentcore.utils.UpdateChecker)

Example 9 with Listener

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();
}
Also used : Listener(net.md_5.bungee.api.plugin.Listener) UpdateListener(com.viaversion.viaversion.bungee.listeners.UpdateListener) ScheduledTask(net.md_5.bungee.api.scheduler.ScheduledTask)

Example 10 with Listener

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;
}
Also used : InventoryOpener(gg.projecteden.nexus.features.menus.api.opener.InventoryOpener) Setter(lombok.Setter) Getter(lombok.Getter) InventoryType(org.bukkit.event.inventory.InventoryType) JsonBuilder(gg.projecteden.nexus.utils.JsonBuilder) Event(org.bukkit.event.Event) InventoryContents(gg.projecteden.nexus.features.menus.api.content.InventoryContents) Player(org.bukkit.entity.Player) InventoryCloseEvent(org.bukkit.event.inventory.InventoryCloseEvent) ComponentLike(net.kyori.adventure.text.ComponentLike) Inventory(org.bukkit.inventory.Inventory) ArrayList(java.util.ArrayList) List(java.util.List) SlotPos(gg.projecteden.nexus.features.menus.api.content.SlotPos) Component(net.kyori.adventure.text.Component) Map(java.util.Map) InventoryProvider(gg.projecteden.nexus.features.menus.api.content.InventoryProvider) Optional(java.util.Optional) Preconditions(com.google.common.base.Preconditions) Collections(java.util.Collections) ChatColor(net.md_5.bungee.api.ChatColor) InventoryOpener(gg.projecteden.nexus.features.menus.api.opener.InventoryOpener) InventoryCloseEvent(org.bukkit.event.inventory.InventoryCloseEvent) InventoryContents(gg.projecteden.nexus.features.menus.api.content.InventoryContents) Inventory(org.bukkit.inventory.Inventory)

Aggregations

ListenerInfo (net.md_5.bungee.api.config.ListenerInfo)9 Player (org.bukkit.entity.Player)7 Listener (net.md_5.bungee.api.plugin.Listener)6 TextComponent (net.md_5.bungee.api.chat.TextComponent)5 EventHandler (net.md_5.bungee.event.EventHandler)5 ChannelFuture (io.netty.channel.ChannelFuture)4 BInventory (com.bencodez.advancedcore.api.inventory.BInventory)3 ClickEvent (com.bencodez.advancedcore.api.inventory.BInventory.ClickEvent)3 BInventoryButton (com.bencodez.advancedcore.api.inventory.BInventoryButton)3 AdvancedCoreUser (com.bencodez.advancedcore.api.user.AdvancedCoreUser)3 BookManager (com.bencodez.advancedcore.api.valuerequest.book.BookManager)3 BookSign (com.bencodez.advancedcore.api.valuerequest.book.BookSign)3 ChannelFutureListener (io.netty.channel.ChannelFutureListener)3 ProxiedPlayer (net.md_5.bungee.api.connection.ProxiedPlayer)3 BungeePlayer (codecrafter47.bungeetablistplus.player.BungeePlayer)2 ValueRequest (com.bencodez.advancedcore.api.valuerequest.ValueRequest)2 PromptManager (com.bencodez.advancedcore.api.valuerequest.prompt.PromptManager)2 PromptReturnString (com.bencodez.advancedcore.api.valuerequest.prompt.PromptReturnString)2 TabView (de.codecrafter47.taboverlay.TabView)2 EventListener (de.codecrafter47.taboverlay.config.platform.EventListener)2