Skip to content

Commit 0f2bdca

Browse files
authored
Merge pull request #195 from Maxlego08/codex/add-/lag-command-for-entity-count
feat: add lag command
2 parents 7e47c9a + 49f42ca commit 0f2bdca

File tree

12 files changed

+143
-0
lines changed

12 files changed

+143
-0
lines changed

API/src/main/java/fr/maxlego08/essentials/api/commands/Permission.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ public enum Permission {
159159
ESSENTIALS_NEAR,
160160
ESSENTIALS_PLAY_TIME,
161161
ESSENTIALS_KILL_ALL,
162+
ESSENTIALS_LAG,
162163
ESSENTIALS_SEEN,
163164
ESSENTIALS_SEEN_IP,
164165
ESSENTIALS_SEEN_SHOW_IP("Allows to see the IP of a player"),

API/src/main/java/fr/maxlego08/essentials/api/messages/Message.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,10 @@ public enum Message {
153153
COMMAND_PLAYER_TIME_RESET("&7You just changed the time to that of the server."),
154154
COMMAND_PLAYER_TIME_CHANGE("&7You’re here to change your time."),
155155

156+
COMMAND_LAG_WORLD_LINE("&a%world%&7: &a%peaceful% peaceful&7, &c%monsters% monsters&7, &e%items% items"),
157+
COMMAND_LAG_WORLD_HEADER("&aEntities for world &2%world%&a:"),
158+
COMMAND_LAG_WORLD_ENTRY("&7- &a%type%&7: &f%amount%"),
159+
156160
DESCRIPTION_CLEAR_RANDOM_WORD("Clear random words"),
157161
DESCRIPTION_RELOAD("Reload configuration files"),
158162
DESCRIPTION_DELETE_WORLD("Removes data being linked to a world"),
@@ -262,6 +266,8 @@ public enum Message {
262266
DESCRIPTION_PLAY_TIME("Show player's playtime"),
263267
DESCRIPTION_VERSION("Show plugin version"),
264268
DESCRIPTION_KILL_ALL("Kill entities"),
269+
DESCRIPTION_LAG("Display entity counts per world"),
270+
DESCRIPTION_LAG_WORLD("Display detailed entity counts for a world"),
265271
DESCRIPTION_SEEN("Show player informations"),
266272
DESCRIPTION_SEEN_IP("Show players who have the same IP"),
267273
DESCRIPTION_KIT("Get a kit"),

src/main/java/fr/maxlego08/essentials/commands/CommandLoader.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@
9494
import fr.maxlego08.essentials.commands.commands.utils.CommandRepair;
9595
import fr.maxlego08.essentials.commands.commands.utils.CommandRepairAll;
9696
import fr.maxlego08.essentials.commands.commands.utils.CommandRules;
97+
import fr.maxlego08.essentials.commands.commands.utils.lag.CommandLag;
9798
import fr.maxlego08.essentials.commands.commands.utils.CommandSudo;
9899
import fr.maxlego08.essentials.commands.commands.utils.CommandSuicide;
99100
import fr.maxlego08.essentials.commands.commands.utils.CommandTrash;
@@ -255,6 +256,7 @@ public void loadCommands(CommandManager commandManager) {
255256
register("playtime", CommandPlayTime.class);
256257
register("essversion", CommandVersion.class, "ev");
257258
register("killall", CommandKillAll.class);
259+
register("lag", CommandLag.class);
258260
register("seen", CommandSeen.class, "whois");
259261
register("seenip", CommandSeenIp.class, "whoisip");
260262
register("enchant", CommandEnchant.class, "enchantment");
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package fr.maxlego08.essentials.commands.commands.utils.lag;
2+
3+
import fr.maxlego08.essentials.api.EssentialsPlugin;
4+
import fr.maxlego08.essentials.api.commands.CommandResultType;
5+
import fr.maxlego08.essentials.api.commands.Permission;
6+
import fr.maxlego08.essentials.api.messages.Message;
7+
import fr.maxlego08.essentials.zutils.utils.commands.VCommand;
8+
import org.bukkit.Bukkit;
9+
import org.bukkit.World;
10+
import org.bukkit.entity.Entity;
11+
import org.bukkit.entity.Item;
12+
import org.bukkit.entity.LivingEntity;
13+
import org.bukkit.entity.Monster;
14+
import org.bukkit.entity.Player;
15+
16+
public class CommandLag extends VCommand {
17+
18+
public CommandLag(EssentialsPlugin plugin) {
19+
super(plugin);
20+
this.setPermission(Permission.ESSENTIALS_LAG);
21+
this.setDescription(Message.DESCRIPTION_LAG);
22+
this.addSubCommand(new CommandLagWorld(plugin));
23+
}
24+
25+
@Override
26+
protected CommandResultType perform(EssentialsPlugin plugin) {
27+
28+
for (World world : Bukkit.getWorlds()) {
29+
int monster = 0;
30+
int peaceful = 0;
31+
int items = 0;
32+
for (Entity entity : world.getEntities()) {
33+
if (entity instanceof Monster) {
34+
monster++;
35+
} else if (entity instanceof Item) {
36+
items++;
37+
} else if (entity instanceof LivingEntity && !(entity instanceof Player)) {
38+
peaceful++;
39+
}
40+
}
41+
message(this.sender, Message.COMMAND_LAG_WORLD_LINE,
42+
"%world%", world.getName(),
43+
"%peaceful%", peaceful,
44+
"%monsters%", monster,
45+
"%items%", items);
46+
}
47+
48+
return CommandResultType.SUCCESS;
49+
}
50+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package fr.maxlego08.essentials.commands.commands.utils.lag;
2+
3+
import fr.maxlego08.essentials.api.EssentialsPlugin;
4+
import fr.maxlego08.essentials.api.commands.CommandResultType;
5+
import fr.maxlego08.essentials.api.commands.Permission;
6+
import fr.maxlego08.essentials.api.messages.Message;
7+
import fr.maxlego08.essentials.zutils.utils.commands.VCommand;
8+
import org.bukkit.Bukkit;
9+
import org.bukkit.World;
10+
import org.bukkit.entity.Entity;
11+
import org.bukkit.entity.EntityType;
12+
import org.bukkit.entity.Player;
13+
14+
import java.util.Comparator;
15+
import java.util.Map;
16+
import java.util.stream.Collectors;
17+
18+
public class CommandLagWorld extends VCommand {
19+
20+
public CommandLagWorld(EssentialsPlugin plugin) {
21+
super(plugin);
22+
this.addSubCommand("world");
23+
this.setPermission(Permission.ESSENTIALS_LAG);
24+
this.setDescription(Message.DESCRIPTION_LAG_WORLD);
25+
this.addRequireArg("world", (a, b) -> Bukkit.getWorlds().stream().map(World::getName).toList());
26+
}
27+
28+
@Override
29+
protected CommandResultType perform(EssentialsPlugin plugin) {
30+
31+
World world = this.argAsWorld(0);
32+
if (world == null) {
33+
return CommandResultType.SYNTAX_ERROR;
34+
}
35+
36+
message(this.sender, Message.COMMAND_LAG_WORLD_HEADER, "%world%", world.getName());
37+
Map<EntityType, Long> counts = world.getEntities().stream()
38+
.filter(entity -> !(entity instanceof Player))
39+
.collect(Collectors.groupingBy(Entity::getType, Collectors.counting()));
40+
41+
counts.entrySet().stream()
42+
.sorted(Map.Entry.comparingByValue(Comparator.reverseOrder()))
43+
.forEach(entry -> message(this.sender, Message.COMMAND_LAG_WORLD_ENTRY,
44+
"%type%", entry.getKey().name().toLowerCase(),
45+
"%amount%", entry.getValue()));
46+
47+
return CommandResultType.SUCCESS;
48+
}
49+
}

src/main/resources/messages/message_zh.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,9 @@ command-player-weather-reset: '&7您刚刚更改天气为服务器的天气。'
8686
command-player-weather-downfall: '&7您刚刚为自己开启了下雨。'
8787
command-player-time-reset: '&7您刚刚更改时间为服务器的时间。'
8888
command-player-time-change: '&7您正在改变自己的时间。'
89+
command-lag-world-line: '&a%world%&7: &a%peaceful% 和平实体&7, &c%monsters% 怪物&7, &e%items% 掉落物'
90+
command-lag-world-header: '&a世界 &2%world%&a 的实体:'
91+
command-lag-world-entry: '&7- &a%type%&7: &f%amount%'
8992
command-fly-enable: '&7飞行模式 <success>启用 &7给 &f%player%<success>。'
9093
command-fly-disable: '&7飞行模式 <error>禁用 &7给 &f%player%<success>。'
9194
command-fly-error-world: <error>您不能在这个世界飞行。
@@ -341,6 +344,8 @@ description-repair-all: 修复背包中的所有物品
341344
description-ext: 停止燃烧
342345
description-near: 显示附近的玩家
343346
description-play-time: 显示玩家的游戏时间
347+
description-lag: 显示每个世界的实体数量
348+
description-lag-world: 显示世界中实体的详细统计
344349
description-bottom: 传送到底部
345350
description-compact-all: 压缩库存中的物品
346351
description-version: 显示插件版本

src/main/resources/messages/messages.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,9 @@ command-player-weather-reset: "&7You just changed the weather to that of the ser
8888
command-player-weather-downfall: "&7You just put the rain on for yourself."
8989
command-player-time-reset: "&7You just changed the time to that of the server."
9090
command-player-time-change: "&7You’re here to change your time."
91+
command-lag-world-line: "&a%world%&7: &a%peaceful% peaceful&7, &c%monsters% monsters&7, &e%items% items"
92+
command-lag-world-header: "&aEntities for world &2%world%&a:"
93+
command-lag-world-entry: "&7- &a%type%&7: &f%amount%"
9194
command-fly-enable: "&7Flight mode <success>enable &7for &f%player%<success>."
9295
command-fly-disable: "&7Flight mode <error>disable &7for &f%player%<success>."
9396
command-fly-error-world: "<error>You can’t fly in this world."
@@ -457,6 +460,8 @@ description-pub: "Send a message highlighted in the chat"
457460
description-step: "Show steps commands"
458461
description-step-start: "Start a step"
459462
description-step-finish: "Finish a step"
463+
description-lag: "Display entity counts per world"
464+
description-lag-world: "Display detailed entity counts for a world"
460465

461466
# Time format
462467
format-second: " second"

src/main/resources/messages/messages_de.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,9 @@ command-player-weather-reset: "&7Du hast gerade das Wetter auf das des Servers g
9595
command-player-weather-downfall: "&7Du hast gerade den Regen für dich eingeschaltet."
9696
command-player-time-reset: "&7Du hast gerade die Zeit auf die des Servers geändert."
9797
command-player-time-change: "&7Du hast gerade deine Zeit geändert."
98+
command-lag-world-line: "&a%world%&7: &a%peaceful% friedliche&7, &c%monsters% Monster&7, &e%items% Items"
99+
command-lag-world-header: "&aEntitäten in Welt &2%world%&a:"
100+
command-lag-world-entry: "&7- &a%type%&7: &f%amount%"
98101
command-fly-enable: "&7Flugmodus <success>aktiviert &7für &f%player%<success>."
99102
command-fly-disable: "&7Flugmodus <error>deaktiviert &7für &f%player%<success>."
100103
command-furnace-type: "<error>Es ist unmöglich, das Material &f%material%<error> zu schmelzen."
@@ -317,6 +320,8 @@ description-repair-all: "Alle Gegenstände in deinem Inventar reparieren"
317320
description-ext: "Das Brennen stoppen"
318321
description-near: "Spieler in deiner Nähe anzeigen"
319322
description-play-time: "Spielzeit eines Spielers anzeigen"
323+
description-lag: "Entitätsanzahl pro Welt anzeigen"
324+
description-lag-world: "Detaillierte Entitätsanzahl für eine Welt anzeigen"
320325
description-bottom: "Zum tiefsten Punkt teleportieren"
321326
description-compact-all: "Gegenstände in deinen Inventaren komprimieren"
322327
description-version: "Plugin-Version anzeigen"

src/main/resources/messages/messages_es.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,9 @@ command-player-weather-reset: "&7Acabas de cambiar el clima al del servidor."
8585
command-player-weather-downfall: "&7Acabas de poner la lluvia solo para ti."
8686
command-player-time-reset: "&7Acabas de cambiar la hora al del servidor."
8787
command-player-time-change: "&7Has cambiado tu hora."
88+
command-lag-world-line: "&a%world%&7: &a%peaceful% pacíficas&7, &c%monsters% monstruos&7, &e%items% ítems"
89+
command-lag-world-header: "&aEntidades del mundo &2%world%&a:"
90+
command-lag-world-entry: "&7- &a%type%&7: &f%amount%"
8891
command-fly-enable: "&7Modo vuelo <success>habilitado &7para &f%player%<success>."
8992
command-fly-disable: "&7Modo vuelo <error>deshabilitado &7para &f%player%<success>."
9093
command-furnace-type: "<error>Imposible fundir el material &f%material%<error>."
@@ -299,6 +302,8 @@ description-repair-all: "Reparar todos los objetos en tu inventario"
299302
description-ext: "Detener la quema"
300303
description-near: "Mostrar jugadores cercanos a ti"
301304
description-play-time: "Mostrar el tiempo de juego del jugador"
305+
description-lag: "Mostrar el número de entidades por mundo"
306+
description-lag-world: "Mostrar conteos detallados de entidades para un mundo"
302307
description-bottom: "Teletransportarse al fondo"
303308
description-compact-all: "Compactar los objetos en tus inventarios"
304309
description-version: "Mostrar la versión del plugin"

src/main/resources/messages/messages_fr.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,9 @@ command-player-weather-reset: "&7Vous venez de changer la météo pour celle du
8686
command-player-weather-downfall: "&7Vous venez de mettre la pluie pour vous-même."
8787
command-player-time-reset: "&7Vous venez de changer l'heure pour celle du serveur."
8888
command-player-time-change: "&7Vous êtes ici pour changer votre heure."
89+
command-lag-world-line: "&a%world%&7 : &a%peaceful% pacifiques&7, &c%monsters% monstres&7, &e%items% items"
90+
command-lag-world-header: "&aEntités pour le monde &2%world%&a :"
91+
command-lag-world-entry: "&7- &a%type%&7 : &f%amount%"
8992
command-fly-enable: "&7Mode vol <success>activé &7pour &f%player%<success>."
9093
command-fly-disable: "&7Mode vol <error>désactivé &7pour &f%player%<success>."
9194
command-fly-error-world: "<error>Vous ne pouvez pas voler dans ce monde."
@@ -450,6 +453,8 @@ description-pub: "Envoyer un message mis en avant dans le chat"
450453
description-step: "Afficher les commandes des étapes"
451454
description-step-start: "Commencer une étape"
452455
description-step-finish: "Terminer une étape"
456+
description-lag: "Affiche le nombre d'entités par monde"
457+
description-lag-world: "Affiche des détails sur les entités du monde"
453458

454459
# Format de l'heure
455460
format-second: " seconde"

0 commit comments

Comments
 (0)