L2AdminCommandAccessRight.java 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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 com.l2jserver.gameserver.model;
  16. import com.l2jserver.gameserver.datatables.AccessLevels;
  17. /**
  18. * @author FBIagent<br>
  19. */
  20. public class L2AdminCommandAccessRight
  21. {
  22. /** The admin command<br> */
  23. private String _adminCommand = null;
  24. /** The access levels which can use the admin command<br> */
  25. private L2AccessLevel[] _accessLevels = null;
  26. /**
  27. * Initialized members
  28. *
  29. * @param adminCommand as String
  30. * @param accessLevels as String
  31. */
  32. public L2AdminCommandAccessRight(String adminCommand, String accessLevels)
  33. {
  34. _adminCommand = adminCommand;
  35. String[] accessLevelsSplit = accessLevels.split(",");
  36. int numLevels = accessLevelsSplit.length;
  37. _accessLevels = new L2AccessLevel[numLevels];
  38. for (int i = 0; i < numLevels; ++i)
  39. {
  40. try
  41. {
  42. _accessLevels[i] = AccessLevels.getInstance().getAccessLevel(Integer.parseInt(accessLevelsSplit[i]));
  43. }
  44. catch (NumberFormatException nfe)
  45. {
  46. _accessLevels[i] = null;
  47. }
  48. }
  49. }
  50. /**
  51. * Returns the admin command the access right belongs to<br><br>
  52. *
  53. * @return String: the admin command the access right belongs to<br>
  54. */
  55. public String getAdminCommand()
  56. {
  57. return _adminCommand;
  58. }
  59. /**
  60. * Checks if the given characterAccessLevel is allowed to use the admin command which belongs to this access right<br><br>
  61. *
  62. * @param characterAccessLevel<br><br>
  63. *
  64. * @return boolean: true if characterAccessLevel is allowed to use the admin command which belongs to this access right, otherwise false<br>
  65. */
  66. public boolean hasAccess(L2AccessLevel characterAccessLevel)
  67. {
  68. for (int i = 0; i < _accessLevels.length; ++i)
  69. {
  70. L2AccessLevel accessLevel = _accessLevels[i];
  71. if (accessLevel != null
  72. && (accessLevel.getLevel() == characterAccessLevel.getLevel() || characterAccessLevel.hasChildAccess(accessLevel)))
  73. return true;
  74. }
  75. return false;
  76. }
  77. }