org.bukkit.event.Event.Result Java Examples

The following examples show how to use org.bukkit.event.Event.Result. 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: InfernalBonemeal.java    From Slimefun4 with GNU General Public License v3.0 6 votes vote down vote up
@Override
public ItemUseHandler getItemHandler() {
    return e -> {
        Optional<Block> block = e.getClickedBlock();
        e.setUseBlock(Result.DENY);

        if (block.isPresent()) {
            Block b = block.get();

            if (b.getType() == Material.NETHER_WART) {
                Ageable ageable = (Ageable) b.getBlockData();

                if (ageable.getAge() < ageable.getMaximumAge()) {
                    ageable.setAge(ageable.getMaximumAge());
                    b.setBlockData(ageable);
                    b.getWorld().playEffect(b.getLocation(), Effect.STEP_SOUND, Material.REDSTONE_BLOCK);

                    if (e.getPlayer().getGameMode() != GameMode.CREATIVE) {
                        ItemUtils.consumeItem(e.getItem(), false);
                    }
                }
            }
        }
    };
}
 
Example #2
Source File: SignShopListener.java    From Shopkeepers with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = false)
void onPlayerInteract(PlayerInteractEvent event) {
	Player player = event.getPlayer();
	Block block = event.getClickedBlock();

	// check for sign shop
	if (event.getAction() == Action.RIGHT_CLICK_BLOCK && Utils.isSign(block.getType())) {
		Shopkeeper shopkeeper = plugin.getShopkeeperByBlock(block);
		if (shopkeeper != null) {
			// only trigger shopkeeper interaction for main-hand events:
			if (NMSManager.getProvider().isMainHandInteraction(event)) {
				Log.debug("Player " + player.getName() + " is interacting with sign shopkeeper at " + block.getWorld().getName() + "," + block.getX() + "," + block.getY() + "," + block.getZ());
				if (event.useInteractedBlock() == Result.DENY) {
					Log.debug("  Cancelled by another plugin");
				} else {
					shopkeeper.onPlayerInteraction(player);
				}
			}

			// always cancel interactions with shopkeepers, to prevent any default behavior:
			event.setCancelled(true);
		}
	}
}
 
Example #3
Source File: TestMultiblockListener.java    From Slimefun4 with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void testMultiblock() {
    Player player = server.addPlayer();
    World world = server.addSimpleWorld("Multiblock Test World");
    Block top = world.getBlockAt(1234, 92, -60);
    top.setType(multiblock.getStructure()[1]);

    Block self = world.getBlockAt(1234, 91, -60);
    self.setType(multiblock.getStructure()[4]);

    Block bottom = world.getBlockAt(1234, 90, -60);
    bottom.setType(multiblock.getStructure()[7]);

    PlayerInteractEvent event = new PlayerInteractEvent(player, Action.RIGHT_CLICK_BLOCK, new ItemStack(Material.AIR), self, BlockFace.NORTH);
    listener.onRightClick(event);

    Assertions.assertEquals(Result.DENY, event.useInteractedBlock());

    server.getPluginManager().assertEventFired(MultiBlockInteractEvent.class, e -> {
        Assertions.assertEquals(player, e.getPlayer());
        Assertions.assertEquals(self, e.getClickedBlock());
        Assertions.assertEquals(BlockFace.NORTH, e.getClickedFace());
        Assertions.assertEquals(multiblock, e.getMultiBlock());
        return true;
    });
}
 
Example #4
Source File: SlimefunGuideListener.java    From Slimefun4 with GNU General Public License v3.0 6 votes vote down vote up
private Result openGuide(PlayerRightClickEvent e, SlimefunGuideLayout layout) {
    Player p = e.getPlayer();
    ItemStack item = e.getItem();

    if (SlimefunUtils.isItemSimilar(item, SlimefunGuide.getItem(layout), true)) {
        e.cancel();

        if (!SlimefunPlugin.getWorldSettingsService().isWorldEnabled(p.getWorld())) {
            SlimefunPlugin.getLocalization().sendMessage(p, "messages.disabled-item", true);
            return Result.DENY;
        }

        return Result.ALLOW;
    }

    return Result.DEFAULT;
}
 
Example #5
Source File: SlimefunGuideListener.java    From Slimefun4 with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler(priority = EventPriority.LOWEST)
public void onInteract(PlayerRightClickEvent e) {
    Player p = e.getPlayer();

    if (openGuide(e, SlimefunGuideLayout.BOOK) == Result.ALLOW) {
        if (p.isSneaking()) {
            SlimefunGuideSettings.openSettings(p, e.getItem());
        }
        else {
            SlimefunGuide.openGuide(p, SlimefunGuideLayout.BOOK);
        }
    }
    else if (openGuide(e, SlimefunGuideLayout.CHEST) == Result.ALLOW) {
        if (p.isSneaking()) {
            SlimefunGuideSettings.openSettings(p, e.getItem());
        }
        else {
            SlimefunGuide.openGuide(p, SlimefunGuideLayout.CHEST);
        }
    }
    else if (openGuide(e, SlimefunGuideLayout.CHEAT_SHEET) == Result.ALLOW) {
        // We rather just run the command here,
        // all necessary permission checks will be handled there.
        p.chat("/sf cheat");
    }
}
 
Example #6
Source File: VanillaMachinesListener.java    From Slimefun4 with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler(ignoreCancelled = true)
public void onGrindstone(InventoryClickEvent e) {
    // The Grindstone was only ever added in MC 1.14
    MinecraftVersion minecraftVersion = SlimefunPlugin.getMinecraftVersion();
    if (!minecraftVersion.isAtLeast(MinecraftVersion.MINECRAFT_1_14)) {
        return;
    }

    if (e.getRawSlot() == 2 && e.getWhoClicked() instanceof Player && e.getInventory().getType() == InventoryType.GRINDSTONE) {
        ItemStack item1 = e.getInventory().getContents()[0];
        ItemStack item2 = e.getInventory().getContents()[1];

        if (checkForUnallowedItems(item1, item2)) {
            e.setResult(Result.DENY);
        }
    }

}
 
Example #7
Source File: WorldGuardListener.java    From ShopChest with MIT License 6 votes vote down vote up
@EventHandler(priority = EventPriority.LOW)
public void onUseBlock(WrappedUseBlockEvent event) {
    if (Config.enableWorldGuardIntegration) {
        Player player = event.getPlayer();

        if (event.getOriginalEvent() instanceof PlayerInteractEvent) {
            Block block = event.getBlocks().get(0);
            Material type = block.getType();
            
            if (type == Material.CHEST || type == Material.TRAPPED_CHEST) {
                if (isAllowed(player, block.getLocation())) {
                    event.setResult(Result.ALLOW);
                }
            }
        } else if (event.getOriginalEvent() instanceof InventoryOpenEvent) {
            InventoryOpenEvent orig = (InventoryOpenEvent) event.getOriginalEvent();

            if (orig.getInventory().getHolder() instanceof Chest) {
                if (isAllowed(player, ((Chest) orig.getInventory().getHolder()).getLocation())) {
                    event.setResult(Result.ALLOW);
                }
            }
        }
    }
}
 
Example #8
Source File: BlockListener.java    From WorldGuardExtraFlagsPlugin with MIT License 5 votes vote down vote up
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = false)
public void onBlockBreakEvent(BreakBlockEvent event)
{
	Result originalResult = event.getResult();
	Object cause = event.getCause().getRootCause();
	
	if (cause instanceof Player)
	{
		Player player = (Player)cause;

		for(Block block : event.getBlocks())
		{
			ApplicableRegionSet regions = this.plugin.getWorldGuardCommunicator().getRegionContainer().createQuery().getApplicableRegions(block.getLocation());

			Set<Material> state = WorldGuardUtils.queryValue(player, player.getWorld(), regions.getRegions(), Flags.ALLOW_BLOCK_BREAK);
			if (state != null && state.contains(block.getType()))
			{
				event.setResult(Result.ALLOW);
			}
			else
			{
				Set<Material> state2 = WorldGuardUtils.queryValue(player, player.getWorld(), regions.getRegions(), Flags.DENY_BLOCK_BREAK);
				if (state2 != null && state2.contains(block.getType()))
				{
					event.setResult(Result.DENY);
					return;
				}
				else
				{
					event.setResult(originalResult);
					return;
				}
			}
		}
	}
}
 
Example #9
Source File: DisplayProtectionListener.java    From QuickShop-Reremake with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
public void inventory(InventoryClickEvent event) {
    if (!useEnhanceProtection) {
        return;
    }
    if (DisplayItem.getNowUsing() != DisplayType.REALITEM) {
        return;
    }
    if (!DisplayItem.checkIsGuardItemStack(event.getCurrentItem())) {
        return;
    }
    if (event.getClickedInventory() == null) {
        return;
    }
    if (event.getClickedInventory().getLocation() == null) {
        return;
    }
    event.setCancelled(true);

    sendAlert(
            "[DisplayGuard] Inventory "
                    + event.getClickedInventory().getHolder()
                    + " at"
                    + event.getClickedInventory().getLocation()
                    + " was clicked the displayItem, QuickShop already removed it.");
    //event.getCurrentItem().setAmount(0);
    event.getCurrentItem().setType(Material.AIR);
    event.setResult(Result.DENY);
    Util.inventoryCheck(event.getInventory());
}
 
Example #10
Source File: ArmorListener.java    From AdditionsAPI with MIT License 5 votes vote down vote up
@EventHandler(priority =  EventPriority.HIGHEST, ignoreCancelled = true)
public void inventoryDrag(InventoryDragEvent event){
	// getType() seems to always be even.
	// Old Cursor gives the item you are equipping
	// Raw slot is the ArmorType slot
	// Can't replace armor using this method making getCursor() useless.
	ArmorType type = ArmorType.matchType(event.getOldCursor());
	if(event.getRawSlots().isEmpty()) return;// Idk if this will ever happen
	if(type != null && type.getSlot() == event.getRawSlots().stream().findFirst().orElse(0)){
		ArmorEquipEvent armorEquipEvent = new ArmorEquipEvent((Player) event.getWhoClicked(), EquipMethod.DRAG, type, null, event.getOldCursor());
		Bukkit.getServer().getPluginManager().callEvent(armorEquipEvent);
		if(armorEquipEvent.isCancelled()){
			event.setResult(Result.DENY);
			event.setCancelled(true);
		}
	}
	// Debug shit
	/*System.out.println("Slots: " + event.getInventorySlots().toString());
	System.out.println("Raw Slots: " + event.getRawSlots().toString());
	if(event.getCursor() != null){
		System.out.println("Cursor: " + event.getCursor().getType().name());
	}
	if(event.getOldCursor() != null){
		System.out.println("OldCursor: " + event.getOldCursor().getType().name());
	}
	System.out.println("Type: " + event.getType().name());*/
}
 
Example #11
Source File: TestMultiblockListener.java    From Slimefun4 with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testNoMultiblock() {
    Player player = server.addPlayer();
    World world = server.addSimpleWorld("Multiblock Test World");
    Block b = world.getBlockAt(3456, 90, -100);
    b.setType(Material.STONE);

    PlayerInteractEvent event = new PlayerInteractEvent(player, Action.RIGHT_CLICK_BLOCK, new ItemStack(Material.AIR), b, BlockFace.NORTH);
    listener.onRightClick(event);

    // No Multiblock, so nothing should happen
    Assertions.assertEquals(Result.ALLOW, event.useInteractedBlock());
}
 
Example #12
Source File: TestVanillaMachinesListener.java    From Slimefun4 with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testBrewingithVanillaItem() {
    VanillaItem item = TestUtilities.mockVanillaItem(plugin, Material.BLAZE_POWDER, true);
    item.register(plugin);

    InventoryClickEvent event = mockBrewingEvent(item.getItem());
    Assertions.assertEquals(Result.ALLOW, event.getResult());
}
 
Example #13
Source File: TestVanillaMachinesListener.java    From Slimefun4 with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testBrewingWithSlimefunItem() {
    SlimefunItem item = TestUtilities.mockSlimefunItem(plugin, "MOCK_POWDER", new CustomItem(Material.BLAZE_POWDER, "&6Magic Mock Powder"));
    item.register(plugin);

    InventoryClickEvent event = mockBrewingEvent(item.getItem());
    Assertions.assertEquals(Result.DENY, event.getResult());
}
 
Example #14
Source File: TestVanillaMachinesListener.java    From Slimefun4 with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testAnvilWithVanillaItem() {
    VanillaItem item = TestUtilities.mockVanillaItem(plugin, Material.IRON_SWORD, true);
    item.register(plugin);

    InventoryClickEvent event = mockAnvilEvent(item.getItem());
    Assertions.assertEquals(Result.DEFAULT, event.getResult());
}
 
Example #15
Source File: TestVanillaMachinesListener.java    From Slimefun4 with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testAnvilWithSlimefunItem() {
    SlimefunItem item = TestUtilities.mockSlimefunItem(plugin, "MOCKED_IRON_SWORD", new CustomItem(Material.IRON_SWORD, "&6Mock"));
    item.register(plugin);

    InventoryClickEvent event = mockAnvilEvent(item.getItem());
    Assertions.assertEquals(Result.DENY, event.getResult());
}
 
Example #16
Source File: TestVanillaMachinesListener.java    From Slimefun4 with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testCraftEventWithVanillaItem() {
    VanillaItem item = TestUtilities.mockVanillaItem(plugin, Material.DIAMOND, true);
    item.register(plugin);

    CraftItemEvent event = mockCraftingEvent(item.getItem());
    Assertions.assertEquals(Result.DEFAULT, event.getResult());
}
 
Example #17
Source File: TestVanillaMachinesListener.java    From Slimefun4 with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testCraftEventWithChangingSlimefunItem() {
    SlimefunItem item = TestUtilities.mockSlimefunItem(plugin, "CHANGING_ITEM", new CustomItem(Material.DIAMOND, "&dChanging Diamond"));
    item.register(plugin);

    item.setUseableInWorkbench(true);
    CraftItemEvent event = mockCraftingEvent(item.getItem());
    Assertions.assertEquals(Result.DEFAULT, event.getResult());

    item.setUseableInWorkbench(false);
    CraftItemEvent event2 = mockCraftingEvent(item.getItem());
    Assertions.assertEquals(Result.DENY, event2.getResult());
}
 
Example #18
Source File: TestVanillaMachinesListener.java    From Slimefun4 with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testCraftEventWithSlimefunItem() {
    SlimefunItem item = TestUtilities.mockSlimefunItem(plugin, "MOCK_DIAMOND", new CustomItem(Material.DIAMOND, "&cMock Diamond"));
    item.register(plugin);

    CraftItemEvent event = mockCraftingEvent(item.getItem());
    Assertions.assertEquals(Result.DENY, event.getResult());
}
 
Example #19
Source File: TestVanillaMachinesListener.java    From Slimefun4 with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testGrindStoneWithVanillaItem() {
    VanillaItem item = TestUtilities.mockVanillaItem(plugin, Material.ENCHANTED_BOOK, true);
    item.register(plugin);

    InventoryClickEvent event = mockGrindStoneEvent(item.getItem());
    Assertions.assertEquals(Result.DEFAULT, event.getResult());
}
 
Example #20
Source File: TestVanillaMachinesListener.java    From Slimefun4 with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testGrindStoneWithSlimefunItem() {
    SlimefunItem item = TestUtilities.mockSlimefunItem(plugin, "ENCHANTED_MOCK_BOOK", new CustomItem(Material.ENCHANTED_BOOK, "&6Mock"));
    item.register(plugin);

    InventoryClickEvent event = mockGrindStoneEvent(item.getItem());
    Assertions.assertEquals(Result.DENY, event.getResult());
}
 
Example #21
Source File: PickaxeOfTheSeeker.java    From Slimefun4 with GNU General Public License v3.0 5 votes vote down vote up
@Override
public ItemUseHandler getItemHandler() {
    return e -> {
        Player p = e.getPlayer();
        Block closest = findClosestOre(p);

        e.setUseBlock(Result.DENY);

        if (closest == null) {
            SlimefunPlugin.getLocalization().sendMessage(p, "miner.no-ores");
        }
        else {
            double l = closest.getX() + 0.5 - p.getLocation().getX();
            double w = closest.getZ() + 0.5 - p.getLocation().getZ();

            double c = Math.sqrt(l * l + w * w);
            float alpha1 = (float) -(Math.asin(l / c) / Math.PI * 180);
            float alpha2 = (float) (Math.acos(w / c) / Math.PI * 180);

            float yaw = alpha2 > 90 ? (180 - alpha1) : alpha1;
            float pitch = (float) ((-Math.atan((closest.getY() - 0.5 - p.getLocation().getY()) / Math.sqrt(l * l + w * w))) * 180 / Math.PI);

            p.teleport(new Location(p.getWorld(), p.getLocation().getX(), p.getLocation().getY(), p.getLocation().getZ(), yaw, pitch));
        }

        damageItem(p, e.getItem());
    };
}
 
Example #22
Source File: VanillaMachinesListener.java    From Slimefun4 with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(ignoreCancelled = true)
public void onAnvil(InventoryClickEvent e) {
    if (e.getRawSlot() == 2 && e.getInventory().getType() == InventoryType.ANVIL && e.getWhoClicked() instanceof Player) {
        ItemStack item1 = e.getInventory().getContents()[0];
        ItemStack item2 = e.getInventory().getContents()[1];

        if (checkForUnallowedItems(item1, item2)) {
            e.setResult(Result.DENY);
            SlimefunPlugin.getLocalization().sendMessage((Player) e.getWhoClicked(), "anvil.not-working", true);
        }
    }
}
 
Example #23
Source File: ATM.java    From TimeIsMoney with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler
public void onInventoryDrag(InventoryDragEvent e) {
	if (e == null || e.getInventory() == null) return;

	if (openATMs.contains(e.getView().getTopInventory())) {
		e.setResult(Result.DENY);
	}
}
 
Example #24
Source File: UnitMaterial.java    From civcraft with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void onInteract(PlayerInteractEvent event) {
	event.setUseItemInHand(Result.DENY);
	//if (event.getClickedBlock() == null) {
		event.setCancelled(true);
		CivMessage.sendError(event.getPlayer(), "Cannot use this item.");
	//}
}
 
Example #25
Source File: UnitMaterial.java    From civcraft with GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings("deprecation")
@Override
public void onInvShiftClick(InventoryClickEvent event,
		Inventory fromInv, Inventory toInv,
		ItemStack stack) {
	
	if (fromInv.equals(toInv)) {
		event.setCancelled(true);
		event.setResult(Result.DENY);
		return;
	}
	
	if (toInv.getHolder() instanceof Player) {
		Player player = (Player)toInv.getHolder();

		if(!validateUnitUse(player, stack)) {
			CivMessage.sendError(player, "You cannot use this unit because it does not belong to your civlization.");
			event.setCancelled(true);
			return;
		}
		
		//Prevent dropping in two unit materials.
		ConfigUnit unit = Unit.getPlayerUnit(player);
		if (unit != null) {
			//player already has a unit item, cancel this event.
			CivMessage.sendError(player, "You already are a "+unit.name+" cannot pickup another unit item.");
			event.setCancelled(true);
			event.setResult(Result.DENY);
			event.getView().close();
			player.updateInventory();
			return;
		}

		
		onItemToPlayer(player, stack);
	} else if (fromInv.getHolder() instanceof Player) {
		onItemFromPlayer((Player)fromInv.getHolder(), stack);
	}
	
}
 
Example #26
Source File: AncientAltarListener.java    From Slimefun4 with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler
public void onInteract(PlayerRightClickEvent e) {
    if (altar == null || altar.isDisabled() || e.useBlock() == Result.DENY) {
        return;
    }

    Optional<Block> blockOptional = e.getClickedBlock();
    if (!blockOptional.isPresent()) {
        return;
    }

    Block b = blockOptional.get();
    if (b.getType() != Material.ENCHANTING_TABLE && b.getType() != Material.DISPENSER) {
        return;
    }

    Optional<SlimefunItem> slimefunBlock = e.getSlimefunBlock();
    if (!slimefunBlock.isPresent()) {
        return;
    }

    String id = slimefunBlock.get().getID();

    if (id.equals(SlimefunItems.ANCIENT_PEDESTAL.getItemId())) {
        e.cancel();
        usePedestal(b, e.getPlayer());
    }
    else if (id.equals(SlimefunItems.ANCIENT_ALTAR.getItemId())) {
        if (!Slimefun.hasUnlocked(e.getPlayer(), SlimefunItems.ANCIENT_ALTAR.getItem(), true) || altarsInUse.contains(b.getLocation())) {
            e.cancel();
            return;
        }

        // Make altarinuse simply because that was the last block clicked.
        altarsInUse.add(b.getLocation());
        e.cancel();

        useAltar(b, e.getPlayer());
    }
}
 
