Create builder for ViaManager

This commit is contained in:
Matsv 2016-09-25 21:33:47 +02:00
parent 573374866b
commit e56bce2f31
No known key found for this signature in database
GPG Key ID: 97CEC2A2EA31350F
4 changed files with 16 additions and 13 deletions

View File

@ -1,3 +1 @@
Handle injector errors Handle injector errors
Important: Create builder for ViaManager which allows supplying on the command exectutor, injector, platform :D

View File

@ -45,8 +45,14 @@ public class ViaVersionPlugin extends JavaPlugin implements ViaPlatform {
public ViaVersionPlugin() { public ViaVersionPlugin() {
// Config magic // Config magic
conf = new ViaConfig(this); conf = new ViaConfig(this);
// Command handler
commandHandler = new BukkitCommandHandler();
// Init platform // Init platform
Via.init(this); Via.init(ViaManager.builder()
.platform(this)
.commandHandler(commandHandler)
.injector(new BukkitViaInjector())
.build());
// For compatibility // For compatibility
ViaVersion.setInstance(this); ViaVersion.setInstance(this);
@ -95,7 +101,7 @@ public class ViaVersionPlugin extends JavaPlugin implements ViaPlatform {
Via.getManager().init(); Via.getManager().init();
} }
getCommand("viaversion").setExecutor(commandHandler = new BukkitCommandHandler()); getCommand("viaversion").setExecutor(commandHandler);
getCommand("viaversion").setTabCompleter(commandHandler); getCommand("viaversion").setTabCompleter(commandHandler);
// Warn them if they have anti-xray on and they aren't using spigot // Warn them if they have anti-xray on and they aren't using spigot

View File

@ -1,5 +1,6 @@
package us.myles.ViaVersion; package us.myles.ViaVersion;
import lombok.Builder;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
import us.myles.ViaVersion.api.data.UserConnection; import us.myles.ViaVersion.api.data.UserConnection;
@ -18,9 +19,10 @@ import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
@Getter @Getter
@Builder
public class ViaManager { public class ViaManager {
private ViaPlatform platform;
private final Map<UUID, UserConnection> portedPlayers = new ConcurrentHashMap<>(); private final Map<UUID, UserConnection> portedPlayers = new ConcurrentHashMap<>();
private ViaPlatform platform;
private ViaProviders providers = new ViaProviders(); private ViaProviders providers = new ViaProviders();
@Setter @Setter
private boolean debug = false; private boolean debug = false;
@ -29,10 +31,6 @@ public class ViaManager {
private ViaCommandHandler commandHandler; private ViaCommandHandler commandHandler;
private ViaPlatformLoader loader; private ViaPlatformLoader loader;
public ViaManager(ViaPlatform platform) {
this.platform = platform;
}
public void init() { public void init() {
if (System.getProperty("ViaVersion") != null) { if (System.getProperty("ViaVersion") != null) {
// Reload? // Reload?

View File

@ -11,10 +11,11 @@ public class Via {
@Getter @Getter
private static ViaManager manager; private static ViaManager manager;
public static void init(ViaPlatform platform) { public static void init(ViaManager viaManager) {
Validate.isTrue(platform == null, "Platform is already set"); Validate.isTrue(manager == null, "ViaManager is already set");
Via.platform = platform;
Via.manager = new ViaManager(platform); Via.platform = viaManager.getPlatform();
Via.manager = viaManager;
} }
public static ViaAPI getAPI() { public static ViaAPI getAPI() {