mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2025-07-05 20:36:42 +00:00
Further modernise and remove legacy item classes
This commit is contained in:
@ -46,6 +46,7 @@ import com.sk89q.worldedit.function.mask.BlockMask;
|
||||
import com.sk89q.worldedit.function.pattern.BlockPattern;
|
||||
import com.sk89q.worldedit.function.pattern.Pattern;
|
||||
import com.sk89q.worldedit.session.ClipboardHolder;
|
||||
import com.sk89q.worldedit.util.HandSide;
|
||||
import com.sk89q.worldedit.util.command.binding.Switch;
|
||||
import com.sk89q.worldedit.util.command.parametric.Optional;
|
||||
|
||||
@ -84,7 +85,7 @@ public class BrushCommands {
|
||||
@Optional("2") double radius, @Switch('h') boolean hollow) throws WorldEditException {
|
||||
worldEdit.checkMaxBrushRadius(radius);
|
||||
|
||||
BrushTool tool = session.getBrushTool(player.getItemInHand());
|
||||
BrushTool tool = session.getBrushTool(player.getItemInHand(HandSide.MAIN_HAND).getType());
|
||||
tool.setFill(fill);
|
||||
tool.setSize(radius);
|
||||
|
||||
@ -114,7 +115,7 @@ public class BrushCommands {
|
||||
worldEdit.checkMaxBrushRadius(radius);
|
||||
worldEdit.checkMaxBrushRadius(height);
|
||||
|
||||
BrushTool tool = session.getBrushTool(player.getItemInHand());
|
||||
BrushTool tool = session.getBrushTool(player.getItemInHand(HandSide.MAIN_HAND).getType());
|
||||
tool.setFill(fill);
|
||||
tool.setSize(radius);
|
||||
|
||||
@ -149,7 +150,7 @@ public class BrushCommands {
|
||||
worldEdit.checkMaxBrushRadius(size.getBlockY());
|
||||
worldEdit.checkMaxBrushRadius(size.getBlockZ());
|
||||
|
||||
BrushTool tool = session.getBrushTool(player.getItemInHand());
|
||||
BrushTool tool = session.getBrushTool(player.getItemInHand(HandSide.MAIN_HAND).getType());
|
||||
tool.setBrush(new ClipboardBrush(holder, ignoreAir, usingOrigin), "worldedit.brush.clipboard");
|
||||
|
||||
player.print("Clipboard brush shape equipped.");
|
||||
@ -173,7 +174,7 @@ public class BrushCommands {
|
||||
|
||||
worldEdit.checkMaxBrushRadius(radius);
|
||||
|
||||
BrushTool tool = session.getBrushTool(player.getItemInHand());
|
||||
BrushTool tool = session.getBrushTool(player.getItemInHand(HandSide.MAIN_HAND).getType());
|
||||
tool.setSize(radius);
|
||||
tool.setBrush(new SmoothBrush(iterations, naturalBlocksOnly), "worldedit.brush.smooth");
|
||||
|
||||
@ -192,7 +193,7 @@ public class BrushCommands {
|
||||
public void extinguishBrush(Player player, LocalSession session, EditSession editSession, @Optional("5") double radius) throws WorldEditException {
|
||||
worldEdit.checkMaxBrushRadius(radius);
|
||||
|
||||
BrushTool tool = session.getBrushTool(player.getItemInHand());
|
||||
BrushTool tool = session.getBrushTool(player.getItemInHand(HandSide.MAIN_HAND).getType());
|
||||
Pattern fill = new BlockPattern(new BaseBlock(BlockTypes.AIR));
|
||||
tool.setFill(fill);
|
||||
tool.setSize(radius);
|
||||
@ -218,7 +219,7 @@ public class BrushCommands {
|
||||
public void gravityBrush(Player player, LocalSession session, EditSession editSession, @Optional("5") double radius, @Switch('h') boolean fromMaxY) throws WorldEditException {
|
||||
worldEdit.checkMaxBrushRadius(radius);
|
||||
|
||||
BrushTool tool = session.getBrushTool(player.getItemInHand());
|
||||
BrushTool tool = session.getBrushTool(player.getItemInHand(HandSide.MAIN_HAND).getType());
|
||||
tool.setSize(radius);
|
||||
tool.setBrush(new GravityBrush(fromMaxY), "worldedit.brush.gravity");
|
||||
|
||||
@ -265,7 +266,7 @@ public class BrushCommands {
|
||||
CreatureButcher flags = new CreatureButcher(player);
|
||||
flags.fromCommand(args);
|
||||
|
||||
BrushTool tool = session.getBrushTool(player.getItemInHand());
|
||||
BrushTool tool = session.getBrushTool(player.getItemInHand(HandSide.MAIN_HAND).getType());
|
||||
tool.setSize(radius);
|
||||
tool.setBrush(new ButcherBrush(flags), "worldedit.brush.butcher");
|
||||
|
||||
|
@ -19,11 +19,13 @@
|
||||
|
||||
package com.sk89q.worldedit.command;
|
||||
|
||||
import com.google.common.collect.Sets;
|
||||
import com.sk89q.minecraft.util.commands.Command;
|
||||
import com.sk89q.minecraft.util.commands.CommandContext;
|
||||
import com.sk89q.minecraft.util.commands.CommandPermissions;
|
||||
import com.sk89q.worldedit.*;
|
||||
import com.sk89q.worldedit.blocks.ItemType;
|
||||
import com.sk89q.worldedit.blocks.type.ItemType;
|
||||
import com.sk89q.worldedit.blocks.type.ItemTypes;
|
||||
import com.sk89q.worldedit.entity.Player;
|
||||
import com.sk89q.worldedit.extension.platform.Actor;
|
||||
import com.sk89q.worldedit.function.mask.Mask;
|
||||
@ -161,64 +163,55 @@ public class GeneralCommands {
|
||||
boolean blocksOnly = args.hasFlag('b');
|
||||
boolean itemsOnly = args.hasFlag('i');
|
||||
|
||||
try {
|
||||
int id = Integer.parseInt(query);
|
||||
ItemType type = ItemTypes.getItemType(query);
|
||||
|
||||
ItemType type = ItemType.fromID(id);
|
||||
|
||||
if (type != null) {
|
||||
actor.print("#" + type.getID() + " (" + type.getName() + ")");
|
||||
} else {
|
||||
actor.printError("No item found by ID " + id);
|
||||
}
|
||||
|
||||
return;
|
||||
} catch (NumberFormatException ignored) {
|
||||
}
|
||||
|
||||
if (query.length() <= 2) {
|
||||
actor.printError("Enter a longer search string (len > 2).");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!blocksOnly && !itemsOnly) {
|
||||
actor.print("Searching for: " + query);
|
||||
} else if (blocksOnly && itemsOnly) {
|
||||
actor.printError("You cannot use both the 'b' and 'i' flags simultaneously.");
|
||||
return;
|
||||
} else if (blocksOnly) {
|
||||
actor.print("Searching for blocks: " + query);
|
||||
if (type != null) {
|
||||
actor.print(type.getId() + " (" + type.getName() + ")");
|
||||
} else {
|
||||
actor.print("Searching for items: " + query);
|
||||
}
|
||||
|
||||
int found = 0;
|
||||
|
||||
for (ItemType type : ItemType.values()) {
|
||||
if (found >= 15) {
|
||||
actor.print("Too many results!");
|
||||
break;
|
||||
if (query.length() <= 2) {
|
||||
actor.printError("Enter a longer search string (len > 2).");
|
||||
return;
|
||||
}
|
||||
|
||||
if (blocksOnly && type.getID() > 255) {
|
||||
continue;
|
||||
if (!blocksOnly && !itemsOnly) {
|
||||
actor.print("Searching for: " + query);
|
||||
} else if (blocksOnly && itemsOnly) {
|
||||
actor.printError("You cannot use both the 'b' and 'i' flags simultaneously.");
|
||||
return;
|
||||
} else if (blocksOnly) {
|
||||
actor.print("Searching for blocks: " + query);
|
||||
} else {
|
||||
actor.print("Searching for items: " + query);
|
||||
}
|
||||
|
||||
if (itemsOnly && type.getID() <= 255) {
|
||||
continue;
|
||||
}
|
||||
int found = 0;
|
||||
|
||||
for (String alias : type.getAliases()) {
|
||||
if (alias.contains(query)) {
|
||||
actor.print("#" + type.getID() + " (" + type.getName() + ")");
|
||||
++found;
|
||||
for (ItemType searchType : ItemTypes.values()) {
|
||||
if (found >= 15) {
|
||||
actor.print("Too many results!");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (found == 0) {
|
||||
actor.printError("No items found.");
|
||||
// TODO if (blocksOnly && searchType.getID() > 255) {
|
||||
// continue;
|
||||
// }
|
||||
//
|
||||
// if (itemsOnly && searchType.getID() <= 255) {
|
||||
// continue;
|
||||
// }
|
||||
|
||||
for (String alias : Sets.newHashSet(searchType.getId(), searchType.getName())) {
|
||||
if (alias.contains(query)) {
|
||||
actor.print(searchType.getId() + " (" + searchType.getName() + ")");
|
||||
++found;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (found == 0) {
|
||||
actor.printError("No items found.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -34,6 +34,7 @@ import com.sk89q.worldedit.Vector2D;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.WorldEditException;
|
||||
import com.sk89q.worldedit.blocks.BaseBlock;
|
||||
import com.sk89q.worldedit.blocks.type.ItemTypes;
|
||||
import com.sk89q.worldedit.entity.Player;
|
||||
import com.sk89q.worldedit.extension.input.ParserContext;
|
||||
import com.sk89q.worldedit.extension.platform.permission.ActorSelectorLimits;
|
||||
@ -276,7 +277,7 @@ public class SelectionCommands {
|
||||
@CommandPermissions("worldedit.wand")
|
||||
public void wand(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException {
|
||||
|
||||
player.giveItem(we.getConfiguration().wandItem, 1);
|
||||
player.giveItem(ItemTypes.getItemType(we.getConfiguration().wandItem).getLegacyId(), 1);
|
||||
player.print("Left click: select pos #1; Right click: select pos #2");
|
||||
}
|
||||
|
||||
|
@ -24,11 +24,12 @@ import com.sk89q.minecraft.util.commands.CommandContext;
|
||||
import com.sk89q.minecraft.util.commands.CommandPermissions;
|
||||
import com.sk89q.worldedit.*;
|
||||
import com.sk89q.worldedit.blocks.BaseBlock;
|
||||
import com.sk89q.worldedit.blocks.ItemType;
|
||||
import com.sk89q.worldedit.blocks.BaseItemStack;
|
||||
import com.sk89q.worldedit.entity.Player;
|
||||
import com.sk89q.worldedit.extension.input.ParserContext;
|
||||
import com.sk89q.worldedit.command.tool.*;
|
||||
import com.sk89q.worldedit.function.pattern.Pattern;
|
||||
import com.sk89q.worldedit.util.HandSide;
|
||||
import com.sk89q.worldedit.util.TreeGenerator;
|
||||
|
||||
public class ToolCommands {
|
||||
@ -47,7 +48,7 @@ public class ToolCommands {
|
||||
)
|
||||
public void none(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException {
|
||||
|
||||
session.setTool(player.getItemInHand(), null);
|
||||
session.setTool(player.getItemInHand(HandSide.MAIN_HAND).getType(), null);
|
||||
player.print("Tool unbound from your current item.");
|
||||
}
|
||||
|
||||
@ -61,9 +62,10 @@ public class ToolCommands {
|
||||
@CommandPermissions("worldedit.tool.info")
|
||||
public void info(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException {
|
||||
|
||||
session.setTool(player.getItemInHand(), new QueryTool());
|
||||
BaseItemStack itemStack = player.getItemInHand(HandSide.MAIN_HAND);
|
||||
session.setTool(itemStack.getType(), new QueryTool());
|
||||
player.print("Info tool bound to "
|
||||
+ ItemType.toHeldName(player.getItemInHand()) + ".");
|
||||
+ itemStack.getType().getName() + ".");
|
||||
}
|
||||
|
||||
@Command(
|
||||
@ -76,8 +78,8 @@ public class ToolCommands {
|
||||
@CommandPermissions("worldedit.tool.tree")
|
||||
public void tree(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException {
|
||||
|
||||
TreeGenerator.TreeType type = args.argsLength() > 0 ?
|
||||
type = TreeGenerator.lookup(args.getString(0))
|
||||
TreeGenerator.TreeType type = args.argsLength() > 0
|
||||
? TreeGenerator.lookup(args.getString(0))
|
||||
: TreeGenerator.TreeType.TREE;
|
||||
|
||||
if (type == null) {
|
||||
@ -85,9 +87,9 @@ public class ToolCommands {
|
||||
return;
|
||||
}
|
||||
|
||||
session.setTool(player.getItemInHand(), new TreePlanter(new TreeGenerator(type)));
|
||||
player.print("Tree tool bound to "
|
||||
+ ItemType.toHeldName(player.getItemInHand()) + ".");
|
||||
BaseItemStack itemStack = player.getItemInHand(HandSide.MAIN_HAND);
|
||||
session.setTool(itemStack.getType(), new TreePlanter(new TreeGenerator(type)));
|
||||
player.print("Tree tool bound to " + itemStack.getType().getName() + ".");
|
||||
}
|
||||
|
||||
@Command(
|
||||
@ -108,9 +110,9 @@ public class ToolCommands {
|
||||
context.setPreferringWildcard(false);
|
||||
|
||||
BaseBlock targetBlock = we.getBlockFactory().parseFromInput(args.getString(0), context);
|
||||
session.setTool(player.getItemInHand(), new BlockReplacer(targetBlock));
|
||||
player.print("Block replacer tool bound to "
|
||||
+ ItemType.toHeldName(player.getItemInHand()) + ".");
|
||||
BaseItemStack itemStack = player.getItemInHand(HandSide.MAIN_HAND);
|
||||
session.setTool(itemStack.getType(), new BlockReplacer(targetBlock));
|
||||
player.print("Block replacer tool bound to " + itemStack.getType().getName() + ".");
|
||||
}
|
||||
|
||||
@Command(
|
||||
@ -123,9 +125,9 @@ public class ToolCommands {
|
||||
@CommandPermissions("worldedit.tool.data-cycler")
|
||||
public void cycler(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException {
|
||||
|
||||
session.setTool(player.getItemInHand(), new BlockDataCyler());
|
||||
player.print("Block data cycler tool bound to "
|
||||
+ ItemType.toHeldName(player.getItemInHand()) + ".");
|
||||
BaseItemStack itemStack = player.getItemInHand(HandSide.MAIN_HAND);
|
||||
session.setTool(itemStack.getType(), new BlockDataCyler());
|
||||
player.print("Block data cycler tool bound to " + itemStack.getType().getName() + ".");
|
||||
}
|
||||
|
||||
@Command(
|
||||
@ -152,9 +154,9 @@ public class ToolCommands {
|
||||
context.setSession(session);
|
||||
Pattern pattern = we.getPatternFactory().parseFromInput(args.getString(0), context);
|
||||
|
||||
session.setTool(player.getItemInHand(), new FloodFillTool(range, pattern));
|
||||
player.print("Block flood fill tool bound to "
|
||||
+ ItemType.toHeldName(player.getItemInHand()) + ".");
|
||||
BaseItemStack itemStack = player.getItemInHand(HandSide.MAIN_HAND);
|
||||
session.setTool(itemStack.getType(), new FloodFillTool(range, pattern));
|
||||
player.print("Block flood fill tool bound to " + itemStack.getType().getName() + ".");
|
||||
}
|
||||
|
||||
@Command(
|
||||
@ -167,9 +169,10 @@ public class ToolCommands {
|
||||
@CommandPermissions("worldedit.tool.deltree")
|
||||
public void deltree(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException {
|
||||
|
||||
session.setTool(player.getItemInHand(), new FloatingTreeRemover());
|
||||
player.print("Floating tree remover tool bound to "
|
||||
+ ItemType.toHeldName(player.getItemInHand()) + ".");
|
||||
BaseItemStack itemStack = player.getItemInHand(HandSide.MAIN_HAND);
|
||||
session.setTool(itemStack.getType(), new FloatingTreeRemover());
|
||||
player.print("Floating tree remover tool bound to "
|
||||
+ itemStack.getType().getName() + ".");
|
||||
}
|
||||
|
||||
@Command(
|
||||
@ -182,8 +185,9 @@ public class ToolCommands {
|
||||
@CommandPermissions("worldedit.tool.farwand")
|
||||
public void farwand(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException {
|
||||
|
||||
session.setTool(player.getItemInHand(), new DistanceWand());
|
||||
player.print("Far wand tool bound to " + ItemType.toHeldName(player.getItemInHand()) + ".");
|
||||
BaseItemStack itemStack = player.getItemInHand(HandSide.MAIN_HAND);
|
||||
session.setTool(itemStack.getType(), new DistanceWand());
|
||||
player.print("Far wand tool bound to " + itemStack.getType().getName() + ".");
|
||||
}
|
||||
|
||||
@Command(
|
||||
@ -206,9 +210,11 @@ public class ToolCommands {
|
||||
BaseBlock secondary = we.getBlockFactory().parseFromInput(args.getString(0), context);
|
||||
BaseBlock primary = we.getBlockFactory().parseFromInput(args.getString(1), context);
|
||||
|
||||
session.setTool(player.getItemInHand(), new LongRangeBuildTool(primary, secondary));
|
||||
player.print("Long-range building tool bound to " + ItemType.toHeldName(player.getItemInHand()) + ".");
|
||||
player.print("Left-click set to " + ItemType.toName(secondary.getType().getLegacyId()) + "; right-click set to "
|
||||
+ ItemType.toName(primary.getType().getLegacyId()) + ".");
|
||||
BaseItemStack itemStack = player.getItemInHand(HandSide.MAIN_HAND);
|
||||
|
||||
session.setTool(itemStack.getType(), new LongRangeBuildTool(primary, secondary));
|
||||
player.print("Long-range building tool bound to " + itemStack.getType().getName() + ".");
|
||||
player.print("Left-click set to " + secondary.getType().getName() + "; right-click set to "
|
||||
+ primary.getType().getName() + ".");
|
||||
}
|
||||
}
|
||||
|
@ -26,6 +26,7 @@ import com.sk89q.worldedit.*;
|
||||
import com.sk89q.worldedit.entity.Player;
|
||||
import com.sk89q.worldedit.function.mask.Mask;
|
||||
import com.sk89q.worldedit.function.pattern.Pattern;
|
||||
import com.sk89q.worldedit.util.HandSide;
|
||||
import com.sk89q.worldedit.util.command.parametric.Optional;
|
||||
|
||||
/**
|
||||
@ -78,10 +79,10 @@ public class ToolUtilCommands {
|
||||
@CommandPermissions("worldedit.brush.options.mask")
|
||||
public void mask(Player player, LocalSession session, EditSession editSession, @Optional Mask mask) throws WorldEditException {
|
||||
if (mask == null) {
|
||||
session.getBrushTool(player.getItemInHand()).setMask(null);
|
||||
session.getBrushTool(player.getItemInHand(HandSide.MAIN_HAND).getType()).setMask(null);
|
||||
player.print("Brush mask disabled.");
|
||||
} else {
|
||||
session.getBrushTool(player.getItemInHand()).setMask(mask);
|
||||
session.getBrushTool(player.getItemInHand(HandSide.MAIN_HAND).getType()).setMask(mask);
|
||||
player.print("Brush mask set.");
|
||||
}
|
||||
}
|
||||
@ -95,7 +96,7 @@ public class ToolUtilCommands {
|
||||
)
|
||||
@CommandPermissions("worldedit.brush.options.material")
|
||||
public void material(Player player, LocalSession session, EditSession editSession, Pattern pattern) throws WorldEditException {
|
||||
session.getBrushTool(player.getItemInHand()).setFill(pattern);
|
||||
session.getBrushTool(player.getItemInHand(HandSide.MAIN_HAND).getType()).setFill(pattern);
|
||||
player.print("Brush material set.");
|
||||
}
|
||||
|
||||
@ -109,7 +110,7 @@ public class ToolUtilCommands {
|
||||
@CommandPermissions("worldedit.brush.options.range")
|
||||
public void range(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException {
|
||||
int range = args.getInteger(0);
|
||||
session.getBrushTool(player.getItemInHand()).setRange(range);
|
||||
session.getBrushTool(player.getItemInHand(HandSide.MAIN_HAND).getType()).setRange(range);
|
||||
player.print("Brush range set.");
|
||||
}
|
||||
|
||||
@ -126,7 +127,7 @@ public class ToolUtilCommands {
|
||||
int radius = args.getInteger(0);
|
||||
we.checkMaxBrushRadius(radius);
|
||||
|
||||
session.getBrushTool(player.getItemInHand()).setSize(radius);
|
||||
session.getBrushTool(player.getItemInHand(HandSide.MAIN_HAND).getType()).setSize(radius);
|
||||
player.print("Brush size set.");
|
||||
}
|
||||
}
|
||||
|
@ -35,6 +35,7 @@ import com.sk89q.worldedit.extension.platform.Actor;
|
||||
import com.sk89q.worldedit.function.Contextual;
|
||||
import com.sk89q.worldedit.function.operation.Operation;
|
||||
import com.sk89q.worldedit.regions.factory.RegionFactory;
|
||||
import com.sk89q.worldedit.util.HandSide;
|
||||
import com.sk89q.worldedit.util.command.argument.CommandArgs;
|
||||
import com.sk89q.worldedit.util.command.composition.CommandExecutor;
|
||||
import com.sk89q.worldedit.util.command.composition.SimpleCommand;
|
||||
@ -71,7 +72,7 @@ public class ShapedBrushCommand extends SimpleCommand<Object> {
|
||||
|
||||
try {
|
||||
WorldEdit.getInstance().checkMaxBrushRadius(radius);
|
||||
BrushTool tool = session.getBrushTool(player.getItemInHand());
|
||||
BrushTool tool = session.getBrushTool(player.getItemInHand(HandSide.MAIN_HAND).getType());
|
||||
tool.setSize(radius);
|
||||
tool.setBrush(new OperationFactoryBrush(factory, regionFactory), permission);
|
||||
} catch (MaxBrushRadiusException | InvalidToolBindException e) {
|
||||
|
@ -20,18 +20,19 @@
|
||||
package com.sk89q.worldedit.command.tool;
|
||||
|
||||
import com.sk89q.worldedit.WorldEditException;
|
||||
import com.sk89q.worldedit.blocks.type.ItemType;
|
||||
|
||||
public class InvalidToolBindException extends WorldEditException {
|
||||
|
||||
private int itemId;
|
||||
private ItemType item;
|
||||
|
||||
public InvalidToolBindException(int itemId, String msg) {
|
||||
public InvalidToolBindException(ItemType item, String msg) {
|
||||
super(msg);
|
||||
this.itemId = itemId;
|
||||
this.item = item;
|
||||
}
|
||||
|
||||
public int getItemId() {
|
||||
return itemId;
|
||||
public ItemType getItemType() {
|
||||
return this.item;
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user