Skip to content

Commit

Permalink
Merge pull request #220 from SkytAsul/release/0.19.2
Browse files Browse the repository at this point in the history
Release/0.19.2
  • Loading branch information
SkytAsul authored Apr 15, 2022
2 parents b00e49d + 2d5f1e8 commit 5e7eb36
Show file tree
Hide file tree
Showing 64 changed files with 1,297 additions and 964 deletions.
26 changes: 19 additions & 7 deletions core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<parent>
<groupId>fr.skytasul</groupId>
<artifactId>beautyquests-parent</artifactId>
<version>0.19.1</version>
<version>0.19.2</version>
</parent>

<build>
Expand Down Expand Up @@ -89,10 +89,10 @@
<id>maven-central</id>
<url>https://oss.sonatype.org/content/groups/public</url>
</repository>
<repository>
<id>teamvk-repo</id>
<url>https://raw.githubusercontent.com/TeamVK/maven-repository/master/release/</url>
</repository>
<repository>
<id>teamvk-repo</id>
<url>https://raw.githubusercontent.com/TeamVK/maven-repository/master/release/</url>
</repository>
<repository>
<id>lumine</id>
<url>https://mvn.lumine.io/repository/maven-public/</url>
Expand Down Expand Up @@ -123,7 +123,7 @@
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot</artifactId>
<version>1.18-R0.1-SNAPSHOT</version>
<version>1.18.2-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
Expand All @@ -136,7 +136,7 @@
<dependency>
<groupId>org.mcmonkey</groupId>
<artifactId>sentinel</artifactId>
<version>2.4.0-SNAPSHOT</version>
<version>2.5.0-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
Expand Down Expand Up @@ -210,6 +210,12 @@
<version>4.12.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>io.lumine</groupId>
<artifactId>Mythic-Dist</artifactId>
<version>5.0.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.github.promcteam</groupId>
<artifactId>proskillapi</artifactId>
Expand All @@ -234,6 +240,12 @@
<version>18.37.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.mariadb.jdbc</groupId>
<artifactId>mariadb-java-client</artifactId>
<version>2.7.5</version>
<scope>provided</scope> <!-- this is added to runtime through Spigot libraries system -->
</dependency>

<!-- Local JARs -->
<dependency>
Expand Down
46 changes: 24 additions & 22 deletions core/src/main/java/fr/skytasul/quests/BeautyQuests.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@

import fr.skytasul.quests.api.QuestsAPI;
import fr.skytasul.quests.api.bossbar.BQBossBarImplementation;
import fr.skytasul.quests.api.npcs.BQNPC;
import fr.skytasul.quests.commands.Commands;
import fr.skytasul.quests.commands.CommandsManager;
import fr.skytasul.quests.editors.Editor;
Expand All @@ -51,7 +50,6 @@
import fr.skytasul.quests.players.PlayersManagerDB;
import fr.skytasul.quests.players.PlayersManagerYAML;
import fr.skytasul.quests.scoreboards.ScoreboardManager;
import fr.skytasul.quests.structure.NPCStarter;
import fr.skytasul.quests.structure.Quest;
import fr.skytasul.quests.structure.QuestsManager;
import fr.skytasul.quests.structure.pools.QuestPoolsManager;
Expand Down Expand Up @@ -84,11 +82,10 @@ public class BeautyQuests extends JavaPlugin {

private YamlConfiguration data;
private File dataFile;
public static File saveFolder;
private File saveFolder;

/* --------- Datas --------- */

private Map<BQNPC, NPCStarter> npcs = new HashMap<>();
private ScoreboardManager scoreboards;
private QuestsManager quests;
private QuestPoolsManager pools;
Expand Down Expand Up @@ -122,6 +119,8 @@ public void onLoad(){
@Override
public void onEnable(){
try {
logger.info("------------ BeautyQuests ------------");

dependencies.testCompatibilities();
Bukkit.getPluginManager().registerEvents(dependencies, this);

Expand All @@ -137,7 +136,7 @@ public void onEnable(){
try {
dependencies.initializeCompatibilities();
}catch (Exception ex) {
logger.severe("Error when initializing compatibilities. Consider restarting.", ex);
logger.severe("An error occurred while initializing compatibilities. Consider restarting.", ex);
}

if (QuestsAPI.getNPCsManager() == null) {
Expand All @@ -161,15 +160,18 @@ public void run() {

if (!lastVersion.equals(pluginVersion)) { // maybe change in data structure : update of all quest files
DebugUtils.logMessage("Migrating from " + lastVersion + " to " + pluginVersion);
for (Quest qu : quests) qu.saveToFile();
int updated = 0;
for (Quest qu : quests) {
if (qu.saveToFile()) updated++;
}
if (updated > 0) logger.info("Updated " + updated + " quests during migration.");
saveAllConfig(false);
}
}catch (Throwable e) {
logger.severe("An error occurred while loading plugin datas.", e);
}
}
}.runTaskLater(this, QuestsAPI.getNPCsManager().getTimeToWaitForNPCs());


// Start of non-essential systems
if (loggerHandler != null) loggerHandler.launchFlushTimer();
Expand Down Expand Up @@ -249,7 +251,7 @@ public void run() {
}
}
};
logger.info("Periodic saves task started (" + cycle + " ticks). Task ID: " + saveTask.runTaskTimer(this, cycle, cycle).getTaskId());
logger.info("Periodic saves task started (" + cycle + " ticks). Task ID: " + saveTask.runTaskTimerAsynchronously(this, cycle, cycle).getTaskId());
}
}

