API
~ The following is an API for InSignsPlus
[Auto-updating sign]
If you want a sign for your plugin to auto-update, you can simply have a whitelisted placeholder on it, and InSignsPlus will handle the rest.
- Below are examples for creating you own placeholder and adding it to the whitelist.
[Adding a placeholder]
- First off, make sure you add InSignsPlus.jar to your build path (Need an example?)
- Below you can see an example of creating a new placeholder.
Click here for the example below
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | Plugin insignsplus = getServer().getPluginManager().getPlugin("InSignsPlus"); if ((insignsplus!=null) && insignsplus.isEnabled()) { InSignsPlus ISP = (InSignsPlus) insignsplus; ISP.addPlaceholder(new Placeholder("walkspeed") { @Override public String getValue(Player player, Location location,String[] modifiers, Boolean elevation) { return ""+player.getWalkSpeed(); } // New getDescription method avaliable (it's optional) @Override public String getDescription() { return "{walkspeed:*username} - Returns a player's walkspeed"; } }); } |
Once you have your placeholder, it can just be added to a sign normally!
1 2 3 4 5 6 7 | // Setting the line of a sign BlockState state = (new Location(world, x, y, z)).getBlock().getState(); if (state instanceof Sign) { Sign sign = (Sign) state; sign.setLine(0, "{your placeholder}"); sign.update(true); } |
[Modifying sign packet event]
Click here for the example below
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | @EventHandler(ignoreCancelled=true) private void onSignUpdate(SignUpdateEvent event) { Player player = event.getPlayer(); Location location = event.getLocation(); // Get the event that caused the sign update e.g. PlayerInteractEvent (may be null) event.getCauseEvent(); //Get or set the lines event.getLine(i); event.getLine(i) event.setLine(i, line); event.setLines(lines); // Cancel it? event.setCancelled(true); } |
Don't forget your imports:
import com.empcraft.InSignsPlus; import com.empcraft.Placeholder;
[Updating Signs]
Add a placeholder to the whitelist using the API:
ISP.whitelistPlaceholder(String key) ISP.whitelistPlaceholder(Placeholder placeholder)
Update a sign manually
ISP.updateSign(Player player, Location location);
Update all signs near a player:
ISP.updateAllSigns(Player player); // Or, in the case of a moving/teleporting player: ISP.updateAllSigns(Player player, Location location);
[Other Methods]
Get the original player evaluating the placeholder
ISP.getSender();
Change the user to evaluate with
Change the player you are evaluating with in the future.
(Will not change the current instance of player)
ISP.setUser(Player player);
Enabling a disabled placeholder:
ISP.addPlaceholder(String key);
Remove a placeholder
To remove a placeholder (assuming you kept a reference) simply use:
ISP.removePlaceholder(Placeholder placeholder);
You can also remove the placeholder matching a key:
ISP.removePlaceholderKey(String key);
Get a list of placeholders
ISP.getPlaceholders();
Check if a placeholder is whitelisted
// Remember to put in the curly brackets {} ISP.iswhitelisted(String line);
Get a message from the language file
ISP.getmsg(String key);
Quickly evaluate some javascript
ISP.javascript(String line);
Comments