Skip to content

Commit

Permalink
Merge pull request #12 from Project-Redemi/ver/2.1.1
Browse files Browse the repository at this point in the history
Version 2.1.1 update
  • Loading branch information
RICE0707 authored Aug 29, 2024
2 parents fdc9413 + 42e7953 commit 47e5747
Show file tree
Hide file tree
Showing 42 changed files with 1,305 additions and 465 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ plugins {
}

group = "engineer.skyouo.plugins.naturerevive"
version = "2.1.0"
version = "2.1.1"

repositories {
mavenCentral()
Expand Down
37 changes: 37 additions & 0 deletions naturerevive-spigot/nms/nms-1_21/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
plugins {
id("java-library")
id("io.papermc.paperweight.userdev") version "1.7.1"
}


group = "engineer.skyouo.plugins.naturerevive.spigot.nms"
version = project.rootProject.version

dependencies {
paperDevBundle("1.21-R0.1-SNAPSHOT")

compileOnly("org.spigotmc:spigot-api:1.21-R0.1-SNAPSHOT")
compileOnly(project(":naturerevive-common"))
}

tasks {
assemble {
dependsOn(reobfJar)
}

compileJava {
options.encoding = Charsets.UTF_8.name() // We want UTF-8 for everything

// Set the release flag. This configures what version bytecode the compiler will emit, as well as what JDK APIs are usable.
// See https://openjdk.java.net/jeps/247 for more information.
options.release.set(21)
}

javadoc {
options.encoding = Charsets.UTF_8.name() // We want UTF-8 for everything
}

processResources {
filteringCharset = Charsets.UTF_8.name() // We want UTF-8 for everything
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
package engineer.skyouo.plugins.naturerevive.spigot.nms;

import com.mojang.brigadier.exceptions.CommandSyntaxException;
import engineer.skyouo.plugins.naturerevive.common.INMSWrapper;
import net.minecraft.core.BlockPos;
import net.minecraft.core.HolderLookup;
import net.minecraft.nbt.TagParser;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.level.ServerLevel;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.BlockState;
import org.bukkit.block.data.BlockData;
import org.bukkit.craftbukkit.CraftWorld;
import org.bukkit.craftbukkit.block.CraftBlockStates;
import org.bukkit.craftbukkit.block.data.CraftBlockData;
import org.bukkit.craftbukkit.entity.CraftPlayer;
import org.bukkit.entity.Player;

import java.util.List;

public class NMSHandler1_21 implements INMSWrapper {
@Override
public List<String> getCompatibleNMSVersion() {
return List.of("1.21", "1.21.1");
}

@Override
public String getNbtAsString(World world, BlockState blockState) {
ServerLevel level = ((CraftWorld) world).getHandle();
return level.getBlockEntity(new BlockPos(blockState.getX(), blockState.getY(), blockState.getZ()))
.saveWithFullMetadata(level.registryAccess()).getAsString();
}

@Override
public void setBlockNMS(World world, int x, int y, int z, BlockData data) {
((CraftWorld) world).getHandle().setBlock(
new BlockPos(x, y, z), ((CraftBlockData) data).getState(), 3
);
}

@Override
public void loadTileEntity(World world, int x, int y, int z, String nbt) {
try {
ServerLevel level = ((CraftWorld) world).getHandle();
level.getBlockEntity(new BlockPos(x, y, z))
.loadCustomOnly(TagParser.parseTag(nbt), level.registryAccess());
} catch (CommandSyntaxException | NullPointerException e) {
throw new RuntimeException(e);
}
}

@Override
public void createTileEntity(World world, int x, int y, int z, BlockData data, String nbt) {
setBlockNMS(world, x, y, z, data);
loadTileEntity(world, x, y, z, nbt);
}

@Override
public double[] getRecentTps() {
return new double[]{
MinecraftServer.getServer().tps1.getAverage(),
MinecraftServer.getServer().tps5.getAverage(),
MinecraftServer.getServer().tps15.getAverage()
};
}

@Override
public double getLuckForPlayer(Player player) {
return ((CraftPlayer) player).getHandle().getLuck();
}

@Override
public BlockState convertBlockDataToBlockState(BlockData blockData) {
return CraftBlockStates.getBlockState(((CraftBlockData) blockData).getState(), null);
}

@Override
public int getWorldMinHeight(World world) {
return ((CraftWorld) world).getHandle().getMinBuildHeight();
}

Material[] oreBlocks = new Material[] {
Material.COAL_ORE, Material.COPPER_ORE, Material.IRON_ORE, Material.GOLD_ORE, Material.DIAMOND_ORE, Material.EMERALD_ORE, Material.LAPIS_ORE, Material.REDSTONE_ORE, Material.DEEPSLATE_COAL_ORE, Material.DEEPSLATE_COPPER_ORE, Material.DEEPSLATE_IRON_ORE, Material.DEEPSLATE_GOLD_ORE, Material.DEEPSLATE_DIAMOND_ORE, Material.DEEPSLATE_EMERALD_ORE, Material.DEEPSLATE_LAPIS_ORE, Material.DEEPSLATE_REDSTONE_ORE, Material.NETHER_GOLD_ORE, Material.NETHER_QUARTZ_ORE, Material.ANCIENT_DEBRIS
};

@Override
public Material[] getOreBlocks() {
return oreBlocks;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;

@Deprecated(forRemoval = true)
/**
* @deprecated - Due to the future cross-platform compatibility,
* this class has been deprecated, see {@link NatureReviveComponentLogger} for better logging system implementation.
* */
@Deprecated(forRemoval = true, since = "2.1.0")
public class NatureReviveBukkitLogger {
public static void ok(String message) {
Bukkit.getConsoleSender()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
package engineer.skyouo.plugins.naturerevive.spigot;

import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.TextColor;
import org.bukkit.Bukkit;

public class NatureReviveComponentLogger {
public static void ok(String message) {
ok(message, TextColor.fromHexString("#FFFFFF"));
}

public static void ok(String message, TextColor color) {
Bukkit.getConsoleSender()
.sendMessage(
HeadComponentBuilder.build("OK", TextColor.fromHexString("#55FF55"))
.append(Component.text(" "))
.append(Component.text(message, color))
);
}

public static void ok(String message, Object... args) {
ok(String.format(message, args));
}

public static void ok(String message, TextColor color, Object... args) {
ok(String.format(message, args), color);
}

public static void info(String message) {
info(message, TextColor.fromHexString("#FFFFFF"));
}

public static void info(String message, TextColor color) {
Bukkit.getConsoleSender()
.sendMessage(
HeadComponentBuilder.build("INFO", TextColor.fromHexString("#55FFFF"))
.append(Component.text(" "))
.append(Component.text(message, color))
);
}

public static void info(String message, Object... args) {
info(String.format(message, args));
}

public static void info(String message, TextColor color, Object... args) {
info(String.format(message, args), color);
}

public static void warning(String message) {
warning(message, TextColor.fromHexString("#FFFFFF"));
}

public static void warning(String message, TextColor color) {
Bukkit.getConsoleSender()
.sendMessage(
HeadComponentBuilder.build("WARNING", TextColor.fromHexString("#FFFF55"))
.append(Component.text(" "))
.append(Component.text(message, color))
);
}

public static void warning(String message, Object... args) {
warning(String.format(message, args));
}

public static void warning(String message, TextColor color, Object... args) {
warning(String.format(message, args), color);
}

public static void error(String message) {
error(message, TextColor.fromHexString("#FFFFFF"));
}

public static void error(String message, TextColor color) {
Bukkit.getConsoleSender()
.sendMessage(
HeadComponentBuilder.build("ERROR", TextColor.fromHexString("#FF5555"))
.append(Component.text(" "))
.append(Component.text(message, color))
);
}

public static void error(String message, Object... args) {
error(String.format(message, args));
}

public static void error(String message, TextColor color, Object... args) {
error(String.format(message, args), color);
}

public static void debug(String message) {
debug(message, TextColor.fromHexString("#FFFFFF"));
}

public static void debug(String message, TextColor color) {
if (!NatureRevivePlugin.readonlyConfig.debug)
return;

Bukkit.getConsoleSender()
.sendMessage(
HeadComponentBuilder.build("DEBUG", TextColor.fromHexString("#AAAAAA"))
.append(Component.text(" "))
.append(Component.text(message, color))
);
}

public static void debug(String message, Object... args) {
debug(String.format(message, args));
}

public static void debug(String message, TextColor color, Object... args) {
debug(String.format(message, args), color);
}

public static void log(Component header, Component body) {
Bukkit.getConsoleSender()
.sendMessage(
header
.append(Component.text(" "))
.append(body)
);
}

public static class HeadComponentBuilder {
public static Component build(String tag, TextColor tagColor) {
return Component.text("[NatureRevive/")
.append(Component.text(tag, tagColor))
.append(Component.text("]"));
}

public static Component build(String feature, String tag, TextColor tagColor) {
return Component.text("[NatureRevive/")
.append(Component.text(feature))
.append(Component.text("/"))
.append(Component.text(tag, tagColor))
.append(Component.text("]"));
}

public static Component build(String feature, TextColor featureColor, String tag, TextColor tagColor) {
return Component.text("[NatureRevive/")
.append(Component.text(feature, featureColor))
.append(Component.text("/"))
.append(Component.text(tag, tagColor))
.append(Component.text("]"));
}
}
}
Loading

0 comments on commit 47e5747

Please sign in to comment.