ch.njol.skript.classes.Changer.ChangeMode Java Examples
The following examples show how to use
ch.njol.skript.classes.Changer.ChangeMode.
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: ExprRayfallOffhand.java From skRayFall with GNU General Public License v3.0 | 6 votes |
@SuppressWarnings("unchecked") @Override @Nullable public Class<?>[] acceptChange(final ChangeMode mode) { switch (mode) { case SET: return CollectionUtils.array(ItemStack.class); case ADD: case REMOVE: case DELETE: case REMOVE_ALL: case RESET: default: return null; } }
Example #2
Source File: EffReplace.java From Skript with GNU General Public License v3.0 | 6 votes |
@SuppressWarnings({"null"}) @Override public boolean init(final Expression<?>[] exprs, final int matchedPattern, final Kleenean isDelayed, final ParseResult parseResult) { haystack = exprs[1 + matchedPattern % 2]; replaceString = matchedPattern < 4; replaceFirst = matchedPattern > 1 && matchedPattern < 4; if (replaceString && !ChangerUtils.acceptsChange(haystack, ChangeMode.SET, String.class)) { Skript.error(haystack + " cannot be changed and can thus not have parts replaced."); return false; } if (SkriptConfig.caseSensitive.value() || parseResult.mark == 1) { caseSensitive = true; } needles = exprs[0]; replacement = exprs[2 - matchedPattern % 2]; return true; }
Example #3
Source File: ExprIdOf.java From Skript with GNU General Public License v3.0 | 6 votes |
@Override @Nullable public Class<?>[] acceptChange(final ChangeMode mode) { if (!getExpr().isSingle()) return null; if (!ChangerUtils.acceptsChange(getExpr(), ChangeMode.SET, ItemStack.class, ItemType.class)) return null; changeItemStack = ChangerUtils.acceptsChange(getExpr(), ChangeMode.SET, ItemStack.class); switch (mode) { case ADD: case REMOVE: case SET: return new Class[] {Number.class}; case RESET: case DELETE: case REMOVE_ALL: default: return null; } }
Example #4
Source File: ExprWeather.java From Skript with GNU General Public License v3.0 | 6 votes |
@Override public void change(final Event e, final @Nullable Object[] delta, final ChangeMode mode) { final WeatherType t = delta == null ? WeatherType.CLEAR : (WeatherType) delta[0]; for (final World w : getExpr().getArray(e)) { assert w != null : getExpr(); if (getTime() >= 0 && e instanceof WeatherEvent && w.equals(((WeatherEvent) e).getWorld()) && !Delay.isDelayed(e)) { if (e instanceof WeatherChangeEvent) { if (((WeatherChangeEvent) e).toWeatherState() && t == WeatherType.CLEAR) ((WeatherChangeEvent) e).setCancelled(true); if (((WeatherChangeEvent) e).getWorld().isThundering() != (t == WeatherType.THUNDER)) ((WeatherChangeEvent) e).getWorld().setThundering(t == WeatherType.THUNDER); } else if (e instanceof ThunderChangeEvent) { if (((ThunderChangeEvent) e).toThunderState() && t != WeatherType.THUNDER) ((ThunderChangeEvent) e).setCancelled(true); if (((ThunderChangeEvent) e).getWorld().hasStorm() == (t == WeatherType.CLEAR)) ((ThunderChangeEvent) e).getWorld().setStorm(t != WeatherType.CLEAR); } } else { t.setWeather(w); } } }
Example #5
Source File: ExprLore.java From Skript with GNU General Public License v3.0 | 6 votes |
@Override @Nullable public Class<?>[] acceptChange(final ChangeMode mode) { boolean acceptsMany = lineNumber == null; switch (mode) { case REMOVE: case REMOVE_ALL: case DELETE: acceptsMany = false; case SET: case ADD: if (ChangerUtils.acceptsChange(item, ChangeMode.SET, ItemStack.class, ItemType.class)) { return CollectionUtils.array(acceptsMany ? String[].class : String.class); } return null; case RESET: default: return null; } }
Example #6
Source File: ExprLevel.java From Skript with GNU General Public License v3.0 | 6 votes |
@Override @Nullable public Class<?>[] acceptChange(final ChangeMode mode) { if (mode == ChangeMode.REMOVE_ALL) return null; if (ScriptLoader.isCurrentEvent(PlayerRespawnEvent.class) && !ScriptLoader.hasDelayBefore.isTrue()) { Skript.error("Cannot change a player's level in a respawn event. Add a delay of 1 tick or change the 'new level' in a death event."); return null; } if (ScriptLoader.isCurrentEvent(PlayerDeathEvent.class) && getTime() == 0 && getExpr().isDefault() && !ScriptLoader.hasDelayBefore.isTrue()) { Skript.warning("Changing the player's level in a death event will change the player's level before he dies. " + "Use either 'past level of player' or 'new level of player' to clearly state whether to change the level before or after he dies."); } if (getTime() == -1 && !ScriptLoader.isCurrentEvent(PlayerDeathEvent.class)) return null; return new Class[] {Number.class}; }
Example #7
Source File: EffChange.java From Skript with GNU General Public License v3.0 | 6 votes |
@Override protected void execute(final Event e) { final Expression<?> changer = this.changer; Object[] delta = changer == null ? null : changer.getArray(e); delta = changer == null ? delta : changer.beforeChange(changed, delta); if (delta != null && delta.length == 0) return; if (delta == null && (mode != ChangeMode.DELETE && mode != ChangeMode.RESET)) return; changed.change(e, delta, mode); // Trigger beforeChanged hook // REMIND use a random element out of delta if changed only supports changing a single instance // changed.change(e, new Changer2<Object>() { // @Override // public Object change(Object o) { // return delta; // } // }, mode); }
Example #8
Source File: ExprVelocity.java From Skript with GNU General Public License v3.0 | 6 votes |
@Override @SuppressWarnings("null") public void change(Event e, @Nullable Object[] delta, ChangeMode mode) { assert delta != null; for (final Entity entity : getExpr().getArray(e)) { if (entity == null) return; switch (mode) { case ADD: entity.setVelocity(entity.getVelocity().add((Vector) delta[0])); break; case REMOVE: entity.setVelocity(entity.getVelocity().subtract((Vector) delta[0])); break; case REMOVE_ALL: break; case DELETE: case RESET: entity.setVelocity(new Vector()); break; case SET: entity.setVelocity((Vector) delta[0]); } } }
Example #9
Source File: ExprSpawnerType.java From Skript with GNU General Public License v3.0 | 6 votes |
@SuppressWarnings("null") @Override public void change(final Event e, final @Nullable Object[] delta, final ChangeMode mode) { for (Block b : getExpr().getArray(e)) { if (b.getType() != MATERIAL_SPAWNER) continue; CreatureSpawner s = (CreatureSpawner) b.getState(); switch (mode) { case SET: s.setSpawnedType(toBukkitEntityType((EntityData) delta[0])); break; case RESET: s.setSpawnedType(org.bukkit.entity.EntityType.PIG); break; } s.update(); // Actually trigger the spawner's update } }
Example #10
Source File: ExprName.java From Skript with GNU General Public License v3.0 | 6 votes |
@Override @Nullable public Class<?>[] acceptChange(ChangeMode mode) { if (mode == ChangeMode.DELETE && (type.acceptChange & ~PLAYER) != 0 || mode == ChangeMode.RESET) return new Class[0]; if (mode != ChangeMode.SET) return null; if ((type.acceptChange & PLAYER) != 0 && Player.class.isAssignableFrom(getExpr().getReturnType())) { changeType = PLAYER; } else if ((type.acceptChange & INVENTORY) != 0 && Inventory.class.isAssignableFrom(getExpr().getReturnType())) { changeType = INVENTORY; } else if ((type.acceptChange & ITEM) != 0 && (getExpr().isSingle() && ChangerUtils.acceptsChange(getExpr(), ChangeMode.SET, ItemStack.class, ItemType.class) || Slot.class.isAssignableFrom(getExpr().getReturnType()))) { changeType = ITEM; } else if ((type.acceptChange & ENTITY) != 0 && Entity.class.isAssignableFrom(getExpr().getReturnType())) { if (type == NameType.NAME && Player.class.isAssignableFrom(getExpr().getReturnType())) { Skript.error("Can't change the Minecraft name of a player. Change the 'display name' or 'tab list name' instead."); return null; } changeType = ENTITY; } return changeType == 0 ? null : CollectionUtils.array(String.class); }
Example #11
Source File: ExprOnlinePlayersCount.java From Skript with GNU General Public License v3.0 | 6 votes |
@Override @Nullable public Class<?>[] acceptChange(ChangeMode mode) { if (!isReal) { if (ScriptLoader.hasDelayBefore.isTrue()) { Skript.error("Can't change the shown online players count anymore after the server list ping event has already passed"); return null; } switch (mode) { case SET: case ADD: case REMOVE: case DELETE: case RESET: return CollectionUtils.array(Number.class); } } return null; }
Example #12
Source File: ExprMaxHealth.java From Skript with GNU General Public License v3.0 | 6 votes |
@Override public void change(final Event e, final @Nullable Object[] delta, final ChangeMode mode) { double d = delta == null ? 0 : ((Number) delta[0]).doubleValue(); for (final LivingEntity en : getExpr().getArray(e)) { assert en != null : getExpr(); switch (mode) { case SET: HealthUtils.setMaxHealth(en, d); break; case REMOVE: d = -d; //$FALL-THROUGH$ case ADD: HealthUtils.setMaxHealth(en, HealthUtils.getMaxHealth(en) + d); break; case RESET: en.resetMaxHealth(); break; case DELETE: case REMOVE_ALL: assert false; } } }
Example #13
Source File: ExprVectorXYZ.java From Skript with GNU General Public License v3.0 | 5 votes |
@Override public void change(Event e, @Nullable Object[] delta, ChangeMode mode) { assert delta != null; final Vector v = getExpr().getSingle(e); if (v == null) return; double n = ((Number) delta[0]).doubleValue(); switch (mode) { case REMOVE: n = -n; //$FALL-THROUGH$ case ADD: if (axis == 0) v.setX(v.getX() + n); else if (axis == 1) v.setY(v.getY() + n); else v.setZ(v.getZ() + n); getExpr().change(e, new Vector[] {v}, ChangeMode.SET); break; case SET: if (axis == 0) v.setX(n); else if (axis == 1) v.setY(n); else v.setZ(n); getExpr().change(e, new Vector[] {v}, ChangeMode.SET); } }
Example #14
Source File: ExprVectorXYZ.java From Skript with GNU General Public License v3.0 | 5 votes |
@Override @SuppressWarnings("null") public Class<?>[] acceptChange(ChangeMode mode) { if ((mode == ChangeMode.ADD || mode == ChangeMode.REMOVE || mode == ChangeMode.SET) && getExpr().isSingle() && Changer.ChangerUtils.acceptsChange(getExpr(), ChangeMode.SET, Vector.class)) return CollectionUtils.array(Number.class); return null; }
Example #15
Source File: ExprLastDamageCause.java From Skript with GNU General Public License v3.0 | 5 votes |
@Override @Nullable public Class<?>[] acceptChange(final ChangeMode mode) { if (mode == ChangeMode.REMOVE_ALL) return null; return CollectionUtils.array(DamageCause.class); }
Example #16
Source File: ExprYawPitch.java From Skript with GNU General Public License v3.0 | 5 votes |
@SuppressWarnings({"null"}) @Override public Class<?>[] acceptChange(final ChangeMode mode) { if (mode == ChangeMode.SET || mode == ChangeMode.ADD || mode == ChangeMode.REMOVE) return CollectionUtils.array(Number.class); return null; }
Example #17
Source File: ExprRespawnLocation.java From Skript with GNU General Public License v3.0 | 5 votes |
@Nullable @Override public Class<?>[] acceptChange(Changer.ChangeMode mode) { if (mode == ChangeMode.SET) return CollectionUtils.array(Location.class); return null; }
Example #18
Source File: ExprEntityTamer.java From Skript with GNU General Public License v3.0 | 5 votes |
@Nullable @Override public Class<?>[] acceptChange(ChangeMode mode) { if (mode == ChangeMode.SET || mode == ChangeMode.DELETE || mode == ChangeMode.RESET) return CollectionUtils.array(OfflinePlayer.class); return null; }
Example #19
Source File: ExprVectorLength.java From Skript with GNU General Public License v3.0 | 5 votes |
@Override @SuppressWarnings("null") public Class<?>[] acceptChange(ChangeMode mode) { if (mode == ChangeMode.ADD || mode == ChangeMode.REMOVE || mode == ChangeMode.SET) return CollectionUtils.array(Number.class); return null; }
Example #20
Source File: EffEnchant.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) { item = (Expression<ItemType>) exprs[0]; if (!ChangerUtils.acceptsChange(item, ChangeMode.SET, ItemStack.class)) { Skript.error(item + " cannot be changed, thus it cannot be (dis)enchanted"); return false; } if (matchedPattern == 0) enchs = (Expression<EnchantmentType>) exprs[1]; return true; }
Example #21
Source File: ExprMOTD.java From Skript with GNU General Public License v3.0 | 5 votes |
@SuppressWarnings("null") @Override public void change(Event e, @Nullable Object[] delta, ChangeMode mode) { ServerListPingEvent event = (ServerListPingEvent) e; switch (mode) { case SET: event.setMotd((String) delta[0]); break; case DELETE: event.setMotd(""); break; case RESET: event.setMotd(Bukkit.getMotd()); } }
Example #22
Source File: ExprHealth.java From Skript with GNU General Public License v3.0 | 5 votes |
@Override public void change(final Event e, final @Nullable Object[] delta, final ChangeMode mode) { double d = delta == null ? 0 : ((Number) delta[0]).doubleValue(); switch (mode) { case DELETE: case SET: for (final LivingEntity entity : getExpr().getArray(e)) { assert entity != null : getExpr(); HealthUtils.setHealth(entity, d); } break; case REMOVE: d = -d; //$FALL-THROUGH$ case ADD: for (final LivingEntity entity : getExpr().getArray(e)) { assert entity != null : getExpr(); HealthUtils.heal(entity, d); } break; case RESET: for (final LivingEntity entity : getExpr().getArray(e)) { assert entity != null : getExpr(); HealthUtils.setHealth(entity, HealthUtils.getMaxHealth(entity)); } break; case REMOVE_ALL: assert false; } }
Example #23
Source File: ExprTime.java From Skript with GNU General Public License v3.0 | 5 votes |
@Override public void change(final Event e, final @Nullable Object[] delta, final ChangeMode mode) { final World[] worlds = getExpr().getArray(e); int mod = 1; switch (mode) { case SET: assert delta != null; final int time = delta[0] instanceof Time ? ((Time) delta[0]).getTicks() : ((Timeperiod) delta[0]).start; for (final World w : worlds) { w.setTime(time); } break; case REMOVE: mod = -1; //$FALL-THROUGH$ case ADD: assert delta != null; final Timespan ts = (Timespan) delta[0]; for (final World w : worlds) { w.setTime(w.getTime() + mod * ts.getTicks_i()); } break; case DELETE: case REMOVE_ALL: case RESET: assert false; } }
Example #24
Source File: ExprWeather.java From Skript with GNU General Public License v3.0 | 5 votes |
@Override @Nullable public Class<?>[] acceptChange(final ChangeMode mode) { if (mode == ChangeMode.DELETE || mode == ChangeMode.SET) return CollectionUtils.array(WeatherType.class); return null; }
Example #25
Source File: ExprGravity.java From Skript with GNU General Public License v3.0 | 5 votes |
@Override @Nullable public Class<?>[] acceptChange(final ChangeMode mode) { if (mode == ChangeMode.SET || mode == ChangeMode.RESET) return new Class[] {Boolean.class}; return null; }
Example #26
Source File: ExprDifficulty.java From Skript with GNU General Public License v3.0 | 5 votes |
@Override public void change(Event e, @Nullable Object[] delta, ChangeMode mode) { if (delta == null) return; Difficulty difficulty = (Difficulty) delta[0]; for (World world : getExpr().getArray(e)) { world.setDifficulty(difficulty); } }
Example #27
Source File: ExprDifficulty.java From Skript with GNU General Public License v3.0 | 5 votes |
@Override @Nullable public Class<?>[] acceptChange(ChangeMode mode) { if (mode == ChangeMode.SET) return CollectionUtils.array(Difficulty.class); return null; }
Example #28
Source File: ExprEnchantmentLevel.java From Skript with GNU General Public License v3.0 | 5 votes |
@Override public void change(Event e, @Nullable Object[] delta, ChangeMode mode) { if (delta == null) return; ItemType[] source = items.getArray(e); Enchantment[] enchantments = enchants.getArray(e); int newLevel = ((Number) delta[0]).intValue(); for (ItemType item : source) { if (!item.hasAnyEnchantments(enchantments)) continue; EnchantmentType[] enchants = item.getEnchantmentTypes(); assert enchants != null; // Can't be null at this point due to the above check for (EnchantmentType enchant : enchants) { item.removeEnchantments(enchant); Enchantment type = enchant.getType(); int changed = newLevel; assert type != null; if (mode == ChangeMode.ADD) changed = Math.max(0, enchant.getLevel() + changed); else if (mode == ChangeMode.REMOVE) changed = Math.max(0, enchant.getLevel() - changed); if (changed > 0) item.addEnchantments(new EnchantmentType(type, newLevel)); } } }
Example #29
Source File: ExprEnchantmentLevel.java From Skript with GNU General Public License v3.0 | 5 votes |
@Nullable @Override public Class<?>[] acceptChange(ChangeMode mode) { switch (mode) { case SET: case REMOVE: case ADD: return CollectionUtils.array(Number.class); default: return null; } }
Example #30
Source File: ExprVelocity.java From Skript with GNU General Public License v3.0 | 5 votes |
@Override @SuppressWarnings("null") public Class<?>[] acceptChange(ChangeMode mode) { if ((mode == ChangeMode.ADD || mode == ChangeMode.REMOVE || mode == ChangeMode.SET || mode == ChangeMode.DELETE || mode == ChangeMode.RESET)) return CollectionUtils.array(Vector.class); return null; }