Skip to content

Commit

Permalink
Added EXPERIENCE_PICKUP flag
Browse files Browse the repository at this point in the history
#217
* Added EXPERIENCE_PICKUP flag (as a PROTECTION flag)
* Created ExperiencePickupListener
* Updated en-US locale accordingly
  • Loading branch information
Poslovitch committed Dec 12, 2018
1 parent 486de0d commit f61b109
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 34 deletions.
Original file line number Diff line number Diff line change
@@ -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);
}
}
}
}
38 changes: 4 additions & 34 deletions src/main/java/world/bentobox/bentobox/lists/Flags.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,40 +11,7 @@
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;
Expand Down Expand Up @@ -142,6 +109,9 @@ private 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();

Expand Down
4 changes: 4 additions & 0 deletions src/main/resources/locales/en-US.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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]"
Expand Down

0 comments on commit f61b109

Please sign in to comment.