Expand Down Expand Up @@ -294,7 +296,7 @@ private void launchMetrics(String pluginVersion) {
private void launchUpdateChecker(String pluginVersion) throws ReflectiveOperationException {
DebugUtils.logMessage("Starting Spigot updater");
if (pluginVersion.contains("_")) {
Matcher matcher = Pattern.compile("_BUILD(.+)").matcher(pluginVersion);
Matcher matcher = Pattern.compile("_BUILD(\\d+)").matcher(pluginVersion);
if (matcher.find()) {
String build = matcher.group(1);
UpdateChecker.init(instance, "https://ci.codemc.io/job/SkytAsul/job/BeautyQuests/lastSuccessfulBuild/buildNumber")
Expand Down Expand Up @@ -330,13 +332,16 @@ private void loadConfigParameters(boolean init) throws LoadingException {

ConfigurationSection dbConfig = config.getConfig().getConfigurationSection("database");
if (dbConfig.getBoolean("enabled")) {
db = new Database(dbConfig);
if (db.openConnection()) {
try {
db = new Database(dbConfig);
db.testConnection();
logger.info("Connection to database etablished.");
}else {
db.closeConnection();
db = null;
throw new LoadingException("Connection to database has failed.");
}catch (Exception ex) {
if (db != null) {
db.closeConnection();
db = null;
}
throw new LoadingException("Connection to database has failed.", ex);
}
}

Expand Down Expand Up @@ -486,7 +491,7 @@ private void loadAllDatas() throws Throwable {

public void saveAllConfig(boolean unload) throws Exception {
if (unload) {
quests.unloadQuests();
if (quests != null) quests.unloadQuests();

QuestsAPI.getQuestsHandlers().forEach(handler -> {
try {
Expand All @@ -498,6 +503,7 @@ public void saveAllConfig(boolean unload) throws Exception {
}

if (loaded) {
long time = System.currentTimeMillis();
data.set("lastID", quests.getLastID());
data.set("version", getDescription().getVersion());

Expand All @@ -508,18 +514,18 @@ public void saveAllConfig(boolean unload) throws Exception {
logger.severe("Error when saving player datas.", ex);
}
data.save(dataFile);
DebugUtils.logMessage("Saved datas (" + (((double) System.currentTimeMillis() - time) / 1000D) + "s)!");
}

if (unload){
QuestsAPI.getNPCsManager().unload();
resetDatas();
}
}

private void resetDatas(){
npcs.values().forEach(NPCStarter::removeHolograms);
quests = null;
pools = null;
npcs.clear();
if (db != null) db.closeConnection();
//HandlerList.unregisterAll(this);
loaded = false;
Expand Down Expand Up @@ -616,10 +622,6 @@ public void run() {
public QuestsConfiguration getConfiguration() {
return config;
}

public Map<BQNPC, NPCStarter> getNPCs() {
return npcs;
}

public FileConfiguration getDataFile(){
return data;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import com.google.common.collect.Sets;

import fr.skytasul.quests.api.QuestsAPI;
import fr.skytasul.quests.gui.ItemUtils;
import fr.skytasul.quests.gui.quests.PlayerListGUI.Category;
import fr.skytasul.quests.structure.QuestBranch.Source;
import fr.skytasul.quests.structure.QuestDescription;
Expand Down Expand Up @@ -155,6 +156,7 @@ void init() {
}else if (config.isString("item")) {
item = XMaterial.matchXMaterial(config.getString("item")).orElse(XMaterial.BOOK).parseItem();
}else item = XMaterial.BOOK.parseItem();
item = ItemUtils.clearVisibleAttributes(item);
if (config.contains("pageItem")) pageItem = XMaterial.matchXMaterial(config.getString("pageItem")).orElse(XMaterial.ARROW);
if (pageItem == null) pageItem = XMaterial.ARROW;
startParticleDistance = config.getInt("startParticleDistance");
Expand Down
114 changes: 56 additions & 58 deletions core/src/main/java/fr/skytasul/quests/QuestsListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@
import fr.skytasul.quests.players.PlayersManager;
import fr.skytasul.quests.players.events.PlayerAccountJoinEvent;
import fr.skytasul.quests.players.events.PlayerAccountLeaveEvent;
import fr.skytasul.quests.structure.NPCStarter;
import fr.skytasul.quests.structure.Quest;
import fr.skytasul.quests.structure.pools.QuestPool;
import fr.skytasul.quests.utils.DebugUtils;
import fr.skytasul.quests.utils.Lang;
import fr.skytasul.quests.utils.Utils;
import fr.skytasul.quests.utils.XMaterial;
Expand All @@ -57,67 +57,65 @@ public void onNPCClick(BQNPCClickEvent e) {

if (Inventories.isInSystem(p)) return;

NPCStarter starter = BeautyQuests.getInstance().getNPCs().get(npc);
if (starter != null) {
PlayerAccount acc = PlayersManager.getPlayerAccount(p);
if (acc == null) return;

Set<Quest> quests = starter.getQuests();
quests = quests.stream().filter(qu -> !qu.hasStarted(acc) && (qu.isRepeatable() ? true : !qu.hasFinished(acc))).collect(Collectors.toSet());
if (quests.isEmpty() && starter.getPools().isEmpty()) return;

List<Quest> launcheable = new ArrayList<>();
List<Quest> requirements = new ArrayList<>();
List<Quest> timer = new ArrayList<>();
for (Quest qu : quests) {
try {
if (!qu.testRequirements(p, acc, false)) {
requirements.add(qu);
}else if (!qu.testTimer(acc, false)) {
timer.add(qu);
}else launcheable.add(qu);
}catch (Exception ex) {
BeautyQuests.logger.severe("An exception occured when checking requirements on the quest " + qu.getID() + " for player " + p.getName(), ex);
}
PlayerAccount acc = PlayersManager.getPlayerAccount(p);
if (acc == null) return;

Set<Quest> quests = npc.getQuests();
quests = quests.stream().filter(qu -> !qu.hasStarted(acc) && (qu.isRepeatable() ? true : !qu.hasFinished(acc))).collect(Collectors.toSet());
if (quests.isEmpty() && npc.getPools().isEmpty()) return;

List<Quest> launcheable = new ArrayList<>();
List<Quest> requirements = new ArrayList<>();
List<Quest> timer = new ArrayList<>();
for (Quest qu : quests) {
try {
if (!qu.testRequirements(p, acc, false)) {
requirements.add(qu);
}else if (!qu.testTimer(acc, false)) {
timer.add(qu);
}else launcheable.add(qu);
}catch (Exception ex) {
BeautyQuests.logger.severe("An exception occured when checking requirements on the quest " + qu.getID() + " for player " + p.getName(), ex);
}

Set<QuestPool> startablePools = starter.getPools().stream().filter(pool -> {
try {
return pool.canGive(p, acc);
}catch (Exception ex) {
BeautyQuests.logger.severe("An exception occured when checking requirements on the pool " + pool.getID() + " for player " + p.getName(), ex);
return false;
}
}).collect(Collectors.toSet());

e.setCancelled(true);
if (!launcheable.isEmpty()) {
for (Quest quest : launcheable) {
if (quest.isInDialog(p)) {
quest.clickNPC(p);
return;
}
}
ChooseQuestGUI gui = new ChooseQuestGUI(launcheable, (quest) -> {
if (quest == null) return;
}

Set<QuestPool> startablePools = npc.getPools().stream().filter(pool -> {
try {
return pool.canGive(p, acc);
}catch (Exception ex) {
BeautyQuests.logger.severe("An exception occured when checking requirements on the pool " + pool.getID() + " for player " + p.getName(), ex);
return false;
}
}).collect(Collectors.toSet());

e.setCancelled(true);
if (!launcheable.isEmpty()) {
for (Quest quest : launcheable) {
if (quest.isInDialog(p)) {
quest.clickNPC(p);
});
gui.setValidate(__ -> {
new PlayerListGUI(acc).create(p);
}, ItemUtils.item(XMaterial.BOOKSHELF, Lang.questMenu.toString(), QuestOption.formatDescription(Lang.questMenuLore.toString())));
gui.create(p);
}else if (!startablePools.isEmpty()) {
startablePools.iterator().next().give(p);
}else {
if (!timer.isEmpty()) {
timer.get(0).testTimer(acc, true);
}else if (!requirements.isEmpty()) {
requirements.get(0).testRequirements(p, acc, true);
}else {
Utils.sendMessage(p, starter.getPools().iterator().next().give(p));
return;
}
e.setCancelled(false);
}
ChooseQuestGUI gui = new ChooseQuestGUI(launcheable, (quest) -> {
if (quest == null) return;
quest.clickNPC(p);
});
gui.setValidate(__ -> {
new PlayerListGUI(acc).create(p);
}, ItemUtils.item(XMaterial.BOOKSHELF, Lang.questMenu.toString(), QuestOption.formatDescription(Lang.questMenuLore.toString())));
gui.create(p);
}else if (!startablePools.isEmpty()) {
QuestPool pool = startablePools.iterator().next();
DebugUtils.logMessage("NPC " + npc.getId() + ": " + startablePools.size() + " pools, result: " + pool.give(p));
}else {
if (!timer.isEmpty()) {
timer.get(0).testTimer(acc, true);
}else if (!requirements.isEmpty()) {
requirements.get(0).testRequirements(p, acc, true);
}else {
Utils.sendMessage(p, npc.getPools().iterator().next().give(p));
}
e.setCancelled(false);
}
}

Expand Down
Loading

0 comments on commit 5e7eb36

Please sign in to comment.