enabled some client side command interpretation.
This commit is contained in:
1 parent
f3093183ce
commit
fe63334509
8 files changed
+74
-7
No files matched your search
@@ -119,6 +119,7 @@ public class CarpetServer // static for now - easier to handle all around the co
|
||||
settingsManager.detachServer();
|
||||
LoggerRegistry.stopLoggers();
|
||||
extensions.forEach(e -> e.onServerClosed(server));
|
||||
minecraft_server = null;
|
||||
}
|
||||
|
||||
public static void registerExtensionLoggers()
|
||||
|
||||
@@ -30,6 +30,7 @@ import static carpet.settings.RuleCategory.SURVIVAL;
|
||||
import static carpet.settings.RuleCategory.TNT;
|
||||
import static carpet.settings.RuleCategory.DISPENSER;
|
||||
import static carpet.settings.RuleCategory.SCARPET;
|
||||
import static carpet.settings.RuleCategory.CLIENT;
|
||||
|
||||
@SuppressWarnings("CanBeFinal")
|
||||
public class CarpetSettings
|
||||
@@ -364,7 +365,11 @@ public class CarpetSettings
|
||||
@Rule(desc = "placing blocks cause block updates", category = CREATIVE)
|
||||
public static boolean interactionUpdates = true;
|
||||
|
||||
@Rule(desc = "smooth client animations with low tps settings", extra = "works only in SP, and will slow down players", category = CREATIVE)
|
||||
@Rule(
|
||||
desc = "smooth client animations with low tps settings",
|
||||
extra = "works only in SP, and will slow down players",
|
||||
category = {CREATIVE, SURVIVAL, CLIENT}
|
||||
)
|
||||
public static boolean smoothClientAnimations;
|
||||
|
||||
//@Rule(
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
package carpet.mixins;
|
||||
|
||||
import carpet.CarpetServer;
|
||||
import net.minecraft.client.network.ClientPlayerEntity;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
@Mixin(ClientPlayerEntity.class)
|
||||
public class ClientPlayerEntity_clientCommandMixin
|
||||
{
|
||||
@Inject(method = "sendChatMessage", at = @At("HEAD"))
|
||||
private void inspectMessage(String string, CallbackInfo ci)
|
||||
{
|
||||
if (CarpetServer.minecraft_server == null)
|
||||
CarpetServer.settingsManager.inspectClientsideCommand(string);
|
||||
}
|
||||
}
|
||||
@@ -20,6 +20,7 @@ public final class ParsedRule<T> implements Comparable<ParsedRule> {
|
||||
public final ImmutableList<String> categories;
|
||||
public final ImmutableList<String> options;
|
||||
public boolean isStrict;
|
||||
public boolean isClient;
|
||||
public final Class<T> type;
|
||||
public final List<Validator<T>> validators;
|
||||
public final T defaultValue;
|
||||
@@ -46,6 +47,11 @@ public final class ParsedRule<T> implements Comparable<ParsedRule> {
|
||||
this.validators.add((Validator<T>) callConstructor(Validator._COMMAND_LEVEL_VALIDATOR.class));
|
||||
}
|
||||
}
|
||||
this.isClient = categories.contains(RuleCategory.CLIENT);
|
||||
if (this.isClient)
|
||||
{
|
||||
this.validators.add(callConstructor(Validator._CLIENT.class));
|
||||
}
|
||||
this.defaultValue = get();
|
||||
this.defaultAsString = convertToString(this.defaultValue);
|
||||
if (rule.options().length > 0)
|
||||
@@ -132,16 +138,19 @@ public final class ParsedRule<T> implements Comparable<ParsedRule> {
|
||||
value = validator.validate(source, this, value, stringValue);
|
||||
if (value == null)
|
||||
{
|
||||
Messenger.m(source, "r Wrong value for " + name + ": " + stringValue);
|
||||
if (validator.description()!= null)
|
||||
Messenger.m(source, "r " + validator.description());
|
||||
if (source != null)
|
||||
{
|
||||
Messenger.m(source, "r Wrong value for " + name + ": " + stringValue);
|
||||
if (validator.description() != null)
|
||||
Messenger.m(source, "r " + validator.description());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
if (!value.equals(get()))
|
||||
if (!value.equals(get()) || source == null)
|
||||
{
|
||||
this.field.set(null, value);
|
||||
CarpetServer.settingsManager.notifyRuleChanged(source, this, stringValue);
|
||||
if (source != null) CarpetServer.settingsManager.notifyRuleChanged(source, this, stringValue);
|
||||
}
|
||||
}
|
||||
catch (IllegalAccessException e)
|
||||
|
||||
@@ -12,5 +12,6 @@ public class RuleCategory
|
||||
public static final String TNT = "tnt";
|
||||
public static final String DISPENSER = "dispenser";
|
||||
public static final String SCARPET = "scarpet";
|
||||
public static final String CLIENT = "client";
|
||||
|
||||
}
|
||||
@@ -558,4 +558,22 @@ public class SettingsManager
|
||||
return 1;
|
||||
}
|
||||
|
||||
public void inspectClientsideCommand(String string)
|
||||
{
|
||||
if (string.startsWith("/carpet "))
|
||||
{
|
||||
String[] res = string.split("\\s+", 3);
|
||||
if (res.length == 3)
|
||||
{
|
||||
String setting = res[1];
|
||||
String strOption = res[2];
|
||||
if (rules.containsKey(setting) && rules.get(setting).isClient)
|
||||
{
|
||||
rules.get(setting).set(null, strOption);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -41,6 +41,19 @@ public abstract class Validator<T>
|
||||
public String description() { return "It has an accompanying command";}
|
||||
}
|
||||
|
||||
public static class _CLIENT<T> extends Validator<T>
|
||||
{
|
||||
@Override
|
||||
public T validate(ServerCommandSource source, ParsedRule<T> currentRule, T newValue, String string)
|
||||
{
|
||||
return newValue;
|
||||
}
|
||||
@Override
|
||||
public String description() { return "Its a client command so can be issued when connecting to non-carpet servers. " +
|
||||
"In client-server setting it will only affect the executing player, so each player needs to type it" +
|
||||
" separately for the desired effect";}
|
||||
}
|
||||
|
||||
public static class _COMMAND_LEVEL_VALIDATOR extends Validator<String> {
|
||||
private static ImmutableList<String> OPTIONS = ImmutableList.of("true", "false", "ops", "0", "1", "2", "3", "4");
|
||||
@Override public String validate(ServerCommandSource source, ParsedRule<String> currentRule, String newValue, String userString) {
|
||||
|
||||
@@ -163,7 +163,8 @@
|
||||
"InGameHudMixin",
|
||||
"PlayerListHudMixin",
|
||||
"PistonBlockEntityRenderer_movableTEMixin",
|
||||
"ClientPlayNetworkHandler_smoothClientAnimationsMixin"
|
||||
"ClientPlayNetworkHandler_smoothClientAnimationsMixin",
|
||||
"ClientPlayerEntity_clientCommandMixin"
|
||||
],
|
||||
"server": [
|
||||
"MinecraftDedicatedServerMixin"
|
||||
|
||||
Reference in new issue
Block a user