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
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() {
// 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

View File

@ -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<UUID, UserConnection> 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?

View File

@ -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() {