Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package eu.penguinpiz.slenderman.commands;
- import java.io.File;
- import java.io.IOException;
- import org.bukkit.command.Command;
- import org.bukkit.command.CommandExecutor;
- import org.bukkit.command.CommandSender;
- import org.bukkit.configuration.file.FileConfiguration;
- import org.bukkit.configuration.file.YamlConfiguration;
- import org.bukkit.entity.Player;
- import eu.penguinpiz.slenderman.main.Main;
- public class CoinSystem implements CommandExecutor{
- @Override
- public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
- Player p = (Player) sender;
- if(args.length == 0) {
- p.sendMessage(Main.PREFIX + "§7You Have §a" + getCoins(p.getName()));
- } else if(args.length == 3) {
- if(args[0].equalsIgnoreCase("add")) {
- if(p.hasPermission("sm.coind.add")) {
- String target = args[1];
- Integer amount = Integer.valueOf(args[2]);
- addCoins(target, amount);
- p.sendMessage(Main.PREFIX + "§7The Player §f" + target + " §aGot " + amount + " §f§lCoins");
- } else {
- p.sendMessage(Main.NO_PERMISSION);
- }
- }else if(args[0].equalsIgnoreCase("remove")) {
- if(p.hasPermission("sm.coind.remove")) {
- String target = args[1];
- Integer amount = Integer.valueOf(args[2]);
- removeCoins(target, amount);
- p.sendMessage(Main.PREFIX + "§7The Player §f" + target + " §cLost " + amount + " §f§lCoins");
- } else {
- p.sendMessage(Main.NO_PERMISSION);
- }
- } else if(args[0].equalsIgnoreCase("set")) {
- if(p.hasPermission("sm.coind.set")) {
- String target = args[1];
- Integer amount = Integer.valueOf(args[2]);
- setCoins(target, amount);
- p.sendMessage(Main.PREFIX + "§7The §f§lCoins §7of " + target + " §7were §aSet §7to " + amount);
- } else {
- p.sendMessage(Main.NO_PERMISSION);
- }
- } else {
- p.sendMessage(Main.PREFIX + "§7System §aOutDated§7! §7:D");
- }
- } else {
- p.sendMessage(Main.PREFIX + "§7System §aOutDated§7! §7:D");
- }
- return false;
- }
- public Integer getCoins(String name) {
- File file = new File("plugins/SlenderMan", "coins.yml");
- FileConfiguration cfg = YamlConfiguration.loadConfiguration(file);
- int coins = cfg.getInt(name + ".coins");
- return coins;
- }
- public void addCoins(String name, int amount) {
- File file = new File("plugins/SlenderMan", "coins.yml");
- FileConfiguration cfg = YamlConfiguration.loadConfiguration(file);
- int coins = cfg.getInt(name + ".coins");
- coins=coins+amount;
- cfg.set(name + ".coins", coins);
- try {
- cfg.save(file);
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- public void removeCoins(String name, int amount) {
- File file = new File("plugins/SlenderMan", "coins.yml");
- FileConfiguration cfg = YamlConfiguration.loadConfiguration(file);
- int coins = cfg.getInt(name + ".coins");
- coins=coins-amount;
- cfg.set(name + ".coins", coins);
- try {
- cfg.save(file);
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- public void setCoins(String name, int amount) {
- File file = new File("plugins/SlenderMan", "coins.yml");
- FileConfiguration cfg = YamlConfiguration.loadConfiguration(file);
- cfg.set(name + ".coins", amount);
- try {
- cfg.save(file);
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- public boolean hasCoins(String name, int amount) {
- File file = new File("plugins/SlenderMan", "coins.yml");
- FileConfiguration cfg = YamlConfiguration.loadConfiguration(file);
- int coins = cfg.getInt(name + ".coins");
- if(coins >= amount) {
- removeCoins(name, amount);
- return true;
- } else
- return false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement