Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Mars.PVP.Commands;
- import org.bukkit.Bukkit;
- import org.bukkit.ChatColor;
- import org.bukkit.Location;
- import org.bukkit.command.Command;
- import org.bukkit.command.CommandExecutor;
- import org.bukkit.command.CommandSender;
- import org.bukkit.configuration.file.FileConfiguration;
- import org.bukkit.craftbukkit.v1_8_R3.entity.CraftEntity;
- import org.bukkit.entity.EntityType;
- import org.bukkit.entity.LivingEntity;
- import org.bukkit.entity.Player;
- import org.bukkit.entity.Villager.Profession;
- import org.bukkit.event.entity.EntityDamageEvent;
- import Mars.PVP.Main.Main;
- import net.minecraft.server.v1_8_R3.NBTTagCompound;
- public class Villager implements CommandExecutor {
- private Main main;
- public Villager(Main main) {
- this.main = main;
- }
- private FileConfiguration getConfig() {
- return main.getConfig();
- }
- @Override
- public boolean onCommand(CommandSender sender, Command command, String arg2, String[] args) {
- if (command.getName().equalsIgnoreCase("villager")) {
- if (sender instanceof Player) {
- if (sender.hasPermission("pvp.admin")) {
- if (args.length == 0) {
- sender.sendMessage("/villager create");
- sender.sendMessage("/villager delete");
- } else if (args.length == 1) {
- if (args[0].equalsIgnoreCase("create")) {
- if (VillagerExits() != false) {
- deleteVillager(
- new Location(Bukkit.getWorld(getConfig().getString("Villager.Location.World")),
- getConfig().getDouble("Villager.Location.X"),
- getConfig().getDouble("Villager.Location.Y"),
- getConfig().getDouble("Villager.Location.Z"),
- (float) getConfig().getDouble("Villager.Location.PITCH"),
- (float) getConfig().getDouble("Villager.Location.YAW")));
- }
- sender.sendMessage("Villager Created");
- CreateVillager(((Player) sender).getLocation());
- return true;
- }
- if (args[0].equalsIgnoreCase("delete")) {
- if (VillagerExits() != true) {
- sender.sendMessage("Villager not found");
- return true;
- }
- sender.sendMessage("Villager removed.");
- deleteVillager(
- new Location(Bukkit.getWorld(getConfig().getString("Villager.Location.World")),
- getConfig().getDouble("Villager.Location.X"),
- getConfig().getDouble("Villager.Location.Y"),
- getConfig().getDouble("Villager.Location.Z"),
- (float) getConfig().getDouble("Villager.Location.PITCH"),
- (float) getConfig().getDouble("Villager.Location.YAW")));
- } else {
- sender.sendMessage("/villager");
- }
- } else {
- sender.sendMessage("/villager");
- }
- }
- } else {
- sender.sendMessage("Player only use this command.");
- }
- }
- return false;
- }
- public void CreateVillager(Location location) {
- org.bukkit.entity.Villager villager = (org.bukkit.entity.Villager) location.getWorld().spawnEntity(location,
- EntityType.VILLAGER);
- villager.setCanPickupItems(false);
- villager.setProfession(Profession.LIBRARIAN);
- villager.setCustomName("§8»» §7PVP Profile §8««");
- getConfig().set("Villager.Location.World", location.getWorld().getName());
- getConfig().set("Villager.Location.X", location.getX());
- getConfig().set("Villager.Location.Y", location.getY());
- getConfig().set("Villager.Location.Z", location.getZ());
- getConfig().set("Villager.Location.PITCH", location.getPitch());
- getConfig().set("Villager.Location.YAW", location.getYaw());
- getConfig().set("Villager.name", villager.getCustomName());
- main.saveConfig();
- net.minecraft.server.v1_8_R3.Entity nmsEntity = ((CraftEntity) villager).getHandle();
- NBTTagCompound tag = nmsEntity.getNBTTag();
- if (tag == null) {
- tag = new NBTTagCompound();
- }
- nmsEntity.c(tag);
- tag.setInt("NoAI", 1);
- nmsEntity.f(tag);
- }
- public boolean VillagerExits() {
- try {
- int x = getConfig().getInt("Villager.Location.X");
- if (x < 0) {
- x = getConfig().getInt("Villager.Location.X") - 1;
- }
- int y = getConfig().getInt("Villager.Location.Y");
- if (y < 0) {
- y = getConfig().getInt("Villager.Location.Y") - 1;
- }
- int z = getConfig().getInt("Villager.Location.Z");
- if (z < 0) {
- z = getConfig().getInt("Villager.Location.Z") - 1;
- }
- for (LivingEntity en : Bukkit.getWorld(getConfig().getString("Villager.Location.World"))
- .getLivingEntities()) {
- if (en.getType() == EntityType.VILLAGER) {
- Location location2 = new Location(en.getWorld(), en.getLocation().getBlockX(),
- en.getLocation().getBlockY(), en.getLocation().getBlockZ());
- if (new Location(Bukkit.getWorld(getConfig().getString("Villager.Location.World")), x, y, z)
- .equals(location2)) {
- if (ChatColor.stripColor(en.getCustomName()).equals(getConfig().getString("Villager.name"))) {
- return true;
- }
- }
- }
- }
- } catch (Exception e) {
- }
- return false;
- }
- public void deleteVillager(Location location) {
- for (LivingEntity en : location.getWorld().getLivingEntities()) {
- if (en.getType() == EntityType.VILLAGER) {
- Location location2 = new Location(en.getWorld(), en.getLocation().getBlockX(),
- en.getLocation().getBlockY(), en.getLocation().getBlockZ());
- int x = getConfig().getInt("Villager.Location.X");
- if (x < 0) {
- x = getConfig().getInt("Villager.Location.X") - 1;
- }
- int y = getConfig().getInt("Villager.Location.Y");
- if (y < 0) {
- y = getConfig().getInt("Villager.Location.Y") - 1;
- }
- int z = getConfig().getInt("Villager.Location.Z");
- if (z < 0) {
- z = getConfig().getInt("Villager.Location.Z") - 1;
- }
- if (new Location(Bukkit.getWorld(getConfig().getString("Villager.Location.World")), x, y, z)
- .equals(location2)) {
- if (ChatColor.stripColor(en.getCustomName()).equals(getConfig().getString("Villager.name"))) {
- en.remove();
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement