Bukkit编程之动态向yml文件中添加属性
yaml = new Yaml();
String goods = args[0];
String goodsNum = args[1]; YamlConfiguration yc = new YamlConfiguration();
try {
yc.load(new File(System.getProperty("user.dir")+"/plugins/PbMainPlugin/configDef.yml"));
} catch (FileNotFoundException e1) { e1.printStackTrace();
} catch (IOException e1) { e1.printStackTrace();
} catch (InvalidConfigurationException e1) { e1.printStackTrace();
} Set set = yc.getConfigurationSection("drop").getKeys(false); lastDropNum = set.size(); //查看yml文件中是否有内容,没有内容返回0,否则返回内容长度 player.sendMessage("大小是:"+set.size()+"");
player.sendMessage("内容是:"+set+"");
YamlConfiguration yamlConfiguration = new YamlConfiguration();
if(lastDropNum==0) { //如果原来yml文件中没有内容 ConfigurationSection drop = yamlConfiguration.createSection("drop"); Map<String, Object> item = new HashMap();
item.put("item-Id", Material.valueOf(goods.trim()).getId());
item.put("item-Name", Material.valueOf(goods.trim()).name());
drop.createSection("1",item);
try { yamlConfiguration.save(System.getProperty("user.dir")+"/plugins/PbMainPlugin/configDef.yml");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} } if(lastDropNum!=0) { //如果yml中有内容,则向yml文件中追加新的内容
yamlConfiguration = YamlConfiguration.loadConfiguration(new File(System.getProperty("user.dir")+"/plugins/PbMainPlugin/configDef.yml"));
ConfigurationSection drop = yamlConfiguration.getConfigurationSection("drop");
Map<String, Object> item = new HashMap();
item.put("item-Id", Material.valueOf(goods.trim()).getId());
item.put("item-Name", Material.valueOf(goods.trim()).name());
drop.set((lastDropNum+1)+"", item);
try {
yamlConfiguration.save(System.getProperty("user.dir")+"/plugins/PbMainPlugin/configDef.yml");
} catch (IOException e) { e.printStackTrace();
} } //向玩家背包中添加物品
PlayerInventory inventory = player.getInventory();
ItemStack itemStack = new ItemStack(Material.valueOf(goods.trim()),Integer.parseInt(goodsNum));
inventory.addItem(itemStack);
return true;
yml文件中的结构为:

Bukkit编程之动态向yml文件中添加属性的更多相关文章
- 你有没有觉得邮件发送人固定配置在yml文件中是不妥当的呢?SpringBoot 动态设置邮件发送人
明月当天,不知道你有没有思念的人 前言 之前其实已经写过SpringBoot异步发送邮件,但是今天在一个小项目中要用到发送邮件时,我突然觉得邮件发送人只有一个,并且固定写在yml文件中,就是非常的不妥 ...
- Spring boot中普通工具类不能使用@Value注入yml文件中的自定义参数的问题
在写一个工具类的时候,因为要用到yml中的自定义参数,使用@Value发现值不能正常注入,都显示为null: yml文件中的自定义格式 调用工具类的时候不能new的方式 要使用@Autowired的方 ...
- Springboot读取自定义的yml文件中的List对象
Yml文件(novellist.xml)如下: novellist: list: - name: 笑傲江湖 type: 武侠 master: 令狐冲 a ...
- springboot2.0application.在yml文件中添加自定义配置
1. 在application.yml文件中添加自定义配置 app: platform: version: code: '1.0.0' 2. 定义bean类 具体格式: 其中的成员变量名称需要与配 ...
- linux向文件中添加数据,数据被追加到了上一行的行尾
当我们在windows上新建了文件,并且要上传到linux上时,一定要在文件后加上空格,否则就会出现标题上讲的,数据被追加到了上一行的行尾,而不是新起一行,但是如果是在linux上新建的文件,则没有这 ...
- 如何在maven项目的pom.xml文件中添加jar包
在使用maven进行项目开发时,我们需要在pom.xml文件中添加自己所需要的jar包.这就要求我们获取jar包的groupId和artifactId. 我们可以在一些maven仓库上搜索我们所需要的 ...
- VS2010在C#头文件中添加文件注释的方法
步骤: 1.VS2010 中找到安装盘符(本人安装目录在D盘,所以以D盘为例)D:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\I ...
- 向php文件中添加php.ini文件
向php文件中添加php.ini文件 默认情况下,php是没有php.ini配置文件的,必须手工添加php.ini文件 在php安装目录中,复制php.ini文件到/usr/local/php/lib ...
- gitignore文件中添加新过滤文件,但是此文件已经提交,如何解决?
gitignore文件中添加新过滤文件,但是此文件已经提交到远程库,如何解决? 第一步,为避免冲突需要先同步下远程仓库 git pull 第二步,在本地项目目录下删除缓存 git rm -r --ca ...
随机推荐
- 多线程调试DLL
http://blog.csdn.net/wfq_1985/article/details/7303825
- NOIP 2018 day1 题解
今年noip的题和去年绝对是比较坑的题了,但是打好的话就算是普通水准也能350分以上吧. t1: 很显然这是一个简单的dp即可. #include<iostream> #include&l ...
- 转:Redis 3.2.1集群搭建
Redis 3.2.1集群搭建 一.概述 Redis3.0版本之后支持Cluster. 1.1.redis cluster的现状 目前redis支持的cluster特性: 1):节点自动发现 2) ...
- SpringMVC 的使用映射路径 <mvc:resources >
以下是测试结果,可能存在纰漏,暂记录一下. 使用springMVC时,一般将DispatcherServlet请求映射配置为"/",则Spring MVC将捕获Web容器所有的请求 ...
- /etc/passwd- 和/etc/shadow-文件
今天偶尔看到系统里有/etc/passwd- 和/etc/shadow-文件,经测试只要执行过系统的用户操作命令就会产生,如deluser.passwd.chpasswd.adduser等命令,应该是 ...
- 按键控制led驱动
内核版本:linux2.6.22.6 硬件平台:JZ2440 驱动源码 key_drv.c : #include<linux/module.h> #include<linux/ker ...
- mint-ui是什么?怎么使用?说出至少三个组件使用方法?
mint-ui是基于vue的前端组件库.npm安装,然后import样式和js,vue.use(mintUi)全局引入.在单个组件局部引入:import { Toast } from 'mint-ui ...
- struts2 中的 addActionError 、addFieldError、addActionMessage的方法【转】
一.addActionError("错误内容"): Action级别的错误消息this.addActionError("错误信息1");this.addAct ...
- grub启动流程和配置
grub stage 1 MBR中前 446个字节,如果把这里面的内容损坏,那么系统会认为当前磁盘没有启动引导功能,会尝试从光盘或者网络启动系统 grub stage 1.5 存放识别/boot ...
- 007-js中的Array常用方法
原文:http://www.runoob.com/jsref/jsref-obj-array.html 摘要常用方法 const array=new Array(); // 1 增加元素 // 1.1 ...