Java Code Examples for org.bukkit.event.player.PlayerInteractEvent

The following examples show how to use org.bukkit.event.player.PlayerInteractEvent. 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 onInteract(PlayerInteractEvent ev) {
  if (ev.getAction().equals(Action.LEFT_CLICK_AIR)
      || ev.getAction().equals(Action.LEFT_CLICK_BLOCK)) {
    return;
  }

  Player player = ev.getPlayer();
  Game game = BedwarsRel.getInstance().getGameManager().getGameOfPlayer(player);

  if (game == null) {
    return;
  }

  if (game.getState() != GameState.RUNNING) {
    return;
  }

  RescuePlatform platform = new RescuePlatform();
  if (!ev.getMaterial().equals(platform.getItemMaterial())) {
    return;
  }

  platform.create(player, game);
}
 
Example 2
Source Project: NBTEditor   Source File: EntityRemoverTool.java    License: GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onRightClick(PlayerInteractEvent event, PlayerDetails details) {
	Player player = event.getPlayer();
	if (player.isSneaking()) {
		Location location = event.getPlayer().getLocation();
		int i = 0;
		for (Entity entity : location.getWorld().getNearbyEntities(location, _radius, _radius, _radius)) {
			if (entity.getType() != EntityType.PLAYER) {
				entity.remove();
				i++;
			}
		}
		if (i == 1) {
			player.sendMessage(ChatColor.GREEN + "Removed " + i + " entity.");
		} else if (i != 0) {
			player.sendMessage(ChatColor.GREEN + "Removed " + i + " entities.");
		} else {
			player.sendMessage(ChatColor.YELLOW + "No entities on a " + _radius + " block radius.");
		}
	}
}
 
Example 3
Source Project: PGM   Source File: RegionMatchModule.java    License: GNU Affero General Public License v3.0 6 votes vote down vote up
private void handleUse(Event event, BlockState blockState, MatchPlayer player) {
  if (!player.canInteract()) return;

  PlayerBlockQuery query = new PlayerBlockQuery(event, player, blockState);

  for (RegionFilterApplication rfa : this.rfaContext.get(RFAScope.USE)) {
    if (rfa.region.contains(blockState)) {
      if (processQuery(rfa, query)) {
        if (query.getEvent() instanceof PlayerInteractEvent
            && ((PlayerInteractEvent) query.getEvent()).isCancelled()) {
          PlayerInteractEvent pie = (PlayerInteractEvent) query.getEvent();
          pie.setCancelled(false);
          pie.setUseItemInHand(Event.Result.ALLOW);
          pie.setUseInteractedBlock(Event.Result.DENY);

          if (rfa.message != null) {
            player.sendWarning(rfa.message);
          }
        }
        if (this.useRegionPriority || rfa.useRegionPriority) {
          break;
        }
      }
    }
  }
}
 
Example 4
Source Project: PGM   Source File: AntiGriefListener.java    License: GNU Affero General Public License v3.0 6 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST)
public void checkDefuse(final PlayerInteractEvent event) {
  ItemStack hand = event.getPlayer().getItemInHand();
  if (hand == null || hand.getType() != DEFUSE_ITEM) return;

  MatchPlayer clicker = this.mm.getPlayer(event.getPlayer());
  if (clicker != null
      && clicker.isObserving()
      && clicker.getBukkit().hasPermission(Permissions.DEFUSE)) {
    if (event.getAction() == Action.RIGHT_CLICK_AIR) {
      this.obsTntDefuse(clicker, event.getPlayer().getLocation());
    } else if (event.getAction() == Action.RIGHT_CLICK_BLOCK) {
      this.obsTntDefuse(clicker, event.getClickedBlock().getLocation());
    }
  }
}
 
Example 5
Source Project: PGM   Source File: AntiGriefListener.java    License: GNU Affero General Public License v3.0 6 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR)
public void cloneCraftingWindow(final PlayerInteractEvent event) {
  if (!event.isCancelled()
      && event.getAction() == Action.RIGHT_CLICK_BLOCK
      && event.getPlayer().getOpenInventory().getType()
          == InventoryType.CRAFTING /* nothing open */) {
    Block block = event.getClickedBlock();
    if (block != null
        && block.getType() == Material.WORKBENCH
        && !event.getPlayer().isSneaking()) {
      // create the window ourself
      event.setCancelled(true);
      event.getPlayer().openWorkbench(null, true); // doesn't check reachable
    }
  }
}
 
Example 6
Source Project: HeavySpleef   Source File: FlagQueueLobby.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.isQueued(player)) {
		return;
	}
	
	MetadatableItemStack inHand = new MetadatableItemStack(player.getBukkitPlayer().getItemInHand());
	if (!inHand.hasItemMeta() || !inHand.getItemMeta().hasLore() || !inHand.hasMetadata(LEAVE_ITEM_KEY)) {
		return;
	}
	
	//Leave the queue mode
	game.unqueue(player);
	player.sendMessage(getI18N().getVarString(Messages.Command.REMOVED_FROM_QUEUE)
			.setVariable("game", game.getName())
			.toString());
}
 
Example 7
Source Project: MineTinker   Source File: Power.java    License: GNU General Public License v3.0 6 votes vote down vote up
private void powerCreateFarmland(Player player, ItemStack tool, Block block) {
	if (block.getType().equals(Material.GRASS_BLOCK) || block.getType().equals(Material.DIRT)) {
		if (block.getWorld().getBlockAt(block.getLocation().add(0, 1, 0)).getType().equals(Material.AIR)) {
			if (tool.getItemMeta() instanceof Damageable) {
				Damageable damageable = (Damageable) tool.getItemMeta();
				damageable.setDamage(damageable.getDamage() + 1);
				tool.setItemMeta((ItemMeta) damageable);
			}

			PlayerInteractEvent event = new PlayerInteractEvent(player, Action.RIGHT_CLICK_BLOCK, tool, block, BlockFace.UP);
			Bukkit.getPluginManager().callEvent(event);

			block.setType(Material.FARMLAND); // Event only does Plugin event (no vanilla conversion to Farmland and
			// Tool-Damage)
		}
	}
}
 
Example 8
Source Project: ViaBackwards   Source File: LecternInteractListener.java    License: MIT License 6 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onLecternInteract(PlayerInteractEvent event) {
    Player player = event.getPlayer();
    if (!isOnPipe(player)) return;

    Block block = event.getClickedBlock();
    if (block == null || block.getType() != Material.LECTERN) return;

    Lectern lectern = (Lectern) block.getState();
    ItemStack book = lectern.getInventory().getItem(0);
    if (book == null) return;

    BookMeta meta = (BookMeta) book.getItemMeta();

    // Open a book with the text of the lectern's writable book
    ItemStack newBook = new ItemStack(Material.WRITTEN_BOOK);
    BookMeta newBookMeta = (BookMeta) newBook.getItemMeta();
    newBookMeta.setPages(meta.getPages());
    newBookMeta.setAuthor("an upsidedown person");
    newBookMeta.setTitle("buk");
    newBook.setItemMeta(newBookMeta);
    player.openBook(newBook);

    event.setCancelled(true);
}
 
Example 9
Source Project: CardinalPGM   Source File: Tutorial.java    License: MIT License 6 votes vote down vote up
@EventHandler
public void onPlayerRightClick(PlayerInteractEvent event) {
    boolean condition = Teams.getTeamByPlayer(event.getPlayer()).isPresent()
            && Teams.getTeamByPlayer(event.getPlayer()).get().isObserver()
            && event.getPlayer().getItemInHand() != null
            && event.getPlayer().getItemInHand().getType().equals(Material.EMERALD);

    if (!this.displayHandlerMap.containsKey(event.getPlayer())) {
        this.displayHandlerMap.put(event.getPlayer(), new DisplayHandler(event.getPlayer(), this));
    }

    if ((event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() == Action.RIGHT_CLICK_BLOCK) && condition) {
        this.displayHandlerMap.get(event.getPlayer()).displayNext();
    }
    if ((event.getAction() == Action.LEFT_CLICK_AIR || event.getAction() == Action.LEFT_CLICK_BLOCK) && condition) {
        this.displayHandlerMap.get(event.getPlayer()).displayPrev();
    }
}
 
