Search in sources :

Example 1 with IEntityPet

use of simplepets.brainsynder.api.entity.IEntityPet in project SimplePets by brainsynder-Dev.

the class Info_SubCommand method run.

@Override
public void run(CommandSender sender, String[] args) {
    if (args.length == 0) {
        sendUsage(sender);
    } else {
        Commands commands = PetCore.get().getCommands();
        Player target = Bukkit.getPlayerExact(args[0]);
        if (target == null) {
            sender.sendMessage(PetCore.get().getMessages().getString("Player-Not-Found", true).replace("%player%", args[0]));
            return;
        }
        PetOwner owner = PetOwner.getPetOwner(target);
        if (owner == null)
            return;
        if (args.length > 1) {
            if (args[1].equalsIgnoreCase("debug")) {
                String JSON = findAll(owner).toJSONString();
                Gson gson = new GsonBuilder().disableHtmlEscaping().setPrettyPrinting().create();
                String jsonString = gson.toJson(new JsonParser().parse(JSON));
                CompletableFuture.runAsync(() -> {
                    String url = Utilities.saveTextToHastebin(jsonString);
                    new BukkitRunnable() {

                        @Override
                        public void run() {
                            if (url != null) {
                                sender.sendMessage("§6[§eSimplePets§6] §7" + target.getName() + "'s Pet Data: §e" + ChatColor.GOLD + url + ".json");
                            } else {
                                sender.sendMessage("§cFailed to upload data to Hastebin... Outputting data to Console/Logs...");
                                System.out.println(jsonString);
                            }
                        }
                    }.runTask(PetCore.get());
                });
                return;
            }
        }
        if (!owner.hasPet()) {
            sender.sendMessage(PetCore.get().getMessages().getString("Player-No-Pet", true).replace("%player%", args[0]));
            return;
        }
        sender.sendMessage(commands.getString("Info.Pet-Data-Header").replace("%player%", args[0]));
        IEntityPet entity = owner.getPet().getVisableEntity();
        StorageTagCompound compound = entity.asCompound();
        compound.getKeySet().forEach(key -> {
            if (!commands.getStringList("Info.Excluded-Data-Values").contains(key)) {
                sender.sendMessage(commands.getString("Info.Pet-Data-Values").replace("%key%", WordUtils.capitalize(key.toLowerCase())).replace("%value%", WordUtils.capitalize(fetchValue(compound.getTag(key)).toLowerCase())));
            }
        });
    }
}
Also used : Player(org.bukkit.entity.Player) PetOwner(simplepets.brainsynder.player.PetOwner) GsonBuilder(com.google.gson.GsonBuilder) Commands(simplepets.brainsynder.storage.files.Commands) Gson(com.google.gson.Gson) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) IEntityPet(simplepets.brainsynder.api.entity.IEntityPet) JsonParser(com.google.gson.JsonParser)

Example 2 with IEntityPet

use of simplepets.brainsynder.api.entity.IEntityPet in project SimplePets by brainsynder-Dev.

the class ArmorMenu method update.

public void update(PetOwner owner) {
    if (!isEnabled())
        return;
    if (owner == null)
        return;
    Player player = Bukkit.getPlayer(owner.getUuid());
    if (player.getOpenInventory() == null)
        return;
    Inventory inv = player.getOpenInventory().getTopInventory();
    if (inv.getHolder() == null)
        return;
    if (!(inv.getHolder() instanceof ArmorHolder))
        return;
    getSlots().forEach((slot, item) -> {
        if (item instanceof Air)
            if (item.isEnabled() && item.addItemToInv(owner, this))
                inv.setItem(slot, item.getItemBuilder().build());
    });
    IEntityPet pet = owner.getPet().getEntity();
    if (!(pet instanceof IEntityArmorStandPet))
        return;
    IEntityArmorStandPet stand = (IEntityArmorStandPet) pet;
    inv.setItem(13, stand.getHeadItem());
    inv.setItem(21, stand.getLeftArmItem());
    inv.setItem(22, stand.getBodyItem());
    inv.setItem(23, stand.getRightArmItem());
    inv.setItem(31, stand.getLegItem());
    inv.setItem(40, stand.getFootItem());
}
Also used : Player(org.bukkit.entity.Player) ArmorHolder(simplepets.brainsynder.menu.holders.ArmorHolder) Air(simplepets.brainsynder.menu.items.list.Air) IEntityArmorStandPet(simplepets.brainsynder.api.entity.ambient.IEntityArmorStandPet) IEntityPet(simplepets.brainsynder.api.entity.IEntityPet) CustomInventory(simplepets.brainsynder.menu.inventory.CustomInventory) Inventory(org.bukkit.inventory.Inventory)

