mirror of
https://github.com/PikaMug/Quests.git
synced 2025-02-17 04:51:19 +01:00
Add utility methods for Planner
This commit is contained in:
parent
173fabc322
commit
bcc34b490a
@ -12,6 +12,8 @@
|
||||
|
||||
package me.blackvein.quests;
|
||||
|
||||
import java.util.Calendar;
|
||||
|
||||
public class Planner {
|
||||
public String start = null;
|
||||
public String end = null;
|
||||
@ -21,24 +23,56 @@ public class Planner {
|
||||
public String getStart() {
|
||||
return start;
|
||||
}
|
||||
public long getStartInMillis() {
|
||||
if (start == null) {
|
||||
return -1;
|
||||
}
|
||||
Calendar cal = Calendar.getInstance();
|
||||
String[] s = start.split(":");
|
||||
cal.set(Integer.valueOf(s[2]), Integer.valueOf(s[1]), Integer.valueOf(s[0]),
|
||||
Integer.valueOf(s[3]), Integer.valueOf(s[4]), Integer.valueOf(s[5]));
|
||||
return cal.getTimeInMillis();
|
||||
}
|
||||
public boolean hasStart() {
|
||||
return start != null;
|
||||
}
|
||||
public void setStart(String start) {
|
||||
this.start = start;
|
||||
}
|
||||
public String getEnd() {
|
||||
return end;
|
||||
}
|
||||
public long getEndInMillis() {
|
||||
if (end == null) {
|
||||
return -1;
|
||||
}
|
||||
Calendar cal = Calendar.getInstance();
|
||||
String[] s = end.split(":");
|
||||
cal.set(Integer.valueOf(s[2]), Integer.valueOf(s[1]), Integer.valueOf(s[0]),
|
||||
Integer.valueOf(s[3]), Integer.valueOf(s[4]), Integer.valueOf(s[5]));
|
||||
return cal.getTimeInMillis();
|
||||
}
|
||||
public boolean hasEnd() {
|
||||
return end != null;
|
||||
}
|
||||
public void setEnd(String end) {
|
||||
this.end = end;
|
||||
}
|
||||
public long getRepeat() {
|
||||
return repeat;
|
||||
}
|
||||
public boolean hasRepeat() {
|
||||
return repeat != -1;
|
||||
}
|
||||
public void setRepeat(long repeat) {
|
||||
this.repeat = repeat;
|
||||
}
|
||||
public long getCooldown() {
|
||||
return cooldown;
|
||||
}
|
||||
public boolean hasCooldown() {
|
||||
return cooldown != -1;
|
||||
}
|
||||
public void setCooldown(long cooldown) {
|
||||
this.cooldown = cooldown;
|
||||
}
|
||||
|
@ -15,7 +15,6 @@ package me.blackvein.quests;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
@ -392,19 +391,11 @@ public class Quester {
|
||||
Planner pln = q.getPlanner();
|
||||
long start = -1;
|
||||
long end = -1;
|
||||
if (pln.getStart() != null) {
|
||||
Calendar cal = Calendar.getInstance();
|
||||
String[] s = pln.getStart().split(":");
|
||||
cal.set(Integer.valueOf(s[2]), Integer.valueOf(s[1]), Integer.valueOf(s[0]),
|
||||
Integer.valueOf(s[3]), Integer.valueOf(s[4]), Integer.valueOf(s[5]));
|
||||
start = cal.getTimeInMillis();
|
||||
if (pln.hasStart()) {
|
||||
start = pln.getStartInMillis();
|
||||
}
|
||||
if (pln.getEnd() != null) {
|
||||
Calendar cal = Calendar.getInstance();
|
||||
String[] s = pln.getEnd().split(":");
|
||||
cal.set(Integer.valueOf(s[2]), Integer.valueOf(s[1]), Integer.valueOf(s[0]),
|
||||
Integer.valueOf(s[3]), Integer.valueOf(s[4]), Integer.valueOf(s[5]));
|
||||
end = cal.getTimeInMillis();
|
||||
if (pln.hasEnd()) {
|
||||
end = pln.getEndInMillis();
|
||||
}
|
||||
if (start > -1 && end > -1) {
|
||||
if (pln.getRepeat() > -1) {
|
||||
|
@ -3166,9 +3166,18 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener
|
||||
public static String getDyeString(DyeColor dc) {
|
||||
return Lang.get("COLOR_" + dc.name());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Checks whether an NPC has a quest that the player may accept
|
||||
* @param npc The giver NPC to check
|
||||
* @param quester The player to check
|
||||
* @return true if at least one quest is available
|
||||
*/
|
||||
public boolean hasQuest(NPC npc, Quester quester) {
|
||||
for (Quest q : quests) {
|
||||
// Return false for expired quests
|
||||
|
||||
// Return true if not yet completed
|
||||
if (q.npcStart != null && quester.completedQuests.contains(q.getName()) == false) {
|
||||
if (q.npcStart.getId() == npc.getId()) {
|
||||
boolean ignoreLockedQuests = settings.canIgnoreLockedQuests();
|
||||
|
Loading…
Reference in New Issue
Block a user