Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
andrei1058 committed Dec 1, 2023
1 parent a6bd4a4 commit eca3963
Show file tree
Hide file tree
Showing 47 changed files with 2,348 additions and 0 deletions.
33 changes: 33 additions & 0 deletions bedwars-common/bedwars-common-api/pom.xml
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>
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 {
}
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();
}
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();
};
}
}
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);
}
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();
}
Loading

0 comments on commit eca3963

Please sign in to comment.