Example 3 with IEntityPet

use of simplepets.brainsynder.api.entity.IEntityPet in project SimplePets by brainsynder-Dev.

the class MainListeners method onManipulate.

@EventHandler
public void onManipulate(PlayerArmorStandManipulateEvent e) {
    Object handle = ReflectionUtil.getEntityHandle(e.getRightClicked());
    if (handle instanceof IEntityPet) {
        e.setCancelled(true);
        IEntityPet entityPet = (IEntityPet) handle;
        if (entityPet.getOwner().getName().equals(e.getPlayer().getName())) {
            PetCore.get().getInvLoaders().PET_DATA.open(PetOwner.getPetOwner(entityPet.getOwner()));
        }
    }
}
Also used : IEntityPet(simplepets.brainsynder.api.entity.IEntityPet) EventHandler(org.bukkit.event.EventHandler)

Example 4 with IEntityPet

use of simplepets.brainsynder.api.entity.IEntityPet in project SimplePets by brainsynder-Dev.

the class MainListeners method onInteract.

@EventHandler(priority = EventPriority.MONITOR)
public void onInteract(PlayerInteractAtEntityEvent e) {
    if (!(e.getRightClicked() instanceof Player)) {
        Object handle = ReflectionUtil.getEntityHandle(e.getRightClicked());
        if (handle instanceof IEntityPet) {
            e.setCancelled(true);
            IEntityPet entityPet = (IEntityPet) handle;
            if (entityPet.getOwner().getName().equals(e.getPlayer().getName())) {
                PetCore.get().getInvLoaders().PET_DATA.open(PetOwner.getPetOwner(entityPet.getOwner()));
            }
        }
    }
}
Also used : Player(org.bukkit.entity.Player) IEntityPet(simplepets.brainsynder.api.entity.IEntityPet) EventHandler(org.bukkit.event.EventHandler)

Example 5 with IEntityPet

use of simplepets.brainsynder.api.entity.IEntityPet in project SimplePets by brainsynder-Dev.

the class SpawnUtil method spawn.

