Skip to content

Commit ce35bde

Browse files
committed
Merge branch 'master' of https://github.com/bensku/Skript
2 parents eddf56a + 69f3df9 commit ce35bde

13 files changed

+406
-265
lines changed

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

Lines changed: 22 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -230,8 +230,8 @@ public boolean accept(final @Nullable File f) {
230230
/**
231231
* Loads the specified scripts.
232232
*
233-
* @param configs
234-
* @return Info on the loaded scripts
233+
* @param configs Configs for scripts, loaded by {@link #loadStructures(File[])}
234+
* @return Info on the loaded scripts.
235235
*/
236236
public final static ScriptInfo loadScripts(final List<Config> configs) {
237237
Collections.sort(configs);
@@ -256,8 +256,25 @@ public final static ScriptInfo loadScripts(final List<Config> configs) {
256256
return i;
257257
}
258258

259+
/**
260+
* Loads the specified scripts.
261+
*
262+
* @param configs Configs for scripts, loaded by {@link #loadStructure(File)}
263+
* @return Info on the loaded scripts
264+
*/
265+
@SuppressWarnings("null")
266+
public final static ScriptInfo loadScripts(final Config... configs) {
267+
return loadScripts(Arrays.asList(configs));
268+
}
269+
270+
/**
271+
* Loads one script. Only for internal use, as this doesn't register/update
272+
* event handlers.
273+
* @param config Config for script to be loaded.
274+
* @return Info about script that is loaded
275+
*/
259276
@SuppressWarnings("unchecked")
260-
final static ScriptInfo loadScript(final @Nullable Config config) {
277+
private final static ScriptInfo loadScript(final @Nullable Config config) {
261278
if (config == null) { // Something bad happened, hopefully got logged to console
262279
return new ScriptInfo();
263280
}
@@ -457,31 +474,6 @@ public String run(final Matcher m) {
457474
numErrors.stop();
458475
}
459476

460-
// if (SkriptConfig.enableScriptCaching.value() && cache != null) {
461-
// if (numErrors.getCount() > 0) {
462-
// ObjectOutputStream out = null;
463-
// try {
464-
// cache.getParentFile().mkdirs();
465-
// out = new ObjectOutputStream(new FileOutputStream(cache));
466-
// out.writeLong(f.lastModified());
467-
// out.writeObject(script);
468-
// } catch (final NotSerializableException e) {
469-
// Skript.exception(e, "Cannot cache " + f.getName());
470-
// if (out != null)
471-
// out.close();
472-
// cache.delete();
473-
// } catch (final IOException e) {
474-
// Skript.warning("Cannot cache " + f.getName() + ": " + e.getLocalizedMessage());
475-
// if (out != null)
476-
// out.close();
477-
// cache.delete();
478-
// } finally {
479-
// if (out != null)
480-
// out.close();
481-
// }
482-
// }
483-
// }
484-
485477
return new ScriptInfo(1, numTriggers, numCommands, numFunctions);
486478
} catch (final Exception e) {
487479
Skript.exception(e, "Could not load " + config.getFileName());
@@ -492,7 +484,7 @@ public String run(final Matcher m) {
492484
}
493485

494486
/**
495-
* Loads the specified scripts.
487+
* Loads structures of specified scripts.
496488
*
497489
* @param files
498490
*/
@@ -505,7 +497,6 @@ public final static List<Config> loadStructures(final File[] files) {
505497
loadedFiles.add(loadStructure(f));
506498
}
507499

508-
SkriptEventHandler.registerBukkitEvents();
509500
return loadedFiles;
510501
}
511502

@@ -538,24 +529,13 @@ public final static List<Config> loadStructures(final File directory) {
538529
public final static @Nullable Config loadStructure(final File f) {
539530
try {
540531
final Config config = new Config(f, true, false, ":");
541-
if (SkriptConfig.keepConfigsLoaded.value())
542-
SkriptConfig.configs.add(config);
543-
int numTriggers = 0;
544-
int numCommands = 0;
545-
int numFunctions = 0;
546-
547-
currentAliases.clear();
548-
currentOptions.clear();
549-
currentScript = config;
550-
551-
// final SerializedScript script = new SerializedScript();
552532

553533
final CountingLogHandler numErrors = SkriptLogger.startLogHandler(new CountingLogHandler(SkriptLogger.SEVERE));
554534

555535
try {
556536
for (final Node cnode : config.getMainNode()) {
557537
if (!(cnode instanceof SectionNode)) {
558-
Skript.error("invalid line - all code has to be put into triggers");
538+
// Don't spit error yet, we are only pre-parsing...
559539
continue;
560540
}
561541

@@ -573,9 +553,6 @@ public final static List<Config> loadStructures(final File directory) {
573553
setCurrentEvent("function", FunctionEvent.class);
574554

575555
final Signature<?> func = Functions.loadSignature(config.getFileName(), node);
576-
if (func != null) {
577-
numFunctions++;
578-
}
579556

580557
deleteCurrentEvent();
581558

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ public boolean onCommand(final @Nullable CommandSender sender, final @Nullable C
184184
reloading(sender, "script", f.getName());
185185
ScriptLoader.unloadScript(f);
186186
Config config = ScriptLoader.loadStructure(f);
187-
ScriptLoader.loadScript(config);
187+
ScriptLoader.loadScripts(config);
188188
reloaded(sender, r, "script", f.getName());
189189
} else {
190190
reloading(sender, "scripts in folder", f.getName());
@@ -232,7 +232,7 @@ public boolean onCommand(final @Nullable CommandSender sender, final @Nullable C
232232

233233
info(sender, "enable.single.enabling", f.getName());
234234
Config config = ScriptLoader.loadStructure(f);
235-
ScriptLoader.loadScript(config);
235+
ScriptLoader.loadScripts(config);
236236
if (r.numErrors() == 0) {
237237
info(sender, "enable.single.enabled", f.getName());
238238
} else {

src/main/java/ch/njol/skript/conditions/CondIsEmpty.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,13 @@ public class CondIsEmpty extends PropertyCondition<Object> {
4646
public boolean check(final Object o) {
4747
if (o instanceof String)
4848
return ((String) o).isEmpty();
49-
if (o instanceof Inventory)
50-
return !((Inventory) o).iterator().hasNext();
49+
if (o instanceof Inventory) {
50+
for (ItemStack s : ((Inventory) o).getContents()) {
51+
if (s != null && s.getType() != Material.AIR)
52+
return false; // There is an item here!
53+
}
54+
return true;
55+
}
5156
if (o instanceof Slot) {
5257
final Slot s = (Slot) o;
5358
final ItemStack i = s.getItem();

src/main/java/ch/njol/skript/effects/EffMessage.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
import java.lang.reflect.Array;
2323
import java.util.Arrays;
24+
import java.util.List;
2425

2526
import org.bukkit.command.CommandSender;
2627
import org.bukkit.conversations.Conversable;
@@ -37,7 +38,9 @@
3738
import ch.njol.skript.lang.Expression;
3839
import ch.njol.skript.lang.SkriptParser.ParseResult;
3940
import ch.njol.skript.lang.VariableString;
41+
import ch.njol.skript.util.chat.BungeeConverter;
4042
import ch.njol.skript.util.chat.ChatMessages;
43+
import ch.njol.skript.util.chat.MessageComponent;
4144
import ch.njol.util.Kleenean;
4245
import net.md_5.bungee.api.chat.BaseComponent;
4346
import net.md_5.bungee.chat.ComponentSerializer;
@@ -79,10 +82,10 @@ public boolean init(final Expression<?>[] exprs, final int matchedPattern, final
7982
protected void execute(final Event e) {
8083
assert messages != null;
8184
if (canSendRaw) {
82-
// Sadly this is essentially serializing, then deserializing, then serializing again...
83-
// TODO measure performance, potentially improve it
8485
assert messages != null;
85-
BaseComponent[] components = ComponentSerializer.parse(((VariableString) messages).toChatString(e));
86+
List<MessageComponent> componentList = ((VariableString) messages).getMessageComponents(e);
87+
@SuppressWarnings("null") // Most certainly safe, but I guess not...
88+
BaseComponent[] components = BungeeConverter.convert(componentList.toArray(new MessageComponent[componentList.size()]));
8689
for (final CommandSender s : recipients.getArray(e)) {
8790
if (s instanceof Player) { // Use JSON chat
8891
((Player) s).spigot().sendMessage(components);
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
/*
2+
* This file is part of Skript.
3+
*
4+
* Skript is free software: you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation, either version 3 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* Skript is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with Skript. If not, see <http://www.gnu.org/licenses/>.
16+
*
17+
*
18+
* Copyright 2011-2016 Peter Güttinger and contributors
19+
*
20+
*/
21+
22+
package ch.njol.skript.effects;
23+
24+
import org.bukkit.Location;
25+
import org.bukkit.SoundCategory;
26+
import org.bukkit.entity.Player;
27+
import org.bukkit.event.Event;
28+
import org.eclipse.jdt.annotation.Nullable;
29+
30+
import ch.njol.skript.Skript;
31+
import ch.njol.skript.doc.Description;
32+
import ch.njol.skript.doc.Examples;
33+
import ch.njol.skript.doc.Name;
34+
import ch.njol.skript.doc.Since;
35+
import ch.njol.skript.lang.Effect;
36+
import ch.njol.skript.lang.Expression;
37+
import ch.njol.skript.lang.SkriptParser.ParseResult;
38+
import ch.njol.util.Kleenean;
39+
40+
@Name("Play Sound")
41+
@Description("Plays a sound at given location for everyone or just for given players. Playing sounds from resource packs is supported.")
42+
@Examples("")
43+
@Since("2.2-dev28")
44+
public class EffPlaySound extends Effect {
45+
46+
static {
47+
Skript.registerEffect(EffPlaySound.class, "play sound %string% [with volume %number%] [(and|with) pitch %number%] at %location% [for %players%]");
48+
}
49+
50+
@SuppressWarnings("null")
51+
private Expression<String> sound;
52+
@Nullable
53+
private Expression<Number> volume;
54+
@Nullable
55+
private Expression<Number> pitch;
56+
57+
@SuppressWarnings("null")
58+
private Expression<Location> location;
59+
@Nullable
60+
private Expression<Player> players;
61+
62+
@SuppressWarnings({"unchecked", "null"})
63+
@Override
64+
public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) {
65+
sound = (Expression<String>) exprs[0];
66+
volume = (Expression<Number>) exprs[1];
67+
pitch = (Expression<Number>) exprs[2];
68+
location = (Expression<Location>) exprs[3];
69+
players = (Expression<Player>) exprs[4];
70+
71+
return true;
72+
}
73+
74+
@SuppressWarnings("null")
75+
@Override
76+
protected void execute(Event e) {
77+
Location l = location.getSingle(e);
78+
79+
String s = sound.getSingle(e);
80+
float vol = volume != null ? volume.getSingle(e).floatValue() : 0;
81+
float pi = pitch != null ? pitch.getSingle(e).floatValue() : 0;
82+
83+
if (players != null) {
84+
for (Player p : players.getAll(e)) {
85+
p.playSound(l, s, SoundCategory.MASTER, vol, pi);
86+
}
87+
} else {
88+
l.getWorld().playSound(l, s, vol, pi);
89+
}
90+
}
91+
92+
@Override
93+
public String toString(@Nullable Event e, boolean debug) {
94+
if (e != null)
95+
return "play sound " + sound.getSingle(e);
96+
return "play sound";
97+
}
98+
99+
}

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

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import org.bukkit.event.entity.EntityExplodeEvent;
3939
import org.bukkit.event.entity.EntityPortalEnterEvent;
4040
import org.bukkit.event.entity.EntityRegainHealthEvent;
41+
import org.bukkit.event.entity.EntityResurrectEvent;
4142
import org.bukkit.event.entity.EntityTameEvent;
4243
import org.bukkit.event.entity.EntityToggleGlideEvent;
4344
import org.bukkit.event.entity.ExplosionPrimeEvent;
@@ -397,9 +398,17 @@ public class SimpleEvents {
397398
.examples("")
398399
.since("2.2-dev21");
399400
Skript.registerEvent("Slime Split", SimpleEvent.class, SlimeSplitEvent.class, "slime split")
400-
.description("Called when slime splits.")
401+
.description("Called when a slime splits. Usually this happens when a big slime dies.")
401402
.examples("")
402403
.since("2.2-dev26");
403-
404+
if (Skript.classExists("org.bukkit.event.entity.EntityResurrectEvent")) {
405+
Skript.registerEvent("Resurrect Attempt", SimpleEvent.class, EntityResurrectEvent.class, "[entity] resurrect attempt")
406+
.description("Called when an entity dies, always. If they are not holding a totem, this is calcelled - you can, however, uncancel it.")
407+
.examples("on resurrect attempt:",
408+
" entity is player",
409+
" entity has permission \"admin.undying\"",
410+
" uncancel the event")
411+
.since("2.2-dev28");
412+
}
404413
}
405414
}

0 commit comments

Comments
 (0)