pala M-homes-1: homes personnels (/sethome /home /delhome /homes)
This commit is contained in:
@@ -96,6 +96,17 @@ public final class PalaCommands {
|
||||
.executes(command -> minage(command.getSource())));
|
||||
dispatcher.register(Commands.literal("farmland")
|
||||
.executes(command -> farmland(command.getSource())));
|
||||
dispatcher.register(Commands.literal("sethome")
|
||||
.then(Commands.argument("nom", com.mojang.brigadier.arguments.StringArgumentType.word())
|
||||
.executes(command -> setHome(command.getSource(), command))));
|
||||
dispatcher.register(Commands.literal("home")
|
||||
.then(Commands.argument("nom", com.mojang.brigadier.arguments.StringArgumentType.word())
|
||||
.executes(command -> goHome(command.getSource(), command))));
|
||||
dispatcher.register(Commands.literal("delhome")
|
||||
.then(Commands.argument("nom", com.mojang.brigadier.arguments.StringArgumentType.word())
|
||||
.executes(command -> delHome(command.getSource(), command))));
|
||||
dispatcher.register(Commands.literal("homes")
|
||||
.executes(command -> listHomes(command.getSource())));
|
||||
dispatcher.register(Commands.literal("tpa")
|
||||
.then(Commands.argument("cible", EntityArgument.player())
|
||||
.executes(command -> tpa(command.getSource(),
|
||||
@@ -1139,6 +1150,91 @@ public final class PalaCommands {
|
||||
}
|
||||
}
|
||||
|
||||
// M-homes-1 (wiki grades) : homes personnels /sethome /home /delhome /homes.
|
||||
private static int setHome(CommandSourceStack source,
|
||||
com.mojang.brigadier.context.CommandContext<CommandSourceStack> ctx) {
|
||||
try {
|
||||
ServerPlayer player = source.getPlayerOrException();
|
||||
String name = com.mojang.brigadier.arguments.StringArgumentType
|
||||
.getString(ctx, "nom").toLowerCase(java.util.Locale.ROOT);
|
||||
fr.surviepote.pala.core.PalaStorage store =
|
||||
fr.surviepote.pala.core.PalaStorage.get();
|
||||
fr.surviepote.pala.core.PalaStorage.PlayerData data =
|
||||
store.data(player.getUUID());
|
||||
int max = fr.surviepote.pala.core.PalaConfig.get().maxHomesBase;
|
||||
if (!data.homes.containsKey(name) && data.homes.size() >= max) {
|
||||
source.sendFailure(Component.literal(
|
||||
"§cLimite de homes atteinte (" + max + ")."));
|
||||
return 0;
|
||||
}
|
||||
data.homes.put(name, player.level().dimension().identifier()
|
||||
+ ":" + player.blockPosition().getX()
|
||||
+ ":" + player.blockPosition().getY()
|
||||
+ ":" + player.blockPosition().getZ());
|
||||
store.markDirty();
|
||||
source.sendSuccess(() -> Component.literal("§aHome '" + name + "' defini."), false);
|
||||
return Command.SINGLE_SUCCESS;
|
||||
} catch (com.mojang.brigadier.exceptions.CommandSyntaxException e) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
private static int goHome(CommandSourceStack source,
|
||||
com.mojang.brigadier.context.CommandContext<CommandSourceStack> ctx) {
|
||||
try {
|
||||
ServerPlayer player = source.getPlayerOrException();
|
||||
String name = com.mojang.brigadier.arguments.StringArgumentType
|
||||
.getString(ctx, "nom").toLowerCase(java.util.Locale.ROOT);
|
||||
String zone = fr.surviepote.pala.core.PalaStorage.get()
|
||||
.data(player.getUUID()).homes.get(name);
|
||||
if (zone == null) {
|
||||
source.sendFailure(Component.literal(
|
||||
"§cHome inconnu (liste : /homes)."));
|
||||
return 0;
|
||||
}
|
||||
return zoneTeleport(source, zone, "Home");
|
||||
} catch (com.mojang.brigadier.exceptions.CommandSyntaxException e) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
private static int delHome(CommandSourceStack source,
|
||||
com.mojang.brigadier.context.CommandContext<CommandSourceStack> ctx) {
|
||||
try {
|
||||
ServerPlayer player = source.getPlayerOrException();
|
||||
String name = com.mojang.brigadier.arguments.StringArgumentType
|
||||
.getString(ctx, "nom").toLowerCase(java.util.Locale.ROOT);
|
||||
fr.surviepote.pala.core.PalaStorage store =
|
||||
fr.surviepote.pala.core.PalaStorage.get();
|
||||
if (store.data(player.getUUID()).homes.remove(name) == null) {
|
||||
source.sendFailure(Component.literal("§cHome inconnu."));
|
||||
return 0;
|
||||
}
|
||||
store.markDirty();
|
||||
source.sendSuccess(() -> Component.literal("§aHome '" + name + "' supprime."), false);
|
||||
return Command.SINGLE_SUCCESS;
|
||||
} catch (com.mojang.brigadier.exceptions.CommandSyntaxException e) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
private static int listHomes(CommandSourceStack source) {
|
||||
try {
|
||||
ServerPlayer player = source.getPlayerOrException();
|
||||
java.util.Map<String, String> homes = fr.surviepote.pala.core.PalaStorage.get()
|
||||
.data(player.getUUID()).homes;
|
||||
if (homes.isEmpty()) {
|
||||
source.sendSuccess(() -> Component.literal("§7Aucun home (/sethome <nom>)."), false);
|
||||
} else {
|
||||
source.sendSuccess(() -> Component.literal(
|
||||
"§6[Homes] §7" + String.join(", ", homes.keySet())), false);
|
||||
}
|
||||
return Command.SINGLE_SUCCESS;
|
||||
} catch (com.mojang.brigadier.exceptions.CommandSyntaxException e) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
private static int fDisband(CommandSourceStack source) {
|
||||
try {
|
||||
ServerPlayer player = source.getPlayerOrException();
|
||||
|
||||
@@ -96,6 +96,10 @@ public final class PalaConfig {
|
||||
public String miningZone = "";
|
||||
public String farmlandZone = "";
|
||||
|
||||
// M-homes-1 (wiki grades : homes multiples) : homes personnels max (base, ECART :
|
||||
// base non publiee, configurable ; grades payants boutique externe SKIP).
|
||||
public int maxHomesBase = 3;
|
||||
|
||||
// M-rtp (wiki commandes) : cooldown minutes entre deux /rtp (wiki : 15).
|
||||
public int rtpCooldownMinutes = 15;
|
||||
// Rayon max du /rtp autour du spawn (blocs). UNVERIFIED (wiki : "aleatoire", sans borne).
|
||||
@@ -252,7 +256,7 @@ public final class PalaConfig {
|
||||
"serverName", "wikiUrl", "discordUrl", "shopUrl",
|
||||
"afkKickMinutes", "rtpCooldownMinutes", "rtpRadius",
|
||||
"factionMaxClaims", "marketExpiryDays",
|
||||
"miningZone", "farmlandZone");
|
||||
"miningZone", "farmlandZone", "maxHomesBase");
|
||||
boolean complete = true;
|
||||
try (Reader keysReader = Files.newBufferedReader(path)) {
|
||||
com.google.gson.JsonObject obj =
|
||||
|
||||
@@ -37,8 +37,11 @@ public final class PalaStorage {
|
||||
public Map<String, JobData> jobs = new HashMap<>();
|
||||
public String rank = "default";
|
||||
public double money = 0.0;
|
||||
// M-homes-1 : homes personnels (nom -> "dimension:x:y:z").
|
||||
public Map<String, String> homes = new HashMap<>();
|
||||
}
|
||||
|
||||
|
||||
private final Map<String, PlayerData> players = new HashMap<>();
|
||||
private boolean dirty = false;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user