-
Notifications
You must be signed in to change notification settings - Fork 4
/Sit Command (For Tank) #35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Fishywishi
wants to merge
17
commits into
Warzone:master
Choose a base branch
from
Fishywishi:sit
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
ce1f3e4
UwuCommand
Fishywishi 4475756
Replace message color
Fishywishi fdee708
Basic Sit functionality
Fishywishi a3f17ee
More Sit Changes
Fishywishi a4720ad
Implement chair rotation
Mew2K 4de43bd
Merge pull request #1 from Mew2K/sit
Fishywishi 9d18597
Sit fixes and cleanup
Fishywishi 51fdae1
Fixed wrong detection when crouching on edge of most blocks
Fishywishi 0bf998e
Move uwu to own branch
Fishywishi 22e04b6
Refactoring and Bug Fixes
Fishywishi f8aa471
Final Refactoring
Fishywishi f00a6f4
Unnecessary change went through
Fishywishi e9687b4
Bug Fix and refactoring
Fishywishi 1bb5351
Unnecessary change
Fishywishi 1e68f5b
Refactoring
Fishywishi f8b9a0b
PR fix
Fishywishi 1c5e03e
PR Fix
Fishywishi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
102 changes: 102 additions & 0 deletions
102
src/main/kotlin/network/warzone/mars/player/controllers/SitController.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,102 @@ | ||
| package network.warzone.mars.player.controllers | ||
|
|
||
| import app.ashcon.intake.CommandException | ||
| import org.bukkit.Bukkit | ||
| import org.bukkit.ChatColor | ||
| import org.bukkit.Location | ||
| import org.bukkit.Material | ||
| import org.bukkit.block.Block | ||
| import org.bukkit.craftbukkit.v1_8_R3.entity.CraftEntity | ||
| import org.bukkit.entity.ArmorStand | ||
| import org.bukkit.entity.Entity | ||
| import org.bukkit.entity.EntityType | ||
| import org.bukkit.entity.Player | ||
| import java.util.* | ||
| import kotlin.math.floor | ||
|
|
||
| class SitController { | ||
| val sitting: HashMap<UUID?, Pair<ArmorStand?, Block?>> = HashMap() | ||
|
|
||
| fun sit(player: Player) { | ||
| if (isSitting(player)) { | ||
| return; | ||
| } | ||
| val block = getBlockBelow(player) | ||
| if(!validSeatLocation(player, block)) { | ||
| throw CommandException("You were unable to sit!") | ||
| } | ||
| val chair = createChair(player.location, player) | ||
| sitting.put(player.uniqueId, Pair(chair, block)) | ||
| player.sendActionBar("${ChatColor.GREEN}You are now sitting!") | ||
| } | ||
|
|
||
| fun isSitting(player: Player): Boolean { | ||
| return sitting.contains(player.uniqueId); | ||
| } | ||
|
|
||
| fun unSit(player: Player) { | ||
| if (player.vehicle is ArmorStand) { | ||
| unSit(player, player.vehicle as ArmorStand) | ||
| } | ||
| } | ||
|
|
||
| fun unSit(player: Player, seat: ArmorStand) { | ||
| if (!isSitting(player)) { | ||
| return; | ||
| } | ||
| player.sendActionBar("${ChatColor.DARK_RED}You are no longer sitting!") | ||
| sitting.remove(player.uniqueId) | ||
| seat.remove() | ||
| } | ||
|
|
||
| fun validSeatLocation(player: Player, block: Block?): Boolean { | ||
| return !(block?.type == Material.AIR || block == null || !player.isOnGround); | ||
| } | ||
|
|
||
| fun clearAllSeats() { | ||
| for ((uuid) in sitting) { | ||
| val player = Bukkit.getPlayer(uuid) ?: continue | ||
| unSit(player) | ||
| } | ||
| } | ||
|
|
||
| private fun createChair(loc: Location, player: Player): ArmorStand { | ||
| val world = loc.world | ||
| val chair = world.spawnEntity(loc.add(0.0, 0.05, 0.0), EntityType.ARMOR_STAND) as ArmorStand | ||
| chair.setGravity(false) | ||
| chair.isMarker = true | ||
| chair.isSmall = true | ||
| chair.passenger = player | ||
| chair.isVisible = false | ||
| return chair | ||
| } | ||
|
|
||
| fun getBlockBelow(entity: Entity): Block? { | ||
| val bb = (entity as CraftEntity).handle.boundingBox | ||
| val minX = floor(bb.a).toInt() | ||
| val maxX = floor(bb.d).toInt() | ||
| val minZ = floor(bb.c).toInt() | ||
| val maxZ = floor(bb.f).toInt() | ||
| val y = floor(bb.b - 0.02).toInt() | ||
| val world = entity.world | ||
| for (x in minX..maxX) { | ||
| for (z in minZ..maxZ) { | ||
| val block = world.getBlockAt(x, y, z) | ||
| if (block.type == Material.AIR) { | ||
| val belowBlock = world.getBlockAt(x,y - 1,z) | ||
| val type = belowBlock.type | ||
| if (type == Material.FENCE || | ||
| type == Material.NETHER_FENCE || | ||
| type == Material.COBBLE_WALL || | ||
| type == Material.STEP || | ||
| type == Material.FENCE_GATE) { | ||
| return belowBlock | ||
| } | ||
| } else { | ||
| return block | ||
| } | ||
| } | ||
| } | ||
| return null; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -252,4 +252,4 @@ class ChatListener : Listener { | |
| } | ||
| return component.hoverEvent(hoverComponent.build()) | ||
| } | ||
| } | ||
| } | ||
58 changes: 58 additions & 0 deletions
58
src/main/kotlin/network/warzone/mars/player/listeners/DismountListener.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| package network.warzone.mars.player.listeners | ||
|
|
||
| import network.warzone.mars.Mars | ||
| import network.warzone.mars.feature.ResourceType | ||
| import network.warzone.mars.player.controllers.SitController | ||
| import org.bukkit.Bukkit | ||
| import org.bukkit.Location | ||
| import org.bukkit.craftbukkit.v1_8_R3.entity.CraftArmorStand | ||
| import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer | ||
| import org.bukkit.entity.ArmorStand | ||
| import org.bukkit.entity.Player | ||
| import org.bukkit.event.EventHandler | ||
| import org.bukkit.event.Listener | ||
| import org.bukkit.event.block.BlockBreakEvent | ||
| import org.bukkit.event.entity.EntityDamageByEntityEvent | ||
| import org.bukkit.event.player.PlayerQuitEvent | ||
| import org.spigotmc.event.entity.EntityDismountEvent | ||
|
|
||
| class DismountListener : Listener { | ||
|
|
||
|
|
||
| val sitController = Mars.sitController | ||
| @EventHandler | ||
| fun onDismount(event: EntityDismountEvent) { | ||
| if (event.entity is Player && event.dismounted is ArmorStand && sitController.isSitting(event.entity as Player)) { | ||
| val player = (event.entity as CraftPlayer).handle | ||
| val armorStand = (event.dismounted as CraftArmorStand).handle | ||
| sitController.unSit(event.entity as CraftPlayer) | ||
| player.setPositionRotation(armorStand.locX, armorStand.locY,armorStand.locZ, player.yaw, player.pitch) | ||
| } | ||
| } | ||
|
|
||
| @EventHandler | ||
| fun onPlayerQuit(event: PlayerQuitEvent) { | ||
| if (sitController.isSitting(event.player)) { | ||
| sitController.unSit(event.player) | ||
| } | ||
| } | ||
|
|
||
| @EventHandler | ||
| fun onPlayerDamaged(event: EntityDamageByEntityEvent) { | ||
| if (event.entity !is Player) return | ||
| val player = event.entity as Player | ||
| sitController.unSit(player); | ||
| } | ||
|
|
||
| @EventHandler | ||
| fun onBlockBreak(event: BlockBreakEvent) { | ||
| val block = event.block | ||
| for ((uuid) in sitController.sitting) { | ||
| val player = Bukkit.getPlayer(uuid) | ||
| if (block == sitController.sitting.get(player.uniqueId)?.second) { | ||
| sitController.unSit(player) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| } | ||
31 changes: 31 additions & 0 deletions
31
src/main/kotlin/network/warzone/mars/player/listeners/tasks/ChairRotationTask.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| package network.warzone.mars.player.listeners.tasks | ||
|
|
||
| import network.warzone.mars.Mars | ||
| import network.warzone.mars.player.controllers.SitController | ||
| import org.bukkit.Bukkit | ||
| import org.bukkit.craftbukkit.v1_8_R3.entity.CraftArmorStand | ||
| import org.bukkit.scheduler.BukkitRunnable | ||
|
|
||
| class ChairRotationTask : BukkitRunnable() { | ||
|
|
||
| val sitController = Mars.sitController | ||
|
|
||
| override fun run() { | ||
| for ((uuid) in sitController.sitting) { | ||
| val player = Bukkit.getPlayer(uuid) ?: continue | ||
| val armorStand = sitController.sitting.get(uuid)?.first ?: continue | ||
| val entityArmorStand = (armorStand as CraftArmorStand).handle | ||
| entityArmorStand.setPositionRotation( | ||
| entityArmorStand.locX, | ||
| entityArmorStand.locY, | ||
| entityArmorStand.locZ, | ||
| player.location.yaw, | ||
| entityArmorStand.pitch | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| fun start() { | ||
| this.runTaskTimer(Mars.Companion.get(), 0L, 1L) | ||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR would break compatibility for modern server versions since you are directly using craftbukkit imports in some files.
Currently Mars does not have any utility functions for handling NMS/OBC imports so that would need to be implemented as well