Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

SetNickColour.java 4.9KB

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