Skip to content

Commit 44b036e

Browse files
author
Liam
committed
Release
0 parents  commit 44b036e

File tree

22 files changed

+1705
-0
lines changed

22 files changed

+1705
-0
lines changed

.github/workflows/maven.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# This workflow will build a Java project with Maven
2+
# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven
3+
4+
name: Java CI with Maven
5+
6+
on:
7+
push:
8+
branches: [ master ]
9+
pull_request:
10+
branches: [ master ]
11+
12+
jobs:
13+
build:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- uses: actions/checkout@v2
17+
- name: Set up JDK 1.8
18+
uses: actions/setup-java@v1
19+
with:
20+
java-version: 1.8
21+
- name: Deploy
22+
run: mvn --settings settings.xml --batch-mode -V clean deploy
23+
env:
24+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.gitignore

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# Eclipse
2+
/.classpath
3+
/.project
4+
/.settings
5+
6+
# Netbeans
7+
/nbproject
8+
9+
# We active maven!
10+
/build.xml
11+
12+
# Maven
13+
/target
14+
/dependency-reduced-pom.xml
15+
*/target
16+
*/dependency-reduced-pom.xml
17+
18+
# Vim
19+
.*.sw[a-p]
20+
21+
# Various other potential build files
22+
/build
23+
/bin
24+
/dist
25+
/manifest.mf
26+
/MANIFEST.MF
27+
/META-INF/MANIFEST.MF
28+
git.properties
29+
.ssh
30+
key
31+
key.pub
32+
dependency-reduced-pom.xml
33+
34+
# Mac Filesystem Dust
35+
.DS_Store
36+
37+
# IntelliJ IDEA
38+
*.iml
39+
*.ipr
40+
*.iws
41+
.idea/
42+
43+
#Libraries jar files
44+
libraries/*.jar
45+
=======
46+
# Compiled class file
47+
*.class
48+
49+
# Log file
50+
*.log
51+
52+
# BlueJ files
53+
*.ctxt
54+
55+
# Mobile Tools for Java (J2ME)
56+
.mtj.tmp/
57+
58+
# Package Files #
59+
*.jar
60+
*.war
61+
*.nar
62+
*.ear
63+
*.zip
64+
*.tar.gz
65+
*.rar
66+
67+
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
68+
hs_err_pid*

LICENSE

Lines changed: 674 additions & 0 deletions
Large diffs are not rendered by default.

README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Video to Minecraft
2+
This plugin is meant to read video files and allow you to watch it in minecraft using ffmpeg *(no audio)*
3+
4+
# Commands
5+
* `/watch <video>` - This command searches for a video in the plugin's data folder (`plugins/VideoToMinecraft`) and plays it on a map item *(requires `videotominecraft.watch` permission)*
6+
* `/watchmovie <video>` - This command does the same as `/watch` however, it uses item frames and multiple maps to increase the resolution of your video *(requires `videotominecraft.watchmovie` permission)*
7+
8+
# Known Issues
9+
10+
* You have to be looking south to spawn a movie theatre correctly
11+
* The max extraction time is 120 seconds which can limit your
12+
13+
# Next Steps
14+
* Better cache system
15+
* Resource pack server to host a templated pack with audio

pom.xml

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xmlns="http://maven.apache.org/POM/4.0.0"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<groupId>com.birthdates</groupId>
8+
<artifactId>video-to-minecraft</artifactId>
9+
<version>1.0.0</version>
10+
11+
<properties>
12+
<maven.compiler.source>1.8</maven.compiler.source>
13+
<maven.compiler.target>1.8</maven.compiler.target>
14+
<encoding>UTF-8</encoding>
15+
</properties>
16+
17+
<build>
18+
<plugins>
19+
<plugin>
20+
<groupId>org.apache.maven.plugins</groupId>
21+
<artifactId>maven-shade-plugin</artifactId>
22+
<version>3.2.1</version>
23+
<executions>
24+
<execution>
25+
<phase>package</phase>
26+
<goals>
27+
<goal>shade</goal>
28+
</goals>
29+
</execution>
30+
</executions>
31+
</plugin>
32+
</plugins>
33+
</build>
34+
35+
<distributionManagement>
36+
<repository>
37+
<id>github</id>
38+
<name>GitHub Packages</name>
39+
<url>https://maven.pkg.github.com/birthdates/Video-To-Minecraft</url>
40+
</repository>
41+
</distributionManagement>
42+
43+
<repositories>
44+
<!-- This adds the Spigot Maven repository to the build -->
45+
<repository>
46+
<id>spigot-repo</id>
47+
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
48+
</repository>
49+
</repositories>
50+
51+
<dependencies>
52+
<!--This adds the Spigot API artifact to the build -->
53+
<dependency>
54+
<groupId>org.spigotmc</groupId>
55+
<artifactId>spigot-api</artifactId>
56+
<version>1.16.5-R0.1-SNAPSHOT</version>
57+
<scope>provided</scope>
58+
</dependency>
59+
<dependency>
60+
<groupId>org.projectlombok</groupId>
61+
<artifactId>lombok</artifactId>
62+
<version>1.18.20</version>
63+
<scope>provided</scope>
64+
</dependency>
65+
<!-- https://mvnrepository.com/artifact/org.jetbrains/annotations -->
66+
<dependency>
67+
<groupId>org.jetbrains</groupId>
68+
<artifactId>annotations</artifactId>
69+
<version>21.0.0</version>
70+
</dependency>
71+
</dependencies>
72+
73+
</project>

settings.xml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
5+
http://maven.apache.org/xsd/settings-1.0.0.xsd">
6+
7+
<activeProfiles>
8+
<activeProfile>github</activeProfile>
9+
</activeProfiles>
10+
11+
<profiles>
12+
<profile>
13+
<id>github</id>
14+
<repositories>
15+
<repository>
16+
<id>central</id>
17+
<url>https://repo1.maven.org/maven2</url>
18+
</repository>
19+
<repository>
20+
<id>github</id>
21+
<url>https://maven.pkg.github.com/birthdates/*/</url>
22+
<releases><enabled>true</enabled></releases>
23+
<snapshots><enabled>true</enabled></snapshots>
24+
</repository>
25+
</repositories>
26+
</profile>
27+
</profiles>
28+
29+
<servers>
30+
<server>
31+
<id>github</id>
32+
<username>birthdates</username>
33+
<password>${GITHUB_TOKEN}</password>
34+
</server>
35+
</servers>
36+
</settings>
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package com.birthdates.videotominecraft;
2+
3+
import com.birthdates.videotominecraft.command.watch.StopWatchingCommand;
4+
import com.birthdates.videotominecraft.command.watch.WatchCommand;
5+
import com.birthdates.videotominecraft.command.watch.WatchMovieCommand;
6+
import com.birthdates.videotominecraft.executor.WrappedScheduledThreadPoolExecutor;
7+
import com.birthdates.videotominecraft.worker.Worker;
8+
import lombok.Getter;
9+
import org.bukkit.Bukkit;
10+
import org.bukkit.plugin.java.JavaPlugin;
11+
12+
import java.io.File;
13+
import java.util.concurrent.ScheduledThreadPoolExecutor;
14+
15+
@Getter
16+
public class VideoToMinecraft extends JavaPlugin {
17+
18+
@Getter
19+
private static VideoToMinecraft instance;
20+
private final int FPS = 20; //FPS for canvas
21+
private final int WORKERS_PER_THREAD = 1;
22+
private final ScheduledThreadPoolExecutor executorService = new WrappedScheduledThreadPoolExecutor(WORKERS_PER_THREAD);
23+
24+
public void onEnable() {
25+
instance = this;
26+
createDataFolderIfNotExists();
27+
registerCommands();
28+
}
29+
30+
public void onDisable() {
31+
for (int i = Worker.getWorkers().size() - 1; i >= 0; i--) { //loop in reverse to prevent CME
32+
Worker worker = Worker.getWorkers().get(i);
33+
worker.finish();
34+
}
35+
}
36+
37+
public void resizePool() {
38+
int workerCount = Worker.getWorkers().size();
39+
int neededThreads = workerCount / WORKERS_PER_THREAD;
40+
41+
if (neededThreads == 0 || executorService.getCorePoolSize() == neededThreads) return;
42+
executorService.setCorePoolSize(neededThreads);
43+
}
44+
45+
public void postToMainThread(Runnable task) {
46+
Bukkit.getScheduler().runTask(this, task);
47+
}
48+
49+
private void registerCommands() {
50+
getCommand("watch").setExecutor(new WatchCommand());
51+
getCommand("stopwatching").setExecutor(new StopWatchingCommand());
52+
getCommand("watchmovie").setExecutor(new WatchMovieCommand());
53+
}
54+
55+
private void createDataFolderIfNotExists() {
56+
File folder = getDataFolder();
57+
if(folder.exists() || folder.mkdir()) return;
58+
throw new IllegalStateException("Failed to create data folder.");
59+
}
60+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package com.birthdates.videotominecraft.command;
2+
3+
import org.bukkit.ChatColor;
4+
import org.bukkit.command.Command;
5+
import org.bukkit.command.CommandExecutor;
6+
import org.bukkit.command.CommandSender;
7+
import org.bukkit.entity.Player;
8+
9+
/**
10+
* A class to extend to make your command player only.
11+
*/
12+
public abstract class PlayerOnlyCommand implements CommandExecutor {
13+
14+
@Override
15+
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
16+
if (!(sender instanceof Player)) {
17+
sender.sendMessage(ChatColor.RED + "You must be a player to execute this command.");
18+
return false;
19+
}
20+
return true;
21+
}
22+
23+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package com.birthdates.videotominecraft.command.watch;
2+
3+
import com.birthdates.videotominecraft.command.PlayerOnlyCommand;
4+
import com.birthdates.videotominecraft.maps.Maps;
5+
import com.birthdates.videotominecraft.worker.Worker;
6+
import com.birthdates.videotominecraft.worker.impl.FrameWorker;
7+
import org.bukkit.ChatColor;
8+
import org.bukkit.command.Command;
9+
import org.bukkit.command.CommandSender;
10+
import org.bukkit.entity.Player;
11+
import org.bukkit.inventory.ItemStack;
12+
13+
import java.util.Objects;
14+
import java.util.Optional;
15+
16+
/**
17+
* Command used to stop watching a video on a map
18+
*/
19+
public class StopWatchingCommand extends PlayerOnlyCommand {
20+
21+
@Override
22+
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
23+
if (!super.onCommand(sender, command, label, args)) return false; //is not a player
24+
25+
Player player = (Player) sender;
26+
boolean removed =
27+
removeMapAndWorker(player, player.getInventory().getContents()) ||
28+
removeMapAndWorker(player, player.getInventory().getExtraContents());
29+
sender.sendMessage((removed ? ChatColor.GREEN : ChatColor.RED) + "You have " + (removed ? "" : "not") + " removed any video players.");
30+
return true;
31+
}
32+
33+
private boolean removeMapAndWorker(Player player, ItemStack[] contents) {
34+
boolean found = false;
35+
for (ItemStack content : contents) {
36+
if (content == null || !content.hasItemMeta() ||
37+
!content.getItemMeta().hasDisplayName() || !content.getItemMeta().getDisplayName().equals(Maps.getMapName()))
38+
continue;
39+
player.getInventory().remove(content);
40+
41+
//stop worker
42+
Optional<Worker> workerOptional = FrameWorker.getWorkers()
43+
.stream()
44+
.filter(worker -> Objects.equals(worker.getId(), content)).findAny();
45+
workerOptional.ifPresent(Worker::finish);
46+
47+
found = true;
48+
}
49+
return found;
50+
}
51+
}

0 commit comments

Comments
 (0)