Skip to content

Commit

Permalink
Ability to give each objective a task description
Browse files Browse the repository at this point in the history
  • Loading branch information
AlessioGr committed Jul 2, 2022
1 parent 62e13a8 commit 1e85e5d
Show file tree
Hide file tree
Showing 66 changed files with 1,048 additions and 1,009 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
import rocks.gravili.notquests.paper.commands.arguments.DurationArgument;
import rocks.gravili.notquests.paper.commands.arguments.ItemStackSelectionArgument;
import rocks.gravili.notquests.paper.commands.arguments.MiniMessageSelector;
import rocks.gravili.notquests.paper.commands.arguments.MiniMessageStringSelector;
import rocks.gravili.notquests.paper.commands.arguments.wrappers.ItemStackSelection;
import rocks.gravili.notquests.paper.managers.data.Category;
import rocks.gravili.notquests.paper.structs.Quest;
Expand Down Expand Up @@ -817,36 +818,41 @@ public void handleEditObjectives(final Command.Builder<CommandSender> builder) {
));
}));

manager.command(builder.literal("description")
.literal("set")
.argument(StringArrayArgument.of("Objective Description",
(context, lastString) -> {
final List<String> allArgs = context.getRawInput();
main.getUtilManager().sendFancyCommandCompletion(context.getSender(), allArgs.toArray(new String[0]), "<Enter new Objective description>", "");
ArrayList<String> completions = new ArrayList<>();
manager.command(builder.literal("taskDescription")
.literal("show")
.meta(CommandMeta.DESCRIPTION, "Shows current objective task description.")
.handler((context) -> {
final Quest quest = context.get("quest");
final int objectiveID = context.get("Objective ID");
final Objective objective = quest.getObjectiveFromID(objectiveID);
assert objective != null; //Shouldn't be null

String rawInput = context.getRawInputJoined();
if (lastString.startsWith("{")) {
completions.addAll(main.getCommandManager().getAdminCommands().placeholders);
} else {
if(lastString.startsWith("<")){
for(String color : main.getUtilManager().getMiniMessageTokens()){
completions.add("<"+ color +">");
//Now the closings. First we search IF it contains an opening and IF it doesnt contain more closings than the opening
if(rawInput.contains("<"+color+">")){
if(StringUtils.countMatches(rawInput, "<"+color+">") > StringUtils.countMatches(rawInput, "</"+color+">")){
completions.add("</"+ color +">");
}
}
}
}else{
completions.add("<Enter new Objective description>");
}
}
context.getSender().sendMessage(main.parse(
"<main>Current task description of objective with ID <highlight>" + objectiveID + "</highlight>: <highlight2>"
+ objective.getTaskDescriptionProvided()
));
}));
manager.command(builder.literal("taskDescription")
.literal("remove")
.meta(CommandMeta.DESCRIPTION, "Removes current objective task description.")
.handler((context) -> {
final Quest quest = context.get("quest");
final int objectiveID = context.get("Objective ID");
final Objective objective = quest.getObjectiveFromID(objectiveID);
assert objective != null; //Shouldn't be null

objective.removeTaskDescription(true);
context.getSender().sendMessage(main.parse(
"<main>Task description successfully removed from objective with ID <highlight>" + objectiveID + "</highlight>! New description: <highlight2>"
+ objective.getTaskDescriptionProvided()
));
}));

return completions;
}
), ArgumentDescription.of("Objective description"))
manager.command(builder.literal("description")
.literal("set")
.argument(MiniMessageSelector.<CommandSender>newBuilder("Objective Description", main)
.withPlaceholders()
.build(), ArgumentDescription.of("Objective description"))
.meta(CommandMeta.DESCRIPTION, "Sets current objective description.")
.handler((context) -> {
final Quest quest = context.get("quest");
Expand All @@ -862,6 +868,26 @@ public void handleEditObjectives(final Command.Builder<CommandSender> builder) {
));
}));

