mirror of
https://github.com/ayunami2000/ayunEagVidMap.git
synced 2024-12-21 22:24:10 -08:00
Will it work?
This commit is contained in:
parent
959f6da907
commit
021a4a9eb2
|
@ -11,7 +11,6 @@ import org.bukkit.event.player.PlayerJoinEvent;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
public class Main extends JavaPlugin implements CommandExecutor, Listener {
|
public class Main extends JavaPlugin implements CommandExecutor, Listener {
|
||||||
private boolean playing = false;
|
|
||||||
private VideoMapPacketCodecBukkit videoMapCodec = null;
|
private VideoMapPacketCodecBukkit videoMapCodec = null;
|
||||||
private int[][] mapIds;
|
private int[][] mapIds;
|
||||||
private Location audioLoc;
|
private Location audioLoc;
|
||||||
|
@ -21,25 +20,12 @@ public class Main extends JavaPlugin implements CommandExecutor, Listener {
|
||||||
public void onEnable(){
|
public void onEnable(){
|
||||||
this.saveDefaultConfig();
|
this.saveDefaultConfig();
|
||||||
this.getCommand("ayunvid").setExecutor(this);
|
this.getCommand("ayunvid").setExecutor(this);
|
||||||
int width = this.getConfig().getInt("width");
|
|
||||||
int height = this.getConfig().getInt("width");
|
|
||||||
mapIds = new int[height][width];
|
|
||||||
int offset = this.getConfig().getInt("offset");
|
|
||||||
for (int y = 0; y < mapIds.length; y++) {
|
|
||||||
for (int x = 0; x < mapIds[y].length; x++) {
|
|
||||||
mapIds[y][x] = offset++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
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"));
|
||||||
videoMapCodec = new VideoMapPacketCodecBukkit(mapIds, audioLoc.getX(), audioLoc.getY(), audioLoc.getZ(), 0.5f);
|
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.getServer().getScheduler().scheduleSyncRepeatingTask(this, this::syncToAllPlayers, 10000, 10000); // sync every 10 seconds
|
||||||
for (Player player : this.getServer().getOnlinePlayers()) {
|
|
||||||
VideoMapPacketCodecBukkit.nativeSendPacketToPlayer(player, videoMapCodec.syncPlaybackWithPlayersBukkit());
|
|
||||||
}
|
|
||||||
}, 10000, 10000); // sync every 10 seconds
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -47,11 +33,36 @@ public class Main extends JavaPlugin implements CommandExecutor, Listener {
|
||||||
videoMapCodec.disableVideoBukkit();
|
videoMapCodec.disableVideoBukkit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void syncToPlayer(Player player) {
|
||||||
|
VideoMapPacketCodecBukkit.nativeSendPacketToPlayer(player, videoMapCodec.syncPlaybackWithPlayersBukkit());
|
||||||
|
}
|
||||||
|
|
||||||
|
private void syncToAllPlayers() {
|
||||||
|
for (Player player : this.getServer().getOnlinePlayers()) {
|
||||||
|
syncToPlayer(player);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void sendToAllPlayers(VideoMapPacketCodecBukkit.VideoMapPacket p) {
|
||||||
|
for (Player player : this.getServer().getOnlinePlayers()) {
|
||||||
|
VideoMapPacketCodecBukkit.nativeSendPacketToPlayer(player, p);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setSize(int width, int height) {
|
||||||
|
mapIds = new int[height][width];
|
||||||
|
int offset = this.getConfig().getInt("offset");
|
||||||
|
for (int y = 0; y < mapIds.length; y++) {
|
||||||
|
for (int x = 0; x < mapIds[y].length; x++) {
|
||||||
|
mapIds[y][x] = offset++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
videoMapCodec = new VideoMapPacketCodecBukkit(mapIds, audioLoc.getX(), audioLoc.getY(), audioLoc.getZ(), 0.5f);
|
||||||
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||||
if (playing) {
|
syncToPlayer(event.getPlayer());
|
||||||
VideoMapPacketCodecBukkit.nativeSendPacketToPlayer(event.getPlayer(), videoMapCodec.);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -69,19 +80,46 @@ public class Main extends JavaPlugin implements CommandExecutor, Listener {
|
||||||
}
|
}
|
||||||
this.getConfig().set("url", args[1]);
|
this.getConfig().set("url", args[1]);
|
||||||
this.saveConfig();
|
this.saveConfig();
|
||||||
|
url = args[1];
|
||||||
|
sendToAllPlayers(videoMapCodec.beginPlaybackBukkit(url, true, Integer.MAX_VALUE / 1000.0f));
|
||||||
sender.sendMessage("seturl");
|
sender.sendMessage("seturl");
|
||||||
break;
|
break;
|
||||||
case "l":
|
case "l":
|
||||||
case "loc":
|
case "loc":
|
||||||
case "location":
|
case "location":
|
||||||
|
if (args.length < 4) {
|
||||||
|
sender.sendMessage("not enough args, using current location...");
|
||||||
|
if (!(sender instanceof Player)) {
|
||||||
|
sender.sendMessage("you are not in game! you must specify the coordinates to use this command from console...");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
audioLoc = ((Player) sender).getLocation();
|
||||||
|
} else {
|
||||||
|
double x,y,z;
|
||||||
|
try {
|
||||||
|
x = Double.parseDouble(args[1]);
|
||||||
|
y = Double.parseDouble(args[2]);
|
||||||
|
z = Double.parseDouble(args[3]);
|
||||||
|
} catch(NumberFormatException e) {
|
||||||
|
sender.sendMessage("one or more of the provided arguments is not a number!");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
audioLoc.setX(x);
|
||||||
|
audioLoc.setY(y);
|
||||||
|
audioLoc.setZ(z);
|
||||||
|
}
|
||||||
|
syncToAllPlayers();
|
||||||
sender.sendMessage("set location of audio");
|
sender.sendMessage("set location of audio");
|
||||||
break;
|
break;
|
||||||
case "p":
|
case "p":
|
||||||
case "play":
|
case "play":
|
||||||
case "pause":
|
case "pause":
|
||||||
sender.sendMessage("resuming & loading if needed, or pausing");
|
sender.sendMessage("resuming & loading if needed, or pausing");
|
||||||
|
if (videoMapCodec.isPaused()) {
|
||||||
new VideoMapPacketCodecBukkit()
|
sendToAllPlayers(videoMapCodec.beginPlaybackBukkit(url, true, Integer.MAX_VALUE / 1000.0f));
|
||||||
|
} else {
|
||||||
|
sendToAllPlayers(videoMapCodec.setPausedBukkit(true));
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case "s":
|
case "s":
|
||||||
case "size":
|
case "size":
|
||||||
|
@ -101,6 +139,9 @@ public class Main extends JavaPlugin implements CommandExecutor, Listener {
|
||||||
this.getConfig().set("width", width);
|
this.getConfig().set("width", width);
|
||||||
this.getConfig().set("height", height);
|
this.getConfig().set("height", height);
|
||||||
this.saveConfig();
|
this.saveConfig();
|
||||||
|
sendToAllPlayers(videoMapCodec.disableVideoBukkit());
|
||||||
|
setSize(width, height);
|
||||||
|
syncToAllPlayers();
|
||||||
sender.sendMessage("set width & height");
|
sender.sendMessage("set width & height");
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user