2
0
Эх сурвалжийг харах

BETA: Minor improvements and cleanup related to effects.
* Added !JavaDocs.

Zoey76 11 жил өмнө
parent
commit
282cd998f7

+ 1 - 1
L2J_Server_BETA/java/com/l2jserver/gameserver/engines/DocumentBase.java

@@ -390,7 +390,7 @@ public abstract class DocumentBase
 			}
 			n = n.getNextSibling();
 		}
-		return parameters;
+		return parameters == null ? StatsSet.EMPTY_STATSET : parameters;
 	}
 	
 	protected Condition parseCondition(Node n, Object template)

+ 14 - 6
L2J_Server_BETA/java/com/l2jserver/gameserver/model/StatsSet.java

@@ -19,9 +19,9 @@
 package com.l2jserver.gameserver.model;
 
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.List;
 import java.util.Map;
-import java.util.Map.Entry;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
@@ -38,6 +38,9 @@ import com.l2jserver.gameserver.model.interfaces.IParserAdvUtils;
 public class StatsSet implements IParserAdvUtils
 {
 	private static final Logger _log = Logger.getLogger(StatsSet.class.getName());
+	/** Static empty immutable map, used to avoid multiple null checks over the source. */
+	public static final StatsSet EMPTY_STATSET = new StatsSet(Collections.<String, Object> emptyMap());
+	
 	private final Map<String, Object> _set;
 	
 	public StatsSet()
@@ -65,11 +68,16 @@ public class StatsSet implements IParserAdvUtils
 	 */
 	public void add(StatsSet newSet)
 	{
-		Map<String, Object> newMap = newSet.getSet();
-		for (Entry<String, Object> entry : newMap.entrySet())
-		{
-			_set.put(entry.getKey(), entry.getValue());
-		}
+		_set.putAll(newSet.getSet());
+	}
+	
+	/**
+	 * Verifies if the stat set is empty.
+	 * @return {@code true} if the stat set is empty, {@code false} otherwise
+	 */
+	public boolean isEmpty()
+	{
+		return _set.isEmpty();
 	}
 	
 	/**

+ 21 - 10
L2J_Server_BETA/java/com/l2jserver/gameserver/model/effects/AbstractEffect.java

@@ -39,7 +39,8 @@ import com.l2jserver.gameserver.model.stats.Env;
 /**
  * Abstract effect implementation.<br>
  * Instant effects should not override {@link #onExit(BuffInfo)}.<br>
- * Instant effects should not override {@link #canStart(BuffInfo)}, all checks should be done {@link #onStart(BuffInfo)}. Do not call super class methods {@link #onStart(BuffInfo)} nor {@link #onExit(BuffInfo)}.<br>
+ * Instant effects should not override {@link #canStart(BuffInfo)}, all checks should be done {@link #onStart(BuffInfo)}.<br>
+ * Do not call super class methods {@link #onStart(BuffInfo)} nor {@link #onExit(BuffInfo)}.
  * @since <a href="http://trac.l2jserver.com/changeset/6249">Changeset 6249</a> the "effect steal constructor" is deprecated.
  * @author Zoey76
  */
@@ -48,9 +49,12 @@ public abstract class AbstractEffect implements IChanceSkillTrigger
 	protected static final Logger _log = Logger.getLogger(AbstractEffect.class.getName());
 	
 	// Conditions
+	/** Attach condition. */
 	private final Condition _attachCond;
+	// Apply condition
 	// private final Condition _applyCond; // TODO: Use or cleanup.
 	private List<FuncTemplate> _funcTemplates;
+	/** Effect class name. */
 	private final String _name;
 	private final double _val;
 	/** Ticks. */
@@ -61,10 +65,10 @@ public abstract class AbstractEffect implements IChanceSkillTrigger
 	
 	/**
 	 * Abstract effect constructor.
-	 * @param attachCond
-	 * @param applyCond
-	 * @param set
-	 * @param params
+	 * @param attachCond the attach condition
+	 * @param applyCond the apply condition
+	 * @param set the attributes
+	 * @param params the parameters
 	 */
 	protected AbstractEffect(Condition attachCond, Condition applyCond, StatsSet set, StatsSet params)
 	{
@@ -78,6 +82,14 @@ public abstract class AbstractEffect implements IChanceSkillTrigger
 		_chanceCondition = ChanceCondition.parse(set.getString("chanceType", null), set.getInt("activationChance", -1), set.getInt("activationMinDamage", -1), set.getString("activationElements", null), set.getString("activationSkills", null), set.getBoolean("pvpChanceOnly", false));
 	}
 	
+	/**
+	 * Creates an effect given the parameters.
+	 * @param attachCond the attach condition
+	 * @param applyCond the apply condition
+	 * @param set the attributes
+	 * @param params the parameters
+	 * @return the new effect
+	 */
 	public static final AbstractEffect createEffect(Condition attachCond, Condition applyCond, StatsSet set, StatsSet params)
 	{
 		final String name = set.getString("name");
@@ -93,10 +105,9 @@ public abstract class AbstractEffect implements IChanceSkillTrigger
 		{
 			constructor = handler.getConstructor(Condition.class, Condition.class, StatsSet.class, StatsSet.class);
 		}
-		catch (NoSuchMethodException | SecurityException e1)
+		catch (NoSuchMethodException | SecurityException e)
 		{
-			_log.warning(AbstractEffect.class.getSimpleName() + ": Requested unexistent constructor for effect handler: " + name);
-			e1.printStackTrace();
+			_log.warning(AbstractEffect.class.getSimpleName() + ": Requested unexistent constructor for effect handler: " + name + ": " + e.getMessage());
 			return null;
 		}
 		
@@ -106,7 +117,7 @@ public abstract class AbstractEffect implements IChanceSkillTrigger
 		}
 		catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e)
 		{
-			e.printStackTrace();
+			_log.warning(AbstractEffect.class.getSimpleName() + ": Unable to initialize effect handler: " + name + ": " + e.getMessage());
 		}
 		return null;
 	}
@@ -122,7 +133,7 @@ public abstract class AbstractEffect implements IChanceSkillTrigger
 	}
 	
 	/**
-	 * Attachs a function template.
+	 * Attaches a function template.
 	 * @param f the function
 	 */
 	public void attach(FuncTemplate f)