From 7d23b12f85765f9711fa053e84d7383711347e07 Mon Sep 17 00:00:00 2001 From: Matsv Date: Sun, 2 Oct 2016 21:35:54 +0200 Subject: [PATCH] Implement the UpdateListener for Bungee --- .../java/us/myles/ViaVersion/BungeePlugin.java | 7 +++---- .../bungee/listeners/UpdateListener.java | 18 ++++++++++++++++++ .../bungee/platform/BungeeViaLoader.java | 3 +++ 3 files changed, 24 insertions(+), 4 deletions(-) create mode 100644 bungee/src/main/java/us/myles/ViaVersion/bungee/listeners/UpdateListener.java diff --git a/bungee/src/main/java/us/myles/ViaVersion/BungeePlugin.java b/bungee/src/main/java/us/myles/ViaVersion/BungeePlugin.java index 96144322d..544f4936a 100644 --- a/bungee/src/main/java/us/myles/ViaVersion/BungeePlugin.java +++ b/bungee/src/main/java/us/myles/ViaVersion/BungeePlugin.java @@ -12,7 +12,6 @@ import net.md_5.bungee.event.EventHandler; import us.myles.ViaVersion.api.Pair; import us.myles.ViaVersion.api.Via; import us.myles.ViaVersion.api.ViaAPI; -import us.myles.ViaVersion.api.ViaVersionConfig; import us.myles.ViaVersion.api.command.ViaCommandSender; import us.myles.ViaVersion.api.configuration.ConfigurationProvider; import us.myles.ViaVersion.api.data.UserConnection; @@ -83,7 +82,7 @@ public class BungeePlugin extends Plugin implements ViaPlatform, Listener { @Override public TaskId runSync(Runnable runnable) { - return new BungeeTaskId(getProxy().getScheduler().runAsync(this, runnable).getId()); + return runAsync(runnable); } @Override @@ -112,13 +111,13 @@ public class BungeePlugin extends Plugin implements ViaPlatform, Listener { @Override public void sendMessage(UUID uuid, String message) { - getProxy().getPlayer(uuid).sendMessage(new TextComponent(message)); + getProxy().getPlayer(uuid).sendMessage(TextComponent.fromLegacyText(message)); } @Override public boolean kickPlayer(UUID uuid, String message) { if (getProxy().getPlayer(uuid) != null) { - getProxy().getPlayer(uuid).disconnect(new TextComponent(message)); + getProxy().getPlayer(uuid).disconnect(TextComponent.fromLegacyText(message)); return true; } return false; diff --git a/bungee/src/main/java/us/myles/ViaVersion/bungee/listeners/UpdateListener.java b/bungee/src/main/java/us/myles/ViaVersion/bungee/listeners/UpdateListener.java new file mode 100644 index 000000000..b27ba57e8 --- /dev/null +++ b/bungee/src/main/java/us/myles/ViaVersion/bungee/listeners/UpdateListener.java @@ -0,0 +1,18 @@ +package us.myles.ViaVersion.bungee.listeners; + +import net.md_5.bungee.api.event.PostLoginEvent; +import net.md_5.bungee.api.plugin.Listener; +import net.md_5.bungee.event.EventHandler; +import us.myles.ViaVersion.api.Via; +import us.myles.ViaVersion.update.UpdateUtil; + +public class UpdateListener implements Listener { + + @EventHandler + public void onJoin(PostLoginEvent e) { + if (e.getPlayer().hasPermission("viaversion.update") + && Via.getConfig().isCheckForUpdates()) { + UpdateUtil.sendUpdateMessage(e.getPlayer().getUniqueId()); + } + } +} diff --git a/bungee/src/main/java/us/myles/ViaVersion/bungee/platform/BungeeViaLoader.java b/bungee/src/main/java/us/myles/ViaVersion/bungee/platform/BungeeViaLoader.java index 3348535e3..9ba4e250e 100644 --- a/bungee/src/main/java/us/myles/ViaVersion/bungee/platform/BungeeViaLoader.java +++ b/bungee/src/main/java/us/myles/ViaVersion/bungee/platform/BungeeViaLoader.java @@ -5,6 +5,7 @@ import net.md_5.bungee.api.ProxyServer; import us.myles.ViaVersion.BungeePlugin; import us.myles.ViaVersion.api.Via; import us.myles.ViaVersion.api.platform.ViaPlatformLoader; +import us.myles.ViaVersion.bungee.listeners.UpdateListener; import us.myles.ViaVersion.bungee.providers.BungeeMovementTransmitter; import us.myles.ViaVersion.bungee.providers.BungeeVersionProvider; import us.myles.ViaVersion.bungee.service.ProtocolDetectorService; @@ -21,6 +22,8 @@ public class BungeeViaLoader implements ViaPlatformLoader { public void load() { // Listeners ProxyServer.getInstance().getPluginManager().registerListener(plugin, plugin); + ProxyServer.getInstance().getPluginManager().registerListener(plugin, new UpdateListener()); + // Providers Via.getManager().getProviders().use(MovementTransmitterProvider.class, new BungeeMovementTransmitter()); Via.getManager().getProviders().use(VersionProvider.class, new BungeeVersionProvider());