You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

SetNickColour.java 4.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. /*
  2. * Copyright (c) 2006-2007 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 java.awt.Color;
  24. import java.util.Map;
  25. import com.dmdirc.Channel;
  26. import com.dmdirc.ChannelClientProperty;
  27. import com.dmdirc.Config;
  28. import com.dmdirc.Server;
  29. import com.dmdirc.commandparser.ChannelCommand;
  30. import com.dmdirc.commandparser.CommandManager;
  31. import com.dmdirc.commandparser.CommandWindow;
  32. import com.dmdirc.parser.ChannelClientInfo;
  33. import com.dmdirc.parser.ChannelInfo;
  34. import com.dmdirc.ui.ChannelFrame;
  35. import com.dmdirc.ui.messages.ColourManager;
  36. /**
  37. * Allows the user to set a nickname on the channel to use a custom colour.
  38. * @author chris
  39. */
  40. public final class SetNickColour extends ChannelCommand {
  41. /** Creates a new instance of SetNickColour. */
  42. public SetNickColour() {
  43. super();
  44. CommandManager.registerCommand(this);
  45. }
  46. /**
  47. * Executes this command.
  48. * @param origin The frame in which this command was issued
  49. * @param server The server object that this command is associated with
  50. * @param channel The channel object that this command is associated with
  51. * @param isSilent Whetehr this command is silenced or not
  52. * @param args The user supplied arguments
  53. */
  54. @SuppressWarnings("unchecked")
  55. public void execute(final CommandWindow origin, final Server server,
  56. final Channel channel, final boolean isSilent, final String... args) {
  57. int offset = 0;
  58. boolean nicklist = true;
  59. boolean text = true;
  60. if (args.length > offset && args[offset].equalsIgnoreCase("--nicklist")) {
  61. text = false;
  62. offset++;
  63. } else if (args.length > offset && args[offset].equalsIgnoreCase("--text")) {
  64. nicklist = false;
  65. offset++;
  66. }
  67. if (args.length <= offset) {
  68. origin.addLine("commandUsage", Config.getCommandChar(),
  69. "setnickcolour", "[--nicklist|--text] <nick> [colour]");
  70. return;
  71. }
  72. final ChannelClientInfo target = channel.getChannelInfo().getUser(args[offset]);
  73. offset++;
  74. if (target == null) {
  75. origin.addLine("commandError", "No such nickname!");
  76. } else if (args.length <= offset) {
  77. // We're removing the colour
  78. if (nicklist) {
  79. target.getMap().remove(ChannelClientProperty.NICKLIST_FOREGROUND);
  80. }
  81. if (text) {
  82. target.getMap().remove(ChannelClientProperty.TEXT_FOREGROUND);
  83. }
  84. ((ChannelFrame) channel.getFrame()).getNickList().repaint();
  85. } else {
  86. // We're setting the colour
  87. final Color newColour = ColourManager.parseColour(args[offset], null);
  88. if (newColour == null) {
  89. origin.addLine("commandError", "Invalid colour specified.");
  90. return;
  91. }
  92. if (nicklist) {
  93. target.getMap().put(ChannelClientProperty.NICKLIST_FOREGROUND, newColour);
  94. }
  95. if (text) {
  96. target.getMap().put(ChannelClientProperty.TEXT_FOREGROUND, newColour);
  97. }
  98. ((ChannelFrame) channel.getFrame()).getNickList().repaint();
  99. }
  100. }
  101. /** {@inheritDoc}. */
  102. public String getName() {
  103. return "setnickcolour";
  104. }
  105. /** {@inheritDoc}. */
  106. public boolean showInHelp() {
  107. return true;
  108. }
  109. /** {@inheritDoc}. */
  110. public boolean isPolyadic() {
  111. return true;
  112. }
  113. /** {@inheritDoc}. */
  114. public int getArity() {
  115. return 0;
  116. }
  117. /** {@inheritDoc}. */
  118. public String getHelp() {
  119. return "setnickcolour [--nicklist|--text] <nick> [colour] - set the specified person's display colour";
  120. }
  121. }