Major Plugin Help

Discussion in 'Plugin Development' started by Aperx, Jul 2, 2013.

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

    Aperx

    Okay. Basically, im coding for a new server coming out, but im using teams and array lists and to be honest, im completely lost. I've tried doing so many things that just don't work, i've never worked with teams before so i'm not 100% sure how that all works along with other things. Anyway, i want some help looking over my code, as i know its not right as it already has bugs.

    Code:java
    1. package me.aperxmc.youtube;
    2.  
    3. import java.util.HashSet;
    4. import java.util.Set;
    5. import java.util.logging.Logger;
    6.  
    7. import org.bukkit.Bukkit;
    8. import org.bukkit.ChatColor;
    9. import org.bukkit.command.Command;
    10. import org.bukkit.command.CommandSender;
    11. import org.bukkit.entity.Player;
    12. import org.bukkit.plugin.PluginDescriptionFile;
    13. import org.bukkit.plugin.PluginManager;
    14. import org.bukkit.plugin.java.JavaPlugin;
    15. import org.bukkit.scoreboard.Scoreboard;
    16. import org.bukkit.scoreboard.ScoreboardManager;
    17. import org.bukkit.scoreboard.Team;
    18.  
    19. public class Maingame extends JavaPlugin {
    20.  
    21. public final Logger logger = Logger.getLogger("Minecraft");
    22. private final String PREFIX = ChatColor.DARK_GRAY + "[" + ChatColor.RESET + ChatColor.DARK_RED + ChatColor.BOLD.toString() + "AoA" + ChatColor.RESET + ChatColor.DARK_GRAY + "] " + ChatColor.RESET;
    23. private final String GP = ChatColor.GOLD + ChatColor.BOLD.toString() + "[" + ChatColor.RESET + ChatColor.DARK_AQUA + "Guard" + ChatColor.GOLD + ChatColor.BOLD.toString() + "]";
    24. private final String AP = ChatColor.GOLD + ChatColor.BOLD.toString() + "[" + ChatColor.RESET + ChatColor.RED + "Assasin" + ChatColor.GOLD + ChatColor.BOLD.toString() + "]";
    25. public static final FriendlyFireHandler FFH = new FriendlyFireHandler();
    26. private ScoreboardManager sbMgr;
    27. public Scoreboard sbMain;
    28. public static Maingame plugin;
    29.  
    30. @Override
    31. public void onEnable(){
    32. // TODO Insert logic to be performed when the plugin is enabled
    33. PluginDescriptionFile pdfFile = this.getDescription();
    34. this.logger.info( "Attack of the Assasins Version " + pdfFile.getVersion() + " Has Begun! Coded By Aperx. Designed by Doooogle");
    35. PluginManager pm = getServer().getPluginManager();
    36. this.sbMgr = Bukkit.getScoreboardManager();
    37. this.sbMain = this.sbMgr.getMainScoreboard();
    38. Guards.clear();
    39. Assasins.clear();
    40.  
    41.  
    42.  
    43. }
    44.  
    45.  
    46. @Override
    47. public void onDisable() {
    48. // TODO Insert logic to be performed when the plugin is disabled
    49. PluginDescriptionFile pdfFile = this.getDescription();
    50. this.logger.info("Attack of the Assasians Version " + pdfFile.getVersion() + " Has Ended! Thankyou for Using us! Coded by Aperx, Designed by Doooogle");
    51. Guards.clear();
    52. Assasins.clear();
    53. }
    54.  
    55. static Set<String> Assasins = new HashSet<String>();
    56. static Set<String> Guards = new HashSet<String>();
    57.  
    58.  
    59.  
    60.  
    61.  
    62. public boolean onCommand(CommandSender sender, Command cmd, String CommandLabel, String[] args){
    63. Player player = (Player) sender;
    64.  
    65.  
    66.  
    67. if (CommandLabel.equalsIgnoreCase("join"));
    68. if (Assasins.size()== 5);
    69. if (Guards.size()== 5);
    70. player.sendMessage(this.PREFIX + ChatColor.RED + "Sorry, the game is full. Please type /spawn, spectate or wait for the next game.");
    71.  
    72.  
    73. if(Guards.size() == Assasins.size()){
    74. Guards.add(player.getName());
    75. player.setDisplayName(ChatColor.GOLD + "[" + ChatColor.DARK_AQUA + "Guard" + ChatColor.GOLD + "] " + player.getName());
    76. player.sendMessage(this.PREFIX + ChatColor.DARK_AQUA + "You are now a Guard. Pick your Class!");
    77. }
    78. else if(Guards.size() > Assasins.size())
    79. {
    80. Assasins.add(player.getName());
    81. player.setDisplayName(ChatColor.GOLD + "[" + ChatColor.DARK_AQUA + "Guard" + ChatColor.GOLD + "] " + player.getName());
    82. player.sendMessage(this.PREFIX + ChatColor.RED + "You are now a Assasin. Pick your Class!");
    83. }
    84. else if(Assasins.size() < Guards.size())
    85.  
    86. {
    87. Assasins.add(player.getName());
    88. player.setDisplayName(ChatColor.GOLD + "[" + ChatColor.DARK_AQUA + "Guard" + ChatColor.GOLD + "] " + player.getName());
    89. player.sendMessage(this.PREFIX + ChatColor.RED + "You are now a Assasin. Pick your Class!");
    90. }
    91.  
    92. return false;
    93.  
    94. }
    95.  
    96.  
    97. private boolean ChangeName(Player target, String name) {
    98. Team bTeam = this.sbMain.getPlayerTeam(target);
    99. ((Team) Guards).setPrefix("[Guard]");
    100. return true;
    101.  
    102. }
    103.  
    104.  
    105.  
    106.  
    107.  
    108.  
    109.  
    110. }
    111.  
    112. //End of Main Class
    113.  


    Here, i'm trying to make it so on the /join command, the player is added to team, Assassin or Guard, they would be added to a team, set a prefix depending on their team, and then i have another class that doesn't allow people on the same team to hit eachother, but i believe you can set the friendly fire off, however, again, i'm not sure, well not so much not sure how, but more so where to put it.

    The friendly fire handler is here

    Code:java
    1. package me.aperxmc.youtube;
    2.  
    3. import java.util.ArrayList;
    4. import java.util.LinkedList;
    5. import org.bukkit.ChatColor;
    6. import org.bukkit.entity.Player;
    7. import org.bukkit.event.EventHandler;
    8. import org.bukkit.event.EventPriority;
    9. import org.bukkit.event.Listener;
    10. import org.bukkit.event.entity.EntityDamageByEntityEvent;
    11.  
    12. public class FriendlyFireHandler
    13. implements Listener
    14.  
    15.  
    16. {
    17.  
    18. private final String PREFIX = ChatColor.DARK_GRAY + "[" + ChatColor.RESET + ChatColor.DARK_RED + ChatColor.BOLD.toString() + "AoA" + ChatColor.RESET + ChatColor.DARK_GRAY + "] " + ChatColor.RESET;
    19. @EventHandler(priority=EventPriority.HIGH)
    20. public void onPlayerHit(EntityDamageByEntityEvent e)
    21. {
    22. if (((e.getDamager() instanceof Player)) &&
    23. ((e.getEntity() instanceof Player))) {
    24. if ((Maingame.Guards.contains(e.getDamager())) &&
    25. (Maingame.Guards.contains(e.getEntity()))) {
    26. Player dmg = (Player)e.getDamager();
    27. dmg.sendMessage(this.PREFIX +
    28. ChatColor.RED + "You can't hurt your teammates!");
    29. e.setCancelled(true);
    30. return;
    31. }
    32.  
    33. if ((Maingame.Assasins.contains(e.getDamager())) &&
    34. (Maingame.Assasins.contains(e.getEntity()))) {
    35. Player dmg = (Player)e.getDamager();
    36. dmg.sendMessage(this.PREFIX +
    37. ChatColor.RED + "You can't hurt your teammates!");
    38. e.setCancelled(true);
    39. return;
    40. }
    41.  
    42.  
    43.  
    44. return;
    45. }
    46. }
    47. }


    That's basically the basis of it. Once i get that all working, the rest of it should be pretty easy, but until then i'm calling on you guys to help a fellow coder out and give me some direction, examples and all.

    Any help is muchly appreciated! Thanks
    Aperx
     
  2. Offline

    Aperx

    *Bump* :p
     
  3. Offline

    GodzOfMadness

    Aperx For the ChangeName method, you never actually 'change' the name. You also might want to put a try/catch block on it to make sure that the name isn't null or the player. If it is then the function has support for returning false when it wasn't successful.

    Try formatting your code aswell, it really helps a lot(unless it's already formatted and that is what happened when pasting it to the page).
     
  4. Offline

    Aperx

    GodzOfMadness So what you're saying is, I've told it what to change their name to, but i haven't actually set it? If this is the case, how do i actually set it?
     
  5. Offline

    GodzOfMadness

    Aperx I'm not sure how this is working but you set the prefix by casting Team to a Set data type. I think you should just get the team the player is on and then just set the prefix by like bTeam.setDisplayName("[Guard]") Which sets the prefix for all players in that team. I don't know about setting their name thought, what are you trying to do there?
     
Thread Status:
Not open for further replies.

Share This Page