Java Code Examples for ch.njol.skript.util.Timespan#getTicks_i()

The following examples show how to use ch.njol.skript.util.Timespan#getTicks_i() . 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: EffPoison.java    From Skript with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected void execute(final Event e) {
	for (final LivingEntity le : entites.getArray(e)) {
		if (!cure) {
			Timespan dur;
			int d = (int) (duration != null && (dur = duration.getSingle(e)) != null ? 
					(dur.getTicks_i() >= Integer.MAX_VALUE ? Integer.MAX_VALUE : dur.getTicks_i()) : DEFAULT_DURATION);
			if (le.hasPotionEffect(PotionEffectType.POISON)) {
				for (final PotionEffect pe : le.getActivePotionEffects()) {
					if (pe.getType() != PotionEffectType.POISON)
						continue;
					d += pe.getDuration();
				}
			}
			le.addPotionEffect(new PotionEffect(PotionEffectType.POISON, d, 0), true);
		} else {
			le.removePotionEffect(PotionEffectType.POISON);
		}
	}
}
 
Example 2
Source File: EffIgnite.java    From Skript with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected void execute(final Event e) {
	final int d;
	if (duration != null) {
		final Timespan t = duration.getSingle(e);
		if (t == null)
			return;
		d = (int) (t.getTicks_i() >= Integer.MAX_VALUE ? Integer.MAX_VALUE : t.getTicks_i());
	} else {
		d = ignite ? DEFAULT_DURATION : 0;
	}
	for (final Entity en : entities.getArray(e)) {
		if (e instanceof EntityDamageEvent && ((EntityDamageEvent) e).getEntity() == en && !Delay.isDelayed(e)) {
			Bukkit.getScheduler().scheduleSyncDelayedTask(Skript.getInstance(), new Runnable() {
				@Override
				public void run() {
					en.setFireTicks(d);
				}
			});
		} else {
			if (e instanceof EntityCombustEvent && ((EntityCombustEvent) e).getEntity() == en && !Delay.isDelayed(e))
				((EntityCombustEvent) e).setCancelled(true);// can't change the duration, thus simply cancel the event (and create a new one)
			en.setFireTicks(d);
		}
	}
}
 
Example 3
Source File: VariablesStorage.java    From Skript with GNU General Public License v3.0 6 votes vote down vote up
public void startBackupTask(final Timespan t) {
	final File file = this.file;
	if (file == null || t.getTicks_i() == 0)
		return;
	backupTask = new Task(Skript.getInstance(), t.getTicks_i(), t.getTicks_i(), true) {
		@Override
		public void run() {
			synchronized (connectionLock) {
				disconnect();
				try {
					FileUtils.backup(file);
				} catch (final IOException e) {
					Skript.error("Automatic variables backup failed: " + e.getLocalizedMessage());
				} finally {
					connect();
				}
			}
		}
	};
}