Skip to content

Commit

Permalink
Merge pull request #49 from efrei-craft/init-dac
Browse files Browse the repository at this point in the history
Draft: DAC + MapManager mapFolder
  • Loading branch information
JiveOff authored Dec 10, 2023
2 parents 92aa656 + bb7ee3b commit d368c85
Show file tree
Hide file tree
Showing 12 changed files with 439 additions and 56 deletions.
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 @@ -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
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
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

0 comments on commit d368c85

Please sign in to comment.