Path: blob/main/samples/ayunami2000/VideoMapPacketCodecBukkit.java
8641 views
package ayunami2000;12import java.util.List;34import org.bukkit.craftbukkit.v1_5_R3.entity.CraftPlayer;5import org.bukkit.entity.Player;67import net.minecraft.server.v1_5_R3.Packet;8import net.minecraft.server.v1_5_R3.Packet131ItemData;910public class VideoMapPacketCodecBukkit extends VideoMapPacketCodec {1112/**13* @param mapIds 2D grid of map IDs that make up the screen (mapIds[y][x])14* @param posX audio playback X coord15* @param posY audio playback Y coord16* @param posZ audio playback Z coord17* @param volume the volume of the clip18*/19public VideoMapPacketCodecBukkit(int[][] mapIds, double posX, double posY, double posZ, float volume) {20super(mapIds, posX, posY, posZ, volume);21}2223/**24* @param mapIds 2D grid of map IDs that make up the screen (mapIds[y][x])25* @param posX audio playback X coord26* @param posY audio playback Y coord27* @param posZ audio playback Z coord28*/29public VideoMapPacketCodecBukkit(int[][] mapIds, double posX, double posY, double posZ) {30super(mapIds, posX, posY, posZ);31}3233/**34* @param mapIds 2D grid of map IDs that make up the screen (mapIds[y][x])35*/36public VideoMapPacketCodecBukkit(int[][] mapIds) {37super(mapIds);38}3940public static class VideoMapPacket {41protected final Object packet;42protected VideoMapPacket(byte[] packet) {43this(packet, false);44}45protected VideoMapPacket(byte[] packet, boolean image) {46this.packet = new Packet131ItemData((short)(104 + (image ? 1 : 0)), (short)0, packet);47}48public Object getNativePacket() {49return packet;50}51public void send(Player p) {52nativeSendPacketToPlayer(p, packet);53}54public void send(Player... p) {55for(Player pp : p) {56nativeSendPacketToPlayer(pp, packet);57}58}59public void send(List<Player> p) {60for(Player pp : p) {61nativeSendPacketToPlayer(pp, packet);62}63}64}6566/**67* @param posX audio playback X coord68* @param posY audio playback Y coord69* @param posZ audio playback Z coord70* @param volume the volume of the clip71* @return packet to send to players72*/73public VideoMapPacket moveAudioSourceBukkit(double posX, double posY, double posZ, float volume) {74return new VideoMapPacket(moveAudioSource(posX, posY, posZ, volume));75}7677/**78* unloads video and resets all map object to vanilla renderer79* @return packet to send to players80*/81public VideoMapPacket disableVideoBukkit() {82return new VideoMapPacket(disableVideo());83}8485/**86* unloads image and resets all map object to vanilla renderer87* @return packet to send to players88*/89public VideoMapPacket disableImageBukkit() {90return new VideoMapPacket(disableVideo(), true);91}9293/**94* syncs the server side video timestamp with players95* @return packet to send to players96*/97public VideoMapPacket syncPlaybackWithPlayersBukkit() {98return new VideoMapPacket(syncPlaybackWithPlayers());99}100101/**102* syncs the server side image with players103* @return packet to send to players104*/105public VideoMapPacket syncPlaybackWithPlayersImageBukkit() {106return new VideoMapPacket(syncPlaybackWithPlayers(), true);107}108109/**110* @param url URL to an MP4 or other HTML5 supported video file111* @param loop If the video file should loop112* @param durationSeconds duration of the video in seconds113* @return packet to send to players114*/115public VideoMapPacket beginPlaybackBukkit(String url, boolean loop, float duration) {116return new VideoMapPacket(beginPlayback(url, loop, duration));117}118119/**120* @param url URL to a PNG, JPEG, GIF, or other HTML5 supported image file121* @return packet to send to players122*/123public VideoMapPacket beginPlaybackImageBukkit(String url) {124return new VideoMapPacket(beginPlayback(url));125}126127/**128* Tells the browser to pre-load a URL to a video to be played in the future129* @param url the URL of the video130* @param ttl the amount of time the video should stay loaded131* @return packet to send to players132*/133public static VideoMapPacket bufferVideoBukkit(String url, int ttl) {134return new VideoMapPacket(bufferVideo(url, ttl));135}136137/**138* Tells the browser to pre-load a URL to an image to be played in the future139* @param url the URL of the image140* @param ttl the amount of time the image should stay loaded141* @return packet to send to players142*/143public static VideoMapPacket bufferImageBukkit(String url, int ttl) {144return new VideoMapPacket(bufferVideo(url, ttl), true);145}146147/**148* @param time time in seconds to seek the video to149*/150public VideoMapPacket setPlaybackTimeBukkit(float time) {151return new VideoMapPacket(setPlaybackTime(time));152}153154/**155* @param loop video should loop156*/157public VideoMapPacket setLoopEnableBukkit(boolean loop) {158return new VideoMapPacket(setLoopEnable(loop));159}160161/**162* @param pause set if video should pause163* @return packet to send to players164*/165public VideoMapPacket setPausedBukkit(boolean pause) {166return new VideoMapPacket(setPaused(pause));167}168169public static void nativeSendPacketToPlayer(Player player, Object obj) {170if(obj == null) {171return;172}173((CraftPlayer)player).getHandle().playerConnection.sendPacket((Packet)obj);174}175}176177178