-
Notifications
You must be signed in to change notification settings - Fork 225
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
KKiiya
wants to merge
7
commits into
andrei1058:master
Choose a base branch
from
KKiiya:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
ec52295
Fixed tag apply
KKiiya d6d329a
Updated set tag for VersionSupport#setShopUpgradeIdentifier
KKiiya 69037c8
Merge remote-tracking branch 'upstream/master'
KKiiya 690c01e
Update ShopBuyEvent.java and CategoryContent.java
KKiiya a935262
Update ShopBuyEvent.java
KKiiya 5cbd7cf
Fixed pom.xml
KKiiya 7f7acf5
Update pom.xml
KKiiya File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
@@ -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); | ||
} | ||
|
@@ -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(); | ||
|
@@ -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)); | ||
|
@@ -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); | ||
|
@@ -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()) { | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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