Search in sources :

Example 1 with HandItemProvider

use of com.viaversion.viaversion.protocols.protocol1_9to1_8.providers.HandItemProvider in project ViaVersion by ViaVersion.

the class BukkitViaLoader method load.

@Override
public void load() {
    // Update Listener
    registerListener(new UpdateListener());
    /* Base Protocol */
    final ViaVersionPlugin plugin = (ViaVersionPlugin) Bukkit.getPluginManager().getPlugin("ViaVersion");
    // Add ProtocolSupport ConnectListener if necessary.
    ClassGenerator.registerPSConnectListener(plugin);
    int serverProtocolVersion = Via.getAPI().getServerVersion().lowestSupportedVersion();
    /* 1.9 client to 1.8 server */
    if (serverProtocolVersion < ProtocolVersion.v1_9.getVersion()) {
        storeListener(new ArmorListener(plugin)).register();
        storeListener(new DeathListener(plugin)).register();
        storeListener(new BlockListener(plugin)).register();
        if (plugin.getConf().isItemCache()) {
            handItemCache = new HandItemCache();
            // Updates player's items :)
            tasks.add(handItemCache.runTaskTimerAsynchronously(plugin, 1L, 1L));
        }
    }
    if (serverProtocolVersion < ProtocolVersion.v1_14.getVersion()) {
        boolean use1_9Fix = plugin.getConf().is1_9HitboxFix() && serverProtocolVersion < ProtocolVersion.v1_9.getVersion();
        if (use1_9Fix || plugin.getConf().is1_14HitboxFix()) {
            try {
                storeListener(new PlayerSneakListener(plugin, use1_9Fix, plugin.getConf().is1_14HitboxFix())).register();
            } catch (ReflectiveOperationException e) {
                Via.getPlatform().getLogger().warning("Could not load hitbox fix - please report this on our GitHub");
                e.printStackTrace();
            }
        }
    }
    if (serverProtocolVersion < ProtocolVersion.v1_15.getVersion()) {
        try {
            Class.forName("org.bukkit.event.entity.EntityToggleGlideEvent");
            storeListener(new EntityToggleGlideListener(plugin)).register();
        } catch (ClassNotFoundException ignored) {
        }
    }
    if (serverProtocolVersion < ProtocolVersion.v1_12.getVersion() && !Boolean.getBoolean("com.viaversion.ignorePaperBlockPlacePatch")) {
        boolean paper = true;
        try {
            // Paper 1.8 ?
            Class.forName("org.github.paperspigot.PaperSpigotConfig");
        } catch (ClassNotFoundException ignored) {
            try {
                // Paper 1.9+ ?
                Class.forName("com.destroystokyo.paper.PaperConfig");
            } catch (ClassNotFoundException alsoIgnored) {
                // Definitely not Paper
                paper = false;
            }
        }
        if (paper) {
            storeListener(new PaperPatch(plugin)).register();
        }
    }
    /* Providers */
    if (serverProtocolVersion < ProtocolVersion.v1_9.getVersion()) {
        Via.getManager().getProviders().use(MovementTransmitterProvider.class, new BukkitViaMovementTransmitter());
        Via.getManager().getProviders().use(HandItemProvider.class, new HandItemProvider() {

            @Override
            public Item getHandItem(final UserConnection info) {
                if (handItemCache != null) {
                    return handItemCache.getHandItem(info.getProtocolInfo().getUuid());
                }
                try {
                    return Bukkit.getScheduler().callSyncMethod(Bukkit.getPluginManager().getPlugin("ViaVersion"), () -> {
                        UUID playerUUID = info.getProtocolInfo().getUuid();
                        Player player = Bukkit.getPlayer(playerUUID);
                        if (player != null) {
                            return HandItemCache.convert(player.getItemInHand());
                        }
                        return null;
                    }).get(10, TimeUnit.SECONDS);
                } catch (Exception e) {
                    Via.getPlatform().getLogger().severe("Error fetching hand item: " + e.getClass().getName());
                    if (Via.getManager().isDebug())
                        e.printStackTrace();
                    return null;
                }
            }
        });
    }
    if (serverProtocolVersion < ProtocolVersion.v1_12.getVersion()) {
        if (plugin.getConf().is1_12QuickMoveActionFix()) {
            Via.getManager().getProviders().use(InventoryQuickMoveProvider.class, new BukkitInventoryQuickMoveProvider());
        }
    }
    if (serverProtocolVersion < ProtocolVersion.v1_13.getVersion()) {
        if (Via.getConfig().getBlockConnectionMethod().equalsIgnoreCase("world")) {
            BukkitBlockConnectionProvider blockConnectionProvider = new BukkitBlockConnectionProvider();
            Via.getManager().getProviders().use(BlockConnectionProvider.class, blockConnectionProvider);
            ConnectionData.blockConnectionProvider = blockConnectionProvider;
        }
    }
}
Also used : Player(org.bukkit.entity.Player) PaperPatch(com.viaversion.viaversion.bukkit.listeners.protocol1_9to1_8.PaperPatch) BukkitViaMovementTransmitter(com.viaversion.viaversion.bukkit.providers.BukkitViaMovementTransmitter) UserConnection(com.viaversion.viaversion.api.connection.UserConnection) BukkitBlockConnectionProvider(com.viaversion.viaversion.bukkit.providers.BukkitBlockConnectionProvider) Item(com.viaversion.viaversion.api.minecraft.item.Item) EntityToggleGlideListener(com.viaversion.viaversion.bukkit.listeners.protocol1_15to1_14_4.EntityToggleGlideListener) BukkitInventoryQuickMoveProvider(com.viaversion.viaversion.bukkit.providers.BukkitInventoryQuickMoveProvider) ArmorListener(com.viaversion.viaversion.bukkit.listeners.protocol1_9to1_8.ArmorListener) BlockListener(com.viaversion.viaversion.bukkit.listeners.protocol1_9to1_8.BlockListener) PlayerSneakListener(com.viaversion.viaversion.bukkit.listeners.multiversion.PlayerSneakListener) HandItemProvider(com.viaversion.viaversion.protocols.protocol1_9to1_8.providers.HandItemProvider) ViaVersionPlugin(com.viaversion.viaversion.ViaVersionPlugin) UpdateListener(com.viaversion.viaversion.bukkit.listeners.UpdateListener) UUID(java.util.UUID) HandItemCache(com.viaversion.viaversion.bukkit.listeners.protocol1_9to1_8.HandItemCache) DeathListener(com.viaversion.viaversion.bukkit.listeners.protocol1_9to1_8.DeathListener)

