Skip to content

Instantly share code, notes, and snippets.

@BeYkeRYkt BeYkeRYkt/LightTest.java
Last active Apr 3, 2016

Embed
What would you like to do?
Example plugin for LightAPI-2.0.1
package ru.BeYkeRYkt.LightTest;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.AsyncPlayerChatEvent;
import org.bukkit.plugin.java.JavaPlugin;
import ru.beykerykt.lightapi.chunks.ChunkInfo;
import ru.beykerykt.lightapi.chunks.Chunks;
import ru.beykerykt.lightapi.light.LightDataRequest;
import ru.beykerykt.lightapi.light.Lights;
/**
*
* Test plugin for LightAPI
* LightAPI version: 2.0.1
*
* @author BeYkeRYkt
*
*/
public class LightTest extends JavaPlugin implements Listener {
@Override
public void onEnable() {
getServer().getPluginManager().registerEvents(this, this);
}
@EventHandler
public void onPlayerChat(AsyncPlayerChatEvent event) {
String message = event.getMessage();
Player player = event.getPlayer();
Location location = player.getLocation();
int level = 15;
if (message.equals("createasync")) {
createLight(location, level, true);
player.sendMessage(message + ": Async request has been added to queue.");
} else if (message.equals("create")) {
createLight(location, level, false);
player.sendMessage(message + ": Sync request has been completed");
} else if (message.equals("deleteasync")) {
deleteLight(location, true);
player.sendMessage(message + ": Async request has been added to queue.");
} else if (message.equals("delete")) {
deleteLight(location, false);
player.sendMessage(message + ": Sync request has been completed");
} else if (message.equals("recreateasync")) {
recreateLight(location, level, true);
player.sendMessage(message + ": Async request has been added to queue.");
} else if (message.equals("recreate")) {
recreateLight(location, level, false);
player.sendMessage(message + ": Sync request has been added to queue.");
}
}
private void createLight(Location location, int level, boolean flag) {
LightDataRequest request = Lights.createLight(location, level, flag);
if (request != null) {
Chunks.addChunkToQueue(request);
} else {
for (ChunkInfo info : Chunks.collectModifiedChunks(location)) {
Chunks.sendChunkUpdate(info);
}
}
}
private void deleteLight(Location location, boolean flag) {
LightDataRequest request = Lights.deleteLight(location, flag);
if (request != null) {
Chunks.addChunkToQueue(request);
} else {
for (ChunkInfo info : Chunks.collectModifiedChunks(location)) {
Chunks.sendChunkUpdate(info);
}
}
}
private void recreateLight(Location location, int level, boolean flag) {
Lights.deleteLight(location, flag);
LightDataRequest request = Lights.createLight(location, level, flag);
if (request != null) {
Chunks.addChunkToQueue(request);
} else {
for (ChunkInfo info : Chunks.collectModifiedChunks(location)) {
Chunks.sendChunkUpdate(info);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.