Skip to content

Commit

Permalink
Fixed EssentialsX deserializer
Browse files Browse the repository at this point in the history
  • Loading branch information
Mgazul committed Jun 11, 2021
1 parent b93d1b6 commit fa50a83
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 5 deletions.
@@ -0,0 +1,64 @@
/*
* Copyright (C) 2011 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.google.gson.internal.bind;

import com.google.gson.TypeAdapter;
import com.google.gson.annotations.SerializedName;
import com.google.gson.stream.JsonReader;
import com.google.gson.stream.JsonToken;
import com.google.gson.stream.JsonWriter;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

public final class TypeAdapters$EnumTypeAdapter<T extends Enum<T>> extends TypeAdapter<T> {
private final Map<String, T> nameToConstant = new HashMap<String, T>();
private final Map<T, String> constantToName = new HashMap<T, String>();

public TypeAdapters$EnumTypeAdapter(Class<T> classOfT) {
try {
for (T constant : classOfT.getEnumConstants()) {
String name = constant.name();
SerializedName annotation = classOfT.getField(name).getAnnotation(SerializedName.class);
if (annotation != null) {
name = annotation.value();
for (String alternate : annotation.alternate()) {
nameToConstant.put(alternate, constant);
}
}
nameToConstant.put(name, constant);
constantToName.put(constant, name);
}
} catch (NoSuchFieldException e) {
// Mohist - Don't throw exception
}
}

@Override
public T read(JsonReader in) throws IOException {
if (in.peek() == JsonToken.NULL) {
in.nextNull();
return null;
}
return nameToConstant.get(in.nextString());
}

@Override
public void write(JsonWriter out, T value) throws IOException {
out.value(value == null ? null : constantToName.get(value));
}
}
2 changes: 2 additions & 0 deletions src/fmllauncher/java/com/mohistmc/MohistMCStart.java
@@ -1,5 +1,6 @@
package com.mohistmc;

import com.google.gson.internal.bind.TypeAdapters$EnumTypeAdapter;
import com.mohistmc.config.MohistConfigUtil;
import com.mohistmc.libraries.CustomLibraries;
import com.mohistmc.libraries.DefaultLibraries;
Expand Down Expand Up @@ -39,6 +40,7 @@ public static void main() throws Exception {
}
CustomLibraries.loadCustomLibs();
new JarLoader().loadJar(InstallUtils.extra);
TypeAdapters$EnumTypeAdapter.class.getClassLoader();
if (MohistConfigUtil.bMohist("check_update", "true")) UpdateUtils.versionCheck();
if (!hasAcceptedEULA()) {
System.out.println(i18n.get("eula"));
Expand Down
5 changes: 0 additions & 5 deletions src/fmllauncher/java/com/mohistmc/util/AutoDeletePlugins.java
Expand Up @@ -10,11 +10,6 @@
public class AutoDeletePlugins {

public static ArrayList<PluginsModsDelete.Fix> LIST = new ArrayList<>(Arrays.asList(
new PluginsModsDelete.Fix("com.earth2me.essentials.Essentials",
"https://github.com/KR33PY/Essentials/releases/download/essxmohist/EssentialsX-2.19.0-dev+99-fd961d5.jar",
"2.19.0-dev+99-fd961d5",
"https://github.com/MohistMC/Essentials",
"This fix make modded blocks and items compatible"),

new PluginsModsDelete.Fix("com.sk89q.worldedit.bukkit.WorldEditPlugin",
"https://github.com/MohistMC/WorldEdit/releases/download/1.16.5-1.0/worldedit-bukkit-7.3.0-MOHIST-dist.jar",
Expand Down

0 comments on commit fa50a83

Please sign in to comment.