Skip to content

Commit

Permalink
Merge pull request #30 from T0biii/dev
Browse files Browse the repository at this point in the history
Version 5.0
  • Loading branch information
T0biii authored Aug 15, 2020
2 parents 5450034 + 0a360f1 commit 6cffbe8
Show file tree
Hide file tree
Showing 12 changed files with 225 additions and 43 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/maven.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
- name: Build with Maven
run: mvn -B package --file pom.xml
- name: Upload artifact
uses: actions/upload-artifact@v1.0.0
uses: actions/upload-artifact@v2
with:
# Artifact name
name: JoinMusic
Expand Down
6 changes: 6 additions & 0 deletions .idea/google-java-format.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions JoinMusic.iml
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@
<orderEntry type="library" scope="PROVIDED" name="Maven: com.google.code.gson:gson:2.8.0" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: net.md-5:bungeecord-chat:1.13-SNAPSHOT" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: org.yaml:snakeyaml:1.25" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: com.github.koca2000:NoteBlockAPI:1.5.0" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: com.github.koca2000:NoteBlockAPI:1.6.0" level="project" />
<orderEntry type="library" name="Maven: org.bstats:bstats-bukkit:1.7" level="project" />
<orderEntry type="library" name="Maven: com.googlecode.json-simple:json-simple:1.1" level="project" />
<orderEntry type="library" name="Maven: com.googlecode.json-simple:json-simple:1.1.1" level="project" />
<orderEntry type="library" name="Maven: junit:junit:4.10" level="project" />
<orderEntry type="library" name="Maven: org.hamcrest:hamcrest-core:1.1" level="project" />
</component>
</module>
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>de.t0biii</groupId>
<artifactId>JoinMusic</artifactId>
<version>4.0</version>
<version>5.0</version>
<packaging>jar</packaging>

<name>JoinMusic</name>
Expand All @@ -33,7 +33,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.3</version>
<version>3.2.4</version>
<configuration>
<relocations>
<relocation>
Expand Down Expand Up @@ -103,7 +103,7 @@
<dependency>
<groupId>com.github.koca2000</groupId>
<artifactId>NoteBlockAPI</artifactId>
<version>1.5.0</version>
<version>1.6.0</version>
<scope>provided</scope>
</dependency>
<!-- bStats API -->
Expand Down
65 changes: 52 additions & 13 deletions src/main/java/de/t0biii/music/commands/CMD_PlayMusic.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,47 +25,81 @@ public boolean onCommand(CommandSender sender, Command cmd, String commandLabel,
if (sender.hasPermission("JoinMusic.use")) {
if (sender instanceof Player) {
Player player = ((Player) sender).getPlayer();
String noperm = plugin.getConfig().getString("messages.no-permission");
String noperm = plugin.getConfig().getString("messages.no-permission").replaceAll("&", "§");
if (args.length == 1) {
if (args[0].equalsIgnoreCase("reload")) {
if (sender.hasPermission("JoinMusic.command.reload")) {
try {
plugin.reloadConfig();
plugin.cm.reloadConfigs();
player
.sendMessage(plugin.prefix + ChatColor.DARK_AQUA + plugin.getConfig().getString("messages.reload"));
.sendMessage(plugin.prefix + plugin.getConfig().getString("messages.reload").replaceAll("&", "));
} catch (Exception exception) {
player.sendMessage(plugin.prefix + ChatColor.RED + "Reload failed!");
}
} else {
sender.sendMessage(plugin.prefix + ChatColor.RED + noperm);
sender.sendMessage(plugin.prefix + noperm);
}
} else if (args[0].equalsIgnoreCase("stop")) {
if (sender.hasPermission("JoinMusic.command.stop")) {
Music.stop(player);
player.sendMessage(plugin.prefix + ChatColor.DARK_AQUA + plugin.getConfig().getString("messages.stop"));
player.sendMessage(plugin.prefix + plugin.getConfig().getString("messages.stop").replaceAll("&", "));
} else {
sender.sendMessage(plugin.prefix + ChatColor.RED + noperm);
sender.sendMessage(plugin.prefix + noperm);
}
} else {
} else if (args[0].equalsIgnoreCase("disable") && plugin.getConfig().getBoolean("options.allowDisabling")) {
if(sender.hasPermission("JoinMusic.command.disableOwn")) {
plugin.cm.getUserConfigs().set(player.getUniqueId().toString(),true);
sender.sendMessage(plugin.prefix + plugin.getConfig().getString("messages.disabled").replaceAll("&", "§"));
plugin.cm.saveUserConfigs();
}else {
sender.sendMessage(plugin.prefix + noperm);
}
}else if (args[0].equalsIgnoreCase("enable") && plugin.getConfig().getBoolean("options.allowDisabling")) {
if(sender.hasPermission("JoinMusic.command.disableOwn")) {
plugin.cm.getUserConfigs().set(player.getUniqueId().toString(),null);
plugin.cm.saveUserConfigs();
sender.sendMessage(plugin.prefix + plugin.getConfig().getString("messages.enabled").replaceAll("&", "§"));
} else {
sender.sendMessage(plugin.prefix + noperm);
}
} else{
sendInstructions(player);
}
} else {
sendInstructions(player);
}
} else {
sender.sendMessage(plugin.prefix + "This command is not for console!");
if(args.length == 1 && args[0].equalsIgnoreCase("reload")) {
try {
plugin.cm.reloadConfigs();
sender
.sendMessage(plugin.cprefix + plugin.getConfig().getString("messages.reload"));
} catch (Exception exception) {
sender.sendMessage(plugin.cprefix + ChatColor.RED + "Reload failed!");
}
}else {
sender.sendMessage(plugin.cprefix + "Only reload is for console!");
}
}
}
return true;
}

private void sendInstructions(CommandSender sender) {
sender.sendMessage(ChatColor.GRAY + "======= " + ChatColor.GREEN + plugin.prefix + ChatColor.GRAY + "=======");
sender.sendMessage(ChatColor.GRAY + "/jm " + ChatColor.GREEN + "reload " + ChatColor.DARK_GRAY + "| "
+ ChatColor.GREEN + "Config Reload!");
if(sender.hasPermission("JoinMusic.command.reload")) {
sender.sendMessage(ChatColor.GRAY + "/jm " + ChatColor.GREEN + "reload " + ChatColor.DARK_GRAY + "| "
+ ChatColor.GREEN + "Config Reload!");
}
sender.sendMessage(ChatColor.GRAY + "/jm " + ChatColor.GREEN + "stop " + ChatColor.DARK_GRAY + "| "
+ ChatColor.GREEN + "Stop Song Playing!");
sender.sendMessage(ChatColor.GRAY + "======= " + ChatColor.GREEN + plugin.prefix + ChatColor.GRAY + "=======");
+ ChatColor.GREEN + plugin.getConfig().getString("messages.help.stop"));
if(sender.hasPermission("JoinMusic.command.disableOwn")) {
sender.sendMessage(ChatColor.GRAY + "/jm " + ChatColor.GREEN + "disable " + ChatColor.DARK_GRAY + "| "
+ ChatColor.GREEN + plugin.getConfig().getString("messages.help.disableOwn"));
sender.sendMessage(ChatColor.GRAY + "/jm " + ChatColor.GREEN + "enable " + ChatColor.DARK_GRAY + "| "
+ ChatColor.GREEN + plugin.getConfig().getString("messages.help.enableOwn"));
sender.sendMessage(ChatColor.GRAY + "======= " + ChatColor.GREEN + plugin.prefix + ChatColor.GRAY + "=======");
}
}

public static TabCompleter tabCompleter = new TabCompleter() {
Expand All @@ -79,8 +113,13 @@ public List<String> onTabComplete(CommandSender commandSender, Command command,
if (commandSender.hasPermission("JoinMusic.command.stop")) {
list.add("stop");
}
if (commandSender.hasPermission("JoinMusic.command.disableOwn")) {
list.add("enable");
list.add("disable");
}
if (!commandSender.hasPermission("JoinMusic.command.stop")
&& !commandSender.hasPermission("JoinMusic.command.reload")) {
&& !commandSender.hasPermission("JoinMusic.command.reload")
&& !commandSender.hasPermission("JoinMusic.command.disableOwn")) {
list.add(" ");
}
return list;
Expand Down
65 changes: 61 additions & 4 deletions src/main/java/de/t0biii/music/domain/ConfigManager.java
Original file line number Diff line number Diff line change
@@ -1,30 +1,87 @@
package de.t0biii.music.domain;

import java.io.File;
import java.io.IOException;

import org.bukkit.configuration.InvalidConfigurationException;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;

import de.t0biii.music.main.Main;

public class ConfigManager {

private Main plugin;

private FileConfiguration userConfigs = null;

public ConfigManager(Main plugin) {
this.plugin = plugin;
}

public void loadConfig() {
this.plugin.getConfig().options().header("Plugin by itzTobi_!\nChange at your own risk");
this.plugin.getConfig().options().header("Change at your own risk\nOnly the messages with color codes here support color codes. The rest have a default color");
this.plugin.getConfig().addDefault("music", "Song.nbs");
this.plugin.getConfig().addDefault("options.music.random", false);
this.plugin.getConfig().addDefault("options.music.RandomFoldername", "random");
this.plugin.getConfig().addDefault("options.music.Mode", "MonoMode");
this.plugin.getConfig().addDefault("options.music.10Octave", false);
this.plugin.getConfig().addDefault("options.update-check", true);
this.plugin.getConfig().addDefault("options.updateinfo", true);
this.plugin.getConfig().addDefault("options.printSongTitel", true);
this.plugin.getConfig().addDefault("options.delaySong", 2);
this.plugin.getConfig().addDefault("messages.reload", "The reload was successful!");
this.plugin.getConfig().addDefault("messages.stop", "The song was stopped!");
this.plugin.getConfig().addDefault("messages.no-permission", "You don't have enough permissions");
this.plugin.getConfig().addDefault("options.allowDisabling", true);
this.plugin.getConfig().addDefault("options.metrics", true);
this.plugin.getConfig().addDefault("messages.reload", "&3The reload was successful!");
this.plugin.getConfig().addDefault("messages.stop", "&3Stopped playing the song! &7&oYou can disable playing a song on join with &b&o/jm disable");
this.plugin.getConfig().addDefault("messages.no-permission", "&cYou don't have enough permissions");
this.plugin.getConfig().addDefault("messages.disabled","&3Disabled playing a song when joining. To enable it again, use &b/jm enable");
this.plugin.getConfig().addDefault("messages.enabled","&3Enabled playing a song when joining");
this.plugin.getConfig().addDefault("messages.playing", "&2Started Playing the Song: &a&l%song%&2. You can stop it using &a/jm stop");
this.plugin.getConfig().addDefault("messages.help.stop", "Stop playing the Song!");
this.plugin.getConfig().addDefault("messages.help.disableOwn", "Disable playing a song when joining");
this.plugin.getConfig().addDefault("messages.help.enableOwn", "Enable playing a song when joining");


this.plugin.getConfig().options().copyDefaults(true);
}

public void reloadConfigs() {
plugin.reloadConfig();
loadConfig();
plugin.saveConfig();
loadUserConfigsIfNeeded();
}

private void createUserConfigs() {
File userConfigsFile = new File(plugin.getDataFolder(), "disabledPlayers.yml");
if (!userConfigsFile.exists()) {
userConfigsFile.getParentFile().mkdirs();
plugin.saveResource("disabledPlayers.yml", false);
}
this.userConfigs = new YamlConfiguration();
try {
this.userConfigs.load(userConfigsFile);
} catch (IOException | InvalidConfigurationException e) {
e.printStackTrace();
}
}

public FileConfiguration getUserConfigs() {
return this.userConfigs;
}

public void loadUserConfigsIfNeeded() {
if (plugin.getConfig().getBoolean("options.allowDisabling")) {
createUserConfigs();
}
}

public void saveUserConfigs() {
try {
this.userConfigs.save(new File(plugin.getDataFolder(), "disabledPlayers.yml"));
} catch (IOException e) {
e.printStackTrace();
}
}
}
23 changes: 15 additions & 8 deletions src/main/java/de/t0biii/music/domain/Music.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,18 @@ public class Music {
private static HashMap<UUID, SongPlayer> playingSong = new HashMap<>();

public static void start(Player player, Main plugin){
if(plugin.getConfig().getBoolean("options.allowDisabling")) {
if(plugin.cm.getUserConfigs().getBoolean(player.getUniqueId().toString(),false)) {
return;
}
}
play(player, plugin);
}

public static void stop(Player player) {
removePlayer(player.getUniqueId());
}

public static void stop(UUID uuid) {
removePlayer(uuid);
}
Expand Down Expand Up @@ -67,6 +74,9 @@ private static void playSong(Player player, Main plugin) {
final RadioSongPlayer sp = new RadioSongPlayer(s);
sp.addPlayer(player);
sp.setPlaying(true);
if(plugin.getConfig().getBoolean("options.music.10Octave")){
sp.setEnable10Octave(true);
}
String mode = plugin.getConfig().getString("options.music.Mode");
if(mode.equalsIgnoreCase("MonoMode")){
sp.setChannelMode(new MonoMode());
Expand All @@ -79,12 +89,10 @@ private static void playSong(Player player, Main plugin) {
}
playingSong.put(player.getUniqueId(), sp);

if (plugin.getConfig().getBoolean("options.printSongTitel")) {
if (!sp.getSong().getTitle().isEmpty()) {
player.sendMessage(plugin.prefix + "§2Start Playing the Song:§a§l " + sp.getSong().getTitle());
} else {
player.sendMessage(plugin.prefix + "§2Start Playing a Song.");
}
String playingMessage = plugin.getConfig().getString("messages.playing");
if (!playingMessage.isEmpty() && plugin.getConfig().getBoolean("options.printSongTitel")) {
player.sendMessage(plugin.prefix +
playingMessage.replaceAll("%song%",sp.getSong().getTitle().isEmpty() ? "Untitled" : sp.getSong().getTitle()).replaceAll("&", "§"));
}
} catch (IllegalArgumentException e) {
System.err.println(plugin.cprefix + "No sounds detected");
Expand Down Expand Up @@ -113,8 +121,7 @@ private static File SelectRandomFileFromFolder(Main plugin) {
File[] files = dir.listFiles();
if (files.length > 0) {
Random rand = new Random();
File file = files[rand.nextInt(files.length)];
return file;
return files[rand.nextInt(files.length)];
} else {
return new File(plugin.getDataFolder() + "/" + plugin.getConfig().getString("music"));
}
Expand Down
Loading

0 comments on commit 6cffbe8

Please sign in to comment.