Advertisement
Guest User

PTMain.java

a guest
Aug 10th, 2013
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 10.76 KB | None | 0 0
  1. package mc.Bancey.PT;
  2.  
  3. import java.io.IOException;
  4. import java.util.ArrayList;
  5. import java.util.logging.Logger;
  6.  
  7. import org.bukkit.Bukkit;
  8. import org.bukkit.ChatColor;
  9. import org.bukkit.command.Command;
  10. import org.bukkit.command.CommandSender;
  11. import org.bukkit.entity.Player;
  12. import org.bukkit.inventory.PlayerInventory;
  13. import org.bukkit.plugin.PluginDescriptionFile;
  14. import org.bukkit.plugin.java.JavaPlugin;
  15. import org.bukkit.potion.PotionEffect;
  16. import org.bukkit.potion.PotionEffectType;
  17.  
  18. public class PTMain extends JavaPlugin {
  19.     public final Logger logger = Logger.getLogger("Minecraft");
  20.     public static PTMain plugin;
  21.  
  22.     public void onEnable() {
  23.         try {
  24.             Metrics metrics = new Metrics(this);
  25.             metrics.start();
  26.         } catch (IOException e) {
  27.             // Failed to submit the stats :-(
  28.         }
  29.         // get Lore Checking from config
  30.         final ArrayList<String> Lore1 = (ArrayList<String>) this.getConfig().getStringList("Preset1Lore");
  31.         final ArrayList<String> Lore2 = (ArrayList<String>) this.getConfig().getStringList("Preset2Lore");
  32.         final ArrayList<String> Lore3 = (ArrayList<String>) this.getConfig().getStringList("Preset3Lore");
  33.         final ArrayList<String> Lore4 = (ArrayList<String>) this.getConfig().getStringList("Preset4Lore");
  34.         final ArrayList<String> Lore5 = (ArrayList<String>) this.getConfig().getStringList("Preset5Lore");
  35.         final ArrayList<String> Lore6 = (ArrayList<String>) this.getConfig().getStringList("Preset6Lore");
  36.         // get Item Id's from config.
  37.         final int Preset1 = this.getConfig().getInt("Preset1-Item-ID");
  38.         final int Preset2 = this.getConfig().getInt("Preset2-Item-ID");
  39.         final int Preset3 = this.getConfig().getInt("Preset3-Item-ID");
  40.         final int Preset4 = this.getConfig().getInt("Preset4-Item-ID");
  41.         final int Preset5 = this.getConfig().getInt("Preset5-Item-ID");
  42.         final int Preset6 = this.getConfig().getInt("Preset6-Item-ID");
  43.         // get the potion effects from the config.
  44.         final String Preset1PE1 = this.getConfig().getString("Preset1-PotionEffect-1");
  45.         final String Preset1PE2 = this.getConfig().getString("Preset1-PotionEffect-2");
  46.         final String Preset1PE3 = this.getConfig().getString("Preset1-PotionEffect-3");
  47.         final String Preset1PE4 = this.getConfig().getString("Preset1-PotionEffect-4");
  48.         final String Preset1PE5 = this.getConfig().getString("Preset1-PotionEffect-5");
  49.         final String Preset2PE1 = this.getConfig().getString("Preset2-PotionEffect-1");
  50.         final String Preset2PE2 = this.getConfig().getString("Preset2-PotionEffect-2");
  51.         final String Preset2PE3 = this.getConfig().getString("Preset2-PotionEffect-3");
  52.         final String Preset2PE4 = this.getConfig().getString("Preset2-PotionEffect-4");
  53.         final String Preset2PE5 = this.getConfig().getString("Preset2-PotionEffect-5");
  54.         final String Preset3PE1 = this.getConfig().getString("Preset3-PotionEffect-1");
  55.         final String Preset3PE2 = this.getConfig().getString("Preset3-PotionEffect-2");
  56.         final String Preset3PE3 = this.getConfig().getString("Preset3-PotionEffect-3");
  57.         final String Preset3PE4 = this.getConfig().getString("Preset3-PotionEffect-4");
  58.         final String Preset3PE5 = this.getConfig().getString("Preset3-PotionEffect-5");
  59.         final String Preset4PE1 = this.getConfig().getString("Preset4-PotionEffect-1");
  60.         final String Preset4PE2 = this.getConfig().getString("Preset4-PotionEffect-2");
  61.         final String Preset4PE3 = this.getConfig().getString("Preset4-PotionEffect-3");
  62.         final String Preset4PE4 = this.getConfig().getString("Preset4-PotionEffect-4");
  63.         final String Preset4PE5 = this.getConfig().getString("Preset4-PotionEffect-5");
  64.         final String Preset5PE1 = this.getConfig().getString("Preset5-PotionEffect-1");
  65.         final String Preset5PE2 = this.getConfig().getString("Preset5-PotionEffect-2");
  66.         final String Preset5PE3 = this.getConfig().getString("Preset5-PotionEffect-3");
  67.         final String Preset5PE4 = this.getConfig().getString("Preset5-PotionEffect-4");
  68.         final String Preset5PE5 = this.getConfig().getString("Preset5-PotionEffect-5");
  69.         final String Preset6PE1 = this.getConfig().getString("Preset6-PotionEffect-1");
  70.         final String Preset6PE2 = this.getConfig().getString("Preset6-PotionEffect-2");
  71.         final String Preset6PE3 = this.getConfig().getString("Preset6-PotionEffect-3");
  72.         final String Preset6PE4 = this.getConfig().getString("Preset6-PotionEffect-4");
  73.         final String Preset6PE5 = this.getConfig().getString("Preset6-PotionEffect-5");
  74.         // get the potencey from the config.
  75.         final int Preset1Potencey = this.getConfig().getInt("Preset1-PotionPotencey");
  76.         final int Preset2Potencey = this.getConfig().getInt("Preset2-PotionPotencey");
  77.         final int Preset3Potencey = this.getConfig().getInt("Preset3-PotionPotencey");
  78.         final int Preset4Potencey = this.getConfig().getInt("Preset4-PotionPotencey");
  79.         final int Preset5Potencey = this.getConfig().getInt("Preset5-PotionPotencey");
  80.         final int Preset6Potencey = this.getConfig().getInt("Preset6-PotionPotencey");
  81.         PluginDescriptionFile pdfFile = this.getDescription();
  82.         this.logger.info(pdfFile.getName() + " Version " + pdfFile.getVersion() + " By Bancey, Has Been Enabled!");
  83.         saveDefaultConfig();
  84.         getServer().getPluginManager().registerEvents(new PlayerInventoryListener(this), this);
  85.         Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(this, new Runnable() {
  86.                     public void run() {
  87.                         for (Player online : Bukkit.getOnlinePlayers()) {
  88.                             PlayerInventory inv = online.getInventory();
  89.                             Player player = online.getPlayer();
  90.                             if (player.hasPermission("PT.getpotion")) {
  91.                                 // if the player has the permission. Apply the potion effects.
  92.                                 if ((inv.getItemInHand().getTypeId() == Preset1) && (inv.getItemInHand().getItemMeta().getLore().equals(Lore1))) {
  93.                                     player.addPotionEffect(new PotionEffect(PotionEffectType.getByName(Preset1PE1),Integer.MAX_VALUE, Preset1Potencey));
  94.                                     player.addPotionEffect(new PotionEffect(PotionEffectType.getByName(Preset1PE2),Integer.MAX_VALUE, Preset1Potencey));
  95.                                     player.addPotionEffect(new PotionEffect(PotionEffectType.getByName(Preset1PE3),Integer.MAX_VALUE, Preset1Potencey));
  96.                                     player.addPotionEffect(new PotionEffect(PotionEffectType.getByName(Preset1PE4),Integer.MAX_VALUE, Preset1Potencey));
  97.                                     player.addPotionEffect(new PotionEffect(PotionEffectType.getByName(Preset1PE5),Integer.MAX_VALUE, Preset1Potencey));
  98.                                 } else if ((inv.getItemInHand().getTypeId() == Preset2) && (inv.getItemInHand().getItemMeta().getLore().equals(Lore2))) {
  99.                                     player.addPotionEffect(new PotionEffect(PotionEffectType.getByName(Preset2PE1),Integer.MAX_VALUE, Preset2Potencey));
  100.                                     player.addPotionEffect(new PotionEffect(PotionEffectType.getByName(Preset2PE2),Integer.MAX_VALUE, Preset2Potencey));
  101.                                     player.addPotionEffect(new PotionEffect(PotionEffectType.getByName(Preset2PE3),Integer.MAX_VALUE, Preset2Potencey));
  102.                                     player.addPotionEffect(new PotionEffect(PotionEffectType.getByName(Preset2PE4),Integer.MAX_VALUE, Preset2Potencey));
  103.                                     player.addPotionEffect(new PotionEffect(PotionEffectType.getByName(Preset2PE5),Integer.MAX_VALUE, Preset2Potencey));
  104.                                 } else if ((inv.getItemInHand().getTypeId() == Preset3) && (inv.getItemInHand().getItemMeta().getLore().equals(Lore3))) {
  105.                                     player.addPotionEffect(new PotionEffect(PotionEffectType.getByName(Preset3PE1),Integer.MAX_VALUE, Preset3Potencey));
  106.                                     player.addPotionEffect(new PotionEffect(PotionEffectType.getByName(Preset3PE2),Integer.MAX_VALUE, Preset3Potencey));
  107.                                     player.addPotionEffect(new PotionEffect(PotionEffectType.getByName(Preset3PE3),Integer.MAX_VALUE, Preset3Potencey));
  108.                                     player.addPotionEffect(new PotionEffect(PotionEffectType.getByName(Preset3PE4),Integer.MAX_VALUE, Preset3Potencey));
  109.                                     player.addPotionEffect(new PotionEffect(PotionEffectType.getByName(Preset3PE5),Integer.MAX_VALUE, Preset3Potencey));
  110.                                 } else if ((inv.getItemInHand().getTypeId() == Preset4) && (inv.getItemInHand().getItemMeta().getLore().equals(Lore4))) {
  111.                                     player.addPotionEffect(new PotionEffect(PotionEffectType.getByName(Preset4PE1),Integer.MAX_VALUE, Preset4Potencey));
  112.                                     player.addPotionEffect(new PotionEffect(PotionEffectType.getByName(Preset4PE2),Integer.MAX_VALUE, Preset4Potencey));
  113.                                     player.addPotionEffect(new PotionEffect(PotionEffectType.getByName(Preset4PE3),Integer.MAX_VALUE, Preset4Potencey));
  114.                                     player.addPotionEffect(new PotionEffect(PotionEffectType.getByName(Preset4PE4),Integer.MAX_VALUE, Preset4Potencey));
  115.                                     player.addPotionEffect(new PotionEffect(PotionEffectType.getByName(Preset4PE5),Integer.MAX_VALUE, Preset4Potencey));
  116.                                 } else if ((inv.getItemInHand().getTypeId() == Preset5) && (inv.getItemInHand().getItemMeta().getLore().equals(Lore5))) {
  117.                                     player.addPotionEffect(new PotionEffect(PotionEffectType.getByName(Preset5PE1),Integer.MAX_VALUE, Preset5Potencey));
  118.                                     player.addPotionEffect(new PotionEffect(PotionEffectType.getByName(Preset5PE2),Integer.MAX_VALUE, Preset5Potencey));
  119.                                     player.addPotionEffect(new PotionEffect(PotionEffectType.getByName(Preset5PE3),Integer.MAX_VALUE, Preset5Potencey));
  120.                                     player.addPotionEffect(new PotionEffect(PotionEffectType.getByName(Preset5PE4),Integer.MAX_VALUE, Preset5Potencey));
  121.                                     player.addPotionEffect(new PotionEffect(PotionEffectType.getByName(Preset5PE5),Integer.MAX_VALUE, Preset5Potencey));
  122.                                 } else if ((inv.getItemInHand().getTypeId() == Preset6) && (inv.getItemInHand().getItemMeta().getLore().equals(Lore6))) {
  123.                                     player.addPotionEffect(new PotionEffect(PotionEffectType.getByName(Preset6PE1),Integer.MAX_VALUE, Preset6Potencey));
  124.                                     player.addPotionEffect(new PotionEffect(PotionEffectType.getByName(Preset6PE2),Integer.MAX_VALUE, Preset6Potencey));
  125.                                     player.addPotionEffect(new PotionEffect(PotionEffectType.getByName(Preset6PE3),Integer.MAX_VALUE, Preset6Potencey));
  126.                                     player.addPotionEffect(new PotionEffect(PotionEffectType.getByName(Preset6PE4),Integer.MAX_VALUE, Preset6Potencey));
  127.                                     player.addPotionEffect(new PotionEffect(PotionEffectType.getByName(Preset6PE5),Integer.MAX_VALUE, Preset6Potencey));
  128.                                 }
  129.                             }
  130.                         }
  131.                     }
  132.                 }, 20, 40);
  133.     }
  134.  
  135.     public void onDisable() {
  136.         PluginDescriptionFile pdfFile = this.getDescription();
  137.         this.logger.info(pdfFile.getName() + " Version " + pdfFile.getVersion() + " By Bancey, Has Been Disabled!");
  138.     }
  139.  
  140.     public boolean onCommand(CommandSender sender, Command cmd,String commandLabel, String[] args) {
  141.         Player p = (Player) sender;
  142.         if (p instanceof Player) {
  143.             if(commandLabel.equalsIgnoreCase("checkpermissions")) {
  144.                 if (!(p.hasPermission("PT.getPotion"))) {
  145.                     p.sendMessage(ChatColor.DARK_AQUA + "You do not have permission to use ItemPotion by Bancey");
  146.                 } else
  147.                     p.sendMessage(ChatColor.DARK_AQUA + "You do have permission to use ItemPotion by Bancey");
  148.                 }
  149.             }
  150.         return false;
  151.     }
  152. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement