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

The following examples show how to use org.bukkit.event.EventPriority#HIGHEST . 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: AntiGriefListener.java    From PGM with 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 2
Source File: DestroyableMatchModule.java    From PGM with GNU Affero General Public License v3.0 6 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void processBlockDamage(BlockDamageEvent event) {
  if (this.match.getWorld() != event.getBlock().getWorld()) return;

  Block block = event.getBlock();
  MaterialData material = block.getState().getData();
  MatchPlayer player = this.match.getPlayer(event.getPlayer());

  for (Destroyable destroyable : this.destroyables) {
    if (player != null
        && player.getParty() == destroyable.getOwner()
        && !destroyable.isDestroyed()
        && destroyable.getBlockRegion().contains(block)
        && destroyable.hasMaterial(material)) {

      event.setCancelled(true);
      // TODO: translate this
      player.sendWarning(TextComponent.of("You may not damage your own objective."));
    }
  }
}
 
Example 3
Source File: LWCPlayerListener.java    From Modern-LWC with MIT License 6 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST)
public void onPlayerArmorStandManipulate(PlayerArmorStandManipulateEvent e) {
    Entity entity = e.getRightClicked();
    if (plugin.getLWC().isProtectable(e.getRightClicked().getType())) {
        int A = 50000 + entity.getUniqueId().hashCode();

        LWC lwc = LWC.getInstance();
        Protection protection = lwc.getPhysicalDatabase().loadProtection(entity.getWorld().getName(), A, A, A);
        Player p = e.getPlayer();
        boolean canAccess = lwc.canAccessProtection(p, protection);
        if (onPlayerEntityInteract(p, entity, e.isCancelled())) {
            e.setCancelled(true);
        }
        if (protection != null) {
            if (canAccess)
                return;
            e.setCancelled(true);
        }
    }
}
 
Example 4
Source File: ShopProtectionListener.java    From QuickShop-Reremake with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onBlockRedstoneChange(BlockRedstoneEvent event) {
    if (!useEnhanceProtection) {
        return;
    }

    final Shop shop = getShopRedstone(event.getBlock().getLocation(), true);

    if (shop == null) {
        return;
    }

    event.setNewCurrent(event.getOldCurrent());
    // plugin.getLogger().warning("[Exploit Alert] a Redstone tried to active of " + shop);
    // Util.debugLog(ChatColor.RED + "[QuickShop][Exploit alert] Redstone was activated on the
    // following shop " + shop);
}
 
Example 5
Source File: DisplayProtectionListener.java    From QuickShop-Reremake with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
public void player(PlayerBucketEmptyEvent event) {
    if (!useEnhanceProtection) {
        return;
    }
    if (DisplayItem.getNowUsing() != DisplayType.REALITEM) {
        return;
    }
    final Block waterBlock = event.getBlockClicked().getRelative(event.getBlockFace());
    final Shop shop =
            getShopPlayer(waterBlock.getRelative(BlockFace.DOWN).getLocation(),true);
    if (shop == null) {
        return;
    }
    event.setCancelled(true);
    sendAlert(
            "[DisplayGuard] Player  "
                    + event.getPlayer().getName()
                    + " trying use water to move somethings on the shop top, QuickShop already remove it.");
}
 
Example 6
Source File: PlayerEventHandler.java    From GriefDefender with MIT License 6 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST)
public void onPlayerQuit(PlayerQuitEvent event) {
    final Player player = event.getPlayer();
    if (!GriefDefenderPlugin.getInstance().claimsEnabledForWorld(player.getWorld().getUID())) {
        return;
    }

    GDTimings.PLAYER_QUIT_EVENT.startTiming();
    UUID playerID = player.getUniqueId();
    GDPlayerData playerData = this.dataStore.getOrCreatePlayerData(player.getWorld(), playerID);

    if (this.worldEditProvider != null) {
        this.worldEditProvider.revertVisuals(player, playerData, null);
        //this.worldEditProvider.removePlayer(player);
    }

    playerData.onDisconnect();
    PaginationUtil.getInstance().removeActivePageData(player.getUniqueId());
    if (playerData.getClaims().isEmpty()) {
        this.dataStore.clearCachedPlayerData(player.getWorld().getUID(), playerID);
    }
    GDCallbackHolder.getInstance().onPlayerDisconnect(player);
    GDTimings.PLAYER_QUIT_EVENT.stopTiming();
}
 
