How to send a request for someone to duel?

Discussion in 'Plugin Development' started by MinecraftBoxGut, Dec 11, 2016.

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

    MinecraftBoxGut

    I have a PvP plugin and I would like to know how to send a request if a player would like to duel after a right click, with a timeout. Here is my current code:
    Code:
       @EventHandler()
    public void playerOneCl(PlayerInteractEntityEvent e) {
            
             if (e.getPlayer().getInventory().getItemInHand().getType() == Material.BLAZE_ROD) {
               
                 e.getPlayer().sendMessage("Starting...");
                 if(e.getRightClicked() instanceof Player) {
                     if (dict.get(e.getRightClicked())== null) {
                 Player p = (Player) e.getRightClicked();
                 p.sendMessage(ChatColor.GREEN + "" + e.getPlayer().getName() + "has started a duel");
                 Title title = new Title("You're dueling with " , p.getName(),4,5,4);
                 title.setTitleColor(ChatColor.RED);
                 title.setSubtitleColor(ChatColor.GREEN);
    
                 title.send(e.getPlayer());
                 
                 e.getPlayer().sendMessage(ChatColor.GOLD + "Duel started");
                 for (Player a : getServer().getOnlinePlayers())
                  {
                    if (!a.getName().equals(p.getName()) && !a.getName().equals(e.getPlayer().getName())) {
                      p.hidePlayer(a);
                      e.getPlayer().hidePlayer(a);
                   
                    }
                    }
                  ********
    }
     
  2. Offline

    Zombie_Striker

    Make sure the item is not null. If the player is not holding anything, the item will be null and this will throw an NPE

    What is this line? If this is a collection or map, use the .contains method instead of nullchecking.

    Instead of cvomparing names, why not compare memory spaces. That reduced this to
    Code:
    if(a!=p&&a!=e.getPlayer)
    Main problem: Since we do not know what system you currently have for sending or receiving requests, we cannot really help you. We will be able to help you once you post how you handle requests.
     
  3. Offline

    MinecraftBoxGut

    @Zombie_Striker I don't currently have a system for sending and receiving request, but I would like it to be a tellraw that runs a command when pressed and has a timeout, the dictionary is a command that tells you who the player is duelling, or if they are not duelling anyone.
     
    Last edited: Dec 11, 2016
  4. Offline

    Lordloss

    And what exactly stops you from doing it?
     
  5. Offline

    MinecraftBoxGut

    @Lordloss I don't know how to make a command which stores them and has a timeout on each person.
     
  6. Offline

    mythbusterma

    @MinecraftBoxGut

    Since it needs a timeout, I would create a data carrier Object that has two UUIDs (the sender and sendee) and a time the request was made (in milliseconds). You could foreseeably create a list of these requests, and then iterate over it to find matching requests, checking the timeout to see if they are still valid, and discarding invalid ones.
     
    Lordloss likes this.
Thread Status:
Not open for further replies.

Share This Page