Skip to content

Commit

Permalink
🔀 Merge pull request #265 from SkytAsul/release/0.20.1
Browse files Browse the repository at this point in the history
Release: 0.20.1
  • Loading branch information
SkytAsul authored Mar 19, 2023
2 parents 2ad0d08 + 4270bac commit 2af3b39
Show file tree
Hide file tree
Showing 109 changed files with 2,966 additions and 967 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
![bStats Servers](https://img.shields.io/bstats/servers/7460)
![bStats Players](https://img.shields.io/bstats/players/7460)
[![Discord](https://ptb.discordapp.com/api/guilds/482632781395132416/widget.png)](https://discord.gg/H8fXrkD)
[![Gitmoji](https://img.shields.io/badge/gitmoji-%20😜%20😍-FFDD67.svg?style=flat-square)](https://gitmoji.dev)

# BeautyQuests
What is **BeautyQuests**?
Expand Down
2 changes: 1 addition & 1 deletion core/Sky libs.sh
Original file line number Diff line number Diff line change
@@ -1 +1 @@
./libs.sh C:/Users/skyta/Documents/Minecraft/BuildTools/apache-maven-3.6.0/bin/mvn jars/
./libs.sh mvn jars/
30 changes: 15 additions & 15 deletions core/libs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,20 @@ echo -e "\e[93mInstalling BeautyQuests dependencies jars from \"$jarsPath\" to t

echo -e "Maven path: $mavenPath\e[39m"

"$mavenPath" install:install-file -Dfile=$jarsPath/dynmap.jar -DgroupId=org.dynmap -DartifactId=dynmap -Dversion=1.0 -Dpackaging=jar
"$mavenPath" install:install-file -Dfile=$jarsPath/Factions.jar -DgroupId=com.massivecraft -DartifactId=factions -Dversion=1.0 -Dpackaging=jar
"$mavenPath" install:install-file -Dfile=$jarsPath/MassiveCore.jar -DgroupId=com.massivecraft -DartifactId=massivecore -Dversion=1.0 -Dpackaging=jar
"$mavenPath" install:install-file -Dfile=$jarsPath/GPS.jar -DgroupId=com.live.bemmamin -DartifactId=gps -Dversion=1.0 -Dpackaging=jar
"$mavenPath" install:install-file -Dfile=$jarsPath/Jobs.jar -DgroupId=com.gamingmesh -DartifactId=jobs -Dversion=5.1.0.1 -Dpackaging=jar
"$mavenPath" install:install-file -Dfile=$jarsPath/McCombatLevel.jar -DgroupId=com.gmail.mrphpfan -DartifactId=mccombatlevel -Dversion=1.0 -Dpackaging=jar
"$mavenPath" install:install-file -Dfile=$jarsPath/mcMMO.jar -DgroupId=com.gmail.nossr50 -DartifactId=mcmmo -Dversion=1.0 -Dpackaging=jar
"$mavenPath" install:install-file -Dfile=$jarsPath/SkillAPI.jar -DgroupId=com.suxy -DartifactId=skillapi -Dversion=1.0 -Dpackaging=jar
"$mavenPath" install:install-file -Dfile=$jarsPath/Boss.jar -DgroupId=org.mineacademy -DartifactId=boss -Dversion=4.2.1 -Dpackaging=jar
"$mavenPath" install:install-file -Dfile=$jarsPath/CMI.jar -DgroupId=com.zrips -DartifactId=cmi -Dversion=9.0.2.1 -Dpackaging=jar
"$mavenPath" install:install-file -Dfile=$jarsPath/CMILib.jar -DgroupId=com.zrips -DartifactId=cmilib -Dversion=1.2.3.3 -Dpackaging=jar
"$mavenPath" install:install-file -Dfile=$jarsPath/UltimateTimber.jar -DgroupId=com.songoda -DartifactId=ultimatetimber -Dversion=2.2.5 -Dpackaging=jar
"$mavenPath" install:install-file -Dfile=$jarsPath/AdvancedSpawners-API.jar -DgroupId=gcspawners -DartifactId=gcspawners -Dversion=3.3.0 -Dpackaging=jar
#"$mavenPath" install:install-file -Dfile=$jarsPath/MythicMobs.jar -DgroupId=io.lumine.xikage -DartifactId=MythicMobs -Dversion=4.12.0 -Dpackaging=jar
#"$mavenPath" install:install-file -Dfile=$jarsPath/TokenEnchantAPI.jar -DgroupId=com.vk2gpz.tokenenchant -DartifactId=TokenEnchantAPI -Dversion=18.15.2 -Dpackaging=jar
"$mavenPath" install:install-file -Dfile=$jarsPath/dynmap.jar -DgroupId=org.dynmap -DartifactId=dynmap -Dversion=1.0 -Dpackaging=jar -DgeneratePom=true
"$mavenPath" install:install-file -Dfile=$jarsPath/Factions.jar -DgroupId=com.massivecraft -DartifactId=factions -Dversion=1.0 -Dpackaging=jar -DgeneratePom=true
"$mavenPath" install:install-file -Dfile=$jarsPath/MassiveCore.jar -DgroupId=com.massivecraft -DartifactId=massivecore -Dversion=1.0 -Dpackaging=jar -DgeneratePom=true
"$mavenPath" install:install-file -Dfile=$jarsPath/GPS.jar -DgroupId=com.live.bemmamin -DartifactId=gps -Dversion=1.0 -Dpackaging=jar -DgeneratePom=true
"$mavenPath" install:install-file -Dfile=$jarsPath/Jobs.jar -DgroupId=com.gamingmesh -DartifactId=jobs -Dversion=5.1.0.1 -Dpackaging=jar -DgeneratePom=true
"$mavenPath" install:install-file -Dfile=$jarsPath/McCombatLevel.jar -DgroupId=com.gmail.mrphpfan -DartifactId=mccombatlevel -Dversion=1.0 -Dpackaging=jar -DgeneratePom=true
"$mavenPath" install:install-file -Dfile=$jarsPath/mcMMO.jar -DgroupId=com.gmail.nossr50 -DartifactId=mcmmo -Dversion=1.0 -Dpackaging=jar -DgeneratePom=true
"$mavenPath" install:install-file -Dfile=$jarsPath/SkillAPI.jar -DgroupId=com.suxy -DartifactId=skillapi -Dversion=1.0 -Dpackaging=jar -DgeneratePom=true
"$mavenPath" install:install-file -Dfile=$jarsPath/Boss.jar -DgroupId=org.mineacademy -DartifactId=boss -Dversion=4.2.1 -Dpackaging=jar -DgeneratePom=true
"$mavenPath" install:install-file -Dfile=$jarsPath/CMI.jar -DgroupId=com.zrips -DartifactId=cmi -Dversion=9.0.2.1 -Dpackaging=jar -DgeneratePom=true
"$mavenPath" install:install-file -Dfile=$jarsPath/CMILib.jar -DgroupId=com.zrips -DartifactId=cmilib -Dversion=1.2.3.3 -Dpackaging=jar -DgeneratePom=true
"$mavenPath" install:install-file -Dfile=$jarsPath/UltimateTimber.jar -DgroupId=com.songoda -DartifactId=UltimateTimber -Dversion=2.3.5 -Dpackaging=jar -DgeneratePom=true
"$mavenPath" install:install-file -Dfile=$jarsPath/AdvancedSpawners-API.jar -DgroupId=gcspawners -DartifactId=gcspawners -Dversion=3.3.0 -Dpackaging=jar -DgeneratePom=true
#"$mavenPath" install:install-file -Dfile=$jarsPath/MythicMobs.jar -DgroupId=io.lumine.xikage -DartifactId=MythicMobs -Dversion=4.12.0 -Dpackaging=jar -DgeneratePom=true
#"$mavenPath" install:install-file -Dfile=$jarsPath/TokenEnchantAPI.jar -DgroupId=com.vk2gpz.tokenenchant -DartifactId=TokenEnchantAPI -Dversion=18.15.2 -Dpackaging=jar -DgeneratePom=true

echo -e "\e[92mOperation complete."
16 changes: 11 additions & 5 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.20.0</version>
<version>0.20.1-SNAPSHOT</version>
</parent>

<build>
Expand Down Expand Up @@ -295,15 +295,21 @@
<version>2022.6</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.github.LoneDev6</groupId>
<artifactId>api-itemsadder</artifactId>
<version>3.2.5</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.github.Revxrsal.Lamp</groupId>
<artifactId>bukkit</artifactId>
<version>d72483065c</version>
<version>3.1.1</version>
</dependency>
<dependency>
<groupId>com.github.Revxrsal.Lamp</groupId>
<artifactId>common</artifactId>
<version>d72483065c</version>
<version>3.1.1</version>
</dependency>
<dependency>
<groupId>com.zaxxer</groupId>
Expand All @@ -320,8 +326,8 @@
</dependency>
<dependency>
<groupId>com.songoda</groupId>
<artifactId>ultimatetimber</artifactId>
<version>2.2.5</version>
<artifactId>UltimateTimber</artifactId>
<version>2.3.5</version>
<scope>provided</scope>
</dependency>
<dependency>
Expand Down
21 changes: 15 additions & 6 deletions core/src/main/java/fr/skytasul/quests/BeautyQuests.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ public class BeautyQuests extends JavaPlugin {
private ScoreboardManager scoreboards;
private QuestsManager quests;
private QuestPoolsManager pools;
private PlayersManager players;

/* ---------- Operations -------- */

Expand Down Expand Up @@ -249,6 +250,7 @@ private void checkPaper() {
private void registerCommands(){
command = new CommandsManager();
command.initializeCommands();
command.lockCommands(); // we are obligated to register Brigadier during plugin initialization...
}

private void launchSaveCycle(){
Expand Down Expand Up @@ -369,7 +371,8 @@ private void loadConfigParameters(boolean init) throws LoadingException {
}
}

PlayersManager.manager = db == null ? new PlayersManagerYAML() : new PlayersManagerDB(db);
players = db == null ? new PlayersManagerYAML() : new PlayersManagerDB(db);
PlayersManager.manager = players;

/* static initialization */
if (init) {
Expand Down Expand Up @@ -425,7 +428,7 @@ private void loadDataFile() throws LoadingException {
private void loadAllDatas() throws Throwable {
if (disable) return;
dependencies.lockDependencies();
command.lockCommands();
// command.lockCommands(); we cannot register Brigadier after plugin initialization...

if (scoreboards == null && QuestsConfiguration.showScoreboards()) {
File scFile = new File(getDataFolder(), "scoreboard.yml");
Expand All @@ -435,9 +438,10 @@ private void loadAllDatas() throws Throwable {
}

try{
if (db == null && backupDir != null) createPlayerDatasBackup(backupDir, (PlayersManagerYAML) PlayersManager.manager);
if (db == null && backupDir != null)
createPlayerDatasBackup(backupDir, (PlayersManagerYAML) players);

PlayersManager.manager.load();
players.load();
}catch (Exception ex) {
if (backupDir == null) createDataBackup(backupDir());
logger.severe("Error while loading player datas.", ex);
Expand Down Expand Up @@ -475,7 +479,7 @@ private void loadAllDatas() throws Throwable {

Bukkit.getScheduler().runTaskLater(BeautyQuests.getInstance(), () -> {
for (Player p : Bukkit.getOnlinePlayers()) {
PlayersManager.loadPlayer(p);
players.loadPlayer(p);
}
loaded = true;
}, 1L);
Expand All @@ -500,7 +504,7 @@ public void saveAllConfig(boolean unload) throws Exception {
data.set("version", getDescription().getVersion());

try {
PlayersManager.manager.save();
players.save();
}catch (Exception ex) {
logger.severe("Error when saving player datas.", ex);
}
Expand All @@ -522,6 +526,7 @@ private void resetDatas(){
}catch (Exception ex) {
logger.severe("An error occurred while closing database connection.", ex);
}
players = null;
PlayersManager.manager = null;
//HandlerList.unregisterAll(this);
loaded = false;
Expand Down Expand Up @@ -683,6 +688,10 @@ public QuestPoolsManager getPoolsManager() {
return pools;
}

public PlayersManager getPlayersManager() {
return players;
}

public ILoggerHandler getLoggerHandler() {
return loggerHandler == null ? ILoggerHandler.EMPTY_LOGGER : loggerHandler;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ public class QuestsConfiguration {
private static boolean stageStart = true;
private static boolean questConfirmGUI = false;
private static Collection<ClickType> npcClicks = Arrays.asList(ClickType.RIGHT, ClickType.SHIFT_RIGHT);
private static boolean skipNpcGuiIfOnlyOneQuest = true;
private static String dSetName = "Quests";
private static String dIcon = "bookshelf";
private static int dMinZoom = 0;
Expand Down Expand Up @@ -179,6 +180,7 @@ void init() {
}catch (IllegalArgumentException ex) {
BeautyQuests.logger.warning("Unknown click type " + config.get("npcClick") + " for config entry \"npcClick\"");
}
skipNpcGuiIfOnlyOneQuest = config.getBoolean("skip npc gui if only one quest");
enablePrefix = config.getBoolean("enablePrefix");
disableTextHologram = config.getBoolean("disableTextHologram");
showCustomHologramName = config.getBoolean("showCustomHologramName");
Expand Down Expand Up @@ -319,6 +321,10 @@ public static Collection<ClickType> getNPCClicks() {
return npcClicks;
}

public static boolean skipNpcGuiIfOnlyOneQuest() {
return skipNpcGuiIfOnlyOneQuest;
}

public static boolean handleGPS(){
return gps;
}
Expand Down
14 changes: 10 additions & 4 deletions core/src/main/java/fr/skytasul/quests/QuestsListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,10 @@ public void onNPCClick(BQNPCClickEvent e) {
return;
}
}
ChooseQuestGUI gui = new ChooseQuestGUI(launcheable, (quest) -> {
ChooseQuestGUI gui = new ChooseQuestGUI(launcheable, quest -> {
if (quest == null) return;
quest.clickNPC(p);
});
}, true);
gui.setValidate(__ -> {
new PlayerListGUI(acc).create(p);
}, ItemUtils.item(XMaterial.BOOKSHELF, Lang.questMenu.toString(), QuestOption.formatDescription(Lang.questMenuLore.toString())));
Expand Down Expand Up @@ -145,15 +145,21 @@ public void onOpen(InventoryOpenEvent e) {
@EventHandler (priority = EventPriority.LOWEST)
public void onJoin(PlayerJoinEvent e){
Player player = e.getPlayer();

DebugUtils.logMessage(player.getName() + " (" + player.getUniqueId().toString() + ") joined the server");
// for timing purpose

if (BeautyQuests.loaded && !QuestsConfiguration.hookAccounts()) {
PlayersManager.loadPlayer(player);
BeautyQuests.getInstance().getPlayersManager().loadPlayer(player);
}
}

@EventHandler
public void onQuit(PlayerQuitEvent e) {
Player player = e.getPlayer();
DebugUtils.logMessage(player.getName() + " left the server"); // for timing purpose
if (!QuestsConfiguration.hookAccounts()) {
PlayersManager.unloadPlayer(e.getPlayer());
BeautyQuests.getInstance().getPlayersManager().unloadPlayer(player);
}
}

Expand Down
8 changes: 7 additions & 1 deletion core/src/main/java/fr/skytasul/quests/api/QuestsAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,16 @@ public static List<ItemComparison> getItemComparisons() {
}

public static void registerItemComparison(ItemComparison comparison) {
Validate.isTrue(itemComparisons.stream().noneMatch(x -> x.getID().equals(comparison.getID())), "This item comparison was already registerd");
Validate.isTrue(itemComparisons.stream().noneMatch(x -> x.getID().equals(comparison.getID())),
"This item comparison was already registered");
itemComparisons.add(comparison);
DebugUtils.logMessage("Item comparison registered (id: " + comparison.getID() + ")");
}

public static void unregisterItemComparison(ItemComparison comparison) {
Validate.isTrue(itemComparisons.remove(comparison), "This item comparison was not registered");
DebugUtils.logMessage("Item comparison unregistered (id: " + comparison.getID() + ")");
}

public static List<MobStacker> getMobStackers() {
return mobStackers;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
package fr.skytasul.quests.api.comparison;

import java.util.function.BiPredicate;

import org.bukkit.inventory.ItemStack;

public class ItemComparison {

private final String id, itemName, itemDescription;
private final BiPredicate<ItemStack, ItemStack> comparator;
private boolean enabledByDefault, needsMeta;
private boolean enabledByDefault, needsMeta, hasPriority;

public ItemComparison(String id, String itemName, String itemDescription, BiPredicate<ItemStack, ItemStack> comparator) {
this.id = id;
Expand Down Expand Up @@ -47,6 +46,15 @@ public boolean isMetaNeeded() {
return needsMeta;
}

public ItemComparison setHasPriority() {
this.hasPriority = true;
return this;
}

public boolean hasPriority() {
return hasPriority;
}

/**
* This must <i>not</i> check the amount of the item. The function call must not affect the item in any way.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package fr.skytasul.quests.api.comparison;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.bukkit.Material;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;

import fr.skytasul.quests.api.QuestsAPI;

public class ItemComparisonMap implements Cloneable {
Expand All @@ -32,22 +32,25 @@ public ItemComparisonMap(Map<String, Boolean> notDefault) {
public void setNotDefaultComparisons(ConfigurationSection section) {
this.notDefault = (Map) section.getValues(false);

effective = new ArrayList<>();
effective = new ArrayList<>(3);
for (ItemComparison comp : QuestsAPI.getItemComparisons()) {
if (section.getBoolean(comp.getID(), comp.isEnabledByDefault())) effective.add(comp);
if (section.getBoolean(comp.getID(), comp.isEnabledByDefault()))
effective.add(comp);
}
updated();
}

public void setNotDefaultComparisons(Map<String, Boolean> comparisons) {
this.notDefault = comparisons;
effective = new ArrayList<>();

effective = new ArrayList<>(3);
for (ItemComparison comp : QuestsAPI.getItemComparisons()) {
Boolean bool = notDefault.get(comp.getID());
if (Boolean.FALSE.equals(bool)) continue;
if (!comp.isEnabledByDefault() && !Boolean.TRUE.equals(bool)) continue;
effective.add(comp);
}
updated();
}

public Map<String, Boolean> getNotDefault() {
Expand Down Expand Up @@ -79,23 +82,49 @@ public boolean toggle(ItemComparison comparison) {
}
if (bool) {
effective.add(comparison);
updated();
return true;
}else {
effective.remove(comparison);
return false;
}
}

private void updated() {
Collections.sort(effective, Comparator.comparing(ItemComparison::hasPriority));
}

public boolean isSimilar(ItemStack item1, ItemStack item2) {
boolean meta1 = item1.hasItemMeta();
boolean meta2 = item2.hasItemMeta();
return effective.stream().allMatch(x -> {
if (x.isMetaNeeded()) {
if (meta1 != meta2) return false;
if (!meta1) return true;

boolean lastResult = true;
for (ItemComparison comparison : effective) {
if (!comparison.hasPriority() && !lastResult) {
// comparisons with priority are tested at the very beginning
// if this comparison does not has priority and the last result is false then there is no need to go
// further: we can stop there
return false;
}
return x.isSimilar(item1, item2);
});

Boolean result = null;

if (comparison.isMetaNeeded()) {
if (meta1 != meta2) continue;
if (!meta1) result = true;
}

if (result == null) result = comparison.isSimilar(item1, item2);

if (result && comparison.hasPriority()) {
// if the comparison has priority and matches those items then we can stop there
return true;
}

lastResult = result;
}

return lastResult;
}

public boolean containsItems(Inventory inv, ItemStack i, int amount) {
Expand Down
Loading

0 comments on commit 2af3b39

Please sign in to comment.