code refactoring

This commit is contained in:
unurled 2024-03-18 22:26:42 +01:00
parent ad919e76d5
commit f706a7e91a
Signed by: unurled
GPG key ID: FDBC9CBE1F82423F
4 changed files with 16 additions and 11 deletions

View file

@ -11,12 +11,15 @@ import org.bukkit.Bukkit;
import org.bukkit.event.inventory.InventoryType;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
public class InventoryDeserializer implements JsonDeserializer<Inventory> {
@Override
public Inventory deserialize(
JsonElement jsonElement, Type type, JsonDeserializationContext jsonDeserializationContext)
@NotNull JsonElement jsonElement,
Type type,
JsonDeserializationContext jsonDeserializationContext)
throws JsonParseException {
Inventory inv = Bukkit.createInventory(null, InventoryType.PLAYER);
// parse from a string, to a list of string

View file

@ -7,18 +7,18 @@ import com.google.gson.JsonSerializer;
import java.lang.reflect.Type;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import org.bukkit.inventory.Inventory;
import org.jetbrains.annotations.NotNull;
public class InventorySerializer implements JsonSerializer<Inventory> {
@Override
public JsonElement serialize(
Inventory itemStacks, Type type, JsonSerializationContext jsonSerializationContext) {
@NotNull Inventory itemStacks, Type type, JsonSerializationContext jsonSerializationContext) {
List<String> collect =
Arrays.stream(itemStacks.getContents())
.map(item -> item == null ? "null" : Arrays.toString(item.serializeAsBytes()))
.collect(Collectors.toList());
.toList();
String s = String.join(";", collect);
return new JsonPrimitive(s);

View file

@ -1,7 +1,7 @@
package me.unurled.sacredrealms.sr.gui.entitytype;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import me.unurled.sacredrealms.sr.components.entity.EntityManager;
import me.unurled.sacredrealms.sr.components.entity.SREntityType;
import me.unurled.sacredrealms.sr.gui.BackItem;
@ -21,11 +21,11 @@ public class EntityTypeGUI {
public static @NotNull Gui listGui() {
EntityManager em = Manager.getInstance(EntityManager.class);
List<Item> items =
em.getTypes().stream()
.map(type -> new SimpleItem(new ItemBuilder(type.getItem())))
.collect(Collectors.toList());
List<Item> list = new ArrayList<>();
for (SREntityType type : em.getTypes()) {
SimpleItem simpleItem = new SimpleItem(new ItemBuilder(type.getItem()));
list.add(simpleItem);
}
return PagedGui.items()
.setStructure(
"# # # # # # # # #",
@ -36,7 +36,7 @@ public class EntityTypeGUI {
.addIngredient('X', Markers.CONTENT_LIST_SLOT_HORIZONTAL)
.addIngredient('<', new BackItem())
.addIngredient('>', new ForwardItem())
.setContent(items)
.setContent(list)
.build();
}

View file

@ -5,6 +5,8 @@ import net.kyori.adventure.text.Component;
public class Logger {
private Logger() {}
public static void log(String message) {
SR.getInstance().getLogger().info(message);
}