enabled some client side command interpretation.
This commit is contained in:
1 parent
f3093183ce
commit
fe63334509
8 files changed
+71
-4
No files matched your search
@@ -119,6 +119,7 @@ public class CarpetServer // static for now - easier to handle all around the co
|
|||||||
settingsManager.detachServer();
|
settingsManager.detachServer();
|
||||||
LoggerRegistry.stopLoggers();
|
LoggerRegistry.stopLoggers();
|
||||||
extensions.forEach(e -> e.onServerClosed(server));
|
extensions.forEach(e -> e.onServerClosed(server));
|
||||||
|
minecraft_server = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void registerExtensionLoggers()
|
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.TNT;
|
||||||
import static carpet.settings.RuleCategory.DISPENSER;
|
import static carpet.settings.RuleCategory.DISPENSER;
|
||||||
import static carpet.settings.RuleCategory.SCARPET;
|
import static carpet.settings.RuleCategory.SCARPET;
|
||||||
|
import static carpet.settings.RuleCategory.CLIENT;
|
||||||
|
|
||||||
@SuppressWarnings("CanBeFinal")
|
@SuppressWarnings("CanBeFinal")
|
||||||
public class CarpetSettings
|
public class CarpetSettings
|
||||||
@@ -364,7 +365,11 @@ public class CarpetSettings
|
|||||||
@Rule(desc = "placing blocks cause block updates", category = CREATIVE)
|
@Rule(desc = "placing blocks cause block updates", category = CREATIVE)
|
||||||
public static boolean interactionUpdates = true;
|
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;
|
public static boolean smoothClientAnimations;
|
||||||
|
|
||||||
//@Rule(
|
//@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> categories;
|
||||||
public final ImmutableList<String> options;
|
public final ImmutableList<String> options;
|
||||||
public boolean isStrict;
|
public boolean isStrict;
|
||||||
|
public boolean isClient;
|
||||||
public final Class<T> type;
|
public final Class<T> type;
|
||||||
public final List<Validator<T>> validators;
|
public final List<Validator<T>> validators;
|
||||||
public final T defaultValue;
|
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.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.defaultValue = get();
|
||||||
this.defaultAsString = convertToString(this.defaultValue);
|
this.defaultAsString = convertToString(this.defaultValue);
|
||||||
if (rule.options().length > 0)
|
if (rule.options().length > 0)
|
||||||
@@ -131,17 +137,20 @@ public final class ParsedRule<T> implements Comparable<ParsedRule> {
|
|||||||
{
|
{
|
||||||
value = validator.validate(source, this, value, stringValue);
|
value = validator.validate(source, this, value, stringValue);
|
||||||
if (value == null)
|
if (value == null)
|
||||||
|
{
|
||||||
|
if (source != null)
|
||||||
{
|
{
|
||||||
Messenger.m(source, "r Wrong value for " + name + ": " + stringValue);
|
Messenger.m(source, "r Wrong value for " + name + ": " + stringValue);
|
||||||
if (validator.description() != null)
|
if (validator.description() != null)
|
||||||
Messenger.m(source, "r " + validator.description());
|
Messenger.m(source, "r " + validator.description());
|
||||||
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!value.equals(get()))
|
if (!value.equals(get()) || source == null)
|
||||||
{
|
{
|
||||||
this.field.set(null, value);
|
this.field.set(null, value);
|
||||||
CarpetServer.settingsManager.notifyRuleChanged(source, this, stringValue);
|
if (source != null) CarpetServer.settingsManager.notifyRuleChanged(source, this, stringValue);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (IllegalAccessException e)
|
catch (IllegalAccessException e)
|
||||||
|
|||||||
@@ -12,5 +12,6 @@ public class RuleCategory
|
|||||||
public static final String TNT = "tnt";
|
public static final String TNT = "tnt";
|
||||||
public static final String DISPENSER = "dispenser";
|
public static final String DISPENSER = "dispenser";
|
||||||
public static final String SCARPET = "scarpet";
|
public static final String SCARPET = "scarpet";
|
||||||
|
public static final String CLIENT = "client";
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -558,4 +558,22 @@ public class SettingsManager
|
|||||||
return 1;
|
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 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> {
|
public static class _COMMAND_LEVEL_VALIDATOR extends Validator<String> {
|
||||||
private static ImmutableList<String> OPTIONS = ImmutableList.of("true", "false", "ops", "0", "1", "2", "3", "4");
|
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) {
|
@Override public String validate(ServerCommandSource source, ParsedRule<String> currentRule, String newValue, String userString) {
|
||||||
|
|||||||
@@ -163,7 +163,8 @@
|
|||||||
"InGameHudMixin",
|
"InGameHudMixin",
|
||||||
"PlayerListHudMixin",
|
"PlayerListHudMixin",
|
||||||
"PistonBlockEntityRenderer_movableTEMixin",
|
"PistonBlockEntityRenderer_movableTEMixin",
|
||||||
"ClientPlayNetworkHandler_smoothClientAnimationsMixin"
|
"ClientPlayNetworkHandler_smoothClientAnimationsMixin",
|
||||||
|
"ClientPlayerEntity_clientCommandMixin"
|
||||||
],
|
],
|
||||||
"server": [
|
"server": [
|
||||||
"MinecraftDedicatedServerMixin"
|
"MinecraftDedicatedServerMixin"
|
||||||
|
|||||||
Reference in new issue
Block a user