mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-22 13:16:45 +01:00
Add paper specific listener for limiting the amount of tile entities in a chunk during build, instead of just doing it during chunk unloading
This commit is contained in:
parent
d20fa39cf5
commit
3deff629b0
@ -33,6 +33,7 @@ import com.destroystokyo.paper.event.entity.SlimePathfindEvent;
|
|||||||
import com.destroystokyo.paper.event.player.PlayerLaunchProjectileEvent;
|
import com.destroystokyo.paper.event.player.PlayerLaunchProjectileEvent;
|
||||||
import com.plotsquared.bukkit.util.BukkitUtil;
|
import com.plotsquared.bukkit.util.BukkitUtil;
|
||||||
import com.plotsquared.core.PlotSquared;
|
import com.plotsquared.core.PlotSquared;
|
||||||
|
import com.plotsquared.core.configuration.Captions;
|
||||||
import com.plotsquared.core.configuration.Settings;
|
import com.plotsquared.core.configuration.Settings;
|
||||||
import com.plotsquared.core.location.Location;
|
import com.plotsquared.core.location.Location;
|
||||||
import com.plotsquared.core.player.PlotPlayer;
|
import com.plotsquared.core.player.PlotPlayer;
|
||||||
@ -41,6 +42,7 @@ import com.plotsquared.core.plot.PlotArea;
|
|||||||
import com.plotsquared.core.plot.flag.implementations.DoneFlag;
|
import com.plotsquared.core.plot.flag.implementations.DoneFlag;
|
||||||
import org.bukkit.Chunk;
|
import org.bukkit.Chunk;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
|
import org.bukkit.block.TileState;
|
||||||
import org.bukkit.entity.Entity;
|
import org.bukkit.entity.Entity;
|
||||||
import org.bukkit.entity.EntityType;
|
import org.bukkit.entity.EntityType;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
@ -48,7 +50,9 @@ import org.bukkit.entity.Projectile;
|
|||||||
import org.bukkit.entity.Slime;
|
import org.bukkit.entity.Slime;
|
||||||
import org.bukkit.entity.ThrownPotion;
|
import org.bukkit.entity.ThrownPotion;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.EventPriority;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.block.BlockPlaceEvent;
|
||||||
import org.bukkit.event.entity.CreatureSpawnEvent;
|
import org.bukkit.event.entity.CreatureSpawnEvent;
|
||||||
import org.bukkit.projectiles.ProjectileSource;
|
import org.bukkit.projectiles.ProjectileSource;
|
||||||
|
|
||||||
@ -252,6 +256,27 @@ public class PaperListener implements Listener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.HIGHEST) public void onBlockPlace(BlockPlaceEvent event) {
|
||||||
|
if (!Settings.Paper_Components.TILE_ENTITY_CHECK) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!(event.getBlock().getState(false) instanceof TileState)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
final Location location = BukkitUtil.getLocation(event.getBlock().getLocation());
|
||||||
|
final PlotArea plotArea = location.getPlotArea();
|
||||||
|
if (plotArea == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
final int tileEntityCount = event.getBlock().getChunk().getTileEntities(false).length;
|
||||||
|
if (tileEntityCount >= Settings.Chunk_Processor.MAX_TILES) {
|
||||||
|
final PlotPlayer plotPlayer = BukkitUtil.getPlayer(event.getPlayer());
|
||||||
|
Captions.TILE_ENTITY_CAP_REACHED.send(plotPlayer, Settings.Chunk_Processor.MAX_TILES);
|
||||||
|
event.setCancelled(true);
|
||||||
|
event.setBuild(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unsure if this will be any performance improvement over the spigot version,
|
* Unsure if this will be any performance improvement over the spigot version,
|
||||||
* but here it is anyway :)
|
* but here it is anyway :)
|
||||||
|
@ -446,6 +446,7 @@ public enum Captions implements Caption {
|
|||||||
NOT_VALID_PLOT_WORLD("$2That is not a valid plot area (case sensitive)", "Errors"),
|
NOT_VALID_PLOT_WORLD("$2That is not a valid plot area (case sensitive)", "Errors"),
|
||||||
NO_PLOTS("$2You don't have any plots", "Errors"),
|
NO_PLOTS("$2You don't have any plots", "Errors"),
|
||||||
WAIT_FOR_TIMER("$2A set block timer is bound to either the current plot or you. Please wait for it to finish", "Errors"),
|
WAIT_FOR_TIMER("$2A set block timer is bound to either the current plot or you. Please wait for it to finish", "Errors"),
|
||||||
|
TILE_ENTITY_CAP_REACHED("$2The total number of tile entities in this chunk may not exceed $1%s", "Errors"),
|
||||||
//</editor-fold>
|
//</editor-fold>
|
||||||
DEBUG_REPORT_CREATED("$1Uploaded a full debug to: $1%url%", "Paste"),
|
DEBUG_REPORT_CREATED("$1Uploaded a full debug to: $1%url%", "Paste"),
|
||||||
PURGE_SUCCESS("$4Successfully purged %s plots", "Purge"),
|
PURGE_SUCCESS("$4Successfully purged %s plots", "Purge"),
|
||||||
|
@ -484,6 +484,8 @@ public class Settings extends Config {
|
|||||||
public static boolean SPAWNER_SPAWN = true;
|
public static boolean SPAWNER_SPAWN = true;
|
||||||
@Comment("Cancel entity spawns from tick spawn rates before they happen (performance buff)")
|
@Comment("Cancel entity spawns from tick spawn rates before they happen (performance buff)")
|
||||||
public static boolean CREATURE_SPAWN = true;
|
public static boolean CREATURE_SPAWN = true;
|
||||||
|
@Comment("Check the tile entity limit on block placement")
|
||||||
|
public static boolean TILE_ENTITY_CHECK = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user