Advertisement
Blaze_4_Dayz

Code for my events class

Jan 6th, 2019
198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.13 KB | None | 0 0
  1. private static int mcoins;
  2. @EventHandler
  3. public void OnPlayerJoin(PlayerJoinEvent e) {
  4. CoinsAPI.createPlayer(e.getPlayer().getUniqueId().toString());
  5. }
  6.  
  7. @EventHandler
  8. public void OnInvClick(InventoryClickEvent e) {
  9. if ((e.getInventory() != null) &&
  10. (e.getInventory().getTitle().equals(Utils.getTitle()))) {
  11. Player p = (Player)e.getWhoClicked();
  12. for (int i = 0; i < 28; i++) {
  13. if (Utils.getitem(i, p) != null) {
  14. if (e.getCurrentItem().equals(Utils.getitem(i, p))) {
  15. String player = p.getUniqueId().toString();
  16. if (CoinsAPI.getCoins(player).intValue() >= Utils.getPrice(i, p)) {
  17. p.closeInventory();
  18. CoinsAPI.removeCoins(player, Utils.getPrice(i, p));
  19. p.sendMessage(Utils.getprefix() + ChatColor.GRAY + " You Bought an Item From The Shop!");
  20. java.util.List<String> command = MainCoins.getInstance().getConfig().getStringList("Shop." + i + ".Commands");
  21. for (String cmd : command) {
  22. org.bukkit.Bukkit.getServer().dispatchCommand(org.bukkit.Bukkit.getServer().getConsoleSender(), cmd.replace("%player%", e.getWhoClicked().getName()));
  23. }
  24. } else {
  25. p.closeInventory();
  26. p.sendMessage(Utils.getprefix() + ChatColor.GRAY + " You don't have enough Mobcoins!");
  27. }
  28. } else {
  29. Shop.reloadBals();
  30. p.updateInventory();
  31. e.setCancelled(true);
  32. }
  33. }
  34. }
  35. }
  36. }
  37. @SuppressWarnings("deprecation")
  38. @EventHandler
  39. public void OnEntityDeath(EntityDeathEvent e)
  40. {
  41. if ((e.getEntity().getKiller() != null) &&
  42. (e.getEntityType() != null) && (e.getEntityType().getName() != null) &&
  43. (Utils.hasmob(e.getEntityType().getName().toUpperCase()).booleanValue())) {
  44. Random object = new Random();
  45. int i = 1 + object.nextInt(100);
  46. if (i <= Utils.getChange(e.getEntityType().getName().toUpperCase())) {
  47. Player p = e.getEntity().getKiller();
  48. if (p == null) return;
  49. String player = p.getUniqueId().toString();
  50. MobCoinsGiveEvent event = new MobCoinsGiveEvent(p, 1);
  51. org.bukkit.Bukkit.getPluginManager().callEvent(event);
  52. if (event.getAmount().intValue() > 1) {
  53. p.sendMessage(Utils.getprefix() + ChatColor.GRAY + " You Killed A " + e.getEntityType().getName() + " and Gained " + event.getAmount() + " Mobcoins!");
  54. } else {
  55. p.sendMessage(Utils.getprefix() + ChatColor.GRAY + " You Killed A " + e.getEntityType().getName() + " and Gained " + event.getAmount() + " Mobcoin!");
  56. }
  57. CoinsAPI.addCoins(player, event.getAmount().intValue());
  58. }
  59. }
  60. }
  61. private final java.io.File bal = new java.io.File("plugins//MobCoinss//Balances.yml");
  62. private final YamlConfiguration bal1 = YamlConfiguration.loadConfiguration(bal);
  63. @EventHandler
  64. public void onPlayerJoin(PlayerJoinEvent e) {
  65. Player p = e.getPlayer();
  66. String player = p.getUniqueId().toString();
  67. if (!bal1.contains(player)) {
  68. bal1.set(player, 0);
  69. MainCoins.getInstance().saveCustomYml(bal1, bal);
  70.  
  71. }
  72. }
  73.  
  74. public static int getItemAmount(ItemStack ie, Player p){
  75. ItemStack item = p.getItemInHand();
  76. ItemMeta itemm = item.getItemMeta();
  77. if(itemm.getLore() != null && item != null){
  78. for(String line : itemm.getLore()) {
  79. if(line.startsWith("Amount: ")){
  80. String level = line.replace("Amount: ", "");
  81. level = ChatColor.stripColor(level);
  82. item.setItemMeta(itemm);
  83. Events.mcoins = Integer.parseInt(level);
  84. }
  85. }
  86. }
  87. return Events.mcoins;
  88. }
  89.  
  90. @EventHandler
  91. public void onpi(PlayerInteractEvent e) {
  92. Player p = e.getPlayer();
  93.  
  94. if (e.getAction() == Action.RIGHT_CLICK_AIR) {
  95. p.sendMessage("1");
  96. if (e.getPlayer().getItemInHand().getItemMeta().getDisplayName().contains(ChatColor.translateAlternateColorCodes('&', "&6&lMob Coin &7(Right Click)"))) {
  97. ItemStack item = p.getItemInHand();
  98. Events.getItemAmount(item, p);
  99. p.sendMessage( "there is " + mcoins);
  100. }
  101. }
  102. }
  103.  
  104. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement