Implementing Vault

Discussion in 'Plugin Development' started by Jaaakee224, Jan 29, 2014.

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

    Jaaakee224

    How can I implement Vault so that it costs money to receive a perk from my plugin. What my plugin does is you click a perk sign, and you are given a perk. I want to make it so you can add a cost to the perk. I would like it if nobody gave me an example from somebody else, but explained it them self and showed me the code/how to do it in a very nice way. Here is my code:

    Main Class
    Code:java
    1. public class PerkCola extends JavaPlugin {
    2.  
    3. @Override
    4. public void onDisable() {
    5.  
    6. }
    7.  
    8. @Override
    9. public void onEnable() {
    10. Bukkit.getServer().getPluginManager().registerEvents((Listener) new Events(), this);
    11. Bukkit.getServer().getPluginManager().registerEvents((Listener) new Juggernog(), this);
    12. Bukkit.getServer().getPluginManager().registerEvents((Listener) new Stamina(), this);
    13. Bukkit.getServer().getPluginManager().registerEvents((Listener) new PhD(), this);
    14. Bukkit.getServer().getPluginManager().registerEvents((Listener) new DoubleTap(), this);
    15. Bukkit.getServer().getPluginManager().registerEvents((Listener) new Tombstone(), this);
    16. }
    17. }


    Events Class
    Code:java
    1. public class Events implements Listener {
    2.  
    3. @EventHandler
    4. public void onPlayerDeath(PlayerDeathEvent e) {
    5. e.getEntity().removePotionEffect(PotionEffectType.SPEED);
    6. e.getEntity().removePotionEffect(PotionEffectType.REGENERATION);
    7. e.getEntity().setMaxHealth(20.0);
    8. e.getEntity().sendMessage(ChatColor.GOLD + "[Perk-A-Cola]" + ChatColor.AQUA + " All current perks have been removed.");
    9. }
    10. }


    Stamina Class
    Code:java
    1. public class Stamina implements Listener {
    2.  
    3. @EventHandler
    4. public void onSignChange(SignChangeEvent e) {
    5. if(e.getLine(0).equalsIgnoreCase("[Perk-A-Cola]")) {
    6. if(e.getLine(2).equalsIgnoreCase("Stamina Up")) {
    7. if(e.getPlayer().hasPermission("perk.place"))
    8. e.setLine(0, ChatColor.DARK_RED + "[Perk-A-Cola]");
    9. e.setLine(2, ChatColor.BOLD + "Stamina Up");
    10. e.getPlayer().sendMessage(ChatColor.GOLD + "[Perk-A-Cola]" + ChatColor.AQUA + " You have created a Perk-A-Cola sign!");
    11. }
    12. }
    13. }
    14. @EventHandler
    15. public void onPlayerInteract(PlayerInteractEvent e) {
    16. Player player = e.getPlayer();
    17. if(e.getAction() == Action.RIGHT_CLICK_BLOCK) {
    18. Block b = e.getClickedBlock();
    19. if(b.getType() == Material.WALL_SIGN || b.getType() == Material.SIGN_POST) {
    20. Sign sign = (Sign) b.getState();
    21. String[] lines = sign.getLines();
    22. if(lines[0].equalsIgnoreCase(ChatColor.DARK_RED + "[Perk-A-Cola]")) {
    23. if(lines[2].equals(ChatColor.BOLD + "Stamina Up")) {
    24. if(player.hasPermission("perk.use"))
    25. player.sendMessage(ChatColor.GOLD + "[Perk-A-Cola]" + ChatColor.AQUA + " You have purchased Stamina Up!");
    26. player.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 999999999, 10));
    27. player.playSound(player.getLocation(), Sound.LEVEL_UP, 10.0F, 3);
    28. }
    29. }
    30. }
    31. }
    32. }
    33. }


    Juggernog Class
    Code:java
    1. public class Juggernog implements Listener {
    2.  
    3. @EventHandler
    4. public void onSignChange(SignChangeEvent e) {
    5. if(e.getLine(0).equalsIgnoreCase("[Perk-A-Cola]")) {
    6. if(e.getLine(2).equalsIgnoreCase("Juggernog")) {
    7. if(e.getPlayer().hasPermission("perk.place"))
    8. e.setLine(0, ChatColor.DARK_RED + "[Perk-A-Cola]");
    9. e.setLine(2, ChatColor.BOLD + "Juggernog");
    10. e.getPlayer().sendMessage(ChatColor.GOLD + "[Perk-A-Cola]" + ChatColor.AQUA + " You have created a Perk-A-Cola sign!");
    11.  
    12.  
    13. }
    14. }
    15. }
    16.  
    17. @EventHandler
    18. public void onPlayerInteract(PlayerInteractEvent e) {
    19. Player player = e.getPlayer();
    20.  
    21. if(e.getAction() == Action.RIGHT_CLICK_BLOCK) {
    22. Block b = e.getClickedBlock();
    23. if(b.getType() == Material.WALL_SIGN || b.getType() == Material.SIGN_POST) {
    24. Sign sign = (Sign) b.getState();
    25. String[] lines = sign.getLines();
    26. if(lines[0].equalsIgnoreCase(ChatColor.DARK_RED + "[Perk-A-Cola]")) {
    27. if(lines[2].equals(ChatColor.BOLD + "Juggernog")) {
    28. if(player.hasPermission("perk.use"))
    29. player.sendMessage(ChatColor.GOLD + "[Perk-A-Cola]" + ChatColor.AQUA + " You have purchased Juggernog!");
    30. player.addPotionEffect(new PotionEffect(PotionEffectType.REGENERATION, 50, 10));
    31. player.playSound(player.getLocation(), Sound.LEVEL_UP, 10.0F, 3);
    32. player.setMaxHealth(40.0);
    33. }
    34. }
    35.  
    36. }
    37. }
    38. }
    39. }
    40.  


    DoubleTap Class
    Code:java
    1. public class DoubleTap implements Listener {
    2.  
    3. @EventHandler
    4. public void onSignChange(SignChangeEvent e) {
    5. if(e.getLine(0).equalsIgnoreCase("[Perk-A-Cola]")) {
    6. if(e.getLine(2).equalsIgnoreCase("Double Tap")) {
    7. if(e.getPlayer().hasPermission("perk.place"))
    8. e.setLine(0, ChatColor.DARK_RED + "[Perk-A-Cola]");
    9. e.setLine(2, ChatColor.BOLD + "Double Tap");
    10. e.getPlayer().sendMessage(ChatColor.GOLD + "[Perk-A-Cola]" + ChatColor.AQUA + " You have created a Perk-A-Cola sign!");
    11. }
    12. }
    13. }
    14. @EventHandler
    15. public void onPlayerInteract(PlayerInteractEvent e) {
    16. Player player = e.getPlayer();
    17. if(e.getAction() == Action.RIGHT_CLICK_BLOCK) {
    18. Block b = e.getClickedBlock();
    19. if(b.getType() == Material.WALL_SIGN || b.getType() == Material.SIGN_POST) {
    20. Sign sign = (Sign) b.getState();
    21. String[] lines = sign.getLines();
    22. if(lines[0].equalsIgnoreCase(ChatColor.DARK_RED + "[Perk-A-Cola]")) {
    23. if(lines[2].equals(ChatColor.BOLD + "Double Tap")) {
    24. if(player.hasPermission("perk.use"))
    25. player.sendMessage(ChatColor.GOLD + "[Perk-A-Cola]" + ChatColor.AQUA + " You have purchased Double Tap!");
    26. player.addPotionEffect(new PotionEffect(PotionEffectType.FAST_DIGGING, 999999999, 3));
    27. player.playSound(player.getLocation(), Sound.LEVEL_UP, 10.0F, 3);
    28. }
    29. }
    30. }
    31. }
    32. }
    33. }


    PhD Class
    Code:java
    1. public class PhD implements Listener {
    2.  
    3. public HashMap<Player, Boolean> map = new HashMap<Player, Boolean>();
    4.  
    5. public void setPlayerImmune(Player p, Boolean immune){
    6.  
    7. map.put(p, immune);
    8.  
    9. }
    10.  
    11. public Boolean isImmune(Player p){
    12.  
    13. if(map.containsKey(p)){
    14. Boolean a = map.get(p);
    15.  
    16. return Boolean.valueOf(a);
    17.  
    18. }else{
    19.  
    20. return false;
    21.  
    22. }
    23.  
    24. }
    25.  
    26.  
    27. @EventHandler
    28. public void onEntityDamage(EntityDamageEvent e){
    29. if(e.getEntity() instanceof Player && e.getCause().equals(DamageCause.BLOCK_EXPLOSION)) {
    30.  
    31. if(e.getEntity() instanceof Player){
    32.  
    33. Player p = (Player) e.getEntity();
    34.  
    35. if(this.isImmune(p).equals(true)) {
    36. e.setCancelled(true);
    37. }
    38. }
    39. }
    40. }
    41.  
    42. @EventHandler
    43. public void onSignChange(SignChangeEvent e) {
    44. if(e.getLine(0).equalsIgnoreCase("[Perk-A-Cola]")) {
    45. if(e.getLine(2).equalsIgnoreCase("PhD")) {
    46. if(e.getPlayer().hasPermission("perk.place"))
    47. e.setLine(0, ChatColor.DARK_RED + "[Perk-A-Cola]");
    48. e.setLine(2, ChatColor.BOLD + "PhD");
    49. e.getPlayer().sendMessage(ChatColor.GOLD + "[Perk-A-Cola]" + ChatColor.AQUA + " You have created a Perk-A-Cola sign!");
    50. }
    51. }
    52. }
    53. @EventHandler
    54. public void onPlayerInteract(PlayerInteractEvent e) {
    55. Player player = e.getPlayer();
    56. if(e.getAction() == Action.RIGHT_CLICK_BLOCK) {
    57. Block b = e.getClickedBlock();
    58. if(b.getType() == Material.WALL_SIGN || b.getType() == Material.SIGN_POST) {
    59. Sign sign = (Sign) b.getState();
    60. String[] lines = sign.getLines();
    61. if(lines[0].equalsIgnoreCase(ChatColor.DARK_RED + "[Perk-A-Cola]")) {
    62. if(lines[2].equals(ChatColor.BOLD + "PhD")) {
    63. if(player.hasPermission("perk.use"))
    64. this.setPlayerImmune(player, true);
    65. player.sendMessage(ChatColor.GOLD + "[Perk-A-Cola]" + ChatColor.AQUA + " You have purchased PhD!");
    66. player.playSound(player.getLocation(), Sound.LEVEL_UP, 10.0F, 3);
    67. }
    68. }
    69. }
    70. }
    71. }
    72. }


    Tombstone Class (Not Finished)
    Code:java
    1. public class Tombstone implements Listener {
    2.  
    3. @EventHandler
    4. public void onSignChange(SignChangeEvent e) {
    5. if(e.getLine(0).equalsIgnoreCase("[Perk-A-Cola]")) {
    6. if(e.getLine(2).equalsIgnoreCase("Tombstone")) {
    7. if(e.getPlayer().hasPermission("perk.place"))
    8. e.setLine(0, ChatColor.DARK_RED + "[Perk-A-Cola]");
    9. e.setLine(2, ChatColor.BOLD + "Tombstone");
    10. e.getPlayer().sendMessage(ChatColor.GOLD + "[Perk-A-Cola]" + ChatColor.AQUA + " You have created a Perk-A-Cola sign!");
    11. }
    12. }
    13. }
    14. @EventHandler
    15. public void onPlayerInteract(PlayerInteractEvent e) {
    16. Player player = e.getPlayer();
    17. if(e.getAction() == Action.RIGHT_CLICK_BLOCK) {
    18. Block b = e.getClickedBlock();
    19. if(b.getType() == Material.WALL_SIGN || b.getType() == Material.SIGN_POST) {
    20. Sign sign = (Sign) b.getState();
    21. String[] lines = sign.getLines();
    22. if(lines[0].equalsIgnoreCase(ChatColor.DARK_RED + "[Perk-A-Cola]")) {
    23. if(lines[2].equals(ChatColor.BOLD + "Tombstone")) {
    24. if(player.hasPermission("perk.use"))
    25. player.sendMessage(ChatColor.GOLD + "[Perk-A-Cola]" + ChatColor.AQUA + " You have purchased Tombstone!");
    26. player.playSound(player.getLocation(), Sound.LEVEL_UP, 10.0F, 3);
    27. }
    28. }
    29. }
    30. }
    31. }
    32. }



    If you read my code, you would see on all the perks, you have the if statements for the sign, I want to be able to check if their is a price at the 3rd line of the sign, if not, then make the price of the sign to free. Please ask any questions and feel free to use any website to edit my code. Thank you.
     
  2. Offline

    Jaaakee224

    SoTotallyRoary
    I looked at this before I posted, I still can't figure it out.
     
  3. thats litterally the code you have to type to implement vault so you can use economy. if you want to actually charge people when using the command or whatever then you will need the vault java docs
     
  4. Offline

    Jaaakee224

    SoTotallyRoary Do I have to do setupChat & setupPermissions? I want it to charge the player on the sign click for my perk plugin, that is why I gave out all the classes for someone to implement Vault and explain to me what everything is. (This is my first time working with an economy.) Sorry for the dumb questions and whatever.
     
  5. I'm not sure but to be safe I would do them.
     
Thread Status:
Not open for further replies.

Share This Page