How to answer?

Discussion in 'Plugin Development' started by CraftRay, Mar 28, 2016.

Thread Status:
Not open for further replies.
  1. How to do it?
    line 40

    import java.util.HashMap;
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.Location;
    import org.bukkit.Sound;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Entity;
    import org.bukkit.entity.Player;
    import org.bukkit.event.Listener;
    import org.bukkit.plugin.Plugin;
    public class Friends implements Listener {
        HashMap<String,String> mapa = new HashMap<>();
         public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args){
                if(cmd.getName().equalsIgnoreCase("znajomi") || cmd.getName().equalsIgnoreCase("friends") || cmd.getName().equalsIgnoreCase("z") || cmd.getName().equalsIgnoreCase("f")){
                        sender.sendMessage(ChatColor.RED + "Nie możesz dodać samego siebie do listy znajomych!");
                        Player player = Bukkit.getPlayerExact(args[0]);
                        if(player == null)
                            sender.sendMessage(ChatColor.RED + "Nie znaleziono gracza!");
                            return true;
                            mapa.put(sender.getName(), args[0]);
                             sender.sendMessage(ChatColor.GREEN + "Poczekaj aż " + ChatColor.YELLOW + args[0] + ChatColor.GREEN + " potwierdzi zaproszenie do listy znajomych");
                             Bukkit.getPlayer(args[0]).sendMessage(ChatColor.YELLOW + sender.getName() + ChatColor.GREEN + " zaprosil cie do znajomych.");
                             Bukkit.getPlayer(args[0]).sendMessage(ChatColor.GREEN + "Masz 15 sekund na potwierdzenie zaproszenia");
                             Bukkit.getPlayer(args[0]).sendMessage(ChatColor.GREEN + "Aby potwierdzić zaproszenie wpisz: " + ChatColor.RED + "/znajomi "+sender.getName());
                             Bukkit.getScheduler().scheduleSyncDelayedTask((Plugin)this, new Runnable() {
                                public void run()
                                        // args[0] == invited player
                                    //if args[0] send command with args[0].equals(sender.getName()) ?
                                    sender.sendMessage(ChatColor.RED + "Nie zaakceptowałeś/aś " +ChatColor.YELLOW + sender.getName() + ChatColor.RED + " do listy znajomych!");
                                    ((Entity) sender).getLocation().getWorld().playSound((Location)((Entity) sender).getLocation(), Sound.CHEST_CLOSE, 5, 5);
                             }, 20*15);
                             return true;
                    return true;
                return false;
  2. Offline


    Please, look at the link in my signature. This is the fourth time you made a thread that does not have any information we need. We have no idea what the problem is, so we can't help you.
  3. @Zombie_Striker
    How to do that when someone gets a call , in 15 seconds can use command /friend (Sender nick).
    I don't know what I must doing with onCommand.
  4. Offline


    So you want to create a "cooldown" or a "time limit"? You want where the player can issue a command after 15 seconds, or do you want it where the player has to send the command before 15 seconds?
  5. @Zombie_Striker I want do second player can to send command before 15 seconds when first used command /friends (nick first player)
  6. Offline


    • Create a map that will store the first player and a Long, which will be the time the command was sent.
    • When the first player sends the command, add the player and the time in milliseconds.
    • When the second player sends the command, if the time -in -milliseconds minus the time in the Map is less than (15*1000), or fifteen seconds, do stuff.
  7. it is method ;)

    @Zombie_Striker I so sorry.. it isn't possible, because i don't know what check when selected player send this command?

    I would like create plugin ,,Friends"
    If player send command /friends player player get message and can accept sender to friends list.
    Player have 15 sec to accept invite.
    Last edited: Mar 28, 2016
  8. Offline


    • Let your class implement CommandExecutor
    • Add the un implemented methods, which will be called when a command is sent
    • Check if the sender is a player
    • Is so, add the Player to the map as a key, with a long as the value
    • Remove the player from the map when the current time is greater than the added time
    • If they aren't in the map, they aren't on cooldown
    • Send the target player the message
    • If they accept, add it to an ArrayList or store it to a database
Thread Status:
Not open for further replies.

Share This Page