Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
AlessioGr committed Aug 15, 2022
1 parent 1272068 commit 09ebe00
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 123 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ plugins {


group = "rocks.gravili.notquests"
version = "5.2.0"
version = "5.2.1"


repositories {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -956,4 +956,53 @@ public String analyze(final ConversationLine conversationLine, String beginningS

return toReturn.toString().toString();
}

/** Resends the chat history without ANY conversation messages */
public void removeOldMessages(final Player player) {
if (!main.getConfiguration().deletePreviousConversations) {
return;
}
// Send back old messages
ArrayList<Component> allChatHistory =
main.getConversationManager().getChatHistory().get(player.getUniqueId());

main.getLogManager().debug("Conversation stop stage 1");

if (allChatHistory == null) {
return;
}

ArrayList<Component> allConversationHistory =
main.getConversationManager()
.getConversationChatHistory()
.get(player.getUniqueId());
main.getLogManager().debug("Conversation stop stage 1.5");
if (allConversationHistory == null) {
return;
}
main.getLogManager().debug("Conversation stop stage 2");


Component collectiveComponent = Component.text("");
for (int i = 0; i < allChatHistory.size(); i++) {
Component component = allChatHistory.get(i);
if (component != null) {
// audience.sendMessage(component.append(Component.text("fg9023zf729ofz")));
collectiveComponent = collectiveComponent.append(component).append(Component.newline());
}
}
player.sendMessage(collectiveComponent);

allChatHistory.removeAll(allConversationHistory);
allConversationHistory.clear();
main.getConversationManager()
.getChatHistory()
.put(player.getUniqueId(), allChatHistory);
main.getConversationManager()
.getConversationChatHistory()
.put(player.getUniqueId(), allConversationHistory);

// maybe this won't send the huge, 1-component-chat-history again
allConversationHistory.add(collectiveComponent);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ public void sendLine(final ConversationLine conversationLine, boolean deletePrev
+ "] <GRAY>"
+ main.getUtilManager().applyPlaceholders(conversationLine.getMessage(), player));
if (deletePrevious) {
removeOldMessages();
main.getConversationManager().removeOldMessages(player);
}

if (main.getConfiguration().deletePreviousConversations) {
Expand Down Expand Up @@ -363,56 +363,6 @@ public void chooseOption(final String option) {
}
}

/** Resends the chat history without ANY conversation messages */
public void removeOldMessages() {
if (!main.getConfiguration().deletePreviousConversations) {
return;
}
// Send back old messages
ArrayList<Component> allChatHistory =
main.getConversationManager().getChatHistory().get(getQuestPlayer().getUniqueId());

main.getLogManager().debug("Conversation stop stage 1");

if (allChatHistory == null) {
return;
}

ArrayList<Component> allConversationHistory =
main.getConversationManager()
.getConversationChatHistory()
.get(getQuestPlayer().getUniqueId());
main.getLogManager().debug("Conversation stop stage 1.5");
if (allConversationHistory == null) {
return;
}
main.getLogManager().debug("Conversation stop stage 2");

final Player player = getQuestPlayer().getPlayer();

Component collectiveComponent = Component.text("");
for (int i = 0; i < allChatHistory.size(); i++) {
Component component = allChatHistory.get(i);
if (component != null) {
// audience.sendMessage(component.append(Component.text("fg9023zf729ofz")));
collectiveComponent = collectiveComponent.append(component).append(Component.newline());
}
}
player.sendMessage(collectiveComponent);

allChatHistory.removeAll(allConversationHistory);
allConversationHistory.clear();
main.getConversationManager()
.getChatHistory()
.put(getQuestPlayer().getUniqueId(), allChatHistory);
main.getConversationManager()
.getConversationChatHistory()
.put(getQuestPlayer().getUniqueId(), allConversationHistory);

// maybe this won't send the huge, 1-component-chat-history again
allConversationHistory.add(collectiveComponent);
}

public final QuestPlayer getQuestPlayer() {
return questPlayer;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,17 @@

package rocks.gravili.notquests.paper.events.hooks;

import org.betonquest.betonquest.BetonQuest;
import org.betonquest.betonquest.api.ConversationOptionEvent;
import org.betonquest.betonquest.api.PlayerObjectiveChangeEvent;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import rocks.gravili.notquests.paper.NotQuests;
import rocks.gravili.notquests.paper.commands.arguments.wrappers.ItemStackSelection;
import rocks.gravili.notquests.paper.structs.ActiveObjective;
import rocks.gravili.notquests.paper.structs.ActiveQuest;
import rocks.gravili.notquests.paper.structs.QuestPlayer;
import rocks.gravili.notquests.paper.structs.objectives.CollectItemsObjective;
import rocks.gravili.notquests.paper.structs.objectives.hooks.betonquest.BetonQuestObjectiveStateChangeObjective;

public class BetonQuestEvents implements Listener {
Expand All @@ -38,29 +41,34 @@ public BetonQuestEvents(NotQuests main) {
@EventHandler
public void onBetonQuestObjectiveStateChange(final PlayerObjectiveChangeEvent e) {
final QuestPlayer questPlayer = main.getQuestPlayerManager().getQuestPlayer(e.getPlayer().getUniqueId());
if (questPlayer != null) {
if (questPlayer.getActiveQuests().size() > 0) {
for (final ActiveQuest activeQuest : questPlayer.getActiveQuests()) {
for (final ActiveObjective activeObjective : activeQuest.getActiveObjectives()) {
if (activeObjective.getObjective() instanceof BetonQuestObjectiveStateChangeObjective betonQuestObjectiveStateChangeObjective) {
if (activeObjective.isUnlocked()) {
if(e.getState() == betonQuestObjectiveStateChangeObjective.getObjectiveState()){
if(e.getObjectiveID().getFullID().equalsIgnoreCase(betonQuestObjectiveStateChangeObjective.getObjectiveFullID())){
activeObjective.addProgress(1);
}
}
}

if (questPlayer == null || questPlayer.getActiveQuests().isEmpty()) {
return;
}
questPlayer.queueObjectiveCheck(activeObjective -> {
if (activeObjective.getObjective() instanceof final BetonQuestObjectiveStateChangeObjective betonQuestObjectiveStateChangeObjective) {
if (activeObjective.isUnlocked()) {
if(e.getState() == betonQuestObjectiveStateChangeObjective.getObjectiveState()){
if(e.getObjectiveID().getFullID().equalsIgnoreCase(betonQuestObjectiveStateChangeObjective.getObjectiveFullID())){
activeObjective.addProgress(1);
}
}
activeQuest.removeCompletedObjectives(true);
}
questPlayer.removeCompletedQuests();

}
}
});
questPlayer.checkQueuedObjectives();
}


@EventHandler
public void onBetonQuestObjectiveStateChange(final ConversationOptionEvent e) {
final BetonQuest betonQuest = main.getIntegrationsManager().getBetonQuestManager().getBetonQuest();

if(e.getConversation().getInterceptor().getClass() == betonQuest.getInterceptor("notquests")){
main.getConversationManager().removeOldMessages(e.getPlayer());
}
}



}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

package rocks.gravili.notquests.paper.managers.integrations.betonquest;


import org.betonquest.betonquest.BetonQuest;
import rocks.gravili.notquests.paper.NotQuests;
import rocks.gravili.notquests.paper.managers.integrations.betonquest.conditions.BQConditionsCondition;
Expand Down Expand Up @@ -78,4 +79,7 @@ public void initialize() {
public BetonQuest getBetonQuest() {
return betonQuest;
}



}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,12 @@ public NotQuestsInterceptor(final Conversation conv, final String playerID) {
*/
@Override
public void sendMessage(final String message) {
final Component parsedMessage = LegacyComponentSerializer.legacy('§').deserialize(message.replace("&", "§"));
final Component parsedMessage = main.parse(
main.getMiniMessage().serialize(LegacyComponentSerializer.legacy('§').deserialize(message.replace("&", "§")))
.replace("\\<", "<")
.replace("</white><bold><white> </white></bold><white>", "")
);

if (main.getConfiguration().deletePreviousConversations) {
ArrayList<Component> hist =
main.getConversationManager().getConversationChatHistory().get(player.getUniqueId());
Expand All @@ -51,7 +56,11 @@ public void sendMessage(final String message) {

@Override
public void sendMessage(final BaseComponent... message) {
final Component parsedMessage = BungeeComponentSerializer.legacy().deserialize(message);
final String mmString = main.getMiniMessage().serialize(BungeeComponentSerializer.get().deserialize(message))
.replace("\\<", "<")
.replace("</white><bold><white> </white></bold><white>", "");
final Component parsedMessage = main.parse(mmString);

if (main.getConfiguration().deletePreviousConversations) {
ArrayList<Component> hist =
main.getConversationManager().getConversationChatHistory().get(player.getUniqueId());
Expand All @@ -71,58 +80,6 @@ public void sendMessage(final BaseComponent... message) {
public void end() {
HandlerList.unregisterAll(this);

removeOldMessages();
//main.getConversationManager().removeOldMessages();
}

/** Resends the chat history without ANY conversation messages */
public void removeOldMessages() {
if (!main.getConfiguration().deletePreviousConversations) {
return;
}
// Send back old messages
ArrayList<Component> allChatHistory =
main.getConversationManager().getChatHistory().get(player.getUniqueId());

main.getLogManager().debug("Conversation stop stage 1");

if (allChatHistory == null) {
return;
}

ArrayList<Component> allConversationHistory =
main.getConversationManager()
.getConversationChatHistory()
.get(player.getUniqueId());
main.getLogManager().debug("Conversation stop stage 1.5");
if (allConversationHistory == null) {
return;
}
main.getLogManager().debug("Conversation stop stage 2");


Component collectiveComponent = Component.text("");
for (int i = 0; i < allChatHistory.size(); i++) {
Component component = allChatHistory.get(i);
if (component != null) {
// audience.sendMessage(component.append(Component.text("fg9023zf729ofz")));
collectiveComponent = collectiveComponent.append(component).append(Component.newline());
}
}
player.sendMessage(collectiveComponent);

allChatHistory.removeAll(allConversationHistory);
allConversationHistory.clear();
main.getConversationManager()
.getChatHistory()
.put(player.getUniqueId(), allChatHistory);
main.getConversationManager()
.getConversationChatHistory()
.put(player.getUniqueId(), allConversationHistory);

// maybe this won't send the huge, 1-component-chat-history again
allConversationHistory.add(collectiveComponent);
}



}

0 comments on commit 09ebe00

Please sign in to comment.