Java Code Examples for org.bukkit.event.block.Action

The following examples show how to use org.bukkit.event.block.Action. These examples are extracted from open source projects. 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
@EventHandler
public void onTrackerUse(PlayerInteractEvent event) {
    Player player = event.getPlayer();
    if (!Main.isPlayerInGame(player)) {
        return;
    }

    GamePlayer gamePlayer = Main.getPlayerGameProfile(player);
    Game game = gamePlayer.getGame();
    if (event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() == Action.RIGHT_CLICK_BLOCK) {
        if (game.getStatus() == GameStatus.RUNNING && !gamePlayer.isSpectator) {
            if (event.getItem() != null) {
                ItemStack stack = event.getItem();
                String unhidden = APIUtils.unhashFromInvisibleStringStartsWith(stack, TRACKER_PREFIX);
                if (unhidden != null) {
                    event.setCancelled(true);

                    Tracker tracker = new Tracker(game, player, game.getTeamOfPlayer(player));
                    tracker.runTask();
                }
            }
        }
    }
}
 
Example 2
Source Project: AnnihilationPro   Source File: SpecialItemKit.java    License: MIT License 6 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST)
public void specialItemActionCheck(final PlayerInteractEvent event)
{
	if(useDefaultChecking())
	{
		if(event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() == Action.RIGHT_CLICK_BLOCK)
		{
			if(event.getItem() != null && event.getItem().getType() == specialItem.getType())
			{
				AnniPlayer p = AnniPlayer.getPlayer(event.getPlayer().getUniqueId());
				if(p != null && p.getKit().equals(this) && isSpecialItem(event.getItem()))
				{
					event.setCancelled(true);
					if(!delays.hasActiveDelay(event.getPlayer(), getInternalName()))
					{
						//Do firestorm
						if(performSpecialAction(event.getPlayer(),p) && getDelayLength() > 0)
							delays.addDelay(event.getPlayer(), System.currentTimeMillis()+getDelayLength(), getInternalName());
					}
				}
			}
		}
	}
}
 
Example 3
Source Project: askyblock   Source File: IslandGuard.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Prevents usage of an Ender Chest
 *
 * @param event
 */

@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onEnderChestEvent(final PlayerInteractEvent event) {
    if (DEBUG) {
        plugin.getLogger().info("Ender chest " + event.getEventName());
    }
    Player player = event.getPlayer();
    if (inWorld(player) || player.getWorld().equals(ASkyBlock.getNetherWorld())) {
        if (event.getAction() == Action.RIGHT_CLICK_BLOCK) {
            if (event.getClickedBlock().getType() == Material.ENDER_CHEST) {
                if (!(event.getPlayer().hasPermission(Settings.PERMPREFIX + "craft.enderchest"))) {
                    Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).errorNoPermission);
                    event.setCancelled(true);
                }
            }
        }
    }
}
 
Example 4
Source Project: civcraft   Source File: PlayerListener.java    License: GNU General Public License v2.0 6 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST)
public void onInventoryOpenEvent(InventoryOpenEvent event) {
	if (event.getInventory() instanceof DoubleChestInventory) {
		DoubleChestInventory doubleInv = (DoubleChestInventory)event.getInventory();
					
		Chest leftChest = (Chest)doubleInv.getHolder().getLeftSide();			
		/*Generate a new player 'switch' event for the left and right chests. */
		PlayerInteractEvent interactLeft = new PlayerInteractEvent((Player)event.getPlayer(), Action.RIGHT_CLICK_BLOCK, null, leftChest.getBlock(), null);
		BlockListener.OnPlayerSwitchEvent(interactLeft);
		
		if (interactLeft.isCancelled()) {
			event.setCancelled(true);
			return;
		}
		
		Chest rightChest = (Chest)doubleInv.getHolder().getRightSide();
		PlayerInteractEvent interactRight = new PlayerInteractEvent((Player)event.getPlayer(), Action.RIGHT_CLICK_BLOCK, null, rightChest.getBlock(), null);
		BlockListener.OnPlayerSwitchEvent(interactRight);
		
		if (interactRight.isCancelled()) {
			event.setCancelled(true);
			return;
		}			
	}
}
 
Example 5
Source Project: uSkyBlock   Source File: ToolMenuEvents.java    License: GNU General Public License v3.0 6 votes vote down vote up
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onBlockHit(PlayerInteractEvent e) {
    if (e == null || e.getClickedBlock() == null
            || e.getAction() != Action.LEFT_CLICK_BLOCK || e.getPlayer().getGameMode() != GameMode.SURVIVAL) {
        return;
    }
    Player player = e.getPlayer();
    if (!plugin.getWorldManager().isSkyAssociatedWorld(player.getWorld()) || !isTool(e.getItem())) {
        return;
    }

    // We are in a skyworld, a block has been hit, with the tool
    Material block = e.getClickedBlock().getType();
    short data = e.getClickedBlock().getData();
    String itemId = ItemStackUtil.asString(new ItemStack(block, 1, data));
    if (commandMap.containsKey(itemId)) {
        doCmd(e, player, itemId);
    }
    if (!e.isCancelled()) {
        itemId = ItemStackUtil.asString(new ItemStack(block, 1));
        if (commandMap.containsKey(itemId)) {
            doCmd(e, player, itemId);
        }
    }
}
 
Example 6
Source Project: Shopkeepers   Source File: SignShopListener.java    License: 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 7
Source Project: civcraft   Source File: NoCauldronWash.java    License: GNU General Public License v2.0 6 votes vote down vote up
@SuppressWarnings("deprecation")
public void onInteract(PlayerInteractEvent event) {
	if (event.getAction().equals(Action.RIGHT_CLICK_AIR) || event.getAction().equals(Action.RIGHT_CLICK_BLOCK)) {
		if (!event.hasBlock()) {
			return;
		}
					
		BlockCoord bcoord = new BlockCoord(event.getClickedBlock());
					
		if (ItemManager.getId(bcoord.getBlock()) == ItemManager.getId(Material.CAULDRON)) {			
			event.getPlayer().updateInventory();
			event.setCancelled(true);
			return;
		}
	}
}
 
Example 8
Source Project: CloudNet   Source File: SignSelector.java    License: Apache License 2.0 6 votes vote down vote up
@EventHandler
public void handleInteract(PlayerInteractEvent e) {
    if ((e.getAction().equals(Action.RIGHT_CLICK_BLOCK)) && e.getClickedBlock() != null && e.getClickedBlock()
                                                                                            .getState() instanceof org.bukkit.block.Sign) {
        if (containsPosition(e.getClickedBlock().getLocation())) {
            Sign sign = getSignByPosition(e.getClickedBlock().getLocation());
            if (sign.getServerInfo() != null) {
                String s = sign.getServerInfo().getServiceId().getServerId();
                ByteArrayDataOutput output = ByteStreams.newDataOutput();
                output.writeUTF("Connect");
                output.writeUTF(s);
                e.getPlayer().sendPluginMessage(CloudServer.getInstance().getPlugin(), "BungeeCord", output.toByteArray());
            }
        }
    }
}
 
Example 9
Source Project: uSkyBlock   Source File: SignEvents.java    License: GNU General Public License v3.0 6 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST)
public void onBlockHit(PlayerInteractEvent e) {
    Player player = e.getPlayer();
    if (e.getPlayer() == null
            || e.getClickedBlock() == null
            || e.getAction() != Action.RIGHT_CLICK_BLOCK
            || e.getPlayer().getGameMode() != GameMode.SURVIVAL
            || !isSign(e.getClickedBlock().getType())
            || !player.hasPermission("usb.island.signs.use")
            || !plugin.getWorldManager().isSkyAssociatedWorld(player.getWorld())) {
        return;
    }

    if (e.getClickedBlock().getState() instanceof Sign) {
        Sign sign = (Sign) e.getClickedBlock().getState();
        String firstLine = FormatUtil.stripFormatting(sign.getLine(0)).trim();
        if (firstLine.startsWith("/")) {
            e.setCancelled(true);
            player.performCommand(firstLine.substring(1));
        }
    }
}
 
Example 10
Source Project: SkyWarsReloaded   Source File: SignListener.java    License: GNU General Public License v3.0 6 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = false)
public void onPlayerInteract(PlayerInteractEvent e) {
	Player player = e.getPlayer();
   	if (e.getAction() == Action.RIGHT_CLICK_BLOCK) {
   		 if (e.getClickedBlock().getType() == Material.WALL_SIGN || e.getClickedBlock().getType() == SkyWarsReloaded.getNMS().getMaterial("SIGN_POST").getType()) {
   				Sign s = (Sign) e.getClickedBlock().getState();
   			    Location loc = s.getLocation();
   			    SWRServer server = SWRServer.getSign(loc);
   			    if (server != null) {
   			    	if (server.getMatchState().equals(MatchState.WAITINGSTART) && server.getPlayerCount() < server.getMaxPlayers()) {
   			    		server.setPlayerCount(server.getPlayerCount() + 1);
       			    	server.updateSigns();
   			    		SkyWarsReloaded.get().sendBungeeMsg(player, "Connect", server.getServerName());
   					}
   			    }
   		 }
   	}
}
 
