Skip to content

Commit 2bdbd3e

Browse files
committed
Some docs
1 parent eee7c19 commit 2bdbd3e

2 files changed

Lines changed: 49 additions & 184 deletions

File tree

src/main/java/org/skriptlang/skript/bukkit/spawners/SpawnerModule.java

Lines changed: 28 additions & 184 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,22 @@ public void init(SkriptAddon addon) {
5151
Classes.registerClass(new ClassInfo<>(SkriptSpawnerData.class, "spawnerdata")
5252
.user("spawner ?datas?")
5353
.name("Spawner Data")
54-
.description("todo")
54+
.description("""
55+
Represents the common data of a mob spawner or a trial spawner, including spawner entries, minimum \
56+
and maximum spawn delays, and more.
57+
""")
58+
.defaultExpression(new EventValueExpression<>(SkriptSpawnerData.class))
5559
.since("INSERT VERSION")
5660
);
5761

5862
Classes.registerClass(new ClassInfo<>(SkriptMobSpawnerData.class, "mobspawnerdata")
59-
.user("(mob|entity) ?spawner ?datas?")
63+
.user("mob ?spawner ?datas?")
6064
.name("Mob Spawner Data")
61-
.description("todo")
65+
.description("""
66+
Represents mob spawner data that can be contained in a monster spawner or a spawner minecart. \
67+
Additional information can be found on \
68+
<a href='https://minecraft.wiki/w/Monster_Spawner'>the Minecraft wiki page about mob spawners</a>.
69+
""")
6270
.since("INSERT VERSION")
6371
.defaultExpression(new EventValueExpression<>(SkriptMobSpawnerData.class))
6472
.parser(new Parser<>() {
@@ -83,7 +91,12 @@ public String toVariableNameString(SkriptMobSpawnerData data) {
8391
Classes.registerClass(new ClassInfo<>(SkriptTrialSpawnerData.class, "trialspawnerdata")
8492
.user("trial ?spawner ?datas?")
8593
.name("Trial Spawner Data")
86-
.description("todo")
94+
.description("""
95+
Represents the static data of a trial spawner, including details such as \
96+
activation range, reward entries, and more.
97+
Additional information can be found on \
98+
<a href='https://minecraft.wiki/w/Trial_Spawner'>the Minecraft wiki page about trial spawners</a>.
99+
""")
87100
.since("INSERT VERSION")
88101
.requiredPlugins("Minecraft 1.21+")
89102
.defaultExpression(new EventValueExpression<>(SkriptTrialSpawnerData.class))
@@ -109,7 +122,12 @@ public String toVariableNameString(SkriptTrialSpawnerData data) {
109122
Classes.registerClass(new ClassInfo<>(SkriptSpawnerEntry.class, "spawnerentry")
110123
.user("spawner ?entr(y|ies)")
111124
.name("Spawner Entry")
112-
.description("todo")
125+
.description("""
126+
A spawner entry represents what entity can spawn from a spawner, including details such as \
127+
spawn rules, spawn weight, and equipment.
128+
More information about spawner entries can be found on \
129+
<a href='https://minecraft.wiki/w/Monster_Spawner'>the Minecraft wiki page about spawners</a>
130+
""")
113131
.since("INSERT VERSION")
114132
.defaultExpression(new EventValueExpression<>(SkriptSpawnerEntry.class))
115133
.parser(new Parser<>() {
@@ -188,7 +206,11 @@ protected boolean canBeInstantiated() {
188206
Classes.registerClass(new ClassInfo<>(SpawnRule.class, "spawnrule")
189207
.user("spawn ?rules?")
190208
.name("Spawn Rule")
191-
.description("todo")
209+
.description("""
210+
Spawn rules specify the light levels required for a spawner entry to spawn. \
211+
More information can be found on \
212+
<a href='https://minecraft.wiki/w/Monster_Spawner'>the Minecraft wiki page about spawners</a>.
213+
""")
192214
.since("INSERT VERSION")
193215
.defaultExpression(new EventValueExpression<>(SpawnRule.class))
194216
.parser(new Parser<>() {
@@ -286,184 +308,6 @@ public void load(SkriptAddon addon) {
286308
})
287309
.build()
288310
.loadClasses(Skript.class, Skript.getAddonInstance().getFile());
289-
/*
290-
291-
Classes.registerClass(new ClassInfo<>(TrialSpawnerConfig.class, "trialspawnerconfig")
292-
.user("trial ?spawner ?config(urations?)?")
293-
.name("Trial Spawner Configuration")
294-
.description(
295-
"Represents a trial spawner configuration. Trial spawner configurations fall under the "
296-
+ "base spawner category, having more configuration options. When using the base spawner expressions, "
297-
+ "effects or conditions, you can use this configuration to specify the type of trial spawner you want. "
298-
+ "If you were to specify a trial spawner block in those expressions, it would use the current configuration."
299-
+ "You can find more information about this in the Minecraft wiki for "
300-
+ "<a href='https://minecraft.wiki/w/Trial_Spawner'>trial spawners</a>")
301-
.since("INSERT VERSION")
302-
.requiredPlugins("MC 1.21+")
303-
.parser(new Parser<>() {
304-
@Override
305-
public boolean canParse(ParseContext context) {
306-
return false;
307-
}
308-
309-
@Override
310-
public String toString(TrialSpawnerConfig config, int flags) {
311-
StringBuilder builder = new StringBuilder();
312-
if (config.ominous()) {
313-
builder.append("ominous ");
314-
} else {
315-
builder.append("normal ");
316-
}
317-
318-
builder.append("trial spawner config of trial spawner at ");
319-
builder.append(Classes.toString(config.state().getLocation()));
320-
321-
return builder.toString();
322-
}
323-
324-
@Override
325-
public String toVariableNameString(TrialSpawnerConfig config) {
326-
return "trial spawner configuration:" + config.hashCode();
327-
}
328-
})
329-
);
330-
331-
Classes.registerClass(new ClassInfo<>(WeightedLootTable.class, "weightedloottable")
332-
.user("weighted ?loot ?tables?")
333-
.name("Weighted Loot Table")
334-
.description(
335-
"Represents a weighted loot table. Trial spawners pick a weighted loot table to use as its reward.",
336-
"This is a weighted type. The weight expression can be used here, e.g. `weight of %weighted loot table%`")
337-
.since("INSERT VERSION")
338-
.requiredPlugins("MC 1.21+")
339-
.parser(new Parser<>() {
340-
@Override
341-
public boolean canParse(ParseContext context) {
342-
return false;
343-
}
344-
345-
public
346-
@Override String toString(WeightedLootTable reward, int flags) {
347-
return "trial spawner reward with "
348-
+ Classes.toString(reward.getLootTable())
349-
+ " and weight " + reward.spawnerWeight();
350-
}
351-
352-
@Override
353-
public String toVariableNameString(WeightedLootTable reward) {
354-
return "trial spawner reward:" + reward.getLootTable().getKey() + ',' + reward.spawnerWeight();
355-
}
356-
})
357-
);
358-
359-
Classes.registerClass(new ClassInfo<>(SpawnerEntry.class, "spawnerentry")
360-
.user("spawner ?entr(y|ies)")
361-
.name("Spawner Entry")
362-
.description("Represents a spawner entry. Spawner entries are entities that spawn from a spawner with "
363-
+ "more configuration, e.g. spawn rules, spawn weight, and equipment. You can find more information "
364-
+ "about this in the Minecraft wiki for <a href='https://minecraft.wiki/w/Monster_Spawner'>spawners</a>",
365-
"This is a weighted type. The weight expression can be used here, e.g. `weight of %spawner entry%`")
366-
.since("INSERT VERSION")
367-
.defaultExpression(new EventValueExpression<>(SpawnerEntry.class))
368-
.requiredPlugins("MC 1.21+")
369-
.parser(new Parser<>() {
370-
@Override
371-
public boolean canParse(ParseContext context) {
372-
return false;
373-
}
374-
375-
@Override
376-
public String toString(SpawnerEntry entry, int flags) {
377-
StringBuilder builder = new StringBuilder();
378-
379-
builder.append("spawner entry with ").append(Classes.toString(entry.getSnapshot()));
380-
if (entry.getSpawnRule() != null)
381-
builder.append(", ").append(Classes.toString(entry.getSpawnRule()));
382-
builder.append(" and weight ").append(entry.getSpawnWeight());
383-
384-
return builder.toString();
385-
}
386-
387-
@Override
388-
public String toVariableNameString(SpawnerEntry entry) {
389-
return "spawner entry:" + entry.getSnapshot() + ',' + entry.getSpawnRule() + ',' + entry.getSpawnWeight();
390-
}
391-
})
392-
);
393-
394-
Classes.registerClass(new ClassInfo<>(SpawnRule.class, "spawnrule")
395-
.user("spawn ?rules?")
396-
.name("Spawn Rule")
397-
.description("Represents a spawn rule. Spawn rules are used to specify the light levels required for an entity "
398-
+ "to spawn. You can find more information about this in the Minecraft wiki for "
399-
+ "<a href='https://minecraft.wiki/w/Monster_Spawner'>spawners</a>")
400-
.since("INSERT VERSION")
401-
.requiredPlugins("MC 1.21+")
402-
.defaultExpression(new EventValueExpression<>(SpawnRuleWrapper.class))
403-
.parser(new Parser<>() {
404-
@Override
405-
public boolean canParse(ParseContext context) {
406-
return false;
407-
}
408-
409-
@Override
410-
public String toString(SpawnRule rule, int flags) {
411-
StringJoiner joiner = new StringJoiner(" ");
412-
joiner.add("spawn rule with");
413-
joiner.add("min block light " + rule.getMinBlockLight() + ',');
414-
joiner.add("max block light " + rule.getMaxBlockLight() + ',');
415-
joiner.add("min sky light " + rule.getMinSkyLight() + ", and");
416-
joiner.add("max sky light " + rule.getMaxSkyLight());
417-
return joiner.toString();
418-
}
419-
420-
@Override
421-
public String toVariableNameString(SpawnRule rule) {
422-
return "spawn rule:"
423-
+ rule.getMinBlockLight() + ','
424-
+ rule.getMaxBlockLight() + ','
425-
+ rule.getMinSkyLight() + ','
426-
+ rule.getMaxSkyLight();
427-
}
428-
})
429-
.serializer(new Serializer<>() {
430-
@Override
431-
public Fields serialize(SpawnRule spawnRule) {
432-
Fields fields = new Fields();
433-
fields.putPrimitive("minBlockLight", spawnRule.getMinBlockLight());
434-
fields.putPrimitive("maxBlockLight", spawnRule.getMaxBlockLight());
435-
fields.putPrimitive("minSkyLight", spawnRule.getMinSkyLight());
436-
fields.putPrimitive("maxSkyLight", spawnRule.getMaxSkyLight());
437-
return fields;
438-
}
439-
440-
@Override
441-
public void deserialize(SpawnRule o, Fields f) {
442-
assert false;
443-
}
444-
445-
@Override
446-
protected SpawnRule deserialize(Fields fields) throws StreamCorruptedException {
447-
int minBlockLight = fields.getPrimitive("minBlockLight", int.class);
448-
int maxBlockLight = fields.getPrimitive("maxBlockLight", int.class);
449-
int minSkyLight = fields.getPrimitive("minSkyLight", int.class);
450-
int maxSkyLight = fields.getPrimitive("maxSkyLight", int.class);
451-
return new SpawnRuleWrapper(minBlockLight, maxBlockLight, minSkyLight, maxSkyLight);
452-
}
453-
454-
@Override
455-
public boolean mustSyncDeserialization() {
456-
return true;
457-
}
458-
459-
@Override
460-
protected boolean canBeInstantiated() {
461-
return false;
462-
}
463-
})
464-
);
465-
466-
*/
467311
}
468312

469313
}

src/main/java/org/skriptlang/skript/bukkit/spawners/util/SpawnerDataType.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,20 @@
77
import java.util.List;
88
import java.util.Locale;
99

10+
/**
11+
* Represents the type of spawner data.
12+
*/
1013
public enum SpawnerDataType {
1114

1215
MOB(SkriptMobSpawnerData.class),
1316
TRIAL(SkriptTrialSpawnerData.class),
1417
ANY(SkriptSpawnerData.class);
1518

19+
/**
20+
* Creates a SpawnerDataType from the given parse result tags.
21+
* @param tags the tags from the parse result
22+
* @return the corresponding SpawnerDataType
23+
*/
1624
public static SpawnerDataType fromTags(List<String> tags) {
1725
if (tags.contains("trial")) {
1826
return TRIAL;
@@ -28,18 +36,31 @@ public static SpawnerDataType fromTags(List<String> tags) {
2836
this.dataClass = dataClass;
2937
}
3038

39+
/**
40+
* Gets the class of the SkriptSpawnerData associated with this type.
41+
* @return the class of SkriptSpawnerData
42+
*/
3143
public Class<? extends SkriptSpawnerData> getDataClass() {
3244
return dataClass;
3345
}
3446

47+
/**
48+
* @return whether the type is {@link #MOB}
49+
*/
3550
public boolean isMob() {
3651
return this == MOB;
3752
}
3853

54+
/**
55+
* @return whether the type is {@link #TRIAL}
56+
*/
3957
public boolean isTrial() {
4058
return this == TRIAL;
4159
}
4260

61+
/**
62+
* @return whether the type is {@link #ANY}
63+
*/
4364
public boolean isAny() {
4465
return this == ANY;
4566
}

0 commit comments

Comments
 (0)