Skip to content

Commit a01e974

Browse files
committed
化粧品実装
1 parent 2991229 commit a01e974

File tree

6 files changed

+106
-5
lines changed

6 files changed

+106
-5
lines changed

src/main/java/com/github/elic0de/thejpspit/cosmetics/AbstractCosmetic.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
public interface AbstractCosmetic {
44

5+
// todo: slot charの追加, material
56
String getId();
67

78
String getName();

src/main/java/com/github/elic0de/thejpspit/cosmetics/Cosmetic.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public Cosmetic() {
2727

2828
public final boolean canExecute(PitPlayer player) {
2929
final AtomicBoolean canExecute = new AtomicBoolean(false);
30-
player.getPreferences().ifPresent(preferences -> canExecute.set(preferences.getCosmeticsCollection().isSelectedCosmetic(cosmeticId)));
30+
player.getPreferences().ifPresent(preferences -> canExecute.set(preferences.getCosmeticsCollection().isSelectedCosmetic(this)));
3131

3232
return canExecute.get();
3333
}

src/main/java/com/github/elic0de/thejpspit/cosmetics/impl/kill/FireCosmetic.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import xyz.xenondevs.particle.ParticleBuilder;
88
import xyz.xenondevs.particle.ParticleEffect;
99

10-
@CosmeticData(id = "Fire", name = "ファイやー", coin = 50)
10+
@CosmeticData(id = "Fire", name = "ファイやー", description = "足元が焦げて..", coin = 50)
1111
public class FireCosmetic extends Cosmetic implements KillCosmetic {
1212

1313
@Override
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
package com.github.elic0de.thejpspit.gui;
2+
3+
import com.github.elic0de.thejpspit.TheJpsPit;
4+
import com.github.elic0de.thejpspit.cosmetics.Cosmetic;
5+
import com.github.elic0de.thejpspit.player.PitPlayer;
6+
import com.github.elic0de.thejpspit.player.PitPlayerManager;
7+
import com.github.elic0de.thejpspit.player.PurchasedCosmeticsCollection;
8+
import de.themoep.inventorygui.DynamicGuiElement;
9+
import de.themoep.inventorygui.InventoryGui;
10+
import de.themoep.inventorygui.StaticGuiElement;
11+
import java.util.concurrent.atomic.AtomicBoolean;
12+
import org.bukkit.Material;
13+
import org.bukkit.entity.Player;
14+
import org.bukkit.inventory.ItemStack;
15+
import org.checkerframework.checker.units.qual.A;
16+
17+
public class CosmeticsMenu {
18+
19+
private static final String[] MENU_LAYOUT = {
20+
" ",
21+
" SCBoFLc ",
22+
" tvueG ",
23+
" "
24+
};
25+
26+
private final InventoryGui menu;
27+
28+
private CosmeticsMenu(TheJpsPit plugin, String title) {
29+
this.menu = new InventoryGui(plugin, title, MENU_LAYOUT);
30+
plugin.getCosmeticManager().getKillCosmetics().values().stream().map(killCosmetic -> getItemElement((Cosmetic) killCosmetic)).forEach(this.menu::addElement);
31+
}
32+
33+
public static CosmeticsMenu create(TheJpsPit plugin, String title) {
34+
return new CosmeticsMenu(plugin, title);
35+
}
36+
37+
private DynamicGuiElement getItemElement(Cosmetic cosmetic) {
38+
return new DynamicGuiElement(cosmetic.getId().charAt(0), (viewer) -> {
39+
final PitPlayer pitPlayer = PitPlayerManager.getPitPlayer((Player) viewer);
40+
final AtomicBoolean hasCosmetic = new AtomicBoolean(false);
41+
final AtomicBoolean isSelected = new AtomicBoolean(false);
42+
pitPlayer.getPreferences().ifPresent(preferences -> {
43+
final PurchasedCosmeticsCollection cosmeticsCollection = preferences.getCosmeticsCollection();
44+
hasCosmetic.set(cosmeticsCollection.has(cosmetic));
45+
isSelected.set(cosmeticsCollection.isSelectedCosmetic(cosmetic));
46+
});
47+
return new StaticGuiElement(cosmetic.getName().charAt(0), new ItemStack(Material.COMPASS), click -> {
48+
pitPlayer.getPreferences().ifPresent(preferences -> {
49+
final PurchasedCosmeticsCollection cosmeticsCollection = preferences.getCosmeticsCollection();
50+
if (hasCosmetic.get()) {
51+
if (isSelected.get()) {
52+
cosmeticsCollection.unSelectCosmetic();
53+
return;
54+
}
55+
cosmeticsCollection.selectCosmetic(cosmetic);
56+
return;
57+
}
58+
if (cosmeticsCollection.canBuy(pitPlayer, cosmetic)) {
59+
cosmeticsCollection.buy(pitPlayer, cosmetic);
60+
return;
61+
}
62+
pitPlayer.sendMessage("たりない");
63+
});
64+
click.getGui().draw();
65+
return true;
66+
}, "&a" + cosmetic.getName(),
67+
"&7" + cosmetic.getDescription(),
68+
" ",
69+
"&e" + cosmetic.getCoin() + "JP",
70+
isSelected.get() ? "&c解除する": hasCosmetic.get() ? "&a選択する" : "&c購入する"
71+
);
72+
});
73+
}
74+
75+
public void show(PitPlayer player) {
76+
menu.show(player.getPlayer());
77+
}
78+
}

src/main/java/com/github/elic0de/thejpspit/gui/ShopMenu.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,32 +9,46 @@
99
import de.themoep.inventorygui.DynamicGuiElement;
1010
import de.themoep.inventorygui.InventoryGui;
1111
import de.themoep.inventorygui.StaticGuiElement;
12+
import org.bukkit.Material;
1213
import org.bukkit.entity.Player;
1314
import org.bukkit.event.inventory.ClickType;
1415
import org.bukkit.inventory.Inventory;
1516

1617
import java.math.BigDecimal;
18+
import org.bukkit.inventory.ItemStack;
1719

1820
public class ShopMenu {
1921

2022
private static final String[] MENU_LAYOUT = {
2123
" ",
2224
" SCBofLc ",
2325
" tvueG ",
24-
" "
26+
" s "
2527
};
2628

2729
private final InventoryGui menu;
2830

2931
private ShopMenu(TheJpsPit plugin, String title) {
3032
this.menu = new InventoryGui(plugin, title, MENU_LAYOUT);
33+
this.menu.addElement(cosmeticShopButton());
3134
ItemManager.getAllEntry().stream().map(this::getItemElement).forEach(this.menu::addElement);
3235
}
3336

3437
public static ShopMenu create(TheJpsPit plugin, String title) {
3538
return new ShopMenu(plugin, title);
3639
}
3740

41+
private StaticGuiElement cosmeticShopButton() {
42+
return new StaticGuiElement('s', new ItemStack(Material.EMERALD),
43+
click -> {
44+
final PitPlayer pitPlayer = PitPlayerManager.getPitPlayer((Player) click.getWhoClicked());
45+
CosmeticsMenu.create(TheJpsPit.getInstance(), "Cosmetics").show(pitPlayer);
46+
return true;
47+
},
48+
"&a化粧品"
49+
);
50+
}
51+
3852
private DynamicGuiElement getItemElement(PitItemEntry pitItemEntry) {
3953
return new DynamicGuiElement(pitItemEntry.getSlotChar(), (viewer) -> {
4054
final PitPlayer pitPlayer = PitPlayerManager.getPitPlayer((Player) viewer);

src/main/java/com/github/elic0de/thejpspit/player/PurchasedCosmeticsCollection.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,16 @@ public class PurchasedCosmeticsCollection {
2424
@SerializedName("selected_id")
2525
private String selectedCosmeticId = "";
2626

27-
public boolean isSelectedCosmetic(String cosmeticId) {
28-
return this.selectedCosmeticId.equals(cosmeticId);
27+
public void selectCosmetic(Cosmetic cosmetic) {
28+
this.selectedCosmeticId = cosmetic.getId();
29+
}
30+
31+
public void unSelectCosmetic() {
32+
this.selectedCosmeticId = "";
33+
}
34+
35+
public boolean isSelectedCosmetic(Cosmetic cosmetic) {
36+
return this.selectedCosmeticId.equals(cosmetic.getId());
2937
}
3038

3139
public boolean canBuy(PitPlayer pitPlayer, Cosmetic cosmetic){

0 commit comments

Comments
 (0)