1
mirror of https://github.com/CarmJos/UltraDepository.git synced 2026-06-05 00:58:22 +08:00

Compare commits

...

11 Commits

Author SHA1 Message Date
carm af82d64ab1 [v1.3.5] 更新GithubReleases4J版本 2022-01-22 15:27:44 +08:00
carm 5d057d2e8e [v1.3.5] 更新GithubReleases4J版本 2022-01-22 14:47:58 +08:00
carm a427db36e9 [v1.3.4] 版本更新
- [A] 添加版本更新检查。
2022-01-22 06:07:33 +08:00
carm afd62a493d [v1.3.3] 版本更新
- [A] 支持通过 PlugMan 等插件进行热重载。
2022-01-21 23:19:09 +08:00
carm c841a7b1b3 [v1.3.2] 版本更新
- [F] 修复Javadoc错误
2022-01-21 13:13:43 +08:00
carm dc57e822b5 [v1.3.1] 版本更新
- [F] 修复Javadoc错误
2022-01-21 13:09:45 +08:00
carm 54cc9c070b [v1.3.1] 版本更新
- [U] 修改预测仓库配置文件的位置,使其在初次启动时自动生成,避免用户完全不知道还有预设仓库这回事。
2022-01-21 13:03:43 +08:00
carm fa07564548 [v1.3.0] [A] 添加Java注释,修改debug消息位置。 2022-01-17 13:54:32 +08:00
carm 7138d20357 [v1.2.6] [R] 整合构建、部署(Javadoc)与版本发布。 2022-01-16 08:08:17 +08:00
carm 379068b440 [v1.2.5] 版本更新
- [A] 针对物品能否出售的状态提供额外的配置。
- [A] 添加ActionBar提示(如需关掉仅需将消息设为"")
- [A] 添加取回物品到背包的声音。
- [F] 修复SellGUI数量重调回0后(虽然不可能发生)物品仍然显示的问题
- [F] 修复SellGUI中可能存在的精度显示异常的问题。
2022-01-14 19:09:49 +08:00
carm 23e900cf3f 添加发布地址 2022-01-14 14:57:28 +08:00
26 changed files with 570 additions and 171 deletions
+4 -4
View File
@@ -17,18 +17,18 @@
## 预设配置截图
### 渔夫仓库 ([fishman.yml](files/fishman.yml))
### 渔夫仓库 ([fishman.yml](../../src/main/resources/depositories/fishman.yml))
![fishman](images/fishman.png)
### 矿工仓库 ([miner.yml](files/miner.yml))
### 矿工仓库 ([miner.yml](../../src/main/resources/depositories/miner.yml))
![miner](images/miner.png)
### 农夫仓库 ([farmer.yml](files/farmer.yml))
### 农夫仓库 ([farmer.yml](../../src/main/resources/depositories/farmer.yml))
![farmer](images/farmer.png)
### 猎人仓库 ([hunter.yml](files/hunter.yml))
### 猎人仓库 ([hunter.yml](../../src/main/resources/depositories/hunter.yml))
![hunter](images/hunter.png)
+17 -7
View File
@@ -1,7 +1,7 @@
# This workflow will build a Java project with Maven, and cache/restore any dependencies to improve the workflow execution time
# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven
name: Project Deploy
name: Deploy & Upload
on:
# 支持手动触发构建
@@ -27,13 +27,23 @@ jobs:
server-username: MAVEN_USERNAME
server-password: MAVEN_TOKEN
- name: "Maven Deploy With Javadoc"
- name: "Maven Deploy"
run: mvn -B deploy --file pom.xml -DskipTests
env:
MAVEN_USERNAME: ${{ github.repository_owner }}
MAVEN_TOKEN: ${{secrets.GITHUB_TOKEN}}
- name: "Copy Javadoc to Location"
- name: "Release Asset Upload"
id: upload-release-asset
uses: shogo82148/actions-upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ github.event.release.upload_url }}
asset_path: asset/*.jar
asset_content_type: application/java-archive
- name: "Javadoc Deploy Staging"
run: |
rm -rf docs
mkdir -vp docs
@@ -44,10 +54,10 @@ jobs:
id: sitemap
uses: cicirello/generate-sitemap@v1
with:
base-url-path: https://carmjos.github.io/EasySQL
base-url-path: https://${{ github.repository_owner }}.github.io/${{ github.event.repository.name }}
path-to-root: docs
- name: "Output stats"
- name: "Output Javadoc stats"
run: |
echo "sitemap-path = ${{ steps.sitemap.outputs.sitemap-path }}"
echo "url-count = ${{ steps.sitemap.outputs.url-count }}"
@@ -65,11 +75,11 @@ jobs:
git config --global user.name 'CarmJos'
git config --global user.email 'carm@carm.cc'
- name: "Commit documentations"
- name: "Commit Javadocs"
run: |
cd docs
git init
git remote add origin git@github.com:CarmJos/UltraDepository.git
git remote add origin git@github.com:${{ github.repository }}.git
git checkout -b gh-pages
git add -A
git commit -m "API Document generated."
+1
View File
@@ -2,3 +2,4 @@
/target/
./*.iml
*.iml
asset/
+8 -7
View File
@@ -24,13 +24,15 @@
本插件由 [墨豆Mordo](https://www.mordo.cn)、[子墨Zimrs](https://www.zimrs.cn) 资助本人开发,经过授权后开源。
> 本插件已发布于 [MCBBS](https://www.mcbbs.net/forum.php?mod=viewthread&tid=1292631) 和 [SpigotMC]() 。
## 功能介绍
本插件允许配置多个不同功能的仓库,玩家通过 击杀生物/挖掘方块/捡起收集 获得的原版物品可以自动被放入仓库中。
进入仓库后的物品玩家可以选择拿出或直接按量出售,且每日的出售数量上限和每件物品的价格可以自定义。
插件支持针对不同的权限配置仓库的容量,由此可以制作付费享用的”农业仓库“、”战斗仓库“、”伐木仓库“...
插件支持针对不同的权限配置仓库的容量,由此可以制作付费享用的”作物仓库“、”药剂师仓库“、”伐木仓库“...
综上,该插件不但提供了一种功能特权,对其合理配置之后也将大大为玩家带来便利。
@@ -172,13 +174,9 @@
<summary>展开查看所有权限</summary>
```text
# UltraDepository.use
- 超级仓库的基本使用权限 (默认所有人都有)
# UltraDepository.silent
- 拥有该权限将不再接收到放入背包的提示。
# UltraDepository.Command.Sell
- 玩家使用Sell指令的权限
@@ -194,9 +192,12 @@
- 若玩家缺失该权限或“UltraDepository.auto”权限,则自动收集物品功能不会启用。
- 您可以自己使用GUI创建一个按钮,后通过给玩家添加/删除该权限决定玩家是否开启自动收集。
# UltraDepository.silent
- 拥有该权限将不再接收到放入背包的提示。
- 您可以自己使用GUI创建一个按钮,后通过给玩家添加/删除该权限决定玩家是否开启收集提示。
# UltraDepository.admin
- "超级仓库的管理权限"
```
</details>
@@ -217,7 +218,7 @@
文件名即仓库的ID,**强烈推荐使用纯英文**。以`.`开头的仓库配置不会被加载。部分符号可能会影响正常读取,请避免使用。
随本项目预设了几个常用的仓库类型,可以 [在这里](.examples/depositories) 找到您需要的仓库配置加以修改后使用。
随本项目预设了几个常用的仓库类型,可以 [在这里](.examples/depositories) 直接下载您需要的仓库配置加以修改后使用。
您也可以 [点击这里](src/main/resources/depositories/.example-depository.yml) 查看一份*详细的仓库配置示例*,以制作您自己的仓库。
+19 -2
View File
@@ -9,13 +9,13 @@
<maven.compiler.target>11</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.encoding>UTF-8</maven.compiler.encoding>
<easyplugin.version>1.3.4</easyplugin.version>
<easyplugin.version>1.3.5</easyplugin.version>
</properties>
<groupId>cc.carm.plugin</groupId>
<artifactId>ultradepository</artifactId>
<packaging>jar</packaging>
<version>1.2.4</version>
<version>1.3.4</version>
<name>UltraDepository</name>
<description>超级仓库插件,支持设定不同物品的存储仓库。</description>
@@ -116,6 +116,13 @@
<optional>true</optional>
</dependency>
<dependency>
<groupId>cc.carm.lib</groupId>
<artifactId>githubreleases4j</artifactId>
<version>1.3.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
@@ -244,16 +251,26 @@
</executions>
<configuration>
<finalName>${project.name}-${project.version}</finalName>
<outputDirectory>${project.basedir}/asset/</outputDirectory>
<createDependencyReducedPom>false</createDependencyReducedPom>
<relocations>
<relocation>
<pattern>org.bstats</pattern>
<shadedPattern>cc.carm.plugin.ultradepository.lib.bstats</shadedPattern>
</relocation>
<relocation>
<pattern>org.json</pattern>
<shadedPattern>cc.carm.plugin.ultradepository.lib.json</shadedPattern>
</relocation>
<relocation>
<pattern>cc.carm.lib.easyplugin</pattern>
<shadedPattern>cc.carm.plugin.ultradepository.lib.easyplugin</shadedPattern>
</relocation>
<relocation>
<pattern>cc.carm.lib.githubreleases4j</pattern>
<shadedPattern>cc.carm.plugin.ultradepository.lib.github</shadedPattern>
</relocation>
</relocations>
<filters>
<filter>
@@ -7,6 +7,7 @@ import cc.carm.lib.easyplugin.utils.MessageUtils;
import cc.carm.plugin.ultradepository.command.DepositoryCommand;
import cc.carm.plugin.ultradepository.configuration.PluginConfig;
import cc.carm.plugin.ultradepository.hooker.PAPIExpansion;
import cc.carm.plugin.ultradepository.hooker.UpdateChecker;
import cc.carm.plugin.ultradepository.listener.CollectListener;
import cc.carm.plugin.ultradepository.listener.UserListener;
import cc.carm.plugin.ultradepository.manager.ConfigManager;
@@ -60,9 +61,6 @@ public class UltraDepository extends EasyPlugin {
return false;
}
log("加载用户系统...");
userManager = new UserManager();
log("加载经济系统...");
if (Bukkit.getPluginManager().getPlugin("Vault") != null) {
economyManager = new EconomyManager();
@@ -76,11 +74,15 @@ public class UltraDepository extends EasyPlugin {
log("加载仓库管理器...");
depositoryManager = new DepositoryManager();
getDepositoryManager().loadDepositories();
GUI.initialize(this);
log("加载用户系统...");
userManager = new UserManager();
log("注册监听器...");
regListener(new UserListener());
regListener(new CollectListener());
GUI.initialize(this);
log("注册指令...");
registerCommand("UltraDepository", new DepositoryCommand());
@@ -107,6 +109,16 @@ public class UltraDepository extends EasyPlugin {
else return plugin.getDescription().getVersion();
}));
}
if (PluginConfig.CHECK_UPDATE.get()) {
log("开始检查更新...");
UpdateChecker.checkUpdate(this);
} else {
log("已禁用检查更新,跳过。");
}
getUserManager().loadPlayersData();
return true;
}
@@ -123,6 +135,7 @@ public class UltraDepository extends EasyPlugin {
log("卸载监听器...");
Bukkit.getServicesManager().unregisterAll(this);
}
public static DataStorage getStorage() {
@@ -21,6 +21,10 @@ public class PluginConfig {
"metrics", Boolean.class, true
);
public static final ConfigValue<Boolean> CHECK_UPDATE = new ConfigValue<>(
"check-update", Boolean.class, true
);
public static final ConfigStringCast<StorageMethod> STORAGE_METHOD = new ConfigStringCast<>(
"storage.method", StorageMethod::read, StorageMethod.YAML
);
@@ -47,6 +51,7 @@ public class PluginConfig {
public static class Sounds {
public static final ConfigSound COLLECT = new ConfigSound("sounds.collect", Sound.ENTITY_VILLAGER_CELEBRATE);
public static final ConfigSound TAKEOUT = new ConfigSound("sounds.collect");
public static final ConfigSound SELL_SUCCESS = new ConfigSound("sounds.sell-success");
public static final ConfigSound SELL_FAIL = new ConfigSound("sounds.sell-fail");
public static final ConfigSound GUI_CLICK = new ConfigSound("sounds.gui-click");
@@ -56,20 +61,49 @@ public class PluginConfig {
* 通用配置
*/
public static class General {
/**
* 针对每一件物品的额外介绍
* 将添加到背包界面内的物品上,避免重复配置
*/
public static final ConfigMessageList ADDITIONAL_LORE = new ConfigMessageList(
ConfigManager::getPluginConfig, "general.additional-lore", new String[]{},
public static class AdditionalLore {
public static final ConfigMessageList AVAILABLE_FOR_SALE = new ConfigMessageList(
ConfigManager::getPluginConfig, "general.additional-lore.available-for-sale",
new String[]{},
new String[]{
"%(item_name)", "%(amount)", "%(price)", "%(sold)", "%(remain)", "%(limit)"
});
public static final ConfigMessageList NOT_FOR_SALE = new ConfigMessageList(
ConfigManager::getPluginConfig, "general.additional-lore.not-for-sale",
new String[]{}, new String[]{
"%(item_name)", "%(amount)"
});
}
/**
* 提示玩家点击行为的介绍
* 将添加到背包界面内的物品上,避免重复配置
*/
public static class ClickLore {
public static final ConfigMessageList AVAILABLE_FOR_SALE = new ConfigMessageList(
ConfigManager::getPluginConfig,
"general.click-lore.available-for-sale",
new String[]{}, new String[]{
"%(item_name)", "%(amount)", "%(price)"
});
public static final ConfigMessageList NOT_FOR_SALE = new ConfigMessageList(
ConfigManager::getPluginConfig, "general.click-lore.not-for-sale",
new String[]{},
new String[]{
"%(item_name)", "%(amount)"
});
}
public static final ConfigMessageList CLICK_LORE = new ConfigMessageList(
ConfigManager::getPluginConfig,
"general.click-lore",
@@ -1,6 +1,7 @@
package cc.carm.plugin.ultradepository.configuration;
import cc.carm.lib.easyplugin.configuration.language.EasyMessage;
import cc.carm.lib.easyplugin.configuration.language.EasyMessageList;
import cc.carm.lib.easyplugin.configuration.language.MessagesRoot;
import cc.carm.lib.easyplugin.configuration.language.MessagesSection;
@@ -55,14 +56,23 @@ public class PluginMessages extends MessagesRoot {
new String[]{"%(item)", "%(amount)"}
);
public static final EasyMessageList ITEM_TAKEOUT = new EasyMessageList(
new String[]{"&f您从仓库中拿取了 &r%(item)&7x%(amount) &f放入到您的背包中。"},
new String[]{"%(item)", "%(amount)"}
);
public static final EasyMessageList ITEM_COLLECT = new EasyMessageList(
new String[]{"&f您收集了 &r%(item)&7x%(amount) &f,已自动放入到您的 &6%(depository) &f中。"},
new String[]{"%(item)", "%(amount)", "%(depository)"}
);
public static final EasyMessage ITEM_COLLECT_ACTIONBAR = new EasyMessage(
"&r%(item)&7x%(amount) &f-> &6%(depository)",
new String[]{"%(item)", "%(amount)", "%(depository)"}
);
public static final EasyMessageList NO_SPACE = new EasyMessageList(
"&f您仓库内没有足够的空间取出物品!"
"&f您背包内没有足够的空间取出物品!"
);
public static final EasyMessageList NO_ECONOMY = new EasyMessageList(
@@ -85,4 +95,8 @@ public class PluginMessages extends MessagesRoot {
"&f数目输入错误,请输入正确的数字!"
);
public static final EasyMessage LOAD_FAILED = new EasyMessage(
"&c您的背包数据未被正确加载,请重新进入!"
);
}
@@ -116,8 +116,8 @@ public class DepositoryItem {
return new DepositoryItem(
depository, material, data,
section.getInt("slot", 0),
section.getDouble("price", 0),
section.getInt("limit", 0),
section.getDouble("price", -1),
section.getInt("limit", -1),
section.getString("name", material.name()),
section.getStringList("lore")
);
@@ -0,0 +1,32 @@
package cc.carm.plugin.ultradepository.hooker;
import cc.carm.lib.githubreleases4j.GithubReleases4J;
import cc.carm.plugin.ultradepository.UltraDepository;
public class UpdateChecker {
public static void checkUpdate(UltraDepository plugin) {
plugin.getScheduler().runAsync(() -> {
Integer behindVersions = GithubReleases4J.getVersionBehind(
"CarmJos", "UltraDepository",
plugin.getDescription().getVersion()
);
if (behindVersions == null) {
plugin.error("检查更新失败,请您定期查看插件是否更新,避免安全问题。");
plugin.error("插件下载地址&e " + GithubReleases4J.getReleasesURL("CarmJos", "UltraDepository"));
} else {
if (behindVersions > 0) {
plugin.log("检查更新完成,当前已落后 " + behindVersions + " 个版本。");
plugin.log("最新版本下载地址&e " + GithubReleases4J.getLatestReleaseURL("CarmJos", "UltraDepository"));
} else {
plugin.log("检查更新完成,当前已是最新版本。");
}
}
});
}
}
@@ -1,6 +1,7 @@
package cc.carm.plugin.ultradepository.listener;
import cc.carm.plugin.ultradepository.UltraDepository;
import cc.carm.plugin.ultradepository.configuration.PluginMessages;
import cc.carm.plugin.ultradepository.data.UserData;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
@@ -19,15 +20,13 @@ public class UserListener implements Listener {
if (event.getLoginResult() != AsyncPlayerPreLoginEvent.Result.ALLOWED) {
return;
}
UUID uuid = event.getUniqueId();
UltraDepository.getInstance().debug("尝试加载玩家 " + event.getName() + " 的数据...");
UltraDepository.getUserManager().getDataCache().put(uuid, UltraDepository.getUserManager().loadData(uuid));
UltraDepository.getUserManager().loadDataCache(event.getUniqueId());
}
@EventHandler(priority = EventPriority.MONITOR)
public void onPreLoginMonitor(AsyncPlayerPreLoginEvent event) {
if (event.getLoginResult() != AsyncPlayerPreLoginEvent.Result.ALLOWED) {
UltraDepository.getUserManager().getDataCache().remove(event.getUniqueId());
UltraDepository.getUserManager().removeDataCache(event.getUniqueId());
}
}
@@ -36,7 +35,7 @@ public class UserListener implements Listener {
UserData data = UltraDepository.getUserManager().getData(e.getPlayer().getUniqueId());
if (data == null) {
e.setResult(PlayerLoginEvent.Result.KICK_OTHER);
e.setKickMessage(UltraDepository.getInstance().getName() + " 数据未被正确加载,请重新进入。");
e.setKickMessage(PluginMessages.LOAD_FAILED.get(e.getPlayer()));
}
}
@@ -44,7 +43,8 @@ public class UserListener implements Listener {
public void onQuit(PlayerQuitEvent event) {
Player player = event.getPlayer();
UUID playerUUID = player.getUniqueId();
UltraDepository.getInstance().getScheduler().runAsync(() -> UltraDepository.getUserManager().unloadData(playerUUID, true));
UltraDepository.getInstance().getScheduler()
.runAsync(() -> UltraDepository.getUserManager().unloadData(playerUUID, true));
}
}
@@ -6,6 +6,7 @@ import cc.carm.plugin.ultradepository.configuration.PluginMessages;
import cc.carm.plugin.ultradepository.configuration.depository.Depository;
import cc.carm.plugin.ultradepository.configuration.depository.DepositoryItem;
import cc.carm.plugin.ultradepository.event.DepositoryCollectItemEvent;
import cc.carm.plugin.ultradepository.util.JarUtil;
import com.google.common.collect.HashMultimap;
import org.bukkit.Bukkit;
import org.bukkit.Material;
@@ -18,6 +19,7 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.io.File;
import java.io.IOException;
import java.util.*;
import java.util.stream.Collectors;
@@ -46,9 +48,13 @@ public class DepositoryManager {
if (!folder.exists()) {
folder.mkdir();
UltraDepository.getInstance().saveResource(
"depositories/.example-depository.yml", false
try {
JarUtil.copyFolderFromJar(
"depositories", UltraDepository.getInstance().getDataFolder(),
JarUtil.CopyOption.COPY_IF_NOT_EXIST
);
} catch (IOException ignore) {
}
} else if (folder.isDirectory()) {
folder.delete();
@@ -179,6 +185,12 @@ public class DepositoryManager {
finalAmount, depository.getName()
});
PluginConfig.Sounds.COLLECT.play(player);
PluginMessages.ITEM_COLLECT_ACTIONBAR.sendBar(player, new Object[]{
depository.getItems().get(typeID).getName(),
finalAmount, depository.getName()
}); // Support action bar
}
UltraDepository.getInstance().debug("Item collected successfully.");
return true;
@@ -4,6 +4,7 @@ import cc.carm.plugin.ultradepository.UltraDepository;
import cc.carm.plugin.ultradepository.data.UserData;
import cc.carm.plugin.ultradepository.storage.DataStorage;
import cc.carm.plugin.ultradepository.util.DateIntUtil;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -20,6 +21,27 @@ public class UserManager {
return dataCache;
}
public void loadPlayersData() {
if (Bukkit.getOnlinePlayers().size() < 1) return;
UltraDepository.getInstance().log("加载当前在线玩家数据...");
// 用于热加载时重载玩家数据。
Bukkit.getOnlinePlayers().forEach(player -> loadDataCache(player.getUniqueId()));
}
public @NotNull UserData loadDataCache(@NotNull UUID userUUID) {
UserData data = loadData(userUUID);
UltraDepository.getUserManager().getDataCache().put(userUUID, data);
return data;
}
public boolean removeDataCache(@NotNull UUID userUUID) {
boolean contains = getDataCache().containsKey(userUUID);
getDataCache().remove(userUUID);
return contains;
}
public @Nullable UserData getData(@NotNull UUID userUUID) {
return getDataCache().get(userUUID);
}
@@ -32,7 +54,7 @@ public class UserManager {
try {
long start = System.currentTimeMillis();
DataStorage storage = UltraDepository.getStorage();
UltraDepository.getInstance().debug("正通过 " + storage.getClass().getSimpleName() + " 加载 " + userUUID + " 的用户数据...");
UltraDepository.getInstance().debug("正通过 " + storage.getClass().getSimpleName() + " 加载 " + userUUID + " 的用户数据...(" + System.currentTimeMillis() + ")");
UserData data = UltraDepository.getStorage().loadData(userUUID);
if (data == null) {
@@ -56,7 +78,7 @@ public class UserManager {
UserData data = getData(uuid);
if (data == null) return;
if (save) saveData(data);
dataCache.remove(uuid);
removeDataCache(uuid);
}
public void saveData(UserData data) {
@@ -64,7 +86,7 @@ public class UserManager {
long start = System.currentTimeMillis();
DataStorage storage = UltraDepository.getStorage();
UltraDepository.getInstance().debug("正通过 " + storage.getClass().getSimpleName() + " 保存 " + data.getUserUUID() + " 的用户数据...");
UltraDepository.getInstance().debug("正通过 " + storage.getClass().getSimpleName() + " 保存 " + data.getUserUUID() + " 的用户数据...(" + System.currentTimeMillis() + ")");
storage.saveUserData(data);
UltraDepository.getInstance().debug("通过 " + storage.getClass().getSimpleName() + " 保存 " + data.getUserUUID() + " 的用户数据完成," +
@@ -1,6 +1,7 @@
package cc.carm.plugin.ultradepository.storage;
import cc.carm.plugin.ultradepository.data.UserData;
import cc.carm.plugin.ultradepository.manager.UserManager;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -8,14 +9,38 @@ import java.util.UUID;
public interface DataStorage {
/**
* 在插件加载存储源时执行。
*
* @return 是否初始化成功
*/
boolean initialize();
/**
* 在插件被卸载时执行。
*/
void shutdown();
/**
* 用于加载用户数据的方法。<b>该方法将会被异步运行!</b>
* <br>该方法一般无需自行执行,见 {@link UserManager#loadData(UUID)}
* <br>
* <br>若不存在该用户的数据,请返回 null 。
* <br>若加载出现任何错误,请抛出异常。
*
* @param uuid 用户UUID
* @throws Exception 当出现任何错误时抛出
*/
@Nullable
UserData loadData(@NotNull UUID uuid) throws Exception;
/**
* 用于保存用户数据的方法。 <b>该方法将会被异步运行!</b>
* <br>该方法一般无需自行执行,见 {@link UserManager#saveData(UserData)}
*
* @param data 用户数据
* @throws Exception 当出现任何错误时抛出
*/
void saveUserData(@NotNull UserData data) throws Exception;
/**
@@ -13,8 +13,10 @@ import cc.carm.plugin.ultradepository.data.UserData;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.ClickType;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.IntStream;
@@ -24,7 +26,7 @@ public class DepositoryGUI extends GUI {
UserData userData;
Depository depository;
public DepositoryGUI(Player player, Depository depository) {
private DepositoryGUI(Player player, Depository depository) {
super(depository.getGUIConfiguration().getGUIType(), depository.getGUIConfiguration().getTitle());
this.player = player;
@@ -35,53 +37,53 @@ public class DepositoryGUI extends GUI {
}
public void setupItems() {
loadConfigItems();
loadDepositoryItems();
}
public void loadConfigItems() {
depository.getGUIConfiguration().setupItems(player, this);
}
public void loadDepositoryItems() {
depository.getItems().values().forEach(depositoryItem -> setItem(depositoryItem.getSlot(), createGUIItem(depositoryItem)));
}
private GUIItem createGUIItem(DepositoryItem item) {
DepositoryItemData itemData = userData.getItemData(item);
int canSell = item.getLimit() - itemData.getSold();
ItemStackFactory factory = new ItemStackFactory(item.getDisplayItem());
List<String> additionalLore = PluginConfig.General.ADDITIONAL_LORE.get(player, new Object[]{
item.getName(), itemData.getAmount(), item.getPrice(),
itemData.getSold(), canSell, item.getLimit()
});
additionalLore.forEach(factory::addLore);
List<String> clickLore = PluginConfig.General.CLICK_LORE.get(player, new Object[]{
item.getName(), itemData.getAmount(), item.getPrice()
});
clickLore.forEach(factory::addLore);
return new GUIItem(factory.toItemStack()) {
return new GUIItem(getItemIcon(player, userData, item)) {
@Override
public void onClick(ClickType type) {
DepositoryItemData itemData = userData.getItemData(item);
if (itemData.getAmount() < 1) {
PluginConfig.Sounds.SELL_FAIL.play(player);
PluginMessages.NO_ENOUGH_ITEM.send(player);
return;
}
if (type == ClickType.LEFT) {
if (canSell >= 1) {
if (canSell(item) && type == ClickType.LEFT) {
int sellableAmount = item.getLimit() - itemData.getSold();
if (sellableAmount >= 1) {
SellItemGUI.open(player, userData, itemData, depository, item);
} else {
PluginConfig.Sounds.SELL_FAIL.play(player);
PluginMessages.ITEM_SOLD_LIMIT.send(player, new Object[]{canSell, item.getLimit()});
PluginMessages.ITEM_SOLD_LIMIT.send(player, new Object[]{sellableAmount, item.getLimit()});
player.closeInventory();
}
} else if (type == ClickType.RIGHT) {
if (hasEmptySlot(player)) {
int pickupAmount = Math.min(itemData.getAmount(), item.getMaterial().getMaxStackSize());
userData.removeItemAmount(item.getDepository().getIdentifier(), item.getTypeID(), pickupAmount);
player.getInventory().addItem(item.getRawItem(pickupAmount));
PluginMessages.ITEM_PICKUP.send(player, new Object[]{
item.getName(), pickupAmount
int takeoutAmount = Math.min(itemData.getAmount(), item.getMaterial().getMaxStackSize());
userData.removeItemAmount(
item.getDepository().getIdentifier(), item.getTypeID(), takeoutAmount
);
player.getInventory().addItem(item.getRawItem(takeoutAmount));
PluginMessages.ITEM_TAKEOUT.send(player, new Object[]{
item.getName(), takeoutAmount
});
setupItems(); //刷新GUI
PluginConfig.Sounds.TAKEOUT.play(player);
setDisplay(getItemIcon(player, userData, item)); // 刷新物品显示
loadConfigItems(); // 更新配置中的其他物品
updateView();
} else {
PluginMessages.NO_SPACE.send(player);
@@ -92,12 +94,51 @@ public class DepositoryGUI extends GUI {
};
}
private boolean hasEmptySlot(Player player) {
public static boolean hasEmptySlot(Player player) {
return IntStream.range(0, 36)
.mapToObj(i -> player.getInventory().getItem(i))
.anyMatch(i -> i == null || i.getType() == Material.AIR);
}
public static ItemStack getItemIcon(@NotNull Player player,
@NotNull UserData userData,
@NotNull DepositoryItem item) {
DepositoryItemData itemData = userData.getItemData(item);
ItemStackFactory factory = new ItemStackFactory(item.getDisplayItem());
getExtraLore(player, itemData).forEach(factory::addLore);
return factory.toItemStack();
}
public static List<String> getExtraLore(@NotNull Player player,
@NotNull DepositoryItemData itemData) {
DepositoryItem item = itemData.getSource();
int canSell = item.getLimit() - itemData.getSold();
List<String> lore = new ArrayList<>();
if (canSell(item)) {
lore.addAll(PluginConfig.General.AdditionalLore.AVAILABLE_FOR_SALE.get(player, new Object[]{
item.getName(), itemData.getAmount(), item.getPrice(),
itemData.getSold(), canSell, item.getLimit()
}));
lore.addAll(PluginConfig.General.ClickLore.AVAILABLE_FOR_SALE.get(player, new Object[]{
item.getName(), itemData.getAmount(), item.getPrice()
}));
} else {
lore.addAll(PluginConfig.General.AdditionalLore.NOT_FOR_SALE.get(player, new Object[]{
item.getName(), itemData.getAmount()
}));
lore.addAll(PluginConfig.General.ClickLore.NOT_FOR_SALE.get(player, new Object[]{
item.getName(), itemData.getAmount()
}));
}
return lore;
}
public static boolean canSell(DepositoryItem item) {
return UltraDepository.getEconomyManager().isInitialized()
&& item.getLimit() > 0 && item.getPrice() > 0;
}
public static void open(@NotNull Player player, @NotNull Depository depository) {
player.closeInventory();
DepositoryGUI gui = new DepositoryGUI(player, depository);
@@ -15,6 +15,8 @@ import org.bukkit.entity.Player;
import org.bukkit.event.inventory.ClickType;
import org.bukkit.inventory.ItemStack;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.List;
import static cc.carm.plugin.ultradepository.configuration.PluginConfig.General.SellGUI.Items.*;
@@ -51,8 +53,9 @@ public class SellItemGUI extends GUI {
private void load(int amount) {
this.currentAmount = Math.max(1, amount); // 不可小于1
ItemStackFactory factory = new ItemStackFactory(this.itemDisplay);
List<String> additionalLore = PluginConfig.General.ADDITIONAL_LORE.get(player, new Object[]{
getItemName(), getReUltraDepositoryAmount(), getItemPrice(),
List<String> additionalLore = PluginConfig.General.AdditionalLore.AVAILABLE_FOR_SALE
.get(player, new Object[]{
getItemName(), getDepositoryAmount(), getItemPrice(),
getSoldAmount(), (getSellLimit() - getSoldAmount()), getSellLimit()
});
additionalLore.forEach(factory::addLore);
@@ -67,7 +70,7 @@ public class SellItemGUI extends GUI {
setItem(16, getAddableAmount() >= 100 ? getAddItem(100) : null);
setItem(17, getAddableAmount() >= 1000 ? getAddItem(1000) : null);
if (getCurrentAmount() >= 1) setItem(getConfirmItem(), 27, 28, 29, 30);
setItem(getCurrentAmount() >= 1 ? getConfirmItem() : null, 27, 28, 29, 30);
setItem(getCancelItem(), 32, 33, 34, 35);
}
@@ -104,7 +107,7 @@ public class SellItemGUI extends GUI {
})) {
@Override
public void onClick(ClickType type) {
int amount = Math.min(getCurrentAmount(), Math.min(getReUltraDepositoryAmount(), getSellLimit() - getSoldAmount()));
int amount = Math.min(getCurrentAmount(), Math.min(getDepositoryAmount(), getSellLimit() - getSoldAmount()));
if (amount > 0) UltraDepository.getEconomyManager().sellItem(player, userData, item, amount);
player.closeInventory();
}
@@ -138,10 +141,11 @@ public class SellItemGUI extends GUI {
}
private double getTotalMoney() {
return getCurrentAmount() * getItemPrice();
BigDecimal money = BigDecimal.valueOf(getCurrentAmount() * getItemPrice()).setScale(2, RoundingMode.DOWN);
return money.doubleValue();
}
private int getReUltraDepositoryAmount() {
private int getDepositoryAmount() {
return userData.getItemData(this.item).getAmount();
}
@@ -150,7 +154,7 @@ public class SellItemGUI extends GUI {
}
private int getAddableAmount() {
return Math.min(getReUltraDepositoryAmount(), getSellLimit() - getSoldAmount()) - getCurrentAmount();
return Math.min(getDepositoryAmount(), getSellLimit() - getSoldAmount()) - getCurrentAmount();
}
public static void open(Player player, UserData userData, DepositoryItemData itemData,
+22 -2
View File
@@ -11,6 +11,11 @@ debug: false
# 当然,您也可以选择在这里关闭,或在plugins/bStats下的配置文件中关闭。
metrics: true
# 检查更新设定
# 该选项用于插件判断是否要检查更新,若您不希望插件检查更新并提示您,可以选择关闭。
# 检查更新为异步操作,绝不会影响性能与使用体验。
check-update: true
# 存储相关配置
# 注意:存储配置不会通过重载指令生效,如有修改请重新启动服务器。
storage:
@@ -20,7 +25,7 @@ storage:
# 选择 yaml/json 存储方式时的存储路径
# 默认为相对路径,相对于插件生成的配置文件夹下的路径
# 支持绝对路径,如 “/var/data/ub/"(linux) 或 "D:\data\ub\"(windows)
# 支持绝对路径,如 “/var/data/ud/"(linux) 或 "D:\data\ud\"(windows)
# 使用绝对路径时请注意权限问题
file-path: data
@@ -44,6 +49,7 @@ collect:
sounds:
collect: "ENTITY_EXPERIENCE_ORB_PICKUP:0.5"
takeout: "ENTITY_HORSE_ARMOR:0.5"
sell-success: "ENTITY_VILLAGER_CELEBRATE"
sell-fail: "ENTITY_VILLAGER_NO"
gui-click: "UI_BUTTON_CLICK"
@@ -51,20 +57,34 @@ sounds:
# 通用配置
general:
# 针对每一件物品的额外介绍
# 针对可出售物品的额外介绍
# 将添加到背包界面内的物品上,避免重复配置
additional-lore:
available-for-sale:
# 可出售物品的介绍
- " "
- "&f仓库内数量 &a%(amount)"
- "&f该物品单价 &a%(price)"
- "&f今日可出售 &a%(remain)&8/%(limit)"
not-for-sale:
# 针对不可出售的物品的额外介绍
# (当 未安装经济插件 或 每日可售出数量<=0 或 单价<=0 时判断为不可出售)
- " "
- "&f仓库内数量 &a%(amount)"
# 提示玩家点击行为的介绍
# 将添加到背包界面内的物品上,避免重复配置
click-lore:
available-for-sale:
- " "
- "&a&l左键点击 &8| &f按量售出该物品"
- "&a&l右键点击 &8| &f取出一组该物品"
not-for-sale:
# 针对不可出售的物品的额外介绍
# (当 未安装经济插件 或 每日可售出数量<=0 或 单价<=0 时判断为不可出售)
- " "
- "&a&l右键点击 &8| &f取出一组该物品"
# 售出界面的配置
sell-gui:
+20 -1
View File
@@ -20,7 +20,7 @@ storage:
method: yaml
# The storage file path when choosing "yaml"/"json" method.
# Support absolute paths, e.g. “/var/data/ub/"(linux) or "D:\data\ub\"(windows)
# Support absolute paths, e.g. “/var/data/ud/"(linux) or "D:\data\ud\"(windows)
# **Be aware of permission issues when using absolute paths!**
file-path: data
@@ -52,17 +52,36 @@ general:
# Hints lore for the item's information
# Will add to items in BackpackGUI and SellGUI.
additional-lore:
available-for-sale:
- " "
- "&fAmount &a%(amount)"
- "&fPrice &a%(price)"
- "&fSold &a%(remain)&8/%(limit)"
not-for-sale:
# Display when :
# 1. Vault not installed
# 2. No economy plugins
# 3. daily sell limit <= 0
# 4. item price <=0
- " "
- "&fAmount &a%(amount)"
# Hints lore for the player's click
# Will add to items in BackpackGUI.
click-lore:
available-for-sale:
- " "
- "&a&lLEFT-CLICK &8| &fSell items"
- "&a&lRIGHT-CLICK &8| &fTake one Stack"
not-for-sale:
# Display when :
# 1. Vault not installed
# 2. No economy plugins
# 3. daily sell limit <= 0
# 4. item price <=0
- " "
- "&a&lRIGHT-CLICK &8| &fTake one Stack"
# Configuration of the SellGUI
sell-gui:
@@ -0,0 +1,48 @@
help:
console:
- '&6&l超级仓库 &f后台指令帮助'
- '&8#&f info &6<玩家> &e[仓库ID] &e[物品ID]'
- '&8-&7 得到玩家的相关物品信息。'
- '&8#&f add &6<玩家> &6<仓库ID> &6<物品ID> &6<数量>'
- '&8-&7 为玩家添加对应仓库中对于物品的数量。'
- '&8#&f remove &6<玩家> &6<仓库ID> &6<物品ID> &e[数量]'
- '&8-&7 为玩家减少对应仓库中对于物品的数量。'
- '&8-&7 若不填写数量,则清空对应仓库的对应物品。'
- '&8#&f sell &6<玩家> &e[仓库ID] &e[物品ID] &e[数量]'
- '&8-&7 为玩家售出相关物品。'
- '&8-&7 若不填写数量,则售出所有对应仓库的对应物品。'
- '&8-&7 若不填写物品,则售出对应仓库内所有物品。'
- '&8-&7 若不填写仓库,则售出所有仓库内所有物品。'
- '&8-&7 该指令受到玩家每日售出数量的限制。'
player:
- '&6&l超级仓库 &f玩家指令帮助'
- '&8#&f open &e[仓库ID]'
- '&8-&7 打开对应仓库的界面。'
- '&8#&f sell &6<仓库ID> &6<物品ID> &6<数量>'
- '&8-&7 售出对应数量的对应物品。'
- '&8-&7 该指令受到玩家每日售出数量的限制。'
- '&8#&f sellAll &e[仓库ID] &e[物品ID]'
- '&8-&7 该指令受到玩家每日售出数量的限制。'
item-sold:
- '&f您出售了 &r%(item)&7x%(amount) &f,共赚取 &6%(money) &f元。'
item-sold-limit:
- '&f该物品今日剩余可出售额度为 &a%(amount)&8/%(limit) &f个。'
item-pickup:
- '&f您拾取了 &r%(item)&7x%(amount) &f,已自动放入到您的仓库中。'
item-takeout:
- '&f您从仓库中拿取了 &r%(item)&7x%(amount) &f放入到您的背包中。'
item-collect:
- '&f您收集了 &r%(item)&7x%(amount) &f,已自动放入到您的 &6%(depository) &f中。'
item-collect-actionbar: '&r%(item)&7x%(amount) &f-> &6%(depository)'
no-space:
- '&f您背包内没有足够的空间取出物品!'
no-economy:
- '&f本服务器暂未启用出售功能。'
no-depository:
- '&f不存在该仓库,请检查仓库ID是否正确。'
no-item:
- '&f仓库中不存在该物品,请检查物品ID是否正确。'
no-enough-item:
- '&f仓库中不存在足够的物品。'
wrong-number:
- '&f数目输入错误,请输入正确的数字!'
+19 -1
View File
@@ -20,7 +20,7 @@ storage:
method: yaml
# The storage file path when choosing "yaml"/"json" method.
# Support absolute paths, e.g. “/var/data/ub/"(linux) or "D:\data\ub\"(windows)
# Support absolute paths, e.g. “/var/data/ud/"(linux) or "D:\data\ud\"(windows)
# **Be aware of permission issues when using absolute paths!**
file-path: data
@@ -52,17 +52,35 @@ general:
# Hints lore for the item's information
# Will add to items in BackpackGUI and SellGUI.
additional-lore:
available-for-sale:
- " "
- "&fAmount &a%(amount)"
- "&fPrice &a%(price)"
- "&fSold &a%(remain)&8/%(limit)"
not-for-sale:
# Display when :
# 1. Vault not installed
# 2. No economy plugins
# 3. daily sell limit <= 0
# 4. item price <=0
- " "
- "&fAmount &a%(amount)"
# Hints lore for the player's click
# Will add to items in BackpackGUI.
click-lore:
available-for-sale:
- " "
- "&a&lLEFT-CLICK &8| &fSell items"
- "&a&lRIGHT-CLICK &8| &fTake one Stack"
not-for-sale:
# Display when :
# 1. Vault not installed
# 2. No economy plugins
# 3. daily sell limit <= 0
# 4. item price <=0
- " "
- "&a&lRIGHT-CLICK &8| &fTake one Stack"
# Configuration of the SellGUI
sell-gui:
@@ -0,0 +1,48 @@
help:
console:
- '&6&l超级仓库 &f后台指令帮助'
- '&8#&f info &6<玩家> &e[仓库ID] &e[物品ID]'
- '&8-&7 得到玩家的相关物品信息。'
- '&8#&f add &6<玩家> &6<仓库ID> &6<物品ID> &6<数量>'
- '&8-&7 为玩家添加对应仓库中对于物品的数量。'
- '&8#&f remove &6<玩家> &6<仓库ID> &6<物品ID> &e[数量]'
- '&8-&7 为玩家减少对应仓库中对于物品的数量。'
- '&8-&7 若不填写数量,则清空对应仓库的对应物品。'
- '&8#&f sell &6<玩家> &e[仓库ID] &e[物品ID] &e[数量]'
- '&8-&7 为玩家售出相关物品。'
- '&8-&7 若不填写数量,则售出所有对应仓库的对应物品。'
- '&8-&7 若不填写物品,则售出对应仓库内所有物品。'
- '&8-&7 若不填写仓库,则售出所有仓库内所有物品。'
- '&8-&7 该指令受到玩家每日售出数量的限制。'
player:
- '&6&l超级仓库 &f玩家指令帮助'
- '&8#&f open &e[仓库ID]'
- '&8-&7 打开对应仓库的界面。'
- '&8#&f sell &6<仓库ID> &6<物品ID> &6<数量>'
- '&8-&7 售出对应数量的对应物品。'
- '&8-&7 该指令受到玩家每日售出数量的限制。'
- '&8#&f sellAll &e[仓库ID] &e[物品ID]'
- '&8-&7 该指令受到玩家每日售出数量的限制。'
item-sold:
- '&f您出售了 &r%(item)&7x%(amount) &f,共赚取 &6%(money) &f元。'
item-sold-limit:
- '&f该物品今日剩余可出售额度为 &a%(amount)&8/%(limit) &f个。'
item-pickup:
- '&f您拾取了 &r%(item)&7x%(amount) &f,已自动放入到您的仓库中。'
item-takeout:
- '&f您从仓库中拿取了 &r%(item)&7x%(amount) &f放入到您的背包中。'
item-collect:
- '&f您收集了 &r%(item)&7x%(amount) &f,已自动放入到您的 &6%(depository) &f中。'
item-collect-actionbar: '&r%(item)&7x%(amount) &f-> &6%(depository)'
no-space:
- '&f您背包内没有足够的空间取出物品!'
no-economy:
- '&f本服务器暂未启用出售功能。'
no-depository:
- '&f不存在该仓库,请检查仓库ID是否正确。'
no-item:
- '&f仓库中不存在该物品,请检查物品ID是否正确。'
no-enough-item:
- '&f仓库中不存在足够的物品。'
wrong-number:
- '&f数目输入错误,请输入正确的数字!'
+20
View File
@@ -0,0 +1,20 @@
import cc.carm.lib.githubreleases4j.GithubRelease;
import cc.carm.lib.githubreleases4j.GithubReleases4J;
import org.junit.Test;
import java.util.List;
public class ReleasesTest {
@Test
public void onTest() {
List<GithubRelease> releases = GithubReleases4J.listReleases("CarmJos", "UltraDepository");
for (GithubRelease release : releases) {
System.out.println("#" + release.getID() + " (:" + release.getTagName() + ")" + " " + release.getName());
System.out.println("- " + release.getHTMLUrl());
}
}
}