Skip to content

Commit

Permalink
fix: command name and readme
Browse files Browse the repository at this point in the history
  • Loading branch information
Nathan committed Apr 21, 2024
1 parent 776fa8d commit efed108
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 21 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ This project was inspired by the work on [ArmorStand-Limiter](https://github.com

# Support

[![support image](https://www.heroxwar.com/discordLogo.png)](https://discord.com/invite/3QGe3ts)
[![support image](https://www.heroxwar.com/discordLogo.png)](https://discord.gg/5qQbJq45QY)

**[https://discord.com/invite/3QGe3ts](https://discord.com/invite/3QGe3ts)**
**[https://discord.com/invite/3QGe3ts](https://discord.gg/5qQbJq45QY)**


# Download
Expand Down
48 changes: 36 additions & 12 deletions src/main/java/com/expectale/entitylimiter/Checker.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@

import java.awt.Color;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;


public class Checker {
Expand Down Expand Up @@ -100,21 +102,43 @@ public static void removeEntities(EntityType type) {
}
}

public static void sendInGameCheck(Player player, Chunk chunk, EntityType type) {
final EntityLimiterConfiguration configuration = EntityLimiter.getINSTANCE().getConfiguration();
public static List<Chunk> getChunksAround(Chunk chunk, int radius) {
int chunkX = chunk.getX();
int chunkZ = chunk.getZ();
int minX = chunkX - radius;
int minZ = chunkZ - radius;
int maxX = chunkX + radius;
int maxZ = chunkZ + radius;

List<Chunk> chunks = new ArrayList<>();
for (int x = minX; x <= maxX; x++) {
for (int z = minZ; z <= maxZ; z++) {
chunks.add(chunk.getWorld().getChunkAt(x, z));
}
}

return chunks;
}

public static void sendInGameCheck(Player player, List<Chunk> chunks, EntityType type) {
StringBuilder players = new StringBuilder();

for (Entity entity : chunk.getWorld().getNearbyLivingEntities(new Location(chunk.getWorld(), chunk.getX() * 16, 150, chunk.getZ() * 16), 150)) {
Chunk centerChunk = chunks.get(chunks.size() / 2);
for (Entity entity : centerChunk.getWorld().getNearbyLivingEntities(new Location(centerChunk.getWorld(), centerChunk.getX() * 16, 150, centerChunk.getZ() * 16), 150)) {
if (entity instanceof Player) {
players.append(" ").append(entity.getName());
}
}
player.sendMessage(ChatColor.YELLOW + "Check Entity Limiter :");
player.sendMessage(ChatColor.GRAY + "- World " + chunk.getWorld().getName());
player.sendMessage(ChatColor.GRAY + "- X " + chunk.getX() * 16);
player.sendMessage(ChatColor.GRAY + "- Z " + chunk.getZ() * 16);
player.sendMessage(ChatColor.GRAY + "- Nearby players (150 blocks) " + ((players.length() == 0) ? "NONE" : players.toString()));
player.sendMessage(ChatColor.GRAY + "- Counter " + countEntityInChunk(chunk, type) + "/" + configuration.getChunkLimit());
int counter = 0;
for (Chunk chunk : chunks) {
counter += countEntityInChunk(chunk, type);
}
player.sendMessage(ChatColor.YELLOW + "Check Entity Limiter (" + type.toString() + ") :");
player.sendMessage(ChatColor.GRAY + "- World " + centerChunk.getWorld().getName());
player.sendMessage(ChatColor.GRAY + "- X " + centerChunk.getX() * 16);
player.sendMessage(ChatColor.GRAY + "- Z " + centerChunk.getZ() * 16);
player.sendMessage(ChatColor.GRAY + "- Nearby players (150 blocks) " + ((players.length() == 0) ? (ChatColor.RED + "NONE") : players.toString()));
player.sendMessage(ChatColor.GRAY + "- Counter " + counter);
}

public static void sendInGameAlert(Player player, Chunk chunk, EntityType type) {
Expand Down Expand Up @@ -145,8 +169,8 @@ public static void sendDiscordAlert(Chunk chunk, EntityType type) {
}

DiscordWebhook webhook = new DiscordWebhook(configuration.getDiscordWebhook());
webhook.setAvatarUrl("https://upload.wikimedia.org/wikipedia/commons/thumb/3/3b/OOjs_UI_icon_alert-warning.svg/1024px-OOjs_UI_icon_alert-warning.svg.png");
webhook.setUsername("Alert !");
webhook.setAvatarUrl("https://labocraft.fr/storage/img/logo64x64.png");
webhook.setUsername("Entity-Limiter");
webhook.setTts(false);
webhook.addEmbed(new DiscordWebhook.EmbedObject()
.setTitle("A significant number of entites ("+ type.toString() +") have been removed")
Expand All @@ -157,7 +181,7 @@ public static void sendDiscordAlert(Chunk chunk, EntityType type) {
.addField("Z", chunk.getZ() * 16 + "", false)
.addField("Nearby players (150 blocks)", (players.length() == 0) ? "NONE" : players.toString(), false)
.addField("Counter", countEntityInChunk(chunk, type) + "/" + configuration.getChunkLimit(), false)
.setAuthor("Entity-Limiter", "https://labocraft.fr", "https://labocraft.fr/storage/img/logo64x64.png")
.setAuthor("Entity-Limiter Alert", "https://labocraft.fr", "https://upload.wikimedia.org/wikipedia/commons/thumb/3/3b/OOjs_UI_icon_alert-warning.svg/1024px-OOjs_UI_icon_alert-warning.svg.png")
);
try {
webhook.execute();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public void reloadConfig() {
public void onEnable() {
INSTANCE = this;
reloadConfig();
getCommand("ml").setExecutor(new EntityLimiterCommand());
getCommand("entity-limiter").setExecutor(new EntityLimiterCommand());
getServer().getPluginManager().registerEvents(new EntityListener(), this);
getLogger().info("EntityLimiter is enabled");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,60 @@

import com.expectale.entitylimiter.Checker;
import com.expectale.entitylimiter.EntityLimiter;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Chunk;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;

import java.util.List;

public class EntityLimiterCommand implements CommandExecutor {

private void sendHelpMessage(CommandSender sender) {
sender.sendMessage(ChatColor.YELLOW + "Usage Entity Limiter : ");
sender.sendMessage(ChatColor.GRAY + "- /ml reload ");
sender.sendMessage(ChatColor.GRAY + "- /ml check [<player>] [<radius>]");
}

@Override
public boolean onCommand(CommandSender sender, Command cmd, String msg, String[] args) {

if (sender instanceof Player) {
if (args.length == 1 && args[0].equalsIgnoreCase("reload")) {
EntityLimiter.getINSTANCE().reloadConfig();
sender.sendMessage(ChatColor.YELLOW + "The configuration file has been successfully reloaded");
} else if (args.length == 1 && args[0].equalsIgnoreCase("check")) {
sender.sendMessage(ChatColor.YELLOW + "SOON");
} else if (args.length >= 1 && args[0].equalsIgnoreCase("check")) {
Chunk chunk = ((Player)sender).getChunk();
int radius = 1;
if (args.length >= 2) {
Player player = Bukkit.getPlayer(args[1]);
if (player != null) {
chunk = player.getChunk();
} else {
sender.sendMessage(ChatColor.RED + "Can't find player " + args[1]);
sendHelpMessage(sender);
return true;
}
}
if (args.length >= 3) {
try {
radius = Integer.parseInt(args[2]);
} catch (Exception exception) {
sender.sendMessage(ChatColor.RED + "Invalid radius " + args[2]);
sendHelpMessage(sender);
return true;
}
}
List<Chunk> chunks = Checker.getChunksAround(chunk, radius);
for (EntityType type : EntityLimiter.getINSTANCE().getConfiguration().getEntityType()) {
Checker.sendInGameCheck((Player)sender, ((Player)sender).getChunk(), type);
Checker.sendInGameCheck((Player)sender, chunks, type);
}
} else {
sender.sendMessage(ChatColor.YELLOW + "Usage Entity Limiter : ");
sender.sendMessage(ChatColor.GRAY + "- /ml reload ");
sender.sendMessage(ChatColor.GRAY + "- /ml check");
sendHelpMessage(sender);
}
}
return true;
Expand Down

0 comments on commit efed108

Please sign in to comment.