Update for 1.12
Fixed for 1.12 removed CitizensAPI dependency added disabledelay added disablecooldown fixed drop-item
This commit is contained in:
		
							
								
								
									
										
											BIN
										
									
								
								lib/HyperConomy.jar
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								lib/HyperConomy.jar
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										11
									
								
								plugin.yml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								plugin.yml
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,11 @@ | |||||||
|  | name: Blacksmith | ||||||
|  | author: aPunch, jrbudda, HurricanKai | ||||||
|  | version: 1.12 | ||||||
|  | main: net.apunch.blacksmith.BlacksmithPlugin | ||||||
|  | depend: [Citizens, Vault] | ||||||
|  | softdepend: [HyperConomy] | ||||||
|  |  | ||||||
|  | commands: | ||||||
|  |   blacksmithreload: | ||||||
|  |     permission: blacksmith.reload | ||||||
|  |     description: reloads the config file for Blacksmith | ||||||
							
								
								
									
										110
									
								
								pom.xml
									
									
									
									
									
								
							
							
						
						
									
										110
									
								
								pom.xml
									
									
									
									
									
								
							| @@ -1,75 +1,87 @@ | |||||||
| <!-- Blacksmith build file --> | <!-- Blacksmith build file --> | ||||||
|  |  | ||||||
| <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||||||
| 	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> |          xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||||||
| 	<modelVersion>4.0.0</modelVersion> |     <modelVersion>4.0.0</modelVersion> | ||||||
|  |  | ||||||
| 	<groupId>net.apunch</groupId> |     <groupId>net.apunch</groupId> | ||||||
| 	<artifactId>blacksmith</artifactId> |     <artifactId>blacksmith</artifactId> | ||||||
| 	<version>1.0-SNAPSHOT</version> |     <version>1.12-SNAPSHOT</version> | ||||||
| 	<name>Blacksmith</name> |     <name>Blacksmith</name> | ||||||
| 	<description>Blacksmith Character for the CitizensAPI</description> |     <description>Blacksmith Character for the CitizensAPI</description> | ||||||
|  |  | ||||||
| 	<!-- Properties --> |     <!-- Properties --> | ||||||
| 	<properties> |     <properties> | ||||||
| 		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> |         <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||||||
| 		<bukkit.version>1.2.5-R0.1-SNAPSHOT</bukkit.version> |         <bukkit.version>1.10.2-R0.1-SNAPSHOT</bukkit.version> | ||||||
| 		<citizensapi.version>2.0-SNAPSHOT</citizensapi.version> |         <citizensapi.version>2.0.20-SNAPSHOT</citizensapi.version> | ||||||
| 		<vault.version>1.2.13-SNAPSHOT</vault.version> |         <vault.version>1.5.6</vault.version> | ||||||
| 		<build.number>Unknown</build.number> |         <hyperconomy.version>0.975.7-SNAPSHOT</hyperconomy.version> | ||||||
| 	</properties> |         <build.number>Unknown</build.number> | ||||||
|  |     </properties> | ||||||
|  |  | ||||||
| 	<!-- Repositories --> |     <!-- Repositories --> | ||||||
| 	<repositories> |     <repositories> | ||||||
| 		<repository> | 		<repository> | ||||||
| 			<id>bukkit-repo</id> |             <id>spigot-repo</id> | ||||||
| 			<url>http://repo.bukkit.org/content/groups/public/</url> |             <url>https://hub.spigotmc.org/nexus/content/groups/public/</url> | ||||||
| 		</repository> | 		</repository> | ||||||
| 		<repository> | 		<repository> | ||||||
| 			<id>citizens-repo</id> | 			<id>citizens-repo</id> | ||||||
| 			<url>http://repo.citizensnpcs.net/</url> | 			<url>http://ci.citizensnpcs.co/job/Citizens2/lastSuccessfulBuild/maven-repository/repository/</url> | ||||||
| 		</repository> | 		</repository> | ||||||
| 		<repository> | 		<repository> | ||||||
| 			<id>vault-repo</id> | 			<id>vault-repo</id> | ||||||
| 			<url>http://ci.milkbowl.net/plugin/repository/everything</url> | 			<url>http://nexus.hc.to/content/repositories/pub_releases</url> | ||||||
| 		</repository> | 		</repository> | ||||||
| 	</repositories> | 		<repository> | ||||||
|  | 			<id>grokswell-repo</id> | ||||||
|  | 			<url>http://www.grokswell.com:8000/repo/</url> | ||||||
|  | 		</repository> | ||||||
|  |     </repositories> | ||||||
|  |  | ||||||
| 	<!-- Dependencies --> |     <!-- Dependencies --> | ||||||
| 	<dependencies> |     <dependencies> | ||||||
| 		<dependency> |     	<dependency> | ||||||
|  | 			<groupId>net.citizensnpcs</groupId> | ||||||
|  | 			<artifactId>citizensapi</artifactId> | ||||||
|  | 			<version>2.0.22-SNAPSHOT</version> | ||||||
|  | 			<type>jar</type> | ||||||
|  | 			<scope>compile</scope> | ||||||
|  | 		</dependency> | ||||||
|  |     	<dependency> | ||||||
| 			<groupId>org.bukkit</groupId> | 			<groupId>org.bukkit</groupId> | ||||||
| 			<artifactId>bukkit</artifactId> | 			<artifactId>bukkit</artifactId> | ||||||
| 			<version>${bukkit.version}</version> | 			<version>${bukkit.version}</version> | ||||||
| 			<scope>provided</scope> | 			<scope>provided</scope> | ||||||
| 		</dependency> | 		</dependency> | ||||||
|  |         <dependency> | ||||||
|  |             <groupId>net.milkbowl.vault</groupId> | ||||||
|  |             <artifactId>Vault</artifactId> | ||||||
|  |             <version>${vault.version}</version> | ||||||
|  |             <scope>provided</scope> | ||||||
|  |         </dependency> | ||||||
| 		<dependency> | 		<dependency> | ||||||
| 			<groupId>net.citizensnpcs</groupId> | 			<groupId>regalowl.hyperconomy</groupId> | ||||||
| 			<artifactId>citizensapi</artifactId> | 			<artifactId>hyperconomy</artifactId> | ||||||
| 			<version>${citizensapi.version}</version> | 			<version>${hyperconomy.version}</version> | ||||||
| 			<scope>provided</scope> | 			<scope>provided</scope> | ||||||
| 		</dependency>  | 		</dependency>  | ||||||
| 		<dependency> |     </dependencies> | ||||||
| 			<groupId>net.milkbowl.vault</groupId> |  | ||||||
| 			<artifactId>Vault</artifactId> |  | ||||||
| 			<version>${vault.version}</version> |  | ||||||
| 			<scope>provided</scope> |  | ||||||
| 		</dependency> |  | ||||||
| 	</dependencies> |  | ||||||
|  |  | ||||||
| 	<!-- Build information --> |     <!-- Build information --> | ||||||
| 	<build> |     <build> | ||||||
| 		<plugins> |         <plugins> | ||||||
| 			<plugin> |             <plugin> | ||||||
| 				<groupId>org.apache.maven.plugins</groupId> |                 <groupId>org.apache.maven.plugins</groupId> | ||||||
| 				<artifactId>maven-compiler-plugin</artifactId> |                 <artifactId>maven-compiler-plugin</artifactId> | ||||||
| 				<version>2.3.2</version> |                 <version>2.5.1</version> | ||||||
| 				<configuration> |                 <configuration> | ||||||
| 					<source>1.6</source> |                     <source>1.6</source> | ||||||
| 					<target>1.6</target> |                     <target>1.6</target> | ||||||
| 				</configuration> |                 </configuration> | ||||||
| 			</plugin> |             </plugin> | ||||||
| 		</plugins> |         </plugins> | ||||||
| 	</build> |     </build> | ||||||
|  |  | ||||||
| </project> | </project> | ||||||
| @@ -1,149 +1,288 @@ | |||||||
| package net.apunch.blacksmith; | package net.apunch.blacksmith; | ||||||
|  |  | ||||||
|  | import java.util.ArrayList; | ||||||
| import java.util.logging.Level; | import java.util.logging.Level; | ||||||
|  |  | ||||||
| import net.apunch.blacksmith.util.Settings; | import net.apunch.blacksmith.util.Settings; | ||||||
| import net.apunch.blacksmith.util.Settings.Setting; | import net.apunch.blacksmith.util.Settings.Setting; | ||||||
|  |  | ||||||
| import net.citizensnpcs.api.CitizensAPI; | import net.citizensnpcs.api.CitizensAPI; | ||||||
| import net.citizensnpcs.api.npc.character.CharacterFactory; | import net.citizensnpcs.api.npc.NPC; | ||||||
| import net.citizensnpcs.api.util.DataKey; | import net.citizensnpcs.api.util.DataKey; | ||||||
|  |  | ||||||
| import net.milkbowl.vault.economy.Economy; | import net.milkbowl.vault.economy.Economy; | ||||||
|  |  | ||||||
|  | import org.bukkit.Bukkit; | ||||||
|  | import org.bukkit.ChatColor; | ||||||
|  | import org.bukkit.Material; | ||||||
|  | import org.bukkit.OfflinePlayer; | ||||||
|  | import org.bukkit.command.Command; | ||||||
|  | import org.bukkit.command.CommandSender; | ||||||
| import org.bukkit.enchantments.Enchantment; | import org.bukkit.enchantments.Enchantment; | ||||||
| import org.bukkit.entity.Player; | import org.bukkit.entity.Player; | ||||||
| import org.bukkit.inventory.ItemStack; | import org.bukkit.inventory.ItemStack; | ||||||
|  | import org.bukkit.plugin.Plugin; | ||||||
| import org.bukkit.plugin.RegisteredServiceProvider; | import org.bukkit.plugin.RegisteredServiceProvider; | ||||||
| import org.bukkit.plugin.java.JavaPlugin; | import org.bukkit.plugin.java.JavaPlugin; | ||||||
|  |  | ||||||
|  | import regalowl.hyperconomy.HyperAPI; | ||||||
|  | import regalowl.hyperconomy.HyperConomy; | ||||||
|  | import regalowl.hyperconomy.bukkit.BukkitConnector; | ||||||
|  | import regalowl.hyperconomy.inventory.HItemStack; | ||||||
|  | import regalowl.hyperconomy.tradeobject.TradeObject; | ||||||
|  |  | ||||||
|  |  | ||||||
| public class BlacksmithPlugin extends JavaPlugin { | public class BlacksmithPlugin extends JavaPlugin { | ||||||
|     private Settings config; | 	public BlacksmithPlugin plugin; | ||||||
|     private Economy economy; | 	private Settings config; | ||||||
|  | 	private Economy economy; | ||||||
|  | 	private HyperAPI hyperAPI; | ||||||
|  | 	private BukkitConnector bukCon; | ||||||
|  | 	private boolean useHyperAPI = false; | ||||||
|  |         //private boolean hasCititrader = false; // CitiTrader dependency outdated and broken | ||||||
|  |  | ||||||
|     @Override | 	@Override | ||||||
|     public void onDisable() { | 	public void onDisable() { | ||||||
|         config.save(); | 	//	config.save(); | ||||||
|  |  | ||||||
|         getLogger().log(Level.INFO, " v" + getDescription().getVersion() + " disabled."); | 		getLogger().log(Level.INFO, " v" + getDescription().getVersion() + " disabled."); | ||||||
|     } | 	} | ||||||
|  |  | ||||||
|     @Override | 	@Override | ||||||
|     public void onEnable() { | 	public void onEnable() { | ||||||
|         config = new Settings(this); | 		config = new Settings(this); | ||||||
|  | 		config.load(); | ||||||
|  | 		// Setup Hyperconomy (Soft-Depend only, so this is completely optional!)     | ||||||
|  | 		// Hyperconomy uses your favorite Vault-compatible economy system | ||||||
|  | 		// and calculates prices for items based on supply and demand on the fly. | ||||||
|  | 		// This is only used to get the cost of a repair. | ||||||
|  | 		if (Bukkit.getPluginManager().getPlugin("HyperConomy") != null) { | ||||||
|  | 			getServer().getLogger().log(Level.INFO, "Found HyperConomy! Using that for calculating prices, base-prices and price-per-durability-point in the Blacksmith config.yml will NOT be used!"); | ||||||
|  | 			this.useHyperAPI = true; | ||||||
|  | 			Plugin hcPlugin = getServer().getPluginManager().getPlugin("HyperConomy"); | ||||||
|  | 			bukCon = (BukkitConnector)hcPlugin; | ||||||
|  | 			HyperConomy hc = bukCon.getHC(); | ||||||
|  | 			this.hyperAPI = (HyperAPI) hc.getAPI(); | ||||||
|  | 		} | ||||||
|  | 		getLogger().log(Level.INFO, "Setting Up Vault now...."); | ||||||
|  |         /* CitiTrader dependency outdated and broken | ||||||
|  |                 // Check for Cititrader | ||||||
|  |                  if(getServer().getPluginManager().getPlugin("CitiTrader") != null) { | ||||||
|  |                      hasCititrader = true; | ||||||
|  |                  } | ||||||
|  |                  */ | ||||||
|  |                  | ||||||
|  | 		boolean canload = SetupVault(); | ||||||
|  | 		if (!canload) | ||||||
|  | 		{ | ||||||
|  | 			getLogger().log(Level.INFO, "Vault Failed...."); | ||||||
|  | 			getServer().getPluginManager().disablePlugin(this); | ||||||
|  | 			return; | ||||||
|  | 		} | ||||||
|  | 		CitizensAPI.getTraitFactory().registerTrait(net.citizensnpcs.api.trait.TraitInfo.create(BlacksmithTrait.class).withName("blacksmith")); | ||||||
|  |  | ||||||
|  |  | ||||||
|  | 		getLogger().log(Level.INFO, " v" + getDescription().getVersion() + " enabled."); | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  |     private boolean SetupVault() { | ||||||
|  | 		// Setup Vault | ||||||
|  | 		RegisteredServiceProvider<Economy> economyProvider = getServer().getServicesManager().getRegistration( | ||||||
|  | 				Economy.class); | ||||||
|  | 		if (economyProvider != null) | ||||||
|  | 		{ | ||||||
|  | 			economy = economyProvider.getProvider(); | ||||||
|  | 			return true; | ||||||
|  | 		} | ||||||
|  | 		else { | ||||||
|  | 			// Disable if no economy plugin was found | ||||||
|  | 			getServer().getLogger().log(Level.SEVERE, "Failed to load an economy plugin. Disabling..."); | ||||||
|  | 			return false; | ||||||
|  | 		} | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	@Override | ||||||
|  |     public boolean onCommand(final CommandSender sender, final Command command, final String label, final String[] args) { | ||||||
|         config.load(); |         config.load(); | ||||||
|  |         sender.sendMessage(ChatColor.GREEN + "Blacksmith config reloaded!"); | ||||||
|  |         return true; | ||||||
|  |     } | ||||||
|  |  | ||||||
|         // Setup Vault |     /* CitiTrader dependency outdated and broken | ||||||
|         RegisteredServiceProvider<Economy> economyProvider = getServer().getServicesManager().getRegistration( |     // Return if we have cititrader | ||||||
|                 Economy.class); |          public boolean hasCititrader() { | ||||||
|         if (economyProvider != null) |             return this.hasCititrader; | ||||||
|             economy = economyProvider.getProvider(); |          } | ||||||
|         else { |          */ | ||||||
|             // Disable if no economy plugin was found |          | ||||||
|             getServer().getLogger().log(Level.SEVERE, "Failed to load an economy plugin. Disabling..."); | 	public BlacksmithTrait getBlacksmith(NPC npc){ | ||||||
|             getServer().getPluginManager().disablePlugin(this); |  | ||||||
|             return; | 		if (npc !=null && npc.hasTrait(BlacksmithTrait.class)){ | ||||||
|  | 			return npc.getTrait(BlacksmithTrait.class); | ||||||
|  | 		} | ||||||
|  |  | ||||||
|  | 		return null; | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  |  | ||||||
|  | 	public boolean isTool(ItemStack item) { | ||||||
|  | 		switch (item.getType()) { | ||||||
|  | 		case WOOD_PICKAXE: | ||||||
|  | 		case WOOD_SPADE: | ||||||
|  | 		case WOOD_HOE: | ||||||
|  | 		case WOOD_SWORD: | ||||||
|  | 		case WOOD_AXE: | ||||||
|  | 		case STONE_PICKAXE: | ||||||
|  | 		case STONE_SPADE: | ||||||
|  | 		case STONE_HOE: | ||||||
|  | 		case STONE_SWORD: | ||||||
|  | 		case STONE_AXE: | ||||||
|  | 		case GOLD_PICKAXE: | ||||||
|  | 		case GOLD_SPADE: | ||||||
|  | 		case GOLD_HOE: | ||||||
|  | 		case GOLD_SWORD: | ||||||
|  | 		case GOLD_AXE: | ||||||
|  | 		case IRON_PICKAXE: | ||||||
|  | 		case IRON_SPADE: | ||||||
|  | 		case IRON_HOE: | ||||||
|  | 		case IRON_SWORD: | ||||||
|  | 		case IRON_AXE: | ||||||
|  | 		case DIAMOND_PICKAXE: | ||||||
|  | 		case DIAMOND_SPADE: | ||||||
|  | 		case DIAMOND_HOE: | ||||||
|  | 		case DIAMOND_SWORD: | ||||||
|  | 		case DIAMOND_AXE: | ||||||
|  | 		case BOW: | ||||||
|  | 		case FLINT_AND_STEEL: | ||||||
|  | 		case FISHING_ROD: | ||||||
|  | 		case SHEARS: | ||||||
|  | 			return true; | ||||||
|  | 		default: | ||||||
|  | 			return false; | ||||||
|  | 		} | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	public boolean isArmor(ItemStack item) { | ||||||
|  | 		switch (item.getType()) { | ||||||
|  | 		case LEATHER_HELMET: | ||||||
|  | 		case LEATHER_CHESTPLATE: | ||||||
|  | 		case LEATHER_LEGGINGS: | ||||||
|  | 		case LEATHER_BOOTS: | ||||||
|  | 		case CHAINMAIL_HELMET: | ||||||
|  | 		case CHAINMAIL_CHESTPLATE: | ||||||
|  | 		case CHAINMAIL_LEGGINGS: | ||||||
|  | 		case CHAINMAIL_BOOTS: | ||||||
|  | 		case GOLD_HELMET: | ||||||
|  | 		case GOLD_CHESTPLATE: | ||||||
|  | 		case GOLD_LEGGINGS: | ||||||
|  | 		case GOLD_BOOTS: | ||||||
|  | 		case IRON_HELMET: | ||||||
|  | 		case IRON_CHESTPLATE: | ||||||
|  | 		case IRON_LEGGINGS: | ||||||
|  | 		case IRON_BOOTS: | ||||||
|  | 		case DIAMOND_HELMET: | ||||||
|  | 		case DIAMOND_CHESTPLATE: | ||||||
|  | 		case DIAMOND_LEGGINGS: | ||||||
|  | 		case DIAMOND_BOOTS: | ||||||
|  | 			return true; | ||||||
|  | 		default: | ||||||
|  | 			return false; | ||||||
|  | 		} | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	public boolean doesPlayerHaveEnough(Player player) { | ||||||
|  | 		return economy.getBalance((OfflinePlayer) player) - getCost(player.getItemInHand(), player) >= 0; | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	public String formatCost(Player player) { | ||||||
|  | 		double cost = getCost(player.getItemInHand(), player); | ||||||
|  | 		return economy.format(cost); | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	public void withdraw(Player player) { | ||||||
|  | 		economy.withdrawPlayer(((OfflinePlayer) player), getCost(player.getItemInHand(), player)); | ||||||
|  | 	} | ||||||
|  |        /* CitiTrader dependency outdated and broken. | ||||||
|  |         public void deposit(NPC npc, Player player) { | ||||||
|  | //            if(hasCititrader) { | ||||||
|  | //             if(npc.hasTrait(WalletTrait.class)) { | ||||||
|  | //                  npc.getTrait(WalletTrait.class).deposit(getCost(player.getItemInHand())); | ||||||
|  | //              } | ||||||
|  | //            } | ||||||
|         } |         } | ||||||
|  |         */ | ||||||
|  |  | ||||||
|         CitizensAPI.getCharacterManager().registerCharacter( | 	private double getCost(ItemStack item, Player player) { | ||||||
|                 new CharacterFactory(Blacksmith.class).withName("blacksmith")); | 		DataKey root = config.getConfig().getKey(""); | ||||||
|  | 		double price = Setting.BASE_PRICE.asDouble(); | ||||||
|  | 		if (root.keyExists("base-prices." + item.getType().name().toLowerCase().replace('_', '-'))) | ||||||
|  | 			price = root.getDouble("base-prices." + item.getType().name().toLowerCase().replace('_', '-')); | ||||||
|  |  | ||||||
|         getLogger().log(Level.INFO, " v" + getDescription().getVersion() + " enabled."); | 		// Adjust price based on durability and enchantments | ||||||
|     } | 		if (this.useHyperAPI) { | ||||||
|  | 			// If using hyperconomy, price is calculated like so: | ||||||
|  | 			// New Item Price + Enchantments Price (from hyperconomy) / maxDurability = price per durability point | ||||||
|  | 			// Total price would then be base_price + price per durablity point * current durability | ||||||
|  | 			double hyperPrice = 0; | ||||||
|  | 			HItemStack hi = hyperAPI.getHyperPlayer(player.getName()).getItemInHand(); | ||||||
|  | 			ItemStack item2 = player.getItemInHand().clone(); | ||||||
| 			 | 			 | ||||||
|     public boolean isTool(ItemStack item) { | 			for (TradeObject enchant : hyperAPI.getEnchantmentHyperObjects(hi, player.getName())) { | ||||||
|         switch (item.getType()) { | 				hyperPrice = hyperPrice + enchant.getBuyPrice(1); | ||||||
|         case WOOD_PICKAXE: | 				item2.removeEnchantment(Enchantment.getByName(enchant.getEnchantment().getEnchantmentName())); | ||||||
|         case WOOD_SPADE: | 			} | ||||||
|         case WOOD_HOE: |  | ||||||
|         case WOOD_SWORD: |  | ||||||
|         case WOOD_AXE: |  | ||||||
|         case STONE_PICKAXE: |  | ||||||
|         case STONE_SPADE: |  | ||||||
|         case STONE_HOE: |  | ||||||
|         case STONE_SWORD: |  | ||||||
|         case STONE_AXE: |  | ||||||
|         case GOLD_PICKAXE: |  | ||||||
|         case GOLD_SPADE: |  | ||||||
|         case GOLD_HOE: |  | ||||||
|         case GOLD_SWORD: |  | ||||||
|         case GOLD_AXE: |  | ||||||
|         case IRON_PICKAXE: |  | ||||||
|         case IRON_SPADE: |  | ||||||
|         case IRON_HOE: |  | ||||||
|         case IRON_SWORD: |  | ||||||
|         case IRON_AXE: |  | ||||||
|         case DIAMOND_PICKAXE: |  | ||||||
|         case DIAMOND_SPADE: |  | ||||||
|         case DIAMOND_HOE: |  | ||||||
|         case DIAMOND_SWORD: |  | ||||||
|         case DIAMOND_AXE: |  | ||||||
|         case BOW: |  | ||||||
|         case FLINT_AND_STEEL: |  | ||||||
|         case FISHING_ROD: |  | ||||||
|         case SHEARS: |  | ||||||
|             return true; |  | ||||||
|         default: |  | ||||||
|             return false; |  | ||||||
|         } |  | ||||||
|     } |  | ||||||
| 			 | 			 | ||||||
|     public boolean isArmor(ItemStack item) { | 			ArrayList<Material> leathers = new ArrayList<Material>(); | ||||||
|         switch (item.getType()) { | 			leathers.add(Material.LEATHER_BOOTS); | ||||||
|         case LEATHER_HELMET: | 			leathers.add(Material.LEATHER_CHESTPLATE); | ||||||
|         case LEATHER_CHESTPLATE: | 			leathers.add(Material.LEATHER_HELMET); | ||||||
|         case LEATHER_LEGGINGS: | 			leathers.add(Material.LEATHER_LEGGINGS); | ||||||
|         case LEATHER_BOOTS: |  | ||||||
|         case CHAINMAIL_HELMET: |  | ||||||
|         case CHAINMAIL_CHESTPLATE: |  | ||||||
|         case CHAINMAIL_LEGGINGS: |  | ||||||
|         case CHAINMAIL_BOOTS: |  | ||||||
|         case GOLD_HELMET: |  | ||||||
|         case GOLD_CHESTPLATE: |  | ||||||
|         case GOLD_LEGGINGS: |  | ||||||
|         case GOLD_BOOTS: |  | ||||||
|         case IRON_HELMET: |  | ||||||
|         case IRON_CHESTPLATE: |  | ||||||
|         case IRON_LEGGINGS: |  | ||||||
|         case IRON_BOOTS: |  | ||||||
|         case DIAMOND_HELMET: |  | ||||||
|         case DIAMOND_CHESTPLATE: |  | ||||||
|         case DIAMOND_LEGGINGS: |  | ||||||
|         case DIAMOND_BOOTS: |  | ||||||
|             return true; |  | ||||||
|         default: |  | ||||||
|             return false; |  | ||||||
|         } |  | ||||||
|     } |  | ||||||
| 			 | 			 | ||||||
|     public boolean doesPlayerHaveEnough(Player player) { | 			HItemStack hi3 = null; | ||||||
|         return economy.getBalance(player.getName()) - getCost(player.getItemInHand()) >= 0; | 			if (leathers.contains(player.getItemInHand().getType())){ | ||||||
|     } | 				hi3 = bukCon.getBukkitCommon().getSerializableItemStack(new ItemStack(player.getItemInHand().getType())); | ||||||
|  | 			} | ||||||
| 			 | 			 | ||||||
|     public String formatCost(Player player) { | 			TradeObject to = this.hyperAPI.getHyperObject(hi, "default"); | ||||||
|         return economy.format(getCost(player.getItemInHand())); | 			if (to==null) { | ||||||
|     } | 				to = hyperAPI.getHyperObject(hi3, "default"); | ||||||
|  | 				if (to==null) { | ||||||
|  | 					HItemStack hi4 = bukCon.getBukkitCommon().getSerializableItemStack(new ItemStack(player.getItemInHand().getType())); | ||||||
|  | 					to = this.hyperAPI.getHyperObject(hi4, "default"); | ||||||
|  | 				} | ||||||
|  | 				hyperPrice = hyperPrice+to.getSellPrice(1); | ||||||
| 	 | 	 | ||||||
|     public void withdraw(Player player) { | 			} else { | ||||||
|         economy.withdrawPlayer(player.getName(), getCost(player.getItemInHand())); | 				hyperPrice = to.getSellPrice(1); | ||||||
|     } | 			} | ||||||
|  | 			double hyperPricePerDurability = hyperPrice / item.getType().getMaxDurability(); | ||||||
|  | 			price += (item.getDurability() * hyperPricePerDurability); | ||||||
| 			 | 			 | ||||||
|     private double getCost(ItemStack item) { | 			double enchantmentModifier = Setting.ENCHANTMENT_MODIFIER.asDouble(); | ||||||
|         DataKey root = config.getConfig().getKey(""); | 			for (Enchantment enchantment : item2.getEnchantments().keySet()) { | ||||||
|         double price = Setting.BASE_PRICE.asDouble(); | 				if (root.keyExists("enchantment-modifiers." + enchantment.getName().toLowerCase().replace('_', '-'))) | ||||||
|         if (root.keyExists("base-prices." + item.getType().name().toLowerCase().replace('_', '-'))) | 					enchantmentModifier = root.getDouble("enchantment-modifiers." | ||||||
|             price = root.getDouble("base-prices." + item.getType().name().toLowerCase().replace('_', '-')); | 							+ enchantment.getName().toLowerCase().replace('_', '-')); | ||||||
|  | 				price += enchantmentModifier * item2.getEnchantmentLevel(enchantment); | ||||||
|  | 			} | ||||||
| 			 | 			 | ||||||
|         // Adjust price based on durability and enchantments |  | ||||||
|         price += (item.getType().getMaxDurability() - item.getDurability()); |  | ||||||
| 			 | 			 | ||||||
|         double enchantmentModifier = Setting.ENCHANTMENT_MODIFIER.asDouble(); | 			return price; | ||||||
|         for (Enchantment enchantment : item.getEnchantments().keySet()) { | 		} | ||||||
|             if (root.keyExists("enchantment-modifiers." + enchantment.getName().toLowerCase().replace('_', '-'))) |  | ||||||
|                 enchantmentModifier = root.getDouble("enchantment-modifiers." | 		else { | ||||||
|                         + enchantment.getName().toLowerCase().replace('_', '-')); | 			if (root.keyExists("price-per-durability-point." + item.getType().name().toLowerCase().replace('_', '-'))) | ||||||
|             price += enchantmentModifier * item.getEnchantmentLevel(enchantment); | 				price += item.getDurability() * root.getDouble("price-per-durability-point." + item.getType().name().toLowerCase().replace('_', '-')); | ||||||
|         } | 			else price += (item.getDurability() * Setting.PRICE_PER_DURABILITY_POINT.asDouble()); | ||||||
|         return price; | 		} | ||||||
|     } |  | ||||||
|  | 		double enchantmentModifier = Setting.ENCHANTMENT_MODIFIER.asDouble(); | ||||||
|  | 		for (Enchantment enchantment : item.getEnchantments().keySet()) { | ||||||
|  | 			if (root.keyExists("enchantment-modifiers." + enchantment.getName().toLowerCase().replace('_', '-'))) | ||||||
|  | 				enchantmentModifier = root.getDouble("enchantment-modifiers." | ||||||
|  | 						+ enchantment.getName().toLowerCase().replace('_', '-')); | ||||||
|  | 			price += enchantmentModifier * item.getEnchantmentLevel(enchantment); | ||||||
|  | 		} | ||||||
|  | 		return price; | ||||||
|  | 	} | ||||||
| } | } | ||||||
							
								
								
									
										345
									
								
								src/main/java/net/apunch/blacksmith/BlacksmithTrait.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										345
									
								
								src/main/java/net/apunch/blacksmith/BlacksmithTrait.java
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,345 @@ | |||||||
|  | package net.apunch.blacksmith; | ||||||
|  |  | ||||||
|  | import java.util.ArrayList; | ||||||
|  | import java.util.Calendar; | ||||||
|  | import java.util.HashMap; | ||||||
|  | import java.util.List; | ||||||
|  | import java.util.Map; | ||||||
|  | import java.util.Random; | ||||||
|  |  | ||||||
|  | import org.bukkit.Bukkit; | ||||||
|  | import org.bukkit.Material; | ||||||
|  | import org.bukkit.enchantments.Enchantment; | ||||||
|  | import org.bukkit.entity.LivingEntity; | ||||||
|  | import org.bukkit.entity.Player; | ||||||
|  | import org.bukkit.event.EventHandler; | ||||||
|  | import org.bukkit.inventory.ItemStack; | ||||||
|  |  | ||||||
|  | import net.apunch.blacksmith.util.Settings.Setting; | ||||||
|  |  | ||||||
|  | import net.citizensnpcs.api.npc.NPC; | ||||||
|  | import net.citizensnpcs.api.trait.Trait; | ||||||
|  | import net.citizensnpcs.api.util.DataKey; | ||||||
|  |  | ||||||
|  | public class BlacksmithTrait extends Trait { | ||||||
|  | 	private static final String[] enchantments = new String[Enchantment.values().length]; | ||||||
|  |  | ||||||
|  | 	private final BlacksmithPlugin plugin; | ||||||
|  | 	private final List<Material> reforgeableItems = new ArrayList<Material>(); | ||||||
|  | 	private final Map<String, Calendar> cooldowns = new HashMap<String, Calendar>(); | ||||||
|  | 	private ReforgeSession session; | ||||||
|  |  | ||||||
|  | 	// Defaults | ||||||
|  | 	private String busyWithPlayerMsg = Setting.BUSY_WITH_PLAYER_MESSAGE.asString(); | ||||||
|  | 	private String busyReforgingMsg = Setting.BUSY_WITH_REFORGE_MESSAGE.asString(); | ||||||
|  | 	private String costMsg = Setting.COST_MESSAGE.asString(); | ||||||
|  | 	private String invalidItemMsg = Setting.INVALID_ITEM_MESSAGE.asString(); | ||||||
|  | 	private String startReforgeMsg = Setting.START_REFORGE_MESSAGE.asString(); | ||||||
|  | 	private String successMsg = Setting.SUCCESS_MESSAGE.asString(); | ||||||
|  | 	private String failMsg = Setting.FAIL_MESSAGE.asString(); | ||||||
|  | 	private String insufficientFundsMsg = Setting.INSUFFICIENT_FUNDS_MESSAGE.asString(); | ||||||
|  | 	private String cooldownUnexpiredMsg = Setting.COOLDOWN_UNEXPIRED_MESSAGE.asString(); | ||||||
|  | 	private String itemChangedMsg = Setting.ITEM_UNEXPECTEDLY_CHANGED_MESSAGE.asString(); | ||||||
|  | 	private int minReforgeDelay = Setting.MIN_REFORGE_DELAY.asInt(); | ||||||
|  | 	private int maxReforgeDelay = Setting.MAX_REFORGE_DELAY.asInt(); | ||||||
|  | 	private int reforgeCooldown = Setting.REFORGE_COOLDOWN.asInt(); | ||||||
|  | 	private int failChance = Setting.FAIL_CHANCE.asInt(); | ||||||
|  | 	private int extraEnchantmentChance = Setting.EXTRA_ENCHANTMENT_CHANCE.asInt(); | ||||||
|  | 	private int maxEnchantments = Setting.MAX_ENCHANTMENTS.asInt(); | ||||||
|  | 	private boolean dropItem = Setting.DROP_ITEM.asBoolean(); | ||||||
|  | 	private boolean disablecooldown = Setting.DISABLE_COOLDOWN.asBoolean(); | ||||||
|  | 	private boolean disabledelay = Setting.DISABLE_DELAY.asBoolean(); | ||||||
|  |  | ||||||
|  | 	public BlacksmithTrait() { | ||||||
|  | 		super("blacksmith"); | ||||||
|  | 		plugin = (BlacksmithPlugin) Bukkit.getServer().getPluginManager().getPlugin("Blacksmith"); | ||||||
|  | 		int i = 0; | ||||||
|  | 		for (Enchantment enchantment : Enchantment.values()) | ||||||
|  | 			enchantments[i++] = enchantment.getName(); | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	@Override | ||||||
|  | 	public void load(DataKey key) { | ||||||
|  | 		for (DataKey sub : key.getRelative("reforgeable-items").getIntegerSubKeys()) | ||||||
|  | 			if (Material.getMaterial(sub.getString("").toUpperCase().replace('-', '_')) != null) | ||||||
|  | 				reforgeableItems.add(Material.getMaterial(sub.getString("").toUpperCase().replace('-', '_'))); | ||||||
|  |  | ||||||
|  | 		// Override defaults if they exist | ||||||
|  | 		if (key.keyExists("messages.busy-with-player")) | ||||||
|  | 			busyWithPlayerMsg = key.getString("messages.busy-with-player"); | ||||||
|  | 		if (key.keyExists("messages.busy-with-reforge")) | ||||||
|  | 			busyReforgingMsg = key.getString("messages.busy-with-reforge"); | ||||||
|  | 		if (key.keyExists("messages.cost")) | ||||||
|  | 			costMsg = key.getString("messages.cost"); | ||||||
|  | 		if (key.keyExists("messages.invalid-item")) | ||||||
|  | 			invalidItemMsg = key.getString("messages.invalid-item"); | ||||||
|  | 		if (key.keyExists("messages.start-reforge")) | ||||||
|  | 			startReforgeMsg = key.getString("messages.start-reforge"); | ||||||
|  | 		if (key.keyExists("messages.successful-reforge")) | ||||||
|  | 			successMsg = key.getString("messages.successful-reforge"); | ||||||
|  | 		if (key.keyExists("messages.fail-reforge")) | ||||||
|  | 			failMsg = key.getString("messages.fail-reforge"); | ||||||
|  | 		if (key.keyExists("messages.insufficient-funds")) | ||||||
|  | 			insufficientFundsMsg = key.getString("messages.insufficient-funds"); | ||||||
|  | 		if (key.keyExists("messages.cooldown-not-expired")) | ||||||
|  | 			cooldownUnexpiredMsg = key.getString("messages.cooldown-not-expired"); | ||||||
|  | 		if (key.keyExists("messages.item-changed-during-reforge")) | ||||||
|  | 			itemChangedMsg = key.getString("messages.item-changed-during-reforge"); | ||||||
|  | 		if (key.keyExists("delays-in-seconds.minimum")) | ||||||
|  | 			minReforgeDelay = key.getInt("delays-in-seconds.minimum"); | ||||||
|  | 		if (key.keyExists("delays-in-seconds.maximum")) | ||||||
|  | 			maxReforgeDelay = key.getInt("delays-in-seconds.maximum"); | ||||||
|  | 		if (key.keyExists("delays-in-seconds.reforge-cooldown")) | ||||||
|  | 			reforgeCooldown = key.getInt("delays-in-seconds.reforge-cooldown"); | ||||||
|  | 		if (key.keyExists("percent-chance-to-fail-reforge")) | ||||||
|  | 			failChance = key.getInt("percent-chance-to-fail-reforge"); | ||||||
|  | 		if (key.keyExists("maximum-enchantments")) | ||||||
|  | 			maxEnchantments = key.getInt("maximum-enchantments"); | ||||||
|  | 		if (key.keyExists("extra-enchantments-chance")) | ||||||
|  | 			extraEnchantmentChance = key.getInt("extra-enchantment-chance"); | ||||||
|  | 		if (key.keyExists("drop-item")) | ||||||
|  | 			dropItem = key.getBoolean("drop-item"); | ||||||
|  | 		if (key.keyExists("disable-cooldown")) | ||||||
|  | 			disablecooldown = key.getBoolean("disable-cooldown"); | ||||||
|  | 		if (key.keyExists("disable-delay")) | ||||||
|  | 			disabledelay = key.getBoolean("disable-delay"); | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	@EventHandler | ||||||
|  | 	public void onRightClick(net.citizensnpcs.api.event.NPCRightClickEvent event) { | ||||||
|  | 		if(this.npc!=event.getNPC()) return; | ||||||
|  |  | ||||||
|  | 		Player player = event.getClicker(); | ||||||
|  | 		if ((disablecooldown & (cooldowns.get(player.getName()) != (null)))) | ||||||
|  | 		{ | ||||||
|  | 			cooldowns.remove(player.getName()); | ||||||
|  | 		} | ||||||
|  | 		if (!player.hasPermission("blacksmith.reforge")) | ||||||
|  | 			return; | ||||||
|  |  | ||||||
|  | 		if (cooldowns.get(player.getName()) != null) { | ||||||
|  | 			if (!Calendar.getInstance().after(cooldowns.get(player.getName()))) { | ||||||
|  | 				player.sendMessage(cooldownUnexpiredMsg); | ||||||
|  | 				return; | ||||||
|  | 			} | ||||||
|  | 			cooldowns.remove(player.getName()); | ||||||
|  | 		} | ||||||
|  |  | ||||||
|  |  | ||||||
|  | 		ItemStack hand = player.getItemInHand(); | ||||||
|  |  | ||||||
|  | 		if(session!=null){ | ||||||
|  | 			//timeout | ||||||
|  | 			if ( System.currentTimeMillis() > _sessionstart + 10*1000 || this.npc.getEntity().getLocation().distance(session.player.getLocation()) > 20 ){ | ||||||
|  | 				session = null; | ||||||
|  | 			}	 | ||||||
|  | 		} | ||||||
|  |  | ||||||
|  |  | ||||||
|  | 		if (session != null) { | ||||||
|  | 			if (!session.isInSession(player)) { | ||||||
|  |  | ||||||
|  | 				player.sendMessage( busyWithPlayerMsg); | ||||||
|  | 				return;		 | ||||||
|  |  | ||||||
|  | 			} | ||||||
|  |  | ||||||
|  | 			if (session.isRunning()) { | ||||||
|  | 				player.sendMessage( busyReforgingMsg); | ||||||
|  | 				return; | ||||||
|  | 			} | ||||||
|  | 			if (session.handleClick()) | ||||||
|  | 				session = null; | ||||||
|  | 			else | ||||||
|  | 				reforge(npc, player); | ||||||
|  | 		} else { | ||||||
|  | 			if ((!plugin.isTool(hand) && !plugin.isArmor(hand)) | ||||||
|  | 					|| (!reforgeableItems.isEmpty() && !reforgeableItems.contains(hand.getType()))) { | ||||||
|  | 				player.sendMessage( invalidItemMsg); | ||||||
|  | 				return; | ||||||
|  | 			} | ||||||
|  | 			 | ||||||
|  | 			String cost = plugin.formatCost(player); | ||||||
|  | 			 | ||||||
|  | 			_sessionstart = System.currentTimeMillis(); | ||||||
|  | 			session = new ReforgeSession(player, npc); | ||||||
|  | 			player.sendMessage(costMsg.replace("<price>", cost).replace("<item>", | ||||||
|  | 					hand.getType().name().toLowerCase().replace('_', ' '))); | ||||||
|  |  | ||||||
|  | 		} | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	private long _sessionstart = System.currentTimeMillis(); | ||||||
|  |  | ||||||
|  | 	@Override | ||||||
|  | 	public void save(DataKey key) { | ||||||
|  | 		for (int i = 0; i < reforgeableItems.size(); i++) | ||||||
|  | 			key.getRelative("reforgeable-items").setString(String.valueOf(i), | ||||||
|  | 					reforgeableItems.get(i).name().toLowerCase().replace('_', '-')); | ||||||
|  |  | ||||||
|  | 		key.setString("messages.busy-with-player", busyWithPlayerMsg); | ||||||
|  | 		key.setString("messages.busy-with-reforge", busyReforgingMsg); | ||||||
|  | 		key.setString("messages.cost", costMsg); | ||||||
|  | 		key.setString("messages.invalid-item", invalidItemMsg); | ||||||
|  | 		key.setString("messages.start-reforge", startReforgeMsg); | ||||||
|  | 		key.setString("messages.successful-reforge", successMsg); | ||||||
|  | 		key.setString("messages.fail-reforge", failMsg); | ||||||
|  | 		key.setString("messages.insufficient-funds", insufficientFundsMsg); | ||||||
|  | 		key.setString("messages.cooldown-not-expired", cooldownUnexpiredMsg); | ||||||
|  | 		key.setString("messages.item-changed-during-reforge", itemChangedMsg); | ||||||
|  | 		key.setInt("delays-in-seconds.minimum", minReforgeDelay); | ||||||
|  | 		key.setInt("delays-in-seconds.maximum", maxReforgeDelay); | ||||||
|  | 		key.setInt("delays-in-seconds.reforge-cooldown", reforgeCooldown); | ||||||
|  | 		key.setInt("percent-chance-to-fail-reforge", failChance); | ||||||
|  | 		key.setInt("percent-chance-for-extra-enchantment", extraEnchantmentChance); | ||||||
|  | 		key.setInt("maximum-enchantments", maxEnchantments); | ||||||
|  | 		key.setBoolean("drop-item", dropItem); | ||||||
|  |         key.setBoolean("disable-delay", disabledelay); | ||||||
|  |         key.setBoolean("disable-cooldown", disablecooldown); | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	private void reforge(NPC npc, Player player) { | ||||||
|  | 		player.sendMessage( startReforgeMsg); | ||||||
|  |                  | ||||||
|  |                 //plugin.deposit(npc, player); // CitiTrader dependency outdated and broken | ||||||
|  |                  | ||||||
|  |                 plugin.withdraw(player); | ||||||
|  | 		session.beginReforge(); | ||||||
|  | 		if (npc.getEntity() instanceof Player) | ||||||
|  | 			((Player) npc.getEntity()).setItemInHand(player.getItemInHand()); | ||||||
|  |         else | ||||||
|  |         	((LivingEntity) npc.getEntity()).getEquipment().setItemInHand(player.getItemInHand()); | ||||||
|  | 		player.setItemInHand(null); | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	private class ReforgeSession implements Runnable { | ||||||
|  | 		private final Player player; | ||||||
|  | 		private final NPC npc; | ||||||
|  | 		private final ItemStack reforge; | ||||||
|  | 		private int taskId; | ||||||
|  |  | ||||||
|  | 		private ReforgeSession(Player player, NPC npc) { | ||||||
|  | 			this.player = player; | ||||||
|  | 			this.npc = npc; | ||||||
|  | 			reforge = player.getItemInHand(); | ||||||
|  | 		} | ||||||
|  |  | ||||||
|  | 		@Override | ||||||
|  | 		public void run() { | ||||||
|  | 			player.sendMessage("dropitem:" + dropItem); | ||||||
|  | 			player.sendMessage( reforgeItemInHand() ? successMsg : failMsg); | ||||||
|  | 			if (npc.getEntity() instanceof Player) | ||||||
|  | 				((Player) npc.getEntity()).setItemInHand(null); | ||||||
|  |             else | ||||||
|  |                 ((LivingEntity) npc.getEntity()).getEquipment().setItemInHand(null); | ||||||
|  | 			if (!disabledelay) | ||||||
|  | 			{ | ||||||
|  | 				if (dropItem) | ||||||
|  | 					player.getWorld().dropItemNaturally(npc.getEntity().getLocation(), reforge); | ||||||
|  | 				else { | ||||||
|  | 					player.getInventory().addItem(reforge); | ||||||
|  | 					/* | ||||||
|  | 					oldmethode ? | ||||||
|  | 					for (ItemStack stack : player.getInventory().addItem(reforge).values()) | ||||||
|  | 						player.getWorld().dropItemNaturally(npc.getEntity().getLocation(), stack); | ||||||
|  | 					 */ | ||||||
|  | 				} | ||||||
|  | 			} | ||||||
|  | 			else | ||||||
|  | 			{ | ||||||
|  | 				player.setItemInHand(reforge); | ||||||
|  | 			} | ||||||
|  | 			session = null; | ||||||
|  | 			// Start cooldown | ||||||
|  | 			Calendar wait = Calendar.getInstance(); | ||||||
|  | 			wait.add(Calendar.SECOND, reforgeCooldown); | ||||||
|  | 			cooldowns.put(player.getName(), wait); | ||||||
|  | 		} | ||||||
|  |  | ||||||
|  | 		private boolean reforgeItemInHand() { | ||||||
|  | 			Random random = new Random(); | ||||||
|  | 			if (random.nextInt(100) < failChance) { | ||||||
|  | 				for (Enchantment enchantment : reforge.getEnchantments().keySet()) { | ||||||
|  | 					// Remove or downgrade enchantments | ||||||
|  | 					if (random.nextBoolean()) | ||||||
|  | 						reforge.removeEnchantment(enchantment); | ||||||
|  | 					else { | ||||||
|  | 						if (reforge.getEnchantmentLevel(enchantment) > 1) { | ||||||
|  | 							reforge.removeEnchantment(enchantment); | ||||||
|  | 							reforge.addEnchantment(enchantment, 1); | ||||||
|  | 						} | ||||||
|  | 					} | ||||||
|  | 				} | ||||||
|  | 				// Damage the item | ||||||
|  | 				short durability = (short) (reforge.getDurability() + reforge.getDurability() * random.nextInt(8)); | ||||||
|  | 				short maxDurability = reforge.getType().getMaxDurability(); | ||||||
|  | 				if (durability <= 0) | ||||||
|  | 					durability = (short) (maxDurability / 3); | ||||||
|  | 				else if (reforge.getDurability() + durability > maxDurability) | ||||||
|  | 					durability = (short) (maxDurability - random.nextInt(maxDurability - 25)); | ||||||
|  | 				reforge.setDurability(durability); | ||||||
|  | 				return false; | ||||||
|  | 			} | ||||||
|  |  | ||||||
|  | 			reforge.setDurability((short) 0); | ||||||
|  |  | ||||||
|  | 			// Add random enchantments | ||||||
|  |  | ||||||
|  |  | ||||||
|  | 			// If durability is full, chance is multiplied by 4. Seems unbalanced, so disabled for now. | ||||||
|  | 			/*if (reforge.getDurability() == 0) | ||||||
|  |             	chance *= 4; | ||||||
|  |             else */ | ||||||
|  |  | ||||||
|  | 			int roll = random.nextInt(100); | ||||||
|  | 			if (roll < extraEnchantmentChance && reforge.getEnchantments().keySet().size() < maxEnchantments){ | ||||||
|  |  | ||||||
|  | 				Enchantment enchantment = Enchantment.getByName(enchantments[random.nextInt(enchantments.length)]); | ||||||
|  | 				if (enchantment.canEnchantItem(reforge)) reforge.addEnchantment(enchantment, random.nextInt(enchantment.getMaxLevel() - enchantment.getStartLevel()) + enchantment.getStartLevel()); | ||||||
|  |  | ||||||
|  | 			} | ||||||
|  |  | ||||||
|  | 			return true; | ||||||
|  | 		} | ||||||
|  |  | ||||||
|  | 		// Return if the session should end | ||||||
|  | 		private boolean handleClick() { | ||||||
|  | 			// Prevent player from switching items during session | ||||||
|  | 			if (!reforge.equals(player.getItemInHand())) { | ||||||
|  | 				player.sendMessage( itemChangedMsg); | ||||||
|  | 				return true; | ||||||
|  | 			} | ||||||
|  | 			if (!plugin.doesPlayerHaveEnough(player)) { | ||||||
|  | 				player.sendMessage( insufficientFundsMsg); | ||||||
|  | 				return true; | ||||||
|  | 			} | ||||||
|  | 			return false; | ||||||
|  | 		} | ||||||
|  |  | ||||||
|  | 		private boolean isRunning() { | ||||||
|  | 			return plugin.getServer().getScheduler().isQueued(taskId); | ||||||
|  | 		} | ||||||
|  |  | ||||||
|  | 		private boolean isInSession(Player other) { | ||||||
|  | 			return player.getName().equals(other.getName()); | ||||||
|  | 		} | ||||||
|  |  | ||||||
|  | 		private void beginReforge() { | ||||||
|  | 			if (!disablecooldown) | ||||||
|  | 			{ | ||||||
|  | 			taskId = plugin | ||||||
|  | 					.getServer() | ||||||
|  | 					.getScheduler() | ||||||
|  | 					.scheduleSyncDelayedTask(plugin, this, | ||||||
|  | 							(new Random().nextInt(maxReforgeDelay) + minReforgeDelay) * 20); | ||||||
|  | 			} | ||||||
|  | 			else | ||||||
|  | 			{ | ||||||
|  | 				taskId = plugin | ||||||
|  | 						.getServer() | ||||||
|  | 						.getScheduler() | ||||||
|  | 						.scheduleSyncDelayedTask(plugin, this,0); | ||||||
|  | 			} | ||||||
|  | 		} | ||||||
|  | 	} | ||||||
|  | } | ||||||
| @@ -11,10 +11,11 @@ public class Settings { | |||||||
|     private final YamlStorage config; |     private final YamlStorage config; | ||||||
|  |  | ||||||
|     public Settings(BlacksmithPlugin plugin) { |     public Settings(BlacksmithPlugin plugin) { | ||||||
|         config = new YamlStorage(plugin.getDataFolder() + File.separator + "config.yml", "Blacksmith Configuration"); |         config = new YamlStorage(new File(plugin.getDataFolder() + File.separator + "config.yml"), "Blacksmith Configuration"); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public void load() { |     public void load() { | ||||||
|  |         config.load(); | ||||||
|         DataKey root = config.getKey(""); |         DataKey root = config.getKey(""); | ||||||
|         for (Setting setting : Setting.values()) |         for (Setting setting : Setting.values()) | ||||||
|             if (!root.keyExists(setting.path)) |             if (!root.keyExists(setting.path)) | ||||||
| @@ -22,10 +23,6 @@ public class Settings { | |||||||
|             else |             else | ||||||
|                 setting.set(root.getRaw(setting.path)); |                 setting.set(root.getRaw(setting.path)); | ||||||
|  |  | ||||||
|         save(); |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     public void save() { |  | ||||||
|         config.save(); |         config.save(); | ||||||
|     } |     } | ||||||
|  |  | ||||||
| @@ -35,31 +32,35 @@ public class Settings { | |||||||
|  |  | ||||||
|     public enum Setting { |     public enum Setting { | ||||||
|         BASE_PRICE("base-prices.default", 10), |         BASE_PRICE("base-prices.default", 10), | ||||||
|         BUSY_WITH_PLAYER_MESSAGE("defaults.messages.busy-with-player", "<c>I'm busy at the moment. Come back later!"), |         PRICE_PER_DURABILITY_POINT("price-per-durability-point.default", 1), | ||||||
|         BUSY_WITH_REFORGE_MESSAGE("defaults.messages.busy-with-reforge", "<c>I'm working on it. Be patient!"), |         BUSY_WITH_PLAYER_MESSAGE("defaults.messages.busy-with-player", "§cI'm busy at the moment. Come back later!"), | ||||||
|  |         BUSY_WITH_REFORGE_MESSAGE("defaults.messages.busy-with-reforge", "§cI'm working on it. Be patient!"), | ||||||
|         COOLDOWN_UNEXPIRED_MESSAGE( |         COOLDOWN_UNEXPIRED_MESSAGE( | ||||||
|                 "defaults.messages.cooldown-not-expired", |                 "defaults.messages.cooldown-not-expired", | ||||||
|                 "<c>You've already had your chance! Give me a break!"), |                 "§cYou've already had your chance! Give me a break!"), | ||||||
|         COST_MESSAGE( |         COST_MESSAGE( | ||||||
|                 "defaults.messages.cost", |                 "defaults.messages.cost", | ||||||
|                 "<e>It will cost <a><price> <e>to reforge that <a><item><e>! Click again to reforge!"), |                 "§eIt will cost §a<price> §eto reforge that §a<item>§e! Click again to reforge!"), | ||||||
|         DROP_ITEM("defaults.drop-item", true), |         DROP_ITEM("defaults.dropitem", true), | ||||||
|  |         DISABLE_COOLDOWN("defaults.disablecooldown", false), | ||||||
|  |         DISABLE_DELAY("defaults.disabledelay", false), | ||||||
|         ENCHANTMENT_MODIFIER("enchantment-modifiers.default", 5), |         ENCHANTMENT_MODIFIER("enchantment-modifiers.default", 5), | ||||||
|         FAIL_CHANCE("defaults.percent-chance-to-fail-reforge", 10), |         FAIL_CHANCE("defaults.percent-chance-to-fail-reforge", 10), | ||||||
|         FAIL_MESSAGE("defaults.messages.fail-reforge", "<c>Whoops! Didn't mean to do that! Maybe next time?"), |         FAIL_MESSAGE("defaults.messages.fail-reforge", "§cWhoops! Didn't mean to do that! Maybe next time?"), | ||||||
|         INSUFFICIENT_FUNDS_MESSAGE( |         INSUFFICIENT_FUNDS_MESSAGE( | ||||||
|                 "defaults.messages.insufficient-funds", |                 "defaults.messages.insufficient-funds", | ||||||
|                 "<c>You don't have enough money to reforge that item!"), |                 "§cYou don't have enough money to reforge that item!"), | ||||||
|         INVALID_ITEM_MESSAGE("defaults.messages.invalid-item", "<c>I'm sorry, but I don't know how to reforge that!"), |         INVALID_ITEM_MESSAGE("defaults.messages.invalid-item", "§cI'm sorry, but I don't know how to reforge that!"), | ||||||
|         ITEM_UNEXPECTEDLY_CHANGED_MESSAGE( |         ITEM_UNEXPECTEDLY_CHANGED_MESSAGE( | ||||||
|                 "defaults.messages.item-changed-during-reforge", |                 "defaults.messages.item-changed-during-reforge", | ||||||
|                 "<c>That's not the item you wanted to reforge before!"), |                 "§cThat's not the item you wanted to reforge before!"), | ||||||
|  |         EXTRA_ENCHANTMENT_CHANCE("defaults.percent-chance-for-extra-enchantment", 5), | ||||||
|         MAX_ENCHANTMENTS("defaults.maximum-enchantments", 3), |         MAX_ENCHANTMENTS("defaults.maximum-enchantments", 3), | ||||||
|         MAX_REFORGE_DELAY("defaults.delays-in-seconds.maximum", 30), |         MAX_REFORGE_DELAY("defaults.delays-in-seconds.maximum", 30), | ||||||
|         MIN_REFORGE_DELAY("defaults.delays-in-seconds.minimum", 5), |         MIN_REFORGE_DELAY("defaults.delays-in-seconds.minimum", 5), | ||||||
|         REFORGE_COOLDOWN("defaults.delays-in-seconds.reforge-cooldown", 60), |         REFORGE_COOLDOWN("defaults.delays-in-seconds.reforge-cooldown", 60), | ||||||
|         START_REFORGE_MESSAGE("defaults.messages.start-reforge", "<e>Ok, let's see what I can do..."), |         START_REFORGE_MESSAGE("defaults.messages.start-reforge", "§eOk, let's see what I can do..."), | ||||||
|         SUCCESS_MESSAGE("defaults.messages.successful-reforge", "<a>There you go! All better!"); |         SUCCESS_MESSAGE("defaults.messages.successful-reforge", "There you go! All better!"); | ||||||
|  |  | ||||||
|         private String path; |         private String path; | ||||||
|         private Object value; |         private Object value; | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 HurricanKai
					HurricanKai