Merge branch 'basic_systems'
# Conflicts: # src/main/java/carpet/commands/SpawnCommand.java # src/main/java/carpet/helpers/CtrlQCrafting.javax # src/main/java/carpet/utils/HUDController.java # src/main/java/carpet/utils/SpawnReporter.java # src/main/resources/carpet.mixins.json
This commit is contained in:
commit
5109263fd8
48 files changed
+6071
-54
No files matched your search
@@ -0,0 +1,202 @@
|
||||
package carpet.commands;
|
||||
|
||||
import carpet.CarpetSettings;
|
||||
import carpet.CarpetSettings.CarpetSettingEntry;
|
||||
import carpet.utils.Messenger;
|
||||
import com.mojang.brigadier.CommandDispatcher;
|
||||
import com.mojang.brigadier.arguments.StringArgumentType;
|
||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||
import net.minecraft.server.command.ServerCommandSource;
|
||||
import net.minecraft.server.command.CommandManager;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.network.chat.BaseComponent;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import static net.minecraft.server.command.CommandManager.argument;
|
||||
import static net.minecraft.server.command.CommandManager.literal;
|
||||
import static net.minecraft.server.command.CommandSource.suggestMatching;
|
||||
|
||||
public class CarpetCommand
|
||||
{
|
||||
public static void register(CommandDispatcher<ServerCommandSource> dispatcher)
|
||||
{
|
||||
LiteralArgumentBuilder<ServerCommandSource> literalargumentbuilder = literal("carpet").requires((player) ->
|
||||
player.hasPermissionLevel(2) && !CarpetSettings.locked);
|
||||
|
||||
literalargumentbuilder.executes((context)->listAllSettings(context.getSource())).
|
||||
then(literal("list").
|
||||
executes( (c) -> listSettings(c.getSource(),
|
||||
"All CarpetMod Settings",
|
||||
CarpetSettings.findAll(null))).
|
||||
then(literal("defaults").
|
||||
executes( (c)-> listSettings(c.getSource(),
|
||||
"Current CarpetMod Startup Settings from carpet.conf",
|
||||
CarpetSettings.findStartupOverrides(c.getSource().getMinecraftServer())))).
|
||||
then(argument("tag",StringArgumentType.word()).
|
||||
suggests( (c, b)->suggestMatching(CarpetSettings.default_tags, b)).
|
||||
executes( (c) -> listSettings(c.getSource(),
|
||||
String.format("CarpetMod Settings matching \"%s\"", StringArgumentType.getString(c, "tag")),
|
||||
CarpetSettings.findAll(StringArgumentType.getString(c, "tag"))))));
|
||||
|
||||
for (CarpetSettingEntry rule: CarpetSettings.getAllCarpetSettings())
|
||||
{
|
||||
literalargumentbuilder.then(literal(rule.getName()).executes( (context) ->
|
||||
displayRuleMenu(context.getSource(),rule)));
|
||||
literalargumentbuilder.then(literal("removeDefault").
|
||||
then(literal(rule.getName()).executes((context) ->
|
||||
removeDefault(context.getSource(), rule))));
|
||||
literalargumentbuilder.then(literal(rule.getName()).
|
||||
then(argument("value", StringArgumentType.word()).
|
||||
suggests((c, b)-> suggestMatching(rule.getOptions(),b)).
|
||||
executes((context) ->
|
||||
setRule(context.getSource(), rule, StringArgumentType.getString(context, "value")))));
|
||||
literalargumentbuilder.then(literal("setDefault").
|
||||
then(literal(rule.getName()).
|
||||
then(argument("value", StringArgumentType.word()).
|
||||
suggests((c, b)-> suggestMatching(rule.getOptions(),b)).
|
||||
executes((context) ->
|
||||
setDefault(context.getSource(), rule, StringArgumentType.getString(context, "value"))))));
|
||||
}
|
||||
dispatcher.register(literalargumentbuilder);
|
||||
}
|
||||
|
||||
private static int displayRuleMenu(ServerCommandSource source, CarpetSettingEntry rule)
|
||||
{
|
||||
PlayerEntity player;
|
||||
try
|
||||
{
|
||||
player = source.getPlayer();
|
||||
}
|
||||
catch (CommandSyntaxException e)
|
||||
{
|
||||
Messenger.m(source, "w "+rule.getName() +" is set to: ","wb "+rule.getStringValue());
|
||||
return 1;
|
||||
}
|
||||
|
||||
Messenger.m(player, "");
|
||||
Messenger.m(player, "wb "+rule.getName(),"!/carpet "+rule.getName(),"^g refresh");
|
||||
Messenger.m(player, "w "+rule.getToast());
|
||||
|
||||
Arrays.stream(rule.getInfo()).forEach(s -> Messenger.m(player, "g "+s));
|
||||
|
||||
List<BaseComponent> tags = new ArrayList<>();
|
||||
tags.add(Messenger.c("w Tags: "));
|
||||
for (String t: rule.getTags())
|
||||
{
|
||||
tags.add(Messenger.c("c ["+t+"]", "^g list all "+t+" settings","!/carpet list "+t));
|
||||
tags.add(Messenger.c("w , "));
|
||||
}
|
||||
tags.remove(tags.size()-1);
|
||||
Messenger.m(player, tags.toArray(new Object[0]));
|
||||
|
||||
Messenger.m(player, "w Current value: ",String.format("%s %s (%s value)",rule.getBoolValue()?"lb":"nb", rule.getStringValue(),rule.isDefault()?"default":"modified"));
|
||||
List<BaseComponent> options = new ArrayList<>();
|
||||
options.add(Messenger.c("w Options: ", "y [ "));
|
||||
for (String o: rule.getOptions())
|
||||
{
|
||||
options.add(Messenger.c(
|
||||
String.format("%s%s %s",(o.equals(rule.getDefault()))?"u":"", (o.equals(rule.getStringValue()))?"bl":"y", o ),
|
||||
"^g switch to "+o,
|
||||
String.format("?/carpet %s %s",rule.getName(),o)));
|
||||
options.add(Messenger.c("w "));
|
||||
}
|
||||
options.remove(options.size()-1);
|
||||
options.add(Messenger.c("y ]"));
|
||||
Messenger.m(player, options.toArray(new Object[0]));
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
private static int setRule(ServerCommandSource source, CarpetSettingEntry rule, String newValue)
|
||||
{
|
||||
CarpetSettings.set(rule.getName(), newValue);
|
||||
Messenger.m(source, "w "+rule.toString()+", ", "c [change permanently?]",
|
||||
"^w Click to keep the settings in carpet.conf to save across restarts",
|
||||
"?/carpet setDefault "+rule.getName()+" "+rule.getStringValue());
|
||||
return 1;
|
||||
}
|
||||
private static int setDefault(ServerCommandSource source, CarpetSettingEntry rule, String defaultValue)
|
||||
{
|
||||
CarpetSettings.setDefaultRule(source.getMinecraftServer(), rule.getName(), defaultValue);
|
||||
Messenger.m(source ,"gi rule "+ rule.getName()+" will now default to "+ defaultValue);
|
||||
return 1;
|
||||
}
|
||||
private static int removeDefault(ServerCommandSource source, CarpetSettingEntry rule)
|
||||
{
|
||||
CarpetSettings.removeDefaultRule(source.getMinecraftServer(), rule.getName());
|
||||
Messenger.m(source ,"gi rule "+ rule.getName()+" defaults to Vanilla");
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
private static BaseComponent displayInteractiveSetting(CarpetSettingEntry e)
|
||||
{
|
||||
List<Object> args = new ArrayList<>();
|
||||
args.add("w - "+e.getName()+" ");
|
||||
args.add("!/carpet "+e.getName());
|
||||
args.add("^y "+e.getToast());
|
||||
for (String option: e.getOptions())
|
||||
{
|
||||
String style = e.isDefault()?"g":(option.equalsIgnoreCase(e.getDefault())?"y":"e");
|
||||
if (option.equalsIgnoreCase(e.getDefault()))
|
||||
style = style+"b";
|
||||
else if (option.equalsIgnoreCase(e.getStringValue()))
|
||||
style = style+"u";
|
||||
args.add(style+" ["+option+"]");
|
||||
if (!option.equalsIgnoreCase(e.getStringValue()))
|
||||
{
|
||||
args.add("!/carpet " + e.getName() + " " + option);
|
||||
args.add("^w switch to " + option);
|
||||
}
|
||||
args.add("w ");
|
||||
}
|
||||
args.remove(args.size()-1);
|
||||
return Messenger.c(args.toArray(new Object[0]));
|
||||
}
|
||||
|
||||
private static int listSettings(ServerCommandSource source, String title, CarpetSettingEntry[] settings_list)
|
||||
{
|
||||
try
|
||||
{
|
||||
PlayerEntity player = source.getPlayer();
|
||||
Messenger.m(player,String.format("wb %s:",title));
|
||||
Arrays.stream(settings_list).forEach(e -> Messenger.m(player,displayInteractiveSetting(e)));
|
||||
|
||||
}
|
||||
catch (CommandSyntaxException e)
|
||||
{
|
||||
Messenger.m(source, "w s:"+title);
|
||||
Arrays.stream(settings_list).forEach(r -> Messenger.m(source, "w - "+ r.toString()));
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
private static int listAllSettings(ServerCommandSource source)
|
||||
{
|
||||
listSettings(source, "Current CarpetMod Settings", CarpetSettings.find_nondefault(source.getMinecraftServer()));
|
||||
|
||||
Messenger.m(source, "Carpet Mod version: "+CarpetSettings.carpetVersion);
|
||||
try
|
||||
{
|
||||
PlayerEntity player = source.getPlayer();
|
||||
List<Object> tags = new ArrayList<>();
|
||||
tags.add("w Browse Categories:\n");
|
||||
for (String t : CarpetSettings.default_tags)
|
||||
{
|
||||
tags.add("c [" + t+"]");
|
||||
tags.add("^g list all " + t + " settings");
|
||||
tags.add("!/carpet list " + t);
|
||||
tags.add("w ");
|
||||
}
|
||||
tags.remove(tags.size() - 1);
|
||||
Messenger.m(player, tags.toArray(new Object[0]));
|
||||
}
|
||||
catch (CommandSyntaxException e)
|
||||
{
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
package carpet.commands;
|
||||
|
||||
import carpet.CarpetSettings;
|
||||
import carpet.helpers.HopperCounter;
|
||||
import carpet.utils.Messenger;
|
||||
import com.mojang.brigadier.CommandDispatcher;
|
||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||
import net.minecraft.command.CommandException;
|
||||
import net.minecraft.server.command.ServerCommandSource;
|
||||
import net.minecraft.server.command.CommandManager;
|
||||
import net.minecraft.util.DyeColor;
|
||||
import net.minecraft.network.chat.BaseComponent;
|
||||
|
||||
public class CounterCommand
|
||||
{
|
||||
public static void register(CommandDispatcher<ServerCommandSource> dispatcher)
|
||||
{
|
||||
LiteralArgumentBuilder<ServerCommandSource> literalargumentbuilder = CommandManager.literal("counter").executes((context)
|
||||
-> listAllCounters(context.getSource(), false)).requires((player) ->
|
||||
CarpetSettings.getBool("hopperCounters"));
|
||||
|
||||
literalargumentbuilder.
|
||||
then((CommandManager.literal("reset").executes( (p_198489_1_)->
|
||||
resetCounter(p_198489_1_.getSource(), null))));
|
||||
for (DyeColor enumDyeColor: DyeColor.values())
|
||||
{
|
||||
String color = enumDyeColor.toString();
|
||||
literalargumentbuilder.
|
||||
then((CommandManager.literal(color).executes( (p_198489_1_)-> displayCounter(p_198489_1_.getSource(), color, false))));
|
||||
literalargumentbuilder.then(CommandManager.literal(color).
|
||||
then(CommandManager.literal("reset").executes((context) ->
|
||||
resetCounter(context.getSource(), color))));
|
||||
literalargumentbuilder.then(CommandManager.literal(color).
|
||||
then(CommandManager.literal("realtime").executes((context) ->
|
||||
displayCounter(context.getSource(), color, true))));
|
||||
}
|
||||
dispatcher.register(literalargumentbuilder);
|
||||
}
|
||||
|
||||
private static int displayCounter(ServerCommandSource source, String color, boolean realtime)
|
||||
{
|
||||
HopperCounter counter = HopperCounter.getCounter(color);
|
||||
if (counter == null) throw new CommandException(Messenger.s("Unknown wool color: "+color));
|
||||
|
||||
for (BaseComponent message: counter.format(source.getMinecraftServer(), realtime, false))
|
||||
{
|
||||
source.sendFeedback(message, false);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
private static int resetCounter(ServerCommandSource source, String color)
|
||||
{
|
||||
if (color == null)
|
||||
{
|
||||
HopperCounter.resetAll(source.getMinecraftServer());
|
||||
Messenger.m(source, "w Restarted all counters");
|
||||
}
|
||||
else
|
||||
{
|
||||
HopperCounter counter = HopperCounter.getCounter(color);
|
||||
if (counter == null) throw new CommandException(Messenger.s("Unknown wool color"));
|
||||
counter.reset(source.getMinecraftServer());
|
||||
Messenger.m(source, "w Restarted "+color+" counter");
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
private static int listAllCounters(ServerCommandSource source, boolean realtime)
|
||||
{
|
||||
for (BaseComponent message: HopperCounter.formatAll(source.getMinecraftServer(), realtime))
|
||||
{
|
||||
source.sendFeedback(message, false);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,214 @@
|
||||
package carpet.commands;
|
||||
|
||||
import carpet.CarpetSettings;
|
||||
import carpet.logging.Logger;
|
||||
import carpet.logging.LoggerRegistry;
|
||||
import carpet.utils.Messenger;
|
||||
import com.mojang.brigadier.CommandDispatcher;
|
||||
import com.mojang.brigadier.arguments.StringArgumentType;
|
||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||
import net.minecraft.server.command.ServerCommandSource;
|
||||
import net.minecraft.server.command.CommandManager;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static com.mojang.brigadier.arguments.StringArgumentType.getString;
|
||||
import static net.minecraft.server.command.CommandSource.suggestMatching;
|
||||
|
||||
public class LogCommand
|
||||
{
|
||||
public static void register(CommandDispatcher<ServerCommandSource> dispatcher)
|
||||
{
|
||||
LiteralArgumentBuilder<ServerCommandSource> literalargumentbuilder = CommandManager.literal("log").
|
||||
requires((player) -> CarpetSettings.getBool("commandLog")).
|
||||
executes((context) -> listLogs(context.getSource())).
|
||||
then(CommandManager.literal("clear").
|
||||
executes( (c) -> unsubFromAll(c.getSource(), c.getSource().getName())).
|
||||
then(CommandManager.argument("player", StringArgumentType.word()).
|
||||
suggests( (c, b)-> suggestMatching(c.getSource().getPlayerNames(),b)).
|
||||
executes( (c) -> unsubFromAll(c.getSource(), getString(c, "player")))));
|
||||
|
||||
literalargumentbuilder.then(CommandManager.argument("log name",StringArgumentType.word()).
|
||||
suggests( (c, b)-> suggestMatching(LoggerRegistry.getLoggerNames(),b)).
|
||||
executes( (c)-> toggleSubscription(c.getSource(), c.getSource().getName(), getString(c, "log name"))).
|
||||
then(CommandManager.literal("clear").
|
||||
executes( (c) -> unsubFromLogger(
|
||||
c.getSource(),
|
||||
c.getSource().getName(),
|
||||
getString(c, "log name")))).
|
||||
then(CommandManager.argument("option", StringArgumentType.word()).
|
||||
suggests( (c, b) -> suggestMatching(
|
||||
(LoggerRegistry.getLogger(getString(c, "log name"))==null
|
||||
?new String[]{}
|
||||
:LoggerRegistry.getLogger(getString(c, "log name")).getOptions()),
|
||||
b)).
|
||||
executes( (c) -> subscribePlayer(
|
||||
c.getSource(),
|
||||
c.getSource().getName(),
|
||||
getString(c, "log name"),
|
||||
getString(c, "option"))).
|
||||
then(CommandManager.argument("player", StringArgumentType.word()).
|
||||
suggests( (c, b) -> suggestMatching(c.getSource().getPlayerNames(),b)).
|
||||
executes( (c) -> subscribePlayer(
|
||||
c.getSource(),
|
||||
getString(c, "player"),
|
||||
getString(c, "log name"),
|
||||
getString(c, "option"))))));
|
||||
|
||||
dispatcher.register(literalargumentbuilder);
|
||||
}
|
||||
private static int listLogs(ServerCommandSource source)
|
||||
{
|
||||
PlayerEntity player;
|
||||
try
|
||||
{
|
||||
player = source.getPlayer();
|
||||
}
|
||||
catch (CommandSyntaxException e)
|
||||
{
|
||||
Messenger.m(source, "For players only");
|
||||
return 0;
|
||||
}
|
||||
Map<String,String> subs = LoggerRegistry.getPlayerSubscriptions(source.getName());
|
||||
if (subs == null)
|
||||
{
|
||||
subs = new HashMap<>();
|
||||
}
|
||||
List<String> all_logs = new ArrayList<>(LoggerRegistry.getLoggerNames());
|
||||
Collections.sort(all_logs);
|
||||
Messenger.m(player, "w _____________________");
|
||||
Messenger.m(player, "w Available logging options:");
|
||||
for (String lname: all_logs)
|
||||
{
|
||||
List<Object> comp = new ArrayList<>();
|
||||
String color = subs.containsKey(lname)?"w":"g";
|
||||
comp.add("w - "+lname+": ");
|
||||
Logger logger = LoggerRegistry.getLogger(lname);
|
||||
String [] options = logger.getOptions();
|
||||
if (options.length == 0)
|
||||
{
|
||||
if (subs.containsKey(lname))
|
||||
{
|
||||
comp.add("l Subscribed ");
|
||||
}
|
||||
else
|
||||
{
|
||||
comp.add(color + " [Subscribe] ");
|
||||
comp.add("^w subscribe to " + lname);
|
||||
comp.add("!/log " + lname);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (String option : logger.getOptions())
|
||||
{
|
||||
if (subs.containsKey(lname) && subs.get(lname).equalsIgnoreCase(option))
|
||||
{
|
||||
comp.add("l [" + option + "] ");
|
||||
} else
|
||||
{
|
||||
comp.add(color + " [" + option + "] ");
|
||||
comp.add("^w subscribe to " + lname + " " + option);
|
||||
comp.add("!/log " + lname + " " + option);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
if (subs.containsKey(lname))
|
||||
{
|
||||
comp.add("nb [X]");
|
||||
comp.add("^w Click to unsubscribe");
|
||||
comp.add("!/log "+lname);
|
||||
}
|
||||
Messenger.m(player,comp.toArray(new Object[0]));
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
private static int unsubFromAll(ServerCommandSource source, String player_name)
|
||||
{
|
||||
PlayerEntity player = source.getMinecraftServer().getPlayerManager().getPlayer(player_name);
|
||||
if (player == null)
|
||||
{
|
||||
Messenger.m(source, "r No player specified");
|
||||
return 0;
|
||||
}
|
||||
for (String logname : LoggerRegistry.getLoggerNames())
|
||||
{
|
||||
LoggerRegistry.unsubscribePlayer(player_name, logname);
|
||||
}
|
||||
Messenger.m(source, "gi Unsubscribed from all logs");
|
||||
return 1;
|
||||
}
|
||||
private static int unsubFromLogger(ServerCommandSource source, String player_name, String logname)
|
||||
{
|
||||
PlayerEntity player = source.getMinecraftServer().getPlayerManager().getPlayer(player_name);
|
||||
if (player == null)
|
||||
{
|
||||
Messenger.m(source, "r No player specified");
|
||||
return 0;
|
||||
}
|
||||
if (LoggerRegistry.getLogger(logname) == null)
|
||||
{
|
||||
Messenger.m(source, "r Unknown logger: ","rb "+logname);
|
||||
return 0;
|
||||
}
|
||||
LoggerRegistry.unsubscribePlayer(player_name, logname);
|
||||
Messenger.m(source, "gi Unsubscribed from "+logname);
|
||||
return 1;
|
||||
}
|
||||
|
||||
private static int toggleSubscription(ServerCommandSource source, String player_name, String logName)
|
||||
{
|
||||
PlayerEntity player = source.getMinecraftServer().getPlayerManager().getPlayer(player_name);
|
||||
if (player == null)
|
||||
{
|
||||
Messenger.m(source, "r No player specified");
|
||||
return 0;
|
||||
}
|
||||
if (LoggerRegistry.getLogger(logName) == null)
|
||||
{
|
||||
Messenger.m(source, "r Unknown logger: ","rb "+logName);
|
||||
return 0;
|
||||
}
|
||||
boolean subscribed = LoggerRegistry.togglePlayerSubscription(player_name, logName);
|
||||
if (subscribed)
|
||||
{
|
||||
Messenger.m(source, "gi "+player_name+" subscribed to " + logName + ".");
|
||||
}
|
||||
else
|
||||
{
|
||||
Messenger.m(source, "gi "+player_name+" unsubscribed from " + logName + ".");
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
private static int subscribePlayer(ServerCommandSource source, String player_name, String logname, String option)
|
||||
{
|
||||
PlayerEntity player = source.getMinecraftServer().getPlayerManager().getPlayer(player_name);
|
||||
if (player == null)
|
||||
{
|
||||
Messenger.m(source, "r No player specified");
|
||||
return 0;
|
||||
}
|
||||
if (LoggerRegistry.getLogger(logname) == null)
|
||||
{
|
||||
Messenger.m(source, "r Unknown logger: ","rb "+logname);
|
||||
return 0;
|
||||
}
|
||||
LoggerRegistry.subscribePlayer(player_name, logname, option);
|
||||
if (option!=null)
|
||||
{
|
||||
Messenger.m(source, "gi Subscribed to " + logname + "(" + option + ")");
|
||||
}
|
||||
else
|
||||
{
|
||||
Messenger.m(source, "gi Subscribed to " + logname);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
package carpet.commands;
|
||||
|
||||
import carpet.CarpetSettings;
|
||||
import carpet.utils.Messenger;
|
||||
import carpet.utils.PerimeterDiagnostics;
|
||||
import com.mojang.brigadier.CommandDispatcher;
|
||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||
import net.minecraft.command.suggestion.SuggestionProviders;
|
||||
import net.minecraft.entity.EntityType;
|
||||
import net.minecraft.entity.mob.MobEntity;
|
||||
import net.minecraft.server.command.ServerCommandSource;
|
||||
import net.minecraft.command.arguments.BlockPosArgumentType;
|
||||
import net.minecraft.command.arguments.EntitySummonArgumentType;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
|
||||
import static net.minecraft.server.command.CommandManager.argument;
|
||||
import static net.minecraft.server.command.CommandManager.literal;
|
||||
|
||||
public class PerimeterInfoCommand
|
||||
{
|
||||
public static void register(CommandDispatcher<ServerCommandSource> dispatcher)
|
||||
{
|
||||
LiteralArgumentBuilder<ServerCommandSource> command = literal("perimeterinfo").
|
||||
requires((player) -> CarpetSettings.getBool("commandPerimeterInfo")).
|
||||
executes( (c) -> perimeterDiagnose(
|
||||
c.getSource(),
|
||||
new BlockPos(c.getSource().getPosition()),
|
||||
null)).
|
||||
then(argument("center position", BlockPosArgumentType.create()).
|
||||
executes( (c) -> perimeterDiagnose(
|
||||
c.getSource(),
|
||||
BlockPosArgumentType.getBlockPos(c, "center position"),
|
||||
null)).
|
||||
then(argument("mob",EntitySummonArgumentType.create()).
|
||||
suggests(SuggestionProviders.SUMMONABLE_ENTITIES).
|
||||
executes( (c) -> perimeterDiagnose(
|
||||
c.getSource(),
|
||||
BlockPosArgumentType.getBlockPos(c, "center position"),
|
||||
EntitySummonArgumentType.getEntitySummon(c, "mob").toString()
|
||||
))));
|
||||
dispatcher.register(command);
|
||||
}
|
||||
|
||||
private static int perimeterDiagnose(ServerCommandSource source, BlockPos pos, String mobId)
|
||||
{
|
||||
CompoundTag nbttagcompound = new CompoundTag();
|
||||
MobEntity entityliving = null;
|
||||
if (mobId != null)
|
||||
{
|
||||
nbttagcompound.putString("id", mobId);
|
||||
entityliving = (MobEntity) EntityType.loadEntityWithPassengers(nbttagcompound, source.getWorld(), (entity_1x) -> {
|
||||
entity_1x.setPositionAndAngles(pos.getX(), pos.getY(), pos.getZ(), entity_1x.yaw, entity_1x.pitch);
|
||||
return !source.getWorld().method_18768(entity_1x) ? null : entity_1x;
|
||||
});
|
||||
if (entityliving == null)
|
||||
{
|
||||
Messenger.m(source, "r Failed to spawn test entity");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
PerimeterDiagnostics.Result res = PerimeterDiagnostics.countSpots(source.getWorld(), pos, entityliving);
|
||||
|
||||
Messenger.m(source, "w Spawning spaces around ",Messenger.tp("c",pos), "w :");
|
||||
Messenger.m(source, "w potential in-liquid: ","wb "+res.liquid);
|
||||
Messenger.m(source, "w potential on-ground: ","wb "+res.ground);
|
||||
if (entityliving != null)
|
||||
{
|
||||
Messenger.m(source, "w ", entityliving.getDisplayName() ,"w : ","wb "+res.specific);
|
||||
res.samples.forEach(bp -> Messenger.m(source, "w ", Messenger.tp("c", bp)));
|
||||
entityliving.remove();
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,477 @@
|
||||
package carpet.commands;
|
||||
|
||||
import carpet.CarpetSettings;
|
||||
import carpet.fakes.ServerPlayerEntityInterface;
|
||||
import carpet.patches.EntityPlayerMPFake;
|
||||
import carpet.utils.Messenger;
|
||||
import com.google.common.collect.Sets;
|
||||
import com.mojang.brigadier.CommandDispatcher;
|
||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||
import com.mojang.brigadier.context.CommandContext;
|
||||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||
import net.minecraft.command.arguments.DimensionArgumentType;
|
||||
import net.minecraft.command.arguments.RotationArgumentType;
|
||||
import net.minecraft.command.arguments.Vec3ArgumentType;
|
||||
import net.minecraft.server.command.ServerCommandSource;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.util.math.Vec2f;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.world.GameMode;
|
||||
import net.minecraft.world.dimension.DimensionType;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Set;
|
||||
|
||||
import static com.mojang.brigadier.arguments.IntegerArgumentType.getInteger;
|
||||
import static com.mojang.brigadier.arguments.IntegerArgumentType.integer;
|
||||
import static com.mojang.brigadier.arguments.StringArgumentType.getString;
|
||||
import static com.mojang.brigadier.arguments.StringArgumentType.word;
|
||||
import static net.minecraft.server.command.CommandManager.argument;
|
||||
import static net.minecraft.server.command.CommandManager.literal;
|
||||
import static net.minecraft.server.command.CommandSource.suggestMatching;
|
||||
|
||||
public class PlayerCommand
|
||||
{
|
||||
public static void register(CommandDispatcher<ServerCommandSource> dispatcher)
|
||||
{
|
||||
LiteralArgumentBuilder<ServerCommandSource> literalargumentbuilder = literal("player").
|
||||
requires((player) -> CarpetSettings.getBool("commandPlayer")).
|
||||
then(argument("player", word()).
|
||||
suggests( (c, b) -> suggestMatching(getPlayers(c.getSource()), b)).
|
||||
then(literal("stop").
|
||||
executes(PlayerCommand::stop)).
|
||||
then(literal("use").
|
||||
executes(PlayerCommand::useOnce).
|
||||
then(literal("once").
|
||||
executes( PlayerCommand::useOnce)).
|
||||
then(literal("continuous").
|
||||
executes( PlayerCommand::useContinuous)).
|
||||
then(literal("interval").
|
||||
then(argument("ticks",integer(2)).
|
||||
executes( PlayerCommand::useInterval)))).
|
||||
then(literal("jump").
|
||||
executes( PlayerCommand::jumpOnce).
|
||||
then(literal("once").
|
||||
executes( PlayerCommand::jumpOnce)).
|
||||
then(literal("continuous").
|
||||
executes( PlayerCommand::jumpContinuous)).
|
||||
then(literal("interval").
|
||||
then(argument("ticks",integer(2)).
|
||||
executes( PlayerCommand::jumpInterval )))).
|
||||
then(literal("attack").
|
||||
executes(PlayerCommand::attackOnce).
|
||||
then(literal("once").
|
||||
executes(PlayerCommand::attackOnce)).
|
||||
then(literal("continuous").
|
||||
executes(PlayerCommand::attackContinuous)).
|
||||
then(literal("interval").
|
||||
then(argument("ticks",integer(2)).
|
||||
executes(PlayerCommand::attackInterval)))).
|
||||
then(literal("drop").
|
||||
executes(PlayerCommand::dropItem)).
|
||||
then(literal("swapHands").
|
||||
executes(PlayerCommand::swapHands)).
|
||||
then(literal("kill").
|
||||
executes(PlayerCommand::kill)).
|
||||
then(literal("shadow").
|
||||
executes(PlayerCommand::shadow)).
|
||||
then(literal("mount").
|
||||
executes(PlayerCommand::mount)).
|
||||
then(literal("dismount").
|
||||
executes(PlayerCommand::dismount)).
|
||||
then(literal("sneak").
|
||||
executes(PlayerCommand::sneak)).
|
||||
then(literal("sprint").
|
||||
executes(PlayerCommand::sprint)).
|
||||
then(literal("look").
|
||||
then(literal("north").
|
||||
executes(PlayerCommand::lookNorth)).
|
||||
then(literal("south").
|
||||
executes(PlayerCommand::lookSouth)).
|
||||
then(literal("east").
|
||||
executes(PlayerCommand::lookEast)).
|
||||
then(literal("west").
|
||||
executes(PlayerCommand::lookWest)).
|
||||
then(literal("up").
|
||||
executes(PlayerCommand::lookUp)).
|
||||
then(literal("down").
|
||||
executes(PlayerCommand::lookDown)).
|
||||
then(argument("direction", RotationArgumentType.create()).
|
||||
executes(PlayerCommand::lookAround))).
|
||||
then(literal("turn").
|
||||
then(literal("left").
|
||||
executes(PlayerCommand::turnLeft)).
|
||||
then(literal("right").
|
||||
executes(PlayerCommand::turnRight)).
|
||||
then(literal("back").
|
||||
executes(PlayerCommand::turnBack)).
|
||||
then(argument("direction",RotationArgumentType.create()).
|
||||
executes(PlayerCommand::turn))).
|
||||
then(literal("move").
|
||||
then(literal("forward").
|
||||
executes(PlayerCommand::moveForward)).
|
||||
then(literal("backward").
|
||||
executes(PlayerCommand::moveBackward)).
|
||||
then(literal("left").
|
||||
executes(PlayerCommand::strafeLeft)).
|
||||
then(literal("right").
|
||||
executes(PlayerCommand::strafeRight))).
|
||||
then(literal("spawn").
|
||||
executes(PlayerCommand::spawn).
|
||||
then(literal("at").
|
||||
then(argument("position", Vec3ArgumentType.create()).
|
||||
executes(PlayerCommand::spawn).
|
||||
then(literal("facing").
|
||||
then(argument("direction",RotationArgumentType.create()).
|
||||
executes(PlayerCommand::spawn).
|
||||
then(literal("in").
|
||||
then(argument("dimension", DimensionArgumentType.create()).
|
||||
executes(PlayerCommand::spawn)))))))));
|
||||
|
||||
dispatcher.register(literalargumentbuilder);
|
||||
}
|
||||
private static Collection<String> getPlayers(ServerCommandSource source)
|
||||
{
|
||||
Set<String> players = Sets.newLinkedHashSet( Arrays.asList("Steve","Alex"));
|
||||
players.addAll(source.getPlayerNames());
|
||||
return players;
|
||||
}
|
||||
|
||||
private static ServerPlayerEntity getPlayer(CommandContext<ServerCommandSource> context)
|
||||
{
|
||||
String playerName = getString(context,"player");
|
||||
MinecraftServer server = context.getSource().getMinecraftServer();
|
||||
return server.getPlayerManager().getPlayer(playerName);
|
||||
}
|
||||
|
||||
private static boolean cantSpawn(CommandContext<ServerCommandSource> context)
|
||||
{
|
||||
String playerName = getString(context,"player");
|
||||
PlayerEntity player = context.getSource().getMinecraftServer().getPlayerManager().getPlayer(playerName);
|
||||
if (player != null)
|
||||
{
|
||||
Messenger.m(context.getSource(), "r Player ", "rb "+playerName, "r is already logged on");
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static boolean cantManipulate(CommandContext<ServerCommandSource> context)
|
||||
{
|
||||
PlayerEntity player = getPlayer(context);
|
||||
if (player == null)
|
||||
{
|
||||
Messenger.m(context.getSource(),"r Can only manipulate existing players");
|
||||
return true;
|
||||
}
|
||||
PlayerEntity sendingPlayer;
|
||||
try
|
||||
{
|
||||
sendingPlayer = context.getSource().getPlayer();
|
||||
}
|
||||
catch (CommandSyntaxException e)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!(context.getSource().getMinecraftServer().getPlayerManager().isOperator(sendingPlayer.getGameProfile())))
|
||||
{
|
||||
if (!(sendingPlayer == player || player instanceof EntityPlayerMPFake))
|
||||
{
|
||||
Messenger.m(context.getSource(),"r Non OP players can't control other real players");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static boolean cantShadow(CommandContext<ServerCommandSource> context)
|
||||
{
|
||||
if (cantManipulate(context))
|
||||
return true;
|
||||
PlayerEntity player = getPlayer(context);
|
||||
if (player instanceof EntityPlayerMPFake)
|
||||
{
|
||||
Messenger.m(context.getSource(), "r Only real players can be shadowed");
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static boolean cantReMove(CommandContext<ServerCommandSource> context)
|
||||
{
|
||||
if (cantManipulate(context))
|
||||
return true;
|
||||
PlayerEntity player = getPlayer(context);
|
||||
if (!(player instanceof EntityPlayerMPFake))
|
||||
{
|
||||
Messenger.m(context.getSource(), "r Only fake players can be moved or killed");
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static int stop(CommandContext<ServerCommandSource> context)
|
||||
{
|
||||
if (cantManipulate(context)) return 0;
|
||||
((ServerPlayerEntityInterface)getPlayer(context)).getActionPack().stop();
|
||||
return 1;
|
||||
}
|
||||
private static int useOnce(CommandContext<ServerCommandSource> context)
|
||||
{
|
||||
if (cantManipulate(context)) return 0;
|
||||
((ServerPlayerEntityInterface)getPlayer(context)).getActionPack().useOnce();
|
||||
return 1;
|
||||
}
|
||||
private static int useContinuous(CommandContext<ServerCommandSource> context)
|
||||
{
|
||||
if (cantManipulate(context)) return 0;
|
||||
((ServerPlayerEntityInterface)getPlayer(context)).getActionPack().setUseForever();
|
||||
return 1;
|
||||
}
|
||||
private static int useInterval(CommandContext<ServerCommandSource> context)
|
||||
{
|
||||
if (cantManipulate(context)) return 0;
|
||||
int ticks = getInteger(context, "ticks");
|
||||
((ServerPlayerEntityInterface)getPlayer(context)).getActionPack().setUse(ticks, 0);
|
||||
return 1;
|
||||
}
|
||||
private static int jumpOnce(CommandContext<ServerCommandSource> context)
|
||||
{
|
||||
if (cantManipulate(context)) return 0;
|
||||
((ServerPlayerEntityInterface)getPlayer(context)).getActionPack().jumpOnce();
|
||||
return 1;
|
||||
}
|
||||
private static int jumpContinuous(CommandContext<ServerCommandSource> context)
|
||||
{
|
||||
if (cantManipulate(context)) return 0;
|
||||
((ServerPlayerEntityInterface)getPlayer(context)).getActionPack().setJumpForever();
|
||||
return 1;
|
||||
}
|
||||
private static int jumpInterval(CommandContext<ServerCommandSource> context)
|
||||
{
|
||||
if (cantManipulate(context)) return 0;
|
||||
int ticks = getInteger(context, "ticks");
|
||||
((ServerPlayerEntityInterface)getPlayer(context)).getActionPack().setJump(ticks, 0);
|
||||
return 1;
|
||||
}
|
||||
private static int attackOnce(CommandContext<ServerCommandSource> context)
|
||||
{
|
||||
if (cantManipulate(context)) return 0;
|
||||
((ServerPlayerEntityInterface)getPlayer(context)).getActionPack().attackOnce();
|
||||
//((ServerPlayerEntityInterface)getPlayer(context)).getActionPack().resetBlockRemoving(true);
|
||||
|
||||
return 1;
|
||||
}
|
||||
private static int attackContinuous(CommandContext<ServerCommandSource> context)
|
||||
{
|
||||
if (cantManipulate(context)) return 0;
|
||||
((ServerPlayerEntityInterface)getPlayer(context)).getActionPack().setAttackForever();
|
||||
return 1;
|
||||
}
|
||||
private static int attackInterval(CommandContext<ServerCommandSource> context)
|
||||
{
|
||||
if (cantManipulate(context)) return 0;
|
||||
int ticks = getInteger(context, "ticks");
|
||||
((ServerPlayerEntityInterface)getPlayer(context)).getActionPack().setAttack(ticks, 0);
|
||||
return 1;
|
||||
}
|
||||
private static int dropItem(CommandContext<ServerCommandSource> context)
|
||||
{
|
||||
if (cantManipulate(context)) return 0;
|
||||
((ServerPlayerEntityInterface)getPlayer(context)).getActionPack().dropItem();
|
||||
return 1;
|
||||
}
|
||||
private static int swapHands(CommandContext<ServerCommandSource> context)
|
||||
{
|
||||
if (cantManipulate(context)) return 0;
|
||||
((ServerPlayerEntityInterface)getPlayer(context)).getActionPack().swapHands();
|
||||
return 1;
|
||||
}
|
||||
private static int kill(CommandContext<ServerCommandSource> context)
|
||||
{
|
||||
if (cantReMove(context)) return 0;
|
||||
getPlayer(context).kill();
|
||||
return 1;
|
||||
}
|
||||
private static int shadow(CommandContext<ServerCommandSource> context)
|
||||
{
|
||||
if (cantShadow(context)) return 0;
|
||||
EntityPlayerMPFake.createShadow(
|
||||
context.getSource().getMinecraftServer(),
|
||||
getPlayer(context));
|
||||
return 1;
|
||||
}
|
||||
private static int mount(CommandContext<ServerCommandSource> context)
|
||||
{
|
||||
if (cantManipulate(context)) return 0;
|
||||
((ServerPlayerEntityInterface)getPlayer(context)).getActionPack().mount();
|
||||
return 1;
|
||||
}
|
||||
private static int dismount(CommandContext<ServerCommandSource> context)
|
||||
{
|
||||
if (cantManipulate(context)) return 0;
|
||||
((ServerPlayerEntityInterface)getPlayer(context)).getActionPack().dismount();
|
||||
return 1;
|
||||
}
|
||||
private static int sneak(CommandContext<ServerCommandSource> context)
|
||||
{
|
||||
if (cantReMove(context)) return 0;
|
||||
((ServerPlayerEntityInterface)getPlayer(context)).getActionPack().setSneaking(true);
|
||||
return 1;
|
||||
}
|
||||
private static int sprint(CommandContext<ServerCommandSource> context)
|
||||
{
|
||||
if (cantReMove(context)) return 0;
|
||||
((ServerPlayerEntityInterface)getPlayer(context)).getActionPack().setSprinting(true);
|
||||
return 1;
|
||||
}
|
||||
private static int lookNorth(CommandContext<ServerCommandSource> context)
|
||||
{
|
||||
if (cantReMove(context)) return 0;
|
||||
((ServerPlayerEntityInterface)getPlayer(context)).getActionPack().look("north");
|
||||
return 1;
|
||||
}
|
||||
private static int lookSouth(CommandContext<ServerCommandSource> context)
|
||||
{
|
||||
if (cantReMove(context)) return 0;
|
||||
((ServerPlayerEntityInterface)getPlayer(context)).getActionPack().look("south");
|
||||
return 1;
|
||||
}
|
||||
private static int lookEast(CommandContext<ServerCommandSource> context)
|
||||
{
|
||||
if (cantReMove(context)) return 0;
|
||||
((ServerPlayerEntityInterface)getPlayer(context)).getActionPack().look("east");
|
||||
return 1;
|
||||
}
|
||||
private static int lookWest(CommandContext<ServerCommandSource> context)
|
||||
{
|
||||
if (cantReMove(context)) return 0;
|
||||
((ServerPlayerEntityInterface)getPlayer(context)).getActionPack().look("west");
|
||||
return 1;
|
||||
}
|
||||
private static int lookUp(CommandContext<ServerCommandSource> context)
|
||||
{
|
||||
if (cantReMove(context)) return 0;
|
||||
((ServerPlayerEntityInterface)getPlayer(context)).getActionPack().look("up");
|
||||
return 1;
|
||||
}
|
||||
private static int lookDown(CommandContext<ServerCommandSource> context)
|
||||
{
|
||||
if (cantReMove(context)) return 0;
|
||||
((ServerPlayerEntityInterface)getPlayer(context)).getActionPack().look("down");
|
||||
return 1;
|
||||
}
|
||||
private static int lookAround(CommandContext<ServerCommandSource> context)
|
||||
{
|
||||
if (cantReMove(context)) return 0;
|
||||
Vec2f vec2f = RotationArgumentType.getRotation(context, "direction").toAbsoluteRotation(context.getSource());
|
||||
((ServerPlayerEntityInterface)getPlayer(context)).getActionPack().look(vec2f.y,vec2f.x);
|
||||
return 1;
|
||||
}
|
||||
private static int turnRight(CommandContext<ServerCommandSource> context)
|
||||
{
|
||||
if (cantReMove(context)) return 0;
|
||||
((ServerPlayerEntityInterface)getPlayer(context)).getActionPack().turn("right");
|
||||
return 1;
|
||||
}
|
||||
private static int turnLeft(CommandContext<ServerCommandSource> context)
|
||||
{
|
||||
if (cantReMove(context)) return 0;
|
||||
((ServerPlayerEntityInterface)getPlayer(context)).getActionPack().turn("left");
|
||||
return 1;
|
||||
}
|
||||
private static int turnBack(CommandContext<ServerCommandSource> context)
|
||||
{
|
||||
if (cantReMove(context)) return 0;
|
||||
((ServerPlayerEntityInterface)getPlayer(context)).getActionPack().turn("back");
|
||||
return 1;
|
||||
}
|
||||
private static int turn(CommandContext<ServerCommandSource> context)
|
||||
{
|
||||
if (cantReMove(context)) return 0;
|
||||
Vec2f vec2f = RotationArgumentType.getRotation(context, "direction").toAbsoluteRotation(context.getSource());
|
||||
((ServerPlayerEntityInterface)getPlayer(context)).getActionPack().turn(vec2f.y,vec2f.x);
|
||||
return 1;
|
||||
}
|
||||
private static int moveForward(CommandContext<ServerCommandSource> context)
|
||||
{
|
||||
if (cantReMove(context)) return 0;
|
||||
((ServerPlayerEntityInterface)getPlayer(context)).getActionPack().setForward(1.0F);
|
||||
return 1;
|
||||
}
|
||||
private static int moveBackward(CommandContext<ServerCommandSource> context)
|
||||
{
|
||||
if (cantReMove(context)) return 0;
|
||||
((ServerPlayerEntityInterface)getPlayer(context)).getActionPack().setForward(-1.0F);
|
||||
return 1;
|
||||
}
|
||||
private static int strafeLeft(CommandContext<ServerCommandSource> context)
|
||||
{
|
||||
if (cantReMove(context)) return 0;
|
||||
((ServerPlayerEntityInterface)getPlayer(context)).getActionPack().setStrafing(-1.0F);
|
||||
return 1;
|
||||
}
|
||||
private static int strafeRight(CommandContext<ServerCommandSource> context)
|
||||
{
|
||||
if (cantReMove(context)) return 0;
|
||||
((ServerPlayerEntityInterface)getPlayer(context)).getActionPack().setStrafing(1.0F);
|
||||
return 1;
|
||||
}
|
||||
private static int spawn(CommandContext<ServerCommandSource> context) throws CommandSyntaxException
|
||||
{
|
||||
if (cantSpawn(context)) return 0;
|
||||
Vec3d pos;
|
||||
Vec2f facing;
|
||||
DimensionType dim;
|
||||
try
|
||||
{
|
||||
pos = Vec3ArgumentType.getVec3(context, "position");
|
||||
}
|
||||
catch (IllegalArgumentException e)
|
||||
{
|
||||
pos = context.getSource().getPosition();
|
||||
}
|
||||
try
|
||||
{
|
||||
facing = RotationArgumentType.getRotation(context, "direction").toAbsoluteRotation(context.getSource());
|
||||
}
|
||||
catch (IllegalArgumentException e)
|
||||
{
|
||||
facing = context.getSource().getRotation();
|
||||
}
|
||||
try
|
||||
{
|
||||
dim = DimensionArgumentType.getDimensionArgument(context, "dimension");
|
||||
}
|
||||
catch (IllegalArgumentException e)
|
||||
{
|
||||
dim = context.getSource().getWorld().dimension.getType();
|
||||
}
|
||||
GameMode mode = GameMode.CREATIVE;
|
||||
try
|
||||
{
|
||||
ServerPlayerEntity player = context.getSource().getPlayer();
|
||||
mode = player.interactionManager.getGameMode();
|
||||
}
|
||||
catch (CommandSyntaxException ignored)
|
||||
{
|
||||
}
|
||||
PlayerEntity p = EntityPlayerMPFake.createFake(
|
||||
getString(context,"player"),
|
||||
context.getSource().getMinecraftServer(),
|
||||
pos.x, pos.y, pos.z,
|
||||
facing.y, facing.x,
|
||||
dim,
|
||||
mode);
|
||||
if (p == null)
|
||||
{
|
||||
Messenger.m(context.getSource(), "rb Player "+getString(context,"player")+" doesn't exist " +
|
||||
"and cannot spawn in online mode. Turn the server offline to spawn non-existing players");
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,144 @@
|
||||
package carpet.commands;
|
||||
|
||||
import carpet.CarpetSettings;
|
||||
import carpet.helpers.TickSpeed;
|
||||
import carpet.utils.CarpetProfiler;
|
||||
import carpet.utils.Messenger;
|
||||
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.network.chat.BaseComponent;
|
||||
import net.minecraft.server.command.ServerCommandSource;
|
||||
|
||||
import static com.mojang.brigadier.arguments.FloatArgumentType.floatArg;
|
||||
import static com.mojang.brigadier.arguments.FloatArgumentType.getFloat;
|
||||
import static com.mojang.brigadier.arguments.IntegerArgumentType.getInteger;
|
||||
import static com.mojang.brigadier.arguments.IntegerArgumentType.integer;
|
||||
import static com.mojang.brigadier.arguments.StringArgumentType.getString;
|
||||
import static com.mojang.brigadier.arguments.StringArgumentType.greedyString;
|
||||
import static net.minecraft.server.command.CommandManager.argument;
|
||||
import static net.minecraft.server.command.CommandManager.literal;
|
||||
import static net.minecraft.server.command.CommandSource.suggestMatching;
|
||||
|
||||
public class TickCommand
|
||||
{
|
||||
public static void register(CommandDispatcher<ServerCommandSource> dispatcher)
|
||||
{
|
||||
LiteralArgumentBuilder<ServerCommandSource> literalargumentbuilder = literal("tick").
|
||||
requires((player) -> CarpetSettings.getBool("commandTick")).
|
||||
then(literal("rate").
|
||||
executes((c) -> queryTps(c.getSource())).
|
||||
then(argument("rate", floatArg(0.1F, 500.0F)).
|
||||
suggests( (c, b) -> suggestMatching(new String[]{"20.0"},b)).
|
||||
executes((c) -> setTps(c.getSource(), getFloat(c, "rate"))))).
|
||||
then(literal("warp").
|
||||
executes( (c)-> setWarp(c.getSource(), 0, null)).
|
||||
then(argument("ticks", integer(0,4000000)).
|
||||
suggests( (c, b) -> suggestMatching(new String[]{"3600","72000"},b)).
|
||||
executes((c) -> setWarp(c.getSource(), getInteger(c,"ticks"), null)).
|
||||
then(argument("tail command", greedyString()).
|
||||
executes( (c) -> setWarp(
|
||||
c.getSource(),
|
||||
getInteger(c,"ticks"),
|
||||
getString(c, "tail command")))))).
|
||||
then(literal("freeze").executes( (c)-> toggleFreeze(c.getSource()))).
|
||||
then(literal("step").
|
||||
executes((c) -> step(1)).
|
||||
then(argument("ticks", integer(1,72000)).
|
||||
suggests( (c, b) -> suggestMatching(new String[]{"20"},b)).
|
||||
executes((c) -> step(getInteger(c,"ticks"))))).
|
||||
then(literal("superHot").executes( (c)-> toggleSuperHot(c.getSource()))).
|
||||
then(literal("health").
|
||||
executes( (c) -> healthReport(c.getSource(), 100)).
|
||||
then(argument("ticks", integer(20,24000)).
|
||||
executes( (c) -> healthReport(c.getSource(), getInteger(c, "ticks"))))).
|
||||
then(literal("entities").
|
||||
executes((c) -> healthEntities(c.getSource(), 100)).
|
||||
then(argument("ticks", integer(20,24000)).
|
||||
executes((c) -> healthEntities(c.getSource(), getInteger(c, "ticks")))));
|
||||
|
||||
|
||||
dispatcher.register(literalargumentbuilder);
|
||||
}
|
||||
|
||||
|
||||
private static int setTps(ServerCommandSource source, float tps)
|
||||
{
|
||||
TickSpeed.tickrate(tps);
|
||||
queryTps(source);
|
||||
return (int)tps;
|
||||
}
|
||||
|
||||
private static int queryTps(ServerCommandSource source)
|
||||
{
|
||||
Messenger.m(source, "w Current tps is: ",String.format("wb %.1f", TickSpeed.tickrate));
|
||||
return (int)TickSpeed.tickrate;
|
||||
}
|
||||
|
||||
private static int setWarp(ServerCommandSource source, int advance, String tail_command)
|
||||
{
|
||||
PlayerEntity player = null;
|
||||
try
|
||||
{
|
||||
player = source.getPlayer();
|
||||
}
|
||||
catch (CommandSyntaxException ignored)
|
||||
{
|
||||
}
|
||||
BaseComponent message = TickSpeed.tickrate_advance(player, advance, tail_command, source);
|
||||
if (message != null)
|
||||
{
|
||||
source.sendFeedback(message, false);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
private static int toggleFreeze(ServerCommandSource source)
|
||||
{
|
||||
TickSpeed.is_paused = !TickSpeed.is_paused;
|
||||
if (TickSpeed.is_paused)
|
||||
{
|
||||
Messenger.m(source, "gi Game is paused");
|
||||
}
|
||||
else
|
||||
{
|
||||
Messenger.m(source, "gi Game runs normally");
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
private static int step(int advance)
|
||||
{
|
||||
TickSpeed.add_ticks_to_run_in_pause(advance);
|
||||
return 1;
|
||||
}
|
||||
|
||||
private static int toggleSuperHot(ServerCommandSource source)
|
||||
{
|
||||
TickSpeed.is_superHot = !TickSpeed.is_superHot;
|
||||
if (TickSpeed.is_superHot)
|
||||
{
|
||||
Messenger.m(source,"gi Superhot enabled");
|
||||
}
|
||||
else
|
||||
{
|
||||
Messenger.m(source, "gi Superhot disabled");
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
private static int healthReport(ServerCommandSource source, int ticks)
|
||||
{
|
||||
CarpetProfiler.prepare_tick_report(ticks);
|
||||
return 1;
|
||||
}
|
||||
|
||||
private static int healthEntities(ServerCommandSource source, int ticks)
|
||||
{
|
||||
CarpetProfiler.prepare_entity_report(ticks);
|
||||
return 1;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user