Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge game basics to Main #10

Draft
wants to merge 63 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
d5a3f4c
:sparkles: Add pegasus plugin main class
Xen0Xys Mar 15, 2024
d5c4142
:heavy_plus_sign: Add worldedit dependency
Xen0Xys Mar 15, 2024
bc9020c
:sparkles: Add schematic support for loading and pasting
Xen0Xys Mar 15, 2024
7dcef3f
:sparkles: Add relative location to get a location without depending …
Xen0Xys Mar 15, 2024
1954f1b
:sparkles: Add sample lobby schematic
Xen0Xys Mar 15, 2024
ea8beaa
:sparkles: Add generator for empty world
Xen0Xys Mar 15, 2024
954a794
:sparkles: Implement world creation
Xen0Xys Mar 15, 2024
52472af
:sparkles: Implement server and world management
Xen0Xys Mar 15, 2024
0e840d6
:memo: Add complete documentation
Xen0Xys Mar 15, 2024
f92449b
:wrench: Add options for game and instances
Xen0Xys Mar 16, 2024
219310f
:sparkles: Add PegasusPlayer to allow game start without connected users
Xen0Xys Mar 16, 2024
488962b
:sparkles: Implement team support
Xen0Xys Mar 16, 2024
4f3bbd9
:sparkles: Implement first instances support
Xen0Xys Mar 16, 2024
9746e84
:memo: Add samples for instances management
Xen0Xys Mar 16, 2024
0e2ac2c
:white_check_mark: Change main plugin class to allow better testing
Xen0Xys Mar 16, 2024
35e076f
:bug: Fix teleportation bug because of bad event priority
Xen0Xys Mar 16, 2024
2dde454
:spark: Implement Instance and game state and state change events
Xen0Xys Mar 20, 2024
ab1c78f
:sparkles: Implement instances countdown
Xen0Xys Mar 20, 2024
53c9c31
:test_tube: Add test instance schematic
Xen0Xys Mar 20, 2024
f6e357b
:sparkles: Add world time option with default value
Xen0Xys Mar 20, 2024
2f022a7
:bug: Fix PegasusPlayer usage in HashSet and HashMap by adding #equal…
Xen0Xys Mar 20, 2024
c615a65
:sparkles: Add default world time in lobby world
Xen0Xys Mar 20, 2024
0c449c6
:sparkles: Update sample codes with new features
Xen0Xys Mar 20, 2024
96841b8
:memo: Add documentation for InstancesManager
Xen0Xys Mar 20, 2024
07190f3
:memo: Add minor documentation for InstancesManager
Xen0Xys Mar 20, 2024
aa5c004
:memo: Add minor documentation for InstancesManager
Xen0Xys Mar 20, 2024
6a73108
Merge remote-tracking branch 'origin/feature/game-basics' into featur…
Xen0Xys Mar 20, 2024
b93293d
:art: Change player null check by isOnline instead of nullable getPlayer
Xen0Xys Mar 20, 2024
c2ba8c7
:sparkles: Add documentation and player reconnection management
Xen0Xys Mar 21, 2024
8137efc
:test_tube: Add tests for GameManager methods
Xen0Xys Mar 21, 2024
f08e424
:sparkles: Add a dispatcher to dispatch 2 list into a hashmap with 4 …
Xen0Xys Mar 21, 2024
92b798a
:sparkles: Add easy random utility
Xen0Xys Mar 21, 2024
565cbde
:sparkles: Implement a PlayerManager to manage instance players, spaw…
Xen0Xys Mar 21, 2024
70e53b1
:sparkles: Implement instance cleanup after the end of the game
Xen0Xys Mar 21, 2024
5138d8c
:art: Minor changes for GameManager creation method
Xen0Xys Mar 21, 2024
ff3cd07
:rocket: Update samples
Xen0Xys Mar 21, 2024
e992866
:memo: Add documentation for Countdown class
Xen0Xys Mar 21, 2024
618855a
:zap: Optimize imports
Xen0Xys Mar 21, 2024
bfca600
:memo: Add documentation for dispatcher
Xen0Xys Mar 21, 2024
e5e7b1b
:memo: Add documentation for PegasusPlayer
Xen0Xys Mar 21, 2024
0bbab4c
:memo: Add README.md with minimal usage information
Xen0Xys Mar 21, 2024
88fb137
:bug: Fix double instanciation bug
Xen0Xys Mar 21, 2024
33f453a
:art: Minor code refactor
Xen0Xys Mar 21, 2024
12d0089
:rocket: Add missing getter
Xen0Xys Mar 21, 2024
e10edad
:sparkles: Implement better handle for player disconnection and recon…
Xen0Xys Mar 21, 2024
f52eaf3
:rocket: Implement conditional lobby teleporting
Xen0Xys Mar 22, 2024
bfb0f99
:memo: Add missing documentation
Xen0Xys Mar 22, 2024
87e391c
:bug: Fix instance event unregistering
Xen0Xys Mar 22, 2024
792c6ee
:memo: Complete README.md with getting started part
Xen0Xys Mar 22, 2024
443d9f2
:sparkles: Change PlayerManager creation behavior, and add onTick met…
Xen0Xys Mar 22, 2024
0c52de5
:rocket: Add inventory clear when the game end
Xen0Xys Mar 22, 2024
1df56ce
:rocket: Change constructor and add setTeams method
Xen0Xys Mar 22, 2024
dc059a1
:white_check_mark: Add minor testing behavior for the sample instance
Xen0Xys Mar 22, 2024
7a9a7c1
:zap: Optimize code and imports
Xen0Xys Mar 22, 2024
c3d1c6d
:sparkles: Add announcer for future usage
Xen0Xys Mar 22, 2024
c786220
:rocket: Prevent spectator teleport for instance players and fix exis…
Xen0Xys Mar 22, 2024
e075d4c
:rocket: Add constructor with random seed and new method for random s…
Xen0Xys Mar 22, 2024
91631df
:white_check_mark: Improve fake team generation for multi-instances t…
Xen0Xys Mar 22, 2024
0f64d5a
:rocket: Add new constructor to get a PegasusPlayer from a Bukkit Player
Xen0Xys Mar 22, 2024
5a560f0
:rocket: Minor tweaks with testing purposes to sample plugin class
Xen0Xys Mar 22, 2024
b0df69c
:art: Improve code quality
Xen0Xys Mar 22, 2024
fe5e4d2
:art: Improve code quality and structure by adding announcer and more…
Xen0Xys Mar 22, 2024
4a93f88
:rocket: Add missing announceTitle method with string title and subtitle
Xen0Xys Mar 22, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
127 changes: 127 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
# Pegasus Framework

## Getting started

### Creating instance class

Start by creating an instance class **with this constructor**, and implementing all lifecycle methods.

All the instance logic goes on this class !

```java
public class SampleInstance extends Instance {
public SampleInstance(int id, JavaPlugin plugin, CommonOptions commonOptions, InstanceOptions instanceOptions, ScoreManager scoreManager) {
super(id, plugin, commonOptions, instanceOptions, scoreManager);
}
}
```

### Setting up instance behavior

#### Main plugin class

Make sure that your plugin extends of PegasusPlugin.

```java
public class GameSamplePlugin extends PegasusPlugin{
@Override
public void onEnable(){
super.onEnable();
// The initialization code goes here
}
}
```
#### Creating the game world

To create the game world, just create a new WorldBuilder, and set on it all the world options that you want !

After that, just call the ServerManager#addGameWorld(WorldBuilder) to get the newly created game world.

_Note : If the game world already exists, the given settings will overwrite the older._

```java
public class GameSamplePlugin extends PegasusPlugin{
@Override
public void onEnable(){
super.onEnable();
WorldBuilder gameWorldBuilder = new WorldBuilder("pegasus_sample");
gameWorldBuilder.setGameMode(GameMode.CREATIVE)
.setDifficulty(Difficulty.PEACEFUL)
.addGameRule(GameRule.DO_DAYLIGHT_CYCLE, false)
.addGameRule(GameRule.DO_WEATHER_CYCLE, false)
.setWorldTime(6000)
.addPrevention(WorldPreventions.ALL)
.addPrevention(WorldPreventions.PREVENT_PVP);
PegasusWorld gameWorld = this.getServerManager().addGameWorld(gameWorldBuilder);
}
}
```

#### Creating the game settings

Start by creating a new OptionsBuilder, and set all the settings you want.

