Skip to content

stylextv/gsigns-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

25 Commits
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation



πŸ”“ Source code of the GSigns-API, made with love in Java.

stars Codacy Badge GitHub All Releases

What is it?

GSigns-API is a lightweight api for the plugin GSigns that allows the creation and removal of signs.

The github page of the plugin can be found here.

Including

To include this api in your own plugin, download the latest release and add the following line to your plugin.yml:

depend: [GSigns]

Implementing GSigns

Implementing GSigns is quite simple. It requires getting the GSigns-API service from the Bukkit ServiceManager. See the example below:

package com.example.plugin;

import java.util.UUID;

import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.plugin.RegisteredServiceProvider;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitRunnable;

import de.stylextv.gs.api.GSignsAPI;

public class Main extends JavaPlugin {
	
	private GSignsAPI gSignsAPI;
	
	private UUID signUid;
	
	@Override
	public void onEnable() {
		if(!setupGSignsAPI()) {
			System.out.println(getDescription().getName()+" - Disabled due to no GSigns dependency found!");
			getServer().getPluginManager().disablePlugin(this);
			return;
        	}
		
		new BukkitRunnable() {
			@Override
			public void run() {
				World w = Bukkit.getWorld("world");
				String code = "{bg-url:https://raw.githubusercontent.com/StylexTV/GSigns/master/showcase/socials/cover.png,dith:false}";
				signUid = gSignsAPI.createSign(code, new Location(w, -402, 100, -43), new Location(w, -395, 97, -43));
			}
		}.runTaskLater(this, 5);
	}
	
	@Override
	public void onDisable() {
		if(signUid != null) {
			gSignsAPI.removeSign(signUid);
		}
	}
	
	private boolean setupGSignsAPI() {
        	if(getServer().getPluginManager().getPlugin("GSigns") == null) {
        		return false;
        	}
        	RegisteredServiceProvider<GSignsAPI> rsp = getServer().getServicesManager().getRegistration(GSignsAPI.class);
        	if(rsp == null) {
			return false;
		}
		gSignsAPI = rsp.getProvider();
		return gSignsAPI != null;
	}
	
}

About

πŸ”“πŸ€ A simple API for the GSigns plugin.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages