Vault Prefix Change

Discussion in 'Plugin Development' started by Rmarmorstein, Dec 1, 2012.

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

    Rmarmorstein

    Ok, So i am confused on how to do this, yes, I am just learning Java, But i do have a Good understanding of the language.

    I am trying to change the players prefix on a command, I am using Vault to accomplish this. In my main class, i did the chat thing for vault, then in my command executor class, i tried to use the setPlayerPrefix, and did not get very far.

    This is what vault gave me to use https://github.com/MilkBowl/Vault/blob/master/src/net/milkbowl/vault/chat/Chat.java

    Here is my code so Far:
    -Main
    Code:java
    1.  
    2. package us.rivertech.ezdonor;
    3.  
    4. import org.bukkit.plugin.PluginDescriptionFile;
    5. import org.bukkit.plugin.RegisteredServiceProvider;
    6. import org.bukkit.plugin.java.JavaPlugin;
    7.  
    8. import net.milkbowl.vault.chat.Chat;
    9. import net.milkbowl.vault.permission.Permission;
    10.  
    11. public final class ezDonor extends JavaPlugin {
    12.  
    13. PluginDescriptionFile pdfile = getDescription();
    14. public static Permission perms = null;
    15. public static Chat chat =null;
    16.  
    17. public String getPlayerSuffix(String world, String player) {
    18. return null;
    19. }
    20.  
    21.  
    22.  
    23. @Override
    24. public void onEnable(){
    25.  
    26. getCommand("prefix").setExecutor(new PrefixCommandExecuter());
    27. setupChat();
    28. }
    29.  
    30. @Override
    31. public void onDisable(){
    32. getLogger().info("ezDonor Disabled");
    33. }
    34.  
    35. public boolean setupChat() {
    36. RegisteredServiceProvider<Chat> rsp = getServer().getServicesManager().getRegistration(Chat.class);
    37. chat = rsp.getProvider();
    38. return chat != null;
    39.  
    40. }
    41.  
    42. }
    43.  


    Now here is my Command Executor Class:
    Code:java
    1.  
    2. package us.rivertech.ezdonor;
    3.  
    4.  
    5. import org.bukkit.Bukkit;
    6. import org.bukkit.ChatColor;
    7. import org.bukkit.command.Command;
    8. import org.bukkit.command.CommandExecutor;
    9. import org.bukkit.command.CommandSender;
    10.  
    11. public class PrefixCommandExecuter implements CommandExecutor {
    12.  
    13. @Override
    14. public boolean onCommand(CommandSender cdsend, Command cmd, String label,
    15. String[] args) {
    16. System.out.print("Command Executed");
    17. if(label.equalsIgnoreCase("prefix")) {
    18. if (args.length > 2) {
    19. cdsend.sendMessage(ChatColor.RED + "Too Many Arguments!");
    20. return false; }
    21. else if (args.length < 2) {
    22. cdsend.sendMessage(ChatColor.RED + "Too Little Arguments!");
    23. return false; }
    24. }
    25. else if (cdsend.hasPermission("ezdonor.prefix")){
    26. cdsend.sendMessage(ChatColor.AQUA + "Your Prefix Has Been Changed To: " + args[1]);
    27.  
    28. }return true;
    29. }
    30.  
    31.  
    32.  
    33.  
    34. }
    35.  
    36.  
    37.  


    Any Help is appretiated.
     
  2. Offline

    NinjaW0lf

    Show the Error please
     
  3. Offline

    Rmarmorstein

    The Error is, i am not sure how to fit it in, i am looking for some help on where to put it.

    On the link is what i got from vault, and i am not sure what to do with the setPlayerPrefix

    Did you even read My Posy NinjaW0lf?
     
  4. Offline

    NinjaW0lf

    Rmarmorstein ah,k gotcha. Give me a min. i thought u had all the code and just had an error. my bad.
     
  5. Offline

    Rmarmorstein

    No Problem. As i said, i am still learning, and the vault guys just gave me a link, and it threw me off.

    I tried fiddling around with it again, and putting stuff in certain places, but still getting nothing

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

    NinjaW0lf

    Code:java
    1.  
    2. package us.rivertech.ezdonor;
    3.  
    4. import org.bukkit.ChatColor;
    5. import org.bukkit.command.Command;
    6. import org.bukkit.command.CommandExecutor;
    7. import org.bukkit.command.CommandSender;
    8. import org.bukkit.entity.Player;
    9.  
    10. public class PrefixCommandExecutor implements CommandExecutor {
    11.  
    12. @Override
    13. public boolean onCommand(CommandSender cdsend, Command cmd, String label,
    14. String[] args) {
    15. System.out.print("Command Executed");
    16. if (label.equalsIgnoreCase("prefix")) {
    17. if (args.length > 2) {
    18. cdsend.sendMessage(ChatColor.RED + "Too Many Arguments!");
    19. return false;
    20. }
    21. else if (args.length < 2) {
    22. cdsend.sendMessage(ChatColor.RED + "Too Little Arguments!");
    23. return false;
    24. } else if (cdsend.hasPermission("ezdonor.prefix")) {
    25. ezDonor.chat.setPlayerPrefix((Player)cdsend, args[1]);
    26. cdsend.sendMessage(ChatColor.AQUA + "Your Prefix Has Been Changed To: " + args[1]);
    27.  
    28. }
    29. }
    30. return true;
    31. }
    32.  
    33. }
    34.  

    That should work. if u want to access it, just use ezDonor.chat.Whatever
    with that u can access all of the methods in the caht area of here:
    link

    Also, u want to add a check to see if a player is sending that command, as right now. if a console sends that, it will prob throw errors.
     
  7. Offline

    Rmarmorstein

    Thanks, That sounds good. Awesome. I'll let you know if i get any errors.
     
Thread Status:
Not open for further replies.

Share This Page