0.1.2 prepare for redis support and new control system

This commit is contained in:
unurled 2023-08-01 22:54:06 +02:00
parent d224397c87
commit b149003e0a
Signed by: unurled
GPG key ID: FDBC9CBE1F82423F
14 changed files with 231 additions and 19 deletions

1
.gitignore vendored
View file

@ -7,7 +7,6 @@
# IntelliJ # IntelliJ
out/ out/
# mpeltonen/sbt-idea plugin
.idea_modules/ .idea_modules/
# JIRA plugin # JIRA plugin

View file

@ -5,10 +5,11 @@ plugins {
id 'java' id 'java'
id 'io.papermc.paperweight.userdev' version '1.5.5' id 'io.papermc.paperweight.userdev' version '1.5.5'
id 'maven-publish' id 'maven-publish'
id 'com.github.johnrengelman.shadow' version '8.1.1'
} }
group = 'me.unurled.sacredrealms' group = 'me.unurled.sacredrealms'
version = '0.1.1' version = '0.1.2'
def minecraft_version = '1.20.1' def minecraft_version = '1.20.1'
repositories { repositories {
@ -42,6 +43,9 @@ dependencies {
compileOnly ("net.citizensnpcs:citizens-main:2.0.32-SNAPSHOT") { compileOnly ("net.citizensnpcs:citizens-main:2.0.32-SNAPSHOT") {
exclude group: '*', module: '*' exclude group: '*', module: '*'
} }
// Redis
implementation "redis.clients:jedis:4.3.1"
} }
def targetJavaVersion = 17 def targetJavaVersion = 17
@ -54,6 +58,19 @@ java {
} }
} }
shadowJar {
archiveClassifier.set('')
}
tasks {
assemble {
dependsOn(reobfJar)
}
build {
dependsOn(shadowJar)
}
}
tasks.withType(JavaCompile).configureEach { tasks.withType(JavaCompile).configureEach {
if (targetJavaVersion >= 10 || JavaVersion.current().isJava10Compatible()) { if (targetJavaVersion >= 10 || JavaVersion.current().isJava10Compatible()) {
options.release = targetJavaVersion options.release = targetJavaVersion
@ -97,7 +114,7 @@ def serverDir = file("${project.buildDir}/server")
def serverJar = file("${serverDir}/paper-${minecraft_version}.jar") def serverJar = file("${serverDir}/paper-${minecraft_version}.jar")
def pluginsDir = file("${serverDir}/plugins") def pluginsDir = file("${serverDir}/plugins")
def pluginJar = file("${pluginsDir}/${archivesBaseName}.jar") def pluginJar = file("${pluginsDir}/${archivesBaseName}.jar")
def buildJar = file("${project.buildDir}/libs/${archivesBaseName}-${version}-dev.jar") def buildJar = file("${project.buildDir}/libs/${archivesBaseName}-${version}.jar")
def semver = minecraft_version.tokenize('.') def semver = minecraft_version.tokenize('.')
tasks.register('prepare') { tasks.register('prepare') {
@ -133,7 +150,7 @@ tasks.register('start', JavaExec) {
classpath = files(serverJar) classpath = files(serverJar)
workingDir = serverDir workingDir = serverDir
main = 'io.papermc.paperclip.Main' mainClass = 'io.papermc.paperclip.Main'
jvmArgs = [ '-Ddisable.watchdog=true', '-Dcom.mojang.eula.agree=true' ] jvmArgs = [ '-Ddisable.watchdog=true', '-Dcom.mojang.eula.agree=true' ]
args = [ '--nogui' ] args = [ '--nogui' ]
standardInput = System.in standardInput = System.in

View file

@ -1,11 +1,9 @@
package me.unurled.sacredrealms.cutscenes; package me.unurled.sacredrealms.cutscenes;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap; import java.util.HashMap;
import java.util.Objects; import java.util.Objects;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.NamespacedKey; import org.bukkit.NamespacedKey;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -161,6 +159,21 @@ public class Cutscene {
tasks.put(p, task); tasks.put(p, task);
} }
// TODO: implement correctly isPlaying
boolean isPlaying(Player p) {
return false;
}
// TODO: implement correctly clear
void clear(Player p) {
}
// TODO: implement correctly pause
public void pause(Player p) {
}
public void stop(Player p) { public void stop(Player p) {
PersistentDataContainer pdc = p.getPersistentDataContainer(); PersistentDataContainer pdc = p.getPersistentDataContainer();
if (pdc.has(PLAYING)) { if (pdc.has(PLAYING)) {
@ -174,7 +187,6 @@ public class Cutscene {
pdc.remove(PLAYING); pdc.remove(PLAYING);
if (tasks.get(p) != null) if (tasks.get(p) != null)
tasks.get(p).cancel(); tasks.get(p).cancel();
// TODO: replace player to it's original location
Location loc = Cutscenes.getInstance().getOriginalLocation(p); Location loc = Cutscenes.getInstance().getOriginalLocation(p);
if (loc != null) { if (loc != null) {
p.teleport(loc); p.teleport(loc);
@ -198,7 +210,7 @@ public class Cutscene {
} }
public void calculateMarkers() { public void calculateMarkers() {
if (markers.size() == 0) if (markers.isEmpty())
return; return;
for (int i = 0 ; i < markers.size() ; i++) { for (int i = 0 ; i < markers.size() ; i++) {
if (i < markers.size() - 1) { if (i < markers.size() - 1) {

View file

@ -4,7 +4,9 @@ import java.io.File;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.Objects; import me.unurled.sacredrealms.cutscenes.commands.BlockCommand;
import me.unurled.sacredrealms.cutscenes.commands.CutsceneCommand;
import me.unurled.sacredrealms.cutscenes.commands.NPCCommand;
import me.unurled.sacredrealms.cutscenes.parse.CutsceneParser; import me.unurled.sacredrealms.cutscenes.parse.CutsceneParser;
import me.unurled.sacredrealms.cutscenes.parse.MarkerParser; import me.unurled.sacredrealms.cutscenes.parse.MarkerParser;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
@ -28,28 +30,39 @@ public final class Cutscenes extends JavaPlugin {
private static Logger LOGGER = LoggerFactory.getLogger("Cutscenes"); private static Logger LOGGER = LoggerFactory.getLogger("Cutscenes");
@Override @Override
public void onEnable() { public void onEnable() {
// Plugin startup logic // Plugin startup logic
instance = this; instance = this;
CutsceneCommand command = new CutsceneCommand(); saveDefaultConfig();
getCommand("cutscenes").setExecutor(command);
getCommand("cutscenes").setTabCompleter(command); commands();
load(); load();
} }
void commands() {
CutsceneCommand cutsceneCommand = new CutsceneCommand();
getCommand("cutscenes").setExecutor(cutsceneCommand);
getCommand("cutscenes").setTabCompleter(cutsceneCommand);
NPCCommand npcCommand = new NPCCommand();
getCommand("csnpc").setExecutor(npcCommand);
getCommand("csnpc").setTabCompleter(npcCommand);
BlockCommand blockCommand = new BlockCommand();
getCommand("csblock").setExecutor(blockCommand);
getCommand("csblock").setTabCompleter(blockCommand);
}
public void load() { public void load() {
cutscenes = new ArrayList<>(); cutscenes = new ArrayList<>();
currentPlayingCutscenes = new HashMap<>(); currentPlayingCutscenes = new HashMap<>();
originalLocation = new HashMap<>(); originalLocation = new HashMap<>();
cutscenesId = new ArrayList<>(); cutscenesId = new ArrayList<>();
// TODO: detect all cutscenes in the cutscenes folder and load them.
detectAndParseAllCutscenes(); detectAndParseAllCutscenes();
} }
@Override @Override
@ -133,6 +146,18 @@ public final class Cutscenes extends JavaPlugin {
return currentPlayingCutscenes; return currentPlayingCutscenes;
} }
// TODO: make it save the changes
public void createCutscene(String id) {
Cutscene cutscene = new Cutscene(id, id);
addCutscene(cutscene);
}
// TODO: make it save the changes
public void removeCutscene(String id) {
Cutscene cutscene = getCutscene(id);
removeCutscene(cutscene);
}
public void addCutscene(Cutscene cutscene) { public void addCutscene(Cutscene cutscene) {
LOGGER.info("Adding cutscene " + cutscene.getID().toUpperCase() + " to the list of cutscenes!"); LOGGER.info("Adding cutscene " + cutscene.getID().toUpperCase() + " to the list of cutscenes!");
cutscenes.add(cutscene); cutscenes.add(cutscene);
@ -165,6 +190,14 @@ public final class Cutscenes extends JavaPlugin {
} }
} }
public void pauseCutscenes(Player p) {
for (Cutscene cutscene : currentPlayingCutscenes.keySet()) {
if (currentPlayingCutscenes.get(cutscene).equals(p)) {
cutscene.stop(p);
}
}
}
public void stopCutscenesForAllPlayers() { public void stopCutscenesForAllPlayers() {
for (Cutscene cutscene : currentPlayingCutscenes.keySet()) { for (Cutscene cutscene : currentPlayingCutscenes.keySet()) {
cutscene.stop(currentPlayingCutscenes.get(cutscene)); cutscene.stop(currentPlayingCutscenes.get(cutscene));

View file

@ -1,7 +1,6 @@
package me.unurled.sacredrealms.cutscenes; package me.unurled.sacredrealms.cutscenes;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List;
import org.bukkit.Location; import org.bukkit.Location;
public class MarkerInterpolator { public class MarkerInterpolator {

View file

@ -0,0 +1,24 @@
package me.unurled.sacredrealms.cutscenes.commands;
import java.util.List;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabExecutor;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public class BlockCommand implements TabExecutor {
// TODO: make it work :shurg:
@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command,
@NotNull String label, @NotNull String[] args) {
return false;
}
@Override
public @Nullable List<String> onTabComplete(@NotNull CommandSender sender,
@NotNull Command command, @NotNull String label, @NotNull String[] args) {
return null;
}
}

View file

@ -0,0 +1,24 @@
package me.unurled.sacredrealms.cutscenes.commands;
import java.util.List;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabExecutor;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public class CameraCommand implements TabExecutor {
// TODO: make it work :shurg:
@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command,
@NotNull String label, @NotNull String[] args) {
return false;
}
@Override
public @Nullable List<String> onTabComplete(@NotNull CommandSender sender,
@NotNull Command command, @NotNull String label, @NotNull String[] args) {
return null;
}
}

View file

@ -1,7 +1,8 @@
package me.unurled.sacredrealms.cutscenes; package me.unurled.sacredrealms.cutscenes.commands;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import me.unurled.sacredrealms.cutscenes.Cutscenes;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.TextColor; import net.kyori.adventure.text.format.TextColor;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
@ -60,6 +61,14 @@ public class CutsceneCommand implements TabExecutor {
Cutscenes.getInstance().stopCutscene(Bukkit.getPlayer(args[1])); Cutscenes.getInstance().stopCutscene(Bukkit.getPlayer(args[1]));
return true; return true;
} }
} else if (args[0].equalsIgnoreCase("create")) {
Cutscenes.getInstance().createCutscene(args[1].toUpperCase());
sender.sendMessage(Component.text("Created cutscene " + args[1].toUpperCase()).color(TextColor.color(0, 255, 0)));
return true;
} else if (args[0].equalsIgnoreCase("remove")) {
Cutscenes.getInstance().removeCutscene(args[1].toUpperCase());
sender.sendMessage(Component.text("Removed cutscene " + args[1].toUpperCase()).color(TextColor.color(255, 0, 0)));
return true;
} }
} }
} else if (args.length == 3) { } else if (args.length == 3) {
@ -99,6 +108,8 @@ public class CutsceneCommand implements TabExecutor {
complete.add("play"); complete.add("play");
complete.add("list"); complete.add("list");
complete.add("reload"); complete.add("reload");
complete.add("create");
complete.add("remove");
} }
List<String> result = new ArrayList<>(); List<String> result = new ArrayList<>();
if (args.length == 1) { if (args.length == 1) {
@ -116,7 +127,7 @@ public class CutsceneCommand implements TabExecutor {
result.add(p.getName()); result.add(p.getName());
} }
} }
} else if (args[0].equalsIgnoreCase("play")) { } else if (args[0].equalsIgnoreCase("play") || args[0].equalsIgnoreCase("remove")) {
for (String s : Cutscenes.getInstance().getCutscenesId()) { for (String s : Cutscenes.getInstance().getCutscenesId()) {
if (s.toLowerCase().startsWith(args[1].toLowerCase())) { if (s.toLowerCase().startsWith(args[1].toLowerCase())) {
result.add(s); result.add(s);
@ -138,4 +149,16 @@ public class CutsceneCommand implements TabExecutor {
} }
return null; return null;
} }
@Override
public String toString() {
return """
<gold>Cutscene usage:
<gray>/cs play <cutscene_id> <player>
<gray>/cs stop <player>
<gray>/cs list
<gray>/cs reload
<gray>/cs create <cutscene_id>
<gray>/cs remove <cutscene_id>""";
}
} }

View file

@ -0,0 +1,24 @@
package me.unurled.sacredrealms.cutscenes.commands;
import java.util.List;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabExecutor;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public class NPCCommand implements TabExecutor {
// TODO: make it work :shurg:
@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command,
@NotNull String label, @NotNull String[] args) {
return false;
}
@Override
public @Nullable List<String> onTabComplete(@NotNull CommandSender sender,
@NotNull Command command, @NotNull String label, @NotNull String[] args) {
return null;
}
}

View file

@ -0,0 +1,38 @@
package me.unurled.sacredrealms.cutscenes.data;
import me.unurled.sacredrealms.cutscenes.Cutscenes;
import redis.clients.jedis.JedisPooled;
// TODO: implement redis correctly...
/**
* RedisHandler
* Structure of data retention :
* ---
* Location = world, x, y, z, yaw, pitch
* ---
* sr:cs:cutscene_id:property | value
* property = name, marker_id, start, end
* ---
* sr:mk:marker_id:property | value
* property = name, cutscene_id, start, [frame_locs], time_between_frames, overall_time
*/
public class RedisHandler {
JedisPooled jedis;
public RedisHandler() {
this.jedis = new JedisPooled(
Cutscenes.getInstance().getConfig().getString("redis_uri", "localhost"),
Cutscenes.getInstance().getConfig().getInt("redis_port", 6379)
);
}
public void set(String key, String value) {
jedis.set(key, value);
}
public String get(String key) {
return jedis.get(key);
}
}

View file

@ -0,0 +1,14 @@
package me.unurled.sacredrealms.cutscenes.event;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerQuitEvent;
public class Quit implements Listener {
@EventHandler
public void onQuit(PlayerQuitEvent event) {
// TODO: management when player quits (and then joins again)
}
}

View file

@ -1,7 +1,6 @@
package me.unurled.sacredrealms.cutscenes.parse; package me.unurled.sacredrealms.cutscenes.parse;
import me.unurled.sacredrealms.cutscenes.Cutscenes; import me.unurled.sacredrealms.cutscenes.Cutscenes;
import me.unurled.sacredrealms.cutscenes.Frame;
import me.unurled.sacredrealms.cutscenes.Marker; import me.unurled.sacredrealms.cutscenes.Marker;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;

View file

@ -0,0 +1,2 @@
redis_uri: "localhost"
redis_port: 6379

View file

@ -11,6 +11,10 @@ commands:
cutscenes: cutscenes:
aliases: cs aliases: cs
description: cutscenes command description: cutscenes command
csnpc:
description: cutscene npc command
csblock:
description: cutscene block command
permissions: permissions:
cutscenes.admin: cutscenes.admin: