Solved HashMap .get() returning error

Discussion in 'Plugin Development' started by ariaDEE, Aug 19, 2014.

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

    ariaDEE

    Hey. So I've been trying to implement a teleport request function into my plugin and can't seem to get it to work. My problem is: I'm using a HashMap to store the player and target player's names in, but in my tpaccept command, I cannot retrieve the player names.
    Code:java
    1. if(args[0].equalsIgnoreCase("tpa") || args[0].equalsIgnoreCase("tp")){
    2. if(isMianite.contains(player.getUniqueId()) || isDianite.contains(player.getUniqueId()) || isIanite.contains(player.getUniqueId())){
    3. if(args.length == 1){
    4. player.sendMessage(ChatColor.RED + "You must specify a player you would like to request a teleport to.");
    5. }else{
    6. if(prayPoints.containsKey(player.getUniqueId())){
    7. if(prayPoints.get(player.getUniqueId()) >= 10){
    8. Player source = (Player) sender;
    9. Player target = (Bukkit.getServer().getPlayer(args[1]));
    10. teleport.put(target, source);
    11. target.sendMessage(ChatColor.AQUA + player.getName() + ChatColor.RED + " wishes to teleport to you. " + ChatColor.AQUA + "/pray tpaccept or /pray tpdeny?");
    12. player.sendMessage(ChatColor.AQUA + "You have sucessfully sent a teleport request to " + ChatColor.RED + target.getName() + ChatColor.AQUA + " via the Gods.");
    13. }
    14. }
    15. }
    16. }
    17. }
    18. }
    19. if(args[0].equalsIgnoreCase("tpaccept")){
    20. player.sendMessage("testicals 123");
    21. if(teleport.containsValue(player.getUniqueId())){
    22. Player requester = teleport.get(source);
    23. requester.teleport(player);
    24. player.sendMessage(ChatColor.AQUA + "You sucessfully accepted the teleportation request.");
    25. teleport.get(player).sendMessage(ChatColor.AQUA + "Your request has been accepted.");
    26.  
    27. }

    Code:java
    1. teleport.get(source);
    (source) always returns an error: source cannot be resolved to a variable and I can't figure out why.

    Cheers for any help!
     
  2. Offline

    iBecameALoaf

    Please show your full code, as we won't be able to help you without the full class.
    P.S nice debug messages...
     
  3. Offline

    br456

    ariaDEE
    It always good pratice never to store a player object in a hashmap or arraylist, this can cause memory leaks.
    Try to change to storing the names in hashmaps
     
  4. Offline

    ariaDEE

    Code:java
    1. if(args[0].equalsIgnoreCase("tpa") || args[0].equalsIgnoreCase("tp")){
    2. if(isMianite.contains(player.getUniqueId()) || isDianite.contains(player.getUniqueId()) || isIanite.contains(player.getUniqueId())){
    3. if(args.length == 1){
    4. player.sendMessage(ChatColor.RED + "You must specify a player you would like to request a teleport to.");
    5. }else{
    6. if(prayPoints.containsKey(player.getUniqueId())){
    7. if(prayPoints.get(player.getUniqueId()) >= 10){
    8. Player source = (Player) sender;
    9. Player target = (Bukkit.getServer().getPlayer(args[1]));
    10. teleport.put(target.getName(), source.getName());
    11. target.sendMessage(ChatColor.AQUA + player.getName() + ChatColor.RED + " wishes to teleport to you. " + ChatColor.AQUA + "/pray tpaccept or /pray tpdeny?");
    12. player.sendMessage(ChatColor.AQUA + "You have sucessfully sent a teleport request to " + ChatColor.RED + target.getName() + ChatColor.AQUA + " via the Gods.");
    13. }
    14. }
    15. }
    16. }
    17. }
    18. }
    19. if(args[0].equalsIgnoreCase("tpaccept")){
    20. if(teleport.containsValue(player.getUniqueId())){
    21. Player requester = teleport.get(source);
    22. requester.teleport(player);
    23. player.sendMessage(ChatColor.AQUA + "You sucessfully accepted the teleportation request.");
    24. teleport.get(source).sendMessage(ChatColor.AQUA + "Your request has been accepted.");
    25.  
    26. }
    27. }if(args[0].equalsIgnoreCase("tpdeny")){
    28. if(teleport.containsValue(player.getUniqueId())){
    29. player.sendMessage(ChatColor.AQUA + "You sucessfully denied the teleportation request.");
    30. teleport.get(player).sendMessage(ChatColor.AQUA + "Your request has been denied.");
    31. }
    32. }

    iBecameALoaf
    These are the most current relevant parts of my class.

    Code:java
    1. public HashMap<Player, Player> teleport = new HashMap<Player, Player>();


    br456 I've already tried storing the names into a HashMap but the same error still gets returned.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 9, 2016
  5. Offline

    br456

    ariaDEE
    Just store the players names in the hashmap, and use Bukkit.getServer().getPlayerExact(teleport.get(player.getName());
    to retrieve the player from the hashmap

    How did you retrieve them?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 9, 2016
  6. Offline

    xTigerRebornx

    ariaDEE You've never defined what "source" is, so how do you expect to use it.
     
  7. Offline

    stormneo7

    The way you are doing it is insufficient. When storing an object with an object, it'll override it if you restore it.
    For example, if I stored "A", "B" then stored "A", "C", the AB would have never existed.
    Simply, change your HashMap to HashMap<String, List<String>>. I suggest using player names or uuids.

    Edit:
    Code:java
    1. Player target = (Bukkit.getServer().getPlayer(args[1]));

    If that player isn't online, it'll return null. So basically you've put (null, "PlayerName") into the HashMap. Run a check to see if the player != null and .isOnline()
     
  8. Offline

    br456

    Wow how did I miss that...
     
  9. Offline

    fireblast709

    Weak referencing please :3
     
  10. Offline

    ariaDEE

  11. Offline

    br456

    ariaDEE
    Can you post the whole class?
     
  12. Offline

    ariaDEE

    stormneo7 I've fixed the online player issue, and have also changed my HashMap to <String, List> but am still getting the same error.

    br456 It's all pretty ugly, but if you insist:
    Code:java
    1. package me.SuperiorCallz.Mianite;
    2.  
    3. import java.util.ArrayList;
    4. import java.util.HashMap;
    5. import java.util.List;
    6. import java.util.Random;
    7. import java.util.UUID;
    8. import java.util.logging.Logger;
    9.  
    10. import org.bukkit.Bukkit;
    11. import org.bukkit.ChatColor;
    12. import org.bukkit.Location;
    13. import org.bukkit.Material;
    14. import org.bukkit.command.Command;
    15. import org.bukkit.command.CommandSender;
    16. import org.bukkit.entity.Entity;
    17. import org.bukkit.entity.Monster;
    18. import org.bukkit.entity.Player;
    19. import org.bukkit.event.EventHandler;
    20. import org.bukkit.event.Listener;
    21. import org.bukkit.event.entity.EntityDamageByEntityEvent;
    22. import org.bukkit.event.entity.EntityDeathEvent;
    23. import org.bukkit.event.player.AsyncPlayerChatEvent;
    24. import org.bukkit.event.player.PlayerJoinEvent;
    25. import org.bukkit.event.player.PlayerMoveEvent;
    26. import org.bukkit.inventory.ItemStack;
    27. import org.bukkit.plugin.PluginDescriptionFile;
    28. import org.bukkit.plugin.java.JavaPlugin;
    29.  
    30. public class Mianite extends JavaPlugin implements Listener{
    31.  
    32. public final Logger logger = Logger.getLogger("Minecraft");
    33. public static Mianite plugin;
    34.  
    35. public ArrayList<UUID> cantMove = new ArrayList<UUID>();
    36.  
    37. public List<UUID> isMianite = new ArrayList<UUID>();
    38. public List<UUID> isDianite = new ArrayList<UUID>();
    39. public List<UUID> isIanite = new ArrayList<UUID>();
    40. public HashMap<UUID, Long> coolDown = new HashMap<UUID, Long>();
    41. public HashMap<UUID, Long> coolDownKill = new HashMap<UUID, Long>();
    42. public HashMap<UUID, Long> coolDownSpawn = new HashMap<UUID, Long>();
    43. public HashMap<UUID, Integer> mobKillAmount = new HashMap<UUID, Integer>();
    44. public HashMap<UUID, Integer> prayPoints = new HashMap<UUID, Integer>();
    45. public HashMap<String, List> teleport = new HashMap<String, List>();
    46.  
    47. @Override
    48. public void onEnable() {
    49. PluginDescriptionFile pdfFile = this.getDescription();
    50. this.logger.info(pdfFile.getName() + " version " + pdfFile.getVersion() + " has been enabled.");
    51. getServer().getPluginManager().registerEvents(this, this);
    52. getConfig().options().copyDefaults(true);
    53. saveConfig();
    54. try {
    55. isMianite = SLAPI.load("isMianite.bin");
    56. isDianite = SLAPI.load("isDianite.bin");
    57. isIanite = SLAPI.load("isIanite.bin");
    58. coolDown = SLAPI.load("coolDown.bin");
    59. coolDownKill = SLAPI.load("coolDownKill.bin");
    60. prayPoints = SLAPI.load("prayPoints.bin");
    61. } catch(Exception e) {
    62. //handle the exception
    63. e.printStackTrace();
    64. }
    65. }
    66.  
    67. @Override
    68. public void onDisable() {
    69. PluginDescriptionFile pdfFile = this.getDescription();
    70. this.logger.info(pdfFile.getName() + " has been disabled.");
    71. getConfig().options().copyDefaults(true);
    72. saveConfig();
    73.  
    74. try {
    75. SLAPI.save(isMianite,"isMianite.bin");
    76. SLAPI.save(isDianite,"isDianite.bin");
    77. SLAPI.save(isIanite,"isIanite.bin");
    78. SLAPI.save(coolDown,"coolDown.bin");
    79. SLAPI.save(coolDownKill,"coolDownKill.bin");
    80. SLAPI.save(prayPoints,"prayPoints.bin");
    81. } catch(Exception e) {
    82. e.printStackTrace();
    83. }
    84. }
    85.  
    86.  
    87. @EventHandler
    88. public void move(PlayerMoveEvent move)
    89. {
    90. //Check if player is in the cantMove list, and if so, don't allow them to move.
    91. if(!move.getPlayer().hasPermission("mianite.canMove")){
    92. if(cantMove.contains(move.getPlayer().getUniqueId())){
    93. Location from=move.getFrom();
    94. Location to=move.getTo();
    95. double x=Math.floor(from.getX());
    96. double z=Math.floor(from.getZ());
    97. if(Math.floor(to.getX())!=x||Math.floor(to.getZ())!=z)
    98. {
    99. x+=.5;
    100. z+=.5;
    101. move.getPlayer().teleport(new Location(from.getWorld(),x,from.getY(),z,from.getYaw(),from.getPitch()));
    102. }
    103. move.getPlayer().sendMessage(ChatColor.AQUA + "You may not move until a team has been picked. " + ChatColor.GREEN + "/mianite," + ChatColor.DARK_RED + " /dianite, " + ChatColor.YELLOW + "/ianite");
    104. }
    105. }
    106. }
    107.  
    108. @EventHandler
    109. public void onPlayerJoinEvent(PlayerJoinEvent event) {
    110. if(!event.getPlayer().hasPlayedBefore()) {
    111. event.getPlayer().sendMessage(ChatColor.AQUA + "Welcome to the world of Mianite. Pick your team. " + ChatColor.GREEN + "/mianite," + ChatColor.DARK_RED + " /dianite, " + ChatColor.YELLOW + "/ianite");
    112. cantMove.add(event.getPlayer().getUniqueId());
    113. }
    114. }
    115.  
    116. @SuppressWarnings("deprecation")
    117. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args){
    118. Player player = (Player) sender;
    119. if(cmd.getName().equalsIgnoreCase("mianite")){
    120. if(!(isDianite.contains(player.getUniqueId()) || isMianite.contains(player.getUniqueId()) || isIanite.contains(player.getUniqueId()))){
    121. //Remove player from cantMove list.
    122. cantMove.remove(player.getPlayer().getUniqueId());
    123. //Add player to isMianite list.
    124. isMianite.add(player.getUniqueId());
    125. //getConfig().addDefault("Mianite Followers", this.isMianite);
    126. player.sendMessage(ChatColor.AQUA + "Congratulations. You have parted with " + ChatColor.GREEN + "Mianite");
    127.  
    128. //Teleport player to coordinates set in config as "mianite:x:y:z
    129. String[] rawValues = getConfig().getString("mianite").split(" ");
    130. int x, y, z;
    131. try {
    132. x = Integer.parseInt(rawValues[0]);
    133. y = Integer.parseInt(rawValues[1]);
    134. z = Integer.parseInt(rawValues[2]);
    135. Location tpLoc = new Location (Bukkit.getWorlds().get(0), (double) (x), (double) (y), (double) (z));
    136. player.teleport(tpLoc); /*this is whoever issued the command*/
    137. } catch(NullPointerException e) {
    138. //If the config is fucked up it goes here.
    139. }
    140. }else{
    141. player.sendMessage(ChatColor.DARK_RED + "You are already in a team.");
    142. }
    143.  
    144. }
    145.  
    146. if(cmd.getName().equalsIgnoreCase("dianite")){
    147. if(!(isDianite.contains(player.getUniqueId()) || isMianite.contains(player.getUniqueId()) || isIanite.contains(player.getUniqueId()))){
    148. cantMove.remove(player.getPlayer().getUniqueId());
    149. isDianite.add(player.getUniqueId());;
    150. //String uid = player.getUniqueId().toString();
    151. //getConfig().addDefault("Dianite Followers", uid);
    152. //saveConfig();
    153. player.sendMessage(ChatColor.AQUA + "Congratulations. You are now following " + ChatColor.DARK_RED + "Dianite");
    154.  
    155. String[] rawValues = getConfig().getString("dianite").split(" ");
    156. int x, y, z;
    157. try {
    158. x = Integer.parseInt(rawValues[0]);
    159. y = Integer.parseInt(rawValues[1]);
    160. z = Integer.parseInt(rawValues[2]);
    161. Location tpLoc = new Location (Bukkit.getWorlds().get(0), (double) (x), (double) (y), (double) (z));
    162. player.teleport(tpLoc); /*this is whoever issued the command*/
    163. } catch(NullPointerException e) {
    164. //If the config is fucked up it goes here.
    165. }
    166. }else{
    167. player.sendMessage(ChatColor.DARK_RED + "You are already in a team.");
    168. }
    169.  
    170. }
    171.  
    172. if(cmd.getName().equalsIgnoreCase("ianite")){
    173. if(!(isDianite.contains(player.getUniqueId()) || isMianite.contains(player.getUniqueId()) || isIanite.contains(player.getUniqueId()))){
    174. cantMove.remove(player.getPlayer().getUniqueId());
    175. isIanite.add(player.getUniqueId());
    176. getConfig().addDefault("Ianite Followers", this.isIanite);
    177. saveConfig();
    178. player.sendMessage(ChatColor.AQUA + "Congratulations. You have parted with " + ChatColor.YELLOW + "Ianite");
    179.  
    180. String[] rawValues = getConfig().getString("ianite").split(" ");
    181. int x, y, z;
    182. try {
    183. x = Integer.parseInt(rawValues[0]);
    184. y = Integer.parseInt(rawValues[1]);
    185. z = Integer.parseInt(rawValues[2]);
    186. Location tpLoc = new Location (Bukkit.getWorlds().get(0), (double) (x), (double) (y), (double) (z));
    187. player.teleport(tpLoc); /*this is whoever issued the command*/
    188. } catch(NullPointerException e) {
    189. //If the config is fucked up it goes here.
    190. }
    191. }else{
    192. player.sendMessage(ChatColor.DARK_RED + "You are already in a team.");
    193. }
    194.  
    195. }
    196.  
    197. if(cmd.getName().equalsIgnoreCase("pray")){
    198. if(args.length == 0){
    199. player.sendMessage(ChatColor.RED + "You must specify a prayer type.");
    200. }else{
    201. if(args[0].equalsIgnoreCase("kill")){
    202. if(isMianite.contains(player.getUniqueId()) || isDianite.contains(player.getUniqueId()) || isIanite.contains(player.getUniqueId())){
    203. if(args.length == 1){
    204. player.sendMessage(ChatColor.RED + "You must specify a player.");
    205. }else{
    206. int coolDownTime = 259200;
    207. if(coolDown.containsKey(player.getUniqueId())){
    208. long secondsLeft = ((coolDown.get(player.getUniqueId())/1000)+coolDownTime) - (System.currentTimeMillis()/1000);
    209.  
    210. if(secondsLeft > 0){
    211. sender.sendMessage(ChatColor.RED + "You may not pray for kills to the Gods for another " + ChatColor.AQUA + secondsLeft + " seconds.");
    212. return true;
    213. }
    214. }
    215. coolDown.put(player.getUniqueId(), System.currentTimeMillis());
    216. Player target = sender.getServer().getPlayer(args[1]);
    217. if (target == null){
    218. sender.sendMessage(ChatColor.AQUA + args[1] + ChatColor.RED + " is not currently online.");
    219. return true;
    220. }
    221. Random random = new Random();
    222. int randomChance = 100; //100 %
    223. final int DROP_NUMBER = random.nextInt(randomChance);
    224. if (DROP_NUMBER <= 45) {
    225. target.sendMessage(ChatColor.DARK_RED + "A fellow Mianitee, who calls himself " + ChatColor.AQUA + target.getName() + ChatColor.DARK_RED + ", has prayed to his God for your death.");
    226. target.setHealth(0);
    227. sender.sendMessage(ChatColor.GREEN + "Your God has faithfully accepted your prayer. " + ChatColor.RED + args[1] + ChatColor.GREEN + " has died.");
    228. }else{
    229. sender.sendMessage(ChatColor.DARK_RED + "Your God has denied your prayer.");
    230. }
    231. return true;
    232. }
    233. }else{
    234. player.sendMessage(ChatColor.RED + "You must have a God to pray.");
    235. }
    236. }else if(args[0].equalsIgnoreCase("location") || args[0].equalsIgnoreCase("loc")){
    237. if(isMianite.contains(player.getUniqueId()) || isDianite.contains(player.getUniqueId()) || isIanite.contains(player.getUniqueId())){
    238. if(args.length == 1){
    239. player.sendMessage(ChatColor.RED + "You must specify a player.");
    240. }else{
    241. int coolDownTime = 259200;
    242. if(coolDownKill.containsKey(player.getUniqueId())){
    243. long secondsLeft = ((coolDownKill.get(player.getUniqueId())/1000)+coolDownTime) - (System.currentTimeMillis()/1000);
    244. if(secondsLeft > 0){
    245. sender.sendMessage(ChatColor.RED + "You may not location pray to the Gods for another " + ChatColor.AQUA + secondsLeft + " seconds.");
    246. return true;
    247. }
    248. }
    249. if(prayPoints.containsKey(player.getUniqueId())){
    250. if(prayPoints.get(player.getUniqueId()) >= 3){
    251. coolDownKill.put(player.getUniqueId(), System.currentTimeMillis());
    252. prayPoints.put(player.getUniqueId(), prayPoints.get(player.getUniqueId()) - 3);
    253. Player playerLoc = Bukkit.getPlayer(args[1]);
    254. if(playerLoc != null && playerLoc.isOnline()){
    255. sender.sendMessage(ChatColor.RED + "3 prayer points reducted. The coordinates are: " + ChatColor.AQUA + "x " + playerLoc.getLocation().getBlockX() + " y " + playerLoc.getLocation().getBlockY() + " x " + playerLoc.getLocation().getBlockZ());
    256. }
    257. }
    258. }
    259. }
    260. }
    261. }else if(args[0].equalsIgnoreCase("item") || args[0].equalsIgnoreCase("spawn")){
    262. if(isMianite.contains(player.getUniqueId()) || isDianite.contains(player.getUniqueId()) || isIanite.contains(player.getUniqueId())){
    263. if(args.length == 1){
    264. player.sendMessage(ChatColor.RED + "You must specify an item.");
    265. }else{
    266. int coolDownTime = 1800;
    267. if(coolDownSpawn.containsKey(player.getUniqueId())){
    268. long secondsLeft = ((coolDownSpawn.get(player.getUniqueId())/1000)+coolDownTime) - (System.currentTimeMillis()/1000);
    269. if(secondsLeft > 0){
    270. sender.sendMessage(ChatColor.RED + "You may not pray for an item to the Gods for another " + ChatColor.AQUA + secondsLeft + " seconds.");
    271. return true;
    272. }
    273. }
    274. if(prayPoints.containsKey(player.getUniqueId())){
    275. if(prayPoints.get(player.getUniqueId()) >= 10){
    276. Material material = Material.matchMaterial(args[1]);
    277. if(material != null){
    278. prayPoints.put(player.getUniqueId(), prayPoints.get(player.getUniqueId()) - 10);
    279. coolDownSpawn.put(player.getUniqueId(), System.currentTimeMillis());
    280. ItemStack itemStack = new ItemStack(material, (int) (3*Math.random()+7));
    281. player.getInventory().addItem(itemStack);
    282. player.sendMessage(ChatColor.RED + "You have received a random amount of " + ChatColor.AQUA + material);
    283. }else{
    284. player.sendMessage(ChatColor.RED + "The item you prayed for does not exist.");
    285. }
    286. }else{
    287. player.sendMessage(ChatColor.RED + "You do not have enough prayer points.");
    288. }
    289. }
    290. }
    291. }else{
    292. player.sendMessage(ChatColor.RED + "You must have a God to pray.");
    293. }
    294. }else if(args[0].equalsIgnoreCase("tpa") || args[0].equalsIgnoreCase("tp")){
    295. if(isMianite.contains(player.getUniqueId()) || isDianite.contains(player.getUniqueId()) || isIanite.contains(player.getUniqueId())){
    296. if(args.length == 1){
    297. player.sendMessage(ChatColor.RED + "You must specify a player you would like to request a teleport to.");
    298. }else{
    299. if(prayPoints.containsKey(player.getUniqueId())){
    300. if(prayPoints.get(player.getUniqueId()) >= 10){
    301. if(Bukkit.getServer().getPlayer(args[1]).isOnline()){
    302. Player source = (Player) sender;
    303. Player target = (Bukkit.getServer().getPlayer(args[1]));
    304. teleport.put(target.getUniqueId(), source.getUniqueId());
    305. target.sendMessage(ChatColor.AQUA + player.getName() + ChatColor.RED + " wishes to teleport to you. " + ChatColor.AQUA + "/pray tpaccept or /pray tpdeny?");
    306. player.sendMessage(ChatColor.AQUA + "You have sucessfully sent a teleport request to " + ChatColor.RED + target.getName() + ChatColor.AQUA + " via the Gods.");
    307. }
    308. }
    309. }
    310. }
    311. }
    312. }
    313. }
    314. if(args[0].equalsIgnoreCase("tpaccept")){
    315. if(teleport.containsValue(player.getUniqueId())){
    316. Player requester = Bukkit.getServer().getPlayerExact(teleport.get(source.getName()));
    317. requester.teleport(player);
    318. player.sendMessage(ChatColor.AQUA + "You sucessfully accepted the teleportation request.");
    319. teleport.get(source).sendMessage(ChatColor.AQUA + "Your request has been accepted.");
    320.  
    321. }
    322. }if(args[0].equalsIgnoreCase("tpdeny")){
    323. if(teleport.containsValue(player.getUniqueId())){
    324. player.sendMessage(ChatColor.AQUA + "You sucessfully denied the teleportation request.");
    325. teleport.get(source).sendMessage(ChatColor.AQUA + "Your request has been denied.");
    326. }
    327. }
    328. }
    329.  
    330. if(cmd.getName().equalsIgnoreCase("praypoints") || getName().equalsIgnoreCase("prayerpoints") || getName().equalsIgnoreCase("pp")){
    331. if(prayPoints.size() >= 1){
    332. player.sendMessage(ChatColor.AQUA + "Prayer Points: "+ ChatColor.RED + prayPoints.get(player.getUniqueId()));
    333. }else{
    334. player.sendMessage(ChatColor.RED + "You do not yet have any prayer points.");
    335. }
    336. }
    337.  
    338. if(cmd.getName().equalsIgnoreCase("devtools")){
    339. if(player.hasPermission("mianite.devtools")){
    340. if(args.length == 0){
    341. player.sendMessage(ChatColor.RED + "Bruh, you need to specify what tool you want");
    342. }else{
    343. if(args[0].equalsIgnoreCase("mobpoints")){
    344. player.sendMessage(ChatColor.RED + "Your mob points: " + ChatColor.AQUA + mobKillAmount.get(player.getUniqueId()));
    345. }
    346. if(args[0].equalsIgnoreCase("praygive")){
    347. prayPoints.put(player.getUniqueId(), prayPoints.get(player.getUniqueId()) + 100);
    348. player.sendMessage(ChatColor.RED + "You have received 100 pray points.");
    349. }
    350. }
    351. }else{
    352. player.sendMessage(ChatColor.DARK_RED + "You do not have permission to access this command.");
    353. }
    354. }
    355. return false;
    356. }
    357.  
    358. @EventHandler
    359. public void onEntityDeath(EntityDeathEvent event){
    360. Player killer = (event.getEntity().getKiller());
    361. if(event.getEntity() instanceof Monster){
    362. if(event.getEntity().getKiller() instanceof Player){
    363. if(mobKillAmount.containsKey(killer.getUniqueId())){
    364. if(mobKillAmount.get(killer.getUniqueId()) >= 100){
    365. mobKillAmount.put(killer.getUniqueId(), mobKillAmount.get(killer.getUniqueId()) - 100);
    366. if(prayPoints.containsKey(killer.getUniqueId())){
    367. prayPoints.put(killer.getUniqueId(), prayPoints.get(killer.getUniqueId()) + 1);
    368. killer.sendMessage(ChatColor.AQUA + "You have received a pray point.");
    369. }else{
    370. prayPoints.put(killer.getUniqueId(), 1);
    371. }
    372. }
    373. }
    374. if(mobKillAmount.containsKey(killer.getUniqueId())){
    375. mobKillAmount.put(killer.getUniqueId(), mobKillAmount.get(killer.getUniqueId()) + 1);
    376. }else{
    377. mobKillAmount.put(killer.getUniqueId(), 1);
    378. }
    379. }
    380. }
    381. }
    382.  
    383. @EventHandler
    384. public void onPlayerMianite(AsyncPlayerChatEvent e){
    385. Player player = (Player) e.getPlayer();
    386. if(isMianite.contains(e.getPlayer().getUniqueId())){
    387. player.setDisplayName(ChatColor.GREEN + "[M] " + ChatColor.WHITE + player.getName());
    388. }
    389. }
    390.  
    391. @EventHandler
    392. public void onPlayerDianite(AsyncPlayerChatEvent e){
    393. Player player = (Player) e.getPlayer();
    394. if(isDianite.contains(e.getPlayer().getUniqueId())){
    395. player.setDisplayName(ChatColor.DARK_RED + "[D] " + ChatColor.WHITE + player.getName());
    396. }
    397. }
    398.  
    399. @EventHandler
    400. public void onPlayerIanite(AsyncPlayerChatEvent e){
    401. Player player = (Player) e.getPlayer();
    402. if(isIanite.contains(e.getPlayer().getUniqueId())){
    403. player.setDisplayName(ChatColor.YELLOW + "[I] " + ChatColor.WHITE + player.getName());
    404. }
    405. }
    406.  
    407. @EventHandler
    408. public void onDamage(EntityDamageByEntityEvent event) {
    409. Entity player = event.getEntity();
    410. Entity attacker = event.getDamager();
    411. if(event.getDamager() instanceof Player && event.getEntity() instanceof Player){
    412. if(isMianite.contains(player.getUniqueId()) && isMianite.contains(attacker.getUniqueId()) || isDianite.contains(player.getUniqueId()) && isDianite.contains(attacker.getUniqueId()) || isIanite.contains(player.getUniqueId()) && isIanite.contains(attacker.getUniqueId())) {
    413. event.setCancelled(true);
    414. }
    415. }
    416. }
    417.  
    418. }
    419. [/I]


    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 9, 2016
  13. Offline

    xTigerRebornx

    ariaDEE Let me rephrase that. You haven't defined 'source' within a scope that can be accessed when you call get(). You are doing something like:
    Code:
    if(whatever){
      Player p = (...)
    }
     
     
    map.get(p);
    Which wouldn't compile as p is not defined within an accessible scope as p is defined in the if statement's block, meaning it can only be access inside that block.
     
  14. Offline

    ariaDEE

    xTigerRebornx If I use something like 'player' which is accessible outside that block, the error still occurs.
     
  15. Offline

    br456

    ariaDEE
    I believe when using put(key,value); You are putting the target as the key
    When you use get(key); You are using the source variable which isn't reacheable, as xTigerRebornx said. But even if it was accessible, it wouldn't work because source isn't the key
     
  16. Offline

    ariaDEE

    br456 Source is now the key, and the error still persists..
     
  17. Offline

    br456

    ariaDEE
    Please post updated class and the full error
     
  18. Offline

    ariaDEE

    br456
    Code:java
    1. package me.SuperiorCallz.Mianite;
    2.  
    3. import java.util.ArrayList;
    4. import java.util.HashMap;
    5. import java.util.List;
    6. import java.util.Random;
    7. import java.util.UUID;
    8. import java.util.logging.Logger;
    9.  
    10. import org.bukkit.Bukkit;
    11. import org.bukkit.ChatColor;
    12. import org.bukkit.Location;
    13. import org.bukkit.Material;
    14. import org.bukkit.command.Command;
    15. import org.bukkit.command.CommandSender;
    16. import org.bukkit.entity.Entity;
    17. import org.bukkit.entity.Monster;
    18. import org.bukkit.entity.Player;
    19. import org.bukkit.event.EventHandler;
    20. import org.bukkit.event.Listener;
    21. import org.bukkit.event.entity.EntityDamageByEntityEvent;
    22. import org.bukkit.event.entity.EntityDeathEvent;
    23. import org.bukkit.event.player.AsyncPlayerChatEvent;
    24. import org.bukkit.event.player.PlayerJoinEvent;
    25. import org.bukkit.event.player.PlayerMoveEvent;
    26. import org.bukkit.inventory.ItemStack;
    27. import org.bukkit.plugin.PluginDescriptionFile;
    28. import org.bukkit.plugin.java.JavaPlugin;
    29.  
    30. public class Mianite extends JavaPlugin implements Listener{
    31.  
    32. public final Logger logger = Logger.getLogger("Minecraft");
    33. public static Mianite plugin;
    34.  
    35. public ArrayList<UUID> cantMove = new ArrayList<UUID>();
    36.  
    37. public List<UUID> isMianite = new ArrayList<UUID>();
    38. public List<UUID> isDianite = new ArrayList<UUID>();
    39. public List<UUID> isIanite = new ArrayList<UUID>();
    40. public HashMap<UUID, Long> coolDown = new HashMap<UUID, Long>();
    41. public HashMap<UUID, Long> coolDownKill = new HashMap<UUID, Long>();
    42. public HashMap<UUID, Long> coolDownSpawn = new HashMap<UUID, Long>();
    43. public HashMap<UUID, Integer> mobKillAmount = new HashMap<UUID, Integer>();
    44. public HashMap<UUID, Integer> prayPoints = new HashMap<UUID, Integer>();
    45. public HashMap<String, List> teleport = new HashMap<String, List>();
    46.  
    47. @Override
    48. public void onEnable() {
    49. PluginDescriptionFile pdfFile = this.getDescription();
    50. this.logger.info(pdfFile.getName() + " version " + pdfFile.getVersion() + " has been enabled.");
    51. getServer().getPluginManager().registerEvents(this, this);
    52. getConfig().options().copyDefaults(true);
    53. saveConfig();
    54. try {
    55. isMianite = SLAPI.load("isMianite.bin");
    56. isDianite = SLAPI.load("isDianite.bin");
    57. isIanite = SLAPI.load("isIanite.bin");
    58. coolDown = SLAPI.load("coolDown.bin");
    59. coolDownKill = SLAPI.load("coolDownKill.bin");
    60. prayPoints = SLAPI.load("prayPoints.bin");
    61. } catch(Exception e) {
    62. //handle the exception
    63. e.printStackTrace();
    64. }
    65. }
    66.  
    67. @Override
    68. public void onDisable() {
    69. PluginDescriptionFile pdfFile = this.getDescription();
    70. this.logger.info(pdfFile.getName() + " has been disabled.");
    71. getConfig().options().copyDefaults(true);
    72. saveConfig();
    73.  
    74. try {
    75. SLAPI.save(isMianite,"isMianite.bin");
    76. SLAPI.save(isDianite,"isDianite.bin");
    77. SLAPI.save(isIanite,"isIanite.bin");
    78. SLAPI.save(coolDown,"coolDown.bin");
    79. SLAPI.save(coolDownKill,"coolDownKill.bin");
    80. SLAPI.save(prayPoints,"prayPoints.bin");
    81. } catch(Exception e) {
    82. e.printStackTrace();
    83. }
    84. }
    85.  
    86.  
    87. @EventHandler
    88. public void move(PlayerMoveEvent move)
    89. {
    90. //Check if player is in the cantMove list, and if so, don't allow them to move.
    91. if(!move.getPlayer().hasPermission("mianite.canMove")){
    92. if(cantMove.contains(move.getPlayer().getUniqueId())){
    93. Location from=move.getFrom();
    94. Location to=move.getTo();
    95. double x=Math.floor(from.getX());
    96. double z=Math.floor(from.getZ());
    97. if(Math.floor(to.getX())!=x||Math.floor(to.getZ())!=z)
    98. {
    99. x+=.5;
    100. z+=.5;
    101. move.getPlayer().teleport(new Location(from.getWorld(),x,from.getY(),z,from.getYaw(),from.getPitch()));
    102. }
    103. move.getPlayer().sendMessage(ChatColor.AQUA + "You may not move until a team has been picked. " + ChatColor.GREEN + "/mianite," + ChatColor.DARK_RED + " /dianite, " + ChatColor.YELLOW + "/ianite");
    104. }
    105. }
    106. }
    107.  
    108. @EventHandler
    109. public void onPlayerJoinEvent(PlayerJoinEvent event) {
    110. if(!event.getPlayer().hasPlayedBefore()) {
    111. event.getPlayer().sendMessage(ChatColor.AQUA + "Welcome to the world of Mianite. Pick your team. " + ChatColor.GREEN + "/mianite," + ChatColor.DARK_RED + " /dianite, " + ChatColor.YELLOW + "/ianite");
    112. cantMove.add(event.getPlayer().getUniqueId());
    113. }
    114. }
    115.  
    116. @SuppressWarnings("deprecation")
    117. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args){
    118. Player player = (Player) sender;
    119. if(cmd.getName().equalsIgnoreCase("mianite")){
    120. if(!(isDianite.contains(player.getUniqueId()) || isMianite.contains(player.getUniqueId()) || isIanite.contains(player.getUniqueId()))){
    121. //Remove player from cantMove list.
    122. cantMove.remove(player.getPlayer().getUniqueId());
    123. //Add player to isMianite list.
    124. isMianite.add(player.getUniqueId());
    125. //getConfig().addDefault("Mianite Followers", this.isMianite);
    126. player.sendMessage(ChatColor.AQUA + "Congratulations. You are now following " + ChatColor.GREEN + "Mianite");
    127.  
    128. //Teleport player to coordinates set in config as "mianite:x:y:z
    129. String[] rawValues = getConfig().getString("mianite").split(" ");
    130. int x, y, z;
    131. try {
    132. x = Integer.parseInt(rawValues[0]);
    133. y = Integer.parseInt(rawValues[1]);
    134. z = Integer.parseInt(rawValues[2]);
    135. Location tpLoc = new Location (Bukkit.getWorlds().get(0), (double) (x), (double) (y), (double) (z));
    136. player.teleport(tpLoc); /*this is whoever issued the command*/
    137. } catch(NullPointerException e) {
    138. //If the config is fucked up it goes here.
    139. }
    140. }else{
    141. player.sendMessage(ChatColor.DARK_RED + "You are already in a team.");
    142. }
    143.  
    144. }
    145.  
    146. if(cmd.getName().equalsIgnoreCase("dianite")){
    147. if(!(isDianite.contains(player.getUniqueId()) || isMianite.contains(player.getUniqueId()) || isIanite.contains(player.getUniqueId()))){
    148. cantMove.remove(player.getPlayer().getUniqueId());
    149. isDianite.add(player.getUniqueId());;
    150. //String uid = player.getUniqueId().toString();
    151. //getConfig().addDefault("Dianite Followers", uid);
    152. //saveConfig();
    153. player.sendMessage(ChatColor.AQUA + "Congratulations. You are now following " + ChatColor.DARK_RED + "Dianite");
    154.  
    155. String[] rawValues = getConfig().getString("dianite").split(" ");
    156. int x, y, z;
    157. try {
    158. x = Integer.parseInt(rawValues[0]);
    159. y = Integer.parseInt(rawValues[1]);
    160. z = Integer.parseInt(rawValues[2]);
    161. Location tpLoc = new Location (Bukkit.getWorlds().get(0), (double) (x), (double) (y), (double) (z));
    162. player.teleport(tpLoc); /*this is whoever issued the command*/
    163. } catch(NullPointerException e) {
    164. //If the config is fucked up it goes here.
    165. }
    166. }else{
    167. player.sendMessage(ChatColor.DARK_RED + "You are already in a team.");
    168. }
    169.  
    170. }
    171.  
    172. if(cmd.getName().equalsIgnoreCase("ianite")){
    173. if(!(isDianite.contains(player.getUniqueId()) || isMianite.contains(player.getUniqueId()) || isIanite.contains(player.getUniqueId()))){
    174. cantMove.remove(player.getPlayer().getUniqueId());
    175. isIanite.add(player.getUniqueId());
    176. getConfig().addDefault("Ianite Followers", this.isIanite);
    177. saveConfig();
    178. player.sendMessage(ChatColor.AQUA + "Congratulations. You are now following " + ChatColor.YELLOW + "Ianite");
    179.  
    180. String[] rawValues = getConfig().getString("ianite").split(" ");
    181. int x, y, z;
    182. try {
    183. x = Integer.parseInt(rawValues[0]);
    184. y = Integer.parseInt(rawValues[1]);
    185. z = Integer.parseInt(rawValues[2]);
    186. Location tpLoc = new Location (Bukkit.getWorlds().get(0), (double) (x), (double) (y), (double) (z));
    187. player.teleport(tpLoc); /*this is whoever issued the command*/
    188. } catch(NullPointerException e) {
    189. //If the config is fucked up it goes here.
    190. }
    191. }else{
    192. player.sendMessage(ChatColor.DARK_RED + "You are already in a team.");
    193. }
    194.  
    195. }
    196.  
    197. if(cmd.getName().equalsIgnoreCase("pray")){
    198. if(args.length == 0){
    199. player.sendMessage(ChatColor.RED + "You must specify a prayer type.");
    200. }else{
    201. if(args[0].equalsIgnoreCase("kill")){
    202. if(isMianite.contains(player.getUniqueId()) || isDianite.contains(player.getUniqueId()) || isIanite.contains(player.getUniqueId())){
    203. if(args.length == 1){
    204. player.sendMessage(ChatColor.RED + "You must specify a player.");
    205. }else{
    206. int coolDownTime = 259200;
    207. if(coolDown.containsKey(player.getUniqueId())){
    208. long secondsLeft = ((coolDown.get(player.getUniqueId())/1000)+coolDownTime) - (System.currentTimeMillis()/1000);
    209.  
    210. if(secondsLeft > 0){
    211. sender.sendMessage(ChatColor.RED + "You may not pray for kills to the Gods for another " + ChatColor.AQUA + secondsLeft + " seconds.");
    212. return true;
    213. }
    214. }
    215. coolDown.put(player.getUniqueId(), System.currentTimeMillis());
    216. Player target = sender.getServer().getPlayer(args[1]);
    217. if (target == null){
    218. sender.sendMessage(ChatColor.AQUA + args[1] + ChatColor.RED + " is not currently online.");
    219. return true;
    220. }
    221. Random random = new Random();
    222. int randomChance = 100; //100 %
    223. final int DROP_NUMBER = random.nextInt(randomChance);
    224. if (DROP_NUMBER <= 45) {
    225. target.sendMessage(ChatColor.DARK_RED + "A fellow Mianitee, who calls himself " + ChatColor.AQUA + target.getName() + ChatColor.DARK_RED + ", has prayed to his God for your death.");
    226. target.setHealth(0);
    227. sender.sendMessage(ChatColor.GREEN + "Your God has faithfully accepted your prayer. " + ChatColor.RED + args[1] + ChatColor.GREEN + " has died.");
    228. }else{
    229. sender.sendMessage(ChatColor.DARK_RED + "Your God has denied your prayer.");
    230. }
    231. return true;
    232. }
    233. }else{
    234. player.sendMessage(ChatColor.RED + "You must have a God to pray.");
    235. }
    236. }else if(args[0].equalsIgnoreCase("location") || args[0].equalsIgnoreCase("loc")){
    237. if(isMianite.contains(player.getUniqueId()) || isDianite.contains(player.getUniqueId()) || isIanite.contains(player.getUniqueId())){
    238. if(args.length == 1){
    239. player.sendMessage(ChatColor.RED + "You must specify a player.");
    240. }else{
    241. int coolDownTime = 259200;
    242. if(coolDownKill.containsKey(player.getUniqueId())){
    243. long secondsLeft = ((coolDownKill.get(player.getUniqueId())/1000)+coolDownTime) - (System.currentTimeMillis()/1000);
    244. if(secondsLeft > 0){
    245. sender.sendMessage(ChatColor.RED + "You may not location pray to the Gods for another " + ChatColor.AQUA + secondsLeft + " seconds.");
    246. return true;
    247. }
    248. }
    249. if(prayPoints.containsKey(player.getUniqueId())){
    250. if(prayPoints.get(player.getUniqueId()) >= 3){
    251. coolDownKill.put(player.getUniqueId(), System.currentTimeMillis());
    252. prayPoints.put(player.getUniqueId(), prayPoints.get(player.getUniqueId()) - 3);
    253. Player playerLoc = Bukkit.getPlayer(args[1]);
    254. if(playerLoc != null && playerLoc.isOnline()){
    255. sender.sendMessage(ChatColor.RED + "3 prayer points reducted. The coordinates are: " + ChatColor.AQUA + "x " + playerLoc.getLocation().getBlockX() + " y " + playerLoc.getLocation().getBlockY() + " x " + playerLoc.getLocation().getBlockZ());
    256. }
    257. }
    258. }
    259. }
    260. }
    261. }else if(args[0].equalsIgnoreCase("item") || args[0].equalsIgnoreCase("spawn")){
    262. if(isMianite.contains(player.getUniqueId()) || isDianite.contains(player.getUniqueId()) || isIanite.contains(player.getUniqueId())){
    263. if(args.length == 1){
    264. player.sendMessage(ChatColor.RED + "You must specify an item.");
    265. }else{
    266. int coolDownTime = 1800;
    267. if(coolDownSpawn.containsKey(player.getUniqueId())){
    268. long secondsLeft = ((coolDownSpawn.get(player.getUniqueId())/1000)+coolDownTime) - (System.currentTimeMillis()/1000);
    269. if(secondsLeft > 0){
    270. sender.sendMessage(ChatColor.RED + "You may not pray for an item to the Gods for another " + ChatColor.AQUA + secondsLeft + " seconds.");
    271. return true;
    272. }
    273. }
    274. if(prayPoints.containsKey(player.getUniqueId())){
    275. if(prayPoints.get(player.getUniqueId()) >= 10){
    276. Material material = Material.matchMaterial(args[1]);
    277. if(material != null){
    278. prayPoints.put(player.getUniqueId(), prayPoints.get(player.getUniqueId()) - 10);
    279. coolDownSpawn.put(player.getUniqueId(), System.currentTimeMillis());
    280. ItemStack itemStack = new ItemStack(material, (int) (3*Math.random()+7));
    281. player.getInventory().addItem(itemStack);
    282. player.sendMessage(ChatColor.RED + "You have received a random amount of " + ChatColor.AQUA + material);
    283. }else{
    284. player.sendMessage(ChatColor.RED + "The item you prayed for does not exist.");
    285. }
    286. }else{
    287. player.sendMessage(ChatColor.RED + "You do not have enough prayer points.");
    288. }
    289. }
    290. }
    291. }else{
    292. player.sendMessage(ChatColor.RED + "You must have a God to pray.");
    293. }
    294. }else if(args[0].equalsIgnoreCase("tpa") || args[0].equalsIgnoreCase("tp")){
    295. if(isMianite.contains(player.getUniqueId()) || isDianite.contains(player.getUniqueId()) || isIanite.contains(player.getUniqueId())){
    296. if(args.length == 1){
    297. player.sendMessage(ChatColor.RED + "You must specify a player you would like to request a teleport to.");
    298. }else{
    299. if(prayPoints.containsKey(player.getUniqueId())){
    300. if(prayPoints.get(player.getUniqueId()) >= 10){
    301. if(Bukkit.getServer().getPlayer(args[1]).isOnline() && Bukkit.getServer().getPlayer(args[1]) != null){
    302. Player target = (Bukkit.getServer().getPlayer(args[1]));
    303. teleport.put(player.getUniqueId(), target.getUniqueId());
    304. target.sendMessage(ChatColor.AQUA + player.getName() + ChatColor.RED + " wishes to teleport to you. " + ChatColor.AQUA + "/pray tpaccept or /pray tpdeny?");
    305. player.sendMessage(ChatColor.AQUA + "You have sucessfully sent a teleport request to " + ChatColor.RED + target.getName() + ChatColor.AQUA + " via the Gods.");
    306. }
    307. }
    308. }
    309. }
    310. }
    311. }
    312. }
    313. if(args[0].equalsIgnoreCase("tpaccept")){
    314. if(teleport.containsValue(player.getUniqueId())){
    315. Player requester = Bukkit.getServer().getPlayerExact(teleport.get(player.getName()));
    316. requester.teleport(player);
    317. player.sendMessage(ChatColor.AQUA + "You sucessfully accepted the teleportation request.");
    318. teleport.get(player).sendMessage(ChatColor.AQUA + "Your request has been accepted.");
    319.  
    320. }
    321. }if(args[0].equalsIgnoreCase("tpdeny")){
    322. if(teleport.containsValue(player.getUniqueId())){
    323. player.sendMessage(ChatColor.AQUA + "You sucessfully denied the teleportation request.");
    324. teleport.get(player).sendMessage(ChatColor.AQUA + "Your request has been denied.");
    325. }
    326. }
    327. }
    328.  
    329. if(cmd.getName().equalsIgnoreCase("praypoints") || getName().equalsIgnoreCase("prayerpoints") || getName().equalsIgnoreCase("pp")){
    330. if(prayPoints.size() >= 1){
    331. player.sendMessage(ChatColor.AQUA + "Prayer Points: "+ ChatColor.RED + prayPoints.get(player.getUniqueId()));
    332. }else{
    333. player.sendMessage(ChatColor.RED + "You do not yet have any prayer points.");
    334. }
    335. }
    336.  
    337. if(cmd.getName().equalsIgnoreCase("devtools")){
    338. if(player.hasPermission("mianite.devtools")){
    339. if(args.length == 0){
    340. player.sendMessage(ChatColor.RED + "Bruh, you need to specify what tool you want");
    341. }else{
    342. if(args[0].equalsIgnoreCase("mobpoints")){
    343. player.sendMessage(ChatColor.RED + "Your mob points: " + ChatColor.AQUA + mobKillAmount.get(player.getUniqueId()));
    344. }
    345. if(args[0].equalsIgnoreCase("praygive")){
    346. prayPoints.put(player.getUniqueId(), prayPoints.get(player.getUniqueId()) + 100);
    347. player.sendMessage(ChatColor.RED + "You have received 100 pray points.");
    348. }
    349. }
    350. }else{
    351. player.sendMessage(ChatColor.DARK_RED + "You do not have permission to access this command.");
    352. }
    353. }
    354. return false;
    355. }
    356.  
    357. @EventHandler
    358. public void onEntityDeath(EntityDeathEvent event){
    359. Player killer = (event.getEntity().getKiller());
    360. if(event.getEntity() instanceof Monster){
    361. if(event.getEntity().getKiller() instanceof Player){
    362. if(mobKillAmount.containsKey(killer.getUniqueId())){
    363. if(mobKillAmount.get(killer.getUniqueId()) >= 100){
    364. mobKillAmount.put(killer.getUniqueId(), mobKillAmount.get(killer.getUniqueId()) - 100);
    365. if(prayPoints.containsKey(killer.getUniqueId())){
    366. prayPoints.put(killer.getUniqueId(), prayPoints.get(killer.getUniqueId()) + 1);
    367. killer.sendMessage(ChatColor.AQUA + "You have received a pray point.");
    368. }else{
    369. prayPoints.put(killer.getUniqueId(), 1);
    370. }
    371. }
    372. }
    373. if(mobKillAmount.containsKey(killer.getUniqueId())){
    374. mobKillAmount.put(killer.getUniqueId(), mobKillAmount.get(killer.getUniqueId()) + 1);
    375. }else{
    376. mobKillAmount.put(killer.getUniqueId(), 1);
    377. }
    378. }
    379. }
    380. }
    381.  
    382. @EventHandler
    383. public void onPlayerMianite(AsyncPlayerChatEvent e){
    384. Player player = (Player) e.getPlayer();
    385. if(isMianite.contains(e.getPlayer().getUniqueId())){
    386. player.setDisplayName(ChatColor.GREEN + "[M] " + ChatColor.WHITE + player.getName());
    387. }
    388. }
    389.  
    390. @EventHandler
    391. public void onPlayerDianite(AsyncPlayerChatEvent e){
    392. Player player = (Player) e.getPlayer();
    393. if(isDianite.contains(e.getPlayer().getUniqueId())){
    394. player.setDisplayName(ChatColor.DARK_RED + "[D] " + ChatColor.WHITE + player.getName());
    395. }
    396. }
    397.  
    398. @EventHandler
    399. public void onPlayerIanite(AsyncPlayerChatEvent e){
    400. Player player = (Player) e.getPlayer();
    401. if(isIanite.contains(e.getPlayer().getUniqueId())){
    402. player.setDisplayName(ChatColor.YELLOW + "[I] " + ChatColor.WHITE + player.getName());
    403. }
    404. }
    405.  
    406. @EventHandler
    407. public void onDamage(EntityDamageByEntityEvent event) {
    408. Entity player = event.getEntity();
    409. Entity attacker = event.getDamager();
    410. if(event.getDamager() instanceof Player && event.getEntity() instanceof Player){
    411. if(isMianite.contains(player.getUniqueId()) && isMianite.contains(attacker.getUniqueId()) || isDianite.contains(player.getUniqueId()) && isDianite.contains(attacker.getUniqueId()) || isIanite.contains(player.getUniqueId()) && isIanite.contains(attacker.getUniqueId())) {
    412. event.setCancelled(true);
    413. }
    414. }
    415. }
    416.  
    417. }[/I]

    I am now getting the errors:
    The method getPlayerExact(String) in the type Server is not applicable for the arguments (List) on .getPlayerExact

    The method put(String, List) in the type HashMap<String,List> is not applicable for the arguments (UUID, UUID) on teleport.put

    The method sendMessage(String) is undefined for the type List on .sendMessage a bunch of times.
     
  19. Offline

    br456

    ok, we have made some progress. But first, your teleport hashmap is type String and List, you are storing type UUID, UUID. So the teleport hashmap must be String and String.

    Then when you put the playerUniqueID into teleport, use
    Code:java
    1. player.getUniqueID().toString();
    and
    Code:java
    1. target.getUniqueID().toString();


    Finally, when you use teleport.get(); It will be returning a uuid string. then use

    Code:java
    1. Bukkit.getServer().getPlayer(teleport.get(player.getUniqueID().toString()));
     
  20. Offline

    Necrodoom

    br456 that would be trying to get a player with the name of UUID.
     
  21. Offline

    br456

    In the 1.7.9 bukkit api, you can get player by uuid
     
  22. Offline

    Gater12

    br456
    Yeah, but you're getting a player with a String because teleport has a value of String with a String key.
     
  23. Offline

    Necrodoom

    br456 yes, by giving it a UUID object, not a String.
     
  24. Offline

    ariaDEE

    br456
    So like this?
    Code:java
    1. if(args[0].equalsIgnoreCase("tpa") || args[0].equalsIgnoreCase("tp")){
    2. if(isMianite.contains(player.getUniqueId()) || isDianite.contains(player.getUniqueId()) || isIanite.contains(player.getUniqueId())){
    3. if(args.length == 1){
    4. player.sendMessage(ChatColor.RED + "You must specify a player you would like to request a teleport to.");
    5. }else{
    6. if(prayPoints.containsKey(player.getUniqueId())){
    7. if(prayPoints.get(player.getUniqueId()) >= 10){
    8. if(Bukkit.getServer().getPlayer(args[1]).isOnline() && Bukkit.getServer().getPlayer(args[1]) != null){
    9. Player target = (Bukkit.getServer().getPlayer(args[1]));
    10. teleport.put(player.getUniqueId().toString(), target.getUniqueId().toString());
    11. target.sendMessage(ChatColor.AQUA + player.getName() + ChatColor.RED + " wishes to teleport to you. " + ChatColor.AQUA + "/pray tpaccept or /pray tpdeny?");
    12. player.sendMessage(ChatColor.AQUA + "You have sucessfully sent a teleport request to " + ChatColor.RED + target.getName() + ChatColor.AQUA + " via the Gods.");
    13. }
    14. }
    15. }
    16. }
    17. }
    18. }
    19. }
    20. if(args[0].equalsIgnoreCase("tpaccept")){
    21. if(teleport.containsValue(player.getUniqueId())){
    22. Player requester = Bukkit.getServer().getPlayer(teleport.get(player.getUniqueID().toString()));
    23. requester.teleport(player);
    24. player.sendMessage(ChatColor.AQUA + "You sucessfully accepted the teleportation request.");
    25. teleport.get(player).sendMessage(ChatColor.AQUA + "Your request has been accepted.");
    26.  
    27. }

    I'm getting errors on getUniqueId: The method getUniqueID() is undefined for the type Player
    and sendMessage: The method sendMessage(String) is undefined for the type String
     
  25. Offline

    Necrodoom

    ariaDEE you should stop copy-pasting code and understand what you are doing.

    If you want to store UUID in the hashmap, store UUID and get player by UUID.

    If you want to store names in the hashmap, store names and get player by name.

    Currently your code is a mess of both while forgetting to get the player off the result.

    Fix it and paste new code.
     
  26. Offline

    ariaDEE

    I barely ever 'copy and paste' code. It's very late and I should be well asleep by now. I'm rushing to fix everything so I'm not really paying too much attention to details. Thank you.
     
  27. Offline

    Necrodoom

    ariaDEE but yet you are trying to sendMessage to a String.
     
  28. Offline

    ariaDEE

    Necrodoom
    I figured it out and it's now working :)
    My current code:
    Code:java
    1. }else if(args[0].equalsIgnoreCase("tpaccept")){
    2. if(teleport.containsValue(player.getUniqueId())){
    3. Player requester = Bukkit.getServer().getPlayer(teleport.get(player.getUniqueId()));
    4. requester.teleport(player);
    5. player.sendMessage(ChatColor.AQUA + "You sucessfully accepted the teleportation request.");
    6. requester.sendMessage(ChatColor.AQUA + "Your request has been accepted.");
    7. teleport.remove(player.getUniqueId());
    8. teleport.remove(requester.getUniqueId());
    9. return true;
    10. }
    11. }else if(args[0].equalsIgnoreCase("tpdeny")){
    12. if(teleport.containsValue(player.getUniqueId())){
    13. Player requester = Bukkit.getServer().getPlayer(teleport.get(player.getUniqueId()));
    14. player.sendMessage(ChatColor.AQUA + "You sucessfully denied the teleportation request.");
    15. requester.sendMessage(ChatColor.AQUA + "Your request has been denied.");
    16. teleport.remove(player.getUniqueId());
    17. teleport.remove(requester.getUniqueId());
    18. return true;
    19. }
    20. }

    I can finally call it a night :)

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 9, 2016
Thread Status:
Not open for further replies.

Share This Page