Skip to content

Commit

Permalink
Allow console to run /countallentities
Browse files Browse the repository at this point in the history
  • Loading branch information
andrew121410 committed Jun 4, 2024
1 parent bf51546 commit 7ac3ac9
Showing 1 changed file with 5 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;

import java.util.ArrayList;
import java.util.Arrays;
Expand All @@ -37,13 +36,8 @@ public CountAllEntitiesCMD(World16Essentials plugin) {

@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
if (!(sender instanceof Player player)) {
sender.sendMessage("Only Players Can Use This Command.");
return true;
}

if (!player.hasPermission("world16.countallentities")) {
api.sendPermissionErrorMessage(player);
if (!sender.hasPermission("world16.countallentities")) {
api.sendPermissionErrorMessage(sender);
return true;
}

Expand All @@ -53,7 +47,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String label, String
allEntities.addAll(world.getEntities());
}

player.sendMessage(Translate.color("&aThere are &e" + allEntities.size() + " &aentities on the server."));
sender.sendMessage(Translate.color("&aThere are &e" + allEntities.size() + " &aentities on the server."));
} else {
EntityType entityType = null;
try {
Expand All @@ -62,7 +56,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String label, String
}

if (entityType == null) {
player.sendMessage(Translate.color("&cInvalid Entity Type."));
sender.sendMessage(Translate.color("&cInvalid Entity Type."));
return true;
}

Expand All @@ -74,7 +68,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String label, String
entities.addAll(world.getEntitiesByClass(entityType.getEntityClass()));
}

player.sendMessage(Translate.color("&a&lTotal Entities: &f" + entities.size() + " &aof type &f" + entityType.name()));
sender.sendMessage(Translate.color("&a&lTotal Entities: &f" + entities.size() + " &aof type &f" + entityType.name()));
}
return true;
}
Expand Down

0 comments on commit 7ac3ac9

Please sign in to comment.