Nothing happens ?

Discussion in 'Plugin Development' started by CXdur, Sep 22, 2012.

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

    CXdur

    Hey, I am trying to make a simple TPA system in my plugin.

    However when I try to accept a TP request nothing happens.

    Handler.
    Code:
        private HashMap<Player, Player> tpRequest = new HashMap<Player, Player>();
    
        public void acceptRequest(Player p) {
            if (!hasRequest(p)) {
                p.sendMessage(ChatColor.RED + "Du har ingen TPA forespørsel.");
                return;
            }
                for (Entry<Player, Player> entry : tpRequest.entrySet()) {
                    if (entry.getKey().getName().equalsIgnoreCase(p.getName())) {
                        Player v = entry.getValue();
                        p.teleport(v.getLocation());
                        p.sendMessage(ChatColor.GREEN + "Du teleporterte til: " + v.getName() + " med TPA.");
                        v.sendMessage(ChatColor.GREEN + p.getName() + " teleporterte til deg med TPA.");
                        tpRequest.remove(p);
                    }
                        } }
       
     
        public void denyRequest(Player p) {
            if (!hasRequest(p)) {
                p.sendMessage(ChatColor.RED + "Du har ingen TPA forespørsel å avslå.");
                return;
            }
                for (Entry<Player, Player> entry : tpRequest.entrySet()) {
                    if (entry.getKey().getName().equalsIgnoreCase(p.getName())) {
                        Player v = entry.getKey();
                        p.sendMessage(ChatColor.GREEN + "Du avslo TPA forespørslen.");
                        v.sendMessage(ChatColor.RED + p.getName() + " avslo din TPA forespørsel.");
                    }
                } }
       
     
        public void sendRequest(Player p, Player v) {
            // Player p sends request. Player v receives the request.
            if (hasSentRequest(p)) {
                p.sendMessage(ChatColor.RED + "Du har allerede sendt en TPA forespørsel.");
                return;
            }
            if (hasRequest(v)) {
                p.sendMessage(ChatColor.RED + v.getName() + " har allerede en TPA forespørsel.");
                return;
            }
            tpRequest.put(p, v);
            p.sendMessage(ChatColor.GREEN + "Sendte TPA forespørsel til: " + v.getName() + ".");
            v.sendMessage(ChatColor.GREEN + "Du fikk en TPA forespørsel av: " + p.getName() + ".");
            v.sendMessage(ChatColor.GREEN + "Godta med: /tpasvar godta. Avslå med: /tpasvar avslå.");
        }
    
    Command:
    Code:
        @Override
        public boolean onCommand(Player p, Command cmd, String label,
                String[] args) {
            if (args.length == 0) {
                p.sendMessage(ChatColor.RED + "/tpasvar avslå/godta");
                return true;
            } else if (args.length == 1) {
                if (args[0].equalsIgnoreCase("godta")) {
                    warpHandler.acceptRequest(p);
                    return true;
                } else if (args[0].equalsIgnoreCase("avslå")) {
                    warpHandler.denyRequest(p);
                    return true;
                } else {
                    p.sendMessage(ChatColor.RED + "Feil i args.");
                    return true;
                }
            }
            return false;
        }
     
    }
     
    Another class:
     
      @Override
        public boolean onCommand(Player p, Command cmd, String label,
                String[] args) {
            if (args.length == 0) {
                p.sendMessage(ChatColor.RED + "Bruk! /tpa [spiller");
                return true;
            } else if (args.length == 1) {
                Player v = Bukkit.getPlayer(args[0]);
                if (v != null) {
                    warpHandler.sendRequest(p, v);
                } else {
                    p.sendMessage(ChatColor.RED + "Fant ingen match med: " + args[0] + ".");
                }
                return true;
            }
        return false;   
        }
    }
    
    bump

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

    Fl1pzta

    Code:
        public boolean onCommand(Player p, Command cmd, String label,
                String[] args)
    Player p needs to be CommandSender p. I'm sure, but that's my guess.
     
  3. I wonder why your IDE didn't tell you what Fl1pzta told, cause the @Override should bring the IDE to tell you that it's wrong. If I copy&paste your code I get this:
     
  4. Offline

    Fl1pzta

    I think the reason why it didn't show up for him is because he's using a different IDE like you said.
     
  5. Offline

    CXdur

    Nono, sorry guys. Forgot to say that I have my own CommandHandler. It's not the CommandHandler that is the problem as all the other commands work. I'm using Eclipse btw.
     
  6. CXdur You have to implement CommandExecutor at some point (or be in your main class which does this by default) and override it's onCommand method.
    Also if it's not in your main class you need that in onEnable():
    getCommand("yourCommand").setExecutor(yourCommandExecutor);

    So I really don't know what you mean with "have my own CommandHandler". Either you describe the best you can (with code snippets) or show us all your code.
     
  7. Offline

    CXdur

    Okay I will try to explain. I have a commandHandler and the class extends the CommandHandler. In OnEnable I get the command and there comes no "Error! Unknown command" message. The error is that nothing happens at all when I execute the command.

    Sorry, but I'm really bad to explaind :(
     
  8. CXdur And the ComandHandler class is self-written? Again: At some point you have to implement CommandExecutor and overwrite its onCommand
    Also show what exactly you do in onEnable ("In OnEnable I get the command").
     
  9. Offline

    CXdur

    Yes it's self written and the CommandHandler is abstract and it implements the CommandExecutor.
    Code:
            getCommand("tpasvar").setExecutor(new TPASvarCommand(this));
    
    But I'm telling you; it's not the the registering of the command that isn't working. I don't know why but when I for example write /tpasvar it tells me that I need args but when I write /tpasvar godta it ignores it. If you understand?
     
  10. Offline

    kroltan

    Stupid question: Did you register the command in plugin.yml?
     
  11. Offline

    CXdur

    Yes, the command works just fine but Nothing happens whEn i use /tpasvar godta or avslå.
     
  12. Offline

    kroltan

    Why don't you store those values in the player's Metadata? Take a look on MicroTP (Check the source included in the jar) to see what I mean.
     
  13. Offline

    Wratery

    The abstracted class (CommandHandler), is using the CommandExecutor as its interface. The interface will work as it does, but the CommandHandler will gather the informasion needed from the command, and this will be done trough a object.

    Example:

    public abstract class classname implements CommandExecutor {

    public classname(Plugin plugin) {
    super(); //using plugin class as main resource
    }

    @Override
    public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
    return onPlayerCommand(Player p, Command cmd, String label, String[] args);
    return false;
    }

    @Override
    public abstract boolean onPlayerCommand(Player player, Command command, String label, String[] args);
    }

    The issue right here is how we should get the server to handel the command that is executed.
     
  14. Offline

    CXdur

    Dude... that's not the problem I said. The ComamandHandler works just fine. It's the EntrySet that is bugging it up, but I'll try to use MetaData now.

    EDIT: Problem solved, thanks kroltan.

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

    Wratery

    Haha, I ment that, lol. The MetaData should not be used for this, when the map for the MetaData has many known issues. Google it.
     
Thread Status:
Not open for further replies.

Share This Page