Vinetos

[Bukkit NMS] Mount - 2

Sep 9th, 2015
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.26 KB | None | 0 0
  1. public class PetsUtils {
  2.  
  3. public static HashMap<String, Integer> mounter = new HashMap<String, Integer>();
  4.  
  5. public static void spawnWolf(Player p){
  6. WorldServer nmsWorld = ((CraftWorld) p.getLocation().getWorld()).getHandle();
  7. make(new CustomLoup(nmsWorld), p);
  8. }
  9.  
  10. public static void spawnHorse(Player p){
  11. WorldServer nmsWorld = ((CraftWorld) p.getLocation().getWorld()).getHandle();
  12. CustomCheval nmsEntity = new CustomCheval(nmsWorld);
  13. Horse bEntity = (Horse) nmsEntity.getBukkitEntity();
  14. bEntity.setVariant(Variant.HORSE);
  15. bEntity.setColor(Color.WHITE);
  16. bEntity.setTamed(true);
  17. bEntity.setOwner(p);
  18. bEntity.getInventory().setSaddle(new ItemStack(Material.SADDLE));
  19. make(nmsEntity, p);
  20. }
  21.  
  22. public static void spawnPig(Player p){
  23. WorldServer nmsWorld = ((CraftWorld) p.getLocation().getWorld()).getHandle();
  24. make(new CustomPig(nmsWorld), p);
  25. }
  26.  
  27. public static void spawnSheep(Player p){
  28. WorldServer nmsWorld = ((CraftWorld) p.getLocation().getWorld()).getHandle();
  29. make(new CustomSheep(nmsWorld), p);
  30. }
  31.  
  32. public static void spawnChicken(Player p){
  33. WorldServer nmsWorld = ((CraftWorld) p.getLocation().getWorld()).getHandle();
  34. make(new CustomPoulet(nmsWorld), p);
  35. }
  36.  
  37. public static void spawnMushCow(Player p){
  38. WorldServer nmsWorld = ((CraftWorld) p.getLocation().getWorld()).getHandle();
  39. make(new CustomCow(nmsWorld), p);
  40. }
  41. public static void spawnOcelot(Player p){
  42. WorldServer nmsWorld = ((CraftWorld) p.getLocation().getWorld()).getHandle();
  43. make(new CustomOcelot(nmsWorld), p);
  44. }
  45.  
  46. private static void addMounter(int ID, Player p){
  47. if(!mounter.containsKey(p.getName())){
  48. mounter.put(p.getName(), ID);
  49. }
  50.  
  51. }
  52.  
  53. public static void removeMounter(Player p){
  54. if(mounter.containsKey(p.getName())){
  55. int ID = mounter.get(p.getName());
  56. for(Entity e : p.getWorld().getEntities()){
  57. if(e.getEntityId() == ID){
  58. e.remove();
  59. mounter.remove(p.getName());
  60. break;
  61. }
  62. }
  63. }
  64.  
  65. }
  66.  
  67. private static void make(EntityLiving nmsEntity, Player player){
  68. if(!canSummonMount(player.getLocation())){
  69. player.sendMessage("§cVous ne pouvez pas avoir votre monture ici !");
  70. return;
  71. }
  72.  
  73. LivingEntity mount = (LivingEntity) nmsEntity.getBukkitEntity();
  74.  
  75. Location loc = player.getLocation();
  76. World nmsWorld = ((CraftWorld) loc.getWorld()).getHandle();
  77. nmsEntity.setPosition(loc.getX(), loc.getY() + 0.3, loc.getZ());
  78. nmsWorld.addEntity(nmsEntity, SpawnReason.CUSTOM);
  79.  
  80. mount.setMaxHealth(mount.getMaxHealth());
  81. mount.setPassenger(player);
  82.  
  83. removeMounter(player);
  84. addMounter(mount.getEntityId(), player);
  85. }
  86.  
  87. public static boolean canSummonMount(Location location) {
  88. org.bukkit.World world = location.getWorld();
  89. Block block = location.getBlock();
  90. for(int x = location.getBlockX() - 1; x <= location.getBlockX() + 1; x++){
  91. for(int y = location.getBlockY(); y <= location.getBlockY() + 1; y++){
  92. for(int z = location.getBlockZ() - 1; z <= location.getBlockZ() + 1; z++){
  93. block = world.getBlockAt(x, y, z);
  94. if (block.getType().isSolid()) return false;
  95. }
  96. }
  97. }
  98.  
  99. return true;
  100. }
  101.  
  102. public static void removeAllPets(){
  103. for(Player p : Bukkit.getOnlinePlayers()){
  104. PetsUtils.removeMounter(p);
  105. }
  106. }
  107.  
  108. }
Advertisement
Add Comment
Please, Sign In to add comment