Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package loretest;
- import java.util.ArrayList;
- import java.util.HashMap;
- import java.util.List;
- import java.util.Map;
- import java.util.regex.Matcher;
- import java.util.regex.Pattern;
- import org.apache.commons.lang.StringUtils;
- import org.bukkit.Bukkit;
- import org.bukkit.Material;
- import org.bukkit.Server;
- import org.bukkit.command.Command;
- import org.bukkit.command.CommandSender;
- import org.bukkit.configuration.MemorySection;
- import org.bukkit.configuration.file.FileConfiguration;
- import org.bukkit.configuration.file.FileConfigurationOptions;
- import org.bukkit.entity.Player;
- import org.bukkit.event.HandlerList;
- import org.bukkit.inventory.ItemStack;
- import org.bukkit.inventory.meta.ItemMeta;
- import org.bukkit.permissions.Permission;
- import org.bukkit.plugin.Plugin;
- import org.bukkit.plugin.PluginManager;
- import org.bukkit.plugin.RegisteredServiceProvider;
- import org.bukkit.plugin.java.JavaPlugin;
- import org.bukkit.scheduler.BukkitRunnable;
- import loretest.util.DataUtil;
- import net.md_5.bungee.api.ChatColor;
- public class LoreAttributes
- extends JavaPlugin
- {
- private Pattern dexterityRegex;
- private Pattern strengthRegex;
- private Pattern intelligenceRegex;
- public static LoreManager loreManager;
- public static Plugin plugin;
- public static Permission permission = null;
- public static FileConfiguration config = null;
- public Map<String, Object> playerData = new HashMap<>();
- public HashMap<Player, Integer> cooldownTime;
- public static HashMap<Player, BukkitRunnable> cooldownTask;
- public void onEnable()
- {
- cooldownTime = new HashMap<Player, Integer>();
- config = getConfig();
- config.options().copyDefaults(true);
- saveConfig();
- if (loreManager == null) {
- loreManager = new LoreManager(this);
- }
- Bukkit.getServer().getPluginManager().registerEvents(new LoreEvents(), this);
- plugin = this;
- this.strengthRegex = Pattern.compile("[+](\\d+)[ ](" + LoreAttributes.config.getString("lore.strength.keyword").toLowerCase() + ")");
- this.dexterityRegex = Pattern.compile("[+](\\d+)[ ](" + LoreAttributes.config.getString("lore.dexterity.keyword").toLowerCase() + ")");
- this.intelligenceRegex = Pattern.compile("[+](\\d+)[ ](" + LoreAttributes.config.getString("lore.intelligence.keyword").toLowerCase() + ")");
- }
- public void onDisable()
- {
- HandlerList.unregisterAll(this);
- }
- @SuppressWarnings("static-access")
- public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args)
- {
- if (cmd.getLabel().equalsIgnoreCase("hp"))
- {
- if (!(sender instanceof Player)) {
- return false;
- }
- Player p = (Player)sender;
- p.sendMessage("Health: " + p.getHealth() + "/" + p.getMaxHealth());
- return true;
- }
- {
- if(cmd.getName().equalsIgnoreCase("torment") && sender instanceof Player) {
- Player player = (Player) sender;
- if (args.length > 0) {
- try {
- double level = Double.valueOf(args[0]);
- player.sendMessage(ChatColor.GREEN + "Torment difficulty has been set to " + level);
- config.set("torment." + player.getName(), level);
- saveConfig();
- DataUtil.writePlayerData(player, "tormentLevel", level);
- }catch(Exception e) {
- e.printStackTrace();
- }
- } else {
- player.sendMessage(ChatColor.RED + "Incorrect usage, do /torment <level>, or do /tormentlevel to get the current level.");
- }
- }
- if(cmd.getLabel().equalsIgnoreCase("tormentlevel") && sender instanceof Player){
- Player p = (Player) sender;
- p.sendMessage(ChatColor.GREEN + "The current Torment Level is " + LoreAttributes.config.getDouble("torment." + p.getName()));
- }
- if (cmd.getLabel().equalsIgnoreCase("lorestats") && sender instanceof Player)
- {
- loreManager.displayLoreStats((Player)sender);
- return true;
- }
- if(cmd.getLabel().equalsIgnoreCase("classes") && sender instanceof Player){
- sender.sendMessage(ChatColor.GREEN + "Available classes: " + ChatColor.GOLD + "Demon Hunter" + ChatColor.GREEN + ", " + ChatColor.GOLD + "Necromancer"
- + ChatColor.GREEN + ", " + ChatColor.GOLD + "Crusader" + ChatColor.GREEN + ". " + ChatColor.GREEN + "Do /class <classname> to pick a class" + ChatColor.GREEN + ".");
- }
- if(cmd.getName().equalsIgnoreCase("class") && sender instanceof Player) {
- Player player = (Player) sender;
- if (args[0].equalsIgnoreCase("demonhunter")) {
- player.sendMessage(ChatColor.GREEN + "You are now a" + ChatColor.GOLD + " Demon Hunter" + ChatColor.GREEN + "!");
- player.addAttachment(this, "c.demonhunter", true);
- player.addAttachment(this, "c.crusader", false);
- player.addAttachment(this, "c.necromancer", false);
- return true;
- }
- if(cmd.getName().equalsIgnoreCase("class") && sender instanceof Player) {
- if (args[0].equalsIgnoreCase("necromancer")) {
- player.sendMessage(ChatColor.GREEN + "You are now a" + ChatColor.GOLD + " Necromancer" + ChatColor.GREEN + "!");
- player.addAttachment(this, "c.demonhunter", false);
- player.addAttachment(this, "c.crusader", false);
- player.addAttachment(this, "c.necromancer", true);
- return true;
- }
- if(cmd.getName().equalsIgnoreCase("class") && sender instanceof Player) {
- if (args[0].equalsIgnoreCase("crusader")) {
- player.sendMessage(ChatColor.GREEN + "You are now a" + ChatColor.GOLD + " Crusader" + ChatColor.GREEN + "!");
- player.addAttachment(this, "c.demonhunter", false);
- player.addAttachment(this, "c.crusader", true);
- player.addAttachment(this, "c.necromancer", false);
- return true;
- }
- else{
- player.sendMessage(ChatColor.RED + "Incorrect usage, do /class <classname>");
- }
- }
- }
- }
- if(cmd.getLabel().equalsIgnoreCase("toggledamageon") && sender instanceof Player){
- Player p = (Player) sender;
- p.addAttachment(this, "d.on", true);
- p.sendMessage(ChatColor.DARK_GRAY + "Damage display in chat is toggled: " + ChatColor.GREEN + "ON" + ChatColor.DARK_GRAY + ".");
- }
- if(cmd.getLabel().equalsIgnoreCase("toggledamageoff") && sender instanceof Player){
- Player p = (Player) sender;
- p.addAttachment(this, "d.on", false);
- p.sendMessage(ChatColor.DARK_GRAY + "Damage display in chat is toggled: " + ChatColor.RED + "OFF" + ChatColor.DARK_GRAY + ".");
- }
- if(cmd.getLabel().equalsIgnoreCase("fixstats") && sender instanceof Player){
- Player p = (Player) sender;
- if(p.hasPermission("c.demonhunter")){
- ItemStack[] arrayOfItemStack;
- ItemStack target = p.getInventory().getItem(0);
- List<String> lore = target.getItemMeta().getLore();
- for(int j = 0; j < lore.size(); j++){
- String str = lore.get(j).toLowerCase();
- if(str.endsWith(" strength")){
- str.replace(" strength", "Dexterity");
- p.sendMessage(ChatColor.GREEN + "Your Main Stat was fixed according to your class. "
- + ChatColor.GOLD + "(Demon Hunter)" + ChatColor.GREEN + ".");
- }
- }
- }
- }
- }
- return false;
- }
- public static Plugin getPlugin() {
- return plugin;
- }
- public static MemorySection config() {
- return LoreAttributes.config;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement