update adapter and platform manager

This commit is contained in:
Jesse Boyd 2019-08-29 13:57:03 +01:00
parent aa4c443358
commit 68eea925e1
No known key found for this signature in database
GPG Key ID: 59F1DE6293AF6E1F
27 changed files with 27060 additions and 1197 deletions

View File

@ -29,6 +29,7 @@ configurations.all {
dependencies { dependencies {
"compile"("net.milkbowl.vault:VaultAPI:1.7") { isTransitive = false } "compile"("net.milkbowl.vault:VaultAPI:1.7") { isTransitive = false }
"api"(project(":worldedit-core")) "api"(project(":worldedit-core"))
"api"(project(":worldedit-libs:core"))
"api"(project(":worldedit-libs:bukkit")) "api"(project(":worldedit-libs:bukkit"))
"compile"("it.unimi.dsi:fastutil:8.2.1") "compile"("it.unimi.dsi:fastutil:8.2.1")
"api"("com.destroystokyo.paper:paper-api:1.14.4-R0.1-SNAPSHOT") { "api"("com.destroystokyo.paper:paper-api:1.14.4-R0.1-SNAPSHOT") {

View File

@ -403,7 +403,7 @@ public class BukkitGetBlocks_1_14 extends CharGetBlocks {
lock.setModified(false); lock.setModified(false);
// Efficiently convert ChunkSection to raw data // Efficiently convert ChunkSection to raw data
try { try {
Spigot_v1_14_R1 adapter = ((Spigot_v1_14_R1) WorldEditPlugin.getInstance().getBukkitImplAdapter()); Spigot_v1_14_R4 adapter = ((Spigot_v1_14_R4) WorldEditPlugin.getInstance().getBukkitImplAdapter());
final DataPaletteBlock<IBlockData> blocks = section.getBlocks(); final DataPaletteBlock<IBlockData> blocks = section.getBlocks();
final DataBits bits = (DataBits) BukkitAdapter_1_14.fieldBits.get(blocks); final DataBits bits = (DataBits) BukkitAdapter_1_14.fieldBits.get(blocks);
@ -478,7 +478,7 @@ public class BukkitGetBlocks_1_14 extends CharGetBlocks {
} }
} }
private final char ordinal(IBlockData ibd, Spigot_v1_14_R1 adapter) { private final char ordinal(IBlockData ibd, Spigot_v1_14_R4 adapter) {
if (ibd == null) { if (ibd == null) {
return BlockTypes.AIR.getDefaultState().getOrdinalChar(); return BlockTypes.AIR.getDefaultState().getOrdinalChar();
} else { } else {

View File

@ -0,0 +1,80 @@
package com.boydti.fawe.bukkit.adapter.mc1_14;
import com.mojang.authlib.GameProfile;
import net.minecraft.server.v1_14_R1.DamageSource;
import net.minecraft.server.v1_14_R1.DimensionManager;
import net.minecraft.server.v1_14_R1.Entity;
import net.minecraft.server.v1_14_R1.EntityPlayer;
import net.minecraft.server.v1_14_R1.IChatBaseComponent;
import net.minecraft.server.v1_14_R1.ITileInventory;
import net.minecraft.server.v1_14_R1.PacketPlayInSettings;
import net.minecraft.server.v1_14_R1.PlayerInteractManager;
import net.minecraft.server.v1_14_R1.Statistic;
import net.minecraft.server.v1_14_R1.Vec3D;
import net.minecraft.server.v1_14_R1.WorldServer;
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
import javax.annotation.Nullable;
import java.util.OptionalInt;
import java.util.UUID;
class FakePlayer_v1_14_R4 extends EntityPlayer {
private static final GameProfile FAKE_WORLDEDIT_PROFILE = new GameProfile(UUID.nameUUIDFromBytes("worldedit".getBytes()), "[WorldEdit]");
FakePlayer_v1_14_R4(WorldServer world) {
super(world.getMinecraftServer(), world, FAKE_WORLDEDIT_PROFILE, new PlayerInteractManager(world));
}
@Override
public Vec3D bP() {
return new Vec3D(0, 0, 0);
}
@Override
public void tick() {
}
@Override
public void die(DamageSource damagesource) {
}
@Override
public Entity a(DimensionManager dimensionmanager, TeleportCause cause) {
return this;
}
@Override
public OptionalInt openContainer(@Nullable ITileInventory itileinventory) {
return OptionalInt.empty();
}
@Override
public void a(PacketPlayInSettings packetplayinsettings) {
}
@Override
public void sendMessage(IChatBaseComponent ichatbasecomponent) {
}
@Override
public void a(IChatBaseComponent ichatbasecomponent, boolean flag) {
}
@Override
public void a(Statistic<?> statistic, int i) {
}
@Override
public void a(Statistic<?> statistic) {
}
@Override
public boolean isInvulnerable(DamageSource damagesource) {
return true;
}
@Override
public boolean p(boolean flag) { // canEat, search for foodData usage
return true;
}
}

View File

@ -20,6 +20,9 @@
package com.boydti.fawe.bukkit.adapter.mc1_14; package com.boydti.fawe.bukkit.adapter.mc1_14;
import com.boydti.fawe.Fawe; import com.boydti.fawe.Fawe;
import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
import com.sk89q.jnbt.ByteArrayTag; import com.sk89q.jnbt.ByteArrayTag;
@ -37,6 +40,8 @@ import com.sk89q.jnbt.NBTConstants;
import com.sk89q.jnbt.ShortTag; import com.sk89q.jnbt.ShortTag;
import com.sk89q.jnbt.StringTag; import com.sk89q.jnbt.StringTag;
import com.sk89q.jnbt.Tag; import com.sk89q.jnbt.Tag;
import com.sk89q.worldedit.blocks.BaseItem;
import com.sk89q.worldedit.blocks.BaseItemStack;
import com.sk89q.worldedit.blocks.TileEntityBlock; import com.sk89q.worldedit.blocks.TileEntityBlock;
import com.sk89q.worldedit.bukkit.BukkitAdapter; import com.sk89q.worldedit.bukkit.BukkitAdapter;
import com.sk89q.worldedit.bukkit.adapter.BukkitImplAdapter; import com.sk89q.worldedit.bukkit.adapter.BukkitImplAdapter;
@ -71,11 +76,17 @@ import net.minecraft.server.v1_14_R1.ChunkCoordIntPair;
import net.minecraft.server.v1_14_R1.ChunkSection; import net.minecraft.server.v1_14_R1.ChunkSection;
import net.minecraft.server.v1_14_R1.Entity; import net.minecraft.server.v1_14_R1.Entity;
import net.minecraft.server.v1_14_R1.EntityTypes; import net.minecraft.server.v1_14_R1.EntityTypes;
import net.minecraft.server.v1_14_R1.EnumDirection;
import net.minecraft.server.v1_14_R1.EnumHand;
import net.minecraft.server.v1_14_R1.EnumInteractionResult;
import net.minecraft.server.v1_14_R1.IBlockData; import net.minecraft.server.v1_14_R1.IBlockData;
import net.minecraft.server.v1_14_R1.IBlockState; import net.minecraft.server.v1_14_R1.IBlockState;
import net.minecraft.server.v1_14_R1.INamable; import net.minecraft.server.v1_14_R1.INamable;
import net.minecraft.server.v1_14_R1.IRegistry; import net.minecraft.server.v1_14_R1.IRegistry;
import net.minecraft.server.v1_14_R1.ItemActionContext;
import net.minecraft.server.v1_14_R1.ItemStack;
import net.minecraft.server.v1_14_R1.MinecraftKey; import net.minecraft.server.v1_14_R1.MinecraftKey;
import net.minecraft.server.v1_14_R1.MovingObjectPositionBlock;
import net.minecraft.server.v1_14_R1.NBTBase; import net.minecraft.server.v1_14_R1.NBTBase;
import net.minecraft.server.v1_14_R1.NBTTagByte; import net.minecraft.server.v1_14_R1.NBTTagByte;
import net.minecraft.server.v1_14_R1.NBTTagByteArray; import net.minecraft.server.v1_14_R1.NBTTagByteArray;
@ -94,6 +105,7 @@ import net.minecraft.server.v1_14_R1.PacketPlayOutEntityStatus;
import net.minecraft.server.v1_14_R1.PacketPlayOutTileEntityData; import net.minecraft.server.v1_14_R1.PacketPlayOutTileEntityData;
import net.minecraft.server.v1_14_R1.PlayerChunkMap; import net.minecraft.server.v1_14_R1.PlayerChunkMap;
import net.minecraft.server.v1_14_R1.TileEntity; import net.minecraft.server.v1_14_R1.TileEntity;
import net.minecraft.server.v1_14_R1.Vec3D;
import net.minecraft.server.v1_14_R1.World; import net.minecraft.server.v1_14_R1.World;
import net.minecraft.server.v1_14_R1.WorldServer; import net.minecraft.server.v1_14_R1.WorldServer;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
@ -105,6 +117,7 @@ import org.bukkit.craftbukkit.v1_14_R1.CraftWorld;
import org.bukkit.craftbukkit.v1_14_R1.block.data.CraftBlockData; import org.bukkit.craftbukkit.v1_14_R1.block.data.CraftBlockData;
import org.bukkit.craftbukkit.v1_14_R1.entity.CraftEntity; import org.bukkit.craftbukkit.v1_14_R1.entity.CraftEntity;
import org.bukkit.craftbukkit.v1_14_R1.entity.CraftPlayer; import org.bukkit.craftbukkit.v1_14_R1.entity.CraftPlayer;
import org.bukkit.craftbukkit.v1_14_R1.inventory.CraftItemStack;
import org.bukkit.craftbukkit.v1_14_R1.util.CraftMagicNumbers; import org.bukkit.craftbukkit.v1_14_R1.util.CraftMagicNumbers;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason; import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason;
@ -120,12 +133,13 @@ import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.concurrent.ExecutionException;
import java.util.function.Supplier; import java.util.function.Supplier;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;
public final class Spigot_v1_14_R1 extends CachedBukkitAdapter implements BukkitImplAdapter<NBTBase>{ public final class Spigot_v1_14_R4 extends CachedBukkitAdapter implements BukkitImplAdapter<NBTBase>{
private final Logger logger = LoggerFactory.getLogger(getClass()); private final Logger logger = LoggerFactory.getLogger(getClass());
@ -141,7 +155,7 @@ public final class Spigot_v1_14_R1 extends CachedBukkitAdapter implements Bukkit
// Code that may break between versions of Minecraft // Code that may break between versions of Minecraft
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
public Spigot_v1_14_R1() throws NoSuchFieldException, NoSuchMethodException { public Spigot_v1_14_R4() throws NoSuchFieldException, NoSuchMethodException {
// The list of tags on an NBTTagList // The list of tags on an NBTTagList
nbtListTagListField = NBTTagList.class.getDeclaredField("list"); nbtListTagListField = NBTTagList.class.getDeclaredField("list");
nbtListTagListField.setAccessible(true); nbtListTagListField.setAccessible(true);
@ -259,12 +273,7 @@ public final class Spigot_v1_14_R1 extends CachedBukkitAdapter implements Bukkit
@Override @Override
public DataFixer getDataFixer() { public DataFixer getDataFixer() {
try { return DataConverters_1_14_R4.INSTANCE;
Class<?> converter = Class.forName("com.sk89q.worldedit.bukkit.adapter.impl.DataConverters_1_14_R4");
return (DataFixer) converter.getDeclaredField("INSTANCE").get(null);
} catch (ClassNotFoundException | NoSuchFieldException | IllegalAccessException e) {
throw new RuntimeException(e);
}
} }
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
@ -632,15 +641,75 @@ public final class Spigot_v1_14_R1 extends CachedBukkitAdapter implements Bukkit
this.setBlock(position.getChunk(), position.getBlockX(), position.getBlockY(), position.getBlockZ(), previousType, true); this.setBlock(position.getChunk(), position.getBlockX(), position.getBlockY(), position.getBlockZ(), previousType, true);
} }
@Override
public boolean setBlock(Location location, BlockStateHolder<?> state, boolean notifyAndLight) {
return this.setBlock(location.getChunk(), location.getBlockX(), location.getBlockY(), location.getBlockZ(), state, notifyAndLight);
}
@Override @Override
public void sendFakeOP(Player player) { public void sendFakeOP(Player player) {
((CraftPlayer) player).getHandle().playerConnection.sendPacket(new PacketPlayOutEntityStatus( ((CraftPlayer) player).getHandle().playerConnection.sendPacket(new PacketPlayOutEntityStatus(
((CraftPlayer) player).getHandle(), (byte) 28 ((CraftPlayer) player).getHandle(), (byte) 28
)); ));
} }
private static EnumDirection adapt(Direction face) {
switch (face) {
case NORTH: return EnumDirection.NORTH;
case SOUTH: return EnumDirection.SOUTH;
case WEST: return EnumDirection.WEST;
case EAST: return EnumDirection.EAST;
case DOWN: return EnumDirection.DOWN;
case UP:
default:
return EnumDirection.UP;
}
}
private LoadingCache<WorldServer, FakePlayer_v1_14_R4> fakePlayers = CacheBuilder.newBuilder().weakKeys().softValues().build(CacheLoader.from(FakePlayer_v1_14_R4::new));
@Override
public synchronized boolean simulateItemUse(org.bukkit.World world, BlockVector3 position, BaseItem item, Direction face) {
CraftWorld craftWorld = (CraftWorld) world;
WorldServer worldServer = craftWorld.getHandle();
ItemStack stack = CraftItemStack.asNMSCopy(BukkitAdapter.adapt(item instanceof BaseItemStack
? ((BaseItemStack) item) : new BaseItemStack(item.getType(), item.getNbtData(), 1)));
stack.setTag((NBTTagCompound) fromNative(item.getNbtData()));
FakePlayer_v1_14_R4 fakePlayer;
try {
fakePlayer = fakePlayers.get(worldServer);
} catch (ExecutionException ignored) {
return false;
}
fakePlayer.a(EnumHand.MAIN_HAND, stack);
fakePlayer.setLocation(position.getBlockX(), position.getBlockY(), position.getBlockZ(),
(float) face.toVector().toYaw(), (float) face.toVector().toPitch());
final BlockPosition blockPos = new BlockPosition(position.getBlockX(), position.getBlockY(), position.getBlockZ());
final Vec3D blockVec = new Vec3D(blockPos);
final EnumDirection enumFacing = adapt(face);
MovingObjectPositionBlock rayTrace = new MovingObjectPositionBlock(blockVec, enumFacing, blockPos, false);
ItemActionContext context = new ItemActionContext(fakePlayer, EnumHand.MAIN_HAND, rayTrace);
EnumInteractionResult result = stack.placeItem(context, EnumHand.MAIN_HAND);
if (result != EnumInteractionResult.SUCCESS) {
if (worldServer.getType(blockPos).interact(worldServer, fakePlayer, EnumHand.MAIN_HAND, rayTrace)) {
result = EnumInteractionResult.SUCCESS;
} else {
result = stack.getItem().a(worldServer, fakePlayer, EnumHand.MAIN_HAND).a();
}
}
return result == EnumInteractionResult.SUCCESS;
}
@Override
public org.bukkit.inventory.ItemStack adapt(BaseItemStack item) {
ItemStack stack = new ItemStack(IRegistry.ITEM.get(MinecraftKey.a(item.getType().getId())), item.getAmount());
stack.setTag(((NBTTagCompound) fromNative(item.getNbtData())));
return CraftItemStack.asCraftMirror(stack);
}
@Override
public BaseItemStack adapt(org.bukkit.inventory.ItemStack itemStack) {
final ItemStack nmsStack = CraftItemStack.asNMSCopy(itemStack);
final BaseItemStack weStack = new BaseItemStack(BukkitAdapter.asItemType(itemStack.getType()), itemStack.getAmount());
weStack.setNbtData(((CompoundTag) toNative(nmsStack.getTag())));
return weStack;
}
} }

View File

@ -54,8 +54,8 @@ import org.bukkit.util.Consumer;
import org.bukkit.util.RayTraceResult; import org.bukkit.util.RayTraceResult;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import javax.annotation.Nullable;
import java.io.File; import java.io.File;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;

View File

@ -16,7 +16,8 @@ import org.bukkit.DyeColor;
import org.bukkit.block.Sign; import org.bukkit.block.Sign;
import org.bukkit.persistence.PersistentDataContainer; import org.bukkit.persistence.PersistentDataContainer;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import javax.annotation.Nullable;
public class AsyncSign extends AsyncBlockState implements Sign { public class AsyncSign extends AsyncBlockState implements Sign {
public AsyncSign(AsyncBlock block, BaseBlock state) { public AsyncSign(AsyncBlock block, BaseBlock state) {

View File

@ -29,8 +29,12 @@ import com.sk89q.worldedit.util.Location;
import com.sk89q.worldedit.util.auth.AuthorizationException; import com.sk89q.worldedit.util.auth.AuthorizationException;
import com.sk89q.worldedit.util.formatting.text.Component; import com.sk89q.worldedit.util.formatting.text.Component;
import com.sk89q.worldedit.util.formatting.text.adapter.bukkit.TextAdapter; import com.sk89q.worldedit.util.formatting.text.adapter.bukkit.TextAdapter;
import org.bukkit.Chunk;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.command.BlockCommandSender; import org.bukkit.command.BlockCommandSender;
import org.jetbrains.annotations.NotNull;
import java.util.UUID; import java.util.UUID;
@ -149,14 +153,20 @@ public class BukkitBlockCommandSender extends AbstractNonPlayerActor implements
@Override @Override
public boolean isActive() { public boolean isActive() {
return sender.getBlock().getType() == Material.COMMAND_BLOCK @NotNull Block block = sender.getBlock();
|| sender.getBlock().getType() == Material.CHAIN_COMMAND_BLOCK @NotNull World world = block.getWorld();
|| sender.getBlock().getType() == Material.REPEATING_COMMAND_BLOCK; if (world.isChunkLoaded(block.getX() >> 4, block.getZ() >> 4)) {
@NotNull Material type = block.getType();
return type == Material.COMMAND_BLOCK
|| type == Material.CHAIN_COMMAND_BLOCK
|| type == Material.REPEATING_COMMAND_BLOCK;
}
return false;
} }
@Override @Override
public boolean isPersistent() { public boolean isPersistent() {
return false; return true;
} }
@Override @Override

View File

@ -32,6 +32,8 @@ import java.io.File;
import java.util.UUID; import java.util.UUID;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.command.ConsoleCommandSender;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
public class BukkitCommandSender extends AbstractNonPlayerActor { public class BukkitCommandSender extends AbstractNonPlayerActor {
@ -42,14 +44,12 @@ public class BukkitCommandSender extends AbstractNonPlayerActor {
private static final UUID DEFAULT_ID = UUID.fromString("a233eb4b-4cab-42cd-9fd9-7e7b9a3f74be"); private static final UUID DEFAULT_ID = UUID.fromString("a233eb4b-4cab-42cd-9fd9-7e7b9a3f74be");
private CommandSender sender; private CommandSender sender;
private WorldEditPlugin plugin;
public BukkitCommandSender(WorldEditPlugin plugin, CommandSender sender) { public BukkitCommandSender(WorldEditPlugin plugin, CommandSender sender) {
checkNotNull(plugin); checkNotNull(plugin);
checkNotNull(sender); checkNotNull(sender);
checkArgument(!(sender instanceof Player), "Cannot wrap a player"); checkArgument(!(sender instanceof Player), "Cannot wrap a player");
this.plugin = plugin;
this.sender = sender; this.sender = sender;
} }
@ -152,6 +152,10 @@ public class BukkitCommandSender extends AbstractNonPlayerActor {
@Override @Override
public boolean isActive() { public boolean isActive() {
if (sender instanceof Entity) {
Entity entity = (Entity) sender;
return (entity.isValid() && !entity.isDead());
}
return true; return true;
} }

View File

@ -19,11 +19,12 @@
package com.sk89q.worldedit.bukkit; package com.sk89q.worldedit.bukkit;
import com.bekvon.bukkit.residence.commands.message;
import com.boydti.fawe.Fawe; import com.boydti.fawe.Fawe;
import com.boydti.fawe.bukkit.FaweBukkit; import com.boydti.fawe.bukkit.FaweBukkit;
import com.boydti.fawe.util.MainUtil; import com.boydti.fawe.util.MainUtil;
import com.boydti.fawe.bukkit.adapter.mc1_14.Spigot_v1_14_R1; import com.boydti.fawe.bukkit.adapter.mc1_14.Spigot_v1_14_R4;
import com.google.common.base.Joiner; import com.google.common.base.Joiner;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;
import com.sk89q.util.yaml.YAMLProcessor; import com.sk89q.util.yaml.YAMLProcessor;
@ -37,19 +38,13 @@ import com.sk89q.worldedit.bukkit.adapter.BukkitImplLoader;
import com.sk89q.worldedit.event.platform.CommandEvent; import com.sk89q.worldedit.event.platform.CommandEvent;
import com.sk89q.worldedit.event.platform.CommandSuggestionEvent; import com.sk89q.worldedit.event.platform.CommandSuggestionEvent;
import com.sk89q.worldedit.event.platform.PlatformReadyEvent; import com.sk89q.worldedit.event.platform.PlatformReadyEvent;
import com.sk89q.worldedit.extension.input.InputParseException;
import com.sk89q.worldedit.extension.input.ParserContext;
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.Platform; import com.sk89q.worldedit.extension.platform.Platform;
import com.sk89q.worldedit.extent.inventory.BlockBag; import com.sk89q.worldedit.extent.inventory.BlockBag;
import com.sk89q.worldedit.internal.command.CommandUtil; import com.sk89q.worldedit.internal.command.CommandUtil;
import com.sk89q.worldedit.registry.state.Property;
import com.sk89q.worldedit.world.biome.BiomeType; import com.sk89q.worldedit.world.biome.BiomeType;
import com.sk89q.worldedit.world.block.BlockCategory; import com.sk89q.worldedit.world.block.BlockCategory;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.block.BlockType;
import com.sk89q.worldedit.world.block.FuzzyBlockState;
import com.sk89q.worldedit.world.entity.EntityType; import com.sk89q.worldedit.world.entity.EntityType;
import com.sk89q.worldedit.world.gamemode.GameModes; import com.sk89q.worldedit.world.gamemode.GameModes;
import com.sk89q.worldedit.world.item.ItemCategory; import com.sk89q.worldedit.world.item.ItemCategory;
@ -305,7 +300,11 @@ public class WorldEditPlugin extends JavaPlugin { //implements TabCompleter
try { try {
Bukkit.getPluginManager().loadPlugin(dummy); Bukkit.getPluginManager().loadPlugin(dummy);
} catch (Throwable e) { } catch (Throwable e) {
e.printStackTrace(); if (Bukkit.getUpdateFolderFile().mkdirs()) {
MainUtil.copyFile(MainUtil.getJarFile(), "DummyFawe.src", pluginsFolder, Bukkit.getUpdateFolder() + File.separator + "DummyFawe.jar");
} else {
getLogger().info("Please delete DummyFawe.jar and restart");
}
} }
getLogger().info("Please restart the server if you have any plugins which depend on FAWE."); getLogger().info("Please restart the server if you have any plugins which depend on FAWE.");
} else if (dummy == null) { } else if (dummy == null) {
@ -343,7 +342,7 @@ public class WorldEditPlugin extends JavaPlugin { //implements TabCompleter
// Attempt to load a Bukkit adapter // Attempt to load a Bukkit adapter
BukkitImplLoader adapterLoader = new BukkitImplLoader(); BukkitImplLoader adapterLoader = new BukkitImplLoader();
try { try {
adapterLoader.addClass(Spigot_v1_14_R1.class); adapterLoader.addClass(Spigot_v1_14_R4.class);
} catch (Throwable throwable) { } catch (Throwable throwable) {
throwable.printStackTrace(); throwable.printStackTrace();
} }
@ -439,7 +438,7 @@ public class WorldEditPlugin extends JavaPlugin { //implements TabCompleter
// code of WorldEdit expects it // code of WorldEdit expects it
String[] split = new String[args.length + 1]; String[] split = new String[args.length + 1];
System.arraycopy(args, 0, split, 1, args.length); System.arraycopy(args, 0, split, 1, args.length);
split[0] = "/" + commandLabel; split[0] = commandLabel;
CommandEvent event = new CommandEvent(wrapCommandSender(sender), Joiner.on(" ").join(split)); CommandEvent event = new CommandEvent(wrapCommandSender(sender), Joiner.on(" ").join(split));
getWorldEdit().getEventBus().post(event); getWorldEdit().getEventBus().post(event);

View File

@ -23,9 +23,12 @@ import com.boydti.fawe.Fawe;
import com.boydti.fawe.bukkit.FaweBukkit; import com.boydti.fawe.bukkit.FaweBukkit;
import com.sk89q.jnbt.CompoundTag; import com.sk89q.jnbt.CompoundTag;
import com.sk89q.jnbt.Tag; import com.sk89q.jnbt.Tag;
import com.sk89q.worldedit.blocks.BaseItem;
import com.sk89q.worldedit.blocks.BaseItemStack;
import com.sk89q.worldedit.entity.BaseEntity; import com.sk89q.worldedit.entity.BaseEntity;
import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.registry.state.Property; import com.sk89q.worldedit.registry.state.Property;
import com.sk89q.worldedit.util.Direction;
import com.sk89q.worldedit.world.DataFixer; import com.sk89q.worldedit.world.DataFixer;
import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockState;
@ -39,8 +42,10 @@ import org.bukkit.World;
import org.bukkit.WorldCreator; import org.bukkit.WorldCreator;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import java.util.Map; import java.util.Map;
import java.util.OptionalInt;
import javax.annotation.Nullable; import javax.annotation.Nullable;
@ -72,9 +77,6 @@ public interface BukkitImplAdapter<T> extends IBukkitAdapter {
*/ */
BaseBlock getBlock(Location location); BaseBlock getBlock(Location location);
boolean setBlock(Chunk chunk, int x, int y, int z, BlockStateHolder<?> state, boolean update);
boolean isChunkInUse(Chunk chunk);
/** /**
* Set the block at the given location. * Set the block at the given location.
* *
@ -83,7 +85,11 @@ public interface BukkitImplAdapter<T> extends IBukkitAdapter {
* @param notifyAndLight notify and light if set * @param notifyAndLight notify and light if set
* @return true if a block was likely changed * @return true if a block was likely changed
*/ */
boolean setBlock(Location location, BlockStateHolder<?> state, boolean notifyAndLight); default boolean setBlock(Location location, BlockStateHolder<?> state, boolean notifyAndLight) {
return this.setBlock(location.getChunk(), location.getBlockX(), location.getBlockY(), location.getBlockZ(), state, notifyAndLight);
}
boolean setBlock(Chunk chunk, int x, int y, int z, BlockStateHolder<?> state, boolean update);
/** /**
* Notifies the simulation that the block at the given location has * Notifies the simulation that the block at the given location has
@ -121,22 +127,6 @@ public interface BukkitImplAdapter<T> extends IBukkitAdapter {
*/ */
Map<String, ? extends Property<?>> getProperties(BlockType blockType); Map<String, ? extends Property<?>> getProperties(BlockType blockType);
default BlockMaterial getMaterial(BlockType blockType) {
return null;
}
default BlockMaterial getMaterial(BlockState blockState) {
return null;
}
default Tag toNative(T foreign) {
return null;
}
default T fromNative(Tag foreign) {
return null;
}
/** /**
* Send the given NBT data to the player. * Send the given NBT data to the player.
* *
@ -154,7 +144,65 @@ public interface BukkitImplAdapter<T> extends IBukkitAdapter {
*/ */
void sendFakeOP(Player player); void sendFakeOP(Player player);
default @org.jetbrains.annotations.Nullable World createWorld(WorldCreator creator) { /**
* Simulates a player using an item.
*
* @param world the world
* @param position the location
* @param item the item to be used
* @param face the direction in which to "face" when using the item
* @return whether the usage was successful
*/
default boolean simulateItemUse(World world, BlockVector3 position, BaseItem item, Direction face) {
return false;
}
/**
* Create a Bukkit ItemStack with NBT, if available.
*
* @param item the WorldEdit BaseItemStack to adapt
* @return the Bukkit ItemStack
*/
ItemStack adapt(BaseItemStack item);
/**
* Create a WorldEdit ItemStack with NBT, if available.
*
* @param itemStack the Bukkit ItemStack to adapt
* @return the WorldEdit BaseItemStack
*/
BaseItemStack adapt(ItemStack itemStack);
/**
* Retrieve the internal ID for a given state, if possible.
*
* @param state The block state
* @return the internal ID of the state
*/
default OptionalInt getInternalBlockStateId(BlockState state) {
return OptionalInt.empty();
}
boolean isChunkInUse(Chunk chunk);
default BlockMaterial getMaterial(BlockType blockType) {
return null;
}
default BlockMaterial getMaterial(BlockState blockState) {
return null;
}
default Tag toNative(T foreign) {
return null;
}
default T fromNative(Tag foreign) {
return null;
}
default @Nullable World createWorld(WorldCreator creator) {
return ((FaweBukkit) Fawe.imp()).createWorldUnloaded(creator::createWorld); return ((FaweBukkit) Fawe.imp()).createWorldUnloaded(creator::createWorld);
} }
} }

View File

@ -29,7 +29,6 @@ import com.sk89q.worldedit.command.util.CommandPermissions;
import com.sk89q.minecraft.util.commands.NestedCommand; import com.sk89q.minecraft.util.commands.NestedCommand;
import com.sk89q.worldedit.command.BiomeCommands; import com.sk89q.worldedit.command.BiomeCommands;
import com.sk89q.worldedit.command.BrushCommands; import com.sk89q.worldedit.command.BrushCommands;
import com.sk89q.worldedit.command.BrushOptionsCommands;
import com.sk89q.worldedit.command.ChunkCommands; import com.sk89q.worldedit.command.ChunkCommands;
import com.sk89q.worldedit.command.ClipboardCommands; import com.sk89q.worldedit.command.ClipboardCommands;
import com.sk89q.worldedit.command.GenerationCommands; import com.sk89q.worldedit.command.GenerationCommands;
@ -124,7 +123,6 @@ public final class DocumentationPrinter {
writePermissionsWikiTable(stream, builder, "/", ScriptingCommands.class); writePermissionsWikiTable(stream, builder, "/", ScriptingCommands.class);
writePermissionsWikiTable(stream, builder, "/", ChunkCommands.class); writePermissionsWikiTable(stream, builder, "/", ChunkCommands.class);
writePermissionsWikiTable(stream, builder, "/", ToolUtilCommands.class); writePermissionsWikiTable(stream, builder, "/", ToolUtilCommands.class);
writePermissionsWikiTable(stream, builder, "/", BrushOptionsCommands.class);
writePermissionsWikiTable(stream, builder, "/tool ", ToolCommands.class); writePermissionsWikiTable(stream, builder, "/tool ", ToolCommands.class);
writePermissionsWikiTable(stream, builder, "/brush ", BrushCommands.class); writePermissionsWikiTable(stream, builder, "/brush ", BrushCommands.class);
//writePermissionsWikiTable(stream, builder, "", MaskCommands.class, "/Masks"); //writePermissionsWikiTable(stream, builder, "", MaskCommands.class, "/Masks");

View File

@ -72,6 +72,28 @@ public class ApplyBrushCommands {
.ofTypes(ImmutableList.of(Key.of(double.class))) .ofTypes(ImmutableList.of(Key.of(double.class)))
.build(); .build();
public static void register(CommandManagerService service, CommandManager commandManager, CommandRegistrationHandler registration) {
commandManager.register("apply", builder -> {
builder.description(TextComponent.of("Apply brush, apply a function to every block"));
builder.action(org.enginehub.piston.Command.Action.NULL_ACTION);
CommandManager manager = service.newCommandManager();
registration.register(
manager,
ApplyBrushCommandsRegistration.builder(),
new ApplyBrushCommands()
);
builder.condition(new PermissionCondition(ImmutableSet.of("worldedit.brush.apply")));
builder.addParts(REGION_FACTORY, RADIUS);
builder.addPart(SubCommandPart.builder(TranslatableComponent.of("type"), TextComponent.of("Type of brush to use"))
.withCommands(manager.getAllCommands().collect(Collectors.toList()))
.required()
.build());
});
}
private void setApplyBrush(CommandParameters parameters, Player player, LocalSession localSession, private void setApplyBrush(CommandParameters parameters, Player player, LocalSession localSession,
Contextual<? extends RegionFunction> generatorFactory) throws WorldEditException { Contextual<? extends RegionFunction> generatorFactory) throws WorldEditException {
double radius = requireNonNull(RADIUS.value(parameters).asSingle(double.class)); double radius = requireNonNull(RADIUS.value(parameters).asSingle(double.class));

View File

@ -56,7 +56,9 @@ import com.boydti.fawe.object.brush.heightmap.ScalableHeightMap;
import com.boydti.fawe.object.brush.heightmap.ScalableHeightMap.Shape; import com.boydti.fawe.object.brush.heightmap.ScalableHeightMap.Shape;
import com.boydti.fawe.object.brush.sweep.SweepBrush; import com.boydti.fawe.object.brush.sweep.SweepBrush;
import com.boydti.fawe.object.clipboard.MultiClipboardHolder; import com.boydti.fawe.object.clipboard.MultiClipboardHolder;
import com.boydti.fawe.object.io.PGZIPOutputStream;
import com.boydti.fawe.object.mask.IdMask; import com.boydti.fawe.object.mask.IdMask;
import com.boydti.fawe.util.MainUtil;
import com.boydti.fawe.util.MathMan; import com.boydti.fawe.util.MathMan;
import com.boydti.fawe.util.StringMan; import com.boydti.fawe.util.StringMan;
import com.boydti.fawe.util.image.ImageUtil; import com.boydti.fawe.util.image.ImageUtil;
@ -67,6 +69,7 @@ import com.sk89q.worldedit.EmptyClipboardException;
import com.sk89q.worldedit.LocalSession; import com.sk89q.worldedit.LocalSession;
import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.blocks.BaseItem;
import com.sk89q.worldedit.command.factory.TreeGeneratorFactory; import com.sk89q.worldedit.command.factory.TreeGeneratorFactory;
import com.sk89q.worldedit.command.tool.BrushTool; import com.sk89q.worldedit.command.tool.BrushTool;
import com.sk89q.worldedit.command.tool.InvalidToolBindException; import com.sk89q.worldedit.command.tool.InvalidToolBindException;
@ -112,13 +115,19 @@ import com.sk89q.worldedit.world.block.BlockStateHolder;
import com.sk89q.worldedit.world.block.BlockType; import com.sk89q.worldedit.world.block.BlockType;
import com.sk89q.worldedit.world.block.BlockTypes; import com.sk89q.worldedit.world.block.BlockTypes;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.net.URI; import java.net.URI;
import java.nio.file.FileSystems;
import java.util.List; import java.util.List;
import java.util.zip.GZIPInputStream;
import org.enginehub.piston.annotation.Command; import org.enginehub.piston.annotation.Command;
import org.enginehub.piston.annotation.CommandContainer; import org.enginehub.piston.annotation.CommandContainer;
import org.enginehub.piston.annotation.param.Arg; import org.enginehub.piston.annotation.param.Arg;
@ -930,6 +939,91 @@ public class BrushCommands {
new Deform("y+=1"), shape, "worldedit.brush.lower"); new Deform("y+=1"), shape, "worldedit.brush.lower");
} }
@Command(
name = "savebrush",
aliases = {"save"},
desc = "Save your current brush"
)
@CommandPermissions("worldedit.brush.save")
public void saveBrush(Player player, LocalSession session, String name,
@Switch(name = 'g', desc = "Save the brush globally") boolean root) throws WorldEditException, IOException {
BrushTool tool = session.getBrushTool(player);
if (tool != null) {
root |= name.startsWith("../");
name = FileSystems.getDefault().getPath(name).getFileName().toString();
File folder = MainUtil.getFile(Fawe.imp().getDirectory(), "brushes");
name = name.endsWith(".jsgz") ? name : name + ".jsgz";
File file;
if (root && player.hasPermission("worldedit.brush.save.other")) {
file = new File(folder, name);
} else {
file = new File(folder, player.getUniqueId() + File.separator + name);
}
File parent = file.getParentFile();
if (!parent.exists()) {
parent.mkdirs();
}
file.createNewFile();
try (DataOutputStream out = new DataOutputStream(
new PGZIPOutputStream(new FileOutputStream(file)))) {
out.writeUTF(tool.toString());
} catch (Throwable e) {
e.printStackTrace();
}
BBC.SCHEMATIC_SAVED.send(player, name);
} else {
BBC.BRUSH_NONE.send(player);
}
}
@Command(
name = "loadbrush",
aliases = {"load"},
desc = "Load a brush"
)
@CommandPermissions("worldedit.brush.load")
public void loadBrush(Player player, LocalSession session, String name)
throws WorldEditException, IOException {
name = FileSystems.getDefault().getPath(name).getFileName().toString();
File folder = MainUtil.getFile(Fawe.imp().getDirectory(), "brushes");
name = name.endsWith(".jsgz") ? name : name + ".jsgz";
File file = new File(folder, player.getUniqueId() + File.separator + name);
if (!file.exists()) {
file = new File(folder, name);
}
if (!file.exists()) {
File[] files = folder.listFiles(pathname -> false);
BBC.BRUSH_NOT_FOUND.send(player, name);
return;
}
try (DataInputStream in = new DataInputStream(
new GZIPInputStream(new FileInputStream(file)))) {
String json = in.readUTF();
BrushTool tool = BrushTool.fromString(player, session, json);
BaseItem item = player.getItemInHand(HandSide.MAIN_HAND);
session.setTool(item, tool, player);
BBC.BRUSH_EQUIPPED.send(player, name);
} catch (Throwable e) {
e.printStackTrace();
BBC.BRUSH_INCOMPATIBLE.send(player);
}
}
@Command(
name = "/listbrush",
desc = "List saved brushes",
descFooter = "List all brushes in the brush directory"
)
@CommandPermissions("worldedit.brush.list")
public void list(Actor actor, InjectedValueAccess args,
@ArgFlag(name = 'p', desc = "Prints the requested page", def = "0")
int page) throws WorldEditException {
String baseCmd = "/brush loadbrush";
File dir = MainUtil.getFile(Fawe.imp().getDirectory(), "brushes");
// TODO NOT IMPLEMENTED
// UtilityCommands.list(dir, actor, args, page, null, true, baseCmd);
}
static void setOperationBasedBrush(Player player, LocalSession session, Expression radius, static void setOperationBasedBrush(Player player, LocalSession session, Expression radius,
Contextual<? extends Operation> factory, Contextual<? extends Operation> factory,
RegionFactory shape, RegionFactory shape,

View File

@ -1,491 +0,0 @@
package com.sk89q.worldedit.command;
import com.boydti.fawe.Fawe;
import com.boydti.fawe.config.BBC;
import com.boydti.fawe.object.brush.BrushSettings;
import com.boydti.fawe.object.brush.TargetMode;
import com.boydti.fawe.object.brush.scroll.ScrollAction;
import com.boydti.fawe.object.brush.visualization.VisualMode;
import com.boydti.fawe.object.extent.ResettableExtent;
import com.boydti.fawe.object.io.PGZIPOutputStream;
import com.boydti.fawe.util.MainUtil;
import com.boydti.fawe.util.MathMan;
import com.boydti.fawe.util.StringMan;
import com.google.common.collect.Iterables;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.LocalSession;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.blocks.BaseItem;
import com.sk89q.worldedit.command.argument.Arguments;
import com.sk89q.worldedit.command.tool.BrushTool;
import com.sk89q.worldedit.command.util.CommandPermissions;
import com.sk89q.worldedit.command.util.CommandPermissionsConditionGenerator;
import com.sk89q.worldedit.entity.Player;
import com.sk89q.worldedit.event.platform.CommandEvent;
import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.extension.platform.PlatformCommandManager;
import com.sk89q.worldedit.function.mask.Mask;
import com.sk89q.worldedit.function.pattern.Pattern;
import com.sk89q.worldedit.internal.annotation.Range;
import com.sk89q.worldedit.internal.command.CommandArgParser;
import com.sk89q.worldedit.util.HandSide;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.file.FileSystems;
import java.util.List;
import java.util.zip.GZIPInputStream;
import org.enginehub.piston.annotation.Command;
import org.enginehub.piston.annotation.CommandContainer;
import org.enginehub.piston.annotation.param.Arg;
import org.enginehub.piston.annotation.param.ArgFlag;
import org.enginehub.piston.annotation.param.Switch;
import org.enginehub.piston.inject.InjectedValueAccess;
/**
* Tool commands.
*/
@CommandContainer(superTypes = CommandPermissionsConditionGenerator.Registration.class)
public class BrushOptionsCommands {
private WorldEdit worldEdit;
public BrushOptionsCommands(WorldEdit worldEdit) {
this.worldEdit = worldEdit;
}
@Command(
name = "savebrush",
aliases = {"save"},
desc = "Save your current brush"
)
@CommandPermissions("worldedit.brush.save")
public void saveBrush(Player player, LocalSession session, String name,
@Switch(name = 'g', desc = "Save the brush globally") boolean root) throws WorldEditException, IOException {
BrushTool tool = session.getBrushTool(player);
if (tool != null) {
root |= name.startsWith("../");
name = FileSystems.getDefault().getPath(name).getFileName().toString();
File folder = MainUtil.getFile(Fawe.imp().getDirectory(), "brushes");
name = name.endsWith(".jsgz") ? name : name + ".jsgz";
File file;
if (root && player.hasPermission("worldedit.brush.save.other")) {
file = new File(folder, name);
} else {
file = new File(folder, player.getUniqueId() + File.separator + name);
}
File parent = file.getParentFile();
if (!parent.exists()) {
parent.mkdirs();
}
file.createNewFile();
try (DataOutputStream out = new DataOutputStream(
new PGZIPOutputStream(new FileOutputStream(file)))) {
out.writeUTF(tool.toString());
} catch (Throwable e) {
e.printStackTrace();
}
BBC.SCHEMATIC_SAVED.send(player, name);
} else {
BBC.BRUSH_NONE.send(player);
}
}
@Command(
name = "loadbrush",
aliases = {"load"},
desc = "Load a brush"
)
@CommandPermissions("worldedit.brush.load")
public void loadBrush(Player player, LocalSession session, String name)
throws WorldEditException, IOException {
name = FileSystems.getDefault().getPath(name).getFileName().toString();
File folder = MainUtil.getFile(Fawe.imp().getDirectory(), "brushes");
name = name.endsWith(".jsgz") ? name : name + ".jsgz";
File file = new File(folder, player.getUniqueId() + File.separator + name);
if (!file.exists()) {
file = new File(folder, name);
}
if (!file.exists()) {
File[] files = folder.listFiles(pathname -> false);
BBC.BRUSH_NOT_FOUND.send(player, name);
return;
}
try (DataInputStream in = new DataInputStream(
new GZIPInputStream(new FileInputStream(file)))) {
String json = in.readUTF();
BrushTool tool = BrushTool.fromString(player, session, json);
BaseItem item = player.getItemInHand(HandSide.MAIN_HAND);
session.setTool(item, tool, player);
BBC.BRUSH_EQUIPPED.send(player, name);
} catch (Throwable e) {
e.printStackTrace();
BBC.BRUSH_INCOMPATIBLE.send(player);
}
}
@Command(
name = "/listbrush",
desc = "List saved brushes",
descFooter = "List all brushes in the brush directory"
)
@CommandPermissions("worldedit.brush.list")
public void list(Actor actor, InjectedValueAccess args,
@ArgFlag(name = 'p', desc = "Prints the requested page", def = "0")
int page) throws WorldEditException {
String baseCmd = "/brush loadbrush";
File dir = MainUtil.getFile(Fawe.imp().getDirectory(), "brushes");
// TODO NOT IMPLEMENTED
// UtilityCommands.list(dir, actor, args, page, null, true, baseCmd);
}
@Command(
name = "none",
aliases = {"/none"},
desc = "Unbind a bound tool from your current item"
)
public void none(Player player, LocalSession session) throws WorldEditException {
session.setTool(player, null);
BBC.TOOL_NONE.send(player);
}
@Command(
name = "/",
aliases = {","},
desc = "Toggle the super pickaxe function"
)
@CommandPermissions("worldedit.superpickaxe")
public void togglePickaxe(Player player, LocalSession session,
@Arg(desc = "state", def = "on") String state) throws WorldEditException {
if (session.hasSuperPickAxe()) {
if ("on".equals(state)) {
BBC.SUPERPICKAXE_ENABLED.send(player);
return;
}
session.disableSuperPickAxe();
BBC.SUPERPICKAXE_DISABLED.send(player);
} else {
if ("off".equals(state)) {
BBC.SUPERPICKAXE_DISABLED.send(player);
return;
}
session.enableSuperPickAxe();
BBC.SUPERPICKAXE_ENABLED.send(player);
}
}
@Command(
name = "primary",
desc = "Set the right click brush",
descFooter = "Set the right click brush"
)
@CommandPermissions("worldedit.brush.primary")
public void primary(Player player, LocalSession session,
@Arg(desc = "The brush command", variable = true) List<String> commandStr) throws WorldEditException {
BaseItem item = player.getItemInHand(HandSide.MAIN_HAND);
BrushTool tool = session.getBrushTool(player, false);
session.setTool(item, null, player);
String cmd = "brush " + StringMan.join(commandStr, " ");
CommandEvent event = new CommandEvent(player, cmd);
PlatformCommandManager.getInstance().handleCommandOnCurrentThread(event);
BrushTool newTool = session.getBrushTool(item, player, false);
if (newTool != null && tool != null) {
newTool.setSecondary(tool.getSecondary());
}
}
@Command(
name = "secondary",
desc = "Set the left click brush",
descFooter = "Set the left click brush"
)
@CommandPermissions("worldedit.brush.secondary")
public void secondary(Player player, LocalSession session,
@Arg(desc = "The brush command", variable = true) List<String> commandStr)
throws WorldEditException {
BaseItem item = player.getItemInHand(HandSide.MAIN_HAND);
BrushTool tool = session.getBrushTool(player, false);
session.setTool(item, null, player);
String cmd = "brush " + StringMan.join(commandStr, " ");
CommandEvent event = new CommandEvent(player, cmd);
PlatformCommandManager.getInstance().handleCommandOnCurrentThread(event);
BrushTool newTool = session.getBrushTool(item, player, false);
if (newTool != null && tool != null) {
newTool.setPrimary(tool.getPrimary());
}
}
@Command(
name = "visualize",
aliases = {"visual", "vis"},
desc = "Toggle between different visualization modes",
descFooter = "Toggle between different visualization modes\n" +
"0 = No visualization\n" +
"1 = Single block at target position\n" +
"2 = Glass showing what blocks will be changed"
)
@CommandPermissions("worldedit.brush.visualize")
public void visual(Player player, LocalSession session, @Arg(name = "mode", desc = "int", def = "0") @Range(min = 0, max = 2) int mode)
throws WorldEditException {
BrushTool tool = session.getBrushTool(player, false);
if (tool == null) {
BBC.BRUSH_NONE.send(player);
return;
}
VisualMode[] modes = VisualMode.values();
VisualMode newMode = modes[MathMan.wrap(mode, 0, modes.length - 1)];
tool.setVisualMode(player, newMode);
BBC.BRUSH_VISUAL_MODE_SET.send(player, newMode);
}
@Command(
name = "target",
aliases = {"tar"},
desc = "Toggle between different target modes"
)
@CommandPermissions("worldedit.brush.target")
public void target(Player player, LocalSession session,
@Arg(name = "mode", desc = "int", def = "0") int mode) throws WorldEditException {
BrushTool tool = session.getBrushTool(player, false);
if (tool == null) {
BBC.BRUSH_NONE.send(player);
return;
}
TargetMode[] modes = TargetMode.values();
TargetMode newMode = modes[MathMan.wrap(mode, 0, modes.length - 1)];
tool.setTargetMode(newMode);
BBC.BRUSH_TARGET_MODE_SET.send(player, newMode);
}
@Command(
name = "targetmask",
aliases = {"tarmask", "tm"},
desc = "Set the targeting mask"
)
@CommandPermissions("worldedit.brush.targetmask")
public void targetMask(Player player, EditSession editSession, LocalSession session, @Arg(desc = "The destination mask", def = "") Mask maskOpt) throws WorldEditException {
BrushTool tool = session.getBrushTool(player, false);
if (tool == null) {
BBC.BRUSH_NONE.send(player);
return;
}
tool.setTraceMask(maskOpt);
BBC.BRUSH_TARGET_MASK_SET.send(player, maskOpt.toString());
}
@Command(
name = "targetoffset",
aliases = {"to"},
desc = "Set the targeting mask"
)
@CommandPermissions("worldedit.brush.targetoffset")
public void targetOffset(Player player, EditSession editSession, LocalSession session,
int offset) throws WorldEditException {
BrushTool tool = session.getBrushTool(player, false);
if (tool == null) {
BBC.BRUSH_NONE.send(player);
return;
}
tool.setTargetOffset(offset);
BBC.BRUSH_TARGET_OFFSET_SET.send(player, offset);
}
@Command(
name = "scroll",
desc = "Toggle between different target modes"
)
@CommandPermissions("worldedit.brush.scroll")
public void scroll(Player player, EditSession editSession, LocalSession session,
@Switch(name = 'h', desc = "TODO")
boolean offHand,
@Arg(desc = "Target Modes")
String modes,
@Arg(desc = "The scroll action", variable = true)
List<String> commandStr) throws WorldEditException {
// TODO NOT IMPLEMENTED Convert ScrollAction to an argument converter
BrushTool bt = session.getBrushTool(player, false);
if (bt == null) {
BBC.BRUSH_NONE.send(player);
return;
}
BrushSettings settings = offHand ? bt.getOffHand() : bt.getContext();
ScrollAction action = ScrollAction.fromArguments(bt, player, session, StringMan.join(commandStr, " "), true);
settings.setScrollAction(action);
if (modes.equalsIgnoreCase("none")) {
BBC.BRUSH_SCROLL_ACTION_UNSET.send(player);
} else if (action != null) {
settings.addSetting(BrushSettings.SettingType.SCROLL_ACTION, modes);
BBC.BRUSH_SCROLL_ACTION_SET.send(player, modes);
}
bt.update();
}
@Command(
name = "mask",
aliases = {"/mask"},
desc = "Set the brush destination mask"
)
@CommandPermissions({"worldedit.brush.options.mask", "worldedit.mask.brush"})
public void mask(Player player, LocalSession session, EditSession editSession,
@Switch(name = 'h', desc = "TODO")
boolean offHand,
@Arg(desc = "The destination mask", def = "")
Mask maskArg,
Arguments arguments)
throws WorldEditException {
BrushTool tool = session.getBrushTool(player, false);
if (tool == null) {
player.print(BBC.BRUSH_NONE.s());
return;
}
if (maskArg == null) {
BBC.BRUSH_MASK_DISABLED.send(player);
tool.setMask(null);
return;
}
BrushSettings settings = offHand ? tool.getOffHand() : tool.getContext();
String lastArg = Iterables.getLast(CommandArgParser.spaceSplit(arguments.get())).getSubstring();
System.out.println(lastArg + " TODO check this is not the whole command");
settings.addSetting(BrushSettings.SettingType.MASK, lastArg);
settings.setMask(maskArg);
tool.update();
BBC.BRUSH_MASK.send(player);
}
@Command(
name = "smask",
aliases = {"/smask", "/sourcemask", "sourcemask"},
desc = "Set the brush source mask",
descFooter = "Set the brush source mask"
)
@CommandPermissions({"worldedit.brush.options.mask", "worldedit.mask.brush"})
public void smask(Player player, LocalSession session, EditSession editSession,
@Arg(desc = "The destination mask", def = "")
Mask maskArg,
@Switch(name = 'h', desc = "TODO")
boolean offHand,
Arguments arguments) throws WorldEditException {
BrushTool tool = session.getBrushTool(player, false);
if (tool == null) {
player.print(BBC.BRUSH_NONE.s());
return;
}
if (maskArg == null) {
BBC.BRUSH_SOURCE_MASK_DISABLED.send(player);
tool.setSourceMask(null);
return;
}
BrushSettings settings = offHand ? tool.getOffHand() : tool.getContext();
String lastArg = Iterables.getLast(CommandArgParser.spaceSplit(arguments.get())).getSubstring();
settings.addSetting(BrushSettings.SettingType.SOURCE_MASK, lastArg);
settings.setSourceMask(maskArg);
tool.update();
BBC.BRUSH_SOURCE_MASK.send(player);
}
@Command(
name = "transform",
desc = "Set the brush transform"
)
@CommandPermissions({"worldedit.brush.options.transform", "worldedit.transform.brush"})
public void transform(Player player, LocalSession session, EditSession editSession,
@Arg(desc = "The transform", def = "") ResettableExtent transform,
@Switch(name = 'h', desc = "TODO")
boolean offHand,
Arguments arguments) throws WorldEditException {
BrushTool tool = session.getBrushTool(player, false);
if (tool == null) {
player.print(BBC.BRUSH_NONE.s());
return;
}
if (transform == null) {
BBC.BRUSH_TRANSFORM_DISABLED.send(player);
tool.setTransform(null);
return;
}
BrushSettings settings = offHand ? tool.getOffHand() : tool.getContext();
String lastArg = Iterables.getLast(CommandArgParser.spaceSplit(arguments.get())).getSubstring();
settings.addSetting(BrushSettings.SettingType.TRANSFORM, lastArg);
settings.setTransform(transform);
tool.update();
BBC.BRUSH_TRANSFORM.send(player);
}
@Command(
name = "mat",
aliases = {"material"},
desc = "Set the brush material"
)
@CommandPermissions("worldedit.brush.options.material")
public void material(Player player, EditSession editSession, LocalSession session,
@Arg(desc = "brush material pattern", def = "") Pattern patternOpt,
@Switch(name = 'h', desc = "TODO")
boolean offHand,
Arguments arguments) throws WorldEditException {
BrushTool tool = session.getBrushTool(player, false);
if (tool == null) {
player.print(BBC.BRUSH_NONE.s());
return;
}
if (patternOpt == null) {
BBC.BRUSH_MATERIAL.send(player);
tool.setFill(null);
return;
}
BrushSettings settings = offHand ? tool.getOffHand() : tool.getContext();
settings.setFill(patternOpt);
String lastArg = Iterables.getLast(CommandArgParser.spaceSplit(arguments.get())).getSubstring();
settings.addSetting(BrushSettings.SettingType.FILL, lastArg);
tool.update();
BBC.BRUSH_MATERIAL.send(player);
}
@Command(
name = "range",
desc = "Set the brush range"
)
@CommandPermissions("worldedit.brush.options.range")
public void range(Player player, LocalSession session,
@Arg(desc = "Range")
int range) throws WorldEditException {
range = Math.max(0, Math.min(256, range));
BrushTool tool = session.getBrushTool(player, false);
if (tool == null) {
player.print(BBC.BRUSH_NONE.s());
return;
}
tool.setRange(range);
BBC.BRUSH_RANGE.send(player);
}
@Command(
name = "size",
desc = "Set the brush size"
)
@CommandPermissions("worldedit.brush.options.size")
public void size(Player player, LocalSession session,
@Arg(desc = "The size of the brush", def = "5")
int radius,
@Switch(name = 'h', desc = "TODO")
boolean offHand) throws WorldEditException {
worldEdit.checkMaxBrushRadius(radius);
BrushTool tool = session.getBrushTool(player, false);
if (tool == null) {
player.print(BBC.BRUSH_NONE.s());
return;
}
BrushSettings settings = offHand ? tool.getOffHand() : tool.getContext();
settings.setSize(radius);
tool.update();
BBC.BRUSH_SIZE.send(player);
}
}

View File

@ -1,448 +1,448 @@
//package com.sk89q.worldedit.command; package com.sk89q.worldedit.command;
//
//import com.boydti.fawe.object.mask.AdjacentAnyMask; import com.boydti.fawe.object.mask.AdjacentAnyMask;
//import com.boydti.fawe.object.mask.AdjacentMask; import com.boydti.fawe.object.mask.AdjacentMask;
//import com.boydti.fawe.object.mask.AngleMask; import com.boydti.fawe.object.mask.AngleMask;
//import com.boydti.fawe.object.mask.BiomeMask; import com.boydti.fawe.object.mask.BiomeMask;
//import com.boydti.fawe.object.mask.BlockLightMask; import com.boydti.fawe.object.mask.BlockLightMask;
//import com.boydti.fawe.object.mask.BrightnessMask; import com.boydti.fawe.object.mask.BrightnessMask;
//import com.boydti.fawe.object.mask.DataMask; import com.boydti.fawe.object.mask.DataMask;
//import com.boydti.fawe.object.mask.ExtremaMask; import com.boydti.fawe.object.mask.ExtremaMask;
//import com.boydti.fawe.object.mask.IdDataMask; import com.boydti.fawe.object.mask.IdDataMask;
//import com.boydti.fawe.object.mask.IdMask; import com.boydti.fawe.object.mask.IdMask;
//import com.boydti.fawe.object.mask.LightMask; import com.boydti.fawe.object.mask.LightMask;
//import com.boydti.fawe.object.mask.OpacityMask; import com.boydti.fawe.object.mask.OpacityMask;
//import com.boydti.fawe.object.mask.ROCAngleMask; import com.boydti.fawe.object.mask.ROCAngleMask;
//import com.boydti.fawe.object.mask.RadiusMask; import com.boydti.fawe.object.mask.RadiusMask;
//import com.boydti.fawe.object.mask.RandomMask; import com.boydti.fawe.object.mask.RandomMask;
//import com.boydti.fawe.object.mask.SimplexMask; import com.boydti.fawe.object.mask.SimplexMask;
//import com.boydti.fawe.object.mask.SkyLightMask; import com.boydti.fawe.object.mask.SkyLightMask;
//import com.boydti.fawe.object.mask.SurfaceMask; import com.boydti.fawe.object.mask.SurfaceMask;
//import com.boydti.fawe.object.mask.WallMask; import com.boydti.fawe.object.mask.WallMask;
//import com.boydti.fawe.object.mask.XAxisMask; import com.boydti.fawe.object.mask.XAxisMask;
//import com.boydti.fawe.object.mask.YAxisMask; import com.boydti.fawe.object.mask.YAxisMask;
//import com.boydti.fawe.object.mask.ZAxisMask; import com.boydti.fawe.object.mask.ZAxisMask;
//import com.sk89q.worldedit.IncompleteRegionException; import com.sk89q.worldedit.IncompleteRegionException;
//import com.sk89q.worldedit.LocalSession; import com.sk89q.worldedit.LocalSession;
//import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.WorldEdit;
//import com.sk89q.worldedit.command.util.CommandPermissionsConditionGenerator; import com.sk89q.worldedit.command.util.CommandPermissionsConditionGenerator;
//import com.sk89q.worldedit.entity.Player; import com.sk89q.worldedit.entity.Player;
//import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.extent.Extent;
//import com.sk89q.worldedit.function.mask.BlockMaskBuilder; import com.sk89q.worldedit.function.mask.BlockMaskBuilder;
//import com.sk89q.worldedit.function.mask.ExistingBlockMask; import com.sk89q.worldedit.function.mask.ExistingBlockMask;
//import com.sk89q.worldedit.function.mask.ExpressionMask; import com.sk89q.worldedit.function.mask.ExpressionMask;
//import com.sk89q.worldedit.function.mask.Mask; import com.sk89q.worldedit.function.mask.Mask;
//import com.sk89q.worldedit.function.mask.MaskIntersection; import com.sk89q.worldedit.function.mask.MaskIntersection;
//import com.sk89q.worldedit.function.mask.MaskUnion; import com.sk89q.worldedit.function.mask.MaskUnion;
//import com.sk89q.worldedit.function.mask.Masks; import com.sk89q.worldedit.function.mask.Masks;
//import com.sk89q.worldedit.function.mask.OffsetMask; import com.sk89q.worldedit.function.mask.OffsetMask;
//import com.sk89q.worldedit.function.mask.RegionMask; import com.sk89q.worldedit.function.mask.RegionMask;
//import com.sk89q.worldedit.function.mask.SolidBlockMask; import com.sk89q.worldedit.function.mask.SolidBlockMask;
//import com.sk89q.worldedit.internal.expression.Expression; import com.sk89q.worldedit.internal.expression.Expression;
//import com.sk89q.worldedit.internal.expression.ExpressionException; import com.sk89q.worldedit.internal.expression.ExpressionException;
//import com.sk89q.worldedit.internal.expression.runtime.ExpressionEnvironment; import com.sk89q.worldedit.internal.expression.runtime.ExpressionEnvironment;
//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.shape.WorldEditExpressionEnvironment; import com.sk89q.worldedit.regions.shape.WorldEditExpressionEnvironment;
//import com.sk89q.worldedit.session.request.RequestSelection; import com.sk89q.worldedit.session.request.RequestSelection;
//import com.sk89q.worldedit.world.biome.BiomeType; import com.sk89q.worldedit.world.biome.BiomeType;
//import org.enginehub.piston.annotation.Command; import org.enginehub.piston.annotation.Command;
//import org.enginehub.piston.annotation.CommandContainer; import org.enginehub.piston.annotation.CommandContainer;
//import org.enginehub.piston.annotation.param.Arg; import org.enginehub.piston.annotation.param.Arg;
//import org.enginehub.piston.annotation.param.Switch; import org.enginehub.piston.annotation.param.Switch;
//
////@Command(aliases = {"masks"}, //@Command(aliases = {"masks"},
//// desc = "Help for the various masks. [More Info](https://git.io/v9r4K)", // desc = "Help for the various masks. [More Info](https://git.io/v9r4K)",
//// descFooter = "Masks determine if a block can be placed\n" + // descFooter = "Masks determine if a block can be placed\n" +
//// " - Use [brackets] for arguments\n" + // " - Use [brackets] for arguments\n" +
//// " - Use , to OR multiple\n" + // " - Use , to OR multiple\n" +
//// " - Use & to AND multiple\n" + // " - Use & to AND multiple\n" +
//// "e.g. >[stone,dirt],#light[0][5],$jungle\n" + // "e.g. >[stone,dirt],#light[0][5],$jungle\n" +
//// "More Info: https://git.io/v9r4K" // "More Info: https://git.io/v9r4K"
////)
//@CommandContainer//(superTypes = CommandPermissionsConditionGenerator.Registration.class)
//public class MaskCommands {
// private final WorldEdit worldEdit;
//
// public MaskCommands(WorldEdit worldEdit) {
// this.worldEdit = worldEdit;
// }
//
// @Command(
// name = "#simplex",
// desc = "Use simplex noise as the mask"
// )
// public Mask simplex(double scale, @Arg(name="mine", desc = "min light") double minInt, @Arg(name="mine", desc = "max light") double maxInt) {
// scale = 1d / Math.max(1, scale);
// minInt = (minInt - 50) / 50;
// maxInt = (maxInt - 50) / 50;
// return new SimplexMask(scale, minInt, maxInt);
// }
//
// @Command(
// name = "#light",
// desc = "Restrict to specific light levels"
// )
// public Mask light(Extent extent, @Arg(name="mine", desc = "min light") double minInt, @Arg(name="mine", desc = "max light") double maxInt) {
// return new LightMask(extent, (int) minInt, (int) maxInt);
// }
//
// @Command(
// name = "#false",
// desc = "Always false"
// )
// public Mask falseMask(Extent extent) {
// return Masks.alwaysFalse();
// }
//
// @Command(
// name = "#true",
// desc = "Always true"
// )
// public Mask trueMask(Extent extent) {
// return Masks.alwaysTrue();
// }
//
// @Command(
// name = "#skylight",
// desc = "Restrict to specific sky light levels"
// )
// public Mask skylight(Extent extent, @Arg(name="mine", desc = "min light") double minInt, @Arg(name="mine", desc = "max light") double maxInt) {
// return new SkyLightMask(extent, (int) minInt, (int) maxInt);
// }
//
// @Command(
// name = "#blocklight",
// aliases = {"#emittedlight"},
// desc = "Restrict to specific block light levels"
// )
// public Mask blocklight(Extent extent, @Arg(name="mine", desc = "min light") double minInt, @Arg(name="mine", desc = "max light") double maxInt) {
// return new BlockLightMask(extent, (int) minInt, (int) maxInt);
// }
//
// @Command(
// name = "#opacity",
// desc = "Restrict to specific opacity levels"
// )
// public Mask opacity(Extent extent, @Arg(name="mine", desc = "min light") double minInt, @Arg(name="mine", desc = "max light") double maxInt) {
// return new OpacityMask(extent, (int) minInt, (int) maxInt);
// }
//
// @Command(
// name = "#brightness",
// desc = "Restrict to specific block brightness"
// )
// public Mask brightness(Extent extent, @Arg(name="mine", desc = "min light") double minInt, @Arg(name="mine", desc = "max light") double maxInt) {
// return new BrightnessMask(extent, (int) minInt, (int) maxInt);
// }
//
// @Command(
// name = "#offset",
// desc = "Offset a mask"
// )
// public Mask offset(double x, double y, double z, Mask mask) {
// return new OffsetMask(mask, BlockVector3.at(x, y, z));
// }
//
// @Command(
// name = "#haslight",
// desc = "Restricts to blocks with light (sky or emitted)"
// )
// public Mask haslight(Extent extent) {
// return new LightMask(extent, 1, Integer.MAX_VALUE);
// }
//
// @Command(
// name = "#nolight",
// desc = "Restrict to blocks without light (sky or emitted)"
// )
// public Mask nolight(Extent extent) {
// return new LightMask(extent, 0, 0);
// }
//
// @Command(
// name = "#existing",
// desc = "If there is a non air block"
// )
// public Mask existing(Extent extent) {
// return new ExistingBlockMask(extent);
// }
//
// @Command(
// name = "#solid",
// desc = "If there is a solid block"
// )
// public Mask solid(Extent extent) {
// return new SolidBlockMask(extent);
// }
//
// @Command(
// name = "#liquid",
// desc = "If there is a solid block"
// )
// public Mask liquid(Extent extent) {
// return new BlockMaskBuilder().addAll(b -> b.getMaterial().isLiquid()).build(extent);
// }
//
// @Command(
// name = "#dregion",
// aliases = {"#dselection", "#dsel"},
// desc = "inside the player's selection"
// )
// public Mask dregion() {
// return new RegionMask(new RequestSelection());
// }
//
// @Command(
// name = "#region",
// aliases = {"#selection", "#sel"},
// desc = "inside the provided selection"
// )
// public Mask selection(Player player, LocalSession session) throws IncompleteRegionException {
// return new RegionMask(session.getSelection(player.getWorld()).clone());
// }
//
// @Command(
// name = "#xaxis",
// desc = "Restrict to initial x axis"
// )
// public Mask xaxis() {
// return new XAxisMask();
// }
//
// @Command(
// name = "#yaxis",
// desc = "Restrict to initial y axis"
// )
// public Mask yaxis() {
// return new YAxisMask();
// }
//
// @Command(
// name = "#zaxis",
// desc = "Restrict to initial z axis"
// )
// public Mask zaxis() {
// return new ZAxisMask();
// }
//
// @Command(
// name = "#id",
// desc = "Restrict to initial id"
// )
// public Mask id(Extent extent) {
// return new IdMask(extent);
// }
//
// @Command(
// name = "#data",
// desc = "Restrict to initial data"
// )
// public Mask data(Extent extent) {
// return new DataMask(extent);
// }
//
// @Command(
// name = "#iddata",
// desc = "Restrict to initial block id and data"
// )
// public Mask iddata(Extent extent) {
// return new IdDataMask(extent);
// }
//
// @Command(
// name = "#air",
// desc = "Restrict to types of air"
// )
// public Mask air(Extent extent) {
// return new BlockMaskBuilder().addAll(b -> b.getMaterial().isAir()).build(extent);
// }
//
// @Command(
// name = "#wall",
// desc = "Restrict to walls (any block n,e,s,w of air)"
// )
// public Mask wall(Extent extent) {
// Mask blockMask = air(extent);
// return new MaskUnion(new ExistingBlockMask(extent), new WallMask(blockMask, 1, 8));
// }
//
// @Command(
// name = "#surface",
// desc = "Restrict to surfaces (any solid block touching air)"
// )
// public Mask surface(Extent extent) {
// return new SurfaceMask(extent);
// }
//
// @Command(
// name = "\\",
// aliases = {"/", "#angle", "#\\", "#/"},
// desc = "Restrict to specific terrain angle",
// descFooter = "Restrict to specific terrain angle\n" +
// "The -o flag will only overlay\n" +
// "Example: /[0d][45d]\n" +
// "Explanation: Allows any block where the adjacent block is between 0 and 45 degrees.\n" +
// "Example: /[3][20]\n" +
// "Explanation: Allows any block where the adjacent block is between 3 and 20 blocks below"
//) //)
// public Mask angle(Extent extent, @Arg(name="min", desc = "min angle") String minStr, @Arg(name="max", desc = "max angle") String maxStr, @Switch(name = 'o', desc = "TODO") boolean overlay, @Arg(name = "distance", desc = "int", def = "1") int distanceOpt) throws ExpressionException { @CommandContainer//(superTypes = CommandPermissionsConditionGenerator.Registration.class)
// double y1, y2; public class MaskCommands {
// boolean override; private final WorldEdit worldEdit;
// if (maxStr.endsWith("d")) {
// double y1d = Expression.compile(minStr.substring(0, minStr.length() - 1)).evaluate(); public MaskCommands(WorldEdit worldEdit) {
// double y2d = Expression.compile(maxStr.substring(0, maxStr.length() - 1)).evaluate(); this.worldEdit = worldEdit;
// y1 = Math.tan(y1d * (Math.PI / 180)); }
// y2 = Math.tan(y2d * (Math.PI / 180));
// } else { @Command(
// y1 = Expression.compile(minStr).evaluate(); name = "#simplex",
// y2 = Expression.compile(maxStr).evaluate(); desc = "Use simplex noise as the mask"
// } )
// return new AngleMask(extent, y1, y2, overlay, distanceOpt); public Mask simplex(double scale, @Arg(name="mine", desc = "min light") double minInt, @Arg(name="mine", desc = "max light") double maxInt) {
// } scale = 1d / Math.max(1, scale);
// minInt = (minInt - 50) / 50;
// @Command( maxInt = (maxInt - 50) / 50;
// name = "(", return new SimplexMask(scale, minInt, maxInt);
// aliases = {")", "#roc", "#(", "#)"}, }
// desc = "Restrict to near specific terrain slope rate of change",
// descFooter = "Restrict to near specific terrain slope rate of change\n" + @Command(
// "The -o flag will only overlay\n" + name = "#light",
// "Example: ([0d][45d][5]\n" + desc = "Restrict to specific light levels"
// "Explanation: Restrict near where the angle changes between 0-45 degrees within 5 blocks\n" + )
// "Note: Use negatives for decreasing slope" public Mask light(Extent extent, @Arg(name="mine", desc = "min light") double minInt, @Arg(name="mine", desc = "max light") double maxInt) {
//) return new LightMask(extent, (int) minInt, (int) maxInt);
// public Mask roc(Extent extent, @Arg(name="min", desc = "min angle") String minStr, @Arg(name="max", desc = "max angle") String maxStr, @Switch(name = 'o', desc = "TODO") boolean overlay, @Arg(name = "distance", desc = "int", def = "4") int distanceOpt) throws ExpressionException { }
// double y1, y2;
// boolean override; @Command(
// if (maxStr.endsWith("d")) { name = "#false",
// double y1d = Expression.compile(minStr.substring(0, minStr.length() - 1)).evaluate(); desc = "Always false"
// double y2d = Expression.compile(maxStr.substring(0, maxStr.length() - 1)).evaluate(); )
// y1 = Math.tan(y1d * (Math.PI / 180)); public Mask falseMask(Extent extent) {
// y2 = Math.tan(y2d * (Math.PI / 180)); return Masks.alwaysFalse();
// } else { }
// y1 = Expression.compile(minStr).evaluate();
// y2 = Expression.compile(maxStr).evaluate(); @Command(
// } name = "#true",
// return new ROCAngleMask(extent, y1, y2, overlay, distanceOpt); desc = "Always true"
// } )
// public Mask trueMask(Extent extent) {
// @Command( return Masks.alwaysTrue();
// name = "^", }
// aliases = {"#extrema", "#^"},
// desc = "Restrict to near specific terrain extrema", @Command(
// descFooter = "Restrict to near specific terrain extrema\n" + name = "#skylight",
// "The -o flag will only overlay\n" + desc = "Restrict to specific sky light levels"
// "Example: ([0d][45d][5]\n" + )
// "Explanation: Restrict to near 45 degrees of local maxima\n" + public Mask skylight(Extent extent, @Arg(name="mine", desc = "min light") double minInt, @Arg(name="mine", desc = "max light") double maxInt) {
// "Note: Use negatives for local minima" return new SkyLightMask(extent, (int) minInt, (int) maxInt);
//) }
// public Mask extrema(Extent extent, @Arg(name="min", desc = "min angle") String minStr, @Arg(name="max", desc = "max angle") String maxStr, @Switch(name = 'o', desc = "TODO") boolean overlay, @Arg(name = "distance", desc = "int", def = "4") int distanceOpt) throws ExpressionException {
// double y1, y2; @Command(
// boolean override; name = "#blocklight",
// if (maxStr.endsWith("d")) { aliases = {"#emittedlight"},
// double y1d = Expression.compile(minStr.substring(0, minStr.length() - 1)).evaluate(); desc = "Restrict to specific block light levels"
// double y2d = Expression.compile(maxStr.substring(0, maxStr.length() - 1)).evaluate(); )
// y1 = Math.tan(y1d * (Math.PI / 180)); public Mask blocklight(Extent extent, @Arg(name="mine", desc = "min light") double minInt, @Arg(name="mine", desc = "max light") double maxInt) {
// y2 = Math.tan(y2d * (Math.PI / 180)); return new BlockLightMask(extent, (int) minInt, (int) maxInt);
// } else { }
// y1 = Expression.compile(minStr).evaluate();
// y2 = Expression.compile(maxStr).evaluate(); @Command(
// } name = "#opacity",
// return new ExtremaMask(extent, y1, y2, overlay, distanceOpt); desc = "Restrict to specific opacity levels"
// } )
// public Mask opacity(Extent extent, @Arg(name="mine", desc = "min light") double minInt, @Arg(name="mine", desc = "max light") double maxInt) {
// @Command( return new OpacityMask(extent, (int) minInt, (int) maxInt);
// name = "{", }
// aliases = {"#{"},
// desc = "Restricts blocks to within a specific radius range of the initial block" @Command(
//) name = "#brightness",
// public Mask radius(@Arg(name="mine", desc = "min light") double minInt, @Arg(name="mine", desc = "max light") double maxInt) throws ExpressionException { desc = "Restrict to specific block brightness"
// return new RadiusMask((int) minInt, (int) maxInt); )
// } public Mask brightness(Extent extent, @Arg(name="mine", desc = "min light") double minInt, @Arg(name="mine", desc = "max light") double maxInt) {
// return new BrightnessMask(extent, (int) minInt, (int) maxInt);
// @Command( }
// name = "|",
// aliases = {"#|", "#side"}, @Command(
// desc = "sides with a specific number of other blocks" name = "#offset",
//) desc = "Offset a mask"
// public Mask wall(Mask mask, @Arg(name="mine", desc = "min light") double minInt, @Arg(name="mine", desc = "max light") double maxInt) throws ExpressionException { )
// return new WallMask(mask, (int) minInt, (int) maxInt); public Mask offset(double x, double y, double z, Mask mask) {
// } return new OffsetMask(mask, BlockVector3.at(x, y, z));
// }
// @Command(
// name = "~", @Command(
// aliases = {"#~", "#adjacent"}, name = "#haslight",
// desc = "Adjacent to a specific number of other blocks" desc = "Restricts to blocks with light (sky or emitted)"
//) )
// public Mask adjacent(Mask mask, @Arg(name = "min", desc = "double", def = "-1") double min, @Arg(name = "max", desc = "double", def = "-1") double max) throws ExpressionException { public Mask haslight(Extent extent) {
// if (min == -1 && max == -1) { return new LightMask(extent, 1, Integer.MAX_VALUE);
// min = 1; }
// max = 8;
// } else if (max == -1) max = min; @Command(
// if (max >= 8 && min == 1) { name = "#nolight",
// return new AdjacentAnyMask(mask); desc = "Restrict to blocks without light (sky or emitted)"
// } )
// return new AdjacentMask(mask, (int) min, (int) max); public Mask nolight(Extent extent) {
// } return new LightMask(extent, 0, 0);
// }
// @Command(
// name = "<", @Command(
// aliases = {"#<", "#below"}, name = "#existing",
// desc = "below a specific block" desc = "If there is a non air block"
//) )
// public Mask below(Mask mask) throws ExpressionException { public Mask existing(Extent extent) {
// OffsetMask offsetMask = new OffsetMask(mask, BlockVector3.at(0, 1, 0)); return new ExistingBlockMask(extent);
// return new MaskIntersection(offsetMask, Masks.negate(mask)); }
// }
// @Command(
// @Command( name = "#solid",
// name = ">", desc = "If there is a solid block"
// aliases = {"#>", "#above"}, )
// desc = "above a specific block" public Mask solid(Extent extent) {
//) return new SolidBlockMask(extent);
// public Mask above(Mask mask) throws ExpressionException { }
// OffsetMask offsetMask = new OffsetMask(mask, BlockVector3.at(0, -1, 0));
// return new MaskIntersection(offsetMask, Masks.negate(mask)); @Command(
// } name = "#liquid",
// desc = "If there is a solid block"
// @Command( )
// name = "$", public Mask liquid(Extent extent) {
// aliases = {"#biome", "#$"}, return new BlockMaskBuilder().addAll(b -> b.getMaterial().isLiquid()).build(extent);
// desc = "in a specific biome", }
// descFooter = "in a specific biome. For a list of biomes use //biomelist"
//) @Command(
// public Mask biome(Extent extent, BiomeType biome) throws ExpressionException { name = "#dregion",
// return new BiomeMask(extent, biome); aliases = {"#dselection", "#dsel"},
// } desc = "inside the player's selection"
// )
// @Command( public Mask dregion() {
// name = "%", return new RegionMask(new RequestSelection());
// aliases = {"#%", "#percent"}, }
// desc = "percentage chance"
//) @Command(
// public Mask random(double chance) throws ExpressionException { name = "#region",
// chance = chance / 100; aliases = {"#selection", "#sel"},
// return new RandomMask(chance); desc = "inside the provided selection"
// } )
// public Mask selection(Player player, LocalSession session) throws IncompleteRegionException {
// @Command( return new RegionMask(session.getSelection(player.getWorld()).clone());
// name = "=", }
// aliases = {"#=", "#expression"},
// desc = "expression mask" @Command(
//) name = "#xaxis",
// public Mask expression(Extent extent, String input) throws ExpressionException { desc = "Restrict to initial x axis"
// Expression exp = Expression.compile(input, "x", "y", "z"); )
// ExpressionEnvironment env = new WorldEditExpressionEnvironment(extent, Vector3.ONE, Vector3.ZERO); public Mask xaxis() {
// exp.setEnvironment(env); return new XAxisMask();
// return new ExpressionMask(exp); }
// }
// @Command(
// @Command( name = "#yaxis",
// name = "!", desc = "Restrict to initial y axis"
// aliases = {"#not", "#negate", "#!"}, )
// desc = "Negate another mask" public Mask yaxis() {
//) return new YAxisMask();
// public Mask expression(Mask mask) throws ExpressionException { }
// return Masks.negate(mask);
// } @Command(
//} name = "#zaxis",
desc = "Restrict to initial z axis"
)
public Mask zaxis() {
return new ZAxisMask();
}
@Command(
name = "#id",
desc = "Restrict to initial id"
)
public Mask id(Extent extent) {
return new IdMask(extent);
}
@Command(
name = "#data",
desc = "Restrict to initial data"
)
public Mask data(Extent extent) {
return new DataMask(extent);
}
@Command(
name = "#iddata",
desc = "Restrict to initial block id and data"
)
public Mask iddata(Extent extent) {
return new IdDataMask(extent);
}
@Command(
name = "#air",
desc = "Restrict to types of air"
)
public Mask air(Extent extent) {
return new BlockMaskBuilder().addAll(b -> b.getMaterial().isAir()).build(extent);
}
@Command(
name = "#wall",
desc = "Restrict to walls (any block n,e,s,w of air)"
)
public Mask wall(Extent extent) {
Mask blockMask = air(extent);
return new MaskUnion(new ExistingBlockMask(extent), new WallMask(blockMask, 1, 8));
}
@Command(
name = "#surface",
desc = "Restrict to surfaces (any solid block touching air)"
)
public Mask surface(Extent extent) {
return new SurfaceMask(extent);
}
@Command(
name = "\\",
aliases = {"/", "#angle", "#\\", "#/"},
desc = "Restrict to specific terrain angle",
descFooter = "Restrict to specific terrain angle\n" +
"The -o flag will only overlay\n" +
"Example: /[0d][45d]\n" +
"Explanation: Allows any block where the adjacent block is between 0 and 45 degrees.\n" +
"Example: /[3][20]\n" +
"Explanation: Allows any block where the adjacent block is between 3 and 20 blocks below"
)
public Mask angle(Extent extent, @Arg(name="min", desc = "min angle") String minStr, @Arg(name="max", desc = "max angle") String maxStr, @Switch(name = 'o', desc = "TODO") boolean overlay, @Arg(name = "distance", desc = "int", def = "1") int distanceOpt) throws ExpressionException {
double y1, y2;
boolean override;
if (maxStr.endsWith("d")) {
double y1d = Expression.compile(minStr.substring(0, minStr.length() - 1)).evaluate();
double y2d = Expression.compile(maxStr.substring(0, maxStr.length() - 1)).evaluate();
y1 = Math.tan(y1d * (Math.PI / 180));
y2 = Math.tan(y2d * (Math.PI / 180));
} else {
y1 = Expression.compile(minStr).evaluate();
y2 = Expression.compile(maxStr).evaluate();
}
return new AngleMask(extent, y1, y2, overlay, distanceOpt);
}
@Command(
name = "(",
aliases = {")", "#roc", "#(", "#)"},
desc = "Restrict to near specific terrain slope rate of change",
descFooter = "Restrict to near specific terrain slope rate of change\n" +
"The -o flag will only overlay\n" +
"Example: ([0d][45d][5]\n" +
"Explanation: Restrict near where the angle changes between 0-45 degrees within 5 blocks\n" +
"Note: Use negatives for decreasing slope"
)
public Mask roc(Extent extent, @Arg(name="min", desc = "min angle") String minStr, @Arg(name="max", desc = "max angle") String maxStr, @Switch(name = 'o', desc = "TODO") boolean overlay, @Arg(name = "distance", desc = "int", def = "4") int distanceOpt) throws ExpressionException {
double y1, y2;
boolean override;
if (maxStr.endsWith("d")) {
double y1d = Expression.compile(minStr.substring(0, minStr.length() - 1)).evaluate();
double y2d = Expression.compile(maxStr.substring(0, maxStr.length() - 1)).evaluate();
y1 = Math.tan(y1d * (Math.PI / 180));
y2 = Math.tan(y2d * (Math.PI / 180));
} else {
y1 = Expression.compile(minStr).evaluate();
y2 = Expression.compile(maxStr).evaluate();
}
return new ROCAngleMask(extent, y1, y2, overlay, distanceOpt);
}
@Command(
name = "^",
aliases = {"#extrema", "#^"},
desc = "Restrict to near specific terrain extrema",
descFooter = "Restrict to near specific terrain extrema\n" +
"The -o flag will only overlay\n" +
"Example: ([0d][45d][5]\n" +
"Explanation: Restrict to near 45 degrees of local maxima\n" +
"Note: Use negatives for local minima"
)
public Mask extrema(Extent extent, @Arg(name="min", desc = "min angle") String minStr, @Arg(name="max", desc = "max angle") String maxStr, @Switch(name = 'o', desc = "TODO") boolean overlay, @Arg(name = "distance", desc = "int", def = "4") int distanceOpt) throws ExpressionException {
double y1, y2;
boolean override;
if (maxStr.endsWith("d")) {
double y1d = Expression.compile(minStr.substring(0, minStr.length() - 1)).evaluate();
double y2d = Expression.compile(maxStr.substring(0, maxStr.length() - 1)).evaluate();
y1 = Math.tan(y1d * (Math.PI / 180));
y2 = Math.tan(y2d * (Math.PI / 180));
} else {
y1 = Expression.compile(minStr).evaluate();
y2 = Expression.compile(maxStr).evaluate();
}
return new ExtremaMask(extent, y1, y2, overlay, distanceOpt);
}
@Command(
name = "{",
aliases = {"#{"},
desc = "Restricts blocks to within a specific radius range of the initial block"
)
public Mask radius(@Arg(name="mine", desc = "min light") double minInt, @Arg(name="mine", desc = "max light") double maxInt) throws ExpressionException {
return new RadiusMask((int) minInt, (int) maxInt);
}
@Command(
name = "|",
aliases = {"#|", "#side"},
desc = "sides with a specific number of other blocks"
)
public Mask wall(Mask mask, @Arg(name="mine", desc = "min light") double minInt, @Arg(name="mine", desc = "max light") double maxInt) throws ExpressionException {
return new WallMask(mask, (int) minInt, (int) maxInt);
}
@Command(
name = "~",
aliases = {"#~", "#adjacent"},
desc = "Adjacent to a specific number of other blocks"
)
public Mask adjacent(Mask mask, @Arg(name = "min", desc = "double", def = "-1") double min, @Arg(name = "max", desc = "double", def = "-1") double max) throws ExpressionException {
if (min == -1 && max == -1) {
min = 1;
max = 8;
} else if (max == -1) max = min;
if (max >= 8 && min == 1) {
return new AdjacentAnyMask(mask);
}
return new AdjacentMask(mask, (int) min, (int) max);
}
@Command(
name = "<",
aliases = {"#<", "#below"},
desc = "below a specific block"
)
public Mask below(Mask mask) throws ExpressionException {
OffsetMask offsetMask = new OffsetMask(mask, BlockVector3.at(0, 1, 0));
return new MaskIntersection(offsetMask, Masks.negate(mask));
}
@Command(
name = ">",
aliases = {"#>", "#above"},
desc = "above a specific block"
)
public Mask above(Mask mask) throws ExpressionException {
OffsetMask offsetMask = new OffsetMask(mask, BlockVector3.at(0, -1, 0));
return new MaskIntersection(offsetMask, Masks.negate(mask));
}
@Command(
name = "$",
aliases = {"#biome", "#$"},
desc = "in a specific biome",
descFooter = "in a specific biome. For a list of biomes use //biomelist"
)
public Mask biome(Extent extent, BiomeType biome) throws ExpressionException {
return new BiomeMask(extent, biome);
}
@Command(
name = "%",
aliases = {"#%", "#percent"},
desc = "percentage chance"
)
public Mask random(double chance) throws ExpressionException {
chance = chance / 100;
return new RandomMask(chance);
}
@Command(
name = "=",
aliases = {"#=", "#expression"},
desc = "expression mask"
)
public Mask expression(Extent extent, String input) throws ExpressionException {
Expression exp = Expression.compile(input, "x", "y", "z");
ExpressionEnvironment env = new WorldEditExpressionEnvironment(extent, Vector3.ONE, Vector3.ZERO);
exp.setEnvironment(env);
return new ExpressionMask(exp);
}
@Command(
name = "!",
aliases = {"#not", "#negate", "#!"},
desc = "Negate another mask"
)
public Mask expression(Mask mask) throws ExpressionException {
return Masks.negate(mask);
}
}

View File

@ -77,6 +77,28 @@ public class PaintBrushCommands {
.ofTypes(ImmutableList.of(Key.of(double.class))) .ofTypes(ImmutableList.of(Key.of(double.class)))
.build(); .build();
public static void register(CommandManagerService service, CommandManager commandManager, CommandRegistrationHandler registration) {
commandManager.register("paint", builder -> {
builder.description(TextComponent.of("Paint brush, apply a function to a surface"));
builder.action(org.enginehub.piston.Command.Action.NULL_ACTION);
CommandManager manager = service.newCommandManager();
registration.register(
manager,
PaintBrushCommandsRegistration.builder(),
new PaintBrushCommands()
);
builder.condition(new PermissionCondition(ImmutableSet.of("worldedit.brush.paint")));
builder.addParts(REGION_FACTORY, RADIUS, DENSITY);
builder.addPart(SubCommandPart.builder(TranslatableComponent.of("type"), TextComponent.of("Type of brush to use"))
.withCommands(manager.getAllCommands().collect(Collectors.toList()))
.required()
.build());
});
}
private void setPaintBrush(CommandParameters parameters, Player player, LocalSession localSession, private void setPaintBrush(CommandParameters parameters, Player player, LocalSession localSession,
Contextual<? extends RegionFunction> generatorFactory) throws WorldEditException { Contextual<? extends RegionFunction> generatorFactory) throws WorldEditException {
double radius = requireNonNull(RADIUS.value(parameters).asSingle(double.class)); double radius = requireNonNull(RADIUS.value(parameters).asSingle(double.class));

View File

@ -20,14 +20,26 @@
package com.sk89q.worldedit.command; package com.sk89q.worldedit.command;
import com.boydti.fawe.config.BBC; import com.boydti.fawe.config.BBC;
import com.boydti.fawe.object.brush.BrushSettings;
import com.boydti.fawe.object.brush.InspectBrush; import com.boydti.fawe.object.brush.InspectBrush;
import com.boydti.fawe.object.brush.TargetMode;
import com.boydti.fawe.object.brush.scroll.ScrollAction;
import com.boydti.fawe.object.brush.visualization.VisualMode;
import com.boydti.fawe.object.extent.ResettableExtent;
import com.boydti.fawe.util.MathMan;
import com.boydti.fawe.util.StringMan;
import com.google.common.collect.Iterables;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.LocalConfiguration; import com.sk89q.worldedit.LocalConfiguration;
import com.sk89q.worldedit.LocalSession; import com.sk89q.worldedit.LocalSession;
import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.blocks.BaseItem;
import com.sk89q.worldedit.blocks.BaseItemStack; import com.sk89q.worldedit.blocks.BaseItemStack;
import com.sk89q.worldedit.command.argument.Arguments;
import com.sk89q.worldedit.command.tool.BlockDataCyler; import com.sk89q.worldedit.command.tool.BlockDataCyler;
import com.sk89q.worldedit.command.tool.BlockReplacer; import com.sk89q.worldedit.command.tool.BlockReplacer;
import com.sk89q.worldedit.command.tool.BrushTool;
import com.sk89q.worldedit.command.tool.DistanceWand; import com.sk89q.worldedit.command.tool.DistanceWand;
import com.sk89q.worldedit.command.tool.FloatingTreeRemover; import com.sk89q.worldedit.command.tool.FloatingTreeRemover;
import com.sk89q.worldedit.command.tool.FloodFillTool; import com.sk89q.worldedit.command.tool.FloodFillTool;
@ -39,7 +51,12 @@ import com.sk89q.worldedit.command.tool.TreePlanter;
import com.sk89q.worldedit.command.util.CommandPermissions; import com.sk89q.worldedit.command.util.CommandPermissions;
import com.sk89q.worldedit.command.util.CommandPermissionsConditionGenerator; import com.sk89q.worldedit.command.util.CommandPermissionsConditionGenerator;
import com.sk89q.worldedit.entity.Player; import com.sk89q.worldedit.entity.Player;
import com.sk89q.worldedit.event.platform.CommandEvent;
import com.sk89q.worldedit.extension.platform.PlatformCommandManager;
import com.sk89q.worldedit.function.mask.Mask;
import com.sk89q.worldedit.function.pattern.Pattern; import com.sk89q.worldedit.function.pattern.Pattern;
import com.sk89q.worldedit.internal.annotation.Range;
import com.sk89q.worldedit.internal.command.CommandArgParser;
import com.sk89q.worldedit.internal.expression.Expression; import com.sk89q.worldedit.internal.expression.Expression;
import com.sk89q.worldedit.util.HandSide; import com.sk89q.worldedit.util.HandSide;
import com.sk89q.worldedit.util.TreeGenerator; import com.sk89q.worldedit.util.TreeGenerator;
@ -47,6 +64,9 @@ import com.sk89q.worldedit.world.item.ItemType;
import org.enginehub.piston.annotation.Command; import org.enginehub.piston.annotation.Command;
import org.enginehub.piston.annotation.CommandContainer; import org.enginehub.piston.annotation.CommandContainer;
import org.enginehub.piston.annotation.param.Arg; import org.enginehub.piston.annotation.param.Arg;
import org.enginehub.piston.annotation.param.Switch;
import java.util.List;
@CommandContainer(superTypes = CommandPermissionsConditionGenerator.Registration.class) @CommandContainer(superTypes = CommandPermissionsConditionGenerator.Registration.class)
public class ToolCommands { public class ToolCommands {
@ -56,16 +76,6 @@ public class ToolCommands {
this.we = we; this.we = we;
} }
@Command(
name = "none",
desc = "Unbind a bound tool from your current item"
)
public void none(Player player, LocalSession session) throws WorldEditException {
session.setTool(player, null);
player.print("Tool unbound from your current item.");
}
@Command( @Command(
name = "/selwand", name = "/selwand",
aliases = "selwand", aliases = "selwand",

View File

@ -19,18 +19,38 @@
package com.sk89q.worldedit.command; package com.sk89q.worldedit.command;
import com.boydti.fawe.config.BBC;
import com.boydti.fawe.object.brush.BrushSettings;
import com.boydti.fawe.object.brush.TargetMode;
import com.boydti.fawe.object.brush.scroll.ScrollAction;
import com.boydti.fawe.object.brush.visualization.VisualMode;
import com.boydti.fawe.object.extent.ResettableExtent;
import com.boydti.fawe.util.MathMan;
import com.boydti.fawe.util.StringMan;
import com.google.common.collect.Iterables;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.LocalSession; import com.sk89q.worldedit.LocalSession;
import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.blocks.BaseItem;
import com.sk89q.worldedit.command.argument.Arguments;
import com.sk89q.worldedit.command.tool.BrushTool;
import com.sk89q.worldedit.command.util.CommandPermissions; import com.sk89q.worldedit.command.util.CommandPermissions;
import com.sk89q.worldedit.command.util.CommandPermissionsConditionGenerator; import com.sk89q.worldedit.command.util.CommandPermissionsConditionGenerator;
import com.sk89q.worldedit.entity.Player; import com.sk89q.worldedit.entity.Player;
import com.sk89q.worldedit.event.platform.CommandEvent;
import com.sk89q.worldedit.extension.platform.PlatformCommandManager;
import com.sk89q.worldedit.function.mask.Mask; import com.sk89q.worldedit.function.mask.Mask;
import com.sk89q.worldedit.function.pattern.Pattern; import com.sk89q.worldedit.function.pattern.Pattern;
import com.sk89q.worldedit.internal.annotation.Range;
import com.sk89q.worldedit.internal.command.CommandArgParser;
import com.sk89q.worldedit.util.HandSide; import com.sk89q.worldedit.util.HandSide;
import org.enginehub.piston.annotation.Command; import org.enginehub.piston.annotation.Command;
import org.enginehub.piston.annotation.CommandContainer; import org.enginehub.piston.annotation.CommandContainer;
import org.enginehub.piston.annotation.param.Arg; import org.enginehub.piston.annotation.param.Arg;
import org.enginehub.piston.annotation.param.Switch;
import java.util.List;
/** /**
* Tool commands. * Tool commands.
@ -44,56 +64,64 @@ public class ToolUtilCommands {
} }
@Command( @Command(
name = "/", name = "mask",
aliases = { "," }, aliases = {"/mask"},
desc = "Toggle the super pickaxe function" desc = "Set the brush destination mask"
) )
@CommandPermissions("worldedit.superpickaxe") @CommandPermissions({"worldedit.brush.options.mask", "worldedit.mask.brush"})
public void togglePickaxe(Player player, LocalSession session, public void mask(Player player, LocalSession session,
@Arg(desc = "The new super pickaxe state", def = "") @Switch(name = 'h', desc = "TODO")
Boolean superPickaxe) { boolean offHand,
boolean hasSuperPickAxe = session.hasSuperPickAxe(); @Arg(desc = "The destination mask", def = "")
if (superPickaxe != null && superPickaxe == hasSuperPickAxe) { Mask maskOpt,
player.printError("Super pickaxe already " + (superPickaxe ? "enabled" : "disabled") + "."); Arguments arguments)
throws WorldEditException {
BrushTool tool = session.getBrushTool(player, false);
if (tool == null) {
player.print(BBC.BRUSH_NONE.s());
return; return;
} }
if (hasSuperPickAxe) {
session.disableSuperPickAxe();
player.print("Super pickaxe disabled.");
} else {
session.enableSuperPickAxe();
player.print("Super pickaxe enabled.");
}
}
@Command(
name = "mask",
desc = "Set the brush mask"
)
@CommandPermissions("worldedit.brush.options.mask")
public void mask(Player player, LocalSession session,
@Arg(desc = "The mask to set", def = "")
Mask maskOpt) throws WorldEditException {
session.getBrushTool(player).setMask(maskOpt);
if (maskOpt == null) { if (maskOpt == null) {
player.print("Brush mask disabled."); BBC.BRUSH_MASK_DISABLED.send(player);
} else { tool.setMask(null);
player.print("Brush mask set."); return;
} }
BrushSettings settings = offHand ? tool.getOffHand() : tool.getContext();
String lastArg = Iterables.getLast(CommandArgParser.spaceSplit(arguments.get())).getSubstring();
System.out.println(lastArg + " TODO check this is not the whole command");
settings.addSetting(BrushSettings.SettingType.MASK, lastArg);
settings.setMask(maskOpt);
tool.update();
BBC.BRUSH_MASK.send(player);
} }
@Command( @Command(
name = "material", name = "material",
aliases = { "/material" }, aliases = {"mat", "/material", "pattern"},
desc = "Set the brush material" desc = "Set the brush material"
) )
@CommandPermissions("worldedit.brush.options.material") @CommandPermissions("worldedit.brush.options.material")
public void material(Player player, LocalSession session, public void material(Player player, LocalSession session,
@Arg(desc = "The pattern of blocks to use") @Arg(desc = "brush material pattern", def = "") Pattern patternOpt,
Pattern pattern) throws WorldEditException { @Switch(name = 'h', desc = "TODO")
session.getBrushTool(player).setFill(pattern); boolean offHand,
player.print("Brush material set."); Arguments arguments) throws WorldEditException {
BrushTool tool = session.getBrushTool(player, false);
if (tool == null) {
player.print(BBC.BRUSH_NONE.s());
return;
}
if (patternOpt == null) {
BBC.BRUSH_MATERIAL.send(player);
tool.setFill(null);
return;
}
BrushSettings settings = offHand ? tool.getOffHand() : tool.getContext();
settings.setFill(patternOpt);
String lastArg = Iterables.getLast(CommandArgParser.spaceSplit(arguments.get())).getSubstring();
settings.addSetting(BrushSettings.SettingType.FILL, lastArg);
tool.update();
BBC.BRUSH_MATERIAL.send(player);
} }
@Command( @Command(
@ -102,10 +130,16 @@ public class ToolUtilCommands {
) )
@CommandPermissions("worldedit.brush.options.range") @CommandPermissions("worldedit.brush.options.range")
public void range(Player player, LocalSession session, public void range(Player player, LocalSession session,
@Arg(desc = "The range of the brush") @Arg(desc = "Range")
int range) throws WorldEditException { int range) throws WorldEditException {
session.getBrushTool(player).setRange(range); range = Math.max(0, Math.min(256, range));
player.print("Brush range set."); BrushTool tool = session.getBrushTool(player, false);
if (tool == null) {
player.print(BBC.BRUSH_NONE.s());
return;
}
tool.setRange(range);
BBC.BRUSH_RANGE.send(player);
} }
@Command( @Command(
@ -114,27 +148,265 @@ public class ToolUtilCommands {
) )
@CommandPermissions("worldedit.brush.options.size") @CommandPermissions("worldedit.brush.options.size")
public void size(Player player, LocalSession session, public void size(Player player, LocalSession session,
@Arg(desc = "The size of the brush") @Arg(desc = "The size of the brush", def = "5")
int size) throws WorldEditException { int radius,
we.checkMaxBrushRadius(size); @Switch(name = 'h', desc = "TODO")
boolean offHand) throws WorldEditException {
session.getBrushTool(player).setSize(size); we.checkMaxBrushRadius(radius);
player.print("Brush size set."); BrushTool tool = session.getBrushTool(player, false);
if (tool == null) {
player.print(BBC.BRUSH_NONE.s());
return;
}
BrushSettings settings = offHand ? tool.getOffHand() : tool.getContext();
settings.setSize(radius);
tool.update();
BBC.BRUSH_SIZE.send(player);
} }
@Command( @Command(
name = "tracemask", name = "tracemask",
aliases = {"tarmask", "tm", "targetmask"},
desc = "Set the mask used to stop tool traces" desc = "Set the mask used to stop tool traces"
) )
@CommandPermissions("worldedit.brush.options.tracemask") @CommandPermissions("worldedit.brush.options.tracemask")
public void traceMask(Player player, LocalSession session, public void traceMask(Player player, LocalSession session,
@Arg(desc = "The trace mask to set", def = "") @Arg(desc = "The trace mask to set", def = "")
Mask maskOpt) throws WorldEditException { Mask maskOpt) throws WorldEditException {
session.getBrushTool(player).setTraceMask(maskOpt); BrushTool tool = session.getBrushTool(player, false);
if (maskOpt == null) { if (tool == null) {
player.print("Trace mask disabled."); BBC.BRUSH_NONE.send(player);
} else { return;
player.print("Trace mask set.");
} }
tool.setTraceMask(maskOpt);
BBC.BRUSH_TARGET_MASK_SET.send(player, maskOpt.toString());
}
@Command(
name = "none",
aliases = {"/none"},
desc = "Unbind a bound tool from your current item"
)
public void none(Player player, LocalSession session) throws WorldEditException {
session.setTool(player, null);
BBC.TOOL_NONE.send(player);
}
@Command(
name = "/",
aliases = {","},
desc = "Toggle the super pickaxe function"
)
@CommandPermissions("worldedit.superpickaxe")
public void togglePickaxe(Player player, LocalSession session,
@Arg(desc = "state", def = "on") String state) throws WorldEditException {
if (session.hasSuperPickAxe()) {
if ("on".equals(state)) {
BBC.SUPERPICKAXE_ENABLED.send(player);
return;
}
session.disableSuperPickAxe();
BBC.SUPERPICKAXE_DISABLED.send(player);
} else {
if ("off".equals(state)) {
BBC.SUPERPICKAXE_DISABLED.send(player);
return;
}
session.enableSuperPickAxe();
BBC.SUPERPICKAXE_ENABLED.send(player);
}
}
@Command(
name = "primary",
desc = "Set the right click brush",
descFooter = "Set the right click brush"
)
@CommandPermissions("worldedit.brush.primary")
public void primary(Player player, LocalSession session,
@Arg(desc = "The brush command", variable = true) List<String> commandStr) throws WorldEditException {
BaseItem item = player.getItemInHand(HandSide.MAIN_HAND);
BrushTool tool = session.getBrushTool(player, false);
session.setTool(item, null, player);
String cmd = "brush " + StringMan.join(commandStr, " ");
CommandEvent event = new CommandEvent(player, cmd);
PlatformCommandManager.getInstance().handleCommandOnCurrentThread(event);
BrushTool newTool = session.getBrushTool(item, player, false);
if (newTool != null && tool != null) {
newTool.setSecondary(tool.getSecondary());
}
}
@Command(
name = "secondary",
desc = "Set the left click brush",
descFooter = "Set the left click brush"
)
@CommandPermissions("worldedit.brush.secondary")
public void secondary(Player player, LocalSession session,
@Arg(desc = "The brush command", variable = true) List<String> commandStr)
throws WorldEditException {
BaseItem item = player.getItemInHand(HandSide.MAIN_HAND);
BrushTool tool = session.getBrushTool(player, false);
session.setTool(item, null, player);
String cmd = "brush " + StringMan.join(commandStr, " ");
CommandEvent event = new CommandEvent(player, cmd);
PlatformCommandManager.getInstance().handleCommandOnCurrentThread(event);
BrushTool newTool = session.getBrushTool(item, player, false);
if (newTool != null && tool != null) {
newTool.setPrimary(tool.getPrimary());
}
}
@Command(
name = "visualize",
aliases = {"visual", "vis"},
desc = "Toggle between different visualization modes",
descFooter = "Toggle between different visualization modes\n" +
"0 = No visualization\n" +
"1 = Single block at target position\n" +
"2 = Glass showing what blocks will be changed"
)
@CommandPermissions("worldedit.brush.visualize")
public void visual(Player player, LocalSession session, @Arg(name = "mode", desc = "int", def = "0") @Range(min = 0, max = 2) int mode)
throws WorldEditException {
BrushTool tool = session.getBrushTool(player, false);
if (tool == null) {
BBC.BRUSH_NONE.send(player);
return;
}
VisualMode[] modes = VisualMode.values();
VisualMode newMode = modes[MathMan.wrap(mode, 0, modes.length - 1)];
tool.setVisualMode(player, newMode);
BBC.BRUSH_VISUAL_MODE_SET.send(player, newMode);
}
@Command(
name = "target",
aliases = {"tar"},
desc = "Toggle between different target modes"
)
@CommandPermissions("worldedit.brush.target")
public void target(Player player, LocalSession session,
@Arg(name = "mode", desc = "int", def = "0") int mode) throws WorldEditException {
BrushTool tool = session.getBrushTool(player, false);
if (tool == null) {
BBC.BRUSH_NONE.send(player);
return;
}
TargetMode[] modes = TargetMode.values();
TargetMode newMode = modes[MathMan.wrap(mode, 0, modes.length - 1)];
tool.setTargetMode(newMode);
BBC.BRUSH_TARGET_MODE_SET.send(player, newMode);
}
@Command(
name = "targetoffset",
aliases = {"to"},
desc = "Set the targeting mask"
)
@CommandPermissions("worldedit.brush.targetoffset")
public void targetOffset(Player player, EditSession editSession, LocalSession session,
int offset) throws WorldEditException {
BrushTool tool = session.getBrushTool(player, false);
if (tool == null) {
BBC.BRUSH_NONE.send(player);
return;
}
tool.setTargetOffset(offset);
BBC.BRUSH_TARGET_OFFSET_SET.send(player, offset);
}
@Command(
name = "scroll",
desc = "Toggle between different target modes"
)
@CommandPermissions("worldedit.brush.scroll")
public void scroll(Player player, EditSession editSession, LocalSession session,
@Switch(name = 'h', desc = "TODO")
boolean offHand,
@Arg(desc = "Target Modes")
String modes,
@Arg(desc = "The scroll action", variable = true)
List<String> commandStr) throws WorldEditException {
// TODO NOT IMPLEMENTED Convert ScrollAction to an argument converter
BrushTool bt = session.getBrushTool(player, false);
if (bt == null) {
BBC.BRUSH_NONE.send(player);
return;
}
BrushSettings settings = offHand ? bt.getOffHand() : bt.getContext();
ScrollAction action = ScrollAction.fromArguments(bt, player, session, StringMan.join(commandStr, " "), true);
settings.setScrollAction(action);
if (modes.equalsIgnoreCase("none")) {
BBC.BRUSH_SCROLL_ACTION_UNSET.send(player);
} else if (action != null) {
settings.addSetting(BrushSettings.SettingType.SCROLL_ACTION, modes);
BBC.BRUSH_SCROLL_ACTION_SET.send(player, modes);
}
bt.update();
}
@Command(
name = "smask",
aliases = {"/smask", "/sourcemask", "sourcemask"},
desc = "Set the brush source mask",
descFooter = "Set the brush source mask"
)
@CommandPermissions({"worldedit.brush.options.mask", "worldedit.mask.brush"})
public void smask(Player player, LocalSession session, EditSession editSession,
@Arg(desc = "The destination mask", def = "")
Mask maskArg,
@Switch(name = 'h', desc = "TODO")
boolean offHand,
Arguments arguments) throws WorldEditException {
BrushTool tool = session.getBrushTool(player, false);
if (tool == null) {
player.print(BBC.BRUSH_NONE.s());
return;
}
if (maskArg == null) {
BBC.BRUSH_SOURCE_MASK_DISABLED.send(player);
tool.setSourceMask(null);
return;
}
BrushSettings settings = offHand ? tool.getOffHand() : tool.getContext();
String lastArg = Iterables.getLast(CommandArgParser.spaceSplit(arguments.get())).getSubstring();
settings.addSetting(BrushSettings.SettingType.SOURCE_MASK, lastArg);
settings.setSourceMask(maskArg);
tool.update();
BBC.BRUSH_SOURCE_MASK.send(player);
}
@Command(
name = "transform",
desc = "Set the brush transform"
)
@CommandPermissions({"worldedit.brush.options.transform", "worldedit.transform.brush"})
public void transform(Player player, LocalSession session, EditSession editSession,
@Arg(desc = "The transform", def = "") ResettableExtent transform,
@Switch(name = 'h', desc = "TODO")
boolean offHand,
Arguments arguments) throws WorldEditException {
BrushTool tool = session.getBrushTool(player, false);
if (tool == null) {
player.print(BBC.BRUSH_NONE.s());
return;
}
if (transform == null) {
BBC.BRUSH_TRANSFORM_DISABLED.send(player);
tool.setTransform(null);
return;
}
BrushSettings settings = offHand ? tool.getOffHand() : tool.getContext();
String lastArg = Iterables.getLast(CommandArgParser.spaceSplit(arguments.get())).getSubstring();
settings.addSetting(BrushSettings.SettingType.TRANSFORM, lastArg);
settings.setTransform(transform);
tool.update();
BBC.BRUSH_TRANSFORM.send(player);
} }
} }

View File

@ -54,7 +54,7 @@ public final class RegistryConverter<V extends Keyed> implements ArgumentConvert
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public static void register(CommandManager commandManager) { public static void register(CommandManager commandManager) {
ImmutableList.of( ImmutableList.of(
BlockTypes.class, BlockType.class,
BlockCategory.class, BlockCategory.class,
ItemType.class, ItemType.class,
ItemCategory.class, ItemCategory.class,

View File

@ -19,38 +19,30 @@
package com.sk89q.worldedit.extension.platform; package com.sk89q.worldedit.extension.platform;
import static com.google.common.base.Preconditions.checkNotNull;
import com.boydti.fawe.Fawe; import com.boydti.fawe.Fawe;
import com.boydti.fawe.command.AnvilCommands; import com.boydti.fawe.command.AnvilCommands;
import com.boydti.fawe.command.AnvilCommandsRegistration; import com.boydti.fawe.command.AnvilCommandsRegistration;
import com.boydti.fawe.command.CFICommand;
import com.boydti.fawe.command.CFICommands; import com.boydti.fawe.command.CFICommands;
import com.boydti.fawe.command.CFICommandsRegistration; import com.boydti.fawe.command.CFICommandsRegistration;
import com.boydti.fawe.config.BBC; import com.boydti.fawe.config.BBC;
import com.boydti.fawe.config.Settings; import com.boydti.fawe.config.Settings;
import com.boydti.fawe.object.FawePlayer; import com.boydti.fawe.object.FawePlayer;
import com.boydti.fawe.object.task.ThrowableSupplier; import com.boydti.fawe.object.task.ThrowableSupplier;
import com.boydti.fawe.util.StringMan;
import com.boydti.fawe.util.TaskManager; import com.boydti.fawe.util.TaskManager;
import com.boydti.fawe.wrappers.LocationMaskedPlayerWrapper; import com.boydti.fawe.wrappers.LocationMaskedPlayerWrapper;
import com.google.common.collect.HashMultimap;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Multimap;
import com.google.common.collect.SetMultimap;
import com.google.common.reflect.TypeToken; import com.google.common.reflect.TypeToken;
import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.LocalConfiguration; import com.sk89q.worldedit.LocalConfiguration;
import com.sk89q.worldedit.LocalSession; import com.sk89q.worldedit.LocalSession;
import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.command.ApplyBrushCommands; import com.sk89q.worldedit.command.ApplyBrushCommands;
import com.sk89q.worldedit.command.ApplyBrushCommandsRegistration;
import com.sk89q.worldedit.command.BiomeCommands; import com.sk89q.worldedit.command.BiomeCommands;
import com.sk89q.worldedit.command.BiomeCommandsRegistration; import com.sk89q.worldedit.command.BiomeCommandsRegistration;
import com.sk89q.worldedit.command.BrushCommands; import com.sk89q.worldedit.command.BrushCommands;
import com.sk89q.worldedit.command.BrushCommandsRegistration; import com.sk89q.worldedit.command.BrushCommandsRegistration;
import com.sk89q.worldedit.command.BrushOptionsCommands;
import com.sk89q.worldedit.command.BrushOptionsCommandsRegistration;
import com.sk89q.worldedit.command.ChunkCommands; import com.sk89q.worldedit.command.ChunkCommands;
import com.sk89q.worldedit.command.ChunkCommandsRegistration; import com.sk89q.worldedit.command.ChunkCommandsRegistration;
import com.sk89q.worldedit.command.ClipboardCommands; import com.sk89q.worldedit.command.ClipboardCommands;
@ -62,10 +54,11 @@ import com.sk89q.worldedit.command.GenerationCommands;
import com.sk89q.worldedit.command.GenerationCommandsRegistration; import com.sk89q.worldedit.command.GenerationCommandsRegistration;
import com.sk89q.worldedit.command.HistoryCommands; import com.sk89q.worldedit.command.HistoryCommands;
import com.sk89q.worldedit.command.HistoryCommandsRegistration; import com.sk89q.worldedit.command.HistoryCommandsRegistration;
import com.sk89q.worldedit.command.MaskCommands;
import com.sk89q.worldedit.command.MaskCommandsRegistration;
import com.sk89q.worldedit.command.NavigationCommands; import com.sk89q.worldedit.command.NavigationCommands;
import com.sk89q.worldedit.command.NavigationCommandsRegistration; import com.sk89q.worldedit.command.NavigationCommandsRegistration;
import com.sk89q.worldedit.command.PaintBrushCommands; import com.sk89q.worldedit.command.PaintBrushCommands;
import com.sk89q.worldedit.command.PaintBrushCommandsRegistration;
import com.sk89q.worldedit.command.PatternCommands; import com.sk89q.worldedit.command.PatternCommands;
import com.sk89q.worldedit.command.PatternCommandsRegistration; import com.sk89q.worldedit.command.PatternCommandsRegistration;
import com.sk89q.worldedit.command.RegionCommands; import com.sk89q.worldedit.command.RegionCommands;
@ -123,6 +116,7 @@ import com.sk89q.worldedit.internal.command.CommandRegistrationHandler;
import com.sk89q.worldedit.internal.command.exception.ExceptionConverter; import com.sk89q.worldedit.internal.command.exception.ExceptionConverter;
import com.sk89q.worldedit.internal.command.exception.WorldEditExceptionConverter; import com.sk89q.worldedit.internal.command.exception.WorldEditExceptionConverter;
import com.sk89q.worldedit.internal.util.Substring; import com.sk89q.worldedit.internal.util.Substring;
import com.sk89q.worldedit.session.SessionKey;
import com.sk89q.worldedit.session.request.Request; import com.sk89q.worldedit.session.request.Request;
import com.sk89q.worldedit.util.auth.AuthorizationException; import com.sk89q.worldedit.util.auth.AuthorizationException;
import com.sk89q.worldedit.util.eventbus.Subscribe; import com.sk89q.worldedit.util.eventbus.Subscribe;
@ -132,29 +126,6 @@ import com.sk89q.worldedit.util.formatting.text.format.TextColor;
import com.sk89q.worldedit.util.logging.DynamicStreamHandler; import com.sk89q.worldedit.util.logging.DynamicStreamHandler;
import com.sk89q.worldedit.util.logging.LogFormat; import com.sk89q.worldedit.util.logging.LogFormat;
import com.sk89q.worldedit.world.World; import com.sk89q.worldedit.world.World;
import java.io.File;
import java.io.IOException;
import java.lang.annotation.Annotation;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.concurrent.Callable;
import java.util.function.BiConsumer;
import java.util.function.BiFunction;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.logging.FileHandler;
import java.util.logging.Level;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import javax.annotation.Nullable;
import org.enginehub.piston.Command; import org.enginehub.piston.Command;
import org.enginehub.piston.CommandManager; import org.enginehub.piston.CommandManager;
import org.enginehub.piston.TextConfig; import org.enginehub.piston.TextConfig;
@ -180,6 +151,28 @@ import org.enginehub.piston.util.ValueProvider;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import javax.annotation.Nullable;
import java.io.File;
import java.io.IOException;
import java.lang.annotation.Annotation;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.function.BiConsumer;
import java.util.function.Consumer;
import java.util.logging.FileHandler;
import java.util.logging.Level;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import static com.google.common.base.Preconditions.checkNotNull;
/** /**
* Handles the registration and invocation of commands. * Handles the registration and invocation of commands.
@ -234,6 +227,7 @@ public final class PlatformCommandManager {
} }
private void initialize() { private void initialize() {
System.out.println("========== INITIALIZE");
// Register this instance for command events // Register this instance for command events
worldEdit.getEventBus().register(this); worldEdit.getEventBus().register(this);
@ -279,42 +273,14 @@ public final class PlatformCommandManager {
// TODO NOT IMPLEMENTED - register the following using a custom processor / annotations // TODO NOT IMPLEMENTED - register the following using a custom processor / annotations
} }
public org.enginehub.piston.annotation.Command createAnnotation(String name, List<String> aliases, String desc) { public <CI> void registerSubCommands(String name, List<String> aliases, String desc, CommandManager commandManager, Consumer<BiConsumer<CommandRegistration,CI>> handlerInstance) {
return new org.enginehub.piston.annotation.Command() { registerSubCommands(name, aliases, desc, commandManager, handlerInstance, m -> {});
@Override
public Class<? extends Annotation> annotationType() {
return getClass();
} }
@Override public <CI> void registerSubCommands(String name, List<String> aliases, String desc, CommandManager commandManager, Consumer<BiConsumer<CommandRegistration,CI>> handlerInstance, Consumer<CommandManager> additionalConfig) {
public String name() { commandManager.register(name, builder -> {
return name; builder.aliases(aliases);
} builder.description(TextComponent.of(desc));
@Override
public String[] aliases() {
return aliases.toArray(new String[0]);
}
@Override
public String desc() {
return desc;
}
@Override
public String descFooter() {
return "";
}
};
}
public <CI> void registerSubCommands(org.enginehub.piston.annotation.Command annotation, Consumer<BiConsumer<CommandRegistration,CI>> handlerInstance) {
registerSubCommands(annotation, commandManager, handlerInstance);
}
public <CI> void registerSubCommands(org.enginehub.piston.annotation.Command annotation, CommandManager commandManager, Consumer<BiConsumer<CommandRegistration,CI>> handlerInstance) {
commandManager.register(annotation.name(), builder -> {
builder.description(TextComponent.of(annotation.desc()));
builder.action(org.enginehub.piston.Command.Action.NULL_ACTION); builder.action(org.enginehub.piston.Command.Action.NULL_ACTION);
CommandManager manager = commandManagerService.newCommandManager(); CommandManager manager = commandManagerService.newCommandManager();
@ -338,11 +304,11 @@ public final class PlatformCommandManager {
public <CI> void registerSubCommands(String name, List<String> aliases, String desc, public <CI> void registerSubCommands(String name, List<String> aliases, String desc,
CommandRegistration<CI> registration, CI instance) { CommandRegistration<CI> registration, CI instance) {
registerSubCommands(createAnnotation(name, aliases, desc), commandManager, c -> c.accept(registration, instance)); registerSubCommands(name, aliases, desc, commandManager, c -> c.accept(registration, instance));
} }
public <CI> void registerSubCommands(String name, List<String> aliases, String desc, Consumer<BiConsumer<CommandRegistration,CI>> handlerInstance) { public <CI> void registerSubCommands(String name, List<String> aliases, String desc, Consumer<BiConsumer<CommandRegistration,CI>> handlerInstance) {
registerSubCommands(createAnnotation(name, aliases, desc), commandManager, handlerInstance); registerSubCommands(name, aliases, desc, commandManager, handlerInstance);
} }
public void registerAllCommands() { public void registerAllCommands() {
@ -354,6 +320,13 @@ public final class PlatformCommandManager {
PatternCommandsRegistration.builder(), PatternCommandsRegistration.builder(),
new PatternCommands() new PatternCommands()
); );
registerSubCommands(
"masks",
ImmutableList.of(),
"Masks determine which blocks are placed",
MaskCommandsRegistration.builder(),
new MaskCommands(worldEdit)
);
registerSubCommands( registerSubCommands(
"transforms", "transforms",
ImmutableList.of(), ImmutableList.of(),
@ -383,20 +356,17 @@ public final class PlatformCommandManager {
new SuperPickaxeCommands(worldEdit) new SuperPickaxeCommands(worldEdit)
); );
registerSubCommands( registerSubCommands(
createAnnotation("brush", Arrays.asList("br", "/brush", "/br", "/tool", "tool"), "Brushing commands"), "brush", Arrays.asList("br", "/brush", "/br", "/tool", "tool"), "Brushing commands",
commandManager,
c -> { c -> {
c.accept(BrushCommandsRegistration.builder(), new BrushCommands(worldEdit)); c.accept(BrushCommandsRegistration.builder(), new BrushCommands(worldEdit));
c.accept(PaintBrushCommandsRegistration.builder(), new PaintBrushCommands()); c.accept(ToolCommandsRegistration.builder(), new ToolCommands(worldEdit));
c.accept(ApplyBrushCommandsRegistration.builder(), new ApplyBrushCommands()); },
manager -> {
PaintBrushCommands.register(commandManagerService, manager, registration);
ApplyBrushCommands.register(commandManagerService, manager, registration);
} }
); );
registerSubCommands(
"brush",
ImmutableList.of("br", "/brush", "/br", "/tool", "tool"),
"Tool commands",
BrushOptionsCommandsRegistration.builder(),
new BrushOptionsCommands(worldEdit)
);
registerSubCommands( registerSubCommands(
"worldedit", "worldedit",
ImmutableList.of("we"), ImmutableList.of("we"),
@ -418,17 +388,6 @@ public final class PlatformCommandManager {
AnvilCommandsRegistration.builder(), AnvilCommandsRegistration.builder(),
new AnvilCommands(worldEdit) new AnvilCommands(worldEdit)
); );
// registerSubCommands(
// "transforms",
// ImmutableList.of(),
// "Transforms modify how a block is placed\n" +
// " - Use [brackets] for arguments\n" +
// " - Use , to OR multiple\n" +
// " - Use & to AND multiple\n" +
// "More Info: https://git.io/v9KHO",
// TransformCommandsRegistration.builder(),
// new TransformCommands()
// );
this.registration.register( this.registration.register(
commandManager, commandManager,
BiomeCommandsRegistration.builder(), BiomeCommandsRegistration.builder(),
@ -500,6 +459,7 @@ public final class PlatformCommandManager {
UtilityCommandsRegistration.builder(), UtilityCommandsRegistration.builder(),
new UtilityCommands(worldEdit) new UtilityCommands(worldEdit)
); );
System.out.println("========== REGISTERED COMMANDS");
} }
} }
@ -609,7 +569,7 @@ public final class PlatformCommandManager {
} }
public Stream<Substring> parseArgs(String input) { public Stream<Substring> parseArgs(String input) {
return new CommandArgParser(CommandArgParser.spaceSplit(input.substring(1))).parseArgs(); return new CommandArgParser(CommandArgParser.spaceSplit(input)).parseArgs();
} }
public <T> Collection<T> parse(Class<T> clazz, String arguments, @Nullable Actor actor) { public <T> Collection<T> parse(Class<T> clazz, String arguments, @Nullable Actor actor) {
@ -667,24 +627,30 @@ public final class PlatformCommandManager {
Request.reset(); Request.reset();
Actor actor = event.getActor(); Actor actor = event.getActor();
String args = event.getArguments(); String args = event.getArguments();
CommandEvent finalEvent = new CommandEvent(actor, args); CommandEvent finalEvent = event;
final FawePlayer<Object> fp = FawePlayer.wrap(actor); final FawePlayer<Object> fp = FawePlayer.wrap(actor);
System.out.println(1);
TaskManager.IMP.taskNow(() -> { TaskManager.IMP.taskNow(() -> {
int space0 = args.indexOf(' '); int space0 = args.indexOf(' ');
String arg0 = space0 == -1 ? args : args.substring(0, space0); String arg0 = space0 == -1 ? args : args.substring(0, space0);
Optional<Command> optional = commandManager.getCommand(arg0); Optional<Command> optional = commandManager.getCommand(arg0);
if (!optional.isPresent()) return; if (!optional.isPresent()) {
System.out.println("No command for '" + arg0 + "' " + StringMan.getString(commandManager.getAllCommands().map(command -> command.getName()).collect(Collectors.toList())));
return;
}
Command cmd = optional.get(); Command cmd = optional.get();
CommandQueuedCondition queued = cmd.getCondition().as(CommandQueuedCondition.class).orElse(null); CommandQueuedCondition queued = cmd.getCondition().as(CommandQueuedCondition.class).orElse(null);
if (queued != null && !queued.isQueued()) { if (queued != null && !queued.isQueued()) {
handleCommandOnCurrentThread(finalEvent); handleCommandOnCurrentThread(finalEvent);
return; return;
} }
if (!fp.runAction( LocalSession session = worldEdit.getSessionManager().get(actor);
() -> PlatformCommandManager.this.handleCommandOnCurrentThread(finalEvent), false, true)) { synchronized (session) {
BBC.WORLDEDIT_COMMAND_LIMIT.send(fp); SessionKey key = actor.getSessionKey();
if (key.isActive()) {
PlatformCommandManager.this.handleCommandOnCurrentThread(finalEvent);
}
} }
finalEvent.setCancelled(true);
}, Fawe.isMainThread()); }, Fawe.isMainThread());
} }
@ -707,7 +673,6 @@ public final class PlatformCommandManager {
Request.request().setWorld(((World) extent)); Request.request().setWorld(((World) extent));
} }
} }
LocalConfiguration config = worldEdit.getConfiguration();
MemoizingValueAccess context = initializeInjectedValues(event::getArguments, actor); MemoizingValueAccess context = initializeInjectedValues(event::getArguments, actor);

View File

@ -19,6 +19,8 @@
package com.sk89q.worldedit.session; package com.sk89q.worldedit.session;
import com.sk89q.worldedit.LocalSession;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.util.auth.Subject; import com.sk89q.worldedit.util.auth.Subject;
/** /**
@ -33,4 +35,8 @@ public interface SessionOwner extends Subject {
*/ */
SessionKey getSessionKey(); SessionKey getSessionKey();
default LocalSession getSession() {
return WorldEdit.getInstance().getSessionManager().get(this);
}
} }

View File

@ -937,9 +937,9 @@ public final class BlockTypes {
} }
// Add to $Registry // Add to $Registry
for (BlockType type : values) { // for (BlockType type : values) {
BlockType.REGISTRY.register(type.getId().toLowerCase(Locale.ROOT), type); // BlockType.REGISTRY.register(type.getId().toLowerCase(Locale.ROOT), type);
} // }
states = stateList.toArray(new BlockState[stateList.size()]); states = stateList.toArray(new BlockState[stateList.size()]);
@ -969,7 +969,6 @@ public final class BlockTypes {
} }
// register states // register states
if (typeName.startsWith("minecraft:")) BlockType.REGISTRY.register(typeName.substring(10), existing);
BlockType.REGISTRY.register(typeName, existing); BlockType.REGISTRY.register(typeName, existing);
String nameSpace = typeName.substring(0, typeName.indexOf(':')); String nameSpace = typeName.substring(0, typeName.indexOf(':'));
$NAMESPACES.add(nameSpace); $NAMESPACES.add(nameSpace);

View File

@ -393,22 +393,22 @@
"62:3": "minecraft:furnace[facing=south,lit=true]", "62:3": "minecraft:furnace[facing=south,lit=true]",
"62:4": "minecraft:furnace[facing=west,lit=true]", "62:4": "minecraft:furnace[facing=west,lit=true]",
"62:5": "minecraft:furnace[facing=east,lit=true]", "62:5": "minecraft:furnace[facing=east,lit=true]",
"63:0": "minecraft:sign[rotation=0]", "63:0": "minecraft:oak_sign[rotation=0]",
"63:1": "minecraft:sign[rotation=1]", "63:1": "minecraft:oak_sign[rotation=1]",
"63:2": "minecraft:sign[rotation=2]", "63:2": "minecraft:oak_sign[rotation=2]",
"63:3": "minecraft:sign[rotation=3]", "63:3": "minecraft:oak_sign[rotation=3]",
"63:4": "minecraft:sign[rotation=4]", "63:4": "minecraft:oak_sign[rotation=4]",
"63:5": "minecraft:sign[rotation=5]", "63:5": "minecraft:oak_sign[rotation=5]",
"63:6": "minecraft:sign[rotation=6]", "63:6": "minecraft:oak_sign[rotation=6]",
"63:7": "minecraft:sign[rotation=7]", "63:7": "minecraft:oak_sign[rotation=7]",
"63:8": "minecraft:sign[rotation=8]", "63:8": "minecraft:oak_sign[rotation=8]",
"63:9": "minecraft:sign[rotation=9]", "63:9": "minecraft:oak_sign[rotation=9]",
"63:10": "minecraft:sign[rotation=10]", "63:10": "minecraft:oak_sign[rotation=10]",
"63:11": "minecraft:sign[rotation=11]", "63:11": "minecraft:oak_sign[rotation=11]",
"63:12": "minecraft:sign[rotation=12]", "63:12": "minecraft:oak_sign[rotation=12]",
"63:13": "minecraft:sign[rotation=13]", "63:13": "minecraft:oak_sign[rotation=13]",
"63:14": "minecraft:sign[rotation=14]", "63:14": "minecraft:oak_sign[rotation=14]",
"63:15": "minecraft:sign[rotation=15]", "63:15": "minecraft:oak_sign[rotation=15]",
"64:0": "minecraft:oak_door[hinge=right,half=lower,powered=false,facing=east,open=false]", "64:0": "minecraft:oak_door[hinge=right,half=lower,powered=false,facing=east,open=false]",
"64:1": "minecraft:oak_door[hinge=right,half=lower,powered=false,facing=south,open=false]", "64:1": "minecraft:oak_door[hinge=right,half=lower,powered=false,facing=south,open=false]",
"64:2": "minecraft:oak_door[hinge=right,half=lower,powered=false,facing=west,open=false]", "64:2": "minecraft:oak_door[hinge=right,half=lower,powered=false,facing=west,open=false]",
@ -443,10 +443,10 @@
"67:5": "minecraft:cobblestone_stairs[half=top,shape=straight,facing=west]", "67:5": "minecraft:cobblestone_stairs[half=top,shape=straight,facing=west]",
"67:6": "minecraft:cobblestone_stairs[half=top,shape=straight,facing=south]", "67:6": "minecraft:cobblestone_stairs[half=top,shape=straight,facing=south]",
"67:7": "minecraft:cobblestone_stairs[half=top,shape=straight,facing=north]", "67:7": "minecraft:cobblestone_stairs[half=top,shape=straight,facing=north]",
"68:2": "minecraft:wall_sign[facing=north]", "68:2": "minecraft:oak_wall_sign[facing=north]",
"68:3": "minecraft:wall_sign[facing=south]", "68:3": "minecraft:oak_wall_sign[facing=south]",
"68:4": "minecraft:wall_sign[facing=west]", "68:4": "minecraft:oak_wall_sign[facing=west]",
"68:5": "minecraft:wall_sign[facing=east]", "68:5": "minecraft:oak_wall_sign[facing=east]",
"69:0": "minecraft:lever[powered=false,facing=north,face=ceiling]", "69:0": "minecraft:lever[powered=false,facing=north,face=ceiling]",
"69:1": "minecraft:lever[powered=false,facing=east,face=wall]", "69:1": "minecraft:lever[powered=false,facing=east,face=wall]",
"69:2": "minecraft:lever[powered=false,facing=west,face=wall]", "69:2": "minecraft:lever[powered=false,facing=west,face=wall]",
@ -2165,8 +2165,8 @@
"350:0": "minecraft:cooked_cod", "350:0": "minecraft:cooked_cod",
"350:1": "minecraft:cooked_salmon", "350:1": "minecraft:cooked_salmon",
"351:0": "minecraft:ink_sac", "351:0": "minecraft:ink_sac",
"351:1": "minecraft:rose_red", "351:1": "minecraft:red_dye",
"351:2": "minecraft:cactus_green", "351:2": "minecraft:green_dye",
"351:3": "minecraft:cocoa_beans", "351:3": "minecraft:cocoa_beans",
"351:4": "minecraft:lapis_lazuli", "351:4": "minecraft:lapis_lazuli",
"351:5": "minecraft:purple_dye", "351:5": "minecraft:purple_dye",
@ -2175,7 +2175,7 @@
"351:8": "minecraft:gray_dye", "351:8": "minecraft:gray_dye",
"351:9": "minecraft:pink_dye", "351:9": "minecraft:pink_dye",
"351:10": "minecraft:lime_dye", "351:10": "minecraft:lime_dye",
"351:11": "minecraft:dandelion_yellow", "351:11": "minecraft:yellow_dye",
"351:12": "minecraft:light_blue_dye", "351:12": "minecraft:light_blue_dye",
"351:13": "minecraft:magenta_dye", "351:13": "minecraft:magenta_dye",
"351:14": "minecraft:orange_dye", "351:14": "minecraft:orange_dye",