-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Liam
committed
May 25, 2021
0 parents
commit 44b036e
Showing
22 changed files
with
1,705 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# This workflow will build a Java project with Maven | ||
# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven | ||
|
||
name: Java CI with Maven | ||
|
||
on: | ||
push: | ||
branches: [ master ] | ||
pull_request: | ||
branches: [ master ] | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Set up JDK 1.8 | ||
uses: actions/setup-java@v1 | ||
with: | ||
java-version: 1.8 | ||
- name: Deploy | ||
run: mvn --settings settings.xml --batch-mode -V clean deploy | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
# Eclipse | ||
/.classpath | ||
/.project | ||
/.settings | ||
|
||
# Netbeans | ||
/nbproject | ||
|
||
# We active maven! | ||
/build.xml | ||
|
||
# Maven | ||
/target | ||
/dependency-reduced-pom.xml | ||
*/target | ||
*/dependency-reduced-pom.xml | ||
|
||
# Vim | ||
.*.sw[a-p] | ||
|
||
# Various other potential build files | ||
/build | ||
/bin | ||
/dist | ||
/manifest.mf | ||
/MANIFEST.MF | ||
/META-INF/MANIFEST.MF | ||
git.properties | ||
.ssh | ||
key | ||
key.pub | ||
dependency-reduced-pom.xml | ||
|
||
# Mac Filesystem Dust | ||
.DS_Store | ||
|
||
# IntelliJ IDEA | ||
*.iml | ||
*.ipr | ||
*.iws | ||
.idea/ | ||
|
||
#Libraries jar files | ||
libraries/*.jar | ||
======= | ||
# Compiled class file | ||
*.class | ||
|
||
# Log file | ||
*.log | ||
|
||
# BlueJ files | ||
*.ctxt | ||
|
||
# Mobile Tools for Java (J2ME) | ||
.mtj.tmp/ | ||
|
||
# Package Files # | ||
*.jar | ||
*.war | ||
*.nar | ||
*.ear | ||
*.zip | ||
*.tar.gz | ||
*.rar | ||
|
||
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml | ||
hs_err_pid* |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# Video to Minecraft | ||
This plugin is meant to read video files and allow you to watch it in minecraft using ffmpeg *(no audio)* | ||
|
||
# Commands | ||
* `/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)* | ||
* `/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)* | ||
|
||
# Known Issues | ||
|
||
* You have to be looking south to spawn a movie theatre correctly | ||
* The max extraction time is 120 seconds which can limit your | ||
|
||
# Next Steps | ||
* Better cache system | ||
* Resource pack server to host a templated pack with audio |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xmlns="http://maven.apache.org/POM/4.0.0" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<groupId>com.birthdates</groupId> | ||
<artifactId>video-to-minecraft</artifactId> | ||
<version>1.0.0</version> | ||
|
||
<properties> | ||
<maven.compiler.source>1.8</maven.compiler.source> | ||
<maven.compiler.target>1.8</maven.compiler.target> | ||
<encoding>UTF-8</encoding> | ||
</properties> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-shade-plugin</artifactId> | ||
<version>3.2.1</version> | ||
<executions> | ||
<execution> | ||
<phase>package</phase> | ||
<goals> | ||
<goal>shade</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
<distributionManagement> | ||
<repository> | ||
<id>github</id> | ||
<name>GitHub Packages</name> | ||
<url>https://maven.pkg.github.com/birthdates/Video-To-Minecraft</url> | ||
</repository> | ||
</distributionManagement> | ||
|
||
<repositories> | ||
<!-- This adds the Spigot Maven repository to the build --> | ||
<repository> | ||
<id>spigot-repo</id> | ||
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url> | ||
</repository> | ||
</repositories> | ||
|
||
<dependencies> | ||
<!--This adds the Spigot API artifact to the build --> | ||
<dependency> | ||
<groupId>org.spigotmc</groupId> | ||
<artifactId>spigot-api</artifactId> | ||
<version>1.16.5-R0.1-SNAPSHOT</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.projectlombok</groupId> | ||
<artifactId>lombok</artifactId> | ||
<version>1.18.20</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
<!-- https://mvnrepository.com/artifact/org.jetbrains/annotations --> | ||
<dependency> | ||
<groupId>org.jetbrains</groupId> | ||
<artifactId>annotations</artifactId> | ||
<version>21.0.0</version> | ||
</dependency> | ||
</dependencies> | ||
|
||
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 | ||
http://maven.apache.org/xsd/settings-1.0.0.xsd"> | ||
|
||
<activeProfiles> | ||
<activeProfile>github</activeProfile> | ||
</activeProfiles> | ||
|
||
<profiles> | ||
<profile> | ||
<id>github</id> | ||
<repositories> | ||
<repository> | ||
<id>central</id> | ||
<url>https://repo1.maven.org/maven2</url> | ||
</repository> | ||
<repository> | ||
<id>github</id> | ||
<url>https://maven.pkg.github.com/birthdates/*/</url> | ||
<releases><enabled>true</enabled></releases> | ||
<snapshots><enabled>true</enabled></snapshots> | ||
</repository> | ||
</repositories> | ||
</profile> | ||
</profiles> | ||
|
||
<servers> | ||
<server> | ||
<id>github</id> | ||
<username>birthdates</username> | ||
<password>${GITHUB_TOKEN}</password> | ||
</server> | ||
</servers> | ||
</settings> |
60 changes: 60 additions & 0 deletions
60
src/main/java/com/birthdates/videotominecraft/VideoToMinecraft.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package com.birthdates.videotominecraft; | ||
|
||
import com.birthdates.videotominecraft.command.watch.StopWatchingCommand; | ||
import com.birthdates.videotominecraft.command.watch.WatchCommand; | ||
import com.birthdates.videotominecraft.command.watch.WatchMovieCommand; | ||
import com.birthdates.videotominecraft.executor.WrappedScheduledThreadPoolExecutor; | ||
import com.birthdates.videotominecraft.worker.Worker; | ||
import lombok.Getter; | ||
import org.bukkit.Bukkit; | ||
import org.bukkit.plugin.java.JavaPlugin; | ||
|
||
import java.io.File; | ||
import java.util.concurrent.ScheduledThreadPoolExecutor; | ||
|
||
@Getter | ||
public class VideoToMinecraft extends JavaPlugin { | ||
|
||
@Getter | ||
private static VideoToMinecraft instance; | ||
private final int FPS = 20; //FPS for canvas | ||
private final int WORKERS_PER_THREAD = 1; | ||
private final ScheduledThreadPoolExecutor executorService = new WrappedScheduledThreadPoolExecutor(WORKERS_PER_THREAD); | ||
|
||
public void onEnable() { | ||
instance = this; | ||
createDataFolderIfNotExists(); | ||
registerCommands(); | ||
} | ||
|
||
public void onDisable() { | ||
for (int i = Worker.getWorkers().size() - 1; i >= 0; i--) { //loop in reverse to prevent CME | ||
Worker worker = Worker.getWorkers().get(i); | ||
worker.finish(); | ||
} | ||
} | ||
|
||
public void resizePool() { | ||
int workerCount = Worker.getWorkers().size(); | ||
int neededThreads = workerCount / WORKERS_PER_THREAD; | ||
|
||
if (neededThreads == 0 || executorService.getCorePoolSize() == neededThreads) return; | ||
executorService.setCorePoolSize(neededThreads); | ||
} | ||
|
||
public void postToMainThread(Runnable task) { | ||
Bukkit.getScheduler().runTask(this, task); | ||
} | ||
|
||
private void registerCommands() { | ||
getCommand("watch").setExecutor(new WatchCommand()); | ||
getCommand("stopwatching").setExecutor(new StopWatchingCommand()); | ||
getCommand("watchmovie").setExecutor(new WatchMovieCommand()); | ||
} | ||
|
||
private void createDataFolderIfNotExists() { | ||
File folder = getDataFolder(); | ||
if(folder.exists() || folder.mkdir()) return; | ||
throw new IllegalStateException("Failed to create data folder."); | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
src/main/java/com/birthdates/videotominecraft/command/PlayerOnlyCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.birthdates.videotominecraft.command; | ||
|
||
import org.bukkit.ChatColor; | ||
import org.bukkit.command.Command; | ||
import org.bukkit.command.CommandExecutor; | ||
import org.bukkit.command.CommandSender; | ||
import org.bukkit.entity.Player; | ||
|
||
/** | ||
* A class to extend to make your command player only. | ||
*/ | ||
public abstract class PlayerOnlyCommand implements CommandExecutor { | ||
|
||
@Override | ||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { | ||
if (!(sender instanceof Player)) { | ||
sender.sendMessage(ChatColor.RED + "You must be a player to execute this command."); | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
} |
51 changes: 51 additions & 0 deletions
51
src/main/java/com/birthdates/videotominecraft/command/watch/StopWatchingCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package com.birthdates.videotominecraft.command.watch; | ||
|
||
import com.birthdates.videotominecraft.command.PlayerOnlyCommand; | ||
import com.birthdates.videotominecraft.maps.Maps; | ||
import com.birthdates.videotominecraft.worker.Worker; | ||
import com.birthdates.videotominecraft.worker.impl.FrameWorker; | ||
import org.bukkit.ChatColor; | ||
import org.bukkit.command.Command; | ||
import org.bukkit.command.CommandSender; | ||
import org.bukkit.entity.Player; | ||
import org.bukkit.inventory.ItemStack; | ||
|
||
import java.util.Objects; | ||
import java.util.Optional; | ||
|
||
/** | ||
* Command used to stop watching a video on a map | ||
*/ | ||
public class StopWatchingCommand extends PlayerOnlyCommand { | ||
|
||
@Override | ||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { | ||
if (!super.onCommand(sender, command, label, args)) return false; //is not a player | ||
|
||
Player player = (Player) sender; | ||
boolean removed = | ||
removeMapAndWorker(player, player.getInventory().getContents()) || | ||
removeMapAndWorker(player, player.getInventory().getExtraContents()); | ||
sender.sendMessage((removed ? ChatColor.GREEN : ChatColor.RED) + "You have " + (removed ? "" : "not") + " removed any video players."); | ||
return true; | ||
} | ||
|
||
private boolean removeMapAndWorker(Player player, ItemStack[] contents) { | ||
boolean found = false; | ||
for (ItemStack content : contents) { | ||
if (content == null || !content.hasItemMeta() || | ||
!content.getItemMeta().hasDisplayName() || !content.getItemMeta().getDisplayName().equals(Maps.getMapName())) | ||
continue; | ||
player.getInventory().remove(content); | ||
|
||
//stop worker | ||
Optional<Worker> workerOptional = FrameWorker.getWorkers() | ||
.stream() | ||
.filter(worker -> Objects.equals(worker.getId(), content)).findAny(); | ||
workerOptional.ifPresent(Worker::finish); | ||
|
||
found = true; | ||
} | ||
return found; | ||
} | ||
} |
Oops, something went wrong.