Skip to content

Commit 729eb21

Browse files
committed
Implemented the dash
1 parent d9ca3f7 commit 729eb21

File tree

6 files changed

+46
-20
lines changed

6 files changed

+46
-20
lines changed

src/main/java/com/liphium/core/util/ItemStackBuilder.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ public ItemStack buildStack() {
154154
// Meta
155155
// Set displayname if name is not null
156156
if (name != null) {
157-
itemMeta.displayName(name);
157+
itemMeta.itemName(name);
158158
}
159159
// Set lore if it is not null nor empty
160160
if (lore != null && !lore.isEmpty()) {

src/main/java/com/liphium/vampires/Vampires.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import com.liphium.vampires.listener.machines.Machine;
1111
import com.liphium.vampires.listener.machines.MachineManager;
1212
import com.liphium.vampires.screens.BrewingScreen;
13+
import com.liphium.vampires.screens.ItemShopScreen;
1314
import com.liphium.vampires.screens.TeamSelectionScreen;
1415
import com.liphium.vampires.util.TaskManager;
1516
import com.onarandombox.MultiverseCore.MultiverseCore;
@@ -58,7 +59,7 @@ public void onEnable() {
5859
getCommand("set").setExecutor(new SetCommand());
5960
getCommand("timer").setExecutor(new TimerCommand());
6061

61-
Core.getInstance().getScreens().register(new TeamSelectionScreen(), new BrewingScreen());
62+
Core.getInstance().getScreens().register(new TeamSelectionScreen(), new BrewingScreen(), new ItemShopScreen());
6263
}
6364

6465
@Override

src/main/java/com/liphium/vampires/command/SetCommand.java

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
package com.liphium.vampires.command;
22

3+
import com.liphium.core.Core;
34
import com.liphium.vampires.Vampires;
45
import com.liphium.vampires.util.LocationAPI;
56
import net.kyori.adventure.text.Component;
6-
import org.bukkit.Bukkit;
77
import org.bukkit.command.Command;
88
import org.bukkit.command.CommandExecutor;
99
import org.bukkit.command.CommandSender;
@@ -19,6 +19,12 @@ public boolean onCommand(CommandSender cs, Command cmd, String label, String[] a
1919
if (args.length == 0) {
2020
player.sendMessage(Component.text("§c/set <name> §8-> §7Setzt eine Position."));
2121
} else {
22+
23+
if (args[0].equals("item")) {
24+
Core.getInstance().getScreens().open(player, 3);
25+
return true;
26+
}
27+
2228
LocationAPI.setLocation(args[0], player.getLocation());
2329
player.sendMessage(Vampires.PREFIX.append(Component.text("§cPosition §7gesetzt.")));
2430
}

src/main/java/com/liphium/vampires/game/state/IngameState.java

+3-5
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import com.liphium.vampires.game.team.Team;
88
import com.liphium.vampires.game.team.impl.HumanTeam;
99
import com.liphium.vampires.game.team.impl.VampireTeam;
10+
import com.liphium.vampires.screens.ItemShopScreen;
1011
import com.liphium.vampires.util.LocationAPI;
1112
import net.kyori.adventure.text.Component;
1213
import net.kyori.adventure.text.format.NamedTextColor;
@@ -132,11 +133,8 @@ public void onInteract(PlayerInteractEvent event) {
132133
} else if (usedItem.getType().equals(Material.FEATHER) && event.getPlayer().getCooldown(Material.FEATHER) <= 0) {
133134

134135
event.getPlayer().setVelocity(event.getPlayer().getLocation().getDirection().normalize().multiply(event.getPlayer().isOnGround() ? 1.8 : 1.1));
135-
event.getPlayer().setCooldown(Material.FEATHER, 200);
136-
} else if (usedItem.getType().equals(Material.WIND_CHARGE) && event.getPlayer().isSneaking()) {
137-
event.getPlayer().getNearbyEntities(3, 3, 3).stream()
138-
.filter(entity -> event.getPlayer().hasLineOfSight(entity))
139-
.forEach(entity -> entity.setVelocity(event.getPlayer().getLocation().getDirection().normalize().multiply(4)));
136+
event.getPlayer().setCooldown(Material.FEATHER, 50);
137+
ItemShopScreen.removeAmountFromInventory(event.getPlayer(), Material.FEATHER, 1);
140138
}
141139
}
142140
}

src/main/java/com/liphium/vampires/game/team/Team.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public ArrayList<Component> playerLore() {
4747
lore.add(Component.text("Click to join!", NamedTextColor.GRAY));
4848
} else {
4949
for (Player player : players) {
50-
lore.add(Component.text("§7- " + cc.substring(0, 2) + player.getName()));
50+
lore.add(Component.text(7- " + cc.substring(0, 2) + player.getName()));
5151
}
5252
}
5353

src/main/java/com/liphium/vampires/screens/ItemShopScreen.java

+32-11
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
public class ItemShopScreen extends CScreen {
2121

2222
public ItemShopScreen() {
23-
super(3, Component.text("Item shop", NamedTextColor.GOLD, TextDecoration.BOLD), 3, false);
23+
super(3, Component.text("Item shop", NamedTextColor.GOLD, TextDecoration.BOLD), 4, false);
2424
}
2525

2626
@Override
@@ -37,8 +37,29 @@ public void init(Player player, Inventory inventory) {
3737

3838
public void openCategory(CClickEvent event, int id, Inventory inventory) {
3939
final ShopCategory category = ShopCategory.values()[id];
40-
for (int i = 0; i < category.getItems().size(); i++) {
41-
setItemNotCached(event.getPlayer(), 19 + i, category.getItems().get(i), inventory);
40+
for (int i = 0; i < 9; i++) {
41+
if (category.getItems().size() <= i) {
42+
setItemNotCached(event.getPlayer(), 18 + i, ShopCategory.spacer(), inventory);
43+
} else {
44+
setItemNotCached(event.getPlayer(), 18 + i, category.getItems().get(i), inventory);
45+
}
46+
}
47+
}
48+
49+
public static void removeAmountFromInventory(Player player, Material material, int amount) {
50+
int count = amount;
51+
for (ItemStack item : player.getInventory()) {
52+
if (item != null && item.getType() == material) {
53+
int sub = Math.min(item.getAmount(), count);
54+
int newAmount = item.getAmount() - sub;
55+
if (newAmount == 0) {
56+
item.setAmount(newAmount);
57+
}
58+
count -= sub;
59+
if (count <= 0) {
60+
break;
61+
}
62+
}
4263
}
4364
}
4465

@@ -126,16 +147,14 @@ public List<CItem> getItems() {
126147
private static ItemStack item = new ItemStackBuilder(Material.BLACK_STAINED_GLASS_PANE).withName(Component.text("§r")).buildStack();
127148

128149
public static CItem spacer() {
129-
return new CItem(item);
150+
return new CItem(item).notClickable();
130151
}
131152

132153
public static CItem itemWithPrice(Material material, String name, NamedTextColor color, int price, int amount) {
133-
final var stackBuilder = new ItemStackBuilder(material).withName(Component.text(name, color));
134-
135-
return new CItem(stackBuilder
154+
return new CItem(new ItemStackBuilder(material).withName(Component.text(name, color))
136155
.withLore(Component.text("Price: ", NamedTextColor.GRAY).append(Component.text(price, NamedTextColor.GOLD)))
137156
.buildStack()
138-
).onClick(event -> buyFunction(event, stackBuilder.withAmount(amount).buildStack(), price));
157+
).onClick(event -> buyFunction(event, new ItemStackBuilder(material).withName(Component.text(name, color)).withAmount(amount).buildStack(), price));
139158
}
140159

141160
public static CItem itemWithPriceCustom(Material material, String name, NamedTextColor color, int price, ItemStack sold) {
@@ -146,21 +165,23 @@ public static CItem itemWithPriceCustom(Material material, String name, NamedTex
146165
}
147166

148167
public static void buyFunction(CClickEvent event, ItemStack stack, int price) {
149-
event.getPlayer().closeInventory();
150-
151168
// Get the amount of pumpkins in the inventory
152169
int count = 0;
153170
for (ItemStack item : event.getPlayer().getInventory()) {
154-
if (item.getType() == Material.CARVED_PUMPKIN) {
171+
if (item != null && item.getType() == Material.CARVED_PUMPKIN) {
155172
count += item.getAmount();
156173
}
157174
}
158175

159176
if (count < price) {
160177
event.getPlayer().sendMessage(Vampires.PREFIX.append(Component.text("You don't have enough pumpkins to purchase this item.", NamedTextColor.RED)));
178+
event.getPlayer().closeInventory();
161179
return;
162180
}
163181

182+
// Remove the pumpkins from the players inventory
183+
removeAmountFromInventory(event.getPlayer(), Material.CARVED_PUMPKIN, price);
184+
164185
event.getPlayer().getInventory().addItem(stack);
165186
}
166187
}

0 commit comments

Comments
 (0)