Skip to content

Commit

Permalink
update for upstream cuboid changes
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Oct 18, 2021
1 parent 8c63c8a commit cc465be
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 43 deletions.
Expand Up @@ -67,7 +67,7 @@ public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException
if (!scriptEntry.hasObject("server")
&& arg.startsWith("server:")) {
scriptEntry.addObject("server", new ElementTag(TagManager.tag(arg.substring("server:".length()),
scriptEntry.entryData.getTagContext())));
scriptEntry.getContext())));
}
else if (!scriptEntry.hasObject("tag")) {
scriptEntry.addObject("tag", new ElementTag(arg));
Expand Down
Expand Up @@ -97,9 +97,7 @@ private enum Action {CREATE_SCHEMATIC, COPY_TO_CLIPBOARD, PASTE}

@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {

for (Argument arg : scriptEntry.getProcessedArgs()) {

if (!scriptEntry.hasObject("position")
&& arg.matchesPrefix("position")) {
scriptEntry.addObject("position", arg.asType(LocationTag.class));
Expand Down Expand Up @@ -132,7 +130,6 @@ else if (!scriptEntry.hasObject("action")
arg.reportUnhandled();
}
}

if (!scriptEntry.hasObject("action")) {
throw new InvalidArgumentsException("Action not specified!");
}
Expand All @@ -143,33 +140,23 @@ public CuboidRegion cuboidToWECuboid(CuboidTag cuboid) {
LocationTag bottom = cuboid.getLow(0);
BlockVector3 topVector = BlockVector3.at(top.getBlockX(), top.getBlockY(), top.getBlockZ());
BlockVector3 bottomVector = BlockVector3.at(bottom.getBlockX(), bottom.getBlockY(), bottom.getBlockZ());
World w = new BukkitWorld(cuboid.getWorld());
World w = new BukkitWorld(cuboid.getWorld().getWorld());
return new CuboidRegion(w, bottomVector, topVector);
}

@Override
public void execute(ScriptEntry scriptEntry) {

ElementTag action = scriptEntry.getObjectTag("action");
ElementTag file = scriptEntry.getObjectTag("file");
LocationTag position = scriptEntry.getObjectTag("position");
ElementTag noAir = scriptEntry.getObjectTag("noair");
CuboidTag cuboid = scriptEntry.getObjectTag("cuboid");
ElementTag undoable = scriptEntry.getObjectTag("undoable");
ElementTag rotate = scriptEntry.getObjectTag("rotate");

if (scriptEntry.dbCallShouldDebug()) {
Debug.report(scriptEntry, getName(), action.debug()
+ (file != null ? file.debug() : "")
+ (position != null ? position.debug() : "")
+ (noAir != null ? noAir.debug() : "")
+ (cuboid != null ? cuboid.debug() : "")
+ (undoable != null ? undoable.debug() : "")
+ (rotate != null ? rotate.debug() : ""));
Debug.report(scriptEntry, getName(), action, file, position, noAir, cuboid, undoable, rotate);
}

PlayerTag target = Utilities.getEntryPlayer(scriptEntry);

if (action.asString().equalsIgnoreCase("paste")) {
if (file == null) {
Debug.echoError("File path not specified");
Expand Down
Expand Up @@ -56,86 +56,65 @@ private enum Action {ADD, REMOVE}

@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {

for (Argument arg : scriptEntry.getProcessedArgs()) {

if (!scriptEntry.hasObject("region_id")
&& arg.matchesPrefix("id")) {
scriptEntry.addObject("region_id", arg.asElement());
}

else if (!scriptEntry.hasObject("cuboid")
&& arg.matchesArgumentType(CuboidTag.class)) {
scriptEntry.addObject("cuboid", arg.asType(CuboidTag.class));
}

else if (!scriptEntry.hasObject("world")
&& arg.matchesArgumentType(WorldTag.class)) {
scriptEntry.addObject("world", arg.asType(WorldTag.class));
}

else if (!scriptEntry.hasObject("action")
&& arg.matchesEnum(Action.values())) {
scriptEntry.addObject("action", arg.asElement());
}

else {
arg.reportUnhandled();
}

}

if (!scriptEntry.hasObject("region_id")) {
throw new InvalidArgumentsException("Must specify a region id!");
}

if (!scriptEntry.hasObject("cuboid") && (!scriptEntry.hasObject("action")
|| scriptEntry.getElement("action").asString().equalsIgnoreCase("ADD"))) {
throw new InvalidArgumentsException("Must specify a valid cuboid!");
}

if (!scriptEntry.hasObject("world") && scriptEntry.hasObject("action")
&& scriptEntry.getElement("action").asString().equalsIgnoreCase("REMOVE")) {
throw new InvalidArgumentsException("Must specify a valid world!");
}

if (!scriptEntry.hasObject("action")) {
scriptEntry.addObject("action", new ElementTag("ADD"));
}

}

@Override
public void execute(ScriptEntry scriptEntry) {

ElementTag region_id = scriptEntry.getElement("region_id");
CuboidTag cuboid = scriptEntry.getObjectTag("cuboid");
WorldTag w = scriptEntry.getObjectTag("world");
World world = w != null ? w.getWorld() : cuboid != null ? cuboid.getWorld() : null;
World world = w != null ? w.getWorld() : cuboid != null ? cuboid.getWorld().getWorld() : null;
ElementTag action = scriptEntry.getElement("action");

if (world == null) {
Debug.echoError("No valid world found!");
return;
}

Debug.report(scriptEntry, getName(), region_id.debug() + (cuboid != null ? cuboid.debug() : "")
+ ArgumentHelper.debugObj("world", world.getName()) + action.debug());

Debug.report(scriptEntry, getName(), region_id, cuboid, ArgumentHelper.debugObj("world", world.getName()), action);
RegionManager regionManager = WorldGuard.getInstance().getPlatform().getRegionContainer().get(BukkitAdapter.adapt(world));

if (action.asString().equalsIgnoreCase("REMOVE")) {
regionManager.removeRegion(region_id.asString());
return;
}

Location low = cuboid.getLow(0);
Location high = cuboid.getHigh(0);
ProtectedCuboidRegion region = new ProtectedCuboidRegion(region_id.asString(),
BlockVector3.at(low.getX(), low.getY(), low.getZ()),
BlockVector3.at(high.getX(), high.getY(), high.getZ()));

regionManager.addRegion(region);

}
}
Expand Up @@ -63,7 +63,7 @@ public static WorldEditPlayerProperties getFrom(ObjectTag object) {

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

private WorldEditPlayerProperties(PlayerTag player) {
this.player = player.getPlayerEntity();
Expand Down Expand Up @@ -184,7 +184,7 @@ public void adjust(Mechanism mechanism) {
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)));
selector = new CuboidRegionSelector(BukkitAdapter.adapt(input.getWorld().getWorld()), BukkitAdapter.asBlockVector(input.getLow(0)), BukkitAdapter.asBlockVector(input.getHigh(0)));
}
else if (mechanism.getValue().asString().startsWith("ellipsoid@")) {
EllipsoidTag input = mechanism.valueAsType(EllipsoidTag.class);
Expand Down
Expand Up @@ -69,7 +69,7 @@ private ApplicableRegionSet getApplicableRegions() {
BlockVector3 vecLow = BlockVector3.at(low.getX(), low.getY(), low.getZ());
BlockVector3 vecHigh = BlockVector3.at(high.getX(), high.getY(), high.getZ());
ProtectedCuboidRegion region = new ProtectedCuboidRegion("FAKE_REGION", vecLow, vecHigh);
return WorldGuard.getInstance().getPlatform().getRegionContainer().get(BukkitAdapter.adapt(cuboid.getWorld())).getApplicableRegions(region);
return WorldGuard.getInstance().getPlatform().getRegionContainer().get(BukkitAdapter.adapt(cuboid.getWorld().getWorld())).getApplicableRegions(region);
}

private boolean hasRegion() {
Expand Down Expand Up @@ -106,7 +106,7 @@ public String getAttribute(Attribute attribute) {
// Returns a list of regions that are in this cuboid.
// -->
if (attribute.startsWith("regions")) {
return getRegions(cuboid.getWorld()).getAttribute(attribute.fulfill(1));
return getRegions(cuboid.getWorld().getWorld()).getAttribute(attribute.fulfill(1));
}

return null;
Expand Down

0 comments on commit cc465be

Please sign in to comment.