Skip to content

Commit

Permalink
Start working on claim map menu
Browse files Browse the repository at this point in the history
  • Loading branch information
cjburkey01 committed May 28, 2024
1 parent 9b6ca83 commit bb0c832
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 15 deletions.
2 changes: 2 additions & 0 deletions src/main/java/com/cjburkey/claimchunk/ClaimChunkConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ public class ClaimChunkConfig {
@Getter private String guiMainMenuCurrentChunkItem;
@Getter private String guiMainMenuChunkMapItem;
@Getter private String guiMainMenuPermFlagsItem;
@Getter private boolean guiMapMenuAllowClaimOtherChunks;

/* Titles */

Expand Down Expand Up @@ -170,6 +171,7 @@ public void reload() {
guiMainMenuCurrentChunkItem = getString("gui", "mainMenuCurrentChunk");
guiMainMenuChunkMapItem = getString("gui", "mainMenuChunkMapItem");
guiMainMenuPermFlagsItem = getString("gui", "mainMenuPermFlagsItem");
guiMapMenuAllowClaimOtherChunks = getBool("gui", "mapMenuAllowClaimOtherChunks");

useTitlesInsteadOfChat = getBool("titles", "useTitlesInsteadOfChat");
useActionBar = getBool("titles", "useActionBar");
Expand Down
15 changes: 14 additions & 1 deletion src/main/java/com/cjburkey/claimchunk/gui/GuiMenuScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ public abstract class GuiMenuScreen implements ICCGui {
/** Anonymous callback for item click event. */
@FunctionalInterface
public interface GuiItemAction {

/** Called when the item is clicked. */
void onClick(@NotNull ClickType clickType, @NotNull ItemStack stack);
}
Expand Down Expand Up @@ -134,4 +133,18 @@ public void onClose(@NotNull Inventory inventory, @NotNull Player player) {}
public int getRows() {
return rowCount;
}

/**
* Get the given item name's associated {@link Material} enum variant.
*
* @param val The item name, like {@code minecraft:grass_block}.
* @return The Material, or {@link Material#BARRIER} if the provided item isn't valid.
*/
protected static @NotNull Material materialFromStr(String val) {
Material item = Material.matchMaterial(val);
if (item == null) {
item = Material.BARRIER;
}
return item;
}
}
23 changes: 9 additions & 14 deletions src/main/java/com/cjburkey/claimchunk/gui/screens/MainMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
import com.cjburkey.claimchunk.gui.GuiMenuScreen;
import com.cjburkey.claimchunk.player.PlayerHandler;

import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Objects;
import java.util.UUID;
import java.util.regex.Pattern;

Expand All @@ -25,7 +25,7 @@ public class MainMenu extends GuiMenuScreen {
// 6: Chunk permissions

public MainMenu(ClaimChunk claimChunk) {
super(claimChunk, 1, "ClaimChunk Menu");
super(claimChunk, 1, claimChunk.getMessages().guiMainMenuTitle);
}

@Override
Expand Down Expand Up @@ -74,7 +74,7 @@ private void addCurrentChunkItem(@NotNull Player player) {

addInteractiveButton(
2,
material(claimChunk.getConfigHandler().getGuiMainMenuCurrentChunkItem()),
materialFromStr(claimChunk.getConfigHandler().getGuiMainMenuCurrentChunkItem()),
claimChunk.getMessages().guiMainMenuCurrentChunkItemName,
lore,
(clickType, stack) -> {
Expand All @@ -99,26 +99,21 @@ private void addCurrentChunkItem(@NotNull Player player) {
private void addMapItem() {
addInteractiveButton(
4,
material(claimChunk.getConfigHandler().getGuiMainMenuChunkMapItem()),
materialFromStr(claimChunk.getConfigHandler().getGuiMainMenuChunkMapItem()),
claimChunk.getMessages().guiMainMenuMapItemName,
Collections.singletonList(claimChunk.getMessages().guiMapDescription),
(clickType, stack) -> {});
(clickType, stack) ->
claimChunk
.getGuiHandler()
.openGui(Objects.requireNonNull(player), new MapMenu(claimChunk)));
}

private void addPermsItem() {
addInteractiveButton(
6,
material(claimChunk.getConfigHandler().getGuiMainMenuPermFlagsItem()),
materialFromStr(claimChunk.getConfigHandler().getGuiMainMenuPermFlagsItem()),
claimChunk.getMessages().guiMainMenuPermFlagsItemName,
Collections.singletonList(claimChunk.getMessages().guiMainMenuPermFlagsDescription),
(clickType, stack) -> {});
}

private @NotNull Material material(String val) {
Material item = Material.matchMaterial(val);
if (item == null) {
item = Material.BARRIER;
}
return item;
}
}
49 changes: 49 additions & 0 deletions src/main/java/com/cjburkey/claimchunk/gui/screens/MapMenu.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package com.cjburkey.claimchunk.gui.screens;

import com.cjburkey.claimchunk.ClaimChunk;
import com.cjburkey.claimchunk.chunk.ChunkPos;
import com.cjburkey.claimchunk.gui.GuiMenuScreen;

import org.bukkit.Material;

import java.util.ArrayList;

public class MapMenu extends GuiMenuScreen {

private static final int MAP_HEIGHT = 5;

public MapMenu(ClaimChunk claimChunk) {
super(claimChunk, MAP_HEIGHT, claimChunk.getMessages().guiMapMenuTitle);
}

@Override
protected void onBuildGui() {
if (player == null) return;

ChunkPos centerChunk = new ChunkPos(player.getLocation().getChunk());

int halfHeight = Math.floorDiv(MAP_HEIGHT, 2);

// Inventory width is 9, so go 4 eastward and westward
for (int offsetX = -4; offsetX <= 4; offsetX++) {
// Inventory height is `MAP_HEIGHT`, so go `halfHeight` northward and southward
for (int offsetZ = -halfHeight; offsetZ <= halfHeight; offsetZ++) {
int slot = (offsetX + 4) + 9 * (offsetZ + halfHeight);
ChunkPos offsetChunk =
new ChunkPos(
centerChunk.world(),
centerChunk.x() + offsetX,
centerChunk.z() + offsetZ);

// TODO: CHANGE MATERIAL

addInteractiveButton(
slot,
Material.DIRT,
"&r&fChunk at " + offsetChunk,
new ArrayList<>(),
(clickType, stack) -> {});
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ public final class V2JsonMessages {
public String chunkCancelPearlLaunch = "&cYou can't use ender pearls in &e%%OWNER%%&c's chunk";

// GUI localization
public String guiMainMenuTitle = "ClaimChunk Main GUI";
public String guiMainMenuCurrentChunkItemName = "&r&3&lCurrent Chunk";
public String guiChunkPos = "&fIn &e%%WORLD%%&f at (&e%%X%%&f, &e%%Z%%&f)";
public String guiChunkOwner = "&fOwner: %%NAME%%";
Expand All @@ -192,6 +193,7 @@ public final class V2JsonMessages {
public String guiMainMenuPermFlagsItemName = "&r&3&lPermission Flags";
public String guiMainMenuPermFlagsDescription =
"&fClick to manage other players' permissions in your chunk(s)";
public String guiMapMenuTitle = "ClaimChunk Map";

// AdminOverride localization
public String adminOverrideEnable = "&eYou now have protection bypass";
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ gui:
mainMenuCurrentChunk: 'minecraft:grass_block'
mainMenuChunkMapItem: 'minecraft:map'
mainMenuPermFlagsItem: 'minecraft:writable_book'
mapMenuAllowClaimOtherChunks: true

titles:
useTitlesInsteadOfChat: true
Expand Down

0 comments on commit bb0c832

Please sign in to comment.