Solved Recipe / RealName Command ?

Discussion in 'Plugin Development' started by Astrophylite, Sep 6, 2015.

Thread Status:
Not open for further replies.
  1. Hey all,

    I have just made a message command, but I don't know how to create the reply part of it... I know I have to use HashMaps but that is about it..

    Any help will be appreciated,
    _Zircon_

    Wanna help with the plugin? (open)
    What should I add to my plugin next?
    I currently have:
    • Freeze
    • AFK
    • Heal
    • Feed
    • Pranking
    • MOTD
    • Teleporting
    • Spawn
    • MOTD
    • Kits
    • ClearInventory
    • Announcer
    • Warping
    • Moderation (Kick, Ban, Mute)
    • OP, DeOP, IsOP
    • Ignore
    • List
    • ClearChat
    • GameMode
    • Fly
    • God
    • Vanish
    • InvSee
    • HelpOP
    • StaffChat
    • Message
    • Emote
    Any ideas? Post below :)
     
  2. Offline

    SuperSniper

    Use a hashmap of <Player, Player>
    Code:
    HashMap<Player, Player> reply = new HashMap<Player, Player>();
    
    once a message is sent to a player, cast the message RECIEVER to a player, and then do this:
    Code:
    reply.put(sender, reciever);
    
    Once someone does /reply or whatever you want, do this:
    Code:
    // get all of the args into one string
    Player r = (Player)reply.get(sender);
    r.sendMessage(allArgs);
    
    That should work out how you want it to. I hope I made it clear enough, if this doesn't work, sorry, I am really tired as of making this post :p
     
  3. Thanks for the reply. I'll try it out now...

    Okay, it works.
    One more question though: how can I make an ItemStack from an argument, like how Essentials has /i ITEM ?

    EDIT: And how would I do a /realname?
    My plugin has support for nicknames and it sets the player's display name to said nickname, but how do I then take that nickname and put it back into the player's real name ?

    <Edited by bwfcwalshy: Merged posts, please use the edit button rather than double posting.>
     
    Last edited by a moderator: Sep 6, 2015
  4. player.getName() returns the real name.
     
  5. I know that part, but how do I make it so that they give the nickname and it sends them the player's real name ?

    EDIT: Also, how do I make a recipe command? Much like how Essentials when you do /recipe <item>, it displays all the recipes for that item, how would I do that ?
     
    Last edited: Sep 6, 2015
  6. Offline

    ZP18

    If you have a HashMap of player, player hen when getting the reciever from the map, you don't need to cast it to a player as it should already be a player
     
  7. I have got the reply working. The part I am stuck on is the realname command and the recipe command.
     
  8. Is anyone able to help me with this realname command ?
     
  9. Offline

    mythbusterma

    @SuperSniper @_zircon_

    Don't store a reference to a Player like that, unless you're 9001% certain that you will remove them from the Map as soon as the player logs out. Which I'm certain you're not doing. And your post doesn't mention.
     
  10. @bwfcwalshy Sooooo many people have told me that, but how would I allow them to input a nickname? Bukkit.getServer().getPlayer(name); expects the actual name so I can't use that. Same with Bukkit.getServer().matchPlayer(name) and Bukkit.getServer().getOfflinePlayer(name); so I am really stuck...

    EDIT: @mythbusterma I will change that now, thanks ;)
     
  11. Offline

    mythbusterma

    @_zircon_

    Use their name or UUID instead.

    You could also iterate over every Player on the server, checking their display name (that's now getPlayer(...) works, but with the actual name instead of the display one).
     
  12. Oh okay. Thanks @mythbusterma !

    EDIT: Hmm... It isn't working for some reason.
    Code:
    for(Player p : Bukkit.getOnlinePlayers()) {
        if(p.getDisplayName().equalsIgnoreCase(args[0].toString()) {
            sender.sendMessage(ChatColor.AQUA + "Player " + args[0].toString() + "'s realname is "
                + p.getName();
            break;
        }
    }
    return true;
    
    EDIT2: Also, how would I make an EnderChest command?? I have tried creating a new inventory grabbing the target's enderchest but that doesn't work, and I've tried using target.getEnderChest(); but that doesn't work either. So how would I do that ?
     
    Last edited: Sep 7, 2015
  13. Offline

    mythbusterma

    @_zircon_

    Keep in mind that this means they'd also have to type any colours that are in their name, which is very difficult to do.
     
  14. @mythbusterma I did /realname &7&l_&6&lZircon&7&l_ but it didn't return anything. No console errors etiher.

    EDIT: I addreesed this in my last post, but how would I make an enderchest command ??
     
  15. Offline

    timtower Administrator Administrator Moderator

    @_zircon_ Strip the colors of the displayname / alias / what you might be using, then use /realname without the colors
     
  16. I just did that and it still didn't return anything ? No console errors again.

    EDIT: Anyone ??
     
    Last edited: Sep 7, 2015
  17. Offline

    RoboticPlayer

    To do an enderchest, it's quite simple. To do it on yourself, do:
    Code:
                if (args.length == 0) {
                    Inventory i = p.getEnderChest();
    
                    p.openInventory(i);
                    return true;
                }
    In the above, "p" is the sender, make sure you check that the sender is a player first.
    To do someone else's, it's literally the exact same thing except get the target's enderchest instead of the sender's.
     
  18. Offline

    SuperSniper

    @_zircon_
    To make an enderchest command, do this:
    Code:
    // onCommand stuff.
    // check the command (enderchest)
    Inventory enderchest = player.getEnderChest();
    player.openInventory(enderchest);
    
    If you want to make it enderchest (player), do this:
    Code:
    // onCommand stuff.
    // check the command (enderchest)
    Player targetPlayer = Bukkit.getPlayer(args[0]);
    Inventory targetEnderChest = targetPlayer.getEnderChest();
    player.openInventory(targetEnderChest);
    
    
    EDIT: Got the idea to make this post after seeing @henderry2019 's
     
  19. @SuperSniper Thanks for the help, but now, how do I give it a custom name so that I can block them from taking stuff in / out of the EnderChest that they are viewing ?

    EDIT: Also (completely off topic here), how do I remove a permission from someone when they run a command ?
     
    Last edited: Sep 8, 2015
  20. I don't know if getHolder() will return the owner, if it does you can on InventoryClickEvent check if the player who's clicking doesn't equals to the Holder and then cancel.

    If getHolder() does return the owner of the EnderChest you can try creating your own Inventory with a custom InventoryHolder and putting the items from the EnderChest there, and then on InventoryClickEvent check if the holder is your custom InventoryHolder and if it is cancel the event.
     
  21. @MaTaMoR_ I don't think that will work ;( Good suggestion though. Reason why it won't work is because I use an onCommand method and the InventoryClickEvent can't pick up the target sadly...

    Another ideas?
    _Zircon_
     
  22. No-one has replied to this thread in ages, so sorry for bumping a dead thread, I was supposed to mark this a solved for ages.
    All I needed to do was strip the colours from the player's nickname xD
     
Thread Status:
Not open for further replies.

Share This Page