-
Notifications
You must be signed in to change notification settings - Fork 1
Minecraft Plugin
The jar is a full Spigot and Bungeecord plugin capable to provide the functionalities of the RedstoneAPI.
To install the RedstoneAPI on your Spigot/Paper or Bungeecord/Waterfall server just drop the latest released jar in your plugins folder.
To use the RedstoneAPI in your plugin just add the Maven dependency as described here and add it as dependency in your plugin.yml like this.
depend:
- RedstoneAPI
In case you make a Spigot and Bungeecord plugin put it also in your bungee.yml.
At the moment there is only one permission for both Spigot and Bungeecord.
- redstoneapi.admin.notifyupdate: Get notified when a newer version is available
usermanager:
enabled: true # Enable or disable the usermanager
fetchonmissing: true # Get the user from the MojangAPI when the persistance is over or the player was not logged in before
persistance: 30 # persistance in days how long the stored playernames are valid
storage:
type: SQLITE # SQLITE or MYSQL | how to store the playernames and their uuids
mysql:
host: 'localhost'
port: 3306
database: 'redstoneapi'
username: 'redstoneapi'
password: 'redstoneapi'
sqlite:
name: 'redstoneapi.db' # filename
update:
notify:
console: true # Log on console when a new version is available
adminjoin: true # Send to players with the notify permissions that a new version is available on join
ipc:
enabled: false # Whether to enable the builtin IPCServer. If enabled make sure its protected by a firewall. Undocumented!
host: '127.0.0.1' # The hostname to listen for
port: 2000 # The server port
This is a more advanced base class for Bungeecord plugins.
public class TestPlugin extends BungeecordPlugin { ... }
This base class provides a config.yml
by default.
To get the config use this example code.
Configuration config = getConfig();
Load / reload the config.
loadConfig();
Save the config stored in the resources
saveDefaultConfig("bungeeconfig.yml"); // the filename is the filename in the resources folder
Render the String to a colored String for Minecraft using the key '&'
String colored = renderColors("&cThis is red");
Register permissions so permission managers like LuckPerms as able to autocomplete it.
registerPermissions("permission1.test", "permission2.admin", ...);
Register all commands at once in the simplest way possible.
registerCommands(command1, command2, ...);
Register all listeners at once in the simplest way possible.
registerListeners(listener1, listener2, ...);
Send a message to the console
sendConsoleMessage("test");
Schedule some stuff
Schedule a Task for later
schedule(() -> System.out.println("This is printed after 5 seconds"), 5, TimeUnit.SECONDS);
Schedule a Task to be run every n units.
schedule(() -> System.out.println("This is printed every 5 seconds beginning after 15 seconds"), 15, 5, TimeUnit.SECONDS);
To get the plugin instance use this example code.
RedstoneAPIBungee instance = RedstoneAPIBungee.getInstance();
Since Bungeecord does not provide a native ability for offline user management the RedstoneAPI implements this.
To get the instance of the UserManager you can use this example code.
UserManager userManager = RedstoneAPIBungee.getInstance().getUserManager();
The User object provides some basic features and can provide the ProxiedPlayer if online.
Get the UUID of the User
UUID uuid = user.getUniqueId();
Does what it says. Get the playername
String playername = user.getPlayerName();
Returns true if the player is online.
boolean online = user.isOnline();
Get the ProxiedPlayer instance. Returns 'null' if the player is offline.
ProxiedPlayer player = user.getOnlinePlayer();
You can user the UserManager to get User objects or check them.
Get a User instance by one of the following options
Get the User by his name
User user = RedstoneAPIBungee.getInstance().getUserManager().getUser("playername");
Get the User by his UUID
User user = RedstoneAPIBungee.getInstance().getUserManager().getUser(UUID.fromString("00000000-0000-0000-0000-000000000000"));
Get the user by a ProxiedPlayer instance
ProxiedPlayer player = ProxyServer.getInstance.getPlayer("playername");
User user = RedstoneAPIBungee.getInstance().getUserManager().getUser(player);
The PendingConnection is for provided by the PreLoginEvent
User user = RedstoneAPIBungee.getInstance().getUserManager().getUser(pendingConnection);
Check if the player if already registered / known in the database. Since players connecting to the server are automatically stored in the database the check is useless for ProxiedPlayer and PendingConnection.
Returns true if the name is already in the database.
boolean registered = RedstoneAPIBungee.getInstance().getUserManager().isRegistered("playername");
Returns true if the UUID is already in the database.
boolean registered = RedstoneAPIBungee.getInstance().getUserManager().isRegistered(UUID.fromString("00000000-0000-0000-0000-000000000000"));
Because it is possible to create a User instance by the contructor this check is possible but propably useless. The check is done using the UUID. Use it or ignore it.
User user = RedstoneAPIBungee.getInstance().getUserManager().getUser("playername");
boolean registered = RedstoneAPIBungee.getInstance().getUserManager().isRegistered(user);
If the UUID doesn't exist already a new User will be stored in the database else the playername will be updated.
RedstoneAPIBungee.getInstance().getUserManager().updateUser(UUID.fromString("00000000-0000-0000-0000-000000000000"), "playername");
Whether fetching a User from the MojangAPI is enabled if the User is missing or the name is outdated or not.
boolean enabled = RedstoneAPIBungee.getInstance().getUserManager().isFetchOnMissing();
RedstoneAPIBungee.getInstance().getUserManager().setFetchOnMissing(true);
The amount of milliseconds the username is valid if fetchOnMissing is enabled.
long millis = RedstoneAPIBungee.getInstance().getUserManager().getPersistance();
RedstoneAPIBungee.getInstance().getUserManager().setPersistance(2592000000);
This is a advanced Plugin base for Spigot plugins.
public class TestPlugin extends SpigotPlugin {
@Override
public void onEnabled() { ... } // Notice the methods name ends with a 'd'
@Override
public void onServerLoaded() { ... } // This is executed after the Server completed loading
}
Register multiple Listener easily.
registerListeners(listener1, listener2);
Color a String by the key '&'
renderColors("&cThis is red.");
Since this event is missing on Spigot the RedstoneAPI adds it. The event is fired when a Player jumps.
@EventHandler
public void onJump(PlayerJumpEvent event) { ... }
Get the player that jumped.
Player player = event.getPlayer();
The Location of the Player before the jump.
Location from = event.getFrom();
The Location of the Player after the jump (in air).
Location to = event.getTo();
The InventoryHelper can store inventories, itemstacks and itemmeta in json objects and restore it.
Serializing is easy but deserializing must be explained. To deserialize you have to first get the ItemMeta from an ItemStack, deserialize and set the ItemMeta again.
JSONObject obj = InventoryHelper.serializeItemMeta(itemMeta);
ItemStack itemStack;
JSONObject obj;
ItemMeta itemMeta = itemStack.getItemMeta();
InventoryHelper.deserializeItemMeta(data, itemMeta);
JSONObject obj = InventoryHelper.serializeItemStack(itemStack);
ItemStack itemStack = InventoryHelper.deserializeItemStack(obj);
Use this only for custom inventories without owners.
JSONObject obj = InventoryHelper.serializeInventory(inventory);
Inventory inventory = InventoryHelper.deserializeInventory(obj);
There is a wrapper for using inventories with items to create a clickable GUI.
// title |rows| on open | on close
GuiInventory gui = new GuiInventory("title", 6, (event) -> {}, (event) -> {});
// OnOpen and OnClose could be used for loading and storing settings.
// You can set onOpen and onClose later also.
gui.setOnGuiOpen((event) -> {});
gui.setOnGuiClose((event) -> {});
int size = gui.size();
String title = gui.getTitle();
// Get open inventories for players. This is needed so the different options are different for different players.
Map<Player, Inventory> inventories = gui.getInventories();
// Get open inventory of player.
Inventory inventory = gui.getFor(player);
// Open the inventory for a player.
gui.openFor(player);
// Example for a switch with items diamond on and emerald off. Can be further customized with lores etc.
Map<Boolean, ItemStack> states = new HashMap<>();
states.put(true, new ItemStack(Material.DIAMOND));
states.put(false, new ItemStack(Material.EMERALD));
GuiOptionStates guiOptionStates = new GuiOptionStates(states, false); // The second argument must be type of the maps key and is the default state that must be in the states map.
// Set options with items and corresponding states.
gui.setOption(new GuiInventory.Option(0, 0, ), guiOptionStates); // Set clickevent for topleft item.
On its own the GuiInventory won't do much so it has to be known to the GuiInventoryManager which takes care of firing events etc.
// Get the instance.
GuiInventoryManager manager = RedstoneAPISpigot.getInstance().getInventoryManager();
// Add GuiInventory
manager.addInventory(guiInventory);
// Or remove GuiInventory
manager.removeInventory(guiInventory);
If you want to help improving this wiki create an issue or a pull request.