mirror of
https://github.com/EngineHub/WorldEdit.git
synced 2024-12-21 04:49:51 +08:00
Allow biome commands to be used from non-player actors (#2034)
This commit is contained in:
parent
17b9f00501
commit
76ec878eb2
@ -30,6 +30,7 @@
|
|||||||
import com.sk89q.worldedit.entity.Player;
|
import com.sk89q.worldedit.entity.Player;
|
||||||
import com.sk89q.worldedit.extension.platform.Actor;
|
import com.sk89q.worldedit.extension.platform.Actor;
|
||||||
import com.sk89q.worldedit.extension.platform.Capability;
|
import com.sk89q.worldedit.extension.platform.Capability;
|
||||||
|
import com.sk89q.worldedit.extension.platform.Locatable;
|
||||||
import com.sk89q.worldedit.function.RegionFunction;
|
import com.sk89q.worldedit.function.RegionFunction;
|
||||||
import com.sk89q.worldedit.function.RegionMaskingFilter;
|
import com.sk89q.worldedit.function.RegionMaskingFilter;
|
||||||
import com.sk89q.worldedit.function.biome.BiomeReplace;
|
import com.sk89q.worldedit.function.biome.BiomeReplace;
|
||||||
@ -106,7 +107,7 @@ public void biomeList(Actor actor,
|
|||||||
descFooter = "By default, uses all blocks in your selection."
|
descFooter = "By default, uses all blocks in your selection."
|
||||||
)
|
)
|
||||||
@CommandPermissions("worldedit.biome.info")
|
@CommandPermissions("worldedit.biome.info")
|
||||||
public void biomeInfo(Player player, LocalSession session,
|
public void biomeInfo(Actor actor, World world, LocalSession session,
|
||||||
@Switch(name = 't', desc = "Use the block you are looking at.")
|
@Switch(name = 't', desc = "Use the block you are looking at.")
|
||||||
boolean useLineOfSight,
|
boolean useLineOfSight,
|
||||||
@Switch(name = 'p', desc = "Use the block you are currently in.")
|
@Switch(name = 'p', desc = "Use the block you are currently in.")
|
||||||
@ -117,23 +118,32 @@ public void biomeInfo(Player player, LocalSession session,
|
|||||||
String messageKey;
|
String messageKey;
|
||||||
|
|
||||||
if (useLineOfSight) {
|
if (useLineOfSight) {
|
||||||
Location blockPosition = player.getBlockTrace(300);
|
if (actor instanceof Player) {
|
||||||
if (blockPosition == null) {
|
Location blockPosition = ((Player) actor).getBlockTrace(300);
|
||||||
player.printError(TranslatableComponent.of("worldedit.raytrace.noblock"));
|
if (blockPosition == null) {
|
||||||
|
actor.printError(TranslatableComponent.of("worldedit.raytrace.noblock"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
BiomeType biome = world.getBiome(blockPosition.toVector().toBlockPoint());
|
||||||
|
biomes.add(biome);
|
||||||
|
|
||||||
|
messageKey = "worldedit.biomeinfo.lineofsight";
|
||||||
|
} else {
|
||||||
|
actor.printError(TranslatableComponent.of("worldedit.raytrace.require-player"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
BiomeType biome = player.getWorld().getBiome(blockPosition.toVector().toBlockPoint());
|
|
||||||
biomes.add(biome);
|
|
||||||
|
|
||||||
messageKey = "worldedit.biomeinfo.lineofsight";
|
|
||||||
} else if (usePosition) {
|
} else if (usePosition) {
|
||||||
BiomeType biome = player.getWorld().getBiome(player.getLocation().toVector().toBlockPoint());
|
if (actor instanceof Locatable) {
|
||||||
biomes.add(biome);
|
BiomeType biome = world.getBiome(((Locatable) actor).getLocation().toVector().toBlockPoint());
|
||||||
|
biomes.add(biome);
|
||||||
|
|
||||||
messageKey = "worldedit.biomeinfo.position";
|
messageKey = "worldedit.biomeinfo.position";
|
||||||
|
} else {
|
||||||
|
actor.printError(TranslatableComponent.of("worldedit.biomeinfo.not-locatable"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
World world = player.getWorld();
|
|
||||||
Region region = session.getSelection(world);
|
Region region = session.getSelection(world);
|
||||||
|
|
||||||
for (BlockVector3 pt : region) {
|
for (BlockVector3 pt : region) {
|
||||||
@ -148,7 +158,7 @@ public void biomeInfo(Player player, LocalSession session,
|
|||||||
HoverEvent.showText(TextComponent.of(biome.getId()))
|
HoverEvent.showText(TextComponent.of(biome.getId()))
|
||||||
)
|
)
|
||||||
).collect(Collectors.toList());
|
).collect(Collectors.toList());
|
||||||
player.printInfo(TranslatableComponent.of(messageKey, TextUtils.join(components, TextComponent.of(", "))));
|
actor.printInfo(TranslatableComponent.of(messageKey, TextUtils.join(components, TextComponent.of(", "))));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Command(
|
@Command(
|
||||||
@ -158,17 +168,21 @@ public void biomeInfo(Player player, LocalSession session,
|
|||||||
)
|
)
|
||||||
@Logging(REGION)
|
@Logging(REGION)
|
||||||
@CommandPermissions("worldedit.biome.set")
|
@CommandPermissions("worldedit.biome.set")
|
||||||
public void setBiome(Player player, LocalSession session, EditSession editSession,
|
public void setBiome(Actor actor, World world, LocalSession session, EditSession editSession,
|
||||||
@Arg(desc = "Biome type.") BiomeType target,
|
@Arg(desc = "Biome type.") BiomeType target,
|
||||||
@Switch(name = 'p', desc = "Use your current position")
|
@Switch(name = 'p', desc = "Use your current position")
|
||||||
boolean atPosition) throws WorldEditException {
|
boolean atPosition) throws WorldEditException {
|
||||||
World world = player.getWorld();
|
|
||||||
Region region;
|
Region region;
|
||||||
Mask mask = editSession.getMask();
|
Mask mask = editSession.getMask();
|
||||||
|
|
||||||
if (atPosition) {
|
if (atPosition) {
|
||||||
final BlockVector3 pos = player.getLocation().toVector().toBlockPoint();
|
if (actor instanceof Locatable) {
|
||||||
region = new CuboidRegion(pos, pos);
|
final BlockVector3 pos = ((Locatable) actor).getLocation().toVector().toBlockPoint();
|
||||||
|
region = new CuboidRegion(pos, pos);
|
||||||
|
} else {
|
||||||
|
actor.printError(TranslatableComponent.of("worldedit.setbiome.not-locatable"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
region = session.getSelection(world);
|
region = session.getSelection(world);
|
||||||
}
|
}
|
||||||
@ -180,7 +194,7 @@ public void setBiome(Player player, LocalSession session, EditSession editSessio
|
|||||||
RegionVisitor visitor = new RegionVisitor(region, replace);
|
RegionVisitor visitor = new RegionVisitor(region, replace);
|
||||||
Operations.completeLegacy(visitor);
|
Operations.completeLegacy(visitor);
|
||||||
|
|
||||||
player.printInfo(TranslatableComponent.of(
|
actor.printInfo(TranslatableComponent.of(
|
||||||
"worldedit.setbiome.changed",
|
"worldedit.setbiome.changed",
|
||||||
TextComponent.of(visitor.getAffected())
|
TextComponent.of(visitor.getAffected())
|
||||||
)
|
)
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
"worldedit.biomeinfo.lineofsight": "Biomes at line of sight point: {0}",
|
"worldedit.biomeinfo.lineofsight": "Biomes at line of sight point: {0}",
|
||||||
"worldedit.biomeinfo.position": "Biomes at your position: {0}",
|
"worldedit.biomeinfo.position": "Biomes at your position: {0}",
|
||||||
"worldedit.biomeinfo.selection": "Biomes in your selection: {0}",
|
"worldedit.biomeinfo.selection": "Biomes in your selection: {0}",
|
||||||
|
"worldedit.biomeinfo.not-locatable": "Command sender must be present in the world to use the -p flag.",
|
||||||
|
|
||||||
"worldedit.brush.radius-too-large": "Maximum allowed brush radius: {0}",
|
"worldedit.brush.radius-too-large": "Maximum allowed brush radius: {0}",
|
||||||
"worldedit.brush.apply.description": "Apply brush, apply a function to every block",
|
"worldedit.brush.apply.description": "Apply brush, apply a function to every block",
|
||||||
@ -33,6 +34,7 @@
|
|||||||
|
|
||||||
"worldedit.setbiome.changed": "Biomes were changed for approximately {0} blocks.",
|
"worldedit.setbiome.changed": "Biomes were changed for approximately {0} blocks.",
|
||||||
"worldedit.setbiome.warning": "You may have to re-join your game (or close and re-open your world) to see changes.",
|
"worldedit.setbiome.warning": "You may have to re-join your game (or close and re-open your world) to see changes.",
|
||||||
|
"worldedit.setbiome.not-locatable": "Command sender must be present in the world to use the -p flag.",
|
||||||
|
|
||||||
"worldedit.drawsel.disabled": "Server CUI disabled.",
|
"worldedit.drawsel.disabled": "Server CUI disabled.",
|
||||||
"worldedit.drawsel.enabled": "Server CUI enabled. This only supports cuboid regions, with a maximum size of {0}x{1}x{2}.",
|
"worldedit.drawsel.enabled": "Server CUI enabled. This only supports cuboid regions, with a maximum size of {0}x{1}x{2}.",
|
||||||
@ -77,6 +79,7 @@
|
|||||||
"worldedit.clearhistory.cleared": "History cleared.",
|
"worldedit.clearhistory.cleared": "History cleared.",
|
||||||
|
|
||||||
"worldedit.raytrace.noblock": "No block in sight!",
|
"worldedit.raytrace.noblock": "No block in sight!",
|
||||||
|
"worldedit.raytrace.require-player": "Raytracing commands require a player!",
|
||||||
|
|
||||||
"worldedit.restore.not-configured": "Snapshot/backup restore is not configured.",
|
"worldedit.restore.not-configured": "Snapshot/backup restore is not configured.",
|
||||||
"worldedit.restore.not-available": "That snapshot does not exist or is not available.",
|
"worldedit.restore.not-available": "That snapshot does not exist or is not available.",
|
||||||
|
Loading…
Reference in New Issue
Block a user