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())));
}
});
}
}
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());
}
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()));
}
}
}
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()));
}
}
}
}
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);
}
}
Aggregations