diff --git a/src/main/java/cc/sfclub/game/api/event/GameStateSwitched.java b/src/main/java/cc/sfclub/game/api/event/GameStateSwitched.java new file mode 100644 index 0000000..1842421 --- /dev/null +++ b/src/main/java/cc/sfclub/game/api/event/GameStateSwitched.java @@ -0,0 +1,50 @@ +/* + * + * Oyster - The universal minigame framework for spigot servers. + * Copyright (C) 2021 SaltedFish Club + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 + * USA + */ + +package cc.sfclub.game.api.event; + +import cc.sfclub.game.module.game.OysterGame; +import cc.sfclub.game.module.game.State; +import lombok.Getter; +import org.bukkit.event.HandlerList; +import org.jetbrains.annotations.ApiStatus; +import org.jetbrains.annotations.NotNull; + +@ApiStatus.AvailableSince("0.1.0") +public class GameStateSwitched extends OysterEvent { + private final HandlerList handlerList = new HandlerList(); + @Getter + private final State originalState; + @Getter + private final State nextState; + + public GameStateSwitched(OysterGame game, State origin, State next) { + super(game); + this.originalState = origin; + this.nextState = next; + } + + @NotNull + @Override + public HandlerList getHandlers() { + return handlerList; + } +} diff --git a/src/main/java/cc/sfclub/game/api/event/OysterEvent.java b/src/main/java/cc/sfclub/game/api/event/OysterEvent.java new file mode 100644 index 0000000..abdda41 --- /dev/null +++ b/src/main/java/cc/sfclub/game/api/event/OysterEvent.java @@ -0,0 +1,40 @@ +/* + * + * Oyster - The universal minigame framework for spigot servers. + * Copyright (C) 2021 SaltedFish Club + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 + * USA + */ + +package cc.sfclub.game.api.event; + +import cc.sfclub.game.module.game.OysterGame; +import lombok.RequiredArgsConstructor; +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; +import org.jetbrains.annotations.NotNull; + +@RequiredArgsConstructor +public class OysterEvent extends Event { + private final HandlerList handlerList = new HandlerList(); + private final OysterGame game; + + @NotNull + @Override + public HandlerList getHandlers() { + return handlerList; + } +} diff --git a/src/main/java/cc/sfclub/game/mechanic/GameEvent.java b/src/main/java/cc/sfclub/game/mechanic/GameEvent.java index 32aafdd..b146fad 100644 --- a/src/main/java/cc/sfclub/game/mechanic/GameEvent.java +++ b/src/main/java/cc/sfclub/game/mechanic/GameEvent.java @@ -23,12 +23,13 @@ import lombok.AllArgsConstructor; import lombok.Getter; +import org.bukkit.event.Event; import org.jetbrains.annotations.ApiStatus; @Getter @AllArgsConstructor @ApiStatus.AvailableSince("0.1.0") -public abstract class GameEvent { +public abstract class GameEvent extends Event { private final Scope scope; public enum Scope { diff --git a/src/main/java/cc/sfclub/game/module/game/OysterGame.java b/src/main/java/cc/sfclub/game/module/game/OysterGame.java index e9ffca9..9e4524d 100644 --- a/src/main/java/cc/sfclub/game/module/game/OysterGame.java +++ b/src/main/java/cc/sfclub/game/module/game/OysterGame.java @@ -21,6 +21,7 @@ package cc.sfclub.game.module.game; +import cc.sfclub.game.api.event.GameStateSwitched; import cc.sfclub.game.mechanic.Flaggable; import cc.sfclub.game.mechanic.GameEvent; import cc.sfclub.game.module.flag.Flag; @@ -28,9 +29,11 @@ import cc.sfclub.game.module.game.region.GameScope; import cc.sfclub.game.module.player.OysterPlayer; import cc.sfclub.game.module.player.team.OysterTeam; +import lombok.AccessLevel; import lombok.Builder; import lombok.Getter; import lombok.NonNull; +import org.bukkit.Bukkit; import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.Nullable; @@ -38,15 +41,17 @@ import java.util.stream.Collectors; @ApiStatus.AvailableSince("0.1.0") -@Builder +@Builder(access = AccessLevel.PRIVATE) public class OysterGame extends GameMechanic implements Flaggable { - private final State state; + private final String name; @Builder.Default @Getter private final GameScope scope = new AnywhereScope(); @Builder.Default @Getter private final List players = new ArrayList<>(); + @Getter + private State state; @Builder.Default @Getter @@ -63,6 +68,10 @@ public class OysterGame extends GameMechanic implements Flaggable { @Builder.Default private final GameMechanic mechanic = new EmptyGameMechanic(); + { + // TODO: 10/08/2021 Register itself into OysterGameManager + } + public T getStateAs(Class t) { return t.cast(state); } @@ -87,6 +96,11 @@ public void removeFlag(Flag flag) { rules.remove(flag); } + public void switchState(State newState) { + Bukkit.getPluginManager().callEvent(new GameStateSwitched(this, this.state, newState)); + this.state = newState; + } + @Override public boolean addFlag(Flag flag) { return rules.add(flag); diff --git a/src/main/java/cc/sfclub/game/module/game/region/GameScope.java b/src/main/java/cc/sfclub/game/module/game/region/GameScope.java index 934a177..d5e0b60 100644 --- a/src/main/java/cc/sfclub/game/module/game/region/GameScope.java +++ b/src/main/java/cc/sfclub/game/module/game/region/GameScope.java @@ -29,4 +29,5 @@ public interface GameScope { Location getWarp(String warpName); void setWarp(String warpName, Location location); + } diff --git a/src/main/java/cc/sfclub/game/module/game/region/Warps.java b/src/main/java/cc/sfclub/game/module/game/region/Warps.java new file mode 100644 index 0000000..4afe134 --- /dev/null +++ b/src/main/java/cc/sfclub/game/module/game/region/Warps.java @@ -0,0 +1,30 @@ +/* + * + * Oyster - The universal minigame framework for spigot servers. + * Copyright (C) 2021 SaltedFish Club + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 + * USA + */ + +package cc.sfclub.game.module.game.region; + +public enum Warps { + SPAWN("SPAWN"), + LOBBY("LOBBY"); + + Warps(String warp) { + } +}