Getting Ready for 1.21

This commit is contained in:
Navoei
2024-06-08 14:07:33 -05:00
parent 4b2dc1485a
commit 5f5a231a7a
5 changed files with 138 additions and 25 deletions

View File

@@ -39,7 +39,7 @@ dependencies {
implementation "io.papermc.paper:paper-api:${bukkit_version}" implementation "io.papermc.paper:paper-api:${bukkit_version}"
implementation "de.maxhenkel.voicechat:voicechat-api:${voicechat_api_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";
} }

View File

@@ -1,15 +1,15 @@
org.gradle.jvmargs=-Xmx2G org.gradle.jvmargs=-Xmx2G
java_version=21 java_version=22
mp3spi_version=1.9.5.4 mp3spi_version=1.9.5.4
bukkit_api_version=1.20 bukkit_api_version=1.20
bukkit_version=1.20.2-R0.1-SNAPSHOT bukkit_version=1.20.4-R0.1-SNAPSHOT
mod_id=customdiscsplugin mod_id=customdiscsplugin
# Target an older API to make it compatible with older versions of Simple Voice Chat # 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 plugin_version=2.6
maven_group=me.Navoei.customdiscsplugin maven_group=me.Navoei.customdiscsplugin

View File

@@ -10,37 +10,28 @@ import com.comphenix.protocol.events.PacketEvent;
import de.maxhenkel.voicechat.api.BukkitVoicechatService; import de.maxhenkel.voicechat.api.BukkitVoicechatService;
import me.Navoei.customdiscsplugin.command.CommandManager; import me.Navoei.customdiscsplugin.command.CommandManager;
import me.Navoei.customdiscsplugin.event.JukeBox; import me.Navoei.customdiscsplugin.event.JukeBox;
import org.apache.logging.log4j.LogManager; import java.util.logging.Logger;
import org.apache.logging.log4j.Logger;
import org.bukkit.Bukkit; import me.Navoei.customdiscsplugin.language.Lang;
import org.bukkit.Material;
import org.bukkit.NamespacedKey; import org.bukkit.NamespacedKey;
import org.bukkit.block.BlockFace;
import org.bukkit.block.Hopper;
import org.bukkit.block.Jukebox; import org.bukkit.block.Jukebox;
import org.bukkit.inventory.ItemStack; import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.persistence.PersistentDataType; import org.bukkit.persistence.PersistentDataType;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import javax.sound.sampled.LineUnavailableException; import java.io.*;
import javax.sound.sampled.UnsupportedAudioFileException;
import java.io.File;
import java.io.IOException;
import java.nio.file.Path;
import java.util.Objects; import java.util.Objects;
import java.util.logging.Level;
import static me.Navoei.customdiscsplugin.PlayerManager.getLengthSeconds;
public final class CustomDiscs extends JavaPlugin { 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; static CustomDiscs instance;
@Nullable @Nullable
private VoicePlugin voicechatPlugin; private VoicePlugin voicechatPlugin;
private Logger log;
public static YamlConfiguration LANG;
public static File LANG_FILE;
public float musicDiscDistance; public float musicDiscDistance;
public float musicDiscVolume; public float musicDiscVolume;
@@ -48,10 +39,12 @@ public final class CustomDiscs extends JavaPlugin {
public void onEnable() { public void onEnable() {
CustomDiscs.instance = this; CustomDiscs.instance = this;
log = getLogger();
BukkitVoicechatService service = getServer().getServicesManager().load(BukkitVoicechatService.class); BukkitVoicechatService service = getServer().getServicesManager().load(BukkitVoicechatService.class);
this.saveDefaultConfig(); this.saveDefaultConfig();
loadLang();
File musicData = new File(this.getDataFolder(), "musicdata"); File musicData = new File(this.getDataFolder(), "musicdata");
if (!(musicData.exists())) { if (!(musicData.exists())) {
@@ -61,9 +54,9 @@ public final class CustomDiscs extends JavaPlugin {
if (service != null) { if (service != null) {
voicechatPlugin = new VoicePlugin(); voicechatPlugin = new VoicePlugin();
service.registerPlugin(voicechatPlugin); service.registerPlugin(voicechatPlugin);
LOGGER.info("Successfully registered CustomDiscs plugin"); log.info("Successfully registered CustomDiscs plugin");
} else { } else {
LOGGER.info("Failed to register CustomDiscs plugin"); log.info("Failed to register CustomDiscs plugin");
} }
getServer().getPluginManager().registerEvents(new JukeBox(), this); getServer().getPluginManager().registerEvents(new JukeBox(), this);
@@ -102,7 +95,7 @@ public final class CustomDiscs extends JavaPlugin {
public void onDisable() { public void onDisable() {
if (voicechatPlugin != null) { if (voicechatPlugin != null) {
getServer().getServicesManager().unregister(voicechatPlugin); 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; 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();
}
}
} }

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

View File