org.bukkit.event.entity.ExpBottleEvent Java Examples

The following examples show how to use org.bukkit.event.entity.ExpBottleEvent. 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: EvtExperienceSpawn.java    From Skript with GNU General Public License v3.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
private static void registerExecutor() {
	if (registeredExecutor)
		return;
	for (final Class<? extends Event> c : new Class[] {BlockExpEvent.class, EntityDeathEvent.class, ExpBottleEvent.class, PlayerFishEvent.class})
		Bukkit.getPluginManager().registerEvent(c, new Listener() {}, SkriptConfig.defaultEventPriority.value(), executor, Skript.getInstance(), true);
	registeredExecutor = true;
}
 
Example #2
Source File: ExpCapListener.java    From NyaaUtils with MIT License 4 votes vote down vote up
@EventHandler
public void onExpCapHit(ExpBottleEvent event) {
    if (event.getEntity().hasMetadata("nu_expcap_exp")) {
        List<MetadataValue> nu_expcap_exp = event.getEntity().getMetadata("nu_expcap_exp");
        MetadataValue metadataValue = nu_expcap_exp.get(0);
        if (metadataValue == null) {
            return;
        }
        int exp = metadataValue.asInt();
        if (exp <= 0)return;
        //生成的经验球数量大于1,小于总经验数
        int maxOrbAmount = Math.min(exp,cfg.expcap_max_orb_amount);
        int minOrbAmount = Math.max(1, ((NyaaUtils) plugin).cfg.expcap_min_orb_amount);
        int orbAmount = Math.min(Math.max(exp, minOrbAmount), maxOrbAmount);
        Location location = event.getEntity().getLocation();
        int expPerOrb = exp / orbAmount;
        int delay = 0;
        int step = Math.max(cfg.expcap_orb_ticksBetweenSpawn,0);
        //整形除法可能导致实际生成经验量偏少
        int spawnedExp = orbAmount * expPerOrb;
        int remain = exp - spawnedExp;
        final World world = location.getWorld();
        if (world == null) return;
        world.spawn(location, ExperienceOrb.class, experienceOrb -> {
            experienceOrb.setExperience(remain);
        });

        for (int i = 0; i < orbAmount; i++) {
            Bukkit.getScheduler().runTaskLater(plugin, ()->{
                Location add = null;
                for (int j = 0; j < 5; j++) {
                    Location clone = location.clone();
                    double dx = random.nextDouble() * 6;
                    double dy = random.nextDouble() * 3;
                    double dz = random.nextDouble() * 6;
                    dx -= 3;
                    dz -= 3;
                    add = clone.add(new Vector(dx, dy, dz));
                    if (!world.getBlockAt(location).getType().isSolid())break;
                }
                if (!world.getBlockAt(location).getType().isSolid()) add = location;
                world.spawn(add, ExperienceOrb.class, experienceOrb -> {
                    experienceOrb.setExperience(expPerOrb);
                });
            },delay+=step);
        }
    }
}
 
Example #3
Source File: DisableXPListener.java    From civcraft with GNU General Public License v2.0 4 votes vote down vote up
@EventHandler(priority = EventPriority.LOW)
public void onExpBottleEvent(ExpBottleEvent event) {
	event.setExperience(0);
}