Advertisement
Guest User

Untitled

a guest
Mar 18th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 8.05 KB | None | 0 0
  1. package eu.hyxperia.factions;
  2.  
  3. import java.io.File;
  4. import java.util.List;
  5. import java.util.Random;
  6. import java.util.UUID;
  7. import net.md_5.bungee.api.ChatColor;
  8. import org.bukkit.Bukkit;
  9. import org.bukkit.Server;
  10. import org.bukkit.configuration.file.FileConfiguration;
  11. import org.bukkit.configuration.file.YamlConfiguration;
  12. import org.bukkit.entity.EntityType;
  13. import org.bukkit.entity.HumanEntity;
  14. import org.bukkit.entity.LivingEntity;
  15. import org.bukkit.entity.Player;
  16. import org.bukkit.event.EventHandler;
  17. import org.bukkit.event.Listener;
  18. import org.bukkit.event.entity.EntityDeathEvent;
  19. import org.bukkit.event.inventory.InventoryClickEvent;
  20. import org.bukkit.event.player.PlayerJoinEvent;
  21. import org.bukkit.inventory.Inventory;
  22. import org.bukkit.inventory.ItemStack;
  23. import org.bukkit.inventory.meta.ItemMeta;
  24.  
  25. public class Events
  26.   implements Listener
  27. {
  28.   private static Main plugin;
  29.   File CE = new File("plugins//CustomEnchants//config.yml");
  30.   YamlConfiguration CEConfig = YamlConfiguration.loadConfiguration(this.CE);
  31.  
  32.   public Events(Main pl)
  33.   {
  34.     plugin = pl;
  35.   }
  36.  
  37.   public static String convertPower(int i)
  38.   {
  39.     if (i <= 0) {
  40.       return "I";
  41.     }
  42.     if (i == 1) {
  43.       return "I";
  44.     }
  45.     if (i == 2) {
  46.       return "II";
  47.     }
  48.     if (i == 3) {
  49.       return "III";
  50.     }
  51.     if (i == 4) {
  52.       return "IV";
  53.     }
  54.     if (i == 5) {
  55.       return "V";
  56.     }
  57.     if (i == 6) {
  58.       return "VI";
  59.     }
  60.     if (i == 7) {
  61.       return "VII";
  62.     }
  63.     if (i == 8) {
  64.       return "VIII";
  65.     }
  66.     if (i == 9) {
  67.       return "IX";
  68.     }
  69.     if (i == 10) {
  70.       return "X";
  71.     }
  72.     return i;
  73.   }
  74.  
  75.   @EventHandler
  76.   public void OnPlayerJoin(PlayerJoinEvent e)
  77.   {
  78.     Player p = e.getPlayer();
  79.     String player = p.getUniqueId().toString();
  80.     CoinsAPI.createPlayer(player);
  81.   }
  82.  
  83.   @EventHandler
  84.   public void OnInvClick(InventoryClickEvent e)
  85.   {
  86.     if (e.getInventory().getTitle().equals(Utils.getTitle()))
  87.     {
  88.       Player p = (Player)e.getWhoClicked();
  89.       for (int i = 0; i < 28; i++) {
  90.         if (e.getCurrentItem().equals(Utils.getItem(i, p)))
  91.         {
  92.           String player = p.getUniqueId().toString();
  93.           if (CoinsAPI.getCoins(player).intValue() >= Utils.getPrice(i, p))
  94.           {
  95.             p.closeInventory();
  96.             CoinsAPI.removeCoins(player, Utils.getPrice(i, p));
  97.             p.sendMessage(Utils.getprefix() + ChatColor.GRAY + " You Brought an Item From The Shop!");
  98.             List<String> command = plugin.getConfig().getStringList("Shop." + i + ".Commands");
  99.             for (String cmd : command) {
  100.               Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), cmd.replace("%player%", e.getWhoClicked().getName()));
  101.             }
  102.           }
  103.           else
  104.           {
  105.             p.closeInventory();
  106.             p.sendMessage(Utils.getprefix() + ChatColor.GRAY + " You dont have enough Mobcoins!");
  107.           }
  108.         }
  109.         else
  110.         {
  111.           e.setCancelled(true);
  112.         }
  113.       }
  114.     }
  115.   }
  116.  
  117.   @EventHandler
  118.   public void OnEntityDeath(EntityDeathEvent e)
  119.   {
  120.     if (e.getEntityType().equals(EntityType.GHAST))
  121.     {
  122.       Random object = new Random();
  123.       for (int counter = 1; counter <= 1; counter++)
  124.       {
  125.         int i = 1 + object.nextInt(100);
  126.         if (i <= Utils.getghast())
  127.         {
  128.           Player p = e.getEntity().getKiller();
  129.           if (p == null) {
  130.             return;
  131.           }
  132.           String player = p.getUniqueId().toString();
  133.           if ((p.getItemInHand() != null) &&
  134.             (p.getItemInHand().hasItemMeta()) &&
  135.             (p.getItemInHand().getItemMeta().hasLore())) {
  136.             for (int counter1 = 1; counter1 <= this.CEConfig.getInt("MaxPower.Coins"); counter1++) {
  137.               if (Utils.hasenchant("Coins " + convertPower(counter1), p.getItemInHand()).booleanValue())
  138.               {
  139.                 p.sendMessage(Utils.getprefix() + ChatColor.GRAY + " Hai ucciso un ghast, hai guadagnato " + (counter1 + 1) + " Mobcoins!");
  140.                 CoinsAPI.addCoins(player, counter1 + 1);
  141.                 return;
  142.               }
  143.             }
  144.           }
  145.           p.sendMessage(Utils.getprefix() + ChatColor.GRAY + " Hai ucciso un ghast ed hai guadagnato 1 Mobcoin!");
  146.           CoinsAPI.addCoins(player, 1);
  147.         }
  148.       }
  149.     }
  150.     if (e.getEntityType().equals(EntityType.VILLAGER))
  151.     {
  152.       Random object = new Random();
  153.       for (int counter = 1; counter <= 1; counter++)
  154.       {
  155.         int i = 1 + object.nextInt(100);
  156.         if (i <= Utils.getvillager())
  157.         {
  158.           Player p = e.getEntity().getKiller();
  159.           if (p == null) {
  160.             return;
  161.           }
  162.           String player = p.getUniqueId().toString();
  163.           if ((p.getItemInHand() != null) &&
  164.             (p.getItemInHand().hasItemMeta()) &&
  165.             (p.getItemInHand().getItemMeta().hasLore())) {
  166.             for (int counter1 = 1; counter1 <= this.CEConfig.getInt("MaxPower.Coins"); counter1++) {
  167.               if (Utils.hasenchant("Coins " + convertPower(counter1), p.getItemInHand()).booleanValue())
  168.               {
  169.                 p.sendMessage(Utils.getprefix() + ChatColor.GRAY + " Hai ucciso un villager, hai guadagnato " + (counter1 + 1) + " Mobcoins!");
  170.                 CoinsAPI.addCoins(player, counter1 + 1);
  171.                 return;
  172.               }
  173.             }
  174.           }
  175.           p.sendMessage(Utils.getprefix() + ChatColor.GRAY + " Hai ucciso un villager ed hai guadagnato 1 Mobcoin!");
  176.           CoinsAPI.addCoins(player, 1);
  177.         }
  178.       }
  179.     }
  180.     if (e.getEntityType().equals(EntityType.BLAZE))
  181.     {
  182.       Random object = new Random();
  183.       for (int counter = 1; counter <= 1; counter++)
  184.       {
  185.         int i = 1 + object.nextInt(100);
  186.         if (i <= Utils.getblaze())
  187.         {
  188.           Player p = e.getEntity().getKiller();
  189.           if (p == null) {
  190.             return;
  191.           }
  192.           String player = p.getUniqueId().toString();
  193.           if ((p.getItemInHand() != null) &&
  194.             (p.getItemInHand().hasItemMeta()) &&
  195.             (p.getItemInHand().getItemMeta().hasLore())) {
  196.             for (int counter1 = 1; counter1 <= this.CEConfig.getInt("MaxPower.Coins"); counter1++) {
  197.               if (Utils.hasenchant("Coins " + convertPower(counter1), p.getItemInHand()).booleanValue())
  198.               {
  199.                 p.sendMessage(Utils.getprefix() + ChatColor.GRAY + " Hai ucciso un ghast, hai guadagnato " + (counter1 + 1) + " Mobcoins!");
  200.                 CoinsAPI.addCoins(player, counter1 + 1);
  201.                 return;
  202.               }
  203.             }
  204.           }
  205.           p.sendMessage(Utils.getprefix() + ChatColor.GRAY + " Hai ucciso un blaze ed hai guadagnato 1 Mobcoin!");
  206.           CoinsAPI.addCoins(player, 1);
  207.         }
  208.       }
  209.     }
  210.     if (e.getEntityType().equals(EntityType.MAGMA_CUBE))
  211.     {
  212.       Random object = new Random();
  213.       for (int counter = 1; counter <= 1; counter++)
  214.       {
  215.         int i = 1 + object.nextInt(100);
  216.         if (i <= Utils.getcube())
  217.         {
  218.           Player p = e.getEntity().getKiller();
  219.           if (p == null) {
  220.             return;
  221.           }
  222.           String player = p.getUniqueId().toString();
  223.           if ((p.getItemInHand() != null) &&
  224.             (p.getItemInHand().hasItemMeta()) &&
  225.             (p.getItemInHand().getItemMeta().hasLore())) {
  226.             for (int counter1 = 1; counter1 <= this.CEConfig.getInt("MaxPower.Coins"); counter1++) {
  227.               if (Utils.hasenchant("Coins " + convertPower(counter1), p.getItemInHand()).booleanValue())
  228.               {
  229.                 p.sendMessage(Utils.getprefix() + ChatColor.GRAY + " Hai ucciso un MAGMACUBE, hai guadagnato " + (counter1 + 1) + " Mobcoins!");
  230.                 CoinsAPI.addCoins(player, counter1 + 1);
  231.                 return;
  232.               }
  233.             }
  234.           }
  235.           p.sendMessage(Utils.getprefix() + ChatColor.GRAY + " Hai ucciso un MAGNACUBE ed hai guadagnato 1 Mobcoin!");
  236.           CoinsAPI.addCoins(player, 1);
  237.         }
  238.       }
  239.     }
  240.   }
  241. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement