Java Code Examples for org.bukkit.event.EventPriority

The following examples show how to use org.bukkit.event.EventPriority. 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(priority = EventPriority.HIGHEST)
public void onCommandExecuted(PlayerCommandPreprocessEvent event) {
    if (event.isCancelled()) {
        return;
    }

    final Player player = event.getPlayer();
    if (Main.isPlayerInGame(player)) {
        //Allow players with permissions to use all commands
        if (player.hasPermission(ADMIN_PERMISSION)) {
            return;
        }

        final String message = event.getMessage();
        if (Main.isCommandLeaveShortcut(message)) {
            event.setCancelled(true);
            Main.getPlayerGameProfile(event.getPlayer()).changeGame(null);
        } else if (!Main.isCommandAllowedInGame(message.split(" ")[0])) {
            event.setCancelled(true);
            event.getPlayer().sendMessage(i18n("command_is_not_allowed"));
        }
    }
}
 
Example 2
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onDyeing(PlayerInteractEvent e) {
    if (e.getAction() != Action.RIGHT_CLICK_BLOCK || e.getItem() == null || !Util.isDyes(e.getItem().getType())) {
        return;
    }
    final Block block = e.getClickedBlock();
    if (block == null || !Util.isWallSign(block.getType())) {
        return;
    }
    final Block attachedBlock = Util.getAttached(block);
    if (attachedBlock == null || plugin.getShopManager().getShopIncludeAttached(attachedBlock.getLocation()) == null) {
        return;
    }
    e.setCancelled(true);
    Util.debugLog("Disallow " + e.getPlayer().getName() + " dye the shop sign.");
}
 
Example 3
Source Project: TAB   Source File: NameTagX.java    License: Apache License 2.0 6 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void a(PlayerMoveEvent e) {
	if (e.getFrom().getX() == e.getTo().getX() && e.getFrom().getY() == e.getTo().getY() && e.getFrom().getZ() == e.getTo().getZ()) return; //player only moved head
	ITabPlayer p = Shared.getPlayer(e.getPlayer().getUniqueId());
	if (p == null) return;
	if (!p.disabledNametag) Shared.featureCpu.runMeasuredTask("processing PlayerMoveEvent", CPUFeature.NAMETAGX_EVENT_MOVE, new Runnable() {
		public void run() {
			for (ArmorStand as : p.getArmorStands()) {
				as.updateLocation(e.getTo());
				List<ITabPlayer> nearbyPlayers = as.getNearbyPlayers();
				synchronized (nearbyPlayers){
					for (ITabPlayer nearby : nearbyPlayers) {
						nearby.sendPacket(as.getTeleportPacket(nearby));
					}
				}
			}
		}
	});
}
 
Example 4
Source Project: GriefDefender   Source File: WorldEventHandler.java    License: MIT License 6 votes vote down vote up
@EventHandler(priority = EventPriority.LOWEST)
public void onChunkLoad(ChunkLoadEvent event) {
    if (!GriefDefenderPlugin.getInstance().claimsEnabledForWorld(event.getWorld().getUID())) {
        return;
    }

    final GDClaimManager claimWorldManager = GriefDefenderPlugin.getInstance().dataStore.getClaimWorldManager(event.getWorld().getUID());
    final GDChunk gdChunk = claimWorldManager.getChunk(event.getChunk());
    if (gdChunk != null) {
        try {
            gdChunk.loadChunkTrackingData();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
 
Example 5
Source Project: PGM   Source File: ScoreMatchModule.java    License: GNU Affero General Public License v3.0 6 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void playerAcquireRedeemableInBox(final PlayerItemTransferEvent event) {
  if (!event.isAcquiring()) return;
  final MatchPlayer player = this.match.getPlayer(event.getPlayer());
  if (player == null || !player.canInteract() || player.getBukkit().isDead()) return;

  for (final ScoreBox box : this.scoreBoxes) {
    if (!box.getRedeemables().isEmpty()
        && box.getRegion().contains(player.getBukkit())
        && box.canScore(player.getParticipantState())) {
      match
          .getExecutor(MatchScope.RUNNING)
          .execute(
              () -> {
                if (player.getBukkit().isOnline()) {
                  double points = redeemItems(box, player.getInventory());
                  ScoreMatchModule.this.playerScore(box, player, points);
                }
              });
    }
  }
}
 
Example 6
Source Project: PGM   Source File: KitMatchModule.java    License: GNU Affero General Public License v3.0 6 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onGrenadeLaunch(final ProjectileLaunchEvent event) {
  if (event.getEntity().getShooter() instanceof Player) {
    Player player = (Player) event.getEntity().getShooter();
    ItemStack stack = player.getItemInHand();

    if (stack != null) {
      // special case for grenade arrows
      if (stack.getType() == Material.BOW) {
        int arrows = player.getInventory().first(Material.ARROW);
        if (arrows == -1) return;
        stack = player.getInventory().getItem(arrows);
      }

      Grenade grenade = Grenade.ITEM_TAG.get(stack);
      if (grenade != null) {
        grenade.set(PGM.get(), event.getEntity());
      }
    }
  }
}
 
Example 7
/**
 * Called when the player touches or leaves the ground
 */
@EventHandler(priority = EventPriority.MONITOR)
public void onPlayerOnGroundChanged(final PlayerOnGroundEvent event) {
    MatchPlayer player = match.getParticipant(event.getPlayer());
    if(player == null) return;

    FallState fall = this.falls.get(player);
    if(fall != null) {
        if(event.getOnGround()) {
            // Falling player landed on the ground, cancel the fall if they are still there after MAX_ON_GROUND_TIME
            fall.onGroundTick = match.getClock().now().tick;
            fall.groundTouchCount++;
            this.scheduleCheckFallTimeout(fall, FallState.MAX_ON_GROUND_TICKS + 1);
        } else {
            // Falling player left the ground, check if it was caused by the attack
            this.playerBecameUnsupported(fall);
        }
    }
}
 
Example 8
Source Project: MineTinker   Source File: KineticPlating.java    License: GNU General Public License v3.0 6 votes vote down vote up
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void effect(EntityDamageEvent event) {
	if (!(event.getEntity() instanceof Player)) return;
	if (event.getCause() != EntityDamageEvent.DamageCause.FLY_INTO_WALL) return;

	Player player = (Player) event.getEntity();
	if (!player.hasPermission("minetinker.modifiers.kineticplating.use")) return;
	ItemStack elytra = player.getInventory().getChestplate();

	if (!modManager.hasMod(elytra, this)) return;

	int level = modManager.getModLevel(elytra, this);
	double damageMod = 1.0 - (this.amount * level);
	if (damageMod < 0.0) damageMod = 0.0;
	double oldDamage = event.getDamage();
	double newDamage = oldDamage * damageMod;
	event.setDamage(newDamage);
	ChatWriter.logModifier(player, event, this, elytra, String.format("Damage(%.2f -> %.2f [x%.2f])", oldDamage, newDamage, damageMod));
}
 
Example 9
Source Project: TAB   Source File: NameTagX.java    License: Apache License 2.0 6 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void a(PlayerTeleportEvent e) {
	ITabPlayer p = Shared.getPlayer(e.getPlayer().getUniqueId());
	if (p == null) return;
	if (!p.disabledNametag) Shared.featureCpu.runMeasuredTask("processing PlayerTeleportEvent", CPUFeature.NAMETAGX_EVENT_TELEPORT, new Runnable() {
		public void run() {
			synchronized (p.armorStands) {
				for (ArmorStand as : p.armorStands) {
					as.updateLocation(e.getTo());
					List<ITabPlayer> nearbyPlayers = as.getNearbyPlayers();
					synchronized (nearbyPlayers){
						for (ITabPlayer nearby : nearbyPlayers) {
							nearby.sendPacket(as.getTeleportPacket(nearby));
						}
					}
				}
			}
		}
	});
}
 
Example 10
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void partyLeave(PlayerLeavePartyEvent event) {
    if(event.getOldParty() instanceof MultiPlayerParty) {
        PlayerManager playerManager = channelsPlugin.getPlayerManager();
        Player bukkitPlayer = event.getPlayer().getBukkit();
        PartyChannel channel = partyChannels.get(event.getOldParty());

        if(channel != null) {
            bukkitPlayer.removeAttachments(channel.getListeningPermission());
            bukkitPlayer.removeAttachments(matchListeningPermission);

            // Whenever the player leaves a party with its own channel, check if that is the player's current channel,
            // and if it's not, then set their team chat setting to false. This is the only way to find out when they
            // switch to global chat, because the Channels plugin doesn't provide any notifcation.
            if(playerManager.getMembershipChannel(bukkitPlayer) != channel) {
                teamChatters.put(bukkitPlayer, false);
            }
        }
    }
}
 
Example 11
@EventHandler(priority = EventPriority.LOWEST)
public void checkInventoryClick(InventoryClickEvent event) {
    if(event.getCurrentItem() == null ||
       event.getCurrentItem().getItemMeta() == null ||
       event.getCurrentItem().getItemMeta().getDisplayName() == null) return;

    match.player(event.getActor()).ifPresent(player -> {
        if(!this.picking.contains(player)) return;

        this.handleInventoryClick(
            player,
            ChatColor.stripColor(event.getCurrentItem().getItemMeta().getDisplayName()),
            event.getCurrentItem().getData()
        );
        event.setCancelled(true);
    });
}
 
Example 12
Source Project: GriefDefender   Source File: CommandEventHandler.java    License: MIT License 6 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR)
public void onPlayerCommandMonitor(PlayerCommandPreprocessEvent event) {
    String message = event.getMessage();
    String arguments = "";
    String command = "";
    if (!message.contains(" ")) {
        command = message.replace("/", "");
    } else {
        command = message.substring(0, message.indexOf(" ")).replace("/", "");
        arguments = message.substring(message.indexOf(" ") + 1, message.length());
    }
    if (command.equalsIgnoreCase("datapack") && (arguments.contains("enable") || arguments.contains("disable"))) {
        if (GriefDefenderPlugin.getInstance().getTagProvider() != null) {
            GriefDefenderPlugin.getInstance().getTagProvider().refresh();
        }
    }
}
 
Example 13
Source Project: GriefDefender   Source File: BlockEventHandler.java    License: MIT License 6 votes vote down vote up
@EventHandler(priority = EventPriority.LOWEST)
public void onBlockDispense(BlockDispenseEvent event) {
    final Block block = event.getBlock();
    final World world = event.getBlock().getWorld();
    if (!GriefDefenderPlugin.getInstance().claimsEnabledForWorld(world.getUID())) {
        return;
    }

    final Location location = block.getLocation();
    final GDClaimManager claimWorldManager = GriefDefenderPlugin.getInstance().dataStore.getClaimWorldManager(world.getUID());
    final GDChunk gpChunk = claimWorldManager.getChunk(block.getChunk());
    final GDPermissionUser user = gpChunk.getBlockOwner(location);
    if (user != null) {
        final BlockFace face = NMSUtil.getInstance().getFacing(block);
        final Location faceLocation = BlockUtil.getInstance().getBlockRelative(location, face);
        final GDClaim targetClaim = this.storage.getClaimAt(faceLocation);
        final ItemStack activeItem = user != null && user.getOnlinePlayer() != null ? NMSUtil.getInstance().getActiveItem(user.getOnlinePlayer()) : null;
        final Tristate result = GDPermissionManager.getInstance().getFinalPermission(event, location, targetClaim, Flags.INTERACT_BLOCK_SECONDARY, activeItem, event.getBlock(), user, TrustTypes.BUILDER, true);
        if (result == Tristate.FALSE) {
            event.setCancelled(true);
        } else {
            GDCauseStackManager.getInstance().pushCause(user);
        }
    }
}
 
Example 14
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void shopPriceChanges(ShopPriceChangeEvent event) {
    plugin.log(
            "Shop at location "
                    + event.getShop().getLocation()
                    + " price was changed from "
                    + event.getOldPrice()
                    + " to "
                    + event.getNewPrice());
}
 
Example 15
@TargetedEventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onKill(final MatchPlayerDeathEvent event) {
    ParticipantState killer = event.getKiller();
    if (event.getVictim().getUniqueId().equals(player)) {
        ++deaths;
    } else if (killer != null && killer.getUniqueId().equals(player) && event.isEnemyKill()) {
        ++lifeKills;
        ++teamKills;
        ++matchKills;
    }
}
 
Example 16
@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 17
Source Project: AdditionsAPI   Source File: DurabilityBar.java    License: MIT License 5 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST)
public void onPlayerTeleport(PlayerTeleportEvent event) {
	if (event.isCancelled())
		return;
	Player player = event.getPlayer();
	Bukkit.getScheduler().scheduleSyncDelayedTask(AdditionsAPI.getInstance(), () -> {
		sendDurabilityBossBar(player, player.getInventory().getItemInMainHand(), EquipmentSlot.HAND);
		sendDurabilityBossBar(player, player.getInventory().getItemInOffHand(), EquipmentSlot.OFF_HAND);
	});
}
 
Example 18
Source Project: Civs   Source File: CivilianListener.java    License: GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
public void onAdvertisementPlace(SignChangeEvent event) {
    Town town = TownManager.getInstance().getTownAt(event.getBlock().getLocation());
    if (town == null) {
        return;
    }
    Government government = GovernmentManager.getInstance().getGovernment(town.getGovernmentType());
    if (government.getGovernmentType() != GovernmentType.IDIOCRACY) {
        return;
    }
    changeAdvertising(event.getBlock(), town, false);
    changeAdvertising(event.getLines(), town, true);
    Util.checkNoise(town, event.getPlayer());
}
 
Example 19
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void addPlayersToRegisteredTeam(EntrantRegisterEvent event) throws EventException {
    event.yield();

    Match match = event.getTeam().getMatch();
    TeamMatchModule tmm = match.needMatchModule(TeamMatchModule.class);

    for(MatchPlayer player : match.getPlayers()) {
        if(event.getEntrant().members().contains(player.getPlayerId())) {
            tourney.getLogger().info("Adding player '" + player.getDisplayName() + "' to team '" + event.getTeam().getName() + "'");
            tmm.forceJoin(player, event.getTeam());
        }
    }
}
 
Example 20
@EventHandler(priority = EventPriority.HIGHEST)
public void onQuit(PlayerQuitEvent event) throws EventException {
    event.setQuitMessage(null);
    final User user = userStore.getUser(event.getPlayer());
    final SessionChange change = pendingQuits.getIfPresent(user);

    event.yield();

    if(change != null) {
        pendingQuits.invalidate(user);
        announce(change);
    }
}
 
Example 21
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onEntityIgnite(EntityCombustByBlockEvent event) {
    if(event.getDuration() == 0) return;

    ParticipantState owner = blocks.getOwner(event.getCombuster());
    if(owner != null) {
        burningEntities.put(event.getEntity(), new FireInfo(blocks.resolveBlock(event.getCombuster())));
    }
}
 
Example 22
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onMonitorBreakBlock(BlockBreakEvent event) {
    try {
        final Block block = event.getBlock();
        final Location location = block.getLocation();
        final IslandManager islandManager = IridiumSkyblock.getIslandManager();
        final Island island = islandManager.getIslandViaLocation(location);
        if (island == null) return;

        if (Utils.isBlockValuable(block)) {
            final Material material = block.getType();
            final String materialName = XMaterial.matchXMaterial(material).name();
            island.valuableBlocks.computeIfPresent(materialName, (name, original) -> original - 1);
            if (island.updating)
                island.tempValues.remove(location);

            Bukkit.getScheduler().runTask(IridiumSkyblock.getInstance(), island::calculateIslandValue);
        }

        island.failedGenerators.remove(location);
    } catch (Exception e) {
        IridiumSkyblock.getInstance().sendErrorMessage(e);
    }
}
 
Example 23
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onPlayerDamage(EntityDamageEvent event) {
    MatchPlayer victim = match.getParticipant(event.getEntity());
    if(victim == null) return;

    lastDamageInfos.put(victim, eventResolver.resolveDamage(event));
}
 
Example 24
Source Project: PGM   Source File: DeathTracker.java    License: GNU Affero General Public License v3.0 5 votes vote down vote up
/** Must run after {@link tc.oc.pgm.spawns.SpawnMatchModule#onVanillaDeath} */
@EventHandler(priority = EventPriority.NORMAL)
public void onPlayerDeath(PlayerDeathEvent event) {
  logger.fine("Wrapping " + event);
  MatchPlayer victim = match.getParticipant(event.getEntity());
  if (victim == null || victim.isDead()) return;

  DamageInfo info = getLastDamage(victim);
  if (info == null) info = new GenericDamageInfo(EntityDamageEvent.DamageCause.CUSTOM);

  match.callEvent(
      new MatchPlayerDeathEvent(event, victim, info, CombatLogTracker.isCombatLog(event)));
}
 
Example 25
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void shopCreate(ShopCreateEvent event) {
    plugin.log(
            "Player "
                    + event.getPlayer().getName()
                    + " created a shop at location "
                    + event.getShop().getLocation());
}
 
Example 26
Source Project: MineTinker   Source File: Poisonous.java    License: GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGH)
public void onDamage(EntityDamageEvent event) {
	if (event.getCause() != EntityDamageEvent.DamageCause.POISON) return;
	if (!(event.getEntity() instanceof Player)) return;
	if (!this.effectHealsPlayer) return;

	Player player = (Player) event.getEntity();
	if (!player.hasPermission("minetinker.modifiers.poisonous.use")) {
		return;
	}

	boolean hasPoisonous = false;
	ItemStack armor = null;
	for (ItemStack stack : player.getInventory().getArmorContents()) {
		if (stack == null) continue;
		if (modManager.hasMod(stack, this)) {
			hasPoisonous = true;
			armor = stack;
			break;
		}
	}

	if (!hasPoisonous) return;

	double damage = event.getDamage();
	if (damage > 0) {
		event.setDamage(0);
		double health = player.getHealth();
		player.setHealth(Math.min(health + damage, player.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue()));
		ChatWriter.logModifier(player, event, this, armor, String.format("Health(%.2f -> %.2f)", health, player.getHealth()));
	}
}
 
Example 27
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void cancelClicks(final InventoryClickEvent event) {
    final View view = views.get(event.getActor());
    if(view != null && event.getInventory().equals(view.preview)) {
        event.setCancelled(true);
    }
}
 
Example 28
Source Project: AdditionsAPI   Source File: CustomItemShearEntity.java    License: MIT License 5 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR)
public void onCustomItemShearEntity(CustomItemShearEntityEvent customEvent) {
	if (customEvent.isCancelled())
		return;
	CustomItem cItem = customEvent.getCustomItem();
	PlayerShearEntityEvent event = customEvent.getPlayerShearEntityEvent();
	Player player = event.getPlayer();
	if (cItem.getDurabilityMechanics() instanceof ShearDurability) {
		ItemStack item = customEvent.getCustomItemStack().getItemStack();
		ShearDurability mechanics = (ShearDurability) cItem.getDurabilityMechanics();
		Bukkit.getServer().getPluginManager()
				.callEvent(new PlayerCustomItemDamageEvent(player, item, mechanics.getShearSheep(), cItem));
	}
}
 
Example 29
@EventHandler(priority = EventPriority.MONITOR)
private void onPlayerKill(MatchPlayerDeathEvent event) {
    if(event.getKiller() != null &&
       event.isChallengeKill() &&
       getProximityMetricType(event.getKiller().getParty()) == ProximityMetric.Type.CLOSEST_KILL) {

        updateProximity(event.getKiller(), event.getKiller().getLocation());
    }
}
 
Example 30
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void rightClickDefuse(final PlayerInteractEntityEvent event) {
    ItemStack hand = event.getPlayer().getItemInHand();
    if(hand == null || hand.getType() != DEFUSE_ITEM) return;

    this.participantDefuse(event.getPlayer(), event.getRightClicked());
}