Ver código fonte

BETA: Cleanup `ArmorType`, `EtcItemType` and `WeaponType` enums.
Reviewed by: Nos, UnAfraid
Thanks to: Nos

Adry_85 11 anos atrás
pai
commit
462f2eca8f

+ 0 - 17
L2J_Server_BETA/java/com/l2jserver/gameserver/datatables/ItemTable.java

@@ -48,8 +48,6 @@ import com.l2jserver.gameserver.model.items.L2EtcItem;
 import com.l2jserver.gameserver.model.items.L2Item;
 import com.l2jserver.gameserver.model.items.L2Weapon;
 import com.l2jserver.gameserver.model.items.instance.L2ItemInstance;
-import com.l2jserver.gameserver.model.items.type.ArmorType;
-import com.l2jserver.gameserver.model.items.type.WeaponType;
 import com.l2jserver.gameserver.scripting.scriptengine.events.ItemCreateEvent;
 import com.l2jserver.gameserver.scripting.scriptengine.listeners.player.NewItemListener;
 import com.l2jserver.gameserver.util.GMAudit;
@@ -65,8 +63,6 @@ public class ItemTable
 	private static FastList<NewItemListener> newItemListeners = new FastList<NewItemListener>().shared();
 	
 	public static final Map<String, Integer> _slots = new FastMap<>();
-	public static final Map<String, WeaponType> _weaponTypes = new FastMap<>();
-	public static final Map<String, ArmorType> _armorTypes = new FastMap<>();
 	
 	private L2Item[] _allTemplates;
 	private final Map<Integer, L2EtcItem> _etcItems;
@@ -75,18 +71,6 @@ public class ItemTable
 	
 	static
 	{
-		// weapon types
-		for (WeaponType type : WeaponType.values())
-		{
-			_weaponTypes.put(type.getName(), type);
-		}
-		
-		// armor types
-		for (ArmorType type : ArmorType.values())
-		{
-			_armorTypes.put(type.getName(), type);
-		}
-		
 		_slots.put("shirt", L2Item.SLOT_UNDERWEAR);
 		_slots.put("lbracelet", L2Item.SLOT_L_BRACELET);
 		_slots.put("rbracelet", L2Item.SLOT_R_BRACELET);
@@ -123,7 +107,6 @@ public class ItemTable
 		_slots.put("alldress", L2Item.SLOT_ALLDRESS);
 		_slots.put("deco1", L2Item.SLOT_DECO);
 		_slots.put("waist", L2Item.SLOT_BELT);
-		
 	}
 	
 	/**

+ 12 - 6
L2J_Server_BETA/java/com/l2jserver/gameserver/engines/DocumentBase.java

@@ -1091,7 +1091,7 @@ public abstract class DocumentBase
 						String item = st.nextToken().trim();
 						for (WeaponType wt : WeaponType.values())
 						{
-							if (wt.getName().equals(item))
+							if (wt.name().equals(item))
 							{
 								mask |= wt.mask();
 								break;
@@ -1099,7 +1099,7 @@ public abstract class DocumentBase
 						}
 						for (ArmorType at : ArmorType.values())
 						{
-							if (at.getName().equals(item))
+							if (at.name().equals(item))
 							{
 								mask |= at.mask();
 								break;
@@ -1178,14 +1178,20 @@ public abstract class DocumentBase
 					{
 						int old = mask;
 						String item = st.nextToken().trim();
-						if (ItemTable._weaponTypes.containsKey(item))
+						for (WeaponType wt : WeaponType.values())
 						{
-							mask |= ItemTable._weaponTypes.get(item).mask();
+							if (wt.name().equals(item))
+							{
+								mask |= wt.mask();
+							}
 						}
 						
-						if (ItemTable._armorTypes.containsKey(item))
+						for (ArmorType at : ArmorType.values())
 						{
-							mask |= ItemTable._armorTypes.get(item).mask();
+							if (at.name().equals(item))
+							{
+								mask |= at.mask();
+							}
 						}
 						
 						if (old == mask)

+ 1 - 1
L2J_Server_BETA/java/com/l2jserver/gameserver/model/actor/templates/L2CharTemplate.java

@@ -116,7 +116,7 @@ public class L2CharTemplate
 		_baseShldDef = set.getInt("baseShldDef", 0);
 		_baseAttackRange = set.getInt("baseAtkRange", 40);
 		_randomDamage = set.getInt("baseRndDam", 0);
-		_baseAttackType = WeaponType.findByName(set.getString("baseAtkType", "Fist"));
+		_baseAttackType = set.getEnum("baseAtkType", WeaponType.class, WeaponType.FIST);
 		_baseShldRate = set.getInt("baseShldRate", 0);
 		_baseCritRate = set.getInt("baseCritRate", 4);
 		_baseMCritRate = set.getInt("baseMCritRate", 0);

+ 1 - 1
L2J_Server_BETA/java/com/l2jserver/gameserver/model/actor/transform/TransformTemplate.java

@@ -59,7 +59,7 @@ public final class TransformTemplate
 	{
 		_collisionRadius = set.getDouble("radius", 0);
 		_collisionHeight = set.getDouble("height", 0);
-		_baseAttackType = WeaponType.findByName(set.getString("attackType", "FIST"));
+		_baseAttackType = set.getEnum("attackType", WeaponType.class, WeaponType.FIST);
 		_baseAttackRange = set.getInt("range", 40);
 		_baseRandomDamage = set.getDouble("randomDamage", 0);
 		

+ 1 - 1
L2J_Server_BETA/java/com/l2jserver/gameserver/model/items/L2Armor.java

@@ -42,7 +42,7 @@ public final class L2Armor extends L2Item
 	public L2Armor(StatsSet set)
 	{
 		super(set);
-		_type = ArmorType.valueOf(set.getString("armor_type", "none").toUpperCase());
+		_type = set.getEnum("armor_type", ArmorType.class, ArmorType.NONE);
 		
 		int _bodyPart = getBodyPart();
 		if ((_bodyPart == L2Item.SLOT_NECK) || ((_bodyPart & L2Item.SLOT_L_EAR) != 0) || ((_bodyPart & L2Item.SLOT_L_FINGER) != 0) || ((_bodyPart & L2Item.SLOT_R_BRACELET) != 0) || ((_bodyPart & L2Item.SLOT_L_BRACELET) != 0))

+ 1 - 1
L2J_Server_BETA/java/com/l2jserver/gameserver/model/items/L2EtcItem.java

@@ -44,7 +44,7 @@ public final class L2EtcItem extends L2Item
 	public L2EtcItem(StatsSet set)
 	{
 		super(set);
-		_type = EtcItemType.valueOf(set.getString("etcitem_type", "none").toUpperCase());
+		_type = set.getEnum("etcitem_type", EtcItemType.class, EtcItemType.NONE);
 		
 		// l2j custom - L2EtcItemType.SHOT
 		switch (getDefaultAction())

+ 8 - 21
L2J_Server_BETA/java/com/l2jserver/gameserver/model/items/type/ArmorType.java

@@ -19,31 +19,27 @@
 package com.l2jserver.gameserver.model.items.type;
 
 /**
- * Description of Armor Type
+ * Armor Type enumerated.
  */
-
 public enum ArmorType implements ItemType
 {
-	NONE("None"),
-	LIGHT("Light"),
-	HEAVY("Heavy"),
-	MAGIC("Magic"),
-	SIGIL("Sigil"),
+	NONE,
+	LIGHT,
+	HEAVY,
+	MAGIC,
+	SIGIL,
 	
 	// L2J CUSTOM
-	SHIELD("Shield");
+	SHIELD;
 	
 	final int _mask;
-	final String _name;
 	
 	/**
 	 * Constructor of the ArmorType.
-	 * @param name : String designating the name of the ArmorType
 	 */
-	private ArmorType(String name)
+	private ArmorType()
 	{
 		_mask = 1 << (ordinal() + WeaponType.values().length);
-		_name = name;
 	}
 	
 	/**
@@ -54,13 +50,4 @@ public enum ArmorType implements ItemType
 	{
 		return _mask;
 	}
-	
-	/**
-	 * @return the name of the ArmorType
-	 */
-	@Override
-	public String getName()
-	{
-		return _name;
-	}
 }

