PageRenderTime 66ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/src/com/gmail/nossr50/skills/Skills.java

https://github.com/krinsdeath/mcMMO
Java | 409 lines | 364 code | 22 blank | 23 comment | 120 complexity | 12ca09dd55641c30d2ce8edc8c6edb99 MD5 | raw file
  1. package com.gmail.nossr50.skills;
  2. import java.util.logging.Logger;
  3. import org.bukkit.ChatColor;
  4. import org.bukkit.entity.Entity;
  5. import org.bukkit.entity.Player;
  6. import org.bukkit.inventory.ItemStack;
  7. import org.getspout.spoutapi.SpoutManager;
  8. import org.getspout.spoutapi.player.SpoutPlayer;
  9. import com.gmail.nossr50.Leaderboard;
  10. import com.gmail.nossr50.Users;
  11. import com.gmail.nossr50.m;
  12. import com.gmail.nossr50.mcMMO;
  13. import com.gmail.nossr50.mcPermissions;
  14. import com.gmail.nossr50.config.LoadProperties;
  15. import com.gmail.nossr50.spout.SpoutStuff;
  16. import com.gmail.nossr50.datatypes.PlayerProfile;
  17. import com.gmail.nossr50.datatypes.PlayerStat;
  18. import com.gmail.nossr50.datatypes.SkillType;
  19. import com.gmail.nossr50.locale.mcLocale;
  20. public class Skills
  21. {
  22. protected static final Logger log = Logger.getLogger("Minecraft");
  23. public void updateSQLfromFile(Player player){
  24. }
  25. public static boolean cooldownOver(Player player, long oldTime, int cooldown){
  26. long currentTime = System.currentTimeMillis();
  27. if(currentTime - oldTime >= (cooldown * 1000)){
  28. return true;
  29. } else {
  30. return false;
  31. }
  32. }
  33. public boolean hasArrows(Player player){
  34. for(ItemStack x : player.getInventory().getContents()){
  35. if (x.getTypeId() == 262){
  36. return true;
  37. }
  38. }
  39. return false;
  40. }
  41. public void addArrows(Player player){
  42. for(ItemStack x : player.getInventory().getContents()){
  43. if (x.getTypeId() == 262){
  44. x.setAmount(x.getAmount() + 1);
  45. return;
  46. }
  47. }
  48. }
  49. public static int calculateTimeLeft(Player player, long deactivatedTimeStamp, int cooldown)
  50. {
  51. return (int) (((deactivatedTimeStamp + (cooldown * 1000)) - System.currentTimeMillis())/1000);
  52. }
  53. public static void watchCooldowns(Player player){
  54. PlayerProfile PP = Users.getProfile(player);
  55. if(!PP.getGreenTerraInformed() && System.currentTimeMillis() - (PP.getGreenTerraDeactivatedTimeStamp()*1000) >= (LoadProperties.greenTerraCooldown * 1000)){
  56. PP.setGreenTerraInformed(true);
  57. player.sendMessage(mcLocale.getString("Skills.YourGreenTerra"));
  58. }
  59. if(!PP.getTreeFellerInformed() && System.currentTimeMillis() - (PP.getTreeFellerDeactivatedTimeStamp()*1000) >= (LoadProperties.greenTerraCooldown * 1000)){
  60. PP.setTreeFellerInformed(true);
  61. player.sendMessage(mcLocale.getString("Skills.YourTreeFeller"));
  62. }
  63. if(!PP.getSuperBreakerInformed() && System.currentTimeMillis() - (PP.getSuperBreakerDeactivatedTimeStamp()*1000) >= (LoadProperties.superBreakerCooldown * 1000)){
  64. PP.setSuperBreakerInformed(true);
  65. player.sendMessage(mcLocale.getString("Skills.YourSuperBreaker"));
  66. }
  67. if(!PP.getSerratedStrikesInformed() && System.currentTimeMillis() - (PP.getSerratedStrikesDeactivatedTimeStamp()*1000) >= (LoadProperties.serratedStrikeCooldown * 1000)){
  68. PP.setSerratedStrikesInformed(true);
  69. player.sendMessage(mcLocale.getString("Skills.YourSerratedStrikes"));
  70. }
  71. if(!PP.getBerserkInformed() && System.currentTimeMillis() - (PP.getBerserkDeactivatedTimeStamp()*1000) >= (LoadProperties.berserkCooldown * 1000)){
  72. PP.setBerserkInformed(true);
  73. player.sendMessage(mcLocale.getString("Skills.YourBerserk"));
  74. }
  75. if(!PP.getSkullSplitterInformed() && System.currentTimeMillis() - (PP.getSkullSplitterDeactivatedTimeStamp()*1000) >= (LoadProperties.skullSplitterCooldown * 1000)){
  76. PP.setSkullSplitterInformed(true);
  77. player.sendMessage(mcLocale.getString("Skills.YourSkullSplitter"));
  78. }
  79. if(!PP.getGigaDrillBreakerInformed() && System.currentTimeMillis() - (PP.getGigaDrillBreakerDeactivatedTimeStamp()*1000) >= (LoadProperties.gigaDrillBreakerCooldown * 1000)){
  80. PP.setGigaDrillBreakerInformed(true);
  81. player.sendMessage(mcLocale.getString("Skills.YourGigaDrillBreaker"));
  82. }
  83. }
  84. public static void hoeReadinessCheck(Player player)
  85. {
  86. PlayerProfile PP = Users.getProfile(player);
  87. if(mcPermissions.getInstance().herbalismAbility(player) && m.isHoe(player.getItemInHand()) && !PP.getHoePreparationMode()){
  88. if(!PP.getGreenTerraMode() && !cooldownOver(player, (PP.getGreenTerraDeactivatedTimeStamp()*1000), LoadProperties.greenTerraCooldown)){
  89. player.sendMessage(mcLocale.getString("Skills.TooTired")
  90. +ChatColor.YELLOW+" ("+calculateTimeLeft(player, (PP.getGreenTerraDeactivatedTimeStamp()*1000), LoadProperties.greenTerraCooldown)+"s)");
  91. return;
  92. }
  93. player.sendMessage(mcLocale.getString("Skills.ReadyHoe"));
  94. PP.setHoePreparationATS(System.currentTimeMillis());
  95. PP.setHoePreparationMode(true);
  96. }
  97. }
  98. public static void monitorSkills(Player player){
  99. PlayerProfile PP = Users.getProfile(player);
  100. if(PP != null)
  101. {
  102. if(PP.getHoePreparationMode() && System.currentTimeMillis() - (PP.getHoePreparationATS()*1000) >= 4000){
  103. PP.setHoePreparationMode(false);
  104. player.sendMessage(mcLocale.getString("Skills.LowerHoe"));
  105. }
  106. if(PP.getAxePreparationMode() && System.currentTimeMillis() - (PP.getAxePreparationATS()*1000) >= 4000){
  107. PP.setAxePreparationMode(false);
  108. player.sendMessage(mcLocale.getString("Skills.LowerAxe"));
  109. }
  110. if(PP.getPickaxePreparationMode() && System.currentTimeMillis() - (PP.getPickaxePreparationATS()*1000) >= 4000){
  111. PP.setPickaxePreparationMode(false);
  112. player.sendMessage(mcLocale.getString("Skills.LowerPickAxe"));
  113. }
  114. if(PP.getSwordsPreparationMode() && System.currentTimeMillis() - (PP.getSwordsPreparationATS()*1000) >= 4000){
  115. PP.setSwordsPreparationMode(false);
  116. player.sendMessage(mcLocale.getString("Skills.LowerSword"));
  117. }
  118. if(PP.getFistsPreparationMode() && System.currentTimeMillis() - (PP.getFistsPreparationATS()*1000) >= 4000){
  119. PP.setFistsPreparationMode(false);
  120. player.sendMessage(mcLocale.getString("Skills.LowerFists"));
  121. }
  122. if(PP.getShovelPreparationMode() && System.currentTimeMillis() - (PP.getShovelPreparationATS()*1000) >= 4000){
  123. PP.setShovelPreparationMode(false);
  124. player.sendMessage(mcLocale.getString("Skills.LowerShovel"));
  125. }
  126. /*
  127. * HERBALISM ABILITY
  128. */
  129. if(mcPermissions.getInstance().herbalismAbility(player)){
  130. if(PP.getGreenTerraMode() && (PP.getGreenTerraDeactivatedTimeStamp()*1000) <= System.currentTimeMillis()){
  131. PP.setGreenTerraMode(false);
  132. PP.setGreenTerraInformed(false);
  133. player.sendMessage(mcLocale.getString("Skills.GreenTerraOff"));
  134. }
  135. }
  136. /*
  137. * AXES ABILITY
  138. */
  139. if(mcPermissions.getInstance().axesAbility(player)){
  140. if(PP.getSkullSplitterMode() && (PP.getSkullSplitterDeactivatedTimeStamp()*1000) <= System.currentTimeMillis()){
  141. PP.setSkullSplitterMode(false);
  142. PP.setSkullSplitterInformed(false);
  143. player.sendMessage(mcLocale.getString("Skills.SkullSplitterOff"));
  144. }
  145. }
  146. /*
  147. * WOODCUTTING ABILITY
  148. */
  149. if(mcPermissions.getInstance().woodCuttingAbility(player)){
  150. if(PP.getTreeFellerMode() && (PP.getTreeFellerDeactivatedTimeStamp()*1000) <= System.currentTimeMillis()){
  151. PP.setTreeFellerMode(false);
  152. PP.setTreeFellerInformed(false);
  153. player.sendMessage(mcLocale.getString("Skills.TreeFellerOff"));
  154. }
  155. }
  156. /*
  157. * MINING ABILITY
  158. */
  159. if(mcPermissions.getInstance().miningAbility(player)){
  160. if(PP.getSuperBreakerMode() && (PP.getSuperBreakerDeactivatedTimeStamp()*1000) <= System.currentTimeMillis()){
  161. PP.setSuperBreakerMode(false);
  162. PP.setSuperBreakerInformed(false);
  163. player.sendMessage(mcLocale.getString("Skills.SuperBreakerOff"));
  164. }
  165. }
  166. /*
  167. * EXCAVATION ABILITY
  168. */
  169. if(mcPermissions.getInstance().excavationAbility(player)){
  170. if(PP.getGigaDrillBreakerMode() && (PP.getGigaDrillBreakerDeactivatedTimeStamp()*1000) <= System.currentTimeMillis()){
  171. PP.setGigaDrillBreakerMode(false);
  172. PP.setGigaDrillBreakerInformed(false);
  173. player.sendMessage(mcLocale.getString("Skills.GigaDrillBreakerOff"));
  174. }
  175. }
  176. /*
  177. * SWORDS ABILITY
  178. */
  179. if(mcPermissions.getInstance().swordsAbility(player)){
  180. if(PP.getSerratedStrikesMode() && (PP.getSerratedStrikesDeactivatedTimeStamp()*1000) <= System.currentTimeMillis()){
  181. PP.setSerratedStrikesMode(false);
  182. PP.setSerratedStrikesInformed(false);
  183. player.sendMessage(mcLocale.getString("Skills.SerratedStrikesOff"));
  184. }
  185. }
  186. /*
  187. * UNARMED ABILITY
  188. */
  189. if(mcPermissions.getInstance().unarmedAbility(player)){
  190. if(PP.getBerserkMode() && (PP.getBerserkDeactivatedTimeStamp()*1000) <= System.currentTimeMillis()){
  191. PP.setBerserkMode(false);
  192. PP.setBerserkInformed(false);
  193. player.sendMessage(mcLocale.getString("Skills.BerserkOff"));
  194. }
  195. }
  196. }
  197. }
  198. public static void abilityActivationCheck(Player player)
  199. {
  200. PlayerProfile PP = Users.getProfile(player);
  201. if(PP != null)
  202. {
  203. if(!PP.getAbilityUse())
  204. return;
  205. if(mcPermissions.getInstance().miningAbility(player) && m.isMiningPick(player.getItemInHand()) && !PP.getPickaxePreparationMode())
  206. {
  207. if(!PP.getSuperBreakerMode() && !cooldownOver(player, (PP.getSuperBreakerDeactivatedTimeStamp()*1000), LoadProperties.superBreakerCooldown))
  208. {
  209. player.sendMessage(mcLocale.getString("Skills.TooTired")
  210. +ChatColor.YELLOW+" ("+calculateTimeLeft(player, (PP.getSuperBreakerDeactivatedTimeStamp()*1000), LoadProperties.superBreakerCooldown)+"s)");
  211. return;
  212. }
  213. player.sendMessage(mcLocale.getString("Skills.ReadyPickAxe"));
  214. PP.setPickaxePreparationATS(System.currentTimeMillis());
  215. PP.setPickaxePreparationMode(true);
  216. }
  217. if(mcPermissions.getInstance().excavationAbility(player) && m.isShovel(player.getItemInHand()) && !PP.getShovelPreparationMode())
  218. {
  219. if(!PP.getGigaDrillBreakerMode() && !cooldownOver(player, (PP.getGigaDrillBreakerDeactivatedTimeStamp()*1000), LoadProperties.gigaDrillBreakerCooldown))
  220. {
  221. player.sendMessage(mcLocale.getString("Skills.TooTired")
  222. +ChatColor.YELLOW+" ("+calculateTimeLeft(player, (PP.getGigaDrillBreakerDeactivatedTimeStamp()*1000), LoadProperties.gigaDrillBreakerCooldown)+"s)");
  223. return;
  224. }
  225. player.sendMessage(mcLocale.getString("Skills.ReadyShovel"));
  226. PP.setShovelPreparationATS(System.currentTimeMillis());
  227. PP.setShovelPreparationMode(true);
  228. }
  229. if(mcPermissions.getInstance().swordsAbility(player) && m.isSwords(player.getItemInHand()) && !PP.getSwordsPreparationMode())
  230. {
  231. if(!PP.getSerratedStrikesMode() && !cooldownOver(player, (PP.getSerratedStrikesDeactivatedTimeStamp()*1000), LoadProperties.serratedStrikeCooldown))
  232. {
  233. player.sendMessage(mcLocale.getString("Skills.TooTired")
  234. +ChatColor.YELLOW+" ("+calculateTimeLeft(player, (PP.getSerratedStrikesDeactivatedTimeStamp()*1000), LoadProperties.serratedStrikeCooldown)+"s)");
  235. return;
  236. }
  237. player.sendMessage(mcLocale.getString("Skills.ReadySword"));
  238. PP.setSwordsPreparationATS(System.currentTimeMillis());
  239. PP.setSwordsPreparationMode(true);
  240. }
  241. if(mcPermissions.getInstance().unarmedAbility(player) && player.getItemInHand().getTypeId() == 0 && !PP.getFistsPreparationMode())
  242. {
  243. if(!PP.getBerserkMode() && !cooldownOver(player, (PP.getBerserkDeactivatedTimeStamp()*1000), LoadProperties.berserkCooldown))
  244. {
  245. player.sendMessage(mcLocale.getString("Skills.TooTired")
  246. +ChatColor.YELLOW+" ("+calculateTimeLeft(player, (PP.getBerserkDeactivatedTimeStamp()*1000), LoadProperties.berserkCooldown)+"s)");
  247. return;
  248. }
  249. player.sendMessage(mcLocale.getString("Skills.ReadyFists"));
  250. PP.setFistsPreparationATS(System.currentTimeMillis());
  251. PP.setFistsPreparationMode(true);
  252. }
  253. if((mcPermissions.getInstance().axesAbility(player) || mcPermissions.getInstance().woodCuttingAbility(player)) && !PP.getAxePreparationMode())
  254. {
  255. if(m.isAxes(player.getItemInHand()))
  256. {
  257. player.sendMessage(mcLocale.getString("Skills.ReadyAxe"));
  258. PP.setAxePreparationATS(System.currentTimeMillis());
  259. PP.setAxePreparationMode(true);
  260. }
  261. }
  262. }
  263. }
  264. public static void ProcessLeaderboardUpdate(SkillType skillType, Player player)
  265. {
  266. PlayerProfile PP = Users.getProfile(player);
  267. PlayerStat ps = new PlayerStat();
  268. if(skillType != SkillType.ALL)
  269. ps.statVal = PP.getSkillLevel(skillType);
  270. else
  271. ps.statVal = m.getPowerLevel(player);
  272. ps.name = player.getName();
  273. Leaderboard.updateLeaderboard(ps, skillType);
  274. }
  275. public static void XpCheckSkill(SkillType skillType, Player player)
  276. {
  277. PlayerProfile PP = Users.getProfile(player);
  278. if(PP.getSkillXpLevel(skillType) >= PP.getXpToLevel(skillType))
  279. {
  280. int skillups = 0;
  281. while(PP.getSkillXpLevel(skillType) >= PP.getXpToLevel(skillType))
  282. {
  283. skillups++;
  284. PP.removeXP(skillType, PP.getXpToLevel(skillType));
  285. PP.skillUp(skillType, 1);
  286. }
  287. if(!LoadProperties.useMySQL)
  288. {
  289. ProcessLeaderboardUpdate(skillType, player);
  290. ProcessLeaderboardUpdate(SkillType.ALL, player);
  291. }
  292. String capitalized = m.getCapitalized(skillType.toString());
  293. //Contrib stuff
  294. if(LoadProperties.spoutEnabled && player instanceof SpoutPlayer)
  295. {
  296. SpoutPlayer sPlayer = SpoutManager.getPlayer(player);
  297. if(sPlayer.isSpoutCraftEnabled())
  298. {
  299. SpoutStuff.levelUpNotification(skillType, sPlayer);
  300. } else
  301. {
  302. player.sendMessage(mcLocale.getString("Skills."+capitalized+"Up", new Object[] {String.valueOf(skillups), PP.getSkillLevel(skillType)}));
  303. }
  304. }
  305. else
  306. player.sendMessage(mcLocale.getString("Skills."+capitalized+"Up", new Object[] {String.valueOf(skillups), PP.getSkillLevel(skillType)}));
  307. }
  308. if(LoadProperties.xpbar && LoadProperties.spoutEnabled)
  309. {
  310. SpoutPlayer sPlayer = SpoutManager.getPlayer(player);
  311. if(sPlayer.isSpoutCraftEnabled())
  312. {
  313. SpoutStuff.updateXpBar(sPlayer);
  314. }
  315. }
  316. }
  317. public static void XpCheckAll(Player player)
  318. {
  319. for(SkillType x : SkillType.values())
  320. {
  321. //Don't want to do anything with this one
  322. if(x == SkillType.ALL)
  323. continue;
  324. XpCheckSkill(x, player);
  325. }
  326. }
  327. public static SkillType getSkillType(String skillName)
  328. {
  329. for(SkillType x : SkillType.values())
  330. {
  331. if(x.toString().equals(skillName.toUpperCase()))
  332. return x;
  333. }
  334. return null;
  335. }
  336. public static boolean isSkill(String skillname){
  337. skillname = skillname.toUpperCase();
  338. for(SkillType x : SkillType.values())
  339. {
  340. if(x.toString().equals(skillname))
  341. return true;
  342. }
  343. return false;
  344. }
  345. public static void arrowRetrievalCheck(Entity entity, mcMMO plugin)
  346. {
  347. if(plugin.misc.arrowTracker.containsKey(entity))
  348. {
  349. Integer x = 0;
  350. while(x < plugin.misc.arrowTracker.get(entity))
  351. {
  352. m.mcDropItem(entity.getLocation(), 262);
  353. x++;
  354. }
  355. }
  356. plugin.misc.arrowTracker.remove(entity);
  357. }
  358. public static String getSkillStats(String skillname, Integer level, Integer XP, Integer XPToLevel)
  359. {
  360. ChatColor parColor = ChatColor.DARK_AQUA;
  361. ChatColor xpColor = ChatColor.GRAY;
  362. ChatColor LvlColor = ChatColor.GREEN;
  363. ChatColor skillColor = ChatColor.YELLOW;
  364. return skillColor+skillname+LvlColor+level+parColor+" XP"+"("+xpColor+XP+parColor+"/"+xpColor+XPToLevel+parColor+")";
  365. }
  366. public static boolean hasCombatSkills(Player player)
  367. {
  368. if(mcPermissions.getInstance().axes(player) || mcPermissions.getInstance().archery(player) || mcPermissions.getInstance().swords(player) || mcPermissions.getInstance().taming(player) || mcPermissions.getInstance().unarmed(player))
  369. return true;
  370. else
  371. return false;
  372. }
  373. public static boolean hasGatheringSkills(Player player)
  374. {
  375. if(mcPermissions.getInstance().excavation(player) || mcPermissions.getInstance().herbalism(player) || mcPermissions.getInstance().mining(player) || mcPermissions.getInstance().woodcutting(player))
  376. return true;
  377. else
  378. return false;
  379. }
  380. public static boolean hasMiscSkills(Player player)
  381. {
  382. if(mcPermissions.getInstance().acrobatics(player) || mcPermissions.getInstance().repair(player))
  383. return true;
  384. else
  385. return false;
  386. }
  387. }