diff --git a/landlords-client/src/main/java/org/nico/ratel/landlords/client/SimpleClient.java b/landlords-client/src/main/java/org/nico/ratel/landlords/client/SimpleClient.java index 3cff8ac..be4dbbd 100644 --- a/landlords-client/src/main/java/org/nico/ratel/landlords/client/SimpleClient.java +++ b/landlords-client/src/main/java/org/nico/ratel/landlords/client/SimpleClient.java @@ -50,9 +50,11 @@ public class SimpleClient { for(int i = 0; i < serverAddressList.size(); i++) { SimplePrinter.printNotice((i+1) + ". " + serverAddressList.get(i)); } - int serverPick = Integer.parseInt(SimpleWriter.write("option")); + int serverPick = 0; while(serverPick<1 || serverPick>serverAddressList.size()){ - SimplePrinter.printNotice("Invalid Option"); + try { + serverPick = Integer.parseInt(SimpleWriter.write("option")); + }catch(NumberFormatException e){} } serverAddress = serverAddressList.get(serverPick-1); String[] elements = serverAddress.split(":"); diff --git a/landlords-client/src/main/java/org/nico/ratel/landlords/client/event/ClientEventListener_CODE_GAME_LANDLORD_CONFIRM.java b/landlords-client/src/main/java/org/nico/ratel/landlords/client/event/ClientEventListener_CODE_GAME_LANDLORD_CONFIRM.java index c899885..21df63e 100644 --- a/landlords-client/src/main/java/org/nico/ratel/landlords/client/event/ClientEventListener_CODE_GAME_LANDLORD_CONFIRM.java +++ b/landlords-client/src/main/java/org/nico/ratel/landlords/client/event/ClientEventListener_CODE_GAME_LANDLORD_CONFIRM.java @@ -5,7 +5,6 @@ import java.util.Map; import org.nico.noson.Noson; import org.nico.noson.entity.NoType; -import org.nico.ratel.landlords.client.SimpleClient; import org.nico.ratel.landlords.entity.Poker; import org.nico.ratel.landlords.enums.ServerEventCode; import org.nico.ratel.landlords.helper.MapHelper; diff --git a/landlords-client/src/main/java/org/nico/ratel/landlords/client/event/ClientEventListener_CODE_SHOW_OPTIONS_SETTING.java b/landlords-client/src/main/java/org/nico/ratel/landlords/client/event/ClientEventListener_CODE_SHOW_OPTIONS_SETTING.java index c7a84b3..89d5143 100644 --- a/landlords-client/src/main/java/org/nico/ratel/landlords/client/event/ClientEventListener_CODE_SHOW_OPTIONS_SETTING.java +++ b/landlords-client/src/main/java/org/nico/ratel/landlords/client/event/ClientEventListener_CODE_SHOW_OPTIONS_SETTING.java @@ -13,20 +13,11 @@ public class ClientEventListener_CODE_SHOW_OPTIONS_SETTING extends ClientEventLi @Override public void call(Channel channel, String data) { SimplePrinter.printNotice("Setting: "); - /* - case 0: - return buildHandStringSharp(pokers); - case 1: - return buildHandStringRounded(pokers); - case 2: - return textOnly(pokers); - case 3: - return textOnlyNoType(pokers); - */ SimplePrinter.printNotice("1. Card with shape edges (Default)"); SimplePrinter.printNotice("2. Card with rounded edges"); SimplePrinter.printNotice("3. Text Only with types"); SimplePrinter.printNotice("4. Text Only without types"); + SimplePrinter.printNotice("5. Unicode Cards"); SimplePrinter.printNotice("Please enter the number of setting (enter [BACK] return options list)"); String line = SimpleWriter.write("setting"); @@ -40,7 +31,7 @@ public class ClientEventListener_CODE_SHOW_OPTIONS_SETTING extends ClientEventLi } int choose = Integer.valueOf(line); - if(choose > 0 && choose <= 4){ + if(choose >=1 && choose <= PokerHelper.totalPrinters){ PokerHelper.pokerPrinterType = choose - 1; get(ClientEventCode.CODE_SHOW_OPTIONS).call(channel, data); } else { diff --git a/landlords-client/src/main/java/org/nico/ratel/landlords/client/event/ClientEventListener_CODE_SHOW_ROOMS.java b/landlords-client/src/main/java/org/nico/ratel/landlords/client/event/ClientEventListener_CODE_SHOW_ROOMS.java index 2e25119..eec061e 100644 --- a/landlords-client/src/main/java/org/nico/ratel/landlords/client/event/ClientEventListener_CODE_SHOW_ROOMS.java +++ b/landlords-client/src/main/java/org/nico/ratel/landlords/client/event/ClientEventListener_CODE_SHOW_ROOMS.java @@ -2,12 +2,9 @@ package org.nico.ratel.landlords.client.event; import java.util.List; import java.util.Map; -import java.util.Map.Entry; -import java.util.concurrent.ConcurrentSkipListMap; import org.nico.noson.Noson; import org.nico.noson.entity.NoType; -import org.nico.ratel.landlords.entity.Room; import org.nico.ratel.landlords.enums.ClientEventCode; import org.nico.ratel.landlords.print.SimplePrinter; diff --git a/landlords-common/src/main/java/org/nico/ratel/landlords/enums/SellType.java b/landlords-common/src/main/java/org/nico/ratel/landlords/enums/SellType.java index 5cf61d2..6d19efb 100644 --- a/landlords-common/src/main/java/org/nico/ratel/landlords/enums/SellType.java +++ b/landlords-common/src/main/java/org/nico/ratel/landlords/enums/SellType.java @@ -1,7 +1,5 @@ package org.nico.ratel.landlords.enums; -import java.io.Serializable; - public enum SellType { ILLEGAL("非合法"), diff --git a/landlords-server/src/main/java/org/nico/ratel/landlords/server/event/ServerEventListener.java b/landlords-server/src/main/java/org/nico/ratel/landlords/server/event/ServerEventListener.java index d2b45af..9c0c58b 100644 --- a/landlords-server/src/main/java/org/nico/ratel/landlords/server/event/ServerEventListener.java +++ b/landlords-server/src/main/java/org/nico/ratel/landlords/server/event/ServerEventListener.java @@ -1,5 +1,6 @@ package org.nico.ratel.landlords.server.event; +import java.lang.reflect.InvocationTargetException; import java.util.HashMap; import java.util.Map; @@ -22,7 +23,11 @@ public interface ServerEventListener { }else{ String eventListener = LISTENER_PREFIX + code.name(); Class listenerClass = (Class) Class.forName(eventListener); - listener = listenerClass.newInstance(); + try { + listener = listenerClass.getDeclaredConstructor().newInstance(); + } catch (InvocationTargetException | NoSuchMethodException e) { + e.printStackTrace(); + } ServerEventListener.LISTENER_MAP.put(code, listener); } return listener; diff --git a/landlords-server/src/main/java/org/nico/ratel/landlords/server/event/ServerEventListener_CODE_GAME_LANDLORD_ELECT.java b/landlords-server/src/main/java/org/nico/ratel/landlords/server/event/ServerEventListener_CODE_GAME_LANDLORD_ELECT.java index 22979cc..dae4a8f 100644 --- a/landlords-server/src/main/java/org/nico/ratel/landlords/server/event/ServerEventListener_CODE_GAME_LANDLORD_ELECT.java +++ b/landlords-server/src/main/java/org/nico/ratel/landlords/server/event/ServerEventListener_CODE_GAME_LANDLORD_ELECT.java @@ -1,8 +1,5 @@ package org.nico.ratel.landlords.server.event; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; import org.nico.ratel.landlords.channel.ChannelUtils; import org.nico.ratel.landlords.entity.ClientSide; @@ -10,7 +7,6 @@ import org.nico.ratel.landlords.entity.Room; import org.nico.ratel.landlords.enums.ClientEventCode; import org.nico.ratel.landlords.enums.ClientRole; import org.nico.ratel.landlords.enums.ClientType; -import org.nico.ratel.landlords.enums.RoomType; import org.nico.ratel.landlords.enums.ServerEventCode; import org.nico.ratel.landlords.helper.MapHelper; import org.nico.ratel.landlords.helper.PokerHelper; diff --git a/landlords-server/src/main/java/org/nico/ratel/landlords/server/event/ServerEventListener_CODE_GAME_POKER_PLAY_REDIRECT.java b/landlords-server/src/main/java/org/nico/ratel/landlords/server/event/ServerEventListener_CODE_GAME_POKER_PLAY_REDIRECT.java index 60729fe..843a8b6 100644 --- a/landlords-server/src/main/java/org/nico/ratel/landlords/server/event/ServerEventListener_CODE_GAME_POKER_PLAY_REDIRECT.java +++ b/landlords-server/src/main/java/org/nico/ratel/landlords/server/event/ServerEventListener_CODE_GAME_POKER_PLAY_REDIRECT.java @@ -9,7 +9,6 @@ import org.nico.ratel.landlords.entity.ClientSide; import org.nico.ratel.landlords.entity.Room; import org.nico.ratel.landlords.enums.ClientEventCode; import org.nico.ratel.landlords.helper.MapHelper; -import org.nico.ratel.landlords.helper.PokerHelper; import org.nico.ratel.landlords.server.ServerContains; public class ServerEventListener_CODE_GAME_POKER_PLAY_REDIRECT implements ServerEventListener{ diff --git a/landlords-server/src/main/java/org/nico/ratel/landlords/server/event/ServerEventListener_CODE_GAME_STARTING.java b/landlords-server/src/main/java/org/nico/ratel/landlords/server/event/ServerEventListener_CODE_GAME_STARTING.java index 9df0e6d..c31cb3b 100644 --- a/landlords-server/src/main/java/org/nico/ratel/landlords/server/event/ServerEventListener_CODE_GAME_STARTING.java +++ b/landlords-server/src/main/java/org/nico/ratel/landlords/server/event/ServerEventListener_CODE_GAME_STARTING.java @@ -11,7 +11,6 @@ import org.nico.ratel.landlords.enums.ClientEventCode; import org.nico.ratel.landlords.enums.ClientRole; import org.nico.ratel.landlords.enums.ClientType; import org.nico.ratel.landlords.enums.RoomStatus; -import org.nico.ratel.landlords.enums.RoomType; import org.nico.ratel.landlords.helper.MapHelper; import org.nico.ratel.landlords.helper.PokerHelper; import org.nico.ratel.landlords.server.ServerContains; diff --git a/landlords-server/src/main/java/org/nico/ratel/landlords/server/event/ServerEventListener_CODE_ROOM_JOIN.java b/landlords-server/src/main/java/org/nico/ratel/landlords/server/event/ServerEventListener_CODE_ROOM_JOIN.java index ffc183b..8b4ce0e 100644 --- a/landlords-server/src/main/java/org/nico/ratel/landlords/server/event/ServerEventListener_CODE_ROOM_JOIN.java +++ b/landlords-server/src/main/java/org/nico/ratel/landlords/server/event/ServerEventListener_CODE_ROOM_JOIN.java @@ -3,7 +3,6 @@ package org.nico.ratel.landlords.server.event; import java.util.LinkedList; import java.util.concurrent.ConcurrentSkipListMap; -import org.nico.noson.Noson; import org.nico.ratel.landlords.channel.ChannelUtils; import org.nico.ratel.landlords.entity.ClientSide; import org.nico.ratel.landlords.entity.Room; diff --git a/landlords-server/src/main/java/org/nico/ratel/landlords/server/robot/RobotEventListener.java b/landlords-server/src/main/java/org/nico/ratel/landlords/server/robot/RobotEventListener.java index 0852293..8c3ffe3 100644 --- a/landlords-server/src/main/java/org/nico/ratel/landlords/server/robot/RobotEventListener.java +++ b/landlords-server/src/main/java/org/nico/ratel/landlords/server/robot/RobotEventListener.java @@ -1,5 +1,6 @@ package org.nico.ratel.landlords.server.robot; +import java.lang.reflect.InvocationTargetException; import java.util.HashMap; import java.util.Map; @@ -13,7 +14,7 @@ public interface RobotEventListener { public final static Map LISTENER_MAP = new HashMap<>(); public void call(ClientSide robot, String data); - + public static RobotEventListener get(ClientEventCode code) { RobotEventListener listener = null; try { @@ -22,7 +23,11 @@ public interface RobotEventListener { }else{ String eventListener = LISTENER_PREFIX + code.name(); Class listenerClass = (Class) Class.forName(eventListener); - listener = listenerClass.newInstance(); + try { + listener = listenerClass.getDeclaredConstructor().newInstance(); + } catch (NoSuchMethodException | InvocationTargetException e) { + e.printStackTrace(); + } RobotEventListener.LISTENER_MAP.put(code, listener); } return listener;