Initial 1.19 update

This commit is contained in:
NotAlexNoyle committed 2023-12-22 13:57:02 -05:00
1 parent af062ec67a
commit 1dad25b059
14 files changed
+738 -266

No files matched your search

+6
View File
@@ -3,3 +3,9 @@ out/
.idea/
*.iml
*.class
.gradle/
build/
bin/
.classpath
.settings/
.project
+2 -1
View File
@@ -1,2 +1,3 @@
# GxGUI
My GUI lib for Spigot 1.18
Gxorge's GUI library updated for 1.19 by https://true-og.net
+109
View File
@@ -0,0 +1,109 @@
plugins {
id 'java' // Tell gradle this is a java project.
id 'com.github.johnrengelman.shadow' version '8.1.1' // Import utility to package libraries into .jar file.
id 'eclipse' // Import eclipse plugin for IDE integration.
id 'maven-publish' // Import maven publish repo for Jitpack.
}
java {
// Declare java version.
sourceCompatibility = JavaVersion.VERSION_17
}
group = "com.hotten.gxgui" // Declare bundle identifier.
version = "1.1" // Declare plugin version (will be in .jar).
def apiVersion = "1.19" // Declare minecraft server target version.
processResources {
def props = [
version: version,
apiVersion: apiVersion,
]
inputs.properties props // Indicates to rerun if version changes.
filesMatching("plugin.yml") {
expand props
}
}
repositories {
mavenCentral()
maven {
url "https://repo.purpurmc.org/snapshots" // Get purpur API from purpur maven repository.
}
maven {
url "https://jitpack.io"
}
}
dependencies {
compileOnly "org.purpurmc.purpur:purpur-api:1.19.4-R0.1-SNAPSHOT" // Declare purpur API version to be packaged.
implementation 'com.github.cnie109:Utilities-OG:c1c6c4ac33' // Import Utilities-OG API.
// Import project lombok.
compileOnly 'org.projectlombok:lombok:1.18.30'
annotationProcessor 'org.projectlombok:lombok:1.18.30'
testCompileOnly 'org.projectlombok:lombok:1.18.30'
testAnnotationProcessor 'org.projectlombok:lombok:1.18.30'
}
shadowJar {
minimize()
}
jar.dependsOn shadowJar
tasks.jar.configure {
archiveClassifier = "part"
}
tasks.shadowJar.configure {
archiveClassifier = null
}
tasks.withType(JavaCompile).configureEach {
options.compilerArgs += ["-parameters"]
options.encoding = 'UTF-8' // Override the system character set with a universal set.
options.fork = true // Enable compilation in a separate daemon process.
}
publishing {
publications {
maven(MavenPublication) {
groupId = 'com.hotten.gxgui'
artifactId = 'gxgui'
version = '1.1'
from components.java
}
}
}
Binary file not shown.
+7
View File
@@ -0,0 +1,7 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Vendored Executable
+249
View File
@@ -0,0 +1,249 @@
#!/bin/sh
#
# Copyright © 2015-2021 the original authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
##############################################################################
#
# Gradle start up script for POSIX generated by Gradle.
#
# Important for running:
#
# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is
# noncompliant, but you have some other compliant shell such as ksh or
# bash, then to run this script, type that shell name before the whole
# command line, like:
#
# ksh Gradle
#
# Busybox and similar reduced shells will NOT work, because this script
# requires all of these POSIX shell features:
# * functions;
# * expansions «$var», «${var}», «${var:-default}», «${var+SET}»,
# «${var#prefix}», «${var%suffix}», and «$( cmd )»;
# * compound commands having a testable exit status, especially «case»;
# * various built-in commands including «command», «set», and «ulimit».
#
# Important for patching:
#
# (2) This script targets any POSIX shell, so it avoids extensions provided
# by Bash, Ksh, etc; in particular arrays are avoided.
#
# The "traditional" practice of packing multiple parameters into a
# space-separated string is a well documented source of bugs and security
# problems, so this is (mostly) avoided, by progressively accumulating
# options in "$@", and eventually passing that to Java.
#
# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS,
# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly;
# see the in-line comments for details.
#
# There are tweaks for specific operating systems such as AIX, CygWin,
# Darwin, MinGW, and NonStop.
#
# (3) This script is generated from the Groovy template
# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# within the Gradle project.
#
# You can find Gradle at https://github.com/gradle/gradle/.
#
##############################################################################
# Attempt to set APP_HOME
# Resolve links: $0 may be a link
app_path=$0
# Need this for daisy-chained symlinks.
while
APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path
[ -h "$app_path" ]
do
ls=$( ls -ld "$app_path" )
link=${ls#*' -> '}
case $link in #(
/*) app_path=$link ;; #(
*) app_path=$APP_HOME$link ;;
esac
done
# This is normally unused
# shellcheck disable=SC2034
APP_BASE_NAME=${0##*/}
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit
# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum
warn () {
echo "$*"
} >&2
die () {
echo
echo "$*"
echo
exit 1
} >&2
# OS specific support (must be 'true' or 'false').
cygwin=false
msys=false
darwin=false
nonstop=false
case "$( uname )" in #(
CYGWIN* ) cygwin=true ;; #(
Darwin* ) darwin=true ;; #(
MSYS* | MINGW* ) msys=true ;; #(
NONSTOP* ) nonstop=true ;;
esac
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
# Determine the Java command to use to start the JVM.
if [ -n "$JAVA_HOME" ] ; then
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
# IBM's JDK on AIX uses strange locations for the executables
JAVACMD=$JAVA_HOME/jre/sh/java
else
JAVACMD=$JAVA_HOME/bin/java
fi
if [ ! -x "$JAVACMD" ] ; then
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
else
JAVACMD=java
if ! command -v java >/dev/null 2>&1
then
die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
fi
# Increase the maximum file descriptors if we can.
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
case $MAX_FD in #(
max*)
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC2039,SC3045
MAX_FD=$( ulimit -H -n ) ||
warn "Could not query maximum file descriptor limit"
esac
case $MAX_FD in #(
'' | soft) :;; #(
*)
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC2039,SC3045
ulimit -n "$MAX_FD" ||
warn "Could not set maximum file descriptor limit to $MAX_FD"
esac
fi
# Collect all arguments for the java command, stacking in reverse order:
# * args from the command line
# * the main class name
# * -classpath
# * -D...appname settings
# * --module-path (only if needed)
# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables.
# For Cygwin or MSYS, switch paths to Windows format before running java
if "$cygwin" || "$msys" ; then
APP_HOME=$( cygpath --path --mixed "$APP_HOME" )
CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" )
JAVACMD=$( cygpath --unix "$JAVACMD" )
# Now convert the arguments - kludge to limit ourselves to /bin/sh
for arg do
if
case $arg in #(
-*) false ;; # don't mess with options #(
/?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath
[ -e "$t" ] ;; #(
*) false ;;
esac
then
arg=$( cygpath --path --ignore --mixed "$arg" )
fi
# Roll the args list around exactly as many times as the number of
# args, so each arg winds up back in the position where it started, but
# possibly modified.
#
# NB: a `for` loop captures its iteration list before it begins, so
# changing the positional parameters here affects neither the number of
# iterations, nor the values presented in `arg`.
shift # remove old arg
set -- "$@" "$arg" # push replacement arg
done
fi
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
# Collect all arguments for the java command:
# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
# and any embedded shellness will be escaped.
# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
# treated as '${Hostname}' itself on the command line.
set -- \
"-Dorg.gradle.appname=$APP_BASE_NAME" \
-classpath "$CLASSPATH" \
org.gradle.wrapper.GradleWrapperMain \
"$@"
# Stop when "xargs" is not available.
if ! command -v xargs >/dev/null 2>&1
then
die "xargs is not available"
fi
# Use "xargs" to parse quoted args.
#
# With -n1 it outputs one arg per line, with the quotes and backslashes removed.
#
# In Bash we could simply go:
#
# readarray ARGS < <( xargs -n1 <<<"$var" ) &&
# set -- "${ARGS[@]}" "$@"
#
# but POSIX shell has neither arrays nor command substitution, so instead we
# post-process each arg (as a line of input to sed) to backslash-escape any
# character that might be a shell metacharacter, then use eval to reverse
# that process (while maintaining the separation between arguments), and wrap
# the whole thing up as a single "set" statement.
#
# This will of course break if any of these variables contains a newline or
# an unmatched quote.
#
eval "set -- $(
printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" |
xargs -n1 |
sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' |
tr '\n' ' '
)" '"$@"'
exec "$JAVACMD" "$@"
Vendored
+92
View File
@@ -0,0 +1,92 @@
@rem
@rem Copyright 2015 the original author or authors.
@rem
@rem Licensed under the Apache License, Version 2.0 (the "License");
@rem you may not use this file except in compliance with the License.
@rem You may obtain a copy of the License at
@rem
@rem https://www.apache.org/licenses/LICENSE-2.0
@rem
@rem Unless required by applicable law or agreed to in writing, software
@rem distributed under the License is distributed on an "AS IS" BASIS,
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@rem See the License for the specific language governing permissions and
@rem limitations under the License.
@rem
@if "%DEBUG%"=="" @echo off
@rem ##########################################################################
@rem
@rem Gradle startup script for Windows
@rem
@rem ##########################################################################
@rem Set local scope for the variables with windows NT shell
if "%OS%"=="Windows_NT" setlocal
set DIRNAME=%~dp0
if "%DIRNAME%"=="" set DIRNAME=.
@rem This is normally unused
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%
@rem Resolve any "." and ".." in APP_HOME to make it shorter.
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
@rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome
set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if %ERRORLEVEL% equ 0 goto execute
echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail
:findJavaFromJavaHome
set JAVA_HOME=%JAVA_HOME:"=%
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
if exist "%JAVA_EXE%" goto execute
echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail
:execute
@rem Setup the command line
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
@rem Execute Gradle
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
:end
@rem End local scope for the variables with windows NT shell
if %ERRORLEVEL% equ 0 goto mainEnd
:fail
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
rem the _cmd.exe /c_ return code!
set EXIT_CODE=%ERRORLEVEL%
if %EXIT_CODE% equ 0 set EXIT_CODE=1
if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
exit /b %EXIT_CODE%
:mainEnd
if "%OS%"=="Windows_NT" endlocal
:omega
+7
View File
@@ -0,0 +1,7 @@
jdk:
- 17.0.8
before_install:
- sdk install java 17.0.8-graalce
- sdk use java 17.0.8-graalce
install:
- ./gradlew build publishToMavenLocal
-50
View File
@@ -1,50 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>uk.hotten.gxui</groupId>
<artifactId>GxUI</artifactId>
<version>1.2</version>
<repositories>
<repository>
<id>spigot-repo</id>
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.18.2-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.8</version>
</dependency>
</dependencies>
<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>11</source>
<target>11</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
+1
View File
@@ -0,0 +1 @@
rootProject.name = "GxGUI"
+224 -195
View File
@@ -1,6 +1,11 @@
package uk.hotten.gxui;
import lombok.Getter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.StringTokenizer;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.Sound;
@@ -14,254 +19,278 @@ import org.bukkit.event.inventory.ClickType;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryCloseEvent;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryHolder;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitRunnable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.StringTokenizer;
import lombok.Getter;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.TextComponent;
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
public abstract class GUIBase implements Listener {
private JavaPlugin plugin;
private JavaPlugin plugin;
private HashMap<Integer, GUIItem> inventoryContents;
private HashMap<Integer, GUIItem> inventoryContents;
@Getter private String inventoryName;
@Getter private int inventorySize;
@Getter private boolean fillEmpty;
@Getter private String inventoryName;
@Getter private int inventorySize;
@Getter private boolean fillEmpty;
@Getter private Sound openSound;
@Getter private float openSoundFloat;
@Getter private Sound errorSound;
@Getter private float errorSoundFloat;
@Getter private Sound openSound;
@Getter private float openSoundFloat;
@Getter private Sound errorSound;
@Getter private float errorSoundFloat;
@Getter private Player player;
@Getter private Player player;
private Inventory inventory;
private Inventory inventory;
private boolean isOpen = false; //prevents accidental un-registration from other GUIs that have the same name
private boolean isOpen = false; // prevents accidental un-registration from other GUIs that have the same name
private HashMap<Integer, String> itemErrors;
private HashMap<Integer, Integer> itemTimings;
private HashMap<Integer, String> itemErrors;
private HashMap<Integer, Integer> itemTimings;
public GUIBase(JavaPlugin plugin, Player player, String inventoryName, int inventorySize, boolean fillEmpty) {
this.plugin = plugin;
this.player = player;
this.inventoryName = inventoryName;
this.inventorySize = inventorySize;
this.fillEmpty = fillEmpty;
inventoryContents = new HashMap<>();
public GUIBase(JavaPlugin plugin, Player player, String inventoryName, int inventorySize, boolean fillEmpty) {
this.plugin = plugin;
this.player = player;
this.inventoryName = inventoryName;
this.inventorySize = inventorySize;
this.fillEmpty = fillEmpty;
inventoryContents = new HashMap<>();
openSound = null;
openSound = null;
errorSound = Sound.ENTITY_ITEM_BREAK;
errorSoundFloat = (float) 0.6;
errorSound = Sound.ENTITY_ITEM_BREAK;
errorSoundFloat = (float) 0.6;
itemErrors = new HashMap<>();
itemTimings = new HashMap<>();
}
itemErrors = new HashMap<>();
itemTimings = new HashMap<>();
}
public GUIBase(JavaPlugin plugin, Player player, String inventoryName, int inventorySize, boolean fillEmpty, Sound openSound, float openSoundFloat, Sound errorSound, float errorSoundFloat) {
this.plugin = plugin;
this.player = player;
this.inventoryName = inventoryName;
this.inventorySize = inventorySize;
this.fillEmpty = fillEmpty;
inventoryContents = new HashMap<>();
public GUIBase(JavaPlugin plugin, Player player, String inventoryName, int inventorySize, boolean fillEmpty, Sound openSound, float openSoundFloat, Sound errorSound, float errorSoundFloat) {
this.plugin = plugin;
this.player = player;
this.inventoryName = inventoryName;
this.inventorySize = inventorySize;
this.fillEmpty = fillEmpty;
inventoryContents = new HashMap<>();
this.openSound = openSound;
this.openSoundFloat = openSoundFloat;
this.openSound = openSound;
this.openSoundFloat = openSoundFloat;
this.errorSound = errorSound;
this.errorSoundFloat = errorSoundFloat;
this.errorSound = errorSound;
this.errorSoundFloat = errorSoundFloat;
itemErrors = new HashMap<>();
itemTimings = new HashMap<>();
}
itemErrors = new HashMap<>();
itemTimings = new HashMap<>();
}
public void open(boolean refresh) {
if (!isOpen)
Bukkit.getServer().getPluginManager().registerEvents(this, plugin);
if (openSound != null)
player.playSound(player.getLocation(), openSound, 100f, openSoundFloat);
isOpen = true;
inventory = Bukkit.getServer().createInventory(null, inventorySize, inventoryName);
public void open(boolean refresh) {
if (! isOpen)
Bukkit.getServer().getPluginManager().registerEvents(this, plugin);
if (openSound != null)
player.playSound(player.getLocation(), openSound, 100f, openSoundFloat);
isOpen = true;
inventoryContents.clear();
setupItems();
Inventory playersInventory = player.getInventory();
InventoryHolder inventoryContainer = playersInventory.getHolder(false);
TextComponent nameHandler = LegacyComponentSerializer.legacyAmpersand().deserialize(inventoryName);
inventory = Bukkit.createInventory(inventoryContainer, inventorySize, nameHandler);
for (Map.Entry<Integer, GUIItem> i : inventoryContents.entrySet()) {
inventory.setItem(i.getKey(), i.getValue().build());
}
inventoryContents.clear();
setupItems();
if (fillEmpty) {
for (int i = 0; i<inventorySize; i++) {
if (inventory.getItem(i) == null) {
inventory.setItem(i, fillSlot());
}
}
}
for (Map.Entry<Integer, GUIItem> i : inventoryContents.entrySet()) {
inventory.setItem(i.getKey(), i.getValue().build());
}
player.openInventory(inventory);
if (fillEmpty) {
for (int i = 0; i < inventorySize; i++) {
if (inventory.getItem(i) == null) {
inventory.setItem(i, fillSlot());
}
}
}
if (refresh) {
new BukkitRunnable() {
player.openInventory(inventory);
@Override
public void run() {
Inventory inv = ((HumanEntity) player).getOpenInventory().getTopInventory();
if (refresh) {
new BukkitRunnable() {
if (!player.getOpenInventory().getTitle().equalsIgnoreCase(inventoryName)) {
cancel();
return;
}
@Override
public void run() {
Inventory inventory = ((HumanEntity) player).getOpenInventory().getTopInventory();
Component inventoryTitle = player.getOpenInventory().title();
String inventoryTitleText = inventoryTitle.examinableName();
if (! inventoryTitleText.equalsIgnoreCase(inventoryName)) {
cancel();
return;
}
inv.clear();
inventoryContents.clear();
setupItems();
inventory.clear();
inventoryContents.clear();
setupItems();
int counter = 0;
for (Map.Entry<Integer, GUIItem> i : inventoryContents.entrySet()) {
if (itemErrors.containsKey(i.getKey())) {
for (Map.Entry<Integer, GUIItem> i : inventoryContents.entrySet()) {
if (itemErrors.containsKey(i.getKey())) {
GUIItem error = new GUIItem(Material.RED_STAINED_GLASS_PANE, 1, "§c§lERROR");
ArrayList<String> errorLore = addLinebreaks(itemErrors.get(i.getKey()), 30, "§7");
error.lore(errorLore);
GUIItem error = new GUIItem(Material.RED_STAINED_GLASS_PANE, 1, addLinebreaks(itemErrors.get(i.getKey()), 30, "&7").get(counter), "&c&lERROR");
counter++;
int tick = itemTimings.get(i.getKey());
tick++;
itemTimings.remove(i.getKey());
itemTimings.put(i.getKey(), tick);
int tick = itemTimings.get(i.getKey());
tick++;
itemTimings.remove(i.getKey());
itemTimings.put(i.getKey(), tick);
if (tick >= 9) {
itemErrors.remove(i.getKey());
itemTimings.remove(i.getKey());
inventory.setItem(i.getKey(), i.getValue().build());
continue;
}
if (tick >= 9) {
itemErrors.remove(i.getKey());
itemTimings.remove(i.getKey());
inventory.setItem(i.getKey(), i.getValue().build());
continue;
}
inventory.setItem(i.getKey(), error.build());
inventory.setItem(i.getKey(), error.build());
continue;
}
inv.setItem(i.getKey(), i.getValue().build());
}
continue;
if (fillEmpty) {
for (int i = 0; i<inventorySize; i++) {
if (inventory.getItem(i) == null) {
inventory.setItem(i, fillSlot());
}
}
}
}
}.runTaskTimer(plugin, 0, 5);
}
}
}
public abstract void setupItems();
inventory.setItem(i.getKey(), i.getValue().build());
public void addItem(Integer slot, GUIItem item) {
inventoryContents.put(slot, item);
}
}
private ItemStack fillSlot() {
ItemStack i = new ItemStack(Material.GRAY_STAINED_GLASS_PANE, 1);
ItemMeta m = i.getItemMeta();
m.setDisplayName(" ");
i.setItemMeta(m);
return i;
}
if (fillEmpty) {
for (int i = 0; i<inventorySize; i++) {
if (inventory.getItem(i) == null) {
inventory.setItem(i, fillSlot());
}
}
}
}
}.runTaskTimer(plugin, 0, 5);
}
}
@EventHandler
public void handle(InventoryClickEvent event) {
Player clickedPlayer = (Player) event.getWhoClicked();
ClickType clickType = event.getClick();
Inventory inventory = event.getClickedInventory();
ItemStack item = event.getCurrentItem();
String invName = event.getView().getTitle();
public abstract void setupItems();
if (clickedPlayer != player)
return;
public static ArrayList<TextComponent> convertToTextComponents(List<String> stringList) {
ArrayList<TextComponent> textComponents = new ArrayList<>();
if (inventory == null)
return;
for (String str : stringList) {
TextComponent textComponent = LegacyComponentSerializer.legacyAmpersand().deserialize(str);
textComponents.add(textComponent);
}
if (invName.equalsIgnoreCase(inventoryName)) {
if (item == null || !item.hasItemMeta() || item.getItemMeta().getDisplayName().equalsIgnoreCase(" ")) {
if (errorSound != null)
player.playSound(player.getLocation(), errorSound, 100f, errorSoundFloat);
event.setCancelled(true);
return;
}
return textComponents;
}
if (itemErrors.containsKey(event.getSlot())) {
player.playSound(player.getLocation(), Sound.BLOCK_NOTE_BLOCK_BASS, 100f, 0.7f);
event.setCancelled(true);
return;
}
public void addItem(Integer slot, GUIItem item) {
inventoryContents.put(slot, item);
}
if (inventoryContents.containsKey(event.getSlot())) {
GUIItem guiItem = inventoryContents.get(event.getSlot());
event.setCancelled(true);
private ItemStack fillSlot() {
ItemStack i = new ItemStack(Material.GRAY_STAINED_GLASS_PANE, 1);
ItemMeta m = i.getItemMeta();
TextComponent emptySlotDisplayName = LegacyComponentSerializer.legacyAmpersand().deserialize(" ");
m.displayName(emptySlotDisplayName);
i.setItemMeta(m);
return i;
}
if (!guiItem.isButton()) {
if (guiItem.playErrorSound() && errorSound != null)
player.playSound(player.getLocation(), errorSound, 100f, errorSoundFloat);
return;
}
@EventHandler
public void handle(InventoryClickEvent event) {
Player clickedPlayer = (Player) event.getWhoClicked();
ClickType clickType = event.getClick();
Inventory inventory = event.getClickedInventory();
ItemStack item = event.getCurrentItem();
Component inventoryName = event.getView().title();
String inventoryTitleText = inventoryName.examinableName();
boolean exec = guiItem.executeClick(clickType);
if (!exec) {
if (guiItem.playErrorSound() && errorSound != null)
player.playSound(player.getLocation(), errorSound, 100f, errorSoundFloat);
}
}
}
}
if (clickedPlayer != player)
return;
@EventHandler(priority = EventPriority.HIGHEST)
public void close(InventoryCloseEvent event) {
Player closer = (Player) event.getPlayer();
if (inventory == null)
return;
if (event.getView().getTitle().equalsIgnoreCase(inventoryName) && isOpen) {
if (closer == player) {
HandlerList.unregisterAll(this);
isOpen = false;
}
}
}
if (inventoryTitleText.equalsIgnoreCase(inventoryName.examinableName())) {
if (item == null || ! item.hasItemMeta() || item.getItemMeta().displayName().examinableName().equalsIgnoreCase(" ")) {
if (errorSound != null)
player.playSound(player.getLocation(), errorSound, 100f, errorSoundFloat);
event.setCancelled(true);
return;
}
public void showErrorItem(Player player, Integer item, String error, boolean sound) {
itemErrors.put(item, error);
itemTimings.put(item, 0);
if (sound)
player.playSound(player.getLocation(), Sound.BLOCK_NOTE_BLOCK_BASS, 100f, 0.7f);
}
if (itemErrors.containsKey(event.getSlot())) {
player.playSound(player.getLocation(), Sound.BLOCK_NOTE_BLOCK_BASS, 100f, 0.7f);
event.setCancelled(true);
return;
}
public ArrayList<String> addLinebreaks(String input, int maxLineLength, String toAppendAfterNewline) {
ArrayList<String> result = new ArrayList<>();
if (inventoryContents.containsKey(event.getSlot())) {
GUIItem guiItem = inventoryContents.get(event.getSlot());
event.setCancelled(true);
StringTokenizer tok = new StringTokenizer(input, " ");
StringBuilder output = new StringBuilder();
output.insert(0, toAppendAfterNewline);
int lineLen = 0;
while (tok.hasMoreTokens()) {
String word = tok.nextToken();
if (! guiItem.isButton()) {
if (guiItem.isPlayErrorSound() && errorSound != null)
player.playSound(player.getLocation(), errorSound, 100f, errorSoundFloat);
event.setCancelled(true);
return;
}
if (lineLen + word.length() > maxLineLength) {
result.add(output.toString());
output = new StringBuilder();
output.append(toAppendAfterNewline);
lineLen = 0;
}
output.append(word).append(" ");
lineLen += word.length();
}
result.add(output.toString());
boolean exec = guiItem.executeClick(clickType);
if (! exec) {
if (guiItem.isPlayErrorSound() && errorSound != null)
player.playSound(player.getLocation(), errorSound, 100f, errorSoundFloat);
}
}
}
}
return result;
}
@EventHandler(priority = EventPriority.HIGHEST)
public void close(InventoryCloseEvent event) {
Player closer = (Player) event.getPlayer();
Component inventoryTitle = player.getOpenInventory().title();
String inventoryTitleText = inventoryTitle.examinableName();
if (inventoryTitleText.equalsIgnoreCase(inventoryName) && isOpen) {
if (closer == player) {
HandlerList.unregisterAll(this);
isOpen = false;
}
}
}
public void showErrorItem(Player player, Integer item, String error, boolean sound) {
itemErrors.put(item, error);
itemTimings.put(item, 0);
if (sound)
player.playSound(player.getLocation(), Sound.BLOCK_NOTE_BLOCK_BASS, 100f, 0.7f);
}
public ArrayList<String> addLinebreaks(String input, int maxLineLength, String toAppendAfterNewline) {
ArrayList<String> result = new ArrayList<>();
StringTokenizer tok = new StringTokenizer(input, " ");
StringBuilder output = new StringBuilder();
output.insert(0, toAppendAfterNewline);
int lineLen = 0;
while (tok.hasMoreTokens()) {
String word = tok.nextToken();
if (lineLen + word.length() > maxLineLength) {
result.add(output.toString());
output = new StringBuilder();
output.append(toAppendAfterNewline);
lineLen = 0;
}
output.append(word).append(" ");
lineLen += word.length();
}
result.add(output.toString());
return result;
}
}
+4 -4
View File
@@ -2,9 +2,9 @@ package uk.hotten.gxui;
public abstract interface GUIButton {
public abstract boolean leftClick();
public abstract boolean leftClickShift();
public abstract boolean rightClick();
public abstract boolean rightClickShift();
public abstract boolean leftClick();
public abstract boolean leftClickShift();
public abstract boolean rightClick();
public abstract boolean rightClickShift();
}
+30 -16
View File
@@ -1,8 +1,11 @@
package uk.hotten.gxui;
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.event.inventory.ClickType;
@@ -10,9 +13,11 @@ import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.inventory.meta.SkullMeta;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;
import net.kyori.adventure.text.TextComponent;
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
@Accessors(fluent = true)
public class GUIItem {
@@ -76,17 +81,18 @@ public class GUIItem {
*/
public ItemStack build() {
ItemStack i;
TextComponent displayNameTextComponent = LegacyComponentSerializer.legacyAmpersand().deserialize(displayName);
List<TextComponent> loreTextComponent = GUIBase.convertToTextComponents(lore);
try {
if (!isSkull) {
if (! isSkull) {
if (type != -1)
i = new ItemStack(item, amount); //TODO: shorts
i = new ItemStack(item, amount); // TODO: shorts?
else
i = new ItemStack(item, amount);
ItemMeta m = i.getItemMeta();
if (!displayName.equals("Not Set"))
m.setDisplayName(displayName);
m.setLore(lore);
if (! displayName.equals("Not Set"))
m.displayName(displayNameTextComponent);
m.lore(loreTextComponent);
if (!enchantments.isEmpty())
for (Map.Entry<Enchantment, Integer> e : enchantments.entrySet())
m.addEnchant(e.getKey(), e.getValue(), true);
@@ -95,10 +101,10 @@ public class GUIItem {
} else {
i = new ItemStack(item, amount);
SkullMeta m = (SkullMeta) i.getItemMeta();
m.setOwner(skullOwner);
m.setOwningPlayer(Bukkit.getOfflinePlayer(skullOwner));
if (!displayName.equals("Not Set"))
m.setDisplayName(displayName);
m.setLore(lore);
m.displayName(displayNameTextComponent);
m.lore(loreTextComponent);
i.setItemMeta(m);
}
@@ -110,7 +116,15 @@ public class GUIItem {
return i;
}
public boolean isButton() {
public boolean isPlayErrorSound() {
return playErrorSound;
}
public void setPlayErrorSound(boolean playErrorSound) {
this.playErrorSound = playErrorSound;
}
public boolean isButton() {
return !(button == null);
}
+7
View File
@@ -0,0 +1,7 @@
name: GxGUI
author: Gxorge
description: Gxorge's GUI library updated for 1.19 by TrueOG Network
website: https://github.com/Gxorge/GxGUI
version: '${version}'
api-version: '${apiVersion}'
main: uk/hotten/gxui