join-leave-messages¶
The smallest useful weftkit plugin: it replaces the default join and leave broadcasts with its
own messages. Three classes show the whole wiring model. The full source lives in
examples/bukkit/join-leave-messages.
The walkthrough follows the order the server sees: the plugin main boots the graph, the component holds the message logic, and the listener connects both to Bukkit's events. The build setup itself is covered in getting started; this page focuses on the wiring.
The plugin main¶
JoinLeavePlugin carries @Registry, extends WeftPlugin, and points at the generated
WeftWiring. Nothing else.
package org.weftkit.examples.joinleave;
import org.weftkit.wiring.Registry;
import org.weftkit.wiring.bukkit.WeftPlugin;
import org.weftkit.wiring.registry.ComponentRegistry;
@Registry
public final class JoinLeavePlugin extends WeftPlugin {
@Override
protected ComponentRegistry registry() {
return WeftWiring.INSTANCE;
}
}
The component¶
Messages is a plain @Wired @Singleton component that formats the broadcasts. It is public
because it is injected across packages.
package org.weftkit.examples.joinleave.messages;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import org.weftkit.wiring.Singleton;
import org.weftkit.wiring.Wired;
@Wired
@Singleton
public final class Messages {
public String joined(Player player) {
return ChatColor.YELLOW + player.getName() + " wove into the server.";
}
public String left(Player player) {
return ChatColor.YELLOW + player.getName() + " unraveled from the server.";
}
}
The listener¶
ConnectionListener gets Messages injected through its constructor and handles
PlayerJoinEvent and PlayerQuitEvent. weftkit registers it automatically, so there is no
registerEvents call anywhere. It stays package-private even in its own package: weftkit
generates a wiring holder per package with non-public components, see
internal components.
package org.weftkit.examples.joinleave.listeners;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.weftkit.examples.joinleave.messages.Messages;
import org.weftkit.wiring.Singleton;
import org.weftkit.wiring.Wired;
@Wired
@Singleton
final class ConnectionListener implements Listener {
private final Messages messages;
ConnectionListener(Messages messages) {
this.messages = messages;
}
@EventHandler
public void onJoin(PlayerJoinEvent event) {
event.setJoinMessage(messages.joined(event.getPlayer()));
}
@EventHandler
public void onQuit(PlayerQuitEvent event) {
event.setQuitMessage(messages.left(event.getPlayer()));
}
}
Layout and build¶
The layout is the usual feature-package shape: the plugin main and the generated WeftWiring
at the root, everything else grouped by concern.
The build follows the distribution guide: Shadow bundles weftkit into the plugin jar and relocates it, so several weftkit plugins can coexist on one server.
Run it¶
Build the example as described in the overview, drop the jar into a server's
plugins/ folder, join, and the custom message appears.
The shape is the takeaway: one listener, one injected collaborator, and a plugin main that only anchors the registry. Larger plugins repeat exactly this pattern; player-homes adds lifecycle hooks and two commands on top of it.