Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.90 KB | None | 0 0
  1. package Mars.PVP.Commands;
  2.  
  3. import org.bukkit.Bukkit;
  4. import org.bukkit.ChatColor;
  5. import org.bukkit.Location;
  6. import org.bukkit.command.Command;
  7. import org.bukkit.command.CommandExecutor;
  8. import org.bukkit.command.CommandSender;
  9. import org.bukkit.configuration.file.FileConfiguration;
  10. import org.bukkit.craftbukkit.v1_8_R3.entity.CraftEntity;
  11. import org.bukkit.entity.EntityType;
  12. import org.bukkit.entity.LivingEntity;
  13. import org.bukkit.entity.Player;
  14. import org.bukkit.entity.Villager.Profession;
  15. import org.bukkit.event.entity.EntityDamageEvent;
  16.  
  17. import Mars.PVP.Main.Main;
  18. import net.minecraft.server.v1_8_R3.NBTTagCompound;
  19.  
  20. public class Villager implements CommandExecutor {
  21.  
  22. private Main main;
  23.  
  24. public Villager(Main main) {
  25. this.main = main;
  26. }
  27.  
  28. private FileConfiguration getConfig() {
  29. return main.getConfig();
  30. }
  31.  
  32. @Override
  33. public boolean onCommand(CommandSender sender, Command command, String arg2, String[] args) {
  34. if (command.getName().equalsIgnoreCase("villager")) {
  35. if (sender instanceof Player) {
  36. if (sender.hasPermission("pvp.admin")) {
  37. if (args.length == 0) {
  38. sender.sendMessage("/villager create");
  39. sender.sendMessage("/villager delete");
  40. } else if (args.length == 1) {
  41. if (args[0].equalsIgnoreCase("create")) {
  42. if (VillagerExits() != false) {
  43. deleteVillager(
  44. new Location(Bukkit.getWorld(getConfig().getString("Villager.Location.World")),
  45. getConfig().getDouble("Villager.Location.X"),
  46. getConfig().getDouble("Villager.Location.Y"),
  47. getConfig().getDouble("Villager.Location.Z"),
  48. (float) getConfig().getDouble("Villager.Location.PITCH"),
  49. (float) getConfig().getDouble("Villager.Location.YAW")));
  50.  
  51. }
  52. sender.sendMessage("Villager Created");
  53. CreateVillager(((Player) sender).getLocation());
  54. return true;
  55. }
  56. if (args[0].equalsIgnoreCase("delete")) {
  57. if (VillagerExits() != true) {
  58. sender.sendMessage("Villager not found");
  59. return true;
  60. }
  61. sender.sendMessage("Villager removed.");
  62. deleteVillager(
  63. new Location(Bukkit.getWorld(getConfig().getString("Villager.Location.World")),
  64. getConfig().getDouble("Villager.Location.X"),
  65. getConfig().getDouble("Villager.Location.Y"),
  66. getConfig().getDouble("Villager.Location.Z"),
  67. (float) getConfig().getDouble("Villager.Location.PITCH"),
  68. (float) getConfig().getDouble("Villager.Location.YAW")));
  69. } else {
  70.  
  71. sender.sendMessage("/villager");
  72. }
  73. } else {
  74. sender.sendMessage("/villager");
  75. }
  76. }
  77. } else {
  78. sender.sendMessage("Player only use this command.");
  79. }
  80. }
  81. return false;
  82. }
  83.  
  84. public void CreateVillager(Location location) {
  85. org.bukkit.entity.Villager villager = (org.bukkit.entity.Villager) location.getWorld().spawnEntity(location,
  86. EntityType.VILLAGER);
  87. villager.setCanPickupItems(false);
  88. villager.setProfession(Profession.LIBRARIAN);
  89. villager.setCustomName("§8»» §7PVP Profile §8««");
  90. getConfig().set("Villager.Location.World", location.getWorld().getName());
  91. getConfig().set("Villager.Location.X", location.getX());
  92. getConfig().set("Villager.Location.Y", location.getY());
  93. getConfig().set("Villager.Location.Z", location.getZ());
  94. getConfig().set("Villager.Location.PITCH", location.getPitch());
  95. getConfig().set("Villager.Location.YAW", location.getYaw());
  96. getConfig().set("Villager.name", villager.getCustomName());
  97. main.saveConfig();
  98. net.minecraft.server.v1_8_R3.Entity nmsEntity = ((CraftEntity) villager).getHandle();
  99. NBTTagCompound tag = nmsEntity.getNBTTag();
  100. if (tag == null) {
  101. tag = new NBTTagCompound();
  102. }
  103. nmsEntity.c(tag);
  104. tag.setInt("NoAI", 1);
  105. nmsEntity.f(tag);
  106. }
  107.  
  108. public boolean VillagerExits() {
  109. try {
  110. int x = getConfig().getInt("Villager.Location.X");
  111. if (x < 0) {
  112. x = getConfig().getInt("Villager.Location.X") - 1;
  113. }
  114. int y = getConfig().getInt("Villager.Location.Y");
  115. if (y < 0) {
  116. y = getConfig().getInt("Villager.Location.Y") - 1;
  117. }
  118. int z = getConfig().getInt("Villager.Location.Z");
  119. if (z < 0) {
  120. z = getConfig().getInt("Villager.Location.Z") - 1;
  121. }
  122.  
  123. for (LivingEntity en : Bukkit.getWorld(getConfig().getString("Villager.Location.World"))
  124. .getLivingEntities()) {
  125. if (en.getType() == EntityType.VILLAGER) {
  126. Location location2 = new Location(en.getWorld(), en.getLocation().getBlockX(),
  127. en.getLocation().getBlockY(), en.getLocation().getBlockZ());
  128. if (new Location(Bukkit.getWorld(getConfig().getString("Villager.Location.World")), x, y, z)
  129. .equals(location2)) {
  130. if (ChatColor.stripColor(en.getCustomName()).equals(getConfig().getString("Villager.name"))) {
  131. return true;
  132. }
  133. }
  134. }
  135. }
  136. } catch (Exception e) {
  137.  
  138. }
  139. return false;
  140. }
  141.  
  142. public void deleteVillager(Location location) {
  143. for (LivingEntity en : location.getWorld().getLivingEntities()) {
  144. if (en.getType() == EntityType.VILLAGER) {
  145.  
  146. Location location2 = new Location(en.getWorld(), en.getLocation().getBlockX(),
  147. en.getLocation().getBlockY(), en.getLocation().getBlockZ());
  148. int x = getConfig().getInt("Villager.Location.X");
  149. if (x < 0) {
  150. x = getConfig().getInt("Villager.Location.X") - 1;
  151. }
  152. int y = getConfig().getInt("Villager.Location.Y");
  153. if (y < 0) {
  154. y = getConfig().getInt("Villager.Location.Y") - 1;
  155. }
  156. int z = getConfig().getInt("Villager.Location.Z");
  157. if (z < 0) {
  158. z = getConfig().getInt("Villager.Location.Z") - 1;
  159. }
  160. if (new Location(Bukkit.getWorld(getConfig().getString("Villager.Location.World")), x, y, z)
  161. .equals(location2)) {
  162. if (ChatColor.stripColor(en.getCustomName()).equals(getConfig().getString("Villager.name"))) {
  163. en.remove();
  164. }
  165. }
  166.  
  167. }
  168. }
  169. }
  170. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement