Skip to content

add folia support and zh-CN lang #1

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

Open
wants to merge 9 commits into
base: main
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
29 changes: 29 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@
<version>1.7</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.github.technicallycoded</groupId>
<artifactId>FoliaLib</artifactId>
<version>0.4.3</version>
<scope>compile</scope>
</dependency>
</dependencies>

<build>
Expand Down Expand Up @@ -85,5 +91,28 @@
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.6.0</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
<configuration>
<relocations>
<relocation>
<pattern>com.tcoded.folialib</pattern>
<shadedPattern>shopplusplus.folialib</shadedPattern>
</relocation>
</relocations>
</configuration>
</plugin>
</plugins>
</build>
</project>
7 changes: 7 additions & 0 deletions src/main/java/shopplusplus/Plugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.io.File;

import com.tcoded.folialib.FoliaLib;
import org.bukkit.Bukkit;
import org.bukkit.plugin.java.JavaPlugin;

Expand All @@ -21,9 +22,11 @@ public class Plugin extends JavaPlugin {
public static LanguageLoader language;
public static YmlConfigValidator languageValidator;
public static Vault vault;
private static FoliaLib foliaLib;

public void onEnable() {
long startTime = System.currentTimeMillis();
foliaLib = new FoliaLib(this);

Console.pluginBanner();

Expand Down Expand Up @@ -147,4 +150,8 @@ public boolean isVaultInstalled() {
return Bukkit.getServer().getPluginManager().getPlugin("Vault") != null
&& Bukkit.getServer().getPluginManager().getPlugin("Vault").isEnabled();
}

public static FoliaLib getFoliaLib() {
return foliaLib;
}
}
10 changes: 3 additions & 7 deletions src/main/java/shopplusplus/core/gui/Menu.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import org.bukkit.event.inventory.InventoryCloseEvent;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.scheduler.BukkitRunnable;

import shopplusplus.Plugin;

Expand Down Expand Up @@ -95,12 +94,9 @@ public void onInventoryClick(InventoryClickEvent event) {
int slot = event.getRawSlot();

if (callbacks.containsKey(slot)) {
new BukkitRunnable() {
@Override
public void run() {
callbacks.get(slot).accept(player, event);
}
}.runTask(plugin);
Plugin.getFoliaLib().getScheduler().runAtLocation(event.getWhoClicked().getLocation(),wrappedTask -> {
callbacks.get(slot).accept(player, event);
});
}
}
}
Expand Down
13 changes: 4 additions & 9 deletions src/main/java/shopplusplus/core/gui/MenuPagination.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import org.bukkit.event.inventory.InventoryCloseEvent;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.scheduler.BukkitRunnable;

import shopplusplus.Plugin;
import shopplusplus.utils.formatters.Formatters;
Expand Down Expand Up @@ -217,14 +216,10 @@ public void onInventoryClick(InventoryClickEvent event) {
}

if (slot == size - 9) {
new BukkitRunnable() {
@Override
public void run() {
goBackCallback.accept(player, event);

destroy();
}
}.runTask(plugin);
Plugin.getFoliaLib().getScheduler().runAtLocation(event.getWhoClicked().getLocation() ,wrappedTask -> {
goBackCallback.accept(player, event);
destroy();
});
}

if (slot >= 9 && slot < size - 9) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/shopplusplus/menus/ListedItemsMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public ListedItemsMenu(Player player) {
MenuPagination gui = new MenuPagination(GUIUtils.getTitle("player-listed-items"), 9 * 6,
GUIUtils.getNextPageButton(),
GUIUtils.getPreviousPageButton(), items, (_player, event) -> {
player.closeInventory();
new MainMenu(_player); // command: /shop
}, (_player, context) -> {
if (!context.getEvent().isRightClick()) {
return;
Expand Down
20 changes: 15 additions & 5 deletions src/main/java/shopplusplus/menus/MainMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
import java.util.HashMap;
import java.util.Map;

import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;

import org.bukkit.inventory.meta.SkullMeta;
import shopplusplus.core.ShopManager;
import shopplusplus.core.gui.Menu;
import shopplusplus.core.structures.Category;
Expand All @@ -16,7 +18,7 @@

public class MainMenu {
public MainMenu(Player player) {
Menu gui = new Menu(GUIUtils.getTitle("main-menu"), 9 * 4);
Menu gui = new Menu(GUIUtils.getTitle("main-menu"), 9 * 3);

ItemStack buildingBlocksButton = GUIUtils.getItem("building-blocks");

Expand Down Expand Up @@ -88,12 +90,12 @@ public MainMenu(Player player) {
new SpecificCategoryMenu(player, Category.MISCELLANEOUS);
});

gui.addItem(27, GUIUtils.getBackButton(), (_player, event) -> {
gui.addItem(18, GUIUtils.getBackButton(), (_player, event) -> {
if (!event.isLeftClick()) {
return;
}

player.closeInventory();
player.performCommand("ultimateshop"); // back to last menu
});

PlayerData data = ShopManager.getPlayerDataByPlayer(player);
Expand All @@ -105,9 +107,17 @@ public MainMenu(Player player) {
replacements.put("{player-rank}", String.valueOf(ShopManager.getPlayerRank(player)));

ItemStack playerInfoButton = GUIUtils.getItem("player-info", replacements);
SkullMeta head = (SkullMeta) playerInfoButton.getItemMeta();
head.setOwnerProfile(player.getPlayerProfile());
playerInfoButton.setItemMeta(head);

gui.addItem(35, playerInfoButton, (_player, event) -> {
// Do nothing
gui.addItem(26, playerInfoButton, (_player, event) -> {
// open list items menu (/listed)
if (!event.isLeftClick()) {
return;
}

new ListedItemsMenu(player);
});

gui.open(player, GUIUtils.getEmptySlot());
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ description: 'A simple Minecraft shop plugin!'
author: TFAGaming
version: 2.0.0
api-version: 1.21
folia-supported: true
softdepend:
- Vault
commands:
Expand Down
130 changes: 130 additions & 0 deletions src/main/resources/zh-CN.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
general:
none: "&c无"
expired: "&c已过期"

commands:
noSlotInInventory: "&c你的背包已满!"
noItemInHand: "&c你手上没有任何物品."
noPriceProvided: "&c你必须指定该物品的价格!"
limitReached: "&c你已达到出售上限! 升级更高等级来解锁更多功能."
priceIsNotNumber: "&c价格必须是有效的数字."
priceTooExpensive: "&c价格过于昂贵!"
itemListed: "&a成功出售物品."
itemBuyerIsSeller: "&c不能购买自己的物品!"
notEnoughMoneyToPurchase: "&c你没有足够的金币购买该物品!"
itemNotFound: "&c该物品可能已被其他玩家购买或已被卖家下架."

menu-titles:
main-menu: "Shop++"
player-listed-items: "列出的物品"
category-menu: "分类: {category}"
material-menu: "材料: {material}"
purchase-confirm: "确认购买"

menu-items:
building-blocks:
displayname: "&2建筑方块"
lore:
- "&7左键打开."
icon: GRASS_BLOCK
tools:
displayname: "&f工具"
lore:
- "&7左键打开."
icon: IRON_PICKAXE
food:
displayname: "&d食物"
lore:
- "&7左键打开."
icon: COOKED_BEEF
minerals:
displayname: "&b矿物"
lore:
- "&7左键打开."
icon: DIAMOND
natural:
displayname: "&a自然"
lore:
- "&7左键打开."
icon: OAK_SAPLING
redstone:
displayname: "&c红石"
lore:
- "&7左键打开."
icon: REDSTONE
miscellaneous:
displayname: "&6杂项"
lore:
- "&7左键打开."
icon: LAVA_BUCKET
player-info:
displayname: "&e玩家: &6{player}"
lore:
- "&e排名: &6#{player-rank}"
- ""
- "&e余额: &6{player-balance}"
- "&e共计挣得: &6{player-totalearned}"
icon: PLAYERHEAD-c6e57726de60b1612857280116b2de609613ff342e93f10662391ea65bb3f939
cancel-purchase:
displayname: "&c取消"
lore:
- "&7左键取消."
icon: PLAYERHEAD-ac14600ace50695c7c9bcf09e42afd9f53c9e20daa1524c95db4197dd3116412
confirm-purchase:
displayname: "&a确认"
lore:
- "&7左键确认."
icon: PLAYERHEAD-383a88b593dab7e6218b79f5d95c44bb7ea17427c8e6c8cf6bb51cd2ba6ece2a

menu-others:
category-item:
lore:
- ""
- "&e材料: &6{material}"
- "&eOnly &6{material-count} &eare listed."
- ""
- "&7左键打开."
material-item:
lore:
- ""
- "&e卖家: &6{item-seller}"
- "&e价格: &6{item-price}"
- "&e过期时间: &6{item-expires}"
- ""
- "&7左键购买."
material-item-specific-player:
lore:
- ""
- "&e卖家: &6{item-seller} &e(你)"
- "&e价格: &6{item-price}"
- "&e过期时间: &6{item-expires}"
- ""
- "&7右键删除."
back-button:
displayname: "&c返回"
lore:
- "&7返回上一个菜单."
icon: RED_STAINED_GLASS_PANE
previous-page-button:
displayname: "&9上一页"
lore:
- "&7返回上一页."
icon: ARROW
next-page-button:
displayname: "&9下一页"
lore:
- "&7前往下一页."
icon: ARROW
filler-item:
displayname: " "
icon: GRAY_STAINED_GLASS_PANE

identification:
categories:
1: "建筑方块"
2: "工具"
4: "食物"
8: "矿物"
16: "自然"
32: "红石"
64: "杂项"