+ 34 - 66
L2J_Server_BETA/java/com/l2jserver/gameserver/model/items/type/EtcItemType.java

@@ -19,59 +19,45 @@
 package com.l2jserver.gameserver.model.items.type;
 
 /**
- * Description of EtcItem Type
+ * EtcItem Type enumerated.
  */
 public enum EtcItemType implements ItemType
 {
-	NONE(1, "none"),
-	ARROW(2, "arrow"),
-	POTION(3, "potion"),
-	SCRL_ENCHANT_WP(4, "scrl_enchant_wp"),
-	SCRL_ENCHANT_AM(5, "scrl_enchant_am"),
-	SCROLL(6, "scroll"),
-	RECIPE(7, "recipe"),
-	MATERIAL(8, "material"),
-	PET_COLLAR(9, "pet_collar"),
-	CASTLE_GUARD(10, "castle_guard"),
-	LOTTO(11, "lotto"),
-	RACE_TICKET(12, "race_ticket"),
-	DYE(13, "dye"),
-	SEED(14, "seed"),
-	CROP(15, "crop"),
-	MATURECROP(16, "maturecrop"),
-	HARVEST(17, "harvest"),
-	SEED2(18, "seed2"),
-	TICKET_OF_LORD(19, "ticket_of_lord"),
-	LURE(20, "lure"),
-	BLESS_SCRL_ENCHANT_WP(21, "bless_scrl_enchant_wp"),
-	BLESS_SCRL_ENCHANT_AM(22, "bless_scrl_enchant_am"),
-	COUPON(23, "coupon"),
-	ELIXIR(24, "elixir"),
-	SCRL_ENCHANT_ATTR(25, "scrl_enchant_attr"),
-	BOLT(26, "bolt"),
-	SCRL_INC_ENCHANT_PROP_WP(27, "scrl_inc_enchant_prop_wp"),
-	SCRL_INC_ENCHANT_PROP_AM(28, "scrl_inc_enchant_prop_am"),
-	ANCIENT_CRYSTAL_ENCHANT_WP(29, "ancient_crystal_enchant_wp"),
-	ANCIENT_CRYSTAL_ENCHANT_AM(30, "ancient_crystal_enchant_am"),
-	RUNE_SELECT(31, "rune_select"),
-	RUNE(32, "rune"),
+	NONE,
+	ARROW,
+	POTION,
+	SCRL_ENCHANT_WP,
+	SCRL_ENCHANT_AM,
+	SCROLL,
+	RECIPE,
+	MATERIAL,
+	PET_COLLAR,
+	CASTLE_GUARD,
+	LOTTO,
+	RACE_TICKET,
+	DYE,
+	SEED,
+	CROP,
+	MATURECROP,
+	HARVEST,
+	SEED2,
+	TICKET_OF_LORD,
+	LURE,
+	BLESS_SCRL_ENCHANT_WP,
+	BLESS_SCRL_ENCHANT_AM,
+	COUPON,
+	ELIXIR,
+	SCRL_ENCHANT_ATTR,
+	BOLT,
+	SCRL_INC_ENCHANT_PROP_WP,
+	SCRL_INC_ENCHANT_PROP_AM,
+	ANCIENT_CRYSTAL_ENCHANT_WP,
+	ANCIENT_CRYSTAL_ENCHANT_AM,
+	RUNE_SELECT,
+	RUNE,
 	
 	// L2J CUSTOM, BACKWARD COMPATIBILITY
-	SHOT(33, "Shot");
-	
-	private final int _id;
-	private final String _name;
-	
-	/**
-	 * Constructor of the EtcItemType.
-	 * @param id : int designating the ID of the EtcItemType
-	 * @param name : String designating the name of the EtcItemType
-	 */
-	private EtcItemType(int id, String name)
-	{
-		_id = id;
-		_name = name;
-	}
+	SHOT;
 	
 	/**
 	 * @return the ID of the item after applying the mask.
@@ -81,22 +67,4 @@ public enum EtcItemType implements ItemType
 	{
 		return 0;
 	}
-	
-	/**
-	 * Gets the EtcItem type ID.
-	 * @return the EtcItem type ID
-	 */
-	public int getId()
-	{
-		return _id;
-	}
-	
-	/**
-	 * @return the name of the EtcItemType
-	 */
-	@Override
-	public String getName()
-	{
-		return _name;
-	}
 }

