-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from Project-Redemi/ver/2.1.1
Version 2.1.1 update
- Loading branch information
Showing
42 changed files
with
1,305 additions
and
465 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
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,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 | ||
} | ||
} |
91 changes: 91 additions & 0 deletions
91
...ms-1_21/src/main/java/engineer/skyouo/plugins/naturerevive/spigot/nms/NMSHandler1_21.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,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; | ||
} | ||
} |
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
148 changes: 148 additions & 0 deletions
148
...rc/main/java/engineer/skyouo/plugins/naturerevive/spigot/NatureReviveComponentLogger.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,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("]")); | ||
} | ||
} | ||
} |
Oops, something went wrong.