Example 11
@EventHandler
public void onPlayerInteract(PlayerInteractEvent event) {
    Player player = event.getPlayer();

    if (!(Gizmos.gizmoMap.get(player) instanceof LauncherGizmo)) return;

    if (event.getAction() != Action.RIGHT_CLICK_BLOCK && event.getAction() != Action.RIGHT_CLICK_AIR) return;
    if (player.getItemInHand().getType() != this.getIcon()) return;

    Firework oldFirework = this.launchedPlayers.get(player);
    if (oldFirework == null || oldFirework.isDead()) {
        Firework firework = this.buildFirework(player.getLocation());
        firework.setPassenger(player);
        this.launchedPlayers.put(player, firework);
    }
}
 
Example 12
Source Project: QualityArmory   Source File: QAListener.java    License: GNU General Public License v3.0 6 votes vote down vote up
@EventHandler
public void onAnvilClick(final PlayerInteractEvent e) {
	if (e.getAction() == Action.RIGHT_CLICK_BLOCK && e.getClickedBlock().getType() == Material.ANVIL
			&& QAMain.overrideAnvil && !e.getPlayer().isSneaking()) {
		QAMain.DEBUG("ANVIL InteractEvent Called");
		if (QAMain.shouldSend && !QAMain.resourcepackReq.contains(e.getPlayer().getUniqueId())) {
			QualityArmory.sendResourcepack(e.getPlayer(), true);
			e.setCancelled(true);
			QAMain.DEBUG("Resourcepack message being sent!");
			return;
		}
		if (!e.getPlayer().hasPermission("qualityarmory.craft")) {
			e.getPlayer().sendMessage(QAMain.prefix + ChatColor.RED + QAMain.S_ANVIL);
			return;
		}
		e.getPlayer().openInventory(QAMain.createCraft(0));
		e.setCancelled(true);
		QAMain.DEBUG("Opening crafting menu");
		return;
	}
}
 
Example 13
Source Project: ChestCommands   Source File: SignListener.java    License: GNU General Public License v3.0 6 votes vote down vote up
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onInteract(PlayerInteractEvent event) {

	if (event.getAction() == Action.RIGHT_CLICK_BLOCK && event.hasBlock() && event.getClickedBlock().getState() instanceof Sign) {

		Sign sign = (Sign) event.getClickedBlock().getState();
		if (sign.getLine(0).equalsIgnoreCase(ChatColor.DARK_BLUE + "[menu]")) {

			sign.getLine(1);
			ExtendedIconMenu iconMenu = ChestCommands.getFileNameToMenuMap().get(BukkitUtils.addYamlExtension(sign.getLine(1)));
			if (iconMenu != null) {

				if (event.getPlayer().hasPermission(iconMenu.getPermission())) {
					iconMenu.open(event.getPlayer());
				} else {
					iconMenu.sendNoPermissionMessage(event.getPlayer());
				}

			} else {
				sign.setLine(0, ChatColor.RED + ChatColor.stripColor(sign.getLine(0)));
				event.getPlayer().sendMessage(ChestCommands.getLang().menu_not_found);
			}
		}
	}
}
 
Example 14
Source Project: NBTEditor   Source File: CustomItemListener.java    License: GNU General Public License v3.0 6 votes vote down vote up
@EventHandler
private void playerInteract(PlayerInteractEvent event) {
	Action action = event.getAction();
	if (action != Action.PHYSICAL) {
		if (action == Action.RIGHT_CLICK_BLOCK && _interationMaterials.contains(event.getClickedBlock().getType())) {
			return;
		}
		CustomItem customItem = CustomItemManager.getCustomItem(event.getItem());
		if (customItem != null) {
			if (verifyCustomItem(customItem, event.getPlayer(), false)) {
				if (action == Action.RIGHT_CLICK_AIR || action == Action.RIGHT_CLICK_BLOCK) {
					customItem.onRightClick(event, new PlayerDetails(event));
				} else if (action == Action.LEFT_CLICK_AIR || action == Action.LEFT_CLICK_BLOCK) {
					customItem.onLeftClick(event, new PlayerDetails(event));
				}
			} else {
				event.setCancelled(true);
			}
		}
	}
}
 
