Skip to content

Commit

Permalink
Better ver handling, fix some things
Browse files Browse the repository at this point in the history
  • Loading branch information
Dueris committed Jul 9, 2024
1 parent 473d346 commit a31fde3
Show file tree
Hide file tree
Showing 11 changed files with 96 additions and 38 deletions.
46 changes: 39 additions & 7 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,21 @@ plugins {

val paperweightVersion: String = "1.21-R0.1-SNAPSHOT"

extra["mcMajorVer"] = "21"
extra["mcMinorVer"] = "0"
extra["pluginVer"] = "v1.1.0"

val mcMajorVer = extra["mcMajorVer"] as String
val mcMinorVer = extra["mcMinorVer"] as String
val pluginVer = extra["pluginVer"] as String

val mcVer = "1.$mcMajorVer" + if (mcMinorVer == "0") "" else ".$mcMinorVer"
extra["mcVer"] = mcVer
extra["fullVer"] = "mc$mcVer-$pluginVer"

println("Loading plugin version: $pluginVer")
println("Loading minecraft version: $mcVer")

allprojects {
apply(plugin = "java")
apply(plugin = "maven-publish")
Expand Down Expand Up @@ -42,6 +57,24 @@ allprojects {
maven("https://repo.codemc.org/repository/maven-releases/")
maven("https://jitpack.io")
}

tasks {
processResources {
val props = mapOf(
"mcVer" to mcVer,
"pluginVer" to pluginVer,
"fullVer" to "mc$mcVer-$pluginVer",
"apiVer" to "1.$mcMajorVer"
)
inputs.properties(props)
filesMatching("paper-plugin.yml") {
expand(props)
}

filteringCharset = Charsets.UTF_8.name()
}
}

}

tasks {
Expand All @@ -50,7 +83,7 @@ tasks {
doLast {
val targetJarDirectory: Path = projectDir.toPath().toAbsolutePath().resolve("build/libs")
val subProject: Project = project("origins")
println("Loading OriginsPaper version-build : ".plus(subProject.version))
println("Loading OriginsPaper version-build: $pluginVer")
if (!targetJarDirectory.isDirectory()) error("Target path is not a directory?!")

Files.createDirectories(targetJarDirectory)
Expand All @@ -62,21 +95,20 @@ tasks {
}
}
Files.copy(
file("origins/build/libs/origins-".plus(subProject.version).plus("-all").plus(".jar")).toPath()
.toAbsolutePath(),
targetJarDirectory.resolve("origins-".plus(subProject.version).plus(".jar")),
file("origins/build/libs/origins-${subProject.version}-all.jar").toPath().toAbsolutePath(),
targetJarDirectory.resolve("originspaper-mc$mcVer-$pluginVer.jar"),
StandardCopyOption.REPLACE_EXISTING
)
}
}
runServer {
minecraftVersion("1.21")
minecraftVersion(mcVer)
}
}

tasks.register<Jar>("makePublisher") {
dependsOn(tasks.shadowJar)
archiveFileName.set("originspaper-v1.0.4-SNAPSHOT.jar")
archiveFileName.set("originspaper-$pluginVer-SNAPSHOT.jar")
from(sourceSets.main.get().output)
}

