Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
87964a8
Fixed translations for auto claiming
koiboi-dev May 10, 2026
0392be5
Merge branch 'Create-Civilization:1.21.1-rc' into translation-fix
koiboi-dev May 10, 2026
a745097
Added permissions list
koiboi-dev May 10, 2026
edc11a8
Merge branch 'Create-Civilization:1.21.1-rc' into permission-viewer
koiboi-dev May 10, 2026
2c0293d
Added translations for hover text
koiboi-dev May 10, 2026
12d3c4f
Merge remote-tracking branch 'origin/permission-viewer' into permissi…
koiboi-dev May 11, 2026
5e99e26
Added basic name formatting
koiboi-dev May 11, 2026
d1c1848
Added list command to help command
koiboi-dev May 11, 2026
beca404
Added nation tags to show before player names.
koiboi-dev May 11, 2026
f88c831
Added config for toggling tags
koiboi-dev May 11, 2026
89a9970
Added role-based coloring
koiboi-dev May 11, 2026
10bd921
Cleaning up
koiboi-dev May 11, 2026
4399934
Added a max length to team tags (configurable)
koiboi-dev May 11, 2026
b711f65
Added player check to viewRolePermList
koiboi-dev May 11, 2026
4623fdb
Merge pull request #20 from koiboi-dev/translation-fix
EpicVon2468 May 11, 2026
add2e05
Merge pull request #22 from koiboi-dev/permission-viewer
EpicVon2468 May 11, 2026
8bafd54
Added basic name formatting
koiboi-dev May 11, 2026
c90467e
Added nation tags to show before player names.
koiboi-dev May 11, 2026
b6f14f8
Added config for toggling tags
koiboi-dev May 11, 2026
cf37900
Added role-based coloring
koiboi-dev May 11, 2026
27acf75
Cleaning up
koiboi-dev May 11, 2026
375fce8
Added a max length to team tags (configurable)
koiboi-dev May 11, 2026
c9891df
Merge remote-tracking branch 'origin/name-tags' into name-tags
koiboi-dev May 11, 2026
41f444b
Import fix
koiboi-dev May 11, 2026
568753c
Fixed downcast
koiboi-dev May 12, 2026
7b7a434
Changed "nation" to "team"
koiboi-dev May 12, 2026
07e5b3b
Added translations to the command suggestion
koiboi-dev May 12, 2026
9e76af0
cleaned up getTag
koiboi-dev May 12, 2026
8c7ed21
Pulled duplicated code into its own function
koiboi-dev May 12, 2026
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
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,14 @@ public class CapitolConfig {
public static final ModConfigSpec.ConfigValue<List<? extends String>> BLOCK_PLACE_EXCEPTIONS;
public static final ModConfigSpec.ConfigValue<List<? extends String>> ITEM_USE_EXCEPTIONS;

// Roles

public static final ModConfigSpec.BooleanValue DISPLAY_TAGS_IN_CHAT;
public static final ModConfigSpec.BooleanValue DISPLAY_TAGS_IN_TAB_LIST;

// Teams
public static final ModConfigSpec.IntValue TEAM_TAG_MAX_LENGTH;

public enum ListType {
ONLY,
ALL_BUT
Expand Down Expand Up @@ -169,6 +177,26 @@ public enum ListType {

builder.pop();

builder.comment("Role settings").push("roles");

DISPLAY_TAGS_IN_CHAT = builder
.comment("Whether chat messages with have the players team tag attached.")
.define("displayTagsInChat", true);

DISPLAY_TAGS_IN_TAB_LIST = builder
.comment("Whether the tab list will have the players team tag attached.")
.define("displayTagsInTabList", true);

builder.pop();

builder.comment("Role settings").push("team");

TEAM_TAG_MAX_LENGTH = builder
.comment("Max length for a team to have as a tag.")
.defineInRange("teamTagMaxLength", 3, 0, 16);

builder.pop();

SPEC = builder.build();
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package com.createcivilization.capitol.common.data;

import java.awt.*;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.UUID;

public record TeamRole(int id, UUID teamId, String name, long permissions) {
public record TeamRole(int id, UUID teamId, String name, long permissions, Color color) {

public static final String OWNER_ROLE_NAME = "owner";
public static final String DEFAULT_ROLE_NAME = "default";
Expand All @@ -22,11 +23,17 @@ public boolean hasPermission(Permission perm) {
}

public static TeamRole fromResultSet(ResultSet rs) throws SQLException {
Color color = null;
if (rs.getInt("color") != -1) {
color = new Color(rs.getInt("color"));
}

return new TeamRole(
rs.getInt("id"),
UUID.fromString(rs.getString("team_id")),
rs.getString("name"),
rs.getLong("permissions")
rs.getLong("permissions"),
color
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ private static void createTables() throws SQLException {
"team_id TEXT NOT NULL," +
"name TEXT NOT NULL," +
"permissions INTEGER NOT NULL DEFAULT 0," +
"color INTEGER NOT NULL DEFAULT -1,"+
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@McArctic has made note that we shouldn't touch the database without going through him first.

I'm not sure what exactly the protocol is, but I think it's important he sees this.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will take a deeper review EOW, but its basically means we need to version up DB and add migration code so players can update without nuking the database.

"UNIQUE (team_id, name)," +
"FOREIGN KEY (team_id) REFERENCES teams (id) ON DELETE CASCADE)"
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@
import net.minecraft.world.level.ChunkPos;
import net.minecraft.world.level.Level;

import java.awt.*;
import java.sql.*;
import java.time.Instant;
import java.util.*;
import java.util.List;
import java.util.concurrent.ConcurrentHashMap;

public class CapitolDatabase extends Database {
Expand Down Expand Up @@ -78,19 +80,31 @@ public void setTeamPermissions(Team team, long permissions) {
* @param team the team this role belongs to
* @param name the role name (e.g. "owner", "default")
* @param permissions the bitfield of {@link Permission} flags
* @param color the color this role will override to for nation tags
*/
public void addRole(Team team, String name, long permissions) {
public void addRole(Team team, String name, long permissions, Color color) {
try (PreparedStatement ps = getConnection().prepareStatement(
"INSERT INTO team_roles (team_id, name, permissions) VALUES (?, ?, ?)")) {
"INSERT INTO team_roles (team_id, name, permissions, color) VALUES (?, ?, ?, ?)")) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cc @McArctic
DB change

ps.setString(1, team.getId().toString());
ps.setString(2, name);
ps.setLong(3, permissions);
ps.setInt(4, color == null ? -1 : color.getRGB()); // -1 if the role has no associated color
ps.execute();
} catch (SQLException e) {
Capitol.LOGGER.error("Error while adding role to database.", e);
throw new RuntimeException(e);
}
}
/**
* Inserts a new role into the {@code team_roles} table.
*
* @param team the team this role belongs to
* @param name the role name (e.g. "owner", "default")
* @param permissions the bitfield of {@link Permission} flags
*/
public void addRole(Team team, String name, long permissions) {
addRole(team, name, permissions, null);
}

/**
* Retrieves a role by its auto-incremented database ID.
Expand Down Expand Up @@ -200,6 +214,19 @@ public void updateRoleName(Team team, String roleName, String newName) {
}
}

public void updateRoleColor(Team team, String roleName, Color color) {
try (PreparedStatement ps = getConnection().prepareStatement(
"UPDATE team_roles SET color = ? WHERE team_id = ? AND name = ?")) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cc @McArctic
DB change

ps.setInt(1, color == null ? -1 : color.getRGB());
ps.setString(2, team.getId().toString());
ps.setString(3, roleName);
ps.execute();
} catch (SQLException e) {
Capitol.LOGGER.error("Error while updating role color in database.", e);
throw new RuntimeException(e);
}
}

/**
* Deletes a role by team and role name.
*
Expand Down Expand Up @@ -308,7 +335,7 @@ public void addTeam(Team team) {
throw new RuntimeException(e);
}

addRole(team, TeamRole.OWNER_ROLE_NAME, TeamRole.ownerPermissions());
addRole(team, TeamRole.OWNER_ROLE_NAME, TeamRole.ownerPermissions(), new Color(0x800080));
addRole(team, TeamRole.DEFAULT_ROLE_NAME, TeamRole.defaultPermissions());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,10 +175,10 @@ private static int auto(CommandContext<CommandSourceStack> context) {

if (AutoClaimEvents.isAutoClaimer(player)) {
AutoClaimEvents.removeAutoClaimer(player);
context.getSource().sendSuccess(() -> Component.translatable("commands.capitol.claim.auto_claim.stop").withStyle(ChatFormatting.GREEN), true);
context.getSource().sendSuccess(() -> Component.translatable("commands.capitol.claim.auto_claiming.stop").withStyle(ChatFormatting.GREEN), true);
} else {
AutoClaimEvents.updateAutoClaimer(player);
context.getSource().sendSuccess(() -> Component.translatable("commands.capitol.claim.auto_claim.start").withStyle(ChatFormatting.GREEN), true);
context.getSource().sendSuccess(() -> Component.translatable("commands.capitol.claim.auto_claiming.start").withStyle(ChatFormatting.GREEN), true);
}
return 1;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ private static int showHelp(CommandContext<CommandSourceStack> context) {
msg.append(entry("/capitol team invite <player>", Component.translatable("commands.capitol.help.team.invite")));
msg.append(entry("/capitol team kick <player>", Component.translatable("commands.capitol.help.team.kick")));
msg.append(entry("/capitol team disband", Component.translatable("commands.capitol.help.team.disband")));
msg.append(entry("/capitol team role edit <name> remove|rename|assign|permission", Component.translatable("commands.capitol.help.team.role.edit")));
msg.append(entry("/capitol team role edit <name> remove|rename|assign|permission|list", Component.translatable("commands.capitol.help.team.role.edit")));
msg.append(entry("/capitol team role create <name>", Component.translatable("commands.capitol.help.team.role.create")));
msg.append(entry("/capitol team protection <name>", Component.translatable("commands.capitol.help.team.protection")));
msg.append(entry("/capitol team player <player> permission <perm>", Component.translatable("commands.capitol.help.team.player.permission")));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public static LiteralArgumentBuilder<CommandSourceStack> register() {
}

private static int acceptInvite(CommandContext<CommandSourceStack> context) {
Player player = context.getSource().getPlayer();
ServerPlayer player = context.getSource().getPlayer();
if (player == null) return 0;

Team team = resolveInvitedTeam(context, player);
Expand All @@ -48,6 +48,9 @@ private static int acceptInvite(CommandContext<CommandSourceStack> context) {
DatabaseManager.database.addPlayerToTeam(player, team, role);
InviteHandler.clearInvites(player);

player.refreshDisplayName();
player.refreshTabListName(); // needs to be a ServerPlayer for this.
Comment thread
koiboi-dev marked this conversation as resolved.

MutableComponent joinMsg = Component.translatable("commands.capitol.invites.join.announcement",
Component.literal(player.getName().getString()).withStyle(ChatFormatting.WHITE),
Component.literal(team.getName()).withStyle(ChatFormatting.GOLD))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.createcivilization.capitol.server.commands.team;

import com.createcivilization.capitol.common.config.CapitolConfig;
import com.createcivilization.capitol.common.data.*;
import com.createcivilization.capitol.common.managers.DatabaseManager;
import com.createcivilization.capitol.common.modules.database.CapitolDatabase;
Expand Down Expand Up @@ -198,6 +199,11 @@ private static int createTeam(CommandContext<CommandSourceStack> context) {
).replace("#", "");
String tag = StringArgumentType.getString(context, "tag");

if (tag.length() > CapitolConfig.TEAM_TAG_MAX_LENGTH.get()) {
context.getSource().sendFailure(Component.translatable("commands.capitol.team.create.tag_too_long", CapitolConfig.TEAM_TAG_MAX_LENGTH.get()).withStyle(ChatFormatting.RED));
return 0;
}

String description;
try {
description = StringArgumentType.getString(context, "description");
Expand Down Expand Up @@ -339,4 +345,8 @@ private static int confirmDisband(CommandContext<CommandSourceStack> context) {
context.getSource().sendSuccess(() -> Component.translatable("commands.capitol.team.disband.success").withStyle(ChatFormatting.GREEN), true);
return 1;
}

public static Map<String, String> getNamedColors() {
Comment thread
koiboi-dev marked this conversation as resolved.
return NAMED_COLORS;
}
}
Loading