Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update ShopBuyEvent.java and CategoryContent.java #1060

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public class ShopBuyEvent extends Event implements Cancellable {
private final Player buyer;
private final IArena arena;
private final ICategoryContent categoryContent;
private final int slot;
private boolean cancelled = false;

/**
Expand All @@ -46,17 +47,35 @@ public ShopBuyEvent(Player buyer, ICategoryContent categoryContent) {
this.categoryContent = categoryContent;
this.buyer = buyer;
this.arena = null;
this.slot = -1;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use a Integer object so we can return null when no slot is clicked

}

/**
* Triggered when a player buys from the shop
*
* @deprecated Use {@link #ShopBuyEvent(Player, IArena, ICategoryContent, int)}
*/
@Deprecated
public ShopBuyEvent(Player buyer, IArena arena, ICategoryContent categoryContent) {
this.categoryContent = categoryContent;
this.buyer = buyer;
this.arena = arena;
this.slot = -1;
}

/**
* Triggered when a player buys from the shop
*/
public ShopBuyEvent(Player buyer, IArena arena, ICategoryContent categoryContent, int slot) {
this.categoryContent = categoryContent;
this.buyer = buyer;
this.arena = arena;
this.slot = slot;
}

/**
* Get the arena
*/
public IArena getArena() {
return arena;
}
Expand All @@ -75,6 +94,13 @@ public ICategoryContent getCategoryContent() {
return categoryContent;
}

/**
* Get the slot
*/
public int getSlot() {
return slot;
}

@Override
public HandlerList getHandlers() {
return HANDLERS;
Expand Down
22 changes: 5 additions & 17 deletions bedwars-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@
</pluginRepositories>

<repositories>
<repository>
<id>papermc</id>
<url>https://repo.papermc.io/repository/maven-public/</url>
</repository>
<repository>
<id>simonsators-repo</id>
<url>https://simonsator.de/repo/</url>
Expand Down Expand Up @@ -66,10 +70,6 @@
<id>citizens-repo</id>
<url>https://maven.citizensnpcs.co/repo</url>
</repository>
<repository>
<id>papermc</id>
<url>https://papermc.io/repo/repository/maven-public/</url>
</repository>
</repositories>

<dependencies>
Expand Down Expand Up @@ -216,7 +216,7 @@
<dependency>
<groupId>me.clip</groupId>
<artifactId>placeholderapi</artifactId>
<version>2.11.3</version>
<version>2.11.6</version>
<scope>provided</scope>
</dependency>
<dependency>
Expand Down Expand Up @@ -320,18 +320,6 @@
<version>24.2</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.andrei1058.spigot.sidebar</groupId>
<artifactId>sidebar-v1_20_R4</artifactId>
<version>24.2</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.andrei1058.spigot.sidebar</groupId>
<artifactId>sidebar-v1_20_R4</artifactId>
<version>23.12</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.andrei1058.spigot.sidebar</groupId>
<artifactId>sidebar-v1_20_R4</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,29 +139,27 @@ public void execute(Player player, ShopCache shopCache, int slot) {

IContentTier ct;

//check weight
// Check weight
if (shopCache.getCategoryWeight(father) > weight) return;

if (shopCache.getContentTier(getIdentifier()) > contentTiers.size()) {
Bukkit.getLogger().severe("Wrong tier order at: " + getIdentifier());
return;
}

//check if can re-buy
// Check if can re-buy
if (shopCache.getContentTier(getIdentifier()) == contentTiers.size()) {
if (isPermanent() && shopCache.hasCachedItem(this)) {
player.sendMessage(getMsg(player, Messages.SHOP_ALREADY_BOUGHT));
Sounds.playSound(ConfigPath.SOUNDS_INSUFF_MONEY, player);
return;
}
//current tier

// Current tier
ct = contentTiers.get(shopCache.getContentTier(getIdentifier()) - 1);
} else {
if (!shopCache.hasCachedItem(this)) {
ct = contentTiers.get(0);
} else {
ct = contentTiers.get(shopCache.getContentTier(getIdentifier()));
}
if (!shopCache.hasCachedItem(this)) ct = contentTiers.get(0);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we boomers. we do not like this code style without brackets

else ct = contentTiers.get(shopCache.getContentTier(getIdentifier()));
}

//check money
Expand All @@ -173,37 +171,31 @@ public void execute(Player player, ShopCache shopCache, int slot) {
return;
}

ShopBuyEvent event;
//call shop buy event
Bukkit.getPluginManager().callEvent(event = new ShopBuyEvent(player, Arena.getArenaByPlayer(player), this));

if (event.isCancelled()){
return;
}
// Call shop buy event
ShopBuyEvent event = new ShopBuyEvent(player, Arena.getArenaByPlayer(player), this, slot);
Bukkit.getPluginManager().callEvent(event);
if (event.isCancelled()) return;

//take money
// Take money
takeMoney(player, ct.getCurrency(), ct.getPrice());

//upgrade if possible
// Upgrade if possible
shopCache.upgradeCachedItem(this, slot);


//give items
// Give items
giveItems(player, shopCache, Arena.getArenaByPlayer(player));

//play sound
// Play sound
Sounds.playSound(ConfigPath.SOUNDS_BOUGHT, player);

//send purchase msg
// Send purchase msg
if (itemNamePath == null || Language.getPlayerLanguage(player).getYml().get(itemNamePath) == null) {
ItemStack displayItem = ct.getItemStack();
if (displayItem.getItemMeta() != null && displayItem.getItemMeta().hasDisplayName()) {
player.sendMessage(getMsg(player, Messages.SHOP_NEW_PURCHASE).replace("{item}", displayItem.getItemMeta().getDisplayName()));
}
} else {
player.sendMessage(getMsg(player, Messages.SHOP_NEW_PURCHASE).replace("{item}", ChatColor.stripColor(getMsg(player, itemNamePath))).replace("{color}", "").replace("{tier}", ""));
}

} else player.sendMessage(getMsg(player, Messages.SHOP_NEW_PURCHASE).replace("{item}", ChatColor.stripColor(getMsg(player, itemNamePath))).replace("{color}", "").replace("{tier}", ""));

shopCache.setCategoryWeight(father, weight);
}
Expand Down Expand Up @@ -236,14 +228,10 @@ public boolean hasQuick(Player player) {

public ItemStack getItemStack(Player player, ShopCache shopCache) {
IContentTier ct;
if (shopCache.getContentTier(identifier) == contentTiers.size()) {
ct = contentTiers.get(contentTiers.size() - 1);
} else {
if (shopCache.hasCachedItem(this)) {
ct = contentTiers.get(shopCache.getContentTier(identifier));
} else {
ct = contentTiers.get(shopCache.getContentTier(identifier) - 1);
}
if (shopCache.getContentTier(identifier) == contentTiers.size()) ct = contentTiers.get(contentTiers.size() - 1);
else {
if (shopCache.hasCachedItem(this)) ct = contentTiers.get(shopCache.getContentTier(identifier));
else ct = contentTiers.get(shopCache.getContentTier(identifier) - 1);
}

ItemStack i = ct.getItemStack();
Expand All @@ -264,16 +252,11 @@ public ItemStack getItemStack(Player player, ShopCache shopCache) {
String buyStatus;

if (isPermanent() && shopCache.hasCachedItem(this) && shopCache.getCachedItem(this).getTier() == getContentTiers().size()) {
if (!(nms.isArmor(i))){
buyStatus = getMsg(player, Messages.SHOP_LORE_STATUS_MAXED); //ARMOR
}else {
buyStatus = getMsg(player, Messages.SHOP_LORE_STATUS_ARMOR);
}
} else if (!canAfford) {
buyStatus = getMsg(player, Messages.SHOP_LORE_STATUS_CANT_AFFORD).replace("{currency}", translatedCurrency);
} else {
buyStatus = getMsg(player, Messages.SHOP_LORE_STATUS_CAN_BUY);
}
if (!(nms.isArmor(i))) buyStatus = getMsg(player, Messages.SHOP_LORE_STATUS_MAXED); //ARMOR
else buyStatus = getMsg(player, Messages.SHOP_LORE_STATUS_ARMOR);
} else if (!canAfford) buyStatus = getMsg(player, Messages.SHOP_LORE_STATUS_CANT_AFFORD).replace("{currency}", translatedCurrency);
else buyStatus = getMsg(player, Messages.SHOP_LORE_STATUS_CAN_BUY);



im.setDisplayName(getMsg(player, itemNamePath).replace("{color}", color).replace("{tier}", tier));
Expand All @@ -282,14 +265,9 @@ public ItemStack getItemStack(Player player, ShopCache shopCache) {
for (String s : Language.getList(player, itemLorePath)) {
if (s.contains("{quick_buy}")) {
if (hasQuick) {
if (ShopIndex.getIndexViewers().contains(player.getUniqueId())) {
s = getMsg(player, Messages.SHOP_LORE_QUICK_REMOVE);
} else {
continue;
}
} else {
s = getMsg(player, Messages.SHOP_LORE_QUICK_ADD);
}
if (ShopIndex.getIndexViewers().contains(player.getUniqueId())) s = getMsg(player, Messages.SHOP_LORE_QUICK_REMOVE);
else continue;
} else s = getMsg(player, Messages.SHOP_LORE_QUICK_ADD);
}
s = s.replace("{tier}", tier).replace("{color}", color).replace("{cost}", cColor + String.valueOf(ct.getPrice()))
.replace("{currency}", cColor + translatedCurrency).replace("{buy_status}", buyStatus);
Expand All @@ -313,9 +291,7 @@ public boolean hasQuick(PlayerQuickBuyCache c) {
* Get player's money amount
*/
public static int calculateMoney(Player player, Material currency) {
if (currency == Material.AIR) {
return (int) BedWars.getEconomy().getMoney(player);
}
if (currency == Material.AIR) return (int) BedWars.getEconomy().getMoney(player);

int amount = 0;
for (ItemStack is : player.getInventory().getContents()) {
Expand Down
Loading