PluginSignAPI

Introducing the PluginSignAPI.

When installed on its own this plugin does nothing. It just allows other plugins to work.

While I was attempting to develop several minigames, I always came to the point where I had to find a solid system to manage signs that allowed me to check if someone clicked it and change the displayed text with code. I didn't find what I was looking for, everything I found did either not allow me to change my signs text at runtime or was not simple enough. This is why I ended up coding it myself and it works so good for me that I thought I'd share it. Please note that this API is still in development and it already works but I supposed there are a few things that should be finalized. Leave your feedback to make it better.

I plan on implementing signs that look different for each player and a customizable tag (that means the first line doesn't have to be [PluginSign]. If you're interested in these features please tell me in the comments or as a ticket.

If you're using this API, please leave a comment to let me know if there's a demand for updating it whenever necessary.

Using the PluginSignAPI

Using the PluginSignAPI is simple:

  • To create signs in-game you just have to place a sign and write the following things on it:
  1. [PluginSign] (this is not changeable)
  2. YourPluginName (this is used in your plugin to find out if you care about the sign)
  3. Purpose (this is used in the plugin to seperate signs, for example making signs to join rooms or to spectate)
  4. Data (this can be anything useful for your plugin, such as a room name when you're making a sign to join a room)
  • In your plugin you have to add the PluginSignAPI.jar to your build path and listen for the following events like to every other bukkit event:
  1. PluginSignUpdateEvent is called when the PluginSignAPI updates the text on the signs. This is where you put the text that you want to have displayed on your signs. The event has the methods getPlugin(), getPurpose() and getData() which are self-explanatory. Then you have the method setLine(int index, String line) to display your text on the signs when they're updated. You can also get a PluginSign object with getPluginSign() that contains the above methods and the signs location.
  2. PluginSignClickEvent is called when a player right clicks on a PluginSign. Like in the update event you can check if you care about the sign and what to do. You can also get the player object of the player who clicked the sign with getPlayer().
  • To update every PluginSign just call PluginSignAPI.updateSigns()

Keep in mind that server owners have to have the PluginSignAPI installed as a plugin if your plugin uses it.

Example

And finally I have an example usage of the PluginSignAPI where you can have signs to display a players popping score, saved as the players level, and when someone right clicks the sign it outputs a text. The sign input looks like this:

Example sign

You can see the pattern: first line [PluginSign], second line plugin (which is called "pop"), third line purpose and fourth line the data, in this case the player to show the score for. When you placed the sign it automatically gets updated as specified in the PluginSignUpdateEvent and looks like this:

Created sign

And when you right click it, the PluginSignClickEvent gets called and it sends a message to the player who clicked:

Click event

@EventHandler
  public void onSignUpdate(PluginSignUpdateEvent event) {
    if(event.getPlugin().equalsIgnoreCase("pop")) {
      if(event.getPurpose().equalsIgnoreCase("showscore")) {
        event.setLine(0, "┬žaPOP Score");
        event.setLine(1, event.getData());
        if(getServer().getPlayer(event.getData()) != null) {
          Player player = getServer().getPlayer(event.getData());
          event.setLine(2, "Score: " + player.getLevel());
        }
      }
    }
  }
  
  @EventHandler
  public void onSignClick(PluginSignClickEvent event) {
    if(event.getPlugin().equalsIgnoreCase("pop")) {
      if(event.getPurpose().equalsIgnoreCase("showscore")) {
        if(getServer().getPlayer(event.getData()) != null) {
          Player player = getServer().getPlayer(event.getData());
          event.getPlayer().sendMessage(player.getName() + " has a score of " + player.getLevel());
        }
      }
    }
  }

Comments

Posts Quoted:
Reply
Clear All Quotes

About This Project

  • Project ID
    58007
  • Created
    May 25, 2013
  • Last Released File
    Never
  • Total Downloads
    557
  • License

Categories

Members

Recent Files

Bukkit