Example #27
Source File: BlockListener.java    From WorldGuardExtraFlagsPlugin with MIT License 5 votes vote down vote up
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = false)
public void onBlockPlaceEvent(PlaceBlockEvent event)
{
	Result originalResult = event.getResult();
	Object cause = event.getCause().getRootCause();

	if (cause instanceof Player)
	{
		Player player = (Player)cause;

		for(Block block : event.getBlocks())
		{
			ApplicableRegionSet regions = this.plugin.getWorldGuardCommunicator().getRegionContainer().createQuery().getApplicableRegions(block.getLocation());
			
			Set<Material> state = WorldGuardUtils.queryValue(player, player.getWorld(), regions.getRegions(), Flags.ALLOW_BLOCK_PLACE);
			if (state != null && state.contains(block.getType()))
			{
				event.setResult(Result.ALLOW);
			}
			else
			{
				Set<Material> state2 = WorldGuardUtils.queryValue(player, player.getWorld(), regions.getRegions(), Flags.DENY_BLOCK_PLACE);
				if (state2 != null && state2.contains(block.getType()))
				{
					event.setResult(Result.DENY);
					return;
				}
				else
				{
					event.setResult(originalResult);
					return;
				}
			}
    	}
	}
}
 
Example #28
Source File: VanillaMachinesListener.java    From Slimefun4 with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler
public void onCraft(CraftItemEvent e) {
    for (ItemStack item : e.getInventory().getContents()) {
        SlimefunItem sfItem = SlimefunItem.getByItem(item);

        if (sfItem != null && !sfItem.isUseableInWorkbench()) {
            e.setResult(Result.DENY);
            SlimefunPlugin.getLocalization().sendMessage((Player) e.getWhoClicked(), "workbench.not-enhanced", true);
            break;
        }
    }
}
 
Example #29
Source File: KnowledgeTome.java    From Slimefun4 with GNU General Public License v3.0 5 votes vote down vote up
@Override
public ItemUseHandler getItemHandler() {
    return e -> {
        Player p = e.getPlayer();
        ItemStack item = e.getItem();

        e.setUseBlock(Result.DENY);

        ItemMeta im = item.getItemMeta();
        List<String> lore = im.getLore();

        if (lore.get(1).isEmpty()) {
            lore.set(0, ChatColors.color("&7Owner: &b" + p.getName()));
            lore.set(1, ChatColor.BLACK + "" + p.getUniqueId());
            im.setLore(lore);
            item.setItemMeta(im);
            p.getWorld().playSound(p.getLocation(), Sound.ENTITY_PLAYER_LEVELUP, 1F, 1F);
        }
        else {
            UUID uuid = UUID.fromString(ChatColor.stripColor(item.getItemMeta().getLore().get(1)));

            if (p.getUniqueId().equals(uuid)) {
                SlimefunPlugin.getLocalization().sendMessage(p, "messages.no-tome-yourself");
                return;
            }

            PlayerProfile.get(p, profile -> PlayerProfile.fromUUID(uuid, owner -> {
                for (Research research : owner.getResearches()) {
                    research.unlock(p, true);
                }
            }));

            if (p.getGameMode() != GameMode.CREATIVE) {
                ItemUtils.consumeItem(item, false);
            }
        }
    };
}
 
Example #30
Source File: EffCancelEvent.java    From Skript with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void execute(final Event e) {
	if (e instanceof Cancellable)
		((Cancellable) e).setCancelled(cancel);
	if (e instanceof PlayerInteractEvent) {
		EvtClick.interactTracker.eventModified((Cancellable) e);
		((PlayerInteractEvent) e).setUseItemInHand(cancel ? Result.DENY : Result.DEFAULT);
		((PlayerInteractEvent) e).setUseInteractedBlock(cancel ? Result.DENY : Result.DEFAULT);
	} else if (e instanceof BlockCanBuildEvent) {
		((BlockCanBuildEvent) e).setBuildable(!cancel);
	} else if (e instanceof PlayerDropItemEvent) {
		PlayerUtils.updateInventory(((PlayerDropItemEvent) e).getPlayer());
	}
}