A lot of changes
This commit is contained in:
parent
9f3bb214f7
commit
01f6792719
6 changed files with 131 additions and 23 deletions
|
@ -29,5 +29,14 @@
|
|||
</orderEntry>
|
||||
<orderEntry type="library" scope="PROVIDED" name="spigot-1.14.4" level="project" />
|
||||
<orderEntry type="library" name="Java-WebSocket-1.3.8" level="project" />
|
||||
<orderEntry type="module-library">
|
||||
<library>
|
||||
<CLASSES>
|
||||
<root url="jar://$USER_HOME$/Downloads/WGEvents.jar!/" />
|
||||
</CLASSES>
|
||||
<JAVADOC />
|
||||
<SOURCES />
|
||||
</library>
|
||||
</orderEntry>
|
||||
</component>
|
||||
</module>
|
|
@ -26,7 +26,7 @@ public class MCTPAudioCmd implements CommandExecutor {
|
|||
try {
|
||||
type = AudioType.valueOf(args[2].toUpperCase());
|
||||
} catch (IllegalArgumentException ex) {
|
||||
sender.sendMessage(prefix + args[1] + " is geen correcte type.");
|
||||
sender.sendMessage(prefix + args[2] + " is geen correcte type.");
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -58,12 +58,16 @@ public class MCTPAudioCmd implements CommandExecutor {
|
|||
|
||||
sender.sendMessage(prefix + "Gestart met afspelen!");
|
||||
return true;
|
||||
} else if (args.length == 3 && args[0].equalsIgnoreCase("stop")) {
|
||||
AudioType type;
|
||||
} else if (args.length == 5 && args[0].equalsIgnoreCase("hue")) {
|
||||
int r;
|
||||
int g;
|
||||
int b;
|
||||
try {
|
||||
type = AudioType.valueOf(args[2].toUpperCase());
|
||||
r = Integer.parseInt(args[2]);
|
||||
g = Integer.parseInt(args[3]);
|
||||
b = Integer.parseInt(args[4]);
|
||||
} catch (IllegalArgumentException ex) {
|
||||
sender.sendMessage(prefix + args[1] + " is geen correcte type.");
|
||||
sender.sendMessage(prefix + args[2] + ", " + args[3] + ", " + args[4] + " zijn incorrecte RGB waardes.");
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -81,6 +85,35 @@ public class MCTPAudioCmd implements CommandExecutor {
|
|||
players.addAll(selector.getPlayers(sender));
|
||||
}
|
||||
|
||||
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("uuid", p.getUniqueId().toString().replace("-", ""));
|
||||
Main.getClient().sendData(data);
|
||||
}
|
||||
|
||||
sender.sendMessage(prefix + "Gestart met 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();
|
||||
|
@ -88,7 +121,6 @@ public class MCTPAudioCmd implements CommandExecutor {
|
|||
if (!PinManager.hasPin(p.getUniqueId())) continue;
|
||||
|
||||
data.put("task", "STOP");
|
||||
data.put("type", type.name());
|
||||
data.put("uuid", p.getUniqueId().toString().replace("-", ""));
|
||||
Main.getClient().sendData(data);
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package me.mctp;
|
||||
|
||||
import me.mctp.listener.WGListener;
|
||||
import me.mctp.socket.Client;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
|
@ -19,6 +20,10 @@ public class Main extends JavaPlugin implements Listener {
|
|||
|
||||
Bukkit.getLogger().info(prefix + "loading...");
|
||||
|
||||
getConfig().addDefault("Regions.demosound", "https://audiopagina.mcthemeparks.eu/gallery/voletarium.mp3");
|
||||
getConfig().options().copyDefaults(true);
|
||||
saveConfig();
|
||||
|
||||
pl = this;
|
||||
|
||||
client = new Client("ws://144.91.100.169:30217");
|
||||
|
@ -27,6 +32,8 @@ public class Main extends JavaPlugin implements Listener {
|
|||
getCommand("audio").setExecutor(new MCTPAudioCmd());
|
||||
getCommand("mctpaudio").setExecutor(new MCTPAudioCmd());
|
||||
|
||||
Bukkit.getPluginManager().registerEvents(new WGListener(), this);
|
||||
|
||||
Bukkit.getLogger().info(prefix + " __ __ ____ _____ ____ _ _ _ ");
|
||||
Bukkit.getLogger().info(prefix + " | \\/ |/ ___|_ _| _ \\ / \\ _ _ __| (_) ___ ");
|
||||
Bukkit.getLogger().info(prefix + " | |\\/| | | | | | |_) / _ \\| | | |/ _` | |/ _ \\ ");
|
||||
|
|
55
src/me/mctp/listener/WGListener.java
Normal file
55
src/me/mctp/listener/WGListener.java
Normal file
|
@ -0,0 +1,55 @@
|
|||
package me.mctp.listener;
|
||||
|
||||
import me.mctp.Main;
|
||||
import me.mctp.managers.PinManager;
|
||||
import net.raidstone.wgevents.events.RegionsEnteredEvent;
|
||||
import net.raidstone.wgevents.events.RegionsLeftEvent;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.json.simple.JSONObject;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
|
||||
public class WGListener implements Listener {
|
||||
@EventHandler
|
||||
public void onRegionEnter(RegionsEnteredEvent e) {
|
||||
Set<String> list = Main.getPlugin().getConfig().getConfigurationSection("Regions").getKeys(false);
|
||||
|
||||
if (!Collections.disjoint(list, e.getRegionsNames())) {
|
||||
//One element is the same -> In a region
|
||||
|
||||
Optional<String> name = e.getRegionsNames().stream().filter(list::contains).findFirst();
|
||||
if (!name.isPresent()) return;
|
||||
String regionURL = Main.getPlugin().getConfig().getString("Regions." + name.get());
|
||||
|
||||
JSONObject data = new JSONObject();
|
||||
|
||||
if (!PinManager.hasPin(Objects.requireNonNull(e.getPlayer()).getUniqueId())) return;
|
||||
|
||||
data.put("task", "MUSIC");
|
||||
data.put("path", regionURL);
|
||||
data.put("uuid", e.getPlayer().getUniqueId().toString().replace("-", ""));
|
||||
Main.getClient().sendData(data);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onRegionExit(RegionsLeftEvent e) {
|
||||
Set<String> list = Main.getPlugin().getConfig().getConfigurationSection("Regions").getKeys(false);
|
||||
|
||||
if (!Collections.disjoint(list, e.getRegionsNames())) {
|
||||
//One element is the same -> In a region
|
||||
JSONObject data = new JSONObject();
|
||||
|
||||
if (!PinManager.hasPin(Objects.requireNonNull(e.getPlayer()).getUniqueId())) return;
|
||||
|
||||
data.put("task", "MUSIC");
|
||||
data.put("path", "");
|
||||
data.put("uuid", e.getPlayer().getUniqueId().toString().replace("-", ""));
|
||||
Main.getClient().sendData(data);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -3,7 +3,6 @@ package me.mctp.socket;
|
|||
import me.mctp.Main;
|
||||
import me.mctp.managers.PinManager;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.java_websocket.client.WebSocketClient;
|
||||
import org.java_websocket.handshake.ServerHandshake;
|
||||
import org.json.simple.JSONObject;
|
||||
|
@ -64,14 +63,12 @@ public class Client {
|
|||
String pin = JSONUtil.getValue(json, "pin");
|
||||
if (pin == null || pin.isEmpty()) return;
|
||||
|
||||
UUID pUUID = UUID.fromString(JSONUtil.fixUUID(uuid));
|
||||
UUID pUUID = JSONUtil.formatFromInput(uuid);
|
||||
boolean verified = false;
|
||||
if (Bukkit.getPlayer(pUUID) != null) {
|
||||
verified = PinManager.checkPin(pUUID, pin);
|
||||
}
|
||||
|
||||
Bukkit.getLogger().info("VERIFIED IS: " + verified);
|
||||
|
||||
JSONObject reply = new JSONObject();
|
||||
reply.put("task", "AUTHENTICATION");
|
||||
reply.put("verified", verified);
|
||||
|
|
|
@ -4,6 +4,8 @@ import org.json.simple.JSONObject;
|
|||
import org.json.simple.parser.JSONParser;
|
||||
import org.json.simple.parser.ParseException;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class JSONUtil {
|
||||
public static JSONObject parse(String string) {
|
||||
try {
|
||||
|
@ -23,19 +25,25 @@ public class JSONUtil {
|
|||
return null;
|
||||
}
|
||||
|
||||
public static String fixUUID(String uuid) {
|
||||
if (uuid != null && !uuid.isEmpty()) {
|
||||
StringBuilder sb = new StringBuilder(uuid);
|
||||
sb.insert(8, "-");
|
||||
sb = new StringBuilder(sb.toString());
|
||||
sb.insert(13, "-");
|
||||
sb = new StringBuilder(sb.toString());
|
||||
sb.insert(18, "-");
|
||||
sb = new StringBuilder(sb.toString());
|
||||
sb.insert(23, "-");
|
||||
return sb.toString();
|
||||
} else {
|
||||
return null;
|
||||
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();
|
||||
StringBuilder builder = new StringBuilder(trimmedUUID.trim());
|
||||
/* Backwards adding to avoid index adjustments */
|
||||
try {
|
||||
builder.insert(20, "-");
|
||||
builder.insert(16, "-");
|
||||
builder.insert(12, "-");
|
||||
builder.insert(8, "-");
|
||||
} catch (StringIndexOutOfBoundsException e){
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
|
||||
return UUID.fromString(builder.toString());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue