Advertisement
Guest User

Untitled

a guest
Apr 27th, 2017
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.78 KB | None | 0 0
  1. package me.nathanthesnooper;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.HashMap;
  5. import java.util.Set;
  6.  
  7. import org.bukkit.Bukkit;
  8. import org.bukkit.Location;
  9. import org.bukkit.Material;
  10. import org.bukkit.Sound;
  11. import org.bukkit.block.Block;
  12. import org.bukkit.command.Command;
  13. import org.bukkit.command.CommandSender;
  14. import org.bukkit.entity.Entity;
  15. import org.bukkit.entity.EntityType;
  16. import org.bukkit.entity.Fireball;
  17. import org.bukkit.entity.Player;
  18. import org.bukkit.entity.TNTPrimed;
  19. import org.bukkit.event.Cancellable;
  20. import org.bukkit.event.EventHandler;
  21. import org.bukkit.event.Listener;
  22. import org.bukkit.event.entity.EntityCombustEvent;
  23. import org.bukkit.event.entity.EntityDamageEvent;
  24. import org.bukkit.event.entity.EntityExplodeEvent;
  25. import org.bukkit.event.player.PlayerInteractEvent;
  26. import org.bukkit.inventory.ItemStack;
  27. import org.bukkit.inventory.meta.ItemMeta;
  28. import org.bukkit.plugin.java.JavaPlugin;
  29. import org.bukkit.util.Vector;
  30.  
  31. class wandcooldowns {
  32.  
  33. public boolean[] cooldowns = new boolean[]{true,true,true,true};
  34.  
  35. }
  36.  
  37. public class SinisterWands extends JavaPlugin implements Listener {
  38.  
  39. public static final String[] wands = new String[]{"jump","smite","fireball","tnt"};
  40. public static final String[] wandsDisplay = new String[]{"Jump", "Smite", "Fireball", "Tnt"};
  41. HashMap<Player, wandcooldowns> hm = new HashMap<Player, wandcooldowns>();
  42.  
  43. @Override
  44. public void onEnable () {
  45.  
  46. getLogger().info("SinisterWands is starting!");
  47.  
  48. getConfig().options().copyDefaults(true);
  49. saveConfig();
  50.  
  51. getServer().getPluginManager().registerEvents(this, this);
  52.  
  53. }
  54.  
  55. @Override
  56. public void onDisable () {
  57.  
  58. getLogger().info("SinisterWands is stopping!");
  59.  
  60. }
  61.  
  62. public wandcooldowns getcooldowns (Player p) {
  63. if (hm.containsKey(p)) {
  64. return hm.get(p);
  65. }
  66. hm.put(p, new wandcooldowns());
  67. return getcooldowns(p);
  68. }
  69.  
  70.  
  71. @EventHandler
  72. public void rClickEvent (PlayerInteractEvent event) {
  73.  
  74. Player plr = event.getPlayer();
  75.  
  76. if(!plr.getInventory().getItemInHand().equals(Material.AIR)) {
  77. if(plr.getInventory().getItemInHand().getItemMeta().hasDisplayName() && plr.getInventory().getItemInHand().getItemMeta().hasLore()) {
  78. for(String wandname : wands) {
  79.  
  80. if(getConfig().getString(wandname + "name").equals(plr.getInventory().getItemInHand().getItemMeta().getDisplayName())) {
  81. if(getConfig().getString(wandname + "lore").equals(plr.getInventory().getItemInHand().getItemMeta().getLore().get(0))) {
  82. if(wandname.equals("jump") && getcooldowns(plr).cooldowns[0]) {
  83. getcooldowns(plr).cooldowns[0] = false;
  84. jumpWand(plr);
  85. Bukkit.getScheduler().scheduleSyncDelayedTask(this, new Runnable() {
  86. public void run() {
  87. getcooldowns(plr).cooldowns[0] = true;
  88. if(getConfig().getBoolean("notifyplayers"))
  89. plr.sendMessage(wandsDisplay[0] + " is now ready");
  90. if(getConfig().getBoolean("notifyplayerssound"))
  91. plr.playSound(plr.getLocation(), Sound.NOTE_PLING, 10, 1);
  92. }
  93. }, Math.round(getConfig().getDouble("jumpcooldown") * 20));
  94. }
  95. if(wandname.equals("smite") && getcooldowns(plr).cooldowns[1]) {
  96. getcooldowns(plr).cooldowns[1] = false;
  97. smiteWand(plr);
  98. Bukkit.getScheduler().scheduleSyncDelayedTask(this, new Runnable() {
  99. public void run() {
  100. getcooldowns(plr).cooldowns[1] = true;
  101. if(getConfig().getBoolean("notifyplayers"))
  102. plr.sendMessage(wandsDisplay[1] + " is now ready");
  103. if(getConfig().getBoolean("notifyplayerssound"))
  104. plr.playSound(plr.getLocation(), Sound.NOTE_PLING, 10, 1);
  105. }
  106. }, Math.round(getConfig().getDouble("smitecooldown") * 20));
  107. }
  108. if(wandname.equals("fireball") && getcooldowns(plr).cooldowns[2]) {
  109. getcooldowns(plr).cooldowns[2] = false;
  110. fireballWand(plr);
  111. Bukkit.getScheduler().scheduleSyncDelayedTask(this, new Runnable() {
  112. public void run() {
  113. getcooldowns(plr).cooldowns[2] = true;
  114. if(getConfig().getBoolean("notifyplayers"))
  115. plr.sendMessage(wandsDisplay[2] + " is now ready");
  116. if(getConfig().getBoolean("notifyplayerssound"))
  117. plr.playSound(plr.getLocation(), Sound.NOTE_PLING, 10, 1);
  118. }
  119. }, Math.round(getConfig().getDouble("fireballcooldown") * 20));
  120. }
  121. if(wandname.equals("tnt") && getcooldowns(plr).cooldowns[3]) {
  122. getcooldowns(plr).cooldowns[3] = false;
  123. tntWand(plr);
  124. Bukkit.getScheduler().scheduleSyncDelayedTask(this, new Runnable() {
  125. public void run() {
  126. getcooldowns(plr).cooldowns[3] = true;
  127. if(getConfig().getBoolean("notifyplayers"))
  128. plr.sendMessage(wandsDisplay[3] + " is now ready");
  129. if(getConfig().getBoolean("notifyplayerssound"))
  130. plr.playSound(plr.getLocation(), Sound.NOTE_PLING, 10, 1);
  131. }
  132. }, Math.round(getConfig().getDouble("tntcooldown") * 20));
  133. }
  134. }
  135. }
  136.  
  137. }
  138. }
  139. }
  140.  
  141. }
  142.  
  143. @SuppressWarnings("deprecation")
  144. public boolean onCommand (CommandSender sender, Command command, String alias, String[] args) {
  145.  
  146. if(sender instanceof Player) {
  147.  
  148. Player plr = ((Player) sender).getPlayer();
  149.  
  150. if(command.getName().equals("wand") && plr.isOp()) {
  151.  
  152. if(args.length == 1) {
  153.  
  154. args[0] = args[0].toLowerCase();
  155.  
  156. ItemStack[] item = new ItemStack[1];
  157.  
  158. item[0] = new ItemStack(Material.getMaterial(getConfig().getString(args[0] + "wand")), 1);
  159.  
  160. ItemMeta meta = item[0].getItemMeta();
  161.  
  162. meta.setDisplayName(getConfig().getString(args[0] + "name"));
  163. ArrayList<String> lore = new ArrayList<String>();
  164. lore.add(getConfig().getString(args[0] + "lore"));
  165. meta.setLore(lore);
  166.  
  167. item[0].setItemMeta(meta);
  168.  
  169. plr.getInventory().addItem(item);
  170.  
  171. return true;
  172.  
  173. }
  174.  
  175. if(args.length == 2) {
  176.  
  177. plr = getServer().getPlayerExact(args[1]);
  178.  
  179. args[0] = args[0].toLowerCase();
  180.  
  181. ItemStack[] item = new ItemStack[1];
  182.  
  183. item[0] = new ItemStack(Material.getMaterial(getConfig().getString(args[0] + "wand")), 1);
  184.  
  185. ItemMeta meta = item[0].getItemMeta();
  186.  
  187. meta.setDisplayName(getConfig().getString(args[0] + "name"));
  188. ArrayList<String> lore = new ArrayList<String>();
  189. lore.add(getConfig().getString(args[0] + "lore"));
  190. meta.setLore(lore);
  191.  
  192. item[0].setItemMeta(meta);
  193.  
  194. plr.getInventory().addItem(item);
  195.  
  196. return true;
  197.  
  198. }
  199.  
  200. if(args.length == 0) {
  201.  
  202. plr.sendMessage("\u00a7aAvaliable wands: Jump, Smite, Fireball, Tnt");
  203. plr.sendMessage("\u00a7c[required] <optional>");
  204. plr.sendMessage("\u00a7cUsage: /wand [wand] <Player>");
  205.  
  206. }
  207.  
  208. }
  209.  
  210. }
  211.  
  212. return false;
  213.  
  214. }
  215.  
  216. public void jumpWand(Player plr) {
  217.  
  218. plr.setVelocity(plr.getVelocity().add(plr.getLocation().getDirection().multiply(getConfig().getDouble("jumpforce"))));
  219.  
  220. }
  221.  
  222. public ArrayList<Entity> ede = new ArrayList<Entity>();
  223.  
  224. public void smiteWand (Player plr) {
  225.  
  226. Block targetblock = plr.getTargetBlock((Set<Material>)null, 50);
  227. Location location = targetblock.getLocation();
  228. Entity e = plr.getWorld().strikeLightning(location);
  229.  
  230. ede.add(e);
  231.  
  232. }
  233.  
  234. public void fireballWand (Player plr) {
  235.  
  236. Entity e = plr.launchProjectile(Fireball.class);
  237. e.setVelocity(e.getLocation().getDirection().multiply(2));
  238.  
  239. ede.add(e);
  240.  
  241. }
  242.  
  243. public void tntWand (Player plr) {
  244.  
  245. Entity e = plr.getWorld().spawnEntity(plr.getLocation().add(plr.getLocation().getDirection()).add(new Vector(0,1,0)), EntityType.PRIMED_TNT);
  246. e.setVelocity(plr.getLocation().getDirection().multiply(2));
  247. ((TNTPrimed)e).setFuseTicks(30);
  248.  
  249. ede.add(e);
  250.  
  251. }
  252.  
  253. @EventHandler
  254. public void eLightningDamage (EntityCombustEvent event) {
  255.  
  256. if(ede.contains(event.getEntity())) {
  257.  
  258. event.setCancelled(true);
  259.  
  260. ede.remove(event.getEntity());
  261.  
  262. }
  263.  
  264. }
  265.  
  266. @EventHandler
  267. public void eDamage (EntityDamageEvent event) {
  268.  
  269. if(ede.contains(event.getEntity())) {
  270.  
  271. event.setCancelled(true);
  272.  
  273. ede.remove(event.getEntity());
  274.  
  275. }
  276.  
  277. if(event.getEntity().getType() == EntityType.DROPPED_ITEM) {
  278.  
  279. if(getConfig().getBoolean("forceitemsave")) {
  280.  
  281. ((Cancellable) event).setCancelled(true);
  282.  
  283. }
  284.  
  285. }
  286.  
  287. }
  288.  
  289. @EventHandler
  290. public void eExplode(EntityExplodeEvent event) {
  291.  
  292. if(ede.contains(event.getEntity())) {
  293.  
  294. event.blockList().clear();
  295.  
  296. ede.remove(event.getEntity());
  297.  
  298. }
  299.  
  300. }
  301.  
  302. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement