From e56bce2f311d2e631a194c9cb5203335acb6b521 Mon Sep 17 00:00:00 2001 From: Matsv Date: Sun, 25 Sep 2016 21:33:47 +0200 Subject: [PATCH] Create builder for ViaManager --- TODOLIST | 2 -- .../java/us/myles/ViaVersion/ViaVersionPlugin.java | 10 ++++++++-- .../src/main/java/us/myles/ViaVersion/ViaManager.java | 8 +++----- common/src/main/java/us/myles/ViaVersion/api/Via.java | 9 +++++---- 4 files changed, 16 insertions(+), 13 deletions(-) diff --git a/TODOLIST b/TODOLIST index ade1fa489..177bbbce7 100644 --- a/TODOLIST +++ b/TODOLIST @@ -1,3 +1 @@ Handle injector errors - -Important: Create builder for ViaManager which allows supplying on the command exectutor, injector, platform :D \ No newline at end of file diff --git a/bukkit/src/main/java/us/myles/ViaVersion/ViaVersionPlugin.java b/bukkit/src/main/java/us/myles/ViaVersion/ViaVersionPlugin.java index c02783ebd..ae25d90aa 100644 --- a/bukkit/src/main/java/us/myles/ViaVersion/ViaVersionPlugin.java +++ b/bukkit/src/main/java/us/myles/ViaVersion/ViaVersionPlugin.java @@ -45,8 +45,14 @@ public class ViaVersionPlugin extends JavaPlugin implements ViaPlatform { public ViaVersionPlugin() { // Config magic conf = new ViaConfig(this); + // Command handler + commandHandler = new BukkitCommandHandler(); // Init platform - Via.init(this); + Via.init(ViaManager.builder() + .platform(this) + .commandHandler(commandHandler) + .injector(new BukkitViaInjector()) + .build()); // For compatibility ViaVersion.setInstance(this); @@ -95,7 +101,7 @@ public class ViaVersionPlugin extends JavaPlugin implements ViaPlatform { Via.getManager().init(); } - getCommand("viaversion").setExecutor(commandHandler = new BukkitCommandHandler()); + getCommand("viaversion").setExecutor(commandHandler); getCommand("viaversion").setTabCompleter(commandHandler); // Warn them if they have anti-xray on and they aren't using spigot diff --git a/common/src/main/java/us/myles/ViaVersion/ViaManager.java b/common/src/main/java/us/myles/ViaVersion/ViaManager.java index d0dcdd41f..5f4846332 100644 --- a/common/src/main/java/us/myles/ViaVersion/ViaManager.java +++ b/common/src/main/java/us/myles/ViaVersion/ViaManager.java @@ -1,5 +1,6 @@ package us.myles.ViaVersion; +import lombok.Builder; import lombok.Getter; import lombok.Setter; import us.myles.ViaVersion.api.data.UserConnection; @@ -18,9 +19,10 @@ import java.util.UUID; import java.util.concurrent.ConcurrentHashMap; @Getter +@Builder public class ViaManager { - private ViaPlatform platform; private final Map portedPlayers = new ConcurrentHashMap<>(); + private ViaPlatform platform; private ViaProviders providers = new ViaProviders(); @Setter private boolean debug = false; @@ -29,10 +31,6 @@ public class ViaManager { private ViaCommandHandler commandHandler; private ViaPlatformLoader loader; - public ViaManager(ViaPlatform platform) { - this.platform = platform; - } - public void init() { if (System.getProperty("ViaVersion") != null) { // Reload? diff --git a/common/src/main/java/us/myles/ViaVersion/api/Via.java b/common/src/main/java/us/myles/ViaVersion/api/Via.java index 3eec7ed1e..be852c468 100644 --- a/common/src/main/java/us/myles/ViaVersion/api/Via.java +++ b/common/src/main/java/us/myles/ViaVersion/api/Via.java @@ -11,10 +11,11 @@ public class Via { @Getter private static ViaManager manager; - public static void init(ViaPlatform platform) { - Validate.isTrue(platform == null, "Platform is already set"); - Via.platform = platform; - Via.manager = new ViaManager(platform); + public static void init(ViaManager viaManager) { + Validate.isTrue(manager == null, "ViaManager is already set"); + + Via.platform = viaManager.getPlatform(); + Via.manager = viaManager; } public static ViaAPI getAPI() {