Update blacklist, add purge sub-command

This commit is contained in:
HappyPikachu 2015-03-23 10:20:15 -04:00
parent dd75ec12ef
commit bff39b92cc
6 changed files with 85 additions and 14 deletions

View File

@ -25,8 +25,7 @@ public class NpcEffectThread implements Runnable {
}
@SuppressWarnings("deprecation")
@Override
@Override
public void run() {
for (Player player : plugin.getServer().getOnlinePlayers()) {

View File

@ -578,8 +578,7 @@ public class PlayerListener implements Listener, ColorUtil {
if (damager instanceof Projectile) {
Projectile projectile = (Projectile)damager;
@SuppressWarnings("deprecation")
ProjectileSource source = projectile.getShooter();
ProjectileSource source = projectile.getShooter();
if (source instanceof Player) {

View File

@ -335,6 +335,7 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener,
adminCommands.put(Lang.get("COMMAND_QUESTADMIN_FINISH"), 3); // finish [player] [quest]
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_TOGGLEGUI"), 2); // togglegui [npc id]
adminCommands.put(Lang.get("COMMAND_QUESTADMIN_RELOAD"), 1); // reload
@ -439,10 +440,10 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener,
getLogger().info("Saving Quester data.");
for (Player p : getServer().getOnlinePlayers()) {
Quester quester = getQuester(p.getUniqueId());
quester.saveData();
if (!questerBlacklist.contains(p.getUniqueId().toString())) {
Quester quester = getQuester(p.getUniqueId());
quester.saveData();
}
}
updateData();
@ -740,6 +741,13 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener,
@Override
public boolean onCommand(final CommandSender cs, Command cmd, String label, String[] args) {
if (cs instanceof Player) {
if (checkQuester(((Player)cs).getUniqueId()) == true) {
cs.sendMessage(RED + Lang.get("questBlacklisted"));
return true;
}
}
String error = checkCommand(cmd.getName(), args);
if(error != null) {
@ -818,6 +826,10 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener,
adminFinish(cs, args);
} else if (args[0].equalsIgnoreCase(Lang.get("COMMAND_QUESTADMIN_PURGE"))) {
adminPurge(cs, args);
} else {
cs.sendMessage(YELLOW + Lang.get("questsUnknownAdminCommand"));
@ -1519,6 +1531,45 @@ 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) {
cs.sendMessage(YELLOW + Lang.get("playerNotFound"));
return;
}
try {
final File dataFolder = new File(this.getDataFolder(), "data/");
final File found = new File(dataFolder, id + ".yml");
found.delete();
addToBlacklist(id);
String msg = Lang.get("questPurged");
msg = msg.replaceAll("<player>", GREEN + Bukkit.getOfflinePlayer(id).getName() + GOLD);
cs.sendMessage(GOLD + msg);
cs.sendMessage(PURPLE + " UUID: " + DARKAQUA + id);
} catch (Exception e) {
getLogger().info("Data file does not exist for " + id.toString());
}
} else {
cs.sendMessage(RED + Lang.get("questCmdNoPerms"));
}
}
private boolean questActionsCommandHandler(final CommandSender cs, String[] args) {
@ -2352,6 +2403,7 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener,
cs.sendMessage(DARKRED + "/questadmin " + RED + Lang.get("COMMAND_QUESTADMIN_FINISH_HELP"));
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_TOGGLEGUI_HELP"));
cs.sendMessage(DARKRED + "/questadmin " + RED + Lang.get("COMMAND_QUESTADMIN_RELOAD_HELP"));
} else{
@ -2382,6 +2434,9 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener,
if (cs.hasPermission("quests.admin.setstage")) {
cs.sendMessage(DARKRED + "/questadmin " + RED + Lang.get("COMMAND_QUESTADMIN_SETSTAGE_HELP"));
}
if (cs.hasPermission("quests.admin.purge")) {
cs.sendMessage(DARKRED + "/questadmin " + RED + Lang.get("COMMAND_QUESTADMIN_PURGE_HELP"));
}
if (citizens != null && cs.hasPermission("quests.admin.togglegui")) {
cs.sendMessage(DARKRED + "/questadmin " + RED + Lang.get("COMMAND_QUESTADMIN_TOGGLEGUI_HELP"));
}
@ -2476,16 +2531,16 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener,
if (quester == null) {
if (debug == true) {
if (debug == true && !questerBlacklist.contains(id.toString())) {
getLogger().log(Level.WARNING, "Quester data for UUID \"" + id.toString() + "\" not stored. Attempting manual data retrieval..");
}
quester = new Quester(this);
quester.id = id;
if (quester.loadData() == false) {
getLogger().severe("Quester not found for UUID \"" + id.toString() + "\". Consider adding it to the Quester blacklist.");
if (quester.loadData() == false && !questerBlacklist.contains(id.toString())) {
getLogger().info("Quester not found for UUID \"" + id.toString() + "\". Consider adding them to the Quester blacklist.");
} else {
if (debug == true) {
if (debug == true && !questerBlacklist.contains(id.toString())) {
getLogger().log(Level.INFO, "Manual data retrieval succeeded for UUID \"" + id.toString() + "\"");
}
questers.put(id, quester);
@ -5264,5 +5319,16 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener,
}
}
public void addToBlacklist(UUID id) {
List<String> blacklist = getConfig().getStringList("quester-blacklist");
if (!blacklist.contains(id.toString())) {
blacklist.add(id.toString());
getConfig().set("quester-blacklist", blacklist);
saveConfig();
}
if (!questerBlacklist.contains(id.toString())) {
questerBlacklist.add(id.toString());
}
}
}

View File

@ -157,6 +157,9 @@ public class Lang {
langMap.put("COMMAND_QUESTADMIN_SETSTAGE", "setstage");
langMap.put("COMMAND_QUESTADMIN_SETSTAGE_HELP", "setstage [player] [quest] [stage] - Set the current Stage for a player");
langMap.put("COMMAND_QUESTADMIN_SETSTAGE_USAGE", "Usage: /questadmin setstage [player] [quest] [stage]");
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_TOGGLEGUI", "togglegui");
langMap.put("COMMAND_QUESTADMIN_TOGGLEGUI_HELP", "togglegui [npc id] - Toggle GUI Quest Display on an NPC");
@ -916,6 +919,7 @@ public class Lang {
langMap.put("questForcedFinish", "<player> has forced you to finish your Quest <quest>.");
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("settingAllQuestPoints", "Setting all players' Quest Points...");
langMap.put("allQuestPointsSet", "All players' Quest Points have been set to <number>!");
@ -1060,6 +1064,7 @@ public class Lang {
//Error Messages
langMap.put("questErrorReadingFile", "Error reading Quests file.");
langMap.put("questSaveError", "An error occurred while saving.");
langMap.put("questBlacklisted", "You are blacklisted. Contact an admin if this is in error.");
//
File file = new File(plugin.getDataFolder(), "/lang/" + lang + ".yml");

View File

@ -13,7 +13,6 @@ npc-effect: "note"
max-quests: 0
convert-data-on-startup: false
quester-blacklist:
- "UUID"
- "UUID"
- "UUID"
- "UUID"

View File

@ -64,6 +64,9 @@ permissions:
quests.admin.nextstage:
description: Immediately force Stage completion for a player
default: op
quests.admin.purge:
description: Clear all Quests data of a player
default: op
quests.admin.togglegui:
description: Toggle GUI Quest Display on NPC's
default: op