Skip to content

Commit

Permalink
chore: ported to 1.20
Browse files Browse the repository at this point in the history
  • Loading branch information
desht committed Jun 13, 2023
1 parent a99d439 commit 141292b
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 39 deletions.
50 changes: 25 additions & 25 deletions common/src/main/java/dev/ftb/mods/ftbranks/FTBRanksCommands.java
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ private static String normalizeRankName(String name) {
private static int reloadRanks(CommandSourceStack source) {
try {
FTBRanksAPIImpl.manager.reload();
source.sendSuccess(Component.literal("Ranks reloaded from disk!"), true);
source.sendSuccess(() -> Component.literal("Ranks reloaded from disk!"), true);

for (ServerPlayer p : source.getServer().getPlayerList().getPlayers()) {
source.getServer().getPlayerList().sendPlayerPermissionLevel(p);
Expand All @@ -172,15 +172,15 @@ private static int refreshReadme(CommandSourceStack source) {
ex.printStackTrace();
}

source.sendSuccess(Component.literal("README file refreshed!"), false);
source.sendSuccess(() -> Component.literal("README file refreshed!"), false);
return 1;
}

private static int listAllRanks(CommandSourceStack source) {
source.sendSuccess(Component.literal("Ranks:"), false);
source.sendSuccess(() -> Component.literal("Ranks:"), false);

for (Rank rank : FTBRanksAPIImpl.manager.getAllRanks()) {
source.sendSuccess(Component.literal("- " + rank.getName()).withStyle(rank.getCondition().isDefaultCondition() ? ChatFormatting.AQUA : ChatFormatting.YELLOW), false);
source.sendSuccess(() -> Component.literal("- " + rank.getName()).withStyle(rank.getCondition().isDefaultCondition() ? ChatFormatting.AQUA : ChatFormatting.YELLOW), false);
}

return 1;
Expand All @@ -195,14 +195,14 @@ private static int createRank(CommandSourceStack source, String name, int power)
}

FTBRanksAPIImpl.manager.createRank(id, name, power);
source.sendSuccess(Component.literal("Rank '" + id + "' created!"), false);
source.sendSuccess(() -> Component.literal("Rank '" + id + "' created!"), false);
return 1;
}

private static int deleteRank(CommandSourceStack source, String rankName) throws CommandSyntaxException {
Rank rank = getRank(rankName);
FTBRanksAPI.manager().deleteRank(rank.getId());
source.sendSuccess(Component.literal("Rank '" + rank.getName() + "' deleted!"), false);
source.sendSuccess(() -> Component.literal("Rank '" + rank.getName() + "' deleted!"), false);

return 1;
}
Expand All @@ -211,7 +211,7 @@ private static int addRank(CommandSourceStack source, Collection<GameProfile> pl
Rank rank = getRank(rankName);
for (GameProfile profile : players) {
if (rank.add(profile)) {
source.sendSuccess(Component.literal(String.format("Player %s added to rank '%s'!", profile.getName(), rank.getName())), false);
source.sendSuccess(() -> Component.literal(String.format("Player %s added to rank '%s'!", profile.getName(), rank.getName())), false);
}
}

Expand All @@ -222,19 +222,19 @@ private static int removeRank(CommandSourceStack source, Collection<GameProfile>
Rank rank = getRank(rankName);
for (GameProfile profile : players) {
if (rank.remove(profile)) {
source.sendSuccess(Component.literal(String.format("Player %s removed from rank '%s'!", profile.getName(), rank.getName())), false);
source.sendSuccess(() -> Component.literal(String.format("Player %s removed from rank '%s'!", profile.getName(), rank.getName())), false);
}
}

return 1;
}

private static int listRanksOf(CommandSourceStack source, ServerPlayer player) {
source.sendSuccess(Component.literal(String.format("Ranks added to player '%s':", player.getGameProfile().getName())), false);
source.sendSuccess(() -> Component.literal(String.format("Ranks added to player '%s':", player.getGameProfile().getName())), false);

for (Rank rank : FTBRanksAPIImpl.manager.getAllRanks()) {
if (rank.isActive(player)) {
source.sendSuccess(Component.literal("- " + rank.getName()).withStyle(rank.getCondition().isDefaultCondition() ? ChatFormatting.AQUA : ChatFormatting.YELLOW), false);
source.sendSuccess(() -> Component.literal("- " + rank.getName()).withStyle(rank.getCondition().isDefaultCondition() ? ChatFormatting.AQUA : ChatFormatting.YELLOW), false);
}
}

Expand All @@ -244,11 +244,11 @@ private static int listRanksOf(CommandSourceStack source, ServerPlayer player) {
private static int listPlayersWith(CommandSourceStack source, String rankName) throws CommandSyntaxException {
Rank rank = getRank(rankName);

source.sendSuccess(Component.literal(String.format("Players with rank '%s':", rank.getName())), false);
source.sendSuccess(() -> Component.literal(String.format("Players with rank '%s':", rank.getName())), false);

for (ServerPlayer player : source.getServer().getPlayerList().getPlayers()) {
if (rank.isActive(player)) {
source.sendSuccess(Component.literal("- ").withStyle(ChatFormatting.YELLOW).append(player.getDisplayName()), false);
source.sendSuccess(() -> Component.literal("- ").withStyle(ChatFormatting.YELLOW).append(player.getDisplayName()), false);
}
}

Expand All @@ -260,14 +260,14 @@ private static int listNodes(CommandSourceStack source, String rankName) throws

Collection<String> nodes = rank.getPermissions();
if (nodes.isEmpty()) {
source.sendSuccess(Component.literal(String.format("No permission nodes in rank '%s'", rankName)).withStyle(ChatFormatting.GOLD), false);
source.sendSuccess(() -> Component.literal(String.format("No permission nodes in rank '%s'", rankName)).withStyle(ChatFormatting.GOLD), false);
} else {
source.sendSuccess(Component.literal(String.format("%d permission node(s) in rank '%s':", nodes.size(), rankName)).withStyle(ChatFormatting.GREEN), false);
source.sendSuccess(Component.literal("-".repeat(20)).withStyle(ChatFormatting.GREEN), false);
source.sendSuccess(() -> Component.literal(String.format("%d permission node(s) in rank '%s':", nodes.size(), rankName)).withStyle(ChatFormatting.GREEN), false);
source.sendSuccess(() -> Component.literal("-".repeat(20)).withStyle(ChatFormatting.GREEN), false);
nodes.forEach(node -> {
source.sendSuccess(Component.literal(String.format("%s = %s", node, rank.getPermission(node))).withStyle(ChatFormatting.YELLOW), false);
source.sendSuccess(() -> Component.literal(String.format("%s = %s", node, rank.getPermission(node))).withStyle(ChatFormatting.YELLOW), false);
});
source.sendSuccess(Component.literal("-".repeat(20)).withStyle(ChatFormatting.GREEN), false);
source.sendSuccess(() -> Component.literal("-".repeat(20)).withStyle(ChatFormatting.GREEN), false);
}

return 1;
Expand All @@ -279,9 +279,9 @@ private static int setNode(CommandSourceStack source, String rankName, String no
try {
rank.setPermission(node, PermissionValue.parse(value));
if (value != null) {
source.sendSuccess(Component.literal(String.format("Permission node '%s'='%s' added to rank '%s'", node, rank.getPermission(node), rank)), false);
source.sendSuccess(() -> Component.literal(String.format("Permission node '%s'='%s' added to rank '%s'", node, rank.getPermission(node), rank)), false);
} else {
source.sendSuccess(Component.literal(String.format("Permission node '%s' removed from rank '%s'", node, rank)), false);
source.sendSuccess(() -> Component.literal(String.format("Permission node '%s' removed from rank '%s'", node, rank)), false);
}
} catch (IllegalArgumentException e) {
throw new SimpleCommandExceptionType(Component.literal(e.getMessage())).create();
Expand All @@ -303,7 +303,7 @@ private static int setCondition(CommandSourceStack source, String rankName, Stri
condition = FTBRanksAPI.manager().createCondition(rank, StringTag.valueOf(value));
}
rank.setCondition(condition);
source.sendSuccess(Component.literal(String.format("Condition '%s' added to rank '%s'", value, rank)), false);
source.sendSuccess(() -> Component.literal(String.format("Condition '%s' added to rank '%s'", value, rank)), false);
} catch (Exception e) {
throw new SimpleCommandExceptionType(Component.literal(e.getMessage())).create();
}
Expand All @@ -314,18 +314,18 @@ private static int setCondition(CommandSourceStack source, String rankName, Stri
private static int showRank(CommandSourceStack source, String rankName) throws CommandSyntaxException {
Rank rank = getRank(rankName);

source.sendSuccess(Component.literal("=".repeat(50)).withStyle(ChatFormatting.GREEN), false);
source.sendSuccess(() -> Component.literal("=".repeat(50)).withStyle(ChatFormatting.GREEN), false);

source.sendSuccess(Component.literal(String.format("Rank ID: %s, Rank Name: %s, Power: %d", rank.getId(), rank.getName(), rank.getPower())).withStyle(ChatFormatting.YELLOW), false);
source.sendSuccess(() -> Component.literal(String.format("Rank ID: %s, Rank Name: %s, Power: %d", rank.getId(), rank.getName(), rank.getPower())).withStyle(ChatFormatting.YELLOW), false);

String condStr = rank.getCondition().asString();
Component c = condStr.isEmpty() ?
Component.literal("(none: players must be added)").withStyle(ChatFormatting.WHITE, ChatFormatting.ITALIC) : Component.literal(condStr);
source.sendSuccess(Component.literal("Condition: ").append(c).withStyle(ChatFormatting.YELLOW), false);
source.sendSuccess(() -> Component.literal("Condition: ").append(c).withStyle(ChatFormatting.YELLOW), false);

source.sendSuccess(Component.literal("Permission nodes:").withStyle(ChatFormatting.YELLOW), false);
source.sendSuccess(() -> Component.literal("Permission nodes:").withStyle(ChatFormatting.YELLOW), false);
rank.getPermissions().stream().sorted().forEach(node ->
source.sendSuccess(Component.literal(" - " + node + ": " + rank.getPermission(node)), false)
source.sendSuccess(() -> Component.literal(" - " + node + ": " + rank.getPermission(node)), false)
);

return 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public String getType() {

@Override
public boolean isRankActive(ServerPlayer player) {
return player.level.dimension() == dimension;
return player.level().dimension() == dimension;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ public String getType() {

@Override
public boolean isRankActive(ServerPlayer player) {
if (player.level instanceof ServerLevel && player.level.dimension() == Level.OVERWORLD && player.server.getSpawnProtectionRadius() > 0) {
BlockPos spawn = player.level.getSharedSpawnPos();
if (player.level() instanceof ServerLevel serverLevel && serverLevel.dimension() == Level.OVERWORLD && player.server.getSpawnProtectionRadius() > 0) {
BlockPos spawn = serverLevel.getSharedSpawnPos();
int x = Mth.abs(Mth.floor(player.getX()) - spawn.getX());
int z = Mth.abs(Mth.floor(player.getZ()) - spawn.getZ());
return Math.max(x, z) <= player.server.getSpawnProtectionRadius();
Expand Down
18 changes: 8 additions & 10 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
org.gradle.jvmargs=-Xmx3G
org.gradle.jvmargs=-Xmx2G
org.gradle.daemon=false
mod_id=ftbranks
archives_base_name=ftb-ranks
maven_group=dev.ftb.mods
mod_version=1904.1.1
mod_version=2000.1.1
mod_author=FTB Team

minecraft_version=1.19.4
architectury_version=8.1.75
ftb_library_version=1904.4.1-build.210-SNAPSHOT

fabric_loader_version=0.14.9
fabric_api_version=0.77.0+1.19.4

forge_version=45.0.47
minecraft_version=1.20
architectury_version=9.0.8
fabric_loader_version=0.14.21
fabric_api_version==0.83.0+1.20
ftb_library_version=2000.1.1-build.216-SNAPSHOT
forge_version=46.0.14

curseforge_id_forge=314905
curseforge_id_fabric=472659
Expand Down
2 changes: 1 addition & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ include("common")
include("fabric")
include("forge")

rootProject.name = 'FTB-Ranks-1.19.4'
rootProject.name = 'FTB-Ranks-1.20'

0 comments on commit 141292b

Please sign in to comment.