Skip to content

Commit

Permalink
And some more bug fixes...
Browse files Browse the repository at this point in the history
  • Loading branch information
bensku committed May 13, 2016
1 parent ccc9e5e commit 2f31772
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 8 deletions.
3 changes: 2 additions & 1 deletion src/main/java/ch/njol/skript/SkriptConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,8 @@ public EventPriority convert(final String s) {
public final static Option<Integer> maxTargetBlockDistance = new Option<Integer>("maximum target block distance", 100);

public final static Option<Boolean> caseSensitive = new Option<Boolean>("case sensitive", false);
public final static Option<Boolean> allowFunctionsBeforeDefs = new Option<Boolean>("allow function calls before definations", false);
public final static Option<Boolean> allowFunctionsBeforeDefs = new Option<Boolean>("allow function calls before definations", false)
.optional(true);

public final static Option<Boolean> disableVariableConflictWarnings = new Option<Boolean>("disable variable conflict warnings", false);
public final static Option<Boolean> disableObjectCannotBeSavedWarnings = new Option<Boolean>("disable variable will not be saved warnings", false);
Expand Down
19 changes: 19 additions & 0 deletions src/main/java/ch/njol/skript/classes/data/DefaultConverters.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@

package ch.njol.skript.classes.data;

import java.util.Collection;

import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.OfflinePlayer;
Expand All @@ -38,6 +40,7 @@
import org.eclipse.jdt.annotation.Nullable;

import ch.njol.skript.aliases.ItemType;
import ch.njol.skript.bukkitutil.PlayerUtils;
import ch.njol.skript.classes.Converter;
import ch.njol.skript.entity.EntityData;
import ch.njol.skript.entity.EntityType;
Expand Down Expand Up @@ -289,5 +292,21 @@ public EnchantmentType convert(final Enchantment e) {
}
});

// // Entity - String (UUID) // Very slow, thus disabled for now
// Converters.registerConverter(String.class, Entity.class, new Converter<String, Entity>() {
//
// @Override
// @Nullable
// public Entity convert(String f) {
// Collection<? extends Player> players = PlayerUtils.getOnlinePlayers();
// for (Player p : players) {
// if (p.getName().equals(f) || p.getUniqueId().toString().equals(f))
// return p;
// }
//
// return null;
// }
//
// });
}
}
4 changes: 3 additions & 1 deletion src/main/java/ch/njol/skript/events/EvtClick.java
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,8 @@ public static boolean checkUseOffHand(Player player, int clickType, @Nullable Bl
case STONE_BUTTON:
case COMMAND:
case ITEM_FRAME:
case SIGN_POST:
case WALL_SIGN: // 2 signs...
blockUsable = true;
break;
case CAKE_BLOCK:
Expand Down Expand Up @@ -357,7 +359,7 @@ public static boolean checkUseOffHand(Player player, int clickType, @Nullable Bl

// Still not returned?
if (mainHand.getType() != Material.AIR) return false;
//Skript.info("Main hand is an item.");
//Skript.info("Main hand is not item.");
if (offHand.getType() != Material.AIR) return true;

//Skript.info("Final return!");
Expand Down
35 changes: 34 additions & 1 deletion src/main/java/ch/njol/skript/lang/function/Functions.java
Original file line number Diff line number Diff line change
Expand Up @@ -98,14 +98,19 @@ final static void registerCaller(final FunctionReference<?> r) {
private final static Pattern functionPattern = Pattern.compile("function (" + functionNamePattern + ")\\((.*)\\)(?: :: (.+))?", Pattern.CASE_INSENSITIVE),
paramPattern = Pattern.compile("\\s*(.+?)\\s*:\\s*(.+?)(?:\\s*=\\s*(.+))?\\s*");

/**
* Loads a function from given node.
* @param node Section node.
* @return Script function, or null if something went wrong.
*/
@SuppressWarnings("unchecked")
@Nullable
public final static Function<?> loadFunction(final SectionNode node) {
SkriptLogger.setNode(node);
final String definition = node.getKey();
assert definition != null;
final Matcher m = functionPattern.matcher(definition);
if (!m.matches()) // We have checks when loading the signature
if (!m.matches()) // We have checks when loading the signature, but matches() must be called anyway
return error("Invalid function definition. Please check for typos and that the function's name only contains letters and underscores. Refer to the documentation for more information.");
final String name = "" + m.group(1);
Signature<?> sign = signatures.get(name);
Expand All @@ -122,6 +127,12 @@ public final static Function<?> loadFunction(final SectionNode node) {
return f;
}

/**
* Loads the signature of function from given node.
* @param script Script file name (<b>might</b> be used for some checks).
* @param node Section node.
* @return Signature of function, or null if something went wrong.
*/
@Nullable
public static Signature<?> loadSignature(String script, final SectionNode node) {
SkriptLogger.setNode(node);
Expand Down Expand Up @@ -185,18 +196,35 @@ public static Signature<?> loadSignature(String script, final SectionNode node)
return sign;
}

/**
* Creates an error and returns Function null.
* @param error Error message.
* @return Null.
*/
@Nullable
private final static Function<?> error(final String error) {
Skript.error(error);
return null;
}

/**
* Creates an error and returns Signature null.
* @param error Error message.
* @return Null.
*/
@Nullable
private final static Signature<?> signError(final String error) {
Skript.error(error);
return null;
}

/**
* Gets a function, if it exists. Note that even if function exists in scripts,
* it might not have been parsed yet. If you want to check for existance,
* then use {@link #getSignature(String)}.
* @param name Name of function.
* @return Function, or null if it does not exist.
*/
@Nullable
public final static Function<?> getFunction(final String name) {
final FunctionData d = functions.get(name);
Expand All @@ -205,6 +233,11 @@ public final static Function<?> getFunction(final String name) {
return d.function;
}

/**
* Gets a signature of function with given name
* @param name Name of function.
* @return Signature, or null if function does not exist.
*/
@Nullable
public final static Signature<?> getSignature(final String name) {
return signatures.get(name);
Expand Down
5 changes: 0 additions & 5 deletions src/main/resources/config.sk
Original file line number Diff line number Diff line change
Expand Up @@ -145,11 +145,6 @@ case sensitive: false
# This e.g. applies to the effect 'replace' and the conditions 'contains' and 'is/is not'.
# Variable names are case-insensitive irrespective of this setting.

allow function calls before definations: false
# Whether scripts should be allowed to call functions that are not yet defined.
# If enabled, functions' existences are checked after loading ALL scripts.
# Warning: Unless you have text editor with good directory-search, it can be hard to find your functions!

disable variable conflict warnings: false
# Disables warnings of potential variable name conflicts if set to true.
# I recommend to not touch this option, but if you do so you should at least set it back to false
Expand Down

0 comments on commit 2f31772

Please sign in to comment.