Compare commits
No commits in common. "main" and "1.0-SNAPSHOT" have entirely different histories.
main
...
1.0-SNAPSH
127 changed files with 729 additions and 2578 deletions
|
|
@ -1,43 +0,0 @@
|
||||||
name: Build
|
|
||||||
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
paths:
|
|
||||||
- 'src/**'
|
|
||||||
- '.github/**'
|
|
||||||
- 'build.gradle.kts'
|
|
||||||
- 'gradle.properties'
|
|
||||||
- 'settings.gradle'
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
build:
|
|
||||||
runs-on: arch-linux
|
|
||||||
env:
|
|
||||||
NEMESIS_VERSION_NAME: "autobuild-${{ github.sha }}"
|
|
||||||
NEMESIS_BUILD_CHANNEL: "autobuild"
|
|
||||||
steps:
|
|
||||||
- name: Checkout
|
|
||||||
uses: actions/checkout@v6.0.1
|
|
||||||
|
|
||||||
- name: Setup Java enviroment
|
|
||||||
uses: actions/setup-java@v5.1.0
|
|
||||||
with:
|
|
||||||
distribution: temurin
|
|
||||||
java-version: 21
|
|
||||||
|
|
||||||
- name: Setup Gradle
|
|
||||||
uses: gradle/actions/setup-gradle@v5
|
|
||||||
|
|
||||||
- name: Download CB1060
|
|
||||||
run: |
|
|
||||||
mkdir -p libs
|
|
||||||
curl -L -o libs/craftbukkit-1060.jar https://archive.org/download/craftbukkit1060/craftbukkit1-7-3%281060%29.jar
|
|
||||||
|
|
||||||
- name: Build with Gradle
|
|
||||||
run: ./gradlew buildAll
|
|
||||||
|
|
||||||
|
|
||||||
- name: Upload artifacts
|
|
||||||
uses: actions/upload-artifact@v6.0.0
|
|
||||||
with:
|
|
||||||
path: build/libs/*.jar
|
|
||||||
|
|
@ -1,40 +0,0 @@
|
||||||
name: Release Build
|
|
||||||
|
|
||||||
on:
|
|
||||||
release:
|
|
||||||
types: [published]
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
build-and-release:
|
|
||||||
runs-on: arch-linux
|
|
||||||
env:
|
|
||||||
NEMESIS_VERSION_NAME: "${{ github.ref_name }}"
|
|
||||||
NEMESIS_BUILD_CHANNEL: "production"
|
|
||||||
steps:
|
|
||||||
- name: Checkout
|
|
||||||
uses: actions/checkout@v6.0.1
|
|
||||||
|
|
||||||
- name: Set up Java
|
|
||||||
uses: actions/setup-java@v5.1.0
|
|
||||||
with:
|
|
||||||
distribution: temurin
|
|
||||||
java-version: 21
|
|
||||||
|
|
||||||
- name: Set up Gradle
|
|
||||||
uses: gradle/actions/setup-gradle@v5
|
|
||||||
|
|
||||||
- name: Download CB1060
|
|
||||||
run: |
|
|
||||||
mkdir -p libs
|
|
||||||
curl -L -o libs/craftbukkit-1060.jar \
|
|
||||||
https://archive.org/download/craftbukkit1060/craftbukkit1-7-3%281060%29.jar
|
|
||||||
|
|
||||||
- name: Build with Gradle
|
|
||||||
run: ./gradlew buildAll
|
|
||||||
|
|
||||||
- name: Upload JARs to release
|
|
||||||
uses: softprops/action-gh-release@v2.5.0
|
|
||||||
with:
|
|
||||||
files: build/libs/*.jar
|
|
||||||
tag_name: ${{ github.ref_name }}
|
|
||||||
name: ${{ github.ref_name }}
|
|
||||||
15
.github/FUNDING.yml
vendored
15
.github/FUNDING.yml
vendored
|
|
@ -1,15 +0,0 @@
|
||||||
# These are supported funding model platforms
|
|
||||||
|
|
||||||
github: adrianvic
|
|
||||||
patreon: # Replace with a single Patreon username
|
|
||||||
open_collective: # Replace with a single Open Collective username
|
|
||||||
ko_fi: # Replace with a single Ko-fi username
|
|
||||||
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
|
|
||||||
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
|
|
||||||
liberapay: # Replace with a single Liberapay username
|
|
||||||
issuehunt: # Replace with a single IssueHunt username
|
|
||||||
lfx_crowdfunding: # Replace with a single LFX Crowdfunding project-name e.g., cloud-foundry
|
|
||||||
polar: # Replace with a single Polar username
|
|
||||||
buy_me_a_coffee: # Replace with a single Buy Me a Coffee username
|
|
||||||
thanks_dev: # Replace with a single thanks.dev username
|
|
||||||
custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
|
|
||||||
44
.github/workflows/build.yml
vendored
44
.github/workflows/build.yml
vendored
|
|
@ -1,44 +0,0 @@
|
||||||
name: Build
|
|
||||||
|
|
||||||
on:
|
|
||||||
workflow_dispatch:
|
|
||||||
push:
|
|
||||||
paths:
|
|
||||||
- 'src/**'
|
|
||||||
- '.github/**'
|
|
||||||
- 'build.gradle.kts'
|
|
||||||
- 'gradle.properties'
|
|
||||||
- 'settings.gradle'
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
build:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
env:
|
|
||||||
NEMESIS_VERSION_NAME: "autobuild-${{ github.sha }}"
|
|
||||||
NEMESIS_BUILD_CHANNEL: "autobuild"
|
|
||||||
steps:
|
|
||||||
- name: Checkout
|
|
||||||
uses: actions/checkout@v6.0.1
|
|
||||||
|
|
||||||
- name: Setup Java enviroment
|
|
||||||
uses: actions/setup-java@v5.1.0
|
|
||||||
with:
|
|
||||||
distribution: temurin
|
|
||||||
java-version: 21
|
|
||||||
|
|
||||||
- name: Setup Gradle
|
|
||||||
uses: gradle/actions/setup-gradle@v5
|
|
||||||
|
|
||||||
- name: Download CB1060
|
|
||||||
run: |
|
|
||||||
mkdir -p libs
|
|
||||||
curl -L -o libs/craftbukkit-1060.jar https://archive.org/download/craftbukkit1060/craftbukkit1-7-3%281060%29.jar
|
|
||||||
|
|
||||||
- name: Build with Gradle
|
|
||||||
run: ./gradlew buildAll
|
|
||||||
|
|
||||||
|
|
||||||
- name: Upload artifacts
|
|
||||||
uses: actions/upload-artifact@v3
|
|
||||||
with:
|
|
||||||
path: build/libs/*.jar
|
|
||||||
41
.github/workflows/release-build.yml
vendored
41
.github/workflows/release-build.yml
vendored
|
|
@ -1,41 +0,0 @@
|
||||||
name: Release Build
|
|
||||||
|
|
||||||
on:
|
|
||||||
release:
|
|
||||||
types: [published]
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
build-and-release:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
env:
|
|
||||||
NEMESIS_VERSION_NAME: "${{ github.ref_name }}"
|
|
||||||
NEMESIS_BUILD_CHANNEL: "production"
|
|
||||||
steps:
|
|
||||||
- name: Checkout
|
|
||||||
uses: actions/checkout@v6.0.1
|
|
||||||
|
|
||||||
- name: Set up Java
|
|
||||||
uses: actions/setup-java@v5.1.0
|
|
||||||
with:
|
|
||||||
distribution: temurin
|
|
||||||
java-version: 21
|
|
||||||
|
|
||||||
- name: Set up Gradle
|
|
||||||
uses: gradle/actions/setup-gradle@v5
|
|
||||||
|
|
||||||
- name: Download CB1060
|
|
||||||
run: |
|
|
||||||
mkdir -p libs
|
|
||||||
curl -L -o libs/craftbukkit-1060.jar \
|
|
||||||
https://archive.org/download/craftbukkit1060/craftbukkit1-7-3%281060%29.jar
|
|
||||||
|
|
||||||
- name: Build with Gradle
|
|
||||||
run: ./gradlew buildAll
|
|
||||||
|
|
||||||
- name: Upload artifacts to release
|
|
||||||
run: |
|
|
||||||
curl -X POST \
|
|
||||||
-H "Authorization: token ${{ secrets.FORGEJO_TOKEN }}" \
|
|
||||||
-H "Content-Type: application/octet-stream" \
|
|
||||||
https://inspiran.beetal-castor.ts.net/git/api/v1/repos/${{ github.repository }}/releases/tags/${{ github.ref_name }}/assets \
|
|
||||||
--data-binary @build/libs/your-artifact.jar
|
|
||||||
6
.gitignore
vendored
6
.gitignore
vendored
|
|
@ -1,6 +0,0 @@
|
||||||
.gradle/
|
|
||||||
build/
|
|
||||||
out/
|
|
||||||
.idea/
|
|
||||||
libs/
|
|
||||||
run/
|
|
||||||
BIN
.gradle/8.8/checksums/checksums.lock
Normal file
BIN
.gradle/8.8/checksums/checksums.lock
Normal file
Binary file not shown.
BIN
.gradle/8.8/checksums/md5-checksums.bin
Normal file
BIN
.gradle/8.8/checksums/md5-checksums.bin
Normal file
Binary file not shown.
BIN
.gradle/8.8/checksums/sha1-checksums.bin
Normal file
BIN
.gradle/8.8/checksums/sha1-checksums.bin
Normal file
Binary file not shown.
0
.gradle/8.8/dependencies-accessors/gc.properties
Normal file
0
.gradle/8.8/dependencies-accessors/gc.properties
Normal file
BIN
.gradle/8.8/executionHistory/executionHistory.bin
Normal file
BIN
.gradle/8.8/executionHistory/executionHistory.bin
Normal file
Binary file not shown.
BIN
.gradle/8.8/executionHistory/executionHistory.lock
Normal file
BIN
.gradle/8.8/executionHistory/executionHistory.lock
Normal file
Binary file not shown.
BIN
.gradle/8.8/fileChanges/last-build.bin
Normal file
BIN
.gradle/8.8/fileChanges/last-build.bin
Normal file
Binary file not shown.
BIN
.gradle/8.8/fileHashes/fileHashes.bin
Normal file
BIN
.gradle/8.8/fileHashes/fileHashes.bin
Normal file
Binary file not shown.
BIN
.gradle/8.8/fileHashes/fileHashes.lock
Normal file
BIN
.gradle/8.8/fileHashes/fileHashes.lock
Normal file
Binary file not shown.
BIN
.gradle/8.8/fileHashes/resourceHashesCache.bin
Normal file
BIN
.gradle/8.8/fileHashes/resourceHashesCache.bin
Normal file
Binary file not shown.
0
.gradle/8.8/gc.properties
Normal file
0
.gradle/8.8/gc.properties
Normal file
BIN
.gradle/buildOutputCleanup/buildOutputCleanup.lock
Normal file
BIN
.gradle/buildOutputCleanup/buildOutputCleanup.lock
Normal file
Binary file not shown.
2
.gradle/buildOutputCleanup/cache.properties
Normal file
2
.gradle/buildOutputCleanup/cache.properties
Normal file
|
|
@ -0,0 +1,2 @@
|
||||||
|
#Mon Dec 01 17:53:37 BRT 2025
|
||||||
|
gradle.version=8.8
|
||||||
BIN
.gradle/buildOutputCleanup/outputFiles.bin
Normal file
BIN
.gradle/buildOutputCleanup/outputFiles.bin
Normal file
Binary file not shown.
BIN
.gradle/file-system.probe
Normal file
BIN
.gradle/file-system.probe
Normal file
Binary file not shown.
0
.gradle/vcs-1/gc.properties
Normal file
0
.gradle/vcs-1/gc.properties
Normal file
3
.idea/.gitignore
generated
vendored
Normal file
3
.idea/.gitignore
generated
vendored
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
# Default ignored files
|
||||||
|
/shelf/
|
||||||
|
/workspace.xml
|
||||||
1
.idea/.name
generated
Normal file
1
.idea/.name
generated
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
regions
|
||||||
9
.idea/artifacts/regions_jar.xml
generated
Normal file
9
.idea/artifacts/regions_jar.xml
generated
Normal file
|
|
@ -0,0 +1,9 @@
|
||||||
|
<component name="ArtifactManager">
|
||||||
|
<artifact type="jar" name="regions:jar">
|
||||||
|
<output-path>$PROJECT_DIR$/../../testing/mcregions/plugins/</output-path>
|
||||||
|
<root id="archive" name="regions.jar">
|
||||||
|
<element id="module-output" name="regions.main" />
|
||||||
|
<element id="dir-copy" path="$PROJECT_DIR$/src/main/resources" />
|
||||||
|
</root>
|
||||||
|
</artifact>
|
||||||
|
</component>
|
||||||
6
.idea/compiler.xml
generated
Normal file
6
.idea/compiler.xml
generated
Normal file
|
|
@ -0,0 +1,6 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="CompilerConfiguration">
|
||||||
|
<bytecodeTargetLevel target="21" />
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
17
.idea/gradle.xml
generated
Normal file
17
.idea/gradle.xml
generated
Normal file
|
|
@ -0,0 +1,17 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="GradleMigrationSettings" migrationVersion="1" />
|
||||||
|
<component name="GradleSettings">
|
||||||
|
<option name="linkedExternalProjectsSettings">
|
||||||
|
<GradleProjectSettings>
|
||||||
|
<option name="externalProjectPath" value="$PROJECT_DIR$" />
|
||||||
|
<option name="gradleJvm" value="17" />
|
||||||
|
<option name="modules">
|
||||||
|
<set>
|
||||||
|
<option value="$PROJECT_DIR$" />
|
||||||
|
</set>
|
||||||
|
</option>
|
||||||
|
</GradleProjectSettings>
|
||||||
|
</option>
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
8
.idea/inspectionProfiles/Project_Default.xml
generated
Normal file
8
.idea/inspectionProfiles/Project_Default.xml
generated
Normal file
|
|
@ -0,0 +1,8 @@
|
||||||
|
<component name="InspectionProjectProfileManager">
|
||||||
|
<profile version="1.0">
|
||||||
|
<option name="myName" value="Project Default" />
|
||||||
|
<inspection_tool class="CommentedOutCode" enabled="true" level="WEAK WARNING" enabled_by_default="true">
|
||||||
|
<option name="minLines" value="3" />
|
||||||
|
</inspection_tool>
|
||||||
|
</profile>
|
||||||
|
</component>
|
||||||
9
.idea/mcregions.iml
generated
Normal file
9
.idea/mcregions.iml
generated
Normal file
|
|
@ -0,0 +1,9 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<module type="JAVA_MODULE" version="4">
|
||||||
|
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||||
|
<exclude-output />
|
||||||
|
<content url="file://$MODULE_DIR$" />
|
||||||
|
<orderEntry type="inheritedJdk" />
|
||||||
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
|
</component>
|
||||||
|
</module>
|
||||||
7
.idea/misc.xml
generated
Normal file
7
.idea/misc.xml
generated
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
||||||
|
<component name="ProjectRootManager" version="2" languageLevel="JDK_21" default="true" project-jdk-name="21" project-jdk-type="JavaSDK">
|
||||||
|
<output url="file://$PROJECT_DIR$/out" />
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
14
.idea/modules/regions.main.iml
generated
Normal file
14
.idea/modules/regions.main.iml
generated
Normal file
|
|
@ -0,0 +1,14 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<module version="4">
|
||||||
|
<component name="FacetManager">
|
||||||
|
<facet type="minecraft" name="Minecraft">
|
||||||
|
<configuration>
|
||||||
|
<autoDetectTypes>
|
||||||
|
<platformType>PAPER</platformType>
|
||||||
|
<platformType>ADVENTURE</platformType>
|
||||||
|
</autoDetectTypes>
|
||||||
|
<projectReimportVersion>1</projectReimportVersion>
|
||||||
|
</configuration>
|
||||||
|
</facet>
|
||||||
|
</component>
|
||||||
|
</module>
|
||||||
6
.idea/vcs.xml
generated
Normal file
6
.idea/vcs.xml
generated
Normal file
|
|
@ -0,0 +1,6 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="VcsDirectoryMappings">
|
||||||
|
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
24
README.md
24
README.md
|
|
@ -1,24 +1,4 @@
|
||||||
<img alt="eye_of_nemesis_social_cover" src="https://github.com/user-attachments/assets/a24bc92f-4dc2-4594-93c9-d056130f9695" />
|
|
||||||
|
|
||||||
[](https://modrinth.com/plugin/eye-of-nemesis)
|
|
||||||
[](https://github.com/adrianvic/NemesisEye/wiki)
|
|
||||||
[](https://mgr.rf.gd/w/Eye_of_Nemesis)
|
|
||||||
|
|
||||||
> [!IMPORTANT]
|
|
||||||
> This project is in an early stage, please report any bug you find.
|
|
||||||
|
|
||||||
# Eye of Nemesis
|
# Eye of Nemesis
|
||||||
Eye of Nemesis is a plugin that allows server admins to write policies that will deny or allow (black/whitelist) players to do specific things based on the value of nodes.
|
Eye of Nemesis is a Minecraft Paper plugin that allows server admins to write *policies* that will deny or allow (black/whitelist) players to do specific things.
|
||||||
|
|
||||||
## Motivations
|
You can create policies based on player location, ~but other types of policies are available, like permission and player-name policy.~ (WIP)
|
||||||
I made this plugin as an effort to preserve a village from my private server. Originally from beta 1.7.3 Betalands server, then transferred to RetroMC, and then finally we downloaded the chunks to merge into our server, I was afraid it would not have the same feeling after all the updates, so I had the idea to make a plugin that can block the newer features.
|
|
||||||
|
|
||||||
## Game version and loaders
|
|
||||||
Since version 1.0.3-SNAPSHOT, Eye of Nemesis has _reflection_, a technique that allows me to target multiple versions of the game while sharing the codebase across versions.
|
|
||||||
|
|
||||||
Currently, we support the following Minecraft versions/loaders:
|
|
||||||
- **PaperMC** `1.21, 1.21.1, 1.21.2, 1.21.3, 1.21.4, 1.21.5, 1.21.6, 1.21.7, 1.21.8, 1.21.9, 1.21.10`
|
|
||||||
- **Bukkit** `b1.7.3 (CB1060)`
|
|
||||||
|
|
||||||
## Performance
|
|
||||||
This plugin is not scalable as it is and will end up running unoptimized checks when your players do things with policies in effect, I made it for a server with a few friends. I'll look forward into writing more performant code after all my other priorities are implemented.
|
|
||||||
|
|
|
||||||
55
build.gradle
Normal file
55
build.gradle
Normal file
|
|
@ -0,0 +1,55 @@
|
||||||
|
plugins {
|
||||||
|
id 'java'
|
||||||
|
id("xyz.jpenilla.run-paper") version "2.3.1"
|
||||||
|
}
|
||||||
|
|
||||||
|
group = 'io.github.adrianvic'
|
||||||
|
version = '1.0-SNAPSHOT'
|
||||||
|
|
||||||
|
repositories {
|
||||||
|
mavenCentral()
|
||||||
|
maven {
|
||||||
|
name = "papermc-repo"
|
||||||
|
url = "https://repo.papermc.io/repository/maven-public/"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
compileOnly("io.papermc.paper:paper-api:1.21.10-R0.1-SNAPSHOT")
|
||||||
|
}
|
||||||
|
|
||||||
|
tasks {
|
||||||
|
runServer {
|
||||||
|
// Configure the Minecraft version for our task.
|
||||||
|
// This is the only required configuration besides applying the plugin.
|
||||||
|
// Your plugin's jar (or shadowJar if present) will be used automatically.
|
||||||
|
minecraftVersion("1.21")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
def targetJavaVersion = 21
|
||||||
|
java {
|
||||||
|
def javaVersion = JavaVersion.toVersion(targetJavaVersion)
|
||||||
|
sourceCompatibility = javaVersion
|
||||||
|
targetCompatibility = javaVersion
|
||||||
|
if (JavaVersion.current() < javaVersion) {
|
||||||
|
toolchain.languageVersion = JavaLanguageVersion.of(targetJavaVersion)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
tasks.withType(JavaCompile).configureEach {
|
||||||
|
options.encoding = 'UTF-8'
|
||||||
|
|
||||||
|
if (targetJavaVersion >= 10 || JavaVersion.current().isJava10Compatible()) {
|
||||||
|
options.release.set(targetJavaVersion)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
processResources {
|
||||||
|
def props = [version: version]
|
||||||
|
inputs.properties props
|
||||||
|
filteringCharset 'UTF-8'
|
||||||
|
filesMatching('plugin.yml') {
|
||||||
|
expand props
|
||||||
|
}
|
||||||
|
}
|
||||||
154
build.gradle.kts
154
build.gradle.kts
|
|
@ -1,154 +0,0 @@
|
||||||
plugins {
|
|
||||||
java
|
|
||||||
id("xyz.jpenilla.run-paper") version "2.3.1"
|
|
||||||
}
|
|
||||||
|
|
||||||
group = "io.github.adrianvic"
|
|
||||||
version = System.getenv("NEMESIS_VERSION_NAME") ?: "unknown"
|
|
||||||
|
|
||||||
repositories {
|
|
||||||
mavenCentral()
|
|
||||||
maven("https://repo.papermc.io/repository/maven-public/")
|
|
||||||
}
|
|
||||||
|
|
||||||
/* ----------------------------------------- */
|
|
||||||
/* SUPPORTED VERSIONS */
|
|
||||||
/* ----------------------------------------- */
|
|
||||||
|
|
||||||
val mcVersions = listOf(
|
|
||||||
"b1_7_3",
|
|
||||||
"r1_21"
|
|
||||||
)
|
|
||||||
|
|
||||||
/* ----------------------------------------- */
|
|
||||||
/* CREATE SOURCE SET PER VERSION */
|
|
||||||
/* ----------------------------------------- */
|
|
||||||
|
|
||||||
tasks.withType<ProcessResources> {
|
|
||||||
inputs.property("version", project.version)
|
|
||||||
|
|
||||||
filesMatching("plugin.yml") {
|
|
||||||
expand("version" to project.version)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
mcVersions.forEach { ver ->
|
|
||||||
val ss = sourceSets.create(ver) {
|
|
||||||
java.srcDir("src/$ver/java")
|
|
||||||
|
|
||||||
resources.setSrcDirs(listOf("src/$ver/resources", "src/main/resources"))
|
|
||||||
|
|
||||||
compileClasspath += sourceSets["main"].output
|
|
||||||
runtimeClasspath += output + compileClasspath
|
|
||||||
}
|
|
||||||
|
|
||||||
tasks.withType<ProcessResources> {
|
|
||||||
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
|
|
||||||
}
|
|
||||||
|
|
||||||
configurations[ss.implementationConfigurationName]
|
|
||||||
.extendsFrom(configurations["implementation"])
|
|
||||||
|
|
||||||
configurations[ss.compileOnlyConfigurationName]
|
|
||||||
.extendsFrom(configurations["compileOnly"])
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/* ----------------------------------------- */
|
|
||||||
/* DEPENDENCIES */
|
|
||||||
/* ----------------------------------------- */
|
|
||||||
|
|
||||||
dependencies {
|
|
||||||
add("compileOnly", "io.papermc.paper:paper-api:1.21-R0.1-SNAPSHOT")
|
|
||||||
add("r1_21CompileOnly", "io.papermc.paper:paper-api:1.21-R0.1-SNAPSHOT")
|
|
||||||
add("b1_7_3CompileOnly", files("libs/craftbukkit-1060.jar"))
|
|
||||||
|
|
||||||
testImplementation("org.junit.jupiter:junit-jupiter:5.10.0")
|
|
||||||
testImplementation("org.mockito:mockito-core:5.5.0")
|
|
||||||
testRuntimeOnly("org.junit.platform:junit-platform-launcher")
|
|
||||||
testImplementation("io.papermc.paper:paper-api:1.21-R0.1-SNAPSHOT")
|
|
||||||
testImplementation("com.github.seeseemelk:MockBukkit-v1.21:3.102.0")
|
|
||||||
|
|
||||||
// Allow tests to see the versioned implementations
|
|
||||||
mcVersions.forEach { ver ->
|
|
||||||
testImplementation(sourceSets[ver].output)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
tasks.test {
|
|
||||||
useJUnitPlatform()
|
|
||||||
}
|
|
||||||
|
|
||||||
/* ----------------------------------------- */
|
|
||||||
/* BUILD TASKS */
|
|
||||||
/* ----------------------------------------- */
|
|
||||||
|
|
||||||
mcVersions.forEach { ver ->
|
|
||||||
tasks.register<Jar>("jar${ver.replace(".", "_").replace("-", "_").replace("/", "_").capitalize()}") {
|
|
||||||
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
|
|
||||||
from(sourceSets["main"].output)
|
|
||||||
from(sourceSets[ver].output)
|
|
||||||
archiveClassifier.set(ver)
|
|
||||||
|
|
||||||
manifest {
|
|
||||||
attributes(
|
|
||||||
"Nemesis-Impl-Version" to ver,
|
|
||||||
"Nemesis-Environment" to (System.getenv("NEMESIS_BUILD_CHANNEL") ?: "dev")
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
tasks.register("buildAll") {
|
|
||||||
dependsOn(tasks.withType<Jar>())
|
|
||||||
}
|
|
||||||
|
|
||||||
tasks.register<Jar>("shadowJar") {
|
|
||||||
from(sourceSets["main"].output)
|
|
||||||
mcVersions.forEach { ver ->
|
|
||||||
from(sourceSets[ver].output)
|
|
||||||
}
|
|
||||||
|
|
||||||
// This is kinda gross and, essentially, we shouldn't have it here...
|
|
||||||
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
|
|
||||||
|
|
||||||
archiveClassifier.set("all-implementations")
|
|
||||||
archiveVersion.set(project.version.toString())
|
|
||||||
|
|
||||||
manifest {
|
|
||||||
attributes(
|
|
||||||
"Implemented-Versions" to mcVersions.joinToString(",")
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* ----------------------------------------- */
|
|
||||||
/* JAVA SETTINGS */
|
|
||||||
/* ----------------------------------------- */
|
|
||||||
|
|
||||||
java {
|
|
||||||
toolchain.languageVersion.set(JavaLanguageVersion.of(21))
|
|
||||||
}
|
|
||||||
|
|
||||||
tasks.withType<JavaCompile> {
|
|
||||||
options.encoding = "UTF-8"
|
|
||||||
}
|
|
||||||
|
|
||||||
tasks.runServer {
|
|
||||||
minecraftVersion("1.21")
|
|
||||||
downloadPlugins {
|
|
||||||
modrinth("viaversion", "5.7.0")
|
|
||||||
modrinth("luckperms", "v5.5.17-bukkit")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
tasks.register("runServerClean") {
|
|
||||||
doFirst {
|
|
||||||
exec {
|
|
||||||
commandLine("rm", "run/plugins/Eye-of-Nemesis/settings.yml")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
dependsOn("runServer")
|
|
||||||
}
|
|
||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
4
build/resources/main/plugin.yml
Normal file
4
build/resources/main/plugin.yml
Normal file
|
|
@ -0,0 +1,4 @@
|
||||||
|
name: regions
|
||||||
|
version: '1.0-SNAPSHOT'
|
||||||
|
main: io.github.adrianvic.regions.Regions
|
||||||
|
api-version: '1.21'
|
||||||
Binary file not shown.
Binary file not shown.
BIN
build/tmp/compileJava/previous-compilation-data.bin
Normal file
BIN
build/tmp/compileJava/previous-compilation-data.bin
Normal file
Binary file not shown.
|
|
@ -1,34 +0,0 @@
|
||||||
# Nodes
|
|
||||||
Nodes narrow down even further if an action can be done or not. A node needs _properties_ to know what it should check against, for example, a HIT node needs a _list_ of blocks that it will check if the player is holding; while a USE_ENCHANTMENT node needs a mapping of enchantment to level. Some nodes like glyde don't need a value and will ignore if you provide one.
|
|
||||||
```yaml
|
|
||||||
nodes:
|
|
||||||
- [HIT]:
|
|
||||||
values:
|
|
||||||
- 'GOLD_SWORD'
|
|
||||||
- [USE_ENCHANTMENT]:
|
|
||||||
values:
|
|
||||||
- "UNBREAKING": "1"
|
|
||||||
- [GLYDE]
|
|
||||||
```
|
|
||||||
|
|
||||||
## Available nodes
|
|
||||||
### INTERACT
|
|
||||||
Triggered on `InteractionEvent`, returns true when the provided `list` contains the material used to interact.
|
|
||||||
|
|
||||||
### HIT
|
|
||||||
Triggered on `EntityDamageByEntityEvent`, returns true when the provided `list` contains the material used to hit.
|
|
||||||
|
|
||||||
### PLACE
|
|
||||||
Triggered on `BlockPlaceEvent`, returns true when the provided `list` contains the material being placed.
|
|
||||||
|
|
||||||
### BREAK
|
|
||||||
Triggered on `BlockBreakEvent`, returns true when the provided `list` contains the material used to break.
|
|
||||||
|
|
||||||
### EQUIP
|
|
||||||
Triggered on `InventoryClickEvent` and `PlayerInteractEvent` (only if item is an armor), returns true when the provided `list` contains the material being equipped.
|
|
||||||
|
|
||||||
### GLYDE
|
|
||||||
Triggered on `PlayerMoveEvent`, returns true if player is gliding.
|
|
||||||
|
|
||||||
### USE_ENCHANTMENT
|
|
||||||
Triggered on `BlockBreakEvent` and `onEntityDamageByEntityEvent`, returns true the used item has an enchantment matching the provided mapping of enchantment-level.
|
|
||||||
|
|
@ -1,89 +0,0 @@
|
||||||
# Policies
|
|
||||||
Policies are a list of nodes with a specific condition to be met, they also determine what effect a node is going to have. Below is an example policy:
|
|
||||||
```yaml
|
|
||||||
- name: "Allow example"
|
|
||||||
type: "location"
|
|
||||||
effect: ALLOW
|
|
||||||
weight: 1
|
|
||||||
worlds: [world]
|
|
||||||
locations:
|
|
||||||
coordinates:
|
|
||||||
- corner1: { x: 2100, y: 256, z: 1400 }
|
|
||||||
corner2: { x: 1000, y: -64, z: 2200 }
|
|
||||||
nodes:
|
|
||||||
- [INTERACT, BREAK, HIT, PLACE]:
|
|
||||||
values:
|
|
||||||
- AIR
|
|
||||||
```
|
|
||||||
|
|
||||||
## Properties
|
|
||||||
### `name`
|
|
||||||
Name of the policy, must not contain spaces or else commands that require you to type the policy name will not work.
|
|
||||||
|
|
||||||
Example: `name: "disable-axe-damage"`
|
|
||||||
|
|
||||||
### `type`
|
|
||||||
One of the policy [types](#Types).
|
|
||||||
|
|
||||||
Example: `type: location`
|
|
||||||
|
|
||||||
### `effect`
|
|
||||||
Can be `deny` to block the action if a node check returns true, `ALLOW` to revert `DENY` effects if the node check is true or `ALLOWONLY` to allow the action **only** if the node check returns true.
|
|
||||||
|
|
||||||
Example: `effect: DENY`
|
|
||||||
|
|
||||||
### `weight`
|
|
||||||
A policy with greater weight will override a conflicting policy of lower weight.
|
|
||||||
|
|
||||||
Example: `weight: 0`
|
|
||||||
|
|
||||||
### `nodes`
|
|
||||||
Must contain a list of node mappings to evaluate if the policy applies to a player.
|
|
||||||
|
|
||||||
Example:
|
|
||||||
```yaml
|
|
||||||
nodes:
|
|
||||||
- [HIT]:
|
|
||||||
values:
|
|
||||||
- '.*_AXE$'
|
|
||||||
```
|
|
||||||
|
|
||||||
### `locations`
|
|
||||||
Only used for `type: "location"`, is a list of mappings where corner1 and corner2 should map x, y and z to two corners of a rectangular area where the policy will take effect; `worlds` may be defined here.
|
|
||||||
|
|
||||||
Example:
|
|
||||||
|
|
||||||
```yaml
|
|
||||||
locations:
|
|
||||||
worlds: [world]
|
|
||||||
coordinates:
|
|
||||||
- corner1: { x: 2100, y: 256, z: 1400 }
|
|
||||||
corner2: { x: 1000, y: -64, z: 2200 }
|
|
||||||
```
|
|
||||||
|
|
||||||
### `permissions`
|
|
||||||
Only used for `type: "permission"`, is a list of permissions.
|
|
||||||
|
|
||||||
Example:
|
|
||||||
|
|
||||||
```yaml
|
|
||||||
permissions:
|
|
||||||
- "server.axehit"
|
|
||||||
```
|
|
||||||
|
|
||||||
### `names`
|
|
||||||
Only used for `type: "playerName"`, is a list of player names.
|
|
||||||
|
|
||||||
## Types
|
|
||||||
|
|
||||||
### `global`
|
|
||||||
Always matches.
|
|
||||||
|
|
||||||
### `location`
|
|
||||||
Matches if the player location is inside any rectangle defined in the `locations` property.
|
|
||||||
|
|
||||||
### `playerName`
|
|
||||||
Matches if the player name is in the `names` property.
|
|
||||||
|
|
||||||
### `permission`
|
|
||||||
Matches if the player has a permission in the `permissions` property.
|
|
||||||
10
out/production/resources/plugin.yml
Normal file
10
out/production/resources/plugin.yml
Normal file
|
|
@ -0,0 +1,10 @@
|
||||||
|
name: "Eye-of-Nemesis"
|
||||||
|
version: '1.0-SNAPSHOT'
|
||||||
|
main: io.github.adrianvic.nemesiseye.Nemesis
|
||||||
|
api-version: '1.21'
|
||||||
|
author: 'Adrian Victor'
|
||||||
|
website: "https://github.io/adrianvic/NemesisEye"
|
||||||
|
description: "Change what players can do based in custom criteria."
|
||||||
|
commands:
|
||||||
|
eye:
|
||||||
|
usage: "/eye <option> (help for all available options)"
|
||||||
122
out/production/resources/settings.yml
Normal file
122
out/production/resources/settings.yml
Normal file
|
|
@ -0,0 +1,122 @@
|
||||||
|
Policies:
|
||||||
|
Location:
|
||||||
|
# NO SPACES
|
||||||
|
- name: "Beta-1.7.3-items-only"
|
||||||
|
# Will deny anything that's not allowed by the nodes if set to true
|
||||||
|
allowList: true
|
||||||
|
nodes:
|
||||||
|
- useItem:
|
||||||
|
- AIR
|
||||||
|
- STONE
|
||||||
|
- COBBLESTONE
|
||||||
|
- "^(OAK|SPRUCE|BIRCH)_(LOG|SAPLING|PLANKS|LEAVES)$"
|
||||||
|
- "^(DIAMOND|GOLD|IRON|COAL|LAPIS|REDSTONE)_ORE$"
|
||||||
|
- "^(DIAMOND|GOLD|IRON|LAPIS)_BLOCK$"
|
||||||
|
- GRAVEL
|
||||||
|
- BEDROCK
|
||||||
|
- SAND
|
||||||
|
- SPONGE
|
||||||
|
- WET_SPONGE
|
||||||
|
- GLASS
|
||||||
|
- LAPIS_LAZULI
|
||||||
|
- COBWEB
|
||||||
|
- PISTON
|
||||||
|
- STICKY_PISTON
|
||||||
|
- GRASS
|
||||||
|
- DISPENSER
|
||||||
|
- NOTE_BLOCK
|
||||||
|
- SANDSTONE
|
||||||
|
- RED_BED
|
||||||
|
- "^(POWERED|DETECTOR)_RAIL$"
|
||||||
|
- RAIL
|
||||||
|
- SHORT_GRASS
|
||||||
|
- "^(WHITE|BLACK|GREEN|YELLOW|PINK|PURPLE|CYAN|BLUE|RED|LIME|BROWN|LIGHT_GRAY|GRAY)_(WOOL|DYE)$"
|
||||||
|
- POPPY
|
||||||
|
- DANDELION
|
||||||
|
- "^(RED|BROWN)_MUSHROOM$"
|
||||||
|
- "^(OAK|COBBLESTONE)_SLAB$"
|
||||||
|
- BRICK_BLOCK
|
||||||
|
- TNT
|
||||||
|
- BOOKSHELF
|
||||||
|
- OBSIDIAN
|
||||||
|
- MOSSY_COBBLESTONE
|
||||||
|
- TORCH
|
||||||
|
- SPAWNER
|
||||||
|
- REDSTONE
|
||||||
|
- CHEST
|
||||||
|
- CRAFTING_TABLE
|
||||||
|
- FARMLAND
|
||||||
|
- FURNACE
|
||||||
|
- SIGN
|
||||||
|
- LADDER
|
||||||
|
- "^(COBBLESTONE|OAK)_STAIRS$"
|
||||||
|
- LEVER
|
||||||
|
- "^(OAK|STONE)_PRESSURE_PLATE$"
|
||||||
|
- "^(OAK|IRON)_DOOR$"
|
||||||
|
- BLUE_ICE
|
||||||
|
- REDSTONE_TORCH
|
||||||
|
- STONE_BUTTON
|
||||||
|
- SNOW
|
||||||
|
- SNOW_BLOCK
|
||||||
|
- CLAY
|
||||||
|
- SUGAR_CANE
|
||||||
|
- JUKEBOX
|
||||||
|
- OAK_FENCE
|
||||||
|
- PUMPKIN
|
||||||
|
- NETHERRACK
|
||||||
|
- SOUL_SAND
|
||||||
|
- GLOWSTONE
|
||||||
|
- JACK_O_LANTERN
|
||||||
|
- CAKE
|
||||||
|
- REPEATER
|
||||||
|
- OAK_TRAPDOOR
|
||||||
|
- "^(IRON|STONE|DIAMOND|WOODEN|GOLDEN)_(SHOVEL|AXE|PICKAXE|SWORD|HOE)$"
|
||||||
|
- "^(IRON|LEATHER|DIAMOND|GOLDEN)_(HELMET|CHESTPLATE|LEGGINGS|BOOTS)$"
|
||||||
|
- STICK
|
||||||
|
- BOWL
|
||||||
|
- MUSHROOM_STEW
|
||||||
|
- FEATHER
|
||||||
|
- STRING
|
||||||
|
- GUNPOWDER
|
||||||
|
- WHEAT_SEEDS
|
||||||
|
- WHEAT
|
||||||
|
- FLINT
|
||||||
|
- FLINT_AND_STEEL
|
||||||
|
- PORKCHOP
|
||||||
|
- "^(COOKED|RAW)_(PORKCHOP|FISH)$"
|
||||||
|
- PAINTING
|
||||||
|
- GOLDEN_APPLE
|
||||||
|
- BUCKET
|
||||||
|
- "^(LAVA|MILK|WATER)_BUCKET$"
|
||||||
|
- MINECART
|
||||||
|
- SADDLE
|
||||||
|
- SNOWBALL
|
||||||
|
- OAK_BOAT
|
||||||
|
- LEATHER
|
||||||
|
- "^(FURNACE|CHEST)_MINECART$"
|
||||||
|
- EGG
|
||||||
|
- BOOK
|
||||||
|
- PAPER
|
||||||
|
- BRICK
|
||||||
|
- SLIME_BALL
|
||||||
|
- COMPASS
|
||||||
|
- FISHING_ROD
|
||||||
|
- CLOCK
|
||||||
|
- GLOWSTONE_DUST
|
||||||
|
- INK_SAC
|
||||||
|
- BONE_MEAL
|
||||||
|
- SUGAR
|
||||||
|
- COOKIE
|
||||||
|
- MAP
|
||||||
|
- FILLED_MAP
|
||||||
|
- SHEARS
|
||||||
|
- MUSIC_DISK_CAT
|
||||||
|
- MUSIC_DISK_13
|
||||||
|
- DIRT
|
||||||
|
- BREAD
|
||||||
|
- useEnchantment:
|
||||||
|
"gibberish": 999999
|
||||||
|
locations:
|
||||||
|
-
|
||||||
|
- corner1: { x: 2100, y: 256, z: 1400 }
|
||||||
|
corner2: { x: 1000, y: -64, z: 2200 }
|
||||||
|
|
@ -1 +1 @@
|
||||||
rootProject.name = 'eyeofnemesis'
|
rootProject.name = 'regions'
|
||||||
|
|
|
||||||
|
|
@ -1,89 +0,0 @@
|
||||||
package io.github.adrianvic.nemesiseye.impl;
|
|
||||||
|
|
||||||
import io.github.adrianvic.nemesiseye.Nemesis;
|
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
|
||||||
import org.bukkit.util.config.Configuration;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.nio.file.Files;
|
|
||||||
|
|
||||||
public class ConfigurationEx extends Configuration {
|
|
||||||
private final File configFile;
|
|
||||||
private final Log logger;
|
|
||||||
JavaPlugin plugin;
|
|
||||||
|
|
||||||
public ConfigurationEx(String fileName, Log _logger) {
|
|
||||||
super(new File(Nemesis.getInstance().getDataFolder(), fileName));
|
|
||||||
this.plugin = Nemesis.getInstance();
|
|
||||||
logger = _logger;
|
|
||||||
this.configFile = new File(plugin.getDataFolder(), fileName);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void load() {
|
|
||||||
createParentDirectories();
|
|
||||||
|
|
||||||
if (!configFile.exists()) {
|
|
||||||
copyDefaultConfig();
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
super.load();
|
|
||||||
} catch (Exception e) {
|
|
||||||
logger.severe(String.format("Failed to load config '%s': %s", configFile.getName(), e.getMessage()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void createParentDirectories() {
|
|
||||||
try {
|
|
||||||
Files.createDirectories(configFile.getParentFile().toPath());
|
|
||||||
} catch (IOException e) {
|
|
||||||
logger.severe(String.format("Failed to generate default config directory: %s", e.getMessage()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void copyDefaultConfig() {
|
|
||||||
// Load the config from the JAR directly (it is located at the root level)
|
|
||||||
String resourcePath = "/" + configFile.getName(); // Root path of JAR
|
|
||||||
|
|
||||||
try (InputStream input = plugin.getClass().getResourceAsStream(resourcePath)) {
|
|
||||||
if (input == null) {
|
|
||||||
logger.severe(String.format("Default config '%s' wasn't found in the JAR.", configFile.getName()));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Files.copy(input, configFile.toPath());
|
|
||||||
if (Files.exists(configFile.toPath())) {
|
|
||||||
logger.info(String.format("Default config '%s' generated successfully.", configFile.getName()));
|
|
||||||
} else {
|
|
||||||
logger.warning("We tried to generate the default config file, but it was not found even after the creation. Maybe your permissions are broken?");
|
|
||||||
}
|
|
||||||
} catch (IOException e) {
|
|
||||||
logger.severe(String.format("Failed to generate default config '%s': %s", configFile.getName(), e.getMessage()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void loadConfig() {
|
|
||||||
try {
|
|
||||||
this.load();
|
|
||||||
logger.info(String.format("Config '%s' loaded successfully.", configFile.getName()));
|
|
||||||
} catch (Exception e) {
|
|
||||||
logger.severe(String.format("Failed to load config '%s': %s", configFile.getName(), e.getMessage()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void saveConfig() {
|
|
||||||
try {
|
|
||||||
this.save();
|
|
||||||
logger.info(String.format("Config '%s' saved successfully.", configFile.getName()));
|
|
||||||
} catch (Exception e) {
|
|
||||||
logger.severe(String.format("Failed to save config '%s': %s", configFile.getName(), e.getMessage()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public File getConfig() {
|
|
||||||
return configFile;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,41 +0,0 @@
|
||||||
package io.github.adrianvic.nemesiseye.impl;
|
|
||||||
|
|
||||||
import static org.bukkit.Bukkit.getServer;
|
|
||||||
|
|
||||||
import io.github.adrianvic.nemesiseye.Nemesis;
|
|
||||||
import org.bukkit.plugin.PluginDescriptionFile;
|
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
|
||||||
|
|
||||||
public class Log {
|
|
||||||
JavaPlugin plugin;
|
|
||||||
PluginDescriptionFile pdf;
|
|
||||||
|
|
||||||
public Log() {
|
|
||||||
plugin = Nemesis.getInstance();
|
|
||||||
pdf = plugin.getDescription();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void info(String message) {
|
|
||||||
getServer().getLogger().info("[" + pdf.getName() + "] " + message);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void infoc(String message) {
|
|
||||||
getServer().getLogger().info("[" + pdf.getName() + "] " + message);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void warning(String message) {
|
|
||||||
getServer().getLogger().warning("[" + pdf.getName() + "] " + message);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void warningc(String message) {
|
|
||||||
getServer().getLogger().warning("[" + pdf.getName() + "] " + message);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void severe(String message) {
|
|
||||||
getServer().getLogger().severe("[" + pdf.getName() + "] " + message);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void severec(String message) {
|
|
||||||
getServer().getLogger().severe("[" + pdf.getName() + "] " + message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,152 +0,0 @@
|
||||||
package io.github.adrianvic.nemesiseye.impl;
|
|
||||||
|
|
||||||
import io.github.adrianvic.nemesiseye.Nemesis;
|
|
||||||
import io.github.adrianvic.nemesiseye.impl.commands.Eye;
|
|
||||||
import io.github.adrianvic.nemesiseye.impl.events.BlockEventListener;
|
|
||||||
import io.github.adrianvic.nemesiseye.impl.events.EntityEventListener;
|
|
||||||
import io.github.adrianvic.nemesiseye.impl.events.PlayerEventListener;
|
|
||||||
import io.github.adrianvic.nemesiseye.policy.Policy;
|
|
||||||
import io.github.adrianvic.nemesiseye.policy.PolicyParsers;
|
|
||||||
import io.github.adrianvic.nemesiseye.reflection.Glimmer;
|
|
||||||
import org.bukkit.Material;
|
|
||||||
import org.bukkit.World;
|
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
import org.bukkit.entity.HumanEntity;
|
|
||||||
import org.bukkit.event.Event;
|
|
||||||
import org.bukkit.inventory.ItemStack;
|
|
||||||
import org.bukkit.plugin.PluginManager;
|
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
|
||||||
public class b1_7_3 implements Glimmer {
|
|
||||||
JavaPlugin plugin;
|
|
||||||
PluginManager pm;
|
|
||||||
ConfigurationEx config;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public File loadConfigFile() {
|
|
||||||
config = new ConfigurationEx("settings.yml", new Log());
|
|
||||||
config.load();
|
|
||||||
return config.getConfig();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<Policy> loadPoliciesFromFile(File file) {
|
|
||||||
List<?> rawPolicies = config.getList("Policies");
|
|
||||||
|
|
||||||
if (rawPolicies == null) {
|
|
||||||
return new ArrayList<>();
|
|
||||||
}
|
|
||||||
|
|
||||||
List<Map<?, ?>> result = new ArrayList<>(rawPolicies.size());
|
|
||||||
|
|
||||||
for (Object entry : rawPolicies) {
|
|
||||||
if (entry instanceof Map<?,?> m) {
|
|
||||||
result.add(m);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
List<Policy> allPolicies = new ArrayList<>();
|
|
||||||
for (Map<?, ?> policyMap : result) {
|
|
||||||
if (policyMap.get("type") != null && policyMap.get("type") instanceof String type) {
|
|
||||||
allPolicies.add(PolicyParsers.get(type).parse(policyMap));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return allPolicies;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onLoad() {
|
|
||||||
plugin = Nemesis.getInstance();
|
|
||||||
pm = Nemesis.getInstance().getPluginManager();
|
|
||||||
pm.registerEvent(Event.Type.ENTITY_DAMAGE, new EntityEventListener(), Event.Priority.Normal, plugin);
|
|
||||||
pm.registerEvent(Event.Type.BLOCK_BREAK, new BlockEventListener(), Event.Priority.Normal, plugin);
|
|
||||||
pm.registerEvent(Event.Type.PLAYER_INTERACT, new PlayerEventListener(), Event.Priority.Normal, plugin);
|
|
||||||
plugin.getCommand("eye").setExecutor(new Eye());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ItemStack getItemInMainHandHumanEntity(HumanEntity entity) {
|
|
||||||
return entity.getItemInHand();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isAir(ItemStack item) {
|
|
||||||
return item == null || item.getType() == Material.AIR;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isGliding(org.bukkit.entity.Player player) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setGliding(org.bukkit.entity.Player player, boolean gliding) {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean hasPermission(org.bukkit.command.CommandSender sender, String permission) {
|
|
||||||
if (sender instanceof org.bukkit.entity.Player p) {
|
|
||||||
return p.isOp();
|
|
||||||
}
|
|
||||||
return true; // Console always has permission
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isArmorEquipAttempt(org.bukkit.event.Event event) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ItemStack getEquippedItem(org.bukkit.event.Event event) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void sendMessage(CommandSender commandSender, String text) {
|
|
||||||
String[] lines = text.split("\\r?\\n");
|
|
||||||
for (String line : lines) {
|
|
||||||
commandSender.sendMessage(line);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean hasItemMeta(ItemStack item) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<World> getWorlds() {
|
|
||||||
return plugin.getServer().getWorlds();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean hasEnchantment(ItemStack item, Map<String, String> valuesmap) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean hasAnyEnchantment(ItemStack itemStack) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isArmor(ItemStack item) {
|
|
||||||
if (item == null || item.getType() == Material.AIR) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
String name = item.getType().name();
|
|
||||||
|
|
||||||
return name.endsWith("_HELMET")
|
|
||||||
|| name.endsWith("_CHESTPLATE")
|
|
||||||
|| name.endsWith("_LEGGINGS")
|
|
||||||
|| name.endsWith("_BOOTS");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,19 +0,0 @@
|
||||||
package io.github.adrianvic.nemesiseye.impl.commands;
|
|
||||||
|
|
||||||
import io.github.adrianvic.nemesiseye.commands.EyeCore;
|
|
||||||
import org.bukkit.command.Command;
|
|
||||||
import org.bukkit.command.CommandExecutor;
|
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
|
|
||||||
public class Eye implements CommandExecutor {
|
|
||||||
private final EyeCore core;
|
|
||||||
|
|
||||||
public Eye() {
|
|
||||||
core = new EyeCore();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean onCommand(CommandSender commandSender, Command command, String s, String [] strings) {
|
|
||||||
return core.onCommand(commandSender, command, s, strings);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,18 +0,0 @@
|
||||||
package io.github.adrianvic.nemesiseye.impl.events;
|
|
||||||
|
|
||||||
import io.github.adrianvic.nemesiseye.Events;
|
|
||||||
import org.bukkit.event.block.BlockBreakEvent;
|
|
||||||
import org.bukkit.event.block.BlockListener;
|
|
||||||
import org.bukkit.event.block.BlockPlaceEvent;
|
|
||||||
|
|
||||||
public class BlockEventListener extends BlockListener {
|
|
||||||
@Override
|
|
||||||
public void onBlockBreak(BlockBreakEvent event) {
|
|
||||||
Events.onBlockBreak(event);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onBlockPlace(BlockPlaceEvent event) {
|
|
||||||
Events.onBlockPlaceEvent(event);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,13 +0,0 @@
|
||||||
package io.github.adrianvic.nemesiseye.impl.events;
|
|
||||||
|
|
||||||
import io.github.adrianvic.nemesiseye.Events;
|
|
||||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
|
||||||
import org.bukkit.event.entity.EntityDamageEvent;
|
|
||||||
import org.bukkit.event.entity.EntityListener;
|
|
||||||
|
|
||||||
public class EntityEventListener extends EntityListener {
|
|
||||||
@Override
|
|
||||||
public void onEntityDamage(EntityDamageEvent event) {
|
|
||||||
if (event instanceof EntityDamageByEntityEvent e) Events.onEntityDamageByEntityEvent(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,13 +0,0 @@
|
||||||
package io.github.adrianvic.nemesiseye.impl.events;
|
|
||||||
|
|
||||||
import io.github.adrianvic.nemesiseye.Events;
|
|
||||||
import org.bukkit.event.player.PlayerInteractEvent;
|
|
||||||
import org.bukkit.event.player.PlayerListener;
|
|
||||||
|
|
||||||
public class PlayerEventListener extends PlayerListener {
|
|
||||||
@Override
|
|
||||||
public void onPlayerInteract(PlayerInteractEvent event) {
|
|
||||||
Events.onInteractionEvent(event);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
@ -1,45 +1,56 @@
|
||||||
package io.github.adrianvic.nemesiseye;
|
package io.github.adrianvic.nemesiseye;
|
||||||
|
|
||||||
import io.github.adrianvic.nemesiseye.policy.Policy;
|
import io.github.adrianvic.nemesiseye.policy.LocationPolicy;
|
||||||
import io.github.adrianvic.nemesiseye.policy.PolicyNode;
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
import io.github.adrianvic.nemesiseye.policy.policies.GlobalPolicy;
|
|
||||||
import io.github.adrianvic.nemesiseye.reflection.Glimmer;
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Comparator;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class Config {
|
public class Config {
|
||||||
private static Config instance = new Config();
|
private final static Config instance = new Config();
|
||||||
private final Glimmer glim = Nemesis.getInstance().getGlimmer();
|
|
||||||
private File file;
|
private File file;
|
||||||
private List<Policy> policies = new ArrayList<>();
|
private YamlConfiguration config;
|
||||||
|
|
||||||
private Config() {}
|
private List<LocationPolicy> locationPolicies;
|
||||||
|
// private List<PermissionPolicy> permissionPolicies;
|
||||||
|
// private List<PlayerNamePolicy> playerNamePolicies;
|
||||||
|
|
||||||
public void load() {
|
private Config() {
|
||||||
policies = glim.loadPoliciesFromFile(glim.loadConfigFile());
|
|
||||||
policies.sort(Comparator.comparingInt(Policy::weight).reversed());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Implement config saving
|
public void load() {
|
||||||
//
|
file = new File(Nemesis.getInstance().getDataFolder(), "settings.yml");
|
||||||
// public void save() {
|
|
||||||
// try {
|
|
||||||
// config.save(file);
|
|
||||||
// } catch (Exception e) {
|
|
||||||
// e.printStackTrace();
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// public void set(String path, Object value) {
|
|
||||||
// config.set(path, value);
|
|
||||||
// save();
|
|
||||||
// }
|
|
||||||
|
|
||||||
public List<Policy> getPolicies() {
|
if (!file.exists())
|
||||||
return policies;
|
Nemesis.getInstance().saveResource("settings.yml", false);
|
||||||
|
|
||||||
|
config = new YamlConfiguration();
|
||||||
|
config.options().parseComments(true);
|
||||||
|
|
||||||
|
try {
|
||||||
|
config.load(file);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
locationPolicies = LocationPolicy.parseLocationPolicy(config.getMapList("Policies.Location"));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void save() {
|
||||||
|
try {
|
||||||
|
config.save(file);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void set(String path, Object value) {
|
||||||
|
config.set(path, value);
|
||||||
|
save();
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<LocationPolicy> getLocationPolicies() {
|
||||||
|
return locationPolicies;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Config getInstance() {
|
public static Config getInstance() {
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,5 @@
|
||||||
package io.github.adrianvic.nemesiseye;
|
package io.github.adrianvic.nemesiseye;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
public class DataShifter {
|
public class DataShifter {
|
||||||
|
|
@ -12,52 +8,4 @@ public class DataShifter {
|
||||||
Pattern pattern = Pattern.compile(cleanPattern, Pattern.CASE_INSENSITIVE);
|
Pattern pattern = Pattern.compile(cleanPattern, Pattern.CASE_INSENSITIVE);
|
||||||
return pattern.matcher(against).matches();
|
return pattern.matcher(against).matches();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean safeMatches(List<String> expressions, String against) {
|
|
||||||
for (String s : expressions) {
|
|
||||||
if (DataShifter.safeMatches(s, against)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static List<String> parseValueToStringList(List<Object> values) {
|
|
||||||
List<String> result = new ArrayList<>();
|
|
||||||
for (Object o : values) {
|
|
||||||
if (o instanceof String) result.add((String) o);
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Map<String,String> parseValueToStringMap(List<Object> raw) {
|
|
||||||
Map<String,String> out = new HashMap<>();
|
|
||||||
|
|
||||||
for (Object o : raw) {
|
|
||||||
if (o instanceof Map<?,?> map) {
|
|
||||||
for (Map.Entry<?,?> e : map.entrySet()) {
|
|
||||||
out.put(String.valueOf(e.getKey()), String.valueOf(e.getValue()));
|
|
||||||
}
|
|
||||||
} else if (o instanceof String s) {
|
|
||||||
|
|
||||||
String[] parts = s.split(":", 2);
|
|
||||||
if (parts.length == 2) {
|
|
||||||
out.put(parts[0].trim(), parts[1].trim());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return out;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static <T extends Enum<T>> T enumOrDefault(Class<T> type, String string, T def) {
|
|
||||||
try {
|
|
||||||
return Enum.valueOf(type, string);
|
|
||||||
} catch (IllegalArgumentException e) {
|
|
||||||
return def;
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
return def;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,30 @@
|
||||||
|
package io.github.adrianvic.nemesiseye;
|
||||||
|
|
||||||
|
import org.bukkit.entity.HumanEntity;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.block.BlockBreakEvent;
|
||||||
|
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||||
|
import org.bukkit.event.player.PlayerInteractEvent;
|
||||||
|
|
||||||
|
public class EventListener implements Listener {
|
||||||
|
@EventHandler
|
||||||
|
public void onBlockBreak(BlockBreakEvent event) {
|
||||||
|
event.setCancelled(!Validator.canBreak(event.getPlayer()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onInteractionEvent(PlayerInteractEvent event) {
|
||||||
|
if (event.getItem() != null) {
|
||||||
|
event.setCancelled(!Validator.canInteract(event.getPlayer()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onEntityDamageByEntityEvent(EntityDamageByEntityEvent event) {
|
||||||
|
if (event.getDamager() instanceof Player) {
|
||||||
|
event.setCancelled(!Validator.canHit((HumanEntity) event.getDamager()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,98 +0,0 @@
|
||||||
package io.github.adrianvic.nemesiseye;
|
|
||||||
|
|
||||||
import io.github.adrianvic.nemesiseye.policy.Action;
|
|
||||||
import io.github.adrianvic.nemesiseye.reflection.Glimmer;
|
|
||||||
import org.bukkit.entity.HumanEntity;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.event.block.BlockBreakEvent;
|
|
||||||
import org.bukkit.event.block.BlockPlaceEvent;
|
|
||||||
import org.bukkit.event.entity.CreatureSpawnEvent;
|
|
||||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
|
||||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
|
||||||
import org.bukkit.event.player.PlayerInteractEvent;
|
|
||||||
import org.bukkit.event.player.PlayerMoveEvent;
|
|
||||||
import org.bukkit.inventory.ItemStack;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class Events {
|
|
||||||
|
|
||||||
private static Glimmer g() {
|
|
||||||
return Nemesis.getInstance().getGlimmer();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void onBlockBreak(BlockBreakEvent event) {
|
|
||||||
event.setCancelled(
|
|
||||||
!Validator.can(
|
|
||||||
event.getPlayer(),
|
|
||||||
List.of(Action.BREAK, Action.USE_ENCHANTMENT),
|
|
||||||
event
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void onInteractionEvent(PlayerInteractEvent event) {
|
|
||||||
ItemStack item = event.getItem();
|
|
||||||
|
|
||||||
if (g().isAir(item)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Right-click armor equipping
|
|
||||||
if (g().isArmor(item)
|
|
||||||
&& !Validator.can(event.getPlayer(), Action.EQUIP, event)) {
|
|
||||||
event.setCancelled(true);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Normal item interaction
|
|
||||||
event.setCancelled(
|
|
||||||
!Validator.can(event.getPlayer(), Action.INTERACT, event)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void onBlockPlaceEvent(BlockPlaceEvent event) {
|
|
||||||
event.setCancelled(
|
|
||||||
!Validator.can(event.getPlayer(), Action.PLACE, event)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void onEntityDamageByEntityEvent(EntityDamageByEntityEvent event) {
|
|
||||||
if (event.getDamager() instanceof Player player) {
|
|
||||||
event.setCancelled(
|
|
||||||
!Validator.can(
|
|
||||||
player,
|
|
||||||
List.of(Action.HIT, Action.USE_ENCHANTMENT),
|
|
||||||
event
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void onPlayerMoveEvent(PlayerMoveEvent event) {
|
|
||||||
if (g().isGliding(event.getPlayer())
|
|
||||||
&& !Validator.can(
|
|
||||||
event.getPlayer(),
|
|
||||||
List.of(Action.GLYDE),
|
|
||||||
event
|
|
||||||
)) {
|
|
||||||
g().setGliding(event.getPlayer(), false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void onInventoryClickEvent(InventoryClickEvent event) {
|
|
||||||
if (!g().isArmorEquipAttempt(event)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
HumanEntity entity = event.getWhoClicked();
|
|
||||||
|
|
||||||
if (!Validator.can(entity, Action.EQUIP, event)) {
|
|
||||||
event.setCancelled(true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void onCreatureSpawnEvent(CreatureSpawnEvent event) {
|
|
||||||
event.setCancelled(!Validator.can(event.getEntity(), Action.SPAWN, event));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,28 +1,23 @@
|
||||||
package io.github.adrianvic.nemesiseye;
|
package io.github.adrianvic.nemesiseye;
|
||||||
|
|
||||||
import io.github.adrianvic.nemesiseye.reflection.Glimmer;
|
import io.github.adrianvic.nemesiseye.commands.Eye;
|
||||||
import io.github.adrianvic.nemesiseye.reflection.VersionMatcher;
|
|
||||||
import org.bukkit.plugin.PluginManager;
|
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
public final class Nemesis extends JavaPlugin {
|
public final class Nemesis extends JavaPlugin {
|
||||||
private Glimmer glim;
|
|
||||||
private static final String VERSION_PROP = "impl.version";
|
|
||||||
private static Nemesis instance;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
instance = this;
|
getServer().getPluginManager().registerEvents(new EventListener(), this);
|
||||||
glim = new VersionMatcher().loadGlim();
|
|
||||||
glim.onLoad();
|
|
||||||
Config.getInstance().load();
|
Config.getInstance().load();
|
||||||
|
getCommand("eye").setExecutor(new Eye());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDisable() {
|
public void onDisable() {
|
||||||
|
// Plugin shutdown logic
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Nemesis getInstance() { return instance; }
|
public static Nemesis getInstance() {
|
||||||
public Glimmer getGlimmer() { return glim; }
|
return getPlugin(Nemesis.class);
|
||||||
public PluginManager getPluginManager() { return this.getServer().getPluginManager(); }
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1,55 +1,63 @@
|
||||||
package io.github.adrianvic.nemesiseye;
|
package io.github.adrianvic.nemesiseye;
|
||||||
|
|
||||||
import io.github.adrianvic.nemesiseye.policy.Action;
|
import io.github.adrianvic.nemesiseye.policy.Action;
|
||||||
import io.github.adrianvic.nemesiseye.policy.Policy;
|
import io.github.adrianvic.nemesiseye.policy.LocationPolicy;
|
||||||
|
import io.github.adrianvic.nemesiseye.policy.PolicyNode;
|
||||||
import org.bukkit.entity.HumanEntity;
|
import org.bukkit.entity.HumanEntity;
|
||||||
import org.bukkit.entity.LivingEntity;
|
import org.bukkit.util.BoundingBox;
|
||||||
import org.bukkit.event.Event;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class Validator {
|
public class Validator {
|
||||||
public static boolean can(HumanEntity entity, List<Action> actions, Event event) {
|
public static boolean canInteract(HumanEntity entity) {
|
||||||
for (Action action : actions) {
|
return checkAgainstEntity(entity, Action.INTERACT);
|
||||||
if (!can(entity, action, event)) {
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
public static boolean canBreak(HumanEntity entity) {
|
||||||
|
return checkAgainstEntity(entity, Action.BREAK);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean canHit(HumanEntity entity) {
|
||||||
|
return checkAgainstEntity(entity, Action.HIT);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean checkAgainstEntity(HumanEntity entity, Action action) {
|
||||||
|
return checkAgainstNodes(entity, getNodesForPolicies(getPoliciesForEntity(entity)), action);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean checkAgainstNodes(HumanEntity entity, List<PolicyNode> nodes, Action action) {
|
||||||
|
for (PolicyNode n : nodes) {
|
||||||
|
if (!checkAgainstNode(entity, n, action)) return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean can(LivingEntity entity, Action action, Event event) {
|
public static boolean checkAgainstNode(HumanEntity entity, PolicyNode node, Action action) {
|
||||||
boolean restricted = false;
|
boolean allowed = node.getHandler().allows(entity, node, action);
|
||||||
boolean allowed = false;
|
return node.isWhitelist() != allowed;
|
||||||
|
|
||||||
for (Policy policy : getPoliciesForEntity(entity)) {
|
|
||||||
boolean matches = policy.matches(entity, action, event);
|
|
||||||
|
|
||||||
switch (policy.effect()) {
|
|
||||||
case ALLOW:
|
|
||||||
if (matches) return true;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case DENY:
|
|
||||||
if (matches) return false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
public static List<PolicyNode> getNodesForPolicies(List<LocationPolicy> policies) {
|
||||||
|
List<PolicyNode> nodes = new ArrayList<>();
|
||||||
|
for (LocationPolicy p : policies) {
|
||||||
|
nodes.addAll(p.nodes());
|
||||||
|
}
|
||||||
|
return nodes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static List<LocationPolicy> getPoliciesForEntity(HumanEntity entity) {
|
||||||
public static List<Policy> getPoliciesForEntity(LivingEntity entity) {
|
List<LocationPolicy> lps = Config.getInstance().getLocationPolicies();
|
||||||
List<Policy> ps = Config.getInstance().getPolicies();
|
List<LocationPolicy> applyingLPS = new ArrayList<>();
|
||||||
List<Policy> result = new ArrayList<>();
|
for (LocationPolicy lp : lps) {
|
||||||
|
for (ArrayList<BoundingBox> boxes : lp.locations()) {
|
||||||
for (Policy policy : ps) {
|
for (BoundingBox box : boxes) {
|
||||||
if (policy.applies(entity)) result.add(policy);
|
if (box.contains(entity.getLocation().toVector())) {
|
||||||
|
applyingLPS.add(lp);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return result;
|
}
|
||||||
|
}
|
||||||
|
return applyingLPS;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,35 +0,0 @@
|
||||||
package io.github.adrianvic.nemesiseye.commands;
|
|
||||||
|
|
||||||
import io.github.adrianvic.nemesiseye.Nemesis;
|
|
||||||
import io.github.adrianvic.nemesiseye.commands.sub.*;
|
|
||||||
import io.github.adrianvic.nemesiseye.reflection.Glimmer;
|
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
public class Commands {
|
|
||||||
private static final Map<String, Subcommand> commands = new HashMap<>();
|
|
||||||
private static final Glimmer glim = Nemesis.getInstance().getGlimmer();
|
|
||||||
|
|
||||||
static {
|
|
||||||
commands.put("help", new Help());
|
|
||||||
commands.put("listpolicies", new ListPolicies());
|
|
||||||
commands.put("currentpolicies", new CurrentPolicies());
|
|
||||||
commands.put("policyinfo", new PolicyInfo());
|
|
||||||
commands.put("reload", new Reload());
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Map<String, Subcommand> getAll() {
|
|
||||||
return commands;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Subcommand get(String type) {
|
|
||||||
return commands.get(type);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void sendNoPermissionError(CommandSender sender) {
|
|
||||||
glim.sendMessage(sender, "You do not have the necessary permission to use this command.");
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -0,0 +1,59 @@
|
||||||
|
package io.github.adrianvic.nemesiseye.commands;
|
||||||
|
|
||||||
|
import io.github.adrianvic.nemesiseye.Nemesis;
|
||||||
|
import io.github.adrianvic.nemesiseye.commands.sub.*;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.command.Command;
|
||||||
|
import org.bukkit.command.CommandExecutor;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.command.TabCompleter;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
public class Eye implements CommandExecutor, TabCompleter {
|
||||||
|
private final Map<String, Subcommand> subs = new HashMap<>();
|
||||||
|
|
||||||
|
public Eye() {
|
||||||
|
register(new Reload());
|
||||||
|
register(new ListPolicies());
|
||||||
|
register(new PolicyInfo());
|
||||||
|
register(new CurrentPolicies());
|
||||||
|
}
|
||||||
|
|
||||||
|
private void register(Subcommand sub) {
|
||||||
|
subs.put(sub.name(), sub);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onCommand(@NotNull CommandSender commandSender, @NotNull Command command, @NotNull String s, @NotNull String @NotNull [] strings) {
|
||||||
|
if (strings.length == 0) {
|
||||||
|
commandSender.sendMessage("""
|
||||||
|
%sEye of Nemesis%s version %s
|
||||||
|
Usage: '/eye <command>'
|
||||||
|
Use '/eye help' for a list of available commands
|
||||||
|
""".formatted(ChatColor.RED, ChatColor.RESET, Nemesis.getInstance().getDescription().getVersion()));
|
||||||
|
} else {
|
||||||
|
Subcommand sub = subs.get(strings[0].toLowerCase());
|
||||||
|
if (sub == null) {
|
||||||
|
commandSender.sendMessage("Unknown command, try '/eye help' to list available commands.");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return sub.execute(commandSender, Arrays.copyOfRange(strings, 1, strings.length));
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @Nullable List<String> onTabComplete(@NotNull CommandSender commandSender, @NotNull Command command, @NotNull String s, @NotNull String @NotNull [] strings) {
|
||||||
|
if (strings.length == 1) {
|
||||||
|
return new ArrayList<>(subs.keySet());
|
||||||
|
}
|
||||||
|
Subcommand sub = subs.get(strings[0].toLowerCase());
|
||||||
|
if (sub != null) {
|
||||||
|
return sub.onTabComplete(commandSender, Arrays.copyOfRange(strings, 1, strings.length));
|
||||||
|
}
|
||||||
|
return List.of();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,57 +0,0 @@
|
||||||
package io.github.adrianvic.nemesiseye.commands;
|
|
||||||
|
|
||||||
import io.github.adrianvic.nemesiseye.Nemesis;
|
|
||||||
import io.github.adrianvic.nemesiseye.commands.sub.*;
|
|
||||||
import io.github.adrianvic.nemesiseye.reflection.Glimmer;
|
|
||||||
import org.bukkit.ChatColor;
|
|
||||||
import org.bukkit.command.Command;
|
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
import java.util.*;
|
|
||||||
|
|
||||||
public class EyeCore {
|
|
||||||
private final Glimmer glim = Nemesis.getInstance().getGlimmer();
|
|
||||||
|
|
||||||
public EyeCore() {}
|
|
||||||
|
|
||||||
public boolean onCommand(CommandSender commandSender, Command command, String s, String [] strings) {
|
|
||||||
if (strings.length == 0) {
|
|
||||||
glim.sendMessage(commandSender, """
|
|
||||||
%sEye of Nemesis%s version %s%s%s
|
|
||||||
Usage: '/eye <command>'
|
|
||||||
Use '/eye help' for a list of available commands
|
|
||||||
""".formatted(ChatColor.AQUA, ChatColor.WHITE, ChatColor.GRAY, Nemesis.getInstance().getDescription().getVersion(), ChatColor.WHITE));
|
|
||||||
} else {
|
|
||||||
Subcommand sub = Commands.get(strings[0].toLowerCase());
|
|
||||||
if (sub == null) {
|
|
||||||
commandSender.sendMessage("Unknown command, try '/eye help' to list available commands.");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
else if (glim.hasPermission(commandSender, sub.permission())) {
|
|
||||||
return sub.execute(commandSender, Arrays.copyOfRange(strings, 1, strings.length));
|
|
||||||
} else {
|
|
||||||
// Nemesis.getInstance().getLogger().info("does not have %s".formatted(sub.permission()));
|
|
||||||
Commands.sendNoPermissionError(commandSender);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<String> onTabComplete(CommandSender commandSender, Command command, String s, String [] strings) {
|
|
||||||
if (strings.length == 1) {
|
|
||||||
Map<String, Subcommand> cmds = new HashMap<>();
|
|
||||||
for (Map.Entry<String, Subcommand> e : Commands.getAll().entrySet()) {
|
|
||||||
if (glim.hasPermission(commandSender, e.getValue().permission())) {
|
|
||||||
cmds.put(e.getKey(), e.getValue());
|
|
||||||
cmds.put(e.getKey(), e.getValue());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return new ArrayList<>(cmds.keySet());
|
|
||||||
}
|
|
||||||
Subcommand sub = Commands.get(strings[0].toLowerCase());
|
|
||||||
if (sub != null && glim.hasPermission(commandSender, sub.permission())) {
|
|
||||||
return sub.onTabComplete(commandSender, Arrays.copyOfRange(strings, 1, strings.length));
|
|
||||||
}
|
|
||||||
return List.of();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
package io.github.adrianvic.nemesiseye.commands.sub;
|
package io.github.adrianvic.nemesiseye.commands.sub;
|
||||||
|
|
||||||
import io.github.adrianvic.nemesiseye.Validator;
|
import io.github.adrianvic.nemesiseye.Validator;
|
||||||
import io.github.adrianvic.nemesiseye.policy.Policy;
|
import io.github.adrianvic.nemesiseye.policy.LocationPolicy;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.HumanEntity;
|
import org.bukkit.entity.HumanEntity;
|
||||||
|
|
||||||
|
|
@ -9,11 +9,16 @@ import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class CurrentPolicies implements Subcommand {
|
public class CurrentPolicies implements Subcommand {
|
||||||
|
@Override
|
||||||
|
public String name() {
|
||||||
|
return "currentpolicies";
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean execute(CommandSender commandSender, String[] args) {
|
public boolean execute(CommandSender commandSender, String[] args) {
|
||||||
List<Policy> policies = Validator.getPoliciesForEntity((HumanEntity) commandSender);
|
List<LocationPolicy> policies = Validator.getPoliciesForEntity((HumanEntity) commandSender);
|
||||||
List<String> pstrings = new ArrayList<>();
|
List<String> pstrings = new ArrayList<>();
|
||||||
for (Policy p : policies) {
|
for (LocationPolicy p : policies) {
|
||||||
pstrings.add(" %s (%s nodes)".formatted(p.name(), p.nodes().size()));
|
pstrings.add(" %s (%s nodes)".formatted(p.name(), p.nodes().size()));
|
||||||
}
|
}
|
||||||
if (pstrings.isEmpty()) {
|
if (pstrings.isEmpty()) {
|
||||||
|
|
@ -29,19 +34,4 @@ public class CurrentPolicies implements Subcommand {
|
||||||
public List<String> onTabComplete(CommandSender sender, String[] args) {
|
public List<String> onTabComplete(CommandSender sender, String[] args) {
|
||||||
return List.of();
|
return List.of();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public String description() {
|
|
||||||
return "Lists policies appliying to you.";
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String usage() {
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String permission() {
|
|
||||||
return "nemsiseye.policies.list.self";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,54 +0,0 @@
|
||||||
package io.github.adrianvic.nemesiseye.commands.sub;
|
|
||||||
|
|
||||||
import io.github.adrianvic.nemesiseye.Nemesis;
|
|
||||||
import io.github.adrianvic.nemesiseye.commands.Commands;
|
|
||||||
import io.github.adrianvic.nemesiseye.reflection.Glimmer;
|
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
public class Help implements Subcommand {
|
|
||||||
private final Glimmer glim = Nemesis.getInstance().getGlimmer();
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean execute(CommandSender commandSender, String[] strings) {
|
|
||||||
List<String> rstr = new ArrayList<>();
|
|
||||||
Map<String, Subcommand> allSubcommands = Commands.getAll();
|
|
||||||
if (allSubcommands.isEmpty()) {
|
|
||||||
rstr.add("No commands found.");
|
|
||||||
}
|
|
||||||
for (Map.Entry<String, Subcommand> e : allSubcommands.entrySet()) {
|
|
||||||
if (e.getValue().hasPermission(commandSender)) {
|
|
||||||
rstr.add("""
|
|
||||||
%s - %s
|
|
||||||
Usage: /eye %s %s
|
|
||||||
""".formatted(e.getKey(), e.getValue().description(), e.getKey(), e.getValue().usage()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
glim.sendMessage(commandSender, String.join("\n", rstr));
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<String> onTabComplete(CommandSender sender, String[] strings) {
|
|
||||||
return List.of();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String description() {
|
|
||||||
return "Lists all commands.";
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String usage() {
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String permission() {
|
|
||||||
return "nemsiseye.help";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,17 +1,23 @@
|
||||||
package io.github.adrianvic.nemesiseye.commands.sub;
|
package io.github.adrianvic.nemesiseye.commands.sub;
|
||||||
|
|
||||||
import io.github.adrianvic.nemesiseye.Config;
|
import io.github.adrianvic.nemesiseye.Config;
|
||||||
import io.github.adrianvic.nemesiseye.policy.Policy;
|
import io.github.adrianvic.nemesiseye.policy.LocationPolicy;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class ListPolicies implements Subcommand {
|
public class ListPolicies implements Subcommand {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String name() {
|
||||||
|
return "listpolicies";
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean execute(CommandSender commandSender, String[] args) {
|
public boolean execute(CommandSender commandSender, String[] args) {
|
||||||
List<String> rstr = new ArrayList<>();
|
List<String> rstr = new ArrayList<>();
|
||||||
for (Policy p : Config.getInstance().getPolicies()) {
|
for (LocationPolicy p : Config.getInstance().getLocationPolicies()) {
|
||||||
rstr.add(p.name());
|
rstr.add(p.name());
|
||||||
}
|
}
|
||||||
commandSender.sendMessage(String.join(", ", rstr) + ".");
|
commandSender.sendMessage(String.join(", ", rstr) + ".");
|
||||||
|
|
@ -22,19 +28,4 @@ public class ListPolicies implements Subcommand {
|
||||||
public List<String> onTabComplete(CommandSender sender, String[] args) {
|
public List<String> onTabComplete(CommandSender sender, String[] args) {
|
||||||
return List.of();
|
return List.of();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public String description() {
|
|
||||||
return "Lists all loaded policies.";
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String usage() {
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String permission() {
|
|
||||||
return "nemsiseye.policy.list.all";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,7 @@
|
||||||
package io.github.adrianvic.nemesiseye.commands.sub;
|
package io.github.adrianvic.nemesiseye.commands.sub;
|
||||||
|
|
||||||
import io.github.adrianvic.nemesiseye.Config;
|
import io.github.adrianvic.nemesiseye.Config;
|
||||||
import io.github.adrianvic.nemesiseye.Nemesis;
|
import io.github.adrianvic.nemesiseye.policy.LocationPolicy;
|
||||||
import io.github.adrianvic.nemesiseye.policy.Policy;
|
|
||||||
import io.github.adrianvic.nemesiseye.reflection.Glimmer;
|
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
|
|
||||||
|
|
@ -11,18 +9,25 @@ import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class PolicyInfo implements Subcommand {
|
public class PolicyInfo implements Subcommand {
|
||||||
private final Glimmer glim = Nemesis.getInstance().getGlimmer();
|
@Override
|
||||||
|
public String name() {
|
||||||
|
return "policyinfo";
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean execute(CommandSender commandSender, String[] strings) {
|
public boolean execute(CommandSender commandSender, String[] strings) {
|
||||||
List<Policy> policies = Config.getInstance().getPolicies();
|
List<LocationPolicy> policies = Config.getInstance().getLocationPolicies();
|
||||||
for (Policy policy : policies) {
|
for (LocationPolicy lp : policies) {
|
||||||
if (policy.name().equals(strings[0])) {
|
if (lp.name().equals(strings[0])) {
|
||||||
glim.sendMessage(commandSender, String.format("""
|
String locations = lp.locations().toString();
|
||||||
Showing info for policy %s%s%s:
|
|
||||||
|
commandSender.sendMessage(String.format("""
|
||||||
|
Showing info for policy "%s%s%s":
|
||||||
Type: %s
|
Type: %s
|
||||||
|
Locations: %s
|
||||||
Nodes: %s
|
Nodes: %s
|
||||||
""", ChatColor.GREEN, policy.name(), ChatColor.WHITE, policy.getClass().getTypeName(), policy.nodes().size()));
|
%s
|
||||||
|
""", ChatColor.UNDERLINE, lp.name(), ChatColor.RESET, "location", locations, lp.nodes().size(), lp.allowlist() ? "Is allowlist" : "Is blacklist"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|
@ -31,24 +36,9 @@ public class PolicyInfo implements Subcommand {
|
||||||
@Override
|
@Override
|
||||||
public List<String> onTabComplete(CommandSender sender, String[] args) {
|
public List<String> onTabComplete(CommandSender sender, String[] args) {
|
||||||
List<String> rstr = new ArrayList<>();
|
List<String> rstr = new ArrayList<>();
|
||||||
for (Policy p : Config.getInstance().getPolicies()) {
|
for (LocationPolicy p : Config.getInstance().getLocationPolicies()) {
|
||||||
rstr.add(p.name());
|
rstr.add(p.name());
|
||||||
}
|
}
|
||||||
return rstr;
|
return rstr;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public String description() {
|
|
||||||
return "Shows info for a specified policy.";
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String usage() {
|
|
||||||
return "<policy>";
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String permission() {
|
|
||||||
return "nemsiseye.policy.info";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,12 @@
|
||||||
package io.github.adrianvic.nemesiseye.commands.sub;
|
package io.github.adrianvic.nemesiseye.commands.sub;
|
||||||
|
|
||||||
import io.github.adrianvic.nemesiseye.Config;
|
import io.github.adrianvic.nemesiseye.Config;
|
||||||
import io.github.adrianvic.nemesiseye.commands.Commands;
|
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class Reload implements Subcommand {
|
public class Reload implements Subcommand {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean execute(CommandSender commandSender, String [] strings) {
|
public boolean execute(CommandSender commandSender, String [] strings) {
|
||||||
Config.getInstance().load();
|
Config.getInstance().load();
|
||||||
|
|
@ -20,17 +20,7 @@ public class Reload implements Subcommand {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String permission() {
|
public String name() {
|
||||||
return "nemsiseye.reload";
|
return "reload";
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String description() {
|
|
||||||
return "Reloads the plugin configuration file.";
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String usage() {
|
|
||||||
return "";
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,19 +1,12 @@
|
||||||
package io.github.adrianvic.nemesiseye.commands.sub;
|
package io.github.adrianvic.nemesiseye.commands.sub;
|
||||||
|
|
||||||
import io.github.adrianvic.nemesiseye.Nemesis;
|
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.permissions.Permission;
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public interface Subcommand {
|
public interface Subcommand {
|
||||||
String description();
|
String name();
|
||||||
String usage();
|
|
||||||
@SuppressWarnings("SameReturnValue")
|
@SuppressWarnings("SameReturnValue")
|
||||||
boolean execute(CommandSender commandSender, String[] strings);
|
boolean execute(CommandSender commandSender, String[] strings);
|
||||||
List<String> onTabComplete(CommandSender sender, String[] strings);
|
List<String> onTabComplete(CommandSender sender, String[] strings);
|
||||||
String permission();
|
|
||||||
default boolean hasPermission(CommandSender sender) {
|
|
||||||
return Nemesis.getInstance().getGlimmer().hasPermission(sender, permission());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
@ -4,10 +4,6 @@ public enum Action {
|
||||||
INTERACT,
|
INTERACT,
|
||||||
BREAK,
|
BREAK,
|
||||||
HIT,
|
HIT,
|
||||||
// TODO CRAFT,
|
CRAFT,
|
||||||
EQUIP,
|
EQUIP
|
||||||
PLACE,
|
|
||||||
USE_ENCHANTMENT,
|
|
||||||
GLYDE,
|
|
||||||
SPAWN
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +0,0 @@
|
||||||
package io.github.adrianvic.nemesiseye.policy;
|
|
||||||
|
|
||||||
public enum Effect {
|
|
||||||
DENY,
|
|
||||||
ALLOW,
|
|
||||||
}
|
|
||||||
|
|
@ -0,0 +1,65 @@
|
||||||
|
package io.github.adrianvic.nemesiseye.policy;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.util.BoundingBox;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public record LocationPolicy(String name, List<ArrayList<BoundingBox>> locations, List<PolicyNode> nodes, boolean allowlist) {
|
||||||
|
public static List<LocationPolicy> parseLocationPolicy(List<Map<?,?>> raw) {
|
||||||
|
List<LocationPolicy> out = new ArrayList<>(raw.size());
|
||||||
|
for (Map<?,?> m : raw) {
|
||||||
|
String name = (String) m.get("name");
|
||||||
|
boolean allowlist = Boolean.TRUE.equals(m.get("allowList"));
|
||||||
|
|
||||||
|
// Nodes
|
||||||
|
Object rawNodes = m.get("nodes");
|
||||||
|
List<Map<String, Object>> nodeList = new ArrayList<>();
|
||||||
|
if (rawNodes instanceof List<?> list) {
|
||||||
|
for (Object o : list) {
|
||||||
|
if (o instanceof Map<?, ?> map)
|
||||||
|
nodeList.add((Map<String, Object>) map);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
List<PolicyNode> nodes = PolicyNode.parseNodes(nodeList, allowlist);
|
||||||
|
|
||||||
|
// Parsing locations
|
||||||
|
List<ArrayList<BoundingBox>> locations = new ArrayList<>();
|
||||||
|
Object rawGroups = m.get("locations");
|
||||||
|
List<?> groups = rawGroups instanceof List ? (List<?>) rawGroups : List.of();
|
||||||
|
|
||||||
|
// Getting groups
|
||||||
|
for (Object gObj : groups) {
|
||||||
|
List<?> group = (List<?>) gObj;
|
||||||
|
ArrayList<BoundingBox> boxes = new ArrayList<>(group.size());
|
||||||
|
|
||||||
|
// Now iterate over regions inside the group
|
||||||
|
for (Object rObj : group) {
|
||||||
|
Map<?,?> region = (Map<?, ?>) rObj;
|
||||||
|
Map<?,?> c1 = (Map<?, ?>) region.get("corner1");
|
||||||
|
Map<?,?> c2 = (Map<?, ?>) region.get("corner2");
|
||||||
|
|
||||||
|
double x1 = ((Number) c1.get("x")).doubleValue();
|
||||||
|
double y1 = ((Number) c1.get("y")).doubleValue();
|
||||||
|
double z1 = ((Number) c1.get("z")).doubleValue();
|
||||||
|
|
||||||
|
double x2 = ((Number) c2.get("x")).doubleValue();
|
||||||
|
double y2 = ((Number) c2.get("y")).doubleValue();
|
||||||
|
double z2 = ((Number) c2.get("z")).doubleValue();
|
||||||
|
|
||||||
|
Location loc1 = new Location(Bukkit.getWorlds().getFirst(), x1, y1, z1);
|
||||||
|
Location loc2 = new Location(Bukkit.getWorlds().getFirst(), x2, y2, z2);
|
||||||
|
|
||||||
|
boxes.add(BoundingBox.of(loc1, loc2));
|
||||||
|
}
|
||||||
|
locations.add(boxes);
|
||||||
|
}
|
||||||
|
out.add(new LocationPolicy(name, locations, nodes, allowlist));
|
||||||
|
}
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,9 +1,7 @@
|
||||||
package io.github.adrianvic.nemesiseye.policy;
|
package io.github.adrianvic.nemesiseye.policy;
|
||||||
|
|
||||||
import org.bukkit.entity.HumanEntity;
|
import org.bukkit.entity.HumanEntity;
|
||||||
import org.bukkit.entity.LivingEntity;
|
|
||||||
import org.bukkit.event.Event;
|
|
||||||
|
|
||||||
public interface NodeHandler {
|
public interface NodeHandler {
|
||||||
boolean check(LivingEntity entity, PolicyNode node, Action action, Event event);
|
boolean allows(HumanEntity entity, PolicyNode node, Action action);
|
||||||
}
|
}
|
||||||
|
|
@ -1,25 +1,22 @@
|
||||||
package io.github.adrianvic.nemesiseye.policy;
|
package io.github.adrianvic.nemesiseye.policy;
|
||||||
|
|
||||||
import io.github.adrianvic.nemesiseye.policy.handlers.*;
|
import io.github.adrianvic.nemesiseye.policy.handlers.attackWith;
|
||||||
|
import io.github.adrianvic.nemesiseye.policy.handlers.useEnchantment;
|
||||||
|
import io.github.adrianvic.nemesiseye.policy.handlers.useItem;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public class NodeHandlers {
|
public class NodeHandlers {
|
||||||
private static final Map<Action, NodeHandler> handlers = new HashMap<>();
|
private static final Map<String, NodeHandler> handlers = new HashMap<>();
|
||||||
|
|
||||||
static {
|
static {
|
||||||
handlers.put(Action.HIT, new UseItem());
|
handlers.put("attackWithItemInHand", new attackWith());
|
||||||
handlers.put(Action.PLACE, new BePlaced());
|
handlers.put("useItem", new useItem());
|
||||||
handlers.put(Action.INTERACT, new UseItem());
|
handlers.put("useEnchantment", new useEnchantment());
|
||||||
handlers.put(Action.USE_ENCHANTMENT, new UseEnchantment());
|
|
||||||
handlers.put(Action.GLYDE, new Glyde());
|
|
||||||
handlers.put(Action.EQUIP, new Equip());
|
|
||||||
handlers.put(Action.SPAWN, new Spawn());
|
|
||||||
handlers.put(Action.BREAK, new UseItem()); // TODO: implement place handler
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static NodeHandler get(Action type) {
|
public static NodeHandler get(String type) {
|
||||||
return handlers.get(type);
|
return handlers.get(type);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,28 @@
|
||||||
|
package io.github.adrianvic.nemesiseye.policy;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
public class NodeValueParser {
|
||||||
|
public static List<String> parseValueToStringList(List<Object> values) {
|
||||||
|
List<String> result = new ArrayList<>();
|
||||||
|
for (Object o : values) {
|
||||||
|
if (o instanceof String) result.add((String) o);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Map<String, String> parseValueToStringMap(List<Object> values) {
|
||||||
|
Map<String, String> result = new HashMap<>();
|
||||||
|
|
||||||
|
for (Object o : values) {
|
||||||
|
if (o instanceof Map<?, ?> raw) {
|
||||||
|
for (Map.Entry<?, ?> e : raw.entrySet()) {
|
||||||
|
if (e.getKey() instanceof String k && e.getValue() instanceof String v) {
|
||||||
|
result.put(k, v);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,7 @@
|
||||||
|
package io.github.adrianvic.nemesiseye.policy;
|
||||||
|
|
||||||
|
import org.bukkit.permissions.Permission;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
public record PermissionPolicy(String name, ArrayList<Permission> permissions, PolicyNode nodes, boolean allowlist) {}
|
||||||
|
|
@ -0,0 +1,5 @@
|
||||||
|
package io.github.adrianvic.nemesiseye.policy;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
public record PlayerNamePolicy(String name, ArrayList<String> playerName, PolicyNode nodes, boolean allowlist) {}
|
||||||
|
|
@ -1,35 +0,0 @@
|
||||||
package io.github.adrianvic.nemesiseye.policy;
|
|
||||||
|
|
||||||
import org.bukkit.entity.HumanEntity;
|
|
||||||
import org.bukkit.entity.LivingEntity;
|
|
||||||
import org.bukkit.event.Event;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public interface Policy {
|
|
||||||
String name();
|
|
||||||
List<PolicyNode> nodes();
|
|
||||||
boolean policyAllowList();
|
|
||||||
boolean applies(LivingEntity entity);
|
|
||||||
Effect effect();
|
|
||||||
int weight();
|
|
||||||
List<String> worlds();
|
|
||||||
|
|
||||||
default void addNode(PolicyNode node) {
|
|
||||||
nodes().add(node);
|
|
||||||
}
|
|
||||||
|
|
||||||
default boolean matches(LivingEntity entity, Action action, Event event) {
|
|
||||||
if (!worlds().contains(entity.getWorld().getName())) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (PolicyNode node : nodes()) {
|
|
||||||
if (node.matches(entity, action, event)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,73 +1,34 @@
|
||||||
package io.github.adrianvic.nemesiseye.policy;
|
package io.github.adrianvic.nemesiseye.policy;
|
||||||
|
|
||||||
import io.github.adrianvic.nemesiseye.DataShifter;
|
|
||||||
import org.bukkit.entity.HumanEntity;
|
|
||||||
import org.bukkit.entity.LivingEntity;
|
|
||||||
import org.bukkit.event.Event;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public record PolicyNode(List<Action> actions, List<Object> values) {
|
public record PolicyNode(String type, List<Object> values, boolean isWhitelist) {
|
||||||
public static List<PolicyNode> parseNodes(List<Map<Object,Object>> raw, Effect effect) {
|
public static List<PolicyNode> parseNodes(List<Map<String,Object>> raw, boolean isWhitelist) {
|
||||||
List<PolicyNode> nodes = new ArrayList<>();
|
List<PolicyNode> nodes = new ArrayList<>();
|
||||||
|
|
||||||
for (Map<Object, Object> m : raw) {
|
for (Map<String, Object> m : raw) {
|
||||||
for (Map.Entry<Object, Object> rawNode : m.entrySet()) {
|
for (Map.Entry<String, Object> entry : m.entrySet()) {
|
||||||
List<Action> nodeActions = new ArrayList<>();
|
String type = entry.getKey();
|
||||||
List<Object> nodeValues = new ArrayList<>();
|
List<Object> values = new ArrayList<>();
|
||||||
|
Object val = entry.getValue();
|
||||||
|
|
||||||
if (rawNode.getKey() instanceof List<?> rawTypes && rawNode.getValue() instanceof Map<?,?> rawNodeValues) {
|
if (val instanceof String s) {
|
||||||
for (Object rawType : rawTypes) {
|
values.add(s);
|
||||||
if (rawType instanceof String rts && !rts.isEmpty() && !(rts == null) && DataShifter.enumOrDefault(Action.class, rts, null) != null) {
|
} else if (val instanceof List<?> l) {
|
||||||
nodeActions.add(DataShifter.enumOrDefault(Action.class, rts, null));
|
values.addAll(l);
|
||||||
}
|
} else if (val instanceof Map<?,?> map) {
|
||||||
}
|
values.add(map);
|
||||||
Map<String, Object> semiParsedNodeValue = new HashMap<>();
|
|
||||||
for (Map.Entry<?,?> rawNodeValueEntries : rawNodeValues.entrySet()) {
|
|
||||||
if (rawNodeValueEntries.getKey() instanceof String stringKey) {
|
|
||||||
semiParsedNodeValue.put(stringKey, rawNodeValueEntries.getValue());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (semiParsedNodeValue.get("values") instanceof List<?> l) {
|
nodes.add(new PolicyNode(type, values, isWhitelist));
|
||||||
for (Object v : l) {
|
|
||||||
nodeValues.add(v);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!nodeActions.isEmpty() && !nodeValues.isEmpty()) {
|
|
||||||
PolicyNode newNode = new PolicyNode(nodeActions, nodeValues);
|
|
||||||
nodes.add(newNode);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nodes;
|
return nodes;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<NodeHandler> getHandler() {
|
public NodeHandler getHandler() {
|
||||||
List<NodeHandler> handlers = new ArrayList<>();
|
return NodeHandlers.get(type);
|
||||||
for (Action a : actions) {
|
|
||||||
handlers.add(NodeHandlers.get(a));
|
|
||||||
}
|
|
||||||
return handlers;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean matches(LivingEntity entity, Action action, Event event) {
|
|
||||||
if (!actions.contains(action)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
NodeHandler handler = NodeHandlers.get(action);
|
|
||||||
|
|
||||||
if (handler == null) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean result = handler.check(entity, this, action, event);
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1,47 +0,0 @@
|
||||||
package io.github.adrianvic.nemesiseye.policy;
|
|
||||||
|
|
||||||
import io.github.adrianvic.nemesiseye.DataShifter;
|
|
||||||
import io.github.adrianvic.nemesiseye.policy.policies.Core;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
public interface PolicyParser {
|
|
||||||
default Policy parse(Map<?, ?> raw) {
|
|
||||||
boolean policyAllowList = Boolean.TRUE.equals(raw.get("policyAllowList"));
|
|
||||||
boolean nodesAllowList = Boolean.TRUE.equals(raw.get("nodesAllowList"));
|
|
||||||
Effect effect = DataShifter.enumOrDefault(Effect.class, (String) raw.get("effect"), Effect.DENY);
|
|
||||||
String name = (String) raw.get("name");
|
|
||||||
Integer weightObj = (Integer) raw.get("weight");
|
|
||||||
int weight = weightObj != null ? weightObj : 0;
|
|
||||||
|
|
||||||
// Worlds
|
|
||||||
List<String> worlds = new ArrayList<>();
|
|
||||||
if (raw.get("worlds") instanceof List<?> list) {
|
|
||||||
for (Object object : list) {
|
|
||||||
if (object instanceof String result) {
|
|
||||||
worlds.add(result);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
worlds.add("world");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Nodes
|
|
||||||
Object rawNodes = raw.get("nodes");
|
|
||||||
List<Map<Object, Object>> nodeList = new ArrayList<>();
|
|
||||||
|
|
||||||
if (rawNodes instanceof List<?> list) {
|
|
||||||
for (Object o : list) {
|
|
||||||
if (o instanceof Map<?, ?> map)
|
|
||||||
nodeList.add((Map<Object, Object>) map);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
List<PolicyNode> nodes = PolicyNode.parseNodes(nodeList, effect);
|
|
||||||
return parse(new Core(name, worlds, nodes, nodesAllowList, policyAllowList, effect, weight), raw);
|
|
||||||
}
|
|
||||||
|
|
||||||
Policy parse(Core corePolicy, Map<?, ?> raw);
|
|
||||||
}
|
|
||||||
|
|
@ -1,24 +0,0 @@
|
||||||
package io.github.adrianvic.nemesiseye.policy;
|
|
||||||
|
|
||||||
import io.github.adrianvic.nemesiseye.policy.parser.GlobalPolicyParser;
|
|
||||||
import io.github.adrianvic.nemesiseye.policy.parser.LocationPolicyParser;
|
|
||||||
import io.github.adrianvic.nemesiseye.policy.parser.PermissionPolicyParser;
|
|
||||||
import io.github.adrianvic.nemesiseye.policy.parser.PlayerNamePolicyParser;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
public class PolicyParsers {
|
|
||||||
private static final Map<String, PolicyParser> handlers = new HashMap<>();
|
|
||||||
|
|
||||||
static {
|
|
||||||
handlers.put("location", new LocationPolicyParser());
|
|
||||||
handlers.put("global", new GlobalPolicyParser());
|
|
||||||
handlers.put("playerName", new PlayerNamePolicyParser());
|
|
||||||
handlers.put("permission", new PermissionPolicyParser());
|
|
||||||
}
|
|
||||||
|
|
||||||
public static PolicyParser get(String type) {
|
|
||||||
return handlers.get(type);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue