mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2024-11-22 10:45:22 +01:00
Fixes creeper ignation by visitors (#2375)
This fixes a long-standing bug which was introduced with a code that prevented hostile entities from targeting visitors. As player was not a target for creeper it allowed it to explode. This code change prevents visitors from igniting creepers as I do not see a reason why we should allow them to ignite them, while still protecting from griefing. Addresses issue reported in #2372
This commit is contained in:
parent
888b485f82
commit
885d2449d9
@ -1,5 +1,8 @@
|
||||
package world.bentobox.bentobox.listeners.flags.worldsettings;
|
||||
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Creeper;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -8,6 +11,7 @@ import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
import org.bukkit.event.entity.EntityDamageEvent;
|
||||
import org.bukkit.event.entity.EntityExplodeEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEntityEvent;
|
||||
|
||||
import world.bentobox.bentobox.api.flags.FlagListener;
|
||||
import world.bentobox.bentobox.api.localization.TextVariables;
|
||||
@ -68,4 +72,33 @@ public class CreeperListener extends FlagListener {
|
||||
e.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Prevent creepers from igniting if they are not allowed to grief
|
||||
* @param e - event
|
||||
* @since 2.4.0
|
||||
*/
|
||||
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
|
||||
public void onPlayerInteractEntity(PlayerInteractEntityEvent e)
|
||||
{
|
||||
Player player = e.getPlayer();
|
||||
Location location = e.getRightClicked().getLocation();
|
||||
|
||||
if (!Flags.CREEPER_GRIEFING.isSetForWorld(location.getWorld()) &&
|
||||
e.getRightClicked() instanceof Creeper &&
|
||||
!this.getIslandsManager().locationIsOnIsland(player, location))
|
||||
{
|
||||
Material mainHand = player.getInventory().getItemInMainHand().getType();
|
||||
|
||||
if (Material.FIRE_CHARGE.equals(mainHand) ||
|
||||
Material.FLINT_AND_STEEL.equals(mainHand))
|
||||
{
|
||||
// Creeper igniting
|
||||
User user = User.getInstance(player);
|
||||
user.notify("protection.protected", TextVariables.DESCRIPTION, user.getTranslation(Flags.CREEPER_GRIEFING.getHintReference()));
|
||||
e.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user