Skip to content

Commit 70afe1f

Browse files
committed
Update some MC API docs
1 parent e61eaa6 commit 70afe1f

File tree

10 files changed

+155
-90
lines changed

10 files changed

+155
-90
lines changed

src/main/java/com/laytonsmith/abstraction/enums/MCSpawnReason.java

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,21 @@ public enum MCSpawnReason {
5959
ENCHANTMENT,
6060
TRIAL_SPAWNER,
6161
POTION_EFFECT,
62-
REHYDRATION, // Paper
63-
REANIMATE, // Spigot
62+
REHYDRATION("Paper"), // Happy Ghast
63+
REANIMATE("Spigot"); // Copper Golem
64+
65+
final String mcImplementation;
66+
67+
MCSpawnReason() {
68+
this.mcImplementation = null;
69+
}
70+
71+
MCSpawnReason(String mcImplementation) {
72+
this.mcImplementation = mcImplementation;
73+
}
74+
75+
@Deprecated
76+
public String getImplementation() {
77+
return this.mcImplementation;
78+
}
6479
}

src/main/java/com/laytonsmith/core/events/drivers/EntityEvents.java

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
import com.laytonsmith.abstraction.enums.MCRemoveCause;
2626
import com.laytonsmith.abstraction.enums.MCSpawnReason;
2727
import com.laytonsmith.abstraction.enums.MCTargetReason;
28-
import com.laytonsmith.abstraction.enums.MCUnleashReason;
2928
import com.laytonsmith.abstraction.enums.MCVersion;
3029
import com.laytonsmith.abstraction.events.MCCreatureSpawnEvent;
3130
import com.laytonsmith.abstraction.events.MCEntityChangeBlockEvent;
@@ -741,7 +740,19 @@ public String getName() {
741740

742741
@Override
743742
public String docs() {
744-
return "{type: <macro> | reason: <macro> One of " + StringUtils.Join(MCSpawnReason.values(), ", ", ", or ", " or ") + "}"
743+
StringBuilder reasons = new StringBuilder();
744+
for(MCSpawnReason value : MCSpawnReason.values()) {
745+
if(!reasons.isEmpty()) {
746+
reasons.append(", ");
747+
}
748+
reasons.append(value.name());
749+
if(value.getImplementation() != null) {
750+
reasons.append(" (");
751+
reasons.append(value.getImplementation());
752+
reasons.append(")");
753+
}
754+
}
755+
return "{type: <macro> | reason: <macro> One of: " + reasons + "}"
745756
+ " Fired when a living entity spawns on the server."
746757
+ " {type: the type of creature spawning | id: the entityID of the creature"
747758
+ " | reason: the reason this creature is spawning | location: locationArray of the event}"
@@ -2384,8 +2395,8 @@ public String docs() {
23842395
return "{type: <macro> | reason: <macro>}"
23852396
+ " This event is called when a leash is broken."
23862397
+ " {id: The entityID of the entity | type: The entity type of the entity"
2387-
+ " | reason: The reason the leash broke. Can be one of "
2388-
+ StringUtils.Join(MCUnleashReason.values(), ", ", ", or ", " or ") + "}"
2398+
+ " | reason: The reason the leash broke. Can be one of HOLDER_GONE, PLAYER_UNLEASH, DISTANCE,"
2399+
+ " SHEAR (Spigot-only 1.21.6+), FIREWORK (Spigot-only 1.21.6+), UNKNOWN}"
23892400
+ " {}";
23902401
}
23912402

src/main/java/com/laytonsmith/core/events/drivers/InventoryEvents.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -529,13 +529,13 @@ public String docs() {
529529
+ "{player: The player that enchanted the item | "
530530
+ "item: The item to be enchanted | "
531531
+ "inventorytype: type of inventory | "
532-
+ "levels: The amount of levels the player used | "
532+
+ "levels: The minimum amount of levels the player required | "
533533
+ "enchants: Array of added enchantments | "
534534
+ "location: Location of the used enchantment table | "
535-
+ "option: The enchantment option the player clicked | "
535+
+ "option: The listed option the player clicked (0-2). Can be used to get level cost. | "
536536
+ "levelhint: The level displayed as a hint to the player (MC 1.20.1+) | "
537537
+ "enchanthint: The enchantment displayed as a hint to the player (MC 1.20.1+)}"
538-
+ "{levels: The amount of levels to use | "
538+
+ "{levels: The amount of levels required | "
539539
+ "item: The item to be enchanted | "
540540
+ "enchants: The enchants to add to the item}"
541541
+ "{}";

src/main/java/com/laytonsmith/core/functions/Commands.java

Lines changed: 31 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -338,36 +338,37 @@ public Version since() {
338338
public ExampleScript[] examples() throws ConfigCompileException {
339339
return new ExampleScript[]{
340340
new ExampleScript("Register the /hug <player> command.",
341-
"register_command('hug', array(\n"
342-
+ "\t'description': 'Spread the love!',\n"
343-
+ "\t'usage': '/hug <player>',\n"
344-
+ "\t'permission': 'perms.hugs',\n"
345-
+ "\t'tabcompleter':\n"
346-
+ "\t\tclosure(@alias, @sender, @args) {\n"
347-
+ "\t\t\t// This replicates the default tabcompleter for registered commands.\n"
348-
+ "\t\t\t// If no tabcompleter is set, this behavior is used.\n"
349-
+ "\t\t\t@input = @args[-1];\n"
350-
+ "\t\t\treturn(array_filter(all_players(), closure(@key, @value) {\n"
351-
+ "\t\t\t\treturn(length(@input) <= length(@value)\n"
352-
+ "\t\t\t\t\t\t&& equals_ic(@input, substr(@value, 0, length(@input))));\n"
353-
+ "\t\t\t}));\n"
354-
+ "\t\t},\n"
355-
+ "\t'aliases': array('hugg', 'hugs'),\n"
356-
+ "\t'executor':\n"
357-
+ "\t\tclosure(@alias, @sender, @args) {\n"
358-
+ "\t\t\tif(array_size(@args) == 1) {\n"
359-
+ "\t\t\t\t@target = @args[0];\n"
360-
+ "\t\t\t\tif(ponline(@target)) {\n"
361-
+ "\t\t\t\t\tbroadcast(colorize('&4'.@sender.' &6hugs &4'.@target));\n"
362-
+ "\t\t\t\t} else {\n"
363-
+ "\t\t\t\t\tmsg(colorize('&cThe given player is not online.'));\n"
364-
+ "\t\t\t\t}\n"
365-
+ "\t\t\t\treturn(true);\n"
366-
+ "\t\t\t}\n"
367-
+ "\t\t\treturn(false); // prints usage\n"
368-
+ "\t\t}\n"
369-
+ "));",
370-
"Registers the /hug command.")
341+
"""
342+
register_command('hug', array(
343+
'description': 'Spread the love!',
344+
'usage': '/hug <player>',
345+
'permission': 'perms.hugs',
346+
'aliases': array('hugg', 'hugs'),
347+
'tabcompleter':
348+
closure(@alias, @sender, @args) {
349+
// This replicates the default tabcompleter for registered commands.
350+
// If no tabcompleter is set, this behavior is used.
351+
@input = @args[-1];
352+
return(array_filter(all_players(), closure(@key, @value) {
353+
return(length(@input) <= length(@value)
354+
&& equals_ic(@input, substr(@value, 0, length(@input))));
355+
}));
356+
},
357+
'executor':
358+
closure(@alias, @sender, @args) {
359+
if(array_size(@args) == 1) {
360+
@target = @args[0];
361+
if(ponline(@target)) {
362+
broadcast(colorize('&4'.@sender.' &6hugs &4'.@target));
363+
} else {
364+
msg(colorize('&cThe given player is not online.'));
365+
}
366+
return(true);
367+
}
368+
return(false); // prints usage
369+
}
370+
));""",
371+
"Registers the /hug command.")
371372
};
372373
}
373374
}

src/main/java/com/laytonsmith/core/functions/EntityManagement.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5872,7 +5872,7 @@ public Integer[] numArgs() {
58725872
@Override
58735873
public String docs() {
58745874
return """
5875-
void {entityUUID, pose, [fixed]} Sets an entity's pose. (only Mannequins on Spigot)
5875+
void {entityUUID, pose, [fixed]} Sets an entity's pose. (only Mannequins on Spigot, 1.20.1+ on Paper)
58765876
The fixed argument is a boolean for whether the pose should stay unless manually changed.
58775877
(defaults to false) While in most cases you can set any pose to any entity,
58785878
only certain poses will result in a noticable change for a particular entity type.

src/main/java/com/laytonsmith/core/functions/Environment.java

Lines changed: 43 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1589,8 +1589,7 @@ public MSVersion since() {
15891589

15901590

15911591
@api(environments = {CommandHelperEnvironment.class})
1592-
public static class spawn_particle extends AbstractFunction {
1593-
1592+
public static class spawn_particle extends AbstractFunction implements Optimizable {
15941593
@Override
15951594
public MSVersion since() {
15961595
return MSVersion.V3_3_3;
@@ -1633,12 +1632,12 @@ public String docs() {
16331632
+ "<br>BLOCK_DUST, BLOCK_CRACK, BLOCK_CRUMBLE, BLOCK_MARKER, DUST_PILLAR, and FALLING_DUST"
16341633
+ " particles can take a block type name parameter under the key \"block\" (default: STONE)."
16351634
+ "<br>ITEM_CRACK particles can take an item array or name under the key \"item\" (default: STONE)."
1636-
+ "<br>REDSTONE, SPELL, and SPELL_INSTANT particles take an RGB color array"
1635+
+ "<br>REDSTONE, SPELL (1.21.9+), and SPELL_INSTANT (1.21.9+) particles take an RGB color array"
16371636
+ " (each 0 - 255) or name under the key \"color\" (defaults to RED for REDSTONE, WHITE for others)."
1638-
+ "<br>SPELL_MOB and FLASH particles take an ARGB color array"
1639-
+ " (each 0 - 255) or name under the key \"color\" (defaults to opaque WHITE)."
1640-
+ "<br>SPELL, SPELL_INSTANT and DRAGON_BREATH particles take a \"power\" value that scales velocity."
1641-
+ " (defaults to 1.0)"
1637+
+ "<br>SPELL_MOB (1.20.6+), TINTED_LEAVES (1.20.6+) and FLASH (1.21.9+) particles take an ARGB color"
1638+
+ " array (each 0 - 255) or name under the key \"color\" (defaults to opaque WHITE)."
1639+
+ "<br>SPELL, SPELL_INSTANT and DRAGON_BREATH (1.21.9+) particles take a \"power\" value that scales"
1640+
+ " velocity. (defaults to 1.0)"
16421641
+ "<br>DUST_COLOR_TRANSITION particles take a \"tocolor\" in addition \"color\"."
16431642
+ "<br>VIBRATION particles take a \"destination\" location array or entity UUID."
16441643
+ "<br>SCULK_CHARGE particles take an \"angle\" in radians. (defaults to 0.0)"
@@ -1736,6 +1735,43 @@ public Mixed exec(Target t, com.laytonsmith.core.environments.Environment enviro
17361735
}
17371736
return CVoid.VOID;
17381737
}
1738+
1739+
@Override
1740+
public ParseTree optimizeDynamic(Target t, com.laytonsmith.core.environments.Environment env,
1741+
Set<Class<? extends com.laytonsmith.core.environments.Environment.EnvironmentImpl>> envs,
1742+
List<ParseTree> children, FileOptions fileOptions)
1743+
throws ConfigCompileException, ConfigRuntimeException {
1744+
1745+
if(children.size() < 2) {
1746+
return null;
1747+
}
1748+
ParseTree child = children.get(1);
1749+
if(child.getData() instanceof CFunction && (child.getData().val().equals(DataHandling.array.NAME)
1750+
|| child.getData().val().equals(DataHandling.associative_array.NAME))) {
1751+
for(ParseTree node : child.getChildren()) {
1752+
if(node.getData() instanceof CFunction && node.getData().val().equals(Compiler.centry.NAME)) {
1753+
children = node.getChildren();
1754+
if(children.get(0).getData().val().equals("particle")
1755+
&& children.get(1).getData().isInstanceOf(CString.TYPE)) {
1756+
try {
1757+
MCParticle.MCVanillaParticle.valueOf(children.get(1).getData().val().toUpperCase());
1758+
} catch (IllegalArgumentException ex) {
1759+
env.getEnv(CompilerEnvironment.class).addCompilerWarning(fileOptions,
1760+
new CompilerWarning(children.get(1).getData().val()
1761+
+ " is not a valid enum in com.commandhelper.Particle",
1762+
children.get(1).getTarget(), null));
1763+
}
1764+
}
1765+
}
1766+
}
1767+
}
1768+
return null;
1769+
}
1770+
1771+
@Override
1772+
public Set<OptimizationOption> optimizationOptions() {
1773+
return EnumSet.of(OptimizationOption.OPTIMIZE_DYNAMIC);
1774+
}
17391775
}
17401776

17411777
@api(environments = {CommandHelperEnvironment.class})

src/main/java/com/laytonsmith/core/functions/InventoryManagement.java

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import com.laytonsmith.abstraction.blocks.MCBlockState;
2020
import com.laytonsmith.abstraction.enums.MCInventoryType;
2121
import com.laytonsmith.annotations.api;
22+
import com.laytonsmith.annotations.seealso;
2223
import com.laytonsmith.core.ArgumentValidation;
2324
import com.laytonsmith.core.MSVersion;
2425
import com.laytonsmith.core.ObjectGenerator;
@@ -73,6 +74,7 @@ public static String docs() {
7374
+ " and 'meta' (an array of item meta or null if none exists; see {{function|get_itemmeta}} for details).";
7475

7576
@api(environments = {CommandHelperEnvironment.class})
77+
@seealso({set_pinv.class, ptake_item.class})
7678
public static class pinv extends AbstractFunction {
7779

7880
@Override
@@ -433,6 +435,7 @@ public MSVersion since() {
433435
}
434436

435437
@api(environments = {CommandHelperEnvironment.class})
438+
@seealso({ptake_item.class, pgive_item.class})
436439
public static class set_pinv extends AbstractFunction {
437440

438441
@Override
@@ -610,6 +613,7 @@ public Mixed exec(Target t, Environment env, Mixed... args) throws ConfigRuntime
610613
}
611614

612615
@api(environments = {CommandHelperEnvironment.class})
616+
@seealso({pinv.class})
613617
public static class phas_item extends AbstractFunction implements Optimizable {
614618

615619
@Override
@@ -861,6 +865,7 @@ public ExampleScript[] examples() throws ConfigCompileException {
861865
}
862866

863867
@api(environments = {CommandHelperEnvironment.class})
868+
@seealso({set_pinv.class})
864869
public static class pgive_item extends AbstractFunction implements Optimizable {
865870

866871
@Override
@@ -981,6 +986,7 @@ public Set<OptimizationOption> optimizationOptions() {
981986
}
982987

983988
@api(environments = {CommandHelperEnvironment.class})
989+
@seealso({pinv.class})
984990
public static class ptake_item extends AbstractFunction implements Optimizable {
985991

986992
@Override
@@ -1119,6 +1125,7 @@ public ExampleScript[] examples() throws ConfigCompileException {
11191125
}
11201126

11211127
@api(environments = {CommandHelperEnvironment.class})
1128+
@seealso({set_penderchest.class})
11221129
public static class pgive_enderchest_item extends AbstractFunction implements Optimizable {
11231130

11241131
@Override
@@ -1133,13 +1140,13 @@ public Integer[] numArgs() {
11331140

11341141
@Override
11351142
public String docs() {
1136-
return "int {[player], itemArray} Adds the specified item to a player's"
1137-
+ " enderchest. Unlike set_penderchest(), this does not specify a slot. The items are distributed"
1138-
+ " in the player's inventory, first filling up slots that have the same item type, up to the max"
1139-
+ " stack size, then fills up empty slots, until either the entire inventory is filled or the"
1140-
+ " entire amount has been given. If the player's enderchest is full, the number of items that were"
1141-
+ " not added is returned, which will be less than or equal to the quantity provided. Otherwise,"
1142-
+ " returns 0.";
1143+
return "int {[player], itemArray} Adds the specified item to a player's enderchest."
1144+
+ " Unlike {{function|set_penderchest}}, this does not use a specific slot. The items are"
1145+
+ " distributed in the player's inventory, first filling up slots that have the same items, up to"
1146+
+ " the max stack size, then fills up empty slots, until either the entire inventory is filled or"
1147+
+ " the entire amount has been given. If the player's enderchest is full, the number of items that"
1148+
+ " were not added is returned, which will be less than or equal to the quantity provided."
1149+
+ " Otherwise, returns 0.";
11431150
}
11441151

11451152
@Override
@@ -1236,6 +1243,7 @@ public Set<OptimizationOption> optimizationOptions() {
12361243
}
12371244

12381245
@api(environments = {CommandHelperEnvironment.class})
1246+
@seealso({set_penderchest.class})
12391247
public static class ptake_enderchest_item extends AbstractFunction implements Optimizable {
12401248

12411249
@Override
@@ -1373,6 +1381,7 @@ public ExampleScript[] examples() throws ConfigCompileException {
13731381
}
13741382

13751383
@api(environments = {CommandHelperEnvironment.class})
1384+
@seealso({penderchest.class, ptake_enderchest_item.class, pgive_enderchest_item.class})
13761385
public static class set_penderchest extends AbstractFunction {
13771386

13781387
@Override
@@ -1478,6 +1487,7 @@ public Mixed exec(Target t, Environment env, Mixed... args) throws ConfigRuntime
14781487
}
14791488

14801489
@api(environments = {CommandHelperEnvironment.class})
1490+
@seealso({set_penderchest.class, ptake_enderchest_item.class, pgive_enderchest_item.class})
14811491
public static class penderchest extends AbstractFunction {
14821492

14831493
@Override
@@ -1634,6 +1644,7 @@ public MSVersion since() {
16341644
}
16351645

16361646
@api(environments = {CommandHelperEnvironment.class})
1647+
@seealso({set_inventory_item.class, get_inventory_size.class})
16371648
public static class get_inventory_item extends AbstractFunction {
16381649

16391650
@Override
@@ -1697,6 +1708,7 @@ public MSVersion since() {
16971708
}
16981709

16991710
@api(environments = {CommandHelperEnvironment.class})
1711+
@seealso({get_inventory_item.class, get_inventory_size.class, take_from_inventory.class, add_to_inventory.class})
17001712
public static class set_inventory_item extends AbstractFunction {
17011713

17021714
@Override
@@ -1816,6 +1828,7 @@ public MSVersion since() {
18161828
}
18171829

18181830
@api(environments = {CommandHelperEnvironment.class})
1831+
@seealso({set_inventory.class, set_inventory_item.class, take_from_inventory.class, get_inventory.class})
18191832
public static class get_inventory_size extends AbstractFunction {
18201833

18211834
@Override
@@ -1981,6 +1994,7 @@ public MSVersion since() {
19811994
}
19821995

19831996
@api(environments = {CommandHelperEnvironment.class})
1997+
@seealso({set_inventory.class, set_inventory_item.class, take_from_inventory.class})
19841998
public static class get_inventory extends AbstractFunction {
19851999

19862000
@Override
@@ -2055,6 +2069,7 @@ public Mixed exec(Target t, Environment env, Mixed... args) throws ConfigRuntime
20552069
}
20562070

20572071
@api(environments = {CommandHelperEnvironment.class})
2072+
@seealso({get_inventory.class, get_inventory_size.class, set_inventory_item.class, add_to_inventory.class})
20582073
public static class set_inventory extends AbstractFunction {
20592074

20602075
@Override
@@ -2134,6 +2149,7 @@ public Mixed exec(Target t, Environment env, Mixed... args) throws ConfigRuntime
21342149
}
21352150

21362151
@api(environments = {CommandHelperEnvironment.class})
2152+
@seealso({set_inventory_item.class})
21372153
public static class add_to_inventory extends AbstractFunction implements Optimizable {
21382154

21392155
@Override
@@ -2245,6 +2261,7 @@ public Set<OptimizationOption> optimizationOptions() {
22452261
}
22462262

22472263
@api(environments = {CommandHelperEnvironment.class})
2264+
@seealso({get_inventory.class})
22482265
public static class take_from_inventory extends AbstractFunction implements Optimizable {
22492266

22502267
@Override

0 commit comments

Comments
 (0)