Skip to content

Commit

Permalink
бенримод
Browse files Browse the repository at this point in the history
  • Loading branch information
Даркнесс committed Mar 21, 2023
1 parent b1965f9 commit 8898c14
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 29 deletions.
7 changes: 3 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,20 @@ repositories {
}

ext {
mindustryVersion = 'v140.2'
mindustryVersion = 'v142'
}

dependencies {
compileOnly "com.github.Anuken.Arc:arc-core:$mindustryVersion"
compileOnly "com.github.Anuken.Mindustry:core:$mindustryVersion"

implementation "com.google.code.gson:gson:2.10"

implementation "com.github.xzxADIxzx.useful-stuffs:server-bundle:main-SNAPSHOT"
implementation "com.github.xzxADIxzx.useful-stuffs:bundle:d1e3cc1a5a"
}

jar {
archiveFileName.set "${project.archivesBaseName}.jar"
from {
configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }
}
}
}
35 changes: 18 additions & 17 deletions src/main/java/inside/LightweightHub.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,7 @@

public class LightweightHub extends Plugin {

public static final float
delaySeconds = 3f,
refreshDuration = 6f,
teleportUpdateInterval = 3f;
public static final float updateInterval = 3f;

public static final Interval interval = new Interval();
public static final AtomicInteger counter = new AtomicInteger();
Expand All @@ -31,22 +28,26 @@ public class LightweightHub extends Plugin {
public static Config config;

public static void showOnlineLabel(Player player, Server server, Host host) {
Call.label(player.con, host.name, refreshDuration, server.titleX * tilesize, server.titleY * tilesize);
Call.label(player.con, Bundle.format("server.offline", player, host.players, host.mapname), refreshDuration, server.labelX * tilesize, server.labelY * tilesize);
Call.label(player.con, host.name, updateInterval, server.titleX * tilesize, server.titleY * tilesize);
Call.label(player.con, Bundle.format(!server.isNear(player.tileX(), player.tileY()) ?
"server.online" :
"server.online.full",
player, host.players, host.mapname, host.wave, server.ip + ":" + server.port
), updateInterval, server.labelX * tilesize, server.labelY * tilesize);
}

public static void showOfflineLabel(Player player, Server server) {
Call.label(player.con, Bundle.format("server.online", player), refreshDuration, server.labelX * tilesize, server.labelY * tilesize);
Call.label(player.con, Bundle.format("server.offline", player), updateInterval, server.labelX * tilesize, server.labelY * tilesize);
}

public static void teleport(Player player) {
teleport(player, player.tileX(), player.tileY());
}

public static void teleport(Player player, int x, int y) {
config.servers.forEach(data -> {
if (data.inDiapason(x, y))
data.pingHost(host -> Call.connect(player.con, data.ip, data.port), e -> {});
config.servers.forEach(server -> {
if (server.isInside(x, y))
server.pingHost(host -> Call.connect(player.con, server.ip, server.port), e -> {});
});
}

Expand All @@ -63,35 +64,35 @@ public void init() {

Bundle.load(LightweightHub.class);

content.units().each(type -> type.payloadCapacity = 0f);

Events.run(Trigger.update, () -> {
if (interval.get(teleportUpdateInterval))
if (interval.get(updateInterval))
Groups.player.each(LightweightHub::teleport);
});

Events.on(TapEvent.class, event -> teleport(event.player, event.tile.x, event.tile.y));

Events.on(PlayerJoin.class, event -> config.servers.forEach(server -> server.pingHost(host -> showOnlineLabel(event.player, server, host), e -> showOfflineLabel(event.player, server))));
Events.on(PlayerJoin.class, event -> config.servers.forEach(server -> server.pingHost(host -> showOnlineLabel(event.player, server, host), error -> showOfflineLabel(event.player, server))));

Events.on(WorldLoadEvent.class, event -> {
state.rules.blockDamageMultiplier = 0f;
state.rules.unitDamageMultiplier = 0f;

Structs.each(team -> team.rules().cheat = true, Team.baseTeams);
content.units().each(type -> type.payloadCapacity = 0f);

Structs.each(team -> team.rules().cheat = true, Team.all);
});

Timer.schedule(() -> {
var tasks = config.servers.stream().map(server -> CompletableFuture.runAsync(() -> server.pingHost(host -> {
counter.addAndGet(host.players);
Groups.player.each(player -> showOnlineLabel(player, server, host));
}, e -> Groups.player.each(player -> showOfflineLabel(player, server))))).toArray(CompletableFuture<?>[]::new);
}, error -> Groups.player.each(player -> showOfflineLabel(player, server))))).toArray(CompletableFuture<?>[]::new);

CompletableFuture.allOf(tasks).thenRun(() -> {
counter.addAndGet(Groups.player.size());
Core.settings.put("totalPlayers", counter.getAndSet(0));
}).join();
}, delaySeconds, refreshDuration);
}, 0f, updateInterval);

netServer.admins.addActionFilter(action -> action.type != placeBlock && action.type != breakBlock && (action.type != configure || action.config instanceof Boolean));
}
Expand Down
11 changes: 7 additions & 4 deletions src/main/java/inside/Server.java
Original file line number Diff line number Diff line change
@@ -1,32 +1,35 @@
package inside;

import arc.func.Cons;
import arc.math.Mathf;
import mindustry.net.Host;

import static mindustry.Vars.*;

public class Server {

public String ip = "darkdustry.ml";
public String ip = "darkdustry.net";
public int port;

public int x;
public int y;

public float size;

/** Это умножается на Vars.tilesize! */
public float titleX;
public float titleY;

/** Это умножается на Vars.tilesize! */
public float labelX;
public float labelY;

public boolean inDiapason(int x, int y) {
public boolean isInside(int x, int y) {
return x <= this.x + size && x >= this.x - size && y <= this.y + size && y >= this.y - size;
}

public boolean isNear(int x, int y) {
return Mathf.dst(this.x, this.y, x, y) <= size * 4f;
}

public void pingHost(Cons<Host> valid, Cons<Exception> failed) {
net.pingHost(ip, port, valid, failed);
}
Expand Down
5 changes: 3 additions & 2 deletions src/main/resources/bundles/bundle_en.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
server.online = [scarlet]\u26A0 Offline
server.offline = [white]\uE837 [accent]Players: {0}\n[white]\uE827 [accent]Map: {1}
server.offline = [scarlet]\u26A0 Offline
server.online = [white]\uE837 [accent]Players: {0}\n[white]\uE827 [accent]Map: {1}
server.online.full = [white]\uE837 [accent]Players: {0}\n[white]\uE827 [accent]Map: {1}\n[white]\uE871 [accent]Wave: {2}\n[white]\uE875 [accent]Address: {3}
5 changes: 3 additions & 2 deletions src/main/resources/bundles/bundle_ru.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
server.online = [scarlet]\u26A0 Сервер отключен
server.offline = [white]\uE837 [accent]Игроков: {0}\n[white]\uE827 [accent]Карта: {1}
server.offline = [scarlet]\u26A0 Сервер отключен
server.online = [white]\uE837 [accent]Игроков: {0}\n[white]\uE827 [accent]Карта: {1}
server.online.full = [white]\uE837 [accent]Игроков: {0}\n[white]\uE827 [accent]Карта: {1}\n[white]\uE871 [accent]Волна: {2}\n[white]\uE875 [accent]Адрес: {3}

0 comments on commit 8898c14

Please sign in to comment.