Advertisement
Mouamle

ToArabic

Jul 27th, 2015
522
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.79 KB | None | 0 0
  1. package me.danybv.ArmorEffects;
  2.  
  3. import java.util.List;
  4. import org.bukkit.ChatColor;
  5. import org.bukkit.Server;
  6. import org.bukkit.entity.Player;
  7. import org.bukkit.event.Listener;
  8. import org.bukkit.inventory.ItemStack;
  9. import org.bukkit.inventory.PlayerInventory;
  10. import org.bukkit.inventory.meta.ItemMeta;
  11. import org.bukkit.plugin.PluginManager;
  12. import org.bukkit.plugin.java.JavaPlugin;
  13. import org.bukkit.potion.PotionEffect;
  14. import org.bukkit.potion.PotionEffectType;
  15. import org.bukkit.scheduler.BukkitScheduler;
  16.  
  17. public class Main
  18.   extends JavaPlugin
  19.   implements Listener
  20. {
  21.   public static int POTION_TIME = 21;
  22.  
  23.   public void onEnable()
  24.   {
  25.     getServer().getPluginManager().registerEvents(this, this);
  26.     BukkitScheduler scheduler = getServer().getScheduler();
  27.     scheduler.scheduleSyncRepeatingTask(this, new Runnable()
  28.     {
  29.       public void run()
  30.       {
  31.         for (Player p : Main.this.getServer().getOnlinePlayers())
  32.         {
  33.           Main.this.itemPotion(p, p.getInventory().getHelmet());
  34.           Main.this.itemPotion(p, p.getInventory().getChestplate());
  35.           Main.this.itemPotion(p, p.getInventory().getLeggings());
  36.           Main.this.itemPotion(p, p.getInventory().getBoots());
  37.         }
  38.       }
  39.     }, 0L, POTION_TIME - 1);
  40.   }
  41.  
  42.   boolean checkLore(Player p, ItemStack item)
  43.   {
  44.     if (item == null) {
  45.       return false;
  46.     }
  47.     if (!item.hasItemMeta()) {
  48.       return false;
  49.     }
  50.     if (!item.getItemMeta().hasLore()) {
  51.       return false;
  52.     }
  53.     String[] itemLore = ChatColor.stripColor((String)item.getItemMeta().getLore().get(0)).split(" ");
  54.     if ((PotionEffectType.getByName(itemLore[0]) == null) && (PotionEffectType.getByName(itemLore[0] + "_" + itemLore[1]) == null)) {
  55.       return false;
  56.     }
  57.     return true;
  58.   }
  59.  
  60.   public void itemPotion(Player p, ItemStack item)
  61.   {
  62.     if (checkLore(p, item))
  63.     {
  64.       String itemLore = ChatColor.stripColor(((String)item.getItemMeta().getLore().get(0)).replaceFirst(" ", "_"));
  65.       String[] itemPotionLore = itemLore.split(" ");
  66.       PotionEffect pE = null;
  67.       PotionEffectType pET = PotionEffectType.getByName(itemPotionLore[0]);
  68.       if (itemPotionLore.length == 1) {
  69.         pE = new PotionEffect(pET, POTION_TIME, 0);
  70.       } else if (itemPotionLore.length == 2) {
  71.         pE = new PotionEffect(pET, POTION_TIME, ToArabic(itemPotionLore[1]) - 1);
  72.       }
  73.       p.removePotionEffect(pET);
  74.       p.addPotionEffect(pE);
  75.     }
  76.   }
  77.  
  78.   public int ToArabic(String number)
  79.   {
  80.     if ((number.equalsIgnoreCase("")) || (number == null)) {
  81.       return 0;
  82.     }
  83.     if (number.startsWith("M")) {
  84.       return 1000 + ToArabic(number.substring(1));
  85.     }
  86.     if (number.startsWith("CM")) {
  87.       return 900 + ToArabic(number.substring(2));
  88.     }
  89.     if (number.startsWith("D")) {
  90.       return 500 + ToArabic(number.substring(1));
  91.     }
  92.     if (number.startsWith("CD")) {
  93.       return 400 + ToArabic(number.substring(2));
  94.     }
  95.     if (number.startsWith("C")) {
  96.       return 100 + ToArabic(number.substring(1));
  97.     }
  98.     if (number.startsWith("XC")) {
  99.       return 90 + ToArabic(number.substring(2));
  100.     }
  101.     if (number.startsWith("L")) {
  102.       return 50 + ToArabic(number.substring(1));
  103.     }
  104.     if (number.startsWith("XL")) {
  105.       return 40 + ToArabic(number.substring(2));
  106.     }
  107.     if (number.startsWith("X")) {
  108.       return 10 + ToArabic(number.substring(1));
  109.     }
  110.     if (number.startsWith("IX")) {
  111.       return 9 + ToArabic(number.substring(2));
  112.     }
  113.     if (number.startsWith("V")) {
  114.       return 5 + ToArabic(number.substring(1));
  115.     }
  116.     if (number.startsWith("IV")) {
  117.       return 4 + ToArabic(number.substring(2));
  118.     }
  119.     if (number.startsWith("I")) {
  120.       return 1 + ToArabic(number.substring(1));
  121.     }
  122.     return 0;
  123.   }
  124. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement