Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch to new paginator #37

Merged
merged 2 commits into from
Jul 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Releases can be found on the [releases tab](https://github.com/APDevTeam/Movecra

Development builds can be found on the [GitHub Actions tab](https://github.com/APDevTeam/Movecraft-Warfare/actions) of this repository.

Previous builds can be found on[our SpigotMC page](https://www.spigotmc.org/resources/movecraft-warfare.87359/).
Previous builds can be found on [our SpigotMC page](https://www.spigotmc.org/resources/movecraft-warfare.87359/).

## Building
Run the following to build Movecraft-Warfare:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
import net.countercraft.movecraft.craft.CraftManager;
import net.countercraft.movecraft.craft.type.CraftType;
import net.countercraft.movecraft.repair.MovecraftRepair;
import net.countercraft.movecraft.util.TopicPaginator;
import net.countercraft.movecraft.util.ChatUtils;
import net.countercraft.movecraft.util.ComponentPaginator;
import net.countercraft.movecraft.warfare.MovecraftWarfare;
import net.countercraft.movecraft.warfare.config.Config;
import net.countercraft.movecraft.warfare.features.siege.Siege;
Expand All @@ -15,6 +16,7 @@
import net.countercraft.movecraft.warfare.features.siege.events.SiegePreStartEvent;
import net.countercraft.movecraft.warfare.localisation.I18nSupport;
import net.countercraft.movecraft.worldguard.MovecraftWorldGuard;
import net.kyori.adventure.text.Component;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
Expand Down Expand Up @@ -249,16 +251,22 @@ private boolean listCommand(CommandSender commandSender, String[] args) {
return true;
}

TopicPaginator paginator = new TopicPaginator("Sieges");
ComponentPaginator paginator = new ComponentPaginator(
Component.text("Sieges"),
pageNumber -> "/siege list " + pageNumber);
for (Siege siege : siegeManager.getSieges()) {
paginator.addLine("- " + siege.getName());
paginator.addLine(Component.text("- ").append(Component.text(siege.getName())));
}
if (!paginator.isInBounds(page)) {
commandSender.sendMessage(MOVECRAFT_COMMAND_PREFIX
+ I18nSupport.getInternationalisedString("Paginator - Invalid Page") + " \"" + args[1] + "\"");
commandSender.sendMessage(Component.empty()
.append(ChatUtils.commandPrefix())
.append(net.countercraft.movecraft.localisation.I18nSupport.getInternationalisedComponent("Paginator - Invalid page"))
.append(Component.text(" \""))
.append(Component.text(args[0]))
.append(Component.text("\"")));
return true;
}
for (String line : paginator.getPage(page))
for (Component line : paginator.getPage(page))
commandSender.sendMessage(line);
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,27 @@

import net.countercraft.movecraft.warfare.MovecraftWarfare;
import net.countercraft.movecraft.warfare.config.Config;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.TextComponent;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;

import java.io.*;
import java.util.Properties;
import java.util.logging.Level;

public class I18nSupport {
private static Properties langFile;
private static Properties languageFile;

public static void init() {
langFile = new Properties();
languageFile = new Properties();

File langDirectory = new File(MovecraftWarfare.getInstance().getDataFolder().getAbsolutePath() + "/localisation");
if (!langDirectory.exists()) {
langDirectory.mkdirs();
}

InputStream stream = null;

try {
stream = new FileInputStream(langDirectory.getAbsolutePath()+"/mcwlang_" + Config.Locale + ".properties");
} catch (FileNotFoundException e) {
Expand All @@ -32,18 +35,28 @@ public static void init() {
}

try {
langFile.load(stream);
languageFile.load(stream);
} catch (IOException e) {
e.printStackTrace();
}
}

public static String getInternationalisedString(String key) {
String ret = langFile.getProperty(key);
private static String get(String key) {
String ret = languageFile.getProperty(key);
if (ret != null) {
return ret;
} else {
return key;
}
}

@Deprecated(forRemoval = true)
public static String getInternationalisedString(String key) {
return get(key);
}

@Contract("_ -> new")
public static @NotNull TextComponent getInternationalisedComponent(String key){
return Component.text(get(key));
}
}