This repository was archived by the owner on Dec 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVideoPanel.cs
More file actions
166 lines (140 loc) · 6.8 KB
/
VideoPanel.cs
File metadata and controls
166 lines (140 loc) · 6.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
using BrokeProtocol.API;
using BrokeProtocol.Collections;
using BrokeProtocol.Entities;
using BrokeProtocol.Required;
using System.Collections.Generic;
using System.Linq;
using UnityEngine.UI;
using YouTubeApiSharp;
namespace YoutubePlayer
{
public class Important
{
private const string videoPanel = "videoPanel";
private const string title = "&7Video Panel";
private const string customVideo = "customVideo";
private const string stopVideo = "stopVideo";
private const string youtubePanel = "youtubePanel";
private const string youtubePlay = "youtubePlay";
// default permission
private const string defaultVideoPerm = "bp.videoDefault";
private const string stopVideoPerm = "bp.videoStop";
private const string customVideoPerm = "bp.videoCustom";
// youtubeplayer permission
private const string YTPlayPerm = "yt.play";
private bool VideoPermission(ShPlayer player, ShEntity videoPlayer, string permission, bool checkLimit = false)
{
if (!videoPlayer) return false;
if (checkLimit)
{
const int videoLimit = 3;
int videoCount = 0;
foreach (var e in videoPlayer.svEntity.sector.controlled)
{
if (e != videoPlayer && !string.IsNullOrWhiteSpace(e.svEntity.videoURL))
videoCount++;
}
if (videoCount >= videoLimit)
{
player.svPlayer.SendGameMessage($"Video limit of {videoLimit} reached");
return false;
}
}
return player.InActionRange(videoPlayer) && (player.InOwnApartment || player.svPlayer.HasPermission(permission));
}
[Target(GameSourceEvent.PlayerVideoPanel, ExecutionMode.Override)]
public void OnVideoPanel(ShPlayer player, ShEntity videoEntity)
{
var options = new List<LabelID>();
if (VideoPermission(player, videoEntity, YTPlayPerm))
{
options.Add(new LabelID("&cYouTube", youtubePanel));
}
if (VideoPermission(player, videoEntity, customVideoPerm))
{
options.Add(new LabelID("&6Custom Video URL", customVideo));
}
if (VideoPermission(player, videoEntity, stopVideoPerm))
{
options.Add(new LabelID("&4Stop Video", stopVideo));
}
if (VideoPermission(player, videoEntity, defaultVideoPerm))
{
int index = 0;
foreach (var option in player.manager.svManager.videoOptions)
{
options.Add(new LabelID(option.label, index.ToString()));
index++;
}
}
player.svPlayer.SendOptionMenu(title, videoEntity.ID, videoPanel, options.ToArray(), new LabelID[] { new LabelID("Select", string.Empty) });
}
[Target(GameSourceEvent.PlayerOptionAction, ExecutionMode.Test)]
public bool OnOptionAction(ShPlayer player, int targetID, string menuID, string optionID, string actionID)
{
var videoEntity = EntityCollections.FindByID(targetID);
switch (menuID)
{
case videoPanel:
if (optionID == customVideo && VideoPermission(player, videoEntity, customVideoPerm))
{
player.svPlayer.SendGameMessage("Only direct video links supported - Can upload to Imgur or Discord and link that");
player.svPlayer.SendInputMenu("Direct MP4/WEBM URL", targetID, customVideo, InputField.ContentType.Standard, 128);
}
else if (optionID == stopVideo && VideoPermission(player, videoEntity, stopVideoPerm))
{
videoEntity.svEntity.SvStopVideo();
player.svPlayer.DestroyMenu(videoPanel);
}
else if (VideoPermission(player, videoEntity, defaultVideoPerm, true) && int.TryParse(optionID, out var index))
{
videoEntity.svEntity.SvStartDefaultVideo(index);
player.svPlayer.DestroyMenu(videoPanel);
}
else if (optionID == youtubePanel && VideoPermission(player, videoEntity, YTPlayPerm))
{
List<LabelID> options = new List<LabelID>();
if (VideoPermission(player, videoEntity, YTPlayPerm))
{
options.Add(new LabelID("Play via link", "ytplay"));
}
player.svPlayer.SendOptionMenu("YouTube Panel", videoEntity.ID, youtubePanel, options.ToArray(), new LabelID[] { new LabelID("Select", string.Empty) });
}
return false;
case youtubePanel:
if (optionID == "ytplay" && VideoPermission(player, videoEntity, YTPlayPerm))
{
player.svPlayer.SendGameMessage("〔<color=#546eff>YouTubePlayer</color>〕 | You have provide video link");
player.svPlayer.SendInputMenu("Link", targetID, youtubePlay, InputField.ContentType.Standard, 128);
}
return false;
default:
return true;
}
}
[Target(GameSourceEvent.PlayerSubmitInput, ExecutionMode.Test)]
public bool OnSubmitInput(ShPlayer player, int targetID, string menuID, string input)
{
ShEntity videoEntity = EntityCollections.FindByID(targetID);
switch (menuID)
{
case youtubePlay:
IEnumerable<VideoInfo> videoInfos = DownloadUrlResolver.GetDownloadUrls(input);
VideoInfo video = videoInfos.First(info => info.VideoType == VideoType.Mp4);
if (video.RequiresDecryption) { DownloadUrlResolver.DecryptDownloadUrl(video); }
if (VideoPermission(player, videoEntity, YTPlayPerm, true) && input.StartsWith("https://"))
{
player.svPlayer.SendGameMessage("〔<color=#546eff>YouTubePlayer</color>〕 | Please wait a moment");
videoEntity.svEntity.SvStartCustomVideo(video.DownloadUrl);
}
else
{
player.svPlayer.SendGameMessage("〔<color=#546eff>YouTubePlayer</color>〕 | You must have permission and start with 'https://'");
}
return false;
default:
return true;
}
}
}
}