Skip to content

Commit

Permalink
Merge pull request #4 from Ewoutvans/feature/better-floor-setup
Browse files Browse the repository at this point in the history
Better floor setup & 1.4 update
  • Loading branch information
Ewoutvans authored Oct 20, 2018
2 parents 7c2e2d6 + e64fbed commit e54004c
Show file tree
Hide file tree
Showing 42 changed files with 466 additions and 228 deletions.
Binary file modified .gradle/4.4.1/fileContent/fileContent.lock
Binary file not shown.
Binary file modified .gradle/4.4.1/fileHashes/fileHashes.bin
Binary file not shown.
Binary file modified .gradle/4.4.1/fileHashes/fileHashes.lock
Binary file not shown.
Binary file modified .gradle/4.4.1/taskHistory/taskHistory.bin
Binary file not shown.
Binary file modified .gradle/4.4.1/taskHistory/taskHistory.lock
Binary file not shown.
Binary file modified .gradle/buildOutputCleanup/buildOutputCleanup.lock
Binary file not shown.
Binary file modified .gradle/buildOutputCleanup/outputFiles.bin
Binary file not shown.
2 changes: 1 addition & 1 deletion .idea/modules/GameSpleef_main.iml

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

2 changes: 1 addition & 1 deletion .idea/modules/GameSpleef_test.iml

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

