mirror of
https://github.com/Crazy-Crew/CrazyAuctions.git
synced 2025-01-06 19:18:05 +01:00
add locale class
This commit is contained in:
parent
ca89bd6371
commit
aaa07fbd27
@ -42,7 +42,7 @@ public class ConfigSettings implements SettingsHolder {
|
||||
""
|
||||
};
|
||||
|
||||
conf.setComment("settings", header);
|
||||
conf.setComment("misc", header);
|
||||
}
|
||||
|
||||
@Comment("Allow damage items to be auctioned off.")
|
||||
|
@ -0,0 +1,35 @@
|
||||
package us.crazycrew.crazyauctions.configurations;
|
||||
|
||||
import ch.jalu.configme.SettingsHolder;
|
||||
import ch.jalu.configme.configurationdata.CommentsConfiguration;
|
||||
|
||||
/**
|
||||
* @author RyderBelserion
|
||||
* @author BadBones69
|
||||
*
|
||||
* Date: 3/4/2023
|
||||
* Time: Unknown
|
||||
* Last Edited: 3/4/2023 @ 10:23 PM
|
||||
*
|
||||
* Description: The locale file.
|
||||
*/
|
||||
public class LocaleSettings implements SettingsHolder {
|
||||
|
||||
// Empty constructor required by SettingsHolder
|
||||
public LocaleSettings() {}
|
||||
|
||||
@Override
|
||||
public void registerComments(CommentsConfiguration conf) {
|
||||
String[] header = {
|
||||
"Support: https://discord.gg/crazycrew",
|
||||
"Github: https://github.com/Crazy-Crew",
|
||||
"",
|
||||
"Issues: https://github.com/Crazy-Crew/CrazyAuctions/issues",
|
||||
"Features: https://github.com/Crazy-Crew/CrazyAuctions/discussions",
|
||||
"",
|
||||
"We need translations for this locale file. Please don't hesitate to submit any."
|
||||
};
|
||||
|
||||
conf.setComment("misc", header);
|
||||
}
|
||||
}
|
@ -0,0 +1,90 @@
|
||||
package us.crazycrew.crazyauctions.utils;
|
||||
|
||||
import us.crazycrew.crazycore.CrazyLogger;
|
||||
import java.io.BufferedOutputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.net.JarURLConnection;
|
||||
import java.net.URL;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Enumeration;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipFile;
|
||||
|
||||
public class FileUtils {
|
||||
|
||||
/**
|
||||
* Extracts files from inside the .jar into an output
|
||||
* <p>
|
||||
* @param input the directory in the .jar
|
||||
* @param output the output wherever you use this.
|
||||
* @param replace if we should replace or not.
|
||||
*/
|
||||
public static void extract(String input, Path output, boolean replace) {
|
||||
URL directory = FileUtils.class.getResource(input);
|
||||
|
||||
if (directory == null) CrazyLogger.debug("<#E0115F>Could not find <#11e092>" + input + " <#E0115F>in the jar.");
|
||||
|
||||
assert directory != null;
|
||||
if (!directory.getProtocol().equals("jar"))
|
||||
CrazyLogger.debug("<#E0115F>Failed because the protocol does not equal .jar!");
|
||||
|
||||
ZipFile jar;
|
||||
try {
|
||||
CrazyLogger.debug("<#E0115F>Starting to extract files from <#11e092>" + input + " <#E0115F>directory in the jar.");
|
||||
|
||||
jar = ((JarURLConnection) directory.openConnection()).getJarFile();
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
String filePath = input.substring(1);
|
||||
Enumeration<? extends ZipEntry> fileEntries = jar.entries();
|
||||
|
||||
while (fileEntries.hasMoreElements()) {
|
||||
ZipEntry entry = fileEntries.nextElement();
|
||||
String entryName = entry.getName();
|
||||
|
||||
if (!entryName.startsWith(filePath)) continue;
|
||||
|
||||
Path outFile = output.resolve(entryName);
|
||||
boolean exists = Files.exists(outFile);
|
||||
|
||||
if (!replace && exists) continue;
|
||||
|
||||
if (entry.isDirectory()) {
|
||||
if (exists) {
|
||||
CrazyLogger.debug("<#E0115F>File already exists.");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
Files.createDirectories(outFile);
|
||||
|
||||
CrazyLogger.debug("<#E0115F>Directories have been created.");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
try (InputStream inputStream = jar.getInputStream(entry); OutputStream outputStream = new BufferedOutputStream(new FileOutputStream(outFile.toFile()))) {
|
||||
byte[] buffer = new byte[4096];
|
||||
|
||||
int readCount;
|
||||
|
||||
while ((readCount = inputStream.read(buffer)) > 0) {
|
||||
outputStream.write(buffer, 0, readCount);
|
||||
}
|
||||
|
||||
outputStream.flush();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -8,6 +8,7 @@ import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import us.crazycrew.crazyauctions.CrazyAuctions;
|
||||
import us.crazycrew.crazyauctions.configurations.ConfigSettings;
|
||||
import us.crazycrew.crazyauctions.configurations.LocaleSettings;
|
||||
import us.crazycrew.crazyauctions.configurations.PluginSettings;
|
||||
import us.crazycrew.crazyauctions.configurations.migrations.PluginMigrationService;
|
||||
import us.crazycrew.crazycore.CrazyLogger;
|
||||
@ -34,6 +35,7 @@ public class AuctionsStarter implements PluginBootstrap {
|
||||
|
||||
private static SettingsManager pluginConfig;
|
||||
private static SettingsManager config;
|
||||
private static SettingsManager locale;
|
||||
|
||||
@Override
|
||||
public void bootstrap(@NotNull PluginProviderContext context) {
|
||||
@ -48,6 +50,11 @@ public class AuctionsStarter implements PluginBootstrap {
|
||||
.withYamlFile(new File(context.getDataDirectory().toFile(), "config.yml"))
|
||||
.configurationData(ConfigSettings.class)
|
||||
.create();
|
||||
|
||||
locale = SettingsManagerBuilder
|
||||
.withYamlFile(new File(context.getDataDirectory().toFile() + "/locale/", pluginConfig.getProperty(PluginSettings.LOCALE_FILE)))
|
||||
.configurationData(LocaleSettings.class)
|
||||
.create();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -77,4 +84,8 @@ public class AuctionsStarter implements PluginBootstrap {
|
||||
public static SettingsManager getConfig() {
|
||||
return config;
|
||||
}
|
||||
|
||||
public static SettingsManager getLocale() {
|
||||
return locale;
|
||||
}
|
||||
}
|
@ -2,6 +2,9 @@ package us.crazycrew.crazyauctions.utils.misc;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Color;
|
||||
import us.crazycrew.crazyauctions.api.interfaces.Universal;
|
||||
import us.crazycrew.crazyauctions.configurations.PluginSettings;
|
||||
import us.crazycrew.crazyauctions.loader.AuctionsStarter;
|
||||
import java.util.List;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
@ -12,11 +15,12 @@ import java.util.regex.Pattern;
|
||||
*
|
||||
* Created: 2/18/2023
|
||||
* Time: Unknown
|
||||
* Last Edited: 2/28/2023 @ 3:04 AM
|
||||
* Last Edited: 3/4/2023 @ 11:15 PM
|
||||
*
|
||||
* Description: Color utilities.
|
||||
*/
|
||||
public class ColorUtils {
|
||||
public class ColorUtils implements Universal {
|
||||
|
||||
private static final Pattern HEX_PATTERN = Pattern.compile("#[a-fA-F\\d]{6}");
|
||||
|
||||
public static String color(String message) {
|
||||
@ -70,11 +74,7 @@ public class ColorUtils {
|
||||
return ChatColor.stripColor(msg);
|
||||
}
|
||||
|
||||
public static String getPrefix(String string) {
|
||||
return "";
|
||||
}
|
||||
|
||||
public static String getPrefix() {
|
||||
return getPrefix("");
|
||||
return AuctionsStarter.getPluginConfig().getProperty(PluginSettings.COMMAND_PREFIX);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user