mirror of
https://github.com/ViaVersion/ViaVersion.git
synced 2024-10-31 23:59:33 +01:00
Do not unnecessarily register tasks/listeners
This commit is contained in:
parent
704f946cf7
commit
b06b9c69ca
@ -76,10 +76,11 @@ public class BukkitViaLoader implements ViaPlatformLoader {
|
||||
});
|
||||
|
||||
/* 1.9 client to 1.8 server */
|
||||
|
||||
storeListener(new ArmorListener(plugin)).register();
|
||||
storeListener(new DeathListener(plugin)).register();
|
||||
storeListener(new BlockListener(plugin)).register();
|
||||
if (ProtocolRegistry.SERVER_PROTOCOL < ProtocolVersion.v1_9.getId()) {
|
||||
storeListener(new ArmorListener(plugin)).register();
|
||||
storeListener(new DeathListener(plugin)).register();
|
||||
storeListener(new BlockListener(plugin)).register();
|
||||
}
|
||||
|
||||
if (ProtocolRegistry.SERVER_PROTOCOL < ProtocolVersion.v1_14.getId()) {
|
||||
boolean use1_9Fix = plugin.getConf().is1_9HitboxFix() && ProtocolRegistry.SERVER_PROTOCOL < ProtocolVersion.v1_9.getId();
|
||||
@ -106,42 +107,49 @@ public class BukkitViaLoader implements ViaPlatformLoader {
|
||||
}
|
||||
|
||||
/* Providers */
|
||||
Via.getManager().getProviders().use(BulkChunkTranslatorProvider.class, new BukkitViaBulkChunkTranslator());
|
||||
Via.getManager().getProviders().use(MovementTransmitterProvider.class, new BukkitViaMovementTransmitter());
|
||||
if (plugin.getConf().is1_12QuickMoveActionFix()) {
|
||||
Via.getManager().getProviders().use(InventoryQuickMoveProvider.class, new BukkitInventoryQuickMoveProvider());
|
||||
}
|
||||
if (Via.getConfig().getBlockConnectionMethod().equalsIgnoreCase("world")) {
|
||||
Via.getManager().getProviders().use(BlockConnectionProvider.class, new BukkitBlockConnectionProvider());
|
||||
}
|
||||
Via.getManager().getProviders().use(HandItemProvider.class, new HandItemProvider() {
|
||||
@Override
|
||||
public Item getHandItem(final UserConnection info) {
|
||||
if (handItemCache != null) {
|
||||
return handItemCache.getHandItem(info.get(ProtocolInfo.class).getUuid());
|
||||
} else {
|
||||
try {
|
||||
return Bukkit.getScheduler().callSyncMethod(Bukkit.getPluginManager().getPlugin("ViaVersion"), new Callable<Item>() {
|
||||
@Override
|
||||
public Item call() throws Exception {
|
||||
UUID playerUUID = info.get(ProtocolInfo.class).getUuid();
|
||||
Player player = Bukkit.getPlayer(playerUUID);
|
||||
if (player != null) {
|
||||
return HandItemCache.convert(player.getItemInHand());
|
||||
if (ProtocolRegistry.SERVER_PROTOCOL < ProtocolVersion.v1_9.getId()) {
|
||||
Via.getManager().getProviders().use(BulkChunkTranslatorProvider.class, new BukkitViaBulkChunkTranslator());
|
||||
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.get(ProtocolInfo.class).getUuid());
|
||||
} else {
|
||||
try {
|
||||
return Bukkit.getScheduler().callSyncMethod(Bukkit.getPluginManager().getPlugin("ViaVersion"), new Callable<Item>() {
|
||||
@Override
|
||||
public Item call() throws Exception {
|
||||
UUID playerUUID = info.get(ProtocolInfo.class).getUuid();
|
||||
Player player = Bukkit.getPlayer(playerUUID);
|
||||
if (player != null) {
|
||||
return HandItemCache.convert(player.getItemInHand());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
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;
|
||||
}).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 (ProtocolRegistry.SERVER_PROTOCOL < ProtocolVersion.v1_12.getId()) {
|
||||
if (plugin.getConf().is1_12QuickMoveActionFix()) {
|
||||
Via.getManager().getProviders().use(InventoryQuickMoveProvider.class, new BukkitInventoryQuickMoveProvider());
|
||||
}
|
||||
}
|
||||
if (ProtocolRegistry.SERVER_PROTOCOL < ProtocolVersion.v1_13.getId()) {
|
||||
if (Via.getConfig().getBlockConnectionMethod().equalsIgnoreCase("world")) {
|
||||
Via.getManager().getProviders().use(BlockConnectionProvider.class, new BukkitBlockConnectionProvider());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -4,6 +4,7 @@ authors: [_MylesC, creeper123123321, Gerrygames, KennyTV, Matsv]
|
||||
version: ${project.version}
|
||||
description: ${project.description}
|
||||
load: postworld
|
||||
api-version: 1.13
|
||||
loadbefore: [ProtocolLib, ProxyPipe, SpigotLib, SkinRestorer]
|
||||
softdepend: [ProtocolSupport, PacketListenerApi]
|
||||
commands:
|
||||
|
@ -6,6 +6,8 @@ import net.md_5.bungee.api.scheduler.ScheduledTask;
|
||||
import us.myles.ViaVersion.BungeePlugin;
|
||||
import us.myles.ViaVersion.api.Via;
|
||||
import us.myles.ViaVersion.api.platform.ViaPlatformLoader;
|
||||
import us.myles.ViaVersion.api.protocol.ProtocolRegistry;
|
||||
import us.myles.ViaVersion.api.protocol.ProtocolVersion;
|
||||
import us.myles.ViaVersion.bungee.handlers.BungeeServerHandler;
|
||||
import us.myles.ViaVersion.bungee.listeners.ElytraPatch;
|
||||
import us.myles.ViaVersion.bungee.listeners.UpdateListener;
|
||||
@ -22,10 +24,10 @@ import java.util.Set;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class BungeeViaLoader implements ViaPlatformLoader {
|
||||
private BungeePlugin plugin;
|
||||
private final BungeePlugin plugin;
|
||||
|
||||
private Set<Listener> listeners = new HashSet<>();
|
||||
private Set<ScheduledTask> tasks = new HashSet<>();
|
||||
private final Set<Listener> listeners = new HashSet<>();
|
||||
private final Set<ScheduledTask> tasks = new HashSet<>();
|
||||
|
||||
public BungeeViaLoader(BungeePlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
@ -42,14 +44,20 @@ public class BungeeViaLoader implements ViaPlatformLoader {
|
||||
registerListener(plugin);
|
||||
registerListener(new UpdateListener());
|
||||
registerListener(new BungeeServerHandler());
|
||||
registerListener(new ElytraPatch());
|
||||
|
||||
if (ProtocolRegistry.SERVER_PROTOCOL < ProtocolVersion.v1_9.getId()) {
|
||||
registerListener(new ElytraPatch());
|
||||
}
|
||||
|
||||
// Providers
|
||||
Via.getManager().getProviders().use(MovementTransmitterProvider.class, new BungeeMovementTransmitter());
|
||||
Via.getManager().getProviders().use(VersionProvider.class, new BungeeVersionProvider());
|
||||
Via.getManager().getProviders().use(EntityIdProvider.class, new BungeeEntityIdProvider());
|
||||
Via.getManager().getProviders().use(BossBarProvider.class, new BungeeBossBarProvider());
|
||||
Via.getManager().getProviders().use(MainHandProvider.class, new BungeeMainHandProvider());
|
||||
|
||||
if (ProtocolRegistry.SERVER_PROTOCOL < ProtocolVersion.v1_9.getId()) {
|
||||
Via.getManager().getProviders().use(MovementTransmitterProvider.class, new BungeeMovementTransmitter());
|
||||
Via.getManager().getProviders().use(BossBarProvider.class, new BungeeBossBarProvider());
|
||||
Via.getManager().getProviders().use(MainHandProvider.class, new BungeeMainHandProvider());
|
||||
}
|
||||
|
||||
if (plugin.getConf().getBungeePingInterval() > 0) {
|
||||
tasks.add(plugin.getProxy().getScheduler().schedule(
|
||||
|
@ -104,7 +104,7 @@ public class ProtocolRegistry {
|
||||
|
||||
for (Integer version : supported) {
|
||||
if (!registryMap.containsKey(version)) {
|
||||
registryMap.put(version, new HashMap<Integer, Protocol>());
|
||||
registryMap.put(version, new HashMap<>());
|
||||
}
|
||||
|
||||
registryMap.get(version).put(output, protocol);
|
||||
|
@ -7,6 +7,8 @@ import us.myles.ViaVersion.api.data.UserConnection;
|
||||
import us.myles.ViaVersion.api.minecraft.item.Item;
|
||||
import us.myles.ViaVersion.api.platform.TaskId;
|
||||
import us.myles.ViaVersion.api.platform.ViaPlatformLoader;
|
||||
import us.myles.ViaVersion.api.protocol.ProtocolRegistry;
|
||||
import us.myles.ViaVersion.api.protocol.ProtocolVersion;
|
||||
import us.myles.ViaVersion.protocols.base.ProtocolInfo;
|
||||
import us.myles.ViaVersion.protocols.protocol1_9to1_8.providers.BulkChunkTranslatorProvider;
|
||||
import us.myles.ViaVersion.protocols.protocol1_9to1_8.providers.HandItemProvider;
|
||||
@ -26,10 +28,10 @@ import java.util.Set;
|
||||
|
||||
public class SpongeViaLoader implements ViaPlatformLoader {
|
||||
|
||||
private SpongePlugin plugin;
|
||||
private final SpongePlugin plugin;
|
||||
|
||||
private Set<Object> listeners = new HashSet<>();
|
||||
private Set<TaskId> tasks = new HashSet<>();
|
||||
private final Set<Object> listeners = new HashSet<>();
|
||||
private final Set<TaskId> tasks = new HashSet<>();
|
||||
|
||||
public SpongeViaLoader(SpongePlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
@ -50,34 +52,40 @@ public class SpongeViaLoader implements ViaPlatformLoader {
|
||||
registerListener(new UpdateListener());
|
||||
/* Base Protocol */
|
||||
registerListener(new ClientLeaveListener());
|
||||
/* 1.9 client to 1.8 server */
|
||||
try {
|
||||
Class.forName("org.spongepowered.api.event.entity.DisplaceEntityEvent");
|
||||
storeListener(new Sponge4ArmorListener()).register();
|
||||
} catch (ClassNotFoundException e) {
|
||||
storeListener(new Sponge5ArmorListener(plugin)).register();
|
||||
}
|
||||
storeListener(new DeathListener(plugin)).register();
|
||||
storeListener(new BlockListener(plugin)).register();
|
||||
|
||||
if (plugin.getConf().isItemCache()) {
|
||||
tasks.add(Via.getPlatform().runRepeatingSync(new HandItemCache(), 2L)); // Updates players items :)
|
||||
HandItemCache.CACHE = true;
|
||||
/* 1.9 client to 1.8 server */
|
||||
if (ProtocolRegistry.SERVER_PROTOCOL < ProtocolVersion.v1_9.getId()) {
|
||||
try {
|
||||
Class.forName("org.spongepowered.api.event.entity.DisplaceEntityEvent");
|
||||
storeListener(new Sponge4ArmorListener()).register();
|
||||
} catch (ClassNotFoundException e) {
|
||||
storeListener(new Sponge5ArmorListener(plugin)).register();
|
||||
}
|
||||
storeListener(new DeathListener(plugin)).register();
|
||||
storeListener(new BlockListener(plugin)).register();
|
||||
|
||||
if (plugin.getConf().isItemCache()) {
|
||||
tasks.add(Via.getPlatform().runRepeatingSync(new HandItemCache(), 2L)); // Updates players items :)
|
||||
HandItemCache.CACHE = true;
|
||||
}
|
||||
}
|
||||
|
||||
/* Providers */
|
||||
Via.getManager().getProviders().use(BulkChunkTranslatorProvider.class, new SpongeViaBulkChunkTranslator());
|
||||
Via.getManager().getProviders().use(MovementTransmitterProvider.class, new SpongeViaMovementTransmitter());
|
||||
Via.getManager().getProviders().use(HandItemProvider.class, new HandItemProvider() {
|
||||
@Override
|
||||
public Item getHandItem(final UserConnection info) {
|
||||
if (HandItemCache.CACHE) {
|
||||
return HandItemCache.getHandItem(info.get(ProtocolInfo.class).getUuid());
|
||||
} else {
|
||||
return super.getHandItem(info); // TODO: On API Docs write about this
|
||||
if (ProtocolRegistry.SERVER_PROTOCOL < ProtocolVersion.v1_9.getId()) {
|
||||
Via.getManager().getProviders().use(BulkChunkTranslatorProvider.class, new SpongeViaBulkChunkTranslator());
|
||||
Via.getManager().getProviders().use(MovementTransmitterProvider.class, new SpongeViaMovementTransmitter());
|
||||
|
||||
Via.getManager().getProviders().use(HandItemProvider.class, new HandItemProvider() {
|
||||
@Override
|
||||
public Item getHandItem(final UserConnection info) {
|
||||
if (HandItemCache.CACHE) {
|
||||
return HandItemCache.getHandItem(info.get(ProtocolInfo.class).getUuid());
|
||||
} else {
|
||||
return super.getHandItem(info);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public void unload() {
|
||||
|
@ -4,6 +4,8 @@ import com.velocitypowered.api.plugin.PluginContainer;
|
||||
import us.myles.ViaVersion.VelocityPlugin;
|
||||
import us.myles.ViaVersion.api.Via;
|
||||
import us.myles.ViaVersion.api.platform.ViaPlatformLoader;
|
||||
import us.myles.ViaVersion.api.protocol.ProtocolRegistry;
|
||||
import us.myles.ViaVersion.api.protocol.ProtocolVersion;
|
||||
import us.myles.ViaVersion.protocols.base.VersionProvider;
|
||||
import us.myles.ViaVersion.protocols.protocol1_9to1_8.providers.BossBarProvider;
|
||||
import us.myles.ViaVersion.protocols.protocol1_9to1_8.providers.MovementTransmitterProvider;
|
||||
@ -21,15 +23,18 @@ public class VelocityViaLoader implements ViaPlatformLoader {
|
||||
Object plugin = VelocityPlugin.PROXY.getPluginManager()
|
||||
.getPlugin("viaversion").flatMap(PluginContainer::getInstance).get();
|
||||
|
||||
Via.getManager().getProviders().use(MovementTransmitterProvider.class, new VelocityMovementTransmitter());
|
||||
Via.getManager().getProviders().use(BossBarProvider.class, new VelocityBossBarProvider());
|
||||
if (ProtocolRegistry.SERVER_PROTOCOL < ProtocolVersion.v1_9.getId()) {
|
||||
Via.getManager().getProviders().use(MovementTransmitterProvider.class, new VelocityMovementTransmitter());
|
||||
Via.getManager().getProviders().use(BossBarProvider.class, new VelocityBossBarProvider());
|
||||
VelocityPlugin.PROXY.getEventManager().register(plugin, new ElytraPatch());
|
||||
}
|
||||
|
||||
Via.getManager().getProviders().use(VersionProvider.class, new VelocityVersionProvider());
|
||||
// We probably don't need a EntityIdProvider because velocity sends a Join packet on server change
|
||||
// We don't need main hand patch because Join Game packet makes client send hand data again
|
||||
|
||||
VelocityPlugin.PROXY.getEventManager().register(plugin, new UpdateListener());
|
||||
VelocityPlugin.PROXY.getEventManager().register(plugin, new VelocityServerHandler());
|
||||
VelocityPlugin.PROXY.getEventManager().register(plugin, new ElytraPatch());
|
||||
|
||||
int pingInterval = ((VelocityViaConfig) Via.getPlatform().getConf()).getVelocityPingInterval();
|
||||
if (pingInterval > 0) {
|
||||
|
Loading…
Reference in New Issue
Block a user