Java Code Examples for org.bukkit.event.player.PlayerDropItemEvent#setCancelled()

The following examples show how to use org.bukkit.event.player.PlayerDropItemEvent#setCancelled() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: WarpPowderListener.java    From BedwarsRel with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler
public void onDrop(PlayerDropItemEvent event) {
  Player p = event.getPlayer();
  Game g = BedwarsRel.getInstance().getGameManager().getGameOfPlayer(p);
  if (g == null) {
    return;
  }

  if (g.getState() == GameState.RUNNING
      && event.getItemDrop().getItemStack().getItemMeta().getDisplayName() != null
      && event.getItemDrop().getItemStack().getItemMeta().getDisplayName()
      .equals(BedwarsRel._l("ingame.specials.warp-powder.cancel"))) {
    event.setCancelled(true);
  }

}
 
Example 2
Source File: WarpPowderListener.java    From BedWars with GNU Lesser General Public License v3.0 6 votes vote down vote up
@EventHandler
public void onDrop(PlayerDropItemEvent event) {
    Player player = event.getPlayer();
    if (event.isCancelled() || !Main.isPlayerInGame(player)) {
        return;
    }

    GamePlayer gPlayer = Main.getPlayerGameProfile(player);
    Game game = gPlayer.getGame();
    if (gPlayer.isSpectator) {
        return;
    }

    WarpPowder warpPowder = (WarpPowder) game.getFirstActivedSpecialItemOfPlayer(player, WarpPowder.class);
    if (warpPowder != null) {
        if (warpPowder.getStack().equals(event.getItemDrop().getItemStack())) {
            event.setCancelled(true);
        }
    }
}
 
Example 3
Source File: BlockListeners.java    From CratesPlus with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler(ignoreCancelled = true)
public void onItemDrop(PlayerDropItemEvent event) {
    if (!cratesPlus.getConfigHandler().isDisableKeySwapping())
        return;
    String title;
    ItemStack item = event.getItemDrop().getItemStack();

    for (Map.Entry<String, Crate> crate : cratesPlus.getConfigHandler().getCrates().entrySet()) {
        if (!(crate.getValue() instanceof KeyCrate)) {
            continue;
        }
        KeyCrate keyCrate = (KeyCrate) crate.getValue();
        Key key = keyCrate.getKey();
        if (key == null)
            continue;
        title = key.getName();

        if (item.hasItemMeta() && item.getItemMeta().hasDisplayName() && item.getItemMeta().getDisplayName().contains(title)) {
            MessageHandler.sendMessage(event.getPlayer(), "&cYou can not drop crate keys", crate.getValue(), null);
            event.setCancelled(true);
            return;
        }
    }

}
 
Example 4
Source File: PlayerEvents.java    From askyblock with GNU General Public License v2.0 6 votes vote down vote up
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onVisitorDrop(final PlayerDropItemEvent e) {
    if (DEBUG) {
        plugin.getLogger().info(e.getEventName());
    }
    if (!IslandGuard.inWorld(e.getPlayer())) {
        return;
    }
    Island island = plugin.getGrid().getIslandAt(e.getItemDrop().getLocation());
    if ((island != null && island.getIgsFlag(SettingsFlag.VISITOR_ITEM_DROP))
            || e.getPlayer().isOp() || VaultHelper.checkPerm(e.getPlayer(), Settings.PERMPREFIX + "mod.bypassprotect")
            || plugin.getGrid().locationIsOnIsland(e.getPlayer(), e.getItemDrop().getLocation())) {
        return;
    }
    Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.myLocale(e.getPlayer().getUniqueId()).islandProtected);
    e.setCancelled(true);
}
 
Example 5
Source File: EnhancedItemListener.java    From EnchantmentsEnhance with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Prevents enhanced item from dropping.
 *
 * @param e
 */
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
public void onItemDrop(PlayerDropItemEvent e) {
    Item droppedItem = e.getItemDrop();
    ItemStack DroppedItemStack = droppedItem.getItemStack();
    Player p = e.getPlayer();
    // Checks if the item is a bounded item
    if ((DroppedItemStack.hasItemMeta()) && (DroppedItemStack.getItemMeta()
            .getLore() != null)) {
        if (DroppedItemStack.getItemMeta().getLore().contains(Util.UNIQUEID + Util.toColor(
                SettingsManager.lang.getString("lore.untradeableLore")))) {
            e.setCancelled(true);
            Util.sendMessage(SettingsManager.lang.getString(
                    "messages.noDrop"), p);
        }
    }
}
 
Example 6
Source File: BackpackListener.java    From Slimefun4 with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler
public void onItemDrop(PlayerDropItemEvent e) {
    if (backpacks.containsKey(e.getPlayer().getUniqueId())) {
        ItemStack item = e.getItemDrop().getItemStack();
        SlimefunItem sfItem = SlimefunItem.getByItem(item);

        if (sfItem instanceof SlimefunBackpack) {
            e.setCancelled(true);
        }
    }
}
 
Example 7
Source File: ItemDropEvents.java    From uSkyBlock with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
@SuppressWarnings("unused")
public void onDropEvent(PlayerDropItemEvent event) {
    Player player = event.getPlayer();
    if (!plugin.getWorldManager().isSkyWorld(player.getWorld())) {
        return;
    }
    if (!visitorsCanDrop && !plugin.playerIsOnIsland(player) && !plugin.playerIsInSpawn(player)) {
        event.setCancelled(true);
        plugin.notifyPlayer(player, tr("\u00a7eVisitors can't drop items!"));
        return;
    }
    addDropInfo(player, event.getItemDrop().getItemStack());
}
 
Example 8
Source File: Trade.java    From TradePlus with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler
public void onDropItem(PlayerDropItemEvent event) {
  if (cancelled) return;
  if (player1.equals(event.getPlayer()) || player2.equals(event.getPlayer())) {
    event.setCancelled(true);
    if (accept1 && accept2) {
      giveOnCursor(event.getPlayer());
    }
  }
}
 
Example 9
Source File: VaultListener.java    From NovaGuilds with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler
public void onPlayerDropItem(PlayerDropItemEvent event) {
	if(plugin.getGuildManager().isVaultItemStack(event.getItemDrop().getItemStack())) {
		event.setCancelled(true);
		Message.CHAT_GUILD_VAULT_DROP.send(event.getPlayer());
	}
}
 
Example 10
Source File: PlayerDropItem.java    From StaffPlus with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onDrop(PlayerDropItemEvent event)
{
	UUID uuid = event.getPlayer().getUniqueId();
	
	if((options.modeItemChange || !modeCoordinator.isInMode(uuid)) && !freezeHandler.isFrozen(uuid))
	{
		return;
	}
	
	event.setCancelled(true);
}
 
Example 11
Source File: ItemsListener.java    From UhcCore with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST)
public void onPlayerDropItem(PlayerDropItemEvent event) {
	Player player = event.getPlayer();
	ItemStack item = event.getItemDrop().getItemStack();
	GameManager gm = GameManager.getGameManager();

	if (gm.getGameState() == GameState.WAITING && GameItem.isGameItem(item)){
		event.setCancelled(true);
		return;
	}
}
 
Example 12
Source File: MarkerPlacementManager.java    From civcraft with GNU General Public License v2.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR) 
public void OnPlayerDropItemEvent(PlayerDropItemEvent event) {
	if (isPlayerInPlacementMode(event.getPlayer())) {
		event.setCancelled(true);
		removeFromPlacementMode(event.getPlayer(), true);
	}
}
 
Example 13
Source File: DisableShulkerboxes.java    From Minepacks with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(ignoreCancelled = true)
public void onDrop(PlayerDropItemEvent event)
{
	Material itemType = event.getItemDrop().getItemStack().getType();
	if(itemType == Material.SHULKER_SHELL || SHULKER_BOX_MATERIALS.contains(itemType))
	{
		event.setCancelled(true);
	}
}
 
Example 14
Source File: LWCPlayerListener.java    From Modern-LWC with MIT License 5 votes vote down vote up
@EventHandler(priority = EventPriority.HIGH)
public void onPlayerDropItem(PlayerDropItemEvent event) {
    if (event.isCancelled() || !LWC.ENABLED) {
        return;
    }

    Player player = event.getPlayer();

    LWCDropItemEvent evt = new LWCDropItemEvent(player, event);
    plugin.getLWC().getModuleLoader().dispatchEvent(evt);

    if (evt.isCancelled()) {
        event.setCancelled(true);
    }
}
 
Example 15
Source File: ItemListener.java    From HubBasics with GNU Lesser General Public License v3.0 5 votes vote down vote up
@EventHandler(ignoreCancelled = true)
public void onItemDrop(PlayerDropItemEvent event) {
    ItemStack currentItem = event.getItemDrop().getItemStack();
    if (currentItem.getType() == Material.AIR) return;
    NBTItem nbtItem = new NBTItem(currentItem);
    if (!nbtItem.hasKey("HubBasics")) return;

    CustomItem item = HubBasics.getInstance().getItemManager().get(nbtItem.getString("HubBasics"));
    if (item == null) {
        currentItem.setType(Material.AIR); // Destroy old item
        return;
    }
    if (!item.getAllowDrop())
        event.setCancelled(true); // Call setCancelled only when needed to not conflict with other plugins
}
 
Example 16
Source File: PlayerInteractListener.java    From SkyWarsReloaded with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler
  public void onPlayerDropItem(final PlayerDropItemEvent event) {
  	final GameMap gameMap = MatchManager.get().getPlayerMap(event.getPlayer());
  	if (gameMap == null) {
  		return;
  	}
if (gameMap.getMatchState() == MatchState.WAITINGSTART || gameMap.getMatchState() == MatchState.ENDING) {
	event.setCancelled(true);
}
  }
 
Example 17
Source File: SoulboundRune.java    From Slimefun4 with GNU General Public License v3.0 4 votes vote down vote up
private void activate(Player p, PlayerDropItemEvent e, Item item) {
    // Being sure the entity is still valid and not picked up or whatsoever.
    if (!item.isValid()) {
        return;
    }

    Location l = item.getLocation();
    Collection<Entity> entites = l.getWorld().getNearbyEntities(l, RANGE, RANGE, RANGE, this::findCompatibleItem);
    Optional<Entity> optional = entites.stream().findFirst();

    if (optional.isPresent()) {
        Item entity = (Item) optional.get();
        ItemStack target = entity.getItemStack();

        SlimefunUtils.setSoulbound(target, true);

        if (target.getAmount() == 1) {
            e.setCancelled(true);

            // This lightning is just an effect, it deals no damage.
            l.getWorld().strikeLightningEffect(l);

            Slimefun.runSync(() -> {
                // Being sure entities are still valid and not picked up or whatsoever.
                if (item.isValid() && entity.isValid() && target.getAmount() == 1) {

                    l.getWorld().createExplosion(l, 0);
                    l.getWorld().playSound(l, Sound.ENTITY_GENERIC_EXPLODE, 0.3F, 1);

                    entity.remove();
                    item.remove();
                    l.getWorld().dropItemNaturally(l, target);

                    SlimefunPlugin.getLocalization().sendMessage(p, "messages.soulbound-rune.success", true);
                }
            }, 10L);
        }
        else {
            SlimefunPlugin.getLocalization().sendMessage(p, "messages.soulbound-rune.fail", true);
        }
    }
}
 
Example 18
Source File: FreezeMatchModule.java    From PGM with GNU Affero General Public License v3.0 4 votes vote down vote up
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onPlayerDropItem(final PlayerDropItemEvent event) {
  if (freeze.isFrozen(event.getPlayer())) {
    event.setCancelled(true);
  }
}
 
Example 19
Source File: DPlayerListener.java    From DungeonsXL with GNU General Public License v3.0 4 votes vote down vote up
@EventHandler(priority = EventPriority.HIGH)
public void onPlayerDropItem(PlayerDropItemEvent event) {
    Player player = event.getPlayer();
    if (isCitizensNPC(player)) {
        return;
    }

    GlobalPlayer dPlayer = dPlayers.get(player);
    if (dPlayer == null) {
        return;
    }

    if (dPlayer instanceof EditPlayer && !config.getDropItems() && !DPermission.hasPermission(player, DPermission.INSECURE)) {
        event.setCancelled(true);
    }

    if (!(dPlayer instanceof DGamePlayer)) {
        return;
    }

    DGamePlayer gamePlayer = (DGamePlayer) dPlayer;

    DGroup dGroup = gamePlayer.getGroup();
    if (dGroup == null) {
        return;
    }

    if (!dGroup.isPlaying()) {
        event.setCancelled(true);
        return;
    }

    if (!gamePlayer.isReady()) {
        event.setCancelled(true);
        return;
    }

    for (ExItem item : dGroup.getDungeon().getRules().getState(GameRule.SECURE_OBJECTS)) {
        if (event.getItemDrop().getItemStack().isSimilar(item.toItemStack())) {
            event.setCancelled(true);
            MessageUtil.sendMessage(player, DMessage.ERROR_DROP.getMessage());
            return;
        }
    }
}
 
Example 20
Source File: ServerListener.java    From ZombieEscape with GNU General Public License v2.0 4 votes vote down vote up
@EventHandler
public void onDrop(PlayerDropItemEvent event) {
    event.setCancelled(true);
}