@Override public boolean effect(Event event, Player player) { int slot = player.getInventory().getHeldItemSlot(); ItemStack potion = player.getInventory().getItem(slot + 1); Location loc = player.getLocation(); if (potion != null && potion.getType().toString().contains("POTION")) { ThrownPotion tp = player.launchProjectile(ThrownPotion.class); EffectManager.playSound(loc, "ENTITY_GENERIC_EXPLODE", 0.5f, 2f); try { tp.setItem(potion); } catch (IllegalArgumentException ex) { ItemStack pt = potion.clone(); if (potion.getType().equals(Material.POTION) || potion.getType().equals(Material.LINGERING_POTION)) pt.setType(Material.SPLASH_POTION); tp.setItem(pt); } tp.setBounce(false); tp.setVelocity(loc.getDirection().multiply(ProjectileSpeedMultiplier)); if (!player.getGameMode().equals(GameMode.CREATIVE)) { potion.setAmount(potion.getAmount() - 1); player.getInventory().setItem(slot + 1, potion); player.updateInventory(); } return true; } else { player.sendMessage( ChatColor.RED + "You need a Potion in the slot to the right of the Potion Launcher!"); player.getWorld().playEffect(loc, Effect.CLICK1, 5); } return false; }
private static void block(Player player) { for (int id : instances.keySet()) { EarthBlast blast = instances.get(id); if (blast.player.equals(player)) { continue; } if (!blast.location.getWorld().equals(player.getWorld())) { continue; } if (!blast.progressing) { continue; } if (GeneralMethods.isRegionProtectedFromBuild(player, "EarthBlast", blast.location)) { continue; } Location location = player.getEyeLocation(); Vector vector = location.getDirection(); Location mloc = blast.location; if (mloc.distance(location) <= RANGE && GeneralMethods.getDistanceFromLine(vector, location, blast.location) < deflectrange && mloc.distance(location.clone().add(vector)) < mloc.distance(location.clone().add(vector.clone().multiply(-1)))) { blast.breakBlock(); } } }
private static void redirectTargettedBlasts(Player player, ArrayList<EarthBlast> ignore) { for (int id : instances.keySet()) { EarthBlast blast = instances.get(id); if (!blast.progressing || ignore.contains(blast)) { continue; } if (!blast.location.getWorld().equals(player.getWorld())) { continue; } if (GeneralMethods.isRegionProtectedFromBuild(player, "EarthBlast", blast.location)) { continue; } if (blast.player.equals(player)) { blast.redirect(player, getTargetLocation(player)); } Location location = player.getEyeLocation(); Vector vector = location.getDirection(); Location mloc = blast.location; if (mloc.distance(location) <= RANGE && GeneralMethods.getDistanceFromLine(vector, location, blast.location) < deflectrange && mloc.distance(location.clone().add(vector)) < mloc.distance(location.clone().add(vector.clone().multiply(-1)))) { blast.redirect(player, getTargetLocation(player)); } } }
private void tossItem(ItemStack dropItem) { Location loc = player.getLocation(); loc.setY(loc.getY() + 1); Item item = loc.getWorld().dropItem(loc, dropItem); Vector v = loc.getDirection().multiply(0.2); v.setY(0.2); item.setVelocity(v); }
public static Vector calculateVector(Location loc) { Vector vec = loc.getDirection(); int mult = 3; vec.setX(vec.getX() * mult); vec.setY(vec.getY() * mult); vec.setZ(vec.getZ() * mult); return vec; }
public boolean advance() { Vector dir = loc.getDirection(); dir.add(new Vector(0.0f, -0.008, 0.0f)); // Apply 'gravity' loc.setDirection(dir); loc.add(dir.multiply(speed)); loc.getWorld().createExplosion(loc, 0.0f, false); if (ItemManager.getId(loc.getBlock()) != CivData.AIR) { return true; } if (loc.distance(startLoc) > maxRange) { return true; } return false; }
/** * Check if a player looks at a target of a specific size, with a specific precision value * (roughly). * * @param player the player * @param targetX the target x * @param targetY the target y * @param targetZ the target z * @param targetWidth the target width * @param targetHeight the target height * @param precision the precision * @return the double */ public static double directionCheck( final Player player, final double targetX, final double targetY, final double targetZ, final double targetWidth, final double targetHeight, final double precision) { // Get the eye location of the player. final Location eyes = player.getEyeLocation(); final double factor = Math.sqrt( Math.pow(eyes.getX() - targetX, 2) + Math.pow(eyes.getY() - targetY, 2) + Math.pow(eyes.getZ() - targetZ, 2)); // Get the view direction of the player. final Vector direction = eyes.getDirection(); final double x = targetX - eyes.getX(); final double y = targetY - eyes.getY(); final double z = targetZ - eyes.getZ(); final double xPrediction = factor * direction.getX(); final double yPrediction = factor * direction.getY(); final double zPrediction = factor * direction.getZ(); double off = 0.0D; off += Math.max(Math.abs(x - xPrediction) - (targetWidth / 2 + precision), 0.0D); off += Math.max(Math.abs(z - zPrediction) - (targetWidth / 2 + precision), 0.0D); off += Math.max(Math.abs(y - yPrediction) - (targetHeight / 2 + precision), 0.0D); if (off > 1) off = Math.sqrt(off); return off; }
private static void block(Player player) { for (int id : instances.keySet()) { IceBlast ice = instances.get(id); if (ice.player.equals(player)) continue; if (!ice.location.getWorld().equals(player.getWorld())) continue; if (!ice.progressing) continue; if (GeneralMethods.isRegionProtectedFromBuild(player, "IceBlast", ice.location)) continue; Location location = player.getEyeLocation(); Vector vector = location.getDirection(); Location mloc = ice.location; if (mloc.distance(location) <= defaultrange && GeneralMethods.getDistanceFromLine(vector, location, ice.location) < deflectrange && mloc.distance(location.clone().add(vector)) < mloc.distance(location.clone().add(vector.clone().multiply(-1)))) { ice.cancel(); } } }
@EventHandler(priority = EventPriority.HIGH) public void onPlayerInteract(PlayerInteractEvent event) { final Player player = event.getPlayer(); final TFM_PlayerData playerdata = TFM_PlayerData.getPlayerData(player); switch (event.getAction()) { case RIGHT_CLICK_AIR: case RIGHT_CLICK_BLOCK: { switch (event.getMaterial()) { case WATER_BUCKET: { if (TFM_AdminList.isSuperAdmin(player) || TFM_ConfigEntry.ALLOW_WATER_PLACE.getBoolean()) { break; } player .getInventory() .setItem( player.getInventory().getHeldItemSlot(), new ItemStack(Material.COOKIE, 1)); player.sendMessage(ChatColor.GRAY + "Water buckets are currently disabled."); event.setCancelled(true); break; } case LAVA_BUCKET: { if (TFM_AdminList.isSuperAdmin(player) || TFM_ConfigEntry.ALLOW_LAVA_PLACE.getBoolean()) { break; } player .getInventory() .setItem( player.getInventory().getHeldItemSlot(), new ItemStack(Material.COOKIE, 1)); player.sendMessage(ChatColor.GRAY + "Lava buckets are currently disabled."); event.setCancelled(true); break; } case EXPLOSIVE_MINECART: { if (TFM_ConfigEntry.ALLOW_TNT_MINECARTS.getBoolean()) { break; } player.getInventory().clear(player.getInventory().getHeldItemSlot()); player.sendMessage(ChatColor.GRAY + "TNT minecarts are currently disabled."); event.setCancelled(true); break; } } break; } case LEFT_CLICK_AIR: case LEFT_CLICK_BLOCK: { switch (event.getMaterial()) { case STICK: { if (!TFM_AdminList.isSuperAdmin(player)) { break; } event.setCancelled(true); final Location location = TFM_DepreciationAggregator.getTargetBlock(player, null, 5).getLocation(); final List<RollbackEntry> entries = TFM_RollbackManager.getEntriesAtLocation(location); if (entries.isEmpty()) { TFM_Util.playerMsg(player, "No block edits at that location."); break; } TFM_Util.playerMsg( player, "Block edits at (" + ChatColor.WHITE + "x" + location.getBlockX() + ", y" + location.getBlockY() + ", z" + location.getBlockZ() + ChatColor.BLUE + ")" + ChatColor.WHITE + ":", ChatColor.BLUE); for (RollbackEntry entry : entries) { TFM_Util.playerMsg( player, " - " + ChatColor.BLUE + entry.author + " " + entry.getType() + " " + StringUtils.capitalize(entry.getMaterial().toString().toLowerCase()) + (entry.data == 0 ? "" : ":" + entry.data)); } break; } case BONE: { if (!playerdata.mobThrowerEnabled()) { break; } Location player_pos = player.getLocation(); Vector direction = player_pos.getDirection().normalize(); LivingEntity rezzed_mob = (LivingEntity) player .getWorld() .spawnEntity( player_pos.add(direction.multiply(2.0)), playerdata.mobThrowerCreature()); rezzed_mob.setVelocity(direction.multiply(playerdata.mobThrowerSpeed())); playerdata.enqueueMob(rezzed_mob); event.setCancelled(true); break; } case SULPHUR: { if (!playerdata.isMP44Armed()) { break; } event.setCancelled(true); if (playerdata.toggleMP44Firing()) { playerdata.startArrowShooter(TotalFreedomMod.plugin); } else { playerdata.stopArrowShooter(); } break; } case BLAZE_ROD: { if (!TFM_ConfigEntry.ALLOW_EXPLOSIONS.getBoolean()) { break; } if (!TFM_AdminList.isSeniorAdmin(player, true)) { break; } event.setCancelled(true); Block targetBlock; if (event.getAction().equals(Action.LEFT_CLICK_AIR)) { targetBlock = TFM_DepreciationAggregator.getTargetBlock(player, null, 120); } else { targetBlock = event.getClickedBlock(); } if (targetBlock == null) { player.sendMessage("Can't resolve target block."); break; } player.getWorld().createExplosion(targetBlock.getLocation(), 4F, true); player.getWorld().strikeLightning(targetBlock.getLocation()); break; } case CARROT: { if (!TFM_ConfigEntry.ALLOW_EXPLOSIONS.getBoolean()) { break; } if (!TFM_AdminList.isSeniorAdmin(player, true)) { break; } Location location = player.getLocation().clone(); Vector playerPostion = location.toVector().add(new Vector(0.0, 1.65, 0.0)); Vector playerDirection = location.getDirection().normalize(); double distance = 150.0; Block targetBlock = TFM_DepreciationAggregator.getTargetBlock( player, null, Math.round((float) distance)); if (targetBlock != null) { distance = location.distance(targetBlock.getLocation()); } final List<Block> affected = new ArrayList<Block>(); Block lastBlock = null; for (double offset = 0.0; offset <= distance; offset += (distance / 25.0)) { Block block = playerPostion .clone() .add(playerDirection.clone().multiply(offset)) .toLocation(player.getWorld()) .getBlock(); if (!block.equals(lastBlock)) { if (block.isEmpty()) { affected.add(block); block.setType(Material.TNT); } else { break; } } lastBlock = block; } new BukkitRunnable() { @Override public void run() { for (Block tntBlock : affected) { TNTPrimed tnt = tntBlock.getWorld().spawn(tntBlock.getLocation(), TNTPrimed.class); tnt.setFuseTicks(5); tntBlock.setType(Material.AIR); } } }.runTaskLater(TotalFreedomMod.plugin, 30L); event.setCancelled(true); break; } case RAW_FISH: { final int RADIUS_HIT = 5; final int STRENGTH = 4; // Clownfish if (TFM_DepreciationAggregator.getData_MaterialData(event.getItem().getData()) == 2) { if (TFM_AdminList.isSeniorAdmin(player, true) || TFM_AdminList.isTelnetAdmin(player, true)) { boolean didHit = false; final Location playerLoc = player.getLocation(); final Vector playerLocVec = playerLoc.toVector(); final List<Player> players = player.getWorld().getPlayers(); for (final Player target : players) { if (target == player) { continue; } final Location targetPos = target.getLocation(); final Vector targetPosVec = targetPos.toVector(); try { if (targetPosVec.distanceSquared(playerLocVec) < (RADIUS_HIT * RADIUS_HIT)) { TFM_Util.setFlying(player, false); target.setVelocity( targetPosVec.subtract(playerLocVec).normalize().multiply(STRENGTH)); didHit = true; } } catch (IllegalArgumentException ex) { } } if (didHit) { final Sound[] sounds = Sound.values(); for (Sound sound : sounds) { if (sound.toString().contains("HIT")) { playerLoc .getWorld() .playSound( randomOffset(playerLoc, 5.0), sound, 100.0f, randomDoubleRange(0.5, 2.0).floatValue()); } } } } else { final StringBuilder msg = new StringBuilder(); final char[] chars = (player.getName() + " is a clown.").toCharArray(); for (char c : chars) { msg.append(TFM_Util.randomChatColor()).append(c); } TFM_Util.bcastMsg(msg.toString()); player.getInventory().getItemInHand().setType(Material.POTATO_ITEM); } event.setCancelled(true); break; } } } break; } } }
/* * Return: True if they have an ability matching the held item. False if * they do not have any abilities matching held item */ public boolean useAbility(Player sender, Block b) { // check if they're holding anything if (sender.getItemInHand() == null) { return false; } ItemStack i = sender.getItemInHand(); // sees if they are fightclassed FightClass f = FightClass.get(sender); // goes through each ability, seeeing if any of the MID's match the // lore of the item for (Ability a : f.getAbilities()) { if (i.getItemMeta().hasLore() && i.getItemMeta().getLore().get(0).equalsIgnoreCase(a.getMID())) { // check if cost is able to be paid, and pay it if (a.useCost(sender)) { // check to see if there is a target Player target = null; boolean s = true; Location l = sender.getLocation(); /* * loop through nearby entites to positions x blocks in the * direction the player is looking, starting at 0 and ending * at a.getRange() */ for (int x = 2; x < a.getRange() && (s); x++) { Location lt = l; Collection<Entity> et = lt.getWorld().getNearbyEntities(lt.add(lt.getDirection().multiply(x)), 2, 2, 2); if (!et.isEmpty()) { for (Entity entity : et) { if (entity instanceof Player) { if (!(((Player) entity).equals(sender))) { target = (Player) entity; s = false; } } } } } // see if target got set to anything if (target != null) { a.effect(sender, target); } else { if (a instanceof BlockTargettingAbility) { if (b != null && !b.getType().equals(Material.AIR)) { ((BlockTargettingAbility) a).effect(sender, b); } else { // nothing, needs a block for target it // BlockTargettingAbility } } a.effect(sender); } } else { // nothing } return true; } } return false; }
@EventHandler(priority = EventPriority.HIGH) public void onPlayerInteract(PlayerInteractEvent event) { Player player = event.getPlayer(); switch (event.getAction()) { case RIGHT_CLICK_AIR: case RIGHT_CLICK_BLOCK: { switch (event.getMaterial()) { case WATER_BUCKET: { if (!TotalFreedomMod.allowWaterPlace) { player .getInventory() .setItem( player.getInventory().getHeldItemSlot(), new ItemStack(Material.COOKIE, 1)); player.sendMessage(ChatColor.GRAY + "Water buckets are currently disabled."); event.setCancelled(true); } break; } case LAVA_BUCKET: { if (!TotalFreedomMod.allowLavaPlace) { player .getInventory() .setItem( player.getInventory().getHeldItemSlot(), new ItemStack(Material.COOKIE, 1)); player.sendMessage(ChatColor.GRAY + "Lava buckets are currently disabled."); event.setCancelled(true); } break; } case EXPLOSIVE_MINECART: { if (!TotalFreedomMod.allowTntMinecarts) { player.getInventory().clear(player.getInventory().getHeldItemSlot()); player.sendMessage(ChatColor.GRAY + "TNT minecarts are currently disabled."); event.setCancelled(true); } break; } } break; } case LEFT_CLICK_AIR: case LEFT_CLICK_BLOCK: { switch (event.getMaterial()) { case STICK: { TFM_PlayerData playerdata = TFM_PlayerData.getPlayerData(player); if (playerdata.mobThrowerEnabled()) { Location player_pos = player.getLocation(); Vector direction = player_pos.getDirection().normalize(); LivingEntity rezzed_mob = (LivingEntity) player .getWorld() .spawnEntity( player_pos.add(direction.multiply(2.0)), playerdata.mobThrowerCreature()); rezzed_mob.setVelocity(direction.multiply(playerdata.mobThrowerSpeed())); playerdata.enqueueMob(rezzed_mob); event.setCancelled(true); } break; } case SULPHUR: { TFM_PlayerData playerdata = TFM_PlayerData.getPlayerData(player); if (playerdata.isMP44Armed()) { if (playerdata.toggleMP44Firing()) { playerdata.startArrowShooter(TotalFreedomMod.plugin); } else { playerdata.stopArrowShooter(); } event.setCancelled(true); } break; } case BLAZE_ROD: { if (TotalFreedomMod.allowExplosions) { if (TFM_SuperadminList.isSeniorAdmin(player, true)) { Block target_block; if (event.getAction().equals(Action.LEFT_CLICK_AIR)) { target_block = player.getTargetBlock(null, 120); } else { target_block = event.getClickedBlock(); } if (target_block != null) { player.getWorld().createExplosion(target_block.getLocation(), 4F, true); player.getWorld().strikeLightning(target_block.getLocation()); } else { player.sendMessage("Can't resolve target block."); } event.setCancelled(true); } } break; } case CARROT: { if (TotalFreedomMod.allowExplosions) { if (TFM_SuperadminList.isSeniorAdmin(player, true)) { Location player_location = player.getLocation().clone(); Vector player_pos = player_location.toVector().add(new Vector(0.0, 1.65, 0.0)); Vector player_dir = player_location.getDirection().normalize(); double distance = 150.0; Block target_block = player.getTargetBlock(null, Math.round((float) distance)); if (target_block != null) { distance = player_location.distance(target_block.getLocation()); } final List<Block> affected = new ArrayList<Block>(); Block last_block = null; for (double offset = 0.0; offset <= distance; offset += (distance / 25.0)) { Block test_block = player_pos .clone() .add(player_dir.clone().multiply(offset)) .toLocation(player.getWorld()) .getBlock(); if (!test_block.equals(last_block)) { if (test_block.isEmpty()) { affected.add(test_block); test_block.setType(Material.TNT); } else { break; } } last_block = test_block; } new BukkitRunnable() { @Override public void run() { for (Block tnt_block : affected) { TNTPrimed tnt_primed = tnt_block.getWorld().spawn(tnt_block.getLocation(), TNTPrimed.class); tnt_primed.setFuseTicks(5); tnt_block.setType(Material.AIR); } } }.runTaskLater(TotalFreedomMod.plugin, 30L); event.setCancelled(true); } } break; } } break; } } }
@EventHandler(priority = EventPriority.HIGH) public void onPlayerInteract(PlayerInteractEvent event) { final Player player = event.getPlayer(); final TFM_PlayerData playerdata = TFM_PlayerData.getPlayerData(player); switch (event.getAction()) { case RIGHT_CLICK_AIR: case RIGHT_CLICK_BLOCK: { switch (event.getMaterial()) { case WATER_BUCKET: { if (TFM_ConfigEntry.ALLOW_WATER_PLACE.getBoolean()) { break; } player .getInventory() .setItem( player.getInventory().getHeldItemSlot(), new ItemStack(Material.COOKIE, 1)); player.sendMessage(ChatColor.GRAY + "Water buckets are currently disabled."); event.setCancelled(true); break; } case LAVA_BUCKET: { if (TFM_ConfigEntry.ALLOW_LAVA_PLACE.getBoolean()) { break; } player .getInventory() .setItem( player.getInventory().getHeldItemSlot(), new ItemStack(Material.COOKIE, 1)); player.sendMessage(ChatColor.GRAY + "Lava buckets are currently disabled."); event.setCancelled(true); break; } case EXPLOSIVE_MINECART: { if (TFM_ConfigEntry.ALLOW_TNT_MINECARTS.getBoolean()) { break; } player.getInventory().clear(player.getInventory().getHeldItemSlot()); player.sendMessage(ChatColor.GRAY + "TNT minecarts are currently disabled."); event.setCancelled(true); break; } } break; } case LEFT_CLICK_AIR: case LEFT_CLICK_BLOCK: { switch (event.getMaterial()) { case STICK: { if (!TFM_AdminList.isSuperAdmin(player)) { break; } event.setCancelled(true); final Location location = player.getTargetBlock(null, 5).getLocation(); final List<RollbackEntry> entries = TFM_RollbackManager.getEntriesAtLocation(location); if (entries.isEmpty()) { TFM_Util.playerMsg(player, "No block edits at that location."); break; } TFM_Util.playerMsg( player, "Block edits at (" + ChatColor.WHITE + "x" + location.getBlockX() + ", y" + location.getBlockY() + ", z" + location.getBlockZ() + ChatColor.BLUE + ")" + ChatColor.WHITE + ":", ChatColor.BLUE); for (RollbackEntry entry : entries) { TFM_Util.playerMsg( player, " - " + ChatColor.BLUE + entry.author + " " + entry.getType() + " " + StringUtils.capitalize(entry.getMaterial().toString().toLowerCase()) + (entry.data == 0 ? "" : ":" + entry.data)); } break; } case BONE: { if (!playerdata.mobThrowerEnabled()) { break; } Location player_pos = player.getLocation(); Vector direction = player_pos.getDirection().normalize(); LivingEntity rezzed_mob = (LivingEntity) player .getWorld() .spawnEntity( player_pos.add(direction.multiply(2.0)), playerdata.mobThrowerCreature()); rezzed_mob.setVelocity(direction.multiply(playerdata.mobThrowerSpeed())); playerdata.enqueueMob(rezzed_mob); event.setCancelled(true); break; } case SULPHUR: { if (!playerdata.isMP44Armed()) { break; } event.setCancelled(true); if (playerdata.toggleMP44Firing()) { playerdata.startArrowShooter(TotalFreedomMod.plugin); } else { playerdata.stopArrowShooter(); } break; } case BLAZE_ROD: { if (!TFM_ConfigEntry.ALLOW_EXPLOSIONS.getBoolean()) { break; } if (!TFM_AdminList.isSeniorAdmin(player, true)) { break; } event.setCancelled(true); Block targetBlock; if (event.getAction().equals(Action.LEFT_CLICK_AIR)) { targetBlock = player.getTargetBlock(null, 120); } else { targetBlock = event.getClickedBlock(); } if (targetBlock == null) { player.sendMessage("Can't resolve target block."); break; } player.getWorld().createExplosion(targetBlock.getLocation(), 4F, true); player.getWorld().strikeLightning(targetBlock.getLocation()); break; } case CARROT: { if (!TFM_ConfigEntry.ALLOW_EXPLOSIONS.getBoolean()) { break; } if (!TFM_AdminList.isSeniorAdmin(player, true)) { break; } Location location = player.getLocation().clone(); Vector playerPostion = location.toVector().add(new Vector(0.0, 1.65, 0.0)); Vector playerDirection = location.getDirection().normalize(); double distance = 150.0; Block targetBlock = player.getTargetBlock(null, Math.round((float) distance)); if (targetBlock != null) { distance = location.distance(targetBlock.getLocation()); } final List<Block> affected = new ArrayList<Block>(); Block lastBlock = null; for (double offset = 0.0; offset <= distance; offset += (distance / 25.0)) { Block block = playerPostion .clone() .add(playerDirection.clone().multiply(offset)) .toLocation(player.getWorld()) .getBlock(); if (!block.equals(lastBlock)) { if (block.isEmpty()) { affected.add(block); block.setType(Material.TNT); } else { break; } } lastBlock = block; } new BukkitRunnable() { @Override public void run() { for (Block tntBlock : affected) { TNTPrimed tnt = tntBlock.getWorld().spawn(tntBlock.getLocation(), TNTPrimed.class); tnt.setFuseTicks(5); tntBlock.setType(Material.AIR); } } }.runTaskLater(TotalFreedomMod.plugin, 30L); event.setCancelled(true); break; } } break; } } }
@SuppressWarnings("deprecation") @EventHandler public void onInventoryClick(InventoryClickEvent event) { // controller.getLogger().info("CLICK: " + event.getAction() + ", " + event.getClick() + " on " // + event.getSlotType() + " in "+ event.getInventory().getType() + " slots: " + event.getSlot() // + ":" + event.getRawSlot()); if (event.isCancelled()) return; if (!(event.getWhoClicked() instanceof Player)) return; Player player = (Player) event.getWhoClicked(); Mage apiMage = controller.getMage(player); if (!(apiMage instanceof com.elmakers.mine.bukkit.magic.Mage)) return; final com.elmakers.mine.bukkit.magic.Mage mage = (com.elmakers.mine.bukkit.magic.Mage) apiMage; GUIAction gui = mage.getActiveGUI(); if (gui != null) { gui.clicked(event); return; } // Check for temporary items and skill items InventoryAction action = event.getAction(); InventoryType inventoryType = event.getInventory().getType(); ItemStack clickedItem = event.getCurrentItem(); boolean isDrop = event.getClick() == ClickType.DROP || event.getClick() == ClickType.CONTROL_DROP; boolean isSkill = clickedItem != null && Wand.isSkill(clickedItem); // Preventing putting skills in containers if (isSkill && inventoryType != InventoryType.CRAFTING) { if (!isDrop) { event.setCancelled(true); } return; } // Check for right-click-to-use if (isSkill && action == InventoryAction.PICKUP_HALF) { Spell spell = mage.getSpell(Wand.getSpell(clickedItem)); if (spell != null) { spell.cast(); } player.closeInventory(); event.setCancelled(true); return; } if (clickedItem != null && NMSUtils.isTemporary(clickedItem)) { String message = NMSUtils.getTemporaryMessage(clickedItem); if (message != null && message.length() > 1) { mage.sendMessage(message); } ItemStack replacement = NMSUtils.getReplacement(clickedItem); event.setCurrentItem(replacement); event.setCancelled(true); return; } // Check for wearing spells ItemStack heldItem = event.getCursor(); if (heldItem != null && event.getSlotType() == InventoryType.SlotType.ARMOR) { if (Wand.isSpell(heldItem)) { event.setCancelled(true); return; } if (Wand.isWand(clickedItem) || Wand.isWand(heldItem)) { controller.onArmorUpdated(mage); } } boolean isHotbar = event.getAction() == InventoryAction.HOTBAR_SWAP || event.getAction() == InventoryAction.HOTBAR_MOVE_AND_READD; if (isHotbar && event.getSlotType() == InventoryType.SlotType.ARMOR) { int slot = event.getHotbarButton(); ItemStack item = mage.getPlayer().getInventory().getItem(slot); if (item != null && Wand.isSpell(item)) { event.setCancelled(true); return; } controller.onArmorUpdated(mage); } Wand activeWand = mage.getActiveWand(); boolean isChest = inventoryType == InventoryType.CHEST || inventoryType == InventoryType.HOPPER || inventoryType == InventoryType.DISPENSER || inventoryType == InventoryType.DROPPER; boolean clickedWand = Wand.isWand(clickedItem); boolean isContainerSlot = event.getSlot() == event.getRawSlot(); if (activeWand != null && activeWand.isInventoryOpen()) { // Kind of a hack to avoid hotbar items with 0 amounts disappearing :( Inventory inventory = player.getInventory(); for (int i = 0; i < 8; i++) { ItemStack item = inventory.getItem(i); if (item != null && item.getAmount() == 0) { item.setAmount(1); } } // Don't allow the offhand slot to be messed with while the spell inventory is open if (event.getRawSlot() == 45) { event.setCancelled(true); return; } if (Wand.isSpell(clickedItem) && clickedItem.getAmount() != 1) { clickedItem.setAmount(1); } if (clickedWand) { event.setCancelled(true); if (dropChangesPages) { activeWand.cycleInventory(); } else { activeWand.cycleHotbar(1); } return; } // So many ways to try and move the wand around, that we have to watch for! if (isHotbar && Wand.isWand(player.getInventory().getItem(event.getHotbarButton()))) { event.setCancelled(true); return; } // Can't wear spells if (event.getAction() == InventoryAction.MOVE_TO_OTHER_INVENTORY && clickedItem != null) { if (controller.isWearable(clickedItem)) { event.setCancelled(true); return; } } // Safety check for something that ought not to be possible // but perhaps happens with lag? if (Wand.isWand(event.getCursor())) { activeWand.closeInventory(); event.setCursor(null); event.setCancelled(true); return; } } else if (activeWand != null) { // Check for changes that could have been made to the active wand Integer activeSlot = player.getInventory().getHeldItemSlot(); if (activeSlot != null && (event.getSlot() == activeSlot || (event.getAction() == InventoryAction.HOTBAR_SWAP && event.getHotbarButton() == activeSlot))) { mage.checkWand(); activeWand = mage.getActiveWand(); } } else if (clickedWand && Wand.Undroppable && !player.hasPermission("Magic.wand.override_drop") && isChest && !isContainerSlot) { Wand wand = new Wand(controller, clickedItem); if (wand.isUndroppable()) { event.setCancelled(true); return; } } // Check for armor changing if (event.getAction() == InventoryAction.MOVE_TO_OTHER_INVENTORY && clickedItem != null) { if (controller.isWearable(clickedItem)) { controller.onArmorUpdated(mage); } } // Check for dropping items out of a wand's inventory // or dropping undroppable wands if (isDrop) { if (clickedWand) { Wand wand = new Wand(controller, clickedItem); if (wand.isUndroppable()) { event.setCancelled(true); if (activeWand != null) { if (activeWand.getHotbarCount() > 1) { activeWand.cycleHotbar(1); } else { activeWand.closeInventory(); } } return; } } if (activeWand != null && activeWand.isInventoryOpen()) { ItemStack droppedItem = clickedItem; if (!Wand.isSpell(droppedItem)) { mage.giveItem(droppedItem); event.setCurrentItem(null); event.setCancelled(true); return; } // This is a hack to deal with spells on cooldown disappearing, // Since the event handler doesn't match the zero-count itemstacks Integer slot = event.getSlot(); int heldSlot = player.getInventory().getHeldItemSlot(); Inventory hotbar = activeWand.getHotbar(); if (hotbar != null && slot >= 0 && slot <= hotbar.getSize() && slot != heldSlot && activeWand.getMode() == WandMode.INVENTORY) { if (slot > heldSlot) slot--; if (slot < hotbar.getSize()) { droppedItem = hotbar.getItem(slot); } else { slot = null; } } else { slot = null; } if (!controller.isSpellDroppingEnabled()) { player.closeInventory(); String spellName = Wand.getSpell(droppedItem); if (spellName != null && !activeWand.isManualQuickCastDisabled()) { Spell spell = mage.getSpell(spellName); if (spell != null) { activeWand.cast(spell); // Just in case a spell has levelled up... jeez! if (hotbar != null && slot != null) { droppedItem = hotbar.getItem(slot); } } } event.setCancelled(true); // This is needed to avoid spells on cooldown disappearing from the hotbar if (hotbar != null && slot != null && mage.getActiveGUI() == null) { player.getInventory().setItem(event.getSlot(), droppedItem); player.updateInventory(); } return; } ItemStack newDrop = controller.removeItemFromWand(activeWand, droppedItem); if (newDrop != null) { Location location = player.getLocation(); Item item = location.getWorld().dropItem(location, newDrop); item.setVelocity(location.getDirection().normalize()); } else { event.setCancelled(true); } } return; } // Check for wand cycling with active inventory if (activeWand != null) { WandMode wandMode = activeWand.getMode(); if ((wandMode == WandMode.INVENTORY && inventoryType == InventoryType.CRAFTING) || (wandMode == WandMode.CHEST && inventoryType == InventoryType.CHEST)) { if (activeWand.isInventoryOpen()) { if (event.getAction() == InventoryAction.NOTHING) { int direction = event.getClick() == ClickType.LEFT ? 1 : -1; activeWand.cycleInventory(direction); event.setCancelled(true); return; } if (event.getSlotType() == InventoryType.SlotType.ARMOR) { event.setCancelled(true); return; } // Chest mode falls back to selection from here. if (event.getAction() == InventoryAction.PICKUP_HALF || wandMode == WandMode.CHEST) { controller.onPlayerActivateIcon(mage, activeWand, clickedItem); player.closeInventory(); event.setCancelled(true); } } } } }
@Override public SpellResult perform(CastContext context) { Entity sourceEntity = context.getEntity(); Location sourceLocation = context.getEyeLocation().clone(); Entity targetEntity = context.getTargetEntity(); Location targetLocation = context.getTargetLocation(); if (targetLocation != null) { targetLocation = targetLocation.clone(); } Vector direction = context.getDirection().normalize(); if (sourceLocation == null) { return SpellResult.LOCATION_REQUIRED; } if (targetSelf) { targetEntity = sourceEntity; targetLocation = sourceLocation; } else if (targetEntityLocation && targetEntity != null) { targetLocation = targetEntity.getLocation(); } if (attachBlock) { Block previousBlock = context.getPreviousBlock(); if (previousBlock != null) { Location current = targetLocation; targetLocation = previousBlock.getLocation(); context.getBrush().setTarget(current, targetLocation); } } if (sourceOffset != null) { sourceLocation = sourceLocation.add(sourceOffset); } if (targetOffset != null && targetLocation != null) { targetLocation = targetLocation.add(targetOffset); } if (randomSourceOffset != null) { sourceLocation = RandomUtils.randomizeLocation(sourceLocation, randomSourceOffset); } if (randomTargetOffset != null && targetLocation != null) { targetLocation = RandomUtils.randomizeLocation(targetLocation, randomTargetOffset); } if (targetDirection != null && targetLocation != null) { targetLocation.setDirection(targetDirection); } if (sourceDirection != null) { sourceLocation.setDirection(sourceDirection); direction = sourceDirection.clone(); } if (targetDirectionOffset != null && targetLocation != null) { targetLocation.setDirection(targetLocation.getDirection().add(targetDirectionOffset)); } if (sourceDirectionOffset != null) { sourceLocation.setDirection(direction.add(sourceDirectionOffset)); } if (sourceDirectionSpeed != null) { sourceLocation = sourceLocation.add(direction.clone().multiply(sourceDirectionSpeed)); } if (targetDirectionSpeed != null && targetLocation != null) { targetLocation = targetLocation.add(direction.clone().multiply(targetDirectionSpeed)); } if (sourceAtTarget && targetLocation != null) { sourceLocation.setX(targetLocation.getX()); sourceLocation.setY(targetLocation.getY()); sourceLocation.setZ(targetLocation.getZ()); sourceLocation.setWorld(targetLocation.getWorld()); } if (persistTarget) { context.setTargetLocation(targetLocation); } CastContext newContext = createContext(context, sourceEntity, sourceLocation, targetEntity, targetLocation); return super.perform(newContext); }
private boolean progress() { if (player.isDead() || !player.isOnline() || !GeneralMethods.canBend(player.getName(), "EarthBlast")) { breakBlock(); return false; } if (System.currentTimeMillis() - time >= interval) { time = System.currentTimeMillis(); if (falling) { breakBlock(); return false; } if (!EarthMethods.isEarthbendable(player, sourceblock) && sourceblock.getType() != Material.COBBLESTONE) { instances.remove(id); return false; } if (!progressing && !falling) { if (GeneralMethods.getBoundAbility(player) == null) { unfocusBlock(); return false; } if (!GeneralMethods.getBoundAbility(player).equalsIgnoreCase("EarthBlast")) { unfocusBlock(); return false; } if (sourceblock == null) { instances.remove(id); return false; } if (!player.getWorld().equals(sourceblock.getWorld())) { unfocusBlock(); return false; } if (sourceblock.getLocation().distance(player.getLocation()) > preparerange) { unfocusBlock(); return false; } } if (falling) { breakBlock(); } else { if (!progressing) { return false; } if (sourceblock.getY() == firstdestination.getBlockY()) { settingup = false; } Vector direction; if (settingup) { direction = GeneralMethods.getDirection(location, firstdestination).normalize(); } else { direction = GeneralMethods.getDirection(location, destination).normalize(); } location = location.clone().add(direction); WaterMethods.removeWaterSpouts(location, player); AirMethods.removeAirSpouts(location, player); Block block = location.getBlock(); if (block.getLocation().equals(sourceblock.getLocation())) { location = location.clone().add(direction); block = location.getBlock(); } if (EarthMethods.isTransparentToEarthbending(player, block) && !block.isLiquid()) { GeneralMethods.breakBlock(block); } else if (!settingup) { breakBlock(); return false; } else { location = location.clone().subtract(direction); direction = GeneralMethods.getDirection(location, destination).normalize(); location = location.clone().add(direction); WaterMethods.removeWaterSpouts(location, player); AirMethods.removeAirSpouts(location, player); double radius = FireBlast.AFFECTING_RADIUS; Player source = player; if (EarthBlast.annihilateBlasts(location, radius, source) || WaterManipulation.annihilateBlasts(location, radius, source) || FireBlast.annihilateBlasts(location, radius, source)) { breakBlock(); return false; } Combustion.removeAroundPoint(location, radius); Block block2 = location.getBlock(); if (block2.getLocation().equals(sourceblock.getLocation())) { location = location.clone().add(direction); block2 = location.getBlock(); } if (EarthMethods.isTransparentToEarthbending(player, block) && !block.isLiquid()) { GeneralMethods.breakBlock(block); } else { breakBlock(); return false; } } for (Entity entity : GeneralMethods.getEntitiesAroundPoint(location, FireBlast.AFFECTING_RADIUS)) { if (GeneralMethods.isRegionProtectedFromBuild( player, "EarthBlast", entity.getLocation())) { continue; } if (entity instanceof LivingEntity && (entity.getEntityId() != player.getEntityId() || hitself)) { AirMethods.breakBreathbendingHold(entity); Location location = player.getEyeLocation(); Vector vector = location.getDirection(); entity.setVelocity(vector.normalize().multiply(pushfactor)); double damage = this.damage; if (EarthMethods.isMetal(sourceblock) && EarthMethods.canMetalbend(player)) { damage = EarthMethods.getMetalAugment(this.damage); } GeneralMethods.damageEntity(player, entity, damage); progressing = false; } } if (!progressing) { breakBlock(); return false; } if (revert) { // Methods.addTempEarthBlock(sourceblock, block); if (sourceblock.getType() == Material.RED_SANDSTONE) { sourceblock.setType(sourcetype); if (sourcetype == Material.SAND) { sourceblock.setData((byte) 0x1); } } else { sourceblock.setType(sourcetype); } EarthMethods.moveEarthBlock(sourceblock, block); if (block.getType() == Material.SAND) { block.setType(Material.SANDSTONE); } if (block.getType() == Material.GRAVEL) { block.setType(Material.STONE); } } else { block.setType(sourceblock.getType()); sourceblock.setType(Material.AIR); } sourceblock = block; if (location.distance(destination) < 1) { if (sourcetype == Material.SAND || sourcetype == Material.GRAVEL) { progressing = false; if (sourceblock.getType() == Material.RED_SANDSTONE) { sourcetype = Material.SAND; sourceblock.setType(sourcetype); sourceblock.setData((byte) 0x1); } else { sourceblock.setType(sourcetype); } } falling = true; progressing = false; } return true; } } return false; }