diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index 926eb54d10..14002072ff 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -29,23 +29,17 @@ jobs: # 1. Check out the current working tree - name: Checkout repository - uses: actions/checkout@v3 + uses: actions/checkout@v4.1.1 # 2. Setup Java 17 JDK (Adopt) - name: Java 17 setup - uses: actions/setup-java@v3 + uses: actions/setup-java@v4.2.0 with: distribution: 'adopt' java-package: jdk java-version: '17' - - # 3. Setup local Maven package cache to speed up building - - name: Cache Maven packages - uses: actions/cache@v3 - with: - path: ~/.m2 - key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }} - restore-keys: ${{ runner.os }}-m2 + check-latest: true + cache: 'maven' # 4. Build via Maven - name: Build via Maven @@ -53,7 +47,7 @@ jobs: # 5. Upload via Github Actions - name: Upload - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4.3.1 with: name: mcMMO path: target/mcMMO-*.jar diff --git a/pom.xml b/pom.xml index fed0afa993..a30c123451 100644 --- a/pom.xml +++ b/pom.xml @@ -75,7 +75,7 @@ maven-surefire-plugin - 3.0.0-M7 + 3.2.5 org.junit.jupiter:junit-jupiter @@ -84,7 +84,7 @@ maven-failsafe-plugin - 3.0.0-M7 + 3.2.5 org.junit.jupiter:junit-jupiter @@ -95,12 +95,12 @@ org.apache.maven.plugins maven-release-plugin - 3.0.0-M6 + 3.0.1 org.apache.maven.plugins maven-compiler-plugin - 3.10.1 + 3.12.1 17 diff --git a/src/main/java/com/gmail/nossr50/commands/player/MctopCommand.java b/src/main/java/com/gmail/nossr50/commands/player/MctopCommand.java index 1df80b0495..4d9cadf210 100644 --- a/src/main/java/com/gmail/nossr50/commands/player/MctopCommand.java +++ b/src/main/java/com/gmail/nossr50/commands/player/MctopCommand.java @@ -78,12 +78,12 @@ private void display(int page, PrimarySkillType skill, CommandSender sender, Com return; } - if (sender instanceof Player) { + if (sender instanceof Player player) { if (!CommandUtils.hasPlayerDataKey(sender)) { return; } - McMMOPlayer mcMMOPlayer = UserManager.getPlayer(sender.getName()); + McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player); long cooldownMillis = Math.max(mcMMO.p.getGeneralConfig().getDatabasePlayerCooldown(), 1750); if (mcMMOPlayer.getDatabaseATS() + cooldownMillis > System.currentTimeMillis()) { @@ -96,11 +96,11 @@ private void display(int page, PrimarySkillType skill, CommandSender sender, Com return; } - if (((Player) sender).hasMetadata(MetadataConstants.METADATA_KEY_DATABASE_COMMAND)) { + if (player.hasMetadata(MetadataConstants.METADATA_KEY_DATABASE_COMMAND)) { sender.sendMessage(LocaleLoader.getString("Commands.Database.Processing")); return; } else { - ((Player) sender).setMetadata(MetadataConstants.METADATA_KEY_DATABASE_COMMAND, new FixedMetadataValue(mcMMO.p, null)); + player.setMetadata(MetadataConstants.METADATA_KEY_DATABASE_COMMAND, new FixedMetadataValue(mcMMO.p, null)); } mcMMOPlayer.actualizeDatabaseATS(); diff --git a/src/main/java/com/gmail/nossr50/placeholders/PapiExpansion.java b/src/main/java/com/gmail/nossr50/placeholders/PapiExpansion.java index 1dc5460c49..777ad4dc5b 100644 --- a/src/main/java/com/gmail/nossr50/placeholders/PapiExpansion.java +++ b/src/main/java/com/gmail/nossr50/placeholders/PapiExpansion.java @@ -2,6 +2,7 @@ import com.gmail.nossr50.api.ExperienceAPI; import com.gmail.nossr50.config.experience.ExperienceConfig; +import com.gmail.nossr50.datatypes.database.PlayerStat; import com.gmail.nossr50.datatypes.party.Party; import com.gmail.nossr50.datatypes.player.McMMOPlayer; import com.gmail.nossr50.datatypes.skills.PrimarySkillType; @@ -15,6 +16,7 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.util.List; public class PapiExpansion extends PlaceholderExpansion { public static final String SKILL_LEVEL = "level_"; @@ -34,6 +36,10 @@ public class PapiExpansion extends PlaceholderExpansion { public static final String IS_EXP_EVENT_ACTIVE = "is_xp_event_active"; public static final String MCABILITY = "mcability"; public static final String MCNOTIFY = "mcnotify"; + public static final String TOP_POWER_LEVEL = "top_power_"; + public static final String NAME = "name"; + public static final String LEVEL = "level"; + public List topPowerLevel = getTopPowerLevel(); public PapiExpansion() { } @@ -71,9 +77,38 @@ public String onPlaceholderRequest(final Player player, @NotNull final String pa return String.valueOf(mcMMO.p.getGeneralConfig().getPowerLevelCap()); } + if (params.startsWith(TOP_POWER_LEVEL)) { + String sub = params.substring(TOP_POWER_LEVEL.length()); + String[] split = sub.split("_"); + if (split.length != 2) { + return "top param not valid. Use top_power_name_0 or top_power_level_0."; + } + String type = split[0]; + String rank = split[1]; + if (type.equalsIgnoreCase(NAME)) { + if (Integer.parseInt(rank) >= topPowerLevel.size()) { + return "No player found at that rank."; + } + return topPowerLevel.get(Integer.parseInt(rank)).name; + } else if (type.equalsIgnoreCase(LEVEL)) { + if (Integer.parseInt(rank) >= topPowerLevel.size()) { + return "No player found at that rank."; + } + return String.valueOf(topPowerLevel.get(Integer.parseInt(rank)).statVal); + } + } + final McMMOPlayer user = UserManager.getPlayer(player); if (user == null) return null; + //Player configuration + if (params.equalsIgnoreCase(MCABILITY)) { + return user.getAbilityUse() ? PlaceholderAPIPlugin.booleanTrue() : PlaceholderAPIPlugin.booleanFalse(); + } + if (params.equalsIgnoreCase(MCNOTIFY)) { + return user.useChatNotifications() ? PlaceholderAPIPlugin.booleanTrue() : PlaceholderAPIPlugin.booleanFalse(); + } + if (params.startsWith(SKILL_LEVEL)) { PrimarySkillType skill = PrimarySkillType.valueOf(params.substring(SKILL_LEVEL.length()).toUpperCase()); return skill == null ? null : String.valueOf(user.getSkillLevel(skill)); @@ -115,14 +150,6 @@ else if (Permissions.oneAndOneTenthXp(player, skill)) return String.valueOf(user.getPowerLevel()); } - //Player configuration - if (params.equalsIgnoreCase(MCABILITY)) { - return user.getAbilityUse() ? PlaceholderAPIPlugin.booleanTrue() : PlaceholderAPIPlugin.booleanFalse(); - } - if (params.equalsIgnoreCase(MCNOTIFY)) { - return user.useChatNotifications() ? PlaceholderAPIPlugin.booleanTrue() : PlaceholderAPIPlugin.booleanFalse(); - } - //Party placeholders final Party party = user.getParty(); @@ -142,4 +169,9 @@ else if (Permissions.oneAndOneTenthXp(player, skill)) return null; } + @NotNull + private List getTopPowerLevel() { + return mcMMO.getDatabaseManager().readLeaderboard(null, 1, 10); + } + } diff --git a/src/main/java/com/gmail/nossr50/runnables/commands/MctopCommandDisplayTask.java b/src/main/java/com/gmail/nossr50/runnables/commands/MctopCommandDisplayTask.java index ed1a2f73cb..c193617737 100644 --- a/src/main/java/com/gmail/nossr50/runnables/commands/MctopCommandDisplayTask.java +++ b/src/main/java/com/gmail/nossr50/runnables/commands/MctopCommandDisplayTask.java @@ -21,7 +21,8 @@ public class MctopCommandDisplayTask extends CancellableRunnable { private final CommandSender sender; private final PrimarySkillType skill; private final int page; - private final boolean useBoard, useChat; + private final boolean useBoard; + private final boolean useChat; MctopCommandDisplayTask(List userStats, int page, PrimarySkillType skill, CommandSender sender, boolean useBoard, boolean useChat) { this.userStats = userStats; @@ -42,28 +43,25 @@ public void run() { displayChat(); } - if (sender instanceof Player) { - ((Player) sender).removeMetadata(MetadataConstants.METADATA_KEY_DATABASE_COMMAND, mcMMO.p); - } - if(sender instanceof Player) + if (sender instanceof Player player) { + player.removeMetadata(MetadataConstants.METADATA_KEY_DATABASE_COMMAND, mcMMO.p); sender.sendMessage(LocaleLoader.getString("Commands.mctop.Tip")); + + } } private void displayChat() { if (skill == null) { - if(sender instanceof Player) { + if (sender instanceof Player) { sender.sendMessage(LocaleLoader.getString("Commands.PowerLevel.Leaderboard")); - } - else { + } else { sender.sendMessage(ChatColor.stripColor(LocaleLoader.getString("Commands.PowerLevel.Leaderboard"))); } - } - else { - if(sender instanceof Player) { + } else { + if (sender instanceof Player) { sender.sendMessage(LocaleLoader.getString("Commands.Skill.Leaderboard", mcMMO.p.getSkillTools().getLocalizedSkillName(skill))); - } - else { + } else { sender.sendMessage(ChatColor.stripColor(LocaleLoader.getString("Commands.Skill.Leaderboard", mcMMO.p.getSkillTools().getLocalizedSkillName(skill)))); } } @@ -74,13 +72,12 @@ private void displayChat() { // Format: // 01. Playername - skill value // 12. Playername - skill value - if(sender instanceof Player) { - sender.sendMessage(String.format("%2d. %s%s - %s%s", place, ChatColor.GREEN, stat.name, ChatColor.WHITE, stat.statVal)); - } - else { - sender.sendMessage(String.format("%2d. %s - %s", place, stat.name, stat.statVal)); + if (sender instanceof Player) { + sender.sendMessage(String.format("#%02d - %s%s - %s%s", place, ChatColor.GREEN, stat.name, ChatColor.WHITE, stat.statVal)); + } else { + sender.sendMessage(String.format("#%02d - %s - %s", place, stat.name, stat.statVal)); } - + place++; } } @@ -88,8 +85,7 @@ private void displayChat() { private void displayBoard() { if (skill == null) { ScoreboardManager.showTopPowerScoreboard((Player) sender, page, userStats); - } - else { + } else { ScoreboardManager.showTopScoreboard((Player) sender, skill, page, userStats); } }