mirror of
https://github.com/SPAWNRYS-ban/FUCK-CustomDiscs.git
synced 2025-12-18 17:29:37 +05:00
Getting Ready for 1.21
This commit is contained in:
@@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user