Skip to content

Commit d98acc7

Browse files
committed
Finish remaining syntax
1 parent 91d1faf commit d98acc7

23 files changed

Lines changed: 318 additions & 347 deletions

src/main/java/org/skriptlang/skript/bukkit/spawners/elements/conditions/CondIsActivated.java

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import org.bukkit.block.data.type.TrialSpawner.State;
77
import org.skriptlang.skript.bukkit.spawners.SpawnerModule;
88
import org.skriptlang.skript.bukkit.spawners.util.SpawnerUtils;
9+
import org.skriptlang.skript.registration.SyntaxRegistry;
910

1011
@Name("Spawner - Is Active")
1112
@Description(
@@ -18,22 +19,28 @@
1819
"\tsend \"The spawner is activated!\""
1920
})
2021
@Since("INSERT VERSION")
21-
@RequiredPlugins("MC 1.21+")
22+
@RequiredPlugins("Minecraft 1.21+ (for trial spawners, spawner minecarts)")
2223
public class CondIsActivated extends PropertyCondition<Object> {
2324

24-
static {
25-
register(SpawnerModule.SYNTAX_REGISTRY, CondIsActivated.class,
26-
"[an] (activated|active) spawner", "blocks/entities/trialspawnerconfigs");
25+
public static void register(SyntaxRegistry registry) {
26+
registry.register(SyntaxRegistry.CONDITION, infoBuilder(CondIsActivated.class, PropertyType.BE,
27+
"[an] (activated|active) spawner", SpawnerUtils.spawnerPropertyType)
28+
.supplier(CondIsActivated::new)
29+
.build()
30+
);
2731
}
2832

2933
@Override
3034
public boolean check(Object object) {
31-
if (SpawnerUtils.isSpawner(object)) {
32-
return SpawnerUtils.getAsSkriptSpawner(object).isActivated();
35+
if (SpawnerUtils.isCreatureSpawner(object)) {
36+
return SpawnerUtils.getCreatureSpawner(object).isActivated();
37+
} else if (SpawnerUtils.isSpawnerMinecart(object)) {
38+
return SpawnerUtils.getSpawnerMinecart(object).isActivated();
3339
} else if (SpawnerUtils.isTrialSpawner(object)) {
34-
TrialSpawner data = ((TrialSpawner) SpawnerUtils.getAsSkriptTrialSpawner(object).getBlockData());
35-
return data.getTrialSpawnerState() == State.ACTIVE;
40+
TrialSpawner trialSpawner = (TrialSpawner) SpawnerUtils.getTrialSpawner(object).getBlockData();
41+
return trialSpawner.getTrialSpawnerState() == State.ACTIVE;
3642
}
43+
3744
return false;
3845
}
3946

src/main/java/org/skriptlang/skript/bukkit/spawners/elements/conditions/CondIsOminous.java

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@
22

33
import ch.njol.skript.conditions.base.PropertyCondition;
44
import ch.njol.skript.doc.*;
5-
import org.bukkit.block.Block;
65
import org.bukkit.block.TrialSpawner;
7-
import org.skriptlang.skript.bukkit.spawners.SpawnerModule;
8-
import org.skriptlang.skript.bukkit.spawners.util.TrialSpawnerConfig;
6+
import org.skriptlang.skript.bukkit.spawners.util.SpawnerUtils;
7+
import org.skriptlang.skript.registration.SyntaxRegistry;
98

109
@Name("Trial Spawner - Is Ominous")
1110
@Description(
@@ -20,23 +19,27 @@
2019
"\tsend \"That's true! The config is not ominous.\""
2120
})
2221
@Since("INSERT VERSION")
23-
@RequiredPlugins("MC 1.21+")
22+
@RequiredPlugins("Minecraft 1.21+")
2423
public class CondIsOminous extends PropertyCondition<Object> {
2524

26-
static {
27-
register(SpawnerModule.SYNTAX_REGISTRY, CondIsOminous.class,
28-
"ominous", "trialspawnerconfigs/blocks/blockdatas");
25+
public static void register(SyntaxRegistry registry) {
26+
if (!SpawnerUtils.IS_RUNNING_1_21)
27+
return;
28+
registry.register(SyntaxRegistry.CONDITION, infoBuilder(CondIsOminous.class, PropertyType.BE,
29+
"ominous", "blocks/blockdatas")
30+
.supplier(CondIsOminous::new)
31+
.build()
32+
);
2933
}
3034

3135
@Override
3236
public boolean check(Object object) {
33-
if (object instanceof TrialSpawnerConfig config) {
34-
return config.ominous();
35-
} else if (object instanceof Block block && block.getState() instanceof TrialSpawner spawner) {
36-
return spawner.isOminous();
37+
if (SpawnerUtils.isTrialSpawner(object)) {
38+
return SpawnerUtils.getTrialSpawner(object).isOminous();
3739
} else if (object instanceof org.bukkit.block.data.type.TrialSpawner spawner) {
3840
return spawner.isOminous();
3941
}
42+
4043
return false;
4144
}
4245

src/main/java/org/skriptlang/skript/bukkit/spawners/elements/conditions/CondIsTracking.java

Lines changed: 40 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
package org.skriptlang.skript.bukkit.spawners.elements.conditions;
22

3+
import ch.njol.skript.conditions.base.PropertyCondition;
34
import ch.njol.skript.doc.*;
45
import ch.njol.skript.lang.Condition;
56
import ch.njol.skript.lang.Expression;
67
import ch.njol.skript.lang.SkriptParser.ParseResult;
78
import ch.njol.skript.lang.SyntaxStringBuilder;
9+
import ch.njol.skript.lang.util.SimpleExpression;
810
import ch.njol.util.Kleenean;
11+
import org.bukkit.block.Block;
912
import org.bukkit.block.TrialSpawner;
1013
import org.bukkit.entity.Entity;
1114
import org.bukkit.entity.Player;
@@ -29,72 +32,71 @@
2932
"\tsend \"indeed! you are being tracked..\""
3033
})
3134
@Since("INSERT VERSION")
32-
@RequiredPlugins("MC 1.21+")
35+
@RequiredPlugins("Minecraft 1.21+")
3336
public class CondIsTracking extends Condition {
3437

35-
static {
36-
var info = SyntaxInfo.builder(CondIsTracking.class)
37-
.origin(SyntaxOrigin.of(SpawnerModule.ADDON))
38+
public static void register(SyntaxRegistry registry) {
39+
registry.register(SyntaxRegistry.CONDITION, SyntaxInfo.builder(CondIsTracking.class)
3840
.supplier(CondIsTracking::new)
3941
.priority(SyntaxInfo.COMBINED)
4042
.addPatterns(
41-
"%block/trialspawnerconfig% (is|are) [trial] spawner entity tracking %entities%",
42-
"%block/trialspawnerconfig% (is|are) [trial] spawner player tracking %players%",
43-
"%block/trialspawnerconfig% (isn't|is not|aren't|are not) [trial] spawner entity tracking %entities%",
44-
"%block/trialspawnerconfig% (isn't|is not|aren't|are not) [trial] spawner player tracking %entities%")
45-
.build();
46-
47-
SpawnerModule.SYNTAX_REGISTRY.register(SyntaxRegistry.CONDITION, info);
43+
"%blocks% (is|are) player tracking %players%",
44+
"%blocks% (isn't|is not|aren't|are not) player tracking %players%",
45+
"%blocks% (is|are) entity tracking %entities%",
46+
"%blocks% (isn't|is not|aren't|are not) entity tracking %entities%")
47+
.build()
48+
);
4849
}
4950

50-
private Expression<?> spawner, entities;
51+
private Expression<Block> spawners;
52+
private Expression<Entity> entities;
5153
private boolean player;
5254

5355
@Override
5456
public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) {
55-
if (matchedPattern == 0 || matchedPattern == 2) {
56-
spawner = exprs[0];
57-
entities = exprs[1];
58-
} else {
59-
spawner = exprs[1];
60-
entities = exprs[0];
61-
}
62-
player = matchedPattern == 1 || matchedPattern == 3;
63-
setNegated(matchedPattern > 1);
57+
//noinspection unchecked
58+
spawners = (Expression<Block>) exprs[0];
59+
//noinspection unchecked
60+
entities = (Expression<Entity>) exprs[1];
61+
player = matchedPattern < 2;
62+
setNegated(matchedPattern == 1 || matchedPattern == 3);
6463
return true;
6564
}
6665

6766
@Override
6867
public boolean check(Event event) {
69-
Object object = this.spawner.getSingle(event);
70-
if (object == null)
71-
return isNegated();
72-
73-
if (!SpawnerUtils.isTrialSpawner(object))
74-
return isNegated();
68+
return spawners.check(event, block -> {
69+
if (!SpawnerUtils.isTrialSpawner(block))
70+
return false;
7571

76-
TrialSpawner spawner = SpawnerUtils.getAsSkriptTrialSpawner(object);
72+
TrialSpawner spawner = SpawnerUtils.getTrialSpawner(block);
7773

78-
assert spawner != null;
74+
return entities.check(event, entity -> {
75+
if (player) {
76+
return spawner.isTrackingPlayer((Player) entity);
77+
} else {
78+
return spawner.isTrackingEntity(entity);
79+
}
80+
});
7981

80-
return entities.check(event, entity -> {
81-
if (player) {
82-
return spawner.isTrackingPlayer((Player) entity);
83-
} else {
84-
return spawner.isTrackingEntity((Entity) entity);
85-
}
8682
}, isNegated());
8783
}
8884

8985
@Override
9086
public String toString(@Nullable Event event, boolean debug) {
9187
SyntaxStringBuilder builder = new SyntaxStringBuilder(event, debug);
9288

93-
builder.append(spawner);
89+
builder.append(spawners);
9490
if (isNegated()) {
95-
builder.append("isn't tracking");
91+
builder.append("aren't");
92+
} else {
93+
builder.append("are");
94+
}
95+
96+
if (player) {
97+
builder.append("player tracking");
9698
} else {
97-
builder.append("is tracking");
99+
builder.append("entity tracking");
98100
}
99101
builder.append(entities);
100102

src/main/java/org/skriptlang/skript/bukkit/spawners/elements/effects/EffEjectReward.java

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import ch.njol.skript.lang.Expression;
66
import ch.njol.skript.lang.SkriptParser.ParseResult;
77
import ch.njol.util.Kleenean;
8+
import org.bukkit.block.Block;
89
import org.bukkit.block.data.type.TrialSpawner;
910
import org.bukkit.block.data.type.TrialSpawner.State;
1011
import org.bukkit.event.Event;
@@ -19,37 +20,36 @@
1920
@Description("Make a trial spawner or a trial spawner configuration eject a reward out of it.")
2021
@Examples("eject the trial spawner rewards of target block")
2122
@Since("INSERT VERSION")
22-
@RequiredPlugins("MC 1.21+")
23+
@RequiredPlugins("Minecraft 1.21+")
2324
public class EffEjectReward extends Effect {
2425

25-
static {
26-
var info = SyntaxInfo.builder(EffEjectReward.class)
27-
.origin(SyntaxOrigin.of(SpawnerModule.ADDON))
26+
public static void register(SyntaxRegistry registry) {
27+
registry.register(SyntaxRegistry.EFFECT, SyntaxInfo.builder(EffEjectReward.class)
2828
.supplier(EffEjectReward::new)
2929
.priority(SyntaxInfo.COMBINED)
3030
.addPatterns(
31-
"eject [the] trial spawner reward[s] of %blocks/trialspawnerconfigs%",
32-
"eject [the] %blocks/trialspawnerconfigs%'[s] trial spawner reward[s]")
33-
.build();
34-
35-
SpawnerModule.SYNTAX_REGISTRY.register(SyntaxRegistry.EFFECT, info);
31+
"(spit out|eject) [the] trial reward[s] of %blocks%",
32+
"(spit out|eject) %blocks%'[s] trial reward[s]")
33+
.build()
34+
);
3635
}
3736

38-
private Expression<?> objects;
37+
private Expression<Block> blocks;
3938

4039
@Override
4140
public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) {
42-
objects = exprs[0];
41+
//noinspection unchecked
42+
blocks = (Expression<Block>) exprs[0];
4343
return true;
4444
}
4545

4646
@Override
4747
protected void execute(Event event) {
48-
for (Object object : objects.getArray(event)) {
49-
if (!SpawnerUtils.isTrialSpawner(object))
48+
for (Block block : blocks.getArray(event)) {
49+
if (!SpawnerUtils.isTrialSpawner(block))
5050
continue;
5151

52-
org.bukkit.block.TrialSpawner state = SpawnerUtils.getAsSkriptTrialSpawner(object);
52+
org.bukkit.block.TrialSpawner state = SpawnerUtils.getTrialSpawner(block);
5353
TrialSpawner data = (TrialSpawner) state.getBlockData();
5454

5555
data.setTrialSpawnerState(State.EJECTING_REWARD);
@@ -60,7 +60,7 @@ protected void execute(Event event) {
6060

6161
@Override
6262
public String toString(@Nullable Event event, boolean debug) {
63-
return "eject trial spawner rewards from " + objects.toString(event, debug);
63+
return "spit out the trial rewards of " + blocks.toString(event, debug);
6464
}
6565

6666
}

src/main/java/org/skriptlang/skript/bukkit/spawners/elements/effects/EffMakeOminous.java

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import org.bukkit.event.Event;
1313
import org.jetbrains.annotations.Nullable;
1414
import org.skriptlang.skript.bukkit.spawners.SpawnerModule;
15+
import org.skriptlang.skript.bukkit.spawners.util.SpawnerUtils;
1516
import org.skriptlang.skript.registration.SyntaxInfo;
1617
import org.skriptlang.skript.registration.SyntaxOrigin;
1718
import org.skriptlang.skript.registration.SyntaxRegistry;
@@ -25,18 +26,18 @@
2526
"\tmake the trial spawner state of event-block ominous"
2627
})
2728
@Since("INSERT VERSION")
28-
@RequiredPlugins("MC 1.21+")
29+
@RequiredPlugins("Minecraft 1.21+")
2930
public class EffMakeOminous extends Effect {
3031

31-
static {
32-
var info = SyntaxInfo.builder(EffMakeOminous.class)
33-
.origin(SyntaxOrigin.of(SpawnerModule.ADDON))
32+
public static void register(SyntaxRegistry registry) {
33+
if (!SpawnerUtils.IS_RUNNING_1_21)
34+
return;
35+
registry.register(SyntaxRegistry.EFFECT, SyntaxInfo.builder(EffMakeOminous.class)
3436
.supplier(EffMakeOminous::new)
3537
.priority(SyntaxInfo.COMBINED)
36-
.addPatterns("make [the] trial spawner state of %blocks/blockdatas% (:ominous|normal)")
37-
.build();
38-
39-
SpawnerModule.SYNTAX_REGISTRY.register(SyntaxRegistry.EFFECT, info);
38+
.addPatterns("make %blocks/blockdatas% (:ominous|regular|normal)")
39+
.build()
40+
);
4041
}
4142

4243
private boolean ominous;
@@ -65,11 +66,11 @@ protected void execute(Event event) {
6566
public String toString(@Nullable Event event, boolean debug) {
6667
SyntaxStringBuilder builder = new SyntaxStringBuilder(event, debug);
6768

68-
builder.append("make the trial spawner state of", spawners);
69+
builder.append("make", spawners);
6970
if (ominous) {
7071
builder.append("ominous");
7172
} else {
72-
builder.append("regular");
73+
builder.append("normal");
7374
}
7475

7576
return builder.toString();
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
package org.skriptlang.skript.bukkit.spawners.elements.effects;
2+
3+
import ch.njol.skript.lang.Effect;
4+
import ch.njol.skript.lang.Expression;
5+
import ch.njol.skript.lang.SkriptParser.ParseResult;
6+
import ch.njol.util.Kleenean;
7+
import org.bukkit.block.CreatureSpawner;
8+
import org.bukkit.entity.minecart.SpawnerMinecart;
9+
import org.bukkit.event.Event;
10+
import org.bukkit.inventory.ItemStack;
11+
import org.jetbrains.annotations.Nullable;
12+
import org.skriptlang.skript.bukkit.spawners.util.SpawnerUtils;
13+
import org.skriptlang.skript.registration.SyntaxInfo;
14+
import org.skriptlang.skript.registration.SyntaxRegistry;
15+
16+
public class EffSpawnerItem extends Effect {
17+
18+
public static void register(SyntaxRegistry registry) {
19+
registry.register(SyntaxRegistry.EFFECT, SyntaxInfo.builder(EffSpawnerItem.class)
20+
.supplier(EffSpawnerItem::new)
21+
.priority(SyntaxInfo.COMBINED)
22+
.addPatterns(
23+
"make " + SpawnerUtils.spawnerPropertyType + " spawn %itemstack%",
24+
"force " + SpawnerUtils.spawnerPropertyType + " to spawn %itemstack%")
25+
.build()
26+
);
27+
}
28+
29+
private Expression<?> spawners;
30+
private Expression<ItemStack> itemStack;
31+
32+
@Override
33+
public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) {
34+
spawners = exprs[0];
35+
//noinspection unchecked
36+
itemStack = (Expression<ItemStack>) exprs[1];
37+
return true;
38+
}
39+
40+
@Override
41+
protected void execute(Event event) {
42+
ItemStack item = itemStack.getSingle(event);
43+
if (item == null)
44+
return;
45+
46+
for (Object object : spawners.getArray(event)) {
47+
if (SpawnerUtils.isCreatureSpawner(object)) {
48+
CreatureSpawner spawner = SpawnerUtils.getCreatureSpawner(object);
49+
spawner.setSpawnedItem(item);
50+
spawner.update(true, false);
51+
} else if (SpawnerUtils.isSpawnerMinecart(object)) {
52+
SpawnerMinecart minecart = SpawnerUtils.getSpawnerMinecart(object);
53+
minecart.setSpawnedItem(item);
54+
}
55+
}
56+
}
57+
58+
@Override
59+
public String toString(@Nullable Event event, boolean debug) {
60+
return "force " + spawners.toString(event, debug) + " to spawn " + itemStack.toString(event, debug);
61+
}
62+
63+
}

0 commit comments

Comments
 (0)