T2CodeLib/src/main/java/net/t2code/t2codelib/SPIGOT/api/eco/T2Ceco.java

94 lines
3.9 KiB
Java

package net.t2code.t2codelib.SPIGOT.api.eco;
import com.bencodez.votingplugin.VotingPluginMain;
import net.t2code.t2codelib.SPIGOT.api.messages.T2Csend;
import net.t2code.t2codelib.SPIGOT.api.plugins.T2CpluginCheck;
import net.t2code.t2codelib.SPIGOT.system.T2CodeLibMain;
import net.t2code.t2codelib.SPIGOT.system.config.languages.SelectLibMsg;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
public class T2Ceco {
public static boolean moneyRemove(String prefix, Player player, Double price) {
if (vault(prefix, player)) {
return T2CodeLibMain.getEco().withdrawPlayer(player, price).transactionSuccess();
}
return false;
}
public static boolean moneyAdd(String prefix, Player player, Double price) {
if (vault(prefix, player)) {
return T2CodeLibMain.getEco().depositPlayer(player, price).transactionSuccess();
}
return false;
}
private static boolean vault(String prefix, Player player) {
if (T2CodeLibMain.getEco() == null) {
if (Bukkit.getPluginManager().getPlugin("Vault") == null) {
T2Csend.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, ItemStack itemStack, int amount) {
for (int i = 0; i < amount; i++) {
if (player.getInventory().firstEmpty() != -1) {
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 VotingPluginMain.getPlugin().getVotingPluginUserManager().getVotingPluginUser(player).removePoints(amount);
} else return false;
}
public static boolean votePointsAdd(String prefix, Player player, Integer amount) {
if (votePlugin(prefix, player)) {
Bukkit.getScheduler().runTaskAsynchronously(T2CodeLibMain.getPlugin(), new Runnable() {
@Override
public void run() {
VotingPluginMain.getPlugin().getVotingPluginUserManager().getVotingPluginUser(player).addPoints(amount);
}
});
return true;
} else return false;
}
private static boolean votePlugin(String prefix, Player player) {
if (T2CpluginCheck.votingPlugin()) return true;
T2Csend.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;
}
}