Skip to content

Commit

Permalink
* Added minecart to the entities Limit
Browse files Browse the repository at this point in the history
(Limit for minecarts it is the total entites-pet-chunk limit)
  • Loading branch information
PonnyTheLight committed Feb 19, 2023
1 parent 51c6b9a commit 9a03737
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 14 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>es.ponnythelight</groupId>
<artifactId>ChunkEntityLimiter</artifactId>
<version>1.1.3-SNAPSHOT</version>
<version>1.1.4-SNAPSHOT</version>
<packaging>jar</packaging>

<name>ChunkEntityLimiter</name>
Expand Down
66 changes: 53 additions & 13 deletions src/main/java/es/ponnythelight/listeners/checkListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.entity.Vehicle;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.entity.CreatureSpawnEvent;
import org.bukkit.event.player.PlayerDropItemEvent;
import org.bukkit.event.vehicle.VehicleCreateEvent;
import org.bukkit.event.world.ChunkLoadEvent;

import java.util.Arrays;
Expand Down Expand Up @@ -140,19 +142,6 @@ public void playerDropItem(PlayerDropItemEvent e) {

AtomicInteger counti = new AtomicInteger();

// en.stream().forEach(k -> {
//
// if (k.getType().equals(EntityType.DROPPED_ITEM)) {
// counti.getAndIncrement();
//
// if (counti.get() >= config.getInt("Config.dropped-items-per-chunk")) {
// System.out.println("Spawn");
// e.setCancelled(true);
// return player.sendMessage(ChatColor.translateAlternateColorCodes('&', config.getString("Messages.prefix") + config.getString("Messages.max-dropped-items")));
// }
//
// }
// });

for (Entity i : en) {
if (i.getType().equals(EntityType.DROPPED_ITEM)) {
Expand All @@ -168,5 +157,56 @@ public void playerDropItem(PlayerDropItemEvent e) {
}
}

@EventHandler
public void PlayerInteract(VehicleCreateEvent e) {
Configuration config = plugin.getConfig();
Vehicle v = e.getVehicle();

Chunk chunk = v.getLocation().getChunk();

List<Entity> en = Arrays.asList(chunk.getEntities());
AtomicInteger countp = new AtomicInteger();

en.forEach(k -> {
if (k.getType().equals(EntityType.MINECART)) {
countp.getAndIncrement();

if (countp.get() >= config.getInt("Config.entities-per-chunk")) {
e.setCancelled(true);
}
} else if (k.getType().equals(EntityType.MINECART_CHEST)) {
countp.getAndIncrement();

if (countp.get() >= config.getInt("Config.entities-per-chunk")) {
e.setCancelled(true);
}
} else if (k.getType().equals(EntityType.MINECART_FURNACE)) {
countp.getAndIncrement();

if (countp.get() >= config.getInt("Config.entities-per-chunk")) {
e.setCancelled(true);
}
} else if (k.getType().equals(EntityType.MINECART_HOPPER)) {
countp.getAndIncrement();

if (countp.get() >= config.getInt("Config.entities-per-chunk")) {
e.setCancelled(true);
}
} else if (k.getType().equals(EntityType.MINECART_TNT)) {
countp.getAndIncrement();

if (countp.get() >= config.getInt("Config.entities-per-chunk")) {
e.setCancelled(true);
}
} else if (k.getType().equals(EntityType.MINECART_MOB_SPAWNER)) {
countp.getAndIncrement();

if (countp.get() >= config.getInt("Config.entities-per-chunk")) {
e.setCancelled(true);
}
}
});
}


}

0 comments on commit 9a03737

Please sign in to comment.