manager.command(builder.literal("taskDescription")
.literal("set")
.argument(MiniMessageSelector.<CommandSender>newBuilder("Task Description", main)
.withPlaceholders()
.build(), ArgumentDescription.of("Objective task description"))
.meta(CommandMeta.DESCRIPTION, "Sets current objective task description.")
.handler((context) -> {
final Quest quest = context.get("quest");
final int objectiveID = context.get("Objective ID");
final Objective objective = quest.getObjectiveFromID(objectiveID);
assert objective != null; //Shouldn't be null

final String taskDescription = String.join(" ", (String[]) context.get("Task Description"));
objective.setTaskDescription(taskDescription, true);
context.getSender().sendMessage(main.parse(
"<main>Task Description successfully added to objective with ID <highlight>" + objectiveID + "</highlight>! New description: <highlight2>"
+ objective.getTaskDescriptionProvided()
));
}));


manager.command(builder.literal("displayname")
.literal("show")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ public void loadQuestsFromConfig(final Category category) {

final String objectiveDisplayName = category.getQuestsConfig().getString("quests." + questName + ".objectives." + objectiveNumber + ".displayName", "");
final String objectiveDescription = category.getQuestsConfig().getString("quests." + questName + ".objectives." + objectiveNumber + ".description", "");
final String objectiveTaskDescription = category.getQuestsConfig().getString("quests." + questName + ".objectives." + objectiveNumber + ".taskDescription", "");
final int completionNPCID = category.getQuestsConfig().getInt("quests." + quest.getQuestName() + ".objectives." + objectiveNumber + ".completionNPCID", -1);
final String completionArmorStandUUIDString = category.getQuestsConfig().getString("quests." + quest.getQuestName() + ".objectives." + objectiveNumber + ".completionArmorStandUUID", null);
if (completionArmorStandUUIDString != null) {
Expand All @@ -264,7 +265,7 @@ public void loadQuestsFromConfig(final Category category) {
}

objective.setDescription(objectiveDescription.replace("\\n", "\n"), false);

objective.setTaskDescription(objectiveTaskDescription.replace("\\n", "\n"), false);
objective.setDisplayName(objectiveDisplayName.replace("\\n", "\n"), false);


Expand Down Expand Up @@ -1389,7 +1390,7 @@ public final String getObjectiveTaskDescription(final Objective objective, boole
public final String getObjectiveTaskDescription(final Objective objective, boolean completed, final QuestPlayer questPlayer, @Nullable final ActiveObjective activeObjective) {
String toReturn = "";

toReturn += objective.getObjectiveTaskDescription(questPlayer, activeObjective);
toReturn += objective.getTaskDescription(questPlayer, activeObjective);

if (objective.getCompletionNPCID() != -1) {
if (main.getIntegrationsManager().isCitizensEnabled()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,8 @@ public void registerObjective(
main.getCommandManager()
.getAdminEditAddObjectiveCommandBuilder()
.literal(identifier)
.meta(CommandMeta.DESCRIPTION, "Creates a new " + identifier + " objective"));
.meta(CommandMeta.DESCRIPTION, "Creates a new " + identifier + " objective")
.flag(main.getCommandManager().taskDescription));
} catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException e) {
e.printStackTrace();
}
Expand Down Expand Up @@ -182,11 +183,18 @@ public final Collection<String> getObjectiveIdentifiers() {

public void addObjective(Objective objective, CommandContext<CommandSender> context) {

Quest quest = context.getOrDefault("quest", null);
final Quest quest = context.getOrDefault("quest", null);

final String taskDescription =
context.flags().getValue(main.getCommandManager().taskDescription, "");

if (quest != null) {
objective.setQuest(quest);
objective.setObjectiveID(quest.getFreeObjectiveID());
if(taskDescription != null && !taskDescription.isBlank()) {
objective.setTaskDescription(taskDescription, true);
}

context
.getSender()
.sendMessage(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public void setItemStackSelection(final ItemStackSelection itemStackSelection) {
}

@Override
public String getObjectiveTaskDescription(
public String getTaskDescriptionInternal(
final QuestPlayer questPlayer, final @Nullable ActiveObjective activeObjective) {
/*String translatedMaterialName;
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public static void handleCommands(
}

@Override
public String getObjectiveTaskDescription(
public String getTaskDescriptionInternal(
final QuestPlayer questPlayer, final @Nullable ActiveObjective activeObjective) {
return main.getLanguageManager()
.getString("chat.objectives.taskDescription.breed.base", questPlayer, activeObjective)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public void setItemStackSelection(final ItemStackSelection itemStackSelection) {
}

@Override
public String getObjectiveTaskDescription(
public String getTaskDescriptionInternal(
final QuestPlayer questPlayer, final @Nullable ActiveObjective activeObjective) {
return main.getLanguageManager()
.getString(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public static void handleCommands(
}

@Override
public String getObjectiveTaskDescription(
public String getTaskDescriptionInternal(
final QuestPlayer questPlayer, final @Nullable ActiveObjective activeObjective) {
if (condition != null) {
return condition.getConditionDescription(questPlayer, getQuest());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public void onObjectiveCompleteOrLock(
final boolean completed) {}

@Override
public String getObjectiveTaskDescription(
public String getTaskDescriptionInternal(
final QuestPlayer questPlayer, final @Nullable ActiveObjective activeObjective) {
return main.getLanguageManager()
.getString(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public void onObjectiveCompleteOrLock(
final boolean completed) {}

@Override
public String getObjectiveTaskDescription(
public String getTaskDescriptionInternal(
final QuestPlayer questPlayer, final @Nullable ActiveObjective activeObjective) {
return main.getLanguageManager()
.getString(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ public void setRecipientArmorStandUUID(final UUID recipientArmorStandUUID) {
}

@Override
public String getObjectiveTaskDescription(final QuestPlayer questPlayer, final @Nullable ActiveObjective activeObjective) {
public String getTaskDescriptionInternal(final QuestPlayer questPlayer, final @Nullable ActiveObjective activeObjective) {


String toReturn;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public void setItemStackSelection(final ItemStackSelection itemStackSelection) {
}

@Override
public String getObjectiveTaskDescription(
public String getTaskDescriptionInternal(
final QuestPlayer questPlayer, final @Nullable ActiveObjective activeObjective) {
return main.getLanguageManager()
.getString(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ public class InteractObjective extends Objective {
private Location locationToInteract;
private boolean leftClick = false;
private boolean rightClick = false;
private String taskDescription = "";
private int maxDistance = 1;
private boolean cancelInteraction = false;

Expand Down Expand Up @@ -86,7 +85,6 @@ public static void handleCommands(
.withDescription(
ArgumentDescription.of(
"Makes it so the interaction will be cancelled while this objective is active")))
.flag(main.getCommandManager().taskDescription)
.flag(main.getCommandManager().maxDistance)
.handler(
(context) -> {
Expand All @@ -99,8 +97,6 @@ public static void handleCommands(

final boolean leftClick = context.flags().isPresent("leftClick");
final boolean rightClick = context.flags().isPresent("rightClick");
final String taskDescription =
context.flags().getValue(main.getCommandManager().taskDescription, "");
final int maxDistance =
context.flags().getValue(main.getCommandManager().maxDistance, 1);
final boolean cancelInteraction = context.flags().isPresent("cancelInteraction");
Expand All @@ -109,7 +105,6 @@ public static void handleCommands(
interactObjective.setLocationToInteract(location);
interactObjective.setLeftClick(leftClick);
interactObjective.setRightClick(rightClick);
interactObjective.setTaskDescription(taskDescription);
interactObjective.setMaxDistance(maxDistance);
interactObjective.setCancelInteraction(cancelInteraction);
interactObjective.setProgressNeededExpression(amountExpression);
Expand All @@ -119,9 +114,8 @@ public static void handleCommands(
}

@Override
public String getObjectiveTaskDescription(
public String getTaskDescriptionInternal(
final QuestPlayer questPlayer, final @Nullable ActiveObjective activeObjective) {
String toReturn;
String interactType = "";
if (isLeftClick()) {
interactType = "Left-Click";
Expand All @@ -138,57 +132,29 @@ public String getObjectiveTaskDescription(
worldName = getLocationToInteract().getWorld().getName();
}

if (taskDescription.isBlank()) {
toReturn =
main.getLanguageManager()
.getString(
"chat.objectives.taskDescription.interact.base",
questPlayer,
activeObjective,
Map.of(
"%INTERACTTYPE%", interactType,
"%COORDINATES%",
"X: "
+ getLocationToInteract().getX()
+ " Y: "
+ getLocationToInteract().getY()
+ " Z: "
+ getLocationToInteract().getZ(),
"%WORLDNAME%", worldName));
} else {
toReturn =
main.getLanguageManager()
.getString(
"chat.objectives.taskDescription.interact.taskDescriptionProvided",
questPlayer,
activeObjective,
Map.of(
"%TASKDESCRIPTION%",
getTaskDescription(),
"%INTERACTTYPE%",
interactType,
"%COORDINATES%",
"X: "
+ getLocationToInteract().getX()
+ " Y: "
+ getLocationToInteract().getY()
+ " Z: "
+ getLocationToInteract().getZ(),
"%WORLDNAME%",
worldName));
}

return toReturn;
return main.getLanguageManager()
.getString(
"chat.objectives.taskDescription.interact.base",
questPlayer,
activeObjective,
Map.of(
"%INTERACTTYPE%", interactType,
"%COORDINATES%",
"X: "
+ getLocationToInteract().getX()
+ " Y: "
+ getLocationToInteract().getY()
+ " Z: "
+ getLocationToInteract().getZ(),
"%WORLDNAME%", worldName));
}

@Override
public void save(FileConfiguration configuration, String initialPath) {
configuration.set(initialPath + ".specifics.locationToInteract", getLocationToInteract());
configuration.set(initialPath + ".specifics.leftClick", isLeftClick());
configuration.set(initialPath + ".specifics.rightClick", isRightClick());
if (!getTaskDescription().isBlank()) {
configuration.set(initialPath + ".specifics.taskDescription", getTaskDescription());
}

if (getMaxDistance() > 1) {
configuration.set(initialPath + ".specifics.maxDistance", getMaxDistance());
}
Expand All @@ -200,7 +166,6 @@ public void load(FileConfiguration configuration, String initialPath) {
locationToInteract = configuration.getLocation(initialPath + ".specifics.locationToInteract");
leftClick = configuration.getBoolean(initialPath + ".specifics.leftClick", false);
rightClick = configuration.getBoolean(initialPath + ".specifics.rightClick", false);
taskDescription = configuration.getString(initialPath + ".specifics.taskDescription", "");
maxDistance = configuration.getInt(initialPath + ".specifics.maxDistance", 1);
cancelInteraction =
configuration.getBoolean(initialPath + ".specifics.cancelInteraction", false);
Expand Down Expand Up @@ -241,14 +206,6 @@ public void setRightClick(final boolean rightClick) {
this.rightClick = rightClick;
}

public final String getTaskDescription() {
return taskDescription;
}

public void setTaskDescription(final String taskDescription) {
this.taskDescription = taskDescription;
}

public final int getMaxDistance() {
return maxDistance;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public void onObjectiveCompleteOrLock(
final boolean completed) {}

@Override
public String getObjectiveTaskDescription(
public String getTaskDescriptionInternal(
final QuestPlayer questPlayer, final @Nullable ActiveObjective activeObjective) {
return main.getLanguageManager()
.getString(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public static void handleCommands(
}

@Override
public String getObjectiveTaskDescription(
public String getTaskDescriptionInternal(
final QuestPlayer questPlayer, final @Nullable ActiveObjective activeObjective) {
return main.getLanguageManager()
.getString(
Expand Down
Loading

0 comments on commit 1e85e5d

Please sign in to comment.