Solved PVP Plugin Development. Join command not working?

Discussion in 'Plugin Development' started by Axanite, Jul 24, 2013.

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

    Axanite

    So, you may remember me from yesterday where I asked for help. I got that problem sorted... Now somehow, I've ran into another problem. I do not know how this has happened as Eclipse is not giving me any errors nor console but earlier, /join worked and now it does not for no reason. If anybody could help, it would be appreciated.

    Source Code:

    Code:java
    1. package com.omegagamers.rf2minecraft.PVPBattle;
    2.  
    3. import org.bukkit.ChatColor;
    4. import org.bukkit.Location;
    5. import org.bukkit.Material;
    6. import org.bukkit.Sound;
    7. import org.bukkit.command.Command;
    8. import org.bukkit.command.CommandSender;
    9. import org.bukkit.entity.Player;
    10. import org.bukkit.event.EventHandler;
    11. import org.bukkit.event.EventPriority;
    12. import org.bukkit.event.Listener;
    13. import org.bukkit.event.entity.PlayerDeathEvent;
    14. import org.bukkit.inventory.ItemStack;
    15. import org.bukkit.inventory.PlayerInventory;
    16. import org.bukkit.plugin.Plugin;
    17. import org.bukkit.plugin.PluginManager;
    18. import org.bukkit.plugin.java.JavaPlugin;
    19. import org.bukkit.Bukkit;
    20.  
    21. public final class PVPBattle extends JavaPlugin {
    22. public class DeathListener implements Listener {
    23. @EventHandler(priority = EventPriority.HIGHEST)
    24. public void onDeath(PlayerDeathEvent event) {
    25. Player player = event.getEntity();
    26. Player killer = player.getKiller();
    27. String item = killer.getItemInHand().getType().name();
    28. event.getDrops().clear();
    29. event.setDeathMessage(ChatColor.GOLD + "[" + ChatColor.DARK_PURPLE + "!" + "" + ChatColor.GOLD + "] " + "" + ChatColor.RED + "" + player.getName() + ChatColor.GOLD + " was killed by " + "" + ChatColor.RED + player.getKiller().getName() + "" + ChatColor.RED + " wielding " + ChatColor.GOLD + "" + item);
    30. }
    31. }
    32.  
    33. public void onEnable() {
    34. this.saveDefaultConfig();
    35. this.getConfig();
    36. getLogger().info("PVPBattle by RobloxianFire2 has been enabled!");
    37. Bukkit.getServer().getPluginManager().registerEvents(new DeathListener(), this);
    38. }
    39.  
    40. public void onDisable() {
    41. getLogger().info("PVPBattle by RobloxianFire2 has been disabled!");
    42. }
    43.  
    44. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    45. if(!(sender instanceof Player)) {
    46. sender.sendMessage("Sorry, this command can only be run by an in-game player!");
    47. } else
    48. if(args.length == 0) {
    49. if(cmd.getName().equalsIgnoreCase("pvpbattle")) {
    50. sender.sendMessage(ChatColor.DARK_PURPLE + "" + ChatColor.UNDERLINE + "PVPBattle");
    51. sender.sendMessage("");
    52. sender.sendMessage(ChatColor.GOLD + "List of Classes: /class");
    53. sender.sendMessage(ChatColor.GOLD + "Join Lobby: /join");
    54. sender.sendMessage(ChatColor.GOLD + "PVPBattle Version: /pvpbattle version");
    55. }
    56. } else
    57. if(args.length == 1) {
    58. if(args[0].equalsIgnoreCase("reload")) {
    59. Plugin plugin = this;
    60. PluginManager pm = Bukkit.getServer().getPluginManager();
    61. pm.disablePlugin(plugin);
    62. pm.enablePlugin(plugin);
    63. this.reloadConfig();
    64. sender.sendMessage(ChatColor.GOLD + "PVPBattle has been reloaded!");
    65. }
    66. } else
    67. if(cmd.getName().equalsIgnoreCase("join")) {
    68. Player player = (Player) sender;
    69. Location location = player.getLocation();
    70. location.setX(this.getConfig().getInt("lobbylocation.x"));
    71. location.setY(this.getConfig().getInt("lobbylocation.y"));
    72. location.setZ(this.getConfig().getInt("lobbylocation.z"));
    73. player.teleport(location);
    74. sender.sendMessage(ChatColor.GOLD + "You have been teleported to the lobby.");
    75. player.playSound(location, Sound.LEVEL_UP, 1, 0);
    76. } else
    77. if(cmd.getName().equalsIgnoreCase("class")) {
    78. if (args.length==0) {
    79. sender.sendMessage(ChatColor.RED + "" + ChatColor.GOLD + "" + "Please choose your class:");
    80. sender.sendMessage(ChatColor.RED + "" + "Warrior: " + ChatColor.GOLD + "" + "/class warrior");
    81. sender.sendMessage(ChatColor.RED + "" + "Archer: " + ChatColor.GOLD + "" + "/class archer");
    82. sender.sendMessage(ChatColor.RED + "" + "Knight: " + ChatColor.GOLD + "" + "/class knight");
    83. } else if (args.length==1) {
    84. if (args[0].equalsIgnoreCase("warrior")) {
    85. sender.sendMessage(ChatColor.GREEN + "You have chosen: " + "" + ChatColor.GOLD + "Warrior.");
    86. Player player = (Player) sender;
    87. PlayerInventory inventory = player.getInventory();
    88. Location location = player.getLocation();
    89. ItemStack warriorsword = new ItemStack(Material.DIAMOND_SWORD, 1);
    90. ItemStack warriorhat = new ItemStack(Material.IRON_HELMET);
    91. ItemStack warriorchest = new ItemStack(Material.IRON_CHESTPLATE);
    92. ItemStack warriorlegs = new ItemStack(Material.IRON_LEGGINGS);
    93. ItemStack warriorboots = new ItemStack(Material.IRON_BOOTS);
    94. ItemStack warriorfood = new ItemStack(Material.BREAD, 64);
    95. inventory.setArmorContents(null);
    96. inventory.clear();
    97. inventory.addItem(warriorsword);
    98. inventory.addItem(warriorfood);
    99. inventory.setHelmet(warriorhat);
    100. inventory.setChestplate(warriorchest);
    101. inventory.setLeggings(warriorlegs);
    102. inventory.setBoots(warriorboots);
    103. player.playSound(location, Sound.ORB_PICKUP, 1, 0);
    104. } else
    105. if(args[0].equalsIgnoreCase("archer")) {
    106. sender.sendMessage(ChatColor.GREEN + "You have chosen: " + "" + ChatColor.GOLD + "Archer.");
    107. Player player = (Player) sender;
    108. PlayerInventory inventory = player.getInventory();
    109. Location location = player.getLocation();
    110. ItemStack archerbow = new ItemStack(Material.BOW, 1);
    111. ItemStack archerarrows = new ItemStack(Material.ARROW, 64);
    112. ItemStack archersword = new ItemStack(Material.STONE_SWORD, 1);
    113. ItemStack archerhat = new ItemStack(Material.GOLD_HELMET);
    114. ItemStack archerchest = new ItemStack(Material.GOLD_CHESTPLATE);
    115. ItemStack archerlegs = new ItemStack(Material.GOLD_LEGGINGS);
    116. ItemStack archerboots = new ItemStack(Material.GOLD_BOOTS);
    117. ItemStack archerfood = new ItemStack(Material.BREAD, 32);
    118. inventory.setArmorContents(null);
    119. inventory.clear();
    120. inventory.addItem(archerbow);
    121. inventory.addItem(archerarrows);
    122. inventory.addItem(archersword);
    123. inventory.addItem(archerfood);
    124. inventory.setHelmet(archerhat);
    125. inventory.setChestplate(archerchest);
    126. inventory.setLeggings(archerlegs);
    127. inventory.setBoots(archerboots);
    128. player.playSound(location, Sound.ORB_PICKUP, 1, 0);
    129. } else
    130. if(args[0].equalsIgnoreCase("knight")) {
    131. sender.sendMessage(ChatColor.GREEN + "You have chosen: " + "" + ChatColor.GOLD + "Knight.");
    132. Player player = (Player) sender;
    133. PlayerInventory inventory = player.getInventory();
    134. Location location = player.getLocation();
    135. ItemStack knightsword = new ItemStack(Material.IRON_SWORD);
    136. ItemStack knighthat = new ItemStack(Material.DIAMOND_HELMET);
    137. ItemStack knightchest = new ItemStack(Material.DIAMOND_CHESTPLATE);
    138. ItemStack knightlegs = new ItemStack(Material.DIAMOND_LEGGINGS);
    139. ItemStack knightboots = new ItemStack(Material.DIAMOND_BOOTS);
    140. ItemStack knightfood = new ItemStack(Material.PUMPKIN_PIE, 16);
    141. inventory.setArmorContents(null);
    142. inventory.clear();
    143. inventory.addItem(knightsword);
    144. inventory.addItem(knightfood);
    145. inventory.setHelmet(knighthat);
    146. inventory.setChestplate(knightchest);
    147. inventory.setLeggings(knightlegs);
    148. inventory.setBoots(knightboots);
    149. player.playSound(location, Sound.ORB_PICKUP, 1, 0);
    150. } else {
    151. sender.sendMessage(ChatColor.RED + "That is not a valid class! Please try again.");
    152. }
    153. }
    154. }
    155. return true;
    156. }
    157. }


    As I said, there is no reason for it to not be working unless I'm just blind and I've made a stupid mistake somewhere. ;/

    Sorry if I'm being impatient but I'd like to carry on working with the plugin but without this part working, I cannot as I am not sure if I'd run into more problems and have to post again. If anyone can help, please do so. :)

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

    THEKINGS9701

    rf2minecraft Try adding
    Code:java
    1. location.setYaw(this.getConfig().getInt("lobbylocation.yaw"));
    and adding that line to your config file. By that line I mean lobbylocation.yaw.
     
  3. Offline

    Axanite

    Ok, I'll try.

    What do I add to the config? Just "lobbylocation.yaw"? Nothing else?

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

    THEKINGS9701

  5. Offline

    Axanite

    Yea.

    Code:
    lobbylocation:
      x: 108
      y: 152
      z: 151
     
  6. Offline

    THEKINGS9701

    rf2minecraft add "yaw" under z and see if that works. If it doesn't work actually put "lobbylocation.yaw"
     
  7. Offline

    Axanite

    Ok.

    So after all that, I added the yaw and then I removed unnecessary "else"s from the main class file and then it worked. Thanks guys! :)

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

    THEKINGS9701

    Axanite likes this.
Thread Status:
Not open for further replies.

Share This Page