103 lines
3.9 KiB
Java
103 lines
3.9 KiB
Java
package net.t2code.lib.Spigot.Lib.eco;
|
|
|
|
import net.t2code.lib.Spigot.Lib.messages.send;
|
|
import net.t2code.lib.Spigot.Lib.plugins.PluginCheck;
|
|
import net.t2code.lib.Spigot.system.Main;
|
|
import net.t2code.lib.Spigot.system.languages.SelectLibMsg;
|
|
import org.bukkit.Bukkit;
|
|
import org.bukkit.Material;
|
|
import org.bukkit.entity.Player;
|
|
import org.bukkit.inventory.ItemStack;
|
|
|
|
public class Eco {
|
|
|
|
public static boolean moneyRemove(String prefix, Player player, Double price) {
|
|
if (vault(prefix, player)) {
|
|
return Main.eco.withdrawPlayer(player, price).transactionSuccess();
|
|
}
|
|
return false;
|
|
}
|
|
|
|
public static boolean moneyAdd(String prefix, Player player, Double price) {
|
|
if (vault(prefix, player)) {
|
|
return Main.eco.depositPlayer(player, price).transactionSuccess();
|
|
}
|
|
return false;
|
|
}
|
|
|
|
private static boolean vault(String prefix, Player player) {
|
|
if (Main.eco == null) {
|
|
if (Bukkit.getPluginManager().getPlugin("Vault") == null) {
|
|
send.console(prefix + " §4\n" + prefix + " §4Vault could not be found! §9Please download it here: " +
|
|
"§6https://www.spigotmc.org/resources/vault.34315/§4\n" + prefix);
|
|
}
|
|
player.sendMessage(prefix + "\n" + SelectLibMsg.vaultNotSetUp + "\n" + prefix);
|
|
return false;
|
|
} else return true;
|
|
}
|
|
|
|
public static boolean itemRemove(Player player, String item, int amount) {
|
|
ItemStack itemStack = new ItemStack(Material.valueOf(item.toUpperCase()));
|
|
boolean have = false;
|
|
int anz = 0;
|
|
for (int iam = 0; iam < player.getInventory().getSize(); iam++) {
|
|
ItemStack itm = player.getInventory().getItem(iam);
|
|
if (itm == null) continue;
|
|
if (itm.getType() == itemStack.getType()) {
|
|
anz = anz + itm.getAmount();
|
|
}
|
|
}
|
|
if (anz >= amount) {
|
|
player.getInventory().removeItem(new ItemStack(Material.valueOf(item), amount));
|
|
have = true;
|
|
}
|
|
return have;
|
|
}
|
|
|
|
public static boolean itemAdd(Player player, String item, int amount) {
|
|
ItemStack itemStack = new ItemStack(Material.valueOf(item.toUpperCase()));
|
|
boolean empty = false;
|
|
for (int i = 0; i < player.getInventory().getSize() - 5; i++) {
|
|
if (player.getInventory().getItem(i) == null) {
|
|
empty = true;
|
|
break;
|
|
}
|
|
}
|
|
for (int i = 0; i < amount; i++) {
|
|
if (empty) {
|
|
player.getInventory().addItem(itemStack);
|
|
} else {
|
|
player.getLocation().getWorld().dropItem(player.getLocation(), itemStack);
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
|
|
public static boolean votePointsRemove(String prefix, Player player, Integer amount) {
|
|
if (votePlugin(prefix, player)) {
|
|
return Main.voteUserManager.getVotingPluginUser(player).removePoints(amount);
|
|
|
|
} else return false;
|
|
}
|
|
|
|
public static boolean votePointsAdd(String prefix, Player player, Integer amount) {
|
|
if (votePlugin(prefix, player)) {
|
|
Bukkit.getScheduler().runTaskAsynchronously(Main.plugin, new Runnable() {
|
|
@Override
|
|
public void run() {
|
|
Main.voteUserManager.getVotingPluginUser(player).addPoints(amount);
|
|
}
|
|
});
|
|
return true;
|
|
} else return false;
|
|
}
|
|
|
|
private static boolean votePlugin(String prefix, Player player) {
|
|
if (PluginCheck.votingPlugin()) return true;
|
|
send.console(prefix + " §4\n" + prefix + " §4VotingPlugin could not be found! §9Please download it here: " +
|
|
"§6https://www.spigotmc.org/resources/votingplugin.15358/§4\n" + prefix);
|
|
player.sendMessage(prefix + "\n" + SelectLibMsg.votingPluginNotSetUp + "\n" + prefix);
|
|
return false;
|
|
}
|
|
}
|