How to use

How to use

Basics

Using SignEnhancer is verry simple. You can register your Plugin and Signs like this:

package YOURPACKAGE;

import me.leo.signenhancer.*;

import org.bukkit.plugin.java.JavaPlugin;

public class PInfo extends JavaPlugin {
    
    SignEnhancer e;
    
    @Override
    public void onEnable() {
        e = ((SignServices) getServer().getPluginManager().getPlugin("SignEnhancer")).getSignEnhancer();
        e.registerPlugin(this);
    }
    
    /**
     * Here You will register your signs
     * This will be called on reload too
     */
    public void registerSigns(SignRegister r) {
        r.registerSign(new YOURSIGN());
    }
    
}

In line 13 we asign the variable 'e' to the SignEnhancer, and in line 14 the plugin gets registered.

The Method in line 20-23 will get called after your plugin is registered and you can register your signs with the SignRegister thats given there.

The new YOURSIGN() extends the ESign class to listen to the Sign. Here is an Example how your YOURSIGN class could look like:

package YOURPACKAGE;

import org.bukkit.block.Sign;
import org.bukkit.entity.Player;

import me.leo.signenhancer.ESign;

public class YOURSIGN extends ESign{

    public YOURSIGN() {
        super("HALLO");
    }
    
    @Override
    public void onUse(Sign s, Player p) {
        p.sendMessage("You used the HALLO sign!");
    }

The super("HALLO") in line 11 defines the first line of the sign. The case and ChatColors will be ignored when using, but not removed from the sign. When using Lines of the sign i would recommend to remove the colors from the string('ChatClolor.stripColor(String s)').

The method onUse is called everytime the sign gets rightclicked by a Player.

This is everything you need to use this plugin but there are some other features left.

Advanced

Here are some other methods that are Optional and can be overridden or used:

    public YOURSIGN() {
        super("HALLO")

        this.setDescription("This is the HALLO sign")/* This will set the description that will be displayed in the signlist */
    }
    @Override
    public void onCreate(Sign s, Player p) {
        super.onCreate(s, p); /** This will replace the case without removing ChatColors */
        s.setLine(2, "Created by:");
        s.setLine(3, p.getName());
    }
    
    @Override
    public void onDestroy(Sign s, Player p) {
        p.sendMessage(ChatColor.YELLOW + "You destroyed the HALLO sign");
        super.onDestroy(s, p);
    }
    
    /**
     * This method will only be called if the Player dosent have the 'se.create' permission
     */
    @Override
    public boolean canCreate(Sign s, Player p) {
        return false;
        /**
         * False by default return true to allow a player to create the sign
         */
    }
    
    /**
     * This method will only be called if the Player dosent have the 'se.destroy' permission
     */
    @Override
    public boolean canDestroy(Sign s, Player p) {
        /**
         * False by default return true to allow a player to create the sign
         */
        return false;
    }

You can call the setDescription(String) method to set the description that will show up on the signlist.
The description will look like this:

SignName -> This is the description

The canCreate and canDestroy method is not called if the Player has the permission 'se.create'/'se.destroy'. You can return true or false in canCreate/canDestroy to use your oen create and destroy permission.


The Signs registered by your Plugin will be unregistered when your plugin gets disabled. You can unregister them manually by using the SignEnhancer class or you can reload the signs so you can remove/add new Signs.

You can only register and remove all signs created by a Plugin at once:

    @Override
    public boolean onCommand(CommandSender sender, Command command,
            String label, String[] args) {
        if(command.getName().equalsIgnoreCase("YOURPLUGIN")) {
            if(args.length == 1) {
                switch (args[0].toLowerCase()) {
                /*Reload Signs*/
                case "reload":
                    e.registerPlugin(this); /* If your plugin is already registered it will reload the signs */
                    break;
                /*Remove Signs*/
                case "disable":
                    e.unregisterPlugin(this); /* Removes all the signs registered by this plugin */
                    break;
                }
            }
        }
        return true;
    }

This would add the command 'YOURPLUGIN reload' and 'YOURPLUGIN disable'. The Commands reload or remove the signs created by your plugin.


Comments

Posts Quoted:
Reply
Clear All Quotes