Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

SetNickColour.java 5.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. /*
  2. * Copyright (c) 2006-2011 Chris Smith, Shane Mc Cormack, Gregory Holmes
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a copy
  5. * of this software and associated documentation files (the "Software"), to deal
  6. * in the Software without restriction, including without limitation the rights
  7. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. * copies of the Software, and to permit persons to whom the Software is
  9. * furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice shall be included in
  12. * all copies or substantial portions of the Software.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  20. * SOFTWARE.
  21. */
  22. package com.dmdirc.commandparser.commands.channel;
  23. import com.dmdirc.Channel;
  24. import com.dmdirc.ChannelClientProperty;
  25. import com.dmdirc.FrameContainer;
  26. import com.dmdirc.commandparser.CommandArguments;
  27. import com.dmdirc.commandparser.CommandInfo;
  28. import com.dmdirc.commandparser.CommandType;
  29. import com.dmdirc.commandparser.commands.Command;
  30. import com.dmdirc.commandparser.commands.IntelligentCommand;
  31. import com.dmdirc.commandparser.commands.context.ChannelCommandContext;
  32. import com.dmdirc.commandparser.commands.context.CommandContext;
  33. import com.dmdirc.parser.interfaces.ChannelClientInfo;
  34. import com.dmdirc.ui.input.AdditionalTabTargets;
  35. import com.dmdirc.ui.input.TabCompletionType;
  36. import com.dmdirc.ui.messages.ColourManager;
  37. import java.awt.Color;
  38. /**
  39. * Allows the user to set a nickname on the channel to use a custom colour.
  40. */
  41. public class SetNickColour extends Command implements IntelligentCommand,
  42. CommandInfo {
  43. /** {@inheritDoc} */
  44. @Override
  45. public void execute(final FrameContainer origin,
  46. final CommandArguments args, final CommandContext context) {
  47. final Channel channel = ((ChannelCommandContext) context).getChannel();
  48. int offset = 0;
  49. boolean nicklist = true;
  50. boolean text = true;
  51. if (args.getArguments().length > offset && args.getArguments()[offset]
  52. .equalsIgnoreCase("--nicklist")) {
  53. text = false;
  54. offset++;
  55. } else if (args.getArguments().length > offset && args.getArguments()[offset]
  56. .equalsIgnoreCase("--text")) {
  57. nicklist = false;
  58. offset++;
  59. }
  60. if (args.getArguments().length <= offset) {
  61. showUsage(origin, args.isSilent(), "setnickcolour", "[--nicklist|--text] <nick> [colour]");
  62. return;
  63. }
  64. final ChannelClientInfo target = channel.getChannelInfo()
  65. .getChannelClient(args.getArguments()[offset]);
  66. offset++;
  67. if (target == null) {
  68. sendLine(origin, args.isSilent(), FORMAT_ERROR, "No such nickname ("
  69. + args.getArguments()[offset - 1] + ")!");
  70. } else if (args.getArguments().length <= offset) {
  71. // We're removing the colour
  72. if (nicklist) {
  73. target.getMap().remove(ChannelClientProperty.NICKLIST_FOREGROUND);
  74. }
  75. if (text) {
  76. target.getMap().remove(ChannelClientProperty.TEXT_FOREGROUND);
  77. }
  78. channel.refreshClients();
  79. } else {
  80. // We're setting the colour
  81. final Color newColour = ColourManager.parseColour(args.getArguments()[offset], null);
  82. if (newColour == null) {
  83. sendLine(origin, args.isSilent(), FORMAT_ERROR, "Invalid colour specified.");
  84. return;
  85. }
  86. if (nicklist) {
  87. target.getMap().put(ChannelClientProperty.NICKLIST_FOREGROUND, newColour);
  88. }
  89. if (text) {
  90. target.getMap().put(ChannelClientProperty.TEXT_FOREGROUND, newColour);
  91. }
  92. channel.refreshClients();
  93. }
  94. }
  95. /** {@inheritDoc} */
  96. @Override
  97. public String getName() {
  98. return "setnickcolour";
  99. }
  100. /** {@inheritDoc} */
  101. @Override
  102. public boolean showInHelp() {
  103. return true;
  104. }
  105. /** {@inheritDoc} */
  106. @Override
  107. public CommandType getType() {
  108. return CommandType.TYPE_CHANNEL;
  109. }
  110. /** {@inheritDoc} */
  111. @Override
  112. public String getHelp() {
  113. return "setnickcolour [--nicklist|--text] <nick> [colour] - "
  114. + "set the specified person's display colour";
  115. }
  116. /** {@inheritDoc} */
  117. @Override
  118. public AdditionalTabTargets getSuggestions(final int arg,
  119. final IntelligentCommandContext context) {
  120. final AdditionalTabTargets targets = new AdditionalTabTargets();
  121. targets.excludeAll();
  122. if (arg == 0) {
  123. targets.include(TabCompletionType.CHANNEL_NICK);
  124. targets.add("--nicklist");
  125. targets.add("--text");
  126. } else if (arg == 1 && (context.getPreviousArgs().get(0).equals("--text")
  127. || context.getPreviousArgs().get(0).equals("--nicklist"))) {
  128. targets.include(TabCompletionType.CHANNEL_NICK);
  129. }
  130. return targets;
  131. }
  132. }