mirror of
https://github.com/PikaMug/Quests.git
synced 2025-01-10 18:38:11 +01:00
Merge pull request #75 from PikachuEXE/feature/cmd/admin/remove-completed-quest-offline
Feature/cmd/admin/remove completed quest offline
This commit is contained in:
commit
c760ee2fff
@ -2477,8 +2477,14 @@ public class Quester {
|
||||
|
||||
}
|
||||
|
||||
// #getPlayer is faster
|
||||
OfflinePlayer represented_player = getPlayer();
|
||||
if (represented_player == null) {
|
||||
represented_player = getOfflinePlayer();
|
||||
}
|
||||
|
||||
data.set("hasJournal", hasJournal);
|
||||
data.set("lastKnownName", getPlayer().getName());
|
||||
data.set("lastKnownName", represented_player.getName());
|
||||
|
||||
return data;
|
||||
|
||||
|
@ -15,6 +15,7 @@ import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import org.apache.commons.lang.Validate;
|
||||
|
||||
import me.blackvein.quests.exceptions.InvalidStageException;
|
||||
import me.blackvein.quests.prompts.QuestAcceptPrompt;
|
||||
@ -38,6 +39,7 @@ import org.bukkit.DyeColor;
|
||||
import org.bukkit.Effect;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
@ -1572,15 +1574,17 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener,
|
||||
return;
|
||||
}
|
||||
|
||||
Player target_online_player = PlayerFinder.findOnlinePlayerByPartialCaseInsensitiveNameMatch(args[1]);
|
||||
OfflinePlayer target_offline_player = PlayerFinder.findOfflinePlayerWithNameByExactCaseInsensitiveNameMatch(args[1]);
|
||||
|
||||
// Reject usage without matching online player
|
||||
if (target_online_player == null) {
|
||||
// According to CraftBukkit implementation, OfflinePlayer#getName could be null,
|
||||
// meaning the player has NOT been seen on current server
|
||||
// To avoid displaying stats with name `null`, we consider this as player not found
|
||||
if (target_offline_player == null) {
|
||||
cs.sendMessage(YELLOW + Lang.get("playerNotFound"));
|
||||
return;
|
||||
}
|
||||
|
||||
questsStats(target_online_player, cs);
|
||||
questsStats(target_offline_player, cs);
|
||||
}
|
||||
|
||||
private void adminRemoveCompletedQuest(final CommandSender cs, String[] args) {
|
||||
@ -1590,10 +1594,12 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener,
|
||||
return;
|
||||
}
|
||||
|
||||
Player target_online_player = PlayerFinder.findOnlinePlayerByExactCaseInsensitiveNameMatch(args[1]);
|
||||
OfflinePlayer target_offline_player = PlayerFinder.findOfflinePlayerWithNameByExactCaseInsensitiveNameMatch(args[1]);
|
||||
|
||||
// Reject usage without matching online player
|
||||
if (target_online_player == null) {
|
||||
// According to CraftBukkit implementation, OfflinePlayer#getName could be null,
|
||||
// meaning the player has NOT been seen on current server
|
||||
// To avoid saving data with name `null`, we consider this as player not found
|
||||
if (target_offline_player == null) {
|
||||
cs.sendMessage(YELLOW + Lang.get("playerNotFound"));
|
||||
return;
|
||||
}
|
||||
@ -1604,16 +1610,16 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener,
|
||||
return;
|
||||
}
|
||||
|
||||
UUID target_online_player_uuid = target_online_player.getUniqueId();
|
||||
Quester quester = getQuester(target_online_player_uuid);
|
||||
UUID player_uuid = target_offline_player.getUniqueId();
|
||||
Quester quester = getQuester(player_uuid);
|
||||
|
||||
// We do NOT care whather the quester is taking the quest
|
||||
|
||||
String msg = Lang.get("removedQuestFromQuesterCompletedQuests");
|
||||
msg = msg.replaceAll("<player>", GREEN + target_online_player.getName() + GOLD);
|
||||
msg = msg.replaceAll("<player>", GREEN + target_offline_player.getName() + GOLD);
|
||||
msg = msg.replaceAll("<quest>", ChatColor.DARK_PURPLE + quest_to_be_remove.name + ChatColor.AQUA);
|
||||
cs.sendMessage(GOLD + msg);
|
||||
cs.sendMessage(PURPLE + " UUID: " + DARKAQUA + target_online_player_uuid);
|
||||
cs.sendMessage(PURPLE + " UUID: " + DARKAQUA + player_uuid);
|
||||
|
||||
quester.removeCompletedQuests(quest_to_be_remove);
|
||||
}
|
||||
@ -1808,18 +1814,16 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener,
|
||||
}
|
||||
|
||||
private void questsStats(final Player player) {
|
||||
questsStats(player, null);
|
||||
Validate.notNull(player);
|
||||
questsStats(player, player);
|
||||
}
|
||||
|
||||
private void questsStats(final Player player, final CommandSender customMessageTarget) {
|
||||
private void questsStats(final OfflinePlayer offlinePlayer, final CommandSender messageTarget) {
|
||||
Validate.notNull(offlinePlayer);
|
||||
Validate.notNull(messageTarget);
|
||||
|
||||
CommandSender messageTarget = player;
|
||||
if (customMessageTarget != null) {
|
||||
messageTarget = customMessageTarget;
|
||||
}
|
||||
|
||||
Quester quester = getQuester(player.getUniqueId());
|
||||
messageTarget.sendMessage(GOLD + "- " + player.getName() + " -");
|
||||
Quester quester = getQuester(offlinePlayer.getUniqueId());
|
||||
messageTarget.sendMessage(GOLD + "- " + offlinePlayer.getName() + " -");
|
||||
messageTarget.sendMessage(YELLOW + Lang.get("questPointsDisplay") + " " + PURPLE + quester.questPoints + "/" + totalQuestPoints);
|
||||
if (quester.currentQuests.isEmpty()) {
|
||||
messageTarget.sendMessage(YELLOW + Lang.get("currentQuest") + " " + PURPLE + Lang.get("none"));
|
||||
|
@ -1,8 +1,12 @@
|
||||
package me.blackvein.quests.util;
|
||||
|
||||
import com.evilmidget38.UUIDFetcher;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class PlayerFinder {
|
||||
|
||||
public static Player findOnlinePlayerByPartialCaseInsensitiveNameMatch(String queryString) {
|
||||
@ -31,4 +35,42 @@ public class PlayerFinder {
|
||||
return target_online_player;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param queryString player name
|
||||
* @return according to Bukkit.getOfflinePlayer, always an object (never null)
|
||||
*/
|
||||
public static OfflinePlayer findOfflinePlayerByExactCaseInsensitiveNameMatch(String queryString) {
|
||||
UUID target_offline_player_uuid;
|
||||
|
||||
try {
|
||||
target_offline_player_uuid = UUIDFetcher.getUUIDOf(queryString);
|
||||
}
|
||||
catch (Exception ex) {
|
||||
return null;
|
||||
}
|
||||
if (target_offline_player_uuid == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return Bukkit.getOfflinePlayer(target_offline_player_uuid);
|
||||
}
|
||||
|
||||
//
|
||||
/**
|
||||
* According to CraftBukkit implementation, OfflinePlayer#getName could be null,
|
||||
* meaning the player has NOT been seen on current server
|
||||
* To avoid usage of #getName being null at the end, this method return null instead
|
||||
*
|
||||
* @param queryString player name
|
||||
* @return {@code null} if the value of #getName is null
|
||||
*/
|
||||
public static OfflinePlayer findOfflinePlayerWithNameByExactCaseInsensitiveNameMatch(String queryString) {
|
||||
OfflinePlayer player_found = findOfflinePlayerByExactCaseInsensitiveNameMatch(queryString);
|
||||
if (player_found.getName() == null) {
|
||||
return null;
|
||||
}
|
||||
return player_found;
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user