Ir para conteúdo

Preciso de ajuda urgente com meu plugin.


R.A

Posts Recomendados

 

Erros:

package rodrigo.rcacada.comandos;

import java.util.ArrayList;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.ArmorStand;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.util.EulerAngle;

import rodrigo.rcacada.Main;
import rodrigo.rcacada.apis.ItemBuilder;

public class NPCCacada implements CommandExecutor {

	public static FileConfiguration cache = Main.getPlugin(Main.class).getConfig();
	public static Main main = Main.getPlugin(Main.class);
	ArrayList<String> entitys = new ArrayList<String>();

	@Override
	public boolean onCommand(CommandSender s, Command cmd, String lbl, String[] args) {
		if (!(s instanceof Player)) {
			s.sendMessage("§cApenas jogadores podem executar este comando.");
			return false;
		}

		Player p = (Player) s;

		if (args.length == 0) {
			p.sendMessage("§cSintaxe incorreta, utilize:");
			p.sendMessage("  §c▪ /npccacada criar <id>");
			p.sendMessage("  §c▪ /npccacada remover <id>");
			return true;
		}

		if (args.length >= 1) {
			if (args[0].equalsIgnoreCase("criar")) {
				if (args.length < 2) {
					p.sendMessage("§cSintaxe incorreta, use /npccacada criar <id>");
				} else {
					int id = 0;
					try {
						id = Integer.parseInt(args[1]);
					} catch (NumberFormatException e) {
						p.sendMessage("§cOs IDs só podem ser constituidos de números.");
						return true;
					}

					if (cache.get("npcs." + id) != null) {
						p.sendMessage("§cJá existe um npc com este ID, remova-o ou escolha outro ID.");
						return true;
					}

					ArmorStand npc = (ArmorStand) p.getWorld().spawnEntity(p.getLocation(), EntityType.ARMOR_STAND);
					npc.setArms(true);
					npc.setBasePlate(false);
					npc.setCanPickupItems(false);
					npc.setLeftLegPose(new EulerAngle(Math.toRadians(0), Math.toRadians(0), Math.toRadians(348)));
					npc.setLeftArmPose(new EulerAngle(Math.toRadians(0), Math.toRadians(0), Math.toRadians(348)));
					npc.setRightLegPose(new EulerAngle(Math.toRadians(0), Math.toRadians(0), Math.toRadians(12)));
					npc.setRightArmPose(new EulerAngle(Math.toRadians(0), Math.toRadians(0), Math.toRadians(12)));
					npc.setItemInHand(new ItemBuilder(Material.DIAMOND_SWORD).glow().build());
					npc.setHelmet(new ItemBuilder(Material.SKULL_ITEM, 1, (short) 3).head(
							"http://textures.minecraft.net/texture/c09741fca109c4cb0b5efaa0634616503051a199e1d44e4e1149ede0bdc49c8a")
							.glow().build());
					npc.setChestplate(new ItemBuilder(Material.DIAMOND_CHESTPLATE).glow().build());
					npc.setLeggings(new ItemBuilder(Material.DIAMOND_LEGGINGS).glow().build());
					npc.setBoots(new ItemBuilder(Material.DIAMOND_BOOTS).glow().build());

					ArmorStand hd1 = (ArmorStand) p.getWorld().spawnEntity(p.getLocation().add(0, 0.9, 0),
							EntityType.ARMOR_STAND);
					hd1.setVisible(false);
					hd1.setGravity(false);
					hd1.setCanPickupItems(false);
					hd1.setCustomNameVisible(true);
					hd1.setCustomName("§c§lCAÇADA");

					ArmorStand hd2 = (ArmorStand) p.getWorld().spawnEntity(p.getLocation().add(0, 0.6, 0),
							EntityType.ARMOR_STAND);
					hd2.setVisible(false);
					hd2.setGravity(false);
					hd2.setCanPickupItems(false);
					hd2.setCustomNameVisible(true);
					hd2.setCustomName("§7Complete os desafios e receba");

					ArmorStand hd3 = (ArmorStand) p.getWorld().spawnEntity(p.getLocation().add(0, 0.3, 0),
							EntityType.ARMOR_STAND);
					hd3.setVisible(false);
					hd3.setGravity(false);
					hd3.setCanPickupItems(false);
					hd3.setCustomNameVisible(true);
					hd3.setCustomName("§7recompensas §bRaras§7, §dÉpicas");

					ArmorStand hd4 = (ArmorStand) p.getWorld().spawnEntity(p.getLocation().add(0, 0, 0),
							EntityType.ARMOR_STAND);
					hd4.setVisible(false);
					hd4.setGravity(false);
					hd4.setCanPickupItems(false);
					hd4.setCustomNameVisible(true);
					hd4.setCustomName("§7ou §6Lendárias§7.");
					p.sendMessage("§aSucesso! O npc foi gerado com o ID §7" + id + "§a.");

					entitys.add(npc.getUniqueId().toString());
					entitys.add(hd1.getUniqueId().toString());
					entitys.add(hd2.getUniqueId().toString());
					entitys.add(hd3.getUniqueId().toString());
					entitys.add(hd4.getUniqueId().toString());

					cache.set("npcs." + id, entitys);
					cache.options().copyDefaults(true);
					main.saveConfig();
					entitys.clear();
				}
			} else if (args[0].equalsIgnoreCase("remover")) {
				if (args.length < 2) {
					p.sendMessage("§cSintaxe incorreta, use /npccacada remover <id>");
				} else {
					int id = 0;
					try {
						id = Integer.parseInt(args[1]);
					} catch (NumberFormatException e) {
						p.sendMessage("§cOs IDs só podem ser constituidos de números.");
						return true;
					}

					if (cache.get("npcs." + id) == null) {
						p.sendMessage("§cO npc com ID §7" + id + " §cnão foi encontrado.");
						return true;
					}
					
					for (String uuid : cache.getStringList("npcs." + id)) {
						removeEntityByUniqueId(uuid);
					}
					
					cache.set("npcs." + id, null);
					cache.options().copyDefaults(true);
					main.saveConfig();
					p.sendMessage("§aSucesso! §aO npc com ID §7" + id + " §afoi removido.");
				}
			}
		} else {
			p.sendMessage("§cSintaxe incorreta, utilize:");
			p.sendMessage("§c▪ /npccacada criar");
			p.sendMessage("§c▪ /npccacada <remover> <id>");
		}

		return false;
	}

	private void removeEntityByUniqueId(String uuid) {
		for (World world : Bukkit.getWorlds()) {
			for (Entity entity : world.getEntities()) {
				if (entity.getUniqueId().toString().equals(uuid))
					entity.remove();
			}
		}
	}
}

 

Link para o comentário
Compartilhar em outros sites

3 horas atrás, iNinjaaaZ disse:

Refaça esse sistema de armazenamento, eu usei uma hashmap para armazenar o id e a entity

eGnisdR.gif

Entendi, e ai você salva a HashMap na config, e quando o servidor inicia passa a hashmap da config para uma nova hashmap, e quando desliga salva essa hashmap na config?

Link para o comentário
Compartilhar em outros sites

Visitante
Este tópico está impedido de receber novos posts.
×
×
  • Criar Novo...