Example 15
Source Project: VoxelGamesLibv2   Source File: SignButtons.java    License: MIT License 6 votes vote down vote up
@EventHandler
public void signInteract(@Nonnull PlayerInteractEvent event) {
    if (event.getAction() != Action.RIGHT_CLICK_BLOCK || event.getClickedBlock() == null) {
        return;
    }
    // is block a sign?
    if (event.getClickedBlock().getState() instanceof Sign) {
        User user = userHandler.getUser(event.getPlayer().getUniqueId()).orElseThrow(() -> new UserException(
                "Unknown user " + event.getPlayer().getDisplayName() + "(" + event.getPlayer().getUniqueId() + ")"));
        Sign sign = (Sign) event.getClickedBlock().getState();
        for (int i = 0; i < sign.getLines().length; i++) {
            String line = sign.getLines()[i];
            for (String key : getButtons().keySet()) {
                if (line.contains("[" + key + "]")) {
                    //TODO implement perm check
                    getButtons().get(key).execute(user, event.getClickedBlock());
                }
            }
        }
    }
}
 
Example 16
Source Project: HeavySpleef   Source File: FlagLeaveItem.java    License: GNU General Public License v3.0 6 votes vote down vote up
@EventHandler
public void onPlayerInteract(PlayerInteractEvent event) {
	SpleefPlayer player = getHeavySpleef().getSpleefPlayer(event.getPlayer());
	if (!game.isIngame(player)) {
		return;
	}
	
	if (event.getAction() != Action.RIGHT_CLICK_AIR && event.getAction() != Action.RIGHT_CLICK_BLOCK) {
		return;
	}
	
	MetadatableItemStack clicked = new MetadatableItemStack(player.getBukkitPlayer().getItemInHand());
	if (!clicked.hasItemMeta() || !clicked.getItemMeta().hasLore() || !clicked.hasMetadata(LEAVE_ITEM_KEY)) {
		return;
	}
	
	game.requestLose(player, QuitCause.SELF);
}
 
Example 17
@EventHandler
public void onRightClick(PlayerInteractEvent event) {
    if (!(event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() == Action.RIGHT_CLICK_BLOCK)) {
        return;
    }
    ItemStack itemStack = ReflectionUtils.invokeMethod(event.getPlayer(), this.getItemInHandMethod);
    if (itemStack != null && 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;
        item.onCommand(event.getPlayer());
    }
}
 
Example 18
Source Project: AnnihilationPro   Source File: Scorpio.java    License: MIT License 6 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST)
public void specialItemActionCheck(final PlayerInteractEvent event)
{
	if(event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() == Action.RIGHT_CLICK_BLOCK)
	{
		Player player = event.getPlayer();
		AnniPlayer pl = AnniPlayer.getPlayer(player.getUniqueId());
		if(pl != null && pl.getKit().equals(this))
		{
			if(this.isHookItem(player.getItemInHand()))
			{
				if(!Delays.getInstance().hasActiveDelay(player, this.getInternalName()))
				{
					Delays.getInstance().addDelay(player, System.currentTimeMillis()+5000, this.getInternalName());//kits.addDelay(player.getName(), DelayType.SCORPIO, 10, TimeUnit.SECONDS);
					Item item = player.getWorld().dropItem(player.getEyeLocation(), new ItemStack(Material.NETHER_STAR,1));
					item.setPickupDelay(Integer.MAX_VALUE);
					item.setVelocity(player.getEyeLocation().getDirection().multiply(2));
					Bukkit.getScheduler().scheduleSyncDelayedTask(AnnihilationMain.getInstance(), new HookTracer(item,pl,90,this.getName()), 1);
				}
			}
		}
	}
}
 
Example 19
Source Project: Civs   Source File: RegionsTests.java    License: 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 20
Source Project: Civs   Source File: ProtectionsTests.java    License: GNU General Public License v3.0 6 votes vote down vote up
@Test
    public void chestUseShouldBeCancelled() {
        RegionsTests.loadRegionTypeCobble();
        Player player = mock(Player.class);
        UUID uuid = new UUID(1, 2);
        when(player.getUniqueId()).thenReturn(uuid);
        Player player2 = mock(Player.class);
        UUID uuid2 = new UUID(1, 3);
        when(player2.getUniqueId()).thenReturn(uuid2);

        HashMap<UUID, String> owners = new HashMap<>();

        owners.put(uuid2, Constants.OWNER);
        Location regionLocation = new Location(Bukkit.getWorld("world"), 0,0,0);
        HashMap<String, String> effects = new HashMap<>();
        effects.put("block_break", null);
        effects.put("block_build", null);
        effects.put("chest_use", null);
        RegionManager.getInstance().addRegion(new Region("cobble", owners, regionLocation, RegionsTests.getRadii(), effects,0));
        ProtectionHandler protectionHandler = new ProtectionHandler();
        PlayerInteractEvent event = new PlayerInteractEvent(player, Action.RIGHT_CLICK_BLOCK,null,Bukkit.getWorld("world").getBlockAt(0,0,0), BlockFace.NORTH);
//        BlockBreakEvent event = new BlockBreakEvent(TestUtil.block3, player);
        protectionHandler.onBlockInteract(event);
        assertTrue(event.isCancelled());
    }
 
Example 21
Source Project: AdditionsAPI   Source File: ArmorListener.java    License: MIT License 6 votes vote down vote up
@EventHandler(priority =  EventPriority.HIGHEST, ignoreCancelled = true)
public void playerInteractEvent(PlayerInteractEvent e){
	if(e.getAction() == Action.PHYSICAL) return;
	if(e.getAction() == Action.RIGHT_CLICK_AIR || e.getAction() == Action.RIGHT_CLICK_BLOCK){
		Player player = e.getPlayer();
		ArmorType newArmorType = ArmorType.matchType(e.getItem());
		if(newArmorType != null){
			if(newArmorType.equals(ArmorType.HELMET) && isAirOrNull(e.getPlayer().getInventory().getHelmet()) || newArmorType.equals(ArmorType.CHESTPLATE) && isAirOrNull(e.getPlayer().getInventory().getChestplate()) || newArmorType.equals(ArmorType.LEGGINGS) && isAirOrNull(e.getPlayer().getInventory().getLeggings()) || newArmorType.equals(ArmorType.BOOTS) && isAirOrNull(e.getPlayer().getInventory().getBoots())){
				ArmorEquipEvent armorEquipEvent = new ArmorEquipEvent(e.getPlayer(), EquipMethod.HOTBAR, ArmorType.matchType(e.getItem()), null, e.getItem());
				Bukkit.getServer().getPluginManager().callEvent(armorEquipEvent);
				if(armorEquipEvent.isCancelled()){
					e.setCancelled(true);
					player.updateInventory();
				}
			}
		}
	}
}
 
Example 22
Source Project: StaffPlus   Source File: PlayerInteract.java    License: GNU General Public License v3.0 6 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST)
public void onInteract(PlayerInteractEvent event)
{
	Player player = event.getPlayer();
	UUID uuid = player.getUniqueId();
	Action action = event.getAction();
	ItemStack item = player.getItemInHand();
	
	if(cpsHandler.isTesting(uuid) && (action == Action.LEFT_CLICK_AIR || action == Action.LEFT_CLICK_BLOCK))
	{
		cpsHandler.updateCount(uuid);
		return;
	}
	
	if(!modeCoordinator.isInMode(uuid) || item == null)
	{
		return;
	}
	
	if(handleInteraction(player, item, action))
	{
		event.setCancelled(true);
	}
}
 
Example 23
Source Project: ZombieEscape   Source File: ServerListener.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * This is specific to my test server to prevent Crop trample.
 */
@EventHandler
public void onTrample(PlayerInteractEvent e) {
    if (e.getClickedBlock() == null) {
        return;
    }

    if (e.getAction() == Action.PHYSICAL) {
        Block block = e.getClickedBlock();

        Material material = block.getType();

        if (material == Material.CROPS || material == Material.SOIL) {
            e.setUseInteractedBlock(PlayerInteractEvent.Result.DENY);
            e.setCancelled(true);

            block.setType(material);
            block.setData(block.getData());
        }
    }
}
 
