L2AdminCommandAccessRight.java 2.7 KB

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