mirror of
https://github.com/PikaMug/Quests.git
synced 2024-11-30 14:43:39 +01:00
Pass quest/stage exception message to super and remove unnecessary one
This commit is contained in:
parent
227ff1e730
commit
f5e6303071
@ -41,7 +41,6 @@ import me.blackvein.quests.events.quester.QuesterPostFailQuestEvent;
|
||||
import me.blackvein.quests.events.quester.QuesterPreChangeStageEvent;
|
||||
import me.blackvein.quests.events.quester.QuesterPreCompleteQuestEvent;
|
||||
import me.blackvein.quests.events.quester.QuesterPreFailQuestEvent;
|
||||
import me.blackvein.quests.exceptions.InvalidStageException;
|
||||
import me.blackvein.quests.util.ConfigUtil;
|
||||
import me.blackvein.quests.util.InventoryUtil;
|
||||
import me.blackvein.quests.util.ItemUtil;
|
||||
@ -196,11 +195,7 @@ public class Quest {
|
||||
}
|
||||
completeQuest(quester);
|
||||
} else {
|
||||
try {
|
||||
setStage(quester, quester.currentQuests.get(this) + 1);
|
||||
} catch (InvalidStageException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
setStage(quester, quester.currentQuests.get(this) + 1);
|
||||
}
|
||||
if (quester.getQuestData(this) != null) {
|
||||
quester.getQuestData(this).setDelayStartTime(0);
|
||||
@ -227,13 +222,15 @@ public class Quest {
|
||||
*
|
||||
* @param quester Player to force
|
||||
* @param stage Stage number to specify
|
||||
* @throws InvalidStageException if stage does not exist
|
||||
* @throws IndexOutOfBoundsException if stage does not exist
|
||||
*/
|
||||
public void setStage(Quester quester, int stage) throws InvalidStageException {
|
||||
if (orderedStages.size() - 1 < stage) {
|
||||
throw new InvalidStageException(this, stage);
|
||||
}
|
||||
public void setStage(Quester quester, int stage) throws IndexOutOfBoundsException {
|
||||
OfflinePlayer player = quester.getOfflinePlayer();
|
||||
if (orderedStages.size() - 1 < stage) {
|
||||
String msg = "Tried to set invalid stage number of " + stage + " for quest " + getName() + " on "
|
||||
+ player.getName();
|
||||
throw new IndexOutOfBoundsException(msg);
|
||||
}
|
||||
Stage currentStage = quester.getCurrentStage(this);
|
||||
Stage nextStage = getStage(stage);
|
||||
if (player.isOnline()) {
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -1,3 +1,15 @@
|
||||
/*******************************************************************************************************
|
||||
* Continued by PikaMug (formerly HappyPikachu) with permission from _Blackvein_. All rights reserved.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
|
||||
* NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*******************************************************************************************************/
|
||||
|
||||
package me.blackvein.quests.convo.quests.prompts;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
|
@ -1,51 +0,0 @@
|
||||
/*******************************************************************************************************
|
||||
* Continued by PikaMug (formerly HappyPikachu) with permission from _Blackvein_. All rights reserved.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
|
||||
* NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*******************************************************************************************************/
|
||||
|
||||
package me.blackvein.quests.exceptions;
|
||||
|
||||
import me.blackvein.quests.Quest;
|
||||
|
||||
public class InvalidStageException extends Exception {
|
||||
|
||||
private static final long serialVersionUID = 1778748295752972651L;
|
||||
private final Quest quest;
|
||||
private final int stage;
|
||||
|
||||
/**
|
||||
* Create a new instance of this class with the afflicted quest and stage number.
|
||||
*
|
||||
* @param quest The quest that an invalid stage id was set within.
|
||||
* @param stage The invalid stage id that was set.
|
||||
*/
|
||||
public InvalidStageException(Quest quest, int stage) {
|
||||
this.quest = quest;
|
||||
this.stage = stage;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the quest instance associated with this exception.
|
||||
*
|
||||
* @return The quest that an invalid stage id was set within.
|
||||
*/
|
||||
public Quest getQuest() {
|
||||
return quest;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the invalid stage id that was attempted to be set within the quest class.
|
||||
*
|
||||
* @return The invalid stage id that was set.
|
||||
*/
|
||||
public int getStage() {
|
||||
return stage;
|
||||
}
|
||||
}
|
@ -15,15 +15,32 @@ package me.blackvein.quests.exceptions;
|
||||
public class QuestFormatException extends Exception {
|
||||
|
||||
private static final long serialVersionUID = -5960613170308750149L;
|
||||
private final String quest;
|
||||
private final String message;
|
||||
private final String questId;
|
||||
|
||||
public QuestFormatException(String message, String questId) {
|
||||
super(message + ", see quest of ID " + questId);
|
||||
this.message = message + ", see quest of ID " + questId;
|
||||
this.questId = questId;
|
||||
}
|
||||
/**
|
||||
* Create a new instance of this class with the afflicted.
|
||||
*
|
||||
* @deprecated Use {@link#QuestFormatException(String, String)}
|
||||
* @param quest The quest that an invalid value was set within.
|
||||
*/
|
||||
public QuestFormatException(String quest) {
|
||||
this.quest = quest;
|
||||
public QuestFormatException(String questId) {
|
||||
this.message = "Failed to load quest of ID " + questId;
|
||||
this.questId = questId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the message associated with this exception.
|
||||
*
|
||||
* @return The message.
|
||||
*/
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -32,6 +49,6 @@ public class QuestFormatException extends Exception {
|
||||
* @return The quest that an invalid value was set within.
|
||||
*/
|
||||
public String getQuestId() {
|
||||
return quest;
|
||||
return questId;
|
||||
}
|
||||
}
|
||||
|
@ -17,20 +17,40 @@ import me.blackvein.quests.Quest;
|
||||
public class StageFormatException extends Exception {
|
||||
|
||||
private static final long serialVersionUID = -8217391053042612896L;
|
||||
private final String message;
|
||||
private final Quest quest;
|
||||
private final int stage;
|
||||
|
||||
|
||||
public StageFormatException(String message, Quest quest, int stage) {
|
||||
super(message + ", see quest " + quest.getName() + " stage " + stage);
|
||||
this.message = message + ", see quest " + quest.getName() + " stage " + stage;
|
||||
this.quest = quest;
|
||||
this.stage = stage;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new instance of this class with the afflicted quest and stage number.
|
||||
*
|
||||
* @deprecated Use {@link#StageFormatException(String, Quest, int)}
|
||||
* @param quest The quest that an invalid stage id was set within.
|
||||
* @param stage The invalid stage id that was set.
|
||||
*/
|
||||
public StageFormatException(Quest quest, int stage) {
|
||||
this.message = "Failed to load quest " + quest.getName() + " stage " + stage;
|
||||
this.quest = quest;
|
||||
this.stage = stage;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the message associated with this exception.
|
||||
*
|
||||
* @return The message.
|
||||
*/
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the quest instance associated with this exception.
|
||||
*
|
||||
|
@ -34,7 +34,6 @@ import me.blackvein.quests.events.command.QuestsCommandPreQuestsEditorEvent;
|
||||
import me.blackvein.quests.events.command.QuestsCommandPreQuestsJournalEvent;
|
||||
import me.blackvein.quests.events.command.QuestsCommandPreQuestsListEvent;
|
||||
import me.blackvein.quests.events.quest.QuestQuitEvent;
|
||||
import me.blackvein.quests.exceptions.InvalidStageException;
|
||||
import me.blackvein.quests.util.ItemUtil;
|
||||
import me.blackvein.quests.util.Lang;
|
||||
import me.blackvein.quests.util.MiscUtil;
|
||||
@ -1217,9 +1216,9 @@ public class CmdExecutor implements CommandExecutor {
|
||||
}
|
||||
try {
|
||||
quest.setStage(quester, stage - 1);
|
||||
} catch (InvalidStageException e) {
|
||||
String msg = Lang.get("invalidStageNum");
|
||||
msg = msg.replace("<quest>", ChatColor.DARK_PURPLE + quest.getName() + ChatColor.RED);
|
||||
} catch (IndexOutOfBoundsException e) {
|
||||
String msg = Lang.get("invalidRange");
|
||||
msg = msg.replace("<least>", "1").replace("<greatest>", String.valueOf(quest.getStages().size()));
|
||||
cs.sendMessage(ChatColor.RED + msg);
|
||||
}
|
||||
quester.saveData();
|
||||
|
@ -15,7 +15,6 @@ package me.blackvein.quests.tasks;
|
||||
import me.blackvein.quests.Quest;
|
||||
import me.blackvein.quests.Quester;
|
||||
import me.blackvein.quests.Quests;
|
||||
import me.blackvein.quests.exceptions.InvalidStageException;
|
||||
|
||||
public class StageTimer implements Runnable {
|
||||
|
||||
@ -76,10 +75,9 @@ public class StageTimer implements Runnable {
|
||||
}*/
|
||||
try {
|
||||
quest.setStage(quester, stageNum);
|
||||
} catch (InvalidStageException e) {
|
||||
} catch (IndexOutOfBoundsException e) {
|
||||
plugin.getLogger().severe("Unable to set stage of quest " + quest.getName() + " to Stage "
|
||||
+ stageNum + " after delay");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
if (quester.getQuestData(quest) != null) {
|
||||
|
@ -115,7 +115,7 @@ public class Lang {
|
||||
return orig;
|
||||
}
|
||||
|
||||
public static void loadLang(Quests plugin) throws InvalidConfigurationException, IOException {
|
||||
public static void loadLang(Quests plugin) throws InvalidConfigurationException, IOException {
|
||||
File langFile = new File(plugin.getDataFolder(), File.separator + "lang" + File.separator + iso + File.separator
|
||||
+ "strings.yml");
|
||||
File langFile_new = new File(plugin.getDataFolder(), File.separator + "lang" + File.separator + iso
|
||||
|
@ -678,7 +678,6 @@ questPointsGiven: "<player> gave you <number> Quest Points."
|
||||
invalidMinimum: "Input must be at least <number>!"
|
||||
invalidRange: "Input must be between <least> and <greatest>!"
|
||||
invalidOption: "Invalid option!"
|
||||
invalidStageNum: "Invalid stage number for Quest <quest>"
|
||||
noCurrentQuest: "<player> does not currently have any active Quests."
|
||||
playerNotFound: "Player not found."
|
||||
errorNPCID: 'Error: There is no NPC with ID <number>'
|
||||
|
Loading…
Reference in New Issue
Block a user