Example 10
Source Project: Slimefun4   Source File: TeleporterListener.java    License: GNU General Public License v3.0 6 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onPressurePlateEnter(PlayerInteractEvent e) {
    if (e.getAction() != Action.PHYSICAL || e.getClickedBlock() == null) {
        return;
    }

    String id = BlockStorage.checkID(e.getClickedBlock());
    if (id == null) {
        return;
    }

    if (isTeleporterPad(id, e.getClickedBlock(), e.getPlayer().getUniqueId())) {
        SlimefunItem teleporter = BlockStorage.check(e.getClickedBlock().getRelative(BlockFace.DOWN));

        if (teleporter instanceof Teleporter && checkForPylons(e.getClickedBlock().getRelative(BlockFace.DOWN))) {
            Block block = e.getClickedBlock().getRelative(BlockFace.DOWN);
            UUID owner = UUID.fromString(BlockStorage.getLocationInfo(block.getLocation(), "owner"));
            SlimefunPlugin.getGPSNetwork().getTeleportationManager().openTeleporterGUI(e.getPlayer(), owner, block, SlimefunPlugin.getGPSNetwork().getNetworkComplexity(owner));
        }
    }
    else if (id.equals(SlimefunItems.ELEVATOR_PLATE.getItemId())) {
        ((ElevatorPlate) SlimefunItems.ELEVATOR_PLATE.getItem()).open(e.getPlayer(), e.getClickedBlock());
    }
}
 
Example 11
Source Project: ProjectAres   Source File: GunGizmo.java    License: GNU Affero General Public License v3.0 6 votes vote down vote up
@EventHandler
public void playerInteract(final PlayerInteractEvent event) {
    if(event.getAction() == Action.PHYSICAL
            || !(Gizmos.gizmoMap.get(event.getPlayer()) instanceof GunGizmo)
            || event.getItem() == null || event.getItem().getType() != this.getIcon()) return;

    final Player player = event.getPlayer();
    RaindropUtil.giveRaindrops(Users.playerId(player), -1, new RaindropResult() {
        @Override
        public void run() {
            if(success) {
                Vector velocity = player.getLocation().getDirection().multiply(1.75D);

                Item item = player.getWorld().dropItem(event.getPlayer().getEyeLocation(), new ItemStack(Material.GHAST_TEAR));
                item.setVelocity(velocity);
                item.setTicksLived((5 * 60 * 20) - (5 * 20)); // 5 minutes - 5 seconds
                items.put(item, player.getUniqueId());
            } else {
                player.sendMessage(ChatColor.RED + LobbyTranslations.get().t("gizmo.gun.empty", player));
                player.playSound(player.getLocation(), Sound.UI_BUTTON_CLICK, 1f, 1f);
            }
        }
    }, null, false, true, false);
}
 
Example 12
@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 13
@EventHandler(priority = EventPriority.LOW)
public void onInteract(PlayerInteractEvent event) {
    if(!event.hasItem()) return;

    final ClickType click;
    switch(event.getAction()) {
        case LEFT_CLICK_AIR:
        case LEFT_CLICK_BLOCK:
            click = ClickType.LEFT;
            break;

        case RIGHT_CLICK_AIR:
        case RIGHT_CLICK_BLOCK:
            click = ClickType.RIGHT;
            break;

        default:
            return;
    }

    if(onButtonClick(event.getItem(), event.getActor(), click, event)) {
        event.setUseItemInHand(Event.Result.DENY);
        event.setUseInteractedBlock(Event.Result.DENY);
    }
}
 
