Skip to content

Commit

Permalink
Bump version to 1.3.0 & fix entity removal
Browse files Browse the repository at this point in the history
  • Loading branch information
Realizedd committed Feb 25, 2023
1 parent 63d53e7 commit 7d9d545
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,9 @@
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import lombok.Getter;
Expand All @@ -36,7 +34,6 @@
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Entity;

public class Zone {

Expand Down Expand Up @@ -64,8 +61,8 @@ public class Zone {
@Getter
private final Set<ChunkLoc> chunks = new HashSet<>();

@Getter
private final List<Entity> spawnedEntities = new ArrayList<>();
// @Getter
// private final List<Entity> spawnedEntities = new ArrayList<>();

private Set<Position> changedBlocks = new HashSet<>();

Expand Down Expand Up @@ -234,8 +231,14 @@ public String getName() {
return arena.getName();
}

private int calculateSize() {
return (max.getBlockX() - min.getBlockX() + 1)
+ (max.getBlockY() - min.getBlockY() + 1)
+ (max.getBlockZ() - min.getBlockZ() + 1);
}

public int getTotalBlocks() {
return blocks.size();
return config.isTrackBlockChanges() ? calculateSize() : blocks.size();
}

public World getWorld() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
import me.realized.de.arenaregen.ArenaRegen;
import me.realized.de.arenaregen.config.Config;
import me.realized.de.arenaregen.config.Lang;
import me.realized.de.arenaregen.util.ChunkLoc;
import me.realized.de.arenaregen.util.CompatUtil;
import me.realized.duels.api.arena.Arena;
import me.realized.duels.api.event.arena.ArenaRemoveEvent;
import me.realized.duels.api.event.match.MatchEndEvent;
import org.bukkit.Chunk;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.entity.Entity;
Expand All @@ -27,7 +29,6 @@
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.block.LeavesDecayEvent;
import org.bukkit.event.entity.EntityExplodeEvent;
import org.bukkit.event.entity.EntitySpawnEvent;
import org.bukkit.event.world.ChunkUnloadEvent;

public class ZoneListener implements Listener {
Expand All @@ -44,29 +45,16 @@ public ZoneListener(final ArenaRegen extension, final ZoneManager zoneManager) {

@EventHandler(priority = EventPriority.LOWEST)
public void on(final ChunkUnloadEvent event) {
if (!CompatUtil.isPaper() && zoneManager.getZones().stream().anyMatch(zone -> zone.isResetting() && zone.contains(event.getChunk()))) {
event.setCancelled(true);
}
}


@EventHandler(priority = EventPriority. HIGHEST, ignoreCancelled = true)
public void on(final EntitySpawnEvent event) {
if (config.getRemoveEntities().isEmpty()) {
return;
}

final Entity entity = event.getEntity();
for (final Entity entity : event.getChunk().getEntities()) {
if (!(entity instanceof Item) && !config.getRemoveEntities().contains(entity.getType().name().toUpperCase())) {
continue;
}

if (!(entity instanceof Item) && !config.getRemoveEntities().contains(entity.getType().name().toUpperCase())) {
return;
entity.remove();
}

for (final Zone zone : zoneManager.getZones()) {
if (zone.contains(event.getLocation())) {
zone.getSpawnedEntities().add(entity);
break;
}
if (!CompatUtil.isPaper() && zoneManager.getZones().stream().anyMatch(zone -> zone.isResetting() && zone.contains(event.getChunk()))) {
event.setCancelled(true);
}
}

Expand All @@ -79,12 +67,19 @@ public void on(final MatchEndEvent event) {
if (zone == null) {
return;
}

for (final Entity entity : zone.getSpawnedEntities()) {
entity.remove();

for (final ChunkLoc chunkLoc : zone.getChunks()) {
final Chunk chunk = zone.getWorld().getChunkAt(chunkLoc.getX(), chunkLoc.getZ());

for (final Entity entity : chunk.getEntities()) {
if (!(entity instanceof Item) && !config.getRemoveEntities().contains(entity.getType().name().toUpperCase())) {
continue;
}

entity.remove();
}
}

zone.getSpawnedEntities().clear();

zone.reset();
}

Expand Down
8 changes: 4 additions & 4 deletions arenaregen/src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ experimental:
# If enabled, the extension will track block changes made by players during the match instead of scanning
# the entire arena after the match to locate the block changes. While much more efficient, this method
# is unable to detect block changes caused by other plugins. If you're using such a plugin, avoid this option!
# default: false
track-block-changes: false
# default: true
track-block-changes: true

# Blocks to reset per tick.
blocks-per-tick: 100
Expand All @@ -26,8 +26,8 @@ block-reset-handler-version: auto
remove-dropped-items: true

# Remove entities in the reset zone when the match ends.
# default: [ENDER_CRYSTAL]
remove-entities: [ENDER_CRYSTAL]
# default: [ENDER_CRYSTAL, MINECART_TNT]
remove-entities: [ENDER_CRYSTAL, MINECART_TNT]

# Prevent blocks in the reset zone from burning.
# default: true
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ buildscript {

allprojects {
group 'me.realized.de'
version '1.3.0-SNAPSHOT'
version '1.3.0'
}

subprojects {
Expand Down

0 comments on commit 7d9d545

Please sign in to comment.