Java Code Examples for org.bukkit.event.EventPriority#HIGH

The following examples show how to use org.bukkit.event.EventPriority#HIGH . 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: ArrowBlockerListener.java    From BedWars with GNU Lesser General Public License v3.0 6 votes vote down vote up
@EventHandler(priority = EventPriority.HIGH)
public void onDamage(EntityDamageEvent event) {
    Entity entity = event.getEntity();
    if (!(entity instanceof Player)) {
        return;
    }

    Player player = ((Player) entity).getPlayer();

    if (!Main.isPlayerInGame(player)) {
        return;
    }

    GamePlayer gPlayer = Main.getPlayerGameProfile(player);
    Game game = gPlayer.getGame();

    if (gPlayer.isSpectator) {
        return;
    }

    ArrowBlocker arrowBlocker = (ArrowBlocker) game.getFirstActivedSpecialItemOfPlayer(player, ArrowBlocker.class);
    if (arrowBlocker != null && event.getCause() == EntityDamageEvent.DamageCause.PROJECTILE) {
        event.setCancelled(true);
    }
}
 
Example 2
Source File: LWCBlockListener.java    From Modern-LWC with MIT License 6 votes vote down vote up
@EventHandler(priority = EventPriority.HIGH)
public void onBlockExplode(BlockExplodeEvent event) {
    if (!LWC.ENABLED || event.isCancelled()) {
        return;
    }
    LWC lwc = plugin.getLWC();
    for (Block block : event.blockList()) {
        Protection protection = plugin.getLWC().findProtection(block.getLocation());
        if (protection != null) {
            boolean ignoreExplosions = Boolean
                    .parseBoolean(lwc.resolveProtectionConfiguration(protection.getBlock(), "ignoreExplosions"));
            if (!(ignoreExplosions || protection.hasFlag(Flag.Type.ALLOWEXPLOSIONS))) {
                event.setCancelled(true);
            }
        }
    }
}
 
Example 3
Source File: PlayerListener.java    From BedWars with GNU Lesser General Public License v3.0 6 votes vote down vote up
@EventHandler(priority = EventPriority.HIGH)
public void onHunger(FoodLevelChangeEvent event) {
    if (!(event.getEntity() instanceof Player) || event.isCancelled()) {
        return;
    }

    Player player = (Player) event.getEntity();
    if (Main.isPlayerInGame(player)) {
        GamePlayer gPlayer = Main.getPlayerGameProfile(player);
        Game game = gPlayer.getGame();
        if (game.getStatus() == GameStatus.WAITING || gPlayer.isSpectator) {
            event.setCancelled(true);
        }

        if (game.getStatus() == GameStatus.RUNNING && Main.getConfigurator().config.getBoolean("disable-hunger")) {
            event.setCancelled(true);
        }
    }
}
 
Example 4
Source File: WindowManager.java    From ProjectAres with GNU Affero General Public License v3.0 6 votes vote down vote up
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onClick(InventoryClickEvent event) {
    final View view = views.get(event.getActor());
    if(view != null) {
        if(view.window.equals(event.getView())) {
            if(view.listener.windowClicked(event.getView(),
                                           InventoryUtils.clickedInventory(event),
                                           event.getClick(),
                                           event.getSlotType(),
                                           event.getSlot(),
                                           event.getCurrentItem())) {
                event.setCancelled(true);
            }
        } else {
            // If player clicked in a window other than the one we are tracking for them,
            // it must have already been closed somehow.
            handleCloseWindow(event.getActor());
        }
    }
}
 
Example 5
Source File: VanishManagerImpl.java    From PGM with GNU Affero General Public License v3.0 6 votes vote down vote up
@EventHandler(priority = EventPriority.HIGH)
public void onJoin(PlayerJoinEvent event) {
  MatchPlayer player = matchManager.getPlayer(event.getPlayer());
  if (isVanished(player.getId())) { // Player is already vanished
    player.setVanished(true);
  } else if (player
      .getBukkit()
      .hasPermission(Permissions.VANISH)) { // Player is not vanished, but has permission to

    // Automatic vanish if player logs in via a "vanish" subdomain
    String domain = loginSubdomains.getIfPresent(player.getId());
    if (domain != null) {
      loginSubdomains.invalidate(player.getId());
      tempVanish.add(player.getId());
      setVanished(player, true, true);
    }
  }
}
 
Example 6
Source File: EnhancedItemListener.java    From EnchantmentsEnhance with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Prevents enhanced item from glitching.
 *
 * @param inventoryClickEvent
 */
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGH)
public void onItemGlitch(InventoryClickEvent inventoryClickEvent) {
    ItemStack currentItem = inventoryClickEvent.getCurrentItem();
    ItemStack cursor = inventoryClickEvent.getCursor();
    try {
        if (inventoryClickEvent.getClickedInventory() != null && inventoryClickEvent.getClickedInventory().firstEmpty() == -1) {
            if (currentItem != null && currentItem.hasItemMeta() && (currentItem.getItemMeta().hasLore())) {
                if (currentItem.getItemMeta().getLore().contains(Util.UNIQUEID + Util.toColor(SettingsManager.lang.getString("lore.untradeableLore")))) {
                    inventoryClickEvent.setCancelled(true);
                    Util.sendMessage(SettingsManager.lang.getString("messages.noDrop"), inventoryClickEvent.getWhoClicked());
                }
            }
            if (cursor != null && cursor.hasItemMeta() && (cursor.getItemMeta().hasLore())) {
                if (cursor.getItemMeta().getLore().contains(Util.UNIQUEID + Util.toColor(SettingsManager.lang.getString("lore.untradeableLore")))) {
                    inventoryClickEvent.setCancelled(true);
                    Util.sendMessage(SettingsManager.lang.getString("messages.noDrop"), inventoryClickEvent.getWhoClicked());
                }
            }
        }
    } catch (NoSuchMethodError ex) {
        // craftbukkit
    }
}
 
Example 7
Source File: GUIListener.java    From EnchantmentsEnhance with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Prevents item glitched into menu.
 *
 * @param e
 */
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGH)
public void onInventoryClick(InventoryClickEvent e) {
    if ((e.getInventory().getType() != InventoryType.CRAFTING) && (e.getInventory().getType() != InventoryType.PLAYER)) {
        if ((e.getClick().equals(ClickType.NUMBER_KEY)) && (e.getWhoClicked().getInventory().getItem(e.getHotbarButton()) != null)) {
            Player player = (Player) e.getWhoClicked();
            String playerName = player.getName();
            GUIAbstract gui = GUIManager.getMap().get(playerName);
            if (gui != null && gui.getInventory().equals(e.getInventory())) {
                e.setCancelled(true);
            }
        }
    }
}
 
Example 8
Source File: LifeskillingListener.java    From EnchantmentsEnhance with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Fix a bukkit bug where shift click doesn't register.
 *
 * @param e
 * @return
 */
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGH)
public void onSmelting2(InventoryClickEvent e) {
    Inventory clickedInventory = null;
    Player player = (Player) e.getWhoClicked();
    if (e.getSlot() < 0) {
        clickedInventory = null;
    } else if (e.getView().getTopInventory() != null && e.getSlot() < e
            .getView().getTopInventory().getSize()) {
        clickedInventory = e.getView().getTopInventory();
    } else {
        clickedInventory = e.getView().getBottomInventory();
    }
    if (clickedInventory == null) {
        return;
    }
    if (!clickedInventory.getType().equals(InventoryType.FURNACE)) {
        return;
    }
    if (e.getCurrentItem() == null || e.getCurrentItem().getType() == Material.AIR) {
        return;
    }
    FurnaceInventory fi = (FurnaceInventory) clickedInventory;
    boolean click = e.getClick().isShiftClick() || e.getClick()
            .isLeftClick() && e.getRawSlot() == 2;
    boolean item = fi.getResult() != null;

    if (click && item && !fi.getResult().getType().isFuel() && !fi.getResult().getType().isBurnable() && !Util.invFull(player)) {
        for (int i = 0; i < fi.getResult().getAmount(); i++) {
            if (DropManager.smeltingChance > random.nextDouble()) {
                DropManager.randomDrop(player, DropManager.smeltingLootTable);
            }
        }
    }
}
 
Example 9
Source File: EventRuleMatchModule.java    From ProjectAres with GNU Affero General Public License v3.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void checkUse(final PlayerInteractEvent event) {
    if(event.getAction() == Action.RIGHT_CLICK_BLOCK) {
        MatchPlayer player = this.match.getParticipant(event.getPlayer());
        if(player == null) return;

        Block block = event.getClickedBlock();
        if(block == null) return;

        this.handleUse(event, block.getState(), player);
    }
}
 
Example 10
Source File: EventRuleMatchModule.java    From ProjectAres with GNU Affero General Public License v3.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void checkItemFrameItemRemove(EntityDamageByEntityEvent event) {
    // This event is fired when popping an item out of an item frame, without breaking the frame itself
    if(event.getEntity() instanceof ItemFrame && ((ItemFrame) event.getEntity()).getItem() != null) {
        this.handleHangingBreak(event, (Hanging) event.getEntity(), event.getDamager());
    }
}
 
Example 11
Source File: BlitzMatchModule.java    From ProjectAres with GNU Affero General Public License v3.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void handleDeath(final MatchPlayerDeathEvent event) {
    MatchPlayer victim = event.getVictim();
    if(victim.getParty() instanceof Competitor) {
        int lives = this.lifeManager.addLives(event.getVictim().getPlayerId(), -1);
        if(lives <= 0) {
            this.handleElimination(victim);
        }
    }
}
 
Example 12
Source File: LifeskillingListener.java    From EnchantmentsEnhance with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Killing mobs gives enhancement stone.
 *
 * @param e
 */
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGH)
public void onKilling(EntityDeathEvent e) {
    // If the killed entity is a monster
    if (e.getEntity() instanceof Monster) {
        if (e.getEntity().getKiller() instanceof Player) {
            Player player = e.getEntity().getKiller();
            if (DropManager.killingChance > random.nextDouble()) {
                DropManager.randomDrop(player, DropManager.killingLootTable);
            }
        }
    }
}
 
Example 13
Source File: LifeskillingListener.java    From EnchantmentsEnhance with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Mining gives enhancement stone.
 *
 * @param e
 */
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGH)
public void onMining(BlockBreakEvent e) {
    Player player = e.getPlayer();
    if (player.getGameMode() != GameMode.SURVIVAL) {
        return;
    }
    if (DropManager.getMining().contains(e.getBlock().getType()))
        if (DropManager.miningChance > random.nextDouble()) {
            DropManager.randomDrop(player, DropManager.miningLootTable);
        }
}
 
Example 14
Source File: WorldBorderMatchModule.java    From ProjectAres with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Prevent teleporting outside the border
 */
@EventHandler(priority = EventPriority.HIGH)
public void onPlayerTeleport(final PlayerTeleportEvent event) {
    if(event.getCause() == PlayerTeleportEvent.TeleportCause.PLUGIN) {
        if(WorldBorderUtils.isInsideBorder(event.getFrom()) &&
           !WorldBorderUtils.isInsideBorder(event.getTo())) {
            event.setCancelled(true);
        }
    }
}
 
Example 15
Source File: RegionMatchModule.java    From PGM with GNU Affero General Public License v3.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void checkUse(final PlayerInteractEvent event) {
  if (event.getAction() == Action.RIGHT_CLICK_BLOCK) {
    MatchPlayer player = this.match.getParticipant(event.getPlayer());
    if (player == null) return;

    Block block = event.getClickedBlock();
    if (block == null) return;

    this.handleUse(event, block.getState(), player);
  }
}
 
Example 16
Source File: PlayerDeathListener.java    From UhcCore with GNU General Public License v3.0 4 votes vote down vote up
@EventHandler(priority = EventPriority.HIGH)
public void onPlayerDeath(PlayerDeathEvent event){
	Player player = event.getEntity();
	GameManager gm = GameManager.getGameManager();
	PlayersManager pm = gm.getPlayersManager();
	MainConfiguration cfg = gm.getConfiguration();
	UhcPlayer uhcPlayer = pm.getUhcPlayer(player);

	if (uhcPlayer.getState() != PlayerState.PLAYING){
		Bukkit.getLogger().warning("[UhcCore] " + player.getName() + " died while already in 'DEAD' mode!");
		player.kickPlayer("Don't cheat!");
		return;
	}

	pm.setLastDeathTime();

	// kill event
	Player killer = player.getKiller();
	if(killer != null){
		UhcPlayer uhcKiller = pm.getUhcPlayer(killer);

		uhcKiller.kills++;

		// Call Bukkit event
		UhcPlayerKillEvent killEvent = new UhcPlayerKillEvent(uhcPlayer, uhcKiller);
		Bukkit.getServer().getPluginManager().callEvent(killEvent);

		if(cfg.getEnableKillEvent()){
			double reward = cfg.getRewardKillEvent();
			List<String> killCommands = cfg.getKillCommands();
			if (reward > 0) {
				VaultManager.addMoney(killer, reward);
				if (!Lang.EVENT_KILL_REWARD.isEmpty()) {
					killer.sendMessage(Lang.EVENT_KILL_REWARD.replace("%money%", "" + reward));
				}
			}
			// If the list is empty, this will never execute
			killCommands.forEach(cmd -> {
				try {
					Bukkit.dispatchCommand(Bukkit.getConsoleSender(), cmd.replace("%name%", uhcKiller.getRealName()));
				} catch (CommandException exception){
					Bukkit.getLogger().warning("[UhcCore] Failed to execute kill reward command: " + cmd);
					exception.printStackTrace();
				}
			});
		}
	}

	// Store drops in case player gets re-spawned.
	uhcPlayer.getStoredItems().clear();
	uhcPlayer.getStoredItems().addAll(event.getDrops());

	// eliminations
	ScenarioManager sm = gm.getScenarioManager();
	if (!sm.isActivated(Scenario.SILENTNIGHT) || !((SilentNightListener) sm.getScenarioListener(Scenario.SILENTNIGHT)).isNightMode()) {
		gm.broadcastInfoMessage(Lang.PLAYERS_ELIMINATED.replace("%player%", player.getName()));
	}

	if(cfg.getRegenHeadDropOnPlayerDeath()){
		event.getDrops().add(UhcItems.createRegenHead(uhcPlayer));
	}

	if(cfg.getEnableGoldenHeads()){
		if (cfg.getPlaceHeadOnFence() && !gm.getScenarioManager().isActivated(Scenario.TIMEBOMB)){
			// place head on fence
			Location loc = player.getLocation().clone().add(1,0,0);
			loc.getBlock().setType(UniversalMaterial.OAK_FENCE.getType());
			loc.add(0, 1, 0);
			loc.getBlock().setType(UniversalMaterial.PLAYER_HEAD_BLOCK.getType());

			Skull skull = (Skull) loc.getBlock().getState();
			VersionUtils.getVersionUtils().setSkullOwner(skull, uhcPlayer);
			skull.setRotation(BlockFace.NORTH);
			skull.update();
		}else{
			event.getDrops().add(UhcItems.createGoldenHeadPlayerSkull(player.getName(), player.getUniqueId()));
		}
	}

	if(cfg.getEnableExpDropOnDeath()){
		UhcItems.spawnExtraXp(player.getLocation(), cfg.getExpDropOnDeath());
	}

	uhcPlayer.setState(PlayerState.DEAD);
	pm.strikeLightning(uhcPlayer);
	pm.playSoundPlayerDeath();

	// handle player leaving the server
	boolean canContinueToSpectate = player.hasPermission("uhc-core.spectate.override")
			|| cfg.getCanSpectateAfterDeath();

	if (!canContinueToSpectate) {
		if (cfg.getEnableBungeeSupport()) {
			Bukkit.getScheduler().runTaskAsynchronously(UhcCore.getPlugin(), new TimeBeforeSendBungeeThread(uhcPlayer, cfg.getTimeBeforeSendBungeeAfterDeath()));
		} else {
			player.kickPlayer(Lang.DISPLAY_MESSAGE_PREFIX + " " + Lang.KICK_DEAD);
		}
	}

	pm.checkIfRemainingPlayers();
}
 
Example 17
Source File: EnvironmentControlListener.java    From ProjectAres with GNU Affero General Public License v3.0 4 votes vote down vote up
@EventHandler(priority = EventPriority.HIGH)
public void noForm(final BlockFormEvent event) {
    event.setCancelled(true);
}
 
Example 18
Source File: EnvironmentControlListener.java    From ProjectAres with GNU Affero General Public License v3.0 4 votes vote down vote up
@EventHandler(priority = EventPriority.HIGH)
public void death(final PlayerDeathEvent event) {
    event.getDrops().clear();
}
 
Example 19
Source File: SharedHealthListener.java    From UhcCore with GNU General Public License v3.0 4 votes vote down vote up
@EventHandler (priority = EventPriority.HIGH)
public void onPlayerDamage(EntityDamageEvent e){
    // Check if entity is player
    if (e.getEntityType() != EntityType.PLAYER){
        return;
    }

    if (e.isCancelled()){
        return;
    }

    // Check if GameState is Playing | Deathmatch
    GameState state = getGameManager().getGameState();
    if (state != GameState.PLAYING && state != GameState.DEATHMATCH){
        return;
    }

    UhcPlayer uhcPlayer = getPlayersManager().getUhcPlayer((Player) e.getEntity());

    // Check if player is playing
    if (uhcPlayer.getState() != PlayerState.PLAYING){
        return;
    }

    // If solo player don't share damage
    List<UhcPlayer> onlinePlayingMembers = uhcPlayer.getTeam().getOnlinePlayingMembers();
    if (onlinePlayingMembers.size() <= 1){
        return;
    }

    double damage = e.getDamage()/onlinePlayingMembers.size();
    e.setDamage(damage);

    for (UhcPlayer uhcMember : onlinePlayingMembers){
        if (uhcMember == uhcPlayer){
            continue;
        }

        try {
            uhcMember.getPlayer().damage(damage);
        }catch (UhcPlayerNotOnlineException ex){
            ex.printStackTrace();
        }
    }
}
 
Example 20
Source File: LifeskillingListener.java    From EnchantmentsEnhance with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Breeding animals gives enhancement stone.
 *
 * @param e
 */
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGH)
public void onBreeding(PlayerInteractEntityEvent e) {

}