ch.njol.skript.ScriptLoader Java Examples
The following examples show how to use
ch.njol.skript.ScriptLoader.
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: ExprAttacked.java From Skript with GNU General Public License v3.0 | 6 votes |
@Override public boolean init(final Expression<?>[] vars, final int matchedPattern, final Kleenean isDelayed, final ParseResult parser) { if (!ScriptLoader.isCurrentEvent(EntityDamageEvent.class, EntityDeathEvent.class, VehicleDamageEvent.class, VehicleDestroyEvent.class)) { Skript.error("The expression 'victim' can only be used in a damage or death event", ErrorQuality.SEMANTIC_ERROR); return false; } final String type = parser.regexes.size() == 0 ? null : parser.regexes.get(0).group(); if (type == null) { this.type = EntityData.fromClass(Entity.class); } else { final EntityData<?> t = EntityData.parse(type); if (t == null) { Skript.error("'" + type + "' is not an entity type", ErrorQuality.NOT_AN_EXPRESSION); return false; } this.type = t; } return true; }
Example #2
Source File: ExprFurnaceSlot.java From Skript with GNU General Public License v3.0 | 6 votes |
@SuppressWarnings({"unchecked", "null"}) @Override public boolean init(final Expression<?>[] exprs, final int matchedPattern, final Kleenean isDelayed, final ParseResult parseResult) { isEvent = matchedPattern == 0; slot = parseResult.mark; if (isEvent && slot == RESULT && !ScriptLoader.isCurrentEvent(FurnaceSmeltEvent.class)) { Skript.error("Cannot use 'result slot' outside a fuel smelt event."); return false; } else if (isEvent && slot == FUEL && !ScriptLoader.isCurrentEvent(FurnaceBurnEvent.class)) { Skript.error("Cannot use 'fuel slot' outside a fuel burn event."); return false; } if (!isEvent) setExpr((Expression<Block>) exprs[0]); return true; }
Example #3
Source File: EffCancelDrops.java From Skript with GNU General Public License v3.0 | 6 votes |
@Override public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) { cancelItems = parseResult.mark == 0 || parseResult.mark == 1; cancelExps = parseResult.mark == 0 || parseResult.mark == 2; if (ScriptLoader.isCurrentEvent(BlockBreakEvent.class)) { if (cancelItems && !CAN_CANCEL_BLOCK_ITEM_DROPS) { Skript.error("Cancelling drops of items in a block break event requires Minecraft 1.12 or newer"); return false; } } else if (!ScriptLoader.isCurrentEvent(EntityDeathEvent.class)) { Skript.error("The cancel drops effect can't be used outside of a death" + (CAN_CANCEL_BLOCK_ITEM_DROPS ? " or block break" : "") + " event"); return false; } if (isDelayed.isTrue()) { Skript.error("Can't cancel the drops anymore after the event has already passed"); return false; } return true; }
Example #4
Source File: ExprMaxPlayers.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 fake max 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 #5
Source File: ExprMOTD.java From Skript with GNU General Public License v3.0 | 6 votes |
@Override @Nullable public Class<?>[] acceptChange(ChangeMode mode) { if (!isDefault) { if (ScriptLoader.hasDelayBefore.isTrue()) { Skript.error("Can't change the MOTD anymore after the server list ping event has already passed"); return null; } switch (mode) { case SET: case DELETE: case RESET: return CollectionUtils.array(String.class); } } return null; }
Example #6
Source File: ExprHoverList.java From Skript with GNU General Public License v3.0 | 6 votes |
@Override @Nullable public Class<?>[] acceptChange(ChangeMode mode) { if (ScriptLoader.hasDelayBefore.isTrue()) { Skript.error("Can't change the hover list 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(String[].class, Player[].class); } return null; }
Example #7
Source File: EffCancelEvent.java From Skript with GNU General Public License v3.0 | 6 votes |
@SuppressWarnings("null") @Override public boolean init(final Expression<?>[] vars, final int matchedPattern, final Kleenean isDelayed, final ParseResult parser) { if (isDelayed == Kleenean.TRUE) { Skript.error("Can't cancel an event anymore after it has already passed", ErrorQuality.SEMANTIC_ERROR); return false; } cancel = matchedPattern == 0; final Class<? extends Event>[] es = ScriptLoader.getCurrentEvents(); if (es == null) return false; for (final Class<? extends Event> e : es) { if (Cancellable.class.isAssignableFrom(e) || BlockCanBuildEvent.class.isAssignableFrom(e)) return true; // TODO warning if some event(s) cannot be cancelled even though some can (needs a way to be suppressed) } if (ScriptLoader.isCurrentEvent(PlayerLoginEvent.class)) Skript.error("A connect event cannot be cancelled, but the player may be kicked ('kick player by reason of \"...\"')", ErrorQuality.SEMANTIC_ERROR); else Skript.error(Utils.A(ScriptLoader.getCurrentEventName()) + " event cannot be cancelled", ErrorQuality.SEMANTIC_ERROR); return false; }
Example #8
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 #9
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 #10
Source File: EffReloadSkript.java From skUtilities with GNU General Public License v3.0 | 5 votes |
@Override protected void execute(Event e) { File f = new File("plugins" + File.separator + "Skript" + File.separator + "scripts" + File.separator + str.getSingle(e).replaceAll(".sk", "") + ".sk"); if (f.exists()) { if (!f.isDirectory()) { unloadScript(f); ScriptLoader.loadScripts(new File[]{f}); } } else { skUtilities.prSysE("'" + f + "' doesn't exist!", getClass().getSimpleName()); } }
Example #11
Source File: EffReloadSkript.java From skUtilities with GNU General Public License v3.0 | 5 votes |
private static ScriptLoader.ScriptInfo unloadScript_(final File script) { final ScriptLoader.ScriptInfo info = removeTriggers(script); synchronized (loadedScripts) { loadedScripts.subtract(info); } return info; }
Example #12
Source File: ExprProtocolVersion.java From Skript with GNU General Public License v3.0 | 5 votes |
@Override public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) { if (!PAPER_EVENT_EXISTS) { Skript.error("The protocol version expression requires Paper 1.12.2 or newer"); return false; } else if (!ScriptLoader.isCurrentEvent(PaperServerListPingEvent.class)) { Skript.error("The protocol version expression can't be used outside of a server list ping event"); return false; } return true; }
Example #13
Source File: EffKeepInventory.java From Skript with GNU General Public License v3.0 | 5 votes |
@Override public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) { keepItems = matchedPattern == 0 || parseResult.mark == 1; keepExp = matchedPattern == 1 || parseResult.mark == 1; if (!ScriptLoader.isCurrentEvent(PlayerDeathEvent.class)) { Skript.error("The keep inventory/experience effect can't be used outside of a death event"); return false; } if (isDelayed.isTrue()) { Skript.error("Can't keep the inventory/experience anymore after the event has already passed"); return false; } return true; }
Example #14
Source File: EffScriptOptionLoops.java From Skript with GNU General Public License v3.0 | 5 votes |
@SuppressWarnings("null") @Override public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) { if(!ScriptLoader.isCurrentEvent(ScriptEvent.class) || isDelayed == Kleenean.TRUE){ Skript.error("Current event is not Script Event or you have a delay before the script option. Defaulting to 2.2 loops.", ErrorQuality.SEMANTIC_ERROR); ScriptOptions.getInstance().setUsesNewLoops(ScriptLoader.currentScript.getFile(), true); return false; } ScriptOptions.getInstance().setUsesNewLoops(ScriptLoader.currentScript.getFile(), parseResult.mark == 2); return true; }
Example #15
Source File: EffReloadSkript.java From skUtilities with GNU General Public License v3.0 | 5 votes |
private static ScriptLoader.ScriptInfo removeTriggers(final File script) { final ScriptLoader.ScriptInfo info = new ScriptLoader.ScriptInfo(); info.files = 1; final Iterator<List<Trigger>> triggersIter = triggers.values().iterator(); while (triggersIter.hasNext()) { final List<Trigger> ts = triggersIter.next(); for (int i = 0; i < ts.size(); i++) { if (script.equals(ts.get(i).getScript())) { info.triggers++; ts.remove(i); i--; if (ts.isEmpty()) triggersIter.remove(); } } } for (int i = 0; i < selfRegisteredTriggers.size(); i++) { final Trigger t = selfRegisteredTriggers.get(i); if (script.equals(t.getScript())) { info.triggers++; ((SelfRegisteringSkriptEvent) t.getEvent()).unregister(t); selfRegisteredTriggers.remove(i); i--; } } info.commands = Commands.unregisterCommands(script); info.functions = Functions.clearFunctions(script); return info; }
Example #16
Source File: EffPlayerInfoVisibility.java From Skript with GNU General Public License v3.0 | 5 votes |
@Override public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) { if (!PAPER_EVENT_EXISTS) { Skript.error("The player info visibility effect requires Paper 1.12.2 or newer"); return false; } else if (!ScriptLoader.isCurrentEvent(PaperServerListPingEvent.class)) { Skript.error("The player info visibility effect can't be used outside of a server list ping event"); return false; } else if (isDelayed == Kleenean.TRUE) { Skript.error("Can't change the player info visibility anymore after the server list ping event has already passed"); return false; } shouldHide = matchedPattern == 0; return true; }
Example #17
Source File: ExprFile.java From skUtilities with GNU General Public License v3.0 | 5 votes |
@SuppressWarnings("unchecked") @Override public boolean init(Expression<?>[] arg0, int arg1, Kleenean arg2, SkriptParser.ParseResult arg3) { if (!ScriptLoader.isCurrentEvent(EvtRunApp.class, EvtFileDownload.class, EvtFileCreation.class, EvtFileDeletion.class, EvtFileMove.class, EvtFileCopy.class, EvtFileRename.class, EvtFileWipe.class, EvtFileWrite.class, EvtUnzip.class, EvtFileZip.class)) { skUtilities.prSysE("Cannot use 'file' outside of file events!", getClass().getSimpleName()); return false; } return true; }
Example #18
Source File: EffExit.java From Skript with GNU General Public License v3.0 | 5 votes |
private static int numLevels(final int type) { if (type == EVERYTHING) return ScriptLoader.currentSections.size(); int r = 0; for (final TriggerSection s : ScriptLoader.currentSections) { if (type == CONDITIONALS ? s instanceof Conditional : s instanceof Loop || s instanceof While) r++; } return r; }
Example #19
Source File: SimpleExpression.java From Skript with GNU General Public License v3.0 | 5 votes |
protected final boolean setTime(final int time, final Expression<?> mustbeDefaultVar, final Class<? extends Event>... applicableEvents) { if (ScriptLoader.hasDelayBefore == Kleenean.TRUE && time != 0) { Skript.error("Can't use time states after the event has already passed"); return false; } if (!mustbeDefaultVar.isDefault()) return false; for (final Class<? extends Event> e : applicableEvents) { if (ScriptLoader.isCurrentEvent(e)) { this.time = time; return true; } } return false; }
Example #20
Source File: TriggerSection.java From Skript with GNU General Public License v3.0 | 5 votes |
protected TriggerSection(final SectionNode node) { ScriptLoader.currentSections.add(this); try { setTriggerItems(ScriptLoader.loadItems(node)); } finally { ScriptLoader.currentSections.remove(ScriptLoader.currentSections.size() - 1); } }
Example #21
Source File: ScriptFunction.java From Skript with GNU General Public License v3.0 | 5 votes |
@SuppressFBWarnings("ST_WRITE_TO_STATIC_FROM_INSTANCE_METHOD") public ScriptFunction(Signature<T> sign, SectionNode node) { super(sign); Functions.currentFunction = this; try { trigger = new Trigger(node.getConfig().getFile(), "function " + sign.getName(), new SimpleEvent(), ScriptLoader.loadItems(node)); } finally { Functions.currentFunction = null; } }
Example #22
Source File: ExprProtocolVersion.java From Skript with GNU General Public License v3.0 | 5 votes |
@Override @Nullable public Class<?>[] acceptChange(ChangeMode mode) { if (ScriptLoader.hasDelayBefore.isTrue()) { Skript.error("Can't change the protocol version anymore after the server list ping event has already passed"); return null; } if (mode == ChangeMode.SET) return CollectionUtils.array(Number.class); return null; }
Example #23
Source File: EffSuppressWarnings.java From Skript with GNU General Public License v3.0 | 5 votes |
@Override public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, SkriptParser.ParseResult parseResult) { Config cs = ScriptLoader.currentScript; if (cs == null) { Skript.error("You can only suppress warnings for script files!"); return false; } File scriptFile = cs.getFile(); mark = parseResult.mark; switch (parseResult.mark) { case 1: { //Possible variable conflicts ScriptOptions.getInstance().setSuppressWarning(scriptFile, "conflict"); break; } case 2: { //Variables cannot be saved ScriptOptions.getInstance().setSuppressWarning(scriptFile, "instance var"); break; } case 3: { //Missing "and" or "or" ScriptOptions.getInstance().setSuppressWarning(scriptFile, "conjunction"); break; } case 4: { //Variable starts with expression ScriptOptions.getInstance().setSuppressWarning(scriptFile, "start expression"); break; } default: { throw new AssertionError(); } } return true; }
Example #24
Source File: ExprMaxPlayers.java From Skript with GNU General Public License v3.0 | 5 votes |
@SuppressWarnings({"unchecked", "null"}) @Override public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, SkriptParser.ParseResult parseResult) { boolean isServerPingEvent = ScriptLoader.isCurrentEvent(ServerListPingEvent.class) || (PAPER_EVENT_EXISTS && ScriptLoader.isCurrentEvent(PaperServerListPingEvent.class)); if (parseResult.mark == 2 && !isServerPingEvent) { Skript.error("The 'shown' max players count expression can't be used outside of a server list ping event"); return false; } isReal = (parseResult.mark == 0 && !isServerPingEvent) || parseResult.mark == 1; return true; }
Example #25
Source File: ExprScripts.java From Skript with GNU General Public License v3.0 | 5 votes |
@Override protected String[] get(Event event) { List<File> scripts = new ArrayList<>(); if (includeEnabled) scripts.addAll(ScriptLoader.getLoadedFiles()); if (includeDisabled) scripts.addAll(ScriptLoader.getDisabledFiles()); return formatFiles(scripts); }
Example #26
Source File: ExprMe.java From Skript with GNU General Public License v3.0 | 5 votes |
@Override public boolean init(final Expression<?>[] exprs, final int matchedPattern, final Kleenean isDelayed, final ParseResult parseResult) { if (!ScriptLoader.isCurrentEvent(EffectCommandEvent.class)) { return false; } return true; }
Example #27
Source File: ExprCmdCooldownInfo.java From Skript with GNU General Public License v3.0 | 5 votes |
@Override public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, SkriptParser.ParseResult parseResult) { pattern = matchedPattern; if (!ScriptLoader.isCurrentEvent(ScriptCommandEvent.class)) { Skript.error("The " + getExpressionName() + " expression can only be used within a command", ErrorQuality.SEMANTIC_ERROR); return false; } return true; }
Example #28
Source File: ExprPushedBlocks.java From Skript with GNU General Public License v3.0 | 5 votes |
@Override public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) { if (!ScriptLoader.isCurrentEvent(BlockPistonExtendEvent.class, BlockPistonRetractEvent.class)) { Skript.error("The moved blocks are only usable in piston extend and retract events", ErrorQuality.SEMANTIC_ERROR); return false; } return true; }
Example #29
Source File: ExprBurnCookTime.java From Skript with GNU General Public License v3.0 | 5 votes |
@Override public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, SkriptParser.ParseResult parseResult) { cookTime = parseResult.mark == 1; isEvent = matchedPattern == 0; if (isEvent && !ScriptLoader.isCurrentEvent(FurnaceBurnEvent.class)) { Skript.error("Cannot use 'burning time' outside a fuel burn event."); return false; } if (!isEvent) setExpr((Expression<? extends Block>) exprs[0]); return true; }
Example #30
Source File: ExprDrops.java From Skript with GNU General Public License v3.0 | 5 votes |
@Override public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) { if (!ScriptLoader.isCurrentEvent(EntityDeathEvent.class)) { Skript.error("The expression 'drops' can only be used in death events", ErrorQuality.SEMANTIC_ERROR); return false; } return true; }