Skip to content

Commit

Permalink
implement
Browse files Browse the repository at this point in the history
  • Loading branch information
HSGamer committed Dec 13, 2023
1 parent 776cfed commit 414ea4d
Show file tree
Hide file tree
Showing 10 changed files with 591 additions and 54 deletions.
33 changes: 4 additions & 29 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,18 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<artifactId>example-expansion</artifactId>
<artifactId>pinata</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>jar</packaging>

<name>ExampleExpansion</name>
<description>An Example expansion for GamesInTheBox</description>
<name>Pinata</name>
<description>A mob to punch</description>

<properties>
<project.mainClass>me.hsgamer.gamesinthebox.exampleexpansion.ExampleExpansion</project.mainClass>
<project.mainClass>me.hsgamer.gamesinthebox.pinata.Pinata</project.mainClass>
<shade.attachedArtifact>true</shade.attachedArtifact>
</properties>

<!-- JITPACK -->
<repositories>
<repository>
<id>jitpack.io</id>
Expand All @@ -36,28 +35,4 @@
<scope>provided</scope>
</dependency>
</dependencies>

<!-- GITHUB PACKAGES -->
<!-- <repositories>-->
<!-- <repository>-->
<!-- <id>github</id>-->
<!-- <url>https://maven.pkg.github.com/GamesInTheBox-MC/ExpansionParent</url>-->
<!-- <snapshots>-->
<!-- <enabled>true</enabled>-->
<!-- </snapshots>-->
<!-- </repository>-->
<!-- </repositories>-->
<!-- <parent>-->
<!-- <groupId>me.hsgamer.gamesinthebox</groupId>-->
<!-- <artifactId>expansion-parent</artifactId>-->
<!-- <version>1.0.1</version>-->
<!-- </parent>-->
<!-- <dependencies>-->
<!-- <dependency>-->
<!-- <groupId>me.hsgamer</groupId>-->
<!-- <artifactId>games-in-the-box</artifactId>-->
<!-- <version>1.2.0</version>-->
<!-- <scope>provided</scope>-->
<!-- </dependency>-->
<!-- </dependencies>-->
</project>

This file was deleted.

89 changes: 89 additions & 0 deletions src/main/java/me/hsgamer/gamesinthebox/pinata/GameArenaLogic.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
package me.hsgamer.gamesinthebox.pinata;

import me.hsgamer.gamesinthebox.game.feature.BoundingFeature;
import me.hsgamer.gamesinthebox.game.feature.PointFeature;
import me.hsgamer.gamesinthebox.game.simple.feature.SimpleBoundingFeature;
import me.hsgamer.gamesinthebox.game.simple.feature.SimpleBoundingOffsetFeature;
import me.hsgamer.gamesinthebox.game.simple.feature.SimpleRewardFeature;
import me.hsgamer.gamesinthebox.game.template.TemplateGameArena;
import me.hsgamer.gamesinthebox.game.template.TemplateGameArenaLogic;
import me.hsgamer.gamesinthebox.pinata.feature.ListenerFeature;
import me.hsgamer.gamesinthebox.pinata.feature.PinataFeature;
import me.hsgamer.gamesinthebox.pinata.feature.SpawnFeature;
import me.hsgamer.minigamecore.base.Feature;

import java.util.Arrays;
import java.util.List;
import java.util.UUID;
import java.util.stream.Collectors;

public class GameArenaLogic extends TemplateGameArenaLogic {
private final Pinata expansion;

public GameArenaLogic(Pinata expansion, TemplateGameArena arena) {
super(arena);
this.expansion = expansion;
}

@Override
public void forceEnd() {
PinataFeature pinataFeature = arena.getFeature(PinataFeature.class);
pinataFeature.setClearAllEntities(false);
pinataFeature.stopTask();
pinataFeature.clearAllEntities();

arena.getFeature(ListenerFeature.class).unregister();
}

@Override
public List<Feature> loadFeatures() {
SimpleBoundingFeature boundingFeature = new SimpleBoundingFeature(arena);
return Arrays.asList(
boundingFeature,
new SimpleBoundingOffsetFeature(arena, boundingFeature, true),
new PinataFeature(arena),
new ListenerFeature(expansion, arena),
new SpawnFeature(arena)
);
}

@Override
public void postInit() {
BoundingFeature boundingFeature = arena.getFeature(BoundingFeature.class);
arena.getFeature(PinataFeature.class).addEntityClearCheck(entity -> !boundingFeature.checkBounding(entity.getLocation(), true));
}

@Override
public void onInGameStart() {
arena.getFeature(ListenerFeature.class).register();
arena.getFeature(PinataFeature.class).startTask();
}

@Override
public void onInGameUpdate() {
arena.getFeature(SpawnFeature.class).checkAndSpawn();
}

@Override
public void onEndingStart() {
List<UUID> topList = arena.getFeature(PointFeature.class).getTopUUID().collect(Collectors.toList());
arena.getFeature(SimpleRewardFeature.class).tryReward(topList);

arena.getFeature(PinataFeature.class).setClearAllEntities(true);
}

@Override
public boolean isEndingOver() {
return super.isEndingOver() && arena.getFeature(PinataFeature.class).isAllEntityCleared();
}

@Override
public void onEndingOver() {
PinataFeature pinataFeature = arena.getFeature(PinataFeature.class);
pinataFeature.setClearAllEntities(false);
pinataFeature.stopTask();
pinataFeature.clearAllEntities();

arena.getFeature(ListenerFeature.class).unregister();
}
}
207 changes: 207 additions & 0 deletions src/main/java/me/hsgamer/gamesinthebox/pinata/GameEditor.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,207 @@
package me.hsgamer.gamesinthebox.pinata;

import com.google.common.base.Enums;
import me.hsgamer.gamesinthebox.game.GameArena;
import me.hsgamer.gamesinthebox.game.simple.action.ValueAction;
import me.hsgamer.gamesinthebox.game.simple.feature.SimpleBoundingFeature;
import me.hsgamer.gamesinthebox.game.simple.feature.SimpleBoundingOffsetFeature;
import me.hsgamer.gamesinthebox.game.template.TemplateGame;
import me.hsgamer.gamesinthebox.game.template.TemplateGameArenaLogic;
import me.hsgamer.gamesinthebox.game.template.TemplateGameEditor;
import me.hsgamer.gamesinthebox.game.template.feature.ArenaLogicFeature;
import me.hsgamer.gamesinthebox.pinata.feature.ListenerFeature;
import me.hsgamer.gamesinthebox.pinata.feature.PinataFeature;
import me.hsgamer.hscore.bukkit.utils.MessageUtils;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.EntityType;
import org.jetbrains.annotations.NotNull;

import java.util.*;
import java.util.stream.Collectors;

public class GameEditor extends TemplateGameEditor {
private final SimpleBoundingFeature.Editor simpleBoundingFeatureEditor = SimpleBoundingFeature.editor(true);
private final SimpleBoundingOffsetFeature.Editor simpleBoundingOffsetFeatureEditor = SimpleBoundingOffsetFeature.editor();
private final List<String> nameTags = new ArrayList<>();
private EntityType entityType = EntityType.SHEEP;
private boolean damageAsScore = false;

public GameEditor(@NotNull TemplateGame game) {
super(game);
}

@Override
protected @NotNull Map<String, SimpleAction> createActionMap() {
Map<String, SimpleAction> map = super.createActionMap();

map.putAll(simpleBoundingFeatureEditor.getActions());
map.putAll(simpleBoundingOffsetFeatureEditor.getActions());

map.put("add-name-tag", new SimpleAction() {
@Override
public @NotNull String getDescription() {
return "Add a name tag to the list";
}

@Override
public boolean performAction(@NotNull CommandSender sender, @NotNull String... args) {
if (args.length == 0) {
return false;
}
nameTags.add(String.join(" ", args));
return true;
}

@Override
public @NotNull String getArgsUsage() {
return "<name tag>";
}
});
map.put("clear-name-tags", new SimpleAction() {
@Override
public @NotNull String getDescription() {
return "Clear the name tags list";
}

@Override
public boolean performAction(@NotNull CommandSender sender, @NotNull String... args) {
nameTags.clear();
return true;
}
});
map.put("set-pinata-type", new ValueAction<EntityType>() {
@Override
public @NotNull String getDescription() {
return "Set the pinata type";
}

@Override
protected boolean performAction(@NotNull CommandSender sender, @NotNull EntityType value, String... args) {
entityType = value;
return true;
}

@Override
protected int getValueArgCount() {
return 1;
}

@Override
protected Optional<EntityType> parseValue(@NotNull CommandSender sender, String... args) {
return Optional.ofNullable(args[0])
.map(String::toUpperCase)
.flatMap(s -> Enums.getIfPresent(EntityType.class, s).toJavaUtil())
.filter(EntityType::isAlive);
}

@Override
protected @NotNull List<String> getValueArgs(@NotNull CommandSender sender, String... args) {
return Arrays.stream(EntityType.values())
.filter(EntityType::isAlive)
.map(Enum::name)
.collect(Collectors.toList());
}
});
map.put("set-damage-as-score", new ValueAction<Boolean>() {
@Override
protected boolean performAction(@NotNull CommandSender sender, @NotNull Boolean value, String... args) {
damageAsScore = value;
return true;
}

@Override
protected int getValueArgCount() {
return 1;
}

@Override
protected Optional<Boolean> parseValue(@NotNull CommandSender sender, String... args) {
return Optional.of(Boolean.parseBoolean(args[0]));
}

@Override
protected @NotNull List<String> getValueArgs(@NotNull CommandSender sender, String... args) {
return Arrays.asList("true", "false");
}

@Override
public @NotNull String getDescription() {
return "Set whether to use damage as score";
}

@Override
public @NotNull String getArgsUsage() {
return "<true/false>";
}
});

return map;
}

@Override
protected @NotNull List<@NotNull SimpleEditorStatus> createEditorStatusList() {
List<@NotNull SimpleEditorStatus> list = super.createEditorStatusList();
list.add(simpleBoundingFeatureEditor.getStatus());
list.add(simpleBoundingOffsetFeatureEditor.getStatus());
list.add(new SimpleEditorStatus() {
@Override
public void sendStatus(@NotNull CommandSender sender) {
MessageUtils.sendMessage(sender, "&6&lPinata");
MessageUtils.sendMessage(sender, "&6Type: &f" + entityType.name());
MessageUtils.sendMessage(sender, "&6Damage As Score: &f" + damageAsScore);
MessageUtils.sendMessage(sender, "&6Name Tags: ");
nameTags.forEach(nameTag -> MessageUtils.sendMessage(sender, "&f- " + nameTag));
}

@Override
public void reset(@NotNull CommandSender sender) {
nameTags.clear();
entityType = EntityType.SHEEP;
damageAsScore = false;
}

@Override
public boolean canSave(@NotNull CommandSender sender) {
return true;
}

@Override
public Map<String, Object> toPathValueMap(@NotNull CommandSender sender) {
Map<String, Object> map = new LinkedHashMap<>();
if (!nameTags.isEmpty()) {
map.put("pinata.name-tag", nameTags);
}
if (entityType != EntityType.SHEEP) {
map.put("pinata.type", entityType.name());
}
if (damageAsScore) {
map.put("damage-as-score", true);
}
return map;
}
});
return list;
}

@Override
public boolean migrate(@NotNull CommandSender sender, @NotNull GameArena gameArena) {
ArenaLogicFeature arenaLogicFeature = gameArena.getFeature(ArenaLogicFeature.class);
if (arenaLogicFeature == null) {
return false;
}
TemplateGameArenaLogic templateGameArenaLogic = arenaLogicFeature.getArenaLogic();
if (!(templateGameArenaLogic instanceof GameArenaLogic)) {
return false;
}

nameTags.clear();
nameTags.addAll(gameArena.getFeature(PinataFeature.class).getNameTags());

entityType = gameArena.getFeature(PinataFeature.class).getEntityType();
damageAsScore = gameArena.getFeature(ListenerFeature.class).isDamageAsScore();

simpleBoundingFeatureEditor.migrate(gameArena.getFeature(SimpleBoundingFeature.class));
simpleBoundingOffsetFeatureEditor.migrate(gameArena.getFeature(SimpleBoundingOffsetFeature.class));
return super.migrate(sender, gameArena);
}
}
Loading

0 comments on commit 414ea4d

Please sign in to comment.