9
0
mirror of https://github.com/Xiao-MoMi/Custom-Fishing.git synced 2025-12-19 15:09:24 +00:00

Improve default configs

This commit is contained in:
XiaoMoMi
2024-08-06 21:48:57 +08:00
parent 6d107e805f
commit 777285fcf9
5 changed files with 58 additions and 31 deletions

View File

@@ -51,8 +51,8 @@ public class VersionHelper {
}
updateFuture.complete(true);
} catch (Exception exception) {
plugin.getPluginLogger().warn("Error occurred when checking update.", exception);
updateFuture.complete(false);
plugin.getPluginLogger().warn("Error occurred when checking update.");
updateFuture.completeExceptionally(exception);
}
});
return updateFuture;

View File

@@ -20,34 +20,60 @@ package net.momirealms.customfishing.bukkit.integration;
import net.milkbowl.vault.economy.Economy;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player;
import org.bukkit.plugin.RegisteredServiceProvider;
public class VaultHook {
private static Economy economy;
private static boolean isHooked = false;
public static boolean initialize() {
RegisteredServiceProvider<Economy> rsp = Bukkit.getServicesManager().getRegistration(Economy.class);
if (rsp == null) {
return false;
}
economy = rsp.getProvider();
return true;
public static void init() {
Singleton.initialize();
VaultHook.isHooked = true;
}
public static Economy getEconomy() {
return economy;
public static boolean isHooked() {
return isHooked;
}
public static void deposit(OfflinePlayer player, double amount) {
economy.depositPlayer(player, amount);
public static void deposit(Player player, double amount) {
Singleton.deposit(player, amount);
}
public static void withdraw(OfflinePlayer player, double amount) {
economy.withdrawPlayer(player, amount);
Singleton.withdraw(player, amount);
}
public static double getBalance(OfflinePlayer player) {
return economy.getBalance(player);
return Singleton.getBalance(player);
}
private static class Singleton {
private static Economy economy;
private static boolean initialize() {
RegisteredServiceProvider<Economy> rsp = Bukkit.getServicesManager().getRegistration(Economy.class);
if (rsp == null) {
return false;
}
economy = rsp.getProvider();
return true;
}
private static Economy getEconomy() {
return economy;
}
private static void deposit(OfflinePlayer player, double amount) {
economy.depositPlayer(player, amount);
}
private static void withdraw(OfflinePlayer player, double amount) {
economy.withdrawPlayer(player, amount);
}
private static double getBalance(OfflinePlayer player) {
return economy.getBalance(player);
}
}
}

View File

@@ -628,6 +628,7 @@ public class BukkitActionManager implements ActionManager<Player> {
MathValue<Player> value = MathValue.auto(args);
return context -> {
if (Math.random() > chance) return;
if (!VaultHook.isHooked()) return;
VaultHook.deposit(context.getHolder(), value.evaluate(context));
};
});
@@ -635,6 +636,7 @@ public class BukkitActionManager implements ActionManager<Player> {
MathValue<Player> value = MathValue.auto(args);
return context -> {
if (Math.random() > chance) return;
if (!VaultHook.isHooked()) return;
VaultHook.withdraw(context.getHolder(), value.evaluate(context));
};
});

View File

@@ -131,7 +131,7 @@ public class BukkitIntegrationManager implements IntegrationManager {
registerSeasonProvider(new CustomCropsSeasonProvider());
}
if (isHooked("Vault")) {
VaultHook.initialize();
VaultHook.init();
}
if (isHooked("BattlePass")){
BattlePassQuest battlePassQuest = new BattlePassQuest();

View File

@@ -257,13 +257,13 @@ mechanics:
message_action:
type: message
value: 'You earned {money_formatted} coins from the fish! You can get {rest_formatted} more coins from market today'
command_action:
type: command
value: 'money give {player} {money}'
# Requires Vault and any economy plugin
# money_action:
# type: give-money
# value: '{money}'
# Requires Vault and any economy plugin
money_action:
type: give-money
value: '{money}'
# command_action:
# type: command
# value: 'money give {player} {money}'
deny-icon:
material: REDSTONE_BLOCK
display:
@@ -312,13 +312,12 @@ mechanics:
message_action:
type: message
value: 'You earned {money_formatted} coins from the fish! You can get {rest_formatted} more coins from market today'
command_action:
type: command
value: 'money give {player} {money}'
# Requires Vault and any economy plugin
# money_action:
# type: give-money
# value: '{money}'
money_action:
type: give-money
value: '{money}'
# command_action:
# type: command
# value: 'money give {player} {money}'
deny-icon:
material: REDSTONE_BLOCK
display: