t
This commit is contained in:
parent
7ce814a005
commit
be3798e7cc
@ -0,0 +1,138 @@
|
||||
package rip.tilly.bedwars.menus.shop.weapons;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import rip.tilly.bedwars.BedWars;
|
||||
import rip.tilly.bedwars.playerdata.PlayerData;
|
||||
import rip.tilly.bedwars.utils.CC;
|
||||
import rip.tilly.bedwars.utils.ItemBuilder;
|
||||
import rip.tilly.bedwars.utils.PlayerUtil;
|
||||
import rip.tilly.bedwars.utils.menu.Button;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@AllArgsConstructor
|
||||
public class WeaponsButton extends Button {
|
||||
|
||||
private String name;
|
||||
private Material material;
|
||||
private int data;
|
||||
private int amount;
|
||||
private Material costType;
|
||||
private String costTypeName;
|
||||
private ChatColor costTypeColor;
|
||||
private int cost;
|
||||
private boolean color;
|
||||
|
||||
@Override
|
||||
public ItemStack getButtonItem(Player player) {
|
||||
List<String> lore = new ArrayList<>();
|
||||
lore.add("");
|
||||
lore.add("&9Cost: " + costTypeColor + cost + " " + costTypeName);
|
||||
lore.add("&9Amount: &e" + amount + "x");
|
||||
|
||||
int costItems = 0;
|
||||
for (ItemStack contents : player.getInventory().getContents()) {
|
||||
if (contents != null) {
|
||||
if (contents.getType() == costType) {
|
||||
costItems += contents.getAmount();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
lore.add(" ");
|
||||
lore.add(costItems >= cost ? "&aClick to purchase" : "&cYou don't have enough " + costTypeName);
|
||||
|
||||
PlayerData playerData = BedWars.getInstance().getPlayerDataManager().getPlayerData(player.getUniqueId());
|
||||
|
||||
if (color) {
|
||||
return new ItemBuilder(material)
|
||||
.name((costItems >= cost ? "&a" : "&c") + name)
|
||||
.lore(lore)
|
||||
.amount(amount)
|
||||
.durability(playerData.getPlayerTeam().getColorData())
|
||||
.hideFlags()
|
||||
.build();
|
||||
} else {
|
||||
return new ItemBuilder(material)
|
||||
.name((costItems >= cost ? "&a" : "&c") + name)
|
||||
.lore(lore)
|
||||
.amount(amount)
|
||||
.durability(data)
|
||||
.hideFlags()
|
||||
.build();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clicked(Player player, int slot, ClickType clickType, int hotbarButton) {
|
||||
if (clickType.isShiftClick()) {
|
||||
return;
|
||||
}
|
||||
|
||||
int costItems = 0;
|
||||
|
||||
for (ItemStack contents : player.getInventory().getContents()) {
|
||||
if (contents != null) {
|
||||
if (contents.getType() == costType) {
|
||||
costItems += contents.getAmount();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (costItems < cost) {
|
||||
player.sendMessage(CC.translate("&cYou don't have enough " + costTypeName));
|
||||
|
||||
playFail(player);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
PlayerData playerData = BedWars.getInstance().getPlayerDataManager().getPlayerData(player.getUniqueId());
|
||||
|
||||
int finalCost = cost;
|
||||
|
||||
for (ItemStack i : player.getInventory().getContents()) {
|
||||
if (i == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (i.getType() == costType) {
|
||||
if (i.getAmount() < finalCost) {
|
||||
finalCost -= i.getAmount();
|
||||
|
||||
PlayerUtil.minusAmount(player, i, i.getAmount());
|
||||
|
||||
player.updateInventory();
|
||||
} else {
|
||||
PlayerUtil.minusAmount(player, i, finalCost);
|
||||
|
||||
player.updateInventory();
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (color) {
|
||||
player.getInventory().addItem(new ItemBuilder(material)
|
||||
.amount(amount)
|
||||
.durability(playerData.getPlayerTeam().getColorData())
|
||||
.hideFlags()
|
||||
.build());
|
||||
} else {
|
||||
player.getInventory().addItem(new ItemBuilder(material)
|
||||
.amount(amount)
|
||||
.durability(data)
|
||||
.hideFlags()
|
||||
.build());
|
||||
}
|
||||
|
||||
playNeutral(player);
|
||||
}
|
||||
}
|
@ -0,0 +1,53 @@
|
||||
package rip.tilly.bedwars.menus.shop.weapons;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import rip.tilly.bedwars.BedWars;
|
||||
import rip.tilly.bedwars.menus.shop.ShopType;
|
||||
import rip.tilly.bedwars.menus.shop.ShopTypeButton;
|
||||
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.Menu;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class WeaponsMenu extends Menu {
|
||||
|
||||
private BedWars main = BedWars.getInstance();
|
||||
|
||||
@Override
|
||||
public boolean isUpdateAfterClick() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTitle(Player player) {
|
||||
return CC.translate("&eClick a weapon to purchase...");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<Integer, Button> getButtons(Player player) {
|
||||
Map<Integer, Button> buttons = new HashMap<>();
|
||||
|
||||
for (ShopType types : ShopType.values()) {
|
||||
buttons.put(types.getSlot(), new ShopTypeButton(types));
|
||||
}
|
||||
|
||||
buttons.put(ShopType.WEAPONS.getSlot() + 9, Button.placeholder(Material.STAINED_GLASS_PANE, (byte) 5, ""));
|
||||
buttons.put(19, new WeaponsButton("Stone Sword", Material.STONE_SWORD, 0, 1, Material.IRON_INGOT, "Iron", ChatColor.WHITE, 10, true));
|
||||
buttons.put(20, new WeaponsButton("Iron Sword", Material.IRON_SWORD, 0, 1, Material.GOLD_INGOT, "Gold", ChatColor.GOLD, 7, true));
|
||||
buttons.put(21, new WeaponsButton("Diamond Sword", Material.DIAMOND_SWORD, 0, 1, Material.EMERALD, "Emerald", ChatColor.DARK_GREEN, 3, true));
|
||||
buttons.put(22, new WeaponsButton("Knockback Stick", Material.STICK, 0, 1, Material.GOLD_INGOT, "Gold", ChatColor.GOLD, 5, true));
|
||||
|
||||
this.fillEmptySlots(buttons, new ItemBuilder(Material.STAINED_GLASS_PANE).durability(7).name("").build());
|
||||
|
||||
return buttons;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSize() {
|
||||
return 54;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user