+ 0 - 2
L2J_Server_BETA/java/com/l2jserver/gameserver/model/items/type/ItemType.java

@@ -25,6 +25,4 @@ package com.l2jserver.gameserver.model.items.type;
 public interface ItemType
 {
 	public int mask();
-	
-	public String getName();
 }

+ 22 - 59
L2J_Server_BETA/java/com/l2jserver/gameserver/model/items/type/WeaponType.java

@@ -18,49 +18,42 @@
  */
 package com.l2jserver.gameserver.model.items.type;
 
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
 import com.l2jserver.gameserver.model.stats.TraitType;
 
 /**
- * @author mkizub <BR>
- *         Description of Weapon Type
+ * Weapon Type enumerated.
+ * @author mkizub
  */
 public enum WeaponType implements ItemType
 {
-	SWORD("Sword", TraitType.SWORD),
-	BLUNT("Blunt", TraitType.BLUNT),
-	DAGGER("Dagger", TraitType.DAGGER),
-	BOW("Bow", TraitType.BOW),
-	POLE("Pole", TraitType.POLE),
-	NONE("None", TraitType.NONE),
-	DUAL("Dual Sword", TraitType.DUAL),
-	ETC("Etc", TraitType.ETC),
-	FIST("Fist", TraitType.FIST),
-	DUALFIST("Dual Fist", TraitType.DUALFIST),
-	FISHINGROD("Rod", TraitType.NONE),
-	RAPIER("Rapier", TraitType.RAPIER),
-	ANCIENTSWORD("Ancient", TraitType.ANCIENTSWORD),
-	CROSSBOW("Crossbow", TraitType.CROSSBOW),
-	FLAG("Flag", TraitType.NONE),
-	OWNTHING("Ownthing", TraitType.NONE),
-	DUALDAGGER("Dual Dagger", TraitType.DUALDAGGER);
+	SWORD(TraitType.SWORD),
+	BLUNT(TraitType.BLUNT),
+	DAGGER(TraitType.DAGGER),
+	BOW(TraitType.BOW),
+	POLE(TraitType.POLE),
+	NONE(TraitType.NONE),
+	DUAL(TraitType.DUAL),
+	ETC(TraitType.ETC),
+	FIST(TraitType.FIST),
+	DUALFIST(TraitType.DUALFIST),
+	FISHINGROD(TraitType.NONE),
+	RAPIER(TraitType.RAPIER),
+	ANCIENTSWORD(TraitType.ANCIENTSWORD),
+	CROSSBOW(TraitType.CROSSBOW),
+	FLAG(TraitType.NONE),
+	OWNTHING(TraitType.NONE),
+	DUALDAGGER(TraitType.DUALDAGGER);
 	
-	private static final Logger _log = Logger.getLogger(WeaponType.class.getName());
 	private final int _mask;
-	private final String _name;
 	private final TraitType _traitType;
 	
 	/**
-	 * Constructor of the WeaponType.
-	 * @param name : String designating the name of the WeaponType
+	 * Constructor of the L2WeaponType.
 	 * @param traitType
 	 */
-	private WeaponType(String name, TraitType traitType)
+	private WeaponType(TraitType traitType)
 	{
 		_mask = 1 << ordinal();
-		_name = name;
 		_traitType = traitType;
 	}
 	
@@ -73,15 +66,6 @@ public enum WeaponType implements ItemType
 		return _mask;
 	}
 	
