Gravity Gun

Discussion in 'Archived: Plugin Requests' started by smackman17, Sep 22, 2013.

  1. Offline

    smackman17

    Plugin name: Gravity Gun

    What it will do: Add the gravity gun from Half life into Minecraft! When you right click a block with the gun (gun item configurable), it puts that block in to "falling mode" (like sand/gravel). Wherever you look with the block in the gun, it moves to the nearest block that you are looking at (also works in air). Right click again to place the block.

    Permissions:

    GravityGun.get: Get the gravity gun

    GravityGun.use: Use the Gravity Gun

    Commands:

    /gravitygun get - get the gravity gun

    /gravitygun reload - reload the config (config idea below)

    /gg could be an ailias for /gravitygun

    Config:

    Range: How far the blocks go away from the player (to prevent the block from going infinitely up when player looks up)

    Item: Item ID of the item

    Lore: For custom lore
    Line 1: Lore
    Line 2: Lore
    Line 3: Lore
    Line 4: Lore

    When I would like it by: Whenever it can be made
     
  2. Offline

    toxictroop

    Looks like a really sweet idea!
     
  3. Offline

    Freelix2000

    I could do most of this, the only thing I would have trouble with is the name and lore... I'm not good with metadata.
     
  4. Offline

    AndyMcB1

    timtower could you post your "name" class here?
     
  5. Online

    timtower Administrator Administrator Moderator

    AndyMcB1 Here you go, Freelix2000 I assume that this one is for you
    code (open)
    Code:java
    1. package nl.timdebrouwer.testplugin;
    2.  
    3. import java.util.ArrayList;
    4. import java.util.Arrays;
    5. import java.util.List;
    6. import org.bukkit.Bukkit;
    7. import org.bukkit.inventory.ItemStack;
    8. import org.bukkit.inventory.meta.ItemMeta;
    9.  
    10. public class LoreAPI
    11. {
    12. /**
    13. * Adds lore to the ItemStack
    14. *
    15. * @param itemStack
    16. * ItemStack to add lore to
    17. * @param lore
    18. * Lore to add to ItemStack
    19. * @return lored ItemStack
    20. */
    21. public ItemStack addLore(final ItemStack itemStack, final String lore)
    22. {
    23. ItemStack ret = itemStack;
    24. List<String> loreList = getLore(ret);
    25. loreList.add(lore);
    26. return setLore(ret, loreList);
    27. }
    28.  
    29. /**
    30. * @return all items that the plugin can use
    31. */
    32. /**
    33. * Gets the lore of an ItemStack
    34. *
    35. * @param itemStack
    36. * ItemStack to get the lore of
    37. * @return the lore of an ItemStack
    38. */
    39. public List<String> getLore(final ItemStack itemStack)
    40. {
    41. ItemStack ret = itemStack;
    42. ItemMeta itemMeta;
    43. if (ret.hasItemMeta())
    44. {
    45. itemMeta = ret.getItemMeta();
    46. }
    47. else
    48. {
    49. itemMeta = Bukkit.getItemFactory().getItemMeta(ret.getType());
    50. }
    51. if (itemMeta.hasLore())
    52. return itemMeta.getLore();
    53. return new ArrayList<String>();
    54. }
    55.  
    56. /**
    57. * Gets the name of an ItemStack
    58. *
    59. * @param itemStack
    60. * ItemStack to get the lore of
    61. * @return the lore of an ItemStack
    62. */
    63. public String getName(final ItemStack itemStack)
    64. {
    65. ItemStack ret = itemStack;
    66. ItemMeta itemMeta;
    67. if (ret.hasItemMeta())
    68. {
    69. itemMeta = ret.getItemMeta();
    70. }
    71. else
    72. {
    73. itemMeta = Bukkit.getItemFactory().getItemMeta(ret.getType());
    74. }
    75. if (itemMeta.hasDisplayName())
    76. return itemMeta.getDisplayName();
    77. String unfName = ret.getType().name();
    78. String[] split = unfName.split("_");
    79. String fName = new String();
    80. for (String s : split)
    81. {
    82. String firstLetter = s.substring(0, 1);
    83. String restOfWord = s.substring(1, s.length());
    84. String newName = firstLetter.toUpperCase()
    85. + restOfWord.toLowerCase();
    86. fName = fName + newName + " ";
    87. }
    88. return fName;
    89. }
    90.  
    91. /**
    92. * Replace a line of lore with another line
    93. *
    94. * @param tool
    95. * Tool to replace lore on
    96. * @param toReplace
    97. * Line of lore to be replaced
    98. * @param replaceWith
    99. * Line replacing toReplace
    100. * @return Tool with new lore
    101. */
    102. public ItemStack replaceLore(final ItemStack tool, final String toReplace,
    103. final String replaceWith)
    104. {
    105. ItemMeta meta = tool.getItemMeta();
    106. List<String> loreList = meta.getLore();
    107. if ((loreList == null) || loreList.isEmpty())
    108. return tool;
    109. for (String s : meta.getLore())
    110. if (s.equals(toReplace))
    111. {
    112. loreList.remove(s);
    113. loreList.add(replaceWith);
    114. }
    115. meta.setLore(loreList);
    116. tool.setItemMeta(meta);
    117. return tool;
    118. }
    119.  
    120. /**
    121. * Sets the lore of an ItemStack
    122. *
    123. * @param itemStack
    124. * ItemStack to set lore for
    125. * @param lore
    126. * Lore to give to the ItemStack
    127. * @return lored ItemStack
    128. */
    129. public ItemStack setLore(final ItemStack itemStack, final List<String> lore)
    130. {
    131. ItemStack ret = itemStack;
    132. ItemMeta itemMeta;
    133. if (ret.hasItemMeta())
    134. {
    135. itemMeta = ret.getItemMeta();
    136. }
    137. else
    138. {
    139. itemMeta = Bukkit.getItemFactory().getItemMeta(ret.getType());
    140. }
    141. itemMeta.setLore(lore);
    142. ret.setItemMeta(itemMeta);
    143. return ret;
    144. }
    145.  
    146. /**
    147. * Sets the lore of an ItemStack
    148. *
    149. * @param itemStack
    150. * ItemStack to set lore for
    151. * @param lore
    152. * Lore to give to the ItemStack
    153. * @return lored ItemStack
    154. */
    155. public ItemStack setLore(final ItemStack itemStack, final String... lore)
    156. {
    157. ItemStack ret = itemStack;
    158. ItemMeta itemMeta;
    159. if (ret.hasItemMeta())
    160. {
    161. itemMeta = ret.getItemMeta();
    162. }
    163. else
    164. {
    165. itemMeta = Bukkit.getItemFactory().getItemMeta(ret.getType());
    166. }
    167. itemMeta.setLore(Arrays.asList(lore));
    168. ret.setItemMeta(itemMeta);
    169. return ret;
    170. }
    171.  
    172. /**
    173. * Sets the name of an ItemStack
    174. *
    175. * @param itemStack
    176. * ItemStack to set name for
    177. * @param name
    178. * Name to give to the ItemStack
    179. * @return named ItemStack
    180. */
    181. public ItemStack setName(final ItemStack itemStack, final String name)
    182. {
    183. ItemStack ret = itemStack;
    184. ItemMeta itemMeta;
    185. if (ret.hasItemMeta())
    186. {
    187. itemMeta = ret.getItemMeta();
    188. }
    189. else
    190. {
    191. itemMeta = Bukkit.getItemFactory().getItemMeta(ret.getType());
    192. }
    193. itemMeta.setDisplayName(name);
    194. ret.setItemMeta(itemMeta);
    195. return ret;
    196. }
    197. }
    198.  
     
    calebbfmv and AndyMcB1 like this.
  6. Offline

    smackman17

    Whoevers working on it: could you link the bukkitDev page here when your done?
     
  7. Offline

    Freelix2000

    Sure. I'm not finished with making the name and lore and id for the item, but I have made a basic gravity gun. I'll make a page for it now, but I'll keep working on it.
     
  8. Offline

    smackman17

  9. Offline

    Freelix2000

  10. Offline

    Freelix2000

    Added custom name, item type, and lore. Try the new version whenever it gets approved. :)
     
  11. Offline

    JPG2000

    Freelix2000 Back to the Lore thing its easy. I know timtower sent you code, but I'll explain:
    Code:java
    1. ItemStack yolo = new ItemStack(Material.DIRT, 1) //1 stack of dirt
    2. ItemMeta meta = yolo.getItemMeta(); //The item metta variable of yolo
    3. //Do what you want here, I'll just set Displayname
    4. meta.setDisplayname("stupid" + ChatColor.RED + "word");
    5.  
    6. yolo.setItemMeta(meta); //We only made the meta variable, now we need to set it
    7.  
     
  12. Offline

    AndyMcB1

    JPG2000
    Code:
    ItemStack yolo = new ItemStack(Material.DIRT, 1) //1 stack of dirt
    Isn't that 1 dirt block?
     
  13. Online

    timtower Administrator Administrator Moderator

    Yes it it,
    JPG2000
    Code:java
    1. ItemStack yolo = new ItemStack(Material.DIRT, 64) //This is a stack
     
    AndyMcB1 likes this.
  14. Offline

    Freelix2000

    I already finished it. Well, it still needs a bit more improvement, but the name, lores, and custom materials are done.
     
  15. Offline

    JPG2000

    AndyMcB1 Its one dirt block with a changed display name!
     
  16. Offline

    AndyMcB1

    You commented "1 stack of dirt"
    When if fact it's actually "A stack of 1 dirt"
     
    JPG2000 and timtower like this.
  17. Offline

    JPG2000

    AndyMcB1 Your correct, but I think people are smart enough to esume that the 1 means 1 dirt.
     
    timtower, calebbfmv and AndyMcB1 like this.
  18. Offline

    calebbfmv

  19. Online

    timtower Administrator Administrator Moderator

    [dirt]
     
    calebbfmv likes this.
  20. Offline

    AndyMcB1

    I was so close to actually explaining that but then realised..
     
    JPG2000, timtower and calebbfmv like this.
  21. Offline

    JPG2000

    timtower Dirt is the thing that hides under your bed at night.
     
  22. Offline

    Mathias Eklund

    Thought it was on my pants, good to know.
     
  23. Offline

    Freelix2000

    Added new file with argument checkers to make it a more stable command.
     

Share This Page