2 Questions

Discussion in 'Plugin Development' started by Jellydude, Jul 14, 2013.

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

    Jellydude

    1. This one's stupidly simple but I can't work it out. How do I do 2 different colours in a play message?

    2. How could I make it so when a player did a command it gave them a permission but when the died it removed that permission until they did that command again?
     
  2. Offline

    xTrollxDudex

    Jellydude
    1. Like formatting and a color? ChatColor.BOLD + "" + ChatColor.RED + "this would be a bold red message"
     
  3. Offline

    Jellydude

    xTrollxDudex
    No like having for example Jelly in red and dude in blue all in one player message.
     
  4. Offline

    marti.2001

    2. You can use Vault to give them permissions
     
  5. Offline

    Jellydude

    marti.2001
    That doesn't answer my question. What is the code for it and how do I make the permission get removed when they die.
     
  6. Offline

    xTrollxDudex

    Jellydude
    This makes no sense :p please elaborate. Like when the player chats the name on the left is red and blue?
     
  7. Offline

    Jellydude

    xTrollxDudex
    No for example when a player runs a command the server sends them a message saying "Hello world" and Hello would be red and world would be blue.
     
  8. Offline

    xTrollxDudex

    Jellydude
    Ok I give up
    But chat colors go like this
    Code:java
    1. ChatColor.RED + "Hello" + ChatColor.BLUE + "World"
     
  9. Offline

    Jellydude

    xTrollxDudex
    Thanks the reason I can't explain very well is I'm on my iPad so it takes forever to type a message.
     
  10. Offline

    xTrollxDudex

    Jellydude
    Well I happen to be on my iPod (as always Woobie!) typing everything on the forums :p
     
  11. Offline

    marti.2001

    Jellydude
    Give them permissions when they type the command and take them in PlayerDeathEvent.

    1. Download Vault here: http://dev.bukkit.org/bukkit-plugins/vault/
    2. Add it to your build path (where bukkit.jar is)
    3. Add this to your plugin.yml:
    Code:
    depend: [Vault]
    4. Add this:
    Code:java
    1. public static Permission perms = null;

    5. Add this somewhere in your class:
    Code:java
    1.  
    2. private boolean setupPermissions() {
    3. RegisteredServiceProvider<Permission> rsp = getServer().getServicesManager().getRegistration(Permission.class);
    4. perms = rsp.getProvider();
    5. return perms != null;
    6. }

    6. Add this to your onEnable():
    Code:java
    1. setupPermissions();


    Now you're ready to use Vault (but your plugin will be unable to run without it installed on the server)

    To add permissions:
    Code:java
    1.  
    2. public boolean onCommand(CommandSender sender, Command cmd, String label, String[]args){
    3. if(cmd.getName().equalsIgnoreCase("giveperms")){
    4. if(sender instanceof Player){
    5. Player p = (Player) sender;
    6. perms.playerAdd(p, "your.permission");
    7. }
    8. }
    9. return false;
    10. }
    11.  


    To remove the permission when the player dies add this to your listener class:
    Code:java
    1. @EventHandler
    2. public void onPlayerDeath(PlayerDeathEvent e){
    3. playerRemove(e.getPlayer, "your.permission");
    4. }
    5.  

    (haven't tested this code)
     
  12. Offline

    chasechocolate

    Jellydude hello :) to add a permission, use player.addAttachment(plugin, "permission.node", true) and remove it by changing the true to false.
     
  13. Offline

    xTrollxDudex

    marti.2001
    Awesome info but looking at the common mistakes stick, using Vault is actually slower than using the normal .hasPermission(). Besides vault uses .hasPermission() anyway so why bother!
     
  14. Offline

    marti.2001

    xTrollxDudex
    He wants to add permissions, not to check them.
     
  15. Offline

    xTrollxDudex

    marti.2001
    My point still stands. Instead of using vault which is a bit complex considering registering and other plugin.yml, try looking at this
     
  16. Offline

    Jellydude

    xTrollxDudex
    I'm still getting errors on it.
     
  17. Offline

    xTrollxDudex

  18. Offline

    marti.2001

    xTrollxDudex
    player.addAttachment() will not persist through server reloads/restarts.
     
  19. Offline

    xTrollxDudex

Thread Status:
Not open for further replies.

Share This Page