Advertisement
Guest User

Untitled

a guest
Nov 21st, 2019
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 21.49 KB | None | 0 0
  1. package ru.meloncode.cristalix.prison;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.Collection;
  5. import java.util.HashMap;
  6. import java.util.Map;
  7.  
  8. import org.bukkit.Bukkit;
  9. import org.bukkit.ChatColor;
  10. import org.bukkit.Material;
  11. import org.bukkit.configuration.ConfigurationSection;
  12. import org.bukkit.entity.Player;
  13. import org.bukkit.inventory.Inventory;
  14. import org.bukkit.inventory.InventoryHolder;
  15. import org.bukkit.inventory.ItemStack;
  16. import org.bukkit.scheduler.BukkitRunnable;
  17. import org.bukkit.scoreboard.Objective;
  18. import org.bukkit.scoreboard.Scoreboard;
  19. import net.md_5.bungee.api.ChatMessageType;
  20. import net.md_5.bungee.api.chat.ComponentBuilder;
  21. import ru.luvas.bk.SimpleItemStack;
  22. import ru.meloncode.cristalix.prison.boosters.Booster;
  23. import ru.meloncode.cristalix.prison.boosters.BoosterType;
  24. import ru.meloncode.cristalix.prison.mobs.EntityTypes;
  25. import ru.meloncode.cristalix.prison.utils.StringUtils;
  26.  
  27. public class PrisonPlayer
  28. {
  29. private static Map<String, PrisonPlayer> players;
  30. private String name;
  31. int level;
  32. Map<Material, Integer> block_log;
  33. Map<EntityTypes, Integer> mob_log;
  34. Map<String, Integer> passives;
  35. Map<Achievement, Integer> achievements;
  36. ArrayList<String> accesses;
  37. Objective obj;
  38. int kills;
  39. boolean noPee;
  40. double exp;
  41. double shards;
  42. int deaths;
  43. boolean free;
  44. private Inventory enderChest;
  45. long lastkit;
  46. Faction faction;
  47. Scoreboard board;
  48. int totalblocks;
  49. double booster;
  50. private String lastDamager;
  51. private long lastDamagerHitTime;
  52. private double donateResourcesMultiplier;
  53. private double donateExpMultiplier;
  54. private double donateCrystalsMultiplier;
  55. private double donateshaftMultiplier;
  56. private double donateBlocksMultiplier;
  57.  
  58. private double resourcesMultiplier;
  59. private double expMultiplier;
  60. private double shaftMultiplier;
  61. private double shardMultiplier;
  62. private double blocksMultiplier;
  63.  
  64. static {
  65. PrisonPlayer.players = new HashMap<String, PrisonPlayer>();
  66. }
  67.  
  68. public void setLastDamager(final String lastDamager, final int i) {
  69. this.lastDamager = lastDamager;
  70. this.lastDamagerHitTime = System.currentTimeMillis() / 1000L;
  71. }
  72.  
  73. public String getLastDamager() {
  74. return (System.currentTimeMillis() / 1000L - this.lastDamagerHitTime <= 15L) ? this.lastDamager : null;
  75. }
  76.  
  77. public int getNextLevelPrice() {
  78. return Main.config.getInt("levels." + (this.level + 1) + ".money");
  79. }
  80.  
  81. public int getNextLevelBlockPrice() {
  82. return Main.config.getInt("levels." + (this.level + 1) + ".exp");
  83. }
  84.  
  85. public int getTPDelay() {
  86. final Player p = Bukkit.getPlayer(this.name);
  87. for (int i = 0; i <= 10; ++i) {
  88. if (p.hasPermission("prison.tpdelay" + i)) {
  89. return i * 20;
  90. }
  91. }
  92. return 80;
  93. }
  94.  
  95. public void addExp(final double amount) {
  96. this.exp += amount;
  97. }
  98.  
  99. public void addShards(final double amount) {
  100. this.shards += amount;
  101. }
  102.  
  103. public PrisonPlayer(final String name) {
  104. this.lastDamagerHitTime = -1L;
  105. this.name = name;
  106. this.level = 1;
  107. this.kills = 0;
  108. this.deaths = 0;
  109. this.booster = 1.0;
  110. this.shards = 0;
  111. this.exp = 0;
  112. this.noPee = false;
  113. this.accesses = new ArrayList<String>();
  114. this.block_log = new HashMap<Material, Integer>();
  115. this.mob_log = new HashMap<EntityTypes, Integer>();
  116. this.passives = new HashMap<String, Integer>();
  117. this.achievements = new HashMap<Achievement, Integer>();
  118. this.faction = null;
  119. int extraSlots = 0;
  120. for (int i = 0; i <= 18; ++i) {
  121. if (Bukkit.getPlayer(name).hasPermission("chest." + i)) {
  122. extraSlots = i;
  123. }
  124. }
  125. this.enderChest = Bukkit.createInventory((InventoryHolder)null, 45, "\u042d\u043d\u0434\u0435\u0440\u0421\u0443\u043d\u0434\u0443\u043a");
  126. for (int i = 27 + extraSlots; i < this.enderChest.getSize(); ++i) {
  127. this.enderChest.setItem(i, (ItemStack)new SimpleItemStack(Material.STAINED_GLASS_PANE, "&c\u0417\u0430\u043a\u0440\u044b\u0442\u043e", "&7\u041a\u0443\u043f\u0438\u0442\u0435 \u043d\u0430 \u0441\u0430\u0439\u0442\u0435", new Object[] { (short)7 }));
  128. }
  129. PrisonPlayer.players.put(name, this);
  130. initDonate();
  131. updateMultipliers();
  132. }
  133.  
  134. public int getAchievemntLevel(final Achievement achievement) {
  135. return this.achievements.getOrDefault(achievement, 0);
  136. }
  137.  
  138. public int setAchievemntLevel(final Achievement achievement, final int level) {
  139. return this.achievements.put(achievement, level);
  140. }
  141.  
  142. public PrisonPlayer(final String name, final ConfigurationSection info) {
  143. this.lastDamagerHitTime = -1L;
  144. this.name = name;
  145. this.level = info.getInt("level");
  146. this.kills = info.getInt("kills");
  147. this.deaths = info.getInt("deaths");
  148. this.totalblocks = info.getInt("total-blocks");
  149. this.shards = info.getInt("shards");
  150. this.exp = info.getInt("exp");
  151. this.noPee = info.getBoolean("noPee");
  152. this.booster = info.getDouble("booster");
  153. if (this.noPee) {
  154. Main.disable(name, true);
  155. }
  156. this.faction = Faction.getFaction(info.getString("faction"));
  157. if (info.contains("free")) {
  158. this.free = info.getBoolean("free");
  159. }
  160. this.accesses = new ArrayList<String>();
  161. if (info.contains("accesses")) {
  162. this.accesses = (ArrayList<String>)info.getStringList("accesses");
  163. }
  164. this.block_log = new HashMap<Material, Integer>();
  165. if (info.contains("block-log")) {
  166. final ConfigurationSection bl = info.getConfigurationSection("block-log");
  167. if (bl.getKeys(false).size() > 0) {
  168. for (final String cMaterial : bl.getKeys(false)) {
  169. this.block_log.put(Material.getMaterial(cMaterial), bl.getInt(cMaterial));
  170. }
  171. }
  172. }
  173. this.mob_log = new HashMap<EntityTypes, Integer>();
  174. if (info.contains("mob-log")) {
  175. final ConfigurationSection bl = info.getConfigurationSection("mob-log");
  176. if (bl.getKeys(false).size() > 0) {
  177. for (final String type : bl.getKeys(false)) {
  178. this.mob_log.put(EntityTypes.valueOf(type), bl.getInt(type));
  179. }
  180. }
  181. }
  182. this.achievements = new HashMap<Achievement, Integer>();
  183. if (info.contains("achievements")) {
  184. final ConfigurationSection bl = info.getConfigurationSection("achievements");
  185. if (bl.getKeys(false).size() > 0) {
  186. for (final String type : bl.getKeys(false)) {
  187. this.achievements.put(Achievement.getAchievement(Material.valueOf(type)), bl.getInt(type));
  188. }
  189. }
  190. }
  191. this.passives = new HashMap<String, Integer>();
  192. if (info.contains("passives")) {
  193. final ConfigurationSection bl = info.getConfigurationSection("passives");
  194. if (!bl.contains("Fortune")) {
  195. bl.set("Fortune", (Object)0);
  196. }
  197. if (!bl.contains("Curse")) {
  198. bl.set("Curse", (Object)0);
  199. }
  200. if (bl.getKeys(false).size() > 0) {
  201. for (final String type : bl.getKeys(false)) {
  202. this.passives.put(type, bl.getInt(type));
  203. }
  204. }
  205. }
  206. else {
  207. this.passives.put("Strength", 0);
  208. this.passives.put("Agility", 0);
  209. this.passives.put("Needs", 0);
  210. this.passives.put("Fortune", 0);
  211. this.passives.put("Curse", 0);
  212. }
  213. int extraSlots = 0;
  214. for (int i = 0; i <= 18; ++i) {
  215. if (Bukkit.getPlayer(name).hasPermission("chest." + i)) {
  216. extraSlots = i;
  217. }
  218. }
  219. (this.enderChest = Bukkit.createInventory((InventoryHolder)null, 45, "\u042d\u043d\u0434\u0435\u0440\u0421\u0443\u043d\u0434\u0443\u043a")).setContents(Utils.toStack(info.getString("enderchest")));
  220. for (int i = 27 + extraSlots; i < this.enderChest.getSize(); ++i) {
  221. this.enderChest.setItem(i, (ItemStack)new SimpleItemStack(Material.STAINED_GLASS_PANE, "&c\u0417\u0430\u043a\u0440\u044b\u0442\u043e", "&7\u041a\u0443\u043f\u0438\u0442\u0435 \u043d\u0430 \u0441\u0430\u0439\u0442\u0435", new Object[] { (short)7 }));
  222. }
  223. PrisonPlayer.players.put(name, this);
  224. initDonate();
  225. updateMultipliers();
  226. }
  227.  
  228. public int getExtraSlots() {
  229. int extraSlots = 0;
  230. for (int i = 0; i <= 18; ++i) {
  231. if (Bukkit.getPlayer(this.name).hasPermission("chest." + i)) {
  232. extraSlots = i;
  233. }
  234. }
  235. return extraSlots;
  236. }
  237.  
  238. public void save() {
  239. ConfigurationSection cPlayer;
  240. if (Main.players_storage.contains(this.name)) {
  241. cPlayer = Main.players_storage.getConfigurationSection(this.name);
  242. }
  243. else {
  244. cPlayer = Main.players_storage.createSection(this.name);
  245. }
  246. cPlayer.set("booster", (Object)this.booster);
  247. cPlayer.set("level", (Object)this.level);
  248. cPlayer.set("kills", (Object)this.kills);
  249. cPlayer.set("deaths", (Object)this.deaths);
  250. cPlayer.set("total-blocks", (Object)this.totalblocks);
  251. cPlayer.set("free", (Object)this.free);
  252. cPlayer.set("shards", (Object)this.shards);
  253. cPlayer.set("exp", (Object)this.exp);
  254. cPlayer.set("noPee", (Object)this.noPee);
  255. ConfigurationSection bLog = null;
  256. if (this.accesses != null && this.accesses.size() > 0) {
  257. cPlayer.set("accesses", (Object)this.accesses);
  258. }
  259. if (this.block_log != null && this.block_log.size() > 0) {
  260. if (cPlayer.contains("block-log")) {
  261. bLog = cPlayer.getConfigurationSection("block-log");
  262. }
  263. else {
  264. bLog = cPlayer.createSection("block-log");
  265. }
  266. if (this.block_log.size() > 0) {
  267. for (final Map.Entry<Material, Integer> entry : this.block_log.entrySet()) {
  268. bLog.set(entry.getKey().toString(), (Object)entry.getValue());
  269. }
  270. }
  271. }
  272. if (this.mob_log != null && this.mob_log.size() > 0) {
  273. if (cPlayer.contains("mob-log")) {
  274. bLog = cPlayer.getConfigurationSection("mob-log");
  275. }
  276. else {
  277. bLog = cPlayer.createSection("mob-log");
  278. }
  279. if (this.mob_log.size() > 0) {
  280. for (final Map.Entry<EntityTypes, Integer> entry2 : this.mob_log.entrySet()) {
  281. bLog.set(entry2.getKey().toString(), (Object)entry2.getValue());
  282. }
  283. }
  284. }
  285. if (this.achievements != null && this.achievements.size() > 0) {
  286. if (cPlayer.contains("achievements")) {
  287. bLog = cPlayer.getConfigurationSection("achievements");
  288. }
  289. else {
  290. bLog = cPlayer.createSection("achievements");
  291. }
  292. if (this.achievements.size() > 0) {
  293. for (final Map.Entry<Achievement, Integer> entry3 : this.achievements.entrySet()) {
  294. bLog.set(entry3.getKey().getMaterial().toString(), (Object)entry3.getValue());
  295. }
  296. }
  297. }
  298. if (this.passives != null && this.passives.size() > 0) {
  299. if (cPlayer.contains("passives")) {
  300. bLog = cPlayer.getConfigurationSection("passives");
  301. }
  302. else {
  303. bLog = cPlayer.createSection("passives");
  304. }
  305. if (this.passives.size() > 0) {
  306. for (final Map.Entry<String, Integer> entry4 : this.passives.entrySet()) {
  307. bLog.set(entry4.getKey().toString(), (Object)entry4.getValue());
  308. }
  309. }
  310. }
  311. else {
  312. if (cPlayer.contains("passives")) {
  313. bLog = cPlayer.getConfigurationSection("passives");
  314. }
  315. else {
  316. bLog = cPlayer.createSection("passives");
  317. }
  318. bLog.set("Strength", (Object)0);
  319. bLog.set("Agility", (Object)0);
  320. bLog.set("Needs", (Object)0);
  321. bLog.set("Fortune", (Object)0);
  322. bLog.set("Curse", (Object)0);
  323. }
  324. cPlayer.set("enderchest", (Object)Utils.toString(this.enderChest.getContents()));
  325. }
  326.  
  327. public static void loadPrisonPlayer(final Player player) {
  328. final String name = player.getName();
  329. if (Main.players_storage.contains(player.getName())) {
  330. final PrisonPlayer prisonPlayer = new PrisonPlayer(name, Main.players_storage.getConfigurationSection(name));
  331. }
  332. else {
  333. final PrisonPlayer pp = new PrisonPlayer(name);
  334. new BukkitRunnable() {
  335. public void run() {
  336. PrisonPlayer.giveStartKit(player);
  337. }
  338. }.runTaskLater(Main.getInstance(), 20L);
  339. pp.save();
  340. }
  341. }
  342.  
  343. public void initDonate() {
  344. if (getPlayer().hasPermission("jedi.prince")) {
  345. donateResourcesMultiplier += 0.1;
  346. donateExpMultiplier += 0.05;
  347. donateCrystalsMultiplier += 0.05;
  348. donateshaftMultiplier += 0.05;
  349. }
  350. if (getPlayer().hasPermission("jedi.lord")) {
  351. donateResourcesMultiplier += 0.1;
  352. donateExpMultiplier += 0.1;
  353. donateCrystalsMultiplier += 0.15;
  354. donateshaftMultiplier += 0.05;
  355. }
  356. if (getPlayer().hasPermission("jedi.graf")) {
  357. donateResourcesMultiplier += 0.1;
  358. donateExpMultiplier += 0.2;
  359. donateCrystalsMultiplier += 0.25;
  360. donateshaftMultiplier += 0.05;
  361. }
  362. if (getPlayer().hasPermission("jedi.viking")) {
  363. donateResourcesMultiplier += 0.1;
  364. donateExpMultiplier += 0.3;
  365. donateCrystalsMultiplier += 0.45;
  366. donateshaftMultiplier += 0.05;
  367. }
  368. if (getPlayer().hasPermission("jedi.king")) {
  369. donateResourcesMultiplier += 0.1;
  370. donateExpMultiplier += 0.45;
  371. donateCrystalsMultiplier += 0.6;
  372. donateshaftMultiplier += 0.05;
  373. }
  374. }
  375. public void updateMultipliers() {
  376. if (getPlayer() == null)
  377. return;
  378. blocksMultiplier = StringUtils.fixDouble(3, Main.GLOBAL_BLOCKS_MULTIPLIER + donateBlocksMultiplier + Booster.getGlobalMultiplier(BoosterType.BLOCKS) + Booster.getLocalMultiplier(BoosterType.BLOCKS, this));
  379. resourcesMultiplier = StringUtils.fixDouble(3, Main.GLOBAL_RESOURCES_MULTIPLIER + donateResourcesMultiplier + Booster.getGlobalMultiplier(BoosterType.MONEY) + Booster.getLocalMultiplier(BoosterType.MONEY, this));
  380. expMultiplier = StringUtils.fixDouble(3, Main.GLOBAL_EXP_MULTIPLIER + donateExpMultiplier + Booster.getGlobalMultiplier(BoosterType.EXP) + Booster.getLocalMultiplier(BoosterType.EXP, this));
  381. shaftMultiplier = StringUtils.fixDouble(100, Main.GLOBAL_SHAFT_MULTIPLIER + donateshaftMultiplier + Booster.getGlobalMultiplier(BoosterType.SHAFT) + Booster.getLocalMultiplier(BoosterType.SHAFT, this));
  382. shardMultiplier = StringUtils.fixDouble(3, Main.GLOBAL_SHARDS_MULTIPLIER + donateCrystalsMultiplier + Booster.getGlobalMultiplier(BoosterType.SHARD) + Booster.getLocalMultiplier(BoosterType.SHARD, this));
  383. }
  384. public static void giveStartKit(final Player player) {
  385. final Inventory inv = (Inventory)player.getInventory();
  386. if (Main.startItems.size() > 0 && PrisonItem.items.size() > 0) {
  387. for (final String cItem : Main.startItems) {
  388. inv.addItem(new ItemStack[] { PrisonItem.getPrisonItem(cItem).getUsableItem() });
  389. }
  390. }
  391. getPrisonPlayer(player).lastkit = System.currentTimeMillis() / 1000L / 60L;
  392. }
  393.  
  394. public static PrisonPlayer getPrisonPlayer(final Player player) {
  395. return PrisonPlayer.players.get(player.getName());
  396. }
  397.  
  398. public static PrisonPlayer getPrisonPlayer(String name)
  399. {
  400. return players.get(name);
  401. }
  402.  
  403. public int getLevel() {
  404. return this.level;
  405. }
  406.  
  407. public void levelUp() {
  408. ++this.level;
  409. this.save();
  410. }
  411.  
  412. public void setLevel(final int level) {
  413. this.level = level;
  414. this.save();
  415. }
  416.  
  417. public void unload() {
  418. this.save();
  419. Main.saveConfig(Main.players_storage, "players.yml");
  420. PrisonPlayer.players.remove(this.name);
  421. }
  422.  
  423. public void grantCellarAcess(final String name) {
  424. this.accesses.add(name);
  425. }
  426.  
  427. public boolean hasCellarAcess(final String name) {
  428. return this.accesses.contains(name);
  429. }
  430.  
  431. public double getBalance() {
  432. return Main.economy.getBalance(this.name);
  433. }
  434.  
  435. public boolean takeMoney(final int money) {
  436. if (this.hasMoney(money) && Main.economy.withdrawPlayer(this.name, (double)money).transactionSuccess()) {
  437. Bukkit.getPlayer(this.name).sendMessage(ChatColor.RED + "\u0421 \u0432\u0430\u0448\u0435\u0433\u043e \u0441\u0447\u0435\u0442\u0430 \u0431\u044b\u043b\u043e \u0441\u043f\u0438\u0441\u0430\u043d\u043e " + ChatColor.DARK_RED + money + "$");
  438. return true;
  439. }
  440. return false;
  441. }
  442.  
  443. public void giveMoney(final double money) {
  444. if (Bukkit.getPlayer(this.name) != null) {
  445. try {
  446. Bukkit.getPlayer(this.name).sendMessage(ChatColor.GREEN + "\u041d\u0430 \u0432\u0430\u0448 \u0441\u0447\u0435\u0442 \u0431\u044b\u043b\u043e \u0437\u0430\u0447\u0438\u0441\u043b\u0435\u043d\u043d\u043e " + ChatColor.GREEN + money + "$");
  447. Main.economy.depositPlayer(this.name, money);
  448. }
  449. catch (NullPointerException ex) {}
  450. }
  451. }
  452.  
  453. public void sellItems(final double money) {
  454. if (getPlayer() != null) {
  455. Player p = getPlayer();
  456. p.spigot().sendMessage(ChatMessageType.ACTION_BAR, new ComponentBuilder(ChatColor.WHITE + "Вы получили от продажи " + ChatColor.YELLOW + money * PrisonPlayer.getPrisonPlayer(p).getResourcesMultiplier() + "$").color(net.md_5.bungee.api.ChatColor.GOLD).create());
  457. Main.economy.depositPlayer(p.getName(), money * PrisonPlayer.getPrisonPlayer(p).getResourcesMultiplier());
  458. }
  459. }
  460. public boolean hasMoney(final int money) {
  461. return Main.economy.has(this.name, (double)money);
  462. }
  463.  
  464. public static Collection<PrisonPlayer> getAll() {
  465. return PrisonPlayer.players.values();
  466. }
  467.  
  468. public void addBlockDig(final Material material) {
  469. this.addBlockDig(material, 1);
  470. }
  471.  
  472. public void addBlockDig(final Material material, final int amount) {
  473. if (this.block_log.containsKey(material)) {
  474. this.block_log.put(material, this.block_log.get(material) + amount);
  475. }
  476. else {
  477. this.block_log.put(material, amount);
  478. }
  479. }
  480.  
  481. public int getBlockDigsCount(final Material material) {
  482. if (this.block_log.containsKey(material)) {
  483. return this.block_log.get(material);
  484. }
  485. return 0;
  486. }
  487.  
  488. public void addMobKill(final EntityTypes type) {
  489. if (this.mob_log.containsKey(type)) {
  490. this.mob_log.put(type, this.mob_log.get(type) + 1);
  491. }
  492. else {
  493. this.mob_log.put(type, 1);
  494. }
  495. }
  496.  
  497. public int getMobKillCount(final EntityTypes type) {
  498. if (this.mob_log.containsKey(type)) {
  499. return this.mob_log.get(type);
  500. }
  501. return 0;
  502. }
  503.  
  504. public int getKills() {
  505. return this.kills;
  506. }
  507.  
  508. public Map<String, Integer> getPassives() {
  509. return this.passives;
  510. }
  511.  
  512. public int getDeaths() {
  513. return this.deaths;
  514. }
  515.  
  516. public int getAdditionalDamage() {
  517. return Main.config.getInt("levels." + this.level + ".damage");
  518. }
  519.  
  520. public Scoreboard getScoreboard() {
  521. if (this.board == null) {
  522. this.board = Bukkit.getScoreboardManager().getNewScoreboard();
  523. }
  524. return this.board;
  525. }
  526.  
  527. public Faction getFaction() {
  528. return this.faction;
  529. }
  530.  
  531. public String getName() {
  532. return this.name;
  533. }
  534.  
  535. public void setFaction(final Faction faction) {
  536. this.faction = faction;
  537. Main.players_storage.getConfigurationSection(this.name).set("faction", (Object)((faction != null) ? faction.getId() : null));
  538. }
  539.  
  540. public boolean hasFaction() {
  541. return this.faction != null;
  542. }
  543.  
  544. public Player getPlayer()
  545. {
  546. return Bukkit.getPlayer(getName());
  547. }
  548.  
  549. public double getResourcesMultiplier() {
  550. return resourcesMultiplier;
  551. }
  552.  
  553. public boolean isFree() {
  554. return this.free;
  555. }
  556.  
  557. public double getShaftMultiplier() {
  558. return shaftMultiplier;
  559. }
  560. public double getCrystalsMultiplier() {
  561. return shardMultiplier;
  562. }
  563.  
  564. public double getExpMultiplier() {
  565. return expMultiplier;
  566. }
  567.  
  568. public String getLevelPercent() {
  569. int percent = (int) (exp / getNextLevelBlockPrice() * 100.0);
  570. String percentInfo = percent + "%";
  571. return percent < 33 ? "§c" + percentInfo : (percent < 66 ? "§e" + percentInfo : "§a" + percentInfo);
  572. }
  573.  
  574. public Inventory getEnderChest() {
  575. return this.enderChest;
  576. }
  577. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement