Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
- name: Build with Gradle
run: ./gradlew clean build
- name: Upload artifact
uses: actions/upload-artifact@v2.3.1
uses: actions/upload-artifact@v4.4.3
with:
name: CommandPrompter
path: build/libs
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
![](https://www.spigotmc.org/attachments/asset-4-png.679568/)
![](https://files.gitbook.com/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FDaCb7lTXGFkT8XKPSg62%2Fuploads%2F7dP2oyXS2s5oc3AoU6KA%2FAsset%204.png?alt=media&token=fb70ddc2-4a5f-4f20-93b9-dff1aa3bf801)
# CommandPrompter
[![](https://ci.cyr1en.com/job/CommandPrompter/badge/icon)](https://ci.cyr1en.com/job/CommandPrompter)
[![](https://img.shields.io/badge/GitBook-documentation-brightgreen?logo=gitbook)](https://cyr1en.gitbook.io/commandprompter/)
Expand Down Expand Up @@ -45,7 +45,7 @@ cd CommandPrompter/
<p>This project owes a huge thanks to GitBook's fantastic <a href="https://docs.gitbook.com/account-management/plans/apply-for-the-non-profit-open-source-plan">Open Source License</a> and their amazing platform for creating beautiful and accessible documentation. Their dedication to open source and ease-of-use has been invaluable to this project's success!</p>

<a href="https://lithiumhosting.com/">
<img width="100" src="https://lithiumhosting.com/billing/templates/lagom/assets/img/logo/logo_small_inverse.svg" />
<img width="230" src="https://lithiumhosting.com/lithiumv8/images/svg/logo_horizontal_light.svg" />
</a>

<p>Lithium Hosting's invaluable support by providing a server to facilitate development. Their dedication to open source and the developer community has been instrumental in making this project possible.</p>
Expand Down
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,11 @@ dependencies {
implementation "dev.jorel:commandapi-bukkit-shade:9.6.1"
implementation 'de.rapha149.signgui:signgui:2.4.2'

compileOnly 'me.clip:placeholderapi:2.11.2'
compileOnly 'me.clip:placeholderapi:2.11.6'
compileOnly "net.kyori:adventure-text-serializer-legacy:4.17.0"
compileOnly "net.kyori:adventure-text-serializer-plain:4.17.0"
compileOnly 'com.palmergames.bukkit.towny:towny:0.100.3.0'
compileOnly "org.spigotmc:spigot-api:1.21-R0.1-SNAPSHOT"
compileOnly "org.spigotmc:spigot-api:1.21.3-R0.1-SNAPSHOT"
compileOnly 'com.github.LeonMangler:SuperVanish:6.2.18-3'
compileOnly 'de.hexaoxi:carbonchat-api:3.0.0-beta.26'
compileOnly 'com.github.mbax:VanishNoPacket:3.22'
Expand Down
37 changes: 34 additions & 3 deletions src/main/java/com/cyr1en/commandprompter/config/PromptConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,14 @@ public record PromptConfig(
"Enable-Title - Show the first line of the prompt",
"(if with {br}) as title of Anvil GUI",
"",
"Item - The item to place on the Anvil GUI",
"Item - The Left item to place on the Anvil GUI",
"",
"Enchanted - Do you want the item enchanted?",
"",
"ResultItem - The Result item to place on the Anvil GUI",
"",
"Hide-Tooltips - Hide tooltips of item (1.21.2 OR ABOVE)",
"",
"Custom-Title - If title is enabled, and if custom",
"title is not empty, CommandPrompter will use this instead",
"",
Expand All @@ -174,20 +178,47 @@ public record PromptConfig(
@NodeDefault("")
String promptMessage,


@ConfigNode
@NodeName("AnvilGUI.Item.Material")
@NodeDefault("Paper")
String anvilItem,

@ConfigNode
@NodeName("AnvilGUI.Item.HideTooltips")
@NodeDefault("false")
boolean itemHideTooltips,

@ConfigNode
@NodeName("AnvilGUI.Item.Custom-Model-Data")
@NodeDefault("0")
int itemCustomModelData,

@ConfigNode
@NodeName("AnvilGUI.Enchanted")
@NodeName("AnvilGUI.Item.Enchanted")
@NodeDefault("false")
boolean itemAnvilEnchanted,


@ConfigNode
@NodeName("AnvilGUI.ResultItem.Material")
@NodeDefault("Paper")
String anvilResultItem,

@ConfigNode
@NodeName("AnvilGUI.ResultItem.HideTooltips")
@NodeDefault("false")
boolean resultItemHideTooltips,

@ConfigNode
@NodeName("AnvilGUI.ResultItem.Custom-Model-Data")
@NodeDefault("0")
int resultItemCustomModelData,

@ConfigNode
@NodeName("AnvilGUI.ResultItem.Enchanted")
@NodeDefault("false")
boolean anvilEnchanted,
boolean resultItemAnvilEnchanted,

// ============================== Text Prompt ==============================
@ConfigNode
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import com.cyr1en.commandprompter.prompt.PromptContext;
import com.cyr1en.commandprompter.prompt.PromptParser;
import com.cyr1en.commandprompter.util.Util;
import com.cyr1en.commandprompter.util.VersionUtil;
import net.wesjd.anvilgui.AnvilGUI;
import org.bukkit.ChatColor;
import org.bukkit.Material;
Expand All @@ -54,10 +55,11 @@ public AnvilPrompt(CommandPrompter plugin, PromptContext context,
public void sendPrompt() {
List<String> parts = Arrays.asList(getPrompt().split("\\{br}"));
var item = makeItem(parts);
makeAnvil(parts, item).open((Player) getContext().getSender());
var resultItem = makeResultItem(parts);
makeAnvil(parts, item, resultItem).open((Player) getContext().getSender());
}

private AnvilGUI.Builder makeAnvil(List<String> parts, ItemStack item) {
private AnvilGUI.Builder makeAnvil(List<String> parts, ItemStack item, ItemStack resultItem) {
var isComplete = new AtomicBoolean(false);
var builder = getBuilder(isComplete);
builder.onClose(p -> {
Expand All @@ -76,6 +78,7 @@ private AnvilGUI.Builder makeAnvil(List<String> parts, ItemStack item) {
builder.title(title);
}
builder.itemLeft(item);
builder.itemOutput(resultItem);
builder.plugin(getPlugin());
return builder;
}
Expand Down Expand Up @@ -110,7 +113,7 @@ private ItemStack makeItem(List<String> parts) {
var item = new ItemStack(Util.getCheckedMaterial(getPlugin().getPromptConfig().anvilItem(), Material.PAPER));
var meta = item.getItemMeta();
getPlugin().getPluginLogger().debug("ItemMeta: " + meta);
if (getPlugin().getPromptConfig().anvilEnchanted()) {
if (getPlugin().getPromptConfig().itemAnvilEnchanted()) {
Objects.requireNonNull(meta).addEnchant(Enchantment.LURE, 1, true);
meta.addItemFlags(ItemFlag.HIDE_ENCHANTS);
}
Expand All @@ -125,6 +128,46 @@ private ItemStack makeItem(List<String> parts) {
if (integerData != 0)
meta.setCustomModelData(integerData);

// set hide tool tips
if (VersionUtil.isAtOrAbove("1.21.2")){
boolean hiddenTooltips = getPlugin().getPromptConfig().itemHideTooltips();
meta.setHideTooltip(hiddenTooltips);
}

item.setItemMeta(meta);
return item;
}

private ItemStack makeResultItem(List<String> parts) {
var item = new ItemStack(Util.getCheckedMaterial(getPlugin().getPromptConfig().anvilResultItem(), Material.PAPER));
var meta = item.getItemMeta();
getPlugin().getPluginLogger().debug("ResultItemMeta: " + meta);

// set enchantment glow
if (getPlugin().getPromptConfig().resultItemAnvilEnchanted()) {
Objects.requireNonNull(meta).addEnchant(Enchantment.LURE, 1, true);
meta.addItemFlags(ItemFlag.HIDE_ENCHANTS);
}

// hide attributes
Objects.requireNonNull(meta).addItemFlags(ItemFlag.HIDE_ATTRIBUTES);

meta.setDisplayName(parts.get(0));

if (parts.size() > 1)
meta.setLore(parts.subList(1, parts.size()).stream().map(this::color).toList());

// set custom model data
var integerData = getPlugin().getPromptConfig().resultItemCustomModelData();
if (integerData != 0)
meta.setCustomModelData(integerData);

// set hide tool tips
if (VersionUtil.isAtOrAbove("1.21.2")){
boolean hiddenTooltips = getPlugin().getPromptConfig().resultItemHideTooltips();
meta.setHideTooltip(hiddenTooltips);
}

item.setItemMeta(meta);
return item;
}
Expand Down
40 changes: 40 additions & 0 deletions src/main/java/com/cyr1en/commandprompter/util/VersionUtil.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.cyr1en.commandprompter.util;

import org.bukkit.Bukkit;

public class VersionUtil {

public static boolean isAtOrAbove(String targetVersion) {
// "CraftBukkit version git-Spigot-093165d-8cd8197 (MC: 1.16.5)"
String versionInfo = Bukkit.getServer().getVersion();
String currentVersion = extractMinecraftVersion(versionInfo);

return compareVersions(currentVersion, targetVersion) >= 0;
}

// get Minecraft Version, " (MC: 1.16.5)" -> "1.16.5"
private static String extractMinecraftVersion(String versionInfo) {
int startIndex = versionInfo.indexOf("(MC: ") + 5;
int endIndex = versionInfo.indexOf(")", startIndex);
return versionInfo.substring(startIndex, endIndex).trim();
}

// Compare two versions, return 1 if currentVersion is greater than targetVersion, 0 if equal, -1 if less than
private static int compareVersions(String currentVersion, String targetVersion) {
String[] currentParts = currentVersion.split("\\.");
String[] targetParts = targetVersion.split("\\.");

int length = Math.max(currentParts.length, targetParts.length);
for (int i = 0; i < length; i++) {
int currentPart = i < currentParts.length ? Integer.parseInt(currentParts[i]) : 0;
int targetPart = i < targetParts.length ? Integer.parseInt(targetParts[i]) : 0;

if (currentPart > targetPart) {
return 1;
} else if (currentPart < targetPart) {
return -1;
}
}
return 0;
}
}