@Override public String toString() { return getId(); }
private static ItemType register(final String id) { return register(new ItemType(id)); }
actor.print(type.getId() + " (" + type.getName() + ")"); } else { if (query.length() <= 2) { if (blocksOnly && !searchType.hasBlockType()) { continue; if (itemsOnly && searchType.hasBlockType()) { continue; for (String alias : Sets.newHashSet(searchType.getId(), searchType.getName())) { if (alias.contains(query)) { actor.print(searchType.getId() + " (" + searchType.getName() + ")"); ++found; break;
@Override public BaseBlock getBlockInHand(HandSide handSide) throws WorldEditException { final ItemType typeId = getItemInHand(handSide).getType(); if (typeId.hasBlockType()) { return typeId.getBlockType().getDefaultState().toBaseBlock(); } else { throw new NotABlockException(); } }
@ExceptionMatch public void convert(InvalidToolBindException e) throws CommandException { throw new CommandException("Can't bind tool to " + e.getItemType().getName() + ": " + e.getMessage()); }
/** * Gets whether this item type has a block representation. * * @return If it has a block */ public boolean hasBlockType() { return getBlockType() != null; }
/** * Set the tool. * * @param item the item type * @param tool the tool to set, which can be {@code null} * @throws InvalidToolBindException if the item can't be bound to that item */ public void setTool(ItemType item, @Nullable Tool tool) throws InvalidToolBindException { if (item.hasBlockType()) { throw new InvalidToolBindException(item, "Blocks can't be used"); } else if (item == ItemTypes.get(config.wandItem)) { throw new InvalidToolBindException(item, "Already used for the wand"); } else if (item == ItemTypes.get(config.navigationWand)) { throw new InvalidToolBindException(item, "Already used for the navigation wand"); } this.tools.put(item, tool); }
@Command( aliases = { "farwand" }, usage = "", desc = "Wand at a distance tool", min = 0, max = 0 ) @CommandPermissions("worldedit.tool.farwand") public void farwand(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException { BaseItemStack itemStack = player.getItemInHand(HandSide.MAIN_HAND); session.setTool(itemStack.getType(), new DistanceWand()); player.print("Far wand tool bound to " + itemStack.getType().getName() + "."); }
/** * Create a Bukkit Material form a WorldEdit ItemType * * @param itemType The WorldEdit ItemType * @return The Bukkit Material */ public static Material adapt(ItemType itemType) { checkNotNull(itemType); if (!itemType.getId().startsWith("minecraft:")) { throw new IllegalArgumentException("Bukkit only supports Minecraft items"); } return Material.getMaterial(itemType.getId().substring(10).toUpperCase()); }
@Command( aliases = { "cycler" }, usage = "", desc = "Block data cycler tool", min = 0, max = 0 ) @CommandPermissions("worldedit.tool.data-cycler") public void cycler(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException { BaseItemStack itemStack = player.getItemInHand(HandSide.MAIN_HAND); session.setTool(itemStack.getType(), new BlockDataCyler()); player.print("Block data cycler tool bound to " + itemStack.getType().getName() + "."); }
@Listener public void serverAboutToStart(GameAboutToStartServerEvent event) { if (this.platform != null) { logger.warn("GameAboutToStartServerEvent occurred when GameStoppingServerEvent hasn't"); WorldEdit.getInstance().getPlatformManager().unregister(platform); } this.platform = new SpongePlatform(this); this.provider = new SpongePermissionsProvider(); for (BlockType blockType : Sponge.getRegistry().getAllOf(BlockType.class)) { // TODO Handle blockstate stuff String id = blockType.getId(); if (!com.sk89q.worldedit.world.block.BlockType.REGISTRY.keySet().contains(id)) { com.sk89q.worldedit.world.block.BlockTypes.register(new com.sk89q.worldedit.world.block.BlockType(id)); } } for (ItemType itemType : Sponge.getRegistry().getAllOf(ItemType.class)) { String id = itemType.getId(); if (!com.sk89q.worldedit.world.item.ItemType.REGISTRY.keySet().contains(id)) { ItemTypes.register(new com.sk89q.worldedit.world.item.ItemType(id)); } } WorldEdit.getInstance().getPlatformManager().register(platform); }
public static ItemType register(final ItemType item) { return ItemType.REGISTRY.register(item.getId(), item); }
@Command( aliases = { "repl" }, usage = "<block>", desc = "Block replacer tool", min = 1, max = 1 ) @CommandPermissions("worldedit.tool.replacer") public void repl(Player player, LocalSession session, Pattern pattern) throws WorldEditException { BaseItemStack itemStack = player.getItemInHand(HandSide.MAIN_HAND); session.setTool(itemStack.getType(), new BlockReplacer(pattern)); player.print("Block replacer tool bound to " + itemStack.getType().getName() + "."); }
@EventHandler public void serverAboutToStart(FMLServerAboutToStartEvent event) { if (this.platform != null) { logger.warn("FMLServerStartingEvent occurred when FMLServerStoppingEvent hasn't"); WorldEdit.getInstance().getPlatformManager().unregister(platform); } this.platform = new ForgePlatform(this); WorldEdit.getInstance().getPlatformManager().register(platform); if (Loader.isModLoaded("sponge")) { this.provider = new ForgePermissionsProvider.SpongePermissionsProvider(); } else { this.provider = new ForgePermissionsProvider.VanillaPermissionsProvider(platform); } for (ResourceLocation name : Block.REGISTRY.getKeys()) { String nameStr = name.toString(); if (!BlockType.REGISTRY.keySet().contains(nameStr)) { BlockTypes.register(new BlockType(nameStr)); } } for (ResourceLocation name : Item.REGISTRY.getKeys()) { String nameStr = name.toString(); if (!ItemType.REGISTRY.keySet().contains(nameStr)) { ItemTypes.register(new ItemType(nameStr)); } } }
public String convertLegacyItem(String legacy) { String item = legacy; try { String[] splitter = item.split(":", 2); int id = 0; byte data = 0; if (splitter.length == 1) { id = Integer.parseInt(item); } else { id = Integer.parseInt(splitter[0]); data = Byte.parseByte(splitter[1]); } item = LegacyMapper.getInstance().getItemFromLegacy(id, data).getId(); } catch (Throwable e) { } return item; }
@Command( aliases = { "deltree" }, usage = "", desc = "Floating tree remover tool", min = 0, max = 0 ) @CommandPermissions("worldedit.tool.deltree") public void deltree(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException { BaseItemStack itemStack = player.getItemInHand(HandSide.MAIN_HAND); session.setTool(itemStack.getType(), new FloatingTreeRemover()); player.print("Floating tree remover tool bound to " + itemStack.getType().getName() + "."); }
@Nullable @Override public String getName(ItemType itemType) { BundledItemData.ItemEntry itemEntry = BundledItemData.getInstance().findById(itemType.getId()); return itemEntry != null ? itemEntry.localizedName : null; } }
@Command( aliases = { "info" }, usage = "", desc = "Block information tool", min = 0, max = 0 ) @CommandPermissions("worldedit.tool.info") public void info(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException { BaseItemStack itemStack = player.getItemInHand(HandSide.MAIN_HAND); session.setTool(itemStack.getType(), new QueryTool()); player.print("Info tool bound to " + itemStack.getType().getName() + "."); }
@Override public void giveItem(BaseItemStack itemStack) { this.player.inventory.addItemStackToInventory( new ItemStack(Item.getByNameOrId(itemStack.getType().getId()), itemStack.getAmount(), 0)); }
@Command( aliases = { "floodfill", "flood" }, usage = "<pattern> <range>", desc = "Flood fill tool", min = 2, max = 2 ) @CommandPermissions("worldedit.tool.flood-fill") public void floodFill(Player player, LocalSession session, Pattern pattern, int range) throws WorldEditException { LocalConfiguration config = we.getConfiguration(); if (range > config.maxSuperPickaxeSize) { player.printError("Maximum range: " + config.maxSuperPickaxeSize); return; } 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() + "."); }