• 欢迎来到Minecraft插件百科!
  • 对百科编辑一脸懵逼?帮助:快速入门带您快速熟悉百科编辑!
  • 因近日遭受攻击,百科现已限制编辑,有意编辑请加入插件百科企鹅群:223812289

“Bukkit/插件开发教程”的版本间的差异

来自Minecraft插件百科
跳转至: 导航搜索
(添加原文)
(完成翻译)
第36行: 第36行:
  
 
点击工程名称右边的箭头来进行下一步,现在我们正式开始。
 
点击工程名称右边的箭头来进行下一步,现在我们正式开始。
=== Reference the Bukkit API ===
+
=== 添加Bukkit API ===
  
Before you begin developing your plugin you will need to add the Bukkit API library to your project as a dependency, you can also add any other API's you may want to use.
+
在开发插件之前,你需要添加 Bukkit API库文件到你的项目,作为一个dependency, 你也可以添加其他你想实用的API.
  
Double-click ''pom.xml'', which is at the bottom of your project's folder. Click the ''pom.xml'' tab at the bottom, and you should see something like this:
+
找到项目文件夹中部的''pom.xml''并双击进行编辑. 点击''pom.xml''中部的 tab,你将会看到下图所示内容:
  
 
[[Image:Pomeditor.png]]
 
[[Image:Pomeditor.png]]
  
If you wish to use Java 6+ language features, you must specify the Java version that the project should be built on. Copy and paste this (specifies that the project should be built under Java 7) before ''</project>'':  
+
如果你想使用Java 6以上版本的语言特性,你需要指定搭建项目的Java版本.复制并粘贴以下内容(设定项目只能使用Java 7及以下的版本)''</project>''之前:  
  
 
<code>
 
<code>
第61行: 第61行:
 
</code>
 
</code>
  
