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.events.*;
|
||||
import com.alttd.altitudequests.objects.Quest;
|
||||
import com.alttd.altitudequests.util.AutoHideBossBar;
|
||||
import com.alttd.altitudequests.util.Logger;
|
||||
import com.alttd.altitudequests.util.Utilities;
|
||||
import com.alttd.datalock.DataLockAPI;
|
||||
|
|
@ -37,6 +38,7 @@ public final class AQuest extends JavaPlugin {
|
|||
} else {
|
||||
dataLockAPI.registerChannel("aquest:player-data");
|
||||
}
|
||||
AutoHideBossBar.initiate();
|
||||
|
||||
Logger.info("--------------------------------------------------");
|
||||
Logger.info("AQuest started");
|
||||
|
|
|
|||
|
|
@ -5,18 +5,17 @@ import com.alttd.altitudequests.config.Config;
|
|||
import com.alttd.altitudequests.config.MessagesConfig;
|
||||
import com.alttd.altitudequests.database.Database;
|
||||
import com.alttd.altitudequests.objects.quests.*;
|
||||
import com.alttd.altitudequests.util.AutoHideBossBar;
|
||||
import com.alttd.altitudequests.util.Logger;
|
||||
import com.alttd.altitudequests.util.Utilities;
|
||||
import com.alttd.altitudequests.util.AutoHideBossBar;
|
||||
import org.bukkit.boss.BarColor;
|
||||
import com.alttd.datalock.DataLockAPI;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.boss.BarColor;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.sql.PreparedStatement;
|
||||
|
|
@ -51,8 +50,8 @@ public abstract class Quest {
|
|||
private boolean isDone;
|
||||
private boolean rewardReceived;
|
||||
private final int amount;
|
||||
// private final AutoHideBossBar barProgressOne;
|
||||
// private final AutoHideBossBar barProgressTwo;
|
||||
private final AutoHideBossBar barProgressOne;
|
||||
private final AutoHideBossBar barProgressTwo;
|
||||
|
||||
public static synchronized void putDailyQuest(UUID uuid, Quest quest) {
|
||||
dailyQuests.put(uuid, quest);
|
||||
|
|
@ -93,8 +92,8 @@ public abstract class Quest {
|
|||
this.amount = variant.calculateAmount(loadQuestsDoneThisMonth(uuid));
|
||||
else
|
||||
this.amount = amount;
|
||||
// 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.barProgressOne = new AutoHideBossBar(player, variant, "1", "Step One Progress", BarColor.GREEN);
|
||||
this.barProgressTwo = new AutoHideBossBar(player, variant, "2", "Step Two Progress", BarColor.PURPLE);
|
||||
}
|
||||
|
||||
private int loadQuestsDoneThisMonth(UUID uuid) {
|
||||
|
|
@ -303,7 +302,7 @@ public abstract class Quest {
|
|||
|
||||
public void addStep1(int step1) {
|
||||
this.step1 += step1;
|
||||
// barProgressOne.show(((double) getStep1()) / getAmount());
|
||||
barProgressOne.show(((double) getStep1()) / getAmount());
|
||||
}
|
||||
|
||||
public int getStep2() {
|
||||
|
|
@ -312,7 +311,7 @@ public abstract class Quest {
|
|||
|
||||
public void addStep2(int step2) {
|
||||
this.step2 += step2;
|
||||
// barProgressTwo.show(((double) getStep2()) / getAmount());
|
||||
barProgressTwo.show(((double) getStep2()) / getAmount());
|
||||
}
|
||||
|
||||
public void setDone(boolean done) {
|
||||
|
|
|
|||
|
|
@ -155,7 +155,7 @@ public class OtherQuest extends Quest {
|
|||
}
|
||||
|
||||
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;
|
||||
}
|
||||
addStep1(1);
|
||||
|
|
@ -163,7 +163,7 @@ public class OtherQuest extends Quest {
|
|||
}
|
||||
|
||||
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;
|
||||
}
|
||||
DyeColor color = getDyeColorFromItemStack(otherQuestObject.getMaterial());
|
||||
|
|
@ -177,7 +177,7 @@ public class OtherQuest extends Quest {
|
|||
}
|
||||
|
||||
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;
|
||||
}
|
||||
addStep1(1);
|
||||
|
|
@ -185,7 +185,7 @@ public class OtherQuest extends Quest {
|
|||
}
|
||||
|
||||
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;
|
||||
}
|
||||
addStep1(1);
|
||||
|
|
|
|||
|
|
@ -9,20 +9,22 @@ import org.bukkit.boss.BarColor;
|
|||
import org.bukkit.boss.BarStyle;
|
||||
import org.bukkit.boss.BossBar;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
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 Thread thread = new Thread(this);
|
||||
private Instant endTime;
|
||||
|
||||
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());
|
||||
if (namespacedKeyOne == null) {
|
||||
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(
|
||||
namespacedKeyOne,
|
||||
|
|
@ -33,33 +35,24 @@ public class AutoHideBossBar implements Runnable {
|
|||
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) {
|
||||
bossBar.setVisible(true);
|
||||
bossBar.setProgress(progress);
|
||||
schedule();
|
||||
bossBars.put(bossBar, Instant.now().plusSeconds(Config.BOSS_BAR_AUTO_HIDE.toSeconds()));
|
||||
}
|
||||
|
||||
private synchronized boolean waitOrRunTask() {
|
||||
if (Instant.now().isBefore(endTime))
|
||||
return true;
|
||||
bossBar.setVisible(false);
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
while (waitOrRunTask()) {
|
||||
try {
|
||||
wait(100);
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException(e);
|
||||
public static void initiate() {
|
||||
new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
for (HashMap.Entry<BossBar, Instant> entry : bossBars.entrySet()) {
|
||||
if (Instant.now().isAfter(entry.getValue())) {
|
||||
BossBar bossBar = entry.getKey();
|
||||
bossBar.setVisible(false);
|
||||
bossBars.remove(entry.getKey());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}.runTaskTimer(AQuest.getInstance(), 10, 10);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user