[Bukkit Plugin Dev]学习笔记一:搭建环境及创建自己的第一个插件与模板

1.工具

JDK:插件开发自然少不了Java语言,所以前提还是得懂得基础的Java开发才行

Maven:水桶服的插件项目是用Maven工具来进行管理的,所以少不了

EclipseIntelliJ IDEANetBeans:开发工具IDE,三选一就行了,哪个顺手用哪个或想学哪个用哪个了,随意

Git:使用Git或者其他的版本管理工具来管理你的项目,可选

工具的安装就不讲了,百度一下就有不少资料了。(旧版本的Eclipse可能没有集成M2Eclipse插件,所以需要自己弄一下,不过较新版本的Eclipse就没这烦恼)

阅读全文 »

关于pip的一些问题

当在 pypi 找包来安装的时候我们需要先为Python安装 pip 才行,按照这个链接的方法安装完后(记得在环境变量PATH加上python安装目录下的Scripts 文件夹如:D:\Program Files\Python2\Scripts\),运行时出现:

1
Fatal error in launcher: Unable to create process using '""D:\Program Files\Python2\python.exe"" "D:\Program Files\Python2\Scripts\pip.exe" '

关于这问题 这里 有一些讨论。

在这些讨论里有人提到了 pip Installation 教程里有提到:

1
python -m pip install -U pip

那么我们就可以另辟蹊径了

在 python 安装目录下的 Scripts 文件夹里新建一个 pip.bat 文件 里面可以这么写:

1
python -m pip %1 %2 %3 %4 %5 %6 %7 %8 %9

还要记得把原来 Scripts 文件夹下的 pip.exe 删除或者改名

这样我们就可以直接使用

1
pip install package

来安装我们想要的包了

============================

关于安装包的问题,用pip可能会因网络问题而安装不了,那么就可以直接下载该包,解压后里面有一个 setup.py

在命令行下输入

1
python setup.py install

就可以安装了

Android 在launcher上添加及删除Shortcut方法

需要在Manifest里添加两个权限:

1
2
<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />
<uses-permission android:name="com.android.launcher.permission.UNINSTALL_SHORTCUT" />

添加完就可以照搬下面的代码来实现了

添加Shortcut:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
Intent intent1 = new Intent("android.intent.action.MAIN");
//替换自己项目的
intent1.setClass(MainActivity.this,MainActivity.class);
intent1.addCategory("android.intent.category.LAUNCHER");

Intent intent2 = new Intent();
intent2.putExtra("android.intent.extra.shortcut.INTENT",intent1);
//把Shortcut的名字改为自己项目的
intent2.putExtra("android.intent.extra.shortcut.NAME","MainActivity");
//把context改为自己项目的
intent2.putExtra("android.intent.extra.shortcut.ICON_RESOURCE",Intent.ShortcutIconResource.fromContext(MainActivity.this, R.drawable.icon));
//这里的覆盖参数不管设置为true还是false都没啥效果,不知是为何
intent2.putExtra("duplicate", false);
intent2.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
sendOrderedBroadcast(intent2, null);

删除Shortcut:

1
2
3
4
5
6
7
8
9
10
11
12
13
Intent intent1 = new Intent("android.intent.action.MAIN");
//替换为自己项目的
intent1.setClass(MainActivity.this,MainActivity.class);
intent1.addCategory("android.intent.category.LAUNCHER");

Intent intent2 = new Intent();
intent2.putExtra("android.intent.extra.shortcut.INTENT",intent1);
//把Shortcut的名字改为自己项目的
intent2.putExtra("android.intent.extra.shortcut.NAME","MainActivity");
//把context改为自己项目的. ps:此处不设置图标也无所谓
intent2.putExtra("android.intent.extra.shortcut.ICON_RESOURCE",Intent.ShortcutIconResource.fromContext(MainActivity.this, R.drawable.icon));
intent2.setAction("com.android.launcher.action.UNINSTALL_SHORTCUT");
sendOrderedBroadcast(intent2, null);

获取 Android 自定义资源文件调用URI

在设置Notification的时候,有时会自己提供一个音乐文件,这是就需要在raw文件夹下存一个音乐文件,并在程序里面调用它,那么调用raw文件夹下的文件的方法就很重要了,做法很简单:

1
Uri.parse("android.resource://包名/"+资源ID);

例如:

1
Uri.parse("android.resource://cn.decay.notification/"+R.raw.ring);

这样就能得到资源的URI了,剩下的就不难弄了。