Created
August 30, 2016 05:13
-
-
Save anonymous/37adcb961d171c6dccb791e5cdbb05d6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.Sapphire.SapphireCore.Commands; | |
import java.util.ArrayList; | |
import org.bukkit.Material; | |
import org.bukkit.Sound; | |
import org.bukkit.command.Command; | |
import org.bukkit.command.CommandExecutor; | |
import org.bukkit.command.CommandSender; | |
import org.bukkit.entity.Player; | |
import org.bukkit.inventory.ItemStack; | |
import org.bukkit.inventory.meta.ItemMeta; | |
import com.Sapphire.SapphireCore.Main; | |
import net.md_5.bungee.api.ChatColor; | |
public class Withdraw implements CommandExecutor { | |
Main plugin; | |
public Withdraw(Main plugin) { | |
this.plugin = plugin; | |
} | |
@Override | |
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { | |
if (cmd.getName().equalsIgnoreCase("Withdraw")) { | |
if (!(sender instanceof Player)) { | |
sender.sendMessage( | |
ChatColor.translateAlternateColorCodes('&', plugin.getConfig().getString("Player-only"))); | |
} | |
if (sender instanceof Player) { | |
Player p = (Player) sender; | |
if (args.length == 0) { | |
p.sendMessage(ChatColor.translateAlternateColorCodes('&', | |
plugin.getConfig().getString("Invalid-Money-Amount"))); | |
return true; | |
} | |
if (args.length == 1) { | |
int amount = Integer.parseInt(args[0]); | |
String amountstring = amount + ""; | |
int max = plugin.getConfig().getInt("BankNote.Withdraw.Max"); | |
String maxamount = max - 1 + ""; | |
int min = plugin.getConfig().getInt("BankNote.Withdraw.Min"); | |
String minamount = min + ""; | |
if (amount <= plugin.getConfig().getInt("BankNote.Withdraw.Min")) { | |
p.sendMessage(ChatColor.translateAlternateColorCodes('&', | |
plugin.getConfig().getString("Min-Amount").replace("%MinAmount%", minamount))); | |
} | |
else if (amount >= plugin.getConfig().getInt("BankNote.Withdraw.Max")) { | |
p.sendMessage(ChatColor.translateAlternateColorCodes('&', | |
plugin.getConfig().getString("Max-Amount").replace("%MaxAmount%", maxamount))); | |
} | |
else if (amount <= plugin.getConfig().getInt("BankNote.Withdraw.Max") - 1 | |
&& amount > plugin.getConfig().getInt("BankNote.Withdraw.Min")) { | |
if (plugin.econ.getBalance(p) < amount) { | |
p.sendMessage(ChatColor.translateAlternateColorCodes('&', plugin.getConfig() | |
.getString("Withdrawed-Amount").replace("%WithdrawAmount%", amountstring))); | |
} | |
else { | |
ItemStack note = new ItemStack( | |
Material.getMaterial(plugin.getConfig().getString("BankNote.Item").toUpperCase())); | |
ItemMeta notemeta = note.getItemMeta(); | |
// Name | |
notemeta.setDisplayName(ChatColor.translateAlternateColorCodes('&', plugin.getConfig() | |
.getString("BankNote.Name").replace("%PlayerName%", p.getName()))); | |
// Lore | |
ArrayList<String> notelore = new ArrayList<String>(); | |
for (String lorelist : plugin.getConfig().getStringList("BankNote.Lore")) { | |
notelore.add(ChatColor.translateAlternateColorCodes('&', | |
lorelist.replace("%PlayerName%", p.getName()))); | |
} | |
notelore.add("§6Amount:§a " + amount); | |
// Set | |
notemeta.setLore(notelore); | |
note.setItemMeta(notemeta); | |
plugin.econ.withdrawPlayer(p, amount); | |
p.playSound(p.getLocation(), Sound.BAT_TAKEOFF, 1.0F, 2.0F); | |
p.sendMessage(ChatColor.translateAlternateColorCodes('&', plugin.getConfig() | |
.getString("Withdrawed-Amount").replace("%WithdrawAmount%", amountstring))); | |
p.getInventory().addItem(note); | |
} | |
} | |
return true; | |
} | |
} | |
} | |
return true; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment