AccessLevel.java 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. /*
  2. * This program is free software: you can redistribute it and/or modify it under
  3. * the terms of the GNU General Public License as published by the Free Software
  4. * Foundation, either version 3 of the License, or (at your option) any later
  5. * version.
  6. *
  7. * This program is distributed in the hope that it will be useful, but WITHOUT
  8. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  9. * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  10. * details.
  11. *
  12. * You should have received a copy of the GNU General Public License along with
  13. * this program. If not, see <http://www.gnu.org/licenses/>.
  14. */
  15. package net.sf.l2j.gameserver.datatables;
  16. import java.util.logging.Logger;
  17. /**
  18. * @author FBIagent<br>
  19. */
  20. public class AccessLevel
  21. {
  22. /** The logger<br> */
  23. private static Logger _log = Logger.getLogger( AccessLevel.class.getName() );
  24. /** The access level<br> */
  25. private int _accessLevel = 0;
  26. /** The access level name<br> */
  27. private String _name = null;
  28. /** Child access levels */
  29. AccessLevel[] _childsAccessLevel = null;
  30. /** Child access levels */
  31. private String _childs = null;
  32. /** The name color for the access level<br> */
  33. private int _nameColor = 0;
  34. /** The title color for the access level<br> */
  35. private int _titleColor = 0;
  36. /** Flag to determine if the access level has gm access<br> */
  37. private boolean _isGm = false;
  38. /** Flag for peace zone attack */
  39. private boolean _allowPeaceAttack = false;
  40. /** Flag for fixed res */
  41. private boolean _allowFixedRes = false;
  42. /** Flag for transactions */
  43. private boolean _allowTransaction = false;
  44. /** Flag for AltG commands */
  45. private boolean _allowAltG = false;
  46. /** Flag to give damage */
  47. private boolean _giveDamage = false;
  48. /** Flag to take aggro */
  49. private boolean _takeAggro = false;
  50. /** Flag to gain exp in party */
  51. private boolean _gainExp = false;
  52. /**
  53. * Initializes members<br><br>
  54. *
  55. * @param accessLevel as int<br>
  56. * @param name as String<br>
  57. * @param nameColor as int<br>
  58. * @param titleColor as int<br>
  59. * @param childs as String<br>
  60. * @param isGm as boolean<br>
  61. * @param allowPeaceAttack as boolean<br>
  62. * @param allowFixedRes as boolean<br>
  63. * @param allowTransaction as boolean<br>
  64. * @param allowAltG as boolean<br>
  65. * @param giveDamage as boolean<br>
  66. * @param takeAggro as boolean<br>
  67. * @param gainExp as boolean<br>
  68. */
  69. public AccessLevel(int accessLevel, String name, int nameColor, int titleColor, String childs, boolean isGm,
  70. boolean allowPeaceAttack, boolean allowFixedRes, boolean allowTransaction, boolean allowAltG, boolean giveDamage, boolean takeAggro, boolean gainExp)
  71. {
  72. _accessLevel = accessLevel;
  73. _name = name;
  74. _nameColor = nameColor;
  75. _titleColor = titleColor;
  76. _childs = childs;
  77. _isGm = isGm;
  78. _allowPeaceAttack = allowPeaceAttack;
  79. _allowFixedRes = allowFixedRes;
  80. _allowTransaction = allowTransaction;
  81. _allowAltG = allowAltG;
  82. _giveDamage = giveDamage;
  83. _takeAggro = takeAggro;
  84. _gainExp = gainExp;
  85. }
  86. /**
  87. * Returns the access level<br><br>
  88. *
  89. * @return int: access level<br>
  90. */
  91. public int getLevel()
  92. {
  93. return _accessLevel;
  94. }
  95. /**
  96. * Returns the access level name<br><br>
  97. *
  98. * @return String: access level name<br>
  99. */
  100. public String getName()
  101. {
  102. return _name;
  103. }
  104. /**
  105. * Returns the name color of the access level<br><br>
  106. *
  107. * @return int: the name color for the access level<br>
  108. */
  109. public int getNameColor()
  110. {
  111. return _nameColor;
  112. }
  113. /**
  114. * Returns the title color color of the access level<br><br>
  115. *
  116. * @return int: the title color for the access level<br>
  117. */
  118. public int getTitleColor()
  119. {
  120. return _titleColor;
  121. }
  122. /**
  123. * Retuns if the access level has gm access or not<br><br>
  124. *
  125. * @return boolean: true if access level have gm access, otherwise false<br>
  126. */
  127. public boolean isGm()
  128. {
  129. return _isGm;
  130. }
  131. /**
  132. * Returns if the access level is allowed to attack in peace zone or not<br><br>
  133. *
  134. * @return boolean: true if the access level is allowed to attack in peace zone, otherwise false<br>
  135. */
  136. public boolean allowPeaceAttack()
  137. {
  138. return _allowPeaceAttack;
  139. }
  140. /**
  141. * Retruns if the access level is allowed to use fixed res or not<br><br>
  142. *
  143. * @return: true if the access level is allowed to use fixed res, otherwise false<br>
  144. */
  145. public boolean allowFixedRes()
  146. {
  147. return _allowFixedRes;
  148. }
  149. /**
  150. * Returns if the access level is allowed to perform transactions or not<br><br>
  151. *
  152. * @return boolean: true if access level is allowed to perform transactions, otherwise false<br>
  153. */
  154. public boolean allowTransaction()
  155. {
  156. return _allowTransaction;
  157. }
  158. /**
  159. * Returns if the access level is allowed to use AltG commands or not<br><br>
  160. *
  161. * @return boolean: true if access level is allowed to use AltG commands, otherwise false<br>
  162. */
  163. public boolean allowAltG()
  164. {
  165. return _allowAltG;
  166. }
  167. /**
  168. * Returns if the access level can give damage or not<br><br>
  169. *
  170. * @return boolean: true if the access level can give damage, otherwise false<br>
  171. */
  172. public boolean canGiveDamage()
  173. {
  174. return _giveDamage;
  175. }
  176. /**
  177. * Returns if the access level can take aggro or not<br><br>
  178. *
  179. * @return boolean: true if the access level can take aggro, otherwise false<br>
  180. */
  181. public boolean canTakeAggro()
  182. {
  183. return _takeAggro;
  184. }
  185. /**
  186. * Returns if the access level can gain exp or not<br><br>
  187. *
  188. * @return boolean: true if the access level can gain exp, otherwise false<br>
  189. */
  190. public boolean canGainExp()
  191. {
  192. return _gainExp;
  193. }
  194. /**
  195. * Returns if the access level contains allowedAccess as child<br><br>
  196. *
  197. * @param accessLevel as AccessLevel<br><br>
  198. *
  199. * @return boolean: true if a child access level is equals to allowedAccess, otherwise false<br>
  200. */
  201. public boolean hasChildAccess(AccessLevel accessLevel)
  202. {
  203. if (_childsAccessLevel == null)
  204. {
  205. if (_childs == null)
  206. return false;
  207. setChildAccess(_childs);
  208. for (AccessLevel childAccess : _childsAccessLevel)
  209. {
  210. if (childAccess != null && (childAccess.getLevel() == accessLevel.getLevel() || childAccess.hasChildAccess(accessLevel)))
  211. return true;
  212. }
  213. }
  214. else
  215. {
  216. for (AccessLevel childAccess : _childsAccessLevel)
  217. {
  218. if (childAccess != null && (childAccess.getLevel() == accessLevel.getLevel() || childAccess.hasChildAccess(accessLevel)))
  219. return true;
  220. }
  221. }
  222. return false;
  223. }
  224. private void setChildAccess(String childs)
  225. {
  226. String[] childsSplit = childs.split(";");
  227. _childsAccessLevel = new AccessLevel[childsSplit.length];
  228. for (int i = 0;i < childsSplit.length;++ i)
  229. {
  230. AccessLevel accessLevelInst = AccessLevels.getInstance().getAccessLevel(Integer.valueOf(childsSplit[i]));
  231. if (accessLevelInst == null)
  232. {
  233. _log.warning("AccessLevel: Undefined child access level " + childsSplit[i]);
  234. continue;
  235. }
  236. if (accessLevelInst.hasChildAccess(this))
  237. {
  238. _log.warning("AccessLevel: Child access tree overlapping for " + _name + " and " + accessLevelInst.getName());
  239. continue;
  240. }
  241. _childsAccessLevel[i] = accessLevelInst;
  242. }
  243. }
  244. }