Mirror von
https://github.com/ViaVersion/ViaVersion.git
synchronisiert 2024-09-08 22:02:50 +02:00
Do not unnecessarily register tasks/listeners
Dieser Commit ist enthalten in:
Ursprung
b06b9c69ca
Commit
598b51a4bf
@ -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 {
|
||||||
@ -80,6 +79,11 @@ public class BukkitViaLoader implements ViaPlatformLoader {
|
|||||||
storeListener(new ArmorListener(plugin)).register();
|
storeListener(new ArmorListener(plugin)).register();
|
||||||
storeListener(new DeathListener(plugin)).register();
|
storeListener(new DeathListener(plugin)).register();
|
||||||
storeListener(new BlockListener(plugin)).register();
|
storeListener(new BlockListener(plugin)).register();
|
||||||
|
|
||||||
|
if (plugin.getConf().isItemCache()) {
|
||||||
|
handItemCache = new HandItemCache();
|
||||||
|
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()) {
|
||||||
@ -101,10 +105,6 @@ 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 */
|
||||||
if (ProtocolRegistry.SERVER_PROTOCOL < ProtocolVersion.v1_9.getId()) {
|
if (ProtocolRegistry.SERVER_PROTOCOL < ProtocolVersion.v1_9.getId()) {
|
||||||
@ -116,25 +116,21 @@ public class BukkitViaLoader implements ViaPlatformLoader {
|
|||||||
public Item getHandItem(final UserConnection info) {
|
public Item getHandItem(final UserConnection info) {
|
||||||
if (handItemCache != null) {
|
if (handItemCache != null) {
|
||||||
return handItemCache.getHandItem(info.get(ProtocolInfo.class).getUuid());
|
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;
|
|
||||||
}
|
|
||||||
}).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;
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -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();
|
||||||
|
@ -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.
|
||||||
*/
|
*/
|
||||||
|
@ -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) {
|
||||||
|
@ -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) {
|
||||||
|
@ -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 {
|
||||||
|
@ -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
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren