Filled Dagger throw plugin!

Discussion in 'Archived: Plugin Requests' started by wowzersam, May 4, 2014.

  1. Offline

    wowzersam

    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 :)
     
  2. Offline

    arkolly

    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.
     
  3. Offline

    Onlineids

    Really.......
     
    BetrayedQU and imaboy321 like this.
  4. Offline

    wowzersam

    bump, if anyone is wondering, I'm making this for my new RPG server
     
  5. Offline

    Onlineids

    No need to make it an arrow fyi, you can shoot actual items in your case the sword.
     
  6. Offline

    wowzersam

  7. Offline

    Onlineids

    Yea, done through spawning the item and moving at a speed looks as if being thrown
     
  8. Offline

    wowzersam

    Onlineids You should make me this plugin :3
     
  9. Offline

    Onlineids

    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
     
  10. Offline

    Hoolean

    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. :)
     
    wowzersam and Onlineids like this.
  11. Offline

    wowzersam

  12. Offline

    Onlineids

    I'll try to work with hooleans code and make it depend on nothing tho.
     
  13. I'm going to suggest a couple plugins for RPG, Mythic Mobs, Loot, SkillAPI or Heroes, Citizens, Epic Quest
    EDIT: Sorry for the "advertisement"
     
  14. Offline

    wowzersam

  15. Offline

    Onlineids

    I get home from school in hour and a half
     
  16. Offline

    wowzersam

    Onlineids Okay. Sorry (I'm in a different time zone than most, Hawaii) :p
     
  17. Offline

    TheTrueReality

    Ah, Looks Intresting xD
     
  18. Offline

    wowzersam

  19. Offline

    Onlineids

    yea couldn't get it to work sorry
     
  20. Offline

    wowzersam

    Anyone else interested in making this plugin? Perhaps Hoolean?
     
  21. Offline

    SainttX

    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
    1. package me.sainttx;
    2.  
    3. import java.util.ArrayList;
    4. import java.util.regex.Matcher;
    5. import java.util.regex.Pattern;
    6.  
    7. import org.bukkit.Bukkit;
    8. import org.bukkit.entity.Entity;
    9. import org.bukkit.entity.Item;
    10. import org.bukkit.entity.Player;
    11. import org.bukkit.event.EventHandler;
    12. import org.bukkit.event.Listener;
    13. import org.bukkit.event.block.Action;
    14. import org.bukkit.event.player.PlayerInteractEvent;
    15. import org.bukkit.event.player.PlayerPickupItemEvent;
    16. import org.bukkit.inventory.ItemStack;
    17. import org.bukkit.inventory.meta.ItemMeta;
    18. import org.bukkit.metadata.FixedMetadataValue;
    19. import org.bukkit.plugin.java.JavaPlugin;
    20. import org.bukkit.scheduler.BukkitRunnable;
    21.  
    22. public class ThrowingKnife extends JavaPlugin implements Listener {
    23.  
    24. private static final Pattern p = Pattern.compile("\\+([0-9]+) Dagger Damage");
    25. private static ArrayList<Item> itemtrack = new ArrayList<Item>();
    26.  
    27. @Override
    28. public void onEnable() {
    29. Bukkit.getScheduler().scheduleSyncRepeatingTask(this, new CheckItems(), 1L, 1L);
    30. Bukkit.getPluginManager().registerEvents(this, this);
    31. }
    32.  
    33. @EventHandler
    34. public void onInteract(PlayerInteractEvent event) {
    35. Action action = event.getAction();
    36. Player player = event.getPlayer();
    37. double damage = 0;
    38. boolean throwable = false;
    39. if (!player.hasPermission("throwingknife.throw")) {
    40. return;
    41. }
    42. if ((action == Action.LEFT_CLICK_AIR || action == Action.LEFT_CLICK_BLOCK) && player.isSneaking()) {
    43. ItemStack itemstack = player.getItemInHand().clone();
    44. ItemMeta itemmeta = itemstack.getItemMeta();
    45. if (itemstack.getType().toString().contains("SWORD") && itemmeta.getLore() != null) {
    46. for (String string : itemmeta.getLore()) {
    47. Matcher m = p.matcher(string);
    48. if (string.contains("Sneak + click to throw")) {
    49. throwable = true;
    50. } else if (m.find()) {
    51. damage = Double.parseDouble(m.group(1));
    52. }
    53. }
    54. if (throwable) {
    55. player.getInventory().removeItem(itemstack);
    56. final Item item = player.getWorld().dropItem(player.getEyeLocation(), itemstack);
    57. item.setMetadata("damage", new FixedMetadataValue(this, damage));
    58. item.setMetadata("owner", new FixedMetadataValue(this, player.getName()));
    59. item.setVelocity(player.getLocation().getDirection().multiply(1.4D));
    60. itemtrack.add(item);
    61.  
    62. Bukkit.getScheduler().scheduleSyncDelayedTask(this, new Runnable() {
    63. @Override
    64. public void run() {
    65. itemtrack.remove(item);
    66. }
    67. }, 30L);
    68.  
    69. }
    70. }
    71. }
    72. }
    73.  
    74. @EventHandler
    75. public void onPickup(PlayerPickupItemEvent event) {
    76. Item item = event.getItem();
    77. if (itemtrack.contains(item)) {
    78. item.removeMetadata("damage", this);
    79. item.removeMetadata("owner", this);
    80. itemtrack.remove(item);
    81. }
    82. }
    83.  
    84. public class CheckItems extends BukkitRunnable {
    85. @Override
    86. public void run() {
    87. if (!itemtrack.isEmpty()) {
    88. for (Item item : itemtrack) {
    89. for (Entity nearby : item.getNearbyEntities(0.75D, 0.75D, 0.75D)) {
    90. if (nearby instanceof Player) {
    91. if (item.getMetadata("damage").isEmpty()) return;
    92. if (item.getMetadata("owner").isEmpty()) return;
    93. Player player = (Player) nearby;
    94. String owner = item.getMetadata("owner").get(0).asString();
    95. double damage = item.getMetadata("damage").get(0).asDouble();
    96. if (!owner.equals(player.getName())) {
    97. player.damage(damage);
    98. }
    99. }
    100. }
    101. }
    102. }
    103. }
    104. }
    105. }
    106.  
     
  22. Offline

    wowzersam

    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?
     
  23. Offline

    SainttX

    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):
    [​IMG]
    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.
     
  24. Offline

    wowzersam

    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.
     
  25. Offline

    Onlineids

    SainttX Doesn't look like you added a proper system for damage
     
  26. Offline

    SainttX

    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
    1. package me.sainttx;
    2.  
    3. import java.util.ArrayList;
    4. import java.util.regex.Matcher;
    5. import java.util.regex.Pattern;
    6.  
    7. import org.bukkit.Bukkit;
    8. import org.bukkit.entity.Damageable;
    9. import org.bukkit.entity.Entity;
    10. import org.bukkit.entity.Item;
    11. import org.bukkit.entity.Player;
    12. import org.bukkit.event.EventHandler;
    13. import org.bukkit.event.Listener;
    14. import org.bukkit.event.block.Action;
    15. import org.bukkit.event.entity.ItemDespawnEvent;
    16. import org.bukkit.event.player.PlayerInteractEvent;
    17. import org.bukkit.event.player.PlayerPickupItemEvent;
    18. import org.bukkit.inventory.ItemStack;
    19. import org.bukkit.inventory.meta.ItemMeta;
    20. import org.bukkit.metadata.FixedMetadataValue;
    21. import org.bukkit.plugin.java.JavaPlugin;
    22. import org.bukkit.scheduler.BukkitRunnable;
    23.  
    24. public class ThrowingKnife extends JavaPlugin implements Listener {
    25.  
    26. private static final Pattern p = Pattern.compile("\\+([0-9]+) Dagger Damage");
    27. private static ArrayList<Item> itemtrack = new ArrayList<Item>();
    28. private final FixedMetadataValue nodamage = new FixedMetadataValue(this, 0);
    29.  
    30. @Override
    31. public void onEnable() {
    32. Bukkit.getScheduler().scheduleSyncRepeatingTask(this, new CheckItems(), 1L, 1L);
    33. Bukkit.getPluginManager().registerEvents(this, this);
    34. }
    35.  
    36. @EventHandler
    37. public void onInteract(PlayerInteractEvent event) {
    38. Action action = event.getAction();
    39. Player player = event.getPlayer();
    40. double damage = 0;
    41. boolean throwable = false;
    42. if (!player.hasPermission("throwingknife.throw")) {
    43. return;
    44. }
    45. if ((action == Action.LEFT_CLICK_AIR || action == Action.LEFT_CLICK_BLOCK) && player.isSneaking()) {
    46. ItemStack itemstack = player.getItemInHand().clone();
    47. ItemMeta itemmeta = itemstack.getItemMeta();
    48. if (itemstack.getType().toString().contains("SWORD") && itemmeta.getLore() != null) {
    49. for (String string : itemmeta.getLore()) {
    50. Matcher m = p.matcher(string);
    51. if (string.contains("Sneak + click to throw")) {
    52. throwable = true;
    53. } else if (m.find()) {
    54. damage = Double.parseDouble(m.group(1));
    55. }
    56. }
    57. if (throwable) {
    58. player.getInventory().removeItem(itemstack);
    59. final Item item = player.getWorld().dropItem(player.getEyeLocation(), itemstack);
    60. item.setMetadata("damage", new FixedMetadataValue(this, damage));
    61. item.setMetadata("owner", new FixedMetadataValue(this, player.getName()));
    62. item.setVelocity(player.getLocation().getDirection().multiply(1.5D));
    63. itemtrack.add(item);
    64. }
    65. }
    66. }
    67. }
    68.  
    69. @EventHandler
    70. public void onPickup(PlayerPickupItemEvent event) {
    71. Item item = event.getItem();
    72. Player player = event.getPlayer();
    73. if (itemtrack.contains(item)) {
    74. String owner = item.getMetadata("owner").get(0).asString();
    75. if (!player.getName().equals(owner)) {
    76. event.setCancelled(true);
    77. return;
    78. }
    79. item.removeMetadata("damage", this);
    80. item.removeMetadata("owner", this);
    81. itemtrack.remove(item);
    82. }
    83. }
    84.  
    85. @EventHandler
    86. public void onDespawn(ItemDespawnEvent event) {
    87. Item item = event.getEntity();
    88. if (itemtrack.contains(item)) {
    89. itemtrack.remove(item);
    90. }
    91. }
    92.  
    93. public class CheckItems extends BukkitRunnable {
    94. @Override
    95. public void run() {
    96. if (!itemtrack.isEmpty()) {
    97. for (Item item : itemtrack) {
    98. for (Entity nearby : item.getNearbyEntities(1.0D, 1.0D, 1.0D)) {
    99. if (nearby instanceof Player) {
    100. if (item.getMetadata("damage").isEmpty()) return;
    101. if (item.getMetadata("owner").isEmpty()) return;
    102. Player player = (Player) nearby;
    103. String owner = item.getMetadata("owner").get(0).asString();
    104. double damage = item.getMetadata("damage").get(0).asDouble();
    105. if (damage == 0) return;
    106. if (!owner.equals(player.getName())) {
    107. player.damage(damage);
    108. item.setMetadata("damage", nodamage);
    109. }
    110. } else if (nearby instanceof Damageable) {
    111. Damageable damageable = (Damageable) nearby;
    112. double damage = item.getMetadata("damage").get(0).asDouble();
    113. if (damage == 0) return;
    114. damageable.damage(damage);
    115. item.setMetadata("damage", nodamage);
    116. }
    117. }
    118. }
    119. }
    120. }
    121. }
    122. }
    123.  
     
  27. Offline

    wowzersam

    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?
     
  28. Offline

    SainttX

    wowzersam Do you want it to say anything when it does?
     
  29. Offline

    wowzersam

  30. Offline

    SainttX

    wowzersam https://mega.co.nz/#!1J03lA5B!Z4G50pmOe5wV9jM5aqf2FTU7Eofzp-cVhW7VsZG1OAY enjoy :)
    Code:java
    1. package me.sainttx;
    2.  
    3. import java.util.ArrayList;
    4. import java.util.regex.Matcher;
    5. import java.util.regex.Pattern;
    6.  
    7. import org.bukkit.Bukkit;
    8. import org.bukkit.Material;
    9. import org.bukkit.entity.Damageable;
    10. import org.bukkit.entity.Entity;
    11. import org.bukkit.entity.Item;
    12. import org.bukkit.entity.Player;
    13. import org.bukkit.event.EventHandler;
    14. import org.bukkit.event.Listener;
    15. import org.bukkit.event.block.Action;
    16. import org.bukkit.event.entity.ItemDespawnEvent;
    17. import org.bukkit.event.player.PlayerInteractEvent;
    18. import org.bukkit.event.player.PlayerPickupItemEvent;
    19. import org.bukkit.inventory.ItemStack;
    20. import org.bukkit.inventory.meta.ItemMeta;
    21. import org.bukkit.metadata.FixedMetadataValue;
    22. import org.bukkit.plugin.java.JavaPlugin;
    23. import org.bukkit.scheduler.BukkitRunnable;
    24.  
    25. public class ThrowingKnife extends JavaPlugin implements Listener {
    26.  
    27. private static final Pattern p = Pattern.compile("\\+([0-9]+) Dagger Damage");
    28. private static ArrayList<Item> itemtrack = new ArrayList<Item>();
    29. private final FixedMetadataValue nodamage = new FixedMetadataValue(this, 0);
    30.  
    31. @Override
    32. public void onEnable() {
    33. Bukkit.getScheduler().scheduleSyncRepeatingTask(this, new CheckItems(), 1L, 1L);
    34. Bukkit.getPluginManager().registerEvents(this, this);
    35. }
    36.  
    37. @EventHandler
    38. public void onInteract(PlayerInteractEvent event) {
    39. Action action = event.getAction();
    40. final Player player = event.getPlayer();
    41. double damage = 0;
    42. boolean throwable = false;
    43. if (!player.hasPermission("throwingknife.throw")) {
    44. return;
    45. }
    46. if ((action == Action.LEFT_CLICK_AIR || action == Action.LEFT_CLICK_BLOCK) && player.isSneaking()) {
    47. final ItemStack itemstack = player.getItemInHand().clone();
    48. ItemMeta itemmeta = itemstack.getItemMeta();
    49. if (itemstack.getType().toString().contains("SWORD") && itemmeta.getLore() != null) {
    50. for (String string : itemmeta.getLore()) {
    51. Matcher m = p.matcher(string);
    52. if (string.contains("Sneak + click to throw")) {
    53. throwable = true;
    54. } else if (m.find()) {
    55. damage = Double.parseDouble(m.group(1));
    56. }
    57. }
    58. if (throwable) {
    59. player.getInventory().removeItem(itemstack);
    60. final Item item = player.getWorld().dropItem(player.getEyeLocation(), itemstack);
    61. item.setMetadata("damage", new FixedMetadataValue(this, damage));
    62. item.setMetadata("owner", new FixedMetadataValue(this, player.getName()));
    63. item.setVelocity(player.getLocation().getDirection().multiply(1.5D));
    64. itemtrack.add(item);
    65.  
    66. Bukkit.getScheduler().scheduleSyncDelayedTask(this, new Runnable() {
    67. @Override
    68. public void run() {
    69. if (player.isOnline()) {
    70. if (player.getInventory().firstEmpty() == -1) {
    71. return;
    72. }
    73. player.getInventory().addItem(itemstack);
    74. itemtrack.remove(item);
    75. item.remove();
    76. }
    77. }
    78. }, 100L);
    79. }
    80. }
    81. }
    82. }
    83.  
    84. @EventHandler
    85. public void onPickup(PlayerPickupItemEvent event) {
    86. Item item = event.getItem();
    87. Player player = event.getPlayer();
    88. if (itemtrack.contains(item)) {
    89. String owner = item.getMetadata("owner").get(0).asString();
    90. if (!player.getName().equals(owner)) {
    91. event.setCancelled(true);
    92. return;
    93. }
    94. item.removeMetadata("damage", this);
    95. item.removeMetadata("owner", this);
    96. itemtrack.remove(item);
    97. }
    98. }
    99.  
    100. @EventHandler
    101. public void onDespawn(ItemDespawnEvent event) {
    102. Item item = event.getEntity();
    103. if (itemtrack.contains(item)) {
    104. itemtrack.remove(item);
    105. }
    106. }
    107.  
    108. public class CheckItems extends BukkitRunnable {
    109. @Override
    110. public void run() {
    111. if (!itemtrack.isEmpty()) {
    112. for (Item item : itemtrack) {
    113. for (Entity nearby : item.getNearbyEntities(1.0D, 1.0D, 1.0D)) {
    114. if (nearby instanceof Player) {
    115. if (item.getMetadata("damage").isEmpty()) return;
    116. if (item.getMetadata("owner").isEmpty()) return;
    117. Player player = (Player) nearby;
    118. String owner = item.getMetadata("owner").get(0).asString();
    119. double damage = item.getMetadata("damage").get(0).asDouble();
    120. if (damage == 0) return;
    121. if (!owner.equals(player.getName())) {
    122. player.damage(damage);
    123. item.setMetadata("damage", nodamage);
    124. }
    125. } else if (nearby instanceof Damageable) {
    126. Damageable damageable = (Damageable) nearby;
    127. double damage = item.getMetadata("damage").get(0).asDouble();
    128. if (damage == 0) return;
    129. damageable.damage(damage);
    130. item.setMetadata("damage", nodamage);
    131. }
    132. }
    133. }
    134. }
    135. }
    136. }
    137. }
    138.  
     
    TheMintyMate and wowzersam like this.

Share This Page