♻️ Refactored MCTPAudio, moved to ACF, removed unneeded things, and more.
This commit is contained in:
parent
435007a502
commit
d523a31310
22 changed files with 652 additions and 525 deletions
39
pom.xml
39
pom.xml
|
@ -6,17 +6,16 @@
|
|||
|
||||
<groupId>me.mctp</groupId>
|
||||
<artifactId>MCTPAudio</artifactId>
|
||||
<version>1.2</version>
|
||||
<version>1.3</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>MCTPAudio</name>
|
||||
|
||||
<description>De audio plugin van MCThemeParks.</description>
|
||||
<description>The audio plugin of McThemeParks!</description>
|
||||
<properties>
|
||||
<java.version>1.8</java.version>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
<url>https://sbdplugins.nl</url>
|
||||
<url>https://mcthemeparks.eu</url>
|
||||
|
||||
<build>
|
||||
<defaultGoal>clean package</defaultGoal>
|
||||
|
@ -26,8 +25,17 @@
|
|||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.8.1</version>
|
||||
<configuration>
|
||||
<source>${java.version}</source>
|
||||
<target>${java.version}</target>
|
||||
<release>11</release>
|
||||
<compilerArgs>
|
||||
<arg>-parameters</arg>
|
||||
</compilerArgs>
|
||||
<annotationProcessorPaths>
|
||||
<path>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>1.18.16</version>
|
||||
</path>
|
||||
</annotationProcessorPaths>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
|
@ -41,7 +49,18 @@
|
|||
<goal>shade</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<minimizeJar>true</minimizeJar>
|
||||
<createDependencyReducedPom>false</createDependencyReducedPom>
|
||||
<relocations>
|
||||
<relocation>
|
||||
<pattern>co.aikar.commands</pattern>
|
||||
<shadedPattern>nl.sbdeveloper.mctpaudio.libs.acf</shadedPattern>
|
||||
</relocation>
|
||||
<relocation>
|
||||
<pattern>co.aikar.locales</pattern>
|
||||
<shadedPattern>nl.sbdeveloper.mctpaudio.libs.locales</shadedPattern>
|
||||
</relocation>
|
||||
</relocations>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
|
@ -74,7 +93,7 @@
|
|||
<dependency>
|
||||
<groupId>org.spigotmc</groupId>
|
||||
<artifactId>spigot-api</artifactId>
|
||||
<version>1.16.4-R0.1-SNAPSHOT</version>
|
||||
<version>1.16.5-R0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
|
@ -109,5 +128,11 @@
|
|||
<artifactId>commons-io</artifactId>
|
||||
<version>2.8.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>co.aikar</groupId>
|
||||
<artifactId>acf-paper</artifactId>
|
||||
<version>0.5.0-SNAPSHOT</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
|
|
@ -1,88 +0,0 @@
|
|||
package me.mctp;
|
||||
|
||||
import me.mctp.commands.MCTPAudioCMD;
|
||||
import me.mctp.listener.LogoutListener;
|
||||
import me.mctp.listener.WGListener;
|
||||
import me.mctp.managers.WGManager;
|
||||
import me.mctp.radio.Playlist;
|
||||
import me.mctp.socket.Client;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
public class Main extends JavaPlugin implements Listener {
|
||||
|
||||
private static Plugin pl;
|
||||
private static Client client;
|
||||
private static Playlist playlist;
|
||||
|
||||
public static String prefix = (ChatColor.GOLD + "[" + ChatColor.YELLOW + "MCTP" + ChatColor.GOLD + "] " + ChatColor.GRAY);
|
||||
|
||||
public void onEnable(){
|
||||
Bukkit.getServer().getPluginManager().registerEvents(this, this);
|
||||
|
||||
Bukkit.getLogger().info(prefix + "loading...");
|
||||
|
||||
if (!setupPlugins()) {
|
||||
Bukkit.getLogger().severe(String.format("[%s] Disabled due to no WorldGuard dependency found!", getDescription().getName()));
|
||||
getServer().getPluginManager().disablePlugin(this);
|
||||
return;
|
||||
}
|
||||
|
||||
getConfig().addDefault("Regions.demosound", "https://audiopagina.mcthemeparks.eu/gallery/voletarium.mp3");
|
||||
getConfig().addDefault("HueRegions.demosound", "255_0_0_254");
|
||||
getConfig().options().copyDefaults(true);
|
||||
saveConfig();
|
||||
|
||||
pl = this;
|
||||
|
||||
client = new Client("ws://173.249.31.58:8166");
|
||||
client.connect();
|
||||
|
||||
getCommand("audio").setExecutor(new MCTPAudioCMD());
|
||||
getCommand("mctpaudio").setExecutor(new MCTPAudioCMD());
|
||||
|
||||
Bukkit.getPluginManager().registerEvents(new WGListener(), this);
|
||||
Bukkit.getPluginManager().registerEvents(new LogoutListener(), this);
|
||||
|
||||
playlist = new Playlist();
|
||||
|
||||
Bukkit.getLogger().info(prefix + " __ __ ____ _____ ____ _ _ _ ");
|
||||
Bukkit.getLogger().info(prefix + " | \\/ |/ ___|_ _| _ \\ / \\ _ _ __| (_) ___ ");
|
||||
Bukkit.getLogger().info(prefix + " | |\\/| | | | | | |_) / _ \\| | | |/ _` | |/ _ \\ ");
|
||||
Bukkit.getLogger().info(prefix + " | | | | |___ | | | __/ ___ \\ |_| | (_| | | (_) |");
|
||||
Bukkit.getLogger().info(prefix + " |_| |_|\\____| |_| |_| /_/ \\_\\__,_|\\__,_|_|\\___/ ");
|
||||
Bukkit.getLogger().info(prefix + " ");
|
||||
Bukkit.getLogger().info(prefix + "successfully enabled!");
|
||||
}
|
||||
|
||||
public void onDisable() {
|
||||
client.disconnect();
|
||||
Bukkit.getLogger().info(prefix + "successfully disabled!");
|
||||
}
|
||||
|
||||
private boolean setupPlugins() {
|
||||
if (hasWorldGuardOnServer()) {
|
||||
WGManager.setWorldGuard(getServer().getPluginManager().getPlugin("WorldGuard"));
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
private static boolean hasWorldGuardOnServer() {
|
||||
return Bukkit.getPluginManager().getPlugin("WorldGuard") != null;
|
||||
}
|
||||
|
||||
public static Plugin getPlugin() {
|
||||
return pl;
|
||||
}
|
||||
|
||||
public static Client getClient() {
|
||||
return client;
|
||||
}
|
||||
|
||||
public static Playlist getPlaylist() {
|
||||
return playlist;
|
||||
}
|
||||
}
|
|
@ -1,5 +0,0 @@
|
|||
package me.mctp.api;
|
||||
|
||||
public enum AudioType {
|
||||
MUSIC, SFX, RADIO
|
||||
}
|
|
@ -1,5 +0,0 @@
|
|||
package me.mctp.api;
|
||||
|
||||
public enum HueType {
|
||||
LEFT, MID, RIGHT, ALL
|
||||
}
|
|
@ -1,231 +0,0 @@
|
|||
package me.mctp.commands;
|
||||
|
||||
import me.mctp.Main;
|
||||
import me.mctp.api.AudioType;
|
||||
import me.mctp.api.HueType;
|
||||
import me.mctp.managers.PinManager;
|
||||
import me.mctp.utils.HeadUtil;
|
||||
import me.mctp.utils.SpigotPlayerSelector;
|
||||
import net.md_5.bungee.api.chat.ClickEvent;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.json.simple.JSONObject;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class MCTPAudioCMD implements CommandExecutor {
|
||||
|
||||
public static String prefix = (ChatColor.GOLD + "[" + ChatColor.YELLOW + "MCTP" + ChatColor.GOLD + "] " + ChatColor.GRAY);
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String commandlabel, String[] args) {
|
||||
if (cmd.getName().equalsIgnoreCase("mctpaudio")) {
|
||||
if (!sender.hasPermission("mctp.audio")) {
|
||||
sender.sendMessage(prefix + "You don't have the permission to do this.");
|
||||
return true;
|
||||
}
|
||||
|
||||
if (args.length == 1 && args[0].equalsIgnoreCase("toggleradio")) {
|
||||
if (Main.getPlaylist().isRunning()) {
|
||||
Main.getPlaylist().stop();
|
||||
sender.sendMessage(prefix + "De auto radio is stopgezet. Zodra het huidige nummer is afgelopen, gebeurt er niks meer.");
|
||||
} else {
|
||||
Main.getPlaylist().start();
|
||||
sender.sendMessage(prefix + "De auto radio is weer gestart.");
|
||||
}
|
||||
return true;
|
||||
} else if (args.length == 2 && args[0].equalsIgnoreCase("addsong")) {
|
||||
List<String> urls = Main.getPlugin().getConfig().getStringList("RadioSongs");
|
||||
urls.add(args[1]);
|
||||
Main.getPlugin().getConfig().set("RadioSongs", urls);
|
||||
Main.getPlugin().saveConfig();
|
||||
Main.getPlaylist().addSong(args[1]);
|
||||
sender.sendMessage(prefix + "Nummer toegevoegd aan de lijst.");
|
||||
return true;
|
||||
} else if (args.length == 4 && args[0].equalsIgnoreCase("play")) {
|
||||
AudioType type;
|
||||
try {
|
||||
type = AudioType.valueOf(args[2].toUpperCase());
|
||||
} catch (IllegalArgumentException ex) {
|
||||
sender.sendMessage(prefix + args[2] + " is geen correcte type.");
|
||||
return true;
|
||||
}
|
||||
|
||||
ArrayList<Player> players = new ArrayList<>();
|
||||
Player target = Bukkit.getPlayer(args[1]);
|
||||
if (target != null) {
|
||||
if (!PinManager.hasPin(target.getUniqueId())) {
|
||||
sender.sendMessage(prefix + "Die speler is niet verbonden met de client.");
|
||||
return true;
|
||||
}
|
||||
|
||||
players.add(target);
|
||||
} else {
|
||||
SpigotPlayerSelector selector = new SpigotPlayerSelector(args[1]);
|
||||
players.addAll(selector.getPlayers(sender));
|
||||
}
|
||||
|
||||
JSONObject data;
|
||||
for (Player p : players) {
|
||||
data = new JSONObject();
|
||||
|
||||
if (!PinManager.hasPin(p.getUniqueId())) continue;
|
||||
|
||||
data.put("task", type.name());
|
||||
data.put("path", args[3]);
|
||||
data.put("uuid", p.getUniqueId().toString().replace("-", ""));
|
||||
Main.getClient().sendData(data);
|
||||
}
|
||||
|
||||
sender.sendMessage(prefix + "Gestart met afspelen!");
|
||||
return true;
|
||||
} else if ((args.length == 6 || args.length == 7) && args[0].equalsIgnoreCase("hue")) {
|
||||
int r;
|
||||
int g;
|
||||
int b;
|
||||
try {
|
||||
r = Integer.parseInt(args[2]);
|
||||
g = Integer.parseInt(args[3]);
|
||||
b = Integer.parseInt(args[4]);
|
||||
} catch (IllegalArgumentException ex) {
|
||||
sender.sendMessage(prefix + args[2] + ", " + args[3] + ", " + args[4] + " zijn incorrecte RGB waardes.");
|
||||
return true;
|
||||
}
|
||||
|
||||
Integer brightness = null;
|
||||
if (args.length == 7) {
|
||||
try {
|
||||
brightness = Integer.parseInt(args[6]);
|
||||
} catch (IllegalArgumentException ex) {
|
||||
sender.sendMessage(prefix + args[6] + " is geen correcte brightness.");
|
||||
return true;
|
||||
}
|
||||
|
||||
if (brightness < 0 || brightness > 254) {
|
||||
sender.sendMessage(prefix + args[6] + " is geen correcte brightness.");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
HueType type;
|
||||
try {
|
||||
type = HueType.valueOf(args[5].toUpperCase());
|
||||
} catch (IllegalArgumentException ex) {
|
||||
sender.sendMessage(prefix + args[5] + " is geen correcte type.");
|
||||
return true;
|
||||
}
|
||||
|
||||
ArrayList<Player> players = new ArrayList<>();
|
||||
Player target = Bukkit.getPlayer(args[1]);
|
||||
if (target != null) {
|
||||
if (!PinManager.hasPin(target.getUniqueId())) {
|
||||
sender.sendMessage(prefix + "Die speler is niet verbonden met de client.");
|
||||
return true;
|
||||
}
|
||||
|
||||
players.add(target);
|
||||
} else {
|
||||
SpigotPlayerSelector selector = new SpigotPlayerSelector(args[1]);
|
||||
players.addAll(selector.getPlayers(sender));
|
||||
}
|
||||
|
||||
//CHECK FOR THE REGION SELECTOR -> Then save
|
||||
if (args[1].startsWith("@a") && HeadUtil.getArgument(args[1], "region").length() != 0) {
|
||||
String regionID = HeadUtil.getArgument(args[1], "region");
|
||||
String data = r + "_" + g + "_" + b + "_" + type.name();
|
||||
if (brightness != null) data += "_" + brightness;
|
||||
|
||||
Main.getPlugin().getConfig().set("HueRegions." + regionID, data);
|
||||
Main.getPlugin().saveConfig();
|
||||
}
|
||||
|
||||
JSONObject data;
|
||||
for (Player p : players) {
|
||||
data = new JSONObject();
|
||||
|
||||
if (!PinManager.hasPin(p.getUniqueId())) continue;
|
||||
|
||||
data.put("task", "HUE");
|
||||
data.put("rgb", r + ":" + g + ":" + b);
|
||||
data.put("type", type.name());
|
||||
if (brightness != null) data.put("brightness", brightness);
|
||||
data.put("uuid", p.getUniqueId().toString().replace("-", ""));
|
||||
Main.getClient().sendData(data);
|
||||
}
|
||||
|
||||
sender.sendMessage(prefix + "Indien de speler(s) is/zijn verbonden met Philips Hue, is de kleur veranderd.");
|
||||
return true;
|
||||
} else if (args.length == 3 && args[0].equalsIgnoreCase("setregion")) {
|
||||
String regionName = args[1];
|
||||
String url = args[2];
|
||||
|
||||
Main.getPlugin().getConfig().set("Regions." + regionName, url);
|
||||
Main.getPlugin().saveConfig();
|
||||
|
||||
sender.sendMessage(prefix + "De region zal vanaf nu muziek afspelen.");
|
||||
return true;
|
||||
} else if (args.length == 3 && args[0].equalsIgnoreCase("sethueregion")) {
|
||||
String regionName = args[1];
|
||||
String url = args[2];
|
||||
|
||||
Main.getPlugin().getConfig().set("Regions." + regionName, url);
|
||||
Main.getPlugin().saveConfig();
|
||||
|
||||
sender.sendMessage(prefix + "De region zal vanaf nu muziek afspelen.");
|
||||
return true;
|
||||
} else if (args.length == 2 && args[0].equalsIgnoreCase("stop")) {
|
||||
ArrayList<Player> players = new ArrayList<>();
|
||||
Player target = Bukkit.getPlayer(args[1]);
|
||||
if (target != null) {
|
||||
if (!PinManager.hasPin(target.getUniqueId())) {
|
||||
sender.sendMessage(prefix + "Die speler is niet verbonden met de client.");
|
||||
return true;
|
||||
}
|
||||
|
||||
players.add(target);
|
||||
} else {
|
||||
SpigotPlayerSelector selector = new SpigotPlayerSelector(args[1]);
|
||||
players.addAll(selector.getPlayers(sender));
|
||||
}
|
||||
|
||||
JSONObject data;
|
||||
for (Player p : players) {
|
||||
data = new JSONObject();
|
||||
|
||||
if (!PinManager.hasPin(p.getUniqueId())) continue;
|
||||
|
||||
data.put("task", "STOP");
|
||||
data.put("uuid", p.getUniqueId().toString().replace("-", ""));
|
||||
Main.getClient().sendData(data);
|
||||
}
|
||||
|
||||
sender.sendMessage(prefix + "Gestopt met afspelen!");
|
||||
return true;
|
||||
}
|
||||
} else if (cmd.getName().equalsIgnoreCase("audio")) {
|
||||
if (!(sender instanceof Player)) {
|
||||
sender.sendMessage(prefix + "Alleen spelers kunnen verbinden met onze audioclient.");
|
||||
return true;
|
||||
}
|
||||
|
||||
Player p = (Player) sender;
|
||||
String pin = PinManager.getPIN(p.getUniqueId());
|
||||
|
||||
String url = "http://audio.mcthemeparks.eu/";
|
||||
url = url + "?uuid=" + p.getUniqueId().toString().replace("-", "") + "&pin=" + pin;
|
||||
|
||||
TextComponent message = new TextComponent(TextComponent.fromLegacyText(prefix + "Click here to connect to the audio client."));
|
||||
message.setClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, url));
|
||||
p.spigot().sendMessage(message);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,107 +0,0 @@
|
|||
package me.mctp.listener;
|
||||
|
||||
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
|
||||
import me.mctp.Main;
|
||||
import me.mctp.managers.PinManager;
|
||||
import me.mctp.managers.WGManager;
|
||||
import net.raidstone.wgevents.events.RegionsEnteredEvent;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerMoveEvent;
|
||||
import org.json.simple.JSONObject;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class WGListener implements Listener {
|
||||
/** Music detection */
|
||||
@EventHandler
|
||||
public void onMove(PlayerMoveEvent e) {
|
||||
if (e.getTo() == null || e.getFrom().getWorld() == null || e.getTo().getWorld() == null) return;
|
||||
|
||||
if (e.getFrom().getBlockX() != e.getTo().getBlockX() || e.getFrom().getBlockY() != e.getTo().getBlockY() || e.getFrom().getBlockZ() != e.getTo().getBlockZ()) {
|
||||
Set<String> list = Main.getPlugin().getConfig().getConfigurationSection("Regions").getKeys(false);
|
||||
|
||||
if (!PinManager.hasPin(Objects.requireNonNull(e.getPlayer()).getUniqueId())) return;
|
||||
|
||||
List<ProtectedRegion> regions = WGManager.getRegionsIn(e.getFrom());
|
||||
List<String> regionNames = regions.stream().map(ProtectedRegion::getId).collect(Collectors.toList());
|
||||
List<ProtectedRegion> regions2 = WGManager.getRegionsIn(e.getTo());
|
||||
List<String> regionNames2 = regions2.stream().map(ProtectedRegion::getId).collect(Collectors.toList());
|
||||
|
||||
if ((Collections.disjoint(list, regionNames) && !Collections.disjoint(list, regionNames2)) || (!Collections.disjoint(list, regionNames) && !Collections.disjoint(list, regionNames2))) {
|
||||
//Walked in a region
|
||||
|
||||
if (!Collections.disjoint(list, regionNames) && !Collections.disjoint(list, regionNames2)) {
|
||||
Optional<String> name = regionNames.stream().filter(list::contains).findFirst();
|
||||
Optional<String> name2 = regionNames2.stream().filter(list::contains).findFirst();
|
||||
if (name.isPresent() && name2.isPresent() && name.get().equals(name2.get())) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (name.isPresent() && name2.isPresent()) {
|
||||
String regionURL = Main.getPlugin().getConfig().getString("Regions." + name.get());
|
||||
String regionURL2 = Main.getPlugin().getConfig().getString("Regions." + name2.get());
|
||||
|
||||
if (regionURL.equals(regionURL2)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Optional<String> name = regionNames2.stream().filter(list::contains).findFirst();
|
||||
if (!name.isPresent()) return;
|
||||
String regionURL = Main.getPlugin().getConfig().getString("Regions." + name.get());
|
||||
|
||||
JSONObject data = new JSONObject();
|
||||
data.put("task", "MUSIC");
|
||||
data.put("path", regionURL);
|
||||
data.put("uuid", e.getPlayer().getUniqueId().toString().replace("-", ""));
|
||||
Main.getClient().sendData(data);
|
||||
} else if (!Collections.disjoint(list, regionNames) && Collections.disjoint(list, regionNames2)) {
|
||||
//Not in a region, stop...
|
||||
JSONObject data = new JSONObject();
|
||||
data.put("task", "MUSIC");
|
||||
data.put("path", "");
|
||||
data.put("uuid", e.getPlayer().getUniqueId().toString().replace("-", ""));
|
||||
Main.getClient().sendData(data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** Hue detection */
|
||||
@EventHandler
|
||||
public void onRegionEnter(RegionsEnteredEvent e) {
|
||||
if (e.getPlayer() == null) return;
|
||||
|
||||
Set<String> list2 = Main.getPlugin().getConfig().getConfigurationSection("HueRegions").getKeys(false);
|
||||
|
||||
if (!Collections.disjoint(list2, e.getRegionsNames())) {
|
||||
//One element is the same -> In a region
|
||||
|
||||
Optional<String> name = e.getRegionsNames().stream().filter(list2::contains).findFirst();
|
||||
if (!name.isPresent()) return;
|
||||
String configData = Main.getPlugin().getConfig().getString("HueRegions." + name.get());
|
||||
|
||||
if (configData == null) return;
|
||||
String[] configDataSplit = configData.split("_");
|
||||
|
||||
int r = Integer.parseInt(configDataSplit[0]);
|
||||
int g = Integer.parseInt(configDataSplit[1]);
|
||||
int b = Integer.parseInt(configDataSplit[2]);
|
||||
String type = configDataSplit[3];
|
||||
Integer brightness = null;
|
||||
if (configDataSplit.length == 5) brightness = Integer.parseInt(configDataSplit[4]);
|
||||
|
||||
if (!PinManager.hasPin(e.getPlayer().getUniqueId())) return;
|
||||
|
||||
JSONObject data = new JSONObject();
|
||||
data.put("task", "HUE");
|
||||
data.put("rgb", r + ":" + g + ":" + b);
|
||||
data.put("type", type);
|
||||
if (brightness != null) data.put("brightness", brightness);
|
||||
data.put("uuid", e.getPlayer().getUniqueId().toString().replace("-", ""));
|
||||
Main.getClient().sendData(data);
|
||||
}
|
||||
}
|
||||
}
|
88
src/main/java/nl/sbdeveloper/mctpaudio/MCTPAudio.java
Normal file
88
src/main/java/nl/sbdeveloper/mctpaudio/MCTPAudio.java
Normal file
|
@ -0,0 +1,88 @@
|
|||
package nl.sbdeveloper.mctpaudio;
|
||||
|
||||
import co.aikar.commands.PaperCommandManager;
|
||||
import nl.sbdeveloper.mctpaudio.commands.MCTPAudioCMD;
|
||||
import nl.sbdeveloper.mctpaudio.listener.LogoutListener;
|
||||
import nl.sbdeveloper.mctpaudio.listener.WGListener;
|
||||
import nl.sbdeveloper.mctpaudio.managers.WGManager;
|
||||
import nl.sbdeveloper.mctpaudio.radio.Playlist;
|
||||
import nl.sbdeveloper.mctpaudio.socket.Client;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
/* Copyright (C) McThemeParks - All Rights Reserved
|
||||
* Unauthorized copying of this file, via any medium is strictly prohibited
|
||||
* Proprietary and confidential
|
||||
* Written by Stijn Bannink <stijnbannink23@gmail.com>, July 2020
|
||||
*/
|
||||
|
||||
public final class MCTPAudio extends JavaPlugin {
|
||||
private static Plugin instance;
|
||||
|
||||
private static PaperCommandManager commandManager;
|
||||
|
||||
private static Client client;
|
||||
private static Playlist playlist;
|
||||
|
||||
public void onEnable() {
|
||||
Bukkit.getLogger().info("[MCTPAudio] Loading...");
|
||||
|
||||
if (!setupPlugins()) {
|
||||
Bukkit.getLogger().severe("[MCTPAudio] WorldGuard not found! Disabling...");
|
||||
getServer().getPluginManager().disablePlugin(this);
|
||||
return;
|
||||
}
|
||||
|
||||
instance = this;
|
||||
|
||||
getConfig().addDefault("Regions.demosound", "https://audiopagina.mcthemeparks.eu/gallery/voletarium.mp3");
|
||||
getConfig().addDefault("HueRegions.demosound", "255_0_0_254");
|
||||
getConfig().options().copyDefaults(true);
|
||||
saveConfig();
|
||||
|
||||
Bukkit.getLogger().info("[MCTPAudio] Connecting with socket...");
|
||||
client = new Client("ws://173.249.31.58:8166");
|
||||
client.connect();
|
||||
|
||||
Bukkit.getLogger().info("[MCTPAudio] Loading commands and events...");
|
||||
commandManager = new PaperCommandManager(this);
|
||||
commandManager.enableUnstableAPI("help");
|
||||
|
||||
commandManager.registerCommand(new MCTPAudioCMD());
|
||||
|
||||
Bukkit.getPluginManager().registerEvents(new WGListener(), this);
|
||||
Bukkit.getPluginManager().registerEvents(new LogoutListener(), this);
|
||||
|
||||
Bukkit.getLogger().info("[MCTPAudio] Loading playlist...");
|
||||
playlist = new Playlist();
|
||||
|
||||
Bukkit.getLogger().info("[MCTPAudio] Plugin is enabled!");
|
||||
}
|
||||
|
||||
public void onDisable() {
|
||||
client.disconnect();
|
||||
instance = null;
|
||||
Bukkit.getLogger().info("[MCTPAudio] Plugin is disabled!");
|
||||
}
|
||||
|
||||
private boolean setupPlugins() {
|
||||
if (Bukkit.getPluginManager().getPlugin("WorldGuard") != null) {
|
||||
WGManager.setWorldGuard(getServer().getPluginManager().getPlugin("WorldGuard"));
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static Plugin getPlugin() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
public static Client getClient() {
|
||||
return client;
|
||||
}
|
||||
|
||||
public static Playlist getPlaylist() {
|
||||
return playlist;
|
||||
}
|
||||
}
|
11
src/main/java/nl/sbdeveloper/mctpaudio/api/AudioType.java
Normal file
11
src/main/java/nl/sbdeveloper/mctpaudio/api/AudioType.java
Normal file
|
@ -0,0 +1,11 @@
|
|||
package nl.sbdeveloper.mctpaudio.api;
|
||||
|
||||
/* Copyright (C) McThemeParks - All Rights Reserved
|
||||
* Unauthorized copying of this file, via any medium is strictly prohibited
|
||||
* Proprietary and confidential
|
||||
* Written by Stijn Bannink <stijnbannink23@gmail.com>, July 2020
|
||||
*/
|
||||
|
||||
public enum AudioType {
|
||||
MUSIC, SFX, RADIO
|
||||
}
|
11
src/main/java/nl/sbdeveloper/mctpaudio/api/HueType.java
Normal file
11
src/main/java/nl/sbdeveloper/mctpaudio/api/HueType.java
Normal file
|
@ -0,0 +1,11 @@
|
|||
package nl.sbdeveloper.mctpaudio.api;
|
||||
|
||||
/* Copyright (C) McThemeParks - All Rights Reserved
|
||||
* Unauthorized copying of this file, via any medium is strictly prohibited
|
||||
* Proprietary and confidential
|
||||
* Written by Stijn Bannink <stijnbannink23@gmail.com>, July 2020
|
||||
*/
|
||||
|
||||
public enum HueType {
|
||||
LEFT, MID, RIGHT, ALL
|
||||
}
|
|
@ -0,0 +1,43 @@
|
|||
package nl.sbdeveloper.mctpaudio.api.events;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/* Copyright (C) McThemeParks - All Rights Reserved
|
||||
* Unauthorized copying of this file, via any medium is strictly prohibited
|
||||
* Proprietary and confidential
|
||||
* Written by Stijn Bannink <stijnbannink23@gmail.com>, July 2020
|
||||
*/
|
||||
|
||||
public class AudioConnectionUpdateEvent extends Event {
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
private final Player player;
|
||||
private final boolean connected;
|
||||
|
||||
public AudioConnectionUpdateEvent(@NotNull Player who, boolean connected) {
|
||||
super(true);
|
||||
this.player = who;
|
||||
this.connected = connected;
|
||||
}
|
||||
|
||||
public Player getPlayer() {
|
||||
return player;
|
||||
}
|
||||
|
||||
public boolean isConnected() {
|
||||
return connected;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public HandlerList getHandlers() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static HandlerList getHandlerList() {
|
||||
return handlers;
|
||||
}
|
||||
}
|
|
@ -1,6 +1,13 @@
|
|||
package me.mctp.api.maps;
|
||||
package nl.sbdeveloper.mctpaudio.api.maps;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Random;
|
||||
|
||||
/* Copyright (C) McThemeParks - All Rights Reserved
|
||||
* Unauthorized copying of this file, via any medium is strictly prohibited
|
||||
* Proprietary and confidential
|
||||
* Written by Stijn Bannink <stijnbannink23@gmail.com>, July 2020
|
||||
*/
|
||||
|
||||
/**
|
||||
* An {@link ArrayList} with shuffle support.
|
|
@ -0,0 +1,188 @@
|
|||
package nl.sbdeveloper.mctpaudio.commands;
|
||||
|
||||
import co.aikar.commands.BaseCommand;
|
||||
import co.aikar.commands.CommandHelp;
|
||||
import co.aikar.commands.annotation.*;
|
||||
import nl.sbdeveloper.mctpaudio.MCTPAudio;
|
||||
import nl.sbdeveloper.mctpaudio.api.AudioType;
|
||||
import nl.sbdeveloper.mctpaudio.api.HueType;
|
||||
import nl.sbdeveloper.mctpaudio.managers.PinManager;
|
||||
import nl.sbdeveloper.mctpaudio.utils.HeadUtil;
|
||||
import nl.sbdeveloper.mctpaudio.utils.SpigotPlayerSelector;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.json.simple.JSONObject;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/* Copyright (C) McThemeParks - All Rights Reserved
|
||||
* Unauthorized copying of this file, via any medium is strictly prohibited
|
||||
* Proprietary and confidential
|
||||
* Written by Stijn Bannink <stijnbannink23@gmail.com>, July 2020
|
||||
*/
|
||||
|
||||
@CommandAlias("mctpaudio")
|
||||
@CommandPermission("mctp.audio")
|
||||
public class MCTPAudioCMD extends BaseCommand {
|
||||
@Default
|
||||
@HelpCommand
|
||||
public void onHelp(CommandSender sender, CommandHelp help) {
|
||||
help.showHelp();
|
||||
}
|
||||
|
||||
@Subcommand("toggleradio")
|
||||
@Description("")
|
||||
public void toggleRadio(CommandSender sender) {
|
||||
if (MCTPAudio.getPlaylist().isRunning()) {
|
||||
MCTPAudio.getPlaylist().stop();
|
||||
sender.sendMessage(ChatColor.GRAY + "De auto radio is stopgezet. Zodra het huidige nummer is afgelopen, gebeurt er niks meer.");
|
||||
} else {
|
||||
MCTPAudio.getPlaylist().start();
|
||||
sender.sendMessage(ChatColor.GRAY + "De auto radio is weer gestart.");
|
||||
}
|
||||
}
|
||||
|
||||
@Subcommand("addsong")
|
||||
@Description("")
|
||||
public void onAddSong(CommandSender sender, String url) {
|
||||
List<String> urls = MCTPAudio.getPlugin().getConfig().getStringList("RadioSongs");
|
||||
urls.add(url);
|
||||
MCTPAudio.getPlugin().getConfig().set("RadioSongs", urls);
|
||||
MCTPAudio.getPlugin().saveConfig();
|
||||
MCTPAudio.getPlaylist().addSong(url);
|
||||
sender.sendMessage(ChatColor.GRAY + "Nummer toegevoegd aan de lijst.");
|
||||
}
|
||||
|
||||
@Subcommand("play")
|
||||
@Description("")
|
||||
public void onPlay(CommandSender sender, String selector, AudioType type, String url) {
|
||||
ArrayList<Player> players = new ArrayList<>();
|
||||
Player target = Bukkit.getPlayer(selector);
|
||||
if (target != null) {
|
||||
if (!PinManager.hasPin(target.getUniqueId())) {
|
||||
sender.sendMessage(ChatColor.GRAY + "Die speler is niet verbonden met de client.");
|
||||
return;
|
||||
}
|
||||
|
||||
players.add(target);
|
||||
} else {
|
||||
SpigotPlayerSelector sel = new SpigotPlayerSelector(selector);
|
||||
players.addAll(sel.getPlayers(sender));
|
||||
}
|
||||
|
||||
JSONObject data;
|
||||
for (Player p : players) {
|
||||
data = new JSONObject();
|
||||
|
||||
if (!PinManager.hasPin(p.getUniqueId())) continue;
|
||||
|
||||
data.put("task", type.name());
|
||||
data.put("path", url);
|
||||
data.put("uuid", p.getUniqueId().toString().replace("-", ""));
|
||||
MCTPAudio.getClient().sendData(data);
|
||||
}
|
||||
|
||||
sender.sendMessage(ChatColor.GRAY + "Gestart met afspelen!");
|
||||
}
|
||||
|
||||
@Subcommand("hue")
|
||||
@Description("")
|
||||
public void onHue(CommandSender sender, String selector, int r, int g, int b, HueType type, @Optional Integer brightness) {
|
||||
if (brightness != null && (brightness < 0 || brightness > 254)) {
|
||||
sender.sendMessage(ChatColor.GRAY.toString() + brightness + " is geen correcte brightness.");
|
||||
return;
|
||||
}
|
||||
|
||||
ArrayList<Player> players = new ArrayList<>();
|
||||
Player target = Bukkit.getPlayer(selector);
|
||||
if (target != null) {
|
||||
if (!PinManager.hasPin(target.getUniqueId())) {
|
||||
sender.sendMessage(ChatColor.GRAY + "Die speler is niet verbonden met de client.");
|
||||
return;
|
||||
}
|
||||
|
||||
players.add(target);
|
||||
} else {
|
||||
SpigotPlayerSelector sel = new SpigotPlayerSelector(selector);
|
||||
players.addAll(sel.getPlayers(sender));
|
||||
}
|
||||
|
||||
//CHECK FOR THE REGION SELECTOR -> Then save
|
||||
if (selector.startsWith("@a") && HeadUtil.getArgument(selector, "region").length() != 0) {
|
||||
String regionID = HeadUtil.getArgument(selector, "region");
|
||||
String data = r + "_" + g + "_" + b + "_" + type.name();
|
||||
if (brightness != null) data += "_" + brightness;
|
||||
|
||||
MCTPAudio.getPlugin().getConfig().set("HueRegions." + regionID, data);
|
||||
MCTPAudio.getPlugin().saveConfig();
|
||||
}
|
||||
|
||||
JSONObject data;
|
||||
for (Player p : players) {
|
||||
data = new JSONObject();
|
||||
|
||||
if (!PinManager.hasPin(p.getUniqueId())) continue;
|
||||
|
||||
data.put("task", "HUE");
|
||||
data.put("rgb", r + ":" + g + ":" + b);
|
||||
data.put("type", type.name());
|
||||
if (brightness != null) data.put("brightness", brightness);
|
||||
data.put("uuid", p.getUniqueId().toString().replace("-", ""));
|
||||
MCTPAudio.getClient().sendData(data);
|
||||
}
|
||||
|
||||
sender.sendMessage(ChatColor.GRAY + "Indien de speler(s) is/zijn verbonden met Philips Hue, is de kleur veranderd.");
|
||||
}
|
||||
|
||||
@Subcommand("setregion")
|
||||
@Description("")
|
||||
public void onSetRegion(CommandSender sender, String regionName, String url) {
|
||||
MCTPAudio.getPlugin().getConfig().set("Regions." + regionName, url);
|
||||
MCTPAudio.getPlugin().saveConfig();
|
||||
|
||||
sender.sendMessage(ChatColor.GRAY + "De region zal vanaf nu muziek afspelen.");
|
||||
}
|
||||
|
||||
// @Subcommand("sethueregion")
|
||||
// @Description("")
|
||||
// public void onSetHueRegion(CommandSender sender, String regionName, String url) {
|
||||
// MCTPAudio.getPlugin().getConfig().set("HueRegions." + regionName, url);
|
||||
// MCTPAudio.getPlugin().saveConfig();
|
||||
//
|
||||
// sender.sendMessage(ChatColor.GRAY + "De region zal vanaf nu licht aanpassen.");
|
||||
// }
|
||||
|
||||
@Subcommand("stop")
|
||||
@Description("")
|
||||
public void onStop(CommandSender sender, String selector) {
|
||||
ArrayList<Player> players = new ArrayList<>();
|
||||
Player target = Bukkit.getPlayer(selector);
|
||||
if (target != null) {
|
||||
if (!PinManager.hasPin(target.getUniqueId())) {
|
||||
sender.sendMessage(ChatColor.GRAY + "Die speler is niet verbonden met de client.");
|
||||
return;
|
||||
}
|
||||
|
||||
players.add(target);
|
||||
} else {
|
||||
SpigotPlayerSelector sel = new SpigotPlayerSelector(selector);
|
||||
players.addAll(sel.getPlayers(sender));
|
||||
}
|
||||
|
||||
JSONObject data;
|
||||
for (Player p : players) {
|
||||
data = new JSONObject();
|
||||
|
||||
if (!PinManager.hasPin(p.getUniqueId())) continue;
|
||||
|
||||
data.put("task", "STOP");
|
||||
data.put("uuid", p.getUniqueId().toString().replace("-", ""));
|
||||
MCTPAudio.getClient().sendData(data);
|
||||
}
|
||||
|
||||
sender.sendMessage(ChatColor.GRAY + "Gestopt met afspelen!");
|
||||
}
|
||||
}
|
|
@ -1,17 +1,23 @@
|
|||
package me.mctp.listener;
|
||||
package nl.sbdeveloper.mctpaudio.listener;
|
||||
|
||||
import me.mctp.Main;
|
||||
import nl.sbdeveloper.mctpaudio.MCTPAudio;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import org.json.simple.JSONObject;
|
||||
|
||||
/* Copyright (C) McThemeParks - All Rights Reserved
|
||||
* Unauthorized copying of this file, via any medium is strictly prohibited
|
||||
* Proprietary and confidential
|
||||
* Written by Stijn Bannink <stijnbannink23@gmail.com>, July 2020
|
||||
*/
|
||||
|
||||
public class LogoutListener implements Listener {
|
||||
@EventHandler
|
||||
public void onDisconnect(PlayerQuitEvent e) {
|
||||
JSONObject data = new JSONObject();
|
||||
data.put("task", "LOGOUT");
|
||||
data.put("uuid", e.getPlayer().getUniqueId().toString().replace("-", ""));
|
||||
Main.getClient().sendData(data);
|
||||
MCTPAudio.getClient().sendData(data);
|
||||
}
|
||||
}
|
126
src/main/java/nl/sbdeveloper/mctpaudio/listener/WGListener.java
Normal file
126
src/main/java/nl/sbdeveloper/mctpaudio/listener/WGListener.java
Normal file
|
@ -0,0 +1,126 @@
|
|||
package nl.sbdeveloper.mctpaudio.listener;
|
||||
|
||||
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
|
||||
import nl.sbdeveloper.mctpaudio.MCTPAudio;
|
||||
import nl.sbdeveloper.mctpaudio.managers.PinManager;
|
||||
import nl.sbdeveloper.mctpaudio.managers.WGManager;
|
||||
import net.raidstone.wgevents.events.RegionsEnteredEvent;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerMoveEvent;
|
||||
import org.bukkit.event.player.PlayerTeleportEvent;
|
||||
import org.json.simple.JSONObject;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/* Copyright (C) McThemeParks - All Rights Reserved
|
||||
* Unauthorized copying of this file, via any medium is strictly prohibited
|
||||
* Proprietary and confidential
|
||||
* Written by Stijn Bannink <stijnbannink23@gmail.com>, July 2020
|
||||
*/
|
||||
|
||||
public class WGListener implements Listener {
|
||||
/**
|
||||
* Music detection
|
||||
*/
|
||||
@EventHandler
|
||||
public void onMove(PlayerMoveEvent e) {
|
||||
handlePlayerMovement(e.getPlayer(), e.getFrom(), e.getTo());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onTeleport(PlayerTeleportEvent e) {
|
||||
handlePlayerMovement(e.getPlayer(), e.getFrom(), e.getTo());
|
||||
}
|
||||
|
||||
private void handlePlayerMovement(Player player, Location from, Location to) {
|
||||
if (to == null || from.getWorld() == null || to.getWorld() == null) return;
|
||||
|
||||
if (from.getBlockX() != to.getBlockX() || from.getBlockY() != to.getBlockY() || from.getBlockZ() != to.getBlockZ()) {
|
||||
Set<String> list = MCTPAudio.getPlugin().getConfig().getConfigurationSection("Regions").getKeys(false);
|
||||
|
||||
if (!PinManager.hasPin(Objects.requireNonNull(player).getUniqueId())) return;
|
||||
|
||||
List<String> fromRegions = WGManager.getRegionsIn(from).stream().map(ProtectedRegion::getId).collect(Collectors.toList());
|
||||
List<String> toRegions = WGManager.getRegionsIn(to).stream().map(ProtectedRegion::getId).collect(Collectors.toList());
|
||||
|
||||
if ((Collections.disjoint(list, fromRegions) && !Collections.disjoint(list, toRegions)) || (!Collections.disjoint(list, fromRegions) && !Collections.disjoint(list, toRegions))) {
|
||||
//Walked in a region
|
||||
|
||||
if (!Collections.disjoint(list, fromRegions) && !Collections.disjoint(list, toRegions)) {
|
||||
Optional<String> name = fromRegions.stream().filter(list::contains).findFirst();
|
||||
Optional<String> name2 = toRegions.stream().filter(list::contains).findFirst();
|
||||
|
||||
if (name.isPresent() && name2.isPresent() && name.get().equals(name2.get()))
|
||||
return; //Beide heeft een region, en dat is dezelfde.
|
||||
|
||||
if (name.isPresent() && name2.isPresent()) {
|
||||
String regionURL = MCTPAudio.getPlugin().getConfig().getString("Regions." + name.get());
|
||||
String regionURL2 = MCTPAudio.getPlugin().getConfig().getString("Regions." + name2.get());
|
||||
|
||||
if (regionURL.equals(regionURL2))
|
||||
return; //Beide heeft een region, niet dezelfde, maar wel met dezelfde muziek.
|
||||
}
|
||||
}
|
||||
|
||||
Optional<String> name = toRegions.stream().filter(list::contains).findFirst();
|
||||
if (!name.isPresent()) return;
|
||||
String regionURL = MCTPAudio.getPlugin().getConfig().getString("Regions." + name.get());
|
||||
|
||||
JSONObject data = new JSONObject();
|
||||
data.put("task", "MUSIC");
|
||||
data.put("path", regionURL);
|
||||
data.put("uuid", player.getUniqueId().toString().replace("-", ""));
|
||||
MCTPAudio.getClient().sendData(data);
|
||||
} else if (!Collections.disjoint(list, fromRegions) && Collections.disjoint(list, toRegions)) {
|
||||
//Not in a region, stop...
|
||||
JSONObject data = new JSONObject();
|
||||
data.put("task", "MUSIC");
|
||||
data.put("path", "");
|
||||
data.put("uuid", player.getUniqueId().toString().replace("-", ""));
|
||||
MCTPAudio.getClient().sendData(data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Hue detection
|
||||
*/
|
||||
@EventHandler
|
||||
public void onRegionEnter(RegionsEnteredEvent e) {
|
||||
if (e.getPlayer() == null) return;
|
||||
|
||||
Set<String> list2 = MCTPAudio.getPlugin().getConfig().getConfigurationSection("HueRegions").getKeys(false);
|
||||
|
||||
if (!Collections.disjoint(list2, e.getRegionsNames())) {
|
||||
//One element is the same -> In a region
|
||||
|
||||
Optional<String> name = e.getRegionsNames().stream().filter(list2::contains).findFirst();
|
||||
if (!name.isPresent()) return;
|
||||
String configData = MCTPAudio.getPlugin().getConfig().getString("HueRegions." + name.get());
|
||||
|
||||
if (configData == null) return;
|
||||
String[] configDataSplit = configData.split("_");
|
||||
|
||||
int r = Integer.parseInt(configDataSplit[0]);
|
||||
int g = Integer.parseInt(configDataSplit[1]);
|
||||
int b = Integer.parseInt(configDataSplit[2]);
|
||||
String type = configDataSplit[3];
|
||||
Integer brightness = null;
|
||||
if (configDataSplit.length == 5) brightness = Integer.parseInt(configDataSplit[4]);
|
||||
|
||||
if (!PinManager.hasPin(e.getPlayer().getUniqueId())) return;
|
||||
|
||||
JSONObject data = new JSONObject();
|
||||
data.put("task", "HUE");
|
||||
data.put("rgb", r + ":" + g + ":" + b);
|
||||
data.put("type", type);
|
||||
if (brightness != null) data.put("brightness", brightness);
|
||||
data.put("uuid", e.getPlayer().getUniqueId().toString().replace("-", ""));
|
||||
MCTPAudio.getClient().sendData(data);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,9 +1,15 @@
|
|||
package me.mctp.managers;
|
||||
package nl.sbdeveloper.mctpaudio.managers;
|
||||
|
||||
import java.security.SecureRandom;
|
||||
import java.util.UUID;
|
||||
import java.util.WeakHashMap;
|
||||
|
||||
/* Copyright (C) McThemeParks - All Rights Reserved
|
||||
* Unauthorized copying of this file, via any medium is strictly prohibited
|
||||
* Proprietary and confidential
|
||||
* Written by Stijn Bannink <stijnbannink23@gmail.com>, July 2020
|
||||
*/
|
||||
|
||||
public class PinManager {
|
||||
private static final WeakHashMap<UUID, String> pins = new WeakHashMap<>();
|
||||
|
||||
|
@ -11,7 +17,6 @@ public class PinManager {
|
|||
* Get the pin of a player
|
||||
*
|
||||
* @param pUUID The player UUID
|
||||
*
|
||||
* @return The pin
|
||||
*/
|
||||
public static String getPIN(UUID pUUID) {
|
||||
|
@ -36,7 +41,6 @@ public class PinManager {
|
|||
* Check if a player has a pin
|
||||
*
|
||||
* @param pUUID The player UUID
|
||||
*
|
||||
* @return The pin
|
||||
*/
|
||||
public static boolean hasPin(UUID pUUID) {
|
||||
|
@ -47,8 +51,7 @@ public class PinManager {
|
|||
* Check if the pin is correct
|
||||
*
|
||||
* @param pUUID The player UUID
|
||||
* @param pin The pin
|
||||
*
|
||||
* @param pin The pin
|
||||
* @return true/false
|
||||
*/
|
||||
public static boolean checkPin(UUID pUUID, String pin) {
|
|
@ -1,4 +1,4 @@
|
|||
package me.mctp.managers;
|
||||
package nl.sbdeveloper.mctpaudio.managers;
|
||||
|
||||
import com.sk89q.worldedit.IncompleteRegionException;
|
||||
import com.sk89q.worldedit.LocalSession;
|
||||
|
@ -32,6 +32,12 @@ import java.util.Map;
|
|||
import java.util.Map.Entry;
|
||||
import java.util.UUID;
|
||||
|
||||
/* Copyright (C) McThemeParks - All Rights Reserved
|
||||
* Unauthorized copying of this file, via any medium is strictly prohibited
|
||||
* Proprietary and confidential
|
||||
* Written by Stijn Bannink <stijnbannink23@gmail.com>, July 2020
|
||||
*/
|
||||
|
||||
/**
|
||||
* WorldGuard class to make the usage of WorldGuard easy. This is the 1.14.x version!
|
||||
*
|
||||
|
@ -98,7 +104,8 @@ public class WGManager {
|
|||
|
||||
RegionManager rm = WorldGuard.getInstance().getPlatform().getRegionContainer().get(BukkitAdapter.adapt(loc.getWorld()));
|
||||
|
||||
for (ProtectedRegion protectedRegion : rm.getApplicableRegions(BukkitAdapter.asBlockVector(loc))) inRegions.add(protectedRegion);
|
||||
for (ProtectedRegion protectedRegion : rm.getApplicableRegions(BukkitAdapter.asBlockVector(loc)))
|
||||
inRegions.add(protectedRegion);
|
||||
|
||||
return inRegions;
|
||||
}
|
||||
|
@ -108,7 +115,7 @@ public class WGManager {
|
|||
ApplicableRegionSet mogreg = rm.getApplicableRegions(BukkitAdapter.asBlockVector(loc));
|
||||
for (ProtectedRegion mogregion : mogreg) {
|
||||
for (String strgo : str) {
|
||||
if(strgo.equalsIgnoreCase(mogregion.getId())) {
|
||||
if (strgo.equalsIgnoreCase(mogregion.getId())) {
|
||||
return mogregion;
|
||||
}
|
||||
}
|
||||
|
@ -122,7 +129,7 @@ public class WGManager {
|
|||
RegionManager rm = WorldGuard.getInstance().getPlatform().getRegionContainer().get(BukkitAdapter.adapt(loc.getWorld()));
|
||||
ApplicableRegionSet mogreg = rm.getApplicableRegions(BukkitAdapter.asBlockVector(loc));
|
||||
for (ProtectedRegion mogregion : mogreg) {
|
||||
if(str.equalsIgnoreCase(mogregion.getId())) {
|
||||
if (str.equalsIgnoreCase(mogregion.getId())) {
|
||||
return mogregion;
|
||||
}
|
||||
}
|
||||
|
@ -183,8 +190,7 @@ public class WGManager {
|
|||
rm.save();
|
||||
|
||||
return true;
|
||||
}
|
||||
catch (StorageException e) {
|
||||
} catch (StorageException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -201,8 +207,7 @@ public class WGManager {
|
|||
rm.save();
|
||||
|
||||
return true;
|
||||
}
|
||||
catch (StorageException e) {
|
||||
} catch (StorageException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -219,8 +224,7 @@ public class WGManager {
|
|||
rm.save();
|
||||
|
||||
return true;
|
||||
}
|
||||
catch (StorageException e) {
|
||||
} catch (StorageException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -237,8 +241,7 @@ public class WGManager {
|
|||
rm.save();
|
||||
|
||||
return true;
|
||||
}
|
||||
catch (StorageException e) {
|
||||
} catch (StorageException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -287,8 +290,7 @@ public class WGManager {
|
|||
rm.save();
|
||||
|
||||
return true;
|
||||
}
|
||||
catch (StorageException e) {
|
||||
} catch (StorageException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -1,11 +1,11 @@
|
|||
package me.mctp.radio;
|
||||
package nl.sbdeveloper.mctpaudio.radio;
|
||||
|
||||
import com.mpatric.mp3agic.InvalidDataException;
|
||||
import com.mpatric.mp3agic.UnsupportedTagException;
|
||||
import me.mctp.Main;
|
||||
import me.mctp.api.maps.SongList;
|
||||
import me.mctp.managers.PinManager;
|
||||
import me.mctp.utils.HeadUtil;
|
||||
import nl.sbdeveloper.mctpaudio.MCTPAudio;
|
||||
import nl.sbdeveloper.mctpaudio.api.maps.SongList;
|
||||
import nl.sbdeveloper.mctpaudio.managers.PinManager;
|
||||
import nl.sbdeveloper.mctpaudio.utils.HeadUtil;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
|
@ -13,6 +13,12 @@ import org.json.simple.JSONObject;
|
|||
|
||||
import java.io.IOException;
|
||||
|
||||
/* Copyright (C) McThemeParks - All Rights Reserved
|
||||
* Unauthorized copying of this file, via any medium is strictly prohibited
|
||||
* Proprietary and confidential
|
||||
* Written by Stijn Bannink <stijnbannink23@gmail.com>, July 2020
|
||||
*/
|
||||
|
||||
public class Playlist {
|
||||
private SongList<String> playList = new SongList<>();
|
||||
private final SongList<String> playedList = new SongList<>();
|
||||
|
@ -32,11 +38,11 @@ public class Playlist {
|
|||
* Start this playlist
|
||||
*/
|
||||
public void start() {
|
||||
for (String URL : Main.getPlugin().getConfig().getStringList("RadioSongs")) {
|
||||
for (String URL : MCTPAudio.getPlugin().getConfig().getStringList("RadioSongs")) {
|
||||
addSong(URL);
|
||||
}
|
||||
|
||||
Bukkit.getScheduler().runTaskAsynchronously(Main.getPlugin(), this::nextSong);
|
||||
Bukkit.getScheduler().runTaskAsynchronously(MCTPAudio.getPlugin(), this::nextSong);
|
||||
|
||||
running = true;
|
||||
}
|
||||
|
@ -57,6 +63,7 @@ public class Playlist {
|
|||
|
||||
/**
|
||||
* Add a song by the url
|
||||
*
|
||||
* @param url The song url (mp3)
|
||||
*/
|
||||
public void addSong(String url) {
|
||||
|
@ -92,7 +99,7 @@ public class Playlist {
|
|||
data.put("task", "RADIO");
|
||||
data.put("path", nextURL);
|
||||
data.put("uuid", p.getUniqueId().toString().replace("-", ""));
|
||||
Main.getClient().sendData(data);
|
||||
MCTPAudio.getClient().sendData(data);
|
||||
}
|
||||
|
||||
int ticks;
|
||||
|
@ -110,9 +117,9 @@ public class Playlist {
|
|||
return;
|
||||
}
|
||||
|
||||
Bukkit.getLogger().info("Started song with duration: " + ticks/20 + " sec.");
|
||||
Bukkit.getLogger().info("Started song with duration: " + ticks / 20 + " sec.");
|
||||
|
||||
currentTimer = Bukkit.getScheduler().runTaskLaterAsynchronously(Main.getPlugin(), () -> {
|
||||
currentTimer = Bukkit.getScheduler().runTaskLaterAsynchronously(MCTPAudio.getPlugin(), () -> {
|
||||
currentTimer = null;
|
||||
nextSong();
|
||||
}, ticks);
|
|
@ -1,8 +1,10 @@
|
|||
package me.mctp.socket;
|
||||
package nl.sbdeveloper.mctpaudio.socket;
|
||||
|
||||
import me.mctp.commands.MCTPAudioCMD;
|
||||
import me.mctp.Main;
|
||||
import me.mctp.managers.PinManager;
|
||||
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
|
||||
import nl.sbdeveloper.mctpaudio.MCTPAudio;
|
||||
import nl.sbdeveloper.mctpaudio.api.events.AudioConnectionUpdateEvent;
|
||||
import nl.sbdeveloper.mctpaudio.managers.PinManager;
|
||||
import nl.sbdeveloper.mctpaudio.managers.WGManager;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.java_websocket.client.WebSocketClient;
|
||||
|
@ -11,23 +13,44 @@ import org.json.simple.JSONObject;
|
|||
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/* Copyright (C) McThemeParks - All Rights Reserved
|
||||
* Unauthorized copying of this file, via any medium is strictly prohibited
|
||||
* Proprietary and confidential
|
||||
* Written by Stijn Bannink <stijnbannink23@gmail.com>, July 2020
|
||||
*/
|
||||
|
||||
public class Client {
|
||||
private String url;
|
||||
private final String url;
|
||||
|
||||
private int taskID = 0;
|
||||
private int controlID = 0;
|
||||
|
||||
private WebSocketClient wsc;
|
||||
|
||||
private boolean connected = false;
|
||||
|
||||
/**
|
||||
* Construct a new client
|
||||
*
|
||||
* @param url The URL to connect to
|
||||
*/
|
||||
public Client(String url) {
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
/**
|
||||
* Connect to the websocket
|
||||
*/
|
||||
public void connect() {
|
||||
if (!this.connected) {
|
||||
this.connected = true;
|
||||
this.controlID = Bukkit.getScheduler().runTaskTimer(Main.getPlugin(), () -> {
|
||||
this.controlID = Bukkit.getScheduler().runTaskTimer(MCTPAudio.getPlugin(), () -> {
|
||||
if (!this.connected) {
|
||||
Bukkit.getScheduler().cancelTask(this.controlID);
|
||||
this.controlID = 0;
|
||||
|
@ -48,7 +71,8 @@ public class Client {
|
|||
|
||||
this.wsc = new WebSocketClient(uri) {
|
||||
@Override
|
||||
public void onOpen(ServerHandshake serverHandshake) {}
|
||||
public void onOpen(ServerHandshake serverHandshake) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMessage(String s) {
|
||||
|
@ -73,7 +97,21 @@ public class Client {
|
|||
|
||||
Player p = Bukkit.getPlayer(pUUID);
|
||||
if (p != null && p.isOnline()) {
|
||||
p.sendMessage(MCTPAudioCMD.prefix + "You are now connected with the audioclient.");
|
||||
AudioConnectionUpdateEvent event = new AudioConnectionUpdateEvent(p, true);
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
|
||||
List<String> regions = WGManager.getRegionsIn(p.getLocation()).stream().map(ProtectedRegion::getId).collect(Collectors.toList());
|
||||
Set<String> list = MCTPAudio.getPlugin().getConfig().getConfigurationSection("Regions").getKeys(false);
|
||||
Optional<String> regionName = regions.stream().filter(list::contains).findFirst();
|
||||
regionName.ifPresent(name -> {
|
||||
String regionURL = MCTPAudio.getPlugin().getConfig().getString("Regions." + name);
|
||||
|
||||
JSONObject data = new JSONObject();
|
||||
data.put("task", "MUSIC");
|
||||
data.put("path", regionURL);
|
||||
data.put("uuid", p.getUniqueId().toString().replace("-", ""));
|
||||
MCTPAudio.getClient().sendData(data);
|
||||
});
|
||||
}
|
||||
|
||||
JSONObject reply = new JSONObject();
|
||||
|
@ -88,7 +126,8 @@ public class Client {
|
|||
UUID pUUID = JSONUtil.formatFromInput(uuid);
|
||||
Player p = Bukkit.getPlayer(pUUID);
|
||||
if (p != null && p.isOnline()) {
|
||||
p.sendMessage(MCTPAudioCMD.prefix + "You are now disconnected from the audioclient.");
|
||||
AudioConnectionUpdateEvent event = new AudioConnectionUpdateEvent(p, false);
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -109,7 +148,7 @@ public class Client {
|
|||
this.wsc.connect();
|
||||
|
||||
if (this.taskID == 0) {
|
||||
this.taskID = Bukkit.getScheduler().runTaskTimerAsynchronously(Main.getPlugin(), () -> {
|
||||
this.taskID = Bukkit.getScheduler().runTaskTimerAsynchronously(MCTPAudio.getPlugin(), () -> {
|
||||
if (Client.this.wsc != null && Client.this.wsc.isOpen()) {
|
||||
Client.this.wsc.send("__PING__");
|
||||
} else {
|
||||
|
@ -129,6 +168,9 @@ public class Client {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Disconnect from socket
|
||||
*/
|
||||
public void disconnect() {
|
||||
if (this.wsc != null) {
|
||||
this.wsc.closeConnection(404, "Disconnected from socket");
|
|
@ -1,4 +1,4 @@
|
|||
package me.mctp.socket;
|
||||
package nl.sbdeveloper.mctpaudio.socket;
|
||||
|
||||
import org.json.simple.JSONObject;
|
||||
import org.json.simple.parser.JSONParser;
|
||||
|
@ -6,15 +6,22 @@ import org.json.simple.parser.ParseException;
|
|||
|
||||
import java.util.UUID;
|
||||
|
||||
/* Copyright (C) McThemeParks - All Rights Reserved
|
||||
* Unauthorized copying of this file, via any medium is strictly prohibited
|
||||
* Proprietary and confidential
|
||||
* Written by Stijn Bannink <stijnbannink23@gmail.com>, July 2020
|
||||
*/
|
||||
|
||||
public class JSONUtil {
|
||||
public static JSONObject parse(String string) {
|
||||
try {
|
||||
JSONParser parser = new JSONParser();
|
||||
return (JSONObject) parser.parse(string);
|
||||
} catch (ParseException ignored) { }
|
||||
} catch (ParseException ignored) {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public static String getValue(JSONObject object, String string) {
|
||||
if (object != null && !object.isEmpty()) {
|
||||
Object obj = object.get(string);
|
||||
|
@ -25,14 +32,14 @@ public class JSONUtil {
|
|||
return null;
|
||||
}
|
||||
|
||||
public static UUID formatFromInput(String uuid) throws IllegalArgumentException{
|
||||
if(uuid == null) throw new IllegalArgumentException();
|
||||
public static UUID formatFromInput(String uuid) throws IllegalArgumentException {
|
||||
if (uuid == null) throw new IllegalArgumentException();
|
||||
uuid = uuid.trim();
|
||||
return uuid.length() == 32 ? fromTrimmed(uuid.replaceAll("-", "")) : UUID.fromString(uuid);
|
||||
}
|
||||
|
||||
public static UUID fromTrimmed(String trimmedUUID) throws IllegalArgumentException{
|
||||
if(trimmedUUID == null) throw new IllegalArgumentException();
|
||||
public static UUID fromTrimmed(String trimmedUUID) throws IllegalArgumentException {
|
||||
if (trimmedUUID == null) throw new IllegalArgumentException();
|
||||
StringBuilder builder = new StringBuilder(trimmedUUID.trim());
|
||||
/* Backwards adding to avoid index adjustments */
|
||||
try {
|
||||
|
@ -40,7 +47,7 @@ public class JSONUtil {
|
|||
builder.insert(16, "-");
|
||||
builder.insert(12, "-");
|
||||
builder.insert(8, "-");
|
||||
} catch (StringIndexOutOfBoundsException e){
|
||||
} catch (StringIndexOutOfBoundsException e) {
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package me.mctp.utils;
|
||||
package nl.sbdeveloper.mctpaudio.utils;
|
||||
|
||||
import com.mpatric.mp3agic.InvalidDataException;
|
||||
import com.mpatric.mp3agic.Mp3File;
|
||||
|
@ -12,6 +12,15 @@ import java.io.InputStream;
|
|||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
|
||||
/* Copyright (C) McThemeParks - All Rights Reserved
|
||||
* Unauthorized copying of this file, via any medium is strictly prohibited
|
||||
* Proprietary and confidential
|
||||
* Written by Stijn Bannink <stijnbannink23@gmail.com>, July 2020
|
||||
*/
|
||||
|
||||
/**
|
||||
* Read the head of a MP3 file.
|
||||
*/
|
||||
public class HeadUtil {
|
||||
public static String getArgument(String selector, String key) {
|
||||
StringBuilder result = new StringBuilder();
|
|
@ -1,10 +1,9 @@
|
|||
package me.mctp.utils;
|
||||
package nl.sbdeveloper.mctpaudio.utils;
|
||||
|
||||
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
|
||||
import me.mctp.managers.WGManager;
|
||||
import nl.sbdeveloper.mctpaudio.managers.WGManager;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
|
||||
import org.bukkit.command.BlockCommandSender;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
@ -14,6 +13,12 @@ import java.util.Comparator;
|
|||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/* Copyright (C) McThemeParks - All Rights Reserved
|
||||
* Unauthorized copying of this file, via any medium is strictly prohibited
|
||||
* Proprietary and confidential
|
||||
* Written by Stijn Bannink <stijnbannink23@gmail.com>, July 2020
|
||||
*/
|
||||
|
||||
public class SpigotPlayerSelector {
|
||||
|
||||
private final String selector;
|
||||
|
@ -54,16 +59,13 @@ public class SpigotPlayerSelector {
|
|||
.filter(player -> distance > player.getLocation().distance(standPoint))
|
||||
.get();
|
||||
players.add(nearest);
|
||||
}
|
||||
|
||||
else {
|
||||
} else {
|
||||
Bukkit.getOnlinePlayers().stream()
|
||||
.filter(player -> player.getLocation().getWorld().getName().equals(standPoint.getWorld().getName()))
|
||||
.min(Comparator.comparing(player -> player.getLocation().distance(standPoint)))
|
||||
.ifPresent(players::add);
|
||||
}
|
||||
}
|
||||
else if (selector.startsWith("@a")) {
|
||||
} else if (selector.startsWith("@a")) {
|
||||
//everyone
|
||||
Location standPoint = getLocation(commandSender);
|
||||
|
||||
|
@ -87,20 +89,16 @@ public class SpigotPlayerSelector {
|
|||
.filter(player -> player.getLocation().getWorld().getName().equals(standPoint.getWorld().getName()))
|
||||
.filter(player -> distance > player.getLocation().distance(standPoint))
|
||||
.collect(Collectors.toList()));
|
||||
}
|
||||
|
||||
else {
|
||||
} else {
|
||||
players.addAll(Bukkit.getOnlinePlayers().stream()
|
||||
.filter(player -> player.getLocation().getWorld().getName().equals(standPoint.getWorld().getName()))
|
||||
.collect(Collectors.toList()));
|
||||
}
|
||||
}
|
||||
else if (selector.length() <= 16) {
|
||||
} else if (selector.length() <= 16) {
|
||||
//player
|
||||
Player player = Bukkit.getPlayer(selector);
|
||||
if (player != null) players.add(player);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
//you fucked it
|
||||
commandSender.sendMessage("Invalid player query. Try something like @a, @p, username or other arguments.");
|
||||
}
|
|
@ -1,18 +1,8 @@
|
|||
name: MCTPAudio
|
||||
version: ${project.version}
|
||||
main: me.mctp.Main
|
||||
main: nl.sbdeveloper.mctpaudio.MCTPAudio
|
||||
api-version: 1.16
|
||||
authors: [ SBDeveloper ]
|
||||
depend: [ WorldGuard ]
|
||||
description: Copyright MaybeFromNL & SBDeveloper
|
||||
|
||||
commands:
|
||||
mctpaudio:
|
||||
description: Main command
|
||||
audio:
|
||||
description: Connect command
|
||||
|
||||
permissions:
|
||||
mctp.admin:
|
||||
description: Admin commands
|
||||
default: op
|
||||
authors: [ SBDeveloper ]
|
||||
description: The audio plugin of MCThemeParks!
|
||||
website: https://mcthemeparks.eu
|
||||
|
|
Loading…
Add table
Reference in a new issue