L2AdminCommandAccessRight.java 2.7 KB

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