9
0
mirror of https://github.com/Xiao-MoMi/craft-engine.git synced 2025-12-30 12:29:15 +00:00

参数默认值

This commit is contained in:
XiaoMoMi
2025-06-09 04:25:50 +08:00
parent 22d2b7716e
commit ca021229a6
9 changed files with 60 additions and 16 deletions

View File

@@ -1,12 +1,32 @@
package net.momirealms.craftengine.bukkit.plugin;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import net.momirealms.craftengine.bukkit.nms.FastNMS;
import net.momirealms.craftengine.bukkit.plugin.reflection.minecraft.MRegistryOps;
import net.momirealms.craftengine.core.plugin.CraftEngine;
import net.momirealms.craftengine.core.plugin.Platform;
import net.momirealms.craftengine.core.plugin.locale.LocalizedResourceConfigException;
import org.bukkit.Bukkit;
import java.util.Map;
public class BukkitPlatform implements Platform {
@Override
public void dispatchCommand(String command) {
Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), command);
}
@SuppressWarnings("unchecked")
@Override
public Object nbt2Java(String nbt) {
try {
Object tag = FastNMS.INSTANCE.method$TagParser$parseCompoundFully("{\"root\":" + nbt + "}");
Map<String, Object> map = (Map<String, Object>) MRegistryOps.NBT.convertTo(MRegistryOps.JAVA, tag);
return map.get("root");
} catch (CommandSyntaxException e) {
CraftEngine.instance().debug(e::getMessage);
throw new LocalizedResourceConfigException("warning.config.template.argument.default_value.invalid_syntax", e, nbt);
}
}
}

View File

@@ -9,6 +9,7 @@ import net.momirealms.craftengine.bukkit.util.BukkitReflectionUtils;
import net.momirealms.craftengine.core.util.ReflectionUtils;
import net.momirealms.craftengine.core.util.VersionHelper;
import net.momirealms.sparrow.nbt.Tag;
import net.momirealms.sparrow.nbt.codec.LegacyJavaOps;
import net.momirealms.sparrow.nbt.codec.LegacyNBTOps;
import net.momirealms.sparrow.nbt.codec.NBTOps;
@@ -34,8 +35,12 @@ public class MRegistryOps {
static {
try {
if (clazz$JavaOps != null) {
// 1.20.5+
Object javaOps = ReflectionUtils.getDeclaredField(clazz$JavaOps, clazz$JavaOps, 0).get(null);
JAVA = (DynamicOps<Object>) CoreReflections.method$RegistryOps$create.invoke(null, javaOps, FastNMS.INSTANCE.registryAccess());
} else if (!VersionHelper.isOrAbove1_20_5()) {
// 1.20.1-1.20.4
JAVA = (DynamicOps<Object>) CoreReflections.method$RegistryOps$create.invoke(null, LegacyJavaOps.INSTANCE, FastNMS.INSTANCE.registryAccess());
} else {
JAVA = null;
}

View File

@@ -138,17 +138,17 @@ public class BukkitServerPlayer extends Player {
@Override
public Channel nettyChannel() {
return channel;
return this.channel;
}
@Override
public CraftEngine plugin() {
return plugin;
return this.plugin;
}
@Override
public boolean isMiningBlock() {
return destroyPos != null;
return this.destroyPos != null;
}
public void setDestroyedState(Object destroyedState) {
@@ -221,8 +221,8 @@ public class BukkitServerPlayer extends Player {
@Override
public boolean updateLastSuccessfulInteractionTick(int tick) {
if (lastSuccessfulInteraction != tick) {
lastSuccessfulInteraction = tick;
if (this.lastSuccessfulInteraction != tick) {
this.lastSuccessfulInteraction = tick;
return true;
} else {
return false;
@@ -231,7 +231,7 @@ public class BukkitServerPlayer extends Player {
@Override
public int lastSuccessfulInteractionTick() {
return lastSuccessfulInteraction;
return this.lastSuccessfulInteraction;
}
@Override