ch.njol.skript.classes.Changer Java Examples
The following examples show how to use
ch.njol.skript.classes.Changer.
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: ExprYaml.java From skript-yaml with MIT License | 6 votes |
@Override public Class<?>[] acceptChange(final Changer.ChangeMode mode) { if (mode == Changer.ChangeMode.DELETE || mode == Changer.ChangeMode.RESET) { return CollectionUtils.array(Object.class); } if (state == YamlState.VALUE) { if (mode == Changer.ChangeMode.SET) return CollectionUtils.array(Object.class); } else if (state == YamlState.NODE_KEYS) { if (mode == Changer.ChangeMode.ADD || mode == Changer.ChangeMode.REMOVE) return CollectionUtils.array(Object[].class); } else if (state == YamlState.LIST) { if (mode == Changer.ChangeMode.ADD || mode == Changer.ChangeMode.REMOVE || mode == Changer.ChangeMode.SET) return CollectionUtils.array(Object[].class); } return null; }
Example #2
Source File: ExprCustomModelData.java From Skript with GNU General Public License v3.0 | 6 votes |
@Override public void change(Event e, @Nullable Object[] delta, Changer.ChangeMode mode) { long data = delta == null ? 0 : ((Number) delta[0]).intValue(); if (data > 99999999 || data < 0) data = 0; for (ItemType item : getExpr().getArray(e)) { long oldData = 0; ItemMeta meta = item.getItemMeta(); if (meta.hasCustomModelData()) oldData = meta.getCustomModelData(); switch (mode) { case ADD: data = oldData + data; break; case REMOVE: data = oldData - data; break; case DELETE: case RESET: case REMOVE_ALL: data = 0; } meta.setCustomModelData((int) data); item.setItemMeta(meta); } }
Example #3
Source File: ExprBookAuthor.java From Skript with GNU General Public License v3.0 | 6 votes |
@SuppressWarnings("null") @Override public void change(Event e, @Nullable Object[] delta, Changer.ChangeMode mode) { ItemStack itemStack = getExpr().getSingle(e).getRandom(); if (itemStack == null || !book.isOfType(itemStack)) return; BookMeta bookMeta = (BookMeta) itemStack.getItemMeta(); switch (mode){ case SET: bookMeta.setAuthor(delta == null ? "" : (String) delta[0]); break; case RESET: case DELETE: bookMeta.setAuthor(""); break; //$CASES-OMITTED$ default: assert false; } itemStack.setItemMeta(bookMeta); }
Example #4
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 #5
Source File: ExprBookTitle.java From Skript with GNU General Public License v3.0 | 6 votes |
@SuppressWarnings("null") @Override public void change(Event e, @Nullable Object[] delta, Changer.ChangeMode mode) { ItemStack itemStack = getExpr().getSingle(e).getRandom(); if (itemStack == null || !book.isOfType(itemStack)) return; BookMeta bookMeta = (BookMeta) itemStack.getItemMeta(); switch (mode){ case SET: bookMeta.setTitle(delta == null ? "" : (String) delta[0]); break; case RESET: case DELETE: bookMeta.setTitle(""); break; //$CASES-OMITTED$ default: assert false; } itemStack.setItemMeta(bookMeta); }
Example #6
Source File: SExprYaml.java From skUtilities with GNU General Public License v3.0 | 6 votes |
@SuppressWarnings("unchecked") @Override public Class<?>[] acceptChange(final Changer.ChangeMode mode) { if (mode == Changer.ChangeMode.DELETE) { return CollectionUtils.array(Object.class); } switch (ty) { case 0: { if (mode == Changer.ChangeMode.SET) { return CollectionUtils.array(Object.class); } break; } case 1: case 2: case 3: if (mode == Changer.ChangeMode.ADD || mode == Changer.ChangeMode.REMOVE) { return CollectionUtils.array(Object.class); } break; } return null; }
Example #7
Source File: ExprSpectatorTarget.java From Skript with GNU General Public License v3.0 | 6 votes |
@Override public void change(Event e, @Nullable Object[] delta, Changer.ChangeMode mode) { for (Player player : getExpr().getArray(e)) { if (player.getGameMode() == GameMode.SPECTATOR) { switch (mode) { case SET: assert delta != null; player.setSpectatorTarget((Entity) delta[0]); break; case RESET: case DELETE: player.setSpectatorTarget(null); } } } }
Example #8
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 #9
Source File: ExprChatFormat.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; } String format = null; if (mode == Changer.ChangeMode.SET){ String newFormat = (String) delta[0]; if (newFormat == null){ return; } format = convertToNormal(newFormat); }else if (mode == Changer.ChangeMode.RESET){ format = "<%s> %s"; } if (format == null){ return; } ((AsyncPlayerChatEvent) e).setFormat(format); }
Example #10
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 #11
Source File: ConvertedExpression.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 ClassInfo<? super T> rti = returnTypeInfo; if (rti != null) { final Changer<? super T> c = rti.getChanger(); if (c != null) c.change(getArray(e), delta, mode); } else { source.change(e, delta, mode); } }
Example #12
Source File: SimpleLiteral.java From Skript with GNU General Public License v3.0 | 5 votes |
@Override @Nullable public Class<?>[] acceptChange(final ChangeMode mode) { ClassInfo<? super T> rti = returnTypeInfo; if (rti == null) returnTypeInfo = rti = Classes.getSuperClassInfo(getReturnType()); final Changer<? super T> c = rti.getChanger(); return c == null ? null : c.acceptChange(mode); }
Example #13
Source File: ExprYamlComments.java From skript-yaml with MIT License | 5 votes |
@Override public Class<?>[] acceptChange(final Changer.ChangeMode mode) { if (mode == Changer.ChangeMode.DELETE || mode == Changer.ChangeMode.RESET || mode == Changer.ChangeMode.SET) { return CollectionUtils.array(Object[].class); } return null; }
Example #14
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 #15
Source File: ExprHotbarSlot.java From Skript with GNU General Public License v3.0 | 5 votes |
@Override public void change(Event e, @Nullable Object[] delta, Changer.ChangeMode mode) { assert delta != null; Slot slot = (Slot) delta[0]; if (!(slot instanceof InventorySlot)) return; // Only inventory slots can be hotbar slots int index = ((InventorySlot) slot).getIndex(); if (index > 8) // Only slots in hotbar can be current hotbar slot return; for (Player p : getExpr().getArray(e)) { p.getInventory().setHeldItemSlot(index); } }
Example #16
Source File: ExprHotbarSlot.java From Skript with GNU General Public License v3.0 | 5 votes |
@Override @Nullable public Class<?>[] acceptChange(Changer.ChangeMode mode) { if (mode == Changer.ChangeMode.SET) return new Class[] {Slot.class}; return null; }
Example #17
Source File: ExprAI.java From Skript with GNU General Public License v3.0 | 5 votes |
@Override public void change(Event event, @Nullable Object[] delta, Changer.ChangeMode mode) { if (delta == null || delta[0] == null) { return; } boolean value = (Boolean) delta[0]; for (LivingEntity entity : getExpr().getArray(event)) { entity.setAI(value); } }
Example #18
Source File: SimpleExpressionFork.java From skript-yaml with MIT License | 5 votes |
@Override @Nullable public Class<?>[] acceptChange(final ChangeMode mode) { ClassInfo<?> rti = returnTypeInfo; if (rti == null) returnTypeInfo = rti = Classes.getSuperClassInfo(getReturnType()); final Changer<?> c = rti.getChanger(); if (c == null) return null; return c.acceptChange(mode); }
Example #19
Source File: SimpleExpressionFork.java From skript-yaml with MIT License | 5 votes |
@SuppressWarnings("unchecked") @Override public void change(final Event e, final @Nullable Object[] delta, final ChangeMode mode) { final ClassInfo<?> rti = returnTypeInfo; if (rti == null) throw new UnsupportedOperationException(); final Changer<?> c = rti.getChanger(); if (c == null) throw new UnsupportedOperationException(); ((Changer<T>) c).change(getArray(e), delta, mode); }
Example #20
Source File: ExprBookAuthor.java From Skript with GNU General Public License v3.0 | 5 votes |
@Nullable @Override public Class<?>[] acceptChange(Changer.ChangeMode mode) { if (mode == Changer.ChangeMode.SET || mode == Changer.ChangeMode.RESET || mode == Changer.ChangeMode.DELETE) return CollectionUtils.array(String.class); return null; }
Example #21
Source File: ExprVectorYawPitch.java From Skript with GNU General Public License v3.0 | 5 votes |
@Override @SuppressWarnings("null") public Class<?>[] acceptChange(ChangeMode mode) { if ((mode == ChangeMode.SET || mode == ChangeMode.ADD || mode == ChangeMode.REMOVE) && getExpr().isSingle() && Changer.ChangerUtils.acceptsChange(getExpr(), ChangeMode.SET, Vector.class)) return CollectionUtils.array(Number.class); return null; }
Example #22
Source File: ExprBookTitle.java From Skript with GNU General Public License v3.0 | 5 votes |
@Nullable @Override public Class<?>[] acceptChange(Changer.ChangeMode mode) { if (mode == Changer.ChangeMode.SET || mode == Changer.ChangeMode.RESET || mode == Changer.ChangeMode.DELETE){ return new Class<?>[]{String.class}; } return null; }
Example #23
Source File: ExprChatFormat.java From Skript with GNU General Public License v3.0 | 5 votes |
@Nullable @Override public Class<?>[] acceptChange(Changer.ChangeMode mode) { if (mode == Changer.ChangeMode.SET || mode == Changer.ChangeMode.RESET){ return new Class<?>[]{String.class}; } return null; }
Example #24
Source File: ExprBurnCookTime.java From Skript with GNU General Public License v3.0 | 5 votes |
@Override @Nullable public Class<?>[] acceptChange(Changer.ChangeMode mode) { if (mode == Changer.ChangeMode.ADD || mode == Changer.ChangeMode.REMOVE || mode == Changer.ChangeMode.SET) return CollectionUtils.array(Timespan.class); return null; }
Example #25
Source File: ConvertedExpression.java From Skript with GNU General Public License v3.0 | 5 votes |
@Override @Nullable public Class<?>[] acceptChange(final ChangeMode mode) { final Class<?>[] r = source.acceptChange(mode); if (r == null) { ClassInfo<? super T> rti = returnTypeInfo; returnTypeInfo = rti = Classes.getSuperClassInfo(getReturnType()); final Changer<?> c = rti.getChanger(); return c == null ? null : c.acceptChange(mode); } return r; }
Example #26
Source File: SimpleExpression.java From Skript with GNU General Public License v3.0 | 5 votes |
@SuppressWarnings("unchecked") @Override public void change(final Event e, final @Nullable Object[] delta, final ChangeMode mode) { final ClassInfo<?> rti = returnTypeInfo; if (rti == null) throw new UnsupportedOperationException(); final Changer<?> c = rti.getChanger(); if (c == null) throw new UnsupportedOperationException(); ((Changer<T>) c).change(getArray(e), delta, mode); }
Example #27
Source File: ExprMetadata.java From Skript with GNU General Public License v3.0 | 5 votes |
@Override @Nullable public Class<?>[] acceptChange(Changer.ChangeMode mode) { if (mode == Changer.ChangeMode.DELETE || mode == Changer.ChangeMode.SET) return CollectionUtils.array(Object.class); return null; }
Example #28
Source File: ExprMetadata.java From Skript with GNU General Public License v3.0 | 5 votes |
@Override public void change(Event e, @Nullable Object[] delta, Changer.ChangeMode mode) { for (String value : values.getArray(e)) { for (Metadatable holder : holders.getArray(e)) { switch (mode) { case SET: holder.setMetadata(value, new FixedMetadataValue(Skript.getInstance(), delta[0])); break; case DELETE: holder.removeMetadata(value, Skript.getInstance()); } } } }
Example #29
Source File: SimpleExpression.java From Skript with GNU General Public License v3.0 | 5 votes |
@Override @Nullable public Class<?>[] acceptChange(final ChangeMode mode) { ClassInfo<?> rti = returnTypeInfo; if (rti == null) returnTypeInfo = rti = Classes.getSuperClassInfo(getReturnType()); final Changer<?> c = rti.getChanger(); if (c == null) return null; return c.acceptChange(mode); }
Example #30
Source File: ExprGroup.java From Skript with GNU General Public License v3.0 | 5 votes |
@Override @Nullable public Class<?>[] acceptChange(Changer.ChangeMode mode) { if (mode == Changer.ChangeMode.ADD || mode == Changer.ChangeMode.REMOVE || mode == Changer.ChangeMode.SET || mode == Changer.ChangeMode.DELETE || mode == Changer.ChangeMode.RESET) { return new Class<?>[] {String[].class}; } return null; }