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

The following examples show how to use org.bukkit.event.EventPriority#NORMAL . 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: LugolsIodinePotion.java    From CraftserveRadiation with Apache License 2.0 6 votes vote down vote up
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onPlayerItemConsume(PlayerItemConsumeEvent event) {
    ItemStack item = event.getItem();
    if (!this.test(item)) {
        return;
    }

    PersistentDataContainer container = item.getItemMeta().getPersistentDataContainer();

    int durationSeconds = 0;
    if (container.has(this.durationSecondsKey, PersistentDataType.INTEGER)) {
        durationSeconds = container.getOrDefault(this.durationSecondsKey, PersistentDataType.INTEGER, 0);
    } else if (container.has(this.durationKey, PersistentDataType.INTEGER)) {
        durationSeconds = (int) TimeUnit.MINUTES.toSeconds(container.getOrDefault(this.durationKey, PersistentDataType.INTEGER, 0)); // legacy
    }

    if (durationSeconds <= 0) {
        return;
    }

    Player player = event.getPlayer();
    this.effect.setEffect(player, durationSeconds);
    this.broadcastConsumption(player, durationSeconds);
}
 
Example 2
Source File: SpawnMatchModule.java    From PGM with GNU Affero General Public License v3.0 6 votes vote down vote up
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = false)
public void teleportObservers(final EntityDamageEvent event) {
  // when an observer begins to take fall damage, teleport them to their spawn
  if (event.getEntity() instanceof Player
      && event.getCause() == EntityDamageEvent.DamageCause.VOID) {
    MatchPlayer player = match.getPlayer(event.getEntity());
    if (player != null && player.isObserving()) {
      Spawn spawn = chooseSpawn(player);
      if (spawn != null) {
        Location location = spawn.getSpawn(player);
        if (location != null) {
          player.getBukkit().teleport(location);
        }
      }
    }
  }
}
 
Example 3
Source File: MultiTradeMatchModule.java    From PGM with GNU Affero General Public License v3.0 6 votes vote down vote up
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onInteract(PlayerInteractEntityEvent event) {
  if (event.getRightClicked() instanceof Villager) {
    // Fallback to once-at-a-time trading if multi trade does not work
    if (ok) {
      event.setCancelled(true);
    } else {
      return;
    }

    try {
      InventoryUtils.openVillager((Villager) event.getRightClicked(), event.getPlayer());
    } catch (NoSuchMethodError e) {
      logger.log(Level.WARNING, "<multitrade/> is not compatible with your server version");
      ok = false;
    } catch (Throwable t) {
      logger.log(
          Level.WARNING,
          String.format(
              "Villager at (%s) has invalid NBT data",
              event.getRightClicked().getLocation().toVector()),
          t);
      ok = false;
    }
  }
}
 
Example 4
Source File: RaindropListener.java    From ProjectAres with GNU Affero General Public License v3.0 6 votes vote down vote up
@EventHandler(priority = EventPriority.NORMAL)
public void kill(final MatchPlayerDeathEvent event) {
    if(!event.isChallengeKill()) return;

    // Death raindrops are given by the backend, to reduce API usage

    final int raindrops = calculateRaindrops(
        event.getKiller(),
        RaindropConstants.KILL_REWARD,
        false,
        1
    );

    event.setRaindrops(raindrops);

    final MatchPlayer killer = event.getOnlineKiller();
    if(killer != null) {
        RaindropUtil.showRaindrops(
            killer.getBukkit(),
            raindrops,
            RaindropUtil.calculateMultiplier(event.getKiller().getPlayerId()),
            new TranslatableComponent("match.kill.killed", event.getVictim().getComponentName())
        );
    }
}
 
Example 5
Source File: DeathTracker.java    From ProjectAres with 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 6
Source File: MetricsHandler.java    From CraftserveRadiation with Apache License 2.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.NORMAL)
public void onMetricSubmit(MetricSubmitEvent event) {
    Map<NamespacedKey, Object> data = event.getData();
    data.put(this.key("lugols_iodine_duration"), this.potion.getDuration().getSeconds());
    data.put(this.key("lugols_iodione_affected_count"), (int) this.server.getOnlinePlayers().stream()
            .filter(player -> this.effect.getEffect(player) != null)
            .count());
}
 
Example 7
Source File: DisableDamageMatchModule.java    From ProjectAres with GNU Affero General Public License v3.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void handleIgnition(EntityCombustByBlockEvent event) {
    MatchPlayer victim = getMatch().getParticipant(event.getEntity());
    if(victim == null) return;

    ParticipantState attacker = blockResolver.getOwner(event.getCombuster());

    // Disabling FIRE/LAVA damage also prevents setting on fire
    if(!this.canDamage(getBlockDamageCause(event.getCombuster()), victim, attacker)) {
        event.setCancelled(true);
    }
}
 
Example 8
Source File: FriendlyFireRefundMatchModule.java    From ProjectAres with GNU Affero General Public License v3.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.NORMAL)
public void handleFriendlyFire(EntityDamageByEntityEvent event) {
    if(event.isCancelled() && event.getDamager() instanceof Arrow) {
        Arrow arrow = (Arrow) event.getDamager();
        if(arrow.getPickupStatus() == Arrow.PickupStatus.ALLOWED && arrow.getShooter() != null && arrow.getShooter() instanceof Player){
            Player owner = (Player) arrow.getShooter();
            owner.getInventory().addItem(new ItemStack(Material.ARROW));
            arrow.remove();
        }
    }
}
 
Example 9
Source File: MultiTradeMatchModule.java    From ProjectAres with GNU Affero General Public License v3.0 5 votes vote down vote up
@ListenerScope(MatchScope.LOADED)
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void processItemRemoval(PlayerInteractEntityEvent event) {
    if(event.getRightClicked() instanceof Villager) {
        event.setCancelled(true);
        event.getPlayer().openMerchantCopy((Villager) event.getRightClicked());
    }
}
 
Example 10
Source File: HungerMatchModule.java    From PGM with GNU Affero General Public License v3.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void handleHungerChange(final FoodLevelChangeEvent event) {
  if (event.getEntity() instanceof Player) {
    int oldFoodLevel = ((Player) event.getEntity()).getFoodLevel();
    event.setFoodLevel(oldFoodLevel);
  }
}
 
Example 11
Source File: DeathTracker.java    From PGM with 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 12
Source File: DisableDamageMatchModule.java    From PGM with GNU Affero General Public License v3.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void handleIgnition(EntityCombustByBlockEvent event) {
  MatchPlayer victim = match.getParticipant(event.getEntity());
  if (victim == null) return;

  ParticipantState attacker =
      match.needModule(TrackerMatchModule.class).getOwner(event.getCombuster());

  // Disabling FIRE/LAVA damage also prevents setting on fire
  if (!this.canDamage(getBlockDamageCause(event.getCombuster()), victim, attacker)) {
    event.setCancelled(true);
  }
}
 
Example 13
Source File: FriendlyFireRefundMatchModule.java    From PGM with GNU Affero General Public License v3.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.NORMAL)
public void onHit(EntityDamageByEntityEvent event) {
  final Entity damager = event.getDamager();
  if (!event.isCancelled()
      || event.getCause() != EntityDamageEvent.DamageCause.PROJECTILE
      || !(damager instanceof Projectile)
      || !damager.hasMetadata(METADATA_KEY)) return;

  final Player shooter = (Player) ((Projectile) damager).getShooter();
  if (match.getParticipant(shooter) == null) return;

  damager.remove();
  shooter.getInventory().addItem(new ItemStack(Material.ARROW));
}
 
Example 14
Source File: PlayerListener.java    From ProjectAres with GNU Affero General Public License v3.0 4 votes vote down vote up
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onLogin(UserLoginEvent event) {
    final User user = event.getUser();
    final Player player = event.getPlayer();
    final Audience audience = audiences.get(player);

    audience.sendMessage(Components.blank());

    audience.sendMessage(
        new HeaderComponent(
            new Component(GREEN).translate("welcome", generalFormatter.brandName())
        )
    );

    audience.sendMessage(
        new Component(DARK_AQUA)
            .translate(
                "welcome.instructions",
                new Component(AQUA).translate("servers.lobby"),
                new Component(GOLD).translate("welcome.sign"),
                new Component(GREEN).translate("navigator.title")
            )
    );

    if(user.trial_expires_at() != null) {
        final Instant expires = TimeUtils.toInstant(user.trial_expires_at());
        final Instant now = Instant.now();

        if(expires.isAfter(now)) {
            long days = TimeUtils.daysRoundingUp(Duration.between(now, expires));
            final String key;
            if(days <= 1) {
                key = "trial.remaining.singular";
                days = 1;
            } else {
                key = "trial.remaining.plural";
            }

            audience.sendMessage(
                new Component(DARK_PURPLE)
                    .translate(
                        key,
                        new Component(LIGHT_PURPLE).translate("trial.freeTrial"),
                        new Component(days, LIGHT_PURPLE)
                    )
                    .extra(" ")
                    .translate(
                        "trial.details",
                        new Component(LIGHT_PURPLE).translate("trial.joinFull"),
                        new Component(LIGHT_PURPLE).translate("trial.chooseTeam")
                    )
                    .extra(" ")
                    .translate(
                        "trial.upgrade",
                        Links.shopLink()
                    )
            );
        }
    }

    audience.sendMessage(new HeaderComponent(
        new Component(ChatColor.GREEN)
            .translate(
                "welcome.visitWebsite",
                Links.homeLink()
            )
    ));
}
 
Example 15
Source File: AnvilListener.java    From MineTinker with GNU General Public License v3.0 4 votes vote down vote up
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onInventoryClick(InventoryClickEvent event) {
	HumanEntity he = event.getWhoClicked();

	if (!(he instanceof Player && event.getClickedInventory() instanceof AnvilInventory)) {
		return;
	}

	AnvilInventory inv = (AnvilInventory) event.getClickedInventory();
	Player player = (Player) he;

	ItemStack tool = inv.getItem(0);
	ItemStack modifier = inv.getItem(1);
	ItemStack newTool = inv.getItem(2);

	if (tool == null || modifier == null || newTool == null) {
		return;
	}

	if (event.getSlot() != 2) {
		return;
	}

	if (Lists.WORLDS.contains(player.getWorld().getName())) {
		return;
	}

	if (!(modManager.isToolViable(tool) || modManager.isArmorViable(tool))) {
		return;
	}

	//boolean deleteAllItems = false;
	if (event.getCursor() != null && !event.getCursor().getType().equals(Material.AIR)) {
		return;
	}

	if (!modManager.isModifierItem(modifier)) { //upgrade
		if (tool.getType().equals(newTool.getType())) return; //Not an upgrade

		if (new Random().nextInt(100) < MineTinker.getPlugin().getConfig().getInt("ChanceToFailToolUpgrade")) {
			newTool = tool;
			Bukkit.getPluginManager().callEvent(new ToolUpgradeEvent(player, newTool, false));
		} else {
			Bukkit.getPluginManager().callEvent(new ToolUpgradeEvent(player, newTool, true));
		}

		// ------ upgrade
		if (event.isShiftClick()) {
			if (player.getInventory().addItem(newTool).size() != 0) { //adds items to (full) inventory and then case if inventory is full
				event.setCancelled(true); //cancels the event if the player has a full inventory
				return;
			} // no else as it gets added in if-clause

			inv.clear();
			return;
		}

		player.setItemOnCursor(newTool);
		inv.clear();
	} else { //is modifier
		Modifier mod = modManager.getModifierFromItem(modifier);

		if (mod == null) {
			return;
		}

		modifier.setAmount(modifier.getAmount() - 1);

		if (new Random().nextInt(100) < MineTinker.getPlugin().getConfig().getInt("ChanceToFailModifierApply")) {
			newTool = tool;
			Bukkit.getPluginManager().callEvent(new ModifierFailEvent(player, tool, mod, ModifierFailCause.PLAYER_FAILURE, false));
		} else {
			Bukkit.getPluginManager().callEvent(new ModifierApplyEvent(player, tool, mod, modManager.getFreeSlots(newTool), false));
		}

		if (event.isShiftClick()) {
			if (player.getInventory().addItem(newTool).size() != 0) { //adds items to (full) inventory and then case if inventory is full
				event.setCancelled(true); //cancels the event if the player has a full inventory
				return;
			} // no else as it gets added in if-clause

			inv.clear();
			inv.setItem(1, modifier);

			return;
		}

		player.setItemOnCursor(newTool);

		inv.clear();
		inv.setItem(1, modifier);
	}
}
 
Example 16
Source File: SpawnMatchModule.java    From ProjectAres with GNU Affero General Public License v3.0 4 votes vote down vote up
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void playerMove(final CoarsePlayerMoveEvent event) {
    dispatchEvent(event.getPlayer(), (player, state) -> state.onEvent(event));
}
 
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.NORMAL)
public void noHunger(final FoodLevelChangeEvent event) {
    event.setCancelled(true);
}
 
Example 18
Source File: LaneMatchModule.java    From ProjectAres with GNU Affero General Public License v3.0 4 votes vote down vote up
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void preventBlockPlaceByVoidPlayer(final BlockTransformEvent event) {
    if(event instanceof PlayerBlockTransformEvent) {
        event.setCancelled(this.voidPlayers.contains(((PlayerBlockTransformEvent) event).getPlayerState().getPlayerId()));
    }
}
 
Example 19
Source File: PlayerDamageListener.java    From UhcCore with GNU General Public License v3.0 4 votes vote down vote up
@EventHandler(priority=EventPriority.NORMAL)
public void onPlayerDamage(EntityDamageByEntityEvent event){
	handlePvpAndFriendlyFire(event);
	handleLightningStrike(event);
	handleArrow(event);
}
 
Example 20
Source File: LugolsIodinePotion.java    From CraftserveRadiation with Apache License 2.0 4 votes vote down vote up
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onBrew(BrewEvent event) {
    if (!config.recipe.enabled) {
        return;
    }

    BrewerInventory inventory = event.getContents();
    BrewingStandWindow window = BrewingStandWindow.fromArray(inventory.getContents());

    if (!window.ingredient.getType().equals(config.recipe.ingredient)) {
        return;
    }

    boolean[] modified = new boolean[BrewingStandWindow.SLOTS];

    for (int i = 0; i < BrewingStandWindow.SLOTS; i++) {
        ItemStack result = window.results[i];
        if (result == null) {
            continue; // nothing in this slot
        }

        ItemMeta itemMeta = result.getItemMeta();
        if (!(itemMeta instanceof PotionMeta)) {
            continue;
        }

        PotionMeta potionMeta = (PotionMeta) itemMeta;
        if (potionMeta.getBasePotionData().getType().equals(config.recipe.basePotion)) {
            result.setItemMeta(this.convert(potionMeta));

            modified[i] = true;
        }
    }

    // delay this, because nms changes item stacks after BrewEvent is called
    this.plugin.getServer().getScheduler().runTask(this.plugin, () -> {
        for (int i = 0; i < BrewingStandWindow.SLOTS; i++) {
            if (modified[i]) {
                ItemStack[] contents = inventory.getContents();
                contents[i] = window.getResult(i);
                inventory.setContents(contents);
            }
        }
    });
}