mirror of
https://github.com/PikaMug/Quests.git
synced 2025-01-13 11:41:21 +01:00
Improve compass functionality and use permission, fixes #1106
This commit is contained in:
parent
fc7ccbe654
commit
ca9f71d16b
@ -182,7 +182,7 @@ public class Quest {
|
|||||||
this, quester.getPlayer()));
|
this, quester.getPlayer()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (plugin.getSettings().canUseCompass()) {
|
if (quester.getPlayer().hasPermission("quests.compass")) {
|
||||||
quester.resetCompass();
|
quester.resetCompass();
|
||||||
quester.findCompassTarget();
|
quester.findCompassTarget();
|
||||||
}
|
}
|
||||||
@ -277,31 +277,31 @@ public class Quest {
|
|||||||
* Method may be called as often as needed.
|
* Method may be called as often as needed.
|
||||||
*
|
*
|
||||||
* @param quester The online quester to have their compass updated
|
* @param quester The online quester to have their compass updated
|
||||||
* @param nextStage The stage to process for targets
|
* @param stage The stage to process for targets
|
||||||
* @return true if successful
|
* @return true if successful
|
||||||
*/
|
*/
|
||||||
public boolean updateCompass(Quester quester, Stage nextStage) {
|
public boolean updateCompass(Quester quester, Stage stage) {
|
||||||
if (!plugin.getSettings().canUseCompass()) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (quester == null) {
|
if (quester == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (nextStage == null) {
|
if (stage == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!quester.getOfflinePlayer().isOnline()) {
|
if (!quester.getOfflinePlayer().isOnline()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
if (!quester.getPlayer().hasPermission("quests.compass")) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
Location targetLocation = null;
|
Location targetLocation = null;
|
||||||
if (nextStage.citizensToInteract != null && nextStage.citizensToInteract.size() > 0) {
|
if (stage.citizensToInteract != null && stage.citizensToInteract.size() > 0) {
|
||||||
targetLocation = plugin.getDependencies().getNPCLocation(nextStage.citizensToInteract.getFirst());
|
targetLocation = plugin.getDependencies().getNPCLocation(stage.citizensToInteract.getFirst());
|
||||||
} else if (nextStage.citizensToKill != null && nextStage.citizensToKill.size() > 0) {
|
} else if (stage.citizensToKill != null && stage.citizensToKill.size() > 0) {
|
||||||
targetLocation = plugin.getDependencies().getNPCLocation(nextStage.citizensToKill.getFirst());
|
targetLocation = plugin.getDependencies().getNPCLocation(stage.citizensToKill.getFirst());
|
||||||
} else if (nextStage.locationsToReach != null && nextStage.locationsToReach.size() > 0) {
|
} else if (stage.locationsToReach != null && stage.locationsToReach.size() > 0) {
|
||||||
targetLocation = nextStage.locationsToReach.getFirst();
|
targetLocation = stage.locationsToReach.getFirst();
|
||||||
} else if (nextStage.itemDeliveryTargets != null && nextStage.itemDeliveryTargets.size() > 0) {
|
} else if (stage.itemDeliveryTargets != null && stage.itemDeliveryTargets.size() > 0) {
|
||||||
NPC npc = plugin.getDependencies().getCitizens().getNPCRegistry().getById(nextStage.itemDeliveryTargets
|
NPC npc = plugin.getDependencies().getCitizens().getNPCRegistry().getById(stage.itemDeliveryTargets
|
||||||
.getFirst());
|
.getFirst());
|
||||||
targetLocation = npc.getStoredLocation();
|
targetLocation = npc.getStoredLocation();
|
||||||
}
|
}
|
||||||
|
@ -30,6 +30,7 @@ import java.util.concurrent.ConcurrentHashMap;
|
|||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.DyeColor;
|
import org.bukkit.DyeColor;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
@ -76,6 +77,7 @@ public class Quester {
|
|||||||
private UUID id;
|
private UUID id;
|
||||||
protected String questToTake;
|
protected String questToTake;
|
||||||
protected int questPoints = 0;
|
protected int questPoints = 0;
|
||||||
|
private String compassTargetQuestId;
|
||||||
protected ConcurrentHashMap<Integer, Quest> timers = new ConcurrentHashMap<Integer, Quest>();
|
protected ConcurrentHashMap<Integer, Quest> timers = new ConcurrentHashMap<Integer, Quest>();
|
||||||
protected ConcurrentHashMap<Quest, Integer> currentQuests = new ConcurrentHashMap<Quest, Integer>() {
|
protected ConcurrentHashMap<Quest, Integer> currentQuests = new ConcurrentHashMap<Quest, Integer>() {
|
||||||
|
|
||||||
@ -254,6 +256,24 @@ public class Quester {
|
|||||||
public void setQuestPoints(int questPoints) {
|
public void setQuestPoints(int questPoints) {
|
||||||
this.questPoints = questPoints;
|
this.questPoints = questPoints;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get compass target quest. Returns null if not set
|
||||||
|
*
|
||||||
|
* @return Quest or null
|
||||||
|
*/
|
||||||
|
public Quest getCompassTarget() {
|
||||||
|
return compassTargetQuestId != null ? plugin.getQuestById(compassTargetQuestId) : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set compass target quest. Does not update in-game
|
||||||
|
*
|
||||||
|
* @param quest The target quest
|
||||||
|
*/
|
||||||
|
public void setCompassTarget(Quest quest) {
|
||||||
|
compassTargetQuestId = quest.getId();
|
||||||
|
}
|
||||||
|
|
||||||
public ConcurrentHashMap<Integer, Quest> getTimers() {
|
public ConcurrentHashMap<Integer, Quest> getTimers() {
|
||||||
return timers;
|
return timers;
|
||||||
@ -3535,8 +3555,9 @@ public class Quester {
|
|||||||
* Will set to Quester's spawn location if bed spawn does not exist
|
* Will set to Quester's spawn location if bed spawn does not exist
|
||||||
*/
|
*/
|
||||||
public void resetCompass() {
|
public void resetCompass() {
|
||||||
if (!plugin.getSettings().canUseCompass())
|
if (!getPlayer().hasPermission("quests.compass")) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
Player player = getPlayer();
|
Player player = getPlayer();
|
||||||
if (player == null)
|
if (player == null)
|
||||||
return;
|
return;
|
||||||
@ -3544,25 +3565,64 @@ public class Quester {
|
|||||||
if (defaultLocation == null) {
|
if (defaultLocation == null) {
|
||||||
defaultLocation = player.getWorld().getSpawnLocation();
|
defaultLocation = player.getWorld().getSpawnLocation();
|
||||||
}
|
}
|
||||||
|
compassTargetQuestId = null;
|
||||||
player.setCompassTarget(defaultLocation);
|
player.setCompassTarget(defaultLocation);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets first stage target from current quests, then updates compass accordingly
|
* Update compass target to current stage of first available current quest, if possible
|
||||||
*/
|
*/
|
||||||
public void findCompassTarget() {
|
public void findCompassTarget() {
|
||||||
if (!plugin.getSettings().canUseCompass())
|
if (!getPlayer().hasPermission("quests.compass")) {
|
||||||
return;
|
|
||||||
Player player = getPlayer();
|
|
||||||
if (player == null)
|
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
for (Quest quest : currentQuests.keySet()) {
|
for (Quest quest : currentQuests.keySet()) {
|
||||||
Stage stage = getCurrentStage(quest);
|
Stage stage = getCurrentStage(quest);
|
||||||
if (stage != null && quest.updateCompass(this, stage))
|
if (stage != null && quest.updateCompass(this, stage)) {
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update compass target to current stage of next available current quest, if possible
|
||||||
|
*
|
||||||
|
* @param notify Whether to notify this quester of result
|
||||||
|
*/
|
||||||
|
public void findNextCompassTarget(boolean notify) {
|
||||||
|
if (!getPlayer().hasPermission("quests.compass")) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Bukkit.getScheduler().runTaskAsynchronously(plugin, new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
LinkedList<String> list = currentQuests.keySet().stream()
|
||||||
|
.sorted(Comparator.comparing(Quest::getName)).map(Quest::getId)
|
||||||
|
.collect(Collectors.toCollection(LinkedList::new));
|
||||||
|
int index = 0;
|
||||||
|
if (compassTargetQuestId != null) {
|
||||||
|
if (!list.contains(compassTargetQuestId) && notify) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
index = list.indexOf(compassTargetQuestId) + 1;
|
||||||
|
if (index >= list.size()) {
|
||||||
|
index = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
final Quest quest = plugin.getQuestById(list.get(index));
|
||||||
|
compassTargetQuestId = quest.getId();
|
||||||
|
final Stage stage = getCurrentStage(quest);
|
||||||
|
if (stage != null) {
|
||||||
|
quest.updateCompass(Quester.this, stage);
|
||||||
|
if (notify && getPlayer().isOnline()) {
|
||||||
|
getPlayer().sendMessage(ChatColor.YELLOW + Lang.get(getPlayer(), "compassSet")
|
||||||
|
.replace("<quest>", ChatColor.GOLD + quest.getName() + ChatColor.YELLOW));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check whether the Quester's inventory contains the specified item
|
* Check whether the Quester's inventory contains the specified item
|
||||||
*
|
*
|
||||||
|
@ -37,7 +37,6 @@ public class Settings {
|
|||||||
private int topLimit = 150;
|
private int topLimit = 150;
|
||||||
private boolean translateNames = false;
|
private boolean translateNames = false;
|
||||||
private boolean translateSubCommands = false;
|
private boolean translateSubCommands = false;
|
||||||
private boolean useCompass = true;
|
|
||||||
private boolean useGPS = true;
|
private boolean useGPS = true;
|
||||||
|
|
||||||
public Settings(Quests plugin) {
|
public Settings(Quests plugin) {
|
||||||
@ -146,12 +145,6 @@ public class Settings {
|
|||||||
public void setTranslateSubCommands(boolean translateSubCommands) {
|
public void setTranslateSubCommands(boolean translateSubCommands) {
|
||||||
this.translateSubCommands = translateSubCommands;
|
this.translateSubCommands = translateSubCommands;
|
||||||
}
|
}
|
||||||
public boolean canUseCompass() {
|
|
||||||
return useCompass;
|
|
||||||
}
|
|
||||||
public void setUseCompass(boolean useCompass) {
|
|
||||||
this.useCompass = useCompass;
|
|
||||||
}
|
|
||||||
public boolean canUseGPS() {
|
public boolean canUseGPS() {
|
||||||
return useGPS;
|
return useGPS;
|
||||||
}
|
}
|
||||||
@ -184,7 +177,6 @@ public class Settings {
|
|||||||
topLimit = config.getInt("top-limit", 150);
|
topLimit = config.getInt("top-limit", 150);
|
||||||
translateNames = config.getBoolean("translate-names", true);
|
translateNames = config.getBoolean("translate-names", true);
|
||||||
translateSubCommands = config.getBoolean("translate-subcommands", false);
|
translateSubCommands = config.getBoolean("translate-subcommands", false);
|
||||||
useCompass = config.getBoolean("use-compass", true);
|
|
||||||
useGPS = config.getBoolean("use-gps-plugin", true);
|
useGPS = config.getBoolean("use-gps-plugin", true);
|
||||||
try {
|
try {
|
||||||
config.save(new File(plugin.getDataFolder(), "config.yml"));
|
config.save(new File(plugin.getDataFolder(), "config.yml"));
|
||||||
|
@ -183,9 +183,9 @@ public class PlayerListener implements Listener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (plugin.checkQuester(evt.getPlayer().getUniqueId()) == false) {
|
if (plugin.checkQuester(evt.getPlayer().getUniqueId()) == false) {
|
||||||
|
final Quester quester = plugin.getQuester(evt.getPlayer().getUniqueId());
|
||||||
|
final Player player = evt.getPlayer();
|
||||||
if (evt.getAction().equals(Action.RIGHT_CLICK_BLOCK)) {
|
if (evt.getAction().equals(Action.RIGHT_CLICK_BLOCK)) {
|
||||||
final Quester quester = plugin.getQuester(evt.getPlayer().getUniqueId());
|
|
||||||
final Player player = evt.getPlayer();
|
|
||||||
boolean hasObjective = false;
|
boolean hasObjective = false;
|
||||||
if (evt.isCancelled() == false) {
|
if (evt.isCancelled() == false) {
|
||||||
final ItemStack blockItemStack = new ItemStack(evt.getClickedBlock().getType(), 1, evt
|
final ItemStack blockItemStack = new ItemStack(evt.getClickedBlock().getType(), 1, evt
|
||||||
@ -347,6 +347,19 @@ public class PlayerListener implements Listener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (evt.getItem() != null && evt.getItem().getType().equals(Material.COMPASS)) {
|
||||||
|
if (!player.hasPermission("quests.compass")) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (evt.getAction().equals(Action.LEFT_CLICK_AIR)
|
||||||
|
|| evt.getAction().equals(Action.LEFT_CLICK_BLOCK)) {
|
||||||
|
quester.resetCompass();
|
||||||
|
player.sendMessage(ChatColor.YELLOW + Lang.get(player, "compassReset"));
|
||||||
|
} else if (evt.getAction().equals(Action.RIGHT_CLICK_AIR)
|
||||||
|
|| evt.getAction().equals(Action.RIGHT_CLICK_BLOCK)) {
|
||||||
|
quester.findNextCompassTarget(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -935,7 +948,7 @@ public class PlayerListener implements Listener {
|
|||||||
LinkedList<Quester> temp = plugin.getQuesters();
|
LinkedList<Quester> temp = plugin.getQuesters();
|
||||||
temp.add(quester);
|
temp.add(quester);
|
||||||
plugin.setQuesters(temp);
|
plugin.setQuesters(temp);
|
||||||
if (plugin.getSettings().canUseCompass()) {
|
if (evt.getPlayer().hasPermission("quests.compass")) {
|
||||||
quester.resetCompass();
|
quester.resetCompass();
|
||||||
}
|
}
|
||||||
for (String s : quester.getCompletedQuests()) {
|
for (String s : quester.getCompletedQuests()) {
|
||||||
|
@ -18,5 +18,4 @@ show-titles: true
|
|||||||
strict-player-movement: 0
|
strict-player-movement: 0
|
||||||
top-limit: 150
|
top-limit: 150
|
||||||
translate-names: true
|
translate-names: true
|
||||||
translate-subcommands: false
|
translate-subcommands: false
|
||||||
use-compass: true
|
|
@ -38,6 +38,9 @@ permissions:
|
|||||||
quests.journal:
|
quests.journal:
|
||||||
description: Toggle the Quest Journal
|
description: Toggle the Quest Journal
|
||||||
default: true
|
default: true
|
||||||
|
quests.compass:
|
||||||
|
description: Use a Compass to target quests
|
||||||
|
default: true
|
||||||
quests.admin:
|
quests.admin:
|
||||||
description: Display administrator help
|
description: Display administrator help
|
||||||
default: op
|
default: op
|
||||||
|
@ -702,6 +702,8 @@ journalAlreadyHave: "You already have your Quest Journal out."
|
|||||||
journalNoRoom: "You have no room in your inventory for your Quest Journal!"
|
journalNoRoom: "You have no room in your inventory for your Quest Journal!"
|
||||||
journalNoQuests: "You have no accepted quests!"
|
journalNoQuests: "You have no accepted quests!"
|
||||||
journalDenied: "You cannot do that with your Quest Journal."
|
journalDenied: "You cannot do that with your Quest Journal."
|
||||||
|
compassSet: "Set compass target to quest <quest>."
|
||||||
|
compassReset: "Reset compass target."
|
||||||
timeZone: "Time zone"
|
timeZone: "Time zone"
|
||||||
timeDay: "Day"
|
timeDay: "Day"
|
||||||
timeDays: "Days"
|
timeDays: "Days"
|
||||||
|
Loading…
Reference in New Issue
Block a user