Skip to content

Commit

Permalink
we_selection mechanism
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Apr 25, 2021
1 parent 124099d commit af3fdbb
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 9 deletions.
Expand Up @@ -45,7 +45,7 @@ public void tagEvent(ReplaceableTagEvent event) {
Attribute attribute = event.getAttributes().fulfill(1);

// <--[tag]
// @attribute <essentials.warp[<warp name>]>
// @attribute <essentials.warp[<warp_name>]>
// @returns LocationTag
// @plugin Depenizen, Essentials
// @description
Expand Down
Expand Up @@ -182,7 +182,7 @@ public void execute(ScriptEntry scriptEntry) {
String directory = URLDecoder.decode(System.getProperty("user.dir"));
File fileToLoad = new File(directory + "/plugins/Denizen/schematics/" + file + ".schem");
if (!Utilities.canReadFile(fileToLoad)) {
Debug.echoError("Permission to read file '" + file + "' denied by config.");
Debug.echoError("Cannot read from that file path due to security settings in Denizen/config.yml.");
return;
}
if (!fileToLoad.exists()) {
Expand Down Expand Up @@ -259,7 +259,7 @@ else if (action.asString().equalsIgnoreCase("create_schematic")) {
String directory = URLDecoder.decode(System.getProperty("user.dir"));
File fileToSave = new File(directory + "/plugins/Denizen/schematics/" + file + ".schem");
if (!Utilities.canWriteToFile(fileToSave)) {
Debug.echoError("Permission to write file '" + file + "' denied by config.");
Debug.echoError("Cannot write to that file path due to security settings in Denizen/config.yml.");
return;
}
if (cuboid == null) {
Expand Down Expand Up @@ -352,7 +352,7 @@ else if (action.asString().equalsIgnoreCase("copy_to_clipboard")) {
String directory = URLDecoder.decode(System.getProperty("user.dir"));
File fileToLoad = new File(directory + "/plugins/Denizen/schematics/" + file + ".schem");
if (!Utilities.canReadFile(fileToLoad)) {
Debug.echoError("Permission to read file '" + file + "' denied by config.");
Debug.echoError("Cannot read from that file path due to security settings in Denizen/config.yml.");
return;
}
if (!fileToLoad.exists()) {
Expand Down
Expand Up @@ -15,6 +15,7 @@
import com.sk89q.worldedit.regions.EllipsoidRegion;
import com.sk89q.worldedit.regions.Polygonal2DRegion;
import com.sk89q.worldedit.regions.RegionSelector;
import com.sk89q.worldedit.regions.selector.CuboidRegionSelector;
import com.sk89q.worldedit.regions.selector.EllipsoidRegionSelector;
import com.sk89q.worldedit.regions.selector.Polygonal2DRegionSelector;
import com.sk89q.worldedit.world.item.ItemType;
Expand All @@ -28,6 +29,8 @@
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;

import java.util.stream.Collectors;

public class WorldEditPlayerProperties implements Property {

@Override
Expand All @@ -40,11 +43,6 @@ public String getPropertyId() {
return "WorldEditPlayer";
}

@Override
public void adjust(Mechanism mechanism) {
// None
}

public static boolean describes(ObjectTag object) {
return object instanceof PlayerTag
&& ((PlayerTag) object).isOnline();
Expand All @@ -64,6 +62,7 @@ public static WorldEditPlayerProperties getFrom(ObjectTag object) {
};

public static final String[] handledMechs = new String[] {
"we_selection"
}; // None

private WorldEditPlayerProperties(PlayerTag player) {
Expand Down Expand Up @@ -128,6 +127,7 @@ public String getAttribute(Attribute attribute) {
// <--[tag]
// @attribute <PlayerTag.we_selection>
// @returns ObjectTag
// @mechanism PlayerTag.we_selection
// @plugin Depenizen, WorldEdit
// @description
// Returns the player's current block area selection, as a CuboidTag, EllipsoidTag, or PolygonTag.
Expand Down Expand Up @@ -164,6 +164,41 @@ else if (selection instanceof Polygonal2DRegionSelector) {
}

return null;
}

@Override
public void adjust(Mechanism mechanism) {

// <--[mechanism]
// @object PlayerTag
// @name we_selection
// @plugin Depenizen, WorldEdit
// @input ObjectTag
// @description
// Sets the player's current block area selection, as a CuboidTag, EllipsoidTag, or PolygonTag.
// @tags
// <PlayerTag.we_selection>
// -->
if (mechanism.matches("we_selection")) {
WorldEditPlugin worldEdit = (WorldEditPlugin) WorldEditBridge.instance.plugin;
RegionSelector selector;
if (mechanism.getValue().asString().startsWith("cu@")) {
CuboidTag input = mechanism.valueAsType(CuboidTag.class);
selector = new CuboidRegionSelector(BukkitAdapter.adapt(input.getWorld()), BukkitAdapter.asBlockVector(input.getLow(0)), BukkitAdapter.asBlockVector(input.getHigh(0)));
}
else if (mechanism.getValue().asString().startsWith("ellipsoid@")) {
EllipsoidTag input = mechanism.valueAsType(EllipsoidTag.class);
selector = new EllipsoidRegionSelector(BukkitAdapter.adapt(input.center.getWorld()), BukkitAdapter.asBlockVector(input.center), BukkitAdapter.asVector(input.size));
}
else if (mechanism.getValue().asString().startsWith("polygon@")) {
PolygonTag input = mechanism.valueAsType(PolygonTag.class);
selector = new Polygonal2DRegionSelector(BukkitAdapter.adapt(input.world.getWorld()), input.corners.stream().map(c -> BlockVector2.at(c.x, c.z)).collect(Collectors.toList()), (int)input.yMin, (int)input.yMax);
}
else {
Debug.echoError("Invalid we_selection input");
return;
}
worldEdit.getSession(player).setRegionSelector(BukkitAdapter.adapt(player.getWorld()), selector);
}
}
}

0 comments on commit af3fdbb

Please sign in to comment.