feat(release): v0.2.0
Added /suicide command with confirmation mechanism, interactive clickable message, and proper chat/console handling on player death.
This commit is contained in:
parent
c6d7c845a2
commit
7e622a5761
|
@ -4,6 +4,16 @@
|
|||
|
||||
Формат основан на [Keep a Changelog](https://keepachangelog.com/ru/1.0.0/), и проект соответствует [Семантическому Версионированию](https://semver.org/lang/ru/).
|
||||
|
||||
## [0.2] - 2024-11-13
|
||||
|
||||
### Добавлено
|
||||
|
||||
- **PlayerActions**:
|
||||
- **Команда самоубийства**:
|
||||
- Добавлена команда `/suicide`, которая запрашивает подтверждение перед выполнением.
|
||||
- Игроки могут подтвердить действие, нажав на интерактивное сообщение или введя `/suicide confirm`.
|
||||
- После подтверждения игрок мгновенно умирает, а окно чата или консоли закрывается для предотвращения дальнейшего взаимодействия.
|
||||
|
||||
## [0.1] - 2024-11-10
|
||||
|
||||
### Добавлено
|
||||
|
|
10
CHANGELOG.md
10
CHANGELOG.md
|
@ -4,6 +4,16 @@ All notable changes to this project will be documented in this file.
|
|||
|
||||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/).
|
||||
|
||||
## [0.2] - 2024-11-13
|
||||
|
||||
### Added
|
||||
|
||||
- **PlayerActions**:
|
||||
- **Suicide Command**:
|
||||
- Added a `/suicide` command that prompts players for confirmation before execution.
|
||||
- Players can confirm by clicking on the generated clickable message or typing `/suicide confirm`.
|
||||
- Upon confirmation, the player dies instantly, and the chat window or console is closed to prevent further interaction.
|
||||
|
||||
## [0.1] - 2024-11-10
|
||||
|
||||
### Added
|
||||
|
|
|
@ -38,7 +38,7 @@ mod_name=HubMcUtils
|
|||
# The license of the mod. Review your options at https://choosealicense.com/. All Rights Reserved is the default.
|
||||
mod_license=All Rights Reserved
|
||||
# The mod version. See https://semver.org/
|
||||
mod_version=0.1-BETA
|
||||
mod_version=0.2.0-BETA
|
||||
# The group ID for the mod. It is only important when publishing as an artifact to a Maven repository.
|
||||
# This should match the base package used for the mod sources.
|
||||
# See https://maven.apache.org/guides/mini/guide-naming-conventions.html
|
||||
|
|
|
@ -8,6 +8,8 @@ import net.minecraftforge.eventbus.api.SubscribeEvent;
|
|||
import net.minecraftforge.fml.common.Mod;
|
||||
import org.slf4j.Logger;
|
||||
|
||||
import org.itqop.hubmcutils.command.CommandHandler;
|
||||
|
||||
@Mod(HubMcUtils.MODID)
|
||||
public class HubMcUtils {
|
||||
|
||||
|
@ -16,6 +18,7 @@ public class HubMcUtils {
|
|||
|
||||
public HubMcUtils() {
|
||||
MinecraftForge.EVENT_BUS.register(this);
|
||||
MinecraftForge.EVENT_BUS.register(CommandHandler.class);
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
package org.itqop.hubmcutils.command;
|
||||
|
||||
import com.mojang.brigadier.CommandDispatcher;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
import net.minecraftforge.event.RegisterCommandsEvent;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import org.itqop.hubmcutils.command.list.PlayerActions;
|
||||
|
||||
public class CommandHandler {
|
||||
|
||||
@SubscribeEvent
|
||||
public static void onRegisterCommands(RegisterCommandsEvent event) {
|
||||
CommandDispatcher<CommandSourceStack> dispatcher = event.getDispatcher();
|
||||
PlayerActions.registerCommands(dispatcher);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,56 @@
|
|||
package org.itqop.hubmcutils.command.list;
|
||||
|
||||
import com.mojang.brigadier.Command;
|
||||
import com.mojang.brigadier.CommandDispatcher;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
import net.minecraft.commands.Commands;
|
||||
import net.minecraft.network.chat.ClickEvent;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.chat.HoverEvent;
|
||||
import net.minecraft.network.chat.Style;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
public class PlayerActions {
|
||||
|
||||
private static final Set<String> pendingConfirmation = new HashSet<>();
|
||||
|
||||
public static void registerCommands(CommandDispatcher<CommandSourceStack> dispatcher) {
|
||||
dispatcher.register(Commands.literal("suicide")
|
||||
.executes(context -> {
|
||||
ServerPlayer player = context.getSource().getPlayerOrException();
|
||||
String playerName = player.getName().getString();
|
||||
|
||||
pendingConfirmation.add(playerName);
|
||||
|
||||
Component confirmMessage = Component.literal("[Нажмите здесь, чтобы подтвердить]")
|
||||
.withStyle(Style.EMPTY
|
||||
.withColor(0xFF5555) // Красный цвет
|
||||
.withClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/suicide confirm"))
|
||||
.withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, Component.literal("Подтвердите команду /suicide confirm"))));
|
||||
|
||||
player.sendSystemMessage(Component.literal("Вы уверены, что хотите покончить с собой? ").append(confirmMessage));
|
||||
return Command.SINGLE_SUCCESS;
|
||||
})
|
||||
.then(Commands.literal("confirm")
|
||||
.executes(context -> {
|
||||
ServerPlayer player = context.getSource().getPlayerOrException();
|
||||
String playerName = player.getName().getString();
|
||||
|
||||
if (pendingConfirmation.contains(playerName)) {
|
||||
pendingConfirmation.remove(playerName);
|
||||
player.sendSystemMessage(Component.literal("Вы приняли решение покончить с собой.").withStyle(Style.EMPTY.withColor(0xFF5555)));
|
||||
player.setHealth(0.0F); // Устанавливаем здоровье игрока на 0 для мгновенной смерти
|
||||
player.closeContainer(); // Закрываем окно чата или инвентаря
|
||||
return Command.SINGLE_SUCCESS;
|
||||
} else {
|
||||
player.sendSystemMessage(Component.literal("Сначала используйте команду /suicide, чтобы запросить подтверждение.").withStyle(Style.EMPTY.withColor(0xFFFF55))); // Желтый цвет
|
||||
return Command.SINGLE_SUCCESS;
|
||||
}
|
||||
})
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue