Skip to content

Commit

Permalink
A big update on menu system.
Browse files Browse the repository at this point in the history
  • Loading branch information
Rubix327 committed Oct 7, 2022
1 parent 95a3e38 commit cd3c544
Show file tree
Hide file tree
Showing 14 changed files with 259 additions and 233 deletions.
3 changes: 2 additions & 1 deletion src/main/java/org/mineacademy/fo/PlayerUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.mineacademy.fo.exception.FoException;
import org.mineacademy.fo.jsonsimple.JSONObject;
import org.mineacademy.fo.jsonsimple.JSONParser;
import org.mineacademy.fo.menu.AdvancedMenu;
import org.mineacademy.fo.menu.Menu;
import org.mineacademy.fo.model.HookManager;
import org.mineacademy.fo.plugin.SimplePlugin;
Expand Down Expand Up @@ -837,7 +838,7 @@ public static void updateInventoryTitle(final Menu menu, final Player player, fi
pending.cancel();

pending = Common.runLater(duration, () -> {
final Menu futureMenu = Menu.getMenu(player);
final AdvancedMenu futureMenu = AdvancedMenu.getMenu(player);

if (futureMenu != null && futureMenu.getClass().getName().equals(menu.getClass().getName()))
updateInventoryTitle(player, oldTitle);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,30 +1,21 @@
package org.mineacademy.fo.conversation;

import java.util.concurrent.TimeUnit;

import org.bukkit.conversations.Conversable;
import org.bukkit.conversations.Conversation;
import org.bukkit.conversations.ConversationAbandonedEvent;
import org.bukkit.conversations.ConversationAbandonedListener;
import org.bukkit.conversations.ConversationCanceller;
import org.bukkit.conversations.ConversationContext;
import org.bukkit.conversations.ConversationPrefix;
import org.bukkit.conversations.InactivityConversationCanceller;
import org.bukkit.conversations.Prompt;
import lombok.AccessLevel;
import lombok.Getter;
import org.bukkit.conversations.*;
import org.bukkit.entity.Player;
import org.mineacademy.fo.Common;
import org.mineacademy.fo.Messenger;
import org.mineacademy.fo.Valid;
import org.mineacademy.fo.collection.expiringmap.ExpiringMap;
import org.mineacademy.fo.menu.Menu;
import org.mineacademy.fo.menu.AdvancedMenu;
import org.mineacademy.fo.model.BoxedMessage;
import org.mineacademy.fo.model.Variables;
import org.mineacademy.fo.plugin.SimplePlugin;
import org.mineacademy.fo.remain.CompSound;
import org.mineacademy.fo.settings.SimpleLocalization;

import lombok.AccessLevel;
import lombok.Getter;
import java.util.concurrent.TimeUnit;

/**
* A simple way to communicate with the player
Expand All @@ -36,7 +27,7 @@ public abstract class SimpleConversation implements ConversationAbandonedListene
/**
* The menu to return to, if any
*/
private Menu menuToReturnTo;
private AdvancedMenu menuToReturnTo;

/**
* Creates a simple conversation
Expand All @@ -48,10 +39,8 @@ protected SimpleConversation() {
/**
* Creates a simple conversation that opens the
* menu when finished
*
* @param menuToReturnTo
*/
protected SimpleConversation(final Menu menuToReturnTo) {
protected SimpleConversation(final AdvancedMenu menuToReturnTo) {
this.menuToReturnTo = menuToReturnTo;
}

Expand Down Expand Up @@ -116,14 +105,14 @@ public final void conversationAbandoned(final ConversationAbandonedEvent event)
(event.gracefulExit() ? CompSound.SUCCESSFUL_HIT : CompSound.NOTE_BASS).play(player, 1F, 1F);

if (this.menuToReturnTo != null && this.reopenMenu()) {
final Menu newMenu = this.menuToReturnTo.newInstance();
final AdvancedMenu menu = AdvancedMenu.newInstanceOf(menuToReturnTo.getClass(), player);

newMenu.displayTo(player);
menu.display();

final String title = this.getMenuAnimatedTitle();

if (title != null)
Common.runLater(2, () -> newMenu.animateTitle(title));
Common.runLater(2, () -> menu.animateTitle(title));
}
}
}
Expand Down Expand Up @@ -220,10 +209,8 @@ protected boolean isModal() {

/**
* Sets the menu to return to after the end of this conversation
*
* @param menu
*/
public final void setMenuToReturnTo(final Menu menu) {
public final void setMenuToReturnTo(final AdvancedMenu menu) {
this.menuToReturnTo = menu;
}

Expand Down
23 changes: 5 additions & 18 deletions src/main/java/org/mineacademy/fo/conversation/SimplePrompt.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
package org.mineacademy.fo.conversation;

import org.bukkit.conversations.Conversable;
import org.bukkit.conversations.ConversationAbandonedEvent;
import org.bukkit.conversations.ConversationContext;
import org.bukkit.conversations.ConversationPrefix;
import org.bukkit.conversations.Prompt;
import org.bukkit.conversations.ValidatingPrompt;
import org.bukkit.conversations.*;
import org.bukkit.entity.Player;
import org.mineacademy.fo.Common;
import org.mineacademy.fo.Messenger;
import org.mineacademy.fo.Valid;
import org.mineacademy.fo.exception.FoException;
import org.mineacademy.fo.menu.Menu;
import org.mineacademy.fo.menu.AdvancedMenu;
import org.mineacademy.fo.model.Variables;
import org.mineacademy.fo.settings.SimpleLocalization;

Expand Down Expand Up @@ -48,25 +43,20 @@ protected SimplePrompt(final boolean openMenu) {

/**
* Return the prefix before tell messages
*
* @param ctx
* @return
*/
protected String getCustomPrefix() {
return null;
}

/**
* @see {@link SimpleConversation#isModal()}
*
* @return
* @see SimpleConversation#isModal()
*/
protected boolean isModal() {
return true;
}

/**
* @see SimpleConversation#setMenuAnimatedTitle(String)
* @see SimpleConversation#getMenuAnimatedTitle()
*
* @return
*/
Expand Down Expand Up @@ -137,9 +127,6 @@ protected final Player getPlayer(final ConversationContext ctx) {

/**
* Send the player (in case any) the given message
*
* @param ctx
* @param message
*/
protected final void tell(final String message) {
Valid.checkNotNull(this.player, "Cannot use tell() when player not yet set!");
Expand Down Expand Up @@ -265,7 +252,7 @@ protected void onConversationEnd(ConversationAbandonedEvent event, boolean cance
};

if (this.openMenu) {
final Menu menu = Menu.getMenu(player);
final AdvancedMenu menu = AdvancedMenu.getMenu(player);

if (menu != null)
conversation.setMenuToReturnTo(menu);
Expand Down
Loading

0 comments on commit cd3c544

Please sign in to comment.