Search in sources :

Example 1 with GsonBuilder

use of com.massivecraft.massivecore.xlib.gson.GsonBuilder in project MassiveCore by MassiveCraft.

the class MassiveCore method getMassiveCoreGsonBuilder.

public static GsonBuilder getMassiveCoreGsonBuilder() {
    // Create
    GsonBuilder ret = new GsonBuilder();
    // Basic Behavior
    ret.setPrettyPrinting();
    ret.disableHtmlEscaping();
    ret.excludeFieldsWithModifiers(Modifier.TRANSIENT);
    // Raw Adapters
    ret.registerTypeAdapter(JsonNull.class, AdapterJsonElement.get());
    ret.registerTypeAdapter(JsonPrimitive.class, AdapterJsonElement.get());
    ret.registerTypeAdapter(JsonArray.class, AdapterJsonElement.get());
    ret.registerTypeAdapter(JsonObject.class, AdapterJsonElement.get());
    // Enumeration Annotation Dodge
    ret.registerTypeAdapterFactory(AdapterModdedEnumType.ENUM_FACTORY);
    // Massive Containers
    ret.registerTypeAdapter(MassiveList.class, AdapterMassiveList.get());
    ret.registerTypeAdapter(MassiveListDef.class, AdapterMassiveList.get());
    ret.registerTypeAdapter(MassiveMap.class, AdapterMassiveMap.get());
    ret.registerTypeAdapter(MassiveMapDef.class, AdapterMassiveMap.get());
    ret.registerTypeAdapter(MassiveSet.class, AdapterMassiveSet.get());
    ret.registerTypeAdapter(MassiveSetDef.class, AdapterMassiveSet.get());
    ret.registerTypeAdapter(MassiveTreeMap.class, AdapterMassiveTreeMap.get());
    ret.registerTypeAdapter(MassiveTreeMapDef.class, AdapterMassiveTreeMap.get());
    ret.registerTypeAdapter(MassiveTreeSet.class, AdapterMassiveTreeSet.get());
    ret.registerTypeAdapter(MassiveTreeSetDef.class, AdapterMassiveTreeSet.get());
    // Entries (Is this still needed?)
    ret.registerTypeAdapter(Entry.class, AdapterEntry.get());
    // Assorted Custom
    ret.registerTypeAdapter(BackstringSet.class, AdapterBackstringSet.get());
    ret.registerTypeAdapter(PS.class, PSAdapter.get());
    ret.registerTypeAdapter(Sound.class, AdapterSound.get());
    ret.registerTypeAdapter(UUID.class, AdapterUUID.get());
    // Mson
    ret.registerTypeAdapter(Mson.class, AdapterMson.get());
    ret.registerTypeAdapter(MsonEvent.class, AdapterMsonEvent.get());
    // Banner Patterns Upgrade Adapter
    // NOTE: Must come after the "MassiveContainers" section for priority.
    Type typeBannerPatterns = new TypeToken<MassiveListDef<DataBannerPattern>>() {
    }.getType();
    ret.registerTypeAdapter(typeBannerPatterns, AdapterBannerPatterns.get());
    // ItemStack
    ret.registerTypeAdapter(ItemStack.class, AdapterItemStack.get());
    Class<?> classCraftItemStack = NmsItemStackCreate17R4P.getClassCraftItemStackCatch();
    if (classCraftItemStack != null)
        ret.registerTypeAdapter(classCraftItemStack, AdapterItemStack.get());
    // Inventory
    ret.registerTypeAdapter(Inventory.class, AdapterInventory.get());
    ret.registerTypeAdapter(PlayerInventory.class, AdapterPlayerInventory.get());
    // Storage
    ret.registerTypeAdapter(EntityInternalMap.class, AdapterEntityInternalMap.get());
    // Return
    return ret;
}
Also used : RegistryType(com.massivecraft.massivecore.command.type.RegistryType) Type(java.lang.reflect.Type) AdapterModdedEnumType(com.massivecraft.massivecore.adapter.AdapterModdedEnumType) GsonBuilder(com.massivecraft.massivecore.xlib.gson.GsonBuilder) MassiveListDef(com.massivecraft.massivecore.collections.MassiveListDef)

Example 2 with GsonBuilder

use of com.massivecraft.massivecore.xlib.gson.GsonBuilder in project MassiveCore by MassiveCraft.

the class Mson method createGson.

private static Gson createGson(boolean external) {
    GsonBuilder builder = new GsonBuilder();
    builder.disableHtmlEscaping();
    if (external)
        builder.registerTypeAdapter(MsonEvent.class, AdapterMsonEventFix.get());
    builder.registerTypeAdapter(MsonEventAction.class, ADAPTER_LOWERCASE_MSON_EVENT_ACTION);
    builder.registerTypeAdapter(ChatColor.class, ADAPTER_LOWERCASE_CHAT_COLOR);
    // and returns a non-null value on Class#getEnumConstants.
    for (ChatColor color : ChatColor.values()) {
        builder.registerTypeAdapter(color.getClass(), ADAPTER_LOWERCASE_CHAT_COLOR);
    }
    return builder.create();
}
Also used : GsonBuilder(com.massivecraft.massivecore.xlib.gson.GsonBuilder) ChatColor(org.bukkit.ChatColor)

Aggregations

GsonBuilder (com.massivecraft.massivecore.xlib.gson.GsonBuilder)2 AdapterModdedEnumType (com.massivecraft.massivecore.adapter.AdapterModdedEnumType)1 MassiveListDef (com.massivecraft.massivecore.collections.MassiveListDef)1 RegistryType (com.massivecraft.massivecore.command.type.RegistryType)1 Type (java.lang.reflect.Type)1 ChatColor (org.bukkit.ChatColor)1