use of com.viaversion.viaversion.bukkit.providers.BukkitViaMovementTransmitter 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;
}
}
}
Aggregations