pala M-cmd-util: /craft table portable + /spawn delai 3s (wiki commandes)
This commit is contained in:
@@ -24,12 +24,17 @@ import fr.surviepote.pala.core.PalaPermissions;
|
||||
import fr.surviepote.pala.core.PalaStorage;
|
||||
|
||||
// Commandes Pala : /end /overworld (permission niveau 4, legacy), /nether (gate metier
|
||||
// mineur niv.3, M0), /pala reload|info|rank (admin), /jobs (metiers). Voir CDC §3.8.
|
||||
// mineur niv.3, M0), /pala reload|info|rank (admin), /jobs (metiers), /craft (table de
|
||||
// craft portable, wiki commandes), /spawn (tp spawn overworld, delai 3 s sans grade, wiki).
|
||||
// Voir CDC §3.8.
|
||||
// Origine : CommandEnd/Nether/Overworld + procedures *CommandExecuted qui
|
||||
// teleportaient le joueur au spawn de la dimension visee. Ici via
|
||||
// TeleportTransition (API 26.x), sans le Teleporter custom du legacy.
|
||||
public final class PalaCommands {
|
||||
|
||||
// M-cmd-util : /spawn differe (delai wiki 3 s = 60 ticks). UUID -> tick d'execution.
|
||||
private static final java.util.Map<java.util.UUID, Long> SPAWN_QUEUE = new java.util.HashMap<>();
|
||||
|
||||
private PalaCommands() {
|
||||
}
|
||||
|
||||
@@ -69,6 +74,12 @@ public final class PalaCommands {
|
||||
.then(joueurArg)));
|
||||
dispatcher.register(Commands.literal("jobs")
|
||||
.executes(command -> jobs(command.getSource())));
|
||||
dispatcher.register(Commands.literal("craft")
|
||||
.executes(command -> craft(command.getSource())));
|
||||
dispatcher.register(Commands.literal("spawn")
|
||||
.executes(command -> spawn(command.getSource())));
|
||||
net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents.END_SERVER_TICK
|
||||
.register(PalaCommands::tickSpawnQueue);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -204,14 +215,69 @@ public final class PalaCommands {
|
||||
} else {
|
||||
spawn = target.getRespawnData().pos();
|
||||
}
|
||||
Vec3 pos = new Vec3(spawn.getX() + 0.5, spawn.getY() + 1.0, spawn.getZ() + 0.5);
|
||||
player.teleport(new TeleportTransition(target, pos, Vec3.ZERO, player.getYRot(), player.getXRot(),
|
||||
TeleportTransition.DO_NOTHING));
|
||||
target.playSound(null, pos.x(), pos.y(), pos.z(), SoundEvents.ENDERMAN_TELEPORT,
|
||||
SoundSource.NEUTRAL, 1.0F, 1.0F);
|
||||
teleportPlayer(player, target, spawn);
|
||||
return Command.SINGLE_SUCCESS;
|
||||
} catch (com.mojang.brigadier.exceptions.CommandSyntaxException e) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
private static void teleportPlayer(ServerPlayer player, ServerLevel target, BlockPos spawn) {
|
||||
Vec3 pos = new Vec3(spawn.getX() + 0.5, spawn.getY() + 1.0, spawn.getZ() + 0.5);
|
||||
player.teleport(new TeleportTransition(target, pos, Vec3.ZERO, player.getYRot(), player.getXRot(),
|
||||
TeleportTransition.DO_NOTHING));
|
||||
target.playSound(null, pos.x(), pos.y(), pos.z(), SoundEvents.ENDERMAN_TELEPORT,
|
||||
SoundSource.NEUTRAL, 1.0F, 1.0F);
|
||||
}
|
||||
|
||||
// /craft : table de craft portable (wiki commandes).
|
||||
private static int craft(CommandSourceStack source) {
|
||||
try {
|
||||
ServerPlayer player = source.getPlayerOrException();
|
||||
player.openMenu(new net.minecraft.world.SimpleMenuProvider(
|
||||
(syncId, inventory, p) -> new net.minecraft.world.inventory.CraftingMenu(syncId,
|
||||
inventory),
|
||||
Component.translatable("container.crafting")));
|
||||
return Command.SINGLE_SUCCESS;
|
||||
} catch (com.mojang.brigadier.exceptions.CommandSyntaxException e) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
// /spawn : tp au spawn overworld avec delai wiki 3 s (60 ticks). Pas d'annulation sur
|
||||
// mouvement cote wiki (teleportation simple apres delai).
|
||||
private static int spawn(CommandSourceStack source) {
|
||||
try {
|
||||
ServerPlayer player = source.getPlayerOrException();
|
||||
MinecraftServer server = source.getServer();
|
||||
SPAWN_QUEUE.put(player.getUUID(), (long) server.getTickCount() + 60L);
|
||||
player.sendSystemMessage(
|
||||
Component.literal("§6[Pala] §7Teleportation dans 3 secondes..."));
|
||||
return Command.SINGLE_SUCCESS;
|
||||
} catch (com.mojang.brigadier.exceptions.CommandSyntaxException e) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
private static void tickSpawnQueue(MinecraftServer server) {
|
||||
if (SPAWN_QUEUE.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
int now = server.getTickCount();
|
||||
java.util.Iterator<java.util.Map.Entry<java.util.UUID, Long>> it =
|
||||
SPAWN_QUEUE.entrySet().iterator();
|
||||
while (it.hasNext()) {
|
||||
java.util.Map.Entry<java.util.UUID, Long> entry = it.next();
|
||||
if (now < entry.getValue()) {
|
||||
continue;
|
||||
}
|
||||
it.remove();
|
||||
ServerPlayer player = server.getPlayerList().getPlayer(entry.getKey());
|
||||
if (player == null) {
|
||||
continue;
|
||||
}
|
||||
ServerLevel overworld = server.overworld();
|
||||
teleportPlayer(player, overworld, overworld.getRespawnData().pos());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user