diff --git a/pom.xml b/pom.xml
index 9f9433b..4864e84 100644
--- a/pom.xml
+++ b/pom.xml
@@ -19,15 +19,15 @@
nukkitx-repo
- http://repo.nukkitx.com/main/
+ http://repo.nukkitx.com/snapshot/
- cn.nukkit
- nukkit
- 1.0-SNAPSHOT
+ com.nukkitx
+ nukkitx-api
+ 2.0.0-SNAPSHOT
provided
diff --git a/src/main/java/cn/nukkit/exampleplugin/BroadcastPluginTask.java b/src/main/java/cn/nukkit/exampleplugin/BroadcastPluginTask.java
deleted file mode 100644
index d2cf517..0000000
--- a/src/main/java/cn/nukkit/exampleplugin/BroadcastPluginTask.java
+++ /dev/null
@@ -1,19 +0,0 @@
-package cn.nukkit.exampleplugin;
-
-import cn.nukkit.scheduler.PluginTask;
-
-/**
- * author: MagicDroidX
- * ExamplePlugin Project
- */
-public class BroadcastPluginTask extends PluginTask {
-
- public BroadcastPluginTask(ExamplePlugin owner) {
- super(owner);
- }
-
- @Override
- public void onRun(int currentTick) {
- this.getOwner().getLogger().info("I've run on tick " + currentTick);
- }
-}
diff --git a/src/main/java/cn/nukkit/exampleplugin/EventListener.java b/src/main/java/cn/nukkit/exampleplugin/EventListener.java
deleted file mode 100644
index 18c18d7..0000000
--- a/src/main/java/cn/nukkit/exampleplugin/EventListener.java
+++ /dev/null
@@ -1,24 +0,0 @@
-package cn.nukkit.exampleplugin;
-
-import cn.nukkit.event.EventHandler;
-import cn.nukkit.event.EventPriority;
-import cn.nukkit.event.Listener;
-import cn.nukkit.event.server.ServerCommandEvent;
-
-/**
- * author: MagicDroidX
- * NukkitExamplePlugin Project
- */
-public class EventListener implements Listener {
- private final ExamplePlugin plugin;
-
- public EventListener(ExamplePlugin plugin) {
- this.plugin = plugin;
- }
-
- @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = false) //DON'T FORGET THE ANNOTATION @EventHandler
- public void onServerCommand(ServerCommandEvent event) {
- this.plugin.getLogger().info("ServerCommandEvent is called!");
- //you can do more here!
- }
-}
diff --git a/src/main/java/cn/nukkit/exampleplugin/ExamplePlugin.java b/src/main/java/cn/nukkit/exampleplugin/ExamplePlugin.java
deleted file mode 100644
index 0a34b9b..0000000
--- a/src/main/java/cn/nukkit/exampleplugin/ExamplePlugin.java
+++ /dev/null
@@ -1,76 +0,0 @@
-package cn.nukkit.exampleplugin;
-
-import cn.nukkit.command.Command;
-import cn.nukkit.command.CommandSender;
-import cn.nukkit.plugin.PluginBase;
-import cn.nukkit.utils.Config;
-import cn.nukkit.utils.TextFormat;
-import cn.nukkit.utils.Utils;
-
-import java.io.File;
-import java.io.IOException;
-import java.util.LinkedHashMap;
-
-/**
- * author: MagicDroidX
- * NukkitExamplePlugin Project
- */
-public class ExamplePlugin extends PluginBase {
-
- @Override
- public void onLoad() {
- this.getLogger().info(TextFormat.WHITE + "I've been loaded!");
- }
-
- @Override
- public void onEnable() {
- this.getLogger().info(TextFormat.DARK_GREEN + "I've been enabled!");
-
- this.getLogger().info(String.valueOf(this.getDataFolder().mkdirs()));
-
- //Register the EventListener
- this.getServer().getPluginManager().registerEvents(new EventListener(this), this);
-
- //PluginTask
- this.getServer().getScheduler().scheduleRepeatingTask(new BroadcastPluginTask(this), 200);
-
- //Save resources
- this.saveResource("string.txt");
-
- //Config reading and writing
- Config config = new Config(
- new File(this.getDataFolder(), "config.yml"),
- Config.YAML,
- //Default values (not necessary)
- new LinkedHashMap() {
- {
- put("this-is-a-key", "Hello! Config!");
- put("another-key", true); //you can also put other standard objects!
- }
- });
- //Now try to get the value, the default value will be given if the key isn't exist!
- this.getLogger().info(String.valueOf(config.get("this-is-a-key", "this-is-default-value")));
- //Don't forget to save it!
- config.save();
- }
-
- @Override
- public void onDisable() {
- this.getLogger().info(TextFormat.DARK_RED + "I've been disabled!");
- }
-
- @Override
- public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
- switch (command.getName().toLowerCase()) {
- case "example":
- try {
- this.getLogger().info(Utils.readFile(new File(this.getDataFolder(), "string.txt")) + " " + sender.getName());
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
- break;
- }
- return true;
- }
-
-}
diff --git a/src/main/java/com/nukkitx/exampleplugin/ExamplePlugin.java b/src/main/java/com/nukkitx/exampleplugin/ExamplePlugin.java
new file mode 100644
index 0000000..796cb6f
--- /dev/null
+++ b/src/main/java/com/nukkitx/exampleplugin/ExamplePlugin.java
@@ -0,0 +1,64 @@
+package com.nukkitx.exampleplugin;
+
+import com.nukkitx.api.Server;
+import com.nukkitx.api.event.Listener;
+import com.nukkitx.api.event.player.PlayerJoinEvent;
+import com.nukkitx.api.event.server.ServerInitializationEvent;
+import com.nukkitx.api.event.server.ServerShutdownEvent;
+import com.nukkitx.api.event.server.ServerStartEvent;
+import com.nukkitx.api.message.TextFormat;
+import com.nukkitx.api.message.TipMessage;
+import com.nukkitx.api.plugin.Plugin;
+import com.nukkitx.api.plugin.PluginDescription;
+import com.nukkitx.exampleplugin.generator.DiscoChunkGenerator;
+import org.slf4j.Logger;
+
+import javax.inject.Inject;
+import java.nio.file.Path;
+
+@Plugin(id = "ExamplePlugin", authors = {"NukkitX Team"}, version = "1.0.0")
+public class ExamplePlugin {
+ private final Logger logger;
+ private final PluginDescription description;
+ private final Path dataFolder;
+ private final Server server;
+
+ @Inject
+ private ExamplePlugin(Logger logger, PluginDescription description, Path dataFolder, Server server) {
+ this.logger = logger;
+ this.description = description;
+ this.dataFolder = dataFolder;
+ this.server = server;
+ }
+
+ /*
+ * This event is called before the server has fully loaded.
+ */
+ @Listener
+ public void onInitialization(ServerInitializationEvent event) {
+ logger.info(TextFormat.DARK_GREEN + description.getId() + " initialization!");
+ server.getGeneratorRegistry().register("DISCO", DiscoChunkGenerator::new);
+ }
+
+ /*
+ * This event is called after the server is fully loaded.
+ */
+ @Listener
+ public void onStart(ServerStartEvent event) {
+ logger.info(TextFormat.GREEN + description.getId() + " started!");
+
+ }
+
+ /*
+ * This event is called before the server has fully shuts down.
+ */
+ @Listener
+ public void onShutdown(ServerShutdownEvent event) {
+ logger.info(TextFormat.DARK_RED + description.getId() + " shutting down!");
+ }
+
+ @Listener
+ public void onJoin(PlayerJoinEvent event) {
+ event.setJoinMessage(new TipMessage("Welcome to the test server! This is experimental server software so there may be bugs."));
+ }
+}
diff --git a/src/main/java/com/nukkitx/exampleplugin/generator/DiscoChunkGenerator.java b/src/main/java/com/nukkitx/exampleplugin/generator/DiscoChunkGenerator.java
new file mode 100644
index 0000000..ad3ddfc
--- /dev/null
+++ b/src/main/java/com/nukkitx/exampleplugin/generator/DiscoChunkGenerator.java
@@ -0,0 +1,52 @@
+package com.nukkitx.exampleplugin.generator;
+
+import com.flowpowered.math.vector.Vector3f;
+import com.nukkitx.api.Server;
+import com.nukkitx.api.block.BlockState;
+import com.nukkitx.api.block.BlockType;
+import com.nukkitx.api.block.BlockTypes;
+import com.nukkitx.api.level.Level;
+import com.nukkitx.api.level.chunk.Chunk;
+import com.nukkitx.api.level.chunk.generator.ChunkGenerator;
+
+import java.util.Random;
+
+public class DiscoChunkGenerator implements ChunkGenerator {
+ private static final Vector3f SPAWN = new Vector3f(0, 3, 0);
+ private static final BlockType[] TYPES = new BlockType[] {
+ BlockTypes.COAL_BLOCK, BlockTypes.DIAMOND_BLOCK, BlockTypes.GOLD_BLOCK, BlockTypes.IRON_BLOCK,
+ BlockTypes.REDSTONE_BLOCK, BlockTypes.EMERALD_BLOCK, BlockTypes.LAPIS_LAZULI_BLOCK
+ };
+ private final Server server;
+ private final BlockState bedrock;
+
+ public DiscoChunkGenerator(Server server) {
+ this.server = server;
+ bedrock = server.blockStateBuilder().setBlockType(BlockTypes.BEDROCK).build();
+ }
+
+ @Override
+ public void generateChunk(Level level, Chunk chunk, Random random) {
+ for (int x1 = 0; x1 < 16; x1++) {
+ for (int z1 = 0; z1 < 16; z1++) {
+ chunk.setBlock(x1, 0, z1, bedrock, false);
+ BlockType type = TYPES[random.nextInt(TYPES.length)];
+ chunk.setBlock(x1, 1, z1, server.blockStateBuilder().setBlockType(type).build(), false);
+ }
+ }
+
+ if (chunk.getX() == 0 && chunk.getZ() == 0) {
+ chunk.setBlock(0, 4, 0, bedrock, false);
+ }
+ }
+
+ @Override
+ public void populateChunk(Level level, Chunk chunk, Random random) {
+ // Nothing to do... yet
+ }
+
+ @Override
+ public Vector3f getDefaultSpawn() {
+ return SPAWN;
+ }
+}
diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml
deleted file mode 100644
index c94dd3f..0000000
--- a/src/main/resources/plugin.yml
+++ /dev/null
@@ -1,36 +0,0 @@
-#name, main, version and api are required
-name: ExamplePlugin
-main: cn.nukkit.exampleplugin.ExamplePlugin
-#remember version and api is string, don't write it like this: 1.0.0, or there will be an exception
-version: "1.0.0"
-api: ["1.0.5"]
-load: POSTWORLD
-author: Nukkit Project
-# Authors and author will be added together in one list.
-authors: ["Example", "Another"]
-description: Example plugin showing the API
-website: https://github.com/NukkitX/ExamplePlugin
-# These dependencies are required for the plugin to start.
-#depend: ["OtherPlugin", "ThisPlugin"]
-# These dependencies are not required.
-softdepend: ["PluginA", "PluginB"]
-# Log prefix in console
-prefix: "Example"
-# Plugin will be loaded before these. Any cyclic loadbefore's or dependencies's will throw errors!
-loadbefore: ["ImportantPlugin"]
-
-commands:
- example:
- description: Example command
- usage: "/example"
- aliases: ["xample", "nukkitexample"]
- permission: exampleplugin.command.example
- permission-message: "You do not have the required permission to run /example"
-permissions:
- exampleplugin.command.example:
- description: "Allows the user to run the example command"
- default: true
- children:
-# exampleplugin.command.example.test:
-# description: "Use the test feature in the example command"
-# default: true
diff --git a/src/main/resources/string.txt b/src/main/resources/string.txt
deleted file mode 100644
index 05a682b..0000000
--- a/src/main/resources/string.txt
+++ /dev/null
@@ -1 +0,0 @@
-Hello!
\ No newline at end of file