mirror of
https://github.com/Rogiel/l2jserver2
synced 2025-12-06 07:32:46 +00:00
Removes duplicated Shortcut class
This commit is contained in:
@@ -1,324 +0,0 @@
|
||||
/*
|
||||
* This file is part of l2jserver2 <l2jserver2.com>.
|
||||
*
|
||||
* l2jserver2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* l2jserver2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with l2jserver2. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.l2jserver.model.game;
|
||||
|
||||
import com.l2jserver.model.AbstractModel;
|
||||
import com.l2jserver.model.id.ShortcutID;
|
||||
import com.l2jserver.model.id.object.CharacterID;
|
||||
import com.l2jserver.model.id.object.ItemID;
|
||||
import com.l2jserver.model.id.template.SkillTemplateID;
|
||||
import com.l2jserver.model.world.L2Character;
|
||||
|
||||
/**
|
||||
* An shortcut in Lineage II game interface
|
||||
*
|
||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||
*/
|
||||
public class Shortcut extends AbstractModel<ShortcutID> {
|
||||
/**
|
||||
* The character id
|
||||
*/
|
||||
private final CharacterID characterID;
|
||||
/**
|
||||
* The shortcut skill id (only if <tt>type</tt> is
|
||||
* {@link ShortcutType#SKILL})
|
||||
*/
|
||||
private SkillTemplateID skillID;
|
||||
|
||||
/**
|
||||
* The shortcut item id (only if <tt>type</tt> is {@link ShortcutType#ITEM})
|
||||
*/
|
||||
private ItemID itemID;
|
||||
|
||||
/**
|
||||
* The shortcut slot (0 - 11 = 12 slots/page)
|
||||
*/
|
||||
private int slot;
|
||||
/**
|
||||
* The shortcut page (0-3 = 4 pages)
|
||||
*/
|
||||
private int page;
|
||||
/**
|
||||
* The shortcut type
|
||||
*/
|
||||
private ShortcutType type;
|
||||
|
||||
/**
|
||||
* Enum with all shortcut types supported
|
||||
*
|
||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||
*/
|
||||
public enum ShortcutType {
|
||||
/**
|
||||
* Item shortcut
|
||||
*/
|
||||
ITEM(1),
|
||||
/**
|
||||
* Skill shortcut
|
||||
*/
|
||||
SKILL(2),
|
||||
/**
|
||||
* Social action shortcut
|
||||
*/
|
||||
ACTION(3),
|
||||
/**
|
||||
* Macro shortcut
|
||||
*/
|
||||
MACRO(4),
|
||||
/**
|
||||
* Recipe shortcut
|
||||
*/
|
||||
RECIPE(5),
|
||||
/**
|
||||
* Bookmark shortcut
|
||||
*/
|
||||
TPBOOKMARK(6);
|
||||
|
||||
/**
|
||||
* The shortcut type id
|
||||
*/
|
||||
public final int id;
|
||||
|
||||
/**
|
||||
* @param id
|
||||
* the numeric id
|
||||
*/
|
||||
ShortcutType(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param id
|
||||
* the type id
|
||||
* @return the {@link ShortcutType}
|
||||
*/
|
||||
public static ShortcutType fromID(int id) {
|
||||
for (final ShortcutType shortcut : values()) {
|
||||
if (shortcut.id == id)
|
||||
return shortcut;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The skill level (only if <tt>type</tt> is {@link ShortcutType#SKILL})
|
||||
*/
|
||||
private int level;
|
||||
/**
|
||||
* unknown!
|
||||
*/
|
||||
private int characterType;
|
||||
|
||||
/**
|
||||
* Creates a new instance
|
||||
*
|
||||
* @param characterID
|
||||
* the character id
|
||||
*/
|
||||
public Shortcut(CharacterID characterID) {
|
||||
this.characterID = characterID;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new Item Shortcut
|
||||
*
|
||||
* @param characterID
|
||||
* the character id
|
||||
* @param itemID
|
||||
* the item id
|
||||
* @param characterType
|
||||
* the character type
|
||||
*/
|
||||
public Shortcut(CharacterID characterID, ItemID itemID, int characterType) {
|
||||
this.type = ShortcutType.ITEM;
|
||||
this.characterID = characterID;
|
||||
this.itemID = itemID;
|
||||
this.characterType = characterType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new Skill Shortcut
|
||||
*
|
||||
* @param characterID
|
||||
* the character id
|
||||
* @param skillID
|
||||
* the skill id
|
||||
* @param level
|
||||
* the skill level
|
||||
* @param characterType
|
||||
* the character type
|
||||
*/
|
||||
public Shortcut(CharacterID characterID, SkillTemplateID skillID,
|
||||
int level, int characterType) {
|
||||
this.type = ShortcutType.SKILL;
|
||||
this.characterID = characterID;
|
||||
this.skillID = skillID;
|
||||
this.level = level;
|
||||
this.characterType = characterType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates another type of shortcut
|
||||
*
|
||||
* @param characterID
|
||||
* the character id
|
||||
* @param type
|
||||
* the shortcut type
|
||||
* @param slot
|
||||
* the shortcut slot
|
||||
* @param page
|
||||
* the shortcut page
|
||||
* @param characterType
|
||||
* the character type
|
||||
*/
|
||||
public Shortcut(CharacterID characterID, ShortcutType type, int slot,
|
||||
int page, int characterType) {
|
||||
this.characterID = characterID;
|
||||
this.slot = slot;
|
||||
this.page = page;
|
||||
this.type = type;
|
||||
this.characterType = characterType;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the skillID
|
||||
*/
|
||||
public SkillTemplateID getSkillID() {
|
||||
return skillID;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param skillID
|
||||
* the skillID to set
|
||||
*/
|
||||
public void setSkillID(SkillTemplateID skillID) {
|
||||
desireUpdate();
|
||||
this.skillID = skillID;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the itemID
|
||||
*/
|
||||
public ItemID getItemID() {
|
||||
return itemID;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param itemID
|
||||
* the itemID to set
|
||||
*/
|
||||
public void setItemID(ItemID itemID) {
|
||||
desireUpdate();
|
||||
this.itemID = itemID;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the slot
|
||||
*/
|
||||
public int getSlot() {
|
||||
return slot;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param slot
|
||||
* the slot to set
|
||||
*/
|
||||
public void setSlot(int slot) {
|
||||
desireUpdate();
|
||||
this.slot = slot;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the page
|
||||
*/
|
||||
public int getPage() {
|
||||
return page;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param page
|
||||
* the page to set
|
||||
*/
|
||||
public void setPage(int page) {
|
||||
desireUpdate();
|
||||
this.page = page;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the type
|
||||
*/
|
||||
public ShortcutType getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param type
|
||||
* the type to set
|
||||
*/
|
||||
public void setType(ShortcutType type) {
|
||||
desireUpdate();
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the level
|
||||
*/
|
||||
public int getLevel() {
|
||||
return level;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param level
|
||||
* the level to set
|
||||
*/
|
||||
public void setLevel(int level) {
|
||||
desireUpdate();
|
||||
this.level = level;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the characterType
|
||||
*/
|
||||
public int getCharacterType() {
|
||||
return characterType;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param characterType
|
||||
* the characterType to set
|
||||
*/
|
||||
public void setCharacterType(int characterType) {
|
||||
desireUpdate();
|
||||
this.characterType = characterType;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the character id
|
||||
*/
|
||||
public CharacterID getCharacterID() {
|
||||
return characterID;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the character
|
||||
*/
|
||||
public L2Character getCharacter() {
|
||||
return characterID.getObject();
|
||||
}
|
||||
}
|
||||
@@ -1,98 +0,0 @@
|
||||
/*
|
||||
* This file is part of l2jserver2 <l2jserver2.com>.
|
||||
*
|
||||
* l2jserver2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* l2jserver2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with l2jserver2. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.l2jserver.model.id;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.assistedinject.Assisted;
|
||||
import com.l2jserver.model.game.Shortcut;
|
||||
import com.l2jserver.model.id.compound.AbstractCompoundID;
|
||||
import com.l2jserver.model.id.object.CharacterID;
|
||||
import com.l2jserver.model.id.object.ItemID;
|
||||
import com.l2jserver.model.id.provider.IDProvider;
|
||||
import com.l2jserver.model.id.template.SkillTemplateID;
|
||||
|
||||
/**
|
||||
* Each {@link Shortcut} is identified by an {@link ID}.
|
||||
* <p>
|
||||
* Please, do not directly instantiate this class, use an {@link IDProvider}
|
||||
* instead.
|
||||
*
|
||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||
*/
|
||||
public class ShortcutID extends AbstractCompoundID<CharacterID, ID<?>> {
|
||||
/**
|
||||
* Creates a new instance
|
||||
*
|
||||
* @param id1
|
||||
* the first id
|
||||
* @param id2
|
||||
* the second id
|
||||
*/
|
||||
@Inject
|
||||
public ShortcutID(@Assisted("id1") CharacterID id1,
|
||||
@Assisted("id2") ID<?> id2) {
|
||||
super(id1, id2);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the character ID
|
||||
*/
|
||||
public CharacterID getCharacterID() {
|
||||
return getID1();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the shortcut target ID
|
||||
*/
|
||||
public ID<?> getTargetID() {
|
||||
return getID2();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true if the {@link #getTargetID()} returns an
|
||||
* {@link SkillTemplateID}
|
||||
*/
|
||||
public boolean isSkill() {
|
||||
return getID2() instanceof SkillTemplateID;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return return the {@link #getTargetID()} casted to
|
||||
* {@link SkillTemplateID}
|
||||
* @throws ClassCastException
|
||||
* if {@link #isSkill()} returns null.
|
||||
*/
|
||||
public SkillTemplateID getSkillID() {
|
||||
return (SkillTemplateID) getTargetID();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true if the {@link #getTargetID()} returns an {@link ItemID}
|
||||
*/
|
||||
public boolean isItem() {
|
||||
return getID2() instanceof ItemID;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return return the {@link #getTargetID()} casted to {@link ItemID}
|
||||
* @throws ClassCastException
|
||||
* if {@link #isItem()} returns null.
|
||||
*/
|
||||
public ItemID getItemID() {
|
||||
return (ItemID) getTargetID();
|
||||
}
|
||||
}
|
||||
@@ -31,7 +31,6 @@ import com.l2jserver.service.game.world.event.WorldEventDispatcher;
|
||||
|
||||
/**
|
||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||
*
|
||||
*/
|
||||
public class ShortcutServiceImpl extends AbstractService implements
|
||||
ShortcutService {
|
||||
@@ -62,8 +61,8 @@ public class ShortcutServiceImpl extends AbstractService implements
|
||||
int slot) throws ShortcutSlotNotFreeServiceException {
|
||||
Preconditions.checkNotNull(character, "character");
|
||||
Preconditions.checkNotNull(item, "item");
|
||||
Preconditions.checkArgument(page >= 0 && page <= 10, "0 <= page <= 10");
|
||||
Preconditions.checkArgument(page >= 0 && slot <= 12, "0 <= slot <= 10");
|
||||
Preconditions.checkArgument(page >= 0 && page < 10, "0 <= page < 10");
|
||||
Preconditions.checkArgument(page >= 0 && slot < 12, "0 <= slot < 12");
|
||||
|
||||
if (character.getShortcuts().get(page, slot) != null)
|
||||
throw new ShortcutSlotNotFreeServiceException();
|
||||
@@ -90,15 +89,15 @@ public class ShortcutServiceImpl extends AbstractService implements
|
||||
public void remove(L2Character character, int page, int slot)
|
||||
throws ShortcutSlotEmptyServiceException {
|
||||
Preconditions.checkNotNull(character, "character");
|
||||
Preconditions.checkArgument(page >= 0 && page <= 10, "0 <= page <= 10");
|
||||
Preconditions.checkArgument(page >= 0 && slot <= 12, "0 <= slot <= 10");
|
||||
Preconditions.checkArgument(page >= 0 && page < 10, "0 <= page < 10");
|
||||
Preconditions.checkArgument(page >= 0 && slot < 12, "0 <= slot < 12");
|
||||
final CharacterShortcut shortcut = character.getShortcuts().get(page,
|
||||
slot);
|
||||
if (shortcut == null)
|
||||
throw new ShortcutSlotEmptyServiceException();
|
||||
|
||||
// synchronous delete here
|
||||
shortcutDao.delete(shortcut);
|
||||
// asynchronous delete here
|
||||
shortcutDao.deleteObjectsAsync(shortcut);
|
||||
character.getShortcuts().unregister(shortcut);
|
||||
|
||||
eventDispatcher.dispatch(new CharacterDeleteShortcutEvent(character,
|
||||
|
||||
Reference in New Issue
Block a user