Skip to content

Commit 545dae9

Browse files
committed
improved citizens list
1 parent e3492e3 commit 545dae9

File tree

4 files changed

+51
-26
lines changed

4 files changed

+51
-26
lines changed

src/main/java/pro/cloudnode/smp/smpcore/Messages.java

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ public Messages() {
189189
.deserialize(Objects.requireNonNull(config.getString(member.isActive() ? "nation.citizens.status.active" : "nation.citizens.status.inactive")));
190190
}
191191

192-
public @NotNull Component nationCitizensList(final @NotNull Nation nation, final @NotNull Permissible sender) {
192+
public @NotNull Component nationCitizensList(final @NotNull Nation nation, final @NotNull Permissible sender, final boolean other) {
193193
final @NotNull HashSet<@NotNull Member> members = nation.citizens();
194194
final @NotNull Component header = MiniMessage.miniMessage()
195195
.deserialize(Objects.requireNonNull(config.getString("nation.citizens.list.header"))
@@ -204,16 +204,16 @@ public Messages() {
204204
final @NotNull List<@NotNull Component> list = new ArrayList<>();
205205

206206
final @NotNull Member leader = members.stream().filter(m -> m.uuid.equals(nation.leaderUUID)).findFirst().orElseThrow(IllegalStateException::new);
207-
list.add(nationCitizensListEntry(nation, leader, sender));
207+
list.add(nationCitizensListEntry(nation, leader, sender, other));
208208

209209
final @NotNull Member vice = members.stream().filter(m -> m.uuid.equals(nation.viceLeaderUUID)).findFirst().orElseThrow(IllegalStateException::new);
210210
if (!vice.uuid.equals(leader.uuid))
211-
list.add(nationCitizensListEntry(nation, vice, sender));
211+
list.add(nationCitizensListEntry(nation, vice, sender, other));
212212

213-
final @NotNull List<@NotNull Component> citizens = members.stream().filter(m -> !m.uuid.equals(leader.uuid) && !m.uuid.equals(vice.uuid) && m.isActive()).map(m -> nationCitizensListEntry(nation, m, sender)).toList();
213+
final @NotNull List<@NotNull Component> citizens = members.stream().filter(m -> !m.uuid.equals(leader.uuid) && !m.uuid.equals(vice.uuid) && m.isActive()).map(m -> nationCitizensListEntry(nation, m, sender, other)).toList();
214214
list.addAll(citizens);
215215

216-
final @NotNull List<@NotNull Component> inactive = members.stream().filter(m -> !m.uuid.equals(leader.uuid) && !m.uuid.equals(vice.uuid) && !m.isActive()).map(m -> nationCitizensListEntry(nation, m, sender)).toList();
216+
final @NotNull List<@NotNull Component> inactive = members.stream().filter(m -> !m.uuid.equals(leader.uuid) && !m.uuid.equals(vice.uuid) && !m.isActive()).map(m -> nationCitizensListEntry(nation, m, sender, other)).toList();
217217
list.addAll(inactive);
218218

219219
final @NotNull TextComponent.Builder listComponent = Component.text();
@@ -225,15 +225,15 @@ public Messages() {
225225
return Component.text().append(header).append(Component.newline()).append(listComponent.build()).build();
226226
}
227227

228-
private @NotNull Component nationCitizensListEntry(final @NotNull Nation nation, final @NotNull Member member, final @NotNull Permissible sender) {
228+
private @NotNull Component nationCitizensListEntry(final @NotNull Nation nation, final @NotNull Member member, final @NotNull Permissible sender, final boolean other) {
229229
if (member.uuid.equals(nation.leaderUUID)) {
230230
return MiniMessage.miniMessage()
231231
.deserialize(Objects.requireNonNull(config.getString("nation.citizens.list.entry.leader"))
232232
.replaceAll("<color>", "<#" + nation.color + ">")
233233
.replaceAll("</color>", "</#" + nation.color + ">")
234234
.replaceAll("<member-name>", Optional.ofNullable(member.player().getName()).orElse(member.uuid.toString())),
235235
Placeholder.component("member-status", nationCitizensStatus(member)),
236-
Placeholder.component("buttons", nationCitizensListButtons(nation, member, sender))
236+
Placeholder.component("buttons", nationCitizensListButtons(nation, member, sender, other))
237237
);
238238
}
239239
if (member.uuid.equals(nation.viceLeaderUUID)) {
@@ -243,7 +243,7 @@ public Messages() {
243243
.replaceAll("</color>", "</#" + nation.color + ">")
244244
.replaceAll("<member-name>", Optional.ofNullable(member.player().getName()).orElse(member.uuid.toString())),
245245
Placeholder.component("member-status", nationCitizensStatus(member)),
246-
Placeholder.component("buttons", nationCitizensListButtons(nation, member, sender))
246+
Placeholder.component("buttons", nationCitizensListButtons(nation, member, sender, other))
247247
);
248248
}
249249
if (member.isActive()) {
@@ -253,7 +253,7 @@ public Messages() {
253253
.replaceAll("</color>", "</#" + nation.color + ">")
254254
.replaceAll("<member-name>", Optional.ofNullable(member.player().getName()).orElse(member.uuid.toString())),
255255
Placeholder.component("member-status", nationCitizensStatus(member)),
256-
Placeholder.component("buttons", nationCitizensListButtons(nation, member, sender))
256+
Placeholder.component("buttons", nationCitizensListButtons(nation, member, sender, other))
257257
);
258258
}
259259
return MiniMessage.miniMessage()
@@ -262,17 +262,33 @@ public Messages() {
262262
.replaceAll("</color>", "</#" + nation.color + ">")
263263
.replaceAll("<member-name>", Optional.ofNullable(member.player().getName()).orElse(member.uuid.toString())),
264264
Placeholder.component("member-status", nationCitizensStatus(member)),
265-
Placeholder.component("buttons", nationCitizensListButtons(nation, member, sender))
265+
Placeholder.component("buttons", nationCitizensListButtons(nation, member, sender, other))
266266
);
267267
}
268268

269-
private @NotNull Component nationCitizensListButtons(final @NotNull Nation nation, final @NotNull Member member, final @NotNull Permissible sender) {
269+
private @NotNull Component nationCitizensListButtons(final @NotNull Nation nation, final @NotNull Member member, final @NotNull Permissible sender, final boolean other) {
270270
final @NotNull List<@NotNull Component> buttons = new ArrayList<>();
271-
if (sender.hasPermission(Permission.NATION_CITIZENS_KICK) && !(member.uuid.equals(nation.leaderUUID) || member.uuid.equals(nation.viceLeaderUUID)))
271+
if (
272+
((!other && sender.hasPermission(Permission.NATION_CITIZENS_KICK))
273+
|| sender.hasPermission(Permission.NATION_CITIZENS_KICK_OTHER))
274+
&& !(member.uuid.equals(nation.leaderUUID) || member.uuid.equals(nation.viceLeaderUUID))
275+
)
272276
buttons.add(nationCitizensListButton("kick", nation, member));
273-
if (sender.hasPermission(Permission.NATION_VICE_DEMOTE) && member.uuid.equals(nation.viceLeaderUUID) && !member.uuid.equals(nation.leaderUUID))
277+
if (
278+
((!other && sender.hasPermission(Permission.NATION_DEMOTE))
279+
|| sender.hasPermission(Permission.NATION_DEMOTE_OTHER))
280+
&& member.uuid.equals(nation.leaderUUID)
281+
&& !member.uuid.equals(nation.viceLeaderUUID)
282+
)
274283
buttons.add(nationCitizensListButton("demote", nation, member));
275-
if (sender.hasPermission(Permission.NATION_VICE_PROMOTE) && nation.viceLeaderUUID.equals(nation.leaderUUID) && !(member.uuid.equals(nation.leaderUUID) || member.uuid.equals(nation.viceLeaderUUID)) && member.isActive())
284+
285+
if (
286+
((!other && sender.hasPermission(Permission.NATION_PROMOTE))
287+
|| sender.hasPermission(Permission.NATION_PROMOTE_OTHER))
288+
&& nation.viceLeaderUUID.equals(nation.leaderUUID)
289+
&& !member.uuid.equals(nation.leaderUUID)
290+
&& member.isActive()
291+
)
276292
buttons.add(nationCitizensListButton("promote", nation, member));
277293

278294
final @NotNull TextComponent.Builder buttonsComponent = Component.text();

src/main/java/pro/cloudnode/smp/smpcore/Permission.java

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -138,12 +138,22 @@ public final class Permission {
138138
public static @NotNull String NATION_CITIZEN_ADD_SWITCH = "smpcore.nation.citizens.add.switch";
139139

140140
/**
141-
* Appoint nation citizen as vice-leader
141+
* Appoint nation citizen as vice-leader of your nation
142142
*/
143-
public static @NotNull String NATION_VICE_PROMOTE = "smpcore.nation.vice-promote";
143+
public static @NotNull String NATION_PROMOTE = "smpcore.nation.citizens.promote";
144144

145145
/**
146-
* Relieve vice-leader of duties
146+
* Appoint nation citizen as vice-leader of any nation
147147
*/
148-
public static @NotNull String NATION_VICE_DEMOTE = "smpcore.nation.vice-demote";
148+
public static @NotNull String NATION_PROMOTE_OTHER = "smpcore.nation.citizens.promote.other";
149+
150+
/**
151+
* Relieve vice-leader of your nation of their duties
152+
*/
153+
public static @NotNull String NATION_DEMOTE = "smpcore.nation.citizens.demote";
154+
155+
/**
156+
* Relieve vice-leader of any nation of their duties
157+
*/
158+
public static @NotNull String NATION_DEMOTE_OTHER = "smpcore.nation.citizens.demote.other";
149159
}

src/main/java/pro/cloudnode/smp/smpcore/command/NationCommand.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -358,13 +358,12 @@ public static boolean listCitizens(
358358
final @NotNull Nation nation,
359359
final @NotNull CommandSender sender
360360
) {
361-
if (!sender.hasPermission(Permission.NATION_CITIZENS_LIST_OTHER) && (
362-
member == null || !nation.id.equals(member.nationID)
363-
|| !sender.hasPermission(Permission.NATION_CITIZENS_LIST)
364-
))
361+
final boolean other = member == null || !nation.id.equals(member.nationID);
362+
if (!sender.hasPermission(Permission.NATION_CITIZENS_LIST)
363+
|| (other && !sender.hasPermission(Permission.NATION_CITIZENS_LIST_OTHER)))
365364
return sendMessage(sender, SMPCore.messages().errorNoPermission());
366365
else
367-
return sendMessage(sender, SMPCore.messages().nationCitizensList(nation, sender));
366+
return sendMessage(sender, SMPCore.messages().nationCitizensList(nation, sender, other));
368367
}
369368

370369
public static boolean kickCitizen(

src/main/resources/messages.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,9 @@ nation:
5959
prefix: ' '
6060
separator: ' '
6161
suffix: ''
62-
kick: <click:run_command:/nation kick <member-name>><hover:show_text:'Remove citizen from the nation'><dark_gray>[<red>Kick</red>]</dark_gray></hover></click>
63-
demote: <click:run_command:/nation vice-demote <member-name>><hover:show_text:'Demote vice-leader to citizen'><dark_gray>[<red>Demote</red>]</dark_gray></hover></click>
64-
promote: <click:run_command:/nation vice-promote <member-name>><hover:show_text:'Appoint citizen as vice-leader'><dark_gray>[<green>Promote</green>]</dark_gray></hover></click>
62+
kick: <click:run_command:/nation citizens kick <member-name>><hover:show_text:'Remove citizen from the nation'><dark_gray>[<red>Kick</red>]</dark_gray></hover></click>
63+
demote: <click:run_command:/nation citizens demote <member-name>><hover:show_text:'Demote vice-leader to citizen'><dark_gray>[<red>Demote</red>]</dark_gray></hover></click>
64+
promote: <click:run_command:/nation citizens promote <member-name>><hover:show_text:'Appoint citizen as vice-leader'><dark_gray>[<green>Promote</green>]</dark_gray></hover></click>
6565
kicked: <green>(!) Player <gray><player></gray> is no longer a citizen of the nation.</green>
6666
join:
6767
request-sent: <green>(!) Your request to join <gray><nation></gray> has been sent.</green> <click:run_command:"/nation cancel <nation-id>"><hover:show_text:"<red>Click to cancel.</red>"><white>[Cancel]</white></hover></click>

0 commit comments

Comments
 (0)