Update upstream

17b9f00 Move tinyurls to ehub.to (2033)
76ec878 Allow biome commands to be used from non-player actors (2034)
This commit is contained in:
NotMyFault
2022-02-20 14:18:58 +01:00
parent 39081e62c9
commit f8e6feb1f2
5 changed files with 40 additions and 22 deletions

View File

@ -33,6 +33,7 @@ import com.sk89q.worldedit.command.util.annotation.Preload;
import com.sk89q.worldedit.entity.Player;
import com.sk89q.worldedit.extension.platform.Actor;
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.RegionMaskingFilter;
import com.sk89q.worldedit.function.biome.BiomeReplace;
@ -112,7 +113,7 @@ public class BiomeCommands {
)
@CommandPermissions("worldedit.biome.info")
public void biomeInfo(
Player player, LocalSession session,
Actor actor, World world, LocalSession session,
@Switch(name = 't', desc = "Use the block you are looking at.")
boolean useLineOfSight,
@Switch(name = 'p', desc = "Use the block you are currently in.")
@ -124,23 +125,33 @@ public class BiomeCommands {
String messageKey;
if (useLineOfSight) {
Location blockPosition = player.getBlockTrace(300);
if (blockPosition == null) {
player.print(Caption.of("worldedit.raytrace.noblock"));
if (actor instanceof Player) {
Location blockPosition = ((Player) actor).getBlockTrace(300);
if (blockPosition == null) {
actor.print(Caption.of("worldedit.raytrace.noblock"));
return;
}
BiomeType biome = world.getBiome(blockPosition.toVector().toBlockPoint());
biomes.add(biome);
messageKey = "worldedit.biomeinfo.lineofsight";
} else {
actor.print(Caption.of("worldedit.raytrace.require-player"));
return;
}
BiomeType biome = player.getWorld().getBiome(blockPosition.toVector().toBlockPoint());
biomes.add(biome);
messageKey = "worldedit.biomeinfo.lineofsight";
} else if (usePosition) {
BiomeType biome = player.getWorld().getBiome(player.getLocation().toVector().toBlockPoint());
biomes.add(biome);
if (actor instanceof Locatable) {
BiomeType biome = world.getBiome(((Locatable) actor).getLocation().toVector().toBlockPoint());
biomes.add(biome);
messageKey = "worldedit.biomeinfo.position";
messageKey = "worldedit.biomeinfo.position";
} else {
actor.print(Caption.of("worldedit.biomeinfo.not-locatable"));
return;
}
} else {
World world = player.getWorld();
Region region = session.getSelection(world);
for (BlockVector3 pt : region) {
@ -155,7 +166,7 @@ public class BiomeCommands {
HoverEvent.showText(TextComponent.of(biome.getId()))
)
).collect(Collectors.toList());
player.print(Caption.of(messageKey, TextUtils.join(components, TextComponent.of(", "))));
actor.print(Caption.of(messageKey, TextUtils.join(components, TextComponent.of(", "))));
}
@Command(
@ -168,18 +179,22 @@ public class BiomeCommands {
@Confirm(Confirm.Processor.REGION)
@CommandPermissions("worldedit.biome.set")
public void setBiome(
Player player, LocalSession session, EditSession editSession,
Actor actor, World world, LocalSession session, EditSession editSession,
@Arg(desc = "Biome type.") BiomeType target,
@Switch(name = 'p', desc = "Use your current position")
boolean atPosition
) throws WorldEditException {
World world = player.getWorld();
Region region;
Mask mask = editSession.getMask();
if (atPosition) {
final BlockVector3 pos = player.getLocation().toVector().toBlockPoint();
region = new CuboidRegion(pos, pos);
if (actor instanceof Locatable) {
final BlockVector3 pos = ((Locatable) actor).getLocation().toVector().toBlockPoint();
region = new CuboidRegion(pos, pos);
} else {
actor.print(Caption.of("worldedit.setbiome.not-locatable"));
return;
}
} else {
region = session.getSelection(world);
}
@ -191,7 +206,7 @@ public class BiomeCommands {
RegionVisitor visitor = new RegionVisitor(region, replace);
Operations.completeLegacy(visitor);
player.print(Caption.of(
actor.print(Caption.of(
"worldedit.setbiome.changed",
TextComponent.of(visitor.getAffected() / (editSession.getMaxY() - editSession.getMinY()))
));