Example 14
Source Project: uSkyBlock   Source File: SpawnEvents.java    License: GNU General Public License v3.0 6 votes vote down vote up
@EventHandler
public void onSpawnEggEvent(PlayerInteractEvent event) {
    Player player = event != null ? event.getPlayer() : null;
    if (player == null || event.isCancelled() || !plugin.getWorldManager().isSkyWorld(player.getWorld())) {
        return; // Bail out, we don't care
    }
    if (player.hasPermission("usb.mod.bypassprotection") || player.isOp()) {
        return;
    }
    ItemStack item = event.getItem();
    if (RIGHT_CLICKS.contains(event.getAction()) && item != null && isSpawnEgg(item)) {
        if (!plugin.playerIsOnIsland(player)) {
            event.setCancelled(true);
            plugin.notifyPlayer(player, tr("\u00a7eYou can only use spawn-eggs on your own island."));
            return;
        }
        SpawnEgg spawnEgg = (SpawnEgg) item.getData();
        checkLimits(event, spawnEgg.getSpawnedType(), player.getLocation());
        if (event.isCancelled()) {
            plugin.notifyPlayer(player, tr("\u00a7cYou have reached your spawn-limit for your island."));
            event.setUseItemInHand(Event.Result.DENY);
            event.setUseInteractedBlock(Event.Result.DENY);
        }
    }
}
 
Example 15
Source Project: VoxelGamesLibv2   Source File: SkullPlaceHolders.java    License: MIT License 6 votes vote down vote up
@EventHandler
public void handleInteract(@Nonnull PlayerInteractEvent event) {
    if (event.getAction() == org.bukkit.event.block.Action.RIGHT_CLICK_BLOCK && event.getClickedBlock() != null) {
        if (event.getClickedBlock().getState() instanceof Skull) {
            Skull skull = (Skull) event.getClickedBlock().getState();
            if (skull.hasMetadata("UpdateCooldown")) {
                long cooldown = skull.getMetadata("UpdateCooldown").get(0).asLong();
                if (cooldown > System.currentTimeMillis() - 1 * 1000) {
                    return;
                }
            }
            skull.update();
            skull.setMetadata("UpdateCooldown", new FixedMetadataValue(voxelGamesLib, System.currentTimeMillis()));
        }
    }
}
 
Example 16
Source Project: uSkyBlock   Source File: SignEvents.java    License: GNU General Public License v3.0 6 votes vote down vote up
@EventHandler(priority = EventPriority.HIGH)
public void onPlayerHitSign(PlayerInteractEvent e) {
    if (e.isCancelled()
            || e.getPlayer() == null
            || (e.getAction() != Action.RIGHT_CLICK_BLOCK && e.getAction() != Action.LEFT_CLICK_BLOCK)
            || e.getClickedBlock() == null
            || e.getClickedBlock().getType() != SkyBlockMenu.WALL_SIGN_MATERIAL
            || !(e.getClickedBlock().getState() instanceof Sign)
            || !e.getPlayer().hasPermission("usb.island.signs.use")
            || !plugin.getWorldManager().isSkyAssociatedWorld(e.getPlayer().getWorld())
            || !(plugin.playerIsOnOwnIsland(e.getPlayer()))
            ) {
        return;
    }
    if (e.getAction() == Action.LEFT_CLICK_BLOCK) {
        logic.updateSign(e.getClickedBlock().getLocation());
    } else {
        logic.signClicked(e.getPlayer(), e.getClickedBlock().getLocation());
    }
}
 
