perf: 重写部分代码

This commit is contained in:
2023-05-30 04:51:53 +08:00
parent c485c29d5d
commit 525d99a8bf
2 changed files with 5 additions and 7 deletions

View File

@@ -3,7 +3,6 @@ package cn.hamster3.mc.plugin.core.bukkit.util;
import cn.hamster3.mc.plugin.core.bukkit.listener.CallbackListener; import cn.hamster3.mc.plugin.core.bukkit.listener.CallbackListener;
import cn.hamster3.mc.plugin.core.common.data.DisplayMessage; import cn.hamster3.mc.plugin.core.common.data.DisplayMessage;
import com.comphenix.protocol.utility.StreamSerializer; import com.comphenix.protocol.utility.StreamSerializer;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Material; import org.bukkit.Material;
@@ -281,13 +280,12 @@ public final class CoreBukkitUtils {
} }
@NotNull @NotNull
public static PotionEffect deserializePotionEffect(@NotNull JsonElement element) { public static PotionEffect deserializePotionEffect(@NotNull JsonObject object) {
JsonObject effectObject = element.getAsJsonObject();
//noinspection ConstantConditions //noinspection ConstantConditions
return new PotionEffect( return new PotionEffect(
PotionEffectType.getByName(effectObject.get("type").getAsString()), PotionEffectType.getByName(object.get("type").getAsString()),
effectObject.get("duration").getAsInt(), object.get("duration").getAsInt(),
effectObject.get("amplifier").getAsInt() object.get("amplifier").getAsInt()
); );
} }

View File

@@ -17,7 +17,7 @@ public final class PotionEffectAdapter implements JsonSerializer<PotionEffect>,
if (json.isJsonNull()) { if (json.isJsonNull()) {
return null; return null;
} }
return CoreBukkitUtils.deserializePotionEffect(json); return CoreBukkitUtils.deserializePotionEffect(json.getAsJsonObject());
} }
@Override @Override