Example 7
Source File: TeamListener.java    From ProjectAres with GNU Affero General Public License v3.0 6 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST)
public void handleMatchJoin(final MatchPlayerAddEvent event) {
    if (!tourney.getState().equals(TourneyState.ENABLED_FINISHED)) {
        final MatchManager matchManager = matchManagerProvider.get();
        if(matchManager.getMatch().equals(event.getMatch())) {
            final Player player = event.getPlayer().getBukkit();
            Team team = teamManagerProvider.get().getTeam(player);
            if(team != null) {
                event.getMatch().setPlayerParty(event.getPlayer(), team);
                ChannelsPlugin.get().getPlayerManager().setMembershipChannel(
                    player,
                    event.getMatch().needMatchModule(ChannelMatchModule.class).getChannel(team)
                );
            }
        }
    }
}
 
Example 8
Source File: ListenerShortcutSwapHand.java    From TrMenu with MIT License 5 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void offHand(PlayerSwapHandItemsEvent e) {
    boolean opened = TrMenuAPI.openByShortcut(e.getPlayer(), (e.getPlayer().isSneaking() ? TrMenu.SETTINGS.getString("SHORTCUT-OPEN.SNEAKING-OFFHAND", null) : TrMenu.SETTINGS.getString("SHORTCUT-OPEN.OFFHAND", null)));
    if (opened) {
        e.setCancelled(true);
    }
}
 
Example 9
Source File: EntityShootBow.java    From AdditionsAPI with MIT License 5 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST)
public void onEntityShootBow(EntityShootBowEvent event) {
	ItemStack item = event.getBow();
	if (AdditionsAPI.isCustomItem(item)) {
		CustomItemStack cStack = new CustomItemStack(item);
		CustomItem cItem = cStack.getCustomItem();
		if (cItem.getItemType() == ItemType.BOW) {
			Bukkit.getServer().getPluginManager().callEvent(new EntityShootCustomBowEvent(event, cStack));
		}
	}
}
 
Example 10
Source File: WorldListener.java    From BedWars with GNU Lesser General Public License v3.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST)
public void onBedWarsSpawnIsCancelled(CreatureSpawnEvent event) {
    if (!event.isCancelled()) {
        return;
    }
    // Fix for uSkyBlock plugin
    if (event.getSpawnReason() == SpawnReason.CUSTOM && Main.getInstance().isEntityInGame(event.getEntity())) {
        event.setCancelled(false);
    }
}
 
Example 11
Source File: CoreMatchModule.java    From ProjectAres with GNU Affero General Public License v3.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void damageCheck(BlockDamageEvent event) {
    Block block = event.getBlock();
    if(block.getWorld() != this.match.getWorld()) return;
    MatchPlayer player = this.match.getPlayer(event.getPlayer());
    Vector center = BlockUtils.center(block).toVector();

    for(Core core : this.cores) {
        if(!core.hasLeaked() && core.getCasingRegion().contains(center) && player.getParty() == core.getOwner()) {
            event.setCancelled(true);
            player.sendWarning(PGMTranslations.t("match.core.damageOwn", player), true);
        }
    }
}
 
Example 12
Source File: PlayerDeathListener.java    From EnchantmentsEnhance with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Prevents enhanced item dropped from death.
 *
 * @param e
 */
@EventHandler(priority = EventPriority.HIGHEST)
public void onPlayerDeath(PlayerDeathEvent e) {
    Player p = e.getEntity();
    List<ItemStack> newInventory = new ArrayList<ItemStack>();
    File playerFile = new File(m.getDataFolder() + "/death/" + p.getName() + ".yml");
    FileConfiguration pFile = YamlConfiguration.loadConfiguration(playerFile);
    pFile.set("PlayerName", p.getName());
    if (!e.getDrops().isEmpty() || e.getDrops() != null) {
        for (int i = 0; i < e.getDrops().size(); i++) {
            ItemStack stack = e.getDrops().get(i);
            if (stack.hasItemMeta()) {
                ItemMeta meta = stack.getItemMeta();
                if (meta.hasLore()) {
                    List<String> lore = meta.getLore();
                    for (String s : lore) {
                        s = ChatColor.stripColor(s);
                        if (s.contains(ChatColor.stripColor(Util.toColor(SettingsManager.lang.getString("lore.untradeableLore"))))
                                || s.contains(ChatColor.stripColor(Util.toColor(SettingsManager.lang.getString("lore.tradeableLore"))))) {
                            newInventory.add(e.getDrops().get(i));
                        }
                    }
                }
            }
        }
        ItemStack[] newStack = newInventory.toArray(new ItemStack[newInventory.size()]);
        pFile.set("Items", newStack);
        try {
            pFile.save(playerFile);
        } catch (IOException e1) {

        }
        e.getDrops().removeAll(newInventory);
    }
}
 
Example 13
Source File: DeathTracker.java    From ProjectAres with GNU Affero General Public License v3.0 5 votes vote down vote up
@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 14
Source File: PingListener.java    From UhcCore with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST)
public void onPing(ServerListPingEvent event){
	GameManager gm = GameManager.getGameManager();

	if (gm == null){
		return; // Still loading
	}

	if (gm.getConfiguration().getDisableMotd()){
		return; // No motd support
	}

	// Display motd
	switch(gm.getGameState()){
		case ENDED:
			event.setMotd(Lang.DISPLAY_MOTD_ENDED);
			break;
		case LOADING:
			event.setMotd(Lang.DISPLAY_MOTD_LOADING);
			break;
		case DEATHMATCH:
		case PLAYING:
			event.setMotd(Lang.DISPLAY_MOTD_PLAYING);
			break;
		case STARTING:
			event.setMotd(Lang.DISPLAY_MOTD_STARTING);
			break;
		case WAITING:
			event.setMotd(Lang.DISPLAY_MOTD_WAITING);
			break;
		default:
			event.setMotd(Lang.DISPLAY_MESSAGE_PREFIX);
			break;
	}
}
 
Example 15
Source File: JoinMessageAnnouncer.java    From ProjectAres with GNU Affero General Public License v3.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST)
public void onJoin(PlayerJoinEvent event) {
    event.setJoinMessage(null);
    final User user = userStore.getUser(event.getPlayer());
    final SessionChange change = pendingJoins.getIfPresent(user);
    if(change != null) {
        pendingJoins.invalidate(user);
        announce(change);
    }
}
 
Example 16
Source File: TNTTracker.java    From ProjectAres with GNU Affero General Public License v3.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onPrime(ExplosionPrimeEvent event) {
    if(event.getEntity() instanceof TNTPrimed) {
        // Some TNT was activated, try to figure out why
        TNTPrimed tnt = (TNTPrimed) event.getEntity();
        TNTInfo info = null;

        if(event instanceof ExplosionPrimeByEntityEvent) {
            Entity primer = ((ExplosionPrimeByEntityEvent) event).getPrimer();
            if(primer instanceof TNTPrimed) {
                // Primed by another owned explosive, propagate the damage info (e.g. origin location)
                info = resolveEntity(primer);
            } else {
                ParticipantState owner = entities().getOwner(primer);
                if(owner != null) {
                    // Primed by some other type of owned entity e.g. flaming arrow, pet creeper, etc.
                    info = new TNTInfo(owner, tnt.getLocation());
                }
            }
        }

        if(info == null) {
            ParticipantState placer = blocks().getOwner(tnt.getLocation().getBlock());
            if(placer != null) {
                // If no primer was resolved for the event, give the TNT entity to the block placer, if any
                info = new TNTInfo(placer, tnt.getLocation());
            }
        }

        if(info != null) {
            entities().trackEntity(tnt, info);
        }
    }
}
 
Example 17
Source File: Berserk.java    From MineTinker with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST)
public void onHit(EntityDamageEvent event) {
	if (!(event.getEntity() instanceof Player)) {
		return;
	}

	Player player = (Player) event.getEntity();

	if (!player.hasPermission("minetinker.modifiers.berserk.use")) {
		return;
	}

	ItemStack chest = player.getInventory().getChestplate();

	if (!modManager.isArmorViable(chest)) {
		return;
	}

	int modifierLevel = modManager.getModLevel(chest, this);

	if (modifierLevel <= 0) {
		return;
	}

	double lifeAfterDamage = player.getHealth() - event.getFinalDamage();
	AttributeInstance healthAttr = player.getAttribute(Attribute.GENERIC_MAX_HEALTH);

	double maxHealth = 20;

	if (healthAttr != null) {
		maxHealth = healthAttr.getValue();
	}

	if (player.getHealth() / maxHealth > trigger / 100.0 && lifeAfterDamage / maxHealth <= trigger / 100.0) {
		player.addPotionEffect(new PotionEffect(PotionEffectType.INCREASE_DAMAGE, boostTime, modifierLevel - 1));
		ChatWriter.logModifier(player, event, this, chest,
				"Time(" + boostTime + ")", "Amplifier(" + (modifierLevel - 1) + ")");
	}
}
 
