Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Rewrite #1

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@
<repositories>
<repository>
<id>nukkitx-repo</id>
<url>http://repo.nukkitx.com/main/</url>
<url>http://repo.nukkitx.com/snapshot/</url>
</repository>
</repositories>

<dependencies>
<dependency>
<groupId>cn.nukkit</groupId>
<artifactId>nukkit</artifactId>
<version>1.0-SNAPSHOT</version>
<groupId>com.nukkitx</groupId>
<artifactId>nukkitx-api</artifactId>
<version>2.0.0-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
</dependencies>
Expand Down
19 changes: 0 additions & 19 deletions src/main/java/cn/nukkit/exampleplugin/BroadcastPluginTask.java

This file was deleted.

24 changes: 0 additions & 24 deletions src/main/java/cn/nukkit/exampleplugin/EventListener.java

This file was deleted.

76 changes: 0 additions & 76 deletions src/main/java/cn/nukkit/exampleplugin/ExamplePlugin.java

This file was deleted.

64 changes: 64 additions & 0 deletions src/main/java/com/nukkitx/exampleplugin/ExamplePlugin.java
Original file line number Diff line number Diff line change
@@ -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."));
}
}
Original file line number Diff line number Diff line change
@@ -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;
}
}
36 changes: 0 additions & 36 deletions src/main/resources/plugin.yml

This file was deleted.

1 change: 0 additions & 1 deletion src/main/resources/string.txt

This file was deleted.