Skip to content

Commit 59da66c

Browse files
committed
Merge branch 'feature/21.5' into dev
2 parents d0969f7 + 5e68248 commit 59da66c

File tree

13 files changed

+46
-46
lines changed

13 files changed

+46
-46
lines changed

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 "1.7-SNAPSHOT" apply false
3+
id "dev.architectury.loom" version "1.10-SNAPSHOT" apply false
44
id "me.modmuss50.mod-publish-plugin" version "0.5.1"
55
}
66

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,8 +180,8 @@ private static Component makeRankNameClicky(Rank rank) {
180180
return Component.literal(rank.getName())
181181
.withStyle(isDef ? ChatFormatting.AQUA : ChatFormatting.YELLOW)
182182
.withStyle(Style.EMPTY
183-
.withClickEvent(new ClickEvent(Action.RUN_COMMAND, "/ftbranks show_rank " + rank.getId()))
184-
.withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, isDef ?
183+
.withClickEvent(new ClickEvent.RunCommand("/ftbranks show_rank " + rank.getId()))
184+
.withHoverEvent(new HoverEvent.ShowText(isDef ?
185185
Component.literal("Players must be explicitly added to this rank\nwith '/ftbranks add <player> " + rank.getId() + "'").withStyle(ChatFormatting.GRAY, ChatFormatting.ITALIC) :
186186
Component.literal("Rank condition: " + rank.getCondition().asString()).withStyle(ChatFormatting.GRAY, ChatFormatting.ITALIC))
187187
)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public static Component formatPlayerName(Player player, Component originalName)
2626
FTBRanks.LOGGER.error(s);
2727
return Component.literal("BrokenFormatting").withStyle(Style.EMPTY
2828
.withColor(ChatFormatting.RED)
29-
.withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, Component.literal(s)))
29+
.withHoverEvent(new HoverEvent.ShowText(Component.literal(s)))
3030
);
3131
}
3232
} else {

common/src/main/java/dev/ftb/mods/ftbranks/impl/PlayerRankData.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -92,22 +92,22 @@ SNBTCompoundTag writeSNBT() {
9292
}
9393

9494
static PlayerRankData fromSNBT(RankManagerImpl manager, UUID playerId, SNBTCompoundTag tag, Map<String,RankImpl> tempRanks) {
95-
PlayerRankData data = new PlayerRankData(manager, playerId, tag.getString("name"));
95+
PlayerRankData data = new PlayerRankData(manager, playerId, tag.getStringOr("name", ""));
9696

97-
SNBTCompoundTag ranksTag = tag.getCompound("ranks");
98-
for (String rankKey : ranksTag.getAllKeys()) {
97+
SNBTCompoundTag ranksTag = tag.getAsSnbtComponent("ranks");
98+
for (String rankKey : ranksTag.keySet()) {
9999
RankImpl rank = tempRanks.get(rankKey);
100100
if (rank != null) {
101101
try {
102-
data.added.put(rank, Instant.parse(ranksTag.getString(rankKey)));
102+
data.added.put(rank, Instant.parse(ranksTag.getStringOr(rankKey, "")));
103103
} catch (DateTimeParseException e) {
104104
throw new RankException(e.getMessage());
105105
}
106106
}
107107
}
108108

109-
SNBTCompoundTag permTag = tag.getCompound("permissions");
110-
for (String permKey : permTag.getAllKeys()) {
109+
SNBTCompoundTag permTag = tag.getAsSnbtComponent("permissions");
110+
for (String permKey : permTag.keySet()) {
111111
while (permKey.endsWith(".*")) {
112112
permKey = permKey.substring(0, permKey.length() - 2);
113113
manager.markPlayerDataDirty();
@@ -119,4 +119,4 @@ static PlayerRankData fromSNBT(RankManagerImpl manager, UUID playerId, SNBTCompo
119119

120120
return data;
121121
}
122-
}
122+
}

common/src/main/java/dev/ftb/mods/ftbranks/impl/RankImpl.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -155,14 +155,14 @@ public Collection<String> getPermissions() {
155155
}
156156

157157
public static RankImpl readSNBT(RankManagerImpl manager, String rankId, SNBTCompoundTag tag, RankFileSource source) throws RankException {
158-
String displayName = tag.getString("name").isEmpty() ? rankId : tag.getString("name");
159-
RankImpl rank = create(manager, rankId, displayName, tag.getInt("power"), source);
158+
String displayName = tag.getStringOr("name", rankId);
159+
RankImpl rank = create(manager, rankId, displayName, tag.getIntOr("power", 0), source); // TODO: A default of 0 might not be ideal
160160

161161
if (tag.contains("condition")) {
162162
rank.setCondition(manager.createCondition(rank, tag.get("condition")));
163163
}
164164

165-
for (String key : tag.getAllKeys()) {
165+
for (String key : tag.keySet()) {
166166
if (!SPECIAL_FIELDS.contains(key)) {
167167
while (key.endsWith(".*")) {
168168
key = key.substring(0, key.length() - 2);
@@ -203,4 +203,4 @@ public SNBTCompoundTag writeSNBT() {
203203
public RankFileSource getSource() {
204204
return source;
205205
}
206-
}
206+
}

common/src/main/java/dev/ftb/mods/ftbranks/impl/RankManagerImpl.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -140,11 +140,11 @@ public Set<Rank> getAddedRanks(GameProfile profile) {
140140
public RankCondition createCondition(Rank rank, @Nullable Tag tag) throws RankException {
141141
SNBTCompoundTag compoundTag = new SNBTCompoundTag();
142142
if (tag instanceof StringTag) {
143-
compoundTag.putString("type", tag.getAsString());
143+
compoundTag.putString("type", tag.asString().orElseThrow());
144144
} else if (tag instanceof SNBTCompoundTag c) {
145145
compoundTag = c;
146146
}
147-
String key = compoundTag.getString("type");
147+
String key = compoundTag.getStringOr("type", "");
148148
if (!conditions.containsKey(key)) {
149149
throw new IllegalArgumentException("Can't create condition from tag: '" + tag + "'");
150150
}
@@ -221,8 +221,8 @@ public void reload() throws Exception {
221221
Map<UUID, PlayerRankData> tempPlayerData = new LinkedHashMap<>();
222222
SNBTCompoundTag playerFileTag = SNBT.read(playerFile);
223223
if (playerFileTag != null) {
224-
for (String key : playerFileTag.getAllKeys()) {
225-
SNBTCompoundTag o = playerFileTag.getCompound(key);
224+
for (String key : playerFileTag.keySet()) {
225+
SNBTCompoundTag o = playerFileTag.getAsSnbtComponent(key);
226226
UUID id = UUID.fromString(key);
227227
PlayerRankData data = PlayerRankData.fromSNBT(this, id, o, tempRanks);
228228
tempPlayerData.put(id, data);
@@ -248,9 +248,9 @@ private void readRankFile(RankFileSource source, Map<String, RankImpl> rankMap)
248248
SNBTCompoundTag rankFileTag = SNBT.read(inputFile);
249249
if (rankFileTag != null) {
250250
int size = rankMap.size();
251-
for (String rankId : rankFileTag.getAllKeys()) {
251+
for (String rankId : rankFileTag.keySet()) {
252252
try {
253-
RankImpl rank = RankImpl.readSNBT(this, rankId, rankFileTag.getCompound(rankId), source);
253+
RankImpl rank = RankImpl.readSNBT(this, rankId, rankFileTag.getAsSnbtComponent(rankId), source);
254254
if (rankMap.putIfAbsent(rank.getId(), rank) != null) {
255255
FTBRanks.LOGGER.warn("Conflicting rank ID '{}' detected while reading {}, ignoring", rank.getId(), inputFile);
256256
}
@@ -372,17 +372,17 @@ void savePlayersNow() {
372372

373373
static PermissionValue ofTag(SNBTCompoundTag tag, String key) {
374374
if (tag.isBoolean(key)) {
375-
return BooleanPermissionValue.of(tag.getBoolean(key));
375+
return BooleanPermissionValue.of(tag.getBooleanOr(key, false)); // TODO: False default might not be ideal
376376
}
377377

378378
Tag v = tag.get(key);
379379

380380
if (v == null || v instanceof EndTag) {
381381
return PermissionValue.MISSING;
382382
} else if (v instanceof NumericTag) {
383-
return NumberPermissionValue.of(((NumericTag) v).getAsNumber());
383+
return NumberPermissionValue.of(v.asNumber().orElseThrow());
384384
} else if (v instanceof StringTag) {
385-
return StringPermissionValue.of(v.getAsString());
385+
return StringPermissionValue.of(v.asString().orElseThrow());
386386
}
387387

388388
return StringPermissionValue.of(v.toString());
@@ -404,4 +404,4 @@ static SNBTCompoundTag writePermissions(Map<String, PermissionValue> map, SNBTCo
404404
});
405405
return res;
406406
}
407-
}
407+
}

common/src/main/java/dev/ftb/mods/ftbranks/impl/condition/DimensionCondition.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public class DimensionCondition implements RankCondition {
1212
private final ResourceKey<Level> dimension;
1313

1414
public DimensionCondition(SNBTCompoundTag tag) {
15-
dimension = ResourceKey.create(Registries.DIMENSION, ResourceLocation.parse(tag.getString("dimension")));
15+
dimension = ResourceKey.create(Registries.DIMENSION, ResourceLocation.parse(tag.getStringOr("dimension", "")));
1616
}
1717

1818
@Override
@@ -29,4 +29,4 @@ public boolean isRankActive(ServerPlayer player) {
2929
public void save(SNBTCompoundTag tag) {
3030
tag.putString("dimension", dimension.location().toString());
3131
}
32-
}
32+
}

common/src/main/java/dev/ftb/mods/ftbranks/impl/condition/PlaytimeCondition.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@ public class PlaytimeCondition implements RankCondition {
2121
private final Stat<ResourceLocation> stat;
2222

2323
public PlaytimeCondition(SNBTCompoundTag tag) {
24-
time = tag.getInt("time");
24+
time = tag.getIntOr("time", 0);
2525

2626
if (!tag.contains("time_unit")) {
2727
FTBRanks.LOGGER.warn("missing 'time_unit' field in playtime condition - assuming 'ticks'");
2828
}
29-
switch (tag.getString("time_unit")) {
29+
switch (tag.getStringOr("time_unit", "seconds")) {
3030
case "seconds" -> timeUnit = SECONDS;
3131
case "minutes" -> timeUnit = MINUTES;
3232
case "hours" -> timeUnit = HOURS;
@@ -61,4 +61,4 @@ public void save(SNBTCompoundTag tag) {
6161
default -> tag.putString("time_unit", "ticks");
6262
}
6363
}
64-
}
64+
}

common/src/main/java/dev/ftb/mods/ftbranks/impl/condition/RankAddedCondition.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public class RankAddedCondition implements RankCondition {
1111

1212
public RankAddedCondition(Rank r, SNBTCompoundTag tag) {
1313
original = r;
14-
id = tag.getString("rank");
14+
id = tag.getStringOr("rank", "");
1515
}
1616

1717
@Override

common/src/main/java/dev/ftb/mods/ftbranks/impl/condition/StatCondition.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,15 @@ public class StatCondition implements RankCondition {
2424
private final Stat<?> stat;
2525

2626
public StatCondition(SNBTCompoundTag tag) {
27-
statId = ResourceLocation.parse(tag.getString("stat"));
27+
statId = ResourceLocation.parse(tag.getStringOr("stat", ""));
2828
stat = BuiltInRegistries.CUSTOM_STAT.getOptional(statId)
2929
.map(Stats.CUSTOM::get)
3030
.orElseThrow(() ->
3131
new NoSuchElementException(String.format("%s does not match any known stat", statId))
3232
);
33-
value = tag.getInt("value");
33+
value = tag.getIntOr("value", 0);
3434

35-
switch (tag.getString("value_check")) {
35+
switch (tag.getStringOr("value_check", "")) {
3636
case "not_equals", "not", "!=" -> valueCheck = NOT_EQUALS;
3737
case "greater", ">" -> valueCheck = GREATER;
3838
case "greater_or_equal", ">=" -> valueCheck = GREATER_OR_EQUAL;
@@ -75,4 +75,4 @@ public void save(SNBTCompoundTag tag) {
7575
default -> tag.putString("value_check", "==");
7676
}
7777
}
78-
}
78+
}

0 commit comments

Comments
 (0)