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

SetNickColour.java 5.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. /*
  2. * Copyright (c) 2006-2011 DMDirc Developers
  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.BaseCommandInfo;
  27. import com.dmdirc.commandparser.CommandArguments;
  28. import com.dmdirc.commandparser.CommandInfo;
  29. import com.dmdirc.commandparser.CommandType;
  30. import com.dmdirc.commandparser.commands.Command;
  31. import com.dmdirc.commandparser.commands.IntelligentCommand;
  32. import com.dmdirc.commandparser.commands.context.ChannelCommandContext;
  33. import com.dmdirc.commandparser.commands.context.CommandContext;
  34. import com.dmdirc.parser.interfaces.ChannelClientInfo;
  35. import com.dmdirc.ui.input.AdditionalTabTargets;
  36. import com.dmdirc.ui.input.TabCompletionType;
  37. import com.dmdirc.ui.messages.ColourManager;
  38. import java.awt.Color;
  39. /**
  40. * Allows the user to set a nickname on the channel to use a custom colour.
  41. */
  42. public class SetNickColour extends Command implements IntelligentCommand {
  43. /** A command info object for this command. */
  44. public static final CommandInfo INFO = new BaseCommandInfo("setnickcolour",
  45. "setnickcolour [--nicklist|--text] <nick> [colour] - "
  46. + "set the specified person's display colour",
  47. CommandType.TYPE_CHANNEL);
  48. /** {@inheritDoc} */
  49. @Override
  50. public void execute(final FrameContainer origin,
  51. final CommandArguments args, final CommandContext context) {
  52. final Channel channel = ((ChannelCommandContext) context).getChannel();
  53. int offset = 0;
  54. boolean nicklist = true;
  55. boolean text = true;
  56. if (args.getArguments().length > offset && args.getArguments()[offset]
  57. .equalsIgnoreCase("--nicklist")) {
  58. text = false;
  59. offset++;
  60. } else if (args.getArguments().length > offset && args.getArguments()[offset]
  61. .equalsIgnoreCase("--text")) {
  62. nicklist = false;
  63. offset++;
  64. }
  65. if (args.getArguments().length <= offset) {
  66. showUsage(origin, args.isSilent(), "setnickcolour", "[--nicklist|--text] <nick> [colour]");
  67. return;
  68. }
  69. final ChannelClientInfo target = channel.getChannelInfo()
  70. .getChannelClient(args.getArguments()[offset]);
  71. offset++;
  72. if (target == null) {
  73. sendLine(origin, args.isSilent(), FORMAT_ERROR, "No such nickname ("
  74. + args.getArguments()[offset - 1] + ")!");
  75. } else if (args.getArguments().length <= offset) {
  76. // We're removing the colour
  77. if (nicklist) {
  78. target.getMap().remove(ChannelClientProperty.NICKLIST_FOREGROUND);
  79. }
  80. if (text) {
  81. target.getMap().remove(ChannelClientProperty.TEXT_FOREGROUND);
  82. }
  83. channel.refreshClients();
  84. } else {
  85. // We're setting the colour
  86. final Color newColour = ColourManager.parseColour(args.getArguments()[offset], null);
  87. if (newColour == null) {
  88. sendLine(origin, args.isSilent(), FORMAT_ERROR, "Invalid colour specified.");
  89. return;
  90. }
  91. if (nicklist) {
  92. target.getMap().put(ChannelClientProperty.NICKLIST_FOREGROUND, newColour);
  93. }
  94. if (text) {
  95. target.getMap().put(ChannelClientProperty.TEXT_FOREGROUND, newColour);
  96. }
  97. channel.refreshClients();
  98. }
  99. }
  100. /** {@inheritDoc} */
  101. @Override
  102. public AdditionalTabTargets getSuggestions(final int arg,
  103. final IntelligentCommandContext context) {
  104. final AdditionalTabTargets targets = new AdditionalTabTargets();
  105. targets.excludeAll();
  106. if (arg == 0) {
  107. targets.include(TabCompletionType.CHANNEL_NICK);
  108. targets.add("--nicklist");
  109. targets.add("--text");
  110. } else if (arg == 1 && (context.getPreviousArgs().get(0).equals("--text")
  111. || context.getPreviousArgs().get(0).equals("--nicklist"))) {
  112. targets.include(TabCompletionType.CHANNEL_NICK);
  113. }
  114. return targets;
  115. }
  116. }