Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
lDEVinux
GitHub Repository: lDEVinux/eaglercraft
Path: blob/main/samples/ayunami2000/VideoMapPacketCodecBukkit.java
8641 views
1
package ayunami2000;
2
3
import java.util.List;
4
5
import org.bukkit.craftbukkit.v1_5_R3.entity.CraftPlayer;
6
import org.bukkit.entity.Player;
7
8
import net.minecraft.server.v1_5_R3.Packet;
9
import net.minecraft.server.v1_5_R3.Packet131ItemData;
10
11
public class VideoMapPacketCodecBukkit extends VideoMapPacketCodec {
12
13
/**
14
* @param mapIds 2D grid of map IDs that make up the screen (mapIds[y][x])
15
* @param posX audio playback X coord
16
* @param posY audio playback Y coord
17
* @param posZ audio playback Z coord
18
* @param volume the volume of the clip
19
*/
20
public VideoMapPacketCodecBukkit(int[][] mapIds, double posX, double posY, double posZ, float volume) {
21
super(mapIds, posX, posY, posZ, volume);
22
}
23
24
/**
25
* @param mapIds 2D grid of map IDs that make up the screen (mapIds[y][x])
26
* @param posX audio playback X coord
27
* @param posY audio playback Y coord
28
* @param posZ audio playback Z coord
29
*/
30
public VideoMapPacketCodecBukkit(int[][] mapIds, double posX, double posY, double posZ) {
31
super(mapIds, posX, posY, posZ);
32
}
33
34
/**
35
* @param mapIds 2D grid of map IDs that make up the screen (mapIds[y][x])
36
*/
37
public VideoMapPacketCodecBukkit(int[][] mapIds) {
38
super(mapIds);
39
}
40
41
public static class VideoMapPacket {
42
protected final Object packet;
43
protected VideoMapPacket(byte[] packet) {
44
this(packet, false);
45
}
46
protected VideoMapPacket(byte[] packet, boolean image) {
47
this.packet = new Packet131ItemData((short)(104 + (image ? 1 : 0)), (short)0, packet);
48
}
49
public Object getNativePacket() {
50
return packet;
51
}
52
public void send(Player p) {
53
nativeSendPacketToPlayer(p, packet);
54
}
55
public void send(Player... p) {
56
for(Player pp : p) {
57
nativeSendPacketToPlayer(pp, packet);
58
}
59
}
60
public void send(List<Player> p) {
61
for(Player pp : p) {
62
nativeSendPacketToPlayer(pp, packet);
63
}
64
}
65
}
66
67
/**
68
* @param posX audio playback X coord
69
* @param posY audio playback Y coord
70
* @param posZ audio playback Z coord
71
* @param volume the volume of the clip
72
* @return packet to send to players
73
*/
74
public VideoMapPacket moveAudioSourceBukkit(double posX, double posY, double posZ, float volume) {
75
return new VideoMapPacket(moveAudioSource(posX, posY, posZ, volume));
76
}
77
78
/**
79
* unloads video and resets all map object to vanilla renderer
80
* @return packet to send to players
81
*/
82
public VideoMapPacket disableVideoBukkit() {
83
return new VideoMapPacket(disableVideo());
84
}
85
86
/**
87
* unloads image and resets all map object to vanilla renderer
88
* @return packet to send to players
89
*/
90
public VideoMapPacket disableImageBukkit() {
91
return new VideoMapPacket(disableVideo(), true);
92
}
93
94
/**
95
* syncs the server side video timestamp with players
96
* @return packet to send to players
97
*/
98
public VideoMapPacket syncPlaybackWithPlayersBukkit() {
99
return new VideoMapPacket(syncPlaybackWithPlayers());
100
}
101
102
/**
103
* syncs the server side image with players
104
* @return packet to send to players
105
*/
106
public VideoMapPacket syncPlaybackWithPlayersImageBukkit() {
107
return new VideoMapPacket(syncPlaybackWithPlayers(), true);
108
}
109
110
/**
111
* @param url URL to an MP4 or other HTML5 supported video file
112
* @param loop If the video file should loop
113
* @param durationSeconds duration of the video in seconds
114
* @return packet to send to players
115
*/
116
public VideoMapPacket beginPlaybackBukkit(String url, boolean loop, float duration) {
117
return new VideoMapPacket(beginPlayback(url, loop, duration));
118
}
119
120
/**
121
* @param url URL to a PNG, JPEG, GIF, or other HTML5 supported image file
122
* @return packet to send to players
123
*/
124
public VideoMapPacket beginPlaybackImageBukkit(String url) {
125
return new VideoMapPacket(beginPlayback(url));
126
}
127
128
/**
129
* Tells the browser to pre-load a URL to a video to be played in the future
130
* @param url the URL of the video
131
* @param ttl the amount of time the video should stay loaded
132
* @return packet to send to players
133
*/
134
public static VideoMapPacket bufferVideoBukkit(String url, int ttl) {
135
return new VideoMapPacket(bufferVideo(url, ttl));
136
}
137
138
/**
139
* Tells the browser to pre-load a URL to an image to be played in the future
140
* @param url the URL of the image
141
* @param ttl the amount of time the image should stay loaded
142
* @return packet to send to players
143
*/
144
public static VideoMapPacket bufferImageBukkit(String url, int ttl) {
145
return new VideoMapPacket(bufferVideo(url, ttl), true);
146
}
147
148
/**
149
* @param time time in seconds to seek the video to
150
*/
151
public VideoMapPacket setPlaybackTimeBukkit(float time) {
152
return new VideoMapPacket(setPlaybackTime(time));
153
}
154
155
/**
156
* @param loop video should loop
157
*/
158
public VideoMapPacket setLoopEnableBukkit(boolean loop) {
159
return new VideoMapPacket(setLoopEnable(loop));
160
}
161
162
/**
163
* @param pause set if video should pause
164
* @return packet to send to players
165
*/
166
public VideoMapPacket setPausedBukkit(boolean pause) {
167
return new VideoMapPacket(setPaused(pause));
168
}
169
170
public static void nativeSendPacketToPlayer(Player player, Object obj) {
171
if(obj == null) {
172
return;
173
}
174
((CraftPlayer)player).getHandle().playerConnection.sendPacket((Packet)obj);
175
}
176
}
177
178