mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-21 20:56:45 +01:00
Entity#getEntitySpawnReason compatibility for spigot (#4305)
chore: Entity#getEntitySpawnReason compatibility for spigot
This commit is contained in:
parent
966c878a72
commit
448577774a
@ -779,8 +779,11 @@ public final class BukkitPlatform extends JavaPlugin implements Listener, PlotPl
|
|||||||
Iterator<Entity> iterator = entities.iterator();
|
Iterator<Entity> iterator = entities.iterator();
|
||||||
while (iterator.hasNext()) {
|
while (iterator.hasNext()) {
|
||||||
Entity entity = iterator.next();
|
Entity entity = iterator.next();
|
||||||
final String spawnReason = entity.getEntitySpawnReason().name();
|
if (PaperLib.isPaper() && "CUSTOM".equals(entity.getEntitySpawnReason().name())) {
|
||||||
if ("CUSTOM".equals(spawnReason)) {
|
continue;
|
||||||
|
}
|
||||||
|
// Fallback for Spigot not having Entity#getEntitySpawnReason
|
||||||
|
if (entity.getMetadata("ps_custom_spawned").stream().anyMatch(MetadataValue::asBoolean)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
switch (entity.getType().toString()) {
|
switch (entity.getType().toString()) {
|
||||||
|
@ -19,6 +19,7 @@
|
|||||||
package com.plotsquared.bukkit.listener;
|
package com.plotsquared.bukkit.listener;
|
||||||
|
|
||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
|
import com.plotsquared.bukkit.BukkitPlatform;
|
||||||
import com.plotsquared.bukkit.player.BukkitPlayer;
|
import com.plotsquared.bukkit.player.BukkitPlayer;
|
||||||
import com.plotsquared.bukkit.util.BukkitEntityUtil;
|
import com.plotsquared.bukkit.util.BukkitEntityUtil;
|
||||||
import com.plotsquared.bukkit.util.BukkitUtil;
|
import com.plotsquared.bukkit.util.BukkitUtil;
|
||||||
@ -41,6 +42,7 @@ import com.plotsquared.core.util.EventDispatcher;
|
|||||||
import com.plotsquared.core.util.PlotFlagUtil;
|
import com.plotsquared.core.util.PlotFlagUtil;
|
||||||
import com.sk89q.worldedit.bukkit.BukkitAdapter;
|
import com.sk89q.worldedit.bukkit.BukkitAdapter;
|
||||||
import com.sk89q.worldedit.world.block.BlockType;
|
import com.sk89q.worldedit.world.block.BlockType;
|
||||||
|
import io.papermc.lib.PaperLib;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.Particle;
|
import org.bukkit.Particle;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
@ -78,15 +80,18 @@ import java.util.List;
|
|||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
public class EntityEventListener implements Listener {
|
public class EntityEventListener implements Listener {
|
||||||
|
|
||||||
|
private final BukkitPlatform platform;
|
||||||
private final PlotAreaManager plotAreaManager;
|
private final PlotAreaManager plotAreaManager;
|
||||||
private final EventDispatcher eventDispatcher;
|
private final EventDispatcher eventDispatcher;
|
||||||
private float lastRadius;
|
private float lastRadius;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public EntityEventListener(
|
public EntityEventListener(
|
||||||
|
final @NonNull BukkitPlatform platform,
|
||||||
final @NonNull PlotAreaManager plotAreaManager,
|
final @NonNull PlotAreaManager plotAreaManager,
|
||||||
final @NonNull EventDispatcher eventDispatcher
|
final @NonNull EventDispatcher eventDispatcher
|
||||||
) {
|
) {
|
||||||
|
this.platform = platform;
|
||||||
this.plotAreaManager = plotAreaManager;
|
this.plotAreaManager = plotAreaManager;
|
||||||
this.eventDispatcher = eventDispatcher;
|
this.eventDispatcher = eventDispatcher;
|
||||||
}
|
}
|
||||||
@ -170,7 +175,18 @@ public class EntityEventListener implements Listener {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case "BUILD_IRONGOLEM", "BUILD_SNOWMAN", "BUILD_WITHER", "CUSTOM" -> {
|
case "CUSTOM" -> {
|
||||||
|
if (!area.isSpawnCustom()) {
|
||||||
|
event.setCancelled(true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// No need to clutter metadata if running paper
|
||||||
|
if (!PaperLib.isPaper()) {
|
||||||
|
entity.setMetadata("ps_custom_spawned", new FixedMetadataValue(this.platform, true));
|
||||||
|
}
|
||||||
|
return; // Don't cancel if mob spawning is disabled
|
||||||
|
}
|
||||||
|
case "BUILD_IRONGOLEM", "BUILD_SNOWMAN", "BUILD_WITHER" -> {
|
||||||
if (!area.isSpawnCustom()) {
|
if (!area.isSpawnCustom()) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
return;
|
return;
|
||||||
|
@ -123,8 +123,10 @@ public class EntitySpawnListener implements Listener {
|
|||||||
if (!location.isPlotArea() || area == null) {
|
if (!location.isPlotArea() || area == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (area.isSpawnCustom() && "CUSTOM".equals(entity.getEntitySpawnReason().name())) {
|
if (PaperLib.isPaper()) {
|
||||||
return;
|
if (area.isSpawnCustom() && "CUSTOM".equals(entity.getEntitySpawnReason().name())) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Plot plot = location.getOwnedPlotAbs();
|
Plot plot = location.getOwnedPlotAbs();
|
||||||
EntityType type = entity.getType();
|
EntityType type = entity.getType();
|
||||||
|
Loading…
Reference in New Issue
Block a user