Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package me.danybv.ArmorEffects;
- import java.util.List;
- import org.bukkit.ChatColor;
- import org.bukkit.Server;
- import org.bukkit.entity.Player;
- import org.bukkit.event.Listener;
- import org.bukkit.inventory.ItemStack;
- import org.bukkit.inventory.PlayerInventory;
- import org.bukkit.inventory.meta.ItemMeta;
- import org.bukkit.plugin.PluginManager;
- import org.bukkit.plugin.java.JavaPlugin;
- import org.bukkit.potion.PotionEffect;
- import org.bukkit.potion.PotionEffectType;
- import org.bukkit.scheduler.BukkitScheduler;
- public class Main
- extends JavaPlugin
- implements Listener
- {
- public static int POTION_TIME = 21;
- public void onEnable()
- {
- getServer().getPluginManager().registerEvents(this, this);
- BukkitScheduler scheduler = getServer().getScheduler();
- scheduler.scheduleSyncRepeatingTask(this, new Runnable()
- {
- public void run()
- {
- for (Player p : Main.this.getServer().getOnlinePlayers())
- {
- Main.this.itemPotion(p, p.getInventory().getHelmet());
- Main.this.itemPotion(p, p.getInventory().getChestplate());
- Main.this.itemPotion(p, p.getInventory().getLeggings());
- Main.this.itemPotion(p, p.getInventory().getBoots());
- }
- }
- }, 0L, POTION_TIME - 1);
- }
- boolean checkLore(Player p, ItemStack item)
- {
- if (item == null) {
- return false;
- }
- if (!item.hasItemMeta()) {
- return false;
- }
- if (!item.getItemMeta().hasLore()) {
- return false;
- }
- String[] itemLore = ChatColor.stripColor((String)item.getItemMeta().getLore().get(0)).split(" ");
- if ((PotionEffectType.getByName(itemLore[0]) == null) && (PotionEffectType.getByName(itemLore[0] + "_" + itemLore[1]) == null)) {
- return false;
- }
- return true;
- }
- public void itemPotion(Player p, ItemStack item)
- {
- if (checkLore(p, item))
- {
- String itemLore = ChatColor.stripColor(((String)item.getItemMeta().getLore().get(0)).replaceFirst(" ", "_"));
- String[] itemPotionLore = itemLore.split(" ");
- PotionEffect pE = null;
- PotionEffectType pET = PotionEffectType.getByName(itemPotionLore[0]);
- if (itemPotionLore.length == 1) {
- pE = new PotionEffect(pET, POTION_TIME, 0);
- } else if (itemPotionLore.length == 2) {
- pE = new PotionEffect(pET, POTION_TIME, ToArabic(itemPotionLore[1]) - 1);
- }
- p.removePotionEffect(pET);
- p.addPotionEffect(pE);
- }
- }
- public int ToArabic(String number)
- {
- if ((number.equalsIgnoreCase("")) || (number == null)) {
- return 0;
- }
- if (number.startsWith("M")) {
- return 1000 + ToArabic(number.substring(1));
- }
- if (number.startsWith("CM")) {
- return 900 + ToArabic(number.substring(2));
- }
- if (number.startsWith("D")) {
- return 500 + ToArabic(number.substring(1));
- }
- if (number.startsWith("CD")) {
- return 400 + ToArabic(number.substring(2));
- }
- if (number.startsWith("C")) {
- return 100 + ToArabic(number.substring(1));
- }
- if (number.startsWith("XC")) {
- return 90 + ToArabic(number.substring(2));
- }
- if (number.startsWith("L")) {
- return 50 + ToArabic(number.substring(1));
- }
- if (number.startsWith("XL")) {
- return 40 + ToArabic(number.substring(2));
- }
- if (number.startsWith("X")) {
- return 10 + ToArabic(number.substring(1));
- }
- if (number.startsWith("IX")) {
- return 9 + ToArabic(number.substring(2));
- }
- if (number.startsWith("V")) {
- return 5 + ToArabic(number.substring(1));
- }
- if (number.startsWith("IV")) {
- return 4 + ToArabic(number.substring(2));
- }
- if (number.startsWith("I")) {
- return 1 + ToArabic(number.substring(1));
- }
- return 0;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement