diff --git a/.gitignore b/.gitignore
index 2508ba5..7a712cf 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,62 +1,139 @@
-# Created by .ignore support plugin (hsz.mobi)
-### Gradle template
-.gradle
-/build/
-
-# Ignore Gradle GUI config
-gradle-app.setting
-
-# Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored)
-!gradle-wrapper.jar
-
-# Cache of project
-.gradletasknamecache
-
-# # Work around https://youtrack.jetbrains.com/issue/IDEA-116898
-# gradle/wrapper/gradle-wrapper.properties
-### JetBrains template
-# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm
-# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
-
-# User-specific stuff:
-.idea/workspace.xml
-.idea/tasks.xml
-
-# Sensitive or high-churn files:
-.idea/dataSources/
-.idea/dataSources.ids
-.idea/dataSources.xml
-.idea/dataSources.local.xml
-.idea/sqlDataSources.xml
-.idea/dynamic.xml
-.idea/uiDesigner.xml
-
-# Gradle:
-.idea/gradle.xml
-.idea/libraries
-
-# Mongo Explorer plugin:
-.idea/mongoSettings.xml
-
-## File-based project format:
-*.iws
-
-## Plugin-specific files:
-
-# IntelliJ
-/out/
-
-# mpeltonen/sbt-idea plugin
-.idea_modules/
-
-# JIRA plugin
-atlassian-ide-plugin.xml
-
-# Crashlytics plugin (for Android Studio and IntelliJ)
-com_crashlytics_export_strings.xml
-crashlytics.properties
-crashlytics-build.properties
-fabric.properties
-/unsed/
-run/forge/
-run/vanilla/
+### JetBrains template
+# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
+# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
+
+# User-specific stuff
+.idea/**/workspace.xml
+.idea/**/tasks.xml
+.idea/**/usage.statistics.xml
+.idea/**/dictionaries
+.idea/**/shelf
+
+# Generated files
+.idea/**/contentModel.xml
+
+# Sensitive or high-churn files
+.idea/**/dataSources/
+.idea/**/dataSources.ids
+.idea/**/dataSources.local.xml
+.idea/**/sqlDataSources.xml
+.idea/**/dynamic.xml
+.idea/**/uiDesigner.xml
+.idea/**/dbnavigator.xml
+
+# Gradle
+.idea/**/gradle.xml
+.idea/**/libraries
+
+# Gradle and Maven with auto-import
+# When using Gradle or Maven with auto-import, you should exclude module files,
+# since they will be recreated, and may cause churn. Uncomment if using
+# auto-import.
+# .idea/artifacts
+# .idea/compiler.xml
+# .idea/jarRepositories.xml
+# .idea/modules.xml
+# .idea/*.iml
+# .idea/modules
+# *.iml
+# *.ipr
+
+# CMake
+cmake-build-*/
+
+# Mongo Explorer plugin
+.idea/**/mongoSettings.xml
+
+# File-based project format
+*.iws
+
+# IntelliJ
+out/
+
+# mpeltonen/sbt-idea plugin
+.idea_modules/
+
+# JIRA plugin
+atlassian-ide-plugin.xml
+
+# Cursive Clojure plugin
+.idea/replstate.xml
+
+# Crashlytics plugin (for Android Studio and IntelliJ)
+com_crashlytics_export_strings.xml
+crashlytics.properties
+crashlytics-build.properties
+fabric.properties
+
+# Editor-based Rest Client
+.idea/httpRequests
+
+# Android studio 3.1+ serialized cache file
+.idea/caches/build_file_checksums.ser
+
+### Java template
+# Compiled class file
+*.class
+
+# Log file
+*.log
+
+# BlueJ files
+*.ctxt
+
+# Mobile Tools for Java (J2ME)
+.mtj.tmp/
+
+# Package Files #
+*.jar
+*.war
+*.nar
+*.ear
+*.zip
+*.tar.gz
+*.rar
+
+# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
+hs_err_pid*
+
+### Gradle template
+.gradle
+**/build/
+!src/**/build/
+
+# Ignore Gradle GUI config
+gradle-app.setting
+
+# Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored)
+!gradle-wrapper.jar
+
+# Cache of project
+.gradletasknamecache
+
+# # Work around https://youtrack.jetbrains.com/issue/IDEA-116898
+# gradle/wrapper/gradle-wrapper.properties
+
+### Example user template template
+### Example user template
+
+# IntelliJ project files
+.idea
+*.iml
+out
+gen
+### Maven template
+target/
+pom.xml.tag
+pom.xml.releaseBackup
+pom.xml.versionsBackup
+pom.xml.next
+release.properties
+dependency-reduced-pom.xml
+buildNumber.properties
+.mvn/timing.properties
+# https://github.com/takari/maven-wrapper#usage-without-binary-jar
+.mvn/wrapper/maven-wrapper.jar
+/unsed/
+run/forge/
+run/vanilla/
+
diff --git a/HEADER.txt b/HEADER.txt
new file mode 100644
index 0000000..cb59650
--- /dev/null
+++ b/HEADER.txt
@@ -0,0 +1,17 @@
+ This file is part of ${name}.
+
+ ${name} is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ ${name} is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with ${name}. If not, see .
+
+ Copyright (c) ${organization} <${url}>
+ Copyright (c) contributors
\ No newline at end of file
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..d231faf
--- /dev/null
+++ b/README.md
@@ -0,0 +1,35 @@
+# NyxBackpack
+A simple backpack plugin.
+
+----------
+
+**This plugin uses bStats I would really appreciate it if you guys allow data collection by running `/sponge metrics NyxBackpack enable`**
+
+## Migrating from VirtualTool
+Copy files in `/config/virtualtool/backpacks` to `/config/Nyx/NyxBackpack/backpacks/`
+
+## Dependencies / Requirements
+NyxCore https://poqdavid.github.io/NyxCore/
+
+## Commands
+ /backpack, /bp [[]] [] [-m ]
+ /backpacklock, /bplock [-l ] [-u ]
+
+## Premissions
+ NyxCore.Backpack.Command.Main
+ NyxCore.Backpack.Command.Help
+ NyxCore.Backpack.Command.BackpackLock
+ NyxCore.Backpack.Command.BackpackAdminRead
+ NyxCore.Backpack.Command.BackpackAdminModify
+ NyxCore.Backpack.Command.BackpackSize.One
+ NyxCore.Backpack.Command.BackpackSize.Two
+ NyxCore.Backpack.Command.BackpackSize.Three
+ NyxCore.Backpack.Command.BackpackSize.Four
+ NyxCore.Backpack.Command.BackpackSize.Five
+ NyxCore.Backpack.Command.BackpackSize.Six
+
+**Donate:**
+
**BTC Legacy:** 1Q2JQG3iCLZPT2iJfDLow1oQVGKmxheoAh
+
**BTC Segwit:** bc1q8gurls0wjkfe43ygmrqmu2pzmyjetnrvgws9sr
+
**BCH:** qrks52smlqw7d8700d77uqvmve03d4knzvd2vghaqz
+
**ETH:** 0x7218779242a8425879B09969431c20F5eC1a192D
\ No newline at end of file
diff --git a/build.gradle b/build.gradle
new file mode 100644
index 0000000..81381ee
--- /dev/null
+++ b/build.gradle
@@ -0,0 +1,221 @@
+buildscript {
+ repositories {
+ mavenCentral()
+ maven {
+ name = "forge"
+ url = "https://files.minecraftforge.net/maven"
+ }
+ maven {
+ name = "oss-sonatype-public"
+ url = "https://oss.sonatype.org/content/repositories/public/"
+ }
+ maven {
+ name = "Sponge"
+ url = "https://repo.spongepowered.org/maven"
+ }
+ maven {
+ name = "Gradle-Plugins"
+ url = "https://plugins.gradle.org/m2/"
+ }
+ }
+ dependencies {
+ classpath group: 'net.minecraftforge.gradle', name: 'ForgeGradle', version: '4.+', changing: true
+
+ //classpath group: 'com.github.jengelman.gradle.plugins', name: 'shadow', version: '2.0.2'
+ classpath group: 'com.github.jengelman.gradle.plugins', name: 'shadow', version: '6.+' //Gradle 6
+
+ classpath 'org.spongepowered:mixingradle:0.7-SNAPSHOT'
+ classpath "org.spongepowered:SpongeGradle:0.11.5"
+ classpath "gradle.plugin.net.minecrell:licenser:0.4.1"
+ }
+}
+
+plugins {
+ id "groovy"
+ id "java"
+ id "idea"
+ id "signing"
+}
+
+apply plugin: 'net.minecraftforge.gradle'
+apply plugin: 'com.github.johnrengelman.shadow'
+apply plugin: 'net.minecrell.licenser'
+apply plugin: 'org.spongepowered.mixin'
+apply plugin: 'org.spongepowered.gradle.plugin'
+
+group = "${getProjectProperty('m_group')}" as Object
+version = "${getProjectProperty('minecraft_version')}-${getProjectProperty('m_major')}.${getProjectProperty('m_minor')}-${getProjectProperty('m_api')}-${getProjectProperty('m_suffix')}" as Object
+description = "${getProjectProperty('m_description')}"
+
+if (System.getenv().BUILD_NUMBER != null) {
+ version += "+${System.getenv().BUILD_NUMBER}"
+}
+
+minecraft {
+ mappings channel: getProjectProperty('mappings_channel'), version: getProjectProperty('mappings_version')
+}
+
+mixin {
+ defaultObfuscationEnv "notch"
+}
+
+sourceSets {
+ main {
+ ext.refMap = "mixins.${project.name.toLowerCase()}.refmap.json"
+ }
+}
+
+mixin {
+ add sourceSets.main, "mixins.${project.name.toLowerCase()}.refmap.json"
+}
+
+repositories {
+ mavenLocal()
+ mavenCentral()
+ maven {
+ name = "Gradle-Plugins"
+ url = "https://plugins.gradle.org/m2"
+ }
+ maven {
+ name = "Sponge"
+ url = "https://repo.spongepowered.org/maven"
+ }
+ maven {
+ name = "Forge"
+ url = "https://files.minecraftforge.net/maven"
+ }
+ maven {
+ name = "Nucleus"
+ url = "https://repo.drnaylor.co.uk/artifactory/list/minecraft"
+ }
+ maven {
+ name = "QuickStart"
+ url = "https://repo.drnaylor.co.uk/artifactory/list/quickstart"
+ }
+ maven {
+ name = "JitPack"
+ url = "https://jitpack.io"
+ }
+ maven {
+ name = "CodeMC"
+ url = "https://repo.codemc.org/repository/maven-public"
+ }
+}
+
+configurations {
+ provided
+ compile.extendsFrom provided
+ compileJava.options.encoding = "UTF-8"
+ jar.archiveName = "${project.name}-${project.version}.jar"
+}
+
+dependencies {
+ minecraft "net.minecraftforge:forge:${getProjectProperty('forgeVersion')}"
+ implementation("org.spongepowered:spongeapi:${getProjectProperty('spongeapi')}")
+ compile 'org.spongepowered:mixin:0.8.3-SNAPSHOT'
+ compile 'org.spongepowered:mixin:0.8.3-SNAPSHOT:processor'
+
+ implementation 'org.spongepowered:mixin:0.8.1-SNAPSHOT'
+ implementation("javax.validation:validation-api:2.0.1.Final")
+ compile group: 'commons-io', name: 'commons-io', version: '2.6'
+ compile group: 'org.bstats', name: 'bstats-sponge', version: '2.2.1'
+ shadow group: 'org.bstats', name: 'bstats-sponge', version: '2.2.1'
+
+ annotationProcessor("org.spongepowered:spongeapi:${getProjectProperty('spongeapi')}")
+ annotationProcessor("org.spongepowered:mixin:0.8.3-SNAPSHOT:processor")
+
+ implementation files('../NyxCore/build/libs/NyxCore-1.12.2-1.1-S7.3.0-STABLE.jar')
+}
+
+license {
+ header = file('HEADER.txt')
+ newLine = true
+ ext {
+ name = getProjectProperty('m_name')
+ organization = getProjectProperty('m_organization')
+ url = getProjectProperty('m_url')
+ }
+ include '**/*.java'
+ include '**/*.groovy'
+}
+
+idea {
+ module {
+ inheritOutputDirs = true
+ }
+}
+
+compileJava {
+ sourceCompatibility = targetCompatibility = "1.8"
+ options.encoding = 'UTF-8'
+ //options.compilerArgs << "-Xlint:unchecked" << "-Xlint:deprecation"
+ options.compilerArgs += [
+ '-Xlint:-processing',
+ '-Xlint:-deprecation',
+ ]
+ options.deprecation = true
+}
+
+processResources {
+ // this will ensure that this task is redone when the versions change.
+ inputs.property "version", "${getProjectProperty('m_major')}.${getProjectProperty('m_minor')}"
+ inputs.property "mcversion", getProjectProperty('minecraft_version')
+ inputs.property "modid", getProjectProperty('m_id')
+ inputs.property "description", getProjectProperty('m_description')
+ // replace stuff in mcmod.info, nothing else
+ from(sourceSets.main.resources.srcDirs) {
+ include "mcmod.info"
+
+ // replace version and mcversion
+ expand 'version': "${getProjectProperty('m_major')}.${getProjectProperty('m_minor')}", 'mcversion': getProjectProperty('minecraft_version')
+ }
+
+ // copy everything else, thats not the mcmod.info
+ from(sourceSets.main.resources.srcDirs) {
+ exclude "mcmod.info"
+ }
+ from 'LICENSE.txt'
+}
+
+shadowJar {
+ configurations = [project.configurations.shadow]
+ classifier('')
+ exclude 'dummyThing'
+ relocate "org.bstats", "${getProjectProperty('m_group')}.${getProjectProperty('m_id')}.shaded.bstats"
+ archiveName("${project.name}-${project.version}.jar")
+}
+
+reobf {
+ shadowJar {
+ classpath = sourceSets.main.compileClasspath
+ }
+}
+
+artifacts {
+ archives shadowJar
+}
+
+signing {
+ required { hasProperty("signing.keyId") }
+ sign configurations.archives, configurations.shadow
+}
+
+task copyJar(type: Copy) {
+ from jar.archiveFile
+ into 'C:/Minecraft/Servers/Sponge/mods'
+ project.logger.log(LogLevel.WARN, "Copied file: ${jar.archiveFile}")
+}
+
+String getProjectProperty(String propertyName) {
+ String temp = "null"
+ if (hasProperty(propertyName)) {
+ temp = this.properties.get(propertyName)
+ project.logger.log(LogLevel.WARN, "Found property: ${propertyName} value: ${temp}")
+ } else {
+ project.logger.log(LogLevel.ERROR, "Property (${propertyName}) not found!")
+ }
+ return temp
+}
+
+tasks.jar.finalizedBy('reobfJar')
+tasks.build.finalizedBy('copyJar')
\ No newline at end of file
diff --git a/gradle.properties b/gradle.properties
new file mode 100644
index 0000000..cebe40b
--- /dev/null
+++ b/gradle.properties
@@ -0,0 +1,36 @@
+# The Gradle daemon aims to improve the startup and execution time of Gradle.
+# When set to true the Gradle daemon is to run the build.
+org.gradle.daemon=false
+
+# Specifies the JVM arguments used for the daemon process.
+# The setting is particularly useful for tweaking memory settings.
+# Default value: -Xmx10248m -XX:MaxPermSize=256m
+org.gradle.jvmargs=-Xmx1G -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
+
+## General
+m_name=NyxBackpack
+m_id=nyxbackpack
+m_url=https://github.com/poqdavid/NyxBackpack
+m_organization=POQDavid
+m_authors=POQDavid
+m_group=io.github.poqdavid.nyx
+m_description=A simple backpack plugin
+
+## Version
+m_major=1
+m_minor=1
+m_api=S7.3.0
+m_suffix=STABLE
+
+## Dependencies
+spongeapi=7.3.0
+##spongeforge=7.1.6
+##spongeforgeServerFolder=run/spongeforge
+
+minecraft_version=1.12.2
+forge_rundir=run/forge
+forgeVersion=1.12.2-14.23.5.2854
+mappings_channel=snapshot
+mappings_version=20180814-1.12
+
+validation=1.1.0.Final
\ No newline at end of file
diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar
new file mode 100644
index 0000000..e708b1c
Binary files /dev/null and b/gradle/wrapper/gradle-wrapper.jar differ
diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties
new file mode 100644
index 0000000..3ab0b72
--- /dev/null
+++ b/gradle/wrapper/gradle-wrapper.properties
@@ -0,0 +1,5 @@
+distributionBase=GRADLE_USER_HOME
+distributionPath=wrapper/dists
+distributionUrl=https\://services.gradle.org/distributions/gradle-6.9.1-bin.zip
+zipStoreBase=GRADLE_USER_HOME
+zipStorePath=wrapper/dists
diff --git a/gradlew b/gradlew
new file mode 100644
index 0000000..4f906e0
--- /dev/null
+++ b/gradlew
@@ -0,0 +1,185 @@
+#!/usr/bin/env sh
+
+#
+# Copyright 2015 the original author or authors.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# https://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+##############################################################################
+##
+## Gradle start up script for UN*X
+##
+##############################################################################
+
+# Attempt to set APP_HOME
+# Resolve links: $0 may be a link
+PRG="$0"
+# Need this for relative symlinks.
+while [ -h "$PRG" ] ; do
+ ls=`ls -ld "$PRG"`
+ link=`expr "$ls" : '.*-> \(.*\)$'`
+ if expr "$link" : '/.*' > /dev/null; then
+ PRG="$link"
+ else
+ PRG=`dirname "$PRG"`"/$link"
+ fi
+done
+SAVED="`pwd`"
+cd "`dirname \"$PRG\"`/" >/dev/null
+APP_HOME="`pwd -P`"
+cd "$SAVED" >/dev/null
+
+APP_NAME="Gradle"
+APP_BASE_NAME=`basename "$0"`
+
+# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
+DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
+
+# Use the maximum available, or set MAX_FD != -1 to use that value.
+MAX_FD="maximum"
+
+warn () {
+ echo "$*"
+}
+
+die () {
+ echo
+ echo "$*"
+ echo
+ exit 1
+}
+
+# OS specific support (must be 'true' or 'false').
+cygwin=false
+msys=false
+darwin=false
+nonstop=false
+case "`uname`" in
+ CYGWIN* )
+ cygwin=true
+ ;;
+ Darwin* )
+ darwin=true
+ ;;
+ MINGW* )
+ msys=true
+ ;;
+ NONSTOP* )
+ nonstop=true
+ ;;
+esac
+
+CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
+
+
+# Determine the Java command to use to start the JVM.
+if [ -n "$JAVA_HOME" ] ; then
+ if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
+ # IBM's JDK on AIX uses strange locations for the executables
+ JAVACMD="$JAVA_HOME/jre/sh/java"
+ else
+ JAVACMD="$JAVA_HOME/bin/java"
+ fi
+ if [ ! -x "$JAVACMD" ] ; then
+ die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
+
+Please set the JAVA_HOME variable in your environment to match the
+location of your Java installation."
+ fi
+else
+ JAVACMD="java"
+ which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
+
+Please set the JAVA_HOME variable in your environment to match the
+location of your Java installation."
+fi
+
+# Increase the maximum file descriptors if we can.
+if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
+ MAX_FD_LIMIT=`ulimit -H -n`
+ if [ $? -eq 0 ] ; then
+ if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
+ MAX_FD="$MAX_FD_LIMIT"
+ fi
+ ulimit -n $MAX_FD
+ if [ $? -ne 0 ] ; then
+ warn "Could not set maximum file descriptor limit: $MAX_FD"
+ fi
+ else
+ warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
+ fi
+fi
+
+# For Darwin, add options to specify how the application appears in the dock
+if $darwin; then
+ GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
+fi
+
+# For Cygwin or MSYS, switch paths to Windows format before running java
+if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
+ APP_HOME=`cygpath --path --mixed "$APP_HOME"`
+ CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
+
+ JAVACMD=`cygpath --unix "$JAVACMD"`
+
+ # We build the pattern for arguments to be converted via cygpath
+ ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
+ SEP=""
+ for dir in $ROOTDIRSRAW ; do
+ ROOTDIRS="$ROOTDIRS$SEP$dir"
+ SEP="|"
+ done
+ OURCYGPATTERN="(^($ROOTDIRS))"
+ # Add a user-defined pattern to the cygpath arguments
+ if [ "$GRADLE_CYGPATTERN" != "" ] ; then
+ OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
+ fi
+ # Now convert the arguments - kludge to limit ourselves to /bin/sh
+ i=0
+ for arg in "$@" ; do
+ CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
+ CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
+
+ if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
+ eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
+ else
+ eval `echo args$i`="\"$arg\""
+ fi
+ i=`expr $i + 1`
+ done
+ case $i in
+ 0) set -- ;;
+ 1) set -- "$args0" ;;
+ 2) set -- "$args0" "$args1" ;;
+ 3) set -- "$args0" "$args1" "$args2" ;;
+ 4) set -- "$args0" "$args1" "$args2" "$args3" ;;
+ 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
+ 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
+ 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
+ 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
+ 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
+ esac
+fi
+
+# Escape application args
+save () {
+ for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
+ echo " "
+}
+APP_ARGS=`save "$@"`
+
+# Collect all arguments for the java command, following the shell quoting and substitution rules
+eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
+
+exec "$JAVACMD" "$@"
diff --git a/gradlew.bat b/gradlew.bat
new file mode 100644
index 0000000..ac1b06f
--- /dev/null
+++ b/gradlew.bat
@@ -0,0 +1,89 @@
+@rem
+@rem Copyright 2015 the original author or authors.
+@rem
+@rem Licensed under the Apache License, Version 2.0 (the "License");
+@rem you may not use this file except in compliance with the License.
+@rem You may obtain a copy of the License at
+@rem
+@rem https://www.apache.org/licenses/LICENSE-2.0
+@rem
+@rem Unless required by applicable law or agreed to in writing, software
+@rem distributed under the License is distributed on an "AS IS" BASIS,
+@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+@rem See the License for the specific language governing permissions and
+@rem limitations under the License.
+@rem
+
+@if "%DEBUG%" == "" @echo off
+@rem ##########################################################################
+@rem
+@rem Gradle startup script for Windows
+@rem
+@rem ##########################################################################
+
+@rem Set local scope for the variables with windows NT shell
+if "%OS%"=="Windows_NT" setlocal
+
+set DIRNAME=%~dp0
+if "%DIRNAME%" == "" set DIRNAME=.
+set APP_BASE_NAME=%~n0
+set APP_HOME=%DIRNAME%
+
+@rem Resolve any "." and ".." in APP_HOME to make it shorter.
+for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
+
+@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
+set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
+
+@rem Find java.exe
+if defined JAVA_HOME goto findJavaFromJavaHome
+
+set JAVA_EXE=java.exe
+%JAVA_EXE% -version >NUL 2>&1
+if "%ERRORLEVEL%" == "0" goto execute
+
+echo.
+echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
+echo.
+echo Please set the JAVA_HOME variable in your environment to match the
+echo location of your Java installation.
+
+goto fail
+
+:findJavaFromJavaHome
+set JAVA_HOME=%JAVA_HOME:"=%
+set JAVA_EXE=%JAVA_HOME%/bin/java.exe
+
+if exist "%JAVA_EXE%" goto execute
+
+echo.
+echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
+echo.
+echo Please set the JAVA_HOME variable in your environment to match the
+echo location of your Java installation.
+
+goto fail
+
+:execute
+@rem Setup the command line
+
+set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
+
+
+@rem Execute Gradle
+"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
+
+:end
+@rem End local scope for the variables with windows NT shell
+if "%ERRORLEVEL%"=="0" goto mainEnd
+
+:fail
+rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
+rem the _cmd.exe /c_ return code!
+if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
+exit /b 1
+
+:mainEnd
+if "%OS%"=="Windows_NT" endlocal
+
+:omega
diff --git a/settings.gradle b/settings.gradle
new file mode 100644
index 0000000..025476d
--- /dev/null
+++ b/settings.gradle
@@ -0,0 +1 @@
+rootProject.name = 'NyxBackpack'
diff --git a/src/main/java/io/github/poqdavid/nyx/nyxbackpack/Commands/BackpackCMD.java b/src/main/java/io/github/poqdavid/nyx/nyxbackpack/Commands/BackpackCMD.java
new file mode 100644
index 0000000..4396a20
--- /dev/null
+++ b/src/main/java/io/github/poqdavid/nyx/nyxbackpack/Commands/BackpackCMD.java
@@ -0,0 +1,154 @@
+/*
+ * This file is part of NyxBackpack.
+ *
+ * NyxBackpack is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * NyxBackpack is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with NyxBackpack. If not, see .
+ *
+ * Copyright (c) POQDavid
+ * Copyright (c) contributors
+ */
+
+package io.github.poqdavid.nyx.nyxbackpack.Commands;
+
+import io.github.poqdavid.nyx.nyxbackpack.NyxBackpack;
+import io.github.poqdavid.nyx.nyxbackpack.Utils.Backpack;
+import io.github.poqdavid.nyx.nyxcore.Permissions.BackpackPermission;
+import io.github.poqdavid.nyx.nyxcore.Utils.Tools;
+import org.spongepowered.api.command.CommandException;
+import org.spongepowered.api.command.CommandPermissionException;
+import org.spongepowered.api.command.CommandResult;
+import org.spongepowered.api.command.CommandSource;
+import org.spongepowered.api.command.args.CommandContext;
+import org.spongepowered.api.command.spec.CommandExecutor;
+import org.spongepowered.api.entity.living.player.Player;
+import org.spongepowered.api.item.inventory.Inventory;
+import org.spongepowered.api.item.inventory.property.InventoryTitle;
+import org.spongepowered.api.text.Text;
+import org.spongepowered.api.text.serializer.TextSerializers;
+
+import java.io.File;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+
+public class BackpackCMD implements CommandExecutor {
+
+ private final NyxBackpack nb;
+
+ public BackpackCMD(NyxBackpack nb) {
+ this.nb = nb;
+ }
+
+ public static Text getDescription() {
+ return Text.of("/backpack, /bp");
+ }
+
+ public static String[] getAlias() {
+ return new String[]{"backpack", "bp"};
+ }
+
+ @Override
+ public CommandResult execute(CommandSource src, CommandContext args) throws CommandException {
+ if (src instanceof Player) {
+ final Player player_cmd_src = Tools.getPlayer(src);
+
+ if (player_cmd_src.hasPermission(BackpackPermission.COMMAND_BACKPACK_MAIN)) {
+
+ this.backpackCheckLock(player_cmd_src, player_cmd_src);
+
+ final Backpack backpack = new Backpack(player_cmd_src, player_cmd_src, this.getBackpackSize(player_cmd_src), true, nb);
+ player_cmd_src.openInventory(backpack.getBackpack());
+
+ } else {
+ throw new CommandPermissionException(Text.of("You don't have permission to use this command."));
+ }
+ } else {
+ throw new CommandException(Text.of("You can't use this command if you are not a player!"));
+ }
+ return CommandResult.success();
+ }
+
+ public int getBackpackSize(Player player) {
+ if (player.hasPermission(BackpackPermission.COMMAND_BACKPACK_SIZE_SIX))
+ return 6;
+ if (player.hasPermission(BackpackPermission.COMMAND_BACKPACK_SIZE_FIVE))
+ return 5;
+ if (player.hasPermission(BackpackPermission.COMMAND_BACKPACK_SIZE_FOUR))
+ return 4;
+ if (player.hasPermission(BackpackPermission.COMMAND_BACKPACK_SIZE_THREE))
+ return 3;
+ if (player.hasPermission(BackpackPermission.COMMAND_BACKPACK_SIZE_TWO))
+ return 2;
+ if (player.hasPermission(BackpackPermission.COMMAND_BACKPACK_SIZE_ONE))
+ return 1;
+ return 1;
+ }
+
+
+ private void backpackCheckLock(Player player, Player playerSrc) throws CommandException {
+
+ Path file = Paths.get(this.nb.getConfigPath() + File.separator + "backpacks" + File.separator + player.getUniqueId() + ".lock");
+
+ if (Files.exists(file)) {
+ throw new CommandPermissionException(Text.of("Sorry currently your backpack is locked."));
+ } else {
+
+ if (isBackpackOpen(player)) {
+ throw new CommandPermissionException(Text.of("Sorry currently your backpack is locked!!"));
+ }
+ }
+ }
+
+ private Boolean isBackpackOpen(Player player) {
+ String tl = player.getName() + "'s " + "Backpack";
+ if (player.isOnline()) {
+ if (player.isViewingInventory()) {
+ Inventory inv = player.getInventory();
+
+ InventoryTitle title = inv.getInventoryProperty(InventoryTitle.class).orElse(InventoryTitle.of(Text.of("NONE")));
+ String titles = TextSerializers.FORMATTING_CODE.serialize(title.getValue());
+
+ if (titles.equals("Backpack")) {
+ return true;
+ } else {
+ return searchInvs(tl);
+ }
+
+ } else {
+
+ return searchInvs(tl);
+ }
+
+ } else {
+ return searchInvs(tl);
+ }
+ }
+
+ private Boolean searchInvs(String title) {
+ for (Player pl : this.nb.getGame().getServer().getOnlinePlayers()) {
+ if (pl.isViewingInventory()) {
+ Inventory inv2 = pl.getInventory();
+
+ InventoryTitle title2 = inv2.getInventoryProperty(InventoryTitle.class).orElse(InventoryTitle.of(Text.of("NONE")));
+ String titles2 = TextSerializers.FORMATTING_CODE.serialize(title2.getValue());
+
+ if (titles2.equals(title)) {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
+
+}
diff --git a/src/main/java/io/github/poqdavid/nyx/nyxbackpack/Commands/BackpackLockCMD.java b/src/main/java/io/github/poqdavid/nyx/nyxbackpack/Commands/BackpackLockCMD.java
new file mode 100644
index 0000000..0a2995a
--- /dev/null
+++ b/src/main/java/io/github/poqdavid/nyx/nyxbackpack/Commands/BackpackLockCMD.java
@@ -0,0 +1,101 @@
+/*
+ * This file is part of NyxBackpack.
+ *
+ * NyxBackpack is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * NyxBackpack is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with NyxBackpack. If not, see .
+ *
+ * Copyright (c) POQDavid
+ * Copyright (c) contributors
+ */
+
+package io.github.poqdavid.nyx.nyxbackpack.Commands;
+
+import io.github.poqdavid.nyx.nyxcore.Permissions.BackpackPermission;
+import io.github.poqdavid.nyx.nyxcore.Utils.Tools;
+import org.spongepowered.api.command.CommandException;
+import org.spongepowered.api.command.CommandPermissionException;
+import org.spongepowered.api.command.CommandResult;
+import org.spongepowered.api.command.CommandSource;
+import org.spongepowered.api.command.args.CommandContext;
+import org.spongepowered.api.command.spec.CommandExecutor;
+import org.spongepowered.api.entity.living.player.User;
+import org.spongepowered.api.text.Text;
+
+import java.util.Optional;
+
+
+public class BackpackLockCMD implements CommandExecutor {
+
+ public BackpackLockCMD() {
+ }
+
+ public static Text getDescription() {
+ return Text.of("/backpacklock, /bplock");
+ }
+
+ public static String[] getAlias() {
+ return new String[]{"backpacklock", "bplock"};
+ }
+
+ @Override
+ public CommandResult execute(CommandSource src, CommandContext args) throws CommandException {
+ final Optional user = args.getOne("user");
+ User user_args = null;
+ if (user.isPresent()) {
+ user_args = user.get();
+ }
+
+ if (src.hasPermission(BackpackPermission.COMMAND_BACKPACKLOCK)) {
+ if (user_args != null) {
+ if (args.hasAny("l") || args.hasAny("u")) {
+ if (args.hasAny("l")) {
+ if (!Tools.backpackCheckLock(user_args)) {
+ this.bpLock(user_args, src);
+ }
+ }
+ if (args.hasAny("u")) {
+ if (Tools.backpackCheckLock(user_args)) {
+ this.bpunlock(user_args, src);
+ }
+ }
+ } else {
+ if (Tools.backpackCheckLock(user_args)) {
+ this.bpunlock(user_args, src);
+ } else {
+ this.bpLock(user_args, src);
+ }
+ }
+ }
+ } else {
+ throw new CommandPermissionException(Text.of("You don't have permission to use this command."));
+ }
+ return CommandResult.success();
+ }
+
+ private void bpLock(User user_args, CommandSource src) {
+ if (Tools.lockBackpack(user_args, true)) {
+ src.sendMessage(Text.of("Backpack for " + user_args.getName() + " is now locked"));
+ } else {
+ src.sendMessage(Text.of("Backpack lock for " + user_args.getName() + " didn't work"));
+ }
+ }
+
+ private void bpunlock(User user_args, CommandSource src) {
+ if (Tools.unlockBackpack(user_args, true)) {
+ src.sendMessage(Text.of("Backpack for " + user_args.getName() + " is now unlocked"));
+ } else {
+ src.sendMessage(Text.of("Backpack unlock for " + user_args.getName() + " didn't work"));
+ src.sendMessage(Text.of("This can be a error or just there is no lock"));
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/io/github/poqdavid/nyx/nyxbackpack/Commands/CommandManager.java b/src/main/java/io/github/poqdavid/nyx/nyxbackpack/Commands/CommandManager.java
new file mode 100644
index 0000000..e2f81d7
--- /dev/null
+++ b/src/main/java/io/github/poqdavid/nyx/nyxbackpack/Commands/CommandManager.java
@@ -0,0 +1,77 @@
+/*
+ * This file is part of NyxBackpack.
+ *
+ * NyxBackpack is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * NyxBackpack is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with NyxBackpack. If not, see .
+ *
+ * Copyright (c) POQDavid
+ * Copyright (c) contributors
+ */
+
+package io.github.poqdavid.nyx.nyxbackpack.Commands;
+
+import io.github.poqdavid.nyx.nyxbackpack.NyxBackpack;
+import org.spongepowered.api.Game;
+import org.spongepowered.api.command.args.GenericArguments;
+import org.spongepowered.api.command.spec.CommandSpec;
+import org.spongepowered.api.text.Text;
+
+
+public class CommandManager {
+
+ public static CommandSpec helpCmd;
+ public static CommandSpec openCmd;
+ public static CommandSpec backpackCmd;
+ public static CommandSpec backpacklockCmd;
+ private final Game game;
+ private final NyxBackpack nb;
+
+
+ public CommandManager(Game game, NyxBackpack nb) {
+ this.game = game;
+ this.nb = nb;
+ registerCommands();
+ }
+
+ public void registerCommands() {
+ helpCmd = CommandSpec.builder()
+ .description(Text.of("/bp help"))
+ .executor(new HelpCMD())
+ .build();
+
+ openCmd = CommandSpec.builder()
+ .description(OpenCMD.getDescription())
+ .executor(new OpenCMD(this.nb))
+ .arguments(GenericArguments.user(Text.of("user")), GenericArguments.flags().flag("m").buildWith(GenericArguments.none()), GenericArguments.optional(GenericArguments.integer(Text.of("size"))))
+ .build();
+
+ backpacklockCmd = CommandSpec.builder()
+ .description(BackpackLockCMD.getDescription())
+ .executor(new BackpackLockCMD())
+ .arguments(GenericArguments.user(Text.of("user")), GenericArguments.flags().flag("l").flag("u").buildWith(GenericArguments.none()))
+ .build();
+
+ backpackCmd = CommandSpec.builder()
+ .description(BackpackCMD.getDescription())
+ .executor(new BackpackCMD(this.nb))
+ .child(openCmd, OpenCMD.getAlias())
+ .child(helpCmd, HelpCMD.getAlias())
+ .build();
+
+ game.getCommandManager().register(nb, backpacklockCmd, BackpackLockCMD.getAlias());
+ game.getCommandManager().register(nb, backpackCmd, BackpackCMD.getAlias());
+ game.getCommandManager().register(nb, openCmd, "backpackopen", "bpop");
+
+ }
+
+}
diff --git a/src/main/java/io/github/poqdavid/nyx/nyxbackpack/Commands/HelpCMD.java b/src/main/java/io/github/poqdavid/nyx/nyxbackpack/Commands/HelpCMD.java
new file mode 100644
index 0000000..592fc35
--- /dev/null
+++ b/src/main/java/io/github/poqdavid/nyx/nyxbackpack/Commands/HelpCMD.java
@@ -0,0 +1,85 @@
+/*
+ * This file is part of NyxBackpack.
+ *
+ * NyxBackpack is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * NyxBackpack is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with NyxBackpack. If not, see .
+ *
+ * Copyright (c) POQDavid
+ * Copyright (c) contributors
+ */
+
+package io.github.poqdavid.nyx.nyxbackpack.Commands;
+
+import io.github.poqdavid.nyx.nyxbackpack.NyxBackpack;
+import io.github.poqdavid.nyx.nyxcore.Permissions.BackpackPermission;
+import org.spongepowered.api.command.CommandException;
+import org.spongepowered.api.command.CommandPermissionException;
+import org.spongepowered.api.command.CommandResult;
+import org.spongepowered.api.command.CommandSource;
+import org.spongepowered.api.command.args.CommandContext;
+import org.spongepowered.api.command.spec.CommandExecutor;
+import org.spongepowered.api.service.pagination.PaginationList;
+import org.spongepowered.api.text.Text;
+import org.spongepowered.api.text.action.TextActions;
+import org.spongepowered.api.text.format.TextColors;
+import org.spongepowered.api.text.format.TextStyles;
+
+import java.net.MalformedURLException;
+import java.net.URL;
+
+
+public class HelpCMD implements CommandExecutor {
+
+ public HelpCMD() {
+ }
+
+ public static String[] getAlias() {
+ return new String[]{"help", "?"};
+ }
+
+ @Override
+ public CommandResult execute(CommandSource src, CommandContext args) throws CommandException {
+ if (src.hasPermission(BackpackPermission.COMMAND_BACKPACK_HELP)) {
+ PaginationList.Builder builder = PaginationList.builder();
+ URL url1 = null;
+ try {
+ url1 = new URL("https://github.com/poqdavid/NyxBackpack/");
+ } catch (MalformedURLException e) {
+ e.printStackTrace();
+ }
+
+ Text h1 = Text.builder("Author: ").color(TextColors.BLUE).style(TextStyles.BOLD).build();
+ Text h2 = Text.builder("POQDavid").color(TextColors.GRAY).style(TextStyles.BOLD).onHover(TextActions.showText(Text.of(url1.toString()))).onClick(TextActions.openUrl(url1)).build();
+
+ builder.title(Text.of("§9Nyx§5Backpack §7- §6V" + NyxBackpack.getInstance().getVersion()))
+ .header(Text.of(h1, h2))
+ .contents(
+ Text.of(TextColors.BLUE, TextStyles.ITALIC, ""),
+ Text.of(TextColors.GREEN, TextStyles.BOLD, "Commands"),
+ Text.of("§6- /§7backpack§b, §6/§7bp"),
+ Text.of("§6- /§7backpack open§b, §6/§7bp open §6<§7user§6> [§7-m §6] [§7§6]"),
+ Text.of("§6- /§7backpackopen§b, §6/§7bpop §6<§7user§6> [§7-m §6] [§7§6]"),
+ Text.of("§6- /§7backpacklock§b, §6/§7bplock §6<§7user§6> [§7-u §6] [§7-l §6]")
+ )
+ .padding(Text.of("="))
+ .sendTo(src);
+ } else {
+ throw new CommandPermissionException(Text.of("You don't have permission to use this command."));
+ }
+
+ return CommandResult.success();
+ }
+
+}
+
+
diff --git a/src/main/java/io/github/poqdavid/nyx/nyxbackpack/Commands/OpenCMD.java b/src/main/java/io/github/poqdavid/nyx/nyxbackpack/Commands/OpenCMD.java
new file mode 100644
index 0000000..ded5a03
--- /dev/null
+++ b/src/main/java/io/github/poqdavid/nyx/nyxbackpack/Commands/OpenCMD.java
@@ -0,0 +1,234 @@
+/*
+ * This file is part of NyxBackpack.
+ *
+ * NyxBackpack is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * NyxBackpack is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with NyxBackpack. If not, see .
+ *
+ * Copyright (c) POQDavid
+ * Copyright (c) contributors
+ */
+
+package io.github.poqdavid.nyx.nyxbackpack.Commands;
+
+import io.github.poqdavid.nyx.nyxbackpack.NyxBackpack;
+import io.github.poqdavid.nyx.nyxbackpack.Utils.Backpack;
+import io.github.poqdavid.nyx.nyxcore.Permissions.BackpackPermission;
+import io.github.poqdavid.nyx.nyxcore.Utils.Tools;
+import org.spongepowered.api.command.CommandException;
+import org.spongepowered.api.command.CommandPermissionException;
+import org.spongepowered.api.command.CommandResult;
+import org.spongepowered.api.command.CommandSource;
+import org.spongepowered.api.command.args.CommandContext;
+import org.spongepowered.api.command.spec.CommandExecutor;
+import org.spongepowered.api.entity.living.player.Player;
+import org.spongepowered.api.entity.living.player.User;
+import org.spongepowered.api.item.inventory.Inventory;
+import org.spongepowered.api.item.inventory.property.InventoryTitle;
+import org.spongepowered.api.text.Text;
+import org.spongepowered.api.text.serializer.TextSerializers;
+
+import java.io.File;
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.Optional;
+
+public class OpenCMD implements CommandExecutor {
+
+ private final NyxBackpack nb;
+
+ public OpenCMD(NyxBackpack nb) {
+ this.nb = nb;
+ }
+
+ public static Text getDescription() {
+ return Text.of("/backpack open, /bp open");
+ }
+
+ public static String[] getAlias() {
+ return new String[]{"open", "op"};
+ }
+
+ @Override
+ public CommandResult execute(CommandSource src, CommandContext args) throws CommandException {
+ if (src instanceof Player) {
+ final Player player_cmd_src = Tools.getPlayer(src);
+ final Optional user = args.getOne("user");
+ User user_args = null;
+ if (user.isPresent()) {
+ user_args = user.get();
+ }
+
+ final Integer bpszie = args.getOne("size").orElse(0);
+
+ src.sendMessage(Text.of("§6Opening Backpack for:"));
+
+ src.sendMessage(Text.of("§6Name: §7" + user_args.getName()));
+ src.sendMessage(Text.of("§6UUID: §7" + user_args.getUniqueId()));
+
+ if (player_cmd_src.hasPermission(BackpackPermission.COMMAND_BACKPACK_MAIN)) {
+ if (user_args != null) {
+ if (player_cmd_src.hasPermission(BackpackPermission.COMMAND_BACKPACK_ADMIN_READ)) {
+ if (user_args.hasPermission(BackpackPermission.COMMAND_BACKPACK_MAIN)) {
+ if (args.hasAny("m")) {
+ if (player_cmd_src.hasPermission(BackpackPermission.COMMAND_BACKPACK_ADMIN_MODIFY)) {
+ this.backpackcheck(user_args);
+ this.backpackchecklock(user_args, player_cmd_src);
+
+ final Backpack backpack = new Backpack(user_args, player_cmd_src, this.getBackpackSize(user_args, bpszie), true, this.nb);
+ player_cmd_src.openInventory(backpack.getBackpack());
+ } else {
+ throw new CommandPermissionException(Text.of("You don't have permission to modify other backpacks."));
+ }
+ } else {
+ this.backpackcheck(user_args);
+ final Backpack backpack = new Backpack(user_args, player_cmd_src, this.getBackpackSize(user_args, bpszie), false, nb);
+ player_cmd_src.openInventory(backpack.getBackpack());
+ }
+ } else {
+ throw new CommandPermissionException(Text.of("This user doesn't have permission to use backpack."));
+ }
+ } else {
+ throw new CommandPermissionException(Text.of("You don't have permission to view other backpacks."));
+ }
+
+ } else {
+ throw new CommandPermissionException(Text.of("Player doesn't exist!"));
+ }
+ } else {
+ throw new CommandPermissionException(Text.of("You don't have permission to use this command."));
+ }
+ } else {
+ throw new CommandException(Text.of("You can't use this command if you are not a player!"));
+ }
+ return CommandResult.success();
+ }
+
+ public int getBackpackSize(User user) {
+ if (user.hasPermission(BackpackPermission.COMMAND_BACKPACK_SIZE_SIX))
+ return 6;
+ if (user.hasPermission(BackpackPermission.COMMAND_BACKPACK_SIZE_FIVE))
+ return 5;
+ if (user.hasPermission(BackpackPermission.COMMAND_BACKPACK_SIZE_FOUR))
+ return 4;
+ if (user.hasPermission(BackpackPermission.COMMAND_BACKPACK_SIZE_THREE))
+ return 3;
+ if (user.hasPermission(BackpackPermission.COMMAND_BACKPACK_SIZE_TWO))
+ return 2;
+ if (user.hasPermission(BackpackPermission.COMMAND_BACKPACK_SIZE_ONE))
+ return 1;
+ return 1;
+ }
+
+ public int getBackpackSize(User user, Integer size) {
+ if (size == 0) {
+ if (user.hasPermission(BackpackPermission.COMMAND_BACKPACK_SIZE_SIX))
+ return 6;
+ if (user.hasPermission(BackpackPermission.COMMAND_BACKPACK_SIZE_FIVE))
+ return 5;
+ if (user.hasPermission(BackpackPermission.COMMAND_BACKPACK_SIZE_FOUR))
+ return 4;
+ if (user.hasPermission(BackpackPermission.COMMAND_BACKPACK_SIZE_THREE))
+ return 3;
+ if (user.hasPermission(BackpackPermission.COMMAND_BACKPACK_SIZE_TWO))
+ return 2;
+ if (user.hasPermission(BackpackPermission.COMMAND_BACKPACK_SIZE_ONE))
+ return 1;
+ return 1;
+ } else {
+ if (size < 6) {
+ return 6;
+ } else {
+ return size;
+ }
+ }
+
+ }
+
+ private void backpackchecklock(User user, Player playersrc) throws CommandException {
+
+ Path file = Paths.get(this.nb.getConfigPath() + File.separator + "backpacks" + File.separator + user.getUniqueId() + ".lock");
+
+ if (Files.exists(file)) {
+ throw new CommandPermissionException(Text.of("Sorry currently your backpack is locked."));
+ } else {
+ if (isBackpackOpen(user)) {
+ throw new CommandPermissionException(Text.of("Sorry currently your backpack is locked!!"));
+ }
+ }
+ }
+
+ private Boolean isBackpackOpen(User user) {
+ String tl = user.getName() + "'s " + "Backpack";
+ if (user.isOnline()) {
+ if (user.getPlayer().isPresent()) {
+ Player player = user.getPlayer().get();
+ if (player.isViewingInventory()) {
+ Inventory inv = player.getInventory();
+
+ InventoryTitle title = inv.getInventoryProperty(InventoryTitle.class).orElse(InventoryTitle.of(Text.of("NONE")));
+ String titles = TextSerializers.FORMATTING_CODE.serialize(title.getValue());
+
+ if (titles == "Backpack") {
+ return true;
+ } else {
+ return searchInvs(tl);
+ }
+
+ } else {
+
+ return searchInvs(tl);
+ }
+ } else {
+ return searchInvs(tl);
+ }
+ } else {
+ return searchInvs(tl);
+ }
+ }
+
+ private Boolean searchInvs(String title) {
+ for (Player pl : this.nb.getGame().getServer().getOnlinePlayers()) {
+ if (pl.isViewingInventory()) {
+ Inventory inv2 = pl.getInventory();
+
+ InventoryTitle title2 = inv2.getInventoryProperty(InventoryTitle.class).orElse(InventoryTitle.of(Text.of("NONE")));
+ String titles2 = TextSerializers.FORMATTING_CODE.serialize(title2.getValue());
+
+ if (titles2 == title) {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
+ private void backpackcheck(User user) throws CommandException {
+ Path file = Paths.get(this.nb.getConfigPath() + File.separator + "backpacks" + File.separator + user.getUniqueId() + ".backpack");
+ if (!Files.exists(file)) {
+ throw new CommandPermissionException(Text.of("Sorry there is no backpack data for " + user.getName()));
+ } else {
+ String content = null;
+ try {
+ content = new String(Files.readAllBytes(file), StandardCharsets.UTF_8);
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ if (content == "{}") {
+ throw new CommandPermissionException(Text.of("Sorry there is no backpack data for " + user.getName()));
+ }
+ }
+ }
+}
diff --git a/src/main/java/io/github/poqdavid/nyx/nyxbackpack/NyxBackpack.java b/src/main/java/io/github/poqdavid/nyx/nyxbackpack/NyxBackpack.java
new file mode 100644
index 0000000..671b462
--- /dev/null
+++ b/src/main/java/io/github/poqdavid/nyx/nyxbackpack/NyxBackpack.java
@@ -0,0 +1,175 @@
+/*
+ * This file is part of NyxBackpack.
+ *
+ * NyxBackpack is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * NyxBackpack is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with NyxBackpack. If not, see .
+ *
+ * Copyright (c) POQDavid
+ * Copyright (c) contributors
+ */
+
+package io.github.poqdavid.nyx.nyxbackpack;
+
+import com.google.inject.Inject;
+import io.github.poqdavid.nyx.nyxbackpack.Commands.CommandManager;
+import io.github.poqdavid.nyx.nyxcore.NyxCore;
+import io.github.poqdavid.nyx.nyxcore.Utils.CText;
+import io.github.poqdavid.nyx.nyxcore.Utils.NCLogger;
+import io.github.poqdavid.nyx.nyxcore.Utils.Tools;
+import org.bstats.sponge.Metrics;
+import org.slf4j.Logger;
+import org.spongepowered.api.Game;
+import org.spongepowered.api.Sponge;
+import org.spongepowered.api.config.ConfigDir;
+import org.spongepowered.api.entity.living.player.Player;
+import org.spongepowered.api.event.Listener;
+import org.spongepowered.api.event.game.GameReloadEvent;
+import org.spongepowered.api.event.game.state.GameInitializationEvent;
+import org.spongepowered.api.event.game.state.GamePreInitializationEvent;
+import org.spongepowered.api.event.game.state.GameStartedServerEvent;
+import org.spongepowered.api.event.game.state.GameStartingServerEvent;
+import org.spongepowered.api.event.network.ClientConnectionEvent;
+import org.spongepowered.api.event.service.ChangeServiceProviderEvent;
+import org.spongepowered.api.plugin.Dependency;
+import org.spongepowered.api.plugin.Plugin;
+import org.spongepowered.api.plugin.PluginContainer;
+import org.spongepowered.api.service.permission.PermissionDescription;
+import org.spongepowered.api.service.permission.PermissionService;
+
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+import java.nio.file.Path;
+
+
+@Plugin(id = PluginData.id, name = PluginData.name, version = PluginData.version, description = PluginData.description, url = PluginData.url, authors = {PluginData.author1}, dependencies = {@Dependency(id = "nyxcore", version = "1.1", optional = false)})
+public class NyxBackpack {
+
+ private static NyxBackpack nyxbackpack;
+ private final NCLogger logger;
+ private final PluginContainer pluginContainer;
+ private final Metrics metrics;
+ public PermissionService permService;
+
+ @Inject
+ private Game game;
+ private CommandManager cmdManager;
+
+ @Inject
+ public NyxBackpack(Metrics.Factory metricsFactory, @ConfigDir(sharedRoot = true) Path path, Logger logger, PluginContainer container) {
+ nyxbackpack = this;
+ this.pluginContainer = container;
+ this.logger = NyxCore.getInstance().getLogger(CText.get(CText.Colors.BLUE, 1, "Nyx") + CText.get(CText.Colors.MAGENTA, 0, "Backpack"));
+
+ this.logger.info(" ");
+ this.logger.info(CText.get(CText.Colors.MAGENTA, 0, "NyxBackpack") + CText.get(CText.Colors.YELLOW, 0, " v" + io.github.poqdavid.nyx.nyxbackpack.PluginData.version));
+ this.logger.info("Starting...");
+ this.logger.info(" ");
+
+ metrics = metricsFactory.make(12559);
+ }
+
+
+ @Nonnull
+ public static NyxBackpack getInstance() {
+ return nyxbackpack;
+ }
+
+ @Nonnull
+ public Path getConfigPath() {
+ return NyxCore.getInstance().getBackpackPath();
+ }
+
+ @Nonnull
+ public Path getBackpackPath() {
+ return NyxCore.getInstance().getBackpacksPath();
+ }
+
+ @Nonnull
+ public PluginContainer getPluginContainer() {
+ return this.pluginContainer;
+ }
+
+ @Nonnull
+ public String getVersion() {
+ return PluginData.version;
+ }
+
+ @Nonnull
+ public NCLogger getLogger() {
+ return logger;
+ }
+
+ @Nonnull
+ public Game getGame() {
+ return game;
+ }
+
+ @Inject
+ public void setGame(Game game) {
+ this.game = game;
+ }
+
+ @Listener
+ public void onGamePreInit(@Nullable final GamePreInitializationEvent event) {
+ this.logger.info(" ");
+ this.logger.info(CText.get(CText.Colors.MAGENTA, 0, "NyxBackpack") + CText.get(CText.Colors.YELLOW, 0, " v" + io.github.poqdavid.nyx.nyxbackpack.PluginData.version));
+ this.logger.info("Initializing...");
+ this.logger.info(" ");
+
+ Tools.backpackUnlockAll();
+ }
+
+ @Listener
+ public void onChangeServiceProvider(ChangeServiceProviderEvent event) {
+ if (event.getService().equals(PermissionService.class)) {
+ this.permService = (PermissionService) event.getNewProviderRegistration().getProvider();
+ }
+ }
+
+ @Listener
+ public void onGameInit(@Nullable final GameInitializationEvent event) {
+ if (Sponge.getServiceManager().getRegistration(PermissionService.class).get().getPlugin().getId().equalsIgnoreCase("sponge")) {
+ this.logger.error("Unable to initialize plugin. NyxBackpack requires a PermissionService like LuckPerms, PEX, PermissionsManager.");
+ return;
+ }
+
+ this.logger.info("Plugin Initialized successfully!");
+ }
+
+ @Listener
+ public void onServerStarting(GameStartingServerEvent event) {
+ this.logger.info("Loading...");
+ this.cmdManager = new CommandManager(game, this);
+ this.logger.info("Loaded!");
+ }
+
+ @Listener
+ public void onServerStart(GameStartedServerEvent event) {
+ //this.logger.info("Game Server Started...");
+ }
+
+ @Listener
+ public void onPlayerJoin(ClientConnectionEvent.Join event) {
+ final Player player = Tools.getPlayer(event.getCause()).get();
+ Tools.MakeNewBP(player);
+ }
+
+ @Listener
+ public void onGameReload(@Nullable final GameReloadEvent event) {
+ this.logger.info("Reloading...");
+
+ Tools.backpackUnlockAll();
+ this.logger.info("Reloaded!");
+ }
+
+}
diff --git a/src/main/java/io/github/poqdavid/nyx/nyxbackpack/PluginData.java b/src/main/java/io/github/poqdavid/nyx/nyxbackpack/PluginData.java
new file mode 100644
index 0000000..c97de7c
--- /dev/null
+++ b/src/main/java/io/github/poqdavid/nyx/nyxbackpack/PluginData.java
@@ -0,0 +1,32 @@
+/*
+ * This file is part of NyxBackpack.
+ *
+ * NyxBackpack is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * NyxBackpack is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with NyxBackpack. If not, see .
+ *
+ * Copyright (c) POQDavid
+ * Copyright (c) contributors
+ */
+
+package io.github.poqdavid.nyx.nyxbackpack;
+
+public class PluginData {
+ public static final String id = "nyxbackpack";
+ public static final String name = "NyxBackpack";
+ public static final String version = "1.1";
+ public static final String description = "A simple backpack plugin";
+ public static final String organization = "POQDavid";
+ public static final String author1 = "POQDavid";
+ public static final String url = "https://github.com/poqdavid/NyxBackpack";
+
+}
diff --git a/src/main/java/io/github/poqdavid/nyx/nyxbackpack/Utils/Backpack.java b/src/main/java/io/github/poqdavid/nyx/nyxbackpack/Utils/Backpack.java
new file mode 100644
index 0000000..97b4a0b
--- /dev/null
+++ b/src/main/java/io/github/poqdavid/nyx/nyxbackpack/Utils/Backpack.java
@@ -0,0 +1,217 @@
+/*
+ * This file is part of NyxBackpack.
+ *
+ * NyxBackpack is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * NyxBackpack is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with NyxBackpack. If not, see .
+ *
+ * Copyright (c) POQDavid
+ * Copyright (c) contributors
+ */
+
+package io.github.poqdavid.nyx.nyxbackpack.Utils;
+
+import com.google.common.base.Charsets;
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+import com.google.gson.reflect.TypeToken;
+import io.github.poqdavid.nyx.nyxbackpack.NyxBackpack;
+import io.github.poqdavid.nyx.nyxcore.Utils.Tools;
+import org.apache.commons.io.FileUtils;
+import org.spongepowered.api.entity.living.player.Player;
+import org.spongepowered.api.entity.living.player.User;
+import org.spongepowered.api.event.item.inventory.ClickInventoryEvent;
+import org.spongepowered.api.item.ItemTypes;
+import org.spongepowered.api.item.inventory.Inventory;
+import org.spongepowered.api.item.inventory.InventoryArchetypes;
+import org.spongepowered.api.item.inventory.ItemStack;
+import org.spongepowered.api.item.inventory.property.InventoryDimension;
+import org.spongepowered.api.item.inventory.property.InventoryTitle;
+import org.spongepowered.api.item.inventory.property.SlotIndex;
+import org.spongepowered.api.item.inventory.property.SlotPos;
+import org.spongepowered.api.item.inventory.query.QueryOperationTypes;
+import org.spongepowered.api.text.Text;
+
+import java.io.File;
+import java.io.IOException;
+import java.lang.reflect.Type;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.HashMap;
+import java.util.Map;
+
+public class Backpack {
+
+ private final Path backpackFilePath;
+ private final User user_args;
+ private final Player playerCmdSrc;
+ private final Inventory inventory;
+ private final NyxBackpack nb;
+ private final Text backpackTitleText;
+ private final String backpackTitleStr;
+ private final int size;
+ private final Boolean saveIt;
+
+ public Backpack(User user_args, Player player_cmd_src, int size, Boolean saveit, NyxBackpack nb) {
+ this.backpackFilePath = Paths.get(nb.getBackpackPath() + File.separator + user_args.getUniqueId() + ".backpack");
+
+ this.nb = nb;
+ this.user_args = user_args;
+ this.playerCmdSrc = player_cmd_src;
+ this.size = size;
+ this.saveIt = saveit;
+
+ if (!player_cmd_src.getUniqueId().equals(this.user_args.getUniqueId())) {
+ this.backpackTitleText = Text.of(this.user_args.getName() + "'s " + "Backpack");
+ this.backpackTitleStr = this.user_args.getName() + "'s " + "Backpack";
+ } else {
+ this.backpackTitleText = Text.of("Backpack");
+ this.backpackTitleStr = "Backpack";
+ }
+
+ this.inventory = Inventory.builder()
+ .of(InventoryArchetypes.CHEST).withCarrier(this.playerCmdSrc)
+ .property(InventoryTitle.PROPERTY_NAME, InventoryTitle.of(Text.of(this.backpackTitleText)))
+ .property(InventoryDimension.PROPERTY_NAME, InventoryDimension.of(9, this.size))
+ .listener(ClickInventoryEvent.class, this::triggerClickEvent)
+ .build(NyxBackpack.getInstance());
+ this.loadBackpack(this.user_args, this.nb);
+ }
+
+ private void saveBackpack(User user, Map items, NyxBackpack nb) {
+ Gson gson = new GsonBuilder().setPrettyPrinting().disableHtmlEscaping().create();
+
+ if (items == null || items.isEmpty()) {
+ Tools.WriteFile(this.backpackFilePath.toFile(), "{}");
+ } else {
+ Tools.WriteFile(this.backpackFilePath.toFile(), gson.toJson(items));
+ }
+ }
+
+ private Map loadStacks(User user) throws Exception {
+ Map items = loadSlots();
+
+ for (Inventory slot : this.inventory.slots()) {
+
+ if (slot.getProperty(SlotIndex.class, "slotindex").isPresent()) {
+
+ Integer index = slot.getProperty(SlotIndex.class, "slotindex").get().getValue();
+ SlotPos slotP = Tools.indexToSP(index);
+ items.put(slotP.getX() + "," + slotP.getY(), "EMPTY");
+
+ if (slot.size() > 0) {
+
+ if (slot.peek().isPresent()) {
+
+ if (slot.getProperty(SlotIndex.class, "slotindex").isPresent()) {
+
+ if (!slot.peek().get().getType().equals(ItemTypes.NONE)) {
+ try {
+
+ items.put(slotP.getX() + "," + slotP.getY(), Tools.ItemStackToBase64(slot.peek().get()));
+
+ } catch (Exception e) {
+ NyxBackpack.getInstance().getLogger().error("Failed to load a stack data from inventory for this user: " + user.getName() + " SlotPos: " + slotP.getX() + "X," + slotP.getY() + "Y");
+ e.printStackTrace();
+ throw new Exception("Failed to load a stack data from inventory for this user: " + user.getName() + " SlotPos: " + slotP.getX() + "X," + slotP.getY() + "Y");
+ }
+ }
+
+ }
+
+ }
+ }
+
+ }
+
+ }
+
+ return items;
+
+ }
+
+ private Map loadSlots() throws Exception {
+ final File file = this.backpackFilePath.toFile();
+
+ if (!file.exists()) {
+ Tools.WriteFile(file, "{}");
+ }
+
+ Gson gson = new Gson();
+ Type type = new TypeToken