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;
}
}
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;
}
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();
}
}
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);
}
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;
}
Aggregations