Added translation to all Components

This commit is contained in:
2022-10-03 20:56:14 +02:00
parent 18db3514e3
commit 6907a767c6
247 changed files with 4113 additions and 654 deletions

View File

@ -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(

View File

@ -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;

View File

@ -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,

View File

@ -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);

View File

@ -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();
}

View File

@ -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));
}
}

View File

@ -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));
}
}

View File

@ -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;
}

View File

@ -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;

View File

@ -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
);

View File

@ -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
);
}
}

View File

@ -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
);

View File

@ -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
);
}
}

View File

@ -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

View File

@ -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");
}
}

View File

@ -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

View File

@ -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

View File

@ -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()));
}
}

View File

@ -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()))
);
}
}

View File

@ -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) {

View File

@ -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()));
}
}

View File

@ -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))
);
}
}

View File

@ -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;

View File

@ -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;
}

View File

@ -9,6 +9,6 @@ public class NamespacedTranslatable {
}
public TranslatedComponent get(String mapId) {
return TranslatedComponent.raw(namespace + mapId);
return TranslatedComponent.byId(namespace + mapId);
}
}

View File

@ -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);
}
}

View File

@ -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);
}

View File

@ -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;

View File

@ -0,0 +1 @@
,elias,ELIAS-PC,03.10.2022 16:40,file:///home/elias/.config/libreoffice/4;

View File

@ -1,10 +1,81 @@
map,en_us,de_de
localName,English,Deutsch
name,English,German
symbol,eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvY2Q5MTQ1Njg3N2Y1NGJmMWFjZTI1MWU0Y2VlNDBkYmE1OTdkMmNjNDAzNjJjYjhmNGVkNzExZTUwYjBiZTViMyJ9fX0=,eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvNWU3ODk5YjQ4MDY4NTg2OTdlMjgzZjA4NGQ5MTczZmU0ODc4ODY0NTM3NzQ2MjZiMjRiZDhjZmVjYzc3YjNmIn19fQ==
sample,The brown fox jumps over the white fence,Der braune Fuchs springt über den weißen Zaun
,,
ns:common#,,
select_language,Please select your prefered Language,Bitte wähle deine bevorzugte Sprache!
welcome,Welcome!,Willkommen!
asdasd,asd,ads
map;en_us;de_de
localName;English;Deutsch
name;English;German
symbol;eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvY2Q5MTQ1Njg3N2Y1NGJmMWFjZTI1MWU0Y2VlNDBkYmE1OTdkMmNjNDAzNjJjYjhmNGVkNzExZTUwYjBiZTViMyJ9fX0=;eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvNWU3ODk5YjQ4MDY4NTg2OTdlMjgzZjA4NGQ5MTczZmU0ODc4ODY0NTM3NzQ2MjZiMjRiZDhjZmVjYzc3YjNmIn19fQ==
sample;The quick brown fox jumps over the lazy dog;Victor jagt zwölf Boxkämpfer quer über den großen Sylter Deich
;;
ns:common#;;
select_language;Please select your prefered Language;Bitte wähle deine bevorzugte Sprache!
welcome;Welcome!;Willkommen!
back;Back;Zurück
forward;Next;Nächste
;;
ns:GameType#;;
other;Other games;Andere Spiele
other_description;Games which does not fit into other Categories;Spiele welche nicht in die anderen Kategorien passen
pvp;Player vs Player;Spieler gegen Spieler
pvp_description;Fight against other Players;Kämpfe gegen andere Spieler
pve;Player vs Enviroment;Spieler gegen Umwelt
pve_description;Surivie the world or fight entities;Überlebe die Welt oder kämpfe gegen Mobs
;;
ns:hub#;;
invTitle;MineNet Servernetwork;MineNet Servernetzwerk
create;Create your personal Lobby;Erstelle deine persönliche Lobby
create_description;Let other players join your Lobby to play with them;Lasse andere Spieler auf deine Lobby joinen um mit ihnen zusammen zu spielen
join;Join existing Lobby;Betrete eine bestehende Lobby
join_description;All you need is the Username of the Lobby you want to join;Alles was du benötigst ist der Nutzername des Besitzers, dessen Lobby du beitreten möchtest
join_title;Enter Username;Benutzername
join_notFound;Lobby not found: ;Lobby konnte nicht gefunden werden:
;;
ns:score#;;
result;Results;Ergebnisse
thanks;Thank you for Playing;Danke fürs spielen
;;
;;
ns:restriction#;;
fail;Some requirements are not met;Bedinungen sind nicht erfüllt
success;Play;Spielen
minPlayersInRoom;Minimal amount of Players in Lobby;Minimale Anzahl von Spielern in deiner Lobby
minPlayersInRoomDescription;You need more Players in your room to play this;Die Anzahl der Spieler ist zu gering um dieses Spiel zu starten
maxPlayersInRoom;Maximal amount of Players in Lobby;Maximale Anzahl von Spielern in deiner Lobby
maxPlayersInRoomDescription;There are too many players in your room;Die Anzahl der Spieler in deiner Lobby ist zu hoch für dieses Spiel
;;
ns:optionCommon#;;
value;Value;Wert
width;Width;Breite
length;Length;Länge
height;Height;Höhe
radius;Radius;Radius
;;
;;
;;
;;
;;
;;
;;
;;
ns:room#;;
invTitle;Select a Minigame;Wähle einen Spielmodus
noOption;No options here;Keine Optionen hier
noOptionDescription;There are no options for this Game;Es gibt keine Einstellungen für dieses Spiel
;;
ns:GameFactory#;;
missingDescription;No description;Keine Beschreibung
;;
ns:game_Minerun#;;
name;Minerun;Minenrennen
description;Ditch deadly Mines in the ground an be the first in the goal;Weiche den tödlichen Bodenmienen aus und sei der erste im Ziel
optionPercentageMines;Percentage of Miens;Prozentsatz der Minen
;;
ns:game_Deathcube#;;
name;Deathcube;Todeswürfel
description;Find a way to jump higher and be the first on the top;Finde einen weg nach oben und sei der erste im Ziel
optionPercentageBlocks;Percentage of Blocks;Prozentsatz der Blöcke
;;
ns:game_Stickfight#;;
name;Stickfight;Stockschlacht
description;Push your opponents off the Bridge;Stoße deine Gegener von der Brücke
;;
ns:game_TrafficlightRace#;;
name;Red light green light;Rotes licht, Grünes licht
description;Only go forward if the Trafficlights show green;Gehe nur bei Grün vorran

1 map en_us de_de
2 localName English Deutsch
3 name English German
4 symbol eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvY2Q5MTQ1Njg3N2Y1NGJmMWFjZTI1MWU0Y2VlNDBkYmE1OTdkMmNjNDAzNjJjYjhmNGVkNzExZTUwYjBiZTViMyJ9fX0= eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvNWU3ODk5YjQ4MDY4NTg2OTdlMjgzZjA4NGQ5MTczZmU0ODc4ODY0NTM3NzQ2MjZiMjRiZDhjZmVjYzc3YjNmIn19fQ==
5 sample The brown fox jumps over the white fence The quick brown fox jumps over the lazy dog Der braune Fuchs springt über den weißen Zaun Victor jagt zwölf Boxkämpfer quer über den großen Sylter Deich
6
7 ns:common#
8 select_language Please select your prefered Language Bitte wähle deine bevorzugte Sprache!
9 welcome Welcome! Willkommen!
10 asdasd back asd Back ads Zurück
11 forward Next Nächste
12
13 ns:GameType#
14 other Other games Andere Spiele
15 other_description Games which does not fit into other Categories Spiele welche nicht in die anderen Kategorien passen
16 pvp Player vs Player Spieler gegen Spieler
17 pvp_description Fight against other Players Kämpfe gegen andere Spieler
18 pve Player vs Enviroment Spieler gegen Umwelt
19 pve_description Surivie the world or fight entities Überlebe die Welt oder kämpfe gegen Mobs
20
21 ns:hub#
22 invTitle MineNet Servernetwork MineNet Servernetzwerk
23 create Create your personal Lobby Erstelle deine persönliche Lobby
24 create_description Let other players join your Lobby to play with them Lasse andere Spieler auf deine Lobby joinen um mit ihnen zusammen zu spielen
25 join Join existing Lobby Betrete eine bestehende Lobby
26 join_description All you need is the Username of the Lobby you want to join Alles was du benötigst ist der Nutzername des Besitzers, dessen Lobby du beitreten möchtest
27 join_title Enter Username Benutzername
28 join_notFound Lobby not found: Lobby konnte nicht gefunden werden:
29
30 ns:score#
31 result Results Ergebnisse
32 thanks Thank you for Playing Danke für‘s spielen
33
34
35 ns:restriction#
36 fail Some requirements are not met Bedinungen sind nicht erfüllt
37 success Play Spielen
38 minPlayersInRoom Minimal amount of Players in Lobby Minimale Anzahl von Spielern in deiner Lobby
39 minPlayersInRoomDescription You need more Players in your room to play this Die Anzahl der Spieler ist zu gering um dieses Spiel zu starten
40 maxPlayersInRoom Maximal amount of Players in Lobby Maximale Anzahl von Spielern in deiner Lobby
41 maxPlayersInRoomDescription There are too many players in your room Die Anzahl der Spieler in deiner Lobby ist zu hoch für dieses Spiel
42
43 ns:optionCommon#
44 value Value Wert
45 width Width Breite
46 length Length Länge
47 height Height Höhe
48 radius Radius Radius
49
50
51
52
53
54
55
56
57 ns:room#
58 invTitle Select a Minigame Wähle einen Spielmodus
59 noOption No options here Keine Optionen hier
60 noOptionDescription There are no options for this Game Es gibt keine Einstellungen für dieses Spiel
61
62 ns:GameFactory#
63 missingDescription No description Keine Beschreibung
64
65 ns:game_Minerun#
66 name Minerun Minenrennen
67 description Ditch deadly Mines in the ground an be the first in the goal Weiche den tödlichen Bodenmienen aus und sei der erste im Ziel
68 optionPercentageMines Percentage of Miens Prozentsatz der Minen
69
70 ns:game_Deathcube#
71 name Deathcube Todeswürfel
72 description Find a way to jump higher and be the first on the top Finde einen weg nach oben und sei der erste im Ziel
73 optionPercentageBlocks Percentage of Blocks Prozentsatz der Blöcke
74
75 ns:game_Stickfight#
76 name Stickfight Stockschlacht
77 description Push your opponents off the Bridge Stoße deine Gegener von der Brücke
78
79 ns:game_TrafficlightRace#
80 name Red light green light Rotes licht, Grünes licht
81 description Only go forward if the Trafficlights show green Gehe nur bei Grün vorran