@ -13,192 +13,194 @@ import java.util.function.BiConsumer;
@SuppressWarnings ( "NullableProblems" )
@SuppressWarnings ( "NullableProblems" )
public class Commands implements TabExecutor {
public class Commands implements TabExecutor {
final private Map < List < String > , Pair < BiConsumer < CommandSender , String > , String > > commands = new HashMap < > ( ) ;
final private Map < List < String > , Pair < BiConsumer < CommandSender , String > , String > > commands = new HashMap < > ( ) ;
{
addCommand ( "get" , ( sender , arg ) - > commandGetHealth ( sender ) , "Displays current health value." ) ;
{
addCommand ( "reset" , ( sender , arg ) - > commandReset ( sender ) , "Gives every player full health and resets 'isFailed' to false. GameMode becomes Survival." ) ;
addCommand ( "get" , ( sender , arg ) - > commandGetHealth ( sender ) , "Displays current health value." ) ;
addCommand ( "add" , ( sender , name ) - > commandActivePlayer ( sender , name , true ) , "Adds a player to the Plugin." ) ;
addCommand ( "reset" , ( sender , arg ) - > commandReset ( sender ) , "Gives every player full health and resets 'isFailed' to false. GameMode becomes Survival." ) ;
addCommand ( "remove" , ( sender , name ) - > commandActivePlayer ( sender , name , false ) , "Removes a player from the Plugin." ) ;
addCommand ( "add" , ( sender , name ) - > commandActivePlayer ( sender , name , true ) , "Adds a player to the Plugin." ) ;
addCommand ( "totem one" , ( sender , arg ) - > commandSetTotemMode ( sender , TotemManager . Mode . One ) , "Totem of Undying: At least one player needs to hold it." ) ;
addCommand ( "remove" , ( sender , name ) - > commandActivePlayer ( sender , name , false ) , "Removes a player from the Plugin." ) ;
addCommand ( "totem all" , ( sender , arg ) - > commandSetTotemMode ( sender , TotemManager . Mode . All ) , "Totem of Undying: All players need to hold it." ) ;
addCommand ( "totem one" , ( sender , arg ) - > commandSetTotemMode ( sender , TotemManager . Mode . One ) , "Totem of Undying: At least one player needs to hold it." ) ;
addCommand ( "totem fraction" , ( sender , arg ) - > commandSetTotemMode ( sender , TotemManager . Mode . Fraction ) , "Totem of Undying: At least fraction * player-count need to hold it." ) ;
addCommand ( "totem all" , ( sender , arg ) - > commandSetTotemMode ( sender , TotemManager . Mode . All ) , "Totem of Undying: All players need to hold it." ) ;
addCommand ( "totem disabled" , ( sender , arg ) - > commandSetTotemMode ( sender , TotemManager . Mode . Disabled ) , "Totem of Undying: Disabled" ) ;
addCommand ( "totem fraction" , ( sender , arg ) - > commandSetTotemMode ( sender , TotemManager . Mode . Fraction ) , "Totem of Undying: At least fraction * player-count need to hold it." ) ;
addCommand ( "totem setfraction" , this : : commandSetTotemFraction , "Totem of Undying: Set amount for mode: fraction." ) ;
addCommand ( "totem disabled" , ( sender , arg ) - > commandSetTotemMode ( sender , TotemManager . Mode . Disabled ) , "Totem of Undying: Disabled" ) ;
addCommand ( "totem getfraction" , ( sender , arg ) - > commandGetTotemFraction ( sender ) , "Totem of Undying: Get amount for mode: fraction." ) ;
addCommand ( "totem setfraction" , this : : commandSetTotemFraction , "Totem of Undying: Set amount for mode: fraction." ) ;
addCommand ( "totem get" , ( sender , arg ) - > commandGetTotemMode ( sender ) , "Totem of Undying: Get current mode." ) ;
addCommand ( "totem getfraction" , ( sender , arg ) - > commandGetTotemFraction ( sender ) , "Totem of Undying: Get amount for mode: fraction." ) ;
addCommand ( "log on" , ( sender , arg ) - > commandSetLogging ( sender , true ) , "Enables Logging." ) ;
addCommand ( "totem get" , ( sender , arg ) - > commandGetTotemMode ( sender ) , "Totem of Undying: Get current mode." ) ;
addCommand ( "log off" , ( sender , arg ) - > commandSetLogging ( sender , false ) , "Disables Logging." ) ;
addCommand ( "log on" , ( sender , arg ) - > commandSetLogging ( sender , true ) , "Enables Logging." ) ;
addCommand ( "log get" , ( sender , arg ) - > commandGetLogging ( sender ) , "Displays if Logging is enabled." ) ;
addCommand ( "log off" , ( sender , arg ) - > commandSetLogging ( sender , false ) , "Disables Logging." ) ;
addCommand ( "stats" , ( sender , arg ) - > commandSendStats ( sender ) , "Displays statistics about every player." ) ;
addCommand ( "log get" , ( sender , arg ) - > commandGetLogging ( sender ) , "Displays if Logging is enabled." ) ;
addCommand ( "help" , ( sender , arg ) - > commandGetHelp ( sender ) , "Displays help message for command usage." ) ;
addCommand ( "stats" , ( sender , arg ) - > commandSendStats ( sender ) , "Displays statistics about every player." ) ;
}
addCommand ( "help" , ( sender , arg ) - > commandGetHelp ( sender ) , "Displays help message for command usage." ) ;
}
private void addCommand ( String cmdList , BiConsumer < CommandSender , String > call , String description ) {
commands . put ( Arrays . asList ( cmdList . split ( " " ) ) , Pair . pair ( call , description ) ) ;
private void addCommand ( String cmdList , BiConsumer < CommandSender , String > call , String description ) {
}
commands . put ( Arrays . asList ( cmdList . split ( " " ) ) , Pair . pair ( call , description ) ) ;
}
final private List < String > mainSchema ;
final private List < String > hasSecondSchema ;
final private List < String > mainSchema ;
final private List < List < String > > secondSchema ;
final private List < String > hasSecondSchema ;
{
final private List < List < String > > secondSchema ;
//This is a mess, no idea how to expand it for 3 part commands
Map < String , List < String > > mapping = new HashMap < > ( ) ;
{
commands . keySet ( ) . stream ( ) . sorted ( ( l1 , l2 ) - > l1 . stream ( ) . reduce ( "" , ( w1 , w2 ) - > w1 + w2 ) . compareTo ( l2 . stream ( ) . reduce ( "" , ( w1 , w2 ) - > w1 + w2 ) ) ) . forEach ( parts - > {
//This is a mess, no idea how to expand it for 3 part commands
String part1 = parts . get ( 0 ) ;
Map < String , List < String > > mapping = new HashMap < > ( ) ;
String part2 = "" ;
commands . keySet ( ) . stream ( ) . sorted ( ( l1 , l2 ) - > l1 . stream ( ) . reduce ( "" , ( w1 , w2 ) - > w1 + w2 ) . compareTo ( l2 . stream ( ) . reduce ( "" , ( w1 , w2 ) - > w1 + w2 ) ) ) . forEach ( parts - > {
if ( parts . size ( ) = = 2 ) {
String part1 = parts . get ( 0 ) ;
part2 = parts . get ( 1 ) ;
String part2 = "" ;
}
if ( parts . size ( ) = = 2 ) {
mapping . putIfAbsent ( part1 , new ArrayList < > ( ) ) ;
part2 = parts . get ( 1 ) ;
if ( ! part2 . isEmpty ( ) )
}
mapping . get ( part1 ) . add ( part2 ) ;
mapping . putIfAbsent ( part1 , new ArrayList < > ( ) ) ;
} ) ;
if ( ! part2 . isEmpty ( ) )
mainSchema = new ArrayList < > ( mapping . keySet ( ) ) ;
mapping . get ( part1 ) . add ( part2 ) ;
} ) ;
hasSecondSchema = new ArrayList < > ( mapping . keySet ( ) ) ;
mainSchema = new ArrayList < > ( mapping . keySet ( ) ) ;
hasSecondSchema . removeIf ( s - > mapping . get ( s ) . size ( ) = = 0 ) ;
hasSecondSchema = new ArrayList < > ( mapping . keySet ( ) ) ;
secondSchema = new ArrayList < > ( mapping . values ( ) ) ;
hasSecondSchema . removeIf ( s - > mapping . get ( s ) . size ( ) = = 0 ) ;
}
secondSchema = new ArrayList < > ( mapping . values ( ) ) ;
@Override
}
public List < String > onTabComplete ( CommandSender commandSender , Command command , String s , String [ ] strings ) {
List < String > list = new ArrayList < > ( ) ;
@Override
public List < String > onTabComplete ( CommandSender commandSender , Command command , String s , String [ ] strings ) {
if ( strings . length = = 1 ) {
List < String > list = new ArrayList < > ( ) ;
StringUtil . copyPartialMatches ( strings [ 0 ] , mainSchema , list ) ;
}
if ( strings . length = = 1 ) {
if ( strings . length = = 2 ) {
StringUtil . copyPartialMatches ( strings [ 0 ] , mainSchema , list ) ;
if ( hasSecondSchema . contains ( strings [ 0 ] ) ) {
}
int index = mainSchema . indexOf ( strings [ 0 ] ) ;
if ( strings . length = = 2 ) {
List < String > checkList = secondSchema . get ( index ) ;
if ( hasSecondSchema . contains ( strings [ 0 ] ) ) {
StringUtil . copyPartialMatches ( strings [ 1 ] , checkList , list ) ;
int index = mainSchema . indexOf ( strings [ 0 ] ) ;
}
List < String > checkList = secondSchema . get ( index ) ;
}
StringUtil . copyPartialMatches ( strings [ 1 ] , checkList , list ) ;
}
return list ;
}
}
return list ;
@Override
}
public boolean onCommand ( CommandSender sender , Command cmd , String label , String [ ] args ) {
@Override
Pair < BiConsumer < CommandSender , String > , String > command = getCommand ( args ) ;
public boolean onCommand ( CommandSender sender , Command cmd , String label , String [ ] args ) {
command . first . accept ( sender , args . length > 0 ? args [ args . length - 1 ] : "" ) ;
Pair < BiConsumer < CommandSender , String > , String > command = getCommand ( args ) ;
return true ;
command . first . accept ( sender , args . length > 0 ? args [ args . length - 1 ] : "" ) ;
}
return true ;
private Pair < BiConsumer < CommandSender , String > , String > getCommand ( String [ ] args ) {
}
List < String > argList = Arrays . asList ( args ) ;
private Pair < BiConsumer < CommandSender , String > , String > getCommand ( String [ ] args ) {
if ( commands . containsKey ( argList ) )
List < String > argList = Arrays . asList ( args ) ;
return commands . get ( argList ) ;
if ( commands . containsKey ( argList ) )
if ( args . length > 1 ) {
return commands . get ( argList ) ;
List < String > argListWithoutLast = argList . subList ( 0 , args . length - 1 ) ;
if ( commands . containsKey ( argListWithoutLast ) )
if ( args . length > 1 ) {
return commands . get ( argListWithoutLast ) ;
List < String > argListWithoutLast = argList . subList ( 0 , args . length - 1 ) ;
}
if ( commands . containsKey ( argListWithoutLast ) )
return commands . get ( argListWithoutLast ) ;
return Pair . pair ( ( cmdSender , arg ) - > unknownCommand ( cmdSender ) , "" ) ;
}
}
return Pair . pair ( ( cmdSender , arg ) - > unknownCommand ( cmdSender ) , "" ) ;
private void commandReset ( CommandSender sender ) {
}
if ( ! sender . hasPermission ( "sharehealth.reset" ) ) {
sender . sendMessage ( "You don't have permissions for this command!" ) ;
private void commandReset ( CommandSender sender ) {
return ;
if ( ! sender . hasPermission ( "sharehealth.reset" ) ) {
}
sender . sendMessage ( "You don't have permissions for this command!" ) ;
Sharehealth . Instance . reset ( ) ;
return ;
}
}
Sharehealth . Instance . reset ( ) ;
private void commandActivePlayer ( CommandSender sender , String playerName , boolean add ) {
}
if ( ! sender . hasPermission ( "sharehealth.players" ) ) {
sender . sendMessage ( "You don't have permissions for this command!" ) ;
private void commandActivePlayer ( CommandSender sender , String playerName , boolean add ) {
return ;
if ( ! sender . hasPermission ( "sharehealth.players" ) ) {
}
sender . sendMessage ( "You don't have permissions for this command!" ) ;
UUID uuid = Bukkit . getOfflinePlayer ( playerName ) . getUniqueId ( ) ;
return ;
if ( add ) {
}
Sharehealth . Instance . addPlayer ( uuid ) ;
UUID uuid = Bukkit . getOfflinePlayer ( playerName ) . getUniqueId ( ) ;
sender . sendMessage ( "Added player " + playerName ) ;
if ( add ) {
} else {
Sharehealth . Instance . addPlayer ( uuid ) ;
Sharehealth . Instance . removePlayer ( uuid ) ;
sender . sendMessage ( "Added player " + playerName ) ;
sender . sendMessage ( "Removed player " + playerName ) ;
} else {
}
Sharehealth . Instance . removePlayer ( uuid ) ;
}
sender . sendMessage ( "Removed player " + playerName ) ;
}
private void commandGetHealth ( CommandSender sender ) {
}
String message = "Current health: " + Sharehealth . Instance . getHealthManager ( ) . getHealthString ( ) ;
sender . sendMessage ( message ) ;
private void commandGetHealth ( CommandSender sender ) {
}
String message = "Current health: " + Sharehealth . Instance . getHealthManager ( ) . getHealthString ( ) ;
sender . sendMessage ( message ) ;
private void commandSetTotemMode ( CommandSender sender , TotemManager . Mode mode ) {
}
if ( ! sender . hasPermission ( "sharehealth.totem" ) ) {
sender . sendMessage ( "You don't have permissions for this command!" ) ;
private void commandSetTotemMode ( CommandSender sender , TotemManager . Mode mode ) {
return ;
if ( ! sender . hasPermission ( "sharehealth.totem" ) ) {
}
sender . sendMessage ( "You don't have permissions for this command!" ) ;
Sharehealth . Instance . getTotemManager ( ) . setMode ( mode ) ;
return ;
sender . sendMessage ( "Set Totem mode to " + mode . name ( ) ) ;
}
}
Sharehealth . Instance . getTotemManager ( ) . setMode ( mode ) ;
sender . sendMessage ( "Set Totem mode to " + mode . name ( ) ) ;
private void commandGetTotemMode ( CommandSender sender ) {
}
TotemManager . Mode mode = Sharehealth . Instance . getTotemManager ( ) . getMode ( ) ;
sender . sendMessage ( "Current Totem mode: " + mode . name ( ) ) ;
private void commandGetTotemMode ( CommandSender sender ) {
}
TotemManager . Mode mode = Sharehealth . Instance . getTotemManager ( ) . getMode ( ) ;
sender . sendMessage ( "Current Totem mode: " + mode . name ( ) ) ;
private void commandSetTotemFraction ( CommandSender sender , String amountStr ) {
}
if ( ! sender . hasPermission ( "sharehealth.totem" ) ) {
sender . sendMessage ( "You don't have permissions for this command!" ) ;
private void commandSetTotemFraction ( CommandSender sender , String amountStr ) {
return ;
if ( ! sender . hasPermission ( "sharehealth.totem" ) ) {
}
sender . sendMessage ( "You don't have permissions for this command!" ) ;
return ;
try {
}
double fraction = Double . parseDouble ( amountStr ) ;
Sharehealth . Instance . getTotemManager ( ) . setFractionNeeded ( fraction ) ;
try {
double newValue = Sharehealth . Instance . getTotemManager ( ) . getFractionNeeded ( ) ;
double fraction = Double . parseDouble ( amountStr ) ;
sender . sendMessage ( "Set totem fraction value to " + newValue ) ;
Sharehealth . Instance . getTotemManager ( ) . setFractionNeeded ( fraction ) ;
} catch ( NumberFormatException e ) {
double newValue = Sharehealth . Instance . getTotemManager ( ) . getFractionNeeded ( ) ;
sender . sendMessage ( "Provided value was not a number between 0.0 and 1.0!" ) ;
sender . sendMessage ( "Set totem fraction value to " + newValue ) ;
}
} catch ( NumberFormatException e ) {
}
sender . sendMessage ( "Provided value was not a number between 0.0 and 1.0!" ) ;
}
private void commandGetTotemFraction ( CommandSender sender ) {
}
double value = Sharehealth . Instance . getTotemManager ( ) . getFractionNeeded ( ) ;
sender . sendMessage ( "Totem fraction value: " + value ) ;
private void commandGetTotemFraction ( CommandSender sender ) {
}
double value = Sharehealth . Instance . getTotemManager ( ) . getFractionNeeded ( ) ;
sender . sendMessage ( "Totem fraction value: " + value ) ;
private void commandSetLogging ( CommandSender sender , boolean hasLogging ) {
}
if ( sender instanceof Player ) {
if ( ! Sharehealth . GetPlayers ( ) . contains ( sender ) )
private void commandSetLogging ( CommandSender sender , boolean hasLogging ) {
return ;
if ( sender instanceof Player ) {
if ( ! Sharehealth . GetPlayers ( ) . contains ( sender ) )
Sharehealth . Instance . onLoggingUpdated ( ( Player ) sender , hasLogging ) ;
return ;
sender . sendMessage ( "Logging settings updated." ) ;
}
Sharehealth . Instance . onLoggingUpdated ( ( Player ) sender , hasLogging ) ;
}
sender . sendMessage ( "Logging settings updated." ) ;
}
private void commandGetLogging ( CommandSender sender ) {
}
if ( sender instanceof Player ) {
if ( ! Sharehealth . GetPlayers ( ) . contains ( sender ) )
private void commandGetLogging ( CommandSender sender ) {
return ;
if ( sender instanceof Player ) {
if ( ! Sharehealth . GetPlayers ( ) . contains ( sender ) )
String message = "Logging enabled: " + Sharehealth . Instance . getLogging ( ( Player ) sender ) ;
return ;
sender . sendMessage ( message ) ;
}
String message = "Logging enabled: " + Sharehealth . Instance . getLogging ( ( Player ) sender ) ;
}
sender . sendMessage ( message ) ;
}
private void commandSendStats ( CommandSender sender ) {
}
String message = Sharehealth . Instance . getMessenger ( ) . statisticsMessage ( ) ;
sender . sendMessage ( message ) ;
private void commandSendStats ( CommandSender sender ) {
}
String message = Sharehealth . Instance . getMessenger ( ) . statisticsMessage ( ) ;
sender . sendMessage ( message ) ;
private void commandGetHelp ( CommandSender sender ) {
}
String message = Sharehealth . Instance . getMessenger ( ) . helpMessage ( commands ) ;
sender . sendMessage ( message ) ;
private void commandGetHelp ( CommandSender sender ) {
}
String message = Sharehealth . Instance . getMessenger ( ) . helpMessage ( commands ) ;
sender . sendMessage ( message ) ;
private void unknownCommand ( CommandSender sender ) {
}
String message = "Unknown command. Type \"/sh help\" for help." ;
sender . sendMessage ( message ) ;
private void unknownCommand ( CommandSender sender ) {
}
String message = "Unknown command. Type \"/sh help\" for help." ;
sender . sendMessage ( message ) ;
}
}
}