Skip to content

Commit

Permalink
Update PluginUtilities to 1.6.0
Browse files Browse the repository at this point in the history
  • Loading branch information
jyhsu2000 committed Feb 18, 2024
1 parent 6132b2c commit c0fad11
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 57 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
<dependency>
<groupId>com.github.jyhsu2000</groupId>
<artifactId>PluginUtilities</artifactId>
<version>1.5.0</version>
<version>1.6.0</version>
</dependency>
<dependency>
<groupId>org.jetbrains</groupId>
Expand Down
34 changes: 17 additions & 17 deletions src/main/java/club/kid7/bannermaker/customMenu/BannerInfoMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
import club.kid7.bannermaker.util.IOUtil;
import club.kid7.bannermaker.util.InventoryUtil;
import club.kid7.bannermaker.util.MessageUtil;
import club.kid7.pluginutilities.gui.ClickAction;
import club.kid7.pluginutilities.gui.CustomGUIInventory;
import club.kid7.pluginutilities.gui.CustomGUIItem;
import club.kid7.pluginutilities.gui.CustomGUIManager;
import club.kid7.pluginutilities.gui.CustomGUIMenu;
import club.kid7.pluginutilities.kitemstack.KItemStack;
Expand Down Expand Up @@ -92,18 +92,18 @@ public CustomGUIInventory build(final Player player) {
//上一頁
if (currentRecipePage > 1) {
KItemStack prevPage = new KItemStack(Material.ARROW).amount(currentRecipePage - 1).name(MessageUtil.format("&a" + tl("gui.prev-page")));
menu.setClickableItem(22, prevPage).set(ClickType.LEFT, event -> {
menu.setItem(22, prevPage, new ClickAction(ClickType.LEFT, event -> {
playerData.setCurrentRecipePage(currentRecipePage - 1);
CustomGUIManager.openPrevious(player);
});
}));
}
//下一頁
if (currentRecipePage < totalPage) {
KItemStack nextPage = new KItemStack(Material.ARROW).amount(currentRecipePage + 1).name(MessageUtil.format("&a" + tl("gui.next-page")));
menu.setClickableItem(26, nextPage).set(ClickType.LEFT, event -> {
menu.setItem(26, nextPage, new ClickAction(ClickType.LEFT, event -> {
playerData.setCurrentRecipePage(currentRecipePage + 1);
CustomGUIManager.openPrevious(player);
});
}));
}
//取得合成表配方
HashMap<Integer, ItemStack> patternRecipe = BannerUtil.getPatternRecipe(banner, currentRecipePage);
Expand All @@ -130,11 +130,11 @@ public CustomGUIInventory build(final Player player) {
if (key != null) {
//有KEY時(儲存於玩家資料時),才顯示刪除按鈕
KItemStack btnDelete = new KItemStack(Material.BARRIER).name(MessageUtil.format("&c" + tl("gui.delete")));
menu.setClickableItem(47, btnDelete).set(ClickType.LEFT, event -> {
menu.setItem(47, btnDelete, new ClickAction(ClickType.LEFT, event -> {
//刪除
IOUtil.removeBanner(player, key);
CustomGUIManager.open(player, MainMenu.class);
});
}));
}
//取得旗幟
if (player.hasPermission("BannerMaker.getBanner")) {
Expand All @@ -145,13 +145,13 @@ public CustomGUIInventory build(final Player player) {
//具有免費取得權限
//左鍵:免費取得
btnGetBanner.lore(MessageUtil.format("&e[" + tl("gui.click.left") + "] &a" + tl("gui.get-banner-for-free")));
menu.setClickableItem(49, btnGetBanner).set(ClickType.LEFT, event -> {
menu.setItem(49, btnGetBanner, new ClickAction(ClickType.LEFT, event -> {
//取得旗幟
InventoryUtil.give(player, banner);
//顯示訊息
player.sendMessage(MessageUtil.format(true, "&a" + tl("gui.get-banner", showName)));
CustomGUIManager.openPrevious(player);
});
}));
} else {
//左鍵:合成
btnGetBanner.lore(MessageUtil.format("&e[" + tl("gui.click.left") + "] &a" + tl("gui.get-banner-by-craft")));
Expand All @@ -162,7 +162,7 @@ public CustomGUIInventory build(final Player player) {
String priceStr = BannerMaker.getInstance().econ.format(price);
btnGetBanner.lore(MessageUtil.format("&e[" + tl("gui.click.right") + "] &a" + tl("gui.buy-banner-in-price", priceStr)));
}
CustomGUIItem customGUIItemGetBanner = menu.setClickableItem(49, btnGetBanner).set(ClickType.LEFT, event -> {
menu.setItem(49, btnGetBanner, new ClickAction(ClickType.LEFT, event -> {
//嘗試合成旗幟
boolean success = BannerUtil.craft(player, banner);
if (success) {
Expand All @@ -171,39 +171,39 @@ public CustomGUIInventory build(final Player player) {
player.sendMessage(MessageUtil.format(true, "&c" + tl("gui.materials.not-enough")));
}
CustomGUIManager.openPrevious(player);
});
}));
//檢查是否啟用經濟
if (BannerMaker.getInstance().econ != null) {
customGUIItemGetBanner.set(ClickType.RIGHT, event -> {
menu.addActions(49, new ClickAction(ClickType.RIGHT, event -> {
//取得旗幟
//嘗試給予玩家旗幟
boolean success = BannerUtil.buy(player, banner);
if (success) {
player.sendMessage(MessageUtil.format(true, "&a" + tl("gui.get-banner", showName)));
}
CustomGUIManager.openPrevious(player);
});
}));
}
}
}
//複製並編輯
KItemStack btnCloneAndEdit = new KItemStack(Material.WRITABLE_BOOK).name(MessageUtil.format("&9" + tl("gui.clone-and-edit")));
menu.setClickableItem(51, btnCloneAndEdit).set(ClickType.LEFT, event -> {
menu.setItem(51, btnCloneAndEdit, new ClickAction(ClickType.LEFT, event -> {
//設定為編輯中旗幟
playerData.setCurrentEditBanner(banner);
CustomGUIManager.open(player, CreateBannerMenu.class);
});
}));

//返回
KItemStack btnBackToMenu = new KItemStack(Material.RED_WOOL).name(MessageUtil.format("&c" + tl("gui.back")));
menu.setClickableItem(45, btnBackToMenu).set(ClickType.LEFT, event -> {
menu.setItem(45, btnBackToMenu, new ClickAction(ClickType.LEFT, event -> {
if (AlphabetBanner.isAlphabetBanner(banner)) {
//若為Alphabet旗幟,回到Alphabet旗幟頁面
CustomGUIManager.open(player, CreateAlphabetMenu.class);
return;
}
CustomGUIManager.open(player, MainMenu.class);
});
}));
return menu;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import club.kid7.bannermaker.BannerMaker;
import club.kid7.bannermaker.PlayerData;
import club.kid7.bannermaker.util.MessageUtil;
import club.kid7.pluginutilities.gui.ClickAction;
import club.kid7.pluginutilities.gui.CustomGUIInventory;
import club.kid7.pluginutilities.gui.CustomGUIManager;
import club.kid7.pluginutilities.gui.CustomGUIMenu;
Expand Down Expand Up @@ -39,21 +40,21 @@ public CustomGUIInventory build(final Player player) {
char alphabet = alphabetArray[i];
final AlphabetBanner alphabetBanner = new AlphabetBanner(String.valueOf(alphabet), DyeColor.WHITE, DyeColor.BLACK, alphabetBorder);
ItemStack alphabetItem = alphabetBanner.toItemStack();
menu.setClickableItem(i, alphabetItem).set(ClickType.LEFT, event -> {
menu.setItem(i, alphabetItem, new ClickAction(ClickType.LEFT, event -> {
//設定當前編輯中的字母
playerData.setCurrentAlphabetBanner(alphabetBanner);
CustomGUIManager.open(player, CreateAlphabetMenu.class);
});
}));
}
//切換有無邊框
menu.setClickableItem(49, btnBorderedBanner).set(ClickType.LEFT, event -> {
menu.setItem(49, btnBorderedBanner, new ClickAction(ClickType.LEFT, event -> {
playerData.setAlphabetBannerBordered(!playerData.isAlphabetBannerBordered());
CustomGUIManager.openPrevious(player);
});
}));

//返回
KItemStack btnBackToMenu = new KItemStack(Material.RED_WOOL).name(MessageUtil.format("&c" + tl("gui.back")));
menu.setClickableItem(45, btnBackToMenu).set(ClickType.LEFT, event -> CustomGUIManager.open(player, MainMenu.class));
menu.setItem(45, btnBackToMenu, new ClickAction(ClickType.LEFT, event -> CustomGUIManager.open(player, MainMenu.class)));
return menu;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import club.kid7.bannermaker.PlayerData;
import club.kid7.bannermaker.util.DyeColorUtil;
import club.kid7.bannermaker.util.MessageUtil;
import club.kid7.pluginutilities.gui.ClickAction;
import club.kid7.pluginutilities.gui.CustomGUIInventory;
import club.kid7.pluginutilities.gui.CustomGUIManager;
import club.kid7.pluginutilities.gui.CustomGUIMenu;
Expand Down Expand Up @@ -37,40 +38,40 @@ public CustomGUIInventory build(final Player player) {
//選擇底色
for (int i = 0; i < 16; i++) {
final KItemStack banner = new KItemStack(DyeColorUtil.toBannerMaterial(DyeColorUtil.of(i)));
menu.setClickableItem(i + 1 + (i / 8), banner).set(ClickType.LEFT, event -> {
menu.setItem(i + 1 + (i / 8), banner, new ClickAction(ClickType.LEFT, event -> {
currentAlphabetBanner.baseColor = DyeColorUtil.of(banner.getType());
playerData.setCurrentAlphabetBanner(currentAlphabetBanner);
CustomGUIManager.openPrevious(player);
});
}));
}
//選擇主要顏色
for (int i = 0; i < 16; i++) {
final KItemStack dye = new KItemStack(DyeColorUtil.toDyeMaterial(DyeColorUtil.of(i)));
menu.setClickableItem(18 + i + 1 + (i / 8), dye).set(ClickType.LEFT, event -> {
menu.setItem(18 + i + 1 + (i / 8), dye, new ClickAction(ClickType.LEFT, event -> {
currentAlphabetBanner.dyeColor = DyeColorUtil.of(dye.getType());
playerData.setCurrentAlphabetBanner(currentAlphabetBanner);
CustomGUIManager.openPrevious(player);
});
}));
}
//切換有無邊框
menu.setClickableItem(37, btnBorderedBanner).set(ClickType.LEFT, event -> {
menu.setItem(37, btnBorderedBanner, new ClickAction(ClickType.LEFT, event -> {
currentAlphabetBanner.bordered = !currentAlphabetBanner.bordered;
playerData.setCurrentAlphabetBanner(currentAlphabetBanner);
CustomGUIManager.openPrevious(player);
});
}));
//檢視旗幟資訊按鈕
KItemStack btnBannerInfo = new KItemStack(Material.LIME_WOOL).name(MessageUtil.format("&a" + tl("gui.banner-info")));
menu.setClickableItem(49, btnBannerInfo).set(ClickType.LEFT, event -> {
menu.setItem(49, btnBannerInfo, new ClickAction(ClickType.LEFT, event -> {
//檢視旗幟資訊
playerData.setViewInfoBanner(currentAlphabetBanner.toItemStack());
//重置頁數
playerData.setCurrentRecipePage(1);
CustomGUIManager.open(player, BannerInfoMenu.class);
});
}));

//返回
KItemStack btnBackToMenu = new KItemStack(Material.RED_WOOL).name(MessageUtil.format("&c" + tl("gui.back")));
menu.setClickableItem(45, btnBackToMenu).set(ClickType.LEFT, event -> CustomGUIManager.open(player, ChooseAlphabetMenu.class));
menu.setItem(45, btnBackToMenu, new ClickAction(ClickType.LEFT, event -> CustomGUIManager.open(player, ChooseAlphabetMenu.class)));
return menu;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import club.kid7.bannermaker.util.DyeColorUtil;
import club.kid7.bannermaker.util.IOUtil;
import club.kid7.bannermaker.util.MessageUtil;
import club.kid7.pluginutilities.gui.ClickAction;
import club.kid7.pluginutilities.gui.CustomGUIInventory;
import club.kid7.pluginutilities.gui.CustomGUIManager;
import club.kid7.pluginutilities.gui.CustomGUIMenu;
Expand All @@ -32,17 +33,17 @@ public CustomGUIInventory build(final Player player) {
CustomGUIInventory menu = new CustomGUIInventory(title);
//返回
KItemStack btnBackToMenu = new KItemStack(Material.RED_WOOL).name(MessageUtil.format("&c" + tl("gui.back")));
menu.setClickableItem(45, btnBackToMenu).set(ClickType.LEFT, event -> CustomGUIManager.open(player, MainMenu.class));
menu.setItem(45, btnBackToMenu, new ClickAction(ClickType.LEFT, event -> CustomGUIManager.open(player, MainMenu.class)));
//取得當前編輯中的旗幟
final ItemStack currentBanner = playerData.getCurrentEditBanner();
if (currentBanner == null) {
//剛開始編輯,先選擇底色
for (int i = 0; i < 16; i++) {
final KItemStack banner = new KItemStack(DyeColorUtil.toBannerMaterial(DyeColorUtil.of(i)));
menu.setClickableItem(i + 1 + (i / 8), banner).set(ClickType.LEFT, event -> {
menu.setItem(i + 1 + (i / 8), banner, new ClickAction(ClickType.LEFT, event -> {
playerData.setCurrentEditBanner(banner);
CustomGUIManager.openPrevious(player);
});
}));
}
return menu;
}
Expand All @@ -58,23 +59,23 @@ public CustomGUIInventory build(final Player player) {
//顏色
for (int i = 0; i < 16; i++) {
final KItemStack dye = new KItemStack(DyeColorUtil.toDyeMaterial(DyeColorUtil.of(i)));
menu.setClickableItem(i + 1 + (i / 8), dye).set(ClickType.LEFT, event -> {
menu.setItem(i + 1 + (i / 8), dye, new ClickAction(ClickType.LEFT, event -> {
playerData.setSelectedColor(DyeColorUtil.of(dye.getType()));
CustomGUIManager.openPrevious(player);
});
}));
}
//選擇的顏色
DyeColor selectedColor = playerData.getSelectedColor();
//預覽模式
boolean isInSimplePreviewMode = playerData.isInSimplePreviewMode();
//預覽模式切換按鈕
final KItemStack previewDye = new KItemStack(DyeColorUtil.toDyeMaterial(selectedColor))
.name(MessageUtil.format("&9"+tl("gui.selected-pattern-color")))
.name(MessageUtil.format("&9" + tl("gui.selected-pattern-color")))
.lore(MessageUtil.format("&e[" + tl("gui.click.left") + "] &a" + tl("gui.toggle-preview-mode")));
menu.setClickableItem(18, previewDye).set(ClickType.LEFT, event -> {
menu.setItem(18, previewDye, new ClickAction(ClickType.LEFT, event -> {
playerData.setInSimplePreviewMode(!isInSimplePreviewMode);
CustomGUIManager.openPrevious(player);
});
}));

//預覽模式
final KItemStack baseBannerForPreview;
Expand All @@ -101,44 +102,44 @@ public CustomGUIInventory build(final Player player) {
PatternType patternType = BannerUtil.getPatternTypeList().get(patternIndex);
final KItemStack banner = ((KItemStack) baseBannerForPreview.clone())
.pattern(new Pattern(selectedColorForPreview, patternType));
menu.setClickableItem(i + 19 + (i / 8), banner).set(ClickType.LEFT, event -> {
menu.setItem(i + 19 + (i / 8), banner, new ClickAction(ClickType.LEFT, event -> {
//新增Pattern
BannerMeta currentBm = (BannerMeta) currentBanner.getItemMeta();
Objects.requireNonNull(currentBm).addPattern(new Pattern(selectedColor, patternType));
currentBanner.setItemMeta(currentBm);
playerData.setCurrentEditBanner(currentBanner);
CustomGUIManager.openPrevious(player);
});
}));
}
//更多Pattern
KItemStack btnMorePattern = new KItemStack(Material.NETHER_STAR).name(MessageUtil.format("&a" + tl("gui.more-patterns")));
menu.setClickableItem(51, btnMorePattern).set(ClickType.LEFT, event -> {
menu.setItem(51, btnMorePattern, new ClickAction(ClickType.LEFT, event -> {
playerData.setShowMorePatterns(!playerData.isShowMorePatterns());
CustomGUIManager.openPrevious(player);
});
}));
//建立旗幟
KItemStack btnCreate = new KItemStack(Material.LIME_WOOL).name(MessageUtil.format("&a" + tl("gui.create")));
menu.setClickableItem(53, btnCreate).set(ClickType.LEFT, event -> {
menu.setItem(53, btnCreate, new ClickAction(ClickType.LEFT, event -> {
IOUtil.saveBanner(player, currentBanner);
playerData.setCurrentEditBanner(null);
CustomGUIManager.open(player, MainMenu.class);
});
}));
//刪除
KItemStack btnDelete = new KItemStack(Material.BARRIER).name(MessageUtil.format("&c" + tl("gui.delete")));
menu.setClickableItem(47, btnDelete).set(ClickType.LEFT, event -> {
menu.setItem(47, btnDelete, new ClickAction(ClickType.LEFT, event -> {
playerData.setCurrentEditBanner(null);
CustomGUIManager.openPrevious(player);
});
}));
if (currentBanner.hasItemMeta() && ((BannerMeta) Objects.requireNonNull(currentBanner.getItemMeta())).numberOfPatterns() > 0) {
//移除Pattern
KItemStack btnRemovePattern = new KItemStack(Material.BARRIER).name(MessageUtil.format("&c" + tl("gui.remove-last-pattern")));
menu.setClickableItem(49, btnRemovePattern).set(ClickType.LEFT, event -> {
menu.setItem(49, btnRemovePattern, new ClickAction(ClickType.LEFT, event -> {
BannerMeta bm = (BannerMeta) currentBanner.getItemMeta();
bm.removePattern(bm.numberOfPatterns() - 1);
currentBanner.setItemMeta(bm);
playerData.setCurrentEditBanner(currentBanner);
CustomGUIManager.openPrevious(player);
});
}));
}
return menu;
}
Expand Down
Loading

0 comments on commit c0fad11

Please sign in to comment.