001/* 002 * PlotSquared, a land and world management plugin for Minecraft. 003 * Copyright (C) IntellectualSites <https://intellectualsites.com> 004 * Copyright (C) IntellectualSites team and contributors 005 * 006 * This program is free software: you can redistribute it and/or modify 007 * it under the terms of the GNU General Public License as published by 008 * the Free Software Foundation, either version 3 of the License, or 009 * (at your option) any later version. 010 * 011 * This program is distributed in the hope that it will be useful, 012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 014 * GNU General Public License for more details. 015 * 016 * You should have received a copy of the GNU General Public License 017 * along with this program. If not, see <https://www.gnu.org/licenses/>. 018 */ 019package com.plotsquared.bukkit.listener; 020 021import com.plotsquared.bukkit.util.BukkitUtil; 022import com.plotsquared.core.location.Location; 023import com.plotsquared.core.player.PlotPlayer; 024import com.plotsquared.core.plot.Plot; 025import com.plotsquared.core.plot.PlotArea; 026import com.plotsquared.core.plot.flag.implementations.WindChargeFlag; 027import com.plotsquared.core.util.PlotFlagUtil; 028import org.bukkit.entity.EntityType; 029import org.bukkit.entity.Player; 030import org.bukkit.entity.Projectile; 031import org.bukkit.event.EventHandler; 032import org.bukkit.event.EventPriority; 033import org.bukkit.event.Listener; 034import org.bukkit.event.entity.ProjectileHitEvent; 035import org.bukkit.projectiles.ProjectileSource; 036 037/** 038 * For events since 1.21.1 039 * @since 7.6.0 040 */ 041public class ProjectileEventListener1211 implements Listener { 042 043 @EventHandler(priority = EventPriority.HIGH) 044 public void onWindCharge(ProjectileHitEvent event) { 045 046 Projectile entity = event.getEntity(); 047 if ((entity.getType() != EntityType.WIND_CHARGE) && (entity.getType() != EntityType.BREEZE_WIND_CHARGE)) { 048 return; 049 } 050 051 ProjectileSource shooter = entity.getShooter(); 052 if (!(shooter instanceof Player)) { 053 return; 054 } 055 Location location = BukkitUtil.adapt(entity.getLocation()); 056 PlotArea area = location.getPlotArea(); 057 if (area == null) { 058 return; 059 } 060 PlotPlayer<Player> pp = BukkitUtil.adapt((Player) shooter); 061 Plot plot = location.getOwnedPlot(); 062 063 if (plot == null) { 064 if (PlotFlagUtil.isAreaRoadFlagsAndFlagEquals(area, WindChargeFlag.class, false)) { 065 entity.remove(); 066 event.setCancelled(true); 067 } 068 return; 069 } 070 071 if (!plot.hasOwner()) { 072 entity.remove(); 073 event.setCancelled(true); 074 return; 075 } 076 077 if (!plot.isAdded(pp.getUUID())) { 078 if (!plot.getFlag(WindChargeFlag.class)) { 079 plot.debug("Could not update blocks by wind charge because wind-charge = false"); 080 entity.remove(); 081 event.setCancelled(true); 082 } 083 } 084 085 } 086 087}