public IEntityPet spawn(Location l, IPet pet, String className) {
    try {
        World mcWorld = ((CraftWorld) l.getWorld()).getHandle();
        EntityTypes<?> types = EntityUtils.getType((className.equals("EntityControllerPet")) ? EntityWrapper.ZOMBIE : pet.getEntityType());
        EntityPet customEntity = (EntityPet) petMap.get(className).getDeclaredConstructor(EntityTypes.class, World.class, IPet.class).newInstance(types, mcWorld, pet);
        customEntity.setInvisible(false);
        customEntity.setLocation(l.getX(), l.getY(), l.getZ(), l.getYaw(), l.getPitch());
        mcWorld.addEntity(customEntity, CreatureSpawnEvent.SpawnReason.CUSTOM);
        if (customEntity instanceof IEntityControllerPet) {
            if (pet.getPetType() instanceof ArmorStandDefault) {
                ArmorStand stand = EntityArmorStandPet.spawn(l, ((EntityControllerPet) customEntity));
                stand.setGravity(false);
                stand.setArms(true);
                stand.setCollidable(false);
                stand.setLeftLegPose(new EulerAngle(0.0D, 0.0D, 0.0D));
                stand.setRightLegPose(new EulerAngle(0.0D, 0.0D, 0.0D));
                stand.setLeftArmPose(new EulerAngle(0.0D, 0.0D, 0.0D));
                stand.setRightArmPose(new EulerAngle(0.0D, 0.0D, 0.0D));
                ((IEntityControllerPet) customEntity).setDisplayEntity(stand);
            } else if (pet.getPetType() instanceof ShulkerDefault) {
                ArmorStand stand = EntityGhostStandPet.spawn(l, pet);
                stand.setGravity(false);
                stand.setCollidable(false);
                stand.setSmall(true);
                Shulker shulker = EntityShulkerPet.spawn(l, (EntityControllerPet) customEntity);
                shulker.setAI(false);
                shulker.setCollidable(false);
                ((CraftEntity) stand).getHandle().passengers.add(0, ((CraftEntity) shulker).getHandle());
                ((IEntityControllerPet) customEntity).setDisplayEntity(stand);
            }
        }
        return customEntity;
    } catch (Exception e) {
        e.printStackTrace();
        throw new SimplePetsException("Could not summon the " + pet.getPetType().getConfigName() + " Pet", e);
    }
}
Also used : ShulkerDefault(simplepets.brainsynder.pet.types.ShulkerDefault) CraftEntity(org.bukkit.craftbukkit.v1_13_R2.entity.CraftEntity) CraftWorld(org.bukkit.craftbukkit.v1_13_R2.CraftWorld) World(net.minecraft.server.v1_13_R2.World) Shulker(org.bukkit.entity.Shulker) SimplePetsException(simplepets.brainsynder.errors.SimplePetsException) IEntityControllerPet(simplepets.brainsynder.api.entity.IEntityControllerPet) IEntityPet(simplepets.brainsynder.api.entity.IEntityPet) EntityControllerPet(simplepets.brainsynder.nms.v1_13_R2.entities.list.EntityControllerPet) IEntityControllerPet(simplepets.brainsynder.api.entity.IEntityControllerPet) ArmorStand(org.bukkit.entity.ArmorStand) ArmorStandDefault(simplepets.brainsynder.pet.types.ArmorStandDefault) SimplePetsException(simplepets.brainsynder.errors.SimplePetsException) EulerAngle(org.bukkit.util.EulerAngle) CraftWorld(org.bukkit.craftbukkit.v1_13_R2.CraftWorld)

Aggregations

IEntityPet (simplepets.brainsynder.api.entity.IEntityPet)17 IEntityControllerPet (simplepets.brainsynder.api.entity.IEntityControllerPet)7 ArmorStand (org.bukkit.entity.ArmorStand)6 Player (org.bukkit.entity.Player)6 Shulker (org.bukkit.entity.Shulker)6 EventHandler (org.bukkit.event.EventHandler)6 EulerAngle (org.bukkit.util.EulerAngle)6 SimplePetsException (simplepets.brainsynder.errors.SimplePetsException)6 ArmorStandDefault (simplepets.brainsynder.pet.types.ArmorStandDefault)6 ShulkerDefault (simplepets.brainsynder.pet.types.ShulkerDefault)6 PetOwner (simplepets.brainsynder.player.PetOwner)4 BukkitRunnable (org.bukkit.scheduler.BukkitRunnable)3 Inventory (org.bukkit.inventory.Inventory)2 PetCore (simplepets.brainsynder.PetCore)2 IEntityArmorStandPet (simplepets.brainsynder.api.entity.ambient.IEntityArmorStandPet)2 Gson (com.google.gson.Gson)1 GsonBuilder (com.google.gson.GsonBuilder)1 JsonParser (com.google.gson.JsonParser)1 List (java.util.List)1 World (net.minecraft.server.v1_11_R1.World)1