Skip to content

Commit

Permalink
Added "pac setpropertyforeverysinglecourse (property) [value]"
Browse files Browse the repository at this point in the history
Added "pac setpropertyforeverysingleplayer (property) [value]"
  • Loading branch information
A5H73Y committed Nov 5, 2022
1 parent bb27168 commit b953f6c
Show file tree
Hide file tree
Showing 9 changed files with 95 additions and 33 deletions.
14 changes: 14 additions & 0 deletions docs/files/parkourCommands.json
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,20 @@
"consoleSyntax": "pac reset (course / player / leaderboard / prize / commands) (argument)",
"autoTabSyntax": "[course,player,leaderboard,prize,commands] {1:player=(player),*=(course)}"
},
{
"command": "setpropertyforeverysinglecourse",
"title": "Set Property for every Course",
"description": "Set the specified property for every single known Parkour Course, not providing a value will remove the property.",
"consoleSyntax": "pac setpropertyforeverysingleplayer (property) [value]",
"consoleOnly": true
},
{
"command": "setpropertyforeverysingleplayer",
"title": "Set Property for every Player",
"description": "Set the specified property for every single known Parkour player, not providing a value will remove the property.",
"consoleSyntax": "pac setpropertyforeverysingleplayer (property) [value]",
"consoleOnly": true
},
{
"command": "respawn",
"title": "Respawn to last Checkpoint",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,14 @@
import io.github.a5h73y.parkour.other.AbstractPluginReceiver;
import io.github.a5h73y.parkour.other.PluginBackupUtil;
import io.github.a5h73y.parkour.type.course.CourseConfig;
import io.github.a5h73y.parkour.type.player.PlayerConfig;
import io.github.a5h73y.parkour.utility.PlayerUtils;
import io.github.a5h73y.parkour.utility.PluginUtils;
import io.github.a5h73y.parkour.utility.StringUtils;
import io.github.a5h73y.parkour.utility.TranslationUtils;
import io.github.a5h73y.parkour.utility.ValidationUtils;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
Expand Down Expand Up @@ -375,13 +378,54 @@ public boolean onCommand(@NotNull CommandSender commandSender,
PluginBackupUtil.backupNow(true);
break;

case "setpropertyforeverysingleplayer":
if (!ValidationUtils.validateArgs(commandSender, args, 2)) {
return false;
}

setPropertyForEverySinglePlayerConfig(args[1], args.length == 3 ? args[2] : null);
break;

case "setpropertyforeverysinglecourse":
if (!ValidationUtils.validateArgs(commandSender, args, 2, 3)) {
return false;
}

setPropertyForEverySingleCourseConfig(args[1], args.length == 3 ? args[2] : null);
break;

default:
TranslationUtils.sendMessage(commandSender, "Unknown Command. Enter 'pac cmds' to display all console commands.");
break;
}
return true;
}

private void setPropertyForEverySinglePlayerConfig(String property, String value) {
parkour.getConfigManager().getAllPlayerUuids()
.forEach(uuid -> {
OfflinePlayer player = PlayerUtils.findPlayer(uuid);
PlayerConfig config = parkour.getConfigManager().getPlayerConfig(player);
if (value == null || value.trim().isEmpty()) {
config.remove(property);
} else {
config.set(property, value);
}
});
}

private void setPropertyForEverySingleCourseConfig(String property, String value) {
parkour.getConfigManager().getAllCourseNames()
.forEach(courseName -> {
CourseConfig config = parkour.getConfigManager().getCourseConfig(courseName);
if (value == null || value.trim().isEmpty()) {
config.remove(property);
} else {
config.set(property, value);
}
});
}

private void displayConsoleCommands() {
parkour.getParkourCommands().getCommandUsages().stream()
.filter(commandUsage -> commandUsage.getConsoleSyntax() != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,14 @@
import io.github.a5h73y.parkour.Parkour;
import io.github.a5h73y.parkour.other.AbstractPluginReceiver;
import io.github.a5h73y.parkour.type.player.PlayerConfig;
import io.github.a5h73y.parkour.utility.PlayerUtils;
import io.github.a5h73y.parkour.utility.StringUtils;
import io.github.a5h73y.parkour.utility.TranslationUtils;
import io.github.a5h73y.parkour.utility.ValidationUtils;
import io.github.a5h73y.parkour.utility.permission.Permission;
import io.github.a5h73y.parkour.utility.permission.PermissionUtils;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
Expand Down Expand Up @@ -166,13 +165,7 @@ public void processResetCommand(@NotNull CommandSender commandSender,
break;

case "player":
OfflinePlayer targetPlayer;

if (ValidationUtils.isUuidFormat(argument)) {
targetPlayer = Bukkit.getOfflinePlayer(UUID.fromString(argument));
} else {
targetPlayer = Bukkit.getOfflinePlayer(argument);
}
OfflinePlayer targetPlayer = PlayerUtils.findPlayer(argument);

if (!PlayerConfig.hasPlayerConfig(targetPlayer)) {
TranslationUtils.sendMessage(commandSender,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.OfflinePlayer;
Expand Down Expand Up @@ -269,13 +268,7 @@ public void resetPlayerCourseLeaderboards(CommandSender commandSender, String ta
return;
}

OfflinePlayer targetPlayer;

if (ValidationUtils.isUuidFormat(targetPlayerId)) {
targetPlayer = Bukkit.getOfflinePlayer(UUID.fromString(targetPlayerId));
} else {
targetPlayer = Bukkit.getOfflinePlayer(targetPlayerId);
}
OfflinePlayer targetPlayer = PlayerUtils.findPlayer(targetPlayerId);

if (!PlayerConfig.hasPlayerConfig(targetPlayer)) {
TranslationUtils.sendMessage(commandSender,
Expand Down Expand Up @@ -311,7 +304,8 @@ public void deleteNthLeaderboardRow(CommandSender commandSender, String courseNa
return;
}

parkour.getDatabaseManager().deletePlayerCourseTimes(PlayerUtils.findPlayer(result.getPlayerId()), courseName);
parkour.getDatabaseManager().deletePlayerCourseTimes(
PlayerUtils.findDatabasePlayer(result.getPlayerId()), courseName);
parkour.getPlaceholderApi().clearCache();
TranslationUtils.sendValueTranslation("Parkour.Delete", "Leaderboard row " + rowNumber, commandSender);
PluginUtils.logToFile("Leaderboard row " + rowNumber + " was deleted by " + commandSender.getName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1060,13 +1060,7 @@ public void processSetCommand(CommandSender commandSender, String... args) {
* @param targetPlayerId target player identifier
*/
public void resetPlayer(CommandSender commandSender, String targetPlayerId) {
OfflinePlayer targetPlayer;

if (ValidationUtils.isUuidFormat(targetPlayerId)) {
targetPlayer = Bukkit.getOfflinePlayer(UUID.fromString(targetPlayerId));
} else {
targetPlayer = Bukkit.getOfflinePlayer(targetPlayerId);
}
OfflinePlayer targetPlayer = PlayerUtils.findPlayer(targetPlayerId);

resetPlayer(targetPlayer);
TranslationUtils.sendValueTranslation("Parkour.Reset", targetPlayerId, commandSender);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import io.github.a5h73y.parkour.type.player.session.ParkourSession;
import io.github.a5h73y.parkour.type.player.session.ParkourSessionConfig;
import io.github.a5h73y.parkour.upgrade.ParkourUpgrader;
import io.github.a5h73y.parkour.utility.PlayerUtils;
import io.github.a5h73y.parkour.utility.PluginUtils;
import java.io.BufferedInputStream;
import java.io.File;
Expand All @@ -20,9 +21,7 @@
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.UUID;
import java.util.stream.Stream;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.inventory.ItemStack;
Expand Down Expand Up @@ -66,7 +65,7 @@ protected boolean doWork() {
}

ConfigurationSection playerSection = getConfig().getConfigurationSection(playerId);
OfflinePlayer player = Bukkit.getOfflinePlayer(UUID.fromString(playerId));
OfflinePlayer player = PlayerUtils.findPlayer(playerId);

if (playerSection != null) {
PlayerConfig newPlayerConfig = PlayerConfig.getConfig(player);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@
import io.github.a5h73y.parkour.type.player.PlayerConfig;
import io.github.a5h73y.parkour.upgrade.ParkourUpgrader;
import io.github.a5h73y.parkour.upgrade.TimedUpgradeTask;
import io.github.a5h73y.parkour.utility.PlayerUtils;
import java.util.List;
import java.util.UUID;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;

public class PlayerMinorUpgradeTask extends TimedUpgradeTask {
Expand All @@ -26,7 +25,7 @@ protected boolean doWork() {
List<String> uuids = getParkourUpgrader().getNewConfigManager().getAllPlayerUuids();

uuids.forEach(uuid -> {
OfflinePlayer player = Bukkit.getOfflinePlayer(UUID.fromString(uuid));
OfflinePlayer player = PlayerUtils.findPlayer(uuid);
PlayerConfig config = getParkourUpgrader().getNewConfigManager().getPlayerConfig(player);

updateConfigEntry(config, "Snapshot.JoinLocation", "JoinLocation");
Expand Down
15 changes: 13 additions & 2 deletions src/main/java/io/github/a5h73y/parkour/utility/PlayerUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ public static String padPlayerUuid(String playerId) {
*/
@NotNull
public static String findPlayerName(String uuid) {
OfflinePlayer player = findPlayer(uuid);
OfflinePlayer player = findDatabasePlayer(uuid);
return player.getName() != null ? player.getName() : "Unknown Player";
}

Expand All @@ -235,10 +235,21 @@ public static String findPlayerName(String uuid) {
* @param uuid uuid
* @return matching Player
*/
public static OfflinePlayer findPlayer(String uuid) {
public static OfflinePlayer findDatabasePlayer(String uuid) {
return Bukkit.getOfflinePlayer(UUID.fromString(padPlayerUuid(uuid)));
}

public static OfflinePlayer findPlayer(String playerId) {
OfflinePlayer result;
if (ValidationUtils.isUuidFormat(playerId)) {
result = Bukkit.getOfflinePlayer(UUID.fromString(playerId));
} else {
result = Bukkit.getOfflinePlayer(playerId);
}

return result;
}

/**
* Clear the Player's inventory and Armor.
* @param player player
Expand Down
14 changes: 14 additions & 0 deletions src/main/resources/parkourCommands.json
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,20 @@
"consoleSyntax": "pac reset (course / player / leaderboard / prize / commands) (argument)",
"autoTabSyntax": "[course,player,leaderboard,prize,commands] {1:player=(player),*=(course)}"
},
{
"command": "setpropertyforeverysinglecourse",
"title": "Set Property for every Course",
"description": "Set the specified property for every single known Parkour Course, not providing a value will remove the property.",
"consoleSyntax": "pac setpropertyforeverysingleplayer (property) [value]",
"consoleOnly": true
},
{
"command": "setpropertyforeverysingleplayer",
"title": "Set Property for every Player",
"description": "Set the specified property for every single known Parkour player, not providing a value will remove the property.",
"consoleSyntax": "pac setpropertyforeverysingleplayer (property) [value]",
"consoleOnly": true
},
{
"command": "respawn",
"title": "Respawn to last Checkpoint",
Expand Down

0 comments on commit b953f6c

Please sign in to comment.