Revise new commands

This commit is contained in:
HappyPikachu 2015-04-15 12:11:44 -04:00
parent 0ebc32f40a
commit ee57773668
5 changed files with 135 additions and 198 deletions

View File

@ -3412,6 +3412,15 @@ if (quest != null) {
}
}
public void hardRemove(Quest quest) {
try {
completedQuests.remove(quest.name);
} catch (Exception ex) {
Logger.getLogger(Quests.class.getName()).log(Level.SEVERE, null, ex);
}
}
public void hardClear() {
@ -3445,15 +3454,4 @@ if (quest != null) {
}
/**
*
* @param quest quest to be removed
* @return {@code true} if completedQuests contained the specified quest
*/
public boolean removeCompletedQuests(Quest quest) {
boolean containedQuest = this.completedQuests.remove(quest.name);
this.saveData();
return containedQuest;
}
}

View File

@ -15,15 +15,12 @@ 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;
import me.blackvein.quests.util.ColorUtil;
import me.blackvein.quests.util.ItemUtil;
import me.blackvein.quests.util.Lang;
import me.blackvein.quests.util.MiscUtil;
import me.blackvein.quests.util.PlayerFinder;
import net.aufdemrand.denizen.Denizen;
import net.aufdemrand.denizencore.scripts.ScriptRegistry;
import net.citizensnpcs.api.CitizensAPI;
@ -39,7 +36,6 @@ 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;
@ -101,7 +97,6 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener,
public static mcMMO mcmmo = null;
public static Heroes heroes = null;
public static PhatLoots phatLoots = null;
public static boolean snoop = true;
public static boolean npcEffects = true;
public static boolean ignoreLockedQuests = false;
public static boolean genFilesOnJoin = true;
@ -332,6 +327,7 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener,
adminCommands.put(Lang.get("COMMAND_QUESTADMIN_STATS"), 2); // stats [player]
adminCommands.put(Lang.get("COMMAND_QUESTADMIN_GIVE"), 3); // give [player] [quest]
adminCommands.put(Lang.get("COMMAND_QUESTADMIN_QUIT"), 3); // quit [player] [quest]
adminCommands.put(Lang.get("COMMAND_QUESTADMIN_REMOVE"), 3); // remove [player] [quest]
adminCommands.put(Lang.get("COMMAND_QUESTADMIN_POINTS"), 3); // points [player] [amount]
adminCommands.put(Lang.get("COMMAND_QUESTADMIN_TAKEPOINTS"), 3); // takepoints [player] [amount]
adminCommands.put(Lang.get("COMMAND_QUESTADMIN_GIVEPOINTS"), 3); // givepoints [player] [amount]
@ -340,7 +336,6 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener,
adminCommands.put(Lang.get("COMMAND_QUESTADMIN_NEXTSTAGE"), 3); // nextstage [player] [quest]
adminCommands.put(Lang.get("COMMAND_QUESTADMIN_SETSTAGE"), 4); // setstage [player] [quest] [stage]
adminCommands.put(Lang.get("COMMAND_QUESTADMIN_PURGE"), 2); // purge [player]
adminCommands.put(Lang.get("COMMAND_QUESTADMIN_REMOVECOMPLETEDQUEST"), 3); // removecompletedquest [player] [quest]
adminCommands.put(Lang.get("COMMAND_QUESTADMIN_TOGGLEGUI"), 2); // togglegui [npc id]
adminCommands.put(Lang.get("COMMAND_QUESTADMIN_RELOAD"), 1); // reload
@ -538,7 +533,6 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener,
showQuestReqs = config.getBoolean("show-requirements", true);
allowQuitting = config.getBoolean("allow-quitting", true);
genFilesOnJoin = config.getBoolean("generate-files-on-join", true);
snoop = config.getBoolean("snoop", true);
npcEffects = config.getBoolean("show-npc-effects", true);
effect = config.getString("npc-effect", "note");
debug = config.getBoolean("debug-mode", false);
@ -839,9 +833,9 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener,
adminStats(cs, args);
} else if (args[0].equalsIgnoreCase(Lang.get("COMMAND_QUESTADMIN_REMOVECOMPLETEDQUEST"))) {
} else if (args[0].equalsIgnoreCase(Lang.get("COMMAND_QUESTADMIN_REMOVE"))) {
adminRemoveCompletedQuest(cs, args);
adminRemove(cs, args);
} else {
@ -1527,37 +1521,37 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener,
}
}
private void adminPurge(final CommandSender cs, String[] args) {
if (cs.hasPermission("quests.admin.*") || cs.hasPermission("quests.admin.purge")) {
UUID id;
try {
id = UUIDFetcher.getUUIDOf(args[1]);
Quester quester = getQuester(id);
if (quester.loadData() == false) {
cs.sendMessage(YELLOW + Lang.get("playerNotFound"));
return;
}
} catch (Exception e) {
Quester quester = getQuester(args[1]);
if (quester == null) {
cs.sendMessage(YELLOW + Lang.get("playerNotFound"));
return;
}
try {
quester.hardClear();
quester.saveData();
quester.updateJournal();
final File dataFolder = new File(this.getDataFolder(), "data/");
final File found = new File(dataFolder, id + ".yml");
final File found = new File(dataFolder, quester.id + ".yml");
found.delete();
addToBlacklist(id);
addToBlacklist(quester.id);
String msg = Lang.get("questPurged");
msg = msg.replaceAll("<player>", GREEN + Bukkit.getOfflinePlayer(id).getName() + GOLD);
if (Bukkit.getOfflinePlayer(quester.id).getName() != null) {
msg = msg.replaceAll("<player>", GREEN + Bukkit.getOfflinePlayer(quester.id).getName() + GOLD);
} else {
msg = msg.replaceAll("<player>", GREEN + args[1] + GOLD);
}
cs.sendMessage(GOLD + msg);
cs.sendMessage(PURPLE + " UUID: " + DARKAQUA + id);
cs.sendMessage(PURPLE + " UUID: " + DARKAQUA + quester.id);
} catch (Exception e) {
getLogger().info("Data file does not exist for " + id.toString());
getLogger().info("Data file does not exist for " + quester.id.toString());
}
} else {
@ -1566,62 +1560,57 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener,
}
}
private void adminStats(final CommandSender cs, String[] args) {
// Reject usage without permission
if (!cs.hasPermission("quests.admin.*") && !cs.hasPermission("quests.admin.stats")) {
cs.sendMessage(RED + Lang.get("questCmdNoPerms"));
return;
if (cs.hasPermission("quests.admin.*") && cs.hasPermission("quests.admin.stats")) {
questsStats(cs, args);
} else {
cs.sendMessage(RED + Lang.get("questCmdNoPerms"));
}
OfflinePlayer target_offline_player = PlayerFinder.findOfflinePlayerWithNameByExactCaseInsensitiveNameMatch(args[1]);
// 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_offline_player, cs);
}
private void adminRemoveCompletedQuest(final CommandSender cs, String[] args) {
// Reject usage without permission
if (!cs.hasPermission("quests.admin.*") && !cs.hasPermission("quests.admin.removecompletedquest")) {
cs.sendMessage(RED + Lang.get("questCmdNoPerms"));
return;
private void adminRemove(final CommandSender cs, String[] args) {
if (cs.hasPermission("quests.admin.*") && cs.hasPermission("quests.admin.remove")) {
Quester quester = getQuester(args[1]);
if (quester == null) {
cs.sendMessage(YELLOW + Lang.get("playerNotFound"));
return;
}
Quest toRemove = findQuest(MiscUtil.concatArgArray(args, 2, args.length - 1, ' '));
if (toRemove == null) {
cs.sendMessage(RED + Lang.get("questNotFound"));
return;
}
String msg = Lang.get("questRemoved");
if (Bukkit.getOfflinePlayer(quester.id).getName() != null) {
msg = msg.replaceAll("<player>", GREEN + Bukkit.getOfflinePlayer(quester.id).getName() + GOLD);
} else {
msg = msg.replaceAll("<player>", GREEN + args[1] + GOLD);
}
msg = msg.replaceAll("<quest>", ChatColor.DARK_PURPLE + toRemove.name + ChatColor.AQUA);
cs.sendMessage(GOLD + msg);
cs.sendMessage(PURPLE + " UUID: " + DARKAQUA + quester.id.toString());
quester.hardRemove(toRemove);
quester.saveData();
quester.updateJournal();
} else {
cs.sendMessage(RED + Lang.get("questCmdNoPerms"));
}
OfflinePlayer target_offline_player = PlayerFinder.findOfflinePlayerWithNameByExactCaseInsensitiveNameMatch(args[1]);
// 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;
}
Quest quest_to_be_remove = findQuest(MiscUtil.concatArgArray(args, 2, args.length - 1, ' '));
if (quest_to_be_remove == null) {
cs.sendMessage(RED + Lang.get("questNotFound"));
return;
}
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_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 + player_uuid);
quester.removeCompletedQuests(quest_to_be_remove);
}
private boolean questActionsCommandHandler(final CommandSender cs, String[] args) {
@ -1649,7 +1638,7 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener,
} else if (args[0].equalsIgnoreCase(Lang.get("COMMAND_STATS"))) {
questsStats((Player) cs);
questsStats(cs, null);
} else if (args[0].equalsIgnoreCase(Lang.get("COMMAND_JOURNAL"))) {
@ -1813,24 +1802,34 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener,
return true;
}
private void questsStats(final Player player) {
Validate.notNull(player);
questsStats(player, player);
}
private void questsStats(final CommandSender cs, String[] args) {
private void questsStats(final OfflinePlayer offlinePlayer, final CommandSender messageTarget) {
Validate.notNull(offlinePlayer);
Validate.notNull(messageTarget);
Quester quester = getQuester(offlinePlayer.getUniqueId());
messageTarget.sendMessage(GOLD + "- " + offlinePlayer.getName() + " -");
messageTarget.sendMessage(YELLOW + Lang.get("questPointsDisplay") + " " + PURPLE + quester.questPoints + "/" + totalQuestPoints);
Quester quester;
if (args != null) {
quester = getQuester(args[1]);
if (quester == null) {
cs.sendMessage(YELLOW + Lang.get("playerNotFound"));
return;
} else if (Bukkit.getOfflinePlayer(quester.id).getName() != null) {
cs.sendMessage(GOLD + "- " + Bukkit.getOfflinePlayer(quester.id).getName() + " -");
} else {
cs.sendMessage(GOLD + "- " + args[1] + " -");
}
} else {
quester = getQuester(((Player)cs).getUniqueId());
cs.sendMessage(GOLD + "- " + ((Player)cs).getName() + " -");
}
cs.sendMessage(YELLOW + Lang.get("questPointsDisplay") + " " + PURPLE + quester.questPoints);
if (quester.currentQuests.isEmpty()) {
messageTarget.sendMessage(YELLOW + Lang.get("currentQuest") + " " + PURPLE + Lang.get("none"));
cs.sendMessage(YELLOW + Lang.get("currentQuest") + " " + PURPLE + Lang.get("none"));
} else {
messageTarget.sendMessage(YELLOW + Lang.get("currentQuest"));
cs.sendMessage(YELLOW + Lang.get("currentQuest"));
for (Quest q : quester.currentQuests.keySet()) {
messageTarget.sendMessage(PINK + " - " + PURPLE + q.name);
cs.sendMessage(PINK + " - " + PURPLE + q.name);
}
}
@ -1857,8 +1856,8 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener,
}
messageTarget.sendMessage(YELLOW + Lang.get("completedQuestsTitle"));
messageTarget.sendMessage(completed);
cs.sendMessage(YELLOW + Lang.get("completedQuestsTitle"));
cs.sendMessage(completed);
}
private void questsJournal(final Player player) {
@ -2465,7 +2464,7 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener,
cs.sendMessage(DARKRED + "/questadmin " + RED + Lang.get("COMMAND_QUESTADMIN_NEXTSTAGE_HELP"));
cs.sendMessage(DARKRED + "/questadmin " + RED + Lang.get("COMMAND_QUESTADMIN_SETSTAGE_HELP"));
cs.sendMessage(DARKRED + "/questadmin " + RED + Lang.get("COMMAND_QUESTADMIN_PURGE_HELP"));
cs.sendMessage(DARKRED + "/questadmin " + RED + Lang.get("COMMAND_QUESTADMIN_REMOVECOMPLETEDQUEST_HELP"));
cs.sendMessage(DARKRED + "/questadmin " + RED + Lang.get("COMMAND_QUESTADMIN_REMOVE_HELP"));
cs.sendMessage(DARKRED + "/questadmin " + RED + Lang.get("COMMAND_QUESTADMIN_TOGGLEGUI_HELP"));
cs.sendMessage(DARKRED + "/questadmin " + RED + Lang.get("COMMAND_QUESTADMIN_RELOAD_HELP"));
} else{
@ -2502,8 +2501,8 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener,
if (cs.hasPermission("quests.admin.purge")) {
cs.sendMessage(DARKRED + "/questadmin " + RED + Lang.get("COMMAND_QUESTADMIN_PURGE_HELP"));
}
if (cs.hasPermission("quests.admin.removecompletedquest")) {
cs.sendMessage(DARKRED + "/questadmin " + RED + Lang.get("COMMAND_QUESTADMIN_REMOVECOMPLETEDQUEST_HELP"));
if (cs.hasPermission("quests.admin.remove")) {
cs.sendMessage(DARKRED + "/questadmin " + RED + Lang.get("COMMAND_QUESTADMIN_REMOVE_HELP"));
}
if (citizens != null && cs.hasPermission("quests.admin.togglegui")) {
cs.sendMessage(DARKRED + "/questadmin " + RED + Lang.get("COMMAND_QUESTADMIN_TOGGLEGUI_HELP"));
@ -2619,6 +2618,32 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener,
}
public Quester getQuester(String name) {
UUID id = null;
Quester quester = null;
for (Player p : Bukkit.getOnlinePlayers()) {
if (p.getName().equalsIgnoreCase(name)) {
id = p.getUniqueId();
break;
}
}
try {
if (id == null) {
id = UUIDFetcher.getUUIDOf(name);
}
} catch (Exception e) {
//Do nothing
}
if (id != null) {
quester = getQuester(id);
}
return quester;
}
public Map<UUID, Quester> getOnlineQuesters() {
Map<UUID, Quester> qs = new HashMap<UUID, Quester>();

View File

@ -164,8 +164,8 @@ public class Lang {
langMap.put("COMMAND_QUESTADMIN_PURGE", "purge");
langMap.put("COMMAND_QUESTADMIN_PURGE_HELP", "purge [player] - Clear all Quests data of a player");
langMap.put("COMMAND_QUESTADMIN_REMOVECOMPLETEDQUEST", "removecompletedquest");
langMap.put("COMMAND_QUESTADMIN_REMOVECOMPLETEDQUEST_HELP", "removecompletedquest [player] [quest] - Remove a Quest to a player's completed Quests");
langMap.put("COMMAND_QUESTADMIN_REMOVE", "remove");
langMap.put("COMMAND_QUESTADMIN_REMOVE_HELP", "remove [player] [quest] - Remove a completed Quest from a player");
langMap.put("COMMAND_QUESTADMIN_TOGGLEGUI", "togglegui");
langMap.put("COMMAND_QUESTADMIN_TOGGLEGUI_HELP", "togglegui [npc id] - Toggle GUI Quest Display on an NPC");
@ -926,7 +926,7 @@ public class Lang {
langMap.put("questForceNextStage", "<player> has advanced to the next Stage in the Quest <quest>.");
langMap.put("questForcedNextStage", "<player> has advanced you to the next Stage in your Quest <quest>.");
langMap.put("questPurged", "<player> has been purged and blacklisted.");
langMap.put("removedQuestFromQuesterCompletedQuests", "Quest <quest> has been removed from player <player>'s completed Quests.");
langMap.put("questRemoved", "Quest <quest> has been removed from player <player>'s completed Quests.");
langMap.put("settingAllQuestPoints", "Setting all players' Quest Points...");
langMap.put("allQuestPointsSet", "All players' Quest Points have been set to <number>!");

View File

@ -1,86 +0,0 @@
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 {
/**
*
* @param queryString String that contains part of player name
* @return if there is a player with exact name (case insensitive), return it
* else if there is a player with name which contains part of queryString, return it
* else {@code null}
*/
public static Player findOnlinePlayerByPartialCaseInsensitiveNameMatch(String queryString) {
Player target_online_player = findOnlinePlayerByExactCaseInsensitiveNameMatch(queryString);
if (target_online_player != null) {
return target_online_player;
}
for (Player online_player : Bukkit.getOnlinePlayers()) {
if (online_player.getName().toLowerCase().contains(queryString.toLowerCase())) {
target_online_player = online_player;
break;
}
}
return target_online_player;
}
public static Player findOnlinePlayerByExactCaseInsensitiveNameMatch(String queryString) {
Player target_online_player = null;
for (Player online_player : Bukkit.getOnlinePlayers()) {
if (online_player.getName().equalsIgnoreCase(queryString)) {
target_online_player = online_player;
break;
}
}
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;
}
}

View File

@ -70,8 +70,8 @@ permissions:
quests.admin.purge:
description: Clear all Quests data of a player
default: op
quests.admin.removecompletedquest:
description: Remove a Quest to a player's completed Quests
quests.admin.remove:
description: Remove a completed Quest from a player
default: op
quests.admin.togglegui:
description: Toggle GUI Quest Display on NPC's