fixed missing client side server references. fixes #311

This commit is contained in:
gnembon committed 2020-06-06 20:39:25 -03:00
1 parent 7bbae714ea
commit b3484fd012
10 files changed
+36 -27

No files matched your search

+1 -1
View File
@@ -57,7 +57,7 @@ public class CarpetServer // static for now - easier to handle all around the co
if (sm != null) sm.attachServer(server);
e.onServerLoaded(server);
});
scriptServer = new CarpetScriptServer();
scriptServer = new CarpetScriptServer(server);
scriptServer.loadAllWorldScripts();
MobAI.resetTrackers();
LoggerRegistry.initLoggers();
+3 -2
View File
@@ -501,8 +501,8 @@ public class CarpetSettings
if (server.isDedicated())
{
int vd = (newValue >= 2)?newValue:((DedicatedServer) server).getProperties().viewDistance;
if (vd != CarpetServer.minecraft_server.getPlayerManager().getViewDistance())
CarpetServer.minecraft_server.getPlayerManager().setViewDistance(vd);
if (vd != server.getPlayerManager().getViewDistance())
server.getPlayerManager().setViewDistance(vd);
return newValue;
}
else
@@ -549,6 +549,7 @@ public class CarpetSettings
//must been some startup thing
return newValue;
}
if (CarpetServer.minecraft_server == null) return newValue;
ServerWorld currentOverworld = CarpetServer.minecraft_server.getWorld(DimensionType.OVERWORLD);
if (currentOverworld != null)
{
@@ -16,6 +16,7 @@ import net.minecraft.command.arguments.DimensionArgumentType;
import net.minecraft.entity.EntityCategory;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.util.DyeColor;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.dimension.DimensionType;
@@ -195,7 +196,7 @@ public class SpawnCommand
TickSpeed.tickrate_advance(null, 0, null, null);
// tick warp given player
ServerCommandSource csource = null;
PlayerEntity player = null;
ServerPlayerEntity player = null;
try
{
player = source.getPlayer();
@@ -9,6 +9,7 @@ import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.text.BaseText;
import net.minecraft.server.command.ServerCommandSource;
@@ -80,7 +81,7 @@ public class TickCommand
private static int setWarp(ServerCommandSource source, int advance, String tail_command)
{
PlayerEntity player = null;
ServerPlayerEntity player = null;
try
{
player = source.getPlayer();
+5 -4
View File
@@ -7,10 +7,10 @@ import java.util.function.BiConsumer;
import carpet.CarpetServer;
import carpet.network.ServerNetworkHandler;
import carpet.utils.Messenger;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.command.CommandManager;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.text.BaseText;
public class TickSpeed
@@ -21,7 +21,7 @@ public class TickSpeed
public static long time_bias = 0;
public static long time_warp_start_time = 0;
public static long time_warp_scheduled_ticks = 0;
public static PlayerEntity time_advancerer = null;
public static ServerPlayerEntity time_advancerer = null;
public static String tick_warp_callback = null;
public static ServerCommandSource tick_warp_sender = null;
public static int player_active_timeout = 0;
@@ -68,13 +68,14 @@ public class TickSpeed
player_active_timeout = PLAYER_GRACE+ticks;
}
public static BaseText tickrate_advance(PlayerEntity player, int advance, String callback, ServerCommandSource source)
public static BaseText tickrate_advance(ServerPlayerEntity player, int advance, String callback, ServerCommandSource source)
{
if (0 == advance)
{
tick_warp_callback = null;
tick_warp_sender = null;
if (source != tick_warp_sender) tick_warp_sender = null;
finish_time_warp();
tick_warp_sender = null;
return Messenger.c("gi Warp interrupted");
}
if (time_bias > 0)
@@ -23,7 +23,7 @@ public abstract class PlayerEntity_antiCheatDisabled
@Inject(method = "method_23668", at = @At("HEAD"), cancellable = true)
private void allowDeploys(CallbackInfoReturnable<Boolean> cir)
{
if (CarpetSettings.antiCheatDisabled && CarpetServer.minecraft_server.isDedicated())
if (CarpetSettings.antiCheatDisabled && CarpetServer.minecraft_server != null && CarpetServer.minecraft_server.isDedicated())
{
ItemStack itemStack_1 = getEquippedStack(EquipmentSlot.CHEST);
if (itemStack_1.getItem() == Items.ELYTRA && ElytraItem.isUsable(itemStack_1)) {
@@ -13,6 +13,7 @@ import carpet.script.value.Value;
import carpet.utils.Messenger;
import net.minecraft.block.BlockState;
import net.minecraft.entity.damage.DamageSource;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.entity.Entity;
import net.minecraft.server.network.ServerPlayerEntity;
@@ -51,6 +52,7 @@ import java.util.stream.Collectors;
public class CarpetEventServer
{
public final List<ScheduledCall> scheduledCalls = new LinkedList<>();
public final MinecraftServer server;
public static class Callback
{
@@ -652,8 +654,9 @@ public class CarpetEventServer
}
public CarpetEventServer()
public CarpetEventServer(MinecraftServer server)
{
this.server = server;
for (Event e: Event.values())
e.handler.callList.clear();
}
@@ -323,7 +323,7 @@ public class CarpetScriptHost extends ScriptHost
{
try
{
callUDF(BlockPos.ORIGIN, CarpetServer.minecraft_server.getCommandSource(), closing, Collections.emptyList());
callUDF(BlockPos.ORIGIN, scriptServer.server.getCommandSource(), closing, Collections.emptyList());
}
catch (InvalidCallbackException ignored)
{
@@ -334,8 +334,8 @@ public class CarpetScriptHost extends ScriptHost
FunctionValue userClosing = value.getFunction("__on_close");
if (userClosing != null)
{
ServerPlayerEntity player = CarpetServer.minecraft_server.getPlayerManager().getPlayer(key);
ServerCommandSource source = (player != null)?player.getCommandSource():CarpetServer.minecraft_server.getCommandSource();
ServerPlayerEntity player = scriptServer.server.getPlayerManager().getPlayer(key);
ServerCommandSource source = (player != null)?player.getCommandSource():scriptServer.server.getCommandSource();
try
{
((CarpetScriptHost) value).callUDF(BlockPos.ORIGIN, source, userClosing, Collections.emptyList());
@@ -347,7 +347,7 @@ public class CarpetScriptHost extends ScriptHost
});
String markerName = CarpetExpression.MARKER_STRING+"_"+((getName()==null)?"":getName());
for (ServerWorld world : CarpetServer.minecraft_server.getWorlds())
for (ServerWorld world : scriptServer.server.getWorlds())
{
for (Entity e : world.getEntities(EntityType.ARMOR_STAND, (as) -> as.getScoreboardTags().contains(markerName)))
{
@@ -15,6 +15,7 @@ import carpet.utils.Messenger;
import com.mojang.brigadier.arguments.StringArgumentType;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import com.mojang.brigadier.tree.CommandNode;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.util.math.BlockPos;
@@ -34,6 +35,7 @@ import static net.minecraft.server.command.CommandManager.literal;
public class CarpetScriptServer
{
//make static for now, but will change that later:
public final MinecraftServer server;
public final CarpetScriptHost globalHost;
public final Map<String, CarpetScriptHost> modules;
public long tickStart;
@@ -49,14 +51,15 @@ public class CarpetScriptServer
add(new BundledModule("math", true));
}};
public CarpetScriptServer()
public CarpetScriptServer(MinecraftServer server)
{
this.server = server;
ScriptHost.systemGlobals.clear();
events = new CarpetEventServer();
events = new CarpetEventServer(server);
modules = new HashMap<>();
tickStart = 0L;
stopAll = false;
holyMoly = CarpetServer.minecraft_server.getCommandManager().getDispatcher().getRoot().getChildren().stream().map(CommandNode::getName).collect(Collectors.toSet());
holyMoly = server.getCommandManager().getDispatcher().getRoot().getChildren().stream().map(CommandNode::getName).collect(Collectors.toSet());
globalHost = CarpetScriptHost.create(this, null, false, null);
}
@@ -64,10 +67,10 @@ public class CarpetScriptServer
{
if (CarpetSettings.scriptsAutoload)
{
Messenger.m(CarpetServer.minecraft_server.getCommandSource(), "Auto-loading world scarpet apps");
Messenger.m(server.getCommandSource(), "Auto-loading world scarpet apps");
for (String moduleName: listAvailableModules(false))
{
addScriptHost(CarpetServer.minecraft_server.getCommandSource(), moduleName, true, true);
addScriptHost(server.getCommandSource(), moduleName, true, true);
}
}
@@ -75,8 +78,8 @@ public class CarpetScriptServer
public Module getModule(String name, boolean allowLibraries)
{
File folder = CarpetServer.minecraft_server.getLevelStorage().resolveFile(
CarpetServer.minecraft_server.getLevelName(), "scripts");
File folder = server.getLevelStorage().resolveFile(
server.getLevelName(), "scripts");
File[] listOfFiles = folder.listFiles();
if (listOfFiles != null)
for (File script : listOfFiles)
@@ -110,8 +113,8 @@ public class CarpetScriptServer
if (!mi.isLibrary()) moduleNames.add(mi.getName());
}
}
File folder = CarpetServer.minecraft_server.getLevelStorage().resolveFile(
CarpetServer.minecraft_server.getLevelName(), "scripts");
File folder = server.getLevelStorage().resolveFile(
server.getLevelName(), "scripts");
File[] listOfFiles = folder.listFiles();
if (listOfFiles == null)
return moduleNames;
@@ -223,7 +226,7 @@ public class CarpetScriptServer
})));
}
Messenger.m(source, "gi "+hostName+" app loaded with /"+hostName+" command");
CarpetServer.minecraft_server.getCommandManager().getDispatcher().register(command);
server.getCommandManager().getDispatcher().register(command);
CarpetServer.settingsManager.notifyPlayersCommandsChanged();
}
@@ -362,8 +362,7 @@ public class SettingsManager
{
if (dispatcher.getRoot().getChildren().stream().anyMatch(node -> node.getName().equalsIgnoreCase(identifier)))
{
Messenger.print_server_message(CarpetServer.minecraft_server,
Messenger.c("rb Failed to add settings command for " + identifier + ". It is masking previous command."));
CarpetSettings.LOG.error("Failed to add settings command for " + identifier + ". It is masking previous command.");
return;
}