Solved Help me, with my plugin, pls?

Discussion in 'Plugin Development' started by ZygoZ, Feb 16, 2015.

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

    ZygoZ

    [I don't know if this should be in Plugin Requests.]

    I have this code so far, but I want more with it.. I'm new to this, please don't judge me.
    I want it to be like a request system.
    So for example. "/flashr <name>" or "/fr <name>" Requests to be flashed to another player, then the "targeted player" has to accept it with "/flasha" or "/flash accept" if possible, or he can decide to type "/flashd" or "/flash decline" if possible.

    I also really wanted it so OPs could flash silently, if there could be some sort of "silent" flash, like a permission.

    Thank you!

    Code:
    package me.ZygoZ;
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.Effect;
    import org.bukkit.Location;
    import org.bukkit.Sound;
    import org.bukkit.World;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.event.world.WorldEvent;
    import org.bukkit.plugin.PluginManager;
    import org.bukkit.plugin.java.JavaPlugin;
    @SuppressWarnings("unused")
    public class Flash extends JavaPlugin {
        @Override
        public void onDisable() {
        }
        @Override
        public void onEnable() {
        }
        @SuppressWarnings("deprecation")
        public boolean onCommand (CommandSender sender, Command cmd, String label, String[] args) {
            Player player = (Player) sender;
            if(label.equalsIgnoreCase("flash")) {
                if (args.length == 0) {
                    player.sendMessage(ChatColor.DARK_RED + "Wrong! Use:" + ChatColor.GOLD + ChatColor.BOLD + " '/flash <Name>'");
                }if(args.length == 1){
                    Player targetPlayer = Bukkit.getServer().getPlayer(args[0]);
                    if(targetPlayer != null) {
                        Location targetLocation = targetPlayer.getLocation(); //gets the location of the target player
                        player.teleport(targetLocation); //Teleports the player to the target Location
                        for(int i = 0; i < 20; i++) { //loop (doing this command 20 times)
                            player.playEffect(targetLocation, Effect.ENDER_SIGNAL,5);
                            player.playSound(targetLocation,Sound.ENDERMAN_TELEPORT,(float)0.1,3);
                        }
                        player.sendMessage(ChatColor.GREEN + "You're being flashed to " + ChatColor.AQUA + ChatColor.BOLD + targetPlayer.getName() + ChatColor.RESET + ChatColor.GREEN + "!");
                        targetPlayer.sendMessage(ChatColor.BOLD + player.getName() + ChatColor.RESET + ChatColor.GREEN + " have been flashed to you!");
                    }
                    else {
                        player.sendMessage(ChatColor.RED+"Could not find Player!");
                    }
                }
            }
            return true;
        }
    }
     
  2. Offline

    hopstar

    What is your question? Do have a error when you run it? Ore do you wanne know how to use permissions nodes?
     
  3. @ZygoZ The last return should be false not true.
     
  4. Offline

    ZygoZ

    @hopstar I haven't made the complete plugin yet, so I wanted to know if anyone had some skills, so they could help me.
    @bwfcwalshy Why is that? If you don't mind me asking.
     
  5. @ZygoZ That's how it goes, can't really think of a better answer.

    As for the plugin, save the Player who requested and who it was to in a HashMap, then when someone does /flasha flasha check the HashMap to see if they are in there and who they are against. Remove them from the HashMap and teleport them somewhere.

    Make sure to do checks that the requestee is still online and not in a game.


    Also; cmd.getName().equalsIgnoreCase not label.
    And no need to reset when changing colours
     
  6. Offline

    ZygoZ

    @bwfcwalshy I am totally new, so I have not tried all the "HasMap" shizzle yet, but I really want to learn it. Could you make this plugin work and maybe explain to me what the codes do? That would be appreciated. :)
     
  7. Offline

    ZygoZ

    Thanks anyways, I'll try to understand some of it. :)
     
  8. there you go

    create a hashmap
    Code:
        public HashMap<UUID, UUID> flashrequests = new HashMap<UUID, UUID>();
    
    command
    Code:
           
    Player player = (Player) sender;
            if(cmd.getName().equalsIgnoreCase("flash")) {
                if(args.length == 1){
                    if(args[0].equalsIgnoreCase("accept")){
                        if(flashrequests.containsKey(player)){
                            Player target = Bukkit.getPlayer(flashrequests.get(player.getUniqueId()));
                            target.teleport(player.getLocation());
                            if(!(target.hasPermission("flash.hide"))){
                               for(int i = 0; i < 20; i++) { //loop (doing this command 20 times)
                                   target.playEffect(target.getLocation(), Effect.ENDER_SIGNAL,5);
                                   target.playSound(target.getLocation(),Sound.ENDERMAN_TELEPORT,(float)0.1,3);
                               }
                            }
                            player.sendMessage("You accepted the request from " + target.getName());
                            target.sendMessage("Your request to " + player.getName() + " has been accepted");
                            flashrequests.remove(player.getUniqueId());
                        }else{
                            player.sendMessage("You have nothing accept");
                        }
                    }else if(args[0].equalsIgnoreCase("decline")){
                        if(flashrequests.containsKey(player)){
                            Player target = Bukkit.getPlayer(flashrequests.get(player.getUniqueId()));
                            player.sendMessage("You declined the request from " + target.getName());
                            target.sendMessage("Your request to " + player.getName() + " has been declined");
                            flashrequests.remove(player.getUniqueId());
                        }else{
                            player.sendMessage("You have nothing to decline");
                        }
                    }
                }else if(args.length == 2){
                    if(args[0].equalsIgnoreCase("request")){
                        Player target = Bukkit.getServer().getPlayer(args[1]);
                        if(target != null){
                            flashrequests.put(target.getUniqueId(), player.getUniqueId());
                            target.sendMessage("Player " + player.getName() + " requested to falsh to you");
                            player.sendMessage("Flash request has been sent to " + target.getName());
                        }else{
                            player.sendMessage("Player " + args[1] + " not online");
                        }
                    }else{
                        player.sendMessage("Wrong! Use: '/flash <request/accept/decline> [Name]'");
                    }
                }else{
                    player.sendMessage("Wrong! Use: '/flash <request/accept/decline> [Name]'");
                }
            }
    
    hope thats what u meant


    thats what i just did ? haha

    EDIT: changed hashmap from <Player, Player> to <UUID, UUID>
     
    Last edited: Feb 16, 2015
    ZygoZ likes this.
  9. Offline

    ZygoZ

    @sn1cko so I always have to type the name even if it's decline or accept? :confused:
     
  10. no, there are 3 commands
    /flash request <name>
    /flash accept
    /flash decline

    the help command "Wrong! Use: '/flash <request/accept/decline> [Name]'" includes "<>" and "[]"
    "<>" = means, it's required
    "[]" = means, it's not always required... (only if you use "/flash request")
     
    ZygoZ likes this.
  11. Offline

    ZygoZ

    @sn1cko erhm, do I have to make the aliases in the plugin.yml or do I have to write them manually in the plugin file?
     
  12. And the award for spoonfeeding goes to........... @sn1cko

    Save UUID's in the HashMap not players.
     
  13. Hahaha :D
    thanks for that awesome reward hahaha

    and thanks forgot that (changed it)

    plugin.yml would look like this
    Code:
    commands:
       flash:
          description: flash command desc.
          permission-message: You don't have Permissions.
    
    is this thread done ? @ZygoZ

    if so, you could mark it as solved
     
    Last edited by a moderator: Feb 16, 2015
    ZygoZ likes this.
  14. Offline

    ZygoZ

    Some sort of solved, thank you. :)
     
Thread Status:
Not open for further replies.

Share This Page