t
This commit is contained in:
parent
92b4ebfb34
commit
c6ca791676
@ -6,6 +6,7 @@ import org.bukkit.event.inventory.ClickType;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import rip.tilly.bedwars.menus.shop.armor.ArmorMenu;
|
||||
import rip.tilly.bedwars.menus.shop.blocks.BlocksMenu;
|
||||
import rip.tilly.bedwars.menus.shop.utilities.UtilityMenu;
|
||||
import rip.tilly.bedwars.utils.ItemBuilder;
|
||||
import rip.tilly.bedwars.utils.menu.Button;
|
||||
|
||||
@ -20,7 +21,7 @@ public class ShopTypeButton extends Button {
|
||||
@Override
|
||||
public ItemStack getButtonItem(Player player) {
|
||||
List<String> loreList = new ArrayList<>(shopType.getLore());
|
||||
loreList.add("&eClick to open the " + shopType.getName() + " section!");
|
||||
loreList.add("&eClick to open the " + shopType.getName() + " section");
|
||||
|
||||
return new ItemBuilder(shopType.getMaterial())
|
||||
.durability(shopType.getData())
|
||||
@ -39,9 +40,11 @@ public class ShopTypeButton extends Button {
|
||||
break;
|
||||
case BLOCKS:
|
||||
new BlocksMenu().openMenu(player);
|
||||
|
||||
break;
|
||||
case ARMOR:
|
||||
new ArmorMenu().openMenu(player);
|
||||
|
||||
break;
|
||||
case TOOLS:
|
||||
break;
|
||||
@ -52,6 +55,8 @@ public class ShopTypeButton extends Button {
|
||||
case POTIONS:
|
||||
break;
|
||||
case UTILITY:
|
||||
new UtilityMenu().openMenu(player);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,145 @@
|
||||
package rip.tilly.bedwars.menus.shop.utilities;
|
||||
|
||||
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 UtilityButton extends Button {
|
||||
|
||||
private String name;
|
||||
private List<String> lore;
|
||||
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("");
|
||||
|
||||
for (String string : this.lore) {
|
||||
lore.add("&7" + string);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
@ -4,18 +4,15 @@ import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import rip.tilly.bedwars.BedWars;
|
||||
import rip.tilly.bedwars.menus.shop.ShopButton;
|
||||
import rip.tilly.bedwars.menus.shop.ShopType;
|
||||
import rip.tilly.bedwars.menus.shop.ShopTypeButton;
|
||||
import rip.tilly.bedwars.menus.shop.tools.ShearsButton;
|
||||
import rip.tilly.bedwars.playerdata.PlayerData;
|
||||
import rip.tilly.bedwars.playerdata.currentgame.PlayerCurrentGameData;
|
||||
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.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class UtilityMenu extends Menu {
|
||||
@ -36,20 +33,92 @@ public class UtilityMenu extends Menu {
|
||||
public Map<Integer, Button> getButtons(Player player) {
|
||||
Map<Integer, Button> buttons = new HashMap<>();
|
||||
|
||||
PlayerData playerData = this.main.getPlayerDataManager().getPlayerData(player.getUniqueId());
|
||||
|
||||
PlayerCurrentGameData playerCurrentGameData = playerData.getCurrentGameData();
|
||||
|
||||
for (ShopType types : ShopType.values()) {
|
||||
buttons.put(types.getSlot(), new ShopTypeButton(types));
|
||||
}
|
||||
|
||||
// im making the utility menu
|
||||
// so, do not touch this
|
||||
// lol
|
||||
List<String> lore = new ArrayList<String>();
|
||||
|
||||
buttons.put(ShopType.UTILITY.getSlot() + 9, Button.placeholder(Material.STAINED_GLASS_PANE, (byte) 5, ""));
|
||||
buttons.put(19, new ShopButton("Golden Apple", Material.GOLDEN_APPLE, 0, 1, Material.GOLD_INGOT, "Gold", ChatColor.GOLD, 3, true));
|
||||
|
||||
lore.add("Well rounded healing");
|
||||
|
||||
buttons.put(19, new UtilityButton("Golden Apple", lore, Material.GOLDEN_APPLE, 0, 1, Material.GOLD_INGOT, "Gold", ChatColor.GOLD, 3, true));
|
||||
|
||||
lore.clear();
|
||||
|
||||
lore.add("Spawns a silverfish where the");
|
||||
lore.add("snowball lands to distract your");
|
||||
lore.add("enemies");
|
||||
|
||||
buttons.put(20, new UtilityButton("Bed Bug", lore, Material.SNOW_BALL, 0, 1, Material.IRON_INGOT, "Iron", ChatColor.WHITE, 30, true));
|
||||
|
||||
lore.clear();
|
||||
|
||||
lore.add("Spawns an iron golem to help");
|
||||
lore.add("defend your base");
|
||||
|
||||
buttons.put(21, new UtilityButton("Dream Defender", lore, Material.SNOW_BALL, 0, 1, Material.IRON_INGOT, "Iron", ChatColor.WHITE, 120, true));
|
||||
|
||||
lore.clear();
|
||||
|
||||
lore.add("Right click to throw a fireball");
|
||||
lore.add("at your enemies when they are currently");
|
||||
lore.add("walking on a bridge");
|
||||
|
||||
buttons.put(22, new UtilityButton("Fireball", lore, Material.FIREBALL, 0, 1, Material.IRON_INGOT, "Iron", ChatColor.WHITE, 40, true));
|
||||
|
||||
lore.clear();
|
||||
|
||||
lore.add("Instantly ignites and is ready");
|
||||
lore.add("to explode things");
|
||||
|
||||
buttons.put(23, new UtilityButton("TNT", lore, Material.TNT, 0, 1, Material.GOLD_INGOT, "Gold", ChatColor.GOLD, 4, true));
|
||||
|
||||
lore.clear();
|
||||
|
||||
lore.add("The fastest way to get");
|
||||
lore.add("to an enemy's base");
|
||||
|
||||
buttons.put(24, new UtilityButton("Ender Pearl", lore, Material.ENDER_PEARL, 0, 1, Material.EMERALD, "Emerald", ChatColor.DARK_GREEN, 4, true));
|
||||
|
||||
lore.clear();
|
||||
|
||||
lore.add("Awesome for clutching");
|
||||
lore.add("and much more");
|
||||
|
||||
buttons.put(25, new UtilityButton("Water Bucket", lore, Material.WATER_BUCKET, 0, 1, Material.GOLD_INGOT, "Gold", ChatColor.GOLD, 6, true));
|
||||
|
||||
lore.clear();
|
||||
|
||||
lore.add("Right click to throw an egg");
|
||||
lore.add("to then make a bridge in its");
|
||||
lore.add("trail");
|
||||
|
||||
buttons.put(28, new UtilityButton("Bridge Egg", lore, Material.EGG, 0, 1, Material.EMERALD, "Emerald", ChatColor.DARK_GREEN, 1, true));
|
||||
|
||||
lore.clear();
|
||||
|
||||
lore.add("Avoid setting off a trap");
|
||||
lore.add("for thirty seconds");
|
||||
|
||||
buttons.put(29, new UtilityButton("Magic Milk", lore, Material.MILK_BUCKET, 0, 1, Material.GOLD_INGOT, "Gold", ChatColor.GOLD, 4, true));
|
||||
|
||||
lore.clear();
|
||||
|
||||
lore.add("Awesome for distracting");
|
||||
lore.add("your enemies");
|
||||
|
||||
buttons.put(30, new UtilityButton("Sponge", lore, Material.SPONGE, 0, 4, Material.GOLD_INGOT, "Gold", ChatColor.GOLD, 6, true));
|
||||
|
||||
lore.clear();
|
||||
|
||||
lore.add("Right click to make a");
|
||||
lore.add("popup tower");
|
||||
|
||||
buttons.put(31, new UtilityButton("Popup Tower", lore, Material.CHEST, 0, 1, Material.IRON_INGOT, "Iron", ChatColor.WHITE, 24, true));
|
||||
|
||||
lore.clear();
|
||||
|
||||
this.fillEmptySlots(buttons, new ItemBuilder(Material.STAINED_GLASS_PANE).durability(7).name("").build());
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user