Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package me.acemen.core.Object;
- import java.text.ParseException;
- import java.text.SimpleDateFormat;
- import java.util.ArrayList;
- import java.util.Date;
- import java.util.GregorianCalendar;
- import java.util.HashMap;
- import java.util.List;
- import java.util.UUID;
- import org.bukkit.entity.Player;
- import org.bukkit.permissions.PermissionAttachment;
- import me.acemen.core.Main;
- import me.acemen.core.API.CMySQL;
- import me.acemen.core.API.Eco;
- import me.acemen.core.Data.DataManager;
- import me.acemen.core.Enums.DataBase;
- import me.acemen.core.Object.Utils.UtilsCUser;
- import me.acemen.core.Object.Utils.UtilsGroup;
- import me.acemen.core.Tools.Utils;
- public class CUser {
- private int id;
- private String name, displayNick, password, email, ctag, chat;
- private UUID uuid;
- private Player player;
- private double money, multiple, zlotowki;
- private Group group, xpgroup;
- private Date expire;
- private List<String> colors;
- public CUser(Player p) {
- this.player = p;
- this.name = p.getName();
- this.uuid = p.getUniqueId();
- List<HashMap<String, String>> r = CMySQL.QueryResult(DataBase.CROSS.toString(), "SELECT * FROM auth WHERE uuid='" + p.getUniqueId() + "'");
- if (!r.isEmpty()) {
- HashMap<String, String> rs = r.get(0);
- this.password = rs.get("password");
- this.email = rs.get("email");
- this.id = Integer.valueOf(rs.get("id"));
- }else {
- CMySQL.QueryUpLoad(DataBase.CROSS.toString(), "INSERT INTO auth(id, name, uuid, password, email, ip) VALUES (NULL,'" + p.getName() + "','" + p.getUniqueId() + "',NULL,NULL,NULL)");
- List<HashMap<String, String>> r2 = CMySQL.QueryResult(DataBase.CROSS.toString(), "SELECT * FROM auth WHERE uuid='" + p.getUniqueId() + "'");
- HashMap<String, String> rs = r2.get(0);
- this.password = rs.get("password");
- this.email = rs.get("email");
- this.id = Integer.valueOf(rs.get("id"));
- }
- r = CMySQL.QueryResult(DataBase.CROSS.toString(), "SELECT * FROM users_colors WHERE user='" + id + "'");
- if (!r.isEmpty()) {
- HashMap<String, String> rs = r.get(0);
- this.displayNick = rs.get("nick");
- this.chat = rs.get("chat");
- this.colors = new ArrayList<String>();
- p.setDisplayName(Utils.colored("&" + this.displayNick + name));
- p.setPlayerListName(this.group.getPrefix() + " " + Utils.colored("&" + this.displayNick + name + "§r"));
- for(String s : rs.get("hasColors").split(":")) {
- colors.add(s);
- }
- }
- r = CMySQL.QueryResult(DataBase.CROSS.toString(), "SELECT * FROM users_ranks WHERE user='" + id + "'");
- if (!r.isEmpty()) {
- HashMap<String, String> rs = r.get(0);
- this.group = UtilsGroup.getGroup(Integer.valueOf(rs.get("rank")));
- }else {
- this.group = UtilsGroup.getGroup(0);
- }
- DownloadZlotowki();
- r = CMySQL.QueryResult(DataBase.CROSS.toString(), "SELECT * FROM users_xprank WHERE user='" + id + "'");
- if (!r.isEmpty()) {
- HashMap<String, String> rs = r.get(0);
- if (!CMySQL.NullDetector(rs.get("expire")).equalsIgnoreCase("null")) {
- this.xpgroup = UtilsGroup.getGroup(Integer.valueOf(rs.get("rank")));
- SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
- try {
- this.expire = formatter.parse(rs.get("expire").substring(0, 19));
- } catch (ParseException e) {
- e.printStackTrace();
- }
- }else if(Integer.valueOf(rs.get("rank")) != 0) {
- this.xpgroup = UtilsGroup.getGroup(Integer.valueOf(rs.get("rank")));
- this.expire = null;
- }
- }
- recalculateMultiple();
- refreshName();
- UtilsCUser.addCUser(this);
- recalculatePerms();
- }
- public void DownloadZlotowki() {
- List<HashMap<String, String>> r = CMySQL.QueryResult(DataBase.CROSS.toString(), "SELECT * FROM users_money WHERE id='" + id + "'");
- if (!r.isEmpty()) {
- HashMap<String, String> rs = r.get(0);
- this.zlotowki = Double.valueOf(rs.get("money"));
- }
- }
- public void recalculateMultiple() {
- multiple = group.getXppercent();
- if (xpgroup != null) multiple += xpgroup.getXppercent();
- }
- public void remove() {
- if (CMySQL.NullDetector(password).equalsIgnoreCase("NULL")) {
- UtilsCUser.removeCUser(this);
- return;
- }
- String expiree = "";
- if (expire == null) {
- expiree = "NULL";
- } else {
- GregorianCalendar calendar = new GregorianCalendar();
- SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
- calendar.setTime(expire);
- expiree = "'" + format.format(calendar.getTime()) + "'";
- }
- CMySQL.QueryUpLoad(DataBase.CROSS.toString(), "INSERT INTO auth(id, name, uuid, password, email, ip) VALUES ('" + id + "','" + name + "','" + uuid + "','" + password + "','" + email + "','" + player.getAddress().getHostString() + "') ON DUPLICATE KEY UPDATE password='" + password + "', email='" + email + "', ip='" + player.getAddress().getHostString() + "'");
- if(group.getId() != 0) CMySQL.QueryUpLoad(DataBase.CROSS.toString(), "INSERT INTO users_ranks(user, rank) VALUES ('" + id + "','" + group.getId() + "') ON DUPLICATE KEY UPDATE rank='" + group.getId()+"';");
- if(xpgroup != null) {
- CMySQL.QueryUpLoad(DataBase.CROSS.toString(), "INSERT INTO users_xprank(user, rank, expire) VALUES ('" + id + "','" + xpgroup.getId() + "'," + expiree + ") ON DUPLICATE KEY UPDATE rank='" + xpgroup.getId()+"', expire=" + expiree);
- }
- UtilsCUser.removeCUser(this);
- }
- public void refreshName() {
- if(player == null) return;
- if(this.displayNick != null && !this.displayNick.equalsIgnoreCase("")) {
- player.setDisplayName(Utils.colored("&" + this.displayNick + name + "§r"));
- player.setPlayerListName(this.group.getPrefix() + " " + Utils.colored("&" + this.displayNick + name + "§r"));
- }else {
- player.setPlayerListName(this.group.getPrefix() + " §r" + player.getName());
- }
- }
- public void takeCoins(double i) {
- Eco.takeMoney(this, i);
- }
- public void addCoins(double i) {
- Eco.addMoney(this, i);
- }
- public void addGameCoins(double i) {
- Eco.addGameCoins(this, i);
- }
- public double getCoins() {
- return Eco.getMoney(this);
- }
- public void sendMessage(String message) {
- player.sendMessage(message);
- }
- public int getId() {
- return id;
- }
- public void setId(int id) {
- this.id = id;
- }
- public String getName() {
- return name;
- }
- public void setName(String name) {
- this.name = name;
- }
- public UUID getUuid() {
- return uuid;
- }
- public void setUuid(UUID uuid) {
- this.uuid = uuid;
- }
- public Player getPlayer() {
- return player;
- }
- public void setPlayer(Player player) {
- this.player = player;
- }
- public double getMoney() {
- return money;
- }
- public void setMoney(double money) {
- this.money = money;
- }
- public String getDisplayNick() {
- if(this.displayNick != null) return Utils.colored("&" + this.displayNick + name + "&r");
- return name;
- }
- public void setDisplayNick(String displayNick) {
- this.displayNick = displayNick;
- refreshName();
- }
- public Group getGroup() {
- return group;
- }
- public void setGroup(Group group) {
- this.group = group;
- refreshName();
- recalculatePerms();
- }
- public void recalculatePerms() {
- PermissionAttachment attachment = this.player.addAttachment(Main.getInst());
- for (String s : this.group.getPerms()) {
- attachment.setPermission(s, true);
- }
- DataManager.perms.put(this.player.getUniqueId(), attachment);
- }
- public Group getXpgroup() {
- return xpgroup;
- }
- public void setXpgroup(Group xpgroup) {
- this.xpgroup = xpgroup;
- refreshName();
- recalculatePerms();
- }
- public Date getExpire() {
- return expire;
- }
- public void setExpire(Date expire) {
- this.expire = expire;
- }
- public double getMultiple() {
- return multiple;
- }
- public void setMultiple(double multiple) {
- this.multiple = multiple;
- }
- public String getPassword() {
- return password;
- }
- public void setPassword(String password) {
- this.password = password;
- }
- public String getEmail() {
- return email;
- }
- public void setEmail(String email) {
- this.email = email;
- }
- public String getCtag() {
- return ctag;
- }
- public void setCtag(String ctag) {
- this.ctag = ctag;
- }
- public String getChat() {
- return chat;
- }
- public void setChat(String chat) {
- this.chat = chat;
- }
- public List<String> getColors() {
- return colors;
- }
- public void setColors(List<String> colors) {
- this.colors = colors;
- }
- public double getZlotowki() {
- return zlotowki;
- }
- public void addZlotowki(double zl) {
- CMySQL.QueryUpLoad(DataBase.CROSS.toString(), "INSERT INTO users_money(id, money) VALUES ('" + id + "','" + zl + "') ON DUPLICATE KEY UPDATE money=money+" + zl + ";");
- DownloadZlotowki();
- }
- public void takeZlotowki(double zl) {
- CMySQL.QueryUpLoad(DataBase.CROSS.toString(), "INSERT INTO users_money(id, money) VALUES ('" + id + "','" + (-zl) + "') ON DUPLICATE KEY UPDATE money=money-" + zl + ";");
- DownloadZlotowki();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement