Thread: [530] (Xenorune) - Spawn Command

Results 1 to 3 of 3
  1. #1 [530] (Xenorune) - Spawn Command 
    Sexy User
    User's Avatar
    Join Date
    Apr 2013
    Posts
    603
    Thanks given
    97
    Thanks received
    218
    Rep Power
    346
    Ello, was playing around on this old source and got bored so I added an item db lookup type command for those of us who are too lazy to go to itemdb.biz

    Thought someone out there might enjoy it as well, nothing much just a simple command.

    Uses:
    ::itemn dragon dag $noted #400
    ::itemn dragon $list

    Looks like this (kinda color coded)


    Can easily be converted to whatever source you use I guess if you don't like your current version of it. Cheers m8.

    Code:
    package com.xeno.packethandler.commands;
    
    import java.util.ArrayList;
    import java.util.Iterator;
    import java.util.List;
    
    import com.xeno.model.ItemDefinition;
    import com.xeno.model.player.Player;
    
    /**
     * <b>Creation:</b> 1/24/16<br><br>
     * Item search and spawn command.
     * @author Phillip
     */
    public class ItemSearch implements Command {
        
        /**
         * Conducts a search from the database by name given.
         * @param spawn    If the first result should be spawned.
         * @param name    The given attributes for finding the item.
         */
        private void search(Player player, String... name) {
            StringBuilder sb = new StringBuilder("");
            int quantitySpecification = 1;
            boolean noted = false;
            boolean listResults = false;
            for (int i = 0; i < name.length; i++) {
                if (name[i].startsWith("#")) {
                    quantitySpecification = Integer.valueOf(name[i].substring(1));
                    continue;
                } else if (name[i].equals("$noted")) {
                    noted = true;
                    continue;
                } else if (name[i].equals("$list")) {
                    listResults = true;
                    continue;
                }
                sb.append(name[i] + " ");
            }
            System.out.println("Search Terms: Contains '" + sb.toString().trim() + "' Qty: " + quantitySpecification + " Noted: " + noted + " Listing Results: " + listResults);
            List<ItemDefinition> list = find(sb.toString().trim());
            for (Iterator<ItemDefinition> iterator = list.iterator(); iterator.hasNext();) {
                ItemDefinition def = iterator.next();
                if (def == null)
                    continue;
                if (!listResults) {
                    player.getActionSender().sendMessage("Spawned " + quantitySpecification + "x " + def.getName() + (noted ? " (noted)" : "") + " <col=880000>(" + def.getId() + ")"
                            + "</col>. Search Result: (1/" + list.size() + ")");
                    spawn(player, def.getId(), quantitySpecification, noted);
                    return;
                } else {
                    player.getActionSender().sendMessage("Found " + def.getName() + " <col=880000>(" + def.getId() + ")");
                }
                System.out.println("Found " + def.getName() + " (" + def.getId() + ")");
            }
        }
        
        private void spawn(Player player, int id, int amount, boolean noted) {
            ItemDefinition defs = ItemDefinition.forId(id);
            int finalId = noted ? (defs.isNoted() || defs.isStackable() ? id : id + 1) : id;
            if (ItemDefinition.forId(finalId).getName().equals(defs.getName()))
                player.getInventory().addItem(finalId, amount);
            else {
                player.getActionSender().sendMessage("There was a problem finding the note id for this item!");
                player.getInventory().addItem(id, amount);
            }
        }
        
        /**
         * Returns a database lookup from the id.
         */
        private List<ItemDefinition> find(String str) {
            List<ItemDefinition> list = new ArrayList<>();
            for (ItemDefinition def : ItemDefinition.getDefinitions().values()) {
                if (def.getName().toLowerCase().contains(str.toLowerCase())) {
                    list.add(def);
                }
            }
            return list;
        }
    
        @Override
        public void execute(Player player, String command) {
            if (command.length() < 7)
                return;
            command = command.substring(6);
            String cmd[] = command.split(" ");
            if (cmd.length < 1) {
                return;
            }
            search(player, cmd);
        }
    
        @Override
        public int minimumRightsNeeded() {
            return 0;
        }
    
    }
    Reply With Quote  
     

  2. #2  
    Super Donator

    Join Date
    Oct 2008
    Posts
    328
    Thanks given
    34
    Thanks received
    20
    Rep Power
    66
    nasty, 2016, and you're posting this wat

    edit
    idk if this is right, I'm drunk
    Code:
            if (StringUtils.isNumeric(args[1])) {
                player.getInventory().add(new Item(Integer.parseInt(args[1]), Integer.parseInt(args[2])));
                return;
            }
            if (args[1].startsWith("s:")) {
                for (ItemDefinition itemDefinition : ItemDefinition.values()) {
                    if (itemDefinition.getName().toLowerCase().contains(args[1])) {
                        player.getActionSender().sendMessage(itemDefinition.getName() + ": " + itemDefinition.getId());
                        break;
                    }
                }
            }
            for (ItemDefinition itemDefinition : ItemDefinition.values()) {
                if (itemDefinition.getName().toLowerCase().contains(args[1])) {
                    player.getInventory().add(new Item(Integer.parseInt(args[1]), args.length == 3 ? Integer.parseInt(args[2]) : 1));
                    break;
                }
            }
    stringutils
    Code:
            <dependency>
                <groupId>org.apache.commons</groupId>
                <artifactId>commons-compress</artifactId>
                <version>1.10</version>
            </dependency>
    [Only registered and activated users can see links. ]



    ::item 995 1
    ::item armadyl_godsword
    ::item armadyl_godsword 1
    ::item armadyl - search results
    do the parameter checks or w/e
    menth
    Reply With Quote  
     

  3. #3  
    Sexy User
    User's Avatar
    Join Date
    Apr 2013
    Posts
    603
    Thanks given
    97
    Thanks received
    218
    Rep Power
    346
    Quote Originally Posted by M,i,K,e_ View Post
    nasty, 2016, and you're posting this wat
    2016 and people still posting dumbass comments trying to make themselves feel important in the rsps scene
    Reply With Quote  
     

  4. Thankful user:



Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)


User Tag List

Similar Threads

  1. [508]My sexy item spawning command[508]
    By Cocaine in forum Configuration
    Replies: 26
    Last Post: 04-02-2011, 06:08 PM
  2. ::object spawning command
    By Aaron C. in forum Requests
    Replies: 1
    Last Post: 04-26-2009, 06:04 PM
  3. npc spawn command [508]
    By mige5 in forum Help
    Replies: 1
    Last Post: 02-19-2009, 06:16 PM
  4. Npc spawning command
    By jareq in forum Requests
    Replies: 7
    Last Post: 02-13-2009, 02:56 AM
  5. Loads of spawning commands
    By Pie in forum Configuration
    Replies: 7
    Last Post: 12-22-2008, 04:30 PM
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •