A request command like TPA

Discussion in 'Plugin Development' started by Knaxel, Apr 23, 2013.

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

    Knaxel

    Here's what i have so far
    Code:
    package Main;
     
    import java.util.HashMap;
     
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.Material;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.event.Listener;
    import org.bukkit.event.inventory.InventoryType;
    import org.bukkit.inventory.Inventory;
    import org.bukkit.inventory.ItemStack;
     
    public class CommandExucutor implements CommandExecutor, Listener {
    public HashMap<Player, Player> hashmap = new HashMap<Player, Player>();
    public HashMap<Player, Player> hashmap2 = new HashMap<Player, Player>();
    public HashMap<Player, Player> hashmap3 = new HashMap<Player, Player>();
    public HashMap<Player, Player> hashmap4 = new HashMap<Player, Player>();
    public HashMap<Player, Player> hashmap5 = new HashMap<Player, Player>();
    public Player SenderPlayer;
    public Player TargetPlayer;
    public Inventory inventory;
    boolean toggle = false;
     
    public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
     
    if(args == null){
    sender.sendMessage(ChatColor.RED + "Usage: '/rps help'");
    }
    if(args[0] == "help"){
    sender.sendMessage("'/rps help' - Display's all RPS commands");
    sender.sendMessage("'/rps <Player_Name>'- Request a game with another player");
    sender.sendMessage("'/rps accept' - Accept a request");
    sender.sendMessage("'/rps deny' - Deny a request");
    }
    if(args[0] != "accept" || args[0] != "deny" || args[0] != "help"){
    if(args[0] == null){
    sender.sendMessage( args[0] + " Is not online at the moment or is not a charachter");
    return true;
    }
     
    SenderPlayer = (Player) sender;
    TargetPlayer = Bukkit.getServer().getPlayer(args[0]);
     
     
    }
    if(args[0] == "accept" && sender == TargetPlayer){
    Inventory inventorys = Bukkit.createInventory(TargetPlayer, InventoryType.CHEST);
    inventory.setItem(0, new ItemStack(Material.COBBLESTONE));
    inventory.setItem(1, new ItemStack(Material.PAPER));
    inventory.setItem(1, new ItemStack(Material.SHEARS));
    Player SPlayer = (Player) sender;
    SPlayer.openInventory(inventory);
    SenderPlayer.openInventory(inventory);
    inventory = inventorys;
     
    }
    return true;
    }
    }
    but i don't know where to go from here i've tried everything, how is a TPA request made could someone help me out?
     
  2. Offline

    Tirelessly

    I have no idea why you have so many hashmaps. You only need one.
    Don't store player objects, store their names.
    args will never be null, it will just be empty.
    You can't compare strings or other objects using ==, you must use .equals()
    Keep your variables at the lowest scope possible; Don't have SenderPlayer/TargetPlayer/etc as global variables

    And others.
     
  3. Offline

    Knaxel

    @Tirelesslyi was expirementing, heres what i have now but it wtill didn't work... i used .equals and stored both there names and players saved, no working..
    Code:
    package Main;
     
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.Material;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.event.Listener;
    import org.bukkit.event.inventory.InventoryType;
    import org.bukkit.inventory.Inventory;
    import org.bukkit.inventory.ItemStack;
     
    public class CommandExucutor implements CommandExecutor, Listener {
    public Player SenderPlayer;
    public String SenderPlayerN;
    public Player TargetPlayer;
    public String TargetPlayerN;
    public Inventory inventory;
    boolean toggle = false;
     
    public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
     
    if(args == null){
    sender.sendMessage(ChatColor.RED + "Usage: '/rps help'");
    }
    if(args[0].equalsIgnoreCase("help")){
    sender.sendMessage("'/rps help' - Display's all RPS commands");
    sender.sendMessage("'/rps <Player_Name>'- Request a game with another player");
    sender.sendMessage("'/rps accept' - Accept a request");
    sender.sendMessage("'/rps deny' - Deny a request");
    }
    if(args[0] == null){
    sender.sendMessage( args[0] + " Is not online at the moment or is not a charachter");
    return true;
    }
     
    SenderPlayer = (Player) sender;
    SenderPlayerN = SenderPlayer.getName();
    TargetPlayer = Bukkit.getServer().getPlayer(args[0]);
    TargetPlayerN = args[0];
     
    if(args[0].equalsIgnoreCase("accept") && sender.getName().equalsIgnoreCase(TargetPlayerN)){
    Inventory inventorys = Bukkit.createInventory(TargetPlayer, InventoryType.CHEST);
    inventory.setItem(0, new ItemStack(Material.COBBLESTONE));
    inventory.setItem(1, new ItemStack(Material.PAPER));
    inventory.setItem(1, new ItemStack(Material.SHEARS));
    Player SPlayer = (Player) sender;
    SPlayer.openInventory(inventory);
    SenderPlayer.openInventory(inventory);
    inventory = inventorys;
     
    }
    return true;
    }
    }
    
     
  4. Offline

    bellegueule

    args will never be null..

    Code:
    if(args.lenght == 0){}//  /rps = o agrs
     
    if(args.lenght == 1){}//  /rps <player name> = 1 agrs
     
    
     
  5. Offline

    Knaxel

  6. Offline

    kreashenz

    To do this a kind of simple way, couldn't you do something like :
    Code:
    have a hashmap to store
    // boolean
    // command name, sender, permissions
    scheduler to remove the player off the hashmap
    wait X seconds
    teleport the player
    Something like that, I guess?
     
  7. Offline

    Knaxel

    kreashenz well you see im not trying to makethe teleport im making it a bit diferent.
     
  8. Offline

    kreashenz

    Knaxel Honestly I don't see.. So, sorry for getting it wrong.
     
  9. Offline

    ZeusAllMighty11

    cool, you going to tell us how you want to make it, or are you just going to sit there and expect us to know..


    And you didn't even listen to anyone in this thread
     
  10. Offline

    skore87

    An enum is an object and you can use the == operator. But that is, of course, if they are used in a static/global fashion where you compare if two references point to the same object.

    e.g. if (item.getType() == Material.Whatever)...

    Check out this link: http://tothepointtalks.blogspot.com/2009/05/equals-vs-in-java_06.html
     
  11. Offline

    Tirelessly

    I know. You know what I mean. There was no need for this post.
     
Thread Status:
Not open for further replies.

Share This Page