Skip to content

Commit

Permalink
feat(Refinement)
Browse files Browse the repository at this point in the history
  • Loading branch information
BlurOne-GIT committed Jul 23, 2023
1 parent f57a34d commit 37a58be
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 21 deletions.
74 changes: 54 additions & 20 deletions src/main/java/code/blurone/snifferexploited/SnifferExploited.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,31 +10,45 @@ import net.minecraft.world.item.Item
import net.minecraft.world.item.Items
import net.minecraft.world.item.alchemy.Potion
import net.minecraft.world.item.alchemy.PotionBrewing
import net.minecraft.world.item.alchemy.PotionUtils
import net.minecraft.world.item.alchemy.Potions
import net.minecraft.world.level.block.BrewingStandBlock
import net.minecraft.world.level.block.entity.BrewingStandBlockEntity
import org.apache.commons.lang.UnhandledException
import org.bukkit.*
import org.bukkit.block.BrewingStand
import org.bukkit.craftbukkit.v1_20_R1.block.CraftBrewingStand
import org.bukkit.craftbukkit.v1_20_R1.entity.CraftDisplay
import org.bukkit.craftbukkit.v1_20_R1.entity.CraftPlayer
import org.bukkit.craftbukkit.v1_20_R1.entity.CraftSniffer
import org.bukkit.craftbukkit.v1_20_R1.inventory.CraftItemStack
import org.bukkit.entity.*
import org.bukkit.event.EventHandler
import org.bukkit.event.EventPriority
import org.bukkit.event.Listener
import org.bukkit.event.block.Action
import org.bukkit.event.block.BlockBreakEvent
import org.bukkit.event.block.BlockPlaceEvent
import org.bukkit.event.block.BrewingStartEvent
import org.bukkit.event.inventory.BrewEvent
import org.bukkit.event.player.PlayerInteractEntityEvent
import org.bukkit.event.player.PlayerInteractEvent
import org.bukkit.event.player.PlayerTeleportEvent
import org.bukkit.inventory.EquipmentSlot
import org.bukkit.inventory.ItemStack
import org.bukkit.inventory.meta.PotionMeta
import org.bukkit.inventory.meta.SkullMeta
import org.bukkit.metadata.FixedMetadataValue
import org.bukkit.plugin.java.JavaPlugin
import org.bukkit.potion.PotionEffectType
import org.bukkit.scheduler.BukkitRunnable
import org.bukkit.scheduler.BukkitTask
import org.bukkit.util.Transformation
import org.joml.Vector3f
import java.util.*
import kotlin.math.atan2
import kotlin.math.pow
import kotlin.math.sqrt


class SnifferExploited : JavaPlugin(), Listener {
Expand All @@ -44,24 +58,20 @@ class SnifferExploited : JavaPlugin(), Listener {
private val oreSniffingRange = config.getInt("oreSniffingRange", 16)
private val oreSniffingDuration = config.getLong("oreSniffingDuration", 60) * 20
private val oreSniffingDurationNether = config.getLong("oreSniffingDurationNether", 10) * 20
//private val experimentalPotions = config.getBoolean("experimentalPotions", false)

override fun onEnable() {
// Plugin startup logic
saveDefaultConfig()
server.pluginManager.registerEvents(this, this)
timeBeforeExploding = config.getInt("timeBeforeExploding", 4) * 5

/*
if (!experimentalPotions) return
val wereAccessible: MutableList<Boolean> = mutableListOf()
// Unfreeze registry
/*
val unregisteredIntrusiveHoldersField = MappedRegistry::class.java.getDeclaredField("m") //m -> unregisteredIntrusiveHolders: Map<T, Holder.Reference<T>>
wereAccessible.add(unregisteredIntrusiveHoldersField.isAccessible)
unregisteredIntrusiveHoldersField.isAccessible = true
val map = IdentityHashMap<Potion, Holder.Reference<Potion>>()
unregisteredIntrusiveHoldersField.set(BuiltInRegistries.POTION, map)
*/

val frozenField = MappedRegistry::class.java.getDeclaredField("l") //l -> frozen: Boolean
wereAccessible.add(frozenField.isAccessible)
frozenField.isAccessible = true
Expand Down Expand Up @@ -90,6 +100,7 @@ class SnifferExploited : JavaPlugin(), Listener {
BuiltInRegistries.POTION.freeze()
addMixMethod.isAccessible = wereAccessible.removeLast()
frozenField.isAccessible = wereAccessible.removeLast()
*/
}

override fun onDisable() {
Expand All @@ -99,6 +110,18 @@ class SnifferExploited : JavaPlugin(), Listener {
}
}

/*
@EventHandler(priority = EventPriority.HIGHEST)
fun brewFinishEvent(event: BrewEvent)
{
if (!experimentalPotions) return
event.results.forEach {
it.itemMeta = org.bukkit.craftbukkit.v1_20_R1.inventory.CraftMeta
}
}
*/

@EventHandler
fun playerInteractEvent(event: PlayerInteractEntityEvent)
{
Expand All @@ -118,25 +141,35 @@ class SnifferExploited : JavaPlugin(), Listener {
{
sniffer.handle.goalSelector.removeAllGoals { it.stop(); true }
sniffer.handle.navigation.stop()
//sniffer.handle.lookAt((event.player as CraftPlayer).handle, 360f, 180f)
sniffer.location.yaw = Math.toDegrees(
atan2(
event.player.location.z - sniffer.location.z, event.player.location.x - sniffer.location.x
)
).toFloat() - 90
//sniffer.location.pitch =
sniffer.teleport(sniffer.location.apply {
yaw = Math.toDegrees(
atan2(
event.player.location.z - sniffer.location.z, event.player.location.x - sniffer.location.x
)
).toFloat() - 90

pitch = Math.toDegrees(
-atan2(
event.player.eyeLocation.y - sniffer.eyeLocation.y,
sqrt(
(event.player.location.x - sniffer.location.x).pow(2) + (event.player.location.z - sniffer.location.z).pow(2)
)
)
).toFloat()
}, PlayerTeleportEvent.TeleportCause.PLUGIN)
sniffer.handle.setYBodyRot(sniffer.handle.yHeadRot)
val goal = RunAroundLikeHighOnSugarGoal(sniffer)
object : BukkitRunnable()
{
override fun run() {sniffer.state = Sniffer.State.SNIFFING}
}.runTaskLater(this, 5)
override fun run() {sniffer.state = Sniffer.State.SNIFFING; sniffer.handle.sniffingAnimationState.startIfStopped(sniffer.handle.tickCount)}
}.runTaskLater(this, 10)
object : BukkitRunnable()
{
override fun run() {
sniffer.handle.goalSelector.addGoal(0, goal)
sniffer.handle.goalSelector.availableGoals.first { it.goal == goal }.start()
}
}.runTaskLater(this, 25)
}.runTaskLater(this, 30)
sniffer.setMetadata(highOnSugarMetaName, FixedMetadataValue(this, goal))
}
else
Expand All @@ -161,14 +194,15 @@ class SnifferExploited : JavaPlugin(), Listener {
@EventHandler(priority = EventPriority.LOWEST)
fun sniffEvent(event: PlayerInteractEvent)
{
if (event.item?.type != Material.PLAYER_HEAD ||
if (event.item?.type != Material.PLAYER_HEAD || event.player.gameMode == GameMode.SPECTATOR ||
(event.action != Action.RIGHT_CLICK_AIR &&
event.action != Action.RIGHT_CLICK_BLOCK)) return

val skullMeta = event.item!!.itemMeta as SkullMeta
if (!skullMeta.hasOwner() || skullMeta.ownerProfile!!.name != snifferNoseName) return

event.item!!.amount--
if (event.player.gameMode != GameMode.CREATIVE)
event.item!!.amount--
event.player.playSound(event.player.location, Sound.ENTITY_SNIFFER_SNIFFING, SoundCategory.PLAYERS, 4f, 0.75f)
scanForOres(event.player)
}
Expand Down
2 changes: 1 addition & 1 deletion target/maven-archiver/pom.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#Generated by Maven
#Sat Jul 22 19:34:00 ART 2023
#Sun Jul 23 03:56:07 ART 2023
groupId=code.blurone
artifactId=SnifferExploited
version=1.0-SNAPSHOT

0 comments on commit 37a58be

Please sign in to comment.