Add from other repository
This commit is contained in:
1 parent
bc17541cea
commit
818f33cc32
160 files changed
+11972
-1
No files matched your search
@@ -0,0 +1,39 @@
|
||||
# Automatically build the project and run any configured tests for every push
|
||||
# and submitted pull request. This can help catch issues that only occur on
|
||||
# certain platforms or Java versions, and provides a first line of defence
|
||||
# against bad commits.
|
||||
|
||||
name: build
|
||||
on: [pull_request, push]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
strategy:
|
||||
matrix:
|
||||
# Use these Java versions
|
||||
java: [
|
||||
17 # Minimum supported by Minecraft
|
||||
]
|
||||
# and run on both Linux and Windows
|
||||
os: [ubuntu-20.04, windows-latest]
|
||||
runs-on: ${{ matrix.os }}
|
||||
steps:
|
||||
- name: checkout repository
|
||||
uses: actions/checkout@v2
|
||||
- name: validate gradle wrapper
|
||||
uses: gradle/wrapper-validation-action@v1
|
||||
- name: setup jdk ${{ matrix.java }}
|
||||
uses: actions/setup-java@v1
|
||||
with:
|
||||
java-version: ${{ matrix.java }}
|
||||
- name: make gradle wrapper executable
|
||||
if: ${{ runner.os != 'Windows' }}
|
||||
run: chmod +x ./gradlew
|
||||
- name: build
|
||||
run: ./gradlew build
|
||||
- name: capture build artifacts
|
||||
if: ${{ runner.os == 'Linux' && matrix.java == '17' }} # Only upload artifacts built from latest java on one OS
|
||||
uses: actions/upload-artifact@v2
|
||||
with:
|
||||
name: Artifacts
|
||||
path: build/libs/
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
# gradle
|
||||
|
||||
.gradle/
|
||||
build/
|
||||
out/
|
||||
classes/
|
||||
|
||||
# eclipse
|
||||
|
||||
*.launch
|
||||
|
||||
# idea
|
||||
|
||||
.idea/
|
||||
*.iml
|
||||
*.ipr
|
||||
*.iws
|
||||
|
||||
# vscode
|
||||
|
||||
.settings/
|
||||
.vscode/
|
||||
bin/
|
||||
.classpath
|
||||
.project
|
||||
|
||||
# fabric
|
||||
|
||||
run/
|
||||
@@ -0,0 +1,121 @@
|
||||
Creative Commons Legal Code
|
||||
|
||||
CC0 1.0 Universal
|
||||
|
||||
CREATIVE COMMONS CORPORATION IS NOT A LAW FIRM AND DOES NOT PROVIDE
|
||||
LEGAL SERVICES. DISTRIBUTION OF THIS DOCUMENT DOES NOT CREATE AN
|
||||
ATTORNEY-CLIENT RELATIONSHIP. CREATIVE COMMONS PROVIDES THIS
|
||||
INFORMATION ON AN "AS-IS" BASIS. CREATIVE COMMONS MAKES NO WARRANTIES
|
||||
REGARDING THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS
|
||||
PROVIDED HEREUNDER, AND DISCLAIMS LIABILITY FOR DAMAGES RESULTING FROM
|
||||
THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS PROVIDED
|
||||
HEREUNDER.
|
||||
|
||||
Statement of Purpose
|
||||
|
||||
The laws of most jurisdictions throughout the world automatically confer
|
||||
exclusive Copyright and Related Rights (defined below) upon the creator
|
||||
and subsequent owner(s) (each and all, an "owner") of an original work of
|
||||
authorship and/or a database (each, a "Work").
|
||||
|
||||
Certain owners wish to permanently relinquish those rights to a Work for
|
||||
the purpose of contributing to a commons of creative, cultural and
|
||||
scientific works ("Commons") that the public can reliably and without fear
|
||||
of later claims of infringement build upon, modify, incorporate in other
|
||||
works, reuse and redistribute as freely as possible in any form whatsoever
|
||||
and for any purposes, including without limitation commercial purposes.
|
||||
These owners may contribute to the Commons to promote the ideal of a free
|
||||
culture and the further production of creative, cultural and scientific
|
||||
works, or to gain reputation or greater distribution for their Work in
|
||||
part through the use and efforts of others.
|
||||
|
||||
For these and/or other purposes and motivations, and without any
|
||||
expectation of additional consideration or compensation, the person
|
||||
associating CC0 with a Work (the "Affirmer"), to the extent that he or she
|
||||
is an owner of Copyright and Related Rights in the Work, voluntarily
|
||||
elects to apply CC0 to the Work and publicly distribute the Work under its
|
||||
terms, with knowledge of his or her Copyright and Related Rights in the
|
||||
Work and the meaning and intended legal effect of CC0 on those rights.
|
||||
|
||||
1. Copyright and Related Rights. A Work made available under CC0 may be
|
||||
protected by copyright and related or neighboring rights ("Copyright and
|
||||
Related Rights"). Copyright and Related Rights include, but are not
|
||||
limited to, the following:
|
||||
|
||||
i. the right to reproduce, adapt, distribute, perform, display,
|
||||
communicate, and translate a Work;
|
||||
ii. moral rights retained by the original author(s) and/or performer(s);
|
||||
iii. publicity and privacy rights pertaining to a person's image or
|
||||
likeness depicted in a Work;
|
||||
iv. rights protecting against unfair competition in regards to a Work,
|
||||
subject to the limitations in paragraph 4(a), below;
|
||||
v. rights protecting the extraction, dissemination, use and reuse of data
|
||||
in a Work;
|
||||
vi. database rights (such as those arising under Directive 96/9/EC of the
|
||||
European Parliament and of the Council of 11 March 1996 on the legal
|
||||
protection of databases, and under any national implementation
|
||||
thereof, including any amended or successor version of such
|
||||
directive); and
|
||||
vii. other similar, equivalent or corresponding rights throughout the
|
||||
world based on applicable law or treaty, and any national
|
||||
implementations thereof.
|
||||
|
||||
2. Waiver. To the greatest extent permitted by, but not in contravention
|
||||
of, applicable law, Affirmer hereby overtly, fully, permanently,
|
||||
irrevocably and unconditionally waives, abandons, and surrenders all of
|
||||
Affirmer's Copyright and Related Rights and associated claims and causes
|
||||
of action, whether now known or unknown (including existing as well as
|
||||
future claims and causes of action), in the Work (i) in all territories
|
||||
worldwide, (ii) for the maximum duration provided by applicable law or
|
||||
treaty (including future time extensions), (iii) in any current or future
|
||||
medium and for any number of copies, and (iv) for any purpose whatsoever,
|
||||
including without limitation commercial, advertising or promotional
|
||||
purposes (the "Waiver"). Affirmer makes the Waiver for the benefit of each
|
||||
member of the public at large and to the detriment of Affirmer's heirs and
|
||||
successors, fully intending that such Waiver shall not be subject to
|
||||
revocation, rescission, cancellation, termination, or any other legal or
|
||||
equitable action to disrupt the quiet enjoyment of the Work by the public
|
||||
as contemplated by Affirmer's express Statement of Purpose.
|
||||
|
||||
3. Public License Fallback. Should any part of the Waiver for any reason
|
||||
be judged legally invalid or ineffective under applicable law, then the
|
||||
Waiver shall be preserved to the maximum extent permitted taking into
|
||||
account Affirmer's express Statement of Purpose. In addition, to the
|
||||
extent the Waiver is so judged Affirmer hereby grants to each affected
|
||||
person a royalty-free, non transferable, non sublicensable, non exclusive,
|
||||
irrevocable and unconditional license to exercise Affirmer's Copyright and
|
||||
Related Rights in the Work (i) in all territories worldwide, (ii) for the
|
||||
maximum duration provided by applicable law or treaty (including future
|
||||
time extensions), (iii) in any current or future medium and for any number
|
||||
of copies, and (iv) for any purpose whatsoever, including without
|
||||
limitation commercial, advertising or promotional purposes (the
|
||||
"License"). The License shall be deemed effective as of the date CC0 was
|
||||
applied by Affirmer to the Work. Should any part of the License for any
|
||||
reason be judged legally invalid or ineffective under applicable law, such
|
||||
partial invalidity or ineffectiveness shall not invalidate the remainder
|
||||
of the License, and in such case Affirmer hereby affirms that he or she
|
||||
will not (i) exercise any of his or her remaining Copyright and Related
|
||||
Rights in the Work or (ii) assert any associated claims and causes of
|
||||
action with respect to the Work, in either case contrary to Affirmer's
|
||||
express Statement of Purpose.
|
||||
|
||||
4. Limitations and Disclaimers.
|
||||
|
||||
a. No trademark or patent rights held by Affirmer are waived, abandoned,
|
||||
surrendered, licensed or otherwise affected by this document.
|
||||
b. Affirmer offers the Work as-is and makes no representations or
|
||||
warranties of any kind concerning the Work, express, implied,
|
||||
statutory or otherwise, including without limitation warranties of
|
||||
title, merchantability, fitness for a particular purpose, non
|
||||
infringement, or the absence of latent or other defects, accuracy, or
|
||||
the present or absence of errors, whether or not discoverable, all to
|
||||
the greatest extent permissible under applicable law.
|
||||
c. Affirmer disclaims responsibility for clearing rights of other persons
|
||||
that may apply to the Work or any use thereof, including without
|
||||
limitation any person's Copyright and Related Rights in the Work.
|
||||
Further, Affirmer disclaims responsibility for obtaining any necessary
|
||||
consents, permissions or other rights required for any use of the
|
||||
Work.
|
||||
d. Affirmer understands and acknowledges that Creative Commons is not a
|
||||
party to this document and has no duty or obligation with respect to
|
||||
this CC0 or use of the Work.
|
||||
@@ -1 +1,6 @@
|
||||
# Nexia Mod
|
||||
# Nexia
|
||||
|
||||
### Requirements
|
||||
- Java 17
|
||||
- Gradle 7.3
|
||||
- Fabric API (cts version)
|
||||
+114
@@ -0,0 +1,114 @@
|
||||
plugins {
|
||||
id 'fabric-loom' version '0.13-SNAPSHOT'
|
||||
id 'maven-publish'
|
||||
}
|
||||
|
||||
sourceCompatibility = JavaVersion.VERSION_1_8
|
||||
targetCompatibility = JavaVersion.VERSION_1_8
|
||||
|
||||
archivesBaseName = project.archives_base_name
|
||||
version = project.mod_version
|
||||
group = project.maven_group
|
||||
|
||||
// Repo for CT intermediary mappings
|
||||
repositories {
|
||||
maven { url 'https://maven.nucleoid.xyz' }
|
||||
maven { url "https://maven.rizecookey.net/" }
|
||||
maven { url "https://maven.shedaniel.me/" }
|
||||
maven { url "https://maven.terraformersmc.com/releases/" }
|
||||
maven { url 'https://oss.sonatype.org/content/repositories/snapshots' }
|
||||
maven { url 'https://github.com/ricksouth/serilum-forge-maven/raw/maven/' }
|
||||
}
|
||||
|
||||
dependencies {
|
||||
//to change the versions see the gradle.properties file
|
||||
minecraft "com.mojang:minecraft:${project.minecraft_version}"
|
||||
mappings loom.officialMojangMappings()
|
||||
modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"
|
||||
|
||||
//modApiMapped('com.combatreforged.factory:factory-api:0.1.13-full')
|
||||
//modApiMapped('com.combatreforged.factory:factory-builder:0.1.13-1.16_combat-6')
|
||||
|
||||
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"
|
||||
|
||||
//include(modApi("eu.pb4:hologram-api:0.1.0") { exclude(group: "net.fabricmc.fabric-api") })
|
||||
//include(modApi("eu.pb4:sidebar-api:0.0.2") { exclude(group: "net.fabricmc.fabric-api") })
|
||||
|
||||
modApi('com.natamus.collective:collective-fabric:1.16.5-5.50')
|
||||
include(modApi('xyz.nucleoid:fantasy:0.4.0') {exclude(group: "net.fabricmc.fabric-api") })
|
||||
include(modApi('eu.pb4:sgui:0.5.0') { exclude(group: "net.fabricmc.fabric-api") })
|
||||
include(modApi('me.sargunvohra.mcmods:autoconfig1u:3.3.1') { exclude(group: "net.fabricmc.fabric-api") })
|
||||
modApi('me.lucko:fabric-permissions-api:0.2-SNAPSHOT')
|
||||
|
||||
// PSA: Some older mods, compiled on Loom 0.2.1, might have outdated Maven POMs.
|
||||
// You may need to force-disable transitiveness on them.
|
||||
}
|
||||
|
||||
// Custom Manifest and Intermediary mappings declaration
|
||||
loom {
|
||||
customMinecraftManifest = "https://gist.githubusercontent.com/rizecookey/4c6142baaccc3875f9b227fe22f2ace5/raw/c8ed74b19f7a5315813c9d4b199798b692a8f359/1.16_combat-6.json"
|
||||
intermediaryUrl = "https://maven.rizecookey.net/net/fabricmc/intermediary/%1\$s/intermediary-%1\$s-v2.jar"
|
||||
}
|
||||
|
||||
processResources {
|
||||
inputs.property "version", project.version
|
||||
filteringCharset "UTF-8"
|
||||
|
||||
filesMatching("fabric.mod.json") {
|
||||
expand "version": project.version
|
||||
}
|
||||
}
|
||||
|
||||
// ensure that the encoding is set to UTF-8, no matter what the system default is
|
||||
// this fixes some edge cases with special characters not displaying correctly
|
||||
// see http://yodaconditions.net/blog/fix-for-java-file-encoding-problems-with-gradle.html
|
||||
def targetJavaVersion = 17
|
||||
tasks.withType(JavaCompile).configureEach {
|
||||
it.options.encoding = "UTF-8"
|
||||
if (targetJavaVersion >= 10 || JavaVersion.current().isJava10Compatible()) {
|
||||
it.options.release = targetJavaVersion
|
||||
}
|
||||
}
|
||||
|
||||
// Loom will automatically attach sourcesJar to a RemapSourcesJar task and to the "build" task
|
||||
// if it is present.
|
||||
// If you remove this task, sources will not be generated.
|
||||
task sourcesJar(type: Jar, dependsOn: classes) {
|
||||
classifier = "sources"
|
||||
from sourceSets.main.allSource
|
||||
}
|
||||
|
||||
java {
|
||||
def javaVersion = JavaVersion.toVersion(targetJavaVersion)
|
||||
if (JavaVersion.current() < javaVersion) {
|
||||
toolchain.languageVersion = JavaLanguageVersion.of(targetJavaVersion)
|
||||
}
|
||||
archivesBaseName = project.archives_base_name
|
||||
}
|
||||
|
||||
jar {
|
||||
from("LICENSE") {
|
||||
rename { "${it}_${project.archivesBaseName}" }
|
||||
}
|
||||
}
|
||||
|
||||
// configure the maven publication
|
||||
publishing {
|
||||
publications {
|
||||
mavenJava(MavenPublication) {
|
||||
// add all the jars that should be included when publishing to maven
|
||||
artifact(remapJar) {
|
||||
builtBy remapJar
|
||||
}
|
||||
artifact(sourcesJar) {
|
||||
builtBy remapSourcesJar
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// select the repositories you want to publish to
|
||||
repositories {
|
||||
// uncomment to publish to the local maven
|
||||
// mavenLocal()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
# Done to increase the memory available to gradle.
|
||||
org.gradle.jvmargs=-Xmx1G
|
||||
|
||||
# Fabric Properties
|
||||
# check these on https://fabricmc.net/use
|
||||
minecraft_version=1.16_combat-6
|
||||
yarn_mappings=1.16_combat-6+build.2
|
||||
loader_version=0.9.3+build.207
|
||||
|
||||
# Mod Properties
|
||||
mod_version = 1.0.0
|
||||
maven_group = com.nexia
|
||||
archives_base_name = nexia
|
||||
|
||||
# Dependencies
|
||||
fabric_version=0.42.0+1.16
|
||||
|
||||
Vendored
BIN
Binary file not shown.
+5
@@ -0,0 +1,5 @@
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3-bin.zip
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
@@ -0,0 +1,183 @@
|
||||
#!/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" "$@"
|
||||
Vendored
+103
@@ -0,0 +1,103 @@
|
||||
@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 init
|
||||
|
||||
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 init
|
||||
|
||||
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
|
||||
|
||||
:init
|
||||
@rem Get command-line arguments, handling Windows variants
|
||||
|
||||
if not "%OS%" == "Windows_NT" goto win9xME_args
|
||||
|
||||
:win9xME_args
|
||||
@rem Slurp the command line arguments.
|
||||
set CMD_LINE_ARGS=
|
||||
set _SKIP=2
|
||||
|
||||
:win9xME_args_slurp
|
||||
if "x%~1" == "x" goto execute
|
||||
|
||||
set CMD_LINE_ARGS=%*
|
||||
|
||||
: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 %CMD_LINE_ARGS%
|
||||
|
||||
: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
|
||||
@@ -0,0 +1,10 @@
|
||||
pluginManagement {
|
||||
repositories {
|
||||
jcenter()
|
||||
maven {
|
||||
name = 'Fabric'
|
||||
url = 'https://maven.fabricmc.net/'
|
||||
}
|
||||
gradlePluginPortal()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package com.nexia.core;
|
||||
|
||||
import com.nexia.core.config.ModConfig;
|
||||
import com.nexia.core.loader.CommandLoader;
|
||||
import com.nexia.core.utilities.misc.NxFileUtil;
|
||||
import com.nexia.minigames.games.bedwars.areas.BwDimension;
|
||||
import com.nexia.minigames.games.bedwars.shop.BwLoadShop;
|
||||
import me.sargunvohra.mcmods.autoconfig1u.AutoConfig;
|
||||
import me.sargunvohra.mcmods.autoconfig1u.serializer.GsonConfigSerializer;
|
||||
import net.fabricmc.api.ModInitializer;
|
||||
import net.fabricmc.loader.api.FabricLoader;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
|
||||
public class Main implements ModInitializer {
|
||||
|
||||
public static MinecraftServer server;
|
||||
|
||||
public static ModConfig config;
|
||||
|
||||
public static final String MOD_NAME = "Nexia";
|
||||
public static final String MOD_NAME_SHORT = "Nx";
|
||||
public static final String modConfigDir = NxFileUtil.makeDir(FabricLoader.getInstance().getConfigDir().toString() + "/nexia");
|
||||
@Override
|
||||
public void onInitialize() {
|
||||
AutoConfig.register(ModConfig.class, GsonConfigSerializer::new);
|
||||
config = AutoConfig.getConfigHolder(ModConfig.class).getConfig();
|
||||
|
||||
CommandLoader.registerCommands();
|
||||
BwLoadShop.loadBedWarsShop(true);
|
||||
BwDimension.register();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package com.nexia.core.commands.player;
|
||||
|
||||
import com.mojang.brigadier.CommandDispatcher;
|
||||
import com.mojang.brigadier.context.CommandContext;
|
||||
import com.nexia.core.Main;
|
||||
import com.nexia.core.utilities.chat.ChatFormat;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
import net.minecraft.commands.Commands;
|
||||
import net.minecraft.network.chat.ClickEvent;
|
||||
import net.minecraft.network.chat.TextComponent;
|
||||
|
||||
public class DiscordCommand {
|
||||
|
||||
public static void register(CommandDispatcher<CommandSourceStack> dispatcher, boolean bl) {
|
||||
dispatcher.register(Commands.literal("discord").executes(DiscordCommand::run));
|
||||
}
|
||||
|
||||
public static int run(CommandContext<CommandSourceStack> context) {
|
||||
|
||||
|
||||
TextComponent message = new TextComponent(ChatFormat.brandColor1 + "Link to discord: ");
|
||||
|
||||
TextComponent discordLink = new TextComponent(ChatFormat.brandColor2 + "\247n" + Main.config.discordLink);
|
||||
discordLink.withStyle(style -> style.withClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, Main.config.discordLink)));
|
||||
|
||||
message.append(discordLink);
|
||||
|
||||
CommandSourceStack player = context.getSource();
|
||||
player.sendSuccess(message, false);
|
||||
|
||||
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
package com.nexia.core.commands.player;
|
||||
|
||||
import com.mojang.brigadier.CommandDispatcher;
|
||||
import com.mojang.brigadier.context.CommandContext;
|
||||
import com.nexia.core.utilities.chat.ChatFormat;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
import net.minecraft.commands.Commands;
|
||||
import net.minecraft.network.chat.TextComponent;
|
||||
|
||||
public class HelpCommand {
|
||||
|
||||
public static void register(CommandDispatcher<CommandSourceStack> dispatcher, boolean bl) {
|
||||
dispatcher.register(Commands.literal("help").executes(HelpCommand::run));
|
||||
}
|
||||
|
||||
static String commandSeparator = ": ";
|
||||
|
||||
static String[] commands = {
|
||||
"join" + commandSeparator + "join a game",
|
||||
"leave" + commandSeparator + "leave a game",
|
||||
"rules" + commandSeparator + "rules of the server",
|
||||
"discord" + commandSeparator + "leads you to our discord",
|
||||
"ping" + commandSeparator + "shows a player's ping",
|
||||
"prefix" + commandSeparator + "allows you to select your prefix",
|
||||
"report" + commandSeparator + "allows you to report other players",
|
||||
"msg" + commandSeparator + "allows you to message other players",
|
||||
"stats" + commandSeparator + "shows you your stats"
|
||||
};
|
||||
|
||||
public static int run(CommandContext<CommandSourceStack> context) {
|
||||
|
||||
String message = ChatFormat.separatorLine("Commands");
|
||||
|
||||
for (int i = 0; i < commands.length; i++) {
|
||||
String[] commandInfo = commands[i].split(commandSeparator);
|
||||
if (commandInfo.length < 2) continue;
|
||||
message += "\n" + ChatFormat.brandColor1 + "/" + commandInfo[0] + ChatFormat.lineColor + " | " + ChatFormat.brandColor2 + commandInfo[1];
|
||||
}
|
||||
|
||||
message += "\n" + ChatFormat.separatorLine(null);
|
||||
|
||||
CommandSourceStack player = context.getSource();
|
||||
player.sendSuccess(new TextComponent(message), false);
|
||||
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package com.nexia.core.commands.player;
|
||||
|
||||
import com.mojang.brigadier.CommandDispatcher;
|
||||
import com.mojang.brigadier.context.CommandContext;
|
||||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||
import com.nexia.core.games.util.LobbyUtil;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
import net.minecraft.commands.Commands;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
|
||||
public class LeaveCommand {
|
||||
|
||||
public static void register(CommandDispatcher<CommandSourceStack> dispatcher, boolean bl) {
|
||||
register(dispatcher, "leave");
|
||||
register(dispatcher, "lobby");
|
||||
register(dispatcher, "l");
|
||||
register(dispatcher, "hub");
|
||||
}
|
||||
|
||||
private static void register(CommandDispatcher<CommandSourceStack> dispatcher, String string) {
|
||||
dispatcher.register(Commands.literal(string).executes(LeaveCommand::run));
|
||||
}
|
||||
|
||||
public static int run(CommandContext<CommandSourceStack> context) throws CommandSyntaxException {
|
||||
ServerPlayer player = context.getSource().getPlayerOrException();
|
||||
LobbyUtil.leaveAllGames(player, true);
|
||||
return 1;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
package com.nexia.core.commands.player;
|
||||
|
||||
import com.mojang.brigadier.CommandDispatcher;
|
||||
import com.mojang.brigadier.arguments.StringArgumentType;
|
||||
import com.mojang.brigadier.context.CommandContext;
|
||||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||
import com.nexia.core.utilities.chat.ChatFormat;
|
||||
import com.nexia.core.utilities.chat.PlayerMutes;
|
||||
import com.nexia.core.utilities.player.PlayerData;
|
||||
import com.nexia.core.utilities.player.PlayerDataManager;
|
||||
import com.nexia.core.utilities.player.PlayerUtil;
|
||||
import net.minecraft.Util;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
import net.minecraft.commands.Commands;
|
||||
import net.minecraft.commands.arguments.EntityArgument;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
|
||||
public class MessageCommand {
|
||||
|
||||
public static void registerMsg(CommandDispatcher<CommandSourceStack> commandDispatcher, boolean bl) {
|
||||
commandDispatcher.register(Commands.literal("msg")
|
||||
.then(Commands.argument("player", EntityArgument.player())
|
||||
.then(Commands.argument("message", StringArgumentType.greedyString())
|
||||
.executes(MessageCommand::msgCommand)
|
||||
)
|
||||
));
|
||||
commandDispatcher.register(Commands.literal("mesaage")
|
||||
.then(Commands.argument("player", EntityArgument.player())
|
||||
.then(Commands.argument("message", StringArgumentType.greedyString())
|
||||
.executes(MessageCommand::msgCommand)
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public static void registerReply(CommandDispatcher<CommandSourceStack> commandDispatcher, boolean bl) {
|
||||
commandDispatcher.register(Commands.literal("r")
|
||||
.then(Commands.argument("message", StringArgumentType.greedyString())
|
||||
.executes(MessageCommand::replyCommand)
|
||||
));
|
||||
commandDispatcher.register(Commands.literal("reply")
|
||||
.then(Commands.argument("message", StringArgumentType.greedyString())
|
||||
.executes(MessageCommand::replyCommand)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
private static int msgCommand(CommandContext<CommandSourceStack> context) throws CommandSyntaxException {
|
||||
ServerPlayer sender = context.getSource().getPlayerOrException();
|
||||
ServerPlayer receiver = EntityArgument.getPlayer(context, "player");
|
||||
String message = StringArgumentType.getString(context, "message");
|
||||
|
||||
sendMessage(sender, receiver, message);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
private static int replyCommand(CommandContext<CommandSourceStack> context) throws CommandSyntaxException {
|
||||
ServerPlayer sender = context.getSource().getPlayerOrException();
|
||||
PlayerData senderData = PlayerDataManager.get(sender);
|
||||
ServerPlayer receiver = PlayerUtil.getFixedPlayer(senderData.lastMessageSender);
|
||||
|
||||
if (receiver == null) {
|
||||
sender.sendMessage(ChatFormat.format("{s}Nobody to reply to"), Util.NIL_UUID);
|
||||
return 1;
|
||||
}
|
||||
|
||||
String message = StringArgumentType.getString(context, "message");
|
||||
|
||||
sendMessage(sender, receiver, message);
|
||||
return 1;
|
||||
}
|
||||
|
||||
private static void sendMessage(ServerPlayer sender, ServerPlayer receiver, String message) {
|
||||
if (PlayerMutes.muted(sender) || sender == receiver) return;
|
||||
|
||||
sender.sendMessage(ChatFormat.format("{b1}To {} {s}» {b1}{}", receiver.getScoreboardName(), message),
|
||||
Util.NIL_UUID);
|
||||
PlayerDataManager.get(sender).lastMessageSender = receiver;
|
||||
|
||||
receiver.sendMessage(ChatFormat.format("{b1}From {} {s}» {b1}{}", sender.getScoreboardName(), message),
|
||||
Util.NIL_UUID);
|
||||
PlayerDataManager.get(receiver).lastMessageSender = sender;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
package com.nexia.core.commands.player;
|
||||
|
||||
import com.mojang.brigadier.CommandDispatcher;
|
||||
import com.mojang.brigadier.context.CommandContext;
|
||||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||
import com.nexia.core.utilities.chat.ChatFormat;
|
||||
import net.minecraft.Util;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
import net.minecraft.commands.Commands;
|
||||
import net.minecraft.commands.arguments.EntityArgument;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
|
||||
public class PingCommand {
|
||||
public static void register(CommandDispatcher<CommandSourceStack> dispatcher, boolean bl) {
|
||||
dispatcher.register(Commands.literal("ping").executes(PingCommand::run)
|
||||
.then(Commands.argument("player", EntityArgument.player())
|
||||
.executes(context -> PingCommand.ping(context, EntityArgument.getPlayer(context, "player")))
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public static int calculate(int ping){
|
||||
if(ping < 4){
|
||||
return -1;
|
||||
}
|
||||
return ping;
|
||||
}
|
||||
|
||||
public static int run(CommandContext<CommandSourceStack> context) throws CommandSyntaxException {
|
||||
ServerPlayer executer = context.getSource().getPlayerOrException();
|
||||
int ping = executer.latency;
|
||||
|
||||
if(calculate(ping) == -1){
|
||||
executer.sendMessage(ChatFormat.format("{b1}Your ping is {b2}INVALID{b1}." ), Util.NIL_UUID);
|
||||
} else {
|
||||
executer.sendMessage(ChatFormat.format("{b1}Your ping is {b2}{}ms{b1}.", ping), Util.NIL_UUID);
|
||||
}
|
||||
|
||||
return ping;
|
||||
}
|
||||
|
||||
public static int ping(CommandContext<CommandSourceStack> context, ServerPlayer player) {
|
||||
CommandSourceStack executer = context.getSource();
|
||||
int ping = player.latency;
|
||||
|
||||
if(calculate(ping) == -1){
|
||||
executer.sendSuccess(ChatFormat.format("{b1}The ping of {} is {b2}INVALID{b1}.", player.getScoreboardName()), false);
|
||||
} else {
|
||||
executer.sendSuccess(ChatFormat.format("{b1}The ping of {} is {b2}{}ms{b1}.", player.getScoreboardName(), ping), false);
|
||||
}
|
||||
|
||||
return ping;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
package com.nexia.core.commands.player;
|
||||
|
||||
import com.mojang.brigadier.CommandDispatcher;
|
||||
import com.mojang.brigadier.context.CommandContext;
|
||||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||
import com.nexia.core.games.util.LobbyUtil;
|
||||
import com.nexia.core.gui.PlayGUI;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
import net.minecraft.commands.Commands;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
|
||||
public class PlayCommand {
|
||||
|
||||
public static void register(CommandDispatcher<CommandSourceStack> dispatcher, boolean bl) {
|
||||
dispatcher.register(Commands.literal("play").executes(PlayCommand::openGUI)
|
||||
.then(Commands.literal("ffa").executes(PlayCommand::openGUI)
|
||||
.then(Commands.literal("classic").executes(PlayCommand::playNormalFFA)))
|
||||
.then(Commands.literal("bedwars").executes(PlayCommand::playBedWars))
|
||||
.then(Commands.literal("duels").executes(PlayCommand::playDuels))
|
||||
.then(Commands.literal("oitc").executes(PlayCommand::playOITC))
|
||||
.then(Commands.literal("bw").executes(PlayCommand::playBedWars)));
|
||||
dispatcher.register(Commands.literal("join").executes(PlayCommand::openGUI)
|
||||
.then(Commands.literal("ffa").executes(PlayCommand::openGUI)
|
||||
.then(Commands.literal("classic")).executes(PlayCommand::playNormalFFA))
|
||||
.then(Commands.literal("bedwars").executes(PlayCommand::playBedWars))
|
||||
.then(Commands.literal("duels").executes(PlayCommand::playDuels))
|
||||
.then(Commands.literal("bw").executes(PlayCommand::playBedWars))
|
||||
.then(Commands.literal("oitc").executes(PlayCommand::playOITC))
|
||||
);
|
||||
dispatcher.register(Commands.literal("ffa").executes(PlayCommand::playNormalFFA));
|
||||
}
|
||||
|
||||
private static int openGUI(CommandContext<CommandSourceStack> context) throws CommandSyntaxException{
|
||||
PlayGUI.openMainGUI(context.getSource().getPlayerOrException());
|
||||
return 1;
|
||||
}
|
||||
|
||||
private static int playNormalFFA(CommandContext<CommandSourceStack> context) throws CommandSyntaxException {
|
||||
ServerPlayer player = context.getSource().getPlayerOrException();
|
||||
LobbyUtil.sendGame(player, "normal ffa", true);
|
||||
return 1;
|
||||
}
|
||||
|
||||
private static int playBedWars(CommandContext<CommandSourceStack> context) throws CommandSyntaxException {
|
||||
ServerPlayer player = context.getSource().getPlayerOrException();
|
||||
LobbyUtil.sendGame(player, "bedwars", true);
|
||||
return 1;
|
||||
}
|
||||
|
||||
private static int playDuels(CommandContext<CommandSourceStack> context) throws CommandSyntaxException {
|
||||
ServerPlayer player = context.getSource().getPlayerOrException();
|
||||
LobbyUtil.sendGame(player, "duels", true);
|
||||
return 1;
|
||||
}
|
||||
|
||||
private static int playOITC(CommandContext<CommandSourceStack> context) throws CommandSyntaxException {
|
||||
ServerPlayer player = context.getSource().getPlayerOrException();
|
||||
LobbyUtil.sendGame(player, "oitc", true);
|
||||
return 1;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package com.nexia.core.commands.player;
|
||||
|
||||
import com.mojang.brigadier.CommandDispatcher;
|
||||
import com.mojang.brigadier.context.CommandContext;
|
||||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||
import com.nexia.core.gui.RankGUI;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
import net.minecraft.commands.Commands;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
|
||||
public class PrefixCommand {
|
||||
public static void register(CommandDispatcher<CommandSourceStack> dispatcher, boolean bl) {
|
||||
dispatcher.register(Commands.literal("prefix").executes(PrefixCommand::run));
|
||||
}
|
||||
|
||||
public static int run(CommandContext<CommandSourceStack> context) throws CommandSyntaxException {
|
||||
ServerPlayer executer = context.getSource().getPlayerOrException();
|
||||
RankGUI.openRankGUI(executer);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
package com.nexia.core.commands.player;
|
||||
|
||||
import com.mojang.brigadier.CommandDispatcher;
|
||||
import com.mojang.brigadier.arguments.StringArgumentType;
|
||||
import com.mojang.brigadier.context.CommandContext;
|
||||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||
import com.nexia.core.Main;
|
||||
import com.nexia.core.utilities.chat.ChatFormat;
|
||||
import com.nexia.core.utilities.http.DiscordWebhook;
|
||||
import com.nexia.core.utilities.player.PlayerUtil;
|
||||
import net.minecraft.Util;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
import net.minecraft.commands.Commands;
|
||||
import net.minecraft.commands.arguments.EntityArgument;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
|
||||
import java.awt.*;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
|
||||
public class ReportCommand {
|
||||
|
||||
private static void sendWebhook(String reporter, String victim, String reason){
|
||||
DiscordWebhook webhook = new DiscordWebhook("https://discord.com/api/webhooks/1076143579585593404/WAvzxt2x1hPOX2UHrklkiCumwVU7xBvUjZ91InBnHKCuuL0nnKPERaEiQxQvgkUxHnZ0");
|
||||
webhook.addEmbed(new DiscordWebhook.EmbedObject()
|
||||
.setAuthor((reporter + " reported " + victim), null, null)
|
||||
.setColor(Color.RED)
|
||||
.addField("Reporter:", reporter, true)
|
||||
.addField("Reported Player:", victim, true)
|
||||
.setThumbnail("https://mc-heads.net/avatar/" + victim + "/64")
|
||||
.addField("Reason:", reason, false)
|
||||
.setFooter("Nexia • " + DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm:ss").format(LocalDateTime.now()), "https://notcoded.needs.rest/r/nexia.png"));
|
||||
try {
|
||||
webhook.execute();
|
||||
} catch (Exception ignored) { }
|
||||
}
|
||||
public static void register(CommandDispatcher<CommandSourceStack> dispatcher, boolean bl) {
|
||||
dispatcher.register(Commands.literal("report")
|
||||
.then(Commands.argument("player", EntityArgument.player())
|
||||
.then(Commands.argument("reason", StringArgumentType.greedyString())
|
||||
.executes(context -> ReportCommand.report(context, EntityArgument.getPlayer(context, "player"), StringArgumentType.getString(context, "reason")))
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
public static int report(CommandContext<CommandSourceStack> context, ServerPlayer player, String reason) throws CommandSyntaxException {
|
||||
ServerPlayer executor = context.getSource().getPlayerOrException();
|
||||
if(executor == player){
|
||||
player.sendMessage(ChatFormat.formatFail("You cannot report yourself!"), Util.NIL_UUID);
|
||||
return 1;
|
||||
}
|
||||
|
||||
executor.sendMessage(ChatFormat.format("{b1}You have reported {b2}{} {b1}for {b2}{}.", player.getScoreboardName(), reason), Util.NIL_UUID);
|
||||
ServerPlayer staffPlayer;
|
||||
sendWebhook(executor.getScoreboardName(), player.getScoreboardName(), reason);
|
||||
for (int i = 0; i != Main.server.getPlayerCount(); i++){
|
||||
staffPlayer = PlayerUtil.getPlayerFromName(Main.server.getPlayerNames()[i]);
|
||||
CommandSourceStack staffStack = staffPlayer.createCommandSourceStack();
|
||||
if(PlayerUtil.hasPermission(staffStack, "nexia.staff.report", 1)) {
|
||||
staffStack.sendSuccess(ChatFormat.format("{b2}{} {b1}has reported {b2}{} {b1}for {b2}{}.", executor.getScoreboardName(), player.getScoreboardName(), reason), false);
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package com.nexia.core.commands.player;
|
||||
|
||||
import com.mojang.brigadier.CommandDispatcher;
|
||||
import com.mojang.brigadier.context.CommandContext;
|
||||
import com.nexia.core.utilities.chat.ChatFormat;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
import net.minecraft.commands.Commands;
|
||||
import net.minecraft.network.chat.TextComponent;
|
||||
|
||||
public class RulesCommand {
|
||||
|
||||
public static void register(CommandDispatcher<CommandSourceStack> dispatcher, boolean bl) {
|
||||
dispatcher.register(Commands.literal("rules").executes(RulesCommand::run));
|
||||
}
|
||||
|
||||
private static final String[] rules = {
|
||||
"No cheats or other unfair advantages",
|
||||
"No racism, excessive spamming or hate speech",
|
||||
"Don't abuse any bugs and glitches",
|
||||
"Keep it G, PG and PG-13",
|
||||
"No interrupting",
|
||||
};
|
||||
|
||||
public static int run(CommandContext<CommandSourceStack> context) {
|
||||
|
||||
String message = ChatFormat.separatorLine("Rules");
|
||||
for (int i = 0; i < rules.length; i++) {
|
||||
message += "\n" + "\247d" + ChatFormat.bold + (i+1) + ". §8» " + ChatFormat.normalColor + rules[i];
|
||||
}
|
||||
message += "\n" + ChatFormat.separatorLine(null);
|
||||
|
||||
context.getSource().sendSuccess(new TextComponent(message), false);
|
||||
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,132 @@
|
||||
package com.nexia.core.commands.player;
|
||||
|
||||
import com.mojang.brigadier.CommandDispatcher;
|
||||
import com.mojang.brigadier.arguments.StringArgumentType;
|
||||
import com.mojang.brigadier.context.CommandContext;
|
||||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||
import com.nexia.core.Main;
|
||||
import com.nexia.core.games.util.LobbyUtil;
|
||||
import com.nexia.core.games.util.PlayerGameMode;
|
||||
import com.nexia.core.utilities.chat.ChatFormat;
|
||||
import com.nexia.core.utilities.player.PlayerData;
|
||||
import com.nexia.ffa.utilities.player.PlayerDataManager;
|
||||
import com.nexia.ffa.utilities.player.SavedPlayerData;
|
||||
import net.minecraft.Util;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
import net.minecraft.commands.Commands;
|
||||
import net.minecraft.commands.SharedSuggestionProvider;
|
||||
import net.minecraft.commands.arguments.EntityArgument;
|
||||
import net.minecraft.network.chat.TextComponent;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
|
||||
import java.text.DecimalFormat;
|
||||
|
||||
public class StatsCommand {
|
||||
public static void register(CommandDispatcher<CommandSourceStack> dispatcher, boolean bl) {
|
||||
dispatcher.register(Commands.literal("stats").executes(StatsCommand::run)
|
||||
.then(Commands.argument("player", EntityArgument.player())
|
||||
.then(Commands.argument("gamemode", StringArgumentType.greedyString())
|
||||
.suggests(((context, builder) -> SharedSuggestionProvider.suggest((LobbyUtil.statsGameModes), builder)))
|
||||
.executes(context -> StatsCommand.other(context, EntityArgument.getPlayer(context, "player"), StringArgumentType.getString(context, "gamemode")))))
|
||||
);
|
||||
}
|
||||
|
||||
public static int run(CommandContext<CommandSourceStack> context) throws CommandSyntaxException {
|
||||
|
||||
ServerPlayer player = context.getSource().getPlayerOrException();
|
||||
PlayerData executerData = com.nexia.core.utilities.player.PlayerDataManager.get(player);
|
||||
if(executerData.gameMode == PlayerGameMode.FFA){
|
||||
String message = ChatFormat.separatorLine("FFA Stats");
|
||||
SavedPlayerData data = PlayerDataManager.get(player).savedData;
|
||||
player.sendMessage(new TextComponent(message), Util.NIL_UUID);
|
||||
player.sendMessage(ChatFormat.format(" §8» {b1}User: {n}{}", player.getScoreboardName()), Util.NIL_UUID);
|
||||
player.sendMessage(ChatFormat.format(" §8» {b1}Kills: §a{}", data.kills), Util.NIL_UUID);
|
||||
player.sendMessage(ChatFormat.format(" §8» {b1}Deaths: §c{}", data.deaths), Util.NIL_UUID);
|
||||
player.sendMessage(ChatFormat.format(" §8» {b1}KDR: §a{}", Float.parseFloat(new DecimalFormat("#.##").format(data.kills / data.deaths))), Util.NIL_UUID);
|
||||
player.sendMessage(ChatFormat.format(" §8» {b1}Killstreak: §6{}§8/§6{}", data.killstreak, data.bestKillstreak), Util.NIL_UUID);
|
||||
player.sendMessage(new TextComponent(ChatFormat.separatorLine(null)), Util.NIL_UUID);
|
||||
}
|
||||
|
||||
if(executerData.gameMode == PlayerGameMode.DUELS){
|
||||
String message = ChatFormat.separatorLine("Duels Stats");
|
||||
com.nexia.minigames.games.duels.util.player.SavedPlayerData data = com.nexia.minigames.games.duels.util.player.PlayerDataManager.get(player).savedData;
|
||||
player.sendMessage(new TextComponent(message), Util.NIL_UUID);
|
||||
player.sendMessage(ChatFormat.format(" §8» {b1}User: {n}{}", player.getScoreboardName()), Util.NIL_UUID);
|
||||
player.sendMessage(ChatFormat.format(" §8» {b1}Wins: §a{}", data.wins), Util.NIL_UUID);
|
||||
player.sendMessage(ChatFormat.format(" §8» {b1}Losses: §c{}", data.loss), Util.NIL_UUID);
|
||||
player.sendMessage(new TextComponent(ChatFormat.separatorLine(null)), Util.NIL_UUID);
|
||||
}
|
||||
|
||||
|
||||
if(executerData.gameMode == PlayerGameMode.BEDWARS){
|
||||
String message = ChatFormat.separatorLine("Bedwars Stats");
|
||||
com.nexia.minigames.games.duels.util.player.SavedPlayerData data = com.nexia.minigames.games.duels.util.player.PlayerDataManager.get(player).savedData;
|
||||
player.sendMessage(new TextComponent(message), Util.NIL_UUID);
|
||||
player.sendMessage(ChatFormat.format(" §8» {b1}User: {n}{}", player.getScoreboardName()), Util.NIL_UUID);
|
||||
player.sendMessage(ChatFormat.format(" §8» {b1}Wins: §a{}", data.wins), Util.NIL_UUID);
|
||||
player.sendMessage(ChatFormat.format(" §8» {b1}Losses: §c{}", data.loss), Util.NIL_UUID);
|
||||
player.sendMessage(new TextComponent(ChatFormat.separatorLine(null)), Util.NIL_UUID);
|
||||
}
|
||||
|
||||
if(executerData.gameMode == PlayerGameMode.OITC){
|
||||
String message = ChatFormat.separatorLine("OITC Stats");
|
||||
com.nexia.minigames.games.oitc.util.player.SavedPlayerData data = com.nexia.minigames.games.oitc.util.player.PlayerDataManager.get(player).savedData;
|
||||
player.sendMessage(new TextComponent(message), Util.NIL_UUID);
|
||||
player.sendMessage(ChatFormat.format(" §8» {b1}User: {n}{}", player.getScoreboardName()), Util.NIL_UUID);
|
||||
player.sendMessage(ChatFormat.format(" §8» {b1}Wins: §a{}", data.wins), Util.NIL_UUID);
|
||||
player.sendMessage(ChatFormat.format(" §8» {b1}Losses: §c{}", data.loss), Util.NIL_UUID);
|
||||
player.sendMessage(ChatFormat.format(" §8» {b1}Kills: §c{}", data.kills), Util.NIL_UUID);
|
||||
player.sendMessage(new TextComponent(ChatFormat.separatorLine(null)), Util.NIL_UUID);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
public static int other(CommandContext<CommandSourceStack> context, ServerPlayer player, String gamemode) {
|
||||
CommandSourceStack executor = context.getSource();
|
||||
if(gamemode.equalsIgnoreCase("ffa")){
|
||||
String message = ChatFormat.separatorLine("FFA Stats");
|
||||
SavedPlayerData data = PlayerDataManager.get(player).savedData;
|
||||
executor.sendSuccess(new TextComponent(message), false);
|
||||
executor.sendSuccess(ChatFormat.format(" §8» {b1}User: {n}{}", player.getScoreboardName()), false);
|
||||
executor.sendSuccess(ChatFormat.format(" §8» {b1}Kills: §a{}", data.kills), false);
|
||||
executor.sendSuccess(ChatFormat.format(" §8» {b1}Deaths: §c{}", data.deaths), false);
|
||||
executor.sendSuccess(ChatFormat.format(" §8» {b1}KDR: §a{}", Float.parseFloat(new DecimalFormat("#.##").format(data.kills / data.deaths))), false);
|
||||
executor.sendSuccess(ChatFormat.format(" §8» {b1}Killstreak: §6{}§8/§6{}", data.killstreak, data.bestKillstreak), false);
|
||||
executor.sendSuccess(new TextComponent(ChatFormat.separatorLine(null)), false);
|
||||
}
|
||||
|
||||
if(gamemode.equalsIgnoreCase("duels")){
|
||||
String message = ChatFormat.separatorLine("Duels Stats");
|
||||
com.nexia.minigames.games.duels.util.player.SavedPlayerData data = com.nexia.minigames.games.duels.util.player.PlayerDataManager.get(player).savedData;
|
||||
executor.sendSuccess(new TextComponent(message), false);
|
||||
executor.sendSuccess(ChatFormat.format(" §8» {b1}User: {n}{}", player.getScoreboardName()), false);
|
||||
executor.sendSuccess(ChatFormat.format(" §8» {b1}Wins: §a{}", data.wins), false);
|
||||
executor.sendSuccess(ChatFormat.format(" §8» {b1}Losses: §c{}", data.loss), false);
|
||||
executor.sendSuccess(new TextComponent(ChatFormat.separatorLine(null)), false);
|
||||
}
|
||||
|
||||
|
||||
if(gamemode.equalsIgnoreCase("bedwars")){
|
||||
String message = ChatFormat.separatorLine("Bedwars Stats");
|
||||
com.nexia.minigames.games.duels.util.player.SavedPlayerData data = com.nexia.minigames.games.duels.util.player.PlayerDataManager.get(player).savedData;
|
||||
executor.sendSuccess(new TextComponent(message), false);
|
||||
executor.sendSuccess(ChatFormat.format(" §8» {b1}User: {n}{}", player.getScoreboardName()), false);
|
||||
executor.sendSuccess(ChatFormat.format(" §8» {b1}Wins: §a{}", data.wins), false);
|
||||
executor.sendSuccess(ChatFormat.format(" §8» {b1}Losses: §c{}", data.loss), false);
|
||||
executor.sendSuccess(new TextComponent(ChatFormat.separatorLine(null)), false);
|
||||
}
|
||||
|
||||
if(gamemode.equalsIgnoreCase("oitc")){
|
||||
String message = ChatFormat.separatorLine("OITC Stats");
|
||||
com.nexia.minigames.games.oitc.util.player.SavedPlayerData data = com.nexia.minigames.games.oitc.util.player.PlayerDataManager.get(player).savedData;
|
||||
executor.sendSuccess(new TextComponent(message), false);
|
||||
executor.sendSuccess(ChatFormat.format(" §8» {b1}User: {n}{}", player.getScoreboardName()), false);
|
||||
executor.sendSuccess(ChatFormat.format(" §8» {b1}Wins: §a{}", data.wins), false);
|
||||
executor.sendSuccess(ChatFormat.format(" §8» {b1}Losses: §c{}", data.loss), false);
|
||||
executor.sendSuccess(ChatFormat.format(" §8» {b1}Kills: §c{}", data.kills), false);
|
||||
executor.sendSuccess(new TextComponent(ChatFormat.separatorLine(null)), false);
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
package com.nexia.core.commands.player.duels;
|
||||
|
||||
import com.mojang.brigadier.CommandDispatcher;
|
||||
import com.mojang.brigadier.arguments.StringArgumentType;
|
||||
import com.mojang.brigadier.context.CommandContext;
|
||||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||
import com.nexia.core.games.util.PlayerGameMode;
|
||||
import com.nexia.core.utilities.chat.ChatFormat;
|
||||
import com.nexia.core.utilities.player.PlayerData;
|
||||
import com.nexia.core.utilities.player.PlayerDataManager;
|
||||
import com.nexia.minigames.Main;
|
||||
import com.nexia.minigames.games.duels.DuelGameMode;
|
||||
import com.nexia.minigames.games.duels.gamemodes.GamemodeHandler;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
import net.minecraft.commands.Commands;
|
||||
import net.minecraft.commands.SharedSuggestionProvider;
|
||||
import net.minecraft.commands.arguments.EntityArgument;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class DuelCommand {
|
||||
public static void register(CommandDispatcher<CommandSourceStack> dispatcher, boolean bl) {
|
||||
dispatcher.register(Commands.literal("duel")
|
||||
.requires(commandSourceStack -> {
|
||||
try {
|
||||
com.nexia.minigames.games.duels.util.player.PlayerData playerData = com.nexia.minigames.games.duels.util.player.PlayerDataManager.get(commandSourceStack.getPlayerOrException());
|
||||
PlayerData playerData1 = PlayerDataManager.get(commandSourceStack.getPlayerOrException());
|
||||
return playerData.gameMode == DuelGameMode.LOBBY && playerData1.gameMode == PlayerGameMode.DUELS;
|
||||
} catch (Exception ignored) {}
|
||||
return false;
|
||||
})
|
||||
.then(Commands.argument("player", EntityArgument.player())
|
||||
.then(Commands.argument("gamemode", StringArgumentType.string())
|
||||
.suggests(((context, builder) -> SharedSuggestionProvider.suggest((DuelGameMode.duels), builder)))
|
||||
.executes(context -> DuelCommand.challenge(context, EntityArgument.getPlayer(context, "player"), StringArgumentType.getString(context, "gamemode"), null))
|
||||
.then(Commands.argument("map", StringArgumentType.string())
|
||||
.suggests(((context, builder) -> SharedSuggestionProvider.suggest((Main.config.duelsMaps), builder)))
|
||||
.executes(context -> DuelCommand.challenge(context, EntityArgument.getPlayer(context, "player"), StringArgumentType.getString(context, "gamemode"), StringArgumentType.getString(context, "map")))
|
||||
))));
|
||||
dispatcher.register(Commands.literal("challenge")
|
||||
.requires(commandSourceStack -> {
|
||||
try {
|
||||
com.nexia.minigames.games.duels.util.player.PlayerData playerData = com.nexia.minigames.games.duels.util.player.PlayerDataManager.get(commandSourceStack.getPlayerOrException());
|
||||
PlayerData playerData1 = PlayerDataManager.get(commandSourceStack.getPlayerOrException());
|
||||
return playerData.gameMode == DuelGameMode.LOBBY && playerData1.gameMode == PlayerGameMode.DUELS;
|
||||
} catch (Exception ignored) {}
|
||||
return false;
|
||||
})
|
||||
.then(Commands.argument("player", EntityArgument.player())
|
||||
.then(Commands.argument("gamemode", StringArgumentType.string())
|
||||
.suggests(((context, builder) -> SharedSuggestionProvider.suggest((DuelGameMode.duels), builder)))
|
||||
.executes(context -> DuelCommand.challenge(context, EntityArgument.getPlayer(context, "player"), StringArgumentType.getString(context, "gamemode"), null))
|
||||
.then(Commands.argument("map", StringArgumentType.string())
|
||||
.suggests(((context, builder) -> SharedSuggestionProvider.suggest((Main.config.duelsMaps), builder)))
|
||||
.executes(context -> DuelCommand.challenge(context, EntityArgument.getPlayer(context, "player"), StringArgumentType.getString(context, "gamemode"), StringArgumentType.getString(context, "map")))
|
||||
))));
|
||||
}
|
||||
|
||||
public static int challenge(CommandContext<CommandSourceStack> context, ServerPlayer player, String gameMode, @Nullable String map) throws CommandSyntaxException {
|
||||
ServerPlayer executer = context.getSource().getPlayerOrException();
|
||||
GamemodeHandler.challengePlayer(executer, player, gameMode, map);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package com.nexia.core.commands.player.duels;
|
||||
|
||||
import com.mojang.brigadier.CommandDispatcher;
|
||||
import com.mojang.brigadier.arguments.StringArgumentType;
|
||||
import com.mojang.brigadier.context.CommandContext;
|
||||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||
import com.nexia.core.games.util.PlayerGameMode;
|
||||
import com.nexia.core.utilities.player.PlayerData;
|
||||
import com.nexia.core.utilities.player.PlayerDataManager;
|
||||
import com.nexia.minigames.games.duels.DuelGameMode;
|
||||
import com.nexia.minigames.games.duels.gamemodes.GamemodeHandler;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
import net.minecraft.commands.Commands;
|
||||
import net.minecraft.commands.SharedSuggestionProvider;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
|
||||
public class QueueCommand {
|
||||
public static void register(CommandDispatcher<CommandSourceStack> dispatcher, boolean bl) {
|
||||
dispatcher.register(Commands.literal("queue")
|
||||
.requires(commandSourceStack -> {
|
||||
try {
|
||||
com.nexia.minigames.games.duels.util.player.PlayerData playerData = com.nexia.minigames.games.duels.util.player.PlayerDataManager.get(commandSourceStack.getPlayerOrException());
|
||||
PlayerData playerData1 = PlayerDataManager.get(commandSourceStack.getPlayerOrException());
|
||||
return playerData.gameMode == DuelGameMode.LOBBY && playerData1.gameMode == PlayerGameMode.DUELS;
|
||||
} catch (Exception ignored) {}
|
||||
return false;
|
||||
})
|
||||
.then(Commands.argument("gamemode", StringArgumentType.string())
|
||||
.suggests(((context, builder) -> SharedSuggestionProvider.suggest((DuelGameMode.duels), builder)))
|
||||
.executes(context -> QueueCommand.queue(context, StringArgumentType.getString(context, "gamemode"))))
|
||||
);
|
||||
}
|
||||
|
||||
public static int queue(CommandContext<CommandSourceStack> context, String gameMode) throws CommandSyntaxException {
|
||||
ServerPlayer executer = context.getSource().getPlayerOrException();
|
||||
GamemodeHandler.joinQueue(executer, gameMode, false);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package com.nexia.core.commands.player.oitc;
|
||||
|
||||
import com.mojang.brigadier.CommandDispatcher;
|
||||
import com.nexia.core.games.util.LobbyUtil;
|
||||
import com.nexia.core.games.util.PlayerGameMode;
|
||||
import com.nexia.core.utilities.player.PlayerDataManager;
|
||||
import com.nexia.minigames.games.oitc.OitcGame;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
import net.minecraft.commands.Commands;
|
||||
|
||||
public class OitcCommand {
|
||||
public static void register(CommandDispatcher<CommandSourceStack> dispatcher, boolean bl) {
|
||||
dispatcher.register(Commands.literal("oitc")
|
||||
.requires(commandSourceStack -> {
|
||||
try {
|
||||
return PlayerDataManager.get(commandSourceStack.getPlayerOrException()).gameMode == PlayerGameMode.OITC;
|
||||
} catch (Exception ignored) {}
|
||||
return false;
|
||||
})
|
||||
.then(Commands.literal("join").executes(context -> {
|
||||
OitcGame.joinQueue(context.getSource().getPlayerOrException());
|
||||
return 1;
|
||||
}))
|
||||
.then(Commands.literal("leave").executes(context -> {
|
||||
LobbyUtil.sendGame(context.getSource().getPlayerOrException(), "oitc", false);
|
||||
return 1;
|
||||
}))
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
package com.nexia.core.commands.staff;
|
||||
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import com.mojang.brigadier.CommandDispatcher;
|
||||
import com.mojang.brigadier.arguments.StringArgumentType;
|
||||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||
import com.nexia.core.Main;
|
||||
import com.nexia.core.utilities.chat.ChatFormat;
|
||||
import com.nexia.core.utilities.player.PlayerUtil;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
import net.minecraft.commands.Commands;
|
||||
import net.minecraft.commands.arguments.GameProfileArgument;
|
||||
import net.minecraft.network.chat.ComponentUtils;
|
||||
import net.minecraft.network.chat.TextComponent;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.server.players.UserBanList;
|
||||
import net.minecraft.server.players.UserBanListEntry;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Date;
|
||||
|
||||
public class BanCommand {
|
||||
public static void register(CommandDispatcher<CommandSourceStack> dispatcher, boolean bl) {
|
||||
dispatcher.register(Commands.literal("ban")
|
||||
.requires(commandSourceStack -> PlayerUtil.hasPermission(commandSourceStack, "nexia.staff.ban", 3))
|
||||
.then(Commands.argument("player", GameProfileArgument.gameProfile())
|
||||
.executes(context -> BanCommand.ban(context.getSource(), GameProfileArgument.getGameProfiles(context, "player"), "No reason specified."))
|
||||
.then(Commands.argument("reason", StringArgumentType.greedyString())
|
||||
.executes(context -> BanCommand.ban(context.getSource(), GameProfileArgument.getGameProfiles(context, "player"), StringArgumentType.getString(context, "reason"))))
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public static int ban(CommandSourceStack context, Collection<GameProfile> collection, String reason) throws CommandSyntaxException {
|
||||
UserBanList userBanList = Main.server.getPlayerList().getBans();
|
||||
int i = 0;
|
||||
|
||||
for (GameProfile gameProfile : collection) {
|
||||
if (!userBanList.isBanned(gameProfile)) {
|
||||
ServerPlayer serverPlayer = Main.server.getPlayerList().getPlayer(gameProfile.getId());
|
||||
|
||||
UserBanListEntry userBanListEntry = new UserBanListEntry(gameProfile, (Date) null, context.getTextName(), (Date) null, reason);
|
||||
userBanList.add(userBanListEntry);
|
||||
++i;
|
||||
context.sendSuccess(ChatFormat.format("{b1}You have banned {b2}{} {b1}for {b2}{}{b1}.", ComponentUtils.getDisplayName(gameProfile).getString(), reason), true);
|
||||
if (serverPlayer != null) {
|
||||
serverPlayer.connection.disconnect(new TextComponent("§c§lYou have been banned.\n§7Reason: §d" + reason + "\n§7You can appeal your ban at §d" + Main.config.discordLink));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (i == 0) {
|
||||
context.sendFailure(ChatFormat.formatFail("That player is already banned."));
|
||||
} else {
|
||||
return i;
|
||||
}
|
||||
|
||||
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package com.nexia.core.commands.staff;
|
||||
|
||||
import com.mojang.brigadier.CommandDispatcher;
|
||||
import com.mojang.brigadier.context.CommandContext;
|
||||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||
import com.nexia.core.utilities.chat.ChatFormat;
|
||||
import com.nexia.core.utilities.player.PlayerUtil;
|
||||
import com.nexia.minigames.games.bedwars.shop.BwLoadShop;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
import net.minecraft.commands.Commands;
|
||||
import net.minecraft.network.chat.TextComponent;
|
||||
|
||||
public class BwReloadShopCommand {
|
||||
|
||||
public static void register(CommandDispatcher<CommandSourceStack> dispatcher, boolean bl) {
|
||||
dispatcher.register(Commands.literal("bwreloadshop").executes(BwReloadShopCommand::run)
|
||||
.requires(commandSourceStack -> PlayerUtil.hasPermission(commandSourceStack, "nexia.dev.bwreloadshop", 3)));
|
||||
}
|
||||
|
||||
public static int run(CommandContext<CommandSourceStack> context) throws CommandSyntaxException {
|
||||
|
||||
boolean success = BwLoadShop.loadBedWarsShop(false) &&
|
||||
BwLoadShop.loadBedWarsShop(false);
|
||||
|
||||
if (success) {
|
||||
String message = ChatFormat.brandColor1 + "Reloaded Bedwars shop successfully!";
|
||||
context.getSource().sendSuccess(new TextComponent(message), false);
|
||||
|
||||
} else {
|
||||
String message = ChatFormat.brandColor2 + "Failed to reload Bedwars shop.";
|
||||
context.getSource().sendFailure(new TextComponent(message));
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package com.nexia.core.commands.staff;
|
||||
|
||||
import com.mojang.brigadier.CommandDispatcher;
|
||||
import com.mojang.brigadier.context.CommandContext;
|
||||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||
import com.nexia.core.utilities.player.PlayerUtil;
|
||||
import com.nexia.minigames.games.bedwars.players.BwTeam;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
import net.minecraft.commands.Commands;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
|
||||
public class BwReloadTeamColorsCommand {
|
||||
|
||||
public static void register(CommandDispatcher<CommandSourceStack> dispatcher, boolean bl) {
|
||||
dispatcher.register(Commands.literal("bwreloadteamcolors").executes(BwReloadTeamColorsCommand::run)
|
||||
.requires(commandSourceStack -> PlayerUtil.hasPermission(commandSourceStack, "nexia.dev.bwreloadteamcolors", 3)));
|
||||
}
|
||||
|
||||
public static int run(CommandContext<CommandSourceStack> context) throws CommandSyntaxException {
|
||||
ServerPlayer player = context.getSource().getPlayerOrException();
|
||||
|
||||
BwTeam.reloadPlayerTeamColors(player);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package com.nexia.core.commands.staff;
|
||||
|
||||
import com.mojang.brigadier.CommandDispatcher;
|
||||
import com.mojang.brigadier.context.CommandContext;
|
||||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||
import com.nexia.core.utilities.player.PlayerUtil;
|
||||
import com.nexia.minigames.games.bedwars.util.BwUtil;
|
||||
import net.minecraft.Util;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
import net.minecraft.commands.Commands;
|
||||
import net.minecraft.network.chat.TextComponent;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
|
||||
public class BwSkipQueueCommand {
|
||||
|
||||
public static void register(CommandDispatcher<CommandSourceStack> dispatcher, boolean bl) {
|
||||
dispatcher.register((Commands.literal("bwskipqueue")
|
||||
.requires(commandSourceStack -> PlayerUtil.hasPermission(commandSourceStack, "nexia.staff.bwskipqueue", 1)))
|
||||
.executes(BwSkipQueueCommand::run)
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
private static int run(CommandContext<CommandSourceStack> context) throws CommandSyntaxException {
|
||||
ServerPlayer player = context.getSource().getPlayerOrException();
|
||||
|
||||
if (BwUtil.skipQueue()) {
|
||||
player.sendMessage(new TextComponent("Skipped queue"), Util.NIL_UUID);
|
||||
} else {
|
||||
player.sendMessage(new TextComponent("Epic queue skip failure"), Util.NIL_UUID);
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
package com.nexia.core.commands.staff;
|
||||
|
||||
import com.mojang.brigadier.CommandDispatcher;
|
||||
import com.mojang.brigadier.context.CommandContext;
|
||||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||
import com.nexia.core.Main;
|
||||
import com.nexia.core.utilities.player.PlayerUtil;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
import net.minecraft.commands.Commands;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
public class DefaultGameRulesCommand {
|
||||
|
||||
public static void register(CommandDispatcher<CommandSourceStack> dispatcher, boolean bl) {
|
||||
dispatcher.register(Commands.literal("defaultgamerules").executes(DefaultGameRulesCommand::run)
|
||||
.requires(commandSourceStack -> PlayerUtil.hasPermission(commandSourceStack, "nexia.dev.defaultgamerules", 3)));
|
||||
}
|
||||
|
||||
public static int run(CommandContext<CommandSourceStack> context) throws CommandSyntaxException {
|
||||
ServerPlayer player = context.getSource().getPlayerOrException();
|
||||
|
||||
for (String gamerule : gamerules.keySet()) {
|
||||
String value = gamerules.get(gamerule);
|
||||
Main.server.getCommands().performCommand(player.createCommandSourceStack(),
|
||||
"gamerule " + gamerule + " " + value);
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
private static final HashMap<String, String> gamerules = getGameRules();
|
||||
|
||||
private static HashMap<String, String> getGameRules() {
|
||||
HashMap<String, String> gamerules = new HashMap<>();
|
||||
gamerules.put("announceAdvancements", "false");
|
||||
gamerules.put("commandBlockOutput", "false");
|
||||
gamerules.put("doDaylightCycle", "false");
|
||||
gamerules.put("doFireTick", "false");
|
||||
gamerules.put("doImmediateRespawn", "true");
|
||||
gamerules.put("doMobSpawning", "false");
|
||||
gamerules.put("doPatrolSpawning", "false");
|
||||
gamerules.put("doTraderSpawning", "false");
|
||||
gamerules.put("doWeatherCycle", "false");
|
||||
gamerules.put("keepInventory", "true");
|
||||
gamerules.put("mobGriefing", "false");
|
||||
gamerules.put("randomTickSpeed", "0");
|
||||
gamerules.put("showDeathMessages", "false");
|
||||
return gamerules;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package com.nexia.core.commands.staff;
|
||||
|
||||
import com.mojang.brigadier.CommandDispatcher;
|
||||
import com.mojang.brigadier.context.CommandContext;
|
||||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||
import com.nexia.core.utilities.chat.ChatFormat;
|
||||
import com.nexia.core.utilities.player.PlayerUtil;
|
||||
import net.minecraft.Util;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
import net.minecraft.commands.Commands;
|
||||
import net.minecraft.commands.arguments.EntityArgument;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
|
||||
public class HealCommand {
|
||||
public static void register(CommandDispatcher<CommandSourceStack> dispatcher, boolean bl) {
|
||||
dispatcher.register(Commands.literal("heal").executes(HealCommand::run)
|
||||
.requires(commandSourceStack -> PlayerUtil.hasPermission(commandSourceStack, "nexia.staff.heal", 1))
|
||||
.then(Commands.argument("player", EntityArgument.player())
|
||||
.executes(context -> HealCommand.heal(context, EntityArgument.getPlayer(context, "player")))
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public static int run(CommandContext<CommandSourceStack> context) throws CommandSyntaxException {
|
||||
ServerPlayer executer = context.getSource().getPlayerOrException();
|
||||
executer.heal(executer.getMaxHealth());
|
||||
|
||||
executer.sendMessage(ChatFormat.format("{b1}You have been healed."), Util.NIL_UUID);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
public static int heal(CommandContext<CommandSourceStack> context, ServerPlayer player) throws CommandSyntaxException {
|
||||
CommandSourceStack executer = context.getSource();
|
||||
player.heal(player.getMaxHealth());
|
||||
|
||||
executer.sendSuccess(ChatFormat.format("{b1}You have healed {b2}{}{b1}.", player.getScoreboardName()), false);
|
||||
player.sendMessage(ChatFormat.format("{b1}You have been healed."), Util.NIL_UUID);
|
||||
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
package com.nexia.core.commands.staff;
|
||||
|
||||
import com.mojang.brigadier.CommandDispatcher;
|
||||
import com.mojang.brigadier.arguments.StringArgumentType;
|
||||
import com.mojang.brigadier.context.CommandContext;
|
||||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||
import com.nexia.core.games.util.LobbyUtil;
|
||||
import com.nexia.core.utilities.chat.ChatFormat;
|
||||
import com.nexia.core.utilities.player.PlayerUtil;
|
||||
import com.nexia.core.utilities.time.ServerTime;
|
||||
import com.nexia.minigames.games.duels.DuelsSpawn;
|
||||
import net.minecraft.Util;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
import net.minecraft.commands.Commands;
|
||||
import net.minecraft.commands.SharedSuggestionProvider;
|
||||
import net.minecraft.commands.arguments.EntityArgument;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.Difficulty;
|
||||
import net.minecraft.world.level.GameRules;
|
||||
import xyz.nucleoid.fantasy.RuntimeWorldConfig;
|
||||
|
||||
public class MapCommand {
|
||||
public static void register(CommandDispatcher<CommandSourceStack> dispatcher, boolean bl) {
|
||||
dispatcher.register((Commands.literal("map")
|
||||
.requires(commandSourceStack -> {
|
||||
try {
|
||||
return PlayerUtil.hasPermission(commandSourceStack, "nexia.staff.map", 2);
|
||||
} catch (Exception ignored) {
|
||||
return false;
|
||||
}
|
||||
})
|
||||
.then(Commands.argument("type", StringArgumentType.string())
|
||||
.suggests(((context, builder) -> SharedSuggestionProvider.suggest((new String[]{"delete", "create", "tp"}), builder)))
|
||||
.then(Commands.argument("map", StringArgumentType.greedyString())
|
||||
.executes(MapCommand::run)
|
||||
)
|
||||
)
|
||||
));
|
||||
}
|
||||
|
||||
private static int run(CommandContext<CommandSourceStack> context) throws CommandSyntaxException {
|
||||
ServerPlayer player = context.getSource().getPlayerOrException();
|
||||
|
||||
String type = StringArgumentType.getString(context, "type");
|
||||
String map = StringArgumentType.getString(context, "map");
|
||||
|
||||
if((ChatFormat.hasWhiteSpacesOrSpaces(null, map) || ChatFormat.hasWhiteSpacesOrSpaces(null, type)) || (type == null || map == null)) {
|
||||
player.sendMessage(ChatFormat.formatFail("Invalid name!"), Util.NIL_UUID);
|
||||
return 1;
|
||||
}
|
||||
|
||||
String[] mapname = map.split(":");
|
||||
|
||||
if(type.equalsIgnoreCase("create")){
|
||||
|
||||
ServerLevel level = ServerTime.fantasy.getOrOpenPersistentWorld(ResourceKey.create(Registry.DIMENSION_REGISTRY, new ResourceLocation(mapname[0], mapname[1])).location(), (
|
||||
new RuntimeWorldConfig()
|
||||
.setDimensionType(DuelsSpawn.duelWorld.dimensionType())
|
||||
.setGenerator(DuelsSpawn.duelWorld.getChunkSource().getGenerator())
|
||||
.setDifficulty(Difficulty.HARD)
|
||||
.setGameRule(GameRules.RULE_KEEPINVENTORY, false)
|
||||
.setGameRule(GameRules.RULE_MOBGRIEFING, false)
|
||||
.setGameRule(GameRules.RULE_WEATHER_CYCLE, false)
|
||||
.setGameRule(GameRules.RULE_DAYLIGHT, false)
|
||||
.setGameRule(GameRules.RULE_DO_IMMEDIATE_RESPAWN, false)
|
||||
.setGameRule(GameRules.RULE_DOMOBSPAWNING, false)
|
||||
.setGameRule(GameRules.RULE_SHOWDEATHMESSAGES, false)
|
||||
.setGameRule(GameRules.RULE_SPAWN_RADIUS, 0))).asWorld();
|
||||
|
||||
player.teleportTo(level, 0, 80, 0, 0, 0);
|
||||
|
||||
player.sendMessage(ChatFormat.format("{b1}Created map called: {b2}{}{b1}.", mapname[1]), Util.NIL_UUID);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (type.equalsIgnoreCase("delete")) {
|
||||
ServerTime.fantasy.getOrOpenPersistentWorld(ResourceKey.create(Registry.DIMENSION_REGISTRY, new ResourceLocation(mapname[0], mapname[1])).location(), null).delete();
|
||||
player.sendMessage(ChatFormat.format("{b1}Deleted map called: {b2}{}{b1}.", mapname[1]), Util.NIL_UUID);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if(type.equalsIgnoreCase("tp")) {
|
||||
ServerLevel level = ServerTime.fantasy.getOrOpenPersistentWorld(ResourceKey.create(Registry.DIMENSION_REGISTRY, new ResourceLocation(mapname[0], mapname[1])).location(), null).asWorld();
|
||||
player.teleportTo(level, 0, 80, 0, 0, 0);
|
||||
|
||||
player.sendMessage(ChatFormat.format("{b1}Teleported to map called: {b2}{}{b1}.", mapname[1]), Util.NIL_UUID);
|
||||
return 1;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
package com.nexia.core.commands.staff;
|
||||
|
||||
import com.mojang.brigadier.CommandDispatcher;
|
||||
import com.mojang.brigadier.StringReader;
|
||||
import com.mojang.brigadier.arguments.StringArgumentType;
|
||||
import com.mojang.brigadier.context.CommandContext;
|
||||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||
import com.nexia.core.utilities.chat.ChatFormat;
|
||||
import com.nexia.core.utilities.chat.PlayerMutes;
|
||||
import com.nexia.core.utilities.player.PlayerUtil;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
import net.minecraft.commands.Commands;
|
||||
import net.minecraft.commands.arguments.EntityArgument;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
public class MuteCommand {
|
||||
|
||||
public static void register(CommandDispatcher<CommandSourceStack> dispatcher, boolean bl) {
|
||||
dispatcher.register(Commands.literal("mute")
|
||||
.requires(commandSourceStack -> PlayerUtil.hasPermission(commandSourceStack, "nexia.staff.mute", 1))
|
||||
.then(Commands.argument("player", EntityArgument.player())
|
||||
.then(Commands.argument("duration", StringArgumentType.word())
|
||||
.executes(context -> MuteCommand.mute(context, StringArgumentType.getString(context, "duration"), "No reason specified."))
|
||||
.then(Commands.argument("reason", StringArgumentType.greedyString())
|
||||
.executes(context -> MuteCommand.mute(context,
|
||||
StringArgumentType.getString(context, "duration"),
|
||||
StringArgumentType.getString(context, "reason"))
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public static int mute(CommandContext<CommandSourceStack> context, String durationArg, String reason) throws CommandSyntaxException {
|
||||
|
||||
CommandSourceStack sender = context.getSource();
|
||||
ServerPlayer muted = EntityArgument.getPlayer(context, "player");
|
||||
|
||||
int durationInSeconds;
|
||||
try {
|
||||
durationInSeconds = parseTimeArg(durationArg);
|
||||
} catch (Exception e) {
|
||||
sender.sendFailure(ChatFormat.format("{f}Invalid duration. Examples: 1s / 2m / 3h"));
|
||||
return 1;
|
||||
}
|
||||
|
||||
PlayerMutes.mute(sender, muted, durationInSeconds * 1000, reason);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
private static int parseTimeArg(String durationArg) throws Exception {
|
||||
StringReader stringReader = new StringReader(durationArg);
|
||||
float number = stringReader.readFloat();
|
||||
String unit = stringReader.readUnquotedString();
|
||||
|
||||
int unitValue = units.getOrDefault(unit, 0);
|
||||
int time = Math.round(number * unitValue);
|
||||
if (time <= 0) {
|
||||
throw new Exception();
|
||||
}
|
||||
return time;
|
||||
}
|
||||
|
||||
static HashMap<String, Integer> units = new HashMap<>();
|
||||
static {
|
||||
units.put("s", 1);
|
||||
units.put("m", 60);
|
||||
units.put("h", 3600);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package com.nexia.core.commands.staff;
|
||||
|
||||
import com.mojang.brigadier.CommandDispatcher;
|
||||
import com.mojang.brigadier.context.CommandContext;
|
||||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||
import com.nexia.core.utilities.player.PlayerUtil;
|
||||
import com.nexia.minigames.games.bedwars.areas.BwAreas;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
import net.minecraft.commands.Commands;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
|
||||
public class ProtectionMapCommand {
|
||||
|
||||
public static void register(CommandDispatcher<CommandSourceStack> dispatcher, boolean bl) {
|
||||
dispatcher.register(Commands.literal("protectionmap")
|
||||
.requires(commandSourceStack -> PlayerUtil.hasPermission(commandSourceStack, "nexia.dev.protectionmap", 3))
|
||||
|
||||
.then(Commands.literal("bedwars").executes(ProtectionMapCommand::bedwars))
|
||||
);
|
||||
}
|
||||
|
||||
public static int bedwars(CommandContext<CommandSourceStack> context) throws CommandSyntaxException {
|
||||
ServerPlayer player = context.getSource().getPlayerOrException();
|
||||
BwAreas.createProtectionMap(player);
|
||||
return 1;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package com.nexia.core.commands.staff;
|
||||
|
||||
import com.mojang.brigadier.CommandDispatcher;
|
||||
import com.mojang.brigadier.arguments.IntegerArgumentType;
|
||||
import com.mojang.brigadier.context.CommandContext;
|
||||
import com.nexia.core.utilities.misc.RandomUtil;
|
||||
import com.nexia.core.utilities.player.PlayerUtil;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
import net.minecraft.commands.Commands;
|
||||
|
||||
import java.util.Random;
|
||||
public class RandomCommand {
|
||||
public static void register(CommandDispatcher<CommandSourceStack> dispatcher, boolean bl) {
|
||||
dispatcher.register(Commands.literal("random")
|
||||
.requires(commandSourceStack -> PlayerUtil.hasPermission(commandSourceStack, "nexia.staff.random", 1))
|
||||
.then(Commands.argument("minimum", IntegerArgumentType.integer())
|
||||
.then(Commands.argument("maximum", IntegerArgumentType.integer())
|
||||
.executes(context -> RandomCommand.calculate(context, IntegerArgumentType.getInteger(context, "minimum"), IntegerArgumentType.getInteger(context, "maximum")))))
|
||||
);
|
||||
}
|
||||
|
||||
public static int calculate(CommandContext<CommandSourceStack> context, int minimum, int maximum) {
|
||||
return RandomUtil.randomInt(minimum, maximum);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
package com.nexia.core.commands.staff;
|
||||
|
||||
import com.mojang.brigadier.CommandDispatcher;
|
||||
import com.mojang.brigadier.arguments.StringArgumentType;
|
||||
import com.mojang.brigadier.context.CommandContext;
|
||||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||
import com.nexia.core.Main;
|
||||
import com.nexia.core.utilities.chat.ChatFormat;
|
||||
import com.nexia.core.utilities.player.PlayerUtil;
|
||||
import net.minecraft.Util;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
import net.minecraft.commands.Commands;
|
||||
import net.minecraft.commands.SharedSuggestionProvider;
|
||||
import net.minecraft.commands.arguments.EntityArgument;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
|
||||
public class RankCommand {
|
||||
public static void register(CommandDispatcher<CommandSourceStack> dispatcher, boolean bl) {
|
||||
dispatcher.register(Commands.literal("rank")
|
||||
.requires(commandSourceStack -> PlayerUtil.hasPermission(commandSourceStack, "nexia.staff.rank", 4))
|
||||
.then(Commands.argument("player", EntityArgument.player())
|
||||
.then(Commands.argument("rank", StringArgumentType.string())
|
||||
.suggests(((context, builder) -> SharedSuggestionProvider.suggest((Main.config.ranks), builder)))
|
||||
.executes(context -> RankCommand.give(context, EntityArgument.getPlayer(context, "player"), StringArgumentType.getString(context, "rank")))))
|
||||
);
|
||||
}
|
||||
|
||||
public static int give(CommandContext<CommandSourceStack> context, ServerPlayer player, String rank) throws CommandSyntaxException {
|
||||
CommandSourceStack executer = context.getSource();
|
||||
|
||||
for(int i = 0; i < 8; i++){
|
||||
if(rank.equalsIgnoreCase(Main.config.ranks[i])){
|
||||
executer.sendSuccess(ChatFormat.format("{b1}You have set the rank of {b2}{} {b1}to: {b2}{b}{}{b1}.", player.getScoreboardName(), Main.config.ranks[i]), false);
|
||||
player.sendMessage(ChatFormat.format("{b1}Your rank has been set to: {b2}{b}{}{b1}.", Main.config.ranks[i]), Util.NIL_UUID);
|
||||
|
||||
for (int i2 = 0; i2 < 8; i2++) {
|
||||
player.removeTag(Main.config.ranks[i2]);
|
||||
}
|
||||
|
||||
PlayerUtil.executeServerCommand("/lp user %player% parent set " + Main.config.ranks[i], player);
|
||||
player.addTag(Main.config.ranks[i]);
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package com.nexia.core.commands.staff;
|
||||
|
||||
import com.mojang.brigadier.CommandDispatcher;
|
||||
import com.mojang.brigadier.context.CommandContext;
|
||||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||
import com.nexia.core.utilities.player.PlayerUtil;
|
||||
import com.nexia.core.utilities.pos.EntityPos;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
import net.minecraft.commands.Commands;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
|
||||
public class RoundPosCommand {
|
||||
|
||||
public static void register(CommandDispatcher<CommandSourceStack> dispatcher, boolean bl) {
|
||||
dispatcher.register(Commands.literal("roundpos").executes(RoundPosCommand::run)
|
||||
.requires(commandSourceStack -> PlayerUtil.hasPermission(commandSourceStack, "nexia.dev.roundpos", 3)));
|
||||
}
|
||||
|
||||
public static int run(CommandContext<CommandSourceStack> context) throws CommandSyntaxException {
|
||||
ServerPlayer player = context.getSource().getPlayerOrException();
|
||||
|
||||
EntityPos pos = new EntityPos(player);
|
||||
pos.x = Math.floor(pos.x) + 0.5;
|
||||
pos.z = Math.floor(pos.z) + 0.5;
|
||||
pos.yaw = Math.round(pos.yaw / 45) * 45;
|
||||
pos.pitch = 0;
|
||||
|
||||
pos.teleportPlayer(player.getLevel(), player);
|
||||
return 1;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
package com.nexia.core.commands.staff;
|
||||
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import com.mojang.brigadier.CommandDispatcher;
|
||||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||
import com.nexia.core.Main;
|
||||
import com.nexia.core.utilities.chat.ChatFormat;
|
||||
import com.nexia.core.utilities.player.PlayerUtil;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
import net.minecraft.commands.Commands;
|
||||
import net.minecraft.commands.SharedSuggestionProvider;
|
||||
import net.minecraft.commands.arguments.GameProfileArgument;
|
||||
import net.minecraft.server.players.UserBanList;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
public class UnBanCommand {
|
||||
public static void register(CommandDispatcher<CommandSourceStack> dispatcher, boolean bl) {
|
||||
dispatcher.register(Commands.literal("unban")
|
||||
.requires(commandSourceStack -> PlayerUtil.hasPermission(commandSourceStack, "nexia.staff.ban", 3))
|
||||
.then(Commands.argument("player", GameProfileArgument.gameProfile())
|
||||
.suggests(((context, builder) -> SharedSuggestionProvider.suggest((context.getSource()).getServer().getPlayerList().getBans().getUserList(), builder)))
|
||||
.executes(context -> UnBanCommand.unban(context.getSource(), GameProfileArgument.getGameProfiles(context, "player")))
|
||||
)
|
||||
);
|
||||
dispatcher.register(Commands.literal("pardon")
|
||||
.requires(commandSourceStack -> PlayerUtil.hasPermission(commandSourceStack, "nexia.staff.ban", 3))
|
||||
.then(Commands.argument("player", GameProfileArgument.gameProfile())
|
||||
.suggests(((context, builder) -> SharedSuggestionProvider.suggest((context.getSource()).getServer().getPlayerList().getBans().getUserList(), builder)))
|
||||
.executes(context -> UnBanCommand.unban(context.getSource(), GameProfileArgument.getGameProfiles(context, "player")))
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public static int unban(CommandSourceStack context, Collection<GameProfile> collection) throws CommandSyntaxException {
|
||||
UserBanList userBanList = Main.server.getPlayerList().getBans();
|
||||
int i = 0;
|
||||
|
||||
for (GameProfile gameProfile : collection) {
|
||||
if (userBanList.isBanned(gameProfile)) {
|
||||
userBanList.remove(gameProfile);
|
||||
++i;
|
||||
context.sendSuccess(ChatFormat.format("{b1}You have unbanned {b2}{}{b1}.", gameProfile.getName()), true);
|
||||
}
|
||||
}
|
||||
|
||||
if (i == 0) {
|
||||
context.sendSuccess(ChatFormat.formatFail("That player is not banned."), false);
|
||||
} else {
|
||||
return i;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package com.nexia.core.commands.staff;
|
||||
|
||||
import com.mojang.brigadier.CommandDispatcher;
|
||||
import com.mojang.brigadier.context.CommandContext;
|
||||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||
import com.nexia.core.utilities.chat.PlayerMutes;
|
||||
import com.nexia.core.utilities.player.PlayerUtil;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
import net.minecraft.commands.Commands;
|
||||
import net.minecraft.commands.arguments.EntityArgument;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
|
||||
public class UnMuteCommand {
|
||||
|
||||
public static void register(CommandDispatcher<CommandSourceStack> dispatcher, boolean bl) {
|
||||
dispatcher.register(Commands.literal("unmute")
|
||||
.requires(commandSourceStack -> PlayerUtil.hasPermission(commandSourceStack, "nexia.staff.mute", 1))
|
||||
|
||||
.then(Commands.argument("player", EntityArgument.player())
|
||||
.executes(UnMuteCommand::unMute)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public static int unMute(CommandContext<CommandSourceStack> context) throws CommandSyntaxException {
|
||||
CommandSourceStack sender = context.getSource();
|
||||
ServerPlayer muted = EntityArgument.getPlayer(context, "player");
|
||||
|
||||
PlayerMutes.unMute(sender, muted);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
package com.nexia.core.config;
|
||||
|
||||
import me.sargunvohra.mcmods.autoconfig1u.ConfigData;
|
||||
import me.sargunvohra.mcmods.autoconfig1u.annotation.Config;
|
||||
import me.sargunvohra.mcmods.autoconfig1u.shadowed.blue.endless.jankson.Comment;
|
||||
|
||||
@Config(name = "nexia-core")
|
||||
public class ModConfig implements ConfigData {
|
||||
@Comment("The server commands that get run whenever a player leaves the server.")
|
||||
public String[] serverLeaveCommands = {""};
|
||||
@Comment("The player commands that get run whenever a player leaves the server.")
|
||||
public String[] playerLeaveCommands = {""};
|
||||
|
||||
@Comment("The server commands that get run whenever a player joins the server.")
|
||||
public String[] serverJoinCommands = {""};
|
||||
@Comment("The player commands that get run whenever a player joins the server.")
|
||||
public String[] playerJoinCommands = {""};
|
||||
|
||||
@Comment("The server commands that get run whenever a player joins the server for the first time.")
|
||||
public String[] serverFirstJoinCommands = {""};
|
||||
@Comment("The player commands that get run whenever a player joins the server for the first time.")
|
||||
public String[] playerFirstJoinCommands = {""};
|
||||
|
||||
@Comment("What the discord link should be.")
|
||||
public String discordLink = "";
|
||||
|
||||
@Comment("List of ranks.")
|
||||
public String[] ranks = {""};
|
||||
|
||||
public double[] lobbyPos = {
|
||||
0.5,
|
||||
65.0,
|
||||
0.5,
|
||||
};
|
||||
|
||||
@Comment("Toggles if the modified knockback is enabled.")
|
||||
public boolean modifiedKnockback = false;
|
||||
|
||||
@Comment("Toggles if the modified fishing rods are enabled.")
|
||||
public boolean modifiedRods = false;
|
||||
|
||||
@Comment("Toggles if the better shields are enabled.")
|
||||
public boolean betterShields = false;
|
||||
|
||||
@Comment("Toggles if the join and leave messages show.")
|
||||
public boolean statusMessages = true;
|
||||
|
||||
@Comment("The message that gets announced when the player joins the server for the first time.")
|
||||
public String firstJoinMessage = "WELCOME %player%";
|
||||
@Comment("The message that gets announced when the player joins the server.")
|
||||
public String joinMessage = "JOIN %player%";
|
||||
|
||||
@Comment("The message that gets announced when the player leaves the server.")
|
||||
public String leaveMessage = "LEAVE %player%";
|
||||
|
||||
}
|
||||
@@ -0,0 +1,177 @@
|
||||
package com.nexia.core.games.util;
|
||||
|
||||
import com.nexia.core.Main;
|
||||
import com.nexia.core.utilities.item.ItemDisplayUtil;
|
||||
import com.nexia.core.utilities.item.ItemStackUtil;
|
||||
import com.nexia.core.utilities.player.PlayerDataManager;
|
||||
import com.nexia.core.utilities.player.PlayerUtil;
|
||||
import com.nexia.core.utilities.pos.EntityPos;
|
||||
import com.nexia.ffa.utilities.FfaAreas;
|
||||
import com.nexia.ffa.utilities.FfaUtil;
|
||||
import com.nexia.minigames.games.bedwars.players.BwPlayerEvents;
|
||||
import com.nexia.minigames.games.bedwars.util.BwScoreboard;
|
||||
import com.nexia.minigames.games.bedwars.util.BwUtil;
|
||||
import com.nexia.minigames.games.duels.DuelGameMode;
|
||||
import com.nexia.minigames.games.duels.DuelsGame;
|
||||
import com.nexia.minigames.games.duels.DuelsSpawn;
|
||||
import com.nexia.minigames.games.duels.gamemodes.GamemodeHandler;
|
||||
import com.nexia.minigames.games.oitc.OitcGame;
|
||||
import com.nexia.minigames.games.oitc.OitcGameMode;
|
||||
import com.nexia.minigames.games.oitc.OitcSpawn;
|
||||
import net.minecraft.network.chat.TextComponent;
|
||||
import net.minecraft.network.protocol.game.ClientboundStopSoundPacket;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.Items;
|
||||
import net.minecraft.world.level.GameType;
|
||||
import net.minecraft.world.level.Level;
|
||||
|
||||
public class LobbyUtil {
|
||||
|
||||
public static String[] statsGameModes = {"FFA", "BEDWARS", "OITC", "DUELS"};
|
||||
|
||||
public static ServerLevel lobbyWorld = null;
|
||||
public static EntityPos lobbySpawn = new EntityPos(Main.config.lobbyPos[0], Main.config.lobbyPos[1], Main.config.lobbyPos[2], 0, 0);
|
||||
|
||||
public static boolean isLobbyWorld(Level level) {
|
||||
return level.dimension() == Level.OVERWORLD;
|
||||
}
|
||||
|
||||
public static void setLobbyWorld(MinecraftServer server) {
|
||||
for (ServerLevel level : server.getAllLevels()) {
|
||||
if (isLobbyWorld(level)) {
|
||||
lobbyWorld = level;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Players with the tag will not be affected by server rank teams given by server datapack
|
||||
public static final String NO_RANK_DISPLAY_TAG = "no_rank_display";
|
||||
|
||||
public static final String NO_FALL_DAMAGE_TAG = "no_fall_damage";
|
||||
|
||||
public static final String NO_DAMAGE_TAG = "no_damage";
|
||||
|
||||
public static String[] removedTags = {
|
||||
"in_bedwars",
|
||||
"ffa",
|
||||
"duels",
|
||||
"oitc",
|
||||
"in_oitc_game"
|
||||
};
|
||||
|
||||
public static void leaveAllGames(ServerPlayer player, boolean tp) {
|
||||
if (BwUtil.isInBedWars(player)) BwPlayerEvents.leaveInBedWars(player);
|
||||
else if (FfaUtil.isFfaPlayer(player)) FfaUtil.leaveOrDie(player, player.getLastDamageSource());
|
||||
else if (PlayerDataManager.get(player).gameMode == PlayerGameMode.DUELS) DuelsGame.leave(player);
|
||||
else if (PlayerDataManager.get(player).gameMode == PlayerGameMode.OITC) OitcGame.leave(player);
|
||||
|
||||
BwScoreboard.removeScoreboardFor(player);
|
||||
|
||||
for(int i = 0; i < LobbyUtil.removedTags.length; i++){
|
||||
if(PlayerUtil.hasTag(player, LobbyUtil.removedTags[i])){
|
||||
player.removeTag(LobbyUtil.removedTags[i]);
|
||||
}
|
||||
}
|
||||
|
||||
returnToLobby(player, tp);
|
||||
}
|
||||
|
||||
public static void returnToLobby(ServerPlayer player, boolean tp) {
|
||||
for(int i = 0; i < LobbyUtil.removedTags.length; i++){
|
||||
if(PlayerUtil.hasTag(player, LobbyUtil.removedTags[i])){
|
||||
player.removeTag(LobbyUtil.removedTags[i]);
|
||||
}
|
||||
}
|
||||
|
||||
PlayerUtil.resetHealthStatus(player);
|
||||
player.setGameMode(GameType.ADVENTURE);
|
||||
|
||||
player.inventory.clearContent();
|
||||
player.inventory.setCarried(ItemStack.EMPTY);
|
||||
player.getEnderChestInventory().clearContent();
|
||||
|
||||
if (tp) {
|
||||
player.setRespawnPosition(lobbyWorld.dimension(), lobbySpawn.toBlockPos(), lobbySpawn.yaw, true, false);
|
||||
lobbySpawn.teleportPlayer(lobbyWorld, player);
|
||||
|
||||
ItemStack compass = new ItemStack(Items.COMPASS);
|
||||
compass.setHoverName(new TextComponent("§eGamemode Selector"));
|
||||
ItemDisplayUtil.addGlint(compass);
|
||||
ItemDisplayUtil.addLore(compass, "§7Right click to open the menu.", 0);
|
||||
|
||||
ItemStack nametag = new ItemStack(Items.NAME_TAG);
|
||||
nametag.setHoverName(new TextComponent("§ePrefix Selector"));
|
||||
ItemDisplayUtil.addGlint(nametag);
|
||||
ItemDisplayUtil.addLore(nametag, "§7Right click to open the menu.", 0);
|
||||
|
||||
player.setSlot(4, compass);
|
||||
player.setSlot(3, nametag);
|
||||
ItemStackUtil.sendInventoryRefreshPacket(player);
|
||||
}
|
||||
|
||||
player.connection.send(new ClientboundStopSoundPacket());
|
||||
player.server.getPlayerList().sendPlayerPermissionLevel(player);
|
||||
|
||||
PlayerDataManager.get(player).gameMode = PlayerGameMode.LOBBY;
|
||||
player.removeTag(LobbyUtil.NO_RANK_DISPLAY_TAG);
|
||||
player.removeTag(LobbyUtil.NO_FALL_DAMAGE_TAG);
|
||||
player.removeTag(LobbyUtil.NO_DAMAGE_TAG);
|
||||
}
|
||||
|
||||
public static void sendGame(ServerPlayer player, String game, boolean message){
|
||||
if (!LobbyUtil.isLobbyWorld(player.level) || PlayerDataManager.get(player).gameMode != PlayerGameMode.LOBBY) {
|
||||
LobbyUtil.leaveAllGames(player, false);
|
||||
} else{
|
||||
PlayerUtil.resetHealthStatus(player);
|
||||
player.setGameMode(GameType.ADVENTURE);
|
||||
|
||||
player.inventory.clearContent();
|
||||
player.inventory.setCarried(ItemStack.EMPTY);
|
||||
player.getEnderChestInventory().clearContent();
|
||||
|
||||
player.connection.send(new ClientboundStopSoundPacket());
|
||||
|
||||
player.removeTag(LobbyUtil.NO_FALL_DAMAGE_TAG);
|
||||
player.removeTag(LobbyUtil.NO_DAMAGE_TAG);
|
||||
}
|
||||
if(game.equalsIgnoreCase("normal ffa")){
|
||||
player.addTag("ffa");
|
||||
FfaUtil.wasInSpawn.add(player.getUUID());
|
||||
PlayerDataManager.get(player).gameMode = PlayerGameMode.FFA;
|
||||
player.teleportTo(FfaAreas.ffaWorld, FfaAreas.spawn.x, FfaAreas.spawn.y, FfaAreas.spawn.z, FfaAreas.spawn.yaw, FfaAreas.spawn.pitch);
|
||||
player.setRespawnPosition(FfaAreas.ffaWorld.dimension(), FfaAreas.spawn.toBlockPos(), FfaAreas.spawn.yaw, true, false);
|
||||
FfaUtil.clearThrownTridents(player);
|
||||
if(message){PlayerUtil.sendActionbar(player, "You have joined §8🗡 §7§lFFA §b🔱");}
|
||||
FfaUtil.setInventory(player);
|
||||
}
|
||||
if(game.equalsIgnoreCase("bedwars")){
|
||||
if(message){PlayerUtil.sendActionbar(player, "You have joined §b\uD83E\uDE93 §c§lBedwars §e⚡");}
|
||||
BwPlayerEvents.tryToJoin(player, false);
|
||||
}
|
||||
|
||||
if(game.equalsIgnoreCase("duels")){
|
||||
player.addTag("duels");
|
||||
PlayerDataManager.get(player).gameMode = PlayerGameMode.DUELS;
|
||||
GamemodeHandler.removeQueue(player, com.nexia.minigames.games.duels.util.player.PlayerDataManager.get(player).gameMode.toString(), true);
|
||||
DuelsGame.death(player, player.getLastDamageSource());
|
||||
com.nexia.minigames.games.duels.util.player.PlayerDataManager.get(player).gameMode = DuelGameMode.LOBBY;
|
||||
player.teleportTo(DuelsSpawn.duelWorld, DuelsSpawn.spawn.x, DuelsSpawn.spawn.y, DuelsSpawn.spawn.z, DuelsSpawn.spawn.yaw, DuelsSpawn.spawn.pitch);
|
||||
player.setRespawnPosition(DuelsSpawn.duelWorld.dimension(), DuelsSpawn.spawn.toBlockPos(), DuelsSpawn.spawn.yaw, true, false);
|
||||
if(message){PlayerUtil.sendActionbar(player, "You have joined §f☯ §c§lDuels §7\uD83E\uDE93");}
|
||||
}
|
||||
|
||||
if(game.equalsIgnoreCase("oitc")){
|
||||
player.addTag("oitc");
|
||||
PlayerDataManager.get(player).gameMode = PlayerGameMode.OITC;
|
||||
OitcGame.death(player, player.getLastDamageSource());
|
||||
com.nexia.minigames.games.oitc.util.player.PlayerDataManager.get(player).gameMode = OitcGameMode.LOBBY;
|
||||
player.teleportTo(OitcSpawn.oitcWorld, OitcSpawn.spawn.x, OitcSpawn.spawn.y, OitcSpawn.spawn.z, OitcSpawn.spawn.yaw, OitcSpawn.spawn.pitch);
|
||||
player.setRespawnPosition(OitcSpawn.oitcWorld.dimension(), OitcSpawn.spawn.toBlockPos(), OitcSpawn.spawn.yaw, true, false);
|
||||
if(message){PlayerUtil.sendActionbar(player, "You have joined §7\uD83D\uDDE1 §f§lOITC §7\uD83C\uDFF9");}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package com.nexia.core.games.util;
|
||||
|
||||
import net.minecraft.world.level.Level;
|
||||
|
||||
public class PlayerGameMode {
|
||||
|
||||
String id;
|
||||
|
||||
public static final PlayerGameMode LOBBY = new PlayerGameMode("lobby");
|
||||
public static final PlayerGameMode BEDWARS = new PlayerGameMode("bedwars");
|
||||
|
||||
public static final PlayerGameMode OITC = new PlayerGameMode("oitc");
|
||||
public static final PlayerGameMode FFA = new PlayerGameMode("ffa");
|
||||
|
||||
public static final PlayerGameMode DUELS = new PlayerGameMode("duels");
|
||||
|
||||
PlayerGameMode(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public static boolean isLobbyWorld(Level level) {
|
||||
return level.dimension().toString().contains("minecraft:overworld");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,169 @@
|
||||
package com.nexia.core.gui;
|
||||
|
||||
import com.nexia.core.games.util.LobbyUtil;
|
||||
import com.nexia.core.utilities.player.PlayerUtil;
|
||||
import eu.pb4.sgui.api.ClickType;
|
||||
import eu.pb4.sgui.api.elements.GuiElementInterface;
|
||||
import eu.pb4.sgui.api.gui.SimpleGui;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.chat.TextComponent;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.inventory.MenuType;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.Items;
|
||||
import net.minecraft.world.item.enchantment.Enchantments;
|
||||
|
||||
public class PlayGUI extends SimpleGui {
|
||||
|
||||
static final TextComponent title = new TextComponent("Game Menu");
|
||||
static final TextComponent ffaTitle = new TextComponent("FFA Menu");
|
||||
|
||||
static final TextComponent minigamesTitle = new TextComponent("Minigames Menu");
|
||||
public PlayGUI(MenuType<?> type, ServerPlayer player, boolean includePlayer) {
|
||||
super(type, player, includePlayer);
|
||||
}
|
||||
|
||||
private void fillEmptySlots(ItemStack itemStack, int slots){
|
||||
for(int i = 0; i < slots; i++){
|
||||
this.setSlot(i, itemStack);
|
||||
/*
|
||||
GuiElementInterface element = this.getSlot(i);
|
||||
if(element != null && element.getItemStack().getItem() == null || element.getItemStack().getItem() == Items.AIR){
|
||||
this.setSlot(i, itemStack);
|
||||
}
|
||||
*/
|
||||
}
|
||||
}
|
||||
private void setMainLayout(){
|
||||
ItemStack enchanted_sword = new ItemStack(Items.NETHERITE_SWORD, 1);
|
||||
enchanted_sword.setHoverName(new TextComponent("§7§lFFA"));
|
||||
enchanted_sword.enchant(Enchantments.SHARPNESS, 1);
|
||||
enchanted_sword.hideTooltipPart(ItemStack.TooltipPart.ENCHANTMENTS);
|
||||
enchanted_sword.hideTooltipPart(ItemStack.TooltipPart.MODIFIERS);
|
||||
|
||||
ItemStack enchanted_barrier = new ItemStack(Items.BARRIER, 1);
|
||||
enchanted_barrier.setHoverName(new TextComponent("§c§lHub"));
|
||||
enchanted_barrier.hideTooltipPart(ItemStack.TooltipPart.MODIFIERS);
|
||||
|
||||
ItemStack enchanted_compass = new ItemStack(Items.COMPASS, 1);
|
||||
enchanted_compass.setHoverName(new TextComponent("§f§lMinigames"));
|
||||
enchanted_compass.enchant(Enchantments.SHARPNESS, 1);
|
||||
enchanted_compass.hideTooltipPart(ItemStack.TooltipPart.ENCHANTMENTS);
|
||||
enchanted_compass.hideTooltipPart(ItemStack.TooltipPart.MODIFIERS);
|
||||
|
||||
ItemStack emptySlot = new ItemStack(Items.BLACK_STAINED_GLASS_PANE, 1);
|
||||
emptySlot.setHoverName(new TextComponent(""));
|
||||
|
||||
fillEmptySlots(emptySlot, 27);
|
||||
this.setSlot(11, enchanted_sword);
|
||||
this.setSlot(13, enchanted_barrier);
|
||||
this.setSlot(15, enchanted_compass);
|
||||
}
|
||||
|
||||
private void setFFALayout(){
|
||||
this.setTitle(ffaTitle);
|
||||
ItemStack enchanted_sword = new ItemStack(Items.NETHERITE_SWORD, 1);
|
||||
enchanted_sword.setHoverName(new TextComponent("§7§lClassic FFA"));
|
||||
enchanted_sword.enchant(Enchantments.SHARPNESS, 1);
|
||||
enchanted_sword.hideTooltipPart(ItemStack.TooltipPart.ENCHANTMENTS);
|
||||
enchanted_sword.hideTooltipPart(ItemStack.TooltipPart.MODIFIERS);
|
||||
|
||||
ItemStack unknown = new ItemStack(Items.BARRIER, 1);
|
||||
unknown.setHoverName(new TextComponent("§7§l???"));
|
||||
unknown.enchant(Enchantments.SHARPNESS, 1);
|
||||
unknown.hideTooltipPart(ItemStack.TooltipPart.ENCHANTMENTS);
|
||||
unknown.hideTooltipPart(ItemStack.TooltipPart.MODIFIERS);
|
||||
|
||||
|
||||
ItemStack emptySlot = new ItemStack(Items.BLACK_STAINED_GLASS_PANE, 1);
|
||||
emptySlot.setHoverName(new TextComponent(""));
|
||||
|
||||
fillEmptySlots(emptySlot, 27);
|
||||
this.setSlot(11, unknown);
|
||||
this.setSlot(13, enchanted_sword);
|
||||
this.setSlot(15, unknown);
|
||||
}
|
||||
|
||||
private void setMinigamesLayout(){
|
||||
this.setTitle(minigamesTitle);
|
||||
ItemStack unknown = new ItemStack(Items.BARRIER, 1);
|
||||
unknown.setHoverName(new TextComponent("§7§l???"));
|
||||
unknown.hideTooltipPart(ItemStack.TooltipPart.MODIFIERS);
|
||||
|
||||
ItemStack bedwars = new ItemStack(Items.RED_BED, 1);
|
||||
bedwars.setHoverName(new TextComponent("§c§lBedwars"));
|
||||
bedwars.enchant(Enchantments.SHARPNESS, 1);
|
||||
bedwars.hideTooltipPart(ItemStack.TooltipPart.ENCHANTMENTS);
|
||||
bedwars.hideTooltipPart(ItemStack.TooltipPart.MODIFIERS);
|
||||
|
||||
ItemStack oitc = new ItemStack(Items.BOW, 1);
|
||||
oitc.setHoverName(new TextComponent("§f§lOITC"));
|
||||
oitc.enchant(Enchantments.SHARPNESS, 1);
|
||||
oitc.hideTooltipPart(ItemStack.TooltipPart.ENCHANTMENTS);
|
||||
oitc.hideTooltipPart(ItemStack.TooltipPart.MODIFIERS);
|
||||
|
||||
|
||||
ItemStack duels = new ItemStack(Items.DIAMOND_SWORD, 1);
|
||||
duels.setHoverName(new TextComponent("§b§lDuels"));
|
||||
duels.enchant(Enchantments.SHARPNESS, 1);
|
||||
duels.hideTooltipPart(ItemStack.TooltipPart.ENCHANTMENTS);
|
||||
duels.hideTooltipPart(ItemStack.TooltipPart.MODIFIERS);
|
||||
|
||||
|
||||
|
||||
ItemStack emptySlot = new ItemStack(Items.BLACK_STAINED_GLASS_PANE, 1);
|
||||
emptySlot.setHoverName(new TextComponent(""));
|
||||
|
||||
fillEmptySlots(emptySlot, 27);
|
||||
this.setSlot(11, duels);
|
||||
this.setSlot(13, bedwars);
|
||||
this.setSlot(15, oitc);
|
||||
}
|
||||
|
||||
public boolean click(int index, ClickType clickType, net.minecraft.world.inventory.ClickType action){
|
||||
GuiElementInterface element = this.getSlot(index);
|
||||
if(element != null && clickType != ClickType.MOUSE_DOUBLE_CLICK) {
|
||||
ItemStack itemStack = element.getItemStack();
|
||||
Component name = itemStack.getHoverName();
|
||||
if(name.getString().equalsIgnoreCase("§7§lClassic FFA")){
|
||||
LobbyUtil.sendGame(this.player, "normal ffa", true);
|
||||
this.close();
|
||||
}
|
||||
if(name.getString().equalsIgnoreCase("§7§lFFA")){
|
||||
this.setFFALayout();
|
||||
}
|
||||
if(name.getString().equalsIgnoreCase("§f§lMinigames")){
|
||||
this.setMinigamesLayout();
|
||||
}
|
||||
if(name.getString().equalsIgnoreCase("§c§lBedwars")){
|
||||
LobbyUtil.sendGame(this.player, "bedwars", true);
|
||||
this.close();
|
||||
}
|
||||
if(name.getString().equalsIgnoreCase("§f§lOITC")){
|
||||
LobbyUtil.sendGame(this.player, "oitc", true);
|
||||
this.close();
|
||||
}
|
||||
|
||||
if(name.getString().equalsIgnoreCase("§b§lDuels")){
|
||||
LobbyUtil.sendGame(this.player, "duels", true);
|
||||
this.close();
|
||||
}
|
||||
|
||||
|
||||
if(name.getString().toLowerCase().contains("hub")){
|
||||
LobbyUtil.leaveAllGames(this.player, true);
|
||||
}
|
||||
|
||||
if(itemStack.getItem() != Items.BLACK_STAINED_GLASS_PANE && itemStack.getItem() != Items.AIR && itemStack.getItem() != Items.NETHERITE_SWORD && itemStack.getItem() != Items.COMPASS){
|
||||
this.close();
|
||||
}
|
||||
}
|
||||
return super.click(index, clickType, action);
|
||||
}
|
||||
public static void openMainGUI(ServerPlayer player) {
|
||||
PlayGUI shop = new PlayGUI(MenuType.GENERIC_9x3, player, false);
|
||||
shop.setTitle(title);
|
||||
shop.setMainLayout();
|
||||
shop.open();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,104 @@
|
||||
package com.nexia.core.gui;
|
||||
|
||||
import com.nexia.core.Main;
|
||||
import com.nexia.core.utilities.chat.ChatFormat;
|
||||
import com.nexia.core.utilities.player.PlayerUtil;
|
||||
import eu.pb4.sgui.api.ClickType;
|
||||
import eu.pb4.sgui.api.elements.GuiElementInterface;
|
||||
import eu.pb4.sgui.api.gui.SimpleGui;
|
||||
import net.minecraft.ChatFormatting;
|
||||
import net.minecraft.Util;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.chat.TextComponent;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.inventory.MenuType;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.Items;
|
||||
import net.minecraft.world.item.enchantment.Enchantments;
|
||||
|
||||
public class RankGUI extends SimpleGui {
|
||||
static final TextComponent title = new TextComponent("Prefix Menu");
|
||||
public RankGUI(MenuType<?> type, ServerPlayer player, boolean includePlayer) {
|
||||
super(type, player, includePlayer);
|
||||
}
|
||||
|
||||
private void fillEmptySlots(ItemStack itemStack, int slots){
|
||||
for(int i = 0; i < slots; i++){
|
||||
this.setSlot(i, itemStack);
|
||||
/*
|
||||
GuiElementInterface element = this.getSlot(i);
|
||||
if(element != null && element.getItemStack().getItem() == null || element.getItemStack().getItem() == Items.AIR){
|
||||
this.setSlot(i, itemStack);
|
||||
}
|
||||
*/
|
||||
}
|
||||
}
|
||||
private void setMainLayout(ServerPlayer player){
|
||||
ItemStack emptySlot = new ItemStack(Items.BLACK_STAINED_GLASS_PANE, 1);
|
||||
emptySlot.setHoverName(new TextComponent(""));
|
||||
|
||||
fillEmptySlots(emptySlot, 36);
|
||||
int slot = 10;
|
||||
int airSlots = 10;
|
||||
for(int air = 0; air < 14; air++){
|
||||
if(airSlots == 17) {
|
||||
airSlots = 19;
|
||||
}
|
||||
this.setSlot(airSlots, new ItemStack(Items.AIR));
|
||||
airSlots++;
|
||||
}
|
||||
for(int i = 0; i < 8; i++){
|
||||
if(slot == 17) {
|
||||
slot = 19;
|
||||
}
|
||||
|
||||
if(PlayerUtil.hasPermission(player.createCommandSourceStack(), "nexia.prefix." + Main.config.ranks[i], 4) && PlayerUtil.hasTag(player, Main.config.ranks[i])){
|
||||
ItemStack enchantedItem = new ItemStack(Items.NAME_TAG, 1);
|
||||
enchantedItem.enchant(Enchantments.SHARPNESS, 1);
|
||||
enchantedItem.hideTooltipPart(ItemStack.TooltipPart.ENCHANTMENTS);
|
||||
enchantedItem.setHoverName(new TextComponent(Main.config.ranks[i]).withStyle(ChatFormatting.BOLD, ChatFormatting.LIGHT_PURPLE));
|
||||
this.setSlot(slot, enchantedItem);
|
||||
slot++;
|
||||
} else if(PlayerUtil.hasPermission(player.createCommandSourceStack(), "nexia.prefix." + Main.config.ranks[i], 4)){
|
||||
ItemStack changedItem = new ItemStack(Items.NAME_TAG, 1);
|
||||
changedItem.setHoverName(new TextComponent(Main.config.ranks[i]).withStyle(ChatFormatting.WHITE));
|
||||
this.setSlot(slot, changedItem);
|
||||
slot++;
|
||||
} else if(PlayerUtil.hasTag(player, Main.config.ranks[i])) {
|
||||
ItemStack enchantedItem = new ItemStack(Items.NAME_TAG, 1);
|
||||
enchantedItem.enchant(Enchantments.SHARPNESS, 1);
|
||||
enchantedItem.hideTooltipPart(ItemStack.TooltipPart.ENCHANTMENTS);
|
||||
enchantedItem.setHoverName(new TextComponent(Main.config.ranks[i]).withStyle(ChatFormatting.BOLD, ChatFormatting.LIGHT_PURPLE));
|
||||
this.setSlot(slot, enchantedItem);
|
||||
slot++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean click(int index, ClickType clickType, net.minecraft.world.inventory.ClickType action){
|
||||
GuiElementInterface element = this.getSlot(index);
|
||||
if(element != null && clickType != ClickType.MOUSE_DOUBLE_CLICK) {
|
||||
ItemStack itemStack = element.getItemStack();
|
||||
Component name = itemStack.getHoverName();
|
||||
|
||||
if(itemStack.getItem() != Items.BLACK_STAINED_GLASS_PANE && itemStack.getItem() != Items.AIR){
|
||||
this.player.sendMessage(ChatFormat.format("{b1}Your prefix has been set to: {b2}{b}{}", name.getString()), Util.NIL_UUID);
|
||||
|
||||
for(int i = 0; i < 8; i++){
|
||||
this.player.removeTag(Main.config.ranks[i]);
|
||||
}
|
||||
|
||||
this.player.addTag(name.getString().toLowerCase());
|
||||
this.setMainLayout(this.player);
|
||||
}
|
||||
|
||||
}
|
||||
return super.click(index, clickType, action);
|
||||
}
|
||||
public static void openRankGUI(ServerPlayer player) {
|
||||
RankGUI shop = new RankGUI(MenuType.GENERIC_9x4, player, false);
|
||||
shop.setTitle(title);
|
||||
shop.setMainLayout(player);
|
||||
shop.open();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
package com.nexia.core.loader;
|
||||
|
||||
import com.mojang.brigadier.tree.CommandNode;
|
||||
import com.nexia.core.commands.player.*;
|
||||
import com.nexia.core.commands.player.duels.*;
|
||||
import com.nexia.core.commands.player.oitc.OitcCommand;
|
||||
import com.nexia.core.commands.staff.*;
|
||||
import com.nexia.core.utilities.misc.NxCmdUtil;
|
||||
import net.fabricmc.fabric.api.command.v1.CommandRegistrationCallback;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
|
||||
public class CommandLoader {
|
||||
|
||||
public static void registerCommands() {
|
||||
|
||||
/*
|
||||
CommandRegistrationCallback.EVENT.register((dispatcher, bl) -> {
|
||||
for (CommandNode<CommandSourceStack> node : dispatcher.getRoot().getChildren()) {
|
||||
NxCmdUtil.alterCommand(node);
|
||||
}
|
||||
});
|
||||
|
||||
*/
|
||||
|
||||
CommandRegistrationCallback.EVENT.register(DefaultGameRulesCommand::register);
|
||||
CommandRegistrationCallback.EVENT.register(ProtectionMapCommand::register);
|
||||
CommandRegistrationCallback.EVENT.register(PrefixCommand::register);
|
||||
CommandRegistrationCallback.EVENT.register(RankCommand::register);
|
||||
CommandRegistrationCallback.EVENT.register(RoundPosCommand::register);
|
||||
CommandRegistrationCallback.EVENT.register(PingCommand::register);
|
||||
|
||||
|
||||
CommandRegistrationCallback.EVENT.register(DuelCommand::register);
|
||||
CommandRegistrationCallback.EVENT.register(QueueCommand::register);
|
||||
CommandRegistrationCallback.EVENT.register(MapCommand::register);
|
||||
|
||||
CommandRegistrationCallback.EVENT.register(OitcCommand::register);
|
||||
|
||||
CommandRegistrationCallback.EVENT.register(MuteCommand::register);
|
||||
CommandRegistrationCallback.EVENT.register(UnMuteCommand::register);
|
||||
|
||||
CommandRegistrationCallback.EVENT.register(PlayCommand::register);
|
||||
CommandRegistrationCallback.EVENT.register(LeaveCommand::register);
|
||||
|
||||
CommandRegistrationCallback.EVENT.register(BanCommand::register);
|
||||
CommandRegistrationCallback.EVENT.register(UnBanCommand::register);
|
||||
CommandRegistrationCallback.EVENT.register(StatsCommand::register);
|
||||
CommandRegistrationCallback.EVENT.register(RulesCommand::register);
|
||||
CommandRegistrationCallback.EVENT.register(DiscordCommand::register);
|
||||
CommandRegistrationCallback.EVENT.register(HelpCommand::register);
|
||||
CommandRegistrationCallback.EVENT.register(ReportCommand::register);
|
||||
|
||||
CommandRegistrationCallback.EVENT.register(MessageCommand::registerMsg);
|
||||
CommandRegistrationCallback.EVENT.register(MessageCommand::registerReply);
|
||||
|
||||
CommandRegistrationCallback.EVENT.register(RandomCommand::register);
|
||||
|
||||
CommandRegistrationCallback.EVENT.register(HealCommand::register);
|
||||
CommandRegistrationCallback.EVENT.register(BwReloadShopCommand::register);
|
||||
CommandRegistrationCallback.EVENT.register(BwReloadTeamColorsCommand::register);
|
||||
CommandRegistrationCallback.EVENT.register(BwSkipQueueCommand::register);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package com.nexia.core.mixin.block;
|
||||
|
||||
import com.nexia.minigames.games.bedwars.util.BwUtil;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.InteractionHand;
|
||||
import net.minecraft.world.InteractionResult;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.block.AnvilBlock;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.phys.BlockHitResult;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
|
||||
@Mixin(AnvilBlock.class)
|
||||
public class AnvilBlockMixin {
|
||||
|
||||
@Inject(method = "use", cancellable = true, at = @At("HEAD"))
|
||||
private void use(BlockState blockState, Level level, BlockPos blockPos, Player player, InteractionHand interactionHand, BlockHitResult blockHitResult, CallbackInfoReturnable<InteractionResult> cir) {
|
||||
if (!(player instanceof ServerPlayer)) return;
|
||||
ServerPlayer serverPlayer = (ServerPlayer) player;
|
||||
|
||||
if (BwUtil.isInBedWars(serverPlayer)) {
|
||||
cir.setReturnValue(InteractionResult.FAIL);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package com.nexia.core.mixin.block;
|
||||
|
||||
import com.nexia.minigames.games.bedwars.areas.BwAreas;
|
||||
import com.nexia.minigames.games.bedwars.util.BwUtil;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
@Mixin(Block.class)
|
||||
public class BlockMixin {
|
||||
|
||||
@Inject(method = "dropResources(Lnet/minecraft/world/level/block/state/BlockState;Lnet/minecraft/world/level/Level;Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/entity/BlockEntity;Lnet/minecraft/world/entity/Entity;Lnet/minecraft/world/item/ItemStack;)V",
|
||||
at = @At("HEAD"),
|
||||
cancellable = true)
|
||||
private static void dropResources(BlockState blockState, Level level, BlockPos blockPos, BlockEntity blockEntity, Entity breakerEntity, ItemStack tool, CallbackInfo ci) {
|
||||
if (!(level instanceof ServerLevel)) return;
|
||||
ServerLevel serverLevel = (ServerLevel) level;
|
||||
|
||||
if (BwAreas.isBedWarsWorld(serverLevel) && !(BwUtil.dropResources(blockState))) {
|
||||
ci.cancel();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
package com.nexia.core.mixin.block;
|
||||
|
||||
import net.minecraft.Util;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.util.Mth;
|
||||
import net.minecraft.util.StringUtil;
|
||||
import net.minecraft.world.level.ChunkPos;
|
||||
import net.minecraft.world.level.block.Mirror;
|
||||
import net.minecraft.world.level.block.Rotation;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraft.world.level.block.entity.BlockEntityType;
|
||||
import net.minecraft.world.level.block.entity.StructureBlockEntity;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.levelgen.structure.templatesystem.BlockRotProcessor;
|
||||
import net.minecraft.world.level.levelgen.structure.templatesystem.StructurePlaceSettings;
|
||||
import net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemplate;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Redirect;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
@Mixin(StructureBlockEntity.class)
|
||||
public class StructureBlockEntityMixin extends BlockEntity {
|
||||
@Shadow private String author;
|
||||
|
||||
@Shadow private float integrity;
|
||||
|
||||
@Shadow private Mirror mirror;
|
||||
|
||||
@Shadow private Rotation rotation;
|
||||
|
||||
@Shadow private long seed;
|
||||
|
||||
@Shadow private BlockPos structurePos;
|
||||
|
||||
@Shadow private BlockPos structureSize;
|
||||
|
||||
@Shadow private boolean ignoreEntities;
|
||||
|
||||
public StructureBlockEntityMixin(BlockEntityType<?> blockEntityType) {
|
||||
super(blockEntityType);
|
||||
}
|
||||
|
||||
private static Random createRandom(long l) {
|
||||
return l == 0L ? new Random(Util.getMillis()) : new Random(l);
|
||||
}
|
||||
|
||||
@Redirect(method = "loadStructure(Lnet/minecraft/server/level/ServerLevel;ZLnet/minecraft/world/level/levelgen/structure/templatesystem/StructureTemplate;)Z", at = @At("HEAD"))
|
||||
public boolean loadStructure(ServerLevel serverLevel, boolean bl, StructureTemplate structureTemplate) {
|
||||
BlockPos blockPos = this.getBlockPos();
|
||||
if (!StringUtil.isNullOrEmpty(structureTemplate.getAuthor())) {
|
||||
this.author = structureTemplate.getAuthor();
|
||||
}
|
||||
|
||||
BlockPos blockPos2 = structureTemplate.getSize();
|
||||
boolean bl2 = this.structureSize.equals(blockPos2);
|
||||
if (!bl2) {
|
||||
this.structureSize = blockPos2;
|
||||
this.setChanged();
|
||||
BlockState blockState = serverLevel.getBlockState(blockPos);
|
||||
serverLevel.sendBlockUpdated(blockPos, blockState, blockState, 3);
|
||||
}
|
||||
|
||||
if (bl && !bl2) {
|
||||
return false;
|
||||
} else {
|
||||
StructurePlaceSettings structurePlaceSettings = (new StructurePlaceSettings()).setMirror(this.mirror).setRotation(this.rotation).setIgnoreEntities(this.ignoreEntities).setChunkPos((ChunkPos)null);
|
||||
if (this.integrity < 1.0F) {
|
||||
structurePlaceSettings.clearProcessors().addProcessor(new BlockRotProcessor(Mth.clamp(this.integrity, 0.0F, 1.0F))).setRandom(createRandom(this.seed));
|
||||
}
|
||||
|
||||
BlockPos blockPos3 = blockPos.offset(this.structurePos);
|
||||
structureTemplate.placeInWorldChunk(serverLevel, blockPos3, structurePlaceSettings, createRandom(this.seed));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package com.nexia.core.mixin.entity;
|
||||
|
||||
import com.nexia.minigames.games.bedwars.areas.BwAreas;
|
||||
import net.minecraft.world.entity.projectile.AbstractArrow;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Redirect;
|
||||
|
||||
@Mixin(AbstractArrow.class)
|
||||
public class AbstractArrowMixin {
|
||||
|
||||
private int arrowDamage;
|
||||
|
||||
@Redirect(method = "onHitEntity", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/Mth;ceil(D)I"))
|
||||
private int modifyArrowDamage(double vanillaCalculated) {
|
||||
|
||||
if (BwAreas.isBedWarsWorld(((AbstractArrow)(Object)this).level)) {
|
||||
vanillaCalculated *= 0.625;
|
||||
}
|
||||
|
||||
arrowDamage = (int)Math.ceil(vanillaCalculated);
|
||||
return arrowDamage;
|
||||
}
|
||||
|
||||
@Redirect(method = "onHitEntity", at = @At(value = "INVOKE", target = "Ljava/lang/Math;min(JJ)J"))
|
||||
private long modifyCritDamage(long vanillaCalculated, long intMaxValue) {
|
||||
|
||||
if (BwAreas.isBedWarsWorld(((AbstractArrow)(Object)this).level)) {
|
||||
long critBoost = arrowDamage / 4 + 1;
|
||||
arrowDamage = (int)Math.min(arrowDamage + critBoost, Integer.MAX_VALUE);
|
||||
|
||||
} else {
|
||||
arrowDamage = (int)Math.min(vanillaCalculated, intMaxValue);
|
||||
}
|
||||
|
||||
return arrowDamage;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package com.nexia.core.mixin.entity;
|
||||
|
||||
import com.nexia.minigames.games.bedwars.areas.BwAreas;
|
||||
import com.nexia.minigames.games.bedwars.util.BwUtil;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.EntityType;
|
||||
import net.minecraft.world.entity.projectile.AbstractHurtingProjectile;
|
||||
import net.minecraft.world.entity.projectile.LargeFireball;
|
||||
import net.minecraft.world.level.Level;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
|
||||
@Mixin(AbstractHurtingProjectile.class)
|
||||
public abstract class AbstractHurtingProjectileMixin extends Entity {
|
||||
|
||||
public AbstractHurtingProjectileMixin(EntityType<?> entityType, Level level) {
|
||||
super(entityType, level);
|
||||
}
|
||||
|
||||
// Slow down fireballs
|
||||
@Inject(method = "getInertia", cancellable = true, at = @At("HEAD"))
|
||||
private void getInertia(CallbackInfoReturnable<Float> cir) {
|
||||
if (BwAreas.isBedWarsWorld(level) && (Object)this instanceof LargeFireball) {
|
||||
cir.setReturnValue(BwUtil.getFireballInertia());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
package com.nexia.core.mixin.entity;
|
||||
|
||||
import com.nexia.core.Main;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.EntityType;
|
||||
import net.minecraft.world.entity.LivingEntity;
|
||||
import net.minecraft.world.entity.ai.attributes.Attribute;
|
||||
import net.minecraft.world.entity.ai.attributes.Attributes;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.Items;
|
||||
import net.minecraft.world.item.ShieldItem;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Overwrite;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
|
||||
|
||||
@Mixin(LivingEntity.class)
|
||||
public abstract class AbstractLivingEntityMixin extends Entity {
|
||||
public AbstractLivingEntityMixin(EntityType<?> type, Level world) {
|
||||
super(type, world);
|
||||
}
|
||||
|
||||
@Shadow public abstract double getAttributeValue(Attribute attribute);
|
||||
|
||||
@Shadow public abstract ItemStack getBlockingItem();
|
||||
|
||||
/**
|
||||
* @author Shinkume, NotCoded
|
||||
* @reason Modification of knockback.
|
||||
*/
|
||||
@Overwrite
|
||||
public void knockback(float f, double d, double e) {
|
||||
double g = this.getAttributeValue(Attributes.KNOCKBACK_RESISTANCE);
|
||||
ItemStack itemStack = this.getBlockingItem();
|
||||
if (!itemStack.isEmpty()) {
|
||||
g = Math.min(1.0, g + (double) ShieldItem.getShieldKnockbackResistanceValue(itemStack));
|
||||
}
|
||||
|
||||
f = (float)((double)f * (1.0 - g));
|
||||
|
||||
if (f > 0.0F && Main.config.modifiedKnockback) {
|
||||
this.hasImpulse = true;
|
||||
Vec3 vec3 = this.getDeltaMovement();
|
||||
Vec3 vec32 = (new Vec3(d, 0.0, e)).normalize().scale((double)f);
|
||||
this.setDeltaMovement(vec3.x / 2.0 - vec32.x, this.onGround ? Math.min(0.4, (double)f * 0.75) : Math.min(0.4, vec3.y * 0.5 + (double)f * 0.675), vec3.z / 2.0 - vec32.z);
|
||||
} else if ((!(f <= 0.0F)) && !Main.config.modifiedKnockback) {
|
||||
this.hasImpulse = true;
|
||||
Vec3 vec3 = this.getDeltaMovement();
|
||||
Vec3 vec32 = (new Vec3(d, 0.0, e)).normalize().scale((double)f);
|
||||
this.setDeltaMovement(vec3.x / 2.0 - vec32.x, this.onGround ? Math.min(0.4, (double)f * 0.75) : Math.min(0.4, vec3.y + (double)f * 0.5), vec3.z / 2.0 - vec32.z);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package com.nexia.core.mixin.entity;
|
||||
|
||||
import com.nexia.ffa.utilities.FfaAreas;
|
||||
import net.minecraft.world.InteractionHand;
|
||||
import net.minecraft.world.InteractionResult;
|
||||
import net.minecraft.world.entity.EntityType;
|
||||
import net.minecraft.world.entity.LivingEntity;
|
||||
import net.minecraft.world.entity.decoration.ArmorStand;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
|
||||
@Mixin(ArmorStand.class)
|
||||
public abstract class ArmorStandMixin extends LivingEntity {
|
||||
|
||||
protected ArmorStandMixin(EntityType<? extends LivingEntity> entityType, Level level) {
|
||||
super(entityType, level);
|
||||
}
|
||||
|
||||
@Inject(method = "interactAt", cancellable = true, at = @At("HEAD"))
|
||||
private void canTakeItem(Player player, Vec3 vec3, InteractionHand interactionHand, CallbackInfoReturnable<InteractionResult> cir) {
|
||||
|
||||
// Disable interacting with armor stands in ffa
|
||||
if (FfaAreas.isFfaWorld(level) && !player.isCreative()) {
|
||||
cir.setReturnValue(InteractionResult.FAIL);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package com.nexia.core.mixin.entity;
|
||||
|
||||
import com.nexia.core.games.util.LobbyUtil;
|
||||
import net.minecraft.commands.CommandSource;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.world.Nameable;
|
||||
import net.minecraft.world.damagesource.DamageSource;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.Redirect;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
@Mixin(Entity.class)
|
||||
public abstract class EntityMixin implements Nameable, CommandSource {
|
||||
|
||||
@Shadow public abstract Set<String> getTags();
|
||||
|
||||
@Inject(method = "isInvulnerableTo", at = @At("HEAD"), cancellable = true)
|
||||
private void hurt(DamageSource damageSource, CallbackInfoReturnable<Boolean> cir) {
|
||||
if (damageSource == DamageSource.FALL && getTags().contains(LobbyUtil.NO_FALL_DAMAGE_TAG) || damageSource == DamageSource.FALL && getTags().contains("ffa")) {
|
||||
cir.setReturnValue(true);
|
||||
}
|
||||
}
|
||||
|
||||
@Redirect(method = "baseTick", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/Entity;getY()D"))
|
||||
private double modifyVoidY(Entity instance) {
|
||||
double voidY = -32;
|
||||
|
||||
if (instance.level instanceof ServerLevel) {
|
||||
ServerLevel serverLevel = (ServerLevel)instance.level;
|
||||
}
|
||||
|
||||
return instance.getY() + -64 - voidY;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
package com.nexia.core.mixin.entity;
|
||||
|
||||
import com.nexia.core.Main;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.EntityType;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.entity.projectile.FishingHook;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Overwrite;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
@Mixin(FishingHook.class)
|
||||
public abstract class FishingBobberEntity extends Entity {
|
||||
|
||||
|
||||
public FishingBobberEntity(EntityType<?> type, Level world) {
|
||||
super(type, world);
|
||||
}
|
||||
|
||||
@Shadow private Entity hookedIn;
|
||||
|
||||
@Shadow @Nullable public abstract Player getPlayerOwner();
|
||||
|
||||
/**
|
||||
* @author NotCoded, Shinkume
|
||||
* @reason Make fishing rod hook pull towards the player.
|
||||
*/
|
||||
@Overwrite
|
||||
public void bringInHookedEntity() {
|
||||
Entity entity = this.getPlayerOwner();
|
||||
if (entity != null) {
|
||||
Vec3 vec3;
|
||||
vec3 = (new Vec3(entity.getX() - this.getX(), entity.getY() - this.getY(), entity.getZ() - this.getZ())).scale(0.1);
|
||||
if(Main.config.modifiedRods) {
|
||||
vec3 = (new Vec3(entity.getX() - this.getX()/2, entity.getY() - this.getY()/2, entity.getZ() - this.getZ()/2)).scale(0.2);
|
||||
}
|
||||
this.hookedIn.setDeltaMovement(this.hookedIn.getDeltaMovement().add(vec3));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package com.nexia.core.mixin.entity;
|
||||
|
||||
import com.nexia.minigames.games.bedwars.areas.BwAreas;
|
||||
import com.nexia.minigames.games.bedwars.util.BwUtil;
|
||||
import net.minecraft.world.entity.item.ItemEntity;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
@Mixin(ItemEntity.class)
|
||||
public class ItemEntityMixin {
|
||||
|
||||
@Inject(at = @At("TAIL"), method = "merge(Lnet/minecraft/world/entity/item/ItemEntity;Lnet/minecraft/world/item/ItemStack;Lnet/minecraft/world/item/ItemStack;)V")
|
||||
private static void mergeTail(ItemEntity itemEntity, ItemStack itemStack, ItemStack itemStack2, CallbackInfo ci) {
|
||||
|
||||
if (BwAreas.isBedWarsWorld(itemEntity.level)) {
|
||||
BwUtil.afterItemMerge(itemEntity);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package com.nexia.core.mixin.entity;
|
||||
|
||||
import com.nexia.ffa.utilities.FfaAreas;
|
||||
import net.minecraft.world.InteractionHand;
|
||||
import net.minecraft.world.InteractionResult;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.EntityType;
|
||||
import net.minecraft.world.entity.decoration.ItemFrame;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.level.Level;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
|
||||
@Mixin(ItemFrame.class)
|
||||
public abstract class ItemFrameMixin extends Entity {
|
||||
|
||||
public ItemFrameMixin(EntityType<?> entityType, Level level) {
|
||||
super(entityType, level);
|
||||
}
|
||||
|
||||
@Inject(method = "interact", cancellable = true, at = @At("HEAD"))
|
||||
private void canTakeItem(Player player, InteractionHand interactionHand, CallbackInfoReturnable<InteractionResult> cir) {
|
||||
|
||||
// Disable interacting with armor stands in ffa
|
||||
if (FfaAreas.isFfaWorld(level) && !player.isCreative()) {
|
||||
cir.setReturnValue(InteractionResult.FAIL);
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package com.nexia.core.mixin.entity;
|
||||
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.EntityType;
|
||||
import net.minecraft.world.entity.projectile.Fireball;
|
||||
import net.minecraft.world.entity.projectile.LargeFireball;
|
||||
import net.minecraft.world.level.Explosion;
|
||||
import net.minecraft.world.level.Level;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.ModifyArg;
|
||||
|
||||
@Mixin(LargeFireball.class)
|
||||
public class LargeFireballMixin extends Fireball {
|
||||
|
||||
public LargeFireballMixin(EntityType<? extends Fireball> entityType, Level level) {
|
||||
super(entityType, level);
|
||||
}
|
||||
|
||||
// Set fireball entity to fireball
|
||||
@ModifyArg(method = "onHit", index = 0, at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/Level;explode(Lnet/minecraft/world/entity/Entity;DDDFZLnet/minecraft/world/level/Explosion$BlockInteraction;)Lnet/minecraft/world/level/Explosion;"))
|
||||
protected Entity onHitSetEntity(@Nullable Entity entity) {
|
||||
return this;
|
||||
}
|
||||
|
||||
// Remove fire from fireballs
|
||||
@ModifyArg(method = "onHit", index = 5, at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/Level;explode(Lnet/minecraft/world/entity/Entity;DDDFZLnet/minecraft/world/level/Explosion$BlockInteraction;)Lnet/minecraft/world/level/Explosion;"))
|
||||
protected boolean onHitRemoveFire(boolean doFire) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Make block destruction mobGriefing independent
|
||||
@ModifyArg(method = "onHit", index = 6, at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/Level;explode(Lnet/minecraft/world/entity/Entity;DDDFZLnet/minecraft/world/level/Explosion$BlockInteraction;)Lnet/minecraft/world/level/Explosion;"))
|
||||
protected Explosion.BlockInteraction onHitSetBlockInteraction(Explosion.BlockInteraction blockInteraction) {
|
||||
return Explosion.BlockInteraction.DESTROY;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
package com.nexia.core.mixin.entity;
|
||||
|
||||
import com.nexia.core.games.util.PlayerGameMode;
|
||||
import com.nexia.core.utilities.player.PlayerDataManager;
|
||||
import com.nexia.minigames.games.bedwars.areas.BwAreas;
|
||||
import com.nexia.minigames.games.bedwars.util.BwUtil;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.CombatRules;
|
||||
import net.minecraft.world.damagesource.DamageSource;
|
||||
import net.minecraft.world.entity.LivingEntity;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.ModifyArg;
|
||||
import org.spongepowered.asm.mixin.injection.Redirect;
|
||||
|
||||
@Mixin(LivingEntity.class)
|
||||
public class LivingEntityMixin {
|
||||
|
||||
// Make void death instant
|
||||
@ModifyArg(method = "hurt", index = 1, at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/LivingEntity;actuallyHurt(Lnet/minecraft/world/damagesource/DamageSource;F)V"))
|
||||
protected float hurt(DamageSource damageSource, float value) {
|
||||
if((Object)this instanceof ServerPlayer){
|
||||
ServerPlayer player = (ServerPlayer)(Object)this;
|
||||
|
||||
if(PlayerDataManager.get(player).gameMode == PlayerGameMode.DUELS) {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
if (damageSource == DamageSource.OUT_OF_WORLD) return 1000000.0F;
|
||||
return value;
|
||||
}
|
||||
|
||||
@Redirect(method = "getDamageAfterMagicAbsorb", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/CombatRules;getDamageAfterMagicAbsorb(FF)F"))
|
||||
private float redirectArmorProtCalculation(float damage, float protection) {
|
||||
if ((Object)this instanceof ServerPlayer) {
|
||||
ServerPlayer player = (ServerPlayer)(Object)this;
|
||||
|
||||
if (BwAreas.isBedWarsWorld(player.getLevel())) {
|
||||
return BwUtil.playerProtCalculation(damage, protection);
|
||||
}
|
||||
|
||||
}
|
||||
return CombatRules.getDamageAfterMagicAbsorb(damage, protection);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package com.nexia.core.mixin.entity;
|
||||
|
||||
import com.nexia.minigames.games.bedwars.custom.BwBridgeEgg;
|
||||
import net.minecraft.world.entity.projectile.ThrownEgg;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Redirect;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
@Mixin(ThrownEgg.class)
|
||||
public class ThrownEggMixin {
|
||||
|
||||
@Redirect(method = "onHit", at = @At(value = "INVOKE", ordinal = 0, target = "Ljava/util/Random;nextInt(I)I"))
|
||||
private int modifyChickenSpawnOdds(Random random, int bound) {
|
||||
|
||||
// Spawns chicken if return value is 0
|
||||
if ((Object)this instanceof BwBridgeEgg) {
|
||||
return 1;
|
||||
}
|
||||
return random.nextInt(bound);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package com.nexia.core.mixin.entity;
|
||||
|
||||
import com.nexia.minigames.games.bedwars.util.BwUtil;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.entity.EntityType;
|
||||
import net.minecraft.world.entity.projectile.ThrowableItemProjectile;
|
||||
import net.minecraft.world.entity.projectile.ThrownEnderpearl;
|
||||
import net.minecraft.world.level.Level;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.ModifyArg;
|
||||
|
||||
@Mixin(ThrownEnderpearl.class)
|
||||
public abstract class ThrownEnderpearlMixin extends ThrowableItemProjectile {
|
||||
|
||||
public ThrownEnderpearlMixin(EntityType<? extends ThrowableItemProjectile> entityType, Level level) {
|
||||
super(entityType, level);
|
||||
}
|
||||
|
||||
@ModifyArg(method = "onHit", index = 1, at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/Entity;hurt(Lnet/minecraft/world/damagesource/DamageSource;F)Z"))
|
||||
private float pearlDamage(float damage) {
|
||||
if (getOwner() instanceof ServerPlayer) {
|
||||
ServerPlayer thrower = (ServerPlayer) getOwner();
|
||||
|
||||
if (BwUtil.isInBedWars(thrower)) {
|
||||
return BwUtil.getPearlDamage();
|
||||
}
|
||||
|
||||
}
|
||||
return damage;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
package com.nexia.core.mixin.entity;
|
||||
|
||||
import com.nexia.minigames.games.bedwars.custom.BwTrident;
|
||||
import net.minecraft.world.entity.EntityType;
|
||||
import net.minecraft.world.entity.LivingEntity;
|
||||
import net.minecraft.world.entity.projectile.AbstractArrow;
|
||||
import net.minecraft.world.entity.projectile.ThrownTrident;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.enchantment.EnchantmentHelper;
|
||||
import net.minecraft.world.level.Level;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Overwrite;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Redirect;
|
||||
|
||||
@Mixin(ThrownTrident.class)
|
||||
public abstract class ThrownTridentMixin extends AbstractArrow {
|
||||
protected ThrownTridentMixin(EntityType<? extends AbstractArrow> entityType, Level level) {
|
||||
super(entityType, level);
|
||||
}
|
||||
|
||||
/**
|
||||
* @author NotCoded
|
||||
* @reason Remove trident despawning.
|
||||
*/
|
||||
@Overwrite
|
||||
public void tickDespawn(){
|
||||
if(this.pickup != Pickup.ALLOWED) {
|
||||
super.tickDespawn();
|
||||
}
|
||||
}
|
||||
|
||||
@Redirect(method = "onHitEntity", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/item/enchantment/EnchantmentHelper;getDamageBonus(Lnet/minecraft/world/item/ItemStack;Lnet/minecraft/world/entity/LivingEntity;)F"))
|
||||
private float getDamageBonus(ItemStack itemStack, LivingEntity livingEntity) {
|
||||
float bonus = EnchantmentHelper.getDamageBonus(itemStack, livingEntity);
|
||||
|
||||
if ((Object)this instanceof BwTrident) {
|
||||
bonus -= 1;
|
||||
}
|
||||
|
||||
return bonus;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package com.nexia.core.mixin.item;
|
||||
|
||||
import com.nexia.minigames.games.bedwars.areas.BwAreas;
|
||||
import com.nexia.minigames.games.bedwars.players.BwPlayerEvents;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.InteractionResult;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.item.AxeItem;
|
||||
import net.minecraft.world.item.context.UseOnContext;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
|
||||
@Mixin(AxeItem.class)
|
||||
public class AxeItemMixin {
|
||||
|
||||
@Inject(method = "useOn", cancellable = true, at = @At(value = "INVOKE", target = "Lnet/minecraft/world/item/context/UseOnContext;getPlayer()Lnet/minecraft/world/entity/player/Player;"))
|
||||
private void stripeWood(UseOnContext context, CallbackInfoReturnable<InteractionResult> cir) {
|
||||
Player playerEntity = context.getPlayer();
|
||||
if (!(playerEntity instanceof ServerPlayer)) return;
|
||||
ServerPlayer player = (ServerPlayer) playerEntity;
|
||||
|
||||
if (BwAreas.isBedWarsWorld(context.getLevel())) {
|
||||
if (!BwPlayerEvents.beforeStripWood(player, context)) {
|
||||
cir.setReturnValue(InteractionResult.PASS);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package com.nexia.core.mixin.item;
|
||||
|
||||
import com.nexia.minigames.games.bedwars.areas.BwAreas;
|
||||
import com.nexia.minigames.games.bedwars.players.BwPlayerEvents;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.InteractionResult;
|
||||
import net.minecraft.world.item.BlockItem;
|
||||
import net.minecraft.world.item.context.BlockPlaceContext;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
|
||||
@Mixin(BlockItem.class)
|
||||
public abstract class BlockItemMixin {
|
||||
|
||||
@Inject(method = "place", cancellable = true, at = @At(value = "INVOKE", target = "Lnet/minecraft/world/item/BlockItem;placeBlock(Lnet/minecraft/world/item/context/BlockPlaceContext;Lnet/minecraft/world/level/block/state/BlockState;)Z"))
|
||||
private void beforePlace(BlockPlaceContext context, CallbackInfoReturnable<InteractionResult> cir) {
|
||||
ServerPlayer player = (ServerPlayer)context.getPlayer();
|
||||
if (player == null) return;
|
||||
BlockPos blockPos = context.getClickedPos();
|
||||
ServerLevel level = player.getLevel();
|
||||
|
||||
if (BwAreas.isBedWarsWorld(player.getLevel()) && !BwPlayerEvents.beforePlace(player, context)) {
|
||||
cir.setReturnValue(InteractionResult.PASS);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package com.nexia.core.mixin.item;
|
||||
|
||||
import com.nexia.minigames.games.bedwars.areas.BwAreas;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.item.CompassItem;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.level.Level;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.Redirect;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
@Mixin(CompassItem.class)
|
||||
public class CompassItemMixin {
|
||||
|
||||
Level level;
|
||||
@Inject(at = @At("HEAD"), method = "inventoryTick")
|
||||
private void tick(ItemStack itemStack, Level level, Entity entity, int i, boolean bl, CallbackInfo ci) {
|
||||
this.level = level;
|
||||
}
|
||||
|
||||
// Not require a lodestone block in order to track someone in oldbedwars
|
||||
@Redirect(method = "inventoryTick", at = @At(value = "INVOKE", target = "Lnet/minecraft/nbt/CompoundTag;remove(Ljava/lang/String;)V"))
|
||||
private void existsAtPosition(CompoundTag instance, String string) {
|
||||
|
||||
if (BwAreas.isBedWarsWorld(level)) return;
|
||||
instance.remove(string);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
package com.nexia.core.mixin.item;
|
||||
|
||||
import com.nexia.core.utilities.item.ItemStackUtil;
|
||||
import com.nexia.minigames.games.bedwars.util.BwUtil;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.inventory.CraftingContainer;
|
||||
import net.minecraft.world.inventory.CraftingMenu;
|
||||
import net.minecraft.world.inventory.ResultContainer;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.level.Level;
|
||||
import org.spongepowered.asm.mixin.Final;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.ModifyArg;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
@Mixin(CraftingMenu.class)
|
||||
public class CraftingMixin {
|
||||
|
||||
@Shadow @Final private Player player;
|
||||
// Set crafter to player
|
||||
private static ServerPlayer crafter;
|
||||
@Inject(method = "slotChangedCraftingGrid", at = @At("HEAD"))
|
||||
private static void craft(int i, Level level, Player player, CraftingContainer craftingContainer, ResultContainer resultContainer, CallbackInfo ci) {
|
||||
if (player instanceof ServerPlayer) {
|
||||
crafter = (ServerPlayer) player;
|
||||
}
|
||||
}
|
||||
|
||||
// Disable crafting for bedwars players
|
||||
@ModifyArg(method = "slotChangedCraftingGrid", index = 1, at = @At(value = "INVOKE", target = "Lnet/minecraft/world/inventory/ResultContainer;setItem(ILnet/minecraft/world/item/ItemStack;)V"))
|
||||
private static ItemStack setCraftResult(ItemStack itemStack) {
|
||||
if (crafter == null) return itemStack;
|
||||
|
||||
if (BwUtil.isInBedWars(crafter)) {
|
||||
ItemStackUtil.sendInventoryRefreshPacket(crafter);
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
return itemStack;
|
||||
}
|
||||
|
||||
@ModifyArg(method = "slotChangedCraftingGrid", index = 2, at = @At(value = "INVOKE", target = "Lnet/minecraft/network/protocol/game/ClientboundContainerSetSlotPacket;<init>(IILnet/minecraft/world/item/ItemStack;)V"))
|
||||
private static ItemStack setCraftResultPacketItem(ItemStack itemStack) {
|
||||
if (crafter == null) return itemStack;
|
||||
|
||||
if (BwUtil.isInBedWars(crafter)) {
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
return itemStack;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
package com.nexia.core.mixin.item;
|
||||
|
||||
import com.nexia.minigames.games.bedwars.areas.BwAreas;
|
||||
import com.nexia.minigames.games.bedwars.players.BwPlayerEvents;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.InteractionHand;
|
||||
import net.minecraft.world.InteractionResultHolder;
|
||||
import net.minecraft.world.entity.LivingEntity;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.entity.projectile.ThrownEgg;
|
||||
import net.minecraft.world.item.EggItem;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.level.Level;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.Redirect;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
|
||||
@Mixin(EggItem.class)
|
||||
public class EggItemMixin {
|
||||
|
||||
private InteractionHand hand;
|
||||
|
||||
@Inject(method = "use", at = @At("HEAD"))
|
||||
private void use(Level level, Player player, InteractionHand interactionHand, CallbackInfoReturnable<InteractionResultHolder<ItemStack>> cir) {
|
||||
this.hand = interactionHand;
|
||||
}
|
||||
|
||||
@Redirect(method = "use", at = @At(value = "NEW", target = "net/minecraft/world/entity/projectile/ThrownEgg"))
|
||||
private ThrownEgg setThrownEgg(Level level, LivingEntity livingEntity) {
|
||||
|
||||
if (livingEntity instanceof ServerPlayer) {
|
||||
ServerPlayer player = (ServerPlayer) livingEntity;
|
||||
|
||||
if (BwAreas.isBedWarsWorld(level)) {
|
||||
return BwPlayerEvents.throwEgg(player, player.getItemInHand(hand));
|
||||
}
|
||||
|
||||
}
|
||||
return new ThrownEgg(level, livingEntity);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
package com.nexia.core.mixin.item;
|
||||
|
||||
import com.nexia.core.utilities.item.ItemStackUtil;
|
||||
import com.nexia.minigames.games.bedwars.players.BwPlayerEvents;
|
||||
import com.nexia.minigames.games.bedwars.util.BwUtil;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.entity.LivingEntity;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.Items;
|
||||
import net.minecraft.world.item.PotionItem;
|
||||
import net.minecraft.world.level.ItemLike;
|
||||
import net.minecraft.world.level.Level;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.Redirect;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
|
||||
@Mixin(PotionItem.class)
|
||||
public class PotionItemMixin {
|
||||
|
||||
private ServerPlayer player = null;
|
||||
|
||||
@Inject(method = "finishUsingItem", at = @At("HEAD"))
|
||||
private void finishUsingItem(ItemStack itemStack, Level level, LivingEntity livingEntity, CallbackInfoReturnable<ItemStack> cir) {
|
||||
if (livingEntity instanceof ServerPlayer) {
|
||||
this.player = (ServerPlayer) livingEntity;
|
||||
}
|
||||
}
|
||||
|
||||
@Inject(method = "finishUsingItem", at = @At("RETURN"))
|
||||
private void finishedUsingItem(ItemStack itemStack, Level level, LivingEntity livingEntity, CallbackInfoReturnable<ItemStack> cir) {
|
||||
if (this.player == null) return;
|
||||
|
||||
if (BwUtil.isBedWarsPlayer(this.player)) {
|
||||
BwPlayerEvents.drankPotion(this.player, itemStack);
|
||||
}
|
||||
}
|
||||
|
||||
@Redirect(method = "finishUsingItem", at = @At(value = "NEW", target = "net/minecraft/world/item/ItemStack"))
|
||||
private ItemStack setItemAfterDrink(ItemLike itemLike) {
|
||||
if (player == null) return new ItemStack(Items.GLASS_BOTTLE);
|
||||
|
||||
if (BwUtil.isBedWarsPlayer(player)) {
|
||||
ItemStackUtil.sendInventoryRefreshPacket(player);
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
return new ItemStack(Items.GLASS_BOTTLE);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
package com.nexia.core.mixin.item;
|
||||
|
||||
|
||||
import com.nexia.ffa.utilities.FfaAreas;
|
||||
import com.nexia.minigames.games.bedwars.players.BwPlayerEvents;
|
||||
import com.nexia.minigames.games.bedwars.util.BwUtil;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.entity.LivingEntity;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.entity.projectile.ThrownTrident;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.TridentItem;
|
||||
import net.minecraft.world.level.Level;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.Redirect;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
@Mixin(TridentItem.class)
|
||||
public class TridentItemMixin {
|
||||
|
||||
@Redirect(method = "releaseUsing", at = @At(value = "NEW", target = "net/minecraft/world/entity/projectile/ThrownTrident"))
|
||||
private ThrownTrident setThrownTrident(Level level, LivingEntity livingEntity, ItemStack itemStack) {
|
||||
|
||||
if (livingEntity instanceof ServerPlayer) {
|
||||
ServerPlayer player = (ServerPlayer) livingEntity;
|
||||
|
||||
if (BwUtil.isBedWarsPlayer(player)) {
|
||||
return BwPlayerEvents.throwTrident(player, itemStack);
|
||||
}
|
||||
|
||||
}
|
||||
return new ThrownTrident(level, livingEntity, itemStack);
|
||||
}
|
||||
|
||||
|
||||
@Inject(method = "releaseUsing", at = @At(value = "HEAD"), cancellable = true)
|
||||
public void changeHoldTime(ItemStack itemStack, Level level, LivingEntity livingEntity, int i, CallbackInfo ci) {
|
||||
if(livingEntity instanceof Player player){
|
||||
if(FfaAreas.isInFfaSpawn(player)) { ci.cancel(); }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package com.nexia.core.mixin.item;
|
||||
|
||||
import com.nexia.core.games.util.PlayerGameMode;
|
||||
import com.nexia.core.gui.PlayGUI;
|
||||
import com.nexia.core.gui.RankGUI;
|
||||
import com.nexia.core.utilities.player.PlayerData;
|
||||
import com.nexia.core.utilities.player.PlayerDataManager;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.InteractionHand;
|
||||
import net.minecraft.world.InteractionResultHolder;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.level.Level;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
|
||||
@Mixin(Item.class)
|
||||
public class UseItemMixin {
|
||||
@Inject(method = "use", at = @At("HEAD"))
|
||||
private void changeUse(Level level, Player player, InteractionHand interactionHand, CallbackInfoReturnable<InteractionResultHolder<ItemStack>> cir){
|
||||
PlayerGameMode gameMode = PlayerDataManager.get(player).gameMode;
|
||||
if(player.getItemInHand(interactionHand).getDisplayName().getString().toLowerCase().contains("gamemode selector") && gameMode == PlayerGameMode.LOBBY) {
|
||||
PlayGUI.openMainGUI((ServerPlayer) player);
|
||||
}
|
||||
if(player.getItemInHand(interactionHand).getDisplayName().getString().toLowerCase().contains("prefix selector") && gameMode == PlayerGameMode.LOBBY) {
|
||||
RankGUI.openRankGUI((ServerPlayer) player);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package com.nexia.core.mixin.misc;
|
||||
|
||||
import com.nexia.core.utilities.misc.EventUtil;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.inventory.AbstractContainerMenu;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
@Mixin(AbstractContainerMenu.class)
|
||||
public class AbstractContainerMenuMixin {
|
||||
|
||||
@Inject(method = "removed", cancellable = true, at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/player/Player;drop(Lnet/minecraft/world/item/ItemStack;Z)Lnet/minecraft/world/entity/item/ItemEntity;"))
|
||||
private void removed(Player player, CallbackInfo ci) {
|
||||
if (!(player instanceof ServerPlayer serverPlayer)) return;
|
||||
|
||||
if (!EventUtil.dropItem(serverPlayer, player.inventory.getCarried())) {
|
||||
if (player.inventory.add(player.inventory.getCarried())) {
|
||||
player.inventory.setCarried(ItemStack.EMPTY);
|
||||
}
|
||||
ci.cancel();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.nexia.core.mixin.misc;
|
||||
|
||||
import com.mojang.brigadier.CommandDispatcher;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
import net.minecraft.server.commands.BanPlayerCommands;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
@Mixin(BanPlayerCommands.class)
|
||||
public class BanCommandMixin {
|
||||
@Inject(method = "register", cancellable = true, at = @At("HEAD"))
|
||||
private static void register(CommandDispatcher<CommandSourceStack> commandDispatcher, CallbackInfo ci) {
|
||||
// Fuck you v2.0
|
||||
ci.cancel();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package com.nexia.core.mixin.misc;
|
||||
|
||||
import net.minecraft.commands.CommandSource;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.spongepowered.asm.mixin.Final;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
@Mixin(CommandSourceStack.class)
|
||||
public class CommandSourceStackMixin {
|
||||
|
||||
@Shadow @Final private CommandSource source;
|
||||
|
||||
@Shadow @Final private @Nullable Entity entity;
|
||||
|
||||
@Inject(method = "broadcastToAdmins", cancellable = true, at = @At("HEAD"))
|
||||
private void broadcastToAdmins(Component component, CallbackInfo ci) {
|
||||
|
||||
// If sourced from datapack
|
||||
if (source instanceof MinecraftServer && entity != null) {
|
||||
ci.cancel();
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
package com.nexia.core.mixin.misc;
|
||||
|
||||
import com.nexia.minigames.games.bedwars.areas.BwAreas;
|
||||
import com.nexia.minigames.games.bedwars.util.BwUtil;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.level.BlockGetter;
|
||||
import net.minecraft.world.level.Explosion;
|
||||
import net.minecraft.world.level.ExplosionDamageCalculator;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.material.FluidState;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.spongepowered.asm.mixin.Final;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.injection.*;
|
||||
import org.spongepowered.asm.mixin.injection.invoke.arg.Args;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
@Mixin(Explosion.class)
|
||||
public class ExplosionMixin {
|
||||
|
||||
@Shadow @Final private @Nullable Entity source;
|
||||
|
||||
@Shadow @Final private Level level;
|
||||
|
||||
@Redirect(method = "explode", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/ExplosionDamageCalculator;getBlockExplosionResistance(Lnet/minecraft/world/level/Explosion;Lnet/minecraft/world/level/BlockGetter;Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;Lnet/minecraft/world/level/material/FluidState;)Ljava/util/Optional;"))
|
||||
protected Optional<Float> modifyExplosionResistance(ExplosionDamageCalculator instance, Explosion explosion, BlockGetter blockGetter, BlockPos blockPos, BlockState blockState, FluidState fluidState) {
|
||||
if (blockState.isAir() && fluidState.isEmpty()) return Optional.empty();
|
||||
|
||||
float resistance = blockState.getBlock().getExplosionResistance();
|
||||
if (BwAreas.isBedWarsWorld(level)) {
|
||||
resistance = BwUtil.modifyBlockExplosionRes(blockPos, blockState, source, resistance);
|
||||
}
|
||||
return Optional.of(Math.max(resistance, fluidState.getExplosionResistance()));
|
||||
}
|
||||
|
||||
@Redirect(method = "explode", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/ExplosionDamageCalculator;shouldBlockExplode(Lnet/minecraft/world/level/Explosion;Lnet/minecraft/world/level/BlockGetter;Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;F)Z"))
|
||||
protected boolean shouldExplode(ExplosionDamageCalculator instance, Explosion explosion, BlockGetter blockGetter, BlockPos blockPos, BlockState blockState, float resistance) {
|
||||
|
||||
if (BwAreas.isBedWarsWorld(level)) {
|
||||
if (!BwUtil.shouldExplode(blockPos, blockState)) return false;
|
||||
}
|
||||
|
||||
return instance.shouldBlockExplode(explosion, blockGetter, blockPos, blockState, resistance);
|
||||
}
|
||||
|
||||
@ModifyArgs(method = "explode", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/phys/Vec3;add(DDD)Lnet/minecraft/world/phys/Vec3;"))
|
||||
protected void modifyKnockback(Args args) {
|
||||
|
||||
if (BwAreas.isBedWarsWorld(level)) {
|
||||
BwUtil.modifyExplosionKb(source, args);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ModifyArg(method = "explode", index = 1, at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/Entity;hurt(Lnet/minecraft/world/damagesource/DamageSource;F)Z"))
|
||||
protected float modifyDamage(float damage) {
|
||||
|
||||
if (BwAreas.isBedWarsWorld(level)) {
|
||||
return BwUtil.getExplosionDamage(damage);
|
||||
}
|
||||
|
||||
return damage;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package com.nexia.core.mixin.misc;
|
||||
|
||||
import com.nexia.core.utilities.time.ServerTime;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
@Mixin(MinecraftServer.class)
|
||||
public class MinecraftServerMixin {
|
||||
|
||||
boolean firstTickPassed = false;
|
||||
|
||||
@Inject(at = @At("HEAD"), method = "tickChildren")
|
||||
private void tickHead(CallbackInfo ci) {
|
||||
if (!firstTickPassed) {
|
||||
firstTickPassed = true;
|
||||
ServerTime.firstTick((MinecraftServer)(Object)this);
|
||||
}
|
||||
}
|
||||
|
||||
@Inject(at = @At("TAIL"), method = "tickChildren")
|
||||
private void tickTail(CallbackInfo ci) {
|
||||
ServerTime.everyTick();
|
||||
}
|
||||
|
||||
@Inject(method = "stopServer", at = @At("HEAD"))
|
||||
protected void stopServer(CallbackInfo ci) {
|
||||
ServerTime.stopServer();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.nexia.core.mixin.misc;
|
||||
|
||||
import com.mojang.brigadier.CommandDispatcher;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
import net.minecraft.server.commands.MsgCommand;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
@Mixin(MsgCommand.class)
|
||||
public class MsgCommandMixin {
|
||||
|
||||
@Inject(method = "register", cancellable = true, at = @At("HEAD"))
|
||||
private static void register(CommandDispatcher<CommandSourceStack> commandDispatcher, CallbackInfo ci) {
|
||||
// Fuck you
|
||||
ci.cancel();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.nexia.core.mixin.misc;
|
||||
|
||||
import com.mojang.brigadier.CommandDispatcher;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
import net.minecraft.server.commands.BanPlayerCommands;
|
||||
import net.minecraft.server.commands.PardonCommand;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
@Mixin(PardonCommand.class)
|
||||
public class PardonCommandMixin {
|
||||
@Inject(method = "register", cancellable = true, at = @At("HEAD"))
|
||||
private static void register(CommandDispatcher<CommandSourceStack> commandDispatcher, CallbackInfo ci) {
|
||||
// Fuck you v2.1
|
||||
ci.cancel();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
package com.nexia.core.mixin.player;
|
||||
|
||||
import com.nexia.core.utilities.player.PlayerData;
|
||||
import com.nexia.core.utilities.player.PlayerDataManager;
|
||||
import com.nexia.minigames.games.bedwars.areas.BwAreas;
|
||||
import com.nexia.minigames.games.bedwars.players.BwPlayerEvents;
|
||||
import com.nexia.minigames.games.bedwars.util.BwUtil;
|
||||
import com.nexia.minigames.games.oitc.OitcGame;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.food.FoodData;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.ModifyArg;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
@Mixin(FoodData.class)
|
||||
public abstract class FoodDataMixin {
|
||||
|
||||
@Shadow private int foodLevel;
|
||||
Player player;
|
||||
@Inject(at = @At("HEAD"), method = "tick")
|
||||
private void tick(Player player, CallbackInfo ci) {
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
// Nerf healing while in combat
|
||||
@ModifyArg(method = "tick", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/player/Player;heal(F)V"))
|
||||
private float heal(float par1) {
|
||||
if (!(player instanceof ServerPlayer serverPlayer)) return 1f;
|
||||
|
||||
if (BwAreas.isBedWarsWorld(serverPlayer.level)) {
|
||||
return 0.5f;
|
||||
}
|
||||
|
||||
if(OitcGame.isOITCPlayer(serverPlayer)) {
|
||||
return 0.0f;
|
||||
}
|
||||
|
||||
return 1f;
|
||||
}
|
||||
|
||||
@Inject(method = "tick", at = @At("TAIL"))
|
||||
private void modifyHunger(Player player, CallbackInfo ci) {
|
||||
if (!(player instanceof ServerPlayer serverPlayer)) return;
|
||||
|
||||
if (BwUtil.isInBedWars(serverPlayer)) {
|
||||
BwPlayerEvents.afterHungerTick((FoodData)(Object)this);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,191 @@
|
||||
package com.nexia.core.mixin.player;
|
||||
|
||||
import com.nexia.core.Main;
|
||||
import com.nexia.core.games.util.LobbyUtil;
|
||||
import com.nexia.core.utilities.chat.ChatFormat;
|
||||
import com.nexia.core.utilities.chat.PlayerMutes;
|
||||
import com.nexia.core.utilities.player.PlayerDataManager;
|
||||
import com.nexia.core.utilities.player.PlayerUtil;
|
||||
import com.nexia.core.utilities.time.ServerTime;
|
||||
import com.nexia.ffa.utilities.player.SavedPlayerData;
|
||||
import com.nexia.minigames.games.bedwars.players.BwPlayerEvents;
|
||||
import com.nexia.minigames.games.bedwars.util.BwUtil;
|
||||
import net.minecraft.ChatFormatting;
|
||||
import net.minecraft.Util;
|
||||
import net.minecraft.network.Connection;
|
||||
import net.minecraft.network.chat.*;
|
||||
import net.minecraft.network.protocol.Packet;
|
||||
import net.minecraft.network.protocol.login.ServerLoginPacketListener;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.server.players.PlayerList;
|
||||
import net.minecraft.stats.Stats;
|
||||
import org.spongepowered.asm.mixin.Final;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.ModifyArgs;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
import org.spongepowered.asm.mixin.injection.invoke.arg.Args;
|
||||
|
||||
@Mixin(PlayerList.class)
|
||||
public abstract class PlayerListMixin {
|
||||
|
||||
// Create player data on join
|
||||
@Inject(at = @At("HEAD"), method = "placeNewPlayer")
|
||||
private void placeNewPlayerHead(Connection connection, ServerPlayer player, CallbackInfo ci) {
|
||||
PlayerDataManager.addPlayerData(player);
|
||||
com.nexia.ffa.utilities.player.PlayerDataManager.addPlayerData(player);
|
||||
com.nexia.minigames.games.duels.util.player.PlayerDataManager.addPlayerData(player);
|
||||
if(player.getStats().getValue(Stats.CUSTOM.get(Stats.LEAVE_GAME)) <= 1) {
|
||||
if(Main.config.serverFirstJoinCommands.length >= 2 && !ChatFormat.hasWhiteSpacesOrSpaces(Main.config.serverFirstJoinCommands, null)){
|
||||
for(int i = 0; i < Main.config.serverFirstJoinCommands.length; i++){
|
||||
PlayerUtil.executeServerCommand(Main.config.serverFirstJoinCommands[i], player);
|
||||
}
|
||||
} else if(Main.config.serverFirstJoinCommands.length <= 1 && !ChatFormat.hasWhiteSpacesOrSpaces(Main.config.serverFirstJoinCommands, null)){
|
||||
PlayerUtil.executeServerCommand(Main.config.serverFirstJoinCommands[0], player);
|
||||
}
|
||||
if(Main.config.playerFirstJoinCommands.length >= 2 && !ChatFormat.hasWhiteSpacesOrSpaces(Main.config.playerFirstJoinCommands, null)){
|
||||
for(int i = 0; i < Main.config.playerFirstJoinCommands.length; i++){
|
||||
PlayerUtil.executePlayerCommand(player, Main.config.playerFirstJoinCommands[i]);
|
||||
}
|
||||
} else if(Main.config.playerFirstJoinCommands.length <= 1 && !ChatFormat.hasWhiteSpacesOrSpaces(Main.config.playerFirstJoinCommands, null)){
|
||||
PlayerUtil.executePlayerCommand(player, Main.config.playerFirstJoinCommands[0]);
|
||||
}
|
||||
}
|
||||
if(Main.config.serverJoinCommands.length >= 2 && !ChatFormat.hasWhiteSpacesOrSpaces(Main.config.serverJoinCommands, null)){
|
||||
for(int i = 0; i < Main.config.serverJoinCommands.length; i++){
|
||||
PlayerUtil.executeServerCommand(Main.config.serverJoinCommands[i], player);
|
||||
}
|
||||
} else if(Main.config.serverJoinCommands.length <= 1 && !ChatFormat.hasWhiteSpacesOrSpaces(Main.config.serverJoinCommands, null)){
|
||||
PlayerUtil.executeServerCommand(Main.config.serverJoinCommands[0], player);
|
||||
}
|
||||
if(Main.config.playerJoinCommands.length >= 2 && !ChatFormat.hasWhiteSpacesOrSpaces(Main.config.serverJoinCommands, null)){
|
||||
for(int i = 0; i < Main.config.playerJoinCommands.length; i++){
|
||||
PlayerUtil.executePlayerCommand(player, Main.config.playerJoinCommands[i]);
|
||||
}
|
||||
} else if(Main.config.playerJoinCommands.length <= 1 && !ChatFormat.hasWhiteSpacesOrSpaces(Main.config.playerJoinCommands, null)){
|
||||
PlayerUtil.executePlayerCommand(player, Main.config.playerJoinCommands[0]);
|
||||
}
|
||||
}
|
||||
|
||||
// Create player data on join
|
||||
@Inject(at = @At("TAIL"), method = "placeNewPlayer")
|
||||
private void placeNewPlayerTail(Connection connection, ServerPlayer player, CallbackInfo ci) {
|
||||
LobbyUtil.leaveAllGames(player, true);
|
||||
player.sendMessage(new TextComponent(ChatFormat.separatorLine("Welcome")), Util.NIL_UUID);
|
||||
player.sendMessage(ChatFormat.format(" §8» {b1}Welcome {b2}{} {b1}to {b2}Nexia{b1}!", player.getScoreboardName()), Util.NIL_UUID);
|
||||
player.sendMessage(ChatFormat.format(" §8» {b1}Players online: {b2}{}", Main.server.getPlayerCount()), Util.NIL_UUID);
|
||||
player.sendMessage(ChatFormat.format(" §8» {b1}Read the rules: {b2}/rules"), Util.NIL_UUID);
|
||||
player.sendMessage(ChatFormat.format(" §8» {b1}Join our discord: ").append(new TextComponent(ChatFormat.brandColor2 + "\247n" + Main.config.discordLink).withStyle(style -> style.withClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, Main.config.discordLink)))), Util.NIL_UUID);
|
||||
player.sendMessage(new TextComponent(ChatFormat.separatorLine(null)), Util.NIL_UUID);
|
||||
}
|
||||
|
||||
// Force-leave on server leave
|
||||
|
||||
@Inject(at = @At("HEAD"), method = "remove")
|
||||
private void removeHead(ServerPlayer player, CallbackInfo ci) {
|
||||
LobbyUtil.leaveAllGames(player, false);
|
||||
if(Main.config.serverLeaveCommands.length >= 2 && !ChatFormat.hasWhiteSpacesOrSpaces(Main.config.serverLeaveCommands, null)){
|
||||
for(int i = 0; i < Main.config.serverLeaveCommands.length; i++){
|
||||
PlayerUtil.executeServerCommand(Main.config.serverLeaveCommands[i], player);
|
||||
}
|
||||
} else if(Main.config.serverFirstJoinCommands.length <= 1 && !ChatFormat.hasWhiteSpacesOrSpaces(Main.config.serverFirstJoinCommands, null)){
|
||||
PlayerUtil.executeServerCommand(Main.config.serverLeaveCommands[0], player);
|
||||
}
|
||||
if(Main.config.playerLeaveCommands.length >= 2 && !ChatFormat.hasWhiteSpacesOrSpaces(Main.config.playerLeaveCommands, null)){
|
||||
for(int i = 0; i < Main.config.playerLeaveCommands.length; i++){
|
||||
PlayerUtil.executePlayerCommand(player, Main.config.playerLeaveCommands[i]);
|
||||
}
|
||||
} else if(Main.config.playerLeaveCommands.length <= 1 && !ChatFormat.hasWhiteSpacesOrSpaces(Main.config.playerLeaveCommands, null)){
|
||||
PlayerUtil.executePlayerCommand(player, Main.config.playerLeaveCommands[0]);
|
||||
}
|
||||
}
|
||||
|
||||
// Clear player data on leave
|
||||
@Inject(at = @At("TAIL"), method = "remove")
|
||||
private void removeTail(ServerPlayer player, CallbackInfo ci) {
|
||||
PlayerDataManager.removePlayerData(player);
|
||||
com.nexia.ffa.utilities.player.PlayerDataManager.removePlayerData(player);
|
||||
com.nexia.minigames.games.duels.util.player.PlayerDataManager.removePlayerData(player);
|
||||
}
|
||||
|
||||
@Inject(at = @At("RETURN"), method = "respawn")
|
||||
private void respawned(ServerPlayer oldPlayer, boolean bl, CallbackInfoReturnable<ServerPlayer> cir) {
|
||||
ServerPlayer player = PlayerUtil.getFixedPlayer(oldPlayer);
|
||||
|
||||
if (BwUtil.isInBedWars(player)) {
|
||||
BwPlayerEvents.respawned(player);
|
||||
}
|
||||
}
|
||||
|
||||
@ModifyArgs(method = "broadcastMessage", at = @At(value = "INVOKE", target = "Lnet/minecraft/network/protocol/game/ClientboundChatPacket;<init>(Lnet/minecraft/network/chat/Component;Lnet/minecraft/network/chat/ChatType;Ljava/util/UUID;)V"))
|
||||
private void handleChat(Args args) {
|
||||
try {
|
||||
Component component = args.get(0);
|
||||
ServerPlayer player = ServerTime.minecraftServer.getPlayerList().getPlayer(args.get(2));
|
||||
|
||||
if(Main.config.statusMessages){
|
||||
String key = ((TranslatableComponent) component).getKey();
|
||||
if (
|
||||
key.contains("multiplayer.player.join")
|
||||
) {
|
||||
args.set(0, joinFormat(component, player));
|
||||
}
|
||||
if (
|
||||
key.contains("multiplayer.player.left")
|
||||
) {
|
||||
args.set(0, leaveFormat(component, player));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if(!PlayerMutes.muted(player)){
|
||||
args.set(0, chatFormat(player, component));
|
||||
}
|
||||
|
||||
} catch (Exception ignored) {}
|
||||
}
|
||||
|
||||
private static Component joinFormat(Component original, ServerPlayer joinPlayer) {
|
||||
try {
|
||||
String name = String.valueOf(joinPlayer.getScoreboardName());
|
||||
if(ChatFormat.hasWhiteSpacesOrSpaces(null, name)) { return original; }
|
||||
if(joinPlayer.getStats().getValue(Stats.CUSTOM.get(Stats.LEAVE_GAME)) < 1) { return ChatFormat.format(Main.config.firstJoinMessage.replaceAll("%player%", name)); }
|
||||
return ChatFormat.format(Main.config.joinMessage.replaceAll("%player%", name));
|
||||
} catch (Exception var8) {
|
||||
return original;
|
||||
}
|
||||
}
|
||||
|
||||
private static Component leaveFormat(Component original, ServerPlayer leavePlayer) {
|
||||
try {
|
||||
String name = String.valueOf(leavePlayer.getScoreboardName());
|
||||
if(ChatFormat.hasWhiteSpacesOrSpaces(null, name)) { return original; }
|
||||
return ChatFormat.format(Main.config.leaveMessage.replaceAll("%player%", name));
|
||||
} catch (Exception var8) {
|
||||
return original;
|
||||
}
|
||||
}
|
||||
|
||||
private static Component chatFormat(ServerPlayer player, Component original) {
|
||||
try {
|
||||
TranslatableComponent component = (TranslatableComponent) original;
|
||||
Object[] args = component.getArgs();
|
||||
|
||||
MutableComponent name = (MutableComponent) args[0];
|
||||
MutableComponent suffix = new TextComponent(" » ").withStyle(ChatFormatting.GRAY);
|
||||
|
||||
String messageString = (String) args[1];
|
||||
MutableComponent message = new TextComponent(messageString).withStyle(ChatFormatting.WHITE);
|
||||
|
||||
return name.append(suffix).append(message);
|
||||
|
||||
} catch (Exception e) {
|
||||
return original;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,152 @@
|
||||
package com.nexia.core.mixin.player;
|
||||
|
||||
import com.nexia.core.Main;
|
||||
import com.nexia.core.games.util.LobbyUtil;
|
||||
import com.nexia.core.utilities.item.ItemStackUtil;
|
||||
import com.nexia.core.utilities.player.PlayerUtil;
|
||||
import com.nexia.core.utilities.pos.EntityPos;
|
||||
import com.nexia.ffa.utilities.FfaUtil;
|
||||
import com.nexia.minigames.games.bedwars.players.BwPlayerEvents;
|
||||
import com.nexia.minigames.games.bedwars.util.BwUtil;
|
||||
import com.nexia.minigames.games.oitc.OitcGame;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.sounds.SoundEvents;
|
||||
import net.minecraft.sounds.SoundSource;
|
||||
import net.minecraft.world.CombatRules;
|
||||
import net.minecraft.world.damagesource.DamageSource;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.EntityType;
|
||||
import net.minecraft.world.entity.LivingEntity;
|
||||
import net.minecraft.world.entity.ai.attributes.Attributes;
|
||||
import net.minecraft.world.entity.player.Inventory;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.entity.projectile.Arrow;
|
||||
import net.minecraft.world.item.ItemCooldowns;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.Items;
|
||||
import net.minecraft.world.level.Level;
|
||||
import org.spongepowered.asm.mixin.Final;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Overwrite;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.Redirect;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
|
||||
@Mixin(Player.class)
|
||||
public abstract class PlayerMixin extends LivingEntity {
|
||||
|
||||
@Shadow @Final public Inventory inventory;
|
||||
|
||||
@Shadow public abstract ItemCooldowns getCooldowns();
|
||||
|
||||
protected PlayerMixin(EntityType<? extends LivingEntity> entityType, Level level) {
|
||||
super(entityType, level);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author NotCoded
|
||||
* @reason Make shield break actually play the sound to other players.
|
||||
*/
|
||||
@Overwrite
|
||||
public boolean disableShield(float f) {
|
||||
this.getCooldowns().addCooldown(Items.SHIELD, (int)(f * 20.0F));
|
||||
this.stopUsingItem();
|
||||
this.level.broadcastEntityEvent(this, (byte)30);
|
||||
if((this.getLastDamageSource() != null && this.getLastDamageSource().getEntity() instanceof Player attacker) && Main.config.betterShields){
|
||||
//this.level.broadcastEntityEvent(attacker, (byte)30);
|
||||
|
||||
SoundSource soundSource = null;
|
||||
for (SoundSource source : SoundSource.values()) {
|
||||
soundSource = source;
|
||||
}
|
||||
PlayerUtil.sendSound((ServerPlayer) attacker, new EntityPos(attacker.position()), SoundEvents.SHIELD_BREAK, soundSource, 2, 1);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Inject(method = "hurt", cancellable = true, at = @At("HEAD"))
|
||||
private void beforeHurt(DamageSource damageSource, float damage, CallbackInfoReturnable<Boolean> cir) {
|
||||
if (!((Object) this instanceof ServerPlayer player)) return;
|
||||
|
||||
if (PlayerUtil.hasTag(player, LobbyUtil.NO_DAMAGE_TAG)) {
|
||||
cir.setReturnValue(false);
|
||||
}
|
||||
|
||||
if (damageSource.getEntity() instanceof ServerPlayer && PlayerUtil.hasTag((ServerPlayer) damageSource.getEntity(), LobbyUtil.NO_DAMAGE_TAG)) {
|
||||
cir.setReturnValue(false);
|
||||
}
|
||||
}
|
||||
|
||||
@Inject(method = "actuallyHurt", at = @At("TAIL"))
|
||||
private void afterHurt(DamageSource damageSource, float damage, CallbackInfo ci) {
|
||||
if (!((Object) this instanceof ServerPlayer player)) return;
|
||||
|
||||
if (BwUtil.isBedWarsPlayer(player)) {
|
||||
BwPlayerEvents.afterHurt(player, damageSource);
|
||||
}
|
||||
}
|
||||
|
||||
@Redirect(method = "actuallyHurt",at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/player/Player;getDamageAfterArmorAbsorb(Lnet/minecraft/world/damagesource/DamageSource;F)F"))
|
||||
private float modifyArmorCalculation(Player instance, DamageSource damageSource, float damage) {
|
||||
|
||||
hurtArmor(damageSource, damage);
|
||||
if (!((Object) this instanceof ServerPlayer player)) return vanillaArmorCalculation(damageSource, damage);
|
||||
|
||||
if (BwUtil.isBedWarsPlayer(player)) {
|
||||
return BwUtil.playerArmorCalculation(player, damageSource, damage);
|
||||
}
|
||||
|
||||
return vanillaArmorCalculation(damageSource, damage);
|
||||
}
|
||||
|
||||
public float vanillaArmorCalculation(DamageSource damageSource, float damage) {
|
||||
if (!damageSource.isBypassArmor()) {
|
||||
damage = CombatRules.getDamageAfterAbsorb(damage, this.getArmorValue(), (float)this.getAttributeValue(Attributes.ARMOR_TOUGHNESS));
|
||||
}
|
||||
return damage;
|
||||
}
|
||||
|
||||
@Inject(method = "drop*", cancellable = true, at = @At("HEAD"))
|
||||
private void drop1(boolean dropAll, CallbackInfoReturnable<Boolean> cir) {
|
||||
if (!((Object) this instanceof ServerPlayer player)) return;
|
||||
|
||||
ItemStack dropped = inventory.getItem(inventory.selected);
|
||||
|
||||
if (FfaUtil.isFfaPlayer(player)) {
|
||||
cir.setReturnValue(false);
|
||||
return;
|
||||
}
|
||||
if(LobbyUtil.isLobbyWorld(player.getLevel())){
|
||||
cir.setReturnValue(false);
|
||||
return;
|
||||
}
|
||||
if (BwUtil.isBedWarsPlayer(player)) {
|
||||
if (!BwUtil.canDropItem(dropped)) {
|
||||
ItemStackUtil.sendInventoryRefreshPacket(player);
|
||||
cir.setReturnValue(false);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if(OitcGame.isOITCPlayer(player)){
|
||||
cir.setReturnValue(false);
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Inject(method = "getAttackDelay", cancellable = true, at = @At("HEAD"))
|
||||
private void getAttackDelay(CallbackInfoReturnable<Integer> cir) {
|
||||
if (!((Object) this instanceof ServerPlayer player)) return;
|
||||
|
||||
if (BwUtil.isBedWarsPlayer(player)) {
|
||||
BwUtil.setAttackSpeed(player);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,133 @@
|
||||
package com.nexia.core.mixin.player;
|
||||
|
||||
import com.nexia.core.utilities.chat.PlayerMutes;
|
||||
import com.nexia.core.utilities.item.ItemStackUtil;
|
||||
import com.nexia.core.utilities.misc.EventUtil;
|
||||
import com.nexia.ffa.utilities.FfaUtil;
|
||||
import com.nexia.minigames.games.bedwars.areas.BwAreas;
|
||||
import com.nexia.minigames.games.bedwars.players.BwPlayerEvents;
|
||||
import com.nexia.minigames.games.bedwars.util.BwUtil;
|
||||
import com.nexia.minigames.games.oitc.OitcGame;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.network.protocol.game.*;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.server.network.ServerGamePacketListenerImpl;
|
||||
import net.minecraft.world.entity.player.Inventory;
|
||||
import net.minecraft.world.inventory.ClickType;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
@Mixin(ServerGamePacketListenerImpl.class)
|
||||
public class ServerGamePacketListenerMixin {
|
||||
|
||||
@Shadow public ServerPlayer player;
|
||||
|
||||
@Inject(method = "handleChat", cancellable = true, at = @At(value = "INVOKE", target = "Lnet/minecraft/server/players/PlayerList;broadcastMessage(Lnet/minecraft/network/chat/Component;Lnet/minecraft/network/chat/ChatType;Ljava/util/UUID;)V"))
|
||||
private void handleChat(ServerboundChatPacket serverboundChatPacket, CallbackInfo ci) {
|
||||
if (PlayerMutes.muted(player)) {
|
||||
ci.cancel();
|
||||
}
|
||||
}
|
||||
|
||||
@Inject(method = "handleInteract", cancellable = true, at = @At("HEAD"))
|
||||
private void mobInteract(ServerboundInteractPacket packet, CallbackInfo ci) {
|
||||
ServerLevel level = player.getLevel();
|
||||
|
||||
if (BwAreas.isBedWarsWorld(level) && !BwPlayerEvents.interact(player, packet)) {
|
||||
ci.cancel();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Inject(method = "handleUseItemOn", at = @At("HEAD"), cancellable = true)
|
||||
private void handleUseItemOn(ServerboundUseItemOnPacket packet, CallbackInfo ci) {
|
||||
|
||||
if (BwUtil.isInBedWars(player)) {
|
||||
if (!BwPlayerEvents.useItem(player, packet.getHand())) {
|
||||
ci.cancel();
|
||||
BlockPos blockPos = packet.getHitResult().getBlockPos().relative(packet.getHitResult().getDirection());
|
||||
player.connection.send(new ClientboundBlockUpdatePacket(blockPos, player.level.getBlockState(blockPos)));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Inject(method = "handleUseItem", at = @At("HEAD"), cancellable = true)
|
||||
private void handleUseItem(ServerboundUseItemPacket serverboundUseItemPacket, CallbackInfo ci) {
|
||||
|
||||
if (BwUtil.isInBedWars(player)) {
|
||||
if (!BwPlayerEvents.useItem(player, serverboundUseItemPacket.getHand())) {
|
||||
ci.cancel();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Inject(method = "handleContainerClick", cancellable = true, at = @At("HEAD"))
|
||||
private void handleContainerClick(ServerboundContainerClickPacket clickPacket, CallbackInfo ci) {
|
||||
int containerId = clickPacket.getContainerId();
|
||||
int slot = clickPacket.getSlotNum();
|
||||
ItemStack itemStack = clickPacket.getItem();
|
||||
|
||||
if ((clickPacket.getClickType() == ClickType.THROW || slot == -999)) {
|
||||
if (!EventUtil.dropItem(player, itemStack)) {
|
||||
ItemStackUtil.sendInventoryRefreshPacket(player);
|
||||
ci.cancel();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (BwUtil.isBedWarsPlayer(player)) {
|
||||
if (!BwPlayerEvents.containerClick(player, clickPacket)) {
|
||||
ItemStackUtil.sendInventoryRefreshPacket(player);
|
||||
ci.cancel();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (FfaUtil.isFfaPlayer(player)) {
|
||||
// If clicks on crafting slot
|
||||
if (containerId == 0 && slot >= 1 && slot <= 4) {
|
||||
ItemStackUtil.sendInventoryRefreshPacket(player);
|
||||
ci.cancel();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Inject(method = "handlePlayerAction", cancellable = true, at = @At("HEAD"))
|
||||
private void handlePlayerAction(ServerboundPlayerActionPacket actionPacket, CallbackInfo ci) {
|
||||
ServerboundPlayerActionPacket.Action action = actionPacket.getAction();
|
||||
Inventory inv = player.inventory;
|
||||
|
||||
if ((action == ServerboundPlayerActionPacket.Action.DROP_ITEM ||
|
||||
action == ServerboundPlayerActionPacket.Action.DROP_ALL_ITEMS) &&
|
||||
!EventUtil.dropItem(player, inv.getItem(player.inventory.selected))) {
|
||||
player.connection.send(new ClientboundContainerSetSlotPacket(0, 36 + inv.selected, inv.getSelected()));
|
||||
ci.cancel();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@Inject(method = "handleTeleportToEntityPacket", cancellable = true, at = @At(value = "INVOKE", target = "Lnet/minecraft/server/level/ServerPlayer;teleportTo(Lnet/minecraft/server/level/ServerLevel;DDDFF)V"))
|
||||
private void handleSpectatorTeleport(ServerboundTeleportToEntityPacket packet, CallbackInfo ci) {
|
||||
|
||||
if (BwUtil.isInBedWars(player)) {
|
||||
if (!BwPlayerEvents.spectatorTeleport(player, packet)) {
|
||||
ci.cancel();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if(OitcGame.isOITCPlayer(player)){
|
||||
ci.cancel();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package com.nexia.core.mixin.player;
|
||||
|
||||
import com.nexia.core.Main;
|
||||
import com.nexia.core.utilities.chat.ChatFormat;
|
||||
import com.nexia.core.utilities.player.PlayerUtil;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.chat.TextComponent;
|
||||
import net.minecraft.network.chat.TranslatableComponent;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.server.network.ServerLoginPacketListenerImpl;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.ModifyArg;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
@Mixin(ServerLoginPacketListenerImpl.class)
|
||||
public class ServerLoginPacketListenerMixin {
|
||||
|
||||
@ModifyArg(method = "handleAcceptedLogin", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/network/ServerLoginPacketListenerImpl;disconnect(Lnet/minecraft/network/chat/Component;)V"))
|
||||
private Component handleAcceptedLogin(Component original) {
|
||||
if (!(original instanceof TranslatableComponent)) return original;
|
||||
TranslatableComponent component = (TranslatableComponent) original;
|
||||
|
||||
if (component.getKey().contains("banned")) {
|
||||
component = new TranslatableComponent("§c§lYou have been banned.\n§7Reason: §d" + component.getString().split("Reason: ")[1] + "\n§7You can appeal your ban at §d" + Main.config.discordLink);
|
||||
}
|
||||
|
||||
return component;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
package com.nexia.core.mixin.player;
|
||||
|
||||
import com.nexia.core.utilities.item.BlockUtil;
|
||||
import com.nexia.minigames.games.bedwars.areas.BwAreas;
|
||||
import com.nexia.minigames.games.bedwars.players.BwPlayerEvents;
|
||||
import com.nexia.minigames.games.bedwars.util.BwUtil;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.server.level.ServerPlayerGameMode;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
|
||||
@Mixin(ServerPlayerGameMode.class)
|
||||
public class ServerPlayerGameModeMixin {
|
||||
|
||||
@Shadow public ServerPlayer player;
|
||||
|
||||
@Shadow public ServerLevel level;
|
||||
|
||||
private boolean isBed = false;
|
||||
|
||||
@Inject(at = @At("HEAD"), method = "destroyBlock", cancellable = true)
|
||||
private void destroyBlock(BlockPos blockPos, CallbackInfoReturnable<Boolean> cir) {
|
||||
|
||||
if (BwAreas.isBedWarsWorld(level) && !BwPlayerEvents.beforeBreakBlock(player, blockPos)) {
|
||||
cir.setReturnValue(false);
|
||||
}
|
||||
|
||||
isBed = BlockUtil.blockToText(player.level.getBlockState(blockPos)).endsWith("_bed");
|
||||
}
|
||||
|
||||
@Inject(at = @At("RETURN"), method = "destroyBlock")
|
||||
private void destroyBlockTail(BlockPos blockPos, CallbackInfoReturnable<Boolean> cir) {
|
||||
|
||||
if (BwUtil.isBedWarsPlayer(player) && isBed) {
|
||||
BwPlayerEvents.bedBroken(player, blockPos);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
package com.nexia.core.mixin.player;
|
||||
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import com.nexia.core.games.util.PlayerGameMode;
|
||||
import com.nexia.core.utilities.player.PlayerDataManager;
|
||||
import com.nexia.ffa.utilities.FfaUtil;
|
||||
import com.nexia.minigames.games.bedwars.areas.BwAreas;
|
||||
import com.nexia.minigames.games.bedwars.players.BwPlayerEvents;
|
||||
import com.nexia.minigames.games.duels.DuelGameMode;
|
||||
import com.nexia.minigames.games.duels.DuelsGame;
|
||||
import com.nexia.minigames.games.oitc.OitcGame;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.sounds.SoundEvent;
|
||||
import net.minecraft.sounds.SoundSource;
|
||||
import net.minecraft.world.damagesource.DamageSource;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.inventory.AbstractContainerMenu;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.level.Level;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.Redirect;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
@Mixin(ServerPlayer.class)
|
||||
public abstract class ServerPlayerMixin extends Player {
|
||||
|
||||
@Shadow public abstract ServerLevel getLevel();
|
||||
|
||||
@Shadow public abstract void playNotifySound(SoundEvent soundEvent, SoundSource soundSource, float f, float g);
|
||||
|
||||
public ServerPlayerMixin(Level level, BlockPos blockPos, float f, GameProfile gameProfile) {
|
||||
super(level, blockPos, f, gameProfile);
|
||||
}
|
||||
|
||||
@Inject(method = "die", at = @At("HEAD"))
|
||||
private void die(DamageSource damageSource, CallbackInfo ci) {
|
||||
ServerPlayer player = (ServerPlayer)(Object)this;
|
||||
|
||||
if (FfaUtil.isFfaPlayer(player)) {
|
||||
FfaUtil.leaveOrDie(player, damageSource);
|
||||
|
||||
} else if (BwAreas.isBedWarsWorld(getLevel())) {
|
||||
BwPlayerEvents.death(player);
|
||||
}
|
||||
else if(PlayerDataManager.get(player).gameMode == PlayerGameMode.OITC){
|
||||
OitcGame.death(player, damageSource);
|
||||
}
|
||||
else if(PlayerDataManager.get(player).gameMode == PlayerGameMode.DUELS){
|
||||
DuelsGame.death(player, damageSource);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
@Inject(method = "die", at = @At("RETURN"))
|
||||
private void dieReturn(DamageSource damageSource, CallbackInfo ci){
|
||||
ServerPlayer player = (ServerPlayer)(Object)this;
|
||||
|
||||
if(PlayerDataManager.get(player).gameMode == PlayerGameMode.DUELS){
|
||||
DuelsGame.death(player, damageSource);
|
||||
}
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
@Redirect(method = "doCloseContainer", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/inventory/AbstractContainerMenu;removed(Lnet/minecraft/world/entity/player/Player;)V"))
|
||||
private void removed(AbstractContainerMenu instance, Player player) {
|
||||
|
||||
if (FfaUtil.isFfaPlayer(player)) {
|
||||
player.inventory.add(inventory.getCarried());
|
||||
player.inventory.setCarried(ItemStack.EMPTY);
|
||||
return;
|
||||
}
|
||||
|
||||
player.containerMenu.removed(player);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,152 @@
|
||||
package com.nexia.core.utilities.chat;
|
||||
|
||||
import net.minecraft.network.chat.TextComponent;
|
||||
import org.apache.commons.lang3.tuple.MutablePair;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class ChatFormat {
|
||||
|
||||
// Colors
|
||||
public static String colorIndex = "\247";
|
||||
public static String bold = "\247l";
|
||||
public static String strikeThrough = "\247m";
|
||||
public static String underLine = "\247n";
|
||||
public static String reset = "\247r";
|
||||
|
||||
public static String chatColor2 = "\2477";
|
||||
|
||||
public static String normalColor = "\247f";
|
||||
public static String systemColor = "\2477";
|
||||
|
||||
public static String brandColor1 = "\247d";
|
||||
|
||||
public static String brandColor2 = "\2475";
|
||||
|
||||
|
||||
public static String failColor = "\247c";
|
||||
|
||||
public static String lineColor = "\2478";
|
||||
public static String lineTitleColor = brandColor1;
|
||||
|
||||
|
||||
private static final HashMap<String, String> colorSymbols = getColorSymbols();
|
||||
private static HashMap<String, String> getColorSymbols() {
|
||||
HashMap<String, String> colorSymbols = new HashMap<>();
|
||||
colorSymbols.put("{b1}", "\247d");
|
||||
colorSymbols.put("{b2}", "\2475");
|
||||
colorSymbols.put("{b}", "\247l"); // Bold
|
||||
colorSymbols.put("{ul}", "\247n"); // Underline
|
||||
colorSymbols.put("{s}", "\2477"); // System
|
||||
colorSymbols.put("{f}", "\247c"); // Fail
|
||||
colorSymbols.put("{n}", "\247f"); // Normal
|
||||
return colorSymbols;
|
||||
}
|
||||
|
||||
public static String formatString(String string, Object... objects) {
|
||||
|
||||
int objectIndex = 0;
|
||||
String objectKey = "{}";
|
||||
|
||||
main:
|
||||
for (int i = 0; i < string.length(); i++) {
|
||||
if (string.charAt(i) != '{') continue;
|
||||
|
||||
// Add color formatting
|
||||
for (Map.Entry<String, String> entry : colorSymbols.entrySet()) {
|
||||
MutablePair<String, Integer> pair = replaceAt(string, entry.getKey(), entry.getValue(), i);
|
||||
if (pair == null) continue;
|
||||
string = pair.left;
|
||||
i = pair.right;
|
||||
continue main;
|
||||
}
|
||||
|
||||
// Add objects
|
||||
if (objects.length <= objectIndex) continue;
|
||||
MutablePair<String, Integer> pair = replaceAt(string, objectKey, objects[objectIndex].toString(), i);
|
||||
if (pair == null) continue;
|
||||
string = pair.left;
|
||||
i = pair.right;
|
||||
objectIndex++;
|
||||
}
|
||||
return string;
|
||||
}
|
||||
|
||||
public static TextComponent format(String string, Object... objects) {
|
||||
return new TextComponent(formatString(string, objects));
|
||||
}
|
||||
|
||||
|
||||
// Returns null if cannot replace
|
||||
@Nullable
|
||||
public static MutablePair<String, Integer> replaceAt(String string, String key, String replacement, int index, boolean ignoreCase) {
|
||||
if (string.length() < index + key.length()) return null;
|
||||
|
||||
String keySubString = string.substring(index, index + key.length());
|
||||
if (ignoreCase) {
|
||||
if (!keySubString.equalsIgnoreCase(key)) return null;
|
||||
} else {
|
||||
if (!keySubString.equals(key)) return null;
|
||||
}
|
||||
|
||||
string = string.substring(0, index)
|
||||
+ replacement
|
||||
+ string.substring(index + key.length());
|
||||
|
||||
index += replacement.length() - 1;
|
||||
return MutablePair.of(string, index);
|
||||
}
|
||||
|
||||
public static MutablePair<String, Integer> replaceAt(String string, String key, String replacement, int index) {
|
||||
return replaceAt(string, key, replacement, index, false);
|
||||
}
|
||||
|
||||
public static TextComponent formatFail(String string) {
|
||||
return new TextComponent(failColor + string);
|
||||
}
|
||||
|
||||
public static String separatorLine(String title) {
|
||||
String spaces = " ";
|
||||
|
||||
if (title != null) {
|
||||
int lineLength = spaces.length() - Math.round((float)title.length() * 1.33F) - 4;
|
||||
return lineColor + strikeThrough + spaces.substring(0, lineLength / 2) +
|
||||
reset + lineColor + "[ " + lineTitleColor + title + lineColor + " ]" +
|
||||
lineColor + strikeThrough + spaces.substring(0, (lineLength + 1) / 2);
|
||||
|
||||
} else {
|
||||
return lineColor + strikeThrough + spaces;
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean hasWhiteSpacesOrSpaces(@Nullable String[] strings, @Nullable String string){
|
||||
if(strings == null && string != null){
|
||||
return string.matches(".*\\s+.*") || string.matches("");
|
||||
} else {
|
||||
for (String s : strings) {
|
||||
if (s.matches(".*\\s+.*") || s.matches("")) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static String removeColors(String string) {
|
||||
StringBuilder stringBuilder = new StringBuilder(string);
|
||||
|
||||
for (int i = 0; i < stringBuilder.length(); i++) {
|
||||
if (stringBuilder.charAt(i) == '§') {
|
||||
stringBuilder.deleteCharAt(i);
|
||||
if (stringBuilder.length() > i) {
|
||||
stringBuilder.deleteCharAt(i);
|
||||
}
|
||||
i--;
|
||||
}
|
||||
}
|
||||
return stringBuilder.toString();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
package com.nexia.core.utilities.chat;
|
||||
|
||||
import com.nexia.core.utilities.player.PlayerDataManager;
|
||||
import com.nexia.core.utilities.player.PlayerUtil;
|
||||
import com.nexia.core.utilities.player.SavedPlayerData;
|
||||
import net.minecraft.Util;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
|
||||
public class PlayerMutes {
|
||||
|
||||
public static void mute(CommandSourceStack sender, ServerPlayer muted, int duration, String reason) {
|
||||
if (PlayerUtil.hasPermission(muted.createCommandSourceStack(), "nexia.staff.mute", 1)) {
|
||||
sender.sendSuccess(ChatFormat.format("{f}You can't mute staff."), false);
|
||||
return;
|
||||
}
|
||||
|
||||
SavedPlayerData mutedData = PlayerDataManager.get(muted).savedData;
|
||||
long currentMuteTime = mutedData.muteEnd - System.currentTimeMillis();
|
||||
|
||||
if (currentMuteTime > 0) {
|
||||
sender.sendSuccess(ChatFormat.format("{s}This player has already been muted for {f}{}{s}." +
|
||||
"\n{s}Reason: {f}{}", muteTimeToText(currentMuteTime), mutedData.muteReason), false);
|
||||
return;
|
||||
}
|
||||
|
||||
mutedData.muteEnd = System.currentTimeMillis() + duration;
|
||||
mutedData.muteReason = reason;
|
||||
|
||||
sender.sendSuccess(ChatFormat.format("{s}Muted {b2}{} {s}for {b2}{}{s}." +
|
||||
"\n{s}Reason: {b2}{}", muted.getScoreboardName(), muteTimeToText(duration), reason), false);
|
||||
muted.sendMessage(ChatFormat.format("{s}You have been muted for {f}{}{s}." +
|
||||
"\n{s}Reason: {f}{}", muteTimeToText(duration), reason), Util.NIL_UUID);
|
||||
|
||||
}
|
||||
|
||||
public static void unMute(CommandSourceStack sender, ServerPlayer unMuted) {
|
||||
SavedPlayerData unMutedData = PlayerDataManager.get(unMuted).savedData;
|
||||
long currentMuteTime = unMutedData.muteEnd - System.currentTimeMillis();
|
||||
|
||||
if (currentMuteTime <= 0) {
|
||||
sender.sendSuccess(ChatFormat.format("{s}This player is not muted."), false);
|
||||
return;
|
||||
}
|
||||
|
||||
unMutedData.muteEnd = System.currentTimeMillis();
|
||||
unMutedData.muteReason = null;
|
||||
|
||||
sender.sendSuccess(ChatFormat.format("{s}Unmuted {b2}{}{s}.", unMuted.getScoreboardName()), false);
|
||||
unMuted.sendMessage(ChatFormat.format("{s}You have been unmuted."), Util.NIL_UUID);
|
||||
}
|
||||
|
||||
public static boolean muted(ServerPlayer player) {
|
||||
SavedPlayerData savedData = PlayerDataManager.get(player).savedData;
|
||||
long muteTime = savedData.muteEnd - System.currentTimeMillis();
|
||||
String reason = savedData.muteReason;
|
||||
|
||||
if (muteTime > 0) {
|
||||
player.sendMessage(ChatFormat.format("{s}You have been muted for {f}{}{s}." +
|
||||
"\n{s}Reason: {f}{}", muteTimeToText(muteTime), reason), Util.NIL_UUID);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static String muteTimeToText(long millis) {
|
||||
long seconds = millis / 1000;
|
||||
long minutes = seconds / 60;
|
||||
seconds %= 60;
|
||||
long hours = minutes / 60;
|
||||
minutes %= 60;
|
||||
|
||||
return hours + "h, " + minutes + "m, " + seconds + "s";
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package com.nexia.core.utilities.chat;
|
||||
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class RomanNumbers {
|
||||
|
||||
private final static TreeMap<Integer, String> romanNumbers = getRomanNumbers();
|
||||
private static TreeMap<Integer, String> getRomanNumbers() {
|
||||
TreeMap<Integer, String> romanNumbers = new TreeMap<>();
|
||||
romanNumbers.put(1000, "M");
|
||||
romanNumbers.put(900, "CM");
|
||||
romanNumbers.put(500, "D");
|
||||
romanNumbers.put(400, "CD");
|
||||
romanNumbers.put(100, "C");
|
||||
romanNumbers.put(90, "XC");
|
||||
romanNumbers.put(50, "L");
|
||||
romanNumbers.put(40, "XL");
|
||||
romanNumbers.put(10, "X");
|
||||
romanNumbers.put(9, "IX");
|
||||
romanNumbers.put(5, "V");
|
||||
romanNumbers.put(4, "IV");
|
||||
romanNumbers.put(1, "I");
|
||||
return romanNumbers;
|
||||
}
|
||||
|
||||
public static String intToRoman(int number) {
|
||||
int floor = romanNumbers.floorKey(number);
|
||||
if (number == floor) {
|
||||
return romanNumbers.get(number);
|
||||
}
|
||||
return romanNumbers.get(floor) + intToRoman(number - floor);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,391 @@
|
||||
package com.nexia.core.utilities.http;
|
||||
|
||||
import javax.net.ssl.HttpsURLConnection;
|
||||
import java.awt.Color;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.lang.reflect.Array;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
|
||||
// Copied from k3kdude
|
||||
// https://gist.github.com/k3kdude/fba6f6b37594eae3d6f9475330733bdb
|
||||
public class DiscordWebhook {
|
||||
|
||||
private final String url;
|
||||
private String content;
|
||||
private String username;
|
||||
private String avatarUrl;
|
||||
private boolean tts;
|
||||
private List<EmbedObject> embeds = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* Constructs a new DiscordWebhook instance
|
||||
*
|
||||
* @param url The webhook URL obtained in Discord
|
||||
*/
|
||||
public DiscordWebhook(String url) {
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
public void setContent(String content) {
|
||||
this.content = content;
|
||||
}
|
||||
|
||||
public void setUsername(String username) {
|
||||
this.username = username;
|
||||
}
|
||||
|
||||
public void setAvatarUrl(String avatarUrl) {
|
||||
this.avatarUrl = avatarUrl;
|
||||
}
|
||||
|
||||
public void setTts(boolean tts) {
|
||||
this.tts = tts;
|
||||
}
|
||||
|
||||
public void addEmbed(EmbedObject embed) {
|
||||
this.embeds.add(embed);
|
||||
}
|
||||
|
||||
public void execute() throws IOException {
|
||||
if (this.content == null && this.embeds.isEmpty()) {
|
||||
throw new IllegalArgumentException("Set content or add at least one EmbedObject");
|
||||
}
|
||||
|
||||
JSONObject json = new JSONObject();
|
||||
|
||||
json.put("content", this.content);
|
||||
json.put("username", this.username);
|
||||
json.put("avatar_url", this.avatarUrl);
|
||||
json.put("tts", this.tts);
|
||||
|
||||
if (!this.embeds.isEmpty()) {
|
||||
List<JSONObject> embedObjects = new ArrayList<>();
|
||||
|
||||
for (EmbedObject embed : this.embeds) {
|
||||
JSONObject jsonEmbed = new JSONObject();
|
||||
|
||||
jsonEmbed.put("title", embed.getTitle());
|
||||
jsonEmbed.put("description", embed.getDescription());
|
||||
jsonEmbed.put("url", embed.getUrl());
|
||||
|
||||
if (embed.getColor() != null) {
|
||||
Color color = embed.getColor();
|
||||
int rgb = color.getRed();
|
||||
rgb = (rgb << 8) + color.getGreen();
|
||||
rgb = (rgb << 8) + color.getBlue();
|
||||
|
||||
jsonEmbed.put("color", rgb);
|
||||
}
|
||||
|
||||
EmbedObject.Footer footer = embed.getFooter();
|
||||
EmbedObject.Image image = embed.getImage();
|
||||
EmbedObject.Thumbnail thumbnail = embed.getThumbnail();
|
||||
EmbedObject.Author author = embed.getAuthor();
|
||||
List<EmbedObject.Field> fields = embed.getFields();
|
||||
|
||||
if (footer != null) {
|
||||
JSONObject jsonFooter = new JSONObject();
|
||||
|
||||
jsonFooter.put("text", footer.getText());
|
||||
jsonFooter.put("icon_url", footer.getIconUrl());
|
||||
jsonEmbed.put("footer", jsonFooter);
|
||||
}
|
||||
|
||||
if (image != null) {
|
||||
JSONObject jsonImage = new JSONObject();
|
||||
|
||||
jsonImage.put("url", image.getUrl());
|
||||
jsonEmbed.put("image", jsonImage);
|
||||
}
|
||||
|
||||
if (thumbnail != null) {
|
||||
JSONObject jsonThumbnail = new JSONObject();
|
||||
|
||||
jsonThumbnail.put("url", thumbnail.getUrl());
|
||||
jsonEmbed.put("thumbnail", jsonThumbnail);
|
||||
}
|
||||
|
||||
if (author != null) {
|
||||
JSONObject jsonAuthor = new JSONObject();
|
||||
|
||||
jsonAuthor.put("name", author.getName());
|
||||
jsonAuthor.put("url", author.getUrl());
|
||||
jsonAuthor.put("icon_url", author.getIconUrl());
|
||||
jsonEmbed.put("author", jsonAuthor);
|
||||
}
|
||||
|
||||
List<JSONObject> jsonFields = new ArrayList<>();
|
||||
for (EmbedObject.Field field : fields) {
|
||||
JSONObject jsonField = new JSONObject();
|
||||
|
||||
jsonField.put("name", field.getName());
|
||||
jsonField.put("value", field.getValue());
|
||||
jsonField.put("inline", field.isInline());
|
||||
|
||||
jsonFields.add(jsonField);
|
||||
}
|
||||
|
||||
jsonEmbed.put("fields", jsonFields.toArray());
|
||||
embedObjects.add(jsonEmbed);
|
||||
}
|
||||
|
||||
json.put("embeds", embedObjects.toArray());
|
||||
}
|
||||
|
||||
URL url = new URL(this.url);
|
||||
HttpsURLConnection connection = (HttpsURLConnection) url.openConnection();
|
||||
connection.addRequestProperty("Content-Type", "application/json");
|
||||
connection.addRequestProperty("User-Agent", "Java-DiscordWebhook-BY-Gelox_");
|
||||
connection.setDoOutput(true);
|
||||
connection.setRequestMethod("POST");
|
||||
|
||||
OutputStream stream = connection.getOutputStream();
|
||||
stream.write(json.toString().getBytes());
|
||||
stream.flush();
|
||||
stream.close();
|
||||
|
||||
connection.getInputStream().close(); //I'm not sure why but it doesn't work without getting the InputStream
|
||||
connection.disconnect();
|
||||
}
|
||||
|
||||
public static class EmbedObject {
|
||||
private String title;
|
||||
private String description;
|
||||
private String url;
|
||||
private Color color;
|
||||
|
||||
private Footer footer;
|
||||
private Thumbnail thumbnail;
|
||||
private Image image;
|
||||
private Author author;
|
||||
private List<Field> fields = new ArrayList<>();
|
||||
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public String getUrl() {
|
||||
return url;
|
||||
}
|
||||
|
||||
public Color getColor() {
|
||||
return color;
|
||||
}
|
||||
|
||||
public Footer getFooter() {
|
||||
return footer;
|
||||
}
|
||||
|
||||
public Thumbnail getThumbnail() {
|
||||
return thumbnail;
|
||||
}
|
||||
|
||||
public Image getImage() {
|
||||
return image;
|
||||
}
|
||||
|
||||
public Author getAuthor() {
|
||||
return author;
|
||||
}
|
||||
|
||||
public List<Field> getFields() {
|
||||
return fields;
|
||||
}
|
||||
|
||||
public EmbedObject setTitle(String title) {
|
||||
this.title = title;
|
||||
return this;
|
||||
}
|
||||
|
||||
public EmbedObject setDescription(String description) {
|
||||
this.description = description;
|
||||
return this;
|
||||
}
|
||||
|
||||
public EmbedObject setUrl(String url) {
|
||||
this.url = url;
|
||||
return this;
|
||||
}
|
||||
|
||||
public EmbedObject setColor(Color color) {
|
||||
this.color = color;
|
||||
return this;
|
||||
}
|
||||
|
||||
public EmbedObject setFooter(String text, String icon) {
|
||||
this.footer = new Footer(text, icon);
|
||||
return this;
|
||||
}
|
||||
|
||||
public EmbedObject setThumbnail(String url) {
|
||||
this.thumbnail = new Thumbnail(url);
|
||||
return this;
|
||||
}
|
||||
|
||||
public EmbedObject setImage(String url) {
|
||||
this.image = new Image(url);
|
||||
return this;
|
||||
}
|
||||
|
||||
public EmbedObject setAuthor(String name, String url, String icon) {
|
||||
this.author = new Author(name, url, icon);
|
||||
return this;
|
||||
}
|
||||
|
||||
public EmbedObject addField(String name, String value, boolean inline) {
|
||||
this.fields.add(new Field(name, value, inline));
|
||||
return this;
|
||||
}
|
||||
|
||||
private class Footer {
|
||||
private String text;
|
||||
private String iconUrl;
|
||||
|
||||
private Footer(String text, String iconUrl) {
|
||||
this.text = text;
|
||||
this.iconUrl = iconUrl;
|
||||
}
|
||||
|
||||
private String getText() {
|
||||
return text;
|
||||
}
|
||||
|
||||
private String getIconUrl() {
|
||||
return iconUrl;
|
||||
}
|
||||
}
|
||||
|
||||
private class Thumbnail {
|
||||
private String url;
|
||||
|
||||
private Thumbnail(String url) {
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
private String getUrl() {
|
||||
return url;
|
||||
}
|
||||
}
|
||||
|
||||
private class Image {
|
||||
private String url;
|
||||
|
||||
private Image(String url) {
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
private String getUrl() {
|
||||
return url;
|
||||
}
|
||||
}
|
||||
|
||||
private class Author {
|
||||
private String name;
|
||||
private String url;
|
||||
private String iconUrl;
|
||||
|
||||
private Author(String name, String url, String iconUrl) {
|
||||
this.name = name;
|
||||
this.url = url;
|
||||
this.iconUrl = iconUrl;
|
||||
}
|
||||
|
||||
private String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
private String getUrl() {
|
||||
return url;
|
||||
}
|
||||
|
||||
private String getIconUrl() {
|
||||
return iconUrl;
|
||||
}
|
||||
}
|
||||
|
||||
private class Field {
|
||||
private String name;
|
||||
private String value;
|
||||
private boolean inline;
|
||||
|
||||
private Field(String name, String value, boolean inline) {
|
||||
this.name = name;
|
||||
this.value = value;
|
||||
this.inline = inline;
|
||||
}
|
||||
|
||||
private String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
private String getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
private boolean isInline() {
|
||||
return inline;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private class JSONObject {
|
||||
|
||||
private final HashMap<String, Object> map = new HashMap<>();
|
||||
|
||||
void put(String key, Object value) {
|
||||
if (value != null) {
|
||||
map.put(key, value);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
Set<Map.Entry<String, Object>> entrySet = map.entrySet();
|
||||
builder.append("{");
|
||||
|
||||
int i = 0;
|
||||
for (Map.Entry<String, Object> entry : entrySet) {
|
||||
Object val = entry.getValue();
|
||||
builder.append(quote(entry.getKey())).append(":");
|
||||
|
||||
if (val instanceof String) {
|
||||
builder.append(quote(String.valueOf(val)));
|
||||
} else if (val instanceof Integer) {
|
||||
builder.append(Integer.valueOf(String.valueOf(val)));
|
||||
} else if (val instanceof Boolean) {
|
||||
builder.append(val);
|
||||
} else if (val instanceof JSONObject) {
|
||||
builder.append(val.toString());
|
||||
} else if (val.getClass().isArray()) {
|
||||
builder.append("[");
|
||||
int len = Array.getLength(val);
|
||||
for (int j = 0; j < len; j++) {
|
||||
builder.append(Array.get(val, j).toString()).append(j != len - 1 ? "," : "");
|
||||
}
|
||||
builder.append("]");
|
||||
}
|
||||
|
||||
builder.append(++i == entrySet.size() ? "}" : ",");
|
||||
}
|
||||
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
private String quote(String string) {
|
||||
return "\"" + string + "\"";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
package com.nexia.core.utilities.item;
|
||||
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.block.BedBlock;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.Rotation;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.block.state.properties.BedPart;
|
||||
|
||||
public class BlockUtil {
|
||||
|
||||
public static void placeBed(Level level, BedBlock block, BlockPos blockPos, float headRotation) {
|
||||
|
||||
int intRotation = (Math.round(headRotation / 90) * 90) % 360;
|
||||
if (intRotation <= -180) intRotation += 360;
|
||||
if (intRotation > 180) intRotation -= 360;
|
||||
Rotation rotation;
|
||||
Direction direction;
|
||||
|
||||
switch (intRotation) {
|
||||
case 90 -> {
|
||||
rotation = Rotation.CLOCKWISE_90;
|
||||
direction = Direction.WEST;
|
||||
}
|
||||
case 180 -> {
|
||||
rotation = Rotation.CLOCKWISE_180;
|
||||
direction = Direction.NORTH;
|
||||
}
|
||||
case -90 -> {
|
||||
rotation = Rotation.COUNTERCLOCKWISE_90;
|
||||
direction = Direction.EAST;
|
||||
}
|
||||
default -> {
|
||||
rotation = Rotation.NONE;
|
||||
direction = Direction.SOUTH;
|
||||
}
|
||||
}
|
||||
|
||||
BlockState blockState = block.defaultBlockState();
|
||||
blockState = blockState.setValue(BedBlock.FACING, rotation.rotate(blockState.getValue(BedBlock.FACING)));
|
||||
blockState = blockState.setValue(BedBlock.PART, BedPart.HEAD);
|
||||
level.setBlock(blockPos, blockState, 3);
|
||||
|
||||
blockState = blockState.setValue(BedBlock.PART, BedPart.FOOT);
|
||||
level.setBlock(blockPos.relative(direction), blockState, 3);
|
||||
}
|
||||
|
||||
public static String blockToText(BlockState blockState) {
|
||||
return blockToText(blockState.getBlock());
|
||||
}
|
||||
|
||||
public static String blockToText(Block block) {
|
||||
String[] splitRegistryKey = Registry.BLOCK.getKey(block).toString().split(":");
|
||||
if (splitRegistryKey.length < 2) return splitRegistryKey[0];
|
||||
return splitRegistryKey[1];
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,158 @@
|
||||
package com.nexia.core.utilities.item;
|
||||
|
||||
import com.natamus.collective_fabric.functions.PlayerFunctions;
|
||||
import com.natamus.collective_fabric.functions.StringFunctions;
|
||||
import com.nexia.core.utilities.chat.ChatFormat;
|
||||
import net.fabricmc.loader.api.FabricLoader;
|
||||
import net.minecraft.Util;
|
||||
import net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.InteractionHand;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
|
||||
public class InventoryUtil {
|
||||
|
||||
static String dirpath = FabricLoader.getInstance().getConfigDir().toString() + "/nexia/inventories";
|
||||
|
||||
public static void sendHandItemPacket(ServerPlayer player, InteractionHand hand) {
|
||||
if (hand == InteractionHand.MAIN_HAND) {
|
||||
sendInvSlotPacket(player, player.inventory.selected);
|
||||
} else if (hand == InteractionHand.OFF_HAND) {
|
||||
sendInvSlotPacket(player, 40);
|
||||
}
|
||||
}
|
||||
|
||||
public static void sendInvSlotPacket(ServerPlayer player, int slot) {
|
||||
int packetSlot;
|
||||
|
||||
if (slot < 9) {
|
||||
packetSlot = 36 + slot;
|
||||
} else if (slot < 36) {
|
||||
packetSlot = slot;
|
||||
} else if (slot < 40) {
|
||||
packetSlot = 44 - slot;
|
||||
} else if (slot == 40) {
|
||||
packetSlot = 45;
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
|
||||
player.connection.send(new ClientboundContainerSetSlotPacket(0, packetSlot, player.inventory.getItem(slot)));
|
||||
}
|
||||
|
||||
public static boolean writeGearStringToFile(String filename, String gearstring, @Nullable String path) {
|
||||
File dir = new File(dirpath);
|
||||
dir.mkdirs();
|
||||
|
||||
try {
|
||||
PrintWriter writer = new PrintWriter(dirpath + "/" + filename + ".txt", StandardCharsets.UTF_8);
|
||||
if(path != null){
|
||||
writer = new PrintWriter(dirpath + path + "/" + filename + ".txt", StandardCharsets.UTF_8);
|
||||
}
|
||||
writer.println(gearstring);
|
||||
writer.close();
|
||||
} catch (Exception e) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static String getGearStringFromFile(String filename, @Nullable String path) {
|
||||
File dir = new File(dirpath);
|
||||
if(path != null){
|
||||
dir = new File(dirpath + path);
|
||||
}
|
||||
File file = new File(dirpath + "/" + filename + ".txt");
|
||||
|
||||
String gearstring = "";
|
||||
if (dir.isDirectory() && file.isFile()) {
|
||||
try {
|
||||
gearstring = new String(Files.readAllBytes(Paths.get(dirpath + "/" + filename + ".txt", new String[0])));
|
||||
}
|
||||
catch (IOException ignored) { }
|
||||
}
|
||||
|
||||
return gearstring;
|
||||
}
|
||||
|
||||
public static String getListOfInventories(@Nullable String path) {
|
||||
StringBuilder inventories = new StringBuilder();
|
||||
|
||||
File folder = new File(dirpath);
|
||||
if(path != null) {
|
||||
folder = new File(dirpath + path);
|
||||
}
|
||||
if (!folder.isDirectory()) {
|
||||
return inventories.toString();
|
||||
}
|
||||
|
||||
File[] listOfFiles = folder.listFiles();
|
||||
for (File listOfFile : listOfFiles) {
|
||||
if (listOfFile.isFile()) {
|
||||
if (!inventories.toString().equals("")) {
|
||||
inventories.append(", ");
|
||||
}
|
||||
inventories.append(listOfFile.getName().replace(".txt", ""));
|
||||
}
|
||||
}
|
||||
|
||||
return inventories.toString();
|
||||
}
|
||||
public static int saveInventory(ServerPlayer player, String name, @Nullable String path, boolean silent) {
|
||||
if (name.trim() == "") {
|
||||
if(!silent){
|
||||
player.sendMessage(ChatFormat.formatFail("The inventory name " + name + " is invalid."), Util.NIL_UUID);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
String gearstring = PlayerFunctions.getPlayerGearString(player);
|
||||
if (StringFunctions.sequenceCount(gearstring, "\n") < 40) {
|
||||
if(!silent){
|
||||
player.sendMessage(ChatFormat.formatFail("Something went wrong while generating the save file content for your inventory."), Util.NIL_UUID);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!InventoryUtil.writeGearStringToFile(name, gearstring, path)) {
|
||||
player.sendMessage(ChatFormat.formatFail("Something went wrong while saving the content of your inventory as '" + name + "'."), Util.NIL_UUID);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if(!silent){
|
||||
player.sendMessage(ChatFormat.format("{b1}Successfully saved your inventory as {b2}'{}'{b1}.", name), Util.NIL_UUID);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
public static int setInventory(ServerPlayer player, String name, @Nullable String path, boolean silent) {
|
||||
if (name.trim() == "") {
|
||||
if(!silent){
|
||||
player.sendMessage(ChatFormat.formatFail("The inventory name '" + name + "' is invalid."), Util.NIL_UUID);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
String gearstring = InventoryUtil.getGearStringFromFile(name, path);
|
||||
if (gearstring == "") {
|
||||
if(!silent){
|
||||
player.sendMessage(ChatFormat.formatFail("Unable to load the content of the inventory with the name '" + name + "'."), Util.NIL_UUID);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
PlayerFunctions.setPlayerGearFromString(player, gearstring);
|
||||
if(!silent){
|
||||
player.sendMessage(ChatFormat.format("{b1}Your inventory has been set to the preset {b2}{}{b1}.", name), Util.NIL_UUID);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
package com.nexia.core.utilities.item;
|
||||
|
||||
import net.minecraft.nbt.*;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.enchantment.EnchantmentHelper;
|
||||
|
||||
public class ItemDisplayUtil {
|
||||
|
||||
public static void addLore(ItemStack itemStack, String string, int line) {
|
||||
CompoundTag compoundTag = itemStack.getOrCreateTag();
|
||||
CompoundTag display = compoundTag.getCompound("display");
|
||||
ListTag listTag = display.getList("Lore", 8);
|
||||
|
||||
string = "{\"text\":\"" + string + "\"}";
|
||||
if (line < 0) {
|
||||
listTag.add(listTag.size() + line + 1, StringTag.valueOf(string));
|
||||
} else {
|
||||
listTag.add(line, StringTag.valueOf(string));
|
||||
}
|
||||
|
||||
display.put("Lore", listTag);
|
||||
compoundTag.put("display", display);
|
||||
itemStack.setTag(compoundTag);
|
||||
}
|
||||
|
||||
public static void removeLore(ItemStack itemStack, int line) {
|
||||
CompoundTag compoundTag = itemStack.getOrCreateTag();
|
||||
CompoundTag display = compoundTag.getCompound("display");
|
||||
ListTag listTag = display.getList("Lore", 8);
|
||||
|
||||
if (line < 0) {
|
||||
if (listTag.size() > 0) listTag.remove(listTag.size() - 1);
|
||||
} else {
|
||||
if (listTag.size() > line) {
|
||||
listTag.remove(line);
|
||||
}
|
||||
}
|
||||
|
||||
if (listTag.size() > 0) display.put("Lore", listTag);
|
||||
else display.remove("Lore");
|
||||
|
||||
if (display.getAllKeys().size() > 0) compoundTag.put("display", display);
|
||||
else compoundTag.remove("display");
|
||||
|
||||
itemStack.setTag(compoundTag);
|
||||
}
|
||||
|
||||
public static void addGlint(ItemStack itemStack) {
|
||||
try {
|
||||
if (!itemStack.isEnchanted()) {
|
||||
ListTag listTag = new ListTag();
|
||||
listTag.add(new CompoundTag());
|
||||
itemStack.getOrCreateTag().put("Enchantments", listTag);
|
||||
}
|
||||
} catch (Exception ignored) {}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,137 @@
|
||||
package com.nexia.core.utilities.item;
|
||||
|
||||
import net.minecraft.core.NonNullList;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.network.protocol.game.ServerboundContainerClickPacket;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.player.Inventory;
|
||||
import net.minecraft.world.item.*;
|
||||
import net.minecraft.world.item.enchantment.Enchantment;
|
||||
import net.minecraft.world.item.enchantment.EnchantmentHelper;
|
||||
import net.minecraft.world.item.enchantment.Enchantments;
|
||||
import net.minecraft.world.level.Level;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class ItemStackUtil {
|
||||
|
||||
public static HashMap<ArmorMaterial, Integer> armorTiers = getArmorTiers();
|
||||
private static HashMap<ArmorMaterial, Integer> getArmorTiers() {
|
||||
HashMap<ArmorMaterial, Integer> tiers = new HashMap<>();
|
||||
tiers.put(ArmorMaterials.LEATHER, 1);
|
||||
tiers.put(ArmorMaterials.GOLD, 2);
|
||||
tiers.put(ArmorMaterials.CHAIN, 3);
|
||||
tiers.put(ArmorMaterials.IRON, 4);
|
||||
tiers.put(ArmorMaterials.TURTLE, 4);
|
||||
tiers.put(ArmorMaterials.DIAMOND, 5);
|
||||
tiers.put(ArmorMaterials.NETHERITE, 6);
|
||||
return tiers;
|
||||
}
|
||||
|
||||
public static int getArmorTier(Item item) {
|
||||
if (!(item instanceof ArmorItem)) return 0;
|
||||
|
||||
ArmorItem armorItem = (ArmorItem) item;
|
||||
ArmorMaterial material = armorItem.getMaterial();
|
||||
if (!armorTiers.containsKey(material)) return 0;
|
||||
|
||||
return armorTiers.get(material);
|
||||
}
|
||||
|
||||
public static boolean hasRoomFor(Inventory inventory, ItemStack itemStack) {
|
||||
int count = itemStack.getCount();
|
||||
|
||||
for (ItemStack slot : inventory.items) {
|
||||
if (slot.getItem() == Items.AIR) {
|
||||
count -= 64;
|
||||
} else if (isSameItem(slot, itemStack)) {
|
||||
count -= 64 - slot.getCount();
|
||||
}
|
||||
if (count <= 0) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean hasItem(Inventory inventory, Item item) {
|
||||
for (int i = 0; i < 41; i++) {
|
||||
if (inventory.getItem(i).getItem() == item) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean isSameItem(ItemStack itemStack1, ItemStack itemStack2) {
|
||||
if (itemStack1.getItem() != itemStack2.getItem()) return false;
|
||||
|
||||
if (itemStack1.getTag() == null) {
|
||||
return itemStack2.getTag() == null;
|
||||
} else {
|
||||
return itemStack1.getTag().equals(itemStack2.getTag());
|
||||
}
|
||||
}
|
||||
|
||||
public static ItemStack stringToItemStack(String string) {
|
||||
try {
|
||||
String[] itemStack = string.split(" ");
|
||||
String item = itemStack[itemStack.length-1];
|
||||
int amount = 1;
|
||||
if (itemStack.length > 1) amount = Integer.parseInt(itemStack[0]);
|
||||
|
||||
return new ItemStack(itemFromString(item), amount);
|
||||
} catch (Exception exception) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static String ItemStackToString(ItemStack itemStack, boolean reversible) {
|
||||
if(reversible){
|
||||
return itemStack.getCount() + " " + itemStack.getDescriptionId().split("\\.")[2];
|
||||
}
|
||||
return itemStack.getDescriptionId();
|
||||
}
|
||||
|
||||
public static ArrayList<ItemStack> getInvItems(ServerPlayer player) {
|
||||
ArrayList<ItemStack> fullInv = new ArrayList<>();
|
||||
fullInv.addAll(player.inventory.items);
|
||||
fullInv.addAll(player.inventory.armor);
|
||||
fullInv.addAll(player.inventory.offhand);
|
||||
return fullInv;
|
||||
}
|
||||
|
||||
public static void sendInventoryRefreshPacket(ServerPlayer player) {
|
||||
NonNullList<ItemStack> i = NonNullList.create();
|
||||
for (int j = 0; j < player.containerMenu.slots.size(); ++j) {
|
||||
ItemStack itemStack = player.containerMenu.slots.get(j).getItem();
|
||||
i.add(itemStack.isEmpty() ? ItemStack.EMPTY : itemStack);
|
||||
}
|
||||
player.refreshContainer(player.containerMenu, i);
|
||||
}
|
||||
|
||||
public static Item itemFromString(String name) {
|
||||
name = name.toLowerCase();
|
||||
return Registry.ITEM.get(new ResourceLocation(name));
|
||||
}
|
||||
|
||||
public static void enchant(ItemStack itemStack, Enchantment enchantment, int level) {
|
||||
Map<Enchantment, Integer> enchantments = EnchantmentHelper.getEnchantments(itemStack);
|
||||
if (level > 0) enchantments.put(enchantment, level);
|
||||
else enchantments.remove(enchantment);
|
||||
EnchantmentHelper.setEnchantments(enchantments, itemStack);
|
||||
}
|
||||
|
||||
public static ItemStack getContainerClickItem(ServerPlayer player, ServerboundContainerClickPacket packet) {
|
||||
int slot = packet.getSlotNum();
|
||||
|
||||
if (slot >= 0 && slot < player.containerMenu.slots.size()) {
|
||||
return player.containerMenu.getSlot(slot).getItem();
|
||||
} else if (slot == -999) {
|
||||
return player.inventory.getCarried();
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.nexia.core.utilities.misc;
|
||||
|
||||
import com.nexia.core.games.util.LobbyUtil;
|
||||
import com.nexia.ffa.utilities.FfaUtil;
|
||||
import com.nexia.minigames.games.duels.DuelsSpawn;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
|
||||
public class EventUtil {
|
||||
|
||||
public static boolean dropItem(ServerPlayer player, ItemStack itemStack) {
|
||||
|
||||
return !FfaUtil.isFfaPlayer(player) || !DuelsSpawn.isInHub(player) || !LobbyUtil.isLobbyWorld(player.getLevel());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
package com.nexia.core.utilities.misc;
|
||||
|
||||
import com.mojang.brigadier.tree.CommandNode;
|
||||
import me.lucko.fabric.api.permissions.v0.Permissions;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
|
||||
import java.util.function.Predicate;
|
||||
public class NxCmdUtil {
|
||||
|
||||
public static final String PREFIX = "minecraft.command.";
|
||||
|
||||
public static void alterCommand(CommandNode<CommandSourceStack> child) {
|
||||
var name = child.getName();
|
||||
var packageName = commandPackageName(child);
|
||||
if (packageName == null || !packageName.startsWith("net.minecraft")) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
var field = CommandNode.class.getDeclaredField("requirement");
|
||||
field.setAccessible(true);
|
||||
Predicate<CommandSourceStack> original = child.getRequirement();
|
||||
field.set(child, original.or((source) -> Permissions.check(source, NxCmdUtil.PREFIX + name, false)));
|
||||
} catch (NoSuchFieldException | IllegalAccessException ignored) {
|
||||
}
|
||||
}
|
||||
|
||||
private static String commandPackageName(CommandNode<CommandSourceStack> node) {
|
||||
var command = node.getCommand();
|
||||
if (command != null) {
|
||||
return command.getClass().getPackageName();
|
||||
}
|
||||
var redirect = node.getRedirect();
|
||||
if (redirect != null) {
|
||||
return commandPackageName(redirect);
|
||||
}
|
||||
for (var child : node.getChildren()) {
|
||||
var childResult = commandPackageName(child);
|
||||
if (childResult != null) {
|
||||
return childResult;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.nexia.core.utilities.misc;
|
||||
|
||||
import com.nexia.core.Main;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public class NxFileUtil {
|
||||
|
||||
public static String makeDir(String string) {
|
||||
new File(string).mkdirs();
|
||||
return string;
|
||||
}
|
||||
|
||||
public static String addConfigDir(String string) {
|
||||
string = Main.modConfigDir + "/" + string;
|
||||
new File(string).mkdirs();
|
||||
return string;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.nexia.core.utilities.misc;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
public class RandomUtil {
|
||||
public static int randomInt(int minimum, int maximum){
|
||||
return new Random().nextInt(maximum - minimum + 1) + minimum;
|
||||
}
|
||||
|
||||
public static float randomFloat(float minimum, float maximum){
|
||||
return new Random().nextFloat(maximum - minimum + 1) + minimum;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package com.nexia.core.utilities.player;
|
||||
|
||||
import com.nexia.core.games.util.LobbyUtil;
|
||||
import com.nexia.core.games.util.PlayerGameMode;
|
||||
import com.nexia.core.utilities.pos.EntityPos;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.entity.player.Inventory;
|
||||
import net.minecraft.world.level.Level;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
public class PlayerData {
|
||||
|
||||
// Stuff saved into files
|
||||
public SavedPlayerData savedData;
|
||||
|
||||
// Stuff not saved in files
|
||||
public PlayerGameMode gameMode;
|
||||
public ResourceKey<Level> spawnWorld;
|
||||
public EntityPos spawnPoint;
|
||||
|
||||
public ServerPlayer combatTagPlayer;
|
||||
public LocalDateTime combatTagEnd;
|
||||
|
||||
public ServerPlayer lastMessageSender;
|
||||
|
||||
public PlayerData(SavedPlayerData savedData) {
|
||||
this.savedData = savedData;
|
||||
|
||||
this.combatTagPlayer = null;
|
||||
this.combatTagEnd = LocalDateTime.now();
|
||||
|
||||
this.gameMode = PlayerGameMode.LOBBY;
|
||||
this.spawnWorld = LobbyUtil.lobbyWorld.dimension();
|
||||
this.spawnPoint = LobbyUtil.lobbySpawn;
|
||||
|
||||
this.lastMessageSender = null;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
package com.nexia.core.utilities.player;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import net.fabricmc.loader.api.FabricLoader;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.HashMap;
|
||||
import java.util.UUID;
|
||||
|
||||
public class PlayerDataManager {
|
||||
|
||||
static String dataDirectory = FabricLoader.getInstance().getConfigDir().toString() + "/nexia/core";
|
||||
static String playerDataDirectory = dataDirectory + "/playerdata";
|
||||
|
||||
static HashMap<UUID, PlayerData> allPlayerData = new HashMap<>();
|
||||
|
||||
public static PlayerData get(Player player) {
|
||||
if (!allPlayerData.containsKey(player.getUUID())) {
|
||||
addPlayerData(player);
|
||||
}
|
||||
return allPlayerData.get(player.getUUID());
|
||||
}
|
||||
|
||||
public static void addPlayerData(Player player) {
|
||||
PlayerData playerData = new PlayerData(loadPlayerData(player));
|
||||
allPlayerData.put(player.getUUID(), playerData);
|
||||
}
|
||||
|
||||
public static void removePlayerData(Player player) {
|
||||
if (!allPlayerData.containsKey(player.getUUID())) return;
|
||||
savePlayerData(player);
|
||||
allPlayerData.remove(player.getUUID());
|
||||
}
|
||||
|
||||
private static void savePlayerData(Player player) {
|
||||
try {
|
||||
|
||||
PlayerData playerData = get(player);
|
||||
Gson gson = new Gson();
|
||||
String json = gson.toJson(playerData.savedData);
|
||||
|
||||
String directory = getDataDir();
|
||||
FileWriter fileWriter = new FileWriter(directory + "/" + player.getUUID() + ".json");
|
||||
fileWriter.write(json);
|
||||
fileWriter.close();
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private static SavedPlayerData loadPlayerData(Player player) {
|
||||
try {
|
||||
|
||||
String directory = getDataDir();
|
||||
String json = Files.readString(Path.of(directory + "/" + player.getUUID() + ".json"));
|
||||
|
||||
Gson gson = new Gson();
|
||||
return gson.fromJson(json, SavedPlayerData.class);
|
||||
|
||||
} catch (Exception e) {
|
||||
return new SavedPlayerData();
|
||||
}
|
||||
}
|
||||
|
||||
private static String getDataDir() {
|
||||
new File(playerDataDirectory).mkdirs();
|
||||
return playerDataDirectory;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,197 @@
|
||||
package com.nexia.core.utilities.player;
|
||||
|
||||
import com.nexia.core.Main;
|
||||
import com.nexia.core.utilities.chat.ChatFormat;
|
||||
import com.nexia.core.utilities.item.ItemStackUtil;
|
||||
import com.nexia.core.utilities.pos.EntityPos;
|
||||
import com.nexia.core.utilities.time.ServerTime;
|
||||
import net.minecraft.Util;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.chat.TextComponent;
|
||||
import net.minecraft.network.protocol.game.ClientboundSetTitlesPacket;
|
||||
import net.minecraft.network.protocol.game.ClientboundSoundPacket;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.sounds.SoundEvent;
|
||||
import net.minecraft.sounds.SoundSource;
|
||||
import net.minecraft.world.effect.MobEffects;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.projectile.Projectile;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class PlayerUtil {
|
||||
|
||||
public static void broadcast(List<ServerPlayer> players, String string) {
|
||||
broadcast(players, new TextComponent(string));
|
||||
}
|
||||
|
||||
public static void sendActionbar(ServerPlayer player, String string){
|
||||
player.connection.send(new ClientboundSetTitlesPacket(ClientboundSetTitlesPacket.Type.ACTIONBAR,
|
||||
ChatFormat.format(string)));
|
||||
}
|
||||
|
||||
public static void broadcast(List<ServerPlayer> players, Component component) {
|
||||
for (ServerPlayer player : players) {
|
||||
player.sendMessage(component, Util.NIL_UUID);
|
||||
}
|
||||
}
|
||||
|
||||
public static void sendTitle(ServerPlayer player, String title, String sub, int in, int stay, int out) {
|
||||
player.connection.send(new ClientboundSetTitlesPacket(in, stay, out));
|
||||
player.connection.send(new ClientboundSetTitlesPacket(
|
||||
ClientboundSetTitlesPacket.Type.TITLE, new TextComponent(title)));
|
||||
player.connection.send(new ClientboundSetTitlesPacket(
|
||||
ClientboundSetTitlesPacket.Type.SUBTITLE, new TextComponent(sub)));
|
||||
}
|
||||
|
||||
public static void broadcastTitle(List<ServerPlayer> players, String title, String subtitle, int in, int stay, int out) {
|
||||
ClientboundSetTitlesPacket titlePacket = new ClientboundSetTitlesPacket(
|
||||
ClientboundSetTitlesPacket.Type.TITLE, new TextComponent(title));
|
||||
ClientboundSetTitlesPacket subtitlePacket = new ClientboundSetTitlesPacket(
|
||||
ClientboundSetTitlesPacket.Type.SUBTITLE, new TextComponent(subtitle));
|
||||
|
||||
for (ServerPlayer player : players) {
|
||||
player.connection.send(new ClientboundSetTitlesPacket(in, stay, out));
|
||||
player.connection.send(titlePacket);
|
||||
player.connection.send(subtitlePacket);
|
||||
}
|
||||
}
|
||||
|
||||
public static void broadcastTitle(List<ServerPlayer> players, String title, String subtitle) {
|
||||
ClientboundSetTitlesPacket titlePacket = new ClientboundSetTitlesPacket(
|
||||
ClientboundSetTitlesPacket.Type.TITLE, new TextComponent(title));
|
||||
ClientboundSetTitlesPacket subtitlePacket = new ClientboundSetTitlesPacket(
|
||||
ClientboundSetTitlesPacket.Type.SUBTITLE, new TextComponent(subtitle));
|
||||
|
||||
for (ServerPlayer player : players) {
|
||||
sendDefaultTitleLength(player);
|
||||
player.connection.send(titlePacket);
|
||||
player.connection.send(subtitlePacket);
|
||||
}
|
||||
}
|
||||
|
||||
private static void sendDefaultTitleLength(ServerPlayer player) {
|
||||
player.connection.send(new ClientboundSetTitlesPacket(10, 60, 20));
|
||||
}
|
||||
|
||||
public static void broadcastSound(List<ServerPlayer> players, SoundEvent soundEvent, SoundSource soundSource, float volume, float pitch) {
|
||||
for (ServerPlayer player : players) {
|
||||
sendSound(player, soundEvent, soundSource, volume, pitch);
|
||||
}
|
||||
}
|
||||
|
||||
public static void sendSound(ServerPlayer player, SoundEvent soundEvent, SoundSource soundSource, float volume, float pitch) {
|
||||
sendSound(player, new EntityPos(player), soundEvent, soundSource, volume, pitch);
|
||||
}
|
||||
|
||||
public static void sendSound(ServerPlayer player, EntityPos position, SoundEvent soundEvent, SoundSource soundSource, float volume, float pitch) {
|
||||
player.connection.send(new ClientboundSoundPacket(soundEvent, soundSource,
|
||||
position.x, position.y, position.z, 16f * volume, pitch));
|
||||
}
|
||||
|
||||
public static ServerPlayer getFixedPlayer(ServerPlayer serverPlayer) {
|
||||
if (serverPlayer == null) return null;
|
||||
return ServerTime.minecraftServer.getPlayerList().getPlayer(serverPlayer.getUUID());
|
||||
}
|
||||
|
||||
public static void resetHealthStatus(ServerPlayer player) {
|
||||
player.setInvulnerable(false);
|
||||
player.removeAllEffects();
|
||||
player.setHealth(player.getMaxHealth());
|
||||
player.getFoodData().setFoodLevel(20);
|
||||
}
|
||||
|
||||
public static Object[] getTags(@NotNull ServerPlayer player){
|
||||
return player.getTags().toArray();
|
||||
}
|
||||
|
||||
public static boolean hasTag(@NotNull ServerPlayer player, @NotNull String tag){
|
||||
Object[] result = getTags(player);
|
||||
if(result.length > 0) {
|
||||
for (Object s : result) {
|
||||
if (String.valueOf(s).equalsIgnoreCase(tag)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return String.valueOf(result[0]).equalsIgnoreCase(tag);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean doesPlayerExist(String player){
|
||||
return (getPlayerFromName(player) != null);
|
||||
}
|
||||
|
||||
public static ServerPlayer getPlayerFromName(String player){
|
||||
return Main.server.getPlayerList().getPlayerByName(player);
|
||||
}
|
||||
|
||||
public static String returnSetPlayer(ServerPlayer player, String command){
|
||||
return command.replaceAll("%player%", String.valueOf(player.getScoreboardName()));
|
||||
}
|
||||
|
||||
public static void executeServerCommand(String command, ServerPlayer player){
|
||||
if(player != null){
|
||||
Main.server.getCommands().performCommand(Main.server.createCommandSourceStack(), returnSetPlayer(player, command));
|
||||
} else {
|
||||
Main.server.getCommands().performCommand(Main.server.createCommandSourceStack(), command);
|
||||
}
|
||||
}
|
||||
|
||||
public static void executePlayerCommand(ServerPlayer player, String command) {
|
||||
if(player != null){
|
||||
Main.server.getCommands().performCommand(player.createCommandSourceStack(), returnSetPlayer(player, command));
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean hasPermission(@NotNull CommandSourceStack permission, @Nullable String command, @Nullable int level) {
|
||||
return me.lucko.fabric.api.permissions.v0.Permissions.check(permission, command, level);
|
||||
}
|
||||
|
||||
public static ServerPlayer getPlayerAttacker(Entity attackerEntity) {
|
||||
if (attackerEntity == null) return null;
|
||||
|
||||
if (attackerEntity instanceof ServerPlayer) {
|
||||
return (ServerPlayer) attackerEntity;
|
||||
|
||||
} else if (attackerEntity instanceof Projectile) {
|
||||
Entity projectileOwner = ((Projectile) attackerEntity).getOwner();
|
||||
if (!(projectileOwner instanceof ServerPlayer)) return null;
|
||||
return (ServerPlayer) projectileOwner;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static boolean couldCrit(ServerPlayer player) {
|
||||
return !player.isOnGround() && player.fallDistance > 0.0f && !player.hasEffect(MobEffects.BLINDNESS)
|
||||
&& !player.onClimbable() && !player.isInWater() && !player.isPassenger();
|
||||
}
|
||||
|
||||
public static void removeItem(ServerPlayer player, Item item, int count) {
|
||||
for (ItemStack itemStack : ItemStackUtil.getInvItems(player)) {
|
||||
if (itemStack.getItem() != item) continue;
|
||||
|
||||
if (itemStack.getCount() >= count) {
|
||||
itemStack.shrink(count);
|
||||
break;
|
||||
} else {
|
||||
count -= itemStack.getCount();
|
||||
itemStack.shrink(itemStack.getCount());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean containsUuid(List<ServerPlayer> playerList, ServerPlayer player) {
|
||||
for (ServerPlayer listPlayer : playerList) {
|
||||
if (listPlayer.getUUID().equals(player.getUUID())) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.nexia.core.utilities.player;
|
||||
|
||||
public class SavedPlayerData {
|
||||
|
||||
public long muteEnd;
|
||||
public String muteReason;
|
||||
|
||||
public SavedPlayerData() {
|
||||
this.muteEnd = System.currentTimeMillis();
|
||||
this.muteReason = null;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
package com.nexia.core.utilities.pos;
|
||||
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
|
||||
public class BlockVec3 {
|
||||
|
||||
public int x;
|
||||
public int y;
|
||||
public int z;
|
||||
|
||||
public BlockVec3(int x, int y, int z) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
}
|
||||
|
||||
public BlockVec3(double x, double y, double z) {
|
||||
this.x = (int)Math.floor(x);
|
||||
this.y = (int)Math.floor(y);
|
||||
this.z = (int)Math.floor(z);
|
||||
}
|
||||
|
||||
public BlockVec3(Vec3 vec3) {
|
||||
this.x = (int)Math.floor(vec3.x);
|
||||
this.y = (int)Math.floor(vec3.y);
|
||||
this.z = (int)Math.floor(vec3.z);
|
||||
}
|
||||
|
||||
public BlockVec3(BlockPos blockPos) {
|
||||
this.x = blockPos.getX();
|
||||
this.y = blockPos.getY();
|
||||
this.z = blockPos.getZ();
|
||||
}
|
||||
|
||||
public BlockVec3(EntityPos entityPos) {
|
||||
this.x = (int)Math.floor(entityPos.x);
|
||||
this.y = (int)Math.floor(entityPos.y);
|
||||
this.z = (int)Math.floor(entityPos.z);
|
||||
}
|
||||
|
||||
|
||||
public BlockVec3(Entity entity) {
|
||||
this.x = (int)Math.floor(entity.getX());
|
||||
this.y = (int)Math.floor(entity.getY());
|
||||
this.z = (int)Math.floor(entity.getZ());
|
||||
}
|
||||
|
||||
public BlockVec3 clone() {
|
||||
return new BlockVec3(this.x, this.y, this.z);
|
||||
}
|
||||
|
||||
public BlockVec3 c() {
|
||||
return this.clone();
|
||||
}
|
||||
|
||||
public BlockVec3 add(int x, int y, int z) {
|
||||
this.x += x;
|
||||
this.y += y;
|
||||
this.z += z;
|
||||
return this;
|
||||
}
|
||||
|
||||
public BlockVec3 add(double x, double y, double z) {
|
||||
return this.add((int)x, (int)y, (int)z );
|
||||
}
|
||||
|
||||
public BlockVec3 add(BlockVec3 blockVec3) {
|
||||
this.x += blockVec3.x;
|
||||
this.y += blockVec3.y;
|
||||
this.z += blockVec3.z;
|
||||
return this;
|
||||
}
|
||||
|
||||
public BlockVec3 subtract(BlockVec3 blockVec3) {
|
||||
this.x -= blockVec3.x;
|
||||
this.y -= blockVec3.y;
|
||||
this.z -= blockVec3.z;
|
||||
return this;
|
||||
}
|
||||
|
||||
public BlockPos toBlockPos() {
|
||||
return new BlockPos(this.x, this.y, this.z);
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "[x: " + this.x + ", y: " + this.y + ", z: " + this.z + "]";
|
||||
}
|
||||
|
||||
}
|
||||
Loaded 100 of 160 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user