Minor changes for OtherQuests and a progress bar was added.
This commit is contained in:
parent
e93a922cc8
commit
2409103b3e
|
|
@ -4,6 +4,7 @@ import com.alttd.altitudequests.commands.CommandManager;
|
||||||
import com.alttd.altitudequests.config.*;
|
import com.alttd.altitudequests.config.*;
|
||||||
import com.alttd.altitudequests.events.*;
|
import com.alttd.altitudequests.events.*;
|
||||||
import com.alttd.altitudequests.objects.Quest;
|
import com.alttd.altitudequests.objects.Quest;
|
||||||
|
import com.alttd.altitudequests.util.AutoHideBossBar;
|
||||||
import com.alttd.altitudequests.util.Logger;
|
import com.alttd.altitudequests.util.Logger;
|
||||||
import com.alttd.altitudequests.util.Utilities;
|
import com.alttd.altitudequests.util.Utilities;
|
||||||
import com.alttd.datalock.DataLockAPI;
|
import com.alttd.datalock.DataLockAPI;
|
||||||
|
|
@ -37,6 +38,7 @@ public final class AQuest extends JavaPlugin {
|
||||||
} else {
|
} else {
|
||||||
dataLockAPI.registerChannel("aquest:player-data");
|
dataLockAPI.registerChannel("aquest:player-data");
|
||||||
}
|
}
|
||||||
|
AutoHideBossBar.initiate();
|
||||||
|
|
||||||
Logger.info("--------------------------------------------------");
|
Logger.info("--------------------------------------------------");
|
||||||
Logger.info("AQuest started");
|
Logger.info("AQuest started");
|
||||||
|
|
|
||||||
|
|
@ -5,18 +5,17 @@ import com.alttd.altitudequests.config.Config;
|
||||||
import com.alttd.altitudequests.config.MessagesConfig;
|
import com.alttd.altitudequests.config.MessagesConfig;
|
||||||
import com.alttd.altitudequests.database.Database;
|
import com.alttd.altitudequests.database.Database;
|
||||||
import com.alttd.altitudequests.objects.quests.*;
|
import com.alttd.altitudequests.objects.quests.*;
|
||||||
import com.alttd.altitudequests.util.AutoHideBossBar;
|
|
||||||
import com.alttd.altitudequests.util.Logger;
|
import com.alttd.altitudequests.util.Logger;
|
||||||
import com.alttd.altitudequests.util.Utilities;
|
import com.alttd.altitudequests.util.Utilities;
|
||||||
|
import com.alttd.altitudequests.util.AutoHideBossBar;
|
||||||
|
import org.bukkit.boss.BarColor;
|
||||||
import com.alttd.datalock.DataLockAPI;
|
import com.alttd.datalock.DataLockAPI;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||||
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
|
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.boss.BarColor;
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.scheduler.BukkitRunnable;
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
|
|
||||||
import java.lang.reflect.Constructor;
|
import java.lang.reflect.Constructor;
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.sql.PreparedStatement;
|
import java.sql.PreparedStatement;
|
||||||
|
|
@ -51,8 +50,8 @@ public abstract class Quest {
|
||||||
private boolean isDone;
|
private boolean isDone;
|
||||||
private boolean rewardReceived;
|
private boolean rewardReceived;
|
||||||
private final int amount;
|
private final int amount;
|
||||||
// private final AutoHideBossBar barProgressOne;
|
private final AutoHideBossBar barProgressOne;
|
||||||
// private final AutoHideBossBar barProgressTwo;
|
private final AutoHideBossBar barProgressTwo;
|
||||||
|
|
||||||
public static synchronized void putDailyQuest(UUID uuid, Quest quest) {
|
public static synchronized void putDailyQuest(UUID uuid, Quest quest) {
|
||||||
dailyQuests.put(uuid, quest);
|
dailyQuests.put(uuid, quest);
|
||||||
|
|
@ -93,8 +92,8 @@ public abstract class Quest {
|
||||||
this.amount = variant.calculateAmount(loadQuestsDoneThisMonth(uuid));
|
this.amount = variant.calculateAmount(loadQuestsDoneThisMonth(uuid));
|
||||||
else
|
else
|
||||||
this.amount = amount;
|
this.amount = amount;
|
||||||
// this.barProgressOne = new AutoHideBossBar(player, variant, "1", "Step One Progress", BarColor.GREEN);
|
this.barProgressOne = new AutoHideBossBar(player, variant, "1", "Step One Progress", BarColor.GREEN);
|
||||||
// this.barProgressTwo = new AutoHideBossBar(player, variant, "2", "Step Two Progress", BarColor.PURPLE);
|
this.barProgressTwo = new AutoHideBossBar(player, variant, "2", "Step Two Progress", BarColor.PURPLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
private int loadQuestsDoneThisMonth(UUID uuid) {
|
private int loadQuestsDoneThisMonth(UUID uuid) {
|
||||||
|
|
@ -303,7 +302,7 @@ public abstract class Quest {
|
||||||
|
|
||||||
public void addStep1(int step1) {
|
public void addStep1(int step1) {
|
||||||
this.step1 += step1;
|
this.step1 += step1;
|
||||||
// barProgressOne.show(((double) getStep1()) / getAmount());
|
barProgressOne.show(((double) getStep1()) / getAmount());
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getStep2() {
|
public int getStep2() {
|
||||||
|
|
@ -312,7 +311,7 @@ public abstract class Quest {
|
||||||
|
|
||||||
public void addStep2(int step2) {
|
public void addStep2(int step2) {
|
||||||
this.step2 += step2;
|
this.step2 += step2;
|
||||||
// barProgressTwo.show(((double) getStep2()) / getAmount());
|
barProgressTwo.show(((double) getStep2()) / getAmount());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setDone(boolean done) {
|
public void setDone(boolean done) {
|
||||||
|
|
|
||||||
|
|
@ -155,7 +155,7 @@ public class OtherQuest extends Quest {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void fish(ItemStack caughtItem) {
|
public void fish(ItemStack caughtItem) {
|
||||||
if (isDone() || !caughtItem.getType().equals(otherQuestObject.getMaterial()) || getAmount() == getStep1()) {
|
if (isDone() || !caughtItem.getType().equals(otherQuestObject.getMaterial()) || getAmount() == getStep1()|| !otherQuestObject.getCategory().equalsIgnoreCase("FISHING")) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
addStep1(1);
|
addStep1(1);
|
||||||
|
|
@ -163,7 +163,7 @@ public class OtherQuest extends Quest {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void shear(Entity entity) {
|
public void shear(Entity entity) {
|
||||||
if (isDone() || !entity.getType().equals(otherQuestObject.getEntity()) || getAmount() == getStep1()) {
|
if (isDone() || !entity.getType().equals(otherQuestObject.getEntity()) || getAmount() == getStep1()|| !otherQuestObject.getCategory().equalsIgnoreCase("SHEARING")) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
DyeColor color = getDyeColorFromItemStack(otherQuestObject.getMaterial());
|
DyeColor color = getDyeColorFromItemStack(otherQuestObject.getMaterial());
|
||||||
|
|
@ -177,7 +177,7 @@ public class OtherQuest extends Quest {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void bucket(ItemStack bucket, Entity entity) {
|
public void bucket(ItemStack bucket, Entity entity) {
|
||||||
if (isDone() || !entity.getType().equals(otherQuestObject.getEntity()) || getAmount() == getStep1()) {
|
if (isDone() || !entity.getType().equals(otherQuestObject.getEntity()) || getAmount() == getStep1()|| !otherQuestObject.getCategory().equalsIgnoreCase("BUCKETING")) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
addStep1(1);
|
addStep1(1);
|
||||||
|
|
@ -185,7 +185,7 @@ public class OtherQuest extends Quest {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void raid() {
|
public void raid() {
|
||||||
if (isDone() || getAmount() == getStep1() || !Objects.equals(otherQuestObject.getCategory(), "Raid")) { //without checking the category, other players who have otherQuests active will also have a step added
|
if (isDone() || getAmount() == getStep1() || !otherQuestObject.getCategory().equalsIgnoreCase("RAID")) { //without checking the category, other players who have otherQuests active will also have a step added
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
addStep1(1);
|
addStep1(1);
|
||||||
|
|
|
||||||
|
|
@ -9,20 +9,22 @@ import org.bukkit.boss.BarColor;
|
||||||
import org.bukkit.boss.BarStyle;
|
import org.bukkit.boss.BarStyle;
|
||||||
import org.bukkit.boss.BossBar;
|
import org.bukkit.boss.BossBar;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
|
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
public class AutoHideBossBar implements Runnable {
|
public class AutoHideBossBar {
|
||||||
|
|
||||||
|
private static final HashMap<BossBar, Instant> bossBars = new HashMap<>();
|
||||||
|
|
||||||
private final BossBar bossBar;
|
private final BossBar bossBar;
|
||||||
private final Thread thread = new Thread(this);
|
|
||||||
private Instant endTime;
|
|
||||||
|
|
||||||
public AutoHideBossBar(Player player, Variant variant, String part, String title, BarColor barColor) throws Exception {
|
public AutoHideBossBar(Player player, Variant variant, String part, String title, BarColor barColor) throws Exception {
|
||||||
NamespacedKey namespacedKeyOne = NamespacedKey.fromString(player.getUniqueId() + variant.getInternalName() + part, AQuest.getInstance());
|
NamespacedKey namespacedKeyOne = NamespacedKey.fromString(player.getUniqueId() + variant.getInternalName() + part, AQuest.getInstance());
|
||||||
if (namespacedKeyOne == null) {
|
if (namespacedKeyOne == null) {
|
||||||
Logger.warning("Unable to create nameSpacedKey with suffix % for quest for %", part, player.getName());
|
Logger.warning("Unable to create nameSpacedKey with suffix % for quest for %", part, player.getName());
|
||||||
throw new Exception("Failed to create namespace key");
|
throw new Exception("Failed to create namespace key"); //quest names containing upper case letters can cause this
|
||||||
}
|
}
|
||||||
this.bossBar = Bukkit.createBossBar(
|
this.bossBar = Bukkit.createBossBar(
|
||||||
namespacedKeyOne,
|
namespacedKeyOne,
|
||||||
|
|
@ -33,33 +35,24 @@ public class AutoHideBossBar implements Runnable {
|
||||||
bossBar.addPlayer(player);
|
bossBar.addPlayer(player);
|
||||||
}
|
}
|
||||||
|
|
||||||
private synchronized void schedule() {
|
|
||||||
endTime = Instant.now().plusSeconds(Config.BOSS_BAR_AUTO_HIDE.toSeconds());
|
|
||||||
if (!thread.isAlive())
|
|
||||||
thread.start();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void show(double progress) {
|
public void show(double progress) {
|
||||||
bossBar.setVisible(true);
|
bossBar.setVisible(true);
|
||||||
bossBar.setProgress(progress);
|
bossBar.setProgress(progress);
|
||||||
schedule();
|
bossBars.put(bossBar, Instant.now().plusSeconds(Config.BOSS_BAR_AUTO_HIDE.toSeconds()));
|
||||||
}
|
}
|
||||||
|
|
||||||
private synchronized boolean waitOrRunTask() {
|
public static void initiate() {
|
||||||
if (Instant.now().isBefore(endTime))
|
new BukkitRunnable() {
|
||||||
return true;
|
@Override
|
||||||
bossBar.setVisible(false);
|
public void run() {
|
||||||
return false;
|
for (HashMap.Entry<BossBar, Instant> entry : bossBars.entrySet()) {
|
||||||
}
|
if (Instant.now().isAfter(entry.getValue())) {
|
||||||
|
BossBar bossBar = entry.getKey();
|
||||||
@Override
|
bossBar.setVisible(false);
|
||||||
public void run() {
|
bossBars.remove(entry.getKey());
|
||||||
while (waitOrRunTask()) {
|
}
|
||||||
try {
|
}
|
||||||
wait(100);
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
}
|
||||||
}
|
}.runTaskTimer(AQuest.getInstance(), 10, 10);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user