plugin - FreshSupaSulley/CensorCraft GitHub Wiki
You need to have ≥ JDK 21 installed and be able to create Minecraft Forge mods. I recommend using the API template to get yourself started. You'll need to add the CensorCraft API library as a dependency (found in the 2.0.0 release of this repo), along with the simple voice chat and CensorCraft mods as runtime dependencies.
A CensorCraft plugin is a Forge mod that uses the CensorCraft API. Plugins can define custom punishments and hook into CensorCraft events!
To register custom events, you'll hook into the server configuration event, and they'll appear in the server config file just like the built-in punishments, allowing server admins to configure it to their liking with parameters you define.
The plugin template defines an example punishment that depletes your hunger bar, which ends up looking like this in the server config file:
[[hunger]]
enable = true
# List of punishment-specific forbidden words and phrases (case-insensitive)
taboo = [""]
# Global taboos don't trigger this punishment
ignore_global_taboos = false
# The amount of food exhaustion to inflict onto the player
exhaustion = 500
Notice that the exhaustion
parameter is unique to this punishment. When your custom punishment is called to punish a player, you'll be able to retrieve these values set by the server admin as inputs.
Usually, you just need the ServerLevel
Minecraft object for everything punishment-related. However, if your punishment requires you to run code on the client instead of the server, I recommend hooking into the ClientAcknowledgePunish
event. This fires when the client receives the list of punishments that they caused (and resets their audio buffer), and will allow you to check if your punishment was called and do something on the client accordingly (this is how the Crash punishment works).
CensorCraft plugins work very similarly to simple voice chat plugins. You'll need to create a class that implements CensorCraftPlugin
with an @ForgeCensorCraftPlugin
and a default no-arg constructor:
@ForgeCensorCraftPlugin
public class MyCCPlugin implements CensorCraftPlugin {
// Constructor must take no args!
public MyCCPlugin()
{
}
// magic method to hook into CensorCraft events
@Override
public void registerEvents(EventRegistration registration)
{
registration.registerEvent(ServerConfigEvent.class, this::onServerConfig);
}
public void onServerConfig(ServerConfigEvent event)
{
event.registerPunishment(HungerPunishment.class);
}
HungerPunishment.class
:
public class HungerPunishment extends Punishment {
@Override
public String getName()
{
return "hunger";
}
@Override
protected void buildConfig()
{
define("exhaustion", 500, "The amount of food exhaustion to inflict onto the player");
}
@Override
public void punish(Object serverPlayer)
{
((ServerPlayer) serverPlayer).causeFoodExhaustion(((Number) config.get("exhaustion")).floatValue());
}
}
Here's the list of events you can hook into. Most (but not all) events are cancellable, and you can check with the inherited isCancellable
getters. The javadoc for each event has more in-depth descriptions as well.
Event | Side | Description |
---|---|---|
ServerConfigEvent | Server | Use this to register your own punishments. |
PunishEvent | Server | The server is about to punish a player. |
ClientAcknowledgePunish | Client | The client received a packet containing the punishments they triggered. |
SendTranscriptionEvent | Client | The client is about to send a packet containing their transcription results to the server. |
On macOS, you may experience issues testing this mod in the IDE because simple voice chat is unable to capture your microphone input due to permission issues. This is namely an issue on Eclipse. I recommend either switching to IntelliJ IDEA, or build the jar file for your mod and test it in CurseForge directly (you should be doing this anyways before you release it).
When your plugin is battle-tested and works as expected, you're ready to publish it! Run ./gradlew build
to generate your mod to build/libs and you're good to publish it (you probably already know that). If you decide to distribute it through CurseForge, make sure to add CensorCraft as a mod dependency.