Expand Down Expand Up @@ -105,7 +137,7 @@ publishing {
artifact(tasks.getByName("makePublisher")) {
groupId = "io.github.dueris"
artifactId = "originspaper"
version = "v1.0.4-SNAPSHOT"
version = "$pluginVer-SNAPSHOT"
}
}
repositories {
Expand Down
4 changes: 4 additions & 0 deletions calio/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
version = "v1.0.0"

println("Loaded subproject \"${project.name}\" with version {$version}")

dependencies {
// Required API
compileOnly("io.github.classgraph:classgraph:4.8.165") // - in DependencyLoader
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public static JsonObject remapJsonObject(JsonObject obj, NamespacedKey currentNa
}

for (Pair<String, String> pair : typeMappings) {
if (key.equalsIgnoreCase("type") && g.startsWith(pair.left())) {
if (key.equalsIgnoreCase("type") && g.split(":")[0].equalsIgnoreCase(pair.left())) {
g = pair.right() + ":" + g.split(":")[1];
}
}
Expand Down
18 changes: 4 additions & 14 deletions origins/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ plugins {
}

group = "me.dueris"
version = "1.21-v1.0.4"
version = "${rootProject.extra["mcVer"]}-${rootProject.extra["pluginVer"]}"
description = "Bringing the Origins Mod to PaperMC"

println("Loaded subproject \"${project.name}\" with version {$version}")

dependencies {
// Project
implementation(project(mapOf("path" to ":calio")))
Expand Down Expand Up @@ -39,19 +41,7 @@ tasks {
javadoc {
options.encoding = Charsets.UTF_8.name()
}
processResources {
filteringCharset = Charsets.UTF_8.name()
val props = mapOf(
"name" to project.name,
"version" to project.version,
"description" to project.description,
"apiVersion" to "1.21"
)
inputs.properties(props)
filesMatching("paper-plugin.yml") {
expand(props)
}
}

}

tasks.register<Jar>("makePublisher") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
import me.dueris.originspaper.factory.powers.apoli.CreativeFlight;
import me.dueris.originspaper.factory.powers.apoli.provider.OriginSimpleContainer;
import me.dueris.originspaper.factory.powers.apoli.provider.PowerProvider;
import me.dueris.originspaper.factory.powers.originspaper.GravityPower;
import me.dueris.originspaper.factory.powers.holder.PowerType;
import me.dueris.originspaper.factory.powers.originspaper.GravityPower;
import me.dueris.originspaper.util.entity.PowerHolderComponent;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
Expand Down
37 changes: 30 additions & 7 deletions origins/src/main/java/me/dueris/originspaper/OriginsPaper.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.mojang.brigadier.tree.CommandNode;
import io.papermc.paper.event.player.PlayerFailMoveEvent;
import io.papermc.paper.plugin.configuration.PluginMeta;
import me.dueris.calio.CraftCalio;
import me.dueris.calio.data.AssetIdentifier.AssetType;
import me.dueris.calio.registry.IRegistry;
Expand Down Expand Up @@ -42,6 +43,8 @@
import net.minecraft.world.level.storage.LevelResource;
import org.bukkit.Bukkit;
import org.bukkit.NamespacedKey;
import org.bukkit.configuration.InvalidConfigurationException;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.craftbukkit.CraftServer;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
Expand All @@ -54,6 +57,8 @@

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Arrays;
Expand All @@ -78,17 +83,12 @@ public final class OriginsPaper extends JavaPlugin implements Listener {
public static OriginScheduler.MainTickerThread scheduler = null;
public static String version = Bukkit.getVersion().split("\\(MC: ")[1].replace(")", "");
public static boolean isCompatible = false;
public static String pluginVersion = "v1.0.4";
public static String pluginVersion;
public static String world_container;
public static ExecutorService loaderThreadPool;
public static ArrayList<String> versions = new ArrayList<>();
public static MinecraftServer server;
private static OriginsPaper plugin;

static {
versions.add("1.21");
}

public IRegistry registry;

public static OriginScheduler.MainTickerThread getScheduler() {
Expand Down Expand Up @@ -133,6 +133,29 @@ public static boolean classExists(String className) {
}
}

public void finalizePreboot() {
PluginMeta meta = this.getPluginMeta();
if (meta == null) {
throw new RuntimeException("PluginMeta was null?");
}

pluginVersion = meta.getVersion().split("-")[1];
// parse the plugin, get the meta yml, read the extra data
try (InputStream stream = this.getClass().getClassLoader().getResourceAsStream("paper-plugin.yml")) {
byte[] bytes = stream.readAllBytes();
String contents = new String(bytes, StandardCharsets.UTF_8);

YamlConfiguration yamlConfiguration = new YamlConfiguration();
yamlConfiguration.loadFromString(contents);

versions.add(yamlConfiguration.get("supportedVer").toString());
} catch (IOException | InvalidConfigurationException e) {
throw new RuntimeException(e);
}

metrics = new BstatsMetrics(this, 18536);
}

@Override
public void onEnable() {
if (!Bootstrap.BOOTSTRAPPED.get()) {
Expand All @@ -141,7 +164,7 @@ public void onEnable() {
}
Bootstrap.BOOTSTRAPPED.set(false);
plugin = this;
metrics = new BstatsMetrics(this, 18536);
this.finalizePreboot();
this.registry = CalioRegistry.INSTANCE;
Bukkit.getLogger().info("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
System.out.println(); // Split new line
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
import me.dueris.calio.data.factory.FactoryJsonObject;
import me.dueris.originspaper.OriginsPaper;
import me.dueris.originspaper.factory.conditions.ConditionExecutor;
import me.dueris.originspaper.factory.powers.originspaper.GravityPower;
import me.dueris.originspaper.factory.powers.holder.PowerType;
import me.dueris.originspaper.factory.powers.originspaper.GravityPower;
import me.dueris.originspaper.util.entity.PowerHolderComponent;
import org.bukkit.GameMode;
import org.bukkit.NamespacedKey;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,16 +153,16 @@ public void keybindPress(KeybindTriggerEvent e) {
boolean cont = !getJsonKey().continuous();
ServerPlayer player = ((CraftPlayer) p).getHandle();
new BukkitRunnable() {
int shotsLeft = -count;
int shotsLeft = (-count) + 1;

@Override
public void run() {
if (shotsLeft >= 0) {
if (shotsLeft > 0) {
if ((!cont || !KeybindUtil.activeKeys.get(p).contains(key)) && !in_continuous.get(p).contains(key)) {
Cooldown.addCooldown(p, cooldown, getSelf());
this.cancel();
return;
}
return;
}
addCooldownPatch(p);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
import me.dueris.calio.data.FactoryData;
import me.dueris.calio.data.annotations.RequiresPlugin;
import me.dueris.calio.data.factory.FactoryJsonObject;
import me.dueris.modelcolor.ModelColorAPI;
import me.dueris.modelcolor.colortransformers.OriginsTransformer;
import me.dueris.originspaper.OriginsPaper;
import me.dueris.originspaper.event.PowerUpdateEvent;
import me.dueris.originspaper.factory.powers.holder.PowerType;
import me.dueris.originspaper.util.RaycastUtils;
import me.dueris.modelcolor.ModelColorAPI;
import me.dueris.modelcolor.colortransformers.OriginsTransformer;
import net.skinsrestorer.api.PropertyUtils;
import net.skinsrestorer.api.SkinsRestorer;
import net.skinsrestorer.api.SkinsRestorerProvider;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,13 @@ public void playerJoin(PlayerJoinEvent e) {
Player p = e.getPlayer();
PowerHolderComponent.powersAppliedList.putIfAbsent(p, new ConcurrentLinkedQueue<>());
//set origins to null if none present
for (NamespacedKey key : p.getPersistentDataContainer().getKeys()) {
if (key.asString().equalsIgnoreCase("genesismc:originlayer")) {
p.getPersistentDataContainer().set(OriginsPaper.identifier("originLayer"), PersistentDataType.STRING, p.getPersistentDataContainer().get(key, PersistentDataType.STRING));
p.getPersistentDataContainer().remove(key);
}

}
if (
!p.getPersistentDataContainer().has(OriginsPaper.identifier("originLayer"), PersistentDataType.STRING) ||
p.getPersistentDataContainer().get(OriginsPaper.identifier("originLayer"), PersistentDataType.STRING) == null ||
Expand Down
6 changes: 4 additions & 2 deletions origins/src/main/resources/paper-plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ bootstrapper: "me.dueris.originspaper.Bootstrap"
loader: "me.dueris.originspaper.DependencyLoader"
load: POSTWORLD
name: "OriginsPaper"
version: 'mc1.21-1.0.4'
version: "${fullVer}"
main: "me.dueris.originspaper.OriginsPaper"
api-version: "1.21"
api-version: "${apiVer}"
authors: [ Dueris ]
folia-supported: false
description: "A port of the Origins mod to PaperMC servers with Custom Origins support"
Expand All @@ -23,3 +23,5 @@ dependencies:
SkinsRestorer:
load: BEFORE
required: false

supportedVer: "${mcVer}"

0 comments on commit a31fde3

Please sign in to comment.