add Minigame project
This commit is contained in:
5
minigame/build.gradle
Normal file
5
minigame/build.gradle
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
dependencies {
|
||||||
|
implementation project(':tools')
|
||||||
|
|
||||||
|
compileOnly libs.bukkit
|
||||||
|
}
|
||||||
2
minigame/gradle.properties
Normal file
2
minigame/gradle.properties
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
moduleName=ghast-mg
|
||||||
|
moduleVersion=1.0-SNAPSHOT
|
||||||
29
minigame/src/main/java/ghast/mg/Game.java
Normal file
29
minigame/src/main/java/ghast/mg/Game.java
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
package ghast.mg;
|
||||||
|
|
||||||
|
import com.google.common.collect.Maps;
|
||||||
|
import ghast.mg.stage.GameStage;
|
||||||
|
import ghast.mg.stage.StageContext;
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public abstract class Game {
|
||||||
|
|
||||||
|
private final Map<GameStage, StageContext> stageMap = Maps.newHashMap();
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
private GameStage stage;
|
||||||
|
|
||||||
|
public StageContext setupStage(GameStage stage) {
|
||||||
|
return stageMap.computeIfAbsent(stage, stage1 -> new StageContext(this, stage1));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void changeStage(GameStage nextStage) {
|
||||||
|
StageContext stageContext = stageMap.get(nextStage);
|
||||||
|
if (stageContext != null && stageContext.getScenario() != null) {
|
||||||
|
stageContext.getScenario().run();
|
||||||
|
}
|
||||||
|
|
||||||
|
this.stage = nextStage;
|
||||||
|
}
|
||||||
|
}
|
||||||
5
minigame/src/main/java/ghast/mg/stage/GameStage.java
Normal file
5
minigame/src/main/java/ghast/mg/stage/GameStage.java
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
package ghast.mg.stage;
|
||||||
|
|
||||||
|
public interface GameStage {
|
||||||
|
|
||||||
|
}
|
||||||
47
minigame/src/main/java/ghast/mg/stage/StageContext.java
Normal file
47
minigame/src/main/java/ghast/mg/stage/StageContext.java
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
package ghast.mg.stage;
|
||||||
|
|
||||||
|
import ghast.EventContext;
|
||||||
|
import ghast.mg.Game;
|
||||||
|
import lombok.Getter;
|
||||||
|
import org.bukkit.event.Cancellable;
|
||||||
|
import org.bukkit.event.Event;
|
||||||
|
import org.bukkit.event.EventPriority;
|
||||||
|
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
|
public class StageContext {
|
||||||
|
|
||||||
|
private final EventContext eventContext;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
private Runnable scenario;
|
||||||
|
|
||||||
|
public StageContext(Game gameInstance, GameStage stage) {
|
||||||
|
eventContext = EventContext.create();
|
||||||
|
eventContext.filter(() -> gameInstance.getStage() == (stage));
|
||||||
|
}
|
||||||
|
|
||||||
|
public StageContext onSetStage(Runnable scenario) {
|
||||||
|
this.scenario = scenario;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public <T extends Event> StageContext onEvent(Class<T> eventType, EventPriority eventPriority, Consumer<T> consumer) {
|
||||||
|
eventContext.onEvent(eventType, eventPriority, consumer);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public <T extends Event> StageContext onEvent(Class<T> eventType, Consumer<T> consumer) {
|
||||||
|
return onEvent(eventType, EventPriority.NORMAL, consumer);
|
||||||
|
}
|
||||||
|
|
||||||
|
public <T extends Event & Cancellable> StageContext cancelEvent(Class<T> eventType, EventPriority eventPriority) {
|
||||||
|
eventContext.cancelEvent(eventType, eventPriority);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public <T extends Event & Cancellable> StageContext cancelEvent(Class<T> eventType) {
|
||||||
|
eventContext.cancelEvent(eventType);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
}
|
||||||
19
minigame/src/main/java/ghast/mg/stage/StandartGameStage.java
Normal file
19
minigame/src/main/java/ghast/mg/stage/StandartGameStage.java
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
package ghast.mg.stage;
|
||||||
|
|
||||||
|
public enum StandartGameStage implements GameStage {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ожидание новой игровой сессии.
|
||||||
|
*/
|
||||||
|
WAIT_NEW_GAME,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Начало игровой сессии.
|
||||||
|
*/
|
||||||
|
START_GAME,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Завершение игровой сессии.
|
||||||
|
*/
|
||||||
|
END_GAME
|
||||||
|
}
|
||||||
@@ -1,2 +1,3 @@
|
|||||||
include 'tools'
|
include 'tools'
|
||||||
|
include 'minigame'
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user