Skip to content

Commit e0155e5

Browse files
authored
Merge pull request #32 from FTBTeam/1.18/dev
1.18/dev
2 parents 0eb8a7b + 259f4d1 commit e0155e5

27 files changed

+662
-99
lines changed

.github/workflows/build.yml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,24 @@ on:
66
# main and dev versions for each mc ver here
77
- "1.18/main"
88
- "1.18/dev"
9+
workflow_dispatch:
10+
inputs:
11+
norelease:
12+
description: 'Do not publish'
13+
required: true
14+
default: 'false'
915

1016
jobs:
1117
build:
1218
runs-on: ubuntu-latest
1319
if: |
1420
!contains(github.event.head_commit.message, '[ci skip]')
1521
steps:
16-
- uses: actions/checkout@v2
22+
- uses: actions/checkout@v3
1723
with:
1824
fetch-depth: 30 # Gets the last 30 commits so the changelog might work
1925
- name: Set up JDK 17
20-
uses: actions/setup-java@v2
26+
uses: actions/setup-java@v3
2127
with:
2228
distribution: 'temurin'
2329
java-version: '17'

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,6 @@ logs
2121
# other
2222
eclipse
2323
run
24-
.vscode
24+
.vscode
25+
/.architectury-transformer/debug.log
26+
/common/.architectury-transformer/debug.log

CHANGELOG.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Changelog
2+
All notable changes to this project will be documented in this file.
3+
4+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
5+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6+
7+
[1802.1.9]
8+
9+
### Added
10+
* Events are now fired for other mods to consume when various things happen:
11+
* Config reloaded with `/ftbranks reload`
12+
* A rank is created or deleted
13+
* Player is added to or removed from a rank
14+
* A permission node of a rank is modified
15+
* A rank's condition is modified
16+
* Added `/ftbranks node <rank> <nodename> <value>` command to change a permission node's value
17+
* Added `/ftbranks condition <rank> <condition>` command to change a rank's condition
18+
* `<condition>` is an SNBT serialized condition e.g. `op` or `{ type "dimension", "dimension": "minecraft:the_nether" }`
19+
* Added `/ftbrank show_rank <rank>` to display details of a rank
20+
* Added Tab-completion for known rank names
21+

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
plugins {
22
id "architectury-plugin" version "3.4-SNAPSHOT"
3-
id "dev.architectury.loom" version "0.11.0-SNAPSHOT" apply false
3+
id "dev.architectury.loom" version "1.0-SNAPSHOT" apply false
44
}
55

66
architectury {

common/src/main/java/dev/ftb/mods/ftbranks/FTBRanks.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@
44
import dev.architectury.event.events.common.CommandRegistrationEvent;
55
import dev.architectury.event.events.common.LifecycleEvent;
66
import dev.ftb.mods.ftbranks.api.FTBRanksAPI;
7+
import dev.ftb.mods.ftbranks.api.Rank;
78
import dev.ftb.mods.ftbranks.impl.FTBRanksAPIImpl;
9+
import net.minecraft.commands.synchronization.ArgumentTypes;
10+
import net.minecraft.commands.synchronization.EmptyArgumentSerializer;
811
import org.apache.logging.log4j.LogManager;
912
import org.apache.logging.log4j.Logger;
1013

@@ -25,5 +28,7 @@ public FTBRanks() {
2528
CommandRegistrationEvent.EVENT.register(FTBRanksCommands::register);
2629
// TODO: Register with LOWEST priority on forge
2730
ChatEvent.SERVER.register(FTBRanksAPIImpl::serverChat);
31+
32+
ArgumentTypes.register("ftbranks:rank", RankArgumentType.class, new RankArgumentType.Serializer());
2833
}
2934
}

common/src/main/java/dev/ftb/mods/ftbranks/FTBRanksCommands.java

Lines changed: 143 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,33 @@
44
import com.mojang.brigadier.CommandDispatcher;
55
import com.mojang.brigadier.arguments.StringArgumentType;
66
import com.mojang.brigadier.exceptions.CommandSyntaxException;
7+
import com.mojang.brigadier.exceptions.SimpleCommandExceptionType;
8+
import dev.ftb.mods.ftblibrary.snbt.SNBT;
9+
import dev.ftb.mods.ftbranks.api.FTBRanksAPI;
10+
import dev.ftb.mods.ftbranks.api.PermissionValue;
711
import dev.ftb.mods.ftbranks.api.Rank;
12+
import dev.ftb.mods.ftbranks.api.RankCondition;
13+
import dev.ftb.mods.ftbranks.impl.BooleanPermissionValue;
814
import dev.ftb.mods.ftbranks.impl.FTBRanksAPIImpl;
15+
import dev.ftb.mods.ftbranks.impl.NumberPermissionValue;
16+
import dev.ftb.mods.ftbranks.impl.StringPermissionValue;
17+
import dev.ftb.mods.ftbranks.impl.condition.DefaultCondition;
918
import net.minecraft.ChatFormatting;
1019
import net.minecraft.commands.CommandSourceStack;
1120
import net.minecraft.commands.Commands;
1221
import net.minecraft.commands.arguments.EntityArgument;
1322
import net.minecraft.commands.arguments.GameProfileArgument;
23+
import net.minecraft.nbt.StringTag;
24+
import net.minecraft.network.chat.Component;
25+
import net.minecraft.network.chat.MutableComponent;
1426
import net.minecraft.network.chat.TextComponent;
27+
import net.minecraft.network.chat.TranslatableComponent;
1528
import net.minecraft.server.level.ServerPlayer;
29+
import org.apache.commons.lang3.math.NumberUtils;
1630

1731
import java.io.IOException;
1832
import java.util.Collection;
33+
import java.util.Collections;
1934

2035
/**
2136
* @author LatvianModder
@@ -39,21 +54,21 @@ public static void register(CommandDispatcher<CommandSourceStack> dispatcher, Co
3954
)
4055
)
4156
.then(Commands.literal("delete")
42-
.then(Commands.argument("rank", StringArgumentType.word())
43-
.executes(context -> deleteRank(context.getSource(), StringArgumentType.getString(context, "rank")))
57+
.then(Commands.argument("rank", RankArgumentType.rank())
58+
.executes(context -> deleteRank(context.getSource(), RankArgumentType.getRank(context, "rank")))
4459
)
4560
)
4661
.then(Commands.literal("add")
4762
.then(Commands.argument("players", GameProfileArgument.gameProfile())
48-
.then(Commands.argument("rank", StringArgumentType.word())
49-
.executes(context -> addRank(context.getSource(), GameProfileArgument.getGameProfiles(context, "players"), StringArgumentType.getString(context, "rank")))
63+
.then(Commands.argument("rank", RankArgumentType.rank())
64+
.executes(context -> addRank(context.getSource(), GameProfileArgument.getGameProfiles(context, "players"), RankArgumentType.getRank(context, "rank")))
5065
)
5166
)
5267
)
5368
.then(Commands.literal("remove")
5469
.then(Commands.argument("players", GameProfileArgument.gameProfile())
55-
.then(Commands.argument("rank", StringArgumentType.word())
56-
.executes(context -> removeRank(context.getSource(), GameProfileArgument.getGameProfiles(context, "players"), StringArgumentType.getString(context, "rank")))
70+
.then(Commands.argument("rank", RankArgumentType.rank())
71+
.executes(context -> removeRank(context.getSource(), GameProfileArgument.getGameProfiles(context, "players"), RankArgumentType.getRank(context, "rank")))
5772
)
5873
)
5974
)
@@ -63,8 +78,38 @@ public static void register(CommandDispatcher<CommandSourceStack> dispatcher, Co
6378
)
6479
)
6580
.then(Commands.literal("list_players_with")
66-
.then(Commands.argument("rank", StringArgumentType.word())
67-
.executes(context -> listPlayersWith(context.getSource(), StringArgumentType.getString(context, "rank")))
81+
.then(Commands.argument("rank", RankArgumentType.rank())
82+
.executes(context -> listPlayersWith(context.getSource(), RankArgumentType.getRank(context, "rank")))
83+
)
84+
)
85+
.then(Commands.literal("node")
86+
.then(Commands.literal("add")
87+
.then(Commands.argument("rank", RankArgumentType.rank())
88+
.then(Commands.argument("node", StringArgumentType.word())
89+
.then(Commands.argument("value", StringArgumentType.greedyString())
90+
.executes(context -> setNode(context.getSource(), RankArgumentType.getRank(context, "rank"), StringArgumentType.getString(context, "node"), StringArgumentType.getString(context, "value")))
91+
)
92+
)
93+
)
94+
)
95+
.then(Commands.literal("remove")
96+
.then(Commands.argument("rank", RankArgumentType.rank())
97+
.then(Commands.argument("node", StringArgumentType.word())
98+
.executes(context -> setNode(context.getSource(), RankArgumentType.getRank(context, "rank"), StringArgumentType.getString(context, "node"), null))
99+
)
100+
)
101+
)
102+
)
103+
.then(Commands.literal("condition")
104+
.then(Commands.argument("rank", RankArgumentType.rank())
105+
.then(Commands.argument("value", StringArgumentType.greedyString())
106+
.executes(context -> setCondition(context.getSource(), RankArgumentType.getRank(context, "rank"), StringArgumentType.getString(context, "value")))
107+
)
108+
)
109+
)
110+
.then(Commands.literal("show_rank")
111+
.then(Commands.argument("rank", RankArgumentType.rank())
112+
.executes(context -> showRank(context.getSource(), RankArgumentType.getRank(context, "rank")))
68113
)
69114
)
70115
);
@@ -77,7 +122,7 @@ private static String normalizeRankName(String name) {
77122
private static int reloadRanks(CommandSourceStack source) {
78123
try {
79124
FTBRanksAPIImpl.manager.reload();
80-
source.sendSuccess(new TextComponent("Ranks reloaded!"), true);
125+
source.sendSuccess(new TranslatableComponent("ftbranks.reload"), true);
81126

82127
for (ServerPlayer p : source.getServer().getPlayerList().getPlayers()) {
83128
source.getServer().getPlayerList().sendPlayerPermissionLevel(p);
@@ -98,12 +143,12 @@ private static int refreshReadme(CommandSourceStack source) {
98143
ex.printStackTrace();
99144
}
100145

101-
source.sendSuccess(new TextComponent("Done!"), false);
146+
source.sendSuccess(new TranslatableComponent("ftbranks.refresh_readme"), false);
102147
return 1;
103148
}
104149

105150
private static int listAllRanks(CommandSourceStack source) {
106-
source.sendSuccess(new TextComponent("Ranks:"), false);
151+
source.sendSuccess(new TranslatableComponent("ftbranks.ranks"), false);
107152

108153
for (Rank rank : FTBRanksAPIImpl.manager.getAllRanks()) {
109154
source.sendSuccess(new TextComponent("- " + rank.getName()).withStyle(rank.getCondition().isDefaultCondition() ? ChatFormatting.AQUA : ChatFormatting.YELLOW), false);
@@ -112,55 +157,48 @@ private static int listAllRanks(CommandSourceStack source) {
112157
return 1;
113158
}
114159

115-
private static int createRank(CommandSourceStack source, String name) throws CommandSyntaxException {
160+
private static int createRank(CommandSourceStack source, String name) {
116161
String id = normalizeRankName(name);
117162

118163
if (FTBRanksAPIImpl.manager.getRank(id).isPresent()) {
119-
source.sendFailure(new TextComponent("Rank ID already taken!"));
164+
source.sendFailure(new TranslatableComponent("ftbranks.rank_taken", name));
120165
return 0;
121166
}
122167

123168
FTBRanksAPIImpl.manager.createRank(id, name);
124-
source.sendSuccess(new TextComponent("Rank created with id '" + id + "'!"), false);
169+
source.sendSuccess(new TranslatableComponent("ftbranks.rank_created", id), false);
125170
return 1;
126171
}
127172

128-
private static int deleteRank(CommandSourceStack source, String name) throws CommandSyntaxException {
129-
if (FTBRanksAPIImpl.manager.deleteRank(normalizeRankName(name)) == null) {
130-
source.sendFailure(new TextComponent("Rank not found!"));
131-
return 0;
132-
}
173+
private static int deleteRank(CommandSourceStack source, Rank rank) {
174+
FTBRanksAPI.INSTANCE.getManager().deleteRank(rank.getId());
175+
source.sendSuccess(new TranslatableComponent("ftbranks.rank_deleted", rank.getName()), false);
133176

134-
source.sendSuccess(new TextComponent("Rank deleted!"), false);
135177
return 1;
136178
}
137179

138-
private static int addRank(CommandSourceStack source, Collection<GameProfile> players, String name) throws CommandSyntaxException {
139-
Rank r = FTBRanksAPIImpl.manager.getRank(normalizeRankName(name)).orElseThrow(NullPointerException::new);
140-
180+
private static int addRank(CommandSourceStack source, Collection<GameProfile> players, Rank rank) {
141181
for (GameProfile profile : players) {
142-
if (r.add(profile)) {
143-
source.sendSuccess(new TextComponent("Added '" + r.getName() + "' to " + profile.getName()), false);
182+
if (rank.add(profile)) {
183+
source.sendSuccess(new TranslatableComponent("ftbranks.player_added", profile.getName(), rank.getName()), false);
144184
}
145185
}
146186

147187
return 1;
148188
}
149189

150-
private static int removeRank(CommandSourceStack source, Collection<GameProfile> players, String name) throws CommandSyntaxException {
151-
Rank r = FTBRanksAPIImpl.manager.getRank(normalizeRankName(name)).orElseThrow(NullPointerException::new);
152-
190+
private static int removeRank(CommandSourceStack source, Collection<GameProfile> players, Rank rank) {
153191
for (GameProfile profile : players) {
154-
if (r.remove(profile)) {
155-
source.sendSuccess(new TextComponent("Removed '" + r.getName() + "' from " + profile.getName()), false);
192+
if (rank.remove(profile)) {
193+
source.sendSuccess(new TranslatableComponent("ftbranks.player_removed", profile.getName(), rank.getName()), false);
156194
}
157195
}
158196

159197
return 1;
160198
}
161199

162200
private static int listRanksOf(CommandSourceStack source, ServerPlayer player) {
163-
source.sendSuccess(new TextComponent("Ranks added to " + player.getGameProfile().getName() + ":"), false);
201+
source.sendSuccess(new TranslatableComponent("ftbranks.list_ranks_of", player.getGameProfile().getName()), false);
164202

165203
for (Rank rank : FTBRanksAPIImpl.manager.getAllRanks()) {
166204
if (rank.isActive(player)) {
@@ -171,17 +209,86 @@ private static int listRanksOf(CommandSourceStack source, ServerPlayer player) {
171209
return 1;
172210
}
173211

174-
private static int listPlayersWith(CommandSourceStack source, String name) {
175-
Rank r = FTBRanksAPIImpl.manager.getRank(normalizeRankName(name)).orElseThrow(NullPointerException::new);
176-
177-
source.sendSuccess(new TextComponent("Players with " + name + " added to them:"), false);
212+
private static int listPlayersWith(CommandSourceStack source, Rank rank) {
213+
source.sendSuccess(new TranslatableComponent("ftbranks.list_players_with", rank.getName()), false);
178214

179215
for (ServerPlayer player : source.getServer().getPlayerList().getPlayers()) {
180-
if (r.isActive(player)) {
216+
if (rank.isActive(player)) {
181217
source.sendSuccess(new TextComponent("- ").withStyle(ChatFormatting.YELLOW).append(player.getDisplayName()), false);
182218
}
183219
}
184220

185221
return 1;
186222
}
223+
224+
private static int setNode(CommandSourceStack source, Rank rank, String node, String value) throws CommandSyntaxException {
225+
try {
226+
rank.setPermission(node, strToPermissionValue(value));
227+
if (value != null) {
228+
source.sendSuccess(new TranslatableComponent("ftbranks.node_added", node, rank.getPermission(node), rank), false);
229+
} else {
230+
source.sendSuccess(new TranslatableComponent("ftbranks.node_removed", node, rank), false);
231+
}
232+
} catch (IllegalArgumentException e) {
233+
throw new SimpleCommandExceptionType(new TextComponent(e.getMessage())).create();
234+
}
235+
236+
return 1;
237+
}
238+
239+
private static int setCondition(CommandSourceStack source, Rank rank, String value) throws CommandSyntaxException {
240+
try {
241+
RankCondition condition;
242+
if (value.equals("default") || value.equals("\"\"")) {
243+
condition = new DefaultCondition(rank);
244+
} else if (value.startsWith("{") || value.contains(" ")) {
245+
condition = FTBRanksAPI.INSTANCE.getManager().createCondition(rank, SNBT.readLines(Collections.singletonList(value)));
246+
} else {
247+
condition = FTBRanksAPI.INSTANCE.getManager().createCondition(rank, StringTag.valueOf(value));
248+
}
249+
rank.setCondition(condition);
250+
source.sendSuccess(new TranslatableComponent("ftbranks.node_added", "condition", value, rank), false);
251+
} catch (Exception e) {
252+
throw new SimpleCommandExceptionType(new TextComponent(e.getMessage())).create();
253+
}
254+
255+
return 1;
256+
}
257+
258+
private static int showRank(CommandSourceStack source, Rank rank) {
259+
source.sendSuccess(new TextComponent("=".repeat(50)).withStyle(ChatFormatting.GREEN), false);
260+
261+
source.sendSuccess(new TranslatableComponent("ftbranks.show_rank.header", col(rank.getId(), ChatFormatting.WHITE), col(rank.getName(), ChatFormatting.WHITE), col(Integer.toString(rank.getPower()), ChatFormatting.WHITE)).withStyle(ChatFormatting.YELLOW), false);
262+
263+
String condStr = rank.getCondition().asString();
264+
Component c = condStr.isEmpty() ?
265+
new TranslatableComponent("ftbranks.show_rank.condition.default").withStyle(ChatFormatting.WHITE, ChatFormatting.ITALIC) :
266+
col(condStr, ChatFormatting.WHITE);
267+
source.sendSuccess(new TranslatableComponent("ftbranks.show_rank.condition", c).withStyle(ChatFormatting.YELLOW), false);
268+
269+
source.sendSuccess(new TranslatableComponent("ftbranks.show_rank.nodes").withStyle(ChatFormatting.YELLOW), false);
270+
rank.getPermissions().stream().sorted().forEach(node ->
271+
source.sendSuccess(new TranslatableComponent("ftbranks.show_rank.node", col(node, ChatFormatting.AQUA), rank.getPermission(node)).withStyle(ChatFormatting.WHITE), false)
272+
);
273+
274+
return 0;
275+
}
276+
277+
private static MutableComponent col(String str, ChatFormatting color) {
278+
return new TextComponent(str).withStyle(color);
279+
}
280+
281+
private static PermissionValue strToPermissionValue(String str) {
282+
if (str == null) {
283+
return null;
284+
} else if (str.startsWith("\"") && str.endsWith("\"")) {
285+
return StringPermissionValue.of(str.substring(1, str.length() - 1));
286+
} if (str.equalsIgnoreCase("true") || str.equalsIgnoreCase("false")) {
287+
return BooleanPermissionValue.of(str.equalsIgnoreCase("true"));
288+
} else if (NumberUtils.isCreatable(str)) {
289+
return NumberPermissionValue.of(NumberUtils.createNumber(str));
290+
} else {
291+
return StringPermissionValue.of(str);
292+
}
293+
}
187294
}

0 commit comments

Comments
 (0)