Skip to content

Commit 8c9daa6

Browse files
committed
updated to distributor 3
1 parent 4c07fed commit 8c9daa6

File tree

4 files changed

+67
-67
lines changed

4 files changed

+67
-67
lines changed

build.gradle.kts

+9-7
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ toxopid {
3232
repositories {
3333
mavenCentral()
3434
maven("https://maven.xpdustry.fr/releases") {
35-
name = "xpdustry-repository"
35+
name = "xpdustry-repository-releases"
3636
mavenContent { releasesOnly() }
3737
}
3838
maven("https://repo.xpdustry.fr/releases") {
@@ -44,8 +44,8 @@ repositories {
4444

4545
dependencies {
4646
mindustryDependencies()
47-
compileOnly("fr.xpdustry:distributor-api:3.0.0-rc.2")
48-
annotationProcessor("fr.xpdustry:distributor-api:3.0.0-rc.2")
47+
compileOnly("fr.xpdustry:distributor-api:3.0.0-rc.3")
48+
annotationProcessor("fr.xpdustry:distributor-api:3.0.0-rc.3")
4949
implementation("com.google.code.gson:gson:2.10")
5050
implementation("net.mindustry_ddns:file-store:2.1.0")
5151

@@ -57,7 +57,6 @@ dependencies {
5757
// Static analysis
5858
annotationProcessor("com.uber.nullaway:nullaway:0.10.4")
5959
errorprone("com.google.errorprone:error_prone_core:2.16")
60-
compileOnly("org.checkerframework:checker-compat-qual:2.5.5")
6160
}
6261

6362
tasks.withType(JavaCompile::class.java).configureEach {
@@ -99,11 +98,13 @@ tasks.shadowJar {
9998
}
10099
}
101100

102-
tasks.build.get().dependsOn(tasks.shadowJar)
101+
tasks.build {
102+
dependsOn(tasks.shadowJar)
103+
}
103104

104105
val distributor = tasks.register<GitHubDownload>("downloadDistributor") {
105106
artifacts.add(
106-
GitHubArtifact.release("Xpdustry", "Distributor", "v3.0.0-rc.2", "Distributor.jar")
107+
GitHubArtifact.release("Xpdustry", "Distributor", "v3.0.0-rc.3", "Distributor.jar")
107108
)
108109
}
109110

@@ -150,7 +151,8 @@ indra {
150151

151152
developers {
152153
developer {
153-
id.set(metadata.author)
154+
id.set("Phinner")
155+
timezone.set("Europe/Brussels")
154156
}
155157
}
156158
}

src/main/java/fr/xpdustry/domination/DominationLogic.java

+11-10
Original file line numberDiff line numberDiff line change
@@ -19,26 +19,27 @@
1919
package fr.xpdustry.domination;
2020

2121
import arc.struct.*;
22-
import fr.xpdustry.distributor.api.*;
23-
import fr.xpdustry.distributor.api.event.*;
22+
import arc.util.*;
23+
import fr.xpdustry.distributor.api.plugin.*;
24+
import fr.xpdustry.distributor.api.util.*;
2425
import java.util.*;
2526
import mindustry.*;
2627
import mindustry.game.*;
2728
import mindustry.game.EventType.*;
2829
import mindustry.gen.*;
2930

30-
public final class DominationLogic implements Runnable {
31+
public final class DominationLogic implements PluginListener {
3132

3233
private final DominationPlugin plugin;
34+
private final Interval interval = new Interval();
3335

3436
public DominationLogic(final DominationPlugin plugin) {
3537
this.plugin = plugin;
36-
DistributorProvider.get().getPluginScheduler().syncRepeatingDelayedTask(this.plugin, this, 10, 10);
3738
}
3839

3940
@Override
40-
public void run() {
41-
if (Vars.state.isPlaying() && plugin.isEnabled()) {
41+
public void onPluginUpdate() {
42+
if (interval.get(Time.toSeconds / 6) && Vars.state.isPlaying() && plugin.isEnabled()) {
4243
for (final var zone : plugin.getState().getZones()) {
4344
// Reset the team if the team got beaten
4445
if (zone.getTeam() != Team.derelict && !zone.getTeam().active()) {
@@ -49,7 +50,7 @@ public void run() {
4950
// Count the number of units in the zone, per team
5051
final var units = new ObjectIntMap<Team>();
5152
Groups.unit.each(
52-
unit -> unit.within(zone.getX(), zone.getY(), zone.getRadius()) && !unit.spawnedByCore,
53+
unit -> unit.within(zone.getX(), zone.getY(), zone.getRadius()) && !unit.spawnedByCore(),
5354
unit -> units.increment(unit.team())
5455
);
5556

@@ -89,7 +90,7 @@ public void run() {
8990
if (leaderboard.size() == 1) {
9091
final var entry = leaderboard.entrySet().iterator().next();
9192
if (!entry.getKey().equals(Team.derelict) && entry.getValue() == plugin.getState().getZones().size() * 100) {
92-
EventBus.mindustry().post(new GameOverEvent(entry.getKey()));
93+
MoreEvents.post(new GameOverEvent(entry.getKey()));
9394
return;
9495
}
9596
}
@@ -113,9 +114,9 @@ public void run() {
113114
}
114115

115116
if (winners.size() == 1) {
116-
EventBus.mindustry().post(new GameOverEvent(winners.get(0)));
117+
MoreEvents.post(new GameOverEvent(winners.get(0)));
117118
} else {
118-
EventBus.mindustry().post(new GameOverEvent(Team.derelict));
119+
MoreEvents.post(new GameOverEvent(Team.derelict));
119120
}
120121
}
121122
}

src/main/java/fr/xpdustry/domination/DominationPlugin.java

+18-22
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import com.google.gson.*;
2323
import fr.xpdustry.distributor.api.command.*;
2424
import fr.xpdustry.distributor.api.command.sender.*;
25-
import fr.xpdustry.distributor.api.event.*;
2625
import fr.xpdustry.distributor.api.plugin.*;
2726
import fr.xpdustry.distributor.api.util.*;
2827
import fr.xpdustry.domination.Zone.*;
@@ -37,7 +36,7 @@
3736
import net.mindustry_ddns.filestore.serial.*;
3837
import org.checkerframework.checker.nullness.qual.*;
3938

40-
public final class DominationPlugin extends ExtendedPlugin implements EventBusListener {
39+
public final class DominationPlugin extends ExtendedPlugin {
4140

4241
public static final String DOMINATION_RULES = """
4342
Welcome to [cyan]Domination PVP[].
@@ -68,19 +67,23 @@ public final class DominationPlugin extends ExtendedPlugin implements EventBusLi
6867

6968
private @MonotonicNonNull DominationState state = null;
7069

71-
@EventHandler(priority = Priority.HIGH)
72-
public void onPlayEvent(final EventType.PlayEvent event) {
73-
loader.setFile(getDirectory().resolve("maps").resolve(Vars.state.map.name() + ".json").toFile());
74-
loader.set(new ArrayList<>());
75-
loader.load();
76-
state = new DominationState(loader);
77-
}
78-
79-
@EventHandler
80-
public void onPlayerJoin(final EventType.PlayerJoin event) {
81-
if (isEnabled()) {
82-
Call.infoMessage(event.player.con(), DOMINATION_RULES);
83-
}
70+
@Override
71+
public void onInit() {
72+
MoreEvents.subscribe(EventType.PlayEvent.class, event -> {
73+
loader.setFile(getDirectory().resolve("maps").resolve(Vars.state.map.name() + ".json").toFile());
74+
loader.set(new ArrayList<>());
75+
loader.load();
76+
state = new DominationState(loader);
77+
});
78+
79+
MoreEvents.subscribe(EventType.PlayerJoin.class, event -> {
80+
if (isEnabled()) {
81+
Call.infoMessage(event.player.con(), DOMINATION_RULES);
82+
}
83+
});
84+
85+
addListener(new DominationLogic(this));
86+
addListener(new DominationRenderer(this));
8487
}
8588

8689
@Override
@@ -99,13 +102,6 @@ public void onClientCommandsRegistration(final CommandHandler handler) {
99102
annotations.parse(new StandardCommands(this));
100103
}
101104

102-
@Override
103-
public void onLoad() {
104-
EventBus.mindustry().register(this);
105-
new DominationLogic(this);
106-
new DominationRenderer(this);
107-
}
108-
109105
public boolean isEnabled() {
110106
return Vars.state.rules.tags.getBool(DOMINATION_ENABLED_KEY);
111107
}

src/main/java/fr/xpdustry/domination/DominationRenderer.java

+29-28
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323
import arc.struct.*;
2424
import arc.util.*;
2525
import cloud.commandframework.meta.*;
26-
import fr.xpdustry.distributor.api.*;
27-
import fr.xpdustry.distributor.api.event.*;
26+
import fr.xpdustry.distributor.api.plugin.*;
27+
import fr.xpdustry.distributor.api.util.*;
2828
import java.util.*;
2929
import mindustry.*;
3030
import mindustry.content.*;
@@ -33,19 +33,30 @@
3333
import mindustry.gen.*;
3434
import mindustry.graphics.*;
3535

36-
public final class DominationRenderer implements Runnable, EventBusListener {
36+
public final class DominationRenderer implements PluginListener {
3737

3838
private static final Seq<Effect> EFFECTS = Seq.with(Fx.mine, Fx.mineBig, Fx.mineHuge);
3939

40-
private final DominationPlugin plugin;
40+
private final Interval interval = new Interval();
4141
private final Map<Zone, WorldLabel> labels = new HashMap<>();
4242
private final Set<Player> viewers = new HashSet<>();
43+
private final DominationPlugin domination;
4344

44-
public DominationRenderer(final DominationPlugin plugin) {
45-
this.plugin = plugin;
46-
EventBus.mindustry().register(this);
47-
DistributorProvider.get().getPluginScheduler().syncRepeatingDelayedTask(this.plugin, this, 10, 10);
48-
plugin.getClientCommandManager().command(plugin.getClientCommandManager()
45+
public DominationRenderer(final DominationPlugin domination) {
46+
this.domination = domination;
47+
}
48+
49+
@Override
50+
public void onPluginLoad() {
51+
MoreEvents.subscribe(EventType.PlayEvent.class, event -> {
52+
labels.clear();
53+
});
54+
55+
MoreEvents.subscribe(EventType.PlayerLeave.class, event -> {
56+
viewers.remove(event.player);
57+
});
58+
59+
domination.getClientCommandManager().command(domination.getClientCommandManager()
4960
.commandBuilder("domination")
5061
.literal("zone")
5162
.literal("view")
@@ -62,20 +73,10 @@ public DominationRenderer(final DominationPlugin plugin) {
6273
}));
6374
}
6475

65-
@EventHandler
66-
public void onPlayEvent(final EventType.PlayEvent event) {
67-
labels.clear();
68-
}
69-
70-
@EventHandler
71-
public void onPlayerQuit(final EventType.PlayerLeave event) {
72-
viewers.remove(event.player);
73-
}
74-
7576
@Override
76-
public void run() {
77-
if (Vars.state.isPlaying()) {
78-
if (plugin.isEnabled()) {
77+
public void onPluginUpdate() {
78+
if (interval.get(Time.toSeconds / 6) && Vars.state.isPlaying()) {
79+
if (domination.isEnabled()) {
7980
// Graphics
8081
Groups.player.forEach(this::drawZoneCircles);
8182
labels.forEach((zone, label) -> {
@@ -84,24 +85,24 @@ public void run() {
8485

8586
// HUD text
8687
final var builder = new StringBuilder(100)
87-
.append("Time remaining > ").append(Strings.formatMillis(plugin.getState().getRemainingTime().toMillis()));
88+
.append("Time remaining > ").append(Strings.formatMillis(domination.getState().getRemainingTime().toMillis()));
8889

8990
// Leaderboard
90-
plugin.getState().getLeaderboard().entrySet()
91+
domination.getState().getLeaderboard().entrySet()
9192
.stream()
9293
.sorted(Comparator.comparingDouble(Map.Entry::getValue))
9394
.forEach(e -> {
9495
builder
9596
.append("\n[#").append(e.getKey().color).append(']')
9697
.append(e.getKey() == Team.derelict ? "Unclaimed" : Strings.capitalize(e.getKey().name))
97-
.append("[] > ").append(e.getValue() / plugin.getState().getZones().size()).append('%');
98+
.append("[] > ").append(e.getValue() / domination.getState().getZones().size()).append('%');
9899
}
99100
);
100101

101102
Call.setHudText(builder.toString());
102103

103104
// Update labels
104-
final var zones = new HashSet<>(plugin.getState().getZones());
105+
final var zones = new HashSet<>(domination.getState().getZones());
105106
final var entries = labels.entrySet().iterator();
106107
while (entries.hasNext()) {
107108
final var entry = entries.next();
@@ -124,7 +125,7 @@ public void run() {
124125
} else {
125126
for (final var viewer : viewers) {
126127
drawZoneCircles(viewer);
127-
for (final var zone : this.plugin.getState().getZones()) {
128+
for (final var zone : this.domination.getState().getZones()) {
128129
Call.label(viewer.con(), "[#" + zone.getTeam().color + "]" + Iconc.star, 1F / 6, zone.getX(), zone.getY());
129130
}
130131
}
@@ -133,7 +134,7 @@ public void run() {
133134
}
134135

135136
private void drawZoneCircles(final Player player) {
136-
for (final var zone : this.plugin.getState().getZones()) {
137+
for (final var zone : this.domination.getState().getZones()) {
137138
final var circle = Geometry.regPoly((int) (Mathf.pi * (zone.getRadius() / Vars.tilesize)), zone.getRadius());
138139
Geometry.iteratePolygon((px, py) -> {
139140
Call.effect(player.con(), EFFECTS.random(), px + zone.getX(), py + zone.getY(), 0, zone.getTeam().color);

0 commit comments

Comments
 (0)