mirror of
				https://github.com/IntellectualSites/PlotSquared.git
				synced 2025-11-04 11:13:45 +01:00 
			
		
		
		
	mob limits
This commit is contained in:
		@@ -8,7 +8,7 @@
 | 
				
			|||||||
	    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
 | 
						    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
 | 
				
			||||||
	</properties>
 | 
						</properties>
 | 
				
			||||||
    <artifactId>PlotSquared</artifactId>
 | 
					    <artifactId>PlotSquared</artifactId>
 | 
				
			||||||
    <version>2.11.6</version>
 | 
					    <version>2.11.7</version>
 | 
				
			||||||
    <name>PlotSquared</name>
 | 
					    <name>PlotSquared</name>
 | 
				
			||||||
    <packaging>jar</packaging>
 | 
					    <packaging>jar</packaging>
 | 
				
			||||||
    <build>
 | 
					    <build>
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -75,7 +75,6 @@ public abstract class HybridUtils {
 | 
				
			|||||||
            boolean c1 = MainUtil.isPlotArea(new Location(plotworld.worldname, x, 1, z));
 | 
					            boolean c1 = MainUtil.isPlotArea(new Location(plotworld.worldname, x, 1, z));
 | 
				
			||||||
            boolean c2 = MainUtil.isPlotArea(new Location(plotworld.worldname, ex, 1, ez));
 | 
					            boolean c2 = MainUtil.isPlotArea(new Location(plotworld.worldname, ex, 1, ez));
 | 
				
			||||||
            if (!c1 && !c2) {
 | 
					            if (!c1 && !c2) {
 | 
				
			||||||
                System.out.print("FALSE!");
 | 
					 | 
				
			||||||
                return false;
 | 
					                return false;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            else {
 | 
					            else {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -65,6 +65,7 @@ import org.bukkit.event.player.PlayerJoinEvent;
 | 
				
			|||||||
import org.bukkit.event.player.PlayerMoveEvent;
 | 
					import org.bukkit.event.player.PlayerMoveEvent;
 | 
				
			||||||
import org.bukkit.event.player.PlayerQuitEvent;
 | 
					import org.bukkit.event.player.PlayerQuitEvent;
 | 
				
			||||||
import org.bukkit.event.player.PlayerTeleportEvent;
 | 
					import org.bukkit.event.player.PlayerTeleportEvent;
 | 
				
			||||||
 | 
					import org.bukkit.event.vehicle.VehicleCreateEvent;
 | 
				
			||||||
import org.bukkit.event.vehicle.VehicleDestroyEvent;
 | 
					import org.bukkit.event.vehicle.VehicleDestroyEvent;
 | 
				
			||||||
import org.bukkit.event.world.ChunkLoadEvent;
 | 
					import org.bukkit.event.world.ChunkLoadEvent;
 | 
				
			||||||
import org.bukkit.event.world.StructureGrowEvent;
 | 
					import org.bukkit.event.world.StructureGrowEvent;
 | 
				
			||||||
@@ -98,6 +99,7 @@ import com.intellectualcrafters.plot.util.Permissions;
 | 
				
			|||||||
import com.intellectualcrafters.plot.util.TaskManager;
 | 
					import com.intellectualcrafters.plot.util.TaskManager;
 | 
				
			||||||
import com.intellectualcrafters.plot.util.bukkit.BukkitUtil;
 | 
					import com.intellectualcrafters.plot.util.bukkit.BukkitUtil;
 | 
				
			||||||
import com.intellectualcrafters.plot.util.bukkit.UUIDHandler;
 | 
					import com.intellectualcrafters.plot.util.bukkit.UUIDHandler;
 | 
				
			||||||
 | 
					import com.sk89q.worldedit.function.EntityFunction;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * Player Events involving plots
 | 
					 * Player Events involving plots
 | 
				
			||||||
@@ -835,69 +837,60 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi
 | 
				
			|||||||
            return;
 | 
					            return;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        Plot plot = MainUtil.getPlot(loc);
 | 
					        Plot plot = MainUtil.getPlot(loc);
 | 
				
			||||||
 | 
					        if (checkEntity(entity, plot)) {
 | 
				
			||||||
 | 
					            event.setCancelled(true);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					    public boolean checkEntity(Entity entity, Plot plot) {
 | 
				
			||||||
        if (plot != null && plot.owner != null) {
 | 
					        if (plot != null && plot.owner != null) {
 | 
				
			||||||
            Flag entityFlag = FlagManager.getPlotFlag(plot, "entity-cap");
 | 
					            Flag entityFlag = FlagManager.getPlotFlag(plot, "entity-cap");
 | 
				
			||||||
            Flag animalFlag = FlagManager.getPlotFlag(plot, "animal-cap");
 | 
					 | 
				
			||||||
            Flag monsterFlag = FlagManager.getPlotFlag(plot, "hostile-cap");
 | 
					 | 
				
			||||||
            Flag mobFlag = FlagManager.getPlotFlag(plot, "mob-cap");
 | 
					 | 
				
			||||||
            Flag vehicleFlag = FlagManager.getPlotFlag(plot, "vehicle-cap");
 | 
					 | 
				
			||||||
            if (!(entity instanceof Creature)) {
 | 
					 | 
				
			||||||
                return;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
            if (entityFlag == null) {
 | 
					 | 
				
			||||||
                if (animalFlag == null && (entity instanceof Animals)) {
 | 
					 | 
				
			||||||
                    return;
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
                if (monsterFlag == null && (entity instanceof Monster)) {
 | 
					 | 
				
			||||||
                    return;
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
            int[] mobs = ChunkManager.manager.countEntities(plot);
 | 
					            int[] mobs = ChunkManager.manager.countEntities(plot);
 | 
				
			||||||
            if (entity instanceof Creature || entity instanceof Vehicle) {
 | 
					 | 
				
			||||||
            if (entityFlag != null) {
 | 
					            if (entityFlag != null) {
 | 
				
			||||||
                int cap = ((Integer) entityFlag.getValue());
 | 
					                int cap = ((Integer) entityFlag.getValue());
 | 
				
			||||||
                if (mobs[0] >= cap) {
 | 
					                if (mobs[0] >= cap) {
 | 
				
			||||||
                        event.setCancelled(true);
 | 
					                    return true;
 | 
				
			||||||
                        return;
 | 
					 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            if (entity instanceof Creature) {
 | 
					            if (entity instanceof Creature) {
 | 
				
			||||||
 | 
					                Flag mobFlag = FlagManager.getPlotFlag(plot, "mob-cap");
 | 
				
			||||||
                if (mobFlag != null) {
 | 
					                if (mobFlag != null) {
 | 
				
			||||||
                    int cap = ((Integer) mobFlag.getValue());
 | 
					                    int cap = ((Integer) mobFlag.getValue());
 | 
				
			||||||
                    if (mobs[3] >= cap) {
 | 
					                    if (mobs[3] >= cap) {
 | 
				
			||||||
                            event.setCancelled(true);
 | 
					                        return true;
 | 
				
			||||||
                            return;
 | 
					 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
                if (entity instanceof Animals) {
 | 
					                if (entity instanceof Animals) {
 | 
				
			||||||
 | 
					                    Flag animalFlag = FlagManager.getPlotFlag(plot, "animal-cap");
 | 
				
			||||||
                    if (animalFlag != null) {
 | 
					                    if (animalFlag != null) {
 | 
				
			||||||
                        int cap = ((Integer) animalFlag.getValue());
 | 
					                        int cap = ((Integer) animalFlag.getValue());
 | 
				
			||||||
                        if (mobs[1] >= cap) {
 | 
					                        if (mobs[1] >= cap) {
 | 
				
			||||||
                                event.setCancelled(true);
 | 
					                            return true;
 | 
				
			||||||
                        }
 | 
					                        }
 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
                        return;
 | 
					 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
                else if (entity instanceof Monster) {
 | 
					                else if (entity instanceof Monster) {
 | 
				
			||||||
 | 
					                    Flag monsterFlag = FlagManager.getPlotFlag(plot, "hostile-cap");
 | 
				
			||||||
                    if (monsterFlag != null) {
 | 
					                    if (monsterFlag != null) {
 | 
				
			||||||
                        int cap = ((Integer) monsterFlag.getValue());
 | 
					                        int cap = ((Integer) monsterFlag.getValue());
 | 
				
			||||||
                        if (mobs[2] >= cap) {
 | 
					                        if (mobs[2] >= cap) {
 | 
				
			||||||
                                event.setCancelled(true);
 | 
					                            return true;
 | 
				
			||||||
                        }
 | 
					                        }
 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
                else {
 | 
					            else if (entity instanceof Vehicle) {
 | 
				
			||||||
 | 
					                Flag vehicleFlag = FlagManager.getPlotFlag(plot, "vehicle-cap");
 | 
				
			||||||
                if (vehicleFlag != null) {
 | 
					                if (vehicleFlag != null) {
 | 
				
			||||||
                    int cap = ((Integer) vehicleFlag.getValue());
 | 
					                    int cap = ((Integer) vehicleFlag.getValue());
 | 
				
			||||||
                    if (mobs[4] >= cap) {
 | 
					                    if (mobs[4] >= cap) {
 | 
				
			||||||
                            event.setCancelled(true);
 | 
					                        return true;
 | 
				
			||||||
                            return;
 | 
					 | 
				
			||||||
                        }
 | 
					 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					        return false;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
 | 
					    @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
 | 
				
			||||||
@@ -1258,6 +1251,16 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
 | 
					    @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
 | 
				
			||||||
 | 
					    public void onVehicleCreate(final VehicleCreateEvent event) {
 | 
				
			||||||
 | 
					        Vehicle entity = event.getVehicle();
 | 
				
			||||||
 | 
					        Location loc = BukkitUtil.getLocation(entity);
 | 
				
			||||||
 | 
					        Plot plot = MainUtil.getPlot(loc);
 | 
				
			||||||
 | 
					        if (checkEntity(entity, plot)) {
 | 
				
			||||||
 | 
					            entity.remove();
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
 | 
					    @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
 | 
				
			||||||
    public void onVehicleDestroy(final VehicleDestroyEvent e) {
 | 
					    public void onVehicleDestroy(final VehicleDestroyEvent e) {
 | 
				
			||||||
        final Location l = BukkitUtil.getLocation(e.getVehicle());
 | 
					        final Location l = BukkitUtil.getLocation(e.getVehicle());
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user