Browse Source

New command system, util cleanup

- CommandInfo annotation
- Reflection to load commands
- Utility methods and classes cleaned up
Tankernn 8 years ago
parent
commit
d68689b968

+ 10 - 10
pom.xml

@@ -1,15 +1,10 @@
 <?xml version="1.0" encoding="UTF-8"?>
 
-<!-- 
-   Copyright (c) 2009, 2012 Mountainminds GmbH & Co. KG and Contributors
-   All rights reserved. This program and the accompanying materials
-   are made available under the terms of the Eclipse Public License v1.0
-   which accompanies this distribution, and is available at
-   http://www.eclipse.org/legal/epl-v10.html
-  
-   Contributors:
-      Marc R. Hoffmann - initial API and implementation
--->
+<!-- Copyright (c) 2009, 2012 Mountainminds GmbH & Co. KG and Contributors 
+	All rights reserved. This program and the accompanying materials are made 
+	available under the terms of the Eclipse Public License v1.0 which accompanies 
+	this distribution, and is available at http://www.eclipse.org/legal/epl-v10.html 
+	Contributors: Marc R. Hoffmann - initial API and implementation -->
 
 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
@@ -30,6 +25,11 @@
 			<version>4.10</version>
 			<scope>test</scope>
 		</dependency>
+		<dependency>
+			<groupId>org.reflections</groupId>
+			<artifactId>reflections</artifactId>
+			<version>0.9.10</version>
+		</dependency>
 	</dependencies>
 
 	<build>

+ 0 - 15
src/main/java/common/Command.java

@@ -1,15 +0,0 @@
-package common;
-
-import server.Client;
-
-public abstract class Command {
-	public abstract void execute(String[] args, Client caller) throws Exception;
-	
-	public abstract String getName();
-	
-	public abstract String getPermission();
-	
-	public abstract String getDescription();
-	
-	public abstract int getMinArgNumber();
-}

+ 47 - 20
src/main/java/server/CommandRegistry.java

@@ -1,26 +1,41 @@
 package server;
 
+import java.util.Arrays;
 import java.util.HashMap;
-import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Set;
+import java.util.stream.Stream;
 
-import common.Command;
-import util.ClassFinder;
-import util.StringArrays;
+import org.reflections.Reflections;
 
