-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
slightly imporve pluginyml class generation
- Loading branch information
Showing
2 changed files
with
86 additions
and
0 deletions.
There are no files selected for viewing
52 changes: 52 additions & 0 deletions
52
src/main/java/org/comroid/api/model/minecraft/model/DefaultPermissionValue.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package org.comroid.api.model.minecraft.model; | ||
|
||
import com.fasterxml.jackson.core.JsonGenerator; | ||
import com.fasterxml.jackson.core.JsonParser; | ||
import com.fasterxml.jackson.databind.DeserializationContext; | ||
import com.fasterxml.jackson.databind.JsonDeserializer; | ||
import com.fasterxml.jackson.databind.JsonSerializer; | ||
import com.fasterxml.jackson.databind.SerializerProvider; | ||
import lombok.AccessLevel; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.Value; | ||
import lombok.experimental.FieldDefaults; | ||
import org.comroid.api.attr.Named; | ||
|
||
import java.io.IOException; | ||
import java.util.Arrays; | ||
|
||
@Getter | ||
@RequiredArgsConstructor | ||
@FieldDefaults(level = AccessLevel.PRIVATE, makeFinal = true) | ||
public | ||
enum DefaultPermissionValue implements Named { | ||
FALSE("false"), | ||
NOT_OP("not op"), | ||
OP("op"), | ||
TRUE("true"); | ||
|
||
String ident; | ||
|
||
@NoArgsConstructor | ||
public static class Serializer extends JsonSerializer<DefaultPermissionValue> { | ||
@Override | ||
public void serialize(DefaultPermissionValue value, JsonGenerator gen, SerializerProvider serializers) throws IOException { | ||
gen.writeString(value.ident); | ||
} | ||
} | ||
|
||
@Value | ||
@NoArgsConstructor | ||
public static class Deserializer extends JsonDeserializer<DefaultPermissionValue> { | ||
@Override | ||
public DefaultPermissionValue deserialize(JsonParser p, DeserializationContext ctxt) throws IOException { | ||
var id = p.getValueAsString(); | ||
return Arrays.stream(values()) | ||
.filter(item -> item.ident.equals(id)) | ||
.findAny() | ||
.orElse(DefaultPermissionValue.OP); | ||
} | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
src/main/java/org/comroid/api/model/minecraft/model/PluginLoadTime.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package org.comroid.api.model.minecraft.model; | ||
|
||
import com.fasterxml.jackson.core.JsonGenerator; | ||
import com.fasterxml.jackson.core.JsonParser; | ||
import com.fasterxml.jackson.databind.DeserializationContext; | ||
import com.fasterxml.jackson.databind.JsonDeserializer; | ||
import com.fasterxml.jackson.databind.JsonSerializer; | ||
import com.fasterxml.jackson.databind.SerializerProvider; | ||
import lombok.NoArgsConstructor; | ||
import lombok.Value; | ||
import org.comroid.api.attr.Named; | ||
|
||
import java.io.IOException; | ||
|
||
public enum PluginLoadTime implements Named { | ||
STARTUP, POSTWORLD; | ||
|
||
@NoArgsConstructor | ||
public static class Serializer extends JsonSerializer<PluginLoadTime> { | ||
@Override | ||
public void serialize(PluginLoadTime value, JsonGenerator gen, SerializerProvider serializers) throws IOException { | ||
gen.writeString(value.name()); | ||
} | ||
} | ||
|
||
@Value | ||
@NoArgsConstructor | ||
public static class Deserializer extends JsonDeserializer<PluginLoadTime> { | ||
@Override | ||
public PluginLoadTime deserialize(JsonParser p, DeserializationContext ctxt) throws IOException { | ||
return PluginLoadTime.valueOf(p.getValueAsString()); | ||
} | ||
} | ||
} |