Added ELYTRA protection flag.

https://github.com/BentoBoxWorld/BentoBox/issues/386
This commit is contained in:
tastybento 2019-07-05 16:15:13 -07:00
parent cb8b3234c8
commit 5c3817d9fe
3 changed files with 56 additions and 0 deletions

View File

@ -0,0 +1,44 @@
package world.bentobox.bentobox.listeners.flags.protection;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.entity.EntityToggleGlideEvent;
import org.bukkit.event.player.PlayerTeleportEvent;
import world.bentobox.bentobox.api.flags.FlagListener;
import world.bentobox.bentobox.api.user.User;
import world.bentobox.bentobox.lists.Flags;
public class ElytraListener extends FlagListener {
/**
* Handle visitors using elytra
* @param e - event
*/
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onGlide(EntityToggleGlideEvent e) {
if (e.getEntity() instanceof Player) {
Player player = (Player) e.getEntity();
checkIsland(e, player, player.getLocation(), Flags.ELYTRA);
}
}
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void wearingElytra(PlayerTeleportEvent e) {
if (!getIWM().inWorld(e.getTo())) {
return;
}
User user = User.getInstance(e.getPlayer());
// Check user's inventory
if (user.getInventory().all(Material.ELYTRA).isEmpty()) {
return;
}
if (getIslands().getProtectedIslandAt(e.getTo()).filter(i-> !i.isAllowed(user, Flags.ELYTRA)).isPresent()) {
user.notify("protection.flags.ELYTRA.hint");
}
}
}

View File

@ -18,6 +18,7 @@ import world.bentobox.bentobox.listeners.flags.protection.BreedingListener;
import world.bentobox.bentobox.listeners.flags.protection.BucketListener;
import world.bentobox.bentobox.listeners.flags.protection.DyeListener;
import world.bentobox.bentobox.listeners.flags.protection.EggListener;
import world.bentobox.bentobox.listeners.flags.protection.ElytraListener;
import world.bentobox.bentobox.listeners.flags.protection.EntityInteractListener;
import world.bentobox.bentobox.listeners.flags.protection.ExperiencePickupListener;
import world.bentobox.bentobox.listeners.flags.protection.FireListener;
@ -419,6 +420,13 @@ public final class Flags {
*/
public static final Flag DYE = new Flag.Builder("DYE", Material.LIGHT_BLUE_DYE).type(Type.PROTECTION).listener(new DyeListener()).build();
/**
* Protects against visitors using elytra. By default, it is allowed.
*
* @since 1.6.0
*/
public static final Flag ELYTRA = new Flag.Builder("ELYTRA", Material.ELYTRA).type(Type.PROTECTION).defaultRank(RanksManager.VISITOR_RANK).listener(new ElytraListener()).build();
/**
* Provides a list of all the Flag instances contained in this class using reflection.
* @return List of all the flags in this class

View File

@ -616,6 +616,10 @@ protection:
name: "Droppers"
description: "Toggle dropper interaction"
hint: "Dropper interaction disabled"
ELYTRA:
name: "Elytra"
description: "Toggle elytra allowed or not"
hint: "&cWARNING: Elytra cannot be used here!"
HOPPER:
name: "Hoppers"
description: "Toggle hopper interaction"