mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2025-04-04 10:36:24 +02:00

# Conflicts: # Bukkit/src/main/java/com/plotsquared/bukkit/BukkitPlatform.java # Bukkit/src/main/java/com/plotsquared/bukkit/listener/PlayerEvents.java # Bukkit/src/main/java/com/plotsquared/bukkit/player/BukkitOfflinePlayer.java # Bukkit/src/main/java/com/plotsquared/bukkit/player/BukkitPlayer.java # Bukkit/src/main/java/com/plotsquared/bukkit/queue/BukkitLocalQueue.java # Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitEconHandler.java # Core/pom.xml # Core/src/main/java/com/plotsquared/core/PlotAPI.java # Core/src/main/java/com/plotsquared/core/PlotPlatform.java # Core/src/main/java/com/plotsquared/core/PlotSquared.java # Core/src/main/java/com/plotsquared/core/command/Area.java # Core/src/main/java/com/plotsquared/core/command/Auto.java # Core/src/main/java/com/plotsquared/core/command/Claim.java # Core/src/main/java/com/plotsquared/core/command/CmdConfirm.java # Core/src/main/java/com/plotsquared/core/command/Command.java # Core/src/main/java/com/plotsquared/core/command/CommandCaller.java # Core/src/main/java/com/plotsquared/core/command/DebugExec.java # Core/src/main/java/com/plotsquared/core/command/Grant.java # Core/src/main/java/com/plotsquared/core/command/Inbox.java # Core/src/main/java/com/plotsquared/core/command/Load.java # Core/src/main/java/com/plotsquared/core/command/Save.java # Core/src/main/java/com/plotsquared/core/command/Setup.java # Core/src/main/java/com/plotsquared/core/listener/PlotListener.java # Core/src/main/java/com/plotsquared/core/player/ConsolePlayer.java # Core/src/main/java/com/plotsquared/core/player/PlotPlayer.java # Core/src/main/java/com/plotsquared/core/plot/Plot.java # Core/src/main/java/com/plotsquared/core/plot/comment/CommentManager.java # Core/src/main/java/com/plotsquared/core/util/BlockUtil.java # Core/src/main/java/com/plotsquared/core/util/Permissions.java
87 lines
3.2 KiB
Java
87 lines
3.2 KiB
Java
/*
|
|
* _____ _ _ _____ _
|
|
* | __ \| | | | / ____| | |
|
|
* | |__) | | ___ | |_| (___ __ _ _ _ __ _ _ __ ___ __| |
|
|
* | ___/| |/ _ \| __|\___ \ / _` | | | |/ _` | '__/ _ \/ _` |
|
|
* | | | | (_) | |_ ____) | (_| | |_| | (_| | | | __/ (_| |
|
|
* |_| |_|\___/ \__|_____/ \__, |\__,_|\__,_|_| \___|\__,_|
|
|
* | |
|
|
* |_|
|
|
* PlotSquared plot management system for Minecraft
|
|
* Copyright (C) 2020 IntellectualSites
|
|
*
|
|
* This program is free software: you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
package com.plotsquared.bukkit.util;
|
|
|
|
import com.google.inject.Singleton;
|
|
import com.plotsquared.bukkit.player.BukkitOfflinePlayer;
|
|
import com.plotsquared.bukkit.player.BukkitPlayer;
|
|
import com.plotsquared.core.player.OfflinePlotPlayer;
|
|
import com.plotsquared.core.player.PlotPlayer;
|
|
import com.plotsquared.core.util.EconHandler;
|
|
import net.milkbowl.vault.economy.Economy;
|
|
import org.bukkit.Bukkit;
|
|
import org.bukkit.plugin.RegisteredServiceProvider;
|
|
|
|
import javax.annotation.Nullable;
|
|
|
|
@Singleton public class BukkitEconHandler extends EconHandler {
|
|
|
|
private Economy econ;
|
|
|
|
@Override public boolean init() {
|
|
if (this.econ == null) {
|
|
setupEconomy();
|
|
}
|
|
return this.econ != null;
|
|
}
|
|
|
|
private void setupEconomy() {
|
|
if (Bukkit.getServer().getPluginManager().getPlugin("Vault") == null) {
|
|
return;
|
|
}
|
|
RegisteredServiceProvider<Economy> economyProvider =
|
|
Bukkit.getServer().getServicesManager().getRegistration(Economy.class);
|
|
if (economyProvider != null) {
|
|
this.econ = economyProvider.getProvider();
|
|
}
|
|
}
|
|
|
|
@Override public double getMoney(PlotPlayer<?> player) {
|
|
double bal = super.getMoney(player);
|
|
if (Double.isNaN(bal)) {
|
|
return this.econ.getBalance(((BukkitPlayer) player).player);
|
|
}
|
|
return bal;
|
|
}
|
|
|
|
@Override public void withdrawMoney(PlotPlayer<?> player, double amount) {
|
|
this.econ.withdrawPlayer(((BukkitPlayer) player).player, amount);
|
|
}
|
|
|
|
@Override public void depositMoney(PlotPlayer<?> player, double amount) {
|
|
this.econ.depositPlayer(((BukkitPlayer) player).player, amount);
|
|
}
|
|
|
|
@Override public void depositMoney(OfflinePlotPlayer player, double amount) {
|
|
this.econ.depositPlayer(((BukkitOfflinePlayer) player).player, amount);
|
|
}
|
|
|
|
@Override public double getBalance(PlotPlayer<?> player) {
|
|
return this.econ.getBalance(player.getName());
|
|
}
|
|
|
|
}
|