mirror of
https://github.com/SPAWNRYS-ban/FUCK-CustomDiscs.git
synced 2025-12-10 13:30:24 +05:00
Getting Ready for 1.21
This commit is contained in:
@@ -39,7 +39,7 @@ dependencies {
|
||||
implementation "io.papermc.paper:paper-api:${bukkit_version}"
|
||||
implementation "de.maxhenkel.voicechat:voicechat-api:${voicechat_api_version}"
|
||||
|
||||
compileOnly group: "com.comphenix.protocol", name: "ProtocolLib", version: "5.0.0";
|
||||
compileOnly group: "com.comphenix.protocol", name: "ProtocolLib", version: "5.1.0";
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
org.gradle.jvmargs=-Xmx2G
|
||||
|
||||
java_version=21
|
||||
java_version=22
|
||||
|
||||
mp3spi_version=1.9.5.4
|
||||
|
||||
bukkit_api_version=1.20
|
||||
bukkit_version=1.20.2-R0.1-SNAPSHOT
|
||||
bukkit_version=1.20.4-R0.1-SNAPSHOT
|
||||
mod_id=customdiscsplugin
|
||||
|
||||
# Target an older API to make it compatible with older versions of Simple Voice Chat
|
||||
voicechat_api_version=2.4.11
|
||||
voicechat_api_version=2.5.0
|
||||
|
||||
plugin_version=2.6
|
||||
maven_group=me.Navoei.customdiscsplugin
|
||||
|
||||
@@ -10,37 +10,28 @@ import com.comphenix.protocol.events.PacketEvent;
|
||||
import de.maxhenkel.voicechat.api.BukkitVoicechatService;
|
||||
import me.Navoei.customdiscsplugin.command.CommandManager;
|
||||
import me.Navoei.customdiscsplugin.event.JukeBox;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import me.Navoei.customdiscsplugin.language.Lang;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.block.Hopper;
|
||||
import org.bukkit.block.Jukebox;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.persistence.PersistentDataType;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import javax.sound.sampled.LineUnavailableException;
|
||||
import javax.sound.sampled.UnsupportedAudioFileException;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Path;
|
||||
import java.io.*;
|
||||
import java.util.Objects;
|
||||
|
||||
import static me.Navoei.customdiscsplugin.PlayerManager.getLengthSeconds;
|
||||
import java.util.logging.Level;
|
||||
|
||||
public final class CustomDiscs extends JavaPlugin {
|
||||
|
||||
public static final String PLUGIN_ID = "CustomDiscs";
|
||||
public static final Logger LOGGER = LogManager.getLogger(PLUGIN_ID);
|
||||
static CustomDiscs instance;
|
||||
|
||||
@Nullable
|
||||
private VoicePlugin voicechatPlugin;
|
||||
|
||||
private Logger log;
|
||||
public static YamlConfiguration LANG;
|
||||
public static File LANG_FILE;
|
||||
public float musicDiscDistance;
|
||||
public float musicDiscVolume;
|
||||
|
||||
@@ -48,10 +39,12 @@ public final class CustomDiscs extends JavaPlugin {
|
||||
public void onEnable() {
|
||||
|
||||
CustomDiscs.instance = this;
|
||||
log = getLogger();
|
||||
|
||||
BukkitVoicechatService service = getServer().getServicesManager().load(BukkitVoicechatService.class);
|
||||
|
||||
this.saveDefaultConfig();
|
||||
loadLang();
|
||||
|
||||
File musicData = new File(this.getDataFolder(), "musicdata");
|
||||
if (!(musicData.exists())) {
|
||||
@@ -61,9 +54,9 @@ public final class CustomDiscs extends JavaPlugin {
|
||||
if (service != null) {
|
||||
voicechatPlugin = new VoicePlugin();
|
||||
service.registerPlugin(voicechatPlugin);
|
||||
LOGGER.info("Successfully registered CustomDiscs plugin");
|
||||
log.info("Successfully registered CustomDiscs plugin");
|
||||
} else {
|
||||
LOGGER.info("Failed to register CustomDiscs plugin");
|
||||
log.info("Failed to register CustomDiscs plugin");
|
||||
}
|
||||
|
||||
getServer().getPluginManager().registerEvents(new JukeBox(), this);
|
||||
@@ -102,7 +95,7 @@ public final class CustomDiscs extends JavaPlugin {
|
||||
public void onDisable() {
|
||||
if (voicechatPlugin != null) {
|
||||
getServer().getServicesManager().unregister(voicechatPlugin);
|
||||
LOGGER.info("Successfully unregistered CustomDiscs plugin");
|
||||
log.info("Successfully unregistered CustomDiscs plugin");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -110,4 +103,71 @@ public final class CustomDiscs extends JavaPlugin {
|
||||
return instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load the lang.yml file.
|
||||
* @return The lang.yml config.
|
||||
*/
|
||||
public void loadLang() {
|
||||
File lang = new File(getDataFolder(), "lang.yml");
|
||||
if (!lang.exists()) {
|
||||
try {
|
||||
getDataFolder().mkdir();
|
||||
lang.createNewFile();
|
||||
InputStream defConfigStream = this.getResource("lang.yml");
|
||||
if (defConfigStream != null) {
|
||||
copyInputStreamToFile(defConfigStream, lang);
|
||||
YamlConfiguration defConfig = YamlConfiguration.loadConfiguration(lang);
|
||||
defConfig.save(lang);
|
||||
Lang.setFile(defConfig);
|
||||
}
|
||||
} catch(IOException e) {
|
||||
e.printStackTrace(); // So they notice
|
||||
log.severe("Failed to create lang.yml for MyHomes.");
|
||||
log.severe("Now disabling...");
|
||||
this.setEnabled(false); // Without it loaded, we can't send them messages
|
||||
}
|
||||
}
|
||||
YamlConfiguration conf = YamlConfiguration.loadConfiguration(lang);
|
||||
for(Lang item:Lang.values()) {
|
||||
if (conf.getString(item.getPath()) == null) {
|
||||
conf.set(item.getPath(), item.getDefault());
|
||||
}
|
||||
}
|
||||
Lang.setFile(conf);
|
||||
LANG = conf;
|
||||
LANG_FILE = lang;
|
||||
try {
|
||||
conf.save(getLangFile());
|
||||
} catch(IOException e) {
|
||||
log.log(Level.WARNING, "Failed to save lang.yml for MyHomes");
|
||||
log.log(Level.WARNING, "Now disabling...");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the lang.yml config.
|
||||
* @return The lang.yml config.
|
||||
*/
|
||||
public YamlConfiguration getLang() {
|
||||
return LANG;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the lang.yml file.
|
||||
* @return The lang.yml file.
|
||||
*/
|
||||
public File getLangFile() {
|
||||
return LANG_FILE;
|
||||
}
|
||||
|
||||
public static void copyInputStreamToFile(InputStream input, File file) {
|
||||
|
||||
try (OutputStream output = new FileOutputStream(file)) {
|
||||
input.transferTo(output);
|
||||
} catch (IOException ioException) {
|
||||
ioException.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
53
src/main/java/me/Navoei/customdiscsplugin/language/Lang.java
Normal file
53
src/main/java/me/Navoei/customdiscsplugin/language/Lang.java
Normal file
@@ -0,0 +1,53 @@
|
||||
package me.Navoei.customdiscsplugin.language;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
|
||||
public enum Lang {
|
||||
SOME_TEXT("text", "text");
|
||||
|
||||
private final String path;
|
||||
private final String def;
|
||||
private static YamlConfiguration LANG;
|
||||
|
||||
/**
|
||||
* Lang enum constructor.
|
||||
* @param path The string path.
|
||||
* @param start The default string.
|
||||
*/
|
||||
Lang(String path, String start) {
|
||||
this.path = path;
|
||||
this.def = start;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the {@code YamlConfiguration} to use.
|
||||
* @param config The config to set.
|
||||
*/
|
||||
public static void setFile(YamlConfiguration config) {
|
||||
LANG = config;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
if (this == PREFIX)
|
||||
return ChatColor.translateAlternateColorCodes('&', LANG.getString(this.path, def)) + " ";
|
||||
return ChatColor.translateAlternateColorCodes('&', LANG.getString(this.path, def));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the default value of the path.
|
||||
* @return The default value of the path.
|
||||
*/
|
||||
public String getDefault() {
|
||||
return this.def;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the path to the string.
|
||||
* @return The path to the string.
|
||||
*/
|
||||
public String getPath() {
|
||||
return this.path;
|
||||
}
|
||||
}
|
||||
0
src/main/resources/lang.yml
Normal file
0
src/main/resources/lang.yml
Normal file
Reference in New Issue
Block a user