Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package lobby.coinsystem;
- 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 lobby.main.Main;
- public class EconomySystem implements CommandExecutor{
- @Override
- public boolean onCommand(CommandSender sender, Command command, String lable, String[] args) {
- Player p = (Player)sender;
- if(args.length == 0) {
- p.sendMessage(Main.prefix + "§c§l Du hast §f§l[" + getMoney(p.getName()) + "]§c§l Coins");
- } else if(args.length == 3) {
- if(p.hasPermission("example.coins")) {
- if(args[0].equalsIgnoreCase("add")) {
- String target = args[1];
- Integer amount = Integer.valueOf(args[2]);
- addMoney(target, amount);
- p.sendMessage(Main.prefix + "§c§l Du hast dem Spieler "+target+" §f§l[" +amount+"]§c§l Coins zu seinem Guthaben hinzugefügt , Der Spieler hat jetzt "+getMoney(target)+ " Coins !" );
- } else if(args[0].equalsIgnoreCase("remove")) {
- String target = args[1];
- Integer amount = Integer.valueOf(args[2]);
- removeMoney(target, amount);
- p.sendMessage(Main.prefix + "§c§l Du hast dem Spieler "+target+" §f§l[" +amount+"]§c§l Coins vom Guthaben entfernt , Der Spieler hat jetzt §f§l["+getMoney(target)+ "§c§L Coins !" );
- } else if(args[0].equalsIgnoreCase("set")) {
- String target = args[1];
- Integer amount = Integer.valueOf(args[2]);
- setMoney(target, amount);
- p.sendMessage(Main.prefix + "§c§l Du hast dem Spieler "+target+" Das Guthaben auf §f§l[" +amount+"]§c§l gesetzt !" );
- }
- } else {
- p.sendMessage(Main.prefix + "§c§l Dazu hast du keine Rechte ! ");
- }
- }else {
- p.sendMessage(Main.prefix + "§c§l Falsche verwendung! Bitte benutze /coins add/remove/set (SpielerName) (zahl) ");
- }
- return true;
- }
- public Integer getMoney(String name) {
- File file = new File("plugins/baastizockt", "money.yml");
- FileConfiguration cfg = YamlConfiguration.loadConfiguration(file);
- int money = cfg.getInt(name + ".money");
- return money;
- }
- public static void addMoney(String name, int amount) {
- File file = new File("plugins/baastizockt", "money.yml");
- FileConfiguration cfg = YamlConfiguration.loadConfiguration(file);
- int money = cfg.getInt(name + ".money");
- money=money+amount;
- cfg.set(name + ".money" , money);
- try {
- cfg.save(file);
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- public void removeMoney(String name, int amount) {
- File file = new File("plugins/baastizockt", "money.yml");
- FileConfiguration cfg = YamlConfiguration.loadConfiguration(file);
- int money = cfg.getInt(name + ".money");
- money=money-amount;
- cfg.set(name + ".money" , money);
- try {
- cfg.save(file);
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- public void setMoney(String name, int amount) {
- File file = new File("plugins/baastizockt", "money.yml");
- FileConfiguration cfg = YamlConfiguration.loadConfiguration(file);
- cfg.set(name + ".money" , amount);
- try {
- cfg.save(file);
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- public boolean hasEnoughMoney(String name, int amount) {
- File file = new File("plugins/baastizockt", "money.yml");
- FileConfiguration cfg = YamlConfiguration.loadConfiguration(file);
- int money = cfg.getInt(name + ".money");
- if(money >=amount) {
- return true;
- } else
- return false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement