ch.njol.skript.util.Timespan Java Examples
The following examples show how to use
ch.njol.skript.util.Timespan.
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: ExprBurnCookTime.java From Skript with GNU General Public License v3.0 | 6 votes |
@Override protected Timespan[] get(Event e, Block[] source) { if (isEvent) return CollectionUtils.array(Timespan.fromTicks_i(((FurnaceBurnEvent) e).getBurnTime())); else { Timespan[] result = Arrays.stream(source) .filter(block -> anyFurnace.isOfType(block)) .map(furnace -> { Furnace state = (Furnace) furnace.getState(); return Timespan.fromTicks_i(cookTime ? state.getCookTime() : state.getBurnTime()); }) .toArray(Timespan[]::new); assert result != null; return result; } }
Example #2
Source File: EffIgnite.java From Skript with GNU General Public License v3.0 | 6 votes |
@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: EffPoison.java From Skript with GNU General Public License v3.0 | 6 votes |
@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 #4
Source File: VariablesStorage.java From Skript with GNU General Public License v3.0 | 6 votes |
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(); } } } }; }
Example #5
Source File: ExprCmdCooldownInfo.java From Skript with GNU General Public License v3.0 | 6 votes |
@Nullable @Override public Class<?>[] acceptChange(Changer.ChangeMode mode) { switch (mode) { case ADD: case REMOVE: if (pattern <= 1) // remaining or elapsed time return new Class<?>[] { Timespan.class }; case RESET: case SET: if (pattern <= 1) // remaining or elapsed time return new Class<?>[] { Timespan.class }; else if (pattern == 3) // last usage date return new Class<?>[] { Date.class }; } return null; }
Example #6
Source File: ExprTime.java From Skript with GNU General Public License v3.0 | 6 votes |
@Override @Nullable public Class<?>[] acceptChange(final ChangeMode mode) { switch (mode) { case ADD: case REMOVE: return CollectionUtils.array(Timespan.class); case SET: return CollectionUtils.array(Time.class, Timeperiod.class); case DELETE: case REMOVE_ALL: case RESET: default: return null; } }
Example #7
Source File: ExprTimePlayed.java From Skript with GNU General Public License v3.0 | 6 votes |
@Override public void change(Event e, @Nullable Object[] delta, Changer.ChangeMode mode) { if (delta == null) { return; } long ticks = ((Timespan) delta[0]).getTicks_i(); for (Player player : getExpr().getArray(e)) { long playerTicks = player.getStatistic(TIME_PLAYED); switch (mode) { case ADD: ticks = playerTicks + ticks; break; case REMOVE: ticks = playerTicks - ticks; break; } player.setStatistic(TIME_PLAYED, (int) ticks); } }
Example #8
Source File: EffTitleV1_14.java From skRayFall with GNU General Public License v3.0 | 5 votes |
@SuppressWarnings("unchecked") @Override public boolean init(Expression<?>[] exp, int arg1, Kleenean arg2, ParseResult arg3) { player = (Expression<Player>) exp[0]; title = (Expression<String>) exp[1]; subTitle = (Expression<String>) exp[2]; time = (Expression<Timespan>) exp[3]; fadeIn = (Expression<Timespan>) exp[4]; fadeOut = (Expression<Timespan>) exp[5]; return true; }
Example #9
Source File: SkriptYamlRepresenter.java From skript-yaml with MIT License | 5 votes |
public SkriptYamlRepresenter() { this.nullRepresenter = new Represent() { @Override public Node representData(Object o) { return representScalar(Tag.NULL, ""); } }; this.representers.put(SkriptClass.class, new RepresentSkriptClass()); this.representers.put(ItemType.class, new RepresentSkriptItemType()); this.representers.put(Slot.class, new RepresentSkriptSlot()); this.representers.put(Date.class, new RepresentSkriptDate()); this.representers.put(Time.class, new RepresentSkriptTime()); this.representers.put(Timespan.class, new RepresentSkriptTimespan()); this.representers.put(Color.class, new RepresentSkriptColor()); this.representers.put(WeatherType.class, new RepresentSkriptWeather()); this.representers.put(Vector.class, new RepresentVector()); this.representers.put(Location.class, new RepresentLocation()); this.multiRepresenters.put(ConfigurationSerializable.class, new RepresentConfigurationSerializable()); for (Class<?> c : representers.keySet()) { if (c != null) { String name = c.getSimpleName(); if (!representedClasses.contains(name)) representedClasses.add(name); } } }
Example #10
Source File: EffPotion.java From Skript with GNU General Public License v3.0 | 5 votes |
@SuppressWarnings({"unchecked", "null"}) @Override public boolean init(final Expression<?>[] exprs, final int matchedPattern, final Kleenean isDelayed, final ParseResult parseResult) { apply = matchedPattern < 3; replaceExisting = parseResult.mark == 1; if (apply) { potions = (Expression<PotionEffectType>) exprs[0]; tier = (Expression<Number>) exprs[1]; entities = (Expression<LivingEntity>) exprs[2]; duration = (Expression<Timespan>) exprs[3]; } else { potions = (Expression<PotionEffectType>) exprs[0]; entities = (Expression<LivingEntity>) exprs[1]; } // Ambience and particles switch (matchedPattern) { case 0: ambient = false; particles = true; break; case 1: ambient = true; particles = true; break; case 2: ambient = false; particles = false; break; } return true; }
Example #11
Source File: IndeterminateDelay.java From Skript with GNU General Public License v3.0 | 5 votes |
@Override @Nullable protected TriggerItem walk(final Event e) { debug(e, true); final long start = Skript.debug() ? System.nanoTime() : 0; final TriggerItem next = getNext(); if (next != null) { delayed.add(e); final Timespan d = duration.getSingle(e); if (d == null) return null; // Back up local variables Object localVars = Variables.removeLocals(e); Bukkit.getScheduler().scheduleSyncDelayedTask(Skript.getInstance(), new Runnable() { @Override public void run() { if (Skript.debug()) Skript.info(getIndentation() + "... continuing after " + (System.nanoTime() - start) / 1000000000. + "s"); // Re-set local variables if (localVars != null) Variables.setLocalVariables(e, localVars); TriggerItem.walk(next, e); } }, d.getTicks_i()); } return null; }
Example #12
Source File: EffTimedBossBar.java From skRayFall with GNU General Public License v3.0 | 5 votes |
@SuppressWarnings("unchecked") @Override public boolean init(Expression<?>[] exp, int arg1, Kleenean arg2, ParseResult arg3) { text = (Expression<String>) exp[0]; player = (Expression<Player>) exp[1]; time = (Expression<Timespan>) exp[2]; return true; }
Example #13
Source File: EffBan.java From Skript with GNU General Public License v3.0 | 5 votes |
@SuppressWarnings({"null", "unchecked"}) @Override public boolean init(final Expression<?>[] exprs, final int matchedPattern, final Kleenean isDelayed, final ParseResult parseResult) { players = exprs[0]; reason = exprs.length > 1 ? (Expression<String>) exprs[1] : null; expires = exprs.length > 1 ? (Expression<Timespan>) exprs[2] : null; ban = matchedPattern % 2 == 0; ipBan = matchedPattern >= 2; return true; }
Example #14
Source File: Delay.java From Skript with GNU General Public License v3.0 | 5 votes |
@SuppressWarnings({"unchecked", "null"}) @Override public boolean init(final Expression<?>[] exprs, final int matchedPattern, final Kleenean isDelayed, final ParseResult parseResult) { duration = (Expression<Timespan>) exprs[0]; if (duration instanceof Literal) { // If we can, do sanity check for delays long millis = ((Literal<Timespan>) duration).getSingle().getMilliSeconds(); if (millis < 50) { Skript.warning("Delays less than one tick are not possible, defaulting to one tick."); } } return true; }
Example #15
Source File: EffTitleV1_9.java From skRayFall with GNU General Public License v3.0 | 5 votes |
@SuppressWarnings("unchecked") @Override public boolean init(Expression<?>[] exp, int arg1, Kleenean arg2, ParseResult arg3) { player = (Expression<Player>) exp[0]; title = (Expression<String>) exp[1]; subTitle = (Expression<String>) exp[2]; time = (Expression<Timespan>) exp[3]; fadeIn = (Expression<Timespan>) exp[4]; fadeOut = (Expression<Timespan>) exp[5]; return true; }
Example #16
Source File: ClassesTest.java From Skript with GNU General Public License v3.0 | 5 votes |
@Test public void test() { final Object[] random = { // Java (byte) 127, (short) 2000, -1600000, 1L << 40, -1.5f, 13.37, "String", // Skript SkriptColor.BLACK, StructureType.RED_MUSHROOM, WeatherType.THUNDER, new Date(System.currentTimeMillis()), new Timespan(1337), new Time(12000), new Timeperiod(1000, 23000), new Experience(15), new Direction(0, Math.PI, 10), new Direction(new double[] {0, 1, 0}), new EntityType(new SimpleEntityData(HumanEntity.class), 300), new CreeperData(), new SimpleEntityData(Snowball.class), new HorseData(Variant.SKELETON_HORSE), new WolfData(), new XpOrbData(50), // Bukkit - simple classes only GameMode.ADVENTURE, InventoryType.CHEST, DamageCause.FALL, // there is also at least one variable for each class on my test server which are tested whenever the server shuts down. }; for (final Object o : random) { Classes.serialize(o); // includes a deserialisation test } }
Example #17
Source File: EffTitleV1_13.java From skRayFall with GNU General Public License v3.0 | 5 votes |
@SuppressWarnings("unchecked") @Override public boolean init(Expression<?>[] exp, int arg1, Kleenean arg2, ParseResult arg3) { player = (Expression<Player>) exp[0]; title = (Expression<String>) exp[1]; subTitle = (Expression<String>) exp[2]; time = (Expression<Timespan>) exp[3]; fadeIn = (Expression<Timespan>) exp[4]; fadeOut = (Expression<Timespan>) exp[5]; return true; }
Example #18
Source File: EffTitleV1_12.java From skRayFall with GNU General Public License v3.0 | 5 votes |
@SuppressWarnings("unchecked") @Override public boolean init(Expression<?>[] exp, int arg1, Kleenean arg2, ParseResult arg3) { player = (Expression<Player>) exp[0]; title = (Expression<String>) exp[1]; subTitle = (Expression<String>) exp[2]; time = (Expression<Timespan>) exp[3]; fadeIn = (Expression<Timespan>) exp[4]; fadeOut = (Expression<Timespan>) exp[5]; return true; }
Example #19
Source File: EffTitleV1_13_1.java From skRayFall with GNU General Public License v3.0 | 5 votes |
@SuppressWarnings("unchecked") @Override public boolean init(Expression<?>[] exp, int arg1, Kleenean arg2, ParseResult arg3) { player = (Expression<Player>) exp[0]; title = (Expression<String>) exp[1]; subTitle = (Expression<String>) exp[2]; time = (Expression<Timespan>) exp[3]; fadeIn = (Expression<Timespan>) exp[4]; fadeOut = (Expression<Timespan>) exp[5]; return true; }
Example #20
Source File: EffTitleV1_10.java From skRayFall with GNU General Public License v3.0 | 5 votes |
@SuppressWarnings("unchecked") @Override public boolean init(Expression<?>[] exp, int arg1, Kleenean arg2, ParseResult arg3) { player = (Expression<Player>) exp[0]; title = (Expression<String>) exp[1]; subTitle = (Expression<String>) exp[2]; time = (Expression<Timespan>) exp[3]; fadeIn = (Expression<Timespan>) exp[4]; fadeOut = (Expression<Timespan>) exp[5]; return true; }
Example #21
Source File: EffTitleV1_11.java From skRayFall with GNU General Public License v3.0 | 5 votes |
@SuppressWarnings("unchecked") @Override public boolean init(Expression<?>[] exp, int arg1, Kleenean arg2, ParseResult arg3) { player = (Expression<Player>) exp[0]; title = (Expression<String>) exp[1]; subTitle = (Expression<String>) exp[2]; time = (Expression<Timespan>) exp[3]; fadeIn = (Expression<Timespan>) exp[4]; fadeOut = (Expression<Timespan>) exp[5]; return true; }
Example #22
Source File: EffTitleV1_9_4.java From skRayFall with GNU General Public License v3.0 | 5 votes |
@SuppressWarnings("unchecked") @Override public boolean init(Expression<?>[] exp, int arg1, Kleenean arg2, ParseResult arg3) { player = (Expression<Player>) exp[0]; title = (Expression<String>) exp[1]; subTitle = (Expression<String>) exp[2]; time = (Expression<Timespan>) exp[3]; fadeIn = (Expression<Timespan>) exp[4]; fadeOut = (Expression<Timespan>) exp[5]; return true; }
Example #23
Source File: EffTimedBindedHolo.java From skRayFall with GNU General Public License v3.0 | 5 votes |
@SuppressWarnings("unchecked") @Override public boolean init(Expression<?>[] exp, int arg1, Kleenean arg2, ParseResult arg3) { text = (Expression<String>) exp[0]; tar = (Expression<Entity>) exp[1]; time = (Expression<Timespan>) exp[2]; xcord = (Expression<Number>) exp[3]; ycord = (Expression<Number>) exp[4]; zcord = (Expression<Number>) exp[5]; return true; }
Example #24
Source File: EffTimedHologram.java From skRayFall with GNU General Public License v3.0 | 5 votes |
@SuppressWarnings("unchecked") @Override public boolean init(Expression<?>[] exp, int arg1, Kleenean arg2, ParseResult arg3) { text = (Expression<String>) exp[0]; loc = (Expression<Location>) exp[1]; time = (Expression<Timespan>) exp[2]; return true; }
Example #25
Source File: EffTimedClientSideHolo.java From skRayFall with GNU General Public License v3.0 | 5 votes |
@SuppressWarnings("unchecked") @Override public boolean init(Expression<?>[] exp, int arg1, Kleenean arg2, ParseResult arg3) { text = (Expression<String>) exp[0]; loc = (Expression<Location>) exp[1]; player = (Expression<Player>) exp[2]; time = (Expression<Timespan>) exp[3]; return true; }
Example #26
Source File: EffTitleV1_8_3.java From skRayFall with GNU General Public License v3.0 | 5 votes |
@SuppressWarnings("unchecked") @Override public boolean init(Expression<?>[] exp, int arg1, Kleenean arg2, ParseResult arg3) { player = (Expression<Player>) exp[0]; title = (Expression<String>) exp[1]; subTitle = (Expression<String>) exp[2]; time = (Expression<Timespan>) exp[3]; fadeIn = (Expression<Timespan>) exp[4]; fadeOut = (Expression<Timespan>) exp[5]; return true; }
Example #27
Source File: EffTitleV1_8.java From skRayFall with GNU General Public License v3.0 | 5 votes |
@SuppressWarnings("unchecked") @Override public boolean init(Expression<?>[] exp, int arg1, Kleenean arg2, ParseResult arg3) { player = (Expression<Player>) exp[0]; title = (Expression<String>) exp[1]; subTitle = (Expression<String>) exp[2]; time = (Expression<Timespan>) exp[3]; fadeIn = (Expression<Timespan>) exp[4]; fadeOut = (Expression<Timespan>) exp[5]; return true; }
Example #28
Source File: EffTitleV1_8_4.java From skRayFall with GNU General Public License v3.0 | 5 votes |
@SuppressWarnings("unchecked") @Override public boolean init(Expression<?>[] exp, int arg1, Kleenean arg2, ParseResult arg3) { player = (Expression<Player>) exp[0]; title = (Expression<String>) exp[1]; subTitle = (Expression<String>) exp[2]; time = (Expression<Timespan>) exp[3]; fadeIn = (Expression<Timespan>) exp[4]; fadeOut = (Expression<Timespan>) exp[5]; return true; }
Example #29
Source File: EffIgnite.java From Skript with GNU General Public License v3.0 | 5 votes |
@SuppressWarnings({"unchecked", "null"}) @Override public boolean init(final Expression<?>[] exprs, final int matchedPattern, final Kleenean isDelayed, final ParseResult parseResult) { entities = (Expression<Entity>) exprs[0]; ignite = exprs.length > 1; if (ignite) duration = (Expression<Timespan>) exprs[1]; return true; }
Example #30
Source File: CondDate.java From Skript with GNU General Public License v3.0 | 5 votes |
@SuppressWarnings({"unchecked", "null"}) @Override public boolean init(final Expression<?>[] exprs, final int matchedPattern, final Kleenean isDelayed, final ParseResult parseResult) { date = (Expression<Date>) exprs[0]; delta = (Expression<Timespan>) exprs[1]; setNegated(matchedPattern == 1); return true; }