269 changes: 155 additions & 114 deletions .idea/workspace.xml

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion GameSpleef.iml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<module external.linked.project.id="GameSpleef" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$" external.system.id="GRADLE" external.system.module.group="cloud.zeroprox" external.system.module.version="1.3" type="JAVA_MODULE" version="4">
<module external.linked.project.id="GameSpleef" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$" external.system.id="GRADLE" external.system.module.group="cloud.zeroprox" external.system.module.version="1.4" type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified build/classes/java/main/cloud/zeroprox/gamespleef/GameSpleef.class
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified build/classes/java/main/cloud/zeroprox/gamespleef/game/IGame.class
Binary file not shown.
Binary file not shown.
2 changes: 1 addition & 1 deletion build/resources/main/mcmod.info
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{
"modid": "gamespleef",
"name": "GameSpleef",
"version": "1.3",
"version": "1.4",
"description": "A spleef minigame",
"url": "https://zeroprox.cloud",
"authorList": [
Expand Down
2 changes: 1 addition & 1 deletion build/tmp/generateMetadata/mcmod.info
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{
"modid": "gamespleef",
"name": "GameSpleef",
"version": "1.3",
"version": "1.4",
"description": "A spleef minigame",
"url": "https://zeroprox.cloud",
"authorList": [
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
pluginGroup=cloud.zeroprox
pluginId=gamespleef
pluginVersion=1.3
pluginVersion=1.4
56 changes: 38 additions & 18 deletions src/main/java/cloud/zeroprox/gamespleef/GameSpleef.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
import cloud.zeroprox.gamespleef.game.IGame;
import cloud.zeroprox.gamespleef.utils.AABBSerialize;
import cloud.zeroprox.gamespleef.utils.GameSerialize;
import cloud.zeroprox.gamespleef.utils.MessageManager;
import cloud.zeroprox.gamespleef.utils.TransformWorldSerializer;
import com.google.common.collect.Maps;
import com.google.common.reflect.TypeToken;
import com.google.inject.Inject;
import ninja.leaping.configurate.ConfigurationNode;
Expand All @@ -25,6 +25,7 @@
import org.spongepowered.api.command.CommandSource;
import org.spongepowered.api.command.args.*;
import org.spongepowered.api.command.spec.CommandSpec;
import org.spongepowered.api.config.ConfigDir;
import org.spongepowered.api.config.DefaultConfig;
import org.spongepowered.api.entity.Transform;
import org.spongepowered.api.event.Listener;
Expand All @@ -47,19 +48,24 @@
public class GameSpleef {

@Inject
private Logger logger;
public Logger logger;
private static GameSpleef instance;
private static GameManager gameManager;
private static MessageManager messageManager;

@Inject
@DefaultConfig(sharedRoot = true)
@DefaultConfig(sharedRoot = false)
private Path defaultConfig;

@Inject
@DefaultConfig(sharedRoot = true)
private ConfigurationLoader<CommentedConfigurationNode> configManager;
private ConfigurationLoader<CommentedConfigurationNode> configManagerDefaultConfig;

@Inject
@ConfigDir(sharedRoot = false)
private Path privateConfigDir;

private ConfigurationNode rootNode;
private ConfigurationNode rootNodeDefaultConfig;


CommandSpec joinCmd = CommandSpec.builder()
Expand Down Expand Up @@ -144,10 +150,11 @@ public void onServerStart(GameStartedServerEvent event) {

gameManager = new GameManager();
instance = this;
configManager = HoconConfigurationLoader.builder().setPath(defaultConfig).build();
configManagerDefaultConfig = HoconConfigurationLoader.builder().setPath(defaultConfig).build();
try {
rootNode = configManager.load();
rootNodeDefaultConfig = configManagerDefaultConfig.load();
loadConfig();
loadMessages();
} catch(IOException e) {
} catch (ObjectMappingException e) {
e.printStackTrace();
Expand All @@ -162,26 +169,36 @@ public static GameManager getGameManager() {
return gameManager;
}

public static MessageManager mM() {
return messageManager;
}


@Listener
public void onGameReload(GameReloadEvent event) {
try {
rootNodeDefaultConfig = configManagerDefaultConfig.load();
loadConfig();
loadMessages();
} catch (IOException e) {
} catch (ObjectMappingException e) {
}
}

private void loadMessages() {
messageManager = new MessageManager(privateConfigDir);
}

private void loadConfig() throws IOException, ObjectMappingException {
if (rootNode.getNode("areas").isVirtual()) {
if (rootNodeDefaultConfig.getNode("areas").isVirtual()) {
logger.info("Creating configuration");

rootNode.getNode("areas").setValue(new TypeToken<List<GameSerialize>>(){}, Arrays.asList());
configManager.save(rootNode);
rootNodeDefaultConfig.getNode("areas").setValue(new TypeToken<List<GameSerialize>>(){}, Arrays.asList());
configManagerDefaultConfig.save(rootNodeDefaultConfig);
loadConfig();
} else {
getGameManager().iGames.clear();
List<GameSerialize> gameSerializeList = rootNode.getNode("areas").getList(TypeToken.of(GameSerialize.class));
List<GameSerialize> gameSerializeList = rootNodeDefaultConfig.getNode("areas").getList(TypeToken.of(GameSerialize.class));
for (GameSerialize gameSerialize : gameSerializeList) {
IGame iGame = null;

Expand All @@ -200,7 +217,10 @@ private void loadConfig() throws IOException, ObjectMappingException {
gameSerialize.campRadius,
gameSerialize.campInterval,
gameSerialize.campPlayers,
gameSerialize.saveInv
gameSerialize.saveInv,
gameSerialize.winningCommand,
gameSerialize.winningMinPlayers,
gameSerialize.winningCooldown
);
}
getGameManager().iGames.add(iGame);
Expand All @@ -211,12 +231,12 @@ private void loadConfig() throws IOException, ObjectMappingException {

public void addArena(GameSerialize gameSerialize) {
try {
List<GameSerialize> gameSerializeList = rootNode.getNode("areas").getList(TypeToken.of(GameSerialize.class));
List<GameSerialize> gameSerializeList = rootNodeDefaultConfig.getNode("areas").getList(TypeToken.of(GameSerialize.class));
List<GameSerialize> gameList = new ArrayList<>();
gameList.addAll(gameSerializeList);
gameList.add(gameSerialize);
rootNode.getNode("areas").setValue(new TypeToken<List<GameSerialize>>(){}, gameList);
configManager.save(rootNode);
rootNodeDefaultConfig.getNode("areas").setValue(new TypeToken<List<GameSerialize>>(){}, gameList);
configManagerDefaultConfig.save(rootNodeDefaultConfig);
loadConfig();
} catch (ObjectMappingException e) {
e.printStackTrace();
Expand All @@ -227,12 +247,12 @@ public void addArena(GameSerialize gameSerialize) {

public void removeArena(IGame iGame) {
try {
List<GameSerialize> gameSerializeList = rootNode.getNode("areas").getList(TypeToken.of(GameSerialize.class));
List<GameSerialize> gameSerializeList = rootNodeDefaultConfig.getNode("areas").getList(TypeToken.of(GameSerialize.class));
List<GameSerialize> gameList = new ArrayList<>();
gameList.addAll(gameSerializeList);
gameList.removeIf(gameSerialize -> gameSerialize.name.equalsIgnoreCase(iGame.getName()));
rootNode.getNode("areas").setValue(new TypeToken<List<GameSerialize>>(){}, gameList);
configManager.save(rootNode);
rootNodeDefaultConfig.getNode("areas").setValue(new TypeToken<List<GameSerialize>>(){}, gameList);
configManagerDefaultConfig.save(rootNodeDefaultConfig);
loadConfig();
} catch (ObjectMappingException e) {
e.printStackTrace();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package cloud.zeroprox.gamespleef.commands;

import cloud.zeroprox.gamespleef.GameSpleef;
import org.spongepowered.api.command.CommandResult;
import org.spongepowered.api.command.CommandSource;
import org.spongepowered.api.command.args.CommandContext;
Expand All @@ -13,7 +14,7 @@ public class HelpCmd implements CommandExecutor {
@Override
public CommandResult execute(CommandSource src, CommandContext args) {
PaginationList.builder()
.title(Text.of(TextColors.GREEN, "Game KingOfTheWater commands"))
.title(GameSpleef.mM().SPLEEF_HELP_TITLE.apply().build())
.padding(Text.of(TextColors.GOLD, "="))
.contents(
Text.builder("/spleef join ").color(TextColors.GREEN).append(Text.of(TextColors.WHITE, "[area]")).onClick(TextActions.suggestCommand("/spleef join ")).build(),
Expand Down
12 changes: 5 additions & 7 deletions src/main/java/cloud/zeroprox/gamespleef/commands/JoinCmd.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import cloud.zeroprox.gamespleef.GameSpleef;
import cloud.zeroprox.gamespleef.game.IGame;
import com.google.common.collect.ImmutableMap;
import org.spongepowered.api.command.CommandException;
import org.spongepowered.api.command.CommandResult;
import org.spongepowered.api.command.CommandSource;
Expand All @@ -18,19 +19,16 @@ public class JoinCmd implements CommandExecutor {
@Override
public CommandResult execute(CommandSource src, CommandContext args) throws CommandException {
if (!(src instanceof Player)) {
throw new CommandException(Text.of(TextColors.RED, "You need to be a player to join a game"));
throw new CommandException(GameSpleef.mM().NEED_TO_BE_PLAYER.apply().build());
}
Player player = (Player) src;

/*if (player.getInventory().totalItems() != 0) {
throw new CommandException(Text.of(TextColors.RED, "You need a empty inventory to join"));
if (GameSpleef.getGameManager().getPlayerGame(player).isPresent()) {
throw new CommandException(GameSpleef.mM().YOU_ALREADY_PLAYING.apply().build());
}
*/
String gameName = args.<String>getOne(Text.of("game")).orElse(GameSpleef.getGameManager().getDefaultName());
Optional<IGame> game = GameSpleef.getGameManager().getGame(gameName);
if (!game.isPresent()) {
src.sendMessage(Text.of(TextColors.RED, "No game found for name ", gameName));
return CommandResult.empty();
throw new CommandException(GameSpleef.mM().GAME_NAME_NOT_FOUND.apply(ImmutableMap.of("gamename", gameName)).build());
}
game.get().addPlayer(player);
return CommandResult.success();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ public class LeaveCmd implements CommandExecutor {
@Override
public CommandResult execute(CommandSource src, CommandContext args) throws CommandException {
if (!(src instanceof Player)) {
throw new CommandException(Text.of(TextColors.RED, "You need to be a player to join a game"));
throw new CommandException(GameSpleef.mM().NEED_TO_BE_PLAYER.apply().build());
}
Player player = (Player) src;

Optional<IGame> game = GameSpleef.getGameManager().getPlayerGame(player);
if (!game.isPresent()) {
throw new CommandException(Text.of(TextColors.RED, "You are not in a game"));
throw new CommandException(GameSpleef.mM().YOU_ARE_NOT_INGAME.apply().build());
}

game.get().leavePlayer(player, args.hasAny("f"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public CommandResult execute(CommandSource src, CommandContext args) {
}

PaginationList.builder()
.title(Text.of(TextColors.GREEN, "Spleef Arena's"))
.title(GameSpleef.mM().SPLEEF_ARENAS.apply().build())
.padding(Text.of(TextColors.GOLD, "="))
.contents(arenas)
.build()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,9 @@
import org.spongepowered.api.text.Text;
import org.spongepowered.api.text.action.TextActions;
import org.spongepowered.api.text.format.TextColors;
import org.spongepowered.api.util.AABB;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.Random;
import java.util.*;

public class BuildCmd implements CommandExecutor {

Expand Down Expand Up @@ -60,6 +58,9 @@ public CommandResult execute(CommandSource src, CommandContext args) throws Comm
this.gameSerialize.campRadius = 2;
this.gameSerialize.saveInv = true;
this.gameSerialize.playerLimit = 20;
this.gameSerialize.winningCommand = Arrays.asList("give %winner% minecraft:diamond 1", "say %winner% got a diamond for winning spleef in arena %game%!");
this.gameSerialize.winningMinPlayers = 2;
this.gameSerialize.winningCooldown = 1;
showProgress(src);
return CommandResult.success();
}
Expand All @@ -79,29 +80,13 @@ public CommandResult execute(CommandSource src, CommandContext args) throws Comm
case CORNER_FLOOR_1:
gameSerialize.corner_floor_1 = player.getLocation();
if (gameSerialize.corner_floor_2 != null) {
gameSerialize.floors.add(new AABBSerialize(
gameSerialize.corner_floor_1.getBlockX(),
gameSerialize.corner_floor_1.getBlockY(),
gameSerialize.corner_floor_1.getBlockZ(),
gameSerialize.corner_floor_2.getBlockX(),
gameSerialize.corner_floor_2.getBlockY(),
gameSerialize.corner_floor_2.getBlockZ()));
gameSerialize.corner_floor_1 = null;
gameSerialize.corner_floor_2 = null;
trySavingFloor(src);
}
break;
case CORNER_FLOOR_2:
gameSerialize.corner_floor_2 = player.getLocation();
if (gameSerialize.corner_floor_1 != null) {
gameSerialize.floors.add(new AABBSerialize(
gameSerialize.corner_floor_1.getBlockX(),
gameSerialize.corner_floor_1.getBlockY(),
gameSerialize.corner_floor_1.getBlockZ(),
gameSerialize.corner_floor_2.getBlockX(),
gameSerialize.corner_floor_2.getBlockY(),
gameSerialize.corner_floor_2.getBlockZ()));
gameSerialize.corner_floor_1 = null;
gameSerialize.corner_floor_2 = null;
trySavingFloor(src);
}
break;
case CORNER_AREA_1:
Expand All @@ -119,6 +104,48 @@ public CommandResult execute(CommandSource src, CommandContext args) throws Comm
return CommandResult.empty();
}

private void trySavingFloor(CommandSource src) {
try {
// try making the AABB to see if it was setup correctly
AABB aabb = new AABB(gameSerialize.corner_floor_1.getBlockX(),
gameSerialize.corner_floor_1.getBlockY(),
gameSerialize.corner_floor_1.getBlockZ(),
gameSerialize.corner_floor_2.getBlockX(),
gameSerialize.corner_floor_2.getBlockY(),
gameSerialize.corner_floor_2.getBlockZ());

gameSerialize.floors.add(new AABBSerialize(
gameSerialize.corner_floor_1.getBlockX(),
gameSerialize.corner_floor_1.getBlockY(),
gameSerialize.corner_floor_1.getBlockZ(),
gameSerialize.corner_floor_2.getBlockX(),
gameSerialize.corner_floor_2.getBlockY(),
gameSerialize.corner_floor_2.getBlockZ()));
gameSerialize.corner_floor_1 = null;
gameSerialize.corner_floor_2 = null;

} catch (Exception e) {
if (e instanceof IllegalArgumentException) {
switch (e.getMessage()) {
case "The box is degenerate on x":
src.sendMessage(Text.of("The floor is not correctly setup, you have selected the same 'X' location for both corners."));
break;
case "The box is degenerate on y":
src.sendMessage(Text.of("The floor is not correctly setup, you have selected the same 'Y' location for both corners. Try going 1 block lower."));
break;
case "The box is degenerate on z":
src.sendMessage(Text.of("The floor is not correctly setup, you have selected the same 'Z' location for both corners."));
break;
default:
src.sendMessage(Text.of("Unknown problem with making the floor region has occurred."));
break;
}
}
gameSerialize.corner_floor_1 = null;
gameSerialize.corner_floor_2 = null;
}
}

private void showProgress(CommandSource src) {
List<Text> textArray = new ArrayList<>();
if (gameSerialize == null) {
Expand Down
Loading

0 comments on commit e54004c

Please sign in to comment.