I'm making a plugin for Minecraft with Bukkit framework. To add custom event there, I have to do my event class like this:
public class CityCreationCommandEvent extends CancellableCommandEvent {
private static final HandlerList handlers = new HandlerList();
private final String cityName;
public CityCreationCommandEvent(CommandSender sender, String name) {
super(sender);
this.cityName = name;
}
public String getCityName() {
return this.cityName;
}
@NotNull
public HandlerList getHandlers() {
return handlers;
}
@NotNull
public static HandlerList getHandlerList() {
return handlers;
}
}
And, this code contains boilerplate lines, that have to be printed for every new event:
private static final HandlerList handlers = new HandlerList();
public String getCityName() {
return this.cityName;
}
@NotNull
public HandlerList getHandlers() {
return handlers;
}
@NotNull
public static HandlerList getHandlerList() {
return handlers;
}
I can add getter and setters using lombok, but these lines
private static final HandlerList handlers = new HandlerList();
@NotNull
public HandlerList getHandlers() {
return handlers;
}
@NotNull
public static HandlerList getHandlerList() {
return handlers;
}
will stay in code anyway. I want to write my own annotation to do something like this:
@Event
public class CityCreationCommandEvent extends CancellableCommandEvent {
@Getter
private final String cityName;
public CityCreationCommandEvent(CommandSender sender, String name) {
super(sender);
this.cityName = name;
}
}
or even this (but I think it will be hard to make)
@Event
public class CityCreationCommandEvent extends CancellableCommandEvent {
@Value
private final String cityName;
}
or
@Event
@UnmodifiableValue(type = String.class, name = "cityName")
public class CityCreationCommandEvent extends CancellableCommandEvent {}
I have an idea to do this manually by javac, but it quite difficult (keeping in mind the fact that if I want to use the generated methods in the ide, I will have to write my own plugin for the ide).
So, the best way is to integrate with lombok. Does lombok have an API to do something like this? Or, if not, how I can do something like this using already existing annotations?