summaryrefslogtreecommitdiffstats
path: root/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/com/leonardobishop/quests/Quests.java33
-rw-r--r--src/main/java/com/leonardobishop/quests/api/enums/QuestStartResult.java13
-rw-r--r--src/main/java/com/leonardobishop/quests/api/events/PreStartQuestEvent.java57
-rw-r--r--src/main/java/com/leonardobishop/quests/commands/CommandQuests.java17
-rw-r--r--src/main/java/com/leonardobishop/quests/events/EventInventory.java3
-rw-r--r--src/main/java/com/leonardobishop/quests/obj/Messages.java4
-rw-r--r--src/main/java/com/leonardobishop/quests/obj/misc/QItemStack.java6
-rw-r--r--src/main/java/com/leonardobishop/quests/obj/misc/QMenuQuest.java2
-rw-r--r--src/main/java/com/leonardobishop/quests/player/QPlayer.java10
-rw-r--r--src/main/java/com/leonardobishop/quests/player/QPlayerManager.java7
-rw-r--r--src/main/java/com/leonardobishop/quests/player/questprogressfile/QuestProgressFile.java84
-rw-r--r--src/main/java/com/leonardobishop/quests/quests/tasktypes/types/BuildingCertainTaskType.java2
-rw-r--r--src/main/java/com/leonardobishop/quests/quests/tasktypes/types/CitizensDeliverTaskType.java2
-rw-r--r--src/main/java/com/leonardobishop/quests/quests/tasktypes/types/InventoryTaskType.java2
-rw-r--r--src/main/java/com/leonardobishop/quests/quests/tasktypes/types/MiningCertainTaskType.java2
-rw-r--r--src/main/resources/config.yml1
-rw-r--r--src/main/resources/plugin.yml2
17 files changed, 155 insertions, 92 deletions
diff --git a/src/main/java/com/leonardobishop/quests/Quests.java b/src/main/java/com/leonardobishop/quests/Quests.java
index add72bc0..71f42917 100644
--- a/src/main/java/com/leonardobishop/quests/Quests.java
+++ b/src/main/java/com/leonardobishop/quests/Quests.java
@@ -5,6 +5,7 @@ import com.leonardobishop.quests.commands.CommandQuests;
import com.leonardobishop.quests.events.EventInventory;
import com.leonardobishop.quests.events.EventPlayerJoin;
import com.leonardobishop.quests.events.EventPlayerLeave;
+import com.leonardobishop.quests.obj.Messages;
import com.leonardobishop.quests.player.QPlayer;
import com.leonardobishop.quests.player.QPlayerManager;
import com.leonardobishop.quests.player.questprogressfile.QuestProgress;
@@ -28,9 +29,7 @@ import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
-import org.bukkit.plugin.PluginDescriptionFile;
import org.bukkit.plugin.java.JavaPlugin;
-import org.bukkit.plugin.java.JavaPluginLoader;
import java.io.*;
import java.util.ArrayList;
@@ -84,33 +83,17 @@ public class Quests extends JavaPlugin {
return questsConfigLoader;
}
- public String convertToFormat(long m) {
+ public String convertToFormat(long m) { //seconds please
long hours = m / 60;
- long minutesLeft = m - hours * 60;
+ long minutes = (m % 60) / 60;
+ long seconds = ((m % 60) % 60) % 60;
- String formattedTime = "";
-
- if (hours < 10)
- formattedTime = formattedTime + "0";
- formattedTime = formattedTime + hours + "h";
-
- formattedTime = formattedTime + " ";
-
- if (minutesLeft < 10)
- formattedTime = formattedTime + "0";
- formattedTime = formattedTime + minutesLeft + "m";
-
- return formattedTime;
+ return Messages.TIME_FORMAT.getMessage()
+ .replace("{hours}", String.format("%02d", hours))
+ .replace("{minutes}", String.format("%02d", minutes))
+ .replace("{seconds}", String.format("%02d", seconds));
}
- public Quests() {
- }
-
- public Quests(JavaPluginLoader loader, PluginDescriptionFile description, File dataFolder, File file) {
- super(loader, description, dataFolder, file);
- }
-
-
@Override
public void onEnable() {
taskTypeManager = new TaskTypeManager(this);
diff --git a/src/main/java/com/leonardobishop/quests/api/enums/QuestStartResult.java b/src/main/java/com/leonardobishop/quests/api/enums/QuestStartResult.java
new file mode 100644
index 00000000..7241668d
--- /dev/null
+++ b/src/main/java/com/leonardobishop/quests/api/enums/QuestStartResult.java
@@ -0,0 +1,13 @@
+package com.leonardobishop.quests.api.enums;
+
+public enum QuestStartResult {
+ QUEST_SUCCESS, //0
+ QUEST_LIMIT_REACHED, //1
+ QUEST_ALREADY_COMPLETED, //2
+ QUEST_COOLDOWN, //3
+ QUEST_LOCKED, //4
+ QUEST_ALREADY_STARTED, //5
+ QUEST_NO_PERMISSION, //6
+ NO_PERMISSION_FOR_CATEGORY, //7
+ OTHER //8
+}
diff --git a/src/main/java/com/leonardobishop/quests/api/events/PreStartQuestEvent.java b/src/main/java/com/leonardobishop/quests/api/events/PreStartQuestEvent.java
new file mode 100644
index 00000000..abbbd77d
--- /dev/null
+++ b/src/main/java/com/leonardobishop/quests/api/events/PreStartQuestEvent.java
@@ -0,0 +1,57 @@
+package com.leonardobishop.quests.api.events;
+
+import com.leonardobishop.quests.api.enums.QuestStartResult;
+import com.leonardobishop.quests.player.QPlayer;
+import org.bukkit.entity.Player;
+import org.bukkit.event.HandlerList;
+import org.jetbrains.annotations.NotNull;
+
+public class PreStartQuestEvent extends PlayerQuestEvent {
+
+ private final static HandlerList handlers = new HandlerList();
+ private QuestStartResult questStartResult;
+ private String questResultMessage;
+
+ public PreStartQuestEvent(@NotNull Player who, @NotNull QPlayer questPlayer, String questResultMessage, @NotNull QuestStartResult questStartResult) {
+ super(who, questPlayer);
+ this.questStartResult = questStartResult;
+ this.questResultMessage = questResultMessage;
+ }
+
+ public QuestStartResult getQuestStartResult() {
+ return this.questStartResult;
+ }
+
+ public QuestStartResult setQuestStartResult(QuestStartResult questStartResult) {
+ return (this.questStartResult = questStartResult);
+ }
+
+ /**
+ * @return The message sent to the player of the result of the quest
+ * <p>
+ * For {@link QuestStartResult#QUEST_SUCCESS} please use {@link PlayerStartQuestEvent}
+ */
+ public String getQuestResultMessage() {
+ return this.questResultMessage;
+ }
+
+ /**
+ * @param questResultMessage The quest result message
+ * @return The quest result message set
+ * <p>
+ * For {@link QuestStartResult#QUEST_SUCCESS} please use {@link PlayerStartQuestEvent}
+ */
+ public String setQuestResultMessage(String questResultMessage) {
+ return (this.questResultMessage = questResultMessage);
+ }
+
+ @NotNull
+ @Override
+ public HandlerList getHandlers() {
+ return handlers;
+ }
+
+ public static HandlerList getHandlerList() {
+ return handlers;
+ }
+}
diff --git a/src/main/java/com/leonardobishop/quests/commands/CommandQuests.java b/src/main/java/com/leonardobishop/quests/commands/CommandQuests.java
index 159ebb41..ac79f674 100644
--- a/src/main/java/com/leonardobishop/quests/commands/CommandQuests.java
+++ b/src/main/java/com/leonardobishop/quests/commands/CommandQuests.java
@@ -2,6 +2,7 @@ package com.leonardobishop.quests.commands;
import com.leonardobishop.quests.Quests;
import com.leonardobishop.quests.QuestsConfigLoader;
+import com.leonardobishop.quests.api.enums.QuestStartResult;
import com.leonardobishop.quests.obj.Messages;
import com.leonardobishop.quests.obj.Options;
import com.leonardobishop.quests.player.QPlayer;
@@ -231,26 +232,26 @@ public class CommandQuests implements CommandExecutor {
sender.sendMessage(Messages.COMMAND_QUEST_ADMIN_RESET_SUCCESS.getMessage().replace("{player}", name).replace("{quest}", quest.getId()));
success = true;
} else if (args[2].equalsIgnoreCase("start")) {
- int response = questProgressFile.startQuest(quest);
- if (response == 1) {
+ QuestStartResult response = questProgressFile.startQuest(quest);
+ if (response == QuestStartResult.QUEST_LIMIT_REACHED) {
sender.sendMessage(Messages.COMMAND_QUEST_ADMIN_START_FAILLIMIT.getMessage().replace("{player}", name).replace("{quest}", quest.getId()));
return true;
- } else if (response == 2) {
+ } else if (response == QuestStartResult.QUEST_ALREADY_COMPLETED) {
sender.sendMessage(Messages.COMMAND_QUEST_ADMIN_START_FAILCOMPLETE.getMessage().replace("{player}", name).replace("{quest}", quest.getId()));
return true;
- } else if (response == 3) {
+ } else if (response == QuestStartResult.QUEST_COOLDOWN) {
sender.sendMessage(Messages.COMMAND_QUEST_ADMIN_START_FAILCOOLDOWN.getMessage().replace("{player}", name).replace("{quest}", quest.getId()));
return true;
- } else if (response == 4) {
+ } else if (response == QuestStartResult.QUEST_LOCKED) {
sender.sendMessage(Messages.COMMAND_QUEST_ADMIN_START_FAILLOCKED.getMessage().replace("{player}", name).replace("{quest}", quest.getId()));
return true;
- } else if (response == 5) {
+ } else if (response == QuestStartResult.QUEST_ALREADY_STARTED) {
sender.sendMessage(Messages.COMMAND_QUEST_ADMIN_START_FAILSTARTED.getMessage().replace("{player}", name).replace("{quest}", quest.getId()));
return true;
- } else if (response == 6) {
+ } else if (response == QuestStartResult.QUEST_NO_PERMISSION) {
sender.sendMessage(Messages.COMMAND_QUEST_ADMIN_START_FAILPERMISSION.getMessage().replace("{player}", name).replace("{quest}", quest.getId()));
return true;
- } else if (response == 7) {
+ } else if (response == QuestStartResult.NO_PERMISSION_FOR_CATEGORY) {
sender.sendMessage(Messages.COMMAND_QUEST_ADMIN_START_FAILCATEGORYPERMISSION.getMessage().replace("{player}", name).replace("{quest}", quest.getId()));
return true;
}
diff --git a/src/main/java/com/leonardobishop/quests/events/EventInventory.java b/src/main/java/com/leonardobishop/quests/events/EventInventory.java
index bde57436..a2319735 100644
--- a/src/main/java/com/leonardobishop/quests/events/EventInventory.java
+++ b/src/main/java/com/leonardobishop/quests/events/EventInventory.java
@@ -1,5 +1,6 @@
package com.leonardobishop.quests.events;
+import com.leonardobishop.quests.api.enums.QuestStartResult;
import com.leonardobishop.quests.obj.Messages;
import com.leonardobishop.quests.quests.Quest;
import com.leonardobishop.quests.Quests;
@@ -84,7 +85,7 @@ public class EventInventory implements Listener {
String questid = qMenuQuest.getSlotsToMenu().get(event.getSlot() + (((qMenuQuest.getCurrentPage()) - 1) * qMenuQuest.getPageSize()));
Quest quest = plugin.getQuestManager().getQuestById(questid);
if (event.getClick() == ClickType.LEFT) {
- if (qMenuQuest.getOwner().getQuestProgressFile().startQuest(quest) == 0) {
+ if (qMenuQuest.getOwner().getQuestProgressFile().startQuest(quest) == QuestStartResult.QUEST_SUCCESS) {
event.getWhoClicked().closeInventory(); //TODO Option to keep the menu open
}
} else if (event.getClick() == ClickType.RIGHT && Options.ALLOW_QUEST_CANCEL.getBooleanValue()) {
diff --git a/src/main/java/com/leonardobishop/quests/obj/Messages.java b/src/main/java/com/leonardobishop/quests/obj/Messages.java
index 41b4c4f8..1d02e3ef 100644
--- a/src/main/java/com/leonardobishop/quests/obj/Messages.java
+++ b/src/main/java/com/leonardobishop/quests/obj/Messages.java
@@ -5,6 +5,7 @@ import org.bukkit.ChatColor;
public enum Messages {
+ TIME_FORMAT("messages.time-format"),
QUEST_START("messages.quest-start"),
QUEST_COMPLETE("messages.quest-complete"),
QUEST_CANCEL("messages.quest-cancel"),
@@ -49,7 +50,7 @@ public enum Messages {
COMMAND_QUEST_ADMIN_COMPLETE_SUCCESS("messages.command-quest-admin-complete-success"),
COMMAND_QUEST_ADMIN_RESET_SUCCESS("messages.command-quest-admin-reset-success");
- private String path;
+ private final String path;
Messages(String path) {
this.path = path;
@@ -64,5 +65,4 @@ public enum Messages {
}
return path;
}
-
}
diff --git a/src/main/java/com/leonardobishop/quests/obj/misc/QItemStack.java b/src/main/java/com/leonardobishop/quests/obj/misc/QItemStack.java
index 775e19bb..f97b94fe 100644
--- a/src/main/java/com/leonardobishop/quests/obj/misc/QItemStack.java
+++ b/src/main/java/com/leonardobishop/quests/obj/misc/QItemStack.java
@@ -71,13 +71,13 @@ public class QItemStack {
this.data = data;
}
+ @SuppressWarnings("deprecation")
public ItemStack toItemStack(Quest quest, QuestProgressFile questProgressFile, QuestProgress questProgress) {
ItemStack is = new ItemStack(type, 1, (short) data);
ItemMeta ism = is.getItemMeta();
ism.setDisplayName(name);
List<String> formattedLore = new ArrayList<>();
- List<String> tempLore = new ArrayList<>();
- tempLore.addAll(loreNormal);
+ List<String> tempLore = new ArrayList<>(loreNormal);
if (questProgressFile.hasStartedQuest(quest)) {
tempLore.addAll(loreStarted);
ism.addEnchant(Enchantment.ARROW_INFINITE, 1, true);
@@ -90,7 +90,7 @@ public class QItemStack {
}
if (questProgress != null) {
for (String s : tempLore) {
- Matcher m = Pattern.compile("\\{([^}]+)\\}").matcher(s);
+ Matcher m = Pattern.compile("\\{([^}]+)}").matcher(s);
while (m.find()) {
String[] parts = m.group(1).split(":");
if (parts.length > 1) {
diff --git a/src/main/java/com/leonardobishop/quests/obj/misc/QMenuQuest.java b/src/main/java/com/leonardobishop/quests/obj/misc/QMenuQuest.java
index 6e4cdb6d..38914c4b 100644
--- a/src/main/java/com/leonardobishop/quests/obj/misc/QMenuQuest.java
+++ b/src/main/java/com/leonardobishop/quests/obj/misc/QMenuQuest.java
@@ -128,7 +128,7 @@ public class QMenuQuest implements QMenu {
inventory.setItem(invSlot, is);
} else if (cooldown > 0) {
Map<String, String> placeholders = new HashMap<>();
- placeholders.put("{time}", Quests.get().convertToFormat(TimeUnit.MINUTES.convert(cooldown, TimeUnit.MILLISECONDS)));
+ placeholders.put("{time}", Quests.get().convertToFormat(TimeUnit.MINUTES.convert(cooldown, TimeUnit.SECONDS)));
placeholders.put("{quest}", quest.getDisplayNameStripped());
ItemStack is = replaceItemStack(Items.QUEST_COOLDOWN.getItem(), placeholders);
inventory.setItem(invSlot, is);
diff --git a/src/main/java/com/leonardobishop/quests/player/QPlayer.java b/src/main/java/com/leonardobishop/quests/player/QPlayer.java
index b93f0ae5..e9bf2c83 100644
--- a/src/main/java/com/leonardobishop/quests/player/QPlayer.java
+++ b/src/main/java/com/leonardobishop/quests/player/QPlayer.java
@@ -32,7 +32,7 @@ public class QPlayer {
}
public UUID getUuid() {
- return uuid;
+ return this.uuid;
}
/**
@@ -43,7 +43,7 @@ public class QPlayer {
return 2;
}
- Player player = Bukkit.getPlayer(uuid);
+ Player player = Bukkit.getPlayer(this.uuid);
if (player == null) {
return 3;
}
@@ -73,7 +73,7 @@ public class QPlayer {
return 2;
}
- Player player = Bukkit.getPlayer(uuid);
+ Player player = Bukkit.getPlayer(this.uuid);
if (player == null) {
return 3;
}
@@ -92,10 +92,10 @@ public class QPlayer {
return;
}
- if (uuid == null) {
+ if (this.uuid == null) {
return;
}
- Player player = Bukkit.getPlayer(uuid);
+ Player player = Bukkit.getPlayer(this.uuid);
if (player == null) {
return;
}
diff --git a/src/main/java/com/leonardobishop/quests/player/QPlayerManager.java b/src/main/java/com/leonardobishop/quests/player/QPlayerManager.java
index 2f744ab5..1c03e5e5 100644
--- a/src/main/java/com/leonardobishop/quests/player/QPlayerManager.java
+++ b/src/main/java/com/leonardobishop/quests/player/QPlayerManager.java
@@ -19,10 +19,6 @@ public class QPlayerManager {
private final Map<UUID, QPlayer> qPlayers = new HashMap<>();
- public void addPlayer(QPlayer qPlayer) {
- qPlayers.put(qPlayer.getUuid(), qPlayer);
- }
-
public QPlayer getPlayer(UUID uuid) {
return qPlayers.get(uuid);
}
@@ -80,8 +76,7 @@ public class QPlayerManager {
QPlayer qPlayer = new QPlayer(uuid, questProgressFile, onlyData, plugin);
- addPlayer(qPlayer);
+ this.qPlayers.put(uuid, qPlayer);
}
}
-
}
diff --git a/src/main/java/com/leonardobishop/quests/player/questprogressfile/QuestProgressFile.java b/src/main/java/com/leonardobishop/quests/player/questprogressfile/QuestProgressFile.java
index 40377e4b..a8d8dd94 100644
--- a/src/main/java/com/leonardobishop/quests/player/questprogressfile/QuestProgressFile.java
+++ b/src/main/java/com/leonardobishop/quests/player/questprogressfile/QuestProgressFile.java
@@ -2,9 +2,11 @@ package com.leonardobishop.quests.player.questprogressfile;
import com.leonardobishop.quests.Quests;
import com.leonardobishop.quests.api.QuestsAPI;
+import com.leonardobishop.quests.api.enums.QuestStartResult;
import com.leonardobishop.quests.api.events.PlayerCancelQuestEvent;
import com.leonardobishop.quests.api.events.PlayerFinishQuestEvent;
import com.leonardobishop.quests.api.events.PlayerStartQuestEvent;
+import com.leonardobishop.quests.api.events.PreStartQuestEvent;
import com.leonardobishop.quests.obj.Messages;
import com.leonardobishop.quests.obj.Options;
import com.leonardobishop.quests.player.QPlayer;
@@ -72,51 +74,50 @@ public class QuestProgressFile {
* Warning: will fail if the player is not online.
*
* @param quest the quest to check
- * @return 0 if true, 1 if limit reached, 2 if quest is already completed, 3 if quest has cooldown, 4 if still locked, 5 if already started, 6 if
- * no permission, 7 if no permission for category
+ * @return the quest start result
*/
- public int canStartQuest(Quest quest) {
+ public QuestStartResult canStartQuest(Quest quest) {
Player p = Bukkit.getPlayer(playerUUID);
if (getStartedQuests().size() >= Options.QUESTS_START_LIMIT.getIntValue()) {
- return 1;
+ return QuestStartResult.QUEST_LIMIT_REACHED;
}
QuestProgress questProgress = getQuestProgress(quest);
if (!quest.isRepeatable() && questProgress.isCompletedBefore()) {
//if (playerUUID != null) {
// ???
//}
- return 2;
+ return QuestStartResult.QUEST_ALREADY_COMPLETED;
}
long cooldown = getCooldownFor(quest);
if (cooldown > 0) {
- return 3;
+ return QuestStartResult.QUEST_COOLDOWN;
}
if (!hasMetRequirements(quest)) {
- return 4;
+ return QuestStartResult.QUEST_LOCKED;
}
if (questProgress.isStarted()) {
- return 5;
+ return QuestStartResult.QUEST_ALREADY_STARTED;
}
if (quest.isPermissionRequired()) {
if (playerUUID != null) {
if (!p.hasPermission("quests.quest." + quest.getId())) {
- return 6;
+ return QuestStartResult.QUEST_NO_PERMISSION;
}
} else {
- return 6;
+ return QuestStartResult.QUEST_NO_PERMISSION;
}
}
if (quest.getCategoryId() != null && plugin.getQuestManager().getCategoryById(quest.getCategoryId()) != null && plugin.getQuestManager()
.getCategoryById(quest.getCategoryId()).isPermissionRequired()) {
if (playerUUID != null) {
if (!p.hasPermission("quests.category." + quest.getCategoryId())) {
- return 7;
+ return QuestStartResult.NO_PERMISSION_FOR_CATEGORY;
}
} else {
- return 7;
+ return QuestStartResult.NO_PERMISSION_FOR_CATEGORY;
}
}
- return 0;
+ return QuestStartResult.QUEST_SUCCESS;
}
/**
@@ -125,42 +126,51 @@ public class QuestProgressFile {
* Warning: will fail if the player is not online.
*
* @param quest the quest to check
- * @return 0 if successful, 1 if limit reached, 2 if quest is already completed, 3 if quest has cooldown, 4 if still locked, 5 if already started, 6 if
- * no permission, 7 if no permission for category, 8 if other
+ * @return the quest start result
*/
- public int startQuest(Quest quest) {
+ // TODO PlaceholderAPI support
+ public QuestStartResult startQuest(Quest quest) {
Player player = Bukkit.getPlayer(playerUUID);
- int code = canStartQuest(quest);
+ QuestStartResult code = canStartQuest(quest);
if (player != null) {
+ String questResultMessage = null;
switch (code) {
- case 0:
+ case QUEST_SUCCESS:
+ // This one is hacky
break;
- case 1:
- player.sendMessage(Messages.QUEST_START_LIMIT.getMessage().replace("{limit}", String.valueOf(Options.QUESTS_START_LIMIT.getIntValue())));
+ case QUEST_LIMIT_REACHED:
+ questResultMessage = Messages.QUEST_START_LIMIT.getMessage().replace("{limit}", String.valueOf(Options.QUESTS_START_LIMIT.getIntValue()));
break;
- case 2:
- player.sendMessage(Messages.QUEST_START_DISABLED.getMessage());
+ case QUEST_ALREADY_COMPLETED:
+ questResultMessage = Messages.QUEST_START_DISABLED.getMessage();
break;
- case 3:
+ case QUEST_COOLDOWN:
long cooldown = getCooldownFor(quest);
- player.sendMessage(Messages.QUEST_START_COOLDOWN.getMessage().replace("{time}", String.valueOf(plugin.convertToFormat(TimeUnit.MINUTES.convert
- (cooldown, TimeUnit.MILLISECONDS)))));
+ questResultMessage = Messages.QUEST_START_COOLDOWN.getMessage().replace("{time}", String.valueOf(plugin.convertToFormat(TimeUnit.MINUTES.convert
+ (cooldown, TimeUnit.SECONDS))));
break;
- case 4:
- player.sendMessage(Messages.QUEST_START_LOCKED.getMessage());
+ case QUEST_LOCKED:
+ questResultMessage = Messages.QUEST_START_LOCKED.getMessage();
break;
- case 5:
- player.sendMessage(Messages.QUEST_START_STARTED.getMessage());
+ case QUEST_ALREADY_STARTED:
+ questResultMessage = Messages.QUEST_START_STARTED.getMessage();
break;
- case 6:
- player.sendMessage(Messages.QUEST_START_PERMISSION.getMessage());
+ case QUEST_NO_PERMISSION:
+ questResultMessage = Messages.QUEST_START_PERMISSION.getMessage();
break;
- case 7:
- player.sendMessage(Messages.QUEST_CATEGORY_QUEST_PERMISSION.getMessage());
+ case NO_PERMISSION_FOR_CATEGORY:
+ questResultMessage = Messages.QUEST_CATEGORY_QUEST_PERMISSION.getMessage();
break;
}
+ QPlayer questPlayer = QuestsAPI.getPlayerManager().getPlayer(this.playerUUID);
+ // PreStartQuestEvent -- start
+ PreStartQuestEvent preStartQuestEvent = new PreStartQuestEvent(player, questPlayer, questResultMessage, code);
+ Bukkit.getPluginManager().callEvent(preStartQuestEvent);
+ // PreStartQuestEvent -- end
+ if (preStartQuestEvent.getQuestResultMessage() != null && code != QuestStartResult.QUEST_SUCCESS)
+ player.sendMessage(preStartQuestEvent.getQuestResultMessage());
}
- if (code == 0) {
+ if (code == QuestStartResult.QUEST_SUCCESS) {
QuestProgress questProgress = getQuestProgress(quest);
questProgress.setStarted(true);
for (TaskProgress taskProgress : questProgress.getTaskProgress()) {
@@ -170,7 +180,7 @@ public class QuestProgressFile {
questProgress.setCompleted(false);
if (player != null) {
QPlayer questPlayer = QuestsAPI.getPlayerManager().getPlayer(this.playerUUID);
- String questStartMessage = Messages.QUEST_START.getMessage().replace("{quest}", quest.getDisplayNameStripped()); //TODO PlaceholderAPI support
+ String questStartMessage = Messages.QUEST_START.getMessage().replace("{quest}", quest.getDisplayNameStripped());
// PlayerStartQuestEvent -- start
PlayerStartQuestEvent questStartEvent = new PlayerStartQuestEvent(player, questPlayer, questProgress, questStartMessage);
Bukkit.getPluginManager().callEvent(questStartEvent);
@@ -238,8 +248,8 @@ public class QuestProgressFile {
if (!Options.QUEST_AUTOSTART.getBooleanValue()) {
return hasQuestProgress(quest) && getQuestProgress(quest).isStarted();
} else {
- int response = canStartQuest(quest);
- return response == 0 || response == 5;
+ QuestStartResult response = canStartQuest(quest);
+ return response == QuestStartResult.QUEST_SUCCESS || response == QuestStartResult.QUEST_ALREADY_STARTED;
}
}
diff --git a/src/main/java/com/leonardobishop/quests/quests/tasktypes/types/BuildingCertainTaskType.java b/src/main/java/com/leonardobishop/quests/quests/tasktypes/types/BuildingCertainTaskType.java
index 7804e9ab..6b434111 100644
--- a/src/main/java/com/leonardobishop/quests/quests/tasktypes/types/BuildingCertainTaskType.java
+++ b/src/main/java/com/leonardobishop/quests/quests/tasktypes/types/BuildingCertainTaskType.java
@@ -92,7 +92,7 @@ public final class BuildingCertainTaskType extends TaskType {
Object configData = task.getConfigValue("data");
Object configSimilarBlocks = task.getConfigValue("use-similar-blocks");
- material = Material.matchMaterial(String.valueOf(configBlock));
+ material = Material.getMaterial(String.valueOf(configBlock));
Material blockType = block.getType();
short blockData = block.getData();
diff --git a/src/main/java/com/leonardobishop/quests/quests/tasktypes/types/CitizensDeliverTaskType.java b/src/main/java/com/leonardobishop/quests/quests/tasktypes/types/CitizensDeliverTaskType.java
index 16bcdf2a..36ef02a5 100644
--- a/src/main/java/com/leonardobishop/quests/quests/tasktypes/types/CitizensDeliverTaskType.java
+++ b/src/main/java/com/leonardobishop/quests/quests/tasktypes/types/CitizensDeliverTaskType.java
@@ -79,7 +79,7 @@ public final class CitizensDeliverTaskType extends TaskType {
if (configBlock instanceof ConfigurationSection) {
is = Quests.get().getItemStack((org.bukkit.configuration.ConfigurationSection) configBlock);
} else {
- material = Material.matchMaterial(String.valueOf(configBlock));
+ material = Material.getMaterial(String.valueOf(configBlock));
if (material == null) {
continue;
diff --git a/src/main/java/com/leonardobishop/quests/quests/tasktypes/types/InventoryTaskType.java b/src/main/java/com/leonardobishop/quests/quests/tasktypes/types/InventoryTaskType.java
index 1938c842..fb31e3c8 100644
--- a/src/main/java/com/leonardobishop/quests/quests/tasktypes/types/InventoryTaskType.java
+++ b/src/main/java/com/leonardobishop/quests/quests/tasktypes/types/InventoryTaskType.java
@@ -76,7 +76,7 @@ public final class InventoryTaskType extends TaskType {
Object configData = task.getConfigValue("data");
Object remove = task.getConfigValue("remove-items-when-complete");
- material = Material.matchMaterial(String.valueOf(configBlock));
+ material = Material.getMaterial(String.valueOf(configBlock));
if (material == null) {
diff --git a/src/main/java/com/leonardobishop/quests/quests/tasktypes/types/MiningCertainTaskType.java b/src/main/java/com/leonardobishop/quests/quests/tasktypes/types/MiningCertainTaskType.java
index 4674f48e..c2f847c5 100644
--- a/src/main/java/com/leonardobishop/quests/quests/tasktypes/types/MiningCertainTaskType.java
+++ b/src/main/java/com/leonardobishop/quests/quests/tasktypes/types/MiningCertainTaskType.java
@@ -94,7 +94,7 @@ public final class MiningCertainTaskType extends TaskType {
Object configData = task.getConfigValue("data");
Object configSimilarBlocks = task.getConfigValue("use-similar-blocks");
- material = Material.matchMaterial(String.valueOf(configBlock));
+ material = Material.getMaterial(String.valueOf(configBlock));
Material blockType = block.getType();
short blockData = block.getData();
diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml
index 83e9977c..bdf6e0e2 100644
--- a/src/main/resources/config.yml
+++ b/src/main/resources/config.yml
@@ -168,6 +168,7 @@ titles:
# Configure messages
messages:
+ time-format: "{hours}h {minutes}m {seconds}s"
quest-start: "&7Quest &c{quest} &7started!"
quest-complete: "&7Quest &c{quest} &7completed!"
quest-cancel: "&7Quest &c{quest} &7cancelled!"
diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml
index 5cbc933f..23abf62f 100644
--- a/src/main/resources/plugin.yml
+++ b/src/main/resources/plugin.yml
@@ -19,5 +19,7 @@ commands:
permissions:
quests.command:
description: Permission for main command
+ default: true
quests.admin:
description: Permission for the admin commands
+ default: op \ No newline at end of file