Skip to content

Commit f732017

Browse files
authored
Merge branch 'dev/feature' into feature/simplification-2
2 parents 83e12e8 + 904640d commit f732017

30 files changed

Lines changed: 252 additions & 146 deletions

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ org.gradle.parallel=true
55

66
groupid=ch.njol
77
name=skript
8-
version=2.11.0
8+
version=2.11.1
99
jarName=Skript.jar
1010
testEnv=java21/paper-1.21.5
1111
testEnvJavaVersion=21

src/main/java/ch/njol/skript/bukkitutil/block/NewBlockCompat.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
package ch.njol.skript.bukkitutil.block;
22

33
import ch.njol.skript.Skript;
4-
import ch.njol.skript.aliases.Aliases;
5-
import ch.njol.skript.aliases.ItemType;
64
import ch.njol.skript.aliases.MatchQuality;
75
import ch.njol.skript.bukkitutil.ItemUtils;
86
import ch.njol.skript.variables.Variables;
@@ -119,7 +117,11 @@ public void deserialize(@NotNull Fields fields) throws StreamCorruptedException
119117
if (data == null)
120118
throw new StreamCorruptedException("'data' is missing.");
121119

122-
this.data = Bukkit.createBlockData(data);
120+
try {
121+
this.data = Bukkit.createBlockData(data);
122+
} catch (IllegalArgumentException e) {
123+
throw new StreamCorruptedException("Invalid block data: " + data);
124+
}
123125
this.type = this.data.getMaterial();
124126
this.isDefault = isDefault;
125127
}

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -161,16 +161,14 @@ public String toVariableNameString(final WeatherType o) {
161161
Classes.registerClass(new ClassInfo<>(ItemType.class, "itemtype")
162162
.user("item ?types?", "materials?")
163163
.name("Item Type")
164-
.description("An item type is an alias, e.g. 'a pickaxe', 'all plants', etc., and can result in different items when added to an inventory, " +
164+
.description("An item type is an alias that can result in different items when added to an inventory, " +
165165
"and unlike <a href='#itemstack'>items</a> they are well suited for checking whether an inventory contains a certain item or whether a certain item is of a certain type.",
166166
"An item type can also have one or more <a href='#enchantmenttype'>enchantments</a> with or without a specific level defined, " +
167167
"and can optionally start with 'all' or 'every' to make this item type represent <i>all</i> types that the alias represents, including data ranges.")
168168
.usage("[&lt;number&gt; [of]] [all/every] &lt;alias&gt; [of &lt;enchantment&gt; [&lt;level&gt;] [,/and &lt;more enchantments...&gt;]]")
169169
.examples("give 4 torches to the player",
170-
"add all slabs to the inventory of the block",
170+
"add oak slab to the inventory of the block",
171171
"player's tool is a diamond sword of sharpness",
172-
"remove a pickaxes of fortune 4 from {stored items::*}",
173-
"set {_item} to 10 of every upside-down stair",
174172
"block is dirt or farmland")
175173
.since("1.0")
176174
.before("itemstack", "entitydata", "entitytype")

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
@Name("Is Edible")
1111
@Description("Checks whether an item is edible.")
1212
@Examples({
13-
"steak is edible",
13+
"cooked beef is edible",
1414
"player's tool is edible"
1515
})
1616
@Since("2.2-dev36")

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
@Name("Is Enchanted")
2323
@Description("Checks whether an item is enchanted.")
2424
@Examples({"tool of the player is enchanted with efficiency 2",
25-
"helm, chestplate, leggings or boots are enchanted"})
25+
"helm, chestplate, leggings or boots are enchanted"})
2626
@Since("1.4.6")
2727
public class CondIsEnchanted extends Condition {
2828

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
@Name("Is Flammable")
1111
@Description("Checks whether an item is flammable.")
1212
@Examples({
13-
"wood is flammable",
13+
"send whether the tag contents of minecraft tag \"planks\" are flammable",
1414
"player's tool is flammable"
1515
})
1616
@Since("2.2-dev36")

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
@Description("Checks whether an entity is wearing some items (usually armor).")
2727
@Examples({
2828
"player is wearing an iron chestplate and iron leggings",
29-
"player is wearing all diamond armour",
3029
"target is wearing wolf armor"
3130
})
3231
@Since("1.0")

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
@Description("Checks whether a player is holding a specific item. Cannot be used with endermen, use 'entity is [not] an enderman holding &lt;item type&gt;' instead.")
2222
@Examples({
2323
"player is holding a stick",
24-
"victim isn't holding a sword of sharpness"
24+
"victim isn't holding a diamond sword of sharpness"
2525
})
2626
@Since("1.0")
2727
public class CondItemInHand extends Condition {

src/main/java/ch/njol/skript/doc/JSONGenerator.java

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -176,12 +176,22 @@ private static JsonArray getEventValues(SkriptEventInfo<?> info) {
176176
continue;
177177
}
178178

179-
ClassInfo<?> exactClassInfo = Classes.getExactClassInfo(eventValueInfo.valueClass());
180-
if (exactClassInfo == null) {
179+
Class<?> valueClass = eventValueInfo.valueClass();
180+
ClassInfo<?> classInfo;
181+
if (valueClass.isArray()) {
182+
classInfo = Classes.getExactClassInfo(valueClass.componentType());
183+
} else {
184+
classInfo = Classes.getExactClassInfo(valueClass);
185+
}
186+
187+
if (classInfo == null) {
181188
continue;
182189
}
183190

184-
String name = getClassInfoName(exactClassInfo).toLowerCase(Locale.ENGLISH);
191+
String name = classInfo.getName().getSingular();
192+
if (valueClass.isArray()) {
193+
name = classInfo.getName().getPlural();
194+
}
185195
if (name.isBlank()) {
186196
continue;
187197
}
@@ -193,8 +203,8 @@ private static JsonArray getEventValues(SkriptEventInfo<?> info) {
193203
}
194204

195205
JsonObject object = new JsonObject();
196-
object.addProperty("id", DocumentationIdProvider.getId(exactClassInfo));
197-
object.addProperty("name", name);
206+
object.addProperty("id", DocumentationIdProvider.getId(classInfo));
207+
object.addProperty("name", name.toLowerCase(Locale.ENGLISH));
198208
eventValues.add(object);
199209
}
200210
}
@@ -277,7 +287,7 @@ private static JsonObject generateClassInfoElement(ClassInfo<?> classInfo) {
277287

278288
JsonObject syntaxJsonObject = new JsonObject();
279289
syntaxJsonObject.addProperty("id", DocumentationIdProvider.getId(classInfo));
280-
syntaxJsonObject.addProperty("name", getClassInfoName(classInfo));
290+
syntaxJsonObject.addProperty("name", Objects.requireNonNullElse(classInfo.getDocName(), classInfo.getCodeName()));
281291
syntaxJsonObject.addProperty("since", classInfo.getSince());
282292

283293
syntaxJsonObject.add("patterns", cleanPatterns(classInfo.getUsage()));
@@ -304,16 +314,6 @@ private static JsonArray generateClassInfoArray(Iterator<ClassInfo<?>> classInfo
304314
return syntaxArray;
305315
}
306316

307-
/**
308-
* Gets either the explicitly declared documentation name or code name of a ClassInfo
309-
*
310-
* @param classInfo the ClassInfo to get the effective name of
311-
* @return the effective name of the ClassInfo
312-
*/
313-
private static String getClassInfoName(ClassInfo<?> classInfo) {
314-
return Objects.requireNonNullElse(classInfo.getDocName(), classInfo.getCodeName());
315-
}
316-
317317
/**
318318
* Generates the documentation JsonObject for a JavaFunction
319319
*
@@ -342,10 +342,16 @@ private static JsonObject generateFunctionElement(JavaFunction<?> function) {
342342
* @return the JsonObject representing the return type of the JavaFunction
343343
*/
344344
private static JsonObject getReturnType(JavaFunction<?> function) {
345-
JsonObject returnType = new JsonObject();
346-
returnType.addProperty("name", getClassInfoName(function.getReturnType()));
347-
returnType.addProperty("id", DocumentationIdProvider.getId(function.getReturnType()));
348-
return returnType;
345+
JsonObject object = new JsonObject();
346+
347+
ClassInfo<?> returnType = function.getReturnType();
348+
if (returnType == null) {
349+
return null;
350+
}
351+
352+
object.addProperty("id", DocumentationIdProvider.getId(returnType));
353+
object.addProperty("name", Objects.requireNonNullElse(returnType.getDocName(), returnType.getCodeName()));
354+
return object;
349355
}
350356

351357
/**

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

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,5 @@
11
package ch.njol.skript.effects;
22

3-
import java.util.ArrayList;
4-
import java.util.Collections;
5-
import java.util.HashSet;
6-
import java.util.List;
7-
import java.util.Set;
8-
import java.util.regex.Pattern;
9-
103
import ch.njol.skript.Skript;
114
import ch.njol.skript.doc.Description;
125
import ch.njol.skript.doc.Examples;
@@ -24,6 +17,7 @@
2417
import ch.njol.skript.util.Utils;
2518
import ch.njol.skript.util.chat.BungeeConverter;
2619
import ch.njol.skript.util.chat.ChatMessages;
20+
import ch.njol.skript.util.chat.MessageComponent;
2721
import ch.njol.util.Kleenean;
2822
import ch.njol.util.StringUtils;
2923
import ch.njol.util.coll.CollectionUtils;
@@ -35,6 +29,9 @@
3529
import org.bukkit.event.server.BroadcastMessageEvent;
3630
import org.jetbrains.annotations.Nullable;
3731

32+
import java.util.*;
33+
import java.util.regex.Pattern;
34+
3835
@Name("Broadcast")
3936
@Description("Broadcasts a message to the server.")
4037
@Examples({
@@ -83,12 +80,15 @@ public void execute(Event event) {
8380
}
8481

8582
for (Expression<?> message : getMessages()) {
86-
if (message instanceof VariableString) {
87-
if (!dispatchEvent(getRawString(event, (VariableString) message), receivers))
83+
if (message instanceof VariableString variableString) {
84+
// get both unformatted and components with single evaluation: https://github.com/SkriptLang/Skript/issues/7718
85+
StringBuilder unformattedString = new StringBuilder();
86+
List<MessageComponent> messageComponents = variableString.getMessageComponents(event, unformattedString);
87+
if (!dispatchEvent(unformattedString.toString(), receivers))
8888
continue;
89-
BaseComponent[] components = BungeeConverter.convert(((VariableString) message).getMessageComponents(event));
89+
BaseComponent[] components = BungeeConverter.convert(messageComponents);
9090
receivers.forEach(receiver -> receiver.spigot().sendMessage(components));
91-
} else if (message instanceof ExprColoured && ((ExprColoured) message).isUnsafeFormat()) { // Manually marked as trusted
91+
} else if (message instanceof ExprColoured coloured && coloured.isUnsafeFormat()) { // Manually marked as trusted
9292
for (Object realMessage : message.getArray(event)) {
9393
if (!dispatchEvent(Utils.replaceChatStyles((String) realMessage), receivers))
9494
continue;
@@ -97,7 +97,7 @@ public void execute(Event event) {
9797
}
9898
} else {
9999
for (Object messageObject : message.getArray(event)) {
100-
String realMessage = messageObject instanceof String ? (String) messageObject : Classes.toString(messageObject);
100+
String realMessage = messageObject instanceof String string ? string : Classes.toString(messageObject);
101101
if (!dispatchEvent(Utils.replaceChatStyles(realMessage), receivers))
102102
continue;
103103
receivers.forEach(receiver -> receiver.sendMessage(realMessage));
@@ -123,9 +123,9 @@ private Expression<?>[] getMessages() {
123123
* @param message the message
124124
* @return true if the dispatched event does not get cancelled
125125
*/
126-
@SuppressWarnings("deprecation")
126+
@SuppressWarnings("removal")
127127
private static boolean dispatchEvent(String message, List<CommandSender> receivers) {
128-
Set<CommandSender> recipients = Collections.unmodifiableSet(new HashSet<>(receivers));
128+
Set<CommandSender> recipients = Set.copyOf(receivers);
129129
BroadcastMessageEvent broadcastEvent;
130130
if (Skript.isRunningMinecraft(1, 14)) {
131131
broadcastEvent = new BroadcastMessageEvent(!Bukkit.isPrimaryThread(), message, recipients);
@@ -136,11 +136,18 @@ private static boolean dispatchEvent(String message, List<CommandSender> receive
136136
return !broadcastEvent.isCancelled();
137137
}
138138

139-
@Nullable
140-
private static String getRawString(Event event, Expression<? extends String> string) {
141-
if (string instanceof VariableString)
142-
return ((VariableString) string).toUnformattedString(event);
139+
/**
140+
* Gets the raw string from the expression, replacing colour codes.
141+
* @param event the event
142+
* @param string the expression
143+
* @return the raw string
144+
*/
145+
private static @Nullable String getRawString(Event event, Expression<? extends String> string) {
146+
if (string instanceof VariableString variableString)
147+
return variableString.toUnformattedString(event);
143148
String rawString = string.getSingle(event);
149+
if (rawString == null)
150+
return null;
144151
rawString = SkriptColor.replaceColorChar(rawString);
145152
if (rawString.toLowerCase().contains("&x")) {
146153
rawString = StringUtils.replaceAll(rawString, HEX_PATTERN, matchResult ->

0 commit comments

Comments
 (0)