Skip to content

Commit c9a3f52

Browse files
committed
1.19.2
1 parent ffa4fcf commit c9a3f52

File tree

208 files changed

+2
-36709
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

208 files changed

+2
-36709
lines changed

src/main/java/carpet/CarpetExtension.java

-18
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package carpet;
22

3-
import carpet.script.CarpetExpression;
43
import carpet.api.settings.SettingsManager;
54
import com.mojang.brigadier.CommandDispatcher;
65
import net.minecraft.commands.CommandBuildContext;
@@ -152,21 +151,4 @@ default void registerLoggers() {}
152151
*/
153152
default Map<String, String> canHasTranslations(String lang) { return Collections.emptyMap();}
154153

155-
/**
156-
* Handles each call that creates / parses the scarpet expression.
157-
* Extensions can add their own built-in functions here.
158-
*
159-
* Events such as generic events or entity events, can be added statically
160-
* by creating new events as
161-
*
162-
* CarpetEventServer.Event class: to handle `__on_foo()` type of call definitions
163-
*
164-
* or
165-
*
166-
* EntityEventsGroup.Event class: to handle `entity_event('foo', ...)` type of events
167-
*
168-
* @param expression Passed {@link CarpetExpression} to add built-in functions to
169-
*/
170-
default void scarpetApi(CarpetExpression expression) {}
171-
172154
}

src/main/java/carpet/CarpetServer.java

-16
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,15 @@
1414
import carpet.commands.PerimeterInfoCommand;
1515
import carpet.commands.PlayerCommand;
1616
import carpet.commands.ProfileCommand;
17-
import carpet.commands.ScriptCommand;
1817
import carpet.commands.SpawnCommand;
1918
import carpet.commands.TestCommand;
2019
import carpet.commands.TickCommand;
2120
import carpet.network.ServerNetworkHandler;
2221
import carpet.helpers.HopperCounter;
2322
import carpet.helpers.TickSpeed;
2423
import carpet.logging.LoggerRegistry;
25-
import carpet.script.CarpetScriptServer;
2624
import carpet.api.settings.SettingsManager;
2725
import carpet.logging.HUDController;
28-
import carpet.utils.FabricAPIHooks;
2926
import carpet.utils.MobAI;
3027
import carpet.utils.SpawnReporter;
3128
import com.mojang.brigadier.CommandDispatcher;
@@ -42,7 +39,6 @@ public class CarpetServer // static for now - easier to handle all around the co
4239
{
4340
public static MinecraftServer minecraft_server;
4441
private static CommandDispatcher<CommandSourceStack> currentCommandDispatcher;
45-
public static CarpetScriptServer scriptServer;
4642
public static carpet.settings.SettingsManager settingsManager; // to change type to api type, can't change right now because of binary and source compat
4743
public static final List<CarpetExtension> extensions = new ArrayList<>();
4844

@@ -80,8 +76,6 @@ public static void onGameStarted()
8076
settingsManager = new carpet.settings.SettingsManager(CarpetSettings.carpetVersion, "carpet", "Carpet Mod");
8177
settingsManager.parseSettingsClass(CarpetSettings.class);
8278
extensions.forEach(CarpetExtension::onGameStarted);
83-
FabricAPIHooks.initialize();
84-
CarpetScriptServer.parseFunctionClasses();
8579
}
8680

8781
public static void onServerLoaded(MinecraftServer server)
@@ -96,7 +90,6 @@ public static void onServerLoaded(MinecraftServer server)
9690
if (sm != null) sm.attachServer(server);
9791
e.onServerLoaded(server);
9892
});
99-
scriptServer = new CarpetScriptServer(server);
10093
MobAI.resetTrackers();
10194
LoggerRegistry.initLoggers();
10295
//TickSpeed.reset();
@@ -106,14 +99,12 @@ public static void onServerLoadedWorlds(MinecraftServer minecraftServer)
10699
{
107100
HopperCounter.resetAll(minecraftServer, true);
108101
extensions.forEach(e -> e.onServerLoadedWorlds(minecraftServer));
109-
scriptServer.initializeForWorld();
110102
}
111103

112104
public static void tick(MinecraftServer server)
113105
{
114106
TickSpeed.tick();
115107
HUDController.update_hud(server, null);
116-
if (scriptServer != null) scriptServer.tick();
117108

118109
//in case something happens
119110
CarpetSettings.impendingFillSkipUpdates.set(false);
@@ -142,7 +133,6 @@ public static void registerCarpetCommands(CommandDispatcher<CommandSourceStack>
142133
DistanceCommand.register(dispatcher, commandBuildContext);
143134
PerimeterInfoCommand.register(dispatcher, commandBuildContext);
144135
DrawCommand.register(dispatcher, commandBuildContext);
145-
ScriptCommand.register(dispatcher, commandBuildContext);
146136
MobAICommand.register(dispatcher, commandBuildContext);
147137
// registering command of extensions that has registered before either server is created
148138
// for all other, they will have them registered when they add themselves
@@ -163,7 +153,6 @@ public static void onPlayerLoggedIn(ServerPlayer player)
163153
{
164154
ServerNetworkHandler.onPlayerJoin(player);
165155
LoggerRegistry.playerConnected(player);
166-
scriptServer.onPlayerJoin(player);
167156
extensions.forEach(e -> e.onPlayerLoggedIn(player));
168157

169158
}
@@ -177,8 +166,6 @@ public static void onPlayerLoggedOut(ServerPlayer player)
177166

178167
public static void clientPreClosing()
179168
{
180-
if (scriptServer != null) scriptServer.onClose();
181-
scriptServer = null;
182169
}
183170

184171
public static void onServerClosed(MinecraftServer server)
@@ -187,8 +174,6 @@ public static void onServerClosed(MinecraftServer server)
187174
// so we allow to pass multiple times gating it only on existing server ref
188175
if (minecraft_server != null)
189176
{
190-
if (scriptServer != null) scriptServer.onClose();
191-
scriptServer = null;
192177
ServerNetworkHandler.close();
193178
currentCommandDispatcher = null;
194179

@@ -217,7 +202,6 @@ public static void registerExtensionLoggers()
217202

218203
public static void onReload(MinecraftServer server)
219204
{
220-
scriptServer.reload(server);
221205
extensions.forEach(e -> e.onReload(server));
222206
}
223207

src/main/java/carpet/CarpetSettings.java

-84
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import carpet.api.settings.RuleCategory;
55
import carpet.api.settings.Validators;
66
import carpet.api.settings.Validator;
7-
import carpet.script.utils.AppStoreManager;
87
import carpet.settings.Rule;
98
import carpet.utils.Translations;
109
import carpet.utils.CommandHelper;
@@ -49,7 +48,6 @@ public class CarpetSettings
4948
{
5049
public static final String carpetVersion = "1.4.84+v221018";
5150
public static final Logger LOG = LoggerFactory.getLogger("carpet");
52-
public static final ThreadLocal<Boolean> skipGenerationChecks = ThreadLocal.withInitial(() -> false);
5351
public static final ThreadLocal<Boolean> impendingFillSkipUpdates = ThreadLocal.withInitial(() -> false);
5452
public static int runPermissionLevel = 2;
5553
public static boolean doChainStone = false;
@@ -473,88 +471,6 @@ private static class ChainStoneSetting extends Validator<String> {
473471

474472
@Rule(desc = "Enables /draw commands", extra = {"... allows for drawing simple shapes or","other shapes which are sorta difficult to do normally"}, category = COMMAND)
475473
public static String commandDraw = "ops";
476-
477-
478-
@Rule(
479-
desc = "Enables /script command",
480-
extra = "An in-game scripting API for Scarpet programming language",
481-
category = {COMMAND, SCARPET}
482-
)
483-
public static String commandScript = "true";
484-
485-
private static class ModulePermissionLevel extends Validator<String> {
486-
@Override public String validate(CommandSourceStack source, CarpetRule<String> currentRule, String newValue, String string) {
487-
int permissionLevel = switch (newValue) {
488-
case "false":
489-
yield 0;
490-
case "true":
491-
case "ops":
492-
yield 2;
493-
case "0":
494-
case "1":
495-
case "2":
496-
case "3":
497-
case "4":
498-
yield Integer.parseInt(newValue);
499-
default: throw new IllegalArgumentException();
500-
};
501-
if (source != null && !source.hasPermission(permissionLevel))
502-
return null;
503-
CarpetSettings.runPermissionLevel = permissionLevel;
504-
if (source != null)
505-
CommandHelper.notifyPlayersCommandsChanged(source.getServer());
506-
return newValue;
507-
}
508-
@Override
509-
public String description() { return "When changing the rule, you must at least have the permission level you are trying to give it";}
510-
}
511-
@Rule(
512-
desc = "Enables restrictions for arbitrary code execution with scarpet",
513-
extra = {
514-
"Users that don't have this permission level",
515-
"won't be able to load apps or /script run.",
516-
"It is also the permission level apps will",
517-
"have when running commands with run()"
518-
},
519-
category = {SCARPET},
520-
options = {"ops", "0", "1", "2", "3", "4"},
521-
validate = {Validators.CommandLevel.class, ModulePermissionLevel.class}
522-
)
523-
public static String commandScriptACE = "ops";
524-
525-
@Rule(
526-
desc = "Scarpet script from world files will autoload on server/world start ",
527-
extra = "if /script is enabled",
528-
category = SCARPET
529-
)
530-
public static boolean scriptsAutoload = true;
531-
532-
@Rule(
533-
desc = "Enables scripts debugging messages in system log",
534-
category = SCARPET
535-
)
536-
public static boolean scriptsDebugging = false;
537-
538-
@Rule(
539-
desc = "Enables scripts optimization",
540-
category = SCARPET
541-
)
542-
public static boolean scriptsOptimization = true;
543-
544-
@Rule(
545-
desc = "Location of the online repository of scarpet apps",
546-
extra = {
547-
"set to 'none' to disable.",
548-
"Point to any github repo with scarpet apps",
549-
"using <user>/<repo>/contents/<path...>"
550-
},
551-
category = SCARPET,
552-
strict = false,
553-
validate= AppStoreManager.ScarpetAppStoreValidator.class
554-
)
555-
public static String scriptsAppStore = "gnembon/scarpet/contents/programs";
556-
557-
558474
@Rule(desc = "Enables /player command to control/spawn players", category = COMMAND)
559475
public static String commandPlayer = "ops";
560476

src/main/java/carpet/api/settings/SettingsManager.java

-29
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@
5454
import net.minecraft.server.MinecraftServer;
5555
import net.minecraft.world.level.storage.LevelResource;
5656

57-
import static carpet.script.CarpetEventServer.Event.CARPET_RULE_CHANGES;
5857
import static carpet.utils.Translations.tr;
5958
import static java.util.Comparator.comparing;
6059
import static net.minecraft.commands.Commands.argument;
@@ -263,8 +262,6 @@ public void notifyRuleChanged(CommandSourceStack source, CarpetRule<?> rule, Str
263262
observers.forEach(observer -> observer.ruleChanged(source, rule, userInput));
264263
staticObservers.forEach(observer -> observer.ruleChanged(source, rule, userInput));
265264
ServerNetworkHandler.updateRuleWithConnectedClients(rule);
266-
switchScarpetRuleIfNeeded(source, rule); //TODO move into rule
267-
if (CARPET_RULE_CHANGES.isNeeded()) CARPET_RULE_CHANGES.onCarpetRuleChanges(rule, source);
268265
}
269266

270267
/**
@@ -289,19 +286,6 @@ public void detachServer()
289286
for (CarpetRule<?> rule : rules.values()) RuleHelper.resetToDefault(rule, null);
290287
server = null;
291288
}
292-
293-
/**
294-
* <p>Initializes Scarpet rules in this {@link SettingsManager}, if any.</p>
295-
* <p>This is handled automatically by Carpet and calling it is not supported.</p>
296-
*/
297-
public void initializeScarpetRules() { //TODO try remove
298-
for (CarpetRule<?> rule : rules.values())
299-
{
300-
if (rule instanceof ParsedRule<?> pr && !pr.scarpetApp.isEmpty()) {
301-
switchScarpetRuleIfNeeded(server.createCommandSourceStack(), pr);
302-
}
303-
}
304-
}
305289

306290
/**
307291
* Calling this method is not supported.
@@ -326,19 +310,6 @@ public void inspectClientsideCommand(CommandSourceStack source, String string)
326310
}
327311
}
328312
}
329-
330-
private void switchScarpetRuleIfNeeded(CommandSourceStack source, CarpetRule<?> carpetRule) //TODO remove. This should be handled by the rule
331-
{
332-
if (carpetRule instanceof ParsedRule<?> rule && !rule.scarpetApp.isEmpty() && CarpetServer.scriptServer != null) // null check because we may be in server init
333-
{
334-
if (RuleHelper.getBooleanValue(rule) || (rule.type() == String.class && !rule.value().equals("false")))
335-
{
336-
CarpetServer.scriptServer.addScriptHost(source, rule.scarpetApp, s -> CommandHelper.canUseCommand(s, rule.value()), false, false, true, null);
337-
} else {
338-
CarpetServer.scriptServer.removeScriptHost(source, rule.scarpetApp, false, true);
339-
}
340-
}
341-
}
342313

343314
private Path getFile()
344315
{

0 commit comments

Comments
 (0)