Aggregations

ViaVersionPlugin (com.viaversion.viaversion.ViaVersionPlugin)1 UserConnection (com.viaversion.viaversion.api.connection.UserConnection)1 Item (com.viaversion.viaversion.api.minecraft.item.Item)1 UpdateListener (com.viaversion.viaversion.bukkit.listeners.UpdateListener)1 PlayerSneakListener (com.viaversion.viaversion.bukkit.listeners.multiversion.PlayerSneakListener)1 EntityToggleGlideListener (com.viaversion.viaversion.bukkit.listeners.protocol1_15to1_14_4.EntityToggleGlideListener)1 ArmorListener (com.viaversion.viaversion.bukkit.listeners.protocol1_9to1_8.ArmorListener)1 BlockListener (com.viaversion.viaversion.bukkit.listeners.protocol1_9to1_8.BlockListener)1 DeathListener (com.viaversion.viaversion.bukkit.listeners.protocol1_9to1_8.DeathListener)1 HandItemCache (com.viaversion.viaversion.bukkit.listeners.protocol1_9to1_8.HandItemCache)1 PaperPatch (com.viaversion.viaversion.bukkit.listeners.protocol1_9to1_8.PaperPatch)1 BukkitBlockConnectionProvider (com.viaversion.viaversion.bukkit.providers.BukkitBlockConnectionProvider)1 BukkitInventoryQuickMoveProvider (com.viaversion.viaversion.bukkit.providers.BukkitInventoryQuickMoveProvider)1 BukkitViaMovementTransmitter (com.viaversion.viaversion.bukkit.providers.BukkitViaMovementTransmitter)1 HandItemProvider (com.viaversion.viaversion.protocols.protocol1_9to1_8.providers.HandItemProvider)1 UUID (java.util.UUID)1 Player (org.bukkit.entity.Player)1