_Note : Some settings are mandatory to the game be runnable!_

After that, you can get the GameManager by calling the ServerManager#createGameManager(DataManager, OptionsBuilder, ScoreManager) method.

```java
public class GameSamplePlugin extends PegasusPlugin{
@Override
public void onEnable(){
super.onEnable();
// Game world creation code...
OptionsBuilder optionsBuilder = new OptionsBuilder()
.setGameType(GameType.SOLO)
.setWorld(gameWorld)
.setInstanceClass(SampleInstance.class)
.setRoundDurations(List.of(20))
.setSpawnPoints(List.of(new RelativeLocation(0.5, 0, 0.5, 90, 0)))
.setSchematic(new Schematic(this, "instances_test", SchematicFlags.COPY_BIOMES))
.setPreAllocatedInstances(1);
gameManager = this.getServerManager().createGameManager(new SampleDataManager(), optionsBuilder, new SampleScoreManager());
}
}
```

#### Starting the game

To start the game, just call the GameManager#start() method.

## Lifecycles

### Instance lifecycle and behavior

| Instance state | Player game mode | Is player frozen |
|-------------------|------------------|------------------|
| CREATED | Not on instance | Not on instance |
| READY | SPECTATOR | NO |
| PRE_STARTED | SPECTATOR | NO |
| STARTED | SPECTATOR | NO |
| ROUND_PRE_STARTED | ADVENTURE | YES |
| ROUND_STARTED | SURVIVAL | NO |
| ROUND_ENDED | SPECTATOR | NO |
| ENDED | SPECTATOR | NO |
| CLOSED | Not on instance | Not on instance |

### Instances Manager lifecycle

| Instance Manager state | Changed when all instances are in state |
|------------------------|-----------------------------------------|
| READY | READY |
| STARTED | STARTED |
| ENDED | CLOSED |

### Game Manager lifecycle

| Game Manager state | Changed when... |
|--------------------|----------------------------------------------------------|
| CREATED | when new instance created |
| STARTED | when start method is called |
| ENDED | when stop method is called or Instances Manager is ENDED |

## How to get which data ?

### Instance
- Teams and players : Instance#getPlayerManager()
- Score : Instance#getScoreManager()
11 changes: 11 additions & 0 deletions pegasus-framework.iml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,15 @@
<excludeFolder url="file://$MODULE_DIR$/.idea/copilot/chatSessions" />
</content>
</component>
<component name="FacetManager">
<facet type="minecraft" name="Minecraft">
<configuration>
<autoDetectTypes>
<platformType>PAPER</platformType>
<platformType>ADVENTURE</platformType>
</autoDetectTypes>
<projectReimportVersion>1</projectReimportVersion>
</configuration>
</facet>
</component>
</module>
22 changes: 22 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
<id>papermc</id>
<url>https://repo.papermc.io/repository/maven-public/</url>
</repository>
<repository>
<id>enginehub-maven</id>
<url>https://maven.enginehub.org/repo/</url>
</repository>
</repositories>

<dependencies>
Expand All @@ -28,6 +32,24 @@
<version>1.20.4-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.sk89q.worldedit</groupId>
<artifactId>worldedit-core</artifactId>
<version>7.2.14</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.sk89q.worldedit</groupId>
<artifactId>worldedit-bukkit</artifactId>
<version>7.2.14</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>5.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
37 changes: 37 additions & 0 deletions src/main/java/fr/pegasus/papermc/PegasusPlugin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package fr.pegasus.papermc;

import fr.pegasus.papermc.managers.ServerManager;
import org.bukkit.plugin.java.JavaPlugin;

import java.util.logging.Logger;

@SuppressWarnings("unused")
public class PegasusPlugin extends JavaPlugin {

public static Logger logger = Logger.getLogger("PegasusFramework");
private ServerManager serverManager;

@Override
public void onLoad() {
super.onLoad();
logger.info("Pegasus Framework has been loaded");
}

@Override
public void onEnable() {
super.onEnable();
serverManager = new ServerManager(this);
serverManager.initLobby();
logger.info("Pegasus Framework has been enabled");
}

@Override
public void onDisable() {
super.onDisable();
logger.info("Pegasus Framework has been disabled");
}

public ServerManager getServerManager() {
return serverManager;
}
}
Loading