Search in sources :

Example 1 with PlayerData

use of com.fibermc.essentialcommands.PlayerData in project Essential-Commands by John-Paul-R.

the class TeleportDenyCommand method exec.

protected int exec(CommandContext<ServerCommandSource> context, ServerPlayerEntity senderPlayer, ServerPlayerEntity targetPlayer) {
    ServerCommandSource source = context.getSource();
    PlayerData targetPlayerData = ((ServerPlayerEntityAccess) targetPlayer).getEcPlayerData();
    // identify if target player did indeed request to teleport. Continue if so, otherwise throw exception.
    TeleportRequest teleportRequest = targetPlayerData.getSentTeleportRequest();
    if (teleportRequest != null && teleportRequest.getTargetPlayer().equals(senderPlayer)) {
        // inform target player that teleport has been accepted via chat
        targetPlayer.sendSystemMessage(ECText.getInstance().getText("cmd.tpdeny.feedback").setStyle(CONFIG.FORMATTING_DEFAULT.getValue()), Util.NIL_UUID);
        // Send message to command sender confirming that request has been accepted
        source.sendFeedback(ECText.getInstance().getText("cmd.tpdeny.feedback").setStyle(CONFIG.FORMATTING_DEFAULT.getValue()), CONFIG.BROADCAST_TO_OPS.getValue());
        // Clean up TPAsk
        targetPlayerData.setTpTimer(-1);
        // Remove the tp request, as it has been completed.
        TeleportRequestManager.getInstance().endTpRequest(teleportRequest);
        return 1;
    } else {
        source.sendError(ECText.getInstance().getText("cmd.tpa_reply.error.no_request_from_target").setStyle(CONFIG.FORMATTING_ERROR.getValue()));
        return -1;
    }
}
Also used : PlayerData(com.fibermc.essentialcommands.PlayerData) ServerCommandSource(net.minecraft.server.command.ServerCommandSource) ServerPlayerEntityAccess(com.fibermc.essentialcommands.access.ServerPlayerEntityAccess) TeleportRequest(com.fibermc.essentialcommands.TeleportRequest)

Example 2 with PlayerData

use of com.fibermc.essentialcommands.PlayerData in project Essential-Commands by John-Paul-R.

the class HomeSetCommand method run.

@Override
public int run(CommandContext<ServerCommandSource> context) throws CommandSyntaxException {
    ServerCommandSource source = context.getSource();
    // Store command sender
    ServerPlayerEntity senderPlayer = source.getPlayer();
    // Store home name
    String homeName = StringArgumentType.getString(context, "home_name");
    // Add home to PlayerData
    // TODO if home with given name is already set, warn of overwrite and require that the command be typed again, or a confirmation message be given
    PlayerData pData = ((ServerPlayerEntityAccess) senderPlayer).getEcPlayerData();
    int successCode = 0;
    try {
        successCode = pData.addHome(homeName, new MinecraftLocation(senderPlayer));
    } catch (CommandSyntaxException e) {
        source.sendError(TextUtil.concat(ECText.getInstance().getText("cmd.home.feedback.1").setStyle(CONFIG.FORMATTING_ERROR.getValue()), new LiteralText(homeName).setStyle(CONFIG.FORMATTING_ACCENT.getValue()), ECText.getInstance().getText("cmd.home.set.error.exists.2").setStyle(CONFIG.FORMATTING_ERROR.getValue())));
    }
    pData.markDirty();
    pData.save();
    // inform command sender that the home has been set
    if (successCode == 1) {
        source.sendFeedback(ECText.getInstance().getText("cmd.home.feedback.1").setStyle(CONFIG.FORMATTING_DEFAULT.getValue()).append(new LiteralText(homeName).setStyle(CONFIG.FORMATTING_ACCENT.getValue())).append(ECText.getInstance().getText("cmd.home.set.feedback.2").setStyle(CONFIG.FORMATTING_DEFAULT.getValue())), CONFIG.BROADCAST_TO_OPS.getValue());
    }
    return successCode;
}
Also used : MinecraftLocation(com.fibermc.essentialcommands.types.MinecraftLocation) ServerPlayerEntity(net.minecraft.server.network.ServerPlayerEntity) PlayerData(com.fibermc.essentialcommands.PlayerData) CommandSyntaxException(com.mojang.brigadier.exceptions.CommandSyntaxException) ServerCommandSource(net.minecraft.server.command.ServerCommandSource) ServerPlayerEntityAccess(com.fibermc.essentialcommands.access.ServerPlayerEntityAccess) LiteralText(net.minecraft.text.LiteralText)

Example 3 with PlayerData

use of com.fibermc.essentialcommands.PlayerData in project Essential-Commands by John-Paul-R.

the class EssentialsXParser method convertPlayerDataDir.

public static void convertPlayerDataDir(File sourceDir, File targetDir, MinecraftServer server) throws NotDirectoryException, FileNotFoundException {
    if (!sourceDir.exists()) {
        throw new FileNotFoundException(sourceDir.getAbsolutePath() + " does not exist!");
    }
    if (!sourceDir.isDirectory()) {
        throw new NotDirectoryException(sourceDir.getAbsolutePath() + " is not a directory!");
    }
    var worldUuidRegistryKeyMap = getWorldUids(server);
    targetDir.mkdir();
    // Existing EC player data files
    Path targetPath = targetDir.toPath();
    File[] playerDataFiles = Objects.requireNonNull(sourceDir.listFiles());
    for (File file : playerDataFiles) {
        NamedLocationStorage homes = parsePlayerHomes(file, server, worldUuidRegistryKeyMap);
        // WARN: Currently, this will still overwrite player's new homes with EssentialsX homes.
        String targetFilePathStr = targetPath.resolve(file.getName()).toString();
        targetFilePathStr = targetFilePathStr.substring(0, targetFilePathStr.indexOf(".yml")) + ".dat";
        File targetFile = new File(targetFilePathStr);
        PlayerData playerData = PlayerDataFactory.create(homes, targetFile);
        playerData.save();
    }
}
Also used : Path(java.nio.file.Path) NotDirectoryException(java.nio.file.NotDirectoryException) NamedLocationStorage(com.fibermc.essentialcommands.NamedLocationStorage) FileNotFoundException(java.io.FileNotFoundException) File(java.io.File) PlayerData(com.fibermc.essentialcommands.PlayerData)

Example 4 with PlayerData

use of com.fibermc.essentialcommands.PlayerData in project Essential-Commands by John-Paul-R.

the class TeleportResponseCommand method runDefault.

public int runDefault(CommandContext<ServerCommandSource> context) throws CommandSyntaxException {
    ServerPlayerEntity senderPlayer = context.getSource().getPlayer();
    PlayerData senderPlayerData = ((ServerPlayerEntityAccess) senderPlayer).getEcPlayerData();
    LinkedHashMap<UUID, TeleportRequest> incomingTeleportRequests = senderPlayerData.getIncomingTeleportRequests();
    ServerPlayerEntity targetPlayer;
    if (incomingTeleportRequests.size() > 1) {
        throw CommandUtil.createSimpleException(ECText.getInstance().getText("cmd.tpa_reply.error.shortcut_more_than_one"));
    } else if (incomingTeleportRequests.size() < 1) {
        throw CommandUtil.createSimpleException(ECText.getInstance().getText("cmd.tpa_reply.error.shortcut_none_exist"));
    } else {
        targetPlayer = incomingTeleportRequests.values().stream().findFirst().get().getTargetPlayer();
        if (targetPlayer == null) {
            throw CommandUtil.createSimpleException(ECText.getInstance().getText("cmd.tpa_reply.error.no_request_from_target"));
        }
    }
    return exec(context, senderPlayer, targetPlayer);
}
Also used : ServerPlayerEntity(net.minecraft.server.network.ServerPlayerEntity) UUID(java.util.UUID) PlayerData(com.fibermc.essentialcommands.PlayerData) ServerPlayerEntityAccess(com.fibermc.essentialcommands.access.ServerPlayerEntityAccess) TeleportRequest(com.fibermc.essentialcommands.TeleportRequest)

Example 5 with PlayerData

use of com.fibermc.essentialcommands.PlayerData in project Essential-Commands by John-Paul-R.

the class RealNameCommand method run.

@Override
public int run(CommandContext<ServerCommandSource> context) throws CommandSyntaxException {
    String nicknameStr = StringArgumentType.getString(context, "player_nickname");
    List<PlayerData> nicknamePlayers = PlayerDataManager.getInstance().getPlayerDataMatchingNickname(nicknameStr);
    MutableText responseText = new LiteralText("");
    // If no players matched the provided nickname
    if (nicknamePlayers.size() == 0) {
        responseText.append(ECText.getInstance().getText("cmd.realname.feedback.none_match").setStyle(CONFIG.FORMATTING_DEFAULT.getValue())).append(new LiteralText(nicknameStr).setStyle(CONFIG.FORMATTING_ACCENT.getValue())).append(ECText.getInstance().getText("generic.quote_fullstop").setStyle(CONFIG.FORMATTING_DEFAULT.getValue()));
    } else {
        responseText.append(ECText.getInstance().getText("cmd.realname.feedback.matching.1").setStyle(CONFIG.FORMATTING_DEFAULT.getValue())).append(new LiteralText(nicknameStr).setStyle(CONFIG.FORMATTING_ACCENT.getValue())).append(ECText.getInstance().getText("cmd.realname.feedback.matching.2").setStyle(CONFIG.FORMATTING_DEFAULT.getValue()));
        for (PlayerData nicknamePlayer : nicknamePlayers) {
            responseText.append("\n  ");
            responseText.append(nicknamePlayer.getPlayer().getGameProfile().getName());
        }
    }
    context.getSource().sendFeedback(responseText, CONFIG.BROADCAST_TO_OPS.getValue());
    return 0;
}
Also used : MutableText(net.minecraft.text.MutableText) PlayerData(com.fibermc.essentialcommands.PlayerData) LiteralText(net.minecraft.text.LiteralText)

Aggregations

PlayerData (com.fibermc.essentialcommands.PlayerData)11 ServerPlayerEntityAccess (com.fibermc.essentialcommands.access.ServerPlayerEntityAccess)9 ServerPlayerEntity (net.minecraft.server.network.ServerPlayerEntity)5 ServerCommandSource (net.minecraft.server.command.ServerCommandSource)4 LiteralText (net.minecraft.text.LiteralText)4 TeleportRequest (com.fibermc.essentialcommands.TeleportRequest)3 MinecraftLocation (com.fibermc.essentialcommands.types.MinecraftLocation)2 NamedLocationStorage (com.fibermc.essentialcommands.NamedLocationStorage)1 CommandSyntaxException (com.mojang.brigadier.exceptions.CommandSyntaxException)1 File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1 NotDirectoryException (java.nio.file.NotDirectoryException)1 Path (java.nio.file.Path)1 UUID (java.util.UUID)1 PlayerAbilities (net.minecraft.entity.player.PlayerAbilities)1 MutableText (net.minecraft.text.MutableText)1