Skip to content

Minecraft Structures #5222

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 44 commits into
base: dev/feature
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
5d7244c
Start structure feature
TheLimeGlass Nov 25, 2022
937e8eb
Update to master
TheLimeGlass Nov 25, 2022
a73ac5c
Commit changes so far
TheLimeGlass Nov 25, 2022
a36264a
Complete Structures
TheLimeGlass Nov 25, 2022
4af3260
Add minecraft structure get example
TheLimeGlass Nov 25, 2022
87a0fc7
Add collon to section examples
TheLimeGlass Nov 25, 2022
510e720
license update
TheLimeGlass Nov 25, 2022
faea948
Cache StructureManager before loop
TheLimeGlass Nov 25, 2022
2e7080d
Fix error message
TheLimeGlass Nov 25, 2022
d21a056
Fix name doc
TheLimeGlass Nov 25, 2022
e0ebb1d
Describe more in the docs
TheLimeGlass Nov 26, 2022
60006fc
Apply suggestions from code review
TheLimeGlass Dec 28, 2022
b107f29
Update EffStructureSaveUnregister.java
TheLimeGlass Dec 28, 2022
8b6a4db
Add support for don't
TheLimeGlass Dec 28, 2022
8cfeddc
Merge branch 'master' into feature/structures
TheLimeGlass Dec 28, 2022
c9b33f7
Change the changer in ExprStructureSectionInfo to BiConsumers in the …
TheLimeGlass Jan 5, 2023
bd3eda9
Merge branch 'feature/structures' of https://github.com/SkriptLang/Sk…
TheLimeGlass Jan 5, 2023
c3dfcf5
Merge branch 'dev/feature' into feature/structures
TheLimeGlass Sep 22, 2023
cbb8445
Merge branch 'dev/feature' into feature/structures
TheLimeGlass Nov 11, 2023
05653c4
Use isSingle properly now that it can be overriden
TheLimeGlass Nov 11, 2023
4b5a234
Merge branch 'feature/structures' of https://github.com/SkriptLang/Sk…
TheLimeGlass Nov 11, 2023
7efa3f1
Fix array store exception
TheLimeGlass Nov 11, 2023
e6e4f39
Update EffSecStructurePlace.java
TheLimeGlass Dec 13, 2023
9119a98
Update EffSecStructurePlace.java
TheLimeGlass Dec 13, 2023
17e558e
Update EffStructureSaveUnregister.java
TheLimeGlass Dec 13, 2023
ddc205d
Update EffStructureSaveUnregister.java
TheLimeGlass Dec 13, 2023
b89028e
Update CondStructureExists.java
TheLimeGlass Dec 13, 2023
7c1dd93
String structures name
TheLimeGlass Dec 14, 2023
71e4e5f
Add get all structures
TheLimeGlass Dec 14, 2023
2d3f249
Update EffStructureSaveUnregister.java
TheLimeGlass Dec 14, 2023
1ecec64
Update ExprStructure.java
TheLimeGlass Dec 14, 2023
ae6947a
Update ExprStructure.java
TheLimeGlass Dec 14, 2023
bc0e521
Update ExprStructure.java
TheLimeGlass Dec 14, 2023
12378df
Update ExprStructure.java
TheLimeGlass Dec 14, 2023
092ce04
Update ExprStructureInfo.java
TheLimeGlass Dec 14, 2023
542226e
Update ExprStructure.java
TheLimeGlass Dec 15, 2023
c3a88bc
Update BlockUtils.java
TheLimeGlass Dec 15, 2023
98ce259
Merge branch 'dev/feature' into feature/structures
TheLimeGlass Dec 15, 2023
4eead92
Update src/main/java/ch/njol/skript/expressions/ExprStructureSectionI…
TheLimeGlass Jan 2, 2024
59b804e
Merge branch 'dev/feature' into feature/structures
TheLimeGlass Mar 10, 2024
d74a481
Merge branch 'dev/feature' into feature/structures
sovdeeth Mar 19, 2024
b3ad9e7
Merge branch 'dev/feature' into feature/structures
sovdeeth Mar 30, 2024
3e97732
Merge branch 'dev/feature' into feature/structures
Moderocky Sep 13, 2024
c79d244
Update to dev/feature branch
TheLimeGlass Sep 18, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions src/main/java/ch/njol/skript/classes/data/BukkitClasses.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import org.bukkit.GameRule;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.NamespacedKey;
import org.bukkit.OfflinePlayer;
import org.bukkit.Registry;
import org.bukkit.SoundCategory;
Expand All @@ -49,6 +50,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;
Expand Down Expand Up @@ -77,6 +80,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;

Expand All @@ -102,6 +106,7 @@
import ch.njol.skript.util.BlockUtils;
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;
import io.papermc.paper.world.MoonPhase;
Expand Down Expand Up @@ -1526,6 +1531,60 @@ public String toVariableNameString(EnchantmentOffer eo) {
.name("Transform Reason")
.description("Represents a transform reason of an <a href='events.html#entity transform'>entity transform event</a>.")
.since("2.8.0"));

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))
.requiredPlugins("Minecraft 1.17.1")
.since("INSERT VERSION")
.parser(new Parser<Structure>() {
@Override
@Nullable
public Structure parse(String input, ParseContext context) {
NamespacedKey key = Utils.getNamespacedKey(input);
if (key == null)
return null;
return Bukkit.getStructureManager().loadStructure(key, false);
}

@Override
public boolean canParse(ParseContext context) {
return context != ParseContext.CONFIG;
}

@Override
public String toString(Structure structure, int flags) {
return Bukkit.getStructureManager().getStructures().entrySet().stream()
.filter(entry -> entry.getValue().equals(structure))
.map(entry -> "structure " + entry.getKey().asString())
.findFirst()
.orElse("structure " + structure.toString());
}

@Override
public String toVariableNameString(Structure structure) {
return toString(structure, 0);
}
}));

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.")
.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"));
}

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/**
* 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 <http://www.gnu.org/licenses/>.
*
* Copyright Peter Güttinger, SkriptLang team and contributors
*/
package ch.njol.skript.conditions;

import org.bukkit.Bukkit;
import org.bukkit.NamespacedKey;
import org.bukkit.event.Event;
import org.bukkit.structure.StructureManager;
import org.jetbrains.annotations.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 {
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<String> names;

@Override
@SuppressWarnings("unchecked")
public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) {
names = (Expression<String>) exprs[0];
setNegated(matchedPattern == 1);
return true;
}

@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 manager.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";
}

}
103 changes: 103 additions & 0 deletions src/main/java/ch/njol/skript/effects/EffStructureSaveUnregister.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
/**
* 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 <http://www.gnu.org/licenses/>.
*
* Copyright Peter Güttinger, SkriptLang team and contributors
*/
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.Structure;
import org.bukkit.structure.StructureManager;
import org.jetbrains.annotations.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 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 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%");
}

private Expression<Structure> structure;
private Expression<String> names;
private boolean save, unregister;

@Override
@SuppressWarnings("unchecked")
public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) {
names = (Expression<String>) exprs[matchedPattern];
unregister = parseResult.hasTag("unregister");
if (save = matchedPattern == 1)
structure = (Expression<Structure>) exprs[0];
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);
}
}

}
}

@Override
public String toString(@Nullable Event event, boolean debug) {
return (save ? "save" : "delete") + " structures " + names.toString(event, debug);
}

}
Loading
Loading