You may use other levels, such as <code>1.8</code> for Java 8. Please note that [http://mcstats.org/global/ according to MCStats], the vast majority of server owners run Java 7, so compiling for Java 8 will result in most server owners being unable to run your plugin. If you do use Java 1.7 features, Eclipse will suggest changing the language level when you hover over the code "error". Do so.
+
你或许想使用其他版本,例如 <code>1.8</code> 使用Java 8. 请注意 [http://mcstats.org/global/ 根据MCStats数据统计], 大多数服主选择了Java 7, 所以使用Java 8会使许多服务器无法运行你的插件. 如果你使用Java 1.7的特性, Eclipse将会在报错代码"error"中建议你更改语言版本.同意即可.
  
Before the ''</project>'' at the bottom, copy and paste this block (it tells Eclipse where Bukkit's repository is located):  
+
在位于代码中段的''</project>''之前粘贴以下内容(这段代码告诉Eclipse关于Bukkit's repository的地址):  
  
 
<code>
 
<code>
第74行: 第74行:
 
</code>
 
</code>
  
Next, before the ''</project>'' at the bottom, copy and paste this block (it tells Eclipse that we're building against Bukkit):  
+
然后继续在 ''</project>''前粘贴以下内容 (这段代码告诉Eclipse搭建插件的Bukkit版本):  
  
 
<code>
 
<code>
第88行: 第88行:
 
</code>
 
</code>
  
If you wish to, you may change the version of Bukkit you're building against. You can view the available versions [http://repo.bukkit.org/content/groups/public/org/bukkit/bukkit/ here] by looking in the maven-metadata.xml file under versions.
+
你也可以修改这里的Bukkit版本.你可以在[http://repo.bukkit.org/content/groups/public/org/bukkit/bukkit/ here]这里通过查看 maven-metadata.xml文件下的版本列表来获取可用的服务端版本号.
  
When you finish, your ''pom.xml'' should look similar to this:
+
当你完成上述步骤后,''pom.xml''中的内容应该是这样:
  
 
[[Image:Finishedpom.png]]
 
[[Image:Finishedpom.png]]
  
Save your ''pom.xml'' using ''File -> Save'' or pressing <code>Ctrl + S</code>.  Then, right click the projects title and click ''Maven -> Update Project''.
+
通过菜单 ''File -> Save''或者按住 <code>Ctrl + S</code> 来保存''pom.xml''文件 之后, 右键项目标题,然后依次选择 ''Maven -> Update Project''.
 +
 
 
===待添加===
 
===待添加===

2014年10月29日 (三) 22:58的版本

创建一个新的项目

在开始工作之前,你需要先在Eclipse中配置好工作区和文件. 打开Eclipse,然后依次点击File -> New -> Project:来创建一个新的项目.

Newproject.png

现在,打开Maven文件夹, 然后选择Maven Project.点击next,之后在下一个菜单中选择Create a simple project, 再次点击Next: 如果你看不到Maven文件夹, 那么你需要下载m2eclipse

Newproject2.png

现在,你需要给你的组用户命名,就像下面这样:

  • 如果你拥有一个域名,package则填写逆转的域名地址.
    • 例如: i-am-a-bukkit-developer.com 你的package地址即是com.i_am_a_bukkit_developer source
    • 避免使用一个不属于你自己的域名.
  • 没有域名? 这里有几种方法可供选择。
    1. 在资源管理站点创建一个用户,比如GitHub或是sourceforge
      • 对于使用GitHub的用户, 请参照这里的说明 之后你将获得一个子域名,所以你的package地址是io.github.<username>
    2. 使用你的邮箱. 例如: <username>@gmail.com格式的邮箱应输入com.gmail.<username>
    3. 最不济的方法.: 使用独特的组名命名方式,这应当是你最后的解决方法。

以下几个地址不能作为package中的地址前缀:

  • org.bukkit
  • net.bukkit
  • com.bukkit
  • net.minecraft

完成基础的组名以后,你需要在最后加上插件的名称. 在这里用 GitHub页面作为讲解的实例. 如果你创建了一个名为 TestPlugin的插件,那么完整的组名是io.github.<username>, 你的工程名也是 TestPlugin. 至于版本,默认即可,稍后可以修改。 完成向导:

Newproject3.png

如果这是你首次使用Eclipse, 点击右上角的"X" 来关闭Welcome提示页面. 现在,你的窗口视图看起来就像下面的图片这样:

Eclipsemain.png

点击工程名称右边的箭头来进行下一步,现在我们正式开始。

添加Bukkit API

在开发插件之前,你需要添加 Bukkit API库文件到你的项目,作为一个dependency, 你也可以添加其他你想实用的API.

找到项目文件夹中部的pom.xml并双击进行编辑. 点击pom.xml中部的 tab,你将会看到下图所示内容:

Pomeditor.png

如果你想使用Java 6以上版本的语言特性,你需要指定搭建项目的Java版本.复制并粘贴以下内容(设定项目只能使用Java 7及以下的版本)到 </project>之前:

   <build>
      <plugins>
          <plugin>
              <groupId>org.apache.maven.plugins</groupId>
              <artifactId>maven-compiler-plugin</artifactId>
              <configuration>
                  <source>1.7</source>
                  <target>1.7</target>
              </configuration>
          </plugin>
      </plugins>
   </build>

你或许想使用其他版本,例如 1.8 使用Java 8. 请注意 根据MCStats数据统计, 大多数服主选择了Java 7, 所以使用Java 8会使许多服务器无法运行你的插件. 如果你使用Java 1.7的特性, Eclipse将会在报错代码"error"中建议你更改语言版本.同意即可.

在位于代码中段的</project>之前粘贴以下内容(这段代码告诉Eclipse关于Bukkit's repository的地址):

   <repositories>
       <repository>
           <id>bukkit-repo</id>
           <url>http://repo.bukkit.org/content/groups/public/</url>
       </repository>
   </repositories>

然后继续在 </project>前粘贴以下内容 (这段代码告诉Eclipse搭建插件的Bukkit版本):

   <dependencies>
       <dependency>
           <groupId>org.bukkit</groupId>
           <artifactId>bukkit</artifactId>
           <version>1.7.2-R0.3</version>
           <type>jar</type>
           <scope>provided</scope>
       </dependency>
   </dependencies>

你也可以修改这里的Bukkit版本.你可以在here这里通过查看 maven-metadata.xml文件下的版本列表来获取可用的服务端版本号.

当你完成上述步骤后,pom.xml中的内容应该是这样:

Finishedpom.png

通过菜单 File -> Save或者按住 Ctrl + S 来保存pom.xml文件 . 之后, 右键项目标题,然后依次选择 Maven -> Update Project.

待添加