org.bukkit.inventory.EquipmentSlot Java Examples

The following examples show how to use org.bukkit.inventory.EquipmentSlot. 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: EquipmentSlotUtils.java    From AdditionsAPI with MIT License 6 votes vote down vote up
public static EquipmentSlot valueFromAttribute(String string) {
	switch(string) {
	case "mainhand":
		return EquipmentSlot.HAND;
	case "offhand":
		return EquipmentSlot.OFF_HAND;
	case "head":
		return EquipmentSlot.HEAD;
	case "chest":
		return EquipmentSlot.CHEST;
	case "feet":
		return EquipmentSlot.FEET;
	case "legs":
		return EquipmentSlot.LEGS;
	default:
		return EquipmentSlot.HAND;
	}
}
 
Example #2
Source File: PlayerInteractEntityListener.java    From Slimefun4 with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler
public void onInteractEntity(PlayerInteractAtEntityEvent e) {
    if (!e.getRightClicked().isValid()) {
        return;
    }

    ItemStack itemStack;

    if (e.getHand() == EquipmentSlot.OFF_HAND) {
        itemStack = e.getPlayer().getInventory().getItemInOffHand();
    }
    else {
        itemStack = e.getPlayer().getInventory().getItemInMainHand();
    }

    SlimefunItem sfItem = SlimefunItem.getByItem(itemStack);

    if (sfItem != null && Slimefun.hasUnlocked(e.getPlayer(), sfItem, true)) {
        sfItem.callItemHandler(EntityInteractHandler.class, handler -> handler.onInteract(e.getPlayer(), e.getRightClicked(), itemStack, e.getHand() == EquipmentSlot.OFF_HAND));
    }
}
 
Example #3
Source File: EquipmentSlotUtils.java    From AdditionsAPI with MIT License 6 votes vote down vote up
public static String valueFromLangFile(EquipmentSlot slot) {
	switch(slot) {
	case CHEST:
		return LangFileUtils.get("when_in_body");
	case FEET:
		return LangFileUtils.get("when_in_feet");
	case HAND:
		return LangFileUtils.get("when_in_main_hand");
	case HEAD:
		return LangFileUtils.get("when_in_head");
	case LEGS:
		return LangFileUtils.get("when_in_legs");
	case OFF_HAND:
		return LangFileUtils.get("when_in_off_hand");
	default:
		return null;
	}
}
 
Example #4
Source File: ChannelPacketHandler.java    From NameTagChanger with MIT License 6 votes vote down vote up
private Object getEnumItemSlot(EquipmentSlot slot) {
    switch (slot) {
        case HAND:
            return ReflectUtil.invokeMethod(null, ENUM_ITEM_SLOT_BY_NAME, "mainhand").getOrThrow();
        case OFF_HAND:
            return ReflectUtil.invokeMethod(null, ENUM_ITEM_SLOT_BY_NAME, "offhand").getOrThrow();
        case FEET:
            return ReflectUtil.invokeMethod(null, ENUM_ITEM_SLOT_BY_NAME, "feet").getOrThrow();
        case LEGS:
            return ReflectUtil.invokeMethod(null, ENUM_ITEM_SLOT_BY_NAME, "legs").getOrThrow();
        case CHEST:
            return ReflectUtil.invokeMethod(null, ENUM_ITEM_SLOT_BY_NAME, "chest").getOrThrow();
        case HEAD:
            return ReflectUtil.invokeMethod(null, ENUM_ITEM_SLOT_BY_NAME, "head").getOrThrow();
        default:
            logMessage(Level.SEVERE, "Unknown EquipmentSlot: " + slot, null);
            return null;
    }
}
 
Example #5
Source File: ItemShortcut.java    From Minepacks with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onItemFrameInteract(PlayerInteractEntityEvent event)
{
	Player player = event.getPlayer();
	ItemStack item;
	if(MCVersion.isDualWieldingMC())
	{
		item = (event.getHand() == EquipmentSlot.HAND) ? player.getInventory().getItemInMainHand() : player.getInventory().getItemInOffHand();
	}
	else
	{
		item = player.getItemInHand();
	}
	if(isItemShortcut(item))
	{
		event.getPlayer().performCommand(openCommand);
		event.setCancelled(true);
	}
}
 
Example #6
Source File: CustomItem.java    From AdditionsAPI with MIT License 6 votes vote down vote up
/**
 * Adds an Attribute to the CustomItem. If you don't know what they do or how
 * they work, check out the Minecraft wiki. The UUID will be the one that is
 * found by default in Minecraft for the specified Slot. The name will be, as a
 * placeholder, TBD (which means To Be Determined).
 * 
 * @param type
 *            The attribute that will be added.
 * @param amount
 *            The amount of the attribute. Can also be a negative value.
 * @param slot
 *            The {@link EquipmentSlot} at which the Attribute will be applied.
 *            For example, the EquipmentSlot HAND will apply the specified
 *            Attribute to the Main Hand only.
 * @param operation
 *            The math operation that will be used for the amount specified.
 */
public CustomItem addAttribute(AttributeType type, double amount, EquipmentSlot slot, Operation operation) {
	switch (slot) {
	case HEAD:
		addAttribute(type, amount, slot, operation, HEAD_UUID);
		return this;
	case CHEST:
		addAttribute(type, amount, slot, operation, CHEST_UUID);
		return this;
	case LEGS:
		addAttribute(type, amount, slot, operation, LEGS_UUID);
		return this;
	case FEET:
		addAttribute(type, amount, slot, operation, FEET_UUID);
		return this;
	case HAND:
		addAttribute(type, amount, slot, operation, MAIN_HAND_UUID);
		return this;
	case OFF_HAND:
		addAttribute(type, amount, slot, operation, OFF_HAND_UUID);
		return this;
	}
	return this;
}
 
Example #7
Source File: DurabilityBar.java    From AdditionsAPI with MIT License 6 votes vote down vote up
public static void hideDurabilityBossBar(Player player, EquipmentSlot slot) {
	UUID uuid = player.getUniqueId();
	BossBar bar;
	HashMap<UUID, BossBar> playersBars;
	if (slot.equals(EquipmentSlot.HAND)) {
		playersBars = playersBarsMain;
	} else if (slot.equals(EquipmentSlot.OFF_HAND)) {
		playersBars = playersBarsOff;
	} else {
		return;
	}
	if (!playersBars.containsKey(uuid)) {
		return;
	} else {
		bar = playersBars.get(uuid);
	}

	bar.setVisible(false);
	bar.setProgress(1.0D);
	bar.setColor(BarColor.GREEN);
}
 
Example #8
Source File: QuestItemHandler.java    From BetonQuest with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler(ignoreCancelled = true)
public void onItemFrameClick(final PlayerInteractEntityEvent event) {
    if (event.getPlayer().getGameMode() == GameMode.CREATIVE) {
        return;
    }
    // this prevents the journal from being placed inside of item frame
    if (event.getRightClicked() instanceof ItemFrame) {
        ItemStack item = null;
        item = (event.getHand() == EquipmentSlot.HAND) ? event.getPlayer().getInventory().getItemInMainHand()
                : event.getPlayer().getInventory().getItemInOffHand();

        final String playerID = PlayerConverter.getID(event.getPlayer());
        if (Journal.isJournal(playerID, item) || Utils.isQuestItem(item)) {
            event.setCancelled(true);
        }
    }
}
 
Example #9
Source File: RegionsTests.java    From Civs with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void membersShouldBeAbleToOpenChests() {
    loadRegionTypePower(false);
    Region region = PortMenuTest.loadRegion("power");
    region.getPeople().put(TestUtil.player.getUniqueId(), "member");
    PlayerInteractEvent playerInteractEvent = new PlayerInteractEvent(
            TestUtil.player,
            Action.RIGHT_CLICK_BLOCK,
            new ItemStack(Material.AIR),
            TestUtil.blockUnique,
            BlockFace.NORTH,
            EquipmentSlot.HAND);
    ProtectionHandler protectionHandler = new ProtectionHandler();
    protectionHandler.onBlockInteract(playerInteractEvent);
    assertSame(Event.Result.ALLOW, playerInteractEvent.useInteractedBlock());
}
 
Example #10
Source File: HeadDropsModule.java    From UHC with MIT License 6 votes vote down vote up
@EventHandler(priority = EventPriority.LOW)
public void on(PlayerDeathEvent event) {
    if (!isEnabled() || RANDOM.nextDouble() < (1D - dropRate)) {
        // set to an empty map to avoid stale metadata problems
        event.getEntity().setMetadata(StandItemsMetadata.KEY, new StandItemsMetadata(plugin));
        return;
    }

    final Player player = event.getEntity();

    // create a head
    final ItemStack head = playerHeadProvider.getPlayerHeadItem(player);

    // add it to the drops
    event.getDrops().add(head);

    // add metadata for the armour stand module to put the helmet on the player and remove from drops
    final EnumMap<EquipmentSlot, ItemStack> standItems = Maps.newEnumMap(EquipmentSlot.class);
    standItems.put(EquipmentSlot.HEAD, head);

    player.setMetadata(StandItemsMetadata.KEY, new StandItemsMetadata(plugin, standItems));
}
 
Example #11
Source File: CraftEventFactory.java    From Kettle with GNU General Public License v3.0 6 votes vote down vote up
public static BlockPlaceEvent callBlockPlaceEvent(World world, EntityPlayer who, EnumHand hand, BlockState replacedBlockState, int clickedX, int clickedY, int clickedZ) {
    CraftWorld craftWorld = world.getWorld();
    CraftServer craftServer = world.getServer();

    Player player = (Player) who.getBukkitEntity();

    Block blockClicked = craftWorld.getBlockAt(clickedX, clickedY, clickedZ);
    Block placedBlock = replacedBlockState.getBlock();

    boolean canBuild = canBuild(craftWorld, player, placedBlock.getX(), placedBlock.getZ());

    org.bukkit.inventory.ItemStack item;
    EquipmentSlot equipmentSlot;
    if (hand == EnumHand.MAIN_HAND) {
        item = player.getInventory().getItemInMainHand();
        equipmentSlot = EquipmentSlot.HAND;
    } else {
        item = player.getInventory().getItemInOffHand();
        equipmentSlot = EquipmentSlot.OFF_HAND;
    }

    BlockPlaceEvent event = new BlockPlaceEvent(placedBlock, replacedBlockState, blockClicked, item, player, canBuild, equipmentSlot);
    craftServer.getPluginManager().callEvent(event);

    return event;
}
 
Example #12
Source File: ItemListener.java    From HubBasics with GNU Lesser General Public License v3.0 5 votes vote down vote up
@EventHandler
public void onRightClick(PlayerInteractEvent event) {
    if (!(event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() == Action.RIGHT_CLICK_BLOCK)) {
        return;
    }
    ItemStack itemStack;
    if (event.getHand() == EquipmentSlot.HAND) {
        itemStack = event.getPlayer().getInventory().getItemInMainHand();
    } else if (event.getHand() == EquipmentSlot.OFF_HAND) {
        itemStack = event.getPlayer().getInventory().getItemInOffHand();
    } else {
        return;
    }
    if (itemStack.getType() != Material.AIR) {
        NBTItem nbtItem = new NBTItem(itemStack);
        if (!nbtItem.hasKey("HubBasics")) return;
        event.setCancelled(true);
        CustomItem item = HubBasics.getInstance().getItemManager().get(nbtItem.getString("HubBasics"));
        if (item == null) {
            itemStack.setType(Material.AIR); // Destroy old item
            return;
        }
        if (!item.getRunOnRightClick()) return;
        if (event.getHand() == EquipmentSlot.OFF_HAND) {
            if (item.getRunOnOffhand()) {
                item.onCommand(event.getPlayer());
            }
        } else {
            item.onCommand(event.getPlayer());
        }
    }
}
 
Example #13
Source File: TestCargoNodeListener.java    From Slimefun4 with GNU General Public License v3.0 5 votes vote down vote up
@ParameterizedTest
@SlimefunItemsSource(items = { "CARGO_INPUT_NODE", "CARGO_OUTPUT_NODE", "CARGO_OUTPUT_NODE_2" })
public void testInvalidPlacement(ItemStack item) {
    Player player = server.addPlayer();
    Location l = new Location(player.getWorld(), 190, 50, 400);
    Block b = l.getBlock();
    Block against = b.getRelative(BlockFace.DOWN);

    BlockPlaceEvent event = new BlockPlaceEvent(b, new BlockStateMock(), against, item, player, true, EquipmentSlot.HAND);
    listener.onCargoNodePlace(event);
    Assertions.assertTrue(event.isCancelled());
}
 
Example #14
Source File: Parser.java    From CardinalPGM with MIT License 5 votes vote down vote up
public static EquipmentSlot getEquipmentSlot(String slotName) {
    if (!slotName.startsWith("slot.")) slotName = "slot." + slotName;
    EquipmentSlot equipmentSlot = null;
    String[] path = slotName.split("\\.");
    if (path.length != 3) return null;
    if (path[1].equalsIgnoreCase("armor")) {
        equipmentSlot = EquipmentSlot.valueOf(Strings.getTechnicalName(path[2]));
    } else if (path[1].equalsIgnoreCase("weapon")) {
        if (path[2].equalsIgnoreCase("mainhand")) equipmentSlot = EquipmentSlot.HAND;
        if (path[2].equalsIgnoreCase("offhand")) equipmentSlot = EquipmentSlot.OFF_HAND;
    }
    return equipmentSlot;
}
 
Example #15
Source File: ClickEventTracker.java    From Skript with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Processes a click event from a player.
 * @param player Player who caused it.
 * @param event The event.
 * @param hand Slot associated with the event.
 * @return If the event should be passed to scripts.
 */
public boolean checkEvent(Player player, Cancellable event, EquipmentSlot hand) {
	UUID uuid = player.getUniqueId();
	TrackedEvent first = firstEvents.get(uuid);
	if (first != null && first.event != event) { // We've checked an event before, and it is not this one
		if (!modifiedEvents.contains(first.event)) {
			// Do not modify cancellation status of event, Skript did not touch it
			// This avoids issues like #2389
			return false;
		}
		
		// Ignore this, but set its cancelled status based on one set to first event
		if (event instanceof PlayerInteractEvent) { // Handle use item/block separately
			// Failing to do so caused issue SkriptLang/Skript#2303
			PlayerInteractEvent firstClick = (PlayerInteractEvent) first.event;
			PlayerInteractEvent click = (PlayerInteractEvent) event;
			click.setUseInteractedBlock(firstClick.useInteractedBlock());
			click.setUseItemInHand(firstClick.useItemInHand());
		} else {
			event.setCancelled(first.event.isCancelled());
		}
		return false;
	} else { // Remember and run this
		firstEvents.put(uuid, new TrackedEvent(event, hand));
		return true;
	}
}
 
Example #16
Source File: TestIronGolemListener.java    From Slimefun4 with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testWithVanillaIron() {
    VanillaItem item = TestUtilities.mockVanillaItem(plugin, Material.IRON_INGOT, true);
    item.register(plugin);

    PlayerInteractEntityEvent event = callIronGolemEvent(EquipmentSlot.HAND, item.getItem());
    Assertions.assertFalse(event.isCancelled());

    PlayerInteractEntityEvent event2 = callIronGolemEvent(EquipmentSlot.OFF_HAND, item.getItem());
    Assertions.assertFalse(event2.isCancelled());
}
 
Example #17
Source File: EquipmentSlotUtils.java    From AdditionsAPI with MIT License 5 votes vote down vote up
public static String toAttributeString(EquipmentSlot slot) {
	if (slot == EquipmentSlot.HAND)
		return "mainhand";
	if (slot == EquipmentSlot.OFF_HAND)
		return "offhand";
	return slot.toString().toLowerCase();
}
 
Example #18
Source File: DurabilityBar.java    From AdditionsAPI with MIT License 5 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST)
public void onItemBreak(PlayerItemBreakEvent event) {
	ItemStack broken = event.getBrokenItem();
	Player player = event.getPlayer();
	PlayerInventory inv = player.getInventory();
	if (broken.equals(inv.getItemInMainHand()))
		hideDurabilityBossBar(player, EquipmentSlot.HAND);
	else if (broken.equals(inv.getItemInOffHand()))
		hideDurabilityBossBar(player, EquipmentSlot.OFF_HAND);
}
 
Example #19
Source File: TestCargoNodeListener.java    From Slimefun4 with GNU General Public License v3.0 5 votes vote down vote up
@ParameterizedTest
@SlimefunItemsSource(items = { "CARGO_INPUT_NODE", "CARGO_OUTPUT_NODE", "CARGO_OUTPUT_NODE_2" })
public void testSidePlacement(ItemStack item) {
    Player player = server.addPlayer();
    Location l = new Location(player.getWorld(), 190, 50, 400);
    Block b = l.getBlock();
    Block against = b.getRelative(BlockFace.NORTH);

    BlockPlaceEvent event = new BlockPlaceEvent(b, new BlockStateMock(), against, item, player, true, EquipmentSlot.HAND);
    listener.onCargoNodePlace(event);
    Assertions.assertFalse(event.isCancelled());
}
 
Example #20
Source File: DurabilityBar.java    From AdditionsAPI with MIT License 5 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST)
public void onItemDamage(PlayerItemDamageEvent event) {
	if (event.isCancelled())
		return;
	Player player = event.getPlayer();
	Bukkit.getScheduler().scheduleSyncDelayedTask(AdditionsAPI.getInstance(), () -> {
		sendDurabilityBossBar(player, player.getInventory().getItemInMainHand(), EquipmentSlot.HAND);
		sendDurabilityBossBar(player, player.getInventory().getItemInOffHand(), EquipmentSlot.OFF_HAND);
	});
}
 
Example #21
Source File: DurabilityBar.java    From AdditionsAPI with MIT License 5 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST)
public void onHandSwitch(PlayerSwapHandItemsEvent event) {
	if (event.isCancelled())
		return;
	sendDurabilityBossBar(event.getPlayer(), event.getMainHandItem(), EquipmentSlot.HAND);
	sendDurabilityBossBar(event.getPlayer(), event.getOffHandItem(), EquipmentSlot.OFF_HAND);
}
 
Example #22
Source File: DeathStandsModule.java    From UHC with MIT License 5 votes vote down vote up
@SuppressWarnings("Duplicates")
protected Map<EquipmentSlot, ItemStack> getItems(ArmorStand stand) {
    final Map<EquipmentSlot, ItemStack> slots = Maps.newHashMapWithExpectedSize(5);

    slots.put(EquipmentSlot.HAND, stand.getItemInHand());
    slots.put(EquipmentSlot.HEAD, stand.getHelmet());
    slots.put(EquipmentSlot.CHEST, stand.getChestplate());
    slots.put(EquipmentSlot.LEGS, stand.getLeggings());
    slots.put(EquipmentSlot.FEET, stand.getBoots());

    return slots;
}
 
Example #23
Source File: DurabilityBar.java    From AdditionsAPI with MIT License 5 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST)
public void onPlayerTeleport(PlayerTeleportEvent event) {
	if (event.isCancelled())
		return;
	Player player = event.getPlayer();
	Bukkit.getScheduler().scheduleSyncDelayedTask(AdditionsAPI.getInstance(), () -> {
		sendDurabilityBossBar(player, player.getInventory().getItemInMainHand(), EquipmentSlot.HAND);
		sendDurabilityBossBar(player, player.getInventory().getItemInOffHand(), EquipmentSlot.OFF_HAND);
	});
}
 
Example #24
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 onLeftClick(PlayerInteractEvent event) {
    if (!(event.getAction() == Action.LEFT_CLICK_AIR || event.getAction() == Action.LEFT_CLICK_BLOCK)) {
        return;
    }
    ItemStack itemStack;
    if (event.getHand() == EquipmentSlot.HAND) {
        itemStack = event.getPlayer().getInventory().getItemInMainHand();
    } else if (event.getHand() == EquipmentSlot.OFF_HAND) {
        itemStack = event.getPlayer().getInventory().getItemInOffHand();
    } else {
        return;
    }
    if (itemStack.getType() != Material.AIR) {
        NBTItem nbtItem = new NBTItem(itemStack);
        if (!nbtItem.hasKey("HubBasics")) return;
        event.setCancelled(true);
        CustomItem item = HubBasics.getInstance().getItemManager().get(nbtItem.getString("HubBasics"));
        if (item == null) {
            itemStack.setType(Material.AIR); // Destroy old item
            return;
        }
        if (!item.getRunOnLeftClick()) return;
        if (event.getHand() == EquipmentSlot.OFF_HAND) {
            if (item.getRunOnOffhand()) {
                item.onCommand(event.getPlayer());
            }
        } else {
            item.onCommand(event.getPlayer());
        }
    }
}
 
Example #25
Source File: ObserverModule.java    From CardinalPGM with MIT License 5 votes vote down vote up
@EventHandler(ignoreCancelled = true)
public void onPlayerInteractEntity(PlayerInteractEntityEvent event) {
    if (testObserver(event.getPlayer())) {
        if (event.getRightClicked() instanceof Player && !event.getPlayer().isSneaking()){
            if (event.getHand().equals(EquipmentSlot.HAND)) openInventory(event.getPlayer(), (Player) event.getRightClicked(), false);
        } else if (event.getRightClicked() instanceof ItemFrame) {
            event.setCancelled(true);
        }
    }
}
 
Example #26
Source File: ItemUseListener.java    From EnchantmentsEnhance with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler
public void onItemClick(final PlayerInteractEvent event) {
    final Player player = event.getPlayer();

    if (event.getMaterial() == Material.AIR) {
        return;
    }
    if (event.getAction().equals(Action.LEFT_CLICK_BLOCK) || event.getAction().equals(Action.LEFT_CLICK_AIR)) {
        return;
    }
    final ItemStack item = event.getItem();
    if (!ItemManager.getGive(item).isEmpty()) {
        String[] give = ItemManager.getGive(item).split(":");
        if (give.length == 2) {
            int id = Integer.parseInt(give[0]);
            int amount = Integer.parseInt(give[1]);
            if (id < 0) {
                Main.getApi().addAdvice(player.getName(), amount);
                Util.sendMessage(SettingsManager.lang.getString("materialize.adviceSucess")
                        .replace("%level%", Integer.toString(amount)), player);
            } else {
                Main.getApi().addItem(player.getName(), id, amount);
                Util.sendMessage(SettingsManager.lang.getString("materialize.success")
                        .replace("%amount%", Integer.toString(amount))
                        .replace("%item%", SettingsManager.lang.getString("item." + id)), player);
            }
            // Consume the item.
            try {
                if (event.getHand().equals(EquipmentSlot.HAND)) {
                    consumeItem(Util.getMainHand(player), player);
                } else if (event.getHand().equals(EquipmentSlot.OFF_HAND)) {
                    consumeItem(player.getInventory().getItemInOffHand(), player);
                }
            } catch (NoSuchMethodError ex) {
                consumeItem(Util.getMainHand(player), player);
            }
            event.setCancelled(true);
        }
    }
}
 
