Game api additions, Refactoring, Translation api edits
This commit is contained in:
@@ -1,11 +1,13 @@
|
||||
package eu.mhsl.minenet.minigames.instance.game;
|
||||
|
||||
import eu.mhsl.minenet.minigames.instance.MineNetInstance;
|
||||
import eu.mhsl.minenet.minigames.util.CommonEventHandles;
|
||||
import eu.mhsl.minenet.minigames.instance.Spawnable;
|
||||
import eu.mhsl.minenet.minigames.instance.room.Room;
|
||||
import io.github.bloepiloepi.pvp.config.PvPConfig;
|
||||
import net.minestom.server.MinecraftServer;
|
||||
import net.minestom.server.coordinate.Pos;
|
||||
import net.minestom.server.entity.Player;
|
||||
import net.minestom.server.event.EventNode;
|
||||
import net.minestom.server.event.instance.AddEntityToInstanceEvent;
|
||||
import net.minestom.server.event.instance.RemoveEntityFromInstanceEvent;
|
||||
@@ -23,33 +25,31 @@ import org.jetbrains.annotations.NotNull;
|
||||
import java.util.Random;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public abstract class Game extends InstanceContainer implements Spawnable {
|
||||
public abstract class Game extends MineNetInstance implements Spawnable {
|
||||
|
||||
protected boolean isRunning = false;
|
||||
protected boolean isBeforeBeginning = true;
|
||||
|
||||
protected final Random rnd = new Random(); //TODO better way than ths?
|
||||
|
||||
protected final Logger logger;
|
||||
|
||||
public Game(DimensionType dimensionType) {
|
||||
super(UUID.randomUUID(), dimensionType);
|
||||
super(dimensionType);
|
||||
|
||||
MinecraftServer.getInstanceManager().registerInstance(this);
|
||||
|
||||
logger = Logger.getLogger("Game:" + getUniqueId());
|
||||
|
||||
eventNode()
|
||||
.addListener(PlayerMoveEvent.class, this::onPlayerMove)
|
||||
.addListener(PlayerBlockBreakEvent.class, this::onBlockBreak)
|
||||
.addListener(PlayerBlockPlaceEvent.class, this::onBlockPlace)
|
||||
.addListener(AddEntityToInstanceEvent.class, this::onJoin)
|
||||
.addListener(RemoveEntityFromInstanceEvent.class, this::onLeave)
|
||||
.addListener(ItemDropEvent.class, this::onItemDrop);
|
||||
}
|
||||
|
||||
public void enablePvpConfig(PvPConfig config) {
|
||||
//eventNode().addChild((EventNode<? extends InstanceEvent>) config.createNode());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Load and start countdown
|
||||
*/
|
||||
@@ -82,7 +82,7 @@ public abstract class Game extends InstanceContainer implements Spawnable {
|
||||
|
||||
scheduler().scheduleTask(() -> {
|
||||
|
||||
System.out.println("stopping game instance " + this.uniqueId);
|
||||
logger.info("stopping game instance " + this.uniqueId);
|
||||
getPlayers().forEach(player -> player.kick("timeout"));
|
||||
|
||||
MinecraftServer.getInstanceManager().unregisterInstance(this);
|
||||
@@ -108,15 +108,8 @@ public abstract class Game extends InstanceContainer implements Spawnable {
|
||||
playerBlockPlaceEvent.setCancelled(true);
|
||||
}
|
||||
|
||||
protected void onJoin(@NotNull AddEntityToInstanceEvent addEntityToInstanceEvent) {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Make sure when overriding to call checkAbandoned to insure no garbage instances
|
||||
* @param removeEntityFromInstanceEvent
|
||||
*/
|
||||
protected void onLeave(@NotNull RemoveEntityFromInstanceEvent removeEntityFromInstanceEvent) {
|
||||
@Override
|
||||
protected void onPlayerLeave(Player p) {
|
||||
this.checkAbandoned();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package eu.mhsl.minenet.minigames.instance.game.minigame;
|
||||
package eu.mhsl.minenet.minigames.instance.game;
|
||||
|
||||
import eu.mhsl.minenet.minigames.instance.game.minigame.config.GameFactory;
|
||||
import eu.mhsl.minenet.minigames.instance.game.minigame.types.deathcube.DeathcubeFactory;
|
||||
@@ -6,17 +6,23 @@ import eu.mhsl.minenet.minigames.instance.game.minigame.types.minerun.MinerunFac
|
||||
import eu.mhsl.minenet.minigames.instance.game.minigame.types.stickfight.StickFightFactory;
|
||||
import eu.mhsl.minenet.minigames.instance.game.minigame.types.trafficlightrace.TrafficLightRaceFactory;
|
||||
|
||||
public enum MinigameType {
|
||||
DEATHCUBE(new DeathcubeFactory()),
|
||||
STICKFIGHT(new StickFightFactory()),
|
||||
MINERUN(new MinerunFactory()),
|
||||
TRAFFICLIGHTRACE(new TrafficLightRaceFactory());
|
||||
public enum GameList {
|
||||
DEATHCUBE(new DeathcubeFactory(), GameType.OTHER),
|
||||
STICKFIGHT(new StickFightFactory(), GameType.PVP),
|
||||
MINERUN(new MinerunFactory(), GameType.PVE),
|
||||
TRAFFICLIGHTRACE(new TrafficLightRaceFactory(), GameType.OTHER);
|
||||
|
||||
private GameFactory factory;
|
||||
MinigameType(GameFactory factory) {
|
||||
private GameType type;
|
||||
GameList(GameFactory factory, GameType type) {
|
||||
this.factory = factory;
|
||||
this.type = type;
|
||||
}
|
||||
public GameFactory getFactory() {
|
||||
return this.factory;
|
||||
}
|
||||
|
||||
public GameType getType() {
|
||||
return type;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package eu.mhsl.minenet.minigames.instance.game;
|
||||
|
||||
import eu.mhsl.minenet.minigames.message.component.NamespacedTranslatable;
|
||||
import eu.mhsl.minenet.minigames.message.component.TranslatedComponent;
|
||||
import net.minestom.server.item.Material;
|
||||
|
||||
public enum GameType {
|
||||
OTHER(Material.GRASS_BLOCK, TranslatedComponent.raw("GameType#other"), TranslatedComponent.raw("GameType#other_description")),
|
||||
PVP(Material.DIAMOND_SWORD, TranslatedComponent.raw("GameType#pvp"), TranslatedComponent.raw("GameType#pvp_description")),
|
||||
PVE(Material.DIAMOND_PICKAXE, TranslatedComponent.raw("GameType#pve"), TranslatedComponent.raw("GameType#pve_description"));
|
||||
|
||||
|
||||
Material icon;
|
||||
TranslatedComponent title;
|
||||
TranslatedComponent description;
|
||||
|
||||
GameType(Material icon, TranslatedComponent title, TranslatedComponent description) {
|
||||
this.title = title;
|
||||
this.description = description;
|
||||
this.icon = icon;
|
||||
}
|
||||
|
||||
public Material getIcon() {
|
||||
return icon;
|
||||
}
|
||||
|
||||
public TranslatedComponent getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
public TranslatedComponent getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -72,7 +72,6 @@ public class Minigame extends Game {
|
||||
|
||||
if(timeLimit > 0) {
|
||||
scheduler().submitTask(() -> {
|
||||
System.out.println("Countdown running...");
|
||||
if(!isRunning || timeLimit == 0) return TaskSchedule.stop();
|
||||
if(timeLimit <= timePlayed) {
|
||||
stop();
|
||||
|
||||
@@ -40,9 +40,6 @@ class Minerun extends Minigame {
|
||||
this.width = width;
|
||||
this.length = length;
|
||||
this.minePercentage = minePercentage;
|
||||
|
||||
System.out.println(width + " " + length + " " + minePercentage);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -26,7 +26,6 @@ public class MinerunFactory implements GameFactory {
|
||||
|
||||
@Override
|
||||
public Minigame manufacture(Map<String, Option<?>> configuration) {
|
||||
System.out.println("Manufacture" + configuration.get("width").getAsInt());
|
||||
return new Minerun(configuration.get("width").getAsInt(), configuration.get("length").getAsInt(), configuration.get("percentage").getAsInt());
|
||||
}
|
||||
|
||||
|
||||
@@ -59,11 +59,6 @@ public class Stickfight extends Minigame {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onJoin(@NotNull AddEntityToInstanceEvent addEntityToInstanceEvent) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Pos getSpawn() {
|
||||
return new Pos(0.5, 51, 0.5);
|
||||
|
||||
Reference in New Issue
Block a user