Example 18
Source File: CraftListener.java    From UhcCore with GNU General Public License v3.0 4 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST)
public void onCrafting(CraftItemEvent event){
	ItemStack item = event.getRecipe().getResult();
	if (!item.hasItemMeta() || !item.getItemMeta().hasDisplayName()){
		return;
	}

	if (!(event.getWhoClicked() instanceof Player)){
		return;
	}

	Craft craft = CraftsManager.getCraft(item);
	if (craft == null){
		return;
	}

	Player player = (Player) event.getWhoClicked();
	GameManager gm = GameManager.getGameManager();
	UhcPlayer uhcPlayer = gm.getPlayersManager().getUhcPlayer(player);

	if(gm.getConfiguration().getEnableCraftsPermissions() && !player.hasPermission("uhc-core.craft."+craft.getName())){
		uhcPlayer.sendMessage(Lang.ITEMS_CRAFT_NO_PERMISSION.replace("%craft%", ChatColor.translateAlternateColorCodes('&', craft.getName())));
		event.setCancelled(true);
		return;
	}

	if(craft.getLimit() != -1 && (event.isShiftClick() || event.isRightClick())){
		uhcPlayer.sendMessage(Lang.ITEMS_CRAFT_LEFT_CLICK.replace("%craft%", ChatColor.translateAlternateColorCodes('&', craft.getName())));
		event.setCancelled(true);
		return;
	}

	if (craft.isReviveItem()){
		List<UhcPlayer> deadMembers = uhcPlayer.getTeam().getDeadMembers();

		if (deadMembers.isEmpty()){
			event.setCancelled(true);
			uhcPlayer.sendMessage(Lang.ITEMS_REVIVE_ERROR);
			return;
		}

		UhcPlayer revivePlayer = deadMembers.get(0);
		gm.getPlayersManager().revivePlayer(revivePlayer, craft.reviveWithInventory());

		uhcPlayer.sendMessage(Lang.ITEMS_REVIVE_SUCCESS.replace("%player%", revivePlayer.getName()));

		Bukkit.getScheduler().runTask(UhcCore.getPlugin(), () -> {
			player.setItemOnCursor(null);
			player.closeInventory();
		});
		return;
	}

	if(!uhcPlayer.addCraftedItem(craft.getName())){
		uhcPlayer.sendMessage(Lang.ITEMS_CRAFT_LIMIT.replace("%craft%", craft.getName()).replace("%limit%",""+craft.getLimit()));
		event.setCancelled(true);
	}else{
		uhcPlayer.sendMessage(Lang.ITEMS_CRAFT_CRAFTED.replace("%craft%", craft.getName()));
	}
}
 
Example 19
Source File: Nightseeker.java    From MineTinker with GNU General Public License v3.0 4 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST)
public void onHit(MTEntityDamageEvent event) {
	Player player = event.getPlayer();
	ItemStack tool = event.getTool();
	effect(event, event.getEvent(), tool, player);
}
 
Example 20
Source File: TNTMatchModule.java    From PGM with GNU Affero General Public License v3.0 4 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void dispenserNukes(BlockTransformEvent event) {
  BlockState oldState = event.getOldState();
  if (oldState instanceof Dispenser
      && this.properties.dispenserNukeLimit > 0
      && this.properties.dispenserNukeMultiplier > 0
      && event.getCause() instanceof EntityExplodeEvent) {

    EntityExplodeEvent explodeEvent = (EntityExplodeEvent) event.getCause();
    Dispenser dispenser = (Dispenser) oldState;
    int tntLimit =
        Math.round(this.properties.dispenserNukeLimit / this.properties.dispenserNukeMultiplier);
    int tntCount = 0;

    ItemStack[] inv = dispenser.getInventory().getContents();
    for (int slot = 0; slot < inv.length; slot++) {
      ItemStack stack = inv[slot];
      if (stack != null && stack.getType() == Material.TNT) {
        int transfer = Math.min(stack.getAmount(), tntLimit - tntCount);
        if (transfer > 0) {
          stack.setAmount(stack.getAmount() - transfer);
          tntCount += transfer;
          dispenser.getInventory().setItem(slot, stack);
        }
      }
    }

    tntCount = (int) Math.ceil(tntCount * this.properties.dispenserNukeMultiplier);

    for (int i = 0; i < tntCount; i++) {
      TNTPrimed tnt = match.getWorld().spawn(dispenser.getLocation(), TNTPrimed.class);

      tnt.setFuseTicks(
          10
              + match
                  .getRandom()
                  .nextInt(10)); // between 0.5 and 1.0 seconds, same as vanilla TNT chaining

      Random random = match.getRandom();
      Vector velocity =
          new Vector(
              random.nextGaussian(),
              random.nextGaussian(),
              random.nextGaussian()); // uniform random direction
      velocity.normalize().multiply(0.5 + 0.5 * random.nextDouble());
      tnt.setVelocity(velocity);

      callPrimeEvent(tnt, explodeEvent.getEntity());
    }
  }
}