[UNSOLVED]My plugin code help

Discussion in 'Plugin Development' started by spookyDHD, Dec 15, 2013.

Thread Status:
Not open for further replies.
  1. Offline

    spookyDHD

    Hi, i'm making a minigame but i don't know how to do something.

    I want to if someone typed /ts friend <name> that they aren't can kill each other anymore until the game has ended.

    Who has a example?
     
  2. Offline

    Gopaintman

    When that command is called, put the players' name in a hashmap (In any order)

    Create an EntityDamageByEntity Event.
    Check to make sure that both entities are players.
    Then check if the player hitting the other player is key or a value in the hashmap.
    if its a key, then get the value from their name and check it against the player's name who got hit. Cancel event
    if its a value, then use a "getkeyfromvalue" method and basically do the same thing from the other condition.
    otherwise do nothing.
     
  3. Offline

    Webster56

    You could extend Player and add an ArrayList<Player> that would contain your friends

    When the player types your command, it adds the name in the list

    And when he deals damage through an EntityDamageEvent, if the target is an instance of the Player class and is contained in the list, you cancel the action.
     
  4. Offline

    spookyDHD

    Ok i'm going to try it, thx!

    I want to use a command that runs a event but how i need to do it???

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 5, 2016
  5. Offline

    Gopaintman

  6. Offline

    spookyDHD

    i'm going to looking on it, thx

    i don't understand it can you help


    My code:


    Code:java
    1. package me.Ricardo.TeamSurvival.cmds;
    2.  
    3. import org.bukkit.entity.Player;
    4. import org.bukkit.event.EventHandler;
    5. import org.bukkit.event.Listener;
    6. import org.bukkit.event.entity.EntityDamageByEntityEvent;
    7.  
    8. public class Friend extends SubCommand implements Listener {
    9.  
    10. @EventHandler
    11. public void EntityDamage(EntityDamageByEntityEvent e) {
    12.  
    13. }
    14.  
    15. public void onCommand(Player p, String[] args) {
    16.  
    17. }
    18.  
    19. public String name() {
    20. return "friend";
    21. }
    22.  
    23. public String info() {
    24. return "Added a friend!.";
    25. }
    26.  
    27. public String[] aliases() {
    28. return new String[] { "f" };
    29.  
    30. }
    31.  
    32. }
    33.  
    34.  
    35.  
    36.  
    37.  
    38.  
    39.  
    40.  


    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 5, 2016
  7. Offline

    AzubuSan

    spookyDHD Um...If I were you I'd look at the API a bit more..

    EDIT: ^ Random note without looking at his code more then once...might be wrong xD
     
  8. Offline

    bobthefish

    spookyDHD

    So this is extreme psuedocode, but something like

    on command{
    if command = ts{
    if args.length = 1{
    player.sendmessage(not enough args);
    }
    if args.length = 2{
    if args[1] = friend{
    Player friend = getPlayer(args[2])
    //put friend into a hashmap, Im not sure exactly how to this, as I havent used hasmaps in a while, and im deffenitly not a pro developer xD
    }
    }
    }
    }

    and then in the Entity damge event, you could chack if the taarget is in that hashmap, and if they are, then cancel the damage (again, not comletly sure how to that, but Im pretty sure its poosible

    sorry if this all wrong, but Im pretty sure Im not hat bad at doing this :D
     
Thread Status:
Not open for further replies.

Share This Page