From 4dd29eec3fde1add0a85978ffcde5646357080ce Mon Sep 17 00:00:00 2001 From: phinner <62483793+phinner@users.noreply.github.com> Date: Tue, 3 Dec 2024 01:37:20 +0100 Subject: [PATCH] chore(deps): Migrate to distributor 4 --- gradle/libs.versions.toml | 2 +- .../java/com/xpdustry/hexed/HexedCommands.java | 15 +++++++-------- src/main/java/com/xpdustry/hexed/HexedLogic.java | 16 ++++++++-------- .../com/xpdustry/hexed/HexedPluginReloaded.java | 6 ++---- 4 files changed, 18 insertions(+), 21 deletions(-) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index c80c6a9..79f8344 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -4,7 +4,7 @@ java = "17" # utilities -distributor = "4.0.0-rc.3" +distributor = "4.0.1" cloud = "2.0.0" slf4md = "1.0.1" diff --git a/src/main/java/com/xpdustry/hexed/HexedCommands.java b/src/main/java/com/xpdustry/hexed/HexedCommands.java index aa4284b..53b8142 100644 --- a/src/main/java/com/xpdustry/hexed/HexedCommands.java +++ b/src/main/java/com/xpdustry/hexed/HexedCommands.java @@ -19,7 +19,7 @@ package com.xpdustry.hexed; import arc.util.CommandHandler; -import com.xpdustry.distributor.api.DistributorProvider; +import com.xpdustry.distributor.api.Distributor; import com.xpdustry.distributor.api.command.CommandSender; import com.xpdustry.distributor.api.command.cloud.MindustryCommandManager; import com.xpdustry.distributor.api.plugin.MindustryPlugin; @@ -63,11 +63,10 @@ public void onHexedStartCommand( return; } - final var generator = - DistributorProvider.get().getServiceManager().getProviders(HexedMapGenerator.class).stream() - .map(ServiceProvider::getInstance) - .filter(g -> g.getName().equals(name)) - .findFirst(); + final var generator = Distributor.get().getServiceManager().getProviders(HexedMapGenerator.class).stream() + .map(ServiceProvider::getInstance) + .filter(g -> g.getName().equals(name)) + .findFirst(); if (generator.isEmpty()) { sender.error("Generator named " + name + " not found."); return; @@ -122,7 +121,7 @@ public void onSpectateCommand(final CommandSender sender) { return; } if (sender.getPlayer().team() != Team.derelict) { - DistributorProvider.get() + Distributor.get() .getEventBus() .post(new HexPlayerQuitEvent( sender.getPlayer(), sender.getPlayer().team(), false)); @@ -139,7 +138,7 @@ public void onJoinCommand(final CommandSender sender) { return; } if (sender.getPlayer().team() == Team.derelict) { - DistributorProvider.get().getEventBus().post(new HexPlayerJoinEvent(sender.getPlayer(), false)); + Distributor.get().getEventBus().post(new HexPlayerJoinEvent(sender.getPlayer(), false)); } else { sender.error("You are already in the game."); } diff --git a/src/main/java/com/xpdustry/hexed/HexedLogic.java b/src/main/java/com/xpdustry/hexed/HexedLogic.java index efa4f1d..cf6ed5c 100644 --- a/src/main/java/com/xpdustry/hexed/HexedLogic.java +++ b/src/main/java/com/xpdustry/hexed/HexedLogic.java @@ -21,7 +21,7 @@ import arc.math.Mathf; import arc.util.Interval; import arc.util.Time; -import com.xpdustry.distributor.api.DistributorProvider; +import com.xpdustry.distributor.api.Distributor; import com.xpdustry.distributor.api.annotation.EventHandler; import com.xpdustry.distributor.api.collection.MindustryCollections; import com.xpdustry.distributor.api.plugin.PluginListener; @@ -64,7 +64,7 @@ public void onPluginInit() { @EventHandler public void onPlayerJoin(final EventType.PlayerJoin event) { - DistributorProvider.get().getEventBus().post(new HexPlayerJoinEvent(event.player, true)); + Distributor.get().getEventBus().post(new HexPlayerJoinEvent(event.player, true)); } @EventHandler @@ -99,7 +99,7 @@ public void onPlayerJoin(final HexPlayerJoinEvent event) { @EventHandler public void onPlayerLeave(final EventType.PlayerLeave event) { - DistributorProvider.get().getEventBus().post(new HexPlayerQuitEvent(event.player, event.player.team(), false)); + Distributor.get().getEventBus().post(new HexPlayerQuitEvent(event.player, event.player.team(), false)); } @EventHandler @@ -141,14 +141,14 @@ public void onPluginUpdate() { if (oldController != newController && newController != null && newController != Team.derelict) { final var player = Groups.player.find(p -> p.team() == newController); if (player != null) { - DistributorProvider.get().getEventBus().post(new HexCaptureEvent(player, hex)); + Distributor.get().getEventBus().post(new HexCaptureEvent(player, hex)); } } if (oldController != newController && oldController != null && oldController != Team.derelict) { final var player = Groups.player.find(p -> p.team() == oldController); if (player != null) { - DistributorProvider.get().getEventBus().post(new HexLostEvent(player, hex)); + Distributor.get().getEventBus().post(new HexLostEvent(player, hex)); } } } @@ -158,7 +158,7 @@ public void onPluginUpdate() { for (final var player : Groups.player) { if (player.team() != Team.derelict && player.team().cores().isEmpty()) { final var oldTeam = player.team(); - DistributorProvider.get().getEventBus().post(new HexPlayerQuitEvent(player, oldTeam, true)); + Distributor.get().getEventBus().post(new HexPlayerQuitEvent(player, oldTeam, true)); } if (player.team() == Team.derelict) { @@ -183,7 +183,7 @@ public void onPluginUpdate() { private void killTeam(final Team team) { this.hexed.getHexedState0().setDying(team, true); team.data().destroyToDerelict(); - DistributorProvider.get() + Distributor.get() .getPluginScheduler() .schedule(this.hexed) .delay(8, MindustryTimeUnit.SECONDS) @@ -199,7 +199,7 @@ private void endGame() { .filter(team -> team != Team.derelict) .collect(maxList(Comparator.comparingInt( team -> this.hexed.getHexedState().getControlled(team).size()))); - final var bus = DistributorProvider.get().getEventBus(); + final var bus = Distributor.get().getEventBus(); bus.post(new GameOverEvent(winners.size() == 1 ? winners.get(0) : Team.derelict)); bus.post(new HexedGameOverEvent(winners)); } diff --git a/src/main/java/com/xpdustry/hexed/HexedPluginReloaded.java b/src/main/java/com/xpdustry/hexed/HexedPluginReloaded.java index 5a56ed8..611e563 100644 --- a/src/main/java/com/xpdustry/hexed/HexedPluginReloaded.java +++ b/src/main/java/com/xpdustry/hexed/HexedPluginReloaded.java @@ -18,7 +18,7 @@ */ package com.xpdustry.hexed; -import com.xpdustry.distributor.api.DistributorProvider; +import com.xpdustry.distributor.api.Distributor; import com.xpdustry.distributor.api.annotation.PluginAnnotationProcessor; import com.xpdustry.distributor.api.plugin.AbstractMindustryPlugin; import com.xpdustry.distributor.api.plugin.PluginListener; @@ -71,9 +71,7 @@ public boolean start(final MapGenerator generator) { @Override public void onInit() { - DistributorProvider.get() - .getServiceManager() - .register(this, HexedMapGenerator.class, new AnukeHexedGenerator()); + Distributor.get().getServiceManager().register(this, HexedMapGenerator.class, new AnukeHexedGenerator()); this.addListener(new HexedLogic(this)); this.addListener(new HexedRenderer(this)); this.addListener(new HexedCommands(this));