Skip to content

Commit

Permalink
[U] 对 CMI 用户的提示
Browse files Browse the repository at this point in the history
  • Loading branch information
StarWishsama committed Jun 13, 2020
1 parent 9c1b2e5 commit 1f5c1e9
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,16 @@
/**
* @author Nameless
*/
public class VaultHook {
public class VaultHelper {
private static Economy econ = null;

public static void register() {
try {
RegisteredServiceProvider<Economy> rsp = SlimefunPlugin.instance.getServer().getServicesManager().getRegistration(Economy.class);
if (rsp != null) {
Slimefun.getLogger().log(Level.INFO, "成功接入 Vault");
econ = rsp.getProvider();
}
} catch (Exception e) {
Slimefun.getLogger().log(Level.SEVERE, e, () -> "无法接入 Vault");
RegisteredServiceProvider<Economy> rsp = SlimefunPlugin.instance.getServer().getServicesManager().getRegistration(Economy.class);
if (rsp != null) {
Slimefun.getLogger().log(Level.INFO, "成功接入 Vault");
econ = rsp.getProvider();
} else {
Slimefun.getLogger().log(Level.SEVERE, "无法接入 Vault. 如果你是 CMI 用户, 请至配置文件启用经济系统");
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package io.github.thebusybiscuit.slimefun4.core.guide;

import io.github.starwishsama.extra.VaultHook;
import io.github.starwishsama.extra.VaultHelper;
import io.github.thebusybiscuit.slimefun4.api.player.PlayerProfile;
import io.github.thebusybiscuit.slimefun4.core.researching.Research;
import io.github.thebusybiscuit.slimefun4.implementation.guide.BookSlimefunGuide;
Expand Down Expand Up @@ -68,8 +68,8 @@ default void unlockItem(Player p, SlimefunItem sfitem, Consumer<Player> callback
if (p.getGameMode() == GameMode.CREATIVE && SlimefunPlugin.getRegistry().isFreeCreativeResearchingEnabled()) {
research.unlock(p, true, callback);
} else {
if (VaultHook.isUsable()) {
VaultHook.getEcon().withdrawPlayer(p, research.getCost() * SlimefunPlugin.getCfg().getDouble("researches.money-multiply"));
if (VaultHelper.isUsable()) {
VaultHelper.getEcon().withdrawPlayer(p, research.getCost() * SlimefunPlugin.getCfg().getDouble("researches.money-multiply"));
} else {
p.setLevel(p.getLevel() - research.getCost());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package io.github.thebusybiscuit.slimefun4.core.researching;

import io.github.starwishsama.extra.VaultHook;
import io.github.starwishsama.extra.VaultHelper;
import io.github.thebusybiscuit.slimefun4.api.events.ResearchUnlockEvent;
import io.github.thebusybiscuit.slimefun4.api.player.PlayerProfile;
import io.github.thebusybiscuit.slimefun4.core.guide.options.SlimefunGuideSettings;
Expand Down Expand Up @@ -183,8 +183,8 @@ public boolean canUnlock(Player p) {
}

boolean expOrMoney;
if (VaultHook.isUsable()) {
expOrMoney = VaultHook.getEcon().getBalance(p) >= this.getCost() * SlimefunPlugin.getCfg().getDouble("researches.money-multiply");
if (VaultHelper.isUsable()) {
expOrMoney = VaultHelper.getEcon().getBalance(p) >= this.getCost() * SlimefunPlugin.getCfg().getDouble("researches.money-multiply");
} else {
expOrMoney = p.getLevel() >= cost;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package io.github.thebusybiscuit.slimefun4.core.services.plugins;

import io.github.starwishsama.extra.VaultHook;
import io.github.starwishsama.extra.VaultHelper;
import io.github.thebusybiscuit.slimefun4.api.SlimefunAddon;
import io.github.thebusybiscuit.slimefun4.core.categories.FlexCategory;
import me.mrCookieSlime.Slimefun.SlimefunPlugin;
Expand Down Expand Up @@ -54,7 +54,7 @@ public void start() {
}

if (SlimefunPlugin.getCfg().getBoolean("researches.use-money-unlock") && isPluginInstalled("Vault")) {
VaultHook.register();
VaultHelper.register();
}

// WorldEdit Hook to clear Slimefun Data upon //set 0 //cut or any other equivalent
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package io.github.thebusybiscuit.slimefun4.implementation.guide;

import io.github.starwishsama.extra.VaultHook;
import io.github.starwishsama.extra.VaultHelper;
import io.github.thebusybiscuit.cscorelib2.chat.ChatColors;
import io.github.thebusybiscuit.cscorelib2.chat.ChatInput;
import io.github.thebusybiscuit.cscorelib2.chat.json.ChatComponent;
Expand Down Expand Up @@ -160,7 +160,7 @@ public void openCategory(PlayerProfile profile, Category category, int page) {
Research research = item.getResearch();

ChatComponent component = new ChatComponent(ChatUtils.crop(ChatColor.RED, item.getItemName()) + "\n");
if (VaultHook.isUsable()) {
if (VaultHelper.isUsable()) {
component.setHoverEvent(new HoverEvent(ChatColor.RESET + item.getItemName(), ChatColor.DARK_RED.toString() + ChatColor.BOLD + SlimefunPlugin.getLocal().getMessage(p, "guide.locked"), "", ChatColor.GREEN + "> 单击解锁", "", ChatColor.GRAY + "需要 " + (research.getCost() * SlimefunPlugin.getCfg().getDouble("researches.money-multiply")) + " 游戏币"));
} else {
component.setHoverEvent(new HoverEvent(ChatColor.RESET + item.getItemName(), ChatColor.DARK_RED.toString() + ChatColor.BOLD + SlimefunPlugin.getLocal().getMessage(p, "guide.locked"), "", ChatColor.GREEN + "> 单击解锁", "", ChatColor.GRAY + "需要: " + ChatColor.AQUA.toString() + research.getCost() + " 级经验"));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package io.github.thebusybiscuit.slimefun4.implementation.guide;

import io.github.starwishsama.extra.VaultHook;
import io.github.starwishsama.extra.VaultHelper;
import io.github.thebusybiscuit.cscorelib2.chat.ChatInput;
import io.github.thebusybiscuit.cscorelib2.inventory.ItemUtils;
import io.github.thebusybiscuit.cscorelib2.item.CustomItem;
Expand Down Expand Up @@ -211,7 +211,7 @@ public void openCategory(PlayerProfile profile, Category category, int page) {

if (isSurvivalMode() && research != null && !profile.hasUnlocked(research)) {
if (Slimefun.hasPermission(p, sfitem, false)) {
if (VaultHook.isUsable()) {
if (VaultHelper.isUsable()) {
menu.addItem(index, new CustomItem(Material.BARRIER, "&r" + ItemUtils.getItemName(sfitem.getItem()), "&4&l" + SlimefunPlugin.getLocal().getMessage(p, "guide.locked"), "", "&a> 单击解锁", "", "&7需要 &b" + (research.getCost() * SlimefunPlugin.getCfg().getDouble("researches.money-multiply")) + " 游戏币"));
} else {
menu.addItem(index, new CustomItem(Material.BARRIER, "&r" + ItemUtils.getItemName(sfitem.getItem()), "&4&l" + SlimefunPlugin.getLocal().getMessage(p, "guide.locked"), "", "&a> 单击解锁", "", "&7需要 &b" + research.getCost() + " 级经验"));
Expand Down

0 comments on commit 1f5c1e9

Please sign in to comment.