Recoded Paginated menu api and redid all arena menus

This commit is contained in:
Luca 2021-11-23 13:33:53 +01:00
parent e11fdd3931
commit 1775f11016
8 changed files with 86 additions and 83 deletions

View File

@ -4,6 +4,7 @@ import org.bukkit.Material;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import rip.tilly.bedwars.BedWars; import rip.tilly.bedwars.BedWars;
import rip.tilly.bedwars.menus.arena.buttons.ArenaButton; import rip.tilly.bedwars.menus.arena.buttons.ArenaButton;
import rip.tilly.bedwars.utils.CC;
import rip.tilly.bedwars.utils.ItemBuilder; import rip.tilly.bedwars.utils.ItemBuilder;
import rip.tilly.bedwars.utils.menu.Button; import rip.tilly.bedwars.utils.menu.Button;
import rip.tilly.bedwars.utils.menu.pagination.PageButton; import rip.tilly.bedwars.utils.menu.pagination.PageButton;
@ -18,7 +19,7 @@ public class ArenaManagerMenu extends PaginatedMenu {
@Override @Override
public String getPrePaginatedTitle(Player player) { public String getPrePaginatedTitle(Player player) {
return "Arena Management"; return CC.translate("&eArena Management");
} }
@Override @Override

View File

@ -25,20 +25,19 @@ public class ArenaButton extends Button {
public ItemStack getButtonItem(Player player) { public ItemStack getButtonItem(Player player) {
return new ItemBuilder(Material.valueOf(arena.getIcon())) return new ItemBuilder(Material.valueOf(arena.getIcon()))
.durability(arena.getIconData()) .durability(arena.getIconData())
.name("&b" + arena.getName()) .name("&d&l" + arena.getName())
.lore(CC.translate( .lore(Arrays.asList(
Arrays.asList( " ",
" ", "&dArena Information:",
"&bArena Information&7:", " &7⚫ &9State: " + (arena.isEnabled() ? "&aEnabled" : "&cDisabled"),
" &9&l▸ &fState: " + (arena.isEnabled() ? "&aEnabled" : "&cDisabled"), " &7⚫ &9Copies: &e" + (arena.getCopiedArenas().size() == 0 ? "&cZERO!" : arena.getCopiedArenas().size()),
" &9&l▸ &fType: &b" + (arena.getAvailableArenas().size() == 0 ? "Shared" : "Standalone"), " &7⚫ &9Available: &e" + (arena.getAvailableArenas().size() == 0 ? 0 : arena.getAvailableArenas().size()),
" &9&l▸ &fCopies: &b" + (arena.getCopiedArenas().size() == 0 ? "Not Required!" : arena.getCopiedArenas().size()), " ",
" &9&l▸ &fAvailable: &b" + (arena.getAvailableArenas().size() == 0 ? +1 : arena.getAvailableArenas().size()), "&c/arena info " + arena.getName() + " for more information.",
" ", " ",
(arena.getCopiedArenas().size() == 0 ? "&4&l&mMIDDLE-CLICK &4&mto see arena copies" : "&6&lMIDDLE-CLICK &6to see arena copies"), (arena.getCopiedArenas().size() == 0 ? "&4&l&mMiddle Click &4&mto see copied arenas" : "&6&lMiddle Click &6to see copied arenas"),
"&a&lLEFT-CLICK &ato teleport to arena", "&a&lLeft Click &ato teleport to arena",
"&b&lRIGHT CLICK &bto generate standalone arenas") "&b&lRight Click &bto generate copied arenas")
)
) )
.hideFlags() .hideFlags()
.build(); .build();
@ -46,21 +45,23 @@ public class ArenaButton extends Button {
@Override @Override
public void clicked(Player player, int slot, ClickType clickType, int hotbarButton) { public void clicked(Player player, int slot, ClickType clickType, int hotbarButton) {
playSuccess(player); playNeutral(player);
switch (clickType) { switch (clickType) {
case LEFT: case LEFT:
player.teleport(arena.getA().toBukkitLocation()); player.teleport(arena.getA().toBukkitLocation());
player.closeInventory();
break; break;
case RIGHT: case RIGHT:
Bukkit.getScheduler().runTaskLaterAsynchronously(BedWars.getInstance(), () -> new ArenaGenerationMenu(arena).openMenu(player), 1L); Bukkit.getScheduler().runTaskLaterAsynchronously(BedWars.getInstance(), () -> new ArenaGenerationMenu(arena).openMenu(player), 1L);
player.closeInventory();
break; break;
case MIDDLE: case MIDDLE:
if (arena.getCopiedArenas().size() >= 1) { if (arena.getCopiedArenas().size() >= 1) {
Bukkit.getScheduler().runTaskLaterAsynchronously(BedWars.getInstance(), () -> new ArenaCopyMenu(arena).openMenu(player), 1L); Bukkit.getScheduler().runTaskLaterAsynchronously(BedWars.getInstance(), () -> new ArenaCopyMenu(arena).openMenu(player), 1L);
} else {
player.sendMessage(CC.translate("&cThis arena has no copied arenas! &4Generate some!"));
} }
break; break;
} }
player.closeInventory();
} }
} }

View File

@ -27,18 +27,17 @@ public class ArenaCopyButton extends Button {
@Override @Override
public ItemStack getButtonItem(Player player) { public ItemStack getButtonItem(Player player) {
return new ItemBuilder(Material.PAPER) return new ItemBuilder(Material.PAPER)
.name("&8" + number) .name("&d&lCopy #" + number)
.lore(CC.translate( .lore(CC.translate(
Arrays.asList( Arrays.asList(
"&bCopy Information&7:",
" &9&l▸ &fParent Arena: &b" + arena.getName() + " &7(&f#" + number + "&7)",
" &9&l▸ &f1st Spawn: &b" + Math.round(arenaCopy.getA().getX()) + "&7, &b" + Math.round(arenaCopy.getA().getY()) + "&7, &b" + Math.round(arenaCopy.getA().getZ()),
" &9&l▸ &f2nd Spawn: &b" + Math.round(arenaCopy.getB().getX()) + "&7, &b" + Math.round(arenaCopy.getB().getY()) + "&7, &b" + Math.round(arenaCopy.getB().getZ()),
" &9&l▸ &fMin Location: &b" + Math.round(arenaCopy.getMin().getX()) + "&7, &b" + Math.round(arenaCopy.getMin().getY()) + "&7, &b" + Math.round(arenaCopy.getMin().getZ()),
" &9&l▸ &fMax Location: &b" + Math.round(arenaCopy.getMax().getX()) + "&7, &b" + Math.round(arenaCopy.getMax().getY()) + "&7, &b" + Math.round(arenaCopy.getMax().getZ()),
" ", " ",
"&a&lLEFT-CLICK &ato teleport to this copy!", "&dCopied Arena Information:",
"&c&lRIGHT-CLICK &cto delete this copy!" " &7⚫ &9Parent Arena: &e" + arena.getName(),
" &7⚫ &91st Spawn: &e" + Math.round(arenaCopy.getA().getX()) + "&7, &e" + Math.round(arenaCopy.getA().getY()) + "&7, &e" + Math.round(arenaCopy.getA().getZ()),
" &7⚫ &92nd Spawn: &e" + Math.round(arenaCopy.getB().getX()) + "&7, &e" + Math.round(arenaCopy.getB().getY()) + "&7, &e" + Math.round(arenaCopy.getB().getZ()),
" ",
"&a&lLeft Click &ato teleport to this copied arena",
"&c&lRight Click &cto delete this copied arena"
)) ))
) )
.build(); .build();

View File

@ -21,14 +21,14 @@ public class ArenaGenerateButton extends Button {
@Override @Override
public ItemStack getButtonItem(Player player) { public ItemStack getButtonItem(Player player) {
return new ItemBuilder(Material.PAPER) return new ItemBuilder(Material.PAPER)
.name("&aCreate " + currentCopyAmount + " Arena Copies") .name("&eCreate " + currentCopyAmount + " Arena Copies")
.lore(CC.translate( .lore(CC.translate(
Arrays.asList( Arrays.asList(
" ", " ",
"&7Clicking here will generate &b&l" + currentCopyAmount, "&7Clicking here will generate &d&l" + currentCopyAmount,
"&7arenas for the map &b" + arena.getName() + "&7!", "&7arenas for the map &d&l" + arena.getName() + "&7!",
" ", " ",
"&a&lLEFT-CLICK &ato generate arenas") "&a&lLeft Click &ato generate arenas")
)) ))
.amount(currentCopyAmount) .amount(currentCopyAmount)
.build(); .build();
@ -39,11 +39,10 @@ public class ArenaGenerateButton extends Button {
player.performCommand("arena generate " + arena.getName() + " " + currentCopyAmount); player.performCommand("arena generate " + arena.getName() + " " + currentCopyAmount);
player.sendMessage(CC.chatBar); player.sendMessage(CC.chatBar);
player.sendMessage(CC.translate("&b&lGENERATING ARENAS&b...")); player.sendMessage(CC.translate("&d&lGENERATING ARENAS&d..."));
player.sendMessage(CC.translate(" ")); player.sendMessage(CC.translate(" "));
player.sendMessage(CC.translate("&fFrost is currently generating copies for:")); player.sendMessage(CC.translate(" &7⚫ &9Arena: &e" + arena.getName()));
player.sendMessage(CC.translate(" &9&l▸ &fArena: &b" + arena.getName())); player.sendMessage(CC.translate(" &7⚫ &9Copies: &e" + currentCopyAmount));
player.sendMessage(CC.translate(" &9&l▸ &fCopies: &b" + currentCopyAmount));
player.sendMessage(CC.translate(" ")); player.sendMessage(CC.translate(" "));
player.sendMessage(CC.translate("&7&oYou can check the progress in console.")); player.sendMessage(CC.translate("&7&oYou can check the progress in console."));
player.sendMessage(CC.chatBar); player.sendMessage(CC.chatBar);

View File

@ -1,15 +1,16 @@
package rip.tilly.bedwars.utils.menu.buttons; package rip.tilly.bedwars.utils.menu.buttons;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import org.bukkit.ChatColor;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.inventory.ClickType; import org.bukkit.event.inventory.ClickType;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta; import rip.tilly.bedwars.utils.ItemBuilder;
import rip.tilly.bedwars.utils.menu.Button; import rip.tilly.bedwars.utils.menu.Button;
import rip.tilly.bedwars.utils.menu.Menu; import rip.tilly.bedwars.utils.menu.Menu;
import java.util.Arrays;
@AllArgsConstructor @AllArgsConstructor
public class BackButton extends Button { public class BackButton extends Button {
@ -17,19 +18,16 @@ public class BackButton extends Button {
@Override @Override
public ItemStack getButtonItem(Player player) { public ItemStack getButtonItem(Player player) {
ItemStack itemStack = new ItemStack(Material.BED); return new ItemBuilder(Material.BED)
ItemMeta itemMeta = itemStack.getItemMeta(); .name("&cGo Back")
.lore(Arrays.asList(" ", "&9Click to go back."))
itemMeta.setDisplayName(ChatColor.RED + "Go back"); .hideFlags()
itemStack.setItemMeta(itemMeta); .build();
return itemStack;
} }
@Override @Override
public void clicked(Player player, int i, ClickType clickType, int hb) { public void clicked(Player player, int i, ClickType clickType, int hb) {
Button.playNeutral(player);
this.back.openMenu(player); this.back.openMenu(player);
playNeutral(player);
} }
} }

View File

@ -1,15 +1,15 @@
package rip.tilly.bedwars.utils.menu.pagination; package rip.tilly.bedwars.utils.menu.pagination;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import org.bukkit.ChatColor;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.inventory.ClickType; import org.bukkit.event.inventory.ClickType;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta; import rip.tilly.bedwars.utils.ItemBuilder;
import rip.tilly.bedwars.utils.menu.Button; import rip.tilly.bedwars.utils.menu.Button;
import java.util.Arrays; import java.util.ArrayList;
import java.util.List;
@AllArgsConstructor @AllArgsConstructor
public class JumpToPageButton extends Button { public class JumpToPageButton extends Button {
@ -20,26 +20,27 @@ public class JumpToPageButton extends Button {
@Override @Override
public ItemStack getButtonItem(Player player) { public ItemStack getButtonItem(Player player) {
ItemStack itemStack = new ItemStack(this.current ? Material.ENCHANTED_BOOK : Material.BOOK, this.page); List<String> lore = new ArrayList<>();
ItemMeta itemMeta = itemStack.getItemMeta();
itemMeta.setDisplayName(ChatColor.GREEN + "Page " + this.page);
lore.add(" ");
if (this.current) { if (this.current) {
itemMeta.setLore(Arrays.asList( lore.add("&9Current page");
"", } else {
ChatColor.GREEN + "Current page" lore.add("&9Other page");
));
} }
lore.add(" ");
itemStack.setItemMeta(itemMeta); return new ItemBuilder(Material.INK_SACK)
.name("&d&lPage: &e" + this.page)
return itemStack; .durability(this.current ? 10 : 8)
.lore(lore)
.hideFlags()
.build();
} }
@Override @Override
public void clicked(Player player, int i, ClickType clickType, int hb) { public void clicked(Player player, int i, ClickType clickType, int hb) {
this.menu.modPage(player, this.page - this.menu.getPage()); this.menu.modPage(player, this.page - this.menu.getPage());
Button.playNeutral(player); playNeutral(player);
} }
} }

View File

@ -1,15 +1,15 @@
package rip.tilly.bedwars.utils.menu.pagination; package rip.tilly.bedwars.utils.menu.pagination;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import org.bukkit.ChatColor;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.inventory.ClickType; import org.bukkit.event.inventory.ClickType;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta; import rip.tilly.bedwars.utils.ItemBuilder;
import rip.tilly.bedwars.utils.menu.Button; import rip.tilly.bedwars.utils.menu.Button;
import java.util.Arrays; import java.util.ArrayList;
import java.util.List;
@AllArgsConstructor @AllArgsConstructor
public class PageButton extends Button { public class PageButton extends Button {
@ -19,24 +19,19 @@ public class PageButton extends Button {
@Override @Override
public ItemStack getButtonItem(Player player) { public ItemStack getButtonItem(Player player) {
ItemStack itemStack = new ItemStack(Material.CARPET); List<String> lore = new ArrayList<>();
ItemMeta itemMeta = itemStack.getItemMeta();
if (this.hasNext(player)) { lore.add(" ");
itemMeta.setDisplayName(this.mod > 0 ? ChatColor.GREEN + "Next page" : ChatColor.RED + "Previous page"); lore.add("&9Right Click to");
} else { lore.add("&9switch to a page.");
itemMeta.setDisplayName(ChatColor.GRAY + (this.mod > 0 ? "Last page" : "First page")); lore.add(" ");
}
itemMeta.setLore(Arrays.asList( return new ItemBuilder(Material.CARPET)
"", .name(this.hasNext(player) ? (this.mod > 0 ? "&aNext Page" : "&cPrevious Page") : (this.mod > 0 ? "&7Last Page" : "&7First Page"))
ChatColor.GREEN + "Right click to", .durability(this.hasNext(player) ? (this.mod > 0 ? 5 : 14) : 8)
ChatColor.GREEN + "jump to a page" .lore(lore)
)); .hideFlags()
.build();
itemStack.setItemMeta(itemMeta);
return itemStack;
} }
@Override @Override
@ -47,9 +42,9 @@ public class PageButton extends Button {
} else { } else {
if (hasNext(player)) { if (hasNext(player)) {
this.menu.modPage(player, this.mod); this.menu.modPage(player, this.mod);
Button.playNeutral(player); playNeutral(player);
} else { } else {
Button.playFail(player); playFail(player);
} }
} }
} }

View File

@ -3,8 +3,10 @@ package rip.tilly.bedwars.utils.menu.pagination;
import lombok.Getter; import lombok.Getter;
import lombok.NonNull; import lombok.NonNull;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.bukkit.Material;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import rip.tilly.bedwars.utils.CC; import rip.tilly.bedwars.utils.CC;
import rip.tilly.bedwars.utils.ItemBuilder;
import rip.tilly.bedwars.utils.menu.Button; import rip.tilly.bedwars.utils.menu.Button;
import rip.tilly.bedwars.utils.menu.Menu; import rip.tilly.bedwars.utils.menu.Menu;
import rip.tilly.bedwars.utils.menu.buttons.BackButton; import rip.tilly.bedwars.utils.menu.buttons.BackButton;
@ -19,7 +21,7 @@ public class ViewAllPagesMenu extends Menu {
@Override @Override
public String getTitle(Player player) { public String getTitle(Player player) {
return CC.translate("&eJump to page"); return CC.translate("&eSwitch to page...");
} }
@Override @Override
@ -37,6 +39,8 @@ public class ViewAllPagesMenu extends Menu {
} }
} }
fillEmptySlots(buttons, new ItemBuilder(Material.STAINED_GLASS_PANE).durability(7).name(" ").build());
return buttons; return buttons;
} }
@ -44,4 +48,9 @@ public class ViewAllPagesMenu extends Menu {
public boolean isAutoUpdate() { public boolean isAutoUpdate() {
return true; return true;
} }
@Override
public int getSize() {
return 3 * 9;
}
} }