Skip to content

Commit a95457b

Browse files
Merge branch 'dev/patch' into dev/feature
2 parents b87787c + dd063f9 commit a95457b

7 files changed

Lines changed: 67 additions & 35 deletions

File tree

skript-aliases

src/main/java/ch/njol/skript/aliases/ItemType.java

Lines changed: 43 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,7 @@
2121
import ch.njol.yggdrasil.Fields;
2222
import ch.njol.yggdrasil.Fields.FieldContext;
2323
import ch.njol.yggdrasil.YggdrasilSerializable.YggdrasilExtendedSerializable;
24-
import org.bukkit.Location;
25-
import org.bukkit.Material;
26-
import org.bukkit.OfflinePlayer;
27-
import org.bukkit.Tag;
28-
import org.bukkit.Bukkit;
24+
import org.bukkit.*;
2925
import org.bukkit.block.Block;
3026
import org.bukkit.block.BlockState;
3127
import org.bukkit.block.Skull;
@@ -35,6 +31,7 @@
3531
import org.bukkit.inventory.Inventory;
3632
import org.bukkit.inventory.ItemStack;
3733
import org.bukkit.inventory.PlayerInventory;
34+
import org.bukkit.inventory.meta.BlockStateMeta;
3835
import org.bukkit.inventory.meta.ItemMeta;
3936
import org.bukkit.inventory.meta.SkullMeta;
4037
import org.jetbrains.annotations.NotNull;
@@ -43,19 +40,8 @@
4340
import java.io.NotSerializableException;
4441
import java.io.StreamCorruptedException;
4542
import java.lang.reflect.Field;
46-
import java.util.ArrayList;
47-
import java.util.Arrays;
48-
import java.util.Collection;
49-
import java.util.Collections;
50-
import java.util.HashSet;
51-
import java.util.Iterator;
52-
import java.util.List;
53-
import java.util.Map;
43+
import java.util.*;
5444
import java.util.Map.Entry;
55-
import java.util.NoSuchElementException;
56-
import java.util.Random;
57-
import java.util.RandomAccess;
58-
import java.util.Set;
5945
import java.util.stream.Collectors;
6046

6147
@ContainerType(ItemStack.class)
@@ -390,8 +376,8 @@ public boolean setBlock(Block block, boolean applyPhysics) {
390376

391377
ItemMeta itemMeta = getItemMeta();
392378

393-
if (itemMeta instanceof SkullMeta) {
394-
OfflinePlayer offlinePlayer = ((SkullMeta) itemMeta).getOwningPlayer();
379+
if (itemMeta instanceof SkullMeta skullMeta) {
380+
OfflinePlayer offlinePlayer = skullMeta.getOwningPlayer();
395381
if (offlinePlayer == null)
396382
continue;
397383
Skull skull = (Skull) block.getState();
@@ -407,11 +393,49 @@ public boolean setBlock(Block block, boolean applyPhysics) {
407393
skull.update(false, applyPhysics);
408394
}
409395

396+
// https://github.com/SkriptLang/Skript/issues/7735
397+
// No method exists to copy general BlockStateMeta data to a block, so we have to do it manually for now
398+
copyContainerState(block, itemMeta);
399+
410400
return true;
411401
}
412402
return false;
413403
}
414404

405+
/**
406+
* Copies the container state from the item meta to the block state
407+
* @param block The block to copy the state to
408+
* @param itemMeta The item meta to copy the state from
409+
*/
410+
private void copyContainerState(@NotNull Block block, @NotNull ItemMeta itemMeta) {
411+
// ensure the item has a block state
412+
if (!(itemMeta instanceof BlockStateMeta blockStateMeta) || !blockStateMeta.hasBlockState())
413+
return;
414+
415+
// only care about container -> container copying
416+
if (!(blockStateMeta.getBlockState() instanceof org.bukkit.block.Container itemContainer)
417+
|| !(block.getState() instanceof org.bukkit.block.Container blockContainer))
418+
return;
419+
420+
// copy inventory from item to block
421+
copyInventories(itemContainer.getSnapshotInventory(), blockContainer.getSnapshotInventory());
422+
blockContainer.update();
423+
}
424+
425+
/**
426+
* Copies the contents of one inventory to another, maintaining slot positions and making clones.
427+
* @param from The inventory to copy from
428+
* @param to The inventory to copy to
429+
*/
430+
private void copyInventories(@NotNull Inventory from, @NotNull Inventory to) {
431+
for (int i = 0; i < from.getSize(); i++) {
432+
ItemStack item = from.getItem(i);
433+
if (item != null) {
434+
to.setItem(i, item.clone());
435+
}
436+
}
437+
}
438+
415439
/**
416440
* Send a block change to a player
417441
* <p>This will send a fake block change to the player, and will not change the block on the server.</p>

src/main/java/ch/njol/skript/lang/EventRestrictedSyntax.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
/**
88
* A syntax element that restricts the events it can be used in.
99
*/
10+
@FunctionalInterface
1011
public interface EventRestrictedSyntax {
1112

1213
/**

src/main/java/ch/njol/skript/lang/SkriptParser.java

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -240,16 +240,7 @@ public boolean hasTag(String tag) {
240240
if (element instanceof EventRestrictedSyntax eventRestrictedSyntax) {
241241
Class<? extends Event>[] supportedEvents = eventRestrictedSyntax.supportedEvents();
242242
if (!getParser().isCurrentEvent(supportedEvents)) {
243-
Iterator<String> iterator = Arrays.stream(supportedEvents)
244-
.map(it -> "the " + it.getSimpleName()
245-
.replaceAll("([A-Z])", " $1")
246-
.toLowerCase()
247-
.trim())
248-
.iterator();
249-
250-
String events = StringUtils.join(iterator, ", ", " or ");
251-
252-
Skript.error("'" + parseResult.expr + "' can only be used in " + events);
243+
Skript.error("'" + parseResult.expr + "' can only be used in " + supportedEventsNames(supportedEvents));
253244
continue;
254245
}
255246
}
@@ -276,6 +267,22 @@ public boolean hasTag(String tag) {
276267
}
277268
}
278269

270+
private static String supportedEventsNames(Class<? extends Event>[] supportedEvents) {
271+
List<String> names = new ArrayList<>();
272+
273+
for (SkriptEventInfo<?> eventInfo : Skript.getEvents()) {
274+
for (Class<? extends Event> eventClass : supportedEvents) {
275+
for (Class<? extends Event> event : eventInfo.events) {
276+
if (event.isAssignableFrom(eventClass)) {
277+
names.add("the %s event".formatted(eventInfo.getName().toLowerCase()));
278+
}
279+
}
280+
}
281+
}
282+
283+
return StringUtils.join(names, ", ", " or ");
284+
}
285+
279286
private static @NotNull DefaultExpression<?> getDefaultExpression(ExprInfo exprInfo, String pattern) {
280287
DefaultExpression<?> expr = exprInfo.classes[0].getDefaultExpression();
281288
if (expr == null)

src/main/java/org/skriptlang/skript/bukkit/displays/generic/ExprDisplayTeleportDuration.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@
1616
import org.bukkit.event.Event;
1717
import org.jetbrains.annotations.Nullable;
1818

19-
@Name("Display Teleport Delay/Duration")
19+
@Name("Display Teleport Duration")
2020
@Description({
2121
"The teleport duration of displays is the amount of time it takes to get between locations.",
2222
"0 means that updates are applied immediately.",
2323
"1 means that the display entity will move from current position to the updated one over one tick.",
2424
"Higher values spread the movement over multiple ticks. Max of 59 ticks."
2525
})
2626
@Examples({
27-
"set teleport delay of the last spawned text display to 2 ticks",
27+
"set teleport duration of the last spawned text display to 2 ticks",
2828
"teleport last spawned text display to {_location}",
2929
"wait 2 ticks",
3030
"message \"display entity has arrived at %{_location}%\""

src/main/java/org/skriptlang/skript/bukkit/input/elements/events/EvtPlayerInput.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ public class EvtPlayerInput extends SkriptEvent {
1818
if (Skript.classExists("org.bukkit.event.player.PlayerInputEvent")) {
1919
Skript.registerEvent("Player Input", EvtPlayerInput.class, PlayerInputEvent.class,
2020
"[player] (toggle|toggling|1:press[ing]|2:release|2:releasing) of (%-inputkeys%|(an|any) input key)",
21-
"([player] %-inputkeys%|[an|any [player]] input key) (toggle|toggling|1:press[ing]|2:release|2:releasing)")
21+
"([player] %-inputkeys%|[an|player] input key) (toggle|toggling|1:press[ing]|2:release|2:releasing)")
2222
.description("Called when a player sends an updated input to the server.",
2323
"Note: The input keys event value is the set of keys the player is currently pressing, not the keys that were pressed or released.")
24-
.examples("on any input key press:",
24+
.examples("on input key press:",
2525
"\tsend \"You are pressing: %event-inputkeys%\" to player")
2626
.since("2.10")
2727
.requiredPlugins("Minecraft 1.21.3+");

src/test/skript/tests/misc/supported events.sk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ test "supported events":
22
parse:
33
set {_x} to the exploded blocks
44

5-
assert last parse logs contain "'the exploded blocks' can only be used in the entity explode event" with "supported events message did not get sent correctly"
5+
assert last parse logs contain "'the exploded blocks' can only be used in the on explode event" with "supported events message did not get sent correctly"

0 commit comments

Comments
 (0)