Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 95aaea22cb |
+3
-3
@@ -1,12 +1,12 @@
|
||||
org.gradle.jvmargs=-Xmx1G
|
||||
org.gradle.parallel=true
|
||||
org.gradle.configuration-cache=false
|
||||
minecraft_version=1.21.11
|
||||
minecraft_version=1.21.1
|
||||
loader_version=0.18.4
|
||||
loom_version=1.14-SNAPSHOT
|
||||
|
||||
mod_version=1.0.0
|
||||
mod_version=2.0.0
|
||||
maven_group=nl.getagripgal.persistentspawn
|
||||
archives_base_name=persistentspawn
|
||||
|
||||
fabric_api_version=0.140.2+1.21.11
|
||||
fabric_api_version=0.116.8+1.21.1
|
||||
@@ -3,11 +3,11 @@ package nl.getagripgal.persistentspawn;
|
||||
import com.mojang.brigadier.context.CommandContext;
|
||||
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
import net.minecraft.commands.arguments.coordinates.Coordinates;
|
||||
import net.minecraft.commands.arguments.coordinates.Vec3Argument;
|
||||
import net.minecraft.core.registries.Registries;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.resources.Identifier;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
|
||||
/**
|
||||
@@ -21,15 +21,13 @@ public class CommandHandlers {
|
||||
* @return The exit code.
|
||||
*/
|
||||
public static int setPersistentSpawn(CommandContext<CommandSourceStack> context) {
|
||||
Coordinates positionArgument = context.getArgument("position", Coordinates.class);
|
||||
Identifier dimensionArgument = context.getArgument("dimension", Identifier.class);
|
||||
Vec3 position = Vec3Argument.getVec3(context, "position");
|
||||
ResourceLocation dimensionArgument = context.getArgument("dimension", ResourceLocation.class);
|
||||
|
||||
PersistentSpawnManager.CurrentSpawn = positionArgument.getPosition(context.getSource());
|
||||
PersistentSpawnManager.CurrentSpawn = position;
|
||||
PersistentSpawnManager.Dimension = ResourceKey.create(Registries.DIMENSION, dimensionArgument);
|
||||
|
||||
PersistentSpawnManager.syncToDisk();
|
||||
|
||||
Vec3 position = PersistentSpawnManager.CurrentSpawn;
|
||||
context.getSource()
|
||||
.sendSuccess(
|
||||
() -> Component.literal("Set spawn at %s in %s".formatted(position.toString(),
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package nl.getagripgal.persistentspawn;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
|
||||
@@ -21,6 +22,6 @@ public class EventHandlers {
|
||||
|
||||
ServerLevel level = (ServerLevel) player.level().getServer().getLevel(PersistentSpawnManager.Dimension);
|
||||
player.teleportTo(level, PersistentSpawnManager.CurrentSpawn.x, PersistentSpawnManager.CurrentSpawn.y,
|
||||
PersistentSpawnManager.CurrentSpawn.z, Set.of(), 0.0f, 0.0f, false);
|
||||
PersistentSpawnManager.CurrentSpawn.z, Set.of(), 0.0f, 0.0f);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,17 +1,16 @@
|
||||
package nl.getagripgal.persistentspawn;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.mojang.brigadier.arguments.BoolArgumentType;
|
||||
|
||||
import net.fabricmc.api.ModInitializer;
|
||||
import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback;
|
||||
import net.fabricmc.fabric.api.entity.event.v1.ServerPlayerEvents;
|
||||
import net.minecraft.commands.Commands;
|
||||
import net.minecraft.commands.arguments.DimensionArgument;
|
||||
import net.minecraft.commands.arguments.coordinates.Vec3Argument;
|
||||
import net.minecraft.server.permissions.Permissions;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.mojang.brigadier.arguments.BoolArgumentType;
|
||||
|
||||
/**
|
||||
* A very simple mod that implements the functionality of spawning a player at
|
||||
@@ -21,6 +20,11 @@ public class PersistentSpawn implements ModInitializer {
|
||||
public static final String MOD_ID = "persistentspawn";
|
||||
public static final Logger LOGGER = LoggerFactory.getLogger(MOD_ID);
|
||||
|
||||
/**
|
||||
* The permission level for the operator.
|
||||
*/
|
||||
private static final int PERMISSION_OP = 2;
|
||||
|
||||
@Override
|
||||
public void onInitialize() {
|
||||
registerCommands();
|
||||
@@ -34,14 +38,14 @@ public class PersistentSpawn implements ModInitializer {
|
||||
private void registerCommands() {
|
||||
CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> dispatcher
|
||||
.register(Commands.literal("setpersistentspawn")
|
||||
.requires(source -> source.permissions().hasPermission(Permissions.COMMANDS_MODERATOR))
|
||||
.requires(source -> source.hasPermission(PERMISSION_OP))
|
||||
.then(Commands.argument("position", Vec3Argument.vec3())
|
||||
.then(Commands.argument("dimension", DimensionArgument.dimension())
|
||||
.executes(CommandHandlers::setPersistentSpawn)))));
|
||||
|
||||
CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> dispatcher
|
||||
.register(Commands.literal("setpersistentspawnenabled")
|
||||
.requires(source -> source.permissions().hasPermission(Permissions.COMMANDS_MODERATOR))
|
||||
.requires(source -> source.hasPermission(PERMISSION_OP))
|
||||
.then(Commands.argument("enable", BoolArgumentType.bool())
|
||||
.executes(CommandHandlers::enablePersistentSpawn))));
|
||||
}
|
||||
|
||||
@@ -4,17 +4,17 @@ package nl.getagripgal.persistentspawn;
|
||||
* The spawn config as stored on disk.
|
||||
*/
|
||||
public class PersistentSpawnConfig {
|
||||
public int x;
|
||||
public int y;
|
||||
public int z;
|
||||
public double x;
|
||||
public double y;
|
||||
public double z;
|
||||
public String dimension;
|
||||
public boolean enabled;
|
||||
|
||||
public static PersistentSpawnConfig defaultConfig() {
|
||||
PersistentSpawnConfig config = new PersistentSpawnConfig();
|
||||
config.x = 0;
|
||||
config.y = 100;
|
||||
config.z = 0;
|
||||
config.x = 0.0;
|
||||
config.y = 100.0;
|
||||
config.z = 0.0;
|
||||
config.dimension = "minecraft:overworld";
|
||||
config.enabled = false;
|
||||
return config;
|
||||
|
||||
@@ -1,13 +1,14 @@
|
||||
package nl.getagripgal.persistentspawn;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import com.moandjiezana.toml.Toml;
|
||||
import com.moandjiezana.toml.TomlWriter;
|
||||
|
||||
import net.minecraft.core.registries.Registries;
|
||||
import net.minecraft.resources.Identifier;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
|
||||
@@ -44,7 +45,7 @@ public class PersistentSpawnManager {
|
||||
PersistentSpawnConfig config = toml.to(PersistentSpawnConfig.class);
|
||||
|
||||
CurrentSpawn = new Vec3(config.x, config.y, config.z);
|
||||
Dimension = ResourceKey.create(Registries.DIMENSION, Identifier.parse(config.dimension));
|
||||
Dimension = ResourceKey.create(Registries.DIMENSION, ResourceLocation.parse(config.dimension));
|
||||
Enabled = config.enabled;
|
||||
} catch (Exception e) {
|
||||
PersistentSpawn.LOGGER.error(
|
||||
@@ -52,7 +53,7 @@ public class PersistentSpawnManager {
|
||||
e);
|
||||
PersistentSpawnConfig defaultConfig = PersistentSpawnConfig.defaultConfig();
|
||||
CurrentSpawn = new Vec3(defaultConfig.x, defaultConfig.y, defaultConfig.z);
|
||||
Dimension = ResourceKey.create(Registries.DIMENSION, Identifier.parse(defaultConfig.dimension));
|
||||
Dimension = ResourceKey.create(Registries.DIMENSION, ResourceLocation.parse(defaultConfig.dimension));
|
||||
Enabled = defaultConfig.enabled;
|
||||
}
|
||||
}
|
||||
@@ -63,15 +64,15 @@ public class PersistentSpawnManager {
|
||||
public static void syncToDisk() {
|
||||
try {
|
||||
PersistentSpawnConfig config = new PersistentSpawnConfig();
|
||||
config.x = (int) CurrentSpawn.x;
|
||||
config.y = (int) CurrentSpawn.y;
|
||||
config.z = (int) CurrentSpawn.z;
|
||||
config.dimension = Dimension.identifier().toString();
|
||||
config.x = CurrentSpawn.x;
|
||||
config.y = CurrentSpawn.y;
|
||||
config.z = CurrentSpawn.z;
|
||||
config.dimension = Dimension.location().toString();
|
||||
config.enabled = Enabled;
|
||||
|
||||
TomlWriter writer = new TomlWriter();
|
||||
writer.write(config, new File(CONFIG_FILE));
|
||||
} catch (Exception e) {
|
||||
} catch (IOException e) {
|
||||
PersistentSpawn.LOGGER.error("Failed to save persistent spawn config to disk.", e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,30 +1,26 @@
|
||||
{
|
||||
"schemaVersion": 1,
|
||||
"id": "spawnpointonjoin",
|
||||
"version": "1.0.0",
|
||||
"name": "SpawnpointOnJoin",
|
||||
"description": "A very simple mod that implements the functionality of spawning a player at the same location on every join.",
|
||||
"authors": [
|
||||
"GetAGripGal"
|
||||
],
|
||||
"contact": {
|
||||
"homepage": "https://fabricmc.net/",
|
||||
"sources": "https://github.com/FabricMC/fabric-example-mod"
|
||||
},
|
||||
"license": "CC0-1.0",
|
||||
"icon": "assets/spawnpointonjoin/icon.png",
|
||||
"environment": "*",
|
||||
"entrypoints": {
|
||||
"main": [
|
||||
"nl.getagripgal.persistentspawn.PersistentSpawn"
|
||||
],
|
||||
"client": []
|
||||
},
|
||||
"mixins": [],
|
||||
"depends": {
|
||||
"fabricloader": ">=0.18.4",
|
||||
"minecraft": "~1.21.11",
|
||||
"java": ">=21",
|
||||
"fabric-api": "*"
|
||||
}
|
||||
}
|
||||
"schemaVersion": 1,
|
||||
"id": "spawnpointonjoin",
|
||||
"version": "1.0.0",
|
||||
"name": "SpawnpointOnJoin",
|
||||
"description": "A very simple mod that implements the functionality of spawning a player at the same location on every join.",
|
||||
"authors": ["GetAGripGal"],
|
||||
"contact": {
|
||||
"homepage": "https://fabricmc.net/",
|
||||
"sources": "https://github.com/FabricMC/fabric-example-mod"
|
||||
},
|
||||
"license": "CC0-1.0",
|
||||
"icon": "assets/spawnpointonjoin/icon.png",
|
||||
"environment": "*",
|
||||
"entrypoints": {
|
||||
"main": ["nl.getagripgal.persistentspawn.PersistentSpawn"],
|
||||
"client": []
|
||||
},
|
||||
"mixins": [],
|
||||
"depends": {
|
||||
"fabricloader": ">=0.18.4",
|
||||
"minecraft": "~1.21.1",
|
||||
"java": ">=21",
|
||||
"fabric-api": "*"
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user