-public class CommandRegistry extends HashMap<String, Command> {
+import common.MessagePacket;
+import common.MessagePacket.MessageType;
+import server.command.Command;
+import server.command.CommandInfo;
+import util.ArrayUtil;
+
+public class CommandRegistry  {
+	
+	private Map<String, Command> commands = new HashMap<>();
 	
-	/**
-	 * 
-	 */
-	private static final long serialVersionUID = 1L;
+	private static final String COMMAND_PACKAGE = "server.command";
 	
-	public CommandRegistry(String commandPackage) {
-		List<Class<?>> classes = ClassFinder.find(commandPackage);
+	public CommandRegistry() {
+		Reflections reflections = new Reflections(COMMAND_PACKAGE);
+		Set<Class<?>> annotated = reflections.getTypesAnnotatedWith(CommandInfo.class);
 		
-		for (Class<?> comm: classes) {
+		for (Class<?> comm: annotated) {
 			try {
-				Command commInstance = (Command) comm.newInstance();
-				put(commInstance.getName(), commInstance);
+				CommandInfo c = comm.getAnnotation(CommandInfo.class);
+				
+				if (!Arrays.asList(comm.getInterfaces()).contains(Command.class)) {
+					// TODO Proper logging
+					System.err.println(comm.getName() + " is annoteded with " + CommandInfo.class.getName() + ", but does not implement" + Command.class.getName());
+					continue;
+				}
+				
+				commands.put(c.name(), (Command) comm.newInstance());
 			} catch (ClassCastException | InstantiationException | IllegalAccessException ex) {
 				ex.printStackTrace();
 			}
@@ -31,14 +46,15 @@ public class CommandRegistry extends HashMap<String, Command> {
 		String[] command = commandStr.substring(1).split(" ");
 		
 		Command comm;
-		if ((comm = get(command[0])) != null) // Get the command
-			if (caller.hasPermission(comm.getPermission())) { // Check if the client has permission
-				String[] args = StringArrays.removeFirst(command);
-				if (args.length >= comm.getMinArgNumber()) { // Check the number of arguments
+		if ((comm = commands.get(command[0])) != null) { // Get the command
+			CommandInfo info = comm.getClass().getAnnotation(CommandInfo.class);
+			if (caller.hasPermission(info.permission())) { // Check if the client has permission
+				String[] args = ArrayUtil.removeFirst(command);
+				if (args.length >= info.minArg()) { // Check the number of arguments
 					try {
 						comm.execute(args, caller); // Execute command
 					} catch (Exception e) {
-						caller.send("Error while executing command!");
+						caller.send(new MessagePacket("Error while executing command!", MessageType.ERROR));
 						e.printStackTrace();
 					}
 					return;
@@ -50,8 +66,19 @@ public class CommandRegistry extends HashMap<String, Command> {
 				caller.send("Not enough permissions!");
 				return;
 			}
-		else
+		} else
 			caller.send("No such command! Type '/help' for a list of commands.");
 	}
 	
+	public String getHelp() {
+		StringBuilder help = new StringBuilder();
+		help.append("Help for all commands:" + "\n");
+		
+		Stream<Entry<String, Command>> stream = commands.entrySet().stream();
+		
+		stream.map(c -> c.getValue().getClass().getAnnotation(CommandInfo.class)).map((a) -> a.name() + ": " + "\t" + a.desc() + "\n").forEach(help::append);
+		
+		return help.toString();
+	}
+	
 }

+ 1 - 1
src/main/java/server/Server.java

@@ -49,7 +49,7 @@ public class Server {
 		channels.add(new Channel("Main"));
 		
 		System.out.print("Starting commandhandler...");
-		commReg = new CommandRegistry("server.command");
+		commandRegistry = new CommandRegistry();
 		System.out.println("Done");
 		
 		System.out.print("Creating virtual local client...");

+ 18 - 32
src/main/java/server/command/Ban.java

@@ -1,19 +1,19 @@
 package server.command;
 
+import java.io.IOException;
+import java.util.Arrays;
 import java.util.InputMismatchException;
 import java.util.Optional;
 
+import common.MessagePacket;
+import common.MessagePacket.MessageType;
 import server.BanNote;
 import server.Client;
 import server.Server;
-import util.Numbers;
-import util.StringArrays;
-
-import common.Command;
-import common.MessagePacket;
-import common.MessagePacket.MessageType;
+import util.ArrayUtil;
 
-public class Ban extends Command {
+@CommandInfo(desc = "Bans a user. (/ban <username> [seconds] [reason])", name = "ban", permission = "admin.ban", minArg = 1)
+public class Ban implements Command {
 	
 	@Override
 	public void execute(String[] args, Client caller) {
@@ -30,43 +30,29 @@ public class Ban extends Command {
 			return;
 		}
 		
-		IP = victim.getIP();
+		try {
+			IP = victim.getIP();
+		} catch (IOException e) {
+			e.printStackTrace();
+			caller.send(new MessagePacket("Error getting target IP address.", MessageType.ERROR));
+			return;
+		}
 		
 		BanNote bn = new BanNote(IP);
 		
 		if (args.length != 1)
 			try {
-				duration = Numbers.CInt(args[1]);
+				duration = Integer.parseInt(args[1]);
 				
 				if (args.length >= 3)
-					bn = new BanNote(IP, duration, StringArrays.arrayToString(StringArrays.removeFirst(StringArrays.removeFirst(args))));
+					bn = new BanNote(IP, duration, Arrays.toString(ArrayUtil.removeFirst(ArrayUtil.removeFirst(args))));
 				else
 					bn = new BanNote(IP, duration);
 			} catch (InputMismatchException ime) {
-				bn = new BanNote(IP, StringArrays.arrayToString(StringArrays.removeFirst(args)));
+				bn = new BanNote(IP, Arrays.toString(ArrayUtil.removeFirst(args)));
 			}
 		
-		Server.banNotes.add(bn);
-	}
-	
-	@Override
-	public String getName() {
-		return "ban";
-	}
-	
-	@Override
-	public String getPermission() {
-		return "server.ban";
-	}
-	
-	@Override
-	public String getDescription() {
-		return "Bans a user. (/ban <username> [seconds] [reason])";
-	}
-	
-	@Override
-	public int getMinArgNumber() {
-		return 1;
+		Server.ban(bn);
 	}
 	
 }

+ 7 - 0
src/main/java/server/command/Command.java

@@ -0,0 +1,7 @@
+package server.command;
+
+import server.Client;
+
+public interface Command {
+	public void execute(String[] args, Client caller) throws Exception;
+}

+ 18 - 0
src/main/java/server/command/CommandInfo.java

@@ -0,0 +1,18 @@
+package server.command;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+@Retention(RetentionPolicy.RUNTIME)
+@Target(ElementType.TYPE)
+public @interface CommandInfo {
+	public String name();
+	
+	public String permission();
+	
+	public String desc();
+	
+	public int minArg() default 0;
+}

+ 5 - 25
src/main/java/server/command/CreateChannel.java

@@ -1,38 +1,18 @@
 package server.command;
 
+import common.MessagePacket;
+import server.Channel;
 import server.Client;
 import server.Server;
 
-import common.Command;
-import common.MessagePacket;
-
-public class CreateChannel extends Command {
+@CommandInfo(desc = "Creates a channel with specified settings. (/createchannel <name>)", name = "create", permission = "admin.create.channel", minArg = 1)
+public class CreateChannel implements Command {
 	
 	@Override
 	public void execute(String[] args, Client caller) throws Exception {
-		Server.channels.add(new server.Channel(args[0]));
+		Server.getChannels().add(new Channel(args[0]));
 		
 		Server.wideBroadcast(new MessagePacket("Channel " + args[0] + " is now available. Use '/join " + args[0] + "' to join."));
 	}
 	
-	@Override
-	public String getName() {
-		return "createchannel";
-	}
-	
-	@Override
-	public String getPermission() {
-		return "server.createchannel";
-	}
-	
-	@Override
-	public String getDescription() {
-		return "Creates a channel with specified settings. (/createchannel <name>)";
-	}
-	
-	@Override
-	public int getMinArgNumber() {
-		return 1;
-	}
-	
 }

+ 2 - 23
src/main/java/server/command/Exit.java

@@ -3,33 +3,12 @@ package server.command;
 import server.Client;
 import server.Server;
 
-import common.Command;
-
-public class Exit extends Command {
+@CommandInfo(desc = "Stops the server.", name = "stop", permission = "server.exit")
+public class Exit implements Command {
 	
 	@Override
 	public void execute(String[] args, Client caller) {
 		Server.exit();
 	}
 	
-	@Override
-	public String getName() {
-		return "exit";
-	}
-	
-	@Override
-	public int getMinArgNumber() {
-		return 0;
-	}
-	
-	@Override
-	public String getDescription() {
-		return "Exits the server.";
-	}
-	
-	@Override
-	public String getPermission() {
-		return "server.exit";
-	}
-	
 }

+ 2 - 25
src/main/java/server/command/GiveOP.java

@@ -1,12 +1,12 @@
 package server.command;
 
-import common.Command;
 import common.MessagePacket;
 import common.MessagePacket.MessageType;
 import server.Client;
 import server.Server;
 
-public class GiveOP extends Command {
+@CommandInfo(desc = "Give a client OP permissions.", name = "op", permission = "admin.op", minArg = 1)
+public class GiveOP implements Command {
 
 	@Override
 	public void execute(String[] args, Client caller) throws Exception {
@@ -19,27 +19,4 @@ public class GiveOP extends Command {
 		}
 	}
 
-	@Override
-	public String getName() {
-		return "op";
-	}
-
-	@Override
-	public String getPermission() {
-		// TODO Auto-generated method stub
-		return "server.op";
-	}
-
-	@Override
-	public String getDescription() {
-		// TODO Auto-generated method stub
-		return "Give a client OP permissions.";
-	}
-
-	@Override
-	public int getMinArgNumber() {
-		// TODO Auto-generated method stub
-		return 1;
-	}
-
 }

+ 6 - 41
src/main/java/server/command/Help.java

@@ -1,51 +1,16 @@
 package server.command;
 
-import java.util.Iterator;
-import java.util.Map;
-import java.util.Map.Entry;
-
+import common.MessagePacket;
+import common.MessagePacket.MessageType;
 import server.Client;
 import server.Server;
 
-import common.Command;
-import common.MessagePacket;
-import common.MessagePacket.MessageType;
+@CommandInfo(desc = "Writes the descriptions for all commands.", name = "help", permission = "user.help")
+public class Help implements Command {
 
-public class Help extends Command {
-	
 	@Override
 	public void execute(String[] args, Client caller) {
-		String help = "Help for all commands:" + "\n";
-		Iterator<Entry<String, Command>> it = Server.commReg.entrySet().iterator();
-		
-		while (it.hasNext()) {
-			Map.Entry<String, Command> pair = it.next();
-			
-			help += pair.getKey() + ": " + "\t" + pair.getValue().getDescription();
-			if (it.hasNext())
-				help += "\n";
-		}
-		caller.send(new MessagePacket(help, MessageType.COMMAND));
-	}
-	
-	@Override
-	public String getName() {
-		return "help";
+		caller.send(new MessagePacket(Server.getCommReg().getHelp(), MessageType.COMMAND));
 	}
-	
-	@Override
-	public int getMinArgNumber() {
-		return 0;
-	}
-	
-	@Override
-	public String getDescription() {
-		return "Writes the descriptions for all commands.";
-	}
-	
-	@Override
-	public String getPermission() {
-		return "noob.help";
-	}
-	
+
 }

+ 7 - 28
src/main/java/server/command/JoinChannel.java

@@ -5,23 +5,22 @@ import java.util.Optional;
 import server.Channel;
 import server.Client;
 import server.Server;
-
-import common.Command;
 import common.MessagePacket;
 import common.MessagePacket.MessageType;
 
-public class JoinChannel extends Command {
-	
+@CommandInfo(desc = "Sets specified channel as primary (/join <channel>)", name = "join", permission = "user.join", minArg = 1)
+public class JoinChannel implements Command {
+
 	@Override
 	public void execute(String[] args, Client caller) {
-		if (caller.equals(Server.OPClient)) {
+		if (caller.equals(Server.getOPClient())) {
 			caller.send("Client-only command.");
 			return;
 		}
-		
+
 		Optional<Channel> maybeChannel = Server.getChannelByName(args[0]);
 		Channel selectedChannel = maybeChannel.isPresent() ? maybeChannel.get() : null;
-		
+
 		try {
 			selectedChannel.add(caller);
 			caller.primaryChannel = selectedChannel;
@@ -30,25 +29,5 @@ public class JoinChannel extends Command {
 			caller.send(new MessagePacket("No such channel!", MessageType.ERROR));
 		}
 	}
-	
-	@Override
-	public String getName() {
-		return "join";
-	}
-	
-	@Override
-	public String getPermission() {
-		return "noob.channel";
-	}
-	
-	@Override
-	public String getDescription() {
-		return "Sets specified channel as primary (/join <channel>)";
-	}
-	
-	@Override
-	public int getMinArgNumber() {
-		return 1;
-	}
-	
+
 }

+ 5 - 26
src/main/java/server/command/Kick.java

@@ -2,43 +2,22 @@ package server.command;
 
 import java.util.Optional;
 
+import common.MessagePacket;
+import common.MessagePacket.MessageType;
 import server.Client;
 import server.Server;
 
-import common.Command;
-import common.MessagePacket;
-import common.MessagePacket.MessageType;
+@CommandInfo(desc = "Kicks a user. (/kick <username>)", name = "kick", permission = "admin.kick")
+public class Kick implements Command {
 
-public class Kick extends Command {
-	
 	@Override
 	public void execute(String[] args, Client caller) {
 		Optional<Client> maybeVictim = Server.getUserByName(args[0]);
-		
+
 		try {
 			maybeVictim.orElseThrow(NullPointerException::new).disconnect(false);
 		} catch (NullPointerException ex) {
 			caller.send(new MessagePacket("No user called " + args[0] + "!", MessageType.ERROR));
 		}
 	}
-	
-	@Override
-	public String getName() {
-		return "kick";
-	}
-	
-	@Override
-	public int getMinArgNumber() {
-		return 1;
-	}
-	
-	@Override
-	public String getDescription() {
-		return "Kicks a user. (/kick <username>)";
-	}
-	
-	@Override
-	public String getPermission() {
-		return "server.kick";
-	}
 }

+ 10 - 31
src/main/java/server/command/LeaveChannel.java

@@ -2,56 +2,35 @@ package server.command;
 
 import java.util.Optional;
 
+import common.MessagePacket;
+import common.MessagePacket.MessageType;
 import server.Channel;
 import server.Client;
 import server.Server;
 
-import common.Command;
-import common.MessagePacket;
-import common.MessagePacket.MessageType;
+@CommandInfo(desc = "Removes caller from specified channel. (/leave <channel>)", name = "leave", permission = "user.leave", minArg = 1)
+public class LeaveChannel implements Command {
 
-public class LeaveChannel extends Command {
-	
 	@Override
 	public void execute(String[] args, Client caller) throws Exception {
-		if (caller.equals(Server.OPClient)) {
+		if (caller.equals(Server.getOPClient())) {
 			caller.send("Client-only command.");
 			return;
 		}
-		
+
 		Optional<Channel> maybeChannel = Server.getChannelByName(args[0]);
 		Channel selectedChannel = maybeChannel.isPresent() ? maybeChannel.get() : null;
-		
+
 		try {
 			selectedChannel.remove(caller);
 			if (caller.primaryChannel.equals(selectedChannel))
-				caller.primaryChannel = Server.channels.get(0);
+				caller.primaryChannel = Server.getChannels().get(0);
 			caller.send(new MessagePacket("You left channel " + args[0] + ".", MessageType.COMMAND));
-			caller.send(new MessagePacket("You are now speaking in channel " + caller.primaryChannel.name + ".", MessageType.COMMAND));
+			caller.send(new MessagePacket("You are now speaking in channel " + caller.primaryChannel.name + ".",
+					MessageType.COMMAND));
 		} catch (NullPointerException ex) {
 			caller.send(new MessagePacket("No channel named " + args[0] + ".", MessageType.ERROR));
 			return;
 		}
 	}
-	
-	@Override
-	public String getName() {
-		return "leave";
-	}
-	
-	@Override
-	public String getPermission() {
-		return "noob.leave";
-	}
-	
-	@Override
-	public String getDescription() {
-		return "Removes caller from specified channel. (/leave <channel>)";
-	}
-	
-	@Override
-	public int getMinArgNumber() {
-		return 1;
-	}
-	
 }

+ 10 - 30
src/main/java/server/command/List.java

@@ -5,54 +5,34 @@ import java.util.Optional;
 import server.Channel;
 import server.Client;
 import server.Server;
-
-import common.Command;
 import common.MessagePacket;
 import common.MessagePacket.MessageType;
 
-public class List extends Command {
-	
+@CommandInfo(desc = "Lists all users online. (/list [channel])", name = "list", permission = "noob.list")
+public class List implements Command {
+
 	@Override
 	public void execute(String[] args, Client caller) {
 		String arr, channelName = null;
-		
+
 		if (args.length >= 1) {
 			Optional<Channel> maybeChannel = Server.getChannelByName(args[0]);
 			Channel selectedChannel = maybeChannel.isPresent() ? maybeChannel.get() : null;
 			try {
-				arr = selectedChannel.listClients('\n');
+				arr = selectedChannel.listClients("\n");
 				channelName = selectedChannel.name;
 			} catch (NullPointerException ex) {
 				caller.send(new MessagePacket("No channel named " + channelName + ".", MessageType.ERROR));
 				return;
 			}
 		} else
-			arr = Server.listClients('\n');
-		
+			arr = Server.listClients("\n");
+
 		if (channelName == null)
 			caller.send(new MessagePacket("Users online are:" + "\n" + arr, MessageType.COMMAND));
 		else
-			caller.send(new MessagePacket("Users in channel " + channelName + " are:" + "\n" + arr, MessageType.COMMAND));
+			caller.send(
+					new MessagePacket("Users in channel " + channelName + " are:" + "\n" + arr, MessageType.COMMAND));
 	}
-	
-	@Override
-	public String getName() {
-		return "list";
-	}
-	
-	@Override
-	public int getMinArgNumber() {
-		return 0;
-	}
-	
-	@Override
-	public String getDescription() {
-		return "Lists all users online. (/list [channel])";
-	}
-	
-	@Override
-	public String getPermission() {
-		return "noob.list";
-	}
-	
+
 }

+ 12 - 31
src/main/java/server/command/PrivateMessage.java

@@ -1,22 +1,22 @@
 package server.command;
 
+import java.util.Arrays;
 import java.util.Optional;
 
 import server.Client;
 import server.Server;
-import util.StringArrays;
-
-import common.Command;
+import util.ArrayUtil;
 import common.MessagePacket;
 import common.MessagePacket.MessageType;
 
-public class PrivateMessage extends Command {
-	
+@CommandInfo(desc = "Sends a private message to a user", name = "pm", permission = "user.pm", minArg = 2)
+public class PrivateMessage implements Command {
+
 	@Override
 	public void execute(String[] args, Client caller) {
 		Client reciever;
 		Optional<Client> maybeVictim = Server.getUserByName(args[0]);
-		
+
 		if (maybeVictim.isPresent())
 			reciever = maybeVictim.get();
 		else {
@@ -30,32 +30,13 @@ public class PrivateMessage extends Command {
 			caller.send("No user called " + args[0] + ".");
 			return;
 		}
-		
-		MessagePacket mess = new MessagePacket("PM", caller.username, StringArrays.arrayToString(StringArrays.removeFirst(args)), MessagePacket.MessageType.PM);
-		
+
+		MessagePacket mess = new MessagePacket("PM", caller.username,
+				Arrays.toString(ArrayUtil.removeFirst(args)), MessagePacket.MessageType.PM);
+
 		reciever.send(mess);
 		caller.send(mess);
-		
-	}
-	
-	@Override
-	public String getName() {
-		return "pm";
-	}
-	
-	@Override
-	public String getPermission() {
-		return "noob.pm";
-	}
-	
-	@Override
-	public String getDescription() {
-		return "Sends a private message to a user";
-	}
-	
-	@Override
-	public int getMinArgNumber() {
-		return 2;
+
 	}
-	
+
 }

+ 9 - 0
src/main/java/util/ArrayUtil.java

@@ -0,0 +1,9 @@
+package util;
+
+public class ArrayUtil {
+	public static String[] removeFirst(String[] oldArr) {
+		String[] newArr = new String[oldArr.length - 1];
+		System.arraycopy(oldArr, 1, newArr, 0, oldArr.length - 1);
+		return newArr;
+	}
+}

+ 0 - 50
src/main/java/util/ClassFinder.java

@@ -1,50 +0,0 @@
-package util;
-
-import java.io.File;
-import java.net.URL;
-import java.util.ArrayList;
-import java.util.List;
-
-//Class originally developed by 'sp00m' and published on stackoverflow.com
-
-public class ClassFinder {
-	private static final char DOT = '.';
-	
-	private static final char SLASH = '/';
-	
-	private static final String CLASS_SUFFIX = ".class";
-	
-	private static final String BAD_PACKAGE_ERROR = "Unable to get resources from path '%s'. Are you sure the package '%s' exists?";
-	
-	public static List<Class<?>> find(String scannedPackage) {
-		String scannedPath = scannedPackage.replace(DOT, SLASH);
-		URL scannedUrl = Thread.currentThread().getContextClassLoader().getResource(scannedPath);
-		if (scannedUrl == null) {
-			throw new IllegalArgumentException(String.format(BAD_PACKAGE_ERROR, scannedPath, scannedPackage));
-		}
-		File scannedDir = new File(scannedUrl.getFile());
-		List<Class<?>> classes = new ArrayList<Class<?>>();
-		for (File file: scannedDir.listFiles()) {
-			classes.addAll(find(file, scannedPackage));
-		}
-		return classes;
-	}
-	
-	private static List<Class<?>> find(File file, String scannedPackage) {
-		List<Class<?>> classes = new ArrayList<Class<?>>();
-		String resource = scannedPackage + DOT + file.getName();
-		if (file.isDirectory()) {
-			for (File child: file.listFiles()) {
-				classes.addAll(find(child, resource));
-			}
-		} else if (resource.endsWith(CLASS_SUFFIX)) {
-			int endIndex = resource.length() - CLASS_SUFFIX.length();
-			String className = resource.substring(0, endIndex);
-			try {
-				classes.add(Class.forName(className));
-			} catch (ClassNotFoundException ignore) {
-			}
-		}
-		return classes;
-	}
-}

+ 0 - 13
src/main/java/util/Numbers.java

@@ -1,13 +0,0 @@
-package util;
-
-import java.util.Scanner;
-
-public class Numbers {
-	public static int CInt(String str) {
-		int i;
-		Scanner sc = new Scanner(str);
-		i = sc.nextInt();
-		sc.close();
-		return i;
-	}
-}

+ 0 - 16
src/main/java/util/StringArrays.java

@@ -1,16 +0,0 @@
-package util;
-
-public class StringArrays {
-	public static String[] removeFirst(String[] oldArr) {
-		String[] newArr = new String[oldArr.length - 1];
-		for (int i = 1; i < oldArr.length; i++) {
-			newArr[i - 1] = oldArr[i];
-		}
-		return newArr;
-	}
-	
-	public static String arrayToString(String[] arr) {
-		return arr.toString().replace("[", "").replace("]", "")
-				.replace(", ", " ");
-	}
-}

+ 0 - 10
src/test/java/server/ServerTestCase.java

@@ -1,12 +1,7 @@
 package server;
 
-import static org.junit.Assert.assertEquals;
-
 import org.junit.AfterClass;
 import org.junit.BeforeClass;
-import org.junit.Test;
-
-import util.Numbers;
 
 public class ServerTestCase {
 	
@@ -15,11 +10,6 @@ public class ServerTestCase {
 		ServerTestSuite.runServer.start();
 	}
 	
-	@Test
-	public void testCInt() {
-		assertEquals(Numbers.CInt("832"), 832);
-	}
-	
 	@AfterClass
 	public static void tearDownClass() {
 		Server.exit();

+ 2 - 5
src/test/java/server/ServerTestSuite.java

@@ -8,10 +8,7 @@ import org.junit.runners.Suite.SuiteClasses;
 @SuiteClasses(value = {client.ClientTestSuite.class})
 public class ServerTestSuite {
 	
-	public static Thread runServer = new Thread() {
-		@Override
-		public void run() {
+	public static Thread runServer = new Thread(() -> {
 			Server.main(new String[] {});
-		}
-	};
+	});
 }