Errors for no reason?

Discussion in 'Plugin Development' started by Sakarakis, Nov 23, 2014.

Thread Status:
Not open for further replies.
  1. Offline

    Sakarakis

    Picture of the error: http://prntscr.com/59jau3

    Code:
    Code:java
    1. package main;
    2.  
    3. import com.earth2me.essentials.Essentials;
    4. import com.earth2me.essentials.User;
    5. import java.math.BigDecimal;
    6. import java.util.ArrayList;
    7. import java.util.HashMap;
    8. import java.util.List;
    9. import java.util.Map;
    10. import org.bukkit.Bukkit;
    11. import org.bukkit.ChatColor;
    12. import org.bukkit.Material;
    13. import org.bukkit.Server;
    14. import org.bukkit.block.Block;
    15. import org.bukkit.block.BlockState;
    16. import org.bukkit.block.Sign;
    17. import org.bukkit.command.Command;
    18. import org.bukkit.command.CommandSender;
    19. import org.bukkit.command.PluginCommand;
    20. import org.bukkit.configuration.ConfigurationSection;
    21. import org.bukkit.configuration.file.FileConfiguration;
    22. import org.bukkit.entity.Player;
    23. import org.bukkit.event.EventHandler;
    24. import org.bukkit.event.Listener;
    25. import org.bukkit.event.block.Action;
    26. import org.bukkit.event.block.BlockBreakEvent;
    27. import org.bukkit.event.player.PlayerInteractEvent;
    28. import org.bukkit.event.player.PlayerTeleportEvent;
    29. import org.bukkit.inventory.Inventory;
    30. import org.bukkit.inventory.ItemStack;
    31. import org.bukkit.inventory.meta.ItemMeta;
    32. import org.bukkit.permissions.PermissionAttachmentInfo;
    33. import org.bukkit.plugin.PluginManager;
    34. import org.bukkit.plugin.java.JavaPlugin;
    35.  
    36. public class SellAllSigns
    37. extends JavaPlugin
    38. implements Listener
    39. {
    40. Map<String, Boolean> sasign = new HashMap();
    41. boolean globalmult;
    42. double globalmultnum;
    43.  
    44. public void onEnable()
    45. {
    46. getServer().getPluginManager().registerEvents(this, this);
    47. getCommand("globalmultiplier").setPermissionMessage(ChatColor.DARK_RED + "You are not allowed to use that command.");
    48. ConfigurationSection sec = getConfig().getConfigurationSection("SASigns");
    49. ConfigurationSection storage = getConfig().getConfigurationSection("Storage");
    50. for (String key : sec.getKeys(false)) {
    51. this.sasign.put(key, Boolean.valueOf(true));
    52. }
    53. this.globalmult = storage.getBoolean("global");
    54. this.globalmultnum = storage.getDouble("globalnum");
    55. reloadConfig();
    56. saveConfig();
    57. }
    58.  
    59. public void onDisable()
    60. {
    61. getConfig().createSection("SASigns", this.sasign);
    62. ConfigurationSection storage = getConfig().createSection("Storage");
    63. storage.set("global", Boolean.valueOf(this.globalmult));
    64. storage.set("globalnum", Double.valueOf(this.globalmultnum));
    65. saveConfig();
    66. }
    67.  
    68. @EventHandler
    69. public void sign(PlayerInteractEvent event)
    70. {
    71. Player player = event.getPlayer();
    72. if ((event.getAction() == Action.RIGHT_CLICK_BLOCK) || (event.getAction() == Action.LEFT_CLICK_BLOCK))
    73. {
    74. Block block = event.getClickedBlock();
    75. if ((block.getType() == Material.SIGN_POST) || (block.getType() == Material.WALL_SIGN))
    76. {
    77. BlockState state = block.getState();
    78. if ((state instanceof Sign))
    79. {
    80. Sign sign = (Sign)state;
    81. String str = block.toString();
    82. String[] lines = sign.getLines();
    83. String line2 = lines[1];
    84. String line3 = lines[2];
    85. if (this.sasign.containsKey(str))
    86. {
    87. line2 = line2.replace(" ", "_");
    88. Material mat = Material.valueOf(line2.toUpperCase());
    89.  
    90. String sprice = line3;
    91. sprice = getPriceFrom(sprice);
    92. double price = Double.valueOf(sprice).doubleValue();
    93. double displayprice = price;
    94. Inventory inv = player.getInventory();
    95. int totalitems = 0;
    96. double totalmoney = 0.0D;
    97. int slotnum = 0;
    98. double displaymult = 0.0D;
    99. for (ItemStack item : inv.getContents()) {
    100. if ((item != null) && (item.getType() != Material.AIR))
    101. {
    102. if (item.getType() == mat)
    103. {
    104. int amount = item.getAmount();
    105. if (determineMultiplier(player))
    106. {
    107. double mult = multiply(player);
    108. if (this.globalmult) {
    109. mult += this.globalmultnum - 1.0D;
    110. }
    111. displaymult = mult;
    112. price *= mult;
    113. }
    114. if ((this.globalmult) && (!determineMultiplier(player)))
    115. {
    116. displaymult = this.globalmultnum;
    117. price *= this.globalmultnum;
    118. }
    119. double newprice = price * amount;
    120. User user = ((Essentials)Bukkit.getPluginManager().getPlugin("Essentials")).getUser(player);
    121. BigDecimal newmoney = new BigDecimal(user.getMoney().doubleValue() + newprice);
    122. user.setMoney(newmoney);
    123. inv.setItem(slotnum, new ItemStack(Material.AIR));
    124. slotnum++;
    125. totalitems += amount;
    126. totalmoney += newprice;
    127. }
    128. else
    129. {
    130. slotnum++;
    131. }
    132. }
    133. else {
    134. slotnum++;
    135. }
    136. }
    137. if ((totalitems == 0) && (totalmoney == 0.0D))
    138. {
    139. player.sendMessage(ChatColor.RED + "Nothing to sell!");
    140. return;
    141. }
    142. if ((this.globalmult) || (determineMultiplier(player))) {
    143. player.sendMessage(ChatColor.GREEN + totalitems + " items sold for " + "$" + Math.round(totalmoney) + " ($" + displayprice + "/ea x" + displaymult + ")");
    144. } else {
    145. player.sendMessage(ChatColor.GREEN + totalitems + " items sold for " + "$" + Math.round(totalmoney) + " ($" + displayprice + "/ea)");
    146. }
    147. if (!determineMultiplier(player)) {
    148. player.sendMessage("§9Purchase a §a§lPRICE MULTIPLIER §9by using /buy");
    149. }
    150. player.updateInventory();
    151. return;
    152. }
    153. if ((player.getItemInHand().getType() == Material.STICK) && (player.getItemInHand().getItemMeta().getDisplayName().equals(ChatColor.DARK_RED + "Sell All Sign Stick")) &&
    154. (player.isOp()))
    155. {
    156. String strr = block.toString();
    157. this.sasign.put(strr, Boolean.valueOf(true));
    158. player.sendMessage(ChatColor.GOLD + "Sell All Sign Created!");
    159. }
    160. }
    161. }
    162. }
    163. }
    164.  
    165. @EventHandler
    166. public void bbreak(BlockBreakEvent event)
    167. {
    168. Player player = event.getPlayer();
    169. Block block = event.getBlock();
    170. if (((block.getType() == Material.SIGN_POST) || (block.getType() == Material.WALL_SIGN)) &&
    171. (player.isOp()))
    172. {
    173. BlockState state = block.getState();
    174. if ((state instanceof Sign))
    175. {
    176. String bstring = block.toString();
    177. if (this.sasign.containsKey(bstring))
    178. {
    179. player.sendMessage(ChatColor.RED + "Sell All Sign Destroyed");
    180. this.sasign.remove(bstring);
    181. }
    182. }
    183. }
    184. }
    185.  
    186. @EventHandler
    187. public void teleport(PlayerTeleportEvent event)
    188. {
    189. Player player = event.getPlayer();
    190. if (player.hasPermission("carrot.fly")) {
    191. player.setAllowFlight(true);
    192. }
    193. }
    194.  
    195. public String getPriceFrom(String str)
    196. {
    197. for (char a : str.toCharArray()) {
    198. if ((a != '1') && (a != '2') && (a != '3') && (a != '4') && (a != '5') && (a != '6') && (a != '7') && (a != '8') && (a != '9') && (a != '0') && (a != '.'))
    199. {
    200. String s = String.valueOf(a);
    201. str = str.replace(s, "");
    202. }
    203. }
    204. return str;
    205. }
    206.  
    207. public double multiply(Player p)
    208. {
    209. double multiplier = 0.0D;
    210. for (String perm : getPerms(p)) {
    211. if (perm.startsWith("assigns.multipliers."))
    212. {
    213. String[] split = perm.split(".");
    214. String num = split[2];
    215. double dubnum = Double.parseDouble(num);
    216. multiplier = dubnum;
    217. break;
    218. }
    219. }
    220. return multiplier;
    221. }
    222.  
    223. public boolean determineMultiplier(Player p)
    224. {
    225. for (String perm : getPerms(p)) {
    226. if (perm.startsWith("assigns.multipliers.")) {
    227. return true;
    228. }
    229. }
    230. return false;
    231. }
    232.  
    233. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args)
    234. {
    235. if (cmd.getName().equalsIgnoreCase("globalmultiplier"))
    236. {
    237. if (args.length != 1)
    238. {
    239. sender.sendMessage(ChatColor.RED + "Usage: /globalmultiplier <number>");
    240. return true;
    241. }
    242. String numstring = args[0];
    243. numstring = getPriceFrom(numstring);
    244. double num = Double.parseDouble(numstring);
    245. if (num < 1.0D) {
    246. this.globalmult = false;
    247. } else {
    248. this.globalmult = true;
    249. }
    250. this.globalmultnum = num;
    251. sender.sendMessage(ChatColor.GOLD + "Global multiplier has been set to " + ChatColor.RED + num);
    252. }
    253. return true;
    254. }
    255.  
    256. public List<String> getPerms(Player player)
    257. {
    258. List<String> perms = new ArrayList();
    259. for (PermissionAttachmentInfo info : player.getEffectivePermissions()) {
    260. if (info.getValue()) {
    261. perms.add(info.getPermission());
    262. }
    263. }
    264. return perms;
    265. }
    266. }
    267.  



    External JARs:
    - bukkit-1.7.9-R0.2
    - Essentials


    Please help me ASAP and I'm not that advanced with Java.
     
  2. Offline

    teej107

    There is always a reason for an error. That error in your case is that ChatColor is not a String and it needs to be. You can make it into a String by simply calling .toString().
     
  3. Offline

    Sakarakis

    teej107 Thank you for your help.
     
Thread Status:
Not open for further replies.

Share This Page