Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c9883c2638 | ||
|
|
74fb55d96b | ||
|
|
4e844a0095 | ||
|
|
da7f8ea3b6 | ||
|
|
81c4e530e9 | ||
|
|
b1524642aa | ||
|
|
a828c43f99 | ||
|
|
fccfadf1b7 | ||
|
|
18b41c82c4 | ||
|
|
27ee6f519e |
No files matched your search
@@ -131,4 +131,11 @@ public interface ViaManager {
|
||||
* @param runnable runnable to be executed
|
||||
*/
|
||||
void addEnableListener(Runnable runnable);
|
||||
|
||||
/**
|
||||
* Returns whether the manager has been initialized (and protocols have been loaded).
|
||||
*
|
||||
* @return whether the manager has been initialized
|
||||
*/
|
||||
boolean isInitialized();
|
||||
}
|
||||
@@ -256,6 +256,8 @@ public interface ViaVersionConfig {
|
||||
*/
|
||||
boolean is1_13TeamColourFix();
|
||||
|
||||
boolean shouldRegisterUserConnectionOnJoin();
|
||||
|
||||
/**
|
||||
* Should we fix shift quick move action for 1.12 clients
|
||||
*
|
||||
|
||||
@@ -104,23 +104,22 @@ public interface ViaPlatform<T> {
|
||||
PlatformTask runSync(Runnable runnable);
|
||||
|
||||
/**
|
||||
* Run a task Sync after a interval
|
||||
* This must be only used after plugin enable.
|
||||
* Runs a synchronous task after a delay in ticks.
|
||||
*
|
||||
* @param runnable The task to run
|
||||
* @param ticks The interval to run it after
|
||||
* @return The Task ID
|
||||
* @param runnable task to run
|
||||
* @param delay delay in ticks to run it after
|
||||
* @return created task
|
||||
*/
|
||||
PlatformTask runSync(Runnable runnable, long ticks);
|
||||
PlatformTask runSync(Runnable runnable, long delay);
|
||||
|
||||
/**
|
||||
* Run a task at a repeating interval.
|
||||
* Runs a synchronous task at a repeating interval.
|
||||
*
|
||||
* @param runnable The task to run
|
||||
* @param ticks The interval to run it at
|
||||
* @return The Task ID
|
||||
* @param runnable task to run
|
||||
* @param period period in ticks to run at
|
||||
* @return created task
|
||||
*/
|
||||
PlatformTask runRepeatingSync(Runnable runnable, long ticks);
|
||||
PlatformTask runRepeatingSync(Runnable runnable, long period);
|
||||
|
||||
/**
|
||||
* Get the online players
|
||||
|
||||
+4
-2
@@ -57,10 +57,12 @@ public class ViaBukkitListener extends ViaListener implements Listener {
|
||||
*/
|
||||
@Override
|
||||
public void register() {
|
||||
if (isRegistered()) return;
|
||||
if (isRegistered()) {
|
||||
return;
|
||||
}
|
||||
|
||||
plugin.getServer().getPluginManager().registerEvents(this, plugin);
|
||||
setRegistered(true);
|
||||
plugin.getServer().getPluginManager().registerEvents(this, plugin);
|
||||
}
|
||||
|
||||
public Plugin getPlugin() {
|
||||
|
||||
@@ -27,6 +27,7 @@ import com.viaversion.viaversion.api.platform.UnsupportedSoftware;
|
||||
import com.viaversion.viaversion.api.platform.ViaPlatform;
|
||||
import com.viaversion.viaversion.bukkit.commands.BukkitCommandHandler;
|
||||
import com.viaversion.viaversion.bukkit.commands.BukkitCommandSender;
|
||||
import com.viaversion.viaversion.bukkit.listeners.JoinListener;
|
||||
import com.viaversion.viaversion.bukkit.platform.BukkitViaAPI;
|
||||
import com.viaversion.viaversion.bukkit.platform.BukkitViaConfig;
|
||||
import com.viaversion.viaversion.bukkit.platform.BukkitViaInjector;
|
||||
@@ -35,6 +36,7 @@ import com.viaversion.viaversion.bukkit.platform.BukkitViaTask;
|
||||
import com.viaversion.viaversion.bukkit.platform.BukkitViaTaskTask;
|
||||
import com.viaversion.viaversion.bukkit.platform.PaperViaInjector;
|
||||
import com.viaversion.viaversion.dump.PluginInfo;
|
||||
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.ChatRewriter;
|
||||
import com.viaversion.viaversion.unsupported.UnsupportedPlugin;
|
||||
import com.viaversion.viaversion.unsupported.UnsupportedServerSoftware;
|
||||
import com.viaversion.viaversion.util.GsonUtil;
|
||||
@@ -79,6 +81,15 @@ public class ViaVersionPlugin extends JavaPlugin implements ViaPlatform<Player>
|
||||
|
||||
// Config magic
|
||||
conf = new BukkitViaConfig();
|
||||
|
||||
// Load a bunch of classes early with slow reflection and more classloading
|
||||
Via.getManager().getScheduler().execute(() -> {
|
||||
if (conf.shouldRegisterUserConnectionOnJoin()) {
|
||||
JoinListener.init();
|
||||
}
|
||||
|
||||
ChatRewriter.init();
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -171,13 +182,13 @@ public class ViaVersionPlugin extends JavaPlugin implements ViaPlatform<Player>
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlatformTask runSync(Runnable runnable, long ticks) {
|
||||
return new BukkitViaTask(getServer().getScheduler().runTaskLater(this, runnable, ticks));
|
||||
public PlatformTask runSync(Runnable runnable, long delay) {
|
||||
return new BukkitViaTask(getServer().getScheduler().runTaskLater(this, runnable, delay));
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlatformTask runRepeatingSync(Runnable runnable, long ticks) {
|
||||
return new BukkitViaTask(getServer().getScheduler().runTaskTimer(this, runnable, 0, ticks));
|
||||
public PlatformTask runRepeatingSync(Runnable runnable, long period) {
|
||||
return new BukkitViaTask(getServer().getScheduler().runTaskTimer(this, runnable, 0, period));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -25,6 +25,7 @@ import com.viaversion.viaversion.bukkit.util.NMSUtil;
|
||||
import io.netty.channel.Channel;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.logging.Level;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
@@ -41,13 +42,13 @@ public class JoinListener implements Listener {
|
||||
private static final Field CHANNEL;
|
||||
|
||||
static {
|
||||
Method gh = null;
|
||||
Field conn = null, nm = null, ch = null;
|
||||
Method getHandleMethod = null;
|
||||
Field gamePacketListenerField = null, connectionField = null, channelField = null;
|
||||
try {
|
||||
gh = NMSUtil.obc("entity.CraftPlayer").getDeclaredMethod("getHandle");
|
||||
conn = findField(gh.getReturnType(), "PlayerConnection", "ServerGamePacketListenerImpl");
|
||||
nm = findField(conn.getType(), "NetworkManager", "Connection");
|
||||
ch = findField(nm.getType(), "Channel");
|
||||
getHandleMethod = NMSUtil.obc("entity.CraftPlayer").getDeclaredMethod("getHandle");
|
||||
gamePacketListenerField = findField(getHandleMethod.getReturnType(), "PlayerConnection", "ServerGamePacketListenerImpl");
|
||||
connectionField = findField(gamePacketListenerField.getType(), "NetworkManager", "Connection");
|
||||
channelField = findField(connectionField.getType(), Class.forName("io.netty.channel.Channel"));
|
||||
} catch (NoSuchMethodException | NoSuchFieldException | ClassNotFoundException e) {
|
||||
Via.getPlatform().getLogger().log(
|
||||
Level.WARNING,
|
||||
@@ -55,22 +56,47 @@ public class JoinListener implements Listener {
|
||||
"Login race condition fixer will be disabled.\n" +
|
||||
" Some plugins that use ViaAPI on join event may work incorrectly.", e);
|
||||
}
|
||||
GET_HANDLE = gh;
|
||||
CONNECTION = conn;
|
||||
NETWORK_MANAGER = nm;
|
||||
CHANNEL = ch;
|
||||
GET_HANDLE = getHandleMethod;
|
||||
CONNECTION = gamePacketListenerField;
|
||||
NETWORK_MANAGER = connectionField;
|
||||
CHANNEL = channelField;
|
||||
}
|
||||
|
||||
public static void init() {
|
||||
}
|
||||
|
||||
// Loosely search a field with any name, as long as it matches a type name.
|
||||
private static Field findField(Class<?> cl, String... types) throws NoSuchFieldException {
|
||||
for (Field field : cl.getDeclaredFields()) {
|
||||
for (String type : types)
|
||||
if (field.getType().getSimpleName().equals(type))
|
||||
return field;
|
||||
private static Field findField(Class<?> clazz, String... types) throws NoSuchFieldException {
|
||||
for (Field field : clazz.getDeclaredFields()) {
|
||||
String fieldTypeName = field.getType().getSimpleName();
|
||||
for (String type : types) {
|
||||
if (!fieldTypeName.equals(type)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!Modifier.isPublic(field.getModifiers())) {
|
||||
field.setAccessible(true);
|
||||
}
|
||||
return field;
|
||||
}
|
||||
}
|
||||
throw new NoSuchFieldException(types[0]);
|
||||
}
|
||||
|
||||
private static Field findField(Class<?> clazz, Class<?> fieldType) throws NoSuchFieldException {
|
||||
for (Field field : clazz.getDeclaredFields()) {
|
||||
if (field.getType() != fieldType) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!Modifier.isPublic(field.getModifiers())) {
|
||||
field.setAccessible(true);
|
||||
}
|
||||
return field;
|
||||
}
|
||||
throw new NoSuchFieldException(fieldType.getSimpleName());
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
public void onJoin(PlayerJoinEvent e) {
|
||||
if (CHANNEL == null) return;
|
||||
|
||||
+11
-7
@@ -27,6 +27,7 @@ import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.inventory.EquipmentSlot;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.PlayerInventory;
|
||||
|
||||
public final class ArmorToggleListener extends ViaBukkitListener {
|
||||
|
||||
@@ -46,23 +47,26 @@ public final class ArmorToggleListener extends ViaBukkitListener {
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void itemUse(final PlayerInteractEvent event) {
|
||||
if (!ENABLED) {
|
||||
return;
|
||||
}
|
||||
|
||||
final Player player = event.getPlayer();
|
||||
if (!isOnPipe(player) || event.getItem() == null) {
|
||||
final ItemStack item = event.getItem();
|
||||
if (item == null || event.getHand() == null || !isOnPipe(player)) {
|
||||
return;
|
||||
}
|
||||
|
||||
final EquipmentSlot equipmentSlot = event.getItem().getType().getEquipmentSlot();
|
||||
if (equipmentSlot != EquipmentSlot.HAND && equipmentSlot != EquipmentSlot.OFF_HAND) {
|
||||
final ItemStack armor = player.getInventory().getItem(equipmentSlot);
|
||||
final EquipmentSlot armorItemSlot = item.getType().getEquipmentSlot();
|
||||
if (armorItemSlot != EquipmentSlot.HAND && armorItemSlot != EquipmentSlot.OFF_HAND) {
|
||||
final PlayerInventory inventory = player.getInventory();
|
||||
final ItemStack armor = inventory.getItem(armorItemSlot);
|
||||
// If two pieces of armor are equal, the client will do nothing.
|
||||
if (armor != null && armor.getType() != Material.AIR && !armor.equals(event.getItem())) {
|
||||
player.updateInventory();
|
||||
if (armor != null && armor.getType() != Material.AIR && !armor.equals(item)) {
|
||||
inventory.setItem(event.getHand(), inventory.getItem(event.getHand()));
|
||||
inventory.setItem(armorItemSlot, armor);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,6 +32,7 @@ public class BukkitViaConfig extends AbstractViaConfig {
|
||||
private boolean hitboxFix1_14;
|
||||
private String blockConnectionMethod;
|
||||
private boolean armorToggleFix;
|
||||
private boolean registerUserConnectionOnJoin;
|
||||
|
||||
public BukkitViaConfig() {
|
||||
super(new File(((Plugin) Via.getPlatform()).getDataFolder(), "config.yml"));
|
||||
@@ -41,6 +42,7 @@ public class BukkitViaConfig extends AbstractViaConfig {
|
||||
@Override
|
||||
protected void loadFields() {
|
||||
super.loadFields();
|
||||
registerUserConnectionOnJoin = getBoolean("register-userconnections-on-join", true);
|
||||
quickMoveActionFix = getBoolean("quick-move-action-fix", false);
|
||||
hitboxFix1_9 = getBoolean("change-1_9-hitbox", false);
|
||||
hitboxFix1_14 = getBoolean("change-1_14-hitbox", false);
|
||||
@@ -52,6 +54,11 @@ public class BukkitViaConfig extends AbstractViaConfig {
|
||||
protected void handleConfig(Map<String, Object> config) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldRegisterUserConnectionOnJoin() {
|
||||
return registerUserConnectionOnJoin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean is1_12QuickMoveActionFix() {
|
||||
return quickMoveActionFix;
|
||||
|
||||
+34
-2
@@ -17,6 +17,7 @@
|
||||
*/
|
||||
package com.viaversion.viaversion.bukkit.platform;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.viaversion.viaversion.bukkit.handlers.BukkitChannelInitializer;
|
||||
import com.viaversion.viaversion.bukkit.util.NMSUtil;
|
||||
import com.viaversion.viaversion.platform.LegacyViaInjector;
|
||||
@@ -35,6 +36,8 @@ import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
public class BukkitViaInjector extends LegacyViaInjector {
|
||||
|
||||
private static final boolean HAS_SHARED_CONSTANTS = PaperViaInjector.hasClass("net.minecraft.SharedConstants") && PaperViaInjector.hasClass("net.minecraft.WorldVersion");
|
||||
|
||||
@Override
|
||||
public void inject() throws ReflectiveOperationException {
|
||||
if (PaperViaInjector.PAPER_INJECTION_METHOD) {
|
||||
@@ -62,10 +65,37 @@ public class BukkitViaInjector extends LegacyViaInjector {
|
||||
return Bukkit.getUnsafe().getProtocolVersion();
|
||||
}
|
||||
|
||||
// Time to go on a journey! The protocol version is hidden inside an int in ServerPing.ServerData
|
||||
return HAS_SHARED_CONSTANTS ? cursedProtocolDetection() : veryCursedProtocolDetection();
|
||||
}
|
||||
|
||||
private int cursedProtocolDetection() throws ReflectiveOperationException {
|
||||
// Get the version from SharedConstants.getWorldVersion().getProtocolVersion()
|
||||
Class<?> sharedConstantsClass = Class.forName("net.minecraft.SharedConstants");
|
||||
Class<?> worldVersionClass = Class.forName("net.minecraft.WorldVersion");
|
||||
Method getWorldVersionMethod = null;
|
||||
for (Method method : sharedConstantsClass.getDeclaredMethods()) {
|
||||
if (method.getReturnType() == worldVersionClass && method.getParameterTypes().length == 0) {
|
||||
getWorldVersionMethod = method;
|
||||
break;
|
||||
}
|
||||
}
|
||||
Preconditions.checkNotNull(getWorldVersionMethod, "Failed to get world version method");
|
||||
|
||||
Object worldVersion = getWorldVersionMethod.invoke(null);
|
||||
for (Method method : worldVersionClass.getDeclaredMethods()) {
|
||||
if (method.getReturnType() == int.class && method.getParameterTypes().length == 0) {
|
||||
return (int) method.invoke(worldVersion);
|
||||
}
|
||||
}
|
||||
throw new IllegalAccessException("Failed to find protocol version method in WorldVersion");
|
||||
}
|
||||
|
||||
private int veryCursedProtocolDetection() throws ReflectiveOperationException {
|
||||
// Time to go on a journey! The protocol version is hidden inside an int in ServerPing.ServerData, that is only set once the server has ticked once
|
||||
// Grab a static instance of the server
|
||||
Class<?> serverClazz = NMSUtil.nms("MinecraftServer", "net.minecraft.server.MinecraftServer");
|
||||
Object server = ReflectionUtil.invokeStatic(serverClazz, "getServer");
|
||||
Preconditions.checkNotNull(server, "Failed to get server instance");
|
||||
|
||||
// Grab the ping class and find the field to access it
|
||||
Class<?> pingClazz = NMSUtil.nms(
|
||||
@@ -80,6 +110,7 @@ public class BukkitViaInjector extends LegacyViaInjector {
|
||||
break;
|
||||
}
|
||||
}
|
||||
Preconditions.checkNotNull(ping, "Failed to get server ping");
|
||||
|
||||
// Now get the ServerData inside ServerPing
|
||||
Class<?> serverDataClass = NMSUtil.nms(
|
||||
@@ -94,6 +125,7 @@ public class BukkitViaInjector extends LegacyViaInjector {
|
||||
break;
|
||||
}
|
||||
}
|
||||
Preconditions.checkNotNull(serverData, "Failed to get server data");
|
||||
|
||||
// Get protocol version field
|
||||
for (Field field : serverDataClass.getDeclaredFields()) {
|
||||
@@ -155,7 +187,7 @@ public class BukkitViaInjector extends LegacyViaInjector {
|
||||
|
||||
@Override
|
||||
public boolean lateProtocolVersionSetting() {
|
||||
return !PaperViaInjector.PAPER_PROTOCOL_METHOD;
|
||||
return !(PaperViaInjector.PAPER_PROTOCOL_METHOD || HAS_SHARED_CONSTANTS);
|
||||
}
|
||||
|
||||
public boolean isBinded() {
|
||||
|
||||
+19
-21
@@ -51,16 +51,13 @@ import java.util.UUID;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
|
||||
public class BukkitViaLoader implements ViaPlatformLoader {
|
||||
private final ViaVersionPlugin plugin;
|
||||
|
||||
private final Set<Listener> listeners = new HashSet<>();
|
||||
private final Set<BukkitTask> tasks = new HashSet<>();
|
||||
|
||||
private final ViaVersionPlugin plugin;
|
||||
private HandItemCache handItemCache;
|
||||
|
||||
public BukkitViaLoader(ViaVersionPlugin plugin) {
|
||||
@@ -68,21 +65,21 @@ public class BukkitViaLoader implements ViaPlatformLoader {
|
||||
}
|
||||
|
||||
public void registerListener(Listener listener) {
|
||||
Bukkit.getPluginManager().registerEvents(storeListener(listener), plugin);
|
||||
plugin.getServer().getPluginManager().registerEvents(listener, plugin);
|
||||
}
|
||||
|
||||
@Deprecated/*(forRemoval = true)*/
|
||||
public <T extends Listener> T storeListener(T listener) {
|
||||
listeners.add(listener);
|
||||
return listener;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load() {
|
||||
// Update Listener
|
||||
registerListener(new UpdateListener());
|
||||
|
||||
// Login listener
|
||||
registerListener(new JoinListener());
|
||||
if (Via.getConfig().shouldRegisterUserConnectionOnJoin()) {
|
||||
registerListener(new JoinListener());
|
||||
}
|
||||
|
||||
/* Base Protocol */
|
||||
final ViaVersionPlugin plugin = (ViaVersionPlugin) Bukkit.getPluginManager().getPlugin("ViaVersion");
|
||||
@@ -92,13 +89,18 @@ public class BukkitViaLoader implements ViaPlatformLoader {
|
||||
ProtocolSupportCompat.registerPSConnectListener(plugin);
|
||||
}
|
||||
|
||||
if (!Via.getAPI().getServerVersion().isKnown()) {
|
||||
Via.getPlatform().getLogger().severe("Server version has not been loaded yet, cannot register additional listeners");
|
||||
return;
|
||||
}
|
||||
|
||||
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();
|
||||
new ArmorListener(plugin).register();
|
||||
new DeathListener(plugin).register();
|
||||
new BlockListener(plugin).register();
|
||||
|
||||
if (plugin.getConf().isItemCache()) {
|
||||
handItemCache = new HandItemCache();
|
||||
@@ -110,7 +112,7 @@ public class BukkitViaLoader implements ViaPlatformLoader {
|
||||
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();
|
||||
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();
|
||||
@@ -121,7 +123,7 @@ public class BukkitViaLoader implements ViaPlatformLoader {
|
||||
if (serverProtocolVersion < ProtocolVersion.v1_15.getVersion()) {
|
||||
try {
|
||||
Class.forName("org.bukkit.event.entity.EntityToggleGlideEvent");
|
||||
storeListener(new EntityToggleGlideListener(plugin)).register();
|
||||
new EntityToggleGlideListener(plugin).register();
|
||||
} catch (ClassNotFoundException ignored) {
|
||||
}
|
||||
}
|
||||
@@ -138,12 +140,12 @@ public class BukkitViaLoader implements ViaPlatformLoader {
|
||||
}
|
||||
}
|
||||
if (paper) {
|
||||
storeListener(new PaperPatch(plugin)).register();
|
||||
new PaperPatch(plugin).register();
|
||||
}
|
||||
}
|
||||
|
||||
if (serverProtocolVersion < ProtocolVersion.v1_19_4.getVersion() && plugin.getConf().isArmorToggleFix()) {
|
||||
storeListener(new ArmorToggleListener(plugin)).register();
|
||||
new ArmorToggleListener(plugin).register();
|
||||
}
|
||||
|
||||
/* Providers */
|
||||
@@ -189,16 +191,12 @@ public class BukkitViaLoader implements ViaPlatformLoader {
|
||||
}
|
||||
if (serverProtocolVersion < ProtocolVersion.v1_19.getVersion()) {
|
||||
Via.getManager().getProviders().use(AckSequenceProvider.class, new BukkitAckSequenceProvider(plugin));
|
||||
storeListener(new BlockBreakListener(plugin)).register();
|
||||
new BlockBreakListener(plugin).register();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unload() {
|
||||
for (Listener listener : listeners) {
|
||||
HandlerList.unregisterAll(listener);
|
||||
}
|
||||
listeners.clear();
|
||||
for (BukkitTask task : tasks) {
|
||||
task.cancel();
|
||||
}
|
||||
|
||||
@@ -126,13 +126,13 @@ public class BungeePlugin extends Plugin implements ViaServerProxyPlatform<Proxi
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlatformTask runSync(Runnable runnable, long ticks) {
|
||||
return new BungeeViaTask(getProxy().getScheduler().schedule(this, runnable, ticks * 50, TimeUnit.MILLISECONDS));
|
||||
public PlatformTask runSync(Runnable runnable, long delay) {
|
||||
return new BungeeViaTask(getProxy().getScheduler().schedule(this, runnable, delay * 50, TimeUnit.MILLISECONDS));
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlatformTask runRepeatingSync(Runnable runnable, long ticks) {
|
||||
return runRepeatingAsync(runnable, ticks);
|
||||
public PlatformTask runRepeatingSync(Runnable runnable, long period) {
|
||||
return runRepeatingAsync(runnable, period);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -63,6 +63,7 @@ public class ViaManagerImpl implements ViaManager {
|
||||
private final Set<String> subPlatforms = new HashSet<>();
|
||||
private List<Runnable> enableListeners = new ArrayList<>();
|
||||
private PlatformTask<?> mappingLoadingTask;
|
||||
private boolean initialized;
|
||||
|
||||
public ViaManagerImpl(ViaPlatform<?> platform, ViaInjector injector, ViaCommandHandler commandHandler, ViaPlatformLoader loader) {
|
||||
this.platform = platform;
|
||||
@@ -105,6 +106,8 @@ public class ViaManagerImpl implements ViaManager {
|
||||
listener.run();
|
||||
}
|
||||
enableListeners = null;
|
||||
|
||||
initialized = true;
|
||||
}
|
||||
|
||||
public void onServerLoaded() {
|
||||
@@ -149,9 +152,6 @@ public class ViaManagerImpl implements ViaManager {
|
||||
// Check for unsupported plugins/software
|
||||
unsupportedSoftwareWarning();
|
||||
|
||||
// Load Listeners / Tasks
|
||||
protocolManager.onServerLoaded();
|
||||
|
||||
// Load Platform
|
||||
loader.load();
|
||||
// Common tasks
|
||||
@@ -324,6 +324,11 @@ public class ViaManagerImpl implements ViaManager {
|
||||
enableListeners.add(runnable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInitialized() {
|
||||
return initialized;
|
||||
}
|
||||
|
||||
public static final class ViaManagerBuilder {
|
||||
private ViaPlatform<?> platform;
|
||||
private ViaInjector injector;
|
||||
|
||||
@@ -383,6 +383,11 @@ public abstract class AbstractViaConfig extends Config implements ViaVersionConf
|
||||
return nbtArrayFix;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldRegisterUserConnectionOnJoin() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean is1_12QuickMoveActionFix() {
|
||||
return false;
|
||||
|
||||
@@ -109,11 +109,10 @@ public class ProtocolManagerImpl implements ProtocolManager {
|
||||
|
||||
// Input Version -> Output Version & Protocol (Allows fast lookup)
|
||||
private final Int2ObjectMap<Int2ObjectMap<Protocol>> registryMap = new Int2ObjectOpenHashMap<>(32);
|
||||
private final Map<Class<? extends Protocol>, Protocol<?, ?, ?, ?>> protocols = new HashMap<>();
|
||||
private final Map<Class<? extends Protocol>, Protocol<?, ?, ?, ?>> protocols = new HashMap<>(64);
|
||||
private final Map<ProtocolPathKey, List<ProtocolPathEntry>> pathCache = new ConcurrentHashMap<>();
|
||||
private final Set<Integer> supportedVersions = new HashSet<>();
|
||||
private final List<Pair<Range<Integer>, Protocol>> baseProtocols = Lists.newCopyOnWriteArrayList();
|
||||
private final List<Protocol> registerList = new ArrayList<>();
|
||||
|
||||
private final ReadWriteLock mappingLoaderLock = new ReentrantReadWriteLock();
|
||||
private Map<Class<? extends Protocol>, CompletableFuture<Void>> mappingLoaderFutures = new HashMap<>();
|
||||
@@ -208,11 +207,9 @@ public class ProtocolManagerImpl implements ProtocolManager {
|
||||
protocolMap.put(serverVersion, protocol);
|
||||
}
|
||||
|
||||
if (Via.getPlatform().isPluginEnabled()) {
|
||||
protocol.register(Via.getManager().getProviders());
|
||||
protocol.register(Via.getManager().getProviders());
|
||||
if (Via.getManager().isInitialized()) {
|
||||
refreshVersions();
|
||||
} else {
|
||||
registerList.add(protocol);
|
||||
}
|
||||
|
||||
if (protocol.hasMappingDataToLoad()) {
|
||||
@@ -232,11 +229,9 @@ public class ProtocolManagerImpl implements ProtocolManager {
|
||||
baseProtocol.initialize();
|
||||
|
||||
baseProtocols.add(new Pair<>(supportedProtocols, baseProtocol));
|
||||
if (Via.getPlatform().isPluginEnabled()) {
|
||||
baseProtocol.register(Via.getManager().getProviders());
|
||||
baseProtocol.register(Via.getManager().getProviders());
|
||||
if (Via.getManager().isInitialized()) {
|
||||
refreshVersions();
|
||||
} else {
|
||||
registerList.add(baseProtocol);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -498,16 +493,6 @@ public class ProtocolManagerImpl implements ProtocolManager {
|
||||
return new PacketWrapperImpl(packetId, buf, connection);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the server is enabled, to register any non-registered listeners.
|
||||
*/
|
||||
public void onServerLoaded() {
|
||||
for (Protocol protocol : registerList) {
|
||||
protocol.register(Via.getManager().getProviders());
|
||||
}
|
||||
registerList.clear();
|
||||
}
|
||||
|
||||
public void shutdownLoaderExecutor() {
|
||||
Preconditions.checkArgument(!mappingsLoaded);
|
||||
|
||||
|
||||
+4
@@ -28,6 +28,10 @@ import com.viaversion.viaversion.libs.kyori.adventure.text.serializer.legacy.Leg
|
||||
|
||||
public final class ChatRewriter {
|
||||
public static final GsonComponentSerializer HOVER_GSON_SERIALIZER = GsonComponentSerializer.builder().emitLegacyHoverEvent().legacyHoverEventSerializer(NBTLegacyHoverEventSerializer.get()).build();
|
||||
public static final JsonElement EMPTY_COMPONENT = GsonComponentSerializer.gson().serializeToTree(Component.empty());
|
||||
|
||||
public static void init() {
|
||||
}
|
||||
|
||||
public static String legacyTextToJsonString(String message, boolean itemData) {
|
||||
// Not used for chat messages, so no need for url extraction
|
||||
|
||||
+2
-3
@@ -28,6 +28,7 @@ import com.viaversion.viaversion.api.type.types.version.Types1_19_4;
|
||||
import com.viaversion.viaversion.data.entity.EntityTrackerBase;
|
||||
import com.viaversion.viaversion.libs.kyori.adventure.text.Component;
|
||||
import com.viaversion.viaversion.libs.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
||||
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.ChatRewriter;
|
||||
import com.viaversion.viaversion.protocols.protocol1_19_3to1_19_1.ClientboundPackets1_19_3;
|
||||
import com.viaversion.viaversion.protocols.protocol1_19_3to1_19_1.ServerboundPackets1_19_3;
|
||||
import com.viaversion.viaversion.protocols.protocol1_19_4to1_19_3.data.MappingData;
|
||||
@@ -42,7 +43,6 @@ import java.util.Base64;
|
||||
public final class Protocol1_19_4To1_19_3 extends AbstractProtocol<ClientboundPackets1_19_3, ClientboundPackets1_19_4, ServerboundPackets1_19_3, ServerboundPackets1_19_4> {
|
||||
|
||||
public static final MappingData MAPPINGS = new MappingData();
|
||||
private static final JsonElement EMPTY_COMPONENT = GsonComponentSerializer.gson().serializeToTree(Component.empty());
|
||||
private final EntityPackets entityRewriter = new EntityPackets(this);
|
||||
private final InventoryPackets itemRewriter = new InventoryPackets(this);
|
||||
|
||||
@@ -60,7 +60,6 @@ public final class Protocol1_19_4To1_19_3 extends AbstractProtocol<ClientboundPa
|
||||
soundRewriter.registerSound(ClientboundPackets1_19_3.ENTITY_SOUND);
|
||||
soundRewriter.register1_19_3Sound(ClientboundPackets1_19_3.SOUND);
|
||||
|
||||
|
||||
new CommandRewriter<ClientboundPackets1_19_3>(this) {
|
||||
@Override
|
||||
public void handleArgument(final PacketWrapper wrapper, final String argumentType) throws Exception {
|
||||
@@ -78,7 +77,7 @@ public final class Protocol1_19_4To1_19_3 extends AbstractProtocol<ClientboundPa
|
||||
if (element != null) {
|
||||
wrapper.write(Type.COMPONENT, element);
|
||||
} else {
|
||||
wrapper.write(Type.COMPONENT, EMPTY_COMPONENT);
|
||||
wrapper.write(Type.COMPONENT, ChatRewriter.EMPTY_COMPONENT);
|
||||
}
|
||||
|
||||
final String iconBase64 = wrapper.read(Type.OPTIONAL_STRING);
|
||||
|
||||
+1
-1
@@ -131,7 +131,7 @@ public final class EntityPackets extends EntityRewriter<ClientboundPackets1_19_3
|
||||
wrapper.write(Type.BYTE, event);
|
||||
});
|
||||
|
||||
registerTrackerWithData1_19(ClientboundPackets1_19_3.SPAWN_ENTITY, null);
|
||||
registerTrackerWithData1_19(ClientboundPackets1_19_3.SPAWN_ENTITY, Entity1_19_4Types.FALLING_BLOCK);
|
||||
registerRemoveEntities(ClientboundPackets1_19_3.REMOVE_ENTITIES);
|
||||
registerMetadataRewriter(ClientboundPackets1_19_3.ENTITY_METADATA, Types1_19_3.METADATA_LIST, Types1_19_4.METADATA_LIST);
|
||||
}
|
||||
|
||||
+4
-7
@@ -53,13 +53,10 @@ public class InventoryPackets {
|
||||
// Send 2 properties, splitting it into enchantID & level
|
||||
final short level = (short) (value >> 8);
|
||||
final short enchantID = (short) (value & 0xFF);
|
||||
wrapper.create(wrapper.getId(), new PacketHandler() {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
wrapper.write(Type.UNSIGNED_BYTE, windowId);
|
||||
wrapper.write(Type.SHORT, property);
|
||||
wrapper.write(Type.SHORT, enchantID);
|
||||
}
|
||||
wrapper.create(wrapper.getId(), propertyPacket -> {
|
||||
propertyPacket.write(Type.UNSIGNED_BYTE, windowId);
|
||||
propertyPacket.write(Type.SHORT, property);
|
||||
propertyPacket.write(Type.SHORT, enchantID);
|
||||
}).scheduleSend(Protocol1_9To1_8.class);
|
||||
|
||||
wrapper.set(Type.SHORT, 0, (short) (property + 3));
|
||||
|
||||
@@ -39,8 +39,9 @@ import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
import org.yaml.snakeyaml.DumperOptions;
|
||||
import org.yaml.snakeyaml.Yaml;
|
||||
|
||||
@SuppressWarnings("VulnerableCodeUsages")
|
||||
public abstract class Config implements ConfigurationProvider {
|
||||
private static final YamlCompat YAMP_COMPAT = YamlCompat.isVersion2() ? new Yaml2Compat() : new Yaml1Compat();
|
||||
private static final YamlCompat YAMP_COMPAT = YamlCompat.isVersion1() ? new Yaml1Compat() : new Yaml2Compat();
|
||||
private static final ThreadLocal<Yaml> YAML = ThreadLocal.withInitial(() -> {
|
||||
DumperOptions options = new DumperOptions();
|
||||
options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
|
||||
|
||||
@@ -102,6 +102,9 @@ tracking-max-kick-msg: "You are sending too many packets, :("
|
||||
# MULTIPLE VERSIONS OPTIONS #
|
||||
#----------------------------------------------------------#
|
||||
#
|
||||
# Whether to make sure ViaVersion's UserConnection object is already available in the PlayerJoinEvent.
|
||||
# You may disable this for faster startup/join time if you are 100% sure no plugin requires this.
|
||||
register-userconnections-on-join: true
|
||||
# Should we enable our hologram patch?
|
||||
# If they're in the wrong place enable this
|
||||
hologram-patch: false
|
||||
|
||||
@@ -71,12 +71,12 @@ public final class TestPlatform implements ViaPlatform {
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlatformTask runSync(Runnable runnable, long ticks) {
|
||||
public PlatformTask runSync(Runnable runnable, long delay) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlatformTask runRepeatingSync(Runnable runnable, long ticks) {
|
||||
public PlatformTask runRepeatingSync(Runnable runnable, long period) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -27,9 +27,9 @@ public interface YamlCompat {
|
||||
|
||||
SafeConstructor createSafeConstructor();
|
||||
|
||||
static boolean isVersion2() {
|
||||
static boolean isVersion1() {
|
||||
try {
|
||||
Representer.class.getDeclaredConstructor(DumperOptions.class);
|
||||
SafeConstructor.class.getDeclaredConstructor();
|
||||
return true;
|
||||
} catch (NoSuchMethodException e) {
|
||||
return false;
|
||||
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
# Project properties - we put these here so they can be modified without causing a recompile of the build scripts
|
||||
projectVersion=4.6.0
|
||||
projectVersion=4.6.1
|
||||
|
||||
# Gradle properties
|
||||
org.gradle.daemon=true
|
||||
|
||||
@@ -153,14 +153,14 @@ public class SpongePlugin implements ViaPlatform<Player> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlatformTask runSync(Runnable runnable, long ticks) {
|
||||
final Task task = Task.builder().plugin(container).execute(runnable).delay(Ticks.of(ticks)).build();
|
||||
public PlatformTask runSync(Runnable runnable, long delay) {
|
||||
final Task task = Task.builder().plugin(container).execute(runnable).delay(Ticks.of(delay)).build();
|
||||
return new SpongeViaTask(game.server().scheduler().submit(task));
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlatformTask runRepeatingSync(Runnable runnable, long ticks) {
|
||||
final Task task = Task.builder().plugin(container).execute(runnable).interval(Ticks.of(ticks)).build();
|
||||
public PlatformTask runRepeatingSync(Runnable runnable, long period) {
|
||||
final Task task = Task.builder().plugin(container).execute(runnable).interval(Ticks.of(period)).build();
|
||||
return new SpongeViaTask(game.server().scheduler().submit(task));
|
||||
}
|
||||
|
||||
|
||||
@@ -155,17 +155,17 @@ public class VelocityPlugin implements ViaServerProxyPlatform<Player> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlatformTask runSync(Runnable runnable, long ticks) {
|
||||
public PlatformTask runSync(Runnable runnable, long delay) {
|
||||
return new VelocityViaTask(
|
||||
PROXY.getScheduler()
|
||||
.buildTask(this, runnable)
|
||||
.delay(ticks * 50, TimeUnit.MILLISECONDS).schedule()
|
||||
.delay(delay * 50, TimeUnit.MILLISECONDS).schedule()
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlatformTask runRepeatingSync(Runnable runnable, long ticks) {
|
||||
return runRepeatingAsync(runnable, ticks);
|
||||
public PlatformTask runRepeatingSync(Runnable runnable, long period) {
|
||||
return runRepeatingAsync(runnable, period);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in new issue
Block a user