Advertisement
Guest User

Untitled

a guest
Jul 21st, 2019
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.77 KB | None | 0 0
  1. package constitution.utilities;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.List;
  5. import java.util.UUID;
  6. import java.util.regex.Matcher;
  7. import java.util.regex.Pattern;
  8.  
  9. import javax.annotation.Nullable;
  10.  
  11. import com.mojang.authlib.GameProfile;
  12.  
  13. import constitution.ConstitutionMain;
  14. import constitution.exceptions.PermissionCommandException;
  15. import constitution.localization.LocalizationManager;
  16. import constitution.permissions.Group;
  17. import constitution.permissions.PermissionManager;
  18. import net.minecraft.entity.player.EntityPlayer;
  19. import net.minecraftforge.fml.common.FMLCommonHandler;
  20.  
  21. public class PlayerUtilities {
  22.  
  23.  
  24. protected static UUID getUUIDFromUsername(String username) {
  25. UUID uuid = PlayerUtilities.getUUIDFromName(username);
  26. if (uuid == null) {
  27. throw new PermissionCommandException("constitution.cmd.perm.err.player.notExist",
  28. LocalizationManager.get("constitution.format.user.short", username));
  29. }
  30. return uuid;
  31. }
  32. public static PermissionManager getManager() {
  33. return ConstitutionMain.getPermissionManager();
  34. }
  35.  
  36. public static Group getGroupFromName(String name) {
  37. Group group = getManager().groups.get(name);
  38. return group;
  39. }
  40.  
  41. @Nullable
  42. public static UUID getUUIDFromName(String name) {
  43. if ( FMLCommonHandler.instance().getMinecraftServerInstance().getPlayerList().getPlayerByUsername(name).getPersistentID() != null); {
  44. UUID uuid = FMLCommonHandler.instance().getMinecraftServerInstance().getPlayerList().getPlayerByUsername(name).getPersistentID();
  45. if (uuid != null) {
  46. return uuid;
  47. }
  48. }
  49. return null;
  50. }
  51.  
  52. public static Boolean isOP(UUID uuid) {
  53.  
  54. if (uuid != null) {
  55. if (!VanillaUtilities.getMinecraftServer().isSinglePlayer()) {
  56. EntityPlayer player = VanillaUtilities.getMinecraftServer().getPlayerList().getPlayerByUUID(uuid);
  57. if (player instanceof EntityPlayer) {
  58. if (player != null) {
  59. GameProfile profile = player.getGameProfile();
  60. Integer permissionLevelOP = VanillaUtilities.getMinecraftServer().getOpPermissionLevel();
  61. ConstitutionMain.logger.info("Multiplayer detected: Player: " + player.getDisplayNameString() + " isOP: " + VanillaUtilities.getMinecraftServer().getPlayerList().canSendCommands(profile));
  62. return VanillaUtilities.getMinecraftServer().getPlayerList().canSendCommands(profile);
  63. }
  64. }
  65. } else {
  66. ConstitutionMain.logger.info("Singleplayer Detected: Op Status True");
  67. return true;
  68. }
  69. }
  70. return false;
  71. }
  72.  
  73. public static List<String> regexMatcher(String text, String regex) {
  74. List<String> matchList= new ArrayList<String>();
  75.  
  76. final Pattern pattern = Pattern.compile(regex, Pattern.MULTILINE);
  77. final Matcher matcher = pattern.matcher(text);
  78.  
  79. while (matcher.find()) {
  80. matchList.add(matcher.group(2));
  81. return matchList;
  82. }
  83. return matchList;
  84. }
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement