Skip to content
This repository has been archived by the owner on Apr 27, 2024. It is now read-only.

Commit

Permalink
Add Warps
Browse files Browse the repository at this point in the history
Add GameStateSwitchEvent switchState()
  • Loading branch information
iceBear67 committed Aug 10, 2021
1 parent 8f67f5c commit d046a6d
Show file tree
Hide file tree
Showing 6 changed files with 139 additions and 3 deletions.
50 changes: 50 additions & 0 deletions src/main/java/cc/sfclub/game/api/event/GameStateSwitched.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
40 changes: 40 additions & 0 deletions src/main/java/cc/sfclub/game/api/event/OysterEvent.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
3 changes: 2 additions & 1 deletion src/main/java/cc/sfclub/game/mechanic/GameEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
18 changes: 16 additions & 2 deletions src/main/java/cc/sfclub/game/module/game/OysterGame.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,32 +21,37 @@

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;
import cc.sfclub.game.module.game.region.AnywhereScope;
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;

import java.util.*;
import java.util.stream.Collectors;

@ApiStatus.AvailableSince("0.1.0")
@Builder
@Builder(access = AccessLevel.PRIVATE)
public class OysterGame extends GameMechanic implements Flaggable<OysterGame> {
private final State state;
private final String name;
@Builder.Default
@Getter
private final GameScope scope = new AnywhereScope();
@Builder.Default
@Getter
private final List<OysterPlayer> players = new ArrayList<>();
@Getter
private State state;

@Builder.Default
@Getter
Expand All @@ -63,6 +68,10 @@ public class OysterGame extends GameMechanic implements Flaggable<OysterGame> {
@Builder.Default
private final GameMechanic mechanic = new EmptyGameMechanic();

{
// TODO: 10/08/2021 Register itself into OysterGameManager
}

public <T> T getStateAs(Class<T> t) {
return t.cast(state);
}
Expand All @@ -87,6 +96,11 @@ public void removeFlag(Flag<OysterGame> 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<OysterGame> flag) {
return rules.add(flag);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,5 @@ public interface GameScope {
Location getWarp(String warpName);

void setWarp(String warpName, Location location);

}
30 changes: 30 additions & 0 deletions src/main/java/cc/sfclub/game/module/game/region/Warps.java
Original file line number Diff line number Diff line change
@@ -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) {
}
}

0 comments on commit d046a6d

Please sign in to comment.