-
Notifications
You must be signed in to change notification settings - Fork 101
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Evan Hu
committed
Feb 17, 2021
1 parent
8c44681
commit 83b4d70
Showing
9 changed files
with
65 additions
and
103 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 0 additions & 42 deletions
42
game-server/src/main/java/info/xiaomo/server/StopServerClient.java
This file was deleted.
Oops, something went wrong.
71 changes: 35 additions & 36 deletions
71
game-server/src/main/java/info/xiaomo/server/event/EventUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,52 @@ | ||
package info.xiaomo.server.event; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
/** | ||
* 由于事件都是预先注册好的,所以这里不考虑多线程问题,不允许在游戏运行过成中动态添加观察者 | ||
* | ||
* @author 张力 | ||
* @date 2014-12-6 上午11:19:00 | ||
* 2014-12-6 上午11:19:00 | ||
*/ | ||
public class EventUtil { | ||
|
||
/** | ||
* 游戏启动就初始化的监听者列表 | ||
*/ | ||
private final static Map<EventType, List<IEventListener>> PREPARED_LISTENERS = new HashMap<>(10); | ||
|
||
/** | ||
* 游戏运行中动态添加的监听者列表 | ||
*/ | ||
private final static Logger LOGGER = LoggerFactory.getLogger(EventUtil.class); | ||
|
||
static void addListener(IEventListener listener, EventType type) { | ||
List<IEventListener> listenerList = PREPARED_LISTENERS.computeIfAbsent(type, k -> new ArrayList<>()); | ||
listenerList.add(listener); | ||
} | ||
|
||
public static void fireEvent(EventType type) { | ||
fireEvent(type, null); | ||
} | ||
|
||
public static void fireEvent(EventType type, Object obj) { | ||
|
||
List<IEventListener> listenerList = PREPARED_LISTENERS.get(type); | ||
if (listenerList != null) { | ||
for (IEventListener listener : listenerList) { | ||
try { | ||
listener.update(type, obj); | ||
} catch (Exception e) { | ||
LOGGER.error("事件执行错误", e); | ||
} | ||
} | ||
} | ||
} | ||
/** | ||
* 游戏启动就初始化的监听者列表 | ||
*/ | ||
private final static Map<EventType, List<IEventListener>> PREPARED_LISTENERS = new HashMap<>(10); | ||
|
||
/** | ||
* 游戏运行中动态添加的监听者列表 | ||
*/ | ||
private final static Logger LOGGER = LoggerFactory.getLogger(EventUtil.class); | ||
|
||
static void addListener(IEventListener listener, EventType type) { | ||
List<IEventListener> listenerList = PREPARED_LISTENERS.computeIfAbsent(type, k -> new ArrayList<>()); | ||
listenerList.add(listener); | ||
} | ||
|
||
public static void fireEvent(EventType type) { | ||
fireEvent(type, null); | ||
} | ||
|
||
public static void fireEvent(EventType type, Object obj) { | ||
|
||
List<IEventListener> listenerList = PREPARED_LISTENERS.get(type); | ||
if (listenerList != null) { | ||
for (IEventListener listener : listenerList) { | ||
try { | ||
listener.update(type, obj); | ||
} catch (Exception e) { | ||
LOGGER.error("事件执行错误", e); | ||
} | ||
} | ||
} | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters