From 029a1ee22690dffcb6fb495c7ea65db88812e433 Mon Sep 17 00:00:00 2001 From: 502647092 Date: Mon, 26 Sep 2016 20:13:37 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0Vault=E6=93=8D?= =?UTF-8?q?=E4=BD=9C=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 502647092 --- .../yumc/YumCore/plugin/vault/VaultBase.java | 19 ++++ .../yumc/YumCore/plugin/vault/VaultChat.java | 61 +++++++++++++ .../YumCore/plugin/vault/VaultEconomy.java | 78 ++++++++++++++++ .../YumCore/plugin/vault/VaultPermission.java | 88 +++++++++++++++++++ 4 files changed, 246 insertions(+) create mode 100644 src/main/java/pw/yumc/YumCore/plugin/vault/VaultBase.java create mode 100644 src/main/java/pw/yumc/YumCore/plugin/vault/VaultChat.java create mode 100644 src/main/java/pw/yumc/YumCore/plugin/vault/VaultEconomy.java create mode 100644 src/main/java/pw/yumc/YumCore/plugin/vault/VaultPermission.java diff --git a/src/main/java/pw/yumc/YumCore/plugin/vault/VaultBase.java b/src/main/java/pw/yumc/YumCore/plugin/vault/VaultBase.java new file mode 100644 index 0000000..85548be --- /dev/null +++ b/src/main/java/pw/yumc/YumCore/plugin/vault/VaultBase.java @@ -0,0 +1,19 @@ +package pw.yumc.YumCore.plugin.vault; + +import org.bukkit.Bukkit; + +import pw.yumc.YumCore.kit.PKit; + +/** + * Vault 基础 + * + * @since 2016年5月12日 下午4:52:57 + * @author 喵♂呜 + */ +public class VaultBase { + static { + if (Bukkit.getServer().getPluginManager().getPlugin("Vault") == null) { + PKit.disable("未找到 Vault 插件 停止加载..."); + } + } +} diff --git a/src/main/java/pw/yumc/YumCore/plugin/vault/VaultChat.java b/src/main/java/pw/yumc/YumCore/plugin/vault/VaultChat.java new file mode 100644 index 0000000..2aa2941 --- /dev/null +++ b/src/main/java/pw/yumc/YumCore/plugin/vault/VaultChat.java @@ -0,0 +1,61 @@ +package pw.yumc.YumCore.plugin.vault; + +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; +import org.bukkit.plugin.RegisteredServiceProvider; + +import net.milkbowl.vault.chat.Chat; +import pw.yumc.YumCore.bukkit.Log; +import pw.yumc.YumCore.kit.PKit; + +/** + * Vault 聊天管理 + * + * @since 2016年5月12日 下午5:02:03 + * @author 喵♂呜 + */ +public class VaultChat extends VaultBase { + private static Chat chat; + + static { + final RegisteredServiceProvider rsp = Bukkit.getServer().getServicesManager().getRegistration(Chat.class); + chat = rsp.getProvider(); + if (chat == null) { + PKit.disable("已加载 Vault 但是未找到聊天相关插件 停止加载..."); + } else { + Log.info("发现 Vault 使用聊天管理系统 " + chat.getName()); + } + } + + /** + * 获得Chat实例 + * + * @return {@link Chat} + */ + public static Chat getChat() { + return chat; + } + + /** + * 获得玩家称号 + * + * @param player + * 玩家实体 + * @return 玩家称号 + */ + public static String getPlayerPrefix(final Player player) { + return chat.getPlayerPrefix(player); + } + + /** + * 设置玩家所有世界称号 + * + * @param player + * 玩家实体 + * @param prefix + * 玩家称号 + */ + public static void setPlayerPrefix(final Player player, final String prefix) { + chat.setPlayerPrefix(player, prefix); + } +} diff --git a/src/main/java/pw/yumc/YumCore/plugin/vault/VaultEconomy.java b/src/main/java/pw/yumc/YumCore/plugin/vault/VaultEconomy.java new file mode 100644 index 0000000..71cca21 --- /dev/null +++ b/src/main/java/pw/yumc/YumCore/plugin/vault/VaultEconomy.java @@ -0,0 +1,78 @@ +package pw.yumc.YumCore.plugin.vault; + +import org.bukkit.Bukkit; +import org.bukkit.OfflinePlayer; +import org.bukkit.plugin.RegisteredServiceProvider; + +import net.milkbowl.vault.economy.Economy; +import net.milkbowl.vault.economy.EconomyResponse; +import pw.yumc.YumCore.bukkit.Log; +import pw.yumc.YumCore.kit.PKit; + +/** + * Vault 经济管理 + * + * @since 2016年5月12日 下午5:02:03 + * @author 喵♂呜 + */ +public class VaultEconomy extends VaultBase { + private static Economy economy; + + static { + final RegisteredServiceProvider rsp = Bukkit.getServer().getServicesManager().getRegistration(Economy.class); + economy = rsp.getProvider(); + if (economy == null) { + PKit.disable("已加载 Vault 但是未找到经济相关插件 停止加载..."); + } else { + Log.info("发现 Vault 使用经济管理系统 " + economy.getName()); + } + } + + /** + * 添加金额 + * + * @param oPlayer + * 玩家 + * @param amont + * 数量 + * @return {@link EconomyResponse} + */ + public static EconomyResponse add(final OfflinePlayer oPlayer, final double amont) { + return economy.depositPlayer(oPlayer, amont); + } + + /** + * 获得Economy实例 + * + * @return {@link Economy} + */ + public static Economy getEconomy() { + return economy; + } + + /** + * 判断玩家是否有指定的金额 + * + * @param oPlayer + * 玩家 + * @param amont + * 数量 + * @return 是否 + */ + public static boolean had(final OfflinePlayer oPlayer, final double amont) { + return economy.has(oPlayer, amont); + } + + /** + * 减少金额 + * + * @param oPlayer + * 玩家 + * @param amont + * 数量 + * @return {@link EconomyResponse} + */ + public static EconomyResponse remove(final OfflinePlayer oPlayer, final double amont) { + return economy.withdrawPlayer(oPlayer, amont); + } +} diff --git a/src/main/java/pw/yumc/YumCore/plugin/vault/VaultPermission.java b/src/main/java/pw/yumc/YumCore/plugin/vault/VaultPermission.java new file mode 100644 index 0000000..6618044 --- /dev/null +++ b/src/main/java/pw/yumc/YumCore/plugin/vault/VaultPermission.java @@ -0,0 +1,88 @@ +package pw.yumc.YumCore.plugin.vault; + +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; +import org.bukkit.plugin.RegisteredServiceProvider; + +import net.milkbowl.vault.permission.Permission; +import pw.yumc.YumCore.bukkit.Log; +import pw.yumc.YumCore.kit.PKit; + +/** + * Vault 权限管理 + * + * @since 2016年5月12日 下午5:02:03 + * @author 喵♂呜 + */ +public class VaultPermission extends VaultBase { + private static Permission permission; + + static { + final RegisteredServiceProvider rsp = Bukkit.getServer().getServicesManager().getRegistration(Permission.class); + permission = rsp.getProvider(); + if (permission == null) { + PKit.disable("已加载 Vault 但是未找到权限相关插件 停止加载..."); + } else { + Log.info("发现 Vault 使用权限管理系统 " + permission.getName()); + } + } + + /** + * 给玩家添加权限 + * + * @param player + * 玩家 + * @param perm + * 权限 + * @return 结果 + */ + public static boolean add(final Player player, final String perm) { + return permission.playerAdd(player, perm); + } + + /** + * 获得玩家权限组 + * + * @param player + * 玩家 + * @return 权限组 + */ + public static String getGroup(final Player player) { + return permission.getPrimaryGroup(player); + } + + /** + * 获得Permission实例 + * + * @return {@link Permission} + */ + public static Permission getPermission() { + return permission; + } + + /** + * 判断玩家是否有权限 + * + * @param player + * 玩家 + * @param perm + * 权限 + * @return 结果 + */ + public static boolean has(final Player player, final String perm) { + return permission.has(player, perm); + } + + /** + * 移除玩家权限 + * + * @param player + * 玩家 + * @param perm + * 权限 + * @return 结果 + */ + public static boolean remove(final Player player, final String perm) { + return permission.playerRemove(player, perm); + } +}