My Project, do you have tips?

Discussion in 'Plugin Development' started by HungerCraftNL, Aug 17, 2013.

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

    HungerCraftNL

    Hello,

    I'm making a 'mini-game' plugin, I've looked quite some tutorials, and I have messed arrount with coding. I'm not a pro in coding.

    Mini-Game Idea
    A simple PvP mini-game, you join the server, and got in the lobby. You'll have 60 to ready yourself (With walking arount). There are 2 teams, a blue one and a red one. If the countdown (60 seconds) is done, you'll automatic go in a team, and get a kit of items (Autostart with 2 players online).
    The team with the most kills wins, and gets points, with points can you buy later items (Like swords/armor).

    Main class:
    Code:java
    1. package me.Shadow48402.scoreboard;
    2.  
    3. import java.util.logging.Logger;
    4.  
    5. import org.bukkit.Bukkit;
    6. import org.bukkit.ChatColor;
    7. import org.bukkit.entity.Player;
    8. import org.bukkit.event.Listener;
    9. import org.bukkit.plugin.java.JavaPlugin;
    10. import org.bukkit.scoreboard.DisplaySlot;
    11. import org.bukkit.scoreboard.Objective;
    12. import org.bukkit.scoreboard.Score;
    13. import org.bukkit.scoreboard.Scoreboard;
    14. import org.bukkit.scoreboard.ScoreboardManager;
    15. import org.bukkit.scoreboard.Team;
    16.  
    17. public class Main extends JavaPlugin implements Listener {
    18. public final Logger logger = Logger.getLogger("Minecraft");
    19.  
    20.  
    21. @Override
    22. public void onDisable() {
    23. this.logger.info("Has Been Disabled!");
    24.  
    25. }
    26.  
    27. public void onEnable() {
    28. getServer().getPluginManager().registerEvents(this, this);
    29. getServer().getPluginManager().registerEvents(new JoinEvent(), this);
    30.  
    31. ScoreboardManager sbManager = Bukkit.getScoreboardManager();
    32. Scoreboard sBoard = sbManager.getNewScoreboard();
    33.  
    34. Team red = sBoard.registerNewTeam("red");
    35. Team blue = sBoard.registerNewTeam("blue");
    36.  
    37. red.setPrefix(ChatColor.RED + "");
    38. blue.setPrefix(ChatColor.BLUE + "");
    39.  
    40. red.setDisplayName(ChatColor.RED + getName());
    41. blue.setDisplayName(ChatColor.BLUE + getName());
    42.  
    43. red.setAllowFriendlyFire(false);
    44. blue.setAllowFriendlyFire(false);
    45.  
    46. Objective obj = sBoard.registerNewObjective("Kill lists", "Kills");
    47.  
    48. obj.setDisplaySlot(DisplaySlot.SIDEBAR);
    49. obj.setDisplayName("Kills");
    50.  
    51. Score score = obj.getScore(Bukkit.getOfflinePlayer("Total kills"));
    52. score.setScore(0);
    53.  
    54. for(Player player : Bukkit.getOnlinePlayers()){
    55. player.setScoreboard(sBoard);
    56. player.setScoreboard(sbManager.getNewScoreboard());
    57. }
    58.  
    59. Scoreboard pHealt = sbManager.getNewScoreboard();
    60. Objective Healt = pHealt.registerNewObjective("PlayerNameHealt", "Healt");
    61. Healt.setDisplaySlot(DisplaySlot.BELOW_NAME);
    62. Healt.setDisplayName(" Hearts");
    63.  
    64. for(Player player : Bukkit.getOnlinePlayers()) {
    65. player.setScoreboard(pHealt);
    66. }
    67. }
    68. }
    69.  

    in this class is the ScoreBoard, and this class contains the onDisable/onEnable.

    JoinEvent:
    Code:java
    1. package me.Shadow48402.scoreboard;
    2.  
    3. import net.minecraft.server.v1_6_R2.Item;
    4. import net.minecraft.server.v1_6_R2.ItemAxe;
    5.  
    6. import org.bukkit.Bukkit;
    7. import org.bukkit.ChatColor;
    8. import org.bukkit.Location;
    9. import org.bukkit.Material;
    10. import org.bukkit.entity.Player;
    11. import org.bukkit.event.EventHandler;
    12. import org.bukkit.event.Listener;
    13. import org.bukkit.event.player.PlayerJoinEvent;
    14. import org.bukkit.inventory.ItemStack;
    15. import org.bukkit.inventory.PlayerInventory;
    16. import org.bukkit.plugin.Plugin;
    17. import org.fusesource.jansi.Ansi.Color;
    18.  
    19. public class JoinEvent implements Listener{
    20.  
    21. @EventHandler
    22. public void onPlayerJoinEvent(PlayerJoinEvent event) {
    23. Player player = event.getPlayer();
    24. player.sendMessage(ChatColor.AQUA + "Welkom in Lomeus Team-PvP");
    25.  
    26. Location Lobby = new Location(Bukkit.getWorld("World"), 1,1, 0); //TODO : Set spawn
    27.  
    28. player.teleport(Lobby);
    29.  
    30. final int Countdown;
    31. final Player player1 = event.getPlayer();
    32. Countdown = Bukkit.getScheduler().scheduleSyncDelayedTask((Plugin) this, new Runnable() {
    33. public void run() {
    34. int count = 6;
    35. if(count !=0){
    36. if(Bukkit.getOnlinePlayers().length == 2); {
    37.  
    38.  
    39. Location SpawnRed = new Location(Bukkit.getWorld("World"), 1,1, 0); //TODO : Set spawn
    40. Location SpawnBlue = new Location(Bukkit.getWorld("World"), 1,1, 0); //TODO : Set spawn
    41.  
    42. player1.teleport(SpawnBlue);
    43.  
    44. ItemStack HelmBlue = new ItemStack(Material.LEATHER_HELMET, 1);
    45. ItemStack ChestPlateBlue = new ItemStack(Material.LEATHER_CHESTPLATE, 1);
    46. ItemStack LeggingsBlue = new ItemStack(Material.LEATHER_LEGGINGS, 1);
    47. ItemStack BootsBlue = new ItemStack(Material.LEATHER_BOOTS, 1);
    48.  
    49. ItemStack HelmRed = new ItemStack(Material.LEATHER_HELMET, 1);
    50. ItemStack ChestPlateRed = new ItemStack(Material.LEATHER_CHESTPLATE, 1);
    51. ItemStack LeggingsRed = new ItemStack(Material.LEATHER_LEGGINGS, 1);
    52. ItemStack BootsRed = new ItemStack(Material.LEATHER_BOOTS, 1);
    53.  
    54. ItemStack SwordRed = new ItemStack(Material.DIAMOND_SWORD, 1);
    55. ItemStack SwordBlue = new ItemStack(Material.DIAMOND_SWORD, 1);
    56.  
    57. SwordRed.getItemMeta().setDisplayName(Color.RED + "RedTeam Sword");
    58. SwordBlue.getItemMeta().setDisplayName(Color.BLUE + "BlueTeam Sword");
    59.  
    60.  
    61. PlayerInventory inv = player1.getInventory();
    62.  
    63. inv.setHelmet(HelmBlue);
    64. inv.setChestplate(ChestPlateBlue);
    65. inv.setLeggings(LeggingsBlue);
    66. inv.setBoots(BootsBlue);
    67. inv.addItem(SwordBlue);
    68. }
    69. }
    70. }
    71. }
    72. }
    73. }

    This class contains the spawns and the countdown, this class will set you also in the teams.

    This what I have so far, I started as a test for the scoreboard (That's why the JavaProject is called ScoreBoard), tips are welcome, and if you can explain something what is not in the classes should I appreciate that.

    Thank you for reading, and sorry for my bad English.

    I've to make a HashMap I know that btw.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 3, 2016
  2. HungerCraftNL Why are you using "getDescription()" in the onDisable() method? There is no countdown somewhere, correct? If you need to add a countdown then just make a repeating task that repeats itself every 20 ticks (20 ticks = 1 second) and then do countdown--;.
     
  3. Offline

    HungerCraftNL

    The 'GetDescription()' was just a little fould, and about the countdown:
    Code:java
    1. int cooldown = 60;//TODO : fix
    2. int maxcooldown = 60;//TODO : fix
    3. final Player p = event.getPlayer();
    4. if(cooldown < maxcooldown)
    5. {
    6. p.setExp(cooldown/maxcooldown);
    7. }
    8. else
    9. {
    10. //TODO : Autoselect to teams
    11. }
    12. }

    will not work?
     
  4. Offline

    HungerCraftNL

    Any suggests, or options for a countdown?
     
  5. HungerCraftNL take a look at scheduler programming, there's a good tutorial on the bukkit wiki.
     
  6. Offline

    HungerCraftNL

    I've worked on the Join listener, but I used the void 'run' and ofcourse he don't understand the 'join' anymore, so the event has changed :/ ( No event player) Can someone help, or give a tip for a new countdown?

    Updated codes.

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

Share This Page