Example 24
Source Project: HubBasics   Source File: JumpPads.java    License: GNU Lesser General Public License v3.0 6 votes vote down vote up
@EventHandler
public void onPlayerInteract(PlayerInteractEvent event) {
    if (!needsPressurePlate(event.getPlayer())) return;
    Player player = event.getPlayer();
    if (event.getAction() == Action.PHYSICAL && !event.isCancelled() && isEnabledInWorld(player.getWorld())) {
        if (event.getClickedBlock().getType() == getPlateType(player)) {
            boolean apply = true;
            if (isBlockRequired(player)) {
                Location loc = event.getClickedBlock().getLocation().subtract(0, 1, 0);
                apply = loc.getWorld().getBlockAt(loc).getType() == getMaterial(player);
            }
            if (apply) {
                player.setVelocity(calculateVector(player));
                if (getSound(player) != null) {
                    player.playSound(player.getLocation(), getSound(player), 1, 1);
                }
                if (getEffect(player) != null) {
                    particleEffect.display(getEffect(player), player.getLocation(), 1, 1, 1, 1, 40);
                }
                event.setCancelled(true);
            }
        }
    }
}
 
Example 25
Source Project: Slimefun4   Source File: DebugFishListener.java    License: 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 26
Source Project: RandomTeleport   Source File: SignListener.java    License: 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 27
@EventHandler
public void onRightClick(PlayerInteractEvent e) {
    if (e.getAction() == Action.RIGHT_CLICK_AIR || e.getAction() == Action.RIGHT_CLICK_BLOCK) {
        if (SlimefunUtils.isItemSimilar(e.getItem(), SlimefunItems.DEBUG_FISH, true)) {
            return;
        }

        PlayerRightClickEvent event = new PlayerRightClickEvent(e);
        Bukkit.getPluginManager().callEvent(event);

        boolean itemUsed = e.getHand() == EquipmentSlot.OFF_HAND;

        if (event.useItem() != Result.DENY) {
            rightClickItem(e, event, itemUsed);
        }

        if (!itemUsed && event.useBlock() != Result.DENY && !rightClickBlock(e, event)) {
            return;
        }

        if (e.useInteractedBlock() != Result.DENY) {
            e.setUseInteractedBlock(event.useBlock());
        }

        if (e.useItemInHand() != Result.DENY) {
            e.setUseItemInHand(event.useItem());
        }
    }
}
 
Example 28
@Nullable
ClickType convertClick(Action action, Player player) {
  switch (action) {
    case LEFT_CLICK_BLOCK:
    case LEFT_CLICK_AIR:
      return ClickType.LEFT;

    case RIGHT_CLICK_BLOCK:
    case RIGHT_CLICK_AIR:
      return convertClick(ClickType.RIGHT, player);

    default:
      return null;
  }
}
 
Example 29
Source Project: CardinalPGM   Source File: TeamPicker.java    License: MIT License 5 votes vote down vote up
@EventHandler
public void onPlayerInteract(PlayerInteractEvent event) {
    Match match = GameHandler.getGameHandler().getMatch();
    if (!match.hasEnded() && !(Blitz.matchIsBlitz() && match.isRunning()) && ObserverModule.testObserverOrDead(event.getPlayer())
            && (event.getAction().equals(Action.RIGHT_CLICK_AIR) || event.getAction().equals(Action.RIGHT_CLICK_BLOCK))
            && event.getItem() != null && event.getItem().equals(getTeamPicker(event.getPlayer().getLocale()))) {
        event.setCancelled(true);
        event.getPlayer().openInventory(getTeamPicker(event.getPlayer()));
    }
}
 
Example 30
Source Project: AnnihilationPro   Source File: GameMap.java    License: MIT License 5 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
	public void signClickCheck(PlayerInteractEvent event)
	{
		if(event.getAction() == Action.RIGHT_CLICK_BLOCK)
		{
			Block b = event.getClickedBlock();
			if(b != null)
			{
				//Bukkit.getLogger().info("Error test 1");
				if(b.getType() == Material.FURNACE || b.getType() == Material.BURNING_FURNACE)
				{
					//Bukkit.getLogger().info("Error test 1");
					MapKey key = MapKey.getKey(b.getLocation());
					if(this.enderFurnaces.containsKey(key))
					{
						//Bukkit.getLogger().info("Error test 2");
						event.setCancelled(true);
						AnniPlayer p = AnniPlayer.getPlayer(event.getPlayer().getUniqueId());
						if(p != null)
						{
//							Bukkit.getLogger().info("Error test 3");
//							if(p.getFurnace() != null)
//							{
//								Bukkit.getLogger().info("Error test 4");
								p.openFurnace();
//							}
//							else
//								Bukkit.getLogger().warning("[Annihilation] Someones enderfurnace was null!");
						}
					}
				}
			}
		}
	}