Example 17
public static boolean anchorCharge(PlayerInteractEvent event, Game game, ItemStack stack) {
    boolean anchorFilled = false;
    RespawnAnchor anchor = (RespawnAnchor) event.getClickedBlock().getBlockData();
    int charges = anchor.getCharges();
    charges++;
    if (charges <= anchor.getMaximumCharges()) {
        anchorFilled = true;
        anchor.setCharges(charges);
        event.getClickedBlock().setBlockData(anchor);
        stack.setAmount(stack.getAmount() - 1);
        Sounds.playSound(event.getClickedBlock().getLocation(), Main.getConfigurator().config.getString("target-block.respawn-anchor.sound.charge"), Sounds.BLOCK_RESPAWN_ANCHOR_CHARGE, 1, 1);
        game.updateScoreboard();
    }
    return anchorFilled;
}
 
Example 18
Source Project: DungeonsXL   Source File: DSignListener.java    License: GNU General Public License v3.0 5 votes vote down vote up
@EventHandler
public void onPlayerInteract(PlayerInteractEvent event) {
    Player player = event.getPlayer();
    if (DPlayerListener.isCitizensNPC(player)) {
        return;
    }
    Block clickedBlock = event.getClickedBlock();
    if (clickedBlock == null) {
        return;
    }
    GamePlayer dPlayer = api.getPlayerCache().getGamePlayer(player);
    if (dPlayer == null) {
        return;
    }

    DGameWorld gameWorld = (DGameWorld) dPlayer.getGameWorld();
    if (gameWorld == null) {
        return;
    }

    InteractTrigger trigger = InteractTrigger.getByBlock(clickedBlock, gameWorld);
    if (trigger != null) {
        if (event.getAction() == Action.LEFT_CLICK_BLOCK || event.getAction() == Action.RIGHT_CLICK_BLOCK) {
            trigger.onTrigger(player);
        }
    }
}
 
Example 19
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 20
Source Project: HeavySpleef   Source File: FlagVote.java    License: GNU General Public License v3.0 5 votes vote down vote up
@SuppressWarnings("deprecation")
@EventHandler
public void onPlayerInteract(PlayerInteractEvent event) {
	SpleefPlayer player = heavySpleef.getSpleefPlayer(event.getPlayer());
	GameManager manager = heavySpleef.getGameManager();
	
	Game game = manager.getGame(player);
	if (game == null) {
		return;
	}
	
	if (!game.isFlagPresent(FlagVote.class)) {
		return;
	}
	
	DefaultConfig config = heavySpleef.getConfiguration(ConfigType.DEFAULT_CONFIG);
	FlagSection section = config.getFlagSection();
	MaterialData readyBlock = section.getReadyBlock();
	
	Block clickedBlock = event.getClickedBlock();
	if (clickedBlock == null || clickedBlock.getType() != readyBlock.getItemType() || clickedBlock.getData() != readyBlock.getData()) {
		return;
	}
	
	if (game.getGameState() != GameState.LOBBY) {
		player.sendMessage(i18n.getString(Messages.Command.FUNCTION_ONLY_IN_LOBBY));
		return;
	}
	
	FlagVote flag = game.getFlag(FlagVote.class);
	boolean success = flag.vote(player, game);
	player.sendMessage(i18n.getString(success ? Messages.Command.SUCCESSFULLY_VOTED : Messages.Command.ALREADY_VOTED));
}
 
Example 21
Source Project: GriefDefender   Source File: BlockEventTracker.java    License: MIT License 5 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR)
public void onPlayerInteractBlockSecondary(PlayerInteractEvent event) {
    if (event.getClickedBlock() == null) {
        return;
    }
    final GDClaimManager claimWorldManager = GriefDefenderPlugin.getInstance().dataStore.getClaimWorldManager(event.getClickedBlock().getWorld().getUID());
    final GDChunk gpChunk = claimWorldManager.getChunk(event.getClickedBlock().getChunk());
    GDCauseStackManager.getInstance().pushCause(event.getPlayer());
    gpChunk.addTrackedBlockPosition(event.getClickedBlock(), event.getPlayer().getUniqueId(), PlayerTracker.Type.NOTIFIER);
    // We must track the position above clicked to block actions like water flow properly.
    final Location aboveLocation = BlockUtil.getInstance().getBlockRelative(event.getClickedBlock().getLocation(), BlockFace.UP);
    gpChunk.addTrackedBlockPosition(aboveLocation.getBlock(), event.getPlayer().getUniqueId(), PlayerTracker.Type.NOTIFIER);
}
 
Example 22
Source Project: civcraft   Source File: TutorialBook.java    License: GNU General Public License v2.0 5 votes vote down vote up
public void onInteract(PlayerInteractEvent event) {
	
	event.setCancelled(true);
	if (!event.getAction().equals(Action.RIGHT_CLICK_AIR) &&
			!event.getAction().equals(Action.RIGHT_CLICK_BLOCK)) {
		return;
	}
	
	//CivTutorial.showCraftingHelp(event.getPlayer());
	CivTutorial.spawnGuiBook(event.getPlayer());

}
 
Example 23
Source Project: PGM   Source File: Spawning.java    License: GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public void onEvent(PlayerInteractEvent event) {
  super.onEvent(event);
  event.setCancelled(true);
  if (event.getAction() == Action.LEFT_CLICK_AIR
      || event.getAction() == Action.LEFT_CLICK_BLOCK) {
    requestSpawn();
  }
}
 
Example 24
Source Project: civcraft   Source File: Library.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Override
public void processSignAction(Player player, StructureSign sign, PlayerInteractEvent event) {
	try {
		add_enchantment_to_tool(player, sign, event);
	} catch (CivException e) {
		CivMessage.send(player, CivColor.Rose+e.getMessage());
	}	
}
 
Example 25
Source Project: ce   Source File: AssassinsBlade.java    License: GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public boolean effect(Event event, final Player player) {
	if(event instanceof PlayerInteractEvent) {
		if(!player.hasMetadata("ce.assassin"))
			if(player.isSneaking())
					  player.setMetadata("ce.assassin", new FixedMetadataValue(main, null));
					  player.addPotionEffect(new PotionEffect(PotionEffectType.INVISIBILITY, InvisibilityDuration, 0, true), true);
					  player.sendMessage(ChatColor.GRAY + "" + ChatColor.ITALIC + "You hide in the shadows.");
					  new BukkitRunnable() {
						  @Override
						  public void run() {
							  if(player.hasMetadata("ce.assassin")) {
								  player.removeMetadata("ce.assassin", main);
								  player.sendMessage(ChatColor.GRAY + "" + ChatColor.ITALIC + "You are no longer hidden!");
							  }
						  }
					  }.runTaskLater(main, InvisibilityDuration);
					  return true;
				  }
	if(event instanceof EntityDamageByEntityEvent) {
		EntityDamageByEntityEvent e = ((EntityDamageByEntityEvent) event);
		if(e.getDamager() == player && player.hasMetadata("ce.assassin")) {
			  e.setDamage(e.getDamage() * AmbushDmgMultiplier);
			  player.removeMetadata("ce.assassin", main);
			  player.removePotionEffect(PotionEffectType.INVISIBILITY);
			  EffectManager.playSound(e.getEntity().getLocation(), "BLOCK_PISTON_EXTEND", 0.4f, 0.1f);
			  player.addPotionEffect(new PotionEffect(PotionEffectType.WEAKNESS, WeaknessLength, WeaknessLevel, false), true);
			  player.sendMessage(ChatColor.GRAY + "" + ChatColor.ITALIC + "You are no longer hidden!");
	   }
	}
	 return false;
}
 
