Mirror von
https://github.com/ViaVersion/ViaVersion.git
synchronisiert 2024-12-27 00:22:51 +01:00
Start moving listeners away
Dieser Commit ist enthalten in:
Ursprung
848b0cf113
Commit
49d51de263
2
TODOLIST
2
TODOLIST
@ -9,3 +9,5 @@ Add new info to dump for platform
|
|||||||
Migrate Bukkit types to our own :D
|
Migrate Bukkit types to our own :D
|
||||||
|
|
||||||
Important: Create builder for ViaManager which allows supplying on the command exectutor, injector, platform :D
|
Important: Create builder for ViaManager which allows supplying on the command exectutor, injector, platform :D
|
||||||
|
|
||||||
|
Important: Add BukkitViaLoader to ViaManager sequence
|
@ -8,14 +8,15 @@ import org.bukkit.plugin.java.JavaPlugin;
|
|||||||
import us.myles.ViaVersion.api.Via;
|
import us.myles.ViaVersion.api.Via;
|
||||||
import us.myles.ViaVersion.api.ViaAPI;
|
import us.myles.ViaVersion.api.ViaAPI;
|
||||||
import us.myles.ViaVersion.api.ViaVersion;
|
import us.myles.ViaVersion.api.ViaVersion;
|
||||||
|
import us.myles.ViaVersion.api.command.ViaCommandSender;
|
||||||
import us.myles.ViaVersion.api.data.UserConnection;
|
import us.myles.ViaVersion.api.data.UserConnection;
|
||||||
import us.myles.ViaVersion.api.platform.ViaPlatform;
|
import us.myles.ViaVersion.api.platform.ViaPlatform;
|
||||||
import us.myles.ViaVersion.api.protocol.ProtocolRegistry;
|
import us.myles.ViaVersion.api.protocol.ProtocolRegistry;
|
||||||
import us.myles.ViaVersion.bukkit.BukkitCommandHandler;
|
import us.myles.ViaVersion.bukkit.BukkitCommandHandler;
|
||||||
|
import us.myles.ViaVersion.bukkit.BukkitCommandSender;
|
||||||
import us.myles.ViaVersion.bukkit.BukkitViaAPI;
|
import us.myles.ViaVersion.bukkit.BukkitViaAPI;
|
||||||
import us.myles.ViaVersion.bukkit.BukkitViaInjector;
|
import us.myles.ViaVersion.bukkit.BukkitViaInjector;
|
||||||
import us.myles.ViaVersion.classgenerator.ClassGenerator;
|
import us.myles.ViaVersion.classgenerator.ClassGenerator;
|
||||||
import us.myles.ViaVersion.listeners.UpdateListener;
|
|
||||||
import us.myles.ViaVersion.util.ReflectionUtil;
|
import us.myles.ViaVersion.util.ReflectionUtil;
|
||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
@ -88,7 +89,6 @@ public class ViaVersionPlugin extends JavaPlugin implements ViaPlatform {
|
|||||||
Via.getManager().init();
|
Via.getManager().init();
|
||||||
}
|
}
|
||||||
|
|
||||||
Bukkit.getPluginManager().registerEvents(new UpdateListener(), this);
|
|
||||||
|
|
||||||
getCommand("viaversion").setExecutor(commandHandler = new BukkitCommandHandler());
|
getCommand("viaversion").setExecutor(commandHandler = new BukkitCommandHandler());
|
||||||
getCommand("viaversion").setTabCompleter(commandHandler);
|
getCommand("viaversion").setTabCompleter(commandHandler);
|
||||||
@ -189,6 +189,16 @@ public class ViaVersionPlugin extends JavaPlugin implements ViaPlatform {
|
|||||||
getServer().getScheduler().runTask(this, runnable);
|
getServer().getScheduler().runTask(this, runnable);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ViaCommandSender[] getOnlinePlayers() {
|
||||||
|
ViaCommandSender[] array = new ViaCommandSender[Bukkit.getOnlinePlayers().size()];
|
||||||
|
int i = 0;
|
||||||
|
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||||
|
array[i++] = new BukkitCommandSender(player);
|
||||||
|
}
|
||||||
|
return array;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void sendMessage(UUID uuid, String message) {
|
public void sendMessage(UUID uuid, String message) {
|
||||||
Player player = Bukkit.getPlayer(uuid);
|
Player player = Bukkit.getPlayer(uuid);
|
||||||
|
@ -26,7 +26,7 @@ import java.util.UUID;
|
|||||||
|
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public class BukkitViaAPI implements ViaAPI<Player>, ViaVersionAPI {
|
public class BukkitViaAPI implements ViaAPI<Player>, ViaVersionAPI {
|
||||||
public ViaVersionPlugin plugin;
|
private ViaVersionPlugin plugin;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getPlayerVersion(@NonNull Player player) {
|
public int getPlayerVersion(@NonNull Player player) {
|
||||||
|
51
bukkit/src/main/java/us/myles/ViaVersion/bukkit/BukkitViaLoader.java
Normale Datei
51
bukkit/src/main/java/us/myles/ViaVersion/bukkit/BukkitViaLoader.java
Normale Datei
@ -0,0 +1,51 @@
|
|||||||
|
package us.myles.ViaVersion.bukkit;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.player.PlayerQuitEvent;
|
||||||
|
import us.myles.ViaVersion.ViaVersionPlugin;
|
||||||
|
import us.myles.ViaVersion.api.Via;
|
||||||
|
import us.myles.ViaVersion.api.platform.ViaPlatformLoader;
|
||||||
|
import us.myles.ViaVersion.listeners.UpdateListener;
|
||||||
|
import us.myles.ViaVersion.listeners.protocol1_9to1_8.*;
|
||||||
|
import us.myles.ViaVersion.protocols.protocol1_9to1_8.ViaIdleThread;
|
||||||
|
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class BukkitViaLoader implements ViaPlatformLoader {
|
||||||
|
private ViaVersionPlugin plugin;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void load() {
|
||||||
|
// Update Listener
|
||||||
|
Bukkit.getPluginManager().registerEvents(new UpdateListener(), plugin);
|
||||||
|
|
||||||
|
/* Base Protocol */
|
||||||
|
final ViaVersionPlugin plugin = (ViaVersionPlugin) Bukkit.getPluginManager().getPlugin("ViaVersion");
|
||||||
|
|
||||||
|
Bukkit.getPluginManager().registerEvents(new Listener() {
|
||||||
|
@EventHandler
|
||||||
|
public void onPlayerQuit(PlayerQuitEvent e) {
|
||||||
|
Via.getManager().removePortedClient(e.getPlayer().getUniqueId());
|
||||||
|
}
|
||||||
|
}, plugin);
|
||||||
|
|
||||||
|
/* 1.9 client to 1.8 server */
|
||||||
|
new ArmorListener(plugin).register();
|
||||||
|
new CommandBlockListener(plugin).register();
|
||||||
|
new DeathListener(plugin).register();
|
||||||
|
new BlockListener(plugin).register();
|
||||||
|
|
||||||
|
if (Bukkit.getVersion().toLowerCase().contains("paper") || Bukkit.getVersion().toLowerCase().contains("taco")) {
|
||||||
|
plugin.getLogger().info("Enabling PaperSpigot/TacoSpigot patch: Fixes block placement.");
|
||||||
|
new PaperPatch(plugin).register();
|
||||||
|
}
|
||||||
|
if (plugin.getConf().isStimulatePlayerTick())
|
||||||
|
new ViaIdleThread(Via.getManager().getPortedPlayers()).runTaskTimer(plugin, 1L, 1L); // Updates player's idle status
|
||||||
|
if (plugin.getConf().isItemCache()) {
|
||||||
|
new HandItemCache().runTaskTimerAsynchronously(plugin, 2L, 2L); // Updates player's items :)
|
||||||
|
HandItemCache.CACHE = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -7,6 +7,7 @@ import us.myles.ViaVersion.api.command.ViaVersionCommand;
|
|||||||
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;
|
||||||
|
import us.myles.ViaVersion.api.platform.ViaPlatformLoader;
|
||||||
import us.myles.ViaVersion.api.protocol.ProtocolRegistry;
|
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;
|
||||||
@ -26,6 +27,7 @@ public class ViaManager {
|
|||||||
// Internals
|
// Internals
|
||||||
private ViaInjector injector;
|
private ViaInjector injector;
|
||||||
private ViaCommandHandler commandHandler;
|
private ViaCommandHandler commandHandler;
|
||||||
|
private ViaPlatformLoader loader;
|
||||||
|
|
||||||
public ViaManager(ViaPlatform platform) {
|
public ViaManager(ViaPlatform platform) {
|
||||||
this.platform = platform;
|
this.platform = platform;
|
||||||
|
@ -0,0 +1,5 @@
|
|||||||
|
package us.myles.ViaVersion.api.platform;
|
||||||
|
|
||||||
|
public interface ViaPlatformLoader {
|
||||||
|
public void load();
|
||||||
|
}
|
@ -0,0 +1,4 @@
|
|||||||
|
package us.myles.ViaVersion.api.platform.providers;
|
||||||
|
|
||||||
|
public interface Provider {
|
||||||
|
}
|
@ -0,0 +1,37 @@
|
|||||||
|
package us.myles.ViaVersion.api.platform.providers;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class ViaProviders {
|
||||||
|
private Map<Class<? extends Provider>, Provider> providers = new HashMap<>();
|
||||||
|
private List<Class<? extends Provider>> lonelyProviders = new ArrayList<>();
|
||||||
|
|
||||||
|
public void require(Class<? extends Provider> provider) {
|
||||||
|
lonelyProviders.add(provider);
|
||||||
|
}
|
||||||
|
|
||||||
|
public <T extends Provider> void register(Class<T> provider, T value) {
|
||||||
|
providers.put(provider, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public <T extends Provider> void use(Class<T> provider, T value) {
|
||||||
|
if (lonelyProviders.contains(provider)) {
|
||||||
|
lonelyProviders.remove(provider);
|
||||||
|
}
|
||||||
|
providers.put(provider, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public <T extends Provider> T get(Class<T> provider) {
|
||||||
|
if (providers.containsKey(provider)) {
|
||||||
|
return (T) providers.get(provider);
|
||||||
|
} else {
|
||||||
|
if (lonelyProviders.contains(provider)) {
|
||||||
|
throw new IllegalStateException("There was no provider for " + provider + ", one is required!");
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -9,10 +9,6 @@ import io.netty.util.concurrent.Future;
|
|||||||
import io.netty.util.concurrent.GenericFutureListener;
|
import io.netty.util.concurrent.GenericFutureListener;
|
||||||
import net.md_5.bungee.api.ChatColor;
|
import net.md_5.bungee.api.ChatColor;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
import org.bukkit.event.EventHandler;
|
|
||||||
import org.bukkit.event.Listener;
|
|
||||||
import org.bukkit.event.player.PlayerQuitEvent;
|
|
||||||
import us.myles.ViaVersion.ViaVersionPlugin;
|
|
||||||
import us.myles.ViaVersion.api.PacketWrapper;
|
import us.myles.ViaVersion.api.PacketWrapper;
|
||||||
import us.myles.ViaVersion.api.Pair;
|
import us.myles.ViaVersion.api.Pair;
|
||||||
import us.myles.ViaVersion.api.Via;
|
import us.myles.ViaVersion.api.Via;
|
||||||
@ -204,14 +200,7 @@ public class BaseProtocol extends Protocol {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void registerListeners() {
|
protected void registerListeners() {
|
||||||
final ViaVersionPlugin plugin = (ViaVersionPlugin) Bukkit.getPluginManager().getPlugin("ViaVersion");
|
|
||||||
|
|
||||||
Bukkit.getPluginManager().registerEvents(new Listener() {
|
|
||||||
@EventHandler
|
|
||||||
public void onPlayerQuit(PlayerQuitEvent e) {
|
|
||||||
plugin.removePortedClient(e.getPlayer().getUniqueId());
|
|
||||||
}
|
|
||||||
}, plugin);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -3,8 +3,6 @@ package us.myles.ViaVersion.protocols.protocol1_9to1_8;
|
|||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import com.google.gson.GsonBuilder;
|
import com.google.gson.GsonBuilder;
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import us.myles.ViaVersion.ViaVersionPlugin;
|
|
||||||
import us.myles.ViaVersion.api.PacketWrapper;
|
import us.myles.ViaVersion.api.PacketWrapper;
|
||||||
import us.myles.ViaVersion.api.Via;
|
import us.myles.ViaVersion.api.Via;
|
||||||
import us.myles.ViaVersion.api.data.UserConnection;
|
import us.myles.ViaVersion.api.data.UserConnection;
|
||||||
@ -103,23 +101,7 @@ public class Protocol1_9TO1_8 extends Protocol {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void registerListeners() {
|
protected void registerListeners() {
|
||||||
ViaVersionPlugin plugin = (ViaVersionPlugin) Bukkit.getPluginManager().getPlugin("ViaVersion");
|
|
||||||
|
|
||||||
new ArmorListener(plugin).register();
|
|
||||||
new CommandBlockListener(plugin).register();
|
|
||||||
new DeathListener(plugin).register();
|
|
||||||
new BlockListener(plugin).register();
|
|
||||||
|
|
||||||
if (Bukkit.getVersion().toLowerCase().contains("paper") || Bukkit.getVersion().toLowerCase().contains("taco")) {
|
|
||||||
plugin.getLogger().info("Enabling PaperSpigot/TacoSpigot patch: Fixes block placement.");
|
|
||||||
new PaperPatch(plugin).register();
|
|
||||||
}
|
|
||||||
if (plugin.getConf().isStimulatePlayerTick())
|
|
||||||
new ViaIdleThread(plugin.getPortedPlayers()).runTaskTimer(plugin, 1L, 1L); // Updates player's idle status
|
|
||||||
if (plugin.getConf().isItemCache()) {
|
|
||||||
new HandItemCache().runTaskTimerAsynchronously(plugin, 2L, 2L); // Updates player's items :)
|
|
||||||
HandItemCache.CACHE = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren