From 5d7244c51f2528cfde3f09718b39a620587b7eb5 Mon Sep 17 00:00:00 2001 From: TheLimeGlass Date: Fri, 25 Nov 2022 06:52:47 -0700 Subject: [PATCH 01/33] Start structure feature --- .../skript/classes/data/BukkitClasses.java | 32 +++ .../skript/expressions/ExprStructure.java | 105 ++++++++++ .../skript/expressions/ExprStructureInfo.java | 113 +++++++++++ .../expressions/ExprStructureSectionInfo.java | 150 ++++++++++++++ .../skript/sections/EffSecStructurePlace.java | 188 ++++++++++++++++++ src/main/java/ch/njol/skript/util/Utils.java | 18 +- 6 files changed, 605 insertions(+), 1 deletion(-) create mode 100644 src/main/java/ch/njol/skript/expressions/ExprStructure.java create mode 100644 src/main/java/ch/njol/skript/expressions/ExprStructureInfo.java create mode 100644 src/main/java/ch/njol/skript/expressions/ExprStructureSectionInfo.java create mode 100644 src/main/java/ch/njol/skript/sections/EffSecStructurePlace.java diff --git a/src/main/java/ch/njol/skript/classes/data/BukkitClasses.java b/src/main/java/ch/njol/skript/classes/data/BukkitClasses.java index 324cf87d59a..e49b5f142d8 100644 --- a/src/main/java/ch/njol/skript/classes/data/BukkitClasses.java +++ b/src/main/java/ch/njol/skript/classes/data/BukkitClasses.java @@ -70,6 +70,7 @@ import org.bukkit.metadata.Metadatable; import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffectType; +import org.bukkit.structure.Structure; import org.bukkit.util.CachedServerIcon; import org.bukkit.util.Vector; import org.eclipse.jdt.annotation.Nullable; @@ -101,6 +102,7 @@ import ch.njol.skript.util.InventoryActions; import ch.njol.skript.util.PotionEffectUtils; import ch.njol.skript.util.StringMode; +import ch.njol.skript.util.Utils; import ch.njol.util.StringUtils; import ch.njol.yggdrasil.Fields; @@ -1844,5 +1846,35 @@ public String toVariableNameString(Environment environment) { } }) .serializer(new EnumSerializer<>(Environment.class))); + if (Skript.classExists("org.bukkit.structure.Structure")) { + Classes.registerClass(new ClassInfo<>(Structure.class, "structure") + .user("structures?") + .name("Structure") + .description("Represents a structure in a namespace.") + .defaultExpression(new EventValueExpression<>(Structure.class)) + .since("INSERT VERSION") + .parser(new Parser() { + @Override + @Nullable + public Structure parse(String input, ParseContext context) { + return Bukkit.getStructureManager().loadStructure(Utils.getNamespacedKey(input), false); + } + + @Override + public boolean canParse(ParseContext context) { + return context != ParseContext.CONFIG; + } + + @Override + public String toString(Structure structure, int flags) { + return "Structure " + structure.toString(); + } + + @Override + public String toVariableNameString(Structure structure) { + return "Structure " + structure.toString(); + } + })); + } } } diff --git a/src/main/java/ch/njol/skript/expressions/ExprStructure.java b/src/main/java/ch/njol/skript/expressions/ExprStructure.java new file mode 100644 index 00000000000..7fef45c0440 --- /dev/null +++ b/src/main/java/ch/njol/skript/expressions/ExprStructure.java @@ -0,0 +1,105 @@ +package ch.njol.skript.expressions; + +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.event.Event; +import org.bukkit.structure.Structure; +import org.bukkit.structure.StructureManager; +import org.eclipse.jdt.annotation.Nullable; + +import ch.njol.skript.Skript; +import ch.njol.skript.doc.Description; +import ch.njol.skript.doc.Examples; +import ch.njol.skript.doc.Name; +import ch.njol.skript.doc.RequiredPlugins; +import ch.njol.skript.doc.Since; +import ch.njol.skript.lang.Expression; +import ch.njol.skript.lang.ExpressionType; +import ch.njol.skript.lang.SkriptParser.ParseResult; +import ch.njol.skript.lang.util.SimpleExpression; +import ch.njol.skript.util.Utils; +import ch.njol.util.Kleenean; +import ch.njol.util.coll.CollectionUtils; + +@Name("Structures") +@Description({ + "A structure is a utility that allows you to save a cuboid of blocks and entities.", + "This syntax will returns an existing structure from memory or you can also create a structure between two locations.", + "If the name contains a collon, it'll grab from the Minecraft structure space.", +}) +@Examples({ + "set {_structure} to a new structure between {location1} and {location2} named \"Example\"", + "set {_structure} to structure \"Example\"" +}) +@RequiredPlugins("Minecraft 1.17.1+") +@Since("INSERT VERSION") +public class ExprStructure extends SimpleExpression { + + static { + if (Skript.classExists("org.bukkit.structure.Structure")) + Skript.registerExpression(ExprStructure.class, Structure.class, ExpressionType.COMBINED, + "structure[s] [named] %strings%", + "[a] [new] structure between %location% (and|to) %location% [(including|with) :entities] named %string%" + ); + } + + @Nullable + private Expression location1, location2; + private Expression names; + private boolean entities; + + @Override + @SuppressWarnings("unchecked") + public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) { + entities = parseResult.hasTag("entities"); + if (matchedPattern == 0) { + names = (Expression) exprs[0]; + return true; + } + location1 = (Expression) exprs[0]; + location2 = (Expression) exprs[1]; + names = (Expression) exprs[2]; + return true; + } + + @Override + protected Structure[] get(Event event) { + StructureManager manager = Bukkit.getStructureManager(); + + // Returning existing structure. + if (location1 == null || location2 == null) { + return names.stream(event) + .map(name -> Utils.getNamespacedKey(name)) + .map(name -> name != null ? manager.loadStructure(name, false) : null) + .toArray(Structure[]::new); + } + Location location1 = this.location1.getSingle(event); + Location location2 = this.location2.getSingle(event); + String name = this.names.getSingle(event); + if (location1 == null || location2 == null || name == null) + return new Structure[0]; + + Structure structure = manager.loadStructure(Utils.getNamespacedKey(name), true); + structure.fill(location1, location2, entities); + return CollectionUtils.array(structure); + } + + @Override + public boolean isSingle() { + return names.isSingle(); + } + + @Override + public Class getReturnType() { + return Structure.class; + } + + @Override + public String toString(@Nullable Event event, boolean debug) { + if (location1 == null || location2 == null) + return "structures " + names.toString(event, debug); + return "structure " + names.toString(event, debug) + + " from " + location1.toString(event, debug) + " to " + location2.toString(event, debug); + } + +} diff --git a/src/main/java/ch/njol/skript/expressions/ExprStructureInfo.java b/src/main/java/ch/njol/skript/expressions/ExprStructureInfo.java new file mode 100644 index 00000000000..9b096bd0a4c --- /dev/null +++ b/src/main/java/ch/njol/skript/expressions/ExprStructureInfo.java @@ -0,0 +1,113 @@ +package ch.njol.skript.expressions; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import java.util.Locale; + +import org.bukkit.entity.Entity; +import org.bukkit.event.Event; +import org.bukkit.structure.Structure; +import org.bukkit.util.BlockVector; +import org.eclipse.jdt.annotation.Nullable; + +import ch.njol.skript.Skript; +import ch.njol.skript.doc.Description; +import ch.njol.skript.doc.Examples; +import ch.njol.skript.doc.Name; +import ch.njol.skript.doc.RequiredPlugins; +import ch.njol.skript.doc.Since; +import ch.njol.skript.expressions.base.SimplePropertyExpression; +import ch.njol.skript.lang.Expression; +import ch.njol.skript.lang.SkriptParser.ParseResult; +import ch.njol.skript.util.BlockStateBlock; +import ch.njol.util.Kleenean; + +@Name("Structure Info") +@Description("Collect information about a structures' entities, size or blocks.") +@Examples({ + "loop all entities of structure {_structure}:", + "\tif loop-entity is a diamond:", + "\t\tmessage \"Race to the diamond at %loop-entity's location%\" to {_players::*}", + "\t\tstop", + "if the length of {_structure}'s vector is greater than 100:", + "\tmessage \"&a+50 coins will be granted for winning on this larger map!\"" +}) +@RequiredPlugins("Minecraft 1.17.1+") +@Since("INSERT VERSION") +public class ExprStructureInfo extends SimplePropertyExpression { + + static { + if (Skript.classExists("org.bukkit.structure.Structure")) + register(ExprStructureInfo.class, Object.class, "(:blocks|:entities|size:(size|vector))", "structures"); + } + + private enum Property { + BLOCKS(BlockStateBlock.class), + SIZE(BlockVector.class), + ENTITIES(Entity.class); + + private final Class returnType; + + Property(Class returnType) { + this.returnType = returnType; + } + + public Class getReturnType() { + return returnType; + } + } + + @Nullable + private Expression name; + private Property property; + + @Override + @SuppressWarnings("unchecked") + public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) { + property = Property.valueOf(parseResult.tags.get(0).toUpperCase(Locale.ENGLISH)); + setExpr((Expression) exprs[0]); + return true; + } + + @Override + @Nullable + public Object convert(Structure structure) { + switch (property) { + case BLOCKS: + if (structure.getPaletteCount() > 0) + return structure.getPalettes().get(0).getBlocks().stream() + .map(state -> new BlockStateBlock(state, true)) + .toArray(BlockStateBlock[]::new); + case ENTITIES: + return structure.getEntities().toArray(Entity[]::new); + case SIZE: + return structure.getSize(); + } + return null; + } + + @Override + @Nullable + public Iterator iterator(Event event) { + if (property != Property.BLOCKS) + return getExpr().stream(event).map(this::convert).iterator(); + List blocks = new ArrayList<>(); + for (Structure structure : getExpr().getArray(event)) { + if (structure.getPaletteCount() > 0) + blocks.addAll(structure.getPalettes().get(0).getBlocks()); + } + return blocks.iterator(); + } + + @Override + public Class getReturnType() { + return property.getReturnType(); + } + + @Override + protected String getPropertyName() { + return property.name().toLowerCase(Locale.ENGLISH); + } + +} diff --git a/src/main/java/ch/njol/skript/expressions/ExprStructureSectionInfo.java b/src/main/java/ch/njol/skript/expressions/ExprStructureSectionInfo.java new file mode 100644 index 00000000000..d4af0b8439a --- /dev/null +++ b/src/main/java/ch/njol/skript/expressions/ExprStructureSectionInfo.java @@ -0,0 +1,150 @@ +package ch.njol.skript.expressions; + +import java.util.Locale; + +import org.bukkit.Rotation; +import org.bukkit.block.structure.Mirror; +import org.bukkit.block.structure.StructureRotation; +import org.bukkit.event.Event; +import org.eclipse.jdt.annotation.Nullable; + +import ch.njol.skript.Skript; +import ch.njol.skript.classes.Changer.ChangeMode; +import ch.njol.skript.doc.Description; +import ch.njol.skript.doc.Examples; +import ch.njol.skript.doc.Name; +import ch.njol.skript.doc.RequiredPlugins; +import ch.njol.skript.doc.Since; +import ch.njol.skript.lang.Expression; +import ch.njol.skript.lang.ExpressionType; +import ch.njol.skript.lang.SkriptParser.ParseResult; +import ch.njol.skript.lang.util.SimpleExpression; +import ch.njol.skript.sections.EffSecStructurePlace; +import ch.njol.skript.sections.EffSecStructurePlace.StructurePlaceEvent; +import ch.njol.util.Kleenean; +import ch.njol.util.coll.CollectionUtils; + +@Name("Structure Place Settings") +@Description({ + "Returns or modifies the settings for placing of a structure.", + "- includes entities will determine if the enitites saved should spawn when placing.", + "- rotation will allow placement of the structure based on the rotation at the location point.", + "- integrity determines how damaged the building should look by randomly skipping blocks to place. " + + "This value can range from 0 to 1. With 0 removing all blocks and 1 spawning the structure in pristine condition.", + "- pallet index is what iteration of the structure to use, starting at 0, or -1 to pick a random palette. Useful for Minecraft structures.", + "- mirror the mirror setting for the structure on placement." +}) +@Examples({ + "place structure \"minecraft:end_city\" at player's location", + "\tset includes entities to false", + "\tset integrity to 0.9", + "\tset pallet to 2" +}) +@RequiredPlugins("Minecraft 1.17.1+") +@Since("INSERT VERSION") +public class ExprStructureSectionInfo extends SimpleExpression { + + static { + if (Skript.classExists("org.bukkit.structure.Structure")) { + Skript.registerExpression(ExprStructureSectionInfo.class, Object.class, ExpressionType.SIMPLE, + "includes entities", "rotation", "integrity", "pallet [index]", "mirror"); + } + } + + private enum Setting { + INCLUDES_ENTITIES(Boolean.class), + ROTATION(Rotation.class), + INTEGRITY(Float.class), + PALLET(Integer.class), + MIRROR(Mirror.class); + + private final Class returnType; + + Setting(Class returnType) { + this.returnType = returnType; + } + + public Class getReturnType() { + return returnType; + } + } + + private Setting setting; + + @Override + public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) { + if (!getParser().isCurrentSection(EffSecStructurePlace.class)) { + Skript.error(parseResult.expr + " can only be used in a structure place section!"); + return false; + } + setting = Setting.values()[matchedPattern]; + return true; + } + + @Override + protected Object[] get(Event event) { + if (!(event instanceof StructurePlaceEvent)) + return new Object[0]; + StructurePlaceEvent details = (StructurePlaceEvent) event; + switch (setting) { + case INCLUDES_ENTITIES: + return CollectionUtils.array(details.includeEntities()); + case INTEGRITY: + return CollectionUtils.array(details.includeEntities()); + case PALLET: + return CollectionUtils.array(details.includeEntities()); + case MIRROR: + return CollectionUtils.array(details.getMirror()); + case ROTATION: + return CollectionUtils.array(details.getRotation()); + } + return new Object[0]; + } + + public Class[] acceptChange(ChangeMode mode) { + if (mode != ChangeMode.SET) + return null; + if (setting.getReturnType().isAssignableFrom(Number.class)) + return CollectionUtils.array(Number.class); + return CollectionUtils.array(setting.getReturnType()); + } + + public void change(Event event, @Nullable Object[] delta, ChangeMode mode) { + if (!(event instanceof StructurePlaceEvent)) + return; + StructurePlaceEvent details = (StructurePlaceEvent) event; + switch (setting) { + case INCLUDES_ENTITIES: + details.setIncludesEntities((boolean) delta[0]); + break; + case INTEGRITY: + details.setIntegrity(((Number) delta[0]).floatValue()); + break; + case PALLET: + details.setPallet(((Number) delta[0]).intValue()); + break; + case MIRROR: + details.setMirror((Mirror) delta[0]); + break; + case ROTATION: + details.setRotation((StructureRotation) delta[0]); + break; + } + } + + @Override + public boolean isSingle() { + return true; + } + + @Override + public Class getReturnType() { + return setting.getReturnType(); + } + + @Override + public String toString(@Nullable Event event, boolean debug) { + return "structure place setting " + setting.name().toLowerCase(Locale.ENGLISH).replace("_", " "); + } + +} diff --git a/src/main/java/ch/njol/skript/sections/EffSecStructurePlace.java b/src/main/java/ch/njol/skript/sections/EffSecStructurePlace.java new file mode 100644 index 00000000000..3cc6f2a9e3d --- /dev/null +++ b/src/main/java/ch/njol/skript/sections/EffSecStructurePlace.java @@ -0,0 +1,188 @@ +/** + * This file is part of Skript. + * + * Skript is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Skript is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Skript. If not, see . + * + * Copyright Peter Güttinger, SkriptLang team and contributors + */ +package ch.njol.skript.sections; + +import java.util.List; +import java.util.Random; +import java.util.concurrent.atomic.AtomicBoolean; + +import org.bukkit.Location; +import org.bukkit.block.structure.Mirror; +import org.bukkit.block.structure.StructureRotation; +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; +import org.bukkit.structure.Structure; +import org.eclipse.jdt.annotation.Nullable; +import org.jetbrains.annotations.NotNull; + +import ch.njol.skript.Skript; +import ch.njol.skript.config.SectionNode; +import ch.njol.skript.doc.Description; +import ch.njol.skript.doc.Examples; +import ch.njol.skript.doc.Name; +import ch.njol.skript.doc.Since; +import ch.njol.skript.lang.EffectSection; +import ch.njol.skript.lang.Expression; +import ch.njol.skript.lang.SkriptParser.ParseResult; +import ch.njol.skript.lang.Trigger; +import ch.njol.skript.lang.TriggerItem; +import ch.njol.skript.variables.Variables; +import ch.njol.util.Kleenean; + +@Name("Structure Place") +@Description({ + "Places a structure. This can be used as an effect and as a section.", + "If it is used as a section, the section is run before the entity is added to the world.", + "You can modify the entity in this section, using for example 'event-entity' or 'cow'. ", + "Do note that other event values, such as 'player', won't work in this section." +}) +@Examples({ + "spawn 3 creepers at the targeted block", + "spawn a ghast 5 meters above the player", + "spawn a zombie at the player:", + "\tset name of the zombie to \"\"" +}) +@Since("INSERT VERSION") +public class EffSecStructurePlace extends EffectSection { + + public class StructurePlaceEvent extends Event { + + private StructureRotation rotation = StructureRotation.NONE; + private Mirror mirror = Mirror.NONE; + private final Structure structure; + private float integrity = 1F; + private boolean entities; + private int pallet = 0; + + public StructurePlaceEvent(Structure structure, boolean entities) { + this.structure = structure; + this.entities = entities; + } + + public Structure getStructure() { + return structure; + } + + public boolean includeEntities() { + return entities; + } + + public void setIncludesEntities(boolean entities) { + this.entities = entities; + } + + public StructureRotation getRotation() { + return rotation; + } + + public void setRotation(StructureRotation rotation) { + this.rotation = rotation; + } + + public Mirror getMirror() { + return mirror; + } + + public void setMirror(Mirror mirror) { + this.mirror = mirror; + } + + public int getPallet() { + return pallet; + } + + public void setPallet(int pallet) { + this.pallet = pallet; + } + + public float getIntegrity() { + return integrity; + } + + public void setIntegrity(float integrity) { + this.integrity = integrity; + } + + @Override + @NotNull + public HandlerList getHandlers() { + throw new IllegalStateException(); + } + } + + static { + if (Skript.classExists("org.bukkit.structure.Structure")) + Skript.registerSection(EffSecStructurePlace.class, "place %structure% at %locations% [without :entities]"); + } + + private Expression structure; + private Expression locations; + private boolean entities; + + @Nullable + private Trigger trigger; + + @Override + @SuppressWarnings("unchecked") + public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult, @Nullable SectionNode sectionNode, @Nullable List triggerItems) { + structure = (Expression) exprs[0]; + locations = (Expression) exprs[1]; + entities = !parseResult.hasTag("entities"); // Negated + + if (sectionNode != null) { + AtomicBoolean delayed = new AtomicBoolean(false); + Runnable afterLoading = () -> delayed.set(!getParser().getHasDelayBefore().isFalse()); + trigger = loadCode(sectionNode, "structure place", afterLoading, StructurePlaceEvent.class); + if (delayed.get()) { + Skript.error("Delays can't be used within a structure place event!"); + return false; + } + } + return true; + } + + @Override + @Nullable + protected TriggerItem walk(Event event) { + Structure structure = this.structure.getSingle(event); + if (structure == null) { + debug(event, false); + return getNext(); + } + StructurePlaceEvent details = new StructurePlaceEvent(structure, entities); + if (trigger != null) { + Object localVars = Variables.copyLocalVariables(event); + Variables.setLocalVariables(details, localVars); + TriggerItem.walk(trigger, details); + Variables.setLocalVariables(event, Variables.copyLocalVariables(details)); + Variables.removeLocals(details); + } + + for (Location location : locations.getArray(event)) + structure.place(location, details.includeEntities(), details.getRotation(), details.getMirror(), details.getPallet(), details.getIntegrity(), new Random()); + + return super.walk(event, false); + } + + @Override + public String toString(@Nullable Event event, boolean debug) { + return "place structure " + structure.toString(event, debug) + " at " + locations.toString(event, debug); + } + +} diff --git a/src/main/java/ch/njol/skript/util/Utils.java b/src/main/java/ch/njol/skript/util/Utils.java index 7598fb83b74..2bd3f2d13a1 100644 --- a/src/main/java/ch/njol/skript/util/Utils.java +++ b/src/main/java/ch/njol/skript/util/Utils.java @@ -30,6 +30,7 @@ import java.util.stream.Stream; import org.bukkit.Bukkit; +import org.bukkit.NamespacedKey; import org.bukkit.entity.Player; import org.bukkit.plugin.messaging.Messenger; import org.bukkit.plugin.messaging.PluginMessageListener; @@ -686,5 +687,20 @@ public static int findLastIndex(List list, Checker checker) { } return lastIndex; } - + + /** + * Returns a namespaced key. If the key contains a collon, it'll lookup a Minecraft key. + * Otherwise will return a key registered under Skript. + * Will return null if the Minecraft key doesn't exist. + * + * @param key The string key to lookup. + * @return The found NamespacedKey or null if not found when using a collon. + */ + @Nullable + public static NamespacedKey getNamespacedKey(String key) { + if (key.contains(":")) + return NamespacedKey.fromString(key); + return NamespacedKey.fromString(key, Skript.getInstance()); + } + } From a73ac5c37089bb0f4dd9b8be5323d6181481e6fe Mon Sep 17 00:00:00 2001 From: TheLimeGlass Date: Fri, 25 Nov 2022 07:09:52 -0700 Subject: [PATCH 02/33] Commit changes so far --- .../skript/classes/data/BukkitClasses.java | 20 ++++++++++++++++++- src/main/resources/lang/default.lang | 16 +++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/src/main/java/ch/njol/skript/classes/data/BukkitClasses.java b/src/main/java/ch/njol/skript/classes/data/BukkitClasses.java index c3fe5feb758..1821ec9929b 100644 --- a/src/main/java/ch/njol/skript/classes/data/BukkitClasses.java +++ b/src/main/java/ch/njol/skript/classes/data/BukkitClasses.java @@ -36,6 +36,7 @@ import org.bukkit.GameRule; import org.bukkit.Location; import org.bukkit.Material; +import org.bukkit.NamespacedKey; import org.bukkit.OfflinePlayer; import org.bukkit.SoundCategory; import org.bukkit.World; @@ -46,6 +47,8 @@ import org.bukkit.block.BlockState; import org.bukkit.block.DoubleChest; import org.bukkit.block.data.BlockData; +import org.bukkit.block.structure.Mirror; +import org.bukkit.block.structure.StructureRotation; import org.bukkit.command.CommandSender; import org.bukkit.enchantments.Enchantment; import org.bukkit.enchantments.EnchantmentOffer; @@ -1503,7 +1506,10 @@ public String toVariableNameString(EnchantmentOffer eo) { @Override @Nullable public Structure parse(String input, ParseContext context) { - return Bukkit.getStructureManager().loadStructure(Utils.getNamespacedKey(input), false); + NamespacedKey key = Utils.getNamespacedKey(input); + if (key == null) + return null; + return Bukkit.getStructureManager().loadStructure(key, false); } @Override @@ -1521,6 +1527,18 @@ public String toVariableNameString(Structure structure) { return "Structure " + structure.toString(); } })); + + Classes.registerClass(new EnumClassInfo<>(StructureRotation.class, "structurerotation", "structure rotations") + .user("structure ?rotations?") + .name("Structure Rotations") + .description("Represents a rotation a structure can be rotated as when placed.") + .since("INSERT VERSION")); + + Classes.registerClass(new EnumClassInfo<>(Mirror.class, "mirror", "mirrors") + .user("mirrors?") + .name("mirror") + .description("Represents a mirror setting a structure can be when placed.") + .since("INSERT VERSION")); } } } diff --git a/src/main/resources/lang/default.lang b/src/main/resources/lang/default.lang index 58bac190ed4..6a3c729c113 100644 --- a/src/main/resources/lang/default.lang +++ b/src/main/resources/lang/default.lang @@ -1874,6 +1874,19 @@ moon phases: waxing_crescent: waxing crescent waxing_gibbous: waxing gibbous +# -- Structure Rotations -- +structure rotations: + clockwise_180: clockwise 180 + clockwise_90: clockwise 90 + counterclockwise_90: counter clockwise 90: + none: none, default + +# -- Structure Mirrors -- +mirrors: + front_back: front back, front to back + left_right: left right, left to right + none: none, default + # -- Boolean -- boolean: true: @@ -1937,6 +1950,9 @@ types: gamerule: gamerule¦s @a attributetype: attribute type¦s @a enchantmentoffer: enchantment offer¦s @a + structure: structure¦s @a + structurerotation: structure rotation¦s @a + mirror: mirror¦s @a # Skript weathertype: weather type¦s @a From a36264af621b3190b80822888eedfcf981131d72 Mon Sep 17 00:00:00 2001 From: TheLimeGlass Date: Fri, 25 Nov 2022 16:17:20 -0700 Subject: [PATCH 03/33] Complete Structures --- .../skript/classes/data/BukkitClasses.java | 3 + .../conditions/CondStructureExists.java | 59 +++++++++++++++ .../effects/EffStructureSaveUnregister.java | 71 +++++++++++++++++++ .../expressions/ExprStructureSectionInfo.java | 16 +++-- .../skript/sections/EffSecStructurePlace.java | 16 +++-- src/main/resources/lang/default.lang | 2 +- 6 files changed, 155 insertions(+), 12 deletions(-) create mode 100644 src/main/java/ch/njol/skript/conditions/CondStructureExists.java create mode 100644 src/main/java/ch/njol/skript/effects/EffStructureSaveUnregister.java diff --git a/src/main/java/ch/njol/skript/classes/data/BukkitClasses.java b/src/main/java/ch/njol/skript/classes/data/BukkitClasses.java index 1821ec9929b..95c468090b5 100644 --- a/src/main/java/ch/njol/skript/classes/data/BukkitClasses.java +++ b/src/main/java/ch/njol/skript/classes/data/BukkitClasses.java @@ -1501,6 +1501,7 @@ public String toVariableNameString(EnchantmentOffer eo) { .name("Structure") .description("Represents a structure in a namespace.") .defaultExpression(new EventValueExpression<>(Structure.class)) + .requiredPlugins("Minecraft 1.17.1") .since("INSERT VERSION") .parser(new Parser() { @Override @@ -1532,12 +1533,14 @@ public String toVariableNameString(Structure structure) { .user("structure ?rotations?") .name("Structure Rotations") .description("Represents a rotation a structure can be rotated as when placed.") + .requiredPlugins("Minecraft 1.17.1") .since("INSERT VERSION")); Classes.registerClass(new EnumClassInfo<>(Mirror.class, "mirror", "mirrors") .user("mirrors?") .name("mirror") .description("Represents a mirror setting a structure can be when placed.") + .requiredPlugins("Minecraft 1.17.1") .since("INSERT VERSION")); } } diff --git a/src/main/java/ch/njol/skript/conditions/CondStructureExists.java b/src/main/java/ch/njol/skript/conditions/CondStructureExists.java new file mode 100644 index 00000000000..075b09475b7 --- /dev/null +++ b/src/main/java/ch/njol/skript/conditions/CondStructureExists.java @@ -0,0 +1,59 @@ +package ch.njol.skript.conditions; + +import org.bukkit.Bukkit; +import org.bukkit.NamespacedKey; +import org.bukkit.event.Event; +import org.eclipse.jdt.annotation.Nullable; + +import ch.njol.skript.Skript; +import ch.njol.skript.doc.Description; +import ch.njol.skript.doc.Examples; +import ch.njol.skript.doc.Name; +import ch.njol.skript.doc.RequiredPlugins; +import ch.njol.skript.doc.Since; +import ch.njol.skript.lang.Condition; +import ch.njol.skript.lang.Expression; +import ch.njol.skript.lang.SkriptParser.ParseResult; +import ch.njol.skript.util.Utils; +import ch.njol.util.Kleenean; + +@Name("Structure Exists") +@Description("Check if structures exist.") +@Examples("if structure named \"Example\" does exist") +@RequiredPlugins("Minecraft 1.17.1+") +@Since("INSERT VERSION") +public class CondStructureExists extends Condition { + + static { + Skript.registerCondition(CondStructureExists.class, + "structure[s] [named] %strings% [do[es]] exist[s]", + "structure[s] [named] %strings% (doesn't|do[es] not) exist" + ); + } + + private Expression names; + + @Override + @SuppressWarnings("unchecked") + public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) { + names = (Expression) exprs[0]; + setNegated(matchedPattern == 1); + return true; + } + + @Override + public boolean check(Event event) { + return names.check(event, name -> { + NamespacedKey key = Utils.getNamespacedKey(name); + if (key == null) + return false; + return Bukkit.getStructureManager().loadStructure(key, false) != null; + }, isNegated()); + } + + @Override + public String toString(@Nullable Event event, boolean debug) { + return "structures " + names.toString(event, debug) + (names.isSingle() ? " does " : " do ") + (isNegated() ? "not " : "") + " exist"; + } + +} diff --git a/src/main/java/ch/njol/skript/effects/EffStructureSaveUnregister.java b/src/main/java/ch/njol/skript/effects/EffStructureSaveUnregister.java new file mode 100644 index 00000000000..df582a56ab4 --- /dev/null +++ b/src/main/java/ch/njol/skript/effects/EffStructureSaveUnregister.java @@ -0,0 +1,71 @@ +package ch.njol.skript.effects; + +import java.io.IOException; + +import org.bukkit.Bukkit; +import org.bukkit.NamespacedKey; +import org.bukkit.event.Event; +import org.bukkit.structure.StructureManager; +import org.eclipse.jdt.annotation.Nullable; + +import ch.njol.skript.Skript; +import ch.njol.skript.doc.Description; +import ch.njol.skript.doc.Examples; +import ch.njol.skript.doc.Name; +import ch.njol.skript.doc.RequiredPlugins; +import ch.njol.skript.doc.Since; +import ch.njol.skript.lang.Effect; +import ch.njol.skript.lang.Expression; +import ch.njol.skript.lang.SkriptParser.ParseResult; +import ch.njol.skript.util.Utils; +import ch.njol.util.Kleenean; + +@Name("Structure Place Settings") +@Description("Unregisters or saves a structure by it's namespace key.") +@Examples("unregister structure named \"Example\"") +@RequiredPlugins("Minecraft 1.17.1+") +@Since("INSERT VERSION") +public class EffStructureSaveUnregister extends Effect { + + static { + Skript.registerEffect(EffStructureSaveUnregister.class, "(:save|(delete|unregister)) structure[s] [named] %strings%"); + } + + private Expression names; + private boolean save; + + @Override + @SuppressWarnings("unchecked") + public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) { + names = (Expression) exprs[0]; + save = parseResult.hasTag("save"); + return true; + } + + @Override + protected void execute(Event event) { + StructureManager manager = Bukkit.getStructureManager(); + for (String name : names.getArray(event)) { + NamespacedKey key = Utils.getNamespacedKey(name); + if (key == null) + continue; + if (save) { + manager.saveStructure(key); + } else { + try { + manager.deleteStructure(key); + } catch (IOException e) { + Skript.error("Failed to save structure " + name); + if (Skript.debug()) + e.printStackTrace(); + } + } + } + } + + @Override + public String toString(@Nullable Event event, boolean debug) { + return save ? "save " : "delete " + " structures " + names.toString(event, debug); + } + +} diff --git a/src/main/java/ch/njol/skript/expressions/ExprStructureSectionInfo.java b/src/main/java/ch/njol/skript/expressions/ExprStructureSectionInfo.java index d4af0b8439a..32ce64f0882 100644 --- a/src/main/java/ch/njol/skript/expressions/ExprStructureSectionInfo.java +++ b/src/main/java/ch/njol/skript/expressions/ExprStructureSectionInfo.java @@ -32,13 +32,16 @@ "- integrity determines how damaged the building should look by randomly skipping blocks to place. " + "This value can range from 0 to 1. With 0 removing all blocks and 1 spawning the structure in pristine condition.", "- pallet index is what iteration of the structure to use, starting at 0, or -1 to pick a random palette. Useful for Minecraft structures.", - "- mirror the mirror setting for the structure on placement." + "- mirror the mirror setting for the structure on placement.", + "Default settings for settings are rotation = none, pallet = 0, mirror = none, entities = true, integrity = 1" }) @Examples({ "place structure \"minecraft:end_city\" at player's location", "\tset includes entities to false", "\tset integrity to 0.9", - "\tset pallet to 2" + "\tset pallet to 2", + "\tset rotation to clockwise 90", + "\tset mirror to left to right" }) @RequiredPlugins("Minecraft 1.17.1+") @Since("INSERT VERSION") @@ -110,6 +113,8 @@ public Class[] acceptChange(ChangeMode mode) { } public void change(Event event, @Nullable Object[] delta, ChangeMode mode) { + if (delta == null) + return; if (!(event instanceof StructurePlaceEvent)) return; StructurePlaceEvent details = (StructurePlaceEvent) event; @@ -118,10 +123,13 @@ public void change(Event event, @Nullable Object[] delta, ChangeMode mode) { details.setIncludesEntities((boolean) delta[0]); break; case INTEGRITY: - details.setIntegrity(((Number) delta[0]).floatValue()); + float integrity = ((Number) delta[0]).floatValue(); + details.setIntegrity(Math.min(1, Math.max(0, integrity))); break; case PALLET: - details.setPallet(((Number) delta[0]).intValue()); + int pallet = ((Number) delta[0]).intValue(); + int max = details.getStructure().getPaletteCount(); + details.setPallet(Math.min(max, Math.max(-1, pallet))); break; case MIRROR: details.setMirror((Mirror) delta[0]); diff --git a/src/main/java/ch/njol/skript/sections/EffSecStructurePlace.java b/src/main/java/ch/njol/skript/sections/EffSecStructurePlace.java index 3cc6f2a9e3d..71805d14047 100644 --- a/src/main/java/ch/njol/skript/sections/EffSecStructurePlace.java +++ b/src/main/java/ch/njol/skript/sections/EffSecStructurePlace.java @@ -48,15 +48,17 @@ @Name("Structure Place") @Description({ "Places a structure. This can be used as an effect and as a section.", - "If it is used as a section, the section is run before the entity is added to the world.", - "You can modify the entity in this section, using for example 'event-entity' or 'cow'. ", - "Do note that other event values, such as 'player', won't work in this section." + "If it is used as a section, the section is run before the structure is placed in the world.", + "You can modify the place settings like if it should include entities and any rotation/mirror option you want.", + "For more info on the section settings see Structure Place Settings" }) @Examples({ - "spawn 3 creepers at the targeted block", - "spawn a ghast 5 meters above the player", - "spawn a zombie at the player:", - "\tset name of the zombie to \"\"" + "place structure \"minecraft:end_city\" at player's location without entities", + "\tset integrity to 0.9", + "\tset pallet to -1 # -1 for random pallet", + "\tset pallet to -1 # random pallet", + "\tset rotation to counter clockwise 90", + "\tset mirror to none # already the default not required" }) @Since("INSERT VERSION") public class EffSecStructurePlace extends EffectSection { diff --git a/src/main/resources/lang/default.lang b/src/main/resources/lang/default.lang index 6a3c729c113..6e231444656 100644 --- a/src/main/resources/lang/default.lang +++ b/src/main/resources/lang/default.lang @@ -1878,7 +1878,7 @@ moon phases: structure rotations: clockwise_180: clockwise 180 clockwise_90: clockwise 90 - counterclockwise_90: counter clockwise 90: + counterclockwise_90: counter clockwise 90 none: none, default # -- Structure Mirrors -- From 4af3260030077004c5175dc76bfd2daf046b7e19 Mon Sep 17 00:00:00 2001 From: TheLimeGlass Date: Fri, 25 Nov 2022 16:20:37 -0700 Subject: [PATCH 04/33] Add minecraft structure get example --- src/main/java/ch/njol/skript/expressions/ExprStructure.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/ch/njol/skript/expressions/ExprStructure.java b/src/main/java/ch/njol/skript/expressions/ExprStructure.java index 7fef45c0440..1cbfea76f5f 100644 --- a/src/main/java/ch/njol/skript/expressions/ExprStructure.java +++ b/src/main/java/ch/njol/skript/expressions/ExprStructure.java @@ -29,7 +29,8 @@ }) @Examples({ "set {_structure} to a new structure between {location1} and {location2} named \"Example\"", - "set {_structure} to structure \"Example\"" + "set {_structure} to structure \"Example\"", + "set {_structure} to structure \"minecraft:end_city\"" }) @RequiredPlugins("Minecraft 1.17.1+") @Since("INSERT VERSION") From 87a0fc717eab57c2e044bd77e88fff921d57fc73 Mon Sep 17 00:00:00 2001 From: TheLimeGlass Date: Fri, 25 Nov 2022 16:26:14 -0700 Subject: [PATCH 05/33] Add collon to section examples --- .../ch/njol/skript/expressions/ExprStructureSectionInfo.java | 2 +- src/main/java/ch/njol/skript/sections/EffSecStructurePlace.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/ch/njol/skript/expressions/ExprStructureSectionInfo.java b/src/main/java/ch/njol/skript/expressions/ExprStructureSectionInfo.java index 32ce64f0882..44bff306e82 100644 --- a/src/main/java/ch/njol/skript/expressions/ExprStructureSectionInfo.java +++ b/src/main/java/ch/njol/skript/expressions/ExprStructureSectionInfo.java @@ -36,7 +36,7 @@ "Default settings for settings are rotation = none, pallet = 0, mirror = none, entities = true, integrity = 1" }) @Examples({ - "place structure \"minecraft:end_city\" at player's location", + "place structure \"minecraft:end_city\" at player's location:", "\tset includes entities to false", "\tset integrity to 0.9", "\tset pallet to 2", diff --git a/src/main/java/ch/njol/skript/sections/EffSecStructurePlace.java b/src/main/java/ch/njol/skript/sections/EffSecStructurePlace.java index 71805d14047..73204090251 100644 --- a/src/main/java/ch/njol/skript/sections/EffSecStructurePlace.java +++ b/src/main/java/ch/njol/skript/sections/EffSecStructurePlace.java @@ -53,7 +53,7 @@ "For more info on the section settings see Structure Place Settings" }) @Examples({ - "place structure \"minecraft:end_city\" at player's location without entities", + "place structure \"minecraft:end_city\" at player's location without entities:", "\tset integrity to 0.9", "\tset pallet to -1 # -1 for random pallet", "\tset pallet to -1 # random pallet", From 510e7204d643941721826d58fbebb4e63528d032 Mon Sep 17 00:00:00 2001 From: TheLimeGlass Date: Fri, 25 Nov 2022 16:27:55 -0700 Subject: [PATCH 06/33] license update --- .../skript/conditions/CondStructureExists.java | 18 ++++++++++++++++++ .../effects/EffStructureSaveUnregister.java | 18 ++++++++++++++++++ .../njol/skript/expressions/ExprStructure.java | 18 ++++++++++++++++++ .../skript/expressions/ExprStructureInfo.java | 18 ++++++++++++++++++ .../expressions/ExprStructureSectionInfo.java | 18 ++++++++++++++++++ 5 files changed, 90 insertions(+) diff --git a/src/main/java/ch/njol/skript/conditions/CondStructureExists.java b/src/main/java/ch/njol/skript/conditions/CondStructureExists.java index 075b09475b7..654db8dd464 100644 --- a/src/main/java/ch/njol/skript/conditions/CondStructureExists.java +++ b/src/main/java/ch/njol/skript/conditions/CondStructureExists.java @@ -1,3 +1,21 @@ +/** + * This file is part of Skript. + * + * Skript is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Skript is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Skript. If not, see . + * + * Copyright Peter Güttinger, SkriptLang team and contributors + */ package ch.njol.skript.conditions; import org.bukkit.Bukkit; diff --git a/src/main/java/ch/njol/skript/effects/EffStructureSaveUnregister.java b/src/main/java/ch/njol/skript/effects/EffStructureSaveUnregister.java index df582a56ab4..cd6f2c2ecef 100644 --- a/src/main/java/ch/njol/skript/effects/EffStructureSaveUnregister.java +++ b/src/main/java/ch/njol/skript/effects/EffStructureSaveUnregister.java @@ -1,3 +1,21 @@ +/** + * This file is part of Skript. + * + * Skript is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Skript is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Skript. If not, see . + * + * Copyright Peter Güttinger, SkriptLang team and contributors + */ package ch.njol.skript.effects; import java.io.IOException; diff --git a/src/main/java/ch/njol/skript/expressions/ExprStructure.java b/src/main/java/ch/njol/skript/expressions/ExprStructure.java index 1cbfea76f5f..6ce37e8fdde 100644 --- a/src/main/java/ch/njol/skript/expressions/ExprStructure.java +++ b/src/main/java/ch/njol/skript/expressions/ExprStructure.java @@ -1,3 +1,21 @@ +/** + * This file is part of Skript. + * + * Skript is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Skript is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Skript. If not, see . + * + * Copyright Peter Güttinger, SkriptLang team and contributors + */ package ch.njol.skript.expressions; import org.bukkit.Bukkit; diff --git a/src/main/java/ch/njol/skript/expressions/ExprStructureInfo.java b/src/main/java/ch/njol/skript/expressions/ExprStructureInfo.java index 9b096bd0a4c..42721256365 100644 --- a/src/main/java/ch/njol/skript/expressions/ExprStructureInfo.java +++ b/src/main/java/ch/njol/skript/expressions/ExprStructureInfo.java @@ -1,3 +1,21 @@ +/** + * This file is part of Skript. + * + * Skript is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Skript is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Skript. If not, see . + * + * Copyright Peter Güttinger, SkriptLang team and contributors + */ package ch.njol.skript.expressions; import java.util.ArrayList; diff --git a/src/main/java/ch/njol/skript/expressions/ExprStructureSectionInfo.java b/src/main/java/ch/njol/skript/expressions/ExprStructureSectionInfo.java index 44bff306e82..f97f694b005 100644 --- a/src/main/java/ch/njol/skript/expressions/ExprStructureSectionInfo.java +++ b/src/main/java/ch/njol/skript/expressions/ExprStructureSectionInfo.java @@ -1,3 +1,21 @@ +/** + * This file is part of Skript. + * + * Skript is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Skript is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Skript. If not, see . + * + * Copyright Peter Güttinger, SkriptLang team and contributors + */ package ch.njol.skript.expressions; import java.util.Locale; From faea94880f26146dba3d60dad03aecaca571bcf9 Mon Sep 17 00:00:00 2001 From: TheLimeGlass Date: Fri, 25 Nov 2022 16:46:09 -0700 Subject: [PATCH 07/33] Cache StructureManager before loop --- .../java/ch/njol/skript/conditions/CondStructureExists.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/ch/njol/skript/conditions/CondStructureExists.java b/src/main/java/ch/njol/skript/conditions/CondStructureExists.java index 654db8dd464..7b805f2e52e 100644 --- a/src/main/java/ch/njol/skript/conditions/CondStructureExists.java +++ b/src/main/java/ch/njol/skript/conditions/CondStructureExists.java @@ -21,6 +21,7 @@ import org.bukkit.Bukkit; import org.bukkit.NamespacedKey; import org.bukkit.event.Event; +import org.bukkit.structure.StructureManager; import org.eclipse.jdt.annotation.Nullable; import ch.njol.skript.Skript; @@ -61,11 +62,12 @@ public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelaye @Override public boolean check(Event event) { + StructureManager manager = Bukkit.getStructureManager(); return names.check(event, name -> { NamespacedKey key = Utils.getNamespacedKey(name); if (key == null) return false; - return Bukkit.getStructureManager().loadStructure(key, false) != null; + return manager.loadStructure(key, false) != null; }, isNegated()); } From 2e7080dfc9c5a4af891352a05722e0860039236b Mon Sep 17 00:00:00 2001 From: TheLimeGlass Date: Fri, 25 Nov 2022 16:52:43 -0700 Subject: [PATCH 08/33] Fix error message --- src/main/java/ch/njol/skript/sections/EffSecStructurePlace.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/ch/njol/skript/sections/EffSecStructurePlace.java b/src/main/java/ch/njol/skript/sections/EffSecStructurePlace.java index 73204090251..031b5ecf5d7 100644 --- a/src/main/java/ch/njol/skript/sections/EffSecStructurePlace.java +++ b/src/main/java/ch/njol/skript/sections/EffSecStructurePlace.java @@ -152,7 +152,7 @@ public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelaye Runnable afterLoading = () -> delayed.set(!getParser().getHasDelayBefore().isFalse()); trigger = loadCode(sectionNode, "structure place", afterLoading, StructurePlaceEvent.class); if (delayed.get()) { - Skript.error("Delays can't be used within a structure place event!"); + Skript.error("Delays can't be used within a structure place section!"); return false; } } From d21a0560113e3f041646f3da3ea26e77bfe99937 Mon Sep 17 00:00:00 2001 From: TheLimeGlass Date: Fri, 25 Nov 2022 16:55:24 -0700 Subject: [PATCH 09/33] Fix name doc --- .../java/ch/njol/skript/effects/EffStructureSaveUnregister.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/ch/njol/skript/effects/EffStructureSaveUnregister.java b/src/main/java/ch/njol/skript/effects/EffStructureSaveUnregister.java index cd6f2c2ecef..b5e3927c67b 100644 --- a/src/main/java/ch/njol/skript/effects/EffStructureSaveUnregister.java +++ b/src/main/java/ch/njol/skript/effects/EffStructureSaveUnregister.java @@ -38,7 +38,7 @@ import ch.njol.skript.util.Utils; import ch.njol.util.Kleenean; -@Name("Structure Place Settings") +@Name("Structure Save/Unregister") @Description("Unregisters or saves a structure by it's namespace key.") @Examples("unregister structure named \"Example\"") @RequiredPlugins("Minecraft 1.17.1+") From e0ebb1d0e45b4c685753508ac4a6ad5da85b4589 Mon Sep 17 00:00:00 2001 From: TheLimeGlass Date: Fri, 25 Nov 2022 17:10:10 -0700 Subject: [PATCH 10/33] Describe more in the docs --- .../njol/skript/expressions/ExprStructure.java | 6 +++--- .../skript/expressions/ExprStructureInfo.java | 2 +- .../expressions/ExprStructureSectionInfo.java | 16 ++++++++++++---- 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/main/java/ch/njol/skript/expressions/ExprStructure.java b/src/main/java/ch/njol/skript/expressions/ExprStructure.java index 6ce37e8fdde..3e4c85b6f55 100644 --- a/src/main/java/ch/njol/skript/expressions/ExprStructure.java +++ b/src/main/java/ch/njol/skript/expressions/ExprStructure.java @@ -42,8 +42,8 @@ @Name("Structures") @Description({ "A structure is a utility that allows you to save a cuboid of blocks and entities.", - "This syntax will returns an existing structure from memory or you can also create a structure between two locations.", - "If the name contains a collon, it'll grab from the Minecraft structure space.", + "This syntax will return an existing structure from memory/datapacks or you can also create a structure between two locations.", + "If the name contains a collon, it'll grab from the Minecraft structure space (Data packs included for namespaces).", }) @Examples({ "set {_structure} to a new structure between {location1} and {location2} named \"Example\"", @@ -85,7 +85,7 @@ public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelaye protected Structure[] get(Event event) { StructureManager manager = Bukkit.getStructureManager(); - // Returning existing structure. + // Returning existing structures. if (location1 == null || location2 == null) { return names.stream(event) .map(name -> Utils.getNamespacedKey(name)) diff --git a/src/main/java/ch/njol/skript/expressions/ExprStructureInfo.java b/src/main/java/ch/njol/skript/expressions/ExprStructureInfo.java index 42721256365..180b63d6556 100644 --- a/src/main/java/ch/njol/skript/expressions/ExprStructureInfo.java +++ b/src/main/java/ch/njol/skript/expressions/ExprStructureInfo.java @@ -57,7 +57,7 @@ public class ExprStructureInfo extends SimplePropertyExpression Date: Wed, 28 Dec 2022 00:43:16 -0700 Subject: [PATCH 11/33] Apply suggestions from code review Co-authored-by: Patrick Miller --- src/main/java/ch/njol/skript/classes/data/BukkitClasses.java | 4 ++-- .../ch/njol/skript/effects/EffStructureSaveUnregister.java | 2 +- src/main/java/ch/njol/skript/expressions/ExprStructure.java | 4 ++-- .../java/ch/njol/skript/expressions/ExprStructureInfo.java | 2 +- .../ch/njol/skript/expressions/ExprStructureSectionInfo.java | 3 ++- .../java/ch/njol/skript/sections/EffSecStructurePlace.java | 2 +- 6 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/main/java/ch/njol/skript/classes/data/BukkitClasses.java b/src/main/java/ch/njol/skript/classes/data/BukkitClasses.java index 95c468090b5..d1a29fdfed9 100644 --- a/src/main/java/ch/njol/skript/classes/data/BukkitClasses.java +++ b/src/main/java/ch/njol/skript/classes/data/BukkitClasses.java @@ -1520,12 +1520,12 @@ public boolean canParse(ParseContext context) { @Override public String toString(Structure structure, int flags) { - return "Structure " + structure.toString(); + return "structure " + structure.toString(); } @Override public String toVariableNameString(Structure structure) { - return "Structure " + structure.toString(); + return toString(structure, 0); } })); diff --git a/src/main/java/ch/njol/skript/effects/EffStructureSaveUnregister.java b/src/main/java/ch/njol/skript/effects/EffStructureSaveUnregister.java index b5e3927c67b..1ae7ff7e1c2 100644 --- a/src/main/java/ch/njol/skript/effects/EffStructureSaveUnregister.java +++ b/src/main/java/ch/njol/skript/effects/EffStructureSaveUnregister.java @@ -83,7 +83,7 @@ protected void execute(Event event) { @Override public String toString(@Nullable Event event, boolean debug) { - return save ? "save " : "delete " + " structures " + names.toString(event, debug); + return (save ? "save" : "delete") + " structures " + names.toString(event, debug); } } diff --git a/src/main/java/ch/njol/skript/expressions/ExprStructure.java b/src/main/java/ch/njol/skript/expressions/ExprStructure.java index 3e4c85b6f55..81526674a72 100644 --- a/src/main/java/ch/njol/skript/expressions/ExprStructure.java +++ b/src/main/java/ch/njol/skript/expressions/ExprStructure.java @@ -117,8 +117,8 @@ public Class getReturnType() { public String toString(@Nullable Event event, boolean debug) { if (location1 == null || location2 == null) return "structures " + names.toString(event, debug); - return "structure " + names.toString(event, debug) - + " from " + location1.toString(event, debug) + " to " + location2.toString(event, debug); + return "structure " + names.toString(event, debug) + + " from " + location1.toString(event, debug) + " to " + location2.toString(event, debug); } } diff --git a/src/main/java/ch/njol/skript/expressions/ExprStructureInfo.java b/src/main/java/ch/njol/skript/expressions/ExprStructureInfo.java index 180b63d6556..aff79f05032 100644 --- a/src/main/java/ch/njol/skript/expressions/ExprStructureInfo.java +++ b/src/main/java/ch/njol/skript/expressions/ExprStructureInfo.java @@ -42,7 +42,7 @@ import ch.njol.util.Kleenean; @Name("Structure Info") -@Description("Collect information about a structures' entities, size or blocks.") +@Description("An expression to obtain information about a structure's entities, size, and blocks.") @Examples({ "loop all entities of structure {_structure}:", "\tif loop-entity is a diamond:", diff --git a/src/main/java/ch/njol/skript/expressions/ExprStructureSectionInfo.java b/src/main/java/ch/njol/skript/expressions/ExprStructureSectionInfo.java index d254e185572..05570954aa0 100644 --- a/src/main/java/ch/njol/skript/expressions/ExprStructureSectionInfo.java +++ b/src/main/java/ch/njol/skript/expressions/ExprStructureSectionInfo.java @@ -76,7 +76,8 @@ public class ExprStructureSectionInfo extends SimpleExpression { static { if (Skript.classExists("org.bukkit.structure.Structure")) { Skript.registerExpression(ExprStructureSectionInfo.class, Object.class, ExpressionType.SIMPLE, - "includes entities", "rotation", "integrity", "pallet [index]", "mirror"); + "includes entities", "rotation", "integrity", "pallet [index]", "mirror" + ); } } diff --git a/src/main/java/ch/njol/skript/sections/EffSecStructurePlace.java b/src/main/java/ch/njol/skript/sections/EffSecStructurePlace.java index 031b5ecf5d7..6bf35f2c3c4 100644 --- a/src/main/java/ch/njol/skript/sections/EffSecStructurePlace.java +++ b/src/main/java/ch/njol/skript/sections/EffSecStructurePlace.java @@ -165,7 +165,7 @@ protected TriggerItem walk(Event event) { Structure structure = this.structure.getSingle(event); if (structure == null) { debug(event, false); - return getNext(); + return super.walk(event, false); } StructurePlaceEvent details = new StructurePlaceEvent(structure, entities); if (trigger != null) { From b107f290c93a248ea1fa9f76b6189ee61ef48a56 Mon Sep 17 00:00:00 2001 From: LimeGlass <16087552+TheLimeGlass@users.noreply.github.com> Date: Wed, 28 Dec 2022 00:46:04 -0700 Subject: [PATCH 12/33] Update EffStructureSaveUnregister.java --- .../java/ch/njol/skript/effects/EffStructureSaveUnregister.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/ch/njol/skript/effects/EffStructureSaveUnregister.java b/src/main/java/ch/njol/skript/effects/EffStructureSaveUnregister.java index 1ae7ff7e1c2..f1fe3c03231 100644 --- a/src/main/java/ch/njol/skript/effects/EffStructureSaveUnregister.java +++ b/src/main/java/ch/njol/skript/effects/EffStructureSaveUnregister.java @@ -73,7 +73,7 @@ protected void execute(Event event) { try { manager.deleteStructure(key); } catch (IOException e) { - Skript.error("Failed to save structure " + name); + Skript.exception(e, "Failed to save structure " + name); if (Skript.debug()) e.printStackTrace(); } From 8b6a4db021356250a32e4fec0865b8097c493263 Mon Sep 17 00:00:00 2001 From: LimeGlass <16087552+TheLimeGlass@users.noreply.github.com> Date: Wed, 28 Dec 2022 00:47:17 -0700 Subject: [PATCH 13/33] Add support for don't --- .../java/ch/njol/skript/conditions/CondStructureExists.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/ch/njol/skript/conditions/CondStructureExists.java b/src/main/java/ch/njol/skript/conditions/CondStructureExists.java index 7b805f2e52e..ea18eb6109b 100644 --- a/src/main/java/ch/njol/skript/conditions/CondStructureExists.java +++ b/src/main/java/ch/njol/skript/conditions/CondStructureExists.java @@ -46,7 +46,7 @@ public class CondStructureExists extends Condition { static { Skript.registerCondition(CondStructureExists.class, "structure[s] [named] %strings% [do[es]] exist[s]", - "structure[s] [named] %strings% (doesn't|do[es] not) exist" + "structure[s] [named] %strings% (do[es]n't|do[es] not) exist" ); } From c9b33f763cbad9eaca44a26277d7f3c86a09a33f Mon Sep 17 00:00:00 2001 From: TheLimeGlass Date: Wed, 4 Jan 2023 18:30:49 -0700 Subject: [PATCH 14/33] Change the changer in ExprStructureSectionInfo to BiConsumers in the setting enum --- .../expressions/ExprStructureSectionInfo.java | 52 +++++++++---------- 1 file changed, 24 insertions(+), 28 deletions(-) diff --git a/src/main/java/ch/njol/skript/expressions/ExprStructureSectionInfo.java b/src/main/java/ch/njol/skript/expressions/ExprStructureSectionInfo.java index d254e185572..087c27f90a7 100644 --- a/src/main/java/ch/njol/skript/expressions/ExprStructureSectionInfo.java +++ b/src/main/java/ch/njol/skript/expressions/ExprStructureSectionInfo.java @@ -19,8 +19,8 @@ package ch.njol.skript.expressions; import java.util.Locale; +import java.util.function.BiConsumer; -import org.bukkit.Rotation; import org.bukkit.block.structure.Mirror; import org.bukkit.block.structure.StructureRotation; import org.bukkit.event.Event; @@ -81,21 +81,37 @@ public class ExprStructureSectionInfo extends SimpleExpression { } private enum Setting { - INCLUDES_ENTITIES(Boolean.class), - ROTATION(Rotation.class), - INTEGRITY(Float.class), - PALLET(Integer.class), - MIRROR(Mirror.class); + INCLUDES_ENTITIES(Boolean.class, StructurePlaceEvent::setIncludesEntities), + ROTATION(StructureRotation.class, StructurePlaceEvent::setRotation), + INTEGRITY(Float.class, (details, number) -> { + float integrity = ((Number) number).floatValue(); + details.setIntegrity(Math.min(1, Math.max(0, integrity))); + }), + PALLET(Integer.class, (details, number) -> { + int pallet = ((Number) number).intValue(); + int max = details.getStructure().getPaletteCount(); + details.setPallet(Math.min(max, Math.max(-1, pallet))); + }), + MIRROR(Mirror.class, StructurePlaceEvent::setMirror); + + private final BiConsumer consumer; private final Class returnType; - Setting(Class returnType) { + @SuppressWarnings("unchecked") + Setting(Class returnType, BiConsumer consumer) { this.returnType = returnType; + this.consumer = (BiConsumer) consumer; + } + + public void accept(StructurePlaceEvent event, Object object) { + consumer.accept(event, object); } public Class getReturnType() { return returnType; } + } private Setting setting; @@ -143,27 +159,7 @@ public void change(Event event, @Nullable Object[] delta, ChangeMode mode) { return; if (!(event instanceof StructurePlaceEvent)) return; - StructurePlaceEvent details = (StructurePlaceEvent) event; - switch (setting) { - case INCLUDES_ENTITIES: - details.setIncludesEntities((boolean) delta[0]); - break; - case INTEGRITY: - float integrity = ((Number) delta[0]).floatValue(); - details.setIntegrity(Math.min(1, Math.max(0, integrity))); - break; - case PALLET: - int pallet = ((Number) delta[0]).intValue(); - int max = details.getStructure().getPaletteCount(); - details.setPallet(Math.min(max, Math.max(-1, pallet))); - break; - case MIRROR: - details.setMirror((Mirror) delta[0]); - break; - case ROTATION: - details.setRotation((StructureRotation) delta[0]); - break; - } + setting.accept((StructurePlaceEvent) event, delta[0]); } @Override From 05653c496248d289d00e9c416e61398923dcfefc Mon Sep 17 00:00:00 2001 From: TheLimeGlass Date: Sat, 11 Nov 2023 03:03:21 -0700 Subject: [PATCH 15/33] Use isSingle properly now that it can be overriden --- skript-aliases | 2 +- .../skript/expressions/ExprStructureInfo.java | 36 +++++++++++-------- 2 files changed, 23 insertions(+), 15 deletions(-) diff --git a/skript-aliases b/skript-aliases index fb9c3044e55..1ee77d8573a 160000 --- a/skript-aliases +++ b/skript-aliases @@ -1 +1 @@ -Subproject commit fb9c3044e555667b4dc5558467608bd55fa32df0 +Subproject commit 1ee77d8573aa37456f1b49fe12aec7bb410d1dd7 diff --git a/src/main/java/ch/njol/skript/expressions/ExprStructureInfo.java b/src/main/java/ch/njol/skript/expressions/ExprStructureInfo.java index aff79f05032..ec26f002cd2 100644 --- a/src/main/java/ch/njol/skript/expressions/ExprStructureInfo.java +++ b/src/main/java/ch/njol/skript/expressions/ExprStructureInfo.java @@ -35,11 +35,12 @@ import ch.njol.skript.doc.Name; import ch.njol.skript.doc.RequiredPlugins; import ch.njol.skript.doc.Since; -import ch.njol.skript.expressions.base.SimplePropertyExpression; +import ch.njol.skript.expressions.base.PropertyExpression; import ch.njol.skript.lang.Expression; import ch.njol.skript.lang.SkriptParser.ParseResult; import ch.njol.skript.util.BlockStateBlock; import ch.njol.util.Kleenean; +import ch.njol.util.coll.iterator.ArrayIterator; @Name("Structure Info") @Description("An expression to obtain information about a structure's entities, size, and blocks.") @@ -53,11 +54,11 @@ }) @RequiredPlugins("Minecraft 1.17.1+") @Since("INSERT VERSION") -public class ExprStructureInfo extends SimplePropertyExpression { +public class ExprStructureInfo extends PropertyExpression { static { if (Skript.classExists("org.bukkit.structure.Structure")) - register(ExprStructureInfo.class, Object.class, "(:blocks|:entities|size:(size|[lowest] [block] vector))", "structures"); + register(ExprStructureInfo.class, Object.class, "[structure] (:blocks|:entities|size:(size|[lowest] [block] vector))", "structures"); } private enum Property { @@ -89,18 +90,20 @@ public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelaye } @Override - @Nullable - public Object convert(Structure structure) { + protected Object[] get(Event event, Structure[] source) { switch (property) { case BLOCKS: - if (structure.getPaletteCount() > 0) - return structure.getPalettes().get(0).getBlocks().stream() - .map(state -> new BlockStateBlock(state, true)) - .toArray(BlockStateBlock[]::new); + return get(source, structure -> { + if (structure.getPaletteCount() > 0) + return structure.getPalettes().get(0).getBlocks().stream() + .map(state -> new BlockStateBlock(state, true)) + .toArray(BlockStateBlock[]::new); + return null; + }); case ENTITIES: - return structure.getEntities().toArray(Entity[]::new); + return get(source, structure -> structure.getEntities().toArray(Entity[]::new)); case SIZE: - return structure.getSize(); + return get(source, Structure::getSize); } return null; } @@ -109,7 +112,7 @@ public Object convert(Structure structure) { @Nullable public Iterator iterator(Event event) { if (property != Property.BLOCKS) - return getExpr().stream(event).map(this::convert).iterator(); + return new ArrayIterator(get(event, getExpr().getArray(event))); List blocks = new ArrayList<>(); for (Structure structure : getExpr().getArray(event)) { if (structure.getPaletteCount() > 0) @@ -118,14 +121,19 @@ public Iterator iterator(Event event) { return blocks.iterator(); } + @Override + public boolean isSingle() { + return property == Property.SIZE && getExpr().isSingle(); + } + @Override public Class getReturnType() { return property.getReturnType(); } @Override - protected String getPropertyName() { - return property.name().toLowerCase(Locale.ENGLISH); + public String toString(@Nullable Event event, boolean debug) { + return property.name().toLowerCase(Locale.ENGLISH) + " of " + getExpr().toString(event, debug); } } From 7efa3f12c1deb76c624bbd08cde076fc86418e71 Mon Sep 17 00:00:00 2001 From: TheLimeGlass Date: Sat, 11 Nov 2023 03:38:47 -0700 Subject: [PATCH 16/33] Fix array store exception --- .../java/ch/njol/skript/expressions/ExprStructureInfo.java | 7 +++++-- src/main/java/ch/njol/skript/util/BlockStateBlock.java | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/main/java/ch/njol/skript/expressions/ExprStructureInfo.java b/src/main/java/ch/njol/skript/expressions/ExprStructureInfo.java index ec26f002cd2..8b379638fb2 100644 --- a/src/main/java/ch/njol/skript/expressions/ExprStructureInfo.java +++ b/src/main/java/ch/njol/skript/expressions/ExprStructureInfo.java @@ -23,6 +23,7 @@ import java.util.List; import java.util.Locale; +import org.bukkit.block.BlockState; import org.bukkit.entity.Entity; import org.bukkit.event.Event; import org.bukkit.structure.Structure; @@ -115,8 +116,10 @@ public Iterator iterator(Event event) { return new ArrayIterator(get(event, getExpr().getArray(event))); List blocks = new ArrayList<>(); for (Structure structure : getExpr().getArray(event)) { - if (structure.getPaletteCount() > 0) - blocks.addAll(structure.getPalettes().get(0).getBlocks()); + if (structure.getPaletteCount() > 0) { + for (BlockState state : structure.getPalettes().get(0).getBlocks()) + blocks.add(new BlockStateBlock(state, true)); + } } return blocks.iterator(); } diff --git a/src/main/java/ch/njol/skript/util/BlockStateBlock.java b/src/main/java/ch/njol/skript/util/BlockStateBlock.java index e61014acea0..5dbbeda6313 100644 --- a/src/main/java/ch/njol/skript/util/BlockStateBlock.java +++ b/src/main/java/ch/njol/skript/util/BlockStateBlock.java @@ -70,7 +70,7 @@ public BlockStateBlock(BlockState state) { public BlockStateBlock(BlockState state, boolean delayChanges) { assert state != null; this.state = state; - if (ISPASSABLE_METHOD_EXISTS) + if (ISPASSABLE_METHOD_EXISTS && state.isPlaced()) this.isPassable = state.getBlock().isPassable(); else this.isPassable = false; From e6e4f3999b8bb41cb06b5e92d828ee8dfb4d5597 Mon Sep 17 00:00:00 2001 From: LimeGlass <16087552+TheLimeGlass@users.noreply.github.com> Date: Wed, 13 Dec 2023 16:22:44 -0700 Subject: [PATCH 17/33] Update EffSecStructurePlace.java --- .../skript/sections/EffSecStructurePlace.java | 184 +++++------------- 1 file changed, 48 insertions(+), 136 deletions(-) diff --git a/src/main/java/ch/njol/skript/sections/EffSecStructurePlace.java b/src/main/java/ch/njol/skript/sections/EffSecStructurePlace.java index 6bf35f2c3c4..fdb3bfaa3b7 100644 --- a/src/main/java/ch/njol/skript/sections/EffSecStructurePlace.java +++ b/src/main/java/ch/njol/skript/sections/EffSecStructurePlace.java @@ -16,175 +16,87 @@ * * Copyright Peter Güttinger, SkriptLang team and contributors */ -package ch.njol.skript.sections; +package ch.njol.skript.effects; -import java.util.List; -import java.util.Random; -import java.util.concurrent.atomic.AtomicBoolean; +import java.io.IOException; -import org.bukkit.Location; -import org.bukkit.block.structure.Mirror; -import org.bukkit.block.structure.StructureRotation; +import org.bukkit.Bukkit; +import org.bukkit.NamespacedKey; import org.bukkit.event.Event; -import org.bukkit.event.HandlerList; import org.bukkit.structure.Structure; +import org.bukkit.structure.StructureManager; import org.eclipse.jdt.annotation.Nullable; -import org.jetbrains.annotations.NotNull; import ch.njol.skript.Skript; -import ch.njol.skript.config.SectionNode; import ch.njol.skript.doc.Description; import ch.njol.skript.doc.Examples; import ch.njol.skript.doc.Name; +import ch.njol.skript.doc.RequiredPlugins; import ch.njol.skript.doc.Since; -import ch.njol.skript.lang.EffectSection; +import ch.njol.skript.lang.Effect; import ch.njol.skript.lang.Expression; import ch.njol.skript.lang.SkriptParser.ParseResult; -import ch.njol.skript.lang.Trigger; -import ch.njol.skript.lang.TriggerItem; -import ch.njol.skript.variables.Variables; +import ch.njol.skript.util.Utils; import ch.njol.util.Kleenean; -@Name("Structure Place") -@Description({ - "Places a structure. This can be used as an effect and as a section.", - "If it is used as a section, the section is run before the structure is placed in the world.", - "You can modify the place settings like if it should include entities and any rotation/mirror option you want.", - "For more info on the section settings see Structure Place Settings" -}) -@Examples({ - "place structure \"minecraft:end_city\" at player's location without entities:", - "\tset integrity to 0.9", - "\tset pallet to -1 # -1 for random pallet", - "\tset pallet to -1 # random pallet", - "\tset rotation to counter clockwise 90", - "\tset mirror to none # already the default not required" -}) +@Name("Structure Save/Unregister") +@Description("Unregisters or saves a structure by it's namespace key. Unregister will unload if the structure was loaded vs Delete.") +@Examples("unregister structure named \"Example\"") +@RequiredPlugins("Spigot 1.17.1+") @Since("INSERT VERSION") -public class EffSecStructurePlace extends EffectSection { - - public class StructurePlaceEvent extends Event { - - private StructureRotation rotation = StructureRotation.NONE; - private Mirror mirror = Mirror.NONE; - private final Structure structure; - private float integrity = 1F; - private boolean entities; - private int pallet = 0; - - public StructurePlaceEvent(Structure structure, boolean entities) { - this.structure = structure; - this.entities = entities; - } - - public Structure getStructure() { - return structure; - } - - public boolean includeEntities() { - return entities; - } - - public void setIncludesEntities(boolean entities) { - this.entities = entities; - } - - public StructureRotation getRotation() { - return rotation; - } - - public void setRotation(StructureRotation rotation) { - this.rotation = rotation; - } - - public Mirror getMirror() { - return mirror; - } - - public void setMirror(Mirror mirror) { - this.mirror = mirror; - } - - public int getPallet() { - return pallet; - } - - public void setPallet(int pallet) { - this.pallet = pallet; - } - - public float getIntegrity() { - return integrity; - } - - public void setIntegrity(float integrity) { - this.integrity = integrity; - } - - @Override - @NotNull - public HandlerList getHandlers() { - throw new IllegalStateException(); - } - } +public class EffStructureSaveUnregister extends Effect { static { - if (Skript.classExists("org.bukkit.structure.Structure")) - Skript.registerSection(EffSecStructurePlace.class, "place %structure% at %locations% [without :entities]"); + Skript.registerEffect(EffStructureSaveUnregister.class, "(:unregister|delete) structure[s] [with name|named] %strings%", "save structure %structure% [with name|named] %string%"); } private Expression structure; - private Expression locations; - private boolean entities; - - @Nullable - private Trigger trigger; + private Expression names; + private boolean save, unregister; @Override @SuppressWarnings("unchecked") - public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult, @Nullable SectionNode sectionNode, @Nullable List triggerItems) { - structure = (Expression) exprs[0]; - locations = (Expression) exprs[1]; - entities = !parseResult.hasTag("entities"); // Negated - - if (sectionNode != null) { - AtomicBoolean delayed = new AtomicBoolean(false); - Runnable afterLoading = () -> delayed.set(!getParser().getHasDelayBefore().isFalse()); - trigger = loadCode(sectionNode, "structure place", afterLoading, StructurePlaceEvent.class); - if (delayed.get()) { - Skript.error("Delays can't be used within a structure place section!"); - return false; - } - } + public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) { + names = (Expression) exprs[matchedPattern]; + unregister = parseResult.hasTag("unregister"); + if (save = matchedPattern == 1) + structure = (Expression) exprs[0]; return true; } @Override - @Nullable - protected TriggerItem walk(Event event) { - Structure structure = this.structure.getSingle(event); - if (structure == null) { - debug(event, false); - return super.walk(event, false); - } - StructurePlaceEvent details = new StructurePlaceEvent(structure, entities); - if (trigger != null) { - Object localVars = Variables.copyLocalVariables(event); - Variables.setLocalVariables(details, localVars); - TriggerItem.walk(trigger, details); - Variables.setLocalVariables(event, Variables.copyLocalVariables(details)); - Variables.removeLocals(details); + protected void execute(Event event) { + StructureManager manager = Bukkit.getStructureManager(); + if (save) { + String name = this.names.getSingle(event); + if (name == null) + return; + Structure structure = this.structure.getSingle(event); + if (structure == null) + return; + try { + manager.saveStructure(Utils.getNamespacedKey(name), structure); + } catch (IOException e) { + Skript.exception(e, "Failed to save structure " + name); + } + } else { + for (String name : names.getArray(event)) { + NamespacedKey key = Utils.getNamespacedKey(name); + if (key == null) + continue; + try { + manager.deleteStructure(key, unregister); + } catch (IOException e) { + Skript.exception(e, "Failed to delete structure " + name); + } + } + } - - for (Location location : locations.getArray(event)) - structure.place(location, details.includeEntities(), details.getRotation(), details.getMirror(), details.getPallet(), details.getIntegrity(), new Random()); - - return super.walk(event, false); } @Override public String toString(@Nullable Event event, boolean debug) { - return "place structure " + structure.toString(event, debug) + " at " + locations.toString(event, debug); + return (save ? "save" : "delete") + " structures " + names.toString(event, debug); } } From 9119a98f95ef052b38e55420b6b05f98e929f7b0 Mon Sep 17 00:00:00 2001 From: LimeGlass <16087552+TheLimeGlass@users.noreply.github.com> Date: Wed, 13 Dec 2023 16:25:48 -0700 Subject: [PATCH 18/33] Update EffSecStructurePlace.java --- .../skript/sections/EffSecStructurePlace.java | 184 +++++++++++++----- 1 file changed, 136 insertions(+), 48 deletions(-) diff --git a/src/main/java/ch/njol/skript/sections/EffSecStructurePlace.java b/src/main/java/ch/njol/skript/sections/EffSecStructurePlace.java index fdb3bfaa3b7..6bf35f2c3c4 100644 --- a/src/main/java/ch/njol/skript/sections/EffSecStructurePlace.java +++ b/src/main/java/ch/njol/skript/sections/EffSecStructurePlace.java @@ -16,87 +16,175 @@ * * Copyright Peter Güttinger, SkriptLang team and contributors */ -package ch.njol.skript.effects; +package ch.njol.skript.sections; -import java.io.IOException; +import java.util.List; +import java.util.Random; +import java.util.concurrent.atomic.AtomicBoolean; -import org.bukkit.Bukkit; -import org.bukkit.NamespacedKey; +import org.bukkit.Location; +import org.bukkit.block.structure.Mirror; +import org.bukkit.block.structure.StructureRotation; import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; import org.bukkit.structure.Structure; -import org.bukkit.structure.StructureManager; import org.eclipse.jdt.annotation.Nullable; +import org.jetbrains.annotations.NotNull; import ch.njol.skript.Skript; +import ch.njol.skript.config.SectionNode; import ch.njol.skript.doc.Description; import ch.njol.skript.doc.Examples; import ch.njol.skript.doc.Name; -import ch.njol.skript.doc.RequiredPlugins; import ch.njol.skript.doc.Since; -import ch.njol.skript.lang.Effect; +import ch.njol.skript.lang.EffectSection; import ch.njol.skript.lang.Expression; import ch.njol.skript.lang.SkriptParser.ParseResult; -import ch.njol.skript.util.Utils; +import ch.njol.skript.lang.Trigger; +import ch.njol.skript.lang.TriggerItem; +import ch.njol.skript.variables.Variables; import ch.njol.util.Kleenean; -@Name("Structure Save/Unregister") -@Description("Unregisters or saves a structure by it's namespace key. Unregister will unload if the structure was loaded vs Delete.") -@Examples("unregister structure named \"Example\"") -@RequiredPlugins("Spigot 1.17.1+") +@Name("Structure Place") +@Description({ + "Places a structure. This can be used as an effect and as a section.", + "If it is used as a section, the section is run before the structure is placed in the world.", + "You can modify the place settings like if it should include entities and any rotation/mirror option you want.", + "For more info on the section settings see Structure Place Settings" +}) +@Examples({ + "place structure \"minecraft:end_city\" at player's location without entities:", + "\tset integrity to 0.9", + "\tset pallet to -1 # -1 for random pallet", + "\tset pallet to -1 # random pallet", + "\tset rotation to counter clockwise 90", + "\tset mirror to none # already the default not required" +}) @Since("INSERT VERSION") -public class EffStructureSaveUnregister extends Effect { +public class EffSecStructurePlace extends EffectSection { + + public class StructurePlaceEvent extends Event { + + private StructureRotation rotation = StructureRotation.NONE; + private Mirror mirror = Mirror.NONE; + private final Structure structure; + private float integrity = 1F; + private boolean entities; + private int pallet = 0; + + public StructurePlaceEvent(Structure structure, boolean entities) { + this.structure = structure; + this.entities = entities; + } + + public Structure getStructure() { + return structure; + } + + public boolean includeEntities() { + return entities; + } + + public void setIncludesEntities(boolean entities) { + this.entities = entities; + } + + public StructureRotation getRotation() { + return rotation; + } + + public void setRotation(StructureRotation rotation) { + this.rotation = rotation; + } + + public Mirror getMirror() { + return mirror; + } + + public void setMirror(Mirror mirror) { + this.mirror = mirror; + } + + public int getPallet() { + return pallet; + } + + public void setPallet(int pallet) { + this.pallet = pallet; + } + + public float getIntegrity() { + return integrity; + } + + public void setIntegrity(float integrity) { + this.integrity = integrity; + } + + @Override + @NotNull + public HandlerList getHandlers() { + throw new IllegalStateException(); + } + } static { - Skript.registerEffect(EffStructureSaveUnregister.class, "(:unregister|delete) structure[s] [with name|named] %strings%", "save structure %structure% [with name|named] %string%"); + if (Skript.classExists("org.bukkit.structure.Structure")) + Skript.registerSection(EffSecStructurePlace.class, "place %structure% at %locations% [without :entities]"); } private Expression structure; - private Expression names; - private boolean save, unregister; + private Expression locations; + private boolean entities; + + @Nullable + private Trigger trigger; @Override @SuppressWarnings("unchecked") - public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) { - names = (Expression) exprs[matchedPattern]; - unregister = parseResult.hasTag("unregister"); - if (save = matchedPattern == 1) - structure = (Expression) exprs[0]; + public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult, @Nullable SectionNode sectionNode, @Nullable List triggerItems) { + structure = (Expression) exprs[0]; + locations = (Expression) exprs[1]; + entities = !parseResult.hasTag("entities"); // Negated + + if (sectionNode != null) { + AtomicBoolean delayed = new AtomicBoolean(false); + Runnable afterLoading = () -> delayed.set(!getParser().getHasDelayBefore().isFalse()); + trigger = loadCode(sectionNode, "structure place", afterLoading, StructurePlaceEvent.class); + if (delayed.get()) { + Skript.error("Delays can't be used within a structure place section!"); + return false; + } + } return true; } @Override - protected void execute(Event event) { - StructureManager manager = Bukkit.getStructureManager(); - if (save) { - String name = this.names.getSingle(event); - if (name == null) - return; - Structure structure = this.structure.getSingle(event); - if (structure == null) - return; - try { - manager.saveStructure(Utils.getNamespacedKey(name), structure); - } catch (IOException e) { - Skript.exception(e, "Failed to save structure " + name); - } - } else { - for (String name : names.getArray(event)) { - NamespacedKey key = Utils.getNamespacedKey(name); - if (key == null) - continue; - try { - manager.deleteStructure(key, unregister); - } catch (IOException e) { - Skript.exception(e, "Failed to delete structure " + name); - } - } - + @Nullable + protected TriggerItem walk(Event event) { + Structure structure = this.structure.getSingle(event); + if (structure == null) { + debug(event, false); + return super.walk(event, false); + } + StructurePlaceEvent details = new StructurePlaceEvent(structure, entities); + if (trigger != null) { + Object localVars = Variables.copyLocalVariables(event); + Variables.setLocalVariables(details, localVars); + TriggerItem.walk(trigger, details); + Variables.setLocalVariables(event, Variables.copyLocalVariables(details)); + Variables.removeLocals(details); } + + for (Location location : locations.getArray(event)) + structure.place(location, details.includeEntities(), details.getRotation(), details.getMirror(), details.getPallet(), details.getIntegrity(), new Random()); + + return super.walk(event, false); } @Override public String toString(@Nullable Event event, boolean debug) { - return (save ? "save" : "delete") + " structures " + names.toString(event, debug); + return "place structure " + structure.toString(event, debug) + " at " + locations.toString(event, debug); } } From 17e558ed94155271ddb6ac8de0f07e13e8b9c1ac Mon Sep 17 00:00:00 2001 From: LimeGlass <16087552+TheLimeGlass@users.noreply.github.com> Date: Wed, 13 Dec 2023 16:26:04 -0700 Subject: [PATCH 19/33] Update EffStructureSaveUnregister.java --- .../effects/EffStructureSaveUnregister.java | 47 ++++++++++++------- 1 file changed, 30 insertions(+), 17 deletions(-) diff --git a/src/main/java/ch/njol/skript/effects/EffStructureSaveUnregister.java b/src/main/java/ch/njol/skript/effects/EffStructureSaveUnregister.java index f1fe3c03231..fdb3bfaa3b7 100644 --- a/src/main/java/ch/njol/skript/effects/EffStructureSaveUnregister.java +++ b/src/main/java/ch/njol/skript/effects/EffStructureSaveUnregister.java @@ -23,6 +23,7 @@ import org.bukkit.Bukkit; import org.bukkit.NamespacedKey; import org.bukkit.event.Event; +import org.bukkit.structure.Structure; import org.bukkit.structure.StructureManager; import org.eclipse.jdt.annotation.Nullable; @@ -39,45 +40,57 @@ import ch.njol.util.Kleenean; @Name("Structure Save/Unregister") -@Description("Unregisters or saves a structure by it's namespace key.") +@Description("Unregisters or saves a structure by it's namespace key. Unregister will unload if the structure was loaded vs Delete.") @Examples("unregister structure named \"Example\"") -@RequiredPlugins("Minecraft 1.17.1+") +@RequiredPlugins("Spigot 1.17.1+") @Since("INSERT VERSION") public class EffStructureSaveUnregister extends Effect { static { - Skript.registerEffect(EffStructureSaveUnregister.class, "(:save|(delete|unregister)) structure[s] [named] %strings%"); + Skript.registerEffect(EffStructureSaveUnregister.class, "(:unregister|delete) structure[s] [with name|named] %strings%", "save structure %structure% [with name|named] %string%"); } + private Expression structure; private Expression names; - private boolean save; + private boolean save, unregister; @Override @SuppressWarnings("unchecked") public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) { - names = (Expression) exprs[0]; - save = parseResult.hasTag("save"); + names = (Expression) exprs[matchedPattern]; + unregister = parseResult.hasTag("unregister"); + if (save = matchedPattern == 1) + structure = (Expression) exprs[0]; return true; } @Override protected void execute(Event event) { StructureManager manager = Bukkit.getStructureManager(); - for (String name : names.getArray(event)) { - NamespacedKey key = Utils.getNamespacedKey(name); - if (key == null) - continue; - if (save) { - manager.saveStructure(key); - } else { + if (save) { + String name = this.names.getSingle(event); + if (name == null) + return; + Structure structure = this.structure.getSingle(event); + if (structure == null) + return; + try { + manager.saveStructure(Utils.getNamespacedKey(name), structure); + } catch (IOException e) { + Skript.exception(e, "Failed to save structure " + name); + } + } else { + for (String name : names.getArray(event)) { + NamespacedKey key = Utils.getNamespacedKey(name); + if (key == null) + continue; try { - manager.deleteStructure(key); + manager.deleteStructure(key, unregister); } catch (IOException e) { - Skript.exception(e, "Failed to save structure " + name); - if (Skript.debug()) - e.printStackTrace(); + Skript.exception(e, "Failed to delete structure " + name); } } + } } From ddc205dee205e6bbd6800b357c4503c11b1f282a Mon Sep 17 00:00:00 2001 From: LimeGlass <16087552+TheLimeGlass@users.noreply.github.com> Date: Wed, 13 Dec 2023 16:31:55 -0700 Subject: [PATCH 20/33] Update EffStructureSaveUnregister.java --- .../ch/njol/skript/effects/EffStructureSaveUnregister.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/ch/njol/skript/effects/EffStructureSaveUnregister.java b/src/main/java/ch/njol/skript/effects/EffStructureSaveUnregister.java index fdb3bfaa3b7..ddba8415501 100644 --- a/src/main/java/ch/njol/skript/effects/EffStructureSaveUnregister.java +++ b/src/main/java/ch/njol/skript/effects/EffStructureSaveUnregister.java @@ -47,7 +47,8 @@ public class EffStructureSaveUnregister extends Effect { static { - Skript.registerEffect(EffStructureSaveUnregister.class, "(:unregister|delete) structure[s] [with name|named] %strings%", "save structure %structure% [with name|named] %string%"); + if (Skript.classExists("org.bukkit.structure.Structure")) + Skript.registerEffect(EffStructureSaveUnregister.class, "(:unregister|delete) structure[s] [with name|named] %strings%", "save structure %structure% [with name|named] %string%"); } private Expression structure; From b89028e56a92bd0fa840e0cdae429ae4431a2a71 Mon Sep 17 00:00:00 2001 From: LimeGlass <16087552+TheLimeGlass@users.noreply.github.com> Date: Wed, 13 Dec 2023 16:32:15 -0700 Subject: [PATCH 21/33] Update CondStructureExists.java --- .../ch/njol/skript/conditions/CondStructureExists.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/main/java/ch/njol/skript/conditions/CondStructureExists.java b/src/main/java/ch/njol/skript/conditions/CondStructureExists.java index ea18eb6109b..747543ac43a 100644 --- a/src/main/java/ch/njol/skript/conditions/CondStructureExists.java +++ b/src/main/java/ch/njol/skript/conditions/CondStructureExists.java @@ -44,10 +44,11 @@ public class CondStructureExists extends Condition { static { - Skript.registerCondition(CondStructureExists.class, - "structure[s] [named] %strings% [do[es]] exist[s]", - "structure[s] [named] %strings% (do[es]n't|do[es] not) exist" - ); + if (Skript.classExists("org.bukkit.structure.Structure")) + Skript.registerCondition(CondStructureExists.class, + "structure[s] [named] %strings% [do[es]] exist[s]", + "structure[s] [named] %strings% (do[es]n't|do[es] not) exist" + ); } private Expression names; From 7c1dd93514e7e1015e25347941e376b17fd85548 Mon Sep 17 00:00:00 2001 From: TheLimeGlass Date: Thu, 14 Dec 2023 10:15:14 -0700 Subject: [PATCH 22/33] String structures name --- .../njol/skript/classes/data/BukkitClasses.java | 6 +++++- .../skript/expressions/ExprStructureInfo.java | 17 ++++++++++++++--- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/main/java/ch/njol/skript/classes/data/BukkitClasses.java b/src/main/java/ch/njol/skript/classes/data/BukkitClasses.java index 266fa6b305f..f1bc440c434 100644 --- a/src/main/java/ch/njol/skript/classes/data/BukkitClasses.java +++ b/src/main/java/ch/njol/skript/classes/data/BukkitClasses.java @@ -1550,7 +1550,11 @@ public boolean canParse(ParseContext context) { @Override public String toString(Structure structure, int flags) { - return "structure " + structure.toString(); + return Bukkit.getStructureManager().getStructures().entrySet().stream() + .filter(entry -> entry.getValue().equals(structure)) + .map(entry -> "structure " + entry.getKey().asString()) + .findFirst() + .orElse("structure " + structure.toString()); } @Override diff --git a/src/main/java/ch/njol/skript/expressions/ExprStructureInfo.java b/src/main/java/ch/njol/skript/expressions/ExprStructureInfo.java index 8b379638fb2..4ce1ccf79ac 100644 --- a/src/main/java/ch/njol/skript/expressions/ExprStructureInfo.java +++ b/src/main/java/ch/njol/skript/expressions/ExprStructureInfo.java @@ -22,7 +22,10 @@ import java.util.Iterator; import java.util.List; import java.util.Locale; +import java.util.Map; +import org.bukkit.Bukkit; +import org.bukkit.NamespacedKey; import org.bukkit.block.BlockState; import org.bukkit.entity.Entity; import org.bukkit.event.Event; @@ -59,13 +62,14 @@ public class ExprStructureInfo extends PropertyExpression { static { if (Skript.classExists("org.bukkit.structure.Structure")) - register(ExprStructureInfo.class, Object.class, "[structure] (:blocks|:entities|size:(size|[lowest] [block] vector))", "structures"); + register(ExprStructureInfo.class, Object.class, "[structure] (:blocks|:entities|name:name[s]|size:(size|[lowest] [block] vector)[s])", "structures"); } private enum Property { BLOCKS(BlockStateBlock.class), SIZE(BlockVector.class), - ENTITIES(Entity.class); + ENTITIES(Entity.class), + NAME(String.class); private final Class returnType; @@ -105,6 +109,13 @@ protected Object[] get(Event event, Structure[] source) { return get(source, structure -> structure.getEntities().toArray(Entity[]::new)); case SIZE: return get(source, Structure::getSize); + case NAME: + Map structures = Bukkit.getStructureManager().getStructures(); + return get(source, structure -> structures.entrySet().stream() + .filter(entry -> entry.getValue().equals(structure)) + .map(entry -> "structure " + entry.getKey().asString()) + .findFirst() + .orElse("structure " + structure.toString())); } return null; } @@ -126,7 +137,7 @@ public Iterator iterator(Event event) { @Override public boolean isSingle() { - return property == Property.SIZE && getExpr().isSingle(); + return (property == Property.SIZE || property == Property.NAME) && getExpr().isSingle(); } @Override From 71e4e5f7191a33fc5d00ed695ae7cb1e84602bb9 Mon Sep 17 00:00:00 2001 From: TheLimeGlass Date: Thu, 14 Dec 2023 10:21:13 -0700 Subject: [PATCH 23/33] Add get all structures --- .../skript/expressions/ExprStructure.java | 2 +- .../skript/expressions/ExprStructures.java | 75 +++++++++++++++++++ 2 files changed, 76 insertions(+), 1 deletion(-) create mode 100644 src/main/java/ch/njol/skript/expressions/ExprStructures.java diff --git a/src/main/java/ch/njol/skript/expressions/ExprStructure.java b/src/main/java/ch/njol/skript/expressions/ExprStructure.java index 81526674a72..3ffbe530a49 100644 --- a/src/main/java/ch/njol/skript/expressions/ExprStructure.java +++ b/src/main/java/ch/njol/skript/expressions/ExprStructure.java @@ -39,7 +39,7 @@ import ch.njol.util.Kleenean; import ch.njol.util.coll.CollectionUtils; -@Name("Structures") +@Name("Structure Named") @Description({ "A structure is a utility that allows you to save a cuboid of blocks and entities.", "This syntax will return an existing structure from memory/datapacks or you can also create a structure between two locations.", diff --git a/src/main/java/ch/njol/skript/expressions/ExprStructures.java b/src/main/java/ch/njol/skript/expressions/ExprStructures.java new file mode 100644 index 00000000000..d3d6320c3ac --- /dev/null +++ b/src/main/java/ch/njol/skript/expressions/ExprStructures.java @@ -0,0 +1,75 @@ +/** + * This file is part of Skript. + * + * Skript is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Skript is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Skript. If not, see . + * + * Copyright Peter Güttinger, SkriptLang team and contributors + */ +package ch.njol.skript.expressions; + +import org.bukkit.Bukkit; +import org.bukkit.event.Event; +import org.bukkit.structure.Structure; +import org.eclipse.jdt.annotation.Nullable; + +import ch.njol.skript.Skript; +import ch.njol.skript.doc.Description; +import ch.njol.skript.doc.Examples; +import ch.njol.skript.doc.Name; +import ch.njol.skript.doc.RequiredPlugins; +import ch.njol.skript.doc.Since; +import ch.njol.skript.lang.Expression; +import ch.njol.skript.lang.ExpressionType; +import ch.njol.skript.lang.SkriptParser.ParseResult; +import ch.njol.skript.lang.util.SimpleExpression; +import ch.njol.util.Kleenean; + +@Name("Structures") +@Description("Returns all of the structures registered.") +@Examples("set {_structures::*} to all of the structures") +@RequiredPlugins("Minecraft 1.17.1+") +@Since("INSERT VERSION") +public class ExprStructures extends SimpleExpression { + + static { + if (Skript.classExists("org.bukkit.structure.Structure")) + Skript.registerExpression(ExprStructures.class, Structure.class, ExpressionType.SIMPLE, "[(all [[of] the]|the)] [registered] structures"); + } + + @Override + public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) { + return true; + } + + @Override + protected Structure[] get(Event event) { + return Bukkit.getStructureManager().getStructures().values().toArray(new Structure[0]); + } + + @Override + public boolean isSingle() { + return false; + } + + @Override + public Class getReturnType() { + return Structure.class; + } + + @Override + public String toString(@Nullable Event event, boolean debug) { + return "all of the structures"; + } + +} From 2d3f249e01a7aaf3bd86ed24fc73428ce16c4deb Mon Sep 17 00:00:00 2001 From: LimeGlass <16087552+TheLimeGlass@users.noreply.github.com> Date: Thu, 14 Dec 2023 10:30:52 -0700 Subject: [PATCH 24/33] Update EffStructureSaveUnregister.java --- .../java/ch/njol/skript/effects/EffStructureSaveUnregister.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/ch/njol/skript/effects/EffStructureSaveUnregister.java b/src/main/java/ch/njol/skript/effects/EffStructureSaveUnregister.java index ddba8415501..81b4cfae710 100644 --- a/src/main/java/ch/njol/skript/effects/EffStructureSaveUnregister.java +++ b/src/main/java/ch/njol/skript/effects/EffStructureSaveUnregister.java @@ -48,7 +48,7 @@ public class EffStructureSaveUnregister extends Effect { static { if (Skript.classExists("org.bukkit.structure.Structure")) - Skript.registerEffect(EffStructureSaveUnregister.class, "(:unregister|delete) structure[s] [with name|named] %strings%", "save structure %structure% [with name|named] %string%"); + Skript.registerEffect(EffStructureSaveUnregister.class, "(:unregister|delete) structure[s] [with name|named] %strings%", "save [structure] %structure% [with name|named] %string%"); } private Expression structure; From 1ecec647bf8f2748d1b356ef84c4410fa6a94a5a Mon Sep 17 00:00:00 2001 From: LimeGlass <16087552+TheLimeGlass@users.noreply.github.com> Date: Thu, 14 Dec 2023 10:49:45 -0700 Subject: [PATCH 25/33] Update ExprStructure.java --- .../skript/expressions/ExprStructure.java | 26 ++++++++++--------- 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/src/main/java/ch/njol/skript/expressions/ExprStructure.java b/src/main/java/ch/njol/skript/expressions/ExprStructure.java index 3ffbe530a49..586fc29064b 100644 --- a/src/main/java/ch/njol/skript/expressions/ExprStructure.java +++ b/src/main/java/ch/njol/skript/expressions/ExprStructure.java @@ -39,10 +39,11 @@ import ch.njol.util.Kleenean; import ch.njol.util.coll.CollectionUtils; -@Name("Structure Named") +@Name("Structure Between/Named") @Description({ "A structure is a utility that allows you to save a cuboid of blocks and entities.", "This syntax will return an existing structure from memory/datapacks or you can also create a structure between two locations.", + "The register tag adds the structure to the 'all structures' expression.", "If the name contains a collon, it'll grab from the Minecraft structure space (Data packs included for namespaces).", }) @Examples({ @@ -57,27 +58,29 @@ public class ExprStructure extends SimpleExpression { static { if (Skript.classExists("org.bukkit.structure.Structure")) Skript.registerExpression(ExprStructure.class, Structure.class, ExpressionType.COMBINED, - "structure[s] [named] %strings%", - "[a] [new] structure between %location% (and|to) %location% [(including|with) :entities] named %string%" + "structure[s] [named] %strings% [and register:register]", + "[a] [new] structure between %location% (and|to) %location% [(including|with) entities:entities]" ); } @Nullable private Expression location1, location2; + + @Nullable private Expression names; - private boolean entities; + private boolean entities, register; @Override @SuppressWarnings("unchecked") public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) { - entities = parseResult.hasTag("entities"); if (matchedPattern == 0) { names = (Expression) exprs[0]; return true; } + entities = parseResult.hasTag("entities"); + register = parseResult.hasTag("register"); location1 = (Expression) exprs[0]; location2 = (Expression) exprs[1]; - names = (Expression) exprs[2]; return true; } @@ -86,19 +89,18 @@ protected Structure[] get(Event event) { StructureManager manager = Bukkit.getStructureManager(); // Returning existing structures. - if (location1 == null || location2 == null) { + if (names != null) { return names.stream(event) .map(name -> Utils.getNamespacedKey(name)) - .map(name -> name != null ? manager.loadStructure(name, false) : null) + .map(name -> name != null ? manager.loadStructure(name, register) : null) .toArray(Structure[]::new); } Location location1 = this.location1.getSingle(event); Location location2 = this.location2.getSingle(event); - String name = this.names.getSingle(event); - if (location1 == null || location2 == null || name == null) + if (location1 == null || location2 == null ) return new Structure[0]; - Structure structure = manager.loadStructure(Utils.getNamespacedKey(name), true); + Structure structure = manager.createStructure(); structure.fill(location1, location2, entities); return CollectionUtils.array(structure); } @@ -118,7 +120,7 @@ public String toString(@Nullable Event event, boolean debug) { if (location1 == null || location2 == null) return "structures " + names.toString(event, debug); return "structure " + names.toString(event, debug) + - " from " + location1.toString(event, debug) + " to " + location2.toString(event, debug); + " from " + location1.toString(event, debug) + " to " + location2.toString(event, debug); } } From ae6947a8dbf7d3e729a9eaa72e3d4a4b8b984d69 Mon Sep 17 00:00:00 2001 From: LimeGlass <16087552+TheLimeGlass@users.noreply.github.com> Date: Thu, 14 Dec 2023 10:52:34 -0700 Subject: [PATCH 26/33] Update ExprStructure.java --- src/main/java/ch/njol/skript/expressions/ExprStructure.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/ch/njol/skript/expressions/ExprStructure.java b/src/main/java/ch/njol/skript/expressions/ExprStructure.java index 586fc29064b..1c38b806aba 100644 --- a/src/main/java/ch/njol/skript/expressions/ExprStructure.java +++ b/src/main/java/ch/njol/skript/expressions/ExprStructure.java @@ -39,7 +39,7 @@ import ch.njol.util.Kleenean; import ch.njol.util.coll.CollectionUtils; -@Name("Structure Between/Named") +@Name("Structure Between/Name") @Description({ "A structure is a utility that allows you to save a cuboid of blocks and entities.", "This syntax will return an existing structure from memory/datapacks or you can also create a structure between two locations.", @@ -107,7 +107,7 @@ protected Structure[] get(Event event) { @Override public boolean isSingle() { - return names.isSingle(); + return names != null && names.isSingle(); } @Override From bc0e5215d10d92d63980599f570504b1513dd66a Mon Sep 17 00:00:00 2001 From: LimeGlass <16087552+TheLimeGlass@users.noreply.github.com> Date: Thu, 14 Dec 2023 10:53:07 -0700 Subject: [PATCH 27/33] Update ExprStructure.java --- src/main/java/ch/njol/skript/expressions/ExprStructure.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main/java/ch/njol/skript/expressions/ExprStructure.java b/src/main/java/ch/njol/skript/expressions/ExprStructure.java index 1c38b806aba..db5b52a85d2 100644 --- a/src/main/java/ch/njol/skript/expressions/ExprStructure.java +++ b/src/main/java/ch/njol/skript/expressions/ExprStructure.java @@ -119,8 +119,7 @@ public Class getReturnType() { public String toString(@Nullable Event event, boolean debug) { if (location1 == null || location2 == null) return "structures " + names.toString(event, debug); - return "structure " + names.toString(event, debug) + - " from " + location1.toString(event, debug) + " to " + location2.toString(event, debug); + return "structure from " + location1.toString(event, debug) + " to " + location2.toString(event, debug); } } From 12378df92f7ce70d9706af9fe6fc632f891d6b76 Mon Sep 17 00:00:00 2001 From: LimeGlass <16087552+TheLimeGlass@users.noreply.github.com> Date: Thu, 14 Dec 2023 11:01:55 -0700 Subject: [PATCH 28/33] Update ExprStructure.java --- src/main/java/ch/njol/skript/expressions/ExprStructure.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/ch/njol/skript/expressions/ExprStructure.java b/src/main/java/ch/njol/skript/expressions/ExprStructure.java index db5b52a85d2..6281f1b002f 100644 --- a/src/main/java/ch/njol/skript/expressions/ExprStructure.java +++ b/src/main/java/ch/njol/skript/expressions/ExprStructure.java @@ -107,7 +107,7 @@ protected Structure[] get(Event event) { @Override public boolean isSingle() { - return names != null && names.isSingle(); + return names == null || names.isSingle(); } @Override From 092ce043c5c801857182595eb2b8a57458b74c84 Mon Sep 17 00:00:00 2001 From: LimeGlass <16087552+TheLimeGlass@users.noreply.github.com> Date: Thu, 14 Dec 2023 11:23:26 -0700 Subject: [PATCH 29/33] Update ExprStructureInfo.java --- .../ch/njol/skript/expressions/ExprStructureInfo.java | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/main/java/ch/njol/skript/expressions/ExprStructureInfo.java b/src/main/java/ch/njol/skript/expressions/ExprStructureInfo.java index 4ce1ccf79ac..66e77ac668f 100644 --- a/src/main/java/ch/njol/skript/expressions/ExprStructureInfo.java +++ b/src/main/java/ch/njol/skript/expressions/ExprStructureInfo.java @@ -19,10 +19,12 @@ package ch.njol.skript.expressions; import java.util.ArrayList; +import java.util.Arrays; import java.util.Iterator; import java.util.List; import java.util.Locale; import java.util.Map; +import java.util.Objects; import org.bukkit.Bukkit; import org.bukkit.NamespacedKey; @@ -98,13 +100,14 @@ public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelaye protected Object[] get(Event event, Structure[] source) { switch (property) { case BLOCKS: - return get(source, structure -> { + return Arrays.stream(source).flatMap(structure -> { if (structure.getPaletteCount() > 0) return structure.getPalettes().get(0).getBlocks().stream() - .map(state -> new BlockStateBlock(state, true)) - .toArray(BlockStateBlock[]::new); + .map(state -> new BlockStateBlock(state, true)); return null; - }); + }) + .filter(Objects::nonNull) + .toArray(BlockStateBlock[]::new); case ENTITIES: return get(source, structure -> structure.getEntities().toArray(Entity[]::new)); case SIZE: From 542226e4857f874d5b63d23dbcee0a7c6b507c07 Mon Sep 17 00:00:00 2001 From: LimeGlass <16087552+TheLimeGlass@users.noreply.github.com> Date: Thu, 14 Dec 2023 22:06:10 -0700 Subject: [PATCH 30/33] Update ExprStructure.java --- .../skript/expressions/ExprStructure.java | 24 +++++++++++++++---- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/src/main/java/ch/njol/skript/expressions/ExprStructure.java b/src/main/java/ch/njol/skript/expressions/ExprStructure.java index 6281f1b002f..15a1cc762f5 100644 --- a/src/main/java/ch/njol/skript/expressions/ExprStructure.java +++ b/src/main/java/ch/njol/skript/expressions/ExprStructure.java @@ -20,9 +20,11 @@ import org.bukkit.Bukkit; import org.bukkit.Location; +import org.bukkit.World; import org.bukkit.event.Event; import org.bukkit.structure.Structure; import org.bukkit.structure.StructureManager; +import org.bukkit.util.BlockVector; import org.eclipse.jdt.annotation.Nullable; import ch.njol.skript.Skript; @@ -35,6 +37,7 @@ import ch.njol.skript.lang.ExpressionType; import ch.njol.skript.lang.SkriptParser.ParseResult; import ch.njol.skript.lang.util.SimpleExpression; +import ch.njol.skript.util.BlockUtils; import ch.njol.skript.util.Utils; import ch.njol.util.Kleenean; import ch.njol.util.coll.CollectionUtils; @@ -58,7 +61,7 @@ public class ExprStructure extends SimpleExpression { static { if (Skript.classExists("org.bukkit.structure.Structure")) Skript.registerExpression(ExprStructure.class, Structure.class, ExpressionType.COMBINED, - "structure[s] [named] %strings% [and register:register]", + "structure[s] [named] %strings% [register:and don't register]", "[a] [new] structure between %location% (and|to) %location% [(including|with) entities:entities]" ); } @@ -68,7 +71,7 @@ public class ExprStructure extends SimpleExpression { @Nullable private Expression names; - private boolean entities, register; + private boolean entities, register = true; @Override @SuppressWarnings("unchecked") @@ -78,7 +81,7 @@ public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelaye return true; } entities = parseResult.hasTag("entities"); - register = parseResult.hasTag("register"); + register = !parseResult.hasTag("register"); location1 = (Expression) exprs[0]; location2 = (Expression) exprs[1]; return true; @@ -97,11 +100,22 @@ protected Structure[] get(Event event) { } Location location1 = this.location1.getSingle(event); Location location2 = this.location2.getSingle(event); - if (location1 == null || location2 == null ) + if (location1 == null || location2 == null) + return new Structure[0]; + + World world1 = location1.getWorld(); + World world2 = location2.getWorld(); + if (world1 != world2) return new Structure[0]; + Location lowest = BlockUtils.getLowestBlockLocation(location1, location2); + Location highest = BlockUtils.getHighestBlockLocation(location1, location2); + int x = (highest.getBlockX() + 1) - lowest.getBlockX(); + int y = (highest.getBlockY() + 1) - lowest.getBlockY(); + int z = (highest.getBlockZ() + 1) - lowest.getBlockZ(); + Structure structure = manager.createStructure(); - structure.fill(location1, location2, entities); + structure.fill(lowest, new BlockVector(x, y, z), entities); return CollectionUtils.array(structure); } From c3a88bc09e1ff2f22d65ff4ba583a9299636d267 Mon Sep 17 00:00:00 2001 From: LimeGlass <16087552+TheLimeGlass@users.noreply.github.com> Date: Thu, 14 Dec 2023 22:06:56 -0700 Subject: [PATCH 31/33] Update BlockUtils.java --- .../java/ch/njol/skript/util/BlockUtils.java | 59 +++++++++++++++---- 1 file changed, 46 insertions(+), 13 deletions(-) diff --git a/src/main/java/ch/njol/skript/util/BlockUtils.java b/src/main/java/ch/njol/skript/util/BlockUtils.java index 1e9c12fed01..244129f9779 100644 --- a/src/main/java/ch/njol/skript/util/BlockUtils.java +++ b/src/main/java/ch/njol/skript/util/BlockUtils.java @@ -28,6 +28,7 @@ import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Material; +import org.bukkit.World; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; import org.bukkit.block.data.BlockData; @@ -40,7 +41,7 @@ * TODO !Update with every version [blocks] - also update aliases-*.sk */ public class BlockUtils { - + /** * Sets the given block. * @param block Block to set. @@ -57,25 +58,23 @@ public static boolean set(Block block, Material type, @Nullable BlockValues bloc return true; } - + public static boolean set(Block block, ItemData type, boolean applyPhysics) { return set(block, type.getType(), type.getBlockValues(), applyPhysics); } - + public static void sendBlockChange(Player player, Location location, Material type, @Nullable BlockValues blockValues) { BlockCompat.SETTER.sendBlockChange(player, location, type, blockValues); } - - @SuppressWarnings("null") + public static Iterable getBlocksAround(Block b) { return Arrays.asList(b.getRelative(BlockFace.NORTH), b.getRelative(BlockFace.EAST), b.getRelative(BlockFace.SOUTH), b.getRelative(BlockFace.WEST)); } - - @SuppressWarnings("null") + public static Iterable getFaces() { return Arrays.asList(BlockFace.NORTH, BlockFace.EAST, BlockFace.SOUTH, BlockFace.WEST); } - + /** * @param b A block * @return Location of the block, including its direction @@ -92,7 +91,7 @@ public static Location getLocation(@Nullable Block b) { } return l; } - + @Nullable public static BlockData createBlockData(String dataString) { // Skript uses a comma to separate lists, so we use a semi colon as a delimiter @@ -130,6 +129,7 @@ public static BlockData createBlockData(String dataString) { /** * Get the string version of a block, including type and location. * ex: 'stone' at 1.5, 1.5, 1.5 in world 'world' + * World can be null if the Block is Skript's BlockStateBlock. * * @param block Block to get string of * @param flags @@ -139,16 +139,17 @@ public static BlockData createBlockData(String dataString) { public static String blockToString(Block block, int flags) { String type = ItemType.toString(block, flags); Location location = getLocation(block); - if (location == null) { + if (location == null) return null; - } double x = location.getX(); double y = location.getY(); double z = location.getZ(); - String world = location.getWorld().getName(); - return String.format("'%s' at %s, %s, %s in world '%s'", type, x, y, z, world); + World world = location.getWorld(); + if (world == null) + return String.format("'%s' at %s, %s, %s", type, x, y, z); + return String.format("'%s' at %s, %s, %s in world '%s'", type, x, y, z, world.getName()); } /** @@ -161,4 +162,36 @@ public static Block extractBlock(Block block) { return block instanceof DelayedChangeBlock ? ((DelayedChangeBlock) block).block : block; } + /** + * Returns the lowest block location between the two locations. + * + * @param location1 The first location. + * @param location2 The second location. + * @return Location of the lowest block location from the two locations. Null if worlds don't match. + */ + public static Location getLowestBlockLocation(Location location1, Location location2) { + if (location1.getWorld() != location2.getWorld()) + return null; + int x = Math.min(location1.getBlockX(), location2.getBlockX()); + int y = Math.min(location1.getBlockY(), location2.getBlockY()); + int z = Math.min(location1.getBlockZ(), location2.getBlockZ()); + return new Location(location1.getWorld(), x, y, z); + } + + /** + * Returns the highest block location between the two locations. + * + * @param location1 The first location. + * @param location2 The second location. + * @return Location of the highest block location from the two locations. Null if worlds don't match. + */ + public static Location getHighestBlockLocation(Location location1, Location location2) { + if (location1.getWorld() != location2.getWorld()) + return null; + int x = Math.max(location1.getBlockX(), location2.getBlockX()); + int y = Math.max(location1.getBlockY(), location2.getBlockY()); + int z = Math.max(location1.getBlockZ(), location2.getBlockZ()); + return new Location(location1.getWorld(), x, y, z); + } + } From 4eead92c3a6610f9b0c5f03a19ba1ec8a5a892ff Mon Sep 17 00:00:00 2001 From: LimeGlass <16087552+TheLimeGlass@users.noreply.github.com> Date: Tue, 2 Jan 2024 01:04:23 -0700 Subject: [PATCH 32/33] Update src/main/java/ch/njol/skript/expressions/ExprStructureSectionInfo.java Co-authored-by: Patrick Miller --- .../ch/njol/skript/expressions/ExprStructureSectionInfo.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/ch/njol/skript/expressions/ExprStructureSectionInfo.java b/src/main/java/ch/njol/skript/expressions/ExprStructureSectionInfo.java index cbd10ec463c..1702329b338 100644 --- a/src/main/java/ch/njol/skript/expressions/ExprStructureSectionInfo.java +++ b/src/main/java/ch/njol/skript/expressions/ExprStructureSectionInfo.java @@ -119,7 +119,7 @@ public Class getReturnType() { @Override public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) { - if (!getParser().isCurrentSection(EffSecStructurePlace.class)) { + if (!getParser().isCurrentEvent(StructurePlaceEvent.class)) { Skript.error(parseResult.expr + " can only be used in a structure place section!"); return false; } From c79d2446b566181b31b42728ff627508bc255e32 Mon Sep 17 00:00:00 2001 From: TheLimeGlass Date: Tue, 17 Sep 2024 20:56:09 -0600 Subject: [PATCH 33/33] Update to dev/feature branch --- .../java/ch/njol/skript/conditions/CondStructureExists.java | 2 +- .../ch/njol/skript/effects/EffStructureSaveUnregister.java | 2 +- src/main/java/ch/njol/skript/expressions/ExprStructure.java | 2 +- .../java/ch/njol/skript/expressions/ExprStructureInfo.java | 4 ++-- .../ch/njol/skript/expressions/ExprStructureSectionInfo.java | 3 +-- src/main/java/ch/njol/skript/expressions/ExprStructures.java | 2 +- .../java/ch/njol/skript/sections/EffSecStructurePlace.java | 5 +++-- 7 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/main/java/ch/njol/skript/conditions/CondStructureExists.java b/src/main/java/ch/njol/skript/conditions/CondStructureExists.java index 747543ac43a..5cef42823d8 100644 --- a/src/main/java/ch/njol/skript/conditions/CondStructureExists.java +++ b/src/main/java/ch/njol/skript/conditions/CondStructureExists.java @@ -22,7 +22,7 @@ import org.bukkit.NamespacedKey; import org.bukkit.event.Event; import org.bukkit.structure.StructureManager; -import org.eclipse.jdt.annotation.Nullable; +import org.jetbrains.annotations.Nullable; import ch.njol.skript.Skript; import ch.njol.skript.doc.Description; diff --git a/src/main/java/ch/njol/skript/effects/EffStructureSaveUnregister.java b/src/main/java/ch/njol/skript/effects/EffStructureSaveUnregister.java index 81b4cfae710..70c271b3e8c 100644 --- a/src/main/java/ch/njol/skript/effects/EffStructureSaveUnregister.java +++ b/src/main/java/ch/njol/skript/effects/EffStructureSaveUnregister.java @@ -25,7 +25,7 @@ import org.bukkit.event.Event; import org.bukkit.structure.Structure; import org.bukkit.structure.StructureManager; -import org.eclipse.jdt.annotation.Nullable; +import org.jetbrains.annotations.Nullable; import ch.njol.skript.Skript; import ch.njol.skript.doc.Description; diff --git a/src/main/java/ch/njol/skript/expressions/ExprStructure.java b/src/main/java/ch/njol/skript/expressions/ExprStructure.java index 15a1cc762f5..dd50569111b 100644 --- a/src/main/java/ch/njol/skript/expressions/ExprStructure.java +++ b/src/main/java/ch/njol/skript/expressions/ExprStructure.java @@ -25,7 +25,7 @@ import org.bukkit.structure.Structure; import org.bukkit.structure.StructureManager; import org.bukkit.util.BlockVector; -import org.eclipse.jdt.annotation.Nullable; +import org.jetbrains.annotations.Nullable; import ch.njol.skript.Skript; import ch.njol.skript.doc.Description; diff --git a/src/main/java/ch/njol/skript/expressions/ExprStructureInfo.java b/src/main/java/ch/njol/skript/expressions/ExprStructureInfo.java index 66e77ac668f..1931badf44b 100644 --- a/src/main/java/ch/njol/skript/expressions/ExprStructureInfo.java +++ b/src/main/java/ch/njol/skript/expressions/ExprStructureInfo.java @@ -33,7 +33,7 @@ import org.bukkit.event.Event; import org.bukkit.structure.Structure; import org.bukkit.util.BlockVector; -import org.eclipse.jdt.annotation.Nullable; +import org.jetbrains.annotations.Nullable; import ch.njol.skript.Skript; import ch.njol.skript.doc.Description; @@ -64,7 +64,7 @@ public class ExprStructureInfo extends PropertyExpression { static { if (Skript.classExists("org.bukkit.structure.Structure")) - register(ExprStructureInfo.class, Object.class, "[structure] (:blocks|:entities|name:name[s]|size:(size|[lowest] [block] vector)[s])", "structures"); + register(ExprStructureInfo.class, Object.class, "[structure] (:blocks|:entities|name:name[s]|size:[vector] size[s])", "structures"); } private enum Property { diff --git a/src/main/java/ch/njol/skript/expressions/ExprStructureSectionInfo.java b/src/main/java/ch/njol/skript/expressions/ExprStructureSectionInfo.java index 1702329b338..8dd9603f4f5 100644 --- a/src/main/java/ch/njol/skript/expressions/ExprStructureSectionInfo.java +++ b/src/main/java/ch/njol/skript/expressions/ExprStructureSectionInfo.java @@ -24,7 +24,7 @@ import org.bukkit.block.structure.Mirror; import org.bukkit.block.structure.StructureRotation; import org.bukkit.event.Event; -import org.eclipse.jdt.annotation.Nullable; +import org.jetbrains.annotations.Nullable; import ch.njol.skript.Skript; import ch.njol.skript.classes.Changer.ChangeMode; @@ -37,7 +37,6 @@ import ch.njol.skript.lang.ExpressionType; import ch.njol.skript.lang.SkriptParser.ParseResult; import ch.njol.skript.lang.util.SimpleExpression; -import ch.njol.skript.sections.EffSecStructurePlace; import ch.njol.skript.sections.EffSecStructurePlace.StructurePlaceEvent; import ch.njol.util.Kleenean; import ch.njol.util.coll.CollectionUtils; diff --git a/src/main/java/ch/njol/skript/expressions/ExprStructures.java b/src/main/java/ch/njol/skript/expressions/ExprStructures.java index d3d6320c3ac..14f1b824964 100644 --- a/src/main/java/ch/njol/skript/expressions/ExprStructures.java +++ b/src/main/java/ch/njol/skript/expressions/ExprStructures.java @@ -21,7 +21,7 @@ import org.bukkit.Bukkit; import org.bukkit.event.Event; import org.bukkit.structure.Structure; -import org.eclipse.jdt.annotation.Nullable; +import org.jetbrains.annotations.Nullable; import ch.njol.skript.Skript; import ch.njol.skript.doc.Description; diff --git a/src/main/java/ch/njol/skript/sections/EffSecStructurePlace.java b/src/main/java/ch/njol/skript/sections/EffSecStructurePlace.java index 6bf35f2c3c4..bf87c3eb5c4 100644 --- a/src/main/java/ch/njol/skript/sections/EffSecStructurePlace.java +++ b/src/main/java/ch/njol/skript/sections/EffSecStructurePlace.java @@ -28,7 +28,7 @@ import org.bukkit.event.Event; import org.bukkit.event.HandlerList; import org.bukkit.structure.Structure; -import org.eclipse.jdt.annotation.Nullable; +import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.NotNull; import ch.njol.skript.Skript; @@ -176,8 +176,9 @@ protected TriggerItem walk(Event event) { Variables.removeLocals(details); } - for (Location location : locations.getArray(event)) + for (Location location : locations.getArray(event)) { structure.place(location, details.includeEntities(), details.getRotation(), details.getMirror(), details.getPallet(), details.getIntegrity(), new Random()); + } return super.walk(event, false); }