Example #27
Source File: DebugFishListener.java    From Slimefun4 with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler
public void onDebug(PlayerInteractEvent e) {
    if (e.getAction() == Action.PHYSICAL || e.getHand() != EquipmentSlot.HAND) {
        return;
    }

    Player p = e.getPlayer();

    if (p.isOp() && SlimefunUtils.isItemSimilar(e.getItem(), SlimefunItems.DEBUG_FISH, true)) {
        e.setCancelled(true);

        if (e.getAction() == Action.LEFT_CLICK_BLOCK) {
            if (p.isSneaking()) {
                if (BlockStorage.hasBlockInfo(e.getClickedBlock())) {
                    BlockStorage.clearBlockInfo(e.getClickedBlock());
                }
            }
            else {
                e.setCancelled(false);
            }
        }
        else if (e.getAction() == Action.RIGHT_CLICK_BLOCK) {
            if (p.isSneaking()) {
                Block b = e.getClickedBlock().getRelative(e.getBlockFace());
                b.setType(Material.PLAYER_HEAD);
                SkullBlock.setFromHash(b, HeadTexture.MISSING_TEXTURE.getTexture());
            }
            else if (BlockStorage.hasBlockInfo(e.getClickedBlock())) {
                sendInfo(p, e.getClickedBlock());
            }
        }
    }
}
 
Example #28
Source File: SignListener.java    From RandomTeleport with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(ignoreCancelled = true)
public void onSignClick(PlayerInteractEvent event) {
    if (event.getHand() == EquipmentSlot.HAND && event.getAction() == Action.RIGHT_CLICK_BLOCK
            && event.getClickedBlock() != null && event.getClickedBlock().getType().name().contains("SIGN")) {
        Sign sign = (Sign) event.getClickedBlock().getState();
        if (plugin.matchesSignVariable(sign.getLine(1))) {
            String preset = sign.getLine(2).toLowerCase();
            if (event.getPlayer().hasPermission("randomteleport.sign.preset." + preset)) {
                if (plugin.getConfig().getString("presets." + preset) == null) {
                    plugin.sendMessage(event.getPlayer(), "error.preset-doesnt-exist", "preset", preset);
                } else {
                    for (RandomSearcher searcher : plugin.getRunningSearchers().values()) {
                        if (searcher.getTargets().contains(event.getPlayer())) {
                            plugin.sendMessage(event.getPlayer(), "error.already-searching", "preset", preset);
                            return;
                        }
                    }

                    try {
                        plugin.runPreset(plugin.getServer().getConsoleSender(), preset, event.getPlayer(), event.getClickedBlock().getLocation());
                    } catch (IllegalArgumentException e) {
                        plugin.sendMessage(event.getPlayer(), "error.preset-invalid", "preset", preset);
                        plugin.getLogger().log(Level.SEVERE, "Error while parsing preset " + preset, e);
                    }
                }
            } else {
                plugin.sendMessage(event.getPlayer(), "sign.no-permission.use",
                        "preset", preset,
                        "perm", "randomteleport.sign.use"
                );
            }
        }
    }
}
 
Example #29
Source File: NMSHacks.java    From ProjectAres with GNU Affero General Public License v3.0 5 votes vote down vote up
public static void useEntity(Player user, Entity target, boolean attack, EquipmentSlot hand) {
    ((CraftPlayer) user).getHandle().playerConnection.a(new PacketPlayInUseEntity(
        target.getEntityId(),
        attack ? PacketPlayInUseEntity.EnumEntityUseAction.ATTACK : PacketPlayInUseEntity.EnumEntityUseAction.INTERACT,
        null,
        hand == EquipmentSlot.OFF_HAND ? EnumHand.OFF_HAND : EnumHand.MAIN_HAND
    ));
}
 
Example #30
Source File: TestCargoNodeListener.java    From Slimefun4 with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testNonCargoNode() {
    Player player = server.addPlayer();
    Location l = new Location(player.getWorld(), 190, 50, 400);
    Block b = l.getBlock();
    Block against = b.getRelative(BlockFace.DOWN);

    ItemStack item = new ItemStack(Material.PLAYER_HEAD);

    BlockPlaceEvent event = new BlockPlaceEvent(b, new BlockStateMock(), against, item, player, true, EquipmentSlot.HAND);
    listener.onCargoNodePlace(event);
    Assertions.assertFalse(event.isCancelled());
}