use of com.github.juliarn.npc.profile.Profile in project CloudNet-v3 by CloudNetService.
the class BukkitNPCManagement method createNPC.
private void createNPC(CloudNPC cloudNPC) {
if (!this.isWorldLoaded(cloudNPC)) {
return;
}
Location location = this.toLocation(cloudNPC.getPosition());
NPC npc = new NPC.Builder(new Profile(cloudNPC.getUUID(), cloudNPC.getDisplayName(), cloudNPC.getProfileProperties().stream().map(npcProfileProperty -> new Profile.Property(npcProfileProperty.getName(), npcProfileProperty.getValue(), npcProfileProperty.getSignature())).collect(Collectors.toSet()))).location(location).lookAtPlayer(cloudNPC.isLookAtPlayer()).imitatePlayer(cloudNPC.isImitatePlayer()).spawnCustomizer((spawnedNPC, player) -> {
spawnedNPC.rotation().queueRotate(location.getYaw(), location.getPitch()).send(player);
spawnedNPC.metadata().queue(MetadataModifier.EntityMetadata.SKIN_LAYERS, true).queue(MetadataModifier.EntityMetadata.SNEAKING, false).send(player);
Material material = Material.getMaterial(cloudNPC.getItemInHand());
if (material != null) {
spawnedNPC.equipment().queue(EnumWrappers.ItemSlot.MAINHAND, new ItemStack(material)).send(player);
}
}).build(this.npcPool);
this.npcProperties.put(cloudNPC.getUUID(), new BukkitNPCProperties(cloudNPC, npc.getEntityId(), Bukkit.createInventory(null, this.defaultItems.length, cloudNPC.getDisplayName()), new HashMap<>()));
this.updateNPC(cloudNPC);
}
use of com.github.juliarn.npc.profile.Profile in project CloudNet-v3 by CloudNetService.
the class CloudNPCCommand method editNPC.
private void editNPC(Player player, String[] args) {
this.getNearest(player).ifPresent(cloudNPC -> {
StringBuilder valueBuilder = new StringBuilder();
for (int i = 2; i < args.length; i++) {
valueBuilder.append(args[i]).append(" ");
}
String value = ChatColor.translateAlternateColorCodes('&', valueBuilder.substring(0, valueBuilder.length() - 1));
switch(args[1].toLowerCase()) {
case "infoline":
{
cloudNPC.setInfoLine(value);
break;
}
case "targetgroup":
{
cloudNPC.setTargetGroup(value.split(" ")[0]);
break;
}
case "skinownername":
{
Profile skinProfile = new Profile(value.split(" ")[0]);
if (!skinProfile.complete()) {
player.sendMessage(this.npcManagement.getNPCConfiguration().getMessages().get("command-create-texture-fetch-fail"));
return;
}
cloudNPC.setProfileProperties(skinProfile.getProperties().stream().map(property -> new CloudNPC.NPCProfileProperty(property.getName(), property.getValue(), property.getSignature())).collect(Collectors.toSet()));
break;
}
case "iteminhand":
{
Material itemInHandMaterial = Material.getMaterial(value.toUpperCase());
if (itemInHandMaterial == null) {
player.sendMessage(this.npcManagement.getNPCConfiguration().getMessages().get("command-create-invalid-material"));
return;
}
cloudNPC.setItemInHand(itemInHandMaterial.name());
break;
}
case "shouldlookatplayer":
{
cloudNPC.setLookAtPlayer(value.equalsIgnoreCase("true") || value.equalsIgnoreCase("yes"));
break;
}
case "shouldimitateplayer":
{
cloudNPC.setImitatePlayer(value.equalsIgnoreCase("true") || value.equalsIgnoreCase("yes"));
break;
}
case "displayname":
{
if (value.length() > 16) {
player.sendMessage(this.npcManagement.getNPCConfiguration().getMessages().get("command-create-display-name-too-long"));
return;
}
cloudNPC.setDisplayName(value);
break;
}
case "rightclickaction":
{
try {
NPCAction action = NPCAction.valueOf(value.toUpperCase());
cloudNPC.setRightClickAction(action);
} catch (Exception exception) {
player.sendMessage(this.npcManagement.getNPCConfiguration().getMessages().get("command-edit-invalid-action"));
return;
}
break;
}
case "leftclickaction":
{
try {
NPCAction action = NPCAction.valueOf(value.toUpperCase());
cloudNPC.setLeftClickAction(action);
} catch (Exception exception) {
player.sendMessage(this.npcManagement.getNPCConfiguration().getMessages().get("command-edit-invalid-action"));
return;
}
break;
}
default:
{
this.sendHelp(player);
break;
}
}
this.npcManagement.sendNPCAddUpdate(cloudNPC);
player.sendMessage(this.npcManagement.getNPCConfiguration().getMessages().get("command-edit-success"));
});
}
use of com.github.juliarn.npc.profile.Profile in project NextEconomy by NextPlugins.
the class NPCRunnable method run.
@Override
public void run() {
clearPositions();
if (locationManager.getLocationMap().isEmpty())
return;
ArrayList<SimpleAccount> accounts = new ArrayList<>(rankingStorage.getRankByCoin().values());
val hologramLines = RankingValue.get(RankingValue::hologramArmorStandLines);
val nobodyLines = RankingValue.get(RankingValue::nobodyHologramLines);
for (val entry : locationManager.getLocationMap().entrySet()) {
val position = entry.getKey();
val location = entry.getValue();
if (location == null || location.getWorld() == null)
continue;
val chunk = location.getChunk();
if (!chunk.isLoaded())
chunk.load(true);
SimpleAccount account = position - 1 < accounts.size() ? accounts.get(position - 1) : null;
if (account == null) {
if (!nobodyLines.isEmpty()) {
val hologramLocation = location.clone().add(0, 3, 0);
if (holographicDisplays) {
val hologram = HologramsAPI.createHologram(plugin, hologramLocation);
for (val nobodyLine : nobodyLines) {
hologram.appendTextLine(nobodyLine.replace("$position", String.valueOf(position)));
}
} else {
val cmiHologram = new CMIHologram("NextEconomy" + position, hologramLocation);
for (val nobodyLine : nobodyLines) {
cmiHologram.addLine(nobodyLine.replace("$position", String.valueOf(position)));
}
CMI.getInstance().getHologramManager().addHologram(cmiHologram);
cmiHologram.update();
HOLOGRAMS.add("NextEconomy" + position);
}
}
} else {
if (!hologramLines.isEmpty()) {
val group = plugin.getGroupWrapperManager().getGroup(account.getUsername());
val format = account.getBalanceFormated();
val hologramLocation = location.clone().add(0, 3, 0);
if (holographicDisplays) {
val hologram = HologramsAPI.createHologram(plugin, hologramLocation);
for (val hologramLine : hologramLines) {
hologram.appendTextLine(hologramLine.replace("$position", String.valueOf(position)).replace("$player", account.getUsername()).replace("$prefix", group.getPrefix()).replace("$suffix", group.getSuffix()).replace("$amount", format));
}
} else {
val cmiHologram = new CMIHologram("NextEconomy" + position, hologramLocation);
for (val hologramLine : hologramLines) {
cmiHologram.addLine(hologramLine.replace("$position", String.valueOf(position)).replace("$player", account.getUsername()).replace("$prefix", group.getPrefix()).replace("$suffix", group.getSuffix()).replace("$amount", format));
}
CMI.getInstance().getHologramManager().addHologram(cmiHologram);
cmiHologram.update();
HOLOGRAMS.add("NextEconomy" + position);
}
}
}
val skinName = account == null ? "Yuhtin" : account.getUsername();
val profile = new Profile(skinName);
profile.complete();
profile.setName("");
profile.setUniqueId(new UUID(RANDOM.nextLong(), 0));
val npc = NPC.builder().profile(profile).location(location).imitatePlayer(false).lookAtPlayer(false).build(npcPool);
if (animation) {
val spawnAnimationRaw = AnimationValue.get(AnimationValue::spawnEmote);
executeAnimation(npc, spawnAnimationRaw);
}
}
}
use of com.github.juliarn.npc.profile.Profile in project CloudNet-v3 by CloudNetService.
the class CloudNPCCommand method createNPC.
private void createNPC(Player player, String[] args) {
Material itemInHandMaterial = Material.getMaterial(args[3].toUpperCase());
if (itemInHandMaterial == null) {
player.sendMessage(this.npcManagement.getNPCConfiguration().getMessages().get("command-create-invalid-material"));
return;
}
boolean lookAtPlayer = args[4].equalsIgnoreCase("true") || args[4].equalsIgnoreCase("yes");
boolean imitatePlayer = args[5].equalsIgnoreCase("true") || args[5].equalsIgnoreCase("yes");
Profile skinProfile = new Profile(args[2]);
if (!skinProfile.complete()) {
player.sendMessage(this.npcManagement.getNPCConfiguration().getMessages().get("command-create-texture-fetch-fail"));
return;
}
StringBuilder displayNameBuilder = new StringBuilder();
for (int i = 6; i < args.length; i++) {
displayNameBuilder.append(args[i]).append(" ");
}
String displayName = displayNameBuilder.substring(0, displayNameBuilder.length() - 1);
if (displayName.length() > 16) {
player.sendMessage(this.npcManagement.getNPCConfiguration().getMessages().get("command-create-display-name-too-long"));
return;
}
Location location = player.getLocation();
CloudNPC cloudNPC = new CloudNPC(new UUID(RANDOM.nextLong(), 0), ChatColor.translateAlternateColorCodes('&', displayName), DEFAULT_INFO_LINE, skinProfile.getProperties().stream().map(property -> new CloudNPC.NPCProfileProperty(property.getName(), property.getValue(), property.getSignature())).collect(Collectors.toSet()), new WorldPosition(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch(), location.getWorld().getName(), this.npcManagement.getOwnNPCConfigurationEntry().getTargetGroup()), args[1], itemInHandMaterial.name(), lookAtPlayer, imitatePlayer);
this.npcManagement.sendNPCAddUpdate(cloudNPC);
player.sendMessage(this.npcManagement.getNPCConfiguration().getMessages().get("command-create-success"));
}
Aggregations