Added translation to all Components
This commit is contained in:
@ -60,7 +60,7 @@ public class MineNetInstance extends InstanceContainer {
|
||||
if(target != null)
|
||||
player.setInstance(target);
|
||||
else
|
||||
player.kick(TranslatedComponent.raw("sample").getAssembled(player));
|
||||
player.kick(TranslatedComponent.byId("sample").getAssembled(player));
|
||||
});
|
||||
|
||||
MinecraftServer.getSchedulerManager().scheduleTask(
|
||||
|
@ -1,13 +1,12 @@
|
||||
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"));
|
||||
OTHER(Material.GRASS_BLOCK, TranslatedComponent.byId("GameType#other"), TranslatedComponent.byId("GameType#other_description")),
|
||||
PVP(Material.DIAMOND_SWORD, TranslatedComponent.byId("GameType#pvp"), TranslatedComponent.byId("GameType#pvp_description")),
|
||||
PVE(Material.DIAMOND_PICKAXE, TranslatedComponent.byId("GameType#pve"), TranslatedComponent.byId("GameType#pve_description"));
|
||||
|
||||
|
||||
Material icon;
|
||||
|
@ -6,6 +6,7 @@ import eu.mhsl.minenet.minigames.instance.game.minigame.config.restriction.IRest
|
||||
import eu.mhsl.minenet.minigames.instance.game.minigame.config.restriction.Restriction;
|
||||
import eu.mhsl.minenet.minigames.instance.game.minigame.config.restriction.RestrictionData;
|
||||
import eu.mhsl.minenet.minigames.instance.game.minigame.config.restriction.RestrictionHandler;
|
||||
import eu.mhsl.minenet.minigames.message.component.TranslatedComponent;
|
||||
import eu.mhsl.minenet.minigames.shared.inventory.InteractableInventory;
|
||||
import eu.mhsl.minenet.minigames.util.InventoryItemAlignment;
|
||||
import eu.mhsl.minenet.minigames.util.TextUtil;
|
||||
@ -34,10 +35,12 @@ public class GameConfigurationInventory extends InteractableInventory {
|
||||
|
||||
final private Room room;
|
||||
final private GameFactory factory;
|
||||
final private Player p;
|
||||
|
||||
public GameConfigurationInventory(Room room, GameFactory factory) {
|
||||
super(InventoryType.CHEST_5_ROW, factory.name());
|
||||
public GameConfigurationInventory(Room room, Player p, GameFactory factory) {
|
||||
super(InventoryType.CHEST_5_ROW, factory.name().getAssembled(p));
|
||||
this.room = room;
|
||||
this.p = p;
|
||||
this.factory = factory;
|
||||
|
||||
room.eventNode()
|
||||
@ -47,7 +50,13 @@ public class GameConfigurationInventory extends InteractableInventory {
|
||||
ConfigManager config = factory.configuration();
|
||||
|
||||
setClickableItem(
|
||||
ItemStack.builder(Material.RED_WOOL).displayName(Component.text("Abbrechen", NamedTextColor.RED)).build(),
|
||||
ItemStack.builder(Material.RED_WOOL)
|
||||
.displayName(
|
||||
TranslatedComponent.byId("common#back")
|
||||
.setColor(NamedTextColor.RED)
|
||||
.getAssembled(p)
|
||||
)
|
||||
.build(),
|
||||
0,
|
||||
itemClick -> itemClick.getPlayer().closeInventory(),
|
||||
true
|
||||
@ -56,7 +65,11 @@ public class GameConfigurationInventory extends InteractableInventory {
|
||||
setDummyItem(Material.BLACK_STAINED_GLASS_PANE,1);
|
||||
|
||||
setDummyItem(
|
||||
ItemStack.builder(Material.NAME_TAG).displayName(factory.name()).build(),
|
||||
ItemStack.builder(Material.NAME_TAG)
|
||||
.displayName(
|
||||
factory.name().setColor(NamedTextColor.GOLD).getAssembled(p)
|
||||
)
|
||||
.build(),
|
||||
4
|
||||
);
|
||||
|
||||
@ -70,7 +83,14 @@ public class GameConfigurationInventory extends InteractableInventory {
|
||||
|
||||
if(config == null) {
|
||||
setDummyItem(
|
||||
ItemStack.builder(Material.BARRIER).displayName(Component.text("Keine Optionen")).lore(TextUtil.autoWrap("Für dieses Spiel sind keine Einstellungen verfügbar!")).build(),
|
||||
ItemStack.builder(Material.BARRIER)
|
||||
.displayName(
|
||||
TranslatedComponent.byId("room#noOption").setColor(NamedTextColor.RED).getAssembled(p)
|
||||
)
|
||||
.lore(
|
||||
TranslatedComponent.assemble("room#noOptionDescription", p)
|
||||
)
|
||||
.build(),
|
||||
31
|
||||
);
|
||||
|
||||
@ -82,7 +102,7 @@ public class GameConfigurationInventory extends InteractableInventory {
|
||||
map.put(offset + current.get(), item);
|
||||
|
||||
setDummyItem(
|
||||
item.getCurrent(),
|
||||
item.getCurrent(p),
|
||||
offset + current.get()
|
||||
);
|
||||
}
|
||||
@ -98,7 +118,7 @@ public class GameConfigurationInventory extends InteractableInventory {
|
||||
|
||||
Option item = map.get(slot);
|
||||
setDummyItem(
|
||||
item.getNext(),
|
||||
item.getNext(p),
|
||||
slot
|
||||
);
|
||||
|
||||
@ -110,14 +130,12 @@ public class GameConfigurationInventory extends InteractableInventory {
|
||||
RestrictionHandler restrictionHandler = factory.globalRestrictions();
|
||||
RestrictionData restrictionData = new RestrictionData(room);
|
||||
|
||||
System.out.println("UpdatePlayButton:" + restrictionHandler.canPlay(restrictionData));
|
||||
|
||||
if(restrictionHandler.canPlay(restrictionData)) {
|
||||
|
||||
setClickableItem(
|
||||
ItemStack.builder(restrictionHandler.getWarnings(restrictionData).size() > 0 ? Material.YELLOW_WOOL : Material.GREEN_WOOL)
|
||||
.displayName(Component.text("Start", NamedTextColor.GREEN))
|
||||
.lore(restrictionHandler.getWarnings(restrictionData).stream().map(Component::text).collect(Collectors.toList()))
|
||||
.displayName(TranslatedComponent.byId("restriction#success").setColor(NamedTextColor.GREEN).getAssembled(p))
|
||||
.lore(restrictionHandler.getWarnings(restrictionData).stream().map(translatedComponent -> translatedComponent.getAssembled(p)).collect(Collectors.toList()))
|
||||
.build(),
|
||||
8,
|
||||
itemClick -> {
|
||||
@ -130,12 +148,12 @@ public class GameConfigurationInventory extends InteractableInventory {
|
||||
|
||||
setClickableItem(
|
||||
ItemStack.builder(Material.RED_WOOL)
|
||||
.displayName(Component.text("Bedinungen nicht erfült", NamedTextColor.RED))
|
||||
.displayName(TranslatedComponent.byId("restriction#fail").setColor(NamedTextColor.RED).getAssembled(p))
|
||||
.lore(
|
||||
restrictionHandler.getRestrictions()
|
||||
.stream()
|
||||
.filter(iRestriction -> iRestriction.calculate(restrictionData).getType().equals(Restriction.Type.FAIL))
|
||||
.map(iRestriction -> Component.text(iRestriction.calculate(restrictionData).getName()))
|
||||
.map(iRestriction -> iRestriction.calculate(restrictionData).getDescription().getAssembled(p))
|
||||
.collect(Collectors.toList()))
|
||||
.build(),
|
||||
8,
|
||||
|
@ -2,6 +2,7 @@ package eu.mhsl.minenet.minigames.instance.game.minigame.config;
|
||||
|
||||
import eu.mhsl.minenet.minigames.instance.game.minigame.Minigame;
|
||||
import eu.mhsl.minenet.minigames.instance.game.minigame.config.restriction.RestrictionHandler;
|
||||
import eu.mhsl.minenet.minigames.message.component.TranslatedComponent;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.minestom.server.instance.block.Block;
|
||||
import net.minestom.server.item.Material;
|
||||
@ -11,7 +12,7 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public interface GameFactory {
|
||||
Component name();
|
||||
TranslatedComponent name();
|
||||
ConfigManager configuration();
|
||||
default RestrictionHandler globalRestrictions() {
|
||||
return new RestrictionHandler();
|
||||
@ -20,8 +21,8 @@ public interface GameFactory {
|
||||
default Material symbol() {
|
||||
return Material.GRASS_BLOCK;
|
||||
}
|
||||
default Component description() {
|
||||
return Component.text("- Keine Beschreibung -");
|
||||
default TranslatedComponent description() {
|
||||
return TranslatedComponent.byId("GameFactory#missingDescription");
|
||||
}
|
||||
|
||||
Minigame manufacture(Map<String, Option<?>> configuration);
|
||||
|
@ -1,7 +1,10 @@
|
||||
package eu.mhsl.minenet.minigames.instance.game.minigame.config;
|
||||
|
||||
import eu.mhsl.minenet.minigames.instance.game.minigame.config.restriction.RestrictionHandler;
|
||||
import eu.mhsl.minenet.minigames.message.component.TranslatedComponent;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import net.minestom.server.entity.Player;
|
||||
import net.minestom.server.item.ItemStack;
|
||||
import net.minestom.server.item.Material;
|
||||
|
||||
@ -10,13 +13,13 @@ import java.util.List;
|
||||
public abstract class Option<T> {
|
||||
private RestrictionHandler restrictionHandler;
|
||||
private final Material item;
|
||||
private final String name;
|
||||
private final TranslatedComponent name;
|
||||
private final String id;
|
||||
protected T currentValue;
|
||||
private final List<T> options;
|
||||
private int pointer = 0;
|
||||
|
||||
public Option(String id, Material item, String name, List<T> options) {
|
||||
public Option(String id, Material item, TranslatedComponent name, List<T> options) {
|
||||
this.id = id;
|
||||
this.item = item;
|
||||
this.name = name;
|
||||
@ -34,16 +37,18 @@ public abstract class Option<T> {
|
||||
}
|
||||
|
||||
|
||||
public ItemStack getNext() {
|
||||
public ItemStack getNext(Player p) {
|
||||
if(++pointer >= options.size()) pointer = 0;
|
||||
currentValue = options.get(pointer);
|
||||
return getCurrent();
|
||||
return getCurrent(p);
|
||||
}
|
||||
|
||||
public ItemStack getCurrent() {
|
||||
public ItemStack getCurrent(Player p) {
|
||||
int amount = Integer.parseInt(options.get(pointer).toString());
|
||||
return ItemStack.builder(item)
|
||||
.displayName(Component.text(name).append(Component.text(" - ")).append(Component.text(amount)))
|
||||
.displayName(name.getAssembled(p))
|
||||
.lore(TranslatedComponent.byId("optionCommon#value").setColor(NamedTextColor.GOLD).getAssembled(p)
|
||||
.append(Component.text(": ")).append(Component.text(amount)))
|
||||
.build();
|
||||
}
|
||||
|
||||
|
@ -1,12 +1,13 @@
|
||||
package eu.mhsl.minenet.minigames.instance.game.minigame.config.common;
|
||||
|
||||
import eu.mhsl.minenet.minigames.instance.game.minigame.config.Option;
|
||||
import eu.mhsl.minenet.minigames.message.component.TranslatedComponent;
|
||||
import net.minestom.server.item.Material;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class BoolOption extends Option<Boolean> {
|
||||
public BoolOption(String id, Material item, String name) {
|
||||
public BoolOption(String id, Material item, TranslatedComponent name) {
|
||||
super(id, item, name, List.of(true, false));
|
||||
}
|
||||
}
|
||||
|
@ -2,13 +2,14 @@ package eu.mhsl.minenet.minigames.instance.game.minigame.config.common;
|
||||
|
||||
import eu.mhsl.minenet.minigames.instance.game.minigame.config.Option;
|
||||
import eu.mhsl.minenet.minigames.instance.game.minigame.config.restriction.RestrictionHandler;
|
||||
import eu.mhsl.minenet.minigames.message.component.TranslatedComponent;
|
||||
import net.minestom.server.item.Material;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class NumericOption extends Option<Integer> {
|
||||
|
||||
public NumericOption(String id, Material item, String name, Integer... options) {
|
||||
public NumericOption(String id, Material item, TranslatedComponent name, Integer... options) {
|
||||
super(id, item, name, List.of(options));
|
||||
}
|
||||
}
|
||||
|
@ -1,13 +1,15 @@
|
||||
package eu.mhsl.minenet.minigames.instance.game.minigame.config.restriction;
|
||||
|
||||
import eu.mhsl.minenet.minigames.message.component.TranslatedComponent;
|
||||
|
||||
public class Restriction {
|
||||
final private String name;
|
||||
final private String description;
|
||||
final private String warnMessage;
|
||||
final private TranslatedComponent name;
|
||||
final private TranslatedComponent description;
|
||||
final private TranslatedComponent warnMessage;
|
||||
|
||||
final private Type type;
|
||||
|
||||
public Restriction(String name, String description, String warnMessage, Type type) {
|
||||
public Restriction(TranslatedComponent name, TranslatedComponent description, TranslatedComponent warnMessage, Type type) {
|
||||
this.name = name;
|
||||
this.description = description;
|
||||
this.warnMessage = warnMessage;
|
||||
@ -18,15 +20,15 @@ public class Restriction {
|
||||
}
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
public TranslatedComponent getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
public TranslatedComponent getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public String getWarnMessage() {
|
||||
public TranslatedComponent getWarnMessage() {
|
||||
return warnMessage;
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,7 @@
|
||||
package eu.mhsl.minenet.minigames.instance.game.minigame.config.restriction;
|
||||
|
||||
import eu.mhsl.minenet.minigames.message.component.TranslatedComponent;
|
||||
|
||||
import java.lang.reflect.Array;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@ -30,8 +32,8 @@ public class RestrictionHandler {
|
||||
.noneMatch(iRestriction -> iRestriction.calculate(data).getType().equals(Restriction.Type.FAIL));
|
||||
}
|
||||
|
||||
public List<String> getWarnings(RestrictionData data) {
|
||||
List<String> warnings = new ArrayList<>();
|
||||
public List<TranslatedComponent> getWarnings(RestrictionData data) {
|
||||
List<TranslatedComponent> warnings = new ArrayList<>();
|
||||
for (IRestriction r : this.restrictions) {
|
||||
Restriction calculated = r.calculate(data);
|
||||
if(!calculated.getType().equals(Restriction.Type.WARN)) continue;
|
||||
|
@ -3,6 +3,7 @@ package eu.mhsl.minenet.minigames.instance.game.minigame.config.restriction.comm
|
||||
import eu.mhsl.minenet.minigames.instance.game.minigame.config.restriction.IRestriction;
|
||||
import eu.mhsl.minenet.minigames.instance.game.minigame.config.restriction.Restriction;
|
||||
import eu.mhsl.minenet.minigames.instance.game.minigame.config.restriction.RestrictionData;
|
||||
import eu.mhsl.minenet.minigames.message.component.TranslatedComponent;
|
||||
|
||||
public class MaximalPlayeramountGameRestriction implements IRestriction {
|
||||
private int max;
|
||||
@ -14,8 +15,8 @@ public class MaximalPlayeramountGameRestriction implements IRestriction {
|
||||
@Override
|
||||
public Restriction calculate(RestrictionData data) {
|
||||
return new Restriction(
|
||||
"Minimal players needed",
|
||||
"Minimal players",
|
||||
TranslatedComponent.byId("restriction#maxPlayersInRoom"),
|
||||
TranslatedComponent.byId("restriction#maxPlayersInRoomDescription"),
|
||||
null,
|
||||
data.getRoom().getAllMembers().size() > this.max ? Restriction.Type.FAIL : Restriction.Type.OK
|
||||
);
|
||||
|
@ -1,23 +0,0 @@
|
||||
package eu.mhsl.minenet.minigames.instance.game.minigame.config.restriction.common;
|
||||
|
||||
import eu.mhsl.minenet.minigames.instance.game.minigame.config.restriction.IRestriction;
|
||||
import eu.mhsl.minenet.minigames.instance.game.minigame.config.restriction.Restriction;
|
||||
import eu.mhsl.minenet.minigames.instance.game.minigame.config.restriction.RestrictionData;
|
||||
|
||||
public class MaximalPlayeramountInstanceRestriction implements IRestriction {
|
||||
final private int max;
|
||||
|
||||
public MaximalPlayeramountInstanceRestriction(int max) {
|
||||
this.max = max;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Restriction calculate(RestrictionData data) {
|
||||
return new Restriction(
|
||||
"Maxplayers",
|
||||
"Maximale spieleranzahl",
|
||||
null,
|
||||
data.getRoom().getPlayers().size() > this.max ? Restriction.Type.FAIL : Restriction.Type.OK
|
||||
);
|
||||
}
|
||||
}
|
@ -3,6 +3,7 @@ package eu.mhsl.minenet.minigames.instance.game.minigame.config.restriction.comm
|
||||
import eu.mhsl.minenet.minigames.instance.game.minigame.config.restriction.IRestriction;
|
||||
import eu.mhsl.minenet.minigames.instance.game.minigame.config.restriction.Restriction;
|
||||
import eu.mhsl.minenet.minigames.instance.game.minigame.config.restriction.RestrictionData;
|
||||
import eu.mhsl.minenet.minigames.message.component.TranslatedComponent;
|
||||
|
||||
import javax.xml.transform.OutputKeys;
|
||||
|
||||
@ -16,8 +17,8 @@ public class MinimalPlayeramountGameRestriction implements IRestriction {
|
||||
@Override
|
||||
public Restriction calculate(RestrictionData data) {
|
||||
return new Restriction(
|
||||
"Minimal players",
|
||||
"minimal Players needed",
|
||||
TranslatedComponent.byId("restriction#minPlayersInRoom"),
|
||||
TranslatedComponent.byId("restriction#minPlayersInRoomDescription"),
|
||||
null,
|
||||
data.getRoom().getAllMembers().size() < this.min ? Restriction.Type.FAIL : Restriction.Type.OK
|
||||
);
|
||||
|
@ -1,23 +0,0 @@
|
||||
package eu.mhsl.minenet.minigames.instance.game.minigame.config.restriction.common;
|
||||
|
||||
import eu.mhsl.minenet.minigames.instance.game.minigame.config.restriction.IRestriction;
|
||||
import eu.mhsl.minenet.minigames.instance.game.minigame.config.restriction.Restriction;
|
||||
import eu.mhsl.minenet.minigames.instance.game.minigame.config.restriction.RestrictionData;
|
||||
|
||||
public class MinimalPlayeramountInstanceRestriction implements IRestriction {
|
||||
final int min;
|
||||
|
||||
public MinimalPlayeramountInstanceRestriction(int min) {
|
||||
this.min = min;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Restriction calculate(RestrictionData data) {
|
||||
return new Restriction(
|
||||
"Minimal players",
|
||||
"Minimal amount of players needed",
|
||||
null,
|
||||
data.getRoom().getPlayers().size() < min ? Restriction.Type.FAIL : Restriction.Type.OK
|
||||
);
|
||||
}
|
||||
}
|
@ -5,6 +5,7 @@ import eu.mhsl.minenet.minigames.instance.game.minigame.config.GameFactory;
|
||||
import eu.mhsl.minenet.minigames.instance.game.minigame.config.Option;
|
||||
import eu.mhsl.minenet.minigames.instance.game.minigame.config.ConfigManager;
|
||||
import eu.mhsl.minenet.minigames.instance.game.minigame.config.common.NumericOption;
|
||||
import eu.mhsl.minenet.minigames.message.component.TranslatedComponent;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.minestom.server.item.Material;
|
||||
|
||||
@ -12,16 +13,21 @@ import java.util.Map;
|
||||
|
||||
public class DeathcubeFactory implements GameFactory {
|
||||
@Override
|
||||
public Component name() {
|
||||
return Component.text("Deathcube");
|
||||
public TranslatedComponent name() {
|
||||
return TranslatedComponent.byId("game_Deathcube#name");
|
||||
}
|
||||
|
||||
@Override
|
||||
public TranslatedComponent description() {
|
||||
return TranslatedComponent.byId("game_Deathcube#description");
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConfigManager configuration() {
|
||||
return new ConfigManager()
|
||||
.addOption(new NumericOption("radius", Material.HEART_OF_THE_SEA, "Radius", 10, 30, 50, 100))
|
||||
.addOption(new NumericOption("height", Material.SCAFFOLDING, "Height", 50, 100, 150, 200))
|
||||
.addOption(new NumericOption("percentage", Material.COBWEB, "Percent of blocks", 5, 7, 9, 11, 13));
|
||||
.addOption(new NumericOption("radius", Material.HEART_OF_THE_SEA, TranslatedComponent.byId("optionCommon#radius"), 10, 30, 50, 100))
|
||||
.addOption(new NumericOption("height", Material.SCAFFOLDING, TranslatedComponent.byId("optionCommon#height"), 50, 100, 150, 200))
|
||||
.addOption(new NumericOption("percentage", Material.COBWEB, TranslatedComponent.byId("game_Deathcube#optionPercentageBlocks"), 5, 7, 9, 11, 13));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -5,6 +5,7 @@ import eu.mhsl.minenet.minigames.instance.game.minigame.config.ConfigManager;
|
||||
import eu.mhsl.minenet.minigames.instance.game.minigame.config.GameFactory;
|
||||
import eu.mhsl.minenet.minigames.instance.game.minigame.config.Option;
|
||||
import eu.mhsl.minenet.minigames.instance.game.minigame.config.common.NumericOption;
|
||||
import eu.mhsl.minenet.minigames.message.component.TranslatedComponent;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.minestom.server.item.Material;
|
||||
|
||||
@ -12,16 +13,16 @@ import java.util.Map;
|
||||
|
||||
public class MinerunFactory implements GameFactory {
|
||||
@Override
|
||||
public Component name() {
|
||||
return Component.text("Deathcube");
|
||||
public TranslatedComponent name() {
|
||||
return TranslatedComponent.byId("game_Minerun#name");
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConfigManager configuration() {
|
||||
return new ConfigManager()
|
||||
.addOption(new NumericOption("width", Material.OAK_FENCE, "Width", 10, 30, 50, 100))
|
||||
.addOption(new NumericOption("length", Material.ZOMBIE_HEAD, "Length", 50, 100, 150, 200))
|
||||
.addOption(new NumericOption("percentage", Material.LIGHT_WEIGHTED_PRESSURE_PLATE, "Percent of mines", 30, 40, 50, 60, 70));
|
||||
.addOption(new NumericOption("width", Material.OAK_FENCE, TranslatedComponent.byId("optionCommon#width"), 10, 30, 50, 100))
|
||||
.addOption(new NumericOption("length", Material.ZOMBIE_HEAD, TranslatedComponent.byId("optionCommon#length"), 50, 100, 150, 200))
|
||||
.addOption(new NumericOption("percentage", Material.LIGHT_WEIGHTED_PRESSURE_PLATE, TranslatedComponent.byId("game_Minerun#optionPercentageMiens"), 30, 40, 50, 60, 70));
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -35,7 +36,7 @@ public class MinerunFactory implements GameFactory {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Component description() {
|
||||
return Component.text("Weiche druckplatten aus");
|
||||
public TranslatedComponent description() {
|
||||
return TranslatedComponent.byId("game_Minerun#description");
|
||||
}
|
||||
}
|
||||
|
@ -7,24 +7,27 @@ import eu.mhsl.minenet.minigames.instance.game.minigame.config.Option;
|
||||
import eu.mhsl.minenet.minigames.instance.game.minigame.config.common.NumericOption;
|
||||
import eu.mhsl.minenet.minigames.instance.game.minigame.config.restriction.RestrictionHandler;
|
||||
import eu.mhsl.minenet.minigames.instance.game.minigame.config.restriction.common.MaximalPlayeramountGameRestriction;
|
||||
import eu.mhsl.minenet.minigames.instance.game.minigame.config.restriction.common.MaximalPlayeramountInstanceRestriction;
|
||||
import eu.mhsl.minenet.minigames.instance.game.minigame.config.restriction.common.MinimalPlayeramountGameRestriction;
|
||||
import eu.mhsl.minenet.minigames.instance.game.minigame.config.restriction.common.MinimalPlayeramountInstanceRestriction;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import eu.mhsl.minenet.minigames.message.component.TranslatedComponent;
|
||||
import net.minestom.server.item.Material;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class StickFightFactory implements GameFactory {
|
||||
@Override
|
||||
public Component name() {
|
||||
return Component.text("Stickfight");
|
||||
public TranslatedComponent name() {
|
||||
return TranslatedComponent.byId("game_Stickfight#name");
|
||||
}
|
||||
|
||||
@Override
|
||||
public TranslatedComponent description() {
|
||||
return TranslatedComponent.byId("game_Stickfight#description");
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConfigManager configuration() {
|
||||
return new ConfigManager()
|
||||
.addOption(new NumericOption("lenght", Material.SANDSTONE, "Länge", 5, 7, 9, 11));
|
||||
.addOption(new NumericOption("length", Material.SANDSTONE, TranslatedComponent.byId("optionCommon#length"), 5, 7, 9, 11));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -4,6 +4,7 @@ import eu.mhsl.minenet.minigames.instance.game.minigame.Minigame;
|
||||
import eu.mhsl.minenet.minigames.instance.game.minigame.config.GameFactory;
|
||||
import eu.mhsl.minenet.minigames.instance.game.minigame.config.ConfigManager;
|
||||
import eu.mhsl.minenet.minigames.instance.game.minigame.config.Option;
|
||||
import eu.mhsl.minenet.minigames.message.component.TranslatedComponent;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.minestom.server.item.Material;
|
||||
|
||||
@ -11,8 +12,8 @@ import java.util.Map;
|
||||
|
||||
public class TrafficLightRaceFactory implements GameFactory {
|
||||
@Override
|
||||
public Component name() {
|
||||
return Component.text("TrafficLightRace");
|
||||
public TranslatedComponent name() {
|
||||
return TranslatedComponent.byId("game_TrafficlightRace#name");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -30,6 +30,6 @@ public class RoomSelector extends InteractableEntity {
|
||||
|
||||
@Override
|
||||
public void onInteract(@NotNull PlayerEntityInteractEvent playerEntityInteractEvent) {
|
||||
playerEntityInteractEvent.getPlayer().openInventory(new HubInventory());
|
||||
playerEntityInteractEvent.getPlayer().openInventory(new HubInventory(playerEntityInteractEvent.getPlayer()));
|
||||
}
|
||||
}
|
||||
|
@ -1,22 +1,24 @@
|
||||
package eu.mhsl.minenet.minigames.instance.hub.inventory;
|
||||
|
||||
import eu.mhsl.minenet.minigames.instance.room.Room;
|
||||
import eu.mhsl.minenet.minigames.message.component.TranslatedComponent;
|
||||
import eu.mhsl.minenet.minigames.shared.inventory.InteractableInventory;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.minestom.server.entity.Player;
|
||||
import net.minestom.server.inventory.InventoryType;
|
||||
import net.minestom.server.item.ItemHideFlag;
|
||||
import net.minestom.server.item.ItemStack;
|
||||
import net.minestom.server.item.Material;
|
||||
|
||||
public class HubInventory extends InteractableInventory {
|
||||
public HubInventory() {
|
||||
super(InventoryType.CHEST_3_ROW, Component.text("MineNet Servernetzwerk"));
|
||||
public HubInventory(Player p) {
|
||||
super(InventoryType.CHEST_3_ROW, TranslatedComponent.assemble("hub#invTitle", p));
|
||||
|
||||
setClickableItem(
|
||||
ItemStack
|
||||
.builder(Material.WRITABLE_BOOK)
|
||||
.displayName(Component.text("Create own room"))
|
||||
.lore(Component.text("Create new empty room"))
|
||||
.displayName(TranslatedComponent.assemble("hub#create", p))
|
||||
.lore(TranslatedComponent.assemble("hub#create_description", p))
|
||||
.meta(metaBuilder -> metaBuilder.hideFlag(ItemHideFlag.HIDE_ATTRIBUTES))
|
||||
.build(),
|
||||
12,
|
||||
@ -27,11 +29,11 @@ public class HubInventory extends InteractableInventory {
|
||||
setClickableItem(
|
||||
ItemStack
|
||||
.builder(Material.KNOWLEDGE_BOOK)
|
||||
.displayName(Component.text("Browse room"))
|
||||
.lore(Component.text("Browse existing rooms"))
|
||||
.displayName(TranslatedComponent.assemble("hub#join", p))
|
||||
.lore(TranslatedComponent.assemble("hub#join_description", p))
|
||||
.build(),
|
||||
14,
|
||||
itemClick -> itemClick.getPlayer().openInventory(new JoinInventory())
|
||||
itemClick -> itemClick.getPlayer().openInventory(new JoinInventory(itemClick.getPlayer()))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ package eu.mhsl.minenet.minigames.instance.hub.inventory;
|
||||
|
||||
import eu.mhsl.minenet.minigames.instance.room.Room;
|
||||
import eu.mhsl.minenet.minigames.message.Icon;
|
||||
import eu.mhsl.minenet.minigames.message.component.TranslatedComponent;
|
||||
import eu.mhsl.minenet.minigames.message.type.ChatMessage;
|
||||
import eu.mhsl.minenet.minigames.shared.inventory.InteractableInventory;
|
||||
import eu.mhsl.minenet.minigames.instance.hub.Hub;
|
||||
@ -21,10 +22,10 @@ import java.util.Locale;
|
||||
|
||||
public class JoinInventory extends InteractableInventory {
|
||||
private String typedText = "";
|
||||
private final String prefix = "name:";
|
||||
private final String prefix = "Name:";
|
||||
|
||||
public JoinInventory() {
|
||||
super(InventoryType.ANVIL, Component.text("Enter username"));
|
||||
public JoinInventory(Player p) {
|
||||
super(InventoryType.ANVIL, TranslatedComponent.assemble("hub#join_title", p));
|
||||
|
||||
setClickableItem(
|
||||
ItemStack.builder(Material.PLAYER_HEAD)
|
||||
@ -57,7 +58,7 @@ public class JoinInventory extends InteractableInventory {
|
||||
if(target != null)
|
||||
Room.setRoom(player, target);
|
||||
else
|
||||
new ChatMessage(Icon.ERROR).appendStatic("The room").quote(typedText).appendStatic("could not be found!").send(player);
|
||||
new ChatMessage(Icon.ERROR).appendTranslated("hub#join_notFound").appendStatic(" " + typedText).send(player);
|
||||
}
|
||||
|
||||
private String formatInput(String raw) {
|
||||
|
@ -1,7 +1,7 @@
|
||||
package eu.mhsl.minenet.minigames.instance.room.entity;
|
||||
|
||||
import eu.mhsl.minenet.minigames.instance.room.Room;
|
||||
import eu.mhsl.minenet.minigames.instance.room.inventory.MinigameTypeSelectInventory;
|
||||
import eu.mhsl.minenet.minigames.instance.room.inventory.MinigameSelectInventory;
|
||||
import eu.mhsl.minenet.minigames.message.Icon;
|
||||
import eu.mhsl.minenet.minigames.message.type.ChatMessage;
|
||||
import eu.mhsl.minenet.minigames.shared.entity.InteractableEntity;
|
||||
@ -44,6 +44,6 @@ public class GameSelector extends InteractableEntity {
|
||||
return;
|
||||
}
|
||||
|
||||
playerEntityInteractEvent.getPlayer().openInventory(new MinigameTypeSelectInventory(room));
|
||||
playerEntityInteractEvent.getPlayer().openInventory(new MinigameSelectInventory(room, playerEntityInteractEvent.getPlayer()));
|
||||
}
|
||||
}
|
||||
|
@ -1,14 +1,15 @@
|
||||
package eu.mhsl.minenet.minigames.instance.room.inventory;
|
||||
|
||||
import eu.mhsl.minenet.minigames.instance.game.Game;
|
||||
import eu.mhsl.minenet.minigames.instance.game.GameList;
|
||||
import eu.mhsl.minenet.minigames.instance.game.GameType;
|
||||
import eu.mhsl.minenet.minigames.instance.game.minigame.config.GameConfigurationInventory;
|
||||
import eu.mhsl.minenet.minigames.instance.game.minigame.config.GameFactory;
|
||||
import eu.mhsl.minenet.minigames.instance.room.Room;
|
||||
import eu.mhsl.minenet.minigames.message.component.TranslatedComponent;
|
||||
import eu.mhsl.minenet.minigames.shared.inventory.InteractableInventory;
|
||||
import eu.mhsl.minenet.minigames.util.InventoryItemAlignment;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.minestom.server.entity.Player;
|
||||
import net.minestom.server.inventory.InventoryType;
|
||||
import net.minestom.server.item.ItemHideFlag;
|
||||
import net.minestom.server.item.ItemStack;
|
||||
@ -16,28 +17,27 @@ import net.minestom.server.item.Material;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class MinigameTypeSelectInventory extends InteractableInventory {
|
||||
public class MinigameSelectInventory extends InteractableInventory {
|
||||
final private Room room;
|
||||
public MinigameTypeSelectInventory(Room room) {
|
||||
super(InventoryType.CHEST_6_ROW, Component.text("MineNet Servernetzwerk"));
|
||||
final private Player p;
|
||||
public MinigameSelectInventory(Room room, Player p) {
|
||||
super(InventoryType.CHEST_6_ROW, TranslatedComponent.assemble("room#invTitle", p));
|
||||
this.room = room;
|
||||
this.p = p;
|
||||
|
||||
int typeCount = 0;
|
||||
InventoryItemAlignment itemAlignment = new InventoryItemAlignment(GameType.values().length, 1);
|
||||
for (GameType type : GameType.values()) {
|
||||
setClickableItem(
|
||||
ItemStack.builder(type.getIcon())
|
||||
.displayName(type.getTitle().asComponent())
|
||||
.lore(type.getDescription().asComponent())
|
||||
.displayName(type.getTitle().getAssembled(p))
|
||||
.lore(type.getDescription().getAssembled(p))
|
||||
.build(),
|
||||
itemAlignment.next().get(),
|
||||
itemClick -> {
|
||||
drawGames(type);
|
||||
}
|
||||
);
|
||||
typeCount++;
|
||||
}
|
||||
|
||||
for(int i = 9; i <= 17; i++) {
|
||||
@ -61,12 +61,12 @@ public class MinigameTypeSelectInventory extends InteractableInventory {
|
||||
|
||||
setClickableItem(
|
||||
ItemStack.builder(gameFactory.symbol())
|
||||
.displayName(gameFactory.name())
|
||||
.lore(gameFactory.description())
|
||||
.displayName(gameFactory.name().getAssembled(p))
|
||||
.lore(gameFactory.description().getAssembled(p))
|
||||
.meta(metaBuilder -> metaBuilder.hideFlag(ItemHideFlag.HIDE_ATTRIBUTES))
|
||||
.build(),
|
||||
offset + itemAlignment.next().get(),
|
||||
itemClick -> itemClick.getPlayer().openInventory(new GameConfigurationInventory(room, gameFactory))
|
||||
itemClick -> itemClick.getPlayer().openInventory(new GameConfigurationInventory(room, itemClick.getPlayer(), gameFactory))
|
||||
);
|
||||
}
|
||||
}
|
@ -4,7 +4,9 @@ import eu.mhsl.minenet.minigames.Resource;
|
||||
import net.minestom.server.entity.Player;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.logging.Logger;
|
||||
@ -36,7 +38,7 @@ public class Languages {
|
||||
|
||||
private void readAll() {
|
||||
File locales = new File(Resource.LOCALES.getPath().toString());
|
||||
File[] files = locales.listFiles(File::canRead);
|
||||
File[] files = Arrays.stream(locales.listFiles(File::canRead)).filter(file -> file.getName().endsWith("map.csv")).toArray(File[]::new);
|
||||
|
||||
if(files.length == 0) {
|
||||
logger.warning("Failed to find any Language-files!");
|
||||
@ -52,13 +54,13 @@ public class Languages {
|
||||
boolean computedFileHeader = false;
|
||||
|
||||
for(String line : Files.readAllLines(locale.toPath())) {
|
||||
line = line.replaceAll("[^\\p{L}\\s,#_+.:;]+", "");
|
||||
//line = line.replaceAll("[^\\p{L}\\s,#_+.:;]+", "");
|
||||
line = line.replaceAll("[^a-zA-Z0-9äöüÄÖÜ ,:;#_+]", "");
|
||||
String[] columns = line.split(";");
|
||||
|
||||
if(columns.length < 1) continue;
|
||||
|
||||
if(columns[0].equalsIgnoreCase("map")) {
|
||||
|
||||
if(columns[0].endsWith("map")) {
|
||||
// file header
|
||||
computedFileHeader = true;
|
||||
int index = -1;
|
||||
|
@ -30,7 +30,7 @@ public abstract class TranslatableMessage implements Sendable {
|
||||
}
|
||||
|
||||
public TranslatableMessage appendTranslated(String mapId) {
|
||||
chain.add(TranslatedComponent.raw(mapId));
|
||||
chain.add(TranslatedComponent.byId(mapId));
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -9,6 +9,6 @@ public class NamespacedTranslatable {
|
||||
}
|
||||
|
||||
public TranslatedComponent get(String mapId) {
|
||||
return TranslatedComponent.raw(namespace + mapId);
|
||||
return TranslatedComponent.byId(namespace + mapId);
|
||||
}
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ package eu.mhsl.minenet.minigames.message.component;
|
||||
import eu.mhsl.minenet.minigames.lang.Languages;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.ComponentLike;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import net.minestom.server.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@ -10,10 +11,16 @@ public class TranslatedComponent implements ComponentLike, Translatable {
|
||||
private String mapId;
|
||||
private String result;
|
||||
|
||||
public static TranslatedComponent raw(String mapId) {
|
||||
private NamedTextColor color;
|
||||
|
||||
public static TranslatedComponent byId(String mapId) {
|
||||
return new TranslatedComponent(mapId);
|
||||
}
|
||||
|
||||
public static Component assemble(String mapid, Player p) {
|
||||
return new TranslatedComponent(mapid).getAssembled(p);
|
||||
}
|
||||
|
||||
private TranslatedComponent(String mapId) {
|
||||
this.mapId = mapId;
|
||||
}
|
||||
@ -31,9 +38,17 @@ public class TranslatedComponent implements ComponentLike, Translatable {
|
||||
return asComponent();
|
||||
}
|
||||
|
||||
public TranslatedComponent setColor(NamedTextColor color) {
|
||||
this.color = color;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Component asComponent() {
|
||||
assemble(Languages.getInstance().getLanguage(Languages.defaultLanguage).getEntry(mapId));
|
||||
return Component.text(result);
|
||||
//assemble(Languages.getInstance().getLanguage(Languages.defaultLanguage).getEntry(mapId));
|
||||
if(color != null)
|
||||
return Component.text(result, color);
|
||||
else
|
||||
return Component.text(result);
|
||||
}
|
||||
}
|
||||
|
@ -44,10 +44,10 @@ public class Score {
|
||||
callback.run();
|
||||
|
||||
new ChatMessage(Icon.STAR)
|
||||
.appendStatic("Ergebnisse:").indent(1)
|
||||
.appendTranslated("score#result").indent(1)
|
||||
.list(getMapFormatted())
|
||||
.indent(-1).newLine()
|
||||
.appendStatic("Vielen Dank für's Spielen!")
|
||||
.appendTranslated("score#thanks")
|
||||
.send(instance.getPlayers());
|
||||
|
||||
closed = true;
|
||||
@ -59,7 +59,7 @@ public class Score {
|
||||
if(results.containsKey(p)) return;
|
||||
results.put(p, countResults()+1);
|
||||
|
||||
new TitleMessage(Duration.ofMillis(500), Duration.ofSeconds(1)).appendStatic(Component.text("Fertig", NamedTextColor.GREEN)).send(p);
|
||||
new TitleMessage(Duration.ofMillis(500), Duration.ofSeconds(1)).appendTranslated("score#finish").send(p);
|
||||
|
||||
checkGameEnd(null);
|
||||
}
|
||||
|
@ -6,6 +6,7 @@ import net.minestom.server.network.UuidProvider;
|
||||
import net.minestom.server.network.player.PlayerConnection;
|
||||
import net.minestom.server.utils.mojang.MojangUtils;
|
||||
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.UUID;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
|
Reference in New Issue
Block a user