// when a painting is placed... @EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST) public void onPaintingPlace(PaintingPlaceEvent event) { // FEATURE: similar to above, placing a painting requires build permission in the claim // if the player doesn't have permission, don't allow the placement String noBuildReason = GriefPrevention.instance.allowBuild(event.getPlayer(), event.getPainting().getLocation()); if (noBuildReason != null) { event.setCancelled(true); GriefPrevention.sendMessage(event.getPlayer(), TextMode.Err, noBuildReason); return; } // otherwise, apply entity-count limitations for creative worlds else if (GriefPrevention.instance.creativeRulesApply(event.getPainting().getLocation())) { PlayerData playerData = this.dataStore.getPlayerData(event.getPlayer().getName()); Claim claim = this.dataStore.getClaimAt(event.getBlock().getLocation(), false, playerData.lastClaim); if (claim == null) return; String noEntitiesReason = claim.allowMoreEntities(); if (noEntitiesReason != null) { GriefPrevention.sendMessage(event.getPlayer(), TextMode.Err, noEntitiesReason); event.setCancelled(true); return; } } }
// when a creature spawns... @EventHandler(priority = EventPriority.LOWEST) public void onEntitySpawn(CreatureSpawnEvent event) { LivingEntity entity = event.getEntity(); // these rules apply only to creative worlds if (!GriefPrevention.instance.creativeRulesApply(entity.getLocation())) return; // chicken eggs and breeding could potentially make a mess in the wilderness, once griefers get // involved SpawnReason reason = event.getSpawnReason(); if (reason != SpawnReason.SPAWNER_EGG && reason != SpawnReason.BUILD_IRONGOLEM && reason != SpawnReason.BUILD_SNOWMAN) { event.setCancelled(true); return; } // otherwise, just apply the limit on total entities per claim (and no spawning in the // wilderness!) Claim claim = this.dataStore.getClaimAt(event.getLocation(), false, null); if (claim == null || claim.allowMoreEntities() != null) { event.setCancelled(true); return; } }