Suggested Name: DaggerThrow Category: Fun What I want: Dagger throw would allow you to throw ANY type of sword IF the lore in it says: Right click to throw. When you right click with a dagger, it would turn the dagger into an arrow and deal damage to the first enemy based on whatever lore you give it. So if I gave the dagger: +5 Dagger Damage, the dagger would deal 5 MORE damage than a regular arrow. After hitting the entity, the dagger would be returned to the players inventory in the same slot, and have a cool down (configurable). Ideas for permissions: - dt.use <-- Allows player to throw the dagger Ideas for commands: None When I'd like it: Within a month, if possible
Hi, I could do this, Do not add me on skype, as its not necessary. Please leave all details on this thread! Mod Edit: Changed the message from "Contact me on skype" to what should be said if you want to take on making this plugin.
I'll see if I have time tommorow have alot of requests already, is it alright if it depends on a library would make my life way easier
Pseudo code for anyone thinking of doing it: Code: const STILL_VELOCITY = new Vector(0,0,0) DaggerMonitorTask constructor (dagger) -> this.dagger = dagger run -> if touching(entity) entity.damage(daggerDamage) cancelRepeatingTask else if dagger.getVelocity is STILL_VELOCITY -> cancelRepeatingTask onPlayerInteractEvent -> if not rightClickAir or not dagger -> return direction = player.getDirection() droppedItem = world.spawnDroppedItem(player.getLocation().add(player.getDirection().multiply(3))) droppedItem.setVelocity(direction.multiply(daggerSpeed)) scheduleRepeatingTask(new DaggerMonitorTask(droppedItem)) Obviously not enough to compile but enough to get the gist of what needs to be done.
I'm going to suggest a couple plugins for RPG, Mythic Mobs, Loot, SkillAPI or Heroes, Citizens, Epic Quest EDIT: Sorry for the "advertisement"
wowzersamhttps://mega.co.nz/#!5J11hKCZ!MeNVUMmZq43ptYGYhMcjGqFsefAec6y_ThWf94ZgRcA This should work, let me know if there are any problems info: Permission = throwingknife.throw Required lore: Shift + click to throw & +# Dagger Damage The sword will deal whatever damage you set in the lore (ie. +15 Dagger Damage will deal ~7.5 hearts) and won't damage the person who threw it. src: Code:java package me.sainttx; import java.util.ArrayList;import java.util.regex.Matcher;import java.util.regex.Pattern; import org.bukkit.Bukkit;import org.bukkit.entity.Entity;import org.bukkit.entity.Item;import org.bukkit.entity.Player;import org.bukkit.event.EventHandler;import org.bukkit.event.Listener;import org.bukkit.event.block.Action;import org.bukkit.event.player.PlayerInteractEvent;import org.bukkit.event.player.PlayerPickupItemEvent;import org.bukkit.inventory.ItemStack;import org.bukkit.inventory.meta.ItemMeta;import org.bukkit.metadata.FixedMetadataValue;import org.bukkit.plugin.java.JavaPlugin;import org.bukkit.scheduler.BukkitRunnable; public class ThrowingKnife extends JavaPlugin implements Listener { private static final Pattern p = Pattern.compile("\\+([0-9]+) Dagger Damage"); private static ArrayList<Item> itemtrack = new ArrayList<Item>(); @Override public void onEnable() { Bukkit.getScheduler().scheduleSyncRepeatingTask(this, new CheckItems(), 1L, 1L); Bukkit.getPluginManager().registerEvents(this, this); } @EventHandler public void onInteract(PlayerInteractEvent event) { Action action = event.getAction(); Player player = event.getPlayer(); double damage = 0; boolean throwable = false; if (!player.hasPermission("throwingknife.throw")) { return; } if ((action == Action.LEFT_CLICK_AIR || action == Action.LEFT_CLICK_BLOCK) && player.isSneaking()) { ItemStack itemstack = player.getItemInHand().clone(); ItemMeta itemmeta = itemstack.getItemMeta(); if (itemstack.getType().toString().contains("SWORD") && itemmeta.getLore() != null) { for (String string : itemmeta.getLore()) { Matcher m = p.matcher(string); if (string.contains("Sneak + click to throw")) { throwable = true; } else if (m.find()) { damage = Double.parseDouble(m.group(1)); } } if (throwable) { player.getInventory().removeItem(itemstack); final Item item = player.getWorld().dropItem(player.getEyeLocation(), itemstack); item.setMetadata("damage", new FixedMetadataValue(this, damage)); item.setMetadata("owner", new FixedMetadataValue(this, player.getName())); item.setVelocity(player.getLocation().getDirection().multiply(1.4D)); itemtrack.add(item); Bukkit.getScheduler().scheduleSyncDelayedTask(this, new Runnable() { @Override public void run() { itemtrack.remove(item); } }, 30L); } } } } @EventHandler public void onPickup(PlayerPickupItemEvent event) { Item item = event.getItem(); if (itemtrack.contains(item)) { item.removeMetadata("damage", this); item.removeMetadata("owner", this); itemtrack.remove(item); } } public class CheckItems extends BukkitRunnable { @Override public void run() { if (!itemtrack.isEmpty()) { for (Item item : itemtrack) { for (Entity nearby : item.getNearbyEntities(0.75D, 0.75D, 0.75D)) { if (nearby instanceof Player) { if (item.getMetadata("damage").isEmpty()) return; if (item.getMetadata("owner").isEmpty()) return; Player player = (Player) nearby; String owner = item.getMetadata("owner").get(0).asString(); double damage = item.getMetadata("damage").get(0).asDouble(); if (!owner.equals(player.getName())) { player.damage(damage); } } } } } } }}
SainttX I'm a little confused about the lore system. I figured out the throw lore (which is Sneak + click to throw), but what is the damage lore? Does it go on a separate line or is it connected to the first? Other than that great plugin! PS: I don't think dagger damage is working. I tried it on the second line, as well as connected to the first. Not doing damage. Also, can you make it so the player who threw the dagger is the only one who can pick it up?
wowzersam I made it shift + left click because I was having problems with right click (seemed like a Bukkit bug where when I blocked with the sword it wouldn't remove it from the inventory but one would still spawn) As for the lore, here is a picture of a sword I was testing with that seemed to work (it dealt 2.5 damage): I wasn't sure if you wanted to be able to define the damage like that in the lore or not so I gave the option, I can change it to just take the swords default damage if you'd like. Also, I only tested it with myself so when I work on it a bit more I'll grab another player to test on. I'll do the owner being the only one able to pick it up in a bit.
SainttX Ah. Well only the Sneak + click to throw seems to be working. It does not damage to mobs/players as far as I can tell.
wowzersam Onlineids https://mega.co.nz/#!odtwCZ5Z!rrBdt82q_u03SbPd5UQvfPIAgN_np2CkRSVJudt4XGk Tested on players and monsters and it works fine. After it hits the first entity it won't do damage to any others (no multi combos). I'd track which entities can't take damage twice but it's a little bit annoying; the method I have now prevents people being damaged by trying to pick up the sword. Also, I only had player damage in the previous version; I've added monsters. Code:java package me.sainttx; import java.util.ArrayList;import java.util.regex.Matcher;import java.util.regex.Pattern; import org.bukkit.Bukkit;import org.bukkit.entity.Damageable;import org.bukkit.entity.Entity;import org.bukkit.entity.Item;import org.bukkit.entity.Player;import org.bukkit.event.EventHandler;import org.bukkit.event.Listener;import org.bukkit.event.block.Action;import org.bukkit.event.entity.ItemDespawnEvent;import org.bukkit.event.player.PlayerInteractEvent;import org.bukkit.event.player.PlayerPickupItemEvent;import org.bukkit.inventory.ItemStack;import org.bukkit.inventory.meta.ItemMeta;import org.bukkit.metadata.FixedMetadataValue;import org.bukkit.plugin.java.JavaPlugin;import org.bukkit.scheduler.BukkitRunnable; public class ThrowingKnife extends JavaPlugin implements Listener { private static final Pattern p = Pattern.compile("\\+([0-9]+) Dagger Damage"); private static ArrayList<Item> itemtrack = new ArrayList<Item>(); private final FixedMetadataValue nodamage = new FixedMetadataValue(this, 0); @Override public void onEnable() { Bukkit.getScheduler().scheduleSyncRepeatingTask(this, new CheckItems(), 1L, 1L); Bukkit.getPluginManager().registerEvents(this, this); } @EventHandler public void onInteract(PlayerInteractEvent event) { Action action = event.getAction(); Player player = event.getPlayer(); double damage = 0; boolean throwable = false; if (!player.hasPermission("throwingknife.throw")) { return; } if ((action == Action.LEFT_CLICK_AIR || action == Action.LEFT_CLICK_BLOCK) && player.isSneaking()) { ItemStack itemstack = player.getItemInHand().clone(); ItemMeta itemmeta = itemstack.getItemMeta(); if (itemstack.getType().toString().contains("SWORD") && itemmeta.getLore() != null) { for (String string : itemmeta.getLore()) { Matcher m = p.matcher(string); if (string.contains("Sneak + click to throw")) { throwable = true; } else if (m.find()) { damage = Double.parseDouble(m.group(1)); } } if (throwable) { player.getInventory().removeItem(itemstack); final Item item = player.getWorld().dropItem(player.getEyeLocation(), itemstack); item.setMetadata("damage", new FixedMetadataValue(this, damage)); item.setMetadata("owner", new FixedMetadataValue(this, player.getName())); item.setVelocity(player.getLocation().getDirection().multiply(1.5D)); itemtrack.add(item); } } } } @EventHandler public void onPickup(PlayerPickupItemEvent event) { Item item = event.getItem(); Player player = event.getPlayer(); if (itemtrack.contains(item)) { String owner = item.getMetadata("owner").get(0).asString(); if (!player.getName().equals(owner)) { event.setCancelled(true); return; } item.removeMetadata("damage", this); item.removeMetadata("owner", this); itemtrack.remove(item); } } @EventHandler public void onDespawn(ItemDespawnEvent event) { Item item = event.getEntity(); if (itemtrack.contains(item)) { itemtrack.remove(item); } } public class CheckItems extends BukkitRunnable { @Override public void run() { if (!itemtrack.isEmpty()) { for (Item item : itemtrack) { for (Entity nearby : item.getNearbyEntities(1.0D, 1.0D, 1.0D)) { if (nearby instanceof Player) { if (item.getMetadata("damage").isEmpty()) return; if (item.getMetadata("owner").isEmpty()) return; Player player = (Player) nearby; String owner = item.getMetadata("owner").get(0).asString(); double damage = item.getMetadata("damage").get(0).asDouble(); if (damage == 0) return; if (!owner.equals(player.getName())) { player.damage(damage); item.setMetadata("damage", nodamage); } } else if (nearby instanceof Damageable) { Damageable damageable = (Damageable) nearby; double damage = item.getMetadata("damage").get(0).asDouble(); if (damage == 0) return; damageable.damage(damage); item.setMetadata("damage", nodamage); } } } } } }}
SainttX Awesome! Works well. I have one more thing to ask. Could you make it so 5 seconds after throwing, it returns to your inventory?
wowzersam https://mega.co.nz/#!1J03lA5B!Z4G50pmOe5wV9jM5aqf2FTU7Eofzp-cVhW7VsZG1OAY enjoy Code:java package me.sainttx; import java.util.ArrayList;import java.util.regex.Matcher;import java.util.regex.Pattern; import org.bukkit.Bukkit;import org.bukkit.Material;import org.bukkit.entity.Damageable;import org.bukkit.entity.Entity;import org.bukkit.entity.Item;import org.bukkit.entity.Player;import org.bukkit.event.EventHandler;import org.bukkit.event.Listener;import org.bukkit.event.block.Action;import org.bukkit.event.entity.ItemDespawnEvent;import org.bukkit.event.player.PlayerInteractEvent;import org.bukkit.event.player.PlayerPickupItemEvent;import org.bukkit.inventory.ItemStack;import org.bukkit.inventory.meta.ItemMeta;import org.bukkit.metadata.FixedMetadataValue;import org.bukkit.plugin.java.JavaPlugin;import org.bukkit.scheduler.BukkitRunnable; public class ThrowingKnife extends JavaPlugin implements Listener { private static final Pattern p = Pattern.compile("\\+([0-9]+) Dagger Damage"); private static ArrayList<Item> itemtrack = new ArrayList<Item>(); private final FixedMetadataValue nodamage = new FixedMetadataValue(this, 0); @Override public void onEnable() { Bukkit.getScheduler().scheduleSyncRepeatingTask(this, new CheckItems(), 1L, 1L); Bukkit.getPluginManager().registerEvents(this, this); } @EventHandler public void onInteract(PlayerInteractEvent event) { Action action = event.getAction(); final Player player = event.getPlayer(); double damage = 0; boolean throwable = false; if (!player.hasPermission("throwingknife.throw")) { return; } if ((action == Action.LEFT_CLICK_AIR || action == Action.LEFT_CLICK_BLOCK) && player.isSneaking()) { final ItemStack itemstack = player.getItemInHand().clone(); ItemMeta itemmeta = itemstack.getItemMeta(); if (itemstack.getType().toString().contains("SWORD") && itemmeta.getLore() != null) { for (String string : itemmeta.getLore()) { Matcher m = p.matcher(string); if (string.contains("Sneak + click to throw")) { throwable = true; } else if (m.find()) { damage = Double.parseDouble(m.group(1)); } } if (throwable) { player.getInventory().removeItem(itemstack); final Item item = player.getWorld().dropItem(player.getEyeLocation(), itemstack); item.setMetadata("damage", new FixedMetadataValue(this, damage)); item.setMetadata("owner", new FixedMetadataValue(this, player.getName())); item.setVelocity(player.getLocation().getDirection().multiply(1.5D)); itemtrack.add(item); Bukkit.getScheduler().scheduleSyncDelayedTask(this, new Runnable() { @Override public void run() { if (player.isOnline()) { if (player.getInventory().firstEmpty() == -1) { return; } player.getInventory().addItem(itemstack); itemtrack.remove(item); item.remove(); } } }, 100L); } } } } @EventHandler public void onPickup(PlayerPickupItemEvent event) { Item item = event.getItem(); Player player = event.getPlayer(); if (itemtrack.contains(item)) { String owner = item.getMetadata("owner").get(0).asString(); if (!player.getName().equals(owner)) { event.setCancelled(true); return; } item.removeMetadata("damage", this); item.removeMetadata("owner", this); itemtrack.remove(item); } } @EventHandler public void onDespawn(ItemDespawnEvent event) { Item item = event.getEntity(); if (itemtrack.contains(item)) { itemtrack.remove(item); } } public class CheckItems extends BukkitRunnable { @Override public void run() { if (!itemtrack.isEmpty()) { for (Item item : itemtrack) { for (Entity nearby : item.getNearbyEntities(1.0D, 1.0D, 1.0D)) { if (nearby instanceof Player) { if (item.getMetadata("damage").isEmpty()) return; if (item.getMetadata("owner").isEmpty()) return; Player player = (Player) nearby; String owner = item.getMetadata("owner").get(0).asString(); double damage = item.getMetadata("damage").get(0).asDouble(); if (damage == 0) return; if (!owner.equals(player.getName())) { player.damage(damage); item.setMetadata("damage", nodamage); } } else if (nearby instanceof Damageable) { Damageable damageable = (Damageable) nearby; double damage = item.getMetadata("damage").get(0).asDouble(); if (damage == 0) return; damageable.damage(damage); item.setMetadata("damage", nodamage); } } } } } }}