Advertisement
Guest User

Untitled

a guest
Feb 8th, 2018
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.08 KB | None | 0 0
  1. package loretest;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.HashMap;
  5. import java.util.List;
  6. import java.util.Map;
  7. import java.util.regex.Matcher;
  8. import java.util.regex.Pattern;
  9.  
  10. import org.apache.commons.lang.StringUtils;
  11. import org.bukkit.Bukkit;
  12. import org.bukkit.Material;
  13. import org.bukkit.Server;
  14. import org.bukkit.command.Command;
  15. import org.bukkit.command.CommandSender;
  16. import org.bukkit.configuration.MemorySection;
  17. import org.bukkit.configuration.file.FileConfiguration;
  18. import org.bukkit.configuration.file.FileConfigurationOptions;
  19. import org.bukkit.entity.Player;
  20. import org.bukkit.event.HandlerList;
  21. import org.bukkit.inventory.ItemStack;
  22. import org.bukkit.inventory.meta.ItemMeta;
  23. import org.bukkit.permissions.Permission;
  24. import org.bukkit.plugin.Plugin;
  25. import org.bukkit.plugin.PluginManager;
  26. import org.bukkit.plugin.RegisteredServiceProvider;
  27. import org.bukkit.plugin.java.JavaPlugin;
  28. import org.bukkit.scheduler.BukkitRunnable;
  29.  
  30. import loretest.util.DataUtil;
  31. import net.md_5.bungee.api.ChatColor;
  32.  
  33. public class LoreAttributes
  34. extends JavaPlugin
  35. {
  36. private Pattern dexterityRegex;
  37. private Pattern strengthRegex;
  38. private Pattern intelligenceRegex;
  39. public static LoreManager loreManager;
  40. public static Plugin plugin;
  41. public static Permission permission = null;
  42. public static FileConfiguration config = null;
  43. public Map<String, Object> playerData = new HashMap<>();
  44. public HashMap<Player, Integer> cooldownTime;
  45. public static HashMap<Player, BukkitRunnable> cooldownTask;
  46.  
  47. public void onEnable()
  48. {
  49. cooldownTime = new HashMap<Player, Integer>();
  50. config = getConfig();
  51. config.options().copyDefaults(true);
  52.  
  53. saveConfig();
  54. if (loreManager == null) {
  55. loreManager = new LoreManager(this);
  56. }
  57. Bukkit.getServer().getPluginManager().registerEvents(new LoreEvents(), this);
  58. plugin = this;
  59. this.strengthRegex = Pattern.compile("[+](\\d+)[ ](" + LoreAttributes.config.getString("lore.strength.keyword").toLowerCase() + ")");
  60. this.dexterityRegex = Pattern.compile("[+](\\d+)[ ](" + LoreAttributes.config.getString("lore.dexterity.keyword").toLowerCase() + ")");
  61. this.intelligenceRegex = Pattern.compile("[+](\\d+)[ ](" + LoreAttributes.config.getString("lore.intelligence.keyword").toLowerCase() + ")");
  62.  
  63. }
  64.  
  65. public void onDisable()
  66. {
  67. HandlerList.unregisterAll(this);
  68. }
  69.  
  70. @SuppressWarnings("static-access")
  71. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args)
  72. {
  73. if (cmd.getLabel().equalsIgnoreCase("hp"))
  74. {
  75. if (!(sender instanceof Player)) {
  76. return false;
  77. }
  78. Player p = (Player)sender;
  79. p.sendMessage("Health: " + p.getHealth() + "/" + p.getMaxHealth());
  80. return true;
  81. }
  82. {
  83. if(cmd.getName().equalsIgnoreCase("torment") && sender instanceof Player) {
  84.  
  85. Player player = (Player) sender;
  86. if (args.length > 0) {
  87. try {
  88. double level = Double.valueOf(args[0]);
  89. player.sendMessage(ChatColor.GREEN + "Torment difficulty has been set to " + level);
  90. config.set("torment." + player.getName(), level);
  91. saveConfig();
  92. DataUtil.writePlayerData(player, "tormentLevel", level);
  93. }catch(Exception e) {
  94. e.printStackTrace();
  95. }
  96. } else {
  97. player.sendMessage(ChatColor.RED + "Incorrect usage, do /torment <level>, or do /tormentlevel to get the current level.");
  98. }
  99.  
  100. }
  101. if(cmd.getLabel().equalsIgnoreCase("tormentlevel") && sender instanceof Player){
  102. Player p = (Player) sender;
  103. p.sendMessage(ChatColor.GREEN + "The current Torment Level is " + LoreAttributes.config.getDouble("torment." + p.getName()));
  104. }
  105. if (cmd.getLabel().equalsIgnoreCase("lorestats") && sender instanceof Player)
  106. {
  107. loreManager.displayLoreStats((Player)sender);
  108. return true;
  109. }
  110. if(cmd.getLabel().equalsIgnoreCase("classes") && sender instanceof Player){
  111. sender.sendMessage(ChatColor.GREEN + "Available classes: " + ChatColor.GOLD + "Demon Hunter" + ChatColor.GREEN + ", " + ChatColor.GOLD + "Necromancer"
  112. + ChatColor.GREEN + ", " + ChatColor.GOLD + "Crusader" + ChatColor.GREEN + ". " + ChatColor.GREEN + "Do /class <classname> to pick a class" + ChatColor.GREEN + ".");
  113. }
  114. if(cmd.getName().equalsIgnoreCase("class") && sender instanceof Player) {
  115. Player player = (Player) sender;
  116. if (args[0].equalsIgnoreCase("demonhunter")) {
  117. player.sendMessage(ChatColor.GREEN + "You are now a" + ChatColor.GOLD + " Demon Hunter" + ChatColor.GREEN + "!");
  118. player.addAttachment(this, "c.demonhunter", true);
  119. player.addAttachment(this, "c.crusader", false);
  120. player.addAttachment(this, "c.necromancer", false);
  121. return true;
  122. }
  123. if(cmd.getName().equalsIgnoreCase("class") && sender instanceof Player) {
  124. if (args[0].equalsIgnoreCase("necromancer")) {
  125. player.sendMessage(ChatColor.GREEN + "You are now a" + ChatColor.GOLD + " Necromancer" + ChatColor.GREEN + "!");
  126. player.addAttachment(this, "c.demonhunter", false);
  127. player.addAttachment(this, "c.crusader", false);
  128. player.addAttachment(this, "c.necromancer", true);
  129. return true;
  130. }
  131. if(cmd.getName().equalsIgnoreCase("class") && sender instanceof Player) {
  132. if (args[0].equalsIgnoreCase("crusader")) {
  133. player.sendMessage(ChatColor.GREEN + "You are now a" + ChatColor.GOLD + " Crusader" + ChatColor.GREEN + "!");
  134. player.addAttachment(this, "c.demonhunter", false);
  135. player.addAttachment(this, "c.crusader", true);
  136. player.addAttachment(this, "c.necromancer", false);
  137. return true;
  138. }
  139. else{
  140. player.sendMessage(ChatColor.RED + "Incorrect usage, do /class <classname>");
  141. }
  142. }
  143. }
  144. }
  145. if(cmd.getLabel().equalsIgnoreCase("toggledamageon") && sender instanceof Player){
  146. Player p = (Player) sender;
  147. p.addAttachment(this, "d.on", true);
  148. p.sendMessage(ChatColor.DARK_GRAY + "Damage display in chat is toggled: " + ChatColor.GREEN + "ON" + ChatColor.DARK_GRAY + ".");
  149. }
  150. if(cmd.getLabel().equalsIgnoreCase("toggledamageoff") && sender instanceof Player){
  151. Player p = (Player) sender;
  152. p.addAttachment(this, "d.on", false);
  153. p.sendMessage(ChatColor.DARK_GRAY + "Damage display in chat is toggled: " + ChatColor.RED + "OFF" + ChatColor.DARK_GRAY + ".");
  154. }
  155. if(cmd.getLabel().equalsIgnoreCase("fixstats") && sender instanceof Player){
  156. Player p = (Player) sender;
  157. if(p.hasPermission("c.demonhunter")){
  158. ItemStack[] arrayOfItemStack;
  159. ItemStack target = p.getInventory().getItem(0);
  160. List<String> lore = target.getItemMeta().getLore();
  161. for(int j = 0; j < lore.size(); j++){
  162. String str = lore.get(j).toLowerCase();
  163. if(str.endsWith(" strength")){
  164. str.replace(" strength", "Dexterity");
  165. p.sendMessage(ChatColor.GREEN + "Your Main Stat was fixed according to your class. "
  166. + ChatColor.GOLD + "(Demon Hunter)" + ChatColor.GREEN + ".");
  167. }
  168. }
  169. }
  170. }
  171. }
  172. return false;
  173. }
  174. public static Plugin getPlugin() {
  175. return plugin;
  176. }
  177.  
  178. public static MemorySection config() {
  179. return LoreAttributes.config;
  180. }
  181. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement