I'm going insane [No errors, I've been trying to get it work all week]

Discussion in 'Plugin Development' started by BrushPainter, Mar 9, 2014.

Thread Status:
Not open for further replies.
  1. Offline

    BrushPainter

    timtower Yeah I think that's exactly what it is because I narrowed even the code that I just posted down to this:
    Code:java
    1. package me.BrushPainter.PBGunShop;
    2.  
    3. import java.util.ArrayList;
    4.  
    5. import org.bukkit.Bukkit;
    6. import org.bukkit.ChatColor;
    7. import org.bukkit.Material;
    8. import org.bukkit.command.Command;
    9. import org.bukkit.command.CommandSender;
    10. import org.bukkit.entity.Entity;
    11. import org.bukkit.entity.EntityType;
    12. import org.bukkit.entity.LivingEntity;
    13. import org.bukkit.entity.Player;
    14. import org.bukkit.entity.Villager;
    15. import org.bukkit.event.EventHandler;
    16. import org.bukkit.event.Listener;
    17. import org.bukkit.event.entity.EntityDamageByEntityEvent;
    18. import org.bukkit.event.inventory.InventoryClickEvent;
    19. import org.bukkit.event.player.PlayerInteractEntityEvent;
    20. import org.bukkit.inventory.Inventory;
    21. import org.bukkit.inventory.ItemStack;
    22. import org.bukkit.inventory.meta.ItemMeta;
    23. import org.bukkit.plugin.PluginManager;
    24. import org.bukkit.plugin.java.JavaPlugin;
    25.  
    26. public class Main extends JavaPlugin implements Listener{
    27.  
    28. public void onEnable() {
    29.  
    30. PluginManager pm = getServer().getPluginManager();
    31. pm.registerEvents(this, this);
    32.  
    33. getLogger().info("PBGunShop Enabled");
    34.  
    35. }
    36.  
    37. public void onDisable() {
    38.  
    39. getLogger().info("PBGunShop Disabled");
    40.  
    41. }
    42. public static Inventory PaintballGunShop = Bukkit.createInventory(null, 9, "Inventory");
    43.  
    44. ArrayList<String> lore = new ArrayList<String>();
    45.  
    46. @EventHandler
    47. public void onInventoryClick(InventoryClickEvent event) {
    48.  
    49. Player player = (Player) event.getWhoClicked();
    50. Player buyer = (Player) event.getWhoClicked();
    51.  
    52. ItemStack clicked = event.getCurrentItem();
    53. Inventory inventory = event.getInventory();
    54. ItemStack is = new ItemStack(Material.WOOL );
    55. is.setDurability((byte) 14);
    56. ItemMeta im = is.getItemMeta();
    57. im.setDisplayName(ChatColor.DARK_RED + "Close");
    58.  
    59. lore.add(ChatColor.DARK_GRAY + "Closes the PB Shop.");
    60. im.setLore(lore);
    61. is.setItemMeta(im);
    62.  
    63. if (inventory.getName().equals(PaintballGunShop.getName())) {
    64. if (clicked.getItemMeta().getDisplayName().equalsIgnoreCase(ChatColor.DARK_RED + "Close")) {
    65.  
    66. event.setCancelled(true);
    67. player.closeInventory();
    68.  
    69. }
    70.  
    71. ItemStack fullyauto = new ItemStack(Material.DIAMOND_BARDING, 1);
    72.  
    73. ItemMeta im1 = fullyauto.getItemMeta();
    74. im1.setDisplayName(ChatColor.AQUA + "" + ChatColor.BOLD + "Fully-Automatic Paintball Gun");
    75. fullyauto.setItemMeta(im1);
    76. lore.add(ChatColor.WHITE + "500 Coins");
    77. im1.setLore(lore);
    78.  
    79. PaintballGunShop.setItem(0,fullyauto);
    80.  
    81. if (inventory.getName().equals(PaintballGunShop.getName())) {
    82.  
    83. if (clicked.getItemMeta().getDisplayName().equalsIgnoreCase(ChatColor.AQUA + "" + ChatColor.BOLD + "Fully-Automatic Paintball Gun")) {
    84.  
    85. event.setCancelled(true);
    86. player.closeInventory();
    87.  
    88. Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "manuaddp " + buyer + " paintballguns.getgun.fullyauto");
    89. Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "manuaddp " + buyer + " -pbgunshop.buy.fullyauto");
    90. Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "eco take " + buyer + " 500");
    91.  
    92. buyer.sendMessage(ChatColor.YELLOW + "Congratulations! You purchased the fully-auto paintball gun!");
    93. buyer.sendMessage(ChatColor.YELLOW + "You can now use /fullyauto to get your gun!");
    94.  
    95. }
    96.  
    97. ItemStack threeburst = new ItemStack(Material.GOLD_BARDING, 1);
    98.  
    99. ItemMeta im2 = fullyauto.getItemMeta();
    100. im2.setDisplayName(ChatColor.GOLD + "" + ChatColor.BOLD + "3-Burst Paintball Gun");
    101. threeburst.setItemMeta(im2);
    102. lore.add(ChatColor.WHITE + "1000 Coins");
    103. im2.setLore(lore);
    104.  
    105. PaintballGunShop.setItem(8,threeburst);
    106.  
    107. if (inventory.getName().equals(PaintballGunShop.getName())) {
    108.  
    109. if (clicked.getItemMeta().getDisplayName().equalsIgnoreCase(ChatColor.GOLD + "" + ChatColor.BOLD + "3-Burst Paintball Gun")) {
    110.  
    111. event.setCancelled(true);
    112. player.closeInventory();
    113.  
    114. Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "manuaddp " + buyer + " paintballguns.getgun.threeburst");
    115. Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "manuaddp " + buyer + " -pbgunshop.buy.threeburst");
    116. Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "eco take " + buyer + " 1000");
    117.  
    118. buyer.sendMessage(ChatColor.YELLOW + "Congratulations! You purchased the three-burst paintball gun!");
    119. buyer.sendMessage(ChatColor.YELLOW + "You can now use /threeburst to get your gun!");
    120. }
    121. }
    122. }
    123. }
    124. }
    125.  
    126. ArrayList<String> Damagers = new ArrayList<String>();
    127.  
    128. @EventHandler
    129. public void onEntityDamage(EntityDamageByEntityEvent event) {
    130.  
    131. Player player = (Player) event.getDamager();
    132. LivingEntity entity = (LivingEntity)event.getEntity();
    133. Villager zinc = (Villager) entity;
    134.  
    135. if (entity.getLastDamageCause().getEntity() instanceof Player) {
    136. event.setCancelled(true);
    137.  
    138. } else if
    139. (zinc.getCustomName() != null && zinc.getCustomName().equals(ChatColor.BLUE + "" + ChatColor.BOLD + "Zinc - The Paintballer")){
    140. event.setCancelled(true);
    141.  
    142. } else {
    143.  
    144. if(Damagers.contains(player.getName())) {
    145. event.setCancelled(true);
    146.  
    147. }
    148. }
    149. }
    150.  
    151. @EventHandler
    152. public void onPlayerInteractEntityEvent(PlayerInteractEntityEvent event) {
    153.  
    154. Entity entity = event.getRightClicked();
    155. Villager zinc = (Villager) entity;
    156. Player player = event.getPlayer();
    157.  
    158. if(zinc.getCustomName() != null && zinc.getCustomName().equals(ChatColor.BLUE + "" + ChatColor.BOLD + "Zinc - The Paintballer")){
    159.  
    160.  
    161. player.openInventory(PaintballGunShop);
    162. }
    163. else{
    164.  
    165. }
    166. }
    167.  
    168. public boolean onCommand(CommandSender sender, Command cmd, String Label, String[] args){
    169.  
    170. if (sender instanceof Player) {
    171. if (sender.hasPermission("pbgunshop.spawn")){
    172. if (cmd.getName().equalsIgnoreCase("spbshop")) {
    173.  
    174. Player p = (Player) sender;
    175.  
    176. p.sendMessage(ChatColor.YELLOW + "You have spawned Zinc, The Paintballer!");
    177.  
    178. p.getWorld().spawnEntity(p.getLocation(), EntityType.VILLAGER);
    179.  
    180. }
    181. }
    182. }
    183. return false;
    184. }
    185. }

    And it still won't spawn! I'm going insane... Can you try testing this on your server if you have one? The only one I have is full of plugins.

    I get a couple of warnings when I try that:
    "Multiple markers at this line
    - The method spawnCreature(Location, EntityType) from the type World is deprecated
    - Line breakpoint:Main [line: 178] - onCommand(CommandSender, Command, String,

    String[])"

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 7, 2016
  2. Offline

    timtower Administrator Administrator Moderator

  3. Offline

    BrushPainter

    timtower Ok no problem, thanks. I'll see if I can make a Hamachi server real quick.
     
  4. Offline

    timtower Administrator Administrator Moderator

    No need for hamachi, just a regular localhost will do with just this plugin.
     
  5. Offline

    GameplayJDK

    BrushPainter
    Is "spawn-npcs=true" in your server config?
     
  6. Offline

    BrushPainter

    GameplayJDK timtower I just got your notifications now, I just made a Hamachi server, lol. Anyway, it works fine in my test server, but when you right click the villager instead of showing the inventory, it shows the usual villager trade screen. Should I try set cancelled on villager right click and then open the inventory?

    EDIT: Nevermind! It works, but the inventory is empty. No items are inside of it for some reason. :O
     
  7. Offline

    GameplayJDK

    BrushPainter
    Listen to PlayerInventoryOpen or however it's called, and cancel it if the InventoryType is equal to TRADE or something.. I'm just thinking aloud, but it should work that way.
     
  8. Offline

    BrushPainter

    GameplayJDK timtower I edited my last post, not sure if you saw, but I fixed that problem, it's just that now the items that I have set for the inventory aren't spawning inside, it's just a empty 9 slot inventory.
     
  9. Offline

    timtower Administrator Administrator Moderator

    BrushPainter You are making an inventory but you aren't setting items in it before any events.
     
  10. Offline

    GameplayJDK

    BrushPainter
    Noticed it just now ^^
    Where are you adding the items into the inventory?
     
  11. Offline

    BrushPainter

    GameplayJDK Slot 0 (The first slot), slot 3 (Middle slot) and slot 8 (Last slot).
    timtower Oh ok so I just have to rearrange my code and put the inventory items below my events?
     
  12. Offline

    timtower Administrator Administrator Moderator

    You need to make it a function, call it in the onEnable and after each event call.
     
  13. Offline

    BrushPainter

    timtower I just don't know what to do. Not sure if this is even what you meant, but I tried, mind helping me out please?
    Code:java
    1. int setItems = PaintballGunShop.setItem(0,threeburst) && PaintballGunShop.setItem(8,fullyauto) && PaintballGunShop.setItem(3,is);
     
  14. Offline

    Rainy37

    This is a function you would call in your onEnable() :

    Code:
    public Inventory PaintballGunShop
    public void newInventory() {
        PaintballGunShop = Bukkit.createInventory(null, 9, "Inventory");
        PaintballGunShop.setItem(0, new ItemStack(Material.APPLE, 1));
        PaintballGunShop.setItem(3, new ItemStack(Material.APPLE, 1));
        PaintballGunShop.setItem(8, new ItemStack(Material.APPLE, 1));
    }
    to call it in your onEnable()
    just do

    Code:
    public void onEnable() {
        newInventory();
    }
     
    timtower and BrushPainter like this.
  15. Offline

    BrushPainter

    Rainy37 Thanks so much man! I really appreciate it! :)

    Rainy37 timtower I'm so sorry guys, I'm seriously so excited I can't even think properly. I've been copying/pasting this code everywhere and I can't find out where to put it because it is a defined item stack.

    Code:java
    1. public void newInventory() {
    2. PaintballGunShop.setItem(0, fullyauto);
    3. PaintballGunShop.setItem(3, cancel);
    4. PaintballGunShop.setItem(8, threeburst);
    5. }
    6.  

    Now here is my full code:
    Code:java
    1. package me.BrushPainter.PBGunShop;
    2.  
    3. import java.util.ArrayList;
    4.  
    5. import org.bukkit.Bukkit;
    6. import org.bukkit.ChatColor;
    7. import org.bukkit.Material;
    8. import org.bukkit.command.Command;
    9. import org.bukkit.command.CommandSender;
    10. import org.bukkit.entity.Entity;
    11. import org.bukkit.entity.EntityType;
    12. import org.bukkit.entity.LivingEntity;
    13. import org.bukkit.entity.Player;
    14. import org.bukkit.entity.Villager;
    15. import org.bukkit.event.EventHandler;
    16. import org.bukkit.event.Listener;
    17. import org.bukkit.event.entity.EntityDamageByEntityEvent;
    18. import org.bukkit.event.inventory.InventoryClickEvent;
    19. import org.bukkit.event.player.PlayerInteractEntityEvent;
    20. import org.bukkit.inventory.Inventory;
    21. import org.bukkit.inventory.ItemStack;
    22. import org.bukkit.inventory.meta.ItemMeta;
    23. import org.bukkit.plugin.PluginManager;
    24. import org.bukkit.plugin.java.JavaPlugin;
    25. import org.bukkit.potion.PotionEffect;
    26. import org.bukkit.potion.PotionEffectType;
    27.  
    28. public class Main extends JavaPlugin implements Listener{
    29.  
    30. public void onEnable() {
    31. newInventory();
    32. PluginManager pm = getServer().getPluginManager();
    33. pm.registerEvents(this, this);
    34.  
    35. getLogger().info("PBGunShop Enabled");
    36.  
    37. }
    38.  
    39. public void onDisable() {
    40.  
    41. getLogger().info("PBGunShop Disabled");
    42.  
    43. }
    44.  
    45. ArrayList<String> Damagers = new ArrayList<String>();
    46.  
    47. @EventHandler
    48. public void onEntityDamage(EntityDamageByEntityEvent event) {
    49.  
    50. Player player = (Player) event.getDamager();
    51. LivingEntity entity = (LivingEntity)event.getEntity();
    52. Villager zinc = (Villager) entity;
    53.  
    54. if (entity.getLastDamageCause().getEntity() instanceof Player) {
    55. event.setCancelled(true);
    56.  
    57. } else if
    58. (zinc.getCustomName() != null && zinc.getCustomName().equals(ChatColor.BLUE + "" + ChatColor.BOLD + "Zinc - The Paintballer")){
    59. event.setCancelled(true);
    60.  
    61. } else {
    62.  
    63. if(Damagers.contains(player.getName())) {
    64. event.setCancelled(true);
    65.  
    66. }
    67. }
    68. }
    69.  
    70. ArrayList<String> lore = new ArrayList<String>();
    71. public static Inventory PaintballGunShop = Bukkit.createInventory(null, 9, "PB Gun Shop");
    72. @EventHandler
    73. public void onPlayerInteractEntityEvent(PlayerInteractEntityEvent event) {
    74.  
    75. Entity entity = event.getRightClicked();
    76. Villager zinc = (Villager) entity;
    77. Player player = event.getPlayer();
    78.  
    79. if(zinc.getCustomName() != null && zinc.getCustomName().equals(ChatColor.BLUE + "" + ChatColor.BOLD + "Zinc - The Paintballer")){
    80.  
    81.  
    82. player.openInventory(PaintballGunShop);
    83. }
    84. else{
    85.  
    86. }
    87. }
    88.  
    89. @EventHandler
    90. public void onInventoryClick(InventoryClickEvent event) {
    91.  
    92. Player player = (Player) event.getWhoClicked();
    93. Player buyer = (Player) event.getWhoClicked();
    94.  
    95. ItemStack clicked = event.getCurrentItem();
    96. Inventory inventory = event.getInventory();
    97. ItemStack is = new ItemStack(Material.WOOL );
    98. is.setDurability((byte) 14);
    99. ItemMeta im = is.getItemMeta();
    100. im.setDisplayName(ChatColor.DARK_RED + "Close");
    101.  
    102. lore.add(ChatColor.DARK_GRAY + "Closes the PB Shop.");
    103. im.setLore(lore);
    104. is.setItemMeta(im);
    105.  
    106. if (inventory.getName().equals(PaintballGunShop.getName())) {
    107. if (clicked.getItemMeta().getDisplayName().equalsIgnoreCase(ChatColor.DARK_RED + "Close")) {
    108.  
    109. event.setCancelled(true);
    110. player.closeInventory();
    111.  
    112. }
    113.  
    114. ItemStack fullyauto = new ItemStack(Material.DIAMOND_BARDING, 1);
    115.  
    116. ItemMeta im1 = fullyauto.getItemMeta();
    117. im1.setDisplayName(ChatColor.AQUA + "" + ChatColor.BOLD + "Fully-Automatic Paintball Gun");
    118. fullyauto.setItemMeta(im1);
    119. lore.add(ChatColor.GRAY + "500 Coins");
    120. im1.setLore(lore);
    121.  
    122. PaintballGunShop.setItem(0,fullyauto);
    123.  
    124. if (inventory.getName().equals(PaintballGunShop.getName())) {
    125.  
    126. if (clicked.getItemMeta().getDisplayName().equalsIgnoreCase(ChatColor.AQUA + "" + ChatColor.BOLD + "Fully-Automatic Paintball Gun")) {
    127.  
    128. event.setCancelled(true);
    129. player.closeInventory();
    130.  
    131. Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "manuaddp " + buyer + " paintballguns.getgun.fullyauto");
    132. Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "manuaddp " + buyer + " -pbgunshop.buy.fullyauto");
    133. Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "eco take " + buyer + " 500");
    134.  
    135. buyer.sendMessage(ChatColor.YELLOW + "Congratulations! You purchased the fully-auto paintball gun!");
    136. buyer.sendMessage(ChatColor.YELLOW + "You can now use /fullyauto to get your gun!");
    137.  
    138. }
    139.  
    140. ItemStack threeburst = new ItemStack(Material.GOLD_BARDING, 1);
    141.  
    142. ItemMeta im2 = fullyauto.getItemMeta();
    143. im2.setDisplayName(ChatColor.GOLD + "" + ChatColor.BOLD + "3-Burst Paintball Gun");
    144. threeburst.setItemMeta(im2);
    145. lore.add(ChatColor.GRAY + "1000 Coins");
    146. im2.setLore(lore);
    147.  
    148. PaintballGunShop.setItem(8,threeburst);
    149.  
    150. if (inventory.getName().equals(PaintballGunShop.getName())) {
    151.  
    152. if (clicked.getItemMeta().getDisplayName().equalsIgnoreCase(ChatColor.GOLD + "" + ChatColor.BOLD + "3-Burst Paintball Gun")) {
    153.  
    154. event.setCancelled(true);
    155. player.closeInventory();
    156.  
    157. Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "manuaddp " + buyer + " paintballguns.getgun.threeburst");
    158. Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "manuaddp " + buyer + " -pbgunshop.buy.threeburst");
    159. Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "eco take " + buyer + " 1000");
    160.  
    161. buyer.sendMessage(ChatColor.YELLOW + "Congratulations! You purchased the three-burst paintball gun!");
    162. buyer.sendMessage(ChatColor.YELLOW + "You can now use /threeburst to get your gun!");
    163. }
    164. }
    165. }
    166. }
    167. }
    168.  
    169. public boolean onCommand(CommandSender sender, Command cmd, String Label, String[] args){
    170.  
    171. if (sender instanceof Player) {
    172. if (sender.hasPermission("pbgunshop.spawn")){
    173. if (cmd.getName().equalsIgnoreCase("spbshop")) {
    174.  
    175. Player p = (Player) sender;
    176.  
    177. p.sendMessage(ChatColor.YELLOW + "You have spawned Zinc, The Paintballer!");
    178.  
    179. Villager v = (Villager) p.getWorld().spawnEntity(p.getLocation(), EntityType.VILLAGER);
    180.  
    181. v.setBaby();
    182.  
    183. v.addPotionEffect(new PotionEffect(PotionEffectType.SLOW, Integer.MAX_VALUE, 6));
    184. v.addPotionEffect(new PotionEffect(PotionEffectType.JUMP, Integer.MAX_VALUE, -6));
    185. v.setMaxHealth(12000000);
    186. v.setHealth(12000000);
    187.  
    188. v.setCustomName(ChatColor.BLUE + "" + ChatColor.BOLD + "Zinc - The Paintballer");
    189. v.setCustomNameVisible(true);
    190.  
    191. v.getEquipment().getItemInHand().setType(Material.GOLD_BARDING);
    192. return true;
    193.  
    194. }
    195. }
    196. }
    197. return false;
    198. }
    199. }


    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 7, 2016
  16. Offline

    timtower Administrator Administrator Moderator

    BrushPainter But it is global defined, just put it below the onEnable
     
  17. Offline

    BrushPainter

    timtower I just tried that too, I get this ItemStacks name + "cannot be resolved to a
    variable"
     
  18. Offline

    timtower Administrator Administrator Moderator

    BrushPainter You also need to move the things where you create the item itself. If not working: post updated code
     
  19. Offline

    Rainy37

    Before I begin, make sure your remove your other ItemMeta edits after you finish this
    I will give an example for the threeburst, try doing it for the other guns the same way

    Code:
    public ItemStack threeburst = new ItemStack(Material.GOLD_BARDING, 1);
    public void newInventory() {
       
        PaintballGunShop = Bukkit.createInventory(null, 9, "Inventory");
        ItemMeta threeburstMeta = threeburst.getItemMeta();
        //set your ItemMeta stuff here
        threeburst.setItemMeta(threeburstMeta);
        PaintballGunShop.setItem(0, threeburst);
        PaintballGunShop.setItem(3, new ItemStack(Material.APPLE, 1));
        PaintballGunShop.setItem(8, new ItemStack(Material.APPLE, 1));
    }
     
  20. Offline

    BrushPainter

    timtower I feel like soon I'm just going to give up on this plugin, even though I'm so close, I just can't think properly and everything I do, I get errors... :( Here it is though
    Code:java
    1. package me.BrushPainter.PBGunShop;
    2.  
    3. import java.util.ArrayList;
    4.  
    5. import org.bukkit.Bukkit;
    6. import org.bukkit.ChatColor;
    7. import org.bukkit.Material;
    8. import org.bukkit.command.Command;
    9. import org.bukkit.command.CommandSender;
    10. import org.bukkit.entity.Entity;
    11. import org.bukkit.entity.EntityType;
    12. import org.bukkit.entity.LivingEntity;
    13. import org.bukkit.entity.Player;
    14. import org.bukkit.entity.Villager;
    15. import org.bukkit.event.EventHandler;
    16. import org.bukkit.event.Listener;
    17. import org.bukkit.event.entity.EntityDamageByEntityEvent;
    18. import org.bukkit.event.inventory.InventoryClickEvent;
    19. import org.bukkit.event.player.PlayerInteractEntityEvent;
    20. import org.bukkit.inventory.Inventory;
    21. import org.bukkit.inventory.ItemStack;
    22. import org.bukkit.inventory.meta.ItemMeta;
    23. import org.bukkit.plugin.PluginManager;
    24. import org.bukkit.plugin.java.JavaPlugin;
    25. import org.bukkit.potion.PotionEffect;
    26. import org.bukkit.potion.PotionEffectType;
    27.  
    28. public class Main extends JavaPlugin implements Listener{
    29.  
    30. public void onEnable() {
    31. newInventory();
    32. PluginManager pm = getServer().getPluginManager();
    33. pm.registerEvents(this, this);
    34.  
    35. getLogger().info("PBGunShop Enabled");
    36.  
    37. }
    38.  
    39. public void onDisable() {
    40.  
    41. getLogger().info("PBGunShop Disabled");
    42.  
    43. }
    44.  
    45. public void newInventory() {
    46.  
    47. PaintballGunShop.setItem(0, fullyauto);
    48. PaintballGunShop.setItem(3, cancel);
    49. PaintballGunShop.setItem(8, threeburst);
    50.  
    51. }
    52.  
    53.  
    54. ArrayList<String> Damagers = new ArrayList<String>();
    55.  
    56. @EventHandler
    57. public void onEntityDamage(EntityDamageByEntityEvent event) {
    58.  
    59. Player player = (Player) event.getDamager();
    60. LivingEntity entity = (LivingEntity)event.getEntity();
    61. Villager zinc = (Villager) entity;
    62.  
    63. if (entity.getLastDamageCause().getEntity() instanceof Player) {
    64. event.setCancelled(true);
    65.  
    66. } else if
    67. (zinc.getCustomName() != null && zinc.getCustomName().equals(ChatColor.BLUE + "" + ChatColor.BOLD + "Zinc - The Paintballer")){
    68. event.setCancelled(true);
    69.  
    70. } else {
    71.  
    72. if(Damagers.contains(player.getName())) {
    73. event.setCancelled(true);
    74.  
    75. }
    76. }
    77. }
    78.  
    79. ArrayList<String> lore = new ArrayList<String>();
    80. public static Inventory PaintballGunShop = Bukkit.createInventory(null, 9, "PB Gun Shop");
    81. @EventHandler
    82. public void onPlayerInteractEntityEvent(PlayerInteractEntityEvent event) {
    83.  
    84. Entity entity = event.getRightClicked();
    85. Villager zinc = (Villager) entity;
    86. Player player = event.getPlayer();
    87.  
    88. if(zinc.getCustomName() != null && zinc.getCustomName().equals(ChatColor.BLUE + "" + ChatColor.BOLD + "Zinc - The Paintballer")){
    89.  
    90. player.openInventory(PaintballGunShop);
    91. }
    92. else{
    93.  
    94. }
    95. }
    96.  
    97. @EventHandler
    98. public void onInventoryClick(InventoryClickEvent event) {
    99.  
    100. Player player = (Player) event.getWhoClicked();
    101. Player buyer = (Player) event.getWhoClicked();
    102.  
    103. ItemStack clicked = event.getCurrentItem();
    104. Inventory inventory = event.getInventory();
    105. ItemStack is = new ItemStack(Material.WOOL );
    106. is.setDurability((byte) 14);
    107. ItemMeta im = is.getItemMeta();
    108. im.setDisplayName(ChatColor.DARK_RED + "Close");
    109.  
    110. lore.add(ChatColor.DARK_GRAY + "Closes the PB Shop.");
    111. im.setLore(lore);
    112. is.setItemMeta(im);
    113.  
    114. if (inventory.getName().equals(PaintballGunShop.getName())) {
    115. if (clicked.getItemMeta().getDisplayName().equalsIgnoreCase(ChatColor.DARK_RED + "Close")) {
    116.  
    117. event.setCancelled(true);
    118. player.closeInventory();
    119.  
    120. }
    121.  
    122. ItemStack fullyauto = new ItemStack(Material.DIAMOND_BARDING, 1);
    123.  
    124. ItemMeta im1 = fullyauto.getItemMeta();
    125. im1.setDisplayName(ChatColor.AQUA + "" + ChatColor.BOLD + "Fully-Automatic Paintball Gun");
    126. fullyauto.setItemMeta(im1);
    127. lore.add(ChatColor.GRAY + "500 Coins");
    128. im1.setLore(lore);
    129.  
    130. PaintballGunShop.setItem(0,fullyauto);
    131.  
    132. if (inventory.getName().equals(PaintballGunShop.getName())) {
    133.  
    134. if (clicked.getItemMeta().getDisplayName().equalsIgnoreCase(ChatColor.AQUA + "" + ChatColor.BOLD + "Fully-Automatic Paintball Gun")) {
    135.  
    136. event.setCancelled(true);
    137. player.closeInventory();
    138.  
    139. Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "manuaddp " + buyer + " paintballguns.getgun.fullyauto");
    140. Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "manuaddp " + buyer + " -pbgunshop.buy.fullyauto");
    141. Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "eco take " + buyer + " 500");
    142.  
    143. buyer.sendMessage(ChatColor.YELLOW + "Congratulations! You purchased the fully-auto paintball gun!");
    144. buyer.sendMessage(ChatColor.YELLOW + "You can now use /fullyauto to get your gun!");
    145. }
    146. else {
    147. buyer.sendMessage(ChatColor.RED + "Sorry, you do not have enough money to purchase this gun.");
    148. }
    149. }
    150.  
    151. ItemStack threeburst = new ItemStack(Material.GOLD_BARDING, 1);
    152.  
    153. ItemMeta im2 = fullyauto.getItemMeta();
    154. im2.setDisplayName(ChatColor.GOLD + "" + ChatColor.BOLD + "3-Burst Paintball Gun");
    155. threeburst.setItemMeta(im2);
    156. lore.add(ChatColor.GRAY + "1000 Coins");
    157. im2.setLore(lore);
    158.  
    159. PaintballGunShop.setItem(8,threeburst);
    160.  
    161. if (inventory.getName().equals(PaintballGunShop.getName())) {
    162.  
    163. if (clicked.getItemMeta().getDisplayName().equalsIgnoreCase(ChatColor.GOLD + "" + ChatColor.BOLD + "3-Burst Paintball Gun")) {
    164.  
    165. event.setCancelled(true);
    166. player.closeInventory();
    167.  
    168. Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "manuaddp " + buyer + " paintballguns.getgun.threeburst");
    169. Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "manuaddp " + buyer + " -pbgunshop.buy.threeburst");
    170. Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "eco take " + buyer + " 1000");
    171.  
    172. buyer.sendMessage(ChatColor.YELLOW + "Congratulations! You purchased the three-burst paintball gun!");
    173. buyer.sendMessage(ChatColor.YELLOW + "You can now use /threeburst to get your gun!");
    174. }
    175. }
    176. }
    177. }
    178.  
    179. public boolean onCommand(CommandSender sender, Command cmd, String Label, String[] args){
    180.  
    181. if (sender instanceof Player) {
    182. if (sender.hasPermission("pbgunshop.spawn")){
    183. if (cmd.getName().equalsIgnoreCase("spbshop")) {
    184.  
    185. Player p = (Player) sender;
    186.  
    187. p.sendMessage(ChatColor.YELLOW + "You have spawned Zinc, The Paintballer!");
    188.  
    189. Villager v = (Villager) p.getWorld().spawnEntity(p.getLocation(), EntityType.VILLAGER);
    190.  
    191. v.setBaby();
    192.  
    193. v.addPotionEffect(new PotionEffect(PotionEffectType.SLOW, Integer.MAX_VALUE, 6));
    194. v.addPotionEffect(new PotionEffect(PotionEffectType.JUMP, Integer.MAX_VALUE, -6));
    195. v.setMaxHealth(12000000);
    196. v.setHealth(12000000);
    197.  
    198. v.setCustomName(ChatColor.BLUE + "" + ChatColor.BOLD + "Zinc - The Paintballer");
    199. v.setCustomNameVisible(true);
    200. return true;
    201.  
    202. }
    203. }
    204. }
    205. return false;
    206. }
    207. }
     
  21. Offline

    GameplayJDK

    BrushPainter
    here you go:
    Code:java
    1. package me.BrushPainter.PBGunShop;
    2.  
    3. import java.util.ArrayList;
    4.  
    5. import org.bukkit.Bukkit;
    6. import org.bukkit.ChatColor;
    7. import org.bukkit.Material;
    8. import org.bukkit.command.Command;
    9. import org.bukkit.command.CommandSender;
    10. import org.bukkit.entity.Entity;
    11. import org.bukkit.entity.EntityType;
    12. import org.bukkit.entity.LivingEntity;
    13. import org.bukkit.entity.Player;
    14. import org.bukkit.entity.Villager;
    15. import org.bukkit.event.EventHandler;
    16. import org.bukkit.event.Listener;
    17. import org.bukkit.event.entity.EntityDamageByEntityEvent;
    18. import org.bukkit.event.inventory.InventoryClickEvent;
    19. import org.bukkit.event.player.PlayerInteractEntityEvent;
    20. import org.bukkit.inventory.Inventory;
    21. import org.bukkit.inventory.ItemStack;
    22. import org.bukkit.inventory.meta.ItemMeta;
    23. import org.bukkit.plugin.PluginManager;
    24. import org.bukkit.plugin.java.JavaPlugin;
    25. import org.bukkit.potion.PotionEffect;
    26. import org.bukkit.potion.PotionEffectType;
    27.  
    28. public class Main extends JavaPlugin implements Listener{
    29.  
    30. public void onEnable() {
    31. newInventory();
    32. PluginManager pm = getServer().getPluginManager();
    33. pm.registerEvents(this, this);
    34.  
    35. getLogger().info("PBGunShop Enabled");
    36.  
    37. }
    38.  
    39. // Paste here:
    40. ItemStack fullyauto;
    41.  
    42. public Inventory paintballGunShop;
    43. ItemStack threeburst; // add the cancel item here and down there \/
    44. public void newInventory() {
    45. fullyauto = new ItemStack(Material.DIAMOND_BARDING, 1);
    46. threeburst = new ItemStack(Material.GOLD_BARDING, 1);
    47. // putting items into inventory slots...
    48. }
    49.  
    50. public void onDisable() {
    51.  
    52. getLogger().info("PBGunShop Disabled");
    53.  
    54. }
    55.  
    56. ArrayList<String> Damagers = new ArrayList<String>();
    57.  
    58. @EventHandler
    59. public void onEntityDamage(EntityDamageByEntityEvent event) {
    60.  
    61. Player player = (Player) event.getDamager();
    62. LivingEntity entity = (LivingEntity)event.getEntity();
    63. Villager zinc = (Villager) entity;
    64.  
    65. if (entity.getLastDamageCause().getEntity() instanceof Player) {
    66. event.setCancelled(true);
    67.  
    68. } else if
    69. (zinc.getCustomName() != null && zinc.getCustomName().equals(ChatColor.BLUE + "" + ChatColor.BOLD + "Zinc - The Paintballer")){
    70. event.setCancelled(true);
    71.  
    72. } else {
    73.  
    74. if(Damagers.contains(player.getName())) {
    75. event.setCancelled(true);
    76.  
    77. }
    78. }
    79. }
    80.  
    81. ArrayList<String> lore = new ArrayList<String>();
    82. public static Inventory PaintballGunShop = Bukkit.createInventory(null, 9, "PB Gun Shop");
    83. @EventHandler
    84. public void onPlayerInteractEntityEvent(PlayerInteractEntityEvent event) {
    85.  
    86. Entity entity = event.getRightClicked();
    87. Villager zinc = (Villager) entity;
    88. Player player = event.getPlayer();
    89.  
    90. if(zinc.getCustomName() != null && zinc.getCustomName().equals(ChatColor.BLUE + "" + ChatColor.BOLD + "Zinc - The Paintballer")){
    91.  
    92.  
    93. player.openInventory(PaintballGunShop);
    94. }
    95. else{
    96.  
    97. }
    98. }
    99.  
    100. @EventHandler
    101. public void onInventoryClick(InventoryClickEvent event) {
    102.  
    103. Player player = (Player) event.getWhoClicked();
    104. Player buyer = (Player) event.getWhoClicked();
    105.  
    106. ItemStack clicked = event.getCurrentItem();
    107. Inventory inventory = event.getInventory();
    108. ItemStack is = new ItemStack(Material.WOOL );
    109. is.setDurability((byte) 14);
    110. ItemMeta im = is.getItemMeta();
    111. im.setDisplayName(ChatColor.DARK_RED + "Close");
    112.  
    113. lore.add(ChatColor.DARK_GRAY + "Closes the PB Shop.");
    114. im.setLore(lore);
    115. is.setItemMeta(im);
    116.  
    117. if (inventory.getName().equals(PaintballGunShop.getName())) {
    118. if (clicked.getItemMeta().getDisplayName().equalsIgnoreCase(ChatColor.DARK_RED + "Close")) {
    119.  
    120. event.setCancelled(true);
    121. player.closeInventory();
    122.  
    123. }
    124.  
    125. ItemStack fullyauto = new ItemStack(Material.DIAMOND_BARDING, 1);
    126.  
    127. ItemMeta im1 = fullyauto.getItemMeta();
    128. im1.setDisplayName(ChatColor.AQUA + "" + ChatColor.BOLD + "Fully-Automatic Paintball Gun");
    129. fullyauto.setItemMeta(im1);
    130. lore.add(ChatColor.GRAY + "500 Coins");
    131. im1.setLore(lore);
    132.  
    133. PaintballGunShop.setItem(0,fullyauto);
    134.  
    135. if (inventory.getName().equals(PaintballGunShop.getName())) {
    136.  
    137. if (clicked.getItemMeta().getDisplayName().equalsIgnoreCase(ChatColor.AQUA + "" + ChatColor.BOLD + "Fully-Automatic Paintball Gun")) {
    138.  
    139. event.setCancelled(true);
    140. player.closeInventory();
    141.  
    142. Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "manuaddp " + buyer + " paintballguns.getgun.fullyauto");
    143. Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "manuaddp " + buyer + " -pbgunshop.buy.fullyauto");
    144. Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "eco take " + buyer + " 500");
    145.  
    146. buyer.sendMessage(ChatColor.YELLOW + "Congratulations! You purchased the fully-auto paintball gun!");
    147. buyer.sendMessage(ChatColor.YELLOW + "You can now use /fullyauto to get your gun!");
    148.  
    149. }
    150.  
    151. ItemStack threeburst = new ItemStack(Material.GOLD_BARDING, 1);
    152.  
    153. ItemMeta im2 = fullyauto.getItemMeta();
    154. im2.setDisplayName(ChatColor.GOLD + "" + ChatColor.BOLD + "3-Burst Paintball Gun");
    155. threeburst.setItemMeta(im2);
    156. lore.add(ChatColor.GRAY + "1000 Coins");
    157. im2.setLore(lore);
    158.  
    159. PaintballGunShop.setItem(8,threeburst);
    160.  
    161. if (inventory.getName().equals(PaintballGunShop.getName())) {
    162.  
    163. if (clicked.getItemMeta().getDisplayName().equalsIgnoreCase(ChatColor.GOLD + "" + ChatColor.BOLD + "3-Burst Paintball Gun")) {
    164.  
    165. event.setCancelled(true);
    166. player.closeInventory();
    167.  
    168. Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "manuaddp " + buyer + " paintballguns.getgun.threeburst");
    169. Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "manuaddp " + buyer + " -pbgunshop.buy.threeburst");
    170. Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "eco take " + buyer + " 1000");
    171.  
    172. buyer.sendMessage(ChatColor.YELLOW + "Congratulations! You purchased the three-burst paintball gun!");
    173. buyer.sendMessage(ChatColor.YELLOW + "You can now use /threeburst to get your gun!");
    174. }
    175. }
    176. }
    177. }
    178. }
    179.  
    180. public boolean onCommand(CommandSender sender, Command cmd, String Label, String[] args){
    181.  
    182. if (sender instanceof Player) {
    183. if (sender.hasPermission("pbgunshop.spawn")){
    184. if (cmd.getName().equalsIgnoreCase("spbshop")) {
    185.  
    186. Player p = (Player) sender;
    187.  
    188. p.sendMessage(ChatColor.YELLOW + "You have spawned Zinc, The Paintballer!");
    189.  
    190. Villager v = (Villager) p.getWorld().spawnEntity(p.getLocation(), EntityType.VILLAGER);
    191.  
    192. v.setBaby();
    193.  
    194. v.addPotionEffect(new PotionEffect(PotionEffectType.SLOW, Integer.MAX_VALUE, 6));
    195. v.addPotionEffect(new PotionEffect(PotionEffectType.JUMP, Integer.MAX_VALUE, -6));
    196. v.setMaxHealth(12000000);
    197. v.setHealth(12000000);
    198.  
    199. v.setCustomName(ChatColor.BLUE + "" + ChatColor.BOLD + "Zinc - The Paintballer");
    200. v.setCustomNameVisible(true);
    201.  
    202. v.getEquipment().getItemInHand().setType(Material.GOLD_BARDING);
    203. return true;
    204.  
    205. }
    206. }
    207. }
    208. return false;
    209. }
    210. }
     
  22. Offline

    BrushPainter

    GameplayJDK Thank you so much! It works!!! I'm going to edit it now. :D
     
  23. Offline

    GameplayJDK

  24. Offline

    timtower Administrator Administrator Moderator

    BrushPainter
    Code:java
    1. package me.BrushPainter.PBGunShop;
    2.  
    3. import java.util.ArrayList;
    4.  
    5. import org.bukkit.Bukkit;
    6. import org.bukkit.ChatColor;
    7. import org.bukkit.Material;
    8. import org.bukkit.command.Command;
    9. import org.bukkit.command.CommandSender;
    10. import org.bukkit.entity.Entity;
    11. import org.bukkit.entity.EntityType;
    12. import org.bukkit.entity.LivingEntity;
    13. import org.bukkit.entity.Player;
    14. import org.bukkit.entity.Villager;
    15. import org.bukkit.event.EventHandler;
    16. import org.bukkit.event.Listener;
    17. import org.bukkit.event.entity.EntityDamageByEntityEvent;
    18. import org.bukkit.event.inventory.InventoryClickEvent;
    19. import org.bukkit.event.player.PlayerInteractEntityEvent;
    20. import org.bukkit.inventory.Inventory;
    21. import org.bukkit.inventory.ItemStack;
    22. import org.bukkit.inventory.meta.ItemMeta;
    23. import org.bukkit.plugin.PluginManager;
    24. import org.bukkit.plugin.java.JavaPlugin;
    25. import org.bukkit.potion.PotionEffect;
    26. import org.bukkit.potion.PotionEffectType;
    27.  
    28. public class Main extends JavaPlugin implements Listener{
    29. ArrayList<String> lore = new ArrayList<String>();
    30. public static Inventory PaintballGunShop = Bukkit.createInventory(null, 9, "PB Gun Shop");
    31. ArrayList<String> Damagers = new ArrayList<String>();
    32.  
    33. public void onEnable() {
    34. newInventory();
    35. PluginManager pm = getServer().getPluginManager();
    36. pm.registerEvents(this, this);
    37.  
    38. getLogger().info("PBGunShop Enabled");
    39.  
    40. }
    41.  
    42. public void onDisable() {
    43.  
    44. getLogger().info("PBGunShop Disabled");
    45.  
    46. }
    47.  
    48. public void newInventory() {
    49. ItemStack fullyauto = new ItemStack(Material.DIAMOND_BARDING, 1);
    50. ItemMeta im1 = fullyauto.getItemMeta();
    51. im1.setDisplayName(ChatColor.AQUA + "" + ChatColor.BOLD + "Fully-Automatic Paintball Gun");
    52. fullyauto.setItemMeta(im1);
    53. lore.add(ChatColor.GRAY + "500 Coins");
    54. im1.setLore(lore);
    55.  
    56. ItemStack threeburst = new ItemStack(Material.GOLD_BARDING, 1);
    57. ItemMeta im2 = fullyauto.getItemMeta();
    58. im2.setDisplayName(ChatColor.GOLD + "" + ChatColor.BOLD + "3-Burst Paintball Gun");
    59. threeburst.setItemMeta(im2);
    60. lore.add(ChatColor.GRAY + "1000 Coins");
    61. im2.setLore(lore);
    62.  
    63. ItemStack cancel = new ItemStack(Material.WOOL );
    64. cancel.setDurability((byte) 14);
    65. ItemMeta im = cancel.getItemMeta();
    66. im.setDisplayName(ChatColor.DARK_RED + "Close");
    67. lore.add(ChatColor.DARK_GRAY + "Closes the PB Shop.");
    68. im.setLore(lore);
    69. cancel.setItemMeta(im);
    70.  
    71. PaintballGunShop.setItem(0, fullyauto);
    72. PaintballGunShop.setItem(3, cancel);
    73. PaintballGunShop.setItem(8, threeburst);
    74.  
    75. }
    76.  
    77. @EventHandler
    78. public void onEntityDamage(EntityDamageByEntityEvent event) {
    79.  
    80. Player player = (Player) event.getDamager();
    81. LivingEntity entity = (LivingEntity)event.getEntity();
    82. Villager zinc = (Villager) entity;
    83.  
    84. if (entity.getLastDamageCause().getEntity() instanceof Player) {
    85. event.setCancelled(true);
    86. } else if(zinc.getCustomName() != null && zinc.getCustomName().equals(ChatColor.BLUE + "" + ChatColor.BOLD + "Zinc - The Paintballer")){
    87. event.setCancelled(true);
    88. } else {
    89. if(Damagers.contains(player.getName())) {
    90. event.setCancelled(true);
    91. }
    92. }
    93. }
    94.  
    95.  
    96. @EventHandler
    97. public void onPlayerInteractEntityEvent(PlayerInteractEntityEvent event) {
    98. Entity entity = event.getRightClicked();
    99. Villager zinc = (Villager) entity;
    100. Player player = event.getPlayer();
    101. if(zinc.getCustomName() != null && zinc.getCustomName().equals(ChatColor.BLUE + "" + ChatColor.BOLD + "Zinc - The Paintballer")){
    102. player.openInventory(PaintballGunShop);
    103. }
    104. }
    105.  
    106. @EventHandler
    107. public void onInventoryClick(InventoryClickEvent event) {
    108.  
    109. Player player = (Player) event.getWhoClicked();
    110. Player buyer = (Player) event.getWhoClicked();
    111.  
    112. ItemStack clicked = event.getCurrentItem();
    113. Inventory inventory = event.getInventory();
    114.  
    115. if (inventory.getName().equals(PaintballGunShop.getName())) {
    116. if (clicked.getItemMeta().getDisplayName().equalsIgnoreCase(ChatColor.DARK_RED + "Close")) {
    117. event.setCancelled(true);
    118. player.closeInventory();
    119. }
    120. if (inventory.getName().equals(PaintballGunShop.getName())) {
    121. if (clicked.getItemMeta().getDisplayName().equalsIgnoreCase(ChatColor.AQUA + "" + ChatColor.BOLD + "Fully-Automatic Paintball Gun")) {
    122. event.setCancelled(true);
    123. player.closeInventory();
    124. Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "manuaddp " + buyer + " paintballguns.getgun.fullyauto");
    125. Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "manuaddp " + buyer + " -pbgunshop.buy.fullyauto");
    126. Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "eco take " + buyer + " 500");
    127. buyer.sendMessage(ChatColor.YELLOW + "Congratulations! You purchased the fully-auto paintball gun!");
    128. buyer.sendMessage(ChatColor.YELLOW + "You can now use /fullyauto to get your gun!");
    129. }else {
    130. buyer.sendMessage(ChatColor.RED + "Sorry, you do not have enough money to purchase this gun.");
    131. }
    132. }
    133. if (inventory.getName().equals(PaintballGunShop.getName())) {
    134. if (clicked.getItemMeta().getDisplayName().equalsIgnoreCase(ChatColor.GOLD + "" + ChatColor.BOLD + "3-Burst Paintball Gun")) {
    135. event.setCancelled(true);
    136. player.closeInventory();
    137. Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "manuaddp " + buyer + " paintballguns.getgun.threeburst");
    138. Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "manuaddp " + buyer + " -pbgunshop.buy.threeburst");
    139. Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "eco take " + buyer + " 1000");
    140.  
    141. buyer.sendMessage(ChatColor.YELLOW + "Congratulations! You purchased the three-burst paintball gun!");
    142. buyer.sendMessage(ChatColor.YELLOW + "You can now use /threeburst to get your gun!");
    143. }
    144. }
    145. }
    146. }
    147.  
    148. public boolean onCommand(CommandSender sender, Command cmd, String Label, String[] args){
    149.  
    150. if (sender instanceof Player) {
    151. if (sender.hasPermission("pbgunshop.spawn")){
    152. if (cmd.getName().equalsIgnoreCase("spbshop")) {
    153.  
    154. Player p = (Player) sender;
    155.  
    156. p.sendMessage(ChatColor.YELLOW + "You have spawned Zinc, The Paintballer!");
    157.  
    158. Villager v = (Villager) p.getWorld().spawnEntity(p.getLocation(), EntityType.VILLAGER);
    159.  
    160. v.setBaby();
    161.  
    162. v.addPotionEffect(new PotionEffect(PotionEffectType.SLOW, Integer.MAX_VALUE, 6));
    163. v.addPotionEffect(new PotionEffect(PotionEffectType.JUMP, Integer.MAX_VALUE, -6));
    164. v.setMaxHealth(12000000);
    165. v.setHealth(12000000);
    166.  
    167. v.setCustomName(ChatColor.BLUE + "" + ChatColor.BOLD + "Zinc - The Paintballer");
    168. v.setCustomNameVisible(true);
    169. return true;
    170.  
    171. }
    172. }
    173. }
    174. return false;
    175. }
    176. }
     
  25. Offline

    GameplayJDK

    BrushPainter
    The code of timtower is more detailed, so try it.
    timtower
    But the itemstacks should be defined globally, so the can be used everywhere in the class.
     
  26. Offline

    timtower Administrator Administrator Moderator

    He wasn't using them already and he could get them from the inventory
     
  27. Offline

    GameplayJDK

    timtower
    That's also a possibility..
     
  28. Offline

    BrushPainter

    GameplayJDK timtower Rainy37 They both work exactly how I wanted them to. :D I seriously can't thank you guys enough for all of your help, you've been awesome! :) I just had to change a minor lore error.
     
    Rainy37 and timtower like this.
  29. Offline

    GameplayJDK

    BrushPainter likes this.
  30. Offline

    BrushPainter

    GameplayJDK timtower Rainy37 Do you guys know why this isn't working? All I changed was I added 2 more items, one on row 6 and one on row 2 just to let the player know how much each paintball gun costs because the lore wasn't working on horse armor. It still lets me spawn the villager, but when I right click it nothing happens. Here's my new code:
    Code:java
    1. package me.BrushPainter.PBGunShop;
    2.  
    3. import java.util.ArrayList;
    4.  
    5. import org.bukkit.Bukkit;
    6. import org.bukkit.ChatColor;
    7. import org.bukkit.Material;
    8. import org.bukkit.command.Command;
    9. import org.bukkit.command.CommandSender;
    10. import org.bukkit.entity.Entity;
    11. import org.bukkit.entity.EntityType;
    12. import org.bukkit.entity.LivingEntity;
    13. import org.bukkit.entity.Player;
    14. import org.bukkit.entity.Villager;
    15. import org.bukkit.event.EventHandler;
    16. import org.bukkit.event.Listener;
    17. import org.bukkit.event.entity.EntityDamageByEntityEvent;
    18. import org.bukkit.event.inventory.InventoryClickEvent;
    19. import org.bukkit.event.player.PlayerInteractEntityEvent;
    20. import org.bukkit.inventory.Inventory;
    21. import org.bukkit.inventory.ItemStack;
    22. import org.bukkit.inventory.meta.ItemMeta;
    23. import org.bukkit.plugin.PluginManager;
    24. import org.bukkit.plugin.java.JavaPlugin;
    25. import org.bukkit.potion.PotionEffect;
    26. import org.bukkit.potion.PotionEffectType;
    27.  
    28. public class Main extends JavaPlugin implements Listener{
    29.  
    30. public void onEnable() {
    31. newInventory();
    32. PluginManager pm = getServer().getPluginManager();
    33. pm.registerEvents(this, this);
    34.  
    35. getLogger().info("PBGunShop Enabled");
    36.  
    37. }
    38.  
    39. ItemStack fullyauto;
    40. ItemStack threeburst;
    41. ItemStack cancel;
    42. ItemStack faprice;
    43. ItemStack tbprice;
    44.  
    45. public Inventory paintballGunShop;
    46. public void newInventory() {
    47.  
    48. faprice = new ItemStack(Material.BOOK, 1);
    49. ItemMeta imfa = fullyauto.getItemMeta();
    50. imfa.setDisplayName(ChatColor.GRAY + "Price: 500");
    51. fullyauto.setItemMeta(imfa);
    52.  
    53. tbprice = new ItemStack(Material.BOOK, 1);
    54. ItemMeta imtb = threeburst.getItemMeta();
    55. imtb.setDisplayName(ChatColor.GRAY + "Price: 1000");
    56. threeburst.setItemMeta(imtb);
    57.  
    58. fullyauto = new ItemStack(Material.DIAMOND_BARDING, 1);
    59. ItemMeta im1 = fullyauto.getItemMeta();
    60. im1.setDisplayName(ChatColor.AQUA + "" + ChatColor.BOLD + "Fully-Automatic Paintball Gun");
    61. fullyauto.setItemMeta(im1);
    62.  
    63. threeburst = new ItemStack(Material.GOLD_BARDING, 1);
    64. ItemMeta im2 = fullyauto.getItemMeta();
    65. im2.setDisplayName(ChatColor.GOLD + "" + ChatColor.BOLD + "3-Burst Paintball Gun");
    66. threeburst.setItemMeta(im2);
    67.  
    68. cancel = new ItemStack(Material.WOOL);
    69. ItemMeta im3 = cancel.getItemMeta();
    70. im3.setDisplayName(ChatColor.DARK_RED + "Close");
    71. lore3.add(ChatColor.DARK_GRAY + "Closes the PB Shop.");
    72. im3.setLore(lore3);
    73. cancel.setItemMeta(im3);
    74. cancel.setDurability((byte) 14);
    75.  
    76. PaintballGunShop.setItem(0,fullyauto);
    77. PaintballGunShop.setItem(2,faprice);
    78. PaintballGunShop.setItem(4,cancel);
    79. PaintballGunShop.setItem(6,tbprice);
    80. PaintballGunShop.setItem(8,threeburst);
    81.  
    82. }
    83.  
    84. public void onDisable() {
    85.  
    86. getLogger().info("PBGunShop Disabled");
    87.  
    88. }
    89.  
    90. ArrayList<String> Damagers = new ArrayList<String>();
    91.  
    92. @EventHandler
    93. public void onEntityDamage(EntityDamageByEntityEvent event) {
    94.  
    95. Player player = (Player) event.getDamager();
    96. LivingEntity entity = (LivingEntity)event.getEntity();
    97. Villager zinc = (Villager) entity;
    98.  
    99. if (entity.getLastDamageCause().getEntity() instanceof Player) {
    100. event.setCancelled(true);
    101.  
    102. } else if
    103. (zinc.getCustomName() != null && zinc.getCustomName().equals(ChatColor.BLUE + "" + ChatColor.BOLD + "Zinc - The Paintballer")){
    104. event.setCancelled(true);
    105.  
    106. } else {
    107.  
    108. if(Damagers.contains(player.getName())) {
    109. event.setCancelled(true);
    110.  
    111. }
    112. }
    113. }
    114.  
    115. ArrayList<String> lore1 = new ArrayList<String>();
    116. ArrayList<String> lore2 = new ArrayList<String>();
    117. ArrayList<String> lore3 = new ArrayList<String>();
    118. public static Inventory PaintballGunShop = Bukkit.createInventory(null, 9, "PB Gun Shop");
    119. @EventHandler
    120. public void onPlayerInteractEntityEvent(PlayerInteractEntityEvent event) {
    121.  
    122. Entity entity = event.getRightClicked();
    123. Villager zinc = (Villager) entity;
    124. Player player = event.getPlayer();
    125.  
    126. if(zinc.getCustomName() != null && zinc.getCustomName().equals(ChatColor.BLUE + "" + ChatColor.BOLD + "Zinc - The Paintballer")){
    127.  
    128.  
    129. player.openInventory(PaintballGunShop);
    130. }
    131. else{
    132.  
    133. }
    134. }
    135.  
    136. @EventHandler
    137. public void onInventoryClick(InventoryClickEvent event) {
    138.  
    139. Player player = (Player) event.getWhoClicked();
    140. Player buyer = (Player) event.getWhoClicked();
    141. ItemStack clicked = event.getCurrentItem();
    142. Inventory inventory = event.getInventory();
    143.  
    144. PaintballGunShop.setItem(4,cancel);
    145.  
    146. if (inventory.getName().equals(PaintballGunShop.getName())) {
    147. if (clicked.getItemMeta().getDisplayName().equalsIgnoreCase(ChatColor.DARK_RED + "Close")) {
    148.  
    149. event.setCancelled(true);
    150. player.closeInventory();
    151.  
    152. }
    153.  
    154. PaintballGunShop.setItem(2,faprice);
    155.  
    156. if (inventory.getName().equals(PaintballGunShop.getName())) {
    157. if (clicked.getItemMeta().getDisplayName().equalsIgnoreCase(ChatColor.GRAY + "Price: 500")) {
    158.  
    159. event.setCancelled(true);
    160.  
    161. }
    162.  
    163. PaintballGunShop.setItem(4,tbprice);
    164.  
    165. if (inventory.getName().equals(PaintballGunShop.getName())) {
    166. if (clicked.getItemMeta().getDisplayName().equalsIgnoreCase(ChatColor.GRAY + "Price: 1000")) {
    167.  
    168. event.setCancelled(true);
    169.  
    170. }
    171.  
    172. PaintballGunShop.setItem(0,fullyauto);
    173.  
    174. if (inventory.getName().equals(PaintballGunShop.getName())) {
    175.  
    176. if (clicked.getItemMeta().getDisplayName().equalsIgnoreCase(ChatColor.AQUA + "" + ChatColor.BOLD + "Fully-Automatic Paintball Gun")) {
    177.  
    178. event.setCancelled(true);
    179. player.closeInventory();
    180.  
    181. Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "manuaddp" + buyer + "paintballguns.getgun.fullyauto");
    182. Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "manuaddp" + buyer + "-pbgunshop.buy.fullyauto");
    183. Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "eco take" + buyer + "500");
    184.  
    185. buyer.sendMessage(ChatColor.YELLOW + "Congratulations! You purchased the fully-auto paintball gun!");
    186. buyer.sendMessage(ChatColor.YELLOW + "You can now use /fullyauto to get your gun!");
    187.  
    188. }
    189.  
    190. PaintballGunShop.setItem(8,threeburst);
    191.  
    192. if (inventory.getName().equals(PaintballGunShop.getName())) {
    193.  
    194. if (clicked.getItemMeta().getDisplayName().equalsIgnoreCase(ChatColor.GOLD + "" + ChatColor.BOLD + "3-Burst Paintball Gun")) {
    195.  
    196. event.setCancelled(true);
    197. player.closeInventory();
    198.  
    199. Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "manuaddp" + buyer + "paintballguns.getgun.threeburst");
    200. Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "manuaddp" + buyer + "-pbgunshop.buy.threeburst");
    201. Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "eco take" + buyer + "1000");
    202.  
    203. buyer.sendMessage(ChatColor.YELLOW + "Congratulations! You purchased the three-burst paintball gun!");
    204. buyer.sendMessage(ChatColor.YELLOW + "You can now use /threeburst to get your gun!");
    205. }
    206. else {
    207. buyer.sendMessage(ChatColor.RED + "Sorry, you do not have enough money to purchase this gun.");
    208. }
    209. }
    210. }
    211. }
    212. }
    213. }
    214. }
    215.  
    216. public boolean onCommand(CommandSender sender, Command cmd, String Label, String[] args){
    217.  
    218. if (sender instanceof Player) {
    219. if (sender.hasPermission("pbgunshop.spawn")){
    220. if (cmd.getName().equalsIgnoreCase("spbshop")) {
    221.  
    222. Player p = (Player) sender;
    223.  
    224. p.sendMessage(ChatColor.YELLOW + "You have spawned Zinc, The Paintballer!");
    225.  
    226. Villager v = (Villager) p.getWorld().spawnEntity(p.getLocation(), EntityType.VILLAGER);
    227.  
    228. v.setBaby();
    229.  
    230. v.addPotionEffect(new PotionEffect(PotionEffectType.SLOW, Integer.MAX_VALUE, 6));
    231. v.addPotionEffect(new PotionEffect(PotionEffectType.JUMP, Integer.MAX_VALUE, -6));
    232. v.setMaxHealth(12000000);
    233. v.setHealth(12000000);
    234.  
    235. v.setCustomName(ChatColor.BLUE + "" + ChatColor.BOLD + "Zinc - The Paintballer");
    236. v.setCustomNameVisible(true);
    237.  
    238. v.getEquipment().getItemInHand().setType(Material.GOLD_BARDING);
    239. return true;
    240.  
    241. }
    242. }
    243. }
    244. return false;
    245. }
    246. }

    Here's the console error:
    Code:
    10.03 15:38:12 [Server] INFO at net.minecraft.server.v1_7_R1.ThreadServerApplication.run(SourceFile:617) [craftbukkit_dev_2995.jar:git-Bukkit-1.7.2-R0.2-15-g2f3dbd3-b2995jnks]
    10.03 15:38:12 [Server] INFO at net.minecraft.server.v1_7_R1.MinecraftServer.run(MinecraftServer.java:424) [craftbukkit_dev_2995.jar:git-Bukkit-1.7.2-R0.2-15-g2f3dbd3-b2995jnks]
    10.03 15:38:12 [Server] INFO at net.minecraft.server.v1_7_R1.DedicatedServer.init(DedicatedServer.java:175) [craftbukkit_dev_2995.jar:git-Bukkit-1.7.2-R0.2-15-g2f3dbd3-b2995jnks]
    10.03 15:38:12 [Server] INFO at net.minecraft.server.v1_7_R1.MinecraftServer.a(MinecraftServer.java:275) [craftbukkit_dev_2995.jar:git-Bukkit-1.7.2-R0.2-15-g2f3dbd3-b2995jnks]
    10.03 15:38:12 [Server] INFO at net.minecraft.server.v1_7_R1.MinecraftServer.g(MinecraftServer.java:319) [craftbukkit_dev_2995.jar:git-Bukkit-1.7.2-R0.2-15-g2f3dbd3-b2995jnks]
    10.03 15:38:12 [Server] INFO at net.minecraft.server.v1_7_R1.MinecraftServer.m(MinecraftServer.java:342) [craftbukkit_dev_2995.jar:git-Bukkit-1.7.2-R0.2-15-g2f3dbd3-b2995jnks]
    10.03 15:38:12 [Server] INFO at org.bukkit.craftbukkit.v1_7_R1.CraftServer.enablePlugins(CraftServer.java:282) [craftbukkit_dev_2995.jar:git-Bukkit-1.7.2-R0.2-15-g2f3dbd3-b2995jnks]
    10.03 15:38:12 [Server] INFO at org.bukkit.craftbukkit.v1_7_R1.CraftServer.loadPlugin(CraftServer.java:300) [craftbukkit_dev_2995.jar:git-Bukkit-1.7.2-R0.2-15-g2f3dbd3-b2995jnks]
    10.03 15:38:12 [Server] INFO at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:384) [craftbukkit_dev_2995.jar:git-Bukkit-1.7.2-R0.2-15-g2f3dbd3-b2995jnks]
    10.03 15:38:12 [Server] INFO at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:350) [craftbukkit_dev_2995.jar:git-Bukkit-1.7.2-R0.2-15-g2f3dbd3-b2995jnks]
    10.03 15:38:12 [Server] INFO at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:250) ~[craftbukkit_dev_2995.jar:git-Bukkit-1.7.2-R0.2-15-g2f3dbd3-b2995jnks]
    10.03 15:38:12 [Server] INFO at me.BrushPainter.PBGunShop.Main.onEnable(Main.java:31) ~[?:?]
    10.03 15:38:12 [Server] INFO at me.BrushPainter.PBGunShop.Main.newInventory(Main.java:49) ~[?:?]
    10.03 15:38:12 [Server] INFO java.lang.NullPointerException
    10.03 15:38:12 [Server] ERROR Error occurred while enabling PBGunShop v1.0.1 (Is it up to date?)
    10.03 15:38:12 [Server] INFO Enabling PBGunShop v1.0.1
     
Thread Status:
Not open for further replies.

Share This Page