Skip to content

Commit

Permalink
feat: generic entity support
Browse files Browse the repository at this point in the history
  • Loading branch information
Nathan Fain committed Apr 21, 2024
1 parent 8a0161b commit 776fa8d
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 11 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ This project was inspired by the work on [ArmorStand-Limiter](https://github.com

## Commands
* **/ml reload** - *Reload the config file (Perms: `entitylimiter.use`)*
* **/asl check** - *Show how many minecart/boat/armorstand there are in your actual chunk (Perms: `entitylimiter.use`)*
* **/ml check** - *Show how many minecart/boat/armorstand there are in your actual chunk (Perms: `entitylimiter.use`)*

# Support

Expand All @@ -27,4 +27,4 @@ This project was inspired by the work on [ArmorStand-Limiter](https://github.com


# Download
**[https://github.com/LaboCraft/Minecart-Limiter/releases/tag/latest](https://github.com/LaboCraft/Minecart-Limiter/releases/tag/latest)**
**[https://github.com/LaboCraft/Entity-Limiter/releases/tag/latest](https://github.com/LaboCraft/Entity-Limiter/releases/tag/latest)**
12 changes: 7 additions & 5 deletions src/main/java/com/expectale/entitylimiter/Checker.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
public class Checker {

private static BukkitRunnable task = null;
private static HashSet<Chunk> chunksCheched = new HashSet<>();
private static final HashSet<Chunk> chunksCheched = new HashSet<>();

public static void start() {
final EntityLimiterConfiguration configuration = EntityLimiter.getINSTANCE().getConfiguration();
Expand All @@ -27,12 +27,14 @@ public static void start() {
@Override
public void run() {
if (configuration.isTPSMeter() && Bukkit.getTPS()[0] < configuration.getTPSMeterTrigger()) {
removeEntities(EntityType.BOAT);
removeEntities(EntityType.MINECART);
for (EntityType type : EntityLimiter.getINSTANCE().getConfiguration().getEntityType()) {
removeEntities(type);
}
}
if (configuration.isChunkTask() && System.currentTimeMillis() > lastChunkCheck + (long) configuration.getChunkTaskRefresh() * 60 * 1000) {
removeEntities(EntityType.BOAT);
removeEntities(EntityType.MINECART);
for (EntityType type : EntityLimiter.getINSTANCE().getConfiguration().getEntityType()) {
removeEntities(type);
}
lastChunkCheck = System.currentTimeMillis();
}
chunksCheched.clear();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ public boolean onCommand(CommandSender sender, Command cmd, String msg, String[]
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");
Checker.sendInGameCheck((Player)sender, ((Player)sender).getChunk(), EntityType.MINECART);
Checker.sendInGameCheck((Player)sender, ((Player)sender).getChunk(), EntityType.BOAT);
Checker.sendInGameCheck((Player)sender, ((Player)sender).getChunk(), EntityType.ARMOR_STAND);
for (EntityType type : EntityLimiter.getINSTANCE().getConfiguration().getEntityType()) {
Checker.sendInGameCheck((Player)sender, ((Player)sender).getChunk(), type);
}
} else {
sender.sendMessage(ChatColor.YELLOW + "Usage Entity Limiter : ");
sender.sendMessage(ChatColor.GRAY + "- /ml reload ");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.expectale.entitylimiter.configuration;

import com.expectale.entitylimiter.EntityLimiter;
import org.bukkit.configuration.Configuration;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.EntityType;

import java.util.ArrayList;
import java.util.List;
Expand All @@ -14,6 +16,7 @@ public class EntityLimiterConfiguration {

private List<String> disabledWorlds = new ArrayList<>();
private List<String> disableIfNameContains = new ArrayList<>();
private List<EntityType> entityType = new ArrayList<>();

private boolean TPSMeter = false;
private int TPSMeterTrigger = 17;
Expand Down Expand Up @@ -55,6 +58,22 @@ public void reload(final Configuration configuration) {
}
}

if (configuration.isConfigurationSection("Entity")) {
ConfigurationSection checksConfiguration = configuration.getConfigurationSection("Entity");
if (checksConfiguration != null && checksConfiguration.isList("Entities")) {
List<String> entities = checksConfiguration.getStringList("Entities");
entityType.clear();
for (String entity : entities) {
EntityType type = EntityType.fromName(entity);
if (type != null) {
entityType.add(type);
} else {
EntityLimiter.getINSTANCE().getLogger().warning("Invalid entity type : " + entity);
}
}
}
}

if (configuration.isConfigurationSection("TPSMeter")) {
ConfigurationSection TPSMeterConfiguration = configuration.getConfigurationSection("TPSMeter");
if (TPSMeterConfiguration != null && TPSMeterConfiguration.isBoolean("Enabled")) {
Expand Down Expand Up @@ -96,6 +115,10 @@ public List<String> getDisableIfNameContains() {
return disableIfNameContains;
}

public List<EntityType> getEntityType() {
return entityType;
}

public boolean isTPSMeter() {
return TPSMeter;
}
Expand Down
7 changes: 7 additions & 0 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ Checks:
DisableIfNameContains:
- 'CustomName'

Entity:
# Entity type to check seen : https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/entity/EntityType.html
Entities:
- BOAT
- ARMOR_STAND
- MINECART

# TPS Meter will allow you to analyze the tps every tick,
# if they are lower than the preset value in 'Trigger' the Entity
# will be cleared only if they are more than 'Chunk -> Trigger' in a single chunk
Expand Down
3 changes: 2 additions & 1 deletion src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ description: allows you to limit entity
website: labocraft.fr

commands:
ml:
entity-limiter:
aliases: [ "el" ]
permission: entitylimiter.use
description: This command is used to limit the number of entities in a chunk

Expand Down

0 comments on commit 776fa8d

Please sign in to comment.