add ability to name claims
This commit is contained in:
parent
b1eff37fa2
commit
0d3aa8f3a8
@ -16,7 +16,6 @@ import io.github.flemmli97.flan.player.PlayerClaimData;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.text.LiteralText;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import net.minecraft.util.Formatting;
|
||||
@ -39,7 +38,7 @@ public class Claim implements IPermissionContainer {
|
||||
private UUID owner;
|
||||
|
||||
private UUID claimID;
|
||||
private LiteralText claimName;
|
||||
private String claimName = "";
|
||||
private final Map<ClaimPermission, Boolean> globalPerm = new HashMap<>();
|
||||
private final Map<String, Map<ClaimPermission, Boolean>> permissions = new HashMap<>();
|
||||
|
||||
@ -108,11 +107,11 @@ public class Claim implements IPermissionContainer {
|
||||
return this.claimID;
|
||||
}
|
||||
|
||||
public LiteralText getClaimName() {
|
||||
public String getClaimName() {
|
||||
return this.claimName;
|
||||
}
|
||||
|
||||
public void setClaimName(LiteralText name) {
|
||||
public void setClaimName(String name) {
|
||||
this.claimName = name;
|
||||
this.setDirty(true);
|
||||
}
|
||||
@ -460,6 +459,7 @@ public class Claim implements IPermissionContainer {
|
||||
|
||||
public void readJson(JsonObject obj, UUID uuid) {
|
||||
this.claimID = UUID.fromString(obj.get("ID").getAsString());
|
||||
this.claimName = obj.get("Name").getAsString();
|
||||
JsonArray pos = obj.getAsJsonArray("PosxXzZY");
|
||||
this.minX = pos.get(0).getAsInt();
|
||||
this.maxX = pos.get(1).getAsInt();
|
||||
@ -520,6 +520,7 @@ public class Claim implements IPermissionContainer {
|
||||
|
||||
public JsonObject toJson(JsonObject obj) {
|
||||
obj.addProperty("ID", this.claimID.toString());
|
||||
obj.addProperty("Name", this.claimName);
|
||||
JsonArray pos = new JsonArray();
|
||||
pos.add(this.minX);
|
||||
pos.add(this.maxX);
|
||||
@ -590,7 +591,9 @@ public class Claim implements IPermissionContainer {
|
||||
}
|
||||
|
||||
public String formattedClaim() {
|
||||
if (this.claimName.isEmpty())
|
||||
return String.format("[x=%d,z=%d] - [x=%d,z=%d]", this.minX, this.minZ, this.maxX, this.maxZ);
|
||||
return String.format("%s:[x=%d,z=%d] - [x=%d,z=%d]", this.claimName, this.minX, this.minZ, this.maxX, this.maxZ);
|
||||
}
|
||||
|
||||
public List<Text> infoString(ServerPlayerEntity player) {
|
||||
|
@ -55,6 +55,7 @@ public class CommandClaim {
|
||||
.then(CommandManager.literal("addClaim").requires(src -> CommandPermission.perm(src, CommandPermission.claimCreate)).then(CommandManager.argument("from", BlockPosArgumentType.blockPos()).then(CommandManager.argument("to", BlockPosArgumentType.blockPos()).executes(CommandClaim::addClaim))))
|
||||
.then(CommandManager.literal("menu").requires(src -> CommandPermission.perm(src, CommandPermission.cmdMenu)).executes(CommandClaim::openMenu))
|
||||
.then(CommandManager.literal("trapped").requires(src -> CommandPermission.perm(src, CommandPermission.cmdTrapped)).executes(CommandClaim::trapped))
|
||||
.then(CommandManager.literal("name").requires(src -> CommandPermission.perm(src, CommandPermission.cmdName)).then(CommandManager.argument("name", StringArgumentType.string()).executes(CommandClaim::nameClaim)))
|
||||
.then(CommandManager.literal("unlockDrops").executes(CommandClaim::unlockDrops)
|
||||
.then(CommandManager.argument("players", GameProfileArgumentType.gameProfile()).requires(src -> CommandPermission.perm(src, CommandPermission.cmdUnlockAll, true)).executes(CommandClaim::unlockDropsPlayers)))
|
||||
.then(CommandManager.literal("personalGroups").requires(src -> CommandPermission.perm(src, CommandPermission.cmdPGroup)).executes(CommandClaim::openPersonalGroups))
|
||||
@ -207,6 +208,51 @@ public class CommandClaim {
|
||||
return 0;
|
||||
}
|
||||
|
||||
private static int nameClaim(CommandContext<ServerCommandSource> context) throws CommandSyntaxException {
|
||||
ServerPlayerEntity player = context.getSource().getPlayer();
|
||||
PlayerClaimData data = PlayerClaimData.get(player);
|
||||
if (data.getEditMode() == EnumEditMode.DEFAULT) {
|
||||
Claim claim = PermHelper.checkReturn(player, PermissionRegistry.EDITPERMS, PermHelper.genericNoPermMessage(player));
|
||||
if (claim == null)
|
||||
return 0;
|
||||
boolean nameUsed = ClaimStorage.get(player.getServerWorld()).allClaimsFromPlayer(claim.getOwner())
|
||||
.stream().map(Claim::getClaimName).anyMatch(name -> name.equals(StringArgumentType.getString(context, "name")));
|
||||
if (!nameUsed) {
|
||||
String name = StringArgumentType.getString(context, "name");
|
||||
claim.setClaimName(name);
|
||||
player.sendMessage(PermHelper.simpleColoredText(String.format(ConfigHandler.lang.claimNameSet, name), Formatting.GOLD), false);
|
||||
} else {
|
||||
player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.claimNameUsed, Formatting.DARK_RED), false);
|
||||
}
|
||||
} else {
|
||||
Claim claim = ClaimStorage.get(player.getServerWorld()).getClaimAt(player.getBlockPos());
|
||||
Claim sub = claim.getSubClaim(player.getBlockPos());
|
||||
if (sub != null && (claim.canInteract(player, PermissionRegistry.EDITPERMS, player.getBlockPos()) || sub.canInteract(player, PermissionRegistry.EDITPERMS, player.getBlockPos()))) {
|
||||
boolean nameUsed = claim.getAllSubclaims()
|
||||
.stream().map(Claim::getClaimName).anyMatch(name -> name.equals(StringArgumentType.getString(context, "name")));
|
||||
if (!nameUsed) {
|
||||
String name = StringArgumentType.getString(context, "name");
|
||||
sub.setClaimName(name);
|
||||
player.sendMessage(PermHelper.simpleColoredText(String.format(ConfigHandler.lang.claimNameSet, name), Formatting.GOLD), false);
|
||||
} else {
|
||||
player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.claimNameUsedSub, Formatting.DARK_RED), false);
|
||||
}
|
||||
} else if (claim.canInteract(player, PermissionRegistry.EDITPERMS, player.getBlockPos())) {
|
||||
boolean nameUsed = ClaimStorage.get(player.getServerWorld()).allClaimsFromPlayer(claim.getOwner())
|
||||
.stream().map(Claim::getClaimName).anyMatch(name -> name.equals(StringArgumentType.getString(context, "name")));
|
||||
if (!nameUsed) {
|
||||
String name = StringArgumentType.getString(context, "name");
|
||||
claim.setClaimName(name);
|
||||
player.sendMessage(PermHelper.simpleColoredText(String.format(ConfigHandler.lang.claimNameSet, name), Formatting.GOLD), false);
|
||||
} else {
|
||||
player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.claimNameUsed, Formatting.DARK_RED), false);
|
||||
}
|
||||
} else
|
||||
player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.noPermission, Formatting.DARK_RED), false);
|
||||
}
|
||||
return Command.SINGLE_SUCCESS;
|
||||
}
|
||||
|
||||
private static int unlockDrops(CommandContext<ServerCommandSource> context) throws CommandSyntaxException {
|
||||
ServerPlayerEntity player = context.getSource().getPlayer();
|
||||
PlayerClaimData data = PlayerClaimData.get(player);
|
||||
|
@ -128,6 +128,10 @@ public class LangConfig {
|
||||
public String unlockDrops = "Your deathitems are now unlocked for %s ticks";
|
||||
public String unlockDropsMulti = "Unlocked drops for %s";
|
||||
|
||||
public String claimNameSet = "Claims name set to %s";
|
||||
public String claimNameUsed = "The owner of the claim already has another claim with the same name";
|
||||
public String claimNameUsedSub = "One of the subclaim of this claim already has this name";
|
||||
|
||||
public LangCommands cmdLang = new LangCommands();
|
||||
|
||||
public LangConfig(MinecraftServer server) {
|
||||
|
@ -41,6 +41,7 @@ public class CommandPermission {
|
||||
public static final String cmdBuy = "flan.command.sell";
|
||||
|
||||
public static final String cmdUnlockAll = "flan.command.unlock.all";
|
||||
public static final String cmdName = "flan.command.name";
|
||||
|
||||
public static boolean perm(CommandSource src, String perm) {
|
||||
return perm(src, perm, false);
|
||||
|
Loading…
Reference in New Issue
Block a user