Java Code Examples for ch.njol.skript.Skript#warning()
The following examples show how to use
ch.njol.skript.Skript#warning() .
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: EquipmentSlot.java From Skript with GNU General Public License v3.0 | 9 votes |
@Override @Nullable public ItemStack get(EntityEquipment e) { if (Skript.isRunningMinecraft(1, 9)) { return e.getItemInOffHand(); } Skript.warning("No off hand support, but a skript would need that!"); return new ItemStack(Material.AIR); }
Example 2
Source File: EffSetScore.java From skRayFall with GNU General Public License v3.0 | 6 votes |
@Override protected void execute(Event evt) { if (player == null || num == null || player.getSingle(evt).getScoreboard() == null) { Skript.error("This player is either not online or has yet to have a scoreboard set for them"); return; } Scoreboard sb = player.getSingle(evt).getScoreboard(); Objective objective = sb.getObjective(DisplaySlot.SIDEBAR); Score score; if (name.getSingle(evt) == null){ Skript.warning("First arg in \"set score %string% in sidebar of %player% to %number%\" was null. " + "Objective will now be named null."); score = objective.getScore("null"); } else { score = objective.getScore(name.getSingle(evt).replace("\"", "")); } score.setScore(num.getSingle(evt).intValue()); }
Example 3
Source File: VariablesStorage.java From Skript with GNU General Public License v3.0 | 6 votes |
/** * May be called from a different thread than Bukkit's main thread. */ final void save(final SerializedVariable var) { if (changesQueue.size() > FIRST_WARNING && lastWarning < System.currentTimeMillis() - WARNING_INTERVAL * 1000) { Skript.warning("Cannot write variables to the database '" + databaseName + "' at sufficient speed; server performance may suffer and many variables will be lost if the server crashes. (this warning will be repeated at most once every " + WARNING_INTERVAL + " seconds)"); lastWarning = System.currentTimeMillis(); } if (!changesQueue.offer(var)) { if (lastError < System.currentTimeMillis() - ERROR_INTERVAL * 1000) { Skript.error("Skript cannot save any variables to the database '" + databaseName + "'. The server will hang and may crash if no more variables can be saved."); lastError = System.currentTimeMillis(); } while (true) { try { // REMIND add repetitive error and/or stop saving variables altogether? changesQueue.put(var); break; } catch (final InterruptedException e) {} } } }
Example 4
Source File: ExprUUID.java From Skript with GNU General Public License v3.0 | 6 votes |
@Override @Nullable public String convert(final Object o) { if (o instanceof OfflinePlayer) { if (offlineUUIDSupported) { try { return ((OfflinePlayer) o).getUniqueId().toString(); } catch (UnsupportedOperationException e) { // Some plugins (ProtocolLib) try to emulate offline players, but fail miserably // They will throw this exception... and somehow server may freeze when this happens Skript.warning("A script tried to get uuid of an offline player, which was faked by another plugin (probably ProtocolLib)."); e.printStackTrace(); return null; } } else return ((Player) o).getUniqueId().toString(); } else if (o instanceof Entity) { return ((Entity)o).getUniqueId().toString(); } else if (o instanceof World) { return ((World) o).getUID().toString(); } return null; }
Example 5
Source File: Documentation.java From Skript with GNU General Public License v3.0 | 6 votes |
private static void insertClass(final PrintWriter pw, final ClassInfo<?> info) { if (info.getDocName() == ClassInfo.NO_DOC) return; if (info.getDocName() == null || info.getDescription() == null || info.getUsage() == null || info.getExamples() == null || info.getSince() == null) { Skript.warning("Class " + info.getCodeName() + " is missing information"); return; } final String desc = validateHTML(StringUtils.join(info.getDescription(), "<br/>"), "classes"); final String usage = validateHTML(StringUtils.join(info.getUsage(), "<br/>"), "classes"); final String since = info.getSince() == null ? "" : validateHTML(info.getSince(), "classes"); if (desc == null || usage == null || since == null) { Skript.warning("Class " + info.getCodeName() + "'s description, usage or 'since' is invalid"); return; } final String patterns = info.getUserInputPatterns() == null ? "" : convertRegex(StringUtils.join(info.getUserInputPatterns(), "\n")); insertOnDuplicateKeyUpdate(pw, "classes", "id, name, description, patterns, `usage`, examples, since", "patterns = TRIM(LEADING '\n' FROM CONCAT(patterns, '\n', '" + escapeSQL(patterns) + "'))", escapeHTML(info.getCodeName()), escapeHTML(info.getDocName()), desc, patterns, usage, escapeHTML(StringUtils.join(info.getExamples(), "\n")), since); }
Example 6
Source File: ExprIdOf.java From Skript with GNU General Public License v3.0 | 6 votes |
@SuppressWarnings({"unchecked", "null"}) @Override public boolean init(final Expression<?>[] vars, final int matchedPattern, final Kleenean isDelayed, final ParseResult parser) { if (getMaterialMethod == null) { Skript.error("Items do not have numeric ids on Minecraft 1.13 or newer."); return false; } else { Skript.warning("Items do not have numeric ids on Minecraft 1.13 or newer. This script will not work on those versions!"); } setExpr((Expression<ItemType>) vars[0]); if (parser.mark != 1) { single = true; if (!getExpr().isSingle() || (getExpr() instanceof Literal && ((Literal<ItemType>) getExpr()).getSingle().getTypes().size() != 1)) { Skript.warning("'" + getExpr() + "' has multiple ids"); single = false; } } return true; }
Example 7
Source File: ExprTimes.java From Skript with GNU General Public License v3.0 | 6 votes |
@SuppressWarnings("unchecked") @Override public boolean init(final Expression<?>[] exprs, final int matchedPattern, final Kleenean isDelayed, final ParseResult parseResult) { end = matchedPattern == 0 ? (Expression<Number>) exprs[0] : new SimpleLiteral<>(matchedPattern, false); if (end instanceof Literal) { int amount = ((Literal<Number>) end).getSingle().intValue(); if (amount == 0 && isInLoop()) { Skript.warning("Looping zero times makes the code inside of the loop useless"); } else if (amount == 1 & isInLoop()) { Skript.warning("Since you're looping exactly one time, you could simply remove the loop instead"); } else if (amount < 0) { if (isInLoop()) Skript.error("Looping a negative amount of times is impossible"); else Skript.error("The times expression only supports positive numbers"); return false; } } return true; }
Example 8
Source File: Classes.java From Skript with GNU General Public License v3.0 | 6 votes |
/** * @param info info about the class to register */ public static <T> void registerClass(final ClassInfo<T> info) { try { Skript.checkAcceptRegistrations(); if (classInfosByCodeName.containsKey(info.getCodeName())) throw new IllegalArgumentException("Can't register " + info.getC().getName() + " with the code name " + info.getCodeName() + " because that name is already used by " + classInfosByCodeName.get(info.getCodeName())); if (exactClassInfos.containsKey(info.getC())) throw new IllegalArgumentException("Can't register the class info " + info.getCodeName() + " because the class " + info.getC().getName() + " is already registered"); if (info.getCodeName().length() > DatabaseStorage.MAX_CLASS_CODENAME_LENGTH) throw new IllegalArgumentException("The codename '" + info.getCodeName() + "' is too long to be saved in a database, the maximum length allowed is " + DatabaseStorage.MAX_CLASS_CODENAME_LENGTH); exactClassInfos.put(info.getC(), info); classInfosByCodeName.put(info.getCodeName(), info); tempClassInfos.add(info); } catch (RuntimeException e) { if (SkriptConfig.apiSoftExceptions.value()) Skript.warning("Ignored an exception due to user configuration: " + e.getMessage()); else throw e; } }
Example 9
Source File: Noun.java From Skript with GNU General Public License v3.0 | 6 votes |
@Override protected void onValueChange() { String value = getValue(); if (value == null) { plural = singular = key; gender = 0; return; } final int g = value.lastIndexOf('@'); if (g != -1) { gender = getGender("" + value.substring(g + 1).trim(), key); value = "" + value.substring(0, g).trim(); } else { gender = 0; } final NonNullPair<String, String> p = Noun.getPlural(value); singular = p.getFirst(); plural = p.getSecond(); if (gender == PLURAL && !Objects.equals(singular, plural)) Skript.warning("Noun '" + key + "' is of gender 'plural', but has different singular and plural values."); }
Example 10
Source File: ExprRegionsAt.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) { if (matchedPattern == 1) Skript.warning("Most regions plugins can have multiple intersecting regions at a the same location, thus it is recommended to use \"regions at ...\" instead of \"region at...\" for clarity."); locs = Direction.combine((Expression<? extends Direction>) exprs[0], (Expression<? extends Location>) exprs[1]); return true; }
Example 11
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 12
Source File: EffOpenInventory.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) { int openFlag = 0; if(parseResult.mark >= 7) { openFlag = parseResult.mark ^ 7; invType = DISPENSER; } else if(parseResult.mark >= 6) { openFlag = parseResult.mark ^ 6; invType = DROPPER; } else if(parseResult.mark >= 5) { openFlag = parseResult.mark ^ 5; invType = HOPPER; } else if (parseResult.mark >= 4) { openFlag = parseResult.mark ^ 4; invType = ANVIL; } else if (parseResult.mark >= 3) { openFlag = parseResult.mark ^ 3; invType = CHEST; } else if (parseResult.mark >= 2) { invType = WORKBENCH; openFlag = parseResult.mark ^ 2; } else { openFlag = parseResult.mark; } open = matchedPattern == 0; invi = open ? (Expression<Inventory>) exprs[0] : null; players = (Expression<Player>) exprs[exprs.length - 1]; if (openFlag == 1 && invi != null) { Skript.warning("Using 'show' inventory instead of 'open' is not recommended as it will eventually show an unmodifiable view of the inventory in the future."); } return true; }
Example 13
Source File: EvtSkript.java From Skript with GNU General Public License v3.0 | 5 votes |
@Override public boolean init(final Literal<?>[] args, final int matchedPattern, final ParseResult parser) { isStart = matchedPattern == 0; if (parser.mark == 0) { Skript.warning("Server start/stop events are actually called when Skript is started or stopped. It is thus recommended to use 'on Skript start/stop' instead."); } return true; }
Example 14
Source File: EvtClick.java From Skript with GNU General Public License v3.0 | 5 votes |
@Override public boolean init(final Literal<?>[] args, final int matchedPattern, final ParseResult parser) { click = parser.mark == 0 ? ANY : parser.mark; types = args[matchedPattern]; if (types != null && !ItemType.class.isAssignableFrom(types.getReturnType())) { if (click == LEFT) { Skript.error("A leftclick on an entity is an attack and thus not covered by the 'click' event, but the 'damage' event.", ErrorQuality.SEMANTIC_ERROR); return false; } else if (click == ANY) { Skript.warning("A leftclick on an entity is an attack and thus not covered by the 'click' event, but the 'damage' event. Change this event to a rightclick to disable this warning message."); } } tools = (Literal<ItemType>) args[1 - matchedPattern]; return true; }
Example 15
Source File: Config.java From Skript with GNU General Public License v3.0 | 5 votes |
public Config(final InputStream source, final String fileName, @Nullable final File file, final boolean simple, final boolean allowEmptySections, final String defaultSeparator) throws IOException { try { this.fileName = fileName; if (file != null) // Must check for null before converting to path this.file = file.toPath(); this.simple = simple; this.allowEmptySections = allowEmptySections; this.defaultSeparator = defaultSeparator; separator = defaultSeparator; if (source.available() == 0) { main = new SectionNode(this); Skript.warning("'" + getFileName() + "' is empty"); return; } if (Skript.logVeryHigh()) Skript.info("loading '" + fileName + "'"); final ConfigReader r = new ConfigReader(source); try { main = SectionNode.load(this, r); } finally { r.close(); } } finally { source.close(); } }
Example 16
Source File: ExprItemsIn.java From Skript with GNU General Public License v3.0 | 5 votes |
@SuppressWarnings({"unchecked", "null"}) @Override /* * the parse result will be null if it is used via the ExprInventory expression, however the expression will never * be a variable when used with that expression (it is always a anonymous SimpleExpression) */ public boolean init(final Expression<?>[] exprs, final int matchedPattern, final Kleenean isDelayed, @Nullable final ParseResult parseResult) { invis = (Expression<Inventory>) exprs[0]; if (invis instanceof Variable && !invis.isSingle() && parseResult.mark != 1) Skript.warning("'items in {variable::*}' does not actually represent the items stored in the variable. Use either '{variable::*}' (e.g. 'loop {variable::*}') if the variable contains items, or 'items in inventories {variable::*}' if the variable contains inventories."); return true; }
Example 17
Source File: BukkitUnsafe.java From Skript with GNU General Public License v3.0 | 5 votes |
public static void modifyItemStack(ItemStack stack, String arguments) { try { unsafe.modifyItemStack(stack, arguments); } catch (NullPointerException e) { if (knownNullPtr) { // Probably known Spigot bug // So we continue doing whatever we were doing and hope it works Skript.warning("Item " + stack.getType() + arguments + " failed modifyItemStack. This is a bug on old Spigot versions."); } else { // Not known null pointer, don't just swallow throw e; } } }
Example 18
Source File: EquipmentSlot.java From Skript with GNU General Public License v3.0 | 5 votes |
@Override public void set(EntityEquipment e, @Nullable ItemStack item) { if (Skript.isRunningMinecraft(1, 9)) { e.setItemInOffHand(item); } else { Skript.warning("No off hand support, but a skript would need that!"); } }
Example 19
Source File: Parameter.java From Skript with GNU General Public License v3.0 | 4 votes |
@SuppressWarnings("unchecked") @Nullable public static <T> Parameter<T> newInstance(final String name, final ClassInfo<T> type, final boolean single, final @Nullable String def) { if (!Variable.isValidVariableName(name, true, false)) { Skript.error("An argument's name must be a valid variable name."); // ... because it will be made available as local variable return null; } Expression<? extends T> d = null; if (def != null) { // if (def.startsWith("%") && def.endsWith("%")) { // final RetainingLogHandler log = SkriptLogger.startRetainingLog(); // try { // d = new SkriptParser("" + def.substring(1, def.length() - 1), SkriptParser.PARSE_EXPRESSIONS, ParseContext.FUNCTION_DEFAULT).parseExpression(type.getC()); // if (d == null) { // log.printErrors("Can't understand this expression: " + def + ""); // return null; // } // log.printLog(); // } finally { // log.stop(); // } // } else { final RetainingLogHandler log = SkriptLogger.startRetainingLog(); // Parse the default value literal try { if (def.startsWith("\"") && def.endsWith("\"")) { // Quoted string; always parse as string // Don't ever parse strings as objects, it creates UnparsedLiterals (see #2353) d = (Expression<? extends T>) VariableString.newInstance("" + def.substring(1, def.length() - 1)); } else if (type.getC().equals(String.class)) { // String return type requested /* * For historical reasons, default values of string * parameters needs not to be quoted. This is true even for * strings with spaces, which is very confusing. We issue a * warning for it now, and the behavior may be removed in a * future release. */ if (def.startsWith("\"") && def.endsWith("\"")) { d = (Expression<? extends T>) VariableString.newInstance("" + def.substring(1, def.length() - 1)); } else { // Usage of SimpleLiteral is also deprecated; not worth the risk to change it if (def.contains(" ")) // Warn about whitespace in unquoted string Skript.warning("'" + def + "' contains spaces and is unquoted, which is discouraged"); d = (Expression<? extends T>) new SimpleLiteral<>(def, false); } } else { d = new SkriptParser(def, SkriptParser.PARSE_LITERALS, ParseContext.DEFAULT).parseExpression(type.getC()); } if (d == null) { log.printErrors("'" + def + "' is not " + type.getName().withIndefiniteArticle()); return null; } log.printLog(); } finally { log.stop(); } // } } return new Parameter<>(name, type, single, d); }
Example 20
Source File: Variable.java From Skript with GNU General Public License v3.0 | 4 votes |
/** * Checks whether a string is a valid variable name. This is used to verify variable names as well as command and function arguments. * * @param name The name to test * @param allowListVariable Whether to allow a list variable * @param printErrors Whether to print errors when they are encountered * @return true if the name is valid, false otherwise. */ public static boolean isValidVariableName(String name, final boolean allowListVariable, final boolean printErrors) { name = name.startsWith(LOCAL_VARIABLE_TOKEN) ? "" + name.substring(LOCAL_VARIABLE_TOKEN.length()).trim() : "" + name.trim(); if (!allowListVariable && name.contains(SEPARATOR)) { if (printErrors) Skript.error("List variables are not allowed here (error in variable {" + name + "})"); return false; } else if (name.startsWith(SEPARATOR) || name.endsWith(SEPARATOR)) { if (printErrors) Skript.error("A variable's name must neither start nor end with the separator '" + SEPARATOR + "' (error in variable {" + name + "})"); return false; } else if (name.contains("*") && (!allowListVariable || name.indexOf("*") != name.length() - 1 || !name.endsWith(SEPARATOR + "*"))) { List<Integer> asterisks = new ArrayList<>(); List<Integer> percents = new ArrayList<>(); for (int i = 0; i < name.length(); i++) { char c = name.charAt(i); if (c == '*') asterisks.add(i); else if (c == '%') percents.add(i); } int count = asterisks.size(); int index = 0; for (int i = 0; i < percents.size(); i += 2) { if (index == asterisks.size() || i+1 == percents.size()) // Out of bounds break; int lb = percents.get(i), ub = percents.get(i+1); // Continually decrement asterisk count by checking if any asterisks in current range while (index < asterisks.size() && lb < asterisks.get(index) && asterisks.get(index) < ub) { count--; index++; } } if (!(count == 0 || (count == 1 && name.endsWith(SEPARATOR + "*")))) { if (printErrors) { if (name.indexOf("*") == 0) Skript.error("[2.0] Local variables now start with an underscore, e.g. {_local variable}. The asterisk is reserved for list variables. (error in variable {" + name + "})"); else Skript.error("A variable's name must not contain any asterisks except at the end after '" + SEPARATOR + "' to denote a list variable, e.g. {variable" + SEPARATOR + "*} (error in variable {" + name + "})"); } return false; } } else if (name.contains(SEPARATOR + SEPARATOR)) { if (printErrors) Skript.error("A variable's name must not contain the separator '" + SEPARATOR + "' multiple times in a row (error in variable {" + name + "})"); return false; } else if (name.replace(SEPARATOR, "").contains(SINGLE_SEPARATOR_CHAR)) { if (printErrors) Skript.warning("If you meant to make the variable {" + name + "} a list, its name should contain '" + SEPARATOR + "'. Having a single '" + SINGLE_SEPARATOR_CHAR + "' does nothing!"); } return true; }