Crossfire JXClient, Trunk  R20561
CommandType.java
Go to the documentation of this file.
1 /*
2  * This file is part of JXClient, the Fullscreen Java Crossfire Client.
3  *
4  * JXClient is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * JXClient is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with JXClient; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17  *
18  * Copyright (C) 2005-2008 Yann Chachkoff.
19  * Copyright (C) 2006-2011 Andreas Kirschbaum.
20  */
21 
22 package com.realtime.crossfire.jxclient.gui.commands;
23 
28 import org.jetbrains.annotations.NotNull;
29 import org.jetbrains.annotations.Nullable;
30 
35 public enum CommandType {
36 
40  APPLY {
42  @Override
43  protected void doExecute(@NotNull final CfItem item, @NotNull final CrossfireServerConnection crossfireServerConnection, final int floor, @NotNull final CommandQueue commandQueue) {
44  crossfireServerConnection.sendApply(item.getTag());
45  }
46  },
47 
51  DROP {
53  @Override
54  protected void doExecute(@NotNull final CfItem item, @NotNull final CrossfireServerConnection crossfireServerConnection, final int floor, @NotNull final CommandQueue commandQueue) {
55  if (item.isLocked()) {
56  crossfireServerConnection.drawInfo("This item is locked. To drop it, first unlock by SHIFT+left-clicking on it.", 3);
57  } else {
58  commandQueue.sendMove(floor, item.getTag());
59  }
60  }
61  },
62 
66  EXAMINE {
68  @Override
69  protected void doExecute(@NotNull final CfItem item, @NotNull final CrossfireServerConnection crossfireServerConnection, final int floor, @NotNull final CommandQueue commandQueue) {
70  crossfireServerConnection.sendExamine(item.getTag());
71  }
72  },
73 
77  LOCK {
79  @Override
80  protected void doExecute(@NotNull final CfItem item, @NotNull final CrossfireServerConnection crossfireServerConnection, final int floor, @NotNull final CommandQueue commandQueue) {
81  crossfireServerConnection.sendLock(true, item.getTag());
82  }
83  },
84 
88  LOCK_TOGGLE {
90  @Override
91  protected void doExecute(@NotNull final CfItem item, @NotNull final CrossfireServerConnection crossfireServerConnection, final int floor, @NotNull final CommandQueue commandQueue) {
92  crossfireServerConnection.sendLock(!item.isLocked(), item.getTag());
93  }
94  },
95 
99  MARK {
101  @Override
102  protected void doExecute(@NotNull final CfItem item, @NotNull final CrossfireServerConnection crossfireServerConnection, final int floor, @NotNull final CommandQueue commandQueue) {
103  crossfireServerConnection.sendMark(item.getTag());
104  }
105  },
106 
110  UNLOCK {
112  @Override
113  protected void doExecute(@NotNull final CfItem item, @NotNull final CrossfireServerConnection crossfireServerConnection, final int floor, @NotNull final CommandQueue commandQueue) {
114  crossfireServerConnection.sendLock(false, item.getTag());
115  }
116  },;
117 
123  public static boolean canExecute(@Nullable final GUIItemItem guiItem) {
124  return guiItem != null && guiItem.getItem() != null;
125  }
126 
134  public void execute(@Nullable final GUIItemItem guiItem, @NotNull final CrossfireServerConnection crossfireServerConnection, final int floor, @NotNull final CommandQueue commandQueue) {
135  if (guiItem == null) {
136  return;
137  }
138 
139  final CfItem item = guiItem.getItem();
140  if (item == null) {
141  return;
142  }
143 
144  doExecute(item, crossfireServerConnection, floor, commandQueue);
145  }
146 
154  protected abstract void doExecute(@NotNull final CfItem item, @NotNull final CrossfireServerConnection crossfireServerConnection, final int floor, @NotNull final CommandQueue commandQueue);
155 
156 }
static boolean canExecute(@Nullable final GUIItemItem guiItem)
Returns whether the action can be executed.
A GUIElement instance representing an in-game item.
void execute(@Nullable final GUIItemItem guiItem, @NotNull final CrossfireServerConnection crossfireServerConnection, final int floor, @NotNull final CommandQueue commandQueue)
Executes the action.
Adds encoding/decoding of crossfire protocol packets to a ServerConnection.
Maintains the pending (ncom) commands sent to the server.
The representation of a Crossfire Item, client-side.
Definition: CfItem.java:36