-
Notifications
You must be signed in to change notification settings - Fork 219
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
1 parent
a6bd4a4
commit eca3963
Showing
47 changed files
with
2,348 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>com.andrei1058.bedwars.common</groupId> | ||
<artifactId>bedwars-common</artifactId> | ||
<version>23.10.1-SNAPSHOT</version> | ||
</parent> | ||
|
||
<groupId>com.andrei1058.bedwars.common.api</groupId> | ||
<artifactId>bedwars-common-api</artifactId> | ||
|
||
<properties> | ||
<maven.compiler.source>11</maven.compiler.source> | ||
<maven.compiler.target>11</maven.compiler.target> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
</properties> | ||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<configuration> | ||
<source>14</source> | ||
<target>14</target> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
</project> |
22 changes: 22 additions & 0 deletions
22
...on/bedwars-common-api/src/main/java/dev/andrei1058/bedwars/common/api/CommonProvider.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 |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/* | ||
* BedWars1058 - A bed wars mini-game. | ||
* Copyright (C) 2023 Andrei Dascălu | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program 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 General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package dev.andrei1058.bedwars.common.api; | ||
|
||
public interface CommonProvider { | ||
} |
109 changes: 109 additions & 0 deletions
109
...rs-common-api/src/main/java/dev/andrei1058/bedwars/common/api/arena/DisplayableArena.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 |
---|---|---|
@@ -0,0 +1,109 @@ | ||
package dev.andrei1058.bedwars.common.api.arena; | ||
|
||
import org.bukkit.entity.Player; | ||
import org.bukkit.inventory.ItemStack; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
import java.time.Instant; | ||
import java.util.UUID; | ||
|
||
public interface DisplayableArena { | ||
|
||
UUID getGameId(); | ||
|
||
GameState getGameState(); | ||
|
||
boolean isFull(); | ||
|
||
String getSpectatePermission(); | ||
|
||
// todo language based where null is default server language | ||
String getDisplayName(); | ||
|
||
int getMaxPlayers(); | ||
|
||
int getMinPlayers(); | ||
|
||
int getCurrentPlayers(); | ||
|
||
int getCurrentSpectators(); | ||
|
||
int getCurrentVips(); | ||
|
||
/** | ||
* World template used for this game instance. | ||
* | ||
* @return | ||
*/ | ||
String getTemplate(); | ||
|
||
@Nullable Instant getStartTime(); | ||
|
||
boolean isPrivateGame(); | ||
|
||
void setPrivateGame(); | ||
|
||
void setHost(UUID playerHost); | ||
|
||
@Nullable UUID getPlayerHost(); | ||
|
||
String getGroup(); | ||
|
||
void setGroup(); | ||
|
||
/** | ||
* Add a player to the game as a Player. | ||
* This must be used only on WAITING or STARTING states. | ||
* Will return false if player is already in a game. | ||
* | ||
* @param player user to be added. | ||
* @param ignoreParty if it does not matter if he is the party owner. | ||
* @return true if added to the game session. | ||
*/ | ||
boolean joinPlayer(Player player, boolean ignoreParty); | ||
|
||
/** | ||
* Add a player to the game as a Spectator. | ||
* @param player user to be added. | ||
* @param target spectating target (UUID). Null for no spectating target. | ||
* @param byPass to be defined. | ||
* @return true if added as spectator successfully. | ||
*/ | ||
boolean joinSpectator(Player player, @Nullable String target, boolean byPass); | ||
|
||
/** | ||
* Add a player to the game as a Spectator. | ||
* @param player user to be added. | ||
* @param target spectating target (UUID). Null for no spectating target. | ||
* @return true if added as spectator successfully. | ||
*/ | ||
default boolean joinSpectator(Player player, @Nullable String target) { | ||
return joinSpectator(player, target, false); | ||
} | ||
|
||
/** | ||
* Add a player to the game as a Spectator. | ||
* @param player user to be added. | ||
* @return true if added as spectator successfully. | ||
*/ | ||
default boolean joinSpectator(Player player) { | ||
return joinSpectator(player, null, false); | ||
} | ||
|
||
default int compareTo(@NotNull DisplayableArena other) { | ||
if (other.getGameState() == GameState.STARTING && getGameState() == GameState.STOPPING) { | ||
return Integer.compare(other.getCurrentPlayers(), getCurrentPlayers()); | ||
} | ||
|
||
return Integer.compare(other.getGameState().getWeight(), getGameState().getWeight()); | ||
} | ||
|
||
// todo provide language, null for server default | ||
ItemStack getDisplayItem(); | ||
|
||
/** | ||
* If arena is hosted on this server instance. | ||
*/ | ||
boolean isLocal(); | ||
} |
72 changes: 72 additions & 0 deletions
72
...n/bedwars-common-api/src/main/java/dev/andrei1058/bedwars/common/api/arena/GameState.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 |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/* | ||
* BedWars1058 - A bed wars mini-game. | ||
* Copyright (C) 2023 Andrei Dascălu | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program 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 General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package dev.andrei1058.bedwars.common.api.arena; | ||
|
||
import lombok.Getter; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.util.Arrays; | ||
import java.util.Optional; | ||
|
||
@Getter | ||
public enum GameState { | ||
|
||
LOADING(0), | ||
WAITING(1), | ||
STARTING(2), | ||
IN_GAME(3), | ||
CELEBRATING(4), | ||
STOPPING(5); | ||
|
||
/** | ||
* State code. | ||
* Used for game state comparison. | ||
* When adding new game states make sure to respect the sequence. | ||
*/ | ||
private final int weight; | ||
|
||
GameState(int stateCode) { | ||
this.weight = stateCode; | ||
} | ||
|
||
/** | ||
* Get status by code. | ||
* @return Optional game state. | ||
*/ | ||
public static @NotNull Optional<GameState> getByWeight(int weight) { | ||
return Arrays.stream(values()).filter(status -> status.weight == weight).findFirst(); | ||
} | ||
|
||
/** | ||
* Get game state by slug. | ||
* Can be used to parse configuration into objects. | ||
*/ | ||
public static Optional<GameState> getBySlug(@NotNull String slug) { | ||
|
||
return switch (slug.toLowerCase()) { | ||
case "loading", "l", "enabling" -> Optional.of(LOADING); | ||
case "waiting", "w", "wait", "lobby" -> Optional.of(WAITING); | ||
case "starting", "s", "start" -> Optional.of(STARTING); | ||
case "in_game", "in game", "started", "ig", "g", "playing", "p" -> Optional.of(IN_GAME); | ||
case "celebrating", "celebrate", "c", "finishing", "ending", "closing" -> Optional.of(CELEBRATING); | ||
case "saving", "done", "stopping" -> Optional.of(STOPPING); | ||
default -> Optional.empty(); | ||
}; | ||
} | ||
} |
101 changes: 101 additions & 0 deletions
101
...-common-api/src/main/java/dev/andrei1058/bedwars/common/api/database/DatabaseAdapter.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 |
---|---|---|
@@ -0,0 +1,101 @@ | ||
/* | ||
* BedWars1058 - A bed wars mini-game. | ||
* Copyright (C) 2023 Andrei Dascălu | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program 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 General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package dev.andrei1058.bedwars.common.api.database; | ||
|
||
import com.google.gson.JsonArray; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
import java.util.UUID; | ||
|
||
public interface DatabaseAdapter { | ||
|
||
/** | ||
* Called when this adapter needs to be disabled because the server is stopping | ||
* or because it is being replaced with a new adapter. | ||
*/ | ||
void disable(); | ||
|
||
/** | ||
* Create stats table if not exists. | ||
*/ | ||
void initStatsTable(); | ||
|
||
/** | ||
* Create player language preference table if not exists. | ||
*/ | ||
void initLocaleTable(); | ||
|
||
/** | ||
* Create private games table. | ||
*/ | ||
void initPrivateGamesTable(); | ||
|
||
/** | ||
* Get player's stats. | ||
* @param player target user. | ||
* @return stats object. | ||
*/ | ||
@Nullable | ||
PlayerStats getPlayerStats(UUID player); | ||
|
||
/** | ||
* Save player stats to your data source. | ||
* @param playerStats cached stats from the server. | ||
*/ | ||
void savePlayerStats(PlayerStats playerStats); | ||
|
||
/** | ||
* Retrieve player language. | ||
* @param player given user. | ||
* @return iso code. | ||
*/ | ||
@Nullable | ||
String getPlayerLocale(UUID player); | ||
|
||
/** | ||
* Save language selection to db. | ||
* @param player target. | ||
* @param iso language code. | ||
*/ | ||
void savePlayerLocale(UUID player, @Nullable String iso); | ||
|
||
/** | ||
* Check if the given player has an active private games session. | ||
* Works in combination with parties. | ||
*/ | ||
boolean hasActivePrivateGames(UUID player); | ||
|
||
/** | ||
* Toggle private games for a player. | ||
*/ | ||
void setActivePrivateGames(UUID player, boolean toggle); | ||
|
||
/** | ||
* Get private games settings for the given player. | ||
* Newly added settings will be added to the list in the manager. | ||
* <p> | ||
* Can be null. List (that can be empty) if active; | ||
*/ | ||
@Nullable JsonArray getPrivateGamesSettings(UUID player) throws IllegalAccessException; | ||
|
||
/** | ||
* Save replace current settings to db. | ||
*/ | ||
void setPrivateGamesSettings(UUID player, JsonArray settingList); | ||
} |
37 changes: 37 additions & 0 deletions
37
...-common-api/src/main/java/dev/andrei1058/bedwars/common/api/database/DatabaseHandler.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 |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* BedWars1058 - A bed wars mini-game. | ||
* Copyright (C) 2023 Andrei Dascălu | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program 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 General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package dev.andrei1058.bedwars.common.api.database; | ||
|
||
import org.jetbrains.annotations.Nullable; | ||
|
||
import java.io.File; | ||
|
||
public interface DatabaseHandler { | ||
DatabaseAdapter getDatabase(); | ||
|
||
/** | ||
* Null to restore to server's default. | ||
*/ | ||
boolean setDatabaseAdapter(@Nullable DatabaseAdapter adapter); | ||
|
||
/** | ||
* Get the folder that contains the database yml configuration file. | ||
*/ | ||
File getDatabaseConfigurationPath(); | ||
} |
Oops, something went wrong.