Skip to content

Commit

Permalink
[Layout] Add API method for getting layout from config by name
Browse files Browse the repository at this point in the history
  • Loading branch information
NEZNAMY committed Sep 7, 2024
1 parent 4423442 commit 462d383
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import lombok.NonNull;
import me.neznamy.tab.api.TabAPI;
import me.neznamy.tab.api.TabPlayer;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

/**
Expand All @@ -20,7 +21,19 @@ public interface LayoutManager {
* Unique layout name
* @return Created layout
*/
Layout createNewLayout(String name);
@NotNull
Layout createNewLayout(@NonNull String name);

/**
* Returns defined layout from config by name. If no such layout is defined in config,
* {@code null} is returned.
*
* @param name
* Name of layout defined in config
* @return Layout defined in config by name or {@code null} if no such layout is defined
*/
@Nullable
Layout getLayout(@NonNull String name);

/**
* Sends layout to player. Set to {@code null} to make player not see
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,11 +166,18 @@ public void tickAllLayouts() {
// ------------------

@Override
public Layout createNewLayout(String name) {
@NotNull
public Layout createNewLayout(@NonNull String name) {
ensureActive();
return new LayoutPattern(this, name, new LayoutDefinition(null, Collections.emptyList(), new LinkedHashMap<>()));
}

@Override
@Nullable
public Layout getLayout(@NonNull String name) {
return layouts.get(name);
}

@Override
public void sendLayout(@NonNull me.neznamy.tab.api.TabPlayer player, @Nullable Layout layout) {
ensureActive();
Expand Down

0 comments on commit 462d383

Please sign in to comment.