Mirror von
https://github.com/IntellectualSites/FastAsyncWorldEdit.git
synchronisiert 2024-11-08 04:20:06 +01:00
Allow Actors to use generation commands
Dieser Commit ist enthalten in:
Ursprung
11d30d2f94
Commit
67b3fa054a
@ -184,19 +184,19 @@ public class GenerationCommands {
|
|||||||
)
|
)
|
||||||
@CommandPermissions("worldedit.generation.cylinder")
|
@CommandPermissions("worldedit.generation.cylinder")
|
||||||
@Logging(PLACEMENT)
|
@Logging(PLACEMENT)
|
||||||
public void hcyl(Player fp, Player player, LocalSession session, EditSession editSession,
|
public void hcyl(Actor actor, LocalSession session, EditSession editSession,
|
||||||
@Arg(desc = "The pattern of blocks to generate")
|
@Arg(desc = "The pattern of blocks to generate")
|
||||||
Pattern pattern,
|
Pattern pattern,
|
||||||
BlockVector2 radius,
|
BlockVector2 radius,
|
||||||
@Arg(desc = "The height of the cylinder", def = "1")
|
@Arg(desc = "The height of the cylinder", def = "1")
|
||||||
int height,
|
int height,
|
||||||
@Range(min = 1) @Arg(name = "thickness", desc = "double", def = "1") double thickness, InjectedValueAccess context) throws WorldEditException {
|
@Range(min = 1) @Arg(name = "thickness", desc = "double", def = "1") double thickness, InjectedValueAccess context) throws WorldEditException {
|
||||||
double max = MathMan.max(radius.getBlockX(), radius.getBlockZ());
|
double max = MathMan.max(radius.getBlockX(), radius.getBlockZ());
|
||||||
worldEdit.checkMaxRadius(max);
|
worldEdit.checkMaxRadius(max);
|
||||||
BlockVector3 pos = session.getPlacementPosition(player);
|
BlockVector3 pos = session.getPlacementPosition(actor);
|
||||||
fp.checkConfirmationRadius(() -> {
|
actor.checkConfirmationRadius(() -> {
|
||||||
int affected = editSession.makeHollowCylinder(pos, pattern, radius.getX(), radius.getZ(), Math.min(256, height), thickness - 1);
|
int affected = editSession.makeHollowCylinder(pos, pattern, radius.getX(), radius.getZ(), Math.min(256, height), thickness - 1);
|
||||||
BBC.VISITOR_BLOCK.send(fp, affected);
|
BBC.VISITOR_BLOCK.send(actor, affected);
|
||||||
}, "/hcyl", (int) max, context);
|
}, "/hcyl", (int) max, context);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -206,20 +206,20 @@ public class GenerationCommands {
|
|||||||
)
|
)
|
||||||
@CommandPermissions("worldedit.generation.cylinder")
|
@CommandPermissions("worldedit.generation.cylinder")
|
||||||
@Logging(PLACEMENT)
|
@Logging(PLACEMENT)
|
||||||
public void cyl(Player player, LocalSession session, EditSession editSession,
|
public void cyl(Actor actor, LocalSession session, EditSession editSession,
|
||||||
@Arg(desc = "The pattern of blocks to generate")
|
@Arg(desc = "The pattern of blocks to generate")
|
||||||
Pattern pattern,
|
Pattern pattern,
|
||||||
BlockVector2 radius,
|
BlockVector2 radius,
|
||||||
@Arg(desc = "The height of the cylinder", def = "1")
|
@Arg(desc = "The height of the cylinder", def = "1")
|
||||||
int height,
|
int height,
|
||||||
@Switch(name = 'h', desc = "Make a hollow cylinder")
|
@Switch(name = 'h', desc = "Make a hollow cylinder")
|
||||||
boolean hollow, InjectedValueAccess context) throws WorldEditException {
|
boolean hollow, InjectedValueAccess context) throws WorldEditException {
|
||||||
double max = Math.max(radius.getBlockX(), radius.getBlockZ());
|
double max = Math.max(radius.getBlockX(), radius.getBlockZ());
|
||||||
worldEdit.checkMaxRadius(max);
|
worldEdit.checkMaxRadius(max);
|
||||||
BlockVector3 pos = session.getPlacementPosition(player);
|
BlockVector3 pos = session.getPlacementPosition(actor);
|
||||||
player.checkConfirmationRadius(() -> {
|
actor.checkConfirmationRadius(() -> {
|
||||||
int affected = editSession.makeCylinder(pos, pattern, radius.getX(), radius.getZ(), Math.min(256, height), !hollow);
|
int affected = editSession.makeCylinder(pos, pattern, radius.getX(), radius.getZ(), Math.min(256, height), !hollow);
|
||||||
BBC.VISITOR_BLOCK.send(player, affected);
|
BBC.VISITOR_BLOCK.send(actor, affected);
|
||||||
}, "/cyl", (int) max, context);
|
}, "/cyl", (int) max, context);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -229,14 +229,14 @@ public class GenerationCommands {
|
|||||||
)
|
)
|
||||||
@CommandPermissions("worldedit.generation.sphere")
|
@CommandPermissions("worldedit.generation.sphere")
|
||||||
@Logging(PLACEMENT)
|
@Logging(PLACEMENT)
|
||||||
public void hsphere(Player player, LocalSession session, EditSession editSession,
|
public void hsphere(Actor actor, LocalSession session, EditSession editSession,
|
||||||
@Arg(desc = "The pattern of blocks to generate")
|
@Arg(desc = "The pattern of blocks to generate")
|
||||||
Pattern pattern,
|
Pattern pattern,
|
||||||
@Arg(desc = "The radii of the sphere. Order is N/S, U/D, E/W") BlockVector3 radii,
|
@Arg(desc = "The radii of the sphere. Order is N/S, U/D, E/W") BlockVector3 radii,
|
||||||
@Switch(name = 'r', desc = "Raise the bottom of the sphere to the placement position")
|
@Switch(name = 'r', desc = "Raise the bottom of the sphere to the placement position")
|
||||||
boolean raised,
|
boolean raised,
|
||||||
InjectedValueAccess context) throws WorldEditException {
|
InjectedValueAccess context) throws WorldEditException {
|
||||||
sphere(player, session, editSession, pattern, radii, raised, true, context);
|
sphere(actor, session, editSession, pattern, radii, raised, true, context);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Command(
|
@Command(
|
||||||
@ -245,7 +245,7 @@ public class GenerationCommands {
|
|||||||
)
|
)
|
||||||
@CommandPermissions("worldedit.generation.sphere")
|
@CommandPermissions("worldedit.generation.sphere")
|
||||||
@Logging(PLACEMENT)
|
@Logging(PLACEMENT)
|
||||||
public void sphere(Player player, LocalSession session, EditSession editSession,
|
public void sphere(Actor actor, LocalSession session, EditSession editSession,
|
||||||
@Arg(desc = "The pattern of blocks to generate")
|
@Arg(desc = "The pattern of blocks to generate")
|
||||||
Pattern pattern,
|
Pattern pattern,
|
||||||
@Arg(desc = "The radii of the sphere. Order is N/S, U/D, E/W")
|
@Arg(desc = "The radii of the sphere. Order is N/S, U/D, E/W")
|
||||||
@ -256,12 +256,14 @@ public class GenerationCommands {
|
|||||||
boolean hollow, InjectedValueAccess context) throws WorldEditException {
|
boolean hollow, InjectedValueAccess context) throws WorldEditException {
|
||||||
double max = MathMan.max(radii.getBlockX(), radii.getBlockY(), radii.getBlockZ());
|
double max = MathMan.max(radii.getBlockX(), radii.getBlockY(), radii.getBlockZ());
|
||||||
worldEdit.checkMaxRadius(max);
|
worldEdit.checkMaxRadius(max);
|
||||||
BlockVector3 pos = session.getPlacementPosition(player);
|
BlockVector3 pos = session.getPlacementPosition(actor);
|
||||||
BlockVector3 finalPos = raised ? pos.add(0, radii.getY(), 0) : pos;
|
BlockVector3 finalPos = raised ? pos.add(0, radii.getY(), 0) : pos;
|
||||||
player.checkConfirmationRadius(() -> {
|
actor.checkConfirmationRadius(() -> {
|
||||||
int affected = editSession.makeSphere(finalPos, pattern, radii.getX(), radii.getY(), radii.getZ(), !hollow);
|
int affected = editSession.makeSphere(finalPos, pattern, radii.getX(), radii.getY(), radii.getZ(), !hollow);
|
||||||
player.findFreePosition();
|
if (actor instanceof Player) {
|
||||||
BBC.VISITOR_BLOCK.send(player, affected);
|
((Player) actor).findFreePosition();
|
||||||
|
}
|
||||||
|
BBC.VISITOR_BLOCK.send(actor, affected);
|
||||||
}, "sphere", (int) max, context);
|
}, "sphere", (int) max, context);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -312,12 +314,12 @@ public class GenerationCommands {
|
|||||||
)
|
)
|
||||||
@CommandPermissions("worldedit.generation.pyramid")
|
@CommandPermissions("worldedit.generation.pyramid")
|
||||||
@Logging(PLACEMENT)
|
@Logging(PLACEMENT)
|
||||||
public void hollowPyramid(Player fp, Player player, LocalSession session, EditSession editSession,
|
public void hollowPyramid(Actor actor, LocalSession session, EditSession editSession,
|
||||||
@Arg(desc = "The pattern of blocks to set")
|
@Arg(desc = "The pattern of blocks to set")
|
||||||
Pattern pattern,
|
Pattern pattern,
|
||||||
@Arg(desc = "The size of the pyramid")
|
@Arg(desc = "The size of the pyramid")
|
||||||
int size, InjectedValueAccess context) throws WorldEditException {
|
int size, InjectedValueAccess context) throws WorldEditException {
|
||||||
pyramid(fp, player, session, editSession, pattern, size, true, context);
|
pyramid(actor, session, editSession, pattern, size, true, context);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Command(
|
@Command(
|
||||||
@ -326,7 +328,7 @@ public class GenerationCommands {
|
|||||||
)
|
)
|
||||||
@CommandPermissions("worldedit.generation.pyramid")
|
@CommandPermissions("worldedit.generation.pyramid")
|
||||||
@Logging(PLACEMENT)
|
@Logging(PLACEMENT)
|
||||||
public void pyramid(Player fp, Player player, LocalSession session, EditSession editSession,
|
public void pyramid(Actor actor, LocalSession session, EditSession editSession,
|
||||||
@Arg(desc = "The pattern of blocks to set")
|
@Arg(desc = "The pattern of blocks to set")
|
||||||
Pattern pattern,
|
Pattern pattern,
|
||||||
@Arg(desc = "The size of the pyramid")
|
@Arg(desc = "The size of the pyramid")
|
||||||
@ -334,12 +336,14 @@ public class GenerationCommands {
|
|||||||
@Switch(name = 'h', desc = "Make a hollow pyramid")
|
@Switch(name = 'h', desc = "Make a hollow pyramid")
|
||||||
boolean hollow,
|
boolean hollow,
|
||||||
InjectedValueAccess context) throws WorldEditException {
|
InjectedValueAccess context) throws WorldEditException {
|
||||||
BlockVector3 pos = session.getPlacementPosition(player);
|
BlockVector3 pos = session.getPlacementPosition(actor);
|
||||||
worldEdit.checkMaxRadius(size);
|
worldEdit.checkMaxRadius(size);
|
||||||
fp.checkConfirmationRadius(() -> {
|
actor.checkConfirmationRadius(() -> {
|
||||||
int affected = editSession.makePyramid(pos, pattern, size, !hollow);
|
int affected = editSession.makePyramid(pos, pattern, size, !hollow);
|
||||||
player.findFreePosition();
|
if (actor instanceof Player) {
|
||||||
BBC.VISITOR_BLOCK.send(fp, affected);
|
((Player) actor).findFreePosition();
|
||||||
|
}
|
||||||
|
BBC.VISITOR_BLOCK.send(actor, affected);
|
||||||
}, getArguments(context), size, context);
|
}, getArguments(context), size, context);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -351,7 +355,7 @@ public class GenerationCommands {
|
|||||||
)
|
)
|
||||||
@CommandPermissions("worldedit.generation.shape")
|
@CommandPermissions("worldedit.generation.shape")
|
||||||
@Logging(ALL)
|
@Logging(ALL)
|
||||||
public void generate(Player fp, Player player, LocalSession session, EditSession editSession,
|
public void generate(Actor actor, LocalSession session, EditSession editSession,
|
||||||
@Selection Region region,
|
@Selection Region region,
|
||||||
@Arg(desc = "The pattern of blocks to set")
|
@Arg(desc = "The pattern of blocks to set")
|
||||||
Pattern pattern,
|
Pattern pattern,
|
||||||
@ -374,7 +378,7 @@ public class GenerationCommands {
|
|||||||
zero = Vector3.ZERO;
|
zero = Vector3.ZERO;
|
||||||
unit = Vector3.ONE;
|
unit = Vector3.ONE;
|
||||||
} else if (offset) {
|
} else if (offset) {
|
||||||
zero = session.getPlacementPosition(player).toVector3();
|
zero = session.getPlacementPosition(actor).toVector3();
|
||||||
unit = Vector3.ONE;
|
unit = Vector3.ONE;
|
||||||
} else if (offsetCenter) {
|
} else if (offsetCenter) {
|
||||||
final Vector3 min = region.getMinimumPoint().toVector3();
|
final Vector3 min = region.getMinimumPoint().toVector3();
|
||||||
@ -396,13 +400,15 @@ public class GenerationCommands {
|
|||||||
|
|
||||||
final Vector3 unit1 = unit;
|
final Vector3 unit1 = unit;
|
||||||
|
|
||||||
fp.checkConfirmationRegion(() -> {
|
actor.checkConfirmationRegion(() -> {
|
||||||
try {
|
try {
|
||||||
final int affected = editSession.makeShape(region, zero, unit1, pattern, String.join(" ", expression), hollow, session.getTimeout());
|
final int affected = editSession.makeShape(region, zero, unit1, pattern, String.join(" ", expression), hollow, session.getTimeout());
|
||||||
player.findFreePosition();
|
if (actor instanceof Player) {
|
||||||
BBC.VISITOR_BLOCK.send(fp, affected);
|
((Player) actor).findFreePosition();
|
||||||
|
}
|
||||||
|
BBC.VISITOR_BLOCK.send(actor, affected);
|
||||||
} catch (ExpressionException e) {
|
} catch (ExpressionException e) {
|
||||||
player.printError(e.getMessage());
|
actor.printError(e.getMessage());
|
||||||
}
|
}
|
||||||
}, "/generate", region, context);
|
}, "/generate", region, context);
|
||||||
}
|
}
|
||||||
@ -417,7 +423,7 @@ public class GenerationCommands {
|
|||||||
)
|
)
|
||||||
@CommandPermissions("worldedit.generation.shape.biome")
|
@CommandPermissions("worldedit.generation.shape.biome")
|
||||||
@Logging(ALL)
|
@Logging(ALL)
|
||||||
public void generateBiome(Player fp, LocalSession session, EditSession editSession,
|
public void generateBiome(Actor actor, LocalSession session, EditSession editSession,
|
||||||
@Selection Region region,
|
@Selection Region region,
|
||||||
@Arg(desc = "The biome type to set")
|
@Arg(desc = "The biome type to set")
|
||||||
BiomeType target,
|
BiomeType target,
|
||||||
@ -439,7 +445,7 @@ public class GenerationCommands {
|
|||||||
zero = Vector3.ZERO;
|
zero = Vector3.ZERO;
|
||||||
unit = Vector3.ONE;
|
unit = Vector3.ONE;
|
||||||
} else if (offset) {
|
} else if (offset) {
|
||||||
zero = session.getPlacementPosition(fp).toVector3();
|
zero = session.getPlacementPosition(actor).toVector3();
|
||||||
unit = Vector3.ONE;
|
unit = Vector3.ONE;
|
||||||
} else if (offsetCenter) {
|
} else if (offsetCenter) {
|
||||||
final Vector3 min = region.getMinimumPoint().toVector3();
|
final Vector3 min = region.getMinimumPoint().toVector3();
|
||||||
@ -460,12 +466,12 @@ public class GenerationCommands {
|
|||||||
}
|
}
|
||||||
|
|
||||||
final Vector3 unit1 = unit;
|
final Vector3 unit1 = unit;
|
||||||
fp.checkConfirmationRegion(() -> {
|
actor.checkConfirmationRegion(() -> {
|
||||||
try {
|
try {
|
||||||
final int affected = editSession.makeBiomeShape(region, zero, unit1, target, String.join(" ", expression), hollow, session.getTimeout());
|
final int affected = editSession.makeBiomeShape(region, zero, unit1, target, String.join(" ", expression), hollow, session.getTimeout());
|
||||||
BBC.VISITOR_FLAT.send(fp, affected);
|
BBC.VISITOR_FLAT.send(actor, affected);
|
||||||
} catch (ExpressionException e) {
|
} catch (ExpressionException e) {
|
||||||
fp.printError(e.getMessage());
|
actor.printError(e.getMessage());
|
||||||
}
|
}
|
||||||
}, "/generatebiome", region, context);
|
}, "/generatebiome", region, context);
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,6 @@
|
|||||||
package com.sk89q.worldedit.entity;
|
package com.sk89q.worldedit.entity;
|
||||||
|
|
||||||
import com.boydti.fawe.Fawe;
|
import com.boydti.fawe.Fawe;
|
||||||
import com.boydti.fawe.config.BBC;
|
|
||||||
import com.boydti.fawe.config.Settings;
|
import com.boydti.fawe.config.Settings;
|
||||||
import com.boydti.fawe.object.FaweLimit;
|
import com.boydti.fawe.object.FaweLimit;
|
||||||
import com.boydti.fawe.object.brush.visualization.VirtualWorld;
|
import com.boydti.fawe.object.brush.visualization.VirtualWorld;
|
||||||
@ -40,7 +39,6 @@ import com.sk89q.worldedit.function.mask.Mask;
|
|||||||
import com.sk89q.worldedit.math.BlockVector3;
|
import com.sk89q.worldedit.math.BlockVector3;
|
||||||
import com.sk89q.worldedit.math.Vector3;
|
import com.sk89q.worldedit.math.Vector3;
|
||||||
import com.sk89q.worldedit.regions.Region;
|
import com.sk89q.worldedit.regions.Region;
|
||||||
import com.sk89q.worldedit.regions.RegionOperationException;
|
|
||||||
import com.sk89q.worldedit.regions.RegionSelector;
|
import com.sk89q.worldedit.regions.RegionSelector;
|
||||||
import com.sk89q.worldedit.session.ClipboardHolder;
|
import com.sk89q.worldedit.session.ClipboardHolder;
|
||||||
import com.sk89q.worldedit.util.Direction;
|
import com.sk89q.worldedit.util.Direction;
|
||||||
@ -51,10 +49,7 @@ import com.sk89q.worldedit.world.block.BaseBlock;
|
|||||||
import com.sk89q.worldedit.world.block.BlockStateHolder;
|
import com.sk89q.worldedit.world.block.BlockStateHolder;
|
||||||
import com.sk89q.worldedit.world.gamemode.GameMode;
|
import com.sk89q.worldedit.world.gamemode.GameMode;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.text.NumberFormat;
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
import org.enginehub.piston.inject.InjectedValueAccess;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a player
|
* Represents a player
|
||||||
@ -329,15 +324,6 @@ public interface Player extends Entity, Actor {
|
|||||||
return Settings.IMP.getLimit(this);
|
return Settings.IMP.getLimit(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void checkConfirmationStack(@NotNull Runnable task, @NotNull String command,
|
|
||||||
Region region, int times, InjectedValueAccess context) throws RegionOperationException;
|
|
||||||
|
|
||||||
void checkConfirmationRegion(@NotNull Runnable task, @NotNull String command,
|
|
||||||
Region region, InjectedValueAccess context) throws RegionOperationException;
|
|
||||||
|
|
||||||
void setConfirmTask(@NotNull Runnable task, InjectedValueAccess context,
|
|
||||||
@NotNull String command);
|
|
||||||
|
|
||||||
public Region[] getCurrentRegions();
|
public Region[] getCurrentRegions();
|
||||||
|
|
||||||
Region[] getCurrentRegions(FaweMaskManager.MaskType type);
|
Region[] getCurrentRegions(FaweMaskManager.MaskType type);
|
||||||
@ -386,36 +372,6 @@ public interface Player extends Entity, Actor {
|
|||||||
return WorldEdit.getInstance().getPlatformManager().getWorldForEditing(getWorld());
|
return WorldEdit.getInstance().getPlatformManager().getWorldForEditing(getWorld());
|
||||||
}
|
}
|
||||||
|
|
||||||
void checkConfirmation(@NotNull Runnable task, @NotNull String command, int times,
|
|
||||||
int limit, InjectedValueAccess context) throws RegionOperationException;
|
|
||||||
|
|
||||||
default void checkConfirmationRadius(@NotNull Runnable task, String command, int radius,
|
|
||||||
InjectedValueAccess context) throws RegionOperationException {
|
|
||||||
if (command != null && !getMeta("cmdConfirmRunning", false)) {
|
|
||||||
if (radius > 0) {
|
|
||||||
if (radius > 448) {
|
|
||||||
setConfirmTask(task, context, command);
|
|
||||||
long volume = (long) (Math.PI * ((double) radius * radius));
|
|
||||||
throw new RegionOperationException(BBC.WORLDEDIT_CANCEL_REASON_CONFIRM
|
|
||||||
.format(0, radius, command,
|
|
||||||
NumberFormat.getNumberInstance().format(volume)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
task.run();
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean confirm();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Queue an action to run async
|
|
||||||
*
|
|
||||||
* @param run
|
|
||||||
*/
|
|
||||||
default void queueAction(Runnable run) {
|
|
||||||
runAction(run, false, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
default boolean runAsyncIfFree(Runnable r) {
|
default boolean runAsyncIfFree(Runnable r) {
|
||||||
return runAction(r, true, true);
|
return runAction(r, true, true);
|
||||||
}
|
}
|
||||||
@ -424,13 +380,6 @@ public interface Player extends Entity, Actor {
|
|||||||
return runAction(r, true, false);
|
return runAction(r, true, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
default boolean checkAction() {
|
|
||||||
long time = getMeta("faweActionTick", Long.MIN_VALUE);
|
|
||||||
long tick = Fawe.get().getTimer().getTick();
|
|
||||||
setMeta("faweActionTick", tick);
|
|
||||||
return tick > time;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unregister this player (deletes all metadata etc) - Usually called on logout
|
* Unregister this player (deletes all metadata etc) - Usually called on logout
|
||||||
*/
|
*/
|
||||||
|
@ -19,7 +19,6 @@
|
|||||||
|
|
||||||
package com.sk89q.worldedit.extension.platform;
|
package com.sk89q.worldedit.extension.platform;
|
||||||
|
|
||||||
import com.boydti.fawe.config.BBC;
|
|
||||||
import com.boydti.fawe.object.exception.FaweException;
|
import com.boydti.fawe.object.exception.FaweException;
|
||||||
import com.boydti.fawe.object.task.SimpleAsyncNotifyQueue;
|
import com.boydti.fawe.object.task.SimpleAsyncNotifyQueue;
|
||||||
import com.boydti.fawe.regions.FaweMaskManager;
|
import com.boydti.fawe.regions.FaweMaskManager;
|
||||||
@ -30,7 +29,6 @@ import com.sk89q.worldedit.MaxChangedBlocksException;
|
|||||||
import com.sk89q.worldedit.WorldEdit;
|
import com.sk89q.worldedit.WorldEdit;
|
||||||
import com.sk89q.worldedit.WorldEditException;
|
import com.sk89q.worldedit.WorldEditException;
|
||||||
import com.sk89q.worldedit.entity.Player;
|
import com.sk89q.worldedit.entity.Player;
|
||||||
import com.sk89q.worldedit.event.platform.CommandEvent;
|
|
||||||
import com.sk89q.worldedit.extent.Extent;
|
import com.sk89q.worldedit.extent.Extent;
|
||||||
import com.sk89q.worldedit.function.mask.Mask;
|
import com.sk89q.worldedit.function.mask.Mask;
|
||||||
import com.sk89q.worldedit.internal.cui.CUIEvent;
|
import com.sk89q.worldedit.internal.cui.CUIEvent;
|
||||||
@ -41,7 +39,6 @@ import com.sk89q.worldedit.regions.ConvexPolyhedralRegion;
|
|||||||
import com.sk89q.worldedit.regions.CylinderRegion;
|
import com.sk89q.worldedit.regions.CylinderRegion;
|
||||||
import com.sk89q.worldedit.regions.Polygonal2DRegion;
|
import com.sk89q.worldedit.regions.Polygonal2DRegion;
|
||||||
import com.sk89q.worldedit.regions.Region;
|
import com.sk89q.worldedit.regions.Region;
|
||||||
import com.sk89q.worldedit.regions.RegionOperationException;
|
|
||||||
import com.sk89q.worldedit.regions.RegionSelector;
|
import com.sk89q.worldedit.regions.RegionSelector;
|
||||||
import com.sk89q.worldedit.regions.selector.ConvexPolyhedralRegionSelector;
|
import com.sk89q.worldedit.regions.selector.ConvexPolyhedralRegionSelector;
|
||||||
import com.sk89q.worldedit.regions.selector.CuboidRegionSelector;
|
import com.sk89q.worldedit.regions.selector.CuboidRegionSelector;
|
||||||
@ -65,12 +62,9 @@ import com.sk89q.worldedit.world.item.ItemType;
|
|||||||
import com.sk89q.worldedit.world.item.ItemTypes;
|
import com.sk89q.worldedit.world.item.ItemTypes;
|
||||||
import com.sk89q.worldedit.world.registry.BlockMaterial;
|
import com.sk89q.worldedit.world.registry.BlockMaterial;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.text.NumberFormat;
|
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
import org.enginehub.piston.inject.InjectedValueAccess;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An abstract implementation of both a {@link Actor} and a {@link Player}
|
* An abstract implementation of both a {@link Actor} and a {@link Player}
|
||||||
@ -716,57 +710,6 @@ public abstract class AbstractPlayerActor implements Actor, Player, Cloneable {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void checkConfirmationStack(@NotNull Runnable task, @NotNull String command,
|
|
||||||
Region region, int times, InjectedValueAccess context) throws RegionOperationException {
|
|
||||||
if (!getMeta("cmdConfirmRunning", false)) {
|
|
||||||
if (region != null) {
|
|
||||||
BlockVector3 min = region.getMinimumPoint();
|
|
||||||
BlockVector3 max = region.getMaximumPoint();
|
|
||||||
long area =
|
|
||||||
(long) ((max.getX() - min.getX()) * (max.getZ() - min.getZ() + 1)) * times;
|
|
||||||
if (area > 2 << 18) {
|
|
||||||
setConfirmTask(task, context, command);
|
|
||||||
BlockVector3 base = max.subtract(min).add(BlockVector3.ONE);
|
|
||||||
long volume = (long) base.getX() * base.getZ() * base.getY() * times;
|
|
||||||
throw new RegionOperationException(BBC.WORLDEDIT_CANCEL_REASON_CONFIRM
|
|
||||||
.format(min, max, command,
|
|
||||||
NumberFormat.getNumberInstance().format(volume)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
task.run();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void checkConfirmationRegion(@NotNull Runnable task, @NotNull String command,
|
|
||||||
Region region, InjectedValueAccess context) throws RegionOperationException {
|
|
||||||
if (!getMeta("cmdConfirmRunning", false)) {
|
|
||||||
if (region != null) {
|
|
||||||
BlockVector3 min = region.getMinimumPoint();
|
|
||||||
BlockVector3 max = region.getMaximumPoint();
|
|
||||||
long area = (max.getX() - min.getX()) * (max.getZ() - min.getZ() + 1);
|
|
||||||
if (area > 2 << 18) {
|
|
||||||
setConfirmTask(task, context, command);
|
|
||||||
BlockVector3 base = max.subtract(min).add(BlockVector3.ONE);
|
|
||||||
long volume = (long) base.getX() * base.getZ() * base.getY();
|
|
||||||
throw new RegionOperationException(BBC.WORLDEDIT_CANCEL_REASON_CONFIRM
|
|
||||||
.format(min, max, command,
|
|
||||||
NumberFormat.getNumberInstance().format(volume)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
task.run();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setConfirmTask(@NotNull Runnable task, InjectedValueAccess context,
|
|
||||||
@NotNull String command) {
|
|
||||||
CommandEvent event = new CommandEvent(this, command);
|
|
||||||
Runnable newTask = () -> PlatformCommandManager.getInstance().handleCommandTask(() -> {
|
|
||||||
task.run();
|
|
||||||
return null;
|
|
||||||
}, context, getSession(), event);
|
|
||||||
setMeta("cmdConfirm", newTask);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the player's current allowed WorldEdit regions
|
* Get the player's current allowed WorldEdit regions
|
||||||
*
|
*
|
||||||
@ -817,33 +760,4 @@ public abstract class AbstractPlayerActor implements Actor, Player, Cloneable {
|
|||||||
getSession().setRegionSelector(getWorld(), selector);
|
getSession().setRegionSelector(getWorld(), selector);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void checkConfirmation(@NotNull Runnable task, @NotNull String command, int times,
|
|
||||||
int limit, InjectedValueAccess context) throws RegionOperationException {
|
|
||||||
if (!getMeta("cmdConfirmRunning", false)) {
|
|
||||||
if (times > limit) {
|
|
||||||
setConfirmTask(task, context, command);
|
|
||||||
String volume = "<unspecified>";
|
|
||||||
throw new RegionOperationException(
|
|
||||||
BBC.WORLDEDIT_CANCEL_REASON_CONFIRM.format(0, times, command, volume));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
task.run();
|
|
||||||
}
|
|
||||||
|
|
||||||
public synchronized boolean confirm() {
|
|
||||||
Runnable confirm = deleteMeta("cmdConfirm");
|
|
||||||
if (confirm == null) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
queueAction(() -> {
|
|
||||||
setMeta("cmdConfirmRunning", true);
|
|
||||||
try {
|
|
||||||
confirm.run();
|
|
||||||
} finally {
|
|
||||||
setMeta("cmdConfirmRunning", false);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -19,14 +19,23 @@
|
|||||||
|
|
||||||
package com.sk89q.worldedit.extension.platform;
|
package com.sk89q.worldedit.extension.platform;
|
||||||
|
|
||||||
|
import com.boydti.fawe.Fawe;
|
||||||
|
import com.boydti.fawe.config.BBC;
|
||||||
import com.sk89q.worldedit.entity.Metadatable;
|
import com.sk89q.worldedit.entity.Metadatable;
|
||||||
|
import com.sk89q.worldedit.event.platform.CommandEvent;
|
||||||
import com.sk89q.worldedit.internal.cui.CUIEvent;
|
import com.sk89q.worldedit.internal.cui.CUIEvent;
|
||||||
|
import com.sk89q.worldedit.math.BlockVector3;
|
||||||
|
import com.sk89q.worldedit.regions.Region;
|
||||||
|
import com.sk89q.worldedit.regions.RegionOperationException;
|
||||||
import com.sk89q.worldedit.session.SessionOwner;
|
import com.sk89q.worldedit.session.SessionOwner;
|
||||||
import com.sk89q.worldedit.util.Identifiable;
|
import com.sk89q.worldedit.util.Identifiable;
|
||||||
import com.sk89q.worldedit.util.auth.Subject;
|
import com.sk89q.worldedit.util.auth.Subject;
|
||||||
import com.sk89q.worldedit.util.formatting.text.Component;
|
import com.sk89q.worldedit.util.formatting.text.Component;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.text.NumberFormat;
|
||||||
|
import org.enginehub.piston.inject.InjectedValueAccess;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An object that can perform actions in WorldEdit.
|
* An object that can perform actions in WorldEdit.
|
||||||
@ -123,4 +132,115 @@ public interface Actor extends Identifiable, SessionOwner, Subject, Metadatable
|
|||||||
|
|
||||||
boolean runAction(Runnable ifFree, boolean checkFree, boolean async);
|
boolean runAction(Runnable ifFree, boolean checkFree, boolean async);
|
||||||
|
|
||||||
|
default void checkConfirmationStack(@NotNull Runnable task, @NotNull String command,
|
||||||
|
Region region, int times, InjectedValueAccess context) throws RegionOperationException {
|
||||||
|
if (!getMeta("cmdConfirmRunning", false)) {
|
||||||
|
if (region != null) {
|
||||||
|
BlockVector3 min = region.getMinimumPoint();
|
||||||
|
BlockVector3 max = region.getMaximumPoint();
|
||||||
|
long area =
|
||||||
|
(long) ((max.getX() - min.getX()) * (max.getZ() - min.getZ() + 1)) * times;
|
||||||
|
if (area > 2 << 18) {
|
||||||
|
setConfirmTask(task, context, command);
|
||||||
|
BlockVector3 base = max.subtract(min).add(BlockVector3.ONE);
|
||||||
|
long volume = (long) base.getX() * base.getZ() * base.getY() * times;
|
||||||
|
throw new RegionOperationException(BBC.WORLDEDIT_CANCEL_REASON_CONFIRM
|
||||||
|
.format(min, max, command,
|
||||||
|
NumberFormat.getNumberInstance().format(volume)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
task.run();
|
||||||
|
}
|
||||||
|
|
||||||
|
default void checkConfirmationRegion(@NotNull Runnable task, @NotNull String command,
|
||||||
|
Region region, InjectedValueAccess context) throws RegionOperationException {
|
||||||
|
if (!getMeta("cmdConfirmRunning", false)) {
|
||||||
|
if (region != null) {
|
||||||
|
BlockVector3 min = region.getMinimumPoint();
|
||||||
|
BlockVector3 max = region.getMaximumPoint();
|
||||||
|
long area = (max.getX() - min.getX()) * (max.getZ() - min.getZ() + 1);
|
||||||
|
if (area > 2 << 18) {
|
||||||
|
setConfirmTask(task, context, command);
|
||||||
|
BlockVector3 base = max.subtract(min).add(BlockVector3.ONE);
|
||||||
|
long volume = (long) base.getX() * base.getZ() * base.getY();
|
||||||
|
throw new RegionOperationException(BBC.WORLDEDIT_CANCEL_REASON_CONFIRM
|
||||||
|
.format(min, max, command,
|
||||||
|
NumberFormat.getNumberInstance().format(volume)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
task.run();
|
||||||
|
}
|
||||||
|
|
||||||
|
default void setConfirmTask(@NotNull Runnable task, InjectedValueAccess context,
|
||||||
|
@NotNull String command) {
|
||||||
|
CommandEvent event = new CommandEvent(this, command);
|
||||||
|
Runnable newTask = () -> PlatformCommandManager.getInstance().handleCommandTask(() -> {
|
||||||
|
task.run();
|
||||||
|
return null;
|
||||||
|
}, context, getSession(), event);
|
||||||
|
setMeta("cmdConfirm", newTask);
|
||||||
|
}
|
||||||
|
|
||||||
|
default void checkConfirmation(@NotNull Runnable task, @NotNull String command, int times,
|
||||||
|
int limit, InjectedValueAccess context) throws RegionOperationException {
|
||||||
|
if (!getMeta("cmdConfirmRunning", false)) {
|
||||||
|
if (times > limit) {
|
||||||
|
setConfirmTask(task, context, command);
|
||||||
|
String volume = "<unspecified>";
|
||||||
|
throw new RegionOperationException(
|
||||||
|
BBC.WORLDEDIT_CANCEL_REASON_CONFIRM.format(0, times, command, volume));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
task.run();
|
||||||
|
}
|
||||||
|
|
||||||
|
default void checkConfirmationRadius(@NotNull Runnable task, String command, int radius,
|
||||||
|
InjectedValueAccess context) throws RegionOperationException {
|
||||||
|
if (command != null && !getMeta("cmdConfirmRunning", false)) {
|
||||||
|
if (radius > 0) {
|
||||||
|
if (radius > 448) {
|
||||||
|
setConfirmTask(task, context, command);
|
||||||
|
long volume = (long) (Math.PI * ((double) radius * radius));
|
||||||
|
throw new RegionOperationException(BBC.WORLDEDIT_CANCEL_REASON_CONFIRM
|
||||||
|
.format(0, radius, command,
|
||||||
|
NumberFormat.getNumberInstance().format(volume)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
task.run();
|
||||||
|
}
|
||||||
|
|
||||||
|
default boolean confirm() {
|
||||||
|
Runnable confirm = deleteMeta("cmdConfirm");
|
||||||
|
if (confirm == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
queueAction(() -> {
|
||||||
|
setMeta("cmdConfirmRunning", true);
|
||||||
|
try {
|
||||||
|
confirm.run();
|
||||||
|
} finally {
|
||||||
|
setMeta("cmdConfirmRunning", false);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Queue an action to run async
|
||||||
|
*
|
||||||
|
* @param run
|
||||||
|
*/
|
||||||
|
default void queueAction(Runnable run) {
|
||||||
|
runAction(run, false, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
default boolean checkAction() {
|
||||||
|
long time = getMeta("faweActionTick", Long.MIN_VALUE);
|
||||||
|
long tick = Fawe.get().getTimer().getTick();
|
||||||
|
setMeta("faweActionTick", tick);
|
||||||
|
return tick > time;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren