Первые намётки событийной модели
This commit is contained in:
@@ -24,15 +24,15 @@ public enum ChatStyle {
|
||||
YELLOW('e'),
|
||||
WHITE ('f');
|
||||
|
||||
private static final char COLOR_CHAR = '\u00a7'; // §
|
||||
public static final char SPECIAL_CHAR = '\u00a7'; // §
|
||||
private static final String codes = "0123456789aAbBcCdDeEfF";
|
||||
private static final Pattern EXCAPE_PATTERN = Pattern.compile(COLOR_CHAR + "[0-9a-f]", Pattern.CASE_INSENSITIVE);
|
||||
private static final Pattern EXCAPE_PATTERN = Pattern.compile(SPECIAL_CHAR + "[0-9a-f]", Pattern.CASE_INSENSITIVE);
|
||||
|
||||
public static String format(char colorChar, String message) {
|
||||
char[] chars = message.toCharArray();
|
||||
for (int i = 0; i < chars.length; i++) {
|
||||
if (chars[i] == colorChar && codes.indexOf(chars[i+1]) > -1) {
|
||||
chars[i] = COLOR_CHAR;
|
||||
chars[i] = SPECIAL_CHAR;
|
||||
chars[i+1] = Character.toLowerCase(chars[i+1]);
|
||||
i++;
|
||||
}
|
||||
@@ -48,7 +48,7 @@ public enum ChatStyle {
|
||||
private char[] toString;
|
||||
|
||||
ChatStyle(char ch) {
|
||||
toString = new char[]{ COLOR_CHAR, ch };
|
||||
toString = new char[]{SPECIAL_CHAR, ch };
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -15,5 +15,6 @@ public interface PlayerManager {
|
||||
void leftServer(Player player);
|
||||
Optional<Player> getPlayer(String name);
|
||||
List<Player> getPlayers();
|
||||
int getCountOnlinePlayers();
|
||||
NetChannel getBroadcastChannel();
|
||||
}
|
||||
|
||||
@@ -66,6 +66,11 @@ public class InMemoryPlayerManager implements PlayerManager, Runnable {
|
||||
return players.stream().filter(Player::isOnline).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCountOnlinePlayers() {
|
||||
return players.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public NetChannel getBroadcastChannel() {
|
||||
return new BroadcastNetChannel(players.stream().filter(Player::isOnline));
|
||||
|
||||
13
core/src/main/java/mc/core/events/Event.java
Normal file
13
core/src/main/java/mc/core/events/Event.java
Normal file
@@ -0,0 +1,13 @@
|
||||
/*
|
||||
* DmitriyMX <dimon550@gmail.com>
|
||||
* 2018-05-02
|
||||
*/
|
||||
package mc.core.events;
|
||||
|
||||
public interface Event {
|
||||
void setCanceled(boolean value);
|
||||
boolean isCanceled();
|
||||
|
||||
void setLastProcess(boolean value);
|
||||
boolean isLastProcess();
|
||||
}
|
||||
17
core/src/main/java/mc/core/events/EventBase.java
Normal file
17
core/src/main/java/mc/core/events/EventBase.java
Normal file
@@ -0,0 +1,17 @@
|
||||
/*
|
||||
* DmitriyMX <dimon550@gmail.com>
|
||||
* 2018-05-02
|
||||
*/
|
||||
package mc.core.events;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
public abstract class EventBase implements Event {
|
||||
@Getter
|
||||
@Setter
|
||||
private boolean canceled;
|
||||
@Getter
|
||||
@Setter
|
||||
private boolean lastProcess;
|
||||
}
|
||||
14
core/src/main/java/mc/core/events/EventBusGetter.java
Normal file
14
core/src/main/java/mc/core/events/EventBusGetter.java
Normal file
@@ -0,0 +1,14 @@
|
||||
/*
|
||||
* DmitriyMX <dimon550@gmail.com>
|
||||
* 2018-05-02
|
||||
*/
|
||||
package mc.core.events;
|
||||
|
||||
import com.google.common.eventbus.EventBus;
|
||||
|
||||
public final class EventBusGetter {
|
||||
public static final EventBus INSTANCE = new EventBus();
|
||||
|
||||
private EventBusGetter() {
|
||||
}
|
||||
}
|
||||
21
core/src/main/java/mc/core/events/LoginEvent.java
Normal file
21
core/src/main/java/mc/core/events/LoginEvent.java
Normal file
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
* DmitriyMX <dimon550@gmail.com>
|
||||
* 2018-05-02
|
||||
*/
|
||||
package mc.core.events;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.net.SocketAddress;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
@Getter
|
||||
@Setter
|
||||
public class LoginEvent extends EventBase {
|
||||
private String playerName;
|
||||
private final SocketAddress remoteAddress;
|
||||
private boolean deny;
|
||||
private String denyReason;
|
||||
}
|
||||
19
core/src/main/java/mc/core/events/PlayerLookEvent.java
Normal file
19
core/src/main/java/mc/core/events/PlayerLookEvent.java
Normal file
@@ -0,0 +1,19 @@
|
||||
/*
|
||||
* DmitriyMX <dimon550@gmail.com>
|
||||
* 2018-05-02
|
||||
*/
|
||||
package mc.core.events;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.Setter;
|
||||
import mc.core.Look;
|
||||
import mc.core.Player;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
@Getter
|
||||
@Setter
|
||||
public class PlayerLookEvent extends EventBase {
|
||||
private final Player player;
|
||||
private Look newLook;
|
||||
}
|
||||
19
core/src/main/java/mc/core/events/PlayerPositionEvent.java
Normal file
19
core/src/main/java/mc/core/events/PlayerPositionEvent.java
Normal file
@@ -0,0 +1,19 @@
|
||||
/*
|
||||
* DmitriyMX <dimon550@gmail.com>
|
||||
* 2018-05-02
|
||||
*/
|
||||
package mc.core.events;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.Setter;
|
||||
import mc.core.Location;
|
||||
import mc.core.Player;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
@Getter
|
||||
@Setter
|
||||
public class PlayerPositionEvent extends EventBase {
|
||||
private final Player player;
|
||||
private Location newPosition;
|
||||
}
|
||||
21
core/src/main/java/mc/core/events/ServerPingEvent.java
Normal file
21
core/src/main/java/mc/core/events/ServerPingEvent.java
Normal file
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
* DmitriyMX <dimon550@gmail.com>
|
||||
* 2018-05-02
|
||||
*/
|
||||
package mc.core.events;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.net.SocketAddress;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
@Getter
|
||||
@Setter
|
||||
public class ServerPingEvent extends EventBase {
|
||||
private final SocketAddress remoteAddress;
|
||||
private String description;
|
||||
private int online;
|
||||
private int maxOnline;
|
||||
}
|
||||
Reference in New Issue
Block a user