A Bukkit plugin which offers an API to register custom events that will be launched at a specific date.
To create an event, add a yaml file in the 'event' directory that respect the template bellow. You can have as many event as you want.
# The date of the week when this event must be fired. There is no limit for the number of datesdate:
1: # This section's name does not matter, it just needs to be unique.day: 1# Between 1 and 7. 1 = SUNDAY ; 2 = MONDAY ; ... ; 7 = SATURDAYhour: 18# Between 0 and 23minute: 0# Between 0 and 59# Sunday at 18:002:
day: 2hour: 20minute: 30# Monday at 20:30# The bellow keys are specific to each event, # so you need to check the documentation of the event plugin# The type of the eventtype: <type># The generic parameters of the eventdata:
# The identifier that will be used in command like /customevents infocommand-id: <command-id># Information displayed in the command /customevents info information:
- <line-1>
- <line-2>
- ...# The event parametersevent: <event>How to include the API with Maven:
<project>
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>com.github.Flowsqy</groupId>
<artifactId>CustomEvents</artifactId>
<version>1.0.0</version>
</dependency>
</dependencies>
</project>You can register a custom event like this:
packagefr.flowsqy.customeventexample;
importfr.flowsqy.customevents.CustomEventsPlugin;
importfr.flowsqy.customevents.api.Event;
importfr.flowsqy.customevents.api.EventData;
importfr.flowsqy.customevents.api.EventDeserializer;
importorg.bukkit.Bukkit;
importorg.bukkit.Location;
importorg.bukkit.configuration.ConfigurationSection;
importorg.bukkit.configuration.file.YamlConfiguration;
importorg.bukkit.plugin.Plugin;
importorg.bukkit.plugin.java.JavaPlugin;
importjava.util.logging.Logger;
publicclassCustomEventExamplePluginextendsJavaPlugin {
@OverridepublicvoidonEnable() {
finalPluginplugin = Bukkit.getPluginManager().getPlugin("CustomEvents");
if (plugininstanceofCustomEventsPlugincustomEventsPlugin) {
customEventsPlugin.getEventManager().register(
"example", // That is the type needed in the configuration (see above)newExampleEventDeserializer(),
false// Whether this event can replace an existing event with the same identifier
);
}
}
// The deserializer class. Can be in a separate fileprivatestaticfinalclassExampleEventDeserializerimplementsEventDeserializer {
@OverridepublicEventdeserialize(ConfigurationSectionsection, Loggerlogger, StringfileName, EventDataeventData) {
finalStringmessage = section.getString("message");
if (message == null) {
logger.warning("The message key is null in " + fileName + ", you need to set it. ");
returnnull;
}
returnnewExampleEvent(eventData, message);
}
}
// The event class. Can be in a separate fileprivatestaticfinalclassExampleEventimplementsEvent {
privatefinalEventDataeventData;
privatefinalStringmessage;
publicExampleEvent(EventDataeventData, Stringmessage) {
this.eventData = eventData;
this.message = message;
}
@Overridepublicvoidperform() {
Bukkit.broadcastMessage(message);
}
@OverridepublicEventDatagetData() {
returneventData;
}
}
}It will text a message specified in the configuration each time the event is fired.
Just clone the repository and do mvn clean install or mvn clean package. The jar is in the target directory.