org.spongepowered.api.item.ItemTypes Java Examples

The following examples show how to use org.spongepowered.api.item.ItemTypes. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ItemcanplaceonCommand.java    From UltimateCore with MIT License 6 votes vote down vote up
@Override
public CommandResult execute(CommandSource sender, CommandContext args) throws CommandException {
    checkIfPlayer(sender);
    checkPermission(sender, ItemPermissions.UC_ITEM_ITEMCANPLACEON_BASE);
    Player p = (Player) sender;

    if (p.getItemInHand(HandTypes.MAIN_HAND).getType().equals(ItemTypes.NONE)) {
        throw new ErrorMessageException(Messages.getFormatted(p, "item.noiteminhand"));
    }
    ItemStack stack = p.getItemInHand(HandTypes.MAIN_HAND);
    Set<BlockType> types = new HashSet<>(args.<BlockType>getAll("blocktypes"));

    stack.offer(Keys.PLACEABLE_BLOCKS, types);
    p.setItemInHand(HandTypes.MAIN_HAND, stack);
    Text items = Text.joinWith(Text.of(", "), types.stream().map(type -> Text.of(type.getName())).collect(Collectors.toList()));
    Messages.send(sender, "item.command.itemcanplaceon.success", "%arg%", items);
    return CommandResult.success();
}
 
Example #2
Source File: GlobalListener.java    From RedProtect with GNU General Public License v3.0 6 votes vote down vote up
private boolean canUse(Player p, Region r) {
    boolean claimRps = RedProtect.get().config.globalFlagsRoot().worlds.get(p.getWorld().getName()).deny_item_usage.allow_on_claimed_rps;
    boolean wilderness = RedProtect.get().config.globalFlagsRoot().worlds.get(p.getWorld().getName()).deny_item_usage.allow_on_wilderness;

    ItemType item = RedProtect.get().getVersionHelper().getItemInHand(p);

    //deny item usage
    if (!RedProtect.get().ph.hasPerm(p, "redprotect.world.bypass") && !item.equals(ItemTypes.NONE) && RedProtect.get().config.globalFlagsRoot().worlds.get(p.getWorld().getName()).deny_item_usage.items.stream().anyMatch(item.getType().getName()::matches)) {
        if (r != null && ((!claimRps && r.canBuild(p)) || (claimRps && !r.canBuild(p)))) {
            RedProtect.get().lang.sendMessage(p, "playerlistener.region.cantuse");
            return false;
        }
        if (r == null && !wilderness) {
            RedProtect.get().lang.sendMessage(p, "playerlistener.region.cantuse");
            return false;
        }
    }
    return true;
}
 
Example #3
Source File: BlockListener.java    From RedProtect with GNU General Public License v3.0 6 votes vote down vote up
@Listener(order = Order.FIRST, beforeModifications = true)
public void onInteractBlock(InteractBlockEvent event, @First Player p) {
    BlockSnapshot b = event.getTargetBlock();
    Location<World> l;

    RedProtect.get().logger.debug(LogLevel.PLAYER, "BlockListener - Is InteractBlockEvent event");

    if (!b.getState().getType().equals(BlockTypes.AIR)) {
        l = b.getLocation().get();
        RedProtect.get().logger.debug(LogLevel.PLAYER, "BlockListener - Is InteractBlockEvent event. The block is " + b.getState().getType().getName());
    } else {
        l = p.getLocation();
    }

    Region r = RedProtect.get().rm.getTopRegion(l, this.getClass().getName());
    if (r != null) {
        ItemType itemInHand = RedProtect.get().getVersionHelper().getItemInHand(p);
        if (itemInHand.equals(ItemTypes.ARMOR_STAND) && !r.canBuild(p)) {
            RedProtect.get().lang.sendMessage(p, "blocklistener.region.cantbuild");
            event.setCancelled(true);
        }
    }
}
 
Example #4
Source File: WandCommand.java    From RedProtect with GNU General Public License v3.0 6 votes vote down vote up
public CommandSpec register() {
    return CommandSpec.builder()
            .description(Text.of("Command to get wand tool"))
            .permission("redprotect.command.wand")
            .executor((src, args) -> {
                if (!(src instanceof Player)) {
                    HandleHelpPage(src, 1);
                } else {
                    Player player = (Player) src;
                    if (RedProtect.get().config.getWorldClaimType(player.getWorld().getName()).equalsIgnoreCase("BLOCK") && !RedProtect.get().ph.hasPerm(player, "redprotect.command.admin.wand"))
                        return CommandResult.success();

                    Inventory inv = player.getInventory();
                    ItemType mat = Sponge.getRegistry().getType(ItemType.class, RedProtect.get().config.configRoot().wands.adminWandID).orElse(ItemTypes.GLASS_BOTTLE);
                    ItemStack item = ItemStack.of(mat, 1);
                    item.offer(Keys.ITEM_ENCHANTMENTS, new ArrayList<>());

                    if (inv.query(Hotbar.class).offer(item).getType().equals(InventoryTransactionResult.Type.SUCCESS)) {
                        RedProtect.get().lang.sendMessage(player, RedProtect.get().lang.get("cmdmanager.wand.given").replace("{item}", mat.getName()));
                    } else {
                        RedProtect.get().lang.sendMessage(player, RedProtect.get().lang.get("cmdmanager.wand.nospace").replace("{item}", mat.getName()));
                    }
                }
                return CommandResult.success();
            }).build();
}
 
Example #5
Source File: ItemdurabilityCommand.java    From UltimateCore with MIT License 6 votes vote down vote up
@Override
public CommandResult execute(CommandSource sender, CommandContext args) throws CommandException {
    checkIfPlayer(sender);
    checkPermission(sender, ItemPermissions.UC_ITEM_ITEMDURABILITY_BASE);
    Player p = (Player) sender;

    if (p.getItemInHand(HandTypes.MAIN_HAND).getType().equals(ItemTypes.NONE)) {
        throw new ErrorMessageException(Messages.getFormatted(p, "item.noiteminhand"));
    }
    ItemStack stack = p.getItemInHand(HandTypes.MAIN_HAND);
    int durability = args.<Integer>getOne("durability").get();

    if (!stack.supports(DurabilityData.class)) {
        throw new ErrorMessageException(Messages.getFormatted(sender, "item.command.itemdurability.notsupported"));
    }

    if (durability < stack.get(DurabilityData.class).get().durability().getMinValue() || durability > stack.get(DurabilityData.class).get().durability().getMaxValue()) {
        throw new ErrorMessageException(Messages.getFormatted(sender, "item.numberinvalid", "%number%", durability));
    }

    stack.offer(Keys.ITEM_DURABILITY, durability);
    p.setItemInHand(HandTypes.MAIN_HAND, stack);
    Messages.send(sender, "item.command.itemdurability.success", "%arg%", durability);
    return CommandResult.success();
}
 
Example #6
Source File: BlacklistListener.java    From EssentialCmds with MIT License 6 votes vote down vote up
@Listener
public void onPickupItem(ChangeInventoryEvent.Pickup event, @Root Player player)
{
	if (!player.hasPermission("essentialcmds.blacklist.bypass"))
	{
		for (SlotTransaction transaction : event.getTransactions())
		{
			if (Utils.getBlacklistItems().contains(transaction.getFinal().createStack().getItem().getId()))
			{
				if (Utils.areBlacklistMsgsEnabled())
					player.sendMessage(Text.of(TextColors.RED, "The item ", TextColors.GRAY, transaction.getFinal().createStack().getItem().getId(), TextColors.RED, " has been confiscated as it is blacklisted."));

				transaction.setCustom(Sponge.getRegistry().createBuilder(ItemStack.Builder.class).itemType(ItemTypes.DIRT).quantity(1).build());
			}
		}
	}
}
 
Example #7
Source File: BlacklistListener.java    From EssentialCmds with MIT License 6 votes vote down vote up
@Listener
public void onChangeEquipment(ChangeInventoryEvent.Equipment event, @Root Player player)
{
	if (!player.hasPermission("essentialcmds.blacklist.bypass"))
	{
		for (SlotTransaction transaction : event.getTransactions())
		{
			if (Utils.getBlacklistItems().contains(transaction.getFinal().createStack().getItem().getId()))
			{
				if (Utils.areBlacklistMsgsEnabled())
					player.sendMessage(Text.of(TextColors.RED, "The item ", TextColors.GRAY, transaction.getFinal().createStack().getItem().getId(), TextColors.RED, " has been confiscated as it is blacklisted."));

				transaction.setCustom(Sponge.getRegistry().createBuilder(ItemStack.Builder.class).itemType(ItemTypes.DIRT).quantity(1).build());
			}
		}
	}
}
 
Example #8
Source File: BlacklistListener.java    From EssentialCmds with MIT License 6 votes vote down vote up
@Listener
public void onChangeHeldItem(ChangeInventoryEvent.Held event, @Root Player player)
{
	if (!player.hasPermission("essentialcmds.blacklist.bypass"))
	{
		for (SlotTransaction transaction : event.getTransactions())
		{
			if (Utils.getBlacklistItems().contains(transaction.getFinal().createStack().getItem().getId()))
			{
				if (Utils.areBlacklistMsgsEnabled())
					player.sendMessage(Text.of(TextColors.RED, "The item ", TextColors.GRAY, transaction.getFinal().createStack().getItem().getId(), TextColors.RED, " has been confiscated as it is blacklisted."));

				transaction.setCustom(Sponge.getRegistry().createBuilder(ItemStack.Builder.class).itemType(ItemTypes.DIRT).quantity(1).build());
			}
		}
	}
}
 
Example #9
Source File: ItemcanbreakCommand.java    From UltimateCore with MIT License 6 votes vote down vote up
@Override
public CommandResult execute(CommandSource sender, CommandContext args) throws CommandException {
    checkIfPlayer(sender);
    checkPermission(sender, ItemPermissions.UC_ITEM_ITEMCANBREAK_BASE);
    Player p = (Player) sender;

    if (p.getItemInHand(HandTypes.MAIN_HAND).getType().equals(ItemTypes.NONE)) {
        throw new ErrorMessageException(Messages.getFormatted(p, "item.noiteminhand"));
    }
    ItemStack stack = p.getItemInHand(HandTypes.MAIN_HAND);
    Set<BlockType> types = new HashSet<>(args.<BlockType>getAll("blocktypes"));

    stack.offer(Keys.BREAKABLE_BLOCK_TYPES, types);
    p.setItemInHand(HandTypes.MAIN_HAND, stack);
    Text items = Text.joinWith(Text.of(", "), types.stream().map(type -> Text.of(type.getName())).collect(Collectors.toList()));
    Messages.send(sender, "item.command.itemcanbreak.success", "%arg%", items);
    return CommandResult.success();
}
 
Example #10
Source File: Utils.java    From EssentialCmds with MIT License 6 votes vote down vote up
public static PlayerInventory getPlayerInventory(UUID playerUuid, UUID worldUuid)
{
	ConfigurationNode parentNode = Configs.getConfig(inventoryConfig).getNode("inventory", playerUuid.toString(), worldUuid.toString(), "slots");
	List<ItemStack> slots = Lists.newArrayList();

	for (int slot = 0; slot < parentNode.getChildrenMap().keySet().size(); slot++)
	{
		if (parentNode.getChildrenMap().keySet().contains(String.valueOf(slot)))
		{
			ConfigurationNode inventoryNode = Configs.getConfig(inventoryConfig).getNode("inventory", playerUuid.toString(), worldUuid.toString(), "slots", String.valueOf(slot));
			Optional<ItemStack> optionalStack = ItemStackSerializer.readItemStack(inventoryNode, slot);
			slots.add(optionalStack.orElse(ItemStack.builder().itemType(ItemTypes.NONE).build()));
		}
		else
		{
			slots.add(ItemStack.builder().itemType(ItemTypes.NONE).build());
		}
	}

	return new PlayerInventory(playerUuid, worldUuid, slots);
}
 
Example #11
Source File: ItemnameCommand.java    From UltimateCore with MIT License 6 votes vote down vote up
@Override
public CommandResult execute(CommandSource sender, CommandContext args) throws CommandException {
    checkIfPlayer(sender);
    checkPermission(sender, ItemPermissions.UC_ITEM_ITEMNAME_BASE);
    Player p = (Player) sender;

    if (p.getItemInHand(HandTypes.MAIN_HAND).getType().equals(ItemTypes.NONE)) {
        throw new ErrorMessageException(Messages.getFormatted(p, "item.noiteminhand"));
    }
    ItemStack stack = p.getItemInHand(HandTypes.MAIN_HAND);

    Text name = Messages.toText(args.<String>getOne("name").get());
    stack.offer(Keys.DISPLAY_NAME, name);
    p.setItemInHand(HandTypes.MAIN_HAND, stack);
    Messages.send(sender, "item.command.itemname.success", "%arg%", name);
    return CommandResult.success();
}
 
Example #12
Source File: UIRenderer.java    From SubServers-2 with Apache License 2.0 6 votes vote down vote up
/**
 * Parse an ItemStack from a String
 *
 * @param str String to parse
 * @param def Default to return if unable to parse
 * @return ItemStack
 */
public ItemStack parseItem(String str, ItemStack def) {
    final Container<String> item = new Container<String>(str);
    // minecraft:name
    if (item.get().toLowerCase().startsWith("minecraft:")) {
        item.set(item.get().substring(10));
    } else

        // bukkit:name (ignored on sponge)
        if (item.get().toLowerCase().startsWith("bukkit:")) {
            item.set(item.get().substring(7));
        }

    // material name
    if (!Util.isException(() -> ItemTypes.class.getDeclaredField(item.get().toUpperCase()).get(null))) {
        return ItemStack.builder().itemType((ItemType) Util.getDespiteException(() -> ItemTypes.class.getDeclaredField(item.get().toUpperCase()).get(null), null)).quantity(1).build();
    }

    return def;
}
 
Example #13
Source File: ItemhidetagsCommand.java    From UltimateCore with MIT License 6 votes vote down vote up
@Override
public CommandResult execute(CommandSource sender, CommandContext args) throws CommandException {
    checkIfPlayer(sender);
    checkPermission(sender, ItemPermissions.UC_ITEM_ITEMHIDETAGS_BASE);
    Player p = (Player) sender;

    if (p.getItemInHand(HandTypes.MAIN_HAND).getType().equals(ItemTypes.NONE)) {
        throw new ErrorMessageException(Messages.getFormatted(p, "item.noiteminhand"));
    }
    ItemStack stack = p.getItemInHand(HandTypes.MAIN_HAND);

    Key<Value<Boolean>> key = args.<Key<Value<Boolean>>>getOne("tag").get();
    boolean value = args.<Boolean>getOne("enabled").get();

    stack.offer(key, value);
    p.setItemInHand(HandTypes.MAIN_HAND, stack);
    Messages.send(sender, "item.command.itemhidetags.success", "%tag%", key.getName(), "%status%", Messages.getFormatted(value ? "item.command.itemhidetags.hidden" : "item.command.itemhidetags.shown"));
    return CommandResult.success();
}
 
Example #14
Source File: InteractPermListener.java    From Nations with MIT License 6 votes vote down vote up
@Listener(order=Order.FIRST, beforeModifications = true)
public void onInteract(InteractBlockEvent event, @First Player player)
{
	if (!ConfigHandler.getNode("worlds").getNode(player.getWorld().getName()).getNode("enabled").getBoolean())
	{
		return;
	}
	if (player.hasPermission("nations.admin.bypass.perm.interact"))
	{
		return;
	}
	Optional<ItemStack> optItem = player.getItemInHand(HandTypes.MAIN_HAND);
	if (optItem.isPresent() && (ConfigHandler.isWhitelisted("use", optItem.get().getItem().getId()) || optItem.get().getItem().equals(ItemTypes.GOLDEN_AXE) && ConfigHandler.getNode("others", "enableGoldenAxe").getBoolean(true)))
		return;
	event.getTargetBlock().getLocation().ifPresent(loc -> {
		if (!DataHandler.getPerm("interact", player.getUniqueId(), loc))
		{
			event.setCancelled(true);
			if (loc.getBlockType() != BlockTypes.STANDING_SIGN && loc.getBlockType() != BlockTypes.WALL_SIGN)
				player.sendMessage(Text.of(TextColors.RED, LanguageHandler.ERROR_PERM_INTERACT));
		}
	});
}
 
Example #15
Source File: ItemquantityCommand.java    From UltimateCore with MIT License 6 votes vote down vote up
@Override
public CommandResult execute(CommandSource sender, CommandContext args) throws CommandException {
    checkIfPlayer(sender);
    checkPermission(sender, ItemPermissions.UC_ITEM_ITEMDURABILITY_BASE);
    Player p = (Player) sender;

    if (p.getItemInHand(HandTypes.MAIN_HAND).getType().equals(ItemTypes.NONE)) {
        throw new ErrorMessageException(Messages.getFormatted(p, "item.noiteminhand"));
    }
    ItemStack stack = p.getItemInHand(HandTypes.MAIN_HAND);
    int quantity = args.<Integer>getOne("quantity").get();

    if (quantity > stack.getMaxStackQuantity()) {
        throw new ErrorMessageException(Messages.getFormatted(sender, "item.numberinvalid", "%number%", quantity));
    }

    stack.setQuantity(quantity);
    p.setItemInHand(HandTypes.MAIN_HAND, stack);
    Messages.send(sender, "item.command.itemquantity.success", "%arg%", quantity);
    return CommandResult.success();
}
 
Example #16
Source File: ItemunbreakableCommand.java    From UltimateCore with MIT License 6 votes vote down vote up
@Override
public CommandResult execute(CommandSource sender, CommandContext args) throws CommandException {
    checkIfPlayer(sender);
    checkPermission(sender, ItemPermissions.UC_ITEM_ITEMUNBREAKABLE_BASE);
    Player p = (Player) sender;

    Boolean value = args.<Boolean>getOne("enabled/disabled").get();

    if (p.getItemInHand(HandTypes.MAIN_HAND).getType().equals(ItemTypes.NONE)) {
        throw new ErrorMessageException(Messages.getFormatted(p, "item.noiteminhand"));
    }
    ItemStack stack = p.getItemInHand(HandTypes.MAIN_HAND);

    if (!stack.supports(Keys.UNBREAKABLE)) {
        throw new ErrorMessageException(Messages.getFormatted(sender, "item.command.itemunbreakable.notsupported"));
    }

    stack.offer(Keys.UNBREAKABLE, value);
    p.setItemInHand(HandTypes.MAIN_HAND, stack);
    Messages.send(sender, "item.command.itemunbreakable.success", "%arg%", value);
    return CommandResult.success();
}
 
Example #17
Source File: ItemloreCommand.java    From UltimateCore with MIT License 6 votes vote down vote up
@Override
public CommandResult execute(CommandSource sender, CommandContext args) throws CommandException {
    checkIfPlayer(sender);
    checkPermission(sender, ItemPermissions.UC_ITEM_ITEMLORE_BASE);
    Player p = (Player) sender;

    if (p.getItemInHand(HandTypes.MAIN_HAND).getType().equals(ItemTypes.NONE)) {
        throw new ErrorMessageException(Messages.getFormatted(p, "item.noiteminhand"));
    }
    ItemStack stack = p.getItemInHand(HandTypes.MAIN_HAND);

    Text unsplitlore = Messages.toText(args.<String>getOne("lore").get());
    stack.offer(Keys.ITEM_LORE, unsplitlore.toPlain().contains("|") ? TextUtil.split(unsplitlore, "|") : Arrays.asList(unsplitlore));
    p.setItemInHand(HandTypes.MAIN_HAND, stack);
    Messages.send(sender, "item.command.itemlore.success", "%arg%", unsplitlore);
    return CommandResult.success();
}
 
Example #18
Source File: CreatekitCommand.java    From UltimateCore with MIT License 6 votes vote down vote up
@Override
public CommandResult execute(CommandSource sender, CommandContext args) throws CommandException {
    checkIfPlayer(sender);
    checkPermission(sender, KitPermissions.UC_KIT_CREATEKIT_BASE);
    Player p = (Player) sender;

    String name = args.<String>getOne("name").get().toLowerCase();
    long cooldown = args.hasAny("cooldown") ? args.<Long>getOne("cooldown").get() : -1L;
    String description = args.hasAny("description") ? args.<String>getOne("description").get() : Messages.getFormatted("kit.defaultdescription").toPlain();

    List<ItemStackSnapshot> items = new ArrayList<>();
    p.getInventory().slots().forEach(slot -> {
        ItemStack stack = slot.peek();
        if (!stack.getType().equals(ItemTypes.NONE)) {
            items.add(stack.createSnapshot());
        }
    });

    Kit kit = new Kit(name, description, items, new ArrayList<>(), cooldown);
    List<Kit> kits = GlobalData.get(KitKeys.KITS).get();
    kits.add(kit);
    GlobalData.offer(KitKeys.KITS, kits);
    Messages.send(sender, "kit.command.createkit.success", "%name%", name);
    return CommandResult.success();
}
 
Example #19
Source File: FoodCommand.java    From UltimateCore with MIT License 6 votes vote down vote up
@Override
public CommandResult execute(CommandSource sender, CommandContext args) throws CommandException {
    checkPermission(sender, FoodPermissions.UC_FOOD_FOOD_BASE);
    if (!args.hasAny("player")) {
        checkIfPlayer(sender);
        Player p = (Player) sender;
        p.offer(Keys.FOOD_LEVEL, p.get(FoodData.class).get().foodLevel().getMaxValue());
        p.offer(Keys.SATURATION, ItemStack.builder().itemType(ItemTypes.COOKED_BEEF).build().getProperty(SaturationProperty.class).get().getValue());
        Messages.send(p, "food.command.food.success.self");
        return CommandResult.success();
    } else {
        checkPermission(sender, FoodPermissions.UC_FOOD_FOOD_OTHERS);
        Player t = args.<Player>getOne("player").get();
        t.offer(Keys.FOOD_LEVEL, t.get(FoodData.class).get().foodLevel().getMaxValue());
        t.offer(Keys.SATURATION, ItemStack.builder().itemType(ItemTypes.COOKED_BEEF).build().getProperty(SaturationProperty.class).get().getValue());
        Messages.send(sender, "food.command.food.success.others.self", "%player%", t);
        Messages.send(t, "food.command.food.success.others.others", "%player%", sender);
        return CommandResult.success();
    }
}
 
Example #20
Source File: InventoryListener.java    From Prism with MIT License 6 votes vote down vote up
/**
 * Saves event records when a player picks up an item off of the ground.
 *
 * @param event  ChangeInventoryEvent.Pickup
 * @param player Player
 */
@Listener(order = Order.POST)
public void onChangeInventoryPickup(ChangeInventoryEvent.Pickup event, @Root Player player) {
    if (event.getTransactions().isEmpty() || !Prism.getInstance().getConfig().getEventCategory().isItemPickup()) {
        return;
    }

    for (SlotTransaction transaction : event.getTransactions()) {
        ItemStackSnapshot itemStack = transaction.getFinal();
        int quantity = itemStack.getQuantity();
        if (transaction.getOriginal().getType() != ItemTypes.NONE) {
            quantity -= transaction.getOriginal().getQuantity();
        }

        Prism.getInstance().getLogger().debug("Inventory pickup - {} x{}", itemStack.getType().getId(), quantity);

        PrismRecord.create()
                .source(event.getCause())
                .event(PrismEvents.ITEM_PICKUP)
                .itemStack(itemStack, quantity)
                .location(player.getLocation())
                .buildAndSave();
    }
}
 
Example #21
Source File: ConfigManager.java    From RedProtect with GNU General Public License v3.0 5 votes vote down vote up
public ItemStack getGuiSeparator() {
    ItemStack separator = ItemStack.of(Sponge.getRegistry().getType(ItemType.class, guiRoot.gui_separator.material).orElse(ItemTypes.GLASS_PANE), 1);
    separator.offer(Keys.DISPLAY_NAME, RedProtect.get().guiLang.getFlagString("separator"));
    separator.offer(Keys.ITEM_DURABILITY, guiRoot.gui_separator.data);
    separator.offer(Keys.ITEM_LORE, Arrays.asList(Text.EMPTY, RedProtect.get().guiLang.getFlagString("separator")));
    return separator;
}
 
Example #22
Source File: MoreCommand.java    From UltimateCore with MIT License 5 votes vote down vote up
@Override
public CommandResult execute(CommandSource sender, CommandContext args) throws CommandException {
    checkIfPlayer(sender);
    checkPermission(sender, ItemPermissions.UC_ITEM_MORE_BASE);
    Player p = (Player) sender;
    if (p.getItemInHand(HandTypes.MAIN_HAND).getType().equals(ItemTypes.NONE)) {
        throw new ErrorMessageException(Messages.getFormatted(p, "item.noiteminhand"));
    }
    ItemStack stack = p.getItemInHand(HandTypes.MAIN_HAND);
    stack.setQuantity(stack.getMaxStackQuantity());
    p.setItemInHand(HandTypes.MAIN_HAND, stack);
    Messages.send(p, "item.command.more.success", "%amount%", stack.getMaxStackQuantity());
    return CommandResult.success();
}
 
Example #23
Source File: ItemenchantCommand.java    From UltimateCore with MIT License 5 votes vote down vote up
@Override
public CommandResult execute(CommandSource sender, CommandContext args) throws CommandException {
    checkIfPlayer(sender);
    checkPermission(sender, ItemPermissions.UC_ITEM_ITEMENCHANT_BASE);
    Player p = (Player) sender;

    if (p.getItemInHand(HandTypes.MAIN_HAND).getType().equals(ItemTypes.NONE)) {
        throw new ErrorMessageException(Messages.getFormatted(p, "item.noiteminhand"));
    }
    ItemStack stack = p.getItemInHand(HandTypes.MAIN_HAND);

    EnchantmentType ench = args.<EnchantmentType>getOne("enchantment").get();
    int level = args.hasAny("level") ? args.<Integer>getOne("level").get() : 1;

    if (level > ItemPermissions.UC_ITEM_ITEMENCHANT_MAXLEVEL.getIntFor(p)) {
        throw Messages.error(p, "item.command.itemenchant.maxlevel", "%max%", ItemPermissions.UC_ITEM_ITEMENCHANT_MAXLEVEL.getIntFor(p));
    }

    List<Enchantment> enchs = stack.get(Keys.ITEM_ENCHANTMENTS).orElse(new ArrayList<>());
    if (level > 0) {
        enchs.add(Enchantment.builder().type(ench).level(level).build());
        stack.offer(Keys.ITEM_ENCHANTMENTS, enchs);
        p.setItemInHand(HandTypes.MAIN_HAND, stack);
        Messages.send(sender, "item.command.itemenchant.success", "%enchant%", ench.getTranslation().get(), "%level%", level);
        return CommandResult.success();
    } else {
        enchs = enchs.stream().filter(e -> !e.getType().equals(ench)).collect(Collectors.toList());
        stack.offer(Keys.ITEM_ENCHANTMENTS, enchs);
        p.setItemInHand(HandTypes.MAIN_HAND, stack);
        Messages.send(sender, "item.command.itemenchant.success2", "%enchant%", ench.getTranslation().get(), "%level%", level);
        return CommandResult.success();
    }
}
 
Example #24
Source File: VersionHelper8.java    From RedProtect with GNU General Public License v3.0 5 votes vote down vote up
@Override
public ItemType getItemInHand(Player player) {
    if (!player.getItemInHand(HandTypes.MAIN_HAND).isEmpty()) {
        return player.getItemInHand(HandTypes.MAIN_HAND).getType();
    } else if (!player.getItemInHand(HandTypes.OFF_HAND).isEmpty()) {
        return player.getItemInHand(HandTypes.OFF_HAND).getType();
    }
    return ItemTypes.NONE;
}
 
Example #25
Source File: VersionHelper7.java    From RedProtect with GNU General Public License v3.0 5 votes vote down vote up
@Override
public ItemType getItemInHand(Player player) {
    if (player.getItemInHand(HandTypes.MAIN_HAND).isPresent()) {
        return player.getItemInHand(HandTypes.MAIN_HAND).get().getType();
    } else if (player.getItemInHand(HandTypes.OFF_HAND).isPresent()) {
        return player.getItemInHand(HandTypes.OFF_HAND).get().getType();
    }
    return ItemTypes.NONE;
}
 
Example #26
Source File: HuskyUI.java    From HuskyUI-Plugin with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Handle inventory clicks
 * @param event clickinvevent
 */
@Listener(order = Order.PRE)
public void onItemClick(ClickInventoryEvent event){
    try {
        if (event instanceof ClickInventoryEvent.Primary ||
                event instanceof ClickInventoryEvent.Secondary ||
                event instanceof ClickInventoryEvent.Shift ||
                event instanceof ClickInventoryEvent.Creative) {

            ItemStack affected;
            affected = event.getTransactions().get(0).getOriginal().createStack();
            if (event instanceof ClickInventoryEvent.Shift && (affected.getType() == ItemTypes.AIR || affected.getType() == ItemTypes.NONE)) {
                affected = event.getTransactions().get(0).getDefault().createStack();
            }
            Optional<Integer> potentialID = registry.getElementIDFromItemStack(affected);
            if (potentialID.isPresent()) {
                if (registry.elementExists(potentialID.get())) {
                    if (registry.isElementAuto(potentialID.get())) {
                        if (event.getTransactions().get(0).getSlot().parent().getArchetype().equals(InventoryArchetypes.PLAYER)) {
                            if (registry.isElementFixedAuto(potentialID.get())) {
                                event.setCancelled(true);
                            }
                        } else {
                            event.setCancelled(true);
                        }
                    }
                }
            }
        }
    }catch(Exception ignored){}
}
 
Example #27
Source File: ProtectionManagerImpl.java    From EagleFactions with MIT License 5 votes vote down vote up
private boolean isHoldingEagleFeather(final User user)
{
    return user.getItemInHand(HandTypes.MAIN_HAND).isPresent()
            && user.getItemInHand(HandTypes.MAIN_HAND).get().getType() == ItemTypes.FEATHER
            && user.getItemInHand(HandTypes.MAIN_HAND).get().get(Keys.DISPLAY_NAME).isPresent()
            && user.getItemInHand(HandTypes.MAIN_HAND).get().get(Keys.DISPLAY_NAME).get().equals(EagleFeather.getDisplayName());
}
 
Example #28
Source File: EntityListener.java    From RedProtect with GNU General Public License v3.0 5 votes vote down vote up
@Listener(order = Order.FIRST, beforeModifications = true)
public void onAttemptInteractAS(InteractEntityEvent e, @First Player p) {

    Entity ent = e.getTargetEntity();
    Location<World> l = ent.getLocation();
    Region r = RedProtect.get().rm.getTopRegion(l, this.getClass().getName());

    if (r == null) {
        //global flags
        if (ent.getType().equals(EntityTypes.ARMOR_STAND)) {
            if (!RedProtect.get().config.globalFlagsRoot().worlds.get(l.getExtent().getName()).build) {
                e.setCancelled(true);
                return;
            }
        }
        return;
    }

    ItemType itemInHand = RedProtect.get().getVersionHelper().getItemInHand(p);

    if (!itemInHand.equals(ItemTypes.NONE) && itemInHand.getType().equals(ItemTypes.ARMOR_STAND)) {
        if (!r.canBuild(p)) {
            e.setCancelled(true);
            RedProtect.get().lang.sendMessage(p, "blocklistener.region.cantbuild");
            return;
        }
    }

    //TODO Not working!
    if (ent.getType().equals(EntityTypes.ARMOR_STAND)) {
        if (!r.canBuild(p)) {
            if (!RedProtect.get().ph.hasPerm(p, "redprotect.bypass")) {
                RedProtect.get().lang.sendMessage(p, "playerlistener.region.cantedit");
                e.setCancelled(true);
            }
        }
    }
}
 
Example #29
Source File: ElementRegistry.java    From HuskyUI-Plugin with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Convert an ItemStack into an ElementID
 *
 * @param stack ItemStack to pull ElementID from
 * @return ElementID, if it exists. This ID may not actually be associated with an Element, so please verify that before use with {@link #elementExists(int)}.
 */
public Optional<Integer> getElementIDFromItemStack(ItemStack stack){
    if(stack.getType() == ItemTypes.AIR || stack.getType() == ItemTypes.NONE) return Optional.empty();
    Optional<Object> optRegID = stack.toContainer().get(DataQuery.of("UnsafeData", "regid"));
    if(optRegID.isPresent()){
        return Optional.of((int)optRegID.get());
    }
    return Optional.empty();
}
 
Example #30
Source File: FlagGui.java    From RedProtect with GNU General Public License v3.0 5 votes vote down vote up
@Listener
public void onInventoryClick(ClickInventoryEvent event) {
    if (event.getTargetInventory().getName().get().equals(this.inv.getName().get())) {

        if (this.editable) {
            return;
        }

        if (event.getTransactions().size() > 0) {
            Transaction<ItemStackSnapshot> clickTransaction = event.getTransactions().get(0);

            ItemStack item = clickTransaction.getOriginal().createStack();

            if (!RedProtect.get().getVersionHelper().getItemType(item).equals(ItemTypes.NONE) && item.get(Keys.ITEM_LORE).isPresent()) {
                String flag = item.get(Keys.ITEM_LORE).get().get(1).toPlain().replace("ยง0", "");
                if (RedProtect.get().config.getDefFlags().contains(flag)) {
                    if (RedProtect.get().config.configRoot().flags_configuration.change_flag_delay.enable) {
                        if (RedProtect.get().config.configRoot().flags_configuration.change_flag_delay.flags.contains(flag)) {
                            if (!RedProtect.get().changeWait.contains(this.region.getName() + flag)) {
                                applyFlag(flag, item, event);
                                RedProtect.get().getUtil().startFlagChanger(this.region.getName(), flag, this.player);
                            } else {
                                RedProtect.get().lang.sendMessage(player, RedProtect.get().lang.get("gui.needwait.tochange").replace("{seconds}", RedProtect.get().config.configRoot().flags_configuration.change_flag_delay.seconds + ""));
                                event.setCancelled(true);
                            }
                            return;
                        } else {
                            applyFlag(flag, item, event);
                            return;
                        }
                    } else {
                        applyFlag(flag, item, event);
                        return;
                    }
                }
                event.setCancelled(true);
            }
        }
    }
}