3
0
Mirror von https://github.com/IntellectualSites/FastAsyncWorldEdit.git synchronisiert 2024-12-26 02:50:06 +01:00

Changed command pipeline to use Actor over LocalPlayer.

Dieser Commit ist enthalten in:
sk89q 2014-06-27 17:55:39 -07:00
Ursprung aaf4c61251
Commit ebe2bc6ae2
11 geänderte Dateien mit 127 neuen und 138 gelöschten Zeilen

Datei anzeigen

@ -19,17 +19,29 @@
package com.sk89q.worldedit.bukkit;
import com.sk89q.worldedit.*;
import com.sk89q.worldedit.extent.inventory.BlockBag;
import com.sk89q.worldedit.util.Location;
import com.sk89q.worldedit.LocalWorld;
import com.sk89q.worldedit.PlayerNeededException;
import com.sk89q.worldedit.WorldEditPermissionException;
import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.internal.cui.CUIEvent;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class BukkitCommandSender extends LocalPlayer {
import java.io.File;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
class BukkitCommandSender implements Actor {
private CommandSender sender;
private WorldEditPlugin plugin;
public BukkitCommandSender(WorldEditPlugin plugin, CommandSender sender) {
BukkitCommandSender(WorldEditPlugin plugin, CommandSender sender) {
checkNotNull(plugin);
checkNotNull(sender);
checkArgument(!(sender instanceof Player), "Cannot wrap a player");
this.plugin = plugin;
this.sender = sender;
}
@ -67,6 +79,11 @@ public class BukkitCommandSender extends LocalPlayer {
}
}
@Override
public boolean canDestroyBedrock() {
return true;
}
@Override
public String[] getGroups() {
return new String[0];
@ -74,31 +91,30 @@ public class BukkitCommandSender extends LocalPlayer {
@Override
public boolean hasPermission(String perm) {
if (!plugin.getLocalConfiguration().noOpPermissions && sender.isOp()) {
return true;
}
return true;
}
return plugin.getPermissionsResolver().hasPermission(null, sender.getName(), perm);
@Override
public void checkPermission(String permission) throws WorldEditPermissionException {
}
@Override
public boolean isPlayer() {
return sender instanceof Player;
return false;
}
@Override
public int getItemInHand() {
throw new PlayerNeededException();
public File openFileOpenDialog(String[] extensions) {
return null;
}
@Override
public Location getLocation() {
throw new PlayerNeededException();
public File openFileSaveDialog(String[] extensions) {
return null;
}
@Override
public WorldVector getPosition() {
throw new PlayerNeededException();
public void dispatchCUIEvent(CUIEvent event) {
}
@Override
@ -106,28 +122,4 @@ public class BukkitCommandSender extends LocalPlayer {
throw new PlayerNeededException();
}
@Override
public double getPitch() {
throw new PlayerNeededException();
}
@Override
public double getYaw() {
throw new PlayerNeededException();
}
@Override
public void giveItem(int type, int amt) {
throw new PlayerNeededException();
}
@Override
public void setPosition(Vector pos, float pitch, float yaw) {
throw new PlayerNeededException();
}
@Override
public BlockBag getInventoryBlockBag() {
throw new PlayerNeededException();
}
}

Datei anzeigen

@ -26,7 +26,9 @@ import com.sk89q.worldedit.bukkit.selections.CuboidSelection;
import com.sk89q.worldedit.bukkit.selections.CylinderSelection;
import com.sk89q.worldedit.bukkit.selections.Polygonal2DSelection;
import com.sk89q.worldedit.bukkit.selections.Selection;
import com.sk89q.worldedit.event.platform.CommandEvent;
import com.sk89q.worldedit.event.platform.PlatformReadyEvent;
import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.extent.inventory.BlockBag;
import com.sk89q.worldedit.regions.*;
import org.bukkit.World;
@ -214,20 +216,16 @@ public class WorldEditPlugin extends JavaPlugin {
}
}
/**
* Called on WorldEdit command.
*/
@Override
public boolean onCommand(CommandSender sender, org.bukkit.command.Command cmd,
String commandLabel, String[] args) {
public boolean onCommand(CommandSender sender, org.bukkit.command.Command cmd, String commandLabel, String[] args) {
// Add the command to the array because the underlying command handling
// code of WorldEdit expects it
String[] split = new String[args.length + 1];
System.arraycopy(args, 0, split, 1, args.length);
split[0] = "/" + cmd.getName();
controller.handleCommand(wrapCommandSender(sender), split);
CommandEvent event = new CommandEvent(wrapCommandSender(sender), split);
getWorldEdit().getEventBus().post(event);
return true;
}
@ -334,7 +332,7 @@ public class WorldEditPlugin extends JavaPlugin {
return new BukkitPlayer(this, this.server, player);
}
public LocalPlayer wrapCommandSender(CommandSender sender) {
public Actor wrapCommandSender(CommandSender sender) {
if (sender instanceof Player) {
return wrapPlayer((Player) sender);
}

Datei anzeigen

@ -395,8 +395,7 @@ public class LocalSession {
* @return position
* @throws IncompleteRegionException
*/
public Vector getPlacementPosition(LocalPlayer player)
throws IncompleteRegionException {
public Vector getPlacementPosition(Player player) throws IncompleteRegionException {
if (!placeAtPos1) {
return player.getBlockIn();
}

Datei anzeigen

@ -29,6 +29,7 @@ import com.sk89q.worldedit.event.platform.CommandEvent;
import com.sk89q.worldedit.event.platform.InputType;
import com.sk89q.worldedit.event.platform.PlayerInputEvent;
import com.sk89q.worldedit.extension.input.ParserContext;
import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.extension.platform.Platform;
import com.sk89q.worldedit.extension.platform.PlatformManager;
import com.sk89q.worldedit.extension.registry.BlockRegistry;
@ -626,7 +627,7 @@ public class WorldEdit {
* @param player the player
* @param editSession the edit session
*/
public void flushBlockBag(LocalPlayer player, EditSession editSession) {
public void flushBlockBag(Actor actor, EditSession editSession) {
BlockBag blockBag = editSession.getBlockBag();
if (blockBag != null) {
@ -635,7 +636,7 @@ public class WorldEdit {
Map<Integer, Integer> missingBlocks = editSession.popMissingBlocks();
if (missingBlocks.size() > 0) {
if (!missingBlocks.isEmpty()) {
StringBuilder str = new StringBuilder();
str.append("Missing these blocks: ");
int size = missingBlocks.size();
@ -657,7 +658,7 @@ public class WorldEdit {
}
}
player.printError(str.toString());
actor.printError(str.toString());
}
}

Datei anzeigen

@ -22,9 +22,9 @@ package com.sk89q.worldedit.command;
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.Console;
import com.sk89q.worldedit.*;
import com.sk89q.worldedit.blocks.ItemType;
import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.masks.Mask;
/**
@ -151,9 +151,7 @@ public class GeneralCommands {
min = 1,
max = 1
)
@Console
public void searchItem(CommandContext args, LocalSession session, LocalPlayer player,
EditSession editSession) throws WorldEditException {
public void searchItem(Actor actor, CommandContext args) throws WorldEditException {
String query = args.getString(0).trim().toLowerCase();
boolean blocksOnly = args.hasFlag('b');
@ -165,9 +163,9 @@ public class GeneralCommands {
ItemType type = ItemType.fromID(id);
if (type != null) {
player.print("#" + type.getID() + " (" + type.getName() + ")");
actor.print("#" + type.getID() + " (" + type.getName() + ")");
} else {
player.printError("No item found by ID " + id);
actor.printError("No item found by ID " + id);
}
return;
@ -175,26 +173,26 @@ public class GeneralCommands {
}
if (query.length() <= 2) {
player.printError("Enter a longer search string (len > 2).");
actor.printError("Enter a longer search string (len > 2).");
return;
}
if (!blocksOnly && !itemsOnly) {
player.print("Searching for: " + query);
actor.print("Searching for: " + query);
} else if (blocksOnly && itemsOnly) {
player.printError("You cannot use both the 'b' and 'i' flags simultaneously.");
actor.printError("You cannot use both the 'b' and 'i' flags simultaneously.");
return;
} else if (blocksOnly) {
player.print("Searching for blocks: " + query);
actor.print("Searching for blocks: " + query);
} else {
player.print("Searching for items: " + query);
actor.print("Searching for items: " + query);
}
int found = 0;
for (ItemType type : ItemType.values()) {
if (found >= 15) {
player.print("Too many results!");
actor.print("Too many results!");
break;
}
@ -208,7 +206,7 @@ public class GeneralCommands {
for (String alias : type.getAliases()) {
if (alias.contains(query)) {
player.print("#" + type.getID() + " (" + type.getName() + ")");
actor.print("#" + type.getID() + " (" + type.getName() + ")");
++found;
break;
}
@ -216,7 +214,7 @@ public class GeneralCommands {
}
if (found == 0) {
player.printError("No items found.");
actor.printError("No items found.");
}
}

Datei anzeigen

@ -21,6 +21,7 @@ package com.sk89q.worldedit.command;
import com.sk89q.minecraft.util.commands.*;
import com.sk89q.worldedit.*;
import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.schematic.SchematicFormat;
import com.sk89q.worldedit.world.DataException;
@ -207,11 +208,9 @@ public class SchematicCommands {
desc = "List available schematic formats",
max = 0
)
@Console
@CommandPermissions("worldedit.schematic.formats")
public void formats(CommandContext args, LocalSession session, LocalPlayer player,
EditSession editSession) throws WorldEditException {
player.print("Available schematic formats (Name: Lookup names)");
public void formats(Actor actor) throws WorldEditException {
actor.print("Available schematic formats (Name: Lookup names)");
StringBuilder builder;
boolean first = true;
for (SchematicFormat format : SchematicFormat.getFormats()) {
@ -225,7 +224,7 @@ public class SchematicCommands {
first = false;
}
first = true;
player.print(builder.toString());
actor.print(builder.toString());
}
}
@ -238,10 +237,8 @@ public class SchematicCommands {
" -d sorts by date, oldest first\n" +
" -n sorts by date, newest first\n"
)
@Console
@CommandPermissions("worldedit.schematic.list")
public void list(CommandContext args, LocalSession session, LocalPlayer player,
EditSession editSession) throws WorldEditException {
public void list(Actor actor, CommandContext args) throws WorldEditException {
File dir = we.getWorkingDirectoryFile(we.getConfiguration().saveDir);
File[] files = dir.listFiles(new FileFilter(){
@Override
@ -273,8 +270,8 @@ public class SchematicCommands {
}
});
player.print("Available schematics (Filename (Format)):");
player.print(listFiles("", files));
actor.print("Available schematics (Filename (Format)):");
actor.print(listFiles("", files));
}
private String listFiles(String prefix, File[] files) {

Datei anzeigen

@ -23,6 +23,8 @@ import com.sk89q.minecraft.util.commands.*;
import com.sk89q.worldedit.*;
import com.sk89q.worldedit.LocalWorld.KillFlags;
import com.sk89q.worldedit.blocks.BaseBlock;
import com.sk89q.worldedit.entity.Player;
import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.patterns.Pattern;
import com.sk89q.worldedit.patterns.SingleBlockPattern;
import com.sk89q.worldedit.regions.CuboidRegion;
@ -30,6 +32,7 @@ import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.util.command.CommandMapping;
import com.sk89q.worldedit.util.command.Description;
import com.sk89q.worldedit.util.command.Dispatcher;
import com.sk89q.worldedit.util.command.parametric.Optional;
import com.sk89q.worldedit.world.World;
import java.util.Comparator;
@ -367,9 +370,7 @@ public class UtilityCommands {
)
@CommandPermissions("worldedit.butcher")
@Logging(PLACEMENT)
@Console
public void butcher(CommandContext args, LocalSession session, LocalPlayer player,
EditSession editSession) throws WorldEditException {
public void butcher(Actor actor, @Optional Player player, @Optional LocalSession session, CommandContext args) throws WorldEditException {
LocalConfiguration config = we.getConfiguration();
@ -388,7 +389,7 @@ public class UtilityCommands {
}
}
FlagContainer flags = new FlagContainer(player);
FlagContainer flags = new FlagContainer(actor);
flags.or(KillFlags.FRIENDLY , args.hasFlag('f')); // No permission check here. Flags will instead be filtered by the subsequent calls.
flags.or(KillFlags.PETS , args.hasFlag('p'), "worldedit.butcher.pets");
flags.or(KillFlags.NPCS , args.hasFlag('n'), "worldedit.butcher.npcs");
@ -400,7 +401,7 @@ public class UtilityCommands {
// If you add flags here, please add them to com.sk89q.worldedit.commands.BrushCommands.butcherBrush() as well
int killed;
if (player.isPlayer()) {
if (player != null) {
killed = player.getWorld().killMobs(session.getPlacementPosition(player), radius, flags.flags);
} else {
killed = 0;
@ -410,16 +411,16 @@ public class UtilityCommands {
}
if (radius < 0) {
player.print("Killed " + killed + " mobs.");
actor.print("Killed " + killed + " mobs.");
} else {
player.print("Killed " + killed + " mobs in a radius of " + radius + ".");
actor.print("Killed " + killed + " mobs in a radius of " + radius + ".");
}
}
public static class FlagContainer {
private final LocalPlayer player;
private final Actor player;
public int flags = 0;
public FlagContainer(LocalPlayer player) {
public FlagContainer(Actor player) {
this.player = player;
}
@ -445,15 +446,13 @@ public class UtilityCommands {
)
@CommandPermissions("worldedit.remove")
@Logging(PLACEMENT)
@Console
public void remove(CommandContext args, LocalSession session, LocalPlayer player,
EditSession editSession) throws WorldEditException {
public void remove(Actor actor, @Optional Player player, @Optional LocalSession session, CommandContext args) throws WorldEditException {
String typeStr = args.getString(0);
int radius = args.getInteger(1);
if (radius < -1) {
player.printError("Use -1 to remove all entities in loaded chunks");
actor.printError("Use -1 to remove all entities in loaded chunks");
return;
}
@ -483,12 +482,12 @@ public class UtilityCommands {
} else if (typeStr.matches("xp")) {
type = EntityType.XP_ORBS;
} else {
player.printError("Acceptable types: projectiles, items, paintings, itemframes, boats, minecarts, tnt, xp, or all");
actor.printError("Acceptable types: projectiles, items, paintings, itemframes, boats, minecarts, tnt, xp, or all");
return;
}
int removed = 0;
if (player.isPlayer()) {
if (player != null) {
Vector origin = session.getPlacementPosition(player);
removed = player.getWorld().removeEntities(type, origin, radius);
} else {
@ -506,15 +505,12 @@ public class UtilityCommands {
min = 0,
max = -1
)
@Console
@CommandPermissions("worldedit.help")
public void help(CommandContext args, LocalSession session, LocalPlayer player,
EditSession editSession) throws WorldEditException {
help(args, we, session, player, editSession);
public void help(Actor actor, CommandContext args) throws WorldEditException {
help(args, we, actor);
}
public static void help(CommandContext args, WorldEdit we, LocalSession session, LocalPlayer player, EditSession editSession) {
public static void help(CommandContext args, WorldEdit we, Actor actor) {
final Dispatcher dispatcher = we.getPlatformManager().getCommandManager().getDispatcher();
if (args.argsLength() == 0) {
@ -542,7 +538,7 @@ public class UtilityCommands {
first = false;
}
player.print(sb.toString());
actor.print(sb.toString());
return;
}
@ -551,22 +547,22 @@ public class UtilityCommands {
CommandMapping mapping = dispatcher.get(command);
if (mapping == null) {
player.printError("Unknown command '" + command + "'.");
actor.printError("Unknown command '" + command + "'.");
return;
}
Description description = mapping.getDescription();
if (description.getUsage() != null) {
player.printDebug("Usage: " + description.getUsage());
actor.printDebug("Usage: " + description.getUsage());
}
if (description.getHelp() != null) {
player.print(description.getHelp());
actor.print(description.getHelp());
} else if (description.getDescription() != null) {
player.print(description.getDescription());
actor.print(description.getDescription());
} else {
player.print("No further help is available.");
actor.print("No further help is available.");
}
}
}

Datei anzeigen

@ -22,8 +22,8 @@ package com.sk89q.worldedit.command;
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.Console;
import com.sk89q.worldedit.*;
import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.extension.platform.Capability;
import com.sk89q.worldedit.extension.platform.Platform;
import com.sk89q.worldedit.extension.platform.PlatformManager;
@ -49,24 +49,21 @@ public class WorldEditCommands {
min = 0,
max = 0
)
@Console
public void version(CommandContext args, LocalSession session, LocalPlayer player,
EditSession editSession) throws WorldEditException {
player.print("WorldEdit version " + WorldEdit.getVersion());
player.print("https://github.com/sk89q/worldedit/");
public void version(Actor actor) throws WorldEditException {
actor.print("WorldEdit version " + WorldEdit.getVersion());
actor.print("https://github.com/sk89q/worldedit/");
PlatformManager pm = we.getPlatformManager();
player.printDebug("----------- Platforms -----------");
actor.printDebug("----------- Platforms -----------");
for (Platform platform : pm.getPlatforms()) {
player.printDebug(String.format("* %s (%s)", platform.getPlatformName(), platform.getPlatformVersion()));
actor.printDebug(String.format("* %s (%s)", platform.getPlatformName(), platform.getPlatformVersion()));
}
player.printDebug("----------- Capabilities -----------");
actor.printDebug("----------- Capabilities -----------");
for (Capability capability : Capability.values()) {
Platform platform = pm.queryCapability(capability);
player.printDebug(String.format("%s: %s", capability.name(), platform != null ? platform.getPlatformName() : "NONE"));
actor.printDebug(String.format("%s: %s", capability.name(), platform != null ? platform.getPlatformName() : "NONE"));
}
}
@ -78,12 +75,9 @@ public class WorldEditCommands {
max = 0
)
@CommandPermissions("worldedit.reload")
@Console
public void reload(CommandContext args, LocalSession session, LocalPlayer player,
EditSession editSession) throws WorldEditException {
public void reload(Actor actor) throws WorldEditException {
we.getServer().reload();
player.print("Configuration reloaded!");
actor.print("Configuration reloaded!");
}
@Command(
@ -106,7 +100,6 @@ public class WorldEditCommands {
min = 1,
max = 1
)
@Console
public void tz(CommandContext args, LocalSession session, LocalPlayer player,
EditSession editSession) throws WorldEditException {
TimeZone tz = TimeZone.getTimeZone(args.getString(0));
@ -124,10 +117,7 @@ public class WorldEditCommands {
max = -1
)
@CommandPermissions("worldedit.help")
@Console
public void help(CommandContext args, LocalSession session, LocalPlayer player,
EditSession editSession) throws WorldEditException {
UtilityCommands.help(args, we, session, player, editSession);
public void help(Actor actor, CommandContext args) throws WorldEditException {
UtilityCommands.help(args, we, actor);
}
}

Datei anzeigen

@ -19,8 +19,8 @@
package com.sk89q.worldedit.event.platform;
import com.sk89q.worldedit.LocalPlayer;
import com.sk89q.worldedit.event.AbstractCancellable;
import com.sk89q.worldedit.extension.platform.Actor;
import static com.google.common.base.Preconditions.checkNotNull;
@ -29,30 +29,30 @@ import static com.google.common.base.Preconditions.checkNotNull;
*/
public class CommandEvent extends AbstractCancellable {
private final LocalPlayer player;
private final Actor actor;
private final String[] args;
/**
* Create a new instance.
*
* @param player the player
* @param actor the player
* @param args the arguments
*/
public CommandEvent(LocalPlayer player, String[] args) {
checkNotNull(player);
public CommandEvent(Actor actor, String[] args) {
checkNotNull(actor);
checkNotNull(args);
this.player = player;
this.actor = actor;
this.args = args;
}
/**
* Get the player.
* Get the actor that issued the command.
*
* @return the player
* @return the actor that issued the command
*/
public LocalPlayer getPlayer() {
return player;
public Actor getActor() {
return actor;
}
/**

Datei anzeigen

@ -192,7 +192,7 @@ public final class CommandManager {
public void handleCommand(CommandEvent event) {
Request.reset();
Actor actor = event.getPlayer();
Actor actor = event.getActor();
String split[] = commandDetection(event.getArguments());
// No command found!
@ -241,7 +241,7 @@ public final class CommandManager {
}
}
worldEdit.flushBlockBag(event.getPlayer(), editSession);
worldEdit.flushBlockBag(actor, editSession);
}
}

Datei anzeigen

@ -97,6 +97,24 @@ public class WorldEditBinding extends BindingHelper {
return worldEdit.getSessionManager().get(sender);
}
/**
* Gets an {@link Actor} from a {@link ArgumentStack}.
*
* @param context the context
* @return a local player
* @throws ParameterException on error
*/
@BindingMatch(type = Actor.class,
behavior = BindingBehavior.PROVIDES)
public Actor getActor(ArgumentStack context) throws ParameterException {
Actor sender = context.getContext().getLocals().get(Actor.class);
if (sender == null) {
throw new ParameterException("Missing 'Actor'");
} else {
return sender;
}
}
/**
* Gets an {@link Player} from a {@link ArgumentStack}.
*