3
0
Mirror von https://github.com/ViaVersion/ViaVersion.git synchronisiert 2024-12-27 08:30:09 +01:00

Merge pull request #1638 from KennyTV/abstraction

Do not unnecessarily register tasks/listeners, set api-version
Dieser Commit ist enthalten in:
Myles 2020-01-28 11:38:32 +00:00 committet von GitHub
Commit 6eeecb271b
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 4AEE18F83AFDEB23
12 geänderte Dateien mit 114 neuen und 79 gelöschten Zeilen

Datei anzeigen

@ -33,7 +33,6 @@ import java.util.HashSet;
import java.util.Locale; import java.util.Locale;
import java.util.Set; import java.util.Set;
import java.util.UUID; import java.util.UUID;
import java.util.concurrent.Callable;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
public class BukkitViaLoader implements ViaPlatformLoader { public class BukkitViaLoader implements ViaPlatformLoader {
@ -76,10 +75,16 @@ public class BukkitViaLoader implements ViaPlatformLoader {
}); });
/* 1.9 client to 1.8 server */ /* 1.9 client to 1.8 server */
if (ProtocolRegistry.SERVER_PROTOCOL < ProtocolVersion.v1_9.getId()) {
storeListener(new ArmorListener(plugin)).register();
storeListener(new DeathListener(plugin)).register();
storeListener(new BlockListener(plugin)).register();
storeListener(new ArmorListener(plugin)).register(); if (plugin.getConf().isItemCache()) {
storeListener(new DeathListener(plugin)).register(); handItemCache = new HandItemCache();
storeListener(new BlockListener(plugin)).register(); tasks.add(handItemCache.runTaskTimerAsynchronously(plugin, 2L, 2L)); // Updates player's items :)
}
}
if (ProtocolRegistry.SERVER_PROTOCOL < ProtocolVersion.v1_14.getId()) { if (ProtocolRegistry.SERVER_PROTOCOL < ProtocolVersion.v1_14.getId()) {
boolean use1_9Fix = plugin.getConf().is1_9HitboxFix() && ProtocolRegistry.SERVER_PROTOCOL < ProtocolVersion.v1_9.getId(); boolean use1_9Fix = plugin.getConf().is1_9HitboxFix() && ProtocolRegistry.SERVER_PROTOCOL < ProtocolVersion.v1_9.getId();
@ -100,37 +105,26 @@ public class BukkitViaLoader implements ViaPlatformLoader {
plugin.getLogger().info("Enabling Paper/TacoSpigot/Torch patch: Fixes block placement."); plugin.getLogger().info("Enabling Paper/TacoSpigot/Torch patch: Fixes block placement.");
storeListener(new PaperPatch(plugin)).register(); storeListener(new PaperPatch(plugin)).register();
} }
if (plugin.getConf().isItemCache()) {
handItemCache = new HandItemCache();
tasks.add(handItemCache.runTaskTimerAsynchronously(plugin, 2L, 2L)); // Updates player's items :)
}
/* Providers */ /* Providers */
Via.getManager().getProviders().use(BulkChunkTranslatorProvider.class, new BukkitViaBulkChunkTranslator()); if (ProtocolRegistry.SERVER_PROTOCOL < ProtocolVersion.v1_9.getId()) {
Via.getManager().getProviders().use(MovementTransmitterProvider.class, new BukkitViaMovementTransmitter()); Via.getManager().getProviders().use(BulkChunkTranslatorProvider.class, new BukkitViaBulkChunkTranslator());
if (plugin.getConf().is1_12QuickMoveActionFix()) { Via.getManager().getProviders().use(MovementTransmitterProvider.class, new BukkitViaMovementTransmitter());
Via.getManager().getProviders().use(InventoryQuickMoveProvider.class, new BukkitInventoryQuickMoveProvider());
} Via.getManager().getProviders().use(HandItemProvider.class, new HandItemProvider() {
if (Via.getConfig().getBlockConnectionMethod().equalsIgnoreCase("world")) { @Override
Via.getManager().getProviders().use(BlockConnectionProvider.class, new BukkitBlockConnectionProvider()); public Item getHandItem(final UserConnection info) {
} if (handItemCache != null) {
Via.getManager().getProviders().use(HandItemProvider.class, new HandItemProvider() { return handItemCache.getHandItem(info.get(ProtocolInfo.class).getUuid());
@Override }
public Item getHandItem(final UserConnection info) {
if (handItemCache != null) {
return handItemCache.getHandItem(info.get(ProtocolInfo.class).getUuid());
} else {
try { try {
return Bukkit.getScheduler().callSyncMethod(Bukkit.getPluginManager().getPlugin("ViaVersion"), new Callable<Item>() { return Bukkit.getScheduler().callSyncMethod(Bukkit.getPluginManager().getPlugin("ViaVersion"), () -> {
@Override UUID playerUUID = info.get(ProtocolInfo.class).getUuid();
public Item call() throws Exception { Player player = Bukkit.getPlayer(playerUUID);
UUID playerUUID = info.get(ProtocolInfo.class).getUuid(); if (player != null) {
Player player = Bukkit.getPlayer(playerUUID); return HandItemCache.convert(player.getItemInHand());
if (player != null) {
return HandItemCache.convert(player.getItemInHand());
}
return null;
} }
return null;
}).get(10, TimeUnit.SECONDS); }).get(10, TimeUnit.SECONDS);
} catch (Exception e) { } catch (Exception e) {
Via.getPlatform().getLogger().severe("Error fetching hand item: " + e.getClass().getName()); Via.getPlatform().getLogger().severe("Error fetching hand item: " + e.getClass().getName());
@ -139,9 +133,19 @@ public class BukkitViaLoader implements ViaPlatformLoader {
return null; 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 @Override

Datei anzeigen

@ -4,6 +4,7 @@ authors: [_MylesC, creeper123123321, Gerrygames, KennyTV, Matsv]
version: ${project.version} version: ${project.version}
description: ${project.description} description: ${project.description}
load: postworld load: postworld
api-version: 1.13
loadbefore: [ProtocolLib, ProxyPipe, SpigotLib, SkinRestorer] loadbefore: [ProtocolLib, ProxyPipe, SpigotLib, SkinRestorer]
softdepend: [ProtocolSupport, PacketListenerApi] softdepend: [ProtocolSupport, PacketListenerApi]
commands: commands:

Datei anzeigen

@ -6,6 +6,8 @@ import net.md_5.bungee.api.scheduler.ScheduledTask;
import us.myles.ViaVersion.BungeePlugin; import us.myles.ViaVersion.BungeePlugin;
import us.myles.ViaVersion.api.Via; import us.myles.ViaVersion.api.Via;
import us.myles.ViaVersion.api.platform.ViaPlatformLoader; 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.handlers.BungeeServerHandler;
import us.myles.ViaVersion.bungee.listeners.ElytraPatch; import us.myles.ViaVersion.bungee.listeners.ElytraPatch;
import us.myles.ViaVersion.bungee.listeners.UpdateListener; import us.myles.ViaVersion.bungee.listeners.UpdateListener;
@ -22,10 +24,10 @@ import java.util.Set;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
public class BungeeViaLoader implements ViaPlatformLoader { public class BungeeViaLoader implements ViaPlatformLoader {
private BungeePlugin plugin; private final BungeePlugin plugin;
private Set<Listener> listeners = new HashSet<>(); private final Set<Listener> listeners = new HashSet<>();
private Set<ScheduledTask> tasks = new HashSet<>(); private final Set<ScheduledTask> tasks = new HashSet<>();
public BungeeViaLoader(BungeePlugin plugin) { public BungeeViaLoader(BungeePlugin plugin) {
this.plugin = plugin; this.plugin = plugin;
@ -42,14 +44,20 @@ public class BungeeViaLoader implements ViaPlatformLoader {
registerListener(plugin); registerListener(plugin);
registerListener(new UpdateListener()); registerListener(new UpdateListener());
registerListener(new BungeeServerHandler()); registerListener(new BungeeServerHandler());
registerListener(new ElytraPatch());
if (ProtocolRegistry.SERVER_PROTOCOL < ProtocolVersion.v1_9.getId()) {
registerListener(new ElytraPatch());
}
// Providers // Providers
Via.getManager().getProviders().use(MovementTransmitterProvider.class, new BungeeMovementTransmitter());
Via.getManager().getProviders().use(VersionProvider.class, new BungeeVersionProvider()); Via.getManager().getProviders().use(VersionProvider.class, new BungeeVersionProvider());
Via.getManager().getProviders().use(EntityIdProvider.class, new BungeeEntityIdProvider()); 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) { if (plugin.getConf().getBungeePingInterval() > 0) {
tasks.add(plugin.getProxy().getScheduler().schedule( tasks.add(plugin.getProxy().getScheduler().schedule(

Datei anzeigen

@ -3,6 +3,7 @@ package us.myles.ViaVersion;
import lombok.Builder; import lombok.Builder;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
import us.myles.ViaVersion.api.Via;
import us.myles.ViaVersion.api.data.UserConnection; import us.myles.ViaVersion.api.data.UserConnection;
import us.myles.ViaVersion.api.platform.ViaInjector; import us.myles.ViaVersion.api.platform.ViaInjector;
import us.myles.ViaVersion.api.platform.ViaPlatform; import us.myles.ViaVersion.api.platform.ViaPlatform;
@ -12,6 +13,8 @@ import us.myles.ViaVersion.api.protocol.ProtocolRegistry;
import us.myles.ViaVersion.api.protocol.ProtocolVersion; import us.myles.ViaVersion.api.protocol.ProtocolVersion;
import us.myles.ViaVersion.commands.ViaCommandHandler; import us.myles.ViaVersion.commands.ViaCommandHandler;
import us.myles.ViaVersion.protocols.base.ProtocolInfo; import us.myles.ViaVersion.protocols.base.ProtocolInfo;
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.TabCompleteThread;
import us.myles.ViaVersion.protocols.protocol1_9to1_8.ViaIdleThread;
import us.myles.ViaVersion.update.UpdateUtil; import us.myles.ViaVersion.update.UpdateUtil;
import java.util.Map; import java.util.Map;
@ -83,6 +86,17 @@ public class ViaManager {
// Load Platform // Load Platform
loader.load(); loader.load();
// Common tasks
if (ProtocolRegistry.SERVER_PROTOCOL < ProtocolVersion.v1_9.getId()) {
if (Via.getConfig().isSimulatePlayerTick()) {
Via.getPlatform().runRepeatingSync(new ViaIdleThread(), 1L);
}
}
if (ProtocolRegistry.SERVER_PROTOCOL < ProtocolVersion.v1_13.getId()) {
if (Via.getConfig().get1_13TabCompleteDelay() > 0) {
Via.getPlatform().runRepeatingSync(new TabCompleteThread(), 1L);
}
}
// Refresh Versions // Refresh Versions
ProtocolRegistry.refreshVersions(); ProtocolRegistry.refreshVersions();

Datei anzeigen

@ -1,6 +1,7 @@
package us.myles.ViaVersion.api.platform; package us.myles.ViaVersion.api.platform;
public interface ViaPlatformLoader { public interface ViaPlatformLoader {
/** /**
* Initialise the loading for a platform, eg. registering listeners / providers / events etc. * Initialise the loading for a platform, eg. registering listeners / providers / events etc.
*/ */

Datei anzeigen

@ -104,7 +104,7 @@ public class ProtocolRegistry {
for (Integer version : supported) { for (Integer version : supported) {
if (!registryMap.containsKey(version)) { if (!registryMap.containsKey(version)) {
registryMap.put(version, new HashMap<Integer, Protocol>()); registryMap.put(version, new HashMap<>());
} }
registryMap.get(version).put(output, protocol); registryMap.get(version).put(output, protocol);

Datei anzeigen

@ -9,7 +9,7 @@ import us.myles.ViaVersion.api.data.UserConnection;
import java.util.regex.Pattern; import java.util.regex.Pattern;
public class ChatItemRewriter { public class ChatItemRewriter {
private static Pattern indexRemoval = Pattern.compile("\\d+:(?=([^\"\\\\]*(\\\\.|\"([^\"\\\\]*\\\\.)*[^\"\\\\]*\"))*[^\"]*$)"); private static final Pattern indexRemoval = Pattern.compile("\\d+:(?=([^\"\\\\]*(\\\\.|\"([^\"\\\\]*\\\\.)*[^\"\\\\]*\"))*[^\"]*$)");
// Taken from https://stackoverflow.com/questions/6462578/alternative-to-regex-match-all-instances-not-inside-quotes // Taken from https://stackoverflow.com/questions/6462578/alternative-to-regex-match-all-instances-not-inside-quotes
public static void toClient(JsonElement element, UserConnection user) { public static void toClient(JsonElement element, UserConnection user) {

Datei anzeigen

@ -1167,9 +1167,6 @@ public class Protocol1_13To1_12_2 extends Protocol {
protected void register(ViaProviders providers) { protected void register(ViaProviders providers) {
providers.register(BlockEntityProvider.class, new BlockEntityProvider()); providers.register(BlockEntityProvider.class, new BlockEntityProvider());
providers.register(PaintingProvider.class, new PaintingProvider()); providers.register(PaintingProvider.class, new PaintingProvider());
if (Via.getConfig().get1_13TabCompleteDelay() > 0) {
Via.getPlatform().runRepeatingSync(new TabCompleteThread(), 1L);
}
} }
private int getNewSoundID(final int oldID) { private int getNewSoundID(final int oldID) {

Datei anzeigen

@ -15,10 +15,10 @@ import java.util.HashMap;
import java.util.Map; import java.util.Map;
public class BlockConnectionStorage extends StoredObject { public class BlockConnectionStorage extends StoredObject {
private Map<Long, Pair<byte[], NibbleArray>> blockStorage = createLongObjectMap(); private final Map<Long, Pair<byte[], NibbleArray>> blockStorage = createLongObjectMap();
private static final Map<Short, Short> reverseBlockMappings;
private static Constructor<?> fastUtilLongObjectHashMap; private static Constructor<?> fastUtilLongObjectHashMap;
private static HashMap<Short, Short> reverseBlockMappings;
static { static {
try { try {

Datei anzeigen

@ -100,9 +100,6 @@ public class Protocol1_9To1_8 extends Protocol {
providers.register(BossBarProvider.class, new BossBarProvider()); providers.register(BossBarProvider.class, new BossBarProvider());
providers.register(MainHandProvider.class, new MainHandProvider()); providers.register(MainHandProvider.class, new MainHandProvider());
providers.require(MovementTransmitterProvider.class); providers.require(MovementTransmitterProvider.class);
if (Via.getConfig().isSimulatePlayerTick()) {
Via.getPlatform().runRepeatingSync(new ViaIdleThread(), 1L);
}
} }
@Override @Override

Datei anzeigen

@ -7,6 +7,8 @@ import us.myles.ViaVersion.api.data.UserConnection;
import us.myles.ViaVersion.api.minecraft.item.Item; import us.myles.ViaVersion.api.minecraft.item.Item;
import us.myles.ViaVersion.api.platform.TaskId; import us.myles.ViaVersion.api.platform.TaskId;
import us.myles.ViaVersion.api.platform.ViaPlatformLoader; 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.base.ProtocolInfo;
import us.myles.ViaVersion.protocols.protocol1_9to1_8.providers.BulkChunkTranslatorProvider; import us.myles.ViaVersion.protocols.protocol1_9to1_8.providers.BulkChunkTranslatorProvider;
import us.myles.ViaVersion.protocols.protocol1_9to1_8.providers.HandItemProvider; import us.myles.ViaVersion.protocols.protocol1_9to1_8.providers.HandItemProvider;
@ -26,10 +28,10 @@ import java.util.Set;
public class SpongeViaLoader implements ViaPlatformLoader { public class SpongeViaLoader implements ViaPlatformLoader {
private SpongePlugin plugin; private final SpongePlugin plugin;
private Set<Object> listeners = new HashSet<>(); private final Set<Object> listeners = new HashSet<>();
private Set<TaskId> tasks = new HashSet<>(); private final Set<TaskId> tasks = new HashSet<>();
public SpongeViaLoader(SpongePlugin plugin) { public SpongeViaLoader(SpongePlugin plugin) {
this.plugin = plugin; this.plugin = plugin;
@ -50,34 +52,40 @@ public class SpongeViaLoader implements ViaPlatformLoader {
registerListener(new UpdateListener()); registerListener(new UpdateListener());
/* Base Protocol */ /* Base Protocol */
registerListener(new ClientLeaveListener()); 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()) { /* 1.9 client to 1.8 server */
tasks.add(Via.getPlatform().runRepeatingSync(new HandItemCache(), 2L)); // Updates players items :) if (ProtocolRegistry.SERVER_PROTOCOL < ProtocolVersion.v1_9.getId()) {
HandItemCache.CACHE = true; 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 */ /* Providers */
Via.getManager().getProviders().use(BulkChunkTranslatorProvider.class, new SpongeViaBulkChunkTranslator()); if (ProtocolRegistry.SERVER_PROTOCOL < ProtocolVersion.v1_9.getId()) {
Via.getManager().getProviders().use(MovementTransmitterProvider.class, new SpongeViaMovementTransmitter()); Via.getManager().getProviders().use(BulkChunkTranslatorProvider.class, new SpongeViaBulkChunkTranslator());
Via.getManager().getProviders().use(HandItemProvider.class, new HandItemProvider() { Via.getManager().getProviders().use(MovementTransmitterProvider.class, new SpongeViaMovementTransmitter());
@Override
public Item getHandItem(final UserConnection info) { Via.getManager().getProviders().use(HandItemProvider.class, new HandItemProvider() {
if (HandItemCache.CACHE) { @Override
return HandItemCache.getHandItem(info.get(ProtocolInfo.class).getUuid()); public Item getHandItem(final UserConnection info) {
} else { if (HandItemCache.CACHE) {
return super.getHandItem(info); // TODO: On API Docs write about this return HandItemCache.getHandItem(info.get(ProtocolInfo.class).getUuid());
} else {
return super.getHandItem(info);
}
} }
} });
}); }
} }
public void unload() { public void unload() {

Datei anzeigen

@ -4,6 +4,8 @@ import com.velocitypowered.api.plugin.PluginContainer;
import us.myles.ViaVersion.VelocityPlugin; import us.myles.ViaVersion.VelocityPlugin;
import us.myles.ViaVersion.api.Via; import us.myles.ViaVersion.api.Via;
import us.myles.ViaVersion.api.platform.ViaPlatformLoader; 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.base.VersionProvider;
import us.myles.ViaVersion.protocols.protocol1_9to1_8.providers.BossBarProvider; import us.myles.ViaVersion.protocols.protocol1_9to1_8.providers.BossBarProvider;
import us.myles.ViaVersion.protocols.protocol1_9to1_8.providers.MovementTransmitterProvider; import us.myles.ViaVersion.protocols.protocol1_9to1_8.providers.MovementTransmitterProvider;
@ -21,15 +23,18 @@ public class VelocityViaLoader implements ViaPlatformLoader {
Object plugin = VelocityPlugin.PROXY.getPluginManager() Object plugin = VelocityPlugin.PROXY.getPluginManager()
.getPlugin("viaversion").flatMap(PluginContainer::getInstance).get(); .getPlugin("viaversion").flatMap(PluginContainer::getInstance).get();
Via.getManager().getProviders().use(MovementTransmitterProvider.class, new VelocityMovementTransmitter()); if (ProtocolRegistry.SERVER_PROTOCOL < ProtocolVersion.v1_9.getId()) {
Via.getManager().getProviders().use(BossBarProvider.class, new VelocityBossBarProvider()); 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()); 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 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 // 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 UpdateListener());
VelocityPlugin.PROXY.getEventManager().register(plugin, new VelocityServerHandler()); VelocityPlugin.PROXY.getEventManager().register(plugin, new VelocityServerHandler());
VelocityPlugin.PROXY.getEventManager().register(plugin, new ElytraPatch());
int pingInterval = ((VelocityViaConfig) Via.getPlatform().getConf()).getVelocityPingInterval(); int pingInterval = ((VelocityViaConfig) Via.getPlatform().getConf()).getVelocityPingInterval();
if (pingInterval > 0) { if (pingInterval > 0) {