Skip to content

Instantly share code, notes, and snippets.

@ncurran02
Last active January 21, 2019 11:23
Show Gist options
  • Save ncurran02/f07d6406b4b7580f804107cc564005d0 to your computer and use it in GitHub Desktop.
Save ncurran02/f07d6406b4b7580f804107cc564005d0 to your computer and use it in GitHub Desktop.
Just a random code I made up. I don't know if it has error in them as I was using Notepad++
public static Map<User, String> servers = new HashMap<>();
public static Map<String, Boolean> started = new HashMap<>();
public static void createServer(User user, String name)
{
if (user == null)
{
return;
}
System.out.println("Creating a server, please wait");
servers.put(user, name);
System.out.println("Generating server configuration…");
generateServerConfig(name);
System.out.println("Configuration successfully generated\nStarting the server");
setServerState(user, true);
}
public static void generateServerConfig(String name)
{
// TO DO: create a code here - JSON configuration, use GSON
}
public static void setServerState(User user, Boolean state)
{
if (user == null)
{
System.out.println("Invalid user");
return;
}
Boolean stated = getServerState(user);
if ((stated && state == true) || (!stated && state == false))
{
System.out.println("Sorry, the server state is already on " + stated);
return;
}
started.put(server, state);
System.out.println("Successfully set " + server + " to " + state + " by " + user.getName());
}
public static boolean getServerState(User user)
{
if (user == null)
{
System.out.println("That user is invalid!");
}
String server = servers.get(user);
return started.get(server);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment