com.dsh105.commodus.GeneralUtil Java Examples
The following examples show how to use
com.dsh105.commodus.GeneralUtil.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: HoloCommand.java From HoloAPI with GNU General Public License v3.0 | 6 votes |
@Command( command = "holodebug", description = "Smashing bugs and coloring books", permission = "holo.debug" ) public boolean debug(CommandEvent event) { event.respond("Debug results: "); event.respond("--------------[HoloAPI Stuff]--------------"); event.respond("HoloAPI-Version: " + HoloAPI.getCore().getDescription().getVersion()); event.respond("Message of the day: " + messages[GeneralUtil.random().nextInt(messages.length)]); event.respond("--------------[CraftBukkit Stuff]--------------"); event.respond("Version tag: " + MinecraftReflection.getVersionTag()); event.respond("NMS-package: " + MinecraftReflection.getMinecraftPackage()); event.respond("CB-package: " + MinecraftReflection.getCraftBukkitPackage()); event.respond("Bukkit version: " + Bukkit.getBukkitVersion()); event.respond("--------------[Minecraft Server Stuff]--------------"); event.respond("Using Netty: " + MinecraftReflection.isUsingNetty()); event.respond("MinecraftServer: " + MinecraftReflection.getMinecraftClass("MinecraftServer").getCanonicalName()); event.respond("Entity: " + MinecraftReflection.getMinecraftClass("Entity")); event.respond("Is (forge) Modded: " + (MinecraftReflection.getMinecraftClass("Entity").getCanonicalName().startsWith("net.minecraft.entity") ? "Definitely" : "Probably not")); return true; }
Example #2
Source File: ScriptCommand.java From HoloAPI with GNU General Public License v3.0 | 5 votes |
@Command( command = "script editcurrent <line>", description = "Edits a script currently being built. Not intended for general use outside of context.", includeInHelp = false // No permission, as this cannot be called without another command executing it ) public boolean editCurrentScript(CommandEvent event) { if (!(event.sender() instanceof Conversable)) { event.respond(Lang.NOT_CONVERSABLE.getValue()); return true; } ScriptBuilderPrompt scriptBuilder = SCRIPT_EDITORS.get(getIdent((Conversable) event.sender())); if (scriptBuilder == null) { event.respond(Lang.PROMPT_SCRIPT_NOT_EDITING.getValue()); return true; } int line = 0; try { line = GeneralUtil.toInteger(event.variable("line")); } catch (NumberFormatException e) { event.respond(Lang.INT_ONLY.getValue("string", event.variable("line"))); } event.respond(Lang.PROMPT_SCRIPT_LINE_CHANGE.getValue("line", event.variable("line"))); scriptBuilder.setCurrentlyEditing(line); return true; }
Example #3
Source File: SelectorLayout.java From EchoPet with GNU General Public License v3.0 | 5 votes |
public static void loadLayout() { if (selectorMenu != null) { HandlerList.unregisterAll(selectorMenu); } selectorLayout.clear(); YAMLConfig config = ConfigOptions.instance.getConfig(); String s = "petSelector.menu"; int size = config.getInt(s + ".slots"); for (int i = 1; i <= size; i++) { String cmd = config.getString(s + ".slot-" + i + ".command"); String petType = config.getString(s + ".slot-" + i + ".petType"); PetType pt = null; if (petType != null && GeneralUtil.isEnumType(PetType.class, petType.toUpperCase())) { pt = PetType.valueOf(petType.toUpperCase()); } int id = config.getInt(s + ".slot-" + i + ".materialId"); int data = config.getInt(s + ".slot-" + i + ".materialData"); String name = config.getString(s + ".slot-" + i + ".name"); if (name == null) { continue; } List<String> lore = config.config().getStringList(s + ".slot-" + i + ".lore"); if (lore == null) { lore = new ArrayList<String>(); } ArrayList<String> loreList = new ArrayList<String>(); if (lore.size() > 0) { for (String part : lore) { loreList.add(ChatColor.translateAlternateColorCodes('&', part)); } } selectorLayout.add(new SelectorIcon(i - 1, cmd, pt, id, data, name, loreList.toArray(new String[0]))); } selectorMenu = new SelectorMenu(); }
Example #4
Source File: PetMenu.java From EchoPet with GNU General Public License v3.0 | 5 votes |
public PetMenu(IPet pet, ArrayList<MenuOption> options, int size) { this.pet = pet; this.size = size; this.inv = Bukkit.createInventory(pet.getOwner(), size, "EchoPet DataMenu"); this.options = options; for (MenuOption o : this.options) { if (o.item.getMenuType() == DataMenu.DataMenuType.BOOLEAN) { MenuItem mi = o.item; if (GeneralUtil.isEnumType(PetData.class, mi.toString())) { PetData pd = PetData.valueOf(mi.toString()); if (pet.getPetData().contains(pd)) { this.inv.setItem(o.position, o.item.getBoolean(false)); } else { this.inv.setItem(o.position, o.item.getBoolean(true)); } } else { if (mi.toString().equals("HAT")) { if (pet.isHat()) { this.inv.setItem(o.position, o.item.getBoolean(false)); } else { this.inv.setItem(o.position, o.item.getBoolean(true)); } } if (mi.toString().equals("RIDE")) { if (pet.isOwnerRiding()) { this.inv.setItem(o.position, o.item.getBoolean(false)); } else { this.inv.setItem(o.position, o.item.getBoolean(true)); } } } } else { this.inv.setItem(o.position, o.item.getItem()); } } int book = size - 1; this.inv.setItem(book, DataMenuItem.CLOSE.getItem()); }
Example #5
Source File: PetManager.java From EchoPet with GNU General Public License v3.0 | 5 votes |
@Override public void loadRiderFromFile(String type, IPet pet) { if (pet.getOwner() != null) { String path = type + "." + pet.getOwnerIdentification(); if (EchoPet.getConfig(EchoPet.ConfigType.DATA).get(path + ".rider.type") != null) { PetType riderPetType = PetType.valueOf(EchoPet.getConfig(EchoPet.ConfigType.DATA).getString(path + ".rider.type")); String riderName = EchoPet.getConfig(EchoPet.ConfigType.DATA).getString(path + ".rider.name"); if (riderName.equalsIgnoreCase("") || riderName == null) { riderName = riderPetType.getDefaultName(pet.getNameOfOwner()); } if (riderPetType == null) return; if (EchoPet.getOptions().allowRidersFor(pet.getPetType())) { IPet rider = pet.createRider(riderPetType, true); if (rider != null && rider.getEntityPet() != null) { rider.setPetName(riderName); ArrayList<PetData> riderData = new ArrayList<PetData>(); ConfigurationSection mcs = EchoPet.getConfig(EchoPet.ConfigType.DATA).getConfigurationSection(path + ".rider.data"); if (mcs != null) { for (String key : mcs.getKeys(false)) { if (GeneralUtil.isEnumType(PetData.class, key.toUpperCase())) { PetData pd = PetData.valueOf(key.toUpperCase()); riderData.add(pd); } else { Logger.log(Logger.LogLevel.WARNING, "Error whilst loading data Pet Rider Save Data for " + pet.getNameOfOwner() + ". Unknown enum type: " + key + ".", true); } } } if (!riderData.isEmpty()) { setData(pet, riderData.toArray(new PetData[riderData.size()]), true); } } } } } }
Example #6
Source File: SimpleEntityManager.java From EntityAPI with GNU Lesser General Public License v3.0 | 5 votes |
@Override public void despawn(ControllableEntity controllableEntity, DespawnReason reason) { if (controllableEntity.isSpawned()) { controllableEntity.despawn(reason); } if (!controllableEntity.isSpawned()) { Integer id = GeneralUtil.getKeyAtValue(ENTITIES, controllableEntity); if (id != null) { // May have already been removed this.ENTITIES.remove(id); } } }
Example #7
Source File: SimpleImageLoader.java From HoloAPI with GNU General Public License v3.0 | 5 votes |
public void loadImageConfiguration(YAMLConfig config) { KEY_TO_IMAGE_MAP.clear(); URL_UNLOADED.clear(); File imageFolder = new File(HoloAPI.getCore().getDataFolder() + File.separator + "images"); if (!imageFolder.exists()) { imageFolder.mkdirs(); } ConfigurationSection cs = config.getConfigurationSection("images"); if (cs != null) { for (String key : cs.getKeys(false)) { String path = "images." + key + "."; String imagePath = config.getString(path + "path"); int imageHeight = config.getInt(path + "height", 10); String imageChar = config.getString(path + "characterType", ImageChar.BLOCK.getHumanName()); String imageType = config.getString(path + "type", "FILE"); boolean requiresBorder = config.getBoolean(path + "requiresBorder", true); if (!GeneralUtil.isEnumType(ImageLoader.ImageLoadType.class, imageType.toUpperCase())) { HoloAPI.LOG.info("Failed to load image: " + key + ". Invalid image type."); continue; } ImageLoader.ImageLoadType type = ImageLoader.ImageLoadType.valueOf(imageType.toUpperCase()); ImageGenerator generator = findGenerator(type, key, imagePath, imageHeight, imageChar, requiresBorder); if (generator != null) { this.KEY_TO_IMAGE_MAP.put(key, generator); } } } loaded = true; if (!KEY_TO_IMAGE_MAP.isEmpty() || !URL_UNLOADED.isEmpty()) { HoloAPI.LOG.info("Images loaded."); } }
Example #8
Source File: SimpleAnimationLoader.java From HoloAPI with GNU General Public License v3.0 | 5 votes |
public void loadAnimationConfiguration(YAMLConfig config) { KEY_TO_IMAGE_MAP.clear(); URL_UNLOADED.clear(); File imageFolder = new File(HoloAPI.getCore().getDataFolder() + File.separator + "animations"); if (!imageFolder.exists()) { imageFolder.mkdirs(); } ConfigurationSection cs = config.getConfigurationSection("animations"); if (cs != null) { for (String key : cs.getKeys(false)) { String path = "animations." + key + "."; String imagePath = config.getString(path + "path"); if (imagePath == null) { HoloAPI.LOG.info("Failed to load animation: " + key + ". Invalid path"); continue; } int imageHeight = config.getInt(path + "height", 10); int frameRate = config.getInt(path + "frameRate", 10); boolean requiresBorder = config.getBoolean(path + "requiresBorder", true); String imageChar = config.getString(path + "characterType", ImageChar.BLOCK.getHumanName()); String imageType = config.getString(path + "type", "FILE"); if (!GeneralUtil.isEnumType(ImageLoader.ImageLoadType.class, imageType.toUpperCase())) { HoloAPI.LOG.info("Failed to load animation: " + key + ". Invalid image type."); continue; } AnimationLoadType type = AnimationLoadType.valueOf(imageType.toUpperCase()); AnimatedImageGenerator generator = findGenerator(type, key, imagePath, frameRate, imageHeight, imageChar, requiresBorder); if (generator != null) { this.KEY_TO_IMAGE_MAP.put(key, generator); } } } loaded = true; if (!KEY_TO_IMAGE_MAP.isEmpty() || !URL_UNLOADED.isEmpty()) { HoloAPI.LOG.info("Animations loaded."); } }
Example #9
Source File: HelpCommand.java From HoloAPI with GNU General Public License v3.0 | 5 votes |
@Command( command = "help <index>", description = "Retrieve a certain help page of all HoloAPI commands" ) public boolean helpPage(CommandEvent event) { try { HoloAPI.getCommandManager().getHelpService().sendPage(event.sender(), GeneralUtil.toInteger(event.variable("index"))); if (MinecraftReflection.isUsingNetty() && event.sender() instanceof Player) { event.respond(Lang.TIP_HOVER_COMMANDS.getValue()); } } catch (NumberFormatException e) { event.respond(Lang.HELP_INDEX_TOO_BIG.getValue("index", event.variable("index"))); } return true; }
Example #10
Source File: PetMenu.java From SonarPet with GNU General Public License v3.0 | 5 votes |
public PetMenu(IPet pet, ArrayList<MenuOption> options, int size) { this.pet = pet; this.size = size; this.inv = Bukkit.createInventory(pet.getOwner(), size, "EchoPet DataMenu"); this.options = options; for (MenuOption o : this.options) { if (o.item.getMenuType() == DataMenu.DataMenuType.BOOLEAN) { MenuItem mi = o.item; if (GeneralUtil.isEnumType(PetData.class, mi.toString())) { PetData pd = PetData.valueOf(mi.toString()); if (pet.getPetData().contains(pd)) { this.inv.setItem(o.position, o.item.getBoolean(false)); } else { this.inv.setItem(o.position, o.item.getBoolean(true)); } } else { if (mi.toString().equals("HAT")) { if (pet.isHat()) { this.inv.setItem(o.position, o.item.getBoolean(false)); } else { this.inv.setItem(o.position, o.item.getBoolean(true)); } } if (mi.toString().equals("RIDE")) { if (pet.isOwnerRiding()) { this.inv.setItem(o.position, o.item.getBoolean(false)); } else { this.inv.setItem(o.position, o.item.getBoolean(true)); } } } } else { this.inv.setItem(o.position, o.item.getItem()); } } int book = size - 1; this.inv.setItem(book, DataMenuItem.CLOSE.getItem()); }
Example #11
Source File: NearbyCommand.java From HoloAPI with GNU General Public License v3.0 | 5 votes |
@Command( command = "nearby <radius>", description = "View information on all nearby holograms within the specified radius", permission = "holoapi.holo.nearby" ) public boolean command(CommandEvent<Player> event) { int radius; try { radius = GeneralUtil.toInteger(event.variable("radius")); } catch (NumberFormatException e) { event.respond(Lang.INT_ONLY.getValue("string", event.variable("radius"))); return true; } ArrayList<Hologram> nearby = new ArrayList<Hologram>(); for (Hologram hologram : HoloAPI.getManager().getAllComplexHolograms().keySet()) { if (GeometryUtil.getNearbyEntities(hologram.getDefaultLocation(), radius).contains(event.sender())) { nearby.add(hologram); } } if (nearby.isEmpty()) { event.respond(Lang.NO_NEARBY_HOLOGRAMS.getValue("radius", radius)); return true; } event.respond(Lang.HOLOGRAM_NEARBY.getValue("radius", radius)); InfoCommand.info(event.sender(), nearby); if (MinecraftReflection.isUsingNetty()) { event.respond(Lang.TIP_HOVER_PREVIEW.getValue()); } return true; }
Example #12
Source File: EditCommand.java From HoloAPI with GNU General Public License v3.0 | 5 votes |
@Command( command = "edit <id> <line> <content...>", description = "Edit a line of an existing hologram", permission = "holoapi.holo.edit", help = "The content can be more than one word" ) public boolean editWithContent(CommandEvent event) { final Hologram hologram = HoloAPI.getManager().getHologram(event.variable("id")); if (hologram == null) { event.respond(Lang.HOLOGRAM_NOT_FOUND.getValue("id", event.variable("id"))); return true; } int lineNumber; try { lineNumber = GeneralUtil.toInteger(event.variable("line_number")); } catch (NumberFormatException e) { event.respond(Lang.INT_ONLY.getValue("string", event.variable("line_number"))); return true; } if (lineNumber > hologram.getLines().length) { event.respond(Lang.LINE_INDEX_TOO_BIG.getValue("index", event.variable("line_number"))); return true; } hologram.updateLine(lineNumber - 1, event.variable("content")); event.respond(Lang.HOLOGRAM_UPDATE_LINE.getValue("index", lineNumber, "input", ChatColor.translateAlternateColorCodes('&', event.variable("content")))); return true; }
Example #13
Source File: AnimationBuilderInputPrompt.java From HoloAPI with GNU General Public License v3.0 | 5 votes |
@Override protected boolean isInputValid(ConversationContext conversationContext, String s) { if (conversationContext.getSessionData("askingForDelay") == null) { conversationContext.setSessionData("askingForDelay", false); } if (conversationContext.getSessionData("nextFrame") == null) { conversationContext.setSessionData("nextFrame", false); } return !((Boolean) conversationContext.getSessionData("askingForDelay") && !GeneralUtil.isInt(s)) && !(this.first && s.equalsIgnoreCase("DONE")) && !(s.equalsIgnoreCase("NEXT") && this.lines.isEmpty()); }
Example #14
Source File: LocationFunction.java From HoloAPI with GNU General Public License v3.0 | 5 votes |
@Override public boolean isValid(ConversationContext context, String input) { if (input.contains(" ")) { String[] split = input.split("\\s"); if (split.length == 4) { if (Bukkit.getWorld(split[0]) != null) { for (int i = 1; i <= 3; i++) { if (!GeneralUtil.isInt(split[i])) { context.setSessionData("fail_int", true); return false; } } this.location = new Location(Bukkit.getWorld(split[0]), Integer.parseInt(split[1]), Integer.parseInt(split[2]), Integer.parseInt(split[3])); } else { context.setSessionData("fail_world", true); return false; } } else { context.setSessionData("fail_format", true); return false; } } else { context.setSessionData("fail_format", true); return false; } return true; }
Example #15
Source File: PetManager.java From SonarPet with GNU General Public License v3.0 | 5 votes |
@Override public void loadRiderFromFile(String type, IPet pet) { String path = type + "." + pet.getOwnerUUID(); if (EchoPet.getConfig(EchoPet.ConfigType.DATA).get(path + ".rider.type") != null) { ArrayList<PetData> riderData = new ArrayList<>(); PetType riderPetType = PetType.fromDataString(EchoPet.getConfig(EchoPet.ConfigType.DATA).getString(path + ".rider.type"), riderData); String riderName = EchoPet.getConfig(EchoPet.ConfigType.DATA).getString(path + ".rider.name"); if (Strings.isNullOrEmpty(riderName)) { riderName = riderPetType.getDefaultName(pet.getNameOfOwner()); } if (EchoPet.getOptions().allowRidersFor(pet.getPetType())) { IPet rider = pet.createRider(riderPetType, true); if (rider != null && rider.isSpawned()) { rider.setPetName(riderName); ConfigurationSection mcs = EchoPet.getConfig(EchoPet.ConfigType.DATA).getConfigurationSection(path + ".rider.data"); if (mcs != null) { for (String key : mcs.getKeys(false)) { if (GeneralUtil.isEnumType(PetData.class, key.toUpperCase())) { PetData pd = PetData.valueOf(key.toUpperCase()); riderData.add(pd); } else { Logger.log(Logger.LogLevel.WARNING, "Error whilst loading data Pet Rider Save Data for " + pet.getNameOfOwner() + ". Unknown enum type: " + key + ".", true); } } } if (!riderData.isEmpty()) { setData(pet, riderData.toArray(new PetData[riderData.size()]), true); } } } } }
Example #16
Source File: SelectorLayout.java From SonarPet with GNU General Public License v3.0 | 5 votes |
public static void loadLayout() { if (selectorMenu != null) { HandlerList.unregisterAll(selectorMenu); } selectorLayout.clear(); YAMLConfig config = ConfigOptions.instance.getConfig(); String s = "petSelector.menu"; int size = config.getInt(s + ".slots"); for (int i = 1; i <= size; i++) { String cmd = config.getString(s + ".slot-" + i + ".command"); String petType = config.getString(s + ".slot-" + i + ".petType"); PetType pt = null; if (petType != null && GeneralUtil.isEnumType(PetType.class, petType.toUpperCase())) { pt = PetType.valueOf(petType.toUpperCase()); } int id = config.getInt(s + ".slot-" + i + ".materialId"); int data = config.getInt(s + ".slot-" + i + ".materialData"); String name = config.getString(s + ".slot-" + i + ".name"); if (name == null) { continue; } List<String> lore = config.config().getStringList(s + ".slot-" + i + ".lore"); if (lore == null) { lore = new ArrayList<String>(); } ArrayList<String> loreList = new ArrayList<String>(); if (lore.size() > 0) { for (String part : lore) { loreList.add(ChatColor.translateAlternateColorCodes('&', part)); } } Material type = Material.getMaterial(id); selectorLayout.add(new SelectorIcon(i - 1, cmd, pt, ItemData.create(type, data).withDisplayName(name.trim().isEmpty() ? Optional.empty() : Optional.of(name)).withLore(loreList))); } selectorMenu = new SelectorMenu(); }
Example #17
Source File: SimpleHoloManager.java From HoloAPI with GNU General Public License v3.0 | 4 votes |
public ArrayList<String> loadFileData() { ArrayList<String> unprepared = new ArrayList<>(); ConfigurationSection cs = config.getConfigurationSection("holograms"); if (cs != null) { for (String key : cs.getKeys(false)) { String path = "holograms." + key + "."; String worldName = config.getString(path + "worldName"); double x = config.getDouble(path + "x"); double y = config.getDouble(path + "y"); double z = config.getDouble(path + "z"); if (config.get(path + "animatedImage.image") != null) { if (config.getBoolean(path + "animatedImage.image")) { unprepared.add(key); } else { ArrayList<Frame> frameList = new ArrayList<>(); ConfigurationSection frames = config.getConfigurationSection("holograms." + key + ".animatedImage.frames"); if (frames != null) { for (String frameKey : frames.getKeys(false)) { ConfigurationSection lines = config.getConfigurationSection("holograms." + key + ".animatedImage.frames." + frameKey); if (lines != null) { ArrayList<String> tagList = new ArrayList<>(); int delay = config.getInt("holograms." + key + ".animatedImage.frames." + frameKey + ".delay", 5); for (String tagKey : lines.getKeys(false)) { if (!tagKey.equalsIgnoreCase("delay")) { tagList.add(config.getString("holograms." + key + ".animatedImage.frames." + frameKey + "." + tagKey)); } } if (!tagList.isEmpty()) { frameList.add(new Frame(delay, tagList.toArray(new String[tagList.size()]))); } } } } if (!frameList.isEmpty()) { this.loadExtraData(new AnimatedHologramFactory(HoloAPI.getCore()) .withSaveId(key) .withText(new AnimatedTextGenerator(frameList.toArray(new Frame[frameList.size()]))) .withLocation(new Vector(x, y, z), worldName) .build(), key); } } } else { ConfigurationSection cs1 = config.getConfigurationSection("holograms." + key + ".lines"); boolean containsImage = false; if (cs1 != null) { //ArrayList<String> lines = new ArrayList<String>(); HologramFactory hf = new HologramFactory(HoloAPI.getCore()); for (String key1 : cs1.getKeys(false)) { if (GeneralUtil.isInt(key1)) { String type = config.getString(path + "lines." + key1 + ".type"); String value = config.getString(path + "lines." + key1 + ".value"); if (type.equalsIgnoreCase("image")) { containsImage = true; break; } else { hf.withText(value); } } else { HoloAPI.LOG.warning("Failed to load line section of " + key1 + " for Hologram of ID " + key + "."); } } if (containsImage) { unprepared.add(key); continue; } this.loadExtraData(hf.withSaveId(key).withLocation(new Vector(x, y, z), worldName).build(), key); } } } } return unprepared; }
Example #18
Source File: PetManager.java From EchoPet with GNU General Public License v3.0 | 4 votes |
@Override public IPet createPetFromFile(String type, Player p) { if (EchoPet.getOptions().getConfig().getBoolean("loadSavedPets", true)) { String path = type + "." + UUIDMigration.getIdentificationFor(p); if (EchoPet.getConfig(EchoPet.ConfigType.DATA).get(path) != null) { PetType petType = PetType.valueOf(EchoPet.getConfig(EchoPet.ConfigType.DATA).getString(path + ".pet.type")); String name = EchoPet.getConfig(EchoPet.ConfigType.DATA).getString(path + ".pet.name"); if (name.equalsIgnoreCase("") || name == null) { name = petType.getDefaultName(p.getName()); } if (petType == null) return null; if (!EchoPet.getOptions().allowPetType(petType)) { return null; } IPet pi = this.createPet(p, petType, true); if (pi == null) { return null; } //Pet pi = petType.getNewPetInstance(p, petType); //Pet pi = new Pet(p, petType); pi.setPetName(name); ArrayList<PetData> data = new ArrayList<PetData>(); ConfigurationSection cs = EchoPet.getConfig(EchoPet.ConfigType.DATA).getConfigurationSection(path + ".pet.data"); if (cs != null) { for (String key : cs.getKeys(false)) { if (GeneralUtil.isEnumType(PetData.class, key.toUpperCase())) { PetData pd = PetData.valueOf(key.toUpperCase()); data.add(pd); } else { Logger.log(Logger.LogLevel.WARNING, "Error whilst loading data Pet Save Data for " + pi.getNameOfOwner() + ". Unknown enum type: " + key + ".", true); } } } if (!data.isEmpty()) { setData(pi, data.toArray(new PetData[data.size()]), true); } this.loadRiderFromFile(type, pi); forceAllValidData(pi); return pi; } } return null; }
Example #19
Source File: PetManager.java From SonarPet with GNU General Public License v3.0 | 4 votes |
@Override public IPet createPetFromFile(String type, Player p) { if (EchoPet.getOptions().getConfig().getBoolean("loadSavedPets", true)) { String path = type + "." + UUIDMigration.getIdentificationFor(p); if (EchoPet.getConfig(EchoPet.ConfigType.DATA).get(path) != null) { ArrayList<PetData> data = new ArrayList<>(); PetType petType = PetType.fromDataString(EchoPet.getConfig(EchoPet.ConfigType.DATA).getString(path + ".pet.type"), data); String name = EchoPet.getConfig(EchoPet.ConfigType.DATA).getString(path + ".pet.name"); if (Strings.isNullOrEmpty(name)) { name = petType.getDefaultName(p.getName()); } if (!EchoPet.getOptions().allowPetType(petType)) { return null; } IPet pi = this.createPet(p, petType, true); if (pi == null) { return null; } //Pet pi = petType.getNewPetInstance(p, petType); //Pet pi = new Pet(p, petType); pi.setPetName(name); ConfigurationSection cs = EchoPet.getConfig(EchoPet.ConfigType.DATA).getConfigurationSection(path + ".pet.data"); if (cs != null) { for (String key : cs.getKeys(false)) { if (GeneralUtil.isEnumType(PetData.class, key.toUpperCase())) { PetData pd = PetData.valueOf(key.toUpperCase()); data.add(pd); } else { Logger.log(Logger.LogLevel.WARNING, "Error whilst loading data Pet Save Data for " + pi.getNameOfOwner() + ". Unknown enum type: " + key + ".", true); } } } if (!data.isEmpty()) { setData(pi, data.toArray(new PetData[data.size()]), true); } this.loadRiderFromFile(type, pi); forceAllValidData(pi); return pi; } } return null; }