alexroge

java

Apr 19th, 2015
255
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.95 KB | None | 0 0
  1. package fr.alexroge.rush.Commands;
  2.  
  3. import fr.alexroge.rush.ChatWriter;
  4. import fr.alexroge.rush.Main;
  5. import fr.alexroge.rush.Game.Game;
  6. import fr.alexroge.rush.Game.Team;
  7.  
  8. import java.util.ArrayList;
  9. import java.util.HashSet;
  10.  
  11. import org.bukkit.ChatColor;
  12. import org.bukkit.Material;
  13. import org.bukkit.block.Block;
  14. import org.bukkit.block.BlockFace;
  15. import org.bukkit.command.CommandSender;
  16. import org.bukkit.entity.Player;
  17. import org.bukkit.material.Bed;
  18.  
  19. import com.google.common.collect.ImmutableMap;
  20.  
  21. public class SetBedCommand extends BaseCommand implements ICommand {
  22.  
  23. public SetBedCommand(Main plugin) {
  24. super(plugin);
  25. }
  26.  
  27. @Override
  28. public String getCommand() {
  29. return "setbed";
  30. }
  31.  
  32. @Override
  33. public String getName() {
  34. return Main._l("commands.setbed.name");
  35. }
  36.  
  37. @Override
  38. public String getDescription() {
  39. return Main._l("commands.setbed.desc");
  40. }
  41.  
  42. @Override
  43. public String[] getArguments() {
  44. return new String[] { "game", "team" };
  45. }
  46.  
  47. @Override
  48. public boolean execute(CommandSender sender, ArrayList<String> args) {
  49. if (!super.hasPermission(sender)) {
  50. return false;
  51. }
  52.  
  53. Player player = (Player) sender;
  54. String team = args.get(1);
  55.  
  56. Game game = this.getPlugin().getGameManager().getGame(args.get(0));
  57. if (game == null) {
  58. player.sendMessage(ChatWriter.pluginMessage(ChatColor.RED
  59. + Main._l("errors.gamenotfound",
  60. ImmutableMap.of("game", args.get(0).toString()))));
  61. return false;
  62. }
  63.  
  64. Team gameTeam = game.getTeam(team);
  65.  
  66. if (team == null) {
  67. player.sendMessage(ChatWriter.pluginMessage(ChatColor.RED
  68. + Main._l("errors.teamnotfound")));
  69. return false;
  70. }
  71.  
  72. HashSet<Material> transparent = new HashSet<Material>();
  73. transparent.add(Material.AIR);
  74.  
  75. Block targetBlock = player.getTargetBlock(transparent, 15);
  76. Block standingBlock = player.getLocation().getBlock()
  77. .getRelative(BlockFace.DOWN);
  78.  
  79. if (targetBlock == null || standingBlock == null) {
  80. player.sendMessage(ChatWriter.pluginMessage(ChatColor.RED
  81. + Main._l("errors.bedtargeting")));
  82. return false;
  83. }
  84.  
  85. if (targetBlock.getType() != Material.BED_BLOCK
  86. && standingBlock.getType() != Material.BED_BLOCK) {
  87. player.sendMessage(ChatWriter.pluginMessage(ChatColor.RED
  88. + Main._l("errors.bedtargeting")));
  89. return false;
  90. }
  91.  
  92. Block theBlock = null;
  93. if (targetBlock.getType() == Material.BED_BLOCK) {
  94. theBlock = targetBlock;
  95. } else {
  96. theBlock = standingBlock;
  97. }
  98.  
  99. Bed theBed = (Bed) theBlock.getState().getData();
  100.  
  101. if (!theBed.isHeadOfBed()) {
  102. theBlock = theBlock.getRelative(theBed.getFacing());
  103. }
  104.  
  105. gameTeam.setBed(theBlock);
  106. player.sendMessage(ChatWriter.pluginMessage(ChatColor.GREEN
  107. + Main._l(
  108. "success.bedset",
  109. ImmutableMap.of("team", gameTeam.getChatColor()
  110. + gameTeam.getName() + ChatColor.GREEN))));
  111. return true;
  112. }
  113.  
  114. @Override
  115. public String getPermission() {
  116. return "setup";
  117. }
  118.  
  119. }
Advertisement
Add Comment
Please, Sign In to add comment