forked from Upstream/CommandPanels
Compare commits
58 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
690ac0e6bf | ||
|
86aecb856a | ||
|
e58adfa9f5 | ||
|
5473206adf | ||
|
aced7b6243 | ||
|
98a02f2408 | ||
|
5f5db64255 | ||
|
9975b2f76a | ||
|
768b2a6de9 | ||
|
8b518e3cb7 | ||
|
372a9c0e86 | ||
|
3034ecd8f3 | ||
|
15766dca58 | ||
|
42e61009db | ||
|
f068a61596 | ||
|
a27360f8ff | ||
|
6f2a39d613 | ||
|
6c390a98f2 | ||
|
9aa6a64f1e | ||
|
a8663e41a7 | ||
|
843ba8b393 | ||
|
2bc6259e41 | ||
|
44e4c5831e | ||
|
724d5039c0 | ||
|
558ab7d7b5 | ||
|
d35517af76 | ||
|
2b354a62f7 | ||
|
64bc5f8f60 | ||
|
d1645d6bbb | ||
|
ad25df283f | ||
|
43d1b221b5 | ||
|
43dbaafc94 | ||
|
47aabb03b2 | ||
|
f3e9e023e6 | ||
|
df03148d84 | ||
|
b8ee48a384 | ||
|
016d67f7c8 | ||
|
66944ab903 | ||
|
fe32486b0b | ||
|
ed1b30c6f6 | ||
|
3e9c40c160 | ||
|
e163347f7d | ||
|
abafd085aa | ||
|
53dafd8f69 | ||
|
1ae3b62463 | ||
|
e5cef06194 | ||
|
24a72b82dd | ||
|
68591c7a11 | ||
|
6c558177ec | ||
|
10dc42ac3c | ||
|
6138ef1e2d | ||
|
1830c900db | ||
|
6551246c7a | ||
|
deab494c45 | ||
|
41383140b5 | ||
|
7dadce2fd7 | ||
|
388c7d7a4b | ||
|
c48779291d |
30
.gitea/workflows/build.yml
Normal file
30
.gitea/workflows/build.yml
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
name: Build CommandPanels plugin
|
||||||
|
run-name: Build CommandPanels plugin
|
||||||
|
on: [push]
|
||||||
|
jobs:
|
||||||
|
Build-latest-jar:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Build | Prepare packages
|
||||||
|
run: |
|
||||||
|
apt update; apt-get install software-properties-common -y
|
||||||
|
wget -O- https://apt.corretto.aws/corretto.key | apt-key add -
|
||||||
|
add-apt-repository 'deb https://apt.corretto.aws stable main'
|
||||||
|
apt-get update; apt-get install -y maven java-21-amazon-corretto-jdk
|
||||||
|
- name: Setup git
|
||||||
|
run: |
|
||||||
|
git config --global user.name "Radim Lipovčan"
|
||||||
|
git config --global user.email "radim@lipovcan.cz"
|
||||||
|
- name: Check out repository code
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
- name: Build | Maven clean build
|
||||||
|
run: |
|
||||||
|
mvn clean install && ls -lah && ls */ -lah && ls */* -lah&& ls */*/* -lah
|
||||||
|
- name: Push | Create release
|
||||||
|
uses: https://git.lipovcan.cz/Upstream/gitea-release-action.git@v1
|
||||||
|
with:
|
||||||
|
files: |-
|
||||||
|
target/CommandPanels-DEV.jar
|
||||||
|
- name: Push | Old FTP way to gitea.lipovcan.cz:8081
|
||||||
|
run: |
|
||||||
|
curl --insecure --user username:mypass -T ./target/CommandPanels-DEV.jar ftp://192.168.10.133:/
|
14
.github/ISSUE_TEMPLATE/bug_report.yml
vendored
14
.github/ISSUE_TEMPLATE/bug_report.yml
vendored
@ -33,6 +33,7 @@ body:
|
|||||||
- 1.17
|
- 1.17
|
||||||
- 1.18
|
- 1.18
|
||||||
- 1.19
|
- 1.19
|
||||||
|
- 1.20
|
||||||
validations:
|
validations:
|
||||||
required: true
|
required: true
|
||||||
- type: dropdown
|
- type: dropdown
|
||||||
@ -41,6 +42,9 @@ body:
|
|||||||
label: What CommandPanels version are you using?
|
label: What CommandPanels version are you using?
|
||||||
options:
|
options:
|
||||||
- latest
|
- latest
|
||||||
|
- 3.20.0.3
|
||||||
|
- 3.20.0.2
|
||||||
|
- 3.20.0.1
|
||||||
- 3.19.0.3
|
- 3.19.0.3
|
||||||
- 3.19.0.2
|
- 3.19.0.2
|
||||||
- 3.19.0.1
|
- 3.19.0.1
|
||||||
@ -66,16 +70,6 @@ body:
|
|||||||
- 3.17.4.1
|
- 3.17.4.1
|
||||||
- 3.17.4.0
|
- 3.17.4.0
|
||||||
- 3.17.3.1
|
- 3.17.3.1
|
||||||
- 3.17.3.0
|
|
||||||
- 3.17.2.2
|
|
||||||
- 3.17.2.1
|
|
||||||
- 3.17.2.0
|
|
||||||
- 3.17.1.5
|
|
||||||
- 3.17.1.4
|
|
||||||
- 3.17.1.3
|
|
||||||
- 3.17.1.2
|
|
||||||
- 3.17.1.1
|
|
||||||
- 3.17.1.0
|
|
||||||
- Any other version
|
- Any other version
|
||||||
validations:
|
validations:
|
||||||
required: true
|
required: true
|
||||||
|
14
.github/ISSUE_TEMPLATE/need-help.yml
vendored
14
.github/ISSUE_TEMPLATE/need-help.yml
vendored
@ -31,6 +31,7 @@ body:
|
|||||||
- 1.17
|
- 1.17
|
||||||
- 1.18
|
- 1.18
|
||||||
- 1.19
|
- 1.19
|
||||||
|
- 1.20
|
||||||
validations:
|
validations:
|
||||||
required: true
|
required: true
|
||||||
- type: dropdown
|
- type: dropdown
|
||||||
@ -39,6 +40,9 @@ body:
|
|||||||
label: What CommandPanels version are you using?
|
label: What CommandPanels version are you using?
|
||||||
options:
|
options:
|
||||||
- latest
|
- latest
|
||||||
|
- 3.20.0.3
|
||||||
|
- 3.20.0.2
|
||||||
|
- 3.20.0.1
|
||||||
- 3.19.0.3
|
- 3.19.0.3
|
||||||
- 3.19.0.2
|
- 3.19.0.2
|
||||||
- 3.19.0.1
|
- 3.19.0.1
|
||||||
@ -64,16 +68,6 @@ body:
|
|||||||
- 3.17.4.1
|
- 3.17.4.1
|
||||||
- 3.17.4.0
|
- 3.17.4.0
|
||||||
- 3.17.3.1
|
- 3.17.3.1
|
||||||
- 3.17.3.0
|
|
||||||
- 3.17.2.2
|
|
||||||
- 3.17.2.1
|
|
||||||
- 3.17.2.0
|
|
||||||
- 3.17.1.5
|
|
||||||
- 3.17.1.4
|
|
||||||
- 3.17.1.3
|
|
||||||
- 3.17.1.2
|
|
||||||
- 3.17.1.1
|
|
||||||
- 3.17.1.0
|
|
||||||
- Any other version
|
- Any other version
|
||||||
validations:
|
validations:
|
||||||
required: true
|
required: true
|
||||||
|
3
.gitignore
vendored
3
.gitignore
vendored
@ -1,4 +1,5 @@
|
|||||||
# Project exclude paths
|
# Project exclude paths
|
||||||
/out/
|
/out/
|
||||||
/target/
|
/target/
|
||||||
.idea/
|
.idea/
|
||||||
|
.github
|
@ -6,11 +6,6 @@
|
|||||||
<option name="name" value="Central Repository" />
|
<option name="name" value="Central Repository" />
|
||||||
<option name="url" value="https://repo.maven.apache.org/maven2" />
|
<option name="url" value="https://repo.maven.apache.org/maven2" />
|
||||||
</remote-repository>
|
</remote-repository>
|
||||||
<remote-repository>
|
|
||||||
<option name="id" value="io.papermc" />
|
|
||||||
<option name="name" value="io.papermc" />
|
|
||||||
<option name="url" value="https://papermc.io/repo/repository/maven-releases/" />
|
|
||||||
</remote-repository>
|
|
||||||
<remote-repository>
|
<remote-repository>
|
||||||
<option name="id" value="jitpack.io" />
|
<option name="id" value="jitpack.io" />
|
||||||
<option name="name" value="jitpack.io" />
|
<option name="name" value="jitpack.io" />
|
||||||
@ -21,16 +16,31 @@
|
|||||||
<option name="name" value="jeff-media-public" />
|
<option name="name" value="jeff-media-public" />
|
||||||
<option name="url" value="https://hub.jeff-media.com/nexus/repository/jeff-media-public/" />
|
<option name="url" value="https://hub.jeff-media.com/nexus/repository/jeff-media-public/" />
|
||||||
</remote-repository>
|
</remote-repository>
|
||||||
|
<remote-repository>
|
||||||
|
<option name="id" value="io.papermc" />
|
||||||
|
<option name="name" value="io.papermc" />
|
||||||
|
<option name="url" value="https://papermc.io/repo/repository/maven-releases/" />
|
||||||
|
</remote-repository>
|
||||||
<remote-repository>
|
<remote-repository>
|
||||||
<option name="id" value="sonatype" />
|
<option name="id" value="sonatype" />
|
||||||
<option name="name" value="sonatype" />
|
<option name="name" value="sonatype" />
|
||||||
<option name="url" value="https://oss.sonatype.org/content/groups/public/" />
|
<option name="url" value="https://oss.sonatype.org/content/groups/public/" />
|
||||||
</remote-repository>
|
</remote-repository>
|
||||||
|
<remote-repository>
|
||||||
|
<option name="id" value="io.papermc" />
|
||||||
|
<option name="name" value="io.papermc" />
|
||||||
|
<option name="url" value="https://repo.papermc.io/repository/maven-public/" />
|
||||||
|
</remote-repository>
|
||||||
<remote-repository>
|
<remote-repository>
|
||||||
<option name="id" value="codemc-repo" />
|
<option name="id" value="codemc-repo" />
|
||||||
<option name="name" value="codemc-repo" />
|
<option name="name" value="codemc-repo" />
|
||||||
<option name="url" value="https://repo.codemc.io/repository/maven-public/" />
|
<option name="url" value="https://repo.codemc.io/repository/maven-public/" />
|
||||||
</remote-repository>
|
</remote-repository>
|
||||||
|
<remote-repository>
|
||||||
|
<option name="id" value="opencollab-snapshot" />
|
||||||
|
<option name="name" value="opencollab-snapshot" />
|
||||||
|
<option name="url" value="https://repo.opencollab.dev/main/" />
|
||||||
|
</remote-repository>
|
||||||
<remote-repository>
|
<remote-repository>
|
||||||
<option name="id" value="placeholderapi" />
|
<option name="id" value="placeholderapi" />
|
||||||
<option name="name" value="placeholderapi" />
|
<option name="name" value="placeholderapi" />
|
||||||
@ -42,15 +52,40 @@
|
|||||||
<option name="url" value="https://repo1.maven.org/maven2" />
|
<option name="url" value="https://repo1.maven.org/maven2" />
|
||||||
</remote-repository>
|
</remote-repository>
|
||||||
<remote-repository>
|
<remote-repository>
|
||||||
<option name="id" value="BenCodez Repo" />
|
<option name="id" value="oraxen" />
|
||||||
<option name="name" value="BenCodez Repo" />
|
<option name="name" value="Oraxen Repository" />
|
||||||
<option name="url" value="https://nexus.bencodez.com/repository/maven-public/" />
|
<option name="url" value="https://repo.oraxen.com/#/releases" />
|
||||||
</remote-repository>
|
</remote-repository>
|
||||||
<remote-repository>
|
<remote-repository>
|
||||||
<option name="id" value="phoenix" />
|
<option name="id" value="phoenix" />
|
||||||
<option name="name" value="phoenix" />
|
<option name="name" value="phoenix" />
|
||||||
<option name="url" value="https://nexus.phoenixdevt.fr/repository/maven-public/" />
|
<option name="url" value="https://nexus.phoenixdevt.fr/repository/maven-public/" />
|
||||||
</remote-repository>
|
</remote-repository>
|
||||||
|
<remote-repository>
|
||||||
|
<option name="id" value="BenCodez Repo" />
|
||||||
|
<option name="name" value="BenCodez Repo" />
|
||||||
|
<option name="url" value="https://nexus.bencodez.com/repository/maven-public/" />
|
||||||
|
</remote-repository>
|
||||||
|
<remote-repository>
|
||||||
|
<option name="id" value="central" />
|
||||||
|
<option name="name" value="central" />
|
||||||
|
<option name="url" value="https://repo1.maven.org/maven2" />
|
||||||
|
</remote-repository>
|
||||||
|
<remote-repository>
|
||||||
|
<option name="id" value="oraxen" />
|
||||||
|
<option name="name" value="Oraxen Repository" />
|
||||||
|
<option name="url" value="https://repo.oraxen.com/releases" />
|
||||||
|
</remote-repository>
|
||||||
|
<remote-repository>
|
||||||
|
<option name="id" value="github" />
|
||||||
|
<option name="name" value="github" />
|
||||||
|
<option name="url" value="https://maven.pkg.github.com/xap3y/skullcreator" />
|
||||||
|
</remote-repository>
|
||||||
|
<remote-repository>
|
||||||
|
<option name="id" value="jitpack-repo" />
|
||||||
|
<option name="name" value="jitpack-repo" />
|
||||||
|
<option name="url" value="https://jitpack.io" />
|
||||||
|
</remote-repository>
|
||||||
<remote-repository>
|
<remote-repository>
|
||||||
<option name="id" value="ess-repo" />
|
<option name="id" value="ess-repo" />
|
||||||
<option name="name" value="ess-repo" />
|
<option name="name" value="ess-repo" />
|
||||||
@ -61,6 +96,11 @@
|
|||||||
<option name="name" value="spigot-repo" />
|
<option name="name" value="spigot-repo" />
|
||||||
<option name="url" value="https://hub.spigotmc.org/nexus/content/repositories/snapshots/" />
|
<option name="url" value="https://hub.spigotmc.org/nexus/content/repositories/snapshots/" />
|
||||||
</remote-repository>
|
</remote-repository>
|
||||||
|
<remote-repository>
|
||||||
|
<option name="id" value="jeff-media-public" />
|
||||||
|
<option name="name" value="jeff-media-public" />
|
||||||
|
<option name="url" value="https://repo.jeff-media.com/public/" />
|
||||||
|
</remote-repository>
|
||||||
<remote-repository>
|
<remote-repository>
|
||||||
<option name="id" value="jboss.community" />
|
<option name="id" value="jboss.community" />
|
||||||
<option name="name" value="JBoss Community repository" />
|
<option name="name" value="JBoss Community repository" />
|
||||||
|
@ -8,4 +8,5 @@
|
|||||||
</option>
|
</option>
|
||||||
<option name="workspaceImportForciblyTurnedOn" value="true" />
|
<option name="workspaceImportForciblyTurnedOn" value="true" />
|
||||||
</component>
|
</component>
|
||||||
|
<component name="ProjectRootManager" version="2" languageLevel="JDK_21" project-jdk-name="17" project-jdk-type="JavaSDK" />
|
||||||
</project>
|
</project>
|
2
jitpack.yml
Normal file
2
jitpack.yml
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
jdk:
|
||||||
|
- openjdk17
|
66
pom.xml
66
pom.xml
@ -4,7 +4,7 @@
|
|||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
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>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
<groupId>groupId</groupId>
|
<groupId>me.rockyhawk.commandpanels</groupId>
|
||||||
<artifactId>CommandPanels</artifactId>
|
<artifactId>CommandPanels</artifactId>
|
||||||
<version>DEV</version>
|
<version>DEV</version>
|
||||||
|
|
||||||
@ -71,14 +71,14 @@
|
|||||||
</build>
|
</build>
|
||||||
|
|
||||||
<repositories>
|
<repositories>
|
||||||
<repository>
|
|
||||||
<id>io.papermc</id>
|
|
||||||
<url>https://papermc.io/repo/repository/maven-releases/</url>
|
|
||||||
</repository>
|
|
||||||
<repository>
|
<repository>
|
||||||
<id>jitpack.io</id>
|
<id>jitpack.io</id>
|
||||||
<url>https://jitpack.io</url>
|
<url>https://jitpack.io</url>
|
||||||
</repository>
|
</repository>
|
||||||
|
<repository>
|
||||||
|
<id>io.papermc</id>
|
||||||
|
<url>https://repo.papermc.io/repository/maven-public/</url>
|
||||||
|
</repository>
|
||||||
<repository>
|
<repository>
|
||||||
<id>minecraft-repo</id>
|
<id>minecraft-repo</id>
|
||||||
<url>https://libraries.minecraft.net/</url>
|
<url>https://libraries.minecraft.net/</url>
|
||||||
@ -89,11 +89,7 @@
|
|||||||
</repository>
|
</repository>
|
||||||
<repository>
|
<repository>
|
||||||
<id>jeff-media-public</id>
|
<id>jeff-media-public</id>
|
||||||
<url>https://hub.jeff-media.com/nexus/repository/jeff-media-public/</url>
|
<url>https://repo.jeff-media.com/public/</url>
|
||||||
</repository>
|
|
||||||
<repository>
|
|
||||||
<id>BenCodez Repo</id>
|
|
||||||
<url>https://nexus.bencodez.com/repository/maven-public/</url>
|
|
||||||
</repository>
|
</repository>
|
||||||
<repository>
|
<repository>
|
||||||
<id>ess-repo</id>
|
<id>ess-repo</id>
|
||||||
@ -116,13 +112,17 @@
|
|||||||
<url>https://repo.codemc.io/repository/maven-public/</url>
|
<url>https://repo.codemc.io/repository/maven-public/</url>
|
||||||
<layout>default</layout>
|
<layout>default</layout>
|
||||||
</repository>
|
</repository>
|
||||||
|
<repository>
|
||||||
|
<id>opencollab-snapshot</id>
|
||||||
|
<url>https://repo.opencollab.dev/main/</url>
|
||||||
|
</repository>
|
||||||
</repositories>
|
</repositories>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>de.tr7zw</groupId>
|
<groupId>de.tr7zw</groupId>
|
||||||
<artifactId>item-nbt-api</artifactId>
|
<artifactId>item-nbt-api</artifactId>
|
||||||
<version>2.12.2</version>
|
<version>2.14.1-SNAPSHOT</version>
|
||||||
<scope>compile</scope>
|
<scope>compile</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
@ -134,7 +134,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>net.kyori</groupId>
|
<groupId>net.kyori</groupId>
|
||||||
<artifactId>adventure-text-minimessage</artifactId>
|
<artifactId>adventure-text-minimessage</artifactId>
|
||||||
<version>4.13.0</version>
|
<version>4.17.0</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
@ -146,7 +146,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.spigotmc</groupId>
|
<groupId>org.spigotmc</groupId>
|
||||||
<artifactId>spigot-api</artifactId>
|
<artifactId>spigot-api</artifactId>
|
||||||
<version>1.20-R0.1-SNAPSHOT</version>
|
<version>1.20.5-R0.1-SNAPSHOT</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
@ -158,18 +158,12 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>commons-io</groupId>
|
<groupId>commons-io</groupId>
|
||||||
<artifactId>commons-io</artifactId>
|
<artifactId>commons-io</artifactId>
|
||||||
<version>2.13.0</version>
|
<version>2.14.0</version>
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.bencodez</groupId>
|
|
||||||
<artifactId>votingplugin</artifactId>
|
|
||||||
<version>LATEST</version>
|
|
||||||
<scope>provided</scope>
|
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>me.clip</groupId>
|
<groupId>me.clip</groupId>
|
||||||
<artifactId>placeholderapi</artifactId>
|
<artifactId>placeholderapi</artifactId>
|
||||||
<version>2.11.3</version>
|
<version>2.11.6</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
@ -181,25 +175,13 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>net.Indyuce</groupId>
|
<groupId>net.Indyuce</groupId>
|
||||||
<artifactId>MMOItems-API</artifactId>
|
<artifactId>MMOItems-API</artifactId>
|
||||||
<version>LATEST</version>
|
<version>6.10-SNAPSHOT</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>io.lumine</groupId>
|
<groupId>io.lumine</groupId>
|
||||||
<artifactId>MythicLib-dist</artifactId>
|
<artifactId>MythicLib-dist</artifactId>
|
||||||
<version>1.5.2-SNAPSHOT</version>
|
<version>1.6.2-SNAPSHOT</version>
|
||||||
<scope>provided</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.github.Realizedd</groupId>
|
|
||||||
<artifactId>TokenManager</artifactId>
|
|
||||||
<version>LATEST</version>
|
|
||||||
<exclusions>
|
|
||||||
<exclusion>
|
|
||||||
<groupId>*</groupId>
|
|
||||||
<artifactId>*</artifactId>
|
|
||||||
</exclusion>
|
|
||||||
</exclusions>
|
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
@ -209,15 +191,15 @@
|
|||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.github.Ssomar-Developement</groupId>
|
<groupId>com.github.LoneDev6</groupId>
|
||||||
<artifactId>SCore</artifactId>
|
<artifactId>api-itemsadder</artifactId>
|
||||||
<version>LATEST</version>
|
<version>3.6.1</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>io.papermc</groupId>
|
<groupId>io.papermc</groupId>
|
||||||
<artifactId>paperlib</artifactId>
|
<artifactId>paperlib</artifactId>
|
||||||
<version>1.0.7</version>
|
<version>1.0.8</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>net.essentialsx</groupId>
|
<groupId>net.essentialsx</groupId>
|
||||||
@ -225,5 +207,11 @@
|
|||||||
<version>2.20.1</version>
|
<version>2.20.1</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.geysermc.floodgate</groupId>
|
||||||
|
<artifactId>api</artifactId>
|
||||||
|
<version>2.2.2-SNAPSHOT</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</project>
|
</project>
|
@ -16,7 +16,6 @@ config:
|
|||||||
stop-sound: true
|
stop-sound: true
|
||||||
disabled-world-message: true
|
disabled-world-message: true
|
||||||
panel-snooper: false
|
panel-snooper: false
|
||||||
allow-unsafe-mini-message: false
|
|
||||||
enable-import-command: false
|
enable-import-command: false
|
||||||
format:
|
format:
|
||||||
tag: '&6[&bCommandPanels&6] '
|
tag: '&6[&bCommandPanels&6] '
|
||||||
@ -38,7 +37,7 @@ input:
|
|||||||
- '&aEnter Input for Command'
|
- '&aEnter Input for Command'
|
||||||
- '&cType &4%cp-args% &cto Cancel the command'
|
- '&cType &4%cp-args% &cto Cancel the command'
|
||||||
hexcodes:
|
hexcodes:
|
||||||
start_tag: '#'
|
start_tag: '&#'
|
||||||
end_tag: ''
|
end_tag: ''
|
||||||
placeholders:
|
placeholders:
|
||||||
primary:
|
primary:
|
||||||
@ -49,7 +48,6 @@ placeholders:
|
|||||||
end: '}'
|
end: '}'
|
||||||
updater:
|
updater:
|
||||||
auto-update: false
|
auto-update: false
|
||||||
minor-updates-only: true
|
|
||||||
update-checks: true
|
update-checks: true
|
||||||
purchase:
|
purchase:
|
||||||
currency:
|
currency:
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
version: 3.20.0.0
|
version: 3.21.4.4
|
||||||
main: me.rockyhawk.commandpanels.CommandPanels
|
main: me.rockyhawk.commandpanels.CommandPanels
|
||||||
name: CommandPanels
|
name: CommandPanels
|
||||||
author: RockyHawk
|
author: RockyHawk
|
||||||
api-version: '1.13'
|
api-version: '1.13'
|
||||||
description: Fully Custom GUIs. Make your Server Professional.
|
description: Fully Custom GUIs. Make your Server Professional.
|
||||||
softdepend: [Essentials, PlaceholderAPI, Vault, HeadDatabase, TokenManager, VotingPlugin, MMOItems, ChestSort]
|
softdepend: [Essentials, PlaceholderAPI, Vault, HeadDatabase, TokenManager, VotingPlugin, MMOItems, ChestSort, floodgate]
|
||||||
commands:
|
commands:
|
||||||
commandpanel:
|
commandpanel:
|
||||||
description: Open a command panel.
|
description: Open a command panel.
|
||||||
|
@ -73,12 +73,11 @@ panels:
|
|||||||
- placeholder= [item:APPLE]
|
- placeholder= [item:APPLE]
|
||||||
- refresh
|
- refresh
|
||||||
'21':
|
'21':
|
||||||
material: POTION
|
material: GOLDEN_APPLE
|
||||||
name: '&fClick to heal the player'
|
name: '&fClick to heal the player'
|
||||||
potion: INSTANT_HEAL
|
|
||||||
lore:
|
lore:
|
||||||
- '&7Uses the /heal command so that'
|
- '&7Uses the /heal command if'
|
||||||
- '&7the player needs permission'
|
- '&7the player has permission'
|
||||||
commands:
|
commands:
|
||||||
- heal
|
- heal
|
||||||
'24':
|
'24':
|
||||||
|
@ -1,11 +1,12 @@
|
|||||||
package me.rockyhawk.commandpanels;
|
package me.rockyhawk.commandpanels;
|
||||||
|
|
||||||
import com.bencodez.votingplugin.VotingPluginHooks;
|
import com.google.common.collect.ImmutableMultimap;
|
||||||
import io.lumine.mythic.lib.api.item.NBTItem;
|
import io.lumine.mythic.lib.api.item.NBTItem;
|
||||||
import me.rockyhawk.commandpanels.api.CommandPanelsAPI;
|
import me.rockyhawk.commandpanels.api.CommandPanelsAPI;
|
||||||
import me.rockyhawk.commandpanels.api.Panel;
|
import me.rockyhawk.commandpanels.api.Panel;
|
||||||
import me.rockyhawk.commandpanels.classresources.ExecuteOpenVoids;
|
import me.rockyhawk.commandpanels.classresources.ExecuteOpenVoids;
|
||||||
import me.rockyhawk.commandpanels.classresources.GetCustomHeads;
|
import me.rockyhawk.commandpanels.classresources.MiniMessageUtils;
|
||||||
|
import me.rockyhawk.commandpanels.classresources.customheads.GetCustomHeads;
|
||||||
import me.rockyhawk.commandpanels.classresources.HasSections;
|
import me.rockyhawk.commandpanels.classresources.HasSections;
|
||||||
import me.rockyhawk.commandpanels.classresources.ItemCreation;
|
import me.rockyhawk.commandpanels.classresources.ItemCreation;
|
||||||
import me.rockyhawk.commandpanels.classresources.placeholders.expansion.CpPlaceholderExpansion;
|
import me.rockyhawk.commandpanels.classresources.placeholders.expansion.CpPlaceholderExpansion;
|
||||||
@ -16,16 +17,19 @@ import me.rockyhawk.commandpanels.classresources.placeholders.CreateText;
|
|||||||
import me.rockyhawk.commandpanels.classresources.placeholders.HexColours;
|
import me.rockyhawk.commandpanels.classresources.placeholders.HexColours;
|
||||||
import me.rockyhawk.commandpanels.classresources.placeholders.Placeholders;
|
import me.rockyhawk.commandpanels.classresources.placeholders.Placeholders;
|
||||||
import me.rockyhawk.commandpanels.commands.*;
|
import me.rockyhawk.commandpanels.commands.*;
|
||||||
import me.rockyhawk.commandpanels.commandtags.CommandTags;
|
import me.rockyhawk.commandpanels.commandtags.CommandRunner;
|
||||||
import me.rockyhawk.commandpanels.completetabs.CpTabComplete;
|
import me.rockyhawk.commandpanels.completetabs.CpTabComplete;
|
||||||
import me.rockyhawk.commandpanels.completetabs.UpdateTabComplete;
|
import me.rockyhawk.commandpanels.completetabs.UpdateTabComplete;
|
||||||
import me.rockyhawk.commandpanels.customcommands.Commandpanelcustom;
|
import me.rockyhawk.commandpanels.customcommands.Commandpanelcustom;
|
||||||
import me.rockyhawk.commandpanels.datamanager.DebugManager;
|
import me.rockyhawk.commandpanels.datamanager.DebugManager;
|
||||||
import me.rockyhawk.commandpanels.datamanager.PanelDataLoader;
|
import me.rockyhawk.commandpanels.datamanager.PanelDataLoader;
|
||||||
|
import me.rockyhawk.commandpanels.datamanager.PanelDataPlayerManager;
|
||||||
import me.rockyhawk.commandpanels.editor.*;
|
import me.rockyhawk.commandpanels.editor.*;
|
||||||
|
import me.rockyhawk.commandpanels.floodgatecp.OpenFloodgateGUI;
|
||||||
import me.rockyhawk.commandpanels.generatepanels.Commandpanelsgenerate;
|
import me.rockyhawk.commandpanels.generatepanels.Commandpanelsgenerate;
|
||||||
import me.rockyhawk.commandpanels.generatepanels.GenUtils;
|
import me.rockyhawk.commandpanels.generatepanels.GenUtils;
|
||||||
import me.rockyhawk.commandpanels.generatepanels.TabCompleteGenerate;
|
import me.rockyhawk.commandpanels.generatepanels.TabCompleteGenerate;
|
||||||
|
import me.rockyhawk.commandpanels.interactives.OutsideClickEvent;
|
||||||
import me.rockyhawk.commandpanels.interactives.input.UserInputUtils;
|
import me.rockyhawk.commandpanels.interactives.input.UserInputUtils;
|
||||||
import me.rockyhawk.commandpanels.interactives.Commandpanelrefresher;
|
import me.rockyhawk.commandpanels.interactives.Commandpanelrefresher;
|
||||||
import me.rockyhawk.commandpanels.interactives.OpenOnJoin;
|
import me.rockyhawk.commandpanels.interactives.OpenOnJoin;
|
||||||
@ -33,6 +37,8 @@ import me.rockyhawk.commandpanels.ioclasses.nbt.NBTManager;
|
|||||||
import me.rockyhawk.commandpanels.ioclasses.legacy.LegacyVersion;
|
import me.rockyhawk.commandpanels.ioclasses.legacy.LegacyVersion;
|
||||||
import me.rockyhawk.commandpanels.ioclasses.legacy.MinecraftVersions;
|
import me.rockyhawk.commandpanels.ioclasses.legacy.MinecraftVersions;
|
||||||
import me.rockyhawk.commandpanels.ioclasses.legacy.PlayerHeads;
|
import me.rockyhawk.commandpanels.ioclasses.legacy.PlayerHeads;
|
||||||
|
import me.rockyhawk.commandpanels.ioclasses.potions.ClassicPotionData;
|
||||||
|
import me.rockyhawk.commandpanels.ioclasses.potions.LegacyPotionData;
|
||||||
import me.rockyhawk.commandpanels.openpanelsmanager.*;
|
import me.rockyhawk.commandpanels.openpanelsmanager.*;
|
||||||
import me.rockyhawk.commandpanels.openwithitem.HotbarItemLoader;
|
import me.rockyhawk.commandpanels.openwithitem.HotbarItemLoader;
|
||||||
import me.rockyhawk.commandpanels.openwithitem.SwapItemEvent;
|
import me.rockyhawk.commandpanels.openwithitem.SwapItemEvent;
|
||||||
@ -43,6 +49,8 @@ import me.rockyhawk.commandpanels.panelblocks.Commandpanelblocks;
|
|||||||
import me.rockyhawk.commandpanels.panelblocks.PanelBlockOnClick;
|
import me.rockyhawk.commandpanels.panelblocks.PanelBlockOnClick;
|
||||||
import me.rockyhawk.commandpanels.playerinventoryhandler.InventorySaver;
|
import me.rockyhawk.commandpanels.playerinventoryhandler.InventorySaver;
|
||||||
import me.rockyhawk.commandpanels.playerinventoryhandler.ItemStackSerializer;
|
import me.rockyhawk.commandpanels.playerinventoryhandler.ItemStackSerializer;
|
||||||
|
import me.rockyhawk.commandpanels.playerinventoryhandler.pickupevent.EntityPickupEvent;
|
||||||
|
import me.rockyhawk.commandpanels.playerinventoryhandler.pickupevent.legacyPlayerEvent;
|
||||||
import me.rockyhawk.commandpanels.updater.Updater;
|
import me.rockyhawk.commandpanels.updater.Updater;
|
||||||
import net.milkbowl.vault.economy.Economy;
|
import net.milkbowl.vault.economy.Economy;
|
||||||
import org.apache.commons.io.IOUtils;
|
import org.apache.commons.io.IOUtils;
|
||||||
@ -69,7 +77,6 @@ import java.io.Reader;
|
|||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
public class CommandPanels extends JavaPlugin{
|
public class CommandPanels extends JavaPlugin{
|
||||||
public VotingPluginHooks votingPlugin;
|
|
||||||
public YamlConfiguration config;
|
public YamlConfiguration config;
|
||||||
public Economy econ = null;
|
public Economy econ = null;
|
||||||
public boolean openWithItem = false; //this will be true if there is a panel with open-with-item
|
public boolean openWithItem = false; //this will be true if there is a panel with open-with-item
|
||||||
@ -83,19 +90,25 @@ public class CommandPanels extends JavaPlugin{
|
|||||||
//get alternate classes
|
//get alternate classes
|
||||||
public PanelDownloader downloader = new PanelDownloader(this);
|
public PanelDownloader downloader = new PanelDownloader(this);
|
||||||
|
|
||||||
public CommandTags commandTags = new CommandTags(this);
|
public CommandRunner commandRunner = new CommandRunner(this);
|
||||||
public PanelDataLoader panelData = new PanelDataLoader(this);
|
public PanelDataLoader panelData = new PanelDataLoader(this);
|
||||||
|
public PanelDataPlayerManager panelDataPlayers = new PanelDataPlayerManager(this);
|
||||||
|
|
||||||
public Placeholders placeholders = new Placeholders(this);
|
public Placeholders placeholders = new Placeholders(this);
|
||||||
public DebugManager debug = new DebugManager(this);
|
public DebugManager debug = new DebugManager(this);
|
||||||
public CreateText tex = new CreateText(this);
|
public CreateText tex = new CreateText(this);
|
||||||
public HexColours hex = new HexColours(this);
|
public HexColours hex = new HexColours(this);
|
||||||
|
|
||||||
|
public MiniMessageUtils miniMessage = null;
|
||||||
|
|
||||||
public ExecuteOpenVoids openVoids = new ExecuteOpenVoids(this);
|
public ExecuteOpenVoids openVoids = new ExecuteOpenVoids(this);
|
||||||
public ItemCreation itemCreate = new ItemCreation(this);
|
public ItemCreation itemCreate = new ItemCreation(this);
|
||||||
public HasSections has = new HasSections(this);
|
public HasSections has = new HasSections(this);
|
||||||
public GetCustomHeads customHeads = new GetCustomHeads(this);
|
public GetCustomHeads customHeads = new GetCustomHeads(this);
|
||||||
public Updater updater = new Updater(this);
|
public Updater updater = new Updater(this);
|
||||||
public PlayerHeads getHeads = new PlayerHeads(this);
|
public PlayerHeads getHeads = new PlayerHeads(this);
|
||||||
|
public ClassicPotionData classicPotion = new ClassicPotionData(this);
|
||||||
|
public LegacyPotionData legacyPotion = new LegacyPotionData(this);
|
||||||
public LegacyVersion legacy = new LegacyVersion(this);
|
public LegacyVersion legacy = new LegacyVersion(this);
|
||||||
|
|
||||||
public OpenPanelsLoader openPanels = new OpenPanelsLoader(this);
|
public OpenPanelsLoader openPanels = new OpenPanelsLoader(this);
|
||||||
@ -114,6 +127,9 @@ public class CommandPanels extends JavaPlugin{
|
|||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
Bukkit.getLogger().info("[CommandPanels] RockyHawk's CommandPanels v" + this.getDescription().getVersion() + " Plugin Loading...");
|
Bukkit.getLogger().info("[CommandPanels] RockyHawk's CommandPanels v" + this.getDescription().getVersion() + " Plugin Loading...");
|
||||||
|
|
||||||
|
//Initialise classes that are not used externally
|
||||||
|
new OpenFloodgateGUI(this);
|
||||||
|
|
||||||
//register config files
|
//register config files
|
||||||
this.blockConfig = YamlConfiguration.loadConfiguration(new File(getDataFolder() + File.separator + "blocks.yml"));
|
this.blockConfig = YamlConfiguration.loadConfiguration(new File(getDataFolder() + File.separator + "blocks.yml"));
|
||||||
panelData.dataConfig = YamlConfiguration.loadConfiguration(new File(getDataFolder() + File.separator + "data.yml"));
|
panelData.dataConfig = YamlConfiguration.loadConfiguration(new File(getDataFolder() + File.separator + "data.yml"));
|
||||||
@ -152,6 +168,7 @@ public class CommandPanels extends JavaPlugin{
|
|||||||
new Metrics(this, 5097);
|
new Metrics(this, 5097);
|
||||||
this.setupEconomy();
|
this.setupEconomy();
|
||||||
this.getServer().getMessenger().registerOutgoingPluginChannel(this, "BungeeCord");
|
this.getServer().getMessenger().registerOutgoingPluginChannel(this, "BungeeCord");
|
||||||
|
this.getServer().getMessenger().registerOutgoingPluginChannel(this, "my:psb");
|
||||||
Objects.requireNonNull(this.getCommand("commandpanel")).setExecutor(new Commandpanel(this));
|
Objects.requireNonNull(this.getCommand("commandpanel")).setExecutor(new Commandpanel(this));
|
||||||
Objects.requireNonNull(this.getCommand("commandpanel")).setTabCompleter(new CpTabComplete(this));
|
Objects.requireNonNull(this.getCommand("commandpanel")).setTabCompleter(new CpTabComplete(this));
|
||||||
|
|
||||||
@ -174,12 +191,36 @@ public class CommandPanels extends JavaPlugin{
|
|||||||
Objects.requireNonNull(this.getCommand("commandpanelversion")).setExecutor(new Commandpanelversion(this));
|
Objects.requireNonNull(this.getCommand("commandpanelversion")).setExecutor(new Commandpanelversion(this));
|
||||||
Objects.requireNonNull(this.getCommand("commandpanellist")).setExecutor(new Commandpanelslist(this));
|
Objects.requireNonNull(this.getCommand("commandpanellist")).setExecutor(new Commandpanelslist(this));
|
||||||
this.getServer().getPluginManager().registerEvents(new Utils(this), this);
|
this.getServer().getPluginManager().registerEvents(new Utils(this), this);
|
||||||
|
|
||||||
this.getServer().getPluginManager().registerEvents(inventorySaver, this);
|
this.getServer().getPluginManager().registerEvents(inventorySaver, this);
|
||||||
|
if(this.legacy.MAJOR_VERSION.greaterThanOrEqualTo(MinecraftVersions.v1_12)){
|
||||||
|
this.getServer().getPluginManager().registerEvents(new EntityPickupEvent(this), this);
|
||||||
|
}else{
|
||||||
|
this.getServer().getPluginManager().registerEvents(new legacyPlayerEvent(this), this);
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Check all the minimessage classes exist before loading
|
||||||
|
Class.forName("net.kyori.adventure.text.Component");
|
||||||
|
Class.forName("net.kyori.adventure.text.format.TextDecoration");
|
||||||
|
Class.forName("net.kyori.adventure.text.minimessage.MiniMessage");
|
||||||
|
Class.forName("net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer");
|
||||||
|
miniMessage = new MiniMessageUtils(this);
|
||||||
|
} catch (ClassNotFoundException ignore) {
|
||||||
|
//do not initialise miniMessage
|
||||||
|
}
|
||||||
|
|
||||||
this.getServer().getPluginManager().registerEvents(inputUtils, this);
|
this.getServer().getPluginManager().registerEvents(inputUtils, this);
|
||||||
|
this.getServer().getPluginManager().registerEvents(panelDataPlayers, this);
|
||||||
this.getServer().getPluginManager().registerEvents(new UtilsPanelsLoader(this), this);
|
this.getServer().getPluginManager().registerEvents(new UtilsPanelsLoader(this), this);
|
||||||
this.getServer().getPluginManager().registerEvents(new GenUtils(this), this);
|
this.getServer().getPluginManager().registerEvents(new GenUtils(this), this);
|
||||||
this.getServer().getPluginManager().registerEvents(new ItemFallManager(this), this);
|
this.getServer().getPluginManager().registerEvents(new ItemFallManager(this), this);
|
||||||
this.getServer().getPluginManager().registerEvents(new OpenOnJoin(this), this);
|
this.getServer().getPluginManager().registerEvents(new OpenOnJoin(this), this);
|
||||||
|
this.getServer().getPluginManager().registerEvents(new OutsideClickEvent(this), this);
|
||||||
|
|
||||||
|
if (this.getServer().getPluginManager().isPluginEnabled("floodgate")) {
|
||||||
|
this.getServer().getPluginManager().registerEvents(new OpenFloodgateGUI(this), this);
|
||||||
|
}
|
||||||
|
|
||||||
//load in the updater if requested
|
//load in the updater if requested
|
||||||
if (Objects.requireNonNull(config.getString("updater.update-checks")).equalsIgnoreCase("true")) {
|
if (Objects.requireNonNull(config.getString("updater.update-checks")).equalsIgnoreCase("true")) {
|
||||||
@ -192,7 +233,7 @@ public class CommandPanels extends JavaPlugin{
|
|||||||
}
|
}
|
||||||
|
|
||||||
//load in all built in command tags
|
//load in all built in command tags
|
||||||
commandTags.registerBuiltInTags();
|
commandRunner.registerBuiltInTags();
|
||||||
|
|
||||||
//if refresh-panels set to false, don't load this
|
//if refresh-panels set to false, don't load this
|
||||||
if(Objects.requireNonNull(config.getString("config.refresh-panels")).equalsIgnoreCase("true")){
|
if(Objects.requireNonNull(config.getString("config.refresh-panels")).equalsIgnoreCase("true")){
|
||||||
@ -220,10 +261,6 @@ public class CommandPanels extends JavaPlugin{
|
|||||||
if (!Bukkit.getVersion().contains("1.8")) {
|
if (!Bukkit.getVersion().contains("1.8")) {
|
||||||
this.getServer().getPluginManager().registerEvents(new SwapItemEvent(this), this);
|
this.getServer().getPluginManager().registerEvents(new SwapItemEvent(this), this);
|
||||||
}
|
}
|
||||||
//if VotingPlugin is enabled
|
|
||||||
if (getServer().getPluginManager().isPluginEnabled("VotingPlugin")) {
|
|
||||||
votingPlugin= VotingPluginHooks.getInstance();
|
|
||||||
}
|
|
||||||
//if plugin ChestSort is enabled
|
//if plugin ChestSort is enabled
|
||||||
if(getServer().getPluginManager().isPluginEnabled("ChestSort")){
|
if(getServer().getPluginManager().isPluginEnabled("ChestSort")){
|
||||||
this.getServer().getPluginManager().registerEvents(new UtilsChestSortEvent(this), this);
|
this.getServer().getPluginManager().registerEvents(new UtilsChestSortEvent(this), this);
|
||||||
@ -232,7 +269,7 @@ public class CommandPanels extends JavaPlugin{
|
|||||||
//save the example_top.yml file and the template.yml file
|
//save the example_top.yml file and the template.yml file
|
||||||
if (!this.panelsf.exists()) {
|
if (!this.panelsf.exists()) {
|
||||||
try {
|
try {
|
||||||
if(legacy.LOCAL_VERSION.lessThanOrEqualTo(MinecraftVersions.v1_12)){
|
if(legacy.MAJOR_VERSION.lessThanOrEqualTo(MinecraftVersions.v1_12)){
|
||||||
FileConfiguration exampleFileConfiguration = YamlConfiguration.loadConfiguration(getReaderFromStream(this.getResource("exampleLegacy.yml")));
|
FileConfiguration exampleFileConfiguration = YamlConfiguration.loadConfiguration(getReaderFromStream(this.getResource("exampleLegacy.yml")));
|
||||||
exampleFileConfiguration.save(new File(this.panelsf + File.separator + "example.yml"));
|
exampleFileConfiguration.save(new File(this.panelsf + File.separator + "example.yml"));
|
||||||
}else {
|
}else {
|
||||||
@ -262,6 +299,9 @@ public class CommandPanels extends JavaPlugin{
|
|||||||
//do hotbar items
|
//do hotbar items
|
||||||
hotbar.reloadHotbarSlots();
|
hotbar.reloadHotbarSlots();
|
||||||
|
|
||||||
|
//load all known players for data
|
||||||
|
panelDataPlayers.reloadAllPlayers();
|
||||||
|
|
||||||
//add custom charts bStats
|
//add custom charts bStats
|
||||||
Metrics metrics = new Metrics(this, 5097);
|
Metrics metrics = new Metrics(this, 5097);
|
||||||
metrics.addCustomChart(new SingleLineChart("panels_amount", () -> {
|
metrics.addCustomChart(new SingleLineChart("panels_amount", () -> {
|
||||||
@ -309,17 +349,30 @@ public class CommandPanels extends JavaPlugin{
|
|||||||
assert renamedMeta != null;
|
assert renamedMeta != null;
|
||||||
//hiding attributes will add an NBT tag
|
//hiding attributes will add an NBT tag
|
||||||
if(hideAttributes) {
|
if(hideAttributes) {
|
||||||
renamedMeta.addItemFlags(ItemFlag.HIDE_ATTRIBUTES);
|
|
||||||
renamedMeta.addItemFlags(ItemFlag.HIDE_POTION_EFFECTS);
|
|
||||||
renamedMeta.addItemFlags(ItemFlag.HIDE_ENCHANTS);
|
renamedMeta.addItemFlags(ItemFlag.HIDE_ENCHANTS);
|
||||||
|
renamedMeta.addItemFlags(ItemFlag.HIDE_ATTRIBUTES);
|
||||||
|
//HIDE_ADDITIONAL_TOOLTIP was added into 1.20.5 api
|
||||||
|
if(legacy.MAJOR_VERSION.greaterThanOrEqualTo(MinecraftVersions.v1_21) ||
|
||||||
|
(legacy.MAJOR_VERSION.greaterThanOrEqualTo(MinecraftVersions.v1_20) && legacy.MINOR_VERSION >= 5)){
|
||||||
|
renamedMeta.addItemFlags(ItemFlag.valueOf("HIDE_ADDITIONAL_TOOLTIP"));
|
||||||
|
}
|
||||||
|
//HIDE_POTION_EFFECTS was removed in the 1.20.5 api
|
||||||
|
if(legacy.MAJOR_VERSION.lessThanOrEqualTo(MinecraftVersions.v1_19) ||
|
||||||
|
(legacy.MAJOR_VERSION == MinecraftVersions.v1_20 && legacy.MINOR_VERSION <= 4)){
|
||||||
|
renamedMeta.addItemFlags(ItemFlag.valueOf("HIDE_POTION_EFFECTS"));
|
||||||
|
}
|
||||||
//HIDE_ARMOR_TRIM was added into 1.20 api
|
//HIDE_ARMOR_TRIM was added into 1.20 api
|
||||||
if(legacy.LOCAL_VERSION.greaterThanOrEqualTo(MinecraftVersions.v1_20)){
|
if(legacy.MAJOR_VERSION.greaterThanOrEqualTo(MinecraftVersions.v1_20)){
|
||||||
renamedMeta.addItemFlags(ItemFlag.HIDE_ARMOR_TRIM);
|
renamedMeta.addItemFlags(ItemFlag.HIDE_ARMOR_TRIM);
|
||||||
}
|
}
|
||||||
//HIDE_DYE was added into 1.17 api
|
//HIDE_DYE was added into 1.17 api
|
||||||
if(legacy.LOCAL_VERSION.greaterThanOrEqualTo(MinecraftVersions.v1_17)){
|
if(legacy.MAJOR_VERSION.greaterThanOrEqualTo(MinecraftVersions.v1_17)){
|
||||||
renamedMeta.addItemFlags(ItemFlag.HIDE_DYE);
|
renamedMeta.addItemFlags(ItemFlag.HIDE_DYE);
|
||||||
}
|
}
|
||||||
|
//setAttributeModifiers was added into 1.14 api
|
||||||
|
if(legacy.MAJOR_VERSION.greaterThanOrEqualTo(MinecraftVersions.v1_14)){
|
||||||
|
renamedMeta.setAttributeModifiers(ImmutableMultimap.of());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (customName != null) {
|
if (customName != null) {
|
||||||
renamedMeta.setDisplayName(customName);
|
renamedMeta.setDisplayName(customName);
|
||||||
@ -452,7 +505,7 @@ public class CommandPanels extends JavaPlugin{
|
|||||||
p.sendMessage(ChatColor.GOLD + "/cpv " + ChatColor.WHITE + "Display the current version.");
|
p.sendMessage(ChatColor.GOLD + "/cpv " + ChatColor.WHITE + "Display the current version.");
|
||||||
}
|
}
|
||||||
if (p.hasPermission("commandpanel.refresh")) {
|
if (p.hasPermission("commandpanel.refresh")) {
|
||||||
p.sendMessage(ChatColor.GOLD + "/cpu [player] [position:all] " + ChatColor.WHITE + "Update a panel for a player while it is still open.");
|
p.sendMessage(ChatColor.GOLD + "/cpu <player> [position:all] " + ChatColor.WHITE + "Update a panel for a player while it is still open.");
|
||||||
}
|
}
|
||||||
if (p.hasPermission("commandpanel.update")) {
|
if (p.hasPermission("commandpanel.update")) {
|
||||||
p.sendMessage(ChatColor.GOLD + "/cpv latest " + ChatColor.WHITE + "Download the latest update upon server reload/restart.");
|
p.sendMessage(ChatColor.GOLD + "/cpv latest " + ChatColor.WHITE + "Download the latest update upon server reload/restart.");
|
||||||
@ -462,7 +515,7 @@ public class CommandPanels extends JavaPlugin{
|
|||||||
p.sendMessage(ChatColor.GOLD + "/cpe <panel file> " + ChatColor.WHITE + "Export panel to the Online Editor.");
|
p.sendMessage(ChatColor.GOLD + "/cpe <panel file> " + ChatColor.WHITE + "Export panel to the Online Editor.");
|
||||||
}
|
}
|
||||||
if (p.hasPermission("commandpanel.import")) {
|
if (p.hasPermission("commandpanel.import")) {
|
||||||
p.sendMessage(ChatColor.GOLD + "/cpi [file name] [URL] " + ChatColor.WHITE + "Downloads a panel from a raw link online.");
|
p.sendMessage(ChatColor.GOLD + "/cpi <file name> <URL> " + ChatColor.WHITE + "Downloads a panel from a raw link online.");
|
||||||
}
|
}
|
||||||
if (p.hasPermission("commandpanel.list")) {
|
if (p.hasPermission("commandpanel.list")) {
|
||||||
p.sendMessage(ChatColor.GOLD + "/cpl " + ChatColor.WHITE + "Lists the currently loaded panels.");
|
p.sendMessage(ChatColor.GOLD + "/cpl " + ChatColor.WHITE + "Lists the currently loaded panels.");
|
||||||
|
@ -45,7 +45,7 @@ public class Utils implements Listener {
|
|||||||
//if the panel is clicked on the outside area of the GUI
|
//if the panel is clicked on the outside area of the GUI
|
||||||
if (panel.getConfig().contains("outside-commands")) {
|
if (panel.getConfig().contains("outside-commands")) {
|
||||||
try {
|
try {
|
||||||
plugin.commandTags.runCommands(panel,PanelPosition.Top,p, panel.getConfig().getStringList("outside-commands"),e.getClick());
|
plugin.commandRunner.runCommands(panel,PanelPosition.Top,p, panel.getConfig().getStringList("outside-commands"),e.getClick());
|
||||||
}catch(Exception s){
|
}catch(Exception s){
|
||||||
plugin.debug(s,p);
|
plugin.debug(s,p);
|
||||||
}
|
}
|
||||||
@ -87,23 +87,24 @@ public class Utils implements Listener {
|
|||||||
panel = plugin.openPanels.getOpenPanel(p.getName(),position);
|
panel = plugin.openPanels.getOpenPanel(p.getName(),position);
|
||||||
|
|
||||||
//this loops through all the items in the panel
|
//this loops through all the items in the panel
|
||||||
boolean foundSlot = false;
|
String foundSlot = null;
|
||||||
for(String slot : Objects.requireNonNull(panel.getConfig().getConfigurationSection("item")).getKeys(false)){
|
for(String item : Objects.requireNonNull(panel.getConfig().getConfigurationSection("item")).getKeys(false)){
|
||||||
|
String slot = plugin.tex.placeholdersNoColour(panel, position, p, item);
|
||||||
if (slot.equals(Integer.toString(clickedSlot))) {
|
if (slot.equals(Integer.toString(clickedSlot))) {
|
||||||
foundSlot = true;
|
foundSlot = item;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(!foundSlot){
|
if(foundSlot == null){
|
||||||
e.setCancelled(true);
|
e.setCancelled(true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
//get the section of the slot that was clicked
|
//get the section of the slot that was clicked
|
||||||
String section = plugin.has.hasSection(panel,position,panel.getConfig().getConfigurationSection("item." + clickedSlot), p);
|
String section = plugin.has.hasSection(panel,position,panel.getConfig().getConfigurationSection("item." + foundSlot), p);
|
||||||
|
|
||||||
if(panel.getConfig().contains("item." + clickedSlot + section + ".itemType")){
|
if(panel.getConfig().contains("item." + foundSlot + section + ".itemType")){
|
||||||
if(panel.getConfig().getStringList("item." + clickedSlot + section + ".itemType").contains("placeable")){
|
if(panel.getConfig().getStringList("item." + foundSlot + section + ".itemType").contains("placeable")){
|
||||||
//skip if the item is a placeable
|
//skip if the item is a placeable
|
||||||
e.setCancelled(false);
|
e.setCancelled(false);
|
||||||
return;
|
return;
|
||||||
@ -115,13 +116,13 @@ public class Utils implements Listener {
|
|||||||
p.updateInventory();
|
p.updateInventory();
|
||||||
|
|
||||||
//if an item has an area for input instead of commands
|
//if an item has an area for input instead of commands
|
||||||
if(panel.getConfig().contains("item." + clickedSlot + section + ".player-input")) {
|
if(panel.getConfig().contains("item." + foundSlot + section + ".player-input")) {
|
||||||
plugin.inputUtils.playerInput.put(p,new PlayerInput(panel,panel.getConfig().getStringList("item." + clickedSlot + section + ".player-input"),e.getClick()));
|
plugin.inputUtils.playerInput.put(p,new PlayerInput(panel,panel.getConfig().getStringList("item." + foundSlot + section + ".player-input"),e.getClick()));
|
||||||
plugin.inputUtils.sendMessage(panel,position,p);
|
plugin.inputUtils.sendMessage(panel,position,p);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(panel.getConfig().contains("item." + clickedSlot + section + ".commands")) {
|
if(panel.getConfig().contains("item." + foundSlot + section + ".commands")) {
|
||||||
List<String> commands = panel.getConfig().getStringList("item." + clickedSlot + section + ".commands");
|
List<String> commands = panel.getConfig().getStringList("item." + foundSlot + section + ".commands");
|
||||||
if (!commands.isEmpty()) {
|
if (!commands.isEmpty()) {
|
||||||
for (int i = 0; commands.size() > i; i++) {
|
for (int i = 0; commands.size() > i; i++) {
|
||||||
try {
|
try {
|
||||||
@ -130,12 +131,12 @@ public class Utils implements Listener {
|
|||||||
commands.set(i, commands.get(i).replaceAll("%cp-clicked%", "AIR"));
|
commands.set(i, commands.get(i).replaceAll("%cp-clicked%", "AIR"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (panel.getConfig().contains("item." + clickedSlot + section + ".multi-paywall")) {
|
if (panel.getConfig().contains("item." + foundSlot + section + ".multi-paywall")) {
|
||||||
plugin.commandTags.runMultiPaywall(panel,position,p,
|
plugin.commandRunner.runMultiPaywall(panel,position,p,
|
||||||
panel.getConfig().getStringList("item." + clickedSlot + section + ".multi-paywall"),
|
panel.getConfig().getStringList("item." + foundSlot + section + ".multi-paywall"),
|
||||||
commands,e.getClick());
|
commands,e.getClick());
|
||||||
} else {
|
} else {
|
||||||
plugin.commandTags.runCommands(panel, position, p, commands, e.getClick());
|
plugin.commandRunner.runCommands(panel, position, p, commands, e.getClick());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -87,7 +87,7 @@ public class Panel{
|
|||||||
public ItemStack getHotbarItem(Player p){
|
public ItemStack getHotbarItem(Player p){
|
||||||
if (this.getConfig().contains("open-with-item.pre-load-commands")) {
|
if (this.getConfig().contains("open-with-item.pre-load-commands")) {
|
||||||
try {
|
try {
|
||||||
plugin.commandTags.runCommands(this,PanelPosition.Top,p, this.getConfig().getStringList("open-with-item.pre-load-commands"));
|
plugin.commandRunner.runCommands(this,PanelPosition.Top,p, this.getConfig().getStringList("open-with-item.pre-load-commands"), null);
|
||||||
}catch(Exception s){
|
}catch(Exception s){
|
||||||
plugin.debug(s,p);
|
plugin.debug(s,p);
|
||||||
}
|
}
|
||||||
@ -99,7 +99,7 @@ public class Panel{
|
|||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
//add NBT to item and return the ItemStack
|
//add NBT to item and return the ItemStack
|
||||||
return plugin.nbt.setNBT(s, "CommandPanelsHotbar", panelName + ":" + slot);
|
return plugin.nbt.setNBT(s, "CommandPanelsHotbar", "string_" + panelName + ":" + slot);
|
||||||
}catch(Exception e) {
|
}catch(Exception e) {
|
||||||
//return air if null
|
//return air if null
|
||||||
return new ItemStack(Material.AIR);
|
return new ItemStack(Material.AIR);
|
||||||
|
@ -82,7 +82,7 @@ public class ExecuteOpenVoids {
|
|||||||
//execute commands once the panel opens
|
//execute commands once the panel opens
|
||||||
if (panel.getConfig().contains("commands-on-open")) {
|
if (panel.getConfig().contains("commands-on-open")) {
|
||||||
try {
|
try {
|
||||||
plugin.commandTags.runCommands(panel,position,p, panel.getConfig().getStringList("commands-on-open"));
|
plugin.commandRunner.runCommands(panel,position,p, panel.getConfig().getStringList("commands-on-open"), null);
|
||||||
}catch(Exception s){
|
}catch(Exception s){
|
||||||
p.sendMessage(plugin.tex.colour(plugin.tag + plugin.config.getString("config.format.error") + " " + "commands-on-open: " + panel.getConfig().getString("commands-on-open")));
|
p.sendMessage(plugin.tex.colour(plugin.tag + plugin.config.getString("config.format.error") + " " + "commands-on-open: " + panel.getConfig().getString("commands-on-open")));
|
||||||
}
|
}
|
||||||
@ -155,7 +155,7 @@ public class ExecuteOpenVoids {
|
|||||||
public void beforeLoadCommands(Panel panel,PanelPosition pos, Player p){
|
public void beforeLoadCommands(Panel panel,PanelPosition pos, Player p){
|
||||||
if (panel.getConfig().contains("pre-load-commands")) {
|
if (panel.getConfig().contains("pre-load-commands")) {
|
||||||
try {
|
try {
|
||||||
plugin.commandTags.runCommands(panel,pos,p, panel.getConfig().getStringList("pre-load-commands"));
|
plugin.commandRunner.runCommands(panel,pos,p, panel.getConfig().getStringList("pre-load-commands"), null);
|
||||||
}catch(Exception s){
|
}catch(Exception s){
|
||||||
plugin.debug(s,p);
|
plugin.debug(s,p);
|
||||||
}
|
}
|
||||||
|
@ -9,9 +9,7 @@ import org.bukkit.configuration.ConfigurationSection;
|
|||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.util.Arrays;
|
import java.util.*;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.HashSet;
|
|
||||||
|
|
||||||
public class HasSections {
|
public class HasSections {
|
||||||
CommandPanels plugin;
|
CommandPanels plugin;
|
||||||
@ -19,74 +17,85 @@ public class HasSections {
|
|||||||
plugin = pl;
|
plugin = pl;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String hasSection(Panel panel, PanelPosition position, ConfigurationSection cf, Player p){
|
public String hasSection(Panel panel, PanelPosition position, ConfigurationSection cf, Player p) {
|
||||||
for (int count = 0; cf.getKeys(false).size() > count; count++) {
|
// Use a TreeMap to automatically sort the sections by the extracted number.
|
||||||
String setName;
|
Map<Integer, String> sortedSections = new TreeMap<>();
|
||||||
if(cf.isSet("has" + count)) {
|
|
||||||
setName = "has" + count;
|
// Loop through the section names and filter for the ones starting with "has".
|
||||||
}else{
|
for (String key : cf.getKeys(false)) {
|
||||||
continue;
|
if (!cf.isConfigurationSection(key)) continue;
|
||||||
|
|
||||||
|
// Check if the section starts with "has" and is followed by a number.
|
||||||
|
if (key.startsWith("has")) {
|
||||||
|
try {
|
||||||
|
// Extract the number after "has" and put it in the map for sorting.
|
||||||
|
int number = Integer.parseInt(key.substring(3));
|
||||||
|
sortedSections.put(number, key);
|
||||||
|
} catch (NumberFormatException ignore) {
|
||||||
|
// If the section name doesn't have a valid number after "has", skip it.
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
boolean endProcess = true;
|
for (String hasSection : sortedSections.values()) {
|
||||||
//loop through possible values and compares for hypothetical and operators
|
if (!cf.isConfigurationSection(hasSection)) continue;
|
||||||
for (int a = 0; cf.getConfigurationSection(setName).getKeys(false).size() > a; a++) {
|
|
||||||
if(cf.isSet(setName + ".value" + a) && cf.isSet(setName + ".compare" + a)){
|
|
||||||
//ensure the endProcess variable has been reset for another operation
|
|
||||||
endProcess = true;
|
|
||||||
//get the values of this statement
|
|
||||||
String value;
|
|
||||||
String compare;
|
|
||||||
try {
|
|
||||||
value = ChatColor.stripColor(plugin.tex.placeholders(panel, position, p, cf.getString(setName + ".value" + a)));
|
|
||||||
compare = ChatColor.stripColor(plugin.tex.placeholders(panel, position, p, cf.getString(setName + ".compare" + a)));
|
|
||||||
}catch (Exception e) {
|
|
||||||
//if errors getting text return
|
|
||||||
plugin.debug(e,p);
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
|
|
||||||
String operator = "AND";
|
ConfigurationSection currentSection = cf.getConfigurationSection(hasSection);
|
||||||
if(compare.endsWith(" OR")){
|
int numberOfConditions = currentSection.getKeys(false).size();
|
||||||
compare = compare.substring(0, compare.length()-3);
|
|
||||||
operator = "OR";
|
|
||||||
}else if(compare.endsWith(" AND")){
|
|
||||||
compare = compare.substring(0, compare.length()-4);
|
|
||||||
}
|
|
||||||
|
|
||||||
//list of values with the or operator
|
Boolean currentBlockResult = null; // This will store the result of the current block (a set of conditions combined by AND or OR).
|
||||||
HashSet<String> values = doOperators(new HashSet<>(Collections.singletonList(value)));
|
String previousOperator = "AND"; // Default logical operator to start with.
|
||||||
//go through all values with the or operator
|
|
||||||
for(String val : values){
|
for (int a = 0; a < numberOfConditions; a++) {
|
||||||
if (hasProcess(setName, val, compare, p)) {
|
if (!currentSection.isSet("value" + a) || !currentSection.isSet("compare" + a)) {
|
||||||
endProcess = false;
|
continue;
|
||||||
//if it is true and it is OR, there is no need to check the next value in the line
|
}
|
||||||
if(operator.equals("OR")){
|
|
||||||
a++;
|
String value = ChatColor.stripColor(plugin.tex.placeholders(panel, position, p, currentSection.getString("value" + a)));
|
||||||
}
|
String compare = ChatColor.stripColor(plugin.tex.placeholders(panel, position, p, currentSection.getString("compare" + a)));
|
||||||
}
|
|
||||||
}
|
String operator = "AND"; // Default operator for the current condition.
|
||||||
if(endProcess){
|
if (compare.endsWith(" OR")) {
|
||||||
//check if the operator link between the next value/compare is OR
|
compare = compare.substring(0, compare.length() - 3);
|
||||||
if(operator.equals("OR")){
|
operator = "OR";
|
||||||
//I can just continue because the algorithm already assumes the last sequence was true
|
} else if (compare.endsWith(" AND")) {
|
||||||
endProcess = false;
|
compare = compare.substring(0, compare.length() - 4);
|
||||||
continue;
|
}
|
||||||
}
|
|
||||||
|
HashSet<String> values = doOperators(new HashSet<>(Collections.singletonList(value)));
|
||||||
|
boolean localResult = false; // This tracks the result of the current condition.
|
||||||
|
for (String val : values) {
|
||||||
|
if (hasProcess(val, compare)) {
|
||||||
|
localResult = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (currentBlockResult == null) {
|
||||||
|
// Initialize the result of the block with the result of the first condition.
|
||||||
|
currentBlockResult = localResult;
|
||||||
|
} else {
|
||||||
|
// Combine the result of the current condition with the block result based on the previous operator.
|
||||||
|
if (previousOperator.equals("AND")) {
|
||||||
|
currentBlockResult = currentBlockResult && localResult;
|
||||||
|
} else if (previousOperator.equals("OR")) {
|
||||||
|
currentBlockResult = currentBlockResult || localResult;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
previousOperator = operator; // Update the operator for the next condition.
|
||||||
}
|
}
|
||||||
//if the has section is false move to the next has section
|
|
||||||
if(endProcess){
|
if (currentBlockResult != null && currentBlockResult) {
|
||||||
continue;
|
// If the result of this section is true, check nested sections.
|
||||||
|
return "." + hasSection + hasSection(panel, position, currentSection, p);
|
||||||
}
|
}
|
||||||
//proceed if none of the values were false
|
// If the result is false, continue to the next 'has' section.
|
||||||
return "." + setName + hasSection(panel, position, cf.getConfigurationSection(setName), p);
|
|
||||||
}
|
}
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private HashSet<String> doOperators(HashSet<String> value){
|
private HashSet<String> doOperators(HashSet<String> value){
|
||||||
for(String val : value){
|
for(String val : value){
|
||||||
if(val.contains(" OR ")){
|
if(val.contains(" OR ")){
|
||||||
@ -98,7 +107,7 @@ public class HasSections {
|
|||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean hasProcess(String setName, String value, String compare,Player p){
|
private boolean hasProcess(String value, String compare){
|
||||||
//check to see if the value should be reversed
|
//check to see if the value should be reversed
|
||||||
boolean outputValue = true;
|
boolean outputValue = true;
|
||||||
if(value.startsWith("NOT ")){
|
if(value.startsWith("NOT ")){
|
||||||
@ -106,25 +115,17 @@ public class HasSections {
|
|||||||
outputValue = false;
|
outputValue = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
//the original has sections as TinyTank800 wanted to keep them
|
|
||||||
if(setName.startsWith("hasvalue")) {
|
|
||||||
return compare.equals(value) == outputValue;
|
|
||||||
}
|
|
||||||
if(setName.startsWith("hasperm")) {
|
|
||||||
return p.hasPermission(value) == outputValue;
|
|
||||||
}
|
|
||||||
if(setName.startsWith("hasgreater")) {
|
|
||||||
return (Long.parseLong(compare) >= Long.parseLong(value)) == outputValue;
|
|
||||||
}
|
|
||||||
//the current has section with all the functions implemented inside it
|
//the current has section with all the functions implemented inside it
|
||||||
if(setName.startsWith("has")) {
|
if(value.endsWith(" HASPERM")) {
|
||||||
if(value.endsWith(" HASPERM")) {
|
String playername = value.substring(0, value.length()-8);
|
||||||
return Bukkit.getPlayer(value.substring(0, value.length()-8)).hasPermission(compare) == outputValue;
|
Player player = Bukkit.getPlayerExact(playername);
|
||||||
}else if(value.endsWith(" ISGREATER")) {
|
if(player != null){
|
||||||
return (new BigDecimal(compare).compareTo(new BigDecimal(value.substring(0, value.length()-10).replace(",",""))) <= 0 == outputValue);
|
return player.hasPermission(compare) == outputValue;
|
||||||
}else{
|
|
||||||
return compare.equals(value) == outputValue;
|
|
||||||
}
|
}
|
||||||
|
}else if(value.endsWith(" ISGREATER")) {
|
||||||
|
return (new BigDecimal(compare).compareTo(new BigDecimal(value.substring(0, value.length()-10).replace(",",""))) <= 0 == outputValue);
|
||||||
|
}else{
|
||||||
|
return compare.equals(value) == outputValue;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -1,11 +1,10 @@
|
|||||||
package me.rockyhawk.commandpanels.classresources;
|
package me.rockyhawk.commandpanels.classresources;
|
||||||
|
|
||||||
import de.tr7zw.changeme.nbtapi.NBT;
|
import dev.lone.itemsadder.api.CustomStack;
|
||||||
import de.tr7zw.changeme.nbtapi.NBTItem;
|
|
||||||
import de.tr7zw.changeme.nbtapi.iface.ReadWriteNBT;
|
|
||||||
import me.arcaniax.hdb.api.HeadDatabaseAPI;
|
import me.arcaniax.hdb.api.HeadDatabaseAPI;
|
||||||
import me.rockyhawk.commandpanels.CommandPanels;
|
import me.rockyhawk.commandpanels.CommandPanels;
|
||||||
import me.rockyhawk.commandpanels.api.Panel;
|
import me.rockyhawk.commandpanels.api.Panel;
|
||||||
|
import me.rockyhawk.commandpanels.classresources.customheads.SavedCustomHead;
|
||||||
import me.rockyhawk.commandpanels.ioclasses.legacy.MinecraftVersions;
|
import me.rockyhawk.commandpanels.ioclasses.legacy.MinecraftVersions;
|
||||||
import me.rockyhawk.commandpanels.openpanelsmanager.PanelPosition;
|
import me.rockyhawk.commandpanels.openpanelsmanager.PanelPosition;
|
||||||
import net.Indyuce.mmoitems.MMOItems;
|
import net.Indyuce.mmoitems.MMOItems;
|
||||||
@ -27,9 +26,9 @@ import org.bukkit.inventory.meta.*;
|
|||||||
import org.bukkit.inventory.meta.trim.ArmorTrim;
|
import org.bukkit.inventory.meta.trim.ArmorTrim;
|
||||||
import org.bukkit.inventory.meta.trim.TrimMaterial;
|
import org.bukkit.inventory.meta.trim.TrimMaterial;
|
||||||
import org.bukkit.inventory.meta.trim.TrimPattern;
|
import org.bukkit.inventory.meta.trim.TrimPattern;
|
||||||
import org.bukkit.potion.PotionData;
|
|
||||||
import org.bukkit.potion.PotionType;
|
import org.bukkit.potion.PotionType;
|
||||||
|
|
||||||
|
import java.lang.reflect.Method;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@ -52,7 +51,7 @@ public class ItemCreation {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
ItemStack s = null;
|
ItemStack s = null;
|
||||||
boolean hideAttributes = true;
|
boolean hideAttributes = false;
|
||||||
String mat;
|
String mat;
|
||||||
String matraw;
|
String matraw;
|
||||||
String skullname;
|
String skullname;
|
||||||
@ -85,7 +84,7 @@ public class ItemCreation {
|
|||||||
if (matraw.split("\\s")[0].equalsIgnoreCase("cps=") || matraw.split("\\s")[0].toLowerCase().equals("cpo=")) {
|
if (matraw.split("\\s")[0].equalsIgnoreCase("cps=") || matraw.split("\\s")[0].toLowerCase().equals("cpo=")) {
|
||||||
skullname = p.getUniqueId().toString();
|
skullname = p.getUniqueId().toString();
|
||||||
mat = plugin.getHeads.playerHeadString();
|
mat = plugin.getHeads.playerHeadString();
|
||||||
if(plugin.legacy.LOCAL_VERSION.lessThanOrEqualTo(MinecraftVersions.v1_12)){
|
if(plugin.legacy.MAJOR_VERSION.lessThanOrEqualTo(MinecraftVersions.v1_12)){
|
||||||
id = 3;
|
id = 3;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -93,11 +92,55 @@ public class ItemCreation {
|
|||||||
if (matraw.split("\\s")[0].equalsIgnoreCase("hdb=")) {
|
if (matraw.split("\\s")[0].equalsIgnoreCase("hdb=")) {
|
||||||
skullname = "hdb";
|
skullname = "hdb";
|
||||||
mat = plugin.getHeads.playerHeadString();
|
mat = plugin.getHeads.playerHeadString();
|
||||||
if(plugin.legacy.LOCAL_VERSION.lessThanOrEqualTo(MinecraftVersions.v1_12)){
|
if(plugin.legacy.MAJOR_VERSION.lessThanOrEqualTo(MinecraftVersions.v1_12)){
|
||||||
id = 3;
|
id = 3;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Oraxen support, uses itemID (eg, oraxen= coin)
|
||||||
|
if (matraw.split("\\s")[0].equalsIgnoreCase("oraxen=")) {
|
||||||
|
String itemID = matraw.split("\\s")[1];
|
||||||
|
try {
|
||||||
|
// Load the OraxenItems class
|
||||||
|
Class<?> oraxenItemsClass = Class.forName("io.th0rgal.oraxen.api.OraxenItems");
|
||||||
|
|
||||||
|
// Retrieve the 'getItemById' method from the OraxenItems class
|
||||||
|
Method getItemByIdMethod = oraxenItemsClass.getMethod("getItemById", String.class);
|
||||||
|
getItemByIdMethod.setAccessible(true);
|
||||||
|
|
||||||
|
// Invoke the 'getItemById' method with the itemID
|
||||||
|
Object oraxenItem = getItemByIdMethod.invoke(null, itemID); // static method, so pass 'null'
|
||||||
|
|
||||||
|
// Ensure that the method returned a valid Oraxen item
|
||||||
|
if (oraxenItem != null) {
|
||||||
|
// Now we need to invoke 'getReferenceClone' on the OraxenItem object
|
||||||
|
Method getReferenceCloneMethod = oraxenItem.getClass().getMethod("getReferenceClone");
|
||||||
|
getReferenceCloneMethod.setAccessible(true);
|
||||||
|
ItemStack stack = (ItemStack) getReferenceCloneMethod.invoke(oraxenItem);
|
||||||
|
|
||||||
|
// Check if stack is not null
|
||||||
|
if (stack != null) {
|
||||||
|
s = stack;
|
||||||
|
normalCreation = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
plugin.debug(e, null);
|
||||||
|
// Handle the error or inform the player
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//ItemsAdder support, needs namespaceID (eg, itemsadder= money:coin)
|
||||||
|
if (matraw.split("\\s")[0].equalsIgnoreCase("itemsadder=")) {
|
||||||
|
String namespaceID = matraw.split("\\s")[1];
|
||||||
|
CustomStack stack = CustomStack.getInstance(namespaceID);
|
||||||
|
if(stack != null) {
|
||||||
|
s = stack.getItemStack().clone();
|
||||||
|
normalCreation = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//creates custom MMOItems items
|
//creates custom MMOItems items
|
||||||
if(matraw.split("\\s")[0].equalsIgnoreCase("mmo=") && plugin.getServer().getPluginManager().isPluginEnabled("MMOItems")){
|
if(matraw.split("\\s")[0].equalsIgnoreCase("mmo=") && plugin.getServer().getPluginManager().isPluginEnabled("MMOItems")){
|
||||||
String itemType = matraw.split("\\s")[1];
|
String itemType = matraw.split("\\s")[1];
|
||||||
@ -123,7 +166,7 @@ public class ItemCreation {
|
|||||||
|
|
||||||
//creates item from custom-items section of panel
|
//creates item from custom-items section of panel
|
||||||
if(matraw.split("\\s")[0].equalsIgnoreCase("cpi=")){
|
if(matraw.split("\\s")[0].equalsIgnoreCase("cpi=")){
|
||||||
s = makeCustomItemFromConfig(panel,position,panel.getConfig().getConfigurationSection("custom-item." + matraw.split("\\s")[1]), p, true, true, true);
|
s = makeCustomItemFromConfig(panel,position,panel.getConfig().getConfigurationSection("custom-item." + matraw.split("\\s")[1]), p, true, true, false);
|
||||||
normalCreation = false;
|
normalCreation = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -137,7 +180,7 @@ public class ItemCreation {
|
|||||||
if (matraw.split("\\s")[1].equalsIgnoreCase("self")) {
|
if (matraw.split("\\s")[1].equalsIgnoreCase("self")) {
|
||||||
//if cps= self
|
//if cps= self
|
||||||
meta = (SkullMeta) s.getItemMeta();
|
meta = (SkullMeta) s.getItemMeta();
|
||||||
if(!plugin.legacy.LOCAL_VERSION.lessThanOrEqualTo(MinecraftVersions.v1_12)) {
|
if(!plugin.legacy.MAJOR_VERSION.lessThanOrEqualTo(MinecraftVersions.v1_12)) {
|
||||||
try {
|
try {
|
||||||
assert meta != null;
|
assert meta != null;
|
||||||
meta.setOwningPlayer(Bukkit.getOfflinePlayer(UUID.fromString(skullname)));
|
meta.setOwningPlayer(Bukkit.getOfflinePlayer(UUID.fromString(skullname)));
|
||||||
@ -187,24 +230,22 @@ public class ItemCreation {
|
|||||||
if(itemSection.contains("itemType")){
|
if(itemSection.contains("itemType")){
|
||||||
//if hidden, reverse
|
//if hidden, reverse
|
||||||
if(itemSection.getStringList("itemType").contains("noAttributes")){
|
if(itemSection.getStringList("itemType").contains("noAttributes")){
|
||||||
hideAttributes = false;
|
hideAttributes = true;
|
||||||
}
|
|
||||||
if(itemSection.getStringList("itemType").contains("noNBT")){
|
|
||||||
addNBT = false;
|
|
||||||
}
|
}
|
||||||
if(itemSection.getStringList("itemType").contains("placeable")){
|
if(itemSection.getStringList("itemType").contains("placeable")){
|
||||||
addNBT = false;
|
addNBT = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(addNBT && itemSection.contains("nbt")){
|
if(itemSection.contains("nbt")){
|
||||||
for(String key : Objects.requireNonNull(itemSection.getConfigurationSection("nbt")).getKeys(true)){
|
//ItemStack item, ConfigurationSection section, Player player, Panel panel, PanelPosition position
|
||||||
if(itemSection.isConfigurationSection("nbt." + key)){
|
plugin.nbt.applyNBTRecursively(s, itemSection.getConfigurationSection("nbt"), p, panel, position);
|
||||||
continue;
|
//plugin.nbt.applyNBTRecursively("", itemSection.getConfigurationSection("nbt"), s, p, panel, position);
|
||||||
}
|
|
||||||
s = plugin.nbt.setNBT(s,key,plugin.tex.attachPlaceholders(panel, position, p, Objects.requireNonNull(itemSection.getString("nbt." + key)))); //itemSection.getString("nbt." + key));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
if(addNBT){
|
||||||
|
plugin.nbt.setNBT(s, "CommandPanelsItem","boolean_" + "true");
|
||||||
|
}
|
||||||
|
|
||||||
if (itemSection.contains("enchanted")) {
|
if (itemSection.contains("enchanted")) {
|
||||||
try {
|
try {
|
||||||
ItemMeta EnchantMeta;
|
ItemMeta EnchantMeta;
|
||||||
@ -285,37 +326,46 @@ public class ItemCreation {
|
|||||||
|
|
||||||
if (itemSection.contains("potion")) {
|
if (itemSection.contains("potion")) {
|
||||||
//if the item is a potion, give it an effect
|
//if the item is a potion, give it an effect
|
||||||
try {
|
String[] effectType = plugin.tex.placeholdersNoColour(panel,position,p,itemSection.getString("potion")).split("\\s");
|
||||||
PotionMeta potionMeta = (PotionMeta)s.getItemMeta();
|
//potion legacy or current
|
||||||
String[] effectType = plugin.tex.placeholdersNoColour(panel,position,p,itemSection.getString("potion")).split("\\s");
|
if(plugin.legacy.MAJOR_VERSION.lessThanOrEqualTo(MinecraftVersions.v1_19) ||
|
||||||
assert potionMeta != null;
|
(plugin.legacy.MAJOR_VERSION == MinecraftVersions.v1_20 && plugin.legacy.MINOR_VERSION <= 4)){
|
||||||
boolean extended = false;
|
if(plugin.legacy.MAJOR_VERSION.equals(MinecraftVersions.v1_8)){
|
||||||
boolean upgraded = false;
|
plugin.classicPotion.applyPotionEffect(p, s, effectType);
|
||||||
//create data
|
}else {
|
||||||
if(effectType.length >= 2){
|
plugin.legacyPotion.applyPotionEffect(p, s, effectType);
|
||||||
if(effectType[1].equalsIgnoreCase("true")){
|
}
|
||||||
extended = true;
|
}else{
|
||||||
}
|
try {
|
||||||
if(effectType.length == 3){
|
PotionMeta potionMeta = (PotionMeta)s.getItemMeta();
|
||||||
if(effectType[2].equalsIgnoreCase("true")){
|
assert potionMeta != null;
|
||||||
upgraded = true;
|
PotionType newData = PotionType.valueOf(effectType[0].toUpperCase());
|
||||||
}
|
//set meta
|
||||||
}
|
potionMeta.setBasePotionType(newData);
|
||||||
|
s.setItemMeta(potionMeta);
|
||||||
|
} catch (Exception er) {
|
||||||
|
//don't add the effect
|
||||||
|
plugin.debug(er,p);
|
||||||
|
p.sendMessage(plugin.tex.colour(plugin.tag + ChatColor.RED + plugin.config.getString("config.format.error") + " potion: " + itemSection.getString("potion")));
|
||||||
}
|
}
|
||||||
PotionData newData = new PotionData(PotionType.valueOf(effectType[0].toUpperCase()),extended,upgraded);
|
|
||||||
//set meta
|
|
||||||
potionMeta.setBasePotionData(newData);
|
|
||||||
s.setItemMeta(potionMeta);
|
|
||||||
} catch (Exception er) {
|
|
||||||
//don't add the effect
|
|
||||||
plugin.debug(er,p);
|
|
||||||
p.sendMessage(plugin.tex.colour(plugin.tag + ChatColor.RED + plugin.config.getString("config.format.error") + " potion: " + itemSection.getString("potion")));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(itemSection.contains("potion-color")){
|
||||||
|
if(plugin.legacy.MAJOR_VERSION.greaterThanOrEqualTo(MinecraftVersions.v1_11)){
|
||||||
|
String[] rgb = Objects.requireNonNull(itemSection.getString("potion-color")).split(",");
|
||||||
|
Color color = Color.fromRGB(Integer.parseInt(rgb[0]), Integer.parseInt(rgb[1]), Integer.parseInt(rgb[2]));
|
||||||
|
PotionMeta potionMeta = (PotionMeta)s.getItemMeta();
|
||||||
|
assert potionMeta != null;
|
||||||
|
potionMeta.setColor(color);
|
||||||
|
s.setItemMeta(potionMeta);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (itemSection.contains("damage")) {
|
if (itemSection.contains("damage")) {
|
||||||
//change the damage amount (placeholders accepted)
|
//change the damage amount (placeholders accepted)
|
||||||
//if the damage is not unbreakable and should be a value
|
//if the damage is not unbreakable and should be a value
|
||||||
if (plugin.legacy.LOCAL_VERSION.lessThanOrEqualTo(MinecraftVersions.v1_12)) {
|
if (plugin.legacy.MAJOR_VERSION.lessThanOrEqualTo(MinecraftVersions.v1_12)) {
|
||||||
try {
|
try {
|
||||||
s.setDurability(Short.parseShort(Objects.requireNonNull(plugin.tex.placeholders(panel,position,p, itemSection.getString("damage")))));
|
s.setDurability(Short.parseShort(Objects.requireNonNull(plugin.tex.placeholders(panel,position,p, itemSection.getString("damage")))));
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
@ -328,28 +378,20 @@ public class ItemCreation {
|
|||||||
ItemMeta unbreak = s.getItemMeta();
|
ItemMeta unbreak = s.getItemMeta();
|
||||||
unbreak.setUnbreakable(true);
|
unbreak.setUnbreakable(true);
|
||||||
s.setItemMeta(unbreak);
|
s.setItemMeta(unbreak);
|
||||||
|
}else {
|
||||||
|
try {
|
||||||
|
Damageable itemDamage = (Damageable) s.getItemMeta();
|
||||||
|
itemDamage.setDamage(Integer.parseInt(Objects.requireNonNull(plugin.tex.placeholders(panel, position, p, itemSection.getString("damage")))));
|
||||||
|
s.setItemMeta((ItemMeta) itemDamage);
|
||||||
|
} catch (Exception e) {
|
||||||
|
plugin.debug(e, p);
|
||||||
|
p.sendMessage(plugin.tex.colour(plugin.tag + plugin.config.getString("config.format.error") + " damage: " + itemSection.getString("damage")));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
|
||||||
Damageable itemDamage = (Damageable) s.getItemMeta();
|
|
||||||
itemDamage.setDamage(Integer.parseInt(Objects.requireNonNull(plugin.tex.placeholders(panel,position,p, itemSection.getString("damage")))));
|
|
||||||
s.setItemMeta((ItemMeta) itemDamage);
|
|
||||||
} catch (Exception e) {
|
|
||||||
plugin.debug(e, p);
|
|
||||||
p.sendMessage(plugin.tex.colour(plugin.tag + plugin.config.getString("config.format.error") + " damage: " + itemSection.getString("damage")));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (itemSection.contains("nbt")) {
|
|
||||||
for(String key : Objects.requireNonNull(itemSection.getConfigurationSection("nbt")).getKeys(true)){
|
|
||||||
if(itemSection.isConfigurationSection("nbt." + key)){
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
s = plugin.nbt.setNBT(s,key,plugin.tex.attachPlaceholders(panel, position, p, Objects.requireNonNull(itemSection.getString("nbt." + key)))); //itemSection.getString("nbt." + key));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// 1.20 Trim Feature for Player Armor
|
// 1.20 Trim Feature for Player Armor
|
||||||
if(plugin.legacy.LOCAL_VERSION.greaterThanOrEqualTo(MinecraftVersions.v1_20) && itemSection.contains("trim")){
|
if(plugin.legacy.MAJOR_VERSION.greaterThanOrEqualTo(MinecraftVersions.v1_20) && itemSection.contains("trim")){
|
||||||
// trim: <Material> <Pattern>
|
// trim: <Material> <Pattern>
|
||||||
String trim = itemSection.getString("trim");
|
String trim = itemSection.getString("trim");
|
||||||
String[] trimList = trim.split("\\s");
|
String[] trimList = trim.split("\\s");
|
||||||
@ -379,7 +421,7 @@ public class ItemCreation {
|
|||||||
//check that the panel is already open and not running commands when opening
|
//check that the panel is already open and not running commands when opening
|
||||||
if (itemSection.contains("refresh-commands") && plugin.openPanels.hasPanelOpen(p.getName(), panel.getName(), position)) {
|
if (itemSection.contains("refresh-commands") && plugin.openPanels.hasPanelOpen(p.getName(), panel.getName(), position)) {
|
||||||
try {
|
try {
|
||||||
plugin.commandTags.runCommands(panel,position,p,itemSection.getStringList("refresh-commands"));
|
plugin.commandRunner.runCommands(panel,position,p,itemSection.getStringList("refresh-commands"), null);
|
||||||
}catch(Exception ex){
|
}catch(Exception ex){
|
||||||
plugin.debug(ex,p);
|
plugin.debug(ex,p);
|
||||||
}
|
}
|
||||||
@ -389,7 +431,7 @@ public class ItemCreation {
|
|||||||
p.sendMessage(plugin.tex.colour(plugin.tag + plugin.config.getString("config.format.error") + " material: " + itemSection.getString("material")));
|
p.sendMessage(plugin.tex.colour(plugin.tag + plugin.config.getString("config.format.error") + " material: " + itemSection.getString("material")));
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
plugin.setName(panel,s, itemSection.getString("name"), itemSection.getStringList("lore"), p, placeholders, colours, hideAttributes);
|
s = plugin.setName(panel,s, itemSection.getString("name"), itemSection.getStringList("lore"), p, placeholders, colours, hideAttributes);
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -420,7 +462,7 @@ public class ItemCreation {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(plugin.legacy.LOCAL_VERSION.lessThanOrEqualTo(MinecraftVersions.v1_12)){
|
if(plugin.legacy.MAJOR_VERSION.lessThanOrEqualTo(MinecraftVersions.v1_12)){
|
||||||
if (cont.getDurability() != 0 && !cont.getType().toString().equals("SKULL_ITEM")) {
|
if (cont.getDurability() != 0 && !cont.getType().toString().equals("SKULL_ITEM")) {
|
||||||
file.set("panels." + panelName + ".item." + i + ".ID", cont.getDurability());
|
file.set("panels." + panelName + ".item." + i + ".ID", cont.getDurability());
|
||||||
}
|
}
|
||||||
@ -438,14 +480,7 @@ public class ItemCreation {
|
|||||||
}
|
}
|
||||||
if(plugin.getHeads.ifSkullOrHead(cont.getType().toString())){
|
if(plugin.getHeads.ifSkullOrHead(cont.getType().toString())){
|
||||||
if(!Objects.requireNonNull(file.getString("panels." + panelName + ".item." + i + ".material")).contains("%") && !Objects.requireNonNull(file.getString("panels." + panelName + ".item." + i + ".material")).contains("=")) {
|
if(!Objects.requireNonNull(file.getString("panels." + panelName + ".item." + i + ".material")).contains("%") && !Objects.requireNonNull(file.getString("panels." + panelName + ".item." + i + ".material")).contains("=")) {
|
||||||
SkullMeta meta = (SkullMeta) cont.getItemMeta();
|
file.set("panels." + panelName + ".item." + i + ".material", plugin.getHeads.playerHeadString());
|
||||||
if (plugin.customHeads.getHeadBase64(cont) != null && !plugin.legacy.LOCAL_VERSION.lessThanOrEqualTo(MinecraftVersions.v1_12)) {
|
|
||||||
//inject base64 here, disable for legacy as is not working
|
|
||||||
file.set("panels." + panelName + ".item." + i + ".material", "cps= " + plugin.customHeads.getHeadBase64(cont));
|
|
||||||
} else if (meta.hasOwner()) {
|
|
||||||
//check for skull owner
|
|
||||||
file.set("panels." + panelName + ".item." + i + ".material", "cps= " + meta.getOwner());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
@ -460,13 +495,18 @@ public class ItemCreation {
|
|||||||
file.set("panels." + panelName + ".item." + i + ".banner", null);
|
file.set("panels." + panelName + ".item." + i + ".banner", null);
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
PotionMeta potionMeta = (PotionMeta) cont.getItemMeta();
|
//potion legacy PotionData or current PotionType
|
||||||
assert potionMeta != null;
|
if(plugin.legacy.MAJOR_VERSION.lessThanOrEqualTo(MinecraftVersions.v1_19) ||
|
||||||
PotionData potionData = potionMeta.getBasePotionData();
|
(plugin.legacy.MAJOR_VERSION == MinecraftVersions.v1_20 && plugin.legacy.MINOR_VERSION <= 4)){
|
||||||
PotionType potionType = potionData.getType(); // Gets the potion type as a string rather than bukkit type
|
if(plugin.legacyPotion.retrievePotionData(cont) != null) {
|
||||||
boolean level = potionData.isUpgraded(); // Check if the potion is level II
|
file.set("panels." + panelName + ".item." + i + ".potion", plugin.legacyPotion.retrievePotionData(cont));
|
||||||
boolean extended = potionData.isExtended(); // Check if the potion is extended
|
}
|
||||||
file.set("panels." + panelName + ".item." + i + ".potion", potionType + " " + extended + " " + level);
|
}else{
|
||||||
|
PotionMeta potionMeta = (PotionMeta) cont.getItemMeta();
|
||||||
|
assert potionMeta != null;
|
||||||
|
String potionType = potionMeta.getBasePotionType().toString(); // Gets the potion type as a string rather than bukkit type
|
||||||
|
file.set("panels." + panelName + ".item." + i + ".potion", potionType);
|
||||||
|
}
|
||||||
}catch(Exception ignore){
|
}catch(Exception ignore){
|
||||||
//not a banner
|
//not a banner
|
||||||
file.set("panels." + panelName + ".item." + i + ".potion", null);
|
file.set("panels." + panelName + ".item." + i + ".potion", null);
|
||||||
@ -482,16 +522,9 @@ public class ItemCreation {
|
|||||||
}
|
}
|
||||||
file.set("panels." + panelName + ".item." + i + ".name", Objects.requireNonNull(cont.getItemMeta()).getDisplayName());
|
file.set("panels." + panelName + ".item." + i + ".name", Objects.requireNonNull(cont.getItemMeta()).getDisplayName());
|
||||||
file.set("panels." + panelName + ".item." + i + ".lore", Objects.requireNonNull(cont.getItemMeta()).getLore());
|
file.set("panels." + panelName + ".item." + i + ".lore", Objects.requireNonNull(cont.getItemMeta()).getLore());
|
||||||
if(plugin.legacy.LOCAL_VERSION.greaterThanOrEqualTo(MinecraftVersions.v1_14)){
|
if(plugin.legacy.MAJOR_VERSION.greaterThanOrEqualTo(MinecraftVersions.v1_14)){
|
||||||
file.set("panels." + panelName + ".item." + i + ".customdata", Objects.requireNonNull(cont.getItemMeta()).getCustomModelData());
|
file.set("panels." + panelName + ".item." + i + ".customdata", Objects.requireNonNull(cont.getItemMeta()).getCustomModelData());
|
||||||
}
|
}
|
||||||
// try {
|
|
||||||
// ReadWriteNBT nbt = NBT.itemStackToNBT(cont);
|
|
||||||
// file.set("panels." + panelName + ".item." + i + ".nbt", nbt.toString());
|
|
||||||
// }catch(Exception ignore){
|
|
||||||
// //no nbt or error
|
|
||||||
// file.set("panels." + panelName + ".item." + i + ".nbt", null);
|
|
||||||
// }
|
|
||||||
}catch(Exception n){
|
}catch(Exception n){
|
||||||
//skip over an item that spits an error
|
//skip over an item that spits an error
|
||||||
}
|
}
|
||||||
@ -521,6 +554,13 @@ public class ItemCreation {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}catch(Exception ignore){}
|
}catch(Exception ignore){}
|
||||||
|
//check for ID 1.12.2 and below
|
||||||
|
try {
|
||||||
|
if (plugin.legacy.MAJOR_VERSION.lessThanOrEqualTo(MinecraftVersions.v1_12) &&
|
||||||
|
(one.getDurability() != two.getDurability())) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}catch(Exception ignore){}
|
||||||
//check for lore
|
//check for lore
|
||||||
try {
|
try {
|
||||||
if (!one.getItemMeta().getLore().equals(two.getItemMeta().getLore())) {
|
if (!one.getItemMeta().getLore().equals(two.getItemMeta().getLore())) {
|
||||||
@ -529,20 +569,27 @@ public class ItemCreation {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}catch(Exception ignore){}
|
}catch(Exception ignore){}
|
||||||
|
//check for custom model data
|
||||||
|
try {
|
||||||
|
if (plugin.legacy.MAJOR_VERSION.greaterThanOrEqualTo(MinecraftVersions.v1_14)){
|
||||||
|
if (one.getItemMeta().getCustomModelData() != (two.getItemMeta().getCustomModelData())) {
|
||||||
|
if(one.getItemMeta().hasCustomModelData()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}catch(Exception ignore){}
|
||||||
//check for nbt
|
//check for nbt
|
||||||
if(nbtCheck) {
|
if(nbtCheck) {
|
||||||
try {
|
try {
|
||||||
NBTItem nbtitem1 = new NBTItem(one);
|
if (!plugin.nbt.hasSameNBT(one, two)) {
|
||||||
NBTItem nbtitem2 = new NBTItem(two);
|
|
||||||
|
|
||||||
if (!nbtitem1.equals(nbtitem2)) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} catch (Exception ignore) {}
|
} catch (Exception ignore) {}
|
||||||
}
|
}
|
||||||
//check for damage
|
//check for damage
|
||||||
try {
|
try {
|
||||||
if(plugin.legacy.LOCAL_VERSION.lessThanOrEqualTo(MinecraftVersions.v1_12)){
|
if(plugin.legacy.MAJOR_VERSION.lessThanOrEqualTo(MinecraftVersions.v1_12)){
|
||||||
if(one.getDurability() != two.getDurability()) {
|
if(one.getDurability() != two.getDurability()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -556,19 +603,21 @@ public class ItemCreation {
|
|||||||
} catch (Exception ignore) {}
|
} catch (Exception ignore) {}
|
||||||
//check for potions
|
//check for potions
|
||||||
try {
|
try {
|
||||||
PotionMeta meta1 = (PotionMeta) one.getItemMeta();
|
//choose between legacy PotionData (pre 1.20.5) or PotionType
|
||||||
PotionMeta meta2 = (PotionMeta) two.getItemMeta();
|
if(plugin.legacy.MAJOR_VERSION.lessThanOrEqualTo(MinecraftVersions.v1_19) ||
|
||||||
//different duration
|
(plugin.legacy.MAJOR_VERSION == MinecraftVersions.v1_20 && plugin.legacy.MINOR_VERSION <= 4)){
|
||||||
if(meta1.getBasePotionData().isExtended() != meta2.getBasePotionData().isExtended()){
|
String potionOne = plugin.legacyPotion.retrievePotionData(one);
|
||||||
return false;
|
String potionTwo = plugin.legacyPotion.retrievePotionData(two);
|
||||||
}
|
if(!potionOne.equals(potionTwo)){
|
||||||
//different upgrade
|
return false;
|
||||||
if(meta1.getBasePotionData().isUpgraded() != meta2.getBasePotionData().isUpgraded()){
|
}
|
||||||
return false;
|
}else{
|
||||||
}
|
//post 1.20.5 compare
|
||||||
//different potion type
|
PotionMeta meta1 = (PotionMeta) one.getItemMeta();
|
||||||
if (meta1.getBasePotionData().getType().compareTo(meta2.getBasePotionData().getType()) != 0){
|
PotionMeta meta2 = (PotionMeta) two.getItemMeta();
|
||||||
return false;
|
if (meta1.getBasePotionType().toString().compareTo(meta2.getBasePotionType().toString()) != 0){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}catch(Exception ignore){}
|
}catch(Exception ignore){}
|
||||||
//check for enchantments
|
//check for enchantments
|
||||||
|
@ -0,0 +1,60 @@
|
|||||||
|
package me.rockyhawk.commandpanels.classresources;
|
||||||
|
|
||||||
|
import me.rockyhawk.commandpanels.CommandPanels;
|
||||||
|
import net.kyori.adventure.text.Component;
|
||||||
|
import net.kyori.adventure.text.format.TextDecoration;
|
||||||
|
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||||
|
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
public class MiniMessageUtils {
|
||||||
|
|
||||||
|
CommandPanels plugin;
|
||||||
|
public MiniMessageUtils(CommandPanels pl) {
|
||||||
|
this.plugin = pl;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
MiniMessage is used here as an alternative to the standard Minecraft colour codes &
|
||||||
|
As MiniMessage does not accept legacy colour codes at any point, which is
|
||||||
|
a possibility when using Minecraft colour codes, running a try/catch allows for
|
||||||
|
MiniMessage to be used anywhere and ignored when legacy colour codes are found.
|
||||||
|
*/
|
||||||
|
|
||||||
|
public String doMiniMessageLegacy(String string) {
|
||||||
|
MiniMessage miniMessage = MiniMessage.miniMessage();
|
||||||
|
try {
|
||||||
|
Component component = miniMessage.deserialize(string);
|
||||||
|
return LegacyComponentSerializer.builder()
|
||||||
|
.character('&')
|
||||||
|
.hexColors()
|
||||||
|
.build()
|
||||||
|
.serialize(component);
|
||||||
|
}catch (Exception e){
|
||||||
|
return string;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<String> doMiniMessageLegacy(List<String> strings) {
|
||||||
|
return strings.stream()
|
||||||
|
.map(this::doMiniMessageLegacy)
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
|
public Component doMiniMessage(String string) {
|
||||||
|
LegacyComponentSerializer legacyComponentSerializer = LegacyComponentSerializer.builder().hexColors().character('&').build();
|
||||||
|
Component component = legacyComponentSerializer.deserialize(string.replace('§', '&'));
|
||||||
|
|
||||||
|
return MiniMessage.miniMessage().deserialize(MiniMessage.miniMessage().serialize(component.decoration(TextDecoration.ITALIC, false))
|
||||||
|
.replace("\\<", "<").replace("\\", "").replace("\n", "<br>")).decoration(TextDecoration.ITALIC, false);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Component> doMiniMessage(List<String> strings) {
|
||||||
|
return strings.stream()
|
||||||
|
.map(this::doMiniMessage)
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
}
|
@ -1,11 +0,0 @@
|
|||||||
package me.rockyhawk.commandpanels.classresources;
|
|
||||||
|
|
||||||
import net.kyori.adventure.text.Component;
|
|
||||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
|
||||||
|
|
||||||
public class SerializerUtils {
|
|
||||||
|
|
||||||
public static Component serializeText(String msg){
|
|
||||||
return MiniMessage.miniMessage().deserialize(msg);
|
|
||||||
}
|
|
||||||
}
|
|
@ -0,0 +1,34 @@
|
|||||||
|
package me.rockyhawk.commandpanels.classresources.customheads;
|
||||||
|
|
||||||
|
import me.rockyhawk.commandpanels.CommandPanels;
|
||||||
|
import me.rockyhawk.commandpanels.classresources.customheads.methods.CustomHeadGameProfile;
|
||||||
|
import me.rockyhawk.commandpanels.classresources.customheads.methods.CustomHeadPlayerProfile;
|
||||||
|
import me.rockyhawk.commandpanels.ioclasses.legacy.MinecraftVersions;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
|
public class GetCustomHeads {
|
||||||
|
CustomHeadGameProfile gameProfileHeadClass;
|
||||||
|
CustomHeadPlayerProfile playerProfileHeadClass;
|
||||||
|
CommandPanels plugin;
|
||||||
|
|
||||||
|
public GetCustomHeads(CommandPanels pl) {
|
||||||
|
this.plugin = pl;
|
||||||
|
gameProfileHeadClass = new CustomHeadGameProfile(pl);
|
||||||
|
playerProfileHeadClass = new CustomHeadPlayerProfile();
|
||||||
|
}
|
||||||
|
|
||||||
|
public ItemStack getCustomHead(String base64){
|
||||||
|
if(plugin.legacy.MAJOR_VERSION.greaterThanOrEqualTo(MinecraftVersions.v1_18)){
|
||||||
|
return playerProfileHeadClass.getCustomHead(base64);
|
||||||
|
}else{
|
||||||
|
return gameProfileHeadClass.getCustomHead(base64);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public ItemStack getPlayerHead(String playerName){
|
||||||
|
if(plugin.legacy.MAJOR_VERSION.greaterThanOrEqualTo(MinecraftVersions.v1_21)){
|
||||||
|
return playerProfileHeadClass.getPlayerHead(playerName);
|
||||||
|
}else{
|
||||||
|
return gameProfileHeadClass.getPlayerHead(playerName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,17 @@
|
|||||||
|
package me.rockyhawk.commandpanels.classresources.customheads;
|
||||||
|
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
|
public class SavedCustomHead {
|
||||||
|
public String base64;
|
||||||
|
public ItemStack headItem;
|
||||||
|
public boolean isValid; // true if the head was successfully fetched, false otherwise
|
||||||
|
public long lastAttempt; // timestamp of the last attempt
|
||||||
|
|
||||||
|
public SavedCustomHead(ItemStack head, String base64value, boolean isValidAttempt) {
|
||||||
|
base64 = base64value;
|
||||||
|
headItem = head;
|
||||||
|
isValid = isValidAttempt;
|
||||||
|
lastAttempt = System.currentTimeMillis();
|
||||||
|
}
|
||||||
|
}
|
@ -1,9 +1,10 @@
|
|||||||
package me.rockyhawk.commandpanels.classresources;
|
package me.rockyhawk.commandpanels.classresources.customheads.methods;
|
||||||
|
|
||||||
import com.mojang.authlib.GameProfile;
|
import com.mojang.authlib.GameProfile;
|
||||||
import com.mojang.authlib.properties.Property;
|
import com.mojang.authlib.properties.Property;
|
||||||
import com.mojang.authlib.properties.PropertyMap;
|
import com.mojang.authlib.properties.PropertyMap;
|
||||||
import me.rockyhawk.commandpanels.CommandPanels;
|
import me.rockyhawk.commandpanels.CommandPanels;
|
||||||
|
import me.rockyhawk.commandpanels.classresources.customheads.SavedCustomHead;
|
||||||
import me.rockyhawk.commandpanels.ioclasses.legacy.MinecraftVersions;
|
import me.rockyhawk.commandpanels.ioclasses.legacy.MinecraftVersions;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
@ -17,68 +18,32 @@ import java.lang.reflect.Method;
|
|||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.net.URLConnection;
|
import java.net.URLConnection;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.HashMap;
|
import java.util.*;
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.Scanner;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
public class GetCustomHeads {
|
public class CustomHeadGameProfile {
|
||||||
CommandPanels plugin;
|
CommandPanels plugin;
|
||||||
public GetCustomHeads(CommandPanels pl) {
|
public CustomHeadGameProfile(CommandPanels pl) {
|
||||||
this.plugin = pl;
|
this.plugin = pl;
|
||||||
}
|
}
|
||||||
|
|
||||||
//will not go above 2000 elements in the list which is roughly 270 KB RAM usage
|
public HashMap<String, SavedCustomHead> savedCustomHeads = new HashMap<>();
|
||||||
public HashMap<String, String> playerHeadTextures = new HashMap<>();
|
|
||||||
|
|
||||||
public String getHeadBase64(ItemStack head) {
|
|
||||||
if (plugin.getHeads.ifSkullOrHead(head.getType().toString()) && head.hasItemMeta()) {
|
|
||||||
try {
|
|
||||||
SkullMeta meta = (SkullMeta) head.getItemMeta();
|
|
||||||
assert meta != null;
|
|
||||||
if (!meta.hasOwner()) {
|
|
||||||
Field fld = meta.getClass().getDeclaredField("profile");
|
|
||||||
fld.setAccessible(true);
|
|
||||||
GameProfile prof = (GameProfile) fld.get(meta);
|
|
||||||
Iterator itr = prof.getProperties().get("textures").iterator();
|
|
||||||
if (itr.hasNext()) {
|
|
||||||
Property var5 = (Property) itr.next();
|
|
||||||
return var5.getValue();
|
|
||||||
}
|
|
||||||
}else{
|
|
||||||
Field fld = meta.getClass().getDeclaredField("profile");
|
|
||||||
fld.setAccessible(true);
|
|
||||||
GameProfile prof = (GameProfile) fld.get(meta);
|
|
||||||
Iterator itr = prof.getProperties().get("textures").iterator();
|
|
||||||
if (itr.hasNext()) {
|
|
||||||
Property var5 = (Property) itr.next();
|
|
||||||
String var5string = var5.toString();
|
|
||||||
var5string = var5string.replace("Property[","");
|
|
||||||
var5string = var5string.replace("]","");
|
|
||||||
String[] var5strings = var5string.split(",");
|
|
||||||
for(String var : var5strings){
|
|
||||||
if(var.contains("value= ")){
|
|
||||||
var = var.replace("value= ", "");
|
|
||||||
return var;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}catch(Exception exc){/*skip return null*/}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
//getting the head from a Player Name
|
//getting the head from a Player Name
|
||||||
public ItemStack getPlayerHead(String name) {
|
public ItemStack getPlayerHead(String name) {
|
||||||
byte id = 0;
|
byte id = 0;
|
||||||
if (plugin.legacy.LOCAL_VERSION.lessThanOrEqualTo(MinecraftVersions.v1_15)) {
|
if (plugin.legacy.MAJOR_VERSION.lessThanOrEqualTo(MinecraftVersions.v1_15)) {
|
||||||
id = 3;
|
id = 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
//get texture if already cached
|
//get texture if already cached
|
||||||
if(playerHeadTextures.containsKey(name)) {
|
if (savedCustomHeads.containsKey(name)) {
|
||||||
return getCustomHead(playerHeadTextures.get(name));
|
if (!savedCustomHeads.get(name).isValid && (System.currentTimeMillis() - savedCustomHeads.get(name).lastAttempt) < 60000) {
|
||||||
|
// If the last attempt was less than 60 seconds ago and was invalid, return null or a default item
|
||||||
|
return new ItemStack(Material.valueOf(plugin.getHeads.playerHeadString()));
|
||||||
|
}
|
||||||
|
if(savedCustomHeads.get(name).isValid) {
|
||||||
|
return savedCustomHeads.get(name).headItem; // Return cached item if valid
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//create ItemStack
|
//create ItemStack
|
||||||
@ -95,7 +60,7 @@ public class GetCustomHeads {
|
|||||||
if(plugin.debug.consoleDebug){
|
if(plugin.debug.consoleDebug){
|
||||||
plugin.getServer().getConsoleSender().sendMessage(plugin.tex.colour(plugin.tag +
|
plugin.getServer().getConsoleSender().sendMessage(plugin.tex.colour(plugin.tag +
|
||||||
ChatColor.WHITE +
|
ChatColor.WHITE +
|
||||||
"Attempting to Download & Cache Head Texture for " + name));
|
"Download & Cache Head Texture for " + name));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fetch the player UUID from the Mojang API
|
// Fetch the player UUID from the Mojang API
|
||||||
@ -117,23 +82,47 @@ public class GetCustomHeads {
|
|||||||
String valueReader = new Scanner(texturesConnection.getInputStream(),
|
String valueReader = new Scanner(texturesConnection.getInputStream(),
|
||||||
StandardCharsets.UTF_8.name()).useDelimiter("\\A").next();
|
StandardCharsets.UTF_8.name()).useDelimiter("\\A").next();
|
||||||
String value = valueReader.split("\"value\" : \"")[1].split("\"")[0];
|
String value = valueReader.split("\"value\" : \"")[1].split("\"")[0];
|
||||||
playerHeadTextures.put(name, value);
|
|
||||||
|
|
||||||
// Once the API call is finished, update the ItemStack on the main thread
|
// Once the API call is finished, update the ItemStack on the main thread
|
||||||
Bukkit.getScheduler().runTask(plugin, () -> {
|
Bukkit.getScheduler().runTask(plugin, () -> {
|
||||||
itemStack.setItemMeta(getCustomHead(value).getItemMeta());
|
itemStack.setItemMeta(getCustomHead(name, value).getItemMeta());
|
||||||
|
savedCustomHeads.put(name, new SavedCustomHead(itemStack, value, true));
|
||||||
|
});
|
||||||
|
} catch (Exception ignore) {
|
||||||
|
Bukkit.getScheduler().runTask(plugin, () -> {
|
||||||
|
//do not overwrite a valid cached head
|
||||||
|
if(savedCustomHeads.containsKey(name) && savedCustomHeads.get(name).isValid){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
savedCustomHeads.put(name, new SavedCustomHead(null, null, false)); // Mark as invalid
|
||||||
});
|
});
|
||||||
} catch (Exception e) {
|
|
||||||
// Handle exceptions
|
|
||||||
if(plugin.debug.consoleDebug) {
|
|
||||||
plugin.debug(e,null);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
return itemStack;
|
return itemStack;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//will also use cached heads feature to get heads if player name is provided
|
||||||
|
public ItemStack getCustomHead(String playerName, String b64stringtexture) {
|
||||||
|
//check for any saved heads
|
||||||
|
if(savedCustomHeads.containsKey(playerName)) {
|
||||||
|
if (savedCustomHeads.get(playerName).base64 != null) {
|
||||||
|
return savedCustomHeads.get(playerName).headItem;
|
||||||
|
}
|
||||||
|
savedCustomHeads.get(playerName).isValid = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
//clear cached textures list until length limit is reached
|
||||||
|
Iterator<Map.Entry<String, SavedCustomHead>> iterator = savedCustomHeads.entrySet().iterator();
|
||||||
|
while (savedCustomHeads.size() > 2000 && iterator.hasNext()) {
|
||||||
|
iterator.next(); // Move to next entry
|
||||||
|
iterator.remove(); // Remove the entry
|
||||||
|
}
|
||||||
|
|
||||||
|
//if saved head is not found from player name, get head manually
|
||||||
|
return getCustomHead(b64stringtexture);
|
||||||
|
}
|
||||||
|
|
||||||
//used to get heads from Base64 Textures
|
//used to get heads from Base64 Textures
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
public ItemStack getCustomHead(String b64stringtexture) {
|
public ItemStack getCustomHead(String b64stringtexture) {
|
||||||
@ -145,7 +134,7 @@ public class GetCustomHeads {
|
|||||||
} else {
|
} else {
|
||||||
propertyMap.put("textures", new Property("textures", b64stringtexture));
|
propertyMap.put("textures", new Property("textures", b64stringtexture));
|
||||||
byte id = 0;
|
byte id = 0;
|
||||||
if(plugin.legacy.LOCAL_VERSION.lessThanOrEqualTo(MinecraftVersions.v1_15)){
|
if(plugin.legacy.MAJOR_VERSION.lessThanOrEqualTo(MinecraftVersions.v1_15)){
|
||||||
id = 3;
|
id = 3;
|
||||||
}
|
}
|
||||||
ItemStack head = new ItemStack(Material.matchMaterial(plugin.getHeads.playerHeadString()), 1,id);
|
ItemStack head = new ItemStack(Material.matchMaterial(plugin.getHeads.playerHeadString()), 1,id);
|
@ -0,0 +1,118 @@
|
|||||||
|
package me.rockyhawk.commandpanels.classresources.customheads.methods;
|
||||||
|
|
||||||
|
import com.google.gson.JsonObject;
|
||||||
|
import com.google.gson.JsonParser;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.OfflinePlayer;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.inventory.meta.SkullMeta;
|
||||||
|
import org.bukkit.profile.PlayerProfile;
|
||||||
|
import org.bukkit.profile.PlayerTextures;
|
||||||
|
|
||||||
|
import java.net.MalformedURLException;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
public class CustomHeadPlayerProfile {
|
||||||
|
//cached itemstacks stored for access
|
||||||
|
public HashMap<String, ItemStack> savedCustomHeads = new HashMap<>();
|
||||||
|
|
||||||
|
//Using the PlayerProfile API for getting custom heads
|
||||||
|
public ItemStack getCustomHead(String base64Texture) {
|
||||||
|
//check for any saved heads
|
||||||
|
if(savedCustomHeads.containsKey(base64Texture)) {
|
||||||
|
return savedCustomHeads.get(base64Texture);
|
||||||
|
}
|
||||||
|
|
||||||
|
//clear cached textures list until length limit is reached
|
||||||
|
Iterator<Map.Entry<String, ItemStack>> iterator = savedCustomHeads.entrySet().iterator();
|
||||||
|
while (savedCustomHeads.size() > 2000 && iterator.hasNext()) {
|
||||||
|
iterator.next(); // Move to next entry
|
||||||
|
iterator.remove(); // Remove the entry
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create a new player head ItemStack
|
||||||
|
ItemStack skull = new ItemStack(Material.PLAYER_HEAD, 1);
|
||||||
|
SkullMeta skullMeta = (SkullMeta) skull.getItemMeta();
|
||||||
|
|
||||||
|
// Create a new PlayerProfile
|
||||||
|
UUID uuid = UUID.randomUUID(); // Unique ID for the profile
|
||||||
|
PlayerProfile profile = Bukkit.createPlayerProfile(uuid);
|
||||||
|
|
||||||
|
// Decode the base64 texture and extract the texture URL
|
||||||
|
String decodedTexture = extractSkinUrlFromBase64(base64Texture);
|
||||||
|
|
||||||
|
// Set the skin URL using PlayerTextures
|
||||||
|
PlayerTextures textures = profile.getTextures();
|
||||||
|
try {
|
||||||
|
// Using a URL object for the texture
|
||||||
|
textures.setSkin(new URL(decodedTexture));
|
||||||
|
} catch (MalformedURLException ignore) {} // Base64 has no URL, ignore
|
||||||
|
|
||||||
|
// Apply the textures to the profile
|
||||||
|
profile.setTextures(textures);
|
||||||
|
|
||||||
|
// Apply the PlayerProfile to the SkullMeta
|
||||||
|
skullMeta.setOwnerProfile(profile);
|
||||||
|
|
||||||
|
// Set the modified SkullMeta back to the ItemStack
|
||||||
|
skull.setItemMeta(skullMeta);
|
||||||
|
|
||||||
|
savedCustomHeads.put(base64Texture, skull);
|
||||||
|
return skull;
|
||||||
|
}
|
||||||
|
|
||||||
|
// New method to get a player head by player name
|
||||||
|
public ItemStack getPlayerHead(String playerName) {
|
||||||
|
//check for any saved heads
|
||||||
|
if(savedCustomHeads.containsKey(playerName)) {
|
||||||
|
return savedCustomHeads.get(playerName);
|
||||||
|
}
|
||||||
|
|
||||||
|
//clear cached textures list until length limit is reached
|
||||||
|
Iterator<Map.Entry<String, ItemStack>> iterator = savedCustomHeads.entrySet().iterator();
|
||||||
|
while (savedCustomHeads.size() > 2000 && iterator.hasNext()) {
|
||||||
|
iterator.next(); // Move to next entry
|
||||||
|
iterator.remove(); // Remove the entry
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create a new player head ItemStack
|
||||||
|
ItemStack skull = new ItemStack(Material.PLAYER_HEAD, 1);
|
||||||
|
SkullMeta skullMeta = (SkullMeta) skull.getItemMeta();
|
||||||
|
|
||||||
|
// Get the OfflinePlayer object for the provided player name
|
||||||
|
OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(playerName);
|
||||||
|
|
||||||
|
// Create a PlayerProfile from the player's UUID
|
||||||
|
UUID playerUUID = offlinePlayer.getUniqueId();
|
||||||
|
PlayerProfile profile = Bukkit.createPlayerProfile(playerUUID);
|
||||||
|
|
||||||
|
// Apply the PlayerProfile to the SkullMeta
|
||||||
|
skullMeta.setOwnerProfile(profile);
|
||||||
|
|
||||||
|
// Set the modified SkullMeta back to the ItemStack
|
||||||
|
skull.setItemMeta(skullMeta);
|
||||||
|
|
||||||
|
savedCustomHeads.put(playerName, skull);
|
||||||
|
return skull;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Helper method to extract the skin URL from the base64 texture
|
||||||
|
private String extractSkinUrlFromBase64(String base64Texture) {
|
||||||
|
// Decode the base64 string
|
||||||
|
byte[] decodedBytes = Base64.getDecoder().decode(base64Texture);
|
||||||
|
String decodedString = new String(decodedBytes);
|
||||||
|
|
||||||
|
// Parse the decoded string as JSON
|
||||||
|
JsonObject jsonObject = JsonParser.parseString(decodedString).getAsJsonObject();
|
||||||
|
|
||||||
|
// Navigate to "textures" -> "SKIN" -> "url"
|
||||||
|
JsonObject textures = jsonObject.getAsJsonObject("textures");
|
||||||
|
JsonObject skin = textures.getAsJsonObject("SKIN");
|
||||||
|
|
||||||
|
// Return the URL if it exists
|
||||||
|
return skin.has("url") ? skin.get("url").getAsString() : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -74,7 +74,9 @@ public class CreateText {
|
|||||||
//change colour
|
//change colour
|
||||||
for(String temp : setpapi){
|
for(String temp : setpapi){
|
||||||
try {
|
try {
|
||||||
setpapi.set(tempInt, plugin.hex.translateHexColorCodes(ChatColor.translateAlternateColorCodes('&', temp)));
|
setpapi.set(tempInt,
|
||||||
|
plugin.hex.translateHexColorCodes(
|
||||||
|
ChatColor.translateAlternateColorCodes('&', temp)));
|
||||||
}catch(NullPointerException ignore){}
|
}catch(NullPointerException ignore){}
|
||||||
tempInt += 1;
|
tempInt += 1;
|
||||||
}
|
}
|
||||||
@ -84,7 +86,11 @@ public class CreateText {
|
|||||||
//regular string papi, but only colours so Player doesn't need to be there
|
//regular string papi, but only colours so Player doesn't need to be there
|
||||||
public String colour(String setpapi) {
|
public String colour(String setpapi) {
|
||||||
try {
|
try {
|
||||||
setpapi = plugin.hex.translateHexColorCodes(ChatColor.translateAlternateColorCodes('&', setpapi));
|
if(plugin.miniMessage != null){
|
||||||
|
setpapi = plugin.miniMessage.doMiniMessageLegacy(setpapi);
|
||||||
|
}
|
||||||
|
setpapi = ChatColor.translateAlternateColorCodes('&', setpapi);
|
||||||
|
setpapi = plugin.hex.translateHexColorCodes(setpapi);
|
||||||
return setpapi;
|
return setpapi;
|
||||||
}catch(NullPointerException e){
|
}catch(NullPointerException e){
|
||||||
return setpapi;
|
return setpapi;
|
||||||
@ -105,7 +111,11 @@ public class CreateText {
|
|||||||
public String placeholders(Panel panel, PanelPosition position, Player p, String setpapi) {
|
public String placeholders(Panel panel, PanelPosition position, Player p, String setpapi) {
|
||||||
try {
|
try {
|
||||||
setpapi = attachPlaceholders(panel,position, p,setpapi);
|
setpapi = attachPlaceholders(panel,position, p,setpapi);
|
||||||
setpapi = plugin.hex.translateHexColorCodes(ChatColor.translateAlternateColorCodes('&', setpapi));
|
if(plugin.miniMessage != null){
|
||||||
|
setpapi = plugin.miniMessage.doMiniMessageLegacy(setpapi);
|
||||||
|
}
|
||||||
|
setpapi = ChatColor.translateAlternateColorCodes('&', setpapi);
|
||||||
|
setpapi = plugin.hex.translateHexColorCodes(setpapi);
|
||||||
return setpapi;
|
return setpapi;
|
||||||
}catch(NullPointerException e){
|
}catch(NullPointerException e){
|
||||||
return setpapi;
|
return setpapi;
|
||||||
|
@ -35,7 +35,7 @@ public class HexColours {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//automatically format regex to escape special characters
|
//automatically format regex to escape special characters
|
||||||
public String formatRegex(String path){
|
private String formatRegex(String path){
|
||||||
String inputString = plugin.config.getString(path);
|
String inputString = plugin.config.getString(path);
|
||||||
final String[] metaCharacters = {"\\","^","$","{","}","[","]","(",")",".","*","+","?","|","<",">","-","&","%"};
|
final String[] metaCharacters = {"\\","^","$","{","}","[","]","(",")",".","*","+","?","|","<",">","-","&","%"};
|
||||||
|
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
package me.rockyhawk.commandpanels.classresources.placeholders;
|
package me.rockyhawk.commandpanels.classresources.placeholders;
|
||||||
|
|
||||||
import com.bencodez.votingplugin.VotingPluginHooks;
|
|
||||||
import com.earth2me.essentials.Essentials;
|
import com.earth2me.essentials.Essentials;
|
||||||
import me.realized.tokenmanager.api.TokenManager;
|
|
||||||
import me.rockyhawk.commandpanels.CommandPanels;
|
import me.rockyhawk.commandpanels.CommandPanels;
|
||||||
import me.rockyhawk.commandpanels.api.Panel;
|
import me.rockyhawk.commandpanels.api.Panel;
|
||||||
import me.rockyhawk.commandpanels.ioclasses.legacy.MinecraftVersions;
|
import me.rockyhawk.commandpanels.ioclasses.legacy.MinecraftVersions;
|
||||||
@ -12,7 +10,6 @@ import org.bukkit.entity.Player;
|
|||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.inventory.meta.Damageable;
|
import org.bukkit.inventory.meta.Damageable;
|
||||||
import org.bukkit.inventory.meta.PotionMeta;
|
import org.bukkit.inventory.meta.PotionMeta;
|
||||||
import org.bukkit.potion.PotionEffect;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
@ -141,19 +138,23 @@ public class Placeholders {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//placeholder to check if an item has NBT %cp-nbt-slot:key%
|
//placeholder to check if an item has NBT %cp-nbt-slot:type:key%
|
||||||
if(identifier.startsWith("nbt-")) {
|
if (identifier.startsWith("nbt-")) {
|
||||||
try {
|
try {
|
||||||
String slot_key = identifier.replace("nbt-", "");
|
String slot_key = identifier.replace("nbt-", "");
|
||||||
String value;
|
Object value;
|
||||||
value = plugin.nbt.getNBT(p.getOpenInventory().getTopInventory().getItem((int)Double.parseDouble(slot_key.split(":")[0])),slot_key.split(":")[1]);
|
value = plugin.nbt.getNBT(
|
||||||
if(value.isEmpty()){
|
p.getOpenInventory().getTopInventory().getItem(
|
||||||
value = "empty";
|
(int) Double.parseDouble(slot_key.split(":")[0])
|
||||||
}
|
),
|
||||||
return value;
|
slot_key.split(":")[2],
|
||||||
}catch (Exception ex){
|
slot_key.split(":")[1]
|
||||||
plugin.debug(ex,p);
|
);
|
||||||
return "";
|
// Convert any object type to a string, handle null explicitly if desired
|
||||||
|
return value == null ? "empty" : String.valueOf(value);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
plugin.debug(ex, p);
|
||||||
|
return ""; // Consider returning "error" or some other indicative string
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -168,10 +169,16 @@ public class Placeholders {
|
|||||||
|
|
||||||
// Check if the item is not null and has potion meta
|
// Check if the item is not null and has potion meta
|
||||||
if (item != null && item.hasItemMeta() && item.getItemMeta() instanceof PotionMeta) {
|
if (item != null && item.hasItemMeta() && item.getItemMeta() instanceof PotionMeta) {
|
||||||
PotionMeta potionMeta = (PotionMeta) item.getItemMeta();
|
//choose between legacy PotionData (pre 1.20.5) or PotionType
|
||||||
|
if(plugin.legacy.MAJOR_VERSION.lessThanOrEqualTo(MinecraftVersions.v1_19) ||
|
||||||
//Returns the value like this <Type>:<Extended>:<Upgraded> Example SLOWNESS:true:false
|
(plugin.legacy.MAJOR_VERSION == MinecraftVersions.v1_20 && plugin.legacy.MINOR_VERSION <= 4)){
|
||||||
return potionMeta.getBasePotionData().getType() + ":" + potionMeta.getBasePotionData().isExtended() + ":" + potionMeta.getBasePotionData().isUpgraded();
|
//Returns the value like this <Type>:<Extended>:<Upgraded> Example SLOWNESS:true:false
|
||||||
|
return plugin.legacyPotion.retrievePotionData(item).replaceAll("\\s",":");
|
||||||
|
}else{
|
||||||
|
//post 1.20.5 compare just return PotionType
|
||||||
|
PotionMeta potionMeta = (PotionMeta) item.getItemMeta();
|
||||||
|
return potionMeta.getBasePotionType().toString();
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
return "empty"; // Item is either null or doesn't have potion meta
|
return "empty"; // Item is either null or doesn't have potion meta
|
||||||
}
|
}
|
||||||
@ -189,9 +196,9 @@ public class Placeholders {
|
|||||||
String material;
|
String material;
|
||||||
try {
|
try {
|
||||||
material = p.getOpenInventory().getTopInventory().getItem((int)Double.parseDouble(matNumber)).getType().toString();
|
material = p.getOpenInventory().getTopInventory().getItem((int)Double.parseDouble(matNumber)).getType().toString();
|
||||||
if (plugin.legacy.LOCAL_VERSION.lessThanOrEqualTo(MinecraftVersions.v1_12)) {
|
if (plugin.legacy.MAJOR_VERSION.lessThanOrEqualTo(MinecraftVersions.v1_12)) {
|
||||||
//add the ID to the end if it is legacy (eg, material:id)
|
//add the ID to the end if it is legacy (eg, material:id)
|
||||||
material = material + ":" + p.getOpenInventory().getTopInventory().getItem((int)Double.parseDouble(matNumber)).getType().getId();
|
material = material + ":" + p.getOpenInventory().getTopInventory().getItem((int)Double.parseDouble(matNumber)).getData().getData();
|
||||||
}
|
}
|
||||||
} catch (NullPointerException er) {
|
} catch (NullPointerException er) {
|
||||||
material = "AIR";
|
material = "AIR";
|
||||||
@ -202,6 +209,52 @@ public class Placeholders {
|
|||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
//get name value from slot in current open inventory (panel)
|
||||||
|
if(identifier.startsWith("name-")) {
|
||||||
|
try {
|
||||||
|
String nameNumber = identifier.replace("name-", "");
|
||||||
|
String name;
|
||||||
|
try {
|
||||||
|
ItemStack item = p.getOpenInventory().getTopInventory().getItem((int)Double.parseDouble(nameNumber));
|
||||||
|
name = item.getType().toString().replace("_"," ");
|
||||||
|
if(item.hasItemMeta()){
|
||||||
|
if(item.getItemMeta().hasDisplayName()){
|
||||||
|
name = item.getItemMeta().getDisplayName();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (NullPointerException er) {
|
||||||
|
name = "";
|
||||||
|
}
|
||||||
|
return name;
|
||||||
|
} catch (Exception ex) {
|
||||||
|
plugin.debug(ex,p);
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//get lore value from slot in current open inventory (panel)
|
||||||
|
if(identifier.startsWith("lore-")) {
|
||||||
|
try {
|
||||||
|
String loreNumber = identifier.replace("lore-", "");
|
||||||
|
String lore = "";
|
||||||
|
try {
|
||||||
|
ItemStack item = p.getOpenInventory().getTopInventory().getItem((int)Double.parseDouble(loreNumber));
|
||||||
|
if(item.hasItemMeta()){
|
||||||
|
if(item.getItemMeta().hasLore()){
|
||||||
|
List<String> ListLore = item.getItemMeta().getLore();
|
||||||
|
for(String list : ListLore){
|
||||||
|
lore = lore + list + "\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (NullPointerException er) {
|
||||||
|
lore = "";
|
||||||
|
}
|
||||||
|
return lore;
|
||||||
|
} catch (Exception ex) {
|
||||||
|
plugin.debug(ex,p);
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
}
|
||||||
//get stack amount from slot in current open inventory (panel)
|
//get stack amount from slot in current open inventory (panel)
|
||||||
if(identifier.startsWith("stack-")) {
|
if(identifier.startsWith("stack-")) {
|
||||||
try {
|
try {
|
||||||
@ -241,7 +294,7 @@ public class Placeholders {
|
|||||||
boolean damaged = false;
|
boolean damaged = false;
|
||||||
ItemStack itm = p.getOpenInventory().getTopInventory().getItem((int)Double.parseDouble(matNumber));
|
ItemStack itm = p.getOpenInventory().getTopInventory().getItem((int)Double.parseDouble(matNumber));
|
||||||
try {
|
try {
|
||||||
if(plugin.legacy.LOCAL_VERSION.lessThanOrEqualTo(MinecraftVersions.v1_15)){
|
if(plugin.legacy.MAJOR_VERSION.lessThanOrEqualTo(MinecraftVersions.v1_15)){
|
||||||
if(itm.getType().getMaxDurability() != 0) {
|
if(itm.getType().getMaxDurability() != 0) {
|
||||||
damaged = (itm.getType().getMaxDurability() - itm.getDurability()) < itm.getType().getMaxDurability();
|
damaged = (itm.getType().getMaxDurability() - itm.getDurability()) < itm.getType().getMaxDurability();
|
||||||
}
|
}
|
||||||
@ -320,7 +373,7 @@ public class Placeholders {
|
|||||||
if(dataPoint.contains(",")){
|
if(dataPoint.contains(",")){
|
||||||
String dataName = dataPoint.split(",")[0];
|
String dataName = dataPoint.split(",")[0];
|
||||||
String playerName = dataPoint.split(",")[1];
|
String playerName = dataPoint.split(",")[1];
|
||||||
return plugin.panelData.getUserData(Bukkit.getOfflinePlayer(playerName).getUniqueId(),dataName);
|
return plugin.panelData.getUserData(plugin.panelDataPlayers.getOffline(playerName),dataName);
|
||||||
}else{
|
}else{
|
||||||
return plugin.panelData.getUserData(p.getUniqueId(),dataPoint);
|
return plugin.panelData.getUserData(p.getUniqueId(),dataPoint);
|
||||||
}
|
}
|
||||||
@ -329,12 +382,26 @@ public class Placeholders {
|
|||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
//returns if a player is found
|
||||||
|
if(identifier.startsWith("uuid-")) {
|
||||||
|
try {
|
||||||
|
String dataPoint = identifier.replace("uuid-", "");
|
||||||
|
//get data from other user
|
||||||
|
if(plugin.panelDataPlayers.getOffline(dataPoint) == null){
|
||||||
|
return "unknown";
|
||||||
|
}
|
||||||
|
return plugin.panelDataPlayers.getOffline(dataPoint).toString();
|
||||||
|
}catch (Exception ex){
|
||||||
|
plugin.debug(ex,p);
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
}
|
||||||
//edits data via placeholder execution (will return empty output)
|
//edits data via placeholder execution (will return empty output)
|
||||||
if(identifier.startsWith("setdata-")) {
|
if(identifier.startsWith("setdata-")) {
|
||||||
try {
|
try {
|
||||||
String point_value = identifier.replace("cp-setdata-", "");
|
String point_value = identifier.replace("setdata-", "");
|
||||||
String command = "set-data= " + point_value.split(",")[0] + " " + point_value.split(",")[1];
|
String command = "set-data= " + point_value.split(",")[0] + " " + point_value.split(",")[1];
|
||||||
plugin.commandTags.runCommand(panel,position,p, command);
|
plugin.commandRunner.runCommand(panel,position,p, command);
|
||||||
return "";
|
return "";
|
||||||
}catch (Exception ex){
|
}catch (Exception ex){
|
||||||
plugin.debug(ex,p);
|
plugin.debug(ex,p);
|
||||||
@ -346,7 +413,7 @@ public class Placeholders {
|
|||||||
try {
|
try {
|
||||||
String point_value = identifier.replace("mathdata-", "");
|
String point_value = identifier.replace("mathdata-", "");
|
||||||
String command = "math-data= " + point_value.split(",")[0] + " " + point_value.split(",")[1];
|
String command = "math-data= " + point_value.split(",")[0] + " " + point_value.split(",")[1];
|
||||||
plugin.commandTags.runCommand(panel,position,p,command);
|
plugin.commandRunner.runCommand(panel,position,p,command);
|
||||||
return "";
|
return "";
|
||||||
}catch (Exception ex){
|
}catch (Exception ex){
|
||||||
plugin.debug(ex,p);
|
plugin.debug(ex,p);
|
||||||
@ -394,18 +461,6 @@ public class Placeholders {
|
|||||||
} catch (Exception place) {
|
} catch (Exception place) {
|
||||||
//skip
|
//skip
|
||||||
}
|
}
|
||||||
if (plugin.getServer().getPluginManager().isPluginEnabled("TokenManager")) {
|
|
||||||
TokenManager api = (TokenManager) Bukkit.getServer().getPluginManager().getPlugin("TokenManager");
|
|
||||||
assert api != null;
|
|
||||||
if(identifier.equals("tokenmanager-balance")) {
|
|
||||||
return Long.toString(api.getTokens(p).orElse(0));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (plugin.getServer().getPluginManager().isPluginEnabled("VotingPlugin")) {
|
|
||||||
if(identifier.equals("votingplugin-points")) {
|
|
||||||
return String.valueOf(VotingPluginHooks.getInstance().getUserManager().getVotingPluginUser(p).getPoints());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//end nodes with PlaceHolders
|
//end nodes with PlaceHolders
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
@ -36,6 +36,7 @@ public class CommandPanelImport implements CommandExecutor {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
sender.sendMessage(plugin.tex.colour(plugin.tag + plugin.config.getString("config.format.perms")));
|
sender.sendMessage(plugin.tex.colour(plugin.tag + plugin.config.getString("config.format.perms")));
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
sender.sendMessage(plugin.tex.colour(plugin.tag + ChatColor.RED + "Usage: /cpi <file name> <url>"));
|
sender.sendMessage(plugin.tex.colour(plugin.tag + ChatColor.RED + "Usage: /cpi <file name> <url>"));
|
||||||
return true;
|
return true;
|
||||||
|
@ -36,11 +36,11 @@ public class Commandpanelsdata implements CommandExecutor {
|
|||||||
if (args[1].equalsIgnoreCase("all") || args[1].equalsIgnoreCase("online")) {
|
if (args[1].equalsIgnoreCase("all") || args[1].equalsIgnoreCase("online")) {
|
||||||
for (OfflinePlayer player : Bukkit.getOfflinePlayers()) {
|
for (OfflinePlayer player : Bukkit.getOfflinePlayers()) {
|
||||||
if (args[1].equalsIgnoreCase("online") && !player.isOnline()) continue;
|
if (args[1].equalsIgnoreCase("online") && !player.isOnline()) continue;
|
||||||
plugin.panelData.clearData(plugin.panelData.getOffline(player.getName()));
|
plugin.panelData.clearData(plugin.panelDataPlayers.getOffline(player.getName()));
|
||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
} else
|
} else
|
||||||
plugin.panelData.clearData(plugin.panelData.getOffline(args[1]));
|
plugin.panelData.clearData(plugin.panelDataPlayers.getOffline(args[1]));
|
||||||
if (sendPlayerMessage) {
|
if (sendPlayerMessage) {
|
||||||
sender.sendMessage(plugin.tex.colour(plugin.tag
|
sender.sendMessage(plugin.tex.colour(plugin.tag
|
||||||
+ ChatColor.GREEN + "Cleared all data for "
|
+ ChatColor.GREEN + "Cleared all data for "
|
||||||
@ -54,11 +54,11 @@ public class Commandpanelsdata implements CommandExecutor {
|
|||||||
if (args[1].equalsIgnoreCase("all") || args[1].equalsIgnoreCase("online")) {
|
if (args[1].equalsIgnoreCase("all") || args[1].equalsIgnoreCase("online")) {
|
||||||
for (OfflinePlayer player : Bukkit.getOfflinePlayers()) {
|
for (OfflinePlayer player : Bukkit.getOfflinePlayers()) {
|
||||||
if (args[1].equalsIgnoreCase("online") && !player.isOnline()) continue;
|
if (args[1].equalsIgnoreCase("online") && !player.isOnline()) continue;
|
||||||
plugin.panelData.delUserData(plugin.panelData.getOffline(player.getName()), args[2]);
|
plugin.panelData.delUserData(plugin.panelDataPlayers.getOffline(player.getName()), args[2]);
|
||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
} else
|
} else
|
||||||
plugin.panelData.delUserData(plugin.panelData.getOffline(args[1]), args[2]);
|
plugin.panelData.delUserData(plugin.panelDataPlayers.getOffline(args[1]), args[2]);
|
||||||
if (sendPlayerMessage) {
|
if (sendPlayerMessage) {
|
||||||
sender.sendMessage(plugin.tex.colour(plugin.tag
|
sender.sendMessage(plugin.tex.colour(plugin.tag
|
||||||
+ ChatColor.GREEN + "Removed "
|
+ ChatColor.GREEN + "Removed "
|
||||||
@ -71,7 +71,7 @@ public class Commandpanelsdata implements CommandExecutor {
|
|||||||
//for the get command
|
//for the get command
|
||||||
sender.sendMessage(plugin.tex.colour(plugin.tag
|
sender.sendMessage(plugin.tex.colour(plugin.tag
|
||||||
+ ChatColor.GREEN + "Value of data is "
|
+ ChatColor.GREEN + "Value of data is "
|
||||||
+ ChatColor.WHITE + plugin.panelData.getUserData(plugin.panelData.getOffline(args[1]), args[2])));
|
+ ChatColor.WHITE + plugin.panelData.getUserData(plugin.panelDataPlayers.getOffline(args[1]), args[2])));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
} else if (args.length == 4) {
|
} else if (args.length == 4) {
|
||||||
@ -80,11 +80,11 @@ public class Commandpanelsdata implements CommandExecutor {
|
|||||||
if (args[1].equalsIgnoreCase("all") || args[1].equalsIgnoreCase("online")) {
|
if (args[1].equalsIgnoreCase("all") || args[1].equalsIgnoreCase("online")) {
|
||||||
for (OfflinePlayer player : Bukkit.getOfflinePlayers()) {
|
for (OfflinePlayer player : Bukkit.getOfflinePlayers()) {
|
||||||
if (args[1].equalsIgnoreCase("online") && !player.isOnline()) continue;
|
if (args[1].equalsIgnoreCase("online") && !player.isOnline()) continue;
|
||||||
plugin.panelData.setUserData(plugin.panelData.getOffline(player.getName()), args[2], args[3], true);
|
plugin.panelData.setUserData(plugin.panelDataPlayers.getOffline(player.getName()), args[2], args[3], true);
|
||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
plugin.panelData.setUserData(plugin.panelData.getOffline(args[1]), args[2], args[3], true);
|
plugin.panelData.setUserData(plugin.panelDataPlayers.getOffline(args[1]), args[2], args[3], true);
|
||||||
}
|
}
|
||||||
if (sendPlayerMessage) {
|
if (sendPlayerMessage) {
|
||||||
sender.sendMessage(plugin.tex.colour(plugin.tag
|
sender.sendMessage(plugin.tex.colour(plugin.tag
|
||||||
@ -101,11 +101,11 @@ public class Commandpanelsdata implements CommandExecutor {
|
|||||||
|
|
||||||
for (OfflinePlayer player : Bukkit.getOfflinePlayers()) {
|
for (OfflinePlayer player : Bukkit.getOfflinePlayers()) {
|
||||||
if (args[1].equalsIgnoreCase("online") && !player.isOnline()) continue;
|
if (args[1].equalsIgnoreCase("online") && !player.isOnline()) continue;
|
||||||
plugin.panelData.setUserData(plugin.panelData.getOffline(player.getName()), args[2], args[3], false);
|
plugin.panelData.setUserData(plugin.panelDataPlayers.getOffline(player.getName()), args[2], args[3], false);
|
||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
} else
|
} else
|
||||||
plugin.panelData.setUserData(plugin.panelData.getOffline(args[1]), args[2], args[3], false);
|
plugin.panelData.setUserData(plugin.panelDataPlayers.getOffline(args[1]), args[2], args[3], false);
|
||||||
if (sendPlayerMessage) {
|
if (sendPlayerMessage) {
|
||||||
sender.sendMessage(plugin.tex.colour(plugin.tag
|
sender.sendMessage(plugin.tex.colour(plugin.tag
|
||||||
+ ChatColor.GREEN + "Set "
|
+ ChatColor.GREEN + "Set "
|
||||||
|
@ -8,11 +8,8 @@ import org.bukkit.ChatColor;
|
|||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandExecutor;
|
import org.bukkit.command.CommandExecutor;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.configuration.ConfigurationSection;
|
|
||||||
import org.bukkit.configuration.file.YamlConfiguration;
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.scheduler.BukkitRunnable;
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@ -40,6 +37,9 @@ public class Commandpanelsreload implements CommandExecutor {
|
|||||||
plugin.config = YamlConfiguration.loadConfiguration(new File(plugin.getDataFolder() + File.separator + "config.yml"));
|
plugin.config = YamlConfiguration.loadConfiguration(new File(plugin.getDataFolder() + File.separator + "config.yml"));
|
||||||
plugin.blockConfig = YamlConfiguration.loadConfiguration(new File(plugin.getDataFolder() + File.separator + "blocks.yml"));
|
plugin.blockConfig = YamlConfiguration.loadConfiguration(new File(plugin.getDataFolder() + File.separator + "blocks.yml"));
|
||||||
|
|
||||||
|
//load all known player UUIDs for data
|
||||||
|
plugin.panelDataPlayers.reloadAllPlayers();
|
||||||
|
|
||||||
//check for duplicates
|
//check for duplicates
|
||||||
plugin.checkDuplicatePanel(sender);
|
plugin.checkDuplicatePanel(sender);
|
||||||
|
|
||||||
@ -54,9 +54,6 @@ public class Commandpanelsreload implements CommandExecutor {
|
|||||||
registerCommands();
|
registerCommands();
|
||||||
}
|
}
|
||||||
|
|
||||||
//pre-cache any player head textures from panels
|
|
||||||
reloadCachedHeads(sender);
|
|
||||||
|
|
||||||
sender.sendMessage(plugin.tex.colour(plugin.tag + plugin.config.getString("config.format.reload")));
|
sender.sendMessage(plugin.tex.colour(plugin.tag + plugin.config.getString("config.format.reload")));
|
||||||
}else{
|
}else{
|
||||||
sender.sendMessage(plugin.tex.colour(plugin.tag + plugin.config.getString("config.format.perms")));
|
sender.sendMessage(plugin.tex.colour(plugin.tag + plugin.config.getString("config.format.perms")));
|
||||||
@ -114,47 +111,4 @@ public class Commandpanelsreload implements CommandExecutor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//reload player heads
|
|
||||||
public void reloadCachedHeads(CommandSender sender){
|
|
||||||
new BukkitRunnable() {
|
|
||||||
public void run() {
|
|
||||||
for (Panel temp : plugin.panelList) {
|
|
||||||
ConfigurationSection yaml = temp.getConfig();
|
|
||||||
//look through yaml for player heads
|
|
||||||
if(sender instanceof Player) {
|
|
||||||
Player player = ((Player) sender).getPlayer();
|
|
||||||
checkKeysRecursive(temp, player, yaml);
|
|
||||||
}else{
|
|
||||||
checkKeysRecursive(temp, null, yaml);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}.runTaskAsynchronously(this.plugin);
|
|
||||||
}
|
|
||||||
|
|
||||||
//this will recursively check through all the keys in a panel for cps= values and find ones with Player names
|
|
||||||
private void checkKeysRecursive(Panel panel, Player player, ConfigurationSection section) {
|
|
||||||
for (String key : section.getKeys(false)) {
|
|
||||||
if (key.equals("material")) {
|
|
||||||
String value = section.getString(key);
|
|
||||||
//if value is a custom head
|
|
||||||
if (value.startsWith("cps=")) {
|
|
||||||
String[] words = value.split("\\s");
|
|
||||||
//if value is the length of a players name
|
|
||||||
if (!words[1].equalsIgnoreCase("self") && words[1].length() <= 16) {
|
|
||||||
try {
|
|
||||||
String tempName = plugin.tex.placeholdersNoColour(panel, PanelPosition.Top, player, words[1]);
|
|
||||||
plugin.customHeads.getPlayerHead(tempName); //get the head cached
|
|
||||||
}catch (Exception ignore){} //ignore heads that cannot be cached without the panel being open
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (section.isConfigurationSection(key)) {
|
|
||||||
// Recursive call to check nested sections
|
|
||||||
checkKeysRecursive(panel, player, section.getConfigurationSection(key));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
151
src/me/rockyhawk/commandpanels/commandtags/CommandRunner.java
Normal file
151
src/me/rockyhawk/commandpanels/commandtags/CommandRunner.java
Normal file
@ -0,0 +1,151 @@
|
|||||||
|
package me.rockyhawk.commandpanels.commandtags;
|
||||||
|
|
||||||
|
import me.rockyhawk.commandpanels.CommandPanels;
|
||||||
|
import me.rockyhawk.commandpanels.api.Panel;
|
||||||
|
import me.rockyhawk.commandpanels.commandtags.paywalls.*;
|
||||||
|
import me.rockyhawk.commandpanels.commandtags.paywalls.itempaywall.ItemPaywall;
|
||||||
|
import me.rockyhawk.commandpanels.commandtags.tags.other.DataTags;
|
||||||
|
import me.rockyhawk.commandpanels.commandtags.tags.other.PlaceholderTags;
|
||||||
|
import me.rockyhawk.commandpanels.commandtags.tags.other.SpecialTags;
|
||||||
|
import me.rockyhawk.commandpanels.commandtags.tags.standard.BasicTags;
|
||||||
|
import me.rockyhawk.commandpanels.commandtags.tags.standard.BungeeTags;
|
||||||
|
import me.rockyhawk.commandpanels.commandtags.tags.standard.ItemTags;
|
||||||
|
import me.rockyhawk.commandpanels.openpanelsmanager.PanelPosition;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.inventory.ClickType;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
public class CommandRunner {
|
||||||
|
CommandPanels plugin;
|
||||||
|
|
||||||
|
public CommandRunner(CommandPanels pl) {
|
||||||
|
this.plugin = pl;
|
||||||
|
}
|
||||||
|
|
||||||
|
//with the click type included, use null for no click type check
|
||||||
|
public void runCommands(Panel panel, PanelPosition position, Player p, List<String> commands, ClickType click) {
|
||||||
|
for (String command : commands) {
|
||||||
|
if(click != null) {
|
||||||
|
command = plugin.commandRunner.hasCorrectClick(command, click);
|
||||||
|
if (command.equals("")) {
|
||||||
|
//click type is wrong
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//do paywall check
|
||||||
|
PaywallEvent paywallEvent = new PaywallEvent(plugin, panel, position, p, command);
|
||||||
|
Bukkit.getPluginManager().callEvent(paywallEvent);
|
||||||
|
if (paywallEvent.PAYWALL_OUTPUT == PaywallOutput.Blocked) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
//not a paywall, run as command
|
||||||
|
if (paywallEvent.PAYWALL_OUTPUT == PaywallOutput.NotApplicable) {
|
||||||
|
plugin.commandRunner.runCommand(panel, position, p, command);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void runCommand(Panel panel, PanelPosition position, Player p, String commandRAW) {
|
||||||
|
CommandTagEvent tags = new CommandTagEvent(plugin, panel, position, p, commandRAW);
|
||||||
|
Bukkit.getPluginManager().callEvent(tags);
|
||||||
|
if (!tags.commandTagUsed) {
|
||||||
|
Bukkit.dispatchCommand(p, plugin.tex.attachPlaceholders(panel, position, p, commandRAW.trim()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean runMultiPaywall(Panel panel, PanelPosition position, Player p, List<String> paywalls, List<String> commands, ClickType click) {
|
||||||
|
boolean allPaywallsValid = true;
|
||||||
|
|
||||||
|
// New list combining paywalls and commands
|
||||||
|
List<String> allCommands = new ArrayList<>(paywalls);
|
||||||
|
allCommands.addAll(commands);
|
||||||
|
|
||||||
|
for (String command : allCommands) {
|
||||||
|
// Trigger the event but do not remove the payment from the player
|
||||||
|
PaywallEvent paywallEvent = new PaywallEvent(plugin, panel, position, p, command);
|
||||||
|
paywallEvent.doDelete = false;
|
||||||
|
Bukkit.getPluginManager().callEvent(paywallEvent);
|
||||||
|
|
||||||
|
if (paywallEvent.PAYWALL_OUTPUT == PaywallOutput.Blocked) {
|
||||||
|
allPaywallsValid = false; // Set flag to false if any paywall is blocked
|
||||||
|
break; // Exit the loop if any command is blocked by the paywall
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Execute all commands if all paywalls are valid
|
||||||
|
if (allPaywallsValid) {
|
||||||
|
plugin.commandRunner.runCommands(panel, position, p, allCommands, click);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Return output as boolean for usage if applicable
|
||||||
|
return allPaywallsValid;
|
||||||
|
}
|
||||||
|
|
||||||
|
//do this on startup to load listeners
|
||||||
|
public void registerBuiltInTags() {
|
||||||
|
plugin.getServer().getPluginManager().registerEvents(new Paywall(plugin), plugin);
|
||||||
|
plugin.getServer().getPluginManager().registerEvents(new TokenPaywall(plugin), plugin);
|
||||||
|
plugin.getServer().getPluginManager().registerEvents(new ItemPaywall(plugin), plugin);
|
||||||
|
plugin.getServer().getPluginManager().registerEvents(new Hasperm(plugin), plugin);
|
||||||
|
plugin.getServer().getPluginManager().registerEvents(new XpPaywall(plugin), plugin);
|
||||||
|
plugin.getServer().getPluginManager().registerEvents(new DataPaywall(plugin), plugin);
|
||||||
|
|
||||||
|
plugin.getServer().getPluginManager().registerEvents(new DataTags(plugin), plugin);
|
||||||
|
plugin.getServer().getPluginManager().registerEvents(new PlaceholderTags(plugin), plugin);
|
||||||
|
plugin.getServer().getPluginManager().registerEvents(new SpecialTags(plugin), plugin);
|
||||||
|
|
||||||
|
plugin.getServer().getPluginManager().registerEvents(new BasicTags(plugin), plugin);
|
||||||
|
plugin.getServer().getPluginManager().registerEvents(new BungeeTags(plugin), plugin);
|
||||||
|
plugin.getServer().getPluginManager().registerEvents(new ItemTags(plugin), plugin);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String hasCorrectClick(String command, ClickType click) {
|
||||||
|
try {
|
||||||
|
switch (command.split("\\s")[0]) {
|
||||||
|
case "right=": {
|
||||||
|
//if commands is for right-clicking, remove the 'right=' and continue
|
||||||
|
command = command.replace("right= ", "");
|
||||||
|
if (click != ClickType.RIGHT) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case "rightshift=": {
|
||||||
|
command = command.replace("rightshift= ", "");
|
||||||
|
if (click != ClickType.SHIFT_RIGHT) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case "left=": {
|
||||||
|
command = command.replace("left= ", "");
|
||||||
|
if (click != ClickType.LEFT) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case "leftshift=": {
|
||||||
|
command = command.replace("leftshift= ", "");
|
||||||
|
if (click != ClickType.SHIFT_LEFT) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case "middle=": {
|
||||||
|
command = command.replace("middle= ", "");
|
||||||
|
if (click != ClickType.MIDDLE) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return command;
|
||||||
|
} catch (Exception ex) {
|
||||||
|
return "";
|
||||||
|
//skip if you can't do this
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -3,7 +3,6 @@ package me.rockyhawk.commandpanels.commandtags;
|
|||||||
import me.rockyhawk.commandpanels.CommandPanels;
|
import me.rockyhawk.commandpanels.CommandPanels;
|
||||||
import me.rockyhawk.commandpanels.api.Panel;
|
import me.rockyhawk.commandpanels.api.Panel;
|
||||||
import me.rockyhawk.commandpanels.openpanelsmanager.PanelPosition;
|
import me.rockyhawk.commandpanels.openpanelsmanager.PanelPosition;
|
||||||
import org.bukkit.ChatColor;
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.Event;
|
import org.bukkit.event.Event;
|
||||||
import org.bukkit.event.HandlerList;
|
import org.bukkit.event.HandlerList;
|
||||||
@ -23,7 +22,7 @@ public class CommandTagEvent extends Event {
|
|||||||
this.panel = panel1;
|
this.panel = panel1;
|
||||||
this.pos = position;
|
this.pos = position;
|
||||||
|
|
||||||
//do nopapi= tag (donation feature) which will stop PlaceholderAPI placeholders from executing
|
//do nopapi= tag which will stop PlaceholderAPI placeholders from executing
|
||||||
boolean doApiPlaceholders = true;
|
boolean doApiPlaceholders = true;
|
||||||
if(rawCommand1.startsWith("nopapi= ")){
|
if(rawCommand1.startsWith("nopapi= ")){
|
||||||
rawCommand1 = rawCommand1.replace("nopapi= ","");
|
rawCommand1 = rawCommand1.replace("nopapi= ","");
|
||||||
@ -40,8 +39,8 @@ public class CommandTagEvent extends Event {
|
|||||||
if(doApiPlaceholders) {
|
if(doApiPlaceholders) {
|
||||||
this.args = plugin.tex.attachPlaceholders(panel1,pos, player, split[1].trim()).split("\\s");
|
this.args = plugin.tex.attachPlaceholders(panel1,pos, player, split[1].trim()).split("\\s");
|
||||||
}else{
|
}else{
|
||||||
this.args = ChatColor.translateAlternateColorCodes('&',plugin.placeholders.setPlaceholders(panel, pos, p,split[1].trim(),false)).split("\\s");
|
this.args = plugin.placeholders.setPlaceholders(panel, pos, p,split[1].trim(),false).split("\\s");
|
||||||
this.args = ChatColor.translateAlternateColorCodes('&',plugin.placeholders.setPlaceholders(panel, pos, p,split[1].trim(),true)).split("\\s");
|
this.args = plugin.placeholders.setPlaceholders(panel, pos, p,split[1].trim(),true).split("\\s");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,496 +0,0 @@
|
|||||||
package me.rockyhawk.commandpanels.commandtags;
|
|
||||||
|
|
||||||
import me.realized.tokenmanager.api.TokenManager;
|
|
||||||
import me.rockyhawk.commandpanels.CommandPanels;
|
|
||||||
import me.rockyhawk.commandpanels.api.Panel;
|
|
||||||
import me.rockyhawk.commandpanels.commandtags.tags.economy.BuyCommandTags;
|
|
||||||
import me.rockyhawk.commandpanels.commandtags.tags.economy.BuyItemTags;
|
|
||||||
import me.rockyhawk.commandpanels.commandtags.tags.economy.SellItemTags;
|
|
||||||
import me.rockyhawk.commandpanels.commandtags.tags.other.DataTags;
|
|
||||||
import me.rockyhawk.commandpanels.commandtags.tags.other.PlaceholderTags;
|
|
||||||
import me.rockyhawk.commandpanels.commandtags.tags.other.SpecialTags;
|
|
||||||
import me.rockyhawk.commandpanels.commandtags.tags.standard.BasicTags;
|
|
||||||
import me.rockyhawk.commandpanels.commandtags.tags.standard.BungeeTags;
|
|
||||||
import me.rockyhawk.commandpanels.commandtags.tags.standard.ItemTags;
|
|
||||||
import me.rockyhawk.commandpanels.openpanelsmanager.PanelPosition;
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.ChatColor;
|
|
||||||
import org.bukkit.Material;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.event.inventory.ClickType;
|
|
||||||
import org.bukkit.inventory.ItemStack;
|
|
||||||
|
|
||||||
import java.util.*;
|
|
||||||
|
|
||||||
public class CommandTags {
|
|
||||||
CommandPanels plugin;
|
|
||||||
|
|
||||||
public CommandTags(CommandPanels pl) {
|
|
||||||
this.plugin = pl;
|
|
||||||
}
|
|
||||||
|
|
||||||
//with the click type included
|
|
||||||
public void runCommands(Panel panel, PanelPosition position, Player p, List<String> commands, ClickType click) {
|
|
||||||
for (String command : commands) {
|
|
||||||
command = plugin.commandTags.hasCorrectClick(command, click);
|
|
||||||
if (command.equals("")) {
|
|
||||||
//click type is wrong
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
PaywallOutput val = plugin.commandTags.commandPayWall(panel, p, command, true);
|
|
||||||
if (val == PaywallOutput.Blocked) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (val == PaywallOutput.NotApplicable) {
|
|
||||||
plugin.commandTags.runCommand(panel, position, p, command);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void runCommands(Panel panel, PanelPosition position, Player p, List<String> commands) {
|
|
||||||
for (String command : commands) {
|
|
||||||
PaywallOutput val = plugin.commandTags.commandPayWall(panel, p, command, true);
|
|
||||||
if (val == PaywallOutput.Blocked) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (val == PaywallOutput.NotApplicable) {
|
|
||||||
plugin.commandTags.runCommand(panel, position, p, command);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void runMultiPaywall(Panel panel, PanelPosition position, Player p, List<String> paywalls, List<String> commands, ClickType click) {
|
|
||||||
boolean allPaywallsValid = paywalls.stream()
|
|
||||||
.map(command -> plugin.commandTags.commandPayWall(panel, p, command, false))
|
|
||||||
.allMatch(val -> val != PaywallOutput.Blocked);
|
|
||||||
|
|
||||||
if (allPaywallsValid) {
|
|
||||||
List<String> cmds = new ArrayList<>();
|
|
||||||
cmds.addAll(paywalls);
|
|
||||||
cmds.addAll(commands);
|
|
||||||
plugin.commandTags.runCommands(panel, position, p, cmds, click);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void runCommand(Panel panel, PanelPosition position, Player p, String commandRAW) {
|
|
||||||
CommandTagEvent tags = new CommandTagEvent(plugin, panel, position, p, commandRAW);
|
|
||||||
Bukkit.getPluginManager().callEvent(tags);
|
|
||||||
if (!tags.commandTagUsed) {
|
|
||||||
Bukkit.dispatchCommand(p, plugin.tex.placeholders(panel, position, p, commandRAW.trim()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//do this on startup to load listeners
|
|
||||||
public void registerBuiltInTags() {
|
|
||||||
plugin.getServer().getPluginManager().registerEvents(new BuyCommandTags(plugin), plugin);
|
|
||||||
plugin.getServer().getPluginManager().registerEvents(new BuyItemTags(plugin), plugin);
|
|
||||||
plugin.getServer().getPluginManager().registerEvents(new SellItemTags(plugin), plugin);
|
|
||||||
|
|
||||||
plugin.getServer().getPluginManager().registerEvents(new DataTags(plugin), plugin);
|
|
||||||
plugin.getServer().getPluginManager().registerEvents(new PlaceholderTags(plugin), plugin);
|
|
||||||
plugin.getServer().getPluginManager().registerEvents(new SpecialTags(plugin), plugin);
|
|
||||||
|
|
||||||
plugin.getServer().getPluginManager().registerEvents(new BasicTags(plugin), plugin);
|
|
||||||
plugin.getServer().getPluginManager().registerEvents(new BungeeTags(plugin), plugin);
|
|
||||||
plugin.getServer().getPluginManager().registerEvents(new ItemTags(plugin), plugin);
|
|
||||||
}
|
|
||||||
|
|
||||||
public String hasCorrectClick(String command, ClickType click) {
|
|
||||||
try {
|
|
||||||
switch (command.split("\\s")[0]) {
|
|
||||||
case "right=": {
|
|
||||||
//if commands is for right clicking, remove the 'right=' and continue
|
|
||||||
command = command.replace("right= ", "");
|
|
||||||
if (click != ClickType.RIGHT) {
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case "rightshift=": {
|
|
||||||
command = command.replace("rightshift= ", "");
|
|
||||||
if (click != ClickType.SHIFT_RIGHT) {
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case "left=": {
|
|
||||||
command = command.replace("left= ", "");
|
|
||||||
if (click != ClickType.LEFT) {
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case "leftshift=": {
|
|
||||||
command = command.replace("leftshift= ", "");
|
|
||||||
if (click != ClickType.SHIFT_LEFT) {
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case "middle=": {
|
|
||||||
command = command.replace("middle= ", "");
|
|
||||||
if (click != ClickType.MIDDLE) {
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return command;
|
|
||||||
} catch (Exception ex) {
|
|
||||||
return "";
|
|
||||||
//skip if you can't do this
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
|
||||||
public PaywallOutput commandPayWall(Panel panel, Player p, String rawCommand, boolean removal) { //return 0 means no funds, 1 is they passed and 2 means paywall is not this command
|
|
||||||
|
|
||||||
//create new instance of command but with placeholders parsed
|
|
||||||
switch (rawCommand.split("\\s")[0]) {
|
|
||||||
default: {
|
|
||||||
return PaywallOutput.NotApplicable;
|
|
||||||
}
|
|
||||||
case "paywall=": {
|
|
||||||
String command = plugin.tex.placeholders(panel, PanelPosition.Top, p, rawCommand);
|
|
||||||
//if player uses paywall= [price]
|
|
||||||
try {
|
|
||||||
if (plugin.econ != null) {
|
|
||||||
if (plugin.econ.getBalance(p) >= Double.parseDouble(command.split("\\s")[1])) {
|
|
||||||
if (removal) plugin.econ.withdrawPlayer(p, Double.parseDouble(command.split("\\s")[1]));
|
|
||||||
if (plugin.config.getBoolean("purchase.currency.enable") && removal) {
|
|
||||||
plugin.tex.sendString(panel, PanelPosition.Top, p, Objects.requireNonNull(plugin.config.getString("purchase.currency.success")).replaceAll("%cp-args%", command.split("\\s")[1]));
|
|
||||||
}
|
|
||||||
return PaywallOutput.Passed;
|
|
||||||
} else {
|
|
||||||
if (plugin.config.getBoolean("purchase.currency.enable")) {
|
|
||||||
plugin.tex.sendString(panel, PanelPosition.Top, p, Objects.requireNonNull(plugin.config.getString("purchase.currency.failure")));
|
|
||||||
}
|
|
||||||
return PaywallOutput.Blocked;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
plugin.tex.sendString(p, plugin.tag + ChatColor.RED + "Paying Requires Vault and an Economy to work!");
|
|
||||||
return PaywallOutput.Blocked;
|
|
||||||
}
|
|
||||||
} catch (Exception buyc) {
|
|
||||||
plugin.debug(buyc, p);
|
|
||||||
plugin.tex.sendString(p, plugin.tag + plugin.config.getString("config.format.error") + " " + "commands: " + command);
|
|
||||||
return PaywallOutput.Blocked;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
case "hasperm=": {
|
|
||||||
String command = plugin.tex.placeholders(panel, PanelPosition.Top, p, rawCommand);
|
|
||||||
//if player uses hasperm= [perm]
|
|
||||||
if (p.hasPermission(String.valueOf(command.split("\\s")[1]))) {
|
|
||||||
if (plugin.config.getBoolean("purchase.permission.enable") && removal) {
|
|
||||||
plugin.tex.sendString(panel, PanelPosition.Top, p, Objects.requireNonNull(plugin.config.getString("purchase.permission.success")).replaceAll("%cp-args%", command.split("\\s")[1]));
|
|
||||||
}
|
|
||||||
return PaywallOutput.Passed;
|
|
||||||
} else {
|
|
||||||
if (plugin.config.getBoolean("purchase.currency.enable")) {
|
|
||||||
plugin.tex.sendString(panel, PanelPosition.Top, p, Objects.requireNonNull(plugin.config.getString("purchase.permission.failure")));
|
|
||||||
}
|
|
||||||
return PaywallOutput.Blocked;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
case "tokenpaywall=": {
|
|
||||||
String command = plugin.tex.placeholders(panel, PanelPosition.Top, p, rawCommand);
|
|
||||||
//if player uses tokenpaywall= [price]
|
|
||||||
try {
|
|
||||||
if (plugin.getServer().getPluginManager().isPluginEnabled("TokenManager")) {
|
|
||||||
final TokenManager api = (TokenManager) Bukkit.getPluginManager().getPlugin("TokenManager");
|
|
||||||
assert api != null;
|
|
||||||
int balance = Integer.parseInt(Long.toString(api.getTokens(p).orElse(0)));
|
|
||||||
if (balance >= Double.parseDouble(command.split("\\s")[1])) {
|
|
||||||
if (removal) {
|
|
||||||
api.removeTokens(p, Long.parseLong(command.split("\\s")[1]));
|
|
||||||
}
|
|
||||||
//if the message is empty don't send
|
|
||||||
if (plugin.config.getBoolean("purchase.tokens.enable") && removal) {
|
|
||||||
plugin.tex.sendString(panel, PanelPosition.Top, p, Objects.requireNonNull(plugin.config.getString("purchase.tokens.success")).replaceAll("%cp-args%", command.split("\\s")[1]));
|
|
||||||
}
|
|
||||||
|
|
||||||
return PaywallOutput.Passed;
|
|
||||||
} else {
|
|
||||||
if (plugin.config.getBoolean("purchase.tokens.enable")) {
|
|
||||||
plugin.tex.sendString(panel, PanelPosition.Top, p, Objects.requireNonNull(plugin.config.getString("purchase.tokens.failure")));
|
|
||||||
}
|
|
||||||
return PaywallOutput.Blocked;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
plugin.tex.sendString(p, plugin.tag + ChatColor.RED + "Needs TokenManager to work!");
|
|
||||||
return PaywallOutput.Blocked;
|
|
||||||
}
|
|
||||||
} catch (Exception buyc) {
|
|
||||||
plugin.debug(buyc, p);
|
|
||||||
plugin.tex.sendString(p, plugin.tag + plugin.config.getString("config.format.error") + " " + "commands: " + command);
|
|
||||||
return PaywallOutput.Blocked;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
case "item-paywall=": {
|
|
||||||
String command = plugin.tex.placeholders(panel, PanelPosition.Top, p, rawCommand);
|
|
||||||
//if player uses item-paywall= [Material] [Amount] <id:#> WILL NOT TAKE CUSTOM ITEMS
|
|
||||||
//player can use item-paywall= [custom-item] [Amount]
|
|
||||||
List<ItemStack> cont = new ArrayList<>(Arrays.asList(plugin.inventorySaver.getNormalInventory(p)));
|
|
||||||
HashMap<Integer, ItemStack> remCont = new HashMap<>();
|
|
||||||
String[] args = command.split("\\s");
|
|
||||||
try {
|
|
||||||
int id = -1;
|
|
||||||
for (String val : args) {
|
|
||||||
if (val.startsWith("id:")) {
|
|
||||||
id = Integer.parseInt(val.substring(3));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//create the item to be removed
|
|
||||||
ItemStack sellItem;
|
|
||||||
if (Material.matchMaterial(args[1]) == null) {
|
|
||||||
sellItem = plugin.itemCreate.makeCustomItemFromConfig(panel, PanelPosition.Top, panel.getConfig().getConfigurationSection("custom-item." + args[1]), p, true, true, false);
|
|
||||||
sellItem.setAmount(Integer.parseInt(args[2]));
|
|
||||||
} else {
|
|
||||||
sellItem = new ItemStack(Objects.requireNonNull(Material.matchMaterial(args[1])), Integer.parseInt(args[2]));
|
|
||||||
}
|
|
||||||
//this is not a boolean because it needs to return an int
|
|
||||||
PaywallOutput removedItem = PaywallOutput.Blocked;
|
|
||||||
|
|
||||||
int remainingAmount = sellItem.getAmount();
|
|
||||||
//loop through items in the inventory
|
|
||||||
for (int f = 0; f < 36; f++) {
|
|
||||||
|
|
||||||
if (cont.get(f) == null) {
|
|
||||||
//skip slot if empty
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
ItemStack itm = cont.get(f);
|
|
||||||
|
|
||||||
if (Material.matchMaterial(args[1]) == null) {
|
|
||||||
//item-paywall is a custom item as it is not a material
|
|
||||||
if (plugin.itemCreate.isIdentical(sellItem, itm, Objects.requireNonNull(panel.getConfig().getConfigurationSection("custom-item." + args[1])).contains("nbt"))) {
|
|
||||||
ItemStack add = new ItemStack(p.getInventory().getItem(f).getType(), p.getInventory().getItem(f).getAmount());
|
|
||||||
remainingAmount -= add.getAmount();
|
|
||||||
if (removal) remCont.put(f,add);
|
|
||||||
if (remainingAmount <= 0) {
|
|
||||||
removedItem = PaywallOutput.Passed;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//if custom item is a mmo item (1.14+ for the API)
|
|
||||||
try {
|
|
||||||
if (plugin.getServer().getPluginManager().isPluginEnabled("MMOItems") && panel.getConfig().getString("custom-item." + args[1] + ".material").startsWith("mmo=")) {
|
|
||||||
String customItemMaterial = panel.getConfig().getString("custom-item." + args[1] + ".material");
|
|
||||||
String mmoType = customItemMaterial.split("\\s")[1];
|
|
||||||
String mmoID = customItemMaterial.split("\\s")[2];
|
|
||||||
|
|
||||||
if (plugin.isMMOItem(itm, mmoType, mmoID)) {
|
|
||||||
ItemStack add = new ItemStack(p.getInventory().getItem(f).getType(), p.getInventory().getItem(f).getAmount());
|
|
||||||
remainingAmount -= add.getAmount();
|
|
||||||
if (removal) remCont.put(f,add);
|
|
||||||
if (remainingAmount <= 0) {
|
|
||||||
removedItem = PaywallOutput.Passed;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (Exception ex) {
|
|
||||||
plugin.debug(ex, p);
|
|
||||||
}
|
|
||||||
|
|
||||||
} else {
|
|
||||||
//if the item is a standard material
|
|
||||||
if (itm.getType() == sellItem.getType()) {
|
|
||||||
if(itm.hasItemMeta()){
|
|
||||||
//If item has custom meta continue to next item.
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
//Check if the item matches the id set. If not continue to next in loop.
|
|
||||||
if (id != -1 && itm.getDurability() != id) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
//Adding item to the remove list then checking if we have reached the required amount.
|
|
||||||
ItemStack add = new ItemStack(itm.getType(), itm.getAmount());
|
|
||||||
remainingAmount -= add.getAmount();
|
|
||||||
if (removal) remCont.put(f,add);
|
|
||||||
if (remainingAmount <= 0) {
|
|
||||||
removedItem = PaywallOutput.Passed;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (remainingAmount <= 0) {
|
|
||||||
for(Map.Entry<Integer, ItemStack> entry : remCont.entrySet()) {
|
|
||||||
ItemStack remItem = entry.getValue();
|
|
||||||
|
|
||||||
//Check if its the last item in the loop and only subtract the remaining amount.
|
|
||||||
if (sellItem.getAmount() < remItem.getAmount()) {
|
|
||||||
if (plugin.inventorySaver.hasNormalInventory(p)) {
|
|
||||||
if (removal)
|
|
||||||
p.getInventory().getItem(entry.getKey()).setAmount(remItem.getAmount() - sellItem.getAmount());
|
|
||||||
p.updateInventory();
|
|
||||||
} else {
|
|
||||||
if (removal)
|
|
||||||
cont.get(entry.getKey()).setAmount(remItem.getAmount() - sellItem.getAmount());
|
|
||||||
plugin.inventorySaver.inventoryConfig.set(p.getUniqueId().toString(), plugin.itemSerializer.itemStackArrayToBase64(cont.toArray(new ItemStack[0])));
|
|
||||||
}
|
|
||||||
} else { //If its anywhere but the last in loop just get rid of the items.
|
|
||||||
if (plugin.inventorySaver.hasNormalInventory(p)) {
|
|
||||||
if (removal) p.getInventory().setItem(entry.getKey(), null);
|
|
||||||
//p.getInventory().remove(entry.getValue());
|
|
||||||
//p.getInventory().getItem(entry.getKey()).setAmount(0);
|
|
||||||
p.updateInventory();
|
|
||||||
} else {
|
|
||||||
if (removal) cont.remove(entry.getValue());
|
|
||||||
//cont.get(entry.getKey()).setAmount(0);
|
|
||||||
plugin.inventorySaver.inventoryConfig.set(p.getUniqueId().toString(), plugin.itemSerializer.itemStackArrayToBase64(cont.toArray(new ItemStack[0])));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (removal) sellItem.setAmount(sellItem.getAmount() - remItem.getAmount());
|
|
||||||
}
|
|
||||||
|
|
||||||
removedItem = PaywallOutput.Passed;
|
|
||||||
}
|
|
||||||
|
|
||||||
//send message and return
|
|
||||||
if (removedItem == PaywallOutput.Blocked) {
|
|
||||||
if (plugin.config.getBoolean("purchase.item.enable")) {
|
|
||||||
//no item was found
|
|
||||||
plugin.tex.sendString(panel, PanelPosition.Top, p, Objects.requireNonNull(plugin.config.getString("purchase.item.failure")));
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (plugin.config.getBoolean("purchase.item.enable") && removal) {
|
|
||||||
//item was removed
|
|
||||||
plugin.tex.sendString(panel, PanelPosition.Top, p, Objects.requireNonNull(plugin.config.getString("purchase.item.success")).replaceAll("%cp-args%", command.split("\\s")[1]));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return removedItem;
|
|
||||||
} catch (Exception buyc) {
|
|
||||||
plugin.debug(buyc, p);
|
|
||||||
plugin.tex.sendString(p, plugin.tag + plugin.config.getString("config.format.error") + " " + "commands: " + command);
|
|
||||||
return PaywallOutput.Blocked;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
case "xp-paywall=": {
|
|
||||||
String command = plugin.tex.placeholders(panel, PanelPosition.Top, p, rawCommand);
|
|
||||||
//if player uses xp-paywall= <price> <levels:points>
|
|
||||||
try {
|
|
||||||
int balance;
|
|
||||||
if (command.split("\\s")[2].startsWith("level")) {
|
|
||||||
balance = p.getLevel();
|
|
||||||
} else {
|
|
||||||
balance = getPlayerExp(p);
|
|
||||||
}
|
|
||||||
if (balance >= Integer.parseInt(command.split("\\s")[1])) {
|
|
||||||
if (command.split("\\s")[2].startsWith("level")) {
|
|
||||||
if (removal) p.setLevel(p.getLevel() - Integer.parseInt(command.split("\\s")[1]));
|
|
||||||
} else {
|
|
||||||
if (removal) removePlayerExp(p, Integer.parseInt(command.split("\\s")[1]));
|
|
||||||
}
|
|
||||||
//if the message is empty don't send
|
|
||||||
if (plugin.config.getBoolean("purchase.xp.enable") && removal) {
|
|
||||||
plugin.tex.sendString(panel, PanelPosition.Top, p, Objects.requireNonNull(plugin.config.getString("purchase.xp.success")).replaceAll("%cp-args%", command.split("\\s")[1]));
|
|
||||||
}
|
|
||||||
return PaywallOutput.Passed;
|
|
||||||
} else {
|
|
||||||
if (plugin.config.getBoolean("purchase.xp.enable")) {
|
|
||||||
plugin.tex.sendString(panel, PanelPosition.Top, p, Objects.requireNonNull(plugin.config.getString("purchase.xp.failure")));
|
|
||||||
}
|
|
||||||
return PaywallOutput.Blocked;
|
|
||||||
}
|
|
||||||
} catch (Exception buyc) {
|
|
||||||
plugin.debug(buyc, p);
|
|
||||||
plugin.tex.sendString(p, plugin.tag + plugin.config.getString("config.format.error") + " " + "commands: " + command);
|
|
||||||
return PaywallOutput.Blocked;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
case "data-paywall=": {
|
|
||||||
String command = plugin.tex.placeholders(panel, PanelPosition.Top, p, rawCommand);
|
|
||||||
//if player uses data-paywall= <data> <amount>
|
|
||||||
try {
|
|
||||||
if (Double.parseDouble(plugin.panelData.getUserData(p.getUniqueId(), command.split("\\s")[1])) >= Double.parseDouble(command.split("\\s")[2])) {
|
|
||||||
if (removal)
|
|
||||||
plugin.panelData.doDataMath(p.getUniqueId(), command.split("\\s")[1], "-" + plugin.tex.placeholdersNoColour(panel, PanelPosition.Top, p, command.split("\\s")[2]));
|
|
||||||
//if the message is empty don't send
|
|
||||||
if (plugin.config.getBoolean("purchase.data.enable")) {
|
|
||||||
plugin.tex.sendString(panel, PanelPosition.Top, p, Objects.requireNonNull(plugin.config.getString("purchase.data.success")).replaceAll("%cp-args%", command.split("\\s")[1]));
|
|
||||||
}
|
|
||||||
return PaywallOutput.Passed;
|
|
||||||
} else {
|
|
||||||
if (plugin.config.getBoolean("purchase.data.enable")) {
|
|
||||||
plugin.tex.sendString(panel, PanelPosition.Top, p, Objects.requireNonNull(plugin.config.getString("purchase.data.failure")));
|
|
||||||
}
|
|
||||||
return PaywallOutput.Blocked;
|
|
||||||
}
|
|
||||||
} catch (Exception buyc) {
|
|
||||||
plugin.debug(buyc, p);
|
|
||||||
plugin.tex.sendString(p, plugin.tag + plugin.config.getString("config.format.error") + " " + "commands: " + command);
|
|
||||||
return PaywallOutput.Blocked;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//Experience math is a bit doggy doo doo so these will help to calculate values
|
|
||||||
// Calculate total experience up to a level
|
|
||||||
|
|
||||||
// @author thelonelywolf@https://github.com/TheLonelyWolf1
|
|
||||||
// @date 06 August 2021
|
|
||||||
private int getExpAtLevel(int level) {
|
|
||||||
if (level <= 16) {
|
|
||||||
return (int) (Math.pow(level, 2) + 6 * level);
|
|
||||||
} else if (level <= 31) {
|
|
||||||
return (int) (2.5 * Math.pow(level, 2) - 40.5 * level + 360.0);
|
|
||||||
} else {
|
|
||||||
return (int) (4.5 * Math.pow(level, 2) - 162.5 * level + 2220.0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Calculate amount of EXP needed to level up
|
|
||||||
private int getExpToLevelUp(int level) {
|
|
||||||
if (level <= 15) {
|
|
||||||
return 2 * level + 7;
|
|
||||||
} else if (level <= 30) {
|
|
||||||
return 5 * level - 38;
|
|
||||||
} else {
|
|
||||||
return 9 * level - 158;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Calculate player's current EXP amount
|
|
||||||
private int getPlayerExp(Player player) {
|
|
||||||
int exp = 0;
|
|
||||||
int level = player.getLevel();
|
|
||||||
|
|
||||||
// Get the amount of XP in past levels
|
|
||||||
exp += getExpAtLevel(level);
|
|
||||||
|
|
||||||
// Get amount of XP towards next level
|
|
||||||
exp += Math.round(getExpToLevelUp(level) * player.getExp());
|
|
||||||
|
|
||||||
return exp;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Take EXP
|
|
||||||
private int removePlayerExp(Player player, int exp) {
|
|
||||||
// Get player's current exp
|
|
||||||
int currentExp = getPlayerExp(player);
|
|
||||||
|
|
||||||
// Reset player's current exp to 0
|
|
||||||
player.setExp(0);
|
|
||||||
player.setLevel(0);
|
|
||||||
|
|
||||||
// Give the player their exp back, with the difference
|
|
||||||
int newExp = currentExp - exp;
|
|
||||||
player.giveExp(newExp);
|
|
||||||
|
|
||||||
// Return the player's new exp amount
|
|
||||||
return newExp;
|
|
||||||
}
|
|
||||||
}
|
|
57
src/me/rockyhawk/commandpanels/commandtags/PaywallEvent.java
Normal file
57
src/me/rockyhawk/commandpanels/commandtags/PaywallEvent.java
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
package me.rockyhawk.commandpanels.commandtags;
|
||||||
|
|
||||||
|
import me.rockyhawk.commandpanels.CommandPanels;
|
||||||
|
import me.rockyhawk.commandpanels.api.Panel;
|
||||||
|
import me.rockyhawk.commandpanels.openpanelsmanager.PanelPosition;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.Event;
|
||||||
|
import org.bukkit.event.HandlerList;
|
||||||
|
|
||||||
|
public class PaywallEvent extends Event {
|
||||||
|
|
||||||
|
public final Player p;
|
||||||
|
public final Panel panel;
|
||||||
|
public String[] raw;
|
||||||
|
public String[] args;
|
||||||
|
public String name;
|
||||||
|
public PanelPosition pos;
|
||||||
|
public boolean doDelete = true; //if payment should be removed or not
|
||||||
|
public PaywallOutput PAYWALL_OUTPUT = PaywallOutput.NotApplicable; //the final output
|
||||||
|
|
||||||
|
public PaywallEvent(CommandPanels plugin, Panel panel1, PanelPosition position, Player player, String rawCommand1) {
|
||||||
|
this.p = player;
|
||||||
|
this.panel = panel1;
|
||||||
|
this.pos = position;
|
||||||
|
|
||||||
|
//do nopapi= tag which will stop PlaceholderAPI placeholders from executing
|
||||||
|
boolean doApiPlaceholders = true;
|
||||||
|
if(rawCommand1.startsWith("nopapi= ")){
|
||||||
|
rawCommand1 = rawCommand1.replace("nopapi= ","");
|
||||||
|
doApiPlaceholders = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
String[] split = rawCommand1.split(" ", 2);
|
||||||
|
if(split.length == 1){
|
||||||
|
split = new String[]{split[0],""};
|
||||||
|
}
|
||||||
|
|
||||||
|
this.name = split[0].trim();
|
||||||
|
this.raw = split[1].trim().split("\\s");
|
||||||
|
if(doApiPlaceholders) {
|
||||||
|
this.args = plugin.tex.attachPlaceholders(panel1,pos, player, split[1].trim()).split("\\s");
|
||||||
|
}else{
|
||||||
|
this.args = ChatColor.translateAlternateColorCodes('&',plugin.placeholders.setPlaceholders(panel, pos, p,split[1].trim(),false)).split("\\s");
|
||||||
|
this.args = ChatColor.translateAlternateColorCodes('&',plugin.placeholders.setPlaceholders(panel, pos, p,split[1].trim(),true)).split("\\s");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final HandlerList HANDLERS = new HandlerList();
|
||||||
|
public HandlerList getHandlers() {
|
||||||
|
return HANDLERS;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static HandlerList getHandlerList() {
|
||||||
|
return HANDLERS;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,44 @@
|
|||||||
|
package me.rockyhawk.commandpanels.commandtags.paywalls;
|
||||||
|
|
||||||
|
import me.rockyhawk.commandpanels.CommandPanels;
|
||||||
|
import me.rockyhawk.commandpanels.commandtags.PaywallEvent;
|
||||||
|
import me.rockyhawk.commandpanels.commandtags.PaywallOutput;
|
||||||
|
import me.rockyhawk.commandpanels.openpanelsmanager.PanelPosition;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
public class DataPaywall implements Listener {
|
||||||
|
CommandPanels plugin;
|
||||||
|
public DataPaywall(CommandPanels pl) {
|
||||||
|
this.plugin = pl;
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void commandTag(PaywallEvent e){
|
||||||
|
if(e.name.equalsIgnoreCase("data-paywall=")){
|
||||||
|
//if player uses data-paywall= <data> <amount>
|
||||||
|
try {
|
||||||
|
if (Double.parseDouble(plugin.panelData.getUserData(e.p.getUniqueId(), e.args[0])) >= Double.parseDouble(e.args[1])) {
|
||||||
|
if (e.doDelete)
|
||||||
|
plugin.panelData.doDataMath(e.p.getUniqueId(), e.args[0], "-" + plugin.tex.placeholdersNoColour(e.panel, PanelPosition.Top, e.p, e.args[1]));
|
||||||
|
//if the message is empty don't send
|
||||||
|
if (plugin.config.getBoolean("purchase.data.enable")) {
|
||||||
|
plugin.tex.sendString(e.panel, PanelPosition.Top, e.p, Objects.requireNonNull(plugin.config.getString("purchase.data.success")).replaceAll("%cp-args%", e.args[0]));
|
||||||
|
}
|
||||||
|
e.PAYWALL_OUTPUT = PaywallOutput.Passed;
|
||||||
|
} else {
|
||||||
|
if (plugin.config.getBoolean("purchase.data.enable")) {
|
||||||
|
plugin.tex.sendString(e.panel, PanelPosition.Top, e.p, Objects.requireNonNull(plugin.config.getString("purchase.data.failure")));
|
||||||
|
}
|
||||||
|
e.PAYWALL_OUTPUT = PaywallOutput.Blocked;
|
||||||
|
}
|
||||||
|
} catch (Exception buyc) {
|
||||||
|
plugin.debug(buyc, e.p);
|
||||||
|
plugin.tex.sendString(e.p, plugin.tag + plugin.config.getString("config.format.error") + " " + "commands: " + e.name);
|
||||||
|
e.PAYWALL_OUTPUT = PaywallOutput.Blocked;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,50 @@
|
|||||||
|
package me.rockyhawk.commandpanels.commandtags.paywalls;
|
||||||
|
|
||||||
|
import me.rockyhawk.commandpanels.CommandPanels;
|
||||||
|
import me.rockyhawk.commandpanels.commandtags.PaywallEvent;
|
||||||
|
import me.rockyhawk.commandpanels.commandtags.PaywallOutput;
|
||||||
|
import me.rockyhawk.commandpanels.openpanelsmanager.PanelPosition;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
public class Hasperm implements Listener {
|
||||||
|
CommandPanels plugin;
|
||||||
|
public Hasperm(CommandPanels pl) {
|
||||||
|
this.plugin = pl;
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void commandTag(PaywallEvent e){
|
||||||
|
if(e.name.equalsIgnoreCase("hasperm=")){
|
||||||
|
//if player uses hasperm= [perm]
|
||||||
|
if (e.p.hasPermission(e.args[0])) {
|
||||||
|
if (plugin.config.getBoolean("purchase.permission.enable") && e.doDelete) {
|
||||||
|
plugin.tex.sendString(e.panel, PanelPosition.Top, e.p, Objects.requireNonNull(plugin.config.getString("purchase.permission.success")).replaceAll("%cp-args%", e.args[0]));
|
||||||
|
}
|
||||||
|
e.PAYWALL_OUTPUT = PaywallOutput.Passed;
|
||||||
|
} else {
|
||||||
|
if (plugin.config.getBoolean("purchase.currency.enable")) {
|
||||||
|
plugin.tex.sendString(e.panel, PanelPosition.Top, e.p, Objects.requireNonNull(plugin.config.getString("purchase.permission.failure")));
|
||||||
|
}
|
||||||
|
e.PAYWALL_OUTPUT = PaywallOutput.Blocked;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(e.name.equalsIgnoreCase("hasnoperm=")){
|
||||||
|
//if player uses hasnoperm= [perm]
|
||||||
|
if (!e.p.hasPermission(e.args[0])) {
|
||||||
|
if (plugin.config.getBoolean("purchase.permission.enable") && e.doDelete) {
|
||||||
|
plugin.tex.sendString(e.panel, PanelPosition.Top, e.p, Objects.requireNonNull(plugin.config.getString("purchase.permission.success")).replaceAll("%cp-args%", e.args[0]));
|
||||||
|
}
|
||||||
|
e.PAYWALL_OUTPUT = PaywallOutput.Passed;
|
||||||
|
} else {
|
||||||
|
if (plugin.config.getBoolean("purchase.currency.enable")) {
|
||||||
|
plugin.tex.sendString(e.panel, PanelPosition.Top, e.p, Objects.requireNonNull(plugin.config.getString("purchase.permission.failure")));
|
||||||
|
}
|
||||||
|
e.PAYWALL_OUTPUT = PaywallOutput.Blocked;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,49 @@
|
|||||||
|
package me.rockyhawk.commandpanels.commandtags.paywalls;
|
||||||
|
|
||||||
|
import me.rockyhawk.commandpanels.CommandPanels;
|
||||||
|
import me.rockyhawk.commandpanels.commandtags.PaywallEvent;
|
||||||
|
import me.rockyhawk.commandpanels.commandtags.PaywallOutput;
|
||||||
|
import me.rockyhawk.commandpanels.openpanelsmanager.PanelPosition;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
public class Paywall implements Listener {
|
||||||
|
CommandPanels plugin;
|
||||||
|
public Paywall(CommandPanels pl) {
|
||||||
|
this.plugin = pl;
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void commandTag(PaywallEvent e){
|
||||||
|
if(e.name.equalsIgnoreCase("paywall=")){
|
||||||
|
//if player uses paywall= [price]
|
||||||
|
try {
|
||||||
|
if (plugin.econ != null) {
|
||||||
|
double paywallAmount = Double.parseDouble(e.args[0]);
|
||||||
|
if (plugin.econ.getBalance(e.p) >= paywallAmount) {
|
||||||
|
if (e.doDelete) plugin.econ.withdrawPlayer(e.p, paywallAmount);
|
||||||
|
if (plugin.config.getBoolean("purchase.currency.enable") && e.doDelete) {
|
||||||
|
plugin.tex.sendString(e.panel, PanelPosition.Top, e.p, Objects.requireNonNull(plugin.config.getString("purchase.currency.success")).replaceAll("%cp-args%", e.args[0]));
|
||||||
|
}
|
||||||
|
e.PAYWALL_OUTPUT = PaywallOutput.Passed;
|
||||||
|
} else {
|
||||||
|
if (plugin.config.getBoolean("purchase.currency.enable")) {
|
||||||
|
plugin.tex.sendString(e.panel, PanelPosition.Top, e.p, Objects.requireNonNull(plugin.config.getString("purchase.currency.failure")));
|
||||||
|
}
|
||||||
|
e.PAYWALL_OUTPUT = PaywallOutput.Blocked;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
plugin.tex.sendString(e.p, plugin.tag + ChatColor.RED + "Paying Requires Vault and an Economy to work!");
|
||||||
|
e.PAYWALL_OUTPUT = PaywallOutput.Blocked;
|
||||||
|
}
|
||||||
|
} catch (Exception buyc) {
|
||||||
|
plugin.debug(buyc, e.p);
|
||||||
|
plugin.tex.sendString(e.p, plugin.tag + plugin.config.getString("config.format.error") + " " + "commands: " + e.name);
|
||||||
|
e.PAYWALL_OUTPUT = PaywallOutput.Blocked;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,77 @@
|
|||||||
|
package me.rockyhawk.commandpanels.commandtags.paywalls;
|
||||||
|
import me.rockyhawk.commandpanels.CommandPanels;
|
||||||
|
import me.rockyhawk.commandpanels.commandtags.PaywallEvent;
|
||||||
|
import me.rockyhawk.commandpanels.commandtags.PaywallOutput;
|
||||||
|
import me.rockyhawk.commandpanels.openpanelsmanager.PanelPosition;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
import java.util.Objects;
|
||||||
|
import java.util.OptionalLong;
|
||||||
|
|
||||||
|
public class TokenPaywall implements Listener {
|
||||||
|
private final CommandPanels plugin;
|
||||||
|
|
||||||
|
public TokenPaywall(CommandPanels pl) {
|
||||||
|
this.plugin = pl;
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void commandTag(PaywallEvent e) {
|
||||||
|
if (e.name.equalsIgnoreCase("tokenpaywall=")) {
|
||||||
|
// if player uses tokenpaywall= [price]
|
||||||
|
try {
|
||||||
|
if (plugin.getServer().getPluginManager().isPluginEnabled("TokenManager")) {
|
||||||
|
// Using reflection in this method as TokenManager has issues with Maven due to the Jitpack dependency
|
||||||
|
Object api = Bukkit.getPluginManager().getPlugin("TokenManager");
|
||||||
|
if (api != null) {
|
||||||
|
// Use reflection to access the getTokens and removeTokens methods
|
||||||
|
Method getTokensMethod = api.getClass().getMethod("getTokens", org.bukkit.entity.Player.class);
|
||||||
|
Method removeTokensMethod = api.getClass().getMethod("removeTokens", org.bukkit.entity.Player.class, long.class);
|
||||||
|
|
||||||
|
// Call getTokens
|
||||||
|
Object result = getTokensMethod.invoke(api, e.p);
|
||||||
|
long balance;
|
||||||
|
|
||||||
|
if (result instanceof OptionalLong) {
|
||||||
|
balance = ((OptionalLong) result).orElse(0L);
|
||||||
|
} else {
|
||||||
|
balance = 0L;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (balance >= Double.parseDouble(e.args[0])) {
|
||||||
|
if (e.doDelete) {
|
||||||
|
// Call removeTokens
|
||||||
|
removeTokensMethod.invoke(api, e.p, Long.parseLong(e.args[0]));
|
||||||
|
}
|
||||||
|
// if the message is empty don't send
|
||||||
|
if (plugin.config.getBoolean("purchase.tokens.enable") && e.doDelete) {
|
||||||
|
plugin.tex.sendString(e.panel, PanelPosition.Top, e.p, Objects.requireNonNull(plugin.config.getString("purchase.tokens.success")).replaceAll("%cp-args%", e.args[0]));
|
||||||
|
}
|
||||||
|
|
||||||
|
e.PAYWALL_OUTPUT = PaywallOutput.Passed;
|
||||||
|
} else {
|
||||||
|
if (plugin.config.getBoolean("purchase.tokens.enable")) {
|
||||||
|
plugin.tex.sendString(e.panel, PanelPosition.Top, e.p, Objects.requireNonNull(plugin.config.getString("purchase.tokens.failure")));
|
||||||
|
}
|
||||||
|
e.PAYWALL_OUTPUT = PaywallOutput.Blocked;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
plugin.tex.sendString(e.p, plugin.tag + ChatColor.RED + "Needs TokenManager to work!");
|
||||||
|
e.PAYWALL_OUTPUT = PaywallOutput.Blocked;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
plugin.tex.sendString(e.p, plugin.tag + ChatColor.RED + "Needs TokenManager to work!");
|
||||||
|
e.PAYWALL_OUTPUT = PaywallOutput.Blocked;
|
||||||
|
}
|
||||||
|
} catch (Exception ex) {
|
||||||
|
plugin.debug(ex, e.p);
|
||||||
|
plugin.tex.sendString(e.p, plugin.tag + plugin.config.getString("config.format.error") + " " + "commands: " + e.name);
|
||||||
|
e.PAYWALL_OUTPUT = PaywallOutput.Blocked;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,111 @@
|
|||||||
|
package me.rockyhawk.commandpanels.commandtags.paywalls;
|
||||||
|
|
||||||
|
import me.rockyhawk.commandpanels.CommandPanels;
|
||||||
|
import me.rockyhawk.commandpanels.commandtags.PaywallEvent;
|
||||||
|
import me.rockyhawk.commandpanels.commandtags.PaywallOutput;
|
||||||
|
import me.rockyhawk.commandpanels.openpanelsmanager.PanelPosition;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
public class XpPaywall implements Listener {
|
||||||
|
CommandPanels plugin;
|
||||||
|
public XpPaywall(CommandPanels pl) {
|
||||||
|
this.plugin = pl;
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void commandTag(PaywallEvent e){
|
||||||
|
if(e.name.equalsIgnoreCase("xp-paywall=")){
|
||||||
|
//if player uses xp-paywall= <price> <level:points>
|
||||||
|
try {
|
||||||
|
int balance;
|
||||||
|
if (e.args[1].startsWith("level")) {
|
||||||
|
balance = e.p.getLevel();
|
||||||
|
} else {
|
||||||
|
balance = getPlayerExp(e.p);
|
||||||
|
}
|
||||||
|
if (balance >= Integer.parseInt(e.args[0])) {
|
||||||
|
if (e.args[1].startsWith("level")) {
|
||||||
|
if (e.doDelete) e.p.setLevel(e.p.getLevel() - Integer.parseInt(e.args[0]));
|
||||||
|
} else {
|
||||||
|
if (e.doDelete) removePlayerExp(e.p, Integer.parseInt(e.args[0]));
|
||||||
|
}
|
||||||
|
//if the message is empty don't send
|
||||||
|
if (plugin.config.getBoolean("purchase.xp.enable") && e.doDelete) {
|
||||||
|
plugin.tex.sendString(e.panel, PanelPosition.Top, e.p, Objects.requireNonNull(plugin.config.getString("purchase.xp.success")).replaceAll("%cp-args%", e.args[0]));
|
||||||
|
}
|
||||||
|
e.PAYWALL_OUTPUT = PaywallOutput.Passed;
|
||||||
|
} else {
|
||||||
|
if (plugin.config.getBoolean("purchase.xp.enable")) {
|
||||||
|
plugin.tex.sendString(e.panel, PanelPosition.Top, e.p, Objects.requireNonNull(plugin.config.getString("purchase.xp.failure")));
|
||||||
|
}
|
||||||
|
e.PAYWALL_OUTPUT = PaywallOutput.Blocked;
|
||||||
|
}
|
||||||
|
} catch (Exception buyc) {
|
||||||
|
plugin.debug(buyc, e.p);
|
||||||
|
plugin.tex.sendString(e.p, plugin.tag + plugin.config.getString("config.format.error") + " " + "commands: " + e.name);
|
||||||
|
e.PAYWALL_OUTPUT = PaywallOutput.Blocked;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//Experience math is a bit doggy doo doo so these will help to calculate values
|
||||||
|
// Calculate total experience up to a level
|
||||||
|
|
||||||
|
// @author thelonelywolf@https://github.com/TheLonelyWolf1
|
||||||
|
// @date 06 August 2021
|
||||||
|
private int getExpAtLevel(int level) {
|
||||||
|
if (level <= 16) {
|
||||||
|
return (int) (Math.pow(level, 2) + 6 * level);
|
||||||
|
} else if (level <= 31) {
|
||||||
|
return (int) (2.5 * Math.pow(level, 2) - 40.5 * level + 360.0);
|
||||||
|
} else {
|
||||||
|
return (int) (4.5 * Math.pow(level, 2) - 162.5 * level + 2220.0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Calculate amount of EXP needed to level up
|
||||||
|
private int getExpToLevelUp(int level) {
|
||||||
|
if (level <= 15) {
|
||||||
|
return 2 * level + 7;
|
||||||
|
} else if (level <= 30) {
|
||||||
|
return 5 * level - 38;
|
||||||
|
} else {
|
||||||
|
return 9 * level - 158;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Calculate player's current EXP amount
|
||||||
|
private int getPlayerExp(Player player) {
|
||||||
|
int exp = 0;
|
||||||
|
int level = player.getLevel();
|
||||||
|
|
||||||
|
// Get the amount of XP in past levels
|
||||||
|
exp += getExpAtLevel(level);
|
||||||
|
|
||||||
|
// Get amount of XP towards next level
|
||||||
|
exp += Math.round(getExpToLevelUp(level) * player.getExp());
|
||||||
|
|
||||||
|
return exp;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Take EXP
|
||||||
|
private int removePlayerExp(Player player, int exp) {
|
||||||
|
// Get player's current exp
|
||||||
|
int currentExp = getPlayerExp(player);
|
||||||
|
|
||||||
|
// Reset player's current exp to 0
|
||||||
|
player.setExp(0);
|
||||||
|
player.setLevel(0);
|
||||||
|
|
||||||
|
// Give the player their exp back, with the difference
|
||||||
|
int newExp = currentExp - exp;
|
||||||
|
player.giveExp(newExp);
|
||||||
|
|
||||||
|
// Return the player's new exp amount
|
||||||
|
return newExp;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,21 @@
|
|||||||
|
package me.rockyhawk.commandpanels.commandtags.paywalls.itempaywall;
|
||||||
|
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
|
public class InventoryOperationResult {
|
||||||
|
private final boolean success;
|
||||||
|
private final ItemStack[] inventory;
|
||||||
|
|
||||||
|
public InventoryOperationResult(boolean success, ItemStack[] inventory) {
|
||||||
|
this.success = success;
|
||||||
|
this.inventory = inventory;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isSuccess() {
|
||||||
|
return success;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ItemStack[] getInventory() {
|
||||||
|
return inventory;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,128 @@
|
|||||||
|
package me.rockyhawk.commandpanels.commandtags.paywalls.itempaywall;
|
||||||
|
|
||||||
|
import me.rockyhawk.commandpanels.CommandPanels;
|
||||||
|
import me.rockyhawk.commandpanels.commandtags.PaywallEvent;
|
||||||
|
import me.rockyhawk.commandpanels.commandtags.PaywallOutput;
|
||||||
|
import me.rockyhawk.commandpanels.openpanelsmanager.PanelPosition;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
public class ItemPaywall implements Listener {
|
||||||
|
CommandPanels plugin;
|
||||||
|
public ItemPaywall(CommandPanels pl) {
|
||||||
|
this.plugin = pl;
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void commandTag(PaywallEvent e){
|
||||||
|
if(e.name.equalsIgnoreCase("item-paywall=")){
|
||||||
|
//if player uses item-paywall= [Material] [Amount] <IGNORENBT> WILL NOT TAKE CUSTOM ITEMS. IGNORENBT lets nbt items through. Useful for spawner edge cases.
|
||||||
|
//player can use item-paywall= [custom-item] [Amount]
|
||||||
|
try {
|
||||||
|
boolean ignoreNBT = false;
|
||||||
|
for (String val : e.args) {
|
||||||
|
//This is here for when people want to take nbt items like spawners with types in a check for spawners.
|
||||||
|
if (val.equals("IGNORENBT")) {
|
||||||
|
ignoreNBT = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//create the item to be removed
|
||||||
|
ItemStack sellItem;
|
||||||
|
if (Material.matchMaterial(e.args[0]) == null) {
|
||||||
|
//If custom item set to custom item data.
|
||||||
|
sellItem = plugin.itemCreate.makeCustomItemFromConfig(e.panel, PanelPosition.Top, e.panel.getConfig().getConfigurationSection("custom-item." + e.args[0]), e.p, true, true, false);
|
||||||
|
sellItem.setAmount(Integer.parseInt(e.args[1]));
|
||||||
|
} else {
|
||||||
|
//If normal just set material.
|
||||||
|
sellItem = new ItemStack(Objects.requireNonNull(Material.matchMaterial(e.args[0])), Integer.parseInt(e.args[1]));
|
||||||
|
}
|
||||||
|
|
||||||
|
//try to remove the item and determine outcome
|
||||||
|
PaywallOutput removedItem = PaywallOutput.Blocked;
|
||||||
|
if(removeItem(e.p, sellItem, ignoreNBT, e.doDelete)){
|
||||||
|
removedItem = PaywallOutput.Passed;
|
||||||
|
}
|
||||||
|
|
||||||
|
//send message and return
|
||||||
|
if (removedItem == PaywallOutput.Blocked) {
|
||||||
|
if (plugin.config.getBoolean("purchase.item.enable")) {
|
||||||
|
//no item found to remove
|
||||||
|
plugin.tex.sendString(e.panel, PanelPosition.Top, e.p, Objects.requireNonNull(plugin.config.getString("purchase.item.failure")));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (plugin.config.getBoolean("purchase.item.enable") && e.doDelete) {
|
||||||
|
//item was removed
|
||||||
|
plugin.tex.sendString(e.panel, PanelPosition.Top, e.p, Objects.requireNonNull(plugin.config.getString("purchase.item.success")).replaceAll("%cp-args%", e.args[0]));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
e.PAYWALL_OUTPUT = removedItem;
|
||||||
|
} catch (Exception buyc) {
|
||||||
|
plugin.debug(buyc, e.p);
|
||||||
|
plugin.tex.sendString(e.p, plugin.tag + plugin.config.getString("config.format.error") + " " + "commands: " + e.name);
|
||||||
|
e.PAYWALL_OUTPUT = PaywallOutput.Blocked;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean removeItem(Player p, ItemStack itemToRemove, boolean ignoreNBT, boolean doDelete) {
|
||||||
|
InventoryOperationResult result;
|
||||||
|
|
||||||
|
if (plugin.inventorySaver.hasNormalInventory(p)) {
|
||||||
|
result = removeItemFromInventory(p.getInventory().getContents(), itemToRemove, ignoreNBT, doDelete);
|
||||||
|
p.getInventory().setContents(result.getInventory());
|
||||||
|
} else {
|
||||||
|
ItemStack[] savedInventory = plugin.inventorySaver.getNormalInventory(p);
|
||||||
|
result = removeItemFromInventory(savedInventory, itemToRemove, ignoreNBT, doDelete);
|
||||||
|
plugin.inventorySaver.inventoryConfig.set(p.getUniqueId().toString(), plugin.itemSerializer.itemStackArrayToBase64(result.getInventory()));
|
||||||
|
}
|
||||||
|
|
||||||
|
return result.isSuccess(); // Return the success status of the inventory operation
|
||||||
|
}
|
||||||
|
|
||||||
|
private InventoryOperationResult removeItemFromInventory(ItemStack[] inventory, ItemStack itemToRemove, boolean ignoreNBT, boolean doDelete) {
|
||||||
|
int amountToRemove = itemToRemove.getAmount();
|
||||||
|
int count = 0;
|
||||||
|
|
||||||
|
for (ItemStack item : inventory) {
|
||||||
|
if (item != null && plugin.itemCreate.isIdentical(item, itemToRemove, !ignoreNBT)) {
|
||||||
|
count += item.getAmount();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//return false if the player doesn't have enough items
|
||||||
|
if (count < amountToRemove) {
|
||||||
|
return new InventoryOperationResult(false, inventory); // Not enough items, return with original inventory unchanged
|
||||||
|
}
|
||||||
|
|
||||||
|
//return true because there are enough items, but don't run the code to remove them
|
||||||
|
if(!doDelete){
|
||||||
|
return new InventoryOperationResult(true, inventory);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < inventory.length; i++) {
|
||||||
|
ItemStack currentItem = inventory[i];
|
||||||
|
if (currentItem != null && plugin.itemCreate.isIdentical(currentItem, itemToRemove, !ignoreNBT)) {
|
||||||
|
int removeAmount = Math.min(currentItem.getAmount(), amountToRemove);
|
||||||
|
currentItem.setAmount(currentItem.getAmount() - removeAmount);
|
||||||
|
amountToRemove -= removeAmount;
|
||||||
|
|
||||||
|
if (currentItem.getAmount() == 0) {
|
||||||
|
inventory[i] = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (amountToRemove == 0) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return new InventoryOperationResult(true, inventory); // Return true and the modified inventory
|
||||||
|
}
|
||||||
|
}
|
@ -1,76 +0,0 @@
|
|||||||
package me.rockyhawk.commandpanels.commandtags.tags.economy;
|
|
||||||
|
|
||||||
import me.realized.tokenmanager.api.TokenManager;
|
|
||||||
import me.rockyhawk.commandpanels.CommandPanels;
|
|
||||||
import me.rockyhawk.commandpanels.commandtags.CommandTagEvent;
|
|
||||||
import me.rockyhawk.commandpanels.openpanelsmanager.PanelPosition;
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.ChatColor;
|
|
||||||
import org.bukkit.event.EventHandler;
|
|
||||||
import org.bukkit.event.Listener;
|
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Objects;
|
|
||||||
|
|
||||||
public class BuyCommandTags implements Listener {
|
|
||||||
CommandPanels plugin;
|
|
||||||
public BuyCommandTags(CommandPanels pl) {
|
|
||||||
this.plugin = pl;
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void commandTag(CommandTagEvent e){
|
|
||||||
if(e.name.equalsIgnoreCase("buycommand=")){
|
|
||||||
e.commandTagUsed();
|
|
||||||
//if player uses buycommand [price] [command]
|
|
||||||
try {
|
|
||||||
if (plugin.econ != null) {
|
|
||||||
if (plugin.econ.getBalance(e.p) >= Double.parseDouble(e.args[0])) {
|
|
||||||
plugin.econ.withdrawPlayer(e.p, Double.parseDouble(e.args[0]));
|
|
||||||
//execute command under here
|
|
||||||
String price = e.args[0];
|
|
||||||
String command = String.join(" ",Arrays.copyOfRange(e.raw, 1, e.raw.length));
|
|
||||||
plugin.commandTags.runCommand(e.panel,e.pos,e.p,command);
|
|
||||||
plugin.tex.sendString(e.panel, PanelPosition.Top, e.p, Objects.requireNonNull(plugin.config.getString("purchase.currency.success")).replaceAll("%cp-args%", price));
|
|
||||||
} else {
|
|
||||||
String price = e.args[0];
|
|
||||||
plugin.tex.sendString(e.panel, PanelPosition.Top, e.p, Objects.requireNonNull(plugin.config.getString("purchase.currency.failure")));
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
plugin.tex.sendMessage(e.p, ChatColor.RED + "Buying Requires Vault and an Economy to work!");
|
|
||||||
}
|
|
||||||
} catch (Exception buyc) {
|
|
||||||
plugin.debug(buyc,e.p);
|
|
||||||
plugin.tex.sendMessage(e.p,plugin.config.getString("config.format.error") + " " + "commands: " + e.name);
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if(e.name.equalsIgnoreCase("tokenbuycommand=")){
|
|
||||||
e.commandTagUsed();
|
|
||||||
//if player uses tokenbuycommand [price] [command]
|
|
||||||
try {
|
|
||||||
if (plugin.getServer().getPluginManager().isPluginEnabled("TokenManager")) {
|
|
||||||
TokenManager api = (TokenManager) Bukkit.getServer().getPluginManager().getPlugin("TokenManager");
|
|
||||||
assert api != null;
|
|
||||||
int balance = Integer.parseInt(Long.toString(api.getTokens(e.p).orElse(0)));
|
|
||||||
if (balance >= Double.parseDouble(e.args[0])) {
|
|
||||||
api.removeTokens(e.p, Long.parseLong(e.args[0]));
|
|
||||||
//execute command under here
|
|
||||||
String price = e.args[0];
|
|
||||||
String command = String.join(" ",Arrays.copyOfRange(e.raw, 1, e.raw.length));
|
|
||||||
plugin.commandTags.runCommand(e.panel,e.pos,e.p,command);
|
|
||||||
plugin.tex.sendString(e.panel, PanelPosition.Top, e.p, Objects.requireNonNull(plugin.config.getString("purchase.tokens.success")).replaceAll("%cp-args%", price));
|
|
||||||
} else {
|
|
||||||
String price = e.args[0];
|
|
||||||
plugin.tex.sendString(e.panel, PanelPosition.Top, e.p, Objects.requireNonNull(plugin.config.getString("purchase.tokens.failure")));
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
plugin.tex.sendMessage(e.p, ChatColor.RED + "Buying Requires Vault and an Economy to work!");
|
|
||||||
}
|
|
||||||
} catch (Exception buyc) {
|
|
||||||
plugin.debug(buyc,e.p);
|
|
||||||
plugin.tex.sendMessage(e.p, plugin.config.getString("config.format.error") + " " + "commands: " + e.name);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,90 +0,0 @@
|
|||||||
package me.rockyhawk.commandpanels.commandtags.tags.economy;
|
|
||||||
|
|
||||||
import me.realized.tokenmanager.api.TokenManager;
|
|
||||||
import me.rockyhawk.commandpanels.CommandPanels;
|
|
||||||
import me.rockyhawk.commandpanels.commandtags.CommandTagEvent;
|
|
||||||
import me.rockyhawk.commandpanels.ioclasses.legacy.MinecraftVersions;
|
|
||||||
import me.rockyhawk.commandpanels.openpanelsmanager.PanelPosition;
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.ChatColor;
|
|
||||||
import org.bukkit.Material;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.event.EventHandler;
|
|
||||||
import org.bukkit.event.Listener;
|
|
||||||
import org.bukkit.inventory.ItemStack;
|
|
||||||
|
|
||||||
import java.util.Objects;
|
|
||||||
|
|
||||||
public class BuyItemTags implements Listener {
|
|
||||||
CommandPanels plugin;
|
|
||||||
public BuyItemTags(CommandPanels pl) {
|
|
||||||
this.plugin = pl;
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void commandTag(CommandTagEvent e){
|
|
||||||
if(e.name.equalsIgnoreCase("buy=")){
|
|
||||||
e.commandTagUsed();
|
|
||||||
//if player uses buy= it will be eg. buy= <price> <item> <amount of item> <ID>
|
|
||||||
try {
|
|
||||||
if (plugin.econ != null) {
|
|
||||||
if (plugin.econ.getBalance(e.p) >= Double.parseDouble(e.args[0])) {
|
|
||||||
plugin.econ.withdrawPlayer(e.p, Double.parseDouble(e.args[0]));
|
|
||||||
plugin.tex.sendString(e.panel, PanelPosition.Top, e.p, Objects.requireNonNull(plugin.config.getString("purchase.currency.success")).replaceAll("%cp-args%", e.args[0]));
|
|
||||||
giveItem(e.p, e.args);
|
|
||||||
} else {
|
|
||||||
plugin.tex.sendString(e.panel, PanelPosition.Top, e.p, Objects.requireNonNull(plugin.config.getString("purchase.currency.failure")));
|
|
||||||
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
plugin.tex.sendMessage(e.p, ChatColor.RED + "Buying Requires Vault and an Economy to work!");
|
|
||||||
}
|
|
||||||
} catch (Exception buy) {
|
|
||||||
plugin.debug(buy,e.p);
|
|
||||||
plugin.tex.sendMessage(e.p, plugin.config.getString("config.format.error") + " " + "commands: " + e.name);
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if(e.name.equalsIgnoreCase("tokenbuy=")) {
|
|
||||||
e.commandTagUsed();
|
|
||||||
//if player uses tokenbuy= it will be eg. tokenbuy= <price> <item> <amount of item> <ID>
|
|
||||||
try {
|
|
||||||
if (plugin.getServer().getPluginManager().isPluginEnabled("TokenManager")) {
|
|
||||||
final TokenManager api = (TokenManager) Bukkit.getServer().getPluginManager().getPlugin("TokenManager");
|
|
||||||
assert api != null;
|
|
||||||
int balance = Integer.parseInt(Long.toString(api.getTokens(e.p).orElse(0)));
|
|
||||||
if (balance >= Double.parseDouble(e.args[0])) {
|
|
||||||
api.removeTokens(e.p, Long.parseLong(e.args[0]));
|
|
||||||
plugin.tex.sendMessage(e.p, Objects.requireNonNull(plugin.config.getString("purchase.tokens.success")).replaceAll("%cp-args%", e.args[0]));
|
|
||||||
plugin.tex.sendString(e.panel, PanelPosition.Top, e.p, Objects.requireNonNull(plugin.config.getString("purchase.tokens.success")).replaceAll("%cp-args%", e.args[0]));
|
|
||||||
|
|
||||||
giveItem(e.p,e.args);
|
|
||||||
} else {
|
|
||||||
plugin.tex.sendString(e.panel, PanelPosition.Top, e.p, Objects.requireNonNull(plugin.config.getString("purchase.tokens.failure")));
|
|
||||||
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
plugin.tex.sendMessage(e.p, ChatColor.RED + "Buying Requires TokenManager to work!");
|
|
||||||
}
|
|
||||||
} catch (Exception buy) {
|
|
||||||
plugin.debug(buy, e.p);
|
|
||||||
plugin.tex.sendMessage(e.p, plugin.config.getString("config.format.error") + " " + "commands: " + e.name);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
|
||||||
private void giveItem(Player p, String[] args){
|
|
||||||
//legacy ID
|
|
||||||
byte id = 0;
|
|
||||||
if(plugin.legacy.LOCAL_VERSION.lessThanOrEqualTo(MinecraftVersions.v1_15)) {
|
|
||||||
for (String argsTemp : args) {
|
|
||||||
if (argsTemp.startsWith("id:")) {
|
|
||||||
id = Byte.parseByte(argsTemp.replace("id:", ""));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
plugin.inventorySaver.addItem(p,new ItemStack(Objects.requireNonNull(Material.matchMaterial(args[1])), Integer.parseInt(args[2]),id));
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,205 +0,0 @@
|
|||||||
package me.rockyhawk.commandpanels.commandtags.tags.economy;
|
|
||||||
|
|
||||||
import me.realized.tokenmanager.api.TokenManager;
|
|
||||||
import me.rockyhawk.commandpanels.CommandPanels;
|
|
||||||
import me.rockyhawk.commandpanels.commandtags.CommandTagEvent;
|
|
||||||
import me.rockyhawk.commandpanels.ioclasses.legacy.MinecraftVersions;
|
|
||||||
import me.rockyhawk.commandpanels.openpanelsmanager.PanelPosition;
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.ChatColor;
|
|
||||||
import org.bukkit.Material;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.event.EventHandler;
|
|
||||||
import org.bukkit.event.Listener;
|
|
||||||
import org.bukkit.inventory.ItemStack;
|
|
||||||
import org.bukkit.inventory.meta.PotionMeta;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Objects;
|
|
||||||
|
|
||||||
public class SellItemTags implements Listener {
|
|
||||||
CommandPanels plugin;
|
|
||||||
public SellItemTags(CommandPanels pl) {
|
|
||||||
this.plugin = pl;
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void commandTag(CommandTagEvent e){
|
|
||||||
if(e.name.equalsIgnoreCase("sell=")){
|
|
||||||
e.commandTagUsed();
|
|
||||||
//if player uses sell= it will be eg. sell= <total cashback> <item> <amount of item> [enchanted:KNOCKBACK:1] [potion:JUMP] [custom-data:#]
|
|
||||||
try {
|
|
||||||
if (plugin.econ != null) {
|
|
||||||
int sold = removeItem(e.p, e.args, false);
|
|
||||||
if (sold <= 0) {
|
|
||||||
plugin.tex.sendString(e.panel, PanelPosition.Top, e.p, Objects.requireNonNull(plugin.config.getString("purchase.item.failure")));
|
|
||||||
} else {
|
|
||||||
plugin.econ.depositPlayer(e.p, Double.parseDouble(e.args[0]));
|
|
||||||
plugin.tex.sendString(e.panel, PanelPosition.Top, e.p, Objects.requireNonNull(plugin.config.getString("purchase.item.success")).replaceAll("%cp-args%", e.args[1]).replaceAll("%cp-args2%", "$" + e.args[0]));
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
plugin.tex.sendMessage(e.p, ChatColor.RED + "Selling Requires Vault and an Economy to work!");
|
|
||||||
}
|
|
||||||
} catch (Exception sell) {
|
|
||||||
plugin.debug(sell,e.p);
|
|
||||||
plugin.tex.sendMessage(e.p, plugin.config.getString("config.format.error") + " " + "commands: " + e.name);
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if(e.name.equalsIgnoreCase("sellall=")){
|
|
||||||
e.commandTagUsed();
|
|
||||||
//if player uses sell-all= it will be eg. sell-all= <Per Item Cashback> <item> [enchanted:KNOCKBACK:1] [potion:JUMP]
|
|
||||||
try {
|
|
||||||
if (plugin.econ != null) {
|
|
||||||
int sold = removeItem(e.p, e.args, true);
|
|
||||||
if (sold <= 0) {
|
|
||||||
plugin.tex.sendString(e.panel, PanelPosition.Top, e.p, Objects.requireNonNull(plugin.config.getString("purchase.item.failure")));
|
|
||||||
} else {
|
|
||||||
plugin.econ.depositPlayer(e.p, Double.parseDouble(e.args[0]) * sold);
|
|
||||||
plugin.tex.sendString(e.panel, PanelPosition.Top, e.p, Objects.requireNonNull(plugin.config.getString("purchase.item.success")).replaceAll("%cp-args%", e.args[1]).replaceAll("%cp-args2%", "$" + Double.parseDouble(e.args[0]) * sold));
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
plugin.tex.sendMessage(e.p, ChatColor.RED + "Selling Requires Vault and an Economy to work!");
|
|
||||||
}
|
|
||||||
} catch (Exception sell) {
|
|
||||||
plugin.debug(sell,e.p);
|
|
||||||
plugin.tex.sendMessage(e.p, plugin.config.getString("config.format.error") + " " + "commands: " + e.name);
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if(e.name.equalsIgnoreCase("tokensell=")) {
|
|
||||||
e.commandTagUsed();
|
|
||||||
//if player uses tokensell= it will be eg. tokensell= <cashback> <item> <amount of item> [enchanted:KNOCKBACK:1] [potion:JUMP]
|
|
||||||
try {
|
|
||||||
if (plugin.getServer().getPluginManager().isPluginEnabled("TokenManager")) {
|
|
||||||
final TokenManager api = (TokenManager) Bukkit.getServer().getPluginManager().getPlugin("TokenManager");
|
|
||||||
int sold = removeItem(e.p, e.args, false);
|
|
||||||
if (sold <= 0) {
|
|
||||||
plugin.tex.sendString(e.panel, PanelPosition.Top, e.p, Objects.requireNonNull(plugin.config.getString("purchase.item.failure")));
|
|
||||||
} else {
|
|
||||||
assert api != null;
|
|
||||||
api.addTokens(e.p, Long.parseLong(e.args[0]));
|
|
||||||
plugin.tex.sendString(e.panel, PanelPosition.Top, e.p, Objects.requireNonNull(plugin.config.getString("purchase.item.success")).replaceAll("%cp-args%", e.args[1]));
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
plugin.tex.sendMessage(e.p, ChatColor.RED + "Selling Requires TokenManager to work!");
|
|
||||||
}
|
|
||||||
} catch (Exception sell) {
|
|
||||||
plugin.debug(sell,e.p);
|
|
||||||
plugin.tex.sendMessage(e.p, plugin.config.getString("config.format.error") + " " + "commands: " + e.name);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//returns false if player does not have item
|
|
||||||
private int removeItem(Player p, String[] args, boolean removeAll){
|
|
||||||
//get inventory slots and then an empty list to store slots that have the item to sell
|
|
||||||
List<ItemStack> cont = new ArrayList<>(Arrays.asList(plugin.inventorySaver.getNormalInventory(p)));
|
|
||||||
List<ItemStack> remCont = new ArrayList<>();
|
|
||||||
byte id = -1;
|
|
||||||
String potion = "false";
|
|
||||||
int customData = 0;
|
|
||||||
boolean noCustom = false;
|
|
||||||
for(String argsTemp : args){
|
|
||||||
if(argsTemp.startsWith("potion:")){
|
|
||||||
potion = argsTemp.replace("potion:","");
|
|
||||||
}
|
|
||||||
if (argsTemp.startsWith("id:")) {
|
|
||||||
id = Byte.parseByte(argsTemp.replace("id:", ""));
|
|
||||||
}
|
|
||||||
if (argsTemp.startsWith("custom-data:")) {
|
|
||||||
customData = Integer.parseInt(argsTemp.replace("custom-data:", ""));
|
|
||||||
}
|
|
||||||
if (argsTemp.contains("NOCUSTOMDATA")) {
|
|
||||||
noCustom = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//create an itemstack of the item to sell and the amount to sell (0 if all as args[2] will not be an amount)
|
|
||||||
ItemStack sellItem = new ItemStack(Objects.requireNonNull(Material.matchMaterial(args[1])), removeAll ? 0 : Integer.parseInt(args[2]));
|
|
||||||
int remainingAmount = removeAll ? 0 : sellItem.getAmount();
|
|
||||||
for (int f = 0; f < 36; f++) {
|
|
||||||
ItemStack itm = cont.get(f);
|
|
||||||
ItemStack remItm;
|
|
||||||
if (itm != null && itm.getType().equals(sellItem.getType())) {
|
|
||||||
remItm = new ItemStack(itm.getType(), itm.getAmount(), (short)f);
|
|
||||||
//check to ensure any extensions are checked
|
|
||||||
try {
|
|
||||||
if (!potion.equals("false")) {
|
|
||||||
PotionMeta potionMeta = (PotionMeta) itm.getItemMeta();
|
|
||||||
assert potionMeta != null;
|
|
||||||
if (!potionMeta.getBasePotionData().getType().name().equalsIgnoreCase(potion)) {
|
|
||||||
p.sendMessage(plugin.tex.colour( plugin.tag + ChatColor.RED + "Your item has the wrong potion effect"));
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//Check if the item matches the id set. If not continue to next in loop.
|
|
||||||
if(id != -1 && itm.getDurability() != id){
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
//Check if noCustom is set and if the item has custom data. If so continue to next in loop.
|
|
||||||
if(noCustom && cont.get(f).hasItemMeta()){
|
|
||||||
if(Objects.requireNonNull(cont.get(f).getItemMeta()).hasCustomModelData()){
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//Check if custom model data is set and if the item has that data. If not continue to next in loop.
|
|
||||||
if (customData != 0) {
|
|
||||||
if (!itm.hasItemMeta()) {
|
|
||||||
continue;
|
|
||||||
} else {
|
|
||||||
if(Objects.requireNonNull(itm.getItemMeta()).getCustomModelData() != customData){
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}catch(Exception exc){
|
|
||||||
//skip if it cannot do unless plugin.debug is enabled
|
|
||||||
plugin.debug(exc,p);
|
|
||||||
}
|
|
||||||
|
|
||||||
remCont.add(remItm);
|
|
||||||
|
|
||||||
//if the remaining amount has been reached, break otherwise sell all
|
|
||||||
if (!removeAll) {
|
|
||||||
remainingAmount -= remItm.getAmount();
|
|
||||||
if (remainingAmount <= 0) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
sellItem.setAmount(sellItem.getAmount() + remItm.getAmount());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(remainingAmount <= 0){
|
|
||||||
int removedItems = 0;
|
|
||||||
for (int f = 0; f <= remCont.size() - 1; f++) {
|
|
||||||
ItemStack remItm = remCont.get(f);
|
|
||||||
if(f == remCont.size() - 1){
|
|
||||||
if(plugin.inventorySaver.hasNormalInventory(p)){
|
|
||||||
p.getInventory().getItem(remItm.getDurability()).setAmount(remItm.getAmount() - sellItem.getAmount());
|
|
||||||
p.updateInventory();
|
|
||||||
}else{
|
|
||||||
cont.get(remItm.getDurability()).setAmount(remItm.getAmount() - sellItem.getAmount());
|
|
||||||
plugin.inventorySaver.inventoryConfig.set(p.getUniqueId().toString(), plugin.itemSerializer.itemStackArrayToBase64(cont.toArray(new ItemStack[0])));
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if(plugin.inventorySaver.hasNormalInventory(p)){
|
|
||||||
p.getInventory().getItem(remItm.getDurability()).setAmount(0);
|
|
||||||
p.updateInventory();
|
|
||||||
}else{
|
|
||||||
cont.get(remItm.getDurability()).setAmount(0);
|
|
||||||
plugin.inventorySaver.inventoryConfig.set(p.getUniqueId().toString(), plugin.itemSerializer.itemStackArrayToBase64(cont.toArray(new ItemStack[0])));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
removedItems += remItm.getAmount();
|
|
||||||
sellItem.setAmount(sellItem.getAmount() - remItm.getAmount());
|
|
||||||
}
|
|
||||||
return removedItems;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
@ -16,47 +16,60 @@ public class DataTags implements Listener {
|
|||||||
if(e.name.equalsIgnoreCase("set-data=")){
|
if(e.name.equalsIgnoreCase("set-data=")){
|
||||||
e.commandTagUsed();
|
e.commandTagUsed();
|
||||||
if(e.args.length == 3){
|
if(e.args.length == 3){
|
||||||
plugin.panelData.setUserData(plugin.panelData.getOffline(e.args[2]),e.args[0],plugin.tex.placeholdersNoColour(e.panel,e.pos,e.p,e.args[1]),true);
|
plugin.panelData.setUserData(plugin.panelDataPlayers.getOffline(plugin.tex.placeholdersNoColour(e.panel,e.pos,e.p,e.args[2])),
|
||||||
|
plugin.tex.placeholdersNoColour(e.panel,e.pos,e.p,e.args[0]),
|
||||||
|
plugin.tex.placeholdersNoColour(e.panel,e.pos,e.p,e.args[1]),true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
//this will overwrite data. set-data= [data point] [data value] [optional player]
|
//this will overwrite data. set-data= [data point] [data value] [optional player]
|
||||||
plugin.panelData.setUserData(e.p.getUniqueId(),e.args[0],plugin.tex.placeholdersNoColour(e.panel,e.pos,e.p,e.args[1]),true);
|
plugin.panelData.setUserData(e.p.getUniqueId(),
|
||||||
|
plugin.tex.placeholdersNoColour(e.panel,e.pos,e.p,e.args[0]),
|
||||||
|
plugin.tex.placeholdersNoColour(e.panel,e.pos,e.p,e.args[1]),true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if(e.name.equalsIgnoreCase("add-data=")){
|
if(e.name.equalsIgnoreCase("add-data=")){
|
||||||
e.commandTagUsed();
|
e.commandTagUsed();
|
||||||
if(e.args.length == 3){
|
if(e.args.length == 3){
|
||||||
plugin.panelData.setUserData(plugin.panelData.getOffline(e.args[2]),e.args[0],plugin.tex.placeholdersNoColour(e.panel,e.pos,e.p,e.args[1]),false);
|
plugin.panelData.setUserData(plugin.panelDataPlayers.getOffline(plugin.tex.placeholdersNoColour(e.panel,e.pos,e.p,e.args[2])),
|
||||||
|
plugin.tex.placeholdersNoColour(e.panel,e.pos,e.p,e.args[0]),
|
||||||
|
plugin.tex.placeholdersNoColour(e.panel,e.pos,e.p,e.args[1]),false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
//this will not overwrite existing data. add-data= [data point] [data value] [optional player]
|
//this will not overwrite existing data. add-data= [data point] [data value] [optional player]
|
||||||
plugin.panelData.setUserData(e.p.getUniqueId(),e.args[0],plugin.tex.placeholdersNoColour(e.panel,e.pos,e.p,e.args[1]),false);
|
plugin.panelData.setUserData(e.p.getUniqueId(),
|
||||||
|
plugin.tex.placeholdersNoColour(e.panel,e.pos,e.p,e.args[0]),
|
||||||
|
plugin.tex.placeholdersNoColour(e.panel,e.pos,e.p,e.args[1]),false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if(e.name.equalsIgnoreCase("math-data=")){
|
if(e.name.equalsIgnoreCase("math-data=")){
|
||||||
e.commandTagUsed();
|
e.commandTagUsed();
|
||||||
if(e.args.length == 3){
|
if(e.args.length == 3){
|
||||||
plugin.panelData.doDataMath(plugin.panelData.getOffline(e.args[2]),e.args[0],plugin.tex.placeholdersNoColour(e.panel,e.pos,e.p,e.args[1]));
|
plugin.panelData.doDataMath(plugin.panelDataPlayers.getOffline(plugin.tex.placeholdersNoColour(e.panel,e.pos,e.p,e.args[2])),
|
||||||
|
plugin.tex.placeholdersNoColour(e.panel,e.pos,e.p,e.args[0]),
|
||||||
|
plugin.tex.placeholdersNoColour(e.panel,e.pos,e.p,e.args[1]));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
//only works if data is number, goes math-data= [data point] [operator:number] [optional player] eg, math-data= -1 OR /3
|
//only works if data is number, goes math-data= [data point] [operator:number] [optional player] eg, math-data= -1 OR /3
|
||||||
plugin.panelData.doDataMath(e.p.getUniqueId(),e.args[0],plugin.tex.placeholdersNoColour(e.panel,e.pos,e.p,e.args[1]));
|
plugin.panelData.doDataMath(e.p.getUniqueId(),
|
||||||
|
plugin.tex.placeholdersNoColour(e.panel,e.pos,e.p,e.args[0]),
|
||||||
|
plugin.tex.placeholdersNoColour(e.panel,e.pos,e.p,e.args[1]));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if(e.name.equalsIgnoreCase("clear-data=")){
|
if(e.name.equalsIgnoreCase("clear-data=")){
|
||||||
e.commandTagUsed();
|
e.commandTagUsed();
|
||||||
//will clear all data for player clear-data= [playerName]
|
//will clear all data for player clear-data= [playerName]
|
||||||
plugin.panelData.clearData(e.p.getUniqueId());
|
plugin.panelData.clearData(plugin.panelDataPlayers.getOffline(plugin.tex.placeholdersNoColour(e.panel,e.pos,e.p,e.args[0])));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if(e.name.equalsIgnoreCase("del-data=")){
|
if(e.name.equalsIgnoreCase("del-data=")){
|
||||||
e.commandTagUsed();
|
e.commandTagUsed();
|
||||||
if(e.args.length == 3){
|
if(e.args.length == 2){
|
||||||
plugin.panelData.delUserData(plugin.panelData.getOffline(e.args[1]),e.args[0]);
|
plugin.panelData.delUserData(plugin.panelDataPlayers.getOffline(plugin.tex.placeholdersNoColour(e.panel,e.pos,e.p,e.args[1])),
|
||||||
|
plugin.tex.placeholdersNoColour(e.panel,e.pos,e.p,e.args[0]));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
//this will remove data. del-data= [data point] [optional player]
|
//this will remove data. del-data= [data point] [optional player]
|
||||||
plugin.panelData.delUserData(e.p.getUniqueId(),e.args[0]);
|
plugin.panelData.delUserData(e.p.getUniqueId(),plugin.tex.placeholdersNoColour(e.panel,e.pos,e.p,e.args[0]));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -66,7 +66,7 @@ public class SpecialTags implements Listener {
|
|||||||
plugin.openPanels.closePanelForLoader(e.p.getName(),PanelPosition.Bottom);
|
plugin.openPanels.closePanelForLoader(e.p.getName(),PanelPosition.Bottom);
|
||||||
}else if(position == PanelPosition.Top && plugin.openPanels.hasPanelOpen(e.p.getName(),position)){
|
}else if(position == PanelPosition.Top && plugin.openPanels.hasPanelOpen(e.p.getName(),position)){
|
||||||
//closing top closes all
|
//closing top closes all
|
||||||
plugin.commandTags.runCommand(e.panel,e.pos,e.p,"cpc");
|
plugin.commandRunner.runCommand(e.panel,e.pos,e.p,"cpc");
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -139,7 +139,7 @@ public class SpecialTags implements Listener {
|
|||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
plugin.commandTags.runCommand(e.panel,e.pos, e.p, finalCommand);
|
plugin.commandRunner.runCommand(e.panel,e.pos, e.p, finalCommand);
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
//if there are any errors, cancel so that it doesn't loop errors
|
//if there are any errors, cancel so that it doesn't loop errors
|
||||||
plugin.debug(ex, e.p);
|
plugin.debug(ex, e.p);
|
||||||
|
@ -1,8 +1,10 @@
|
|||||||
package me.rockyhawk.commandpanels.commandtags.tags.standard;
|
package me.rockyhawk.commandpanels.commandtags.tags.standard;
|
||||||
|
|
||||||
|
import com.google.common.io.ByteArrayDataOutput;
|
||||||
|
import com.google.common.io.ByteStreams;
|
||||||
import me.rockyhawk.commandpanels.CommandPanels;
|
import me.rockyhawk.commandpanels.CommandPanels;
|
||||||
import me.rockyhawk.commandpanels.api.PanelCommandEvent;
|
import me.rockyhawk.commandpanels.api.PanelCommandEvent;
|
||||||
import me.rockyhawk.commandpanels.classresources.SerializerUtils;
|
import me.rockyhawk.commandpanels.classresources.MiniMessageUtils;
|
||||||
import me.rockyhawk.commandpanels.commandtags.CommandTagEvent;
|
import me.rockyhawk.commandpanels.commandtags.CommandTagEvent;
|
||||||
import me.rockyhawk.commandpanels.ioclasses.legacy.MinecraftVersions;
|
import me.rockyhawk.commandpanels.ioclasses.legacy.MinecraftVersions;
|
||||||
import me.rockyhawk.commandpanels.openpanelsmanager.PanelOpenType;
|
import me.rockyhawk.commandpanels.openpanelsmanager.PanelOpenType;
|
||||||
@ -69,6 +71,18 @@ public class BasicTags implements Listener {
|
|||||||
e.p.chat("/" + String.join(" ",e.args));
|
e.p.chat("/" + String.join(" ",e.args));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (e.name.equalsIgnoreCase("bungee=")) {
|
||||||
|
e.commandTagUsed();
|
||||||
|
ByteArrayDataOutput out = ByteStreams.newDataOutput();
|
||||||
|
try {
|
||||||
|
out.writeUTF(e.p.getName());
|
||||||
|
out.writeUTF(String.join(" ",e.args));
|
||||||
|
} catch(Exception ex) {
|
||||||
|
e.p.sendMessage(plugin.tag + ChatColor.translateAlternateColorCodes('&', "&cSomething wrong happened..."));
|
||||||
|
}
|
||||||
|
e.p.sendPluginMessage(plugin, "my:psb", out.toByteArray());
|
||||||
|
return;
|
||||||
|
}
|
||||||
if(e.name.equalsIgnoreCase("msg=")) {
|
if(e.name.equalsIgnoreCase("msg=")) {
|
||||||
e.commandTagUsed();
|
e.commandTagUsed();
|
||||||
plugin.tex.sendString(e.panel,e.pos,e.p,String.join(" ",e.args));
|
plugin.tex.sendString(e.panel,e.pos,e.p,String.join(" ",e.args));
|
||||||
@ -137,14 +151,10 @@ public class BasicTags implements Listener {
|
|||||||
}
|
}
|
||||||
if(e.name.equalsIgnoreCase("minimessage=")){
|
if(e.name.equalsIgnoreCase("minimessage=")){
|
||||||
e.commandTagUsed();
|
e.commandTagUsed();
|
||||||
//get checks
|
|
||||||
boolean isVersionCompatible = plugin.legacy.LOCAL_VERSION.greaterThanOrEqualTo(MinecraftVersions.v1_18);
|
|
||||||
boolean isPaper = Bukkit.getServer().getVersion().contains("Paper");
|
|
||||||
boolean allowUnsafeMiniMessage = plugin.config.getBoolean("config.allow-unsafe-mini-message");
|
|
||||||
//do mini message if conditions are met
|
//do mini message if conditions are met
|
||||||
if (isVersionCompatible && (isPaper || allowUnsafeMiniMessage)) {
|
if (plugin.legacy.MAJOR_VERSION.greaterThanOrEqualTo(MinecraftVersions.v1_18)) {
|
||||||
Audience player = (Audience) e.p; // Needed because the basic Player from the Event can't send Paper's Components
|
Audience player = (Audience) e.p; // Needed because the basic Player from the Event can't send Paper's Components
|
||||||
Component parsedText = SerializerUtils.serializeText(String.join(" ", e.args));
|
Component parsedText = plugin.miniMessage.doMiniMessage(String.join(" ", e.args));
|
||||||
player.sendMessage(parsedText);
|
player.sendMessage(parsedText);
|
||||||
} else {
|
} else {
|
||||||
plugin.tex.sendString(e.p, plugin.tag + ChatColor.RED + "MiniMessage-Feature needs Paper 1.18 or newer to work!");
|
plugin.tex.sendString(e.p, plugin.tag + ChatColor.RED + "MiniMessage-Feature needs Paper 1.18 or newer to work!");
|
||||||
|
@ -8,8 +8,8 @@ import org.bukkit.enchantments.Enchantment;
|
|||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
|
|
||||||
import java.util.Objects;
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
public class ItemTags implements Listener {
|
public class ItemTags implements Listener {
|
||||||
@ -37,7 +37,7 @@ public class ItemTags implements Listener {
|
|||||||
e.commandTagUsed();
|
e.commandTagUsed();
|
||||||
//if player uses setitem= [custom item] [slot] [position] it will change the item slot to something, used for placeable items
|
//if player uses setitem= [custom item] [slot] [position] it will change the item slot to something, used for placeable items
|
||||||
//make a section in the panel called "custom-item" then whatever the title of the item is, put that here
|
//make a section in the panel called "custom-item" then whatever the title of the item is, put that here
|
||||||
ItemStack s = plugin.itemCreate.makeItemFromConfig(null, e.pos,e.panel.getConfig().getConfigurationSection("custom-item." + e.args[0]), e.p, true, true, true);
|
ItemStack s = plugin.itemCreate.makeItemFromConfig(null, e.pos,e.panel.getConfig().getConfigurationSection("custom-item." + e.args[0]), e.p, true, true, false);
|
||||||
PanelPosition position = PanelPosition.valueOf(e.args[2]);
|
PanelPosition position = PanelPosition.valueOf(e.args[2]);
|
||||||
if(position == PanelPosition.Top) {
|
if(position == PanelPosition.Top) {
|
||||||
e.p.getOpenInventory().getTopInventory().setItem(Integer.parseInt(e.args[1]), s);
|
e.p.getOpenInventory().getTopInventory().setItem(Integer.parseInt(e.args[1]), s);
|
||||||
@ -102,21 +102,19 @@ public class ItemTags implements Listener {
|
|||||||
e.commandTagUsed();
|
e.commandTagUsed();
|
||||||
//if player uses setcustomdata= [slot] [position] [data] it will change the custom model data of the item
|
//if player uses setcustomdata= [slot] [position] [data] it will change the custom model data of the item
|
||||||
PanelPosition position = PanelPosition.valueOf(e.args[1]);
|
PanelPosition position = PanelPosition.valueOf(e.args[1]);
|
||||||
ItemStack EditItem;
|
ItemStack editItem;
|
||||||
if(position == PanelPosition.Top) {
|
if(position == PanelPosition.Top) {
|
||||||
EditItem = e.p.getOpenInventory().getTopInventory().getItem(Integer.parseInt(e.args[0]));
|
editItem = e.p.getOpenInventory().getTopInventory().getItem(Integer.parseInt(e.args[0]));
|
||||||
}else if(position == PanelPosition.Middle) {
|
}else if(position == PanelPosition.Middle) {
|
||||||
EditItem = e.p.getInventory().getItem(Integer.parseInt(e.args[0])+9);
|
editItem = e.p.getInventory().getItem(Integer.parseInt(e.args[0])+9);
|
||||||
}else{
|
}else{
|
||||||
EditItem = e.p.getInventory().getItem(Integer.parseInt(e.args[0]));
|
editItem = e.p.getInventory().getItem(Integer.parseInt(e.args[0]));
|
||||||
}
|
}
|
||||||
|
|
||||||
assert EditItem != null;
|
|
||||||
|
|
||||||
try{
|
try{
|
||||||
if(EditItem.hasItemMeta()){
|
ItemMeta itemMeta = editItem.getItemMeta();
|
||||||
Objects.requireNonNull(EditItem.getItemMeta()).setCustomModelData(Integer.valueOf(e.args[2]));
|
itemMeta.setCustomModelData(Integer.valueOf(e.args[2]));
|
||||||
}
|
editItem.setItemMeta(itemMeta);
|
||||||
} catch (Exception err){
|
} catch (Exception err){
|
||||||
plugin.debug(err,e.p);
|
plugin.debug(err,e.p);
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,6 @@ import org.bukkit.OfflinePlayer;
|
|||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.command.TabCompleter;
|
import org.bukkit.command.TabCompleter;
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
@ -47,13 +46,13 @@ public class DataTabComplete implements TabCompleter {
|
|||||||
try {
|
try {
|
||||||
|
|
||||||
if (!args[1].equalsIgnoreCase("all") && !args[1].equalsIgnoreCase("online"))
|
if (!args[1].equalsIgnoreCase("all") && !args[1].equalsIgnoreCase("online"))
|
||||||
return new ArrayList<>(plugin.panelData.dataConfig.getConfigurationSection("playerData." + plugin.panelData.getOffline(args[1])).getKeys(false));
|
return new ArrayList<>(plugin.panelData.dataConfig.getConfigurationSection("playerData." + plugin.panelDataPlayers.getOffline(args[1])).getKeys(false));
|
||||||
|
|
||||||
else {
|
else {
|
||||||
Set<String> set = new HashSet<>();
|
Set<String> set = new HashSet<>();
|
||||||
for (OfflinePlayer player : Bukkit.getOfflinePlayers()) {
|
for (OfflinePlayer player : Bukkit.getOfflinePlayers()) {
|
||||||
if (!player.isOnline()&&args[1].equalsIgnoreCase("online")) continue;
|
if (!player.isOnline()&&args[1].equalsIgnoreCase("online")) continue;
|
||||||
set.addAll(plugin.panelData.dataConfig.getConfigurationSection("playerData." + plugin.panelData.getOffline(player.getName())).getKeys(false));
|
set.addAll(plugin.panelData.dataConfig.getConfigurationSection("playerData." + plugin.panelDataPlayers.getOffline(player.getName())).getKeys(false));
|
||||||
|
|
||||||
}
|
}
|
||||||
String[] finalArgs = args;
|
String[] finalArgs = args;
|
||||||
|
@ -1,14 +1,12 @@
|
|||||||
package me.rockyhawk.commandpanels.datamanager;
|
package me.rockyhawk.commandpanels.datamanager;
|
||||||
|
|
||||||
import me.rockyhawk.commandpanels.CommandPanels;
|
import me.rockyhawk.commandpanels.CommandPanels;
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.configuration.file.YamlConfiguration;
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.regex.Pattern;
|
|
||||||
|
|
||||||
public class PanelDataLoader {
|
public class PanelDataLoader {
|
||||||
CommandPanels plugin;
|
CommandPanels plugin;
|
||||||
@ -26,14 +24,6 @@ public class PanelDataLoader {
|
|||||||
if(!overwrite && dataConfig.isSet("playerData." + playerUUID + "." + dataPoint)){
|
if(!overwrite && dataConfig.isSet("playerData." + playerUUID + "." + dataPoint)){
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
//check if string is numeric
|
|
||||||
Pattern pattern = Pattern.compile("-?\\d+(\\.\\d+)?");
|
|
||||||
if(pattern.matcher(dataValue).matches()){
|
|
||||||
doDataMath(playerUUID, dataPoint, dataValue);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
dataConfig.set("playerData." + playerUUID + "." + dataPoint, dataValue);
|
dataConfig.set("playerData." + playerUUID + "." + dataPoint, dataValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -105,10 +95,4 @@ public class PanelDataLoader {
|
|||||||
|
|
||||||
dataConfig.set("playerData." + playerUUID + "." + dataPoint, output.toPlainString());
|
dataConfig.set("playerData." + playerUUID + "." + dataPoint, output.toPlainString());
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
|
||||||
public UUID getOffline(String playerName){
|
|
||||||
//making this a separate function as it is long and deprecated
|
|
||||||
return Bukkit.getOfflinePlayer(playerName).getUniqueId();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,40 @@
|
|||||||
|
package me.rockyhawk.commandpanels.datamanager;
|
||||||
|
|
||||||
|
import me.rockyhawk.commandpanels.CommandPanels;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.OfflinePlayer;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.player.PlayerJoinEvent;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public class PanelDataPlayerManager implements Listener {
|
||||||
|
private CommandPanels plugin;
|
||||||
|
|
||||||
|
public PanelDataPlayerManager(CommandPanels pl) {
|
||||||
|
this.plugin = pl;
|
||||||
|
}
|
||||||
|
|
||||||
|
//will return UUID if found or null
|
||||||
|
public UUID getOffline(String playerName){
|
||||||
|
return knownPlayers.getOrDefault(playerName, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
//Bukkit.getOfflinePlayer uses MojangAPI and can be very slow if a player has never joined the server before
|
||||||
|
//Will get all players who have ever joined the server before and use them
|
||||||
|
private HashMap<String, UUID> knownPlayers = new HashMap<>();
|
||||||
|
public void reloadAllPlayers(){
|
||||||
|
knownPlayers.clear();
|
||||||
|
for(OfflinePlayer p : Bukkit.getOfflinePlayers()){
|
||||||
|
knownPlayers.put(p.getName(), p.getUniqueId());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//Add players who have joined the server to known players
|
||||||
|
@EventHandler
|
||||||
|
public void onPlayerJoin(PlayerJoinEvent e) {
|
||||||
|
knownPlayers.put(e.getPlayer().getName(), e.getPlayer().getUniqueId());
|
||||||
|
}
|
||||||
|
}
|
@ -3,19 +3,19 @@ package me.rockyhawk.commandpanels.editor;
|
|||||||
import me.rockyhawk.commandpanels.CommandPanels;
|
import me.rockyhawk.commandpanels.CommandPanels;
|
||||||
import me.rockyhawk.commandpanels.api.Panel;
|
import me.rockyhawk.commandpanels.api.Panel;
|
||||||
import net.md_5.bungee.api.chat.*;
|
import net.md_5.bungee.api.chat.*;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandExecutor;
|
import org.bukkit.command.CommandExecutor;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
|
||||||
import org.bukkit.scheduler.BukkitRunnable;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
public class CommandPanelsEditor implements CommandExecutor {
|
public class CommandPanelsEditor implements CommandExecutor {
|
||||||
CommandPanels plugin;
|
CommandPanels plugin;
|
||||||
@ -52,18 +52,26 @@ public class CommandPanelsEditor implements CommandExecutor {
|
|||||||
|
|
||||||
// Prepend "fileName: {name}" and "filePath: {relativePath}" to the YAML content
|
// Prepend "fileName: {name}" and "filePath: {relativePath}" to the YAML content
|
||||||
String yamlWithFileNameAndPath = "fileName: " + (relativePath.replaceFirst("[.][^.]+$", "")) + "\n" + fileContents;
|
String yamlWithFileNameAndPath = "fileName: " + (relativePath.replaceFirst("[.][^.]+$", "")) + "\n" + fileContents;
|
||||||
|
byte[] contentBytes = yamlWithFileNameAndPath.getBytes(StandardCharsets.UTF_8);
|
||||||
|
|
||||||
// Create a clickable text component with the modified YAML content
|
//65535 is maximum value that can be represented by an unsigned 16-bit binary number
|
||||||
BaseComponent[] components = new ComponentBuilder(plugin.tag +
|
if (contentBytes.length > 65535) {
|
||||||
net.md_5.bungee.api.ChatColor.GREEN + "Click here to copy " +
|
// If the content is too large, notify the player to use a different method
|
||||||
net.md_5.bungee.api.ChatColor.WHITE + panel.getFile().getName() +
|
sender.sendMessage(plugin.tag + ChatColor.RED +
|
||||||
net.md_5.bungee.api.ChatColor.GREEN + " to the clipboard!")
|
"Content too long to paste in chat. Please copy and paste the panel file into the editor manually.");
|
||||||
.event(new ClickEvent(ClickEvent.Action.COPY_TO_CLIPBOARD, yamlWithFileNameAndPath))
|
} else {
|
||||||
.create();
|
// Safe to send
|
||||||
|
BaseComponent[] components = new ComponentBuilder(plugin.tag +
|
||||||
|
net.md_5.bungee.api.ChatColor.GREEN + "Click here to copy " +
|
||||||
|
net.md_5.bungee.api.ChatColor.WHITE + panel.getFile().getName() +
|
||||||
|
net.md_5.bungee.api.ChatColor.GREEN + " to the clipboard!")
|
||||||
|
.event(new ClickEvent(ClickEvent.Action.COPY_TO_CLIPBOARD, yamlWithFileNameAndPath))
|
||||||
|
.create();
|
||||||
|
|
||||||
|
Player player = (Player) sender;
|
||||||
|
player.spigot().sendMessage(components);
|
||||||
|
}
|
||||||
|
|
||||||
// Send the clickable text to the player
|
|
||||||
Player player = (Player) sender;
|
|
||||||
player.spigot().sendMessage(components);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -73,29 +81,32 @@ public class CommandPanelsEditor implements CommandExecutor {
|
|||||||
}
|
}
|
||||||
//download the requested panel using an import
|
//download the requested panel using an import
|
||||||
if (args.length == 3) {
|
if (args.length == 3) {
|
||||||
new BukkitRunnable() {
|
downloadPanel(sender,args[1],args[0], args[2]).thenAccept((ignored) -> {
|
||||||
@Override
|
plugin.reloadPanelFiles();
|
||||||
public void run() {
|
plugin.hotbar.reloadHotbarSlots();
|
||||||
downloadPanel(sender,args[1],args[0], args[2]);
|
});
|
||||||
plugin.reloadPanelFiles();
|
|
||||||
plugin.hotbar.reloadHotbarSlots();
|
|
||||||
}
|
|
||||||
}.run();
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}else{
|
}else{
|
||||||
sender.sendMessage(plugin.tex.colour(plugin.tag + plugin.config.getString("config.format.perms")));
|
sender.sendMessage(plugin.tex.colour(plugin.tag + plugin.config.getString("config.format.perms")));
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
sender.sendMessage(plugin.tex.colour(plugin.tag + ChatColor.RED + "Usage: /cpe <parameters>"));
|
sender.sendMessage(plugin.tex.colour(plugin.tag + ChatColor.RED + "Usage: /cpe <parameters>"));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void downloadPanel(CommandSender sender, String userID, String fileName, String token) {
|
private CompletableFuture<Void> downloadPanel(CommandSender sender, String userID, String fileName, String token) {
|
||||||
|
CompletableFuture<Void> future = new CompletableFuture<>();
|
||||||
|
|
||||||
//get custom editor URL
|
//get custom editor URL
|
||||||
String url = "https://firebasestorage.googleapis.com/v0/b/commandpanels-website.appspot.com/o/pastes%2F" + userID + "%2F" + fileName + "?alt=media&token=" + token;
|
String url = "https://firebasestorage.googleapis.com/v0/b/commandpanels-website.appspot.com/o/pastes%2F" + userID + "%2F" + fileName + "?alt=media&token=" + token;
|
||||||
|
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
|
||||||
|
plugin.downloader.downloadPanel(sender, url, fileName);
|
||||||
|
future.complete(null);
|
||||||
|
});
|
||||||
|
|
||||||
plugin.downloader.downloadPanel(sender, url, fileName);
|
return future;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private String readFileAsString(String filePath) {
|
private String readFileAsString(String filePath) {
|
||||||
|
173
src/me/rockyhawk/commandpanels/floodgatecp/OpenFloodgateGUI.java
Normal file
173
src/me/rockyhawk/commandpanels/floodgatecp/OpenFloodgateGUI.java
Normal file
@ -0,0 +1,173 @@
|
|||||||
|
package me.rockyhawk.commandpanels.floodgatecp;
|
||||||
|
|
||||||
|
import me.rockyhawk.commandpanels.CommandPanels;
|
||||||
|
import me.rockyhawk.commandpanels.api.Panel;
|
||||||
|
import me.rockyhawk.commandpanels.api.PanelOpenedEvent;
|
||||||
|
import me.rockyhawk.commandpanels.openpanelsmanager.PanelPosition;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.geysermc.cumulus.form.CustomForm;
|
||||||
|
import org.geysermc.cumulus.form.SimpleForm;
|
||||||
|
import org.geysermc.cumulus.response.CustomFormResponse;
|
||||||
|
import org.geysermc.cumulus.response.SimpleFormResponse;
|
||||||
|
import org.geysermc.cumulus.util.FormImage;
|
||||||
|
import org.geysermc.floodgate.api.FloodgateApi;
|
||||||
|
import org.geysermc.floodgate.api.player.FloodgatePlayer;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Comparator;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
public class OpenFloodgateGUI implements Listener {
|
||||||
|
private CommandPanels plugin;
|
||||||
|
|
||||||
|
public OpenFloodgateGUI(CommandPanels pl) {
|
||||||
|
this.plugin = pl;
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onPanelOpen(PanelOpenedEvent e) {
|
||||||
|
if (!FloodgateApi.getInstance().isFloodgatePlayer(e.getPlayer().getUniqueId()) ||
|
||||||
|
!e.getPanel().getConfig().contains("floodgate")) return;
|
||||||
|
|
||||||
|
FloodgatePlayer fgPlayer = FloodgateApi.getInstance().getPlayer(e.getPlayer().getUniqueId());
|
||||||
|
ConfigurationSection fgPanel = e.getPanel().getConfig().getConfigurationSection("floodgate");
|
||||||
|
|
||||||
|
if (fgPanel.contains("simple")) {
|
||||||
|
createAndSendSimpleForm(e, fgPlayer, fgPanel);
|
||||||
|
} else {
|
||||||
|
createAndSendCustomForm(e, fgPlayer, fgPanel);
|
||||||
|
}
|
||||||
|
|
||||||
|
e.setCancelled(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void createAndSendSimpleForm(PanelOpenedEvent e, FloodgatePlayer fgPlayer, ConfigurationSection fgPanel) {
|
||||||
|
//replace for multi-line support in simpleform content title
|
||||||
|
SimpleForm.Builder form = SimpleForm.builder()
|
||||||
|
.title(plugin.tex.placeholders(e.getPanel(), null, e.getPlayer(), plugin.tex.placeholders(e.getPanel(), null, e.getPlayer(), e.getPanel().getConfig().getString("title"))))
|
||||||
|
.content(plugin.tex.placeholders(e.getPanel(), null, e.getPlayer(), plugin.tex.placeholders(e.getPanel(), null, e.getPlayer(), fgPanel.getString("simple")).replaceAll("\\\\n", "\n")));
|
||||||
|
|
||||||
|
List<String> buttonCommands;
|
||||||
|
try {
|
||||||
|
buttonCommands = processButtons(fgPanel, form, e.getPanel(), e.getPlayer());
|
||||||
|
}catch (Exception err){
|
||||||
|
e.getPlayer().sendMessage(plugin.tag + ChatColor.RED + "FloodGate panel button config error");
|
||||||
|
plugin.debug(err, e.getPlayer());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
form.validResultHandler((SimpleFormResponse response) -> {
|
||||||
|
int clickedButtonId = response.clickedButtonId();
|
||||||
|
String configKey = buttonCommands.get(clickedButtonId);
|
||||||
|
|
||||||
|
String section = plugin.has.hasSection(e.getPanel(), PanelPosition.Top, fgPanel.getConfigurationSection(configKey), e.getPlayer());
|
||||||
|
ConfigurationSection buttonConfig = fgPanel.getConfigurationSection(configKey + section);
|
||||||
|
|
||||||
|
if(buttonConfig.contains("commands")) {
|
||||||
|
plugin.commandRunner.runCommands(e.getPanel(), PanelPosition.Top, e.getPlayer(), buttonConfig.getStringList("commands"), null);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
fgPlayer.sendForm(form.build());
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<String> processButtons(ConfigurationSection fgPanel, SimpleForm.Builder form, Panel panel, Player p) {
|
||||||
|
return fgPanel.getKeys(false).stream()
|
||||||
|
.filter(key -> key.matches("\\d+"))
|
||||||
|
.sorted(Comparator.comparingInt(Integer::parseInt)) // Ensure numeric sorting
|
||||||
|
.map(key -> {
|
||||||
|
String section = plugin.has.hasSection(panel, PanelPosition.Top, fgPanel.getConfigurationSection(key), p);
|
||||||
|
ConfigurationSection buttonConfig = fgPanel.getConfigurationSection(key + section);
|
||||||
|
if (buttonConfig == null) return null;
|
||||||
|
|
||||||
|
String buttonContent = plugin.tex.placeholders(panel, null, p, buttonConfig.getString("text").replaceAll("\\\\n", "\n"));
|
||||||
|
if (!buttonConfig.contains("icon")) {
|
||||||
|
form.button(buttonContent);
|
||||||
|
} else {
|
||||||
|
FormImage.Type type = FormImage.Type.valueOf(plugin.tex.placeholders(panel, null, p, buttonConfig.getString("icon.type")).toUpperCase());
|
||||||
|
String texture = plugin.tex.placeholders(panel, null, p, buttonConfig.getString("icon.texture"));
|
||||||
|
form.button(buttonContent, type, texture);
|
||||||
|
}
|
||||||
|
return key;
|
||||||
|
})
|
||||||
|
.filter(key -> key != null)
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
|
private void createAndSendCustomForm(PanelOpenedEvent e, FloodgatePlayer fgPlayer, ConfigurationSection fgPanel) {
|
||||||
|
CustomForm.Builder form = CustomForm.builder()
|
||||||
|
.title(plugin.tex.placeholders(e.getPanel(), null, e.getPlayer(), e.getPanel().getConfig().getString("title")));
|
||||||
|
|
||||||
|
List<String> commandsOrder = new ArrayList<>();
|
||||||
|
fgPanel.getKeys(false).forEach(key -> {
|
||||||
|
if (key.matches("\\d+")) {
|
||||||
|
String section = plugin.has.hasSection(e.getPanel(), e.getPosition(), fgPanel.getConfigurationSection(key), e.getPlayer());
|
||||||
|
ConfigurationSection fieldConfig = fgPanel.getConfigurationSection(key + section);
|
||||||
|
|
||||||
|
try {
|
||||||
|
String type = "toggle";
|
||||||
|
if(fieldConfig.contains("type")) {
|
||||||
|
type = fieldConfig.getString("type").toLowerCase();
|
||||||
|
}
|
||||||
|
switch (type) {
|
||||||
|
case "toggle":
|
||||||
|
form.toggle(plugin.tex.placeholders(e.getPanel(), null, e.getPlayer(), fieldConfig.getString("text").replaceAll("\\\\n", "\n")),
|
||||||
|
Boolean.parseBoolean(plugin.tex.placeholders(e.getPanel(), null, e.getPlayer(), fieldConfig.getString("default"))));
|
||||||
|
commandsOrder.add(key);
|
||||||
|
break;
|
||||||
|
case "slider":
|
||||||
|
form.slider(plugin.tex.placeholders(e.getPanel(), null, e.getPlayer(), fieldConfig.getString("text").replaceAll("\\\\n", "\n")),
|
||||||
|
Long.parseLong(plugin.tex.placeholders(e.getPanel(), null, e.getPlayer(), fieldConfig.getString("min"))),
|
||||||
|
Long.parseLong(plugin.tex.placeholders(e.getPanel(), null, e.getPlayer(), fieldConfig.getString("max"))),
|
||||||
|
Long.parseLong(plugin.tex.placeholders(e.getPanel(), null, e.getPlayer(), fieldConfig.getString("step"))),
|
||||||
|
Long.parseLong(plugin.tex.placeholders(e.getPanel(), null, e.getPlayer(), fieldConfig.getString("default"))));
|
||||||
|
commandsOrder.add(key);
|
||||||
|
break;
|
||||||
|
case "input":
|
||||||
|
form.input(plugin.tex.placeholders(e.getPanel(), null, e.getPlayer(), fieldConfig.getString("text").replaceAll("\\\\n", "\n")),
|
||||||
|
plugin.tex.placeholders(e.getPanel(), null, e.getPlayer(), fieldConfig.getString("placeholder")),
|
||||||
|
plugin.tex.placeholders(e.getPanel(), null, e.getPlayer(), fieldConfig.getString("default")));
|
||||||
|
commandsOrder.add(key);
|
||||||
|
break;
|
||||||
|
case "dropdown":
|
||||||
|
form.dropdown(plugin.tex.placeholders(e.getPanel(), null, e.getPlayer(), fieldConfig.getString("text").replaceAll("\\\\n", "\n")),
|
||||||
|
plugin.tex.placeholdersList(e.getPanel(), null, e.getPlayer(), fieldConfig.getStringList("options"), true));
|
||||||
|
commandsOrder.add(key);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}catch (Exception err){
|
||||||
|
e.getPlayer().sendMessage(plugin.tag + ChatColor.RED + "FloodGate panel button config error");
|
||||||
|
plugin.debug(err, e.getPlayer());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
form.validResultHandler((CustomFormResponse response) -> {
|
||||||
|
for (String configKey : commandsOrder) { // Iterate over each command configuration key
|
||||||
|
if (!response.hasNext()) {
|
||||||
|
break; // Safety check to prevent NoSuchElementException
|
||||||
|
}
|
||||||
|
String section = plugin.has.hasSection(e.getPanel(), e.getPosition(), fgPanel.getConfigurationSection(configKey), e.getPlayer());
|
||||||
|
ConfigurationSection fieldConfig = fgPanel.getConfigurationSection(configKey + section);
|
||||||
|
|
||||||
|
if(fieldConfig.contains("commands")) {
|
||||||
|
Object fieldValue = response.next(); // Retrieve the next response value
|
||||||
|
String value = String.valueOf(fieldValue); // Convert the field value to String
|
||||||
|
List<String> commands = fieldConfig.getStringList("commands"); // Retrieve commands for this field
|
||||||
|
List<String> processedCommands = new ArrayList<>();
|
||||||
|
for (String command : commands) {
|
||||||
|
processedCommands.add(command.replaceAll("%cp-input%", value)); // Replace the placeholder in each command
|
||||||
|
}
|
||||||
|
plugin.commandRunner.runCommands(e.getPanel(), PanelPosition.Top, e.getPlayer(), processedCommands, null); // Execute the processed commands
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
fgPlayer.sendForm(form.build());
|
||||||
|
}
|
||||||
|
}
|
@ -32,6 +32,9 @@ public class GenUtils implements Listener {
|
|||||||
@EventHandler
|
@EventHandler
|
||||||
public void onInventoryClose(InventoryCloseEvent e) {
|
public void onInventoryClose(InventoryCloseEvent e) {
|
||||||
Player p = (Player)e.getPlayer();
|
Player p = (Player)e.getPlayer();
|
||||||
|
if(!p.hasPermission("commandpanel.generate")){
|
||||||
|
return;
|
||||||
|
}
|
||||||
if(!ChatColor.stripColor(e.getView().getTitle()).equals("Generate New Panel")){
|
if(!ChatColor.stripColor(e.getView().getTitle()).equals("Generate New Panel")){
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -93,7 +96,7 @@ public class GenUtils implements Listener {
|
|||||||
|
|
||||||
file.set("panels." + date + ".title", "&8Generated " + date);
|
file.set("panels." + date + ".title", "&8Generated " + date);
|
||||||
file.addDefault("panels." + date + ".command", date);
|
file.addDefault("panels." + date + ".command", date);
|
||||||
if(plugin.legacy.LOCAL_VERSION.lessThanOrEqualTo(MinecraftVersions.v1_15)) {
|
if(plugin.legacy.MAJOR_VERSION.lessThanOrEqualTo(MinecraftVersions.v1_15)) {
|
||||||
file.set("panels." + date + ".empty", "STAINED_GLASS_PANE");
|
file.set("panels." + date + ".empty", "STAINED_GLASS_PANE");
|
||||||
file.set("panels." + date + ".emptyID", "15");
|
file.set("panels." + date + ".emptyID", "15");
|
||||||
}else{
|
}else{
|
||||||
@ -110,4 +113,4 @@ public class GenUtils implements Listener {
|
|||||||
}
|
}
|
||||||
plugin.reloadPanelFiles();
|
plugin.reloadPanelFiles();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,6 +22,10 @@ public class Commandpanelrefresher implements Listener {
|
|||||||
}
|
}
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onPanelOpen(PanelOpenedEvent e){ //Handles when Players open inventory
|
public void onPanelOpen(PanelOpenedEvent e){ //Handles when Players open inventory
|
||||||
|
if(e.isCancelled()){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (plugin.config.contains("config.refresh-panels")) {
|
if (plugin.config.contains("config.refresh-panels")) {
|
||||||
if (Objects.requireNonNull(plugin.config.getString("config.refresh-panels")).trim().equalsIgnoreCase("false")) {
|
if (Objects.requireNonNull(plugin.config.getString("config.refresh-panels")).trim().equalsIgnoreCase("false")) {
|
||||||
return;
|
return;
|
||||||
@ -115,7 +119,7 @@ public class Commandpanelrefresher implements Listener {
|
|||||||
if(plugin.inventorySaver.hasNormalInventory(p)) {
|
if(plugin.inventorySaver.hasNormalInventory(p)) {
|
||||||
for (ItemStack itm : p.getInventory().getContents()) {
|
for (ItemStack itm : p.getInventory().getContents()) {
|
||||||
if (itm != null) {
|
if (itm != null) {
|
||||||
if (plugin.nbt.hasNBT(itm)) {
|
if (plugin.nbt.hasNBT(itm,"CommandPanelsItem")) {
|
||||||
p.getInventory().remove(itm);
|
p.getInventory().remove(itm);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -40,7 +40,7 @@ public class OpenOnJoin implements Listener {
|
|||||||
String joinString = joinType + (world.isEmpty() ? "" : "."+ world);
|
String joinString = joinType + (world.isEmpty() ? "" : "."+ world);
|
||||||
if(plugin.config.contains(joinString)){
|
if(plugin.config.contains(joinString)){
|
||||||
String command = "open= " + plugin.config.getString(joinString);
|
String command = "open= " + plugin.config.getString(joinString);
|
||||||
plugin.commandTags.runCommand(null, PanelPosition.Top,p, command);
|
plugin.commandRunner.runCommand(null, PanelPosition.Top,p, command);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,38 @@
|
|||||||
|
package me.rockyhawk.commandpanels.interactives;
|
||||||
|
|
||||||
|
import me.rockyhawk.commandpanels.CommandPanels;
|
||||||
|
import me.rockyhawk.commandpanels.openpanelsmanager.PanelPosition;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.inventory.ClickType;
|
||||||
|
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||||
|
import org.bukkit.event.inventory.InventoryType;
|
||||||
|
|
||||||
|
public class OutsideClickEvent implements Listener {
|
||||||
|
CommandPanels plugin;
|
||||||
|
public OutsideClickEvent(CommandPanels pl) {
|
||||||
|
this.plugin = pl;
|
||||||
|
}
|
||||||
|
@EventHandler
|
||||||
|
public void onOutsideClick(InventoryClickEvent e){
|
||||||
|
Player p = (Player)e.getWhoClicked();
|
||||||
|
|
||||||
|
//cancel while a panel is open
|
||||||
|
if(plugin.openPanels.hasPanelOpen(p.getName(), PanelPosition.Top) || e.getClick() == ClickType.DOUBLE_CLICK){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//if there is no panel open, use outside-commands from config.yml
|
||||||
|
if(e.getSlotType() == InventoryType.SlotType.OUTSIDE){
|
||||||
|
//if the panel is clicked on the outside area of the GUI
|
||||||
|
if (plugin.config.contains("outside-commands")) {
|
||||||
|
try {
|
||||||
|
plugin.commandRunner.runCommands(null,PanelPosition.Top,p, plugin.config.getStringList("outside-commands"),e.getClick());
|
||||||
|
}catch(Exception s){
|
||||||
|
plugin.debug(s,p);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -50,7 +50,7 @@ public class UserInputUtils implements Listener {
|
|||||||
|
|
||||||
plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
|
plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
plugin.commandTags.runCommands(playerInput.get(e.getPlayer()).panel, PanelPosition.Top,e.getPlayer(), playerInput.get(e.getPlayer()).commands,playerInput.get(e.getPlayer()).click); //I have to do this to run regular Bukkit voids in an ASYNC Event
|
plugin.commandRunner.runCommands(playerInput.get(e.getPlayer()).panel, PanelPosition.Top,e.getPlayer(), playerInput.get(e.getPlayer()).commands,playerInput.get(e.getPlayer()).click); //I have to do this to run regular Bukkit voids in an ASYNC Event
|
||||||
playerInput.remove(e.getPlayer());
|
playerInput.remove(e.getPlayer());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
package me.rockyhawk.commandpanels.ioclasses;
|
package me.rockyhawk.commandpanels.ioclasses.iteminhand;
|
||||||
|
|
||||||
import me.rockyhawk.commandpanels.CommandPanels;
|
import me.rockyhawk.commandpanels.CommandPanels;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
@ -1,4 +1,4 @@
|
|||||||
package me.rockyhawk.commandpanels.ioclasses;
|
package me.rockyhawk.commandpanels.ioclasses.iteminhand;
|
||||||
|
|
||||||
import me.rockyhawk.commandpanels.CommandPanels;
|
import me.rockyhawk.commandpanels.CommandPanels;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
@ -1,24 +1,47 @@
|
|||||||
package me.rockyhawk.commandpanels.ioclasses.legacy;
|
package me.rockyhawk.commandpanels.ioclasses.legacy;
|
||||||
|
|
||||||
import me.rockyhawk.commandpanels.CommandPanels;
|
import me.rockyhawk.commandpanels.CommandPanels;
|
||||||
import me.rockyhawk.commandpanels.ioclasses.GetStorageContents;
|
import me.rockyhawk.commandpanels.ioclasses.storagecontents.GetStorageContents;
|
||||||
import me.rockyhawk.commandpanels.ioclasses.GetStorageContents_Legacy;
|
import me.rockyhawk.commandpanels.ioclasses.storagecontents.GetStorageContents_Legacy;
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.inventory.Inventory;
|
import org.bukkit.inventory.Inventory;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
public class LegacyVersion {
|
public class LegacyVersion {
|
||||||
CommandPanels plugin;
|
CommandPanels plugin;
|
||||||
public MinecraftVersions LOCAL_VERSION;
|
public MinecraftVersions MAJOR_VERSION; //The major version of the server (eg, converts 1.20.5 to 1.20)
|
||||||
|
public int MINOR_VERSION; //The minor version of the server (1.20.5 to 5)
|
||||||
public LegacyVersion(CommandPanels pl) {
|
public LegacyVersion(CommandPanels pl) {
|
||||||
this.plugin = pl;
|
this.plugin = pl;
|
||||||
String VERSION = Bukkit.getServer().getClass().getPackage().getName().split("\\.")[3];
|
String VERSION = plugin.getServer().getBukkitVersion().split("-")[0];
|
||||||
LOCAL_VERSION = MinecraftVersions.get(VERSION);
|
MAJOR_VERSION = MinecraftVersions.get(extractMajorVersion(VERSION));
|
||||||
|
MINOR_VERSION = extractMinorVersion(VERSION);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String extractMajorVersion(String version) {
|
||||||
|
String[] parts = version.split("\\.");
|
||||||
|
if (parts.length < 2) {
|
||||||
|
// Handle the case where there aren't enough parts for a "major.major.minor" format.
|
||||||
|
return version; // Return the original version.
|
||||||
|
}
|
||||||
|
return parts[0] + "." + parts[1];
|
||||||
|
}
|
||||||
|
public Integer extractMinorVersion(String version) {
|
||||||
|
String[] parts = version.split("\\.");
|
||||||
|
if (parts.length > 2) {
|
||||||
|
// Take only the third part and convert it to an integer.
|
||||||
|
try {
|
||||||
|
return Integer.parseInt(parts[2]);
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0; // Return 0 if there are no parts beyond the first two.
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public ItemStack[] getStorageContents(Inventory i){
|
public ItemStack[] getStorageContents(Inventory i){
|
||||||
if(LOCAL_VERSION.lessThanOrEqualTo(MinecraftVersions.v1_12)){
|
if(MAJOR_VERSION.lessThanOrEqualTo(MinecraftVersions.v1_12)){
|
||||||
return new GetStorageContents_Legacy(plugin).getStorageContents(i);
|
return new GetStorageContents_Legacy(plugin).getStorageContents(i);
|
||||||
}else{
|
}else{
|
||||||
return new GetStorageContents(plugin).getStorageContents(i);
|
return new GetStorageContents(plugin).getStorageContents(i);
|
||||||
@ -26,7 +49,7 @@ public class LegacyVersion {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setStorageContents(Player p, ItemStack[] i){
|
public void setStorageContents(Player p, ItemStack[] i){
|
||||||
if(LOCAL_VERSION.lessThanOrEqualTo(MinecraftVersions.v1_15)){
|
if(MAJOR_VERSION.lessThanOrEqualTo(MinecraftVersions.v1_15)){
|
||||||
new GetStorageContents_Legacy(plugin).setStorageContents(p,i);
|
new GetStorageContents_Legacy(plugin).setStorageContents(p,i);
|
||||||
}else{
|
}else{
|
||||||
new GetStorageContents(plugin).setStorageContents(p,i);
|
new GetStorageContents(plugin).setStorageContents(p,i);
|
||||||
|
@ -1,25 +1,20 @@
|
|||||||
package me.rockyhawk.commandpanels.ioclasses.legacy;
|
package me.rockyhawk.commandpanels.ioclasses.legacy;
|
||||||
|
|
||||||
public enum MinecraftVersions {
|
public enum MinecraftVersions {
|
||||||
v1_8( "1_8", 0 ),
|
v1_8( "1.8", 0 ),
|
||||||
v1_9( "1_9", 1 ),
|
v1_9( "1.9", 1 ),
|
||||||
v1_10( "1_10", 2 ),
|
v1_10( "1.10", 2 ),
|
||||||
v1_11( "1_11", 3 ),
|
v1_11( "1.11", 3 ),
|
||||||
v1_12( "1_12", 4 ),
|
v1_12( "1.12", 4 ),
|
||||||
v1_13( "1_13", 5 ),
|
v1_13( "1.13", 5 ),
|
||||||
v1_14( "1_14", 6 ),
|
v1_14( "1.14", 6 ),
|
||||||
v1_15( "1_15", 7 ),
|
v1_15( "1.15", 7 ),
|
||||||
v1_16( "1_16", 8 ),
|
v1_16( "1.16", 8 ),
|
||||||
v1_17( "1_17", 9 ),
|
v1_17( "1.17", 9 ),
|
||||||
v1_18( "1_18", 10 ),
|
v1_18( "1.18", 10 ),
|
||||||
v1_19( "1_19", 11 ),
|
v1_19( "1.19", 11 ),
|
||||||
v1_20( "1_20", 12 ),
|
v1_20( "1.20", 12 ),
|
||||||
v1_21( "1_21", 13 ),
|
v1_21( "1.21", 13 );
|
||||||
v1_22( "1_22", 14 ),
|
|
||||||
v1_23( "1_23", 15 ),
|
|
||||||
v1_24( "1_24", 16 ),
|
|
||||||
v1_25( "1_25", 17 ),
|
|
||||||
v1_26( "1_26", 18 );
|
|
||||||
|
|
||||||
|
|
||||||
private int order;
|
private int order;
|
||||||
|
@ -13,7 +13,7 @@ public class PlayerHeads {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public String playerHeadString() {
|
public String playerHeadString() {
|
||||||
if(plugin.legacy.LOCAL_VERSION.lessThanOrEqualTo(MinecraftVersions.v1_12)){
|
if(plugin.legacy.MAJOR_VERSION.lessThanOrEqualTo(MinecraftVersions.v1_12)){
|
||||||
return "SKULL_ITEM";
|
return "SKULL_ITEM";
|
||||||
}else{
|
}else{
|
||||||
return "PLAYER_HEAD";
|
return "PLAYER_HEAD";
|
||||||
|
@ -1,8 +1,13 @@
|
|||||||
package me.rockyhawk.commandpanels.ioclasses.nbt;
|
package me.rockyhawk.commandpanels.ioclasses.nbt;
|
||||||
|
|
||||||
import de.tr7zw.changeme.nbtapi.NBT;
|
import de.tr7zw.changeme.nbtapi.NBTCompound;
|
||||||
import de.tr7zw.changeme.nbtapi.NBTItem;
|
import de.tr7zw.changeme.nbtapi.NBTItem;
|
||||||
import me.rockyhawk.commandpanels.CommandPanels;
|
import me.rockyhawk.commandpanels.CommandPanels;
|
||||||
|
import me.rockyhawk.commandpanels.api.Panel;
|
||||||
|
import me.rockyhawk.commandpanels.openpanelsmanager.PanelPosition;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
public class NBTManager {
|
public class NBTManager {
|
||||||
@ -11,30 +16,164 @@ public class NBTManager {
|
|||||||
this.plugin = pl;
|
this.plugin = pl;
|
||||||
}
|
}
|
||||||
|
|
||||||
//commandpanel item NBT
|
public boolean hasSameNBT(ItemStack one, ItemStack two){
|
||||||
public boolean hasNBT(ItemStack item){
|
NBTItem nbtitem1 = new NBTItem(one);
|
||||||
NBTItem nbti = new NBTItem(item);
|
NBTItem nbtitem2 = new NBTItem(two);
|
||||||
return nbti.hasTag("CommandPanelsItem");
|
|
||||||
|
return nbtitem1.equals(nbtitem2);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ItemStack setNBT(ItemStack item){
|
public Object getNBT(ItemStack item, String key, String type) {
|
||||||
NBT.modify(item, nbt -> {
|
type = type.toLowerCase();
|
||||||
nbt.setString("CommandPanelsItem", "1");
|
NBTItem nbtItem = new NBTItem(item);
|
||||||
});
|
switch(type.toLowerCase()) {
|
||||||
|
case "byte":
|
||||||
|
return nbtItem.getByte(key);
|
||||||
|
case "boolean":
|
||||||
|
return nbtItem.getBoolean(key);
|
||||||
|
case "short":
|
||||||
|
return nbtItem.getShort(key);
|
||||||
|
case "integer":
|
||||||
|
return nbtItem.getInteger(key);
|
||||||
|
case "long":
|
||||||
|
return nbtItem.getLong(key);
|
||||||
|
case "float":
|
||||||
|
return nbtItem.getFloat(key);
|
||||||
|
case "double":
|
||||||
|
return nbtItem.getDouble(key);
|
||||||
|
case "string":
|
||||||
|
return nbtItem.getString(key);
|
||||||
|
default:
|
||||||
|
throw new IllegalArgumentException("Unsupported NBT type: " + type);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean hasNBT(ItemStack item, String key){
|
||||||
|
NBTItem nbti = new NBTItem(item);
|
||||||
|
return nbti.hasTag(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
//nbt will be assigned with the value "string_value_1
|
||||||
|
//which uses the type "String" and value "value_1"
|
||||||
|
// Method to apply NBT recursively
|
||||||
|
public ItemStack setNBT(ItemStack item, String key, String value) {
|
||||||
|
if (item == null || item.getType() == Material.AIR) {
|
||||||
|
return item;
|
||||||
|
}
|
||||||
|
NBTItem nbtItem = new NBTItem(item);
|
||||||
|
setNBTDirectlyOnItem(nbtItem, key, value);
|
||||||
|
|
||||||
|
item.setItemMeta(nbtItem.getItem().getItemMeta());
|
||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
|
|
||||||
//custom key NBT
|
// Method to apply NBT recursively
|
||||||
public String getNBT(ItemStack item, String key){
|
public void applyNBTRecursively(ItemStack item, ConfigurationSection section, Player player, Panel panel, PanelPosition position) {
|
||||||
NBTItem nbti = new NBTItem(item);
|
NBTItem nbtItem = new NBTItem(item);
|
||||||
if(!nbti.hasNBTData()) return "";
|
|
||||||
return nbti.getString(key);
|
// Iterate over each key in the root of the ConfigurationSection
|
||||||
|
for (String key : section.getKeys(false)) {
|
||||||
|
// Check if the key represents a ConfigurationSection
|
||||||
|
if (section.isConfigurationSection(key)) {
|
||||||
|
// Create a compound for each ConfigurationSection
|
||||||
|
NBTCompound compound = nbtItem.addCompound(key);
|
||||||
|
convertSectionToNBT(compound, section.getConfigurationSection(key), player, panel, position);
|
||||||
|
} else {
|
||||||
|
// Handle non-section values directly on the NBTItem if necessary
|
||||||
|
String value = plugin.tex.attachPlaceholders(panel, position, player, section.getString(key));
|
||||||
|
setNBTDirectlyOnItem(nbtItem, key, value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
item.setItemMeta(nbtItem.getItem().getItemMeta());
|
||||||
}
|
}
|
||||||
|
|
||||||
public ItemStack setNBT(ItemStack item, String key, String value){
|
// Convert ConfigurationSection to NBTCompound recursively
|
||||||
NBT.modify(item, nbt -> {
|
private void convertSectionToNBT(NBTCompound compound, ConfigurationSection section, Player player, Panel panel, PanelPosition position) {
|
||||||
nbt.setString(key, value);
|
for (String key : section.getKeys(false)) {
|
||||||
});
|
if (section.isConfigurationSection(key)) {
|
||||||
return item;
|
// Recursively convert sub-sections to their own compounds
|
||||||
|
NBTCompound subCompound = compound.addCompound(key);
|
||||||
|
convertSectionToNBT(subCompound, section.getConfigurationSection(key), player, panel, position);
|
||||||
|
} else {
|
||||||
|
// Handle scalar values within each compound
|
||||||
|
String value = plugin.tex.attachPlaceholders(panel, position, player, section.getString(key));
|
||||||
|
setNBTOnCompound(compound, key, value);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
private void setNBTDirectlyOnItem(NBTItem nbtItem, String key, String value) {
|
||||||
|
int underscoreIndex = value.indexOf("_");
|
||||||
|
if (underscoreIndex == -1) return; // Skip if format is invalid
|
||||||
|
|
||||||
|
String type = value.substring(0, underscoreIndex);
|
||||||
|
String val = value.substring(underscoreIndex + 1);
|
||||||
|
|
||||||
|
switch (type.toLowerCase()) {
|
||||||
|
case "byte":
|
||||||
|
nbtItem.setByte(key, Byte.parseByte(val));
|
||||||
|
break;
|
||||||
|
case "boolean":
|
||||||
|
nbtItem.setBoolean(key, Boolean.parseBoolean(val));
|
||||||
|
break;
|
||||||
|
case "short":
|
||||||
|
nbtItem.setShort(key, Short.parseShort(val));
|
||||||
|
break;
|
||||||
|
case "integer":
|
||||||
|
nbtItem.setInteger(key, Integer.parseInt(val));
|
||||||
|
break;
|
||||||
|
case "long":
|
||||||
|
nbtItem.setLong(key, Long.parseLong(val));
|
||||||
|
break;
|
||||||
|
case "float":
|
||||||
|
nbtItem.setFloat(key, Float.parseFloat(val));
|
||||||
|
break;
|
||||||
|
case "double":
|
||||||
|
nbtItem.setDouble(key, Double.parseDouble(val));
|
||||||
|
break;
|
||||||
|
case "string":
|
||||||
|
nbtItem.setString(key, val);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw new IllegalArgumentException("Unsupported NBT type: " + type);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set typed value on an NBTCompound
|
||||||
|
private void setNBTOnCompound(NBTCompound compound, String key, String value) {
|
||||||
|
int underscoreIndex = value.indexOf("_");
|
||||||
|
if (underscoreIndex == -1) return; // Invalid format, skip
|
||||||
|
|
||||||
|
String type = value.substring(0, underscoreIndex);
|
||||||
|
String val = value.substring(underscoreIndex + 1);
|
||||||
|
|
||||||
|
switch (type.toLowerCase()) {
|
||||||
|
case "byte":
|
||||||
|
compound.setByte(key, Byte.parseByte(val));
|
||||||
|
break;
|
||||||
|
case "boolean":
|
||||||
|
compound.setBoolean(key, Boolean.parseBoolean(val));
|
||||||
|
break;
|
||||||
|
case "short":
|
||||||
|
compound.setShort(key, Short.parseShort(val));
|
||||||
|
break;
|
||||||
|
case "integer":
|
||||||
|
compound.setInteger(key, Integer.parseInt(val));
|
||||||
|
break;
|
||||||
|
case "long":
|
||||||
|
compound.setLong(key, Long.parseLong(val));
|
||||||
|
break;
|
||||||
|
case "float":
|
||||||
|
compound.setFloat(key, Float.parseFloat(val));
|
||||||
|
break;
|
||||||
|
case "double":
|
||||||
|
compound.setDouble(key, Double.parseDouble(val));
|
||||||
|
break;
|
||||||
|
case "string":
|
||||||
|
compound.setString(key, val);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw new IllegalArgumentException("Unsupported NBT type: " + type);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,77 @@
|
|||||||
|
package me.rockyhawk.commandpanels.ioclasses.potions;
|
||||||
|
|
||||||
|
import me.rockyhawk.commandpanels.CommandPanels;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
|
import java.lang.reflect.Constructor;
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
|
||||||
|
public class ClassicPotionData {
|
||||||
|
private CommandPanels plugin;
|
||||||
|
|
||||||
|
public ClassicPotionData(CommandPanels plugin) {
|
||||||
|
this.plugin = plugin;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void applyPotionEffect(Player p, ItemStack item, String[] effectType) {
|
||||||
|
try {
|
||||||
|
if (item == null || item.getType() != org.bukkit.Material.POTION) {
|
||||||
|
p.sendMessage(plugin.tex.colour(plugin.tag + ChatColor.RED + "Item is not a potion."));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Class<?> potionClass = Class.forName("org.bukkit.potion.Potion");
|
||||||
|
Class<?> potionTypeClass = Class.forName("org.bukkit.potion.PotionType");
|
||||||
|
|
||||||
|
Object potionType = Enum.valueOf((Class<Enum>) potionTypeClass, effectType[0].toUpperCase());
|
||||||
|
Constructor<?> potionConstructor = potionClass.getConstructor(potionTypeClass, int.class);
|
||||||
|
Object potion = potionConstructor.newInstance(potionType, effectType.length >= 3 && effectType[2].equalsIgnoreCase("true") ? 2 : 1);
|
||||||
|
|
||||||
|
Method setSplashMethod = potionClass.getMethod("setSplash", boolean.class);
|
||||||
|
boolean isSplash = (item.getDurability() & 0x4000) != 0; // Checks if the durability indicates it's a splash potion
|
||||||
|
setSplashMethod.invoke(potion, isSplash);
|
||||||
|
|
||||||
|
try {
|
||||||
|
Method setHasExtendedDurationMethod = potionClass.getMethod("setHasExtendedDuration", boolean.class);
|
||||||
|
setHasExtendedDurationMethod.invoke(potion, effectType.length >= 2 && effectType[1].equalsIgnoreCase("true"));
|
||||||
|
}catch (Exception ignore){
|
||||||
|
//ignore as some potions like instant potions cannot be extended
|
||||||
|
}
|
||||||
|
|
||||||
|
Method applyMethod = potionClass.getMethod("apply", ItemStack.class);
|
||||||
|
applyMethod.invoke(potion, item);
|
||||||
|
} catch (Exception er) {
|
||||||
|
plugin.debug(er, p);
|
||||||
|
p.sendMessage(plugin.tex.colour(plugin.tag + ChatColor.RED + "Incorrect potion type or format."));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public String retrievePotionData(ItemStack item) {
|
||||||
|
try {
|
||||||
|
if (item == null || item.getType() != org.bukkit.Material.POTION) {
|
||||||
|
return "Item is not a potion";
|
||||||
|
}
|
||||||
|
|
||||||
|
Class<?> potionClass = Class.forName("org.bukkit.potion.Potion");
|
||||||
|
Method fromItemStackMethod = potionClass.getMethod("fromItemStack", ItemStack.class);
|
||||||
|
Object potion = fromItemStackMethod.invoke(null, item);
|
||||||
|
|
||||||
|
Method getTypeMethod = potionClass.getMethod("getType");
|
||||||
|
Method isExtendedMethod = potionClass.getMethod("hasExtendedDuration");
|
||||||
|
Method isUpgradedMethod = potionClass.getMethod("getLevel");
|
||||||
|
|
||||||
|
Object potionType = getTypeMethod.invoke(potion);
|
||||||
|
boolean extended = (Boolean) isExtendedMethod.invoke(potion);
|
||||||
|
boolean upgraded = ((Integer) isUpgradedMethod.invoke(potion)) > 1;
|
||||||
|
|
||||||
|
boolean isSplash = (item.getDurability() & 0x4000) != 0; // Checks if the durability indicates it's a splash potion
|
||||||
|
|
||||||
|
return potionType.toString() + " " + extended + " " + upgraded + " Splash:" + isSplash;
|
||||||
|
} catch (Exception e) {
|
||||||
|
plugin.debug(e, null);
|
||||||
|
return "Failed to retrieve potion data";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,81 @@
|
|||||||
|
package me.rockyhawk.commandpanels.ioclasses.potions;
|
||||||
|
|
||||||
|
import me.rockyhawk.commandpanels.CommandPanels;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.inventory.meta.PotionMeta;
|
||||||
|
import org.bukkit.potion.PotionType;
|
||||||
|
import java.lang.reflect.Constructor;
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
|
||||||
|
public class LegacyPotionData {
|
||||||
|
/*
|
||||||
|
* To be used in Minecraft 1.9 to 1.20.4
|
||||||
|
* */
|
||||||
|
private CommandPanels plugin;
|
||||||
|
|
||||||
|
public LegacyPotionData(CommandPanels plugin) {
|
||||||
|
this.plugin = plugin;
|
||||||
|
}
|
||||||
|
|
||||||
|
//effect type should be PotionType Extended? Upgraded?
|
||||||
|
public void applyPotionEffect(Player p, ItemStack item, String[] effectType) {
|
||||||
|
try {
|
||||||
|
PotionMeta potionMeta = (PotionMeta) item.getItemMeta();
|
||||||
|
assert potionMeta != null;
|
||||||
|
boolean extended = false;
|
||||||
|
boolean upgraded = false;
|
||||||
|
|
||||||
|
if (effectType.length >= 2) {
|
||||||
|
extended = effectType[1].equalsIgnoreCase("true");
|
||||||
|
if (effectType.length == 3) {
|
||||||
|
upgraded = effectType[2].equalsIgnoreCase("true");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Class<?> potionDataType = Class.forName("org.bukkit.potion.PotionData");
|
||||||
|
Constructor<?> potionDataConstructor = potionDataType.getConstructor(PotionType.class, boolean.class, boolean.class);
|
||||||
|
Object potionData = potionDataConstructor.newInstance(PotionType.valueOf(effectType[0].toUpperCase()), extended, upgraded);
|
||||||
|
|
||||||
|
Method setBasePotionDataMethod = potionMeta.getClass().getMethod("setBasePotionData", potionDataType);
|
||||||
|
setBasePotionDataMethod.setAccessible(true); // Setting the method as accessible
|
||||||
|
setBasePotionDataMethod.invoke(potionMeta, potionData);
|
||||||
|
|
||||||
|
item.setItemMeta(potionMeta);
|
||||||
|
} catch (Exception er) {
|
||||||
|
plugin.debug(er, p);
|
||||||
|
p.sendMessage(plugin.tex.colour(plugin.tag + ChatColor.RED + plugin.config.getString("config.format.error") + " incorrect potion"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//returns PotionType Extended? Upgraded?
|
||||||
|
public String retrievePotionData(ItemStack item) {
|
||||||
|
try {
|
||||||
|
PotionMeta potionMeta = (PotionMeta) item.getItemMeta();
|
||||||
|
assert potionMeta != null;
|
||||||
|
|
||||||
|
Method getBasePotionDataMethod = potionMeta.getClass().getMethod("getBasePotionData");
|
||||||
|
getBasePotionDataMethod.setAccessible(true); // Set the method as accessible
|
||||||
|
Object potionData = getBasePotionDataMethod.invoke(potionMeta);
|
||||||
|
|
||||||
|
Class<?> potionDataType = Class.forName("org.bukkit.potion.PotionData");
|
||||||
|
Method getTypeMethod = potionDataType.getMethod("getType");
|
||||||
|
Method isUpgradedMethod = potionDataType.getMethod("isUpgraded");
|
||||||
|
Method isExtendedMethod = potionDataType.getMethod("isExtended");
|
||||||
|
|
||||||
|
getTypeMethod.setAccessible(true); // Set the method as accessible
|
||||||
|
isUpgradedMethod.setAccessible(true); // Set the method as accessible
|
||||||
|
isExtendedMethod.setAccessible(true); // Set the method as accessible
|
||||||
|
|
||||||
|
PotionType potionType = (PotionType) getTypeMethod.invoke(potionData);
|
||||||
|
boolean level = (boolean) isUpgradedMethod.invoke(potionData);
|
||||||
|
boolean extended = (boolean) isExtendedMethod.invoke(potionData);
|
||||||
|
|
||||||
|
return potionType.name() + " " + extended + " " + level;
|
||||||
|
} catch (Exception e) {
|
||||||
|
plugin.debug(e, null);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,4 +1,4 @@
|
|||||||
package me.rockyhawk.commandpanels.ioclasses;
|
package me.rockyhawk.commandpanels.ioclasses.storagecontents;
|
||||||
|
|
||||||
import me.rockyhawk.commandpanels.CommandPanels;
|
import me.rockyhawk.commandpanels.CommandPanels;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
@ -1,4 +1,4 @@
|
|||||||
package me.rockyhawk.commandpanels.ioclasses;
|
package me.rockyhawk.commandpanels.ioclasses.storagecontents;
|
||||||
|
|
||||||
import me.rockyhawk.commandpanels.CommandPanels;
|
import me.rockyhawk.commandpanels.CommandPanels;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
@ -2,6 +2,7 @@ package me.rockyhawk.commandpanels.openpanelsmanager;
|
|||||||
|
|
||||||
import me.rockyhawk.commandpanels.CommandPanels;
|
import me.rockyhawk.commandpanels.CommandPanels;
|
||||||
import me.rockyhawk.commandpanels.api.Panel;
|
import me.rockyhawk.commandpanels.api.Panel;
|
||||||
|
import me.rockyhawk.commandpanels.ioclasses.legacy.MinecraftVersions;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.configuration.ConfigurationSection;
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
@ -27,15 +28,7 @@ public class OpenGUI {
|
|||||||
|
|
||||||
Inventory i;
|
Inventory i;
|
||||||
if(position == PanelPosition.Top) {
|
if(position == PanelPosition.Top) {
|
||||||
String title;
|
String title = getTitle(p, pconfig, panel, position, animateValue);
|
||||||
if(pconfig.contains("custom-title")) {
|
|
||||||
//used for titles in the custom-title section, for has sections
|
|
||||||
String section = plugin.has.hasSection(panel,position,pconfig.getConfigurationSection("custom-title"), p);
|
|
||||||
title = plugin.tex.placeholders(panel, position, p, pconfig.getString("custom-title" + section + ".title"));
|
|
||||||
}else {
|
|
||||||
//regular inventory title
|
|
||||||
title = plugin.tex.placeholders(panel, position, p, pconfig.getString("title"));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isNumeric(pconfig.getString("rows"))) {
|
if (isNumeric(pconfig.getString("rows"))) {
|
||||||
i = Bukkit.createInventory(p, Integer.parseInt(pconfig.getString("rows")) * 9, title);
|
i = Bukkit.createInventory(p, Integer.parseInt(pconfig.getString("rows")) * 9, title);
|
||||||
@ -56,9 +49,9 @@ public class OpenGUI {
|
|||||||
Set<String> itemList = pconfig.getConfigurationSection("item").getKeys(false);
|
Set<String> itemList = pconfig.getConfigurationSection("item").getKeys(false);
|
||||||
HashSet<Integer> takenSlots = new HashSet<>();
|
HashSet<Integer> takenSlots = new HashSet<>();
|
||||||
for (String item : itemList) {
|
for (String item : itemList) {
|
||||||
String section = "";
|
String section;
|
||||||
//openType needs to not be 3 so the editor won't include hasperm and hasvalue, etc items
|
//openType needs to not be 3 so the editor won't include hasperm and hasvalue, etc items
|
||||||
section = plugin.has.hasSection(panel,position,pconfig.getConfigurationSection("item." + Integer.parseInt(item)), p);
|
section = plugin.has.hasSection(panel,position,pconfig.getConfigurationSection("item." + item), p);
|
||||||
//This section is for animations below here: VISUAL ONLY
|
//This section is for animations below here: VISUAL ONLY
|
||||||
|
|
||||||
//check for if there is animations inside the items section
|
//check for if there is animations inside the items section
|
||||||
@ -69,7 +62,6 @@ public class OpenGUI {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//will only add NBT if not an editor GUI
|
|
||||||
ItemStack s = plugin.itemCreate.makeItemFromConfig(panel,position,Objects.requireNonNull(pconfig.getConfigurationSection("item." + item + section)), p, true, true, true);
|
ItemStack s = plugin.itemCreate.makeItemFromConfig(panel,position,Objects.requireNonNull(pconfig.getConfigurationSection("item." + item + section)), p, true, true, true);
|
||||||
|
|
||||||
//This is for CUSTOM ITEMS
|
//This is for CUSTOM ITEMS
|
||||||
@ -77,17 +69,16 @@ public class OpenGUI {
|
|||||||
//this is for contents in the itemType section
|
//this is for contents in the itemType section
|
||||||
if (pconfig.getStringList("item." + item + section + ".itemType").contains("placeable") && openType == PanelOpenType.Refresh) {
|
if (pconfig.getStringList("item." + item + section + ".itemType").contains("placeable") && openType == PanelOpenType.Refresh) {
|
||||||
//keep item the same, openType == 0 meaning panel is refreshing
|
//keep item the same, openType == 0 meaning panel is refreshing
|
||||||
setItem(p.getOpenInventory().getItem(Integer.parseInt(item)),Integer.parseInt(item),i,p,position);
|
setItem(p.getOpenInventory().getItem(Integer.parseInt(plugin.tex.placeholdersNoColour(panel,position,p,item))), item, i, p, position);
|
||||||
takenSlots.add(Integer.parseInt(item));
|
takenSlots.add(Integer.parseInt(plugin.tex.placeholdersNoColour(panel,position,p,item)));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
//place item into the GUI
|
//place item into the GUI
|
||||||
setItem(s,Integer.parseInt(item),i,p,position);
|
setItem(s,item,i,p,position);
|
||||||
takenSlots.add(Integer.parseInt(item));
|
takenSlots.add(Integer.parseInt(plugin.tex.placeholdersNoColour(panel,position,p,item)));
|
||||||
//i.setItem(Integer.parseInt(item), s);
|
|
||||||
//only place duplicate items in without the editor mode. These are merely visual and will not carry over commands
|
//only place duplicate items in without the editor mode. These are merely visual and will not carry over commands
|
||||||
if(pconfig.contains("item." + item + section + ".duplicate")) {
|
if(pconfig.contains("item." + item + section + ".duplicate")) {
|
||||||
try {
|
try {
|
||||||
@ -128,20 +119,20 @@ public class OpenGUI {
|
|||||||
}
|
}
|
||||||
} catch (ArrayIndexOutOfBoundsException ignore) {}
|
} catch (ArrayIndexOutOfBoundsException ignore) {}
|
||||||
}
|
}
|
||||||
if (pconfig.contains("empty") && !Objects.equals(pconfig.getString("empty"), "AIR")) {
|
if (pconfig.contains("empty") && !plugin.tex.placeholdersNoColour(panel,position,p,pconfig.getString("empty")).equals("AIR")) {
|
||||||
|
String emptyValue = plugin.tex.placeholdersNoColour(panel,position,p,pconfig.getString("empty"));
|
||||||
ItemStack empty;
|
ItemStack empty;
|
||||||
try {
|
try {
|
||||||
//emptyID for older versions of minecraft (might be deprecated later on)
|
//emptyID for older versions of minecraft (might be deprecated later on)
|
||||||
short id = 0;
|
short id = 0;
|
||||||
if(pconfig.contains("emptyID")){
|
if(pconfig.contains("emptyID")){
|
||||||
id = Short.parseShort(pconfig.getString("emptyID"));
|
id = Short.parseShort(plugin.tex.placeholdersNoColour(panel,position,p,pconfig.getString("emptyID")));
|
||||||
}
|
}
|
||||||
//either use custom item or just material type
|
//either use custom item or just material type
|
||||||
if(pconfig.contains("custom-item." + pconfig.getString("empty"))){
|
if(pconfig.contains("custom-item." + emptyValue)){
|
||||||
empty = plugin.itemCreate.makeItemFromConfig(panel,position,pconfig.getConfigurationSection("custom-item." + pconfig.getString("empty")),p,true,true,true);
|
empty = plugin.itemCreate.makeItemFromConfig(panel,position,pconfig.getConfigurationSection("custom-item." + emptyValue),p,true,true,true);
|
||||||
}else{
|
}else{
|
||||||
empty = new ItemStack(Objects.requireNonNull(Material.matchMaterial(pconfig.getString("empty").toUpperCase())), 1,id);
|
empty = new ItemStack(Objects.requireNonNull(Material.matchMaterial(emptyValue.toUpperCase())), 1,id);
|
||||||
empty = plugin.nbt.setNBT(empty);
|
|
||||||
ItemMeta renamedMeta = empty.getItemMeta();
|
ItemMeta renamedMeta = empty.getItemMeta();
|
||||||
assert renamedMeta != null;
|
assert renamedMeta != null;
|
||||||
renamedMeta.setDisplayName(" ");
|
renamedMeta.setDisplayName(" ");
|
||||||
@ -173,7 +164,14 @@ public class OpenGUI {
|
|||||||
}
|
}
|
||||||
plugin.openPanels.skipPanelClose.remove(p.getName());
|
plugin.openPanels.skipPanelClose.remove(p.getName());
|
||||||
} else if (openType == PanelOpenType.Refresh) {
|
} else if (openType == PanelOpenType.Refresh) {
|
||||||
//openType 0 will just refresh the panel
|
//openType Refresh will just refresh the panel
|
||||||
|
if(plugin.legacy.MAJOR_VERSION.greaterThanOrEqualTo(MinecraftVersions.v1_21) ||
|
||||||
|
(plugin.legacy.MAJOR_VERSION.greaterThanOrEqualTo(MinecraftVersions.v1_20) && plugin.legacy.MINOR_VERSION >= 5)){
|
||||||
|
//Title refresh ability added in 1.20.5 api
|
||||||
|
if(position == PanelPosition.Top) {
|
||||||
|
p.getOpenInventory().setTitle(getTitle(p, pconfig, panel, position, animateValue));
|
||||||
|
}
|
||||||
|
}
|
||||||
if(position == PanelPosition.Top) {
|
if(position == PanelPosition.Top) {
|
||||||
plugin.legacy.setStorageContents(p, plugin.legacy.getStorageContents(i));
|
plugin.legacy.setStorageContents(p, plugin.legacy.getStorageContents(i));
|
||||||
}
|
}
|
||||||
@ -193,6 +191,12 @@ public class OpenGUI {
|
|||||||
return 9;
|
return 9;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//allows for a string to be used instead of integer, for placeholders
|
||||||
|
private void setItem(ItemStack item, String slotName, Inventory inv, Player p, PanelPosition position) throws ArrayIndexOutOfBoundsException{
|
||||||
|
int slot = Integer.parseInt(plugin.tex.placeholdersNoColour(null, position, p, slotName));
|
||||||
|
setItem(item, slot, inv, p, position);
|
||||||
|
}
|
||||||
private void setItem(ItemStack item, int slot, Inventory inv, Player p, PanelPosition position) throws ArrayIndexOutOfBoundsException{
|
private void setItem(ItemStack item, int slot, Inventory inv, Player p, PanelPosition position) throws ArrayIndexOutOfBoundsException{
|
||||||
if(position == PanelPosition.Top){
|
if(position == PanelPosition.Top){
|
||||||
inv.setItem(slot, item);
|
inv.setItem(slot, item);
|
||||||
@ -218,4 +222,23 @@ public class OpenGUI {
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String getTitle(Player p, ConfigurationSection pconfig, Panel panel, PanelPosition position, Integer animateValue){
|
||||||
|
String title;
|
||||||
|
if(pconfig.contains("custom-title")) {
|
||||||
|
//used for titles in the custom-title section, for has sections
|
||||||
|
String section = plugin.has.hasSection(panel,position,pconfig.getConfigurationSection("custom-title"), p);
|
||||||
|
|
||||||
|
//check for if there is animations inside the custom-title section
|
||||||
|
if (pconfig.contains("custom-title" + section + ".animate" + animateValue)) {
|
||||||
|
section = section + ".animate" + animateValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
title = plugin.tex.placeholders(panel, position, p, pconfig.getString("custom-title" + section + ".title"));
|
||||||
|
}else {
|
||||||
|
//regular inventory title
|
||||||
|
title = plugin.tex.placeholders(panel, position, p, pconfig.getString("title"));
|
||||||
|
}
|
||||||
|
return title;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,7 @@ import me.rockyhawk.commandpanels.api.Panel;
|
|||||||
import me.rockyhawk.commandpanels.api.PanelClosedEvent;
|
import me.rockyhawk.commandpanels.api.PanelClosedEvent;
|
||||||
import me.rockyhawk.commandpanels.api.PanelsInterface;
|
import me.rockyhawk.commandpanels.api.PanelsInterface;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
@ -123,16 +124,27 @@ public class OpenPanelsLoader {
|
|||||||
if (panel.getConfig().contains("commands-on-close")) {
|
if (panel.getConfig().contains("commands-on-close")) {
|
||||||
//execute commands on panel close
|
//execute commands on panel close
|
||||||
try {
|
try {
|
||||||
plugin.commandTags.runCommands(panel,position,Bukkit.getPlayer(playerName),panel.getConfig().getStringList("commands-on-close"));
|
plugin.commandRunner.runCommands(panel,position,Bukkit.getPlayer(playerName),panel.getConfig().getStringList("commands-on-close"), null);
|
||||||
}catch(Exception s){
|
}catch(Exception s){
|
||||||
plugin.debug(s,null);
|
plugin.debug(s,null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isNBTInjected(ItemStack itm){
|
//if any CommandPanels items exist outside a panel, they will be removed
|
||||||
|
public void deleteCommandPanelsItems(Player p){
|
||||||
|
for(ItemStack itm : p.getInventory().getContents()){
|
||||||
|
if(itm != null){
|
||||||
|
if (plugin.nbt.hasNBT(itm, "CommandPanelsItem")) {
|
||||||
|
p.getInventory().remove(itm);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//checks if an item is from cpanel or not
|
||||||
|
public boolean isCommandPanelsItem(ItemStack itm){
|
||||||
if(itm != null){
|
if(itm != null){
|
||||||
return plugin.nbt.hasNBT(itm);
|
return plugin.nbt.hasNBT(itm,"CommandPanelsItem");
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,7 @@ import me.rockyhawk.commandpanels.CommandPanels;
|
|||||||
import me.rockyhawk.commandpanels.api.Panel;
|
import me.rockyhawk.commandpanels.api.Panel;
|
||||||
import me.rockyhawk.commandpanels.api.PanelClosedEvent;
|
import me.rockyhawk.commandpanels.api.PanelClosedEvent;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.Material;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.EventPriority;
|
import org.bukkit.event.EventPriority;
|
||||||
@ -12,10 +13,7 @@ import org.bukkit.event.inventory.InventoryClickEvent;
|
|||||||
import org.bukkit.event.inventory.InventoryCloseEvent;
|
import org.bukkit.event.inventory.InventoryCloseEvent;
|
||||||
import org.bukkit.event.inventory.InventoryOpenEvent;
|
import org.bukkit.event.inventory.InventoryOpenEvent;
|
||||||
import org.bukkit.event.player.PlayerQuitEvent;
|
import org.bukkit.event.player.PlayerQuitEvent;
|
||||||
import org.bukkit.inventory.ItemStack;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
public class UtilsPanelsLoader implements Listener {
|
public class UtilsPanelsLoader implements Listener {
|
||||||
@ -30,13 +28,7 @@ public class UtilsPanelsLoader implements Listener {
|
|||||||
plugin.openPanels.closePanelForLoader(e.getPlayer().getName(),PanelPosition.Top);
|
plugin.openPanels.closePanelForLoader(e.getPlayer().getName(),PanelPosition.Top);
|
||||||
Player p = e.getPlayer();
|
Player p = e.getPlayer();
|
||||||
p.updateInventory();
|
p.updateInventory();
|
||||||
for(ItemStack itm : p.getInventory().getContents()){
|
plugin.openPanels.deleteCommandPanelsItems(p);
|
||||||
if(itm != null){
|
|
||||||
if (plugin.nbt.hasNBT(itm)) {
|
|
||||||
p.getInventory().remove(itm);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//tell panel loader that player has closed the panel (there is also one of these in EditorUtils)
|
//tell panel loader that player has closed the panel (there is also one of these in EditorUtils)
|
||||||
@ -79,12 +71,6 @@ public class UtilsPanelsLoader implements Listener {
|
|||||||
|
|
||||||
//close panels and run commands for Top panel
|
//close panels and run commands for Top panel
|
||||||
plugin.openPanels.closePanelForLoader(e.getPlayer().getName(),PanelPosition.Top);
|
plugin.openPanels.closePanelForLoader(e.getPlayer().getName(),PanelPosition.Top);
|
||||||
|
|
||||||
//clear cached textures list until length limit is reached
|
|
||||||
while (plugin.customHeads.playerHeadTextures.size() > 2000) {
|
|
||||||
List<String> keys = new ArrayList<>(plugin.customHeads.playerHeadTextures.keySet());
|
|
||||||
plugin.customHeads.playerHeadTextures.remove(keys.get(0));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
@ -92,10 +78,10 @@ public class UtilsPanelsLoader implements Listener {
|
|||||||
//this will check to ensure an item is not from CommandPanels on inventory open
|
//this will check to ensure an item is not from CommandPanels on inventory open
|
||||||
Player p = (Player)e.getWhoClicked();
|
Player p = (Player)e.getWhoClicked();
|
||||||
if(!plugin.openPanels.hasPanelOpen(p.getName(),PanelPosition.Top)){
|
if(!plugin.openPanels.hasPanelOpen(p.getName(),PanelPosition.Top)){
|
||||||
for(ItemStack itm : p.getInventory().getContents()){
|
if(e.getCurrentItem() == null){return;}
|
||||||
if(plugin.openPanels.isNBTInjected(itm)){
|
if(e.getCurrentItem().getType() == Material.AIR){return;}
|
||||||
p.getInventory().remove(itm);
|
if(plugin.openPanels.isCommandPanelsItem(e.getCurrentItem())){
|
||||||
}
|
p.getInventory().remove(e.getCurrentItem());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -36,7 +36,7 @@ public class HotbarItemLoader {
|
|||||||
if(stationaryItems.get(p.getUniqueId()).list.containsKey(String.valueOf(slot))){
|
if(stationaryItems.get(p.getUniqueId()).list.containsKey(String.valueOf(slot))){
|
||||||
if(openPanel) {
|
if(openPanel) {
|
||||||
try {
|
try {
|
||||||
if (!plugin.nbt.getNBT(p.getInventory().getItem(slot), "CommandPanelsHotbar").split(":")[1].equals(String.valueOf(slot))) {
|
if (!String.valueOf(plugin.nbt.getNBT(p.getInventory().getItem(slot), "CommandPanelsHotbar", "string")).split(":")[1].equals(String.valueOf(slot))) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}catch(Exception ex){
|
}catch(Exception ex){
|
||||||
@ -51,7 +51,7 @@ public class HotbarItemLoader {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if(panel.getHotbarSection(p).contains("commands")){
|
if(panel.getHotbarSection(p).contains("commands")){
|
||||||
plugin.commandTags.runCommands(panel,PanelPosition.Top,p,panel.getHotbarSection(p).getStringList("commands"),click);
|
plugin.commandRunner.runCommands(panel,PanelPosition.Top,p,panel.getHotbarSection(p).getStringList("commands"),click);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
panel.open(p, PanelPosition.Top);
|
panel.open(p, PanelPosition.Top);
|
||||||
@ -64,7 +64,7 @@ public class HotbarItemLoader {
|
|||||||
//return true if found
|
//return true if found
|
||||||
public boolean itemCheckExecute(ItemStack invItem, Player p, boolean openPanel, boolean stationaryOnly){
|
public boolean itemCheckExecute(ItemStack invItem, Player p, boolean openPanel, boolean stationaryOnly){
|
||||||
try {
|
try {
|
||||||
if (Objects.equals(plugin.nbt.getNBT(invItem, "CommandPanelsHotbar"), "")) {
|
if (Objects.equals(String.valueOf(plugin.nbt.getNBT(invItem, "CommandPanelsHotbar", "string")), "")) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}catch(IllegalArgumentException | NullPointerException nu){
|
}catch(IllegalArgumentException | NullPointerException nu){
|
||||||
@ -73,13 +73,13 @@ public class HotbarItemLoader {
|
|||||||
for(Panel panel : plugin.panelList) {
|
for(Panel panel : plugin.panelList) {
|
||||||
if(stationaryOnly){
|
if(stationaryOnly){
|
||||||
try {
|
try {
|
||||||
if (plugin.nbt.getNBT(invItem, "CommandPanelsHotbar").split(":")[1].equals("-1")) {
|
if (String.valueOf(plugin.nbt.getNBT(invItem, "CommandPanelsHotbar", "string")).split(":")[1].equals("-1")) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}catch(NullPointerException | IllegalArgumentException ignore){}
|
}catch(NullPointerException | IllegalArgumentException ignore){}
|
||||||
}
|
}
|
||||||
if(panel.hasHotbarItem()){
|
if(panel.hasHotbarItem()){
|
||||||
if(plugin.nbt.getNBT(invItem,"CommandPanelsHotbar").split(":")[0].equals(panel.getName())){
|
if(String.valueOf(plugin.nbt.getNBT(invItem, "CommandPanelsHotbar", "string")).split(":")[0].equals(panel.getName())){
|
||||||
if(openPanel) {
|
if(openPanel) {
|
||||||
//only open panel automatically if there are no commands and if world is not disabled
|
//only open panel automatically if there are no commands and if world is not disabled
|
||||||
if(!plugin.panelPerms.isPanelWorldEnabled(p,panel.getConfig())){
|
if(!plugin.panelPerms.isPanelWorldEnabled(p,panel.getConfig())){
|
||||||
@ -87,7 +87,7 @@ public class HotbarItemLoader {
|
|||||||
}
|
}
|
||||||
if(panel.getHotbarSection(p).contains("commands")){
|
if(panel.getHotbarSection(p).contains("commands")){
|
||||||
for(String command : panel.getHotbarSection(p).getStringList("commands")){
|
for(String command : panel.getHotbarSection(p).getStringList("commands")){
|
||||||
plugin.commandTags.runCommand(panel,PanelPosition.Top,p, command);
|
plugin.commandRunner.runCommand(panel,PanelPosition.Top,p, command);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -120,9 +120,9 @@ public class HotbarItemLoader {
|
|||||||
stationaryItems.put(p.getUniqueId(),new HotbarPlayerManager());
|
stationaryItems.put(p.getUniqueId(),new HotbarPlayerManager());
|
||||||
for(int i = 0; i <= 35; i++){
|
for(int i = 0; i <= 35; i++){
|
||||||
try {
|
try {
|
||||||
if (!Objects.equals(plugin.nbt.getNBT(p.getInventory().getItem(i), "CommandPanelsHotbar"), "")) {
|
if (!Objects.equals(String.valueOf(plugin.nbt.getNBT(p.getInventory().getItem(i), "CommandPanelsHotbar", "string")), "")) {
|
||||||
//do not remove items that are not stationary
|
//do not remove items that are not stationary
|
||||||
if(!plugin.nbt.getNBT(p.getInventory().getItem(i), "CommandPanelsHotbar").endsWith("-1")) {
|
if(!String.valueOf(plugin.nbt.getNBT(p.getInventory().getItem(i), "CommandPanelsHotbar","string")).endsWith("-1")) {
|
||||||
p.getInventory().setItem(i, new ItemStack(Material.AIR));
|
p.getInventory().setItem(i, new ItemStack(Material.AIR));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,14 +1,15 @@
|
|||||||
package me.rockyhawk.commandpanels.openwithitem;
|
package me.rockyhawk.commandpanels.openwithitem;
|
||||||
|
|
||||||
import me.rockyhawk.commandpanels.CommandPanels;
|
import me.rockyhawk.commandpanels.CommandPanels;
|
||||||
import me.rockyhawk.commandpanels.ioclasses.GetItemInHand;
|
import me.rockyhawk.commandpanels.ioclasses.iteminhand.GetItemInHand;
|
||||||
import me.rockyhawk.commandpanels.ioclasses.GetItemInHand_Legacy;
|
import me.rockyhawk.commandpanels.ioclasses.iteminhand.GetItemInHand_Legacy;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.event.block.Action;
|
import org.bukkit.event.block.Action;
|
||||||
|
import org.bukkit.event.block.BlockPlaceEvent;
|
||||||
import org.bukkit.event.entity.PlayerDeathEvent;
|
import org.bukkit.event.entity.PlayerDeathEvent;
|
||||||
import org.bukkit.event.inventory.InventoryAction;
|
import org.bukkit.event.inventory.InventoryAction;
|
||||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||||
@ -67,6 +68,29 @@ public class UtilsOpenWithItem implements Listener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
@EventHandler
|
@EventHandler
|
||||||
|
public void onBlockPlace(BlockPlaceEvent e)
|
||||||
|
{
|
||||||
|
//item right-clicked only (not left because that causes issues when things are interacted with)
|
||||||
|
if(!plugin.openWithItem){
|
||||||
|
//if none of the panels have open-with-item
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Player p = e.getPlayer();
|
||||||
|
if(Bukkit.getVersion().contains("1.8")){
|
||||||
|
if(plugin.hotbar.itemCheckExecute(e.getPlayer().getItemInHand(),p,false,false)){
|
||||||
|
e.setCancelled(true);
|
||||||
|
p.updateInventory();
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
if(plugin.hotbar.itemCheckExecute(e.getPlayer().getInventory().getItemInMainHand(),p,false,false)){
|
||||||
|
e.setCancelled(true);
|
||||||
|
p.updateInventory();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
@EventHandler
|
||||||
public void onWorldChange(PlayerChangedWorldEvent e){
|
public void onWorldChange(PlayerChangedWorldEvent e){
|
||||||
plugin.hotbar.updateHotbarItems(e.getPlayer());
|
plugin.hotbar.updateHotbarItems(e.getPlayer());
|
||||||
}
|
}
|
||||||
@ -74,22 +98,28 @@ public class UtilsOpenWithItem implements Listener {
|
|||||||
public void onPlayerRespawn(PlayerRespawnEvent e){
|
public void onPlayerRespawn(PlayerRespawnEvent e){
|
||||||
plugin.hotbar.updateHotbarItems(e.getPlayer());
|
plugin.hotbar.updateHotbarItems(e.getPlayer());
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onPlayerDeath(PlayerDeathEvent e){
|
public void onPlayerDeath(PlayerDeathEvent e){
|
||||||
if(!plugin.openWithItem){
|
if(!plugin.openWithItem){
|
||||||
//if none of the panels have open-with-item
|
//if none of the panels have open-with-item
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
//a new list instance has to be created with the dropped items to avoid ConcurrentModificationException
|
//a new list instance has to be created with the dropped items to avoid ConcurrentModificationException
|
||||||
for(ItemStack s : new ArrayList<>(e.getDrops())){
|
try {
|
||||||
try {
|
for (ItemStack s : new ArrayList<>(e.getDrops())) {
|
||||||
if (plugin.nbt.getNBT(s, "CommandPanelsHotbar") != null) {
|
try {
|
||||||
//do not remove items that are not stationary
|
if (!String.valueOf(plugin.nbt.getNBT(s, "CommandPanelsHotbar", "string")).isEmpty()) {
|
||||||
if(!plugin.nbt.getNBT(s, "CommandPanelsHotbar").endsWith("-1")) {
|
//do not remove items that are not stationary
|
||||||
e.getDrops().remove(s);
|
if (!String.valueOf(plugin.nbt.getNBT(s, "CommandPanelsHotbar", "string")).endsWith("-1")) {
|
||||||
|
e.getDrops().remove(s);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
} catch (NullPointerException | IllegalArgumentException ignore) {}
|
||||||
}catch(NullPointerException | IllegalArgumentException ignore){}
|
}
|
||||||
|
}catch (NullPointerException ignore){
|
||||||
|
System.out.println("crapped out");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@EventHandler
|
@EventHandler
|
||||||
|
@ -61,7 +61,7 @@ public class PanelBlockOnClick implements Listener {
|
|||||||
if(plugin.blockConfig.contains("blocks." + configLocation + ".commands")){
|
if(plugin.blockConfig.contains("blocks." + configLocation + ".commands")){
|
||||||
if(!isVoid) {
|
if(!isVoid) {
|
||||||
for (String command : plugin.blockConfig.getStringList("blocks." + configLocation + ".commands")) {
|
for (String command : plugin.blockConfig.getStringList("blocks." + configLocation + ".commands")) {
|
||||||
plugin.commandTags.runCommand(null, PanelPosition.Top, p, command);
|
plugin.commandRunner.runCommand(null, PanelPosition.Top, p, command);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
@ -69,7 +69,7 @@ public class PanelBlockOnClick implements Listener {
|
|||||||
//uses the open= tag because it will open a panel with panel names, but also works with open= features like placeholders
|
//uses the open= tag because it will open a panel with panel names, but also works with open= features like placeholders
|
||||||
if(!isVoid) {
|
if(!isVoid) {
|
||||||
String command = "open= " + plugin.blockConfig.getString("blocks." + configLocation + ".panel");
|
String command = "open= " + plugin.blockConfig.getString("blocks." + configLocation + ".panel");
|
||||||
plugin.commandTags.runCommand(null, PanelPosition.Top, p, command);
|
plugin.commandRunner.runCommand(null, PanelPosition.Top, p, command);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -4,11 +4,10 @@ import me.rockyhawk.commandpanels.CommandPanels;
|
|||||||
import me.rockyhawk.commandpanels.api.PanelOpenedEvent;
|
import me.rockyhawk.commandpanels.api.PanelOpenedEvent;
|
||||||
import me.rockyhawk.commandpanels.openpanelsmanager.PanelPosition;
|
import me.rockyhawk.commandpanels.openpanelsmanager.PanelPosition;
|
||||||
import org.bukkit.configuration.file.YamlConfiguration;
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
import org.bukkit.entity.HumanEntity;
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.EventPriority;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.event.entity.EntityPickupItemEvent;
|
|
||||||
import org.bukkit.event.entity.PlayerDeathEvent;
|
import org.bukkit.event.entity.PlayerDeathEvent;
|
||||||
import org.bukkit.event.player.PlayerInteractEvent;
|
import org.bukkit.event.player.PlayerInteractEvent;
|
||||||
import org.bukkit.event.player.PlayerJoinEvent;
|
import org.bukkit.event.player.PlayerJoinEvent;
|
||||||
@ -17,6 +16,7 @@ import org.bukkit.inventory.ItemStack;
|
|||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class InventorySaver implements Listener {
|
public class InventorySaver implements Listener {
|
||||||
public YamlConfiguration inventoryConfig;
|
public YamlConfiguration inventoryConfig;
|
||||||
@ -50,26 +50,26 @@ public class InventorySaver implements Listener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
@EventHandler
|
Run LOW event priority to run first ensuring other plugins and event handlers do not
|
||||||
|
use the CommandPanels panel instead of the players inventory when making decisions
|
||||||
|
*/
|
||||||
|
@EventHandler(priority = EventPriority.LOW)
|
||||||
public void onDeath(PlayerDeathEvent e){
|
public void onDeath(PlayerDeathEvent e){
|
||||||
//drop the players inventory if a panel is open in the inventory
|
//drop the players inventory if a mutli panel is open in the inventory
|
||||||
if (plugin.openPanels.hasPanelOpen(e.getEntity().getName(), PanelPosition.Middle) || plugin.openPanels.hasPanelOpen(e.getEntity().getName(), PanelPosition.Bottom)) {
|
if (plugin.openPanels.hasPanelOpen(e.getEntity().getName(), PanelPosition.Middle) || plugin.openPanels.hasPanelOpen(e.getEntity().getName(), PanelPosition.Bottom)) {
|
||||||
e.getDrops().clear();
|
if(e.getKeepInventory()) return;
|
||||||
e.getDrops().addAll(Arrays.asList(plugin.inventorySaver.getNormalInventory(e.getEntity())));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
e.getDrops().clear();
|
||||||
public void onPickup(EntityPickupItemEvent e){
|
|
||||||
if(e.getEntity() instanceof HumanEntity) {
|
// Retrieve the inventory, filter out null items, and then add them to e.getDrops()
|
||||||
Player p = (Player)e.getEntity();
|
// e.getDrops() will just return Null in general, just by containing null items in it
|
||||||
//move the item into the players inventory instead of the panel
|
ItemStack[] inventoryItems = plugin.inventorySaver.getNormalInventory(e.getEntity());
|
||||||
if (plugin.openPanels.hasPanelOpen(p.getName(), PanelPosition.Middle) || plugin.openPanels.hasPanelOpen(p.getName(), PanelPosition.Bottom)) {
|
List<ItemStack> nonNullItems = Arrays.stream(inventoryItems)
|
||||||
plugin.inventorySaver.addItem(p,e.getItem().getItemStack());
|
.filter(Objects::nonNull) // Filter out null items
|
||||||
e.getItem().remove();
|
.collect(Collectors.toList()); // Collect the remaining items into a list
|
||||||
e.setCancelled(true);
|
|
||||||
}
|
e.getDrops().addAll(nonNullItems);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -0,0 +1,29 @@
|
|||||||
|
package me.rockyhawk.commandpanels.playerinventoryhandler.pickupevent;
|
||||||
|
|
||||||
|
import me.rockyhawk.commandpanels.CommandPanels;
|
||||||
|
import me.rockyhawk.commandpanels.openpanelsmanager.PanelPosition;
|
||||||
|
import org.bukkit.entity.HumanEntity;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.entity.EntityPickupItemEvent;
|
||||||
|
|
||||||
|
public class EntityPickupEvent implements Listener {
|
||||||
|
|
||||||
|
CommandPanels plugin;
|
||||||
|
public EntityPickupEvent(CommandPanels pl) {
|
||||||
|
this.plugin = pl;
|
||||||
|
}
|
||||||
|
@EventHandler
|
||||||
|
public void onPickup(EntityPickupItemEvent e){
|
||||||
|
if(e.getEntity() instanceof HumanEntity) {
|
||||||
|
Player p = (Player)e.getEntity();
|
||||||
|
//move the item into the players inventory instead of the panel
|
||||||
|
if (plugin.openPanels.hasPanelOpen(p.getName(), PanelPosition.Middle) || plugin.openPanels.hasPanelOpen(p.getName(), PanelPosition.Bottom)) {
|
||||||
|
plugin.inventorySaver.addItem(p,e.getItem().getItemStack());
|
||||||
|
e.getItem().remove();
|
||||||
|
e.setCancelled(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,27 @@
|
|||||||
|
package me.rockyhawk.commandpanels.playerinventoryhandler.pickupevent;
|
||||||
|
|
||||||
|
import me.rockyhawk.commandpanels.CommandPanels;
|
||||||
|
import me.rockyhawk.commandpanels.openpanelsmanager.PanelPosition;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.player.PlayerPickupItemEvent;
|
||||||
|
|
||||||
|
public class legacyPlayerEvent implements Listener {
|
||||||
|
|
||||||
|
CommandPanels plugin;
|
||||||
|
public legacyPlayerEvent(CommandPanels pl) {
|
||||||
|
this.plugin = pl;
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onPickup(PlayerPickupItemEvent e){
|
||||||
|
Player p = e.getPlayer();
|
||||||
|
//move the item into the players inventory instead of the panel
|
||||||
|
if (plugin.openPanels.hasPanelOpen(p.getName(), PanelPosition.Middle) || plugin.openPanels.hasPanelOpen(p.getName(), PanelPosition.Bottom)) {
|
||||||
|
plugin.inventorySaver.addItem(p,e.getItem().getItemStack());
|
||||||
|
e.getItem().remove();
|
||||||
|
e.setCancelled(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -83,7 +83,7 @@ public class Updater implements Listener {
|
|||||||
public void run(){
|
public void run(){
|
||||||
HttpURLConnection connection;
|
HttpURLConnection connection;
|
||||||
try {
|
try {
|
||||||
connection = (HttpURLConnection) new URL("https://raw.githubusercontent.com/rockyhawk64/CommandPanels/master/resource/plugin.yml").openConnection();
|
connection = (HttpURLConnection) new URL("https://raw.githubusercontent.com/rockyhawk64/CommandPanels/latest/resource/plugin.yml").openConnection();
|
||||||
connection.setConnectTimeout(5000); // 5 seconds
|
connection.setConnectTimeout(5000); // 5 seconds
|
||||||
connection.setReadTimeout(5000); // 5 seconds
|
connection.setReadTimeout(5000); // 5 seconds
|
||||||
connection.connect();
|
connection.connect();
|
||||||
@ -130,13 +130,9 @@ public class Updater implements Listener {
|
|||||||
//return if auto-update is false
|
//return if auto-update is false
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if(Objects.equals(plugin.config.getString("updater.minor-updates-only"), "true")){
|
if(thisVersion.split("\\.")[1].equals(latestVersion.split("\\.")[1]) && thisVersion.split("\\.")[0].equals(latestVersion.split("\\.")[0])){
|
||||||
//only update versions that will not break
|
//only update if the latest version is a minor update
|
||||||
if(thisVersion.split("\\.")[1].equals(latestVersion.split("\\.")[1]) && thisVersion.split("\\.")[0].equals(latestVersion.split("\\.")[0])){
|
//the first and second number of the version is the same, updates: [major.major.minor.minor]
|
||||||
//the first and second number of the version is the same, updates: [major.major.minor.minor]
|
|
||||||
downloadFile(latestVersion,pluginFileName);
|
|
||||||
}
|
|
||||||
}else{
|
|
||||||
downloadFile(latestVersion,pluginFileName);
|
downloadFile(latestVersion,pluginFileName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user