mirror of
https://github.com/Sollace/Unicopia.git
synced 2024-11-27 15:17:59 +01:00
Fixed server-wide default race being set to human and added a command to change it
This commit is contained in:
parent
99120bd40d
commit
3d5fe40950
6 changed files with 76 additions and 42 deletions
|
@ -2,14 +2,11 @@ package com.minelittlepony.unicopia;
|
|||
|
||||
import net.minecraft.nbt.NbtCompound;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.registry.entry.RegistryEntry;
|
||||
import net.minecraft.world.PersistentState;
|
||||
import net.minecraft.world.dimension.DimensionType;
|
||||
import net.minecraft.world.dimension.DimensionTypes;
|
||||
|
||||
public class WorldTribeManager extends PersistentState {
|
||||
|
||||
private Race defaultRace = Race.HUMAN;
|
||||
private Race defaultRace = Race.UNSET;
|
||||
|
||||
public WorldTribeManager() {}
|
||||
|
||||
|
@ -33,14 +30,7 @@ public class WorldTribeManager extends PersistentState {
|
|||
return tag;
|
||||
}
|
||||
|
||||
public static String nameFor(RegistryEntry<DimensionType> dimension) {
|
||||
if (dimension.matchesKey(DimensionTypes.THE_END)) {
|
||||
return "unicopia:tribes_end";
|
||||
}
|
||||
return "unicopia:tribes";
|
||||
}
|
||||
|
||||
public static WorldTribeManager forWorld(ServerWorld world) {
|
||||
return world.getPersistentStateManager().getOrCreate(WorldTribeManager::new, WorldTribeManager::new, nameFor(world.getDimensionEntry()));
|
||||
return world.getPersistentStateManager().getOrCreate(WorldTribeManager::new, WorldTribeManager::new, "unicopia:tribes");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,6 +22,7 @@ public class Commands {
|
|||
EmoteCommand.register(dispatcher);
|
||||
if (Unicopia.getConfig().enableCheats.get() || environment.dedicated) {
|
||||
SpeciesCommand.register(dispatcher, environment);
|
||||
WorldTribeCommand.register(dispatcher);
|
||||
}
|
||||
if (Unicopia.getConfig().enableCheats.get()) {
|
||||
GravityCommand.register(dispatcher);
|
||||
|
@ -32,9 +33,9 @@ public class Commands {
|
|||
}
|
||||
}
|
||||
});
|
||||
Object game = FabricLoader.getInstance().getGameInstance();
|
||||
if (game instanceof MinecraftServer) {
|
||||
((MinecraftServer)game).setFlightEnabled(true);
|
||||
|
||||
if (FabricLoader.getInstance().getGameInstance() instanceof MinecraftServer server) {
|
||||
server.setFlightEnabled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,9 @@
|
|||
package com.minelittlepony.unicopia.command;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import com.google.common.collect.Streams;
|
||||
import com.minelittlepony.unicopia.entity.player.Pony;
|
||||
import com.mojang.brigadier.CommandDispatcher;
|
||||
import com.mojang.brigadier.arguments.FloatArgumentType;
|
||||
|
@ -36,39 +40,33 @@ class GravityCommand {
|
|||
}
|
||||
|
||||
static int get(ServerCommandSource source, PlayerEntity player, boolean isSelf) throws CommandSyntaxException {
|
||||
String translationKey = "commands.gravity.get";
|
||||
|
||||
Pony iplayer = Pony.of(player);
|
||||
|
||||
float gravity = iplayer.getPhysics().getGravityModifier();
|
||||
|
||||
if (source.getPlayer() == player) {
|
||||
player.sendMessage(Text.translatable(translationKey, gravity), false);
|
||||
} else {
|
||||
source.sendFeedback(Text.translatable(translationKey + ".other", player.getName(), gravity), true);
|
||||
}
|
||||
|
||||
sendFeedback(source, player, "get", false, Pony.of(player).getPhysics().getGravityModifier());
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int set(ServerCommandSource source, PlayerEntity player, float gravity, boolean isSelf) {
|
||||
String translationKey = "commands.gravity.set";
|
||||
|
||||
Pony iplayer = Pony.of(player);
|
||||
|
||||
iplayer.getPhysics().setBaseGravityModifier(gravity);
|
||||
iplayer.setDirty();
|
||||
|
||||
if (source.getEntity() == player) {
|
||||
source.sendFeedback(Text.translatable("commands.gamemode.success.self", gravity), true);
|
||||
} else {
|
||||
if (source.getWorld().getGameRules().getBoolean(GameRules.SEND_COMMAND_FEEDBACK)) {
|
||||
player.sendMessage(Text.translatable(translationKey, gravity));
|
||||
}
|
||||
|
||||
source.sendFeedback(Text.translatable(translationKey + ".other", player.getName(), gravity), true);
|
||||
}
|
||||
|
||||
sendFeedback(source, player, "set", true, gravity);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static void sendFeedback(ServerCommandSource source, PlayerEntity player, String key, boolean notifyTarget, Object...arguments) {
|
||||
String translationKey = "commands.gravity." + key;
|
||||
|
||||
if (source.getEntity() == player) {
|
||||
source.sendFeedback(Text.translatable(translationKey + ".self", arguments), true);
|
||||
} else {
|
||||
if (notifyTarget && source.getWorld().getGameRules().getBoolean(GameRules.SEND_COMMAND_FEEDBACK)) {
|
||||
player.sendMessage(Text.translatable(translationKey, arguments));
|
||||
}
|
||||
|
||||
source.sendFeedback(Text.translatable(translationKey + ".other", Streams.concat(Stream.of(player.getDisplayName()), Arrays.stream(arguments)).toArray()), true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -64,11 +64,11 @@ class SpeciesCommand {
|
|||
pony.setSpecies(race);
|
||||
pony.setDirty();
|
||||
|
||||
if (!isSelf) {
|
||||
source.sendFeedback(Text.translatable("commands.race.success.other", player.getName(), race.getDisplayName()), true);
|
||||
if (player == source.getPlayer()) {
|
||||
source.sendFeedback(Text.translatable("commands.race.success.self", player.getName(), race.getDisplayName()), true);
|
||||
} else {
|
||||
if (player.getEntityWorld().getGameRules().getBoolean(GameRules.SEND_COMMAND_FEEDBACK)) {
|
||||
player.sendMessage(Text.translatable("commands.race.success.self"), false);
|
||||
player.sendMessage(Text.translatable("commands.race.success.other"), false);
|
||||
}
|
||||
source.sendFeedback(Text.translatable("commands.race.success.otherself", player.getName(), race.getDisplayName()), true);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,40 @@
|
|||
package com.minelittlepony.unicopia.command;
|
||||
|
||||
import com.minelittlepony.unicopia.Race;
|
||||
import com.minelittlepony.unicopia.WorldTribeManager;
|
||||
import com.mojang.brigadier.CommandDispatcher;
|
||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||
|
||||
import net.minecraft.server.command.CommandManager;
|
||||
import net.minecraft.server.command.ServerCommandSource;
|
||||
import net.minecraft.text.Text;
|
||||
|
||||
class WorldTribeCommand {
|
||||
static void register(CommandDispatcher<ServerCommandSource> dispatcher) {
|
||||
LiteralArgumentBuilder<ServerCommandSource> builder = CommandManager
|
||||
.literal("worldtribe")
|
||||
.requires(s -> s.hasPermissionLevel(4));
|
||||
|
||||
builder.then(CommandManager.literal("get").executes(context -> get(context.getSource())));
|
||||
builder.then(CommandManager.literal("set")
|
||||
.then(CommandManager.argument("race", Race.argument())
|
||||
.executes(context -> set(context.getSource(), Race.fromArgument(context, "race")))));
|
||||
|
||||
dispatcher.register(builder);
|
||||
}
|
||||
|
||||
static int get(ServerCommandSource source) throws CommandSyntaxException {
|
||||
WorldTribeManager manager = WorldTribeManager.forWorld(source.getWorld());
|
||||
source.sendFeedback(Text.translatable("commands.worldtribe.success.get", manager.getDefaultRace().getDisplayName()), true);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int set(ServerCommandSource source, Race race) {
|
||||
WorldTribeManager manager = WorldTribeManager.forWorld(source.getWorld());
|
||||
manager.setDefaultRace(race);
|
||||
|
||||
source.sendFeedback(Text.translatable("commands.worldtribe.success.set", race.getDisplayName()), true);
|
||||
return 0;
|
||||
}
|
||||
}
|
|
@ -448,6 +448,9 @@
|
|||
"commands.racelist.disallowed": "Removed %1$s from the whitelist.",
|
||||
"commands.racelist.disallowed.failed": "%1$s is not on the whitelist.",
|
||||
|
||||
"commands.worldtribe.success.get": "Default race for all new players is currently set to: %s",
|
||||
"commands.worldtribe.success.set": "Set default race for new players is now set to: %s",
|
||||
|
||||
"commands.disguise.usage": "/disguise <player> <entity> [nbt]",
|
||||
"commands.disguise.notfound": "The entity id '%s' does not exist.",
|
||||
"commands.disguise.removed": "Your disguise has been removed.",
|
||||
|
@ -478,6 +481,8 @@
|
|||
"unicopia.options.world.default_race": "Default Race: %s",
|
||||
"unicopia.options.lan": "Multiplayer (LAN) Settings",
|
||||
|
||||
"unicopia.race.unset": "Unset",
|
||||
"unicopia.race.unset.alt": "Unset",
|
||||
"unicopia.race.human": "Human",
|
||||
"unicopia.race.human.alt": "Humans",
|
||||
"unicopia.race.earth": "Earth Pony",
|
||||
|
|
Loading…
Reference in a new issue