-	/**
-	 * @return the name of the WeaponType
-	 */
-	@Override
-	public String getName()
-	{
-		return _name;
-	}
-	
 	/**
 	 * @return L2TraitType the type of the WeaponType
 	 */
@@ -89,25 +73,4 @@ public enum WeaponType implements ItemType
 	{
 		return _traitType;
 	}
-	
-	public static WeaponType findByName(String name)
-	{
-		if (name.equalsIgnoreCase("DUAL"))
-		{
-			name = "Dual Sword";
-		}
-		else if (name.equalsIgnoreCase("DUALFIST"))
-		{
-			name = "Dual Fist";
-		}
-		for (WeaponType type : values())
-		{
-			if (type.getName().equalsIgnoreCase(name))
-			{
-				return type;
-			}
-		}
-		_log.log(Level.WARNING, WeaponType.class.getSimpleName() + ": Requested unexistent enum member: " + name, new IllegalStateException());
-		return FIST;
-	}
-}
+}

+ 22 - 17
L2J_Server_BETA/java/com/l2jserver/log/filter/ItemFilter.java

@@ -18,10 +18,14 @@
  */
 package com.l2jserver.log.filter;
 
+import java.util.HashSet;
+import java.util.Set;
 import java.util.logging.Filter;
 import java.util.logging.LogRecord;
 
 import com.l2jserver.gameserver.model.items.instance.L2ItemInstance;
+import com.l2jserver.gameserver.model.items.type.EtcItemType;
+import com.l2jserver.gameserver.model.items.type.ItemType;
 
 /**
  * @author Advi
@@ -32,8 +36,14 @@ public class ItemFilter implements Filter
 	// private String _excludeItemType;
 	
 	// This is an example how to exclude consuming of shots and arrows from logging
-	private final String _excludeProcess = "Consume";
-	private final String _excludeItemType = "Arrow, Shot, Herb";
+	private static final String EXCLUDE_PROCESS = "Consume";
+	private static final Set<ItemType> EXCLUDED_ITEM_TYPES = new HashSet<>();
+	
+	static
+	{
+		EXCLUDED_ITEM_TYPES.add(EtcItemType.ARROW);
+		EXCLUDED_ITEM_TYPES.add(EtcItemType.SHOT);
+	}
 	
 	@Override
 	public boolean isLoggable(LogRecord record)
@@ -42,24 +52,19 @@ public class ItemFilter implements Filter
 		{
 			return false;
 		}
-		if (_excludeProcess != null)
+		
+		String[] messageList = record.getMessage().split(":");
+		if ((messageList.length < 2) || !EXCLUDE_PROCESS.contains(messageList[1]))
 		{
-			// if (record.getMessage() == null) return true;
-			String[] messageList = record.getMessage().split(":");
-			if ((messageList.length < 2) || !_excludeProcess.contains(messageList[1]))
-			{
-				return true;
-			}
+			return true;
 		}
-		if (_excludeItemType != null)
+		
+		L2ItemInstance item = ((L2ItemInstance) record.getParameters()[0]);
+		if (!EXCLUDED_ITEM_TYPES.contains(item.getItemType()))
 		{
-			// if (record.getParameters() == null || record.getParameters().length == 0 || !(record.getParameters()[0] instanceof L2ItemInstance)) return true;
-			L2ItemInstance item = ((L2ItemInstance) record.getParameters()[0]);
-			if (!_excludeItemType.contains(item.getItemType().getName()))
-			{
-				return true;
-			}
+			return true;
 		}
-		return ((_excludeProcess == null) && (_excludeItemType == null));
+		
+		return false;
 	}
 }