org.bukkit.event.block.Action Java Examples

The following examples show how to use org.bukkit.event.block.Action. 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: SignSelector.java    From CloudNet with 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 #2
Source File: ItemListener.java    From HubBasics with GNU Lesser General Public License v3.0 6 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 = 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 #3
Source File: Scorpio.java    From AnnihilationPro with 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 #4
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 #5
Source File: ProtectionsTests.java    From Civs with 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 #6
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 #7
Source File: NoCauldronWash.java    From civcraft with 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 File: FlagLeaveItem.java    From HeavySpleef with 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 #9
Source File: ToolMenuEvents.java    From uSkyBlock with 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 #10
Source File: ArmorListener.java    From AdditionsAPI with 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 #11
Source File: SignButtons.java    From VoxelGamesLibv2 with 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 #12
Source File: PlayerInteract.java    From StaffPlus with 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 #13
Source File: CustomItemListener.java    From NBTEditor with 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 #14
Source File: ServerListener.java    From ZombieEscape with 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 #15
Source File: TrackerListener.java    From BedWars with GNU Lesser General Public License v3.0 6 votes vote down vote up
@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 #16
Source File: SpecialItemKit.java    From AnnihilationPro with 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 #17
Source File: SignListener.java    From SkyWarsReloaded with 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 #18
Source File: JumpPads.java    From HubBasics with 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 #19
Source File: SignListener.java    From ChestCommands with 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 #20
Source File: IslandGuard.java    From askyblock with 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 #21
Source File: LauncherGizmo.java    From ProjectAres with GNU Affero General Public License v3.0 6 votes vote down vote up
@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 #22
Source File: QAListener.java    From QualityArmory with 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 #23
Source File: SignEvents.java    From uSkyBlock with 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 #24
Source File: PlayerListener.java    From civcraft with 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 #25
Source File: BrewingTaskType.java    From Quests with MIT License 5 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onBlockPlace(PlayerInteractEvent event) {
    if (event.getAction() == Action.RIGHT_CLICK_BLOCK) {
        if (event.getClickedBlock().getType() == Material.BREWING_STAND) {
            brewingStands.put(event.getClickedBlock().getLocation(), event.getPlayer().getUniqueId());
        }
    }
}
 
Example #26
Source File: DuctListener.java    From Transport-Pipes with MIT License 5 votes vote down vote up
Interaction(Player p, EquipmentSlot hand, ItemStack item, Block clickedBlock, BlockFace blockFace, Action action) {
    this.p = p;
    this.hand = hand;
    this.item = item;
    this.clickedBlock = clickedBlock;
    this.blockFace = blockFace;
    this.action = action;
}
 
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: TutorialListener.java    From ServerTutorial with MIT License 5 votes vote down vote up
@EventHandler
public void onPlayerInteract(PlayerInteractEvent event) {
    Player player = event.getPlayer();
    String name = player.getName();
    if (event.getAction() != Action.PHYSICAL) {
        if (TutorialManager.getManager().isInTutorial(name) && TutorialManager.getManager().getCurrentTutorial
                (name).getViewType() != ViewType.TIME) {
            if (TutorialManager.getManager().getCurrentTutorial(name).getTotalViews() == TutorialManager
                    .getManager().getCurrentView(name)) {
                plugin.getEndTutorial().endTutorial(player);
            } else {
                plugin.incrementCurrentView(name);
                TutorialUtils.getTutorialUtils().messageUtils(player);
                Caching.getCaching().setTeleport(player, true);
                player.teleport(TutorialManager.getManager().getTutorialView(name).getLocation());
            }
        }
    }
    if ((event.getAction() == Action.RIGHT_CLICK_BLOCK || event.getAction() == Action.LEFT_CLICK_BLOCK) &&
            !TutorialManager.getManager().isInTutorial(name)) {
        Block block = event.getClickedBlock();
        if (block.getType() == Material.SIGN || block.getType() == Material.WALL_SIGN) {
            Sign sign = (Sign) block.getState();
            String match = ChatColor.stripColor(TutorialUtils.color(TutorialManager.getManager().getConfigs()
                    .signSetting()));
            if (sign.getLine(0).equalsIgnoreCase(match) && sign.getLine(1) != null) {
                plugin.startTutorial(sign.getLine(1), player);
            }
        }
    }
}
 
Example #29
Source File: IslandGuard1_8.java    From askyblock with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Handle V1.8 blocks that need special treatment
 * Tilling of coarse dirt into dirt
 * Usually prevented because it could lead to an endless supply of dirt with gravel
 *
 * @param e - event
 */
@SuppressWarnings("deprecation")
@EventHandler(priority = EventPriority.LOW, ignoreCancelled=true)
public void onPlayerInteract(final PlayerInteractEvent e) {
    if (DEBUG) {
        plugin.getLogger().info("1.8 " + e.getEventName());
    }
    if (!e.getAction().equals(Action.RIGHT_CLICK_BLOCK)) {
        return;
    }
    if (!IslandGuard.inWorld(e.getPlayer())) {
        return;
    }
    if (e.getPlayer().isOp()) {
        return;
    }
    // This permission bypasses protection
    if (VaultHelper.checkPerm(e.getPlayer(), Settings.PERMPREFIX + "mod.bypassprotect")
            || VaultHelper.checkPerm(e.getPlayer(), Settings.PERMPREFIX + "craft.dirt")) {
        return;
    }
    // Prevents tilling of coarse dirt into dirt
    ItemStack inHand = e.getPlayer().getItemInHand();
    if (inHand.getType() == Material.WOOD_HOE || inHand.getType() == Material.IRON_HOE || inHand.getType() == Material.GOLD_HOE
            || inHand.getType() == Material.DIAMOND_HOE || inHand.getType() == Material.STONE_HOE) {
        // plugin.getLogger().info("1.8 " + "DEBUG: hoe in hand");
        Block block = e.getClickedBlock();
        // plugin.getLogger().info("1.8 " + "DEBUG: block is " + block.getType() +
        // ":" + block.getData());
        // Check if coarse dirt
        if (block.getType() == Material.DIRT && block.getData() == (byte) 1) {
            // plugin.getLogger().info("1.8 " + "DEBUG: hitting coarse dirt!");
            e.setCancelled(true);
        }
    }
}
 
Example #30
Source File: Gizmos.java    From ProjectAres with GNU Affero General Public License v3.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST)
public void openMenu(final PlayerInteractEvent event) {
    if(event.getAction() == Action.PHYSICAL) return;

    Player player = event.getPlayer();
    if(player.getItemInHand().getType() == Material.GHAST_TEAR) {
        GizmoUtils.openMenu(event.getPlayer());
        purchasingMap.put(event.getPlayer(), null);
    }
}