mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2024-11-16 17:16:11 +00:00
Changed command pipeline to use Actor over LocalPlayer.
This commit is contained in:
parent
aaf4c61251
commit
ebe2bc6ae2
@ -19,17 +19,29 @@
|
|||||||
|
|
||||||
package com.sk89q.worldedit.bukkit;
|
package com.sk89q.worldedit.bukkit;
|
||||||
|
|
||||||
import com.sk89q.worldedit.*;
|
import com.sk89q.worldedit.LocalWorld;
|
||||||
import com.sk89q.worldedit.extent.inventory.BlockBag;
|
import com.sk89q.worldedit.PlayerNeededException;
|
||||||
import com.sk89q.worldedit.util.Location;
|
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.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
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 CommandSender sender;
|
||||||
private WorldEditPlugin plugin;
|
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.plugin = plugin;
|
||||||
this.sender = sender;
|
this.sender = sender;
|
||||||
}
|
}
|
||||||
@ -67,6 +79,11 @@ public class BukkitCommandSender extends LocalPlayer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean canDestroyBedrock() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String[] getGroups() {
|
public String[] getGroups() {
|
||||||
return new String[0];
|
return new String[0];
|
||||||
@ -74,31 +91,30 @@ public class BukkitCommandSender extends LocalPlayer {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hasPermission(String perm) {
|
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
|
@Override
|
||||||
public boolean isPlayer() {
|
public boolean isPlayer() {
|
||||||
return sender instanceof Player;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getItemInHand() {
|
public File openFileOpenDialog(String[] extensions) {
|
||||||
throw new PlayerNeededException();
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Location getLocation() {
|
public File openFileSaveDialog(String[] extensions) {
|
||||||
throw new PlayerNeededException();
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public WorldVector getPosition() {
|
public void dispatchCUIEvent(CUIEvent event) {
|
||||||
throw new PlayerNeededException();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -106,28 +122,4 @@ public class BukkitCommandSender extends LocalPlayer {
|
|||||||
throw new PlayerNeededException();
|
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();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -26,7 +26,9 @@ import com.sk89q.worldedit.bukkit.selections.CuboidSelection;
|
|||||||
import com.sk89q.worldedit.bukkit.selections.CylinderSelection;
|
import com.sk89q.worldedit.bukkit.selections.CylinderSelection;
|
||||||
import com.sk89q.worldedit.bukkit.selections.Polygonal2DSelection;
|
import com.sk89q.worldedit.bukkit.selections.Polygonal2DSelection;
|
||||||
import com.sk89q.worldedit.bukkit.selections.Selection;
|
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.event.platform.PlatformReadyEvent;
|
||||||
|
import com.sk89q.worldedit.extension.platform.Actor;
|
||||||
import com.sk89q.worldedit.extent.inventory.BlockBag;
|
import com.sk89q.worldedit.extent.inventory.BlockBag;
|
||||||
import com.sk89q.worldedit.regions.*;
|
import com.sk89q.worldedit.regions.*;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
@ -214,20 +216,16 @@ public class WorldEditPlugin extends JavaPlugin {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Called on WorldEdit command.
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCommand(CommandSender sender, org.bukkit.command.Command cmd,
|
public boolean onCommand(CommandSender sender, org.bukkit.command.Command cmd, String commandLabel, String[] args) {
|
||||||
String commandLabel, String[] args) {
|
|
||||||
|
|
||||||
// Add the command to the array because the underlying command handling
|
// Add the command to the array because the underlying command handling
|
||||||
// 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] = "/" + cmd.getName();
|
split[0] = "/" + cmd.getName();
|
||||||
|
|
||||||
controller.handleCommand(wrapCommandSender(sender), split);
|
CommandEvent event = new CommandEvent(wrapCommandSender(sender), split);
|
||||||
|
getWorldEdit().getEventBus().post(event);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -334,7 +332,7 @@ public class WorldEditPlugin extends JavaPlugin {
|
|||||||
return new BukkitPlayer(this, this.server, player);
|
return new BukkitPlayer(this, this.server, player);
|
||||||
}
|
}
|
||||||
|
|
||||||
public LocalPlayer wrapCommandSender(CommandSender sender) {
|
public Actor wrapCommandSender(CommandSender sender) {
|
||||||
if (sender instanceof Player) {
|
if (sender instanceof Player) {
|
||||||
return wrapPlayer((Player) sender);
|
return wrapPlayer((Player) sender);
|
||||||
}
|
}
|
||||||
|
@ -395,8 +395,7 @@ public class LocalSession {
|
|||||||
* @return position
|
* @return position
|
||||||
* @throws IncompleteRegionException
|
* @throws IncompleteRegionException
|
||||||
*/
|
*/
|
||||||
public Vector getPlacementPosition(LocalPlayer player)
|
public Vector getPlacementPosition(Player player) throws IncompleteRegionException {
|
||||||
throws IncompleteRegionException {
|
|
||||||
if (!placeAtPos1) {
|
if (!placeAtPos1) {
|
||||||
return player.getBlockIn();
|
return player.getBlockIn();
|
||||||
}
|
}
|
||||||
|
@ -29,6 +29,7 @@ import com.sk89q.worldedit.event.platform.CommandEvent;
|
|||||||
import com.sk89q.worldedit.event.platform.InputType;
|
import com.sk89q.worldedit.event.platform.InputType;
|
||||||
import com.sk89q.worldedit.event.platform.PlayerInputEvent;
|
import com.sk89q.worldedit.event.platform.PlayerInputEvent;
|
||||||
import com.sk89q.worldedit.extension.input.ParserContext;
|
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.Platform;
|
||||||
import com.sk89q.worldedit.extension.platform.PlatformManager;
|
import com.sk89q.worldedit.extension.platform.PlatformManager;
|
||||||
import com.sk89q.worldedit.extension.registry.BlockRegistry;
|
import com.sk89q.worldedit.extension.registry.BlockRegistry;
|
||||||
@ -626,7 +627,7 @@ public class WorldEdit {
|
|||||||
* @param player the player
|
* @param player the player
|
||||||
* @param editSession the edit session
|
* @param editSession the edit session
|
||||||
*/
|
*/
|
||||||
public void flushBlockBag(LocalPlayer player, EditSession editSession) {
|
public void flushBlockBag(Actor actor, EditSession editSession) {
|
||||||
BlockBag blockBag = editSession.getBlockBag();
|
BlockBag blockBag = editSession.getBlockBag();
|
||||||
|
|
||||||
if (blockBag != null) {
|
if (blockBag != null) {
|
||||||
@ -635,7 +636,7 @@ public class WorldEdit {
|
|||||||
|
|
||||||
Map<Integer, Integer> missingBlocks = editSession.popMissingBlocks();
|
Map<Integer, Integer> missingBlocks = editSession.popMissingBlocks();
|
||||||
|
|
||||||
if (missingBlocks.size() > 0) {
|
if (!missingBlocks.isEmpty()) {
|
||||||
StringBuilder str = new StringBuilder();
|
StringBuilder str = new StringBuilder();
|
||||||
str.append("Missing these blocks: ");
|
str.append("Missing these blocks: ");
|
||||||
int size = missingBlocks.size();
|
int size = missingBlocks.size();
|
||||||
@ -657,7 +658,7 @@ public class WorldEdit {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
player.printError(str.toString());
|
actor.printError(str.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,9 +22,9 @@ package com.sk89q.worldedit.command;
|
|||||||
import com.sk89q.minecraft.util.commands.Command;
|
import com.sk89q.minecraft.util.commands.Command;
|
||||||
import com.sk89q.minecraft.util.commands.CommandContext;
|
import com.sk89q.minecraft.util.commands.CommandContext;
|
||||||
import com.sk89q.minecraft.util.commands.CommandPermissions;
|
import com.sk89q.minecraft.util.commands.CommandPermissions;
|
||||||
import com.sk89q.minecraft.util.commands.Console;
|
|
||||||
import com.sk89q.worldedit.*;
|
import com.sk89q.worldedit.*;
|
||||||
import com.sk89q.worldedit.blocks.ItemType;
|
import com.sk89q.worldedit.blocks.ItemType;
|
||||||
|
import com.sk89q.worldedit.extension.platform.Actor;
|
||||||
import com.sk89q.worldedit.masks.Mask;
|
import com.sk89q.worldedit.masks.Mask;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -151,9 +151,7 @@ public class GeneralCommands {
|
|||||||
min = 1,
|
min = 1,
|
||||||
max = 1
|
max = 1
|
||||||
)
|
)
|
||||||
@Console
|
public void searchItem(Actor actor, CommandContext args) throws WorldEditException {
|
||||||
public void searchItem(CommandContext args, LocalSession session, LocalPlayer player,
|
|
||||||
EditSession editSession) throws WorldEditException {
|
|
||||||
|
|
||||||
String query = args.getString(0).trim().toLowerCase();
|
String query = args.getString(0).trim().toLowerCase();
|
||||||
boolean blocksOnly = args.hasFlag('b');
|
boolean blocksOnly = args.hasFlag('b');
|
||||||
@ -165,9 +163,9 @@ public class GeneralCommands {
|
|||||||
ItemType type = ItemType.fromID(id);
|
ItemType type = ItemType.fromID(id);
|
||||||
|
|
||||||
if (type != null) {
|
if (type != null) {
|
||||||
player.print("#" + type.getID() + " (" + type.getName() + ")");
|
actor.print("#" + type.getID() + " (" + type.getName() + ")");
|
||||||
} else {
|
} else {
|
||||||
player.printError("No item found by ID " + id);
|
actor.printError("No item found by ID " + id);
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
@ -175,26 +173,26 @@ public class GeneralCommands {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (query.length() <= 2) {
|
if (query.length() <= 2) {
|
||||||
player.printError("Enter a longer search string (len > 2).");
|
actor.printError("Enter a longer search string (len > 2).");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!blocksOnly && !itemsOnly) {
|
if (!blocksOnly && !itemsOnly) {
|
||||||
player.print("Searching for: " + query);
|
actor.print("Searching for: " + query);
|
||||||
} else if (blocksOnly && itemsOnly) {
|
} 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;
|
return;
|
||||||
} else if (blocksOnly) {
|
} else if (blocksOnly) {
|
||||||
player.print("Searching for blocks: " + query);
|
actor.print("Searching for blocks: " + query);
|
||||||
} else {
|
} else {
|
||||||
player.print("Searching for items: " + query);
|
actor.print("Searching for items: " + query);
|
||||||
}
|
}
|
||||||
|
|
||||||
int found = 0;
|
int found = 0;
|
||||||
|
|
||||||
for (ItemType type : ItemType.values()) {
|
for (ItemType type : ItemType.values()) {
|
||||||
if (found >= 15) {
|
if (found >= 15) {
|
||||||
player.print("Too many results!");
|
actor.print("Too many results!");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -208,7 +206,7 @@ public class GeneralCommands {
|
|||||||
|
|
||||||
for (String alias : type.getAliases()) {
|
for (String alias : type.getAliases()) {
|
||||||
if (alias.contains(query)) {
|
if (alias.contains(query)) {
|
||||||
player.print("#" + type.getID() + " (" + type.getName() + ")");
|
actor.print("#" + type.getID() + " (" + type.getName() + ")");
|
||||||
++found;
|
++found;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -216,7 +214,7 @@ public class GeneralCommands {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (found == 0) {
|
if (found == 0) {
|
||||||
player.printError("No items found.");
|
actor.printError("No items found.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,6 +21,7 @@ package com.sk89q.worldedit.command;
|
|||||||
|
|
||||||
import com.sk89q.minecraft.util.commands.*;
|
import com.sk89q.minecraft.util.commands.*;
|
||||||
import com.sk89q.worldedit.*;
|
import com.sk89q.worldedit.*;
|
||||||
|
import com.sk89q.worldedit.extension.platform.Actor;
|
||||||
import com.sk89q.worldedit.schematic.SchematicFormat;
|
import com.sk89q.worldedit.schematic.SchematicFormat;
|
||||||
import com.sk89q.worldedit.world.DataException;
|
import com.sk89q.worldedit.world.DataException;
|
||||||
|
|
||||||
@ -207,11 +208,9 @@ public class SchematicCommands {
|
|||||||
desc = "List available schematic formats",
|
desc = "List available schematic formats",
|
||||||
max = 0
|
max = 0
|
||||||
)
|
)
|
||||||
@Console
|
|
||||||
@CommandPermissions("worldedit.schematic.formats")
|
@CommandPermissions("worldedit.schematic.formats")
|
||||||
public void formats(CommandContext args, LocalSession session, LocalPlayer player,
|
public void formats(Actor actor) throws WorldEditException {
|
||||||
EditSession editSession) throws WorldEditException {
|
actor.print("Available schematic formats (Name: Lookup names)");
|
||||||
player.print("Available schematic formats (Name: Lookup names)");
|
|
||||||
StringBuilder builder;
|
StringBuilder builder;
|
||||||
boolean first = true;
|
boolean first = true;
|
||||||
for (SchematicFormat format : SchematicFormat.getFormats()) {
|
for (SchematicFormat format : SchematicFormat.getFormats()) {
|
||||||
@ -225,7 +224,7 @@ public class SchematicCommands {
|
|||||||
first = false;
|
first = false;
|
||||||
}
|
}
|
||||||
first = true;
|
first = true;
|
||||||
player.print(builder.toString());
|
actor.print(builder.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -238,10 +237,8 @@ public class SchematicCommands {
|
|||||||
" -d sorts by date, oldest first\n" +
|
" -d sorts by date, oldest first\n" +
|
||||||
" -n sorts by date, newest first\n"
|
" -n sorts by date, newest first\n"
|
||||||
)
|
)
|
||||||
@Console
|
|
||||||
@CommandPermissions("worldedit.schematic.list")
|
@CommandPermissions("worldedit.schematic.list")
|
||||||
public void list(CommandContext args, LocalSession session, LocalPlayer player,
|
public void list(Actor actor, CommandContext args) throws WorldEditException {
|
||||||
EditSession editSession) throws WorldEditException {
|
|
||||||
File dir = we.getWorkingDirectoryFile(we.getConfiguration().saveDir);
|
File dir = we.getWorkingDirectoryFile(we.getConfiguration().saveDir);
|
||||||
File[] files = dir.listFiles(new FileFilter(){
|
File[] files = dir.listFiles(new FileFilter(){
|
||||||
@Override
|
@Override
|
||||||
@ -273,8 +270,8 @@ public class SchematicCommands {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
player.print("Available schematics (Filename (Format)):");
|
actor.print("Available schematics (Filename (Format)):");
|
||||||
player.print(listFiles("", files));
|
actor.print(listFiles("", files));
|
||||||
}
|
}
|
||||||
|
|
||||||
private String listFiles(String prefix, File[] files) {
|
private String listFiles(String prefix, File[] files) {
|
||||||
|
@ -23,6 +23,8 @@ import com.sk89q.minecraft.util.commands.*;
|
|||||||
import com.sk89q.worldedit.*;
|
import com.sk89q.worldedit.*;
|
||||||
import com.sk89q.worldedit.LocalWorld.KillFlags;
|
import com.sk89q.worldedit.LocalWorld.KillFlags;
|
||||||
import com.sk89q.worldedit.blocks.BaseBlock;
|
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.Pattern;
|
||||||
import com.sk89q.worldedit.patterns.SingleBlockPattern;
|
import com.sk89q.worldedit.patterns.SingleBlockPattern;
|
||||||
import com.sk89q.worldedit.regions.CuboidRegion;
|
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.CommandMapping;
|
||||||
import com.sk89q.worldedit.util.command.Description;
|
import com.sk89q.worldedit.util.command.Description;
|
||||||
import com.sk89q.worldedit.util.command.Dispatcher;
|
import com.sk89q.worldedit.util.command.Dispatcher;
|
||||||
|
import com.sk89q.worldedit.util.command.parametric.Optional;
|
||||||
import com.sk89q.worldedit.world.World;
|
import com.sk89q.worldedit.world.World;
|
||||||
|
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
@ -367,9 +370,7 @@ public class UtilityCommands {
|
|||||||
)
|
)
|
||||||
@CommandPermissions("worldedit.butcher")
|
@CommandPermissions("worldedit.butcher")
|
||||||
@Logging(PLACEMENT)
|
@Logging(PLACEMENT)
|
||||||
@Console
|
public void butcher(Actor actor, @Optional Player player, @Optional LocalSession session, CommandContext args) throws WorldEditException {
|
||||||
public void butcher(CommandContext args, LocalSession session, LocalPlayer player,
|
|
||||||
EditSession editSession) throws WorldEditException {
|
|
||||||
|
|
||||||
LocalConfiguration config = we.getConfiguration();
|
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.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.PETS , args.hasFlag('p'), "worldedit.butcher.pets");
|
||||||
flags.or(KillFlags.NPCS , args.hasFlag('n'), "worldedit.butcher.npcs");
|
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
|
// If you add flags here, please add them to com.sk89q.worldedit.commands.BrushCommands.butcherBrush() as well
|
||||||
|
|
||||||
int killed;
|
int killed;
|
||||||
if (player.isPlayer()) {
|
if (player != null) {
|
||||||
killed = player.getWorld().killMobs(session.getPlacementPosition(player), radius, flags.flags);
|
killed = player.getWorld().killMobs(session.getPlacementPosition(player), radius, flags.flags);
|
||||||
} else {
|
} else {
|
||||||
killed = 0;
|
killed = 0;
|
||||||
@ -410,16 +411,16 @@ public class UtilityCommands {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (radius < 0) {
|
if (radius < 0) {
|
||||||
player.print("Killed " + killed + " mobs.");
|
actor.print("Killed " + killed + " mobs.");
|
||||||
} else {
|
} 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 {
|
public static class FlagContainer {
|
||||||
private final LocalPlayer player;
|
private final Actor player;
|
||||||
public int flags = 0;
|
public int flags = 0;
|
||||||
public FlagContainer(LocalPlayer player) {
|
public FlagContainer(Actor player) {
|
||||||
this.player = player;
|
this.player = player;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -445,15 +446,13 @@ public class UtilityCommands {
|
|||||||
)
|
)
|
||||||
@CommandPermissions("worldedit.remove")
|
@CommandPermissions("worldedit.remove")
|
||||||
@Logging(PLACEMENT)
|
@Logging(PLACEMENT)
|
||||||
@Console
|
public void remove(Actor actor, @Optional Player player, @Optional LocalSession session, CommandContext args) throws WorldEditException {
|
||||||
public void remove(CommandContext args, LocalSession session, LocalPlayer player,
|
|
||||||
EditSession editSession) throws WorldEditException {
|
|
||||||
|
|
||||||
String typeStr = args.getString(0);
|
String typeStr = args.getString(0);
|
||||||
int radius = args.getInteger(1);
|
int radius = args.getInteger(1);
|
||||||
|
|
||||||
if (radius < -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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -483,12 +482,12 @@ public class UtilityCommands {
|
|||||||
} else if (typeStr.matches("xp")) {
|
} else if (typeStr.matches("xp")) {
|
||||||
type = EntityType.XP_ORBS;
|
type = EntityType.XP_ORBS;
|
||||||
} else {
|
} 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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int removed = 0;
|
int removed = 0;
|
||||||
if (player.isPlayer()) {
|
if (player != null) {
|
||||||
Vector origin = session.getPlacementPosition(player);
|
Vector origin = session.getPlacementPosition(player);
|
||||||
removed = player.getWorld().removeEntities(type, origin, radius);
|
removed = player.getWorld().removeEntities(type, origin, radius);
|
||||||
} else {
|
} else {
|
||||||
@ -506,15 +505,12 @@ public class UtilityCommands {
|
|||||||
min = 0,
|
min = 0,
|
||||||
max = -1
|
max = -1
|
||||||
)
|
)
|
||||||
@Console
|
|
||||||
@CommandPermissions("worldedit.help")
|
@CommandPermissions("worldedit.help")
|
||||||
public void help(CommandContext args, LocalSession session, LocalPlayer player,
|
public void help(Actor actor, CommandContext args) throws WorldEditException {
|
||||||
EditSession editSession) throws WorldEditException {
|
help(args, we, actor);
|
||||||
|
|
||||||
help(args, we, session, player, editSession);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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();
|
final Dispatcher dispatcher = we.getPlatformManager().getCommandManager().getDispatcher();
|
||||||
|
|
||||||
if (args.argsLength() == 0) {
|
if (args.argsLength() == 0) {
|
||||||
@ -542,7 +538,7 @@ public class UtilityCommands {
|
|||||||
first = false;
|
first = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
player.print(sb.toString());
|
actor.print(sb.toString());
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -551,22 +547,22 @@ public class UtilityCommands {
|
|||||||
CommandMapping mapping = dispatcher.get(command);
|
CommandMapping mapping = dispatcher.get(command);
|
||||||
|
|
||||||
if (mapping == null) {
|
if (mapping == null) {
|
||||||
player.printError("Unknown command '" + command + "'.");
|
actor.printError("Unknown command '" + command + "'.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Description description = mapping.getDescription();
|
Description description = mapping.getDescription();
|
||||||
|
|
||||||
if (description.getUsage() != null) {
|
if (description.getUsage() != null) {
|
||||||
player.printDebug("Usage: " + description.getUsage());
|
actor.printDebug("Usage: " + description.getUsage());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (description.getHelp() != null) {
|
if (description.getHelp() != null) {
|
||||||
player.print(description.getHelp());
|
actor.print(description.getHelp());
|
||||||
} else if (description.getDescription() != null) {
|
} else if (description.getDescription() != null) {
|
||||||
player.print(description.getDescription());
|
actor.print(description.getDescription());
|
||||||
} else {
|
} else {
|
||||||
player.print("No further help is available.");
|
actor.print("No further help is available.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,8 +22,8 @@ package com.sk89q.worldedit.command;
|
|||||||
import com.sk89q.minecraft.util.commands.Command;
|
import com.sk89q.minecraft.util.commands.Command;
|
||||||
import com.sk89q.minecraft.util.commands.CommandContext;
|
import com.sk89q.minecraft.util.commands.CommandContext;
|
||||||
import com.sk89q.minecraft.util.commands.CommandPermissions;
|
import com.sk89q.minecraft.util.commands.CommandPermissions;
|
||||||
import com.sk89q.minecraft.util.commands.Console;
|
|
||||||
import com.sk89q.worldedit.*;
|
import com.sk89q.worldedit.*;
|
||||||
|
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.extension.platform.PlatformManager;
|
import com.sk89q.worldedit.extension.platform.PlatformManager;
|
||||||
@ -49,24 +49,21 @@ public class WorldEditCommands {
|
|||||||
min = 0,
|
min = 0,
|
||||||
max = 0
|
max = 0
|
||||||
)
|
)
|
||||||
@Console
|
public void version(Actor actor) throws WorldEditException {
|
||||||
public void version(CommandContext args, LocalSession session, LocalPlayer player,
|
actor.print("WorldEdit version " + WorldEdit.getVersion());
|
||||||
EditSession editSession) throws WorldEditException {
|
actor.print("https://github.com/sk89q/worldedit/");
|
||||||
|
|
||||||
player.print("WorldEdit version " + WorldEdit.getVersion());
|
|
||||||
player.print("https://github.com/sk89q/worldedit/");
|
|
||||||
|
|
||||||
PlatformManager pm = we.getPlatformManager();
|
PlatformManager pm = we.getPlatformManager();
|
||||||
|
|
||||||
player.printDebug("----------- Platforms -----------");
|
actor.printDebug("----------- Platforms -----------");
|
||||||
for (Platform platform : pm.getPlatforms()) {
|
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()) {
|
for (Capability capability : Capability.values()) {
|
||||||
Platform platform = pm.queryCapability(capability);
|
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
|
max = 0
|
||||||
)
|
)
|
||||||
@CommandPermissions("worldedit.reload")
|
@CommandPermissions("worldedit.reload")
|
||||||
@Console
|
public void reload(Actor actor) throws WorldEditException {
|
||||||
public void reload(CommandContext args, LocalSession session, LocalPlayer player,
|
|
||||||
EditSession editSession) throws WorldEditException {
|
|
||||||
|
|
||||||
we.getServer().reload();
|
we.getServer().reload();
|
||||||
player.print("Configuration reloaded!");
|
actor.print("Configuration reloaded!");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Command(
|
@Command(
|
||||||
@ -106,7 +100,6 @@ public class WorldEditCommands {
|
|||||||
min = 1,
|
min = 1,
|
||||||
max = 1
|
max = 1
|
||||||
)
|
)
|
||||||
@Console
|
|
||||||
public void tz(CommandContext args, LocalSession session, LocalPlayer player,
|
public void tz(CommandContext args, LocalSession session, LocalPlayer player,
|
||||||
EditSession editSession) throws WorldEditException {
|
EditSession editSession) throws WorldEditException {
|
||||||
TimeZone tz = TimeZone.getTimeZone(args.getString(0));
|
TimeZone tz = TimeZone.getTimeZone(args.getString(0));
|
||||||
@ -124,10 +117,7 @@ public class WorldEditCommands {
|
|||||||
max = -1
|
max = -1
|
||||||
)
|
)
|
||||||
@CommandPermissions("worldedit.help")
|
@CommandPermissions("worldedit.help")
|
||||||
@Console
|
public void help(Actor actor, CommandContext args) throws WorldEditException {
|
||||||
public void help(CommandContext args, LocalSession session, LocalPlayer player,
|
UtilityCommands.help(args, we, actor);
|
||||||
EditSession editSession) throws WorldEditException {
|
|
||||||
|
|
||||||
UtilityCommands.help(args, we, session, player, editSession);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,8 +19,8 @@
|
|||||||
|
|
||||||
package com.sk89q.worldedit.event.platform;
|
package com.sk89q.worldedit.event.platform;
|
||||||
|
|
||||||
import com.sk89q.worldedit.LocalPlayer;
|
|
||||||
import com.sk89q.worldedit.event.AbstractCancellable;
|
import com.sk89q.worldedit.event.AbstractCancellable;
|
||||||
|
import com.sk89q.worldedit.extension.platform.Actor;
|
||||||
|
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
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 {
|
public class CommandEvent extends AbstractCancellable {
|
||||||
|
|
||||||
private final LocalPlayer player;
|
private final Actor actor;
|
||||||
private final String[] args;
|
private final String[] args;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new instance.
|
* Create a new instance.
|
||||||
*
|
*
|
||||||
* @param player the player
|
* @param actor the player
|
||||||
* @param args the arguments
|
* @param args the arguments
|
||||||
*/
|
*/
|
||||||
public CommandEvent(LocalPlayer player, String[] args) {
|
public CommandEvent(Actor actor, String[] args) {
|
||||||
checkNotNull(player);
|
checkNotNull(actor);
|
||||||
checkNotNull(args);
|
checkNotNull(args);
|
||||||
|
|
||||||
this.player = player;
|
this.actor = actor;
|
||||||
this.args = args;
|
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() {
|
public Actor getActor() {
|
||||||
return player;
|
return actor;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -192,7 +192,7 @@ public final class CommandManager {
|
|||||||
public void handleCommand(CommandEvent event) {
|
public void handleCommand(CommandEvent event) {
|
||||||
Request.reset();
|
Request.reset();
|
||||||
|
|
||||||
Actor actor = event.getPlayer();
|
Actor actor = event.getActor();
|
||||||
String split[] = commandDetection(event.getArguments());
|
String split[] = commandDetection(event.getArguments());
|
||||||
|
|
||||||
// No command found!
|
// No command found!
|
||||||
@ -241,7 +241,7 @@ public final class CommandManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
worldEdit.flushBlockBag(event.getPlayer(), editSession);
|
worldEdit.flushBlockBag(actor, editSession);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -97,6 +97,24 @@ public class WorldEditBinding extends BindingHelper {
|
|||||||
return worldEdit.getSessionManager().get(sender);
|
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}.
|
* Gets an {@link Player} from a {@link ArgumentStack}.
|
||||||
*
|
*
|
||||||
|
Loading…
Reference in New Issue
Block a user