mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-25 22:56:45 +01:00
Clean up bukkit listeners by splitting them up
This commit is contained in:
parent
afb72aa102
commit
3a11ffc77a
@ -27,10 +27,13 @@ package com.plotsquared.bukkit;
|
|||||||
|
|
||||||
import com.plotsquared.bukkit.generator.BukkitHybridUtils;
|
import com.plotsquared.bukkit.generator.BukkitHybridUtils;
|
||||||
import com.plotsquared.bukkit.generator.BukkitPlotGenerator;
|
import com.plotsquared.bukkit.generator.BukkitPlotGenerator;
|
||||||
|
import com.plotsquared.bukkit.listener.BlockEventListener;
|
||||||
import com.plotsquared.bukkit.listener.ChunkListener;
|
import com.plotsquared.bukkit.listener.ChunkListener;
|
||||||
|
import com.plotsquared.bukkit.listener.EntityEventListener;
|
||||||
import com.plotsquared.bukkit.listener.EntitySpawnListener;
|
import com.plotsquared.bukkit.listener.EntitySpawnListener;
|
||||||
import com.plotsquared.bukkit.listener.PaperListener;
|
import com.plotsquared.bukkit.listener.PaperListener;
|
||||||
import com.plotsquared.bukkit.listener.PlayerEvents;
|
import com.plotsquared.bukkit.listener.PlayerEventListener;
|
||||||
|
import com.plotsquared.bukkit.listener.ProjectileEventListener;
|
||||||
import com.plotsquared.bukkit.listener.SingleWorldListener;
|
import com.plotsquared.bukkit.listener.SingleWorldListener;
|
||||||
import com.plotsquared.bukkit.listener.WorldEvents;
|
import com.plotsquared.bukkit.listener.WorldEvents;
|
||||||
import com.plotsquared.bukkit.managers.BukkitWorldManager;
|
import com.plotsquared.bukkit.managers.BukkitWorldManager;
|
||||||
@ -891,9 +894,11 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain<
|
|||||||
return (ChunkGenerator) result.specify(worldName);
|
return (ChunkGenerator) result.specify(worldName);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public void registerPlayerEvents() {
|
@Override public void registerEvents() {
|
||||||
final PlayerEvents main = new PlayerEvents();
|
getServer().getPluginManager().registerEvents(new PlayerEventListener(), this);
|
||||||
getServer().getPluginManager().registerEvents(main, this);
|
getServer().getPluginManager().registerEvents(new BlockEventListener(), this);
|
||||||
|
getServer().getPluginManager().registerEvents(new EntityEventListener(), this);
|
||||||
|
getServer().getPluginManager().registerEvents(new ProjectileEventListener(), this);
|
||||||
getServer().getPluginManager().registerEvents(new EntitySpawnListener(), this);
|
getServer().getPluginManager().registerEvents(new EntitySpawnListener(), this);
|
||||||
if (PaperLib.isPaper() && Settings.Paper_Components.PAPER_LISTENERS) {
|
if (PaperLib.isPaper() && Settings.Paper_Components.PAPER_LISTENERS) {
|
||||||
getServer().getPluginManager().registerEvents(new PaperListener(), this);
|
getServer().getPluginManager().registerEvents(new PaperListener(), this);
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,317 @@
|
|||||||
|
package com.plotsquared.bukkit.listener;
|
||||||
|
|
||||||
|
import com.plotsquared.bukkit.util.BukkitEntityUtil;
|
||||||
|
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.plot.Plot;
|
||||||
|
import com.plotsquared.core.plot.PlotArea;
|
||||||
|
import com.plotsquared.core.plot.flag.implementations.DisablePhysicsFlag;
|
||||||
|
import com.plotsquared.core.plot.flag.implementations.ExplosionFlag;
|
||||||
|
import com.plotsquared.core.plot.flag.implementations.InvincibleFlag;
|
||||||
|
import com.plotsquared.core.plot.flag.implementations.MobPlaceFlag;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.World;
|
||||||
|
import org.bukkit.block.Block;
|
||||||
|
import org.bukkit.entity.Ageable;
|
||||||
|
import org.bukkit.entity.Entity;
|
||||||
|
import org.bukkit.entity.EntityType;
|
||||||
|
import org.bukkit.entity.FallingBlock;
|
||||||
|
import org.bukkit.entity.TNTPrimed;
|
||||||
|
import org.bukkit.entity.Vehicle;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.EventPriority;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.entity.CreatureSpawnEvent;
|
||||||
|
import org.bukkit.event.entity.EntityChangeBlockEvent;
|
||||||
|
import org.bukkit.event.entity.EntityCombustByEntityEvent;
|
||||||
|
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||||
|
import org.bukkit.event.entity.EntityDamageEvent;
|
||||||
|
import org.bukkit.event.entity.EntityExplodeEvent;
|
||||||
|
import org.bukkit.event.entity.ExplosionPrimeEvent;
|
||||||
|
import org.bukkit.event.vehicle.VehicleCreateEvent;
|
||||||
|
import org.bukkit.metadata.FixedMetadataValue;
|
||||||
|
import org.bukkit.metadata.MetadataValue;
|
||||||
|
import org.bukkit.plugin.Plugin;
|
||||||
|
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@SuppressWarnings("unused")
|
||||||
|
public class EntityEventListener implements Listener {
|
||||||
|
|
||||||
|
private float lastRadius;
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.HIGHEST)
|
||||||
|
public void onEntityCombustByEntity(EntityCombustByEntityEvent event) {
|
||||||
|
EntityDamageByEntityEvent eventChange =
|
||||||
|
new EntityDamageByEntityEvent(event.getCombuster(), event.getEntity(),
|
||||||
|
EntityDamageEvent.DamageCause.FIRE_TICK, event.getDuration());
|
||||||
|
onEntityDamageByEntityEvent(eventChange);
|
||||||
|
if (eventChange.isCancelled()) {
|
||||||
|
event.setCancelled(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.HIGHEST)
|
||||||
|
public void onEntityDamageByEntityEvent(EntityDamageByEntityEvent event) {
|
||||||
|
Entity damager = event.getDamager();
|
||||||
|
Location location = BukkitUtil.getLocation(damager);
|
||||||
|
if (!PlotSquared.get().hasPlotArea(location.getWorld())) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Entity victim = event.getEntity();
|
||||||
|
/*
|
||||||
|
if (victim.getType().equals(EntityType.ITEM_FRAME)) {
|
||||||
|
Plot plot = BukkitUtil.getLocation(victim).getPlot();
|
||||||
|
if (plot != null && !plot.isAdded(damager.getUniqueId())) {
|
||||||
|
event.setCancelled(true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
if (!BukkitEntityUtil.entityDamage(damager, victim, event.getCause())) {
|
||||||
|
if (event.isCancelled()) {
|
||||||
|
if (victim instanceof Ageable) {
|
||||||
|
Ageable ageable = (Ageable) victim;
|
||||||
|
if (ageable.getAge() == -24000) {
|
||||||
|
ageable.setAge(0);
|
||||||
|
ageable.setAdult();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
event.setCancelled(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||||
|
public void creatureSpawnEvent(CreatureSpawnEvent event) {
|
||||||
|
Entity entity = event.getEntity();
|
||||||
|
Location location = BukkitUtil.getLocation(entity.getLocation());
|
||||||
|
PlotArea area = location.getPlotArea();
|
||||||
|
if (area == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
CreatureSpawnEvent.SpawnReason reason = event.getSpawnReason();
|
||||||
|
switch (reason.toString()) {
|
||||||
|
case "DISPENSE_EGG":
|
||||||
|
case "EGG":
|
||||||
|
case "OCELOT_BABY":
|
||||||
|
case "SPAWNER_EGG":
|
||||||
|
if (!area.isSpawnEggs()) {
|
||||||
|
event.setCancelled(true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case "REINFORCEMENTS":
|
||||||
|
case "NATURAL":
|
||||||
|
case "MOUNT":
|
||||||
|
case "PATROL":
|
||||||
|
case "RAID":
|
||||||
|
case "SHEARED":
|
||||||
|
case "SHOULDER_ENTITY":
|
||||||
|
case "SILVERFISH_BLOCK":
|
||||||
|
case "TRAP":
|
||||||
|
case "VILLAGE_DEFENSE":
|
||||||
|
case "VILLAGE_INVASION":
|
||||||
|
case "BEEHIVE":
|
||||||
|
case "CHUNK_GEN":
|
||||||
|
if (!area.isMobSpawning()) {
|
||||||
|
event.setCancelled(true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
case "BREEDING":
|
||||||
|
if (!area.isSpawnBreeding()) {
|
||||||
|
event.setCancelled(true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case "BUILD_IRONGOLEM":
|
||||||
|
case "BUILD_SNOWMAN":
|
||||||
|
case "BUILD_WITHER":
|
||||||
|
case "CUSTOM":
|
||||||
|
if (!area.isSpawnCustom() && entity.getType() != EntityType.ARMOR_STAND) {
|
||||||
|
event.setCancelled(true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case "SPAWNER":
|
||||||
|
if (!area.isMobSpawnerSpawning()) {
|
||||||
|
event.setCancelled(true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
Plot plot = area.getOwnedPlotAbs(location);
|
||||||
|
if (plot == null) {
|
||||||
|
if (!area.isMobSpawning()) {
|
||||||
|
event.setCancelled(true);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (BukkitEntityUtil.checkEntity(entity, plot)) {
|
||||||
|
event.setCancelled(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
|
||||||
|
public void onEntityFall(EntityChangeBlockEvent event) {
|
||||||
|
if (event.getEntityType() != EntityType.FALLING_BLOCK) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Block block = event.getBlock();
|
||||||
|
World world = block.getWorld();
|
||||||
|
String worldName = world.getName();
|
||||||
|
if (!PlotSquared.get().hasPlotArea(worldName)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Location location = BukkitUtil.getLocation(block.getLocation());
|
||||||
|
PlotArea area = location.getPlotArea();
|
||||||
|
if (area == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Plot plot = area.getOwnedPlotAbs(location);
|
||||||
|
if (plot == null || plot.getFlag(DisablePhysicsFlag.class)) {
|
||||||
|
event.setCancelled(true);
|
||||||
|
if (plot != null) {
|
||||||
|
plot.debug("Fallin block event was cancelled because disable-physics = true");
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (event.getTo().hasGravity()) {
|
||||||
|
Entity entity = event.getEntity();
|
||||||
|
List<MetadataValue> meta = entity.getMetadata("plot");
|
||||||
|
if (meta.isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Plot origin = (Plot) meta.get(0).value();
|
||||||
|
if (origin != null && !origin.equals(plot)) {
|
||||||
|
event.setCancelled(true);
|
||||||
|
entity.remove();
|
||||||
|
}
|
||||||
|
} else if (event.getTo() == Material.AIR) {
|
||||||
|
event.getEntity()
|
||||||
|
.setMetadata("plot", new FixedMetadataValue((Plugin) PlotSquared.get().IMP, plot));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.HIGH) public void onDamage(EntityDamageEvent event) {
|
||||||
|
if (event.getEntityType() != EntityType.PLAYER) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Location location = BukkitUtil.getLocation(event.getEntity());
|
||||||
|
PlotArea area = location.getPlotArea();
|
||||||
|
if (area == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Plot plot = location.getOwnedPlot();
|
||||||
|
if (plot == null) {
|
||||||
|
if (area.isRoadFlags() && area.getRoadFlag(InvincibleFlag.class)) {
|
||||||
|
event.setCancelled(true);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (plot.getFlag(InvincibleFlag.class)) {
|
||||||
|
plot.debug(
|
||||||
|
event.getEntity().getName() + " could not take damage because invincible = true");
|
||||||
|
event.setCancelled(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||||
|
public void onBigBoom(EntityExplodeEvent event) {
|
||||||
|
Location location = BukkitUtil.getLocation(event.getLocation());
|
||||||
|
PlotArea area = location.getPlotArea();
|
||||||
|
boolean plotArea = location.isPlotArea();
|
||||||
|
if (!plotArea) {
|
||||||
|
if (!PlotSquared.get().hasPlotArea(location.getWorld())) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Plot plot = area.getOwnedPlot(location);
|
||||||
|
if (plot != null) {
|
||||||
|
if (plot.getFlag(ExplosionFlag.class)) {
|
||||||
|
List<MetadataValue> meta = event.getEntity().getMetadata("plot");
|
||||||
|
Plot origin;
|
||||||
|
if (meta.isEmpty()) {
|
||||||
|
origin = plot;
|
||||||
|
} else {
|
||||||
|
origin = (Plot) meta.get(0).value();
|
||||||
|
}
|
||||||
|
if (this.lastRadius != 0) {
|
||||||
|
List<Entity> nearby = event.getEntity()
|
||||||
|
.getNearbyEntities(this.lastRadius, this.lastRadius, this.lastRadius);
|
||||||
|
for (Entity near : nearby) {
|
||||||
|
if (near instanceof TNTPrimed || near.getType()
|
||||||
|
.equals(EntityType.MINECART_TNT)) {
|
||||||
|
if (!near.hasMetadata("plot")) {
|
||||||
|
near.setMetadata("plot",
|
||||||
|
new FixedMetadataValue((Plugin) PlotSquared.get().IMP, plot));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.lastRadius = 0;
|
||||||
|
}
|
||||||
|
Iterator<Block> iterator = event.blockList().iterator();
|
||||||
|
while (iterator.hasNext()) {
|
||||||
|
Block block = iterator.next();
|
||||||
|
location = BukkitUtil.getLocation(block.getLocation());
|
||||||
|
if (!area.contains(location.getX(), location.getZ()) || (origin != null
|
||||||
|
&& !origin.equals(area.getOwnedPlot(location)))) {
|
||||||
|
iterator.remove();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
plot.debug("Explosion was cancelled because explosion = false");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
event.setCancelled(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||||
|
public void onPeskyMobsChangeTheWorldLikeWTFEvent(EntityChangeBlockEvent event) {
|
||||||
|
Entity e = event.getEntity();
|
||||||
|
if (!(e instanceof FallingBlock)) {
|
||||||
|
Location location = BukkitUtil.getLocation(event.getBlock().getLocation());
|
||||||
|
PlotArea area = location.getPlotArea();
|
||||||
|
if (area != null) {
|
||||||
|
Plot plot = area.getOwnedPlot(location);
|
||||||
|
if (plot != null && plot.getFlag(MobPlaceFlag.class)) {
|
||||||
|
System.out.println("bb");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (plot != null) {
|
||||||
|
plot.debug(e.getType() + " could not change block because mob-place = false");
|
||||||
|
}
|
||||||
|
System.out.println("aa");
|
||||||
|
event.setCancelled(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler public void onPrime(ExplosionPrimeEvent event) {
|
||||||
|
this.lastRadius = event.getRadius() + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||||
|
public void onVehicleCreate(VehicleCreateEvent event) {
|
||||||
|
Vehicle entity = event.getVehicle();
|
||||||
|
Location location = BukkitUtil.getLocation(entity);
|
||||||
|
PlotArea area = location.getPlotArea();
|
||||||
|
if (area == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Plot plot = area.getOwnedPlotAbs(location);
|
||||||
|
if (plot == null || BukkitEntityUtil.checkEntity(entity, plot)) {
|
||||||
|
entity.remove();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (Settings.Enabled_Components.KILL_ROAD_VEHICLES) {
|
||||||
|
entity
|
||||||
|
.setMetadata("plot", new FixedMetadataValue((Plugin) PlotSquared.get().IMP, plot));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -25,6 +25,7 @@
|
|||||||
*/
|
*/
|
||||||
package com.plotsquared.bukkit.listener;
|
package com.plotsquared.bukkit.listener;
|
||||||
|
|
||||||
|
import com.plotsquared.bukkit.util.BukkitEntityUtil;
|
||||||
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.Settings;
|
import com.plotsquared.core.configuration.Settings;
|
||||||
@ -155,7 +156,7 @@ public class EntitySpawnListener implements Listener {
|
|||||||
}
|
}
|
||||||
switch (entity.getType()) {
|
switch (entity.getType()) {
|
||||||
case ENDER_CRYSTAL:
|
case ENDER_CRYSTAL:
|
||||||
if (PlayerEvents.checkEntity(entity, plot)) {
|
if (BukkitEntityUtil.checkEntity(entity, plot)) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
}
|
}
|
||||||
case SHULKER:
|
case SHULKER:
|
||||||
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,156 @@
|
|||||||
|
/*
|
||||||
|
* _____ _ _ _____ _
|
||||||
|
* | __ \| | | | / ____| | |
|
||||||
|
* | |__) | | ___ | |_| (___ __ _ _ _ __ _ _ __ ___ __| |
|
||||||
|
* | ___/| |/ _ \| __|\___ \ / _` | | | |/ _` | '__/ _ \/ _` |
|
||||||
|
* | | | | (_) | |_ ____) | (_| | |_| | (_| | | | __/ (_| |
|
||||||
|
* |_| |_|\___/ \__|_____/ \__, |\__,_|\__,_|_| \___|\__,_|
|
||||||
|
* | |
|
||||||
|
* |_|
|
||||||
|
* PlotSquared plot management system for Minecraft
|
||||||
|
* Copyright (C) 2020 IntellectualSites
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
package com.plotsquared.bukkit.listener;
|
||||||
|
|
||||||
|
import com.plotsquared.bukkit.util.BukkitEntityUtil;
|
||||||
|
import com.plotsquared.bukkit.util.BukkitUtil;
|
||||||
|
import com.plotsquared.core.PlotSquared;
|
||||||
|
import com.plotsquared.core.configuration.Captions;
|
||||||
|
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.PlotHandler;
|
||||||
|
import com.plotsquared.core.util.Permissions;
|
||||||
|
import org.bukkit.entity.Entity;
|
||||||
|
import org.bukkit.entity.LivingEntity;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.entity.Projectile;
|
||||||
|
import org.bukkit.entity.ThrownPotion;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.EventPriority;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.entity.LingeringPotionSplashEvent;
|
||||||
|
import org.bukkit.event.entity.PotionSplashEvent;
|
||||||
|
import org.bukkit.event.entity.ProjectileHitEvent;
|
||||||
|
import org.bukkit.event.entity.ProjectileLaunchEvent;
|
||||||
|
import org.bukkit.projectiles.BlockProjectileSource;
|
||||||
|
import org.bukkit.projectiles.ProjectileSource;
|
||||||
|
|
||||||
|
@SuppressWarnings("unused")
|
||||||
|
public class ProjectileEventListener implements Listener {
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||||
|
public void onPotionSplash(LingeringPotionSplashEvent event) {
|
||||||
|
Projectile entity = event.getEntity();
|
||||||
|
Location location = BukkitUtil.getLocation(entity);
|
||||||
|
if (!PlotSquared.get().hasPlotArea(location.getWorld())) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!this.onProjectileHit(event)) {
|
||||||
|
event.setCancelled(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||||
|
public void onPotionSplash(PotionSplashEvent event) {
|
||||||
|
ThrownPotion damager = event.getPotion();
|
||||||
|
Location location = BukkitUtil.getLocation(damager);
|
||||||
|
if (!PlotSquared.get().hasPlotArea(location.getWorld())) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
int count = 0;
|
||||||
|
for (LivingEntity victim : event.getAffectedEntities()) {
|
||||||
|
if (!BukkitEntityUtil.entityDamage(damager, victim)) {
|
||||||
|
event.setIntensity(victim, 0);
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ((count > 0 && count == event.getAffectedEntities().size()) || !onProjectileHit(event)) {
|
||||||
|
event.setCancelled(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler public void onProjectileLaunch(ProjectileLaunchEvent event) {
|
||||||
|
Projectile entity = event.getEntity();
|
||||||
|
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<Player> pp = BukkitUtil.getPlayer((Player) shooter);
|
||||||
|
Plot plot = location.getOwnedPlot();
|
||||||
|
if (plot != null && !plot.isAdded(pp.getUUID())) {
|
||||||
|
entity.remove();
|
||||||
|
event.setCancelled(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings({"BooleanMethodIsAlwaysInverted", "cos it's not... dum IntelliJ"}) @EventHandler
|
||||||
|
public boolean onProjectileHit(ProjectileHitEvent event) {
|
||||||
|
Projectile entity = event.getEntity();
|
||||||
|
Location location = BukkitUtil.getLocation(entity);
|
||||||
|
if (!PlotSquared.get().hasPlotArea(location.getWorld())) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
PlotArea area = location.getPlotArea();
|
||||||
|
if (area == null) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
Plot plot = area.getPlot(location);
|
||||||
|
ProjectileSource shooter = entity.getShooter();
|
||||||
|
if (shooter instanceof Player) {
|
||||||
|
PlotPlayer<?> pp = BukkitUtil.getPlayer((Player) shooter);
|
||||||
|
if (plot == null) {
|
||||||
|
if (!Permissions.hasPermission(pp, Captions.PERMISSION_PROJECTILE_UNOWNED)) {
|
||||||
|
entity.remove();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (plot.isAdded(pp.getUUID()) || Permissions
|
||||||
|
.hasPermission(pp, Captions.PERMISSION_PROJECTILE_OTHER)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
entity.remove();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!(shooter instanceof Entity) && shooter != null) {
|
||||||
|
if (plot == null) {
|
||||||
|
entity.remove();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
Location sLoc =
|
||||||
|
BukkitUtil.getLocation(((BlockProjectileSource) shooter).getBlock().getLocation());
|
||||||
|
if (!area.contains(sLoc.getX(), sLoc.getZ())) {
|
||||||
|
entity.remove();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
Plot sPlot = area.getOwnedPlotAbs(sLoc);
|
||||||
|
if (sPlot == null || !PlotHandler.sameOwners(plot, sPlot)) {
|
||||||
|
entity.remove();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,363 @@
|
|||||||
|
/*
|
||||||
|
* _____ _ _ _____ _
|
||||||
|
* | __ \| | | | / ____| | |
|
||||||
|
* | |__) | | ___ | |_| (___ __ _ _ _ __ _ _ __ ___ __| |
|
||||||
|
* | ___/| |/ _ \| __|\___ \ / _` | | | |/ _` | '__/ _ \/ _` |
|
||||||
|
* | | | | (_) | |_ ____) | (_| | |_| | (_| | | | __/ (_| |
|
||||||
|
* |_| |_|\___/ \__|_____/ \__, |\__,_|\__,_|_| \___|\__,_|
|
||||||
|
* | |
|
||||||
|
* |_|
|
||||||
|
* PlotSquared plot management system for Minecraft
|
||||||
|
* Copyright (C) 2020 IntellectualSites
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
package com.plotsquared.bukkit.util;
|
||||||
|
|
||||||
|
import com.plotsquared.bukkit.player.BukkitPlayer;
|
||||||
|
import com.plotsquared.core.configuration.Captions;
|
||||||
|
import com.plotsquared.core.configuration.Settings;
|
||||||
|
import com.plotsquared.core.location.Location;
|
||||||
|
import com.plotsquared.core.plot.Plot;
|
||||||
|
import com.plotsquared.core.plot.PlotArea;
|
||||||
|
import com.plotsquared.core.plot.flag.implementations.AnimalAttackFlag;
|
||||||
|
import com.plotsquared.core.plot.flag.implementations.AnimalCapFlag;
|
||||||
|
import com.plotsquared.core.plot.flag.implementations.DoneFlag;
|
||||||
|
import com.plotsquared.core.plot.flag.implementations.EntityCapFlag;
|
||||||
|
import com.plotsquared.core.plot.flag.implementations.HangingBreakFlag;
|
||||||
|
import com.plotsquared.core.plot.flag.implementations.HostileAttackFlag;
|
||||||
|
import com.plotsquared.core.plot.flag.implementations.HostileCapFlag;
|
||||||
|
import com.plotsquared.core.plot.flag.implementations.MiscBreakFlag;
|
||||||
|
import com.plotsquared.core.plot.flag.implementations.MiscCapFlag;
|
||||||
|
import com.plotsquared.core.plot.flag.implementations.MobCapFlag;
|
||||||
|
import com.plotsquared.core.plot.flag.implementations.PveFlag;
|
||||||
|
import com.plotsquared.core.plot.flag.implementations.PvpFlag;
|
||||||
|
import com.plotsquared.core.plot.flag.implementations.TamedAttackFlag;
|
||||||
|
import com.plotsquared.core.plot.flag.implementations.VehicleCapFlag;
|
||||||
|
import com.plotsquared.core.util.EntityUtil;
|
||||||
|
import com.plotsquared.core.util.MainUtil;
|
||||||
|
import com.plotsquared.core.util.Permissions;
|
||||||
|
import com.plotsquared.core.util.entity.EntityCategories;
|
||||||
|
import com.sk89q.worldedit.bukkit.BukkitAdapter;
|
||||||
|
import org.bukkit.entity.Arrow;
|
||||||
|
import org.bukkit.entity.Creature;
|
||||||
|
import org.bukkit.entity.Entity;
|
||||||
|
import org.bukkit.entity.EntityType;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.entity.Projectile;
|
||||||
|
import org.bukkit.event.entity.EntityDamageEvent;
|
||||||
|
import org.bukkit.projectiles.BlockProjectileSource;
|
||||||
|
import org.bukkit.projectiles.ProjectileSource;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
public class BukkitEntityUtil {
|
||||||
|
|
||||||
|
public static final com.sk89q.worldedit.world.entity.EntityType FAKE_ENTITY_TYPE =
|
||||||
|
new com.sk89q.worldedit.world.entity.EntityType("plotsquared:fake");
|
||||||
|
|
||||||
|
public static boolean entityDamage(Entity damager, Entity victim) {
|
||||||
|
return entityDamage(damager, victim, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean entityDamage(Entity damager, Entity victim,
|
||||||
|
EntityDamageEvent.DamageCause cause) {
|
||||||
|
Location dloc = BukkitUtil.getLocation(damager);
|
||||||
|
Location vloc = BukkitUtil.getLocation(victim);
|
||||||
|
PlotArea dArea = dloc.getPlotArea();
|
||||||
|
PlotArea vArea;
|
||||||
|
if (dArea != null && dArea.contains(vloc.getX(), vloc.getZ())) {
|
||||||
|
vArea = dArea;
|
||||||
|
} else {
|
||||||
|
vArea = vloc.getPlotArea();
|
||||||
|
}
|
||||||
|
if (dArea == null && vArea == null) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
Plot dplot;
|
||||||
|
if (dArea != null) {
|
||||||
|
dplot = dArea.getPlot(dloc);
|
||||||
|
} else {
|
||||||
|
dplot = null;
|
||||||
|
}
|
||||||
|
Plot vplot;
|
||||||
|
if (vArea != null) {
|
||||||
|
vplot = vArea.getPlot(vloc);
|
||||||
|
} else {
|
||||||
|
vplot = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
Plot plot;
|
||||||
|
String stub;
|
||||||
|
boolean isPlot = true;
|
||||||
|
if (dplot == null && vplot == null) {
|
||||||
|
if (dArea == null) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
plot = null;
|
||||||
|
stub = "road";
|
||||||
|
isPlot = false;
|
||||||
|
} else {
|
||||||
|
// Prioritize plots for close to seamless pvp zones
|
||||||
|
if (victim.getTicksLived() > damager.getTicksLived()) {
|
||||||
|
if (dplot == null || !(victim instanceof Player)) {
|
||||||
|
if (vplot == null) {
|
||||||
|
plot = dplot;
|
||||||
|
} else {
|
||||||
|
plot = vplot;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
plot = dplot;
|
||||||
|
}
|
||||||
|
} else if (dplot == null || !(victim instanceof Player)) {
|
||||||
|
if (vplot == null) {
|
||||||
|
plot = dplot;
|
||||||
|
} else {
|
||||||
|
plot = vplot;
|
||||||
|
}
|
||||||
|
} else if (vplot == null) {
|
||||||
|
plot = dplot;
|
||||||
|
} else {
|
||||||
|
plot = vplot;
|
||||||
|
}
|
||||||
|
if (plot.hasOwner()) {
|
||||||
|
stub = "other";
|
||||||
|
} else {
|
||||||
|
stub = "unowned";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
boolean roadFlags = vArea != null ? vArea.isRoadFlags() : dArea.isRoadFlags();
|
||||||
|
PlotArea area = vArea != null ? vArea : dArea;
|
||||||
|
|
||||||
|
Player player;
|
||||||
|
if (damager instanceof Player) { // attacker is player
|
||||||
|
player = (Player) damager;
|
||||||
|
} else if (damager instanceof Projectile) {
|
||||||
|
Projectile projectile = (Projectile) damager;
|
||||||
|
ProjectileSource shooter = projectile.getShooter();
|
||||||
|
if (shooter instanceof Player) { // shooter is player
|
||||||
|
player = (Player) shooter;
|
||||||
|
} else { // shooter is not player
|
||||||
|
if (shooter instanceof BlockProjectileSource) {
|
||||||
|
Location sLoc = BukkitUtil
|
||||||
|
.getLocation(((BlockProjectileSource) shooter).getBlock().getLocation());
|
||||||
|
dplot = dArea.getPlot(sLoc);
|
||||||
|
}
|
||||||
|
player = null;
|
||||||
|
}
|
||||||
|
} else { // Attacker is not player
|
||||||
|
player = null;
|
||||||
|
}
|
||||||
|
if (player != null) {
|
||||||
|
BukkitPlayer plotPlayer = BukkitUtil.getPlayer(player);
|
||||||
|
|
||||||
|
final com.sk89q.worldedit.world.entity.EntityType entityType;
|
||||||
|
|
||||||
|
// Create a fake entity type if the type does not have a name
|
||||||
|
if (victim.getType().getName() == null) {
|
||||||
|
entityType = FAKE_ENTITY_TYPE;
|
||||||
|
} else {
|
||||||
|
entityType = BukkitAdapter.adapt(victim.getType());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (EntityCategories.HANGING.contains(entityType)) { // hanging
|
||||||
|
if (plot != null && (plot.getFlag(HangingBreakFlag.class) || plot
|
||||||
|
.isAdded(plotPlayer.getUUID()))) {
|
||||||
|
if (Settings.Done.RESTRICT_BUILDING && DoneFlag.isDone(plot)) {
|
||||||
|
if (!Permissions
|
||||||
|
.hasPermission(plotPlayer, Captions.PERMISSION_ADMIN_BUILD_OTHER)) {
|
||||||
|
MainUtil.sendMessage(plotPlayer, Captions.NO_PERMISSION_EVENT,
|
||||||
|
Captions.PERMISSION_ADMIN_BUILD_OTHER);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (!Permissions.hasPermission(plotPlayer, "plots.admin.destroy." + stub)) {
|
||||||
|
MainUtil.sendMessage(plotPlayer, Captions.NO_PERMISSION_EVENT,
|
||||||
|
"plots.admin.destroy." + stub);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} else if (victim.getType() == EntityType.ARMOR_STAND) {
|
||||||
|
if (plot != null && (plot.getFlag(MiscBreakFlag.class) || plot
|
||||||
|
.isAdded(plotPlayer.getUUID()))) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (!Permissions.hasPermission(plotPlayer, "plots.admin.destroy." + stub)) {
|
||||||
|
MainUtil.sendMessage(plotPlayer, Captions.NO_PERMISSION_EVENT,
|
||||||
|
"plots.admin.destroy." + stub);
|
||||||
|
if (plot != null) {
|
||||||
|
plot.debug(player.getName()
|
||||||
|
+ " could not break armor stand because misc-break = false");
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} else if (EntityCategories.HOSTILE.contains(entityType)) {
|
||||||
|
if (isPlot) {
|
||||||
|
if (plot.getFlag(HostileAttackFlag.class) || plot.getFlag(PveFlag.class) || plot
|
||||||
|
.isAdded(plotPlayer.getUUID())) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
} else if (roadFlags && (area.getRoadFlag(HostileAttackFlag.class) || area
|
||||||
|
.getFlag(PveFlag.class))) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (!Permissions.hasPermission(plotPlayer, "plots.admin.pve." + stub)) {
|
||||||
|
MainUtil.sendMessage(plotPlayer, Captions.NO_PERMISSION_EVENT,
|
||||||
|
"plots.admin.pve." + stub);
|
||||||
|
if (plot != null) {
|
||||||
|
plot.debug(player.getName() + " could not attack " + entityType
|
||||||
|
+ " because pve = false OR hostile-attack = false");
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} else if (EntityCategories.TAMEABLE.contains(entityType)) { // victim is tameable
|
||||||
|
if (isPlot) {
|
||||||
|
if (plot.getFlag(TamedAttackFlag.class) || plot.getFlag(PveFlag.class) || plot
|
||||||
|
.isAdded(plotPlayer.getUUID())) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
} else if (roadFlags && (area.getRoadFlag(TamedAttackFlag.class) || area
|
||||||
|
.getFlag(PveFlag.class))) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (!Permissions.hasPermission(plotPlayer, "plots.admin.pve." + stub)) {
|
||||||
|
MainUtil.sendMessage(plotPlayer, Captions.NO_PERMISSION_EVENT,
|
||||||
|
"plots.admin.pve." + stub);
|
||||||
|
if (plot != null) {
|
||||||
|
plot.debug(player.getName() + " could not attack " + entityType
|
||||||
|
+ " because pve = false OR tamned-attack = false");
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} else if (EntityCategories.PLAYER.contains(entityType)) {
|
||||||
|
if (isPlot) {
|
||||||
|
if (!plot.getFlag(PvpFlag.class) && !Permissions
|
||||||
|
.hasPermission(plotPlayer, "plots.admin.pvp." + stub)) {
|
||||||
|
MainUtil.sendMessage(plotPlayer, Captions.NO_PERMISSION_EVENT,
|
||||||
|
"plots.admin.pvp." + stub);
|
||||||
|
plot.debug(player.getName() + " could not attack " + entityType
|
||||||
|
+ " because pve = false");
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
} else if (roadFlags && area.getRoadFlag(PvpFlag.class)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (!Permissions.hasPermission(plotPlayer, "plots.admin.pvp." + stub)) {
|
||||||
|
MainUtil.sendMessage(plotPlayer, Captions.NO_PERMISSION_EVENT,
|
||||||
|
"plots.admin.pvp." + stub);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} else if (EntityCategories.ANIMAL.contains(entityType)) { // victim is animal
|
||||||
|
if (isPlot) {
|
||||||
|
if (plot.getFlag(AnimalAttackFlag.class) || plot.getFlag(PveFlag.class) || plot
|
||||||
|
.isAdded(plotPlayer.getUUID())) {
|
||||||
|
plot.debug(player.getName() + " could not attack " + entityType
|
||||||
|
+ " because pve = false OR animal-attack = false");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
} else if (roadFlags && (area.getRoadFlag(AnimalAttackFlag.class) || area
|
||||||
|
.getFlag(PveFlag.class))) {
|
||||||
|
if (!Permissions.hasPermission(plotPlayer, "plots.admin.pve." + stub)) {
|
||||||
|
MainUtil.sendMessage(plotPlayer, Captions.NO_PERMISSION_EVENT,
|
||||||
|
"plots.admin.pve." + stub);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (EntityCategories.VEHICLE
|
||||||
|
.contains(entityType)) { // Vehicles are managed in vehicle destroy event
|
||||||
|
return true;
|
||||||
|
} else { // victim is something else
|
||||||
|
if (isPlot) {
|
||||||
|
if (plot.getFlag(PveFlag.class) || plot.isAdded(plotPlayer.getUUID())) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
} else if (roadFlags && area.getRoadFlag(PveFlag.class)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (!Permissions.hasPermission(plotPlayer, "plots.admin.pve." + stub)) {
|
||||||
|
MainUtil.sendMessage(plotPlayer, Captions.NO_PERMISSION_EVENT,
|
||||||
|
"plots.admin.pve." + stub);
|
||||||
|
if (plot != null) {
|
||||||
|
plot.debug(player.getName() + " could not attack " + entityType
|
||||||
|
+ " because pve = false");
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
} else if (dplot != null && (!dplot.equals(vplot) || Objects
|
||||||
|
.equals(dplot.getOwnerAbs(), vplot.getOwnerAbs()))) {
|
||||||
|
return vplot != null && vplot.getFlag(PveFlag.class);
|
||||||
|
}
|
||||||
|
//disable the firework damage. too much of a headache to support at the moment.
|
||||||
|
if (vplot != null) {
|
||||||
|
if (EntityDamageEvent.DamageCause.ENTITY_EXPLOSION == cause
|
||||||
|
&& damager.getType() == EntityType.FIREWORK) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (vplot == null && roadFlags && area.getRoadFlag(PveFlag.class)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return ((vplot != null && vplot.getFlag(PveFlag.class)) || !(damager instanceof Arrow
|
||||||
|
&& !(victim instanceof Creature)));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean checkEntity(Entity entity, Plot plot) {
|
||||||
|
if (plot == null || !plot.hasOwner() || plot.getFlags().isEmpty() && plot.getArea()
|
||||||
|
.getFlagContainer().getFlagMap().isEmpty()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
final com.sk89q.worldedit.world.entity.EntityType entityType =
|
||||||
|
BukkitAdapter.adapt(entity.getType());
|
||||||
|
|
||||||
|
if (EntityCategories.PLAYER.contains(entityType)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (EntityCategories.PROJECTILE.contains(entityType) || EntityCategories.OTHER
|
||||||
|
.contains(entityType) || EntityCategories.HANGING.contains(entityType)) {
|
||||||
|
return EntityUtil.checkEntity(plot, EntityCapFlag.ENTITY_CAP_UNLIMITED,
|
||||||
|
MiscCapFlag.MISC_CAP_UNLIMITED);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Has to go go before vehicle as horses are both
|
||||||
|
// animals and vehicles
|
||||||
|
if (EntityCategories.ANIMAL.contains(entityType) || EntityCategories.VILLAGER
|
||||||
|
.contains(entityType) || EntityCategories.TAMEABLE.contains(entityType)) {
|
||||||
|
return EntityUtil
|
||||||
|
.checkEntity(plot, EntityCapFlag.ENTITY_CAP_UNLIMITED, MobCapFlag.MOB_CAP_UNLIMITED,
|
||||||
|
AnimalCapFlag.ANIMAL_CAP_UNLIMITED);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (EntityCategories.HOSTILE.contains(entityType)) {
|
||||||
|
return EntityUtil
|
||||||
|
.checkEntity(plot, EntityCapFlag.ENTITY_CAP_UNLIMITED, MobCapFlag.MOB_CAP_UNLIMITED,
|
||||||
|
HostileCapFlag.HOSTILE_CAP_UNLIMITED);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (EntityCategories.VEHICLE.contains(entityType)) {
|
||||||
|
return EntityUtil.checkEntity(plot, EntityCapFlag.ENTITY_CAP_UNLIMITED,
|
||||||
|
VehicleCapFlag.VEHICLE_CAP_UNLIMITED);
|
||||||
|
}
|
||||||
|
|
||||||
|
return EntityUtil.checkEntity(plot, EntityCapFlag.ENTITY_CAP_UNLIMITED);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -162,7 +162,7 @@ public interface IPlotMain<P> extends ILogger {
|
|||||||
/**
|
/**
|
||||||
* Register the protection system.
|
* Register the protection system.
|
||||||
*/
|
*/
|
||||||
void registerPlayerEvents();
|
void registerEvents();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Register force field events.
|
* Register force field events.
|
||||||
|
@ -43,7 +43,7 @@ import static com.plotsquared.core.util.entity.EntityCategories.CAP_VEHICLE;
|
|||||||
* Entity related general utility methods
|
* Entity related general utility methods
|
||||||
*/
|
*/
|
||||||
@UtilityClass
|
@UtilityClass
|
||||||
public final class EntityUtil {
|
public class EntityUtil {
|
||||||
|
|
||||||
private static int capNumeral(@NonNull final String flagName) {
|
private static int capNumeral(@NonNull final String flagName) {
|
||||||
int i;
|
int i;
|
||||||
|
Loading…
Reference in New Issue
Block a user