Example 26
@EventHandler(priority = EventPriority.HIGHEST)
public void onInteract(PlayerInteractEvent interact) {
  if (interact.getAction().equals(Action.LEFT_CLICK_AIR)
      || interact.getAction().equals(Action.LEFT_CLICK_BLOCK)) {
    return;
  }

  if (interact.getMaterial() == null) {
    return;
  }

  ProtectionWall wall = new ProtectionWall();
  if (interact.getMaterial() != wall.getItemMaterial()) {
    return;
  }

  Game game = BedwarsRel.getInstance().getGameManager().getGameOfPlayer(interact.getPlayer());
  if (game == null) {
    return;
  }

  if (game.getState() != GameState.RUNNING) {
    return;
  }

  if (game.isSpectator(interact.getPlayer())) {
    return;
  }

  wall.create(interact.getPlayer(), game);
  interact.setCancelled(true);
}
 
Example 27
Source Project: AnnihilationPro   Source File: KitLoading.java    License: MIT License 5 votes vote down vote up
@EventHandler(priority=EventPriority.HIGHEST)
public void openKitMenuCheck(PlayerInteractEvent event)
{
	if(event.getAction() == Action.RIGHT_CLICK_BLOCK || event.getAction() == Action.RIGHT_CLICK_AIR)
	{
		final Player player = event.getPlayer();
		if(KitUtils.itemHasName(player.getItemInHand(), CustomItem.KITMAP.getName()))
		{
			openKitMap(player);
			event.setCancelled(true);
		}
	}
}
 
Example 28
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
public void onPortalCreation(PlayerInteractEvent event) {
    Player player = event.getPlayer();
    if (DPlayerListener.isCitizensNPC(player)) {
        return;
    }
    DGlobalPlayer dPlayer = (DGlobalPlayer) plugin.getPlayerCache().get(player);
    if (!dPlayer.isCreatingPortal()) {
        return;
    }
    ItemStack item = event.getItem();
    Block block = event.getClickedBlock();
    if (item == null || !VanillaItem.WOODEN_SWORD.is(item) || block == null) {
        return;
    }

    for (GlobalProtection protection : plugin.getGlobalProtectionCache().getProtections(DPortal.class)) {
        DPortal dPortal = (DPortal) protection;
        if (dPortal.isActive() || dPortal != dPlayer.getPortal()) {
            continue;
        }

        if (dPortal.getBlock1() == null) {
            dPortal.setBlock1(event.getClickedBlock());
            dPlayer.sendMessage(DMessage.PLAYER_PORTAL_PROGRESS.getMessage());

        } else if (dPortal.getBlock2() == null) {
            dPortal.setBlock2(event.getClickedBlock());
            dPortal.setActive(true);
            dPortal.create(dPlayer);
        }
        event.setCancelled(true);
    }
}
 
Example 29
Source Project: civcraft   Source File: Blacksmith.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Override
public void processSignAction(Player player, StructureSign sign, PlayerInteractEvent event) throws CivException {
	int special_id = Integer.valueOf(sign.getAction());
	
	Date now = new Date();
	
	long diff = now.getTime() - lastUse.getTime();
	diff /= 1000;
	
	if (diff < Blacksmith.COOLDOWN) {
		throw new CivException("Blacksmith is on cooldown. Please wait another "+(Blacksmith.COOLDOWN - diff)+" seconds.");
	}
	
	lastUse = now;
	
	switch (special_id) {
	case 0:
		this.deposit_forge(player);
		break;
	case 1:
		double cost = CivSettings.getDoubleStructure("blacksmith.forge_cost");
		this.perform_forge(player, cost);
		break;
	case 2:
		this.depositSmelt(player, player.getItemInHand());
		break;
	case 3:
		this.withdrawSmelt(player);
		break;
	}
	
}
 
Example 30
Source Project: uSkyBlock   Source File: GriefEvents.java    License: GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR)
public void onTrampling(PlayerInteractEvent event) {
    if (!tramplingEnabled || !plugin.getWorldManager().isSkyAssociatedWorld(event.getPlayer().getWorld())) {
        return;
    }
    if (event.getAction() == Action.PHYSICAL
            && !isValidTarget(event.getPlayer())
            && event.hasBlock()
            && event.getClickedBlock().getType() == Material.FARMLAND
            ) {
        event.setCancelled(true);
    }
}