Search in sources :

Example 1 with Profile

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);
}
Also used : CloudNPC(eu.cloudnetservice.cloudnet.ext.npcs.CloudNPC) NPC(com.github.juliarn.npc.NPC) java.util(java.util) ItemMeta(org.bukkit.inventory.meta.ItemMeta) EnumWrappers(com.comphenix.protocol.wrappers.EnumWrappers) NPCConfiguration(eu.cloudnetservice.cloudnet.ext.npcs.configuration.NPCConfiguration) AbstractNPCManagement(eu.cloudnetservice.cloudnet.ext.npcs.AbstractNPCManagement) WorldPosition(de.dytanic.cloudnet.ext.bridge.WorldPosition) Profile(com.github.juliarn.npc.profile.Profile) Location(org.bukkit.Location) NPCConfigurationEntry(eu.cloudnetservice.cloudnet.ext.npcs.configuration.NPCConfigurationEntry) NPCPool(com.github.juliarn.npc.NPCPool) Material(org.bukkit.Material) Bukkit(org.bukkit.Bukkit) CloudNPC(eu.cloudnetservice.cloudnet.ext.npcs.CloudNPC) ServiceInfoSnapshot(de.dytanic.cloudnet.driver.service.ServiceInfoSnapshot) Entity(org.bukkit.entity.Entity) NPC(com.github.juliarn.npc.NPC) Pair(de.dytanic.cloudnet.common.collection.Pair) EntityType(org.bukkit.entity.EntityType) Collectors(java.util.stream.Collectors) MetadataModifier(com.github.juliarn.npc.modifier.MetadataModifier) ItemStack(org.bukkit.inventory.ItemStack) JavaPlugin(org.bukkit.plugin.java.JavaPlugin) BridgeServiceProperty(de.dytanic.cloudnet.ext.bridge.BridgeServiceProperty) ArmorStand(org.bukkit.entity.ArmorStand) NotNull(org.jetbrains.annotations.NotNull) ServiceLifeCycle(de.dytanic.cloudnet.driver.service.ServiceLifeCycle) Material(org.bukkit.Material) ItemStack(org.bukkit.inventory.ItemStack) Profile(com.github.juliarn.npc.profile.Profile) Location(org.bukkit.Location)

Example 2 with Profile

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"));
    });
}
Also used : CloudNetDriver(de.dytanic.cloudnet.driver.CloudNetDriver) CloudNPC(eu.cloudnetservice.cloudnet.ext.npcs.CloudNPC) CommandSender(org.bukkit.command.CommandSender) java.util(java.util) TabCompleter(org.bukkit.command.TabCompleter) Player(org.bukkit.entity.Player) CommandExecutor(org.bukkit.command.CommandExecutor) Collectors(java.util.stream.Collectors) ComponentBuilder(net.md_5.bungee.api.chat.ComponentBuilder) Nullable(org.jetbrains.annotations.Nullable) BaseComponent(net.md_5.bungee.api.chat.BaseComponent) WorldPosition(de.dytanic.cloudnet.ext.bridge.WorldPosition) Profile(com.github.juliarn.npc.profile.Profile) NPCAction(eu.cloudnetservice.cloudnet.ext.npcs.NPCAction) Location(org.bukkit.Location) ChatColor(org.bukkit.ChatColor) Command(org.bukkit.command.Command) NotNull(org.jetbrains.annotations.NotNull) GroupConfiguration(de.dytanic.cloudnet.driver.service.GroupConfiguration) Material(org.bukkit.Material) BukkitNPCManagement(eu.cloudnetservice.cloudnet.ext.npcs.bukkit.BukkitNPCManagement) Material(org.bukkit.Material) NPCAction(eu.cloudnetservice.cloudnet.ext.npcs.NPCAction) Profile(com.github.juliarn.npc.profile.Profile)

Example 3 with Profile

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);
        }
    }
}
Also used : SimpleAccount(com.nextplugins.economy.model.account.SimpleAccount) lombok.val(lombok.val) AnimationValue(com.nextplugins.economy.configuration.AnimationValue) CMIHologram(com.Zrips.CMI.Modules.Holograms.CMIHologram) RankingValue(com.nextplugins.economy.configuration.RankingValue) ArrayList(java.util.ArrayList) UUID(java.util.UUID) Profile(com.github.juliarn.npc.profile.Profile)

Example 4 with Profile

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"));
}
Also used : WorldPosition(de.dytanic.cloudnet.ext.bridge.WorldPosition) CloudNPC(eu.cloudnetservice.cloudnet.ext.npcs.CloudNPC) Material(org.bukkit.Material) Profile(com.github.juliarn.npc.profile.Profile) Location(org.bukkit.Location)

Aggregations

Profile (com.github.juliarn.npc.profile.Profile)4 WorldPosition (de.dytanic.cloudnet.ext.bridge.WorldPosition)3 CloudNPC (eu.cloudnetservice.cloudnet.ext.npcs.CloudNPC)3 Location (org.bukkit.Location)3 Material (org.bukkit.Material)3 java.util (java.util)2 Collectors (java.util.stream.Collectors)2 NotNull (org.jetbrains.annotations.NotNull)2 CMIHologram (com.Zrips.CMI.Modules.Holograms.CMIHologram)1 EnumWrappers (com.comphenix.protocol.wrappers.EnumWrappers)1 NPC (com.github.juliarn.npc.NPC)1 NPCPool (com.github.juliarn.npc.NPCPool)1 MetadataModifier (com.github.juliarn.npc.modifier.MetadataModifier)1 AnimationValue (com.nextplugins.economy.configuration.AnimationValue)1 RankingValue (com.nextplugins.economy.configuration.RankingValue)1 SimpleAccount (com.nextplugins.economy.model.account.SimpleAccount)1 Pair (de.dytanic.cloudnet.common.collection.Pair)1 CloudNetDriver (de.dytanic.cloudnet.driver.CloudNetDriver)1 GroupConfiguration (de.dytanic.cloudnet.driver.service.GroupConfiguration)1 ServiceInfoSnapshot (de.dytanic.cloudnet.driver.service.ServiceInfoSnapshot)1