Advertisement
Guest User

KingsLandingForYah

a guest
May 7th, 2014
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 9.18 KB | None | 0 0
  1. package me.tizzletimmz3.KingsLanding;
  2.  
  3. import java.util.HashMap;
  4. import java.util.List;
  5. import java.util.logging.Logger;
  6.  
  7. import org.bukkit.ChatColor;
  8. import org.bukkit.Effect;
  9. import org.bukkit.Location;
  10. import org.bukkit.Material;
  11. import org.bukkit.command.Command;
  12. import org.bukkit.command.CommandSender;
  13. import org.bukkit.entity.Damageable;
  14. import org.bukkit.entity.Entity;
  15. import org.bukkit.entity.Player;
  16. import org.bukkit.event.EventHandler;
  17. import org.bukkit.event.Listener;
  18. import org.bukkit.event.entity.EntityDamageEvent;
  19. import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
  20. import org.bukkit.inventory.ItemStack;
  21. import org.bukkit.inventory.PlayerInventory;
  22. import org.bukkit.plugin.PluginDescriptionFile;
  23. import org.bukkit.plugin.java.JavaPlugin;
  24.  
  25. public class KingsLanding extends JavaPlugin implements Listener {
  26.  
  27.     public final Logger logger = Logger.getLogger("Minecraft");
  28.     HashMap<String, Integer> plrs = new HashMap<String, Integer>();
  29.  
  30.     @Override
  31.     public void onDisable() {
  32.         PluginDescriptionFile pdfFile = this.getDescription();
  33.         this.logger.info(pdfFile.getName() + " Has Been Disabled!");
  34.     }
  35.  
  36.     @Override
  37.     public void onEnable() {
  38.         getServer().getPluginManager().registerEvents(this, this);
  39.         PluginDescriptionFile pdfFile = this.getDescription();
  40.         this.logger.info(pdfFile.getName() + " Version " + pdfFile.getVersion()
  41.                 + " Has Been Enabled!");
  42.         getConfig().options().copyDefaults(true);
  43.         saveConfig();
  44.     }
  45.  
  46.     @Override
  47.     public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
  48.         Player p = (Player) sender;
  49.         if (!(sender instanceof Player)) {
  50.             return true;
  51.         }
  52.  
  53.         if (label.equalsIgnoreCase("KingsLanding") || label.equalsIgnoreCase("KL")) {
  54.             if (args.length == 1) {
  55.  
  56.                 if (args[0].equalsIgnoreCase("toggle")) {
  57.                     if (p.hasPermission("kingslanding.explosive") || p.isOp()) {
  58.                         if (plrs.containsKey(p.getUniqueId().toString())) {
  59.                             plrs.remove(p.getUniqueId().toString());
  60.                             p.sendMessage(ChatColor.BLUE + "Kingslanding has been toggled off!");
  61.                             return true;
  62.                         } else {
  63.                             plrs.put(p.getUniqueId().toString(), 1);
  64.                             p.sendMessage(ChatColor.BLUE + "Kingslanding has been toggled on!");
  65.                             return true;
  66.                         }
  67.                     } else {
  68.                         p.sendMessage(ChatColor.RED + "You do not have permission to use this command!");
  69.                         return true;
  70.                     }
  71.                 } else if (args[0].equalsIgnoreCase("enable")) {
  72.                     if (p.hasPermission("kingslanding.admin") || p.isOp()) {
  73.                         getConfig().set("Enabled", "true");
  74.                         saveConfig();
  75.                         p.sendMessage(ChatColor.BLUE + "KingsLanding has been enabled!");
  76.                         return true;
  77.                     } else {
  78.                         p.sendMessage(ChatColor.RED + "You do not have permission to use this command!");
  79.                         return true;
  80.                     }
  81.                 } else if (args[0].equalsIgnoreCase("disable")) {
  82.                     if (p.hasPermission("kingslanding.admin") || p.isOp()) {
  83.                         getConfig().set("Enabled", "false");
  84.                         saveConfig();
  85.                         p.sendMessage(ChatColor.BLUE + "KingsLanding has been disabled!");
  86.                         return true;
  87.                     } else {
  88.                         p.sendMessage(ChatColor.RED + "You do not have permission to use this command!");
  89.                         return true;
  90.                     }
  91.                 } else {
  92.                     p.sendMessage(ChatColor.RED + "Try <" + ChatColor.BLUE + "/kl toggle" + ChatColor.RED + "> or <" + ChatColor.BLUE + "/kl enable:disable" + ChatColor.RED + ">");
  93.                 }
  94.             } else {
  95.                 p.sendMessage(ChatColor.RED + "Try <" + ChatColor.BLUE + "/kl toggle" + ChatColor.RED + "> or <" + ChatColor.BLUE + "/kl enable:disable" + ChatColor.RED + ">");
  96.             }
  97.         }
  98.         return true;
  99.     }
  100.  
  101.     @SuppressWarnings("deprecation")
  102.     @EventHandler
  103.     public void onFall(EntityDamageEvent event) {
  104.         if (!(event.getEntity() instanceof Player)) {
  105.             return;
  106.         }
  107.         Player p = (Player) event.getEntity();
  108.         Location location = p.getLocation();
  109.         List<Entity> near = location.getWorld().getEntities();
  110.         int dis = getConfig().getInt("FallDistance");
  111.         int health = getConfig().getInt("Health");
  112.         int ammt = getConfig().getInt("ItemToTake.HowMuch");
  113.         int thin = getConfig().getInt("ItemToTake.ItemID");
  114.         double radius = 4D;
  115.         if (plrs.containsKey(p.getUniqueId().toString())) {
  116.             if (getConfig().getString("Enabled").equals("true")) {
  117.                 if (event.getCause() == DamageCause.FALL) {
  118.                     if (p.hasPermission("kingslanding.explosive") || p.isOp()) {
  119.                         if (p.getFallDistance() >= dis) {
  120.                             if (p.getInventory().contains(thin, ammt)) {
  121.                                 takePowder(p);
  122.                                 int mat = p.getWorld().getBlockAt((int)p.getLocation().getX(), (int)p.getLocation().getY() - 1, (int)p.getLocation().getZ()).getTypeId();
  123.                                 int material = getConfig().getInt("Block.ID1");
  124.                                 int material1 = getConfig().getInt("Block.ID2");
  125.                                 int material2 = getConfig().getInt("Block.ID3");
  126.                                 int material3 = getConfig().getInt("Block.ID4");
  127.                                 int material4 = getConfig().getInt("Block.ID5");
  128.                                 int material5 = getConfig().getInt("Block.ID6");
  129.                                 int material6 = getConfig().getInt("Block.ID7");
  130.                                 int material7 = getConfig().getInt("Block.ID8");
  131.                                 int material8 = getConfig().getInt("Block.ID9");
  132.                                 int material9 = getConfig().getInt("Block.ID10");
  133.  
  134.                                 if ((mat == material1) || (mat == material2) || (mat == material3) || (mat == material4) || (mat == material5) || (mat == material6) || (mat == material7) || (mat == material8) || (mat == material9) || (mat == material)) {
  135.                                     int h = (int) p.getLocation().getX() - 1;
  136.                                     int h1 = (int) p.getLocation().getY();
  137.                                     int h2 = (int) p.getLocation().getZ() - 1;
  138.                                     int f = (int) p.getLocation().getX() + 1;
  139.                                     int f1 = (int) p.getLocation().getY();
  140.                                     int f2 = (int) p.getLocation().getZ() + 1;
  141.                                     int b = (int) p.getLocation().getX();
  142.                                     int b1 = (int) p.getLocation().getY();
  143.                                     int b2 = (int) p.getLocation().getZ() - 2;
  144.                                     int k = (int) p.getLocation().getX();
  145.                                     int k1 = (int) p.getLocation().getY();
  146.                                     int k2 = (int) p.getLocation().getZ() + 2;
  147.                                     int i = (int) p.getLocation().getX() + 2;
  148.                                     int i1 = (int) p.getLocation().getY();
  149.                                     int i2 = (int) p.getLocation().getZ();
  150.                                     int o = (int) p.getLocation().getX() - 2;
  151.                                     int o1 = (int) p.getLocation().getY();
  152.                                     int o2 = (int) p.getLocation().getZ();
  153.                                     int l = (int) p.getLocation().getX() + 1;
  154.                                     int l1 = (int) p.getLocation().getY();
  155.                                     int l2 = (int) p.getLocation().getZ() - 1;
  156.                                     int y = (int) p.getLocation().getX() - 1;
  157.                                     int y1 = (int) p.getLocation().getY();
  158.                                     int y2 = (int) p.getLocation().getZ() + 1;
  159.                                     Location loc = new Location (p.getWorld(), h, h1, h2);
  160.                                     Location loc1 = new Location (p.getWorld(), f, f1, f2);
  161.                                     Location loc2 = new Location (p.getWorld(), b, b1, b2);
  162.                                     Location loc3 = new Location (p.getWorld(), l, l1, l2);
  163.                                     Location loc4 = new Location (p.getWorld(), i, i1, i2);
  164.                                     Location loc5 = new Location (p.getWorld(), y, y1, y2);
  165.                                     Location loc6 = new Location (p.getWorld(), o, o1, o2);
  166.                                     Location loc7 = new Location (p.getWorld(), k, k1, k2);
  167.                                     p.getWorld().createExplosion(p.getLocation().getX(), p.getLocation().getY(), p.getLocation().getZ(), 3, false, false);
  168.                                     p.getWorld().playEffect(location, Effect.MOBSPAWNER_FLAMES, 10, 10);
  169.                                     p.getWorld().playEffect(loc, Effect.MOBSPAWNER_FLAMES, 10, 10);
  170.                                     p.getWorld().playEffect(loc1, Effect.MOBSPAWNER_FLAMES, 10, 10);
  171.                                     p.getWorld().playEffect(loc2, Effect.MOBSPAWNER_FLAMES, 10, 10);
  172.                                     p.getWorld().playEffect(loc3, Effect.MOBSPAWNER_FLAMES, 10, 10);
  173.                                     p.getWorld().playEffect(loc4, Effect.MOBSPAWNER_FLAMES, 10, 10);
  174.                                     p.getWorld().playEffect(loc5, Effect.MOBSPAWNER_FLAMES, 10, 10);
  175.                                     p.getWorld().playEffect(loc6, Effect.MOBSPAWNER_FLAMES, 10, 10);
  176.                                     p.getWorld().playEffect(loc7, Effect.MOBSPAWNER_FLAMES, 10, 10);
  177.                                     for(Entity e : near) {
  178.                                         if (e.getLocation().distance(location) <= radius) {
  179.                                             if (e instanceof Player) {
  180.                                                 Player pl = (Player) e;
  181.                                                 if (!(pl.getName().equals(p.getName()))) {
  182.                                                     pl.setHealth(pl.getHealth() - health);
  183.                                                     return;
  184.                                                 } else {
  185.                                                     return;
  186.                                                 }
  187.                                             } else if (e instanceof Damageable){
  188.                                                 ((Damageable) e).setHealth(((Damageable) e).getHealth() - health);
  189.                                                 return;
  190.                                             }
  191.                                         } else {
  192.                                             return;
  193.                                         }
  194.                                     }
  195.                                 } else {
  196.                                     return;
  197.                                 }
  198.                             } else {
  199.                                 return;
  200.                             }
  201.                         } else {
  202.                             return;
  203.                         }
  204.                     } else {
  205.                         return;
  206.                     }
  207.                 }
  208.             } else {
  209.                 return;
  210.             }
  211.         } else {
  212.             return;
  213.         }
  214.     }
  215.  
  216.     private void takePowder(Player p) {
  217.  
  218.         PlayerInventory inventory = p.getInventory();
  219.  
  220.         for (int i = 0; i < inventory.getSize(); i++) {
  221.             ItemStack item = inventory.getItem(i);
  222.             if (item != null && item.getType() == Material.SULPHUR) {
  223.                 ItemStack newItem;
  224.                 if (item.getAmount() <= 1) {
  225.                     newItem = null;
  226.                 } else {
  227.                     newItem = item.clone();
  228.                     newItem.setAmount(newItem.getAmount() - getConfig().getInt("ItemToTake.HowMuch"));
  229.                 }
  230.                 inventory.setItem(i, newItem);
  231.             }
  232.         }
  233.     }
  234. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement