Partial work on biome commands, need logging replacement

Dieser Commit ist enthalten in:
Kenzie Togami 2019-04-14 01:30:40 -07:00
Ursprung 8ab6585815
Commit f8c4f23658
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 5D200B325E157A81
4 geänderte Dateien mit 60 neuen und 66 gelöschten Zeilen

Datei anzeigen

@ -19,17 +19,11 @@
package com.sk89q.worldedit.command; package com.sk89q.worldedit.command;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.sk89q.minecraft.util.commands.Logging.LogMode.REGION;
import com.sk89q.minecraft.util.commands.Command;
import com.sk89q.minecraft.util.commands.CommandContext;
import com.sk89q.minecraft.util.commands.CommandPermissions;
import com.sk89q.minecraft.util.commands.Logging;
import com.sk89q.worldedit.EditSession; 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.command.util.CommandPermissions;
import com.sk89q.worldedit.entity.Player; import com.sk89q.worldedit.entity.Player;
import com.sk89q.worldedit.extension.platform.Capability; import com.sk89q.worldedit.extension.platform.Capability;
import com.sk89q.worldedit.function.FlatRegionFunction; import com.sk89q.worldedit.function.FlatRegionFunction;
@ -46,11 +40,14 @@ import com.sk89q.worldedit.regions.FlatRegion;
import com.sk89q.worldedit.regions.Region; import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.regions.Regions; import com.sk89q.worldedit.regions.Regions;
import com.sk89q.worldedit.util.Location; import com.sk89q.worldedit.util.Location;
import com.sk89q.worldedit.util.command.binding.Switch;
import com.sk89q.worldedit.world.World; import com.sk89q.worldedit.world.World;
import com.sk89q.worldedit.world.biome.BiomeData; import com.sk89q.worldedit.world.biome.BiomeData;
import com.sk89q.worldedit.world.biome.BiomeType; import com.sk89q.worldedit.world.biome.BiomeType;
import com.sk89q.worldedit.world.registry.BiomeRegistry; import com.sk89q.worldedit.world.registry.BiomeRegistry;
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.Switch;
import java.util.Collection; import java.util.Collection;
import java.util.HashSet; import java.util.HashSet;
@ -59,33 +56,27 @@ import java.util.Set;
/** /**
* Implements biome-related commands such as "/biomelist". * Implements biome-related commands such as "/biomelist".
*/ */
@CommandContainer
public class BiomeCommands { public class BiomeCommands {
private final WorldEdit worldEdit;
/** /**
* Create a new instance. * Create a new instance.
*
* @param worldEdit reference to WorldEdit
*/ */
public BiomeCommands(WorldEdit worldEdit) { public BiomeCommands() {
checkNotNull(worldEdit);
this.worldEdit = worldEdit;
} }
@Command( @Command(
aliases = { "biomelist", "biomels" }, name = "biomelist",
usage = "[page]", aliases = { "biomels" },
desc = "Gets all biomes available.", desc = "Gets all biomes available."
max = 1
) )
@CommandPermissions("worldedit.biome.list") @CommandPermissions("worldedit.biome.list")
public void biomeList(Player player, CommandContext args) throws WorldEditException { public void biomeList(Player player,
int page; @Arg(desc = "Page number.", def = "0") int page) throws WorldEditException {
int offset; int offset;
int count = 0; int count = 0;
if (args.argsLength() == 0 || (page = args.getInteger(0)) < 2) { if (page < 2) {
page = 1; page = 1;
offset = 0; offset = 0;
} else { } else {
@ -115,24 +106,24 @@ public class BiomeCommands {
} }
@Command( @Command(
aliases = { "biomeinfo" }, name = "biomeinfo",
flags = "pt",
desc = "Get the biome of the targeted block.", desc = "Get the biome of the targeted block.",
help = descFooter = "By default, uses all blocks in your selection."
"Get the biome of the block.\n" +
"By default use all the blocks contained in your selection.\n" +
"-t use the block you are looking at.\n" +
"-p use the block you are currently in",
max = 0
) )
@CommandPermissions("worldedit.biome.info") @CommandPermissions("worldedit.biome.info")
public void biomeInfo(Player player, LocalSession session, CommandContext args) throws WorldEditException { public void biomeInfo(Player player, LocalSession session,
@Switch(
name = 't', desc="Use the block you are looking at."
) boolean useLineOfSight,
@Switch(
name = 'p', desc="Use the block you are currently in."
) boolean usePosition) throws WorldEditException {
BiomeRegistry biomeRegistry = WorldEdit.getInstance().getPlatformManager() BiomeRegistry biomeRegistry = WorldEdit.getInstance().getPlatformManager()
.queryCapability(Capability.GAME_HOOKS).getRegistries().getBiomeRegistry(); .queryCapability(Capability.GAME_HOOKS).getRegistries().getBiomeRegistry();
Set<BiomeType> biomes = new HashSet<>(); Set<BiomeType> biomes = new HashSet<>();
String qualifier; String qualifier;
if (args.hasFlag('t')) { if (useLineOfSight) {
Location blockPosition = player.getBlockTrace(300); Location blockPosition = player.getBlockTrace(300);
if (blockPosition == null) { if (blockPosition == null) {
player.printError("No block in sight!"); player.printError("No block in sight!");
@ -143,7 +134,7 @@ public class BiomeCommands {
biomes.add(biome); biomes.add(biome);
qualifier = "at line of sight point"; qualifier = "at line of sight point";
} else if (args.hasFlag('p')) { } else if (usePosition) {
BiomeType biome = player.getWorld().getBiome(player.getLocation().toVector().toBlockPoint().toBlockVector2()); BiomeType biome = player.getWorld().getBiome(player.getLocation().toVector().toBlockPoint().toBlockVector2());
biomes.add(biome); biomes.add(biome);
@ -177,18 +168,15 @@ public class BiomeCommands {
} }
@Command( @Command(
aliases = { "/setbiome" }, name = "/setbiome",
usage = "<biome>",
flags = "p",
desc = "Sets the biome of the player's current block or region.", desc = "Sets the biome of the player's current block or region.",
help = descFooter = "By default, uses all the blocks in your selection"
"Set the biome of the region.\n" +
"By default use all the blocks contained in your selection.\n" +
"-p use the block you are currently in"
) )
@Logging(REGION) // @Logging(REGION)
@CommandPermissions("worldedit.biome.set") @CommandPermissions("worldedit.biome.set")
public void setBiome(Player player, LocalSession session, EditSession editSession, BiomeType target, @Switch('p') boolean atPosition) throws WorldEditException { public void setBiome(Player player, LocalSession session, EditSession editSession,
BiomeType target,
@Switch(name = 'p', desc = "Use your current position") boolean atPosition) throws WorldEditException {
World world = player.getWorld(); World world = player.getWorld();
Region region; Region region;
Mask mask = editSession.getMask(); Mask mask = editSession.getMask();

Datei anzeigen

@ -41,9 +41,8 @@ public class CommandPermissionsConditionGenerator implements CommandConditionGen
CommandPermissions annotation = commandMethod.getAnnotation(CommandPermissions.class); CommandPermissions annotation = commandMethod.getAnnotation(CommandPermissions.class);
checkNotNull(annotation, "Annotation is missing from commandMethod"); checkNotNull(annotation, "Annotation is missing from commandMethod");
Set<String> permissions = ImmutableSet.copyOf(annotation.value()); Set<String> permissions = ImmutableSet.copyOf(annotation.value());
return p -> { return p -> p.injectedValue(ACTOR_KEY)
Actor actor = p.injectedValue(ACTOR_KEY); .map(actor -> permissions.stream().anyMatch(actor::hasPermission))
return permissions.stream().anyMatch(actor::hasPermission); .orElse(false);
};
} }
} }

Datei anzeigen

@ -145,7 +145,7 @@ public final class CommandManager {
dispatcher = new CommandGraph() dispatcher = new CommandGraph()
.builder(builder) .builder(builder)
.commands() .commands()
.registerMethods(new BiomeCommands(worldEdit)) .registerMethods(new BiomeCommands())
.registerMethods(new ChunkCommands(worldEdit)) .registerMethods(new ChunkCommands(worldEdit))
.registerMethods(new ClipboardCommands(worldEdit)) .registerMethods(new ClipboardCommands(worldEdit))
.registerMethods(new GeneralCommands(worldEdit)) .registerMethods(new GeneralCommands(worldEdit))
@ -198,11 +198,12 @@ public final class CommandManager {
desc.setPermissions(ImmutableList.of()); desc.setPermissions(ImmutableList.of());
org.enginehub.piston.CommandManager manager = DefaultCommandManagerService.getInstance() org.enginehub.piston.CommandManager manager = DefaultCommandManagerService.getInstance()
.newCommandManager(); .newCommandManager();
new SchematicCommandsRegistration( SchematicCommandsRegistration.builder()
manager, .commandManager(manager)
new SchematicCommands(worldEdit), .containerInstance(new SchematicCommands(worldEdit))
.commandPermissionsConditionGenerator(
new CommandPermissionsConditionGenerator() new CommandPermissionsConditionGenerator()
); ).build();
return new CommandManagerCallable(worldEdit, manager, desc); return new CommandManagerCallable(worldEdit, manager, desc);
} }

Datei anzeigen

@ -33,6 +33,7 @@ import org.enginehub.piston.CommandManager;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Optional;
/** /**
* Hack to get {@link CommandManager} working under {@link CommandCallable}. * Hack to get {@link CommandManager} working under {@link CommandCallable}.
@ -51,20 +52,25 @@ public class CommandManagerCallable implements CommandCallable {
@Override @Override
public Object call(String arguments, CommandLocals locals, String[] parentCommands) throws CommandException { public Object call(String arguments, CommandLocals locals, String[] parentCommands) throws CommandException {
manager.injectValue(Key.get(Actor.class), () -> locals.get(Actor.class)); manager.injectValue(Key.get(Actor.class), access -> Optional.of(locals.get(Actor.class)));
manager.injectValue(Key.get(Player.class), () -> getPlayer(locals)); manager.injectValue(Key.get(Player.class), access -> {
manager.injectValue(Key.get(LocalSession.class), () -> { Actor actor = locals.get(Actor.class);
Player sender = getPlayer(locals); return actor instanceof Player ? Optional.of(((Player) actor)) : Optional.empty();
return worldEdit.getSessionManager().get(sender);
}); });
manager.injectValue(Key.get(EditSession.class), () -> { manager.injectValue(Key.get(LocalSession.class), access ->
Player sender = getPlayer(locals); access.injectedValue(Key.get(Player.class))
.map(worldEdit.getSessionManager()::get)
);
manager.injectValue(Key.get(EditSession.class), access ->
access.injectedValue(Key.get(Player.class))
.map(sender -> {
LocalSession session = worldEdit.getSessionManager().get(sender); LocalSession session = worldEdit.getSessionManager().get(sender);
EditSession editSession = session.createEditSession(sender); EditSession editSession = session.createEditSession(sender);
editSession.enableStandardMode(); editSession.enableStandardMode();
session.tellVersion(sender); session.tellVersion(sender);
return editSession; return editSession;
}); })
);
return manager.execute(Splitter.on(' ').splitToList(arguments)); return manager.execute(Splitter.on(' ').splitToList(arguments));
} }