Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added support for a custom advancement on first time passing an exam #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions src/com/dogonfire/exams/ExamManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@
import org.bukkit.entity.Player;
import org.bukkit.event.block.SignChangeEvent;
import org.bukkit.plugin.RegisteredServiceProvider;
import org.bukkit.advancement.Advancement;
import org.bukkit.advancement.AdvancementProgress;
import org.bukkit.entity.Player;
import org.bukkit.NamespacedKey;

import net.milkbowl.vault.economy.Economy;

Expand Down Expand Up @@ -417,6 +421,21 @@ public void calculateExamResult(String playerName)

plugin.sendMessage(playerName, ChatColor.GREEN + "Congratulations, you passed the exam!");
plugin.sendToAll(ChatColor.GREEN + playerName + " just PASSED the " + ChatColor.YELLOW + plugin.getStudentManager().getExamForStudent(playerName) + ChatColor.GREEN + " exam!");

// giving player an advancement for passing an exam if set to true
if (plugin.grantAdvancement) {
Advancement a = Bukkit.getAdvancement(NamespacedKey.fromString(plugin.examAdvacementName));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could be changed to see if the exam has an Advancement specified.

Copy link
Member Author

@benjamin1313 benjamin1313 Feb 17, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agree on the part of the if(plugin.grantAdvancement) check

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For now one advancement works as a prof of concept.
The reason you can turn this feature on and of is exactly because people might not have a datapack on their server or want to have one. And it does not have to be a specific datapack. Thats why it can be change in the config.yml so people can create their own datapacks with the advancement they what to give.

if(a != null){
Player player = Bukkit.getServer().getPlayer(playerName);
AdvancementProgress progress = player.getAdvancementProgress(a);
if(progress.isDone() == false) {
player.getAdvancementProgress(a).awardCriteria("Student");
}
}else{
plugin.logDebug("Failed to find Advancement");
}
}

}
else
{
Expand Down
6 changes: 6 additions & 0 deletions src/com/dogonfire/exams/Exams.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@ public class Exams extends JavaPlugin

public boolean debug = false;
public boolean examPricesEnabled = true;
public boolean grantAdvancement = false;

public String serverName = "Your Server";
public String languageFilename = "english.yml";
public String examAdvacementName = "doggycraft:doggycraft/student";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a hardcoded advancement, for completing your first exam.
Would be better to move to the config file for the exams, to have custom per-exam advancements.

Or specify more precisely, that this advancement is a one-time advancement, by calling it something like "firstExamAdvancement".

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agree on naming but the "hardcoded" bit is just a default value. it is change later when the config is loaded.


public int minExamTime = 60;
public int autoCleanTime = 8*60;
Expand Down Expand Up @@ -86,6 +88,8 @@ public void loadSettings()
serverName = config.getString("ServerName", "Your Server");
minExamTime = config.getInt("MinExamTime", 60);
requiredExamScore = config.getInt("RequiredExamScore", 80);
examAdvacementName = config.getString("AdvancementName", "doggycraft:doggycraft/student");
grantAdvancement = config.getBoolean("GrantAdvancement", false);
debug = config.getBoolean("Debug", false);
}

Expand All @@ -94,6 +98,8 @@ public void saveSettings()
config.set("ServerName", serverName);
config.set("MinExamTime", minExamTime);
config.set("RequiredExamScore", requiredExamScore);
config.set("AdvancementName", examAdvacementName);
config.set("GrantAdvancement", grantAdvancement);
config.set("Debug", debug);

saveConfig();
Expand Down