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 dev in prod #51

Merged
merged 13 commits into from
Jun 14, 2024
54 changes: 54 additions & 0 deletions .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions .idea/codeStyles/codeStyleConfig.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ java {

subprojects {

if(project.name == "games") {
return@subprojects
}

apply(plugin = "maven-publish")
apply(plugin = "java")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,7 @@ public void setStatus(GameStatus status) {
case ENDING -> currentGame.endGame();
case WAITING -> {
this.unregisterCurrentGame();
Core.get().getLogger().log(Level.INFO, "Default game: {0}, Auto start: {1}", new Object[]{defaultGamePluginName, autoGameStart});
if (defaultGamePluginName != null && autoGameStart) {
try {
this.loadGame(defaultGamePluginName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@
*/
String name();

/**
* Nom du dossier de la map.
* @return Nom du dossier de la map.
*/
String mapFolder() default "";

/**
* Couleur du jeu.
* @return Couleur du jeu.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@
import fr.efreicraft.animus.IRedisMessageHandler;
import fr.efreicraft.ludos.core.Core;

import java.util.logging.Level;

public class RedisHandler implements IRedisMessageHandler {

@Override
public void run(String... args) {
Core.get().getLogger().log(Level.INFO, "Recieved Redis message with args : " + String.join(" ", args));
switch (args[0]) {
case "changeRequestedGame":
Core.get().getGameManager().changeDefaultGame(args[1]);
Expand Down
42 changes: 31 additions & 11 deletions core/src/main/java/fr/efreicraft/ludos/core/maps/MapManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,14 @@ public void runManager() {
setupLobbyWorld();
}

private String getMapFolder(Game game) {
if (game.getMetadata().mapFolder().isEmpty()) {
return game.getMetadata().name();
} else {
return game.getMetadata().mapFolder();
}
}

/**
* Répertorie les cartes disponibles d'un jeu, accompagnées de leur type.
* Cette fonction est appelée à chaque changement de jeu.
Expand All @@ -82,7 +90,7 @@ public void runManager() {
public void setupCurrentGameMaps(Game game) {
if (!this.currentGameMaps.isEmpty()) clearGameMaps();

File dataFolder = new File(Core.get().getPlugin().getDataFolder(), "game_maps/" + game.getMetadata().name());
File dataFolder = new File(Core.get().getPlugin().getDataFolder(), "game_maps/" + getMapFolder(game));
if(dataFolder.exists()) {
for (File file : Objects.requireNonNull(dataFolder.listFiles())) {
if (file.isFile() && file.getName().endsWith(".schem")) {
Expand Down Expand Up @@ -210,7 +218,7 @@ private ParseMapArgs loadSchematicMap(String mapName) throws MapLoadingException

try {
schematic = SchematicUtils.loadSchematic(
Core.get().getGameManager().getCurrentGame().getMetadata().name() + "/" + mapName
getMapFolder(Core.get().getGameManager().getCurrentGame()) + "/" + mapName
);
} catch (IOException e) {
WorldUtils.deleteWorld(world);
Expand Down Expand Up @@ -272,12 +280,19 @@ private ParseMapArgs loadSchematicMap(String mapName) throws MapLoadingException
private ParseMapArgs loadFolderMap(String mapName) throws MapLoadingException {
Core.get().getLogger().log(Level.INFO, "Copying world folder {0}...", mapName);

File sourceFolder = new File(Core.get().getPlugin().getDataFolder(),
"game_maps/" + Core.get().getGameManager().getCurrentGame().getMetadata().name() + "/" + mapName);
if (!sourceFolder.isDirectory()) throw new MapLoadingException(mapName + " n'est pas un dossier ou n'existe pas.");

Core.get().getLogger().log(Level.INFO, "Path is {0}", Bukkit.getPluginsFolder().getAbsolutePath().substring(0, Bukkit.getPluginsFolder().getAbsolutePath().lastIndexOf(File.separatorChar)));
File destination = new File(Bukkit.getPluginsFolder().getAbsolutePath().substring(0, Bukkit.getPluginsFolder().getAbsolutePath().lastIndexOf(File.separatorChar)));
File sourceFolder = new File(
Core.get().getPlugin().getDataFolder(),
"game_maps/" + getMapFolder(Core.get().getGameManager().getCurrentGame()) + "/" + mapName
);
if (!sourceFolder.isDirectory())
throw new MapLoadingException(mapName + " n'est pas un dossier ou n'existe pas.");

File destination = new File(
Bukkit.getPluginsFolder().getAbsolutePath().substring(
0,
Bukkit.getPluginsFolder().getAbsolutePath().lastIndexOf(File.separatorChar)
)
);

try {
FileUtils.copyDirectory(sourceFolder, new File(destination, WorldUtils.getNormalizedWorldName(mapName)));
Expand All @@ -288,14 +303,19 @@ private ParseMapArgs loadFolderMap(String mapName) throws MapLoadingException {
org.bukkit.World world = WorldUtils.createWorld(mapName);
if (Core.get().getGameManager().getCurrentGame() != null) {
Block spongeBlock = world.getSpawnLocation().getBlock();
if (spongeBlock.getType() != Material.SPONGE) throw new MapLoadingException("World spawn is not The Sponge Block");
if (spongeBlock.getType() != Material.SPONGE)
throw new MapLoadingException("World spawn is not The Sponge Block");
Sign sign = (Sign) world.getBlockAt(spongeBlock.getLocation().add(0, 1, 0)).getState();

int[] coord1;
int[] coord2;
try {
coord1 = Arrays.stream(((TextComponent) sign.line(2)).content().split(" ")).mapToInt(Integer::parseInt).toArray();
coord2 = Arrays.stream(((TextComponent) sign.line(3)).content().split(" ")).mapToInt(Integer::parseInt).toArray();
coord1 = Arrays.stream(((TextComponent) sign.line(2)).content().split(" "))
.mapToInt(Integer::parseInt)
.toArray();
coord2 = Arrays.stream(((TextComponent) sign.line(3)).content().split(" "))
.mapToInt(Integer::parseInt)
.toArray();
} catch (NumberFormatException e) {
throw new MapLoadingException("Bad coords given on the map description Map");
}
Expand Down
3 changes: 2 additions & 1 deletion core/src/main/java/fr/efreicraft/ludos/core/teams/Team.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import net.kyori.adventure.text.format.TextDecoration;
import org.bukkit.Bukkit;
import org.bukkit.Location;

import java.util.HashSet;
Expand Down Expand Up @@ -214,7 +215,7 @@ public void removePlayers(Set<LudosPlayer> players) {
if(player.isEphemeral() && !player.entity().hasPermission("ludos.admin")) {
player.entity().kick(Component.text("Fin de la partie."));
}
if(Core.get().getGameManager().getStatus() == GameManager.GameStatus.WAITING) {
if(Core.get().getGameManager().getStatus() == GameManager.GameStatus.ENDING) {
LobbyPlayerHelper.preparePlayerItems(player);
}
}
Expand Down
44 changes: 0 additions & 44 deletions dev/Run Server.run.xml

This file was deleted.

23 changes: 23 additions & 0 deletions games/dac/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import net.minecrell.pluginyml.bukkit.BukkitPluginDescription

plugins {
`java-library`
id("net.minecrell.plugin-yml.bukkit") version "0.5.2" // Generates plugin.yml
}

dependencies {
implementation(project(":core"))

compileOnly("io.papermc.paper:paper-api:1.19.2-R0.1-SNAPSHOT")

compileOnly("fr.efreicraft:ECATUP:latest.integration")
}

bukkit {
load = BukkitPluginDescription.PluginLoadOrder.POSTWORLD
name = "LudosDAC"
main = "fr.efreicraft.ludos.games.dac.Main"
apiVersion = "1.19"
authors = listOf("Nat.io")
prefix = "DAC"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package fr.efreicraft.ludos.games.dac;

import fr.efreicraft.ludos.core.Core;
import fr.efreicraft.ludos.core.players.LudosPlayer;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.player.PlayerMoveEvent;

public record EventListener(GameLogic dac) implements Listener {

@EventHandler
public void onPlayerMove(PlayerMoveEvent event) {
if (!event.hasChangedBlock()) {
return;
}
LudosPlayer player = Core.get().getPlayerManager().getPlayer(event.getPlayer());
if (!player.getTeam().isPlayingTeam()) {
return;
}
if (this.dac.isInBassin(event.getTo())) {
dac.onPlayerInBassin(player);
} else if (this.dac.isOnGround(event.getTo().getY())) {
dac.onPlayerTouchingGround(player);
}
}


@EventHandler
public void onDamage(EntityDamageEvent event) {
if (event.getEntity() instanceof org.bukkit.entity.Player bukkitPlayer) {
LudosPlayer player = Core.get().getPlayerManager().getPlayer(bukkitPlayer);
if (!player.getTeam().isPlayingTeam()) {
return;
}
event.setDamage(0);
}
}
}
Loading
Loading