3
0
Mirror von https://github.com/ViaVersion/ViaVersion.git synchronisiert 2024-12-24 23:30:15 +01:00

Merge pull request #844 from creeper123123321/platform-and-sponge-changes

Platform and Sponge changes
Dieser Commit ist enthalten in:
Myles 2018-07-02 22:50:12 +01:00 committet von GitHub
Commit 2c62cc37e7
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 4AEE18F83AFDEB23
10 geänderte Dateien mit 231 neuen und 170 gelöschten Zeilen

Datei anzeigen

@ -1,10 +1,11 @@
package us.myles.ViaVersion.bukkit.platform; package us.myles.ViaVersion.bukkit.platform;
import lombok.AllArgsConstructor;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.HandlerList;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.scheduler.BukkitTask;
import us.myles.ViaVersion.ViaVersionPlugin; import us.myles.ViaVersion.ViaVersionPlugin;
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;
@ -21,43 +22,60 @@ import us.myles.ViaVersion.protocols.protocol1_9to1_8.providers.BulkChunkTransla
import us.myles.ViaVersion.protocols.protocol1_9to1_8.providers.HandItemProvider; import us.myles.ViaVersion.protocols.protocol1_9to1_8.providers.HandItemProvider;
import us.myles.ViaVersion.protocols.protocol1_9to1_8.providers.MovementTransmitterProvider; import us.myles.ViaVersion.protocols.protocol1_9to1_8.providers.MovementTransmitterProvider;
import java.util.HashSet;
import java.util.Set;
import java.util.UUID; import java.util.UUID;
import java.util.concurrent.Callable; import java.util.concurrent.Callable;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
@AllArgsConstructor
public class BukkitViaLoader implements ViaPlatformLoader { public class BukkitViaLoader implements ViaPlatformLoader {
private ViaVersionPlugin plugin; private ViaVersionPlugin plugin;
private Set<Listener> listeners = new HashSet<>();
private Set<BukkitTask> tasks = new HashSet<>();
public BukkitViaLoader(ViaVersionPlugin plugin) {
this.plugin = plugin;
}
public void registerListener(Listener listener) {
Bukkit.getPluginManager().registerEvents(storeListener(listener), plugin);
}
public <T extends Listener> T storeListener(T listener) {
listeners.add(listener);
return listener;
}
@Override @Override
public void load() { public void load() {
// Update Listener // Update Listener
Bukkit.getPluginManager().registerEvents(new UpdateListener(), plugin); registerListener(new UpdateListener());
/* Base Protocol */ /* Base Protocol */
final ViaVersionPlugin plugin = (ViaVersionPlugin) Bukkit.getPluginManager().getPlugin("ViaVersion"); final ViaVersionPlugin plugin = (ViaVersionPlugin) Bukkit.getPluginManager().getPlugin("ViaVersion");
Bukkit.getPluginManager().registerEvents(new Listener() { registerListener(new Listener() {
@EventHandler @EventHandler
public void onPlayerQuit(PlayerQuitEvent e) { public void onPlayerQuit(PlayerQuitEvent e) {
Via.getManager().removePortedClient(e.getPlayer().getUniqueId()); Via.getManager().removePortedClient(e.getPlayer().getUniqueId());
} }
}, plugin); });
/* 1.9 client to 1.8 server */ /* 1.9 client to 1.8 server */
new ArmorListener(plugin).register(); storeListener(new ArmorListener(plugin)).register();
new DeathListener(plugin).register(); storeListener(new DeathListener(plugin)).register();
new BlockListener(plugin).register(); storeListener(new BlockListener(plugin)).register();
if (Bukkit.getVersion().toLowerCase().contains("paper") if (Bukkit.getVersion().toLowerCase().contains("paper")
|| Bukkit.getVersion().toLowerCase().contains("taco") || Bukkit.getVersion().toLowerCase().contains("taco")
|| Bukkit.getVersion().toLowerCase().contains("torch")) { || Bukkit.getVersion().toLowerCase().contains("torch")) {
plugin.getLogger().info("Enabling PaperSpigot/TacoSpigot/Torch patch: Fixes block placement."); plugin.getLogger().info("Enabling PaperSpigot/TacoSpigot/Torch patch: Fixes block placement.");
new PaperPatch(plugin).register(); storeListener(new PaperPatch(plugin)).register();
} }
if (plugin.getConf().isItemCache()) { if (plugin.getConf().isItemCache()) {
new HandItemCache().runTaskTimerAsynchronously(plugin, 2L, 2L); // Updates player's items :) tasks.add(new HandItemCache().runTaskTimerAsynchronously(plugin, 2L, 2L)); // Updates player's items :)
HandItemCache.CACHE = true; HandItemCache.CACHE = true;
} }
@ -95,4 +113,16 @@ public class BukkitViaLoader implements ViaPlatformLoader {
}); });
} }
@Override
public void unload() {
for (Listener listener : listeners) {
HandlerList.unregisterAll(listener);
}
listeners.clear();
for (BukkitTask task : tasks) {
task.cancel();
}
tasks.clear();
}
} }

Datei anzeigen

@ -1,7 +1,8 @@
package us.myles.ViaVersion.bungee.platform; package us.myles.ViaVersion.bungee.platform;
import lombok.AllArgsConstructor;
import net.md_5.bungee.api.ProxyServer; import net.md_5.bungee.api.ProxyServer;
import net.md_5.bungee.api.plugin.Listener;
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;
@ -19,20 +20,33 @@ import us.myles.ViaVersion.protocols.protocol1_9to1_8.providers.BossBarProvider;
import us.myles.ViaVersion.protocols.protocol1_9to1_8.providers.EntityIdProvider; import us.myles.ViaVersion.protocols.protocol1_9to1_8.providers.EntityIdProvider;
import us.myles.ViaVersion.protocols.protocol1_9to1_8.providers.MovementTransmitterProvider; import us.myles.ViaVersion.protocols.protocol1_9to1_8.providers.MovementTransmitterProvider;
import java.util.HashSet;
import java.util.Set;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
@AllArgsConstructor
public class BungeeViaLoader implements ViaPlatformLoader { public class BungeeViaLoader implements ViaPlatformLoader {
private BungeePlugin plugin; private BungeePlugin plugin;
private Set<Listener> listeners = new HashSet<>();
private Set<ScheduledTask> tasks = new HashSet<>();
public BungeeViaLoader(BungeePlugin plugin) {
this.plugin = plugin;
}
private void registerListener(Listener listener) {
listeners.add(listener);
ProxyServer.getInstance().getPluginManager().registerListener(plugin, listener);
}
@Override @Override
public void load() { public void load() {
// Listeners // Listeners
ProxyServer.getInstance().getPluginManager().registerListener(plugin, plugin); registerListener(plugin);
ProxyServer.getInstance().getPluginManager().registerListener(plugin, new UpdateListener()); registerListener(new UpdateListener());
ProxyServer.getInstance().getPluginManager().registerListener(plugin, new BungeeServerHandler()); registerListener(new BungeeServerHandler());
ProxyServer.getInstance().getPluginManager().registerListener(plugin, new MainHandPatch()); registerListener(new MainHandPatch());
ProxyServer.getInstance().getPluginManager().registerListener(plugin, new ElytraPatch()); registerListener(new ElytraPatch());
// Providers // Providers
Via.getManager().getProviders().use(MovementTransmitterProvider.class, new BungeeMovementTransmitter()); Via.getManager().getProviders().use(MovementTransmitterProvider.class, new BungeeMovementTransmitter());
@ -41,7 +55,24 @@ public class BungeeViaLoader implements ViaPlatformLoader {
Via.getManager().getProviders().use(BossBarProvider.class, new BungeeBossBarProvider()); Via.getManager().getProviders().use(BossBarProvider.class, new BungeeBossBarProvider());
if (plugin.getConf().getBungeePingInterval() > 0) { if (plugin.getConf().getBungeePingInterval() > 0) {
plugin.getProxy().getScheduler().schedule(plugin, new ProtocolDetectorService(plugin), 0, plugin.getConf().getBungeePingInterval(), TimeUnit.SECONDS); tasks.add(plugin.getProxy().getScheduler().schedule(
plugin,
new ProtocolDetectorService(plugin),
0, plugin.getConf().getBungeePingInterval(),
TimeUnit.SECONDS
));
} }
} }
@Override
public void unload() {
for (Listener listener : listeners) {
ProxyServer.getInstance().getPluginManager().unregisterListener(listener);
}
listeners.clear();
for (ScheduledTask task : tasks) {
task.cancel();
}
tasks.clear();
}
} }

Datei anzeigen

@ -102,6 +102,9 @@ public class ViaManager {
getPlatform().getLogger().severe("ViaVersion failed to uninject:"); getPlatform().getLogger().severe("ViaVersion failed to uninject:");
e.printStackTrace(); e.printStackTrace();
} }
// Unload
loader.unload();
} }
public void addPortedClient(UserConnection info) { public void addPortedClient(UserConnection info) {

Datei anzeigen

@ -5,4 +5,6 @@ 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.
*/ */
void load(); void load();
void unload();
} }

Datei anzeigen

@ -2,14 +2,19 @@ package us.myles.ViaVersion;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import com.google.inject.Inject; import com.google.inject.Inject;
import lombok.Getter;
import net.md_5.bungee.api.chat.TextComponent;
import net.md_5.bungee.chat.ComponentSerializer;
import org.spongepowered.api.Game; import org.spongepowered.api.Game;
import org.spongepowered.api.config.DefaultConfig; import org.spongepowered.api.config.DefaultConfig;
import org.spongepowered.api.entity.living.player.Player; import org.spongepowered.api.entity.living.player.Player;
import org.spongepowered.api.event.Listener; import org.spongepowered.api.event.Listener;
import org.spongepowered.api.event.game.state.GameAboutToStartServerEvent; import org.spongepowered.api.event.game.state.GameAboutToStartServerEvent;
import org.spongepowered.api.event.game.state.GameInitializationEvent;
import org.spongepowered.api.event.game.state.GameStoppingServerEvent;
import org.spongepowered.api.plugin.Plugin; import org.spongepowered.api.plugin.Plugin;
import org.spongepowered.api.plugin.PluginContainer; import org.spongepowered.api.plugin.PluginContainer;
import org.spongepowered.api.scheduler.SpongeExecutorService; import org.spongepowered.api.scheduler.Task;
import org.spongepowered.api.text.serializer.TextSerializers; import org.spongepowered.api.text.serializer.TextSerializers;
import us.myles.ViaVersion.api.Via; import us.myles.ViaVersion.api.Via;
import us.myles.ViaVersion.api.ViaAPI; import us.myles.ViaVersion.api.ViaAPI;
@ -37,8 +42,7 @@ import java.util.logging.Logger;
name = "ViaVersion", name = "ViaVersion",
version = VersionInfo.VERSION, version = VersionInfo.VERSION,
authors = {"_MylesC", "Matsv"}, authors = {"_MylesC", "Matsv"},
description = "Allow newer Minecraft versions to connect to an older server version.", description = "Allow newer Minecraft versions to connect to an older server version."
dependencies = {}
) )
public class SpongePlugin implements ViaPlatform { public class SpongePlugin implements ViaPlatform {
@Inject @Inject
@ -51,23 +55,23 @@ public class SpongePlugin implements ViaPlatform {
@DefaultConfig(sharedRoot = false) @DefaultConfig(sharedRoot = false)
private File defaultConfig; private File defaultConfig;
@Getter
private SpongeViaAPI api = new SpongeViaAPI(); private SpongeViaAPI api = new SpongeViaAPI();
private SpongeExecutorService asyncExecutor; @Getter
private SpongeExecutorService syncExecutor;
private SpongeConfigAPI conf; private SpongeConfigAPI conf;
@Getter
private Logger logger; private Logger logger;
@Listener @Listener
public void onServerStart(GameAboutToStartServerEvent event) { public void onGameStart(GameInitializationEvent event) {
// Setup Logger // Setup Logger
logger = new LoggerWrapper(container.getLogger()); logger = new LoggerWrapper(container.getLogger());
// Setup Plugin // Setup Plugin
conf = new SpongeConfigAPI(container, defaultConfig.getParentFile()); conf = new SpongeConfigAPI(container, defaultConfig.getParentFile());
syncExecutor = game.getScheduler().createSyncExecutor(this);
asyncExecutor = game.getScheduler().createAsyncExecutor(this);
SpongeCommandHandler commandHandler = new SpongeCommandHandler(); SpongeCommandHandler commandHandler = new SpongeCommandHandler();
game.getCommandManager().register(this, commandHandler, Arrays.asList("viaversion", "viaver", "vvsponge")); game.getCommandManager().register(this, commandHandler, "viaversion", "viaver", "vvsponge");
getLogger().info("ViaVersion " + getPluginVersion() + " is now loaded, injecting!"); getLogger().info("ViaVersion " + getPluginVersion() + " is now loaded!");
// Init platform // Init platform
Via.init(ViaManager.builder() Via.init(ViaManager.builder()
.platform(this) .platform(this)
@ -75,14 +79,18 @@ public class SpongePlugin implements ViaPlatform {
.injector(new SpongeViaInjector()) .injector(new SpongeViaInjector())
.loader(new SpongeViaLoader(this)) .loader(new SpongeViaLoader(this))
.build()); .build());
}
@Listener
public void onServerStart(GameAboutToStartServerEvent event) {
// Inject! // Inject!
logger.info("ViaVersion is injecting!");
Via.getManager().init(); Via.getManager().init();
} }
@Override @Listener
public Logger getLogger() { public void onServerStop(GameStoppingServerEvent event) {
return logger; Via.getManager().destroy();
} }
@Override @Override
@ -102,26 +110,41 @@ public class SpongePlugin implements ViaPlatform {
@Override @Override
public TaskId runAsync(Runnable runnable) { public TaskId runAsync(Runnable runnable) {
asyncExecutor.execute(runnable); return new SpongeTaskId(
return new SpongeTaskId(null); Task.builder()
.execute(runnable)
.async()
.submit(this)
);
} }
@Override @Override
public TaskId runSync(Runnable runnable) { public TaskId runSync(Runnable runnable) {
syncExecutor.execute(runnable); return new SpongeTaskId(
return new SpongeTaskId(null); Task.builder()
.execute(runnable)
.submit(this)
);
} }
@Override @Override
public TaskId runSync(Runnable runnable, Long ticks) { public TaskId runSync(Runnable runnable, Long ticks) {
Long delay = ticks * 50L; return new SpongeTaskId(
return new SpongeTaskId(syncExecutor.schedule(runnable, delay, TimeUnit.MILLISECONDS).getTask()); Task.builder()
.execute(runnable)
.delayTicks(ticks)
.submit(this)
);
} }
@Override @Override
public TaskId runRepeatingSync(Runnable runnable, Long ticks) { public TaskId runRepeatingSync(Runnable runnable, Long ticks) {
Long time = ticks * 50L; return new SpongeTaskId(
return new SpongeTaskId(syncExecutor.scheduleAtFixedRate(runnable, time, time, TimeUnit.MILLISECONDS).getTask()); Task.builder()
.execute(runnable)
.intervalTicks(ticks)
.submit(this)
);
} }
@Override @Override
@ -145,21 +168,24 @@ public class SpongePlugin implements ViaPlatform {
@Override @Override
public void sendMessage(UUID uuid, String message) { public void sendMessage(UUID uuid, String message) {
for (Player player : game.getServer().getOnlinePlayers()) { game.getServer().getPlayer(uuid)
if (player.getUniqueId().equals(uuid)) .ifPresent(player ->
player.sendMessage(TextSerializers.LEGACY_FORMATTING_CODE.deserialize(message)); player.sendMessage(
} TextSerializers.JSON.deserialize(
ComponentSerializer.toString(
TextComponent.fromLegacyText(message) // Hacky way to fix links
)
)
)
);
} }
@Override @Override
public boolean kickPlayer(UUID uuid, String message) { public boolean kickPlayer(UUID uuid, String message) {
for (Player player : game.getServer().getOnlinePlayers()) { return game.getServer().getPlayer(uuid).map(player -> {
if (player.getUniqueId().equals(uuid)) { player.kick(TextSerializers.LEGACY_FORMATTING_CODE.deserialize(message));
player.kick(TextSerializers.LEGACY_FORMATTING_CODE.deserialize(message)); return true;
return true; }).orElse(false);
}
}
return false;
} }
@Override @Override
@ -167,16 +193,6 @@ public class SpongePlugin implements ViaPlatform {
return true; return true;
} }
@Override
public ViaAPI getApi() {
return api;
}
@Override
public SpongeConfigAPI getConf() {
return conf;
}
@Override @Override
public ConfigurationProvider getConfigurationProvider() { public ConfigurationProvider getConfigurationProvider() {
return conf; return conf;

Datei anzeigen

@ -1,9 +1,11 @@
package us.myles.ViaVersion.sponge.commands; package us.myles.ViaVersion.sponge.commands;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import net.md_5.bungee.api.chat.TextComponent;
import net.md_5.bungee.chat.ComponentSerializer;
import org.spongepowered.api.command.CommandSource; import org.spongepowered.api.command.CommandSource;
import org.spongepowered.api.entity.living.player.Player;
import org.spongepowered.api.text.serializer.TextSerializers; import org.spongepowered.api.text.serializer.TextSerializers;
import org.spongepowered.api.util.Identifiable;
import us.myles.ViaVersion.api.command.ViaCommandSender; import us.myles.ViaVersion.api.command.ViaCommandSender;
import java.util.UUID; import java.util.UUID;
@ -19,16 +21,23 @@ public class SpongeCommandSender implements ViaCommandSender {
@Override @Override
public void sendMessage(String msg) { public void sendMessage(String msg) {
source.sendMessage(TextSerializers.LEGACY_FORMATTING_CODE.deserialize(msg)); source.sendMessage(
TextSerializers.JSON.deserialize(
ComponentSerializer.toString(
TextComponent.fromLegacyText(msg) // Hacky way to fix links
)
)
);
} }
@Override @Override
public UUID getUUID() { public UUID getUUID() {
if (source instanceof Player) { if (source instanceof Identifiable) {
return ((Player) source).getUniqueId(); return ((Identifiable) source).getUniqueId();
} else { } else {
return UUID.fromString(getName()); return UUID.fromString(getName());
} }
} }
@Override @Override

Datei anzeigen

@ -5,18 +5,20 @@ import io.netty.channel.ChannelInitializer;
import io.netty.channel.socket.SocketChannel; import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.ByteToMessageDecoder; import io.netty.handler.codec.ByteToMessageDecoder;
import io.netty.handler.codec.MessageToByteEncoder; import io.netty.handler.codec.MessageToByteEncoder;
import lombok.Getter;
import us.myles.ViaVersion.api.data.UserConnection; import us.myles.ViaVersion.api.data.UserConnection;
import us.myles.ViaVersion.api.protocol.ProtocolPipeline; import us.myles.ViaVersion.api.protocol.ProtocolPipeline;
import us.myles.ViaVersion.api.protocol.ProtocolRegistry; import us.myles.ViaVersion.api.protocol.ProtocolRegistry;
import java.lang.reflect.Method; import java.lang.reflect.Method;
public class SpongeChannelInitializer extends ChannelInitializer<SocketChannel> { public class SpongeChannelInitializer extends ChannelInitializer<Channel> {
private final ChannelInitializer<SocketChannel> original; @Getter
private final ChannelInitializer<Channel> original;
private Method method; private Method method;
public SpongeChannelInitializer(ChannelInitializer<SocketChannel> oldInit) { public SpongeChannelInitializer(ChannelInitializer<Channel> oldInit) {
this.original = oldInit; this.original = oldInit;
try { try {
this.method = ChannelInitializer.class.getDeclaredMethod("initChannel", Channel.class); this.method = ChannelInitializer.class.getDeclaredMethod("initChannel", Channel.class);
@ -26,29 +28,27 @@ public class SpongeChannelInitializer extends ChannelInitializer<SocketChannel>
} }
} }
public ChannelInitializer<SocketChannel> getOriginal() {
return original;
}
@Override @Override
protected void initChannel(SocketChannel socketChannel) throws Exception { protected void initChannel(Channel channel) throws Exception {
// Ensure ViaVersion is loaded // Ensure ViaVersion is loaded
if (ProtocolRegistry.SERVER_PROTOCOL != -1) { if (ProtocolRegistry.SERVER_PROTOCOL != -1
UserConnection info = new UserConnection(socketChannel); && channel instanceof SocketChannel) { // channel can be LocalChannel on internal server
UserConnection info = new UserConnection((SocketChannel) channel);
// init protocol // init protocol
new ProtocolPipeline(info); new ProtocolPipeline(info);
// Add originals // Add originals
this.method.invoke(this.original, socketChannel); this.method.invoke(this.original, channel);
// Add our transformers // Add our transformers
MessageToByteEncoder encoder = new SpongeEncodeHandler(info, (MessageToByteEncoder) socketChannel.pipeline().get("encoder")); MessageToByteEncoder encoder = new SpongeEncodeHandler(info, (MessageToByteEncoder) channel.pipeline().get("encoder"));
ByteToMessageDecoder decoder = new SpongeDecodeHandler(info, (ByteToMessageDecoder) socketChannel.pipeline().get("decoder")); ByteToMessageDecoder decoder = new SpongeDecodeHandler(info, (ByteToMessageDecoder) channel.pipeline().get("decoder"));
SpongePacketHandler chunkHandler = new SpongePacketHandler(info); SpongePacketHandler chunkHandler = new SpongePacketHandler(info);
socketChannel.pipeline().replace("encoder", "encoder", encoder); channel.pipeline().replace("encoder", "encoder", encoder);
socketChannel.pipeline().replace("decoder", "decoder", decoder); channel.pipeline().replace("decoder", "decoder", decoder);
socketChannel.pipeline().addAfter("packet_handler", "viaversion_packet_handler", chunkHandler); channel.pipeline().addAfter("packet_handler", "viaversion_packet_handler", chunkHandler);
} else { } else {
this.method.invoke(this.original, socketChannel); this.method.invoke(this.original, channel);
} }
} }
} }

Datei anzeigen

@ -1,9 +1,9 @@
package us.myles.ViaVersion.sponge.platform; package us.myles.ViaVersion.sponge.platform;
import io.netty.channel.Channel;
import io.netty.channel.ChannelFuture; import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelHandler; import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelInitializer; import io.netty.channel.ChannelInitializer;
import io.netty.channel.socket.SocketChannel;
import org.spongepowered.api.MinecraftVersion; import org.spongepowered.api.MinecraftVersion;
import org.spongepowered.api.Sponge; import org.spongepowered.api.Sponge;
import us.myles.ViaVersion.api.Pair; import us.myles.ViaVersion.api.Pair;
@ -86,7 +86,7 @@ public class SpongeViaInjector implements ViaInjector {
bootstrapAcceptor = future.channel().pipeline().first(); bootstrapAcceptor = future.channel().pipeline().first();
} }
try { try {
ChannelInitializer<SocketChannel> oldInit = ReflectionUtil.get(bootstrapAcceptor, "childHandler", ChannelInitializer.class); ChannelInitializer<Channel> oldInit = ReflectionUtil.get(bootstrapAcceptor, "childHandler", ChannelInitializer.class);
ChannelInitializer newInit = new SpongeChannelInitializer(oldInit); ChannelInitializer newInit = new SpongeChannelInitializer(oldInit);
ReflectionUtil.set(bootstrapAcceptor, "childHandler", newInit); ReflectionUtil.set(bootstrapAcceptor, "childHandler", newInit);
@ -111,7 +111,7 @@ public class SpongeViaInjector implements ViaInjector {
for (String name : names) { for (String name : names) {
ChannelHandler handler = future.channel().pipeline().get(name); ChannelHandler handler = future.channel().pipeline().get(name);
try { try {
ChannelInitializer<SocketChannel> oldInit = ReflectionUtil.get(handler, "childHandler", ChannelInitializer.class); ChannelInitializer<Channel> oldInit = ReflectionUtil.get(handler, "childHandler", ChannelInitializer.class);
if (oldInit instanceof SpongeChannelInitializer) { if (oldInit instanceof SpongeChannelInitializer) {
bootstrapAcceptor = handler; bootstrapAcceptor = handler;
} }
@ -125,7 +125,7 @@ public class SpongeViaInjector implements ViaInjector {
} }
try { try {
ChannelInitializer<SocketChannel> oldInit = ReflectionUtil.get(bootstrapAcceptor, "childHandler", ChannelInitializer.class); ChannelInitializer<Channel> oldInit = ReflectionUtil.get(bootstrapAcceptor, "childHandler", ChannelInitializer.class);
if (oldInit instanceof SpongeChannelInitializer) { if (oldInit instanceof SpongeChannelInitializer) {
ReflectionUtil.set(bootstrapAcceptor, "childHandler", ((SpongeChannelInitializer) oldInit).getOriginal()); ReflectionUtil.set(bootstrapAcceptor, "childHandler", ((SpongeChannelInitializer) oldInit).getOriginal());
} }

Datei anzeigen

@ -1,11 +1,11 @@
package us.myles.ViaVersion.sponge.platform; package us.myles.ViaVersion.sponge.platform;
import lombok.AllArgsConstructor;
import org.spongepowered.api.Sponge; import org.spongepowered.api.Sponge;
import us.myles.ViaVersion.SpongePlugin; import us.myles.ViaVersion.SpongePlugin;
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;
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.ViaPlatformLoader; import us.myles.ViaVersion.api.platform.ViaPlatformLoader;
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;
@ -21,28 +21,47 @@ import us.myles.ViaVersion.sponge.listeners.protocol1_9to1_8.sponge5.Sponge5Armo
import us.myles.ViaVersion.sponge.providers.SpongeViaBulkChunkTranslator; import us.myles.ViaVersion.sponge.providers.SpongeViaBulkChunkTranslator;
import us.myles.ViaVersion.sponge.providers.SpongeViaMovementTransmitter; import us.myles.ViaVersion.sponge.providers.SpongeViaMovementTransmitter;
@AllArgsConstructor import java.util.HashSet;
import java.util.Set;
public class SpongeViaLoader implements ViaPlatformLoader { public class SpongeViaLoader implements ViaPlatformLoader {
private SpongePlugin plugin; private SpongePlugin plugin;
private Set<Object> listeners = new HashSet<>();
private Set<TaskId> tasks = new HashSet<>();
public SpongeViaLoader(SpongePlugin plugin) {
this.plugin = plugin;
}
private void registerListener(Object listener) {
Sponge.getEventManager().registerListeners(plugin, storeListener(listener));
}
private <T> T storeListener(T listener) {
listeners.add(listener);
return listener;
}
@Override @Override
public void load() { public void load() {
// Update Listener // Update Listener
Sponge.getEventManager().registerListeners(plugin, new UpdateListener()); registerListener(new UpdateListener());
/* Base Protocol */ /* Base Protocol */
Sponge.getEventManager().registerListeners(plugin, new ClientLeaveListener()); registerListener(new ClientLeaveListener());
/* 1.9 client to 1.8 server */ /* 1.9 client to 1.8 server */
try { try {
Class.forName("org.spongepowered.api.event.entity.DisplaceEntityEvent"); Class.forName("org.spongepowered.api.event.entity.DisplaceEntityEvent");
new Sponge4ArmorListener().register(); storeListener(new Sponge4ArmorListener()).register();
} catch (ClassNotFoundException e) { } catch (ClassNotFoundException e) {
new Sponge5ArmorListener(plugin).register(); storeListener(new Sponge5ArmorListener(plugin)).register();
} }
new DeathListener(plugin).register(); storeListener(new DeathListener(plugin)).register();
new BlockListener(plugin).register(); storeListener(new BlockListener(plugin)).register();
if (plugin.getConf().isItemCache()) { if (plugin.getConf().isItemCache()) {
Via.getPlatform().runRepeatingSync(new HandItemCache(), 2L); // Updates players items :) tasks.add(Via.getPlatform().runRepeatingSync(new HandItemCache(), 2L)); // Updates players items :)
HandItemCache.CACHE = true; HandItemCache.CACHE = true;
} }
@ -60,4 +79,11 @@ public class SpongeViaLoader implements ViaPlatformLoader {
} }
}); });
} }
}
public void unload() {
listeners.forEach(Sponge.getEventManager()::unregisterListeners);
listeners.clear();
tasks.forEach(Via.getPlatform()::cancelTask);
tasks.clear();
}
}

Datei anzeigen

@ -2,6 +2,7 @@ package us.myles.ViaVersion.sponge.util;
import org.slf4j.Logger; import org.slf4j.Logger;
import java.text.MessageFormat;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.LogRecord; import java.util.logging.LogRecord;
@ -20,106 +21,49 @@ public class LoggerWrapper extends java.util.logging.Logger {
@Override @Override
public void log(Level level, String msg) { public void log(Level level, String msg) {
if (level == Level.FINEST) { if (level == Level.FINE)
base.trace(msg);
return;
}
if (level == Level.FINE) {
base.debug(msg); base.debug(msg);
return; else if (level == Level.WARNING)
}
if (level == Level.WARNING) {
base.warn(msg); base.warn(msg);
return; else if (level == Level.SEVERE)
}
if (level == Level.SEVERE) {
base.error(msg); base.error(msg);
return; else if (level == Level.INFO)
}
if (level == Level.INFO) {
base.info(msg); base.info(msg);
return; else
} base.trace(msg);
base.trace(msg);
return;
} }
@Override @Override
public void log(Level level, String msg, Object param1) { public void log(Level level, String msg, Object param1) {
if (level == Level.FINEST) { if (level == Level.FINE)
base.trace(msg, param1);
return;
}
if (level == Level.FINE) {
base.debug(msg, param1); base.debug(msg, param1);
return; else if (level == Level.WARNING)
}
if (level == Level.WARNING) {
base.warn(msg, param1); base.warn(msg, param1);
return; else if (level == Level.SEVERE)
}
if (level == Level.SEVERE) {
base.error(msg, param1); base.error(msg, param1);
return; else if (level == Level.INFO)
}
if (level == Level.INFO) {
base.info(msg, param1); base.info(msg, param1);
return; else
} base.trace(msg, param1);
base.trace(msg, param1);
return;
} }
@Override @Override
public void log(Level level, String msg, Object[] params) { public void log(Level level, String msg, Object[] params) {
if (level == Level.FINEST) { log(level, MessageFormat.format(msg, params)); // workaround not formatting correctly
base.trace(msg, params);
return;
}
if (level == Level.FINE) {
base.debug(msg, params);
return;
}
if (level == Level.WARNING) {
base.warn(msg, params);
return;
}
if (level == Level.SEVERE) {
base.error(msg, params);
return;
}
if (level == Level.INFO) {
base.info(msg, params);
return;
}
base.trace(msg, params);
return;
} }
@Override @Override
public void log(Level level, String msg, Throwable params) { public void log(Level level, String msg, Throwable params) {
if (level == Level.FINEST) { if (level == Level.FINE)
base.trace(msg, params);
return;
}
if (level == Level.FINE) {
base.debug(msg, params); base.debug(msg, params);
return; else if (level == Level.WARNING)
}
if (level == Level.WARNING) {
base.warn(msg, params); base.warn(msg, params);
return; else if (level == Level.SEVERE)
}
if (level == Level.SEVERE) {
base.error(msg, params); base.error(msg, params);
return; else if (level == Level.INFO)
}
if (level == Level.INFO) {
base.info(msg, params); base.info(msg, params);
return; else
} base.trace(msg, params);
base.trace(msg, params);
return;
} }
} }