Why is this not going through?

Discussion in 'Plugin Development' started by PieMan456, Dec 6, 2013.

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

    PieMan456

    Ok I am trying to check if the shooter of an egg is a player. It was not working so I used debug lines and for some reason it is not going through. Here is what I put to check:
    Code:java
    1. if(!(e.getEntity().getShooter() instanceof Player)) return;

    This is inside the ProjectileHitEvent. Any ideas to why this is not working?
     
  2. Offline

    Garris0n

    Is the shooter a Player? Can you post the rest of your code?
     
  3. Offline

    PieMan456

    Garris0n
    Here you go:
    Code:java
    1. @EventHandler
    2. public void onProjectileHit(ProjectileHitEvent e){
    3. System.out.println("working");
    4. if(!(e.getEntity().getShooter() instanceof Player)) return;
    5. Player pl = (Player) e.getEntity().getShooter();
    6. if(!(gplayers.contains(pl.getName()))) return;
    7. System.out.println("still working");
    8. Projectile p = e.getEntity();
    9. if(!(p instanceof Egg)) return;
    10. System.out.println("still working!");
    11. Egg egg = (Egg) p;
    12. if(egg.hasMetadata("grenade")){
    13. System.out.println("works!");
    14. double eggx = egg.getLocation().getX();
    15. double eggy = egg.getLocation().getY();
    16. double eggz = egg.getLocation().getZ();
    17. egg.getWorld().createExplosion(eggx, eggy, eggz, 4F, false, false);
    18. gplayers.remove(pl.getName());
    19. return;
    20. }
    21. }
     
  4. Offline

    Garris0n

    Are you sure the player's name is in that list?
     
  5. Offline

    PieMan456

    Garris0n
    That is not the problem it does not get past:
    Code:java
    1. if(!(e.getEntity().getShooter() instanceof Player)) return;


    Anyone? I know this is something that is easy I am probably just making a stupid mistake.

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

    mrkirby153

  7. Offline

    PieMan456

    mrkirby153
    A player. I want to check if the entity is a player and if it is then it keeps going.
     
  8. Offline

    mrkirby153

    PieMan456

    What does System.out.println(event.getEntity().getShooter); print out?
     
  9. Offline

    PieMan456

    mrkirby153
    Hmmm let me check

    mrkirby153
    It won't let me put that in there is an error on .getShooter();

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

    PogoStick29

    I think you want e.getProjectile().getShooter(). e.getEntity() returns what it hits (I could be wrong, but I think that's correct).
     
  11. Offline

    PieMan456

    PogoStick29
    There is not .getProjectile(); in the ProjectileHitEvent.

    Anyone?

    Nobody knows how to fix this?

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

    Rocoty

    Are you making the projectile shoot from the player programmatically? And are you receiving the first println?
     
  13. Offline

    Luke_Lax

    I had this same kind of issue before but with snowballs and I wanted it so that the event only fired if it wasn't a player or a snowman who fired the snowball. Try this, it fixed it for me: check if it's not an instance of a player, then return but add the rest of your code that should fire if it is a player, in an else statement :)
    Code:
    @EventHandler
        public void onProjectileHit(ProjectileHitEvent e){
            System.out.println("working");
            if(!(e.getEntity().getShooter() instanceof Player)) {
    Bukkit.broadcastMessage("You're not a player D: @" + e.getEntity().getShooter());
    } else {
            Player pl = (Player) e.getEntity().getShooter();
            if(!(gplayers.contains(pl.getName()))) return;
            System.out.println("still working");
            Projectile p = e.getEntity();
            if(!(p instanceof Egg)) return;
            System.out.println("still working!");
            Egg egg = (Egg) p;
            if(egg.hasMetadata("grenade")){
                System.out.println("works!");
                double eggx = egg.getLocation().getX();
                double eggy = egg.getLocation().getY();
                double eggz = egg.getLocation().getZ();
                egg.getWorld().createExplosion(eggx, eggy, eggz, 4F, false, false);
                gplayers.remove(pl.getName());
                return;
            }
    }
        }
    
    Ps, sorry for any errors, your IDE will pick them up, I wrote this from my iPad :p
     
  14. Offline

    PogoStick29

    PieMan456 If you are checking if a projectile hits an entity, you can use EntityDamageByEntityEvent.
     
  15. Offline

    Wolfey

    Use EntityDamageByEntityEvent and check if the damager is instanceof the projectile you want. Then Get the shooter of it, like this: egg.getShooter();
     
  16. Offline

    PieMan456

    Wolfey PogoStick29 Luke_Lax Rocoty
    Ok I got it fixed but now there is a weird glitch. When I shoot the egg and I right click a block after I shoot the grenade another egg shoots out into the ground. If I right click on the ground with something else it gives me the egg/grenade back. Why is this doing this?
     
  17. Offline

    Wolfey

    Can I see your code?
     
  18. Offline

    Luke_Lax

    That's normally because the event hasn't actually gone through server side, only client side. So when you click with something else, your client then realises that you've still got the grenade.
     
  19. Offline

    PieMan456

    Wolfey Luke_Lax
    Here is my PlayerInteractEvent where it actually shoots the grenade.
    Code:java
    1. Vector v1 = e.getPlayer().getEyeLocation().getDirection().multiply(2.0);
    2. if(e.getPlayer().getItemInHand().getType() != Material.EGG) return;
    3. if(e.getAction() == Action.RIGHT_CLICK_AIR){
    4. if(e.getPlayer().getItemInHand().getItemMeta().getDisplayName().equalsIgnoreCase(ChatColor.GREEN + "Grenade")){
    5. e.setCancelled(true);
    6. Egg egg = e.getPlayer().getWorld().spawn(e.getPlayer().getEyeLocation().add(v1.getX(), v1.getY(), v1.getZ()), Egg.class);
    7. egg.setMetadata("grenade", new FixedMetadataValue(this, true));
    8. egg.setVelocity(v1);
    9. gplayers.add(e.getPlayer().getName());
    10. return;
    11. }
    12. }
     
  20. Offline

    Luke_Lax


    Hmm I'm not entirely sure, but you might be best off listening to the ProjectileLaunchEvent, checking if it's an egg and cancelling it then call this method above.
     
  21. Offline

    PieMan456

    Luke_Lax
    Ok thanks. That fixed the grenade but I also have a landmine and a bomb that do it as well. And you can't launch the bomb you have to right click it on a block. But event though I canceled the event in the PlayerInteract it still shoots the egg.

    Luke_Lax PogoStick29 Rocoty mrkirby153 Garris0n
    Ok so this is what I have in my projectilelaunchevent. The grenade works perfectly but t he landmine and bomb still shoot the egg and they do not set the location for the bomb or mine.
    Code:java
    1. @SuppressWarnings("deprecation")
    2. @EventHandler
    3. public void onProjectiLaunch(ProjectileLaunchEvent e){
    4. Projectile p = e.getEntity();
    5. if(!(p instanceof Egg)){
    6. return;
    7. } else {
    8. if(p.getShooter() instanceof Player){
    9. final Player pl = (Player) p.getShooter();
    10. if(bob.contains(pl.getName())){
    11. bob.remove(pl.getName());
    12. e.setCancelled(true);
    13. Vector v1 = pl.getEyeLocation().getDirection().multiply(2.0);
    14.  
    15. Egg egg = pl.getWorld().spawn(pl.getEyeLocation().add(v1.getX(), v1.getY(), v1.getZ()), Egg.class);
    16. egg.setMetadata("grenade", new FixedMetadataValue(this, true));
    17. egg.setVelocity(v1);
    18. }
    19. if(lard.contains(pl.getName())){
    20. lard.remove(pl.getName());
    21. e.setCancelled(true);
    22. Block b = pl.getTargetBlock(null, 200);
    23. b.getWorld().playSound(b.getLocation(), Sound.FUSE, 2.0F, 2.0F);
    24. mine.add(b.getLocation());
    25. }
    26. if(doo.contains(pl.getName())){
    27. doo.remove(pl.getName());
    28. e.setCancelled(true);
    29. final Block b = pl.getTargetBlock(null, 200);
    30. b.getWorld().playSound(b.getLocation(), Sound.FUSE, 2.0F, 2.0F);
    31. bomb.add(b.getLocation());
    32. Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable(){
    33. public void run(){
    34. if(players.contains(pl.getName())){
    35. players.remove(pl.getName());
    36. b.getWorld().createExplosion(b.getX(), b.getY(), b.getZ(), 4F, true, true);
    37. bomb.remove(b.getLocation());
    38. }
    39. pl.sendMessage(ChatColor.GREEN + "Bomb going off in 10 seconds!");
    40. players.add(pl.getName());
    41. }
    42. }, 20 * 10);
    43. }
    44. }
    45. }
    46. }


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

    Garris0n

    Code:java
    1. if(!(p instanceof Egg)){
    2. return;
    3. } else {


    What? Why don't you just check if it's an instanceof Egg? Or better yet, just remove the else for cleaner code?

    As for the actual code, I have no idea what the "landmine", "bomb", or "mine" are and it even if I knew what you were talking about that doesn't look like you've posted enough of the code to see what's going wrong.
     
  23. Offline

    PieMan456

    Garris0n
    Here is all of my code:
    Code:java
    1. package me.pieman.eggs;
    2.  
    3. import java.util.ArrayList;
    4.  
    5. import net.milkbowl.vault.economy.Economy;
    6.  
    7. import org.bukkit.Bukkit;
    8. import org.bukkit.ChatColor;
    9. import org.bukkit.Location;
    10. import org.bukkit.Material;
    11. import org.bukkit.Sound;
    12. import org.bukkit.block.Block;
    13. import org.bukkit.block.Sign;
    14. import org.bukkit.entity.Egg;
    15. import org.bukkit.entity.Player;
    16. import org.bukkit.entity.Projectile;
    17. import org.bukkit.event.EventHandler;
    18. import org.bukkit.event.Listener;
    19. import org.bukkit.event.block.Action;
    20. import org.bukkit.event.entity.ProjectileHitEvent;
    21. import org.bukkit.event.entity.ProjectileLaunchEvent;
    22. import org.bukkit.event.inventory.InventoryClickEvent;
    23. import org.bukkit.event.player.PlayerEggThrowEvent;
    24. import org.bukkit.event.player.PlayerInteractEvent;
    25. import org.bukkit.event.player.PlayerMoveEvent;
    26. import org.bukkit.inventory.Inventory;
    27. import org.bukkit.inventory.ItemStack;
    28. import org.bukkit.inventory.meta.ItemMeta;
    29. import org.bukkit.metadata.FixedMetadataValue;
    30. import org.bukkit.plugin.RegisteredServiceProvider;
    31. import org.bukkit.plugin.java.JavaPlugin;
    32. import org.bukkit.scheduler.BukkitTask;
    33. import org.bukkit.util.Vector;
    34.  
    35. public class Eggs extends JavaPlugin implements Listener {
    36.  
    37. public Eggs plugin;
    38.  
    39. public ArrayList<String> players = new ArrayList<String>();
    40.  
    41. public ArrayList<Location> mine = new ArrayList<Location>();
    42.  
    43. public ArrayList<Location> bomb = new ArrayList<Location>();
    44.  
    45. public ArrayList<String> bob = new ArrayList<String>();
    46.  
    47. public ArrayList<String> lard = new ArrayList<String>();
    48.  
    49. public ArrayList<String> doo = new ArrayList<String>();
    50.  
    51. public static Economy econ = null;
    52.  
    53. public void onEnable(){
    54. Bukkit.getServer().getPluginManager().registerEvents(this, this);
    55. if (!setupEconomy() ) {
    56. getLogger().severe(String.format("[%s] - Disabled due to no Vault dependency found!", getDescription().getName()));
    57. getServer().getPluginManager().disablePlugin(this);
    58. return;
    59. }
    60. }
    61.  
    62. private boolean setupEconomy() {
    63. if (getServer().getPluginManager().getPlugin("Vault") == null) {
    64. return false;
    65. }
    66. RegisteredServiceProvider<Economy> rsp = getServer().getServicesManager().getRegistration(Economy.class);
    67. if (rsp == null) {
    68. return false;
    69. }
    70. econ = rsp.getProvider();
    71. return econ != null;
    72. }
    73.  
    74. public String locToString(Location loc) {
    75. return String.valueOf(loc.getX()) + String.valueOf(loc.getY()) + String.valueOf(loc.getZ());
    76. }
    77.  
    78. @EventHandler
    79. public void onProjectileHit(ProjectileHitEvent e){
    80. Projectile p = e.getEntity();
    81. if(!(p instanceof Egg)) return;
    82. if(p.hasMetadata("grenade")){
    83. double eggx = p.getLocation().getX();
    84. double eggy = p.getLocation().getY();
    85. double eggz = p.getLocation().getZ();
    86. p.getWorld().createExplosion(eggx, eggy, eggz, 4F, false, false);
    87. return;
    88. }
    89. }
    90.  
    91. @EventHandler
    92. public void onPlayerMove(PlayerMoveEvent e){
    93. Player p = e.getPlayer();
    94. for(Location mloc : mine){
    95. Location ploc = p.getLocation();
    96. if(ploc.getBlockX() == mloc.getX() && ploc.getBlockY() == mloc.getY() && ploc.getBlockZ() == mloc.getX()){
    97. mloc.getWorld().createExplosion(ploc.getX(), ploc.getY(), ploc.getZ(), 4F, false, false);
    98. mine.remove(mloc);
    99. }
    100. }
    101. }
    102.  
    103. @SuppressWarnings("deprecation")
    104. public void openInventory(Player p){
    105. Inventory inv = Bukkit.createInventory(null, 9, "Bomb Factory");
    106.  
    107. ItemStack grenade = new ItemStack(Material.EGG);
    108. ItemMeta gmeta = grenade.getItemMeta();
    109. ArrayList<String> g = new ArrayList<String>();
    110. g.add(ChatColor.DARK_AQUA + "Cost: " + getConfig().getDouble("grenadeprice"));
    111. gmeta.setLore(g);
    112. gmeta.setDisplayName(ChatColor.GREEN + "Grenade");
    113. grenade.setItemMeta(gmeta);
    114.  
    115. ItemStack bomb = new ItemStack(Material.EGG);
    116. ItemMeta bmeta = bomb.getItemMeta();
    117. ArrayList<String> b = new ArrayList<String>();
    118. b.add(ChatColor.DARK_AQUA + "Cost: " + getConfig().getDouble("bombprice"));
    119. bmeta.setLore(b);
    120. bmeta.setDisplayName(ChatColor.GREEN + "Bomb");
    121. bomb.setItemMeta(bmeta);
    122.  
    123. ItemStack landmine = new ItemStack(Material.EGG);
    124. ItemMeta lmeta = landmine.getItemMeta();
    125. ArrayList<String> l = new ArrayList<String>();
    126. l.add(ChatColor.DARK_AQUA + "Cost: " + getConfig().getDouble("landmineprice"));
    127. lmeta.setLore(l);
    128. lmeta.setDisplayName(ChatColor.GREEN + "LandMine");
    129. landmine.setItemMeta(lmeta);
    130.  
    131. ItemStack wirecutters = new ItemStack(Material.FLINT_AND_STEEL);
    132. ItemMeta wmeta = wirecutters.getItemMeta();
    133. ArrayList<String> w = new ArrayList<String>();
    134. w.add(ChatColor.DARK_AQUA + "Cost: " + getConfig().getDouble("wirecuttersprice"));
    135. wmeta.setLore(w);
    136. wmeta.setDisplayName(ChatColor.GREEN + "WireCutters");
    137. wirecutters.setItemMeta(wmeta);
    138.  
    139. ItemStack money = new ItemStack(Material.DIAMOND);
    140. ItemMeta mmeta = money.getItemMeta();
    141. mmeta.setDisplayName(ChatColor.DARK_PURPLE + "Balance: " + econ.getBalance(p.getName()));
    142. money.setItemMeta(mmeta);
    143.  
    144. p.openInventory(inv);
    145.  
    146. inv.clear();
    147. inv.setItem(0, new ItemStack(grenade));
    148. inv.setItem(2, new ItemStack(bomb));
    149. inv.setItem(4, new ItemStack(money));
    150. inv.setItem(6, new ItemStack(landmine));
    151. inv.setItem(8, new ItemStack(wirecutters));
    152.  
    153. p.updateInventory();
    154. }
    155.  
    156. @EventHandler
    157. public void onEggThrow(PlayerEggThrowEvent e){
    158. if(e.getEgg().hasMetadata("grenade")){
    159. e.setHatching(false);
    160. }
    161. }
    162.  
    163. @EventHandler
    164. public void onInventoryClick(InventoryClickEvent e){
    165. if(!e.getInventory().getName().equalsIgnoreCase("Bomb Factory")) return;
    166. if(!(e.getWhoClicked() instanceof Player)) return;
    167. Player p = (Player) e.getWhoClicked();
    168. if (p.getInventory().firstEmpty() == -1) {
    169. p.sendMessage(ChatColor.RED + "Your inventory is full!");
    170. return;
    171. }
    172. if(e.getCurrentItem().getType() == Material.DIAMOND){
    173. e.setCancelled(true);
    174. }
    175. if(e.getCurrentItem().getItemMeta().getDisplayName().equalsIgnoreCase(ChatColor.GREEN + "Grenade")){
    176. e.setCancelled(true);
    177. if(econ.getBalance(p.getName()) < getConfig().getDouble("grenadeprice")){
    178. p.sendMessage(ChatColor.RED + "You do not have enough money!");
    179. p.closeInventory();
    180. return;
    181. } else {
    182. ItemStack grenade = new ItemStack(Material.EGG);
    183. ItemMeta gmeta = grenade.getItemMeta();
    184. gmeta.setDisplayName(ChatColor.GREEN + "Grenade");
    185. grenade.setItemMeta(gmeta);
    186. p.getInventory().addItem(new ItemStack(grenade));
    187. econ.withdrawPlayer(p.getName(), getConfig().getDouble("grenadeprice"));
    188. }
    189. }
    190. if(e.getCurrentItem().getItemMeta().getDisplayName().equalsIgnoreCase(ChatColor.GREEN + "Bomb")){
    191. e.setCancelled(true);
    192. if(econ.getBalance(p.getName()) < getConfig().getDouble("bombprice")){
    193. p.sendMessage(ChatColor.RED + "You do not have enough money!");
    194. p.closeInventory();
    195. return;
    196. } else {
    197. ItemStack bomb = new ItemStack(Material.EGG);
    198. ItemMeta bmeta = bomb.getItemMeta();
    199. bmeta.setDisplayName(ChatColor.GREEN + "Bomb");
    200. bomb.setItemMeta(bmeta);
    201. p.getInventory().addItem(new ItemStack(bomb));
    202. econ.withdrawPlayer(p.getName(), getConfig().getDouble("bombprice"));
    203. }
    204. }
    205. if(e.getCurrentItem().getItemMeta().getDisplayName().equalsIgnoreCase(ChatColor.GREEN + "LandMine")){
    206. e.setCancelled(true);
    207. if(econ.getBalance(p.getName()) < getConfig().getDouble("landmineprice")){
    208. p.sendMessage(ChatColor.RED + "You do not have enough money!");
    209. p.closeInventory();
    210. return;
    211. } else {
    212. ItemStack landmine = new ItemStack(Material.EGG);
    213. ItemMeta lmeta = landmine.getItemMeta();
    214. lmeta.setDisplayName(ChatColor.GREEN + "LandMine");
    215. landmine.setItemMeta(lmeta);
    216. p.getInventory().addItem(new ItemStack(landmine));
    217. econ.withdrawPlayer(p.getName(), getConfig().getDouble("landmineprice"));
    218. }
    219. }
    220. if(e.getCurrentItem().getItemMeta().getDisplayName().equalsIgnoreCase(ChatColor.GREEN + "WireCutters")){
    221. e.setCancelled(true);
    222. if(econ.getBalance(p.getName()) < getConfig().getDouble("wirecuttersprice")){
    223. p.sendMessage(ChatColor.RED + "You do not have enough money!");
    224. return;
    225. } else {
    226. ItemStack wirecutters = new ItemStack(Material.FLINT_AND_STEEL);
    227. ItemMeta wmeta = wirecutters.getItemMeta();
    228. wmeta.setDisplayName(ChatColor.GREEN + "WireCutters");
    229. wirecutters.setItemMeta(wmeta);
    230. p.getInventory().addItem(new ItemStack(wirecutters));
    231. econ.withdrawPlayer(p.getName(), getConfig().getDouble("landmineprice"));
    232. }
    233. }
    234. }
    235.  
    236. @SuppressWarnings("deprecation")
    237. @EventHandler
    238. public void onProjectiLaunch(ProjectileLaunchEvent e){
    239. Projectile p = e.getEntity();
    240. if(!(p instanceof Egg)){
    241. return;
    242. } else {
    243. if(p.getShooter() instanceof Player){
    244. final Player pl = (Player) p.getShooter();
    245. if(bob.contains(pl.getName())){
    246. bob.remove(pl.getName());
    247. e.setCancelled(true);
    248. Vector v1 = pl.getEyeLocation().getDirection().multiply(2.0);
    249.  
    250. Egg egg = pl.getWorld().spawn(pl.getEyeLocation().add(v1.getX(), v1.getY(), v1.getZ()), Egg.class);
    251. egg.setMetadata("grenade", new FixedMetadataValue(this, true));
    252. egg.setVelocity(v1);
    253. }
    254. if(lard.contains(pl.getName())){
    255. lard.remove(pl.getName());
    256. e.setCancelled(true);
    257. Block b = pl.getTargetBlock(null, 200);
    258. b.getWorld().playSound(b.getLocation(), Sound.FUSE, 2.0F, 2.0F);
    259. mine.add(b.getLocation());
    260. }
    261. if(doo.contains(pl.getName())){
    262. doo.remove(pl.getName());
    263. e.setCancelled(true);
    264. final Block b = pl.getTargetBlock(null, 200);
    265. b.getWorld().playSound(b.getLocation(), Sound.FUSE, 2.0F, 2.0F);
    266. bomb.add(b.getLocation());
    267. Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable(){
    268. public void run(){
    269. if(players.contains(pl.getName())){
    270. players.remove(pl.getName());
    271. b.getWorld().createExplosion(b.getX(), b.getY(), b.getZ(), 4F, true, true);
    272. bomb.remove(b.getLocation());
    273. }
    274. pl.sendMessage(ChatColor.GREEN + "Bomb going off in 10 seconds!");
    275. players.add(pl.getName());
    276. }
    277. }, 20 * 10);
    278. }
    279. }
    280. }
    281. }
    282.  
    283. @EventHandler
    284. public void onPlayerInteract(final PlayerInteractEvent e){
    285. if(e.getAction() == Action.RIGHT_CLICK_BLOCK){
    286. if(e.getClickedBlock().getType() != Material.SIGN && e.getClickedBlock().getType() != Material.WALL_SIGN
    287. && e.getClickedBlock().getType() != Material.SIGN_POST) return;
    288. Sign s = (Sign) e.getClickedBlock().getState();
    289. if(s.getLine(0).equalsIgnoreCase(ChatColor.GREEN + "Eggsplosions")){
    290. Player p = (Player) e.getPlayer();
    291. openInventory(p);
    292. }
    293. }
    294. if(e.getAction() == Action.RIGHT_CLICK_BLOCK){
    295. Block b = e.getClickedBlock();
    296. if(bomb.contains(b.getLocation())){
    297. Player p = e.getPlayer();
    298. if(p.getItemInHand().getType() == Material.FLINT_AND_STEEL && p.getItemInHand().getItemMeta().getDisplayName().equalsIgnoreCase(ChatColor.GREEN + "WireCutters")){
    299. p.sendMessage(ChatColor.GREEN + "You have successfully defused the bomb!");
    300. Bukkit.getServer().getScheduler().cancelTasks(this);
    301. bomb.remove(b.getLocation());
    302. return;
    303. }
    304. }
    305. }
    306. Vector v1 = e.getPlayer().getEyeLocation().getDirection().multiply(2.0);
    307. if(e.getPlayer().getItemInHand().getType() != Material.EGG) return;
    308. if(e.getAction() == Action.RIGHT_CLICK_AIR){
    309. if(e.getPlayer().getItemInHand().getItemMeta().getDisplayName().equalsIgnoreCase(ChatColor.GREEN + "Grenade")){
    310. /*e.setCancelled(true);
    311.   Egg egg = e.getPlayer().getWorld().spawn(e.getPlayer().getEyeLocation().add(v1.getX(), v1.getY(), v1.getZ()), Egg.class);
    312.   egg.setMetadata("grenade", new FixedMetadataValue(this, true));
    313.   egg.setVelocity(v1);*/
    314. bob.add(e.getPlayer().getName());
    315. return;
    316. }
    317. }
    318. if(e.getAction() == Action.RIGHT_CLICK_AIR){
    319. if(e.getPlayer().getItemInHand().getItemMeta().getDisplayName().equalsIgnoreCase(ChatColor.GREEN + "LandMine")){
    320. e.setCancelled(true);
    321. e.getPlayer().sendMessage(ChatColor.RED + "You must plant the landmine on a block!");
    322. return;
    323. }
    324. }
    325.  
    326. if(e.getAction() == Action.RIGHT_CLICK_AIR){
    327. if(e.getPlayer().getItemInHand().getItemMeta().getDisplayName().equalsIgnoreCase(ChatColor.GREEN + "Bomb")){
    328. e.setCancelled(true);
    329. e.getPlayer().sendMessage(ChatColor.RED + "You must plant the bomb on a block!");
    330. return;
    331. }
    332. }
    333.  
    334. if(e.getAction() == Action.RIGHT_CLICK_BLOCK){
    335. if(e.getPlayer().getItemInHand().getItemMeta().getDisplayName().equalsIgnoreCase(ChatColor.GREEN + "LandMine")){
    336. e.setCancelled(true);
    337. Egg egg = e.getPlayer().getWorld().spawn(e.getPlayer().getEyeLocation().add(v1.getX(), v1.getY(), v1.getZ()), Egg.class);
    338. egg.setVelocity(v1);
    339. lard.add(e.getPlayer().getName());
    340. /*Inventory pi = e.getPlayer().getInventory();
    341.   pi.remove(new ItemStack(Material.EGG, 1));
    342.   Block b = e.getClickedBlock();
    343.   b.getWorld().playSound(b.getLocation(), Sound.FUSE, 2.0F, 2.0F);
    344.   mine.add(b.getLocation());*/
    345. return;
    346. }
    347. if(e.getPlayer().getItemInHand().getItemMeta().getDisplayName().equalsIgnoreCase(ChatColor.GREEN + "Bomb")){
    348. e.setCancelled(true);
    349. doo.add(e.getPlayer().getName());
    350. Egg egg = e.getPlayer().getWorld().spawn(e.getPlayer().getEyeLocation().add(v1.getX(), v1.getY(), v1.getZ()), Egg.class);
    351. egg.setVelocity(v1);
    352. /*Inventory pi = e.getPlayer().getInventory();
    353.   pi.remove(e.getPlayer().getItemInHand());
    354.   final Block b = e.getClickedBlock();
    355.   bomb.add(b.getLocation());
    356.   Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable(){
    357.   public void run(){
    358.   Player p = e.getPlayer();
    359.   if(players.contains(p.getName())){
    360.   b.getWorld().createExplosion(b.getX(), b.getY(), b.getZ(), 4F, true, true);
    361.   bomb.remove(b.getLocation());
    362.   }
    363.   e.getPlayer().sendMessage(ChatColor.GREEN + "The bomb is going to blow up in 10 seconds!");
    364.   b.getWorld().playSound(b.getLocation(), Sound.FUSE, 2.0F, 2.0F);
    365.   players.add(p.getName());
    366.   }
    367.   }, 20 * 10);
    368.   return;*/
    369. }
    370. }
    371. }
    372. }
    373.  
     
  24. Offline

    PieMan456

    Last edited by a moderator: Jun 5, 2016
Thread Status:
Not open for further replies.

Share This Page