mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-22 05:06:44 +01:00
Add some more listeners
- Also use setShouldAbortSpawn so it doesn't just try forever - Add config to enable or disable all paper listeners
This commit is contained in:
parent
85a75ad868
commit
c6dc9ee189
@ -637,8 +637,7 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain
|
||||
final PlayerEvents main = new PlayerEvents();
|
||||
getServer().getPluginManager().registerEvents(main, this);
|
||||
getServer().getPluginManager().registerEvents(new EntitySpawnListener(), this);
|
||||
if (PaperLib.isPaper() && Settings.Paper_Components.ENTITY_PATHING
|
||||
|| Settings.Paper_Components.PRE_SPAWN_LISTENER) {
|
||||
if (PaperLib.isPaper() && Settings.Paper_Components.PAPER_LISTENERS) {
|
||||
getServer().getPluginManager().registerEvents(new PaperListener(), this);
|
||||
}
|
||||
PlotListener.startRunnable();
|
||||
|
@ -27,20 +27,29 @@ package com.plotsquared.bukkit.listener;
|
||||
|
||||
import com.destroystokyo.paper.entity.Pathfinder;
|
||||
import com.destroystokyo.paper.event.entity.EntityPathfindEvent;
|
||||
import com.destroystokyo.paper.event.entity.PlayerNaturallySpawnCreaturesEvent;
|
||||
import com.destroystokyo.paper.event.entity.PreCreatureSpawnEvent;
|
||||
import com.destroystokyo.paper.event.entity.PreSpawnerSpawnEvent;
|
||||
import com.destroystokyo.paper.event.entity.SlimePathfindEvent;
|
||||
import com.destroystokyo.paper.event.player.PlayerLaunchProjectileEvent;
|
||||
import com.plotsquared.bukkit.util.BukkitUtil;
|
||||
import com.plotsquared.core.PlotSquared;
|
||||
import com.plotsquared.core.configuration.Settings;
|
||||
import com.plotsquared.core.location.Location;
|
||||
import com.plotsquared.core.player.PlotPlayer;
|
||||
import com.plotsquared.core.plot.Plot;
|
||||
import com.plotsquared.core.plot.PlotArea;
|
||||
import com.plotsquared.core.plot.flag.implementations.DoneFlag;
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.Projectile;
|
||||
import org.bukkit.entity.ThrownPotion;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.CreatureSpawnEvent;
|
||||
import org.bukkit.projectiles.ProjectileSource;
|
||||
|
||||
/**
|
||||
* Events specific to Paper. Some toit nups here
|
||||
@ -132,9 +141,6 @@ public class PaperListener implements Listener {
|
||||
}
|
||||
|
||||
@EventHandler public void onPreCreatureSpawnEvent(PreCreatureSpawnEvent event) {
|
||||
if (!Settings.Paper_Components.PRE_SPAWN_LISTENER) {
|
||||
return;
|
||||
}
|
||||
Location location = BukkitUtil.getLocation(event.getSpawnLocation());
|
||||
PlotArea area = location.getPlotArea();
|
||||
if (!location.isPlotArea()) {
|
||||
@ -143,6 +149,7 @@ public class PaperListener implements Listener {
|
||||
//If entities are spawning... the chunk should be loaded?
|
||||
Entity[] entities = event.getSpawnLocation().getChunk().getEntities();
|
||||
if (entities.length > Settings.Chunk_Processor.MAX_ENTITIES) {
|
||||
event.setShouldAbortSpawn(true);
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
@ -153,6 +160,7 @@ public class PaperListener implements Listener {
|
||||
case OCELOT_BABY:
|
||||
case SPAWNER_EGG:
|
||||
if (!area.isSpawnEggs()) {
|
||||
event.setShouldAbortSpawn(true);
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
@ -171,11 +179,13 @@ public class PaperListener implements Listener {
|
||||
case BEEHIVE:
|
||||
case CHUNK_GEN:
|
||||
if (!area.isMobSpawning()) {
|
||||
event.setShouldAbortSpawn(true);
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
case BREEDING:
|
||||
if (!area.isSpawnBreeding()) {
|
||||
event.setShouldAbortSpawn(true);
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
@ -185,12 +195,14 @@ public class PaperListener implements Listener {
|
||||
case BUILD_WITHER:
|
||||
case CUSTOM:
|
||||
if (!area.isSpawnCustom() && event.getType() != EntityType.ARMOR_STAND) {
|
||||
event.setShouldAbortSpawn(true);
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
break;
|
||||
case SPAWNER:
|
||||
if (!area.isMobSpawnerSpawning()) {
|
||||
event.setShouldAbortSpawn(true);
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
@ -203,17 +215,67 @@ public class PaperListener implements Listener {
|
||||
switch (type) {
|
||||
case DROPPED_ITEM:
|
||||
if (Settings.Enabled_Components.KILL_ROAD_ITEMS) {
|
||||
event.setShouldAbortSpawn(true);
|
||||
event.setCancelled(true);
|
||||
break;
|
||||
}
|
||||
case PLAYER:
|
||||
return;
|
||||
}
|
||||
event.setShouldAbortSpawn(true);
|
||||
event.setCancelled(true);
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (Settings.Done.RESTRICT_BUILDING && DoneFlag.isDone(plot)) {
|
||||
event.setShouldAbortSpawn(true);
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerNaturallySpawnCreaturesEvent(PlayerNaturallySpawnCreaturesEvent event) {
|
||||
if (Settings.Paper_Components.CANCEL_CHUNK_SPAWN) {
|
||||
Location location = BukkitUtil.getLocation(event.getPlayer().getLocation());
|
||||
PlotArea area = location.getPlotArea();
|
||||
if (area != null && !area.isMobSpawning()) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler public void onPreSpawnerSpawnEvent(PreSpawnerSpawnEvent event) {
|
||||
Location location = BukkitUtil.getLocation(event.getSpawnerLocation());
|
||||
PlotArea area = location.getPlotArea();
|
||||
if (area != null && !area.isMobSpawnerSpawning()) {
|
||||
event.setCancelled(true);
|
||||
event.setShouldAbortSpawn(true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Unsure if this will be any performance improvement over the spigot version,
|
||||
* but here it is anyway :)
|
||||
*
|
||||
* @param event Paper's PlayerLaunchProjectileEvent
|
||||
*/
|
||||
@EventHandler public void onProjectileLaunch(PlayerLaunchProjectileEvent event) {
|
||||
Projectile entity = event.getProjectile();
|
||||
if (!(entity instanceof ThrownPotion)) {
|
||||
return;
|
||||
}
|
||||
ProjectileSource shooter = entity.getShooter();
|
||||
if (!(shooter instanceof Player)) {
|
||||
return;
|
||||
}
|
||||
Location location = BukkitUtil.getLocation(entity);
|
||||
if (!PlotSquared.get().hasPlotArea(location.getWorld())) {
|
||||
return;
|
||||
}
|
||||
PlotPlayer pp = BukkitUtil.getPlayer((Player) shooter);
|
||||
Plot plot = location.getOwnedPlot();
|
||||
if (plot != null && !plot.isAdded(pp.getUUID())) {
|
||||
entity.remove();
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
@ -359,8 +359,11 @@ public class Settings extends Config {
|
||||
|
||||
@Comment("Enable or disable parts of the plugin specific to using Paper")
|
||||
public static final class Paper_Components {
|
||||
@Comment("Enable Paper's listeners.") public static boolean PAPER_LISTENERS = true;
|
||||
@Comment("Prevent entities from leaving plots") public static boolean ENTITY_PATHING = true;
|
||||
@Comment("Use paper's PreCreatureSpawnEvent") public static boolean PRE_SPAWN_LISTENER = true;
|
||||
@Comment(
|
||||
"Cancel entity spawns when the chunk is loaded if the PlotArea's mob spawning is off")
|
||||
public static boolean CANCEL_CHUNK_SPAWN = true;
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user