mirror of
https://github.com/ayunami2000/ayunEagVidMap.git
synced 2024-12-21 22:24:10 -08:00
start messages...
This commit is contained in:
parent
e2e0cc12a6
commit
c5e4c01f8a
|
@ -1,5 +1,6 @@
|
||||||
package me.ayunami2000.ayunEagVidMap;
|
package me.ayunami2000.ayunEagVidMap;
|
||||||
|
|
||||||
|
import org.bukkit.command.BlockCommandSender;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandExecutor;
|
import org.bukkit.command.CommandExecutor;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
|
@ -11,27 +12,39 @@ import org.bukkit.plugin.java.JavaPlugin;
|
||||||
import org.bukkit.util.Vector;
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
public class Main extends JavaPlugin implements CommandExecutor, Listener {
|
public class Main extends JavaPlugin implements CommandExecutor, Listener {
|
||||||
//todo: add queue command + store audio loc world & dont send to players in other worlds
|
//todo: add queue command + store audio loc world & dont send to players in other worlds???
|
||||||
|
//todo: also when holding video map play audio at player location for that player
|
||||||
|
|
||||||
|
public static Main plugin;
|
||||||
|
|
||||||
private VideoMapPacketCodecBukkit videoMapCodec = null;
|
private VideoMapPacketCodecBukkit videoMapCodec = null;
|
||||||
private Vector audioLoc = new Vector(0, 100, 0);
|
private Vector audioLoc = new Vector(0, 100, 0);
|
||||||
private String url = "";
|
private String url = "";
|
||||||
private boolean urlChanged = true;
|
private boolean urlChanged = true;
|
||||||
|
private int syncTask = -1;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onLoad(){
|
||||||
|
plugin = this;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEnable(){
|
public void onEnable(){
|
||||||
|
MessageHandler.initMessages();
|
||||||
this.saveDefaultConfig();
|
this.saveDefaultConfig();
|
||||||
this.getCommand("ayunvid").setExecutor(this);
|
|
||||||
audioLoc.setX(this.getConfig().getDouble("audio.x"));
|
audioLoc.setX(this.getConfig().getDouble("audio.x"));
|
||||||
audioLoc.setY(this.getConfig().getDouble("audio.y"));
|
audioLoc.setY(this.getConfig().getDouble("audio.y"));
|
||||||
audioLoc.setZ(this.getConfig().getDouble("audio.z"));
|
audioLoc.setZ(this.getConfig().getDouble("audio.z"));
|
||||||
setSize(this.getConfig().getInt("width"), this.getConfig().getInt("width"));
|
setSize(this.getConfig().getInt("width"), this.getConfig().getInt("width"));
|
||||||
url = this.getConfig().getString("url");
|
url = this.getConfig().getString("url");
|
||||||
this.getServer().getScheduler().scheduleSyncRepeatingTask(this, this::syncToAllPlayers, 10000, 10000); // sync every 10 seconds
|
syncTask = this.getServer().getScheduler().scheduleSyncRepeatingTask(this, this::syncToAllPlayers, 10000, 10000); // sync every 10 seconds
|
||||||
|
this.getCommand("ayunvid").setExecutor(this);
|
||||||
|
this.getServer().getPluginManager().registerEvents(this, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDisable(){
|
public void onDisable(){
|
||||||
|
this.getServer().getScheduler().cancelTask(syncTask);
|
||||||
sendToAllPlayers(videoMapCodec.disableVideoBukkit());
|
sendToAllPlayers(videoMapCodec.disableVideoBukkit());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -66,51 +79,56 @@ public class Main extends JavaPlugin implements CommandExecutor, Listener {
|
||||||
@Override
|
@Override
|
||||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||||
if (args.length == 0){
|
if (args.length == 0){
|
||||||
sender.sendMessage("usage");
|
MessageHandler.sendPrefixedMessage(sender, "usage");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
switch (args[0].toLowerCase()) {
|
switch (args[0].toLowerCase()) {
|
||||||
|
case "h":
|
||||||
|
case "help":
|
||||||
|
MessageHandler.sendPrefixedMessage(sender, "usage");
|
||||||
|
break;
|
||||||
case "u":
|
case "u":
|
||||||
case "url":
|
case "url":
|
||||||
if (args.length < 2) {
|
if (args.length < 2) {
|
||||||
sender.sendMessage("no url specified!");
|
MessageHandler.sendPrefixedMessage(sender, "currentUrl", url);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
this.getConfig().set("url", args[1]);
|
this.getConfig().set("url", args[1]);
|
||||||
this.saveConfig();
|
this.saveConfig();
|
||||||
url = args[1];
|
url = args[1];
|
||||||
urlChanged = true;
|
urlChanged = true;
|
||||||
sender.sendMessage("seturl");
|
MessageHandler.sendPrefixedMessage(sender, "setUrl");
|
||||||
break;
|
break;
|
||||||
case "a":
|
|
||||||
case "aud":
|
|
||||||
case "audio":
|
|
||||||
case "audloc":
|
|
||||||
case "audioloc":
|
|
||||||
case "audiolocation":
|
|
||||||
case "l":
|
case "l":
|
||||||
case "loc":
|
case "loc":
|
||||||
case "location":
|
case "location":
|
||||||
if (args.length < 4) {
|
if (args.length < 4) {
|
||||||
sender.sendMessage("not enough args, using current location...");
|
if(sender instanceof Player) {
|
||||||
if (!(sender instanceof Player)) {
|
MessageHandler.sendPrefixedMessage(sender, "locCurrent");
|
||||||
sender.sendMessage("you are not in game! you must specify the coordinates to use this command from console...");
|
audioLoc = ((Player) sender).getLocation().toVector();
|
||||||
|
} else if (sender instanceof BlockCommandSender) {
|
||||||
|
MessageHandler.sendPrefixedMessage(sender, "locCurrent");
|
||||||
|
audioLoc = ((BlockCommandSender) sender).getBlock().getLocation().toVector().clone().add(new Vector(0.5, 0.5, 0.5));
|
||||||
|
} else {
|
||||||
|
MessageHandler.sendPrefixedMessage(sender, "locFromConsole");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
audioLoc = ((Player) sender).getLocation().toVector();
|
|
||||||
} else {
|
} else {
|
||||||
double x,y,z;
|
double x,y,z;
|
||||||
|
int offendingIndex = 1;
|
||||||
try {
|
try {
|
||||||
x = Double.parseDouble(args[1]);
|
x = Double.parseDouble(args[1]);
|
||||||
|
offendingIndex++;
|
||||||
y = Double.parseDouble(args[2]);
|
y = Double.parseDouble(args[2]);
|
||||||
|
offendingIndex++;
|
||||||
z = Double.parseDouble(args[3]);
|
z = Double.parseDouble(args[3]);
|
||||||
} catch(NumberFormatException e) {
|
} catch(NumberFormatException e) {
|
||||||
sender.sendMessage("one or more of the provided arguments is not a number!");
|
MessageHandler.sendPrefixedMessage(sender, "notANumber", args[offendingIndex]);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
audioLoc.setX(x);
|
audioLoc.setX(x + 0.5);
|
||||||
audioLoc.setY(y);
|
audioLoc.setY(y + 0.5);
|
||||||
audioLoc.setZ(z);
|
audioLoc.setZ(z + 0.5);
|
||||||
}
|
}
|
||||||
this.getConfig().set("audio.x", audioLoc.getX());
|
this.getConfig().set("audio.x", audioLoc.getX());
|
||||||
this.getConfig().set("audio.y", audioLoc.getY());
|
this.getConfig().set("audio.y", audioLoc.getY());
|
||||||
|
@ -119,19 +137,22 @@ public class Main extends JavaPlugin implements CommandExecutor, Listener {
|
||||||
float ct = videoMapCodec.getPlaybackTime();
|
float ct = videoMapCodec.getPlaybackTime();
|
||||||
sendToAllPlayers(videoMapCodec.moveAudioSourceBukkit(audioLoc.getX(), audioLoc.getY(), audioLoc.getZ(), 0.5f));
|
sendToAllPlayers(videoMapCodec.moveAudioSourceBukkit(audioLoc.getX(), audioLoc.getY(), audioLoc.getZ(), 0.5f));
|
||||||
sendToAllPlayers(videoMapCodec.setPlaybackTimeBukkit(ct));
|
sendToAllPlayers(videoMapCodec.setPlaybackTimeBukkit(ct));
|
||||||
sender.sendMessage("set location of audio");
|
MessageHandler.sendPrefixedMessage(sender, "locSet", audioLoc);
|
||||||
break;
|
break;
|
||||||
case "p":
|
case "p":
|
||||||
case "play":
|
case "play":
|
||||||
case "pause":
|
case "pause":
|
||||||
sender.sendMessage("resuming & loading if needed, or pausing");
|
|
||||||
if (urlChanged || videoMapCodec.isPaused()) {
|
if (urlChanged || videoMapCodec.isPaused()) {
|
||||||
if (urlChanged) {
|
if (urlChanged) {
|
||||||
urlChanged = false;
|
urlChanged = false;
|
||||||
|
MessageHandler.sendPrefixedMessage(sender, "playing");
|
||||||
sendToAllPlayers(videoMapCodec.beginPlaybackBukkit(url, true, Integer.MAX_VALUE / 1000.0f));
|
sendToAllPlayers(videoMapCodec.beginPlaybackBukkit(url, true, Integer.MAX_VALUE / 1000.0f));
|
||||||
|
} else {
|
||||||
|
MessageHandler.sendPrefixedMessage(sender, "resuming");
|
||||||
}
|
}
|
||||||
sendToAllPlayers(videoMapCodec.setPausedBukkit(false));
|
sendToAllPlayers(videoMapCodec.setPausedBukkit(false));
|
||||||
} else {
|
} else {
|
||||||
|
MessageHandler.sendPrefixedMessage(sender, "pausing");
|
||||||
sendToAllPlayers(videoMapCodec.setPausedBukkit(true));
|
sendToAllPlayers(videoMapCodec.setPausedBukkit(true));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -0,0 +1,61 @@
|
||||||
|
package me.ayunami2000.ayunEagVidMap;
|
||||||
|
|
||||||
|
import org.apache.commons.lang.StringUtils;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.StandardCopyOption;
|
||||||
|
import java.text.MessageFormat;
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
public class MessageHandler {
|
||||||
|
public static HashMap<String, String> messageData = new HashMap<>();
|
||||||
|
|
||||||
|
public static void initMessages() {
|
||||||
|
File directory = Main.plugin.getDataFolder();
|
||||||
|
if (! directory.exists()){
|
||||||
|
directory.mkdir();
|
||||||
|
}
|
||||||
|
|
||||||
|
File f = new File(directory + File.separator + "messages.yml");
|
||||||
|
if (!f.exists()) {
|
||||||
|
try {
|
||||||
|
InputStream initialStream = Main.plugin.getResource("messages.yml");
|
||||||
|
Files.copy(initialStream, f.toPath(), StandardCopyOption.REPLACE_EXISTING);
|
||||||
|
initialStream.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
FileConfiguration config = YamlConfiguration.loadConfiguration(f);
|
||||||
|
for (String message : config.getConfigurationSection("").getKeys(false)) {
|
||||||
|
if (config.isString(message)) {
|
||||||
|
messageData.put(message, config.getString(message).replaceAll("&", "§"));
|
||||||
|
}else if(config.isList(message)){
|
||||||
|
messageData.put(message, StringUtils.join(config.getStringList(message), "\n").replaceAll("&", "§"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getMessage(String key, Object... args){
|
||||||
|
return MessageFormat.format(messageData.getOrDefault(key, key), args);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getPrefixedMessage(String key, Object... args){
|
||||||
|
return ("\n" + getMessage(key, args)).replace("\n", "\n" + getMessage("prefix")).substring(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void sendMessage(CommandSender commandSender, String key, Object... args){
|
||||||
|
commandSender.sendMessage(getMessage(key, args));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void sendPrefixedMessage(CommandSender commandSender, String key, Object... args){
|
||||||
|
commandSender.sendMessage(getPrefixedMessage(key, args));
|
||||||
|
}
|
||||||
|
}
|
17
src/main/resources/messages.yml
Normal file
17
src/main/resources/messages.yml
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
prefix: "&9&l[&b&l&oayun&d&lEVM&9&l] &r"
|
||||||
|
usage:
|
||||||
|
- "&3&nUsage:"
|
||||||
|
- "&7&o/ayunvid [h|help] &3- Show this message."
|
||||||
|
- "&7&o/ayunvid <u|url> <url> &3- Specify the video URL to use. (Must be CORS-compatible!)"
|
||||||
|
- "&7&o/ayunvid <l|loc|location> [x y z] &3- Specify the location that the audio will come from."
|
||||||
|
- "&7&o/ayunvid <p|play|pause> &3- Toggle playback of the video."
|
||||||
|
- "&7&o/ayunvid <s|size> <width> <height>&3- Set size of video, in maps. E.g. a width of 2 and a height of 3 would result in a video using 6 maps."
|
||||||
|
currentUrl: "&3Current URL: {0}"
|
||||||
|
setUrl: "&3Successfully set URL."
|
||||||
|
locFromConsole: "&cError: You must specify the coordinates when running this command from the console!"
|
||||||
|
locCurrent: "&3Using current location..."
|
||||||
|
notANumber: "&cError: \"{0}\" is not a valid number!"
|
||||||
|
locSet: "&3Successfully set audio location. ({0})"
|
||||||
|
playing: "&3Loading and playing video..."
|
||||||
|
resuming: "&3Resuming video..."
|
||||||
|
pausing: "&3Pausing video..."
|
Loading…
Reference in New Issue
Block a user