Random Grouping

Discussion in 'Plugin Development' started by x17Andrew71x, Jan 13, 2014.

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

    x17Andrew71x

    Hey guys, what am I doing wrong?

    I've rearranged my code like 50 times and I just can't get it...

    The command is called(shows up in console) but does nothing.

    Here is the code:

    Code:java
    1. package com.enderfalls.Main;
    2.  
    3. import java.util.Random;
    4.  
    5. import org.bukkit.Bukkit;
    6. import org.bukkit.ChatColor;
    7. import org.bukkit.command.Command;
    8. import org.bukkit.command.CommandSender;
    9. import org.bukkit.entity.Player;
    10. import org.bukkit.event.Listener;
    11.  
    12. public class TDM implements Listener {
    13.  
    14. public Main plugin;
    15.  
    16. public TDM(Main instance) {
    17. plugin = instance;
    18. }
    19.  
    20. public boolean onCommand(CommandSender sender, Command cmd, String CommandLabel, String[] args) {
    21. Player player = (Player) sender;
    22. if (player.hasPermission("efpvpmgr.tdm.joingame")) {
    23. if (cmd.getName().equalsIgnoreCase("JoinGame")) {
    24. Random random = new Random();
    25. int i = random.nextInt(100);
    26. if (i <= 49) {
    27. Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), "manselect " + player.getWorld().getName());
    28. Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), "manuadd " + player + " RedTeam");
    29. player.sendMessage(ChatColor.RED + "You have been added to the Red team.");
    30. } else if (i >= 50) {
    31. Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), "manselect " + player.getWorld().getName());
    32. Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), "manuadd " + player + " BlueTeam");
    33. player.sendMessage(ChatColor.BLUE + "You have been added to the Blue team.");
    34. }
    35. }
    36. }
    37. return false;
    38. }
    39.  
    40. }


    and here is the plugin.yml:


    Code:
    name: EFPVPMGR
    version: 0.0.1
    description: EnderFalls PVP Manager. (mc.enderfalls.com)
    author: x17Andrew71x
    main: com.enderfalls.Main.Main
     
    commands:
      joingame:
        permission: efpvpmgr.tdm.joingame
     
    permissions:
      efpvpmgr.tdm.joingame:
        description: Gives Permission to Join TDM.
        default: false
       
    
    Thanks!
     
  2. Offline

    metalhedd

    Listener is for events, not commands, you need to implement CommandExecutor, and don't forget to do getCommand("joingame").setExecutor(myExecutor);

    BTW, absolutely terrible title for this thread. has nothing to do with your problem, I was hoping to find something interesting :p

    one more btw: the code isn't called at all, you could have easily verified that by inserting a logging statement inside your onCommand method and seeing that nothing gets logged. it appears in the console because you're typing it into the chat.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 6, 2016
  3. Offline

    x17Andrew71x

    What am I doing wrong then?
     
  4. Offline

    metalhedd


    #1 Your class implements Listener. your class SHOULD implement CommandExecutor or TabExecutor instead.
    #2 You apparently didn't read this http://wiki.bukkit.org/Plugin_Tutorial
     
Thread Status:
Not open for further replies.

Share This Page