Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package me.firstflames;
- import java.util.HashMap;
- import org.bukkit.Bukkit;
- import org.bukkit.ChatColor;
- import org.bukkit.Location;
- import org.bukkit.Material;
- import org.bukkit.Sound;
- import org.bukkit.entity.Player;
- import org.bukkit.event.EventHandler;
- import org.bukkit.event.Listener;
- import org.bukkit.event.block.*;
- import org.bukkit.event.player.PlayerInteractEvent;
- import org.bukkit.event.player.PlayerJoinEvent;
- import org.bukkit.plugin.java.JavaPlugin;
- import org.bukkit.util.Vector;
- import net.minecraft.server.v1_8_R3.Block;
- public class FlashListener extends JavaPlugin implements Listener {
- Integer timer;
- Integer charges;
- Player p;
- Block pBlockLooking;
- Location pBlockLocation;
- double pBlockX;
- double pBlockY;
- double pBlockZ;
- double pBlockLookX;
- double pBlockLookY;
- double pBlockLookZ;
- Location pLocation;
- Location pLocationCheck;
- float pPitch;
- float pYaw;
- Vector pDir;
- int done;
- public Vector stopVelocity = new Vector(0, 0, 0);
- int first;
- Material blockFound;
- Location doLocation;
- HashMap<Player, Integer> map = new HashMap<Player, Integer>();
- HashMap<Player, Integer> map2 = new HashMap<Player, Integer>();
- @Override
- public void onEnable() {
- getServer().getPluginManager().registerEvents(this, this);
- Bukkit.getScheduler().scheduleSyncRepeatingTask(this, new Runnable() {
- @Override
- public void run() {
- for (Player p : map.keySet()) {
- charges = map.get(p);
- timer = map2.get(p);
- if (charges < 6 && p.getItemInHand().getType() == Material.GOLD_AXE) {
- if (timer >= 3) {
- map2.put(p, timer = 0);
- map.put(p, ++charges);
- p.sendMessage(ChatColor.GRAY + "Flash Charges: " + ChatColor.YELLOW + charges);
- } else {
- map2.put(p, ++timer);
- }
- } else if (charges < 5 && p.getItemInHand().getType() == Material.DIAMOND_AXE) {
- if (timer >= 4) {
- map2.put(p, timer = 0);
- map.put(p, ++charges);
- p.sendMessage(ChatColor.GRAY + "Flash Charges: " + ChatColor.YELLOW + charges);
- } else {
- map2.put(p, ++timer);
- }
- } else if (charges < 5 && p.getItemInHand().getType() == Material.IRON_AXE) {
- if (timer >= 4) {
- map2.put(p, timer = 0);
- map.put(p, ++charges);
- p.sendMessage(ChatColor.GRAY + "Flash Charges: " + ChatColor.YELLOW + charges);
- } else {
- map2.put(p, ++timer);
- }
- }
- }
- }
- }, 20, 20);
- }
- @EventHandler
- public void PlayerInteract(PlayerInteractEvent event) {
- p = event.getPlayer();
- charges = map.get(p);
- if (event.getAction() == Action.RIGHT_CLICK_AIR && p.getItemInHand().getType() == Material.IRON_AXE
- && charges > 0) {
- // Run code here
- first = 1;
- pYaw = p.getLocation().getYaw();
- pPitch = p.getLocation().getPitch();
- for (int distTele = 1; distTele < 11; distTele++) {
- pLocation = p.getLocation().toVector().add(p.getLocation().getDirection().multiply(distTele))
- .toLocation(p.getWorld());
- pLocationCheck = pLocation;
- pLocationCheck.setY(pLocation.getY() + 2);
- blockFound = pLocationCheck.getBlock().getType();
- if (blockFound == Material.AIR && done == 0) {
- doLocation = p.getLocation().toVector().add(p.getLocation().getDirection().multiply(distTele))
- .toLocation(p.getWorld());
- first = 0;
- } else if (blockFound != Material.AIR && first == 1) {
- done = 1;
- doLocation = p.getLocation();
- } else {
- done = 1;
- first = 0;
- }
- }
- doLocation.setYaw(pYaw);
- doLocation.setPitch(pPitch);
- p.teleport(doLocation);
- done = 0;
- p.setVelocity(stopVelocity);
- p.setFallDistance(0);
- //p.playSound(p.getLocation(), Sound.BLOCK_ANVIL_BREAK, 1, 1);
- map.put(p, --charges);
- p.sendMessage(ChatColor.GRAY + "Flash Charges: " + ChatColor.YELLOW + charges);
- } else if (event.getAction() == Action.RIGHT_CLICK_AIR && p.getItemInHand().getType() == Material.DIAMOND_AXE
- && charges > 0) {
- // Run code here
- first = 1;
- pYaw = p.getLocation().getYaw();
- pPitch = p.getLocation().getPitch();
- for (int distTele = 1; distTele < 11; distTele++) {
- pLocation = p.getLocation().toVector().add(p.getLocation().getDirection().multiply(distTele))
- .toLocation(p.getWorld());
- pLocationCheck = pLocation;
- pLocationCheck.setY(pLocation.getY() + 2);
- blockFound = pLocationCheck.getBlock().getType();
- if (blockFound == Material.AIR && done == 0) {
- doLocation = p.getLocation().toVector().add(p.getLocation().getDirection().multiply(distTele))
- .toLocation(p.getWorld());
- first = 0;
- } else if (blockFound != Material.AIR && first == 1) {
- done = 1;
- doLocation = p.getLocation();
- } else {
- done = 1;
- first = 0;
- }
- }
- doLocation.setYaw(pYaw);
- doLocation.setPitch(pPitch);
- p.teleport(doLocation);
- done = 0;
- p.setVelocity(stopVelocity);
- p.setFallDistance(0);
- p.playSound(p.getLocation(), Sound.WITHER_SHOOT, 1, 1);
- map.put(p, --charges);
- p.sendMessage(ChatColor.GRAY + "Flash Charges: " + ChatColor.YELLOW + charges);
- } else if (event.getAction() == Action.RIGHT_CLICK_AIR && p.getItemInHand().getType() == Material.GOLD_AXE
- && charges > 0) {
- // Run code here
- first = 1;
- pYaw = p.getLocation().getYaw();
- pPitch = p.getLocation().getPitch();
- for (int distTele = 1; distTele < 11; distTele++) {
- pLocation = p.getLocation().toVector().add(p.getLocation().getDirection().multiply(distTele))
- .toLocation(p.getWorld());
- pLocationCheck = pLocation;
- pLocationCheck.setY(pLocation.getY() + 2);
- blockFound = pLocationCheck.getBlock().getType();
- if (blockFound == Material.AIR && done == 0) {
- doLocation = p.getLocation().toVector().add(p.getLocation().getDirection().multiply(distTele))
- .toLocation(p.getWorld());
- first = 0;
- } else if (blockFound != Material.AIR && first == 1) {
- done = 1;
- doLocation = p.getLocation();
- } else {
- done = 1;
- first = 0;
- }
- }
- doLocation.setYaw(pYaw);
- doLocation.setPitch(pPitch);
- p.teleport(doLocation);
- done = 0;
- p.setVelocity(stopVelocity);
- p.setFallDistance(0);
- p.playSound(p.getLocation(), Sound.WITHER_SHOOT, 1, 1);
- map.put(p, --charges);
- p.sendMessage(ChatColor.GRAY + "Flash Charges: " + ChatColor.YELLOW + charges);
- }
- if (event.getAction() == Action.RIGHT_CLICK_BLOCK && p.getItemInHand().getType() == Material.IRON_AXE
- && charges > 0) {
- // Run code here
- first = 1;
- pYaw = p.getLocation().getYaw();
- pPitch = p.getLocation().getPitch();
- for (int distTele = 1; distTele < 11; distTele++) {
- pLocation = p.getLocation().toVector().add(p.getLocation().getDirection().multiply(distTele))
- .toLocation(p.getWorld());
- pLocationCheck = pLocation;
- pLocationCheck.setY(pLocation.getY() + 2);
- blockFound = pLocationCheck.getBlock().getType();
- if (blockFound == Material.AIR && done == 0) {
- doLocation = p.getLocation().toVector().add(p.getLocation().getDirection().multiply(distTele))
- .toLocation(p.getWorld());
- first = 0;
- } else if (blockFound != Material.AIR && first == 1) {
- done = 1;
- doLocation = p.getLocation();
- } else {
- done = 1;
- first = 0;
- }
- }
- doLocation.setYaw(pYaw);
- doLocation.setPitch(pPitch);
- p.teleport(doLocation);
- done = 0;
- p.setVelocity(stopVelocity);
- p.setFallDistance(0);
- p.playSound(p.getLocation(), Sound.WITHER_SHOOT, 1, 1);
- map.put(p, --charges);
- p.sendMessage(ChatColor.GRAY + "Flash Charges: " + ChatColor.YELLOW + charges);
- } else if (event.getAction() == Action.RIGHT_CLICK_BLOCK && p.getItemInHand().getType() == Material.DIAMOND_AXE
- && charges > 0) {
- // Run code here
- first = 1;
- pYaw = p.getLocation().getYaw();
- pPitch = p.getLocation().getPitch();
- for (int distTele = 1; distTele < 11; distTele++) {
- pLocation = p.getLocation().toVector().add(p.getLocation().getDirection().multiply(distTele))
- .toLocation(p.getWorld());
- pLocationCheck = pLocation;
- pLocationCheck.setY(pLocation.getY() + 2);
- blockFound = pLocationCheck.getBlock().getType();
- if (blockFound == Material.AIR && done == 0) {
- doLocation = p.getLocation().toVector().add(p.getLocation().getDirection().multiply(distTele))
- .toLocation(p.getWorld());
- first = 0;
- } else if (blockFound != Material.AIR && first == 1) {
- done = 1;
- doLocation = p.getLocation();
- } else {
- done = 1;
- first = 0;
- }
- }
- doLocation.setYaw(pYaw);
- doLocation.setPitch(pPitch);
- p.teleport(doLocation);
- done = 0;
- p.setVelocity(stopVelocity);
- p.setFallDistance(0);
- p.playSound(p.getLocation(), Sound.WITHER_SHOOT, 1, 1);
- map.put(p, --charges);
- p.sendMessage(ChatColor.GRAY + "Flash Charges: " + ChatColor.YELLOW + charges);
- } else if (event.getAction() == Action.RIGHT_CLICK_BLOCK && p.getItemInHand().getType() == Material.GOLD_AXE
- && charges > 0) {
- // Run code here
- first = 1;
- pYaw = p.getLocation().getYaw();
- pPitch = p.getLocation().getPitch();
- for (int distTele = 1; distTele < 11; distTele++) {
- pLocation = p.getLocation().toVector().add(p.getLocation().getDirection().multiply(distTele))
- .toLocation(p.getWorld());
- pLocationCheck = pLocation;
- pLocationCheck.setY(pLocation.getY() + 2);
- blockFound = pLocationCheck.getBlock().getType();
- if (blockFound == Material.AIR && done == 0) {
- doLocation = p.getLocation().toVector().add(p.getLocation().getDirection().multiply(distTele))
- .toLocation(p.getWorld());
- first = 0;
- } else if (blockFound != Material.AIR && first == 1) {
- done = 1;
- doLocation = p.getLocation();
- } else {
- done = 1;
- first = 0;
- }
- }
- doLocation.setYaw(pYaw);
- doLocation.setPitch(pPitch);
- p.teleport(doLocation);
- done = 0;
- p.setVelocity(stopVelocity);
- p.setFallDistance(0);
- p.playSound(p.getLocation(), Sound.WITHER_SHOOT, 1, 1);
- map.put(p, --charges);
- p.sendMessage(ChatColor.GRAY + "Flash Charges: " + ChatColor.YELLOW + charges);
- } else if (event.getAction() == Action.RIGHT_CLICK_AIR && p.getItemInHand().getType() == Material.GOLD_AXE
- && charges == 0) {
- p.sendMessage(ChatColor.GRAY + "You have no " + ChatColor.GREEN + "Flash Charges" + ChatColor.GRAY + ".");
- } else if (event.getAction() == Action.RIGHT_CLICK_AIR && p.getItemInHand().getType() == Material.IRON_AXE
- && charges == 0) {
- p.sendMessage(ChatColor.GRAY + "You have no " + ChatColor.GREEN + "Flash Charges" + ChatColor.GRAY + ".");
- } else if (event.getAction() == Action.RIGHT_CLICK_AIR && p.getItemInHand().getType() == Material.DIAMOND_AXE
- && charges == 0) {
- p.sendMessage(ChatColor.GRAY + "You have no " + ChatColor.GREEN + "Flash Charges" + ChatColor.GRAY + ".");
- } else if (event.getAction() == Action.RIGHT_CLICK_BLOCK && p.getItemInHand().getType() == Material.GOLD_AXE
- && charges == 0) {
- p.sendMessage(ChatColor.GRAY + "You have no " + ChatColor.GREEN + "Flash Charges" + ChatColor.GRAY + ".");
- } else if (event.getAction() == Action.RIGHT_CLICK_BLOCK && p.getItemInHand().getType() == Material.IRON_AXE
- && charges == 0) {
- p.sendMessage(ChatColor.GRAY + "You have no " + ChatColor.GREEN + "Flash Charges" + ChatColor.GRAY + ".");
- } else if (event.getAction() == Action.RIGHT_CLICK_BLOCK && p.getItemInHand().getType() == Material.DIAMOND_AXE
- && charges == 0) {
- p.sendMessage(ChatColor.GRAY + "You have no " + ChatColor.GREEN + "Flash Charges" + ChatColor.GRAY + ".");
- }
- }
- @EventHandler
- public void PlayerJoin(PlayerJoinEvent event) {
- p = event.getPlayer();
- charges = 0;
- timer = 0;
- map.put(p, charges);
- map2.put(p, timer);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement