-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix random games not showing correct player count
- Loading branch information
Showing
6 changed files
with
105 additions
and
171 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
src/main/java/xyz/nucleoid/plasmid/game/portal/game/GameConfigGamePortalBackend.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package xyz.nucleoid.plasmid.game.portal.game; | ||
|
||
import net.minecraft.item.ItemStack; | ||
import net.minecraft.item.Items; | ||
import net.minecraft.text.Text; | ||
import net.minecraft.util.Formatting; | ||
import net.minecraft.util.Identifier; | ||
import xyz.nucleoid.plasmid.game.GameSpace; | ||
import xyz.nucleoid.plasmid.game.config.GameConfigs; | ||
import xyz.nucleoid.plasmid.game.manager.GameSpaceManager; | ||
import xyz.nucleoid.plasmid.game.portal.GamePortalBackend; | ||
|
||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.function.Consumer; | ||
|
||
public interface GameConfigGamePortalBackend extends GamePortalBackend { | ||
Identifier gameId(); | ||
|
||
@Override | ||
default void provideGameSpaces(Consumer<GameSpace> consumer) { | ||
var gameConfig = GameConfigs.get(this.gameId()); | ||
for (var gameSpace : GameSpaceManager.get().getOpenGameSpaces()) { | ||
if (gameSpace.getMetadata().isSourceConfig(gameConfig)) { | ||
consumer.accept(gameSpace); | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
default int getPlayerCount() { | ||
int count = 0; | ||
var gameConfig = GameConfigs.get(this.gameId()); | ||
for (var gameSpace : GameSpaceManager.get().getOpenGameSpaces()) { | ||
if (gameSpace.getMetadata().isSourceConfig(gameConfig)) { | ||
count += gameSpace.getPlayers().size(); | ||
} | ||
} | ||
return count; | ||
} | ||
|
||
@Override | ||
default List<Text> getDescription() { | ||
var config = GameConfigs.get(this.gameId()); | ||
if (config != null) { | ||
return config.description(); | ||
} | ||
|
||
return Collections.emptyList(); | ||
} | ||
|
||
@Override | ||
default ItemStack getIcon() { | ||
var config = GameConfigs.get(this.gameId()); | ||
if (config != null) { | ||
return config.icon(); | ||
} | ||
|
||
return Items.BARRIER.getDefaultStack(); | ||
} | ||
|
||
@Override | ||
default Text getName() { | ||
var config = GameConfigs.get(this.gameId()); | ||
if (config != null) { | ||
return config.name(); | ||
} else { | ||
return Text.literal(this.gameId().toString()).formatted(Formatting.RED); | ||
} | ||
} | ||
|
||
@Override | ||
default ActionType getActionType() { | ||
return ActionType.PLAY; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters