Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package ru.lisenochek.npcandother.config.configSettings;
- import org.bukkit.Bukkit;
- import org.bukkit.Location;
- import org.bukkit.World;
- import org.bukkit.configuration.file.YamlConfiguration;
- import org.bukkit.entity.Entity;
- import ru.lisenochek.npcandother.API;
- import ru.lisenochek.npcandother.NPC.CreatorNPC;
- import java.io.File;
- import java.io.IOException;
- import java.util.HashMap;
- public class NPC_DiscSettings {
- private static File f = new File(API.getInstance().getDataFolder(), "NPCbase.yml");
- private static YamlConfiguration y = YamlConfiguration.loadConfiguration(f);
- public static void addToConfig() {
- for (HashMap.Entry<String, Entity> map : CreatorNPC.entitySave.entrySet()) {
- String name = map.getKey();
- Entity ent = map.getValue();
- y.set("NPC." + name + ".world", ent.getLocation().getWorld().getName());
- y.set("NPC." + name + ".x", ent.getLocation().getX());
- y.set("NPC." + name + ".y", ent.getLocation().getY());
- y.set("NPC." + name + ".z", ent.getLocation().getZ());
- y.set("NPC." + name + ".yaw", ent.getLocation().getYaw());
- y.set("NPC." + name + ".pitch", ent.getLocation().getPitch());
- if (!CreatorNPC.entitySave.containsValue(ent)) y.set("NPC." + name, null);
- }
- try {
- y.save(new File(API.getInstance().getDataFolder(), "NPCbase.yml"));
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- public static void addCommandToConfig() {
- for (HashMap.Entry<Entity, String> map : CreatorNPC.entityCommand.entrySet()) {
- Entity ent = map.getKey();
- String cmd = map.getValue();
- y.set("NPC." + ent.getName() + ".command", cmd);
- }
- try {
- y.save(new File(API.getInstance().getDataFolder(), "NPCbase.yml"));
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- public static void addToList() {
- for (String s : y.getConfigurationSection("NPC").getKeys(false)) {
- World w = Bukkit.getWorld(y.getString("NPC." + s + ".world"));
- double x = y.getDouble("NPC." + s + ".x");
- double Y = y.getDouble("NPC." + s + ".y");
- double z = y.getDouble("NPC." + s + ".z");
- float yaw = y.getInt("NPC." + s + ".yaw");
- float pitch = y.getInt("NPC." + s + ".pitch");
- String cmd = y.getString("NPC." + s + ".command");
- Location loc = new Location(w, x, Y, z, yaw, pitch);
- for (Entity ent : w.getNearbyEntities(loc, 1.0, 1.0, 1.0)) {
- CreatorNPC.entitySave.put(s, ent);
- CreatorNPC.entityCommand.put(ent, cmd);
- }
- }
- }
- public static void deleteFromDisc(String name) {
- y.set("NPC." + name, null);
- try {
- y.save(new File(API.getInstance().getDataFolder(), "NPCbase.yml"));
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- public static void deleteCommandFromDisc(String name) {
- y.set("NPC." + name + ".command", null);
- try {
- y.save(new File(API.getInstance().getDataFolder(), "NPCbase.yml"));
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement