Skip to content

Commit 2f31772

Browse files
committed
And some more bug fixes...
1 parent ccc9e5e commit 2f31772

File tree

5 files changed

+58
-8
lines changed

5 files changed

+58
-8
lines changed

src/main/java/ch/njol/skript/SkriptConfig.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,8 @@ public EventPriority convert(final String s) {
151151
public final static Option<Integer> maxTargetBlockDistance = new Option<Integer>("maximum target block distance", 100);
152152

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

156157
public final static Option<Boolean> disableVariableConflictWarnings = new Option<Boolean>("disable variable conflict warnings", false);
157158
public final static Option<Boolean> disableObjectCannotBeSavedWarnings = new Option<Boolean>("disable variable will not be saved warnings", false);

src/main/java/ch/njol/skript/classes/data/DefaultConverters.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121

2222
package ch.njol.skript.classes.data;
2323

24+
import java.util.Collection;
25+
2426
import org.bukkit.Location;
2527
import org.bukkit.Material;
2628
import org.bukkit.OfflinePlayer;
@@ -38,6 +40,7 @@
3840
import org.eclipse.jdt.annotation.Nullable;
3941

4042
import ch.njol.skript.aliases.ItemType;
43+
import ch.njol.skript.bukkitutil.PlayerUtils;
4144
import ch.njol.skript.classes.Converter;
4245
import ch.njol.skript.entity.EntityData;
4346
import ch.njol.skript.entity.EntityType;
@@ -289,5 +292,21 @@ public EnchantmentType convert(final Enchantment e) {
289292
}
290293
});
291294

295+
// // Entity - String (UUID) // Very slow, thus disabled for now
296+
// Converters.registerConverter(String.class, Entity.class, new Converter<String, Entity>() {
297+
//
298+
// @Override
299+
// @Nullable
300+
// public Entity convert(String f) {
301+
// Collection<? extends Player> players = PlayerUtils.getOnlinePlayers();
302+
// for (Player p : players) {
303+
// if (p.getName().equals(f) || p.getUniqueId().toString().equals(f))
304+
// return p;
305+
// }
306+
//
307+
// return null;
308+
// }
309+
//
310+
// });
292311
}
293312
}

src/main/java/ch/njol/skript/events/EvtClick.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,8 @@ public static boolean checkUseOffHand(Player player, int clickType, @Nullable Bl
313313
case STONE_BUTTON:
314314
case COMMAND:
315315
case ITEM_FRAME:
316+
case SIGN_POST:
317+
case WALL_SIGN: // 2 signs...
316318
blockUsable = true;
317319
break;
318320
case CAKE_BLOCK:
@@ -357,7 +359,7 @@ public static boolean checkUseOffHand(Player player, int clickType, @Nullable Bl
357359

358360
// Still not returned?
359361
if (mainHand.getType() != Material.AIR) return false;
360-
//Skript.info("Main hand is an item.");
362+
//Skript.info("Main hand is not item.");
361363
if (offHand.getType() != Material.AIR) return true;
362364

363365
//Skript.info("Final return!");

src/main/java/ch/njol/skript/lang/function/Functions.java

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,14 +98,19 @@ final static void registerCaller(final FunctionReference<?> r) {
9898
private final static Pattern functionPattern = Pattern.compile("function (" + functionNamePattern + ")\\((.*)\\)(?: :: (.+))?", Pattern.CASE_INSENSITIVE),
9999
paramPattern = Pattern.compile("\\s*(.+?)\\s*:\\s*(.+?)(?:\\s*=\\s*(.+))?\\s*");
100100

101+
/**
102+
* Loads a function from given node.
103+
* @param node Section node.
104+
* @return Script function, or null if something went wrong.
105+
*/
101106
@SuppressWarnings("unchecked")
102107
@Nullable
103108
public final static Function<?> loadFunction(final SectionNode node) {
104109
SkriptLogger.setNode(node);
105110
final String definition = node.getKey();
106111
assert definition != null;
107112
final Matcher m = functionPattern.matcher(definition);
108-
if (!m.matches()) // We have checks when loading the signature
113+
if (!m.matches()) // We have checks when loading the signature, but matches() must be called anyway
109114
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.");
110115
final String name = "" + m.group(1);
111116
Signature<?> sign = signatures.get(name);
@@ -122,6 +127,12 @@ public final static Function<?> loadFunction(final SectionNode node) {
122127
return f;
123128
}
124129

130+
/**
131+
* Loads the signature of function from given node.
132+
* @param script Script file name (<b>might</b> be used for some checks).
133+
* @param node Section node.
134+
* @return Signature of function, or null if something went wrong.
135+
*/
125136
@Nullable
126137
public static Signature<?> loadSignature(String script, final SectionNode node) {
127138
SkriptLogger.setNode(node);
@@ -185,18 +196,35 @@ public static Signature<?> loadSignature(String script, final SectionNode node)
185196
return sign;
186197
}
187198

199+
/**
200+
* Creates an error and returns Function null.
201+
* @param error Error message.
202+
* @return Null.
203+
*/
188204
@Nullable
189205
private final static Function<?> error(final String error) {
190206
Skript.error(error);
191207
return null;
192208
}
193209

210+
/**
211+
* Creates an error and returns Signature null.
212+
* @param error Error message.
213+
* @return Null.
214+
*/
194215
@Nullable
195216
private final static Signature<?> signError(final String error) {
196217
Skript.error(error);
197218
return null;
198219
}
199220

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

236+
/**
237+
* Gets a signature of function with given name
238+
* @param name Name of function.
239+
* @return Signature, or null if function does not exist.
240+
*/
208241
@Nullable
209242
public final static Signature<?> getSignature(final String name) {
210243
return signatures.get(name);

src/main/resources/config.sk

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -145,11 +145,6 @@ case sensitive: false
145145
# This e.g. applies to the effect 'replace' and the conditions 'contains' and 'is/is not'.
146146
# Variable names are case-insensitive irrespective of this setting.
147147

148-
allow function calls before definations: false
149-
# Whether scripts should be allowed to call functions that are not yet defined.
150-
# If enabled, functions' existences are checked after loading ALL scripts.
151-
# Warning: Unless you have text editor with good directory-search, it can be hard to find your functions!
152-
153148
disable variable conflict warnings: false
154149
# Disables warnings of potential variable name conflicts if set to true.
155150
# I recommend to not touch this option, but if you do so you should at least set it back to false

0 commit comments

Comments
 (0)