Added EXPERIENCE_PICKUP flag

#217
* Added EXPERIENCE_PICKUP flag (as a PROTECTION flag)
* Created ExperiencePickupListener
* Updated en-US locale accordingly
This commit is contained in:
Florian CUNY 2018-12-12 20:45:55 +01:00
parent 486de0dc19
commit f61b109060
3 changed files with 38 additions and 34 deletions

View File

@ -0,0 +1,30 @@
package world.bentobox.bentobox.listeners.flags;
import org.bukkit.entity.ExperienceOrb;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.entity.EntityTargetLivingEntityEvent;
import world.bentobox.bentobox.api.flags.FlagListener;
import world.bentobox.bentobox.api.user.User;
import world.bentobox.bentobox.lists.Flags;
/**
* Handles the {@link world.bentobox.bentobox.lists.Flags#EXPERIENCE_PICKUP} flag.
*
* @author Poslovitch
*/
public class ExperiencePickupListener extends FlagListener {
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onExperienceOrbTargetPlayer(EntityTargetLivingEntityEvent e) {
// Make sure the target is a Player and the entity is an experience orb
if (e.getTarget() instanceof Player && e.getEntity() instanceof ExperienceOrb) {
setUser(User.getInstance((Player) e.getTarget()));
if (!checkIsland(e, e.getEntity().getLocation(), Flags.EXPERIENCE_PICKUP)) {
// Cancelling the event won't be enough, we need to explicitly set the target to null
e.setTarget(null);
}
}
}
}

View File

@ -11,40 +11,7 @@ import world.bentobox.bentobox.api.flags.Flag;
import world.bentobox.bentobox.api.flags.Flag.Type;
import world.bentobox.bentobox.api.flags.FlagBuilder;
import world.bentobox.bentobox.api.flags.clicklisteners.CycleClick;
import world.bentobox.bentobox.listeners.flags.BlockInteractionListener;
import world.bentobox.bentobox.listeners.flags.BreakBlocksListener;
import world.bentobox.bentobox.listeners.flags.BreedingListener;
import world.bentobox.bentobox.listeners.flags.BucketListener;
import world.bentobox.bentobox.listeners.flags.ChestDamageListener;
import world.bentobox.bentobox.listeners.flags.CleanSuperFlatListener;
import world.bentobox.bentobox.listeners.flags.CoarseDirtTillingListener;
import world.bentobox.bentobox.listeners.flags.CreeperListener;
import world.bentobox.bentobox.listeners.flags.EggListener;
import world.bentobox.bentobox.listeners.flags.EnderChestListener;
import world.bentobox.bentobox.listeners.flags.EndermanListener;
import world.bentobox.bentobox.listeners.flags.EnterExitListener;
import world.bentobox.bentobox.listeners.flags.EntityInteractListener;
import world.bentobox.bentobox.listeners.flags.FireListener;
import world.bentobox.bentobox.listeners.flags.GeoLimitMobsListener;
import world.bentobox.bentobox.listeners.flags.HurtingListener;
import world.bentobox.bentobox.listeners.flags.InventoryListener;
import world.bentobox.bentobox.listeners.flags.InvincibleVisitorsListener;
import world.bentobox.bentobox.listeners.flags.IslandRespawnListener;
import world.bentobox.bentobox.listeners.flags.ItemDropPickUpListener;
import world.bentobox.bentobox.listeners.flags.ItemFrameListener;
import world.bentobox.bentobox.listeners.flags.LeashListener;
import world.bentobox.bentobox.listeners.flags.LockAndBanListener;
import world.bentobox.bentobox.listeners.flags.MobSpawnListener;
import world.bentobox.bentobox.listeners.flags.OfflineRedstoneListener;
import world.bentobox.bentobox.listeners.flags.PVPListener;
import world.bentobox.bentobox.listeners.flags.PhysicalInteractionListener;
import world.bentobox.bentobox.listeners.flags.PistonPushListener;
import world.bentobox.bentobox.listeners.flags.PlaceBlocksListener;
import world.bentobox.bentobox.listeners.flags.PortalListener;
import world.bentobox.bentobox.listeners.flags.RemoveMobsListener;
import world.bentobox.bentobox.listeners.flags.ShearingListener;
import world.bentobox.bentobox.listeners.flags.TNTListener;
import world.bentobox.bentobox.listeners.flags.TeleportationListener;
import world.bentobox.bentobox.listeners.flags.*;
import world.bentobox.bentobox.listeners.flags.clicklisteners.CommandRankClickListener;
import world.bentobox.bentobox.listeners.flags.clicklisteners.GeoLimitClickListener;
import world.bentobox.bentobox.managers.RanksManager;
@ -142,6 +109,9 @@ public class Flags {
public static final Flag ITEM_DROP = new FlagBuilder().id("ITEM_DROP").icon(Material.BEETROOT_SOUP).allowedByDefault(true).listener(new ItemDropPickUpListener()).build();
public static final Flag ITEM_PICKUP = new FlagBuilder().id("ITEM_PICKUP").icon(Material.BEETROOT_SEEDS).build();
// Experience
public static final Flag EXPERIENCE_PICKUP = new FlagBuilder().id("EXPERIENCE_PICKUP").icon(Material.EXPERIENCE_BOTTLE).listener(new ExperiencePickupListener()).build();
// TNT
public static final Flag TNT = new FlagBuilder().id("TNT").icon(Material.TNT).listener(new TNTListener()).allowedByDefault(false).build();

View File

@ -711,6 +711,10 @@ protection:
description: "Toggle Frost Walker enchantment"
name: "Frost Walker"
hint: "Frost Walker cannot be used here"
EXPERIENCE_PICKUP:
name: "Experience pickup"
description: "Toggle experience orb pickup"
hint: "cannot pickup experience orb"
locked: "&cThis island is locked!"
protected: "&cIsland protected: [description]"
spawn-protected: "&cSpawn protected: [description]"