Skip to content

Instantly share code, notes, and snippets.

@BeYkeRYkt
Created June 20, 2016 13:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BeYkeRYkt/470ff32cde7003e06a2277a0ce3735ce to your computer and use it in GitHub Desktop.
Save BeYkeRYkt/470ff32cde7003e06a2277a0ce3735ce to your computer and use it in GitHub Desktop.
Example plugin for LightAPI-3.0.0
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.LightAPI;
import ru.beykerykt.lightapi.chunks.ChunkInfo;
import ru.beykerykt.lightapi.events.DeleteLightEvent;
import ru.beykerykt.lightapi.events.SetLightEvent;
/**
*
* Test plugin for LightAPI
* LightAPI version: 3.0.0
*
* @author BeYkeRYkt
*
*/
public class LightTest extends JavaPlugin implements Listener {
@Override
public void onEnable() {
getServer().getPluginManager().registerEvents(this, this);
}
@EventHandler
public void demoCreateLight(SetLightEvent event){
if(!event.isAsync()){
event.setAsync(true);
}
}
@EventHandler
public void demoDeleteLight(DeleteLightEvent event){
if(!event.isAsync()){
event.setAsync(true);
}
}
@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) {
LightAPI.createLight(location.getWorld(), location.getBlockX(), location.getBlockY(), location.getBlockZ(), level, flag);
for(ChunkInfo info: LightAPI.collectChunks(location.getWorld(), location.getBlockX(), location.getBlockY(), location.getBlockZ())){
LightAPI.updateChunks(info);
}
}
private void deleteLight(Location location, boolean flag) {
LightAPI.deleteLight(location.getWorld(), location.getBlockX(), location.getBlockY(), location.getBlockZ(), flag);
for(ChunkInfo info: LightAPI.collectChunks(location.getWorld(), location.getBlockX(), location.getBlockY(), location.getBlockZ())){
LightAPI.updateChunks(info);
}
}
private void recreateLight(Location location, int level, boolean flag) {
LightAPI.deleteLight(location.getWorld(), location.getBlockX(), location.getBlockY(), location.getBlockZ(), flag);
LightAPI.createLight(location.getWorld(), location.getBlockX(), location.getBlockY(), location.getBlockZ(), level, flag);
for(ChunkInfo info: LightAPI.collectChunks(location.getWorld(), location.getBlockX(), location.getBlockY(), location.getBlockZ())){
LightAPI.updateChunks(info);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment