Skip to content

Commit

Permalink
feat: add defaultmenu to specific wardrobes
Browse files Browse the repository at this point in the history
  • Loading branch information
LoJoSho committed Nov 20, 2024
1 parent 1b6adca commit 6dcaf06
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command
}
Wardrobe wardrobe = WardrobeSettings.getWardrobe(args[1]);
if (wardrobe == null) {
wardrobe = new Wardrobe(args[1], new WardrobeLocation(null, null, null), null, -1);
wardrobe = new Wardrobe(args[1], new WardrobeLocation(null, null, null), null, -1, null);
WardrobeSettings.addWardrobe(wardrobe);
//MessagesUtil.sendMessage(player, "no-wardrobes");
//return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,27 @@ public class Wardrobe {
private final String id;
@Getter @Setter
private int distance;
@Getter @Setter
@Getter @Setter @Nullable
private String permission;
@Getter @Setter
private WardrobeLocation location;
@Getter @Setter @Nullable
private String defaultMenu;

/**
* This creates a Wardrobe object with all the information that a user will need when entering.
* @param id The id of the wardrobe
* @param location The 3 locations of the Wardrobe, if any of these 3 locations are null, the wardrobe will not work
* @param permission The permission required to enter the wardrobe, if null, no permission is required
* @param distance The distance from the wardrobe that the player can be to enter, if -1, the player can enter from any distance
* @param defaultMenu The default menu that the player will open when entering the wardrobe.
*/
public Wardrobe(@NotNull String id, @NotNull WardrobeLocation location, @Nullable String permission, int distance) {
public Wardrobe(@NotNull String id, @NotNull WardrobeLocation location, @Nullable String permission, int distance, @Nullable String defaultMenu) {
this.id = id;
this.location = location;
this.distance = distance;
if (permission != null) this.permission = permission;
if (defaultMenu != null) this.defaultMenu = defaultMenu;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public class WardrobeSettings {
private static final String WARDROBES_PATH = "wardrobes";
private static final String PERMISSION_PATH = "permission";
private static final String DISTANCE_PATH = "distance";
private static final String WARDROBE_DEFAULT_MENU = "default-menu";
private static final String BOSSBAR_PATH = "bossbar";
private static final String BOSSBAR_ENABLE_PATH = "enabled";
private static final String BOSSBAR_TEXT_PATH = "text";
Expand Down Expand Up @@ -174,9 +175,10 @@ public static void load(ConfigurationNode source) {
WardrobeLocation wardrobeLocation = new WardrobeLocation(npcLocation, viewerLocation, leaveLocation);

String permission = wardrobesNode.node(PERMISSION_PATH).getString();
String defaultMenu = wardrobesNode.node(WARDROBE_DEFAULT_MENU).getString();
int distance = wardrobesNode.node(DISTANCE_PATH).getInt(-1);

Wardrobe wardrobe = new Wardrobe(id, wardrobeLocation, permission, distance);
Wardrobe wardrobe = new Wardrobe(id, wardrobeLocation, permission, distance, defaultMenu);
addWardrobe(wardrobe);
} catch (Exception e) {
MessagesUtil.sendDebugMessages("Unable to create wardrobe " + id, Level.SEVERE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,11 @@ public UserWardrobeManager(CosmeticUser user, Wardrobe wardrobe) {
this.viewingLocation = wardrobeLocation.getViewerLocation();
this.npcLocation = wardrobeLocation.getNpcLocation();

String defaultMenu = wardrobe.getDefaultMenu();
if (defaultMenu != null && Menus.hasMenu(defaultMenu)) this.lastOpenMenu = Menus.getMenu(defaultMenu);
else this.lastOpenMenu = Menus.getDefaultMenu();

wardrobeStatus = WardrobeStatus.SETUP;
this.lastOpenMenu = Menus.getDefaultMenu();
}

public void start() {
Expand Down
1 change: 1 addition & 0 deletions common/src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ wardrobe:
default:
distance: -1 # Distance in blocks that a player can interact with the wardrobe. -1 to ignore.
permission: "hmccosmetics.wardrobe.default" # Permission required to use the wardrobe.
default-menu: defaultmenu
npc-location:
world: "world"
x: 0
Expand Down

0 comments on commit 6dcaf06

Please sign in to comment.