Item.java 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /*
  2. This file is part of mcMMO.
  3. mcMMO is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation, either version 3 of the License, or
  6. (at your option) any later version.
  7. mcMMO is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with mcMMO. If not, see <http://www.gnu.org/licenses/>.
  13. */
  14. package com.gmail.nossr50;
  15. import org.bukkit.Location;
  16. import org.bukkit.Material;
  17. import org.bukkit.block.Block;
  18. import org.bukkit.entity.Player;
  19. import org.bukkit.inventory.ItemStack;
  20. import org.bukkit.plugin.Plugin;
  21. import com.gmail.nossr50.config.*;
  22. import com.gmail.nossr50.locale.mcLocale;
  23. import com.gmail.nossr50.skills.*;
  24. import com.gmail.nossr50.datatypes.PlayerProfile;
  25. public class Item {
  26. public static void itemchecks(Player player, Plugin plugin)
  27. {
  28. ItemStack inhand = player.getItemInHand();
  29. if(LoadProperties.chimaeraWingEnable && inhand.getTypeId() == LoadProperties.chimaeraId)
  30. {
  31. chimaerawing(player, plugin);
  32. }
  33. }
  34. public static void chimaerawing(Player player, Plugin plugin)
  35. {
  36. PlayerProfile PP = Users.getProfile(player);
  37. ItemStack is = player.getItemInHand();
  38. Block block = player.getLocation().getBlock();
  39. int chimaeraID = LoadProperties.chimaeraId;
  40. int itemsUsed = LoadProperties.feathersConsumedByChimaeraWing;
  41. if(mcPermissions.getInstance().chimaeraWing(player) && is.getTypeId() == chimaeraID)
  42. {
  43. if(Skills.cooldownOver(player, PP.getRecentlyHurt(), 60) && is.getAmount() >= itemsUsed)
  44. {
  45. Block derp = player.getLocation().getBlock();
  46. int y = derp.getY();
  47. player.setItemInHand(new ItemStack(chimaeraID, is.getAmount() - itemsUsed));
  48. while(y < 127)
  49. {
  50. y++;
  51. if(player != null)
  52. {
  53. if(player.getLocation().getWorld().getBlockAt(block.getX(), y, block.getZ()).getType() != Material.AIR)
  54. {
  55. player.sendMessage(mcLocale.getString("Item.ChimaeraWingFail")); //$NON-NLS-1$
  56. player.teleport(player.getLocation().getWorld().getBlockAt(block.getX(), (y - 1), block.getZ()).getLocation());
  57. return;
  58. }
  59. }
  60. }
  61. if(PP.getMySpawn(player) != null)
  62. {
  63. Location mySpawn = PP.getMySpawn(player);
  64. if(mySpawn != null){
  65. player.teleport(mySpawn); //Do it twice to prevent weird stuff
  66. player.teleport(mySpawn);
  67. }
  68. } else {
  69. player.teleport(player.getWorld().getSpawnLocation());
  70. }
  71. player.sendMessage(mcLocale.getString("Item.ChimaeraWingPass")); //$NON-NLS-1$
  72. } else if (!Skills.cooldownOver(player, PP.getRecentlyHurt(), 60) && is.getAmount() >= 10)
  73. {
  74. player.sendMessage(mcLocale.getString("Item.InjuredWait", new Object[] {Skills.calculateTimeLeft(player, PP.getRecentlyHurt(), 60)})); //$NON-NLS-1$
  75. } else if (is.getTypeId() == LoadProperties.chimaeraId && is.getAmount() <= 9){
  76. player.sendMessage(mcLocale.getString("Item.NeedFeathers")); //$NON-NLS-1$
  77. }
  78. }
  79. }
  80. }