Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ Want to teleport to where you died? Enable `allow_back_on_death` in the [config]
- /top
- /day
- /gametime
- /strike

### Config

Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/fibermc/essentialcommands/ECPerms.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ public static final class Registry {
public static final String near_self = "essentialcommands.near.self";
public static final String near_others = "essentialcommands.near.others";
public static final String motd = "essentialcommands.motd";
public static final String strike = "essentialcommands.strike";

public static final class Group {
public static final String[] tpa_group = {tpa, tpahere, tpaccept, tpdeny};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -573,6 +573,16 @@ public static void register(
.build());
}

if (CONFIG.ENABLE_STRIKE) {
registerNode.accept(CommandManager.literal("strike")
.requires(ECPerms.require(ECPerms.Registry.strike, 2))
.executes(new StrikeCommand())
.then(CommandUtil.targetPlayerArgument()
.executes(new StrikeCommand())
)
.build());
}

var profileNode = ProfileCommand.buildNode();
essentialCommandsRootNode.addChild(profileNode);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package com.fibermc.essentialcommands.commands;

import java.util.Objects;

import com.fibermc.essentialcommands.access.ServerPlayerEntityAccess;
import com.fibermc.essentialcommands.playerdata.PlayerData;

import com.mojang.brigadier.Command;
import com.mojang.brigadier.context.CommandContext;
import com.mojang.brigadier.exceptions.CommandSyntaxException;

import net.minecraft.entity.EntityType;
import net.minecraft.entity.LightningEntity;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.server.network.ServerPlayerEntity;

public class StrikeCommand implements Command<ServerCommandSource> {

public StrikeCommand() {
}

@Override
public int run(CommandContext<ServerCommandSource> context) throws CommandSyntaxException {
ServerCommandSource source = context.getSource();
ServerPlayerEntity targetPlayer = CommandUtil.getCommandTargetPlayer(context);

//Tries to spawn a LightningBolt entity at the target player location
LightningEntity lightningEntity = new LightningEntity(EntityType.LIGHTNING_BOLT, targetPlayer.getServerWorld());
//TODO what's lightningEntity.setCosmetic(); ?
lightningEntity.setPos(targetPlayer.getX(), targetPlayer.getY(), targetPlayer.getZ());

exec(source, targetPlayer, lightningEntity);
return 0;
}

public static void exec(ServerCommandSource source, ServerPlayerEntity target, LightningEntity entity) throws CommandSyntaxException {

PlayerData playerData = ((ServerPlayerEntityAccess) target).ec$getPlayerData();

target.sendAbilitiesUpdate();
target.getWorld().spawnEntity(entity);

var senderPlayer = source.getPlayerOrThrow();
var senderPlayerData = PlayerData.access(senderPlayer);

if (!Objects.equals(senderPlayer, target)) {
senderPlayerData.sendCommandFeedback(
"cmd.strike.feedback",
target.getDisplayName());
}
playerData.sendCommandFeedback(
"cmd.strike.feedback",
target.getDisplayName()
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ public final class EssentialCommandsConfig extends Config<EssentialCommandsConfi
@ConfigOption public final Option<Integer> NEAR_COMMAND_DEFAULT_RADIUS = new Option<>("near_command_default_radius", 200, ConfigUtil::parseInt);
@ConfigOption public final Option<Integer> NEAR_COMMAND_MAX_RADIUS = new Option<>("near_command_max_radius", 200, ConfigUtil::parseInt);
@ConfigOption public final Option<Boolean> PRINT_TELEPORT_COORDINATES = new Option<>("print_teleport_coordinates", true, Boolean::parseBoolean);
@ConfigOption public final Option<Boolean> ENABLE_STRIKE = new Option<>("enable_strike", true, Boolean::parseBoolean);

public EssentialCommandsConfig(Path savePath, String displayName, String documentationLink) {
super(savePath, displayName, documentationLink);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ public final class EssentialCommandsConfigSnapshot {
public final int NEAR_COMMAND_DEFAULT_RADIUS;
public final int NEAR_COMMAND_MAX_RADIUS;
public final boolean PRINT_TELEPORT_COORDINATES;
public final boolean ENABLE_STRIKE;

private EssentialCommandsConfigSnapshot(EssentialCommandsConfig config) {
this.FORMATTING_DEFAULT = config.FORMATTING_DEFAULT.getValue();
Expand Down Expand Up @@ -160,6 +161,7 @@ private EssentialCommandsConfigSnapshot(EssentialCommandsConfig config) {
this.NEAR_COMMAND_DEFAULT_RADIUS = config.NEAR_COMMAND_DEFAULT_RADIUS.getValue();
this.NEAR_COMMAND_MAX_RADIUS = config.NEAR_COMMAND_MAX_RADIUS.getValue();
this.PRINT_TELEPORT_COORDINATES = config.PRINT_TELEPORT_COORDINATES.getValue();
this.ENABLE_STRIKE = config.ENABLE_STRIKE.getValue();
}

public static EssentialCommandsConfigSnapshot create(EssentialCommandsConfig config) {
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/assets/essential_commands/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@
"cmd.list.feedback.empty": "No locations found.",
"cmd.top.location_name": "world surface",

"cmd.strike.feedback": "Summoned a new Lightning Bolt on ${0}.",

"player.afk.enter": "${0} is now AFK.",
"player.afk.exit": "${0} is no longer AFK.",

Expand Down