Skip to content

Commit

Permalink
Add lore toggle config option, add max name length placeholder, disab…
Browse files Browse the repository at this point in the history
…le adding items to expired storage
  • Loading branch information
Bestem0r committed Oct 17, 2022
1 parent faf6b54 commit 4e24c66
Show file tree
Hide file tree
Showing 15 changed files with 57 additions and 15 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

<groupId>me.bestemor.villagermarket</groupId>
<artifactId>VillagerMarket</artifactId>
<version>1.11.1-SNAPSHOT</version>
<version>1.11.2-SNAPSHOT</version>

<repositories>
<repository>
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/net/bestemor/villagermarket/VMPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ protected void onPluginEnable() {
this.playerListener = new PlayerListener(this);
registerEvents();

//Bukkit.getLogger().warning("[VillagerMarket] §cYou are running a §aBETA 1.11.1-#1 of VillagerMarket! Please expect and report all bugs in my discord server");
//Bukkit.getLogger().warning("[VillagerMarket] §cYou are running a §aBETA 1.11.2-#1 of VillagerMarket! Please expect and report all bugs in my discord server");

Bukkit.getScheduler().runTaskLater(this, () -> {
if (Bukkit.getPluginManager().getPlugin("VillagerBank") != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public void run(CommandSender sender, String[] args) {

if (plugin.getShopManager().getExpiredStorages().containsKey(player.getUniqueId())) {
final StorageHolder holder = new StorageHolder(plugin, 0);
holder.setAddingAllowed(false);
holder.loadItems(plugin.getShopManager().getExpiredStorages().get(player.getUniqueId()));

holder.setCloseEvent(() -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,8 @@ public void onCreate(MenuContent content) {
}
}
if (result.length() > ConfigManager.getInt("villager.max_name_length")) {
player.sendMessage(ConfigManager.getMessage("messages.max_name_length"));
player.sendMessage(ConfigManager.getMessage("messages.max_name_length")
.replace("%limit%", String.valueOf(ConfigManager.getInt("villager.max_name_length"))));
return;
}

Expand Down
11 changes: 6 additions & 5 deletions src/main/java/net/bestemor/villagermarket/menu/Shopfront.java
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,9 @@ public void update() {
customerInventories.get(uuid).setContents(getCustomerInventory(p).getContents());
}
}
updateDetailedInventory();
if (!ConfigManager.getBoolean("disable_lore_toggle")) {
updateDetailedInventory();
}
updateEditorInventory();
}

Expand All @@ -130,7 +132,9 @@ private Inventory getCustomerInventory(Player player) {
customerInventory.setItem(slot, item.getCustomerItem(player));
}
buildBottom(customerInventory);
customerInventory.setItem(size - 1, details);
if (!ConfigManager.getBoolean("disable_lore_toggle")) {
customerInventory.setItem(size - 1, details);
}

return customerInventory;
}
Expand All @@ -144,7 +148,6 @@ private void updateDetailedInventory() {
detailedInventory.setItem(slot, item.getRawItem());
}
buildBottom(detailedInventory);
detailedInventory.setItem(size - 1, details);
}
private void updateEditorInventory() {
editorInventory.clear();
Expand Down Expand Up @@ -220,8 +223,6 @@ public void onClick(InventoryClickEvent event) {
if (this.player != event.getWhoClicked()) { return; }
if (event.getRawSlot() < 0) { return; }

ItemStack current = event.getCurrentItem();

if (type == Type.DETAILED || type == Type.CUSTOMER) {
event.setCancelled(true);
}
Expand Down
15 changes: 15 additions & 0 deletions src/main/java/net/bestemor/villagermarket/menu/StorageHolder.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public class StorageHolder {

private final int size;
private final boolean isInfinite;
private boolean addAllowed = true;

public StorageHolder(VMPlugin plugin, PlayerShop shop) {
this.plugin = plugin;
Expand Down Expand Up @@ -129,4 +130,18 @@ public void addItem(ItemStack i) {
}
}
}

public void setAddingAllowed(boolean b) {
this.addAllowed = b;
}

public boolean isAddAllowed() {
return addAllowed;
}

public void closeAll() {
for (StorageMenu storageMenu : storageMenus) {
storageMenu.close();
}
}
}
12 changes: 12 additions & 0 deletions src/main/java/net/bestemor/villagermarket/menu/StorageMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
import net.bestemor.core.menu.MenuContent;
import net.bestemor.core.menu.MenuListener;
import net.bestemor.villagermarket.utils.VMUtils;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.InventoryAction;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryCloseEvent;
import org.bukkit.inventory.ItemStack;
Expand Down Expand Up @@ -90,6 +92,16 @@ protected void onClose(InventoryCloseEvent event) {
@Override
protected void onClick(InventoryClickEvent event) {
int size = event.getView().getTopInventory().getSize();
if (!holder.isAddAllowed()) {
if (event.getRawSlot() >= size && event.getAction() == InventoryAction.MOVE_TO_OTHER_INVENTORY) {
event.setCancelled(true);
return;
}
if (event.getRawSlot() < size && event.getCursor() != null && event.getCursor().getType() != Material.AIR) {
event.setCancelled(true);
return;
}
}
if (isInfinite ? (event.getRawSlot() < size - 9 || event.getRawSlot() > size - 1) : (event.getRawSlot() != size - 1)) {
event.setCancelled(false);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,8 @@ public int getAvailable(ShopItem shopItem) {
public void abandon() {
Bukkit.getPluginManager().callEvent(new AbandonShopEvent(this));

closeAllMenus();

OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(ownerUUID);
Economy economy = plugin.getEconomy();

Expand Down Expand Up @@ -349,6 +351,12 @@ public boolean hasExpired() {
return seconds != 0 && expireDate != null && expireDate.isBefore(Instant.now());
}

@Override
public void closeAllMenus() {
storageHolder.closeAll();
super.closeAllMenus();
}

@Override
public void save() {
config.set("storage", storageHolder.getItems());
Expand Down
4 changes: 3 additions & 1 deletion src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,16 @@ require_collect: false
#Enable per-adminshop permission requirements. The required
#permission will be based on the UUID of the shop:
#e.g. villagermarket.adminshop.01b0be53-aa98-471c-86c7-a12fbf4e7482
#You can retrieve a shop"s UUID with /vm getid
#You can retrieve a shop's UUID with /vm getid
per_adminshop_permissions: false
#Will require villagermarket.buy_shop to buy shops
buy_shop_permission: false
#Will drop spawn egg when a shops created with spawn egg is removed
drop_spawn_egg: true
#Will disable announcing new updates when joining
disable_update_announce: false
#Will disable the 'toggle lore' button for shopfronts
disable_lore_toggle: false
#Language to use
language: en_US

Expand Down
4 changes: 3 additions & 1 deletion src/main/resources/config_8.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,16 @@ require_collect: false
#Enable per-adminshop permission requirements. The required
#permission will be based on the UUID of the shop:
#e.g. villagermarket.adminshop.01b0be53-aa98-471c-86c7-a12fbf4e7482
#You can retrieve a shop"s UUID with /vm getid
#You can retrieve a shop's UUID with /vm getid
per_adminshop_permissions: false
#Will require villagermarket.buy_shop to buy shops
buy_shop_permission: false
#Will drop spawn egg when a shops created with spawn egg is removed
drop_spawn_egg: true
#Will disable announcing new updates when joining
disable_update_announce: false
#Will disable the 'toggle lore' button for shopfronts
disable_lore_toggle: false
#Language to use
language: en_US

Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/de_DE.yml
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ messages:
name_blacklisted: '&cDu darfst diesen Shopnamen nicht verwenden!'
max_item_price: '&cArtikelpreis zu hoch! Bitte versuche es mit einem niedrigeren Preis erneut.'
shopfront_cooldown: '&cBitte warte mit dem erneuten Kauf/Verkauf!'
max_name_length: '&cDer Name ist zu lang! Die maximale Namenslänge beträgt 12 Zeichen.'
max_name_length: '&cDer Name ist zu lang! Die maximale Namenslänge beträgt %limit% Zeichen.'
clone_shop: '&7Klicke mit Rechtsklick auf den &bVillagerShop &7den du klonen möchtest.'
shop_cloned: '&aVillagerShop erfolgreich geklont. Verschiebe den Shop mit &e/vm move&a.'
set_size: '&7Klicke mit Rechtsklick auf den &bVillagerShop &7für den du die Größe festlegen möchtest.'
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/de_DE_legacy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ messages:
name_blacklisted: '&cDu darfst diesen Shopnamen nicht verwenden!'
max_item_price: '&cArtikelpreis zu hoch! Bitte versuche es mit einem niedrigeren Preis erneut.'
shopfront_cooldown: '&cBitte warte mit dem erneuten Kauf/Verkauf!'
max_name_length: '&cDer Name ist zu lang! Die maximale Namenslänge beträgt 12 Zeichen.'
max_name_length: '&cDer Name ist zu lang! Die maximale Namenslänge beträgt %limit% Zeichen.'
clone_shop: '&7Klicke mit Rechtsklick auf den &bVillagerShop &7den du klonen möchtest.'
shop_cloned: '&aVillagerShop erfolgreich geklont. Verschiebe den Shop mit &e/vm move&a.'
set_size: '&7Klicke mit Rechtsklick auf den &bVillagerShop &7für den du die Größe festlegen möchtest.'
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/en_US.yml
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ messages:
name_blacklisted: "&cYou are not allowed to use this shop name!"
max_item_price: "&cItem price too high! Please retry with a lower price."
shopfront_cooldown: "&cPlease wait before buying/selling again!"
max_name_length: "&cThis name is too long! Maximum name length is 12 characters."
max_name_length: "&cThis name is too long! Maximum name length is %limit% characters."
clone_shop: "&7Right click the &bVillager Shop &7you want to clone."
shop_cloned: "&aVillager Shop successfully cloned. Move it using &e/vm move&a."
set_size: "&7Right click the &bVillager Shop &7you want to set size for."
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/en_US_legacy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ messages:
name_blacklisted: "&cYou are not allowed to use this shop name!"
max_item_price: "&cItem price too high! Please retry with a lower price."
shopfront_cooldown: "&cPlease wait before buying/selling again!"
max_name_length: "&cThis name is too long! Maximum name length is 12 characters."
max_name_length: "&cThis name is too long! Maximum name length is %limit% characters."
clone_shop: "&7Right click the &bVillager Shop &7you want to clone."
shop_cloned: "&aVillager Shop successfully cloned. Move it using &e/vm move&a."
set_size: "&7Right click the &bVillager Shop &7you want to set size for."
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: VillagerMarket
main: net.bestemor.villagermarket.VMPlugin
version: 1.11.1
version: 1.11.2
author: Bestem0r
description: A plugin made by Bestem0r to create Villager Shops
api-version: 1.13
Expand Down

0 comments on commit 4e24c66

Please sign in to comment.