Initial commit

This commit is contained in:
SKBotNL committed 2025-09-27 23:43:20 +02:00
commit d443cf8f27
16 files changed
+1303

No files matched your search

+40
View File
@@ -0,0 +1,40 @@
.gradle
build/
.kotlin
!gradle/wrapper/gradle-wrapper.jar
!**/src/main/**/build/
!**/src/test/**/build/
### IntelliJ IDEA ###
.idea/
*.iws
*.iml
*.ipr
out/
!**/src/main/**/out/
!**/src/test/**/out/
### Eclipse ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache
bin/
!**/src/main/**/bin/
!**/src/test/**/bin/
### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
### VS Code ###
.vscode/
### Mac OS ###
.DS_Store
+24
View File
@@ -0,0 +1,24 @@
This is free and unencumbered software released into the public domain.
Anyone is free to copy, modify, publish, use, compile, sell, or
distribute this software, either in source code form or as a compiled
binary, for any purpose, commercial or non-commercial, and by any
means.
In jurisdictions that recognize copyright laws, the author or authors
of this software dedicate any and all copyright interest in the
software to the public domain. We make this dedication for the benefit
of the public at large and to the detriment of our heirs and
successors. We intend this dedication to be an overt act of
relinquishment in perpetuity of all present and future rights to this
software under copyright law.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
For more information, please refer to <https://unlicense.org>
+3
View File
@@ -0,0 +1,3 @@
# AntiPieRay-OG
A plugin that attempts to prevent players from using pie-ray to detect block entities\
Made for [TrueOG](https://github.com/true-og/true-og)
+77
View File
@@ -0,0 +1,77 @@
import java.io.BufferedReader
plugins {
kotlin("jvm") version "2.2.20"
id("com.diffplug.spotless") version "7.0.4"
id("com.gradleup.shadow") version "8.3.6"
}
val commitHash =
try {
Runtime.getRuntime().exec(arrayOf("git", "rev-parse", "--short=10", "HEAD")).let { process ->
process.waitFor()
val output = process.inputStream.use { it.bufferedReader().use(BufferedReader::readText) }
process.destroy()
output.trim().ifBlank { "unknown" }
}
} catch (_: Exception) {
"unknown"
}
val apiVersion = "1.19"
group = "net.trueog"
version = "$apiVersion-$commitHash"
repositories {
mavenCentral()
maven("https://repo.papermc.io/repository/maven-public/") { name = "papermc-repo" }
maven("https://repo.codemc.io/repository/maven-releases/") { name = "codemc-repo" }
}
dependencies {
compileOnly("io.papermc.paper:paper-api:1.19.4-R0.1-SNAPSHOT")
implementation("com.github.retrooper:packetevents-spigot:2.9.5")
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
}
tasks {
build {
dependsOn(spotlessApply)
dependsOn(shadowJar)
}
jar { archiveClassifier.set("part") }
shadowJar { archiveClassifier.set("") }
}
tasks.processResources {
val props = mapOf("version" to version, "apiVersion" to apiVersion)
inputs.properties(props)
filteringCharset = "UTF-8"
filesMatching("plugin.yml") { expand(props) }
}
val targetJavaVersion = 17
kotlin { jvmToolchain(targetJavaVersion) }
java {
toolchain {
languageVersion = JavaLanguageVersion.of(17)
vendor = JvmVendorSpec.GRAAL_VM
}
}
tasks.withType<AbstractArchiveTask>().configureEach {
isPreserveFileTimestamps = false
isReproducibleFileOrder = true
}
spotless {
kotlin { ktfmt().kotlinlangStyle().configure { it.setMaxWidth(120) } }
kotlinGradle {
ktfmt().kotlinlangStyle().configure { it.setMaxWidth(120) }
target("build.gradle.kts", "settings.gradle.kts")
}
}
View File
Whitespace-only changes.
Binary file not shown.
+7
View File
@@ -0,0 +1,7 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-9.1.0-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Vendored Executable
+248
View File
@@ -0,0 +1,248 @@
#!/bin/sh
#
# Copyright © 2015 the original authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# SPDX-License-Identifier: Apache-2.0
#
##############################################################################
#
# Gradle start up script for POSIX generated by Gradle.
#
# Important for running:
#
# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is
# noncompliant, but you have some other compliant shell such as ksh or
# bash, then to run this script, type that shell name before the whole
# command line, like:
#
# ksh Gradle
#
# Busybox and similar reduced shells will NOT work, because this script
# requires all of these POSIX shell features:
# * functions;
# * expansions «$var», «${var}», «${var:-default}», «${var+SET}»,
# «${var#prefix}», «${var%suffix}», and «$( cmd )»;
# * compound commands having a testable exit status, especially «case»;
# * various built-in commands including «command», «set», and «ulimit».
#
# Important for patching:
#
# (2) This script targets any POSIX shell, so it avoids extensions provided
# by Bash, Ksh, etc; in particular arrays are avoided.
#
# The "traditional" practice of packing multiple parameters into a
# space-separated string is a well documented source of bugs and security
# problems, so this is (mostly) avoided, by progressively accumulating
# options in "$@", and eventually passing that to Java.
#
# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS,
# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly;
# see the in-line comments for details.
#
# There are tweaks for specific operating systems such as AIX, CygWin,
# Darwin, MinGW, and NonStop.
#
# (3) This script is generated from the Groovy template
# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# within the Gradle project.
#
# You can find Gradle at https://github.com/gradle/gradle/.
#
##############################################################################
# Attempt to set APP_HOME
# Resolve links: $0 may be a link
app_path=$0
# Need this for daisy-chained symlinks.
while
APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path
[ -h "$app_path" ]
do
ls=$( ls -ld "$app_path" )
link=${ls#*' -> '}
case $link in #(
/*) app_path=$link ;; #(
*) app_path=$APP_HOME$link ;;
esac
done
# This is normally unused
# shellcheck disable=SC2034
APP_BASE_NAME=${0##*/}
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s\n' "$PWD" ) || exit
# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum
warn () {
echo "$*"
} >&2
die () {
echo
echo "$*"
echo
exit 1
} >&2
# OS specific support (must be 'true' or 'false').
cygwin=false
msys=false
darwin=false
nonstop=false
case "$( uname )" in #(
CYGWIN* ) cygwin=true ;; #(
Darwin* ) darwin=true ;; #(
MSYS* | MINGW* ) msys=true ;; #(
NONSTOP* ) nonstop=true ;;
esac
# Determine the Java command to use to start the JVM.
if [ -n "$JAVA_HOME" ] ; then
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
# IBM's JDK on AIX uses strange locations for the executables
JAVACMD=$JAVA_HOME/jre/sh/java
else
JAVACMD=$JAVA_HOME/bin/java
fi
if [ ! -x "$JAVACMD" ] ; then
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
else
JAVACMD=java
if ! command -v java >/dev/null 2>&1
then
die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
fi
# Increase the maximum file descriptors if we can.
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
case $MAX_FD in #(
max*)
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC2039,SC3045
MAX_FD=$( ulimit -H -n ) ||
warn "Could not query maximum file descriptor limit"
esac
case $MAX_FD in #(
'' | soft) :;; #(
*)
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC2039,SC3045
ulimit -n "$MAX_FD" ||
warn "Could not set maximum file descriptor limit to $MAX_FD"
esac
fi
# Collect all arguments for the java command, stacking in reverse order:
# * args from the command line
# * the main class name
# * -classpath
# * -D...appname settings
# * --module-path (only if needed)
# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables.
# For Cygwin or MSYS, switch paths to Windows format before running java
if "$cygwin" || "$msys" ; then
APP_HOME=$( cygpath --path --mixed "$APP_HOME" )
JAVACMD=$( cygpath --unix "$JAVACMD" )
# Now convert the arguments - kludge to limit ourselves to /bin/sh
for arg do
if
case $arg in #(
-*) false ;; # don't mess with options #(
/?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath
[ -e "$t" ] ;; #(
*) false ;;
esac
then
arg=$( cygpath --path --ignore --mixed "$arg" )
fi
# Roll the args list around exactly as many times as the number of
# args, so each arg winds up back in the position where it started, but
# possibly modified.
#
# NB: a `for` loop captures its iteration list before it begins, so
# changing the positional parameters here affects neither the number of
# iterations, nor the values presented in `arg`.
shift # remove old arg
set -- "$@" "$arg" # push replacement arg
done
fi
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
# Collect all arguments for the java command:
# * DEFAULT_JVM_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
# and any embedded shellness will be escaped.
# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
# treated as '${Hostname}' itself on the command line.
set -- \
"-Dorg.gradle.appname=$APP_BASE_NAME" \
-jar "$APP_HOME/gradle/wrapper/gradle-wrapper.jar" \
"$@"
# Stop when "xargs" is not available.
if ! command -v xargs >/dev/null 2>&1
then
die "xargs is not available"
fi
# Use "xargs" to parse quoted args.
#
# With -n1 it outputs one arg per line, with the quotes and backslashes removed.
#
# In Bash we could simply go:
#
# readarray ARGS < <( xargs -n1 <<<"$var" ) &&
# set -- "${ARGS[@]}" "$@"
#
# but POSIX shell has neither arrays nor command substitution, so instead we
# post-process each arg (as a line of input to sed) to backslash-escape any
# character that might be a shell metacharacter, then use eval to reverse
# that process (while maintaining the separation between arguments), and wrap
# the whole thing up as a single "set" statement.
#
# This will of course break if any of these variables contains a newline or
# an unmatched quote.
#
eval "set -- $(
printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" |
xargs -n1 |
sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' |
tr '\n' ' '
)" '"$@"'
exec "$JAVACMD" "$@"
Vendored
+93
View File
@@ -0,0 +1,93 @@
@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
@rem SPDX-License-Identifier: Apache-2.0
@rem
@if "%DEBUG%"=="" @echo off
@rem ##########################################################################
@rem
@rem Gradle startup script for Windows
@rem
@rem ##########################################################################
@rem Set local scope for the variables with windows NT shell
if "%OS%"=="Windows_NT" setlocal
set DIRNAME=%~dp0
if "%DIRNAME%"=="" set DIRNAME=.
@rem This is normally unused
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%
@rem Resolve any "." and ".." in APP_HOME to make it shorter.
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
@rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome
set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if %ERRORLEVEL% equ 0 goto execute
echo. 1>&2
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2
echo. 1>&2
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
echo location of your Java installation. 1>&2
goto fail
:findJavaFromJavaHome
set JAVA_HOME=%JAVA_HOME:"=%
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
if exist "%JAVA_EXE%" goto execute
echo. 1>&2
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2
echo. 1>&2
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
echo location of your Java installation. 1>&2
goto fail
:execute
@rem Setup the command line
@rem Execute Gradle
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -jar "%APP_HOME%\gradle\wrapper\gradle-wrapper.jar" %*
:end
@rem End local scope for the variables with windows NT shell
if %ERRORLEVEL% equ 0 goto mainEnd
:fail
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
rem the _cmd.exe /c_ return code!
set EXIT_CODE=%ERRORLEVEL%
if %EXIT_CODE% equ 0 set EXIT_CODE=1
if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
exit /b %EXIT_CODE%
:mainEnd
if "%OS%"=="Windows_NT" endlocal
:omega
+1
View File
@@ -0,0 +1 @@
rootProject.name = "AntiPieRay-OG"
@@ -0,0 +1,113 @@
package net.trueog.antiPieRayOG
import com.github.retrooper.packetevents.PacketEvents
import com.github.retrooper.packetevents.event.PacketListenerPriority
import com.github.retrooper.packetevents.protocol.world.states.type.StateType
import com.github.retrooper.packetevents.protocol.world.states.type.StateTypes
import io.github.retrooper.packetevents.factory.spigot.SpigotPacketEventsBuilder
import java.util.Collections
import java.util.IdentityHashMap
import org.bukkit.Material
import org.bukkit.plugin.java.JavaPlugin
class AntiPieRay : JavaPlugin() {
companion object {
lateinit var plugin: AntiPieRay
lateinit var blockEntityHider: BlockEntityHider
val hideStateTypes: MutableSet<StateType> = Collections.newSetFromMap(IdentityHashMap())
val hideMaterials: MutableSet<Material> =
Collections.newSetFromMap<Material>(IdentityHashMap()).apply {
addAll(
listOf(
// <editor-fold desc="Block entities">
Material.CHEST,
Material.TRAPPED_CHEST,
Material.SHULKER_BOX,
Material.WHITE_SHULKER_BOX,
Material.ORANGE_SHULKER_BOX,
Material.MAGENTA_SHULKER_BOX,
Material.LIGHT_BLUE_SHULKER_BOX,
Material.YELLOW_SHULKER_BOX,
Material.LIME_SHULKER_BOX,
Material.PINK_SHULKER_BOX,
Material.GRAY_SHULKER_BOX,
Material.LIGHT_GRAY_SHULKER_BOX,
Material.CYAN_SHULKER_BOX,
Material.PURPLE_SHULKER_BOX,
Material.BLUE_SHULKER_BOX,
Material.BROWN_SHULKER_BOX,
Material.GREEN_SHULKER_BOX,
Material.RED_SHULKER_BOX,
Material.BLACK_SHULKER_BOX,
Material.CAMPFIRE,
Material.SOUL_CAMPFIRE,
Material.BEACON,
Material.ENCHANTING_TABLE,
Material.DRAGON_HEAD,
Material.DRAGON_WALL_HEAD,
Material.CONDUIT,
Material.BELL,
Material.ENDER_CHEST,
Material.SPAWNER,
// </editor-fold>
)
)
}
}
override fun onLoad() {
PacketEvents.setAPI(SpigotPacketEventsBuilder.build(this))
PacketEvents.getAPI().load()
// Has to be here otherwise the plugin doesn't load
hideStateTypes.addAll(
listOf(
// <editor-fold desc="Block entities">
StateTypes.CHEST,
StateTypes.TRAPPED_CHEST,
StateTypes.SHULKER_BOX,
StateTypes.WHITE_SHULKER_BOX,
StateTypes.ORANGE_SHULKER_BOX,
StateTypes.MAGENTA_SHULKER_BOX,
StateTypes.LIGHT_BLUE_SHULKER_BOX,
StateTypes.YELLOW_SHULKER_BOX,
StateTypes.LIME_SHULKER_BOX,
StateTypes.PINK_SHULKER_BOX,
StateTypes.GRAY_SHULKER_BOX,
StateTypes.LIGHT_GRAY_SHULKER_BOX,
StateTypes.CYAN_SHULKER_BOX,
StateTypes.PURPLE_SHULKER_BOX,
StateTypes.BLUE_SHULKER_BOX,
StateTypes.BROWN_SHULKER_BOX,
StateTypes.GREEN_SHULKER_BOX,
StateTypes.RED_SHULKER_BOX,
StateTypes.BLACK_SHULKER_BOX,
StateTypes.CAMPFIRE,
StateTypes.SOUL_CAMPFIRE,
StateTypes.BEACON,
StateTypes.ENCHANTING_TABLE,
StateTypes.DRAGON_HEAD,
StateTypes.DRAGON_WALL_HEAD,
StateTypes.CONDUIT,
StateTypes.BELL,
StateTypes.ENDER_CHEST,
StateTypes.SPAWNER,
// </editor-fold>
)
)
PacketEvents.getAPI().eventManager.registerListener(ChunkDataPacketListener(), PacketListenerPriority.NORMAL)
PacketEvents.getAPI().eventManager.registerListener(BlockChangePacketListener(), PacketListenerPriority.NORMAL)
}
override fun onEnable() {
PacketEvents.getAPI().init()
plugin = this
blockEntityHider = BlockEntityHider()
server.pluginManager.registerEvents(Events(), this)
}
override fun onDisable() {
PacketEvents.getAPI().terminate()
}
}
@@ -0,0 +1,40 @@
package net.trueog.antiPieRayOG
import com.github.retrooper.packetevents.event.PacketListener
import com.github.retrooper.packetevents.event.PacketSendEvent
import com.github.retrooper.packetevents.protocol.packettype.PacketType
import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerBlockChange
import net.trueog.antiPieRayOG.BlockEntityHider.Companion.BlockPosition
import org.bukkit.Location
import org.bukkit.entity.Player
class BlockChangePacketListener : PacketListener {
override fun onPacketSend(event: PacketSendEvent) {
if (event.packetType != PacketType.Play.Server.BLOCK_CHANGE) {
return
}
val player = event.getPlayer<Player>()
val worldName = player.world.name
if (worldName != "world" && worldName != "world_nether" && worldName != "world_the_end") return
val blockChange = WrapperPlayServerBlockChange(event)
if (blockChange.blockState.type !in AntiPieRay.hideStateTypes) {
return
}
val pos = blockChange.blockPosition
val visible =
BlockEntityHider.canSee(
player.eyeLocation,
Location(player.world, pos.x.toDouble(), pos.y.toDouble(), pos.z.toDouble()),
)
if (!visible) {
val blockPos = BlockPosition(pos.x, pos.y, pos.z)
AntiPieRay.blockEntityHider.addPos(player.uniqueId, blockPos)
event.isCancelled = true
}
}
}
@@ -0,0 +1,512 @@
package net.trueog.antiPieRayOG
import java.util.*
import java.util.concurrent.ConcurrentHashMap
import kotlin.math.abs
import kotlin.math.min
import kotlin.math.roundToInt
import org.bukkit.Bukkit
import org.bukkit.Location
import org.bukkit.Material
import org.bukkit.World
import org.bukkit.entity.Player
import org.bukkit.util.BlockIterator
import org.bukkit.util.Vector
class BlockEntityHider {
companion object {
fun canSee(eye: Location, loc: Location): Boolean {
// Get the center
val blockCenterLoc = loc.clone().add(0.5, 0.5, 0.5)
val offsets =
listOf(
Vector(0.5, 0.5, 0.5),
Vector(0.5, 0.5, -0.5),
Vector(0.5, -0.5, 0.5),
Vector(0.5, -0.5, -0.5),
Vector(-0.5, 0.5, 0.5),
Vector(-0.5, 0.5, -0.5),
Vector(-0.5, -0.5, 0.5),
Vector(-0.5, -0.5, -0.5),
)
for (offset in offsets) {
val blockLoc = blockCenterLoc.clone().add(offset)
val direction = blockLoc.toVector().subtract(eye.toVector()).normalize()
val offsetEye = eye.clone().setDirection(direction)
val maxDistance = offsetEye.distance(blockLoc).roundToInt() - 1
val blockIterator = BlockIterator(offsetEye, 0.0, maxDistance)
var visible = true
while (blockIterator.hasNext()) {
val hitBlock = blockIterator.next()
if (hitBlock == loc.block) {
break
}
if (!isAir(hitBlock.type) && !isLiquid(hitBlock.type) && !isTransparent(hitBlock.type)) {
visible = false
break
}
}
if (visible) return true
}
return false
}
fun isTransparent(material: Material): Boolean {
return when (material) {
// <editor-fold desc="Transparent materials">
Material.ACACIA_DOOR,
Material.ACACIA_FENCE,
Material.ACACIA_FENCE_GATE,
Material.ACACIA_HANGING_SIGN,
Material.ACACIA_LEAVES,
Material.ACACIA_LOG,
Material.ACACIA_PLANKS,
Material.ACACIA_PRESSURE_PLATE,
Material.ACACIA_SIGN,
Material.ACACIA_SLAB,
Material.ACACIA_STAIRS,
Material.ACACIA_TRAPDOOR,
Material.ACACIA_WALL_HANGING_SIGN,
Material.ACACIA_WALL_SIGN,
Material.ACACIA_WOOD,
Material.AZALEA_LEAVES,
Material.BAMBOO,
Material.BAMBOO_BLOCK,
Material.BAMBOO_DOOR,
Material.BAMBOO_FENCE,
Material.BAMBOO_FENCE_GATE,
Material.BAMBOO_HANGING_SIGN,
Material.BAMBOO_MOSAIC,
Material.BAMBOO_MOSAIC_SLAB,
Material.BAMBOO_MOSAIC_STAIRS,
Material.BAMBOO_PLANKS,
Material.BAMBOO_PRESSURE_PLATE,
Material.BAMBOO_SAPLING,
Material.BAMBOO_SIGN,
Material.BAMBOO_SLAB,
Material.BAMBOO_STAIRS,
Material.BAMBOO_TRAPDOOR,
Material.BAMBOO_WALL_HANGING_SIGN,
Material.BAMBOO_WALL_SIGN,
Material.BARREL,
Material.BEEHIVE,
Material.BEE_NEST,
Material.BIRCH_DOOR,
Material.BIRCH_FENCE,
Material.BIRCH_FENCE_GATE,
Material.BIRCH_HANGING_SIGN,
Material.BIRCH_LEAVES,
Material.BIRCH_LOG,
Material.BIRCH_PLANKS,
Material.BIRCH_PRESSURE_PLATE,
Material.BIRCH_SIGN,
Material.BIRCH_SLAB,
Material.BIRCH_STAIRS,
Material.BIRCH_TRAPDOOR,
Material.BIRCH_WALL_SIGN,
Material.BIRCH_WOOD,
Material.BLACK_BANNER,
Material.BLACK_BED,
Material.BLACK_CARPET,
Material.BLACK_WALL_BANNER,
Material.BLACK_WOOL,
Material.BLUE_BANNER,
Material.BLUE_BED,
Material.BLUE_CARPET,
Material.BLUE_WALL_BANNER,
Material.BLUE_WOOL,
Material.BOOKSHELF,
Material.BROWN_BANNER,
Material.BROWN_BED,
Material.BROWN_CARPET,
Material.BROWN_MUSHROOM_BLOCK,
Material.BROWN_WALL_BANNER,
Material.BROWN_WOOL,
Material.CAMPFIRE,
Material.CARTOGRAPHY_TABLE,
Material.CHERRY_DOOR,
Material.CHERRY_FENCE,
Material.CHERRY_FENCE_GATE,
Material.CHERRY_HANGING_SIGN,
Material.CHERRY_LEAVES,
Material.CHERRY_LOG,
Material.CHERRY_PLANKS,
Material.CHERRY_PRESSURE_PLATE,
Material.CHERRY_SIGN,
Material.CHERRY_SLAB,
Material.CHERRY_STAIRS,
Material.CHERRY_TRAPDOOR,
Material.CHERRY_WALL_HANGING_SIGN,
Material.CHERRY_WALL_SIGN,
Material.CHERRY_WOOD,
Material.CHEST,
Material.CHISELED_BOOKSHELF,
Material.COMPOSTER,
Material.CRAFTING_TABLE,
Material.CRIMSON_HANGING_SIGN,
Material.CRIMSON_WALL_HANGING_SIGN,
Material.CYAN_BANNER,
Material.CYAN_BED,
Material.CYAN_CARPET,
Material.CYAN_WALL_BANNER,
Material.CYAN_WOOL,
Material.DARK_OAK_DOOR,
Material.DARK_OAK_FENCE,
Material.DARK_OAK_FENCE_GATE,
Material.DARK_OAK_HANGING_SIGN,
Material.DARK_OAK_LEAVES,
Material.DARK_OAK_LOG,
Material.DARK_OAK_PLANKS,
Material.DARK_OAK_PRESSURE_PLATE,
Material.DARK_OAK_SIGN,
Material.DARK_OAK_SLAB,
Material.DARK_OAK_STAIRS,
Material.DARK_OAK_TRAPDOOR,
Material.DARK_OAK_WALL_HANGING_SIGN,
Material.DARK_OAK_WALL_SIGN,
Material.DARK_OAK_WOOD,
Material.DAYLIGHT_DETECTOR,
Material.DEAD_BUSH,
Material.FERN,
Material.FLETCHING_TABLE,
Material.FLOWERING_AZALEA_LEAVES,
Material.GLOW_LICHEN,
Material.GRASS,
Material.GRAY_BANNER,
Material.GRAY_BED,
Material.GRAY_CARPET,
Material.GRAY_WALL_BANNER,
Material.GRAY_WOOL,
Material.GREEN_BANNER,
Material.GREEN_BED,
Material.GREEN_CARPET,
Material.GREEN_WALL_BANNER,
Material.GREEN_WOOL,
Material.HANGING_ROOTS,
Material.JUKEBOX,
Material.JUNGLE_DOOR,
Material.JUNGLE_FENCE,
Material.JUNGLE_FENCE_GATE,
Material.JUNGLE_HANGING_SIGN,
Material.JUNGLE_LEAVES,
Material.JUNGLE_LOG,
Material.JUNGLE_PLANKS,
Material.JUNGLE_PRESSURE_PLATE,
Material.JUNGLE_SIGN,
Material.JUNGLE_SLAB,
Material.JUNGLE_STAIRS,
Material.JUNGLE_TRAPDOOR,
Material.JUNGLE_WALL_HANGING_SIGN,
Material.JUNGLE_WALL_SIGN,
Material.JUNGLE_WOOD,
Material.LARGE_FERN,
Material.LECTERN,
Material.LIGHT_BLUE_BANNER,
Material.LIGHT_BLUE_BED,
Material.LIGHT_BLUE_CARPET,
Material.LIGHT_BLUE_WALL_BANNER,
Material.LIGHT_BLUE_WOOL,
Material.LIGHT_GRAY_BANNER,
Material.LIGHT_GRAY_BED,
Material.LIGHT_GRAY_CARPET,
Material.LIGHT_GRAY_WALL_BANNER,
Material.LIGHT_GRAY_WOOL,
Material.LILAC,
Material.LIME_BANNER,
Material.LIME_BED,
Material.LIME_CARPET,
Material.LIME_WALL_BANNER,
Material.LIME_WOOL,
Material.LOOM,
Material.MAGENTA_BANNER,
Material.MAGENTA_BED,
Material.MAGENTA_CARPET,
Material.MAGENTA_WALL_BANNER,
Material.MAGENTA_WOOL,
Material.MANGROVE_DOOR,
Material.MANGROVE_FENCE,
Material.MANGROVE_FENCE_GATE,
Material.MANGROVE_HANGING_SIGN,
Material.MANGROVE_LEAVES,
Material.MANGROVE_LOG,
Material.MANGROVE_PLANKS,
Material.MANGROVE_PRESSURE_PLATE,
Material.MANGROVE_ROOTS,
Material.MANGROVE_SIGN,
Material.MANGROVE_SLAB,
Material.MANGROVE_STAIRS,
Material.MANGROVE_TRAPDOOR,
Material.MANGROVE_WALL_HANGING_SIGN,
Material.MANGROVE_WALL_SIGN,
Material.MANGROVE_WOOD,
Material.MUSHROOM_STEM,
Material.NOTE_BLOCK,
Material.OAK_DOOR,
Material.OAK_FENCE,
Material.OAK_FENCE_GATE,
Material.OAK_HANGING_SIGN,
Material.OAK_LEAVES,
Material.OAK_LOG,
Material.OAK_PLANKS,
Material.OAK_PRESSURE_PLATE,
Material.OAK_SIGN,
Material.OAK_SLAB,
Material.OAK_STAIRS,
Material.OAK_TRAPDOOR,
Material.OAK_WALL_HANGING_SIGN,
Material.OAK_WALL_SIGN,
Material.OAK_WOOD,
Material.ORANGE_BANNER,
Material.ORANGE_BED,
Material.ORANGE_CARPET,
Material.ORANGE_WALL_BANNER,
Material.ORANGE_WOOL,
Material.PEONY,
Material.PINK_BANNER,
Material.PINK_BED,
Material.PINK_CARPET,
Material.PINK_WALL_BANNER,
Material.PINK_WOOL,
Material.PURPLE_BANNER,
Material.PURPLE_BED,
Material.PURPLE_CARPET,
Material.PURPLE_WALL_BANNER,
Material.PURPLE_WOOL,
Material.RED_BANNER,
Material.RED_BED,
Material.RED_CARPET,
Material.RED_MUSHROOM_BLOCK,
Material.RED_WALL_BANNER,
Material.RED_WOOL,
Material.ROSE_BUSH,
Material.SMITHING_TABLE,
Material.SOUL_CAMPFIRE,
Material.SPRUCE_DOOR,
Material.SPRUCE_FENCE,
Material.SPRUCE_FENCE_GATE,
Material.SPRUCE_HANGING_SIGN,
Material.SPRUCE_LEAVES,
Material.SPRUCE_LOG,
Material.SPRUCE_PLANKS,
Material.SPRUCE_PRESSURE_PLATE,
Material.SPRUCE_SIGN,
Material.SPRUCE_SLAB,
Material.SPRUCE_STAIRS,
Material.SPRUCE_TRAPDOOR,
Material.SPRUCE_WALL_HANGING_SIGN,
Material.SPRUCE_WALL_SIGN,
Material.SPRUCE_WOOD,
Material.STRIPPED_ACACIA_LOG,
Material.STRIPPED_ACACIA_WOOD,
Material.STRIPPED_BAMBOO_BLOCK,
Material.STRIPPED_BIRCH_LOG,
Material.STRIPPED_BIRCH_WOOD,
Material.STRIPPED_CHERRY_LOG,
Material.STRIPPED_CHERRY_WOOD,
Material.STRIPPED_DARK_OAK_LOG,
Material.STRIPPED_DARK_OAK_WOOD,
Material.STRIPPED_JUNGLE_LOG,
Material.STRIPPED_JUNGLE_WOOD,
Material.STRIPPED_MANGROVE_LOG,
Material.STRIPPED_MANGROVE_WOOD,
Material.STRIPPED_OAK_LOG,
Material.STRIPPED_OAK_WOOD,
Material.STRIPPED_SPRUCE_LOG,
Material.STRIPPED_SPRUCE_WOOD,
Material.SUNFLOWER,
Material.TALL_GRASS,
Material.TNT,
Material.TRAPPED_CHEST,
Material.VINE,
Material.WARPED_HANGING_SIGN,
Material.WARPED_WALL_HANGING_SIGN,
Material.WHITE_BANNER,
Material.WHITE_BED,
Material.WHITE_CARPET,
Material.WHITE_WALL_BANNER,
Material.WHITE_WOOL,
Material.YELLOW_BANNER,
Material.YELLOW_BED,
Material.YELLOW_CARPET,
Material.YELLOW_WALL_BANNER,
Material.YELLOW_WOOL,
Material.LEGACY_WOOD,
Material.LEGACY_LOG,
Material.LEGACY_LEAVES,
Material.LEGACY_NOTE_BLOCK,
Material.LEGACY_BED_BLOCK,
Material.LEGACY_LONG_GRASS,
Material.LEGACY_DEAD_BUSH,
Material.LEGACY_WOOL,
Material.LEGACY_TNT,
Material.LEGACY_BOOKSHELF,
Material.LEGACY_WOOD_STAIRS,
Material.LEGACY_CHEST,
Material.LEGACY_WORKBENCH,
Material.LEGACY_SIGN_POST,
Material.LEGACY_WOODEN_DOOR,
Material.LEGACY_WALL_SIGN,
Material.LEGACY_WOOD_PLATE,
Material.LEGACY_JUKEBOX,
Material.LEGACY_FENCE,
Material.LEGACY_TRAP_DOOR,
Material.LEGACY_HUGE_MUSHROOM_1,
Material.LEGACY_HUGE_MUSHROOM_2,
Material.LEGACY_VINE,
Material.LEGACY_FENCE_GATE,
Material.LEGACY_WOOD_DOUBLE_STEP,
Material.LEGACY_WOOD_STEP,
Material.LEGACY_SPRUCE_WOOD_STAIRS,
Material.LEGACY_BIRCH_WOOD_STAIRS,
Material.LEGACY_JUNGLE_WOOD_STAIRS,
Material.LEGACY_TRAPPED_CHEST,
Material.LEGACY_DAYLIGHT_DETECTOR,
Material.LEGACY_CARPET,
Material.LEGACY_LEAVES_2,
Material.LEGACY_LOG_2,
Material.LEGACY_ACACIA_STAIRS,
Material.LEGACY_DARK_OAK_STAIRS,
Material.LEGACY_DOUBLE_PLANT,
Material.LEGACY_SPRUCE_FENCE_GATE,
Material.LEGACY_BIRCH_FENCE_GATE,
Material.LEGACY_JUNGLE_FENCE_GATE,
Material.LEGACY_DARK_OAK_FENCE_GATE,
Material.LEGACY_ACACIA_FENCE_GATE,
Material.LEGACY_SPRUCE_FENCE,
Material.LEGACY_BIRCH_FENCE,
Material.LEGACY_JUNGLE_FENCE,
Material.LEGACY_DARK_OAK_FENCE,
Material.LEGACY_ACACIA_FENCE,
Material.LEGACY_STANDING_BANNER,
Material.LEGACY_WALL_BANNER,
Material.LEGACY_DAYLIGHT_DETECTOR_INVERTED,
Material.LEGACY_SPRUCE_DOOR,
Material.LEGACY_BIRCH_DOOR,
Material.LEGACY_JUNGLE_DOOR,
Material.LEGACY_ACACIA_DOOR,
Material.LEGACY_DARK_OAK_DOOR ->
// </editor-fold>
true
else -> false
}
}
fun isAir(material: Material): Boolean {
return when (material) {
Material.AIR,
Material.CAVE_AIR,
Material.VOID_AIR -> true
else -> false
}
}
fun isLiquid(material: Material): Boolean {
return when (material) {
Material.WATER,
Material.LAVA -> true
else -> false
}
}
val neighbourOffsets =
listOf(
Triple(1, 0, 0),
Triple(-1, 0, 0),
Triple(0, 1, 0),
Triple(0, -1, 0),
Triple(0, 0, 1),
Triple(0, 0, -1),
)
fun getAdjacentPositions(pos: BlockPosition): Set<BlockPosition> =
neighbourOffsets.map { (dx, dy, dz) -> pos.add(dx, dy, dz) }.toSet()
data class BlockPosition(var x: Int, var y: Int, var z: Int) {
fun add(x: Int, y: Int, z: Int): BlockPosition {
return BlockPosition(this.x + x, this.y + y, this.z + z)
}
fun toLocation(world: World) = Location(world, x.toDouble(), y.toDouble(), z.toDouble())
}
fun Location.toBlockPosition() = BlockPosition(blockX, blockY, blockZ)
}
val hiddenBlocksForPlayer: MutableMap<UUID, MutableSet<BlockPosition>> = ConcurrentHashMap()
val blockHiddenForPlayers: MutableMap<BlockPosition, MutableSet<UUID>> = ConcurrentHashMap()
fun addPos(uuid: UUID, pos: BlockPosition) {
hiddenBlocksForPlayer.computeIfAbsent(uuid) { ConcurrentHashMap.newKeySet() }.add(pos)
blockHiddenForPlayers.computeIfAbsent(pos) { ConcurrentHashMap.newKeySet() }.add(uuid)
}
fun removePos(uuid: UUID, pos: BlockPosition) {
hiddenBlocksForPlayer[uuid]?.remove(pos)
blockHiddenForPlayers[pos]?.remove(uuid)
if (hiddenBlocksForPlayer[uuid]?.isEmpty() == true) hiddenBlocksForPlayer.remove(uuid)
if (blockHiddenForPlayers[pos]?.isEmpty() == true) blockHiddenForPlayers.remove(pos)
}
fun removeAllPos(uuid: UUID) {
val hiddenBlocks = hiddenBlocksForPlayer[uuid] ?: return
hiddenBlocks.forEach { blockHiddenForPlayers[it]?.remove(uuid) }
hiddenBlocksForPlayer.remove(uuid)
}
fun removeOutOfRangeBlocks(player: Player) {
val threshold = min(player.viewDistance, Bukkit.getViewDistance()) + 1
val chunkX = player.location.x.toInt() shr 4
val chunkZ = player.location.z.toInt() shr 4
blockHiddenForPlayers
.filterKeys {
abs(chunkX - (it.x shr 4)) > threshold || abs(chunkZ - (it.z shr 4)) > threshold
}
.forEach { (pos, uuids) -> uuids.forEach { uuid -> removePos(uuid, pos) } }
}
fun removeIfNeeded(pos: BlockPosition, world: World) {
if (world.getBlockAt(pos.toLocation(world)).type !in AntiPieRay.hideMaterials) {
blockHiddenForPlayers
.filterKeys { pos == it }
.values
.forEach { uuids -> uuids.forEach { uuid -> removePos(uuid, pos) } }
}
}
fun updateBlockVisibility(player: Player) {
val blockList = hiddenBlocksForPlayer[player.uniqueId] ?: return
blockList.forEach {
val loc = it.toLocation(player.world)
val visible = canSee(player.eyeLocation, loc)
if (!visible) {
return@forEach
}
val block = player.world.getBlockAt(loc)
removePos(player.uniqueId, it)
player.sendBlockChange(loc, block.blockData)
}
}
fun updateBlockVisibility(pos: BlockPosition, world: World) {
removeIfNeeded(pos, world)
val adjacentPositions = getAdjacentPositions(pos)
adjacentPositions.forEach { adjacentPos ->
val loc = adjacentPos.toLocation(world)
blockHiddenForPlayers[adjacentPos]?.forEach { uuid ->
val player = Bukkit.getPlayer(uuid) ?: return@forEach
val visible = canSee(player.eyeLocation, loc)
if (!visible) {
return@forEach
}
val block = player.world.getBlockAt(loc)
removePos(player.uniqueId, adjacentPos)
player.sendBlockChange(loc, block.blockData)
}
}
}
}
@@ -0,0 +1,96 @@
package net.trueog.antiPieRayOG
import com.github.retrooper.packetevents.event.PacketListener
import com.github.retrooper.packetevents.event.PacketSendEvent
import com.github.retrooper.packetevents.protocol.packettype.PacketType
import com.github.retrooper.packetevents.protocol.world.chunk.Column
import com.github.retrooper.packetevents.protocol.world.states.type.StateTypes
import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerChunkData
import net.trueog.antiPieRayOG.BlockEntityHider.Companion.BlockPosition
import org.bukkit.Location
import org.bukkit.entity.Player
class ChunkDataPacketListener : PacketListener {
override fun onPacketSend(event: PacketSendEvent) {
if (event.packetType != PacketType.Play.Server.CHUNK_DATA) {
return
}
val player = event.getPlayer<Player>()
val worldName = player.world.name
if (worldName != "world" && worldName != "world_nether" && worldName != "world_the_end") return
val chunkData = WrapperPlayServerChunkData(event)
val column = chunkData.column
val chunks = column.chunks
val tileEntitiesToRemove = mutableSetOf<BlockPosition>()
chunks.forEachIndexed { sectionIndex, baseChunk ->
val sectionBaseY = sectionIndex * 16 - 64
for (x in 0 until 16) {
for (y in 0 until 16) {
for (z in 0 until 16) {
val blockState = baseChunk.get(x, y, z)
if (blockState.type !in AntiPieRay.hideStateTypes) {
continue
}
val absoluteX = column.x * 16 + x
val absoluteY = sectionBaseY + y
val absoluteZ = column.z * 16 + z
val visible =
BlockEntityHider.canSee(
player.eyeLocation,
Location(player.world, absoluteX.toDouble(), absoluteY.toDouble(), absoluteZ.toDouble()),
)
if (!visible) {
val blockPos = BlockPosition(absoluteX, absoluteY, absoluteZ)
tileEntitiesToRemove += blockPos
AntiPieRay.blockEntityHider.addPos(player.uniqueId, blockPos)
baseChunk.set(x, y, z, StateTypes.AIR.createBlockState())
}
}
}
}
}
if (tileEntitiesToRemove.isEmpty()) {
return
}
val tileEntities = column.tileEntities.toMutableSet()
tileEntities.removeIf { BlockPosition(it.x, it.y, it.z) in tileEntitiesToRemove }
val tileEntitiesArray = tileEntities.toTypedArray()
AntiPieRay.blockEntityHider.removeOutOfRangeBlocks(player)
@Suppress("DEPRECATION")
val newColumn =
when {
!column.hasHeightMaps() && !column.hasBiomeData() ->
Column(column.x, column.z, column.isFullChunk, chunks, tileEntitiesArray)
column.hasHeightMaps() && !column.hasBiomeData() ->
Column(column.x, column.z, column.isFullChunk, chunks, tileEntitiesArray, column.heightMaps)
!column.hasHeightMaps() && column.hasBiomeData() ->
Column(column.x, column.z, column.isFullChunk, chunks, tileEntitiesArray, column.biomeDataBytes)
else ->
Column(
column.x,
column.z,
column.isFullChunk,
chunks,
tileEntitiesArray,
column.heightMaps,
column.biomeDataBytes,
)
}
chunkData.column = newColumn
event.markForReEncode(true)
}
}
@@ -0,0 +1,44 @@
package net.trueog.antiPieRayOG
import net.trueog.antiPieRayOG.BlockEntityHider.Companion.toBlockPosition
import org.bukkit.Bukkit
import org.bukkit.event.EventHandler
import org.bukkit.event.Listener
import org.bukkit.event.block.BlockBreakEvent
import org.bukkit.event.player.PlayerChangedWorldEvent
import org.bukkit.event.player.PlayerMoveEvent
class Events : Listener {
@EventHandler
fun onPlayerMove(event: PlayerMoveEvent) {
val worldName = event.player.world.name
if (worldName != "world" && worldName != "world_nether" && worldName != "world_the_end") return
AntiPieRay.blockEntityHider.updateBlockVisibility(event.player)
}
@EventHandler
fun onBlockBreak(event: BlockBreakEvent) {
val worldName = event.player.world.name
if (worldName != "world" && worldName != "world_nether" && worldName != "world_the_end") return
Bukkit.getScheduler()
.runTask(
AntiPieRay.plugin,
Runnable {
AntiPieRay.blockEntityHider.updateBlockVisibility(
event.block.location.toBlockPosition(),
event.block.world,
)
},
)
}
@EventHandler
fun onPlayerChangedWorld(event: PlayerChangedWorldEvent) {
val worldName = event.player.world.name
if (worldName != "world" && worldName != "world_nether" && worldName != "world_the_end") return
AntiPieRay.blockEntityHider.removeAllPos(event.player.uniqueId)
}
}
+5
View File
@@ -0,0 +1,5 @@
name: AntiPieRay-OG
version: '${version}'
main: net.trueog.antiPieRayOG.AntiPieRay
api-version: '${apiVersion}'
author: "SKBotNL"