GUI 商店
GuiShop 是一个用于 Minecraft 的 Fabric 服务端模组,可用于创建和管理图形用户界面(GUI)商店。
它自带一套经济系统,也能无缝集成其他经济插件。
GuiShop 最初是 UnsafeDodo 作品的分支,但随后经过大量修改以满足我的需求。
功能
支持多个商店

出售任意数量的物品

商店视图支持分页

支持多余额

一次性购买或出售单个或多个物品

购买的物品会出现在你的鼠标光标上

其他值得注意的功能:
- 可从背包拖拽任意物品到商店中。只要该物品可以出售,即可成功添加。
- 退回已使用的物品时会应用可配置的卖出惩罚,详见 卖出定价。
- 商店物品支持物品组件(附魔、自定义名称、自定义模型数据等)。
- 支持多种货币,每个物品均可配置使用不同的货币。
- 支持任何实现了 Common Economy API 的经济模组。
- 拥有内置的经济提供程序,可配置多种货币和账户。
- 这些货币可被其他使用 Common Economy API 的模组调用。
- 提供管理余额的命令(查看、发送、增加、减少)。
- 可通过配置前缀、后缀、小数位数和图标来模拟现实生活中的任何货币。
- 可通过命令打开商店,从而与 NPC 模组(如 Taterzens)集成。
- 本模组支持 LuckPerms 进行权限管理。
安装
将 .jar 文件放入 "mods" 文件夹中
(需要 Fabric API,以及(可选地)一个受支持的经济系统)
命令与权限
所有命令均可由管理员(权限等级 2 或更高,详见各命令说明)或具有特定权限的用户/群组使用
| 描述 |
命令 |
权限 |
| 主命令,打开商店选择菜单 |
/guishop |
guishop.main |
| 创建商店 |
/guishop create <shopName> |
guishop.create |
| 删除商店 |
/guishop delete <shopName> |
guishop.delete |
| 向商店中添加物品 |
/guishop additem <shopName> <itemId> <buyPrice> <sellPrice> <currency> <description> |
guishop.additem |
| 将手中的物品添加到商店 |
/guishop addhelditem <shopName> <itemName> <buyPrice> <sellPrice> [currency] [description] |
guishop.additem |
| 从商店中移除物品 |
/guishop removeitem <shopName> <itemName> |
guishop.removeitem |
| 为玩家打开商店 |
/guishop open <shopName> <playerName> |
guishop.open |
| 列出所有商店 |
/guishop list |
guishop.list |
| 列出商店中的所有物品 |
/guishop list <shopName> |
guishop.list |
| 强制保存配置文件 |
/guishop forcesave |
guishop.forcesave |
| 重新加载配置文件 |
/guishop reload |
guishop.reload |
| 显示所有货币的余额 |
/guishop balance |
guishop.balance |
| 显示指定货币的余额 |
/guishop balance <currency> |
guishop.balance |
| 将你的金钱发送给另一位玩家 |
/guishop balance <currency> send <playerName> <amount> |
guishop.balance.send |
| 增加玩家的余额 |
/guishop balance <currency> add <playerName> <amount> |
guishop.balance.add |
| 减少玩家的余额 |
/guishop balance <currency> remove <playerName> <amount> |
guishop.balance.remove |
| 出售你手中的物品 |
/sell hand |
guishop.sell.hand |
命令示例
创建商店:/guishop create "Test shop"
在商店中添加物品:/guishop additem "Diamond" minecraft:diamond[minecraft:enchantment_glint_override=true,minecraft:custom_name=hello] 250 100 guishop:credit "This is a Diamond\\An expensive diamond\\Shiny" (你可以使用 "\\" 来分割每一行描述)
物品组件的支持方式与 /give 命令相同。
你可以使用像 mcstacker 或
Gamergeeks 这样的物品生成器
来生成带有附魔、自定义名称等组件的物品。
在游戏中,你也会获得关于物品组件的建议。
购买和出售价格均不带任何格式。因此,如果你在配置中设置了两位小数,
并且想以 1.50 的价格出售一个物品,你应该使用 150 作为出售价格。
从商店中移除物品:/guishop removeitem "Test shop" "Diamond"
打开商店并将其展示给特定玩家:/guishop open "Test shop" "Steve"
你还可以添加仅限购买或仅能在商店中出售的物品。
购买价格为 -1 的物品只能被出售;出售价格为 -1 的物品只能被购买。
配置
GuiShop 写入的所有内容都位于 ./config/gui-shop/ 下:
config/gui-shop/
├── config.json # 经济、数据库、命令和出售定价
└── shops/
├── spawn_shop.snbt # 每个商店一个文件,文件名基于商店 ID
├── farm_shop.snbt
└── backups/ # 在商店升级到新版 Minecraft 之前自动备份的副本
商店不再包含在主配置文件中。每个商店都是其独立的 .snbt 文件,这是
Minecraft 自己的物品格式,因此物品组件可以在 Minecraft 更新后保留,而不必手动重新输入。
主配置
./config/gui-shop/config.json:
{
"economyDisabled": false,
"database": {
"type": "sqlite",
"fileLocation": "./world/guishop.sqlite"
},
"economy": {
"currencies": {
"credit": {
"name": "Credits",
"prefix": "$",
"suffix": "",
"decimalPlaces": 2,
"icon": "minecraft:diamond"
}
},
"accounts": {
"account": {
"name": "Account",
"currency": "credit",
"icon": "minecraft:diamond"
}
}
},
"command": {
"disabled": false,
"alias": ""
},
"economyProviders": {
"guishop:credit": [
"account"
]
},
"sellPricing": {
"firstUsePenalty": 0.15,
"minValueFraction": 0.05,
"damageCurveExponent": 3.0,
"repairCostPenaltyPerPoint": 0.02,
"customNamePenalty": 0.1,
"lorePenalty": 0.1
}
}
economyDisabled、database 和 economy 配置内置的经济提供程序。如果你只使用另一个经济模组,请将
economyDisabled 设置为 true;该块的其余部分将被忽略。
economyProviders 选择商店实际使用的经济系统。它将 mod_id:currency_id 映射到
account_id 列表。这可以是使用
Common Economy API 的外部经济模组,也可以是内置提供程序。
对于内置提供程序,请在配置的货币前加上 guishop: 前缀。
sellPricing 设置服务器范围内当玩家出售物品时,该物品价值的全局默认值。
每个商店都可以单独覆盖这些设置,详见下文。
出售定价
当玩家出售物品时,GuiShop 并不总是支付全额 sellPrice,如果物品损坏(降低了最大耐久度)、重命名或在玩家持有期间更改了物品描述文字,支付的金额会更少。这防止了玩家购买物品,使用一段时间后以相同价格卖回,并奖励以近乎全新状态出售物品的行为。
payouts 为 sellPrice × multiplier,其中 multiplier 从 1.0(全价)开始,并按以下顺序依次乘以各项系数:
| 设置项 |
控制内容 |
范围 |
默认值 |
firstUsePenalty |
工具/武器/护甲件受到第一次伤害(即使是单次攻击)时的即时价格下跌。 |
0 - 1 |
0.15 |
damageCurveExponent |
随着物品进一步磨损,价格持续下降的方式。1 = 线性下降。低于 1,初期下降迅速,但随着物品损坏程度增加而趋于平缓(就像新车一旦开出经销商大门就贬值)。高于 1,初期几乎不下降,但在耐久度接近耗尽时会断崖式下跌。 |
> 0 |
3.0 |
repairCostPenaltyPerPoint |
玩家持有物品期间,铁砧修复或附魔增加的每个“修复成本”点带来的额外价格下跌(铁砧的使用次数越多,价格越贵)。 |
0 - 1 |
0.02 |
customNamePenalty |
如果玩家重命名了物品(例如在铁砧中),价格下跌幅度。 |
0 - 1 |
0.10 |
lorePenalty |
如果玩家更改了物品的描述文字,价格下跌幅度。 |
0 - 1 |
0.10 |
minValueFraction |
安全底线:无论物品多么磨损、修复过或重命名过,它出售的价格永远不会低于 sellPrice 的此比例。 |
0 - 1 |
0.05 |
不可损坏的物品(方块、食物等)除非被重命名或修改了描述文本,否则总是以全价出售。sellPrice: -1(物品无法出售)和 sellPrice: 0 不受任何这些规则影响,0 售价始终支付 0。
每个商店条目都可以针对该物品覆盖这六项设置中的任何一项,详见下方的 商店文件。
背后的数学逻辑
不可出售的物品(sellPrice: -1)或 sellPrice 为 0 的物品始终支付 0。
否则:
adjustedPayout = max(round(sellPrice * multiplier), 1)
multiplier = max(damageMultiplier * repairMultiplier * nameMultiplier * loreMultiplier, minValueFraction)
damageMultiplier(对于不可损坏的物品,或未受损的物品为 1.0):
remainingDurabilityFraction = (maxDamage - damage) / maxDamage
damageMultiplier = minValueFraction
+ (1 - firstUsePenalty - minValueFraction) * remainingDurabilityFraction ^ damageCurveExponent
repairMultiplier:
delta = max(0, repairCost - originalRepairCost)
repairMultiplier = max(minValueFraction, 1 - delta * repairCostPenaltyPerPoint)
如果物品被重命名,则 nameMultiplier 为 1 - customNamePenalty,否则为 1。
如果物品的描述文本被更改,则 loreMultiplier 为 1 - lorePenalty,否则为 1。
商店文件
每个商店都是 ./config/gui-shop/shops/ 目录下的一个 .snbt 文件。文件名即为商店 ID;其中的 displayName 是玩家看到的名称,因此重命名商店不会改变其文件名。
{
DataVersion: 4671,
displayName: "Spawn Shop",
icon: "minecraft:chest",
defaultCurrency: "guishop:credit",
entries: [
{
displayName: "The boat",
description: ["This is a nice boat", "Very beautiful"],
buyPrice: 50L,
sellPrice: 25L,
stack: {id: "minecraft:acacia_chest_boat"}
},
{
displayName: "Free BBQ Sword",
buyPrice: 0L,
sellPrice: -1L,
currency: "guishop:credit",
stack: {
id: "minecraft:diamond_sword",
components: {
"minecraft:enchantments": {"minecraft:sharpness": 5},
"minecraft:custom_name": {text: "Hello", bold: true}
}
}
},
{
displayName: "Amethyst",
description: ["<red>Such a spectacular</red>", "<purple>amethyst</purple>", "<rainbow>SHINY</rainbow>"],
buyPrice: 200L,
sellPrice: 100L,
stack: {id: "minecraft:large_amethyst_bud"}
}
]
}
DataVersion 是该文件所针对的 Minecraft 版本。请勿修改,模组会自动标注此值,并在 Minecraft 更新后使用它自动升级文件中的物品,在此之前会先将副本保存到 shops/backups/。
stack 是原版物品栈,格式必须与 /give 命令使用的完全一致。
buyPrice 和 sellPrice 是长整型(注意末尾的 L)。-1 分别表示该物品不可购买或不可出售。
currency 在每个条目中是可选的,若未指定则默认使用商店的 defaultCurrency。
description 是可选的,若为空则完全省略。
icon 是可选的,默认为 minecraft:chest。
- 商店还可以包含自己的
sellPricing 区块,其键名与 config.json 中的相同,用于仅对该商店覆盖服务器全局默认值。
displayName 和 description 均支持
简化文本格式。
你可以手动编辑这些文件或在游戏中使用命令进行编辑。只需记住:
- 编辑商店文件后,使用
/guishop reload 重新加载模组,
- 使用
/guishop forcesave 保存游戏中的更改以将其写回磁盘,
- 不要同时在文件和游戏中进行操作。
- 如果已保存游戏内的更改,它们将覆盖对文件所做的任何编辑。
- 如果重新加载文件,它们将覆盖任何未保存的游戏内更改。
- 在服务器运行时进行大规模编辑时要小心,因为模组每 30 分钟会自动保存游戏内的更改。
从旧版 GuiShop 升级
旧的 ./config/guishop.json 和 ./config/guishopeconomy.json 将在首次启动时自动迁移:设置移至 config/gui-shop/config.json,每个商店变为一个 .snbt 文件,原始文件则以 .pre-migration-backup 副本的形式保留在原位置旁边。
支持的经济系统:
从 1.4.5 开始,该模组支持任何使用 Common Economy API 的经济模组(或组合)。
一个很好的例子是 Common Bridge,它将多种经济插件桥接至 Common Economy API。
GuiShop 还自带一个经济提供程序,可在配置文件中配置。
这个内置经济提供程序可以配置多种货币和账户。
(每种货币对应多个账户的功能尚未完全实现。)
GUI Shop
GuiShop is a Fabric server-side mod to create and manage GUI shops in Minecraft.
It comes with its own economy but also integrates seamlessly with other economy providers.
GuiShop started as a fork of UnsafeDodo's work, but has since been heavily modified to fit my needs.
Features
Support for multiple shops

Sell as many items you want

Shop view supports pagination

Support for multiple balances

Buy and sell one or multiple items at once

Bought items appear in your cursor

Other notable features:
- Drag and drop any items from your inventory to the shop. If it can be sold, it will be sold.
- Selling back a used item applies a configurable payout penalty, see Sell pricing.
- Shop items support item components (enchantments, custom names, custom model data, etc.).
- Supports multiple currencies, each item can be configured to use a different currency.
- Supports any economy mod that implements the Common Economy API.
- Has its own built-in economy provider that can be configured with multiple currencies and accounts.
- These currencies can be used by other mods that use the Common Economy API.
- Has commands to manage balances (view, send, add, remove).
- Can simulate any real-life currency by configuring prefix, suffix, decimal places and an icon.
- Shops can be opened through commands, allowing integration with NPC mods like Taterzens.
- The mod supports LuckPerms for permissions.
Installation
Put the .jar file in the "mods" folder
(Requires Fabric API and (optionally) a supported Economy)
Commands and permissions
All commands can be used by admins (permission level 2 or higher, see each command below) or by users/groups with the specific permission
| Description |
Command |
Permission |
| Main command, opens shop selection menu |
/guishop |
guishop.main |
| Create a shop |
/guishop create <shopName> |
guishop.create |
| Delete a shop |
/guishop delete <shopName> |
guishop.delete |
| Add an item in a shop |
/guishop additem <shopName> <itemId> <buyPrice> <sellPrice> <currency> <description> |
guishop.additem |
| Add the item in your hand to a shop |
/guishop addhelditem <shopName> <itemName> <buyPrice> <sellPrice> [currency] [description] |
guishop.additem |
| Remove an item from a shop |
/guishop removeitem <shopName> <itemName> |
guishop.removeitem |
| Open a shop for a player |
/guishop open <shopName> <playerName> |
guishop.open |
| List all shops |
/guishop list |
guishop.list |
| List all items in a shop |
/guishop list <shopName> |
guishop.list |
| Force save config |
/guishop forcesave |
guishop.forcesave |
| Reload config file |
/guishop reload |
guishop.reload |
| Show balance for all currencies |
/guishop balance |
guishop.balance |
| Show balance for a currency |
/guishop balance <currency> |
guishop.balance |
| Send your money to another player |
/guishop balance <currency> send <playerName> <amount> |
guishop.balance.send |
| Increase a player's balance |
/guishop balance <currency> add <playerName> <amount> |
guishop.balance.add |
| Decrease a player's balance |
/guishop balance <currency> remove <playerName> <amount> |
guishop.balance.remove |
| Sell the item in your hand |
/sell hand |
guishop.sell.hand |
Commands examples
Create a shop: /guishop create "Test shop""
Add item in a shop: /guishop additem "Diamond" minecraft:diamond[minecraft:enchantment_glint_override=true,minecraft:custom_name=hello] 250 100 guishop:credit "This is a Diamond\\An expensive diamond\\Shiny" (you can split each description line by using "\\")
Item components are supported in the same way as in the /give command.
You can use an item generator like mcstacker or the one from
Gamergeeks
to generate items with components like enchantments, custom names, etc.
In-game, you'll also get suggestions for item components.
The buy and sell prices are without any formatting so say you configured 2 decimal places in your config
and you want to sell an item for 1.50, you would use 150 as the sell price.
Remove item from shop: /guishop removeitem "Test shop" "Diamond"
Open a shop and show it to a specific player: /guishop open "Test shop" "Steve"
You can also add items only to be bought or sold in a shop.
Items with a buy price of -1 can only be sold and items with a sell price of -1 can only be bought.
Configuration
Everything GuiShop writes lives under ./config/gui-shop/:
config/gui-shop/
├── config.json # economy, database, commands and sell pricing
└── shops/
├── spawn_shop.snbt # one file per shop, named after the shop id
├── farm_shop.snbt
└── backups/ # copies taken automatically before a shop is upgraded to a newer Minecraft version
Shops are no longer part of the main config file. Each shop is its own .snbt file, which is
Minecraft's own item format, so item components survive a Minecraft update instead of having to be
re-entered by hand.
Main configuration
./config/gui-shop/config.json:
{
"economyDisabled": false,
"database": {
"type": "sqlite",
"fileLocation": "./world/guishop.sqlite"
},
"economy": {
"currencies": {
"credit": {
"name": "Credits",
"prefix": "$",
"suffix": "",
"decimalPlaces": 2,
"icon": "minecraft:diamond"
}
},
"accounts": {
"account": {
"name": "Account",
"currency": "credit",
"icon": "minecraft:diamond"
}
}
},
"command": {
"disabled": false,
"alias": ""
},
"economyProviders": {
"guishop:credit": [
"account"
]
},
"sellPricing": {
"firstUsePenalty": 0.15,
"minValueFraction": 0.05,
"damageCurveExponent": 3.0,
"repairCostPenaltyPerPoint": 0.02,
"customNamePenalty": 0.1,
"lorePenalty": 0.1
}
}
economyDisabled, database and economy configure the built-in economy provider. Set
economyDisabled to true if you only use another economy mod; the rest of that block is then
ignored.
economyProviders selects which economies the shops actually use. It maps mod_id:currency_id to a
list of account_ids. That can be an external economy mod that uses the
Common Economy API, or the built-in provider, for
the built-in one, prefix your configured currency with guishop:.
sellPricing sets the server-wide defaults for what a used item is worth when a player sells it
back. Any shop can override these individually, see below.
Sell pricing
When a player sells an item back, GuiShop doesn't always pay the full sellPrice, it pays less if
the item was damaged, repaired (which lowers max durability), renamed, or had its lore changed while
the player owned it. This stops players from buying an item, using it for a while, and selling it
back for the same price, and rewards selling items in near-mint condition.
The payout is sellPrice × multiplier, where multiplier starts at 1.0 (full price) and gets
multiplied down by each of these, in order:
| Setting |
What it controls |
Range |
Default |
firstUsePenalty |
Instant price drop the moment a tool/weapon/armor piece takes its very first point of damage, even a single hit. |
0 - 1 |
0.15 |
damageCurveExponent |
How the price keeps falling as the item wears down further. 1 = drops linearely. Below 1, it drops fast at first then levels off once the item gets more damaged (like a new car losing value the moment you drive away from the dealership). Above 1, it barely drops at first but falls off a cliff near the end of its durability. |
> 0 |
3.0 |
repairCostPenaltyPerPoint |
Extra price drop for every "repair cost" point an anvil repair or enchant has added while the player owned the item (anvils get pricier to use the more you use them). |
0 - 1 |
0.02 |
customNamePenalty |
Price drop if the player renamed the item (e.g. in an anvil). |
0 - 1 |
0.10 |
lorePenalty |
Price drop if the player changed the item's lore text. |
0 - 1 |
0.10 |
minValueFraction |
Safety floor: no matter how worn, repaired, or renamed the item is, it will never sell for less than this fraction of sellPrice. |
0 - 1 |
0.05 |
Items that aren't damageable (blocks, food, etc.) always sell for full price unless they've been
renamed or had their lore changed. sellPrice: -1 (item can't be sold) and sellPrice: 0 are
unaffected by any of this, a 0 sell price always pays out 0.
Every shop entry can override any of these six settings just for that item, see
Shop files below.
The math behind it
An item that isn't sellable (sellPrice: -1) or whose sellPrice is 0 always pays out 0.
Otherwise:
adjustedPayout = max(round(sellPrice * multiplier), 1)
multiplier = max(damageMultiplier * repairMultiplier * nameMultiplier * loreMultiplier, minValueFraction)
damageMultiplier (1.0 for non-damageable items, or if the item hasn't taken damage):
remainingDurabilityFraction = (maxDamage - damage) / maxDamage
damageMultiplier = minValueFraction
+ (1 - firstUsePenalty - minValueFraction) * remainingDurabilityFraction ^ damageCurveExponent
repairMultiplier:
delta = max(0, repairCost - originalRepairCost)
repairMultiplier = max(minValueFraction, 1 - delta * repairCostPenaltyPerPoint)
nameMultiplier is 1 - customNamePenalty if the item was renamed, else 1.
loreMultiplier is 1 - lorePenalty if the item's lore was changed, else 1.
Shop files
Each shop is one .snbt file in ./config/gui-shop/shops/. The file name is the shop id; the
displayName inside is what players see, so renaming a shop does not rename its file.
{
DataVersion: 4671,
displayName: "Spawn Shop",
icon: "minecraft:chest",
defaultCurrency: "guishop:credit",
entries: [
{
displayName: "The boat",
description: ["This is a nice boat", "Very beautiful"],
buyPrice: 50L,
sellPrice: 25L,
stack: {id: "minecraft:acacia_chest_boat"}
},
{
displayName: "Free BBQ Sword",
buyPrice: 0L,
sellPrice: -1L,
currency: "guishop:credit",
stack: {
id: "minecraft:diamond_sword",
components: {
"minecraft:enchantments": {"minecraft:sharpness": 5},
"minecraft:custom_name": {text: "Hello", bold: true}
}
}
},
{
displayName: "Amethyst",
description: ["<red>Such a spectacular</red>", "<purple>amethyst</purple>", "<rainbow>SHINY</rainbow>"],
buyPrice: 200L,
sellPrice: 100L,
stack: {id: "minecraft:large_amethyst_bud"}
}
]
}
DataVersion is the Minecraft version the file was written for. Leave it alone, the mod stamps
it, and uses it to upgrade the file's items automatically after a Minecraft update, taking a copy
into shops/backups/ first.
stack is a vanilla item stack, in exactly the shape the /give command uses.
buyPrice and sellPrice are longs (note the L). -1 means the item cannot be bought, or
cannot be sold, respectively.
currency is optional per entry and falls back to the shop's defaultCurrency.
description is optional and is omitted entirely when empty.
icon is optional and defaults to minecraft:chest.
- A shop may also carry its own
sellPricing block, with the same keys as the one in config.json,
to override the server-wide defaults for that shop only.
Both displayName and description support the
Simplified Text Format.
You can edit these files by hand or use the in-game commands. Just remember to:
- reload the mod using
/guishop reload after editing a shop file,
- save in-game changes using
/guishop forcesave to write them back to disk,
- not work in the files and in-game at the same time.
- If in-game changes are saved, they overwrite any edits made to the files.
- If the files are reloaded, they overwrite any unsaved in-game changes.
- Be careful making large-scale edits while the server is running, since the mod saves in-game changes automatically every 30 minutes.
Upgrading from an older GuiShop
The old ./config/guishop.json and ./config/guishopeconomy.json are migrated automatically on
first start: settings move into config/gui-shop/config.json, each shop becomes a .snbt file, and
the originals are kept as .pre-migration-backup copies next to where they were.
Supported Economies:
From 1.4.5 and onwards, the mod supports any (combination of) economy mod that uses the Common Economy API.
A great example is Common Bridge, which bridges multiple economy plugins to use the Common Economy API.
GuiShop also comes with its own economy provider which can be configured in the config file.
This build-in economy provider can be configured with multiple currencies and accounts.
(The multi-account per currency functionality has not been properly implemented yet.)
评论 0
登录后参与评分
还没有评论,来抢沙发吧