10 changed files with 116 additions and 93 deletions
@ -0,0 +1,48 @@
|
||||
package ru.simsonic.rscPermissions.Bukkit; |
||||
|
||||
import java.net.InetSocketAddress; |
||||
import java.util.ArrayList; |
||||
import org.bukkit.OfflinePlayer; |
||||
import org.bukkit.entity.Player; |
||||
|
||||
public class BukkitUtilities |
||||
{ |
||||
public static String[] getOfflinePlayerIdentifiers(OfflinePlayer offline) |
||||
{ |
||||
final ArrayList<String> result = new ArrayList<>(); |
||||
// SERVERS BEFORE UUIDs
|
||||
try |
||||
{ |
||||
result.add(offline.getName()); |
||||
} catch(RuntimeException | NoSuchMethodError ex) { |
||||
} |
||||
// SERVERS WITH UUIDs
|
||||
try |
||||
{ |
||||
result.add(offline.getUniqueId().toString().toLowerCase()); |
||||
} catch(RuntimeException | NoSuchMethodError ex) { |
||||
} |
||||
return result.toArray(new String[result.size()]); |
||||
} |
||||
public static String[] getPlayerIdentifiers(Player player) |
||||
{ |
||||
// SERVERS BEFORE UUIDs
|
||||
final ArrayList<String> result = new ArrayList<>(); |
||||
try |
||||
{ |
||||
result.add(player.getName()); |
||||
} catch(RuntimeException | NoSuchMethodError ex) { |
||||
} |
||||
// SERVERS WITH UUIDs
|
||||
try |
||||
{ |
||||
result.add(player.getUniqueId().toString().toLowerCase()); |
||||
} catch(RuntimeException | NoSuchMethodError ex) { |
||||
} |
||||
// ONLINE IP CONNECTION
|
||||
final InetSocketAddress socketAddress = player.getAddress(); |
||||
if(socketAddress != null) |
||||
result.add(socketAddress.getAddress().getHostAddress()); |
||||
return result.toArray(new String[result.size()]); |
||||
} |
||||
} |
@ -0,0 +1,42 @@
|
||||
package ru.simsonic.rscPermissions.Engine; |
||||
|
||||
public class CommandUtilities |
||||
{ |
||||
public static boolean argumentToBoolean(String arg, Boolean prevForToggle) throws IllegalArgumentException |
||||
{ |
||||
if(arg == null || "".equals(arg)) |
||||
throw new IllegalArgumentException("Argument is null or empty."); |
||||
switch(arg.toLowerCase()) |
||||
{ |
||||
case "enable": |
||||
case "true": |
||||
case "yes": |
||||
case "on": |
||||
case "1": |
||||
return true; |
||||
case "disable": |
||||
case "false": |
||||
case "no": |
||||
case "off": |
||||
case "0": |
||||
return false; |
||||
case "toggle": |
||||
if(prevForToggle != null) |
||||
return !prevForToggle; |
||||
else |
||||
throw new IllegalArgumentException("Previous value is unknown."); |
||||
} |
||||
throw new IllegalArgumentException("Cannot understand boolean value."); |
||||
} |
||||
public static int argumentToInteger(String arg) throws IllegalArgumentException |
||||
{ |
||||
if(arg == null || "".equals(arg)) |
||||
throw new IllegalArgumentException("Argument is null or empty."); |
||||
try |
||||
{ |
||||
return Integer.parseInt(arg); |
||||
} catch(NumberFormatException ex) { |
||||
throw new IllegalArgumentException(ex.getMessage()); |
||||
} |
||||
} |
||||
} |
Loading…
Reference in new issue