From 40b186170b6552d10cc7b73b5bf6a7266d4d6329 Mon Sep 17 00:00:00 2001 From: disclearing <46827438+disclearing@users.noreply.github.com> Date: Tue, 6 Sep 2022 21:35:47 +0100 Subject: [PATCH] HCF --- Shitty HCF/.gitignore | 7 + Shitty HCF/build.gradle | 81 +++ Shitty HCF/gradle.properties | 10 + Shitty HCF/settings.gradle | 2 + Shitty HCF/src/main/kotlin/cc/fyre/hcf/HCF.kt | 191 +++++++ .../src/main/kotlin/cc/fyre/hcf/HCFModule.kt | 24 + .../kotlin/cc/fyre/hcf/ability/Ability.kt | 142 +++++ .../cc/fyre/hcf/ability/AbilityHandler.kt | 85 +++ .../cc/fyre/hcf/ability/AbilityModule.kt | 69 +++ .../hcf/ability/command/AbilityCommand.kt | 15 + .../ability/command/AbilityCooldownCommand.kt | 29 + .../hcf/ability/command/AbilityGiveCommand.kt | 37 ++ .../parameter/AbilityParameterProvider.kt | 34 ++ .../fyre/hcf/ability/event/AbilityUseEvent.kt | 43 ++ .../hcf/ability/listener/AbilityListener.kt | 124 +++++ .../cc/fyre/hcf/ability/menu/AbilityButton.kt | 54 ++ .../cc/fyre/hcf/ability/menu/AbilityMenu.kt | 21 + .../fyre/hcf/ability/pocketbard/PocketBard.kt | 49 ++ .../ability/pocketbard/PocketBardAbility.kt | 85 +++ .../ability/pocketbard/PocketBardButton.kt | 49 ++ .../hcf/ability/pocketbard/PocketBardMenu.kt | 38 ++ .../hcf/ability/pocketbard/PocketBardType.kt | 38 ++ .../cc/fyre/hcf/ability/type/AntiBuildBone.kt | 170 ++++++ .../cc/fyre/hcf/ability/type/AntiPearl.kt | 102 ++++ .../cc/fyre/hcf/ability/type/AntiTrap.kt | 84 +++ .../kotlin/cc/fyre/hcf/ability/type/Combo.kt | 122 +++++ .../cc/fyre/hcf/ability/type/EggPort.kt | 156 ++++++ .../cc/fyre/hcf/ability/type/FocusMode.kt | 102 ++++ .../cc/fyre/hcf/ability/type/Grapple.kt | 121 +++++ .../cc/fyre/hcf/ability/type/NinjaStar.kt | 148 +++++ .../kotlin/cc/fyre/hcf/ability/type/Rocket.kt | 98 ++++ .../cc/fyre/hcf/ability/type/TimeWarp.kt | 132 +++++ .../ability/type/invisibility/Invisibility.kt | 143 +++++ .../type/invisibility/InvisibilityListener.kt | 36 ++ .../cc/fyre/hcf/combatlogger/CombatLogger.kt | 100 ++++ .../hcf/combatlogger/CombatLoggerHandler.kt | 79 +++ .../hcf/combatlogger/CombatLoggerModule.kt | 34 ++ .../fyre/hcf/combatlogger/kb/ZeroKBProfile.kt | 74 +++ .../listener/CombatLoggerListener.kt | 206 +++++++ .../scheduler/CombatLoggerScheduler.kt | 47 ++ .../main/kotlin/cc/fyre/hcf/death/Death.kt | 78 +++ .../kotlin/cc/fyre/hcf/death/DeathHandler.kt | 82 +++ .../kotlin/cc/fyre/hcf/death/DeathModule.kt | 41 ++ .../cc/fyre/hcf/death/DeathRepository.kt | 91 ++++ .../cc/fyre/hcf/death/DeathStatistic.kt | 75 +++ .../fyre/hcf/death/command/DeathsCommand.kt | 25 + .../cc/fyre/hcf/death/command/KillsCommand.kt | 25 + .../fyre/hcf/death/command/LastInvCommand.kt | 40 ++ .../fyre/hcf/death/command/ReviveCommand.kt | 70 +++ .../fyre/hcf/death/listener/DeathListener.kt | 129 +++++ .../hcf/death/listener/DeathPacketListener.kt | 42 ++ .../cc/fyre/hcf/death/loadout/DeathLoadout.kt | 18 + .../cc/fyre/hcf/death/menu/DeathsMenu.kt | 35 ++ .../fyre/hcf/death/menu/DeathsRefundMenu.kt | 43 ++ .../hcf/death/menu/element/DeathElement.kt | 82 +++ .../death/menu/element/DeathRefundElement.kt | 56 ++ .../death/menu/element/DeathReviveElement.kt | 57 ++ .../kotlin/cc/fyre/hcf/deathmessage/Damage.kt | 32 ++ .../hcf/deathmessage/DeathMessageHandler.kt | 59 ++ .../hcf/deathmessage/DeathMessageModule.kt | 39 ++ .../deathmessage/event/PlayerDamageEvent.kt | 29 + .../listener/DeathMessageListener.kt | 104 ++++ .../hcf/deathmessage/tracker/ArrowTracker.kt | 63 +++ .../hcf/deathmessage/tracker/BurnTracker.kt | 57 ++ .../hcf/deathmessage/tracker/EntityTracker.kt | 36 ++ .../hcf/deathmessage/tracker/FallTracker.kt | 61 +++ .../deathmessage/tracker/GeneralTracker.kt | 34 ++ .../hcf/deathmessage/tracker/PvPTracker.kt | 35 ++ .../hcf/deathmessage/tracker/VoidTracker.kt | 58 ++ .../fyre/hcf/deathmessage/type/ArrowDamage.kt | 13 + .../fyre/hcf/deathmessage/type/BurnDamage.kt | 12 + .../fyre/hcf/deathmessage/type/FallDamage.kt | 13 + .../hcf/deathmessage/type/GeneralDamage.kt | 13 + .../fyre/hcf/deathmessage/type/MobDamage.kt | 7 + .../hcf/deathmessage/type/PlayerDamage.kt | 6 + .../hcf/deathmessage/type/UnknownDamage.kt | 13 + .../fyre/hcf/deathmessage/type/VoidDamage.kt | 13 + .../deathmessage/type/mob/ArrowDamageByMob.kt | 15 + .../hcf/deathmessage/type/mob/EntityDamage.kt | 16 + .../type/player/ArrowDamageByPlayer.kt | 18 + .../type/player/BackStabDamageByPlayer.kt | 14 + .../type/player/BurnDamageByPlayer.kt | 13 + .../type/player/FallDamageByPlayer.kt | 13 + .../hcf/deathmessage/type/player/PvPDamage.kt | 20 + .../type/player/VoidDamageByPlayer.kt | 14 + .../kotlin/cc/fyre/hcf/faction/Faction.kt | 110 ++++ .../cc/fyre/hcf/faction/FactionHandler.kt | 186 +++++++ .../cc/fyre/hcf/faction/FactionMember.kt | 22 + .../cc/fyre/hcf/faction/FactionMetadata.kt | 33 ++ .../cc/fyre/hcf/faction/FactionModule.kt | 134 +++++ .../cc/fyre/hcf/faction/FactionRepository.kt | 83 +++ .../kotlin/cc/fyre/hcf/faction/FactionType.kt | 10 + .../kotlin/cc/fyre/hcf/faction/claim/Claim.kt | 207 +++++++ .../cc/fyre/hcf/faction/claim/ClaimHandler.kt | 228 ++++++++ .../fyre/hcf/faction/claim/ClaimSelection.kt | 108 ++++ .../faction/claim/coordinate/Coordinate.kt | 9 + .../faction/claim/coordinate/CoordinateSet.kt | 31 ++ .../faction/claim/listener/ClaimListener.kt | 16 + .../claim/listener/ClaimPositionListener.kt | 237 ++++++++ .../faction/command/FactionAcceptCommand.kt | 67 +++ .../command/FactionAnnouncementCommand.kt | 50 ++ .../hcf/faction/command/FactionChatCommand.kt | 61 +++ .../faction/command/FactionCreateCommand.kt | 66 +++ .../faction/command/FactionDepositCommand.kt | 51 ++ .../faction/command/FactionFilterCommand.kt | 17 + .../faction/command/FactionFocusCommand.kt | 62 +++ .../hcf/faction/command/FactionHQCommand.kt | 73 +++ .../hcf/faction/command/FactionHelpCommand.kt | 60 +++ .../hcf/faction/command/FactionInfoCommand.kt | 23 + .../faction/command/FactionLeaveCommand.kt | 52 ++ .../hcf/faction/command/FactionListCommand.kt | 61 +++ .../faction/command/FactionLocationCommand.kt | 42 ++ .../command/FactionLocationHomeCommand.kt | 41 ++ .../hcf/faction/command/FactionMapCommand.kt | 82 +++ .../faction/command/FactionRallyCommand.kt | 42 ++ .../faction/command/FactionRegenCommand.kt | 48 ++ .../faction/command/FactionStuckCommand.kt | 44 ++ .../hcf/faction/command/FactionTopCommand.kt | 60 +++ .../command/admin/FactionBalanceAddCommand.kt | 34 ++ .../admin/FactionBalanceRemoveCommand.kt | 33 ++ .../command/admin/FactionBanCommand.kt | 94 ++++ .../command/admin/FactionBlacklistCommand.kt | 95 ++++ .../command/admin/FactionChatSpyAddCommand.kt | 36 ++ .../admin/FactionChatSpyRemoveCommand.kt | 36 ++ .../command/admin/FactionDisbandAllCommand.kt | 81 +++ .../command/admin/FactionEditorCommand.kt | 32 ++ .../admin/FactionForceDisbandCommand.kt | 34 ++ .../command/admin/FactionForceSetHQCommand.kt | 30 ++ .../command/admin/FactionMuteCommand.kt | 34 ++ .../command/admin/FactionPointsAddCommand.kt | 34 ++ .../admin/FactionPointsRemoveCommand.kt | 32 ++ .../command/admin/FactionSetDTRCommand.kt | 27 + .../admin/FactionSetDTRRegenCommand.kt | 27 + .../command/admin/FactionTeleportCommand.kt | 33 ++ .../command/captain/FactionAllyCommand.kt | 103 ++++ .../command/captain/FactionClaimCommand.kt | 57 ++ .../command/captain/FactionInviteCommand.kt | 72 +++ .../captain/FactionInviteRevokeCommand.kt | 69 +++ .../command/captain/FactionKickCommand.kt | 57 ++ .../command/captain/FactionSetHQCommand.kt | 42 ++ .../command/captain/FactionWithdrawCommand.kt | 55 ++ .../command/coleader/FactionDemoteCommand.kt | 67 +++ .../command/coleader/FactionPromoteCommand.kt | 57 ++ .../command/coleader/FactionRenameCommand.kt | 62 +++ .../command/coleader/FactionUnAllyCommand.kt | 51 ++ .../command/coleader/FactionUnClaimCommand.kt | 84 +++ .../command/leader/FactionDisbandCommand.kt | 47 ++ .../command/leader/FactionLeaderCommand.kt | 50 ++ .../parameter/FactionParameterProvider.kt | 50 ++ .../parameter/GameFactionParameterProvider.kt | 41 ++ .../MountainFactionParameterProvider.kt | 41 ++ .../PlayerFactionParameterProvider.kt | 33 ++ .../SystemFactionParameterProvider.kt | 42 ++ .../hcf/faction/event/FactionAllyEvent.kt | 23 + .../hcf/faction/event/FactionClaimEvent.kt | 25 + .../hcf/faction/event/FactionCreateEvent.kt | 23 + .../faction/event/FactionDTRUpdateEvent.kt | 23 + .../hcf/faction/event/FactionDisbandEvent.kt | 22 + .../hcf/faction/event/FactionFocusEvent.kt | 35 ++ .../hcf/faction/event/FactionHQUpdateEvent.kt | 24 + .../faction/event/FactionMemberAddEvent.kt | 24 + .../faction/event/FactionMemberDeathEvent.kt | 24 + .../faction/event/FactionMemberRemoveEvent.kt | 31 ++ .../hcf/faction/event/FactionMoveEvent.kt | 35 ++ .../hcf/faction/event/FactionUnAllyEvent.kt | 23 + .../hcf/faction/event/FactionUnFocusEvent.kt | 35 ++ .../cc/fyre/hcf/faction/list/FactionList.kt | 62 +++ .../fyre/hcf/faction/list/FactionListType.kt | 46 ++ .../faction/listener/FactionChatListener.kt | 104 ++++ .../faction/listener/FactionClaimListener.kt | 85 +++ .../faction/listener/FactionDeathListener.kt | 68 +++ .../faction/listener/FactionFocusListener.kt | 31 ++ .../faction/listener/FactionMapListener.kt | 51 ++ .../faction/listener/FactionMemberListener.kt | 108 ++++ .../listener/FactionMetadataListener.kt | 168 ++++++ .../faction/listener/FactionMoveListener.kt | 98 ++++ .../faction/listener/FactionPistonListener.kt | 66 +++ .../listener/FactionProtectionListener.kt | 345 ++++++++++++ .../faction/listener/FactionRallyListener.kt | 59 ++ .../faction/listener/FactionStaffListener.kt | 32 ++ .../listener/FactionSubclaimListener.kt | 242 +++++++++ .../listener/FactionWayPointListener.kt | 135 +++++ .../faction/menu/faction/FactionFilterMenu.kt | 40 ++ .../faction/button/FactionFilterButton.kt | 57 ++ .../faction/button/FactionFilterTypeButton.kt | 64 +++ .../hcf/faction/menu/system/SystemEditMenu.kt | 50 ++ .../faction/menu/system/SystemEditorMenu.kt | 35 ++ .../menu/system/button/SystemButton.kt | 101 ++++ .../menu/system/button/SystemClaimButton.kt | 73 +++ .../menu/system/button/SystemCreateButton.kt | 25 + .../system/button/SystemDisplayNameButton.kt | 32 ++ .../system/button/SystemMetadataButton.kt | 91 ++++ .../hcf/faction/prompt/FactionCreatePrompt.kt | 51 ++ .../faction/prompt/FactionDisplayPrompt.kt | 26 + .../hcf/faction/service/TeamViewerService.kt | 46 ++ .../cc/fyre/hcf/faction/type/PlayerFaction.kt | 507 ++++++++++++++++++ .../cc/fyre/hcf/faction/type/SystemFaction.kt | 133 +++++ .../faction/type/defaults/TheEndFaction.kt | 19 + .../faction/type/defaults/TheNetherFaction.kt | 19 + .../faction/type/defaults/WarZoneFaction.kt | 51 ++ .../type/defaults/WildernessFaction.kt | 29 + .../fyre/hcf/faction/type/player/ChatMode.kt | 96 ++++ .../hcf/faction/type/player/FactionRole.kt | 69 +++ .../hcf/faction/type/player/RegenState.kt | 12 + .../hcf/faction/type/subclaim/Subclaim.kt | 35 ++ .../kotlin/cc/fyre/hcf/game/GameFaction.kt | 141 +++++ .../kotlin/cc/fyre/hcf/game/GameHandler.kt | 163 ++++++ .../kotlin/cc/fyre/hcf/game/GameModule.kt | 59 ++ .../main/kotlin/cc/fyre/hcf/game/GameType.kt | 13 + .../cc/fyre/hcf/game/capture/CaptureZone.kt | 134 +++++ .../hcf/game/capture/CaptureZoneFaction.kt | 24 + .../hcf/game/capture/type/CitadelFaction.kt | 165 ++++++ .../hcf/game/capture/type/ConquestFaction.kt | 227 ++++++++ .../fyre/hcf/game/capture/type/FuryFaction.kt | 256 +++++++++ .../fyre/hcf/game/capture/type/KOTHFaction.kt | 166 ++++++ .../game/capture/zone/ConquestCaptureZone.kt | 19 + .../hcf/game/capture/zone/ConquestZoneType.kt | 20 + .../hcf/game/capture/zone/FuryCaptureZone.kt | 20 + .../hcf/game/capture/zone/FuryZoneType.kt | 22 + .../hcf/game/command/GameActivateCommand.kt | 31 ++ .../hcf/game/command/GameCreateCommand.kt | 54 ++ .../hcf/game/command/GameGiveKeyCommand.kt | 35 ++ .../hcf/game/command/GameTerminateCommand.kt | 35 ++ .../game/command/citadel/CitadelCommand.kt | 26 + .../command/citadel/CitadelRespawnCommand.kt | 32 ++ .../command/citadel/CitadelScanCommand.kt | 32 ++ .../citadel/CitadelSetCapperCommand.kt | 48 ++ .../game/command/conquest/ConquestCommand.kt | 54 ++ .../conquest/ConquestSetPointsCommand.kt | 37 ++ .../conquest/ConquestSetRadiusCommand.kt | 39 ++ .../conquest/ConquestSetZoneCommand.kt | 34 ++ .../game/command/dtc/DTCSetAmountCommand.kt | 32 ++ .../command/dtc/DTCSetObjectiveCommand.kt | 40 ++ .../fyre/hcf/game/command/fury/FuryCommand.kt | 55 ++ .../game/command/fury/FurySetPointsCommand.kt | 38 ++ .../game/command/fury/FurySetZoneCommand.kt | 35 ++ .../ConquestZoneTypeParameterProvider.kt | 32 ++ .../FuryZoneTypeParameterProvider.kt | 32 ++ .../parameter/GameTypeParameterProvider.kt | 32 ++ .../fyre/hcf/game/event/GameActivateEvent.kt | 34 ++ .../fyre/hcf/game/event/GameCaptureEvent.kt | 25 + .../fyre/hcf/game/event/GameTerminateEvent.kt | 23 + .../hcf/game/listener/CaptureZoneListener.kt | 198 +++++++ .../fyre/hcf/game/listener/CitadelListener.kt | 25 + .../hcf/game/listener/ConquestListener.kt | 32 ++ .../cc/fyre/hcf/game/listener/DTCListener.kt | 42 ++ .../cc/fyre/hcf/game/listener/FuryListener.kt | 32 ++ .../cc/fyre/hcf/game/listener/GameListener.kt | 168 ++++++ .../hcf/game/listener/GameRewardListener.kt | 167 ++++++ .../cc/fyre/hcf/game/menu/GameLootMenu.kt | 25 + .../cc/fyre/hcf/game/other/DTCFaction.kt | 166 ++++++ .../cc/fyre/hcf/game/schedule/GameSchedule.kt | 56 ++ .../hcf/game/schedule/command/GameCommand.kt | 51 ++ .../schedule/command/GameScheduleCommand.kt | 53 ++ .../command/GameScheduleGenerateCommand.kt | 71 +++ .../fyre/hcf/game/scheduler/GameScheduler.kt | 49 ++ .../main/kotlin/cc/fyre/hcf/map/MapConfig.kt | 48 ++ .../main/kotlin/cc/fyre/hcf/map/MapHandler.kt | 122 +++++ .../main/kotlin/cc/fyre/hcf/map/MapModule.kt | 69 +++ .../cc/fyre/hcf/map/border/BorderHandler.kt | 24 + .../hcf/map/border/command/BorderCommand.kt | 25 + .../hcf/map/border/listener/BorderListener.kt | 119 ++++ .../cc/fyre/hcf/map/command/EndExitCommand.kt | 27 + .../cc/fyre/hcf/map/command/MapKitCommand.kt | 24 + .../cc/fyre/hcf/map/command/OresCommand.kt | 33 ++ .../cc/fyre/hcf/map/command/ShopCommand.kt | 27 + .../cc/fyre/hcf/map/command/SpawnCommand.kt | 54 ++ .../fyre/hcf/map/command/ToggleEndCommand.kt | 23 + .../cc/fyre/hcf/map/crowbar/CrowbarHandler.kt | 64 +++ .../fyre/hcf/map/crowbar/CrowbarListener.kt | 169 ++++++ .../hcf/map/crowbar/command/CrowbarCommand.kt | 28 + .../fyre/hcf/map/engine/HCFNameTagAdapter.kt | 62 +++ .../hcf/map/engine/HCFScoreboardAdapter.kt | 167 ++++++ .../cc/fyre/hcf/map/engine/HCFTabAdapter.kt | 207 +++++++ .../cc/fyre/hcf/map/eotw/EOTWHandler.kt | 30 ++ .../map/eotw/command/EOTWDeathbansCommand.kt | 49 ++ .../hcf/map/eotw/command/EOTWFFACommand.kt | 87 +++ .../hcf/map/eotw/command/EOTWStartCommand.kt | 47 ++ .../map/eotw/command/EOTWTeleportCommand.kt | 36 ++ .../map/eotw/command/EOTWUnclaimCommand.kt | 68 +++ .../hcf/map/eotw/listener/EOTWListener.kt | 39 ++ .../cc/fyre/hcf/map/listener/BookListener.kt | 34 ++ .../fyre/hcf/map/listener/DiamondListener.kt | 96 ++++ .../cc/fyre/hcf/map/listener/EXPListener.kt | 113 ++++ .../cc/fyre/hcf/map/listener/EndListener.kt | 94 ++++ .../fyre/hcf/map/listener/GeneralListener.kt | 86 +++ .../fyre/hcf/map/listener/GlitchListener.kt | 142 +++++ .../hcf/map/listener/InventoryListener.kt | 45 ++ .../cc/fyre/hcf/map/listener/MobListener.kt | 78 +++ .../fyre/hcf/map/listener/NameTagListener.kt | 152 ++++++ .../fyre/hcf/map/listener/NetherListener.kt | 88 +++ .../cc/fyre/hcf/map/listener/PearlListener.kt | 119 ++++ .../fyre/hcf/map/listener/PickaxeListener.kt | 36 ++ .../fyre/hcf/map/listener/PotionListener.kt | 102 ++++ .../hcf/map/listener/PreventionListener.kt | 87 +++ .../fyre/hcf/map/listener/RedstoneListener.kt | 68 +++ .../fyre/hcf/map/listener/StatTrakListener.kt | 15 + .../hcf/map/service/RankBroadcastService.kt | 45 ++ .../kotlin/cc/fyre/hcf/map/shop/ShopMenu.kt | 65 +++ .../fyre/hcf/map/shop/block/BlockCategory.kt | 132 +++++ .../hcf/map/shop/block/BlockCategoryButton.kt | 24 + .../hcf/map/shop/block/BlockCategoryMenu.kt | 34 ++ .../cc/fyre/hcf/map/shop/block/BlockMenu.kt | 34 ++ .../cc/fyre/hcf/map/shop/buy/BuyButton.kt | 43 ++ .../cc/fyre/hcf/map/shop/buy/BuyMenu.kt | 65 +++ .../cc/fyre/hcf/map/shop/sell/SellButton.kt | 70 +++ .../cc/fyre/hcf/map/shop/sell/SellMenu.kt | 46 ++ .../cc/fyre/hcf/map/sotw/SOTWHandler.kt | 64 +++ .../hcf/map/sotw/command/SOTWCancelCommand.kt | 27 + .../hcf/map/sotw/command/SOTWEnableCommand.kt | 50 ++ .../hcf/map/sotw/command/SOTWPauseCommand.kt | 22 + .../hcf/map/sotw/command/SOTWStartCommand.kt | 29 + .../fyre/hcf/map/sotw/event/SOTWEndEvent.kt | 22 + .../fyre/hcf/map/sotw/event/SOTWStartEvent.kt | 22 + .../hcf/map/sotw/listener/SOTWListener.kt | 90 ++++ .../hcf/map/sotw/scheduler/SOTWScheduler.kt | 17 + .../cc/fyre/hcf/mountain/MountainFaction.kt | 153 ++++++ .../cc/fyre/hcf/mountain/MountainHandler.kt | 21 + .../cc/fyre/hcf/mountain/MountainModule.kt | 48 ++ .../cc/fyre/hcf/mountain/MountainType.kt | 10 + .../mountain/command/MountainCreateCommand.kt | 48 ++ .../mountain/command/MountainRefillCommand.kt | 24 + .../mountain/command/MountainScanCommand.kt | 27 + .../hcf/mountain/command/cave/CaveCommand.kt | 31 ++ .../command/glowstone/GlowstoneCommand.kt | 30 ++ .../MountainTypeParameterProvider.kt | 33 ++ .../hcf/mountain/listener/MountainListener.kt | 40 ++ .../service/MountainRefillScheduler.kt | 18 + .../cc/fyre/hcf/mountain/type/CaveMountain.kt | 14 + .../hcf/mountain/type/GlowstoneMountain.kt | 13 + .../main/kotlin/cc/fyre/hcf/pillar/Pillar.kt | 16 + .../cc/fyre/hcf/pillar/PillarHandler.kt | 157 ++++++ .../kotlin/cc/fyre/hcf/pillar/PillarModule.kt | 44 ++ .../kotlin/cc/fyre/hcf/pillar/PillarType.kt | 18 + .../hcf/pillar/listener/PillarListener.kt | 28 + .../pillar/listener/PillarPacketListener.kt | 73 +++ .../cc/fyre/hcf/pillar/wall/PillarWall.kt | 29 + .../hcf/pillar/wall/PillarWallRegistry.kt | 15 + .../fyre/hcf/pillar/wall/PillarWallThread.kt | 151 ++++++ .../hcf/pillar/wall/type/GamePillarWall.kt | 33 ++ .../pillar/wall/type/PvPTimerPillarWall.kt | 31 ++ .../pillar/wall/type/SpawnTagPillarWall.kt | 33 ++ .../kotlin/cc/fyre/hcf/pvpclass/PvPClass.kt | 86 +++ .../cc/fyre/hcf/pvpclass/PvPClassHandler.kt | 121 +++++ .../cc/fyre/hcf/pvpclass/PvPClassModule.kt | 56 ++ .../cc/fyre/hcf/pvpclass/PvPClassType.kt | 10 + .../fyre/hcf/pvpclass/energy/EnergyEffect.kt | 24 + .../hcf/pvpclass/event/PvPClassEquipEvent.kt | 35 ++ .../pvpclass/event/PvPClassUnEquipEvent.kt | 25 + .../pvpclass/event/type/ArcherMarkEvent.kt | 24 + .../hcf/pvpclass/event/type/BackstabEvent.kt | 24 + .../pvpclass/event/type/BardEffectEvent.kt | 25 + .../fyre/hcf/pvpclass/item/ConsumableItem.kt | 16 + .../item/type/EffectConsumableItem.kt | 16 + .../hcf/pvpclass/listener/PvPClassListener.kt | 192 +++++++ .../scheduler/PvPClassEnergyScheduler.kt | 37 ++ .../cc/fyre/hcf/pvpclass/type/ArcherClass.kt | 215 ++++++++ .../cc/fyre/hcf/pvpclass/type/MinerClass.kt | 189 +++++++ .../cc/fyre/hcf/pvpclass/type/RogueClass.kt | 125 +++++ .../fyre/hcf/pvpclass/type/bard/BardClass.kt | 218 ++++++++ .../type/bard/effect/BardEnergyEffect.kt | 32 ++ .../bard/scheduler/BardEffectScheduler.kt | 47 ++ .../kotlin/cc/fyre/hcf/statistic/Statistic.kt | 41 ++ .../cc/fyre/hcf/statistic/StatisticHandler.kt | 135 +++++ .../cc/fyre/hcf/statistic/StatisticModule.kt | 84 +++ .../cc/fyre/hcf/statistic/StatisticOption.kt | 6 + .../fyre/hcf/statistic/StatisticRegistry.kt | 25 + .../fyre/hcf/statistic/StatisticRepository.kt | 81 +++ .../cc/fyre/hcf/statistic/StatisticValue.kt | 29 + .../hcf/statistic/command/BalanceCommand.kt | 38 ++ .../hcf/statistic/command/CobbleCommand.kt | 25 + .../statistic/command/DeathMessagesCommand.kt | 26 + .../statistic/command/FoundDiamondsCommand.kt | 28 + .../hcf/statistic/command/LivesCommand.kt | 35 ++ .../fyre/hcf/statistic/command/PayCommand.kt | 60 +++ .../hcf/statistic/command/PlayTimeCommand.kt | 30 ++ .../hcf/statistic/command/ReclaimCommand.kt | 56 ++ .../statistic/command/ReclaimResetCommand.kt | 36 ++ .../hcf/statistic/command/SettingCommand.kt | 21 + .../parameter/StatisticParameterProvider.kt | 35 ++ .../cc/fyre/hcf/statistic/impl/TabOption.kt | 61 +++ .../statistic/leaderboard/LeaderboardEntry.kt | 19 + .../statistic/leaderboard/LeaderboardNPC.kt | 176 ++++++ .../leaderboard/LeaderboardUpdateTask.kt | 35 ++ .../leaderboard/command/LeaderboardCommand.kt | 60 +++ .../command/LeaderboardNPCCommand.kt | 30 ++ .../statistic/listener/StatisticListener.kt | 67 +++ .../fyre/hcf/statistic/menu/SettingButton.kt | 76 +++ .../cc/fyre/hcf/statistic/menu/SettingMenu.kt | 41 ++ .../serializer/StatisticJsonAdapter.kt | 22 + .../serializer/StatisticSerializer.kt | 8 + .../hcf/statistic/type/BalanceStatistic.kt | 5 + .../hcf/statistic/type/DeathsStatistic.kt | 5 + .../hcf/statistic/type/HighestKillStreak.kt | 5 + .../hcf/statistic/type/KillStreakStatistic.kt | 5 + .../fyre/hcf/statistic/type/KillsStatistic.kt | 5 + .../fyre/hcf/statistic/type/LivesStatistic.kt | 5 + .../hcf/statistic/type/PlayTimeStatistic.kt | 36 ++ .../type/defaults/BooleanStatistic.kt | 71 +++ .../statistic/type/defaults/IntStatistic.kt | 63 +++ .../statistic/type/ores/CoalMinedStatistic.kt | 5 + .../type/ores/DiamondMinedStatistic.kt | 5 + .../type/ores/EmeraldMinedStatistic.kt | 5 + .../statistic/type/ores/GoldMinedStatistic.kt | 5 + .../statistic/type/ores/IronMinedStatistic.kt | 5 + .../type/ores/LapisMinedStatistic.kt | 5 + .../type/ores/RedstoneMinedStatistic.kt | 5 + .../type/setting/AbilityCooldownSetting.kt | 12 + .../statistic/type/setting/CobbleSetting.kt | 5 + .../type/setting/CustomTimersSetting.kt | 5 + .../type/setting/DeathMessageSetting.kt | 12 + .../type/setting/EventMessageSetting.kt | 12 + .../type/setting/FactionFilterSetting.kt | 62 +++ .../type/setting/FactionFocusSetting.kt | 12 + .../type/setting/FoundDiamondSetting.kt | 12 + .../hcf/statistic/type/setting/MapSetting.kt | 5 + .../statistic/type/setting/ReclaimSetting.kt | 5 + .../type/setting/SOTWProtectionSetting.kt | 5 + .../statistic/type/setting/TabListSetting.kt | 66 +++ .../main/kotlin/cc/fyre/hcf/timer/Timer.kt | 101 ++++ .../kotlin/cc/fyre/hcf/timer/TimerHandler.kt | 109 ++++ .../kotlin/cc/fyre/hcf/timer/TimerModule.kt | 71 +++ .../cc/fyre/hcf/timer/TimerRepository.kt | 104 ++++ .../kotlin/cc/fyre/hcf/timer/TimerType.kt | 43 ++ .../fyre/hcf/timer/command/TimerAddCommand.kt | 47 ++ .../hcf/timer/command/TimerRemoveCommand.kt | 45 ++ .../parameter/TimerParameterProvider.kt | 34 ++ .../command/pvptimer/PvPEnableCommand.kt | 44 ++ .../timer/command/pvptimer/PvPTimeCommand.kt | 47 ++ .../hcf/timer/command/type/GoppleCommand.kt | 33 ++ .../hcf/timer/command/type/LogoutCommand.kt | 39 ++ .../fyre/hcf/timer/event/TimerCreateEvent.kt | 44 ++ .../fyre/hcf/timer/event/TimerExpireEvent.kt | 27 + .../fyre/hcf/timer/event/TimerExtendEvent.kt | 26 + .../fyre/hcf/timer/event/TimerRemoveEvent.kt | 26 + .../fyre/hcf/timer/listener/AppleListener.kt | 44 ++ .../hcf/timer/listener/ArcherMarkListener.kt | 53 ++ .../hcf/timer/listener/EnderpearlListener.kt | 91 ++++ .../fyre/hcf/timer/listener/GappleListener.kt | 58 ++ .../fyre/hcf/timer/listener/HomeListener.kt | 140 +++++ .../fyre/hcf/timer/listener/LogoutListener.kt | 105 ++++ .../hcf/timer/listener/PvPTimerListener.kt | 244 +++++++++ .../hcf/timer/listener/SpawnTagListener.kt | 125 +++++ .../fyre/hcf/timer/listener/StuckListener.kt | 172 ++++++ .../fyre/hcf/timer/listener/TimerListener.kt | 113 ++++ Shitty HCF/src/main/resources/plugin.yml | 4 + 446 files changed, 26667 insertions(+) create mode 100644 Shitty HCF/.gitignore create mode 100644 Shitty HCF/build.gradle create mode 100644 Shitty HCF/gradle.properties create mode 100644 Shitty HCF/settings.gradle create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/HCF.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/HCFModule.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/ability/Ability.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/ability/AbilityHandler.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/ability/AbilityModule.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/ability/command/AbilityCommand.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/ability/command/AbilityCooldownCommand.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/ability/command/AbilityGiveCommand.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/ability/command/parameter/AbilityParameterProvider.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/ability/event/AbilityUseEvent.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/ability/listener/AbilityListener.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/ability/menu/AbilityButton.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/ability/menu/AbilityMenu.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/ability/pocketbard/PocketBard.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/ability/pocketbard/PocketBardAbility.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/ability/pocketbard/PocketBardButton.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/ability/pocketbard/PocketBardMenu.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/ability/pocketbard/PocketBardType.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/ability/type/AntiBuildBone.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/ability/type/AntiPearl.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/ability/type/AntiTrap.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/ability/type/Combo.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/ability/type/EggPort.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/ability/type/FocusMode.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/ability/type/Grapple.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/ability/type/NinjaStar.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/ability/type/Rocket.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/ability/type/TimeWarp.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/ability/type/invisibility/Invisibility.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/ability/type/invisibility/InvisibilityListener.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/combatlogger/CombatLogger.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/combatlogger/CombatLoggerHandler.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/combatlogger/CombatLoggerModule.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/combatlogger/kb/ZeroKBProfile.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/combatlogger/listener/CombatLoggerListener.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/combatlogger/scheduler/CombatLoggerScheduler.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/death/Death.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/death/DeathHandler.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/death/DeathModule.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/death/DeathRepository.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/death/DeathStatistic.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/death/command/DeathsCommand.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/death/command/KillsCommand.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/death/command/LastInvCommand.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/death/command/ReviveCommand.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/death/listener/DeathListener.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/death/listener/DeathPacketListener.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/death/loadout/DeathLoadout.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/death/menu/DeathsMenu.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/death/menu/DeathsRefundMenu.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/death/menu/element/DeathElement.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/death/menu/element/DeathRefundElement.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/death/menu/element/DeathReviveElement.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/deathmessage/Damage.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/deathmessage/DeathMessageHandler.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/deathmessage/DeathMessageModule.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/deathmessage/event/PlayerDamageEvent.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/deathmessage/listener/DeathMessageListener.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/deathmessage/tracker/ArrowTracker.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/deathmessage/tracker/BurnTracker.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/deathmessage/tracker/EntityTracker.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/deathmessage/tracker/FallTracker.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/deathmessage/tracker/GeneralTracker.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/deathmessage/tracker/PvPTracker.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/deathmessage/tracker/VoidTracker.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/deathmessage/type/ArrowDamage.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/deathmessage/type/BurnDamage.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/deathmessage/type/FallDamage.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/deathmessage/type/GeneralDamage.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/deathmessage/type/MobDamage.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/deathmessage/type/PlayerDamage.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/deathmessage/type/UnknownDamage.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/deathmessage/type/VoidDamage.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/deathmessage/type/mob/ArrowDamageByMob.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/deathmessage/type/mob/EntityDamage.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/deathmessage/type/player/ArrowDamageByPlayer.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/deathmessage/type/player/BackStabDamageByPlayer.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/deathmessage/type/player/BurnDamageByPlayer.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/deathmessage/type/player/FallDamageByPlayer.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/deathmessage/type/player/PvPDamage.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/deathmessage/type/player/VoidDamageByPlayer.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/Faction.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/FactionHandler.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/FactionMember.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/FactionMetadata.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/FactionModule.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/FactionRepository.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/FactionType.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/claim/Claim.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/claim/ClaimHandler.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/claim/ClaimSelection.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/claim/coordinate/Coordinate.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/claim/coordinate/CoordinateSet.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/claim/listener/ClaimListener.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/claim/listener/ClaimPositionListener.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/FactionAcceptCommand.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/FactionAnnouncementCommand.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/FactionChatCommand.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/FactionCreateCommand.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/FactionDepositCommand.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/FactionFilterCommand.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/FactionFocusCommand.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/FactionHQCommand.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/FactionHelpCommand.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/FactionInfoCommand.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/FactionLeaveCommand.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/FactionListCommand.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/FactionLocationCommand.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/FactionLocationHomeCommand.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/FactionMapCommand.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/FactionRallyCommand.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/FactionRegenCommand.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/FactionStuckCommand.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/FactionTopCommand.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/admin/FactionBalanceAddCommand.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/admin/FactionBalanceRemoveCommand.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/admin/FactionBanCommand.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/admin/FactionBlacklistCommand.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/admin/FactionChatSpyAddCommand.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/admin/FactionChatSpyRemoveCommand.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/admin/FactionDisbandAllCommand.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/admin/FactionEditorCommand.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/admin/FactionForceDisbandCommand.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/admin/FactionForceSetHQCommand.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/admin/FactionMuteCommand.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/admin/FactionPointsAddCommand.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/admin/FactionPointsRemoveCommand.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/admin/FactionSetDTRCommand.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/admin/FactionSetDTRRegenCommand.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/admin/FactionTeleportCommand.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/captain/FactionAllyCommand.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/captain/FactionClaimCommand.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/captain/FactionInviteCommand.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/captain/FactionInviteRevokeCommand.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/captain/FactionKickCommand.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/captain/FactionSetHQCommand.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/captain/FactionWithdrawCommand.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/coleader/FactionDemoteCommand.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/coleader/FactionPromoteCommand.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/coleader/FactionRenameCommand.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/coleader/FactionUnAllyCommand.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/coleader/FactionUnClaimCommand.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/leader/FactionDisbandCommand.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/leader/FactionLeaderCommand.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/parameter/FactionParameterProvider.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/parameter/GameFactionParameterProvider.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/parameter/MountainFactionParameterProvider.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/parameter/PlayerFactionParameterProvider.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/parameter/SystemFactionParameterProvider.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/event/FactionAllyEvent.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/event/FactionClaimEvent.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/event/FactionCreateEvent.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/event/FactionDTRUpdateEvent.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/event/FactionDisbandEvent.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/event/FactionFocusEvent.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/event/FactionHQUpdateEvent.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/event/FactionMemberAddEvent.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/event/FactionMemberDeathEvent.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/event/FactionMemberRemoveEvent.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/event/FactionMoveEvent.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/event/FactionUnAllyEvent.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/event/FactionUnFocusEvent.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/list/FactionList.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/list/FactionListType.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/listener/FactionChatListener.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/listener/FactionClaimListener.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/listener/FactionDeathListener.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/listener/FactionFocusListener.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/listener/FactionMapListener.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/listener/FactionMemberListener.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/listener/FactionMetadataListener.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/listener/FactionMoveListener.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/listener/FactionPistonListener.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/listener/FactionProtectionListener.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/listener/FactionRallyListener.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/listener/FactionStaffListener.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/listener/FactionSubclaimListener.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/listener/FactionWayPointListener.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/menu/faction/FactionFilterMenu.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/menu/faction/button/FactionFilterButton.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/menu/faction/button/FactionFilterTypeButton.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/menu/system/SystemEditMenu.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/menu/system/SystemEditorMenu.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/menu/system/button/SystemButton.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/menu/system/button/SystemClaimButton.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/menu/system/button/SystemCreateButton.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/menu/system/button/SystemDisplayNameButton.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/menu/system/button/SystemMetadataButton.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/prompt/FactionCreatePrompt.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/prompt/FactionDisplayPrompt.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/service/TeamViewerService.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/type/PlayerFaction.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/type/SystemFaction.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/type/defaults/TheEndFaction.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/type/defaults/TheNetherFaction.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/type/defaults/WarZoneFaction.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/type/defaults/WildernessFaction.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/type/player/ChatMode.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/type/player/FactionRole.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/type/player/RegenState.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/type/subclaim/Subclaim.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/game/GameFaction.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/game/GameHandler.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/game/GameModule.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/game/GameType.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/game/capture/CaptureZone.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/game/capture/CaptureZoneFaction.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/game/capture/type/CitadelFaction.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/game/capture/type/ConquestFaction.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/game/capture/type/FuryFaction.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/game/capture/type/KOTHFaction.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/game/capture/zone/ConquestCaptureZone.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/game/capture/zone/ConquestZoneType.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/game/capture/zone/FuryCaptureZone.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/game/capture/zone/FuryZoneType.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/game/command/GameActivateCommand.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/game/command/GameCreateCommand.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/game/command/GameGiveKeyCommand.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/game/command/GameTerminateCommand.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/game/command/citadel/CitadelCommand.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/game/command/citadel/CitadelRespawnCommand.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/game/command/citadel/CitadelScanCommand.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/game/command/citadel/CitadelSetCapperCommand.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/game/command/conquest/ConquestCommand.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/game/command/conquest/ConquestSetPointsCommand.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/game/command/conquest/ConquestSetRadiusCommand.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/game/command/conquest/ConquestSetZoneCommand.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/game/command/dtc/DTCSetAmountCommand.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/game/command/dtc/DTCSetObjectiveCommand.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/game/command/fury/FuryCommand.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/game/command/fury/FurySetPointsCommand.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/game/command/fury/FurySetZoneCommand.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/game/command/parameter/ConquestZoneTypeParameterProvider.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/game/command/parameter/FuryZoneTypeParameterProvider.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/game/command/parameter/GameTypeParameterProvider.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/game/event/GameActivateEvent.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/game/event/GameCaptureEvent.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/game/event/GameTerminateEvent.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/game/listener/CaptureZoneListener.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/game/listener/CitadelListener.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/game/listener/ConquestListener.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/game/listener/DTCListener.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/game/listener/FuryListener.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/game/listener/GameListener.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/game/listener/GameRewardListener.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/game/menu/GameLootMenu.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/game/other/DTCFaction.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/game/schedule/GameSchedule.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/game/schedule/command/GameCommand.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/game/schedule/command/GameScheduleCommand.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/game/schedule/command/GameScheduleGenerateCommand.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/game/scheduler/GameScheduler.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/MapConfig.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/MapHandler.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/MapModule.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/border/BorderHandler.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/border/command/BorderCommand.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/border/listener/BorderListener.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/command/EndExitCommand.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/command/MapKitCommand.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/command/OresCommand.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/command/ShopCommand.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/command/SpawnCommand.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/command/ToggleEndCommand.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/crowbar/CrowbarHandler.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/crowbar/CrowbarListener.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/crowbar/command/CrowbarCommand.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/engine/HCFNameTagAdapter.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/engine/HCFScoreboardAdapter.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/engine/HCFTabAdapter.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/eotw/EOTWHandler.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/eotw/command/EOTWDeathbansCommand.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/eotw/command/EOTWFFACommand.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/eotw/command/EOTWStartCommand.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/eotw/command/EOTWTeleportCommand.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/eotw/command/EOTWUnclaimCommand.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/eotw/listener/EOTWListener.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/listener/BookListener.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/listener/DiamondListener.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/listener/EXPListener.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/listener/EndListener.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/listener/GeneralListener.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/listener/GlitchListener.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/listener/InventoryListener.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/listener/MobListener.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/listener/NameTagListener.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/listener/NetherListener.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/listener/PearlListener.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/listener/PickaxeListener.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/listener/PotionListener.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/listener/PreventionListener.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/listener/RedstoneListener.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/listener/StatTrakListener.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/service/RankBroadcastService.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/shop/ShopMenu.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/shop/block/BlockCategory.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/shop/block/BlockCategoryButton.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/shop/block/BlockCategoryMenu.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/shop/block/BlockMenu.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/shop/buy/BuyButton.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/shop/buy/BuyMenu.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/shop/sell/SellButton.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/shop/sell/SellMenu.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/sotw/SOTWHandler.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/sotw/command/SOTWCancelCommand.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/sotw/command/SOTWEnableCommand.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/sotw/command/SOTWPauseCommand.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/sotw/command/SOTWStartCommand.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/sotw/event/SOTWEndEvent.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/sotw/event/SOTWStartEvent.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/sotw/listener/SOTWListener.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/sotw/scheduler/SOTWScheduler.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/mountain/MountainFaction.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/mountain/MountainHandler.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/mountain/MountainModule.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/mountain/MountainType.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/mountain/command/MountainCreateCommand.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/mountain/command/MountainRefillCommand.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/mountain/command/MountainScanCommand.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/mountain/command/cave/CaveCommand.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/mountain/command/glowstone/GlowstoneCommand.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/mountain/command/parameter/MountainTypeParameterProvider.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/mountain/listener/MountainListener.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/mountain/service/MountainRefillScheduler.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/mountain/type/CaveMountain.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/mountain/type/GlowstoneMountain.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/pillar/Pillar.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/pillar/PillarHandler.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/pillar/PillarModule.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/pillar/PillarType.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/pillar/listener/PillarListener.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/pillar/listener/PillarPacketListener.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/pillar/wall/PillarWall.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/pillar/wall/PillarWallRegistry.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/pillar/wall/PillarWallThread.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/pillar/wall/type/GamePillarWall.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/pillar/wall/type/PvPTimerPillarWall.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/pillar/wall/type/SpawnTagPillarWall.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/pvpclass/PvPClass.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/pvpclass/PvPClassHandler.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/pvpclass/PvPClassModule.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/pvpclass/PvPClassType.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/pvpclass/energy/EnergyEffect.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/pvpclass/event/PvPClassEquipEvent.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/pvpclass/event/PvPClassUnEquipEvent.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/pvpclass/event/type/ArcherMarkEvent.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/pvpclass/event/type/BackstabEvent.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/pvpclass/event/type/BardEffectEvent.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/pvpclass/item/ConsumableItem.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/pvpclass/item/type/EffectConsumableItem.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/pvpclass/listener/PvPClassListener.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/pvpclass/scheduler/PvPClassEnergyScheduler.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/pvpclass/type/ArcherClass.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/pvpclass/type/MinerClass.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/pvpclass/type/RogueClass.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/pvpclass/type/bard/BardClass.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/pvpclass/type/bard/effect/BardEnergyEffect.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/pvpclass/type/bard/scheduler/BardEffectScheduler.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/Statistic.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/StatisticHandler.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/StatisticModule.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/StatisticOption.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/StatisticRegistry.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/StatisticRepository.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/StatisticValue.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/command/BalanceCommand.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/command/CobbleCommand.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/command/DeathMessagesCommand.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/command/FoundDiamondsCommand.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/command/LivesCommand.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/command/PayCommand.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/command/PlayTimeCommand.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/command/ReclaimCommand.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/command/ReclaimResetCommand.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/command/SettingCommand.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/command/parameter/StatisticParameterProvider.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/impl/TabOption.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/leaderboard/LeaderboardEntry.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/leaderboard/LeaderboardNPC.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/leaderboard/LeaderboardUpdateTask.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/leaderboard/command/LeaderboardCommand.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/leaderboard/command/LeaderboardNPCCommand.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/listener/StatisticListener.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/menu/SettingButton.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/menu/SettingMenu.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/serializer/StatisticJsonAdapter.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/serializer/StatisticSerializer.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/type/BalanceStatistic.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/type/DeathsStatistic.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/type/HighestKillStreak.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/type/KillStreakStatistic.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/type/KillsStatistic.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/type/LivesStatistic.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/type/PlayTimeStatistic.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/type/defaults/BooleanStatistic.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/type/defaults/IntStatistic.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/type/ores/CoalMinedStatistic.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/type/ores/DiamondMinedStatistic.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/type/ores/EmeraldMinedStatistic.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/type/ores/GoldMinedStatistic.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/type/ores/IronMinedStatistic.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/type/ores/LapisMinedStatistic.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/type/ores/RedstoneMinedStatistic.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/type/setting/AbilityCooldownSetting.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/type/setting/CobbleSetting.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/type/setting/CustomTimersSetting.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/type/setting/DeathMessageSetting.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/type/setting/EventMessageSetting.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/type/setting/FactionFilterSetting.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/type/setting/FactionFocusSetting.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/type/setting/FoundDiamondSetting.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/type/setting/MapSetting.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/type/setting/ReclaimSetting.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/type/setting/SOTWProtectionSetting.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/type/setting/TabListSetting.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/timer/Timer.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/timer/TimerHandler.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/timer/TimerModule.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/timer/TimerRepository.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/timer/TimerType.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/timer/command/TimerAddCommand.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/timer/command/TimerRemoveCommand.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/timer/command/parameter/TimerParameterProvider.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/timer/command/pvptimer/PvPEnableCommand.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/timer/command/pvptimer/PvPTimeCommand.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/timer/command/type/GoppleCommand.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/timer/command/type/LogoutCommand.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/timer/event/TimerCreateEvent.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/timer/event/TimerExpireEvent.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/timer/event/TimerExtendEvent.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/timer/event/TimerRemoveEvent.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/timer/listener/AppleListener.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/timer/listener/ArcherMarkListener.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/timer/listener/EnderpearlListener.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/timer/listener/GappleListener.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/timer/listener/HomeListener.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/timer/listener/LogoutListener.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/timer/listener/PvPTimerListener.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/timer/listener/SpawnTagListener.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/timer/listener/StuckListener.kt create mode 100644 Shitty HCF/src/main/kotlin/cc/fyre/hcf/timer/listener/TimerListener.kt create mode 100644 Shitty HCF/src/main/resources/plugin.yml diff --git a/Shitty HCF/.gitignore b/Shitty HCF/.gitignore new file mode 100644 index 0000000..feb59ed --- /dev/null +++ b/Shitty HCF/.gitignore @@ -0,0 +1,7 @@ +/gradlew.bat +/gradlew +/gradle/ +/build/ +/.idea/ +/.gradle/ +/libs/ diff --git a/Shitty HCF/build.gradle b/Shitty HCF/build.gradle new file mode 100644 index 0000000..cf6892c --- /dev/null +++ b/Shitty HCF/build.gradle @@ -0,0 +1,81 @@ +plugins { + id "org.jetbrains.kotlin.kapt" version "$kotlin_version" apply true + id "org.jetbrains.kotlin.jvm" version "$kotlin_version" + id "com.github.johnrengelman.shadow" version "$shadow_version" +} + +this.group = 'cc.fyre.hcf' +this.version = '1.0-SNAPSHOT' +this.description = 'hcf' + +this.targetCompatibility = '1.8' +this.sourceCompatibility = '1.8' + +shadowJar { + classifier = null +} + +repositories { + mavenLocal() + mavenCentral() + + flatDir { + dirs 'libs' + } + +} + +apply plugin: "kotlin" +apply plugin: "kotlin-kapt" +apply plugin: 'maven-publish' + +dependencies { + + kapt "com.squareup.moshi:moshi-kotlin-codegen:$moshi_version" + + compileOnly "com.squareup.okhttp3:okhttp:$okhttp_version" + compileOnly "com.squareup.moshi:moshi-kotlin:$moshi_version" + compileOnly "com.squareup.moshi:moshi-adapters:$moshi_version" + + compileOnly "cc.fyre.circuit:circuit:$circuit_version" + compileOnly "cc.fyre.core:bukkit:1.1-SNAPSHOT" + compileOnly "cc.fyre.modsuite:bukkit:1.0-SNAPSHOT" + compileOnly "cc.fyre.shard:v1_7:1.0-SNAPSHOT" + compileOnly "net.hylist:spigot-server:$spigot_version" + compileOnly "redis.clients:jedis:$redis_version" + compileOnly "com.squareup.retrofit2:retrofit:$retrofit_version" + + compileOnly "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version" + + compileOnly 'com.comphenix.protocol:ProtocolLib:4.4.0' + implementation "org.mongodb:mongo-java-driver:$mongo_version" + compileOnly fileTree(dir: 'libs', include: ['*.jar']) +} + +compileKotlin { + kotlinOptions.jvmTarget = '1.8' +} + +sourceSets { + main.java.srcDirs += 'src/main/kotlin/' +} + +this.tasks.withType(JavaCompile) { + options.encoding = 'UTF-8' +} + +shadowJar { + shadowJar.archiveName = this.name + "-" + this.version + ".jar" +} + +publishing { + + publications { + + shadow(MavenPublication) { + publication -> project.shadow.component(publication) + } + + } + +} \ No newline at end of file diff --git a/Shitty HCF/gradle.properties b/Shitty HCF/gradle.properties new file mode 100644 index 0000000..9f6c064 --- /dev/null +++ b/Shitty HCF/gradle.properties @@ -0,0 +1,10 @@ +moshi_version=1.12.0 +redis_version=3.6.3 +mongo_version=3.12.10 +shadow_version=5.2.0 +okhttp_version=4.9.1 +kotlin_version=1.5.21 +circuit_version=1.0-SNAPSHOT +retrofit_version=2.9.0 +retrofit_converter_version=2.9.0 +spigot_version=1.7.10-R0.1-SNAPSHOT \ No newline at end of file diff --git a/Shitty HCF/settings.gradle b/Shitty HCF/settings.gradle new file mode 100644 index 0000000..181c98a --- /dev/null +++ b/Shitty HCF/settings.gradle @@ -0,0 +1,2 @@ +rootProject.name = 'hcf' + diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/HCF.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/HCF.kt new file mode 100644 index 0000000..579c129 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/HCF.kt @@ -0,0 +1,191 @@ +package cc.fyre.hcf + +import cc.fyre.core.server.ServerModule +import cc.fyre.hcf.ability.AbilityModule +import cc.fyre.hcf.combatlogger.CombatLoggerModule +import cc.fyre.hcf.death.DeathModule +import cc.fyre.hcf.deathmessage.DeathMessageModule +import cc.fyre.hcf.map.engine.HCFNameTagAdapter +import cc.fyre.hcf.map.engine.HCFScoreboardAdapter +import cc.fyre.hcf.map.engine.HCFTabAdapter +import cc.fyre.hcf.faction.Faction + +import cc.fyre.hcf.faction.FactionModule +import cc.fyre.hcf.faction.FactionType +import cc.fyre.hcf.faction.type.PlayerFaction +import cc.fyre.hcf.faction.type.SystemFaction +import cc.fyre.hcf.game.GameFaction +import cc.fyre.hcf.game.GameModule +import cc.fyre.hcf.game.GameType +import cc.fyre.hcf.game.capture.CaptureZoneFaction +import cc.fyre.hcf.game.capture.type.CitadelFaction +import cc.fyre.hcf.game.capture.type.ConquestFaction +import cc.fyre.hcf.game.capture.type.FuryFaction +import cc.fyre.hcf.game.capture.type.KOTHFaction +import cc.fyre.hcf.game.other.DTCFaction + +import cc.fyre.hcf.map.MapModule +import cc.fyre.hcf.mountain.MountainFaction +import cc.fyre.hcf.mountain.MountainModule +import cc.fyre.hcf.mountain.MountainType +import cc.fyre.hcf.mountain.type.CaveMountain +import cc.fyre.hcf.mountain.type.GlowstoneMountain +import cc.fyre.hcf.pillar.PillarModule +import cc.fyre.hcf.pvpclass.PvPClassModule +import cc.fyre.hcf.statistic.StatisticModule + +import cc.fyre.hcf.timer.TimerModule +import cc.fyre.shard.command.CommandHandler +import cc.fyre.shard.moshi.MoshiUtil +import cc.fyre.shard.nametag.NameTagHandler +import cc.fyre.shard.scoreboard.ScoreboardHandler +import cc.fyre.shard.tab.TabHandler +import com.mongodb.MongoClient +import com.mongodb.client.MongoDatabase +import com.squareup.moshi.adapters.PolymorphicJsonAdapterFactory +import org.bukkit.Bukkit +import org.bukkit.plugin.Plugin + +import org.bukkit.plugin.java.JavaPlugin +import org.github.paperspigot.PaperSpigotConfig +import org.spigotmc.SpigotConfig +import redis.clients.jedis.JedisPool + +/** + * @project hcf + * + * @date 04/04/2020 + * @author xanderume@gmail.com + */ +class HCF : JavaPlugin() { + + private var kitMap: Plugin? = null + private var shutdown = false + + private val modules = mutableListOf() + + private lateinit var mongoDB: MongoDatabase + private lateinit var mongoPool: MongoClient + private lateinit var redisPool: JedisPool + + override fun onEnable() { + instance = this + + this.redisPool = JedisPool() + this.mongoPool = MongoClient() + + this.mongoDB = this.mongoPool.getDatabase(ServerModule.getServerId()) + + MoshiUtil.rebuild{ + + it.add( + PolymorphicJsonAdapterFactory.of(Faction::class.java,"TYPE") + .withSubtype(PlayerFaction::class.java,FactionType.PLAYER.name) + .withSubtype(SystemFaction::class.java,FactionType.SYSTEM.name) + ) + + it.add( + PolymorphicJsonAdapterFactory.of(MountainFaction::class.java,"MOUNTAIN") + .withSubtype(CaveMountain::class.java,MountainType.CAVE.name) + .withSubtype(GlowstoneMountain::class.java,MountainType.GLOWSTONE.name) + ) + + it.add(PolymorphicJsonAdapterFactory.of(GameFaction::class.java,FactionType.GAME.name) + .withSubtype(DTCFaction::class.java,GameType.DTC.name) + .withSubtype(KOTHFaction::class.java,GameType.KOTH.name) + ) + + it.add(PolymorphicJsonAdapterFactory.of(CaptureZoneFaction::class.java,"CAPTURE_ZONE") + .withSubtype(KOTHFaction::class.java,GameType.KOTH.name) + .withSubtype(FuryFaction::class.java,GameType.FURY.name) + .withSubtype(ConquestFaction::class.java,GameType.CONQUEST.name) + ) + + it.add(PolymorphicJsonAdapterFactory.of(KOTHFaction::class.java,GameType.KOTH.name) + .withSubtype(CitadelFaction::class.java,GameType.CITADEL.name) + ) + } + + this.registerModule(MapModule) + this.registerModule(DeathModule) + this.registerModule(TimerModule) + this.registerModule(PillarModule) + this.registerModule(FactionModule) + this.registerModule(AbilityModule) + this.registerModule(PvPClassModule) + this.registerModule(StatisticModule) + this.registerModule(GameModule) + this.registerModule(MountainModule) + this.registerModule(DeathMessageModule) + this.registerModule(CombatLoggerModule) + + SpigotConfig.instantRespawn = true + SpigotConfig.reduceArmorDamage = true + + SpigotConfig.brewingMultiplier = 4 + SpigotConfig.smeltingMultiplier = 4 + + TabHandler.setAdapter(HCFTabAdapter) + NameTagHandler.setAdapter(HCFNameTagAdapter) + ScoreboardHandler.setAdapter(HCFScoreboardAdapter) + + CommandHandler.registerAll(this) + + PaperSpigotConfig.strengthEffectModifier = 0.3 + + this.modules.forEach{it.onLateLoad(this)} + this.server.scheduler.runTaskTimerAsynchronously(this,{this.modules.forEach{it.onSave(this)}},HCFModule.SAVE_INTERVAL,HCFModule.SAVE_INTERVAL) + } + + override fun onDisable() { + this.shutdown = true + + this.modules.forEach{ + it.shutdown(this) + } + + // has to be last + this.mongoPool.close() + this.redisPool.close() + } + + fun registerModule(module: HCFModule) { + this.modules.add(module) + + module.init(this) + module.getCommands().forEach{CommandHandler.registerClass(it)} + module.getAdapters().forEach{CommandHandler.registerAdapter(it.key,it.value)} + module.getListeners().forEach{Bukkit.getServer().pluginManager.registerEvents(it,this)} + + this.modules.add(module) + } + + fun isKitMap():Boolean { + + if (this.kitMap == null) { + this.kitMap = Bukkit.getPluginManager().getPlugin("KitMap") ?: null + } + + return this.kitMap != null && this.kitMap!!.isEnabled + } + + fun isInShutdownState():Boolean { + return this.shutdown + } + + fun getMongoDB():MongoDatabase { + return this.mongoDB + } + + fun getRedisPool():JedisPool { + return this.redisPool + } + + companion object { + + lateinit var instance: HCF + + } + + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/HCFModule.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/HCFModule.kt new file mode 100644 index 0000000..1becc5b --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/HCFModule.kt @@ -0,0 +1,24 @@ +package cc.fyre.hcf + +import cc.fyre.shard.command.data.parameter.ParameterAdapter +import org.bukkit.event.Listener + +interface HCFModule { + + fun init(core: HCF) + fun shutdown(core: HCF) + + fun onSave(core: HCF) {} + fun onLateLoad(core: HCF) {} + + fun getCommands():List> + fun getAdapters():Map, ParameterAdapter<*>> + fun getListeners():List + + companion object { + + const val SAVE_INTERVAL = 5L * (60L * 20L) + + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/ability/Ability.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/ability/Ability.kt new file mode 100644 index 0000000..67508bf --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/ability/Ability.kt @@ -0,0 +1,142 @@ +package cc.fyre.hcf.ability + +import cc.fyre.core.api.ApiHandler +import cc.fyre.core.profile.ProfileHandler +import cc.fyre.hcf.HCF +import cc.fyre.hcf.ability.event.AbilityUseEvent +import cc.fyre.shard.util.item.ItemBuilder +import com.comphenix.protocol.PacketType +import com.comphenix.protocol.events.PacketAdapter +import org.bukkit.Bukkit +import org.bukkit.ChatColor +import org.bukkit.Location +import org.bukkit.entity.Player +import org.bukkit.event.HandlerList +import org.bukkit.event.Listener +import org.bukkit.event.player.PlayerInteractEvent +import org.bukkit.inventory.ItemStack +import org.bukkit.potion.PotionEffectType +import kotlin.collections.ArrayList + +/** + * @project hcf + * + * @date 13/12/2020 + * @author xanderume@gmail.com + */ +abstract class Ability(val id: String, val cooldown: Long) : Listener { + + private var enabled = true + + lateinit var item: ItemStack + lateinit var idLowerCase: String + + fun init() { + this.item = this.build() + this.idLowerCase = this.id.lowercase() + } + + private fun build():ItemStack { + return ItemBuilder.copyOf(this.getItemStack()).name(this.getDisplayName()).lore(this.getFullDescription()).build() + } + + open fun getCrate():String { + return "${ChatColor.DARK_PURPLE}${ChatColor.BOLD}Items" + } + + open fun getFullDescription():List { + + val lore = arrayListOf() + + lore.add(" ") + lore.addAll(this.getDescription()) + lore.add(" ") + lore.add("${ChatColor.GRAY}Available at: ${ChatColor.YELLOW}${ChatColor.BOLD}${ChatColor.UNDERLINE}${ApiHandler.getStoreUrl()}") + + return lore + } + + fun isEnabled():Boolean { + return this.enabled + } + + fun setEnabled(value: Boolean) { + + if (this.enabled == value) { + return + } + + if (value) { + Bukkit.getServer().pluginManager.registerEvents(this,HCF.instance) + } else { + HandlerList.unregisterAll(this) + } + + this.enabled = value + } + + abstract fun getUses():Int + abstract fun getPrice():Int + abstract fun getItemStack():ItemStack + abstract fun getDisplayName():String + abstract fun getDescription():ArrayList + abstract fun onPlayerInteract(event: PlayerInteractEvent) + + open fun isSpawnTag():Boolean { + return false + } + + open fun isInteractAble():Boolean { + return true + } + + open fun isScoreboardDisplay():Boolean { + return true + } + + protected fun callEvent(player: Player):AbilityUseEvent { + return this.callEvent(player,player.location) + } + + protected fun callEvent(player: Player,location: Location):AbilityUseEvent { + return AbilityUseEvent(this,player,location).call() + } + + fun isSimilar(stack: ItemStack?): Boolean { + + if (stack == null) { + return false + } + + if (stack.typeId != this.item.typeId) { + return false + } + + if (stack.hasItemMeta() != this.item.hasItemMeta()) { + return false + } + + return Bukkit.getServer().itemFactory.equals(stack.itemMeta,this.item.itemMeta) + } + + fun getDisplayName(player: Player):String { + + if (player.hasPotionEffect(PotionEffectType.INVISIBILITY)) { + return "???" + } + + return ProfileHandler.getDisplayNameById(player.uniqueId) + } + + companion object { + + val COUNTDOWN_COLORS = mapOf( + 5 to ChatColor.DARK_GREEN, + 4 to ChatColor.GREEN, + 3 to ChatColor.RED, + 2 to ChatColor.GOLD, + 1 to ChatColor.YELLOW + ) + + } +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/ability/AbilityHandler.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/ability/AbilityHandler.kt new file mode 100644 index 0000000..95b7d07 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/ability/AbilityHandler.kt @@ -0,0 +1,85 @@ +package cc.fyre.hcf.ability + +import cc.fyre.hcf.HCF +import cc.fyre.hcf.timer.TimerHandler +import cc.fyre.hcf.timer.TimerType +import com.comphenix.protocol.ProtocolLibrary +import com.google.common.collect.HashBasedTable +import org.bukkit.Bukkit +import org.bukkit.Material +import org.bukkit.inventory.ItemStack +import java.lang.Exception +import java.util.* +import kotlin.math.max + +object AbilityHandler { + + private val abilities = mutableMapOf() + private val abilitiesByItem = mutableMapOf>() + + private val cooldowns = HashBasedTable.create() + + fun register(ability: Ability) { + ability.init() + + this.abilities[ability.idLowerCase] = ability + this.abilitiesByItem.getOrPut(ability.item.type) { mutableListOf() }.add(ability) + + Bukkit.getServer().pluginManager.registerEvents(ability,HCF.instance) + } + + fun getAllAbilities():List { + return this.abilities.values.toList() + } + + fun getAbilityById(id: String): Ability? { + return this.abilities[id.lowercase()] + } + + fun getAbilityByItemStack(item: ItemStack): Ability? { + + if (item.itemMeta == null || item.itemMeta.lore == null || item.itemMeta.displayName == null) { + return null + } + + val byType = this.abilitiesByItem[item.type] + + if (byType == null || byType.isEmpty()) { + return null + } + + return byType.firstOrNull{it.item.durability == item.durability + && it.item.itemMeta.lore.size == item.itemMeta.lore.size + && it.item.itemMeta.displayName == item.itemMeta.displayName + } + } + + fun getCooldown(uuid: UUID,ability: Ability):Long { + + if (!this.cooldowns.contains(uuid,ability.idLowerCase)) { + return TimerHandler.getRemaining(uuid, TimerType.PARTNER_ITEM) + } + + return max( + this.cooldowns[uuid,ability.idLowerCase]!! - System.currentTimeMillis(), + TimerHandler.getRemaining(uuid, TimerType.PARTNER_ITEM) + ) + } + + fun setCooldown(uuid: UUID, ability: Ability, duration: Long = ability.cooldown) { + + if (duration <= 0L) { + this.cooldowns.remove(uuid,ability.idLowerCase) + } else { + this.cooldowns.put(uuid,ability.idLowerCase,System.currentTimeMillis() + duration) + } + + } + + fun getAllCooldowns(uuid: UUID):Map { + return this.cooldowns.row(uuid).entries + .associate{this.abilities[it.key]!! to (it.value - System.currentTimeMillis())} + .filter{it.value > 0L} + } + +} diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/ability/AbilityModule.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/ability/AbilityModule.kt new file mode 100644 index 0000000..0772ab4 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/ability/AbilityModule.kt @@ -0,0 +1,69 @@ +package cc.fyre.hcf.ability + +import cc.fyre.hcf.HCF +import cc.fyre.hcf.HCFModule +import cc.fyre.hcf.ability.command.AbilityCommand +import cc.fyre.hcf.ability.command.AbilityGiveCommand +import cc.fyre.hcf.ability.command.AbilityCooldownCommand +import cc.fyre.hcf.ability.command.parameter.AbilityParameterProvider +import cc.fyre.hcf.ability.pocketbard.PocketBard +import cc.fyre.hcf.ability.pocketbard.PocketBardAbility +import cc.fyre.hcf.ability.pocketbard.PocketBardType +import cc.fyre.hcf.ability.listener.AbilityListener +import cc.fyre.hcf.ability.type.* +import cc.fyre.hcf.ability.type.invisibility.Invisibility +import cc.fyre.shard.command.data.parameter.ParameterAdapter +import org.bukkit.event.Listener + +/** + * @project hcf + * + * @date 13/12/2020 + * @author xanderume@gmail.com + */ +object AbilityModule : HCFModule { + + override fun init(core: HCF) { + + AbilityHandler.register(PocketBard) + + for (type in PocketBardType.values()) { + AbilityHandler.register(PocketBardAbility(type)) + } + + AbilityHandler.register(Combo) + AbilityHandler.register(Rocket) + AbilityHandler.register(Grapple) + AbilityHandler.register(EggPort) + AbilityHandler.register(TimeWarp) + AbilityHandler.register(NinjaStar) + AbilityHandler.register(AntiPearl) + AbilityHandler.register(FocusMode) + AbilityHandler.register(Invisibility) + AbilityHandler.register(AntiBuildBone) + } + + override fun shutdown(core: HCF) {} + + override fun getCommands(): List> { + return listOf( + AbilityCommand::class.java, + AbilityGiveCommand::class.java, + AbilityCooldownCommand::class.java + ) + } + + override fun getAdapters(): Map, ParameterAdapter<*>> { + return mapOf( + Ability::class.java to AbilityParameterProvider + ) + } + + override fun getListeners(): List { + return listOf( + AbilityListener + ) + } + + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/ability/command/AbilityCommand.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/ability/command/AbilityCommand.kt new file mode 100644 index 0000000..bfcd1a5 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/ability/command/AbilityCommand.kt @@ -0,0 +1,15 @@ +package cc.fyre.hcf.ability.command + +import cc.fyre.hcf.ability.menu.AbilityMenu +import cc.fyre.shard.command.data.command.Command +import org.bukkit.entity.Player + +object AbilityCommand { + + @JvmStatic + @Command(names = ["ability","partneritem","partneritems"],permission = "") + fun execute(sender: Player) { + AbilityMenu().open(sender) + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/ability/command/AbilityCooldownCommand.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/ability/command/AbilityCooldownCommand.kt new file mode 100644 index 0000000..9b6224e --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/ability/command/AbilityCooldownCommand.kt @@ -0,0 +1,29 @@ +package cc.fyre.hcf.ability.command + +import cc.fyre.core.profile.ProfileHandler +import cc.fyre.hcf.ability.AbilityHandler +import cc.fyre.hcf.ability.Ability +import cc.fyre.shard.command.data.command.Command +import cc.fyre.shard.command.data.parameter.Parameter +import cc.fyre.shard.command.data.parameter.impl.PlayerParameterAdapter +import org.bukkit.ChatColor +import org.bukkit.command.CommandSender +import org.bukkit.entity.Player + +object AbilityCooldownCommand { + + @JvmStatic + @Command(names = ["ability cooldown","partneritem cooldown"],permission = "hcf.command.ability.cooldown") + fun execute(sender: CommandSender, + @Parameter(name = "ability")ability: Ability, + @Parameter(name = "player",defaultValue = PlayerParameterAdapter.SELF_KEY_WORD)target: Player + ) { + + if (sender !is Player || sender.uniqueId != target.uniqueId) { + sender.sendMessage("${ChatColor.GOLD}You have reset ${ProfileHandler.getDisplayNameById(target.uniqueId)}${ChatColor.GOLD}'s ${ability.getDisplayName()}${ChatColor.GOLD} cooldown.") + } + + AbilityHandler.setCooldown(target.uniqueId,ability,0L) + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/ability/command/AbilityGiveCommand.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/ability/command/AbilityGiveCommand.kt new file mode 100644 index 0000000..11ffeee --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/ability/command/AbilityGiveCommand.kt @@ -0,0 +1,37 @@ +package cc.fyre.hcf.ability.command + +import cc.fyre.core.profile.ProfileHandler +import cc.fyre.shard.command.data.command.Command +import cc.fyre.shard.command.data.parameter.Parameter +import cc.fyre.hcf.ability.Ability +import cc.fyre.shard.command.data.parameter.impl.PlayerParameterAdapter +import cc.fyre.shard.util.item.ItemBuilder +import org.bukkit.ChatColor +import org.bukkit.command.CommandSender +import org.bukkit.entity.Player +/** + * @project hcf + * + * @date 13/12/2020 + * @author xanderume@gmail.com + */ +object AbilityGiveCommand { + + const val PERMISSION = "hcf.command.ability.give" + + @JvmStatic + @Command(names = ["ability give","partneritem give"],permission = PERMISSION) + fun execute(sender: CommandSender, + @Parameter(name = "ability")ability: Ability, + @Parameter(name = "amount",defaultValue = "1")amount: Int, + @Parameter(name = "player",defaultValue = PlayerParameterAdapter.SELF_KEY_WORD)target: Player + ) { + + if (sender !is Player || sender.uniqueId != target.uniqueId) { + sender.sendMessage("${ChatColor.GOLD}You gave ${ProfileHandler.getDisplayNameById(target.uniqueId)}${ChatColor.RED} $amount ${ability.getDisplayName()}${ChatColor.GOLD}'s}.") + } + + target.inventory.addItem(ItemBuilder.copyOf(ability.item.clone()).amount(amount).build()) + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/ability/command/parameter/AbilityParameterProvider.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/ability/command/parameter/AbilityParameterProvider.kt new file mode 100644 index 0000000..5068ce1 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/ability/command/parameter/AbilityParameterProvider.kt @@ -0,0 +1,34 @@ +package cc.fyre.hcf.ability.command.parameter + +import cc.fyre.hcf.ability.AbilityHandler +import cc.fyre.hcf.ability.Ability +import cc.fyre.shard.command.data.parameter.ParameterAdapter +import org.bukkit.ChatColor +import org.bukkit.command.CommandSender +import org.bukkit.entity.Player + +/** + * @project hcf + * + * @date 13/12/2020 + * @author xanderume@gmail.com + */ +object AbilityParameterProvider : ParameterAdapter { + + override fun transform(sender: CommandSender,source: String): Ability? { + + val toReturn = AbilityHandler.getAbilityById(source) + + if (toReturn == null) { + sender.sendMessage(ChatColor.RED.toString() + "Ability " + ChatColor.YELLOW + source + ChatColor.RED + " not found.") + return null + } + + return toReturn + } + + override fun tabComplete(player: Player, flags: Set, source: String): List { + return AbilityHandler.getAllAbilities().filter{it.idLowerCase.startsWith(source,true)}.map{it.id} + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/ability/event/AbilityUseEvent.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/ability/event/AbilityUseEvent.kt new file mode 100644 index 0000000..fe73875 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/ability/event/AbilityUseEvent.kt @@ -0,0 +1,43 @@ +package cc.fyre.hcf.ability.event + +import cc.fyre.hcf.ability.Ability +import org.bukkit.Bukkit +import org.bukkit.Location + +import org.bukkit.entity.Player +import org.bukkit.event.Cancellable +import org.bukkit.event.Event +import org.bukkit.event.HandlerList + +/** + * @project hcf + * + * @date 13/12/2020 + * @author xanderume@gmail.com + */ +class AbilityUseEvent(val ability: Ability, val player: Player, val location: Location = player.location, var cooldown: Long = ability.cooldown) : Event(),Cancellable { + + private var cancelled = false + + override fun isCancelled(): Boolean { + return this.cancelled + } + + override fun setCancelled(value: Boolean) { + this.cancelled = value + } + + override fun getHandlers(): HandlerList { + return handlerList + } + + fun call():AbilityUseEvent { + Bukkit.getServer().pluginManager.callEvent(this) + return this + } + + companion object { + @JvmStatic val handlerList = HandlerList() + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/ability/listener/AbilityListener.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/ability/listener/AbilityListener.kt new file mode 100644 index 0000000..6e10e2c --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/ability/listener/AbilityListener.kt @@ -0,0 +1,124 @@ +package cc.fyre.hcf.ability.listener + +import cc.fyre.hcf.ability.AbilityHandler +import cc.fyre.hcf.ability.event.AbilityUseEvent +import cc.fyre.hcf.timer.TimerHandler +import cc.fyre.hcf.timer.TimerType +import cc.fyre.shard.util.TimeUtil +import org.bukkit.ChatColor +import org.bukkit.Sound +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.player.PlayerInteractEvent +import org.bukkit.event.player.PlayerItemDamageEvent + +/** + * @project hcf + * + * @date 13/12/2020 + * @author xanderume@gmail.com + */ +object AbilityListener : Listener { + + @EventHandler(priority = EventPriority.HIGHEST) + private fun onPlayerInteract(event: PlayerInteractEvent) { + + if (event.action == Action.LEFT_CLICK_BLOCK || event.action == Action.LEFT_CLICK_AIR) { + return + } + + if (event.item == null) { + return + } + + val ability = AbilityHandler.getAbilityByItemStack(event.item) ?: return + + if (!ability.isInteractAble()) { + return + } + + if (ability.cooldown > 0L) { + + val cooldown = AbilityHandler.getCooldown(event.player.uniqueId,ability) + + if (cooldown > 0) { + event.isCancelled = true + + event.player.sendMessage("${ChatColor.RED}You cannot use this for another ${ChatColor.BOLD}${if (cooldown > 60000L) TimeUtil.formatIntoDetailedString(cooldown) else TimeUtil.formatIntoFancy(cooldown)}${ChatColor.RED}.") + event.player.updateInventory() + return + } + + } + + ability.onPlayerInteract(event) + } + + @EventHandler(priority = EventPriority.MONITOR) + private fun onAbilityUse(event: AbilityUseEvent) { + + if (event.isCancelled) { + return + } + + AbilityHandler.setCooldown(event.player.uniqueId,event.ability) + + if (event.ability.isSpawnTag()) { + TimerHandler.addTimer(event.player.uniqueId, TimerType.SPAWN_TAG) + } + + if (event.ability.cooldown > 0L) { + TimerHandler.addTimer(event.player.uniqueId, TimerType.PARTNER_ITEM) + } + + if (event.ability.getUses() == -1) { + return + } + + if (event.ability.getUses() <= 1) { + + if (event.player.itemInHand.amount == 1) { + event.player.itemInHand = null + } else { + event.player.itemInHand.amount = event.player.itemInHand.amount - 1 + } + + return + } + + val durability = event.player.itemInHand.type.maxDurability / event.ability.getUses() + + if (event.player.itemInHand.durability + durability >= event.player.itemInHand.type.maxDurability) { + + if (event.player.itemInHand.amount == 1) { + event.player.itemInHand = null + } else { + event.player.itemInHand.amount = event.player.itemInHand.amount - 1 + } + + event.player.world.playSound(event.player.location,Sound.ITEM_BREAK,1.0F,1.0F) + } else { + event.player.itemInHand.durability = (event.player.itemInHand.durability + durability).toShort() + } + + event.player.updateInventory() + } + + @EventHandler(priority = EventPriority.LOWEST) + private fun onItemDamage(event: PlayerItemDamageEvent) { + + if (AbilityHandler.getAbilityByItemStack(event.item) == null) { + return + } + + if (event.damage <= 0) { + return + } + + event.isCancelled = true + event.player.updateInventory() + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/ability/menu/AbilityButton.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/ability/menu/AbilityButton.kt new file mode 100644 index 0000000..c625baf --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/ability/menu/AbilityButton.kt @@ -0,0 +1,54 @@ +package cc.fyre.hcf.ability.menu + +import cc.fyre.hcf.ability.Ability +import cc.fyre.hcf.ability.command.AbilityGiveCommand +import cc.fyre.shard.menu.button.Button +import cc.fyre.shard.menu.type.ConfirmMenu +import cc.fyre.shard.util.item.ItemBuilder +import org.bukkit.ChatColor +import org.bukkit.Material +import org.bukkit.entity.Player +import org.bukkit.event.inventory.ClickType +import org.bukkit.event.inventory.InventoryClickEvent +import org.bukkit.inventory.ItemStack +import java.util.function.Predicate + +class AbilityButton(private val ability: Ability) : Button() { + + override fun getItem(player: Player): ItemStack { + + if (!this.ability.isEnabled()) { + return ItemBuilder.of(Material.BEDROCK) + .name("${ChatColor.RED}${ChatColor.BOLD}${ChatColor.STRIKETHROUGH}${ChatColor.stripColor(this.ability.getDisplayName())}") + .lore(this.ability.getFullDescription()) + .build() + } + + return this.ability.item + } + + override fun onClick(player: Player, event: InventoryClickEvent) { + + if (!player.hasPermission(AbilityGiveCommand.PERMISSION)) { + return + } + + if (event.click == ClickType.MIDDLE) { + object : ConfirmMenu("${if (ability.isEnabled()) "Disable" else "Enable"}?", Predicate{value -> + + if (value) { + ability.setEnabled(!ability.isEnabled()) + } + + AbilityMenu().open(player) + return@Predicate true + }) { + + }.open(player) + return + } + + player.inventory.addItem(this.ability.item) + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/ability/menu/AbilityMenu.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/ability/menu/AbilityMenu.kt new file mode 100644 index 0000000..03dc6ee --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/ability/menu/AbilityMenu.kt @@ -0,0 +1,21 @@ +package cc.fyre.hcf.ability.menu + +import cc.fyre.hcf.ability.AbilityHandler +import cc.fyre.shard.menu.Menu +import cc.fyre.shard.menu.button.Button +import org.bukkit.entity.Player + +class AbilityMenu : Menu() { + + override fun getTitle(player: Player): String { + return "Abilities" + } + + override fun getButtons(player: Player): MutableMap { + return AbilityHandler.getAllAbilities() + .withIndex() + .associate{it.index to AbilityButton(it.value)} + .toMutableMap() + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/ability/pocketbard/PocketBard.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/ability/pocketbard/PocketBard.kt new file mode 100644 index 0000000..e8fdfa5 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/ability/pocketbard/PocketBard.kt @@ -0,0 +1,49 @@ +package cc.fyre.hcf.ability.pocketbard + +import cc.fyre.shard.util.item.ItemBuilder +import cc.fyre.hcf.ability.Ability +import org.bukkit.ChatColor +import org.bukkit.Material +import org.bukkit.event.player.PlayerInteractEvent +import org.bukkit.inventory.ItemStack + +/** + * @project hcf + * + * @date 13/12/2020 + * @author xanderume@gmail.com + */ +object PocketBard : Ability("pocketbard",0L) { + + const val AMOUNT = 5 + + override fun getUses(): Int { + return 1 + } + + override fun getPrice(): Int { + return 1000 + } + + override fun getItemStack(): ItemStack { + return ItemBuilder.of(Material.INK_SACK).data(14).build() + } + + override fun getDisplayName(): String { + return "${ChatColor.GOLD}${ChatColor.BOLD}Pocket Bard" + } + + override fun getDescription(): ArrayList { + + val description = arrayListOf() + + description.add("${ChatColor.GOLD}Receive ${ChatColor.RED}${ChatColor.BOLD}$AMOUNT${ChatColor.GOLD} portable bard effects!") + + return description + } + + override fun onPlayerInteract(event: PlayerInteractEvent) { + PocketBardMenu.open(event.player) + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/ability/pocketbard/PocketBardAbility.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/ability/pocketbard/PocketBardAbility.kt new file mode 100644 index 0000000..6b626b3 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/ability/pocketbard/PocketBardAbility.kt @@ -0,0 +1,85 @@ +package cc.fyre.hcf.ability.pocketbard + +import cc.fyre.hcf.ability.Ability +import cc.fyre.hcf.faction.FactionMetadata +import cc.fyre.hcf.map.sotw.SOTWHandler +import cc.fyre.hcf.pvpclass.PvPClassHandler +import cc.fyre.hcf.pvpclass.event.type.BardEffectEvent +import cc.fyre.hcf.pvpclass.type.bard.BardClass +import cc.fyre.hcf.pvpclass.type.bard.effect.BardEnergyEffect +import cc.fyre.hcf.timer.TimerHandler +import cc.fyre.hcf.timer.TimerType +import cc.fyre.shard.util.TimeUtil +import org.bukkit.Bukkit +import org.bukkit.ChatColor +import org.bukkit.event.player.PlayerInteractEvent +import org.bukkit.inventory.ItemStack +import java.util.concurrent.TimeUnit + +class PocketBardAbility(private val type: PocketBardType) : Ability("pocketbard_${type.name.lowercase()}",TimeUnit.MINUTES.toMillis(2L)) { + + private val bardEffect = BardEnergyEffect(this.type.material,0,null,this.type.effect) + + override fun getUses(): Int { + return 1 + } + + override fun getPrice(): Int { + return 1000 + } + + override fun isSpawnTag(): Boolean { + return true + } + + override fun isScoreboardDisplay(): Boolean { + return false + } + + override fun getItemStack(): ItemStack { + return ItemStack(this.type.material) + } + + override fun getDisplayName(): String { + return this.type.getDisplayName().split(" ")[0] + } + + override fun getDescription(): ArrayList { + return arrayListOf( + "${ChatColor.GOLD}Give you and your teammates", + "${ChatColor.RED}${ChatColor.BOLD}${TimeUtil.formatIntoDetailedString(((this.type.effect.duration / 20) - 1) * 1000L)}${ChatColor.GOLD} of ${this.type.getDisplayName()}${ChatColor.GOLD}!" + ) + } + + override fun onPlayerInteract(event: PlayerInteractEvent) { + event.isCancelled = true + + if (FactionMetadata.SAFE_ZONE.isValidAtLocation(event.player.location)) { + event.player.sendMessage("${ChatColor.RED}Pocket effects cannot be used while in spawn.") + return + } + + if (TimerHandler.hasTimer(event.player.uniqueId,TimerType.PVP_TIMER)) { + event.player.sendMessage("${ChatColor.RED}You cannot use a ${this.getDisplayName()}${ChatColor.RED} whilst having an active PvP Timer!") + return + } + + if (SOTWHandler.isActive() && SOTWHandler.isProtected(event.player)) { + event.isCancelled = true + event.player.sendMessage("${ChatColor.RED}You cannot use a ${this.getDisplayName()}${ChatColor.RED} whilst having an active SOTW Timer!") + return + } + + if (this.callEvent(event.player).isCancelled) { + return + } + + val players = BardClass.getNearbyPlayers(event.player,BardClass.DEFAULT_RADIUS,this.type.effect).toMutableList() + + players.forEach{PvPClassHandler.addPotionEffect(it,this.type.effect)} + players.remove(event.player) + + Bukkit.getServer().pluginManager.callEvent(BardEffectEvent(event.player,players,this.bardEffect)) + } + +} diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/ability/pocketbard/PocketBardButton.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/ability/pocketbard/PocketBardButton.kt new file mode 100644 index 0000000..cb4e2c5 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/ability/pocketbard/PocketBardButton.kt @@ -0,0 +1,49 @@ +package cc.fyre.hcf.ability.pocketbard + +import cc.fyre.shard.menu.button.Button +import cc.fyre.shard.util.item.ItemBuilder +import org.bukkit.ChatColor +import org.bukkit.entity.Player +import org.bukkit.event.inventory.InventoryClickEvent +import org.bukkit.inventory.ItemStack + +class PocketBardButton(private val type: PocketBardType) : Button() { + + override fun getItem(player: Player): ItemStack { + return ItemBuilder.of(this.type.material) + .name(this.type.getDisplayName()) + .build() + } + + override fun onClick(player: Player, event: InventoryClickEvent) { + + var pocketBard: ItemStack? = null + + for (content in player.inventory.contents.filterNotNull().sortedBy{it.amount}) { + + if (PocketBard.isSimilar(content)) { + pocketBard = content + break + } + + } + + if (pocketBard == null) { + player.closeInventory() + player.sendMessage("${ChatColor.RED}You have no more pocket bards!") + return + } + + if (pocketBard.amount <= 1) { + player.inventory.removeItem(pocketBard) + player.closeInventory() + } else { + pocketBard.amount = pocketBard.amount - 1 + } + + player.inventory.addItem(ItemBuilder.copyOf(this.type.getAbility().item.clone()) + .amount(PocketBard.AMOUNT) + .build() + ) + } +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/ability/pocketbard/PocketBardMenu.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/ability/pocketbard/PocketBardMenu.kt new file mode 100644 index 0000000..052f128 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/ability/pocketbard/PocketBardMenu.kt @@ -0,0 +1,38 @@ +package cc.fyre.hcf.ability.pocketbard + +import cc.fyre.shard.menu.Menu +import cc.fyre.shard.menu.button.Button +import org.bukkit.entity.Player + +object PocketBardMenu : Menu() { + + // Static menu, no point in recreating everything + + private const val SIZE = 3*9 + private const val TITLE = "Select an effect." + + private val BUTTONS = mutableMapOf( + 11 to PocketBardButton(PocketBardType.SPEED), + 12 to PocketBardButton(PocketBardType.JUMP_BOOST), + 13 to PocketBardButton(PocketBardType.STRENGTH), + 14 to PocketBardButton(PocketBardType.RESISTANCE), + 15 to PocketBardButton(PocketBardType.REGENERATION), + ) + + override fun isFill(player: Player, buttons: Map): Boolean { + return true + } + + override fun getSize(player: Player, buttons: Map): Int { + return SIZE + } + + override fun getTitle(player: Player): String { + return TITLE + } + + override fun getButtons(player: Player): MutableMap { + return BUTTONS + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/ability/pocketbard/PocketBardType.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/ability/pocketbard/PocketBardType.kt new file mode 100644 index 0000000..8b67432 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/ability/pocketbard/PocketBardType.kt @@ -0,0 +1,38 @@ +package cc.fyre.hcf.ability.pocketbard + +import cc.fyre.hcf.ability.AbilityHandler +import cc.fyre.shard.util.NumberUtil +import cc.fyre.shard.util.bukkit.PotionUtil +import org.bukkit.ChatColor +import org.bukkit.Material +import org.bukkit.potion.PotionEffect +import org.bukkit.potion.PotionEffectType + +enum class PocketBardType(val material: Material, val effect: PotionEffect, private var ability: PocketBardAbility? = null, private var displayName: String? = null) { + + SPEED(Material.SUGAR,PotionEffect(PotionEffectType.SPEED,6*20,2)), + JUMP_BOOST(Material.FEATHER,PotionEffect(PotionEffectType.JUMP,6*20,6)), + STRENGTH(Material.BLAZE_POWDER,PotionEffect(PotionEffectType.INCREASE_DAMAGE,5*20,1)), + RESISTANCE(Material.IRON_INGOT,PotionEffect(PotionEffectType.DAMAGE_RESISTANCE,6*20,2)), + REGENERATION(Material.GHAST_TEAR,PotionEffect(PotionEffectType.REGENERATION,6*20,2)); + //INVISIBILITY(Material.INK_SACK,PotionEffect(PotionEffectType.INVISIBILITY,46 *20,0)); + + fun getAbility():PocketBardAbility { + + if (this.ability == null) { + this.ability = AbilityHandler.getAbilityById("pocketbard_${this.name.lowercase()}")!! as PocketBardAbility + } + + return this.ability!! + } + + fun getDisplayName():String { + + if (this.displayName == null) { + this.displayName = "${PotionUtil.getColor(this.effect.type)}${ChatColor.BOLD}${PotionUtil.getName(this.effect.type)} ${NumberUtil.toRoman(this.effect.amplifier + 1)}" + } + + return this.displayName!! + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/ability/type/AntiBuildBone.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/ability/type/AntiBuildBone.kt new file mode 100644 index 0000000..163aad9 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/ability/type/AntiBuildBone.kt @@ -0,0 +1,170 @@ +package cc.fyre.hcf.ability.type + +import cc.fyre.core.profile.ProfileHandler +import cc.fyre.hcf.ability.AbilityHandler +import cc.fyre.hcf.ability.Ability +import cc.fyre.shard.util.TimeUtil +import org.bukkit.ChatColor +import org.bukkit.Material +import org.bukkit.entity.Player +import org.bukkit.event.EventHandler +import org.bukkit.event.EventPriority +import org.bukkit.event.block.Action +import org.bukkit.event.block.BlockPlaceEvent +import org.bukkit.event.entity.EntityDamageByEntityEvent +import org.bukkit.event.player.PlayerInteractEvent +import org.bukkit.inventory.ItemStack +import java.util.* +import java.util.concurrent.TimeUnit +import java.util.concurrent.atomic.AtomicInteger +import kotlin.collections.ArrayList +import kotlin.collections.HashMap + +/** + * @project hcf + * + * @date 13/12/2020 + * @author xanderume@gmail.com + */ +object AntiBuildBone : Ability("antibuild",TimeUnit.SECONDS.toMillis(90L)) { + + private val hits = mutableMapOf>() + + override fun getUses(): Int { + return 4 + } + + override fun getPrice(): Int { + return 1000 + } + + override fun getItemStack(): ItemStack { + return ItemStack(Material.BONE) + } + + override fun getDisplayName(): String { + return "${ChatColor.YELLOW}${ChatColor.BOLD}Anti-Build Bone" + } + + override fun getDescription():ArrayList { + + return arrayListOf( + "${ChatColor.GOLD}Hit a player ${ChatColor.RED}${ChatColor.BOLD}$HIT_AMOUNT times ${ChatColor.GOLD}to prevent them", + "${ChatColor.GOLD}from placing blocks for ${ChatColor.YELLOW}${ChatColor.BOLD}${TimeUtil.formatIntoDetailedString(PLACE_COOLDOWN)}${ChatColor.GOLD}." + ) + + } + + override fun onPlayerInteract(event: PlayerInteractEvent) {} + + + @EventHandler(priority = EventPriority.LOWEST) + private fun onBlockPlace(event: BlockPlaceEvent) { + + if (event.isCancelled) { + return + } + + val cooldown = getCooldown(event.player) + + if (cooldown <= 0L) { + return + } + + event.isCancelled = true + event.player.sendMessage("${ChatColor.RED}You cannot do this for another ${ChatColor.BOLD}${TimeUtil.formatIntoFancy(cooldown)}${ChatColor.RED}.") + } + + @EventHandler(priority = EventPriority.LOWEST) + private fun onPlayerInteract2(event: PlayerInteractEvent) { + + if (event.action != Action.RIGHT_CLICK_BLOCK || event.clickedBlock == null || event.clickedBlock.type != Material.FENCE_GATE && !event.clickedBlock.type.name.contains("DOOR")) { + return + } + + val cooldown = getCooldown(event.player) + + if (cooldown <= 0L) { + return + } + + event.isCancelled = true + event.player.sendMessage("${ChatColor.RED}You cannot do this for another ${ChatColor.BOLD}${TimeUtil.formatIntoFancy(cooldown)}${ChatColor.RED}.") + } + + override fun isInteractAble(): Boolean { + return false + } + + @EventHandler(priority = EventPriority.MONITOR) + private fun onEntityDamageByEntity(event: EntityDamageByEntityEvent) { + + if (event.isCancelled) { + return + } + + val player = event.entity + + if (player !is Player || event.damager !is Player) { + return + } + + val damager = event.damager as Player + + if (!this.isSimilar(damager.itemInHand)) { + return + } + + var cooldown = AbilityHandler.getCooldown(damager.uniqueId,this) + + if (cooldown > 0) { + event.isCancelled = true + + damager.sendMessage("${ChatColor.RED}You cannot use this for another ${ChatColor.BOLD}${if (cooldown > 60000L) TimeUtil.formatIntoDetailedString(cooldown) else TimeUtil.formatIntoFancy(cooldown)}${ChatColor.RED}.") + damager.updateInventory() + return + } + + cooldown = getCooldown(player) + + if (cooldown > 0L) { + damager.sendMessage("${this.getDisplayName(player)}${ChatColor.RED} is already on a block up cooldown for another ${ChatColor.BOLD}${TimeUtil.formatIntoFancy(cooldown)}${ChatColor.RED}.") + return + } + + this.hits.putIfAbsent(damager.uniqueId,HashMap()) + this.hits[damager.uniqueId]!!.putIfAbsent(player.uniqueId,AtomicInteger()) + + if (this.hits[damager.uniqueId]!![player.uniqueId]!!.get() < HIT_AMOUNT) { + return + } + + if (this.callEvent(damager).isCancelled) { + return + } + + damager.sendMessage("${ChatColor.GOLD}You have hit ${this.getDisplayName(player)} with a ${this.getDisplayName()}${ChatColor.GOLD}.") + player.sendMessage("${ChatColor.GOLD}You have been hit with a ${this.getDisplayName()}${ChatColor.GOLD} and cannot place blocks for ${ChatColor.YELLOW}${ChatColor.BOLD}${TimeUtil.formatIntoDetailedString( + PLACE_COOLDOWN + )}${ChatColor.GOLD}.") + + this.hits[damager.uniqueId]!!.remove(player.uniqueId) + + cache[player.uniqueId] = System.currentTimeMillis() + } + + private val cache = mutableMapOf() + + private const val HIT_AMOUNT = 3 + private const val PLACE_COOLDOWN = 15_000L + + fun getCooldown(player: Player):Long { + + if (!this.cache.containsKey(player.uniqueId)) { + return 0L + } + + return (this.cache[player.uniqueId]!! + PLACE_COOLDOWN) - System.currentTimeMillis() + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/ability/type/AntiPearl.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/ability/type/AntiPearl.kt new file mode 100644 index 0000000..9dcf49f --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/ability/type/AntiPearl.kt @@ -0,0 +1,102 @@ +package cc.fyre.hcf.ability.type + +import cc.fyre.shard.util.TimeUtil +import cc.fyre.hcf.ability.AbilityHandler +import cc.fyre.hcf.ability.Ability +import cc.fyre.hcf.timer.TimerHandler +import cc.fyre.hcf.timer.TimerType +import org.bukkit.ChatColor +import org.bukkit.Material +import org.bukkit.entity.Player +import org.bukkit.event.EventHandler +import org.bukkit.event.EventPriority +import org.bukkit.event.block.Action +import org.bukkit.event.entity.EntityDamageByEntityEvent +import org.bukkit.event.player.PlayerInteractEvent +import org.bukkit.inventory.ItemStack +import java.util.concurrent.TimeUnit + +/** + * @project hcf + * + * @date 01/01/2021 + * @author xanderume@gmail.com + */ +object AntiPearl : Ability("antipearl",TimeUnit.MINUTES.toMillis(3L)) { + + override fun getUses(): Int { + return 1 + } + + override fun getPrice(): Int { + return 2500 + } + + override fun getItemStack(): ItemStack { + return ItemStack(Material.EYE_OF_ENDER) + } + + override fun getDisplayName(): String { + return "${ChatColor.RED}${ChatColor.BOLD}Anti Pearl" + } + + override fun getDescription(): ArrayList { + return arrayListOf( + "${ChatColor.GOLD}Hit a player to put them on", + "${ChatColor.GOLD}pearl cooldown for ${ChatColor.YELLOW}${ChatColor.BOLD}${TimeUtil.formatIntoDetailedString(TimerType.ENDER_PEARL.duration)}${ChatColor.GOLD}." + ) + } + + override fun isInteractAble(): Boolean { + return false + } + + override fun onPlayerInteract(event: PlayerInteractEvent) {} + + @EventHandler(priority = EventPriority.NORMAL) + private fun onPlayerInteract2(event: PlayerInteractEvent) { + + if (event.action == Action.LEFT_CLICK_AIR || event.action == Action.LEFT_CLICK_BLOCK || event.action == Action.PHYSICAL) { + return + } + + if (event.item == null || !this.isSimilar(event.item)) { + return + } + + event.isCancelled = true + } + + @EventHandler(priority = EventPriority.MONITOR) + private fun onEntityDamageByEntity(event: EntityDamageByEntityEvent) { + + if (event.isCancelled || event.entity !is Player || event.damager !is Player) { + return + } + + val player = event.entity as Player + val damager = event.damager as Player + + if (!this.isSimilar(damager.itemInHand)) { + return + } + + val cooldown = AbilityHandler.getCooldown(damager.uniqueId,this) + + if (cooldown > 0) { + damager.sendMessage("${ChatColor.RED}You cannot use this for another ${ChatColor.BOLD}${TimeUtil.formatIntoFancy(cooldown)}${ChatColor.RED}.") + damager.updateInventory() + return + } + + if (this.callEvent(damager).isCancelled) { + return + } + + TimerHandler.addTimer(event.entity.uniqueId, TimerType.ENDER_PEARL) + + player.sendMessage("${ChatColor.GOLD}You have been hit with an ${this.getDisplayName()}${ChatColor.GOLD}.") + damager.sendMessage("${ChatColor.GOLD}You have hit ${this.getDisplayName(player)}${ChatColor.RED} with an ${this.getDisplayName()}${ChatColor.RED}.") + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/ability/type/AntiTrap.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/ability/type/AntiTrap.kt new file mode 100644 index 0000000..5e005b5 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/ability/type/AntiTrap.kt @@ -0,0 +1,84 @@ +package cc.fyre.hcf.ability.type + +import cc.fyre.hcf.HCF +import cc.fyre.hcf.ability.Ability +import cc.fyre.hcf.faction.FactionHandler +import cc.fyre.hcf.faction.type.SystemFaction +import org.bukkit.ChatColor +import org.bukkit.Material +import org.bukkit.event.EventHandler +import org.bukkit.event.EventPriority +import org.bukkit.event.block.Action +import org.bukkit.event.block.BlockPlaceEvent +import org.bukkit.event.player.PlayerInteractEvent +import org.bukkit.inventory.ItemStack +import org.bukkit.metadata.FixedMetadataValue +import java.util.concurrent.TimeUnit + +object AntiTrap : Ability("antitrap",TimeUnit.MINUTES.toMillis(5L)) { + + override fun getUses(): Int { + return 1 + } + + override fun getPrice(): Int { + return 10_000 + } + + override fun getItemStack(): ItemStack { + return ItemStack(Material.BEACON) + } + + override fun getDisplayName(): String { + return "${ChatColor.DARK_AQUA}${ChatColor.BOLD}Anti-Trap" + } + + override fun getDescription(): ArrayList { + return arrayListOf( + "${ChatColor.GOLD}Place this beacon to prevent all blocks", + "${ChatColor.GOLD}within an ${ChatColor.RED}${ChatColor.BOLD}$RADIUS block ${ChatColor.GOLD} from being placed", + "${ChatColor.GOLD}for a period of ${ChatColor.YELLOW}${ChatColor.BOLD}$DURATION seconds${ChatColor.GOLD}.", + ) + } + + override fun onPlayerInteract(event: PlayerInteractEvent) {} + + @EventHandler(priority = EventPriority.MONITOR) + private fun onBlockPlace(event: BlockPlaceEvent) { + + if (!event.player.itemInHand.isSimilar(this.item)) { + return + } + + val faction = FactionHandler.getFactionByLocation(event.block.location) + + if (faction is SystemFaction) { + return + } + + if (this.callEvent(event.player).isCancelled) { + event.isCancelled = true + return + } + + event.block.setMetadata(METADATA,FixedMetadataValue(HCF.instance,HITS)) + event.isCancelled = false + } + + @EventHandler(priority = EventPriority.MONITOR) + private fun onPlayerInteract2(event: PlayerInteractEvent) { + + if (event.action != Action.LEFT_CLICK_BLOCK) { + return + } + + if (event.clickedBlock == null || event.clickedBlock.type != Material.BEACON) { + return + } + } + + private const val HITS = 10 + private const val RADIUS = 8 + private const val DURATION = 30 + private const val METADATA = "ANTI_TRAP" +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/ability/type/Combo.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/ability/type/Combo.kt new file mode 100644 index 0000000..81db97f --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/ability/type/Combo.kt @@ -0,0 +1,122 @@ +package cc.fyre.hcf.ability.type + +import cc.fyre.hcf.HCF +import cc.fyre.hcf.ability.Ability +import cc.fyre.shard.util.NumberUtil +import cc.fyre.shard.util.TimeUtil +import cc.fyre.shard.util.bukkit.PotionUtil +import cc.fyre.shard.util.item.ItemBuilder +import org.bukkit.ChatColor +import org.bukkit.Material +import org.bukkit.entity.Player +import org.bukkit.entity.Projectile +import org.bukkit.event.EventHandler +import org.bukkit.event.EventPriority +import org.bukkit.event.entity.EntityDamageByEntityEvent +import org.bukkit.event.player.PlayerInteractEvent +import org.bukkit.inventory.ItemStack +import org.bukkit.potion.PotionEffect +import org.bukkit.potion.PotionEffectType +import org.bukkit.scheduler.BukkitRunnable +import org.bukkit.scheduler.BukkitTask +import java.util.* +import java.util.concurrent.TimeUnit +import java.util.concurrent.atomic.AtomicInteger +import kotlin.collections.ArrayList + +object Combo : Ability("combo",TimeUnit.MINUTES.toMillis(4L)) { + + private val hits = mutableMapOf() + private val tasks = mutableMapOf() + + override fun getUses(): Int { + return 1 + } + + override fun getPrice(): Int { + return 4000 + } + + override fun getItemStack(): ItemStack { + return ItemBuilder.of(Material.RAW_FISH) + .data(3) + .build() + } + + override fun getDisplayName(): String { + return "${ChatColor.RED}${ChatColor.BOLD}Combo" + } + + override fun getDescription(): ArrayList { + return arrayListOf( + "${ChatColor.GOLD}Begin a ${ChatColor.YELLOW}${ChatColor.BOLD}${DURATION_PERIOD} second ${ChatColor.GOLD}period where each", + "${ChatColor.GOLD}hit results in a second of ${PotionUtil.getDisplayName(EFFECT_TYPE)} ${NumberUtil.toRoman(EFFECT_AMPLIFIER)}${ChatColor.GOLD}.", + ) + } + + override fun onPlayerInteract(event: PlayerInteractEvent) { + + if (this.callEvent(event.player).isCancelled) { + return + } + + this.hits[event.player.uniqueId] = AtomicInteger() + this.tasks[event.player.uniqueId] = object : BukkitRunnable() { + + override fun run() { + this@Combo.tasks.remove(event.player.uniqueId) + this@Combo.hits.remove(event.player.uniqueId)?.get()?.also{ + + if (it <= 0) { + return@also + } + + if (!event.player.isOnline) { + return@also + } + + var duration = it + + if (duration > DURATION_LIMIT) { + duration = DURATION_LIMIT + } + + event.player.addPotionEffect(PotionEffect(EFFECT_TYPE, (duration * 20),EFFECT_AMPLIFIER - 1)) + event.player.sendMessage("${this@Combo.getDisplayName()}${ChatColor.GOLD} has activated you now have ${ChatColor.YELLOW}${ChatColor.BOLD}${TimeUtil.formatIntoDetailedString(duration * 1000L)}${ChatColor.GOLD} of ${PotionUtil.getDisplayName( + EFFECT_TYPE + )} ${NumberUtil.toRoman(EFFECT_AMPLIFIER)}${ChatColor.GOLD}.") + } + } + + }.runTaskLater(HCF.instance,DURATION_PERIOD * 20L) + } + + @EventHandler(priority = EventPriority.MONITOR) + private fun onEntityDamageByEntity(event: EntityDamageByEntityEvent) { + + val damager = if (event.damager is Player) { + event.damager as Player + } else if (event.damager is Projectile && ((event.damager as Projectile).shooter) is Player) { + (event.damager as Projectile).shooter as Player + } else { + null + } ?: return + + if (event.entity.uniqueId == damager.uniqueId) { + return + } + + if (!this.hits.containsKey(damager.uniqueId)) { + return + } + + this.hits[damager.uniqueId]!!.incrementAndGet() + } + + val EFFECT_TYPE: PotionEffectType = PotionEffectType.INCREASE_DAMAGE + const val EFFECT_AMPLIFIER: Int = 2 + + const val DURATION_LIMIT = 8 + private const val DURATION_PERIOD = 10L + +} diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/ability/type/EggPort.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/ability/type/EggPort.kt new file mode 100644 index 0000000..e453400 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/ability/type/EggPort.kt @@ -0,0 +1,156 @@ +package cc.fyre.hcf.ability.type + +import cc.fyre.shard.util.item.ItemBuilder +import cc.fyre.hcf.HCF +import cc.fyre.hcf.ability.Ability +import cc.fyre.hcf.faction.FactionHandler +import cc.fyre.hcf.game.GameFaction +import cc.fyre.hcf.map.eotw.EOTWHandler +import cc.fyre.hcf.map.sotw.SOTWHandler +import cc.fyre.hcf.timer.TimerHandler +import cc.fyre.hcf.timer.TimerType +import org.bukkit.ChatColor +import org.bukkit.Material +import org.bukkit.World +import org.bukkit.entity.Egg +import org.bukkit.entity.Player +import org.bukkit.event.EventHandler +import org.bukkit.event.EventPriority +import org.bukkit.event.entity.EntityDamageByEntityEvent +import org.bukkit.event.entity.ProjectileLaunchEvent +import org.bukkit.event.player.PlayerEggThrowEvent +import org.bukkit.event.player.PlayerInteractEvent +import org.bukkit.inventory.ItemStack +import org.bukkit.metadata.FixedMetadataValue +import java.util.* +import java.util.concurrent.TimeUnit + +/** + * @project hcf + * + * @date 13/12/2020 + * @author xanderume@gmail.com + */ +object EggPort : Ability("eggport",TimeUnit.SECONDS.toMillis(16L)) { + + override fun getUses(): Int { + return 1 + } + + override fun getPrice(): Int { + return 1000 + } + + override fun getItemStack(): ItemStack { + return ItemBuilder.of(Material.EGG).build() + } + + override fun getDisplayName(): String { + return "${ChatColor.LIGHT_PURPLE}${ChatColor.BOLD}Eggport" + } + + override fun getDescription(): ArrayList { + return arrayListOf( + "${ChatColor.GOLD}Swap locations with a player", + "${ChatColor.GOLD}within a ${ChatColor.RED}${ChatColor.BOLD}$DISTANCE block${ChatColor.GOLD} radius." + ) + } + + override fun onPlayerInteract(event: PlayerInteractEvent) {} + + @EventHandler(priority = EventPriority.MONITOR) + private fun onProjectileLaunch(event: ProjectileLaunchEvent) { + + if (event.entity !is Egg || event.entity.shooter !is Player) { + return + } + + val player = event.entity.shooter as Player + + if (!this.isSimilar(player.itemInHand)) { + return + } + + if (TimerHandler.hasTimer(player.uniqueId, TimerType.PVP_TIMER)) { + event.isCancelled = true + player.sendMessage("${ChatColor.RED}You cannot use a ${this.getDisplayName()}${ChatColor.RED} whilst having an active PvP Timer!") + return + } + + if (SOTWHandler.isActive() && SOTWHandler.isProtected(player)) { + event.isCancelled = true + player.sendMessage("${ChatColor.RED}You cannot use a ${this.getDisplayName()}${ChatColor.RED} whilst being SOTW protected!") + return + } + + if (EOTWHandler.isActive()) { + event.isCancelled = true + player.sendMessage("${ChatColor.RED}You cannot use a ${this.getDisplayName()}${ChatColor.RED} during EOTW!") + return + } + + if (player.world.environment != World.Environment.NORMAL) { + event.isCancelled = true + player.sendMessage("${ChatColor.RED}You cannot use a ${this.getDisplayName()}${ChatColor.RED} in the ${if (player.world.environment == World.Environment.THE_END) "The End" else "Nether"}!") + return + } + + if (this.callEvent(player).isCancelled) { + event.isCancelled = true + return + } + + event.entity.setMetadata(METADATA,FixedMetadataValue(HCF.instance,player.uniqueId.toString())) + } + + @EventHandler(priority = EventPriority.LOWEST) + private fun onEggThrow(event: PlayerEggThrowEvent) { + + if (this.item.type != Material.EGG) { + return + } + + if (!event.egg.hasMetadata(METADATA)) { + return + } + + event.isHatching = false + } + + @EventHandler(priority = EventPriority.MONITOR) + private fun onEntityDamage(event: EntityDamageByEntityEvent) { + + if (event.entity !is Player || event.damager !is Egg || !event.damager.hasMetadata(METADATA)) { + return + } + + if (event.isCancelled) { + return + } + + val shooter = HCF.instance.server.getPlayer(UUID.fromString(event.damager.getMetadata(METADATA)[0].asString())) ?: return + + val faction = FactionHandler.getFactionByLocation(event.entity.location) + + if (faction is GameFaction && faction.isActive()) { + shooter.sendMessage("${ChatColor.RED}You cannot use a ${this.getDisplayName()}${ChatColor.RED} whilst ${faction.getDisplayName(shooter)}${ChatColor.RED} is active!") + return + } + + if (shooter.location.distance(event.entity.location) > DISTANCE) { + shooter.sendMessage("${ChatColor.RED}That player is not within a ${ChatColor.WHITE}$DISTANCE ${ChatColor.RED}block radius!") + return + } + + val entityLocation = event.entity.location.clone() + val shooterLocation = shooter.location.clone() + + shooter.teleport(entityLocation) + + (event.entity as Player).teleport(shooterLocation) + (event.entity as Player).sendMessage("${ChatColor.GREEN}Poof! You were hit by a ${this.getDisplayName()}${ChatColor.GREEN}!") + } + + private const val DISTANCE = 15 + const val METADATA = "EGGPORT" +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/ability/type/FocusMode.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/ability/type/FocusMode.kt new file mode 100644 index 0000000..fb03f16 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/ability/type/FocusMode.kt @@ -0,0 +1,102 @@ +package cc.fyre.hcf.ability.type + +import cc.fyre.core.profile.ProfileHandler +import cc.fyre.hcf.ability.Ability +import cc.fyre.hcf.pvpclass.PvPClassHandler +import cc.fyre.hcf.timer.TimerHandler +import cc.fyre.hcf.timer.TimerType +import cc.fyre.hcf.timer.listener.ArcherMarkListener +import org.bukkit.Bukkit +import org.bukkit.ChatColor +import org.bukkit.Material +import org.bukkit.entity.Player +import org.bukkit.entity.Projectile +import org.bukkit.event.EventHandler +import org.bukkit.event.EventPriority +import org.bukkit.event.entity.EntityDamageByEntityEvent +import org.bukkit.event.player.PlayerInteractEvent +import org.bukkit.inventory.ItemStack +import java.util.* +import java.util.concurrent.TimeUnit +import kotlin.collections.ArrayList + +object FocusMode : Ability("focusmode",TimeUnit.MINUTES.toMillis(3L)) { + + private val lastDamage = mutableMapOf() + + override fun getUses(): Int { + return 1 + } + + override fun getPrice(): Int { + return 5000 + } + + override fun getItemStack(): ItemStack { + return ItemStack(Material.GOLD_NUGGET) + } + + override fun getDisplayName(): String { + return "${ChatColor.YELLOW}${ChatColor.BOLD}Focus Mode" + } + + override fun getDescription(): ArrayList { + return arrayListOf( + "${ChatColor.GOLD}Right click to deal ${ChatColor.RED}${ChatColor.BOLD}${ArcherMarkListener.INCREASE_DAMAGE}% ${ChatColor.GOLD}more damage to", + "${ChatColor.GOLD}the last person you hit for ${ChatColor.YELLOW}${ChatColor.BOLD}${TimerType.ARCHER_MARK.duration / 1000L} seconds${ChatColor.GOLD}." + ) + } + + override fun onPlayerInteract(event: PlayerInteractEvent) { + + val uuid = this.lastDamage[event.player.uniqueId] ?: return + val player = Bukkit.getServer().getPlayer(uuid) + + if (player == null) { + event.player.sendMessage("${ChatColor.RED}This player is no longer online.") + return + } + + val pvpClass = PvPClassHandler.getPvPClassByPlayer(player.uniqueId) + + if (pvpClass != null) { + event.player.sendMessage("${ProfileHandler.getDisplayNameById(player.uniqueId)}${ChatColor.RED} is in a ${pvpClass.getName()} class and cannot be focused.") + return + } + + if (TimerHandler.hasTimer(player.uniqueId,TimerType.ARCHER_MARK)) { + event.player.sendMessage("${ProfileHandler.getDisplayNameById(player.uniqueId)} ${ChatColor.RED}is currently ${ChatColor.GOLD}${ChatColor.BOLD}Archer Marked${ChatColor.RED} and cannot be focused.") + return + } + + if (this.callEvent(event.player).isCancelled) { + return + } + + TimerHandler.addTimer(player.uniqueId,TimerType.ARCHER_MARK) + + player.sendMessage("${ChatColor.GOLD}You have been hit with a ${this.getDisplayName()}${ChatColor.GOLD} you will now take ${ChatColor.RED}${ArcherMarkListener.INCREASE_DAMAGE}%${ChatColor.GOLD} more damage.") + event.player.sendMessage("${ChatColor.GOLD}You have used your ${this.getDisplayName()}${ChatColor.GOLD} on ${ProfileHandler.getDisplayNameById(player.uniqueId)}${ChatColor.GOLD} they will now take ${ChatColor.RED}${ArcherMarkListener.INCREASE_DAMAGE}${ChatColor.GOLD} more damage.") + + this.lastDamage.remove(event.player.uniqueId) + } + + @EventHandler(priority = EventPriority.MONITOR) + private fun onEntityDamageByEntity(event: EntityDamageByEntityEvent) { + + val damager = if (event.damager is Player) { + event.damager as Player + } else if (event.damager is Projectile && ((event.damager as Projectile).shooter) is Player) { + (event.damager as Projectile).shooter as Player + } else { + null + } ?: return + + if (event.entity.uniqueId == damager.uniqueId) { + return + } + + this.lastDamage[damager.uniqueId] = event.entity.uniqueId + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/ability/type/Grapple.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/ability/type/Grapple.kt new file mode 100644 index 0000000..9094212 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/ability/type/Grapple.kt @@ -0,0 +1,121 @@ +package cc.fyre.hcf.ability.type + +import cc.fyre.hcf.ability.AbilityHandler +import cc.fyre.shard.util.TimeUtil +import cc.fyre.hcf.ability.Ability +import org.bukkit.ChatColor +import org.bukkit.Material +import org.bukkit.Sound +import org.bukkit.block.Block +import org.bukkit.block.BlockFace +import org.bukkit.entity.LivingEntity +import org.bukkit.event.EventHandler +import org.bukkit.event.EventPriority +import org.bukkit.event.player.PlayerFishEvent +import org.bukkit.event.player.PlayerInteractEvent +import org.bukkit.inventory.ItemStack +import org.bukkit.util.Vector +import java.util.concurrent.TimeUnit +import kotlin.collections.ArrayList + +/** + * @project hcf + * + * @date 13/12/2020 + * @author xanderume@gmail.com + */ +object Grapple : Ability("grapple",TimeUnit.SECONDS.toMillis(40L)) { + + override fun getUses(): Int { + return 8 + } + + override fun getPrice(): Int { + return 1000 + } + + override fun getItemStack(): ItemStack { + return ItemStack(Material.FISHING_ROD) + } + + override fun getDisplayName(): String { + return "${ChatColor.GREEN}${ChatColor.BOLD}Grapple" + } + + override fun getDescription(): ArrayList { + return arrayListOf( + "${ChatColor.GOLD}Pull yourself towards this rod." + ) + } + + override fun isInteractAble(): Boolean { + return false + } + + override fun onPlayerInteract(event: PlayerInteractEvent) {} + + @EventHandler(priority = EventPriority.LOWEST) + private fun onPlayerFish(event: PlayerFishEvent) { + + if (event.isCancelled) { + return + } + + if (!this.isSimilar(event.player.itemInHand)) { + return + } + + if (event.state == PlayerFishEvent.State.FISHING) { + return + } + + val cooldown = AbilityHandler.getCooldown(event.player.uniqueId,this) + + if (cooldown > 0) { + event.hook.remove() + event.player.sendMessage("${ChatColor.RED}You cannot use this for another ${ChatColor.BOLD}${if (cooldown > 60000L) TimeUtil.formatIntoDetailedString(cooldown) else TimeUtil.formatIntoFancy(cooldown)}${ChatColor.RED}.") + event.player.updateInventory() + return + } + + val hooked = event.hook ?: return + + if (event.caught != null) { + event.hook.remove() + return + } + + val location = event.player.location + val hookedLocation = hooked.location + + if (!(this.isEligible(hookedLocation.block) || this.isEligible(hookedLocation.block.getRelative(BlockFace.UP)) || this.isEligible(hookedLocation.block.getRelative(BlockFace.DOWN)))) { + return + } + + if (this.callEvent(event.player,hookedLocation).isCancelled) { + return + } + + event.player.world.playSound(event.player.player.location,Sound.ZOMBIE_INFECT,0.5F,1.8F) + event.player.velocity = Vector(hookedLocation.x - location.x,hookedLocation.y - location.y,hookedLocation.z - location.z).multiply( + VELOCITY + ) + + event.expToDrop = 0 + + hooked.remove() + + if (event.caught == null || event.caught is LivingEntity) { + return + } + + event.caught.remove() + } + + private fun isEligible(block: Block): Boolean { + return !(block.type == Material.AIR || block.type == Material.STATIONARY_WATER || block.type == Material.WATER) + } + + private const val VELOCITY = 0.25 + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/ability/type/NinjaStar.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/ability/type/NinjaStar.kt new file mode 100644 index 0000000..8188cb9 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/ability/type/NinjaStar.kt @@ -0,0 +1,148 @@ +package cc.fyre.hcf.ability.type + +import cc.fyre.shard.util.TimeUtil +import cc.fyre.hcf.HCF +import cc.fyre.hcf.ability.Ability +import org.bukkit.ChatColor +import org.bukkit.Location +import org.bukkit.Material +import org.bukkit.entity.Player +import org.bukkit.entity.Projectile +import org.bukkit.event.EventHandler +import org.bukkit.event.EventPriority +import org.bukkit.event.entity.EntityDamageByEntityEvent +import org.bukkit.event.entity.PlayerDeathEvent +import org.bukkit.event.player.PlayerInteractEvent +import org.bukkit.inventory.ItemStack +import org.bukkit.scheduler.BukkitRunnable +import java.util.* +import java.util.concurrent.TimeUnit + +/** + * @project hcf + * + * @date 13/12/2020 + * @author xanderume@gmail.com + */ +object NinjaStar : Ability("ninjastar",TimeUnit.MINUTES.toMillis(4L)) { + + private val attackerToPlayer = mutableMapOf() + private val playerToAttacker = mutableMapOf() + + override fun getUses(): Int { + return 1 + } + + override fun getPrice(): Int { + return 1000 + } + + override fun getItemStack(): ItemStack { + return ItemStack(Material.NETHER_STAR) + } + + override fun getDisplayName(): String { + return "${ChatColor.AQUA}${ChatColor.BOLD}Ninja Star" + } + + override fun getDescription(): ArrayList { + return arrayListOf( + "${ChatColor.GOLD}Teleport to the last person that", + "${ChatColor.GOLD}hit you within the last ${ChatColor.YELLOW}${ChatColor.BOLD}${TimeUtil.formatIntoDetailedString( + SPAN + )}${ChatColor.GOLD}!", + ) + } + + override fun onPlayerInteract(event: PlayerInteractEvent) { + + val entry = this.playerToAttacker[event.player.uniqueId] + + if (entry == null || entry.getTimeAgo() > SPAN) { + event.player.sendMessage("${ChatColor.RED}You have not been hit within the last ${ChatColor.BOLD}${TimeUtil.formatIntoDetailedString( + SPAN + )}${ChatColor.RED}!") + return + } + + if (this.callEvent(event.player).isCancelled) { + return + } + + object : BukkitRunnable() { + + private var ticks = DURATION_SECONDS + private val player = event.player + private val target = HCF.instance.server.getPlayer(entry.uuid) + + override fun run() { + + if (this.player == null || !this.player.isOnline) { + this.cancel() + return + } + + if (this.ticks <= 0) { + this.player.teleport(if (this.target != null && this.target.isOnline) this.target.location.clone() else entry.location.clone()) + this.cancel() + return + } + + this.player.sendMessage("${COUNTDOWN_COLORS[this.ticks]}${this.ticks--}..") + } + + }.runTaskTimer(HCF.instance,0L,20L) + } + + @EventHandler(priority = EventPriority.MONITOR) + private fun onPlayerDeath(event: PlayerDeathEvent) { + + val removed = this.attackerToPlayer.remove(event.entity.uniqueId) ?: return + + this.playerToAttacker.remove(removed) + } + + @EventHandler(priority = EventPriority.MONITOR) + private fun onEntityDamageByEntity(event: EntityDamageByEntityEvent) { + + if (event.isCancelled) { + return + } + + if (event.entity !is Player || event.damager !is Player) { + return + } + + var damager: Player? = null + + if (event.damager is Player) { + damager = event.damager as Player + } + + if (event.damager is Projectile && !event.damager.hasMetadata(EggPort.METADATA) && (event.damager as Projectile).shooter is Player) { + damager = (event.damager as Projectile).shooter as Player + } + + if (damager == null) { + return + } + + this.attackerToPlayer[damager.uniqueId] = event.entity.uniqueId + this.playerToAttacker[event.entity.uniqueId] = LastDamageEntry(System.currentTimeMillis(),event.damager.uniqueId,event.damager.location) + } + + + class LastDamageEntry(val time: Long,val uuid: UUID,val location: Location) { + + fun getTimeAgo():Long { + return System.currentTimeMillis() - this.time + } + + } + + + val SPAN = TimeUnit.SECONDS.toMillis(30L) + + const val DURATION_SECONDS = 5 + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/ability/type/Rocket.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/ability/type/Rocket.kt new file mode 100644 index 0000000..73d507a --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/ability/type/Rocket.kt @@ -0,0 +1,98 @@ +package cc.fyre.hcf.ability.type + +import cc.fyre.hcf.ability.Ability +import cc.fyre.shard.util.item.ItemBuilder +import org.bukkit.ChatColor +import org.bukkit.Effect +import org.bukkit.Material +import org.bukkit.Sound +import org.bukkit.entity.Player +import org.bukkit.event.EventHandler +import org.bukkit.event.EventPriority +import org.bukkit.event.entity.EntityDamageEvent +import org.bukkit.event.player.PlayerInteractEvent +import org.bukkit.event.player.PlayerQuitEvent +import org.bukkit.event.player.PlayerTeleportEvent +import org.bukkit.inventory.ItemStack +import org.bukkit.util.Vector +import java.util.* +import java.util.concurrent.TimeUnit + +/** + * @project hcf + * + * @date 13/12/2020 + * @author xanderume@gmail.com + */ +object Rocket : Ability("rocket",TimeUnit.SECONDS.toMillis(60L)) { + + private val cache = ArrayList() + + override fun getUses(): Int { + return 1 + } + + override fun getPrice(): Int { + return 1000 + } + + override fun getItemStack(): ItemStack { + return ItemBuilder.of(Material.FIREWORK).build() + } + + override fun getDisplayName(): String { + return "${ChatColor.DARK_RED}${ChatColor.BOLD}Rocket" + } + + override fun getDescription():ArrayList { + return arrayListOf( + "${ChatColor.GOLD}Launch yourself ${ChatColor.RED}${ChatColor.BOLD}20 blocks", + "${ChatColor.GOLD}up into the air with no fall damage!" + ) + } + + + override fun onPlayerInteract(event: PlayerInteractEvent) { + event.isCancelled = true + + if (this.callEvent(event.player).isCancelled) { + return + } + + event.player.world.playSound(event.player.location,Sound.FIREWORK_LAUNCH,0.0F,2.0F) + event.player.world.playEffect(event.player.location,Effect.MOBSPAWNER_FLAMES,20) + event.player.velocity = Vector(0.0,2.0,0.0) + + this.cache.add(event.player.uniqueId) + } + + @EventHandler(priority = EventPriority.MONITOR) + private fun onPlayerQuit(event: PlayerQuitEvent) { + this.cache.remove(event.player.uniqueId) + } + + @EventHandler(priority = EventPriority.MONITOR) + private fun onPlayerTeleport(event: PlayerTeleportEvent) { + // mainly for when they pearl + this.cache.remove(event.player.uniqueId) + } + + @EventHandler(priority = EventPriority.NORMAL) + private fun onEntityDamage(event: EntityDamageEvent) { + + if (event.entity !is Player) { + return + } + + if (event.cause != EntityDamageEvent.DamageCause.FALL) { + return + } + + if (!this.cache.remove(event.entity.uniqueId)) { + return + } + + event.isCancelled = true + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/ability/type/TimeWarp.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/ability/type/TimeWarp.kt new file mode 100644 index 0000000..9bb430d --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/ability/type/TimeWarp.kt @@ -0,0 +1,132 @@ +package cc.fyre.hcf.ability.type + +import cc.fyre.hcf.HCF +import cc.fyre.hcf.ability.Ability +import cc.fyre.hcf.timer.TimerType +import cc.fyre.hcf.timer.event.TimerExpireEvent +import cc.fyre.hcf.timer.event.TimerRemoveEvent +import org.bukkit.ChatColor +import org.bukkit.Location +import org.bukkit.Material +import org.bukkit.entity.EnderPearl +import org.bukkit.entity.Player +import org.bukkit.event.EventHandler +import org.bukkit.event.EventPriority +import org.bukkit.event.entity.ProjectileLaunchEvent +import org.bukkit.event.player.PlayerInteractEvent +import org.bukkit.inventory.ItemStack +import org.bukkit.scheduler.BukkitRunnable +import java.util.* +import java.util.concurrent.TimeUnit +import kotlin.collections.ArrayList +import kotlin.collections.HashMap + +/** + * @project hcf + * + * @date 31/12/2020 + * @author xanderume@gmail.com + */ +object TimeWarp : Ability("timewarp",TimeUnit.SECONDS.toMillis(150L)) { + + private val cache = mutableMapOf() + + override fun getUses(): Int { + return 1 + } + + override fun getPrice(): Int { + return 5000 + } + + override fun getItemStack(): ItemStack { + return ItemStack(Material.WATCH) + } + + override fun getDisplayName(): String { + return "${ChatColor.DARK_PURPLE}${ChatColor.BOLD}Time Warp" + } + + override fun getDescription(): ArrayList { + return arrayListOf( + "${ChatColor.GOLD}Travel back to where", + "${ChatColor.GOLD}you last threw a pearl!" + ) + } + + override fun onPlayerInteract(event: PlayerInteractEvent) { + + if (!this.cache.containsKey(event.player.uniqueId)) { + event.player.sendMessage("${ChatColor.RED}You have not thrown a pearl in the last ${ChatColor.BOLD}$SECONDS seconds${ChatColor.RED}.") + return + } + + if (this.callEvent(event.player).isCancelled) { + return + } + + event.player.sendMessage("${ChatColor.GOLD}You have used a ${this.getDisplayName()}${ChatColor.GOLD} teleporting you in ${ChatColor.RED}${ChatColor.BOLD}$TELEPORT_SECONDS seconds${ChatColor.GOLD}.") + + object : BukkitRunnable() { + + private var tick = TELEPORT_SECONDS + + override fun run() { + + if (!event.player.isOnline) { + this.cancel() + return + } + + if (this.tick <= 0L) { + this.cancel() + event.player.teleport(this@TimeWarp.cache.remove(event.player.uniqueId)) + return + } + + event.player.sendMessage("${COUNTDOWN_COLORS[this.tick]}${this.tick--}..") + } + + }.runTaskTimer(HCF.instance,0L,20L) + } + + @EventHandler(priority = EventPriority.MONITOR) + private fun onProjectileLaunch(event: ProjectileLaunchEvent) { + + if (event.isCancelled || event.entity !is EnderPearl) { + return + } + + val shooter = event.entity.shooter + + if (shooter !is Player) { + return + } + + this.cache[shooter.uniqueId] = shooter.location.clone() + } + + @EventHandler(priority = EventPriority.MONITOR) + private fun onTimerRemove(event: TimerRemoveEvent) { + + if (event.timer.type != TimerType.ENDER_PEARL) { + return + } + + this.cache.remove(event.uuid) + } + + @EventHandler(priority = EventPriority.MONITOR) + private fun onTimerExpire(event: TimerExpireEvent) { + + if (event.timer.type != TimerType.ENDER_PEARL) { + return + } + + this.cache.remove(event.uuid) + } + + private const val SECONDS = 16 + private const val TELEPORT_SECONDS = 3 + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/ability/type/invisibility/Invisibility.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/ability/type/invisibility/Invisibility.kt new file mode 100644 index 0000000..7553207 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/ability/type/invisibility/Invisibility.kt @@ -0,0 +1,143 @@ +package cc.fyre.hcf.ability.type.invisibility + +import cc.fyre.shard.util.TimeUtil +import cc.fyre.shard.util.item.ItemBuilder +import cc.fyre.hcf.HCF +import cc.fyre.hcf.ability.Ability +import com.comphenix.protocol.PacketType +import com.comphenix.protocol.ProtocolLibrary +import com.comphenix.protocol.events.PacketContainer +import com.comphenix.protocol.events.PacketEvent +import net.minecraft.server.v1_7_R4.ItemArmor +import org.bukkit.Bukkit +import org.bukkit.ChatColor +import org.bukkit.Material +import org.bukkit.craftbukkit.v1_7_R4.inventory.CraftItemStack +import org.bukkit.entity.Player +import org.bukkit.event.EventHandler +import org.bukkit.event.EventPriority +import org.bukkit.event.entity.EntityDamageByEntityEvent +import org.bukkit.event.entity.PotionEffectExpireEvent +import org.bukkit.event.entity.PotionEffectRemoveEvent +import org.bukkit.event.player.PlayerInteractEvent +import org.bukkit.inventory.ItemStack +import org.bukkit.potion.PotionEffect +import org.bukkit.potion.PotionEffectType +import java.util.concurrent.TimeUnit + +/** + * @project hcf + * + * @date 13/12/2020 + * @author xanderume@gmail.com + */ +object Invisibility : Ability("invisibility",TimeUnit.MINUTES.toMillis(5L)) { + + init { + ProtocolLibrary.getProtocolManager().addPacketListener(InvisibilityListener) + } + + override fun getUses(): Int { + return 1 + } + + override fun getPrice(): Int { + return 1000 + } + + override fun getItemStack(): ItemStack { + return ItemBuilder.of(Material.INK_SACK).build() + } + + override fun getDisplayName(): String { + return "${ChatColor.GRAY}${ChatColor.BOLD}Invisibility" + } + + override fun getDescription(): ArrayList { + return arrayListOf( + "${ChatColor.GOLD}Hide your armor for ${ChatColor.YELLOW}${ChatColor.BOLD}${TimeUtil.formatIntoDetailedString((EFFECT.duration / 20) * 1000L)}${ChatColor.GOLD}!", + ) + } + + override fun isInteractAble(): Boolean { + return true + } + + override fun onPlayerInteract(event: PlayerInteractEvent) { + + if (this.callEvent(event.player).isCancelled) { + event.isCancelled = true + return + } + + event.player.addPotionEffect(EFFECT,true) + + sendPacket(event.player,Bukkit.getServer().onlinePlayers,true) + } + + @EventHandler(priority = EventPriority.MONITOR) + private fun onEntityDamageByEntity(event: EntityDamageByEntityEvent) { + + if (event.isCancelled || event.entity !is Player || event.damager !is Player) { + return + } + + val effect = (event.entity as Player).activePotionEffects.firstOrNull{it.type == EFFECT.type && it.amplifier == EFFECT.amplifier} ?: return + + (event.entity as Player).removePotionEffect(effect.type) + (event.entity as Player).addPotionEffect(PotionEffect(effect.type,effect.duration,0)) + (event.entity as Player).sendMessage("${ChatColor.RED}You have been hit and your armor is now visible!") + + sendPacket(event.entity as Player,Bukkit.getServer().onlinePlayers,false) + } + + @EventHandler(priority = EventPriority.LOWEST) + private fun onPotionEffectExpire(event: PotionEffectExpireEvent) { + onPotionEffectRemove(event) + } + + @EventHandler(priority = EventPriority.LOWEST) + private fun onPotionEffectRemove(event: PotionEffectRemoveEvent) { + + if (event.entity !is Player) { + return + } + + if (event.effect.type != EFFECT.type || event.effect.amplifier != EFFECT.amplifier) { + return + } + + val effect = (event.entity as Player).activePotionEffects.firstOrNull{it.type == EFFECT.type && it.amplifier == EFFECT.amplifier} ?: return + + (event.entity as Player).removePotionEffect(effect.type) + (event.entity as Player).addPotionEffect(PotionEffect(effect.type,effect.duration,0)) + (event.entity as Player).sendMessage("${ChatColor.RED}You have been hit and your armor is now visible!") + + Bukkit.getServer().scheduler.runTask(HCF.instance) { + sendPacket(event.entity as Player,Bukkit.getServer().onlinePlayers,false) + } + + } + + private fun sendPacket(player: Player,collection: Collection,invisible: Boolean) { + + val packets = ArrayList() + + for (i in 0 until 4) { + + val packet = PacketContainer(PacketType.Play.Server.ENTITY_EQUIPMENT) + + packet.integers.write(0,player.entityId) + packet.integers.write(1,i + 1) + + packet.itemModifier.write(0,if (invisible) ItemStack(Material.AIR) else player.inventory.armorContents[i]) + + packets.add(packet) + } + + collection.filter{it.uniqueId != player.uniqueId}.forEach{packets.forEach{packet -> ProtocolLibrary.getProtocolManager().sendServerPacket(it,packet)}} + } + + val EFFECT = PotionEffect(PotionEffectType.INVISIBILITY,8*60*20,2,false) + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/ability/type/invisibility/InvisibilityListener.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/ability/type/invisibility/InvisibilityListener.kt new file mode 100644 index 0000000..7ddf37b --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/ability/type/invisibility/InvisibilityListener.kt @@ -0,0 +1,36 @@ +package cc.fyre.hcf.ability.type.invisibility + +import cc.fyre.hcf.HCF +import com.comphenix.protocol.PacketType +import com.comphenix.protocol.events.PacketAdapter +import com.comphenix.protocol.events.PacketEvent +import net.minecraft.server.v1_7_R4.ItemArmor +import org.bukkit.Material +import org.bukkit.craftbukkit.v1_7_R4.inventory.CraftItemStack + +object InvisibilityListener : PacketAdapter(HCF.instance,PacketType.Play.Server.ENTITY_EQUIPMENT) { + + + override fun onPacketSending(event: PacketEvent) { + + val id = event.packet.integers.read(0) + val itemStack = event.packet.itemModifier.read(0) + + if (itemStack == null || itemStack.type == Material.AIR) { + return + } + + if (CraftItemStack.asNMSCopy(itemStack).item !is ItemArmor) { + return + } + + val player = HCF.instance.server.onlinePlayers.firstOrNull{it.entityId == id} ?: return + + if (player.activePotionEffects.none{it.type == Invisibility.EFFECT.type && it.amplifier == Invisibility.EFFECT.amplifier}) { + return + } + + event.isCancelled = true + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/combatlogger/CombatLogger.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/combatlogger/CombatLogger.kt new file mode 100644 index 0000000..a8f7d71 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/combatlogger/CombatLogger.kt @@ -0,0 +1,100 @@ +package cc.fyre.hcf.combatlogger + +import cc.fyre.hcf.HCF +import cc.fyre.hcf.combatlogger.kb.ZeroKBProfile +import cc.fyre.hcf.combatlogger.scheduler.CombatLoggerScheduler +import net.minecraft.server.v1_7_R4.* +import org.bukkit.Bukkit +import org.bukkit.ChatColor +import org.bukkit.Material +import org.bukkit.craftbukkit.v1_7_R4.CraftWorld +import org.bukkit.craftbukkit.v1_7_R4.entity.CraftPlayer +import org.bukkit.craftbukkit.v1_7_R4.event.CraftEventFactory +import org.bukkit.entity.Player +import org.bukkit.event.entity.EntityDeathEvent +import java.util.* + +class CombatLogger(private val player: Player) : EntityVillager((player.location.world as CraftWorld).handle) { + + private var scheduler: CombatLoggerScheduler? = null + + fun spawn(player: Player) { + this.setLocation(player.location.x,player.location.y,player.location.z,player.location.yaw,player.location.pitch) + this.bukkitEntity.velocity = player.velocity + this.bukkitEntity.fallDistance = player.fallDistance + this.k = false + this.fromMobSpawner = true + this.health = player.health.toFloat() + this.kbProfile = ZeroKBProfile + this.customName = "${ChatColor.GRAY}(Combat-Logger) ${ChatColor.RED}${player.name}" + this.customNameVisible = true + + this.world.addEntity(this) + + this.scheduler = CombatLoggerScheduler(this) + this.scheduler!!.runTaskTimer(HCF.instance,20,20L) + } + + fun getPlayer():Player { + return this.player + } + + fun getPlayerId():UUID { + return this.player.uniqueId + } + + override fun move(x: Double,y: Double,z: Double) {} + override fun collide(entity: Entity?) {} + override fun g(d0: Double, d1: Double, d2: Double) {} + + override fun dropDeathLoot(flag: Boolean, i: Int) {} + override fun createChild(entity: EntityAgeable?): EntityAgeable? = null + + fun kill() { + this.die(DamageSource.GENERIC) + this.scheduler?.cancel() + this.scheduler = null + this.destroyScheduler() + } + + fun handleDeath(event: EntityDeathEvent) { + + val handle = (this.player as CraftPlayer).handle + val contents = this.player.inventory.contents + .plus(this.player.inventory.armorContents) + .filter{it != null && it.type != Material.AIR} + .toList() + + CraftEventFactory.callPlayerDeathEvent( + handle, + contents, + null, + this.player.world.getGameRuleValue("keepInventory").toBoolean() + ) + + this.player.inventory.clear() + this.player.inventory.armorContents = null + this.player.health = 0.0 + + Bukkit.getServer().scheduler.runTaskAsynchronously(HCF.instance) { + this.player.saveData() + } + + this.destroyScheduler() + } + + fun destroy() { + this.world.removeEntity(this) + } + + private fun destroyScheduler() { + + if (this.scheduler == null) { + return + } + + this.scheduler!!.cancel() + this.scheduler = null + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/combatlogger/CombatLoggerHandler.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/combatlogger/CombatLoggerHandler.kt new file mode 100644 index 0000000..1ec8c49 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/combatlogger/CombatLoggerHandler.kt @@ -0,0 +1,79 @@ +package cc.fyre.hcf.combatlogger + +import org.bukkit.entity.* +import java.util.* +import java.util.concurrent.ConcurrentHashMap + +/** + * @project hcf + * + * @date 13/09/2020 + * @author xanderume@gmail.com + */ +object CombatLoggerHandler { + + private val loggers = ConcurrentHashMap() + private val loggersById = ConcurrentHashMap() + private val safetyProtection = ConcurrentHashMap.newKeySet() + + fun create(player: Player):CombatLogger { + + var toReturn = this.loggers[player.uniqueId] + + if (toReturn == null) { + toReturn = CombatLogger(player) + this.loggers[player.uniqueId] = toReturn + this.loggersById[toReturn.id] = toReturn + } + + return toReturn + } + + fun destroy(player: Player,kill: Boolean = false) { + + val logger = this.loggers.remove(player.uniqueId) + + if (logger != null) { + + if (kill) { + logger.kill() + } else { + logger.destroy() + } + + player.health = logger.health.toDouble() + + this.loggersById.remove(logger.id) + } + + this.safetyProtection.remove(player.uniqueId) + } + + fun isCombatLogger(entity: Entity):Boolean { + return this.loggersById.contains(entity.entityId) + } + + fun getLoggerByPlayer(uuid: UUID):CombatLogger? { + return this.loggers[uuid] + } + + fun getLoggerByEntityId(id: Int):CombatLogger? { + return this.loggersById[id] + } + + fun getAllLoggers():List { + return this.loggers.values.toList() + } + + fun addSafetyProtection(uuid: UUID) { + this.safetyProtection.add(uuid) + } + + fun hasSafetyProtection(uuid: UUID):Boolean { + return this.safetyProtection.remove(uuid) + } + + const val RADIUS = 40.0 + const val SECONDS = 25 + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/combatlogger/CombatLoggerModule.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/combatlogger/CombatLoggerModule.kt new file mode 100644 index 0000000..0587e24 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/combatlogger/CombatLoggerModule.kt @@ -0,0 +1,34 @@ +package cc.fyre.hcf.combatlogger + +import cc.fyre.hcf.HCF +import cc.fyre.hcf.HCFModule +import cc.fyre.hcf.combatlogger.listener.CombatLoggerListener +import cc.fyre.shard.command.data.parameter.ParameterAdapter +import cc.fyre.shard.util.entity.EntityUtil +import org.bukkit.entity.EntityType +import org.bukkit.event.Listener + +object CombatLoggerModule : HCFModule { + + override fun init(core: HCF) {} + + override fun shutdown(core: HCF) { + EntityUtil.registerEntity(CombatLogger::class.java,"Villager",EntityType.VILLAGER.typeId.toInt()) + CombatLoggerHandler.getAllLoggers().forEach{it.destroy()} + } + + override fun getCommands(): List> { + return listOf() + } + + override fun getAdapters(): Map, ParameterAdapter<*>> { + return mapOf() + } + + override fun getListeners(): List { + return listOf( + CombatLoggerListener + ) + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/combatlogger/kb/ZeroKBProfile.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/combatlogger/kb/ZeroKBProfile.kt new file mode 100644 index 0000000..4ab5181 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/combatlogger/kb/ZeroKBProfile.kt @@ -0,0 +1,74 @@ +package cc.fyre.hcf.combatlogger.kb + +import cc.fyre.knockback.KnockbackProfile + +/** + * @project hcf + * + * @date 13/09/2020 + * @author xanderume@gmail.com + */ +object ZeroKBProfile : KnockbackProfile { + + private const val name = "Zero" + + private var friction = 0.1 + private var vertical = 0.0 + private var horizontal = 0.0 + private var verticalLimit = 0.0 + private var extraVertical = 0.0 + private var extraHorizontal = 0.0 + + override fun getName():String { + return name + } + + override fun getFriction(): Double { + return friction + } + + override fun setFriction(friction: Double) { + this.friction = friction + } + + override fun getHorizontal(): Double { + return horizontal + } + + override fun setHorizontal(horizontal: Double) { + this.horizontal = horizontal + } + + override fun getVertical(): Double { + return vertical + } + + override fun setVertical(vertical: Double) { + this.vertical = vertical + } + + override fun getVerticalLimit(): Double { + return verticalLimit + } + + override fun setVerticalLimit(verticalLimit: Double) { + this.verticalLimit = verticalLimit + } + + override fun getExtraHorizontal(): Double { + return extraHorizontal + } + + override fun setExtraHorizontal(extraHorizontal: Double) { + this.extraHorizontal = extraHorizontal + } + + override fun getExtraVertical(): Double { + return extraVertical + } + + override fun setExtraVertical(extraVertical: Double) { + this.extraVertical = extraVertical + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/combatlogger/listener/CombatLoggerListener.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/combatlogger/listener/CombatLoggerListener.kt new file mode 100644 index 0000000..d0b4d00 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/combatlogger/listener/CombatLoggerListener.kt @@ -0,0 +1,206 @@ +package cc.fyre.hcf.combatlogger.listener + +import cc.fyre.hcf.combatlogger.CombatLoggerHandler +import cc.fyre.hcf.faction.Faction +import cc.fyre.hcf.faction.type.PlayerFaction +import cc.fyre.hcf.faction.type.SystemFaction +import cc.fyre.hcf.faction.listener.FactionProtectionListener +import cc.fyre.hcf.timer.TimerType +import cc.fyre.core.uuid.UUIDHandler +import cc.fyre.hcf.combatlogger.CombatLogger +import cc.fyre.hcf.faction.FactionHandler +import cc.fyre.hcf.faction.FactionMetadata +import cc.fyre.hcf.map.sotw.SOTWHandler +import cc.fyre.hcf.timer.TimerHandler +import cc.fyre.modsuite.mod.ModHandler +import org.bukkit.ChatColor +import org.bukkit.GameMode +import org.bukkit.craftbukkit.v1_7_R4.entity.CraftVillager +import org.bukkit.entity.Player +import org.bukkit.entity.Projectile +import org.bukkit.event.EventHandler +import org.bukkit.event.EventPriority +import org.bukkit.event.Listener +import org.bukkit.event.entity.EntityDamageByEntityEvent +import org.bukkit.event.entity.EntityDeathEvent +import org.bukkit.event.entity.EntityInteractEvent +import org.bukkit.event.entity.EntityPortalEvent +import org.bukkit.event.player.PlayerInteractEntityEvent +import org.bukkit.event.player.PlayerJoinEvent +import org.bukkit.event.player.PlayerQuitEvent +import org.bukkit.event.world.ChunkUnloadEvent +import java.util.* + +/** + * @project hcf + * + * @date 13/09/2020 + * @author xanderume@gmail.com + */ +object CombatLoggerListener : Listener { + + @EventHandler(priority = EventPriority.NORMAL) + private fun onPlayerJoin(event: PlayerJoinEvent) { + CombatLoggerHandler.destroy(event.player) + } + + @EventHandler(priority = EventPriority.NORMAL) + private fun onChunkUnLoad(event: ChunkUnloadEvent) { + event.chunk.entities + .filter{!it.isDead && CombatLoggerHandler.isCombatLogger(it)} + .forEach{it.remove()} + } + + @EventHandler(priority = EventPriority.NORMAL) + private fun onEntityInteract(event: PlayerInteractEntityEvent) { + + if (!CombatLoggerHandler.isCombatLogger(event.rightClicked)) { + return + } + + event.isCancelled = true + } + + @EventHandler(priority = EventPriority.NORMAL) + private fun onEntityPortal(event: EntityPortalEvent) { + + if (!CombatLoggerHandler.isCombatLogger(event.entity)) { + return + } + + event.isCancelled = true + } + + @EventHandler(priority = EventPriority.NORMAL) + private fun onEntityInteract(event: EntityInteractEvent) { + + val logger = CombatLoggerHandler.getLoggerByEntityId(event.entity.entityId) ?: return + + val faction = FactionHandler.getFactionByLocation(event.block.location) + + if (faction is PlayerFaction && (faction.isRaidable() || faction.isMember(logger.getPlayerId()))) { + return + } + + if (FactionProtectionListener.DISALLOW_INTERACT.none{it == event.block.type}) { + return + } + + event.isCancelled = true + } + + @EventHandler(priority = EventPriority.HIGHEST) + private fun onEntityDamageByEntity(event: EntityDamageByEntityEvent) { + + if (event.isCancelled) { + return + } + + val logger = CombatLoggerHandler.getLoggerByEntityId(event.entity.entityId) ?: return + + var damager: Player? = null + + if (event.damager is Player) { + damager = event.damager as Player + } else if (event.damager is Projectile && (event.damager as Projectile).shooter is Player) { + damager = (event.damager as Projectile).shooter as Player + } + + if (damager == null) { + return + } + + if (FactionMetadata.SAFE_ZONE.isValidAtLocation(event.entity.location) || FactionMetadata.SAFE_ZONE.isValidAtLocation(damager.location)) { + event.isCancelled = true + return + } + + if (TimerHandler.hasTimer(damager.uniqueId,TimerType.PVP_TIMER)) { + damager.sendMessage("${ChatColor.RED}You cannot do this while your PvP Timer is active!") + damager.sendMessage("${ChatColor.RED}Type '${ChatColor.YELLOW}/pvp enable${ChatColor.RED}' to remove your timer.") + event.isCancelled = true + return + } + + if (SOTWHandler.isActive() && SOTWHandler.isProtected(damager)) { + damager.sendMessage("${ChatColor.RED}You cannot do this while your SOTW Timer is active!") + damager.sendMessage("${ChatColor.RED}Type '${ChatColor.YELLOW}/sotw enable${ChatColor.RED}' to remove your timer.") + event.isCancelled = true + return + } + + val id = logger.getPlayerId() + val faction = FactionHandler.getFactionByPlayer(damager.uniqueId) + + if (faction != null && faction.isMember(id)) { + damager.sendMessage("${ChatColor.YELLOW}You cannot hurt ${if (faction.isMember(id)) ChatColor.DARK_GREEN else Faction.ALLY_COLOR}${UUIDHandler.getUsernameById(id)}${ChatColor.YELLOW}.") + event.isCancelled = true + return + } + + TimerHandler.addTimer(damager.uniqueId,TimerType.SPAWN_TAG) + } + + @EventHandler(priority = EventPriority.NORMAL) + private fun onPlayerQuit(event: PlayerQuitEvent) { + + if (event.player.isDead) { + return + } + + if (CombatLoggerHandler.hasSafetyProtection(event.player.uniqueId)) { + return + } + + if (event.player.gameMode == GameMode.CREATIVE || ModHandler.isInModMode(event.player.uniqueId) || ModHandler.isInVanish(event.player.uniqueId)) { + return + } + + if (SOTWHandler.isActive() && SOTWHandler.isProtected(event.player)) { + return + } + + if (TimerHandler.hasTimer(event.player.uniqueId,TimerType.PVP_TIMER)) { + return + } + + if (FactionMetadata.SAFE_ZONE.isValidAtLocation(event.player.location)) { + return + } + + val radius = CombatLoggerHandler.RADIUS + val faction = FactionHandler.getFactionByPlayer(event.player.uniqueId) + + event.player.getNearbyEntities(radius,radius,radius).filterIsInstance().firstOrNull{ + + if (it.gameMode == GameMode.CREATIVE || ModHandler.isInModMode(it.uniqueId) || ModHandler.isInVanish(it.uniqueId)) { + return@firstOrNull false + } + + if (SOTWHandler.isActive() && SOTWHandler.isProtected(it)) { + return@firstOrNull false + } + + if (TimerHandler.hasTimer(it.uniqueId,TimerType.PVP_TIMER)) { + return@firstOrNull false + } + + if (FactionMetadata.SAFE_ZONE.isValidAtLocation(it.location)) { + return@firstOrNull false + } + + if (faction != null && faction.isMember(it)) { + return@firstOrNull false + } + + return@firstOrNull true + }?.also{CombatLoggerHandler.create(event.player)} + + } + + @EventHandler(priority = EventPriority.NORMAL) + private fun onEntityDeath(event: EntityDeathEvent) { + CombatLoggerHandler.getLoggerByEntityId(event.entity.entityId)?.handleDeath(event) + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/combatlogger/scheduler/CombatLoggerScheduler.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/combatlogger/scheduler/CombatLoggerScheduler.kt new file mode 100644 index 0000000..f5602b3 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/combatlogger/scheduler/CombatLoggerScheduler.kt @@ -0,0 +1,47 @@ +package cc.fyre.hcf.combatlogger.scheduler + +import cc.fyre.hcf.combatlogger.CombatLogger +import cc.fyre.shard.util.bukkit.NMSUtil +import cc.fyre.hcf.combatlogger.CombatLoggerHandler +import net.minecraft.server.v1_7_R4.EntityInsentient +import org.bukkit.ChatColor +import org.bukkit.World +import org.bukkit.entity.Entity +import org.bukkit.scheduler.BukkitRunnable +import java.util.* + +/** + * @project hcf + * + * @date 13/09/2020 + * @author xanderume@gmail.com + */ +class CombatLoggerScheduler(private val logger: CombatLogger) : BukkitRunnable() { + + var remaining = CombatLoggerHandler.SECONDS + + override fun run() { + + if (this.remaining == 0) { + this.cancel() + + CombatLoggerHandler.destroy(this.logger.getPlayer()) + + if (this.logger.bukkitEntity.isDead || !this.logger.bukkitEntity.isValid) { + return + } + + this.logger.destroy() + return + } + + if (this.logger.bukkitEntity.world.environment == World.Environment.THE_END && this.logger.bukkitEntity.location.blockY < 0) { + this.cancel() + this.logger.kill() + return + } + + this.remaining-- + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/death/Death.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/death/Death.kt new file mode 100644 index 0000000..8cb623b --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/death/Death.kt @@ -0,0 +1,78 @@ +package cc.fyre.hcf.death + +import cc.fyre.hcf.HCF +import cc.fyre.hcf.death.loadout.DeathLoadout +import com.squareup.moshi.Json +import com.squareup.moshi.JsonClass +import org.bukkit.entity.Player + +import java.util.* + +/** + * @project hcf + * + * @date 14/09/2020 + * @author xanderume@gmail.com + */ +@JsonClass(generateAdapter = true) +class Death( + @Json(name = "_id") + val id: UUID, + val player: UUID, + val reason: String +) { + + var loadout: DeathLoadout? = null + var deathBanTime = 0L + + constructor(id: UUID,player: Player,reason: String,killer: Player?):this(id,player.uniqueId,reason) { +// this.loadout = DeathLoadout(player) + + if (killer != null) { + this.killer = killer.uniqueId + //this.killerLoadout = DeathLoadout(killer) + } + + this.deathBanTime = DeathHandler.getBanTimeByPlayer(player) + } + + val time = System.currentTimeMillis() + + + var killer: UUID? = null + var killerLoadout: DeathLoadout? = null + + var reviver: UUID? = null + var revived: Long? = null + + var refunder: UUID? = null + var refunded: Long? = null + + + fun isRevived(): Boolean { + return this.reviver != null && this.revived != null + } + + fun setRevived(uuid: UUID) { + this.reviver = uuid + this.revived = System.currentTimeMillis() + } + + fun isRefunded(): Boolean { + return this.refunder != null && this.refunded != null + } + + fun setRefunded(uuid: UUID) { + this.refunder = uuid + this.refunded = System.currentTimeMillis() + } + + fun isActive():Boolean { + return this.reviver == null && this.revived == null && this.deathBanTime != 0L && (this.time + this.deathBanTime) - System.currentTimeMillis() > 0L + } + + fun getRemaining():Long { + return (this.time + this.deathBanTime) - System.currentTimeMillis() + } + +} diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/death/DeathHandler.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/death/DeathHandler.kt new file mode 100644 index 0000000..221769e --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/death/DeathHandler.kt @@ -0,0 +1,82 @@ +package cc.fyre.hcf.death + +import cc.fyre.core.profile.ProfileHandler +import cc.fyre.hcf.HCF +import cc.fyre.shard.util.item.ItemBuilder +import cc.fyre.hcf.faction.Faction +import cc.fyre.hcf.faction.FactionHandler +import cc.fyre.hcf.faction.FactionMetadata +import cc.fyre.hcf.faction.type.SystemFaction +import cc.fyre.hcf.game.GameHandler +import cc.fyre.hcf.map.MapHandler +import cc.fyre.hcf.map.sotw.SOTWHandler +import cc.fyre.hcf.statistic.StatisticHandler +import org.bukkit.ChatColor +import org.bukkit.Material +import org.bukkit.entity.Player +import org.bukkit.inventory.ItemStack +import java.util.* +import java.util.concurrent.TimeUnit + +/** + * @project hcf + * + * @date 14/09/2020 + * @author xanderume@gmail.com + */ +object DeathHandler { + + const val DEATH_SIGN_NAME = "§dDeath Sign" + + fun isDeathBanned(uuid: UUID):Boolean { + return StatisticHandler.getStatistic(uuid,DeathStatistic).getValue()?.isActive() ?: false + } + + fun getDeathSign(victim: Player,killer: Player):ItemStack { + + val lore = ArrayList() + + lore.add("${ChatColor.DARK_RED}${victim.name}") + lore.add("${ChatColor.YELLOW}Slain By:") + lore.add("${ChatColor.GREEN}${killer.name}") + + lore.add(GameHandler.DATE_FORMAT.format(Date()).replace(" AM","").replace(" PM","")) + + return ItemBuilder.of(Material.SIGN).name(DEATH_SIGN_NAME).lore(lore).build() + } + + fun getBanTimeByPlayer(player: Player):Long { + + if (player.isOp) { + return 0L + } + + if (SOTWHandler.isActive()) { + return TimeUnit.HOURS.toMillis(24L) + } + + val faction = FactionHandler.getFactionByLocation(player.location) + + if (faction is SystemFaction && faction.hasMetadata(FactionMetadata.SAFE_ZONE)) { + return 0L + } + + val rank = ProfileHandler.getProfileById(player.uniqueId)?.rank + + if (rank != null && rank.staff) { + return 0L + } + + var toReturn = if (rank == null) DEFAULT_DEATHBAN else MapHandler.config.deathBans[rank.name.lowercase()] ?: DEFAULT_DEATHBAN + + if (faction.getDeathbanStatus() == Faction.DeathbanStatus.NON_DEATHBAN && toReturn > NON_DEATHBAN_REGION_TIME) { + toReturn = NON_DEATHBAN_REGION_TIME + } + + return toReturn + } + + private val DEFAULT_DEATHBAN = TimeUnit.MINUTES.toMillis(60L) + + private const val NON_DEATHBAN_REGION_TIME = 15 * 60_000L +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/death/DeathModule.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/death/DeathModule.kt new file mode 100644 index 0000000..ec622c7 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/death/DeathModule.kt @@ -0,0 +1,41 @@ +package cc.fyre.hcf.death + +import cc.fyre.hcf.HCF +import cc.fyre.hcf.HCFModule +import cc.fyre.hcf.death.command.DeathsCommand +import cc.fyre.hcf.death.command.KillsCommand +import cc.fyre.hcf.death.command.LastInvCommand +import cc.fyre.hcf.death.command.ReviveCommand +import cc.fyre.hcf.death.listener.DeathListener +import cc.fyre.hcf.statistic.StatisticRegistry +import cc.fyre.shard.command.data.parameter.ParameterAdapter +import org.bukkit.event.Listener + +object DeathModule : HCFModule { + + override fun init(core: HCF) { + StatisticRegistry.register(DeathStatistic) + } + + override fun shutdown(core: HCF) {} + + override fun getCommands(): List> { + return listOf( + KillsCommand::class.java, + DeathsCommand::class.java, + ReviveCommand::class.java, + LastInvCommand::class.java, + ) + } + + override fun getAdapters(): Map, ParameterAdapter<*>> { + return mapOf() + } + + override fun getListeners(): List { + return listOf( + DeathListener + ) + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/death/DeathRepository.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/death/DeathRepository.kt new file mode 100644 index 0000000..8261abc --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/death/DeathRepository.kt @@ -0,0 +1,91 @@ +package cc.fyre.hcf.death + +import cc.fyre.hcf.HCF +import cc.fyre.hcf.death.Death +import cc.fyre.hcf.statistic.StatisticHandler +import cc.fyre.shard.moshi.MoshiUtil +import cc.fyre.shard.util.MongoUtil +import com.mongodb.client.MongoCollection +import com.mongodb.client.model.Filters +import net.minecraft.util.com.google.common.cache.CacheBuilder +import org.bson.Document +import java.util.* +import java.util.concurrent.TimeUnit + +/** + * @project hcf + * + * @date 16/11/2020 + * @author xanderume@gmail.com + */ +object DeathRepository { + + private val deathsByPlayer = CacheBuilder.newBuilder() + .expireAfterAccess(10L,TimeUnit.MINUTES) + .build>() + + private val deathsByKiller = CacheBuilder.newBuilder() + .expireAfterAccess(10L,TimeUnit.MINUTES) + .build>() + + private val collection: MongoCollection = HCF.instance.getMongoDB().getCollection("deaths") + + fun deleteAll() { + + for (entry in StatisticHandler.getAllStatistics(DeathStatistic)) { + + if (entry.value.getValue() == null) { + continue + } + + StatisticHandler.setStatistic(entry.key,DeathStatistic,null) + } + + this.collection.drop() + } + + fun updateById(death: Death) { + this.collection.updateOne( + Filters.eq("_id",death.id.toString()), + Document("\$set",Document.parse(MoshiUtil.instance.adapter(Death::class.java).toJson(death))), + MongoUtil.UPDATE_OPTIONS + ) + + if (death.killer != null) { + this.deathsByKiller.getIfPresent(death.killer!!)?.add(death) + } + + this.deathsByPlayer.getIfPresent(death.player)?.add(death) + } + + fun findAllByPlayer(player: UUID):List { + + var toReturn = this.deathsByPlayer.getIfPresent(player)?.toList() + + if (toReturn == null) { + val adapter = MoshiUtil.instance.adapter(Death::class.java) + + toReturn = this.collection.find(Filters.eq("player",player.toString())) + .mapNotNull{adapter.fromJson(it.toJson(MongoUtil.RELAXED_WRITE_SETTING))} + .toList() + } + + return toReturn + } + + fun findAllByKiller(killer: UUID):List { + + var toReturn = this.deathsByKiller.getIfPresent(killer)?.toList() + + if (toReturn == null) { + val adapter = MoshiUtil.instance.adapter(Death::class.java) + + toReturn = this.collection.find(Filters.and(Filters.exists("killer"),Filters.eq("killer",killer.toString()))) + .mapNotNull{adapter.fromJson(it.toJson(MongoUtil.RELAXED_WRITE_SETTING))} + .toList() + } + + return toReturn + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/death/DeathStatistic.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/death/DeathStatistic.kt new file mode 100644 index 0000000..aa636a0 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/death/DeathStatistic.kt @@ -0,0 +1,75 @@ +package cc.fyre.hcf.death + +import cc.fyre.core.profile.Profile +import cc.fyre.hcf.statistic.Statistic +import cc.fyre.hcf.statistic.StatisticOption +import cc.fyre.hcf.statistic.StatisticValue +import cc.fyre.shard.moshi.MoshiUtil +import cc.fyre.shard.util.MongoUtil +import org.bson.Document + +object DeathStatistic : Statistic() { + + override fun getKey(): String { + return "deathban" + } + + override fun getOptions(): List> { + return listOf() + } + + override fun getDefaultValue(): StatisticValue { + return object : StatisticValue { + + override fun getValue(): Death? { + return null + } + + } + } + + override fun getDisplayName(value: Death?): String { + return "" + } + + override fun isSetting(): Boolean { + return false + } + + override fun hasPermission(profile: Profile,value: Death?): Boolean { + return true + } + + override fun getName(): String { + return "" + } + + override fun getNextValue(value: Death?): Death? { + return null + } + + override fun toBson(document: Document,value: Any) { + + if (value !is Death) { + return + } + + document.append(this.getKey(),Document.parse(MoshiUtil.instance.adapter(Death::class.java).toJson(value))) + } + + override fun fromBson(document: Document): StatisticValue { + return object : StatisticValue { + + override fun getValue(): Death? { + + if (!document.containsKey(this@DeathStatistic.getKey())) { + return null + } + + return MoshiUtil.instance.adapter(Death::class.java).fromJson(document.get(this@DeathStatistic.getKey(),Document::class.java).toJson(MongoUtil.RELAXED_WRITE_SETTING)) + } + + } + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/death/command/DeathsCommand.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/death/command/DeathsCommand.kt new file mode 100644 index 0000000..9bd2ce9 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/death/command/DeathsCommand.kt @@ -0,0 +1,25 @@ +package cc.fyre.hcf.death.command + +import cc.fyre.shard.command.data.command.Command +import cc.fyre.shard.command.data.parameter.Parameter +import cc.fyre.hcf.HCF +import cc.fyre.hcf.death.DeathRepository +import cc.fyre.hcf.death.menu.DeathsMenu +import org.bukkit.entity.Player +import java.util.* + +/** + * @project hcf + * + * @date 18/09/2020 + * @author xanderume@gmail.com + */ +object DeathsCommand { + + @JvmStatic + @Command(names = ["deaths","refund"],async = true,permission = "hcf.command.deaths") + fun execute(player: Player,@Parameter(name = "player")uuid: UUID) { + DeathsMenu(uuid,DeathRepository.findAllByPlayer(uuid)).open(player) + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/death/command/KillsCommand.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/death/command/KillsCommand.kt new file mode 100644 index 0000000..725d76c --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/death/command/KillsCommand.kt @@ -0,0 +1,25 @@ +package cc.fyre.hcf.death.command + +import cc.fyre.shard.command.data.command.Command +import cc.fyre.shard.command.data.parameter.Parameter +import cc.fyre.hcf.HCF +import cc.fyre.hcf.death.DeathRepository +import cc.fyre.hcf.death.menu.DeathsMenu +import org.bukkit.entity.Player +import java.util.* + +/** + * @project hcf + * + * @date 17/11/2020 + * @author xanderume@gmail.com + */ +object KillsCommand { + + @JvmStatic + @Command(names = ["kills"],async = true,permission = "hcf.command.kills") + fun execute(player: Player,@Parameter(name = "player")uuid: UUID) { + DeathsMenu(uuid,DeathRepository.findAllByKiller(uuid)).open(player) + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/death/command/LastInvCommand.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/death/command/LastInvCommand.kt new file mode 100644 index 0000000..f08c97d --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/death/command/LastInvCommand.kt @@ -0,0 +1,40 @@ +package cc.fyre.hcf.death.command + +import cc.fyre.shard.command.data.command.Command +import cc.fyre.shard.command.data.parameter.Parameter +import cc.fyre.hcf.HCF +import cc.fyre.core.profile.ProfileHandler +import cc.fyre.hcf.death.DeathStatistic +import cc.fyre.hcf.statistic.StatisticHandler +import org.bukkit.ChatColor +import org.bukkit.entity.Player +import java.util.* + +/** + * @project hcf + * + * @date 28/11/2020 + * @author xanderume@gmail.com + */ +object LastInvCommand { + + @JvmStatic + @Command(names = ["lastinv"],permission = "hcf.command.lastinv") + fun execute(player: Player,@Parameter(name = "player")uuid: UUID) { + + val death = StatisticHandler.getStatistic(uuid,DeathStatistic).getValue() + + if (death?.loadout == null) { + player.sendMessage("${ChatColor.RED}No last inventory found for ${ProfileHandler.getDisplayNameById(uuid)}${ChatColor.RED}.") + return + } + + player.inventory.contents = death.loadout!!.contents.toTypedArray() + player.inventory.armorContents = death.loadout!!.armor.toTypedArray() + + player.activePotionEffects.forEach{player.removePotionEffect(it.type)} + + player.updateInventory() + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/death/command/ReviveCommand.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/death/command/ReviveCommand.kt new file mode 100644 index 0000000..1b4ab22 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/death/command/ReviveCommand.kt @@ -0,0 +1,70 @@ +package cc.fyre.hcf.death.command + +import cc.fyre.shard.command.data.command.Command +import cc.fyre.shard.command.data.parameter.Parameter +import cc.fyre.hcf.HCF + +import cc.fyre.core.uuid.UUIDHandler +import cc.fyre.hcf.death.DeathRepository +import cc.fyre.hcf.death.DeathStatistic +import cc.fyre.hcf.map.eotw.EOTWHandler +import cc.fyre.hcf.statistic.StatisticHandler +import cc.fyre.hcf.statistic.type.LivesStatistic +import org.bukkit.ChatColor +import org.bukkit.command.CommandSender +import org.bukkit.entity.Player +import java.util.* + +/** + * @project hcf + * + * @date 16/09/2020 + * @author xanderume@gmail.com + */ +object ReviveCommand { + + const val MOD_PERMISSION = "hcf.command.revive.advanced" + + @JvmStatic + @Command(names = ["revive","pvp revive","lives revive"],async = true) + fun execute(sender: CommandSender,@Parameter(name = "player")uuid: UUID) { + + var lives = 0 + + if (sender is Player && !sender.hasPermission(MOD_PERMISSION)) { + + if (EOTWHandler.isActive()) { + sender.sendMessage("${ChatColor.RED}You cannot use lives during EOTW.") + return + } + + lives = StatisticHandler.getStatistic(sender.uniqueId,LivesStatistic).getValue() + + if (lives <= 0) { + sender.sendMessage("${ChatColor.RED}You have no lives!") + return + } + + } + + val name = UUIDHandler.getUsernameById(uuid) + val death = StatisticHandler.getStatistic(uuid,DeathStatistic).getValue() + + if (death == null || !death.isActive()) { + sender.sendMessage("${ChatColor.RED}$name is not death-banned!") + return + } + + if (sender is Player && !sender.hasPermission(MOD_PERMISSION) && lives > 0) { + StatisticHandler.increaseStatistic(sender.uniqueId,LivesStatistic,-1) + } + + death.setRevived(if (sender is Player) sender.uniqueId else UUIDHandler.CONSOLE_ID) + + DeathRepository.updateById(death) + StatisticHandler.setStatistic(uuid,DeathStatistic,death) + + sender.sendMessage("${ChatColor.YELLOW}Revived ${ChatColor.LIGHT_PURPLE}$name${ChatColor.YELLOW}!") + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/death/listener/DeathListener.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/death/listener/DeathListener.kt new file mode 100644 index 0000000..46a516b --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/death/listener/DeathListener.kt @@ -0,0 +1,129 @@ +package cc.fyre.hcf.death.listener + +import cc.fyre.core.server.ServerModule +import cc.fyre.core.server.message.ServerMessageType +import cc.fyre.shard.util.TimeUtil +import cc.fyre.hcf.HCF +import cc.fyre.hcf.death.Death +import cc.fyre.hcf.death.DeathHandler +import cc.fyre.hcf.death.DeathRepository +import cc.fyre.hcf.death.DeathStatistic +import cc.fyre.hcf.statistic.StatisticHandler +import cc.fyre.hcf.statistic.type.LivesStatistic + +import cc.fyre.shard.util.bungee.BungeeUtil +import org.bukkit.Bukkit +import org.bukkit.ChatColor +import org.bukkit.Material +import org.bukkit.block.Sign +import org.bukkit.event.EventHandler +import org.bukkit.event.EventPriority +import org.bukkit.event.Listener +import org.bukkit.event.block.BlockPlaceEvent +import org.bukkit.event.entity.PlayerDeathEvent +import org.bukkit.event.player.AsyncPlayerPreLoginEvent +import org.bukkit.event.player.PlayerRespawnEvent +import java.util.* +import java.util.function.Predicate + +/** + * @project hcf + * + * @date 14/09/2020 + * @author xanderume@gmail.com + */ +object DeathListener : Listener { + + @EventHandler(priority = EventPriority.HIGHEST) + private fun onAsyncPreLogin(event: AsyncPlayerPreLoginEvent) { + + if (HCF.instance.isKitMap()) { + return + } + + val death = StatisticHandler.getStatistic(event.uniqueId,DeathStatistic).getValue() + + if (death == null || !death.isActive()) { + return + } + + val lives = StatisticHandler.getStatistic(event.uniqueId,LivesStatistic).getValue() + + if (lives != 0) { + StatisticHandler.increaseStatistic(event.uniqueId,LivesStatistic,-1) + return + } + + event.disallow(AsyncPlayerPreLoginEvent.Result.KICK_OTHER,"${ChatColor.YELLOW}Come back in ${ChatColor.GOLD}${TimeUtil.formatIntoDetailedString(death.getRemaining())}${ChatColor.YELLOW}!") + } + + @EventHandler(priority = EventPriority.HIGHEST) + private fun onPlayerDeath(event: PlayerDeathEvent) { + + val death = Death(UUID.randomUUID(),event.entity,event.deathMessage,event.entity.killer) + + if (event.entity.killer != null) { + event.entity.world.dropItemNaturally(event.entity.location,DeathHandler.getDeathSign(event.entity,event.entity.killer)) + } + + StatisticHandler.setStatistic(event.entity.uniqueId,DeathStatistic,death) + + Bukkit.getServer().scheduler.runTaskAsynchronously(HCF.instance) { + DeathRepository.updateById(death) + } + + } + + @EventHandler(priority = EventPriority.MONITOR) + private fun onPlayerRespawn(event: PlayerRespawnEvent) { + + if (HCF.instance.isKitMap()) { + return + } + + val death = StatisticHandler.getStatistic(event.player.uniqueId,DeathStatistic).getValue() + + if (death == null || !death.isActive()) { + return + } + + ServerModule.sendToBungee(event.player,ServerMessageType.SEND_TO_HUB,Predicate{ + return@Predicate true + }) + + event.player.sendMessage("${ChatColor.YELLOW}Come back in ${ChatColor.GOLD}${TimeUtil.formatIntoDetailedString(death.getRemaining())}${ChatColor.YELLOW}!") + } + + @EventHandler(priority = EventPriority.MONITOR) + private fun onBlockPlace(event: BlockPlaceEvent) { + + if (event.isCancelled) { + return + } + + val item = event.player.itemInHand + + if (!(item.type == Material.SIGN_POST || item.type == Material.WALL_SIGN)) { + return + } + + if (!item.hasItemMeta() || !item.itemMeta.hasDisplayName() || item.itemMeta.displayName != DeathHandler.DEATH_SIGN_NAME || !item.itemMeta.hasLore()) { + return + } + + val lore = item.itemMeta.lore + val state = event.block.state as Sign + + for (i in 0..3) { + + if (i > lore.lastIndex) { + break + } + + state.setLine(i,lore[i]) + } + + state.update(true) + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/death/listener/DeathPacketListener.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/death/listener/DeathPacketListener.kt new file mode 100644 index 0000000..f4061dd --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/death/listener/DeathPacketListener.kt @@ -0,0 +1,42 @@ +package cc.fyre.hcf.death.listener + +import cc.fyre.circuit.data.Packet +import cc.fyre.circuit.data.PacketListener +import cc.fyre.circuit.data.PacketPriority +import cc.fyre.core.server.ServerModule +import cc.fyre.hcf.HCF +import cc.fyre.hcf.statistic.StatisticHandler +import cc.fyre.hcf.statistic.type.LivesStatistic +import cc.fyre.shard.moshi.json.JsonObject +import java.util.* + +/** + * @project hcf + * + * @date 19/11/2020 + * @author xanderume@gmail.com + */ +object DeathPacketListener : PacketListener { + + /*TODO + @Packet(id = "HCF_LIFE_USE",priority = PacketPriority.LOWEST,forceLocal = true) + fun onUseLife(data: JsonObject) { + + if (!ServerModule.getServerId().equals(data.getString("server"),true)) { + return + } + + val uuid = UUID.fromString(data.getString("_id")) + val death = this.instance.deathHandler.cache[uuid] + + // should never really be null but just in case + if (death != null) { + death.setRevived(uuid) + + this.instance.deathHandler.repository.update(death) + } + + StatisticHandler.increaseStatistic(uuid,LivesStatistic,-1) + }*/ + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/death/loadout/DeathLoadout.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/death/loadout/DeathLoadout.kt new file mode 100644 index 0000000..9333185 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/death/loadout/DeathLoadout.kt @@ -0,0 +1,18 @@ +package cc.fyre.hcf.death.loadout + +import com.squareup.moshi.JsonClass +import org.bukkit.entity.Player +import org.bukkit.inventory.ItemStack + +/** + * @project hcf + * + * @date 16/11/2020 + * @author xanderume@gmail.com + */ +@JsonClass(generateAdapter = true) +data class DeathLoadout(val armor: List, val contents: List, val health: Double, val foodLevel: Int) { + + constructor(player: Player):this(player.inventory.armorContents.filterNotNull().toList(),player.inventory.contents.filterNotNull().toList(),player.health,player.foodLevel) + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/death/menu/DeathsMenu.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/death/menu/DeathsMenu.kt new file mode 100644 index 0000000..a643235 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/death/menu/DeathsMenu.kt @@ -0,0 +1,35 @@ +package cc.fyre.hcf.death.menu + +import cc.fyre.hcf.death.Death +import cc.fyre.hcf.death.menu.element.DeathElement +import cc.fyre.shard.menu.button.Button +import cc.fyre.shard.menu.type.paginated.PaginatedMenu +import org.bukkit.entity.Player +import java.util.* +import kotlin.collections.HashMap + +/** + * @project hcf + * + * @date 18/09/2020 + * @author xanderume@gmail.com + */ +class DeathsMenu(private val id: UUID,private val deaths: Collection) : PaginatedMenu() { + + override fun getTitle(player: Player): String { + return "Deaths" + } + + override fun getButtonsPerPage(player: Player): Int { + return 3*9 + } + + override fun getPagedButtons(player: Player): HashMap { + return this.deaths + .sortedByDescending{it.time} + .withIndex() + .associate{it.index to DeathElement(it.value)} + .toMap(HashMap()) + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/death/menu/DeathsRefundMenu.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/death/menu/DeathsRefundMenu.kt new file mode 100644 index 0000000..83c95cb --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/death/menu/DeathsRefundMenu.kt @@ -0,0 +1,43 @@ +package cc.fyre.hcf.death.menu + +import cc.fyre.hcf.death.Death +import cc.fyre.hcf.death.menu.element.DeathRefundElement +import cc.fyre.hcf.death.menu.element.DeathReviveElement +import cc.fyre.shard.menu.Menu +import cc.fyre.shard.menu.button.Button +import org.bukkit.entity.Player + +/** + * @project hcf + * + * @date 19/09/2020 + * @author xanderume@gmail.com + */ +class DeathsRefundMenu(private val death: Death) : Menu() { + + override fun getSize(player: Player, buttons: Map): Int { + return 5*9 + } + + override fun getTitle(player: Player): String { + return "Refund" + } + + override fun getButtons(player: Player): MutableMap { + + val toReturn = mutableMapOf() + + this.death.loadout!!.contents.forEach{toReturn[toReturn.size] = Button.fromItem(it.clone())} + this.death.loadout!!.armor.withIndex().reversed().forEach{toReturn[36 + it.index] = Button.fromItem(it.value.clone())} + + toReturn[44] = DeathRefundElement(this.death) + toReturn[43] = DeathReviveElement(this.death) + + return toReturn + } + + override fun isFill(player: Player, buttons: Map): Boolean { + return true + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/death/menu/element/DeathElement.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/death/menu/element/DeathElement.kt new file mode 100644 index 0000000..4e5cb37 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/death/menu/element/DeathElement.kt @@ -0,0 +1,82 @@ +package cc.fyre.hcf.death.menu.element + +import cc.fyre.shard.util.TimeUtil +import cc.fyre.shard.util.item.ItemBuilder +import cc.fyre.hcf.death.Death +import cc.fyre.hcf.death.menu.DeathsRefundMenu +import cc.fyre.core.uuid.UUIDHandler +import cc.fyre.shard.menu.button.Button +import org.apache.commons.lang.StringUtils +import org.bukkit.ChatColor +import org.bukkit.DyeColor +import org.bukkit.Material +import org.bukkit.entity.Player +import org.bukkit.event.inventory.InventoryClickEvent +import org.bukkit.inventory.ItemStack +import java.util.* +import kotlin.collections.ArrayList + +/** + * @project hcf + * + * @date 18/09/2020 + * @author xanderume@gmail.com + */ +class DeathElement(private val death: Death) : Button() { + + override fun getItem(player: Player): ItemStack { + + var color = DyeColor.RED + + if (this.death.isActive()) { + color = DyeColor.GREEN + } else { + + if (!this.death.isRefunded()) { + color = DyeColor.YELLOW + } + + } + + val lore = ArrayList() + + lore.add("${ChatColor.GRAY}${ChatColor.STRIKETHROUGH}${StringUtils.repeat("-",18)}") + lore.add("${ChatColor.YELLOW}Reason: ${ChatColor.RED}${ChatColor.stripColor(this.death.reason)}") + + if (this.death.deathBanTime != 0L) { + lore.add("${ChatColor.YELLOW}Duration: ${ChatColor.RED}${TimeUtil.formatIntoDetailedString(this.death.deathBanTime)}") + } + + if (this.death.isRevived()) { + lore.add("${ChatColor.GRAY}${ChatColor.STRIKETHROUGH}${StringUtils.repeat("-",18)}") + lore.add("${ChatColor.RED}${ChatColor.BOLD}Revived") + lore.add(" ") + lore.add("${ChatColor.YELLOW}By: ${ChatColor.RED}${UUIDHandler.getUsernameById(this.death.reviver!!)}") + lore.add(" ") + lore.add("${ChatColor.GOLD}${TimeUtil.formatIntoCalendarString(Date(this.death.revived!!))}") + } + + if (this.death.isRefunded()) { + lore.add("${ChatColor.GRAY}${ChatColor.STRIKETHROUGH}${StringUtils.repeat("-",18)}") + lore.add("${ChatColor.RED}${ChatColor.BOLD}Refunded") + lore.add(" ") + lore.add("${ChatColor.YELLOW}By: ${ChatColor.RED}${UUIDHandler.getUsernameById(this.death.refunder!!)}") + lore.add(" ") + lore.add("${ChatColor.GOLD}${TimeUtil.formatIntoCalendarString(Date(this.death.refunded!!))}") + } + + if (!this.death.isRefunded()) { + lore.add("${ChatColor.GRAY}${ChatColor.STRIKETHROUGH}${StringUtils.repeat("-",18)}") + lore.add("${ChatColor.RED}Click to refund.") + } + + lore.add("${ChatColor.GRAY}${ChatColor.STRIKETHROUGH}${StringUtils.repeat("-",18)}") + + return ItemBuilder.of(Material.WOOL).name("${ChatColor.GOLD}${TimeUtil.formatIntoCalendarString(Date(this.death.time))}").data(color.woolData.toShort()).lore(lore).build() + } + + override fun onClick(player: Player,event: InventoryClickEvent) { + DeathsRefundMenu(this.death).open(player) + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/death/menu/element/DeathRefundElement.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/death/menu/element/DeathRefundElement.kt new file mode 100644 index 0000000..90c91ab --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/death/menu/element/DeathRefundElement.kt @@ -0,0 +1,56 @@ +package cc.fyre.hcf.death.menu.element + +import cc.fyre.shard.util.item.ItemBuilder +import cc.fyre.hcf.HCF +import cc.fyre.hcf.death.Death +import cc.fyre.core.uuid.UUIDHandler +import cc.fyre.hcf.death.DeathRepository +import cc.fyre.hcf.death.DeathStatistic +import cc.fyre.hcf.statistic.StatisticHandler +import cc.fyre.shard.menu.button.Button +import org.bukkit.Bukkit +import org.bukkit.ChatColor +import org.bukkit.Material +import org.bukkit.entity.Player +import org.bukkit.event.inventory.InventoryClickEvent +import org.bukkit.inventory.ItemStack + +/** + * @project hcf + * + * @date 19/09/2020 + * @author xanderume@gmail.com + */ +class DeathRefundElement(private val death: Death) : Button() { + + override fun getItem(player: Player): ItemStack { + return ItemBuilder.of(if (this.death.isRefunded()) Material.MINECART else Material.STORAGE_MINECART).name("${if (this.death.isRefunded()) ChatColor.RED else ChatColor.GREEN}${ChatColor.BOLD}Refund Inventory").build() + } + + override fun onClick(player: Player,event: InventoryClickEvent) { + + if (this.death.isRefunded()) { + player.sendMessage("${ChatColor.RED}This inventory has already been refunded.") + return + } + + val target = HCF.instance.server.getPlayer(this.death.player) + + if (target == null) { + player.sendMessage("${ChatColor.RED}${UUIDHandler.getUsernameById(this.death.player)} is not online.") + return + } + + target.inventory.contents = this.death.loadout!!.contents.toTypedArray() + target.inventory.armorContents = this.death.loadout!!.armor.toTypedArray() + + this.death.setRefunded(player.uniqueId) + + Bukkit.getServer().scheduler.runTaskAsynchronously(HCF.instance) { + DeathRepository.updateById(this.death) + } + + player.sendMessage("${ChatColor.GREEN}Refunded Inventory.") + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/death/menu/element/DeathReviveElement.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/death/menu/element/DeathReviveElement.kt new file mode 100644 index 0000000..7f9b78e --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/death/menu/element/DeathReviveElement.kt @@ -0,0 +1,57 @@ +package cc.fyre.hcf.death.menu.element + +import cc.fyre.hcf.HCF +import cc.fyre.shard.util.item.ItemBuilder +import cc.fyre.hcf.death.Death +import cc.fyre.hcf.death.DeathRepository +import cc.fyre.hcf.death.DeathStatistic +import cc.fyre.hcf.statistic.StatisticHandler +import cc.fyre.shard.menu.button.Button +import org.bukkit.Bukkit +import org.bukkit.ChatColor +import org.bukkit.Material +import org.bukkit.entity.Player +import org.bukkit.event.inventory.InventoryClickEvent +import org.bukkit.inventory.ItemStack + +/** + * @project hcf + * + * @date 19/09/2020 + * @author xanderume@gmail.com + */ +class DeathReviveElement(private val death: Death) : Button() { + + override fun getItem(player: Player): ItemStack { + return ItemBuilder.of(Material.BED).name("${if (this.death.isRevived()) ChatColor.RED else ChatColor.GREEN}${ChatColor.BOLD}Revive").build() + } + + override fun onClick(player: Player,event: InventoryClickEvent) { + + if (!this.death.isActive()) { + player.sendMessage("${ChatColor.RED}This death has already expired.") + return + } + + if (this.death.isRevived()) { + player.sendMessage("${ChatColor.RED}This death has already been revived.") + return + } + + + this.death.setRevived(event.whoClicked.uniqueId) + + Bukkit.getServer().scheduler.runTaskAsynchronously(HCF.instance) { + + if (StatisticHandler.getStatistic(player.uniqueId, DeathStatistic).getValue()?.id == this.death.id) { + StatisticHandler.setStatistic(this.death.player, DeathStatistic,this.death) + } + + DeathRepository.updateById(this.death) + } + + player.sendMessage("${ChatColor.GREEN}Revived.") + return + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/deathmessage/Damage.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/deathmessage/Damage.kt new file mode 100644 index 0000000..217f58c --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/deathmessage/Damage.kt @@ -0,0 +1,32 @@ +package cc.fyre.hcf.deathmessage + +import cc.fyre.shard.util.entity.EntityUtil +import org.apache.commons.lang.WordUtils +import org.bukkit.ChatColor +import org.bukkit.Material +import org.bukkit.entity.Entity +import org.bukkit.entity.EntityType +import org.bukkit.entity.Player +import java.util.* + +/** + * @project engine + * + * @date 15/08/2020 + * @author xanderume@gmail.com + */ +abstract class Damage(val uuid: UUID,val damage: Double) { + + val time = System.currentTimeMillis() + + fun getFormattedMessage(uuid: UUID):String { + return "${DeathMessageHandler.getFormat(uuid)}${ChatColor.YELLOW} ${this.getDeathMessage(uuid)}${ChatColor.YELLOW}." + } + + abstract fun getDeathMessage(uuid: UUID):String + + fun getTimeAgo():Long { + return System.currentTimeMillis() - this.time + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/deathmessage/DeathMessageHandler.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/deathmessage/DeathMessageHandler.kt new file mode 100644 index 0000000..2b4965a --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/deathmessage/DeathMessageHandler.kt @@ -0,0 +1,59 @@ +package cc.fyre.hcf.deathmessage + +import cc.fyre.core.uuid.UUIDHandler +import cc.fyre.hcf.statistic.StatisticHandler +import cc.fyre.hcf.statistic.type.KillsStatistic +import net.minecraft.util.com.google.common.cache.CacheBuilder +import org.bukkit.ChatColor +import org.bukkit.entity.Player + +import java.util.* +import java.util.concurrent.TimeUnit +import kotlin.collections.ArrayList + +/** + * @project engine + * + * @date 15/08/2020 + * @author xanderume@gmail.com + */ +object DeathMessageHandler { + + private val damage = CacheBuilder.newBuilder() + .expireAfterAccess(10L,TimeUnit.MINUTES) + .build>() + + fun create(player: Player) { + this.damage.put(player.uniqueId,arrayListOf()) + } + + fun destroy(player: Player) { + this.damage.invalidate(player) + } + + fun getAllDamageByPlayer(player: Player):List? { + return this.damage.getIfPresent(player.uniqueId) + } + + fun addDamageByPlayer(player: Player,damage: Damage) { + + var cache = this.damage.getIfPresent(player.uniqueId) + + if (cache == null) { + cache = arrayListOf() + this.damage.put(player.uniqueId,cache) + } + + if (cache.size > MAX_ENTRIES) { + cache = cache.toTypedArray().copyOfRange(0,MAX_ENTRIES - 1).toCollection(arrayListOf()) + } + + cache.add(0,damage) + } + + fun getFormat(uuid: UUID): String { + return "${ChatColor.RED}${UUIDHandler.getUsernameById(uuid)}${ChatColor.DARK_RED}[${StatisticHandler.getStatistic(uuid,KillsStatistic).getValue()}]" + } + + private const val MAX_ENTRIES = 30 +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/deathmessage/DeathMessageModule.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/deathmessage/DeathMessageModule.kt new file mode 100644 index 0000000..7e75557 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/deathmessage/DeathMessageModule.kt @@ -0,0 +1,39 @@ +package cc.fyre.hcf.deathmessage + +import cc.fyre.hcf.HCF +import cc.fyre.hcf.HCFModule +import cc.fyre.hcf.deathmessage.listener.DeathMessageListener +import cc.fyre.hcf.deathmessage.tracker.* +import cc.fyre.shard.command.data.parameter.ParameterAdapter +import org.bukkit.event.Listener + +object DeathMessageModule : HCFModule { + + override fun init(core: HCF) { + } + + override fun shutdown(core: HCF) { + } + + override fun getCommands(): List> { + return listOf() + } + + override fun getAdapters(): Map, ParameterAdapter<*>> { + return mapOf() + } + + override fun getListeners(): List { + return listOf( + PvPTracker, + BurnTracker, + FallTracker, + VoidTracker, + ArrowTracker, + EntityTracker, + GeneralTracker, + DeathMessageListener + ) + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/deathmessage/event/PlayerDamageEvent.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/deathmessage/event/PlayerDamageEvent.kt new file mode 100644 index 0000000..d7849ae --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/deathmessage/event/PlayerDamageEvent.kt @@ -0,0 +1,29 @@ +package cc.fyre.hcf.deathmessage.event + +import cc.fyre.hcf.deathmessage.Damage +import org.bukkit.entity.Player +import org.bukkit.event.HandlerList +import org.bukkit.event.entity.EntityDamageEvent +import org.bukkit.event.player.PlayerEvent + +/** + * @project engine + * + * @date 15/08/2020 + * @author xanderume@gmail.com + */ +class PlayerDamageEvent(val event: EntityDamageEvent,var damage: Damage) : PlayerEvent(event.entity as Player) { + + fun getDamage():Double { + return this.event.getDamage(EntityDamageEvent.DamageModifier.BASE) + } + + override fun getHandlers(): HandlerList { + return handlerList + } + + companion object { + @JvmStatic val handlerList = HandlerList() + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/deathmessage/listener/DeathMessageListener.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/deathmessage/listener/DeathMessageListener.kt new file mode 100644 index 0000000..d3196f3 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/deathmessage/listener/DeathMessageListener.kt @@ -0,0 +1,104 @@ +package cc.fyre.hcf.deathmessage.listener + +import cc.fyre.hcf.HCF +import cc.fyre.hcf.deathmessage.Damage +import cc.fyre.hcf.deathmessage.DeathMessageHandler +import cc.fyre.hcf.deathmessage.event.PlayerDamageEvent +import cc.fyre.hcf.deathmessage.type.PlayerDamage +import cc.fyre.hcf.deathmessage.type.UnknownDamage +import cc.fyre.hcf.faction.FactionHandler +import cc.fyre.hcf.statistic.StatisticHandler +import cc.fyre.hcf.statistic.type.setting.DeathMessageSetting +import org.bukkit.Bukkit +import org.bukkit.craftbukkit.v1_7_R4.entity.CraftPlayer +import org.bukkit.entity.Player +import org.bukkit.event.EventHandler +import org.bukkit.event.EventPriority +import org.bukkit.event.Listener +import org.bukkit.event.entity.EntityDamageEvent +import org.bukkit.event.entity.PlayerDeathEvent +import org.bukkit.event.player.PlayerJoinEvent +import org.bukkit.event.player.PlayerQuitEvent +import java.util.concurrent.TimeUnit + +/** + * @project engine + * + * @date 15/08/2020 + * @author xanderume@gmail.com + */ +object DeathMessageListener : Listener { + + @EventHandler(priority = EventPriority.NORMAL) + private fun onPlayerJoin(event: PlayerJoinEvent) { + DeathMessageHandler.create(event.player) + } + + @EventHandler(priority = EventPriority.MONITOR) + private fun onPlayerDamage(event: PlayerDamageEvent) { + DeathMessageHandler.addDamageByPlayer(event.player,event.damage) + } + + @EventHandler(priority = EventPriority.MONITOR,ignoreCancelled = true) + private fun onEntityDamage(event: EntityDamageEvent) { + + if (event.entity !is Player) { + return + } + + Bukkit.getServer().pluginManager.callEvent(PlayerDamageEvent(event,UnknownDamage(event.entity.uniqueId,event.getDamage(EntityDamageEvent.DamageModifier.BASE)))) + } + + @EventHandler(priority = EventPriority.LOWEST) + private fun onPlayerDeath(event: PlayerDeathEvent) { + + var damage = DeathMessageHandler.getAllDamageByPlayer(event.entity)?.firstOrNull() + + if (damage == null) { + damage = UnknownDamage(event.entity.uniqueId,1.0) + } + + event.deathMessage = damage.getFormattedMessage(event.entity.uniqueId) + + if (damage !is PlayerDamage) { + return + } + + if (damage.getTimeAgo() > TimeUnit.MINUTES.toMillis(1L)) { + return + } + + val damager = Bukkit.getServer().getPlayer(damage.attacker) ?: return + + (event.entity as CraftPlayer).handle.killer = (damager as CraftPlayer).handle + } + + @EventHandler(priority = EventPriority.MONITOR) + private fun onBroadcastMessage(event: PlayerDeathEvent) { + + val faction = FactionHandler.getFactionByPlayer(event.entity.uniqueId) + + Bukkit.getServer().onlinePlayers.filter{ + + if (event.entity.uniqueId == it.uniqueId) { + return@filter true + } + + if (event.entity.killer != null && event.entity.killer.uniqueId == it.uniqueId) { + return@filter true + } + + if (faction != null && faction.isFriendly(it)) { + return@filter true + } + + return@filter StatisticHandler.getStatistic(it.uniqueId,DeathMessageSetting).getValue() + }.forEach{it.sendMessage(event.deathMessage)} + + event.deathMessage = null + + + DeathMessageHandler.destroy(event.entity) + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/deathmessage/tracker/ArrowTracker.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/deathmessage/tracker/ArrowTracker.kt new file mode 100644 index 0000000..e229292 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/deathmessage/tracker/ArrowTracker.kt @@ -0,0 +1,63 @@ +package cc.fyre.hcf.deathmessage.tracker + +import cc.fyre.hcf.HCF +import cc.fyre.hcf.deathmessage.Damage +import cc.fyre.hcf.deathmessage.event.PlayerDamageEvent +import cc.fyre.hcf.deathmessage.type.ArrowDamage +import cc.fyre.hcf.deathmessage.type.mob.ArrowDamageByMob +import cc.fyre.hcf.deathmessage.type.player.ArrowDamageByPlayer +import org.bukkit.Location +import org.bukkit.entity.Arrow +import org.bukkit.entity.Entity +import org.bukkit.entity.Player +import org.bukkit.event.EventHandler +import org.bukkit.event.EventPriority +import org.bukkit.event.Listener +import org.bukkit.event.entity.EntityDamageByEntityEvent +import org.bukkit.event.entity.EntityShootBowEvent +import org.bukkit.event.entity.ProjectileHitEvent +import java.util.* + +/** + * @project engine + * + * @date 15/08/2020 + * @author xanderume@gmail.com + */ +object ArrowTracker : Listener { + + private val cache = mutableMapOf() + + @EventHandler(priority = EventPriority.NORMAL) + private fun onEntityShootBow(event: EntityShootBowEvent) { + + if (event.entity !is Player) { + return + } + + this.cache[event.entity.uniqueId] = event.projectile.location + } + + @EventHandler(priority = EventPriority.LOW, ignoreCancelled = true) + fun onPlayerDamage(event: PlayerDamageEvent) { + + if (event.event !is EntityDamageByEntityEvent) { + return + } + + if (event.event.damager !is Arrow) { + return + } + + val shooter = (event.event.damager as Arrow).shooter + + + event.damage = when (shooter) { + is Player -> ArrowDamageByPlayer(event.player.uniqueId,event.getDamage(),shooter.uniqueId,this.cache.remove(shooter.uniqueId)?.distance(event.player.location) ?: 0.0) + is Entity -> ArrowDamageByMob(event.player.uniqueId,event.getDamage(),shooter as Entity) + else -> ArrowDamage(event.player.uniqueId,event.getDamage()) + } + + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/deathmessage/tracker/BurnTracker.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/deathmessage/tracker/BurnTracker.kt new file mode 100644 index 0000000..6517d19 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/deathmessage/tracker/BurnTracker.kt @@ -0,0 +1,57 @@ +package cc.fyre.hcf.deathmessage.tracker + +import cc.fyre.hcf.HCF +import cc.fyre.hcf.deathmessage.Damage +import cc.fyre.hcf.deathmessage.DeathMessageHandler +import cc.fyre.hcf.deathmessage.event.PlayerDamageEvent +import cc.fyre.hcf.deathmessage.type.BurnDamage +import cc.fyre.hcf.deathmessage.type.PlayerDamage +import cc.fyre.hcf.deathmessage.type.player.BurnDamageByPlayer +import org.bukkit.event.EventHandler +import org.bukkit.event.EventPriority +import org.bukkit.event.Listener +import org.bukkit.event.entity.EntityDamageEvent +import java.util.concurrent.TimeUnit + +/** + * @project engine + * + * @date 15/08/2020 + * @author xanderume@gmail.com + */ +object BurnTracker : Listener { + + @EventHandler(priority = EventPriority.LOW) + private fun onPlayerDamage(event: PlayerDamageEvent) { + + if (event.event.cause !== EntityDamageEvent.DamageCause.FIRE_TICK && event.event.cause !== EntityDamageEvent.DamageCause.LAVA) { + return + } + + val damage = DeathMessageHandler.getAllDamageByPlayer(event.player) + + var knocked = 0L + var knocker: PlayerDamage? = null + + if (damage != null && damage.isNotEmpty()) { + damage.firstOrNull{it !is BurnDamage && it !is BurnDamageByPlayer && (it is PlayerDamage && (knocker == null || it.time > knocked))}.also{ + + if (it == null) { + return@also + } + + knocker = it as PlayerDamage + knocked = it.time + } + + } + + event.damage = if (knocker != null && knocked + TimeUnit.MINUTES.toMillis(1L) > System.currentTimeMillis()) { + BurnDamageByPlayer(event.player.uniqueId,event.getDamage(),knocker!!.attacker) + } else { + BurnDamage(event.player.uniqueId,event.getDamage()) + } + + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/deathmessage/tracker/EntityTracker.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/deathmessage/tracker/EntityTracker.kt new file mode 100644 index 0000000..a8e72e3 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/deathmessage/tracker/EntityTracker.kt @@ -0,0 +1,36 @@ +package cc.fyre.hcf.deathmessage.tracker + +import cc.fyre.hcf.HCF +import cc.fyre.hcf.deathmessage.Damage +import cc.fyre.hcf.deathmessage.event.PlayerDamageEvent +import cc.fyre.hcf.deathmessage.type.mob.EntityDamage +import org.bukkit.entity.Arrow +import org.bukkit.entity.Player +import org.bukkit.event.EventHandler +import org.bukkit.event.EventPriority +import org.bukkit.event.Listener +import org.bukkit.event.entity.EntityDamageByEntityEvent + +/** + * @project engine + * + * @date 15/08/2020 + * @author xanderume@gmail.com + */ +object EntityTracker : Listener { + + @EventHandler(priority = EventPriority.LOW,ignoreCancelled = true) + private fun onPlayerDamage(event: PlayerDamageEvent) { + + if (event.event !is EntityDamageByEntityEvent) { + return + } + + if (event.event.damager is Player || event.event.damager is Arrow) { + return + } + + event.damage = EntityDamage(event.player.uniqueId,event.getDamage(),event.event.damager) + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/deathmessage/tracker/FallTracker.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/deathmessage/tracker/FallTracker.kt new file mode 100644 index 0000000..23edfb0 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/deathmessage/tracker/FallTracker.kt @@ -0,0 +1,61 @@ +package cc.fyre.hcf.deathmessage.tracker + +import cc.fyre.hcf.HCF +import cc.fyre.hcf.deathmessage.Damage +import cc.fyre.hcf.deathmessage.DeathMessageHandler +import cc.fyre.hcf.deathmessage.event.PlayerDamageEvent +import cc.fyre.hcf.deathmessage.type.BurnDamage +import cc.fyre.hcf.deathmessage.type.FallDamage +import cc.fyre.hcf.deathmessage.type.PlayerDamage +import cc.fyre.hcf.deathmessage.type.VoidDamage +import cc.fyre.hcf.deathmessage.type.player.BurnDamageByPlayer +import cc.fyre.hcf.deathmessage.type.player.FallDamageByPlayer +import cc.fyre.hcf.deathmessage.type.player.VoidDamageByPlayer +import org.bukkit.event.EventHandler +import org.bukkit.event.EventPriority +import org.bukkit.event.Listener +import org.bukkit.event.entity.EntityDamageEvent +import java.util.concurrent.TimeUnit + +/** + * @project engine + * + * @date 15/08/2020 + * @author xanderume@gmail.com + */ +object FallTracker : Listener { + + @EventHandler(priority = EventPriority.LOW) + private fun onPlayerDamage(event: PlayerDamageEvent) { + + if (event.event.cause != EntityDamageEvent.DamageCause.FALL) { + return + } + + val damage = DeathMessageHandler.getAllDamageByPlayer(event.player) + + var knocked = 0L + var knocker: PlayerDamage? = null + + if (damage != null && damage.isNotEmpty()) { + damage.firstOrNull{it !is FallDamage && it !is FallDamageByPlayer && (it is PlayerDamage && (knocker == null || it.time > knocked))}.also{ + + if (it == null) { + return@also + } + + knocker = it as PlayerDamage + knocked = it.time + } + + } + + event.damage = if (knocker != null && knocked + TimeUnit.MINUTES.toMillis(1L) > System.currentTimeMillis()) { + FallDamageByPlayer(event.player.uniqueId,event.getDamage(),knocker!!.attacker) + } else { + FallDamage(event.player.uniqueId,event.getDamage()) + } + + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/deathmessage/tracker/GeneralTracker.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/deathmessage/tracker/GeneralTracker.kt new file mode 100644 index 0000000..153f55f --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/deathmessage/tracker/GeneralTracker.kt @@ -0,0 +1,34 @@ +package cc.fyre.hcf.deathmessage.tracker + +import cc.fyre.hcf.HCF +import cc.fyre.hcf.deathmessage.Damage +import cc.fyre.hcf.deathmessage.event.PlayerDamageEvent +import cc.fyre.hcf.deathmessage.type.GeneralDamage +import org.bukkit.event.EventHandler +import org.bukkit.event.EventPriority +import org.bukkit.event.Listener +import org.bukkit.event.entity.EntityDamageEvent + +/** + * @project engine + * + * @date 15/08/2020 + * @author xanderume@gmail.com + */ +object GeneralTracker : Listener { + + @EventHandler(priority = EventPriority.LOW,ignoreCancelled = true) + fun onCustomPlayerDamage(event: PlayerDamageEvent) { + + when (event.event.cause) { + EntityDamageEvent.DamageCause.WITHER -> event.damage = GeneralDamage(event.player.uniqueId,event.getDamage(),"withered away") + EntityDamageEvent.DamageCause.POISON -> event.damage = GeneralDamage(event.player.uniqueId,event.getDamage(),"was poisoned") + EntityDamageEvent.DamageCause.DROWNING -> event.damage = GeneralDamage(event.player.uniqueId,event.getDamage(),"drowned") + EntityDamageEvent.DamageCause.LIGHTNING ->event.damage = GeneralDamage(event.player.uniqueId,event.getDamage(),"was struck by lightning") + EntityDamageEvent.DamageCause.STARVATION -> event.damage = GeneralDamage(event.player.uniqueId,event.getDamage(),"starved to death") + EntityDamageEvent.DamageCause.SUFFOCATION -> event.damage = GeneralDamage(event.player.uniqueId,event.getDamage(),"suffocated") + } + + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/deathmessage/tracker/PvPTracker.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/deathmessage/tracker/PvPTracker.kt new file mode 100644 index 0000000..c5f3b6c --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/deathmessage/tracker/PvPTracker.kt @@ -0,0 +1,35 @@ +package cc.fyre.hcf.deathmessage.tracker + +import cc.fyre.hcf.HCF +import cc.fyre.hcf.deathmessage.Damage +import cc.fyre.hcf.deathmessage.event.PlayerDamageEvent +import cc.fyre.hcf.deathmessage.type.player.PvPDamage + +import org.bukkit.entity.Player +import org.bukkit.event.EventHandler +import org.bukkit.event.EventPriority +import org.bukkit.event.Listener +import org.bukkit.event.entity.EntityDamageByEntityEvent +/** + * @project engine + * + * @date 15/08/2020 + * @author xanderume@gmail.com + */ +object PvPTracker : Listener { + + @EventHandler(priority = EventPriority.LOW,ignoreCancelled = true) + private fun onPlayerDamage(event: PlayerDamageEvent) { + + if (event.event !is EntityDamageByEntityEvent) { + return + } + + if (event.event.damager !is Player) { + return + } + + event.damage = PvPDamage(event.player.uniqueId,event.getDamage(),event.event.damager as Player) + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/deathmessage/tracker/VoidTracker.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/deathmessage/tracker/VoidTracker.kt new file mode 100644 index 0000000..78b5bce --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/deathmessage/tracker/VoidTracker.kt @@ -0,0 +1,58 @@ +package cc.fyre.hcf.deathmessage.tracker + +import cc.fyre.hcf.HCF +import cc.fyre.hcf.deathmessage.Damage +import cc.fyre.hcf.deathmessage.DeathMessageHandler +import cc.fyre.hcf.deathmessage.event.PlayerDamageEvent +import cc.fyre.hcf.deathmessage.type.FallDamage +import cc.fyre.hcf.deathmessage.type.PlayerDamage +import cc.fyre.hcf.deathmessage.type.VoidDamage +import cc.fyre.hcf.deathmessage.type.player.FallDamageByPlayer +import cc.fyre.hcf.deathmessage.type.player.VoidDamageByPlayer +import org.bukkit.event.EventHandler +import org.bukkit.event.EventPriority +import org.bukkit.event.Listener +import org.bukkit.event.entity.EntityDamageEvent +import java.util.concurrent.TimeUnit + +/** + * @project engine + * + * @date 15/08/2020 + * @author xanderume@gmail.com + */ +object VoidTracker : Listener { + + @EventHandler(priority = EventPriority.LOW) + private fun onPlayerDamage(event: PlayerDamageEvent) { + + if (event.event.cause != EntityDamageEvent.DamageCause.VOID) { + return + } + val damage = DeathMessageHandler.getAllDamageByPlayer(event.player) + + var knocked = 0L + var knocker: PlayerDamage? = null + + if (damage != null && damage.isNotEmpty()) { + damage.firstOrNull{it !is VoidDamage && it !is VoidDamageByPlayer && (it is PlayerDamage && (knocker == null || it.time > knocked))}.also{ + + if (it == null) { + return@also + } + + knocker = it as PlayerDamage + knocked = it.time + } + + } + + event.damage = if (knocker != null && knocked + TimeUnit.MINUTES.toMillis(1L) > System.currentTimeMillis()) { + VoidDamageByPlayer(event.player.uniqueId,event.getDamage(),knocker!!.attacker) + } else { + VoidDamage(event.player.uniqueId,event.getDamage()) + } + + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/deathmessage/type/ArrowDamage.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/deathmessage/type/ArrowDamage.kt new file mode 100644 index 0000000..51aa171 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/deathmessage/type/ArrowDamage.kt @@ -0,0 +1,13 @@ +package cc.fyre.hcf.deathmessage.type + +import cc.fyre.hcf.deathmessage.Damage +import java.util.* + + +class ArrowDamage(damaged: UUID, damage: Double) : Damage(damaged,damage) { + + override fun getDeathMessage(uuid: UUID): String { + return "was shot" + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/deathmessage/type/BurnDamage.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/deathmessage/type/BurnDamage.kt new file mode 100644 index 0000000..0fd8dc6 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/deathmessage/type/BurnDamage.kt @@ -0,0 +1,12 @@ +package cc.fyre.hcf.deathmessage.type + +import cc.fyre.hcf.deathmessage.Damage +import java.util.* + +class BurnDamage(damaged: UUID, damage: Double) : Damage(damaged,damage) { + + override fun getDeathMessage(uuid: UUID): String { + return "burned to death" + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/deathmessage/type/FallDamage.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/deathmessage/type/FallDamage.kt new file mode 100644 index 0000000..8250cc5 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/deathmessage/type/FallDamage.kt @@ -0,0 +1,13 @@ +package cc.fyre.hcf.deathmessage.type + +import cc.fyre.hcf.deathmessage.Damage +import java.util.* + + +class FallDamage(damaged: UUID, damage: Double) : Damage(damaged,damage) { + + override fun getDeathMessage(uuid: UUID):String { + return "hit the ground too hard" + } + +} diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/deathmessage/type/GeneralDamage.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/deathmessage/type/GeneralDamage.kt new file mode 100644 index 0000000..f3c7923 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/deathmessage/type/GeneralDamage.kt @@ -0,0 +1,13 @@ +package cc.fyre.hcf.deathmessage.type + +import cc.fyre.hcf.deathmessage.Damage +import java.util.* + + +class GeneralDamage(damaged: UUID, damage: Double, private val message: String) : Damage(damaged,damage) { + + override fun getDeathMessage(uuid: UUID): String { + return this.message + } + +} diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/deathmessage/type/MobDamage.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/deathmessage/type/MobDamage.kt new file mode 100644 index 0000000..5c6fc89 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/deathmessage/type/MobDamage.kt @@ -0,0 +1,7 @@ +package cc.fyre.hcf.deathmessage.type + +import cc.fyre.hcf.deathmessage.Damage +import org.bukkit.entity.EntityType +import java.util.* + +abstract class MobDamage(uuid: UUID, damage: Double, val entityType: EntityType) : Damage(uuid,damage) \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/deathmessage/type/PlayerDamage.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/deathmessage/type/PlayerDamage.kt new file mode 100644 index 0000000..8a99cce --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/deathmessage/type/PlayerDamage.kt @@ -0,0 +1,6 @@ +package cc.fyre.hcf.deathmessage.type + +import cc.fyre.hcf.deathmessage.Damage +import java.util.* + +abstract class PlayerDamage(uuid: UUID, damage: Double, val attacker: UUID) : Damage(uuid,damage) \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/deathmessage/type/UnknownDamage.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/deathmessage/type/UnknownDamage.kt new file mode 100644 index 0000000..e5c7f0b --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/deathmessage/type/UnknownDamage.kt @@ -0,0 +1,13 @@ +package cc.fyre.hcf.deathmessage.type + +import cc.fyre.hcf.deathmessage.Damage +import java.util.* + + +class UnknownDamage(uuid: UUID, damage: Double) : Damage(uuid,damage) { + + override fun getDeathMessage(uuid: UUID):String { + return "died" + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/deathmessage/type/VoidDamage.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/deathmessage/type/VoidDamage.kt new file mode 100644 index 0000000..a9db404 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/deathmessage/type/VoidDamage.kt @@ -0,0 +1,13 @@ +package cc.fyre.hcf.deathmessage.type + +import cc.fyre.hcf.deathmessage.Damage +import java.util.* + + +class VoidDamage(damaged: UUID?, damage: Double) : Damage(damaged!!, damage) { + + override fun getDeathMessage(uuid: UUID): String { + return "fell into the void" + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/deathmessage/type/mob/ArrowDamageByMob.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/deathmessage/type/mob/ArrowDamageByMob.kt new file mode 100644 index 0000000..ce13084 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/deathmessage/type/mob/ArrowDamageByMob.kt @@ -0,0 +1,15 @@ +package cc.fyre.hcf.deathmessage.type.mob + +import cc.fyre.hcf.deathmessage.type.MobDamage +import cc.fyre.shard.util.entity.EntityUtil +import org.bukkit.ChatColor +import org.bukkit.entity.Entity +import java.util.* + +class ArrowDamageByMob(damaged: UUID, damage: Double, attacker: Entity) : MobDamage(damaged,damage,attacker.type) { + + override fun getDeathMessage(uuid: UUID):String { + return "was shot by a ${ChatColor.RED}${EntityUtil.getName(this.entityType)}" + } + +} diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/deathmessage/type/mob/EntityDamage.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/deathmessage/type/mob/EntityDamage.kt new file mode 100644 index 0000000..d72b119 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/deathmessage/type/mob/EntityDamage.kt @@ -0,0 +1,16 @@ +package cc.fyre.hcf.deathmessage.type.mob + +import cc.fyre.hcf.deathmessage.type.MobDamage +import cc.fyre.shard.util.entity.EntityUtil +import org.bukkit.ChatColor +import org.bukkit.entity.Entity +import java.util.* + + +class EntityDamage(damaged: UUID, damage: Double, entity: Entity) : MobDamage(damaged,damage,entity.type) { + + override fun getDeathMessage(uuid: UUID):String { + return "was slain by a ${ChatColor.RED} ${EntityUtil.getName(this.entityType)}" + } + +} diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/deathmessage/type/player/ArrowDamageByPlayer.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/deathmessage/type/player/ArrowDamageByPlayer.kt new file mode 100644 index 0000000..15d876b --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/deathmessage/type/player/ArrowDamageByPlayer.kt @@ -0,0 +1,18 @@ +package cc.fyre.hcf.deathmessage.type.player + +import cc.fyre.hcf.deathmessage.DeathMessageHandler +import cc.fyre.hcf.deathmessage.type.PlayerDamage +import org.bukkit.ChatColor +import java.util.* + + +class ArrowDamageByPlayer(damaged: UUID, damage: Double, attacker: UUID, private val distance: Double) : PlayerDamage(damaged,damage,attacker) { + + override fun getDeathMessage(uuid: UUID):String { + + val distance = this.distance.toInt() + + return "was shot by ${DeathMessageHandler.getFormat(this.attacker)}${ChatColor.YELLOW} from ${ChatColor.BLUE}${distance} block${if (distance == 1) "" else "s"}" + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/deathmessage/type/player/BackStabDamageByPlayer.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/deathmessage/type/player/BackStabDamageByPlayer.kt new file mode 100644 index 0000000..2fa2104 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/deathmessage/type/player/BackStabDamageByPlayer.kt @@ -0,0 +1,14 @@ +package cc.fyre.hcf.deathmessage.type.player + +import cc.fyre.hcf.deathmessage.DeathMessageHandler +import cc.fyre.hcf.deathmessage.type.PlayerDamage +import java.util.* + + +class BackStabDamageByPlayer(damaged: UUID, damage: Double, attacker: UUID) : PlayerDamage(damaged,damage,attacker) { + + override fun getDeathMessage(uuid: UUID): String { + return "was backstabbed by ${DeathMessageHandler.getFormat(this.attacker)}" + } + +} diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/deathmessage/type/player/BurnDamageByPlayer.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/deathmessage/type/player/BurnDamageByPlayer.kt new file mode 100644 index 0000000..171388f --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/deathmessage/type/player/BurnDamageByPlayer.kt @@ -0,0 +1,13 @@ +package cc.fyre.hcf.deathmessage.type.player + +import cc.fyre.hcf.deathmessage.DeathMessageHandler +import cc.fyre.hcf.deathmessage.type.PlayerDamage +import java.util.* + +class BurnDamageByPlayer(damaged: UUID, damage: Double, attacker: UUID) : PlayerDamage(damaged,damage,attacker) { + + override fun getDeathMessage(uuid: UUID): String { + return "burned to death thanks to ${DeathMessageHandler.getFormat(this.attacker)}" + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/deathmessage/type/player/FallDamageByPlayer.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/deathmessage/type/player/FallDamageByPlayer.kt new file mode 100644 index 0000000..982b864 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/deathmessage/type/player/FallDamageByPlayer.kt @@ -0,0 +1,13 @@ +package cc.fyre.hcf.deathmessage.type.player + +import cc.fyre.hcf.deathmessage.DeathMessageHandler +import cc.fyre.hcf.deathmessage.type.PlayerDamage +import java.util.* + +class FallDamageByPlayer(damaged: UUID, damage: Double, attacker: UUID) : PlayerDamage(damaged,damage,attacker) { + + override fun getDeathMessage(uuid: UUID): String { + return "hit the ground too hard thanks to ${DeathMessageHandler.getFormat(this.attacker)}" + } + +} diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/deathmessage/type/player/PvPDamage.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/deathmessage/type/player/PvPDamage.kt new file mode 100644 index 0000000..a866e6d --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/deathmessage/type/player/PvPDamage.kt @@ -0,0 +1,20 @@ +package cc.fyre.hcf.deathmessage.type.player + +import cc.fyre.hcf.deathmessage.DeathMessageHandler +import cc.fyre.hcf.deathmessage.type.PlayerDamage +import org.apache.commons.lang.WordUtils +import org.bukkit.ChatColor +import org.bukkit.Material +import org.bukkit.entity.Player +import java.util.* + + +class PvPDamage(damaged: UUID, damage: Double, attacker: Player) : PlayerDamage(damaged,damage,attacker.uniqueId) { + + private var itemString = if (attacker.itemInHand.type == Material.AIR) "their firsts" else if (attacker.itemInHand.itemMeta.hasDisplayName()) ChatColor.stripColor(attacker.itemInHand.itemMeta.displayName) else WordUtils.capitalizeFully(attacker.itemInHand.type.name.replace('_', ' ')) + + override fun getDeathMessage(uuid: UUID): String { + return "was slain by ${DeathMessageHandler.getFormat(this.attacker)}${ChatColor.YELLOW} using ${ChatColor.RED}${this.itemString.trim{it <= ' '}}" + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/deathmessage/type/player/VoidDamageByPlayer.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/deathmessage/type/player/VoidDamageByPlayer.kt new file mode 100644 index 0000000..053fc34 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/deathmessage/type/player/VoidDamageByPlayer.kt @@ -0,0 +1,14 @@ +package cc.fyre.hcf.deathmessage.type.player + +import cc.fyre.hcf.deathmessage.DeathMessageHandler +import cc.fyre.hcf.deathmessage.type.PlayerDamage +import java.util.* + + +class VoidDamageByPlayer(damaged: UUID, damage: Double, attacker: UUID) : PlayerDamage(damaged,damage,attacker) { + + override fun getDeathMessage(uuid: UUID): String { + return "fell into the void thanks to ${DeathMessageHandler.getFormat(uuid)}" + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/Faction.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/Faction.kt new file mode 100644 index 0000000..3c42c81 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/Faction.kt @@ -0,0 +1,110 @@ +package cc.fyre.hcf.faction + +import cc.fyre.hcf.HCF +import cc.fyre.hcf.faction.claim.Claim +import cc.fyre.hcf.faction.event.FactionHQUpdateEvent +import com.lunarclient.bukkitapi.`object`.LCWaypoint +import com.squareup.moshi.Json +import com.squareup.moshi.JsonClass +import org.bukkit.ChatColor +import org.bukkit.Color +import org.bukkit.Location +import org.bukkit.command.CommandSender +import java.lang.IllegalStateException +import java.util.* + +/** + * @project hcf + * + * @date 04/04/2020 + * @author xanderume@gmail.com + */ +@JsonClass(generateAdapter = false) +abstract class Faction( + @Json(name = "_id") + val id: UUID, + var name: String, + val type: FactionType +) { + + var hq: Location? = null + var claims = mutableListOf() + var created = System.currentTimeMillis() + + @Transient protected var wayPoint: LCWaypoint? = null + + open fun init() { + + if (this.hq == null) { + return + } + + this.wayPoint = LCWaypoint(this.name,this.hq,Color.BLUE.asRGB(),true,true) + } + + fun getHQ():Location? { + return this.hq + } + + open fun setHQ(location: Location?) { + HCF.instance.server.pluginManager.callEvent(FactionHQUpdateEvent(this,this.hq,location)) + this.hq = location + this.wayPoint = LCWaypoint(this.name,this.hq,Color.BLUE.asRGB(),true,true) + } + + @JvmName("getWayPoint1") + fun getWayPoint():LCWaypoint? { + return this.wayPoint + } + + fun addClaims(vararg claims: Claim) { + this.claims.addAll(claims.toSet()) + this.flagForSave() + } + + fun removeClaims(vararg claims: Claim) { + this.claims.removeAll(claims.toSet()) + this.flagForSave() + } + + fun flagForSave() { + FactionHandler.addUpdate(this.id) + } + + abstract fun getDeathbanStatus(): DeathbanStatus + + abstract fun sendInfo(sender: CommandSender) + abstract fun getDisplayName(faction: Faction):String + abstract fun getDisplayName(sender: CommandSender):String + + open fun isConstant():Boolean { + return false + } + + enum class DeathbanStatus(val displayName: String) { + + DEATHBAN("${ChatColor.RED}Deathban"), + NON_DEATHBAN("${ChatColor.GREEN}Non-Deathban") + + } + + fun cloneWayPoint(color: Color,name: String? = this.name):LCWaypoint { + + if (this.wayPoint == null) { + throw IllegalStateException("Cannot clone a null waypoint!") + } + + return LCWaypoint(name,this.wayPoint!!.x,this.wayPoint!!.y,this.wayPoint!!.z,this.wayPoint!!.world,color.asRGB(),this.wayPoint!!.isForced,this.wayPoint!!.isVisible) + } + + companion object { + + const val MIN_NAME_LENGTH = 3 + const val MAX_NAME_LENGTH = 16 + + val ALLY_COLOR = ChatColor.BLUE + val ENEMY_COLOR = ChatColor.RED + val FACTION_COLOR = ChatColor.GREEN + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/FactionHandler.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/FactionHandler.kt new file mode 100644 index 0000000..3ac13cc --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/FactionHandler.kt @@ -0,0 +1,186 @@ +package cc.fyre.hcf.faction + +import cc.fyre.core.uuid.UUIDHandler +import cc.fyre.hcf.HCF +import cc.fyre.hcf.faction.type.PlayerFaction +import cc.fyre.hcf.faction.type.SystemFaction +import cc.fyre.hcf.faction.type.defaults.WarZoneFaction +import cc.fyre.hcf.faction.type.defaults.WildernessFaction +import cc.fyre.hcf.game.GameFaction +import cc.fyre.hcf.faction.claim.ClaimHandler +import cc.fyre.hcf.faction.service.TeamViewerService +import cc.fyre.hcf.faction.type.defaults.TheEndFaction +import cc.fyre.hcf.faction.type.defaults.TheNetherFaction +import cc.fyre.shard.util.StringUtil +import org.bukkit.Bukkit +import org.bukkit.GameMode +import org.bukkit.Location +import org.bukkit.World +import org.bukkit.entity.Player +import java.text.DecimalFormat +import java.util.* +import java.util.concurrent.ConcurrentHashMap +import java.util.regex.Pattern + +/** + * @project hcf + * + * @date 04/04/2020 + * @author xanderume@gmail.com + */ +object FactionHandler { + + private val factions = ConcurrentHashMap() + private val factionsByName = ConcurrentHashMap() + private val factionsByType = ConcurrentHashMap>() + private val factionsByPlayer = ConcurrentHashMap() + + private val updateQueue = ConcurrentHashMap.newKeySet() + private val deleteQueue = ConcurrentHashMap.newKeySet() + + fun init() { + FactionRepository.findAll().forEach{ + this.factions[it.id] = it + this.factionsByName[it.name.lowercase()] = it + this.factionsByType.putIfAbsent(it.type,ConcurrentHashMap.newKeySet()) + + if (it is SystemFaction && it.type != FactionType.SYSTEM) { + this.factionsByType.getOrPut(FactionType.SYSTEM) { + ConcurrentHashMap.newKeySet() + }.add(it) + } + + this.factionsByType[it.type]!!.add(it) + this.factionsByType.getOrPut(it.type) { + ConcurrentHashMap.newKeySet() + }.add(it) + + if (it is PlayerFaction) { + it.members.keys.forEach{member -> this.factionsByPlayer[member] = it} + } + + it.init() + } + + Bukkit.getServer().scheduler.runTaskTimerAsynchronously(HCF.instance,TeamViewerService,40L,40L) + + HCF.instance.logger.info("Loaded ${this.factions.size} ${StringUtil.pluralize("Faction",this.factions.size)} from MongoDB.") + } + + fun getFactionById(uuid: UUID): Faction? { + return this.factions[uuid] + } + + fun getFactionByName(name: String): Faction? { + return this.factionsByName[name.lowercase()] + } + + fun getFactionByPlayer(player: UUID):PlayerFaction? { + return this.factionsByPlayer[player] + } + + fun getFactionByArgument(argument: String): Faction? { + + val foundByName = this.getFactionByName(argument) + + if (foundByName != null) { + return foundByName + } + + val id = UUIDHandler.getIdByUsername(argument) ?: return null + + return this.factionsByPlayer[id] + } + + fun getFactionByLocation(location: Location): Faction { + return ClaimHandler.getClaimDataByLocation(location)?.value ?: when { + location.world.environment == World.Environment.THE_END -> TheEndFaction + location.world.environment == World.Environment.NETHER -> TheNetherFaction + ClaimHandler.isWarZone(location) -> WarZoneFaction + else -> WildernessFaction + } + } + + fun getAllFactions():Set { + return this.factions.values.toSet() + } + + fun getAllGameFactions():Set { + return (this.factionsByType[FactionType.GAME] ?: setOf()).filterIsInstance().toSet() + } + + fun getAllSystemFactions():Set { + return (this.factionsByType[FactionType.SYSTEM] ?: setOf()).filterIsInstance().toSet() + } + + fun getAllPlayerFactions():Set { + return (this.factionsByType[FactionType.PLAYER] ?: setOf()).filterIsInstance().toSet() + } + + fun getActiveGameFactions():Set { + return this.getAllGameFactions().filter{it.isActive()}.toSet() + } + + fun update(faction: Faction) { + this.factions[faction.id] = faction + this.factionsByName[faction.name.lowercase()] = faction + this.factionsByType.getOrPut(faction.type) { + ConcurrentHashMap.newKeySet() + }.add(faction) + } + + fun updateName(faction: Faction,name: String) { + this.factionsByName.remove(faction.name.lowercase()) + this.factionsByName[name.lowercase()] = faction + } + + fun destroy(faction: Faction) { + this.factions.remove(faction.id) + this.factionsByName.remove(faction.name.lowercase()) + + if (faction is SystemFaction && faction.type != FactionType.SYSTEM) { + this.factionsByType[FactionType.SYSTEM]?.remove(faction) + } + + if (faction is PlayerFaction) { + faction.members.keys.forEach{this.factionsByPlayer.remove(it)} + } + + this.factionsByType[faction.type]?.remove(faction) + this.updateQueue.remove(faction.id) + this.deleteQueue.add(faction.id) + } + + fun addPlayer(player: UUID,faction: PlayerFaction) { + this.factionsByPlayer[player] = faction + } + + fun removePlayer(player: UUID) { + this.factionsByPlayer.remove(player) + } + + fun addUpdate(uuid: UUID) { + + if (this.deleteQueue.contains(uuid)) { + return + } + + this.updateQueue.add(uuid) + } + + fun getAllUpdates():ConcurrentHashMap.KeySetView { + return this.updateQueue + } + + fun getAllDeletes():ConcurrentHashMap.KeySetView { + return this.deleteQueue + } + + fun isAdminOverride(player: Player):Boolean { + return player.gameMode == GameMode.CREATIVE && player.hasPermission("hcf.override") + } + + val DTR_FORMAT = DecimalFormat("0.00") + val ALPHA_NUMERIC_PATTERN: Pattern = Pattern.compile("[^a-zA-Z0-9]") + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/FactionMember.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/FactionMember.kt new file mode 100644 index 0000000..d278101 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/FactionMember.kt @@ -0,0 +1,22 @@ +package cc.fyre.hcf.faction + +import cc.fyre.core.uuid.UUIDHandler +import cc.fyre.hcf.faction.type.player.ChatMode +import cc.fyre.hcf.faction.type.player.FactionRole +import com.squareup.moshi.JsonClass +import java.util.* + +@JsonClass(generateAdapter = true) +data class FactionMember( + val uuid: UUID, + var role: FactionRole = FactionRole.MEMBER, + var chatMode: ChatMode = ChatMode.FACTION +) { + + @Transient var online = false + + fun getUsername():String { + return UUIDHandler.getUsernameById(this.uuid) ?: "null" + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/FactionMetadata.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/FactionMetadata.kt new file mode 100644 index 0000000..a388c5d --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/FactionMetadata.kt @@ -0,0 +1,33 @@ +package cc.fyre.hcf.faction + +import cc.fyre.hcf.faction.type.SystemFaction +import cc.fyre.shard.util.item.ItemBuilder +import org.bukkit.ChatColor +import org.bukkit.Location +import org.bukkit.Material +import org.bukkit.inventory.ItemStack + + +enum class FactionMetadata(val displayName: String,val icon: ItemStack) { + + ROAD("${ChatColor.GOLD}Road", ItemBuilder.of(Material.RAILS).name("${ChatColor.GOLD}Road").build()), + SAFE_ZONE("${ChatColor.GREEN}Safe-Zone", ItemBuilder.of(Material.EMERALD_BLOCK).name("${ChatColor.GREEN}Safe Zone").build()), + NO_ENDER_PEARL("${ChatColor.DARK_PURPLE}No Pearling", ItemBuilder.of(Material.ENDER_PEARL).name("${ChatColor.DARK_PURPLE}Pearling").build()); + + fun isValidAtLocation(location: Location):Boolean { + + val faction = FactionHandler.getFactionByLocation(location) + + if (faction !is SystemFaction) { + return false + } + + return faction.hasMetadata(this) + } + + companion object { + + val values = values() + + } +} diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/FactionModule.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/FactionModule.kt new file mode 100644 index 0000000..1b13b71 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/FactionModule.kt @@ -0,0 +1,134 @@ +package cc.fyre.hcf.faction + +import cc.fyre.hcf.HCF +import cc.fyre.hcf.HCFModule +import cc.fyre.hcf.faction.claim.ClaimHandler +import cc.fyre.hcf.faction.claim.listener.ClaimListener +import cc.fyre.hcf.faction.claim.listener.ClaimPositionListener +import cc.fyre.hcf.faction.command.* +import cc.fyre.hcf.faction.command.admin.* +import cc.fyre.hcf.faction.command.captain.* +import cc.fyre.hcf.faction.command.coleader.* +import cc.fyre.hcf.faction.command.leader.FactionDisbandCommand +import cc.fyre.hcf.faction.command.leader.FactionLeaderCommand +import cc.fyre.hcf.faction.command.parameter.* +import cc.fyre.hcf.faction.type.PlayerFaction +import cc.fyre.hcf.faction.type.SystemFaction +import cc.fyre.hcf.faction.listener.* +import cc.fyre.hcf.game.GameFaction +import cc.fyre.hcf.mountain.MountainFaction +import cc.fyre.shard.command.data.parameter.ParameterAdapter +import org.bukkit.event.Listener + +object FactionModule : HCFModule { + + override fun init(core: HCF) { + FactionHandler.init() + ClaimHandler.init() + } + + override fun shutdown(core: HCF) { + FactionRepository.saveAll() + FactionRepository.deleteAll() + } + + override fun onSave(core: HCF) { + FactionRepository.saveAll() + FactionRepository.deleteAll() + } + + override fun getCommands(): List> { + return listOf( + FactionAcceptCommand::class.java, + FactionAnnouncementCommand::class.java, + FactionChatCommand::class.java, + FactionCreateCommand::class.java, + FactionDepositCommand::class.java, + FactionFocusCommand::class.java, + FactionHelpCommand::class.java, + FactionHQCommand::class.java, + FactionInfoCommand::class.java, + FactionLeaveCommand::class.java, + FactionListCommand::class.java, + FactionLocationCommand::class.java, + FactionLocationHomeCommand::class.java, + FactionMapCommand::class.java, + FactionRallyListener::class.java, + FactionRegenCommand::class.java, + FactionStuckCommand::class.java, + FactionTopCommand::class.java, + + FactionAllyCommand::class.java, + FactionClaimCommand::class.java, + FactionInviteCommand::class.java, + FactionInviteRevokeCommand::class.java, + FactionKickCommand::class.java, + FactionSetHQCommand::class.java, + FactionWithdrawCommand::class.java, + + FactionDemoteCommand::class.java, + FactionPromoteCommand::class.java, + FactionRenameCommand::class.java, + FactionUnAllyCommand::class.java, + FactionUnClaimCommand::class.java, + + FactionDisbandCommand::class.java, + FactionLeaderCommand::class.java, + + FactionBalanceAddCommand::class.java, + FactionBalanceRemoveCommand::class.java, + FactionBanCommand::class.java, + FactionBlacklistCommand::class.java, + FactionChatSpyAddCommand::class.java, + FactionChatSpyRemoveCommand::class.java, + FactionDisbandAllCommand::class.java, + FactionEditorCommand::class.java, + FactionForceDisbandCommand::class.java, + FactionMuteCommand::class.java, + FactionPointsAddCommand::class.java, + FactionPointsRemoveCommand::class.java, + FactionSetDTRCommand::class.java, + FactionSetDTRRegenCommand::class.java, + FactionTeleportCommand::class.java, + FactionFilterCommand::class.java, + + FactionForceSetHQCommand::class.java, + FactionForceDisbandCommand::class.java + ) + } + + override fun getAdapters(): Map, ParameterAdapter<*>> { + + return mapOf( + Faction::class.java to FactionParameterProvider, + GameFaction::class.java to GameFactionParameterProvider, + SystemFaction::class.java to SystemFactionParameterProvider, + PlayerFaction::class.java to PlayerFactionParameterProvider, + MountainFaction::class.java to MountainFactionParameterProvider + ) + } + + override fun getListeners(): List { + return listOf( + FactionMapListener, + FactionMoveListener, + FactionChatListener, + FactionClaimListener, + FactionFocusListener, + FactionStaffListener, + FactionRallyListener, + FactionDeathListener, + FactionMemberListener, + FactionPistonListener, + FactionMetadataListener, + FactionSubclaimListener, + FactionWayPointListener, + FactionProtectionListener, + + ClaimListener, + ClaimPositionListener + ) + } + + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/FactionRepository.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/FactionRepository.kt new file mode 100644 index 0000000..88d1f8a --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/FactionRepository.kt @@ -0,0 +1,83 @@ +package cc.fyre.hcf.faction + +import cc.fyre.hcf.HCF +import cc.fyre.shard.moshi.MoshiUtil +import cc.fyre.shard.util.MongoUtil +import cc.fyre.shard.util.StringUtil +import com.mongodb.client.model.DeleteOneModel +import com.mongodb.client.model.Filters +import com.mongodb.client.model.ReplaceOneModel +import com.mongodb.client.model.WriteModel +import org.bson.Document +import java.lang.Exception + +/** + * @project hcf + * + * @date 17/11/2020 + * @author xanderume@gmail.com + */ +object FactionRepository { + + private val collection = HCF.instance.getMongoDB().getCollection("factions") + + fun findAll():List { + return this.collection.find().mapNotNull{MoshiUtil.instance.adapter(Faction::class.java).fromJson(it.toJson(MongoUtil.RELAXED_WRITE_SETTING))} + } + + fun saveAll() { + + val adapter = try { + MoshiUtil.instance.adapter(Faction::class.java) + } catch (ex: Exception) { + ex.printStackTrace() + return + } + + val iterator = FactionHandler.getAllUpdates().iterator() + val bulkWrite = mutableListOf>() + + while (iterator.hasNext()) { + + val faction = FactionHandler.getFactionById(iterator.next()) + + if (faction != null) { + bulkWrite.add(ReplaceOneModel( + Filters.eq("_id",faction.id.toString()), + Document.parse(adapter.toJson(faction)), + MongoUtil.REPLACE_OPTIONS + )) + } + + iterator.remove() + } + + if (bulkWrite.isEmpty()) { + return + } + + this.collection.bulkWrite(bulkWrite) + + HCF.instance.logger.info("Saved ${bulkWrite.size} ${StringUtil.pluralize("faction",bulkWrite.size)} to MongoDB.") + } + + fun deleteAll() { + + val iterator = FactionHandler.getAllDeletes().iterator() + val bulkWrite = mutableListOf>() + + while (iterator.hasNext()) { + bulkWrite.add(DeleteOneModel(Filters.eq("_id",iterator.next().toString()))) + iterator.remove() + } + + if (bulkWrite.isEmpty()) { + return + } + + this.collection.bulkWrite(bulkWrite) + + HCF.instance.logger.info("Deleted ${bulkWrite.size} factions from MongoDB.") + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/FactionType.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/FactionType.kt new file mode 100644 index 0000000..fa911ca --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/FactionType.kt @@ -0,0 +1,10 @@ +package cc.fyre.hcf.faction + +enum class FactionType { + + GAME, + PLAYER, + SYSTEM, + MOUNTAIN; + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/claim/Claim.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/claim/Claim.kt new file mode 100644 index 0000000..ff80b74 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/claim/Claim.kt @@ -0,0 +1,207 @@ +package cc.fyre.hcf.faction.claim + +import cc.fyre.hcf.HCF +import cc.fyre.hcf.faction.Faction +import cc.fyre.hcf.faction.FactionHandler +import cc.fyre.hcf.faction.claim.coordinate.Coordinate +import cc.fyre.hcf.faction.claim.coordinate.CoordinateSet +import cc.fyre.shard.util.moshi.world.WorldSerializer +import com.squareup.moshi.Json +import com.squareup.moshi.JsonClass +import org.bukkit.Location +import org.bukkit.World +import org.bukkit.block.Block +import java.util.* +import kotlin.math.abs +import kotlin.math.max +import kotlin.math.min + + +/** + * @project hcf + * + * @date 04/04/2020 + * @author xanderume@gmail.com + */ +@JsonClass(generateAdapter = true) +class Claim( + @WorldSerializer + val world: World, + x1: Int, + x2: Int, + z1: Int, + z2: Int, +) : Iterable { + + constructor(first: Location,second: Location):this(first.world,first.blockX,second.blockX,first.blockZ,second.blockZ) + + @Json(name = "_id") + val id: UUID = UUID.randomUUID() + val x1 = min(x1,x2) + val x2 = max(x1,x2) + val z1 = min(z1,z2) + val z2 = max(z1,z2) + + fun contains(world: String, x: Int,z: Int):Boolean { + return this.world.name == world && x >= this.x1 && x <= this.x2 && z >= this.z1 && z <= this.z2 + } + + fun contains(location: Location):Boolean { + return this.contains(location.world.name,location.blockX,location.blockZ) + } + + fun getLower():Location { + return Location(this.world,this.x1.toDouble(),0.0,this.z1.toDouble()) + } + + fun getUpper():Location { + return Location(this.world,this.x2.toDouble(),256.0,this.z2.toDouble()) + } + + fun getCenter(): Location { + val x1 = this.x2 + 1 + val z1 = this.z2 + 1 + + val location = Location(this.world,this.x1 + (x1 - this.x1) / 2.0,0.0,this.z1 + (z1 - this.z1) / 2.0) + + return location.add(0.0,location.world.getHighestBlockYAt(location).toDouble(),0.0) + } + + private fun expand(direction: Direction, amount: Int):Claim { + return when (direction) { + Direction.WEST -> Claim(this.world,this.x1,this.z2,this.z1,this.z2 + amount) + Direction.EAST -> Claim(this.world,this.x1,this.x2,this.z1 - amount,this.z2) + Direction.SOUTH -> Claim(this.world,this.x1,this.x2 + amount,this.z1,this.z2) + Direction.NORTH -> Claim(this.world,this.x1 - amount,this.x2,this.z1,this.z2) + else -> throw IllegalArgumentException("Invalid direction $direction") + } + } + + fun outset(direction: Direction,amount: Int):Claim { + return when (direction) { + Direction.BOTH -> outset(Direction.HORIZONTAL,amount).outset(Direction.VERTICAL,amount) + Direction.VERTICAL -> expand(Direction.DOWN,amount).expand(Direction.UP,amount) + Direction.HORIZONTAL -> expand(Direction.NORTH,amount).expand(Direction.SOUTH,amount).expand(Direction.EAST,amount).expand(Direction.WEST,amount) + else -> throw IllegalArgumentException("Invalid direction $direction") + } + } + + fun getCorners():Array { + return arrayOf( + Location(this.world,this.x1.toDouble(),0.0,this.z1.toDouble()), + Location(this.world,this.x2.toDouble(),0.0,this.z2.toDouble()), + Location(this.world,this.x1.toDouble(),0.0,this.z2.toDouble()), + Location(this.world,this.x2.toDouble(),0.0,this.z1.toDouble()) + ) + } + + override fun equals(other: Any?): Boolean { + return other is Claim && this.getLower() == other.getLower() && this.getUpper() == other.getUpper() + } + + override fun iterator():Iterator { + return BorderIterator(this,this.x1,this.x2,this.z1,this.z2) + } + + fun blockIterator():Iterator { + return CuboidBlockIterator(this.world,this.x1,0,this.z1,this.z1,256,this.z2) + } + + override fun hashCode(): Int { + return Objects.hash(this.world.hashCode(),this.id.hashCode(),this.x1,this.x2,this.z1,this.z2) + } + + // HCTeams can suck my dick nigga + class BorderIterator(val claim: Claim,x1: Int,x2: Int,z1: Int,z2: Int) : MutableIterator { + + private var x: Int = min(x1,x2) + private var z: Int = min(z1,z2) + + private var next = true + private var direction = BorderDirection.POS_Z + + private var minX: Int = this.claim.getLower().blockX + private var minZ: Int = this.claim.getLower().blockZ + private var maxX: Int = this.claim.getUpper().blockX + private var maxZ: Int = this.claim.getUpper().blockZ + + override fun hasNext(): Boolean { + return this.next + } + + override fun next():Coordinate { + if (this.direction == BorderDirection.POS_Z) { + if (++this.z == this.maxZ) { + this.direction = BorderDirection.POS_X + } + } else if (this.direction == BorderDirection.POS_X) { + if (++this.x == this.maxX) { + this.direction = BorderDirection.NEG_Z + } + } else if (this.direction == BorderDirection.NEG_Z) { + if (--this.z == this.minZ) { + this.direction = BorderDirection.NEG_X + } + } else if (this.direction == BorderDirection.NEG_X) { + if (--this.x == this.minX) { + this.next = false + } + } + return Coordinate(this.x,this.z) + } + + override fun remove() {} + + enum class BorderDirection { + + POS_X, + POS_Z, + NEG_X, + NEG_Z + + } + + } + + class CuboidBlockIterator(private val world: World, private val baseX: Int,private val baseY: Int,private val baseZ: Int, x2: Int, y2: Int, z2: Int) : MutableIterator { + + private var x = 0 + private var y = 0 + private var z = 0 + + private val sizeX = abs(x2 - this.baseX) + 1 + private val sizeY = abs(y2 - this.baseY) + 1 + private val sizeZ = abs(z2 - this.baseZ) + 1 + + override fun hasNext(): Boolean { + return this.x < this.sizeX && this.y < this.sizeY && this.z < this.sizeZ + } + + override fun next(): Block { + val block = this.world.getBlockAt(this.baseX + this.x,this.baseY + this.y,this.baseZ + this.z) + + if (++this.x >= this.sizeX) { + + if (++this.y >= this.sizeY) { + this.z++ + this.y = 0 + } + + this.x = 0 + } + + return block + } + + @Throws(UnsupportedOperationException::class) + override fun remove() { + throw UnsupportedOperationException() + } + + } + + enum class Direction { + NORTH,EAST,SOUTH,WEST,UP,DOWN,HORIZONTAL,VERTICAL,BOTH + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/claim/ClaimHandler.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/claim/ClaimHandler.kt new file mode 100644 index 0000000..ba8b187 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/claim/ClaimHandler.kt @@ -0,0 +1,228 @@ +package cc.fyre.hcf.faction.claim + +import cc.fyre.hcf.faction.Faction +import cc.fyre.hcf.faction.FactionHandler +import cc.fyre.hcf.faction.claim.coordinate.CoordinateSet +import cc.fyre.hcf.faction.type.defaults.WildernessFaction +import cc.fyre.hcf.pillar.PillarHandler +import cc.fyre.hcf.pillar.PillarType +import com.google.common.collect.HashMultimap +import com.google.common.collect.Multimap +import org.bukkit.Bukkit +import org.bukkit.ChatColor +import org.bukkit.Location +import org.bukkit.World +import org.bukkit.entity.Player +import java.util.* +import java.util.concurrent.ConcurrentHashMap +import kotlin.math.abs + +object ClaimHandler { + + private val buckets = ConcurrentHashMap>>() + private val selections = mutableMapOf() + + fun init() { + Bukkit.getServer().worlds.forEach{this.buckets[it.uid] = HashMultimap.create()} + FactionHandler.getAllFactions().forEach{faction -> + faction.claims.forEach{claim -> + this.createClaimEntry(faction,claim) + } + } + } + + fun createBucket(world: World) { + this.buckets[world.uid] = HashMultimap.create() + } + + fun createClaimEntry(faction: Faction, claim: Claim) { + + val step = 1 shl CoordinateSet.BITS + val entry = AbstractMap.SimpleEntry(claim,faction) + + for (x in entry.key.x1..(entry.key.x2 + step) step step) { + for (z in entry.key.z1..(entry.key.z2 + step) step step) { + this.buckets[entry.key.world.uid]!!.put(CoordinateSet(x,z),entry) + } + } + + } + + fun getClaimDataByRadius(center: Location,x: Int,z: Int): Set> { + return this.getClaimDataByLocations( + Location(center.world,(center.blockX - x).toDouble(),0.0,(center.blockZ - z).toDouble()), + Location(center.world,(center.blockX + x).toDouble(),0.0,(center.blockZ + z).toDouble()) + ) + } + + fun getClaimDataByLocation(location: Location):Map.Entry? { + return this.buckets[location.world.uid]!![CoordinateSet(location.blockX,location.blockZ)] + .firstOrNull{it.key.contains(location)} + } + + fun destroy(claim: Claim) { + + val step = 1 shl CoordinateSet.BITS + + for (x in claim.x1..(claim.x2 + step) step step) { + for (z in claim.z1..(claim.z2 + step) step step) { + + val iterator = this.buckets[claim.world.uid]?.get(CoordinateSet(x,z))?.iterator() ?: continue + + while (iterator.hasNext()) { + + if (iterator.next().key == claim) { + iterator.remove() + } + + } + + } + } + + } + + fun getClaimDataByLocations(min: Location,max: Location):Set> { + + val map = this.buckets[min.world.uid] ?: return setOf() + val step = 1 shl CoordinateSet.BITS + val regions = hashSetOf>() + + for (x in min.blockX..(max.blockX + step) step step) { + + for (z in min.blockZ..(max.blockZ + step) step step) { + + val coordinate = CoordinateSet(x,z) + + for (entry in map[coordinate]) { + + if (regions.contains(entry)) { + continue + } + + if (max.blockX >= entry.key.x1 + && min.blockX <= entry.key.x2 + && max.blockZ >= entry.key.z1 + && min.blockZ <= entry.key.z2 + ) { + regions.add(entry) + } + } + } + + } + + return regions + } + + fun getAllSelections():MutableMap { + return this.selections + } + + fun getSelectionByPlayer(player: Player):ClaimSelection? { + return this.selections[player.uniqueId] + } + + fun createSelection(slot: Int,player: Player,faction: Faction) { + + if (this.selections.remove(player.uniqueId) != null) { + player.inventory.removeItem(ClaimSelection.ITEM) + PillarHandler.destroyPillars(player,PillarType.CLAIM_SELECTION) + } + + player.inventory.setItem(slot,ClaimSelection.ITEM) + player.sendMessage("${ChatColor.GREEN}Gave you a claiming wand.") + + this.selections[player.uniqueId] = ClaimSelection(faction) + } + + fun destroySelection(player: Player, removeItem: Boolean = true):ClaimSelection? { + + val selection = this.selections.remove(player.uniqueId) + + if (selection != null && removeItem) { + player.inventory.removeItem(ClaimSelection.ITEM) + } + + return selection + } + + fun isClaimed(location: Location):Boolean { + + if (this.isWarZone(location)) { + return true + } + + return this.getClaimDataByLocation(location)?.key != null + } + + fun getClaimByLocation(location: Location):Claim? { + return this.getClaimDataByLocation(location)?.key + } + + fun containsOtherClaim(claim: Claim):Faction? { + + if (abs(claim.x1 - claim.x2) == 0 || abs(claim.z1 - claim.z2) == 0) { + return null + } + + val maxPoint: Location = claim.getUpper() + val minPoint: Location = claim.getLower() + + for (x in minPoint.blockX..maxPoint.blockX) { + + for (z in minPoint.blockZ..maxPoint.blockZ) { + + val faction = FactionHandler.getFactionByLocation(Location(claim.world,x.toDouble(),80.0,z.toDouble())) + + if (faction is WildernessFaction) { + continue + } + + return faction + } + + } + + return null + } + + fun getTouchingClaims(claim: Claim):HashSet { + val touchingClaims = HashSet() + + for (coordinate in claim.outset(Claim.Direction.HORIZONTAL, BUFFER)) { + val loc = Location( + claim.world, + coordinate.x.toDouble(), + 80.0, + coordinate.z.toDouble() + ) + val claimAtLocation: Map.Entry? = this.getClaimDataByLocation(loc) + if (claimAtLocation != null) { + touchingClaims.add(claimAtLocation.key) + } + } + + return touchingClaims + + } + + + fun isWarZone(location: Location):Boolean { + return abs(location.x) <= WARZONE_RADIUS + && abs(location.z) <= WARZONE_RADIUS + } + + fun isWilderness(location: Location):Boolean { + return abs(location.x) > WARZONE_RADIUS + || abs(location.z) > WARZONE_RADIUS + } + + const val MAX_CLAIMS = 2 + const val MINIMUM_SIZE = 5 + + const val BUFFER = 1 + const val WARZONE_RADIUS = 1000 + + const val WARZONE_RADIUS_BUILD = 350 +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/claim/ClaimSelection.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/claim/ClaimSelection.kt new file mode 100644 index 0000000..17ccade --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/claim/ClaimSelection.kt @@ -0,0 +1,108 @@ +package cc.fyre.hcf.faction.claim + +import cc.fyre.shard.util.item.ItemBuilder +import cc.fyre.hcf.HCF + +import cc.fyre.hcf.faction.Faction +import cc.fyre.hcf.faction.type.PlayerFaction +import cc.fyre.hcf.faction.type.SystemFaction +import org.bukkit.ChatColor +import org.bukkit.Location +import org.bukkit.Material + +import org.bukkit.event.block.Action +import kotlin.math.abs + +/** + * @project hcf + * + * @date 04/04/2020 + * @author xanderume@gmail.com + */ +class ClaimSelection(val faction: Faction) { + + var first: Location? = null + var second: Location? = null + + var lastUpdate: Long = 0 + + constructor(faction: Faction, first:Location, second: Location):this(faction) { + this.first = first + this.second = second + } + + fun getFormattedMessage(action: Action,location: Location):Array { + + val toReturn = arrayOfNulls(2) + + toReturn[0] = "${ChatColor.YELLOW}Set claim's location ${ChatColor.LIGHT_PURPLE}${if (action == Action.LEFT_CLICK_BLOCK) 1 else 2}${ChatColor.YELLOW} to ${ChatColor.GREEN}(${ChatColor.WHITE}${location.blockX}, ${location.blockY}, ${location.blockZ}${ChatColor.GREEN})${ChatColor.YELLOW}." + + if (this.first != null && this.second != null) { + + val price = this.getPrice() + + val width = abs(this.first!!.blockX - this.second!!.blockX) + val length = abs(this.first!!.blockZ - this.second!!.blockZ) + + toReturn[1] = "${ChatColor.YELLOW}Claim cost: ${if (this.faction is PlayerFaction && this.faction.balance < price) ChatColor.RED else ChatColor.GREEN}$${price}${ChatColor.YELLOW}, Current size: (${ChatColor.WHITE}$width, $length${ChatColor.YELLOW}), ${ChatColor.WHITE}${width * length}${ChatColor.YELLOW} blocks." + } + + return toReturn + } + + fun getPrice():Int { + + if (this.faction is SystemFaction) { + return 0 + } + + var toReturn = 0.0 + var modifier = PRICE_MODIFIER + + val x: Int = abs(this.first!!.blockX - this.second!!.blockX) + val z: Int = abs(this.first!!.blockZ - this.second!!.blockZ) + + var done = 0 + var blocks = x * z + + while (blocks > 0) { + done++ + blocks-- + toReturn += modifier + + if (done == 250) { + done = 0 + modifier += PRICE_MODIFIER + } + + } + + toReturn *= PRICE_MULTIPLIER + + return toReturn.toInt() + } + + companion object { + + val ITEM = ItemBuilder.of(Material.WOOD_HOE) + .name("${ChatColor.GREEN}${ChatColor.ITALIC}Claiming Wand") + .lore(arrayListOf( + "", + "${ChatColor.YELLOW}Right Click ${ChatColor.GOLD}Air", + "${ChatColor.AQUA}- ${ChatColor.WHITE}Cancel current claim", + "", + "${ChatColor.YELLOW}Right/Left Click ${ChatColor.GOLD}Block", + "${ChatColor.AQUA}- ${ChatColor.WHITE}Select claim's corners", + "", + "${ChatColor.BLUE}Crouch ${ChatColor.YELLOW}Left Click ${ChatColor.GOLD}Block/Air", + "${ChatColor.AQUA}- ${ChatColor.WHITE}Confirm claim" + )) + .build() + + val PILLAR_MATERIAL = Material.EMERALD_BLOCK + + val PRICE_MODIFIER = 0.4 + val PRICE_MULTIPLIER = 0.8 + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/claim/coordinate/Coordinate.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/claim/coordinate/Coordinate.kt new file mode 100644 index 0000000..34c9771 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/claim/coordinate/Coordinate.kt @@ -0,0 +1,9 @@ +package cc.fyre.hcf.faction.claim.coordinate + +class Coordinate(var x: Int,var z: Int) { + + override fun toString(): String { + return "${this.x}, ${this.z}" + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/claim/coordinate/CoordinateSet.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/claim/coordinate/CoordinateSet.kt new file mode 100644 index 0000000..f90b887 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/claim/coordinate/CoordinateSet.kt @@ -0,0 +1,31 @@ +package cc.fyre.hcf.faction.claim.coordinate + +import java.util.* + +class CoordinateSet(x: Int,z: Int) { + + val x = x shr BITS + val z = z shr BITS + + override fun equals(other: Any?): Boolean { + + if (other == null || other !is CoordinateSet) { + return false + } + + return other.x == x && other.z == z + } + + override fun hashCode(): Int { + return Objects.hash(this.x,this.z) + } + + override fun toString(): String { + return "[${this.x},${this.z}]" + } + + companion object { + const val BITS = 6 + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/claim/listener/ClaimListener.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/claim/listener/ClaimListener.kt new file mode 100644 index 0000000..2cc0aa3 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/claim/listener/ClaimListener.kt @@ -0,0 +1,16 @@ +package cc.fyre.hcf.faction.claim.listener + +import cc.fyre.hcf.faction.claim.ClaimHandler +import org.bukkit.event.EventHandler +import org.bukkit.event.EventPriority +import org.bukkit.event.Listener +import org.bukkit.event.world.WorldLoadEvent + +object ClaimListener : Listener { + + @EventHandler(priority = EventPriority.NORMAL) + private fun onWorldLoad(event: WorldLoadEvent) { + ClaimHandler.createBucket(event.world) + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/claim/listener/ClaimPositionListener.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/claim/listener/ClaimPositionListener.kt new file mode 100644 index 0000000..6666361 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/claim/listener/ClaimPositionListener.kt @@ -0,0 +1,237 @@ +package cc.fyre.hcf.faction.claim.listener + +import cc.fyre.hcf.HCF +import cc.fyre.hcf.faction.claim.Claim +import cc.fyre.hcf.faction.claim.ClaimHandler +import cc.fyre.hcf.faction.claim.ClaimSelection +import cc.fyre.hcf.faction.event.FactionClaimEvent +import cc.fyre.hcf.faction.menu.system.SystemEditMenu +import cc.fyre.hcf.faction.type.PlayerFaction +import cc.fyre.hcf.faction.type.SystemFaction +import cc.fyre.hcf.faction.type.player.FactionRole +import cc.fyre.hcf.map.eotw.EOTWHandler +import cc.fyre.hcf.pillar.PillarHandler +import cc.fyre.hcf.pillar.PillarType +import org.bukkit.Bukkit +import org.bukkit.ChatColor +import org.bukkit.Location +import org.bukkit.World +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.player.PlayerInteractEvent +import kotlin.math.abs + + +/** + * @project hcf + * + * @date 03/06/2020 + * @author xanderume@gmail.com + */ +object ClaimPositionListener : Listener { + + @EventHandler(priority = EventPriority.LOWEST) + private fun onPlayerInteract(event: PlayerInteractEvent) { + + if (event.item == null) { + return + } + + if (!event.item.isSimilar(ClaimSelection.ITEM)) { + return + } + + val selection = ClaimHandler.getSelectionByPlayer(event.player) ?: return + + event.isCancelled = true + + if (event.action == Action.RIGHT_CLICK_AIR) { + event.player.itemInHand = null + event.player.sendMessage("${ChatColor.RED}You have cancelled the claiming process.") + + ClaimHandler.destroySelection(event.player,removeItem = false) + PillarHandler.destroyPillars(event.player, PillarType.CLAIM_SELECTION) + return + } + + if (EOTWHandler.isActive() && (selection.faction !is SystemFaction || !event.player.isOp)) { + event.player.sendMessage("${ChatColor.RED}You cannot claim land whilst EOTW.") + event.isCancelled = true + return + } + + if (event.action == Action.LEFT_CLICK_AIR) { + + if (!event.player.isSneaking) { + return + } + + if (selection.first == null || selection.second == null) { + event.player.sendMessage("${ChatColor.RED}You have not selected both corners of your claim yet!") + return + } + + val price = selection.getPrice() + + val claim = Claim(selection.first!!,selection.second!!) + + if (selection.faction is PlayerFaction) { + + if (selection.faction.claims.size >= ClaimHandler.MAX_CLAIMS) { + event.player.sendMessage("${ChatColor.RED}Your faction has the maximum amount of claims, which is ${ChatColor.WHITE}${ClaimHandler.MAX_CLAIMS}${ChatColor.RED}.") + return + } + + if (selection.faction.getRole(event.player.uniqueId) == FactionRole.MEMBER) { + event.player.sendMessage("${ChatColor.RED}You must be at least a faction captain to claim land!") + return + } + + if (selection.faction.balance < price) { + event.player.sendMessage("${ChatColor.RED}Your faction cannot afford this claim!") + return + } + + if (selection.faction.isRaidable()) { + event.player.sendMessage("${ChatColor.RED}You can't claim land whilst your faction is raidable!") + return + } + + val override = ClaimHandler.containsOtherClaim(claim) + + if (override != null) { + event.player.sendMessage("${ChatColor.RED}This land is currently claimed by ${override.getDisplayName(event.player)}${ChatColor.RED} and cannot be claimed.") + return + } + + val ignoreNearby : List? = null + val touchingClaims: MutableSet = ClaimHandler.getTouchingClaims(claim) + val teamClaims = touchingClaims.iterator() + var removedSelfClaims = false + + while (teamClaims.hasNext()) { + val possibleClaim = teamClaims.next() + if (ignoreNearby != null && ignoreNearby.contains(possibleClaim)) { + removedSelfClaims = true + teamClaims.remove() + } else if (selection.faction.claims.contains(possibleClaim)) { + removedSelfClaims = true + teamClaims.remove() + } + } + + if (selection.faction.claims.size != (0) && !removedSelfClaims + ) { + event.player.sendMessage(ChatColor.RED.toString() + "All of your claims must be touching each other!") + return + } + + if (touchingClaims.size > 1 || touchingClaims.size == 1 && !removedSelfClaims) { + event.player.sendMessage(ChatColor.RED.toString() + "Your claim must be at least 1 block away from enemy claims!") + return + } + + } + + event.player.itemInHand = null + + selection.faction.addClaims(claim) + + ClaimHandler.createClaimEntry(selection.faction,claim) + ClaimHandler.destroySelection(event.player,removeItem = false) + + if (selection.faction is PlayerFaction) { + selection.faction.balance -= price + + event.player.sendMessage("${ChatColor.YELLOW}Your faction's new balance is ${ChatColor.WHITE}$${selection.faction.balance} ${ChatColor.LIGHT_PURPLE}(Price: $${price})${ChatColor.YELLOW}.") + } + + PillarHandler.destroyPillars(event.player,PillarType.CLAIM_SELECTION) + + if (selection.faction is SystemFaction) { + SystemEditMenu(selection.faction).open(event.player) + } + + event.player.sendMessage("${ChatColor.YELLOW}You have claimed this land for your faction!") + + Bukkit.getServer().pluginManager.callEvent(FactionClaimEvent(event.player,claim,selection.faction)) + return + } + + if (event.clickedBlock == null) { + return + } + + // prevent lag + if (selection.lastUpdate != 0L && (System.currentTimeMillis() - selection.lastUpdate) <= 200L) { + return + } + + if (selection.faction is PlayerFaction) { + + if (event.clickedBlock.location.world.environment != World.Environment.NORMAL) { + event.player.sendMessage("${ChatColor.RED}Land can only be claimed in the overworld.") + return + } + + if (ClaimHandler.isWarZone(event.player.location)) { + event.player.sendMessage("${ChatColor.RED}You are currently in the Warzone and can't claim land here. The Warzone ends at ${ClaimHandler.WARZONE_RADIUS}.") + return + } + + if (ClaimHandler.isClaimed(event.clickedBlock.location)) { + event.player.sendMessage("${ChatColor.RED}You can only claim land in the wilderness!") + return + } + + val blockX = event.clickedBlock.location.blockX + val blockZ = event.clickedBlock.location.blockZ + + val opposite = if (event.action == Action.LEFT_CLICK_BLOCK) selection.second else selection.first + + if (opposite != null && ((abs(opposite.blockX - blockX) + 1) < ClaimHandler.MINIMUM_SIZE || (abs(opposite.blockZ - blockZ) + 1) < ClaimHandler.MINIMUM_SIZE)) { + event.player.sendMessage("${ChatColor.RED}Your claim is too small! The claim has to be at least ${ClaimHandler.MINIMUM_SIZE}x${ClaimHandler.MINIMUM_SIZE}!") + return + } + + } + + if (event.action == Action.LEFT_CLICK_BLOCK) { + + if (selection.first != null) { + PillarHandler.destroyPillars(event.player, PillarType.CLAIM_SELECTION) { + it.location.blockX == selection.first!!.blockX && it.location.blockZ == selection.first!!.blockZ + } + } + + selection.first = event.clickedBlock.location + } else { + + if (selection.second != null) { + PillarHandler.destroyPillars(event.player, PillarType.CLAIM_SELECTION) { + it.location.blockX == selection.second!!.blockX && it.location.blockZ == selection.second!!.blockZ + } + } + + selection.second = event.clickedBlock.location + } + + selection.lastUpdate = System.currentTimeMillis() + selection.getFormattedMessage(event.action,event.clickedBlock.location).filterNotNull().forEach{event.player.sendMessage(it)} + + val locations = ArrayList() + + for (i in event.clickedBlock.location.blockY..event.clickedBlock.world.maxHeight) { + locations.add(Location(event.clickedBlock.world,event.clickedBlock.location.x,i.toDouble(),event.clickedBlock.location.z)) + } + + Bukkit.getServer().scheduler.runTask(HCF.instance) { + PillarHandler.createPillars(event.player,PillarType.CLAIM_SELECTION,locations,ClaimSelection.PILLAR_MATERIAL,true) + } + + } + + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/FactionAcceptCommand.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/FactionAcceptCommand.kt new file mode 100644 index 0000000..2e9b7b1 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/FactionAcceptCommand.kt @@ -0,0 +1,67 @@ +package cc.fyre.hcf.faction.command + +import cc.fyre.shard.command.data.command.Command +import cc.fyre.shard.command.data.parameter.Parameter +import cc.fyre.hcf.HCF +import cc.fyre.hcf.faction.FactionHandler +import cc.fyre.hcf.faction.type.PlayerFaction +import cc.fyre.hcf.map.eotw.EOTWHandler +import cc.fyre.hcf.timer.TimerHandler +import cc.fyre.hcf.timer.TimerType +import cc.fyre.shard.command.data.option.Option +import org.bukkit.ChatColor +import org.bukkit.entity.Player + +/** + * @project hcf + * + * @date 25/06/2020 + * @author xanderume@gmail.com + */ +object FactionAcceptCommand { + + @JvmStatic + @Command(names = ["faction join","fac join","f join","team join","t join","faction j","fac j","f j","team j","t j","faction accept","fac accept","f accept","team accept","t accept","faction a","fac a","f a","team a","t a"]) + fun execute(player: Player, + @Option(value = ["f","force"],defaultValue = false,permission = "hcf.command.faction.accept.advanced",description = "Force join a faction.") force: Boolean, + @Parameter(name = "faction")faction: PlayerFaction) { + + if (FactionHandler.getFactionByPlayer(player.uniqueId) != null) { + player.sendMessage("${ChatColor.RED}You are already in a faction!") + return + } + + if (!force) { + + if (!faction.invites.contains(player.uniqueId)) { + player.sendMessage("${ChatColor.RED}This faction has not invited you!") + return + } + + if (faction.members.size >= PlayerFaction.MEMBER_LIMIT) { + player.sendMessage("${ChatColor.RED}${faction.name} is currently full!") + return + } + + if (faction.isOnDTRFreeze()) { + player.sendMessage("${ChatColor.RED}You cannot join ${faction.name} as they are currently on DTR freeze!") + return + } + + if (EOTWHandler.isActive()) { + player.sendMessage("${ChatColor.RED}You cannot join factions during EOTW.") + return + } + + if (TimerHandler.hasTimer(player.uniqueId,TimerType.SPAWN_TAG)) { + player.sendMessage("${ChatColor.RED}You cannot join ${faction.name} as you are currently on spawn-tagged!") + return + } + + } + + faction.addMember(player) + faction.flagForSave() + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/FactionAnnouncementCommand.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/FactionAnnouncementCommand.kt new file mode 100644 index 0000000..7232d31 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/FactionAnnouncementCommand.kt @@ -0,0 +1,50 @@ +package cc.fyre.hcf.faction.command + +import cc.fyre.shard.command.data.command.Command +import cc.fyre.shard.command.data.parameter.Parameter +import cc.fyre.hcf.HCF +import cc.fyre.hcf.faction.FactionHandler +import org.bukkit.ChatColor +import org.bukkit.entity.Player + +/** + * @project hcf + * + * @date 28/06/2020 + * @author xanderume@gmail.com + */ +object FactionAnnouncementCommand { + + @JvmStatic + @Command(names = ["faction announcement","fac announcement","f announcement","team announcement","t announcement"]) + fun execute(player: Player,@Parameter(name = "announcement",true)announcement: String) { + + val faction = FactionHandler.getFactionByPlayer(player.uniqueId) + + if (faction == null) { + player.sendMessage("${ChatColor.RED}You are not in a faction!") + return + } + + if (!faction.getRole(player.uniqueId).isAbleToUpdateAnnouncement()) { + player.sendMessage("${ChatColor.RED}You are not authorized to change the faction announcement.") + return + } + + if (announcement.equals("clear",true) || announcement.equals("reset",true)) { + faction.announcement = null + } else { + faction.announcement = announcement + } + + faction.flagForSave() + + if (faction.announcement == null) { + faction.sendMessage("${ChatColor.LIGHT_PURPLE}${player.name}${ChatColor.YELLOW} has reset the faction announcement.") + return + } + + faction.sendMessage("${ChatColor.LIGHT_PURPLE}${player.name}${ChatColor.YELLOW} changed the faction announcement to ${ChatColor.LIGHT_PURPLE}$announcement${ChatColor.YELLOW}.") + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/FactionChatCommand.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/FactionChatCommand.kt new file mode 100644 index 0000000..8cf543b --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/FactionChatCommand.kt @@ -0,0 +1,61 @@ +package cc.fyre.hcf.faction.command + +import cc.fyre.shard.command.data.command.Command +import cc.fyre.shard.command.data.parameter.Parameter +import cc.fyre.hcf.HCF +import cc.fyre.hcf.faction.FactionHandler +import cc.fyre.hcf.faction.type.PlayerFaction +import cc.fyre.hcf.faction.type.player.ChatMode +import org.bukkit.ChatColor +import org.bukkit.entity.Player + +/** + * @project hcf + * + * @date 28/06/2020 + * @author xanderume@gmail.com + */ +object FactionChatCommand { + + @JvmStatic + @Command(names = ["gc","pc"]) + fun global(player: Player) { + this.execute(player,ChatMode.GLOBAL.arguments[0]) + } + + @JvmStatic + @Command(names = ["fc","tc"]) + fun faction(player: Player) { + this.execute(player,ChatMode.FACTION.arguments[0]) + } + + @JvmStatic + @Command(names = ["oc"]) + fun officer(player: Player) { + this.execute(player,ChatMode.OFFICER.arguments[0]) + } + + @JvmStatic + @Command(names = ["faction chat","fac chat","f chat","team chat","t chat","faction c","fac c","f c","team c","t c"]) + fun execute(player: Player,@Parameter(name = "mode",false,"defaultValue")args: String) { + + val faction = FactionHandler.getFactionByPlayer(player.uniqueId) + + if (faction == null) { + player.sendMessage("${ChatColor.RED}You are not in a faction!") + return + } + + var chatMode = ChatMode.getByArgument(args) + + if (chatMode == null || !chatMode.hasPermission(player.uniqueId,faction)) { + chatMode = faction.getChatMode(player.uniqueId).getNext(player.uniqueId,faction) + } + + faction.members[player.uniqueId]!!.chatMode = chatMode + faction.flagForSave() + + player.sendMessage("${ChatColor.DARK_AQUA}You are now talking in ${chatMode.arguments[0]} chat.") + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/FactionCreateCommand.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/FactionCreateCommand.kt new file mode 100644 index 0000000..23d8d7d --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/FactionCreateCommand.kt @@ -0,0 +1,66 @@ +package cc.fyre.hcf.faction.command + +import cc.fyre.core.profile.ProfileHandler +import cc.fyre.shard.command.data.command.Command +import cc.fyre.shard.command.data.parameter.Parameter +import cc.fyre.hcf.faction.FactionHandler +import cc.fyre.hcf.faction.Faction +import cc.fyre.hcf.faction.type.PlayerFaction +import cc.fyre.hcf.faction.event.FactionCreateEvent +import cc.fyre.hcf.faction.type.player.FactionRole +import org.bukkit.Bukkit +import org.bukkit.ChatColor +import org.bukkit.entity.Player +import java.util.* + +/** + * @project hcf + * + * @date 07/04/2020 + * @author xanderume@gmail.com + */ +object FactionCreateCommand { + + @JvmStatic + @Command(names = ["faction create","fac create","f create","team create","t create"]) + fun execute(player: Player,@Parameter(name = "faction")name: String) { + + if (FactionHandler.getFactionByPlayer(player.uniqueId) != null) { + player.sendMessage("${ChatColor.RED}You are already in a faction!") + return + } + + if (name.length < Faction.MIN_NAME_LENGTH) { + player.sendMessage("${ChatColor.RED}Minimum faction name size is ${Faction.MIN_NAME_LENGTH} characters!") + return + } + + if (name.length > Faction.MAX_NAME_LENGTH) { + player.sendMessage("${ChatColor.RED}Maximum faction name size is ${Faction.MAX_NAME_LENGTH} characters!") + return + } + + if (FactionHandler.ALPHA_NUMERIC_PATTERN.matcher(name).find()) { + player.sendMessage("${ChatColor.RED}Faction names must be alphanumeric!") + return + } + + if (FactionHandler.getFactionByName(name) != null) { + player.sendMessage("${ChatColor.RED}That faction already exists!") + return + } + + val faction = PlayerFaction(UUID.randomUUID(),name) + + faction.addMember(player,FactionRole.LEADER) + + faction.flagForSave() + + FactionHandler.update(faction) + FactionHandler.addPlayer(player.uniqueId,faction) + + Bukkit.getServer().pluginManager.callEvent(FactionCreateEvent(faction)) + Bukkit.getServer().broadcastMessage("${ChatColor.YELLOW}Faction ${ChatColor.BLUE}${faction.name}${ChatColor.YELLOW} has been ${ChatColor.GREEN}created ${ChatColor.YELLOW}by ${ProfileHandler.getDisplayNameById(player.uniqueId)}") + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/FactionDepositCommand.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/FactionDepositCommand.kt new file mode 100644 index 0000000..0e30a6e --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/FactionDepositCommand.kt @@ -0,0 +1,51 @@ +package cc.fyre.hcf.faction.command + +import cc.fyre.shard.command.data.command.Command +import cc.fyre.shard.command.data.parameter.Parameter +import cc.fyre.hcf.HCF +import cc.fyre.hcf.faction.FactionHandler +import cc.fyre.hcf.statistic.StatisticHandler +import cc.fyre.hcf.statistic.type.BalanceStatistic +import org.bukkit.ChatColor +import org.bukkit.entity.Player + +/** + * @project hcf + * + * @date 05/07/2020 + * @author xanderume@gmail.com + */ +object FactionDepositCommand { + + @JvmStatic + @Command(names = ["faction deposit","fac deposit","f deposit","team deposit","t deposit","faction d","fac d","f d","team d","t d"]) + fun execute(player: Player,@Parameter(name = "amount")argument: String) { + + val faction = FactionHandler.getFactionByPlayer(player.uniqueId) + + if (faction == null) { + player.sendMessage("${ChatColor.RED}You are not in a faction!") + return + } + + val current = StatisticHandler.getStatistic(player.uniqueId,BalanceStatistic).getValue() + val balance = if (argument.equals("all",true) || argument.equals("a",true)) current else argument.toIntOrNull() + + if (balance == null || balance <= 0) { + player.sendMessage(ChatColor.RED.toString() + "You can't deposit $0.0 (or less)!") + return + } + + if (current < balance) { + player.sendMessage("${ChatColor.RED}You don't have enough money to do this!") + return + } + + faction.balance += balance + + StatisticHandler.setStatistic(player.uniqueId,BalanceStatistic,current - balance) + + faction.sendMessage("${ChatColor.LIGHT_PURPLE}${player.name} ${ChatColor.YELLOW}deposited ${ChatColor.LIGHT_PURPLE}$$balance${ChatColor.YELLOW} into the faction balance.") + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/FactionFilterCommand.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/FactionFilterCommand.kt new file mode 100644 index 0000000..d8f351f --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/FactionFilterCommand.kt @@ -0,0 +1,17 @@ +package cc.fyre.hcf.faction.command + +import cc.fyre.hcf.faction.menu.faction.FactionFilterMenu +import cc.fyre.hcf.statistic.StatisticHandler +import cc.fyre.hcf.statistic.type.setting.FactionFilterSetting +import cc.fyre.shard.command.data.command.Command +import org.bukkit.entity.Player + +object FactionFilterCommand { + + @JvmStatic + @Command(names = ["faction filter","fac filter","f filter","team filter","t filter","filter"]) + fun execute(sender: Player) { + FactionFilterMenu(StatisticHandler.getStatistic(sender.uniqueId,FactionFilterSetting).getValue()).open(sender) + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/FactionFocusCommand.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/FactionFocusCommand.kt new file mode 100644 index 0000000..2f75881 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/FactionFocusCommand.kt @@ -0,0 +1,62 @@ +package cc.fyre.hcf.faction.command + +import cc.fyre.core.uuid.UUIDHandler +import cc.fyre.shard.command.data.command.Command +import cc.fyre.shard.command.data.parameter.Parameter +import cc.fyre.hcf.HCF +import cc.fyre.hcf.faction.FactionHandler +import cc.fyre.hcf.faction.command.parameter.PlayerFactionParameterProvider +import cc.fyre.hcf.faction.event.FactionFocusEvent +import cc.fyre.hcf.faction.event.FactionUnFocusEvent +import org.bukkit.ChatColor +import org.bukkit.entity.Player + +/** + * @project hcf + * + * @date 06/07/2020 + * @author xanderume@gmail.com + */ +object FactionFocusCommand { + + @Command(names = ["faction focus","fac focus","f focus","team focus","t focus","focus"]) + fun execute(player: Player,@Parameter(name = "player|faction",false,"defaultValue")argument: String) { + + val faction = FactionHandler.getFactionByPlayer(player.uniqueId) + + if (faction == null) { + player.sendMessage("${ChatColor.RED}You are not in a faction!") + return + } + + if (argument == "defaultValue") { + + var current = "None" + + if (faction.focus != null) { + FactionHandler.getFactionById(faction.focus!!)?.also{ + current = faction.name + } + } + + player.sendMessage("${ChatColor.YELLOW}Current Focus: ${ChatColor.LIGHT_PURPLE}$current") + return + } + + val targetFaction = PlayerFactionParameterProvider.transform(player,argument) ?: return + + faction.setFocus(if (targetFaction.id == faction.focus) null else targetFaction) + faction.flagForSave() + + if (faction.focus == null) { + faction.sendMessage("${ChatColor.LIGHT_PURPLE}${player.name}${ChatColor.YELLOW} has unfocused faction ${ChatColor.LIGHT_PURPLE}${targetFaction.name}${ChatColor.YELLOW}.") + HCF.instance.server.pluginManager.callEvent(FactionUnFocusEvent(faction,targetFaction)) + return + } + + faction.sendMessage("${ChatColor.YELLOW}Faction ${ChatColor.LIGHT_PURPLE}${targetFaction.name}${ChatColor.YELLOW} has been focused by ${ChatColor.LIGHT_PURPLE}${player.name}${ChatColor.YELLOW}.") + + HCF.instance.server.pluginManager.callEvent(FactionFocusEvent(faction,targetFaction)) + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/FactionHQCommand.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/FactionHQCommand.kt new file mode 100644 index 0000000..0e5e384 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/FactionHQCommand.kt @@ -0,0 +1,73 @@ +package cc.fyre.hcf.faction.command + +import cc.fyre.shard.command.data.command.Command +import cc.fyre.hcf.HCF +import cc.fyre.hcf.faction.FactionHandler +import cc.fyre.hcf.faction.FactionMetadata +import cc.fyre.hcf.faction.type.SystemFaction +import cc.fyre.hcf.map.eotw.EOTWHandler +import cc.fyre.hcf.timer.TimerHandler +import cc.fyre.hcf.timer.TimerType +import org.bukkit.ChatColor +import org.bukkit.entity.Player + +/** + * @project hcf + * + * @date 06/07/2020 + * @author xanderume@gmail.com + */ +object FactionHQCommand { + + @JvmStatic + @Command(names = ["faction hq","fac hq","f hq","team hq","t hq","hq","faction home","fac home","f home","team home","t home","home"]) + fun execute(player: Player) { + + val faction = FactionHandler.getFactionByPlayer(player.uniqueId) + + if (faction == null) { + player.sendMessage("${ChatColor.RED}You are not in a faction!") + return + } + + if (faction.getHQ() == null) { + player.sendMessage("${ChatColor.RED}HQ not set.") + return + } + + if (TimerHandler.hasTimer(player.uniqueId, TimerType.SPAWN_TAG)) { + player.sendMessage("${ChatColor.RED}You cannot warp to your faction's HQ whilst spawn-tagged!") + return + } + + if (TimerHandler.hasTimer(player.uniqueId, TimerType.HOME)) { + player.sendMessage("${ChatColor.RED}You are already being warped!") + return + } + + if (EOTWHandler.isActive()) { + player.sendMessage("${ChatColor.RED}You cannot warp to your faction's HQ during EOTW.") + return + } + + val locationFaction = FactionHandler.getFactionByLocation(player.location) + + if (locationFaction is SystemFaction) { + + if (locationFaction.hasMetadata(FactionMetadata.SAFE_ZONE)) { + player.teleport(faction.getHQ()) + player.sendMessage("${ChatColor.YELLOW}Warping to ${ChatColor.LIGHT_PURPLE}${faction.name}${ChatColor.YELLOW}'s HQ.") + return + } + + if (locationFaction.isEvent()) { + player.sendMessage("${ChatColor.RED}You cannot warp to your faction's HQ inside of events!") + return + } + + } + + TimerHandler.addTimer(player.uniqueId, TimerType.HOME) + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/FactionHelpCommand.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/FactionHelpCommand.kt new file mode 100644 index 0000000..4d3b2fe --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/FactionHelpCommand.kt @@ -0,0 +1,60 @@ +package cc.fyre.hcf.faction.command + +import cc.fyre.shard.command.data.command.Command +import org.bukkit.command.CommandSender + +/** + * @project hcf + * + * @date 06/07/2020 + * @author xanderume@gmail.com + */ +object FactionHelpCommand { + + @Command(names = ["faction","fac","f","faction","t","team"]) + fun execute(sender: CommandSender) { + arrayOf( + "§6§m-----------------------------------------------------", + "§9§lTeam Help §7- §eTeam Help", + "§7§m-----------------------------------------------------", + + + "§9General Commands:", + "§e/f create §7- Create a new faction", + "§e/f accept §7- Accept a pending invitation", + "§e/f leave §7- Leave your current faction", + "§e/f home §7- Teleport to your faction home", + "§e/f stuck §7- Teleport out of enemy territory", + "§e/f deposit §7- Deposit money into your faction balance", + + + "", + "§9Information Commands:", + "§e/f who [player§7|§efactionName] §7- Display faction information", + "§e/f map §7- Show nearby claims (identified by pillars)", + "§e/f list §7- Show list of factions online (sorted by most online)", + + + "", + "§9Captain Commands:", + "§e/f invite §7- Invite a player to your faction", + "§e/f uninvite §7- Revoke an invitation", + "§e/f kick §7- Kick a player from your faction", + "§e/f claim §7- Start a claim for your faction", + "§e/f sethome §7- Set your faction's home at your current location", + "§e/f withdraw §7- Withdraw money from your faction's balance", + "§e/f announcement [message here] §7- Set your faction's announcement", + + "", + "§9Leader Commands:", + + "§e/f unclaim [all] §7- Unclaim land", + "§e/f rename §7- Rename your faction", + "§e/f disband §7- Disband your faction", + + + "§6§m-----------------------------------------------------" + ).forEach{sender.sendMessage(it)} + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/FactionInfoCommand.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/FactionInfoCommand.kt new file mode 100644 index 0000000..8d9732a --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/FactionInfoCommand.kt @@ -0,0 +1,23 @@ +package cc.fyre.hcf.faction.command + +import cc.fyre.shard.command.data.command.Command +import cc.fyre.shard.command.data.parameter.Parameter +import cc.fyre.hcf.faction.command.parameter.FactionParameterProvider +import cc.fyre.hcf.faction.Faction +import org.bukkit.command.CommandSender + +/** + * @project hcf + * + * @date 24/07/2020 + * @author xanderume@gmail.com + */ +object FactionInfoCommand { + + @JvmStatic + @Command(names = ["faction info","fac info","f info","team info","t info","faction who","fac who","f who","team who","t who","faction show","fac show","f show","team show","t show","faction i","fac i","f i","team i","t i"]) + fun execute(sender: CommandSender,@Parameter(name = "faction",false,FactionParameterProvider.SELF_ARGUMENT)faction: Faction) { + faction.sendInfo(sender) + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/FactionLeaveCommand.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/FactionLeaveCommand.kt new file mode 100644 index 0000000..811e2ea --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/FactionLeaveCommand.kt @@ -0,0 +1,52 @@ +package cc.fyre.hcf.faction.command + +import cc.fyre.shard.command.data.command.Command +import cc.fyre.hcf.faction.FactionHandler +import cc.fyre.hcf.faction.type.player.FactionRole +import cc.fyre.hcf.timer.TimerHandler +import cc.fyre.hcf.timer.TimerType +import org.bukkit.ChatColor +import org.bukkit.entity.Player + +/** + * @project hcf + * + * @date 05/07/2020 + * @author xanderume@gmail.com + */ +object FactionLeaveCommand { + + @JvmStatic + @Command(names = ["faction leave","fac leave","f leave","team leave","t leave"]) + fun execute(player: Player) { + + val faction = FactionHandler.getFactionByPlayer(player.uniqueId) + + if (faction == null) { + player.sendMessage("${ChatColor.RED}You are not in a faction!") + return + } + + if (faction.getRole(player.uniqueId) == FactionRole.LEADER) { + player.sendMessage("${ChatColor.RED}${ChatColor.BOLD}Please choose a new leader or disband the faction.") + return + } + + if (faction.claims.any{it.contains(player.location)}) { + player.sendMessage("${ChatColor.RED}Please leave your faction's territory before leaving.") + return + } + + if (TimerHandler.hasTimer(player.uniqueId, TimerType.SPAWN_TAG)) { + player.sendMessage("${ChatColor.RED}You cannot leave your faction whilst spawn-tagged!") + return + } + + faction.removeMember(player.uniqueId,null) + faction.flagForSave() + + faction.sendMessage("${ChatColor.YELLOW}${player.name} has left the faction!") + player.sendMessage("${ChatColor.YELLOW}You have left the faction!") + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/FactionListCommand.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/FactionListCommand.kt new file mode 100644 index 0000000..4b936bb --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/FactionListCommand.kt @@ -0,0 +1,61 @@ +package cc.fyre.hcf.faction.command + +import cc.fyre.hcf.faction.list.FactionList +import cc.fyre.hcf.faction.list.FactionListType +import cc.fyre.shard.command.data.command.Command +import cc.fyre.shard.command.data.parameter.Parameter +import mkremins.fanciful.FancyMessage +import net.minecraft.util.org.apache.commons.lang3.StringUtils +import org.bukkit.ChatColor +import org.bukkit.command.CommandSender + +/** + * @project hcf + * + * @date 06/07/2020 + * @author xanderume@gmail.com + */ +object FactionListCommand { + + val LINE = "${ChatColor.GRAY}${ChatColor.STRIKETHROUGH}${StringUtils.repeat("-", 53)}" + + @JvmStatic + @Command(names = ["faction list","fac list","f list","team list","t list"]) + fun execute(sender: CommandSender,@Parameter(name = "page",false,"1")page: Int) { + + if (page <= 0) { + sender.sendMessage("${ChatColor.RED}Page number must be positive.") + return + } + + val max = FactionList.getMaxPages(FactionListType.MAX_ONLINE) + + var index = page + + if (index >= max) { + index = max + } + + sender.sendMessage(LINE) + sender.sendMessage("${ChatColor.BLUE}Faction List ${ChatColor.GRAY}Page (${index}/$max)") + + for (faction in FactionList.getPage(FactionListType.MAX_ONLINE,index - 1)) { + + FancyMessage() + .text("${faction.index + 1}. ").color(ChatColor.GRAY).then() + .text(faction.value.name).color(ChatColor.YELLOW) + .tooltip("${ChatColor.YELLOW}DTR: ${faction.value.getDTRDisplay()}${ChatColor.YELLOW}/${faction.value.getMaxDTR()}\n${ChatColor.GREEN}Click to view faction info.") + .command("/faction info ${faction.value.name}") + .then() + .text(" (${faction.value.onlineMembers}/${faction.value.members.size})").color(ChatColor.GREEN) + .send(sender) + } + + + sender.sendMessage("${ChatColor.GRAY}You are currently on ${ChatColor.WHITE}Page $index/$max${ChatColor.GRAY}.") + sender.sendMessage("${ChatColor.GRAY}To view other pages, use ${ChatColor.YELLOW}/faction list ${ChatColor.GRAY}.") + sender.sendMessage(LINE) + + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/FactionLocationCommand.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/FactionLocationCommand.kt new file mode 100644 index 0000000..4547eed --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/FactionLocationCommand.kt @@ -0,0 +1,42 @@ +package cc.fyre.hcf.faction.command + +import cc.fyre.shard.command.data.command.Command +import cc.fyre.shard.command.data.parameter.Parameter +import cc.fyre.hcf.HCF +import cc.fyre.hcf.faction.FactionHandler +import cc.fyre.hcf.faction.type.PlayerFaction +import cc.fyre.hcf.faction.type.player.ChatMode +import cc.fyre.shard.command.data.parameter.impl.PlayerParameterAdapter +import org.bukkit.ChatColor +import org.bukkit.entity.Player + +/** + * @project hcf + * + * @date 14/09/2020 + * @author xanderume@gmail.com + */ +object FactionLocationCommand { + + @JvmStatic + @Command(names = ["faction tl","fac tl","f tl","team tl","t tl","tl"]) + fun execute(player: Player,@Parameter(name = "player",defaultValue = PlayerParameterAdapter.SELF_KEY_WORD)target: Player) { + + val faction = FactionHandler.getFactionByPlayer(player.uniqueId) + + if (faction == null) { + player.sendMessage("${ChatColor.RED}You are not in a faction!") + return + } + + if (!faction.members.containsKey(target.uniqueId)) { + player.sendMessage("${ChatColor.RED}${target.name} is not in your faction!") + return + } + + val message = "[${target.location.blockX}, ${target.location.blockY}, ${target.location.blockZ}] - ${FactionHandler.getFactionByLocation(target.location).getDisplayName(faction)}" + + faction.getOnlineMembers().forEach{it.sendMessage(ChatMode.FACTION.toChatFormat(target,it,message,faction))} + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/FactionLocationHomeCommand.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/FactionLocationHomeCommand.kt new file mode 100644 index 0000000..cfc59a7 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/FactionLocationHomeCommand.kt @@ -0,0 +1,41 @@ +package cc.fyre.hcf.faction.command + +import cc.fyre.shard.command.data.command.Command +import cc.fyre.hcf.HCF +import cc.fyre.hcf.faction.FactionHandler +import cc.fyre.hcf.faction.type.PlayerFaction +import cc.fyre.hcf.faction.type.player.ChatMode +import org.bukkit.ChatColor +import org.bukkit.entity.Player + +/** + * @project hcf + * + * @date 16/09/2020 + * @author xanderume@gmail.com + */ +object FactionLocationHomeCommand { + + @JvmStatic + @Command(names = ["faction thl","fac thl","f thl","team thl","t thl","thl"]) + fun execute(player: Player) { + + val faction = FactionHandler.getFactionByPlayer(player.uniqueId) + + if (faction == null) { + player.sendMessage("${ChatColor.RED}You are not in a faction!") + return + } + + if (faction.getHQ() == null) { + player.sendMessage("${ChatColor.RED}HQ not set.") + return + } + + val message = "[${faction.getHQ()!!.blockX}, ${faction.getHQ()!!.blockY}, ${faction.getHQ()!!.blockZ}] - HQ" + + faction.getOnlineMembers().forEach{it.sendMessage(ChatMode.FACTION.toChatFormat(player,it,message,faction))} + } + + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/FactionMapCommand.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/FactionMapCommand.kt new file mode 100644 index 0000000..60c9da7 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/FactionMapCommand.kt @@ -0,0 +1,82 @@ +package cc.fyre.hcf.faction.command + +import cc.fyre.hcf.faction.FactionMetadata +import cc.fyre.hcf.faction.claim.Claim +import cc.fyre.hcf.faction.claim.ClaimHandler +import cc.fyre.hcf.faction.type.SystemFaction +import cc.fyre.hcf.pillar.PillarHandler +import cc.fyre.hcf.pillar.PillarType +import cc.fyre.hcf.statistic.StatisticHandler +import cc.fyre.hcf.statistic.type.setting.MapSetting +import cc.fyre.shard.command.data.command.Command +import cc.fyre.shard.util.item.ItemUtil +import org.bukkit.ChatColor +import org.bukkit.Location +import org.bukkit.Material +import org.bukkit.entity.Player +import org.bukkit.inventory.ItemStack +import org.bukkit.scoreboard.Team + +/** + * @project hcf + * + * @date 29/08/2020 + * @author xanderume@gmail.com + */ +object FactionMapCommand { + + const val MAP_RADIUS = 50 + + @JvmStatic + @Command(names = ["faction map","fac map","f map","team map","t map","map"]) + fun execute(player: Player) { + + val claims = ClaimHandler.getClaimDataByRadius(player.location,MAP_RADIUS,MAP_RADIUS) + + if (claims.isEmpty()) { + player.sendMessage("${ChatColor.RED}There are no factions within a $MAP_RADIUS block radius.") + return + } + + val value = StatisticHandler.getStatistic(player.uniqueId,MapSetting).getValue() + + if (value) { + player.sendMessage("${ChatColor.RED}Claim pillars have been hidden.") + + PillarHandler.destroyPillars(player,PillarType.CLAIM) + } else { + + var index = 0 + + for ((claim, faction) in claims) { + + if (faction is SystemFaction && faction.hasMetadata(FactionMetadata.ROAD)) { + continue + } + + if (index >= PillarType.CLAIM.materials.lastIndex) { + index = 0 + } + + val material = PillarType.CLAIM.materials[index++] + val locations = arrayListOf() + + for (corner in claim.getCorners()) { + + for (i in 1..256) { + locations.add(corner.clone().add(0.0,i.toDouble(),0.0)) + } + + } + + PillarHandler.createPillars(player, PillarType.CLAIM, locations, material, true) + + player.sendMessage("${ChatColor.YELLOW}Faction ${faction.getDisplayName(player)}${ChatColor.YELLOW} has been displayed with ${ChatColor.BLUE}${ItemUtil.getName(ItemStack(material))}${ChatColor.YELLOW}.") + } + + } + + StatisticHandler.setStatistic(player.uniqueId,MapSetting,!value) + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/FactionRallyCommand.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/FactionRallyCommand.kt new file mode 100644 index 0000000..f833bba --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/FactionRallyCommand.kt @@ -0,0 +1,42 @@ +package cc.fyre.hcf.faction.command + +import cc.fyre.shard.command.data.command.Command +import cc.fyre.shard.util.TimeUtil +import cc.fyre.hcf.faction.FactionHandler +import cc.fyre.hcf.faction.type.PlayerFaction +import com.lunarclient.bukkitapi.LunarClientAPI + +import org.bukkit.ChatColor +import org.bukkit.entity.Player + +/** + * @project hcf + * + * @date 26/07/2020 + * @author xanderume@gmail.com + */ +object FactionRallyCommand { + + @Command(names = ["faction rally","fac rally","f rally","team rally","t rally"]) + fun execute(player: Player) { + + val faction = FactionHandler.getFactionByPlayer(player.uniqueId) + + if (faction == null) { + player.sendMessage("${ChatColor.RED}You are not in a faction!") + return + } + + val members = faction.getOnlineMembers() + + if (faction.rally != null) { + members.forEach{LunarClientAPI.getInstance().removeWaypoint(it,faction.rallyWayPoint)} + } + + faction.setRally(player.location.clone().add(0.5,0.0,0.5)) + faction.sendMessage("${ChatColor.DARK_AQUA}${player.name} has updated the faction's rally point, this will last for ${TimeUtil.formatIntoDetailedString(PlayerFaction.RALLY_DURATION_MILLISECONDS)}!") + + members.forEach{LunarClientAPI.getInstance().sendWaypoint(it,faction.rallyWayPoint)} + } + +} diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/FactionRegenCommand.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/FactionRegenCommand.kt new file mode 100644 index 0000000..0b70d53 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/FactionRegenCommand.kt @@ -0,0 +1,48 @@ +package cc.fyre.hcf.faction.command + +import cc.fyre.shard.command.data.command.Command +import cc.fyre.shard.util.TimeUtil +import cc.fyre.hcf.HCF +import cc.fyre.hcf.faction.FactionHandler +import cc.fyre.hcf.faction.type.PlayerFaction +import cc.fyre.hcf.faction.type.player.RegenState +import org.bukkit.ChatColor +import org.bukkit.entity.Player + +/** + * @project hcf + * + * @date 25/07/2020 + * @author xanderume@gmail.com + */ +object FactionRegenCommand { + + @JvmStatic + @Command(names = ["faction regen","fac regen","f regen","team regen","t regen","regen"]) + fun execute(player: Player) { + + val faction = FactionHandler.getFactionByPlayer(player.uniqueId) + + if (faction == null) { + player.sendMessage("${ChatColor.RED}You are not in a faction!") + return + } + + faction.updateDTR() + + val dtrState = faction.getDTRState() + + if (dtrState == RegenState.FULL) { + player.sendMessage("${ChatColor.RED}Your faction has full DTR.") + return + } + + if (dtrState == RegenState.PAUSED) { + player.sendMessage("${ChatColor.YELLOW}Your faction is on DTR freeze for another ${ChatColor.LIGHT_PURPLE}${TimeUtil.formatIntoDetailedString(faction.getDTRFreeze())}${ChatColor.YELLOW}.") + return + } + + player.sendMessage("${ChatColor.YELLOW}Your faction has ${ChatColor.LIGHT_PURPLE}${faction.getDTR(false)}${ChatColor.YELLOW} DTR and is regenerating at a rate of ${ChatColor.LIGHT_PURPLE}${ChatColor.LIGHT_PURPLE}${PlayerFaction.DTR_UPDATE_INCREMENT * faction.onlineMembers}${ChatColor.YELLOW} every ${ChatColor.LIGHT_PURPLE}${TimeUtil.formatIntoDetailedString(PlayerFaction.DTR_UPDATE_TIME)}.") + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/FactionStuckCommand.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/FactionStuckCommand.kt new file mode 100644 index 0000000..05f3562 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/FactionStuckCommand.kt @@ -0,0 +1,44 @@ +package cc.fyre.hcf.faction.command + +import cc.fyre.shard.command.data.command.Command +import cc.fyre.hcf.HCF +import cc.fyre.hcf.faction.FactionHandler +import cc.fyre.hcf.faction.type.PlayerFaction +import cc.fyre.hcf.timer.TimerHandler +import cc.fyre.hcf.timer.TimerType +import org.bukkit.ChatColor +import org.bukkit.World +import org.bukkit.entity.Player + +/** + * @project hcf + * + * @date 07/07/2020 + * @author xanderume@gmail.com + */ +object FactionStuckCommand { + + @Command(names = ["faction stuck","fac stuck","f stuck","team stuck","t stuck","stuck"]) + fun execute(player: Player) { + + if (player.world.environment != World.Environment.NORMAL) { + player.sendMessage("${ChatColor.RED}You cannot use this command in the ${player.world.environment.name.lowercase().replace("_","")}.") + return + } + + if (TimerHandler.hasTimer(player.uniqueId, TimerType.STUCK)) { + player.sendMessage("${ChatColor.RED}You are already being warped!") + return + } + + val faction = FactionHandler.getFactionByLocation(player.location) + + if (faction !is PlayerFaction) { + player.sendMessage("${ChatColor.RED}You cannot use this command in ${faction.getDisplayName(player)}${ChatColor.RED}.") + return + } + + TimerHandler.addTimer(player.uniqueId, TimerType.STUCK) + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/FactionTopCommand.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/FactionTopCommand.kt new file mode 100644 index 0000000..417cb97 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/FactionTopCommand.kt @@ -0,0 +1,60 @@ +package cc.fyre.hcf.faction.command + +import cc.fyre.core.uuid.UUIDHandler +import cc.fyre.shard.command.data.command.Command +import cc.fyre.hcf.faction.FactionHandler +import cc.fyre.hcf.faction.list.FactionList +import cc.fyre.hcf.faction.list.FactionListType +import cc.fyre.shard.command.data.parameter.Parameter +import mkremins.fanciful.FancyMessage +import org.bukkit.ChatColor +import org.bukkit.command.CommandSender + +/** + * @project hcf + * + * @date 06/07/2020 + * @author xanderume@gmail.com + */ +object FactionTopCommand { + + @JvmStatic + @Command(names = ["faction top","fac top","f top","team top","t top"]) + fun execute(sender: CommandSender,@Parameter(name = "page",false,"1")page: Int) { + + if (page <= 0) { + sender.sendMessage("${ChatColor.RED}Page number must be positive.") + return + } + + val max = FactionList.getMaxPages(FactionListType.POINTS) + + var index = page + + if (index >= max) { + index = max + } + + sender.sendMessage(FactionListCommand.LINE) + sender.sendMessage("${ChatColor.GOLD}Faction Top ${ChatColor.GRAY}Page (${index}/$max)") + + for (faction in FactionList.getPage(FactionListType.POINTS,index - 1)) { + + FancyMessage() + .text("${faction.index + 1}. ").color(ChatColor.GRAY).then() + .text(faction.value.name).color(ChatColor.YELLOW) + .tooltip("${ChatColor.YELLOW}DTR: ${faction.value.getDTRDisplay()}${ChatColor.YELLOW}/${faction.value.getMaxDTR()}\n${ChatColor.GREEN}Click to view faction info.") + .command("/faction info ${faction.value.name}") + .then() + .text(" (${faction.value.onlineMembers}/${faction.value.members.size})").color(ChatColor.GREEN) + .send(sender) + } + + + sender.sendMessage("${ChatColor.GRAY}You are currently on ${ChatColor.WHITE}Page $index/$max${ChatColor.GRAY}.") + sender.sendMessage("${ChatColor.GRAY}To view other pages, use ${ChatColor.YELLOW}/faction list ${ChatColor.GRAY}.") + sender.sendMessage(FactionListCommand.LINE) + + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/admin/FactionBalanceAddCommand.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/admin/FactionBalanceAddCommand.kt new file mode 100644 index 0000000..3ee15bf --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/admin/FactionBalanceAddCommand.kt @@ -0,0 +1,34 @@ +package cc.fyre.hcf.faction.command.admin + +import cc.fyre.shard.command.data.command.Command +import cc.fyre.shard.command.data.parameter.Parameter +import cc.fyre.hcf.faction.type.PlayerFaction +import cc.fyre.core.uuid.UUIDHandler + +import org.bukkit.ChatColor +import org.bukkit.command.CommandSender +import org.bukkit.entity.Player + +/** + * @project hcf + * + * @date 26/07/2020 + * @author xanderume@gmail.com + */ +object FactionBalanceAddCommand { + + @JvmStatic + @Command(names = ["faction balance add","fac balance add","f balance add","team balance add","t balance add","faction bal add","fac bal add","f bal add","team bal add","t bal add"],hidden = true,permission = "hcf.command.faction.balance.add") + fun execute(sender: CommandSender,@Parameter(name = "faction")faction: PlayerFaction,@Parameter(name = "balance")amount: Int,@Parameter(name = "reason")reason: String) { + + if (amount <= 0) { + sender.sendMessage("${ChatColor.RED}Amount must be positive.") + return + } + + faction.balance += amount + + sender.sendMessage("${ChatColor.YELLOW}Faction ${ChatColor.LIGHT_PURPLE}${faction.name}${ChatColor.YELLOW} now has ${ChatColor.LIGHT_PURPLE}$${faction.balance}${ChatColor.YELLOW}.") + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/admin/FactionBalanceRemoveCommand.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/admin/FactionBalanceRemoveCommand.kt new file mode 100644 index 0000000..53423ff --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/admin/FactionBalanceRemoveCommand.kt @@ -0,0 +1,33 @@ +package cc.fyre.hcf.faction.command.admin + +import cc.fyre.shard.command.data.command.Command +import cc.fyre.shard.command.data.parameter.Parameter +import cc.fyre.hcf.faction.type.PlayerFaction +import cc.fyre.core.uuid.UUIDHandler +import org.bukkit.ChatColor +import org.bukkit.command.CommandSender +import org.bukkit.entity.Player + +/** + * @project hcf + * + * @date 26/07/2020 + * @author xanderume@gmail.com + */ +object FactionBalanceRemoveCommand { + + @JvmStatic + @Command(names = ["faction balance remove","fac balance remove","f balance remove","team balance remove","t balance remove","faction bal remove","fac bal remove","f bal remove","team bal remove","t bal remove"],hidden = true,permission = "hcf.command.faction.balance.remove") + fun execute(sender: CommandSender, @Parameter(name = "faction")faction: PlayerFaction, @Parameter(name = "balance")amount: Int, @Parameter(name = "reason")reason: String) { + + if (amount <= 0) { + sender.sendMessage("${ChatColor.RED}Amount must be positive.") + return + } + + faction.balance -= amount + + sender.sendMessage("${ChatColor.YELLOW}Faction ${ChatColor.LIGHT_PURPLE}${faction.name}${ChatColor.YELLOW} now has ${ChatColor.LIGHT_PURPLE}$${faction.balance}${ChatColor.YELLOW}.") + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/admin/FactionBanCommand.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/admin/FactionBanCommand.kt new file mode 100644 index 0000000..1fb97fe --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/admin/FactionBanCommand.kt @@ -0,0 +1,94 @@ +package cc.fyre.hcf.faction.command.admin + +import cc.fyre.core.profile.ProfileHandler +import cc.fyre.core.profile.punishment.PunishmentType +import cc.fyre.core.profile.punishment.command.BanCommand +import cc.fyre.core.profile.update.ProfileUpdateResult +import cc.fyre.core.profile.update.ProfileUpdateType +import cc.fyre.shard.command.data.command.Command +import cc.fyre.shard.command.data.option.Option +import cc.fyre.shard.command.data.parameter.Parameter +import cc.fyre.hcf.faction.type.PlayerFaction +import cc.fyre.core.uuid.UUIDHandler +import cc.fyre.hcf.HCF +import cc.fyre.shard.constants.ApiConstants +import org.bukkit.Bukkit +import org.bukkit.ChatColor +import org.bukkit.command.CommandSender +import org.bukkit.entity.Player +import retrofit2.Call +import retrofit2.Callback +import retrofit2.Response + +/** + * @project hcf + * + * @date 05/07/2020 + * @author xanderume@gmail.com + */ +object FactionBanCommand { + + @JvmStatic + @Command(names = ["faction ban","fac ban","f ban","team ban","t ban"],hidden = true,permission = "hcf.command.faction.ban") + fun execute(sender: CommandSender,@Option(["p","public"])public: Boolean, @Parameter(name = "faction")faction: PlayerFaction, @Parameter(name = "duration")duration: Long, @Parameter(name = "reason",true)reason: String) { + + val senderUuid = if (sender is Player) sender.uniqueId else UUIDHandler.CONSOLE_ID + val members = faction.getOnlineMembers().toList() + + var index = 0 + + sender.sendMessage("${ChatColor.GREEN}Queueing ${ChatColor.YELLOW}${members.size}${ChatColor.GREEN} bans..") + Bukkit.getServer().scheduler.runTaskTimerAsynchronously(HCF.instance,Runnable{ + + if (index > members.lastIndex) { + return@Runnable + } + + val member = members[index++] + + ProfileHandler.getService().updateByUsername(member.name,ProfileUpdateType.ADD_PUNISHMENT.toRequest( + "type" to PunishmentType.BAN.name, + "silent" to !public, + "reason" to reason, + "duration" to duration, + "punishedAt" to System.currentTimeMillis(), + "punishedBy" to senderUuid + )).enqueue(object : Callback { + + override fun onFailure(call: Call, t: Throwable) { + sender.sendMessage(ApiConstants.API_REQUEST_FAILED) + } + + override fun onResponse(call: Call,response: Response) { + + val result = response.body() + + if (result == null) { + sender.sendMessage(ApiConstants.API_REQUEST_FAILED) + return + } + + + if (sender is Player && !sender.isOnline) { + return + } + + val message = when (result.type) { + ProfileUpdateResult.Type.SUCCESS -> null + ProfileUpdateResult.Type.BAD_REQUEST -> ApiConstants.API_REQUEST_FAILED + ProfileUpdateResult.Type.NOT_FOUND -> "${ChatColor.RED}No player with the name \"${member.name}\" found." + ProfileUpdateResult.Type.NOT_FOUND_MOJANG -> "${ChatColor.RED}No player with the name \"${member.name}\" found in mojang database." + ProfileUpdateResult.Type.PUNISHMENT_USER_PROTECTED -> "${ChatColor.RED}You cannot ${PunishmentType.BAN.name.lowercase()} ${result.data!!.getString("displayName")}${ChatColor.RED}." + ProfileUpdateResult.Type.PUNISHMENT_EXECUTOR_NOT_FOUND -> "${ApiConstants.API_REQUEST_FAILED} [2]" + else -> null + } ?: return + + sender.sendMessage(message) + } + + }) + },20L,(members.size - 1) * 20L) + + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/admin/FactionBlacklistCommand.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/admin/FactionBlacklistCommand.kt new file mode 100644 index 0000000..ebc9dbf --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/admin/FactionBlacklistCommand.kt @@ -0,0 +1,95 @@ +package cc.fyre.hcf.faction.command.admin + +import cc.fyre.core.profile.ProfileHandler +import cc.fyre.core.profile.punishment.PunishmentType +import cc.fyre.core.profile.update.ProfileUpdateResult +import cc.fyre.core.profile.update.ProfileUpdateType +import cc.fyre.shard.command.data.command.Command +import cc.fyre.shard.command.data.option.Option +import cc.fyre.shard.command.data.parameter.Parameter +import cc.fyre.hcf.faction.type.PlayerFaction +import cc.fyre.core.uuid.UUIDHandler +import cc.fyre.hcf.HCF +import cc.fyre.shard.constants.ApiConstants +import org.bukkit.Bukkit +import org.bukkit.ChatColor +import org.bukkit.command.CommandSender +import org.bukkit.entity.Player +import retrofit2.Call +import retrofit2.Callback +import retrofit2.Response + +/** + * @project hcf + * + * @date 05/07/2020 + * @author xanderume@gmail.com + */ +object FactionBlacklistCommand { + + + @JvmStatic + @Command(names = ["faction blacklist","fac blacklist","f blacklist","team blacklist","t blacklist"],hidden = true,permission = "hcf.command.faction.blacklist") + fun execute(sender: CommandSender, @Option(["p","public"])public: Boolean, @Parameter(name = "faction")faction: PlayerFaction, @Parameter(name = "duration")duration: Long, @Parameter(name = "reason",true)reason: String) { + + + val senderUuid = if (sender is Player) sender.uniqueId else UUIDHandler.CONSOLE_ID + val members = faction.getOnlineMembers().toList() + + var index = 0 + + sender.sendMessage("${ChatColor.GREEN}Queueing ${ChatColor.YELLOW}${members.size}${ChatColor.GREEN} bans..") + Bukkit.getServer().scheduler.runTaskTimerAsynchronously(HCF.instance,Runnable{ + + if (index > members.lastIndex) { + return@Runnable + } + + val member = members[index++] + + ProfileHandler.getService().updateByUsername(member.name, ProfileUpdateType.ADD_PUNISHMENT.toRequest( + "type" to PunishmentType.BLACKLIST.name, + "silent" to !public, + "reason" to reason, + "duration" to duration, + "punishedAt" to System.currentTimeMillis(), + "punishedBy" to senderUuid + )).enqueue(object : Callback { + + override fun onFailure(call: Call, t: Throwable) { + sender.sendMessage(ApiConstants.API_REQUEST_FAILED) + } + + override fun onResponse(call: Call, response: Response) { + + val result = response.body() + + if (result == null) { + sender.sendMessage(ApiConstants.API_REQUEST_FAILED) + return + } + + + if (sender is Player && !sender.isOnline) { + return + } + + val message = when (result.type) { + ProfileUpdateResult.Type.SUCCESS -> null + ProfileUpdateResult.Type.BAD_REQUEST -> ApiConstants.API_REQUEST_FAILED + ProfileUpdateResult.Type.NOT_FOUND -> "${ChatColor.RED}No player with the name \"${member.name}\" found." + ProfileUpdateResult.Type.NOT_FOUND_MOJANG -> "${ChatColor.RED}No player with the name \"${member.name}\" found in mojang database." + ProfileUpdateResult.Type.PUNISHMENT_USER_PROTECTED -> "${ChatColor.RED}You cannot ${PunishmentType.BLACKLIST.name.lowercase()} ${result.data!!.getString("displayName")}${ChatColor.RED}." + ProfileUpdateResult.Type.PUNISHMENT_EXECUTOR_NOT_FOUND -> "${ApiConstants.API_REQUEST_FAILED} [2]" + else -> null + } ?: return + + sender.sendMessage(message) + } + + }) + },20L,(members.size - 1) * 20L) + + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/admin/FactionChatSpyAddCommand.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/admin/FactionChatSpyAddCommand.kt new file mode 100644 index 0000000..cb00bce --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/admin/FactionChatSpyAddCommand.kt @@ -0,0 +1,36 @@ +package cc.fyre.hcf.faction.command.admin + +/** + * @project hcf + * + * @date 26/07/2020 + * @author xanderume@gmail.com + */ +object FactionChatSpyAddCommand { +/* + @JvmStatic + @Command(names = ["faction chatspy add","fac chatspy add","f chatspy add","team chatspy add","t chatspy add"],hidden = true,permission = "hcf.command.faction.chatspy.add") + fun execute(player: Player,@Parameter(name = "faction")faction: PlayerFaction) { + + val optionalProfile = StatisticHandler.findById(player.uniqueId) + + if (!optionalProfile.isPresent) { + player.sendMessage("${ChatColor.RED}There was an issue fetching your chatspy data please try relogging.") + return + } + + val profile = optionalProfile.get() + + if (profile.chatSpy.contains(faction.id)) { + player.sendMessage("${ChatColor.RED}You are already spying on ${faction.getDisplayName(player)}${ChatColor.RED}'s messages.") + return + } + + profile.chatSpy.add(faction.id) + + StatisticHandler.updateAsync(profile) + + player.sendMessage("${ChatColor.YELLOW}You are now spying on ${faction.getDisplayName(player)}${ChatColor.YELLOW}'s messages.") + } +TODO */ +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/admin/FactionChatSpyRemoveCommand.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/admin/FactionChatSpyRemoveCommand.kt new file mode 100644 index 0000000..3b0d5bf --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/admin/FactionChatSpyRemoveCommand.kt @@ -0,0 +1,36 @@ +package cc.fyre.hcf.faction.command.admin + +/** + * @project hcf + * + * @date 26/07/2020 + * @author xanderume@gmail.com + */ +object FactionChatSpyRemoveCommand { +/* + @JvmStatic + @Command(names = ["faction chatspy remove","fac chatspy remove","f chatspy remove","team chatspy remove","t chatspy remove"],hidden = true,permission = "hcf.command.faction.chatspy.remove") + fun execute(player: Player, @Parameter(name = "faction")faction: PlayerFaction) { + + val optionalProfile = StatisticHandler.findById(player.uniqueId) + + if (!optionalProfile.isPresent) { + player.sendMessage("${ChatColor.RED}There was an issue fetching your chatspy data please try relogging.") + return + } + + val profile = optionalProfile.get() + + if (!profile.chatSpy.contains(faction.id)) { + player.sendMessage("${ChatColor.RED}You are not spying on ${faction.getDisplayName(player)}${ChatColor.RED}'s messages.") + return + } + + profile.chatSpy.remove(faction.id) + + StatisticHandler.updateAsync(profile) + + player.sendMessage("${ChatColor.YELLOW}You are no longer spying on ${faction.getDisplayName(player)}${ChatColor.YELLOW}'s messages.") + } +*TODO */ +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/admin/FactionDisbandAllCommand.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/admin/FactionDisbandAllCommand.kt new file mode 100644 index 0000000..cd7ad3d --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/admin/FactionDisbandAllCommand.kt @@ -0,0 +1,81 @@ +package cc.fyre.hcf.faction.command.admin + +import cc.fyre.shard.command.data.command.Command +import org.bukkit.ChatColor +import org.bukkit.command.CommandSender +import org.bukkit.entity.Player + +/** + * @project hcf + * + * @date 25/08/2020 + * @author xanderume@gmail.com + */ +object FactionDisbandAllCommand { + + var confirm = true + + @JvmStatic + @Command(names = ["faction disbandall","fac disbandall","f disbandall","team disbandall","t disbandall"],hidden = true,permission = "hcf.command.faction.disbandall") + fun execute(sender: CommandSender) { + + if (sender is Player) { + return + } + + this.confirm = true + + sender.sendMessage("${ChatColor.RED}Are you sure you want to disband all factions? ${ChatColor.DARK_RED}/faction forcedisbandall confirm${ChatColor.RED} to confirm or ${ChatColor.DARK_GREEN}/faction forcedisbandall cancel${ChatColor.RED} to cancel.") + } + + @JvmStatic + @Command(names = ["faction disbandall cancel","fac disbandall cancel","f disbandall cancel","team disbandall cancel","t disbandall cancel"],hidden = true,permission = "hcf.command.faction.disbandall") + fun cancel(sender: CommandSender) { + + if (!this.confirm) { + sender.sendMessage("${ChatColor.RED}Nothing to cancel.") + return + } + + sender.sendMessage("${ChatColor.GREEN}Cancelled.") + } + + @JvmStatic + @Command(names = ["faction disbandall confirm","fac disbandall confirm","f disbandall confirm","team disbandall confirm","t disbandall confirm"],hidden = true,permission = "hcf.command.faction.disbandall") + fun confirm(sender: CommandSender) { + + if (this.confirm) { + sender.sendMessage("${ChatColor.RED}Nothing to confirm.") + return + } + + sender.sendMessage("${ChatColor.YELLOW}Disbanding all factions..") + + //TODO + /* + CoroutineScope(Dispatchers.IO).launch{ + + for (faction in FactionHandler.cache.values) { + + if (!ClaimHandler.repository.deleteAll(faction) || !FactionHandler.repository.delete(faction)) { + sender.sendMessage("${ChatColor.RED}${ChatColor.BOLD}Failed to delete ${faction.getDisplayName(sender)}${ChatColor.RED}${ChatColor.BOLD}.") + continue + } + + if (faction is PlayerFaction) { + faction.members.keys.forEach{FactionHandler.uniqueIDCache.remove(it)} + } + + ClaimHandler.cache.remove(faction.id) + FactionHandler.cache.remove(faction.id) + FactionHandler.nameCache.remove(faction.name.lowercase()) + + HCF.instance.server.pluginManager.callEvent(FactionDisbandEvent(faction)) + } + + sender.sendMessage("${ChatColor.GREEN}All factions have been disbanded!") + }*/ + + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/admin/FactionEditorCommand.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/admin/FactionEditorCommand.kt new file mode 100644 index 0000000..61ea47c --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/admin/FactionEditorCommand.kt @@ -0,0 +1,32 @@ +package cc.fyre.hcf.faction.command.admin + +import cc.fyre.shard.command.data.command.Command +import cc.fyre.shard.command.data.parameter.Parameter +import cc.fyre.hcf.faction.type.SystemFaction +import cc.fyre.hcf.faction.menu.system.SystemEditMenu +import cc.fyre.hcf.faction.menu.system.SystemEditorMenu +import org.bukkit.entity.Player + +/** + * @project hcf + * + * @date 05/07/2020 + * @author xanderume@gmail.com + */ +object FactionEditorCommand { + + const val PERMISSION = "comand.faction.editor" + + @JvmStatic + @Command(names = ["faction edit","fac edit","f edit","team edit","t edit"],hidden = true,permission = PERMISSION) + fun edit(player: Player,@Parameter(name = "faction")faction: SystemFaction) { + SystemEditMenu(faction).open(player) + } + + @JvmStatic + @Command(names = ["faction editor","fac editor","f editor","team editor","t editor"],hidden = true,permission = PERMISSION) + fun execute(player: Player) { + SystemEditorMenu().open(player) + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/admin/FactionForceDisbandCommand.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/admin/FactionForceDisbandCommand.kt new file mode 100644 index 0000000..9448883 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/admin/FactionForceDisbandCommand.kt @@ -0,0 +1,34 @@ +package cc.fyre.hcf.faction.command.admin + +import cc.fyre.hcf.faction.Faction +import cc.fyre.hcf.faction.FactionHandler +import cc.fyre.shard.command.CommandHandler +import cc.fyre.shard.command.data.command.Command +import cc.fyre.shard.command.data.parameter.Parameter +import org.bukkit.ChatColor +import org.bukkit.command.CommandSender + +/** + * @project hcf + * + * @date 26/08/2020 + * @author xanderume@gmail.com + */ +object FactionForceDisbandCommand { + + @JvmStatic + @Command(names = ["faction forcedisband","fac forcedisband","f forcedisband","team forcedisband","t forcedisband","forcedisband"],hidden = true,permission = "hcf.command.faction.forcedisband") + fun execute(sender: CommandSender,@Parameter(name = "faction") faction: Faction) { + + if (!sender.isOp) { + sender.sendMessage(CommandHandler.NO_PERMISSION) + return + } + + FactionHandler.destroy(faction) + + sender.sendMessage("${ChatColor.RED}${ChatColor.BOLD}You have force disbanded ${faction.getDisplayName(sender)}${ChatColor.RED}.") + } + + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/admin/FactionForceSetHQCommand.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/admin/FactionForceSetHQCommand.kt new file mode 100644 index 0000000..6a6b4f9 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/admin/FactionForceSetHQCommand.kt @@ -0,0 +1,30 @@ +package cc.fyre.hcf.faction.command.admin + +import cc.fyre.hcf.faction.Faction +import cc.fyre.hcf.faction.FactionHandler +import cc.fyre.shard.command.CommandHandler +import cc.fyre.shard.command.data.command.Command +import cc.fyre.shard.command.data.parameter.Parameter +import org.bukkit.ChatColor +import org.bukkit.command.CommandSender +import org.bukkit.entity.Player + +object FactionForceSetHQCommand { + + @JvmStatic + @Command(names = ["faction forcesethq","fac forcesethq","f forcesethq","team forcesethq","t forcesethq","forcesethq"],hidden = true,permission = "hcf.command.faction.forcesethq") + fun execute(sender: Player, @Parameter(name = "faction") faction: Faction) { + + if (FactionHandler.getFactionByLocation(sender.location) != faction) { + sender.sendMessage("${faction.getDisplayName(sender)}${ChatColor.RED}${ChatColor.BOLD} does not own this land${ChatColor.RED}.") + return + } + + faction.setHQ(sender.location) + faction.flagForSave() + + sender.sendMessage("${ChatColor.DARK_AQUA}You have forcefully set ${faction.getDisplayName(sender)}${ChatColor.DARK_AQUA}'s HQ.") + } + + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/admin/FactionMuteCommand.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/admin/FactionMuteCommand.kt new file mode 100644 index 0000000..9e4e2ec --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/admin/FactionMuteCommand.kt @@ -0,0 +1,34 @@ +package cc.fyre.hcf.faction.command.admin + +import cc.fyre.core.profile.ProfileHandler +import cc.fyre.shard.command.data.command.Command +import cc.fyre.shard.command.data.option.Option +import cc.fyre.shard.command.data.parameter.Parameter +import cc.fyre.hcf.faction.type.PlayerFaction +import cc.fyre.core.uuid.UUIDHandler +import org.bukkit.command.CommandSender +import org.bukkit.entity.Player + +/** + * @project hcf + * + * @date 06/07/2020 + * @author xanderume@gmail.com + */ +object FactionMuteCommand { + + @JvmStatic + @Command(names = ["faction mute","fac mute","f mute","team mute","t mute"],hidden = true,permission = "hcf.command.faction.mute") + fun execute(sender: CommandSender,@Option(["p","public"])public: Boolean,@Parameter(name = "faction")faction: PlayerFaction, @Parameter(name = "duration")duration: Long, @Parameter(name = "reason",true)reason: String) { + + val senderUuid = if (sender is Player) sender.uniqueId else UUIDHandler.CONSOLE_ID + val senderName = ProfileHandler.getDisplayNameById(senderUuid) + + /*TODO + faction.getOnlineMembers().forEach{ + Venom.instance.api.punishmentHandler.punish(Punishment.Type.MUTE,it.uniqueId,senderUuid,reason, Venom.instance.serverHandler.server.id,duration,!public, ProfileHandler.getDisplayNameById(it.uniqueId,it.name, Venom.instance.serverHandler.server),senderName) + }*/ + + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/admin/FactionPointsAddCommand.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/admin/FactionPointsAddCommand.kt new file mode 100644 index 0000000..f773e82 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/admin/FactionPointsAddCommand.kt @@ -0,0 +1,34 @@ +package cc.fyre.hcf.faction.command.admin + +import cc.fyre.shard.command.data.command.Command +import cc.fyre.shard.command.data.parameter.Parameter +import cc.fyre.hcf.faction.type.PlayerFaction + +import org.bukkit.ChatColor +import org.bukkit.command.CommandSender + +/** + * @project hcf + * + * @date 05/07/2020 + * @author xanderume@gmail.com + */ +object FactionPointsAddCommand { + + const val PERMISSION = "hcf.command.faction.points.add" + + @JvmStatic + @Command(names = ["points add","points add","points add","points add","points add"],hidden = true,permission = PERMISSION) + fun execute(sender: CommandSender,@Parameter(name = "faction")faction: PlayerFaction,@Parameter(name = "points")amount: Int,@Parameter(name = "reason")reason: String) { + + if (amount <= 0) { + sender.sendMessage("${ChatColor.RED}Amount must be positive.") + return + } + + faction.points += amount + + sender.sendMessage("${ChatColor.YELLOW}Faction ${ChatColor.LIGHT_PURPLE}${faction.name}${ChatColor.YELLOW} now has ${ChatColor.LIGHT_PURPLE}${faction.points}${ChatColor.YELLOW} points.") + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/admin/FactionPointsRemoveCommand.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/admin/FactionPointsRemoveCommand.kt new file mode 100644 index 0000000..94a37a2 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/admin/FactionPointsRemoveCommand.kt @@ -0,0 +1,32 @@ +package cc.fyre.hcf.faction.command.admin + +import cc.fyre.shard.command.data.command.Command +import cc.fyre.shard.command.data.parameter.Parameter +import cc.fyre.hcf.faction.type.PlayerFaction +import org.bukkit.ChatColor +import org.bukkit.command.CommandSender + +/** + * @project hcf + * + * @date 06/07/2020 + * @author xanderume@gmail.com + */ +object FactionPointsRemoveCommand { + + @JvmStatic + @Command(names = ["points remove","points remove","points remove","points remove","points remove"],hidden = true,permission = "hcf.command.faction.points.remove") + fun execute(sender: CommandSender, @Parameter(name = "faction")faction: PlayerFaction,@Parameter(name = "points")amount: Int,@Parameter(name = "reason")reason: String) { + + if (amount <= 0) { + sender.sendMessage("${ChatColor.RED}Amount must be positive.") + return + } + + faction.points -= amount + + sender.sendMessage("${ChatColor.YELLOW}Faction ${ChatColor.LIGHT_PURPLE}${faction.name}${ChatColor.YELLOW} now has ${ChatColor.LIGHT_PURPLE}${faction.points}${ChatColor.YELLOW} points.") + } + + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/admin/FactionSetDTRCommand.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/admin/FactionSetDTRCommand.kt new file mode 100644 index 0000000..4d4b738 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/admin/FactionSetDTRCommand.kt @@ -0,0 +1,27 @@ +package cc.fyre.hcf.faction.command.admin + +import cc.fyre.shard.command.data.command.Command +import cc.fyre.shard.command.data.parameter.Parameter +import cc.fyre.hcf.faction.type.PlayerFaction +import org.bukkit.ChatColor +import org.bukkit.command.CommandSender +import kotlin.math.min + +/** + * @project hcf + * + * @date 06/07/2020 + * @author xanderume@gmail.com + */ +object FactionSetDTRCommand { + + @JvmStatic + @Command(names = ["faction setdtr","fac setdtr","f setdtr","team setdtr","t setdtr","setdtr"],hidden = true,permission = "hcf.command.faction.setdtr") + fun execute(sender: CommandSender,@Parameter(name = "faction")faction: PlayerFaction,@Parameter(name = "DTR")dtr: Double) { + faction.setDTR(min(dtr,faction.getMaxDTR())) + faction.flagForSave() + + sender.sendMessage("${ChatColor.YELLOW}Faction ${ChatColor.LIGHT_PURPLE}${faction.name}${ChatColor.YELLOW} now has ${ChatColor.LIGHT_PURPLE}${faction.getDTRDisplay().substring(2)}${ChatColor.YELLOW} DTR.") + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/admin/FactionSetDTRRegenCommand.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/admin/FactionSetDTRRegenCommand.kt new file mode 100644 index 0000000..8e15d53 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/admin/FactionSetDTRRegenCommand.kt @@ -0,0 +1,27 @@ +package cc.fyre.hcf.faction.command.admin + +import cc.fyre.shard.command.data.command.Command +import cc.fyre.shard.command.data.parameter.Parameter +import cc.fyre.shard.util.TimeUtil +import cc.fyre.hcf.faction.type.PlayerFaction +import org.bukkit.ChatColor +import org.bukkit.command.CommandSender + +/** + * @project hcf + * + * @date 06/07/2020 + * @author xanderume@gmail.com + */ +object FactionSetDTRRegenCommand { + + @JvmStatic + @Command(names = ["faction setdtrregen","fac setdtrregen","f setdtrregen","team setdtrregen","t setdtrregen","setdtrregen"],hidden = true,permission = "hcf.command.faction.setdtrregen") + fun execute(sender: CommandSender,@Parameter(name = "faction")faction: PlayerFaction,@Parameter(name = "duration")duration: Long) { + faction.setDTRFreeze(duration) + faction.flagForSave() + + sender.sendMessage("${ChatColor.YELLOW}Faction ${ChatColor.LIGHT_PURPLE}${faction.name}${ChatColor.YELLOW} is now on DTR freeze for ${ChatColor.LIGHT_PURPLE}${TimeUtil.formatIntoDetailedString(duration)}${ChatColor.YELLOW}.") + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/admin/FactionTeleportCommand.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/admin/FactionTeleportCommand.kt new file mode 100644 index 0000000..9961cae --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/admin/FactionTeleportCommand.kt @@ -0,0 +1,33 @@ +package cc.fyre.hcf.faction.command.admin + +import cc.fyre.shard.command.data.command.Command +import cc.fyre.shard.command.data.parameter.Parameter +import cc.fyre.hcf.faction.command.parameter.FactionParameterProvider +import cc.fyre.hcf.faction.Faction +import org.bukkit.ChatColor +import org.bukkit.entity.Player + +/** + * @project hcf + * + * @date 06/07/2020 + * @author xanderume@gmail.com + */ +object FactionTeleportCommand { + + @JvmStatic + @Command(names = ["faction tp","fac tp","f tp","team tp","t tp"],permission = "hcf.command.faction.teleport") + fun execute(player: Player,@Parameter(name = "faction",false,FactionParameterProvider.SELF_ARGUMENT)faction: Faction) { + + if (faction.getHQ() == null && faction.claims.isEmpty()) { + player.sendMessage("${ChatColor.LIGHT_PURPLE}${faction.name}${ChatColor.YELLOW} doesn't have a HQ or any claims.") + return + } + + val location = faction.getHQ() ?: faction.claims.iterator().next().getCenter() + + player.teleport(location) + player.sendMessage("${ChatColor.YELLOW}Teleporting to ${ChatColor.LIGHT_PURPLE}${faction.name}${ChatColor.YELLOW}.") + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/captain/FactionAllyCommand.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/captain/FactionAllyCommand.kt new file mode 100644 index 0000000..619cb11 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/captain/FactionAllyCommand.kt @@ -0,0 +1,103 @@ +package cc.fyre.hcf.faction.command.captain + +import cc.fyre.shard.command.data.command.Command +import cc.fyre.shard.command.data.parameter.Parameter +import cc.fyre.hcf.HCF +import cc.fyre.hcf.faction.Faction +import cc.fyre.hcf.faction.FactionHandler +import cc.fyre.hcf.faction.type.PlayerFaction +import cc.fyre.hcf.faction.event.FactionAllyEvent +import mkremins.fanciful.FancyMessage +import org.bukkit.ChatColor +import org.bukkit.entity.Player + +/** + * @project hcf + * + * @date 27/06/2020 + * @author xanderume@gmail.com + */ +object FactionAllyCommand { + + @JvmStatic + @Command(names = ["faction ally","fac ally","f ally","team ally","t ally"]) + fun execute(player: Player,@Parameter(name = "faction")target: PlayerFaction) { + + //TODO + val limit = 0 + + if (limit <= 0) { + player.sendMessage("${ChatColor.RED}Allies are currently disabled.") + return + } + + val faction = FactionHandler.getFactionByPlayer(player.uniqueId) + + if (faction == null) { + player.sendMessage("${ChatColor.RED}You are not in a faction!") + return + } + + if (!faction.getRole(player.uniqueId).isAbleToRequestAlly()) { + player.sendMessage("${ChatColor.RED}You cannot request alliances.") + return + } + + if (faction.id == target.id) { + player.sendMessage("${ChatColor.RED}You cannot ally your own faction!") + return + } + + if (faction.isFactionAllied(target)) { + player.sendMessage("${ChatColor.RED}Your faction is already allied to ${target.getDisplayName(player)}${ChatColor.RED}.") + return + } + + if (target.allies.size >= limit) { + player.sendMessage("${ChatColor.RED}The faction you're trying to ally already has the max number of allies, which is ${ChatColor.WHITE}$limit${ChatColor.RED}.") + return + } + + if (faction.allies.size >= limit) { + player.sendMessage("${ChatColor.RED}Your faction already has the max number of allies, which is ${ChatColor.WHITE}$limit${ChatColor.RED}.") + return + } + + if (faction.allyRequests.contains(target.id)) { + + target.allies.add(faction.id) + faction.allies.add(target.id) + + target.flagForSave() + faction.flagForSave() + + target.getOnlineMembers().forEach{it.sendMessage("${faction.getDisplayName(it)}${ChatColor.YELLOW} has accepted the ally request. The faction now has ${Faction.ALLY_COLOR}${target.allies.size}${ChatColor.YELLOW} allies.")} + faction.getOnlineMembers().forEach{it.sendMessage("${target.getDisplayName(it)}${ChatColor.YELLOW} has accepted the ally request. The faction now has ${Faction.ALLY_COLOR}${faction.allies.size}${ChatColor.YELLOW} allies.")} + + HCF.instance.server.pluginManager.callEvent(FactionAllyEvent(faction,target)) + return + } + + faction.allyRequests.add(target.id) + faction.flagForSave() + + val clickToJoin = FancyMessage("Type '").color(ChatColor.YELLOW).then("/faction ally " + faction.name).color(ChatColor.YELLOW) + + clickToJoin.then("' or ").color(ChatColor.DARK_AQUA) + clickToJoin.then("click here").color(ChatColor.AQUA).command("/faction ally " + faction.name).tooltip("${ChatColor.GREEN}Click to ally ${faction.name}!") + clickToJoin.then(" to ally.").color(ChatColor.DARK_AQUA) + + target.getOnlineMembers().forEach{ + + it.sendMessage("${faction.getDisplayName(target)}${ChatColor.DARK_AQUA} has requested to ally.") + + if (!target.getRole(it.uniqueId).isAbleToRequestAlly()) { + return@forEach + } + + clickToJoin.send(it) + } + + faction.sendMessage("${ChatColor.YELLOW}Your faction has requested ally ${target.getDisplayName(faction)}${ChatColor.YELLOW}.") + } +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/captain/FactionClaimCommand.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/captain/FactionClaimCommand.kt new file mode 100644 index 0000000..ab0c4a8 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/captain/FactionClaimCommand.kt @@ -0,0 +1,57 @@ +package cc.fyre.hcf.faction.command.captain + +import cc.fyre.shard.command.data.command.Command + +import cc.fyre.hcf.HCF +import cc.fyre.hcf.faction.FactionHandler +import cc.fyre.hcf.faction.claim.ClaimHandler + +import org.bukkit.ChatColor +import org.bukkit.entity.Player +import java.util.stream.IntStream + +/** + * @project hcf + * + * @date 07/04/2020 + * @author xanderume@gmail.com + */ +object FactionClaimCommand { + + @JvmStatic + @Command(names = ["faction claim","fac claim","f claim","team claim","t claim"]) + fun execute(player: Player) { + + val faction = FactionHandler.getFactionByPlayer(player.uniqueId) + + if (faction == null) { + player.sendMessage("${ChatColor.RED}You are not in a faction!") + return + } + + if (ClaimHandler.getSelectionByPlayer(player) != null) { + player.sendMessage("${ChatColor.RED}You already have a claiming wand in your inventory!") + return + } + + if (!faction.getRole(player.uniqueId).isAbleToClaimLand()) { + player.sendMessage("${ChatColor.RED}You cannot claim land for your faction.") + return + } + + if (faction.isRaidable()) { + player.sendMessage("${ChatColor.RED}You cannot claim land for your faction while raidable.") + return + } + + val slot = IntStream.range(0,9).filter{player.inventory.getItem(it) == null}.findFirst() + + if (!slot.isPresent) { + player.sendMessage("${ChatColor.RED}You don't have space in your hotbar for the claim wand!") + return + } + + ClaimHandler.createSelection(slot.asInt,player,faction) + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/captain/FactionInviteCommand.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/captain/FactionInviteCommand.kt new file mode 100644 index 0000000..9be5383 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/captain/FactionInviteCommand.kt @@ -0,0 +1,72 @@ +package cc.fyre.hcf.faction.command.captain + +import cc.fyre.shard.command.data.command.Command +import cc.fyre.shard.command.data.parameter.Parameter +import cc.fyre.hcf.HCF +import cc.fyre.core.uuid.UUIDHandler +import cc.fyre.hcf.faction.FactionHandler +import cc.fyre.hcf.faction.type.PlayerFaction +import mkremins.fanciful.FancyMessage +import org.bukkit.ChatColor +import org.bukkit.entity.Player +import java.util.* + +/** + * @project hcf + * + * @date 25/06/2020 + * @author xanderume@gmail.com + */ +object FactionInviteCommand { + + @JvmStatic + @Command(names = ["faction invite","fac invite","f invite","team invite","t invite","faction inv","fac inv","f inv","team inv","t inv"]) + fun execute(player: Player,@Parameter(name = "player")target: UUID) { + + val faction = FactionHandler.getFactionByPlayer(player.uniqueId) + + if (faction == null) { + player.sendMessage("${ChatColor.RED}You are not in a faction!") + return + } + + if (faction.members.size > PlayerFaction.MEMBER_LIMIT) { + player.sendMessage("${ChatColor.RED}The max faction size is ${ChatColor.WHITE}${PlayerFaction.MEMBER_LIMIT}${ChatColor.RED}.") + return + } + + if (!faction.getRole(player.uniqueId).isAbleToInvite()) { + player.sendMessage("${ChatColor.RED}You cannot invite players to the faction.") + return + } + + val name = UUIDHandler.getUsernameById(target) + + if (faction.isMember(target)) { + player.sendMessage("${ChatColor.RED}$name is already in your faction!") + return + } + + if (faction.invites.contains(target)) { + player.sendMessage("${ChatColor.RED}$name has already been invited.") + return + } + + faction.invites.add(target) + faction.flagForSave() + faction.sendMessage("${ChatColor.YELLOW}$name has been invited to the faction!") + + val targetPlayer = HCF.instance.server.getPlayer(target) ?: return + + targetPlayer.sendMessage("${ChatColor.DARK_AQUA}${player.name} invited you to join ${ChatColor.YELLOW}'${faction.name}${ChatColor.DARK_AQUA}'.") + + val clickToJoin = FancyMessage("Type '").color(ChatColor.DARK_AQUA).then("/faction join " + faction.name).color(ChatColor.YELLOW) + + clickToJoin.then("' or ").color(ChatColor.DARK_AQUA) + clickToJoin.then("click here").color(ChatColor.AQUA).command("/faction join " + faction.name).tooltip("${ChatColor.GREEN}Click to join ${faction.name}!") + clickToJoin.then(" to join.").color(ChatColor.DARK_AQUA) + + clickToJoin.send(targetPlayer) + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/captain/FactionInviteRevokeCommand.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/captain/FactionInviteRevokeCommand.kt new file mode 100644 index 0000000..738a422 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/captain/FactionInviteRevokeCommand.kt @@ -0,0 +1,69 @@ +package cc.fyre.hcf.faction.command.captain + +import cc.fyre.shard.command.data.command.Command +import cc.fyre.shard.command.data.parameter.Parameter +import cc.fyre.hcf.HCF +import cc.fyre.core.uuid.UUIDHandler +import cc.fyre.hcf.faction.FactionHandler +import org.bukkit.ChatColor +import org.bukkit.entity.Player +import java.util.* + +/** + * @project hcf + * + * @date 25/06/2020 + * @author xanderume@gmail.com + */ +object FactionInviteRevokeCommand { + + @JvmStatic + @Command(names = ["faction uninvite","fac uninvite","f uninvite","team uninvite","t uninvite","faction revoke","fac revoke","f revoke","team revoke","t revoke"]) + fun execute(player: Player,@Parameter(name = "player")target: UUID) { + + val faction = FactionHandler.getFactionByPlayer(player.uniqueId) + + if (faction == null) { + player.sendMessage("${ChatColor.RED}You are not in a faction!") + return + } + + if (!faction.getRole(player.uniqueId).isAbleToInvite()) { + player.sendMessage("${ChatColor.RED}You cannot un-invite players from the faction.") + return + } + + val name = UUIDHandler.getUsernameById(target) + + if (!faction.invites.contains(target)) { + player.sendMessage("${ChatColor.RED}${name} has not been invited to the faction!") + return + } + + faction.invites.remove(target) + faction.sendMessage("${ChatColor.LIGHT_PURPLE}${player.name} ${ChatColor.YELLOW}has revoked ${ChatColor.LIGHT_PURPLE}${name}${ChatColor.YELLOW}'s invite!") + faction.flagForSave() + } + + @JvmStatic + @Command(names = ["faction uninvite all","fac uninvite all","f uninvite all","team uninvite all","t uninvite all","faction revoke all","fac revoke all","f revoke all","team revoke all","t revoke all"]) + fun execute(player: Player) { + + val faction = FactionHandler.getFactionByPlayer(player.uniqueId) + + if (faction == null) { + player.sendMessage("${ChatColor.RED}You are not in a faction!") + return + } + + if (!faction.getRole(player.uniqueId).isAbleToInvite()) { + player.sendMessage("${ChatColor.RED}You cannot un-invite players from the faction.") + return + } + + faction.invites.clear() + faction.flagForSave() + faction.sendMessage("${ChatColor.RED}${ChatColor.BOLD}${player.name} has cleared all invites!") + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/captain/FactionKickCommand.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/captain/FactionKickCommand.kt new file mode 100644 index 0000000..fd18bbe --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/captain/FactionKickCommand.kt @@ -0,0 +1,57 @@ +package cc.fyre.hcf.faction.command.captain + +import cc.fyre.shard.command.data.command.Command +import cc.fyre.shard.command.data.parameter.Parameter +import cc.fyre.hcf.HCF +import cc.fyre.hcf.faction.event.FactionMemberRemoveEvent +import cc.fyre.core.uuid.UUIDHandler +import cc.fyre.hcf.faction.FactionHandler +import org.bukkit.ChatColor +import org.bukkit.entity.Player +import java.util.* + +/** + * @project hcf + * + * @date 05/07/2020 + * @author xanderume@gmail.com + */ +object FactionKickCommand { + + @JvmStatic + @Command(names = ["faction kick","fac kick","f kick","team kick","t kick"]) + fun execute(player: Player,@Parameter(name = "player")uuid: UUID) { + + val faction = FactionHandler.getFactionByPlayer(player.uniqueId) + + if (faction == null) { + player.sendMessage("${ChatColor.RED}You are not in a faction!") + return + } + + if (!faction.getRole(player.uniqueId).isAbleToInvite()) { + player.sendMessage("${ChatColor.RED}You cannot kick other members") + return + } + + val name = UUIDHandler.getUsernameById(uuid) + + if (!faction.isMember(uuid)) { + player.sendMessage("${ChatColor.RED}$name is not in your faction!") + return + } + + val role = faction.getRole(player.uniqueId) + + if (faction.getRole(uuid).ordinal >= role.ordinal) { + player.sendMessage("${ChatColor.RED}You cannot kick ${name}.") + return + } + + faction.sendMessage("${ChatColor.DARK_AQUA}${name} has been kicked by ${player.name}!") + faction.removeMember(uuid,player.uniqueId) + + HCF.instance.server.pluginManager.callEvent(FactionMemberRemoveEvent(faction,uuid,FactionMemberRemoveEvent.Cause.KICK)) + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/captain/FactionSetHQCommand.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/captain/FactionSetHQCommand.kt new file mode 100644 index 0000000..ff6b971 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/captain/FactionSetHQCommand.kt @@ -0,0 +1,42 @@ +package cc.fyre.hcf.faction.command.captain + +import cc.fyre.shard.command.data.command.Command +import cc.fyre.hcf.HCF +import cc.fyre.hcf.faction.FactionHandler +import org.bukkit.ChatColor +import org.bukkit.entity.Player + +/** + * @project hcf + * + * @date 26/06/2020 + * @author xanderume@gmail.com + */ +object FactionSetHQCommand { + + @Command(names = ["faction sethq","fac sethq","f sethq","team sethq","t sethq","faction sethome","fac sethome","f sethome","team sethome","t sethome","sethq","sethome"]) + fun execute(player: Player) { + + val faction = FactionHandler.getFactionByPlayer(player.uniqueId) + + if (faction == null) { + player.sendMessage("${ChatColor.RED}You are not in a faction!") + return + } + + if (!faction.getRole(player.uniqueId).isAbleToUpdateHQ()) { + player.sendMessage("${ChatColor.RED}You cannot update the faction HQ.") + return + } + + if (!faction.claims.any{it.contains(player.location)}) { + player.sendMessage("${ChatColor.RED}${ChatColor.BOLD}Your faction does not own this claim.") + return + } + + faction.setHQ(player.location) + faction.flagForSave() + faction.sendMessage("${ChatColor.DARK_AQUA}${player.name} has updated the faction's HQ point!") + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/captain/FactionWithdrawCommand.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/captain/FactionWithdrawCommand.kt new file mode 100644 index 0000000..e48f52f --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/captain/FactionWithdrawCommand.kt @@ -0,0 +1,55 @@ +package cc.fyre.hcf.faction.command.captain + +import cc.fyre.shard.command.data.command.Command +import cc.fyre.shard.command.data.parameter.Parameter +import cc.fyre.hcf.HCF +import cc.fyre.hcf.faction.FactionHandler +import cc.fyre.hcf.statistic.StatisticHandler +import cc.fyre.hcf.statistic.type.BalanceStatistic +import org.bukkit.ChatColor +import org.bukkit.entity.Player + +/** + * @project hcf + * + * @date 05/07/2020 + * @author xanderume@gmail.com + */ +object FactionWithdrawCommand { + + @JvmStatic + @Command(names = ["faction withdraw","fac withdraw","f withdraw","team withdraw","t withdraw","faction w","fac w","f w","team w","t w"]) + fun execute(player: Player, @Parameter(name = "amount")argument: String) { + + val faction = FactionHandler.getFactionByPlayer(player.uniqueId) + + if (faction == null) { + player.sendMessage("${ChatColor.RED}You are not in a faction!") + return + } + + if (!faction.getRole(player.uniqueId).isAbleToWithdrawBalance()) { + player.sendMessage("${ChatColor.RED}You cannot withdraw money from the faction.") + return + } + + val balance = if (argument.equals("all",true) || argument.equals("a",true)) faction.balance else argument.toIntOrNull() + + if (balance == null || balance <= 0) { + player.sendMessage(ChatColor.RED.toString() + "You can't withdraw $0.0 (or less)!") + return + } + + if (faction.balance < balance) { + player.sendMessage("${ChatColor.RED}Your faction does not have enough money to do this!") + return + } + + faction.balance -= balance + + StatisticHandler.increaseStatistic(player.uniqueId,BalanceStatistic,balance) + + faction.sendMessage("${ChatColor.LIGHT_PURPLE}${player.name} ${ChatColor.YELLOW}has withdrawn ${ChatColor.LIGHT_PURPLE}$$balance${ChatColor.YELLOW} from the faction balance.") + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/coleader/FactionDemoteCommand.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/coleader/FactionDemoteCommand.kt new file mode 100644 index 0000000..7c5a8fd --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/coleader/FactionDemoteCommand.kt @@ -0,0 +1,67 @@ +package cc.fyre.hcf.faction.command.coleader + +import cc.fyre.shard.command.data.command.Command +import cc.fyre.shard.command.data.parameter.Parameter +import cc.fyre.core.uuid.UUIDHandler +import cc.fyre.hcf.faction.FactionHandler +import cc.fyre.hcf.faction.type.player.FactionRole +import net.minecraft.util.org.apache.commons.lang3.StringUtils +import org.bukkit.ChatColor +import org.bukkit.entity.Player +import java.util.* + +/** + * @project hcf + * + * @date 28/06/2020 + * @author xanderume@gmail.com + */ +object FactionDemoteCommand { + + @JvmStatic + @Command(names = ["faction demote","fac demote","f demote","team demote","t demote"]) + fun execute(player: Player,@Parameter(name = "player")target: UUID) { + + val faction = FactionHandler.getFactionByPlayer(player.uniqueId) + + if (faction == null) { + player.sendMessage("${ChatColor.RED}You are not in a faction!") + return + } + + if (!faction.getRole(player.uniqueId).isAbleToDemote()) { + player.sendMessage("${ChatColor.RED}You cannot demote members.") + return + } + + val name = UUIDHandler.getUsernameById(target) + + if (!faction.isMember(target)) { + player.sendMessage("${ChatColor.RED}$name is not in your faction!") + return + } + + val role = faction.getRole(player.uniqueId) + val targetRole = faction.getRole(target) + + if (targetRole == FactionRole.LEADER) { + player.sendMessage("${ChatColor.RED}${if (role == FactionRole.LEADER) "Use /faction leader to transfer the faction" else "You cannot demote $name"}.") + return + } + + if (role.ordinal < targetRole.ordinal) { + player.sendMessage("${ChatColor.RED}You cannot demote $name.") + return + } + + if (targetRole.ordinal == 0) { + player.sendMessage("${ChatColor.RED}$name is currently a member. To kick them, use /faction kick $name.") + return + } + + faction.setRole(target,FactionRole.values()[targetRole.ordinal - 1]) + faction.flagForSave() + faction.sendMessage("${ChatColor.LIGHT_PURPLE}$name${ChatColor.YELLOW} has been demoted to a faction ${ChatColor.LIGHT_PURPLE}${StringUtils.capitalize(faction.getRole(target).name.lowercase())}${ChatColor.YELLOW}.") + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/coleader/FactionPromoteCommand.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/coleader/FactionPromoteCommand.kt new file mode 100644 index 0000000..b6ffcb2 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/coleader/FactionPromoteCommand.kt @@ -0,0 +1,57 @@ +package cc.fyre.hcf.faction.command.coleader + +import cc.fyre.shard.command.data.command.Command +import cc.fyre.shard.command.data.parameter.Parameter +import cc.fyre.core.uuid.UUIDHandler +import cc.fyre.hcf.faction.FactionHandler +import cc.fyre.hcf.faction.type.player.FactionRole +import org.apache.commons.lang.StringUtils +import org.bukkit.ChatColor +import org.bukkit.entity.Player +import java.util.* + +/** + * @project hcf + * + * @date 06/07/2020 + * @author xanderume@gmail.com + */ +object FactionPromoteCommand { + + @JvmStatic + @Command(names = ["faction promote","fac promote","f promote","team promote","t promote"]) + fun execute(player: Player, @Parameter(name = "player")target: UUID) { + + val faction = FactionHandler.getFactionByPlayer(player.uniqueId) + + if (faction == null) { + player.sendMessage("${ChatColor.RED}You are not in a faction!") + return + } + + if (!faction.getRole(player.uniqueId).isAbleToPromote()) { + player.sendMessage("${ChatColor.RED}You cannot promote members.") + return + } + + val name = UUIDHandler.getUsernameById(target) + + if (!faction.isMember(target)) { + player.sendMessage("${ChatColor.RED}$name is not in your faction!") + return + } + + val role = faction.getRole(player.uniqueId) + val targetRole = faction.getRole(target) + val newRole = FactionRole.values()[targetRole.ordinal + 1] + + if (role.ordinal <= targetRole.ordinal || newRole == FactionRole.LEADER) { + player.sendMessage("${ChatColor.DARK_AQUA}You are not allowed to promote $name!") + return + } + + faction.setRole(player.uniqueId,newRole) + faction.flagForSave() + faction.sendMessage("${ChatColor.LIGHT_PURPLE}$name${ChatColor.YELLOW} has been promoted to a faction ${ChatColor.LIGHT_PURPLE}${StringUtils.capitalize(newRole.name.lowercase())}${ChatColor.YELLOW}.") + } +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/coleader/FactionRenameCommand.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/coleader/FactionRenameCommand.kt new file mode 100644 index 0000000..13b5132 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/coleader/FactionRenameCommand.kt @@ -0,0 +1,62 @@ +package cc.fyre.hcf.faction.command.coleader + +import cc.fyre.shard.command.data.command.Command +import cc.fyre.shard.command.data.parameter.Parameter +import cc.fyre.hcf.HCF +import cc.fyre.hcf.faction.FactionHandler +import cc.fyre.hcf.faction.Faction +import org.bukkit.ChatColor +import org.bukkit.entity.Player + +/** + * @project hcf + * + * @date 26/06/2020 + * @author xanderume@gmail.com + */ +object FactionRenameCommand { + + @Command(names = ["faction rename","fac rename","f rename","team rename"]) + fun execute(player: Player,@Parameter(name = "new name")name: String) { + + val faction = FactionHandler.getFactionByPlayer(player.uniqueId) + + if (faction == null) { + player.sendMessage("${ChatColor.RED}You are not in a faction!") + return + } + + if (!faction.getRole(player.uniqueId).isAbleToUpdateName()) { + player.sendMessage("${ChatColor.RED}You cannot update the faction name.") + return + } + + if (name.length < Faction.MIN_NAME_LENGTH) { + player.sendMessage("${ChatColor.RED}Minimum faction name size is ${Faction.MIN_NAME_LENGTH} characters!") + return + } + + if (name.length > Faction.MAX_NAME_LENGTH) { + player.sendMessage("${ChatColor.RED}Maximum faction name size is ${Faction.MIN_NAME_LENGTH} characters!") + return + } + + if (FactionHandler.ALPHA_NUMERIC_PATTERN.matcher(name).find()) { + player.sendMessage("${ChatColor.RED}Faction names must be alphanumeric!") + return + } + + if (FactionHandler.getFactionByName(name) != null) { + player.sendMessage("${ChatColor.RED}That faction already exists!") + return + } + + FactionHandler.updateName(faction,name) + + faction.name = name + faction.flagForSave() + + faction.sendMessage("${ChatColor.DARK_AQUA}${player.name} has renamed the faction to ${name}.") + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/coleader/FactionUnAllyCommand.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/coleader/FactionUnAllyCommand.kt new file mode 100644 index 0000000..3b10716 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/coleader/FactionUnAllyCommand.kt @@ -0,0 +1,51 @@ +package cc.fyre.hcf.faction.command.coleader + +import cc.fyre.shard.command.data.command.Command +import cc.fyre.shard.command.data.parameter.Parameter +import cc.fyre.hcf.HCF +import cc.fyre.hcf.faction.FactionHandler +import cc.fyre.hcf.faction.type.PlayerFaction +import org.bukkit.ChatColor +import org.bukkit.entity.Player + +/** + * @project hcf + * + * @date 28/06/2020 + * @author xanderume@gmail.com + */ +object FactionUnAllyCommand { + + @JvmStatic + @Command(names = ["faction unally","fac unally","f unally","team unally","t unally"]) + fun execute(player: Player,@Parameter(name = "faction")target: PlayerFaction) { + + val faction = FactionHandler.getFactionByPlayer(player.uniqueId) + + if (faction == null) { + player.sendMessage("${ChatColor.RED}You are not in a faction!") + return + } + + if (!faction.getRole(player.uniqueId).isAbleToRemoveAlly()) { + player.sendMessage("${ChatColor.RED}You cannot drop alliances.") + return + } + + if (!faction.isFactionAllied(target)) { + player.sendMessage("${ChatColor.RED}Your faction is not allied to ${faction.getDisplayName(player)}${ChatColor.RED}.") + return + } + + target.allies.remove(faction.id) + target.flagForSave() + + faction.allies.remove(target.id) + faction.flagForSave() + + + target.getOnlineMembers().forEach{it.sendMessage("${faction.getDisplayName(it)}${ChatColor.YELLOW} has dropped its alliance with your faction.")} + faction.getOnlineMembers().forEach{it.sendMessage("${ChatColor.YELLOW}Your faction has dropped its alliance with ${target.getDisplayName(it)}${ChatColor.YELLOW}.")} + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/coleader/FactionUnClaimCommand.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/coleader/FactionUnClaimCommand.kt new file mode 100644 index 0000000..e6bf6f2 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/coleader/FactionUnClaimCommand.kt @@ -0,0 +1,84 @@ +package cc.fyre.hcf.faction.command.coleader + +import cc.fyre.shard.command.data.command.Command +import cc.fyre.shard.command.data.parameter.Parameter +import cc.fyre.hcf.faction.FactionHandler +import cc.fyre.hcf.faction.claim.ClaimHandler +import cc.fyre.hcf.faction.claim.ClaimSelection +import org.bukkit.ChatColor +import org.bukkit.entity.Player + +/** + * @project hcf + * + * @date 25/06/2020 + * @author xanderume@gmail.com + */ +object FactionUnClaimCommand { + + @JvmStatic + @Command(names = ["faction unclaim","fac unclaim","f unclaim","team unclaim","t unclaim"],async = true) + fun execute(player: Player,@Parameter(name = "all",false,"1")argument: String) { + + val faction = FactionHandler.getFactionByPlayer(player.uniqueId) + + if (faction == null) { + player.sendMessage("${ChatColor.RED}You are not in a faction!") + return + } + + if (!faction.getRole(player.uniqueId).isAbleToRemoveLand()) { + player.sendMessage("${ChatColor.RED}You cannot unclaim land.") + return + } + + if (faction.isRaidable()) { + player.sendMessage("${ChatColor.RED}You cannot unclaim land while your faction is raidable!") + return + } + + val claims = faction.claims + + if (claims.isEmpty()) { + player.sendMessage("${ChatColor.RED}Your faction does not have any claims.") + return + } + + if (argument.equals("all",true)) { + + faction.claims.forEach{ClaimHandler.destroy(it)} + faction.balance -= claims.sumOf{ClaimSelection(faction,it.getLower(),it.getUpper()).getPrice()} + faction.removeClaims(*faction.claims.toTypedArray()) + + if (faction.getHQ() != null) { + faction.setHQ(null) + faction.sendMessage("${ChatColor.RED}The faction HQ has been reset due to unclaiming land.") + } + + faction.sendMessage("${ChatColor.YELLOW}${player.name} has unclaimed all land.") + faction.flagForSave() + return + } + + + val claim = faction.claims.firstOrNull{it.contains(player.location)} + + if (claim == null) { + player.sendMessage("${ChatColor.RED}${ChatColor.BOLD}Your faction does not own this claim.") + return + } + + faction.removeClaims(claim) + faction.sendMessage("${ChatColor.YELLOW}${player.name} has unclaimed land.") + + if (faction.getHQ() != null && claim.contains(faction.getHQ()!!)) { + faction.setHQ(null) + faction.sendMessage("${ChatColor.RED}The faction HQ has been reset due to unclaiming land.") + } + + faction.balance += ClaimSelection(faction,claim.getLower(),claim.getUpper()).getPrice() + + ClaimHandler.destroy(claim) + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/leader/FactionDisbandCommand.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/leader/FactionDisbandCommand.kt new file mode 100644 index 0000000..75ddb15 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/leader/FactionDisbandCommand.kt @@ -0,0 +1,47 @@ +package cc.fyre.hcf.faction.command.leader + +import cc.fyre.shard.command.data.command.Command +import cc.fyre.hcf.HCF +import cc.fyre.hcf.faction.FactionHandler +import cc.fyre.hcf.faction.event.FactionDisbandEvent +import cc.fyre.hcf.faction.type.player.FactionRole +import org.bukkit.ChatColor +import org.bukkit.entity.Player + +/** + * @project hcf + * + * @date 07/04/2020 + * @author xanderume@gmail.com + */ +object FactionDisbandCommand { + + @JvmStatic + @Command(names = ["faction disband","fac disband","f disband","team disband","t disband"]) + fun execute(player: Player) { + + val faction = FactionHandler.getFactionByPlayer(player.uniqueId) + + if (faction == null) { + player.sendMessage("${ChatColor.RED}You are not in a faction!") + return + } + + if (faction.getRole(player.uniqueId) != FactionRole.LEADER) { + player.sendMessage("${ChatColor.RED}You must be the faction leader to disband!") + return + } + + if (faction.isRaidable()) { + player.sendMessage("${ChatColor.RED}You cannot disband your faction while raidable.") + return + } + + FactionHandler.destroy(faction) + + faction.sendMessage("${ChatColor.RED}${ChatColor.BOLD}The faction has been disbanded.") + + HCF.instance.server.pluginManager.callEvent(FactionDisbandEvent(faction)) + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/leader/FactionLeaderCommand.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/leader/FactionLeaderCommand.kt new file mode 100644 index 0000000..b5516cf --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/leader/FactionLeaderCommand.kt @@ -0,0 +1,50 @@ +package cc.fyre.hcf.faction.command.leader + +import cc.fyre.shard.command.data.command.Command +import cc.fyre.shard.command.data.parameter.Parameter +import cc.fyre.core.uuid.UUIDHandler +import cc.fyre.hcf.faction.FactionHandler +import cc.fyre.hcf.faction.type.player.FactionRole +import org.bukkit.ChatColor +import org.bukkit.entity.Player +import java.util.* + +/** + * @project hcf + * + * @date 05/07/2020 + * @author xanderume@gmail.com + */ +object FactionLeaderCommand { + + @JvmStatic + @Command(names = ["faction leader","fac leader","f leader","team leader","t leader"]) + fun execute(player: Player,@Parameter(name = "player")uuid: UUID) { + + val faction = FactionHandler.getFactionByPlayer(player.uniqueId) + + if (faction == null) { + player.sendMessage("${ChatColor.RED}You are not in a faction!") + return + } + + if (faction.getRole(player.uniqueId) != FactionRole.LEADER) { + player.sendMessage("${ChatColor.RED}You are not the faction leader!") + return + } + + val name = UUIDHandler.getUsernameById(uuid) + + if (!faction.isMember(uuid)) { + player.sendMessage("${ChatColor.RED}$name is not in your faction!") + return + } + + faction.setRole(uuid,FactionRole.LEADER) + faction.setRole(player.uniqueId,FactionRole.CO_LEADER) + faction.flagForSave() + + faction.sendMessage("${ChatColor.DARK_AQUA}${player.name} has transferred the faction to ${name}.") + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/parameter/FactionParameterProvider.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/parameter/FactionParameterProvider.kt new file mode 100644 index 0000000..e35c92e --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/parameter/FactionParameterProvider.kt @@ -0,0 +1,50 @@ +package cc.fyre.hcf.faction.command.parameter + +import cc.fyre.hcf.HCF +import cc.fyre.hcf.faction.Faction +import cc.fyre.hcf.faction.FactionHandler +import cc.fyre.shard.command.data.parameter.ParameterAdapter +import net.minecraft.util.org.apache.commons.lang3.StringUtils +import org.bukkit.ChatColor +import org.bukkit.command.CommandSender +import org.bukkit.entity.Player + +/** + * @project hcf + * + * @date 25/06/2020 + * @author xanderume@gmail.com + */ +object FactionParameterProvider : ParameterAdapter { + + override fun transform(sender: CommandSender,source: String): Faction? { + + if (sender is Player && (source == "" || source.equals(SELF_ARGUMENT,true))) { + + val faction = FactionHandler.getFactionByPlayer(sender.uniqueId) + + if (faction == null) { + sender.sendMessage("${ChatColor.RED}You are not in a faction!") + return null + } + + return faction + } + + val faction = FactionHandler.getFactionByArgument(source) + + if (faction == null) { + sender.sendMessage("${ChatColor.RED}No faction or member with the name $source found.") + return null + } + + return faction + } + + override fun tabComplete(player: Player, flags: Set, source: String): List { + return HCF.instance.server.onlinePlayers.filter{StringUtils.startsWithIgnoreCase(it.name,source)}.map{it.name} + } + + const val SELF_ARGUMENT = "S_E_L_F" + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/parameter/GameFactionParameterProvider.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/parameter/GameFactionParameterProvider.kt new file mode 100644 index 0000000..4486ea1 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/parameter/GameFactionParameterProvider.kt @@ -0,0 +1,41 @@ +package cc.fyre.hcf.faction.command.parameter + +import cc.fyre.hcf.HCF +import cc.fyre.hcf.faction.FactionHandler +import cc.fyre.hcf.game.GameFaction +import cc.fyre.shard.command.data.parameter.ParameterAdapter +import net.minecraft.util.org.apache.commons.lang3.StringUtils +import org.bukkit.ChatColor +import org.bukkit.command.CommandSender +import org.bukkit.entity.Player + +/** + * @project hcf + * + * @date 29/08/2020 + * @author xanderume@gmail.com + */ +object GameFactionParameterProvider : ParameterAdapter { + + override fun transform(sender: CommandSender, source: String): GameFaction? { + + val faction = FactionHandler.getFactionByName(source) + + if (faction == null) { + sender.sendMessage("${ChatColor.RED}No faction with the name $source found.") + return null + } + + if (faction !is GameFaction) { + sender.sendMessage("${faction.getDisplayName(sender)}${ChatColor.RED} is not a game faction.") + return null + } + + return faction + } + + override fun tabComplete(player: Player, flags: Set, source: String): List { + return HCF.instance.server.onlinePlayers.filter{ StringUtils.startsWithIgnoreCase(it.name,source)}.map{it.name} + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/parameter/MountainFactionParameterProvider.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/parameter/MountainFactionParameterProvider.kt new file mode 100644 index 0000000..4b1c6b3 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/parameter/MountainFactionParameterProvider.kt @@ -0,0 +1,41 @@ +package cc.fyre.hcf.faction.command.parameter + +import cc.fyre.shard.command.data.parameter.ParameterAdapter +import cc.fyre.hcf.HCF +import cc.fyre.hcf.faction.FactionHandler +import cc.fyre.hcf.mountain.MountainFaction +import net.minecraft.util.org.apache.commons.lang3.StringUtils +import org.bukkit.ChatColor +import org.bukkit.command.CommandSender +import org.bukkit.entity.Player + +/** + * @project hcf + * + * @date 06/09/2020 + * @author xanderume@gmail.com + */ +object MountainFactionParameterProvider : ParameterAdapter { + + override fun transform(sender: CommandSender, source: String): MountainFaction? { + + val faction = FactionHandler.getFactionByName(source) + + if (faction == null) { + sender.sendMessage("${ChatColor.RED}No faction with the name $source found.") + return null + } + + if (faction !is MountainFaction) { + sender.sendMessage("${faction.getDisplayName(sender)}${ChatColor.RED} is not a mountain faction.") + return null + } + + return faction + } + + override fun tabComplete(player: Player, flags: Set, source: String): List { + return HCF.instance.server.onlinePlayers.filter{ StringUtils.startsWithIgnoreCase(it.name,source)}.map{it.name} + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/parameter/PlayerFactionParameterProvider.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/parameter/PlayerFactionParameterProvider.kt new file mode 100644 index 0000000..7610b74 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/parameter/PlayerFactionParameterProvider.kt @@ -0,0 +1,33 @@ +package cc.fyre.hcf.faction.command.parameter + +import cc.fyre.shard.command.data.parameter.ParameterAdapter +import cc.fyre.hcf.faction.type.PlayerFaction +import org.bukkit.ChatColor +import org.bukkit.command.CommandSender +import org.bukkit.entity.Player + +/** + * @project hcf + * + * @date 25/06/2020 + * @author xanderume@gmail.com + */ +object PlayerFactionParameterProvider : ParameterAdapter { + + override fun transform(sender: CommandSender, source: String): PlayerFaction? { + + val toReturn = FactionParameterProvider.transform(sender,source) ?: return null + + if (toReturn !is PlayerFaction) { + sender.sendMessage("${ChatColor.RED}No faction or member with the name $source found.") + return null + } + + return toReturn + } + + override fun tabComplete(player: Player,flags: Set,source: String): List { + return FactionParameterProvider.tabComplete(player,flags,source) + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/parameter/SystemFactionParameterProvider.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/parameter/SystemFactionParameterProvider.kt new file mode 100644 index 0000000..3783dda --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/command/parameter/SystemFactionParameterProvider.kt @@ -0,0 +1,42 @@ +package cc.fyre.hcf.faction.command.parameter + +import cc.fyre.shard.command.data.parameter.ParameterAdapter +import cc.fyre.hcf.HCF +import cc.fyre.hcf.faction.Faction +import cc.fyre.hcf.faction.FactionHandler +import cc.fyre.hcf.faction.type.SystemFaction +import net.minecraft.util.org.apache.commons.lang3.StringUtils +import org.bukkit.ChatColor +import org.bukkit.command.CommandSender +import org.bukkit.entity.Player + +/** + * @project hcf + * + * @date 28/08/2020 + * @author xanderume@gmail.com + */ +object SystemFactionParameterProvider : ParameterAdapter { + + override fun transform(sender: CommandSender, source: String): Faction? { + + val faction = FactionHandler.getFactionByName(source) + + if (faction == null) { + sender.sendMessage("${ChatColor.RED}No faction with the name $source found.") + return null + } + + if (faction !is SystemFaction) { + sender.sendMessage("${faction.getDisplayName(sender)}${ChatColor.RED} is not a system faction.") + return null + } + + return faction + } + + override fun tabComplete(player: Player, flags: Set, source: String): List { + return HCF.instance.server.onlinePlayers.filter{ StringUtils.startsWithIgnoreCase(it.name,source)}.map{it.name} + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/event/FactionAllyEvent.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/event/FactionAllyEvent.kt new file mode 100644 index 0000000..969a9d1 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/event/FactionAllyEvent.kt @@ -0,0 +1,23 @@ +package cc.fyre.hcf.faction.event + +import cc.fyre.hcf.faction.type.PlayerFaction +import org.bukkit.event.Event +import org.bukkit.event.HandlerList + +/** + * @project hcf + * + * @date 05/07/2020 + * @author xanderume@gmail.com + */ +class FactionAllyEvent(val sender: PlayerFaction,val target: PlayerFaction) : Event() { + + override fun getHandlers(): HandlerList { + return handlerList + } + + companion object { + @JvmStatic val handlerList = HandlerList() + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/event/FactionClaimEvent.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/event/FactionClaimEvent.kt new file mode 100644 index 0000000..acc8293 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/event/FactionClaimEvent.kt @@ -0,0 +1,25 @@ +package cc.fyre.hcf.faction.event + +import cc.fyre.hcf.faction.Faction +import cc.fyre.hcf.faction.claim.Claim +import org.bukkit.entity.Player +import org.bukkit.event.Event +import org.bukkit.event.HandlerList + +/** + * @project hcf + * + * @date 25/07/2020 + * @author xanderume@gmail.com + */ +class FactionClaimEvent(val player: Player, val claim: Claim, val faction: Faction):Event() { + + override fun getHandlers(): HandlerList { + return handlerList + } + + companion object { + @JvmStatic val handlerList = HandlerList() + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/event/FactionCreateEvent.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/event/FactionCreateEvent.kt new file mode 100644 index 0000000..bfc52e7 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/event/FactionCreateEvent.kt @@ -0,0 +1,23 @@ +package cc.fyre.hcf.faction.event + +import cc.fyre.hcf.faction.Faction +import org.bukkit.event.Event +import org.bukkit.event.HandlerList + +/** + * @project hcf + * + * @date 18/04/2020 + * @author xanderume@gmail.com + */ +class FactionCreateEvent(val faction: Faction) : Event() { + + override fun getHandlers(): HandlerList { + return handlerList + } + + companion object { + @JvmStatic val handlerList = HandlerList() + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/event/FactionDTRUpdateEvent.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/event/FactionDTRUpdateEvent.kt new file mode 100644 index 0000000..f9ecfbf --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/event/FactionDTRUpdateEvent.kt @@ -0,0 +1,23 @@ +package cc.fyre.hcf.faction.event + +import cc.fyre.hcf.faction.type.PlayerFaction +import org.bukkit.event.Event +import org.bukkit.event.HandlerList + +/** + * @project hcf + * + * @date 23/07/2020 + * @author xanderume@gmail.com + */ +class FactionDTRUpdateEvent(val faction: PlayerFaction,val previousDTR: Double,val newDTR: Double): Event() { + + override fun getHandlers(): HandlerList { + return handlerList + } + + companion object { + @JvmStatic val handlerList = HandlerList() + } + +} diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/event/FactionDisbandEvent.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/event/FactionDisbandEvent.kt new file mode 100644 index 0000000..18b562e --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/event/FactionDisbandEvent.kt @@ -0,0 +1,22 @@ +package cc.fyre.hcf.faction.event + +import cc.fyre.hcf.faction.Faction +import org.bukkit.event.Event +import org.bukkit.event.HandlerList + +/** + * @project hcf + * + * @date 18/04/2020 + * @author xanderume@gmail.com + */ +class FactionDisbandEvent(val faction: Faction):Event() { + + override fun getHandlers(): HandlerList { + return handlerList + } + + companion object { + @JvmStatic val handlerList = HandlerList() + } +} diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/event/FactionFocusEvent.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/event/FactionFocusEvent.kt new file mode 100644 index 0000000..ec34724 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/event/FactionFocusEvent.kt @@ -0,0 +1,35 @@ +package cc.fyre.hcf.faction.event + +import cc.fyre.hcf.faction.type.PlayerFaction +import org.bukkit.entity.Player +import org.bukkit.event.Event +import org.bukkit.event.HandlerList + +/** + * @project hcf + * + * @date 06/07/2020 + * @author xanderume@gmail.com + */ +class FactionFocusEvent(val sender: PlayerFaction): Event() { + + var target: Player? = null + var faction: PlayerFaction? = null + + constructor(sender: PlayerFaction, target: Player):this(sender) { + this.target = target + } + + constructor(sender: PlayerFaction, faction: PlayerFaction):this(sender) { + this.faction = faction + } + + override fun getHandlers(): HandlerList { + return handlerList + } + + companion object { + @JvmStatic val handlerList = HandlerList() + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/event/FactionHQUpdateEvent.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/event/FactionHQUpdateEvent.kt new file mode 100644 index 0000000..8e02aba --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/event/FactionHQUpdateEvent.kt @@ -0,0 +1,24 @@ +package cc.fyre.hcf.faction.event + +import cc.fyre.hcf.faction.Faction +import org.bukkit.Location +import org.bukkit.event.Event +import org.bukkit.event.HandlerList + +/** + * @project hcf + * + * @date 31/08/2020 + * @author xanderume@gmail.com + */ +class FactionHQUpdateEvent(val faction: Faction, val oldHQ: Location?, val newHQ: Location?): Event() { + + override fun getHandlers(): HandlerList { + return handlerList + } + + companion object { + @JvmStatic val handlerList = HandlerList() + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/event/FactionMemberAddEvent.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/event/FactionMemberAddEvent.kt new file mode 100644 index 0000000..7c3e576 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/event/FactionMemberAddEvent.kt @@ -0,0 +1,24 @@ +package cc.fyre.hcf.faction.event + +import cc.fyre.hcf.faction.type.PlayerFaction +import org.bukkit.entity.Player +import org.bukkit.event.Event +import org.bukkit.event.HandlerList + +/** + * @project hcf + * + * @date 05/07/2020 + * @author xanderume@gmail.com + */ +class FactionMemberAddEvent(val faction: PlayerFaction,val target: Player): Event() { + + override fun getHandlers(): HandlerList { + return handlerList + } + + companion object { + @JvmStatic val handlerList = HandlerList() + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/event/FactionMemberDeathEvent.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/event/FactionMemberDeathEvent.kt new file mode 100644 index 0000000..c502ee8 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/event/FactionMemberDeathEvent.kt @@ -0,0 +1,24 @@ +package cc.fyre.hcf.faction.event + +import cc.fyre.hcf.faction.type.PlayerFaction +import org.bukkit.entity.Player +import org.bukkit.event.Event +import org.bukkit.event.HandlerList + +/** + * @project hcf + * + * @date 13/09/2020 + * @author xanderume@gmail.com + */ +class FactionMemberDeathEvent(val faction: PlayerFaction,val player: Player,val killer: Player?,val deathMessage: String): Event() { + + override fun getHandlers(): HandlerList { + return handlerList + } + + companion object { + @JvmStatic val handlerList = HandlerList() + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/event/FactionMemberRemoveEvent.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/event/FactionMemberRemoveEvent.kt new file mode 100644 index 0000000..1f10026 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/event/FactionMemberRemoveEvent.kt @@ -0,0 +1,31 @@ +package cc.fyre.hcf.faction.event + +import cc.fyre.hcf.faction.type.PlayerFaction +import org.bukkit.event.Event +import org.bukkit.event.HandlerList +import java.util.* + +/** + * @project hcf + * + * @date 05/07/2020 + * @author xanderume@gmail.com + */ +class FactionMemberRemoveEvent(val faction: PlayerFaction,val target: UUID,val cause: Cause):Event() { + + override fun getHandlers(): HandlerList { + return handlerList + } + + companion object { + @JvmStatic val handlerList = HandlerList() + } + + enum class Cause { + + KICK, + LEAVE + + } + +} diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/event/FactionMoveEvent.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/event/FactionMoveEvent.kt new file mode 100644 index 0000000..a056700 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/event/FactionMoveEvent.kt @@ -0,0 +1,35 @@ +package cc.fyre.hcf.faction.event + +import cc.fyre.hcf.faction.Faction +import org.bukkit.entity.Player +import org.bukkit.event.Cancellable +import org.bukkit.event.Event +import org.bukkit.event.HandlerList + +/** + * @project hcf + * + * @date 20/07/2020 + * @author xanderume@gmail.com + */ +class FactionMoveEvent(val player: Player, val from: Faction, val to: Faction):Event(),Cancellable { + + private var cancelled = false + + override fun isCancelled(): Boolean { + return this.cancelled + } + + override fun setCancelled(cancelled: Boolean) { + this.cancelled = cancelled + } + + override fun getHandlers(): HandlerList { + return handlerList + } + + companion object { + @JvmStatic val handlerList = HandlerList() + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/event/FactionUnAllyEvent.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/event/FactionUnAllyEvent.kt new file mode 100644 index 0000000..37d867e --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/event/FactionUnAllyEvent.kt @@ -0,0 +1,23 @@ +package cc.fyre.hcf.faction.event + +import cc.fyre.hcf.faction.type.PlayerFaction +import org.bukkit.event.Event +import org.bukkit.event.HandlerList + +/** + * @project hcf + * + * @date 05/07/2020 + * @author xanderume@gmail.com + */ +class FactionUnAllyEvent(val sender: PlayerFaction, val target: PlayerFaction): Event() { + + override fun getHandlers(): HandlerList { + return handlerList + } + + companion object { + @JvmStatic val handlerList = HandlerList() + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/event/FactionUnFocusEvent.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/event/FactionUnFocusEvent.kt new file mode 100644 index 0000000..9ed8e23 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/event/FactionUnFocusEvent.kt @@ -0,0 +1,35 @@ +package cc.fyre.hcf.faction.event + +import cc.fyre.hcf.faction.type.PlayerFaction +import org.bukkit.entity.Player +import org.bukkit.event.Event +import org.bukkit.event.HandlerList + +/** + * @project hcf + * + * @date 06/07/2020 + * @author xanderume@gmail.com + */ +class FactionUnFocusEvent(val sender: PlayerFaction): Event() { + + var target: Player? = null + var faction: PlayerFaction? = null + + constructor(sender: PlayerFaction,target: Player):this(sender) { + this.target = target + } + + constructor(sender: PlayerFaction,faction: PlayerFaction):this(sender) { + this.faction = faction + } + + override fun getHandlers(): HandlerList { + return handlerList + } + + companion object { + @JvmStatic val handlerList = HandlerList() + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/list/FactionList.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/list/FactionList.kt new file mode 100644 index 0000000..dcd853f --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/list/FactionList.kt @@ -0,0 +1,62 @@ +package cc.fyre.hcf.faction.list + +import cc.fyre.hcf.faction.FactionHandler +import cc.fyre.hcf.faction.type.PlayerFaction +import java.util.concurrent.ConcurrentHashMap +import java.util.function.Predicate +import kotlin.math.min + +object FactionList { + + private val lists = ConcurrentHashMap>() + private val updates = ConcurrentHashMap() + + fun getList(type: FactionListType):List { + + val lastUpdate = this.updates[type] ?: 0L + + if (lastUpdate == 0L || ((System.currentTimeMillis() - lastUpdate) >= REFRESH_RATE)) { + this.refresh(type) + } + + return this.lists[type] ?: listOf() + } + + fun take(type: FactionListType,amount: Int):List { + return this.getList(type).take(amount) + } + + fun getPage(type: FactionListType,page: Int):Iterable> { + + val list = this.getList(type) + + if (page <= 0) { + return list.take(10) + .withIndex() + } + + val start = (page * 10) + 1 + val end = start + 9 + + return list.toTypedArray() + .copyOfRange(start,min(end,list.lastIndex)) + .withIndex() + } + + fun getMaxPages(type: FactionListType):Int { + return (this.getList(type).size / 10) + 1 + } + + private fun refresh(type: FactionListType) { + + this.lists[type] = FactionHandler.getAllPlayerFactions() + .filter{(type.filter ?: Predicate{return@Predicate true}).test(it)} + .sortedWith(type.comparator) + .toList() + + this.updates[type] = System.currentTimeMillis() + } + + private const val REFRESH_RATE = 3000L + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/list/FactionListType.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/list/FactionListType.kt new file mode 100644 index 0000000..bc77515 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/list/FactionListType.kt @@ -0,0 +1,46 @@ +package cc.fyre.hcf.faction.list + +import cc.fyre.hcf.faction.type.PlayerFaction +import java.util.function.Predicate + +enum class FactionListType(val displayName: String,val comparator: Comparator,val filter: Predicate? = null,val filterable: Boolean = true) { + + KILLS("Kills",compareByDescending{it.kills},filterable = false), + POINTS("Points",compareByDescending{it.points},filterable = false), + + MAX_DTR("Most DTR",compareByDescending{it.dtr}), + MIN_DTR("Least DTR",compareBy{it.dtr}), + + MAX_ONLINE("Most members online",compareByDescending{it.onlineMembers},Predicate{it.onlineMembers > 0}), + MIN_ONLINE("Least members online",compareBy{it.onlineMembers},Predicate{it.onlineMembers > 0}); + + fun next(filterable: Boolean):FactionListType { + + val types = if (filterable) getAllTypes().filter{it.filterable} else getAllTypes() + + if (this.ordinal >= types.lastIndex) { + return types[0] + } + + return types[this.ordinal + 1] + } + + companion object { + + private val values = mutableMapOf() + + init { + values().forEach{this.values[it.name.lowercase()] = it} + } + + fun getAllTypes():List { + return this.values.values.toList() + } + + fun getTypeByName(name: String):FactionListType? { + return this.values[name.lowercase()] + } + + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/listener/FactionChatListener.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/listener/FactionChatListener.kt new file mode 100644 index 0000000..eee2550 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/listener/FactionChatListener.kt @@ -0,0 +1,104 @@ +package cc.fyre.hcf.faction.listener + +import cc.fyre.hcf.faction.FactionHandler +import cc.fyre.hcf.faction.type.player.ChatMode +import cc.fyre.hcf.faction.type.player.FactionRole +import org.bukkit.Bukkit +import org.bukkit.event.EventHandler +import org.bukkit.event.EventPriority +import org.bukkit.event.Listener +import org.bukkit.event.player.AsyncPlayerChatEvent + +/** + * @project hcf + * + * @date 19/07/2020 + * @author xanderume@gmail.com + */ +object FactionChatListener : Listener/*TODO,ChatProvider*/ { + + /*TODO + init { + Hybrid.instance.chatHandler.provider = this + }*/ + + @EventHandler(priority = EventPriority.MONITOR) + private fun onAsyncChat(event: AsyncPlayerChatEvent) { + + if (event.isCancelled) { + return + } + + val faction = FactionHandler.getFactionByPlayer(event.player.uniqueId) + + var chat = if (faction == null) ChatMode.GLOBAL else { + + val byPrefix = ChatMode.getByPrefix(event.message[0]) + + if (byPrefix != null) { + event.message = event.message.substring(1).trim() + } + + byPrefix ?: faction.getChatMode(event.player.uniqueId) + } + + if (faction != null && !chat.hasPermission(event.player.uniqueId,faction)) { + chat = chat.getNext(event.player.uniqueId,faction) + } + + if (chat != ChatMode.GLOBAL && faction != null) { + + event.recipients.clear() + + when (chat) { + ChatMode.ALLY -> { + event.recipients.addAll(faction.getOnlineMembers()) + event.recipients.addAll(faction.getAllies().map{it.getOnlineMembers()}.flatten()) + } + ChatMode.FACTION -> event.recipients.addAll(faction.getOnlineMembers()) + ChatMode.OFFICER -> event.recipients.addAll(faction.getOnlineMembers().filter{faction.getRole(it.uniqueId).ordinal > FactionRole.MEMBER.ordinal}) + else -> event.recipients.addAll(Bukkit.getServer().onlinePlayers) + } + + } + + event.format = chat.toChatFormat(event.player,Bukkit.getServer().consoleSender,event.message,faction) + event.isCancelled = true + + Bukkit.getServer().consoleSender.sendMessage(event.format) + + event.recipients.forEach{it.sendMessage(chat.toChatFormat(event.player,it,event.message,faction))} + } + + /*TODO + override fun shouldMuteApply(player: Player,message: String): Boolean { + + val faction = FactionHandler.findByPlayerID(player.uniqueId) + + var chat = if (faction == null) ChatMode.GLOBAL else { + + val byPrefix = ChatMode.findByPrefix(message[0]) + + byPrefix ?: faction.findChatMode(player.uniqueId) ?: ChatMode.FACTION + } + + if (faction != null && !chat.hasPermission(player.uniqueId,faction)) { + chat = chat.findNext(player.uniqueId,faction) + } + + return chat == ChatMode.GLOBAL + } + + override fun shouldSlowApply(player: Player, message: String): Boolean { + return this.shouldMuteApply(player,message) + } + + override fun shouldFilterApply(player: Player, message: String): Boolean { + return this.shouldMuteApply(player,message) + } + + override fun shouldCheckForSpam(player: Player, message: String): Boolean { + return this.shouldMuteApply(player,message) + }*/ + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/listener/FactionClaimListener.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/listener/FactionClaimListener.kt new file mode 100644 index 0000000..2652509 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/listener/FactionClaimListener.kt @@ -0,0 +1,85 @@ +package cc.fyre.hcf.faction.listener + +import cc.fyre.hcf.faction.claim.ClaimHandler +import cc.fyre.hcf.faction.claim.ClaimSelection +import cc.fyre.hcf.faction.type.PlayerFaction +import cc.fyre.hcf.faction.event.FactionDisbandEvent +import cc.fyre.hcf.pillar.PillarHandler +import cc.fyre.hcf.pillar.PillarType +import org.bukkit.ChatColor + +import org.bukkit.event.EventHandler +import org.bukkit.event.EventPriority +import org.bukkit.event.Listener +import org.bukkit.event.entity.PlayerDeathEvent + +import org.bukkit.event.player.PlayerDropItemEvent +import org.bukkit.event.player.PlayerItemDamageEvent +import org.bukkit.event.player.PlayerQuitEvent + +/** + * @project hcf + * + * @date 01/05/2020 + * @author xanderume@gmail.com + */ +object FactionClaimListener : Listener { + + @EventHandler(priority = EventPriority.LOWEST) + private fun onPlayerQuit(event: PlayerQuitEvent) { + ClaimHandler.destroySelection(event.player) + } + + @EventHandler(priority = EventPriority.LOWEST) + private fun onPlayerDeath(event: PlayerDeathEvent) { + + if (ClaimHandler.destroySelection(event.entity,removeItem = false) == null) { + return + } + + + event.drops.remove(ClaimSelection.ITEM) + + PillarHandler.destroyPillars(event.entity, PillarType.CLAIM_SELECTION) + } + + @EventHandler(priority = EventPriority.LOWEST) + private fun onPlayerDropItem(event: PlayerDropItemEvent) { + + if (!event.itemDrop.itemStack.isSimilar(ClaimSelection.ITEM)) { + return + } + + event.itemDrop.remove() + + ClaimHandler.destroySelection(event.player) + PillarHandler.destroyPillars(event.player,PillarType.CLAIM_SELECTION) + + event.player.sendMessage("${ChatColor.RED}You have cancelled the claiming process.") + } + + @EventHandler(priority = EventPriority.LOWEST) + private fun onPlayerDamageItem(event: PlayerItemDamageEvent) { + + if (!event.item.isSimilar(ClaimSelection.ITEM)) { + return + } + + event.isCancelled = true + + ClaimHandler.destroySelection(event.player) + PillarHandler.destroyPillars(event.player,PillarType.CLAIM_SELECTION) + } + + @EventHandler(priority = EventPriority.LOWEST) + private fun onFactionDisband(event: FactionDisbandEvent) { + + if (event.faction !is PlayerFaction) { + return + } + + + event.faction.getOnlineMembers().filter{ClaimHandler.destroySelection(it) != null}.forEach{PillarHandler.destroyPillars(it,PillarType.CLAIM_SELECTION)} + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/listener/FactionDeathListener.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/listener/FactionDeathListener.kt new file mode 100644 index 0000000..51a55d8 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/listener/FactionDeathListener.kt @@ -0,0 +1,68 @@ +package cc.fyre.hcf.faction.listener + +import cc.fyre.core.profile.ProfileHandler +import cc.fyre.hcf.faction.FactionHandler +import cc.fyre.hcf.faction.event.FactionMemberDeathEvent +import cc.fyre.hcf.statistic.StatisticHandler +import cc.fyre.hcf.statistic.type.* +import cc.fyre.hcf.timer.TimerHandler +import cc.fyre.hcf.timer.TimerType +import org.bukkit.Bukkit +import org.bukkit.ChatColor +import org.bukkit.event.EventHandler +import org.bukkit.event.EventPriority +import org.bukkit.event.Listener +import org.bukkit.event.entity.PlayerDeathEvent + +object FactionDeathListener : Listener { + + + @EventHandler(priority = EventPriority.LOW) + private fun onPlayerDeath(event: PlayerDeathEvent) { + + var faction = FactionHandler.getFactionByPlayer(event.entity.uniqueId) + + if (faction != null) { + Bukkit.getServer().pluginManager.callEvent(FactionMemberDeathEvent(faction,event.entity,event.entity.killer,event.deathMessage)) + } + + TimerHandler.removeTimer(event.entity.uniqueId,TimerType.SPAWN_TAG) + TimerHandler.removeTimer(event.entity.uniqueId,TimerType.ENDER_PEARL) + + event.entity.world.strikeLightningEffect(event.entity.location) + + StatisticHandler.increaseStatistic(event.entity.uniqueId,DeathsStatistic,1) + StatisticHandler.setStatistic(event.entity.uniqueId,KillStreakStatistic,0) + + if (event.entity.killer == null) { + return + } + + faction = FactionHandler.getFactionByPlayer(event.entity.killer.uniqueId) + + if (faction != null) { + faction.kills += 1 + faction.points += 1 + } + + val killStreak = StatisticHandler.getStatistic(event.entity.killer.uniqueId,KillStreakStatistic).getValue() + 1 + + StatisticHandler.increaseStatistic(event.entity.killer.uniqueId,KillsStatistic,1) + StatisticHandler.increaseStatistic(event.entity.killer.uniqueId,KillStreakStatistic,killStreak) + + if (killStreak > StatisticHandler.getStatistic(event.entity.killer.uniqueId,HighestKillStreak).getValue()) { + StatisticHandler.setStatistic(event.entity.killer.uniqueId,HighestKillStreak,killStreak) + } + + val balance = StatisticHandler.getStatistic(event.entity.uniqueId,BalanceStatistic).getValue() + + if (balance > 0) { + StatisticHandler.setStatistic(event.entity.uniqueId,BalanceStatistic,0) + StatisticHandler.increaseStatistic(event.entity.killer.uniqueId,BalanceStatistic,balance) + event.entity.killer.sendMessage("${ChatColor.GOLD}You earned ${ChatColor.GREEN}${ChatColor.BOLD}$$balance${ChatColor.GOLD} for killing ${ProfileHandler.getDisplayNameById(event.entity.uniqueId)}${ChatColor.GOLD}!") + } + + + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/listener/FactionFocusListener.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/listener/FactionFocusListener.kt new file mode 100644 index 0000000..1328ed7 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/listener/FactionFocusListener.kt @@ -0,0 +1,31 @@ +package cc.fyre.hcf.faction.listener + +import cc.fyre.hcf.faction.FactionHandler +import cc.fyre.hcf.faction.event.FactionHQUpdateEvent +import com.lunarclient.bukkitapi.LunarClientAPI +import org.bukkit.event.EventHandler +import org.bukkit.event.EventPriority +import org.bukkit.event.Listener +import org.bukkit.event.player.PlayerJoinEvent + +/** + * @project hcf + * + * @date 15/01/2021 + * @author xanderume@gmail.com + */ +object FactionFocusListener : Listener { + + @EventHandler(priority = EventPriority.MONITOR) + private fun onPlayerJoin(event: PlayerJoinEvent) { + + val faction = FactionHandler.getFactionByPlayer(event.player.uniqueId) + + if (faction?.getFocusWayPoint() == null) { + return + } + + LunarClientAPI.getInstance().sendWaypoint(event.player,faction.getFocusWayPoint()) + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/listener/FactionMapListener.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/listener/FactionMapListener.kt new file mode 100644 index 0000000..f9dd411 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/listener/FactionMapListener.kt @@ -0,0 +1,51 @@ +package cc.fyre.hcf.faction.listener + +import cc.fyre.hcf.HCF +import cc.fyre.hcf.faction.FactionMetadata +import cc.fyre.hcf.faction.claim.ClaimHandler +import cc.fyre.hcf.faction.command.FactionMapCommand +import cc.fyre.hcf.faction.type.SystemFaction +import cc.fyre.hcf.pillar.PillarHandler +import cc.fyre.hcf.pillar.PillarType +import cc.fyre.hcf.statistic.StatisticHandler +import cc.fyre.hcf.statistic.type.setting.MapSetting +import cc.fyre.shard.util.item.ItemUtil +import org.bukkit.ChatColor +import org.bukkit.Location +import org.bukkit.event.EventHandler +import org.bukkit.event.EventPriority +import org.bukkit.event.Listener +import org.bukkit.event.entity.PlayerDeathEvent +import org.bukkit.event.player.PlayerJoinEvent +import org.bukkit.event.player.PlayerQuitEvent +import org.bukkit.inventory.ItemStack + +/** + * @project hcf + * + * @date 31/08/2020 + * @author xanderume@gmail.com + */ +object FactionMapListener : Listener { + + @EventHandler(priority = EventPriority.LOWEST) + private fun onPlayerDeath(event: PlayerDeathEvent) { + + if (!StatisticHandler.getStatistic(event.entity.uniqueId,MapSetting).getValue()) { + return + } + + StatisticHandler.setStatistic(event.entity.uniqueId,MapSetting,false) + } + + @EventHandler(priority = EventPriority.LOWEST) + private fun onPlayerQuit(event: PlayerQuitEvent) { + + if (!StatisticHandler.getStatistic(event.player.uniqueId,MapSetting).getValue()) { + return + } + + StatisticHandler.setStatistic(event.player.uniqueId,MapSetting,false) + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/listener/FactionMemberListener.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/listener/FactionMemberListener.kt new file mode 100644 index 0000000..e93e96e --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/listener/FactionMemberListener.kt @@ -0,0 +1,108 @@ +package cc.fyre.hcf.faction.listener + +import cc.fyre.hcf.HCF + +import cc.fyre.hcf.faction.FactionHandler +import cc.fyre.hcf.faction.Faction +import cc.fyre.hcf.faction.event.FactionMemberDeathEvent +import cc.fyre.hcf.faction.type.PlayerFaction +import org.bukkit.ChatColor +import org.bukkit.entity.Player +import org.bukkit.entity.Projectile +import org.bukkit.event.EventHandler +import org.bukkit.event.EventPriority +import org.bukkit.event.Listener +import org.bukkit.event.entity.EntityDamageByEntityEvent +import org.bukkit.event.player.PlayerJoinEvent +import org.bukkit.event.player.PlayerQuitEvent + +/** + * @project hcf + * + * @date 20/07/2020 + * @author xanderume@gmail.com + */ +object FactionMemberListener : Listener { + + @EventHandler(priority = EventPriority.MONITOR) + private fun onPlayerJoin(event: PlayerJoinEvent) { + + val faction = FactionHandler.getFactionByPlayer(event.player.uniqueId) ?: return + + faction.onlineMembers++ + faction.members[event.player.uniqueId]?.online = true + + faction.sendInfo(event.player) + faction.getAllies().flatMap{ally -> ally.getOnlineMembers()}.forEach{ally -> ally.sendMessage("${Faction.ALLY_COLOR}Ally Online: ${ChatColor.WHITE}${event.player.name}")} + faction.getOnlineMembers().filter{member -> member.uniqueId != event.player.uniqueId}.forEach{member -> member.sendMessage("${ChatColor.GREEN}Member Online: ${ChatColor.WHITE}${event.player.name}")} + } + + @EventHandler(priority = EventPriority.MONITOR) + private fun onPlayerQuit(event: PlayerQuitEvent) { + + val faction = FactionHandler.getFactionByPlayer(event.player.uniqueId) ?: return + + faction.onlineMembers-- + faction.members[event.player.uniqueId]?.online = false + + faction.getAllies().flatMap{ally -> ally.getOnlineMembers()}.forEach{ally -> ally.sendMessage("${Faction.ALLY_COLOR}Ally Offline: ${ChatColor.WHITE}${event.player.name}")} + faction.getOnlineMembers().filter{member -> member.uniqueId != event.player.uniqueId}.forEach{member -> member.sendMessage("${ChatColor.RED}Member Offline: ${ChatColor.WHITE}${event.player.name}")} + } + + @EventHandler(priority = EventPriority.HIGH) + private fun onEntityDamageByEntity(event: EntityDamageByEntityEvent) { + + if (event.entity !is Player) { + return + } + + var damager: Player? = null + + if (event.damager is Player) { + damager = event.damager as Player + } else if (event.damager is Projectile && (event.damager as Projectile).shooter is Player) { + damager = (event.damager as Projectile).shooter as Player + } + + if (damager == null) { + return + } + + if (event.entity.uniqueId == damager.uniqueId) { + return + } + + val faction = FactionHandler.getFactionByPlayer(damager.uniqueId) + + if (faction == null || !faction.isFriendly(event.entity as Player)) { + return + } + + damager.sendMessage("${ChatColor.YELLOW}You cannot hurt ${if (faction.isMember(event.entity as Player)) ChatColor.DARK_GREEN else Faction.ALLY_COLOR}${(event.entity as Player).name}${ChatColor.YELLOW}.") + + event.isCancelled = true + } + + @EventHandler(priority = EventPriority.MONITOR) + private fun onMemberDeath(event: FactionMemberDeathEvent) { + + val newDTR = event.faction.getDTR(true) - PlayerFaction.DTR_LOSS + + if (event.faction.getDTR() > 0 && newDTR <= 0) { + event.faction.points - (event.faction.points / 2) + } else { + event.faction.points -= 1 + } + + event.faction.setDTR(newDTR) + event.faction.setDTRFreeze(PlayerFaction.DTR_REGEN) + event.faction.flagForSave() + + event.faction.sendMessage( + "${ChatColor.RED}Member Death: ${ChatColor.WHITE}${event.player.name}", + "${ChatColor.RED}DTR: ${ChatColor.WHITE}${FactionHandler.DTR_FORMAT.format(event.faction.getDTR())}" + ) + + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/listener/FactionMetadataListener.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/listener/FactionMetadataListener.kt new file mode 100644 index 0000000..5ee9d11 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/listener/FactionMetadataListener.kt @@ -0,0 +1,168 @@ +package cc.fyre.hcf.faction.listener + +import cc.fyre.hcf.HCF +import cc.fyre.hcf.ability.event.AbilityUseEvent +import cc.fyre.hcf.faction.FactionHandler +import cc.fyre.hcf.faction.FactionMetadata +import cc.fyre.hcf.faction.type.SystemFaction +import cc.fyre.hcf.faction.event.FactionMoveEvent +import cc.fyre.hcf.game.GameFaction +import cc.fyre.hcf.map.sotw.SOTWHandler +import cc.fyre.hcf.timer.TimerHandler +import cc.fyre.hcf.timer.TimerType +import org.bukkit.ChatColor +import org.bukkit.entity.Player +import org.bukkit.entity.Projectile +import org.bukkit.event.EventHandler +import org.bukkit.event.EventPriority +import org.bukkit.event.Listener +import org.bukkit.event.entity.EntityDamageByEntityEvent +import org.bukkit.event.entity.EntityDamageEvent +import org.bukkit.event.entity.FoodLevelChangeEvent +import org.bukkit.event.player.PlayerDropItemEvent +import org.bukkit.event.player.PlayerTeleportEvent + +/** + * @project hcf + * + * @date 23/07/2020 + * @author xanderume@gmail.com + */ +object FactionMetadataListener : Listener { + + @EventHandler(priority = EventPriority.MONITOR) + private fun onFactionMove(event: FactionMoveEvent) { + + if (event.isCancelled) { + return + } + + if (event.to !is SystemFaction || !event.to.hasMetadata(FactionMetadata.SAFE_ZONE)) { + return + } + + event.player.foodLevel = 20 + event.player.health = event.player.maxHealth + } + + @EventHandler(priority = EventPriority.LOWEST) + private fun onFoodLevelChange(event: FoodLevelChangeEvent) { + + if (event.entity !is Player) { + return + } + + if (!FactionMetadata.SAFE_ZONE.isValidAtLocation(event.entity.location)) { + return + } + + event.isCancelled = true + } + + @EventHandler(priority = EventPriority.HIGHEST,ignoreCancelled = true) + private fun onEntityDamage(event: EntityDamageEvent) { + + if (event.entity !is Player) { + return + } + + if (!FactionMetadata.SAFE_ZONE.isValidAtLocation(event.entity.location)) { + return + } + + event.isCancelled = true + } + + @EventHandler(priority = EventPriority.HIGH,ignoreCancelled = true) + private fun onEntityDamageByEntity(event: EntityDamageByEntityEvent) { + + if (event.entity !is Player) { + return + } + + + + var damager: Player? = null + + if (event.damager is Player) { + damager = event.damager as Player + } else if (event.damager is Projectile && (event.damager as Projectile).shooter is Player) { + damager = (event.damager as Projectile).shooter as Player + } + + if (damager == null) { + return + } + + if (!FactionMetadata.SAFE_ZONE.isValidAtLocation(damager.location)) { + return + } + + event.isCancelled = true + } + + @EventHandler(priority = EventPriority.HIGH,ignoreCancelled = true) + private fun onPlayerTeleport(event: PlayerTeleportEvent) { + + if (event.cause != PlayerTeleportEvent.TeleportCause.ENDER_PEARL) { + return + } + + if (!TimerHandler.hasTimer(event.player.uniqueId, TimerType.ENDER_PEARL)) { + // Pearl landed but the player died. + return + } + + val faction = FactionHandler.getFactionByLocation(event.to) + + if (faction is SystemFaction && !faction.isEnderPearlAllowed() && !FactionMetadata.SAFE_ZONE.isValidAtLocation(event.from)) { + event.player.sendMessage("${ChatColor.RED}${ChatColor.BOLD}Invalid Pearl!${ChatColor.YELLOW} You cannot enderpearl into ${faction.getDisplayName(event.player)}${ChatColor.YELLOW}!") + event.isCancelled = true + return + } + + if (!TimerHandler.hasTimer(event.player.uniqueId, TimerType.PVP_TIMER)) { + return + } + + if (faction is SystemFaction && faction.isEvent()) { + event.player.sendMessage("${ChatColor.RED}${ChatColor.BOLD}Invalid Pearl!${ChatColor.YELLOW} You cannot enderpearl into ${faction.getDisplayName(event.player)}${ChatColor.YELLOW} whilst having an active PvP Timer!") + event.isCancelled = true + return + } + + } + + @EventHandler(priority = EventPriority.NORMAL) + private fun onPlayerDropItem(event: PlayerDropItemEvent) { + + if (!FactionMetadata.SAFE_ZONE.isValidAtLocation(event.player.location)) { + return + } + + if (!SOTWHandler.isActive()) { + return + } + + event.itemDrop.remove() + } + + @EventHandler(priority = EventPriority.NORMAL) + private fun onAbilityUse(event: AbilityUseEvent) { + + val faction = FactionHandler.getFactionByLocation(event.player.location) + + var valid = true + + if (faction is SystemFaction && (faction.hasMetadata(FactionMetadata.SAFE_ZONE) || faction is GameFaction && faction.isActive())) { + valid = false + } + + if (valid) { + return + } + + event.player.sendMessage("${ChatColor.RED}You cannot use a ${event.ability.getDisplayName()}${ChatColor.RED} in ${faction.getDisplayName(event.player)}${ChatColor.RED}.") + event.isCancelled = true + } +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/listener/FactionMoveListener.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/listener/FactionMoveListener.kt new file mode 100644 index 0000000..efc3bf0 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/listener/FactionMoveListener.kt @@ -0,0 +1,98 @@ +package cc.fyre.hcf.faction.listener + +import cc.fyre.Forge +import cc.fyre.handler.MovementHandler +import cc.fyre.hcf.faction.FactionHandler +import cc.fyre.hcf.faction.event.FactionMoveEvent +import mkremins.fanciful.FancyMessage +import net.minecraft.server.v1_7_R4.PacketPlayInFlying +import org.bukkit.Bukkit +import org.bukkit.ChatColor +import org.bukkit.Location +import org.bukkit.entity.Player +import org.bukkit.event.EventHandler +import org.bukkit.event.EventPriority +import org.bukkit.event.Listener +import org.bukkit.event.player.PlayerChangedWorldEvent +import org.bukkit.event.player.PlayerPortalEvent +import org.bukkit.event.player.PlayerTeleportEvent + +/** + * @project hcf + * + * @date 16/11/2020 + * @author xanderume@gmail.com + */ +object FactionMoveListener : MovementHandler, Listener { + + init { + Forge.INSTANCE.addMovementHandler(this) + } + + @EventHandler(priority = EventPriority.MONITOR) + private fun onPlayerTeleport(event: PlayerTeleportEvent) { + + if (event.isCancelled) { + return + } + + this.handleUpdateLocation(event.player,event.to,event.from,null) + } + + @EventHandler(priority = EventPriority.MONITOR) + private fun onPlayerPortal(event: PlayerPortalEvent) { + + if (event.isCancelled) { + return + } + + this.handleUpdateLocation(event.player,event.to,event.from,null) + } + + override fun handleUpdateRotation(player: Player, to: Location, from: Location, packet: PacketPlayInFlying?) {} + + override fun handleUpdateLocation(player: Player, to: Location, from: Location, packet: PacketPlayInFlying?) { + + if (from.blockX == to.blockX && from.blockZ == to.blockZ) { + return + } + + val toFaction = FactionHandler.getFactionByLocation(to) + val fromFaction = FactionHandler.getFactionByLocation(from) + + if (fromFaction.id == toFaction.id) { + return + } + + val event = FactionMoveEvent(player,fromFaction,toFaction) + + Bukkit.getServer().pluginManager.callEvent(event) + + if (event.isCancelled) { + player.teleport(from) + return + } + + val faction = FactionHandler.getFactionByPlayer(player.uniqueId) + + FancyMessage("${ChatColor.YELLOW}Now leaving: ") + .then(if (faction != null) fromFaction.getDisplayName(faction) else fromFaction.getDisplayName(player)) + .tooltip("${ChatColor.GREEN}Click to view faction info.") + .command("/faction show ${fromFaction.name}") + .then(" ${ChatColor.YELLOW}(") + .then(fromFaction.getDeathbanStatus().displayName) + .then("${ChatColor.YELLOW})") + .send(player) + + FancyMessage("${ChatColor.YELLOW}Now entering: ") + .then(if (faction != null) toFaction.getDisplayName(faction) else toFaction.getDisplayName(player)) + .tooltip("${ChatColor.GREEN}Click to view faction info.") + .command("/faction show ${toFaction.name}") + .then(" ${ChatColor.YELLOW}(") + .then(toFaction.getDeathbanStatus().displayName) + .then("${ChatColor.YELLOW})") + .send(player) + + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/listener/FactionPistonListener.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/listener/FactionPistonListener.kt new file mode 100644 index 0000000..fd63dd5 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/listener/FactionPistonListener.kt @@ -0,0 +1,66 @@ +package cc.fyre.hcf.faction.listener + +import cc.fyre.hcf.HCF +import cc.fyre.hcf.faction.FactionHandler +import cc.fyre.hcf.faction.type.PlayerFaction +import org.bukkit.event.EventHandler +import org.bukkit.event.EventPriority +import org.bukkit.event.Listener +import org.bukkit.event.block.BlockPistonExtendEvent +import org.bukkit.event.block.BlockPistonRetractEvent + +/** + * @project hcf + * + * @date 22/07/2020 + * @author xanderume@gmail.com + */ +object FactionPistonListener : Listener { + + @EventHandler(priority = EventPriority.HIGH,ignoreCancelled = true) + private fun onPistonExtend(event: BlockPistonExtendEvent) { + + val faction = FactionHandler.getFactionByLocation(event.block.location) + + for (value in event.blocks.withIndex()) { + + val block = event.block.getRelative(event.direction,value.index + 1) + + val targetFaction = FactionHandler.getFactionByLocation(block.location) + + if (targetFaction.id == faction.id || targetFaction is PlayerFaction && targetFaction.isRaidable()) { + continue + } + + if (!(block.isEmpty && block.isLiquid)) { + continue + } + + event.isCancelled = true + break + } + + } + + + @EventHandler(priority = EventPriority.HIGH,ignoreCancelled = true) + private fun onPistonRetract(event: BlockPistonRetractEvent) { + + if (!event.isSticky) { + return + } + + val block = event.retractLocation.block + + if (block.isEmpty || block.isLiquid) { + return + } + + if (FactionHandler.getFactionByLocation(event.block.location).id == FactionHandler.getFactionByLocation(block.location).id) { + return + } + + event.isCancelled = true + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/listener/FactionProtectionListener.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/listener/FactionProtectionListener.kt new file mode 100644 index 0000000..38c2831 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/listener/FactionProtectionListener.kt @@ -0,0 +1,345 @@ +package cc.fyre.hcf.faction.listener + +import cc.fyre.hcf.faction.FactionHandler +import cc.fyre.hcf.faction.type.PlayerFaction +import cc.fyre.hcf.faction.type.SystemFaction +import com.google.common.collect.ImmutableSet +import org.bukkit.ChatColor +import org.bukkit.Material +import org.bukkit.block.Block +import org.bukkit.block.Chest +import org.bukkit.block.DoubleChest +import org.bukkit.entity.ItemFrame +import org.bukkit.entity.Player +import org.bukkit.entity.Projectile +import org.bukkit.entity.minecart.HopperMinecart +import org.bukkit.event.EventHandler +import org.bukkit.event.EventPriority +import org.bukkit.event.Listener +import org.bukkit.event.block.* +import org.bukkit.event.entity.EntityDamageByEntityEvent +import org.bukkit.event.hanging.HangingBreakByEntityEvent +import org.bukkit.event.hanging.HangingPlaceEvent +import org.bukkit.event.inventory.InventoryMoveItemEvent +import org.bukkit.event.inventory.InventoryType +import org.bukkit.event.player.* +import java.util.* + +/** + * @project hcf + * + * @date 20/07/2020 + * @author xanderume@gmail.com + */ +object FactionProtectionListener : Listener { + + private val restricted = mutableMapOf() + + val DISALLOW_INTERACT: ImmutableSet = ImmutableSet.of( + Material.FENCE_GATE, + Material.FURNACE, + Material.BURNING_FURNACE, + Material.BREWING_STAND, + Material.CHEST, + Material.HOPPER, + Material.DISPENSER, + Material.WOODEN_DOOR,Material.STONE_BUTTON,Material.WOOD_BUTTON,Material.TRAPPED_CHEST,Material.TRAP_DOOR,Material.LEVER,Material.DROPPER,Material.ENCHANTMENT_TABLE,Material.BED_BLOCK,Material.ANVIL,Material.BEACON) + val ATTACK_DISABLING_BLOCKS: ImmutableSet = ImmutableSet.of(Material.GLASS,Material.WOOD_DOOR,Material.IRON_DOOR,Material.FENCE_GATE) + + + @EventHandler(priority = EventPriority.HIGH,ignoreCancelled = true) + private fun onBlockPlace(event: BlockPlaceEvent) { + + if (FactionHandler.isAdminOverride(event.player)) { + return + } + + val faction = FactionHandler.getFactionByLocation(event.block.location) + + if (faction is PlayerFaction && (faction.isRaidable() || faction.isMember(event.player))) { + return + } + + if (faction is SystemFaction && faction.isBuildingAllowed(event.block)) { + return + } + + event.isCancelled = true + event.player.sendMessage("${ChatColor.YELLOW}You cannot build in ${faction.getDisplayName(event.player)}${ChatColor.YELLOW}'s territory!") + } + + @EventHandler(priority = EventPriority.NORMAL,ignoreCancelled = true) + private fun onBlockBreak(event: BlockBreakEvent) { + + if (FactionHandler.isAdminOverride(event.player)) { + return + } + + val faction = FactionHandler.getFactionByLocation(event.block.location) + + if (faction is PlayerFaction && (faction.isRaidable() || faction.isMember(event.player))) { + return + } + + if (faction is SystemFaction && faction.isBreakingAllowed(event.block)) { + return + } + + if (ATTACK_DISABLING_BLOCKS.any{it == event.block.type}) { + this.restricted[event.player.uniqueId] = System.currentTimeMillis() + 1000L + } + + event.isCancelled = true + event.player.sendMessage("${ChatColor.YELLOW}You cannot build in ${faction.getDisplayName(event.player)}${ChatColor.YELLOW}'s territory!") + } + + @EventHandler(priority = EventPriority.LOWEST) + private fun onPlayerInteract(event: PlayerInteractEvent) { + + if (FactionHandler.isAdminOverride(event.player)) { + return + } + + if (event.action == Action.LEFT_CLICK_AIR || event.action == Action.RIGHT_CLICK_AIR) { + return + } + + if (event.clickedBlock == null) { + return + } + + val faction = FactionHandler.getFactionByLocation(event.clickedBlock.location) + + if (faction is PlayerFaction && (faction.isRaidable() || faction.isMember(event.player))) { + return + } + + if (faction is SystemFaction && faction.isAllowedToInteract(event.clickedBlock,event.player,event.action)) { + return + } + + if (event.action != Action.PHYSICAL && DISALLOW_INTERACT.none{it == event.clickedBlock.type}) { + return + } + + if (event.action == Action.RIGHT_CLICK_BLOCK) { + this.restricted[event.player.uniqueId] = System.currentTimeMillis() + 750L + } + + if (event.action != Action.PHYSICAL) { + event.player.sendMessage("${ChatColor.YELLOW}You cannot do this in ${faction.getDisplayName(event.player)}${ChatColor.YELLOW}'s territory!") + } + + event.isCancelled = true + } + + @EventHandler(priority = EventPriority.HIGH) + private fun onHangingPlace(event: HangingPlaceEvent) { + + if (FactionHandler.isAdminOverride(event.player)) { + return + } + + val faction = FactionHandler.getFactionByLocation(event.block.location) + + if (faction is PlayerFaction && (faction.isRaidable() || faction.isMember(event.player))) { + return + } + + if (faction is SystemFaction && faction.isBuildingAllowed(event.block)) { + return + } + + event.isCancelled = true + } + + @EventHandler(priority = EventPriority.HIGH) + private fun onHangingBreakByEntity(event: HangingBreakByEntityEvent) { + + if (event.remover !is Player) { + return + } + + val player = event.remover as Player + + if (FactionHandler.isAdminOverride(player)) { + return + } + + val faction = FactionHandler.getFactionByLocation(event.entity.location) + + if (faction is PlayerFaction && (faction.isRaidable() || faction.isMember(player))) { + return + } + + if (faction is SystemFaction && faction.isBreakingAllowed(event.entity.location.block)) { + return + } + + event.isCancelled = true + } + + @EventHandler(priority = EventPriority.HIGHEST,ignoreCancelled = true) + private fun onInteractEntity(event: PlayerInteractEntityEvent) { + + if (event.rightClicked !is ItemFrame) { + return + } + + val faction = FactionHandler.getFactionByLocation(event.rightClicked.location) + + if (faction is PlayerFaction && (faction.isRaidable() || faction.isMember(event.player))) { + return + } + + if (faction is SystemFaction && faction.isAllowedToInteract(event.rightClicked.location.block,event.player,Action.RIGHT_CLICK_BLOCK)) { + return + } + + event.isCancelled = true + } + + @EventHandler(priority = EventPriority.HIGH,ignoreCancelled = true) + private fun onEntityDamageItemFrame(event: EntityDamageByEntityEvent) { + + if (event.entity !is ItemFrame) { + return + } + + if (event.damager !is Player && !(event.damager is Projectile && (event.damager as Projectile).shooter is Player)) { + return + } + + val player = if (event.damager is Player) event.damager as Player else (event.damager as Projectile).shooter as Player + + if (FactionHandler.isAdminOverride(player)) { + return + } + + val faction = FactionHandler.getFactionByLocation(event.entity.location) + + if (faction is PlayerFaction && (faction.isRaidable() || faction.isMember(player))) { + return + } + + if (faction is SystemFaction && faction.isBreakingAllowed(event.entity.location.block)) { + return + } + + event.isCancelled = true + } + + @EventHandler(priority = EventPriority.HIGHEST) + private fun onBlockIgnite(event: BlockIgniteEvent) { + + if (event.player == null || FactionHandler.isAdminOverride(event.player)) { + return + } + + val faction = FactionHandler.getFactionByLocation(event.block.location) + + if (faction is PlayerFaction && (faction.isRaidable() || faction.isMember(event.player))) { + return + } + + if (faction is SystemFaction && faction.isBreakingAllowed(event.block)) { + return + } + + if (event.cause == BlockIgniteEvent.IgniteCause.FLINT_AND_STEEL && (faction is PlayerFaction && faction.isMember(event.player))) { + return + } + + event.isCancelled = true + } + + @EventHandler(priority = EventPriority.NORMAL) + private fun onBucketFill(event: PlayerBucketFillEvent) { + + val location = event.blockClicked.getRelative(event.blockFace).location + + if (FactionHandler.isAdminOverride(event.player)) { + return + } + + val faction = FactionHandler.getFactionByLocation(location) + + if (faction is PlayerFaction && (faction.isRaidable() || faction.isMember(event.player))) { + return + } + + if (faction is SystemFaction && faction.isAllowedToInteract(location.block,event.player,Action.RIGHT_CLICK_BLOCK)) { + return + } + + event.isCancelled = true + event.player.sendMessage("${ChatColor.YELLOW}You cannot build in ${faction.getDisplayName(event.player)}${ChatColor.YELLOW}'s territory.") + } + + @EventHandler(priority = EventPriority.NORMAL) + private fun onBucketEmpty(event: PlayerBucketEmptyEvent) { + + val location = event.blockClicked.getRelative(event.blockFace).location + + if (FactionHandler.isAdminOverride(event.player)) { + return + } + + val faction = FactionHandler.getFactionByLocation(location) + + if (faction is PlayerFaction && (faction.isRaidable() || faction.isMember(event.player))) { + return + } + + if (faction is SystemFaction && faction.isBuildingAllowed(location.block)) { + return + } + + event.isCancelled = true + event.player.sendMessage("${ChatColor.YELLOW}You cannot build in ${faction.getDisplayName(event.player)}${ChatColor.YELLOW}'s territory.") + } + + + @EventHandler(priority = EventPriority.NORMAL) + private fun onInventoryMoveItem(event: InventoryMoveItemEvent) { + + if ((event.source.type != InventoryType.CHEST || event.destination.holder !is HopperMinecart)) { + return + } + + var block: Block? = null + + if (event.source.holder is Chest) { + block = (event.source.holder as Chest).location.block + } else if (event.source.holder is DoubleChest) { + block = (event.source.holder as DoubleChest).location.block + } + + if (block == null) { + return + } + + event.isCancelled = true + } + + @EventHandler(priority = EventPriority.MONITOR) + private fun onPlayerQuit(event: PlayerQuitEvent) { + this.restricted.remove(event.player.uniqueId) + } + + @EventHandler(priority = EventPriority.NORMAL,ignoreCancelled = true) + private fun onEntityDamageByEntity(event: EntityDamageByEntityEvent) { + + if (!this.restricted.containsKey(event.damager.uniqueId)) { + return + } + + if (System.currentTimeMillis() >= this.restricted[event.damager.uniqueId]!!) { + this.restricted.remove(event.damager.uniqueId) + return + } + + event.isCancelled = true + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/listener/FactionRallyListener.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/listener/FactionRallyListener.kt new file mode 100644 index 0000000..0c7d642 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/listener/FactionRallyListener.kt @@ -0,0 +1,59 @@ +package cc.fyre.hcf.faction.listener + +import cc.fyre.hcf.HCF +import cc.fyre.hcf.faction.FactionHandler +import cc.fyre.hcf.faction.event.FactionMemberAddEvent +import cc.fyre.hcf.faction.event.FactionMemberRemoveEvent +import com.lunarclient.bukkitapi.LunarClientAPI +import com.lunarclient.bukkitapi.`object`.LCWaypoint +import org.bukkit.Bukkit +import org.bukkit.event.EventHandler +import org.bukkit.event.EventPriority + +import org.bukkit.event.Listener +import org.bukkit.event.player.PlayerJoinEvent +import java.awt.Color + +/** + * @project hcf + * + * @date 01/11/2020 + * @author xanderume@gmail.com + */ +object FactionRallyListener : Listener { + + @EventHandler(priority = EventPriority.MONITOR) + private fun onPlayerJoin(event: PlayerJoinEvent) { + + val faction = FactionHandler.getFactionByPlayer(event.player.uniqueId) + + if (faction?.rally == null) { + return + } + + LunarClientAPI.getInstance().sendWaypoint(event.player,faction.rallyWayPoint) + } + + @EventHandler(priority = EventPriority.MONITOR) + private fun onFactionJoin(event: FactionMemberAddEvent) { + + if (event.faction.rally == null) { + return + } + + LunarClientAPI.getInstance().sendWaypoint(event.target,event.faction.rallyWayPoint) + } + + @EventHandler(priority = EventPriority.MONITOR) + private fun onFactionLeave(event: FactionMemberRemoveEvent) { + + if (event.faction.rally == null) { + return + } + + val player = Bukkit.getServer().getPlayer(event.target) ?: return + + LunarClientAPI.getInstance().removeWaypoint(player,event.faction.rallyWayPoint) + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/listener/FactionStaffListener.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/listener/FactionStaffListener.kt new file mode 100644 index 0000000..974d974 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/listener/FactionStaffListener.kt @@ -0,0 +1,32 @@ +package cc.fyre.hcf.faction.listener + +import cc.fyre.hcf.faction.FactionHandler +import cc.fyre.modsuite.staff.command.RequestCommand +import cc.fyre.modsuite.staff.event.PlayerRequestStaffEvent +import org.bukkit.ChatColor +import org.bukkit.event.EventHandler +import org.bukkit.event.EventPriority +import org.bukkit.event.Listener + +/** + * @project hcf + * + * @date 12/09/2020 + * @author xanderume@gmail.com + */ +object FactionStaffListener : Listener { + + @EventHandler(priority = EventPriority.NORMAL) + private fun onPlayerRequest(event: PlayerRequestStaffEvent) { + + val faction = FactionHandler.getFactionByPlayer(event.player.uniqueId) ?: return + + if (faction.lastRequest != 0L && ((System.currentTimeMillis() - faction.lastRequest) <= RequestCommand.COOLDOWN)) { + event.setCancelled(true,"${ChatColor.RED}Someone in your faction has already requested staff assistance recently.") + return + } + + faction.lastRequest = System.currentTimeMillis() + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/listener/FactionSubclaimListener.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/listener/FactionSubclaimListener.kt new file mode 100644 index 0000000..c147e83 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/listener/FactionSubclaimListener.kt @@ -0,0 +1,242 @@ +package cc.fyre.hcf.faction.listener + +import cc.fyre.hcf.faction.FactionHandler +import cc.fyre.hcf.faction.type.PlayerFaction +import cc.fyre.hcf.faction.type.player.FactionRole +import com.google.common.collect.ImmutableSet +import org.bukkit.ChatColor +import org.bukkit.Material +import org.bukkit.block.* +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.SignChangeEvent +import org.bukkit.event.inventory.InventoryMoveItemEvent +import org.bukkit.event.inventory.InventoryType +import org.bukkit.event.player.PlayerInteractEvent +import java.util.HashSet + + +/** + * @project hcf + * + * @date 30/08/2020 + * @author xanderume@gmail.com + */ +object FactionSubclaimListener : Listener { + + private val OUTSIDE_FACES: Set = ImmutableSet.of(BlockFace.EAST,BlockFace.WEST,BlockFace.NORTH,BlockFace.SOUTH) + private val SUBCLAIM_IDENTIFIER = ChatColor.YELLOW.toString() + ChatColor.BOLD + "[Subclaim]" + private val NO_ACCESS = ChatColor.YELLOW.toString() + "You do not have access to this chest subclaim!" + + @EventHandler(priority = EventPriority.MONITOR,ignoreCancelled = true) + fun onSignUpdate(event: SignChangeEvent) { + + if (!event.getLine(0).lowercase().contains("subclaim")) { + return + } + + val playerTeam = FactionHandler.getFactionByPlayer(event.player.uniqueId) + + val sign = event.block.state as Sign + + if (playerTeam == null) { + event.block.breakNaturally() + event.player.sendMessage(ChatColor.RED.toString() + "You are not in a faction!") + return + } + + if (playerTeam.claims.none{it.contains(sign.location)}) { + event.block.breakNaturally() + event.player.sendMessage(ChatColor.RED.toString() + "You do not own this land!") + return + } + val attachedFace = (sign.data as org.bukkit.material.Sign).attachedFace + val attachedTo = event.block.getRelative(attachedFace) + if (attachedTo.type != Material.CHEST && attachedTo.type != Material.TRAPPED_CHEST) { + event.player.sendMessage("§cSign subclaims only work on chests.") + return + } + if (subclaimSigns(attachedTo).isNotEmpty()) { + event.block.breakNaturally() + event.player.sendMessage(ChatColor.RED.toString() + "This chest is already subclaimed!") + return + } + /*if (!playerTeam.isCaptain(event.getSource().getKitName()) && !playerTeam.isOwner(event.getSource().getKitName())) { + event.getBlock().breakNaturally(); + event.getSource().sendMessage(ChatColor.RED + "You must be a team captain to be able to do this!"); + return; + }*/ + var found = false + for (i in 1..3) { + if (sign.getLine(i) != null && sign.getLine(i).equals(event.player.name,ignoreCase = true)) { + found = true + break + } + } + if (!found) { + if (event.player.name.length > 15) { + event.block.breakNaturally() + event.player.sendMessage("§cYour name is too long for sign subclaims. Consider changing your username.") + return + } + } + val signText = event.getLine(1) + event.getLine(2) + event.getLine(3) + if (signText.isEmpty()) { + event.player.sendMessage(ChatColor.GREEN.toString() + "We automatically added you to this subclaim.") + event.setLine(1,event.player.name) + } + event.setLine(0,SUBCLAIM_IDENTIFIER) + event.player.sendMessage(ChatColor.GREEN.toString() + "Sign subclaim created!") + } + + @EventHandler(priority = EventPriority.HIGH,ignoreCancelled = true) + fun onBlockBreakChest(event: BlockBreakEvent) { + + if (event.block.state !is Chest) { + return + } + + if (FactionHandler.isAdminOverride(event.player)) { + return + } + + val faction = FactionHandler.getFactionByLocation(event.block.location) + + if (faction !is PlayerFaction) { + return + } + + if (faction.isRaidable()) { + return + } + + for (sign in subclaimSigns(event.block)) { + + if (faction.getRole(event.player.uniqueId) == FactionRole.MEMBER) { + event.player.sendMessage(NO_ACCESS) + event.isCancelled = true + } + + } + } + + @EventHandler(priority = EventPriority.HIGH,ignoreCancelled = true) + fun onBlockBreakSign(event: BlockBreakEvent) { + + if (event.block.state !is Sign) { + return + } + + if (FactionHandler.isAdminOverride(event.player)) { + return + } + + val faction = FactionHandler.getFactionByLocation(event.block.location) + + if (faction !is PlayerFaction) { + return + } + + if (faction.isRaidable()) { + return + } + + val sign = event.block.state as Sign + val uuid = event.player.uniqueId + if (sign.getLine(0) == SUBCLAIM_IDENTIFIER) { + var canAccess = faction.getRole(uuid) != FactionRole.MEMBER + for (i in 0..3) { + if (sign.getLine(i) != null && sign.getLine(i).equals(event.player.name,ignoreCase = true)) { + canAccess = true + break + } + } + if (!canAccess) { + event.player.sendMessage(NO_ACCESS) + event.isCancelled = true + } + } + } + + @EventHandler(priority = EventPriority.HIGH,ignoreCancelled = true) + fun onPlayerInteract(event: PlayerInteractEvent) { + if (event.action != Action.RIGHT_CLICK_BLOCK || event.clickedBlock.state !is Chest ) { + return + } + + if (FactionHandler.isAdminOverride(event.player)) { + return + } + + val faction = FactionHandler.getFactionByLocation(event.clickedBlock.location) + + if (faction !is PlayerFaction) { + return + } + + if (faction.isRaidable()) { + return + } + + // Will never be null, we check isUnclaimedOrRaidable above. + val uuid = event.player.uniqueId + for (sign in subclaimSigns(event.clickedBlock)) { + var canAccess = faction.getRole(uuid) != FactionRole.MEMBER + + for (i in 0..3) { + if (sign.getLine(i) != null && sign.getLine(i).equals(event.player.name,ignoreCase = true)) { + canAccess = true + break + } + } + if (!canAccess) { + event.player.sendMessage(NO_ACCESS) + event.isCancelled = true + } + } + } + + @EventHandler + fun onInventoryMoveItem(event: InventoryMoveItemEvent) { + if (event.source.type == InventoryType.CHEST && event.destination.type == InventoryType.HOPPER) { + val inventoryHolder = event.source.holder + var moveBlock: Block? = null + // Special-case double chests + if (inventoryHolder is DoubleChest) { + moveBlock = inventoryHolder.location.block + } else if (inventoryHolder is BlockState) { + moveBlock = (inventoryHolder as BlockState).block + } + if (moveBlock != null && subclaimSigns(moveBlock).size != 0) { + event.isCancelled = true + } + } + } + + fun subclaimSigns(check: Block): Set { + val signs: MutableSet = HashSet() + for (blockFace in OUTSIDE_FACES) { + val relBlock = check.getRelative(blockFace) + if (relBlock.type == check.type) { + subclaimSigns0(signs,relBlock) + } + } + subclaimSigns0(signs,check) + return signs + } + + fun subclaimSigns0(signs: MutableSet,check: Block) { + for (blockFace in OUTSIDE_FACES) { + val relBlock = check.getRelative(blockFace) + if (relBlock.type == Material.WALL_SIGN || relBlock.type == Material.SIGN) { + val sign = relBlock.state as Sign + if (sign.getLine(0) == SUBCLAIM_IDENTIFIER) { + signs.add(sign) + } + } + } + } +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/listener/FactionWayPointListener.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/listener/FactionWayPointListener.kt new file mode 100644 index 0000000..6729952 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/listener/FactionWayPointListener.kt @@ -0,0 +1,135 @@ +package cc.fyre.hcf.faction.listener + +import cc.fyre.hcf.HCF +import cc.fyre.hcf.faction.FactionHandler +import cc.fyre.hcf.faction.event.FactionHQUpdateEvent +import cc.fyre.hcf.game.GameFaction +import cc.fyre.hcf.game.event.GameActivateEvent +import cc.fyre.hcf.game.event.GameCaptureEvent +import cc.fyre.hcf.game.event.GameTerminateEvent +import com.lunarclient.bukkitapi.LunarClientAPI +import com.lunarclient.bukkitapi.`object`.LCWaypoint +import okhttp3.internal.userAgent +import org.bukkit.Bukkit +import org.bukkit.event.EventHandler +import org.bukkit.event.EventPriority + +import org.bukkit.event.Listener +import org.bukkit.event.player.PlayerJoinEvent +import java.util.* +import java.util.concurrent.ConcurrentHashMap + +/** + * @project hcf + * + * @date 18/12/2020 + * @author xanderume@gmail.com + */ +object FactionWayPointListener : Listener { + + private val wayPoints = ConcurrentHashMap>() + + init { + FactionHandler.getAllSystemFactions().forEach{ + + if (it.getHQ() == null || it.getWayPoint() == null) { + return@forEach + } + + if (it is GameFaction && !it.isActive()) { + return@forEach + } + + this.wayPoints.getOrPut(it.getHQ()!!.world.uid) { ConcurrentHashMap.newKeySet() }.add(it.getWayPoint()) + } + } + + @EventHandler(priority = EventPriority.MONITOR) + private fun onPlayerJoin(event: PlayerJoinEvent) { + + if (!this.wayPoints.containsKey(event.player.world.uid)) { + return + } + + this.wayPoints[event.player.world.uid]?.forEach{LunarClientAPI.getInstance().sendWaypoint(event.player,it)} + } + + @EventHandler(priority = EventPriority.MONITOR) + private fun onFactionHQUpdate(event: FactionHQUpdateEvent) { + + if (event.faction.getHQ() == null || event.faction.getWayPoint() == null) { + return + } + + val oldWayPoint = event.faction.getWayPoint() + + if (event.oldHQ != null && oldWayPoint != null) { + this.wayPoints.getOrPut(event.oldHQ.world.uid) { ConcurrentHashMap.newKeySet() }.remove(oldWayPoint) + } + + // Run a little later for the hq and waypoint to update + Bukkit.getServer().scheduler.runTaskLater(HCF.instance,{ + + if (event.newHQ != null && event.faction.getWayPoint() != null) { + this.wayPoints.getOrPut(event.newHQ.world.uid) { ConcurrentHashMap.newKeySet() }.remove(event.faction.getWayPoint()) + } + + Bukkit.getServer().onlinePlayers.forEach{ + + if (oldWayPoint != null && it.world == event.oldHQ?.world) { + LunarClientAPI.getInstance().removeWaypoint(it,oldWayPoint) + } + + if (event.faction.getWayPoint() == null) { + return@forEach + } + + LunarClientAPI.getInstance().sendWaypoint(it,event.faction.getWayPoint()!!) + } + },5L) + + } + + @EventHandler(priority = EventPriority.MONITOR) + private fun onGameActivate(event: GameActivateEvent) { + + if (event.game.getHQ() == null || event.game.getWayPoint() == null) { + return + } + + Bukkit.getServer().onlinePlayers.filter{it.world == event.game.getHQ()!!.world}.forEach{ + LunarClientAPI.getInstance().sendWaypoint(it,event.game.getWayPoint()) + } + + this.wayPoints.getOrPut(event.game.getHQ()!!.world.uid) { ConcurrentHashMap.newKeySet() }.add(event.game.getWayPoint()) + } + + @EventHandler(priority = EventPriority.MONITOR) + private fun onGameCapture(event: GameCaptureEvent) { + + if (event.game.getHQ() == null || event.game.getWayPoint() == null) { + return + } + + Bukkit.getServer().onlinePlayers.filter{it.world == event.game.getHQ()!!.world}.forEach{ + LunarClientAPI.getInstance().removeWaypoint(it,event.game.getWayPoint()) + } + + this.wayPoints.getOrPut(event.game.getHQ()!!.world.uid) { ConcurrentHashMap.newKeySet() }.remove(event.game.getWayPoint()) + } + + @EventHandler(priority = EventPriority.MONITOR) + private fun onGameTerminate(event: GameTerminateEvent) { + + if (event.game.getHQ() == null || event.game.getWayPoint() == null) { + return + } + + Bukkit.getServer().onlinePlayers.filter{it.world == event.game.getHQ()!!.world}.forEach{ + LunarClientAPI.getInstance().removeWaypoint(it,event.game.getWayPoint()) + } + + this.wayPoints.getOrPut(event.game.getHQ()!!.world.uid) { ConcurrentHashMap.newKeySet() }.remove(event.game.getWayPoint()) + } + +} diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/menu/faction/FactionFilterMenu.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/menu/faction/FactionFilterMenu.kt new file mode 100644 index 0000000..04a83ed --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/menu/faction/FactionFilterMenu.kt @@ -0,0 +1,40 @@ +package cc.fyre.hcf.faction.menu.faction + +import cc.fyre.hcf.faction.FactionHandler +import cc.fyre.hcf.faction.list.FactionList +import cc.fyre.hcf.faction.list.FactionListType +import cc.fyre.hcf.faction.menu.faction.button.FactionFilterButton +import cc.fyre.hcf.faction.menu.faction.button.FactionFilterTypeButton +import cc.fyre.hcf.statistic.StatisticHandler +import cc.fyre.hcf.statistic.type.setting.FactionFilterSetting +import cc.fyre.shard.menu.button.Button +import cc.fyre.shard.menu.type.paginated.type.BoxMenu +import org.bukkit.entity.Player + +class FactionFilterMenu(var type: FactionListType) : BoxMenu() { + + override fun getStaticButtons(player: Player): MutableMap { + return mutableMapOf( + 4 to FactionFilterTypeButton(this) + ) + } + + override fun getTitle(player: Player): String { + return "Filter" + } + + override fun getPagedButtons(player: Player): MutableMap { + + val faction = FactionHandler.getFactionByPlayer(player.uniqueId) + + return FactionList.getList(this.type).filter{it.onlineMembers > 0 && it.id != faction?.id} + .withIndex() + .associate{it.index to FactionFilterButton(it.value)} + .toMutableMap() + } + + override fun onClose(player: Player) { + StatisticHandler.setStatistic(player.uniqueId,FactionFilterSetting,this.type) + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/menu/faction/button/FactionFilterButton.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/menu/faction/button/FactionFilterButton.kt new file mode 100644 index 0000000..667230a --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/menu/faction/button/FactionFilterButton.kt @@ -0,0 +1,57 @@ +package cc.fyre.hcf.faction.menu.faction.button + +import cc.fyre.hcf.faction.FactionHandler +import cc.fyre.hcf.faction.type.PlayerFaction +import cc.fyre.shard.menu.button.Button +import cc.fyre.shard.util.item.ItemBuilder +import org.bukkit.ChatColor +import org.bukkit.Material +import org.bukkit.entity.Player +import org.bukkit.event.inventory.InventoryClickEvent +import org.bukkit.inventory.ItemStack + +class FactionFilterButton(private val faction: PlayerFaction) : Button() { + + override fun getItem(player: Player): ItemStack { + + val lore = arrayListOf() + + val faction = FactionHandler.getFactionByPlayer(player.uniqueId) + val raidable = this.faction.isRaidable() + + lore.add(" ") + + if (this.faction.getHQ() != null) { + lore.add("${ChatColor.GOLD}HQ: ${ChatColor.WHITE}${this.faction.getHQ()!!.blockX}, ${this.faction.getHQ()!!.blockZ}") + } + + lore.add("${ChatColor.GOLD}DTR: ${this.faction.getDTRDisplay()}") + lore.add("${ChatColor.GOLD}Points: ${ChatColor.WHITE}${this.faction.points}") + lore.add(" ") + + if (faction != null) { + lore.add("${ChatColor.YELLOW}Click to ${if (faction.focus == this.faction.id) "un-focus" else "focus"} this faction") + } else { + lore.add("${ChatColor.YELLOW}Click to view more faction info") + } + + return ItemBuilder.of(if (raidable) Material.EXPLOSIVE_MINECART else Material.STORAGE_MINECART) + .name(if (raidable) "${ChatColor.RED}${ChatColor.BOLD}${ChatColor.STRIKETHROUGH}${this.faction.name}" else "${ChatColor.GREEN}${ChatColor.BOLD}${this.faction.name}") + .lore(lore) + .build() + } + + override fun onClick(player: Player, event: InventoryClickEvent) { + + val faction = FactionHandler.getFactionByPlayer(player.uniqueId) + + when { + faction == null -> this.faction.sendInfo(player) + faction.focus == this.faction.focus -> faction.setFocus(null) + else -> faction.setFocus(this.faction) + } + + player.closeInventory() + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/menu/faction/button/FactionFilterTypeButton.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/menu/faction/button/FactionFilterTypeButton.kt new file mode 100644 index 0000000..5ef9c06 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/menu/faction/button/FactionFilterTypeButton.kt @@ -0,0 +1,64 @@ +package cc.fyre.hcf.faction.menu.faction.button + +import cc.fyre.hcf.faction.list.FactionListType +import cc.fyre.hcf.faction.menu.faction.FactionFilterMenu +import cc.fyre.shard.menu.button.Button +import cc.fyre.shard.util.UnicodeUtil +import cc.fyre.shard.util.item.ItemBuilder +import org.bukkit.ChatColor +import org.bukkit.Material +import org.bukkit.entity.Player +import org.bukkit.event.inventory.InventoryClickEvent +import org.bukkit.inventory.ItemStack + +class FactionFilterTypeButton(private val menu: FactionFilterMenu) : Button() { + + override fun getItem(player: Player): ItemStack { + + val lore = arrayListOf() + + lore.add(" ") + + for (type in FactionListType.getAllTypes()) { + lore.add("${if (this.menu.type == type) ChatColor.GREEN else ChatColor.GRAY}${UnicodeUtil.DOT_SYMBOL}${ChatColor.WHITE} ${type.displayName}") + } + + lore.add(" ") + lore.add("${ChatColor.YELLOW}Click to scroll between filters") + + return ItemBuilder.of(Material.ANVIL) + .name("${ChatColor.DARK_AQUA}${ChatColor.BOLD}Filter") + .lore(lore) + .build() + } + + override fun onClick(player: Player, event: InventoryClickEvent) { + + var index = this.menu.type.ordinal + + if (event.isLeftClick) { + + if (index >= FactionListType.getAllTypes().lastIndex) { + index = 0 + } else { + index += 1 + } + + } else if (event.isRightClick) { + + if (index <= 0) { + index = FactionListType.getAllTypes().lastIndex + } else { + index -= 1 + } + + } + + this.menu.type = FactionListType.getAllTypes()[index] + } + + override fun isRefresh(player: Player): Boolean { + return true + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/menu/system/SystemEditMenu.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/menu/system/SystemEditMenu.kt new file mode 100644 index 0000000..adac1a7 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/menu/system/SystemEditMenu.kt @@ -0,0 +1,50 @@ +package cc.fyre.hcf.faction.menu.system + +import cc.fyre.hcf.faction.type.SystemFaction +import cc.fyre.hcf.faction.menu.system.button.SystemClaimButton +import cc.fyre.hcf.faction.menu.system.button.SystemDisplayNameButton +import cc.fyre.hcf.faction.menu.system.button.SystemMetadataButton +import cc.fyre.shard.menu.Menu +import cc.fyre.shard.menu.button.Button +import cc.fyre.shard.menu.button.type.BackButton + +import org.bukkit.entity.Player + +/** + * @project hcf + * + * @date 04/07/2020 + * @author xanderume@gmail.com + */ +class SystemEditMenu(private val faction: SystemFaction) : Menu() { + + override fun getSize(player: Player, buttons: Map): Int { + return 3*9 + } + + override fun getTitle(player: Player): String { + return "Editor - ${this.faction.name}" + } + + override fun getButtons(player: Player): MutableMap { + + val toReturn = mutableMapOf() + + var index = 10 + + toReturn[index++] = SystemDisplayNameButton(this.faction) + toReturn[index++] = SystemClaimButton(this,this.faction) + toReturn[index++] = SystemMetadataButton(this,this.faction) + + toReturn.putAll(this.faction.getEditorButtons()) + + toReturn[16] = BackButton(SystemEditorMenu()) + + return toReturn + } + + override fun isFill(player: Player, buttons: Map): Boolean { + return true + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/menu/system/SystemEditorMenu.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/menu/system/SystemEditorMenu.kt new file mode 100644 index 0000000..0c1e7e1 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/menu/system/SystemEditorMenu.kt @@ -0,0 +1,35 @@ +package cc.fyre.hcf.faction.menu.system + +import cc.fyre.hcf.faction.FactionHandler +import cc.fyre.hcf.faction.menu.system.button.SystemButton +import cc.fyre.hcf.faction.menu.system.button.SystemCreateButton +import cc.fyre.shard.menu.button.Button +import cc.fyre.shard.menu.type.paginated.type.BoxMenu + +import org.bukkit.entity.Player + +/** + * @project hcf + * + * @date 04/07/2020 + * @author xanderume@gmail.com + */ +class SystemEditorMenu : BoxMenu() { + + override fun getTitle(player: Player): String { + return "System Factions" + } + + override fun getPagedButtons(player: Player): MutableMap { + return FactionHandler.getAllSystemFactions() + .withIndex() + .associate{it.index to SystemButton(it.value)} + .toMutableMap() + } + + override fun getStaticButtons(player: Player): MutableMap { + return mutableMapOf( + 4 to SystemCreateButton + ) + } +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/menu/system/button/SystemButton.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/menu/system/button/SystemButton.kt new file mode 100644 index 0000000..7f1bf90 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/menu/system/button/SystemButton.kt @@ -0,0 +1,101 @@ +package cc.fyre.hcf.faction.menu.system.button + +import cc.fyre.shard.util.item.ItemBuilder +import cc.fyre.hcf.HCF +import cc.fyre.hcf.faction.FactionHandler +import cc.fyre.hcf.faction.claim.ClaimHandler +import cc.fyre.hcf.faction.type.SystemFaction +import cc.fyre.hcf.faction.event.FactionDisbandEvent +import cc.fyre.hcf.faction.menu.system.SystemEditMenu +import cc.fyre.hcf.faction.menu.system.SystemEditorMenu +import cc.fyre.shard.menu.button.Button +import cc.fyre.shard.menu.type.ConfirmMenu +import cc.fyre.shard.util.UnicodeUtil +import cc.fyre.shard.util.bukkit.ColorUtil +import cc.fyre.shard.util.bukkit.TextSplitter +import org.bukkit.ChatColor +import org.bukkit.DyeColor + +import org.bukkit.Material +import org.bukkit.entity.Player +import org.bukkit.event.inventory.InventoryClickEvent +import org.bukkit.inventory.ItemStack +import java.util.function.Predicate + +/** + * @project hcf + * + * @date 04/07/2020 + * @author xanderume@gmail.com + */ +class SystemButton(private val faction: SystemFaction) : Button() { + + override fun getItem(player: Player): ItemStack { + + val lore = ArrayList() + val color = if (this.faction.displayName == null || this.faction.displayName!!.length < 2) { + DyeColor.WHITE + } else { + ColorUtil.getDyeColor(ChatColor.getByChar(this.faction.displayName!![1])) + } + + lore.add("${ChatColor.DARK_GRAY}${this.faction.name}") + + lore.addAll(this.faction.getEditorInfo()) + lore.add(" ") + + for (metadata in this.faction.metadata) { + lore.add("${ChatColor.GRAY}${UnicodeUtil.BULLETIN_POINT} ${metadata.displayName}") + } + + lore.add(" ") + lore.add("${ChatColor.YELLOW}Click to edit faction") + + return ItemBuilder.of(Material.WOOL) + .name(this.faction.getDisplayName(player)) + .lore(lore) + .data(color.woolData) + .build() + } + + override fun onClick(player: Player,event: InventoryClickEvent) { + + if (event.click.isLeftClick) { + SystemEditMenu(this.faction).open(player) + return + } + + if (event.isShiftClick) { + + object : ConfirmMenu("Disband?",Predicate{ + + if (it) { + FactionHandler.destroy(faction) + + player.sendMessage("${ChatColor.RED}${ChatColor.BOLD}The faction has been disbanded.") + + HCF.instance.server.pluginManager.callEvent(FactionDisbandEvent(faction)) + SystemEditorMenu().open(player) + } else { + SystemEditMenu(faction).open(player) + } + + return@Predicate true + }){}.open(player) + + return + } + + if (this.faction.getHQ() == null && this.faction.claims.isEmpty()) { + player.sendMessage("${ChatColor.LIGHT_PURPLE}${this.faction.name}${ChatColor.YELLOW} doesn't have a HQ or any claims.") + return + } + + val location = this.faction.getHQ() ?: this.faction.claims.iterator().next().getCenter() + + player.teleport(location) + player.sendMessage("${ChatColor.YELLOW}Teleporting to ${ChatColor.LIGHT_PURPLE}${this.faction.name}${ChatColor.YELLOW}.") + return + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/menu/system/button/SystemClaimButton.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/menu/system/button/SystemClaimButton.kt new file mode 100644 index 0000000..3b666f6 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/menu/system/button/SystemClaimButton.kt @@ -0,0 +1,73 @@ +package cc.fyre.hcf.faction.menu.system.button + +import cc.fyre.hcf.faction.claim.Claim +import cc.fyre.hcf.faction.claim.ClaimHandler +import cc.fyre.hcf.faction.type.SystemFaction +import cc.fyre.shard.menu.Menu +import cc.fyre.shard.menu.button.type.ListButton +import cc.fyre.shard.util.bukkit.TextSplitter +import cc.fyre.shard.util.callback.Callback +import cc.fyre.shard.util.item.ItemBuilder +import org.bukkit.ChatColor +import org.bukkit.Material +import org.bukkit.entity.Player +import org.bukkit.inventory.ItemStack +import java.util.stream.IntStream + +class SystemClaimButton(menu: Menu,private val faction: SystemFaction) : ListButton(menu,10,25) { + + override fun addItem(item: Claim, player: Player): Runnable { + return Runnable{} + } + + override fun getDescription(player: Player): List { + return listOf() + } + + override fun getEmptyDescription(player: Player): List { + return TextSplitter.split(text = "This faction currently has no claims, shift left click to add a claim.") + } + + override fun getItemStack(player: Player): ItemStack { + return ItemBuilder.of(Material.GRASS) + .name("${ChatColor.GOLD}${ChatColor.BOLD}Claims") + .build() + } + + override fun getList(): List { + return this.faction.claims + } + + override fun getTextFormat(item: Claim): Pair { + return Pair( + "[${item.x1},${item.z1}] - [${item.x2},${item.z2}]", + "" + ) + } + + override fun isModifiable(): Boolean { + return true + } + + override fun removeItem(item: Claim, player: Player): Runnable { + return Runnable{} + } + + override fun startAddConversation(player: Player, callback: Callback) { + if (ClaimHandler.getSelectionByPlayer(player) != null) { + player.sendMessage("${ChatColor.RED}You already have a claiming wand in your inventory!") + return + } + + val slot = IntRange(0,9).firstOrNull{player.inventory.getItem(it) == null} + + if (slot == null) { + player.sendMessage("${ChatColor.RED}You don't have space in your hotbar for the claim wand!") + return + } + + player.closeInventory() + + ClaimHandler.createSelection(slot,player,this.faction) + } +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/menu/system/button/SystemCreateButton.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/menu/system/button/SystemCreateButton.kt new file mode 100644 index 0000000..1986040 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/menu/system/button/SystemCreateButton.kt @@ -0,0 +1,25 @@ +package cc.fyre.hcf.faction.menu.system.button + +import cc.fyre.hcf.faction.prompt.FactionCreatePrompt +import cc.fyre.shard.menu.button.Button +import cc.fyre.shard.util.item.ItemBuilder +import cc.fyre.shard.util.player.PlayerUtil +import org.bukkit.ChatColor +import org.bukkit.Material +import org.bukkit.entity.Player +import org.bukkit.event.inventory.InventoryClickEvent +import org.bukkit.inventory.ItemStack + +object SystemCreateButton : Button() { + + override fun getItem(player: Player): ItemStack { + return ItemBuilder.of(Material.NETHER_STAR).name("${ChatColor.GREEN}Create Faction").build() + } + + override fun onClick(player: Player, event: InventoryClickEvent) { + player.closeInventory() + PlayerUtil.startPrompt(player,FactionCreatePrompt,300) + return + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/menu/system/button/SystemDisplayNameButton.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/menu/system/button/SystemDisplayNameButton.kt new file mode 100644 index 0000000..eb1e30f --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/menu/system/button/SystemDisplayNameButton.kt @@ -0,0 +1,32 @@ +package cc.fyre.hcf.faction.menu.system.button + +import cc.fyre.hcf.HCF +import cc.fyre.hcf.faction.prompt.FactionDisplayPrompt +import cc.fyre.hcf.faction.type.SystemFaction +import cc.fyre.shard.menu.button.Button +import cc.fyre.shard.util.item.ItemBuilder +import cc.fyre.shard.util.player.PlayerUtil +import org.bukkit.ChatColor +import org.bukkit.Material +import org.bukkit.entity.Player +import org.bukkit.event.inventory.InventoryClickEvent +import org.bukkit.inventory.ItemStack + +class SystemDisplayNameButton(private val faction: SystemFaction) : Button() { + + override fun getItem(player: Player): ItemStack { + return ItemBuilder.of(Material.ITEM_FRAME) + .name("${ChatColor.GOLD}${ChatColor.BOLD}Display Name") + .lore( + " ", + "${ChatColor.YELLOW}Current: ${ChatColor.RED}${this.faction.displayName ?: "None"}" + ) + .build() + } + + override fun onClick(player: Player,event: InventoryClickEvent) { + player.closeInventory() + PlayerUtil.startPrompt(player,FactionDisplayPrompt(this.faction),300,HCF.instance) + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/menu/system/button/SystemMetadataButton.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/menu/system/button/SystemMetadataButton.kt new file mode 100644 index 0000000..5e8da14 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/menu/system/button/SystemMetadataButton.kt @@ -0,0 +1,91 @@ +package cc.fyre.hcf.faction.menu.system.button + +import cc.fyre.hcf.faction.FactionMetadata +import cc.fyre.hcf.faction.claim.Claim +import cc.fyre.hcf.faction.type.SystemFaction +import cc.fyre.shard.menu.Menu +import cc.fyre.shard.menu.button.type.ListButton +import cc.fyre.shard.util.bukkit.TextSplitter +import cc.fyre.shard.util.callback.Callback +import cc.fyre.shard.util.item.ItemBuilder +import org.bukkit.ChatColor +import org.bukkit.Material +import org.bukkit.entity.Player +import org.bukkit.event.inventory.ClickType +import org.bukkit.event.inventory.InventoryClickEvent +import org.bukkit.inventory.ItemStack + +class SystemMetadataButton(menu: Menu, private val faction: SystemFaction) : ListButton(menu,10,25) { + + override fun getDescription(player: Player): List { + return listOf() + } + + override fun getEmptyDescription(player: Player): List { + return listOf() + } + + override fun getExtraDescription(player: Player): List { + return listOf( + "${ChatColor.AQUA}Middle click to add or remove metadata", + ) + } + + override fun getItemStack(player: Player): ItemStack { + return ItemBuilder.of(Material.COMMAND) + .name("${ChatColor.GOLD}${ChatColor.BOLD}Metadata") + .build() + } + + override fun getList(): List { + return FactionMetadata.values.toList() + } + + override fun getTextFormat(item: FactionMetadata): Pair { + + val name = ChatColor.stripColor(item.displayName) + + return Pair( + "${if (this.faction.hasMetadata(item)) ChatColor.GREEN else ChatColor.WHITE}$name", + "" + ) + } + + override fun onLoadedClick(player: Player,event: InventoryClickEvent) { + + if (this.index > FactionMetadata.values.lastIndex) { + return + } + + val metadata = FactionMetadata.values[this.index] + + if (event.click == ClickType.MIDDLE) { + + if (this.faction.hasMetadata(metadata)) { + this.faction.metadata.remove(metadata) + } else { + this.faction.metadata.add(metadata) + } + + this.faction.flagForSave() + return + } + + super.onLoadedClick(player,event) + } + + override fun isModifiable(): Boolean { + return false + } + + override fun addItem(item: FactionMetadata, player: Player): Runnable { + return Runnable{} + } + + override fun removeItem(item: FactionMetadata, player: Player): Runnable { + return Runnable{} + } + + override fun startAddConversation(player: Player,callback: Callback) {} + +} diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/prompt/FactionCreatePrompt.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/prompt/FactionCreatePrompt.kt new file mode 100644 index 0000000..fa965bd --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/prompt/FactionCreatePrompt.kt @@ -0,0 +1,51 @@ +package cc.fyre.hcf.faction.prompt + +import cc.fyre.hcf.HCF +import cc.fyre.hcf.faction.FactionHandler +import cc.fyre.hcf.faction.type.SystemFaction +import cc.fyre.hcf.faction.menu.system.SystemEditMenu +import org.bukkit.ChatColor +import org.bukkit.conversations.ConversationContext +import org.bukkit.conversations.Prompt +import org.bukkit.conversations.StringPrompt +import org.bukkit.entity.Player +import java.util.* + +/** + * @project hcf + * + * @date 05/07/2020 + * @author xanderume@gmail.com + */ +object FactionCreatePrompt : StringPrompt() { + + override fun getPromptText(conversationText: ConversationContext): String { + return "${ChatColor.YELLOW}Please type a name for this faction, or type ${ChatColor.RED}\"cancel\"${ChatColor.YELLOW} to cancel." + } + + override fun acceptInput(conversationContext: ConversationContext,input: String): Prompt? { + + if (input.equals("cancel",true)) { + conversationContext.forWhom.sendRawMessage("${ChatColor.RED}Cancelled creating faction.") + return Prompt.END_OF_CONVERSATION + } + + if (FactionHandler.getFactionByName(input) != null) { + conversationContext.forWhom.sendRawMessage("${ChatColor.RED}Faction \"$input\" already exists.") + return FactionCreatePrompt + } + + val name = input.replace(" ","") + + val faction = SystemFaction(UUID.randomUUID(),name) + + FactionHandler.update(faction) + + faction.flagForSave() + + SystemEditMenu(faction).open(conversationContext.forWhom as Player) + + return Prompt.END_OF_CONVERSATION + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/prompt/FactionDisplayPrompt.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/prompt/FactionDisplayPrompt.kt new file mode 100644 index 0000000..59a6764 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/prompt/FactionDisplayPrompt.kt @@ -0,0 +1,26 @@ +package cc.fyre.hcf.faction.prompt + +import cc.fyre.hcf.faction.menu.system.SystemEditMenu +import cc.fyre.hcf.faction.type.SystemFaction +import org.bukkit.ChatColor +import org.bukkit.conversations.ConversationContext +import org.bukkit.conversations.Prompt +import org.bukkit.conversations.StringPrompt +import org.bukkit.entity.Player + +class FactionDisplayPrompt(private val faction: SystemFaction) : StringPrompt() { + + override fun getPromptText(context: ConversationContext): String { + return "${ChatColor.GREEN}Enter a display name for: ${this.faction.getDisplayName(context.forWhom as Player)}" + } + + override fun acceptInput(context: ConversationContext,input: String): Prompt? { + this.faction.displayName = input + this.faction.flagForSave() + + SystemEditMenu(this.faction).open(context.forWhom as Player) + return END_OF_CONVERSATION + } + + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/service/TeamViewerService.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/service/TeamViewerService.kt new file mode 100644 index 0000000..3e85dd2 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/service/TeamViewerService.kt @@ -0,0 +1,46 @@ +package cc.fyre.hcf.faction.service + +import cc.fyre.hcf.faction.FactionHandler +import com.lunarclient.bukkitapi.LunarClientAPI +import com.lunarclient.bukkitapi.nethandler.client.LCPacketTeammates +import java.util.* + +object TeamViewerService : Runnable { + + override fun run() { + + val now = System.currentTimeMillis() + + FactionHandler.getAllPlayerFactions().forEach{faction -> + + if (faction.onlineMembers <= 0) { + return@forEach + } + + val members = faction.getOnlineMembers().filter{!it.isDead} + val membersOnLunar = members.filter{LunarClientAPI.getInstance().isRunningLunarClient(it)} + + if (membersOnLunar.isEmpty()) { + return@forEach + } + + val locations = mutableMapOf>() + + for (target in members) { + locations[target.uniqueId] = mutableMapOf( + "x" to target.location.x, + "y" to target.location.y, + "z" to target.location.z + ) + } + + membersOnLunar.forEach{LunarClientAPI.getInstance().sendPacket(it,LCPacketTeammates( + faction.getLeader(), + now, + locations + ))} + } + + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/type/PlayerFaction.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/type/PlayerFaction.kt new file mode 100644 index 0000000..1108ff5 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/type/PlayerFaction.kt @@ -0,0 +1,507 @@ +package cc.fyre.hcf.faction.type + +import cc.fyre.core.uuid.UUIDHandler +import cc.fyre.shard.util.TimeUtil +import cc.fyre.hcf.HCF +import cc.fyre.hcf.faction.Faction +import cc.fyre.hcf.faction.FactionHandler +import cc.fyre.hcf.faction.FactionMember +import cc.fyre.hcf.faction.FactionType +import cc.fyre.hcf.faction.command.admin.FactionPointsAddCommand +import cc.fyre.hcf.faction.event.FactionDTRUpdateEvent +import cc.fyre.hcf.faction.event.FactionMemberAddEvent +import cc.fyre.hcf.faction.event.FactionMemberRemoveEvent +import cc.fyre.hcf.faction.type.player.ChatMode +import cc.fyre.hcf.faction.type.player.RegenState +import cc.fyre.hcf.faction.type.player.FactionRole +import cc.fyre.hcf.statistic.StatisticHandler +import cc.fyre.hcf.statistic.type.KillsStatistic +import com.lunarclient.bukkitapi.LunarClientAPI +import com.lunarclient.bukkitapi.`object`.LCWaypoint +import com.squareup.moshi.Json +import com.squareup.moshi.JsonClass + +import mkremins.fanciful.FancyMessage +import org.apache.commons.lang.StringUtils +import org.bukkit.Bukkit +import org.bukkit.ChatColor +import org.bukkit.Color +import org.bukkit.Location +import org.bukkit.command.CommandSender +import org.bukkit.entity.Player +import org.bukkit.scheduler.BukkitRunnable +import org.bukkit.scheduler.BukkitTask +import java.util.* +import kotlin.collections.HashSet +import kotlin.math.max +import kotlin.math.min +import kotlin.math.round + + +/** + * @project hcf + * + * @date 07/04/2020 + * @author xanderume@gmail.com + */ +@JsonClass(generateAdapter = true) +class PlayerFaction(@Json(name = "_id") id: UUID, name: String) : Faction(id,name,FactionType.PLAYER) { + + var dtr = 1.01 + + var kills = 0 + var points = 0 + var balance = 0 + + var allies = mutableSetOf() + var invites = mutableSetOf() + + var members = mutableMapOf() + + var announcement: String? = null + var allyRequests = mutableSetOf() + + var rally: Location? = null + + var lastDTRUpdate = 0L + var lastDTRFreeze = 0L + + var lastRequest = 0L + + var focus: UUID? = null + + @Transient var rallyTask: BukkitTask? = null + @Transient var rallyWayPoint: LCWaypoint? = null + + @Transient var onlineMembers = 0 + + @Transient private var focusWayPoint: LCWaypoint? = null + + // Quick lookups + @Transient private lateinit var leader: UUID + @Transient private var membersByRole = mutableMapOf>() + + override fun init() { + super.init() + + if (this.rally != null) { + this.setRally(this.rally!!) + } + + if (this.focus != null) { + FactionHandler.getFactionById(this.focus!!)?.also{ + + if (it.getHQ() == null) { + return@also + } + + this.focusWayPoint = LCWaypoint("${ChatColor.WHITE}${it.name}",it.getHQ()!!,Color.RED.asRGB(),true,true) + } + } + + this.members.values.forEach{member -> + this.membersByRole.putIfAbsent(member.role,mutableListOf()) + this.membersByRole[member.role]!!.add(member) + } + + this.leader = this.membersByRole[FactionRole.LEADER]!![0].uuid + } + + fun isMember(uuid: UUID):Boolean { + return this.members.containsKey(uuid) + } + + fun isMember(player: Player):Boolean { + return this.members.containsKey(player.uniqueId) + } + + fun isAllied(uuid: UUID):Boolean { + return this.allies.mapNotNull{FactionHandler.getFactionById(it)}.filterIsInstance().any{it.isMember(uuid)} + } + + fun isAllied(player: Player):Boolean { + return this.allies.mapNotNull{FactionHandler.getFactionById(it)}.filterIsInstance().any{it.isMember(player.uniqueId)} + } + + fun isFriendly(player: Player):Boolean { + return this.isMember(player) || this.isAllied(player) + } + + fun isFactionAllied(faction: PlayerFaction):Boolean { + return this.allies.contains(faction.id) || this.id == faction.id + } + + fun isFocused(player: Player):Boolean { + + if (this.focus == null) { + return false + } + + if (this.focus == player.uniqueId) { + return true + } + + val faction = FactionHandler.getFactionByPlayer(player.uniqueId) + + return faction != null && this.focus == faction.id + } + + fun isRaidable():Boolean { + return this.dtr <= 0.0 + } + + fun getRole(uuid: UUID):FactionRole { + + if (!this.members.containsKey(uuid)) { + throw IllegalStateException("$uuid is not in ${this.name} faction!") + } + + return this.members[uuid]?.role ?: FactionRole.MEMBER + } + + fun setRole(uuid: UUID,role: FactionRole) { + + val member = this.members[uuid] ?: throw IllegalStateException("$uuid is not in ${this.name} faction!") + + if (role == FactionRole.LEADER) { + this.leader = uuid + } + + if (this.membersByRole[member.role]?.size == 1) { + this.membersByRole.remove(member.role) + } else { + this.membersByRole[member.role]!!.remove(member) + } + + member.role = role + + this.membersByRole.putIfAbsent(role,mutableListOf()) + this.membersByRole[role]!!.add(member) + } + + fun getLeader():UUID { + return this.leader + } + + fun getChatMode(uuid: UUID):ChatMode { + + if (!this.members.containsKey(uuid)) { + throw IllegalStateException("$uuid is not in ${this.name} faction!") + } + + return this.members[uuid]?.chatMode ?: ChatMode.FACTION + } + + fun sendMessage(vararg message: String) { + this.members.keys.mapNotNull{HCF.instance.server.getPlayer(it)}.forEach{it.sendMessage(message)} + } + + fun sendMessage(vararg messages: FancyMessage) { + this.members.keys.mapNotNull{HCF.instance.server.getPlayer(it)}.forEach{messages.forEach{message -> message.send(it)}} + } + + override fun getDeathbanStatus():DeathbanStatus { + return DeathbanStatus.DEATHBAN + } + + fun addMember(player: Player,role: FactionRole? = null) { + + if (role == FactionRole.LEADER) { + this.leader = player.uniqueId + } + + this.invites.remove(player.uniqueId) + + val member = FactionMember(player.uniqueId,role ?: FactionRole.MEMBER).also{it.online = true} + + this.members[player.uniqueId] = member + this.membersByRole.putIfAbsent(member.role,mutableListOf()) + this.membersByRole[member.role]!!.add(member) + + if (role != FactionRole.LEADER) { + this.sendMessage("${ChatColor.YELLOW}${player.name} has joined the faction!") + } + + FactionHandler.addPlayer(player.uniqueId,this) + Bukkit.getServer().pluginManager.callEvent(FactionMemberAddEvent(this,player)) + + this.onlineMembers++ + } + + fun removeMember(uuid: UUID,kickedBy: UUID?) { + + val member = this.members.remove(uuid) ?: throw IllegalStateException("$uuid is not in ${this.name} faction!") + + if (this.membersByRole[member.role]?.size == 1) { + this.membersByRole.remove(member.role) + } else { + this.membersByRole[member.role]!!.remove(member) + } + + if (this.dtr > this.getMaxDTR()) { + this.dtr = this.getMaxDTR() + } + + FactionHandler.removePlayer(uuid) + Bukkit.getServer().pluginManager.callEvent(FactionMemberRemoveEvent(this,uuid,if (kickedBy == null) FactionMemberRemoveEvent.Cause.LEAVE else FactionMemberRemoveEvent.Cause.KICK)) + + this.onlineMembers-- + } + + override fun sendInfo(sender: CommandSender) { + + sender.sendMessage("${ChatColor.GRAY}${ChatColor.STRIKETHROUGH}${StringUtils.repeat("-",53)}") + sender.sendMessage("${ChatColor.BLUE}${this.name} ${ChatColor.GRAY}[${this.onlineMembers}/${this.members.size}] ${ChatColor.DARK_AQUA}- ${ChatColor.YELLOW}HQ: ${ChatColor.WHITE}${if (this.getHQ() == null) "None" else "${this.getHQ()!!.blockX}, ${this.getHQ()!!.blockZ}"}") + + for (entry in this.membersByRole.entries) { + val players = StringUtils.join(entry.value.map{member -> "${this.getDisplayName(member.uuid)}${ChatColor.YELLOW}[${ChatColor.GREEN}${StatisticHandler.getStatistic(member.uuid,KillsStatistic).getValue()}${ChatColor.YELLOW}]"}.toTypedArray(),"${ChatColor.GRAY}, ") + + sender.sendMessage("${ChatColor.YELLOW}${entry.key.displayName}${if (entry.key != FactionRole.LEADER) "s" else ""}: $players") + } + + if (sender !is Player || sender.hasPermission(FactionPointsAddCommand.PERMISSION)) { + sender.sendMessage("${ChatColor.YELLOW}Points: ${ChatColor.RED}${this.points}") + } + + sender.sendMessage("${ChatColor.YELLOW}Balance: ${ChatColor.BLUE}$${this.balance}") + + if (this.isOnDTRFreeze()) { + sender.sendMessage("${ChatColor.YELLOW}DTR Regen: ${ChatColor.BLUE}${TimeUtil.formatIntoDetailedString(this.getDTRFreeze())}") + } + + sender.sendMessage("${ChatColor.YELLOW}Deaths Until Raidable: ${this.getDTRDisplay()}${this.getDTRState().display}") + + if (this.announcement != null && sender is Player && this.isMember(sender.uniqueId)) { + sender.sendMessage("${ChatColor.YELLOW}Announcement: ${ChatColor.LIGHT_PURPLE}${this.announcement}") + } + + sender.sendMessage("${ChatColor.GRAY}${ChatColor.STRIKETHROUGH}${StringUtils.repeat("-",53)}") + } + + override fun getDisplayName(faction: Faction): String { + + if (this.id == faction.id) { + return "${FACTION_COLOR}${this.name}" + } + + if (this.allies.contains(faction.id)) { + return "${ALLY_COLOR}${faction.name}" + } + + if (faction is PlayerFaction && this.focus == faction.focus) { + return "${ChatColor.LIGHT_PURPLE}${faction.name}" + } + + return "${ENEMY_COLOR}${this.name}" + } + + override fun getDisplayName(sender: CommandSender): String { + + if (sender !is Player) { + return "${ENEMY_COLOR}${this.name}" + } + + val faction = FactionHandler.getFactionByPlayer(sender.uniqueId) ?: return "${ENEMY_COLOR}${this.name}" + + if (this.allies.contains(faction.id)) { + return "${ALLY_COLOR}${this.name}" + } + + if (faction.focus == this.id) { + return "${ChatColor.LIGHT_PURPLE}${this.name}" + } + + return "${if (faction.id == this.id) FACTION_COLOR else ENEMY_COLOR}${this.name}" + } + + fun getDisplayName(uuid: UUID):String { + + val player = HCF.instance.server.getPlayer(uuid) + + if (player != null) { + return "${ChatColor.GREEN}${player.name}" + } + + return "${ChatColor.GRAY}${UUIDHandler.getUsernameById(uuid)}" + } + + fun getAllies():List { + return this.allies.mapNotNull{FactionHandler.getFactionById(it)}.filterIsInstance() + } + + fun getOnlineMembers():HashSet { + return this.members.keys.mapNotNull{HCF.instance.server.getPlayer(it)}.toHashSet() + } + + fun updateDTR() { + + if (this.getDTRState() != RegenState.REGEN) { + return + } + + val now = System.currentTimeMillis() + val timePassed = now - this.lastDTRUpdate + + if (timePassed < DTR_UPDATE_TIME) { + return + } + + val remaining = timePassed % DTR_UPDATE_TIME + val multiplier = ((timePassed + remaining) / DTR_UPDATE_TIME).toInt() + + this.lastDTRUpdate = now - remaining + + if (HCF.instance.isKitMap()) { + this.setDTR(this.getMaxDTR()) + } else { + this.setDTR(min(this.dtr + (multiplier * (DTR_UPDATE_INCREMENT * (if (this.onlineMembers <= 0) 0 else this.onlineMembers))),this.getMaxDTR())) + } + + this.flagForSave() + } + + fun getDTR():Double { + return this.dtr + } + + fun getDTR(update: Boolean):Double { + + if (update) { + this.updateDTR() + } + + return this.dtr + } + + fun setDTR(dtr: Double) { + + val newDTR = max(round(dtr * 100.0) / 100.0,-0.99) + + HCF.instance.server.pluginManager.callEvent(FactionDTRUpdateEvent(this,this.dtr,newDTR)) + + this.dtr = newDTR + this.lastDTRUpdate = System.currentTimeMillis() + } + + fun getMaxDTR():Double { + return DTR_LIMIT[this.members.size - 1] + } + + fun getDTRState():RegenState { + + if (this.isOnDTRFreeze()) { + return RegenState.PAUSED + } + + if (this.dtr < this.getMaxDTR()) { + + if (this.onlineMembers <= 0) { + return RegenState.WAITING + } + + return RegenState.REGEN + } + + return RegenState.FULL + } + + fun isOnDTRFreeze():Boolean { + return if (this.lastDTRFreeze == 0L) false else (this.lastDTRFreeze - System.currentTimeMillis()) > 0 + } + + fun getDTRFreeze():Long { + return if (this.lastDTRFreeze == 0L) 0L else this.lastDTRFreeze - System.currentTimeMillis() + } + + fun setDTRFreeze(duration: Long) { + + val now = System.currentTimeMillis() + + this.lastDTRFreeze = now + duration + this.lastDTRUpdate = now + (DTR_UPDATE_TIME * 2) + } + + fun getDTRDisplay():String { + this.updateDTR() + return "${if (this.dtr > 1.0) ChatColor.GREEN else if (this.dtr <= 0) ChatColor.DARK_RED else ChatColor.YELLOW}${FactionHandler.DTR_FORMAT.format(this.dtr)}" + } + + fun getFocusWayPoint():LCWaypoint? { + return this.focusWayPoint + } + + fun setFocus(faction: PlayerFaction?) { + + val members = this.getOnlineMembers() + + if (this.focus != null && this.focusWayPoint != null) { + members.forEach{LunarClientAPI.getInstance().removeWaypoint(it,this.focusWayPoint)} + } + + this.focus = faction?.id + + if (faction?.getHQ() == null) { + return + } + + this.focusWayPoint = LCWaypoint("${ChatColor.WHITE}${faction.name}",faction.getHQ()!!,Color.RED.asRGB(),true,true) + + members.forEach{LunarClientAPI.getInstance().sendWaypoint(it,this.focusWayPoint)} + } + + @JvmName("setRally1") + fun setRally(location: Location) { + + if (this.rallyTask != null) { + this.rallyTask!!.cancel() + } + + this.rally = location + this.rallyTask = object : BukkitRunnable() { + + override fun run() { + this@PlayerFaction.rally = null + this@PlayerFaction.rallyTask = null + + if (this@PlayerFaction.rallyWayPoint != null) { + this@PlayerFaction.getOnlineMembers().forEach{LunarClientAPI.getInstance().removeWaypoint(it,this@PlayerFaction.rallyWayPoint)} + } + + this@PlayerFaction.sendMessage("${ChatColor.DARK_AQUA}The faction rally has expired!") + } + + }.runTaskLater(HCF.instance,RALLY_DURATION_SECONDS * 20L) + + this.rallyWayPoint = LCWaypoint("Rally",this.rally,Color.BLUE.asRGB(),true,true) + } + + companion object { + + const val DTR_LOSS = 1.0 + const val DTR_REGEN = 25 * (60 * 1000L) + + //const val RALLY_DURATION_TICK = 10 * 60L + //const val RALLY_DURATION_MILLIS = RALLY_DURATION_TICK * 1000L + + const val RALLY_DURATION_SECONDS = 15 * 60 + const val RALLY_DURATION_MILLISECONDS = RALLY_DURATION_SECONDS * 1000L + + + const val DTR_UPDATE_TIME = 60 * 1000L + const val DTR_UPDATE_INCREMENT = 0.25 + + const val MEMBER_LIMIT = 5 + const val GAME_REQUIRED_MEMBERS = 3 + + val DTR_LIMIT = doubleArrayOf( + 1.01, 2.02, 3.03, 3.6, 4.5, // 1 to 5 + 5.5, 5.75, 5.75, 6.25, // 6 to 10 + 6.25, 6.5, 6.5, 6.5, 6.5, // 11 to 15 + 6.5, 6.5, 6.5, 6.5, 6.5, // 16 to 20 + 6.25, 6.25, 6.25, 6.25, 6.5, // 21 to 25 + 6.5, 6.5, 6.5, 6.75, 6.75, // 26 to 30 + 7.0, 7.0, 7.0, 7.0, 7.0, 9.0, 9.0, 9.0, 9.0, 9.0 + ) + + } +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/type/SystemFaction.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/type/SystemFaction.kt new file mode 100644 index 0000000..dfbb3ea --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/type/SystemFaction.kt @@ -0,0 +1,133 @@ +package cc.fyre.hcf.faction.type + +import cc.fyre.hcf.HCF +import cc.fyre.hcf.faction.Faction +import cc.fyre.hcf.faction.FactionMetadata +import cc.fyre.hcf.faction.FactionType +import cc.fyre.hcf.faction.command.admin.FactionEditorCommand +import cc.fyre.hcf.faction.type.defaults.WarZoneFaction + +import cc.fyre.hcf.faction.type.defaults.WildernessFaction +import cc.fyre.hcf.game.GameFaction +import cc.fyre.shard.menu.button.Button +import cc.fyre.shard.util.bukkit.ColorUtil +import com.squareup.moshi.Json +import com.squareup.moshi.JsonClass + +import mkremins.fanciful.FancyMessage +import org.apache.commons.lang.StringUtils +import org.bukkit.ChatColor +import org.bukkit.World +import org.bukkit.block.Block +import org.bukkit.command.CommandSender +import org.bukkit.entity.Player +import org.bukkit.event.block.Action +import org.bukkit.material.Lever +import org.bukkit.material.PressurePlate + +import java.util.* +import kotlin.collections.ArrayList + +/** + * @project hcf + * + * @date 04/04/2020 + * @author xanderume@gmail.com + */ +@JsonClass(generateAdapter = true) +// Never change "id" or "name" parameter, fucks with moshi kapt +open class SystemFaction(@Json(name = "_id") id: UUID,name: String,type: FactionType) : Faction(id,name,type) { + + constructor(uuid: UUID,name: String):this(uuid,name,FactionType.SYSTEM) + + var metadata = arrayListOf() + var displayName: String? = null + + override fun init() { + super.init() + + if (this.wayPoint == null || this.displayName == null || this.displayName!!.length < 2) { + return + } + + this.wayPoint = this.cloneWayPoint(ColorUtil.getDyeColor(ColorUtil.getChatColorByChar(this.displayName!![1])).color) + } + + fun isEvent():Boolean { + return this is GameFaction + } + + fun hasMetadata(metadata: FactionMetadata):Boolean { + return this.metadata.contains(metadata) + } + + open fun getEditorInfo():List { + return listOf() + } + + open fun getEditorButtons():Map { + return mapOf() + } + + open fun isBuildingAllowed(block: Block):Boolean { + return this is WildernessFaction + } + + open fun isBreakingAllowed(block: Block):Boolean { + return this is WildernessFaction + } + + open fun isAllowedToInteract(block: Block, player: Player, action: Action):Boolean { + + if (action == Action.PHYSICAL + && HCF.instance.isKitMap() + && (block.state.data is PressurePlate || block.state.data is org.bukkit.material.Button || block.state.data is Lever) + && (this is WarZoneFaction || this is GameFaction) + ) { + return true + } + + return this is WildernessFaction + } + + fun isEnderPearlAllowed():Boolean { + return !this.hasMetadata(FactionMetadata.SAFE_ZONE) && !this.hasMetadata(FactionMetadata.NO_ENDER_PEARL) + } + + override fun sendInfo(sender: CommandSender) { + sender.sendMessage("${ChatColor.GRAY}${ChatColor.STRIKETHROUGH}${StringUtils.repeat("-",53)}") + + val message = FancyMessage(this.getDisplayName(sender)).tooltip("${ChatColor.GREEN}Click to manage ${this.getDisplayName(sender)}${ChatColor.GREEN}!").command("/faction edit ${this.name}") + + if (sender.hasPermission(FactionEditorCommand.PERMISSION)) { + message.send(sender) + } else { + sender.sendMessage(message.toOldMessageFormat()) + } + + sender.sendMessage("${ChatColor.YELLOW}Location: ${ChatColor.WHITE}${if (this.getHQ() == null) "None" else "${this.getHQ()!!.blockX}, ${this.getHQ()!!.blockZ} ${if (this.getHQ()!!.world.environment != World.Environment.NORMAL) "(${StringUtils.capitalize(this.getHQ()!!.world.environment.name.lowercase().replace("the",""))})" else ""}"}") + sender.sendMessage("${ChatColor.GRAY}${ChatColor.STRIKETHROUGH}${StringUtils.repeat("-",53)}") + } + + override fun getDeathbanStatus(): DeathbanStatus { + + if (this.metadata.contains(FactionMetadata.SAFE_ZONE)) { + return DeathbanStatus.NON_DEATHBAN + } + + if (this is GameFaction && this.isActive()) { + return DeathbanStatus.NON_DEATHBAN + } + + return DeathbanStatus.DEATHBAN + } + + override fun getDisplayName(faction: Faction): String { + return ChatColor.translateAlternateColorCodes('&',this.displayName ?: "${ChatColor.WHITE}${this.name}") + } + + override fun getDisplayName(sender: CommandSender):String { + return ChatColor.translateAlternateColorCodes('&',this.displayName ?: "${ChatColor.WHITE}${this.name}") + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/type/defaults/TheEndFaction.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/type/defaults/TheEndFaction.kt new file mode 100644 index 0000000..f0d3d68 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/type/defaults/TheEndFaction.kt @@ -0,0 +1,19 @@ +package cc.fyre.hcf.faction.type.defaults + +import cc.fyre.hcf.faction.Faction +import cc.fyre.hcf.faction.type.SystemFaction +import org.bukkit.ChatColor +import org.bukkit.command.CommandSender +import java.util.* + +object TheEndFaction : SystemFaction(UUID.randomUUID(),"The End") { + + override fun getDisplayName(faction: Faction): String { + return this.displayName ?: "${ChatColor.DARK_PURPLE}The End" + } + + override fun getDisplayName(sender: CommandSender): String { + return this.displayName ?: "${ChatColor.DARK_PURPLE}The End" + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/type/defaults/TheNetherFaction.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/type/defaults/TheNetherFaction.kt new file mode 100644 index 0000000..9b23d07 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/type/defaults/TheNetherFaction.kt @@ -0,0 +1,19 @@ +package cc.fyre.hcf.faction.type.defaults + +import cc.fyre.hcf.faction.Faction +import cc.fyre.hcf.faction.type.SystemFaction +import org.bukkit.ChatColor +import org.bukkit.command.CommandSender +import java.util.* + +object TheNetherFaction : SystemFaction(UUID.randomUUID(),"The Nether") { + + override fun getDisplayName(faction: Faction): String { + return this.displayName ?: "${ChatColor.RED}Nether" + } + + override fun getDisplayName(sender: CommandSender): String { + return this.displayName ?: "${ChatColor.RED}Nether" + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/type/defaults/WarZoneFaction.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/type/defaults/WarZoneFaction.kt new file mode 100644 index 0000000..0c96c6f --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/type/defaults/WarZoneFaction.kt @@ -0,0 +1,51 @@ +package cc.fyre.hcf.faction.type.defaults + +import cc.fyre.hcf.faction.Faction +import cc.fyre.hcf.faction.claim.ClaimHandler +import cc.fyre.hcf.faction.type.SystemFaction +import org.bukkit.ChatColor +import org.bukkit.block.Block +import org.bukkit.command.CommandSender +import org.bukkit.entity.Player +import org.bukkit.event.block.Action +import java.util.* +import kotlin.math.abs + +/** + * @project hcf + * + * @date 03/06/2020 + * @author xanderume@gmail.com + */ +object WarZoneFaction : SystemFaction(UUID.randomUUID(),"WarZone") { + + override fun isConstant(): Boolean { + return true + } + + override fun getDisplayName(faction: Faction): String { + return this.displayName ?: "${ChatColor.DARK_RED}${this.name}" + } + + override fun getDisplayName(sender: CommandSender): String { + return this.displayName ?: "${ChatColor.DARK_RED}${this.name}" + } + + override fun isBreakingAllowed(block: Block): Boolean { + return super.isBreakingAllowed(block) + || abs(block.x) > ClaimHandler.WARZONE_RADIUS_BUILD + || abs(block.z) > ClaimHandler.WARZONE_RADIUS_BUILD + } + + override fun isBuildingAllowed(block: Block): Boolean { + return super.isBuildingAllowed(block) + || abs(block.x) > ClaimHandler.WARZONE_RADIUS_BUILD + || abs(block.z) > ClaimHandler.WARZONE_RADIUS_BUILD + } + + override fun isAllowedToInteract(block: Block, player: Player, action: Action): Boolean { + return super.isAllowedToInteract(block,player,action) + || abs(block.x) > ClaimHandler.WARZONE_RADIUS_BUILD + || abs(block.z) > ClaimHandler.WARZONE_RADIUS_BUILD + } +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/type/defaults/WildernessFaction.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/type/defaults/WildernessFaction.kt new file mode 100644 index 0000000..b9f7834 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/type/defaults/WildernessFaction.kt @@ -0,0 +1,29 @@ +package cc.fyre.hcf.faction.type.defaults + +import cc.fyre.hcf.faction.Faction +import cc.fyre.hcf.faction.type.SystemFaction +import org.bukkit.ChatColor +import org.bukkit.command.CommandSender +import java.util.* + +/** + * @project hcf + * + * @date 03/06/2020 + * @author xanderume@gmail.com + */ +object WildernessFaction : SystemFaction(UUID.randomUUID(),"Wilderness") { + + override fun isConstant(): Boolean { + return true + } + + override fun getDisplayName(faction: Faction): String { + return this.displayName ?: "${ChatColor.GRAY}The ${this.name}" + } + + override fun getDisplayName(sender: CommandSender): String { + return this.displayName ?: "${ChatColor.GRAY}The ${this.name}" + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/type/player/ChatMode.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/type/player/ChatMode.kt new file mode 100644 index 0000000..ca5f7c2 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/type/player/ChatMode.kt @@ -0,0 +1,96 @@ +package cc.fyre.hcf.faction.type.player + +import cc.fyre.core.profile.ProfileHandler +import cc.fyre.hcf.faction.Faction +import cc.fyre.hcf.faction.type.PlayerFaction +import org.apache.commons.lang.StringUtils +import org.bukkit.ChatColor +import org.bukkit.command.CommandSender +import org.bukkit.entity.Player +import java.util.* + +enum class ChatMode(val prefix: Char,val color: ChatColor,val arguments: ArrayList,private var displayName: String? = null) { + + GLOBAL('!',ChatColor.RED,arrayListOf("global","gc","g","public","pc","p")), + FACTION('@',ChatColor.DARK_GREEN,arrayListOf("faction","fac","fc","f","team","t")), + OFFICER('^',ChatColor.LIGHT_PURPLE,arrayListOf("officer","oc","o","captain","c")), + ALLY('#',Faction.ALLY_COLOR,arrayListOf("alliance","ally","allies","ac","a")); + + fun getDisplayName():String { + + if (this.displayName == null) { + this.displayName = StringUtils.capitalize(this.name.lowercase()) + } + + return this.displayName!! + } + + fun hasPermission(uuid: UUID, faction: PlayerFaction):Boolean { + + if (this == OFFICER) { + return faction.getRole(uuid).ordinal >= OFFICER.ordinal + } + + return true + } + + fun getNext(uuid: UUID,faction: PlayerFaction):ChatMode { + + val chatModes = values().filter{it.hasPermission(uuid,faction)} + + return if (this.ordinal >= chatModes.lastIndex) { + return chatModes[0] + } else { + chatModes[this.ordinal + 1] + } + } + + fun toChatFormat(player: Player, target: CommandSender, message: String, faction: PlayerFaction?):String? { + + if (this == GLOBAL) { + + val profile = ProfileHandler.getProfileById(player.uniqueId) ?: return "" + var toReturn = "" + + if (faction != null) { + toReturn += "${ChatColor.GOLD}[${faction.getDisplayName(target)}${ChatColor.GOLD}]" + } + + toReturn += profile.rank.prefix + toReturn += "${ChatColor.getByChar(profile.rank.prefix.last()) ?: ChatColor.getByChar(profile.rank.color[1]) ?: ChatColor.WHITE}" + toReturn += player.name + toReturn += "${ChatColor.WHITE}:" + + return "${ChatColor.translateAlternateColorCodes('&',toReturn)} $message" + } + + return "${this.color}(${this.getDisplayName()}) ${player.name}: ${ChatColor.YELLOW}${message}" + } + + companion object { + + private val values = values() + private val valuesByPrefix = this.values.associateBy{it.prefix} + private val valuesByArgument = mutableMapOf().also{ + + for (value in this.values) { + + for (argument in value.arguments) { + it[argument] = value + } + + } + + } + + fun getByPrefix(prefix: Char):ChatMode? { + return this.valuesByPrefix[prefix] + } + + fun getByArgument(argument: String):ChatMode? { + return this.valuesByArgument[argument.lowercase()] + } + + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/type/player/FactionRole.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/type/player/FactionRole.kt new file mode 100644 index 0000000..7fb60a1 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/type/player/FactionRole.kt @@ -0,0 +1,69 @@ +package cc.fyre.hcf.faction.type.player + +import java.util.Comparator + +enum class FactionRole( + val prefix: String, + val displayName: String +) : Comparator { + + // have to be in order + + MEMBER("","Member"), + OFFICER("*","Officer"), + CO_LEADER("**","Co-Leader"), + LEADER("***","Leader"); + + override fun compare(role: FactionRole, other: FactionRole): Int { + + if (role.ordinal >= other.ordinal) { + return 1 + } + + return 0 + } + + fun isAbleToInvite():Boolean { + return this >= OFFICER + } + + fun isAbleToClaimLand():Boolean { + return this >= OFFICER + } + + fun isAbleToRemoveLand():Boolean { + return this >= CO_LEADER + } + + fun isAbleToDemote():Boolean { + return this >= CO_LEADER + } + + fun isAbleToPromote():Boolean { + return this >= CO_LEADER + } + + fun isAbleToUpdateHQ():Boolean { + return this >= OFFICER + } + + fun isAbleToUpdateName():Boolean { + return this >= CO_LEADER + } + + fun isAbleToRemoveAlly():Boolean { + return this >= CO_LEADER + } + + fun isAbleToRequestAlly():Boolean { + return this >= OFFICER + } + + fun isAbleToUpdateAnnouncement():Boolean { + return this >= CO_LEADER + } + + fun isAbleToWithdrawBalance():Boolean { + return this >= CO_LEADER + } +} diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/type/player/RegenState.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/type/player/RegenState.kt new file mode 100644 index 0000000..949e92f --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/type/player/RegenState.kt @@ -0,0 +1,12 @@ +package cc.fyre.hcf.faction.type.player + +import org.bukkit.ChatColor + +enum class RegenState(val display: String) { + + FULL("${ChatColor.GREEN}◀"), + REGEN("${ChatColor.GREEN}▲"), + PAUSED("${ChatColor.RED}■"), + WAITING("${ChatColor.GRAY}◀") + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/type/subclaim/Subclaim.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/type/subclaim/Subclaim.kt new file mode 100644 index 0000000..076fdb5 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/faction/type/subclaim/Subclaim.kt @@ -0,0 +1,35 @@ +package cc.fyre.hcf.faction.type.subclaim + +import cc.fyre.hcf.faction.type.PlayerFaction +import cc.fyre.hcf.faction.type.player.FactionRole +import org.bukkit.Location +import java.util.* + +/** + * @project hcf + * + * @date 30/08/2020 + * @author xanderume@gmail.com + */ +class Subclaim(val owner: UUID,val location: Location) { + + private val members = ArrayList() + + fun addMember(uuid: UUID):Boolean { + return this.members.add(uuid) + } + + fun removeMember(uuid: UUID):Boolean { + return this.members.remove(uuid) + } + + fun isAllowed(uuid: UUID,faction: PlayerFaction):Boolean { + + if (faction.getRole(uuid) == FactionRole.LEADER) { + return true + } + + return this.members.contains(uuid) || faction.getRole(uuid) > faction.getRole(this.owner) + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/game/GameFaction.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/game/GameFaction.kt new file mode 100644 index 0000000..fa0dd8d --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/game/GameFaction.kt @@ -0,0 +1,141 @@ +package cc.fyre.hcf.game + +import cc.fyre.hcf.HCF +import cc.fyre.hcf.faction.Faction +import cc.fyre.hcf.faction.FactionType +import cc.fyre.hcf.faction.type.SystemFaction +import cc.fyre.hcf.game.event.GameActivateEvent +import cc.fyre.hcf.game.capture.type.CitadelFaction +import cc.fyre.hcf.game.capture.type.ConquestFaction +import cc.fyre.hcf.game.other.DTCFaction +import cc.fyre.hcf.game.capture.type.FuryFaction +import cc.fyre.hcf.game.capture.type.KOTHFaction +import cc.fyre.hcf.statistic.StatisticHandler +import cc.fyre.hcf.statistic.type.setting.EventMessageSetting +import com.squareup.moshi.JsonClass + +import org.bukkit.ChatColor +import org.bukkit.command.CommandSender +import org.bukkit.entity.Player +import java.util.* +import kotlin.collections.ArrayList +import kotlin.collections.HashMap + +/** + * @project hcf + * + * @date 29/08/2020 + * @author xanderume@gmail.com + */ +@JsonClass(generateAdapter = false) +abstract class GameFaction(name: String,val gameType: GameType) : SystemFaction(UUID.randomUUID(),name,FactionType.GAME) { + + var active = false + var started = 0L + + open fun onTick() {} + + abstract fun onActivate() + abstract fun onTerminate() + + abstract fun getRewardTier():Int + abstract fun getRewardAmount():Int + abstract fun getRewardPoints():Int + abstract fun getTabLayout(player: Player):List + abstract fun getScoreboardLines(scores: ArrayList):List + abstract fun getStructuredFormat():ArrayList + + abstract fun isAllowedToContest(player: Player):Boolean + + fun isActive():Boolean { + return this.active + } + + @JvmName("setActive1") + fun setActive(value: Boolean) { + + if (value) { + this.started = System.currentTimeMillis() + this.onActivate() + + HCF.instance.server.pluginManager.callEvent(GameActivateEvent(this)) + } else { + this.started = 0L + } + + this.flagForSave() + + this.active = value + } + + fun getUptime():Long { + return System.currentTimeMillis() - this.started + } + + fun isMajorEvent():Boolean { + return this is CitadelFaction || this is ConquestFaction || this is FuryFaction + } + + override fun getDisplayName(faction: Faction): String { + + if (this.displayName != null) { + return ChatColor.translateAlternateColorCodes('&',this.displayName) + } + + return when (this.gameType) { + GameType.DTC -> "${ChatColor.DARK_AQUA}${this.name}" + GameType.FURY -> "${ChatColor.AQUA}${this.name}" + GameType.KOTH -> "${ChatColor.AQUA}${this.name}${ChatColor.GOLD} KOTH" + GameType.CITADEL -> "${ChatColor.DARK_PURPLE}${this.name}" + GameType.CONQUEST -> "${ChatColor.GOLD}${this.name}" + } + + } + + override fun getDisplayName(sender: CommandSender): String { + + if (this.displayName != null) { + return ChatColor.translateAlternateColorCodes('&',this.displayName) + } + + return when (this.gameType) { + GameType.DTC -> "${ChatColor.DARK_AQUA}${this.name}" + GameType.FURY -> "${ChatColor.AQUA}${this.name}" + GameType.KOTH -> "${ChatColor.AQUA}${this.name}${ChatColor.GOLD} KOTH" + GameType.CITADEL -> "${ChatColor.DARK_PURPLE}${this.name}" + GameType.CONQUEST -> "${ChatColor.GOLD}${this.name}" + } + + } + + fun sendMessage(sender: CommandSender,message: String) { + sender.sendMessage(this.gameType.prefix + " " + message) + } + + fun sendMessage(players: Collection,message: String) { + players.filter{StatisticHandler.getStatistic(it.uniqueId,EventMessageSetting).getValue()}.forEach{it.sendMessage(this.gameType.prefix + " " + message)} + } + + fun sendMessage(players: Collection,messages: HashMap) { + players.filter{StatisticHandler.getStatistic(it.uniqueId,EventMessageSetting).getValue()}.forEach{messages.entries.forEach{entry -> it.sendMessage((if (entry.value) this.gameType.prefix else "") + " " + entry.key)}} + } + + fun sendStructuredMessage(players: Collection,messages: Array) { + + val format = this.getStructuredFormat() + + var i = 2 + + format[i++] += " ${this.gameType.prefix}" + + messages.forEach{format[i++] += " $it"} + + players.filter{StatisticHandler.getStatistic(it.uniqueId,EventMessageSetting).getValue()}.forEach{ + it.sendMessage(" ") + it.sendMessage(format.toTypedArray()) + it.sendMessage(" ") + } + + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/game/GameHandler.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/game/GameHandler.kt new file mode 100644 index 0000000..233f62b --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/game/GameHandler.kt @@ -0,0 +1,163 @@ +package cc.fyre.hcf.game + +import cc.fyre.hcf.HCF +import cc.fyre.shard.util.item.ItemBuilder +import cc.fyre.hcf.faction.FactionHandler +import cc.fyre.hcf.faction.type.PlayerFaction +import cc.fyre.hcf.game.schedule.GameSchedule +import cc.fyre.shard.moshi.MoshiUtil +import com.squareup.moshi.JsonReader +import okhttp3.internal.io.FileSystem +import okio.buffer +import org.bukkit.ChatColor +import org.bukkit.Material +import org.bukkit.inventory.ItemStack +import java.io.File +import java.io.FileWriter +import java.text.SimpleDateFormat +import java.util.* +import kotlin.collections.ArrayList + +/** + * @project hcf + * + * @date 29/08/2020 + * @author xanderume@gmail.com + */ +object GameHandler { + + private var next: GameFaction? = null + private var nextSchedule: GameSchedule? = null + + private val schedules = mutableListOf() + + private val file = File("${HCF.instance.dataFolder.path}/schedule.json") + + fun init() { + this.loadFile() + this.loadNextSchedule() + } + + fun loadNextSchedule() { + val now = Date(System.currentTimeMillis()) + + this.schedules.removeIf{it.toDate().before(now)} + this.schedules.minByOrNull{it.toDate()}.also{ + + if (it == null) { + return@also + } + + this.next = FactionHandler.getFactionById(it.faction) as? GameFaction + this.nextSchedule = it + } + } + + fun getNextGame():GameFaction? { + return this.next + } + + fun getNextGameSchedule():GameSchedule? { + return this.nextSchedule + } + + fun resetSchedule() { + this.schedules.clear() + } + + fun addSchedule(schedule: GameSchedule) { + this.schedules.add(schedule) + } + + fun getGameSchedule():List { + return this.schedules.toList() + } + + fun getTier(key: ItemStack):Int { + + if (!key.hasItemMeta() || !key.itemMeta.hasLore() || key.itemMeta.lore.isEmpty() || !key.itemMeta.lore[0].startsWith(KEY_TIER_PREFIX)) { + return 0 + } + + return ChatColor.stripColor(key.itemMeta.lore[0].replace(KEY_TIER_PREFIX,"").replace(" ","").replace("{","").replace("}","")).toIntOrNull() ?: 0 + } + + fun getTime(key: ItemStack):String? { + + if (!key.hasItemMeta() || !key.itemMeta.hasLore() || key.itemMeta.lore.isEmpty() || !key.itemMeta.lore[1].startsWith(KEY_TIME_PREFIX)) { + return null + } + + return ChatColor.stripColor(key.itemMeta.lore[1].replace(KEY_TIME_PREFIX,"").replace(" ","").replace("{","").replace("}","")).toString() + } + + fun getObtainedFrom(key: ItemStack): GameFaction? { + + if (!key.hasItemMeta() || !key.itemMeta.hasLore() || key.itemMeta.lore.lastIndex < 2 || !key.itemMeta.lore[2].startsWith(KEY_OBTAINED_FROM_PREFIX)) { + return null + } + + val faction = FactionHandler.getFactionByName(ChatColor.stripColor(key.itemMeta.lore[2].replace(KEY_OBTAINED_FROM_PREFIX,"").replace(" ","").replace("{","").replace("}","")).toString()) + + if (faction == null || faction !is GameFaction) { + return null + } + + return faction + } + + fun getGameKey(game: GameFaction, tier: Int, amount: Int):ItemStack { + + val lore = ArrayList() + + lore.add("$KEY_TIER_PREFIX ${ChatColor.YELLOW}{${ChatColor.BLUE}${tier}${ChatColor.YELLOW}}") + lore.add("$KEY_TIME_PREFIX ${ChatColor.YELLOW}{${ChatColor.BLUE}${DATE_FORMAT.format(Date()).replace(" AM","").replace(" PM","")}${ChatColor.YELLOW}}") + lore.add("$KEY_OBTAINED_FROM_PREFIX ${ChatColor.YELLOW}{${ChatColor.BLUE}${game.name}${ChatColor.YELLOW}}") + + return ItemBuilder.of(KEY_ITEM).name("${ChatColor.RED}${game.gameType.name} Reward Key").amount(amount).lore(lore).build() + } + + fun getGameSign(game: GameFaction, faction: PlayerFaction):ItemStack { + + val lore = ArrayList() + + lore.add("${ChatColor.BLUE}${game.name}") + lore.add("${ChatColor.YELLOW}Captured By:") + lore.add("${ChatColor.GREEN}${faction.name}") + + lore.add(DATE_FORMAT.format(Date())) + + return ItemBuilder.of(Material.SIGN).name("${ChatColor.LIGHT_PURPLE}${game.gameType.name} Capture Sign").lore(lore).build() + } + + fun loadFile() { + + if (this.file.exists()) { + this.schedules.addAll(MoshiUtil.instance.adapter>(GameSchedule.LIST_TYPE).fromJson(JsonReader.of(FileSystem.SYSTEM.source(this.file).buffer()))!!) + } else { + this.file.createNewFile() + } + + } + + fun saveFile() { + + val writer = FileWriter(this.file) + + if (!this.file.exists()) { + this.file.createNewFile() + } + + writer.write(MoshiUtil.instance.adapter>(GameSchedule.LIST_TYPE).toJson(this.schedules)) + writer.close() + } + + val DATE_FORMAT = SimpleDateFormat("M/d HH:mm:ss") + val SCHEDULE_FORMAT = SimpleDateFormat("EEE h:mm a") + + val KEY_ITEM = Material.GOLD_NUGGET + + private val KEY_TIER_PREFIX = "${ChatColor.WHITE}- ${ChatColor.AQUA}Tier:" + private val KEY_TIME_PREFIX = "${ChatColor.WHITE}- ${ChatColor.AQUA}Time:" + private val KEY_OBTAINED_FROM_PREFIX = "${ChatColor.WHITE}- ${ChatColor.AQUA}Obtained From:" +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/game/GameModule.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/game/GameModule.kt new file mode 100644 index 0000000..a09cbc8 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/game/GameModule.kt @@ -0,0 +1,59 @@ +package cc.fyre.hcf.game + +import cc.fyre.hcf.HCF +import cc.fyre.hcf.HCFModule +import cc.fyre.hcf.game.command.parameter.ConquestZoneTypeParameterProvider +import cc.fyre.hcf.game.command.parameter.FuryZoneTypeParameterProvider +import cc.fyre.hcf.game.command.parameter.GameTypeParameterProvider +import cc.fyre.hcf.game.listener.CitadelListener +import cc.fyre.hcf.game.capture.zone.ConquestCaptureZone +import cc.fyre.hcf.game.capture.zone.ConquestZoneType +import cc.fyre.hcf.game.listener.ConquestListener +import cc.fyre.hcf.game.listener.DTCListener +import cc.fyre.hcf.game.capture.zone.FuryCaptureZone +import cc.fyre.hcf.game.capture.zone.FuryZoneType +import cc.fyre.hcf.game.listener.FuryListener +import cc.fyre.hcf.game.listener.CaptureZoneListener +import cc.fyre.hcf.game.listener.GameListener +import cc.fyre.hcf.game.listener.GameRewardListener +import cc.fyre.hcf.game.scheduler.GameScheduler +import cc.fyre.shard.command.CommandHandler +import cc.fyre.shard.command.data.parameter.ParameterAdapter +import org.bukkit.event.Listener + +object GameModule : HCFModule { + + override fun init(core: HCF) { + GameHandler.init() + core.server.scheduler.runTaskTimer(core,GameScheduler,20L,20L) + } + + override fun shutdown(core: HCF) { + GameHandler.saveFile() + } + + override fun getCommands(): List> { + CommandHandler.registerAdapter(GameType::class.java, GameTypeParameterProvider) + CommandHandler.registerAdapter(FuryZoneType::class.java, FuryZoneTypeParameterProvider) + CommandHandler.registerAdapter(ConquestZoneType::class.java, ConquestZoneTypeParameterProvider) + return listOf() + } + + override fun getAdapters(): Map, ParameterAdapter<*>> { + return mapOf() + } + + override fun getListeners(): List { + return listOf( + DTCListener, + FuryListener, + CitadelListener, + ConquestListener, + + GameListener, + GameRewardListener, + CaptureZoneListener, + ) + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/game/GameType.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/game/GameType.kt new file mode 100644 index 0000000..9bdd213 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/game/GameType.kt @@ -0,0 +1,13 @@ +package cc.fyre.hcf.game + +import org.bukkit.ChatColor + +enum class GameType(val prefix: String,val dominant: ChatColor) { + + DTC("${ChatColor.BLUE}[DTC]",ChatColor.DARK_AQUA), + FURY("${ChatColor.GOLD}[Fury]",ChatColor.YELLOW), + KOTH("${ChatColor.GOLD}[KingOfTheHill]",ChatColor.YELLOW), + CITADEL("${ChatColor.DARK_PURPLE}[Citadel]",ChatColor.YELLOW), + CONQUEST("${ChatColor.YELLOW}[Conquest]",ChatColor.GOLD); + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/game/capture/CaptureZone.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/game/capture/CaptureZone.kt new file mode 100644 index 0000000..444294a --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/game/capture/CaptureZone.kt @@ -0,0 +1,134 @@ +package cc.fyre.hcf.game.capture + +import cc.fyre.hcf.HCF +import cc.fyre.hcf.game.capture.zone.ConquestCaptureZone +import cc.fyre.hcf.game.capture.zone.FuryCaptureZone +import com.squareup.moshi.JsonClass +import org.bukkit.Location +import org.bukkit.entity.Player +import java.util.* +import java.util.concurrent.TimeUnit +import java.util.concurrent.atomic.AtomicInteger +import kotlin.collections.ArrayList +import kotlin.math.abs + +/** + * @project hcf + * + * @date 31/08/2020 + * @author xanderume@gmail.com + */ +@JsonClass(generateAdapter = true) +open class CaptureZone(var location: Location?,var time: Int) { + + constructor(location: Location?,time: Long):this(location,TimeUnit.MILLISECONDS.toSeconds(time).toInt()) + + var radius = 3 + var remaining = AtomicInteger(this.time) + + // We have to make these variables null since json is retarded and doesn't initialize "Transient" variables and causes them to be null (KotlinNullPointerException) + var contester: UUID? = null + var contesters: ArrayList? = ArrayList() + + fun getContester():Player? { + + if (this.contester == null) { + return null + } + + return HCF.instance.server.getPlayer(this.contester) + } + + fun getContesters():MutableList { + return (this.contesters ?: ArrayList()).mapNotNull{HCF.instance.server.getPlayer(it)}.filter{it.isOnline}.toMutableList() + } + + fun onTick(faction: CaptureZoneFaction) { + + if (this.contester == null) { + return + } + + val contester = this.getContester() + + if (contester == null || !this.isInsideCaptureZone(contester.location)) { + + val seconds = this.remaining.get() + + if (this.remaining.get() != this.time) { + this.remaining.set(this.time) + } + + faction.onZoneLoss(this,null,seconds) + return + } + + if (this.remaining.decrementAndGet() <= 0) { + this.remaining.set(this.time) + + if (!(this is ConquestCaptureZone || this is FuryCaptureZone)) { + this.contester = null + this.contesters?.clear() + } + + faction.onZoneCapture(this,contester) + return + } + + if (this.remaining.get() == this.time || this.remaining.get() % 30 != 0) { + return + } + + faction.onZoneTick(this,contester) + } + + fun addContester(player: Player) { + + if (this.contesters == null) { + this.contesters = ArrayList() + } + + this.contesters!!.add(player.uniqueId) + } + + fun removeContester(player: Player) { + + if (this.contesters == null) { + this.contesters = ArrayList() + } + + this.contesters!!.remove(player.uniqueId) + } + + fun setContester(player: Player?,faction: CaptureZoneFaction) { + + val contester = this.getContester() + + if (contester != null) { + faction.onZoneLoss(this,contester,this.remaining.get()) + } + + if (player != null) { + faction.onZoneControl(this,player) + } + + this.remaining.set(this.time) + this.contester = player?.uniqueId + } + + fun findNextContester(faction: CaptureZoneFaction):Player? { + return (this.contesters ?: ArrayList()).mapNotNull{HCF.instance.server.getPlayer(it)}.firstOrNull{it.uniqueId != this.contester && faction.isAllowedToContest(it)} + } + + fun isInsideCaptureZone(location: Location):Boolean { + + val zone = this.location ?: return false + + if (location.world != zone.world) { + return false + } + + return abs(location.blockX - zone.blockX) <= this.radius && abs(location.blockY - zone.blockY) <= 5 && abs(location.blockZ - zone.blockZ) <= this.radius + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/game/capture/CaptureZoneFaction.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/game/capture/CaptureZoneFaction.kt new file mode 100644 index 0000000..6c17eb0 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/game/capture/CaptureZoneFaction.kt @@ -0,0 +1,24 @@ +package cc.fyre.hcf.game.capture + +import cc.fyre.hcf.game.GameFaction +import cc.fyre.hcf.game.GameType +import com.squareup.moshi.JsonClass +import org.bukkit.entity.Player + +/** + * @project hcf + * + * @date 31/08/2020 + * @author xanderume@gmail.com + */ +@JsonClass(generateAdapter = false) +abstract class CaptureZoneFaction(name: String,gameType: GameType): GameFaction(name,gameType) { + + abstract fun getZones():ArrayList + + abstract fun onZoneLoss(zone: CaptureZone, player: Player?, seconds: Int) + abstract fun onZoneTick(zone: CaptureZone, contester: Player) + abstract fun onZoneControl(zone: CaptureZone, contester: Player) + abstract fun onZoneCapture(zone: CaptureZone, contester: Player) + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/game/capture/type/CitadelFaction.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/game/capture/type/CitadelFaction.kt new file mode 100644 index 0000000..098a018 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/game/capture/type/CitadelFaction.kt @@ -0,0 +1,165 @@ +package cc.fyre.hcf.game.capture.type + +import cc.fyre.shard.util.ChanceUtil +import cc.fyre.hcf.HCF +import cc.fyre.hcf.faction.FactionHandler +import cc.fyre.hcf.faction.type.PlayerFaction +import cc.fyre.hcf.faction.listener.FactionProtectionListener +import cc.fyre.hcf.game.GameType +import cc.fyre.hcf.game.capture.CaptureZone +import com.squareup.moshi.JsonClass +import org.bukkit.ChatColor +import org.bukkit.Location +import org.bukkit.Material +import org.bukkit.block.Block +import org.bukkit.block.Chest +import org.bukkit.entity.Player +import org.bukkit.event.block.Action +import org.bukkit.inventory.ItemStack +import java.util.* +import kotlin.collections.ArrayList +import kotlin.collections.HashMap +import kotlin.collections.HashSet + +/** + * @project hcf + * + * @date 01/09/2020 + * @author xanderume@gmail.com + */ +@JsonClass(generateAdapter = true) +class CitadelFaction(name: String) : KOTHFaction(name,GameType.CITADEL) { + + var faction: UUID? = null + var captured: Long = 0L + + val chests = HashSet() + + fun scan() { + this.chests.clear() + + this.claims.forEach{claim -> + + val iterator = claim.blockIterator() + + while (iterator.hasNext()) { + + val block = iterator.next() + + if (block.type != Material.CHEST) { + continue + } + + this.chests.add(block.location) + } + + } + + } + + fun fill() { + + this.chests.map{it.block.state}.filterIsInstance().forEach{ + + HCF.instance.server.scheduler.runTaskAsynchronously(HCF.instance) { + + var loot: ItemStack? = null + + while (loot == null) { + loot = LOOT.filterValues{ value -> ChanceUtil.percent(value)}.keys.firstOrNull() + } + + // go back on main thread + HCF.instance.server.scheduler.runTask(HCF.instance) { + it.inventory.setItem(it.inventory.size / 2,loot) + } + + } + + } + + if (this.isActive() || this.faction == null) { + return + } + + this.sendMessage(HCF.instance.server.onlinePlayers,"${ChatColor.YELLOW}Chests have been refilled!") + } + + fun isAbleToLoot(player: Player):Boolean { + + if (this.faction == null) { + return false + } + + val faction = FactionHandler.getFactionById(this.faction!!) + + if (faction == null || faction !is PlayerFaction) { + return false + } + + return faction.isMember(player) || faction.isAllied(player) + } + + override fun isAllowedToInteract(block: Block, player: Player, action: Action): Boolean { + return this.isAbleToLoot(player) && FactionProtectionListener.DISALLOW_INTERACT.contains(block.type) + } + + override fun onZoneCapture(zone: CaptureZone, contester: Player) { + super.onZoneCapture(zone,contester) + + val faction = FactionHandler.getFactionByPlayer(contester.uniqueId) ?: return + + this.faction = faction.id + this.captured = System.currentTimeMillis() + + val message = HashMap() + + message["${this.getDisplayName(contester)} ${ChatColor.YELLOW}is now ${ChatColor.DARK_RED}closed${ChatColor.YELLOW} and controlled by ${ChatColor.RED}${faction.name}${ChatColor.YELLOW}."] = true + + this.sendMessage(HCF.instance.server.onlinePlayers,message) + } + + fun findFaction():PlayerFaction? { + + if (this.faction == null) { + return null + } + + return (FactionHandler.getFactionById(this.faction!!)) as PlayerFaction + } + + override fun getStructuredFormat(): ArrayList { + + val toReturn = ArrayList() + + toReturn.add("${ChatColor.GRAY}███████") + toReturn.add("${ChatColor.GRAY}██${ChatColor.DARK_PURPLE}████${ChatColor.GRAY}█") + toReturn.add("${ChatColor.GRAY}█${ChatColor.DARK_PURPLE}█${ChatColor.GRAY}█████") + toReturn.add("${ChatColor.GRAY}█${ChatColor.DARK_PURPLE}█${ChatColor.GRAY}█████") + toReturn.add("${ChatColor.GRAY}█${ChatColor.DARK_PURPLE}█${ChatColor.GRAY}█████") + toReturn.add("${ChatColor.GRAY}█${ChatColor.DARK_PURPLE}█${ChatColor.GRAY}█████") + toReturn.add("${ChatColor.GRAY}██${ChatColor.DARK_PURPLE}████${ChatColor.GRAY}█") + toReturn.add("${ChatColor.GRAY}███████") + + return toReturn + } + + override fun getRewardTier(): Int { + return 3 + } + + override fun getRewardAmount(): Int { + return 2 + } + + override fun getRewardPoints(): Int { + return 100 + } + + companion object { + + val LOOT = mutableMapOf(ItemStack(Material.ENDER_PEARL,16) to 1.0) + + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/game/capture/type/ConquestFaction.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/game/capture/type/ConquestFaction.kt new file mode 100644 index 0000000..ee29ea4 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/game/capture/type/ConquestFaction.kt @@ -0,0 +1,227 @@ +package cc.fyre.hcf.game.capture.type + +import cc.fyre.shard.util.TimeUtil + +import cc.fyre.hcf.HCF +import cc.fyre.hcf.map.engine.HCFScoreboardAdapter +import cc.fyre.hcf.faction.FactionHandler +import cc.fyre.hcf.game.GameType +import cc.fyre.hcf.game.event.GameCaptureEvent +import cc.fyre.hcf.game.capture.zone.ConquestCaptureZone + +import cc.fyre.hcf.game.capture.CaptureZoneFaction +import cc.fyre.hcf.game.capture.CaptureZone +import cc.fyre.hcf.game.capture.zone.ConquestZoneType +import com.squareup.moshi.JsonClass +import org.bukkit.ChatColor +import org.bukkit.GameMode +import org.bukkit.entity.Player +import java.util.* +import java.util.concurrent.atomic.AtomicInteger +import kotlin.collections.ArrayList +import kotlin.collections.HashSet + +/** + * @project hcf + * + * @date 01/09/2020 + * @author xanderume@gmail.com + */ +@JsonClass(generateAdapter = true) +class ConquestFaction(name: String) : CaptureZoneFaction(name,GameType.CONQUEST) { + + var deathPenalty = 20 + var requiredPoints = 250 + + val points = mutableMapOf() + + val zones = HashSet() + + init { + ConquestZoneType.values().forEach{this.zones.add(ConquestCaptureZone(it,null, ZONE_CONTROL_TIME))} + } + + override fun onActivate() {} + + override fun onTerminate() { + this.points.clear() + this.zones.forEach{it.remaining.set(ZONE_CONTROL_TIME)} + this.flagForSave() + } + + override fun getRewardTier(): Int { + return 3 + } + + override fun getRewardAmount(): Int { + return 5 + } + + override fun getRewardPoints(): Int { + return 125 + } + + override fun getTabLayout(player: Player): List { + + val toReturn = ArrayList() + + toReturn.add(this.getDisplayName(player)) + + if (this.getHQ() != null) { + toReturn.add("${ChatColor.GRAY}${this.getHQ()!!.blockX}, ${this.getHQ()!!.blockZ}") + } + + if (this.points.isNotEmpty()) { + this.points.entries.associate{ FactionHandler.getFactionById(it.key) to it.value}.filter{it.key != null}.entries.sortedByDescending{it.value.get()}.take(3).forEach{toReturn.add("${ChatColor.YELLOW}${it.key!!.name}${ChatColor.GRAY}: ${ChatColor.RED}${it.value.get()}")} + } + + return toReturn + } + + override fun getScoreboardLines(scores: ArrayList): List { + + val toReturn = ArrayList() + + if (scores.isNotEmpty()) { + scores.add(HCFScoreboardAdapter.LINE) + } + + if (this.points.isNotEmpty()) { + this.points.entries.associate{FactionHandler.getFactionById(it.key) to it.value}.filter{it.key != null}.entries.sortedByDescending{it.value.get()}.take(3).forEach{toReturn.add("${ChatColor.YELLOW}${it.key!!.name}${ChatColor.GRAY}: ${ChatColor.RED}${it.value.get()}")} + toReturn.add("") + } + + var next = true + + this.zones.sortedBy{it.type.points}.forEach{ + + if (next) { + toReturn.add("${it.type.color}⬛${ChatColor.RED} ${TimeUtil.formatIntoHHMMSS(it.remaining.get() * 1000L)}") + } else { + toReturn[toReturn.lastIndex] = "${toReturn[toReturn.lastIndex]} ${it.type.color}⬛ ${ChatColor.RED}${TimeUtil.formatIntoHHMMSS(it.remaining.get() * 1000L)}" + } + + next = !next + } + + return toReturn.reversed() + } + + override fun getStructuredFormat(): ArrayList { + + val toReturn = ArrayList() + + toReturn.add("${ChatColor.GRAY}███████") + toReturn.add("${ChatColor.GRAY}██${ChatColor.GOLD}████${ChatColor.GRAY}█") + toReturn.add("${ChatColor.GRAY}█${ChatColor.GOLD}█${ChatColor.GRAY}█████") + toReturn.add("${ChatColor.GRAY}█${ChatColor.GOLD}█${ChatColor.GRAY}█████") + toReturn.add("${ChatColor.GRAY}█${ChatColor.GOLD}█${ChatColor.GRAY}█████") + toReturn.add("${ChatColor.GRAY}█${ChatColor.GOLD}█${ChatColor.GRAY}█████") + toReturn.add("${ChatColor.GRAY}██${ChatColor.GOLD}████${ChatColor.GRAY}█") + toReturn.add("${ChatColor.GRAY}███████") + + return toReturn + } + + override fun isAllowedToContest(player: Player): Boolean { + return player.gameMode != GameMode.CREATIVE && FactionHandler.getFactionByPlayer(player.uniqueId) != null + } + + override fun getZones(): ArrayList { + + val toReturn = ArrayList(this.zones) + + ConquestZoneType.values().filter{this.zones.none{ zone -> zone.type == it}}.forEach{this.zones.add( + ConquestCaptureZone(it,null, + ZONE_CONTROL_TIME + ) + )} + + return toReturn + } + + override fun onZoneLoss(zone: CaptureZone, player: Player?, seconds: Int) { + + if (zone !is ConquestCaptureZone) { + return + } + + + if ((zone.time - seconds) < (ZONE_CONTROL_TIME / 2)) { + return + } + + if (player == null) { + return + } + + this.sendMessage(player,"${ChatColor.GOLD}You have lost control of ${zone.type.getDisplayName()}${ChatColor.GOLD}.") + } + + override fun onZoneTick(zone: CaptureZone, contester: Player) { + + if (zone !is ConquestCaptureZone) { + return + } + + this.sendMessage(contester,"${ChatColor.GOLD}Attempting to control ${zone.type.getDisplayName()}${ChatColor.GOLD}.") + } + + override fun onZoneControl(zone: CaptureZone, contester: Player) { + + if (zone !is ConquestCaptureZone) { + return + } + + this.sendMessage(contester,"${ChatColor.GOLD}Attempting to control ${zone.type.getDisplayName()}${ChatColor.GOLD}.") + } + + override fun onZoneCapture(zone: CaptureZone, contester: Player) { + + if (zone !is ConquestCaptureZone) { + return + } + + val faction = FactionHandler.getFactionByPlayer(contester.uniqueId) + + if (faction == null) { + contester.sendMessage("${ChatColor.RED}Unable to add points since you are not in a faction!") + return + } + + this.points.putIfAbsent(faction.id,AtomicInteger()) + + if (this.points[faction.id]!!.addAndGet(zone.type.points) < this.requiredPoints) { + this.sendMessage(HCF.instance.server.onlinePlayers,"${ChatColor.YELLOW}${faction.name}${ChatColor.GOLD} captured ${zone.type.getDisplayName()}${ChatColor.GOLD} and has earned ${ChatColor.WHITE}${zone.type.points} point${if (zone.type.points == 1) "" else "s"}${ChatColor.GOLD}! ${ChatColor.RED}(${this.points[faction.id]!!.get()}/${this.requiredPoints})") + return + } + + this.points.clear() + + this.setActive(false) + + this.zones.forEach{it.remaining.set(ZONE_CONTROL_TIME)} + + HCF.instance.server.pluginManager.callEvent(GameCaptureEvent(this,contester,faction)) + } + + fun findZoneByType(type: ConquestZoneType): ConquestCaptureZone { + + var toReturn = this.zones.firstOrNull{it.type == type} + + if (toReturn == null) { + toReturn = ConquestCaptureZone(type,null, ZONE_CONTROL_TIME) + + this.zones.add(toReturn) + } + + return toReturn + } + + companion object { + + const val ZONE_CONTROL_TIME = 30 + + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/game/capture/type/FuryFaction.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/game/capture/type/FuryFaction.kt new file mode 100644 index 0000000..39037d1 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/game/capture/type/FuryFaction.kt @@ -0,0 +1,256 @@ +package cc.fyre.hcf.game.capture.type + +import cc.fyre.shard.util.TimeUtil +import cc.fyre.hcf.HCF +import cc.fyre.hcf.map.engine.HCFScoreboardAdapter +import cc.fyre.hcf.faction.FactionHandler +import cc.fyre.hcf.game.GameType +import cc.fyre.hcf.game.event.GameCaptureEvent + +import cc.fyre.hcf.game.capture.zone.FuryCaptureZone +import cc.fyre.hcf.game.capture.CaptureZoneFaction +import cc.fyre.hcf.game.capture.CaptureZone +import cc.fyre.hcf.game.capture.zone.FuryZoneType +import com.squareup.moshi.JsonClass +import org.bukkit.ChatColor +import org.bukkit.GameMode +import org.bukkit.entity.Player +import java.util.* +import java.util.concurrent.atomic.AtomicInteger +import kotlin.collections.ArrayList +import kotlin.collections.HashSet + +/** + * @project hcf + * + * @date 05/09/2020 + * @author xanderume@gmail.com + */ +@JsonClass(generateAdapter = true) +class FuryFaction(name: String) : CaptureZoneFaction(name,GameType.FURY) { + + var switch = ZONE_SWITCH_TIME + + var deathPenalty = 20 + var requiredPoints = 250 + + val points = mutableMapOf() + val zones = HashSet() + + init { + FuryZoneType.values().forEach{this.zones.add(FuryCaptureZone(it,null, ZONE_CONTROL_TIME))} + } + + override fun onTick() { + + if (this.switch-- > 0) { + return + } + + val zone = this.zones.firstOrNull{it.active} ?: this.findZoneByType(FuryZoneType.OVERWORLD) + val next = this.findZoneByType(if (zone.type.ordinal == FuryZoneType.values().lastIndex) FuryZoneType.values().first() else FuryZoneType.values()[zone.type.ordinal + 1]) + + zone.active = false + zone.remaining.set(ZONE_CONTROL_TIME) + + next.active = true + next.remaining.set(ZONE_CONTROL_TIME) + + this.switch = ZONE_SWITCH_TIME + + this.flagForSave() + + this.sendMessage(HCF.instance.server.onlinePlayers,"${ChatColor.YELLOW}The capture zone has switched to ${next.type.getDisplayName()}${ChatColor.YELLOW}.") + } + + override fun onActivate() { + this.switch = ZONE_SWITCH_TIME + this.findZoneByType(FuryZoneType.OVERWORLD).active = true + this.flagForSave() + } + + override fun onTerminate() { + this.switch = ZONE_SWITCH_TIME + + this.points.clear() + + this.zones.forEach{ + it.active = false + it.remaining.set(ZONE_CONTROL_TIME) + } + + this.flagForSave() + } + + override fun getRewardTier(): Int { + return 3 + } + + override fun getRewardAmount(): Int { + return 5 + } + + override fun getRewardPoints(): Int { + return 100 + } + + override fun getTabLayout(player: Player): List { + + val toReturn = ArrayList() + + toReturn.add(this.getDisplayName(player)) + + if (this.getHQ() != null) { + toReturn.add("${ChatColor.GRAY}${this.getHQ()!!.blockX}, ${this.getHQ()!!.blockZ}") + } + + if (this.points.isNotEmpty()) { + this.points.entries.associate{FactionHandler.getFactionById(it.key) to it.value}.filter{it.key != null}.entries.sortedByDescending{it.value.get()}.take(3).forEach{toReturn.add("${ChatColor.YELLOW}${it.key!!.name}${ChatColor.GRAY}: ${ChatColor.RED}${it.value.get()}")} + } + + return toReturn + } + + override fun getScoreboardLines(scores: ArrayList): List { + + val toReturn = ArrayList() + + if (scores.isNotEmpty()) { + scores.add(HCFScoreboardAdapter.LINE) + } + + val zone = this.zones.first{it.active} + + toReturn.add("${zone.type.color}█${ChatColor.GRAY} ${ChatColor.RED}${TimeUtil.formatIntoHHMMSS(zone.remaining.get() * 1000L)} ${ChatColor.GRAY}[${TimeUtil.formatIntoHHMMSS(this.switch * 1000L)}]") +/* toReturn.add("${ChatColor.AQUA}${ChatColor.BOLD}Fury${ChatColor.GRAY}: ${zone.type.getDisplayName()}") + toReturn.add("${ChatColor.BLUE}${ChatColor.BOLD}Time${ChatColor.GRAY}: ${ChatColor.RED}${TimeUtil.formatIntoHHMMSS(zone.remaining.get() * 1000L)}") + toReturn.add("${ChatColor.YELLOW}${ChatColor.BOLD}Switch${ChatColor.GRAY}: ${ChatColor.RED}${TimeUtil.formatIntoHHMMSS(this.switch * 1000L)}") +*/ + if (this.points.isNotEmpty()) { + toReturn.add("") + this.points.entries.associate{FactionHandler.getFactionById(it.key) to it.value}.filter{it.key != null}.entries.sortedByDescending{it.value.get()}.take(3).forEach{toReturn.add("${ChatColor.YELLOW}${it.key!!.name}${ChatColor.GRAY}: ${ChatColor.RED}${it.value.get()}")} + } + + return toReturn + } + + override fun getStructuredFormat(): ArrayList { + + val toReturn = ArrayList() + + toReturn.add("${ChatColor.GRAY}██████") + toReturn.add("${ChatColor.GRAY}█${ChatColor.GOLD}████${ChatColor.GRAY}█") + toReturn.add("${ChatColor.GRAY}█${ChatColor.GOLD}█${ChatColor.GRAY}████") + toReturn.add("${ChatColor.GRAY}█${ChatColor.GOLD}███${ChatColor.GRAY}██") + toReturn.add("${ChatColor.GRAY}█${ChatColor.GOLD}█${ChatColor.GRAY}████") + toReturn.add("${ChatColor.GRAY}█${ChatColor.GOLD}█${ChatColor.GRAY}████") + toReturn.add("${ChatColor.GRAY}█${ChatColor.GOLD}█${ChatColor.GRAY}████") + toReturn.add("${ChatColor.GRAY}██████") + + return toReturn + } + + override fun isAllowedToContest(player: Player): Boolean { + return player.gameMode != GameMode.CREATIVE && FactionHandler.getFactionByPlayer(player.uniqueId) != null + } + + override fun getZones(): ArrayList { + + val toReturn = ArrayList(this.zones) + + FuryZoneType.values().filter{this.zones.none{ zone -> zone.type == it}}.forEach{this.zones.add( + FuryCaptureZone(it,null, + ZONE_CONTROL_TIME + ) + )} + + return toReturn + } + + override fun onZoneLoss(zone: CaptureZone, player: Player?, seconds: Int) { + + if (zone !is FuryCaptureZone) { + return + } + + if ((zone.time - seconds) < (ZONE_CONTROL_TIME / 2)) { + return + } + + if (player == null) { + return + } + + this.sendMessage(player,"${ChatColor.YELLOW}You have lost control of ${zone.type.getDisplayName()}${ChatColor.YELLOW}.") + } + + override fun onZoneTick(zone: CaptureZone, contester: Player) { + + if (zone !is FuryCaptureZone) { + return + } + + this.sendMessage(contester,"${ChatColor.YELLOW}Attempting to control ${zone.type.getDisplayName()}${ChatColor.YELLOW}.") + } + + override fun onZoneControl(zone: CaptureZone, contester: Player) { + + if (zone !is FuryCaptureZone) { + return + } + + this.sendMessage(contester,"${ChatColor.YELLOW}Attempting to control ${zone.type.getDisplayName()}${ChatColor.YELLOW}.") + } + + override fun onZoneCapture(zone: CaptureZone, contester: Player) { + + if (zone !is FuryCaptureZone) { + return + } + + val faction = FactionHandler.getFactionByPlayer(contester.uniqueId) + + if (faction == null) { + contester.sendMessage("${ChatColor.RED}Unable to add points since you are not in a faction!") + return + } + + this.points.putIfAbsent(faction.id, AtomicInteger()) + + if (this.points[faction.id]!!.addAndGet(zone.type.points) < this.requiredPoints) { + this.sendMessage(HCF.instance.server.onlinePlayers,"${ChatColor.YELLOW}${faction.name}${ChatColor.YELLOW} captured ${zone.type.getDisplayName()}${ChatColor.YELLOW} and has earned ${ChatColor.BLUE}${zone.type.points} point${if (zone.type.points == 1) "" else "s"}${ChatColor.YELLOW}! ${ChatColor.RED}(${this.points[faction.id]!!.get()}/${this.requiredPoints})") + return + } + + this.points.clear() + + this.setActive(false) + + this.zones.forEach{ + it.active = false + it.remaining.set(ZONE_CONTROL_TIME) + } + + HCF.instance.server.pluginManager.callEvent(GameCaptureEvent(this,contester,faction)) + } + + fun findZoneByType(type: FuryZoneType): FuryCaptureZone { + + var toReturn = this.zones.firstOrNull{it.type == type} + + if (toReturn == null) { + toReturn = FuryCaptureZone(type,null, ZONE_CONTROL_TIME) + this.zones.add(toReturn) + } + + return toReturn + } + + companion object { + + const val ZONE_SWITCH_TIME = 15 * 60 + const val ZONE_CONTROL_TIME = 30 + + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/game/capture/type/KOTHFaction.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/game/capture/type/KOTHFaction.kt new file mode 100644 index 0000000..05e9430 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/game/capture/type/KOTHFaction.kt @@ -0,0 +1,166 @@ +package cc.fyre.hcf.game.capture.type + +import cc.fyre.shard.util.TimeUtil +import cc.fyre.hcf.HCF +import cc.fyre.hcf.faction.FactionHandler +import cc.fyre.hcf.game.GameType +import cc.fyre.hcf.game.event.GameCaptureEvent +import cc.fyre.hcf.game.capture.CaptureZone +import cc.fyre.hcf.game.capture.CaptureZoneFaction +import com.squareup.moshi.JsonClass +import org.bukkit.* +import org.bukkit.entity.Player +import java.util.concurrent.TimeUnit +import kotlin.collections.ArrayList +import kotlin.collections.HashMap + +/** + * @project hcf + * + * @date 29/08/2020 + * @author xanderume@gmail.com + */ +@JsonClass(generateAdapter = true) +open class KOTHFaction(name: String,gameType: GameType) : CaptureZoneFaction(name,gameType) { + + constructor(name: String):this(name,GameType.KOTH) + + var zone = CaptureZone(this.getHQ(),TimeUnit.MINUTES.toMillis(7L)) + + override fun setHQ(location: Location?) { + this.zone.location = location + super.setHQ(location) + } + + override fun getRewardTier(): Int { + return 1 + } + + override fun getRewardAmount(): Int { + return 1 + } + + override fun getRewardPoints(): Int { + return 15 + } + + override fun onActivate() {} + + override fun onTerminate() {} + + override fun getScoreboardLines(scores: ArrayList): List { + + val toReturn = ArrayList() + + toReturn.add("${this.displayName ?: "${if (this is CitadelFaction) ChatColor.DARK_PURPLE else ChatColor.BLUE}${ChatColor.BOLD}${this.name}"}${ChatColor.GRAY}: ${ChatColor.RED}${TimeUtil.formatIntoHHMMSS(this.zone.remaining.get() * 1000L)}") + + return toReturn + } + + override fun isAllowedToContest(player: Player): Boolean { + return player.gameMode != GameMode.CREATIVE + } + + override fun getTabLayout(player: Player): List { + + val toReturn = ArrayList() + + toReturn.add(this.getDisplayName(player)) + toReturn.add("${ChatColor.RED}${TimeUtil.formatIntoHHMMSS(zone.remaining.get() * 1000L)}") + + if (this.getHQ() != null) { + toReturn.add("${ChatColor.GRAY}${this.getHQ()!!.blockX}, ${this.getHQ()!!.blockZ}") + } + + return toReturn + } + + override fun getStructuredFormat(): ArrayList { + + val toReturn = ArrayList() + + toReturn.add("${ChatColor.GRAY}███████") + toReturn.add("${ChatColor.GRAY}█${ChatColor.GOLD}█${ChatColor.GRAY}███${ChatColor.GOLD}█${ChatColor.GRAY}█") + toReturn.add("${ChatColor.GRAY}█${ChatColor.GOLD}█${ChatColor.GRAY}██${ChatColor.GOLD}█${ChatColor.GRAY}██") + toReturn.add("${ChatColor.GRAY}█${ChatColor.GOLD}███${ChatColor.GRAY}███") + toReturn.add("${ChatColor.GRAY}█${ChatColor.GOLD}█${ChatColor.GRAY}██${ChatColor.GOLD}█${ChatColor.GRAY}██") + toReturn.add("${ChatColor.GRAY}█${ChatColor.GOLD}█${ChatColor.GRAY}███${ChatColor.GOLD}█${ChatColor.GRAY}█") + toReturn.add("${ChatColor.GRAY}█${ChatColor.GOLD}█${ChatColor.GRAY}███${ChatColor.GOLD}█${ChatColor.GRAY}█") + toReturn.add("${ChatColor.GRAY}███████") + + return toReturn + } + + override fun getZones(): ArrayList { + return arrayListOf(this.zone) + } + + fun getCaptureRadius():Int { + return this.zone.radius + } + + fun setCaptureRadius(radius: Int) { + this.zone.radius = radius + } + + fun getCaptureTime():Long { + return this.zone.time * 1000L + } + + fun setCaptureTime(time: Long) { + + if (this.isActive()) { + + if ((this.zone.remaining.get() * 1000L) > time) { + this.zone.remaining.set((time / 1000L).toInt()) + } + + this.sendMessage(HCF.instance.server.onlinePlayers,"${ChatColor.BLUE}${this.name} ${ChatColor.YELLOW}has been decreased to ${ChatColor.RED}${TimeUtil.formatIntoDetailedString(time)}${ChatColor.YELLOW}.") + } + + this.zone.time = TimeUnit.MILLISECONDS.toSeconds(time).toInt() + } + + override fun onZoneLoss(zone: CaptureZone, player: Player?, seconds: Int) { + + if ((zone.time - seconds) < 30) { + return + } + + this.sendMessage(HCF.instance.server.onlinePlayers,"${ChatColor.YELLOW}Control of ${ChatColor.BLUE}${this.name}${ChatColor.YELLOW} lost. ${ChatColor.RED}(${TimeUtil.formatIntoHHMMSS((zone.time - (zone.time - seconds)) * 1000L)})") + } + + override fun onZoneTick(zone: CaptureZone, contester: Player) { + + val faction = FactionHandler.getFactionByPlayer(contester.uniqueId) + val filtered = arrayListOf(contester.uniqueId) + + if (faction != null) { + + val members = faction.getOnlineMembers().filter{it.uniqueId != contester.uniqueId} + + members.forEach{filtered.add(it.uniqueId)} + + this.sendMessage(members,"${ChatColor.YELLOW}Your faction is controlling ${ChatColor.BLUE}${this.name}${ChatColor.YELLOW}.") + } + + this.sendMessage(contester,"${ChatColor.YELLOW}Attempting to control ${ChatColor.BLUE}${this.name}${ChatColor.YELLOW}.") + + val messages = HashMap() + + messages["${ChatColor.BLUE}${this.name}${ChatColor.YELLOW} is trying to be controlled. ${ChatColor.RED}(${TimeUtil.formatIntoHHMMSS(zone.remaining.get() * 1000L)})"] = true + + this.sendMessage(HCF.instance.server.onlinePlayers.filter{!filtered.contains(it.uniqueId)},messages) + } + + override fun onZoneControl(zone: CaptureZone, contester: Player) { + this.sendMessage(contester,"${ChatColor.YELLOW}Attempting to control ${ChatColor.BLUE}${this.name}${ChatColor.YELLOW}.") + } + + override fun onZoneCapture(zone: CaptureZone, contester: Player) { + this.setActive(false) + + HCF.instance.server.pluginManager.callEvent(GameCaptureEvent(this,contester,FactionHandler.getFactionByPlayer(contester.uniqueId))) + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/game/capture/zone/ConquestCaptureZone.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/game/capture/zone/ConquestCaptureZone.kt new file mode 100644 index 0000000..608bff2 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/game/capture/zone/ConquestCaptureZone.kt @@ -0,0 +1,19 @@ +package cc.fyre.hcf.game.capture.zone + +import cc.fyre.hcf.game.capture.CaptureZone +import org.apache.commons.lang.StringUtils +import org.bukkit.ChatColor +import org.bukkit.Location +import java.util.concurrent.TimeUnit + +/** + * @project hcf + * + * @date 01/09/2020 + * @author xanderume@gmail.com + */ +class ConquestCaptureZone(val type: ConquestZoneType, location: Location?, time: Int) : CaptureZone(location,time) { + + constructor(type: ConquestZoneType, location: Location?, time: Long):this(type,location,TimeUnit.MILLISECONDS.toSeconds(time).toInt()) + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/game/capture/zone/ConquestZoneType.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/game/capture/zone/ConquestZoneType.kt new file mode 100644 index 0000000..24e72b1 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/game/capture/zone/ConquestZoneType.kt @@ -0,0 +1,20 @@ +package cc.fyre.hcf.game.capture.zone + +import org.apache.commons.lang.StringUtils +import org.bukkit.ChatColor + +enum class ConquestZoneType(val color: ChatColor, val points: Int) { + + RED(ChatColor.RED), + BLUE(ChatColor.BLUE), + GREEN(ChatColor.GREEN), + YELLOW(ChatColor.YELLOW), + MIDDLE(ChatColor.GOLD,2); + + constructor(color: ChatColor):this(color,1) + + fun getDisplayName():String { + return "${this.color}${StringUtils.capitalize(this.name.lowercase())}" + } + +} diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/game/capture/zone/FuryCaptureZone.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/game/capture/zone/FuryCaptureZone.kt new file mode 100644 index 0000000..e7c83a2 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/game/capture/zone/FuryCaptureZone.kt @@ -0,0 +1,20 @@ +package cc.fyre.hcf.game.capture.zone + +import cc.fyre.hcf.game.capture.CaptureZone +import org.apache.commons.lang.StringUtils +import org.bukkit.ChatColor +import org.bukkit.Location +import java.util.concurrent.TimeUnit + +/** + * @project hcf + * + * @date 05/09/2020 + * @author xanderume@gmail.com + */ +class FuryCaptureZone(val type: FuryZoneType, location: Location?, time: Int) : CaptureZone(location,time) { + + var active = false + + constructor(type: FuryZoneType, location: Location?, time: Long):this(type,location,TimeUnit.MILLISECONDS.toSeconds(time).toInt()) +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/game/capture/zone/FuryZoneType.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/game/capture/zone/FuryZoneType.kt new file mode 100644 index 0000000..1f8aa07 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/game/capture/zone/FuryZoneType.kt @@ -0,0 +1,22 @@ +package cc.fyre.hcf.game.capture.zone + +import org.apache.commons.lang.StringUtils +import org.bukkit.ChatColor + +enum class FuryZoneType(val color: ChatColor, val points: Int) { + + OVERWORLD(ChatColor.WHITE), + NETHER(ChatColor.RED), + END(ChatColor.DARK_PURPLE); + + constructor(color: ChatColor):this(color,1) + + fun getName():String { + return StringUtils.capitalize(this.name.lowercase()) + } + + fun getDisplayName():String { + return "${this.color}${StringUtils.capitalize(this.name.lowercase())}" + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/game/command/GameActivateCommand.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/game/command/GameActivateCommand.kt new file mode 100644 index 0000000..6b7d4ad --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/game/command/GameActivateCommand.kt @@ -0,0 +1,31 @@ +package cc.fyre.hcf.game.command + +import cc.fyre.shard.command.data.command.Command +import cc.fyre.shard.command.data.parameter.Parameter +import cc.fyre.hcf.game.GameFaction +import org.bukkit.ChatColor +import org.bukkit.command.CommandSender + +/** + * @project hcf + * + * @date 29/08/2020 + * @author xanderume@gmail.com + */ +object +GameActivateCommand { + + @JvmStatic + @Command(names = ["game activate","event activate","game start","event start"],permission = "hcf.command.game.activate") + fun execute(sender: CommandSender,@Parameter(name = "faction")faction: GameFaction) { + + if (faction.isActive()) { + sender.sendMessage("${ChatColor.RED}Game ${faction.getDisplayName(sender)}${ChatColor.RED} is already active!") + return + } + + faction.setActive(true) + faction.flagForSave() + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/game/command/GameCreateCommand.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/game/command/GameCreateCommand.kt new file mode 100644 index 0000000..5aa8172 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/game/command/GameCreateCommand.kt @@ -0,0 +1,54 @@ +package cc.fyre.hcf.game.command + +import cc.fyre.shard.command.data.command.Command +import cc.fyre.shard.command.data.parameter.Parameter +import cc.fyre.hcf.faction.FactionHandler +import cc.fyre.hcf.faction.menu.system.SystemEditMenu +import cc.fyre.hcf.game.GameFaction +import cc.fyre.hcf.game.GameType +import cc.fyre.hcf.game.capture.type.CitadelFaction +import cc.fyre.hcf.game.capture.type.ConquestFaction +import cc.fyre.hcf.game.other.DTCFaction +import cc.fyre.hcf.game.capture.type.FuryFaction +import cc.fyre.hcf.game.capture.type.KOTHFaction + +import org.bukkit.ChatColor +import org.bukkit.command.CommandSender +import org.bukkit.entity.Player + +/** + * @project hcf + * + * @date 29/08/2020 + * @author xanderume@gmail.com + */ +object GameCreateCommand { + + @JvmStatic + @Command(names = ["game create","event create"],permission = "hcf.command.game.create") + fun execute(sender: CommandSender,@Parameter(name = "name")name: String,@Parameter(name = "type")type: GameType) { + + if (FactionHandler.getFactionByName(name) != null) { + sender.sendMessage("${ChatColor.RED}That faction already exists!") + return + } + + val faction = when (type) { + GameType.DTC -> DTCFaction(name) + GameType.FURY -> FuryFaction(name) + GameType.KOTH -> KOTHFaction(name) + GameType.CITADEL -> CitadelFaction(name) + GameType.CONQUEST -> ConquestFaction(name) + } + + FactionHandler.update(faction) + faction.flagForSave() + + if (sender !is Player) { + return + } + + SystemEditMenu(faction).open(sender) + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/game/command/GameGiveKeyCommand.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/game/command/GameGiveKeyCommand.kt new file mode 100644 index 0000000..0f5a4b3 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/game/command/GameGiveKeyCommand.kt @@ -0,0 +1,35 @@ +package cc.fyre.hcf.game.command + +import cc.fyre.core.profile.ProfileHandler +import cc.fyre.shard.command.data.command.Command +import cc.fyre.shard.command.data.parameter.Parameter +import cc.fyre.hcf.HCF +import cc.fyre.hcf.game.GameFaction +import cc.fyre.hcf.game.GameHandler +import cc.fyre.shard.command.data.parameter.impl.PlayerParameterAdapter +import org.bukkit.ChatColor +import org.bukkit.command.CommandSender +import org.bukkit.entity.Player + +/** + * @project hcf + * + * @date 14/09/2020 + * @author xanderume@gmail.com + */ +object GameGiveKeyCommand { + + @JvmStatic + @Command(names = ["game givekey","event givekey"],hidden = true,permission = "hcf.command.game.givekey") + fun execute(sender: CommandSender, @Parameter(name = "faction")faction: GameFaction, @Parameter(name = "tier")tier: Int, @Parameter(name = "amount")amount: Int, @Parameter(name = "player",false,PlayerParameterAdapter.SELF_KEY_WORD)player: Player) { + player.inventory.addItem(GameHandler.getGameKey(faction,tier,amount)) + + if (sender is Player && sender.uniqueId == player.uniqueId) { + sender.sendMessage("${ChatColor.GOLD}Gave yourself ${ChatColor.YELLOW}$amount ${ChatColor.BLUE}Tier $tier ${faction.getDisplayName(sender)}${ChatColor.GOLD} keys.") + return + } + + sender.sendMessage("${ChatColor.GOLD}Gave ${ProfileHandler.getDisplayNameById(player.uniqueId)} ${ChatColor.YELLOW}$amount ${ChatColor.BLUE}Tier $tier ${faction.getDisplayName(sender)}${ChatColor.GOLD} keys.") + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/game/command/GameTerminateCommand.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/game/command/GameTerminateCommand.kt new file mode 100644 index 0000000..4887dd2 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/game/command/GameTerminateCommand.kt @@ -0,0 +1,35 @@ +package cc.fyre.hcf.game.command + +import cc.fyre.shard.command.data.command.Command +import cc.fyre.shard.command.data.parameter.Parameter +import cc.fyre.hcf.HCF +import cc.fyre.hcf.game.event.GameTerminateEvent +import cc.fyre.hcf.game.GameFaction +import org.bukkit.ChatColor +import org.bukkit.command.CommandSender + +/** + * @project hcf + * + * @date 29/08/2020 + * @author xanderume@gmail.com + */ +object GameTerminateCommand { + + @JvmStatic + @Command(names = ["game terminate","event terminate","game cancel","event cancel","game stop","event stop"],permission = "hcf.command.game.terminate") + fun execute(sender: CommandSender, @Parameter(name = "faction")faction: GameFaction) { + + if (!faction.isActive()) { + sender.sendMessage("${ChatColor.RED}Game ${faction.getDisplayName(sender)}${ChatColor.RED} is not active!") + return + } + + faction.setActive(false) + faction.onTerminate() + faction.flagForSave() + + HCF.instance.server.pluginManager.callEvent(GameTerminateEvent(faction)) + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/game/command/citadel/CitadelCommand.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/game/command/citadel/CitadelCommand.kt new file mode 100644 index 0000000..2f133a4 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/game/command/citadel/CitadelCommand.kt @@ -0,0 +1,26 @@ +package cc.fyre.hcf.game.command.citadel + +import cc.fyre.shard.command.data.command.Command +import cc.fyre.hcf.faction.FactionHandler +import cc.fyre.hcf.game.GameType +import cc.fyre.hcf.game.capture.type.CitadelFaction +import org.bukkit.ChatColor +import org.bukkit.command.CommandSender + +/** + * @project hcf + * + * @date 30/08/2020 + * @author xanderume@gmail.com + */ +object CitadelCommand { + + @JvmStatic + @Command(names = ["citadel"]) + fun execute(sender: CommandSender) { + FactionHandler.getAllGameFactions().filterIsInstance().map{it.findFaction()}.forEach{ + sender.sendMessage("${GameType.CITADEL.prefix} ${ChatColor.YELLOW}Citadel ${if (it == null) "was not captured last week" else "is currently controlled by ${it.getDisplayName(sender)}${ChatColor.YELLOW}"}.") + } + } + +} diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/game/command/citadel/CitadelRespawnCommand.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/game/command/citadel/CitadelRespawnCommand.kt new file mode 100644 index 0000000..50d8571 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/game/command/citadel/CitadelRespawnCommand.kt @@ -0,0 +1,32 @@ +package cc.fyre.hcf.game.command.citadel + +import cc.fyre.shard.command.data.command.Command +import cc.fyre.shard.command.data.parameter.Parameter +import cc.fyre.hcf.game.GameFaction +import cc.fyre.hcf.game.capture.type.CitadelFaction + +import org.bukkit.ChatColor +import org.bukkit.command.CommandSender + +/** + * @project hcf + * + * @date 30/08/2020 + * @author xanderume@gmail.com + */ +object CitadelRespawnCommand { + + @JvmStatic + @Command(names = ["citadel respawn","citadel refill"],hidden = true,permission = "hcf.command.citadel.respawn") + fun execute(sender: CommandSender,@Parameter(name = "faction")faction: GameFaction) { + + if (faction !is CitadelFaction) { + sender.sendMessage("${faction.getDisplayName(sender)}${ChatColor.RED} is not a citadel!") + return + } + + faction.fill() + faction.flagForSave() + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/game/command/citadel/CitadelScanCommand.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/game/command/citadel/CitadelScanCommand.kt new file mode 100644 index 0000000..599473d --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/game/command/citadel/CitadelScanCommand.kt @@ -0,0 +1,32 @@ +package cc.fyre.hcf.game.command.citadel + +import cc.fyre.shard.command.data.command.Command +import cc.fyre.shard.command.data.parameter.Parameter +import cc.fyre.hcf.game.GameFaction +import cc.fyre.hcf.game.capture.type.CitadelFaction +import org.bukkit.ChatColor +import org.bukkit.command.CommandSender + +/** + * @project hcf + * + * @date 04/09/2020 + * @author xanderume@gmail.com + */ +object CitadelScanCommand { + + @JvmStatic + @Command(names = ["citadel scan"],hidden = true,permission = "hcf.command.citadel.scan") + fun execute(sender: CommandSender,@Parameter(name = "faction")faction: GameFaction) { + + if (faction !is CitadelFaction) { + sender.sendMessage("${faction.getDisplayName(sender)}${ChatColor.RED} is not a citadel!") + return + } + + faction.scan() + faction.sendMessage(sender,"${ChatColor.YELLOW}Scanned ${faction.getDisplayName(sender)}${ChatColor.YELLOW}!") + faction.flagForSave() + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/game/command/citadel/CitadelSetCapperCommand.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/game/command/citadel/CitadelSetCapperCommand.kt new file mode 100644 index 0000000..87e34d3 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/game/command/citadel/CitadelSetCapperCommand.kt @@ -0,0 +1,48 @@ +package cc.fyre.hcf.game.command.citadel + +import cc.fyre.shard.command.data.command.Command +import cc.fyre.shard.command.data.parameter.Parameter +import cc.fyre.hcf.faction.command.parameter.PlayerFactionParameterProvider +import cc.fyre.hcf.faction.type.PlayerFaction +import cc.fyre.hcf.game.GameFaction +import cc.fyre.hcf.game.capture.type.CitadelFaction +import org.bukkit.ChatColor +import org.bukkit.command.CommandSender + +/** + * @project hcf + * + * @date 05/09/2020 + * @author xanderume@gmail.com + */ +object CitadelSetCapperCommand { + + @JvmStatic + @Command(names = ["citadel setcapper","citadel setcontroller"],hidden = true,permission = "hcf.command.citadel.setcapper") + fun execute(sender: CommandSender, @Parameter(name = "faction")faction: GameFaction, @Parameter(name = "faction|none")argument: String) { + + if (faction !is CitadelFaction) { + sender.sendMessage("${faction.getDisplayName(sender)}${ChatColor.RED} is not a citadel!") + return + } + + val capper: PlayerFaction? = if (argument == "none" || argument.isEmpty()) { + null + } else { + PlayerFactionParameterProvider.transform(sender,argument) + } + + if (capper == null) { + faction.faction = null + faction.captured = 0L + } else { + faction.faction = capper.id + faction.captured = System.currentTimeMillis() + } + + faction.sendMessage(sender,"${ChatColor.YELLOW}Updated capper for ${faction.getDisplayName(sender)}${ChatColor.YELLOW}.") + faction.flagForSave() + } + + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/game/command/conquest/ConquestCommand.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/game/command/conquest/ConquestCommand.kt new file mode 100644 index 0000000..8051235 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/game/command/conquest/ConquestCommand.kt @@ -0,0 +1,54 @@ +package cc.fyre.hcf.game.command.conquest + +import cc.fyre.shard.command.data.command.Command +import cc.fyre.hcf.faction.FactionHandler +import cc.fyre.hcf.game.capture.type.ConquestFaction +import org.apache.commons.lang.StringUtils +import org.bukkit.ChatColor +import org.bukkit.command.CommandSender + +/** + * @project hcf + * + * @date 03/09/2020 + * @author xanderume@gmail.com + */ +object ConquestCommand { + + @JvmStatic + @Command(names = ["conquest"]) + fun execute(sender: CommandSender) { + + val conquest = FactionHandler.getActiveGameFactions().filterIsInstance().firstOrNull() + + if (conquest == null) { + sender.sendMessage("${ChatColor.RED}There is no conquest active.") + return + } + + if (conquest.points.isEmpty() || conquest.points.entries.none{it.value.get() > 0}) { + sender.sendMessage("${ChatColor.RED}No factions have scored any points.") + return + } + + sender.sendMessage("${ChatColor.BLUE}${ChatColor.STRIKETHROUGH}${StringUtils.repeat("-",53)}") + sender.sendMessage("${ChatColor.RED}${ChatColor.BOLD}Conquest Scores") + sender.sendMessage("${ChatColor.BLUE}${ChatColor.STRIKETHROUGH}${StringUtils.repeat("-",53)}") + + conquest.points.entries.associate{FactionHandler.getFactionById(it.key) to it.value}.filter{it.key != null}.entries.sortedByDescending{it.value.get()}.withIndex().take(10).forEach{sender.sendMessage("${getColor(it.index)}#${it.index + 1} ${it.value.key?.getDisplayName(sender)}${ChatColor.GRAY}: ${it.value.value.get()}")} + + sender.sendMessage("${ChatColor.BLUE}${ChatColor.STRIKETHROUGH}${StringUtils.repeat("-",53)}") + } + + private fun getColor(index: Int):ChatColor { + + return when (index) { + 0 -> ChatColor.DARK_GREEN + 1 -> ChatColor.GREEN + 2 -> ChatColor.GOLD + else -> ChatColor.GRAY + } + + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/game/command/conquest/ConquestSetPointsCommand.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/game/command/conquest/ConquestSetPointsCommand.kt new file mode 100644 index 0000000..d77a149 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/game/command/conquest/ConquestSetPointsCommand.kt @@ -0,0 +1,37 @@ +package cc.fyre.hcf.game.command.conquest + +import cc.fyre.shard.command.data.command.Command +import cc.fyre.shard.command.data.parameter.Parameter +import cc.fyre.hcf.faction.FactionHandler +import cc.fyre.hcf.faction.type.PlayerFaction +import cc.fyre.hcf.game.capture.type.ConquestFaction +import org.bukkit.ChatColor +import org.bukkit.command.CommandSender +import java.util.concurrent.atomic.AtomicInteger + +/** + * @project hcf + * + * @date 03/09/2020 + * @author xanderume@gmail.com + */ +object ConquestSetPointsCommand { + + @JvmStatic + @Command(names = ["conquest setpoints","conquest setscore"],hidden = true,permission = "hcf.command.conquest.setpoints") + fun execute(sender: CommandSender,@Parameter(name = "faction")faction: PlayerFaction,@Parameter(name = "points")points: Int) { + + val conquest = FactionHandler.getActiveGameFactions().filterIsInstance().firstOrNull() + + if (conquest == null) { + sender.sendMessage("${ChatColor.RED}There is no conquest active.") + return + } + + conquest.points.putIfAbsent(faction.id,AtomicInteger()) + conquest.points[faction.id]!!.set(points) + conquest.sendMessage(sender,"${faction.getDisplayName(sender)}${ChatColor.GOLD} now has ${ChatColor.WHITE}${points} point${if (points == 1) "" else "s"}${ChatColor.GOLD}!") + conquest.flagForSave() + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/game/command/conquest/ConquestSetRadiusCommand.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/game/command/conquest/ConquestSetRadiusCommand.kt new file mode 100644 index 0000000..1bc2b42 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/game/command/conquest/ConquestSetRadiusCommand.kt @@ -0,0 +1,39 @@ +package cc.fyre.hcf.game.command.conquest + +import cc.fyre.shard.command.data.command.Command +import cc.fyre.shard.command.data.parameter.Parameter +import cc.fyre.hcf.game.GameFaction +import cc.fyre.hcf.game.capture.type.ConquestFaction +import cc.fyre.hcf.game.capture.zone.ConquestCaptureZone +import cc.fyre.hcf.game.capture.zone.ConquestZoneType +import org.bukkit.ChatColor +import org.bukkit.entity.Player + +/** + * @project hcf + * + * @date 13/11/2020 + * @author xanderume@gmail.com + */ +object ConquestSetRadiusCommand { + + @JvmStatic + @Command(names = ["conquest setradius","conquest setcapradius"],hidden = true,permission = "hcf.command.conquest.setzone") + fun execute(player: Player, @Parameter(name = "faction")faction: GameFaction, @Parameter(name = "zone")zone: ConquestZoneType, @Parameter(name = "radius")radius: Int) { + + if (faction !is ConquestFaction) { + player.sendMessage("${faction.getDisplayName(player)}${ChatColor.RED} is not a conquest!") + return + } + + if (radius <= 0) { + player.sendMessage("${ChatColor.RED}Radius must be higher than 0!") + return + } + + faction.findZoneByType(zone).radius = radius + faction.sendMessage(player,"${ChatColor.GOLD}Updated zone radius for ${zone.getDisplayName()}${ChatColor.GOLD}!") + faction.flagForSave() + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/game/command/conquest/ConquestSetZoneCommand.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/game/command/conquest/ConquestSetZoneCommand.kt new file mode 100644 index 0000000..1a93e6b --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/game/command/conquest/ConquestSetZoneCommand.kt @@ -0,0 +1,34 @@ +package cc.fyre.hcf.game.command.conquest + +import cc.fyre.shard.command.data.command.Command +import cc.fyre.shard.command.data.parameter.Parameter +import cc.fyre.hcf.game.GameFaction +import cc.fyre.hcf.game.capture.type.ConquestFaction +import cc.fyre.hcf.game.capture.zone.ConquestCaptureZone +import cc.fyre.hcf.game.capture.zone.ConquestZoneType +import org.bukkit.ChatColor +import org.bukkit.entity.Player + +/** + * @project hcf + * + * @date 03/09/2020 + * @author xanderume@gmail.com + */ +object ConquestSetZoneCommand { + + @JvmStatic + @Command(names = ["conquest setzone","conquest setcapturezone"],hidden = true,permission = "hcf.command.conquest.setzone") + fun execute(player: Player, @Parameter(name = "faction")faction: GameFaction, @Parameter(name = "zone")zone: ConquestZoneType) { + + if (faction !is ConquestFaction) { + player.sendMessage("${faction.getDisplayName(player)}${ChatColor.RED} is not a conquest!") + return + } + + faction.findZoneByType(zone).location = player.location.clone() + faction.sendMessage(player,"${ChatColor.GOLD}Updated zone for ${zone.getDisplayName()}${ChatColor.GOLD}!") + faction.flagForSave() + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/game/command/dtc/DTCSetAmountCommand.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/game/command/dtc/DTCSetAmountCommand.kt new file mode 100644 index 0000000..4694ca9 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/game/command/dtc/DTCSetAmountCommand.kt @@ -0,0 +1,32 @@ +package cc.fyre.hcf.game.command.dtc + +import cc.fyre.shard.command.data.command.Command +import cc.fyre.shard.command.data.parameter.Parameter +import cc.fyre.hcf.game.GameFaction +import cc.fyre.hcf.game.other.DTCFaction +import org.bukkit.ChatColor +import org.bukkit.entity.Player + +/** + * @project hcf + * + * @date 05/09/2020 + * @author xanderume@gmail.com + */ +object DTCSetAmountCommand { + + @JvmStatic + @Command(names = ["dtc setamount","dtc setremaining"],hidden = true,permission = "hcf.command.dtc.setamount") + fun execute(player: Player, @Parameter(name = "faction")faction: GameFaction, @Parameter(name = "amount")amount: Int) { + + if (faction !is DTCFaction) { + player.sendMessage("${faction.getDisplayName(player)}${ChatColor.RED} is not a dtc!") + return + } + + faction.remaining = (amount).coerceAtLeast(faction.objectiveCount) + faction.sendMessage(player,"${ChatColor.DARK_AQUA}Updated remaining for ${faction.getDisplayName(player)}${ChatColor.DARK_AQUA}!") + faction.flagForSave() + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/game/command/dtc/DTCSetObjectiveCommand.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/game/command/dtc/DTCSetObjectiveCommand.kt new file mode 100644 index 0000000..f05eb3d --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/game/command/dtc/DTCSetObjectiveCommand.kt @@ -0,0 +1,40 @@ +package cc.fyre.hcf.game.command.dtc + +import cc.fyre.shard.command.data.command.Command +import cc.fyre.shard.command.data.parameter.Parameter +import cc.fyre.hcf.game.GameFaction +import cc.fyre.hcf.game.other.DTCFaction +import org.bukkit.ChatColor +import org.bukkit.Material +import org.bukkit.entity.Player + +/** + * @project hcf + * + * @date 05/09/2020 + * @author xanderume@gmail.com + */ +object DTCSetObjectiveCommand { + + @JvmStatic + @Command(names = ["dtc setobjective","dtc setcore"],hidden = true,permission = "hcf.command.dtc.setobjective") + fun execute(player: Player, @Parameter(name = "faction")faction: GameFaction) { + + if (faction !is DTCFaction) { + player.sendMessage("${faction.getDisplayName(player)}${ChatColor.RED} is not a dtc!") + return + } + + val block = player.getTargetBlock(null,5) + + if (block == null || block.type == Material.AIR) { + player.sendMessage("${ChatColor.RED}You are not looking at a block.") + return + } + + faction.objective = block.location + faction.sendMessage(player,"${ChatColor.DARK_AQUA}Updated objective for ${faction.getDisplayName(player)}${ChatColor.DARK_AQUA}!") + faction.flagForSave() + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/game/command/fury/FuryCommand.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/game/command/fury/FuryCommand.kt new file mode 100644 index 0000000..ca39f33 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/game/command/fury/FuryCommand.kt @@ -0,0 +1,55 @@ +package cc.fyre.hcf.game.command.fury + +import cc.fyre.shard.command.data.command.Command +import cc.fyre.hcf.faction.FactionHandler + +import cc.fyre.hcf.game.capture.type.FuryFaction +import org.apache.commons.lang.StringUtils +import org.bukkit.ChatColor +import org.bukkit.command.CommandSender + +/** + * @project hcf + * + * @date 05/09/2020 + * @author xanderume@gmail.com + */ +object FuryCommand { + + @JvmStatic + @Command(names = ["fury"]) + fun execute(sender: CommandSender) { + + val fury = FactionHandler.getActiveGameFactions().filterIsInstance().firstOrNull() + + if (fury == null) { + sender.sendMessage("${ChatColor.RED}There is no fury active.") + return + } + + if (fury.points.isEmpty() || fury.points.entries.none{it.value.get() > 0}) { + sender.sendMessage("${ChatColor.RED}No factions have scored any points.") + return + } + + sender.sendMessage("${ChatColor.BLUE}${ChatColor.STRIKETHROUGH}${StringUtils.repeat("-",53)}") + sender.sendMessage("${ChatColor.RED}${ChatColor.BOLD}Fury Scores") + sender.sendMessage("${ChatColor.BLUE}${ChatColor.STRIKETHROUGH}${StringUtils.repeat("-",53)}") + + fury.points.entries.associate{ FactionHandler.getFactionById(it.key) to it.value}.filter{it.key != null}.entries.sortedByDescending{it.value.get()}.withIndex().take(10).forEach{sender.sendMessage("${getColor(it.index)}#${it.index + 1} ${it.value.key?.getDisplayName(sender)}${ChatColor.GRAY}: ${it.value.value.get()}")} + + sender.sendMessage("${ChatColor.BLUE}${ChatColor.STRIKETHROUGH}${StringUtils.repeat("-",53)}") + } + + private fun getColor(index: Int): ChatColor { + + return when (index) { + 0 -> ChatColor.DARK_GREEN + 1 -> ChatColor.GREEN + 2 -> ChatColor.GOLD + else -> ChatColor.GRAY + } + + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/game/command/fury/FurySetPointsCommand.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/game/command/fury/FurySetPointsCommand.kt new file mode 100644 index 0000000..1633450 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/game/command/fury/FurySetPointsCommand.kt @@ -0,0 +1,38 @@ +package cc.fyre.hcf.game.command.fury + +import cc.fyre.shard.command.data.command.Command +import cc.fyre.shard.command.data.parameter.Parameter +import cc.fyre.hcf.faction.FactionHandler +import cc.fyre.hcf.faction.type.PlayerFaction + +import cc.fyre.hcf.game.capture.type.FuryFaction +import org.bukkit.ChatColor +import org.bukkit.command.CommandSender +import java.util.concurrent.atomic.AtomicInteger + +/** + * @project hcf + * + * @date 05/09/2020 + * @author xanderume@gmail.com + */ +object FurySetPointsCommand { + + @JvmStatic + @Command(names = ["fury setpoints","fury setscore"],hidden = true,permission = "hcf.command.fury.setpoints") + fun execute(sender: CommandSender,@Parameter(name = "faction")faction: PlayerFaction,@Parameter(name = "points")points: Int) { + + val fury = FactionHandler.getActiveGameFactions().filterIsInstance().firstOrNull() + + if (fury == null) { + sender.sendMessage("${ChatColor.RED}There is no fury active.") + return + } + + fury.points.putIfAbsent(faction.id, AtomicInteger()) + fury.points[faction.id]!!.set(points) + fury.sendMessage(sender,"${faction.getDisplayName(sender)}${ChatColor.GOLD} now has ${ChatColor.WHITE}${points} point${if (points == 1) "" else "s"}${ChatColor.GOLD}!") + fury.flagForSave() + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/game/command/fury/FurySetZoneCommand.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/game/command/fury/FurySetZoneCommand.kt new file mode 100644 index 0000000..6d7f6cf --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/game/command/fury/FurySetZoneCommand.kt @@ -0,0 +1,35 @@ +package cc.fyre.hcf.game.command.fury + +import cc.fyre.shard.command.data.command.Command +import cc.fyre.shard.command.data.parameter.Parameter +import cc.fyre.hcf.game.GameFaction +import cc.fyre.hcf.game.capture.type.FuryFaction +import cc.fyre.hcf.game.capture.zone.FuryCaptureZone +import cc.fyre.hcf.game.capture.zone.FuryZoneType + +import org.bukkit.ChatColor +import org.bukkit.entity.Player + +/** + * @project hcf + * + * @date 05/09/2020 + * @author xanderume@gmail.com + */ +object FurySetZoneCommand { + + @JvmStatic + @Command(names = ["fury setzone","fury setcapturezone"],hidden = true,permission = "hcf.command.fury.setzone") + fun execute(player: Player, @Parameter(name = "faction")faction: GameFaction, @Parameter(name = "zone")zone: FuryZoneType) { + + if (faction !is FuryFaction) { + player.sendMessage("${faction.getDisplayName(player)}${ChatColor.RED} is not a fury!") + return + } + + faction.findZoneByType(zone).location = player.location.clone() + faction.sendMessage(player,"${ChatColor.GOLD}Updated zone for ${zone.getDisplayName()}${ChatColor.GOLD}!") + faction.flagForSave() + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/game/command/parameter/ConquestZoneTypeParameterProvider.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/game/command/parameter/ConquestZoneTypeParameterProvider.kt new file mode 100644 index 0000000..8321264 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/game/command/parameter/ConquestZoneTypeParameterProvider.kt @@ -0,0 +1,32 @@ +package cc.fyre.hcf.game.command.parameter + +import cc.fyre.shard.command.data.parameter.ParameterAdapter +import cc.fyre.hcf.game.capture.zone.ConquestCaptureZone +import cc.fyre.hcf.game.capture.zone.ConquestZoneType +import org.bukkit.ChatColor +import org.bukkit.command.CommandSender +import org.bukkit.entity.Player + +/** + * @project hcf + * + * @date 03/09/2020 + * @author xanderume@gmail.com + */ +object ConquestZoneTypeParameterProvider : ParameterAdapter { + + override fun transform(sender: CommandSender, source: String): ConquestZoneType? { + return try { + ConquestZoneType.valueOf(source.uppercase()) + } catch (ex: Exception) { + sender.sendMessage("${ChatColor.RED}Zone type '$source' not found.") + return null + } + + } + + override fun tabComplete(player: Player, flags: Set, source: String): List { + return emptyList() + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/game/command/parameter/FuryZoneTypeParameterProvider.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/game/command/parameter/FuryZoneTypeParameterProvider.kt new file mode 100644 index 0000000..27c9ef2 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/game/command/parameter/FuryZoneTypeParameterProvider.kt @@ -0,0 +1,32 @@ +package cc.fyre.hcf.game.command.parameter + +import cc.fyre.shard.command.data.parameter.ParameterAdapter +import cc.fyre.hcf.game.capture.zone.FuryCaptureZone +import cc.fyre.hcf.game.capture.zone.FuryZoneType +import org.bukkit.ChatColor +import org.bukkit.command.CommandSender +import org.bukkit.entity.Player + +/** + * @project hcf + * + * @date 05/09/2020 + * @author xanderume@gmail.com + */ +object FuryZoneTypeParameterProvider : ParameterAdapter { + + override fun transform(sender: CommandSender, source: String): FuryZoneType? { + return try { + FuryZoneType.valueOf(source.uppercase()) + } catch (ex: Exception) { + sender.sendMessage("${ChatColor.RED}Zone type '$source' not found.") + return null + } + + } + + override fun tabComplete(player: Player, flags: Set, source: String): List { + return emptyList() + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/game/command/parameter/GameTypeParameterProvider.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/game/command/parameter/GameTypeParameterProvider.kt new file mode 100644 index 0000000..8d8aa9d --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/game/command/parameter/GameTypeParameterProvider.kt @@ -0,0 +1,32 @@ +package cc.fyre.hcf.game.command.parameter + +import cc.fyre.shard.command.data.parameter.ParameterAdapter +import cc.fyre.hcf.game.GameFaction +import cc.fyre.hcf.game.GameType +import org.bukkit.ChatColor +import org.bukkit.command.CommandSender +import org.bukkit.entity.Player + +/** + * @project hcf + * + * @date 29/08/2020 + * @author xanderume@gmail.com + */ +object GameTypeParameterProvider : ParameterAdapter { + + override fun transform(sender: CommandSender, source: String): GameType? { + return try { + GameType.valueOf(source.uppercase()) + } catch (ex: Exception) { + sender.sendMessage("${ChatColor.RED}Game type '$source' not found.") + return null + } + + } + + override fun tabComplete(player: Player, flags: Set, source: String): List { + return emptyList() + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/game/event/GameActivateEvent.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/game/event/GameActivateEvent.kt new file mode 100644 index 0000000..7258e24 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/game/event/GameActivateEvent.kt @@ -0,0 +1,34 @@ +package cc.fyre.hcf.game.event + +import cc.fyre.hcf.game.GameFaction +import org.bukkit.event.Cancellable +import org.bukkit.event.Event +import org.bukkit.event.HandlerList + +/** + * @project hcf + * + * @date 29/08/2020 + * @author xanderume@gmail.com + */ +class GameActivateEvent(val game: GameFaction) : Event(),Cancellable { + + private var cancelled = false + + override fun isCancelled(): Boolean { + return this.cancelled + } + + override fun setCancelled(cancelled: Boolean) { + this.cancelled = cancelled + } + + override fun getHandlers(): HandlerList { + return handlerList + } + + companion object { + @JvmStatic val handlerList = HandlerList() + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/game/event/GameCaptureEvent.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/game/event/GameCaptureEvent.kt new file mode 100644 index 0000000..ce70bc5 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/game/event/GameCaptureEvent.kt @@ -0,0 +1,25 @@ +package cc.fyre.hcf.game.event + +import cc.fyre.hcf.faction.type.PlayerFaction +import cc.fyre.hcf.game.GameFaction +import org.bukkit.entity.Player +import org.bukkit.event.Event +import org.bukkit.event.HandlerList + +/** + * @project hcf + * + * @date 29/08/2020 + * @author xanderume@gmail.com + */ +class GameCaptureEvent(val game: GameFaction,val player: Player, val faction: PlayerFaction?) : Event() { + + override fun getHandlers(): HandlerList { + return handlerList + } + + companion object { + @JvmStatic val handlerList = HandlerList() + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/game/event/GameTerminateEvent.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/game/event/GameTerminateEvent.kt new file mode 100644 index 0000000..29a49b4 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/game/event/GameTerminateEvent.kt @@ -0,0 +1,23 @@ +package cc.fyre.hcf.game.event + +import cc.fyre.hcf.game.GameFaction +import org.bukkit.event.Event +import org.bukkit.event.HandlerList + +/** + * @project hcf + * + * @date 29/08/2020 + * @author xanderume@gmail.com + */ +class GameTerminateEvent(val game: GameFaction) : Event() { + + override fun getHandlers(): HandlerList { + return handlerList + } + + companion object { + @JvmStatic val handlerList = HandlerList() + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/game/listener/CaptureZoneListener.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/game/listener/CaptureZoneListener.kt new file mode 100644 index 0000000..f4a7aae --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/game/listener/CaptureZoneListener.kt @@ -0,0 +1,198 @@ +package cc.fyre.hcf.game.listener + +import cc.fyre.Forge +import cc.fyre.handler.MovementHandler +import cc.fyre.hcf.faction.FactionHandler +import cc.fyre.hcf.game.event.GameActivateEvent +import cc.fyre.hcf.game.event.GameCaptureEvent +import cc.fyre.hcf.game.event.GameTerminateEvent +import cc.fyre.hcf.game.capture.zone.FuryCaptureZone +import cc.fyre.hcf.game.capture.CaptureZoneFaction +import net.minecraft.server.v1_7_R4.PacketPlayInFlying +import org.bukkit.Bukkit +import org.bukkit.Location +import org.bukkit.entity.Player +import org.bukkit.event.EventHandler +import org.bukkit.event.EventPriority +import org.bukkit.event.Listener +import org.bukkit.event.entity.PlayerDeathEvent +import org.bukkit.event.player.* + +/** + * @project hcf + * + * @date 31/08/2020 + * @author xanderume@gmail.com + */ +object CaptureZoneListener : Listener,MovementHandler { + + init { + Forge.INSTANCE.addMovementHandler(this) + } + + @EventHandler(priority = EventPriority.MONITOR) + private fun onPlayerJoin(event: PlayerJoinEvent) { + + val faction = FactionHandler.getFactionByLocation(event.player.location) + + if (faction !is CaptureZoneFaction) { + return + } + + faction.getZones().filter{it.isInsideCaptureZone(event.player.location)}.forEach{ + + it.addContester(event.player) + + if (it.contester != null) { + return@forEach + } + + it.setContester(event.player,faction) + } + + } + + @EventHandler(priority = EventPriority.MONITOR) + private fun onPlayerKick(event: PlayerKickEvent) { + + val faction = FactionHandler.getFactionByLocation(event.player.location) + + if (faction !is CaptureZoneFaction) { + return + } + + faction.getZones().filter{it.isInsideCaptureZone(event.player.location)}.forEach{ + it.removeContester(event.player) + it.setContester(it.findNextContester(faction),faction) + } + } + + @EventHandler(priority = EventPriority.MONITOR) + private fun onPlayerQuit(event: PlayerQuitEvent) { + + val faction = FactionHandler.getFactionByLocation(event.player.location) + + if (faction !is CaptureZoneFaction) { + return + } + + faction.getZones().filter{it.isInsideCaptureZone(event.player.location)}.forEach{ + it.removeContester(event.player) + it.setContester(it.findNextContester(faction),faction) + } + } + + @EventHandler(priority = EventPriority.MONITOR) + private fun onPlayerDeath(event: PlayerDeathEvent) { + + val faction = FactionHandler.getFactionByLocation(event.entity.location) + + if (faction !is CaptureZoneFaction) { + return + } + + faction.getZones().filter{it.isInsideCaptureZone(event.entity.location)}.forEach{ + it.removeContester(event.entity) + it.setContester(it.findNextContester(faction),faction) + } + + } + + @EventHandler(priority = EventPriority.MONITOR) + private fun onGameActivate(event: GameActivateEvent) { + + if (event.game !is CaptureZoneFaction) { + return + } + + Bukkit.getServer().onlinePlayers.forEach{event.game.getZones().filter{ zone -> zone.isInsideCaptureZone(it.location)}.forEach{ zone -> zone.addContester(it)}} + + + event.game.getZones().forEach{it.setContester(it.findNextContester(event.game),event.game)} + } + + @EventHandler(priority = EventPriority.MONITOR) + private fun onGameCapture(event: GameCaptureEvent) { + + if (event.game !is CaptureZoneFaction) { + return + } + + event.game.getZones().forEach{it.contesters?.clear()} + } + + @EventHandler(priority = EventPriority.MONITOR) + private fun onGameTerminate(event: GameTerminateEvent) { + + if (event.game !is CaptureZoneFaction) { + return + } + + event.game.getZones().forEach{it.contesters?.clear()} + } + + @EventHandler(priority = EventPriority.MONITOR) + private fun onPlayerTeleport(event: PlayerTeleportEvent) { + + if (event.isCancelled) { + return + } + + this.handleUpdateLocation(event.player,event.to,event.from,null) + } + + override fun handleUpdateLocation(player: Player,to: Location,from: Location,packet: PacketPlayInFlying?) { + + if (from.blockX == to.blockX && from.blockZ == to.blockZ) { + return + } + + val faction = FactionHandler.getFactionByLocation(to) + + if (faction !is CaptureZoneFaction) { + return + } + + if (!faction.isActive()) { + return + } + + loop@ for (zone in faction.getZones()) { + + if (zone is FuryCaptureZone && !zone.active) { + continue@loop + } + + val isToInside = zone.isInsideCaptureZone(to) + val isFromInside = zone.isInsideCaptureZone(from) + + when { + isToInside == isFromInside -> continue@loop + !isToInside && isFromInside -> { + + zone.removeContester(player) + + if (zone.contester != player.uniqueId) { + return + } + + zone.setContester(zone.findNextContester(faction),faction) + } + isToInside && !isFromInside -> { + + if (zone.contester == null && faction.isAllowedToContest(player)) { + zone.addContester(player) + zone.setContester(player,faction) + } + + } + + } + + } + + } + + override fun handleUpdateRotation(player: Player,to: Location,from: Location,packet: PacketPlayInFlying?) {} + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/game/listener/CitadelListener.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/game/listener/CitadelListener.kt new file mode 100644 index 0000000..32c8be7 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/game/listener/CitadelListener.kt @@ -0,0 +1,25 @@ +package cc.fyre.hcf.game.listener + +import cc.fyre.hcf.HCF +import org.bukkit.event.Listener + +/** + * @project hcf + * + * @date 05/09/2020 + * @author xanderume@gmail.com + */ +object CitadelListener : Listener { + + /*TODO + @EventHandler(priority = EventPriority.MONITOR) + private fun onHourEvent(event: HourEvent) { + + if (event.hour % 2 != 0) { + return + } + + FactionHandler.findGameFactions().filterIsInstance().forEach{it.fill()} + }*/ + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/game/listener/ConquestListener.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/game/listener/ConquestListener.kt new file mode 100644 index 0000000..bedbb04 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/game/listener/ConquestListener.kt @@ -0,0 +1,32 @@ +package cc.fyre.hcf.game.listener + +import cc.fyre.core.profile.ProfileHandler +import cc.fyre.hcf.HCF +import cc.fyre.hcf.faction.FactionHandler +import cc.fyre.hcf.game.capture.type.ConquestFaction +import org.bukkit.ChatColor +import org.bukkit.event.EventHandler +import org.bukkit.event.EventPriority +import org.bukkit.event.Listener +import org.bukkit.event.entity.PlayerDeathEvent + +/** + * @project hcf + * + * @date 03/09/2020 + * @author xanderume@gmail.com + */ +object ConquestListener : Listener { + + @EventHandler(priority = EventPriority.NORMAL) + private fun onPlayerDeath(event: PlayerDeathEvent) { + + val faction = FactionHandler.getFactionByPlayer(event.entity.uniqueId) ?: return + + val conquest = (FactionHandler.getActiveGameFactions().firstOrNull{it is ConquestFaction && it.points.containsKey(faction.id) && it.points[faction.id]!!.get() > 0} ?: return) as ConquestFaction + + conquest.points[faction.id]!!.set(0.coerceAtLeast(conquest.points[faction.id]!!.get() - conquest.deathPenalty)) + conquest.sendMessage(faction.getOnlineMembers(),"${ChatColor.GOLD}Your faction hast lost ${ChatColor.YELLOW}${conquest.deathPenalty} point${if (conquest.deathPenalty == 1) "" else "s"} ${ChatColor.GOLD}because of ${ProfileHandler.getDisplayNameById(event.entity.uniqueId)}${ChatColor.GOLD}! ${ChatColor.RED}(${conquest.points[faction.id]!!.get()}/${conquest.requiredPoints})") + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/game/listener/DTCListener.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/game/listener/DTCListener.kt new file mode 100644 index 0000000..7e91bb8 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/game/listener/DTCListener.kt @@ -0,0 +1,42 @@ +package cc.fyre.hcf.game.listener + +import cc.fyre.hcf.HCF +import cc.fyre.hcf.faction.FactionHandler +import cc.fyre.hcf.game.other.DTCFaction +import org.bukkit.event.EventHandler +import org.bukkit.event.EventPriority +import org.bukkit.event.Listener +import org.bukkit.event.block.BlockBreakEvent + +/** + * @project hcf + * + * @date 05/09/2020 + * @author xanderume@gmail.com + */ +object DTCListener : Listener { + + @EventHandler(priority = EventPriority.MONITOR) + private fun onBlockBreak(event: BlockBreakEvent) { + + if (event.isCancelled) { + return + } + + val faction = FactionHandler.getFactionByLocation(event.block.location) + + if (faction !is DTCFaction) { + return + } + + if (event.block.location != faction.objective) { + return + } + + faction.onDestroy(event.player,event.block) + faction.flagForSave() + + event.isCancelled = true + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/game/listener/FuryListener.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/game/listener/FuryListener.kt new file mode 100644 index 0000000..f9e49b4 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/game/listener/FuryListener.kt @@ -0,0 +1,32 @@ +package cc.fyre.hcf.game.listener + +import cc.fyre.core.profile.ProfileHandler +import cc.fyre.hcf.HCF +import cc.fyre.hcf.faction.FactionHandler +import cc.fyre.hcf.game.capture.type.FuryFaction +import org.bukkit.ChatColor +import org.bukkit.event.EventHandler +import org.bukkit.event.EventPriority +import org.bukkit.event.Listener +import org.bukkit.event.entity.PlayerDeathEvent + +/** + * @project hcf + * + * @date 05/09/2020 + * @author xanderume@gmail.com + */ +object FuryListener : Listener { + + @EventHandler(priority = EventPriority.NORMAL) + private fun onPlayerDeath(event: PlayerDeathEvent) { + + val faction = FactionHandler.getFactionByPlayer(event.entity.uniqueId) ?: return + + val fury = (FactionHandler.getActiveGameFactions().firstOrNull{it is FuryFaction && it.points.containsKey(faction.id) && it.points[faction.id]!!.get() > 0} ?: return) as FuryFaction + + fury.points[faction.id]!!.set(0.coerceAtLeast(fury.points[faction.id]!!.get() - fury.deathPenalty)) + fury.sendMessage(faction.getOnlineMembers(),"${ChatColor.GOLD}Your faction hast lost ${ChatColor.YELLOW}${fury.deathPenalty} point${if (fury.deathPenalty == 1) "" else "s"} ${ChatColor.GOLD}because of ${ProfileHandler.getDisplayNameById(event.entity.uniqueId)}${ChatColor.GOLD}! ${ChatColor.RED}(${fury.points[faction.id]!!.get()}/${fury.requiredPoints})") + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/game/listener/GameListener.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/game/listener/GameListener.kt new file mode 100644 index 0000000..55f6037 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/game/listener/GameListener.kt @@ -0,0 +1,168 @@ +package cc.fyre.hcf.game.listener + +import cc.fyre.core.profile.ProfileHandler +import cc.fyre.hcf.HCF +import cc.fyre.hcf.faction.FactionHandler +import cc.fyre.hcf.faction.type.PlayerFaction +import cc.fyre.hcf.faction.event.FactionDisbandEvent +import cc.fyre.hcf.faction.event.FactionMoveEvent +import cc.fyre.hcf.game.event.GameActivateEvent +import cc.fyre.hcf.game.event.GameCaptureEvent +import cc.fyre.hcf.game.event.GameTerminateEvent +import cc.fyre.hcf.game.GameFaction +import cc.fyre.hcf.game.GameHandler +import cc.fyre.hcf.game.capture.type.ConquestFaction +import cc.fyre.hcf.game.other.DTCFaction +import cc.fyre.hcf.game.capture.type.FuryFaction +import org.bukkit.Bukkit +import org.bukkit.ChatColor +import org.bukkit.GameMode +import org.bukkit.enchantments.Enchantment +import org.bukkit.entity.Player +import org.bukkit.event.EventHandler +import org.bukkit.event.EventPriority +import org.bukkit.event.Listener +import org.bukkit.event.entity.EntityDamageByEntityEvent +import org.bukkit.event.player.PlayerTeleportEvent + +/** + * @project hcf + * + * @date 31/08/2020 + * @author xanderume@gmail.com + */ +object GameListener : Listener { + + @EventHandler(priority = EventPriority.MONITOR) + private fun onGameActivate(event: GameActivateEvent) { + event.game.sendStructuredMessage(HCF.instance.server.onlinePlayers,arrayOf( + event.game.getDisplayName(Bukkit.getConsoleSender()), + "${event.game.gameType.dominant}can be contested now." + )) + } + + @EventHandler(priority = EventPriority.MONITOR) + private fun onGameCapture(event: GameCaptureEvent) { + + if (event.game.getRewardTier() != 0 && event.game.getRewardAmount() != 0) { + + val item = GameHandler.getGameKey(event.game,event.game.getRewardTier(),event.game.getRewardAmount()) + + event.player.inventory.addItem(item) + + if (!event.player.inventory.contains(item)) { + event.player.world.dropItemNaturally(event.player.location,item) + } + + } + + if (event.faction != null) { + + if (event.game.getRewardPoints() != 0) { + event.faction.points += event.game.getRewardPoints() + } + + val sign = GameHandler.getGameSign(event.game,event.faction) + + event.player.inventory.addItem(sign) + + if (!event.player.inventory.contains(sign)) { + event.player.world.dropItemNaturally(event.player.location,sign) + } + + } + + val messages = arrayOf( + event.game.getDisplayName(Bukkit.getConsoleSender()), + "${event.game.gameType.dominant}has been ${if (event.game is DTCFaction) "destroyed" else "controlled"} by", + "${if (event.faction != null) "${ChatColor.GOLD}[${ChatColor.YELLOW}${event.faction.name}${ChatColor.GOLD}]" else ""}${ProfileHandler.getDisplayNameById(event.player.uniqueId)}${event.game.gameType.dominant}." + ) + + event.game.sendStructuredMessage(HCF.instance.server.onlinePlayers,messages) + } + + @EventHandler(priority = EventPriority.MONITOR) + private fun onGameTerminate(event: GameTerminateEvent) { + event.game.sendMessage(HCF.instance.server.onlinePlayers,"${ChatColor.BLUE}${event.game.name}${event.game.gameType.dominant} has been terminated.") + } + + @EventHandler(priority = EventPriority.MONITOR) + private fun onFactionDisband(event: FactionDisbandEvent) { + + if (event.faction !is PlayerFaction) { + return + } + + FactionHandler.getActiveGameFactions().filter{it is ConquestFaction || it is FuryFaction }.forEach{ + + if (it is ConquestFaction) { + it.points.remove(event.faction.id) + } else if (it is FuryFaction) { + it.points.remove(event.faction.id) + } + + } + + } + + @EventHandler(priority = EventPriority.HIGH) + private fun onPlayerTeleport(event: PlayerTeleportEvent) { + + val moveEvent = FactionMoveEvent(event.player,FactionHandler.getFactionByLocation(event.from),FactionHandler.getFactionByLocation(event.to)) + + this.onFactionMove(moveEvent) + + if (!moveEvent.isCancelled) { + return + } + + event.isCancelled = true + } + + @EventHandler(priority = EventPriority.HIGHEST) + private fun onFactionMove(event: FactionMoveEvent) { + + if (event.player.gameMode == GameMode.CREATIVE) { + return + } + + if (event.to !is GameFaction) { + return + } + + if (!event.to.isMajorEvent()) { + return + } + + val faction = FactionHandler.getFactionByPlayer(event.player.uniqueId) + + if (faction != null && faction.onlineMembers > PlayerFaction.GAME_REQUIRED_MEMBERS) { + return + } + + event.player.sendMessage("${ChatColor.RED}You cannot enter ${event.to.getDisplayName(event.player)}${ChatColor.RED} as a ${PlayerFaction.GAME_REQUIRED_MEMBERS} man or under!") + event.isCancelled = true + } + + @EventHandler(priority = EventPriority.LOWEST) + private fun onEntityDamageByEntity(event: EntityDamageByEntityEvent) { + + if (event.entity !is Player || event.damager !is Player) { + return + } + + if ((event.damager as Player).itemInHand == null || !(event.damager as Player).itemInHand.containsEnchantment(Enchantment.KNOCKBACK)) { + return + } + + val faction = FactionHandler.getFactionByLocation(event.entity.location) + + if (faction !is GameFaction || faction is DTCFaction) { + return + } + + event.isCancelled = true + (event.damager as Player).sendMessage("${ChatColor.RED}You cannot use knockback items at ${faction.getDisplayName(event.damager as Player)}${ChatColor.RED}!") + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/game/listener/GameRewardListener.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/game/listener/GameRewardListener.kt new file mode 100644 index 0000000..0d2824a --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/game/listener/GameRewardListener.kt @@ -0,0 +1,167 @@ +package cc.fyre.hcf.game.listener + +import cc.fyre.core.profile.ProfileHandler +import cc.fyre.shard.util.ChanceUtil +import cc.fyre.shard.util.StringUtil +import cc.fyre.hcf.HCF +import cc.fyre.hcf.faction.FactionMetadata +import cc.fyre.hcf.faction.type.SystemFaction +import cc.fyre.hcf.game.GameHandler +import cc.fyre.hcf.game.menu.GameLootMenu +import cc.fyre.shard.util.entity.InventoryUtil +import cc.fyre.shard.util.item.ItemUtil +import org.bukkit.* +import org.bukkit.block.BlockFace +import org.bukkit.block.Chest +import org.bukkit.entity.EntityType +import org.bukkit.entity.Firework +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.player.PlayerInteractEvent +import org.bukkit.inventory.ItemStack + +/** + * @project hcf + * + * @date 31/08/2020 + * @author xanderume@gmail.com + */ +object GameRewardListener : Listener { + + @EventHandler(priority = EventPriority.NORMAL) + private fun onPlayerInteract(event: PlayerInteractEvent) { + + if (event.clickedBlock == null) { + return + } + + if (event.clickedBlock.type != Material.ENDER_CHEST) { + return + } + + if (!FactionMetadata.SAFE_ZONE.isValidAtLocation(event.clickedBlock.location)) { + return + } + + val state = event.clickedBlock.getRelative(BlockFace.DOWN,3).state + + if (state !is Chest) { + return + } + + if (event.action == Action.LEFT_CLICK_BLOCK) { + GameLootMenu(state).open(event.player) + return + } + + if (event.item == null) { + return + } + + if (event.item.type != GameHandler.KEY_ITEM) { + return + } + + if (!event.item.hasItemMeta() || !event.item.itemMeta.hasDisplayName() || !event.item.itemMeta.hasLore()) { + return + } + + if (event.player.gameMode != GameMode.CREATIVE && !event.player.isSneaking) { + event.isCancelled = true + } + + if (state.inventory.contents.isEmpty()) { + event.player.sendMessage("${ChatColor.RED}It appears the event loot has not been setup yet, please contact an administrator.") + return + } + + val obtainedFrom = GameHandler.getObtainedFrom(event.item) + + if (obtainedFrom == null) { + event.player.sendMessage("${ChatColor.RED}This key is no longer valid, please contact an administrator if this is invalid.") + return + } + + val tier = GameHandler.getTier(event.item) + + if (tier == 0) { + event.player.sendMessage("${ChatColor.RED}This key is no longer valid, please contact an administrator if this is invalid.") + return + } + + if (InventoryUtil.getAvailableSlots(event.player.inventory) < tier * 3) { + event.player.sendMessage("${ChatColor.RED}You must have at least ${tier * 3} open inventory slots to open a tier $tier key.") + return + } + + if (event.player.itemInHand.amount == 1) { + event.player.itemInHand = null + } else { + event.player.itemInHand.amount = event.player.itemInHand.amount - 1 + } + + event.player.updateInventory() + + val loot = ArrayList() + val contents = state.inventory.contents.clone() + + if (contents.isEmpty()) { + return + } + + while (loot.size < tier * 3) { + + val rewards = contents.filter{!loot.contains(it)} + + if (rewards.isEmpty()) { + break + } + + val reward = rewards[ChanceUtil.pick(rewards.size)] ?: continue + + if (reward.type == Material.AIR) { + continue + } + + loot.add(reward) + } + + obtainedFrom.sendMessage(HCF.instance.server.onlinePlayers,"${ProfileHandler.getDisplayNameById(event.player.uniqueId)}${ChatColor.YELLOW} is obtaining loot for a ${ChatColor.BLUE}Tier $tier ${obtainedFrom.gameType.name} Key ${ChatColor.YELLOW}obtained from ${obtainedFrom.getDisplayName(event.player)} ${ChatColor.YELLOW}at ${ChatColor.GOLD}${GameHandler.getTime(event.item) ?: "Unknown"}${ChatColor.YELLOW}.") + + val fireWork = event.player.world.spawnEntity(event.clickedBlock.location.clone().add(0.5,0.0,0.5),EntityType.FIREWORK) as Firework + + val meta = fireWork.fireworkMeta + + meta.power = 2 + meta.addEffect(FireworkEffect.builder().with(FireworkEffect.Type.BALL_LARGE).withColor(Color.ORANGE,Color.YELLOW).withFade(Color.YELLOW,Color.WHITE).withTrail().withFlicker().build()) + + fireWork.fireworkMeta = meta + + HCF.instance.server.scheduler.runTaskLater(HCF.instance,{ + + if (event.player == null || !event.player.isOnline) { + return@runTaskLater + } + + for (itemStack in loot) { + + event.player.inventory.addItem(itemStack) + + if (event.player.inventory.contains(itemStack)) { + continue + } + + event.player.world.dropItemNaturally(event.player.location,itemStack) + } + + event.player.updateInventory() + + obtainedFrom.sendMessage(HCF.instance.server.onlinePlayers, + "${ProfileHandler.getDisplayNameById(event.player.uniqueId)}${ChatColor.YELLOW} obtained ${StringUtil.join(loot.map{"${ChatColor.BLUE}${it.amount}x ${ChatColor.YELLOW}${if (it.hasItemMeta() && it.itemMeta.hasDisplayName()) it.itemMeta.displayName else ItemUtil.getName(it)}"}.toTypedArray(),"${ChatColor.GOLD}, ","${ChatColor.GOLD}and ")}${ChatColor.YELLOW} from a ${ChatColor.BLUE}Tier $tier ${obtainedFrom.gameType.name} Key${ChatColor.YELLOW}.") + },5 * 20L) + + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/game/menu/GameLootMenu.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/game/menu/GameLootMenu.kt new file mode 100644 index 0000000..c344338 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/game/menu/GameLootMenu.kt @@ -0,0 +1,25 @@ +package cc.fyre.hcf.game.menu + +import cc.fyre.shard.menu.Menu +import cc.fyre.shard.menu.button.Button +import org.bukkit.block.Chest + +import org.bukkit.entity.Player + +/** + * @project hcf + * + * @date 31/08/2020 + * @author xanderume@gmail.com + */ +class GameLootMenu(private val chest: Chest) : Menu() { + + override fun getTitle(player: Player): String { + return "Event Loot" + } + + override fun getButtons(player: Player): MutableMap { + return this.chest.inventory.contents.filterNotNull().withIndex().associate{it.index to Button.fromItem(it.value)}.toMutableMap() + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/game/other/DTCFaction.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/game/other/DTCFaction.kt new file mode 100644 index 0000000..2ea22c8 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/game/other/DTCFaction.kt @@ -0,0 +1,166 @@ +package cc.fyre.hcf.game.other + +import cc.fyre.hcf.HCF +import cc.fyre.hcf.faction.FactionHandler +import cc.fyre.hcf.game.event.GameCaptureEvent +import cc.fyre.hcf.game.GameFaction +import cc.fyre.hcf.game.GameType +import com.squareup.moshi.JsonClass +import org.bukkit.ChatColor +import org.bukkit.Location +import org.bukkit.block.Block +import org.bukkit.entity.Player +import java.util.concurrent.TimeUnit + +/** + * @project hcf + * + * @date 05/09/2020 + * @author xanderume@gmail.com + */ +@JsonClass(generateAdapter = true) +class DTCFaction(name: String) : GameFaction(name,GameType.DTC) { + + var objective: Location? = null + var objectiveCount = 175 + + var remaining = this.objectiveCount + + var lastRegen = 0L + var lastAttempt = 0L + + override fun onTick() { + + if (this.remaining >= this.objectiveCount) { + return + } + + if (this.lastAttempt == 0L || ((REGEN_TIME > (System.currentTimeMillis() - this.lastAttempt)) && this.lastRegen == 0L || REGEN_TIME_DIFFERENCE > (System.currentTimeMillis() - this.lastRegen))) { + return + } + + this.lastRegen = System.currentTimeMillis() + + if (++this.remaining == this.objectiveCount) { + this.sendMessage(HCF.instance.server.onlinePlayers,"${ChatColor.GOLD}${this.name} ${ChatColor.DARK_AQUA}has been regenerated.") + return + } + + if (this.remaining % 10 != 0) { + return + } + + this.sendMessage(HCF.instance.server.onlinePlayers,"${ChatColor.GOLD}${this.name} ${ChatColor.DARK_AQUA}is regenerating. ${ChatColor.RED}[${this.remaining}/${this.objectiveCount}]") + } + + override fun onActivate() { + this.remaining = this.objectiveCount + } + + override fun onTerminate() { + this.remaining = this.objectiveCount + } + + override fun getRewardTier(): Int { + return 2 + } + + override fun getRewardAmount(): Int { + return 1 + } + + override fun getRewardPoints(): Int { + return 50 + } + + override fun getTabLayout(player: Player): List { + + val toReturn = ArrayList() + + toReturn.add(this.getDisplayName(player)) + toReturn.add("${ChatColor.RED}${this.remaining}") + + if (this.getHQ() != null) { + toReturn.add("${ChatColor.GRAY}${this.getHQ()!!.blockX}, ${this.getHQ()!!.blockZ}") + } + + return toReturn + } + + override fun getScoreboardLines(scores: ArrayList): List { + + val toReturn = ArrayList() + + toReturn.add("${this.displayName ?: "${"${ChatColor.DARK_AQUA}${ChatColor.BOLD}"}${this.name}"}${ChatColor.GRAY}: ${ChatColor.RED}${this.remaining}") + + return toReturn + } + + override fun getStructuredFormat(): ArrayList { + + val toReturn = ArrayList() + + toReturn.add("${ChatColor.GRAY}███████") + toReturn.add("${ChatColor.GRAY}█${ChatColor.DARK_AQUA}████${ChatColor.GRAY}██") + toReturn.add("${ChatColor.GRAY}█${ChatColor.DARK_AQUA}█${ChatColor.GRAY}███${ChatColor.DARK_AQUA}█${ChatColor.GRAY}█") + toReturn.add("${ChatColor.GRAY}█${ChatColor.DARK_AQUA}█${ChatColor.GRAY}███${ChatColor.DARK_AQUA}█${ChatColor.GRAY}█") + toReturn.add("${ChatColor.GRAY}█${ChatColor.DARK_AQUA}█${ChatColor.GRAY}███${ChatColor.DARK_AQUA}█${ChatColor.GRAY}█") + toReturn.add("${ChatColor.GRAY}█${ChatColor.DARK_AQUA}█${ChatColor.GRAY}███${ChatColor.DARK_AQUA}█${ChatColor.GRAY}█") + toReturn.add("${ChatColor.GRAY}█${ChatColor.DARK_AQUA}████${ChatColor.GRAY}██") + toReturn.add("${ChatColor.GRAY}███████") + + return toReturn + } + + override fun isAllowedToContest(player: Player): Boolean { + return true + } + + override fun isBreakingAllowed(block: Block): Boolean { + return this.isActive() && this.objective != null && this.objective == block.location + } + + fun onDestroy(player: Player,block: Block) { + this.lastAttempt = System.currentTimeMillis() + + if (--this.remaining % 25 != 0) { + return + } + + val faction = FactionHandler.getFactionByPlayer(player.uniqueId) + + if (this.remaining <= 0) { + this.setActive(false) + + HCF.instance.server.pluginManager.callEvent(GameCaptureEvent(this,player,faction)) + return + } + + val filtered = arrayListOf(player.uniqueId) + + if (faction != null) { + + val members = faction.getOnlineMembers().filter{it.uniqueId != player.uniqueId} + + members.forEach{filtered.add(it.uniqueId)} + + this.sendMessage(members,"${ChatColor.DARK_AQUA}Your faction is destroying the core.") + } + + this.sendMessage(player,"${ChatColor.DARK_AQUA}Attempting to destroy ${ChatColor.BLUE}${this.name}${ChatColor.DARK_AQUA}.") + + val messages = HashMap() + + messages["${ChatColor.GOLD}${this.name}${ChatColor.DARK_AQUA} is trying to be destroyed. ${ChatColor.RED}(${this.remaining})"] = true + + this.sendMessage(HCF.instance.server.onlinePlayers.filter{!filtered.contains(it.uniqueId)},messages) + } + + companion object { + + val REGEN_TIME = TimeUnit.MINUTES.toMillis(10L) + val REGEN_TIME_DIFFERENCE = TimeUnit.MINUTES.toMillis(1L) + + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/game/schedule/GameSchedule.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/game/schedule/GameSchedule.kt new file mode 100644 index 0000000..57d0a3a --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/game/schedule/GameSchedule.kt @@ -0,0 +1,56 @@ +package cc.fyre.hcf.game.schedule + +import com.google.common.primitives.Ints +import com.squareup.moshi.JsonClass +import com.squareup.moshi.Types +import java.lang.reflect.ParameterizedType + +import java.util.* + +/** + * @project hcf + * + * @date 03/12/2020 + * @author xanderume@gmail.com + */ +@JsonClass(generateAdapter = true) +class GameSchedule(val day: Int = 0,val hour: Int = 0,val minutes: Int = 0,val faction: UUID) : Comparable { + + @Transient + private val date = Calendar.getInstance().also{ + it[Calendar.SECOND] = 0 + it[Calendar.MINUTE] = this.minutes + it[Calendar.MILLISECOND] = 0 + it[Calendar.DAY_OF_YEAR] = this.day + it[Calendar.HOUR_OF_DAY] = this.hour + }.time + + fun toLong():Long { + return this.date.time + } + + fun toDate():Date { + return this.date + } + + override fun compareTo(other: GameSchedule): Int { + + var toReturn = Ints.compare(this.day,other.day) + + if (toReturn == 0) { + toReturn = Ints.compare(this.hour,other.hour) + } + + if (toReturn == 0) { + toReturn = Ints.compare(this.minutes,other.minutes) + } + + return toReturn + } + + companion object { + + val LIST_TYPE: ParameterizedType = Types.newParameterizedType(List::class.java,GameSchedule::class.java) + + } +} diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/game/schedule/command/GameCommand.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/game/schedule/command/GameCommand.kt new file mode 100644 index 0000000..84999b0 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/game/schedule/command/GameCommand.kt @@ -0,0 +1,51 @@ +package cc.fyre.hcf.game.schedule.command + +import cc.fyre.shard.command.data.command.Command +import cc.fyre.hcf.HCF +import cc.fyre.hcf.faction.FactionHandler +import cc.fyre.hcf.game.GameHandler +import cc.fyre.hcf.game.GameFaction +import cc.fyre.hcf.game.GameType +import cc.fyre.hcf.game.capture.CaptureZoneFaction +import mkremins.fanciful.FancyMessage +import org.bukkit.ChatColor +import org.bukkit.command.CommandSender +import java.util.* + +/** + * @project hcf + * + * @date 03/12/2020 + * @author xanderume@gmail.com + */ +object GameCommand { + + @Command(names = ["game","koth","event","game next","koth next","event next","game info","koth info","event info"]) + fun execute(sender: CommandSender) { + + var game = FactionHandler.getActiveGameFactions().firstOrNull{it.isActive()} + + if (game != null) { + FancyMessage("${game.gameType.prefix} ") + .then(game.getDisplayName(sender)) + .tooltip("${ChatColor.GREEN}Click to view faction info.") + .command("/faction info ${game.name}") + .then("${game.gameType.dominant} can be contested now.") + .send(sender) + return + } + + game = GameHandler.getNextGame() + + if (game == null) { + sender.sendMessage("${GameType.KOTH.prefix}${ChatColor.RED} Next Event: ${GameType.KOTH.dominant}Undefined") + return + } + + sender.sendMessage("${game.gameType.prefix} ${game.getDisplayName(sender)}${game.gameType.dominant} can be ${if (game is CaptureZoneFaction) "captured" else "contested"} at ${ChatColor.BLUE}${GameHandler.SCHEDULE_FORMAT.format(GameHandler.getNextGameSchedule())}${game.gameType.dominant}.") + sender.sendMessage("${game.gameType.prefix} ${game.gameType.dominant}It is currently ${ChatColor.BLUE}${GameHandler.SCHEDULE_FORMAT.format(Date())}${game.gameType.dominant}.") + sender.sendMessage("${game.gameType.dominant}Type '/game schedule' to see more upcoming events.") + + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/game/schedule/command/GameScheduleCommand.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/game/schedule/command/GameScheduleCommand.kt new file mode 100644 index 0000000..a58f90a --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/game/schedule/command/GameScheduleCommand.kt @@ -0,0 +1,53 @@ +package cc.fyre.hcf.game.schedule.command + +import cc.fyre.shard.command.data.command.Command +import cc.fyre.hcf.HCF +import cc.fyre.hcf.faction.FactionHandler +import cc.fyre.hcf.game.GameHandler +import cc.fyre.hcf.game.GameFaction +import cc.fyre.hcf.game.GameType +import cc.fyre.hcf.game.capture.CaptureZoneFaction +import org.bukkit.ChatColor +import org.bukkit.command.CommandSender +import java.util.* + +/** + * @project hcf + * + * @date 03/12/2020 + * @author xanderume@gmail.com + */ +object GameScheduleCommand { + + @Command(names = ["game schedule","koth schedule","event schedule","schedule"]) + fun execute(sender: CommandSender) { + + val now = Date() + var sent = 0 + + for (schedule in GameHandler.getGameSchedule()) { + + val date = schedule.toDate() + val game = FactionHandler.getFactionById(schedule.faction) + + if (game == null || game !is GameFaction || game.isActive() || date.before(now)) { + continue + } + + if (sent > 5) { + break + } + + sent++ + sender.sendMessage("${GameType.KOTH.prefix} ${game.getDisplayName(sender)}${GameType.KOTH.dominant} can be ${if (game is CaptureZoneFaction) "captured" else "contested"} at ${ChatColor.BLUE}${GameHandler.SCHEDULE_FORMAT.format(date)}${GameType.KOTH.dominant}.") + } + + if (sent == 0) { + sender.sendMessage("${GameType.KOTH.prefix}${ChatColor.RED} Game Schedule: ${GameType.KOTH.dominant}Undefined") + return + } + + sender.sendMessage("${GameType.KOTH.prefix}${GameType.KOTH.dominant} It is currently ${ChatColor.BLUE}${GameHandler.SCHEDULE_FORMAT.format(Date())}${GameType.KOTH.dominant}.") + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/game/schedule/command/GameScheduleGenerateCommand.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/game/schedule/command/GameScheduleGenerateCommand.kt new file mode 100644 index 0000000..cc3ca29 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/game/schedule/command/GameScheduleGenerateCommand.kt @@ -0,0 +1,71 @@ +package cc.fyre.hcf.game.schedule.command + +import cc.fyre.shard.command.data.command.Command +import cc.fyre.hcf.faction.FactionHandler +import cc.fyre.hcf.game.GameHandler +import cc.fyre.hcf.game.GameType +import cc.fyre.hcf.game.capture.type.CitadelFaction +import cc.fyre.hcf.game.capture.type.ConquestFaction +import cc.fyre.hcf.game.capture.type.FuryFaction +import cc.fyre.hcf.game.schedule.GameSchedule +import org.bukkit.command.CommandSender +import java.time.DayOfWeek +import java.time.LocalDate +import java.time.LocalDateTime +import java.time.LocalTime +import java.time.temporal.TemporalAdjusters +import java.util.* + +/** + * @project hcf + * + * @date 03/12/2020 + * @author xanderume@gmail.com + */ +object GameScheduleGenerateCommand { + + @Command(names = ["game schedule generate","koth schedule generate","event schedule generate","schedule generate"],hidden = true,permission = "hcf.command.game.schedule.generate") + fun execute(sender: CommandSender) { + + GameHandler.resetSchedule() + + val events = FactionHandler.getAllGameFactions().partition{!it.isMajorEvent()} + val currentDay = Calendar.getInstance().get(Calendar.DAY_OF_YEAR) + + for (dayOffset in 0..20) { + + val day = (currentDay + dayOffset) % 365 + val times = mutableListOf() + + val shuffled = events.first.filter{!it.isMajorEvent()}.shuffled() + + if (shuffled.isEmpty()) { + continue + } + + for (i in 0 until 23) { + times.add(intArrayOf(day,i,0)) + } + + times.withIndex().forEach{GameHandler.addSchedule(GameSchedule(it.value[0],it.value[1],it.value[2],events.first[it.index % shuffled.size].id))} + } + + + events.second.forEach{ + + val schedule = when (it) { + is FuryFaction -> GameSchedule(LocalDateTime.of(LocalDate.now(),LocalTime.now()).with(TemporalAdjusters.next(DayOfWeek.TUESDAY)).dayOfWeek.value,15,0,it.id) + is CitadelFaction -> GameSchedule(LocalDateTime.of(LocalDate.now(),LocalTime.now()).with(TemporalAdjusters.next(DayOfWeek.MONDAY)).dayOfMonth,15,0,it.id) + is ConquestFaction -> GameSchedule(LocalDateTime.of(LocalDate.now(),LocalTime.now()).with(TemporalAdjusters.next(DayOfWeek.SUNDAY)).dayOfWeek.value,14,0,it.id) + else -> return@forEach + } + + GameHandler.addSchedule(schedule) + } + + sender.sendMessage("${GameType.KOTH.prefix}${GameType.KOTH.dominant} Schedule has been regenerated.") + + GameHandler.saveFile() + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/game/scheduler/GameScheduler.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/game/scheduler/GameScheduler.kt new file mode 100644 index 0000000..d61e927 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/game/scheduler/GameScheduler.kt @@ -0,0 +1,49 @@ +package cc.fyre.hcf.game.scheduler + +import cc.fyre.hcf.faction.FactionHandler +import cc.fyre.hcf.game.GameFaction +import cc.fyre.hcf.game.GameHandler +import cc.fyre.hcf.game.GameType +import cc.fyre.hcf.game.capture.CaptureZoneFaction +import cc.fyre.hcf.game.schedule.GameSchedule +import org.bukkit.Bukkit +import org.bukkit.ChatColor +import java.util.* + +/** + * @project hcf + * + * @date 29/08/2020 + * @author xanderume@gmail.com + */ +object GameScheduler : Runnable { + + override fun run() { + + FactionHandler.getActiveGameFactions().forEach{ + + if (it is CaptureZoneFaction) { + it.getZones().forEach{zone -> zone.onTick(it)} + } + + it.onTick() + } + + if (GameHandler.getNextGameSchedule() == null) { + return + } + + if (GameHandler.getNextGameSchedule()!!.toDate().before(Date(System.currentTimeMillis()))) { + return + } + + if (GameHandler.getNextGame() == null) { + Bukkit.getServer().onlinePlayers.filter{it.isOp}.forEach{it.sendMessage("${GameType.KOTH.prefix}${ChatColor.RED} Failed to start event, faction not found.")} + return + } + + GameHandler.getNextGame()!!.setActive(true) + GameHandler.loadNextSchedule() + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/MapConfig.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/MapConfig.kt new file mode 100644 index 0000000..843ca31 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/MapConfig.kt @@ -0,0 +1,48 @@ +package cc.fyre.hcf.map + +import cc.fyre.hcf.HCF +import cc.fyre.shard.util.config.JsonConfig +import com.squareup.moshi.JsonClass +import org.bukkit.Location +import org.bukkit.potion.PotionEffectType +import org.bukkit.potion.PotionType +import java.util.* +import java.util.concurrent.TimeUnit + +@JsonClass(generateAdapter = true) +class MapConfig : JsonConfig() { + + var border = 3000 + var endExit = Location(HCF.instance.server.worlds[0],0.0,75.0,300.0) + + var bardAllies = true + var eotwWhitelist = mutableListOf() + + var reclaims = mutableMapOf( + "default" to mutableListOf( + "niggaballs {rank} 123", + "niggaballs {player} 123", + "niggaballs {playerDisplayName} 123" + ) + ) + + var deathBans = mutableMapOf( + "basic" to TimeUnit.MINUTES.toMillis(50L), + "vip" to TimeUnit.MINUTES.toMillis(40L), + "mvp" to TimeUnit.MINUTES.toMillis(30L), + "ultra" to TimeUnit.MINUTES.toMillis(20L), + "epic" to TimeUnit.MINUTES.toMillis(10L), + "master" to TimeUnit.MINUTES.toMillis(5L), + "fyre" to TimeUnit.MINUTES.toMillis(1L), + ) + + val potionLimits = mutableMapOf( + PotionType.REGEN to 0, + PotionType.POISON to 1, + PotionType.SLOWNESS to 1, + PotionType.STRENGTH to 0, + PotionType.WEAKNESS to 0, + PotionType.INVISIBILITY to 0, + PotionType.INSTANT_DAMAGE to 0, + ) +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/MapHandler.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/MapHandler.kt new file mode 100644 index 0000000..d91efae --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/MapHandler.kt @@ -0,0 +1,122 @@ +package cc.fyre.hcf.map + +import cc.fyre.core.BukkitCore +import cc.fyre.core.rank.Rank +import cc.fyre.core.server.ServerModule +import cc.fyre.hcf.HCF +import cc.fyre.hcf.map.service.RankBroadcastService +import cc.fyre.shard.util.ConfigUtil +import cc.fyre.shard.util.item.ItemBuilder +import org.bukkit.Bukkit +import org.bukkit.ChatColor +import org.bukkit.Location +import org.bukkit.Material +import org.bukkit.enchantments.Enchantment +import org.bukkit.entity.EntityType +import org.bukkit.inventory.ItemStack +import org.bukkit.inventory.ShapelessRecipe +import org.bukkit.potion.PotionType +import kotlin.math.max + + +object MapHandler { + + lateinit var config: MapConfig + + fun init() { + this.config = ConfigUtil.register("map",HCF.instance.name,HCF.instance.dataFolder,MapConfig()) + + val iterator = Bukkit.getServer().recipeIterator() + + while (iterator.hasNext()) { + + val recipe = iterator.next() + + if (DISALLOWED_RECIPES.contains(recipe.result.type)) { + iterator.remove() + } + + } + + var interval = BukkitCore.instance.getServerGroup()?.announcementsInterval + + if (interval == null) { + interval = 300 + } + + interval += (interval / 2) + interval += interval + + Bukkit.getServer().scheduler.also{ + it.runTaskTimerAsynchronously(HCF.instance,RankBroadcastService,interval * 20L,interval * 20L) + } + + Bukkit.getServer().addRecipe(ShapelessRecipe(ItemStack(Material.SPECKLED_MELON)).addIngredient(Material.MELON).addIngredient(Material.GOLD_NUGGET)) + } + + fun getEndExit():Location { + return this.config.endExit + } + + fun setEndExit(location: Location) { + this.config.endExit = location + } + + fun getPotionLimit(type: PotionType): Int { + return this.config.potionLimits[type] ?: type.maxLevel + } + + val ORE_TYPES = arrayOf( + Material.COAL_ORE, + Material.IRON_ORE, + Material.GOLD_ORE, + Material.LAPIS_ORE, + Material.DIAMOND_ORE, + Material.EMERALD_ORE, + Material.GLOWING_REDSTONE_ORE, + ) + + val STARTER_ITEMS = arrayOf( + ItemBuilder.of(Material.FISHING_ROD) + .enchant(Enchantment.LURE,2) + .build(), + ItemBuilder.of(Material.COOKED_BEEF) + .amount(16) + .build() + ) + + var SPAWN_LOCATION = Bukkit.getServer().worlds[0]!!.spawnLocation + .add(0.5,0.0,0.5) + .clone() + + //TODO Mobtimizer + val MOB_ATTACK_BLACKLIST = arrayOf( + EntityType.SLIME, + EntityType.CREEPER, + EntityType.ENDERMAN, + EntityType.MAGMA_CUBE, + ) + + + val CUT_CLEAN_TOOLS = arrayOf(Material.DIAMOND_PICKAXE,Material.GOLD_PICKAXE,Material.IRON_PICKAXE,Material.STONE_PICKAXE,Material.WOOD_PICKAXE) + val CUT_CLEAN_TYPES = mutableMapOf( + Material.IRON_ORE to ItemStack(Material.IRON_INGOT), + Material.GOLD_ORE to ItemStack(Material.GOLD_INGOT) + ) + + val EXP_MULTIPLIERS = mutableMapOf( + 0 to 1.25, + 1 to 1.5, + 2 to 1.75, + 3 to 2.0, + 4 to 2.25 + ) + + val EXP_MULTIPLIER_MAX = EXP_MULTIPLIERS.entries.last() + val DISALLOWED_RECIPES = arrayListOf(Material.BEACON,Material.ENDER_CHEST,Material.SPECKLED_MELON,Material.EXPLOSIVE_MINECART) + + fun getReclaimByRank(rank: Rank):List? { + return this.config.reclaims[rank.name.lowercase()] + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/MapModule.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/MapModule.kt new file mode 100644 index 0000000..10b8556 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/MapModule.kt @@ -0,0 +1,69 @@ +package cc.fyre.hcf.map + +import cc.fyre.hcf.HCF +import cc.fyre.hcf.HCFModule +import cc.fyre.hcf.map.border.command.BorderCommand +import cc.fyre.hcf.map.border.listener.BorderListener +import cc.fyre.hcf.map.crowbar.CrowbarListener +import cc.fyre.hcf.map.crowbar.command.CrowbarCommand +import cc.fyre.hcf.map.eotw.listener.EOTWListener +import cc.fyre.hcf.map.listener.* +import cc.fyre.hcf.map.sotw.command.SOTWCancelCommand +import cc.fyre.hcf.map.sotw.command.SOTWEnableCommand +import cc.fyre.hcf.map.sotw.command.SOTWPauseCommand +import cc.fyre.hcf.map.sotw.command.SOTWStartCommand +import cc.fyre.hcf.map.sotw.listener.SOTWListener +import cc.fyre.shard.command.data.parameter.ParameterAdapter +import org.bukkit.event.Listener + +object MapModule : HCFModule { + + override fun init(core: HCF) { + MapHandler.init() + } + + override fun shutdown(core: HCF) { + } + + override fun getCommands(): List> { + return listOf( + BorderCommand::class.java, + CrowbarCommand::class.java, + + SOTWStartCommand::class.java, + SOTWPauseCommand::class.java, + SOTWCancelCommand::class.java, + SOTWEnableCommand::class.java + ) + } + + override fun getAdapters(): Map, ParameterAdapter<*>> { + return mapOf() + } + + override fun getListeners(): List { + return listOf( + EOTWListener, + SOTWListener, + BorderListener, + CrowbarListener, + + BookListener, + DiamondListener, + EndListener, + EXPListener, + GeneralListener, + GlitchListener, + InventoryListener, + MobListener, + NameTagListener, + NetherListener, + PickaxeListener, + PotionListener, + PreventionListener, + RedstoneListener, + StatTrakListener, + ) + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/border/BorderHandler.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/border/BorderHandler.kt new file mode 100644 index 0000000..604f4ac --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/border/BorderHandler.kt @@ -0,0 +1,24 @@ +package cc.fyre.hcf.map.border + +import cc.fyre.hcf.faction.claim.ClaimHandler +import cc.fyre.hcf.map.MapHandler +import org.bukkit.Location +import kotlin.math.abs + +object BorderHandler { + + fun getBorder():Int { + return MapHandler.config.border + } + + fun setBorder(border: Int) { + MapHandler.config.border = border + } + + + fun isInsideBorder(location: Location):Boolean { + return abs(location.x) <= MapHandler.config.border + || abs(location.z) <= MapHandler.config.border + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/border/command/BorderCommand.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/border/command/BorderCommand.kt new file mode 100644 index 0000000..284c1f7 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/border/command/BorderCommand.kt @@ -0,0 +1,25 @@ +package cc.fyre.hcf.map.border.command + +import cc.fyre.shard.command.data.command.Command +import cc.fyre.shard.command.data.parameter.Parameter +import cc.fyre.hcf.HCF +import cc.fyre.hcf.map.border.BorderHandler +import org.bukkit.ChatColor +import org.bukkit.World +import org.bukkit.command.CommandSender + +/** + * @project hcf + * + * @date 28/11/2020 + * @author xanderume@gmail.com + */ +object BorderCommand { + + @Command(names = ["border","setborder"],hidden = true,permission = "hcf.command.border") + fun execute(sender: CommandSender,@Parameter(name = "border")border: Int) { + BorderHandler.setBorder(border) + sender.sendMessage("${ChatColor.GREEN}Updated the border to: ${ChatColor.YELLOW}$border") + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/border/listener/BorderListener.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/border/listener/BorderListener.kt new file mode 100644 index 0000000..3bc7c3d --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/border/listener/BorderListener.kt @@ -0,0 +1,119 @@ +package cc.fyre.hcf.map.border.listener + +import cc.fyre.handler.MovementHandler +import cc.fyre.hcf.HCF +import cc.fyre.hcf.faction.claim.ClaimHandler +import cc.fyre.hcf.map.border.BorderHandler +import net.minecraft.server.v1_7_R4.PacketPlayInFlying +import org.bukkit.ChatColor +import org.bukkit.Location +import org.bukkit.Material +import org.bukkit.entity.Player +import org.bukkit.event.EventHandler +import org.bukkit.event.EventPriority +import org.bukkit.event.Listener +import org.bukkit.event.block.BlockBreakEvent +import org.bukkit.event.block.BlockPlaceEvent +import org.bukkit.event.player.PlayerPortalEvent +import org.bukkit.event.player.PlayerTeleportEvent +import kotlin.math.abs + +/** + * @project hcf + * + * @date 13/09/2020 + * @author xanderume@gmail.com + */ +object BorderListener : Listener,MovementHandler { + + @EventHandler(priority = EventPriority.NORMAL) + private fun onBlockPlace(event: BlockPlaceEvent) { + + if (BorderHandler.isInsideBorder(event.block.location)) { + return + } + + event.isCancelled = true + } + + @EventHandler(priority = EventPriority.NORMAL) + private fun onBlockBreak(event: BlockBreakEvent) { + + if (BorderHandler.isInsideBorder(event.block.location)) { + return + } + + event.isCancelled = true + } + + @EventHandler(priority = EventPriority.NORMAL) + private fun onPlayerPortal(event: PlayerPortalEvent) { + + if (BorderHandler.isInsideBorder(event.to)) { + return + } + + val location = event.to.clone() + + while (abs(location.x) > BorderHandler.getBorder()) { + location.x = location.x - if (location.x > 0) 1 else -1 + } + + while (abs(location.z) > BorderHandler.getBorder()) { + location.z = location.z - if (location.z > 0) 1 else -1 + } + + event.to = location + event.player.sendMessage(ChatColor.RED.toString() + "That portal's location is past the border. It has been moved inwards.") + } + + override fun handleUpdateRotation(p0: Player?, p1: Location?, p2: Location?, p3: PacketPlayInFlying?) {} + + override fun handleUpdateLocation(player: Player,to: Location,from: Location,packet: PacketPlayInFlying?) { + + if (from.blockX == to.blockX && from.blockZ == to.blockZ) { + return + } + + if (BorderHandler.isInsideBorder(to)) { + return + } + + if (player.vehicle != null) { + player.vehicle.eject() + } + + val location = to.clone() + + var tries = 0 + + while (abs(location.x) > BorderHandler.getBorder() && tries++ < 100) { + location.x = location.x - if (location.x > 0) 1 else -1 + } + + if (tries >= 99) { + HCF.instance.logger.severe("The server would have crashed while doing border checks! New X: " + location.x + ", Old X: " + to.blockX) + return + } + + tries = 0 + + while (abs(location.z) > BorderHandler.getBorder() && tries++ < 100) { + location.z = location.z - if (location.z > 0) 1 else -1 + } + + + if (tries >= 99) { + HCF.instance.logger.severe("The server would have crashed while doing border checks! New Z: " + location.z + ", Old Z: " + to.blockZ) + return + } + + while (location.block.type != Material.AIR) { + location.y = location.blockY + 1.toDouble() + } + + player.teleport(location) + player.sendMessage("${ChatColor.RED}You have hit the border!") + } + +} diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/command/EndExitCommand.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/command/EndExitCommand.kt new file mode 100644 index 0000000..acb8be7 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/command/EndExitCommand.kt @@ -0,0 +1,27 @@ +package cc.fyre.hcf.map.command + +import cc.fyre.shard.command.data.command.Command +import cc.fyre.hcf.HCF +import cc.fyre.hcf.map.MapHandler +import cc.fyre.shard.util.ConfigUtil +import org.bukkit.ChatColor +import org.bukkit.command.CommandSender +import org.bukkit.entity.Player + +/** + * @project hcf + * + * @date 16/09/2020 + * @author xanderume@gmail.com + */ +object EndExitCommand { + + @JvmStatic + @Command(names = ["endexit","setendexit"],hidden = true,permission = "hcf.command.endexit") + fun execute(player: Player) { + MapHandler.setEndExit(player.location.clone()) + player.sendMessage("${ChatColor.GREEN}Updated end exit location.") + } + + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/command/MapKitCommand.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/command/MapKitCommand.kt new file mode 100644 index 0000000..40db7da --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/command/MapKitCommand.kt @@ -0,0 +1,24 @@ +package cc.fyre.hcf.map.command + +import cc.fyre.shard.command.data.command.Command +import org.bukkit.ChatColor +import org.bukkit.command.CommandSender +import org.bukkit.enchantments.Enchantment + +/** + * @project hcf + * + * @date 14/09/2020 + * @author xanderume@gmail.com + */ +object MapKitCommand { + + @JvmStatic + @Command(names = ["mapkit"]) + fun execute(sender: CommandSender) { + sender.sendMessage("${ChatColor.YELLOW}Power: ${ChatColor.RED}${Enchantment.ARROW_DAMAGE.maxLevel}") + sender.sendMessage("${ChatColor.YELLOW}Protection: ${ChatColor.RED}${Enchantment.PROTECTION_ENVIRONMENTAL.maxLevel}") + sender.sendMessage("${ChatColor.YELLOW}Sharpness: ${ChatColor.RED}${Enchantment.DAMAGE_ALL.maxLevel}") + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/command/OresCommand.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/command/OresCommand.kt new file mode 100644 index 0000000..d87fcc6 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/command/OresCommand.kt @@ -0,0 +1,33 @@ +package cc.fyre.hcf.map.command + +import cc.fyre.shard.command.data.command.Command +import cc.fyre.shard.command.data.parameter.Parameter +import cc.fyre.hcf.statistic.StatisticHandler +import cc.fyre.hcf.statistic.type.ores.* +import cc.fyre.shard.command.data.parameter.impl.PlayerParameterAdapter +import org.bukkit.ChatColor +import org.bukkit.command.CommandSender +import org.bukkit.entity.Player +import java.util.* + +/** + * @project hcf + * + * @date 28/11/2020 + * @author xanderume@gmail.com + */ +object OresCommand { + + @JvmStatic + @Command(names = ["ores"]) + fun execute(sender: CommandSender,@Parameter(name = "player",defaultValue = PlayerParameterAdapter.SELF_KEY_WORD) uuid: UUID) { + sender.sendMessage("${ChatColor.AQUA}Diamond mined: ${ChatColor.WHITE}${StatisticHandler.getStatistic(uuid,DiamondMinedStatistic).getValue()}") + sender.sendMessage("${ChatColor.GREEN}Emerald mined: ${ChatColor.WHITE}${StatisticHandler.getStatistic(uuid,EmeraldMinedStatistic).getValue()}") + sender.sendMessage("${ChatColor.GOLD}Gold mined: ${ChatColor.WHITE}${StatisticHandler.getStatistic(uuid,GoldMinedStatistic).getValue()}") + sender.sendMessage("${ChatColor.GRAY}Iron mined: ${ChatColor.WHITE}${StatisticHandler.getStatistic(uuid,IronMinedStatistic).getValue()}") + sender.sendMessage("${ChatColor.BLUE}Lapis mined: ${ChatColor.WHITE}${StatisticHandler.getStatistic(uuid,LapisMinedStatistic).getValue()}") + sender.sendMessage("${ChatColor.RED}Redstone mined: ${ChatColor.WHITE}${StatisticHandler.getStatistic(uuid,RedstoneMinedStatistic).getValue()}") + sender.sendMessage("${ChatColor.DARK_GRAY}Coal mined: ${ChatColor.WHITE}${StatisticHandler.getStatistic(uuid,CoalMinedStatistic).getValue()}") + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/command/ShopCommand.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/command/ShopCommand.kt new file mode 100644 index 0000000..48615aa --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/command/ShopCommand.kt @@ -0,0 +1,27 @@ +package cc.fyre.hcf.map.command + +import cc.fyre.hcf.faction.FactionHandler +import cc.fyre.hcf.faction.FactionMetadata +import cc.fyre.hcf.faction.type.SystemFaction +import cc.fyre.hcf.map.shop.ShopMenu +import cc.fyre.shard.command.data.command.Command +import org.bukkit.ChatColor +import org.bukkit.entity.Player + +object ShopCommand { + + @JvmStatic + @Command(names = ["shop"]) + fun execute(sender: Player) { + + val faction = FactionHandler.getFactionByLocation(sender.location) + + if (faction !is SystemFaction || !faction.hasMetadata(FactionMetadata.SAFE_ZONE)) { + sender.sendMessage("${ChatColor.RED}You can only access the shop in a Safe-Zone!") + return + } + + ShopMenu.open(sender) + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/command/SpawnCommand.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/command/SpawnCommand.kt new file mode 100644 index 0000000..d979d96 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/command/SpawnCommand.kt @@ -0,0 +1,54 @@ +package cc.fyre.hcf.map.command + +import cc.fyre.shard.command.data.command.Command +import cc.fyre.shard.command.data.parameter.Parameter +import cc.fyre.hcf.faction.FactionHandler +import cc.fyre.hcf.faction.FactionMetadata +import cc.fyre.hcf.map.sotw.SOTWHandler +import cc.fyre.shard.command.CommandHandler +import cc.fyre.shard.command.data.parameter.impl.PlayerParameterAdapter +import org.bukkit.ChatColor +import org.bukkit.command.CommandSender +import org.bukkit.entity.Player + +object SpawnCommand { + + const val PERMISSION = "hcf.command.spawn" + + @JvmStatic + @Command(names = ["spawn"],false) + fun spawn(sender: CommandSender,@Parameter(name = "player",defaultValue = PlayerParameterAdapter.SELF_KEY_WORD)target: Player) { + + val spawn = FactionHandler.getAllSystemFactions().firstOrNull{it.hasMetadata(FactionMetadata.SAFE_ZONE) && it.getHQ() != null && it.getHQ()!!.world.uid == target.world.uid} + + if (spawn == null) { + sender.sendMessage("${ChatColor.RED}There is no Safe-Zone in your world.") + return + } + + if (!sender.hasPermission("$PERMISSION.advanced") && sender is Player) { + + if (!SOTWHandler.isActive()) { + sender.sendMessage("${ChatColor.RED}You can only warp to ${spawn.getDisplayName(sender)} ${ChatColor.RED}during SOTW!") + return + } + + if (!SOTWHandler.isProtected(sender)) { + sender.sendMessage("${ChatColor.RED}You must have your SOTW Timer active to warp to ${spawn.getDisplayName(sender)} ${ChatColor.RED}!") + return + } + + sender.sendMessage("${ChatColor.YELLOW}Warping to ${spawn.getDisplayName(sender)}${ChatColor.YELLOW}..") + sender.teleport(spawn.getHQ()) + return + } + + if (sender is Player && sender.uniqueId != target.uniqueId && !sender.hasPermission("$PERMISSION.others")) { + sender.sendMessage(CommandHandler.NO_PERMISSION) + return + } + + target.teleport(spawn.getHQ()) + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/command/ToggleEndCommand.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/command/ToggleEndCommand.kt new file mode 100644 index 0000000..cd5c101 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/command/ToggleEndCommand.kt @@ -0,0 +1,23 @@ +package cc.fyre.hcf.map.command + +import cc.fyre.shard.command.data.command.Command +import org.bukkit.command.CommandSender + +/** + * @project hcf + * + * @date 15/01/2021 + * @author xanderume@gmail.com + */ +object ToggleEndCommand { + + var VALUE = true + + @JvmStatic + @Command(names = ["toggleend"],hidden = true,permission = "teststet") + fun execute(sender: CommandSender) { + VALUE = !VALUE + sender.sendMessage("New: $VALUE") + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/crowbar/CrowbarHandler.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/crowbar/CrowbarHandler.kt new file mode 100644 index 0000000..2c4d1db --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/crowbar/CrowbarHandler.kt @@ -0,0 +1,64 @@ +package cc.fyre.hcf.map.crowbar + +import cc.fyre.shard.util.item.ItemBuilder +import org.bukkit.ChatColor +import org.bukkit.Material +import org.bukkit.inventory.ItemStack + +object CrowbarHandler { + + val ITEM_TYPE = Material.DIAMOND_HOE + + const val LORE_KEY = "§8Crowbar" + const val DISPLAY_NAME = "§cCrowbar" + + fun create(spawnerUses: Int = 1,endPortalUses: Int = 6):ItemStack { + + val lore = mutableListOf() + + lore.add(LORE_KEY) + lore.add(" ") + lore.add("${ChatColor.GRAY}Can Break:") + lore.add("${ChatColor.WHITE} - ${ChatColor.AQUA}Spawners: ${ChatColor.YELLOW}{${ChatColor.BLUE}$spawnerUses${ChatColor.YELLOW}}") + lore.add("${ChatColor.WHITE} - ${ChatColor.AQUA}End Portals: ${ChatColor.YELLOW}{${ChatColor.BLUE}$endPortalUses${ChatColor.YELLOW}}") + + return ItemBuilder.of(ITEM_TYPE) + .name(DISPLAY_NAME) + .lore(lore) + .build() + } + + fun isCrowbar(item: ItemStack):Boolean { + return item.type == ITEM_TYPE + && item.hasItemMeta() + && item.itemMeta.displayName == DISPLAY_NAME + && item.itemMeta.lore != null && item.itemMeta.lore.size >= 5 && item.itemMeta.lore[0] == LORE_KEY + } + + fun getPortalUses(item: ItemStack):Int { + return item.itemMeta.lore[4]!![25].toString().toIntOrNull() ?: 0 + } + + fun setPortalUses(item: ItemStack,amount: Int) { + + val lore = item.itemMeta.lore + + StringBuilder(lore[4]).setCharAt(25,amount.toChar()).also{ + item.itemMeta.lore = lore + } + } + + fun getSpawnerUses(item: ItemStack):Int { + return item.itemMeta.lore[4]!![22].toString().toIntOrNull() ?: 0 + } + + fun setSpawnerUses(item: ItemStack,amount: Int) { + + val lore = item.itemMeta.lore + + StringBuilder(lore[4]).setCharAt(22,amount.toChar()).also{ + item.itemMeta.lore = lore + } + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/crowbar/CrowbarListener.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/crowbar/CrowbarListener.kt new file mode 100644 index 0000000..69524de --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/crowbar/CrowbarListener.kt @@ -0,0 +1,169 @@ +package cc.fyre.hcf.map.crowbar + +import cc.fyre.hcf.faction.FactionHandler +import cc.fyre.hcf.faction.type.PlayerFaction +import cc.fyre.hcf.faction.type.SystemFaction +import org.apache.commons.lang.StringUtils +import org.bukkit.* +import org.bukkit.block.CreatureSpawner +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.player.PlayerInteractEvent +import org.bukkit.inventory.ItemStack + +object CrowbarListener : Listener { + + @EventHandler(priority = EventPriority.NORMAL) + private fun onBlockBreak(event: BlockBreakEvent) { + + if (event.block.type != Material.MOB_SPAWNER) { + return + } + + if (event.player.gameMode == GameMode.CREATIVE) { + return + } + + event.player.sendMessage("${ChatColor.RED}${if (event.player.world.environment == World.Environment.NETHER) { + "You cannot break spawners in the nether!" + } else { + "This is too strong for you to break! Try using a crowbar instead." + }}") + + event.isCancelled = true + } + + @EventHandler(priority = EventPriority.NORMAL) + private fun onPlayerInteract(event: PlayerInteractEvent) { + + if (event.action != Action.RIGHT_CLICK_BLOCK || event.clickedBlock == null) { + return + } + + if (event.item == null || !CrowbarHandler.isCrowbar(event.item)) { + return + } + + if (!(event.clickedBlock.type == Material.MOB_SPAWNER || event.clickedBlock.type == Material.ENDER_PORTAL_FRAME)) { + return + } + + if (FactionHandler.isAdminOverride(event.player)) { + return + } + + val faction = FactionHandler.getFactionByLocation(event.clickedBlock.location) + + if (faction is PlayerFaction && (faction.isRaidable() || faction.isMember(event.player))) { + return + } + + if (faction is SystemFaction && faction.isAllowedToInteract(event.clickedBlock,event.player,event.action)) { + return + } + + event.isCancelled = true + event.player.sendMessage("${ChatColor.YELLOW}You cannot crowbar in ${faction.getDisplayName(event.player)}${ChatColor.YELLOW}'s territory!") + } + + @EventHandler(priority = EventPriority.HIGHEST) + private fun onPlayerInteractBlock(event: PlayerInteractEvent) { + + if (event.isCancelled) { + return + } + + if (event.action != Action.RIGHT_CLICK_BLOCK || event.clickedBlock == null) { + return + } + + if (!(event.clickedBlock.type == Material.MOB_SPAWNER || event.clickedBlock.type == Material.ENDER_PORTAL_FRAME)) { + return + } + + + if (event.item == null || !CrowbarHandler.isCrowbar(event.item)) { + return + } + + if (event.clickedBlock.type == Material.ENDER_PORTAL_FRAME) { + + var uses = CrowbarHandler.getPortalUses(event.item) + + if (uses == 0) { + event.player.sendMessage("${ChatColor.RED}This crowbar has no more end portal uses!") + return + } + event.clickedBlock.world.playEffect(event.clickedBlock.location, Effect.STEP_SOUND, event.clickedBlock.typeId) + event.clickedBlock.type = Material.AIR + event.clickedBlock.state.update() + + event.clickedBlock.world.dropItemNaturally(event.clickedBlock.location, ItemStack(Material.ENDER_PORTAL_FRAME)) + event.clickedBlock.world.playSound(event.clickedBlock.location, Sound.ANVIL_USE, 1.0f, 1.0f) + + for (x in -3..2) { + for (z in -3..2) { + val block = event.clickedBlock.location.add(x.toDouble(), 0.0, z.toDouble()).block + if (block.type == Material.ENDER_PORTAL) { + block.type = Material.AIR + block.world.playEffect(block.location, Effect.STEP_SOUND, Material.ENDER_PORTAL.id) + } + } + } + + uses -= 1 + + if (uses == 0) { + event.player.itemInHand = null + event.clickedBlock.location.world.playSound(event.clickedBlock.location, Sound.ITEM_BREAK, 1.0f, 1.0f) + return + } + + CrowbarHandler.setPortalUses(event.item,uses) + + val max = Material.DIAMOND_HOE.maxDurability.toDouble() + val durability = max / 6 * uses + + event.item.durability = (max - durability).toInt().toShort() + event.player.itemInHand = event.item + return + } + + var uses = CrowbarHandler.getSpawnerUses(event.item) + val spawner = event.clickedBlock.state as CreatureSpawner + + event.clickedBlock.location.world.playEffect(event.clickedBlock.location, Effect.STEP_SOUND,event.clickedBlock.typeId) + event.clickedBlock.type = Material.AIR + event.clickedBlock.state.update() + + val drop = ItemStack(Material.MOB_SPAWNER) + val meta = drop.itemMeta + + meta.displayName = ChatColor.RESET.toString() + StringUtils.capitaliseAllWords(spawner.spawnedType.toString().lowercase().replace("_".toRegex(), " ")) + " Spawner" + drop.itemMeta = meta + + event.clickedBlock.location.world.dropItemNaturally(event.clickedBlock.location, drop) + event.clickedBlock.location.world.playSound(event.clickedBlock.location, Sound.ANVIL_USE, 1.0f, 1.0f) + + uses -= 1 + + if (uses == 0) { + event.player.itemInHand = null + event.clickedBlock.location.world.playSound(event.clickedBlock.location, Sound.ITEM_BREAK, 1.0f, 1.0f) + return + } + + + CrowbarHandler.setSpawnerUses(event.item,uses) + + val max = Material.DIAMOND_HOE.maxDurability.toDouble() + val durability = max / 1 * uses + + event.item.durability = (max - durability).toInt().toShort() + event.player.itemInHand = event.item + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/crowbar/command/CrowbarCommand.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/crowbar/command/CrowbarCommand.kt new file mode 100644 index 0000000..1451364 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/crowbar/command/CrowbarCommand.kt @@ -0,0 +1,28 @@ +package cc.fyre.hcf.map.crowbar.command + +import cc.fyre.core.profile.ProfileHandler +import cc.fyre.hcf.map.crowbar.CrowbarHandler +import cc.fyre.shard.command.data.command.Command +import cc.fyre.shard.command.data.parameter.Parameter +import cc.fyre.shard.command.data.parameter.impl.PlayerParameterAdapter +import org.bukkit.ChatColor +import org.bukkit.command.CommandSender +import org.bukkit.entity.Player + +object CrowbarCommand { + + @JvmStatic + @Command(names = ["crowbar"],hidden = true,permission = "hcf.command.crowbar") + fun execute(sender: CommandSender, @Parameter(name = "player",defaultValue = PlayerParameterAdapter.SELF_KEY_WORD)player: Player) { + + player.inventory.addItem(CrowbarHandler.create()) + + if (sender is Player && sender.uniqueId == player.uniqueId) { + sender.sendMessage("${ChatColor.GREEN}Gave yourself a ${CrowbarHandler.DISPLAY_NAME}${ChatColor.GREEN}.") + return + } + + sender.sendMessage("${ChatColor.GREEN}Gave ${ProfileHandler.getDisplayNameById(player.uniqueId)}${ChatColor.GREEN} a ${CrowbarHandler.DISPLAY_NAME}${ChatColor.GREEN}.") + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/engine/HCFNameTagAdapter.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/engine/HCFNameTagAdapter.kt new file mode 100644 index 0000000..012c4b5 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/engine/HCFNameTagAdapter.kt @@ -0,0 +1,62 @@ +package cc.fyre.hcf.map.engine + +import cc.fyre.core.staff.StaffHandler +import cc.fyre.hcf.faction.Faction +import cc.fyre.hcf.faction.FactionHandler +import cc.fyre.hcf.map.sotw.SOTWHandler +import cc.fyre.hcf.timer.TimerHandler +import cc.fyre.hcf.timer.TimerType +import cc.fyre.shard.nametag.adapter.NameTagAdapter +import cc.fyre.shard.nametag.entry.NameTagEntry +import cc.fyre.shard.nametag.entry.NameTagOption +import org.bukkit.ChatColor +import org.bukkit.entity.Player + +/** + * @project hcf + * + * @date 07/07/2020 + * @author xanderume@gmail.com + */ +object HCFNameTagAdapter : NameTagAdapter { + + private val SOTW_ENTRY = NameTagEntry("sotw",ChatColor.GOLD.toString(),"") + private val ENEMY_ENTRY = NameTagEntry("enemy",ChatColor.YELLOW.toString(),"",NameTagOption.HIDE_INVISIBILITY) + private val FOCUS_ENTRY = NameTagEntry("focus",ChatColor.LIGHT_PURPLE.toString(),"",NameTagOption.HIDE_INVISIBILITY) + private val FACTION_ENTRY = NameTagEntry("faction",ChatColor.DARK_GREEN.toString(),"") + private val ALLIANCE_ENTRY = NameTagEntry("alliance",Faction.ALLY_COLOR.toString(),"") + private val ARCHER_MARK_ENTRY = NameTagEntry("archerMark",ChatColor.RED.toString(),"",NameTagOption.HIDE_INVISIBILITY) + + override fun getEntry(player: Player,target: Player):NameTagEntry { + + val faction = FactionHandler.getFactionByPlayer(player.uniqueId) + + if (SOTWHandler.isActive() && SOTWHandler.isProtected(target)) { + return SOTW_ENTRY + } + + if (TimerHandler.hasTimer(target.uniqueId,TimerType.ARCHER_MARK)) { + return ARCHER_MARK_ENTRY + } + + if (faction != null) { + + if (faction.isFocused(target)) { + return FOCUS_ENTRY + } + + if (faction.isMember(target)) { + return FACTION_ENTRY + } + + if (faction.isAllied(target.uniqueId)) { + return ALLIANCE_ENTRY + } + + } + + + return ENEMY_ENTRY + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/engine/HCFScoreboardAdapter.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/engine/HCFScoreboardAdapter.kt new file mode 100644 index 0000000..026ee7e --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/engine/HCFScoreboardAdapter.kt @@ -0,0 +1,167 @@ +package cc.fyre.hcf.map.engine + +import cc.fyre.core.server.ServerModule +import cc.fyre.shard.util.TimeUtil +import cc.fyre.hcf.HCF +import cc.fyre.hcf.ability.AbilityHandler +import cc.fyre.hcf.ability.type.AntiBuildBone +import cc.fyre.hcf.faction.FactionHandler +import cc.fyre.hcf.faction.FactionMetadata +import cc.fyre.hcf.faction.type.PlayerFaction +import cc.fyre.hcf.faction.type.SystemFaction +import cc.fyre.hcf.map.sotw.SOTWHandler +import cc.fyre.hcf.pvpclass.PvPClassHandler +import cc.fyre.hcf.statistic.StatisticHandler +import cc.fyre.hcf.statistic.type.DeathsStatistic +import cc.fyre.hcf.statistic.type.KillsStatistic +import cc.fyre.hcf.statistic.type.setting.AbilityCooldownSetting +import cc.fyre.hcf.statistic.type.setting.FactionFocusSetting +import cc.fyre.hcf.timer.TimerHandler +import cc.fyre.hcf.timer.TimerType +import cc.fyre.shard.scoreboard.adapter.ScoreboardAdapter +import org.apache.commons.lang.StringUtils +import org.bukkit.ChatColor +import org.bukkit.entity.Player + +/** + * @project hcf + * + * @date 06/07/2020 + * @author xanderume@gmail.com + */ +object HCFScoreboardAdapter : ScoreboardAdapter { + + val LINE = "${ChatColor.GRAY}${ChatColor.STRIKETHROUGH}${StringUtils.repeat("-",20)}" + + // val TITLE = "${ChatColor.GOLD}${ChatColor.BOLD}Fyre ${ChatColor.GRAY}┃ ${ChatColor.WHITE}${if (HCF.instance.isKitMap()) "KitMap" else "Squads"}" + private val TITLE = "${ChatColor.GOLD}${ChatColor.BOLD}${ServerModule.getServerId()}" + + override fun getTitle(player: Player): String { + return TITLE + } + + override fun getScores(player: Player): List { + + val toReturn = ArrayList() + + val faction = FactionHandler.getFactionByLocation(player.location) + + if (HCF.instance.isKitMap() && faction is SystemFaction && faction.hasMetadata(FactionMetadata.SAFE_ZONE)) { + toReturn.add("${ChatColor.GOLD}${ChatColor.BOLD}Kills${ChatColor.GRAY}: ${ChatColor.RED}${StatisticHandler.getStatistic(player.uniqueId,KillsStatistic).getValue()}") + toReturn.add("${ChatColor.GOLD}${ChatColor.BOLD}Deaths${ChatColor.GRAY}: ${ChatColor.RED}${StatisticHandler.getStatistic(player.uniqueId,DeathsStatistic).getValue()}") + } + + if (SOTWHandler.isActive()) { + + if (SOTWHandler.isProtected(player)) { + toReturn.add( + "${ChatColor.GREEN}${ChatColor.BOLD}SOTW${ChatColor.GRAY}: ${ChatColor.RED}${ + TimeUtil.formatIntoDetailedString( + SOTWHandler.getRemainingMillis() + ) + }" + ) + } else { + toReturn.add( + "${ChatColor.GREEN}${ChatColor.BOLD}${ChatColor.STRIKETHROUGH}SOTW${ChatColor.GRAY}: ${ChatColor.RED}${ + TimeUtil.formatIntoHHMMSS( + SOTWHandler.getRemainingMillis() + ) + }" + ) + } + } + + + /*TODO + val remaining = Shard.instance.rebootHandler.findRemaining() + + if (Shard.instance.rebootHandler.isActive() && remaining <= TimeUnit.MINUTES.toMillis(15L)) { + toReturn.add("${ChatColor.GOLD}${ChatColor.BOLD}Reboot${ChatColor.GRAY}: ${ChatColor.RED}${TimeUtil.formatIntoMMSS(remaining)}") + }*/ + + /*TODO + if (HCF.instance.settingHandler.getSetting(player.uniqueId,Setting.CUSTOM_TIMERS)) { + TimerHandler.customTimers.values.forEach{ + toReturn.add("${it.text}${ChatColor.GRAY}: ${ChatColor.RED}${TimeUtil.formatIntoHHMMSS(it.getRemaining())}") + } + }*/ + + if (StatisticHandler.getStatistic(player.uniqueId,AbilityCooldownSetting).getValue()) { + AbilityHandler.getAllCooldowns(player.uniqueId).filter{it.key.isScoreboardDisplay()}.forEach{ + toReturn.add("${it.key.getDisplayName()}${ChatColor.GRAY}: ${ChatColor.RED}${TimeUtil.formatIntoFancy(it.value)}") + } + } + + val blockUpCooldown = AntiBuildBone.getCooldown(player) + + if (blockUpCooldown > 0L) { + toReturn.add("${ChatColor.YELLOW}${ChatColor.BOLD}Blockup${ChatColor.GRAY}:${ChatColor.RED} ${TimeUtil.formatIntoFancy(blockUpCooldown)}") + } + + TimerHandler.getTimersByPlayer(player.uniqueId).filter{it.type.displays}.sortedBy{it.type.ordinal}.forEach{toReturn.add("${it.type.scoreboard}${ChatColor.GRAY}: ${ChatColor.RED}${TimeUtil.formatIntoFancy(it.getRemaining())}")} + + val pvpClass = PvPClassHandler.getPvPClassByPlayer(player.uniqueId) + + if (pvpClass != null) { + + if (pvpClass.isEnergyBased()) { + + val cooldown = TimerHandler.getRemaining(player.uniqueId, TimerType.ENERGY_COOLDOWN) + + if (cooldown > 0L) { + toReturn.add("${ChatColor.GREEN}${ChatColor.BOLD}${pvpClass.getName()} Effect${ChatColor.GRAY}: ${ChatColor.RED}${TimeUtil.formatIntoHHMMSS(cooldown)}") + } + + val energy = pvpClass.getEnergy(player.uniqueId) + + if (energy > 0) { + toReturn.add("${ChatColor.AQUA}${ChatColor.BOLD}${pvpClass.getName()} Energy${ChatColor.GRAY}:${ChatColor.RED} ${energy}.0") + } + + } + + } + + FactionHandler.getActiveGameFactions().sortedBy{it.gameType.ordinal}.forEach{toReturn.addAll(it.getScoreboardLines(toReturn))} + + + if (StatisticHandler.getStatistic(player.uniqueId,FactionFocusSetting).getValue()) { + + val playerFaction = FactionHandler.getFactionByPlayer(player.uniqueId) + + if (playerFaction?.focus != null) { + + val targetFaction = FactionHandler.getFactionById(playerFaction.focus!!) + + if (targetFaction != null && targetFaction is PlayerFaction) { + + if (toReturn.isNotEmpty()) { + toReturn.add(" ") + } + + val hq = targetFaction.getHQ() + + toReturn.add("${ChatColor.GOLD}${ChatColor.BOLD}Team${ChatColor.GRAY}: ${ChatColor.YELLOW}${targetFaction.name}") + + if (hq != null) { + toReturn.add("${ChatColor.GOLD}${ChatColor.BOLD}HQ${ChatColor.GRAY}: ${ChatColor.YELLOW}${"${hq.blockX}, ${hq.blockZ}"}") + } + + toReturn.add("${ChatColor.GOLD}${ChatColor.BOLD}DTR${ChatColor.GRAY}: ${ChatColor.YELLOW}${targetFaction.getDTRDisplay()}${targetFaction.getDTRState().display}") + toReturn.add("${ChatColor.GOLD}${ChatColor.BOLD}Online${ChatColor.GRAY}: ${ChatColor.YELLOW}${targetFaction.onlineMembers}/${targetFaction.members.size}") + } + + } + + } + + if (toReturn.isNotEmpty()) { + toReturn.add(0,LINE) + toReturn.add(toReturn.size,LINE) + } + + return toReturn + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/engine/HCFTabAdapter.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/engine/HCFTabAdapter.kt new file mode 100644 index 0000000..ffca68c --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/engine/HCFTabAdapter.kt @@ -0,0 +1,207 @@ +package cc.fyre.hcf.map.engine + +import cc.fyre.hcf.faction.FactionHandler +import cc.fyre.hcf.faction.list.FactionList +import cc.fyre.hcf.faction.list.FactionListType +import cc.fyre.hcf.game.GameHandler +import cc.fyre.hcf.map.border.BorderHandler +import cc.fyre.hcf.map.sotw.SOTWHandler +import cc.fyre.hcf.statistic.StatisticHandler +import cc.fyre.hcf.statistic.impl.TabOption +import cc.fyre.hcf.statistic.type.DeathsStatistic +import cc.fyre.hcf.statistic.type.KillsStatistic +import cc.fyre.hcf.statistic.type.setting.TabListSetting +import cc.fyre.shard.tab.adapter.TabAdapter +import cc.fyre.shard.tab.data.TabSlot +import cc.fyre.shard.util.TimeUtil +import cc.fyre.shard.util.player.PlayerUtil +import com.google.common.collect.HashBasedTable +import com.google.common.collect.Table +import org.bukkit.Bukkit +import org.bukkit.ChatColor +import org.bukkit.enchantments.Enchantment +import org.bukkit.entity.Player + +/** + * @project hcf + * + * @date 01/12/2020 + * @author xanderume@gmail.com + */ +object HCFTabAdapter : TabAdapter { + + private var lastMemberUpdate = 0L + + override fun getSlots(player: Player):Table { + + val toReturn = HashBasedTable.create() + + toReturn.put(1,0,TabSlot("${ChatColor.GOLD}${ChatColor.BOLD}Fyre")) + + var y = 0 + + val faction = FactionHandler.getFactionByPlayer(player.uniqueId) + + if (faction != null) { + toReturn.put(0,y++,TabSlot("${ChatColor.GOLD}HQ:")) + toReturn.put(0,y++,TabSlot("${ChatColor.GRAY}${if (faction.getHQ() == null) "Not Set" else "${faction.getHQ()!!.blockX}, ${faction.getHQ()!!.blockZ}"}")) + + y++ + + toReturn.put(0,y++,TabSlot("${ChatColor.GOLD}Faction Info:")) + toReturn.put(0,y++,TabSlot("${ChatColor.GRAY}DTR: ${faction.getDTRDisplay()}${faction.getDTRState().display}")) + toReturn.put(0,y++,TabSlot("${ChatColor.GRAY}Online: ${faction.onlineMembers}/${faction.members.size}")) + toReturn.put(0,y++,TabSlot("${ChatColor.GRAY}Balance: $${faction.balance}")) + + y++ + + var z = 3 + + toReturn.put(1,z++,TabSlot("${ChatColor.GOLD}${faction.name}:")) + + if ((System.currentTimeMillis() - this.lastMemberUpdate) > MEMBER_REFRESH_RATE) { + + for (member in faction.members.values.filter{it.online}) { + toReturn.put(1,z++,TabSlot("${ChatColor.GRAY}${member.role.prefix}${ChatColor.DARK_GREEN}${member.getUsername()}")) + } + + } + + } + + + toReturn.put(0,y++,TabSlot("${ChatColor.GOLD}Player Info:")) + toReturn.put(0,y++,TabSlot("${ChatColor.GRAY}Kills: ${StatisticHandler.getStatistic(player.uniqueId,KillsStatistic).getValue()}")) + toReturn.put(0,y++,TabSlot("${ChatColor.GRAY}Deaths: ${StatisticHandler.getStatistic(player.uniqueId,DeathsStatistic).getValue()}")) + + y++ + + toReturn.put(0,y++,TabSlot("${ChatColor.GOLD}Your Location:")) + toReturn.put(0,y++,TabSlot(FactionHandler.getFactionByLocation(player.location).getDisplayName(player))) + toReturn.put(0,y++,TabSlot("${ChatColor.GRAY}${player.location.blockX}, ${player.location.blockZ} [${this.getCardinalDirection(player)}]")) + + y++ + + val event = FactionHandler.getActiveGameFactions().firstOrNull() + + if (event != null) { + event.getTabLayout(player).forEach{toReturn.put(0,y++,TabSlot(it))} + } else { + + toReturn.put(0,y++,TabSlot("${ChatColor.GOLD}Next Event:")) + + val nextGame = GameHandler.getNextGame() + val nextGameSchedule = GameHandler.getNextGameSchedule() + + if (nextGameSchedule != null) { + toReturn.put(0,y++,TabSlot(nextGame?.getDisplayName(player) ?: "N/A")) + toReturn.put(0,y++,TabSlot("${ChatColor.GRAY}${TimeUtil.formatIntoMMSS(System.currentTimeMillis() - nextGameSchedule.toLong())}")) + } else { + toReturn.put(0,y++,TabSlot("${ChatColor.RED}Undefined")) + } + + } + + val legacy = PlayerUtil.isLegacy(player) + + if (legacy) { + + + val option = StatisticHandler.getStatistic(player.uniqueId,TabListSetting).getValue() + + if (option == TabOption.DETAILED) { + this.addInfoSlots(player,2,toReturn) + } else if (option == TabOption.FACTION_LIST) { + this.addFactionList(player,2,toReturn) + } + + } else { + this.addInfoSlots(player,2,toReturn) + this.addFactionList(player,3,toReturn) + } + + + return toReturn + } + + private fun getCardinalDirection(player: Player):String { + + var rot = (player.location.yaw - 90) % 360.toDouble() + + if (rot < 0) { + rot += 360.0 + } + + return this.getDirection(rot) + } + + private fun getDirection(rot: Double):String { + return if (0 <= rot && rot < 22.5) { + "W" + } else if (22.5 <= rot && rot < 67.5) { + "NW" + } else if (67.5 <= rot && rot < 112.5) { + "N" + } else if (112.5 <= rot && rot < 157.5) { + "NE" + } else if (157.5 <= rot && rot < 202.5) { + "E" + } else if (202.5 <= rot && rot < 247.5) { + "SE" + } else if (247.5 <= rot && rot < 292.5) { + "S" + } else if (292.5 <= rot && rot < 337.5) { + "SW" + } else if (337.5 <= rot && rot < 360.0) { + "W" + } else { + "null" + } + } + + private fun addInfoSlots(player: Player,x: Int,slots: Table) { + + var y = 0 + + slots.put(x,y++,TabSlot("${ChatColor.GOLD}Map Kit:")) + slots.put(x,y++,TabSlot("${ChatColor.GRAY}Prot ${Enchantment.PROTECTION_ENVIRONMENTAL.maxLevel}, Sharp ${Enchantment.DAMAGE_ALL.maxLevel}")) + + y++ + + slots.put(x,y++,TabSlot("${ChatColor.GOLD}Border:")) + slots.put(x,y++,TabSlot("${ChatColor.GRAY}${BorderHandler.getBorder()}")) + + y++ + + slots.put(x,y++,TabSlot("${ChatColor.GOLD}Players Online:")) + slots.put(x,y++,TabSlot("${ChatColor.GRAY}${Bukkit.getServer().onlinePlayers.size}")) + + + if (SOTWHandler.isActive()) { + y++ + + slots.put(x,y++,TabSlot("${ChatColor.GOLD}SOTW:")) + slots.put(x,y,TabSlot("${ChatColor.GRAY}${TimeUtil.formatIntoHHMMSS(SOTWHandler.getRemainingMillis())}")) + } + + } + + private fun addFactionList(player: Player,x: Int,slots: Table) { + + var y = 0 + + slots.put(x,y++,TabSlot("${ChatColor.GOLD}Faction List:")) + + for (faction in FactionList.take(FactionListType.MAX_ONLINE,19)) { + + if (y > 20) { + break + } + + slots.put(x,y++,TabSlot("${faction.getDisplayName(player)}${ChatColor.GRAY} (${faction.onlineMembers})")) + } + + } + + const val MEMBER_REFRESH_RATE = 2000L +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/eotw/EOTWHandler.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/eotw/EOTWHandler.kt new file mode 100644 index 0000000..1439252 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/eotw/EOTWHandler.kt @@ -0,0 +1,30 @@ +package cc.fyre.hcf.map.eotw + +import cc.fyre.hcf.map.MapHandler +import java.util.* + +object EOTWHandler { + + private var active = false + + fun isActive():Boolean { + return this.active + } + + fun setActive(value: Boolean) { + this.active = value + } + + fun isWhitelisted(uuid: UUID):Boolean { + return MapHandler.config.eotwWhitelist.contains(uuid) + } + + fun addToWhitelist(uuid: UUID) { + MapHandler.config.eotwWhitelist.add(uuid) + } + + fun removeFromWhitelist(uuid: UUID) { + MapHandler.config.eotwWhitelist.remove(uuid) + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/eotw/command/EOTWDeathbansCommand.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/eotw/command/EOTWDeathbansCommand.kt new file mode 100644 index 0000000..1c950a4 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/eotw/command/EOTWDeathbansCommand.kt @@ -0,0 +1,49 @@ +package cc.fyre.hcf.map.eotw.command + +import cc.fyre.shard.command.data.command.Command +import cc.fyre.hcf.HCF +import cc.fyre.hcf.death.DeathRepository +import cc.fyre.hcf.map.eotw.EOTWHandler +import cc.fyre.hcf.timer.TimerHandler +import cc.fyre.hcf.timer.TimerType +import cc.fyre.shard.command.CommandHandler +import org.bukkit.Bukkit +import org.bukkit.ChatColor +import org.bukkit.Sound +import org.bukkit.command.CommandSender +import org.bukkit.entity.Player + +/** + * @project hcf + * + * @date 16/09/2020 + * @author xanderume@gmail.com + */ +object EOTWDeathbansCommand { + + @JvmStatic + @Command(names = ["eotw deathbans","eotw wipedeathbans"],async = true,permission = "hcf.command.eotw.deathbans") + fun execute(sender: CommandSender) { + + if (sender is Player && !EOTWHandler.isWhitelisted(sender.uniqueId)) { + sender.sendMessage(CommandHandler.NO_PERMISSION) + return + } + + DeathRepository.deleteAll() + + Bukkit.getServer().onlinePlayers.forEach{ + it.playSound(it.location,Sound.WITHER_SPAWN,1.0F,1.0F) + TimerHandler.removeTimer(it.uniqueId,TimerType.PVP_TIMER) + } + + HCF.instance.server.broadcastMessage(ChatColor.RED.toString() + "███████") + HCF.instance.server.broadcastMessage(ChatColor.RED.toString() + "█" + ChatColor.DARK_RED + "█████" + ChatColor.RED + "█" + " " + ChatColor.DARK_RED + "[Pre-EOTW]") + HCF.instance.server.broadcastMessage(ChatColor.RED.toString() + "█" + ChatColor.DARK_RED + "█" + ChatColor.RED + "█████" + " " + ChatColor.RED.toString() + ChatColor.BOLD + "EOTW is about to commence.") + HCF.instance.server.broadcastMessage(ChatColor.RED.toString() + "█" + ChatColor.DARK_RED + "████" + ChatColor.RED + "██" + " " + ChatColor.RED + "PvP Protection is disabled.") + HCF.instance.server.broadcastMessage(ChatColor.RED.toString() + "█" + ChatColor.DARK_RED + "█" + ChatColor.RED + "█████" + " " + ChatColor.RED + "All players have been un-deathbanned.") + HCF.instance.server.broadcastMessage(ChatColor.RED.toString() + "█" + ChatColor.DARK_RED + "█████" + ChatColor.RED + "█" + " " + ChatColor.RED + "All deathbans are now permanent.") + HCF.instance.server.broadcastMessage(ChatColor.RED.toString() + "███████") + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/eotw/command/EOTWFFACommand.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/eotw/command/EOTWFFACommand.kt new file mode 100644 index 0000000..2cf8d1b --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/eotw/command/EOTWFFACommand.kt @@ -0,0 +1,87 @@ +package cc.fyre.hcf.map.eotw.command + +import cc.fyre.shard.command.data.command.Command +import cc.fyre.hcf.HCF +import cc.fyre.hcf.map.eotw.EOTWHandler +import cc.fyre.shard.command.CommandHandler +import org.bukkit.Bukkit +import org.bukkit.ChatColor +import org.bukkit.command.CommandSender +import org.bukkit.conversations.* +import org.bukkit.entity.Player +import org.bukkit.potion.PotionEffect +import org.bukkit.potion.PotionEffectType + +/** + * @project hcf + * + * @date 16/09/2020 + * @author xanderume@gmail.com + */ +object EOTWFFACommand { + + @JvmStatic + @Command(names = ["eotw ffa"],permission = "hcf.command.eotw.ffa") + fun execute(sender: CommandSender) { + + if (sender !is Player) { + return + } + + if (!EOTWHandler.isWhitelisted(sender.uniqueId)) { + sender.sendMessage(CommandHandler.NO_PERMISSION) + return + } + + sender.beginConversation(ConversationFactory(HCF.instance).withModality(true).withPrefix(NullConversationPrefix()).withFirstPrompt(object : StringPrompt() { + + override fun getPromptText(context: ConversationContext): String { + return "${ChatColor.GREEN}Are you sure you want to enter FFA mode? This will start a countdown that cannot be cancelled. Type yes or no to confirm." + } + + override fun acceptInput(context: ConversationContext,input: String): Prompt { + + if (input.equals("no",true)) { + context.forWhom.sendRawMessage("${ChatColor.GREEN}FFA initation aborted.") + return Prompt.END_OF_CONVERSATION + } + + if (!input.equals("yes",true)) { + context.forWhom.sendRawMessage("${ChatColor.GREEN}Unrecognized response. Type ${ChatColor.AQUA}yes${ChatColor.GREEN} to confirm or ${ChatColor.RED}no${ChatColor.YELLOW} to quit.") + return Prompt.END_OF_CONVERSATION + } + + Bukkit.getServer().scheduler.runTask(HCF.instance) { + HCF.instance.server.broadcastMessage(ChatColor.RED.toString() + "███████") + HCF.instance.server.broadcastMessage(ChatColor.RED.toString() + "█" + ChatColor.GOLD + "█████" + ChatColor.RED + "█") + HCF.instance.server.broadcastMessage(ChatColor.RED.toString() + "█" + ChatColor.GOLD + "█" + ChatColor.RED + "█████" + " " + ChatColor.DARK_RED + "[EOTW]") + HCF.instance.server.broadcastMessage(ChatColor.RED.toString() + "█" + ChatColor.GOLD + "████" + ChatColor.RED + "██" + " " + ChatColor.RED.toString() + ChatColor.BOLD + "EOTW " + ChatColor.GOLD.toString() + ChatColor.BOLD + "FFA" + ChatColor.RED.toString() + ChatColor.BOLD + " will commence in: 5:00.") + HCF.instance.server.broadcastMessage(ChatColor.RED.toString() + "█" + ChatColor.GOLD + "█" + ChatColor.RED + "█████" + " " + ChatColor.RED.toString() + "If you ally, you will be punished.") + HCF.instance.server.broadcastMessage(ChatColor.RED.toString() + "█" + ChatColor.GOLD + "█" + ChatColor.RED + "█████") + HCF.instance.server.broadcastMessage(ChatColor.RED.toString() + "███████") + } + + Bukkit.getServer().scheduler.runTaskLater(HCF.instance,{ + HCF.instance.server.broadcastMessage(ChatColor.RED.toString() + "███████") + HCF.instance.server.broadcastMessage(ChatColor.RED.toString() + "█" + ChatColor.GOLD + "█████" + ChatColor.RED + "█") + HCF.instance.server.broadcastMessage(ChatColor.RED.toString() + "█" + ChatColor.GOLD + "█" + ChatColor.RED + "█████" + " " + ChatColor.DARK_RED + "[EOTW]") + HCF.instance.server.broadcastMessage(ChatColor.RED.toString() + "█" + ChatColor.GOLD + "████" + ChatColor.RED + "██" + " " + ChatColor.RED.toString() + ChatColor.BOLD + "EOTW " + ChatColor.GOLD.toString() + ChatColor.BOLD + "FFA" + ChatColor.RED.toString() + ChatColor.BOLD + " has now commenced!") + HCF.instance.server.broadcastMessage(ChatColor.RED.toString() + "█" + ChatColor.GOLD + "█" + ChatColor.RED + "█████" + " " + ChatColor.RED + "Good luck and have fun!") + HCF.instance.server.broadcastMessage(ChatColor.RED.toString() + "█" + ChatColor.GOLD + "█" + ChatColor.RED + "█████") + HCF.instance.server.broadcastMessage(ChatColor.RED.toString() + "███████") + + Bukkit.getServer().onlinePlayers.forEach{ + it.addPotionEffect(PotionEffect(PotionEffectType.SPEED,Integer.MAX_VALUE,1)) + it.addPotionEffect(PotionEffect(PotionEffectType.INVISIBILITY,Integer.MAX_VALUE,0)) + it.addPotionEffect(PotionEffect(PotionEffectType.FIRE_RESISTANCE,Integer.MAX_VALUE,0)) + } + + }, 5 * 60 * 20.toLong()) + + return Prompt.END_OF_CONVERSATION + } + }).withLocalEcho(false).withEscapeSequence("/no").withTimeout(10).thatExcludesNonPlayersWithMessage("Go away evil console!").buildConversation(sender)) + + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/eotw/command/EOTWStartCommand.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/eotw/command/EOTWStartCommand.kt new file mode 100644 index 0000000..5cb3988 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/eotw/command/EOTWStartCommand.kt @@ -0,0 +1,47 @@ +package cc.fyre.hcf.map.eotw.command + +import cc.fyre.shard.command.data.command.Command +import cc.fyre.hcf.HCF +import cc.fyre.hcf.map.eotw.EOTWHandler +import cc.fyre.shard.command.CommandHandler +import org.bukkit.ChatColor +import org.bukkit.Sound +import org.bukkit.command.CommandSender +import org.bukkit.entity.Player + +/** + * @project hcf + * + * @date 16/09/2020 + * @author xanderume@gmail.com + */ +object EOTWStartCommand { + + @JvmStatic + @Command(names = ["eotw start"],permission = "hcf.command.eotw.start") + fun execute(sender: CommandSender) { + + if (sender is Player && EOTWHandler.isWhitelisted(sender.uniqueId)) { + sender.sendMessage(CommandHandler.NO_PERMISSION) + return + } + + EOTWHandler.setActive(!EOTWHandler.isActive()) + + if (!EOTWHandler.isActive()) { + sender.sendMessage("${ChatColor.RED}EOTW is no longer active.") + return + } + + HCF.instance.server.broadcastMessage(ChatColor.RED.toString() + "███████") + HCF.instance.server.broadcastMessage(ChatColor.RED.toString() + "█" + ChatColor.DARK_RED + "█████" + ChatColor.RED + "█") + HCF.instance.server.broadcastMessage(ChatColor.RED.toString() + "█" + ChatColor.DARK_RED + "█" + ChatColor.RED + "█████" + " " + ChatColor.DARK_RED + "[EOTW]") + HCF.instance.server.broadcastMessage(ChatColor.RED.toString() + "█" + ChatColor.DARK_RED + "████" + ChatColor.RED + "██" + " " + ChatColor.RED.toString() + ChatColor.BOLD + "EOTW has commenced.") + HCF.instance.server.broadcastMessage(ChatColor.RED.toString() + "█" + ChatColor.DARK_RED + "█" + ChatColor.RED + "█████" + " " + ChatColor.RED + "All Safe-Zones are now Deathban.") + HCF.instance.server.broadcastMessage(ChatColor.RED.toString() + "█" + ChatColor.DARK_RED + "█████" + ChatColor.RED + "█") + HCF.instance.server.broadcastMessage(ChatColor.RED.toString() + "███████") + + HCF.instance.server.onlinePlayers.forEach{it.playSound(it.location,Sound.WITHER_SPAWN,1.0F,1.0F)} + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/eotw/command/EOTWTeleportCommand.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/eotw/command/EOTWTeleportCommand.kt new file mode 100644 index 0000000..fdaef67 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/eotw/command/EOTWTeleportCommand.kt @@ -0,0 +1,36 @@ +package cc.fyre.hcf.map.eotw.command + +import cc.fyre.shard.command.data.command.Command +import cc.fyre.hcf.HCF +import cc.fyre.hcf.map.eotw.EOTWHandler +import cc.fyre.shard.command.CommandHandler +import org.bukkit.ChatColor +import org.bukkit.command.CommandSender +import org.bukkit.entity.Player + +/** + * @project hcf + * + * @date 16/09/2020 + * @author xanderume@gmail.com + */ +object EOTWTeleportCommand { + + @JvmStatic + @Command(names = ["eotw teleportall","eotw tpall"],permission = "hcf.command.eotw.teleportall") + fun execute(sender: Player) { + + if (!EOTWHandler.isWhitelisted(sender.uniqueId)) { + sender.sendMessage(CommandHandler.NO_PERMISSION) + return + } + + if (!EOTWHandler.isActive()) { + sender.sendMessage("${ChatColor.RED}EOTW is not active.") + return + } + + HCF.instance.server.onlinePlayers.parallelStream().forEach{it.teleport(sender)} + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/eotw/command/EOTWUnclaimCommand.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/eotw/command/EOTWUnclaimCommand.kt new file mode 100644 index 0000000..bf48f91 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/eotw/command/EOTWUnclaimCommand.kt @@ -0,0 +1,68 @@ +package cc.fyre.hcf.map.eotw.command + +import cc.fyre.shard.command.data.command.Command +import cc.fyre.hcf.faction.FactionHandler +import cc.fyre.hcf.faction.claim.ClaimHandler +import cc.fyre.hcf.map.eotw.EOTWHandler +import cc.fyre.shard.command.CommandHandler +import org.bukkit.Bukkit +import org.bukkit.ChatColor +import org.bukkit.command.CommandSender +import org.bukkit.entity.Player + +/** + * @project hcf + * + * @date 16/09/2020 + * @author xanderume@gmail.com + */ +object EOTWUnclaimCommand { + + @JvmStatic + @Command(names = ["eotw wipeclaims"],permission = "hcf.command.eotw.wipeclaims") + fun execute(sender: CommandSender) { + + if (sender is Player && !EOTWHandler.isWhitelisted(sender.uniqueId)) { + sender.sendMessage(CommandHandler.NO_PERMISSION) + return + } + + if (!EOTWHandler.isActive()) { + sender.sendMessage("${ChatColor.RED}EOTW is not active.") + return + } + + FactionHandler.getAllPlayerFactions().forEach{ + it.setHQ(null) + it.removeClaims(*it.claims.toTypedArray()) + } + + val iterator = ClaimHandler.getAllSelections().iterator() + + while (iterator.hasNext()) { + + val player = Bukkit.getServer().getPlayer(iterator.next().key) + + if (player != null) { + ClaimHandler.destroySelection(player,removeItem = true) + } else { + iterator.remove() + } + + } + /* + this.cache.values.flatten().mapNotNull{it.findFaction()}.filterIsInstance().forEach{it.setHQ(null)} + this.cache.entries.removeIf{it.value.mapNotNull{claim -> claim.findFaction()}.any{faction -> faction is PlayerFaction }} + + this.service.cache.clear() + this.selections.keys.mapNotNull{this.instance.server.getPlayer(it)}.forEach{ + it.inventory.removeItem(ClaimSelection.ITEM) + PillarHandler.removePillars(it, PillarType.CLAIM_SELECTION) + } + + this.repository.collection.drop()*/ + + //ClaimHandler.wipe() + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/eotw/listener/EOTWListener.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/eotw/listener/EOTWListener.kt new file mode 100644 index 0000000..6b70705 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/eotw/listener/EOTWListener.kt @@ -0,0 +1,39 @@ +package cc.fyre.hcf.map.eotw.listener + +import cc.fyre.hcf.HCF +import org.bukkit.ChatColor +import org.bukkit.event.EventHandler +import org.bukkit.event.EventPriority +import org.bukkit.event.Listener + +/** + * @project hcf + * + * @date 19/12/2020 + * @author xanderume@gmail.com + */ +object EOTWListener : Listener { + + /*TODO + @EventHandler(priority = EventPriority.LOWEST) + private fun onKitMenu(event: KitMenuEvent) { + + if (!this.instance.engineHandler.isEOTW()) { + return + } + + event.player.sendMessage("${ChatColor.RED}You cannot use kits during EOTW!") + event.isCancelled = true + } + + @EventHandler(priority = EventPriority.LOWEST) + private fun onKitUse(event: KitUseEvent) { + + if (!this.instance.engineHandler.isEOTW()) { + return + } + + event.player.sendMessage("${ChatColor.RED}You cannot use kits during EOTW!") + event.isCancelled = true + }*/ +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/listener/BookListener.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/listener/BookListener.kt new file mode 100644 index 0000000..f2d0014 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/listener/BookListener.kt @@ -0,0 +1,34 @@ +package cc.fyre.hcf.map.listener + +import org.bukkit.ChatColor +import org.bukkit.Material +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.player.PlayerInteractEvent + +object BookListener : Listener { + + @EventHandler(priority = EventPriority.NORMAL) + private fun onPlayerInteract(event: PlayerInteractEvent) { + + if (event.action != Action.LEFT_CLICK_BLOCK) { + return + } + + if (event.clickedBlock == null) { + return + } + + if (event.item == null || event.item.type != Material.ENCHANTED_BOOK) { + return + } + + event.item.type = Material.BOOK + event.player.sendMessage("${ChatColor.GREEN}You reverted this book to its original form!") + event.isCancelled = true + } + + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/listener/DiamondListener.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/listener/DiamondListener.kt new file mode 100644 index 0000000..9483dc3 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/listener/DiamondListener.kt @@ -0,0 +1,96 @@ +package cc.fyre.hcf.map.listener + +import cc.fyre.hcf.HCF +import cc.fyre.hcf.statistic.StatisticHandler +import cc.fyre.hcf.statistic.type.setting.FoundDiamondSetting +import org.bukkit.Bukkit +import org.bukkit.ChatColor +import org.bukkit.Material +import org.bukkit.block.Block +import org.bukkit.block.BlockFace +import org.bukkit.event.EventHandler +import org.bukkit.event.EventPriority +import org.bukkit.event.Listener +import org.bukkit.event.block.BlockBreakEvent +import org.bukkit.event.block.BlockPlaceEvent +import org.bukkit.metadata.FixedMetadataValue + +object DiamondListener : Listener { + + private val METADATA = "PLACED_DIAMOND_ORE" + private val METADATA_VALUE = FixedMetadataValue(HCF.instance,true) + + private val BLOCK_FACES = arrayOf( + BlockFace.NORTH, + BlockFace.SOUTH, + BlockFace.EAST, + BlockFace.WEST, + BlockFace.NORTH_EAST, + BlockFace.NORTH_WEST, + BlockFace.SOUTH_EAST, + BlockFace.SOUTH_WEST, + BlockFace.UP, + BlockFace.DOWN + ) + + @EventHandler(priority = EventPriority.MONITOR) + private fun onBlockPlace(event: BlockPlaceEvent) { + + if (event.isCancelled) { + return + } + + if (event.block.type != Material.DIAMOND_ORE) { + return + } + + event.block.setMetadata(METADATA,METADATA_VALUE) + } + + @EventHandler(priority = EventPriority.HIGHEST) + private fun onBlockBreak(event: BlockBreakEvent) { + + if (event.isCancelled) { + return + } + + if (event.block.type != Material.DIAMOND_ORE) { + return + } + + if (event.block.hasMetadata(METADATA)) { + return + } + + val diamonds = this.count(event.block) + + val message = "[FD] ${ChatColor.AQUA}${event.player.name} found $diamonds diamond${if (diamonds == 1) "" else "s"}." + + Bukkit.getServer().onlinePlayers + .filter{StatisticHandler.getStatistic(it.uniqueId, FoundDiamondSetting).getValue()} + .forEach{it.sendMessage(message)} + + } + + private fun count(block: Block): Int { + var diamonds = 1 + + for (face in BLOCK_FACES) { + + val relative = block.getRelative(face) + + if (relative.type != Material.DIAMOND_ORE || relative.hasMetadata(METADATA)) { + continue + } + + + relative.setMetadata(METADATA,METADATA_VALUE) + + diamonds += this.count(block) + } + + + return diamonds + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/listener/EXPListener.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/listener/EXPListener.kt new file mode 100644 index 0000000..b5d4005 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/listener/EXPListener.kt @@ -0,0 +1,113 @@ +package cc.fyre.hcf.map.listener + +import cc.fyre.hcf.map.MapHandler +import org.bukkit.enchantments.Enchantment +import org.bukkit.entity.Player +import org.bukkit.event.EventHandler +import org.bukkit.event.EventPriority +import org.bukkit.event.Listener +import org.bukkit.event.block.BlockBreakEvent +import org.bukkit.event.entity.EntityDeathEvent +import kotlin.math.ceil +import kotlin.math.max + +/** + * @project hcf + * + * @date 30/08/2020 + * @author xanderume@gmail.com + */ +object EXPListener : Listener { + + @EventHandler(priority = EventPriority.MONITOR) + private fun onEntityDeath(event: EntityDeathEvent) { + + if (event.entity.killer == null || event.entity.killer.itemInHand == null) { + return + } + + val multiplier = if (event.entity.killer.itemInHand.containsEnchantment(Enchantment.LOOT_BONUS_MOBS)) { + MapHandler.EXP_MULTIPLIERS[0]!! + } else { + + var level: Double + + event.entity.killer.itemInHand.getEnchantmentLevel(Enchantment.LOOT_BONUS_MOBS).also{ + + val enchantLevel = max(it,0) + + if (enchantLevel > MapHandler.EXP_MULTIPLIER_MAX.key) { + MapHandler.EXP_MULTIPLIER_MAX.key + } + + level = MapHandler.EXP_MULTIPLIERS[enchantLevel]!! + } + + level + } + + event.droppedExp = ceil(event.droppedExp * multiplier).toInt() + } + + @EventHandler(priority = EventPriority.MONITOR) + private fun onBlockBreak(event: BlockBreakEvent) { + + if (event.isCancelled) { + return + } + + if (event.player.itemInHand == null) { + return + } + + if (!MapHandler.ORE_TYPES.contains(event.block.type)) { + return + } + + val multiplier = if (event.player.itemInHand.containsEnchantment(Enchantment.LOOT_BONUS_BLOCKS)) { + MapHandler.EXP_MULTIPLIERS[0]!! + } else { + + var level: Double + + event.player.itemInHand.getEnchantmentLevel(Enchantment.LOOT_BONUS_BLOCKS).also{ + + val enchantLevel = max(it,0) + + if (enchantLevel > MapHandler.EXP_MULTIPLIER_MAX.key) { + MapHandler.EXP_MULTIPLIER_MAX.key + } + + level = MapHandler.EXP_MULTIPLIERS[enchantLevel]!! + } + + level + } + + event.expToDrop = ceil(event.expToDrop * multiplier).toInt() + } + + + @EventHandler(priority = EventPriority.MONITOR) + private fun onBlockBreak2(event: BlockBreakEvent) { + + if (event.isCancelled) { + return + } + + event.player.giveExp(event.expToDrop) + event.expToDrop = 0 + } + + @EventHandler(priority = EventPriority.MONITOR) + private fun onEntityDeath2(event: EntityDeathEvent) { + + if (event.entity.killer == null || event.entity is Player) { + return + } + + event.entity.killer.giveExp(event.droppedExp) + event.droppedExp = 0 + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/listener/EndListener.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/listener/EndListener.kt new file mode 100644 index 0000000..c58ffbd --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/listener/EndListener.kt @@ -0,0 +1,94 @@ +package cc.fyre.hcf.map.listener + +import cc.fyre.hcf.map.MapHandler +import cc.fyre.Forge +import cc.fyre.handler.MovementHandler +import net.minecraft.server.v1_7_R4.PacketPlayInFlying +import org.bukkit.* +import org.bukkit.entity.Player +import org.bukkit.event.EventHandler +import org.bukkit.event.EventPriority +import org.bukkit.event.Listener +import org.bukkit.event.block.BlockBreakEvent +import org.bukkit.event.block.BlockPlaceEvent +import org.bukkit.event.player.PlayerBucketFillEvent +import org.bukkit.event.player.PlayerPortalEvent + +object EndListener : Listener, MovementHandler { + + init { + Forge.INSTANCE.addMovementHandler(this) + } + + override fun handleUpdateRotation(player: Player, to: Location, from: Location, packet: PacketPlayInFlying?) {} + + override fun handleUpdateLocation(player: Player, to: Location, from: Location, packet: PacketPlayInFlying?) { + + if (to.world.environment != World.Environment.THE_END) { + return + } + + if (to.block.type != Material.STATIONARY_WATER && to.block.type != Material.WATER) { + return + } + + player.teleport(MapHandler.getEndExit()) + } + + @EventHandler(priority = EventPriority.MONITOR) + private fun onPlayerPortal(event: PlayerPortalEvent) { + + if (event.from.world.environment != World.Environment.NORMAL) { + return + } + + if (event.to.world.environment != World.Environment.THE_END) { + return + } + + event.to = event.to.world.spawnLocation + } + + @EventHandler(priority = EventPriority.NORMAL) + private fun onBlockPlace(event: BlockPlaceEvent) { + + if (event.player.world.environment != World.Environment.THE_END) { + return + } + + if (event.player.isOp && event.player.gameMode == GameMode.CREATIVE) { + return + } + + event.isCancelled = true + } + + @EventHandler(priority = EventPriority.NORMAL) + private fun onBlockBreak(event: BlockBreakEvent) { + + if (event.player.world.environment != World.Environment.THE_END) { + return + } + + if (event.player.isOp && event.player.gameMode == GameMode.CREATIVE) { + return + } + + event.isCancelled = true + } + + @EventHandler(priority = EventPriority.NORMAL) + private fun onPlayerBucketFill(event: PlayerBucketFillEvent) { + + if (event.player.world.environment != World.Environment.THE_END) { + return + } + + if (event.player.isOp && event.player.gameMode == GameMode.CREATIVE) { + return + } + + event.isCancelled = true + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/listener/GeneralListener.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/listener/GeneralListener.kt new file mode 100644 index 0000000..2dd9c9e --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/listener/GeneralListener.kt @@ -0,0 +1,86 @@ +package cc.fyre.hcf.map.listener + +import cc.fyre.hcf.map.MapHandler +import org.bukkit.ChatColor +import org.bukkit.Material +import org.bukkit.block.BlockFace +import org.bukkit.block.CreatureSpawner +import org.bukkit.craftbukkit.v1_7_R4.entity.CraftArrow +import org.bukkit.entity.* +import org.bukkit.event.EventHandler +import org.bukkit.event.EventPriority +import org.bukkit.event.Listener +import org.bukkit.event.block.BlockPlaceEvent +import org.bukkit.event.entity.* +import org.bukkit.event.player.PlayerJoinEvent +import org.bukkit.event.player.PlayerQuitEvent +import org.bukkit.event.world.SpawnChangeEvent + +object GeneralListener : Listener { + + @EventHandler(priority = EventPriority.NORMAL) + private fun onPlayerJoin(event: PlayerJoinEvent) { + event.joinMessage = null + event.player.walkSpeed = 0.2F + + if (event.player.hasPlayedBefore()) { + return + } + + event.player.teleport(MapHandler.SPAWN_LOCATION) + event.player.inventory.addItem(*MapHandler.STARTER_ITEMS) + } + + @EventHandler(priority = EventPriority.NORMAL) + private fun onPlayerQuit(event: PlayerQuitEvent) { + event.quitMessage = null + } + + @EventHandler(priority = EventPriority.MONITOR) + private fun onSpawnChange(event: SpawnChangeEvent) { + MapHandler.SPAWN_LOCATION = event.world.spawnLocation + .clone() + .add(0.5,0.0,0.5) + } + + @EventHandler(priority = EventPriority.NORMAL) + private fun onBlockPlace(event: BlockPlaceEvent) { + + if (event.isCancelled) { + return + } + + if (event.player.itemInHand.type != Material.MOB_SPAWNER) { + return + } + + if (!event.player.itemInHand.hasItemMeta() || !event.player.itemInHand.itemMeta.hasDisplayName() || !event.itemInHand.itemMeta.displayName.startsWith( + ChatColor.RED.toString())) { + return + } + + val spawner = event.block.state as CreatureSpawner + + spawner.spawnedType = EntityType.valueOf(ChatColor.stripColor(event.player.itemInHand.itemMeta.displayName).replace(" Spawner","").uppercase().replace(" ".toRegex(),"_")) + spawner.update() + } + + @EventHandler(priority = EventPriority.NORMAL) + private fun onProjectileHit(event: ProjectileHitEvent) { + + if (event.entity !is Arrow) { + return + } + + if (event.entity.shooter is Player) { + return + } + + if ((event.entity as CraftArrow).handle.fromPlayer != 2) { + return + } + + event.entity.remove() + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/listener/GlitchListener.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/listener/GlitchListener.kt new file mode 100644 index 0000000..31b65b9 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/listener/GlitchListener.kt @@ -0,0 +1,142 @@ +package cc.fyre.hcf.map.listener + +import cc.fyre.handler.MovementHandler +import cc.fyre.hcf.HCF +import net.minecraft.server.v1_7_R4.PacketPlayInFlying +import org.bukkit.* +import org.bukkit.entity.* +import org.bukkit.event.EventHandler +import org.bukkit.event.EventPriority +import org.bukkit.event.Listener +import org.bukkit.event.block.BlockPistonExtendEvent +import org.bukkit.event.block.BlockPistonRetractEvent +import org.bukkit.event.block.BlockPlaceEvent +import org.bukkit.event.entity.EntitySpawnEvent +import org.bukkit.event.entity.ExplosionPrimeEvent +import org.bukkit.event.player.PlayerTeleportEvent +import org.bukkit.event.vehicle.VehicleEnterEvent +import org.bukkit.event.vehicle.VehicleMoveEvent +import org.bukkit.event.world.ChunkLoadEvent + +/** + * @project hcf + * + * @date 12/09/2020 + * @author xanderume@gmail.com + */ +object GlitchListener : Listener,MovementHandler { + + @EventHandler(priority = EventPriority.HIGHEST) + private fun onVehicleMove(event: VehicleMoveEvent) { + + if (event.from.blockX == event.to.blockX && event.from.blockZ == event.to.blockZ) { + return + } + + if (event.to.block.type != Material.FENCE_GATE) { + return + } + + if (event.vehicle.passenger is Player) { + (event.vehicle.passenger as Player).sendMessage("${ChatColor.RED}You cannot move a boat into a fence gate.") + } + + event.vehicle.teleport(event.from) + } + + @EventHandler(priority = EventPriority.NORMAL) + private fun onBlockPistonRetract(event: BlockPistonRetractEvent) { + + if (!event.block.type.name.contains("RAIL")) { + return + } + + event.isCancelled = true + } + + @EventHandler(priority = EventPriority.NORMAL) + private fun onBlockPistonExtend(event: BlockPistonExtendEvent) { + event.blocks.stream().filter{it.type.name.contains("RAIL")}.findFirst().ifPresent{event.isCancelled = true} + } + + @EventHandler(priority = EventPriority.NORMAL) + private fun onVehicleEnter(event: VehicleEnterEvent) { + + if (event.vehicle is Horse || event.vehicle is Minecart) { + return + } + + if (event.entered is Player) { + (event.entered as Player).sendMessage(ChatColor.RED.toString() + "You may not enter vehicles.") + } + + event.isCancelled = true + } + + @EventHandler(priority = EventPriority.NORMAL) + private fun onBlockPlace(event: BlockPlaceEvent) { + + if (event.player.gameMode == GameMode.CREATIVE || event.player.world.environment != World.Environment.NETHER) { + return + } + + if (event.block.type != Material.MOB_SPAWNER) { + return + } + + event.isCancelled = true + event.player.sendMessage("${ChatColor.RED}You cannot place spawners in the nether.") + } + + @EventHandler(priority = EventPriority.NORMAL) + private fun onMinecartSpawn(event: EntitySpawnEvent) { + + if (!(event.entityType == EntityType.MINECART_TNT || event.entityType == EntityType.MINECART_HOPPER || event.entityType == EntityType.MINECART_CHEST)) { + return + } + + event.isCancelled = true + } + + @EventHandler(priority = EventPriority.NORMAL) + private fun onMinecartExplode(event: ExplosionPrimeEvent) { + + if (event.entityType != EntityType.MINECART_TNT) { + return + } + + event.isCancelled = true + } + + @EventHandler(priority = EventPriority.NORMAL) + private fun onChunkLoad(event: ChunkLoadEvent) { + event.chunk.entities.filter{it.type == EntityType.MINECART_CHEST}.forEach{it.remove()} + } + + @EventHandler(priority = EventPriority.MONITOR) + private fun onPlayerTeleport(event: PlayerTeleportEvent) { + this.handleUpdateLocation(event.player,event.to,event.from,null) + } + + override fun handleUpdateRotation(player: Player, to: Location, from: Location, packet: PacketPlayInFlying?) {} + + override fun handleUpdateLocation(player: Player,to: Location,from: Location,packet: PacketPlayInFlying?) { + + if (from.blockX == to.blockX && from.blockZ == to.blockZ) { + return + } + + if (player.vehicle == null || player.vehicle !is Boat) { + return + } + + if (to.block.type != Material.FENCE_GATE) { + return + } + + player.vehicle.teleport(from) + + player.sendMessage("${ChatColor.RED}You cannot move a boat into a fence gate.") + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/listener/InventoryListener.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/listener/InventoryListener.kt new file mode 100644 index 0000000..d442875 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/listener/InventoryListener.kt @@ -0,0 +1,45 @@ +package cc.fyre.hcf.map.listener + +import cc.fyre.hcf.map.MapHandler +import cc.fyre.hcf.pvpclass.PvPClassHandler +import cc.fyre.hcf.pvpclass.type.MinerClass +import cc.fyre.hcf.statistic.StatisticHandler +import cc.fyre.hcf.statistic.type.setting.CobbleSetting +import org.bukkit.Material +import org.bukkit.event.EventHandler +import org.bukkit.event.EventPriority +import org.bukkit.event.Listener +import org.bukkit.event.block.BlockDropItemsEvent +import org.bukkit.inventory.ItemStack + +object InventoryListener : Listener { + + @EventHandler(priority = EventPriority.MONITOR) + private fun onBlockBreak(event: BlockDropItemsEvent) { + + if (event.player == null || event.player.itemInHand == null || !MapHandler.CUT_CLEAN_TOOLS.contains(event.player.itemInHand.type)) { + return + } + + event.toDrop.forEach{ + + var item = it.itemStack + + if (item.type == Material.COBBLESTONE + && PvPClassHandler.getPvPClassByPlayer(event.player.uniqueId) is MinerClass + && StatisticHandler.getStatistic(event.player.uniqueId, CobbleSetting).getValue()) { + return@forEach + } + + if (MapHandler.CUT_CLEAN_TYPES.containsKey(item.type)) { + item = ItemStack(MapHandler.CUT_CLEAN_TYPES[item.type]!!) + } + + event.player.inventory.addItem(item) + } + + event.toDrop.clear() + } + + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/listener/MobListener.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/listener/MobListener.kt new file mode 100644 index 0000000..b83aeac --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/listener/MobListener.kt @@ -0,0 +1,78 @@ +package cc.fyre.hcf.map.listener + +import cc.fyre.hcf.map.MapHandler +import org.bukkit.entity.* +import org.bukkit.event.EventHandler +import org.bukkit.event.EventPriority +import org.bukkit.event.Listener +import org.bukkit.event.entity.* + +object MobListener : Listener { + + @EventHandler(priority = EventPriority.NORMAL) + private fun onEntityExplode(event: EntityExplodeEvent) { + event.blockList().clear() + + if (event.entity !is Creeper) { + return + } + + event.isCancelled = true + } + + @EventHandler(priority = EventPriority.NORMAL) + private fun onEntityDamage(event: EntityDamageByEntityEvent) { + + if (!MapHandler.MOB_ATTACK_BLACKLIST.contains(event.damager.type)) { + return + } + + event.isCancelled = true + } + + @EventHandler(priority = EventPriority.NORMAL) + private fun onCreatureSpawn(event: CreatureSpawnEvent) { + + if (event.spawnReason != CreatureSpawnEvent.SpawnReason.NATURAL) { + return + } + + val entity = event.entity + + if (entity !is Skeleton) { + return + } + + if (entity.skeletonType != Skeleton.SkeletonType.WITHER) { + return + } + + event.isCancelled = true + } + + @EventHandler(priority = EventPriority.NORMAL) + private fun onEntitySpawn(event: EntitySpawnEvent) { + + if (event.entity !is Zombie) { + return + } + + event.isCancelled = true + } + + @EventHandler(priority = EventPriority.NORMAL) + private fun onCreeperPower(event: CreeperPowerEvent) { + event.isCancelled = true + } + + @EventHandler(priority = EventPriority.NORMAL) + private fun onEntityExplode(event: ExplosionPrimeEvent) { + + if (event.entity !is Creeper) { + return + } + + event.isCancelled = true + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/listener/NameTagListener.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/listener/NameTagListener.kt new file mode 100644 index 0000000..15aeede --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/listener/NameTagListener.kt @@ -0,0 +1,152 @@ +package cc.fyre.hcf.map.listener + +import cc.fyre.hcf.faction.event.* +import cc.fyre.hcf.faction.type.PlayerFaction +import cc.fyre.hcf.timer.TimerType +import cc.fyre.hcf.timer.event.TimerCreateEvent +import cc.fyre.hcf.timer.event.TimerExpireEvent +import cc.fyre.shard.nametag.NameTagHandler +import org.bukkit.Bukkit +import org.bukkit.event.EventHandler +import org.bukkit.event.EventPriority +import org.bukkit.event.Listener + +/** + * @project hcf + * + * @date 07/07/2020 + * @author xanderume@gmail.com + */ +object NameTagListener : Listener { + + @EventHandler(priority = EventPriority.MONITOR) + private fun onFactionCreate(event: FactionCreateEvent) { + + if (event.faction !is PlayerFaction) { + return + } + + event.faction.getOnlineMembers().first().also{NameTagHandler.update(it,it)} + } + + @EventHandler(priority = EventPriority.MONITOR) + private fun onFactionMemberAdd(event: FactionMemberAddEvent) { + NameTagHandler.updateAll(event.target,event.faction.getOnlineMembers()) + } + + @EventHandler(priority = EventPriority.MONITOR) + private fun onFactionMemberRemove(event: FactionMemberRemoveEvent) { + Bukkit.getServer().getPlayer(event.target)?.also{ + NameTagHandler.updateAll(it,event.faction.getOnlineMembers()) + } + } + + @EventHandler(priority = EventPriority.MONITOR) + private fun onFactionDisband(event: FactionDisbandEvent) { + + if (event.faction !is PlayerFaction) { + return + } + + event.faction.getOnlineMembers().also{ + it.forEach{member -> + NameTagHandler.updateAll(member,it) + } + } + + } + + @EventHandler(priority = EventPriority.MONITOR) + private fun onFactionFocus(event: FactionFocusEvent) { + + val members = event.sender.getOnlineMembers() + + if (event.target != null) { + NameTagHandler.update(event.target!!,members) + return + } + + if (event.faction == null) { + return + } + + event.faction!!.getOnlineMembers().also{ + members.forEach{member -> NameTagHandler.updateAll(member,it)} + } + } + + @EventHandler(priority = EventPriority.MONITOR) + private fun onFactionUnFocus(event: FactionUnFocusEvent) { + + val members = event.sender.getOnlineMembers() + + if (event.target != null) { + NameTagHandler.update(event.target!!,members) + return + } + + if (event.faction == null) { + return + } + + event.faction!!.getOnlineMembers().also{ + members.forEach{member -> NameTagHandler.updateAll(member,it)} + } + } + + @EventHandler(priority = EventPriority.MONITOR) + private fun onFactionAlly(event: FactionAllyEvent) { + + val members = event.sender.getOnlineMembers() + val targets = event.target.getOnlineMembers() + + members.forEach{NameTagHandler.updateAll(it,targets)} + targets.forEach{NameTagHandler.updateAll(it,members)} + } + + @EventHandler(priority = EventPriority.MONITOR) + private fun onFactionUnAlly(event: FactionUnAllyEvent) { + val members = event.sender.getOnlineMembers() + val targets = event.target.getOnlineMembers() + + members.forEach{NameTagHandler.updateAll(it,targets)} + targets.forEach{NameTagHandler.updateAll(it,members)} + } + + @EventHandler(priority = EventPriority.MONITOR) + private fun onArcherMark(event: TimerCreateEvent) { + + if (event.timer.type != TimerType.ARCHER_MARK) { + return + } + + Bukkit.getServer().getPlayer(event.uuid).also{NameTagHandler.updateAll(it,Bukkit.getServer().onlinePlayers)} + } + + @EventHandler(priority = EventPriority.MONITOR) + private fun onArcherMarkExpire(event: TimerExpireEvent) { + + if (event.timer.type != TimerType.ARCHER_MARK) { + return + } + + Bukkit.getServer().getPlayer(event.uuid).also{NameTagHandler.updateAll(it,Bukkit.getServer().onlinePlayers)} + } + + @EventHandler(priority = EventPriority.MONITOR) + private fun onFactionDTRUpdate(event: FactionDTRUpdateEvent) { + event.faction.getOnlineMembers().forEach{NameTagHandler.updateAll(it)} + } + + /*TODO + @EventHandler(priority = EventPriority.MONITOR) + private fun onSettingChange(event: SettingChangeEvent) { + + if (event.setting != Setting.FACTION_NAME_TAGS) { + return + } + + Shard.instance.nameTagHandler.update(event.player) + }*/ + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/listener/NetherListener.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/listener/NetherListener.kt new file mode 100644 index 0000000..84e59d6 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/listener/NetherListener.kt @@ -0,0 +1,88 @@ +package cc.fyre.hcf.map.listener + +import cc.fyre.hcf.HCF +import cc.fyre.hcf.faction.FactionHandler +import cc.fyre.hcf.faction.FactionMetadata +import cc.fyre.hcf.faction.type.SystemFaction +import cc.fyre.hcf.map.MapHandler +import org.bukkit.Bukkit +import org.bukkit.ChatColor +import org.bukkit.Material +import org.bukkit.World +import org.bukkit.event.EventHandler +import org.bukkit.event.EventPriority +import org.bukkit.event.Listener +import org.bukkit.event.block.BlockPlaceEvent +import org.bukkit.event.player.PlayerPortalEvent +import org.bukkit.event.player.PlayerTeleportEvent + +/** + * @project hcf + * + * @date 06/12/2020 + * @author xanderume@gmail.com + */ +object NetherListener : Listener { + + @EventHandler(priority = EventPriority.LOWEST) + private fun onBlockPlace(event: BlockPlaceEvent) { + + if (event.block.world.environment != World.Environment.NETHER) { + return + } + + if (event.block.type != Material.BED) { + return + } + + event.isCancelled = true + } + + @EventHandler(priority = EventPriority.NORMAL) + private fun onPlayerPortalRoad(event: PlayerPortalEvent) { + + if (event.cause != PlayerTeleportEvent.TeleportCause.NETHER_PORTAL) { + return + } + + val faction = FactionHandler.getFactionByLocation(event.to) + + if (faction !is SystemFaction || !faction.hasMetadata(FactionMetadata.ROAD)) { + return + } + + val to = event.to + + when { + faction.name.contains("east",true) -> to.add(0.0,0.0,20.0) + faction.name.contains("north",true) -> to.add(20.0,0.0,0.0) + faction.name.contains("west",true) -> to.subtract(0.0,0.0,20.0) + faction.name.contains("south",true) -> to.subtract(20.0,0.0,0.0) + } + + event.to = to + } + + @EventHandler(priority = EventPriority.NORMAL) + private fun onPlayerPortal(event: PlayerPortalEvent) { + val player = event.player + + + if (event.cause != PlayerTeleportEvent.TeleportCause.NETHER_PORTAL) { + return + } + + if (event.to.world.environment != World.Environment.NORMAL) { + return + } + + if (!FactionMetadata.SAFE_ZONE.isValidAtLocation(event.from)) { + return + } + event.isCancelled = true + + player.teleport(MapHandler.SPAWN_LOCATION) + player.sendMessage("${ChatColor.GREEN}Teleported to overworld spawn!") + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/listener/PearlListener.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/listener/PearlListener.kt new file mode 100644 index 0000000..0d065aa --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/listener/PearlListener.kt @@ -0,0 +1,119 @@ +package cc.fyre.hcf.map.listener + +import cc.fyre.hcf.HCF +import cc.fyre.hcf.timer.TimerHandler +import cc.fyre.hcf.timer.TimerType +import org.bukkit.ChatColor +import org.bukkit.Location +import org.bukkit.Material +import org.bukkit.World +import org.bukkit.block.Block +import org.bukkit.block.BlockFace +import org.bukkit.entity.EnderPearl +import org.bukkit.entity.Player +import org.bukkit.event.EventHandler +import org.bukkit.event.EventPriority +import org.bukkit.event.Listener +import org.bukkit.event.entity.EntityDamageByEntityEvent +import org.bukkit.event.player.PlayerPearlRefundEvent +import org.bukkit.event.player.PlayerTeleportEvent +import org.bukkit.material.Openable + +class PearlListener(private val instance: HCF) : Listener { + + private val returnTypes = listOf( + Material.LADDER, Material.BRICK_STAIRS,Material.SMOOTH_STAIRS, Material.WOOD_STAIRS, Material.SPRUCE_WOOD_STAIRS, Material.TORCH, Material.NETHER_BRICK_STAIRS, + Material.QUARTZ_STAIRS, Material.BEDROCK, Material.CAKE, Material.STEP, Material.WOOD_STEP, Material.LEVER, Material.DAYLIGHT_DETECTOR, Material.COBBLE_WALL, + Material.FENCE_GATE, Material.SIGN, Material.SIGN_POST, Material.WALL_SIGN, Material.STATIONARY_WATER, Material.WATER, Material.LAVA, Material.STATIONARY_LAVA, + Material.STONE_PLATE, Material.WOOD_PLATE, Material.IRON_PLATE, Material.GOLD_PLATE + ) + + init { + /*TODO code my own ones + EntityEnderPearl.pearlAbleType = listOf("STEP", "STAIR", "DAYLIGHT_DETECTOR", "COBBLE_WALL", "BED", "ENDER_PORTAL_FRAME", "TRAP_DOOR", + "PISTON_EXTENSION", "BREWING_STAND", "SKULL", "CHEST", "TRAPPED_CHEST", "ANVIL" + )*/ + + //EntityEnderPearl.forwardTypes = listOf(Material.ENDER_PORTAL_FRAME, Material.BREWING_STAND, Material.DAYLIGHT_DETECTOR, Material.BED_BLOCK, Material.SKULL) + } + + @EventHandler(priority = EventPriority.LOW) + fun onPearlClip(event: PlayerTeleportEvent) { + + val player = event.player + + if (event.isCancelled || event.cause != PlayerTeleportEvent.TeleportCause.ENDER_PEARL || event.to.world.environment != World.Environment.NORMAL) { + return + } + + val blockFace = getDirection(player) + val directionalBlock = getDirectionalBlock(event.to.block, blockFace) + + if (player.hasMetadata("DEBUG")) { + player.sendMessage("Directional Block -> " + (directionalBlock?.type?.name ?: "N/A")) + } + + /*TODO + if (EntityEnderPearl.pearlAbleType.none{event.to.block.type.name.contains(it!!)} && !event.to.block.getRelative(BlockFace.UP).type.name.contains("STEP") || event.to.block.type == null || directionalBlock == null && EntityEnderPearl.pearlAbleType.none { it: String? -> event.to.block.type.name.contains(it!!) }) { + return + }*/ + + if (isPearlGlitching(directionalBlock) && event.to.block.type != Material.AIR) { + HCF.instance.server.pluginManager.callEvent(PlayerPearlRefundEvent(player)) + event.isCancelled = true + player.sendMessage(ChatColor.RED.toString() + "Pearl glitching detected. You have been refunded.") + return + } + + event.to = findSuitableLocation(event.to, blockFace) + } + + private fun getDirectionalBlock(block: Block, blockFace: BlockFace): Block? { + val directionalBlock = block.getRelative(blockFace) + return if (directionalBlock != null && directionalBlock.type != null && directionalBlock.type != Material.AIR) directionalBlock else null + } + + private fun isPearlGlitching(block: Block?): Boolean { + return block != null && block.type != Material.AIR && block.type.isSolid && !returnTypes.contains(block.type) || block is Openable && !(block as Openable).isOpen + } + + private fun findSuitableLocation(to: Location, blockFace: BlockFace): Location? { + val newLocation = to.clone() + if (blockFace == BlockFace.NORTH) { + newLocation.z = newLocation.z - 1 + } + if (blockFace == BlockFace.SOUTH) { + newLocation.z = newLocation.z + 1 + } + if (blockFace == BlockFace.WEST) { + newLocation.x = newLocation.x - 1 + } + if (blockFace == BlockFace.EAST) { + newLocation.x = newLocation.x + 1 + } + if (newLocation.block.getRelative(BlockFace.DOWN) == null || !newLocation.block.getRelative(BlockFace.DOWN).type.isSolid) { + newLocation.y = to.blockY - 1.toDouble() + } + return newLocation + } + + private fun getDirection(player: Player): BlockFace { + var yaw = player.location.yaw + + if (yaw < 0) { + yaw += 360f + } + + if (yaw >= 315 || yaw < 45) { + return BlockFace.SOUTH + } else if (yaw < 135) { + return BlockFace.WEST + } else if (yaw < 225) { + return BlockFace.NORTH + } else if (yaw < 315) { + return BlockFace.EAST + } + + return BlockFace.NORTH + } +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/listener/PickaxeListener.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/listener/PickaxeListener.kt new file mode 100644 index 0000000..1668736 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/listener/PickaxeListener.kt @@ -0,0 +1,36 @@ +package cc.fyre.hcf.map.listener + +import cc.fyre.hcf.map.MapHandler +import org.bukkit.Material +import org.bukkit.enchantments.Enchantment +import org.bukkit.event.EventHandler +import org.bukkit.event.EventPriority +import org.bukkit.event.Listener +import org.bukkit.event.block.BlockBreakEvent +import org.bukkit.inventory.ItemStack + +object PickaxeListener : Listener { + + @EventHandler(priority = EventPriority.MONITOR) + private fun onBlockBreak(event: BlockBreakEvent) { + + if (event.isCancelled) { + return + } + + if (event.player.itemInHand == null + || !MapHandler.CUT_CLEAN_TOOLS.contains(event.player.itemInHand.type) + || event.player.itemInHand.containsEnchantment(Enchantment.SILK_TOUCH)) { + return + } + + val type = MapHandler.CUT_CLEAN_TYPES[event.block.type] ?: return + + event.isCancelled = true + + event.block.world.dropItemNaturally(event.block.location,type) + event.block.type = Material.AIR + event.player.giveExp(event.expToDrop) + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/listener/PotionListener.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/listener/PotionListener.kt new file mode 100644 index 0000000..581522b --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/listener/PotionListener.kt @@ -0,0 +1,102 @@ +package cc.fyre.hcf.map.listener + +import cc.fyre.hcf.HCF +import cc.fyre.hcf.faction.FactionMetadata +import cc.fyre.hcf.map.MapHandler +import cc.fyre.hcf.timer.TimerHandler +import cc.fyre.hcf.timer.TimerType +import cc.fyre.shard.util.bukkit.PotionUtil +import org.bukkit.Bukkit +import org.bukkit.Material +import org.bukkit.entity.Player +import org.bukkit.event.EventHandler +import org.bukkit.event.EventPriority +import org.bukkit.event.Listener +import org.bukkit.event.entity.PotionSplashEvent +import org.bukkit.event.inventory.BrewEvent +import org.bukkit.inventory.ItemStack +import org.bukkit.potion.Potion +import org.bukkit.potion.PotionType + +/** + * @project hcf + * + * @date 26/09/2020 + * @author xanderume@gmail.com + */ +object PotionListener : Listener { + + @EventHandler(priority = EventPriority.HIGH) + private fun onPotionSplash(event: PotionSplashEvent) { + + val potion = Potion.fromItemStack(event.potion.item) + + if (potion.type == PotionType.STRENGTH || potion.type == PotionType.INSTANT_DAMAGE) { + event.isCancelled = true + return + } + + event.affectedEntities.removeIf{FactionMetadata.SAFE_ZONE.isValidAtLocation(it.location)} + + if (event.potion.shooter !is Player || event.isCancelled || event.affectedEntities.isEmpty()) { + return + } + + if (event.potion.effects.none{PotionUtil.DEBUFFS.any{debuff -> debuff == it.type}}) { + return + } + + TimerHandler.addTimer((event.entity.shooter as Player).uniqueId,TimerType.SPAWN_TAG) + } + + + @EventHandler(priority = EventPriority.MONITOR) + private fun onPotionBrew(event: BrewEvent) { + + val inventory = event.contents + val contents = inventory.contents + + val cloned = arrayOfNulls(contents.size) + + for (i in contents.indices) { + cloned[i] = contents[i]?.clone() + } + + val stand = inventory.holder + + Bukkit.getServer().scheduler.runTaskLater(HCF.instance,{ + + if (this.testValidity(inventory.contents)) { + return@runTaskLater + } + + stand.brewingTime = 400 + inventory.contents = cloned + },1L) + + } + + private fun testValidity(contents: Array): Boolean { + for (stack in contents) { + if (stack != null && stack.type == Material.POTION && stack.durability.toInt() != 0) { + val potion = Potion.fromItemStack(stack) ?: continue + + // Just to be safe, null check this. + + // Mundane potions etc, can return a null type + val type = potion.type ?: continue + + // TODO: More configurable if 33 second splash poison is allowed + if (type == PotionType.POISON && !potion.hasExtendedDuration() && potion.level == 1) { + continue + } + + if (potion.level > MapHandler.getPotionLimit(type)) { + return false + } + + } + } + return true + } +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/listener/PreventionListener.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/listener/PreventionListener.kt new file mode 100644 index 0000000..bdd5540 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/listener/PreventionListener.kt @@ -0,0 +1,87 @@ +package cc.fyre.hcf.map.listener + +import cc.fyre.hcf.HCF +import cc.fyre.hcf.faction.FactionMetadata +import cc.fyre.hcf.faction.type.SystemFaction + +import cc.fyre.hcf.faction.claim.ClaimHandler +import org.bukkit.GameMode +import org.bukkit.Material +import org.bukkit.entity.EntityType +import org.bukkit.entity.Skeleton +import org.bukkit.entity.Wither +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.BlockBurnEvent +import org.bukkit.event.block.BlockIgniteEvent +import org.bukkit.event.entity.CreatureSpawnEvent +import org.bukkit.event.entity.EntityChangeBlockEvent +import org.bukkit.event.entity.EntityExplodeEvent +import org.bukkit.event.entity.EntitySpawnEvent +import org.bukkit.event.player.PlayerInteractEvent + +/** + * @project hcf + * + * @date 12/09/2020 + * @author xanderume@gmail.com + */ +object PreventionListener : Listener { + + @EventHandler(priority = EventPriority.HIGH) + private fun onEntityChangeBlock(event: EntityChangeBlockEvent) { + + if (!(event.entity is Wither || FactionMetadata.SAFE_ZONE.isValidAtLocation(event.block.location))) { + return + } + + event.isCancelled = true + } + + @EventHandler(priority = EventPriority.NORMAL) + private fun onPlayerInteract(event: PlayerInteractEvent) { + + if (!(event.action == Action.RIGHT_CLICK_BLOCK && event.player.gameMode != GameMode.CREATIVE)) { + return + } + + if (event.clickedBlock == null || event.clickedBlock.type != Material.ENDER_CHEST) { + return + } + + event.isCancelled = true + } + + @EventHandler(priority = EventPriority.NORMAL) + private fun onBlockBurn(event: BlockBurnEvent) { + + if (!ClaimHandler.isWarZone(event.block.location)) { + return + } + + event.isCancelled = true + } + + @EventHandler(priority = EventPriority.NORMAL) + private fun onBlockIgnite(event: BlockIgniteEvent) { + + if (event.cause != BlockIgniteEvent.IgniteCause.SPREAD) { + return + } + + event.isCancelled = true + } + + @EventHandler(priority = EventPriority.NORMAL) + private fun onEntitySpawn(event: EntitySpawnEvent) { + + if (event.entityType != EntityType.MINECART_TNT) { + return + } + + event.isCancelled = true + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/listener/RedstoneListener.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/listener/RedstoneListener.kt new file mode 100644 index 0000000..eeafa51 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/listener/RedstoneListener.kt @@ -0,0 +1,68 @@ +package cc.fyre.hcf.map.listener + +import cc.fyre.core.profile.ProfileHandler +import cc.fyre.hcf.HCF +import org.bukkit.Bukkit +import org.bukkit.ChatColor +import org.bukkit.Material +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.player.PlayerInteractEvent +import org.bukkit.event.player.PlayerQuitEvent +import java.util.* +import java.util.concurrent.atomic.AtomicInteger + +/** + * @project hcf + * + * @date 30/08/2020 + * @author xanderume@gmail.com + */ +object RedstoneListener : Listener { + + private val cache = mutableMapOf() + + private val lastClick = mutableMapOf() + + @EventHandler(priority = EventPriority.MONITOR) + private fun onPlayerQuit(event: PlayerQuitEvent) { + this.cache.remove(event.player.uniqueId) + this.lastClick.remove(event.player.uniqueId) + } + + @EventHandler(priority = EventPriority.MONITOR) + private fun onPlayerInteract(event: PlayerInteractEvent) { + + if (event.isCancelled) { + return + } + + if (event.action != Action.RIGHT_CLICK_BLOCK || !event.hasBlock()) { + return + } + + if (event.clickedBlock.type != Material.LEVER) { + return + } + + this.cache.putIfAbsent(event.player.uniqueId,AtomicInteger()) + this.lastClick.putIfAbsent(event.player.uniqueId,System.currentTimeMillis()) + + val difference = System.currentTimeMillis() - this.lastClick[event.player.uniqueId]!! + + if (difference in 1..49) { + + Bukkit.getServer().onlinePlayers.filter{it.isOp}.forEach{it.sendMessage( + "${ChatColor.RED}[${ChatColor.YELLOW}⚠${ChatColor.RED}] ${ProfileHandler.getDisplayNameById(event.player.uniqueId)}${ChatColor.GRAY} might be attempting to lag the server! ${ChatColor.RED}[${this.cache[event.player.uniqueId]!!.get()} VL]" + )} + + event.isCancelled = true + } + + this.cache[event.player.uniqueId]!!.addAndGet(1) + this.lastClick[event.player.uniqueId] = System.currentTimeMillis() + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/listener/StatTrakListener.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/listener/StatTrakListener.kt new file mode 100644 index 0000000..19d15a5 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/listener/StatTrakListener.kt @@ -0,0 +1,15 @@ +package cc.fyre.hcf.map.listener + +import org.bukkit.event.Listener + +/** + * @project hcf + * + * @date 20/09/2020 + * @author xanderume@gmail.com + */ +object StatTrakListener : Listener { + + //TODO + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/service/RankBroadcastService.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/service/RankBroadcastService.kt new file mode 100644 index 0000000..14446aa --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/service/RankBroadcastService.kt @@ -0,0 +1,45 @@ +package cc.fyre.hcf.map.service + +import cc.fyre.core.api.ApiHandler +import cc.fyre.core.profile.ProfileHandler +import cc.fyre.core.rank.RankHandler +import cc.fyre.core.server.ServerModule +import cc.fyre.hcf.HCF +import org.apache.commons.lang.StringUtils +import org.bukkit.Bukkit +import org.bukkit.ChatColor + +object RankBroadcastService : Runnable { + + private const val RANK_NAME = "Master" + + override fun run() { + + val rank = RankHandler.getRankByName(RANK_NAME) + + if (rank == null) { + HCF.instance.logger.info("Failed to broadcast online $RANK_NAME users, rank not found.") + return + } + + val players = Bukkit.getServer().onlinePlayers + .mapNotNull{ProfileHandler.getProfileById(it.uniqueId)} + .filter{it.rank.id == rank.id} + .map{it.getDisplayName()} + + if (players.isEmpty()) { + return + } + + Bukkit.broadcastMessage(buildString{ + append("${ChatColor.GRAY}[${ChatColor.RED}${ChatColor.BOLD}${ChatColor.ITALIC}${ServerModule.getServerId()}${ChatColor.GRAY}] ") + append("${ChatColor.GOLD}Online ${rank.getDisplayName()}${ChatColor.GOLD}'s:") + append("\n\n") + append(StringUtils.join(players,"${ChatColor.YELLOW},")) + append("\n") + append("${ChatColor.YELLOW}${ChatColor.BOLD}${ChatColor.UNDERLINE}${ApiHandler.getStoreUrl()}") + }) + + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/shop/ShopMenu.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/shop/ShopMenu.kt new file mode 100644 index 0000000..d2ca819 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/shop/ShopMenu.kt @@ -0,0 +1,65 @@ +package cc.fyre.hcf.map.shop + +import cc.fyre.hcf.map.shop.block.BlockMenu +import cc.fyre.hcf.map.shop.buy.BuyMenu +import cc.fyre.hcf.map.shop.sell.SellMenu +import cc.fyre.shard.menu.Menu +import cc.fyre.shard.menu.button.Button +import cc.fyre.shard.util.item.ItemBuilder +import org.bukkit.ChatColor +import org.bukkit.DyeColor +import org.bukkit.Material +import org.bukkit.entity.Player +import java.util.function.Predicate + +object ShopMenu : Menu() { + + override fun isFill(player: Player, buttons: Map): Boolean { + return true + } + + override fun getSize(player: Player, buttons: Map): Int { + return 3*9 + } + + override fun getTitle(player: Player): String { + return "Shop" + } + + override fun getButtons(player: Player): MutableMap { + return mutableMapOf( + 11 to SELL, + 13 to BLOCK, + 15 to BUY, + ) + } + + private val SELL = Button.fromItem(ItemBuilder.of(Material.WOOL) + .name("${ChatColor.RED}${ChatColor.BOLD}Sell") + .data(DyeColor.RED.woolData) + .build(), + Predicate{ + SellMenu.open(it.whoClicked as Player) + return@Predicate true + } + ) + + private val BLOCK = Button.fromItem(ItemBuilder.of(Material.BOOKSHELF) + .name("${ChatColor.GOLD}${ChatColor.BOLD}Block") + .build(), + Predicate{ + BlockMenu.open(it.whoClicked as Player) + return@Predicate true + } + ) + + private val BUY = Button.fromItem(ItemBuilder.of(Material.WOOL) + .name("${ChatColor.GREEN}${ChatColor.BOLD}Buy") + .data(DyeColor.LIME.woolData) + .build(), + Predicate{ + BuyMenu.open(it.whoClicked as Player) + return@Predicate true + } + ) +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/shop/block/BlockCategory.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/shop/block/BlockCategory.kt new file mode 100644 index 0000000..6a72411 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/shop/block/BlockCategory.kt @@ -0,0 +1,132 @@ +package cc.fyre.hcf.map.shop.block + +import cc.fyre.hcf.map.shop.buy.BuyButton +import cc.fyre.shard.menu.button.Button +import cc.fyre.shard.util.item.ItemBuilder +import org.apache.commons.lang.WordUtils +import org.bukkit.Material +import org.bukkit.inventory.ItemStack + +enum class BlockCategory(val item: ItemStack,val buttons: MutableMap,private var displayName: String? = null) { + + NETHER(ItemStack(Material.NETHER_BRICK_ITEM),mutableMapOf( + 11 to BuyButton(ItemStack(Material.NETHER_BRICK_ITEM),16,35), + 12 to BuyButton(ItemBuilder.of(Material.STEP).data(6).build(),16,75), + 13 to BuyButton(ItemStack(Material.NETHER_BRICK_STAIRS),16,90), + 14 to BuyButton(ItemStack(Material.NETHER_FENCE),16,80), + 15 to BuyButton(ItemStack(Material.NETHER_BRICK),16,100), + + 20 to BuyButton(ItemBuilder.of(Material.STEP).data(7).build(),16,75), + 21 to BuyButton(ItemStack(Material.QUARTZ_STAIRS),16,90), + 22 to BuyButton(ItemStack(Material.QUARTZ_BLOCK),16,100), + 23 to BuyButton(ItemBuilder.of(Material.QUARTZ_BLOCK).data(1).build(),16,150), + 24 to BuyButton(ItemBuilder.of(Material.QUARTZ_BLOCK).data(2).build(),16,150), + )), + + FLOWERS(ItemStack(Material.RED_ROSE),mutableMapOf( + 11 to BuyButton(ItemBuilder.of(Material.RED_ROSE).data(0).build(),16,50), + 12 to BuyButton(ItemBuilder.of(Material.RED_ROSE).data(4).build(),16,50), + 13 to BuyButton(ItemBuilder.of(Material.RED_ROSE).data(5).build(),16,50), + 14 to BuyButton(ItemBuilder.of(Material.RED_ROSE).data(6).build(),16,50), + 15 to BuyButton(ItemBuilder.of(Material.RED_ROSE).data(7).build(),16,50), + + 20 to BuyButton(ItemBuilder.of(Material.RED_ROSE).data(8).build(),16,50), + 21 to BuyButton(ItemBuilder.of(Material.RED_ROSE).data(2).build(),16,50), + 22 to BuyButton(ItemBuilder.of(Material.RED_ROSE).data(1).build(),16,50), + 23 to BuyButton(ItemBuilder.of(Material.RED_ROSE).data(3).build(),16,50), + 24 to BuyButton(ItemBuilder.of(Material.DOUBLE_PLANT).data(0).build(),16,50), + )), + + GLASS(ItemStack(Material.GLASS),mutableMapOf( + 12 to BuyButton(ItemBuilder.of(Material.STAINED_GLASS).data(0).build(),16,300), + 13 to BuyButton(ItemBuilder.of(Material.STAINED_GLASS).data(1).build(),16,300), + 14 to BuyButton(ItemBuilder.of(Material.STAINED_GLASS).data(2).build(),16,300), + + 20 to BuyButton(ItemBuilder.of(Material.STAINED_GLASS).data(3).build(),16,300), + 21 to BuyButton(ItemBuilder.of(Material.STAINED_GLASS).data(4).build(),16,300), + 22 to BuyButton(ItemBuilder.of(Material.STAINED_GLASS).data(5).build(),16,300), + 23 to BuyButton(ItemBuilder.of(Material.STAINED_GLASS).data(6).build(),16,300), + 24 to BuyButton(ItemBuilder.of(Material.STAINED_GLASS).data(7).build(),16,300), + + 29 to BuyButton(ItemBuilder.of(Material.STAINED_GLASS).data(8).build(),16,300), + 30 to BuyButton(ItemBuilder.of(Material.STAINED_GLASS).data(9).build(),16,300), + 31 to BuyButton(ItemBuilder.of(Material.STAINED_GLASS).data(10).build(),16,300), + 32 to BuyButton(ItemBuilder.of(Material.STAINED_GLASS).data(11).build(),16,300), + 33 to BuyButton(ItemBuilder.of(Material.STAINED_GLASS).data(12).build(),16,300), + + 39 to BuyButton(ItemBuilder.of(Material.STAINED_GLASS).data(13).build(),16,300), + 40 to BuyButton(ItemBuilder.of(Material.STAINED_GLASS).data(14).build(),16,300), + 41 to BuyButton(ItemBuilder.of(Material.STAINED_GLASS).data(15).build(),16,300), + )), + + WOOL(ItemStack(Material.WOOL),mutableMapOf( + 12 to BuyButton(ItemBuilder.of(Material.WOOL).data(0).build(),16,200), + 13 to BuyButton(ItemBuilder.of(Material.WOOL).data(1).build(),16,200), + 14 to BuyButton(ItemBuilder.of(Material.WOOL).data(2).build(),16,200), + + 20 to BuyButton(ItemBuilder.of(Material.WOOL).data(3).build(),16,200), + 21 to BuyButton(ItemBuilder.of(Material.WOOL).data(4).build(),16,200), + 22 to BuyButton(ItemBuilder.of(Material.WOOL).data(5).build(),16,200), + 23 to BuyButton(ItemBuilder.of(Material.WOOL).data(6).build(),16,200), + 24 to BuyButton(ItemBuilder.of(Material.WOOL).data(7).build(),16,200), + + 29 to BuyButton(ItemBuilder.of(Material.WOOL).data(8).build(),16,200), + 30 to BuyButton(ItemBuilder.of(Material.WOOL).data(9).build(),16,200), + 31 to BuyButton(ItemBuilder.of(Material.WOOL).data(10).build(),16,200), + 32 to BuyButton(ItemBuilder.of(Material.WOOL).data(11).build(),16,200), + 33 to BuyButton(ItemBuilder.of(Material.WOOL).data(12).build(),16,200), + + 39 to BuyButton(ItemBuilder.of(Material.WOOL).data(13).build(),16,200), + 40 to BuyButton(ItemBuilder.of(Material.WOOL).data(14).build(),16,200), + 41 to BuyButton(ItemBuilder.of(Material.WOOL).data(15).build(),16,200), + )), + + CLAY(ItemStack(Material.HARD_CLAY),mutableMapOf( + 12 to BuyButton(ItemBuilder.of(Material.STAINED_CLAY).data(0).build(),16,350), + 13 to BuyButton(ItemBuilder.of(Material.STAINED_CLAY).data(1).build(),16,350), + 14 to BuyButton(ItemBuilder.of(Material.STAINED_CLAY).data(2).build(),16,350), + + 20 to BuyButton(ItemBuilder.of(Material.STAINED_CLAY).data(3).build(),16,350), + 21 to BuyButton(ItemBuilder.of(Material.STAINED_CLAY).data(4).build(),16,350), + 22 to BuyButton(ItemBuilder.of(Material.STAINED_CLAY).data(5).build(),16,350), + 23 to BuyButton(ItemBuilder.of(Material.STAINED_CLAY).data(6).build(),16,350), + 24 to BuyButton(ItemBuilder.of(Material.STAINED_CLAY).data(7).build(),16,350), + + 29 to BuyButton(ItemBuilder.of(Material.STAINED_CLAY).data(8).build(),16,350), + 30 to BuyButton(ItemBuilder.of(Material.STAINED_CLAY).data(9).build(),16,350), + 31 to BuyButton(ItemBuilder.of(Material.STAINED_CLAY).data(10).build(),16,350), + 32 to BuyButton(ItemBuilder.of(Material.STAINED_CLAY).data(11).build(),16,350), + 33 to BuyButton(ItemBuilder.of(Material.STAINED_CLAY).data(12).build(),16,350), + + 39 to BuyButton(ItemBuilder.of(Material.STAINED_CLAY).data(13).build(),16,350), + 40 to BuyButton(ItemBuilder.of(Material.STAINED_CLAY).data(14).build(),16,350), + 41 to BuyButton(ItemBuilder.of(Material.STAINED_CLAY).data(15).build(),16,350), + )), + + STONE(ItemStack(Material.STONE),mutableMapOf( + 11 to BuyButton(ItemBuilder.of(Material.COBBLE_WALL).data(0).build(),16,50), + 12 to BuyButton(ItemBuilder.of(Material.SMOOTH_BRICK).data(2).build(),16,350), + 13 to BuyButton(ItemBuilder.of(Material.SMOOTH_BRICK).data(1).build(),16,350), + 14 to BuyButton(ItemBuilder.of(Material.SMOOTH_BRICK).data(3).build(),16,350), + 15 to BuyButton(ItemBuilder.of(Material.COBBLE_WALL).data(1).build(),16,300), + )); + + fun getDisplayName():String { + + if (this.displayName == null) { + this.displayName = WordUtils.capitalizeFully(this.name.lowercase()) + } + + return this.displayName!! + } + + companion object { + + private val values = values().associateBy{it.name.lowercase()} + + fun getAllCategories():List { + return this.values.values.toList() + } + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/shop/block/BlockCategoryButton.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/shop/block/BlockCategoryButton.kt new file mode 100644 index 0000000..6526b05 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/shop/block/BlockCategoryButton.kt @@ -0,0 +1,24 @@ +package cc.fyre.hcf.map.shop.block + +import cc.fyre.shard.menu.button.Button +import cc.fyre.shard.util.item.ItemBuilder +import org.bukkit.ChatColor +import org.bukkit.entity.Player +import org.bukkit.event.inventory.InventoryClickEvent +import org.bukkit.inventory.ItemStack + +class BlockCategoryButton(private val category: BlockCategory,private val rows: Int) : Button() { + + private val menu = BlockCategoryMenu(this.category,this.rows) + + override fun getItem(player: Player): ItemStack { + return ItemBuilder.of(this.category.item.type) + .name("${ChatColor.GREEN}${ChatColor.BOLD}${this.category.getDisplayName()}") + .build() + } + + override fun onClick(player: Player,event: InventoryClickEvent) { + this.menu.open(player) + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/shop/block/BlockCategoryMenu.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/shop/block/BlockCategoryMenu.kt new file mode 100644 index 0000000..aece8aa --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/shop/block/BlockCategoryMenu.kt @@ -0,0 +1,34 @@ +package cc.fyre.hcf.map.shop.block + +import cc.fyre.shard.menu.Menu +import cc.fyre.shard.menu.button.Button +import cc.fyre.shard.menu.button.type.BackButton +import org.bukkit.entity.Player + +class BlockCategoryMenu(private val category: BlockCategory,private val rows: Int) : Menu() { + + private val buttons = this.category.buttons.plus(4 to BACK).toMutableMap() + + override fun isFill(player: Player, buttons: Map): Boolean { + return true + } + + override fun getSize(player: Player, buttons: Map): Int { + return this.rows * 9 + } + + override fun getTitle(player: Player): String { + return this.category.getDisplayName() + } + + override fun getButtons(player: Player): MutableMap { + return this.buttons + } + + companion object { + + private val BACK = BackButton(BlockMenu) + + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/shop/block/BlockMenu.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/shop/block/BlockMenu.kt new file mode 100644 index 0000000..16ba2a3 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/shop/block/BlockMenu.kt @@ -0,0 +1,34 @@ +package cc.fyre.hcf.map.shop.block + +import cc.fyre.shard.menu.Menu +import cc.fyre.shard.menu.button.Button +import org.bukkit.entity.Player + +object BlockMenu : Menu() { + + private val buttons = mutableMapOf( + 10 to BlockCategoryButton(BlockCategory.FLOWERS,4), + 11 to BlockCategoryButton(BlockCategory.STONE,3), + 12 to BlockCategoryButton(BlockCategory.WOOL,6), + 13 to BlockCategoryButton(BlockCategory.CLAY,6), + 14 to BlockCategoryButton(BlockCategory.GLASS,6), + 15 to BlockCategoryButton(BlockCategory.NETHER,4), + ) + + override fun isFill(player: Player, buttons: Map): Boolean { + return true + } + + override fun getSize(player: Player, buttons: Map): Int { + return 3*9 + } + + override fun getTitle(player: Player): String { + return "Block" + } + + override fun getButtons(player: Player): MutableMap { + return this.buttons + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/shop/buy/BuyButton.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/shop/buy/BuyButton.kt new file mode 100644 index 0000000..bb82cd6 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/shop/buy/BuyButton.kt @@ -0,0 +1,43 @@ +package cc.fyre.hcf.map.shop.buy + +import cc.fyre.hcf.statistic.StatisticHandler +import cc.fyre.hcf.statistic.type.BalanceStatistic +import cc.fyre.shard.menu.button.Button +import cc.fyre.shard.util.item.ItemBuilder +import org.bukkit.ChatColor +import org.bukkit.entity.Player +import org.bukkit.event.inventory.InventoryClickEvent +import org.bukkit.inventory.ItemStack + +class BuyButton(private val item: ItemStack,private val amount: Int,private val price: Int) : Button() { + + override fun getItem(player: Player): ItemStack { + return ItemBuilder.copyOf(this.item) + .amount(this.amount) + .lore("${ChatColor.YELLOW}${ChatColor.BOLD}$${ChatColor.GOLD}${ChatColor.BOLD}${this.price}") + .build() + } + + override fun onClick(player: Player, event: InventoryClickEvent) { + + val balance = StatisticHandler.getStatistic(player.uniqueId,BalanceStatistic).getValue() + + if (balance < this.price) { + player.sendMessage("${ChatColor.RED}You have insufficient funds to purchase this item.") + return + } + + if (player.inventory.firstEmpty() == -1) { + player.sendMessage("${ChatColor.RED}You do not have any inventory space.") + return + } + + val item = this.item.clone().also{it.amount = this.amount} + + player.inventory.addItem(item) + player.updateInventory() + + StatisticHandler.increaseStatistic(player.uniqueId,BalanceStatistic,-balance) + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/shop/buy/BuyMenu.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/shop/buy/BuyMenu.kt new file mode 100644 index 0000000..970ee6b --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/shop/buy/BuyMenu.kt @@ -0,0 +1,65 @@ +package cc.fyre.hcf.map.shop.buy + +import cc.fyre.hcf.map.crowbar.CrowbarHandler +import cc.fyre.hcf.map.shop.ShopMenu +import cc.fyre.shard.menu.Menu +import cc.fyre.shard.menu.button.Button +import cc.fyre.shard.menu.button.type.BackButton +import cc.fyre.shard.util.item.ItemBuilder +import org.bukkit.DyeColor +import org.bukkit.Material +import org.bukkit.entity.EntityType +import org.bukkit.entity.Player +import org.bukkit.inventory.ItemStack + +object BuyMenu : Menu() { + + private val buttons = mutableMapOf( + 4 to BackButton(ShopMenu), + + 10 to BuyButton(ItemStack(Material.NETHER_STALK),16,500), + 11 to BuyButton(ItemStack(Material.SPECKLED_MELON),16,500), + 12 to BuyButton(ItemStack(Material.SUGAR_CANE),16,500), + 13 to BuyButton(ItemStack(Material.MELON),16,500), + 14 to BuyButton(ItemStack(Material.POTATO_ITEM),16,500), + 15 to BuyButton(ItemStack(Material.CARROT_ITEM),16,500), + 16 to BuyButton(ItemBuilder.of(Material.INK_SACK) + .data(DyeColor.BROWN.dyeData) + .build(), + 16, + 500 + ), + + 19 to BuyButton(ItemStack(Material.BLAZE_ROD),16,500), + 21 to BuyButton(ItemStack(Material.GHAST_TEAR),16,1000), + 20 to BuyButton(ItemStack(Material.FEATHER),16,500), + 22 to BuyButton(ItemStack(Material.INK_SACK),16,1000), + 23 to BuyButton(ItemStack(Material.SLIME_BALL),16,500), + 24 to BuyButton(ItemBuilder.of(Material.MONSTER_EGG) + .data(EntityType.COW.typeId) + .build(), + 2, + 1000 + ), + 25 to BuyButton(ItemStack(Material.ENDER_PORTAL_FRAME),1,3000), + 31 to BuyButton(CrowbarHandler.create(1,6),1,25_000) + ) + + + override fun isFill(player: Player, buttons: Map): Boolean { + return true + } + + override fun getSize(player: Player, buttons: Map): Int { + return 5*9 + } + + override fun getTitle(player: Player): String { + return "Buy" + } + + override fun getButtons(player: Player): MutableMap { + return buttons + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/shop/sell/SellButton.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/shop/sell/SellButton.kt new file mode 100644 index 0000000..d36f0b4 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/shop/sell/SellButton.kt @@ -0,0 +1,70 @@ +package cc.fyre.hcf.map.shop.sell + +import cc.fyre.hcf.statistic.StatisticHandler +import cc.fyre.hcf.statistic.type.BalanceStatistic +import cc.fyre.shard.menu.button.Button +import cc.fyre.shard.util.item.ItemBuilder +import cc.fyre.shard.util.item.ItemUtil +import org.bukkit.ChatColor +import org.bukkit.Material +import org.bukkit.entity.Player +import org.bukkit.event.inventory.InventoryClickEvent +import org.bukkit.inventory.ItemStack + +class SellButton(private val type: Material,private val amount: Int,private val price: Int,private val data: Int = 0) : Button() { + + private val name = ItemUtil.getName(ItemStack(this.type)) + private val individualPrice = (this.price.toFloat() / this.amount.toFloat()).toDouble() + + override fun getItem(player: Player): ItemStack { + return ItemBuilder.of(this.type) + .name("${ChatColor.WHITE}${this.name}") + .data(this.data) + .lore("${ChatColor.YELLOW}${ChatColor.BOLD}$${ChatColor.GOLD}${ChatColor.BOLD}${this.price}") + .build() + } + + override fun onClick(player: Player, event: InventoryClickEvent) { + + val amount = this.amount.coerceAtMost(this.countItems(player,this.type,this.data.toShort())) + + if (amount <= 0) { + player.sendMessage("${ChatColor.RED}You do not have any ${ChatColor.BOLD}${this.name}${ChatColor.RED} on you!") + return + } + + this.removeItem(player,this.type,this.data.toShort(),amount) + + val money = (amount * this.individualPrice).toInt() + + player.updateInventory() + player.sendMessage("${ChatColor.GREEN}You have sold ${ChatColor.YELLOW}${amount}x ${ChatColor.WHITE}${this.name}${ChatColor.GREEN} for ${ChatColor.BOLD}$$money${ChatColor.GREEN}.") + + StatisticHandler.increaseStatistic(player.uniqueId,BalanceStatistic,money) + } + + private fun countItems(player: Player,material: Material,data: Short): Int { + return player.inventory.contents + .filter{it != null && it.type != null && it.type == material && it.durability == data} + .sumOf{it.amount} + } + + private fun removeItem(player: Player,material: Material,data: Short,amount: Int) { + val specialDamage = material.maxDurability == 0.toShort() + for (a in 0 until amount) { + for (i in player.inventory) { + if (i != null) { + if (i.type == material && (!specialDamage || data == i.durability)) { + if (i.amount == 1) { + player.inventory.clear(player.inventory.first(i)) + break + } else { + i.amount = i.amount - 1 + break + } + } + } + } + } + } +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/shop/sell/SellMenu.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/shop/sell/SellMenu.kt new file mode 100644 index 0000000..39fb2d3 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/shop/sell/SellMenu.kt @@ -0,0 +1,46 @@ +package cc.fyre.hcf.map.shop.sell + +import cc.fyre.hcf.map.shop.ShopMenu +import cc.fyre.shard.menu.Menu +import cc.fyre.shard.menu.button.Button +import cc.fyre.shard.menu.button.type.BackButton +import org.bukkit.Material +import org.bukkit.entity.Player + +object SellMenu : Menu() { + + override fun isFill(player: Player, buttons: Map): Boolean { + return true + } + + override fun getSize(player: Player, buttons: Map): Int { + return 3*9 + } + + override fun getTitle(player: Player): String { + return "Sell" + } + + override fun getButtons(player: Player): MutableMap { + return mutableMapOf().also{ + it[4] = BACK + it[10] = COAL + it[11] = IRON + it[12] = GOLD + it[13] = REDSTONE + it[14] = LAPIS + it[15] = DIAMOND + it[16] = EMERALD + } + } + + private val BACK = BackButton(ShopMenu) + private val COAL = SellButton(Material.COAL_BLOCK,16,250) + private val GOLD = SellButton(Material.GOLD_BLOCK,16,500) + private val IRON = SellButton(Material.IRON_BLOCK,16,500) + private val LAPIS = SellButton(Material.LAPIS_BLOCK,16,400) + private val DIAMOND = SellButton(Material.DIAMOND_BLOCK,16,700) + private val EMERALD = SellButton(Material.EMERALD_BLOCK,16,800) + private val REDSTONE = SellButton(Material.REDSTONE_BLOCK,16,250) + +} diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/sotw/SOTWHandler.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/sotw/SOTWHandler.kt new file mode 100644 index 0000000..49478e5 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/sotw/SOTWHandler.kt @@ -0,0 +1,64 @@ +package cc.fyre.hcf.map.sotw + +import cc.fyre.hcf.HCF +import cc.fyre.hcf.map.sotw.event.SOTWEndEvent +import cc.fyre.hcf.map.sotw.scheduler.SOTWScheduler +import cc.fyre.hcf.statistic.StatisticHandler +import cc.fyre.hcf.statistic.type.setting.SOTWProtectionSetting +import org.bukkit.Bukkit +import org.bukkit.entity.Player + +object SOTWHandler { + + private var paused = false + private var remaining = 0 + private var scheduler: SOTWScheduler? = null + + internal fun tick() { + + if (this.remaining-- > 0) { + return + } + + Bukkit.getServer().pluginManager.callEvent(SOTWEndEvent(false)) + } + + fun isActive():Boolean { + return this.scheduler != null && this.remaining > 0 + } + + fun setActive(duration: Long) { + this.remaining = (duration / 1000L).toInt() + this.scheduler?.cancel() + this.scheduler = if (duration > 0L) SOTWScheduler().also{ + it.runTaskTimer(HCF.instance,20L,20L) + } else null + } + + fun isPaused():Boolean { + return this.paused + } + + fun setPaused(value: Boolean) { + this.paused = value + } + + fun getRemaining():Int { + return this.remaining + } + + fun getRemainingMillis():Long { + return this.remaining * 1000L + } + + fun isProtected(player: Player):Boolean { + + if (this.remaining > ENABLE_TIME) { + return true + } + + return StatisticHandler.getStatistic(player.uniqueId,SOTWProtectionSetting).getValue() + } + + const val ENABLE_TIME = 30 * 60 +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/sotw/command/SOTWCancelCommand.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/sotw/command/SOTWCancelCommand.kt new file mode 100644 index 0000000..1f083fd --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/sotw/command/SOTWCancelCommand.kt @@ -0,0 +1,27 @@ +package cc.fyre.hcf.map.sotw.command + +import cc.fyre.shard.command.data.command.Command +import cc.fyre.hcf.map.sotw.event.SOTWEndEvent +import cc.fyre.hcf.map.sotw.SOTWHandler +import org.bukkit.Bukkit +import org.bukkit.ChatColor +import org.bukkit.command.CommandSender + +/** + * @project hcf + * + * @date 12/09/2020 + * @author xanderume@gmail.com + */ +object SOTWCancelCommand { + + @JvmStatic + @Command(names = ["sotw cancel"],permission = "hcf.command.sotw.cancel") + fun execute(sender: CommandSender) { + SOTWHandler.setActive(0L) + Bukkit.getServer().pluginManager.callEvent(SOTWEndEvent(true)) + + sender.sendMessage("${ChatColor.RED}Cancelled SOTW.") + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/sotw/command/SOTWEnableCommand.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/sotw/command/SOTWEnableCommand.kt new file mode 100644 index 0000000..74115e5 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/sotw/command/SOTWEnableCommand.kt @@ -0,0 +1,50 @@ +package cc.fyre.hcf.map.sotw.command + +import cc.fyre.shard.command.data.command.Command +import cc.fyre.shard.util.TimeUtil +import cc.fyre.hcf.HCF +import cc.fyre.hcf.map.sotw.SOTWHandler +import cc.fyre.hcf.statistic.StatisticHandler +import cc.fyre.hcf.statistic.type.setting.SOTWProtectionSetting +import cc.fyre.shard.nametag.NameTagHandler +import org.bukkit.ChatColor +import org.bukkit.entity.Player + +/** + * @project hcf + * + * @date 12/09/2020 + * @author xanderume@gmail.com + */ +object SOTWEnableCommand { + + @JvmStatic + @Command(names = ["sotw enable"]) + fun execute(player: Player) { + + if (!SOTWHandler.isActive()) { + player.sendMessage("${ChatColor.RED}SOTW is not active.") + return + } + + if (!SOTWHandler.isProtected(player)) { + player.sendMessage("${ChatColor.RED}You have already enabled your SOTW Timer") + return + } + + val time = (SOTWHandler.getRemaining() * 1000L) + + if (time >= SOTWHandler.ENABLE_TIME) { + player.sendMessage("${ChatColor.RED}You can enable your SOTW Timer in ${ChatColor.BOLD}${TimeUtil.formatIntoDetailedString(time - SOTWHandler.ENABLE_TIME)}${ChatColor.RED}.") + return + } + + StatisticHandler.setStatistic(player.uniqueId,SOTWProtectionSetting,false) + + NameTagHandler.update(player) + + player.sendMessage("${ChatColor.GREEN}You have enabled your SOTW Timer.") + } + + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/sotw/command/SOTWPauseCommand.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/sotw/command/SOTWPauseCommand.kt new file mode 100644 index 0000000..06817ed --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/sotw/command/SOTWPauseCommand.kt @@ -0,0 +1,22 @@ +package cc.fyre.hcf.map.sotw.command + +import cc.fyre.shard.command.data.command.Command +import cc.fyre.hcf.HCF +import cc.fyre.hcf.map.sotw.SOTWHandler +import org.bukkit.command.CommandSender + +/** + * @project hcf + * + * @date 12/09/2020 + * @author xanderume@gmail.com + */ +object SOTWPauseCommand { + + @JvmStatic + @Command(names = ["sotw pause"],permission = "hcf.command.sotw.pause") + fun execute(sender: CommandSender) { + SOTWHandler.setPaused(true) + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/sotw/command/SOTWStartCommand.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/sotw/command/SOTWStartCommand.kt new file mode 100644 index 0000000..62e9851 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/sotw/command/SOTWStartCommand.kt @@ -0,0 +1,29 @@ +package cc.fyre.hcf.map.sotw.command + +import cc.fyre.shard.command.data.command.Command +import cc.fyre.shard.command.data.parameter.Parameter +import cc.fyre.shard.util.TimeUtil +import cc.fyre.hcf.HCF +import cc.fyre.hcf.map.sotw.event.SOTWStartEvent +import cc.fyre.hcf.map.sotw.SOTWHandler +import org.bukkit.ChatColor +import org.bukkit.command.CommandSender + +/** + * @project hcf + * + * @date 12/09/2020 + * @author xanderume@gmail.com + */ +object SOTWStartCommand { + + @JvmStatic + @Command(names = ["sotw start"],permission = "hcf.command.sotw.start") + fun execute(sender: CommandSender, @Parameter(name = "time")time: Long) { + SOTWHandler.setActive(time) + HCF.instance.server.pluginManager.callEvent(SOTWStartEvent((time / 1000L).toInt())) + + sender.sendMessage("${ChatColor.GREEN}Started SOTW for ${ChatColor.WHITE}${TimeUtil.formatIntoDetailedString(time)}${ChatColor.GREEN}.") + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/sotw/event/SOTWEndEvent.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/sotw/event/SOTWEndEvent.kt new file mode 100644 index 0000000..99b4c2c --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/sotw/event/SOTWEndEvent.kt @@ -0,0 +1,22 @@ +package cc.fyre.hcf.map.sotw.event + +import org.bukkit.event.Event +import org.bukkit.event.HandlerList + +/** + * @project hcf + * + * @date 02/01/2021 + * @author xanderume@gmail.com + */ +class SOTWEndEvent(var force: Boolean) : Event() { + + override fun getHandlers(): HandlerList { + return handlerList + } + + companion object { + @JvmStatic val handlerList = HandlerList() + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/sotw/event/SOTWStartEvent.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/sotw/event/SOTWStartEvent.kt new file mode 100644 index 0000000..6b60c25 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/sotw/event/SOTWStartEvent.kt @@ -0,0 +1,22 @@ +package cc.fyre.hcf.map.sotw.event + +import org.bukkit.event.Event +import org.bukkit.event.HandlerList + +/** + * @project hcf + * + * @date 02/01/2021 + * @author xanderume@gmail.com + */ +class SOTWStartEvent(val seconds: Int) : Event() { + + override fun getHandlers(): HandlerList { + return handlerList + } + + companion object { + @JvmStatic val handlerList = HandlerList() + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/sotw/listener/SOTWListener.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/sotw/listener/SOTWListener.kt new file mode 100644 index 0000000..523ae09 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/sotw/listener/SOTWListener.kt @@ -0,0 +1,90 @@ +package cc.fyre.hcf.map.sotw.listener + +import cc.fyre.hcf.HCF +import cc.fyre.hcf.map.sotw.event.SOTWEndEvent +import cc.fyre.hcf.map.sotw.SOTWHandler +import cc.fyre.hcf.statistic.StatisticHandler +import cc.fyre.hcf.statistic.type.setting.SOTWProtectionSetting +import cc.fyre.shard.nametag.NameTagHandler +import org.bukkit.Bukkit +import org.bukkit.ChatColor +import org.bukkit.entity.Player +import org.bukkit.entity.Projectile +import org.bukkit.event.EventHandler +import org.bukkit.event.EventPriority +import org.bukkit.event.Listener +import org.bukkit.event.entity.EntityDamageByEntityEvent +import org.bukkit.event.entity.EntityDamageEvent +import org.bukkit.event.entity.PlayerDeathEvent + +object SOTWListener : Listener { + + @EventHandler(priority = EventPriority.MONITOR) + private fun onSOTWEnd(event: SOTWEndEvent) { + Bukkit.getServer().onlinePlayers.forEach{NameTagHandler.update(it)} + } + + @EventHandler(priority = EventPriority.MONITOR) + private fun onPlayerDeath(event: PlayerDeathEvent) { + + if (!SOTWHandler.isActive()) { + return + } + + if (!HCF.instance.isKitMap()) { + return + } + + StatisticHandler.setStatistic(event.entity.uniqueId,SOTWProtectionSetting,true) + } + + @EventHandler(priority = EventPriority.HIGHEST) + private fun onEntityDamage(event: EntityDamageEvent) { + + if (event.entity !is Player) { + return + } + + val player = event.entity as Player + + if (!SOTWHandler.isActive()) { + return + } + + val protected = SOTWHandler.isProtected(player) + + if (protected) { + event.isCancelled = true + } + + if (event is EntityDamageByEntityEvent) { + + var damager: Player? = null + + if (event.damager is Player) { + damager = event.damager as Player + } else if (event.damager is Projectile && (event.damager as Projectile).shooter is Player) { + damager = (event.damager as Projectile).shooter as Player + } + + if (damager != null && SOTWHandler.isProtected(damager)) { + event.isCancelled = true + damager.sendMessage("${ChatColor.RED}You cannot do this while your SOTW Timer is active!") + damager.sendMessage("${ChatColor.RED}Type '${ChatColor.YELLOW}/sotw enable${ChatColor.RED}' to remove your timer.") + } + + } + + if (event.cause != EntityDamageEvent.DamageCause.VOID) { + return + } + + if (SOTWHandler.isActive() && protected) { + return + } + + event.entity.teleport(Bukkit.getServer().worlds[0].spawnLocation.add(0.5,0.0,0.5)) + } + +} + diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/sotw/scheduler/SOTWScheduler.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/sotw/scheduler/SOTWScheduler.kt new file mode 100644 index 0000000..b7b62ff --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/map/sotw/scheduler/SOTWScheduler.kt @@ -0,0 +1,17 @@ +package cc.fyre.hcf.map.sotw.scheduler + +import cc.fyre.hcf.map.sotw.SOTWHandler +import org.bukkit.scheduler.BukkitRunnable + +class SOTWScheduler : BukkitRunnable() { + + override fun run() { + + if (SOTWHandler.isPaused()) { + return + } + + SOTWHandler.tick() + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/mountain/MountainFaction.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/mountain/MountainFaction.kt new file mode 100644 index 0000000..e8b0fd3 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/mountain/MountainFaction.kt @@ -0,0 +1,153 @@ +package cc.fyre.hcf.mountain + +import cc.fyre.shard.util.ChanceUtil +import cc.fyre.shard.util.TimeUtil +import cc.fyre.hcf.HCF +import cc.fyre.hcf.faction.command.admin.FactionEditorCommand +import cc.fyre.hcf.faction.Faction +import cc.fyre.hcf.faction.FactionType +import cc.fyre.hcf.faction.type.SystemFaction +import cc.fyre.hcf.mountain.type.CaveMountain +import cc.fyre.hcf.mountain.type.GlowstoneMountain +import mkremins.fanciful.FancyMessage +import org.apache.commons.lang.StringUtils +import org.bukkit.* +import org.bukkit.block.Block +import org.bukkit.command.CommandSender +import org.bukkit.entity.Player +import java.util.* +import java.util.concurrent.TimeUnit +import kotlin.collections.ArrayList + +/** + * @project hcf + * + * @date 05/09/2020 + * @author xanderume@gmail.com + */ +abstract class MountainFaction(name: String,val types: List,var mountainType: MountainType) : SystemFaction(UUID.randomUUID(),name,FactionType.MOUNTAIN) { + + val blocks = ArrayList() + var remaining = this.blocks.size + var lastBroadcast = 0 + + fun scan() { + this.blocks.clear() + + HCF.instance.server.scheduler.runTaskAsynchronously(HCF.instance) { + + this.claims.forEach{claim -> + + val iterator = claim.blockIterator() + + while (iterator.hasNext()) { + + val block = iterator.next() + + if (!this.types.contains(block.type)) { + continue + } + + this.blocks.add(block.location) + } + + } + + this.remaining = this.blocks.size + } + + } + + fun refill() { + this.remaining = this.blocks.size + + HCF.instance.server.broadcastMessage("${this.mountainType.prefix}${ChatColor.GREEN} All blocks have been reset!") + + if (this.types.size == 1) { + this.blocks.forEach{it.block.type = this.types.first()} + return + } + + this.blocks.forEach{it.block.type = this.types[ChanceUtil.pick(this.blocks.lastIndex)]} + } + + override fun getDisplayName(sender: CommandSender): String { + + if (this.displayName != null) { + return ChatColor.translateAlternateColorCodes('&',this.displayName) + } + + return when (this.mountainType) { + MountainType.CAVE -> "${ChatColor.AQUA}${this.name}" + MountainType.GLOWSTONE -> "${ChatColor.GOLD}${this.name} Mountain" + } + } + + override fun getDisplayName(faction: Faction): String { + + if (this.displayName != null) { + return ChatColor.translateAlternateColorCodes('&',this.displayName) + } + + return when (this.mountainType) { + MountainType.CAVE -> "${ChatColor.AQUA}${this.name}" + MountainType.GLOWSTONE -> "${ChatColor.GOLD}${this.name} Mountain" + } + } + + override fun isBreakingAllowed(block: Block): Boolean { + return this.blocks.contains(block.location) && this.types.contains(block.type) + } + + override fun sendInfo(sender: CommandSender) { + + sender.sendMessage("${ChatColor.GRAY}${ChatColor.STRIKETHROUGH}${StringUtils.repeat("-",53)}") + + val message = FancyMessage(this.getDisplayName(sender)).tooltip("${ChatColor.GREEN}Click to manage ${this.getDisplayName(sender)}${ChatColor.GREEN}!").command("/faction edit ${this.name}") + + if (sender.hasPermission(FactionEditorCommand.PERMISSION)) { + message.send(sender) + } else { + sender.sendMessage(message.toOldMessageFormat()) + } + + sender.sendMessage("${ChatColor.YELLOW}Reset: ${ChatColor.RED}${TimeUtil.formatIntoHHMMSS(this.getTimeUntilNextReset())}") + sender.sendMessage("${ChatColor.YELLOW}Location: ${ChatColor.WHITE}${if (this.getHQ() == null) "None" else "${this.getHQ()!!.blockX}, ${this.getHQ()!!.blockZ} ${if (this.getHQ()!!.world.environment != World.Environment.NORMAL) "(${StringUtils.capitalize(this.getHQ()!!.world.environment.name.lowercase().replace("the",""))})" else ""}"}") + sender.sendMessage("${ChatColor.YELLOW}Remaining: ${ChatColor.RED}${this.remaining}") + sender.sendMessage("${ChatColor.GRAY}${ChatColor.STRIKETHROUGH}${StringUtils.repeat("-",53)}") + } + + private fun getTimeUntilNextReset():Long { + return (MountainHandler.getLastRefill() + RESET_TIME) - System.currentTimeMillis() + } + + fun onBlockBreak(player: Player,block: Block) { + + if (--this.remaining == 0) { + HCF.instance.server.broadcastMessage("${this.mountainType.prefix}${ChatColor.GREEN} All blocks have been mined!") + return + } + + val percentage = (((this.blocks.size.toDouble() - (this.remaining).toDouble()) / this.blocks.size.toDouble()) * 100.0).toInt() + + if (!PERCENTAGE_BROADCASTS.contains(percentage)) { + return + } + + if (this.lastBroadcast == percentage) { + return + } + + this.lastBroadcast = percentage + + Bukkit.getServer().broadcastMessage("${this.mountainType.prefix}${ChatColor.YELLOW} $percentage% has been mined!") + } + + companion object { + + val RESET_TIME = TimeUnit.MINUTES.toMillis(20L) + val PERCENTAGE_BROADCASTS = intArrayOf(25,50,75) + + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/mountain/MountainHandler.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/mountain/MountainHandler.kt new file mode 100644 index 0000000..3f693d0 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/mountain/MountainHandler.kt @@ -0,0 +1,21 @@ +package cc.fyre.hcf.mountain + +/** + * @project hcf + * + * @date 05/09/2020 + * @author xanderume@gmail.com + */ +object MountainHandler { + + private var lastRefill = System.currentTimeMillis() + + fun getLastRefill():Long { + return this.lastRefill + } + + fun setLastRefill(lastRefill: Long) { + this.lastRefill = lastRefill + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/mountain/MountainModule.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/mountain/MountainModule.kt new file mode 100644 index 0000000..3774610 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/mountain/MountainModule.kt @@ -0,0 +1,48 @@ +package cc.fyre.hcf.mountain + +import cc.fyre.hcf.HCF +import cc.fyre.hcf.HCFModule +import cc.fyre.hcf.mountain.command.MountainCreateCommand +import cc.fyre.hcf.mountain.command.MountainRefillCommand +import cc.fyre.hcf.mountain.command.MountainScanCommand +import cc.fyre.hcf.mountain.command.cave.CaveCommand +import cc.fyre.hcf.mountain.command.glowstone.GlowstoneCommand +import cc.fyre.hcf.mountain.command.parameter.MountainTypeParameterProvider +import cc.fyre.hcf.mountain.listener.MountainListener +import cc.fyre.hcf.mountain.service.MountainRefillScheduler +import cc.fyre.shard.command.data.parameter.ParameterAdapter +import org.bukkit.event.Listener + +object MountainModule : HCFModule { + + override fun init(core: HCF) { + // Make time precise, exactly at every 2H + core.server.scheduler.runTaskTimer(core,MountainRefillScheduler,(MountainFaction.RESET_TIME / 1000L) * 20,(MountainFaction.RESET_TIME / 1000L) * 20) + } + + override fun shutdown(core: HCF) { + } + + override fun getCommands(): List> { + return listOf( + CaveCommand::class.java, + GlowstoneCommand::class.java, + + MountainScanCommand::class.java, + MountainCreateCommand::class.java, + MountainRefillCommand::class.java, + ) + } + + override fun getAdapters(): Map, ParameterAdapter<*>> { + return mapOf( + MountainType::class.java to MountainTypeParameterProvider + ) + } + + override fun getListeners(): List { + return listOf( + MountainListener + ) + } +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/mountain/MountainType.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/mountain/MountainType.kt new file mode 100644 index 0000000..2009570 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/mountain/MountainType.kt @@ -0,0 +1,10 @@ +package cc.fyre.hcf.mountain + +import org.bukkit.ChatColor + +enum class MountainType(val prefix: String) { + + CAVE("${ChatColor.AQUA}[Cave]"), + GLOWSTONE("${ChatColor.GOLD}[Glowstone Mountain]"); + +} diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/mountain/command/MountainCreateCommand.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/mountain/command/MountainCreateCommand.kt new file mode 100644 index 0000000..024152b --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/mountain/command/MountainCreateCommand.kt @@ -0,0 +1,48 @@ +package cc.fyre.hcf.mountain.command + +import cc.fyre.shard.command.data.command.Command +import cc.fyre.shard.command.data.parameter.Parameter +import cc.fyre.hcf.faction.FactionHandler +import cc.fyre.hcf.faction.menu.system.SystemEditMenu +import cc.fyre.hcf.mountain.MountainFaction +import cc.fyre.hcf.mountain.MountainType +import cc.fyre.hcf.mountain.type.CaveMountain +import cc.fyre.hcf.mountain.type.GlowstoneMountain +import org.bukkit.ChatColor +import org.bukkit.command.CommandSender +import org.bukkit.entity.Player + +/** + * @project hcf + * + * @date 06/09/2020 + * @author xanderume@gmail.com + */ +object MountainCreateCommand { + + @JvmStatic + @Command(names = ["mountain create","mountain create"],permission = "hcf.command.mountain.create") + fun execute(sender: CommandSender, @Parameter(name = "name")name: String,@Parameter(name = "type")type: MountainType) { + + if (FactionHandler.getFactionByName(name) != null) { + sender.sendMessage("${ChatColor.RED}That faction already exists!") + return + } + + val faction = when (type) { + MountainType.CAVE -> CaveMountain(name) + MountainType.GLOWSTONE -> GlowstoneMountain(name) + } + + FactionHandler.update(faction) + + faction.flagForSave() + + if (sender !is Player) { + return + } + + SystemEditMenu(faction).open(sender) + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/mountain/command/MountainRefillCommand.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/mountain/command/MountainRefillCommand.kt new file mode 100644 index 0000000..c2bf486 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/mountain/command/MountainRefillCommand.kt @@ -0,0 +1,24 @@ +package cc.fyre.hcf.mountain.command + +import cc.fyre.shard.command.data.command.Command +import cc.fyre.shard.command.data.parameter.Parameter +import cc.fyre.hcf.mountain.MountainFaction +import org.bukkit.command.CommandSender + +/** + * @project hcf + * + * @date 06/09/2020 + * @author xanderume@gmail.com + */ +object MountainRefillCommand { + + @JvmStatic + @Command(names = ["mountain refill","mountain respawn"],hidden = true,permission = "hcf.command.mountain.refill") + fun execute(sender: CommandSender, @Parameter(name = "mountain")faction: MountainFaction) { + faction.refill() + faction.flagForSave() + } + + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/mountain/command/MountainScanCommand.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/mountain/command/MountainScanCommand.kt new file mode 100644 index 0000000..72de562 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/mountain/command/MountainScanCommand.kt @@ -0,0 +1,27 @@ +package cc.fyre.hcf.mountain.command + +import cc.fyre.shard.command.data.command.Command +import cc.fyre.shard.command.data.parameter.Parameter +import cc.fyre.hcf.mountain.MountainFaction +import org.bukkit.ChatColor +import org.bukkit.command.CommandSender + +/** + * @project hcf + * + * @date 06/09/2020 + * @author xanderume@gmail.com + */ +object MountainScanCommand { + + @JvmStatic + @Command(names = ["mountain scan"],hidden = true,permission = "hcf.command.mountain.scan") + fun execute(sender: CommandSender,@Parameter(name = "mountain")faction: MountainFaction) { + faction.scan() + faction.flagForSave() + + sender.sendMessage("${faction.mountainType.prefix}${ChatColor.AQUA} Scanned ${faction.getDisplayName(sender)}${ChatColor.AQUA}!") + } + + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/mountain/command/cave/CaveCommand.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/mountain/command/cave/CaveCommand.kt new file mode 100644 index 0000000..d00b841 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/mountain/command/cave/CaveCommand.kt @@ -0,0 +1,31 @@ +package cc.fyre.hcf.mountain.command.cave + +import cc.fyre.shard.command.data.command.Command +import cc.fyre.hcf.faction.FactionHandler +import cc.fyre.hcf.mountain.type.CaveMountain + +import org.bukkit.ChatColor +import org.bukkit.command.CommandSender + +/** + * @project hcf + * + * @date 10/09/2020 + * @author xanderume@gmail.com + */ +object CaveCommand { + + @Command(names = ["cave"]) + fun execute(sender: CommandSender) { + + val factions = FactionHandler.getAllSystemFactions().filterIsInstance() + + if (factions.isEmpty()) { + sender.sendMessage("${ChatColor.RED}Unable to fetch cave data.") + return + } + + factions.forEach{it.sendInfo(sender)} + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/mountain/command/glowstone/GlowstoneCommand.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/mountain/command/glowstone/GlowstoneCommand.kt new file mode 100644 index 0000000..4cc0881 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/mountain/command/glowstone/GlowstoneCommand.kt @@ -0,0 +1,30 @@ +package cc.fyre.hcf.mountain.command.glowstone + +import cc.fyre.shard.command.data.command.Command +import cc.fyre.hcf.faction.FactionHandler +import cc.fyre.hcf.mountain.type.GlowstoneMountain +import org.bukkit.ChatColor +import org.bukkit.command.CommandSender + +/** + * @project hcf + * + * @date 05/09/2020 + * @author xanderume@gmail.com + */ +object GlowstoneCommand { + + @Command(names = ["glowstone","glow"]) + fun execute(sender: CommandSender) { + + val factions = FactionHandler.getAllSystemFactions().filterIsInstance() + + if (factions.isEmpty()) { + sender.sendMessage("${ChatColor.RED}Unable to fetch glowstone data.") + return + } + + factions.forEach{it.sendInfo(sender)} + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/mountain/command/parameter/MountainTypeParameterProvider.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/mountain/command/parameter/MountainTypeParameterProvider.kt new file mode 100644 index 0000000..89943e5 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/mountain/command/parameter/MountainTypeParameterProvider.kt @@ -0,0 +1,33 @@ +package cc.fyre.hcf.mountain.command.parameter + +import cc.fyre.shard.command.data.parameter.ParameterAdapter +import cc.fyre.hcf.mountain.MountainFaction +import cc.fyre.hcf.mountain.MountainType +import org.bukkit.ChatColor +import org.bukkit.command.CommandSender +import org.bukkit.entity.Player + +/** + * @project hcf + * + * @date 06/09/2020 + * @author xanderume@gmail.com + */ +object MountainTypeParameterProvider : ParameterAdapter { + + override fun transform(sender: CommandSender, source: String): MountainType? { + + return try { + MountainType.valueOf(source.uppercase()) + } catch (ex: Exception) { + sender.sendMessage("${ChatColor.RED}Mountain type '$source' not found.") + return null + } + + } + + override fun tabComplete(player: Player, flags: Set, source: String): List { + return emptyList() + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/mountain/listener/MountainListener.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/mountain/listener/MountainListener.kt new file mode 100644 index 0000000..f99bf94 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/mountain/listener/MountainListener.kt @@ -0,0 +1,40 @@ +package cc.fyre.hcf.mountain.listener + +import cc.fyre.hcf.HCF +import cc.fyre.hcf.faction.FactionHandler +import cc.fyre.hcf.mountain.MountainFaction +import org.bukkit.event.EventHandler +import org.bukkit.event.EventPriority +import org.bukkit.event.Listener +import org.bukkit.event.block.BlockBreakEvent + +/** + * @project hcf + * + * @date 06/09/2020 + * @author xanderume@gmail.com + */ +object MountainListener : Listener { + + @EventHandler(priority = EventPriority.MONITOR) + private fun onBlockBreak(event: BlockBreakEvent) { + + if (event.isCancelled) { + return + } + + val faction = FactionHandler.getFactionByLocation(event.block.location) + + if (faction !is MountainFaction) { + return + } + + if (!faction.blocks.contains(event.block.location)) { + return + } + + faction.onBlockBreak(event.player,event.block) + faction.flagForSave() + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/mountain/service/MountainRefillScheduler.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/mountain/service/MountainRefillScheduler.kt new file mode 100644 index 0000000..81ddf57 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/mountain/service/MountainRefillScheduler.kt @@ -0,0 +1,18 @@ +package cc.fyre.hcf.mountain.service + +import cc.fyre.hcf.faction.FactionHandler +import cc.fyre.hcf.mountain.MountainFaction + +/** + * @project hcf + * + * @date 06/09/2020 + * @author xanderume@gmail.com + */ +object MountainRefillScheduler : Runnable { + + override fun run() { + FactionHandler.getAllSystemFactions().filterIsInstance().forEach{it.refill()} + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/mountain/type/CaveMountain.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/mountain/type/CaveMountain.kt new file mode 100644 index 0000000..7390a2a --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/mountain/type/CaveMountain.kt @@ -0,0 +1,14 @@ +package cc.fyre.hcf.mountain.type + +import cc.fyre.hcf.mountain.MountainFaction +import cc.fyre.hcf.mountain.MountainType +import org.bukkit.Material + +/** + * @project hcf + * + * @date 10/09/2020 + * @author xanderume@gmail.com + */ +class CaveMountain(name: String) : MountainFaction(name,listOf(Material.IRON_ORE,Material.GOLD_ORE,Material.DIAMOND_ORE,Material.EMERALD_ORE), + MountainType.CAVE) \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/mountain/type/GlowstoneMountain.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/mountain/type/GlowstoneMountain.kt new file mode 100644 index 0000000..fcc4e99 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/mountain/type/GlowstoneMountain.kt @@ -0,0 +1,13 @@ +package cc.fyre.hcf.mountain.type + +import cc.fyre.hcf.mountain.MountainFaction +import cc.fyre.hcf.mountain.MountainType +import org.bukkit.Material + +/** + * @project hcf + * + * @date 05/09/2020 + * @author xanderume@gmail.com + */ +class GlowstoneMountain(name: String) : MountainFaction(name,arrayListOf(Material.GLOWSTONE), MountainType.GLOWSTONE) \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/pillar/Pillar.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/pillar/Pillar.kt new file mode 100644 index 0000000..bb45079 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/pillar/Pillar.kt @@ -0,0 +1,16 @@ +package cc.fyre.hcf.pillar + +import org.bukkit.Location +import org.bukkit.Material + +/** + * @project hcf + * + * @date 27/08/2020 + * @author xanderume@gmail.com + */ +class Pillar(val type: PillarType, val location: Location, val material: Material, val data: Short) { + + constructor(type: PillarType, location: Location, material: Material):this(type,location,material,0) + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/pillar/PillarHandler.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/pillar/PillarHandler.kt new file mode 100644 index 0000000..ed832c4 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/pillar/PillarHandler.kt @@ -0,0 +1,157 @@ +package cc.fyre.hcf.pillar + +import com.google.common.collect.HashBasedTable +import org.bukkit.Location +import org.bukkit.Material +import org.bukkit.entity.Player +import java.lang.Exception +import java.util.* +import java.util.function.Predicate + + +/** + * @project hcf + * + * @date 27/08/2020 + * @author xanderume@gmail.com + */ + +// Rewrite & cleanup of https://github.com/iPvP-MC/iHCF/master/com/doctordark/hcf/visualise/VisualiseHandler.java + +object PillarHandler { + + private val pillars = HashBasedTable.create() + + fun unLoad(uuid: UUID) { + + val iterator = this.pillars.row(uuid).iterator() + + while (iterator.hasNext()) { + + try { + iterator.remove() + } catch (ex: Exception) { + continue + } + + } + + } + + fun getPillarByLocation(uuid: UUID, location: Location): Pillar? { + return this.pillars.get(uuid,location) + } + + fun getAllPillarsByPlayer(uuid: UUID):MutableSet { + return this.pillars.row(uuid).values.toMutableSet() + } + + fun getAllPillarsByPlayer(uuid: UUID,type: PillarType):MutableSet { + return this.pillars.row(uuid).filter{it.value.type == type}.values.toMutableSet() + } + + fun createPillars(player: Player, type: PillarType, locations: Collection, material: Material, overwrite: Boolean) { + this.createPillars(player,type,locations,material,0,overwrite) + } + + fun createPillars(player: Player, type: PillarType, locations: Collection, material: Material, data: Int, overwrite: Boolean) { + this.createPillars(player,type,locations,Material.GLASS,material,data,overwrite) + } + + fun createPillars(player: Player, type: PillarType, locations: Collection, origin: Material, material: Material, data: Int, overwrite: Boolean) { + + for (location in locations) { + + if (this.pillars.contains(player.uniqueId,location) && !overwrite) { + continue + } + + if (location.block.type.isSolid || location.block.type != Material.AIR) { + continue + } + + var blockType = origin + + if (type != PillarType.CLAIM_BORDER) { + + if (location.blockY == 0 || location.blockY % 3 == 0) { + blockType = material + } + + } + + Pillar(type,location,blockType,data.toShort()).also{pillar -> + player.sendBlockChange(location,pillar.material,pillar.data.toByte()) + this.pillars.put(player.uniqueId,location,pillar) + } + + } + + } + + fun sendPillarsAsync(player: Player, type: PillarType, locations: Collection, material: Material, overwrite: Boolean) { + + for (location in locations) { + + if (this.pillars.contains(player.uniqueId,location) && !overwrite) { + continue + } + + location.world.getChunkAtAsync(location) { + + if (location.block.type.isSolid || location.block.type != Material.AIR) { + return@getChunkAtAsync + } + + var blockType = Material.GLASS + + if (type != PillarType.CLAIM_BORDER) { + + if (location.blockY == 0 || location.blockY % 3 == 0) { + blockType = material + } + + } + + val pillar = Pillar(type,location,blockType) + + player.sendBlockChange(location,pillar.material,pillar.data.toByte()) + + this.pillars.put(player.uniqueId,location,pillar) + } + + } + + } + + fun removePillar(player: Player,location: Location) { + + val pillar = this.pillars.remove(player.uniqueId,location) ?: return + + if (pillar.material == location.block.type && pillar.data == location.block.data.toShort()) { + return + } + + player.sendBlockChange(location,location.block.type,location.block.data) + } + + fun destroyPillars(player: Player, type: PillarType) { + this.destroyPillars(player,type) { + true + } + } + + fun destroyPillars(player: Player, locations: Collection) { + locations.forEach{this.removePillar(player,it)} + } + + fun destroyPillars(player: Player, type: PillarType, predicate: Predicate = Predicate { true }) { + + if (!this.pillars.containsRow(player.uniqueId)) { + return + } + + HashMap(this.pillars.row(player.uniqueId)).filter{predicate.test(it.value) && (it.value == null || it.value.type == type)}.forEach{this.removePillar(player,it.key)} + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/pillar/PillarModule.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/pillar/PillarModule.kt new file mode 100644 index 0000000..4f1391a --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/pillar/PillarModule.kt @@ -0,0 +1,44 @@ +package cc.fyre.hcf.pillar + +import cc.fyre.hcf.HCF +import cc.fyre.hcf.HCFModule +import cc.fyre.hcf.pillar.listener.PillarListener +import cc.fyre.hcf.pillar.listener.PillarPacketListener +import cc.fyre.hcf.pillar.wall.PillarWallRegistry +import cc.fyre.hcf.pillar.wall.PillarWallThread +import cc.fyre.hcf.pillar.wall.type.GamePillarWall +import cc.fyre.hcf.pillar.wall.type.PvPTimerPillarWall +import cc.fyre.hcf.pillar.wall.type.SpawnTagPillarWall +import cc.fyre.shard.command.data.parameter.ParameterAdapter +import org.bukkit.event.Listener + +object PillarModule : HCFModule { + + override fun init(core: HCF) { + PillarWallRegistry.register(GamePillarWall) + PillarWallRegistry.register(SpawnTagPillarWall) + PillarWallRegistry.register(PvPTimerPillarWall) + + PillarWallThread.start() + } + + override fun shutdown(core: HCF) {} + + override fun getCommands(): List> { + return listOf() + } + + override fun getAdapters(): Map, ParameterAdapter<*>> { + return mapOf() + } + + override fun getListeners(): List { + return listOf( + PillarListener, + PillarPacketListener, + + PillarWallThread + ) + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/pillar/PillarType.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/pillar/PillarType.kt new file mode 100644 index 0000000..04ea038 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/pillar/PillarType.kt @@ -0,0 +1,18 @@ +package cc.fyre.hcf.pillar + +import org.bukkit.Material + +enum class PillarType(val materials: Array) { + + CLAIM(arrayOf( + Material.DIAMOND_BLOCK, Material.GOLD_BLOCK, Material.REDSTONE_BLOCK, + Material.LAPIS_BLOCK, Material.LOG, Material.BRICK, Material.WOOD, + Material.REDSTONE_BLOCK, Material.LAPIS_BLOCK, Material.CHEST, + Material.MELON_BLOCK, Material.STONE, Material.COBBLESTONE, + Material.COAL_BLOCK, Material.DIAMOND_ORE, Material.COAL_ORE, + Material.GOLD_ORE, Material.REDSTONE_ORE, Material.FURNACE + )), + CLAIM_BORDER(arrayOf(Material.STAINED_GLASS)), + CLAIM_SELECTION(arrayOf(Material.EMERALD_BLOCK)); + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/pillar/listener/PillarListener.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/pillar/listener/PillarListener.kt new file mode 100644 index 0000000..644637a --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/pillar/listener/PillarListener.kt @@ -0,0 +1,28 @@ +package cc.fyre.hcf.pillar.listener + +import cc.fyre.hcf.pillar.PillarHandler +import org.bukkit.event.EventHandler +import org.bukkit.event.EventPriority +import org.bukkit.event.Listener +import org.bukkit.event.entity.PlayerDeathEvent +import org.bukkit.event.player.PlayerQuitEvent + +/** + * @project hcf + * + * @date 28/08/2020 + * @author xanderume@gmail.com + */ +object PillarListener : Listener { + + @EventHandler(priority = EventPriority.MONITOR) + private fun onPlayerQuit(event: PlayerQuitEvent) { + PillarHandler.unLoad(event.player.uniqueId) + } + + @EventHandler(priority = EventPriority.MONITOR) + private fun onPlayerDeath(event: PlayerDeathEvent) { + PillarHandler.unLoad(event.entity.uniqueId) + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/pillar/listener/PillarPacketListener.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/pillar/listener/PillarPacketListener.kt new file mode 100644 index 0000000..43f1a9c --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/pillar/listener/PillarPacketListener.kt @@ -0,0 +1,73 @@ +package cc.fyre.hcf.pillar.listener + +import cc.fyre.hcf.HCF +import cc.fyre.hcf.pillar.PillarHandler +import com.comphenix.protocol.PacketType +import com.comphenix.protocol.ProtocolLibrary +import com.comphenix.protocol.events.PacketAdapter +import com.comphenix.protocol.events.PacketEvent + +import org.bukkit.GameMode +import org.bukkit.Location +import org.bukkit.event.Listener + +/** + * @project hcf + * + * @date 28/08/2020 + * @author xanderume@gmail.com + */ +object PillarPacketListener : Listener,PacketAdapter(HCF.instance,listOf(PacketType.Play.Client.BLOCK_DIG,PacketType.Play.Client.BLOCK_PLACE)) { + + init { + ProtocolLibrary.getProtocolManager().addPacketListener(this) + } + + override fun onPacketReceiving(event: PacketEvent) { + + if (event.packet.type == PacketType.Play.Client.BLOCK_PLACE) { + + val pillar = PillarHandler.getPillarByLocation(event.player.uniqueId,Location( + event.player.world, + event.packet.integers.read(0).toDouble(), + event.packet.integers.read(1).toDouble(), + event.packet.integers.read(2).toDouble() + )) + + if (pillar == null || event.player.gameMode == GameMode.CREATIVE) { + return + } + + event.isCancelled = true + return + } + + val action = event.packet.integers.read(4) + + if (!(action == 0 || action == 2)) { + return + } + + val x = event.packet.integers.read(0) + val y = event.packet.integers.read(1) + val z = event.packet.integers.read(2) + + val location = Location(event.player.world,x.toDouble(),y.toDouble(),z.toDouble()) + + val pillar = PillarHandler.getPillarByLocation(event.player.uniqueId,location) ?: return + + event.isCancelled = true + + if (action == 2) { + event.player.sendBlockChange(location,pillar.material,pillar.data.toByte()) + return + } + + if (event.player.gameMode == GameMode.CREATIVE) { + return + } + + event.player.sendBlockChange(location,pillar.material,pillar.data.toByte()) + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/pillar/wall/PillarWall.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/pillar/wall/PillarWall.kt new file mode 100644 index 0000000..ac8e307 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/pillar/wall/PillarWall.kt @@ -0,0 +1,29 @@ +package cc.fyre.hcf.pillar.wall + +import org.bukkit.entity.Player +import cc.fyre.hcf.faction.Faction +import cc.fyre.hcf.faction.type.PlayerFaction +import org.bukkit.Material + +/** + * @project hcf + * + * @date 02/01/2021 + * @author xanderume@gmail.com + */ +interface PillarWall { + + fun getMaterial(player: Player):Pair + fun shouldCheck(player: Player,faction: PlayerFaction?):Boolean + fun shouldApply(player: Player, factionAt: Faction, playerFaction: PlayerFaction?):Boolean + + companion object { + + const val WALL_HEIGHT = 4 + + const val REGION_DISTANCE = 7 + const val REGION_DISTANCE_SQUARED = REGION_DISTANCE * REGION_DISTANCE + + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/pillar/wall/PillarWallRegistry.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/pillar/wall/PillarWallRegistry.kt new file mode 100644 index 0000000..b30a9f5 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/pillar/wall/PillarWallRegistry.kt @@ -0,0 +1,15 @@ +package cc.fyre.hcf.pillar.wall + +object PillarWallRegistry { + + private val walls = mutableListOf() + + fun getAllWalls():List { + return this.walls + } + + fun register(wall: PillarWall) { + this.walls.add(wall) + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/pillar/wall/PillarWallThread.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/pillar/wall/PillarWallThread.kt new file mode 100644 index 0000000..bf1261c --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/pillar/wall/PillarWallThread.kt @@ -0,0 +1,151 @@ +package cc.fyre.hcf.pillar.wall + +import cc.fyre.hcf.faction.FactionHandler +import cc.fyre.hcf.faction.claim.Claim +import cc.fyre.hcf.faction.claim.ClaimHandler +import cc.fyre.hcf.pillar.PillarHandler +import cc.fyre.hcf.pillar.PillarType +import org.bukkit.Bukkit +import org.bukkit.GameMode +import org.bukkit.Location +import org.bukkit.Material +import org.bukkit.entity.Player +import org.bukkit.event.EventHandler +import org.bukkit.event.EventPriority +import org.bukkit.event.Listener +import org.bukkit.event.player.PlayerQuitEvent +import org.bukkit.material.MaterialData +import java.util.* +import java.util.concurrent.ConcurrentHashMap + +object PillarWallThread : Thread("HCF - Pillar Wall Thread"), Listener { + + private val blocks = ConcurrentHashMap>() + + override fun run() { + + while (true) { + + try { + Bukkit.getServer().onlinePlayers.forEach{this.tick(it)} + } catch (ex: Exception) { + ex.printStackTrace() + } + + try { + sleep(250L) + } catch (ex: InterruptedException) { + ex.printStackTrace() + } + + } + + } + + private fun tick(player: Player) { + + try { + + val claims = mutableMapOf>() + + if (player.gameMode == GameMode.CREATIVE) { + return + } + + val faction = FactionHandler.getFactionByPlayer(player.uniqueId) + + val walls = PillarWallRegistry.getAllWalls().filter{it.shouldCheck(player,faction)} + + for (wall in walls) { + + for (entry in ClaimHandler.getClaimDataByRadius(player.location,PillarWall.REGION_DISTANCE,PillarWall.REGION_DISTANCE)) { + + if (entry.key.contains(player.location)) { + continue + } + + if (!wall.shouldApply(player,entry.value,faction)) { + continue + } + + claims.putIfAbsent(wall, arrayListOf()) + claims[wall]!!.add(entry.key) + } + + } + + if (claims.isEmpty()) { + this.clearPlayer(player) + } else { + this.blocks.putIfAbsent(player.uniqueId,hashMapOf()) + + val iterator = this.blocks[player.uniqueId]!!.entries.iterator() + + while (iterator.hasNext()) { + + val (location,time) = iterator.next() + + if (System.currentTimeMillis() >= time) { + + if (!location.world.isChunkLoaded(location.blockX shr 4,location.blockZ shr 4)) { + continue + } + + PillarHandler.removePillar(player,location) + + iterator.remove() + } + + } + claims.forEach{ (key, value) -> value.forEach{ claim -> this.sendClaimToPlayer(player,key,claim)}} + } + } catch (ex: Exception) { + ex.printStackTrace() + } + + } + + private fun sendClaimToPlayer(player: Player,wall: PillarWall,claim: Claim) { + // This gets us all the coordinates on the outside of the claim. + // Probably could be made better + for (coordinate in claim) { + val onPlayerY = Location(player.world,coordinate.x.toDouble(),player.location.y,coordinate.z.toDouble()) + + // Ignore an entire pillar if the block closest to the player is further than the max distance (none of the others will be close enough, either) + if (onPlayerY.distanceSquared(player.location) > PillarWall.REGION_DISTANCE_SQUARED) { + continue + } + + val locations = arrayListOf() + + for (i in -(PillarWall.WALL_HEIGHT)..PillarWall.WALL_HEIGHT) { + + val location = onPlayerY.clone().add(0.0, i.toDouble(), 0.0) + + locations.add(location) + this.blocks[player.uniqueId]!![location] = System.currentTimeMillis() + 2500L + } + + val material = wall.getMaterial(player) + + PillarHandler.createPillars(player,PillarType.CLAIM_BORDER,locations,material.first,material.first,material.second,true) + } + + } + + private fun clearPlayer(player: Player) { + + if (!this.blocks.containsKey(player.uniqueId)) { + return + } + + this.blocks[player.uniqueId]!!.keys.forEach{ _ -> PillarHandler.destroyPillars(player,PillarType.CLAIM_BORDER)} + this.blocks.remove(player.uniqueId) + } + + @EventHandler(priority = EventPriority.MONITOR) + private fun onPlayerQuit(event: PlayerQuitEvent) { + this.blocks.remove(event.player.uniqueId) + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/pillar/wall/type/GamePillarWall.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/pillar/wall/type/GamePillarWall.kt new file mode 100644 index 0000000..9692e94 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/pillar/wall/type/GamePillarWall.kt @@ -0,0 +1,33 @@ +package cc.fyre.hcf.pillar.wall.type + +import cc.fyre.hcf.faction.Faction +import cc.fyre.hcf.faction.type.PlayerFaction +import cc.fyre.hcf.game.GameFaction +import cc.fyre.hcf.pillar.wall.PillarWall +import org.bukkit.Material +import org.bukkit.entity.Player + +/** + * @project hcf + * + * @date 02/01/2021 + * @author xanderume@gmail.com + */ +object GamePillarWall : PillarWall { + + override fun getMaterial(player: Player): Pair { + return Pair(Material.STAINED_GLASS,14) + } + + override fun shouldCheck(player: Player,faction: PlayerFaction?): Boolean { + return faction == null + || faction.onlineMembers < PlayerFaction.GAME_REQUIRED_MEMBERS + } + + override fun shouldApply(player: Player, factionAt: Faction, playerFaction: PlayerFaction?): Boolean { + return factionAt is GameFaction + && (playerFaction == null || playerFaction.onlineMembers < PlayerFaction.GAME_REQUIRED_MEMBERS) + && factionAt.isMajorEvent() + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/pillar/wall/type/PvPTimerPillarWall.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/pillar/wall/type/PvPTimerPillarWall.kt new file mode 100644 index 0000000..e47138c --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/pillar/wall/type/PvPTimerPillarWall.kt @@ -0,0 +1,31 @@ +package cc.fyre.hcf.pillar.wall.type + +import cc.fyre.hcf.faction.Faction +import cc.fyre.hcf.faction.type.PlayerFaction +import cc.fyre.hcf.pillar.wall.PillarWall +import cc.fyre.hcf.timer.TimerHandler +import cc.fyre.hcf.timer.TimerType +import org.bukkit.Material +import org.bukkit.entity.Player + +/** + * @project hcf + * + * @date 02/01/2021 + * @author xanderume@gmail.com + */ +object PvPTimerPillarWall : PillarWall { + + override fun getMaterial(player: Player): Pair { + return Pair(Material.STAINED_GLASS,14) + } + + override fun shouldCheck(player: Player,faction: PlayerFaction?): Boolean { + return TimerHandler.hasTimer(player.uniqueId, TimerType.PVP_TIMER) + } + + override fun shouldApply(player: Player, factionAt: Faction, playerFaction: PlayerFaction?): Boolean { + return factionAt is PlayerFaction && factionAt.id != playerFaction?.id + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/pillar/wall/type/SpawnTagPillarWall.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/pillar/wall/type/SpawnTagPillarWall.kt new file mode 100644 index 0000000..c0aa1fe --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/pillar/wall/type/SpawnTagPillarWall.kt @@ -0,0 +1,33 @@ +package cc.fyre.hcf.pillar.wall.type + +import cc.fyre.hcf.faction.Faction +import cc.fyre.hcf.faction.FactionMetadata +import cc.fyre.hcf.faction.type.PlayerFaction +import cc.fyre.hcf.faction.type.SystemFaction +import cc.fyre.hcf.pillar.wall.PillarWall +import cc.fyre.hcf.timer.TimerHandler +import cc.fyre.hcf.timer.TimerType +import org.bukkit.Material +import org.bukkit.entity.Player + +/** + * @project hcf + * + * @date 02/01/2021 + * @author xanderume@gmail.com + */ +object SpawnTagPillarWall : PillarWall { + + override fun getMaterial(player: Player): Pair { + return Pair(Material.STAINED_GLASS,14) + } + + override fun shouldCheck(player: Player,faction: PlayerFaction?): Boolean { + return TimerHandler.hasTimer(player.uniqueId,TimerType.SPAWN_TAG) + } + + override fun shouldApply(player: Player, factionAt: Faction, playerFaction: PlayerFaction?): Boolean { + return factionAt is SystemFaction && factionAt.hasMetadata(FactionMetadata.SAFE_ZONE) + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/pvpclass/PvPClass.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/pvpclass/PvPClass.kt new file mode 100644 index 0000000..08c6b3c --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/pvpclass/PvPClass.kt @@ -0,0 +1,86 @@ +package cc.fyre.hcf.pvpclass + +import cc.fyre.hcf.HCF +import cc.fyre.hcf.pvpclass.energy.EnergyEffect +import cc.fyre.hcf.pvpclass.item.ConsumableItem +import com.google.common.collect.HashBasedTable +import org.bukkit.Material +import org.bukkit.entity.Player +import org.bukkit.potion.PotionEffect +import org.bukkit.potion.PotionEffectType +import java.util.* + +/** + * @project hcf + * + * @date 10/09/2020 + * @author xanderume@gmail.com + */ +abstract class PvPClass(val type: PvPClassType) { + + protected val effects = mutableMapOf() + + internal val energy = mutableMapOf() + internal val abilities = mutableMapOf() + internal val consumables = mutableMapOf() + + private val cooldowns = HashBasedTable.create() + + fun getName():String { + return this.type.displayName + } + + abstract fun init(core: HCF) + + abstract fun onEnable(player: Player) + abstract fun onDisable(player: Player) + + abstract fun isEquipped(player: Player):Boolean + abstract fun isEnergyBased():Boolean + + fun getPassiveEffect(effect: PotionEffectType):PotionEffect? { + return this.effects[effect] + } + + fun getPassiveEffects():List { + return this.effects.values.toList() + } + + fun getEnergy(uuid: UUID):Int { + return this.energy[uuid] ?: 0 + } + + fun setEnergy(uuid: UUID,energy: Int) { + this.energy[uuid] = energy + } + + fun getCooldown(player: Player,consumable: ConsumableItem):Long { + + if (!this.cooldowns.contains(player.uniqueId,consumable.material)) { + return 0L + } + + return (this.cooldowns.get(player.uniqueId,consumable.material)!! + consumable.cooldown) - System.currentTimeMillis() + } + + fun setCooldown(player: Player,consumable: ConsumableItem) { + this.cooldowns.put(player.uniqueId,consumable.material,System.currentTimeMillis()) + } + + fun getAbilityByItem(material: Material):EnergyEffect? { + return this.abilities[material] + } + + fun getConsumableByItem(material: Material):ConsumableItem? { + return this.consumables[material] + } + + override fun equals(other: Any?): Boolean { + return other is PvPClass && other.type == this.type + } + + override fun hashCode(): Int { + return Objects.hash(this.type.name) + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/pvpclass/PvPClassHandler.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/pvpclass/PvPClassHandler.kt new file mode 100644 index 0000000..f2b1f16 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/pvpclass/PvPClassHandler.kt @@ -0,0 +1,121 @@ +package cc.fyre.hcf.pvpclass + +import cc.fyre.hcf.HCF +import cc.fyre.hcf.pvpclass.event.PvPClassEquipEvent +import cc.fyre.hcf.pvpclass.event.PvPClassUnEquipEvent +import cc.fyre.shard.util.bukkit.PotionUtil +import com.google.common.collect.HashBasedTable +import org.bukkit.Bukkit +import org.bukkit.entity.Player +import org.bukkit.event.Listener +import org.bukkit.potion.PotionEffect +import org.bukkit.potion.PotionEffectType +import java.util.* + + +/** + * @project hcf + * + * @date 10/09/2020 + * @author xanderume@gmail.com + */ +object PvPClassHandler { + + private val classes = mutableMapOf() + private val classesByPlayer = mutableMapOf() + + internal val effects = HashBasedTable.create() + + fun register(pvpClass: PvPClass) { + pvpClass.init(HCF.instance) + + if (pvpClass is Listener) { + Bukkit.getServer().pluginManager.registerEvents(pvpClass,HCF.instance) + } + + this.classes[pvpClass.type] = pvpClass + } + + fun getAllPvPClasses():List { + return this.classes.values.toList() + } + + fun getAllPvPClassesByPlayers():Map { + return this.classesByPlayer.entries.associate{it.key to this.classes[it.value]!!}.toMap() + } + + fun getPvPClassByType(type: PvPClassType):PvPClass? { + return this.classes[type] + } + + fun getPvPClassByPlayer(uuid: UUID):PvPClass? { + + val type = this.classesByPlayer[uuid] + + if (type == null || !this.classes.containsKey(type)) { + return null + } + + return this.classes[type] + } + + fun setPvPClass(player: Player,type: PvPClassType?) { + + if (this.classesByPlayer.containsKey(player.uniqueId)) { + + if (this.classesByPlayer[player.uniqueId] == type) { + return + } + + val pvpClass = this.classes[this.classesByPlayer.remove(player.uniqueId)!!]!! + + Bukkit.getServer().pluginManager.callEvent(PvPClassUnEquipEvent(player,pvpClass)) + + pvpClass.energy.remove(player.uniqueId) + pvpClass.onDisable(player) + pvpClass.getPassiveEffects().filter{player.activePotionEffects.any{effect -> it.type == effect.type + && it.duration > MAX_POTION_TICKS + && it.amplifier == effect.amplifier} + }.forEach{player.removePotionEffect(it.type)} + } + + if (type == null) { + return + } + + val pvpClass = this.classes[type] ?: return + val event = PvPClassEquipEvent(player,pvpClass) + + Bukkit.getServer().pluginManager.callEvent(event) + + if (event.isCancelled) { + return + } + + pvpClass.onEnable(player) + pvpClass.getPassiveEffects().forEach{player.addPotionEffect(it,true)} + + this.classesByPlayer[player.uniqueId] = type + } + + fun addPotionEffect(player: Player,effect: PotionEffect) { + + if (player.activePotionEffects.any{it.type == effect.type && (it.amplifier > effect.amplifier || (it.amplifier == effect.amplifier && it.duration > effect.duration))}) { + return + } + + // only cache the ones are lower then infinite & normal bard speed duration + player.activePotionEffects.firstOrNull{it.type == effect.type && it.duration > 120 && it.duration <= 1_000_000}.also{ + + if (it == null) { + return@also + } + + this.effects.put(player.uniqueId,it.type,it) + } + + player.addPotionEffect(effect,true) + } + + val MAX_POTION_TICKS = (PotionUtil.MAX_POTION_DURATION / 1000) * 20 +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/pvpclass/PvPClassModule.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/pvpclass/PvPClassModule.kt new file mode 100644 index 0000000..7ce565e --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/pvpclass/PvPClassModule.kt @@ -0,0 +1,56 @@ +package cc.fyre.hcf.pvpclass + +import cc.fyre.hcf.HCF +import cc.fyre.hcf.HCFModule +import cc.fyre.hcf.pvpclass.listener.PvPClassListener +import cc.fyre.hcf.pvpclass.scheduler.PvPClassEnergyScheduler +import cc.fyre.hcf.pvpclass.type.ArcherClass +import cc.fyre.hcf.pvpclass.type.MinerClass +import cc.fyre.hcf.pvpclass.type.RogueClass +import cc.fyre.hcf.pvpclass.type.bard.BardClass +import cc.fyre.shard.command.data.parameter.ParameterAdapter +import org.bukkit.Bukkit +import org.bukkit.event.Listener + +object PvPClassModule : HCFModule { + + override fun init(core: HCF) { + PvPClassHandler.register(BardClass) + PvPClassHandler.register(RogueClass) + PvPClassHandler.register(MinerClass) + PvPClassHandler.register(ArcherClass) + + core.server.scheduler.runTaskTimer(core,PvPClassEnergyScheduler,20L,20L) + } + + override fun shutdown(core: HCF) { + Bukkit.getServer().onlinePlayers.forEach{player -> + PvPClassHandler.getPvPClassByPlayer(player.uniqueId)?.getPassiveEffects()?.forEach{effect -> + + if (player.activePotionEffects.none{it.type == effect.type + && it.amplifier == effect.amplifier + && it.duration > PvPClassHandler.MAX_POTION_TICKS} + ) { + return@forEach + } + + player.removePotionEffect(effect.type) + } + } + } + + override fun getCommands(): List> { + return listOf() + } + + override fun getAdapters(): Map, ParameterAdapter<*>> { + return mapOf() + } + + override fun getListeners(): List { + return listOf( + PvPClassListener + ) + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/pvpclass/PvPClassType.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/pvpclass/PvPClassType.kt new file mode 100644 index 0000000..35e9d40 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/pvpclass/PvPClassType.kt @@ -0,0 +1,10 @@ +package cc.fyre.hcf.pvpclass + +enum class PvPClassType(val displayName: String) { + + BARD("Bard"), + MINER("Miner"), + ROGUE("Rogue"), + ARCHER("Archer"); + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/pvpclass/energy/EnergyEffect.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/pvpclass/energy/EnergyEffect.kt new file mode 100644 index 0000000..dd30032 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/pvpclass/energy/EnergyEffect.kt @@ -0,0 +1,24 @@ +package cc.fyre.hcf.pvpclass.energy + +import cc.fyre.hcf.pvpclass.PvPClassHandler +import org.bukkit.Material +import org.bukkit.entity.Player +import org.bukkit.potion.PotionEffect +import java.util.function.Predicate + +open class EnergyEffect(val item: Material, val energy: Int, val effect: PotionEffect?, val predicate: Predicate? = null) { + + open fun consume(player: Player) { + + if (this.predicate != null) { + this.predicate.test(player) + } + + if (this.effect == null) { + return + } + + PvPClassHandler.addPotionEffect(player,this.effect) + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/pvpclass/event/PvPClassEquipEvent.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/pvpclass/event/PvPClassEquipEvent.kt new file mode 100644 index 0000000..7ee34e6 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/pvpclass/event/PvPClassEquipEvent.kt @@ -0,0 +1,35 @@ +package cc.fyre.hcf.pvpclass.event + +import cc.fyre.hcf.pvpclass.PvPClass +import org.bukkit.entity.Player +import org.bukkit.event.Cancellable +import org.bukkit.event.Event +import org.bukkit.event.HandlerList + +/** + * @project hcf + * + * @date 11/09/2020 + * @author xanderume@gmail.com + */ +class PvPClassEquipEvent(val player: Player,val pvpClass: PvPClass) : Event(), Cancellable { + + private var cancelled = false + + override fun isCancelled(): Boolean { + return this.cancelled + } + + override fun setCancelled(cancelled: Boolean) { + this.cancelled = cancelled + } + + override fun getHandlers(): HandlerList { + return handlerList + } + + companion object { + @JvmStatic val handlerList = HandlerList() + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/pvpclass/event/PvPClassUnEquipEvent.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/pvpclass/event/PvPClassUnEquipEvent.kt new file mode 100644 index 0000000..8647bcf --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/pvpclass/event/PvPClassUnEquipEvent.kt @@ -0,0 +1,25 @@ +package cc.fyre.hcf.pvpclass.event + +import cc.fyre.hcf.pvpclass.PvPClass +import org.bukkit.entity.Player + +import org.bukkit.event.Event +import org.bukkit.event.HandlerList + +/** + * @project hcf + * + * @date 11/09/2020 + * @author xanderume@gmail.com + */ +class PvPClassUnEquipEvent(val player: Player,val pvpClass: PvPClass) : Event() { + + override fun getHandlers(): HandlerList { + return handlerList + } + + companion object { + @JvmStatic val handlerList = HandlerList() + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/pvpclass/event/type/ArcherMarkEvent.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/pvpclass/event/type/ArcherMarkEvent.kt new file mode 100644 index 0000000..efc8cb7 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/pvpclass/event/type/ArcherMarkEvent.kt @@ -0,0 +1,24 @@ +package cc.fyre.hcf.pvpclass.event.type + +import org.bukkit.entity.Player +import org.bukkit.event.Event +import org.bukkit.event.HandlerList + +/** + * @project hcf + * + * @date 11/09/2020 + * @author xanderume@gmail.com + */ +class ArcherMarkEvent(val player: Player,val damager: Player,var damage: Double) : Event() { + + override fun getHandlers(): HandlerList { + return handlerList + } + + companion object { + @JvmStatic val handlerList = HandlerList() + } + + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/pvpclass/event/type/BackstabEvent.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/pvpclass/event/type/BackstabEvent.kt new file mode 100644 index 0000000..7255cef --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/pvpclass/event/type/BackstabEvent.kt @@ -0,0 +1,24 @@ +package cc.fyre.hcf.pvpclass.event.type + +import org.bukkit.entity.Player +import org.bukkit.event.Event +import org.bukkit.event.HandlerList + +/** + * @project hcf + * + * @date 11/09/2020 + * @author xanderume@gmail.com + */ +class BackstabEvent(val player: Player,val damager: Player,var damage: Double) : Event() { + + override fun getHandlers(): HandlerList { + return handlerList + } + + companion object { + @JvmStatic val handlerList = HandlerList() + } + + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/pvpclass/event/type/BardEffectEvent.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/pvpclass/event/type/BardEffectEvent.kt new file mode 100644 index 0000000..49a6d6e --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/pvpclass/event/type/BardEffectEvent.kt @@ -0,0 +1,25 @@ +package cc.fyre.hcf.pvpclass.event.type + +import cc.fyre.hcf.pvpclass.type.bard.effect.BardEnergyEffect +import org.bukkit.entity.Player +import org.bukkit.event.Event +import org.bukkit.event.HandlerList + +/** + * @project hcf + * + * @date 11/09/2020 + * @author xanderume@gmail.com + */ +class BardEffectEvent(val player: Player,val receivers: Collection,val effect: BardEnergyEffect) : Event() { + + override fun getHandlers(): HandlerList { + return handlerList + } + + companion object { + @JvmStatic val handlerList = HandlerList() + } + + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/pvpclass/item/ConsumableItem.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/pvpclass/item/ConsumableItem.kt new file mode 100644 index 0000000..f75afc7 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/pvpclass/item/ConsumableItem.kt @@ -0,0 +1,16 @@ +package cc.fyre.hcf.pvpclass.item + +import org.bukkit.Material +import org.bukkit.entity.Player + +/** + * @project hcf + * + * @date 10/09/2020 + * @author xanderume@gmail.com + */ +abstract class ConsumableItem(val material: Material,val cooldown: Long) { + + abstract fun consume(player: Player): Boolean + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/pvpclass/item/type/EffectConsumableItem.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/pvpclass/item/type/EffectConsumableItem.kt new file mode 100644 index 0000000..a799259 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/pvpclass/item/type/EffectConsumableItem.kt @@ -0,0 +1,16 @@ +package cc.fyre.hcf.pvpclass.item.type + +import cc.fyre.hcf.pvpclass.PvPClassHandler +import cc.fyre.hcf.pvpclass.item.ConsumableItem +import org.bukkit.Material +import org.bukkit.entity.Player +import org.bukkit.potion.PotionEffect + +class EffectConsumableItem(material: Material,cooldown: Long,private val effect: PotionEffect) : ConsumableItem(material,cooldown) { + + override fun consume(player: Player): Boolean { + PvPClassHandler.addPotionEffect(player,this.effect) + return true + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/pvpclass/listener/PvPClassListener.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/pvpclass/listener/PvPClassListener.kt new file mode 100644 index 0000000..87f4461 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/pvpclass/listener/PvPClassListener.kt @@ -0,0 +1,192 @@ +package cc.fyre.hcf.pvpclass.listener + +import cc.fyre.hcf.HCF +import cc.fyre.hcf.ability.AbilityHandler +import cc.fyre.hcf.ability.pocketbard.PocketBardAbility +import cc.fyre.hcf.faction.FactionMetadata +import cc.fyre.hcf.pvpclass.PvPClassHandler +import cc.fyre.hcf.pvpclass.type.bard.BardClass +import cc.fyre.hcf.timer.TimerHandler +import cc.fyre.hcf.timer.TimerType +import cc.fyre.shard.util.TimeUtil +import org.bukkit.ChatColor +import org.bukkit.entity.Player +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.entity.PotionEffectExpireEvent +import org.bukkit.event.inventory.EquipmentSetEvent +import org.bukkit.event.player.PlayerInteractEvent +import org.bukkit.event.player.PlayerJoinEvent +import org.bukkit.event.player.PlayerQuitEvent +import org.bukkit.scheduler.BukkitRunnable + +/** + * @project hcf + * + * @date 10/09/2020 + * @author xanderume@gmail.com + */ +object PvPClassListener : Listener { + + @EventHandler(priority = EventPriority.HIGHEST) + private fun onPlayerJoin(event: PlayerJoinEvent) { + + for (pvpClass in PvPClassHandler.getAllPvPClasses()) { + + if (pvpClass.isEquipped(event.player)) { + PvPClassHandler.setPvPClass(event.player,pvpClass.type) + break + } + + } + + } + + @EventHandler(priority = EventPriority.LOWEST) + private fun onPlayerQuit(event: PlayerQuitEvent) { + PvPClassHandler.setPvPClass(event.player,null) + } + + @EventHandler(priority = EventPriority.LOWEST) + private fun onEquipmentSet(event: EquipmentSetEvent) { + + if (event.humanEntity !is Player) { + return + } + + val current = PvPClassHandler.getPvPClassByPlayer(event.humanEntity.uniqueId) + + // current one is equipped no need to check for other one + if (current != null && current.isEquipped(event.humanEntity as Player)) { + return + } + + val new = PvPClassHandler.getAllPvPClasses().firstOrNull{it.isEquipped(event.humanEntity as Player)} + + if (new != null) { + PvPClassHandler.setPvPClass(event.humanEntity as Player,new.type) + return + } + + PvPClassHandler.setPvPClass(event.humanEntity as Player,null) + } + + @EventHandler(priority = EventPriority.MONITOR) + private fun onPlayerInteract(event: PlayerInteractEvent) { + + if (event.action == Action.PHYSICAL) { + return + } + + if (event.item == null) { + return + } + + val pvpClass = PvPClassHandler.getPvPClassByPlayer(event.player.uniqueId) ?: return + + val consumable = pvpClass.getConsumableByItem(event.item.type) ?: return + + val cooldown = pvpClass.getCooldown(event.player,consumable) + + if (cooldown > 0L) { + event.player.sendMessage("${ChatColor.RED}You cannot use this for another ${ChatColor.BOLD}${TimeUtil.formatIntoFancy(cooldown)}${ChatColor.RED}.") + return + } + + if (!consumable.consume(event.player)) { + return + } + + pvpClass.setCooldown(event.player,consumable) + } + + @EventHandler(priority = EventPriority.MONITOR) + private fun onEnergyInteract(event: PlayerInteractEvent) { + + if (!event.action.name.contains("RIGHT")) { + return + } + + if (event.player.itemInHand == null) { + return + } + + val pvpClass = PvPClassHandler.getPvPClassByPlayer(event.player.uniqueId) ?: return + + if (!pvpClass.isEnergyBased()) { + return + } + + val effect = pvpClass.getAbilityByItem(event.player.itemInHand.type) ?: return + + if (pvpClass is BardClass && AbilityHandler.getAbilityByItemStack(event.player.itemInHand) is PocketBardAbility) { + return + } + + if (FactionMetadata.SAFE_ZONE.isValidAtLocation(event.player.location)) { + event.player.sendMessage("${ChatColor.RED}${pvpClass.getName()} effects cannot be used while in spawn.") + return + } + + val cooldown = TimerHandler.getRemaining(event.player.uniqueId, TimerType.ENERGY_COOLDOWN) + + if (cooldown > 0L) { + event.player.sendMessage("${ChatColor.RED}You cannot use this for another ${ChatColor.BOLD}${TimeUtil.formatIntoFancy(cooldown)}${ChatColor.RED}.") + return + } + + val energy = pvpClass.getEnergy(event.player.uniqueId) + + if (energy < effect.energy) { + event.player.sendMessage("${ChatColor.RED}You do not have enough energy for this! You need ${effect.energy} energy, but you only have ${energy.toInt()}.") + return + } + + effect.consume(event.player) + + if (event.player.itemInHand.amount == 1) { + event.player.itemInHand = null + } else { + event.player.itemInHand.amount = event.player.itemInHand.amount - 1 + } + + pvpClass.setEnergy(event.player.uniqueId,energy - effect.energy) + + if (!TimerHandler.hasTimer(event.player.uniqueId, TimerType.PVP_TIMER)) { + TimerHandler.addTimer(event.player.uniqueId, TimerType.SPAWN_TAG) + } + + TimerHandler.addTimer(event.player.uniqueId, TimerType.ENERGY_COOLDOWN) + } + + @EventHandler(priority = EventPriority.MONITOR) + private fun onPotionExpire(event: PotionEffectExpireEvent) { + + if (event.entity !is Player) { + return + } + + val previous = PvPClassHandler.effects.remove(event.entity.uniqueId,event.effect.type) + + //restore all effects that are missing for example infinite speed 2 + if (previous == null || previous.duration > PvPClassHandler.MAX_POTION_TICKS) { + + val effect = PvPClassHandler.getPvPClassByPlayer(event.entity.uniqueId)?.getPassiveEffect(event.effect.type) ?: return + + object : BukkitRunnable() { + + override fun run() { + event.entity.addPotionEffect(effect) + } + + }.runTaskLater(HCF.instance,1L) + return + } + + event.isCancelled = true + event.entity.addPotionEffect(previous,true) + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/pvpclass/scheduler/PvPClassEnergyScheduler.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/pvpclass/scheduler/PvPClassEnergyScheduler.kt new file mode 100644 index 0000000..110961f --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/pvpclass/scheduler/PvPClassEnergyScheduler.kt @@ -0,0 +1,37 @@ +package cc.fyre.hcf.pvpclass.scheduler + +import cc.fyre.hcf.pvpclass.PvPClassHandler +import org.bukkit.Bukkit +import org.bukkit.ChatColor + +object PvPClassEnergyScheduler : Runnable { + + override fun run() { + PvPClassHandler.getAllPvPClassesByPlayers().filterValues{it.isEnergyBased()}.forEach{entry -> + + val player = Bukkit.getServer().getPlayer(entry.key) + + if (player == null) { + + if (entry.value.energy.containsKey(entry.key)) { + entry.value.energy.remove(entry.key) + } + + return@forEach + } + + var energy = entry.value.getEnergy(player.uniqueId) + + if (energy >= 100) { + return@forEach + } + + if (++energy % 10 == 0) { + player.sendMessage("${ChatColor.AQUA}${entry.value.getName()} Energy: ${ChatColor.GREEN}$energy") + } + + entry.value.energy[player.uniqueId] = energy + } + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/pvpclass/type/ArcherClass.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/pvpclass/type/ArcherClass.kt new file mode 100644 index 0000000..d3805c1 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/pvpclass/type/ArcherClass.kt @@ -0,0 +1,215 @@ +package cc.fyre.hcf.pvpclass.type + +import cc.fyre.hcf.HCF +import cc.fyre.hcf.pvpclass.PvPClass +import cc.fyre.hcf.pvpclass.PvPClassHandler +import cc.fyre.hcf.pvpclass.PvPClassType +import cc.fyre.hcf.pvpclass.energy.EnergyEffect +import cc.fyre.hcf.pvpclass.event.type.ArcherMarkEvent +import cc.fyre.hcf.timer.TimerHandler +import cc.fyre.hcf.timer.TimerType +import cc.fyre.hcf.timer.event.TimerCreateEvent +import cc.fyre.hcf.timer.event.TimerExpireEvent +import cc.fyre.hcf.timer.event.TimerRemoveEvent +import cc.fyre.hcf.timer.listener.ArcherMarkListener +import cc.fyre.shard.util.TimeUtil +import org.bukkit.Bukkit +import org.bukkit.ChatColor +import org.bukkit.Location +import org.bukkit.Material +import org.bukkit.entity.Arrow +import org.bukkit.entity.Player +import org.bukkit.event.EventHandler +import org.bukkit.event.EventPriority +import org.bukkit.event.Listener +import org.bukkit.event.entity.EntityDamageByEntityEvent +import org.bukkit.event.entity.EntityShootBowEvent +import org.bukkit.event.entity.PotionEffectAddEvent +import org.bukkit.metadata.FixedMetadataValue +import org.bukkit.potion.PotionEffect +import org.bukkit.potion.PotionEffectType +import java.util.* + +/** + * @project hcf + * + * @date 11/09/2020 + * @author xanderume@gmail.com + */ +object ArcherClass : PvPClass(PvPClassType.ARCHER),Listener { + + private const val PULL_BACK_MINIMUM = 0.6 + + private const val LOCATION_METADATA = "LOCATION_METADATA" + private const val PULL_BACK_METADATA = "PULL_BACK_METADATA" + + private val invisibility = mutableMapOf() + + override fun init(core: HCF) { + this.effects[PotionEffectType.SPEED] = PotionEffect(PotionEffectType.SPEED,Integer.MAX_VALUE,2) + this.effects[PotionEffectType.DAMAGE_RESISTANCE] = PotionEffect(PotionEffectType.DAMAGE_RESISTANCE,Integer.MAX_VALUE,1) + + this.abilities[Material.SUGAR] = EnergyEffect(Material.SUGAR,40,PotionEffect(PotionEffectType.SPEED,10*20,3)) + this.abilities[Material.FEATHER] = EnergyEffect(Material.FEATHER,40,PotionEffect(PotionEffectType.JUMP,10*20,6)) + this.abilities[Material.IRON_INGOT] = EnergyEffect(Material.IRON_INGOT,40,PotionEffect(PotionEffectType.DAMAGE_RESISTANCE,6*20,2)) + } + + override fun onEnable(player: Player) {} + + override fun onDisable(player: Player) {} + + override fun isEnergyBased(): Boolean { + return true + } + + override fun isEquipped(player: Player): Boolean { + + if (player.inventory.helmet == null || player.inventory.chestplate == null || player.inventory.leggings == null || player.inventory.boots == null) { + return false + } + + return player.inventory.helmet.type == Material.LEATHER_HELMET + && player.inventory.chestplate.type == Material.LEATHER_CHESTPLATE + && player.inventory.leggings.type == Material.LEATHER_LEGGINGS + && player.inventory.boots.type == Material.LEATHER_BOOTS + } + + @EventHandler(priority = EventPriority.MONITOR) + private fun onEntityShootBow(event: EntityShootBowEvent) { + + if (event.entity !is Player) { + return + } + + if (PvPClassHandler.getPvPClassByPlayer(event.entity.uniqueId)?.type != this.type) { + return + } + + event.projectile.setMetadata(LOCATION_METADATA,FixedMetadataValue(HCF.instance,event.entity.location)) + event.projectile.setMetadata(PULL_BACK_METADATA,FixedMetadataValue(HCF.instance,event.force)) + } + + @EventHandler(priority = EventPriority.MONITOR) + private fun onTimerCreate(event: TimerCreateEvent) { + + if (event.timer.type != TimerType.ARCHER_MARK) { + return + } + + val player = Bukkit.getServer().getPlayer(event.uuid) ?: return + + player.sendMessage("${ChatColor.RED}${ChatColor.BOLD}Marked! ${ChatColor.YELLOW}An archer has shot you and marked you (+${ArcherMarkListener.INCREASE_DAMAGE}% damage) for ${TimeUtil.formatIntoDetailedString(event.duration)}.") + } + + @EventHandler(priority = EventPriority.MONITOR) + private fun onTimerRemove(event: TimerRemoveEvent) { + + if (event.timer.type != TimerType.ARCHER_MARK) { + return + } + + val invisibility = this.invisibility.remove(event.uuid) ?: return + + Bukkit.getServer().getPlayer(event.uuid)?.addPotionEffect(invisibility) + } + + @EventHandler(priority = EventPriority.MONITOR) + private fun onTimerExpire(event: TimerExpireEvent) { + + if (event.timer.type != TimerType.ARCHER_MARK) { + return + } + + val invisibility = this.invisibility.remove(event.uuid) ?: return + + Bukkit.getServer().getPlayer(event.uuid)?.addPotionEffect(invisibility) + } + + @EventHandler(priority = EventPriority.NORMAL) + private fun onPotionAdd(event: PotionEffectAddEvent) { + + if (event.entity !is Player) { + return + } + + if (event.effect.type != PotionEffectType.INVISIBILITY) { + return + } + + if (!this.invisibility.containsKey(event.entity.uniqueId)) { + return + } + + if (!TimerHandler.hasTimer(event.entity.uniqueId, TimerType.ARCHER_MARK)) { + return + } + + event.isCancelled = true + } + + @EventHandler(priority = EventPriority.MONITOR) + private fun onEntityDamageByEntity(event: EntityDamageByEntityEvent) { + + if (event.isCancelled) { + return + } + + if (event.entity !is Player || event.damager !is Arrow || ((event.damager as Arrow).shooter !is Player)) { + return + } + + val damager = (event.damager as Arrow).shooter as Player + + if (PvPClassHandler.getPvPClassByPlayer(damager.uniqueId)?.type != this.type) { + return + } + + if (!event.damager.hasMetadata(PULL_BACK_METADATA)) { + return + } + + val pulledBack = event.damager.getMetadata(PULL_BACK_METADATA)[0].asFloat() >= PULL_BACK_MINIMUM + val archerMarked = TimerHandler.hasTimer(event.entity.uniqueId, TimerType.ARCHER_MARK) + val inArcherClass = PvPClassHandler.getPvPClassByPlayer(event.entity.uniqueId)?.type == this.type + + val damage = if (!pulledBack) 1.0 else if (inArcherClass) 1.0 else if (archerMarked) 3.0 else 2.0 + + if ((event.entity as Player).health - damage <= 0.0) { + event.isCancelled = true + } else { + event.damage = 0.0 + } + + (event.entity as Player).health = 0.0.coerceAtLeast((event.entity as Player).health - damage) + + + val distance = if (event.damager.hasMetadata(LOCATION_METADATA)) { + (event.damager.getMetadata(LOCATION_METADATA)[0].value() as Location).distance(event.entity.location).toInt() + } else { + damager.location.distance(event.entity.location).toInt() + } + + val message = when { + !pulledBack -> "${ChatColor.RED}Bow wasn't fully drawn back" + inArcherClass -> "${ChatColor.RED}Cannot mark other Archers" + else -> "${ChatColor.GOLD}Marked player for ${TimeUtil.formatIntoDetailedString(TimerType.ARCHER_MARK.duration)}" + } + + damager.sendMessage("${ChatColor.YELLOW}[${ChatColor.BLUE}Arrow Range ${ChatColor.YELLOW}(${ChatColor.RED}$distance${ChatColor.YELLOW})] $message. ${ChatColor.BLUE}${ChatColor.BOLD}(${damage / 2} heart${if (damage == 2.0) "" else "s"})") + + if (!pulledBack || inArcherClass) { + return + } + + val invisibility = (event.entity as Player).activePotionEffects.firstOrNull{it.type == PotionEffectType.INVISIBILITY} + + if (invisibility != null) { + (event.entity as Player).removePotionEffect(PotionEffectType.INVISIBILITY) + this.invisibility[event.entity.uniqueId] = invisibility + } + + TimerHandler.addTimer(event.entity.uniqueId, TimerType.ARCHER_MARK) + Bukkit.getServer().pluginManager.callEvent(ArcherMarkEvent(event.entity as Player,damager,damage)) + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/pvpclass/type/MinerClass.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/pvpclass/type/MinerClass.kt new file mode 100644 index 0000000..3190400 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/pvpclass/type/MinerClass.kt @@ -0,0 +1,189 @@ +package cc.fyre.hcf.pvpclass.type + +import cc.fyre.hcf.HCF +import cc.fyre.hcf.pvpclass.PvPClass +import cc.fyre.hcf.pvpclass.PvPClassHandler +import cc.fyre.hcf.pvpclass.PvPClassType +import cc.fyre.hcf.statistic.StatisticHandler +import cc.fyre.hcf.statistic.type.ores.DiamondMinedStatistic +import cc.fyre.hcf.statistic.type.setting.CobbleSetting +import cc.fyre.shard.util.NumberUtil +import cc.fyre.shard.util.StringUtil +import cc.fyre.shard.util.bukkit.PotionUtil +import cc.fyre.Forge +import cc.fyre.handler.MovementHandler +import net.minecraft.server.v1_7_R4.PacketPlayInFlying +import org.bukkit.ChatColor +import org.bukkit.Location +import org.bukkit.Material +import org.bukkit.enchantments.Enchantment +import org.bukkit.entity.Player +import org.bukkit.event.EventHandler +import org.bukkit.event.EventPriority +import org.bukkit.event.Listener +import org.bukkit.event.block.BlockBreakEvent +import org.bukkit.event.player.PlayerPickupItemEvent +import org.bukkit.event.player.PlayerTeleportEvent +import org.bukkit.potion.PotionEffect +import org.bukkit.potion.PotionEffectType + +/** + * @project hcf + * + * @date 11/09/2020 + * @author xanderume@gmail.com + */ +object MinerClass : PvPClass(PvPClassType.MINER), MovementHandler,Listener { + + private val INVISIBILITY = PotionEffect(PotionEffectType.INVISIBILITY,Int.MAX_VALUE,0) + private const val INVISIBILITY_LEVEL = 20 + + private val upgrades = mutableMapOf( + 50 to arrayOf(PotionEffect(PotionEffectType.FAST_DIGGING,Integer.MAX_VALUE,2)), + 100 to arrayOf(PotionEffect(PotionEffectType.SPEED,Integer.MAX_VALUE,0)), + 150 to arrayOf(PotionEffect(PotionEffectType.FAST_DIGGING,Integer.MAX_VALUE,3)), + 200 to arrayOf(PotionEffect(PotionEffectType.SPEED,Integer.MAX_VALUE,1)), + 250 to arrayOf(PotionEffect(PotionEffectType.FIRE_RESISTANCE,Integer.MAX_VALUE,0)), + 300 to arrayOf(PotionEffect(PotionEffectType.REGENERATION,Integer.MAX_VALUE,0)), + 350 to arrayOf(PotionEffect(PotionEffectType.SATURATION,Integer.MAX_VALUE,0)) + ) + + override fun init(core: HCF) { + this.effects[PotionEffectType.FAST_DIGGING] = PotionEffect(PotionEffectType.FAST_DIGGING,Integer.MAX_VALUE,1) + this.effects[PotionEffectType.NIGHT_VISION] = PotionEffect(PotionEffectType.NIGHT_VISION,Integer.MAX_VALUE,0) + this.effects[PotionEffectType.FIRE_RESISTANCE] = PotionEffect(PotionEffectType.FIRE_RESISTANCE,Integer.MAX_VALUE,0) + + Forge.INSTANCE.addMovementHandler(this) + } + + override fun onEnable(player: Player) { + + val diamonds = StatisticHandler.getStatistic(player.uniqueId,DiamondMinedStatistic).getValue() + + for (upgrade in this.upgrades.entries) { + + if (upgrade.key > diamonds) { + continue + } + + upgrade.value.forEach{player.addPotionEffect(it,true)} + } + + } + + override fun onDisable(player: Player) { + + val diamonds = StatisticHandler.getStatistic(player.uniqueId,DiamondMinedStatistic).getValue() + + for (upgrade in this.upgrades.entries) { + + if (upgrade.key > diamonds) { + continue + } + + upgrade.value.forEach{player.removePotionEffect(it.type)} + } + + } + + override fun isEnergyBased(): Boolean { + return false + } + + override fun isEquipped(player: Player): Boolean { + + if (player.inventory.helmet == null || player.inventory.chestplate == null || player.inventory.leggings == null || player.inventory.boots == null) { + return false + } + + return player.inventory.helmet.type == Material.IRON_HELMET + && player.inventory.chestplate.type == Material.IRON_CHESTPLATE + && player.inventory.leggings.type == Material.IRON_LEGGINGS + && player.inventory.boots.type == Material.IRON_BOOTS + } + + @EventHandler(priority = EventPriority.NORMAL) + private fun onItemPickup(event: PlayerPickupItemEvent) { + + if (event.item.itemStack.type != Material.COBBLESTONE) { + return + } + + if (PvPClassHandler.getPvPClassByPlayer(event.player.uniqueId) !is MinerClass) { + return + } + + if (StatisticHandler.getStatistic(event.player.uniqueId,CobbleSetting).getValue()) { + return + } + + event.isCancelled = true + } + + @EventHandler(priority = EventPriority.MONITOR) + private fun onBlockBreak(event: BlockBreakEvent) { + + if (event.isCancelled) { + return + } + + if (event.block.type != Material.DIAMOND_ORE) { + return + } + + if (PvPClassHandler.getPvPClassByPlayer(event.player.uniqueId)?.type != this.type) { + return + } + + if (event.player.itemInHand != null && event.player.itemInHand.containsEnchantment(Enchantment.SILK_TOUCH)) { + return + } + + val diamonds = StatisticHandler.getStatistic(event.player.uniqueId,DiamondMinedStatistic).getValue() + val upgrades = this.upgrades[diamonds] ?: return + + for (upgrade in upgrades) { + event.player.addPotionEffect(upgrade,true) + } + + event.player.sendMessage("${ChatColor.YELLOW}You have mined ${ChatColor.RED}${diamonds}${ChatColor.YELLOW} diamonds and received ${ChatColor.RED}${StringUtil.join(upgrades.map{"${ChatColor.RED}${PotionUtil.getName(it.type)} ${NumberUtil.toRoman(it.amplifier + 1)}"}.toTypedArray(),"${ChatColor.YELLOW}, ","${ChatColor.YELLOW}and ")}${ChatColor.YELLOW}.") + } + + @EventHandler(priority = EventPriority.MONITOR) + private fun onPlayerTeleport(event: PlayerTeleportEvent) { + this.handleUpdateLocation(event.player,event.to,event.from,null) + } + + override fun handleUpdateRotation(player: Player, to: Location, from: Location, packet: PacketPlayInFlying?) {} + + override fun handleUpdateLocation(player: Player, to: Location, from: Location, packet: PacketPlayInFlying?) { + + if (from.blockY == to.blockY) { + return + } + + if (from.blockX == to.blockX && from.blockZ == to.blockZ) { + return + } + + if (PvPClassHandler.getPvPClassByPlayer(player.uniqueId)?.type != this.type) { + return + } + + if (from.blockY < INVISIBILITY_LEVEL && to.blockY > INVISIBILITY_LEVEL) { + player.activePotionEffects.stream().filter{it.type == INVISIBILITY.type && it.duration > PotionUtil.MAX_POTION_DURATION}.findFirst().ifPresent{player.removePotionEffect(INVISIBILITY.type)} + return + } + + if (from.blockY > INVISIBILITY_LEVEL) { + return + } + + if (player.hasPotionEffect(PotionEffectType.INVISIBILITY)) { + return + } + + player.addPotionEffect(INVISIBILITY) + } + +} diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/pvpclass/type/RogueClass.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/pvpclass/type/RogueClass.kt new file mode 100644 index 0000000..c9deaa9 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/pvpclass/type/RogueClass.kt @@ -0,0 +1,125 @@ +package cc.fyre.hcf.pvpclass.type + +import cc.fyre.hcf.HCF +import cc.fyre.hcf.deathmessage.Damage +import cc.fyre.hcf.deathmessage.DeathMessageHandler +import cc.fyre.hcf.deathmessage.type.player.BackStabDamageByPlayer +import cc.fyre.hcf.pvpclass.PvPClass +import cc.fyre.hcf.pvpclass.PvPClassHandler +import cc.fyre.hcf.pvpclass.PvPClassType +import cc.fyre.hcf.pvpclass.event.type.BackstabEvent +import cc.fyre.hcf.pvpclass.item.type.EffectConsumableItem +import org.bukkit.ChatColor +import org.bukkit.Effect +import org.bukkit.Material +import org.bukkit.Sound +import org.bukkit.entity.Player +import org.bukkit.event.EventHandler +import org.bukkit.event.EventPriority +import org.bukkit.event.Listener +import org.bukkit.event.entity.EntityDamageByEntityEvent +import org.bukkit.potion.PotionEffect +import org.bukkit.potion.PotionEffectType +import java.util.concurrent.TimeUnit +import kotlin.math.abs +import kotlin.math.max + +/** + * @project hcf + * + * @date 11/09/2020 + * @author xanderume@gmail.com + */ +object RogueClass : PvPClass(PvPClassType.ROGUE),Listener { + + private const val ANGLE = 1.4 + private val DEBUFF = PotionEffect(PotionEffectType.SLOW,2*20,2) + + override fun init(core: HCF) { + this.effects[PotionEffectType.JUMP] = PotionEffect(PotionEffectType.JUMP,Integer.MAX_VALUE,1) + this.effects[PotionEffectType.SPEED] = PotionEffect(PotionEffectType.SPEED,Integer.MAX_VALUE,2) + this.effects[PotionEffectType.DAMAGE_RESISTANCE] = PotionEffect(PotionEffectType.DAMAGE_RESISTANCE,Integer.MAX_VALUE,0) + + this.consumables[Material.SUGAR] = EffectConsumableItem(Material.SUGAR,TimeUnit.MINUTES.toMillis(1L),PotionEffect(PotionEffectType.SPEED,10*20,4)) + this.consumables[Material.FEATHER] = EffectConsumableItem(Material.FEATHER,TimeUnit.MINUTES.toMillis(2L),PotionEffect(PotionEffectType.JUMP,10*20,6)) + this.consumables[Material.IRON_INGOT] = EffectConsumableItem(Material.IRON_INGOT,TimeUnit.MINUTES.toMillis(2L),PotionEffect(PotionEffectType.DAMAGE_RESISTANCE,6*20,1)) + //this.abilities[Material.SUGAR] = EnergyEffect(Material.SUGAR,40,PotionEffect(PotionEffectType.SPEED,10*20,4)) + //this.abilities[Material.FEATHER] = EnergyEffect(Material.FEATHER,40,PotionEffect(PotionEffectType.JUMP,10*20,6)) + //this.abilities[Material.IRON_INGOT] = EnergyEffect(Material.IRON_INGOT,40,PotionEffect(PotionEffectType.DAMAGE_RESISTANCE,6*20,1)) + } + + override fun onEnable(player: Player) {} + + override fun onDisable(player: Player) {} + + override fun isEnergyBased(): Boolean { + return false + } + + override fun isEquipped(player: Player): Boolean { + + if (player.inventory.helmet == null || player.inventory.chestplate == null || player.inventory.leggings == null || player.inventory.boots == null) { + return false + } + + return player.inventory.helmet.type == Material.CHAINMAIL_HELMET + && player.inventory.chestplate.type == Material.CHAINMAIL_CHESTPLATE + && player.inventory.leggings.type == Material.CHAINMAIL_LEGGINGS + && player.inventory.boots.type == Material.CHAINMAIL_BOOTS + } + + @EventHandler(priority = EventPriority.MONITOR) + private fun onEntityDamageByEntity(event: EntityDamageByEntityEvent) { + + if (event.isCancelled) { + return + } + + if (event.entity !is Player || event.damager !is Player) { + return + } + + if ((event.damager as Player).itemInHand == null || (event.damager as Player).itemInHand.type != Material.GOLD_SWORD) { + return + } + + if (PvPClassHandler.getPvPClassByPlayer(event.damager.uniqueId) != this) { + return + } + + if ((event.damager as Player).activePotionEffects.any{it.type == DEBUFF.type && it.amplifier == DEBUFF.amplifier}) { + event.damage = 0.0 + return + } + + val vector = event.entity.location.direction.setY(0) + val damagerVector = event.damager.location.direction.setY(0) + + if (abs(damagerVector.angle(vector)) >= ANGLE) { + (event.damager as Player).sendMessage("${ChatColor.RED}Backstab failed!") + return + } + + (event.damager as Player).itemInHand = null + + event.entity.world.playSound(event.entity.location,Sound.ITEM_BREAK,1.0F,1.0F) + event.entity.world.playEffect(event.entity.location,Effect.STEP_SOUND,Material.REDSTONE_BLOCK) + + val damage = 7.0 + + val backstabEvent = BackstabEvent(event.entity as Player,event.damager as Player,damage) + + DeathMessageHandler.addDamageByPlayer(event.entity as Player,BackStabDamageByPlayer(event.entity.uniqueId,backstabEvent.damage,event.damager.uniqueId)) + + if (((event.entity as Player).health - backstabEvent.damage) <= 0) { + event.isCancelled = true + } else { + event.damage = 0.0 + } + + (event.entity as Player).health = max(0.0,(event.entity as Player).health - backstabEvent.damage) + (event.damager as Player).addPotionEffect(DEBUFF) + } + + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/pvpclass/type/bard/BardClass.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/pvpclass/type/bard/BardClass.kt new file mode 100644 index 0000000..0c1ce8f --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/pvpclass/type/bard/BardClass.kt @@ -0,0 +1,218 @@ +package cc.fyre.hcf.pvpclass.type.bard + +import cc.fyre.hcf.HCF +import cc.fyre.hcf.faction.FactionHandler +import cc.fyre.hcf.faction.FactionMetadata +import cc.fyre.hcf.faction.type.SystemFaction +import cc.fyre.hcf.map.MapHandler +import cc.fyre.hcf.map.sotw.SOTWHandler +import cc.fyre.hcf.pvpclass.PvPClass +import cc.fyre.hcf.pvpclass.PvPClassHandler +import cc.fyre.hcf.pvpclass.PvPClassType +import cc.fyre.hcf.pvpclass.event.type.BardEffectEvent +import cc.fyre.hcf.pvpclass.type.bard.effect.BardEnergyEffect +import cc.fyre.hcf.pvpclass.type.bard.scheduler.BardEffectScheduler +import cc.fyre.hcf.timer.TimerHandler +import cc.fyre.hcf.timer.TimerType +import cc.fyre.shard.util.NumberUtil +import cc.fyre.shard.util.bukkit.PotionUtil +import org.bukkit.ChatColor +import org.bukkit.Material +import org.bukkit.entity.Player +import org.bukkit.event.EventHandler +import org.bukkit.event.EventPriority +import org.bukkit.event.Listener +import org.bukkit.event.entity.PotionEffectAddEvent +import org.bukkit.potion.PotionEffect +import org.bukkit.potion.PotionEffectType +import java.util.function.Predicate + +/** + * @project hcf + * + * @date 12/09/2020 + * @author xanderume@gmail.com + */ +object BardClass: PvPClass(PvPClassType.BARD),Listener { + + const val DEFAULT_RADIUS = 25.0 + + private val BARD_ILLEGAL_EFFECTS = arrayOf(PotionEffectType.INCREASE_DAMAGE) + + override fun init(core: HCF) { + this.effects[PotionEffectType.SPEED] = PotionEffect(PotionEffectType.SPEED,Integer.MAX_VALUE,1) + this.effects[PotionEffectType.REGENERATION] = PotionEffect(PotionEffectType.REGENERATION,Integer.MAX_VALUE,0) + this.effects[PotionEffectType.DAMAGE_RESISTANCE] = PotionEffect(PotionEffectType.DAMAGE_RESISTANCE,Integer.MAX_VALUE,1) + + this.abilities[Material.SUGAR] = BardEnergyEffect( + Material.SUGAR, + 20, + PotionEffect(PotionEffectType.SPEED,6*20,1), + PotionEffect(PotionEffectType.SPEED,6*20,2) + ) + this.abilities[Material.BLAZE_POWDER] = BardEnergyEffect( + Material.BLAZE_POWDER, + 45, + PotionEffect(PotionEffectType.INCREASE_DAMAGE,6*20,0), + PotionEffect(PotionEffectType.INCREASE_DAMAGE,5*20,1) + ) + this.abilities[Material.GHAST_TEAR] = BardEnergyEffect( + Material.GHAST_TEAR, + 40, + PotionEffect(PotionEffectType.REGENERATION,6*20,0), + PotionEffect(PotionEffectType.REGENERATION,6*20,2) + ) + this.abilities[Material.IRON_INGOT] = BardEnergyEffect( + Material.IRON_INGOT, + 40, + PotionEffect(PotionEffectType.DAMAGE_RESISTANCE,6*20,0), + PotionEffect(PotionEffectType.DAMAGE_RESISTANCE,6*20,2) + ) + this.abilities[Material.FEATHER] = BardEnergyEffect( + Material.FEATHER, + 25, + PotionEffect(PotionEffectType.JUMP,6*20,1), + PotionEffect(PotionEffectType.JUMP,5*20,6) + ) + this.abilities[Material.MAGMA_CREAM] = BardEnergyEffect( + Material.MAGMA_CREAM, + 25, + PotionEffect(PotionEffectType.FIRE_RESISTANCE,6*20,0), + PotionEffect(PotionEffectType.FIRE_RESISTANCE,46*20,0) + ) + this.abilities[Material.SPIDER_EYE] = BardEnergyEffect( + Material.SPIDER_EYE, + 35, + null, + PotionEffect(PotionEffectType.WITHER,5*20,1), + ) + this.abilities[Material.WHEAT] = BardEnergyEffect( + Material.WHEAT, + 25, + null, + null, + Predicate{ + it.foodLevel = 20 + it.saturation = 10.0F + return@Predicate true + } + ) + + core.server.scheduler.runTaskTimerAsynchronously(core,BardEffectScheduler,4L,4L) + } + + override fun onEnable(player: Player) { + + if (!TimerHandler.hasTimer(player.uniqueId, TimerType.PVP_TIMER)) { + return + } + + player.sendMessage("${ChatColor.RED}You are currently PvP protected and cannot use ${this.getName()} effects. Type '/pvp enable' to remove your protection.") + } + + override fun onDisable(player: Player) {} + + override fun isEnergyBased(): Boolean { + return true + } + + override fun isEquipped(player: Player): Boolean { + + if (player.inventory.helmet == null || player.inventory.chestplate == null || player.inventory.leggings == null || player.inventory.boots == null) { + return false + } + + return player.inventory.helmet.type == Material.GOLD_HELMET + && player.inventory.chestplate.type == Material.GOLD_CHESTPLATE + && player.inventory.leggings.type == Material.GOLD_LEGGINGS + && player.inventory.boots.type == Material.GOLD_BOOTS + } + + @EventHandler(priority = EventPriority.MONITOR) + private fun onPotionEffectAdd(event: PotionEffectAddEvent) { + + if (PvPClassHandler.getPvPClassByPlayer(event.entity.uniqueId)?.type != this.type) { + return + } + + if (BARD_ILLEGAL_EFFECTS.none{it == event.effect.type}) { + return + } + + event.isCancelled = true + } + + @EventHandler(priority = EventPriority.MONITOR) + private fun onBardEffect(event: BardEffectEvent) { + + if (event.effect.effect == null) { + return + } + + val name = PotionUtil.getDisplayName(event.effect.effect.type) + val level = NumberUtil.toRoman(event.effect.effect.amplifier + 1) + val debuff = PotionUtil.isDebuff(event.effect.effect.type) + + val total = event.receivers.size + + event.player.sendMessage("${ChatColor.YELLOW}You have given $name $level ${ChatColor.YELLOW}to ${if (debuff) "${ChatColor.RED}${total}${ChatColor.YELLOW} enem${if (total == 1) "y" else "ies"}" else if (total == 0 && !BARD_ILLEGAL_EFFECTS.contains(event.effect.effect.type)) "yourself" else "${ChatColor.GREEN}$total ${ChatColor.YELLOW}teammate${if (total == 1) "" else "s"}"}.") + } + + fun isIllegalEffect(effect: PotionEffectType):Boolean { + return BARD_ILLEGAL_EFFECTS.contains(effect) + } + + fun getNearbyPlayers(player: Player,range: Double,effect: PotionEffect?):List { + + val isStartOfTheWorld = SOTWHandler.isActive() + val isStartOfTheWorldProtected = SOTWHandler.isProtected(player) + + if (TimerHandler.hasTimer(player.uniqueId,TimerType.PVP_TIMER)) { + return listOf(player) + } + + val debuff = if (effect == null) false else PotionUtil.isDebuff(effect.type) + val faction = FactionHandler.getFactionByPlayer(player.uniqueId) + val toReturn = arrayListOf() + + toReturn.add(player) + + if (faction != null) { + + for (entity in player.getNearbyEntities(range,range / 2,range)) { + + if (entity !is Player) { + continue + } + + if (isStartOfTheWorld && SOTWHandler.isProtected(entity) != isStartOfTheWorldProtected) { + continue + } + + if (FactionMetadata.SAFE_ZONE.isValidAtLocation(entity.location)) { + continue + } + + if (effect != null) { + + if (PvPClassHandler.getPvPClassByPlayer(entity.uniqueId) is BardClass && BARD_ILLEGAL_EFFECTS.contains(effect.type)) { + continue + } + + } + + if (debuff && faction.isMember(entity)) { + continue + } else if (!debuff && !faction.isMember(entity)) { + continue + } + + toReturn.add(entity) + } + + } + + return toReturn + } + +} diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/pvpclass/type/bard/effect/BardEnergyEffect.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/pvpclass/type/bard/effect/BardEnergyEffect.kt new file mode 100644 index 0000000..f21186e --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/pvpclass/type/bard/effect/BardEnergyEffect.kt @@ -0,0 +1,32 @@ +package cc.fyre.hcf.pvpclass.type.bard.effect + +import cc.fyre.hcf.pvpclass.energy.EnergyEffect +import cc.fyre.hcf.pvpclass.event.type.BardEffectEvent +import cc.fyre.hcf.pvpclass.type.bard.BardClass +import org.bukkit.Bukkit +import org.bukkit.Material +import org.bukkit.entity.Player +import org.bukkit.potion.PotionEffect +import java.util.function.Predicate + +class BardEnergyEffect(item: Material,energy: Int,val passive: PotionEffect?,effect: PotionEffect?,predicate: Predicate? = null) : EnergyEffect( + item, + energy, + effect, + predicate +) { + + override fun consume(player: Player) { + + val players = BardClass.getNearbyPlayers(player,BardClass.DEFAULT_RADIUS,this.effect).toMutableList() + + for (target in players) { + super.consume(target) + } + + players.remove(player) + + Bukkit.getServer().pluginManager.callEvent(BardEffectEvent(player,players,this)) + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/pvpclass/type/bard/scheduler/BardEffectScheduler.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/pvpclass/type/bard/scheduler/BardEffectScheduler.kt new file mode 100644 index 0000000..7fa6bb3 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/pvpclass/type/bard/scheduler/BardEffectScheduler.kt @@ -0,0 +1,47 @@ +package cc.fyre.hcf.pvpclass.type.bard.scheduler +import cc.fyre.hcf.pvpclass.PvPClassHandler +import cc.fyre.hcf.pvpclass.type.bard.BardClass +import cc.fyre.hcf.pvpclass.type.bard.effect.BardEnergyEffect +import org.bukkit.Bukkit + +object BardEffectScheduler : Runnable { + + override fun run() { + + for (entry in PvPClassHandler.getAllPvPClassesByPlayers()) { + + val pvpClass = entry.value + + if (pvpClass !is BardClass) { + continue + } + + val player = Bukkit.getServer().getPlayer(entry.key) + + if (player == null || player.itemInHand == null) { + continue + } + + val effect = pvpClass.getAbilityByItem(player.itemInHand.type) + + if (effect == null || effect !is BardEnergyEffect) { + continue + } + + if (effect.passive == null) { + continue + } + + for (nearbyPlayer in pvpClass.getNearbyPlayers( + player, + BardClass.DEFAULT_RADIUS, + effect.passive + )) { + PvPClassHandler.addPotionEffect(nearbyPlayer,effect.passive) + } + + } + + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/Statistic.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/Statistic.kt new file mode 100644 index 0000000..a6d0910 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/Statistic.kt @@ -0,0 +1,41 @@ +package cc.fyre.hcf.statistic +import cc.fyre.core.profile.Profile +import org.bson.Document +import org.bukkit.Material +import java.util.* + +abstract class Statistic { + + var icon = Material.AIR + var data = 0 + + abstract fun getKey():String + abstract fun getName():String + abstract fun getOptions():List> + abstract fun getDefaultValue():StatisticValue + + abstract fun getNextValue(value: T):T + abstract fun getDisplayName(value: T):String + + abstract fun isSetting():Boolean + abstract fun hasPermission(profile: Profile, value: T):Boolean + + open fun toBson(document: Document,value: Any) { + document.append(this.getKey(),value) + } + + abstract fun fromBson(document: Document):StatisticValue + + fun getDescription():List { + return listOf() + } + + override fun equals(other: Any?): Boolean { + return other is Statistic<*> && other.getKey() == this.getKey() + } + + override fun hashCode(): Int { + return Objects.hash(this.getKey()) + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/StatisticHandler.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/StatisticHandler.kt new file mode 100644 index 0000000..a1ecb0b --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/StatisticHandler.kt @@ -0,0 +1,135 @@ +package cc.fyre.hcf.statistic + +import cc.fyre.hcf.statistic.leaderboard.LeaderboardEntry +import cc.fyre.hcf.statistic.leaderboard.LeaderboardNPC +import cc.fyre.hcf.statistic.type.PlayTimeStatistic +import cc.fyre.shard.entity.EntityHandler +import com.google.common.collect.HashBasedTable +import org.bukkit.ChatColor +import org.bukkit.entity.Player +import java.util.* +import java.util.concurrent.ConcurrentHashMap + +/** + * @project hcf + * + * @date 02/07/2020 + * @author xanderume@gmail.com + */ +object StatisticHandler { + + private val needsUpdate = ConcurrentHashMap.newKeySet() + private val statistics = HashBasedTable.create,StatisticValue<*>>() + private val leaderboards = ConcurrentHashMap>() + private var lastLeaderboardUpdate = System.currentTimeMillis() + + private val playTimeSession = ConcurrentHashMap() + + fun init() { + EntityHandler.registerType(LeaderboardNPC::class.java,"HCF_LEADERBOARD") + + this.statistics.putAll(StatisticRepository.findAll()) + } + + fun getAllUpdates():ConcurrentHashMap.KeySetView { + return this.needsUpdate + } + + fun getAllStatistics(statistic: Statistic):Map> { + return this.statistics.column(statistic) as Map> + } + + fun getStatistic(uuid: UUID,statistic: Statistic):StatisticValue { + + var value = this.statistics.get(uuid,statistic) + + if (value == null) { + + val defaultValue = statistic.getDefaultValue() + + if (defaultValue.getValue() == null) { + value = StatisticValue.NULL as StatisticValue + } else { + value = defaultValue + this.statistics.put(uuid,statistic,value) + } + + } + + return value as StatisticValue + } + + fun setStatistic(uuid: UUID,statistic: Statistic, value: T) { + this.statistics.put(uuid,statistic,object : StatisticValue { + + override fun getValue(): T { + return value + } + + }) + this.needsUpdate.add(uuid) + } + + fun getStatistics(statistic: Statistic):Map> { + return this.statistics.column(statistic) as Map> + } + + fun toggleStatistic(uuid: UUID,statistic: Statistic):Boolean { + + val value = !this.getStatistic(uuid,statistic).getValue() + + this.setStatistic(uuid,statistic,value) + + return value + } + + fun increaseStatistic(uuid: UUID,statistic: Statistic,increase: Int) { + this.setStatistic(uuid,statistic,this.getStatistic(uuid,statistic).getValue() + increase) + } + + fun getPlayTimeSeconds(player: UUID):Int { + + var time = this.getStatistic(player,PlayTimeStatistic).getValue() + + if (this.playTimeSession.contains(player)) { + time += ((System.currentTimeMillis() - this.playTimeSession[player]!!) / 1000L).toInt() + } + + return time + } + + fun createPlayTimeSession(player: Player) { + this.playTimeSession[player.uniqueId] = System.currentTimeMillis() + } + + fun destroyPlayTimeSession(player: Player): Long? { + return this.playTimeSession.remove(player.uniqueId) + } + + fun setLeaderboard(type: Statistic<*>,entries: Array) { + this.leaderboards[type.getKey()] = entries + } + + fun getLeaderboard(statistic: Statistic<*>):Array? { + return this.leaderboards[statistic.getKey()] + } + + fun getLastLeaderboardUpdate():Long { + return this.lastLeaderboardUpdate + } + + fun setLastLeaderboardUpdate(time: Long) { + this.lastLeaderboardUpdate = time + } + + val LEADERBOARD_COLORS = mapOf( + 1 to ChatColor.DARK_GREEN, + 2 to ChatColor.GREEN, + 3 to ChatColor.RED, + 4 to ChatColor.GOLD, + 5 to ChatColor.YELLOW + ) + + const val LEADERBOARD_INTERVAL_SECONDS = 5 * 60 + const val LEADERBOARD_INTERVAL_MILLIS = LEADERBOARD_INTERVAL_SECONDS * 1000L +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/StatisticModule.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/StatisticModule.kt new file mode 100644 index 0000000..d2e767c --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/StatisticModule.kt @@ -0,0 +1,84 @@ +package cc.fyre.hcf.statistic + +import cc.fyre.hcf.HCF +import cc.fyre.hcf.HCFModule +import cc.fyre.hcf.statistic.command.* +import cc.fyre.hcf.statistic.command.parameter.StatisticParameterProvider +import cc.fyre.hcf.statistic.leaderboard.LeaderboardNPC +import cc.fyre.hcf.statistic.leaderboard.LeaderboardUpdateTask +import cc.fyre.hcf.statistic.leaderboard.command.LeaderboardCommand +import cc.fyre.hcf.statistic.leaderboard.command.LeaderboardNPCCommand +import cc.fyre.hcf.statistic.listener.StatisticListener +import cc.fyre.hcf.statistic.type.* +import cc.fyre.hcf.statistic.type.ores.* +import cc.fyre.hcf.statistic.type.setting.* +import cc.fyre.shard.command.data.parameter.ParameterAdapter +import org.bukkit.event.Listener + +object StatisticModule : HCFModule { + + override fun init(core: HCF) { + StatisticRegistry.register(LivesStatistic) + StatisticRegistry.register(KillsStatistic) + StatisticRegistry.register(DeathsStatistic) + StatisticRegistry.register(BalanceStatistic) + StatisticRegistry.register(PlayTimeStatistic) + StatisticRegistry.register(HighestKillStreak) + + StatisticRegistry.register(CoalMinedStatistic) + StatisticRegistry.register(IronMinedStatistic) + StatisticRegistry.register(GoldMinedStatistic) + StatisticRegistry.register(LapisMinedStatistic) + StatisticRegistry.register(DiamondMinedStatistic) + StatisticRegistry.register(EmeraldMinedStatistic) + StatisticRegistry.register(RedstoneMinedStatistic) + + StatisticRegistry.register(MapSetting) + StatisticRegistry.register(CobbleSetting) + StatisticRegistry.register(ReclaimSetting) + StatisticRegistry.register(TabListSetting) + StatisticRegistry.register(CustomTimersSetting) + StatisticRegistry.register(EventMessageSetting) + StatisticRegistry.register(DeathMessageSetting) + StatisticRegistry.register(FoundDiamondSetting) + StatisticRegistry.register(AbilityCooldownSetting) + StatisticRegistry.register(FactionFocusSetting) + StatisticRegistry.register(FactionFilterSetting) + + StatisticHandler.init() + + core.server.scheduler.runTaskTimerAsynchronously(HCF.instance,LeaderboardUpdateTask,0L,(StatisticHandler.LEADERBOARD_INTERVAL_SECONDS) * 20L) + } + + override fun shutdown(core: HCF) { + StatisticRepository.saveAll() + } + + override fun onSave(core: HCF) { + StatisticRepository.saveAll() + } + + override fun getCommands(): List> { + return listOf( + PayCommand::class.java, + LivesCommand::class.java, + BalanceCommand::class.java, + LeaderboardCommand::class.java, + LeaderboardNPCCommand::class.java + ) + } + + override fun getAdapters(): Map, ParameterAdapter<*>> { + return mapOf( + Statistic::class.java to StatisticParameterProvider + ) + } + + override fun getListeners(): List { + return listOf( + StatisticListener + ) + } + + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/StatisticOption.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/StatisticOption.kt new file mode 100644 index 0000000..9732bf0 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/StatisticOption.kt @@ -0,0 +1,6 @@ +package cc.fyre.hcf.statistic + +data class StatisticOption( + val name: String, + val value: T, +) \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/StatisticRegistry.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/StatisticRegistry.kt new file mode 100644 index 0000000..e87aef9 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/StatisticRegistry.kt @@ -0,0 +1,25 @@ +package cc.fyre.hcf.statistic + +object StatisticRegistry { + + private val statistics = mutableMapOf>() + private val statisticsByClass = mutableMapOf>() + + fun register(statistic: Statistic<*>) { + this.statistics[statistic.getKey()] = statistic + this.statisticsByClass[statistic::class.java.simpleName] = statistic + } + + fun getAllStatistics():List> { + return this.statistics.values.toList() + } + + fun getStatisticByKey(key: String): Statistic<*>? { + return this.statistics[key] + } + + fun getStatisticByClass(clazz: Class<*>): Statistic<*>? { + return this.statisticsByClass[clazz.simpleName] + } + +} diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/StatisticRepository.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/StatisticRepository.kt new file mode 100644 index 0000000..329dcab --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/StatisticRepository.kt @@ -0,0 +1,81 @@ +package cc.fyre.hcf.statistic + +import cc.fyre.hcf.HCF +import cc.fyre.shard.util.MongoUtil +import cc.fyre.shard.util.StringUtil +import com.google.common.collect.HashBasedTable +import com.google.common.collect.Table +import com.mongodb.client.model.Filters +import com.mongodb.client.model.ReplaceOneModel +import org.bson.Document +import java.util.* + +/** + * @project hcf + * + * @date 16/11/2020 + * @author xanderume@gmail.com + */ +object StatisticRepository { + + private val collection = HCF.instance.getMongoDB().getCollection("statistics") + + fun saveAll() { + + val iterator = StatisticHandler.getAllUpdates().iterator() + val bulkWrite = mutableListOf>() + + while (iterator.hasNext()) { + + val uuid = iterator.next() + val key = uuid.toString() + val document = Document("_id",key) + + for (statistic in StatisticRegistry.getAllStatistics()) { + StatisticHandler.getStatistic(uuid,statistic).getValue().also{ + + if (it == null || it == statistic.getDefaultValue().getValue()) { + return@also + } + + statistic.toBson(document,it) + } + } + + bulkWrite.add(ReplaceOneModel(Filters.eq("_id",key),document,MongoUtil.UPDATE_OPTIONS)) + iterator.remove() + } + + if (bulkWrite.isEmpty()) { + return + } + + this.collection.bulkWrite(bulkWrite) + + HCF.instance.logger.info("Saved ${bulkWrite.size} ${StringUtil.pluralize("statistic",bulkWrite.size)} to MongoDB.") + + } + + fun findAll():Table,StatisticValue<*>> { + + val table = HashBasedTable.create,StatisticValue<*>>() + + for (document in this.collection.find()) { + + val uuid = UUID.fromString(document.getString("_id")) + + for (statistic in StatisticRegistry.getAllStatistics()) { + + if (!document.containsKey(statistic.getKey())) { + continue + } + + table.put(uuid,statistic,statistic.fromBson(document)) + } + + } + + return table + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/StatisticValue.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/StatisticValue.kt new file mode 100644 index 0000000..0f04af6 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/StatisticValue.kt @@ -0,0 +1,29 @@ +package cc.fyre.hcf.statistic + + +interface StatisticValue { + + fun getValue(): T + + companion object { + + val NULL = object : StatisticValue { + + override fun getValue(): Any? { + return null + } + + } + + fun of(value: T): StatisticValue { + return object : StatisticValue { + + override fun getValue(): T { + return value + } + + } + } + } +} + diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/command/BalanceCommand.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/command/BalanceCommand.kt new file mode 100644 index 0000000..429eb46 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/command/BalanceCommand.kt @@ -0,0 +1,38 @@ +package cc.fyre.hcf.statistic.command + +import cc.fyre.core.profile.ProfileHandler +import cc.fyre.shard.command.data.command.Command +import cc.fyre.shard.command.data.parameter.Parameter +import cc.fyre.hcf.statistic.StatisticHandler +import cc.fyre.hcf.statistic.type.BalanceStatistic +import cc.fyre.shard.command.data.parameter.impl.PlayerParameterAdapter +import org.bukkit.ChatColor +import org.bukkit.command.CommandSender +import org.bukkit.entity.Player +import java.util.* + +/** + * @project hcf + * + * @date 13/09/2020 + * @author xanderume@gmail.com + */ +object BalanceCommand { + + @JvmStatic + @Command(names = ["balance","bal"]) + fun execute(sender: CommandSender, + @Parameter(name = "player",defaultValue = PlayerParameterAdapter.SELF_KEY_WORD)uuid: UUID + ) { + + val value = StatisticHandler.getStatistic(uuid,BalanceStatistic).getValue() + + if (sender is Player && sender.uniqueId == uuid) { + sender.sendMessage("${ChatColor.GOLD}Balance: ${ChatColor.WHITE}$$value") + return + } + + sender.sendMessage("${ProfileHandler.getDisplayNameById(uuid)}${ChatColor.GOLD}'s Balance: ${ChatColor.WHITE}$$value") + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/command/CobbleCommand.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/command/CobbleCommand.kt new file mode 100644 index 0000000..91d0bdb --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/command/CobbleCommand.kt @@ -0,0 +1,25 @@ +package cc.fyre.hcf.statistic.command + +import cc.fyre.shard.command.data.command.Command +import cc.fyre.hcf.statistic.StatisticHandler +import cc.fyre.hcf.statistic.type.setting.CobbleSetting +import org.bukkit.ChatColor +import org.bukkit.entity.Player + +/** + * @project hcf + * + * @date 17/09/2020 + * @author xanderume@gmail.com + */ +object CobbleCommand { + + @JvmStatic + @Command(names = ["cobble","cobblepickup"]) + fun execute(player: Player) { + val value = StatisticHandler.toggleStatistic(player.uniqueId,CobbleSetting) + + player.sendMessage("${ChatColor.YELLOW}You are now ${if (!value) "${ChatColor.GREEN}" else "${ChatColor.RED}un"}able ${ChatColor.YELLOW}to pickup cobblestone whilst in Miner Class!") + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/command/DeathMessagesCommand.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/command/DeathMessagesCommand.kt new file mode 100644 index 0000000..f86981a --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/command/DeathMessagesCommand.kt @@ -0,0 +1,26 @@ +package cc.fyre.hcf.statistic.command + +import cc.fyre.shard.command.data.command.Command +import cc.fyre.hcf.statistic.StatisticHandler +import cc.fyre.hcf.statistic.type.setting.DeathMessageSetting +import org.bukkit.ChatColor +import org.bukkit.entity.Player + +/** + * @project hcf + * + * @date 16/09/2020 + * @author xanderume@gmail.com + */ +object DeathMessagesCommand { + + @JvmStatic + @Command(names = ["deathmessages","death-messages","toggledeathmessages","tdm"]) + fun execute(player: Player) { + + val value = StatisticHandler.toggleStatistic(player.uniqueId,DeathMessageSetting) + + player.sendMessage("${ChatColor.YELLOW}You are now ${if (value) "${ChatColor.GREEN}" else "${ChatColor.RED}un"}able ${ChatColor.YELLOW}to see death messages!") + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/command/FoundDiamondsCommand.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/command/FoundDiamondsCommand.kt new file mode 100644 index 0000000..2b25755 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/command/FoundDiamondsCommand.kt @@ -0,0 +1,28 @@ +package cc.fyre.hcf.statistic.command + +import cc.fyre.shard.command.data.command.Command +import cc.fyre.hcf.HCF +import cc.fyre.hcf.statistic.StatisticHandler +import cc.fyre.hcf.statistic.type.setting.FoundDiamondSetting +import org.bukkit.ChatColor +import org.bukkit.entity.Player + +/** + * @project hcf + * + * @date 16/09/2020 + * @author xanderume@gmail.com + */ +object FoundDiamondsCommand { + + @JvmStatic + @Command(names = ["founddiamonds","found-diamonds","togglefounddiamonds","tfd","togglefd","fd toggle"]) + fun execute(player: Player) { + + val value = StatisticHandler.toggleStatistic(player.uniqueId,FoundDiamondSetting) + + player.sendMessage("${ChatColor.YELLOW}You are now ${if (value) "${ChatColor.GREEN}" else "${ChatColor.RED}un"}able ${ChatColor.YELLOW}to see found diamond messages!") + } + + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/command/LivesCommand.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/command/LivesCommand.kt new file mode 100644 index 0000000..d11f3d0 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/command/LivesCommand.kt @@ -0,0 +1,35 @@ +package cc.fyre.hcf.statistic.command + +import cc.fyre.core.profile.ProfileHandler +import cc.fyre.shard.command.data.command.Command +import cc.fyre.hcf.statistic.StatisticHandler +import cc.fyre.hcf.statistic.type.LivesStatistic +import cc.fyre.shard.command.data.parameter.Parameter +import cc.fyre.shard.command.data.parameter.impl.PlayerParameterAdapter +import org.bukkit.ChatColor +import org.bukkit.command.CommandSender +import org.bukkit.entity.Player +import java.util.* + +/** + * @project hcf + * + * @date 17/09/2020 + * @author xanderume@gmail.com + */ +object LivesCommand { + + @JvmStatic + @Command(names = ["lives"]) + fun execute(sender: CommandSender, + @Parameter(name = "player",defaultValue = PlayerParameterAdapter.SELF_KEY_WORD)uuid: UUID + ) { + if (sender is Player && sender.uniqueId != uuid && !sender.hasPermission("hcf.command.lives.advanced")) { + sender.sendMessage("${ChatColor.GOLD}Lives: ${ChatColor.WHITE}${StatisticHandler.getStatistic(uuid,LivesStatistic).getValue()}") + return + } + + sender.sendMessage("${ProfileHandler.getDisplayNameById(uuid)}${ChatColor.GOLD}'s Lives: ${ChatColor.WHITE}${StatisticHandler.getStatistic(uuid,LivesStatistic).getValue()}") + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/command/PayCommand.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/command/PayCommand.kt new file mode 100644 index 0000000..5c3259d --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/command/PayCommand.kt @@ -0,0 +1,60 @@ +package cc.fyre.hcf.statistic.command + +import cc.fyre.core.uuid.UUIDHandler +import cc.fyre.shard.command.data.command.Command +import cc.fyre.shard.command.data.parameter.Parameter +import cc.fyre.hcf.statistic.StatisticHandler +import cc.fyre.hcf.statistic.type.BalanceStatistic +import org.bukkit.Bukkit +import org.bukkit.ChatColor +import org.bukkit.entity.Player +import java.util.* + +/** + * @project hcf + * + * @date 14/09/2020 + * @author xanderume@gmail.com + */ +object PayCommand { + + @JvmStatic + @Command(names = ["pay"]) + fun execute(player: Player, + @Parameter(name = "player")uuid: UUID, + @Parameter(name = "amount")amount: Int + ) { + + if (amount <= 0) { + player.sendMessage("${ChatColor.RED}Amount must be positive.") + return + } + + if (player.uniqueId == uuid) { + player.sendMessage("${ChatColor.RED}You cannot send money to yourself.") + return + } + + val balance = StatisticHandler.getStatistic(player.uniqueId,BalanceStatistic).getValue() + + if (balance < amount) { + player.sendMessage("${ChatColor.RED}You do not have ${ChatColor.BOLD}$$amount${ChatColor.RED}!") + return + } + + StatisticHandler.increaseStatistic(uuid,BalanceStatistic,amount) + StatisticHandler.increaseStatistic(player.uniqueId,BalanceStatistic,-amount) + + Bukkit.getServer().getPlayer(uuid).also{ + + if (it == null || !it.isOnline) { + return@also + } + + it.sendMessage("${ChatColor.LIGHT_PURPLE}${player.name} ${ChatColor.YELLOW}sent you ${ChatColor.LIGHT_PURPLE}$$amount${ChatColor.YELLOW}.") + } + + player.sendMessage("${ChatColor.YELLOW}You have sent ${ChatColor.LIGHT_PURPLE}$$amount ${ChatColor.YELLOW}to ${ChatColor.LIGHT_PURPLE}${UUIDHandler.getUsernameById(uuid)}${ChatColor.YELLOW}.") + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/command/PlayTimeCommand.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/command/PlayTimeCommand.kt new file mode 100644 index 0000000..1678e3d --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/command/PlayTimeCommand.kt @@ -0,0 +1,30 @@ +package cc.fyre.hcf.statistic.command + +import cc.fyre.core.uuid.UUIDHandler +import cc.fyre.hcf.statistic.StatisticHandler +import cc.fyre.shard.command.data.command.Command +import cc.fyre.shard.command.data.parameter.Parameter +import cc.fyre.shard.command.data.parameter.impl.PlayerParameterAdapter +import cc.fyre.shard.util.TimeUtil +import org.bukkit.ChatColor +import org.bukkit.command.CommandSender +import org.bukkit.entity.Player +import java.util.* + +object PlayTimeCommand { + + @JvmStatic + @Command(names = ["playtime"]) + fun execute(sender: CommandSender,@Parameter(name = "player",defaultValue = PlayerParameterAdapter.SELF_KEY_WORD) uuid: UUID) { + + val time = TimeUtil.formatIntoDetailedString(StatisticHandler.getPlayTimeSeconds(uuid) * 1000L) + + if (sender is Player && sender.uniqueId == uuid) { + sender.sendMessage("${ChatColor.YELLOW}You have a total play time of ${ChatColor.LIGHT_PURPLE}$time${ChatColor.YELLOW}.") + return + } + + sender.sendMessage("${ChatColor.LIGHT_PURPLE}${UUIDHandler.getUsernameById(uuid)}${ChatColor.YELLOW} has a total play time of ${ChatColor.LIGHT_PURPLE}$time${ChatColor.YELLOW}.") + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/command/ReclaimCommand.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/command/ReclaimCommand.kt new file mode 100644 index 0000000..6412980 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/command/ReclaimCommand.kt @@ -0,0 +1,56 @@ +package cc.fyre.hcf.statistic.command + +import cc.fyre.core.profile.ProfileHandler +import cc.fyre.shard.command.data.command.Command +import cc.fyre.hcf.HCF +import cc.fyre.hcf.map.MapHandler +import cc.fyre.hcf.statistic.StatisticHandler +import cc.fyre.hcf.statistic.type.setting.ReclaimSetting +import cc.fyre.shard.constants.ApiConstants +import org.bukkit.Bukkit +import org.bukkit.ChatColor +import org.bukkit.entity.Player + +/** + * @project hcf + * + * @date 13/11/2020 + * @author xanderume@gmail.com + */ +object ReclaimCommand { + + @Command(names = ["reclaim"]) + fun execute(player: Player) { + + val profile = ProfileHandler.getProfileById(player.uniqueId) + + if (profile == null) { + player.sendMessage(ApiConstants.API_REQUEST_FAILED) + return + } + + if (StatisticHandler.getStatistic(player.uniqueId,ReclaimSetting).getValue()) { + player.sendMessage(ChatColor.RED.toString() + "You have already reclaimed this map.") + return + } + + val commands = MapHandler.getReclaimByRank(profile.rank) + + if (commands == null) { + player.sendMessage(ChatColor.RED.toString() + "It appears there is no reclaim found for your rank.") + return + } + + val displayName = profile.getDisplayName() + + commands.forEach{Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(),it + .replace("{player}",player.name) + .replace("{playerDisplayName}",displayName) + .replace("{rank}",profile.rank.name) + .replace("{rankDisplayName}",profile.rank.getDisplayName())) + } + + StatisticHandler.setStatistic(player.uniqueId,ReclaimSetting,true) + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/command/ReclaimResetCommand.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/command/ReclaimResetCommand.kt new file mode 100644 index 0000000..d29ef1a --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/command/ReclaimResetCommand.kt @@ -0,0 +1,36 @@ +package cc.fyre.hcf.statistic.command + +import cc.fyre.core.profile.ProfileHandler +import cc.fyre.shard.command.data.command.Command +import cc.fyre.shard.command.data.parameter.Parameter +import cc.fyre.hcf.HCF +import cc.fyre.hcf.statistic.StatisticHandler +import cc.fyre.hcf.statistic.type.setting.ReclaimSetting +import org.bukkit.ChatColor +import org.bukkit.command.CommandSender +import java.util.* + +/** + * @project hcf + * + * @date 28/11/2020 + * @author xanderume@gmail.com + */ +object ReclaimResetCommand { + + @Command(names = ["resetreclaim","reclaimreset"],hidden = true,permission = "hcf.command.reclaim.reset") + fun execute(sender: CommandSender,@Parameter(name = "player")player: UUID) { + + val displayName = ProfileHandler.getDisplayNameById(player) + + if (!StatisticHandler.getStatistic(player,ReclaimSetting).getValue()) { + sender.sendMessage("$displayName ${ChatColor.RED}has not reclaimed this map.") + return + } + + StatisticHandler.setStatistic(player,ReclaimSetting,false) + + sender.sendMessage("${ChatColor.GREEN}Reset reclaim for $displayName${ChatColor.GREEN}.") + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/command/SettingCommand.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/command/SettingCommand.kt new file mode 100644 index 0000000..611af41 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/command/SettingCommand.kt @@ -0,0 +1,21 @@ +package cc.fyre.hcf.statistic.command + +import cc.fyre.shard.command.data.command.Command +import cc.fyre.hcf.statistic.menu.SettingMenu +import org.bukkit.entity.Player + +/** + * @project hcf + * + * @date 14/09/2020 + * @author xanderume@gmail.com + */ +object SettingCommand { + + @JvmStatic + @Command(names = ["setting","settings","options"]) + fun execute(player: Player) { + SettingMenu().open(player) + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/command/parameter/StatisticParameterProvider.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/command/parameter/StatisticParameterProvider.kt new file mode 100644 index 0000000..56dcfe4 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/command/parameter/StatisticParameterProvider.kt @@ -0,0 +1,35 @@ +package cc.fyre.hcf.statistic.command.parameter + +import cc.fyre.hcf.statistic.Statistic +import cc.fyre.hcf.statistic.StatisticRegistry +import cc.fyre.shard.command.data.parameter.ParameterAdapter +import net.minecraft.util.org.apache.commons.lang3.StringUtils +import org.bukkit.ChatColor +import org.bukkit.command.CommandSender +import org.bukkit.entity.Player + +/** + * @project hcf + * + * @date 13/09/2020 + * @author xanderume@gmail.com + */ +object StatisticParameterProvider : ParameterAdapter?> { + + override fun transform(sender: CommandSender, source: String): Statistic<*>? { + + val statistic = StatisticRegistry.getStatisticByKey(source) + + if (statistic == null) { + sender.sendMessage("${ChatColor.RED}No statistic with the name \"${source}\" not found.") + return null + } + + return statistic + } + + override fun tabComplete(player: Player, flags: Set, source: String): List { + return StatisticRegistry.getAllStatistics().filter{StringUtils.startsWithIgnoreCase(it.getKey(),source)}.map{it.getKey()}.toList() + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/impl/TabOption.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/impl/TabOption.kt new file mode 100644 index 0000000..cb238a6 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/impl/TabOption.kt @@ -0,0 +1,61 @@ +package cc.fyre.hcf.statistic.impl + +import cc.fyre.hcf.faction.list.FactionListType +import org.bukkit.entity.Player +import java.util.function.Predicate +import cc.fyre.shard.tab.TabHandler + +enum class TabOption(val displayName: String,val predicate: Predicate) { + + DETAILED("Detailed",Predicate{ + + if (TabHandler.getTabById(it.uniqueId) != null) { + return@Predicate true + } + + TabHandler.create(it) + return@Predicate true + }), + FACTION_LIST("Faction List",Predicate{ + + if (TabHandler.getTabById(it.uniqueId) != null) { + return@Predicate true + } + + TabHandler.create(it) + return@Predicate true + }), + VANILLA("Vanilla",Predicate{ + + if (TabHandler.getTabById(it.uniqueId) == null) { + return@Predicate true + } + + TabHandler.destroy(it) + return@Predicate true + }); + + fun next():TabOption { + + if (this.ordinal >= getAllOptions().lastIndex) { + return getAllOptions()[0] + } + + return getAllOptions()[this.ordinal + 1] + } + + companion object { + + private val options = values().associateBy{it.name.lowercase()} + + fun getAllOptions():List { + return this.options.values.toList() + } + + fun getOptionByName(name: String):TabOption? { + return this.options[name.lowercase()] + } + + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/leaderboard/LeaderboardEntry.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/leaderboard/LeaderboardEntry.kt new file mode 100644 index 0000000..0e4e4a1 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/leaderboard/LeaderboardEntry.kt @@ -0,0 +1,19 @@ +package cc.fyre.hcf.statistic.leaderboard + +import org.bukkit.ChatColor +import java.util.* + +data class LeaderboardEntry( + val uuid: UUID, + val value: Int, + val displayName: String, +) { + + companion object { + + // MHF_Question + val NULL_ENTRY = LeaderboardEntry(UUID.fromString("606e2ff0-ed77-4842-9d6c-e1d3321c7838"),0,"${ChatColor.WHITE}???") + + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/leaderboard/LeaderboardNPC.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/leaderboard/LeaderboardNPC.kt new file mode 100644 index 0000000..907d399 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/leaderboard/LeaderboardNPC.kt @@ -0,0 +1,176 @@ +package cc.fyre.hcf.statistic.leaderboard + +import cc.fyre.core.uuid.UUIDHandler +import cc.fyre.hcf.HCF +import cc.fyre.hcf.statistic.StatisticHandler +import cc.fyre.hcf.statistic.type.BalanceStatistic +import cc.fyre.hcf.statistic.type.KillStreakStatistic +import cc.fyre.hcf.statistic.type.KillsStatistic +import cc.fyre.hcf.statistic.type.PlayTimeStatistic +import cc.fyre.hcf.statistic.type.ores.DiamondMinedStatistic +import cc.fyre.shard.entity.type.npc.NPC +import com.squareup.moshi.JsonClass +import org.apache.commons.lang.StringUtils +import org.bukkit.Bukkit +import org.bukkit.ChatColor +import org.bukkit.Location +import java.util.* + +@JsonClass(generateAdapter = true) +class LeaderboardNPC(location: Location) : NPC("Leaderboards",location) { + + @Transient private var index = 0 + @Transient private var current = TYPES[this.index] + @Transient private var entries = StatisticHandler.getLeaderboard(this.current) ?: arrayOf() + @Transient private var countdown = INTERVAL + + @Transient private var blockIndex = 0 + + override fun init() { + super.init() + this.hologram.lines.clear() + this.updateNPC() + this.updateHologram() + } + + override fun onTick() { + + if (this.tick < 19) { + return + } + + this.countdown-- + + if (this.countdown > 0) { + + if (this.countdown % 3 != 0) { + return + } + + this.blockIndex++ + this.hologram.setText(this.hologram.lines.lastIndex,"${ChatColor.GRAY}[${this.getLoadingText()}${ChatColor.GRAY}]") + return + } + + this.countdown = INTERVAL + + if (this.index >= TYPES.lastIndex) { + this.index = 0 + this.current = TYPES[0] + } else { + this.index++ + this.current = TYPES[this.index] + } + + this.blockIndex = 0 + + this.entries = StatisticHandler.getLeaderboard(this.current) ?: arrayOf() + this.updateNPC() + + Bukkit.getServer().scheduler.runTaskAsynchronously(HCF.instance) { + this.updateHologram() + } + } + + private fun updateNPC() { + + val entry = if (this.entries.isEmpty()) LeaderboardEntry.NULL_ENTRY else this.entries[0] + + if (entry.uuid == UNKNOWN_UUID) { + this.setSkin(entry.displayName,UNKNOWN_SKIN_TEXTURE,UNKNOWN_SKIN_SIGNATURE) + return + } + + val player = Bukkit.getServer().getPlayer(entry.uuid) + + if (player != null) { + + if (this.skinUsername == player.name) { + return + } + + this.setSkin(player) + return + } + + UUIDHandler.getService().getSkinFromMojang(entry.uuid).execute().also{ + + if (it.body() == null) { + HCF.instance.server.logger.info("API request for ${ChatColor.stripColor(entry.displayName)}'s skin texture failed.") + this.setSkin(entry.displayName,UNKNOWN_SKIN_TEXTURE,UNKNOWN_SKIN_SIGNATURE) + return@also + } + + if (this.skinUsername == it.body()!!.username) { + return + } + + this.setSkin(it.body()!!.username,it.body()!!.texture,it.body()!!.signature) + } + + } + + private fun updateHologram() { + + val text = arrayListOf() + + text.add("${ChatColor.RED}${ChatColor.BOLD}${this.current.getDisplayName(0)}") + text.add("${ChatColor.GOLD}${ChatColor.BOLD}Leaderboard") + text.add("blank") + + for (i in 0 until 5) { + + val entry = if (i >= this.entries.lastIndex) { + LeaderboardEntry.NULL_ENTRY + } else { + this.entries[i] + } + + val value = when (this.current) { + is PlayTimeStatistic -> PlayTimeStatistic.format(entry.value) + is BalanceStatistic -> "$${entry.value}" + else -> entry.value + } + + text.add("${StatisticHandler.LEADERBOARD_COLORS[i + 1]}#${i + 1} ${entry.displayName}${ChatColor.GRAY}: ${ChatColor.YELLOW}$value") + } + + text.add("blank") + text.add(DEFAULT_LOADING_TEXT.toString()) + + this.hologram.setText(*text.toTypedArray()) + } + + fun getLoadingText():String { + val blocks = arrayOfNulls(TEXT_LENGTH) + + Arrays.fill(blocks,"${ChatColor.GRAY}$ICON") + + for (i in 0 until this.blockIndex) { + blocks[i] = "${ChatColor.GREEN}$ICON" + } + + return StringUtils.join(blocks) + } + + companion object { + + val TYPES = arrayOf( + KillsStatistic, + PlayTimeStatistic, + KillStreakStatistic, + DiamondMinedStatistic + ) + + const val ICON = "■" + const val INTERVAL = 30 + const val TEXT_LENGTH = 10 + + val DEFAULT_LOADING_TEXT = StringBuilder("${ChatColor.GRAY}[${StringUtils.repeat(ICON,TEXT_LENGTH)}]") + + val UNKNOWN_UUID = LeaderboardEntry.NULL_ENTRY.uuid + val UNKNOWN_SKIN_TEXTURE = "ewogICJ0aW1lc3RhbXAiIDogMTYzOTQ5NDIyMjYzNSwKICAicHJvZmlsZUlkIiA6ICI2MDZlMmZmMGVkNzc0ODQyOWQ2Y2UxZDMzMjFjNzgzOCIsCiAgInByb2ZpbGVOYW1lIiA6ICJNSEZfUXVlc3Rpb24iLAogICJzaWduYXR1cmVSZXF1aXJlZCIgOiB0cnVlLAogICJ0ZXh0dXJlcyIgOiB7CiAgICAiU0tJTiIgOiB7CiAgICAgICJ1cmwiIDogImh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvZDM0ZTA2M2NhZmI0NjdhNWM4ZGU0M2VjNzg2MTkzOTlmMzY5ZjRhNTI0MzRkYTgwMTdhOTgzY2RkOTI1MTZhMCIKICAgIH0KICB9Cn0=" + val UNKNOWN_SKIN_SIGNATURE = "xWzxlNdWjlWcSwFbD3C9ImROtxdbftibDzb6FpJvArF0e5XYavb/tDhL0gAewBaJsQQj5oXkjRO3P5JC0dmS3jpcgvGyUCXRzj840CKpls0Hb0Dp3erV1tJV7vKBd8v6h/r1COAxUSHFlyFdDgG5DrptVx3tDDtX9JiuJE/I+voUaHUol8clYFAanQkc2ADv9cJmZ649vwIJU+MWyefHdv8+/bcsg/tZECQomRkAs+Ht7usjZmrJc3JrZ/dnMewgFEg5SHta4URzAWFxtho1FkS/fW0HCRzjzE22p1RGv8rIIRunQbBQQb476ATjp8un5i2TCcNR80VEJx5P1759K5qnMyTIyhJ8gAOfUIVKZal+GEeeAZvO/9Qn44p6im2zCkCiku7Wcs7Hy91SnaeKHSxyGtKfpZ0WUfwt9cBRbHU+XffTcInI8buPIagtObq8iuJJKnr4Gwpa9aPY2N0x7CNeBtswMdIaF2BY6awfOHL7wcaMNN9KoM3cNwCfhOsU0UVvLL3tF2M1L5eFY/1LAeQJp58f4eCo35KYzPaeGAOFBssgUdnV4W5deRAHqpOW6YkwuFMQgEueKPTZE46FWI6yO8Yw4yDg1G5meUWSQNSnMoKO7kwsVECu6B3fnnM9IDLe/UlqeSqky04TWNeZTbb4sPj+bDI7C75OIi6k7h0=" + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/leaderboard/LeaderboardUpdateTask.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/leaderboard/LeaderboardUpdateTask.kt new file mode 100644 index 0000000..737858d --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/leaderboard/LeaderboardUpdateTask.kt @@ -0,0 +1,35 @@ +package cc.fyre.hcf.statistic.leaderboard + +import cc.fyre.core.profile.ProfileHandler +import cc.fyre.hcf.statistic.StatisticHandler +import cc.fyre.hcf.statistic.StatisticRegistry +import cc.fyre.hcf.statistic.type.defaults.IntStatistic + +object LeaderboardUpdateTask : Runnable { + + override fun run() { + + for (statistic in StatisticRegistry.getAllStatistics()) { + + if (statistic !is IntStatistic) { + continue + } + + // I was thinking of caching old entries and checking if + // they had the same value so we don't have to request + // their displayName everytime but the core already + // caches these for 10 minutes and leaderboards update every 5 + + val leaderboard = StatisticHandler.getStatistics(statistic) + .entries + .sortedByDescending{it.value.getValue()} + .take(10) + .map{LeaderboardEntry(it.key,it.value.getValue(),ProfileHandler.getDisplayNameById(it.key))} + + StatisticHandler.setLeaderboard(statistic,leaderboard.toTypedArray()) + } + + StatisticHandler.setLastLeaderboardUpdate(System.currentTimeMillis()) + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/leaderboard/command/LeaderboardCommand.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/leaderboard/command/LeaderboardCommand.kt new file mode 100644 index 0000000..e5254f6 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/leaderboard/command/LeaderboardCommand.kt @@ -0,0 +1,60 @@ +package cc.fyre.hcf.statistic.leaderboard.command + +import cc.fyre.hcf.statistic.Statistic +import cc.fyre.shard.command.data.command.Command +import cc.fyre.shard.command.data.parameter.Parameter +import cc.fyre.hcf.statistic.StatisticHandler +import cc.fyre.hcf.statistic.leaderboard.LeaderboardEntry +import cc.fyre.hcf.statistic.type.BalanceStatistic +import cc.fyre.hcf.statistic.type.PlayTimeStatistic +import cc.fyre.shard.util.TimeUtil +import org.apache.commons.lang.StringUtils +import org.bukkit.ChatColor +import org.bukkit.command.CommandSender + +/** + * @project hcf + * + * @date 17/09/2020 + * @author xanderume@gmail.com + */ +object LeaderboardCommand { + + @JvmStatic + @Command(names = ["statistic top","stats top","leaderboard","leaderboards","lb"]) + fun execute(sender: CommandSender,@Parameter(name = "statistic",wildcard = true)statistic: Statistic<*>) { + + val leaderboard = StatisticHandler.getLeaderboard(statistic) + + if (leaderboard == null) { + sender.sendMessage("${ChatColor.RED}No leaderboard found for ${statistic.getKey()}!") + return + } + + val nextUpdate = StatisticHandler.LEADERBOARD_INTERVAL_MILLIS - (System.currentTimeMillis() - StatisticHandler.getLastLeaderboardUpdate()) + + sender.sendMessage("${ChatColor.GRAY}${ChatColor.STRIKETHROUGH}${StringUtils.repeat("-",53)}") + sender.sendMessage("${ChatColor.GOLD}${ChatColor.BOLD}${statistic.getName()}${ChatColor.GRAY} - Updates in ${ChatColor.YELLOW}${TimeUtil.formatIntoMMSS(nextUpdate)}") + sender.sendMessage(" ") + + for (i in 0 until 10) { + + val entry = if (i > leaderboard.lastIndex) { + LeaderboardEntry.NULL_ENTRY + } else { + leaderboard[i] + } + + val value = when (statistic) { + is PlayTimeStatistic -> PlayTimeStatistic.format(entry.value) + is BalanceStatistic -> "$${entry.value}" + else -> entry.value + } + + sender.sendMessage("${StatisticHandler.LEADERBOARD_COLORS[i + 1] ?: ChatColor.GRAY}#${i + 1} ${entry.displayName}${ChatColor.GRAY}: ${ChatColor.YELLOW}${entry.value}") + } + + sender.sendMessage("${ChatColor.GRAY}${ChatColor.STRIKETHROUGH}${StringUtils.repeat("-",53)}") + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/leaderboard/command/LeaderboardNPCCommand.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/leaderboard/command/LeaderboardNPCCommand.kt new file mode 100644 index 0000000..eb4d98d --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/leaderboard/command/LeaderboardNPCCommand.kt @@ -0,0 +1,30 @@ +package cc.fyre.hcf.statistic.leaderboard.command + +import cc.fyre.hcf.statistic.leaderboard.LeaderboardNPC +import cc.fyre.shard.command.data.command.Command +import cc.fyre.shard.entity.EntityHandler +import cc.fyre.shard.entity.EntityVisibility +import org.bukkit.ChatColor +import org.bukkit.entity.Player + +object LeaderboardNPCCommand { + + @JvmStatic + @Command(names = ["leaderboardnpc","lbnpc"],permission = "hcf.command.leaderboard.npc") + fun execute(sender: Player) { + + for (entity in EntityHandler.getAllEntities().filterIsInstance()) { + EntityHandler.destroy(entity) + } + + sender.sendMessage("${ChatColor.GREEN}Spawned leaderboard NPC") + + val npc = LeaderboardNPC(sender.location.clone()) + + npc.tagVisibility = EntityVisibility.HIDDEN + npc.tabVisibility = EntityVisibility.HIDDEN + + EntityHandler.register(npc) + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/listener/StatisticListener.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/listener/StatisticListener.kt new file mode 100644 index 0000000..608cfaa --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/listener/StatisticListener.kt @@ -0,0 +1,67 @@ +package cc.fyre.hcf.statistic.listener + +import cc.fyre.hcf.statistic.StatisticHandler +import cc.fyre.hcf.statistic.type.PlayTimeStatistic +import cc.fyre.hcf.statistic.type.ores.* +import org.bukkit.Material +import org.bukkit.enchantments.Enchantment +import org.bukkit.event.EventHandler +import org.bukkit.event.EventPriority +import org.bukkit.event.Listener +import org.bukkit.event.block.BlockBreakEvent +import org.bukkit.event.player.PlayerJoinEvent +import org.bukkit.event.player.PlayerQuitEvent +import java.util.* + +/** + * @project hcf + * + * @date 28/11/2020 + * @author xanderume@gmail.com + */ +object StatisticListener : Listener { + + + @EventHandler(priority = EventPriority.MONITOR) + private fun onPlayerJoin(event: PlayerJoinEvent) { + StatisticHandler.createPlayTimeSession(event.player) + } + + @EventHandler(priority = EventPriority.MONITOR) + private fun onPlayerQuit(event: PlayerQuitEvent) { + + val time = StatisticHandler.destroyPlayTimeSession(event.player) + + if (time == null) { + return + } + + StatisticHandler.increaseStatistic(event.player.uniqueId,PlayTimeStatistic,((System.currentTimeMillis() - time) / 1000).toInt()) + } + + @EventHandler(priority = EventPriority.HIGH) + private fun onBlockBreak(event: BlockBreakEvent) { + + if (event.isCancelled) { + return + } + + if (event.player.itemInHand != null && event.player.itemInHand.containsEnchantment(Enchantment.SILK_TOUCH)) { + return + } + + val statistic = when(event.block.type) { + Material.COAL_ORE -> CoalMinedStatistic + Material.IRON_ORE -> IronMinedStatistic + Material.GOLD_ORE -> GoldMinedStatistic + Material.LAPIS_ORE -> LapisMinedStatistic + Material.DIAMOND_ORE -> DiamondMinedStatistic + Material.EMERALD_ORE -> EmeraldMinedStatistic + Material.GLOWING_REDSTONE_ORE -> RedstoneMinedStatistic + else -> null + } ?: return + + StatisticHandler.increaseStatistic(event.player.uniqueId,statistic,1) + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/menu/SettingButton.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/menu/SettingButton.kt new file mode 100644 index 0000000..789480a --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/menu/SettingButton.kt @@ -0,0 +1,76 @@ +package cc.fyre.hcf.statistic.menu + +import cc.fyre.hcf.HCF +import cc.fyre.hcf.statistic.Statistic +import cc.fyre.hcf.statistic.StatisticHandler +import cc.fyre.hcf.statistic.StatisticValue +import cc.fyre.hcf.statistic.impl.TabOption +import cc.fyre.hcf.statistic.type.defaults.BooleanStatistic +import cc.fyre.shard.menu.button.Button +import cc.fyre.shard.tab.TabHandler +import cc.fyre.shard.util.UnicodeUtil +import cc.fyre.shard.util.item.ItemBuilder +import org.bukkit.Bukkit +import org.bukkit.ChatColor +import org.bukkit.entity.Player +import org.bukkit.event.inventory.InventoryClickEvent +import org.bukkit.inventory.ItemStack + +/** + * @project hcf + * + * @date 14/09/2020 + * @author xanderume@gmail.com + */ +class SettingButton(private val setting: Statistic) : Button() { + + override fun getItem(player: Player): ItemStack { + + val lore = ArrayList() + val value = StatisticHandler.getStatistic(player.uniqueId,this.setting).getValue() + + this.setting.getDescription().forEach{lore.add("${ChatColor.BLUE}$it")} + + lore.add(" ") + + for (option in this.setting.getOptions()) { + + val color = if (value == option.value) ChatColor.GREEN else ChatColor.GRAY + + lore.add("$color${ChatColor.BOLD}${UnicodeUtil.SMALL_ARROW} $color${option.name}") + } + + lore.add(" ") + lore.add("${ChatColor.YELLOW}Click to switch options") + + return ItemBuilder.of(this.setting.icon) + .name("${ChatColor.BLUE}${ChatColor.BOLD}${this.setting.getName()}") + .data(this.setting.data) + .lore(lore) + .build() + } + + override fun onClick(player: Player, event: InventoryClickEvent) { + + val old = StatisticHandler.getStatistic(player.uniqueId,this.setting).getValue() + val new = this.setting.getNextValue(old) + + if (old is TabOption && new is TabOption) { + + if (old == TabOption.VANILLA) { + TabHandler.create(player) + } else if (new == TabOption.VANILLA) { + Bukkit.getServer().scheduler.runTaskAsynchronously(HCF.instance) { + TabHandler.destroy(player) + } + } + + } + + StatisticHandler.setStatistic(player.uniqueId,this.setting,new) + } + + override fun isRefresh(player: Player): Boolean { + return true + } +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/menu/SettingMenu.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/menu/SettingMenu.kt new file mode 100644 index 0000000..843f65f --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/menu/SettingMenu.kt @@ -0,0 +1,41 @@ +package cc.fyre.hcf.statistic.menu + +import cc.fyre.hcf.statistic.impl.TabOption +import cc.fyre.hcf.statistic.type.setting.* +import cc.fyre.shard.menu.Menu +import cc.fyre.shard.menu.button.Button +import org.bukkit.entity.Player + +/** + * @project hcf + * + * @date 14/09/2020 + * @author xanderume@gmail.com + */ +class SettingMenu : Menu() { + + override fun getSize(player: Player, buttons: Map): Int { + return 3*9 + } + + override fun getTitle(player: Player): String { + return "Settings" + } + + override fun getButtons(player: Player): MutableMap { + return mutableMapOf( + 10 to SettingButton(TabListSetting), + 11 to SettingButton(DeathMessageSetting), + 12 to SettingButton(FoundDiamondSetting), + 13 to SettingButton(FactionFocusSetting), + 14 to SettingButton(FactionFilterSetting), + 15 to SettingButton(EventMessageSetting), + 16 to SettingButton(AbilityCooldownSetting), + ) + } + + override fun isFill(player: Player, buttons: Map): Boolean { + return true + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/serializer/StatisticJsonAdapter.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/serializer/StatisticJsonAdapter.kt new file mode 100644 index 0000000..724eb63 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/serializer/StatisticJsonAdapter.kt @@ -0,0 +1,22 @@ +package cc.fyre.hcf.statistic.serializer + +import cc.fyre.hcf.statistic.Statistic +import cc.fyre.hcf.statistic.StatisticRegistry +import com.squareup.moshi.FromJson +import com.squareup.moshi.ToJson + +object StatisticJsonAdapter { + + @ToJson + fun toJson(@StatisticSerializer statistic: Statistic<*>):String { + return statistic.getKey() + } + + @FromJson + @StatisticSerializer + fun fromJson(value: String): Statistic<*>? { + return StatisticRegistry.getStatisticByKey(value) + } + + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/serializer/StatisticSerializer.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/serializer/StatisticSerializer.kt new file mode 100644 index 0000000..5b512ec --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/serializer/StatisticSerializer.kt @@ -0,0 +1,8 @@ +package cc.fyre.hcf.statistic.serializer + +import com.squareup.moshi.JsonQualifier + +@Retention(AnnotationRetention.RUNTIME) +@Target(AnnotationTarget.FIELD,AnnotationTarget.FUNCTION,AnnotationTarget.TYPE_PARAMETER,AnnotationTarget.VALUE_PARAMETER) +@JsonQualifier +annotation class StatisticSerializer \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/type/BalanceStatistic.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/type/BalanceStatistic.kt new file mode 100644 index 0000000..8eb4094 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/type/BalanceStatistic.kt @@ -0,0 +1,5 @@ +package cc.fyre.hcf.statistic.type + +import cc.fyre.hcf.statistic.type.defaults.IntStatistic + +object BalanceStatistic : IntStatistic("balance", "Balance",250) \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/type/DeathsStatistic.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/type/DeathsStatistic.kt new file mode 100644 index 0000000..8a5000a --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/type/DeathsStatistic.kt @@ -0,0 +1,5 @@ +package cc.fyre.hcf.statistic.type + +import cc.fyre.hcf.statistic.type.defaults.IntStatistic + +object DeathsStatistic : IntStatistic("deaths","Deaths",0) \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/type/HighestKillStreak.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/type/HighestKillStreak.kt new file mode 100644 index 0000000..a0c3a9d --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/type/HighestKillStreak.kt @@ -0,0 +1,5 @@ +package cc.fyre.hcf.statistic.type + +import cc.fyre.hcf.statistic.type.defaults.IntStatistic + +object HighestKillStreak : IntStatistic("highestKillStreak","Highest Kill Streak",0) \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/type/KillStreakStatistic.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/type/KillStreakStatistic.kt new file mode 100644 index 0000000..dccf3a4 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/type/KillStreakStatistic.kt @@ -0,0 +1,5 @@ +package cc.fyre.hcf.statistic.type + +import cc.fyre.hcf.statistic.type.defaults.IntStatistic + +object KillStreakStatistic : IntStatistic("killStreak","Kill Streak",0) \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/type/KillsStatistic.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/type/KillsStatistic.kt new file mode 100644 index 0000000..d8a40b5 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/type/KillsStatistic.kt @@ -0,0 +1,5 @@ +package cc.fyre.hcf.statistic.type + +import cc.fyre.hcf.statistic.type.defaults.IntStatistic + +object KillsStatistic : IntStatistic("kills","Kills",0) \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/type/LivesStatistic.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/type/LivesStatistic.kt new file mode 100644 index 0000000..57098c4 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/type/LivesStatistic.kt @@ -0,0 +1,5 @@ +package cc.fyre.hcf.statistic.type + +import cc.fyre.hcf.statistic.type.defaults.IntStatistic + +object LivesStatistic : IntStatistic("lives","Lives",0) \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/type/PlayTimeStatistic.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/type/PlayTimeStatistic.kt new file mode 100644 index 0000000..f28c35e --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/type/PlayTimeStatistic.kt @@ -0,0 +1,36 @@ +package cc.fyre.hcf.statistic.type + +import cc.fyre.hcf.statistic.type.defaults.IntStatistic + +// stored in seconds +object PlayTimeStatistic : IntStatistic("playTime","Play Time",0) { + + fun format(secs: Int):String { + + val remainder = secs % 86400 + + val days = secs / 86400 + val hours = remainder / 3600 + val minutes = remainder / 60 - hours * 60 + val seconds = remainder % 3600 - minutes * 60 + + val fDays = if (days > 0) " ${days}d" else "" + + var fHours = "" + var fMinutes = "" + var fSeconds = "" + + if (days < 1) { + fHours = if (hours > 0) " ${hours}h" else "" + + if (hours < 1) { + fMinutes = if (minutes > 0) " ${minutes}m" else "" + fSeconds = if (seconds > 0) " ${seconds}s" else "" + } + + } + + return (fDays + fHours + fMinutes + fSeconds).trim { it <= ' ' } + } + +} diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/type/defaults/BooleanStatistic.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/type/defaults/BooleanStatistic.kt new file mode 100644 index 0000000..3aa523c --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/type/defaults/BooleanStatistic.kt @@ -0,0 +1,71 @@ +package cc.fyre.hcf.statistic.type.defaults + +import cc.fyre.core.profile.Profile +import cc.fyre.hcf.statistic.Statistic +import cc.fyre.hcf.statistic.StatisticOption +import cc.fyre.hcf.statistic.StatisticValue +import org.bson.Document + +abstract class BooleanStatistic( + private val key: String, + private val displayName: String, + private val defaultValue: Boolean +): Statistic() { + + override fun getKey(): String { + return this.key + } + + override fun getOptions(): List> { + return options + } + + override fun getName(): String { + return this.displayName + } + + override fun getDisplayName(value: Boolean): String { + return this.displayName + } + + override fun getNextValue(value: Boolean): Boolean { + return !value + } + + override fun getDefaultValue(): StatisticValue { + return object : StatisticValue { + + override fun getValue(): Boolean { + return this@BooleanStatistic.defaultValue + } + + } + } + + override fun isSetting(): Boolean { + return true + } + + override fun hasPermission(profile: Profile, value: Boolean): Boolean { + return true + } + + override fun fromBson(document: Document): StatisticValue { + return object : StatisticValue { + + override fun getValue(): Boolean { + return document.getBoolean(this@BooleanStatistic.key) + } + + } + } + + companion object { + + private val options = arrayListOf( + StatisticOption("Enabled",true), + StatisticOption("Disabled",false) + ) + + } +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/type/defaults/IntStatistic.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/type/defaults/IntStatistic.kt new file mode 100644 index 0000000..83e6116 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/type/defaults/IntStatistic.kt @@ -0,0 +1,63 @@ +package cc.fyre.hcf.statistic.type.defaults + +import cc.fyre.core.profile.Profile +import cc.fyre.hcf.statistic.Statistic +import cc.fyre.hcf.statistic.StatisticOption +import cc.fyre.hcf.statistic.StatisticValue +import org.bson.Document + +abstract class IntStatistic( + private val key: String, + private val displayName: String, + private val defaultValue: Int +): Statistic() { + + override fun getKey(): String { + return this.key + } + + override fun getName(): String { + return this.displayName + } + + override fun getDisplayName(value: Int): String { + return this.displayName + } + + override fun isSetting(): Boolean { + return false + } + + override fun getOptions(): List> { + return listOf() + } + + override fun hasPermission(profile: Profile, value: Int): Boolean { + return true + } + + override fun getNextValue(value: Int): Int { + return value + } + + override fun getDefaultValue(): StatisticValue { + return object : StatisticValue { + + override fun getValue(): Int { + return this@IntStatistic.defaultValue + } + + } + } + + override fun fromBson(document: Document): StatisticValue { + return object : StatisticValue { + + override fun getValue(): Int { + return document.getInteger(this@IntStatistic.key) + } + + } + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/type/ores/CoalMinedStatistic.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/type/ores/CoalMinedStatistic.kt new file mode 100644 index 0000000..f23d2c4 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/type/ores/CoalMinedStatistic.kt @@ -0,0 +1,5 @@ +package cc.fyre.hcf.statistic.type.ores + +import cc.fyre.hcf.statistic.type.defaults.IntStatistic + +object CoalMinedStatistic : IntStatistic("coalMined","Coal Mined",0) \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/type/ores/DiamondMinedStatistic.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/type/ores/DiamondMinedStatistic.kt new file mode 100644 index 0000000..d093973 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/type/ores/DiamondMinedStatistic.kt @@ -0,0 +1,5 @@ +package cc.fyre.hcf.statistic.type.ores + +import cc.fyre.hcf.statistic.type.defaults.IntStatistic + +object DiamondMinedStatistic : IntStatistic("diamondMined","Diamonds Mined",0) \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/type/ores/EmeraldMinedStatistic.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/type/ores/EmeraldMinedStatistic.kt new file mode 100644 index 0000000..1f55e72 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/type/ores/EmeraldMinedStatistic.kt @@ -0,0 +1,5 @@ +package cc.fyre.hcf.statistic.type.ores + +import cc.fyre.hcf.statistic.type.defaults.IntStatistic + +object EmeraldMinedStatistic : IntStatistic("emeraldMined","Emerald Mined",0) \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/type/ores/GoldMinedStatistic.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/type/ores/GoldMinedStatistic.kt new file mode 100644 index 0000000..16b9594 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/type/ores/GoldMinedStatistic.kt @@ -0,0 +1,5 @@ +package cc.fyre.hcf.statistic.type.ores + +import cc.fyre.hcf.statistic.type.defaults.IntStatistic + +object GoldMinedStatistic : IntStatistic("goldMined","Gold Mined",0) \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/type/ores/IronMinedStatistic.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/type/ores/IronMinedStatistic.kt new file mode 100644 index 0000000..54eac85 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/type/ores/IronMinedStatistic.kt @@ -0,0 +1,5 @@ +package cc.fyre.hcf.statistic.type.ores + +import cc.fyre.hcf.statistic.type.defaults.IntStatistic + +object IronMinedStatistic : IntStatistic("ironMined","Iron Mined",0) \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/type/ores/LapisMinedStatistic.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/type/ores/LapisMinedStatistic.kt new file mode 100644 index 0000000..3082980 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/type/ores/LapisMinedStatistic.kt @@ -0,0 +1,5 @@ +package cc.fyre.hcf.statistic.type.ores + +import cc.fyre.hcf.statistic.type.defaults.IntStatistic + +object LapisMinedStatistic : IntStatistic("lapisMined","Lapis Mined",0) \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/type/ores/RedstoneMinedStatistic.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/type/ores/RedstoneMinedStatistic.kt new file mode 100644 index 0000000..a189831 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/type/ores/RedstoneMinedStatistic.kt @@ -0,0 +1,5 @@ +package cc.fyre.hcf.statistic.type.ores + +import cc.fyre.hcf.statistic.type.defaults.IntStatistic + +object RedstoneMinedStatistic : IntStatistic("redstoneMined","Redstone Mined",0) \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/type/setting/AbilityCooldownSetting.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/type/setting/AbilityCooldownSetting.kt new file mode 100644 index 0000000..bba6aa9 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/type/setting/AbilityCooldownSetting.kt @@ -0,0 +1,12 @@ +package cc.fyre.hcf.statistic.type.setting + +import cc.fyre.hcf.statistic.type.defaults.BooleanStatistic +import org.bukkit.Material + +object AbilityCooldownSetting : BooleanStatistic("abilityCooldowns","Ability Cooldowns",true) { + + init { + this.icon = Material.BLAZE_POWDER + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/type/setting/CobbleSetting.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/type/setting/CobbleSetting.kt new file mode 100644 index 0000000..e891188 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/type/setting/CobbleSetting.kt @@ -0,0 +1,5 @@ +package cc.fyre.hcf.statistic.type.setting + +import cc.fyre.hcf.statistic.type.defaults.BooleanStatistic + +object CobbleSetting : BooleanStatistic("cobblePickup","Cobble Pickup",true) \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/type/setting/CustomTimersSetting.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/type/setting/CustomTimersSetting.kt new file mode 100644 index 0000000..2e20ea1 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/type/setting/CustomTimersSetting.kt @@ -0,0 +1,5 @@ +package cc.fyre.hcf.statistic.type.setting + +import cc.fyre.hcf.statistic.type.defaults.BooleanStatistic + +object CustomTimersSetting : BooleanStatistic("customTimers","Custom Timers",true) \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/type/setting/DeathMessageSetting.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/type/setting/DeathMessageSetting.kt new file mode 100644 index 0000000..19efe39 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/type/setting/DeathMessageSetting.kt @@ -0,0 +1,12 @@ +package cc.fyre.hcf.statistic.type.setting + +import cc.fyre.hcf.statistic.type.defaults.BooleanStatistic +import org.bukkit.Material + +object DeathMessageSetting : BooleanStatistic("deathMessages","Death Messages",true) { + + init { + this.icon = Material.SIGN + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/type/setting/EventMessageSetting.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/type/setting/EventMessageSetting.kt new file mode 100644 index 0000000..7a83dc8 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/type/setting/EventMessageSetting.kt @@ -0,0 +1,12 @@ +package cc.fyre.hcf.statistic.type.setting + +import cc.fyre.hcf.statistic.type.defaults.BooleanStatistic +import org.bukkit.Material + +object EventMessageSetting : BooleanStatistic("eventMessages","Event Messages",true) { + + init { + this.icon = Material.BEACON + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/type/setting/FactionFilterSetting.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/type/setting/FactionFilterSetting.kt new file mode 100644 index 0000000..c289a9d --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/type/setting/FactionFilterSetting.kt @@ -0,0 +1,62 @@ +package cc.fyre.hcf.statistic.type.setting + +import cc.fyre.core.profile.Profile +import cc.fyre.hcf.faction.Faction +import cc.fyre.hcf.faction.list.FactionListType +import cc.fyre.hcf.statistic.Statistic +import cc.fyre.hcf.statistic.StatisticOption +import cc.fyre.hcf.statistic.StatisticValue +import cc.fyre.hcf.statistic.impl.TabOption +import org.bson.Document +import org.bukkit.Material + +object FactionFilterSetting : Statistic() { + + init { + this.icon = Material.ANVIL + } + + private val options = FactionListType.getAllTypes().filter{it.filterable} + .map{StatisticOption(it.displayName,it)} + + override fun toBson(document: Document, value: Any) { + document[this.getKey()] = (value as TabOption).name + } + + override fun fromBson(document: Document): StatisticValue { + return StatisticValue.of(FactionListType.getTypeByName(document.getString(this.getKey())) ?: FactionListType.MAX_ONLINE) + } + + override fun getDefaultValue(): StatisticValue { + return StatisticValue.of(FactionListType.MAX_ONLINE) + } + + override fun getName(): String { + return "Filter Type" + } + + override fun getNextValue(value: FactionListType): FactionListType { + return value.next(true) + } + + override fun getDisplayName(value: FactionListType): String { + return value.displayName + } + + override fun getKey(): String { + return "filterType" + } + + override fun getOptions(): List> { + return this.options + } + + override fun hasPermission(profile: Profile, value: FactionListType): Boolean { + return true + } + + override fun isSetting(): Boolean { + return true + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/type/setting/FactionFocusSetting.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/type/setting/FactionFocusSetting.kt new file mode 100644 index 0000000..ce9d5db --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/type/setting/FactionFocusSetting.kt @@ -0,0 +1,12 @@ +package cc.fyre.hcf.statistic.type.setting + +import cc.fyre.hcf.statistic.type.defaults.BooleanStatistic +import org.bukkit.Material + +object FactionFocusSetting : BooleanStatistic("factionFocus","Faction Focus",true) { + + init { + this.icon = Material.COMPASS + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/type/setting/FoundDiamondSetting.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/type/setting/FoundDiamondSetting.kt new file mode 100644 index 0000000..32d945d --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/type/setting/FoundDiamondSetting.kt @@ -0,0 +1,12 @@ +package cc.fyre.hcf.statistic.type.setting + +import cc.fyre.hcf.statistic.type.defaults.BooleanStatistic +import org.bukkit.Material + +object FoundDiamondSetting : BooleanStatistic("foundDiamonds","Found Diamonds",true) { + + init { + this.icon = Material.DIAMOND + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/type/setting/MapSetting.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/type/setting/MapSetting.kt new file mode 100644 index 0000000..5449c9b --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/type/setting/MapSetting.kt @@ -0,0 +1,5 @@ +package cc.fyre.hcf.statistic.type.setting + +import cc.fyre.hcf.statistic.type.defaults.BooleanStatistic + +object MapSetting : BooleanStatistic("map","Faction Map",false) \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/type/setting/ReclaimSetting.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/type/setting/ReclaimSetting.kt new file mode 100644 index 0000000..e3e1bf7 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/type/setting/ReclaimSetting.kt @@ -0,0 +1,5 @@ +package cc.fyre.hcf.statistic.type.setting + +import cc.fyre.hcf.statistic.type.defaults.BooleanStatistic + +object ReclaimSetting : BooleanStatistic("reclaimed","Reclaimed",false) \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/type/setting/SOTWProtectionSetting.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/type/setting/SOTWProtectionSetting.kt new file mode 100644 index 0000000..7e74725 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/type/setting/SOTWProtectionSetting.kt @@ -0,0 +1,5 @@ +package cc.fyre.hcf.statistic.type.setting + +import cc.fyre.hcf.statistic.type.defaults.BooleanStatistic + +object SOTWProtectionSetting : BooleanStatistic("sotwProtection","SOTW Protection",true) \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/type/setting/TabListSetting.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/type/setting/TabListSetting.kt new file mode 100644 index 0000000..5329bba --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/statistic/type/setting/TabListSetting.kt @@ -0,0 +1,66 @@ +package cc.fyre.hcf.statistic.type.setting + +import cc.fyre.core.profile.Profile +import cc.fyre.hcf.statistic.Statistic +import cc.fyre.hcf.statistic.StatisticOption +import cc.fyre.hcf.statistic.StatisticValue +import cc.fyre.hcf.statistic.impl.TabOption +import org.bson.Document +import org.bukkit.Material + +object TabListSetting : Statistic() { + + init { + this.icon = Material.ITEM_FRAME + } + + private val options = TabOption.getAllOptions().map{StatisticOption(it.displayName,it)} + + override fun getKey(): String { + return "tabList" + } + + override fun getName(): String { + return "Tab Option" + } + + override fun getOptions(): List> { + return this.options + } + + override fun getNextValue(value: TabOption): TabOption { + return value.next() + } + + override fun getDefaultValue(): StatisticValue { + return object : StatisticValue { + + override fun getValue(): TabOption { + return TabOption.FACTION_LIST + } + + } + } + + override fun getDisplayName(value: TabOption): String { + return "Tab Option" + } + + override fun isSetting(): Boolean { + return true + } + + override fun hasPermission(profile: Profile, value: TabOption): Boolean { + return true + } + + override fun fromBson(document: Document): StatisticValue { + return object : StatisticValue { + + override fun getValue(): TabOption { + return TabOption.getOptionByName(document.getString(this@TabListSetting.getKey())) ?: TabOption.FACTION_LIST + } + + } + } +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/timer/Timer.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/timer/Timer.kt new file mode 100644 index 0000000..37cb2a3 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/timer/Timer.kt @@ -0,0 +1,101 @@ +package cc.fyre.hcf.timer + +import cc.fyre.hcf.HCF +import cc.fyre.hcf.timer.event.TimerExpireEvent +import com.squareup.moshi.JsonClass +import org.bukkit.Bukkit +import org.bukkit.scheduler.BukkitRunnable +import org.bukkit.scheduler.BukkitTask +import java.util.* + +/** + * @project hcf + * + * @date 06/07/2020 + * @author xanderume@gmail.com + */ +@JsonClass(generateAdapter = true) +open class Timer(val type: TimerType, val duration: Long, var owner: UUID?) { + + constructor(type: TimerType,owner: UUID?):this(type,type.duration,owner) + + var paused = 0L + var started = System.currentTimeMillis() + var expires = this.started + this.duration + + @Transient var task: Int? = if (this.owner == null) null else this.createTask(this.duration).taskId + + @JvmName("getDuration1") + fun getDuration(): Long { + return this.duration + } + + fun isPaused():Boolean { + return this.paused != 0L + } + + fun setPaused(value: Boolean) { + + if (value == this.isPaused()) { + return + } + + if (value) { + + if (this.task != null) { + Bukkit.getServer().scheduler.cancelTask(this.task!!) + } + + this.paused = this.getRemaining() + return + } + + this.setRemaining(this.paused) + this.paused = 0L + } + + fun getRemaining():Long { + + if (this.paused != 0L) { + return this.paused + } + + return this.expires - System.currentTimeMillis() + } + + fun setRemaining(duration: Long) { + + if (duration <= 0L) { + return + } + + this.expires = System.currentTimeMillis() + duration + + if (this.owner == null) { + return + } + + if (this.task != null) { + Bukkit.getServer().scheduler.cancelTask(this.task!!) + } + + this.task = this.createTask(duration).taskId + } + + private fun createTask(duration: Long):BukkitTask { + return object : BukkitRunnable() { + + override fun run() { + + if (this@Timer.owner == null) { + return + } + + TimerHandler.removeTimer(this@Timer.owner!!,this@Timer.type) + + HCF.instance.server.pluginManager.callEvent(TimerExpireEvent(this@Timer,this@Timer.owner!!)) + } + + }.runTaskLater(HCF.instance,duration / 50L) + } +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/timer/TimerHandler.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/timer/TimerHandler.kt new file mode 100644 index 0000000..4956e14 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/timer/TimerHandler.kt @@ -0,0 +1,109 @@ +package cc.fyre.hcf.timer + +import cc.fyre.hcf.timer.event.TimerCreateEvent +import cc.fyre.hcf.timer.event.TimerExtendEvent +import cc.fyre.hcf.timer.event.TimerRemoveEvent +import com.google.common.collect.HashBasedTable +import org.bukkit.Bukkit +import java.util.* +import java.util.concurrent.ConcurrentHashMap + +/** + * @project hcf + * + * @date 06/07/2020 + * @author xanderume@gmail.com + */ +object TimerHandler { + + private val timers = HashBasedTable.create() + private val updates = ConcurrentHashMap>() + + fun getAllTimers():MutableMap> { + + val toReturn = mutableMapOf>() + + for (uuid in this.timers.rowKeySet()) { + + val timers = mutableListOf() + + for (entry in this.timers.row(uuid)) { + timers.add(entry.value) + } + + toReturn[uuid] = timers.toList() + } + + return toReturn + } + + fun getTimerByPlayer(uuid: UUID,type: TimerType):Timer? { + return this.timers.get(uuid,type) + } + + fun getTimersByPlayer(uuid: UUID):List { + return this.timers.row(uuid).values.toList() + } + + fun addTimer(uuid: UUID,type: TimerType,force: Boolean = false) { + this.addTimer(uuid,type,type.duration,force) + } + + fun addTimer(uuid: UUID,type: TimerType,duration: Long,force: Boolean = false) { + + var timer = this.timers.get(uuid,type) + + if (timer == null) { + timer = Timer(type,duration,uuid) + + val event = TimerCreateEvent(timer,uuid,duration).call() + + if (force && event.isCancelled) { + return + } + + this.timers.put(uuid,timer.type,timer) + } else { + timer.setRemaining(duration) + Bukkit.getServer().pluginManager.callEvent(TimerExtendEvent(timer,uuid,duration)) + } + + } + + fun removeTimer(uuid: UUID,type: TimerType):Boolean { + + val timer = this.timers.remove(uuid,type) ?: return false + + if (timer.task != null) { + Bukkit.getServer().scheduler.cancelTask(timer.task!!) + } + + Bukkit.getServer().pluginManager.callEvent(TimerRemoveEvent(timer,uuid)) + return true + } + + fun hasTimer(uuid: UUID,type: TimerType):Boolean { + return this.timers.contains(uuid,type) && this.timers[uuid,type]!!.getRemaining() > 0L + } + + fun setPaused(uuid: UUID, type: TimerType, value: Boolean):Boolean { + return this.timers.get(uuid,type)?.setPaused(value) != null + } + + fun getRemaining(uuid: UUID,type: TimerType):Long { + return this.timers.get(uuid,type)?.getRemaining() ?: 0L + } + + fun addUpdate(uuid: UUID,timers: List) { + this.updates[uuid] = timers + } + + fun removeIfQueued(uuid: UUID):List? { + return this.updates.remove(uuid) + } + + fun getUpdates():ConcurrentHashMap> { + return this.updates + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/timer/TimerModule.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/timer/TimerModule.kt new file mode 100644 index 0000000..f0ea3ce --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/timer/TimerModule.kt @@ -0,0 +1,71 @@ +package cc.fyre.hcf.timer + +import cc.fyre.hcf.HCF +import cc.fyre.hcf.HCFModule +import cc.fyre.hcf.timer.command.TimerAddCommand +import cc.fyre.hcf.timer.command.TimerRemoveCommand +import cc.fyre.hcf.timer.command.parameter.TimerParameterProvider +import cc.fyre.hcf.timer.command.pvptimer.PvPEnableCommand +import cc.fyre.hcf.timer.command.pvptimer.PvPTimeCommand +import cc.fyre.hcf.timer.command.type.GoppleCommand +import cc.fyre.hcf.timer.command.type.LogoutCommand +import cc.fyre.hcf.timer.listener.* +import cc.fyre.shard.command.data.parameter.ParameterAdapter +import org.bukkit.event.Listener +import java.util.* + +object TimerModule : HCFModule { + + override fun init(core: HCF) {} + + override fun onSave(core: HCF) { + + val updates = mutableMapOf>() + + for ((key,value) in TimerHandler.getUpdates()) { + updates[key] = value + } + + TimerHandler.getUpdates().clear() + TimerRepository.updateAllById(updates) + } + + override fun shutdown(core: HCF) { + TimerRepository.saveAll() + } + + override fun getCommands(): List> { + return listOf( + GoppleCommand::class.java, + LogoutCommand::class.java, + + PvPTimeCommand::class.java, + PvPEnableCommand::class.java, + + TimerAddCommand::class.java, + TimerRemoveCommand::class.java + ) + } + + override fun getAdapters(): Map, ParameterAdapter<*>> { + return mutableMapOf( + TimerType::class.java to TimerParameterProvider + ) + } + + override fun getListeners(): List { + return listOf( + TimerListener, + HomeListener, + StuckListener, + AppleListener, + LogoutListener, + GappleListener, + PvPTimerListener, + SpawnTagListener, + ArcherMarkListener, + EnderpearlListener, + ) + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/timer/TimerRepository.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/timer/TimerRepository.kt new file mode 100644 index 0000000..bcc58f3 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/timer/TimerRepository.kt @@ -0,0 +1,104 @@ +package cc.fyre.hcf.timer + +import cc.fyre.hcf.HCF +import cc.fyre.shard.moshi.MoshiUtil +import cc.fyre.shard.runRedisCommand +import cc.fyre.shard.runRedisPipelinedCommand +import com.squareup.moshi.Types +import java.lang.IllegalStateException +import java.util.* + +object TimerRepository { + + private val REDIS_KEY = "HCF:Timers" + private val TYPE = Types.newParameterizedType(List::class.java, Timer::class.java) + + fun saveAll() { + HCF.instance.getRedisPool().runRedisPipelinedCommand{ + + TimerHandler.getAllTimers().forEach{(uuid,timers) -> + + val toSave = timers.filter{timer -> timer.type.isPersistable()} + + if (toSave.isEmpty()) { + return@forEach + } + + toSave.filter{timer -> !timer.isPaused()}.forEach{timer -> timer.setPaused(true)} + + val key = "$REDIS_KEY:$uuid" + val highest = toSave.maxByOrNull{timer -> timer.getRemaining()}?.getRemaining() ?: 0L + + it.set(key,MoshiUtil.instance.adapter>(TYPE).toJson(toSave)) + it.expire(key,highest / 1000L) + } + + it.sync() + } + } + + fun findAllById(uuid: UUID,delete: Boolean = false):List { + + val key = "$REDIS_KEY:$uuid" + val adapter = MoshiUtil.instance.adapter>(TYPE) + + return HCF.instance.getRedisPool().runRedisCommand{ + + if (it.exists(key)) { + + val json = it.get(key)!! + + if (delete) { + it.del(key) + } + + adapter.fromJson(json)!!.filter{timer -> timer.setPaused(false) + return@filter true + } + } else { + listOf() + } + + } + + } + + fun updateAllById(uuid: UUID,timers: List) { + + if (timers.isEmpty()) { + throw IllegalStateException("Timers cannot be empty.") + } + + val key = "$REDIS_KEY:$uuid" + val highest = timers.maxByOrNull{it.getRemaining()}?.getRemaining() ?: 0L + + timers.filter{!it.isPaused()}.forEach{it.setPaused(true)} + + HCF.instance.getRedisPool().runRedisCommand{ + it.set(key,MoshiUtil.instance.adapter>(TYPE).toJson(timers)) + it.expire(key,highest / 1000L) + } + + } + + fun updateAllById(map: Map>) { + + HCF.instance.getRedisPool().runRedisPipelinedCommand{ + + for ((uuid,timers) in map) { + + val key = "$REDIS_KEY:$uuid" + val highest = timers.maxByOrNull{timer -> timer.getRemaining()}?.getRemaining() ?: 0L + + timers.filter{timer -> !timer.isPaused()}.forEach{timer -> timer.setPaused(true)} + + it.set(key,MoshiUtil.instance.adapter>(TYPE).toJson(timers)) + it.expire(key,highest / 1000L) + } + + it.sync() + } + + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/timer/TimerType.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/timer/TimerType.kt new file mode 100644 index 0000000..bc13ae2 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/timer/TimerType.kt @@ -0,0 +1,43 @@ +package cc.fyre.hcf.timer + +import org.bukkit.ChatColor +import org.bukkit.Material +import java.util.concurrent.TimeUnit + +/** + * @project hcf + * + * @date 06/07/2020 + * @author xanderume@gmail.com + */ +enum class TimerType(var duration: Long,val scoreboard: String,val displays: Boolean,val icon: Material?) { + + CUSTOM(0L,"",false,null), + + HOME(TimeUnit.SECONDS.toMillis(10L),"${ChatColor.BLUE}${ChatColor.BOLD}Home",Material.WOODEN_DOOR), + STUCK(TimeUnit.SECONDS.toMillis(60L),"${ChatColor.DARK_RED}${ChatColor.BOLD}Stuck",Material.FENCE_GATE), + APPLE(TimeUnit.SECONDS.toMillis(25L),"${ChatColor.GOLD}${ChatColor.BOLD}Apple",Material.GOLDEN_APPLE), + LOGOUT(TimeUnit.SECONDS.toMillis(30L),"${ChatColor.DARK_RED}${ChatColor.BOLD}Logout",Material.IRON_DOOR), + GOD_APPLE(TimeUnit.MINUTES.toMillis(60L),"${ChatColor.GOLD}${ChatColor.BOLD}Gapple",false,null), + SPAWN_TAG(TimeUnit.SECONDS.toMillis(30L),"${ChatColor.RED}${ChatColor.BOLD}Spawn Tag",Material.DIAMOND_SWORD), + PVP_TIMER(TimeUnit.MINUTES.toMillis(30L),"${ChatColor.GREEN}${ChatColor.BOLD}PvP Timer",Material.LEASH), + ENDER_PEARL(TimeUnit.SECONDS.toMillis(16L),"${ChatColor.YELLOW}${ChatColor.BOLD}Enderpearl",Material.ENDER_PEARL), + ARCHER_MARK(TimeUnit.SECONDS.toMillis(10L),"${ChatColor.GOLD}${ChatColor.BOLD}Archer Mark",Material.BOW), + PARTNER_ITEM(TimeUnit.SECONDS.toMillis(10L),"${ChatColor.LIGHT_PURPLE}${ChatColor.BOLD}Partner Item",Material.EMPTY_MAP), + ENERGY_COOLDOWN(TimeUnit.SECONDS.toMillis(10L),"${ChatColor.GREEN}${ChatColor.BOLD}Energy Effect",false,Material.GOLD_HELMET); + + constructor(duration: Long,scoreboard: String,icon: Material?):this(duration,scoreboard,true,icon) + + fun isPersistable():Boolean { + return this == PVP_TIMER || this == GOD_APPLE + } + + companion object { + + fun findByName(name: String): TimerType? { + return values().firstOrNull{it.name.equals(name,true) || it.name.replace("_", "").equals(name,true) || ChatColor.stripColor(it.scoreboard.replace(" ", "")).equals(name,true)} + } + + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/timer/command/TimerAddCommand.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/timer/command/TimerAddCommand.kt new file mode 100644 index 0000000..f5ed052 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/timer/command/TimerAddCommand.kt @@ -0,0 +1,47 @@ +package cc.fyre.hcf.timer.command + +import cc.fyre.core.profile.ProfileHandler +import cc.fyre.shard.command.data.command.Command +import cc.fyre.shard.command.data.parameter.Parameter +import cc.fyre.shard.util.TimeUtil +import cc.fyre.hcf.timer.TimerHandler +import cc.fyre.hcf.timer.TimerType +import cc.fyre.shard.command.data.parameter.impl.PlayerParameterAdapter +import org.bukkit.ChatColor +import org.bukkit.command.CommandSender +import org.bukkit.entity.Player + +/** + * @project hcf + * + * @date 07/07/2020 + * @author xanderume@gmail.com + */ +object TimerAddCommand { + + const val PERMISSION = "hcf.command.timer.add" + + @JvmStatic + @Command(names = ["timer add","timer set"],permission = PERMISSION) + fun execute(sender: CommandSender, + @Parameter(name = "timer")type: TimerType, + @Parameter(name = "duration")duration: Long, + @Parameter(name = "player",defaultValue = PlayerParameterAdapter.SELF_KEY_WORD)target: Player + ) { + + if (sender is Player && sender.uniqueId != target.uniqueId && !sender.hasPermission("${PERMISSION}.other")) { + sender.sendMessage("${ChatColor.RED}You cannot add timers to other players.") + return + } + + TimerHandler.addTimer(target.uniqueId,type,duration) + + if (sender !is Player || sender.uniqueId != target.uniqueId) { + sender.sendMessage("${ChatColor.YELLOW}Added ${type.scoreboard}${ChatColor.YELLOW} to ${ProfileHandler.getDisplayNameById(target.uniqueId)}${ChatColor.YELLOW} for ${ChatColor.RED}${TimeUtil.formatIntoDetailedString(duration)}${ChatColor.YELLOW}.") + return + } + + sender.sendMessage("${ChatColor.YELLOW}You have been put on ${type.scoreboard}${ChatColor.YELLOW} for ${ChatColor.RED}${TimeUtil.formatIntoDetailedString(duration)}${ChatColor.YELLOW}.") + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/timer/command/TimerRemoveCommand.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/timer/command/TimerRemoveCommand.kt new file mode 100644 index 0000000..3daf006 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/timer/command/TimerRemoveCommand.kt @@ -0,0 +1,45 @@ +package cc.fyre.hcf.timer.command + +import cc.fyre.core.profile.ProfileHandler +import cc.fyre.shard.command.data.command.Command +import cc.fyre.shard.command.data.parameter.Parameter +import cc.fyre.hcf.timer.TimerHandler +import cc.fyre.hcf.timer.TimerType +import cc.fyre.shard.command.data.parameter.impl.PlayerParameterAdapter +import org.bukkit.ChatColor +import org.bukkit.command.CommandSender +import org.bukkit.entity.Player + +/** + * @project hcf + * + * @date 19/07/2020 + * @author xanderume@gmail.com + */ +object TimerRemoveCommand { + + const val PERMISSION = "hcf.command.timer" + + @JvmStatic + @Command(names = ["timer remove"],permission = PERMISSION) + fun execute(sender: CommandSender, + @Parameter(name = "timer")type: TimerType, + @Parameter(name = "player",defaultValue = PlayerParameterAdapter.SELF_KEY_WORD) target: Player + ) { + + if (sender is Player && sender.uniqueId != target.uniqueId && !sender.hasPermission("${PERMISSION}.other")) { + sender.sendMessage("${ChatColor.RED}You cannot remove timers from other players.") + return + } + + TimerHandler.removeTimer(target.uniqueId,type) + + if (sender !is Player || sender.uniqueId != target.uniqueId) { + sender.sendMessage("${ChatColor.YELLOW}Removed ${type.scoreboard}${ChatColor.YELLOW} for ${ProfileHandler.getDisplayNameById(target.uniqueId)}${ChatColor.YELLOW}.") + return + } + + sender.sendMessage("${ChatColor.YELLOW}Removed your ${type.scoreboard}${ChatColor.YELLOW} timer.") + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/timer/command/parameter/TimerParameterProvider.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/timer/command/parameter/TimerParameterProvider.kt new file mode 100644 index 0000000..da079e2 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/timer/command/parameter/TimerParameterProvider.kt @@ -0,0 +1,34 @@ +package cc.fyre.hcf.timer.command.parameter + +import cc.fyre.shard.command.data.parameter.ParameterAdapter +import cc.fyre.hcf.timer.TimerType +import net.minecraft.util.org.apache.commons.lang3.StringUtils +import org.bukkit.ChatColor +import org.bukkit.command.CommandSender +import org.bukkit.entity.Player + +/** + * @project hcf + * + * @date 07/07/2020 + * @author xanderume@gmail.com + */ +object TimerParameterProvider : ParameterAdapter { + + override fun transform(sender: CommandSender,source: String): TimerType? { + + val timer = TimerType.findByName(source) + + if (timer == null) { + sender.sendMessage("${ChatColor.RED}Timer ${ChatColor.YELLOW}${source}${ChatColor.RED} not found.") + return null + } + + return timer + } + + override fun tabComplete(player: Player, flags: Set, source: String): List { + return TimerType.values().filter{StringUtils.startsWithIgnoreCase(it.name,source)}.map{it.name}.toList() + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/timer/command/pvptimer/PvPEnableCommand.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/timer/command/pvptimer/PvPEnableCommand.kt new file mode 100644 index 0000000..a73e6d0 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/timer/command/pvptimer/PvPEnableCommand.kt @@ -0,0 +1,44 @@ +package cc.fyre.hcf.timer.command.pvptimer + +import cc.fyre.core.profile.ProfileHandler +import cc.fyre.shard.command.data.command.Command +import cc.fyre.shard.command.data.parameter.Parameter +import cc.fyre.hcf.timer.TimerHandler +import cc.fyre.hcf.timer.TimerType +import cc.fyre.modsuite.mod.command.ModCommand +import cc.fyre.shard.command.data.parameter.impl.PlayerParameterAdapter +import org.bukkit.ChatColor +import org.bukkit.command.CommandSender +import org.bukkit.entity.Player + +/** + * @project hcf + * + * @date 31/08/2020 + * @author xanderume@gmail.com + */ +object PvPEnableCommand { + + @JvmStatic + @Command(names = ["pvptimer enable","pvp enable","pvptimer remove","pvp remove"]) + fun execute(sender: CommandSender, + @Parameter(name = "player",defaultValue = PlayerParameterAdapter.SELF_KEY_WORD)player: Player + ) { + + var target = player + + if (sender is Player && !target.hasPermission(ModCommand.PERMISSION)) { + target = sender + } + + val self = sender is Player && sender.uniqueId == target.uniqueId + + if (!TimerHandler.removeTimer(player.uniqueId,TimerType.PVP_TIMER)) { + sender.sendMessage("${ChatColor.RED}${if (self) "You do not" else "${ProfileHandler.getDisplayNameById(target.uniqueId)}${ChatColor.RED} does not"} have a active PvP Timer!") + return + } + + sender.sendMessage("${if (self) "${ChatColor.RED}Your" else "${ProfileHandler.getDisplayNameById(target.uniqueId)}${ChatColor.RED}'s"} PvP Timer has been removed!") + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/timer/command/pvptimer/PvPTimeCommand.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/timer/command/pvptimer/PvPTimeCommand.kt new file mode 100644 index 0000000..f58a8de --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/timer/command/pvptimer/PvPTimeCommand.kt @@ -0,0 +1,47 @@ +package cc.fyre.hcf.timer.command.pvptimer + +import cc.fyre.core.profile.ProfileHandler +import cc.fyre.shard.command.data.command.Command +import cc.fyre.shard.command.data.parameter.Parameter +import cc.fyre.shard.util.TimeUtil +import cc.fyre.hcf.timer.TimerHandler +import cc.fyre.hcf.timer.TimerType +import cc.fyre.modsuite.mod.command.ModCommand +import cc.fyre.shard.command.data.parameter.impl.PlayerParameterAdapter +import org.bukkit.ChatColor +import org.bukkit.command.CommandSender +import org.bukkit.entity.Player + +/** + * @project hcf + * + * @date 31/08/2020 + * @author xanderume@gmail.com + */ +object PvPTimeCommand { + + @JvmStatic + @Command(names = ["pvptimer time","pvp time"]) + fun execute(sender: CommandSender, + @Parameter(name = "player",defaultValue = PlayerParameterAdapter.SELF_KEY_WORD)player: Player + ) { + + var target = player + + if (sender is Player && !target.hasPermission(ModCommand.PERMISSION)) { + target = sender + } + + val self = sender is Player && sender.uniqueId == player.uniqueId + + val remaining = TimerHandler.getRemaining(target.uniqueId, TimerType.PVP_TIMER) + + if (remaining <= 0) { + sender.sendMessage("${if (self) "You do not" else "${ProfileHandler.getDisplayNameById(target.uniqueId)}${ChatColor.RED} does not"} have a active PvP Timer!") + return + } + + sender.sendMessage("${if (self) "${ChatColor.RED}You have" else "${ProfileHandler.getDisplayNameById(target.uniqueId)}${ChatColor.RED} has"} ${TimeUtil.formatIntoFancy(remaining)}${ChatColor.RED} left on ${if (self) "your" else "their"} PvP Timer!") + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/timer/command/type/GoppleCommand.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/timer/command/type/GoppleCommand.kt new file mode 100644 index 0000000..8b67fa4 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/timer/command/type/GoppleCommand.kt @@ -0,0 +1,33 @@ +package cc.fyre.hcf.timer.command.type + +import cc.fyre.shard.command.data.command.Command +import cc.fyre.shard.util.TimeUtil + +import cc.fyre.hcf.timer.TimerHandler +import cc.fyre.hcf.timer.TimerType +import org.bukkit.ChatColor +import org.bukkit.entity.Player + +/** + * @project hcf + * + * @date 14/09/2020 + * @author xanderume@gmail.com + */ +object GoppleCommand { + + @JvmStatic + @Command(names = ["gopple","gapple"]) + fun execute(player: Player) { + + val cooldown = TimerHandler.getRemaining(player.uniqueId, TimerType.GOD_APPLE) + + if (cooldown > 0) { + player.sendMessage("${ChatColor.GOLD}Gopple Cooldown: ${ChatColor.WHITE}${TimeUtil.formatIntoDetailedString(cooldown)}") + return + } + + player.sendMessage("${ChatColor.RED}You are not on gapple cooldown!") + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/timer/command/type/LogoutCommand.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/timer/command/type/LogoutCommand.kt new file mode 100644 index 0000000..3d44d71 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/timer/command/type/LogoutCommand.kt @@ -0,0 +1,39 @@ +package cc.fyre.hcf.timer.command.type + +import org.bukkit.entity.Player +import cc.fyre.shard.command.data.command.Command +import cc.fyre.shard.util.TimeUtil +import cc.fyre.hcf.timer.TimerHandler +import cc.fyre.hcf.timer.TimerType +import cc.fyre.modsuite.freeze.FreezeHandler +import org.bukkit.ChatColor + +/** + * @project hcf + * + * @date 14/09/2020 + * @author xanderume@gmail.com + */ +object LogoutCommand { + + @JvmStatic + @Command(names = ["logout"]) + fun execute(player: Player) { + + if (FreezeHandler.isFrozen(player)) { + player.sendMessage("${ChatColor.RED}You cannot logout while your frozen!") + return + } + + if (TimerHandler.hasTimer(player.uniqueId, TimerType.LOGOUT)) { + player.sendMessage("${ChatColor.RED}You are already being logged out!") + return + } + + player.sendMessage("${ChatColor.YELLOW}You are being logged out in ${ChatColor.RED}${TimeUtil.formatIntoDetailedString( + TimerType.LOGOUT.duration)}${ChatColor.YELLOW}.") + + TimerHandler.addTimer(player.uniqueId, TimerType.LOGOUT) + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/timer/event/TimerCreateEvent.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/timer/event/TimerCreateEvent.kt new file mode 100644 index 0000000..4263809 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/timer/event/TimerCreateEvent.kt @@ -0,0 +1,44 @@ +package cc.fyre.hcf.timer.event + +import cc.fyre.hcf.timer.Timer +import org.bukkit.Bukkit +import org.bukkit.entity.Player +import org.bukkit.event.Cancellable +import org.bukkit.event.Event +import org.bukkit.event.HandlerList +import java.util.* + +/** + * @project hcf + * + * @date 06/07/2020 + * @author xanderume@gmail.com + */ +class TimerCreateEvent(val timer: Timer,val uuid: UUID,val duration: Long) : Event(),Cancellable { + + private var cancelled = false + + override fun getHandlers(): HandlerList { + return handlerList + } + + override fun isCancelled(): Boolean { + return this.cancelled + } + + override fun setCancelled(cancelled: Boolean) { + this.cancelled = cancelled + } + + fun call():TimerCreateEvent { + Bukkit.getPluginManager().callEvent(this) + return this + } + + companion object { + + @JvmStatic val handlerList = HandlerList() + + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/timer/event/TimerExpireEvent.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/timer/event/TimerExpireEvent.kt new file mode 100644 index 0000000..fb385e5 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/timer/event/TimerExpireEvent.kt @@ -0,0 +1,27 @@ +package cc.fyre.hcf.timer.event + +import cc.fyre.hcf.timer.Timer +import org.bukkit.entity.Player +import org.bukkit.event.Event +import org.bukkit.event.HandlerList +import java.util.* + +/** + * @project hcf + * + * @date 06/07/2020 + * @author xanderume@gmail.com + */ +class TimerExpireEvent(val timer: Timer,val uuid: UUID) : Event() { + + override fun getHandlers(): HandlerList { + return handlerList + } + + companion object { + + @JvmStatic val handlerList = HandlerList() + + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/timer/event/TimerExtendEvent.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/timer/event/TimerExtendEvent.kt new file mode 100644 index 0000000..c3e056d --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/timer/event/TimerExtendEvent.kt @@ -0,0 +1,26 @@ +package cc.fyre.hcf.timer.event + +import cc.fyre.hcf.timer.Timer +import org.bukkit.event.Event +import org.bukkit.event.HandlerList +import java.util.* + +/** + * @project hcf + * + * @date 01/11/2020 + * @author xanderume@gmail.com + */ +class TimerExtendEvent(val timer: Timer,val uuid: UUID,val newDuration: Long) : Event() { + + override fun getHandlers(): HandlerList { + return handlerList + } + + companion object { + + @JvmStatic val handlerList = HandlerList() + + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/timer/event/TimerRemoveEvent.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/timer/event/TimerRemoveEvent.kt new file mode 100644 index 0000000..50de1e2 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/timer/event/TimerRemoveEvent.kt @@ -0,0 +1,26 @@ +package cc.fyre.hcf.timer.event + +import cc.fyre.hcf.timer.Timer +import org.bukkit.event.Event +import org.bukkit.event.HandlerList +import java.util.* + +/** + * @project hcf + * + * @date 19/07/2020 + * @author xanderume@gmail.com + */ +class TimerRemoveEvent(val timer: Timer,val uuid: UUID) : Event() { + + override fun getHandlers(): HandlerList { + return handlerList + } + + companion object { + + @JvmStatic val handlerList = HandlerList() + + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/timer/listener/AppleListener.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/timer/listener/AppleListener.kt new file mode 100644 index 0000000..4b51720 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/timer/listener/AppleListener.kt @@ -0,0 +1,44 @@ +package cc.fyre.hcf.timer.listener + +import cc.fyre.shard.util.TimeUtil +import cc.fyre.hcf.timer.TimerHandler +import cc.fyre.hcf.timer.TimerType +import org.bukkit.ChatColor +import org.bukkit.Material +import org.bukkit.event.EventHandler +import org.bukkit.event.EventPriority +import org.bukkit.event.Listener +import org.bukkit.event.player.PlayerItemConsumeEvent + +/** + * @project hcf + * + * @date 30/08/2020 + * @author xanderume@gmail.com + */ +object AppleListener : Listener { + + @EventHandler(priority = EventPriority.LOWEST) + private fun onItemConsume(event: PlayerItemConsumeEvent) { + + if (event.item == null || event.item.type != Material.GOLDEN_APPLE) { + return + } + + if (event.item.durability != 0.toShort()) { + return + } + + val cooldown = TimerHandler.getRemaining(event.player.uniqueId,TimerType.APPLE) + + if (cooldown > 0) { + event.isCancelled = true + event.player.sendMessage("${ChatColor.RED}You cannot use this for another ${ChatColor.BOLD}${TimeUtil.formatIntoFancy(cooldown)}${ChatColor.RED}.") + return + } + + TimerHandler.addTimer(event.player.uniqueId, TimerType.APPLE) + } + + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/timer/listener/ArcherMarkListener.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/timer/listener/ArcherMarkListener.kt new file mode 100644 index 0000000..6e1e014 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/timer/listener/ArcherMarkListener.kt @@ -0,0 +1,53 @@ +package cc.fyre.hcf.timer.listener + +import cc.fyre.hcf.timer.TimerHandler +import cc.fyre.hcf.timer.TimerType + +import org.bukkit.entity.Player +import org.bukkit.entity.Projectile +import org.bukkit.event.EventHandler +import org.bukkit.event.EventPriority +import org.bukkit.event.Listener +import org.bukkit.event.entity.EntityDamageByEntityEvent + +/** + * @project hcf + * + * @date 11/09/2020 + * @author xanderume@gmail.com + */ +object ArcherMarkListener : Listener { + + const val INCREASE_DAMAGE = 25 + + @EventHandler(priority = EventPriority.NORMAL) + private fun onEntityDamageByEntity(event: EntityDamageByEntityEvent) { + + if (event.isCancelled) { + return + } + + if (event.entity !is Player) { + return + } + + var damager: Player? = null + + if (event.damager is Player) { + damager = event.damager as Player + } else if (event.damager is Projectile && (event.damager as Projectile).shooter is Player) { + damager = (event.damager as Projectile).shooter as Player + } + + if (damager == null) { + return + } + + if (!TimerHandler.hasTimer(event.entity.uniqueId,TimerType.ARCHER_MARK)) { + return + } + + event.damage = event.damage + ((event.damage / 100) * INCREASE_DAMAGE) + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/timer/listener/EnderpearlListener.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/timer/listener/EnderpearlListener.kt new file mode 100644 index 0000000..1290c50 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/timer/listener/EnderpearlListener.kt @@ -0,0 +1,91 @@ +package cc.fyre.hcf.timer.listener + +import cc.fyre.shard.util.TimeUtil +import cc.fyre.hcf.timer.TimerHandler +import cc.fyre.hcf.timer.TimerType +import org.bukkit.ChatColor +import org.bukkit.Material +import org.bukkit.entity.EnderPearl +import org.bukkit.entity.Player +import org.bukkit.event.EventHandler +import org.bukkit.event.EventPriority +import org.bukkit.event.Listener +import org.bukkit.event.entity.PlayerDeathEvent +import org.bukkit.event.entity.ProjectileLaunchEvent +import org.bukkit.event.player.PlayerPearlRefundEvent +import org.bukkit.inventory.ItemStack +import java.util.* +import kotlin.collections.HashMap + +/** + * @project hcf + * + * @date 20/07/2020 + * @author xanderume@gmail.com + */ +object EnderpearlListener : Listener { + + //TODO EnderPearlHandler cache their enderpearls to imrpove pearls and performance + val cache = mutableMapOf() + + @EventHandler(priority = EventPriority.MONITOR,ignoreCancelled = true) + private fun onProjectileLaunched(event: ProjectileLaunchEvent) { + + if (event.entity !is EnderPearl || event.entity.shooter !is Player) { + return + } + + if (event.isCancelled) { + return + } + + val shooter = event.entity.shooter + + if (shooter !is Player) { + return + } + + this.cache[shooter.uniqueId] = event.entity as EnderPearl + + TimerHandler.addTimer(shooter.uniqueId,TimerType.ENDER_PEARL) + } + + @EventHandler(priority = EventPriority.MONITOR) + private fun onPlayerDeath(event: PlayerDeathEvent) { + this.cache.remove(event.entity.uniqueId)?.remove() + } + + @EventHandler(priority = EventPriority.HIGH,ignoreCancelled = true) + private fun onProjectileLaunch(event: ProjectileLaunchEvent) { + + val entity = event.entity + + if (entity !is EnderPearl) { + return + } + + val shooter = event.entity.shooter + + if (shooter !is Player) { + return + } + + val cooldown = TimerHandler.getRemaining((event.entity.shooter as Player).uniqueId, TimerType.ENDER_PEARL) + + if (cooldown <= 0) { + return + } + + event.isCancelled = true + + shooter.sendMessage("${ChatColor.RED}You cannot use this for another ${ChatColor.BOLD}${TimeUtil.formatIntoFancy(cooldown)}${ChatColor.RED}.") + shooter.updateInventory() + } + + @EventHandler(priority = EventPriority.MONITOR) + private fun onPearlRefund(event: PlayerPearlRefundEvent) { + event.player.inventory.addItem(ItemStack(Material.ENDER_PEARL)) + TimerHandler.removeTimer(event.player.uniqueId,TimerType.ENDER_PEARL) + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/timer/listener/GappleListener.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/timer/listener/GappleListener.kt new file mode 100644 index 0000000..18c86eb --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/timer/listener/GappleListener.kt @@ -0,0 +1,58 @@ +package cc.fyre.hcf.timer.listener + +import cc.fyre.shard.util.TimeUtil +import cc.fyre.hcf.HCF +import cc.fyre.hcf.timer.TimerHandler +import cc.fyre.hcf.timer.TimerType +import org.bukkit.ChatColor +import org.bukkit.Material +import org.bukkit.event.EventHandler +import org.bukkit.event.EventPriority +import org.bukkit.event.Listener +import org.bukkit.event.player.PlayerItemConsumeEvent +import java.util.concurrent.TimeUnit + +/** + * @project hcf + * + * @date 30/08/2020 + * @author xanderume@gmail.com + */ +object GappleListener : Listener { + + @EventHandler(priority = EventPriority.LOWEST) + private fun onItemConsume(event: PlayerItemConsumeEvent) { + + if (event.item == null || event.item.type != Material.GOLDEN_APPLE) { + return + } + + if (event.item.durability != 1.toShort()) { + return + } + + val cooldown = TimerHandler.getRemaining(event.player.uniqueId,TimerType.GOD_APPLE) + + if (cooldown > 0) { + event.isCancelled = true + event.player.sendMessage("${ChatColor.RED}You cannot use this for another ${ChatColor.BOLD}${TimeUtil.formatIntoDetailedString(cooldown)}${ChatColor.RED}.") + return + } + + TimerHandler.addTimer(event.player.uniqueId,TimerType.GOD_APPLE,if (HCF.instance.isKitMap()) { + TimeUnit.MINUTES.toMillis(5L) + } else { + TimerType.GOD_APPLE.duration + }) + + event.player.sendMessage("${ChatColor.DARK_GREEN}███${ChatColor.YELLOW}██${ChatColor.DARK_GREEN}███") + event.player.sendMessage("${ChatColor.DARK_GREEN}███${ChatColor.YELLOW}█${ChatColor.DARK_GREEN}████") + event.player.sendMessage("${ChatColor.DARK_GREEN}██${ChatColor.GOLD}████${ChatColor.DARK_GREEN}██ ${ChatColor.GOLD}Golden Apple:") + event.player.sendMessage("${ChatColor.DARK_GREEN}█${ChatColor.GOLD}██${ChatColor.WHITE}█${ChatColor.GOLD}███${ChatColor.DARK_GREEN}█${ChatColor.DARK_GREEN} Consumed") + event.player.sendMessage("${ChatColor.DARK_GREEN}█${ChatColor.GOLD}█${ChatColor.WHITE}█${ChatColor.GOLD}████${ChatColor.DARK_GREEN}█${ChatColor.YELLOW} Cooldown:") + event.player.sendMessage("${ChatColor.DARK_GREEN}█${ChatColor.GOLD}██████${ChatColor.DARK_GREEN}█${ChatColor.BLUE} ${TimeUtil.formatIntoDetailedString(if (HCF.instance.isKitMap()) TimeUnit.MINUTES.toMillis(5L) else TimerType.GOD_APPLE.duration)}") + event.player.sendMessage("${ChatColor.DARK_GREEN}█${ChatColor.GOLD}██████${ChatColor.DARK_GREEN}█") + event.player.sendMessage("${ChatColor.DARK_GREEN}██${ChatColor.GOLD}████${ChatColor.DARK_GREEN}██") + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/timer/listener/HomeListener.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/timer/listener/HomeListener.kt new file mode 100644 index 0000000..dca4f45 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/timer/listener/HomeListener.kt @@ -0,0 +1,140 @@ +package cc.fyre.hcf.timer.listener + +import cc.fyre.shard.util.TimeUtil +import cc.fyre.hcf.HCF +import cc.fyre.hcf.faction.FactionHandler +import cc.fyre.hcf.timer.TimerHandler +import cc.fyre.hcf.timer.TimerType +import cc.fyre.hcf.timer.event.TimerCreateEvent +import cc.fyre.hcf.timer.event.TimerExpireEvent +import cc.fyre.Forge +import cc.fyre.handler.MovementHandler +import net.minecraft.server.v1_7_R4.PacketPlayInFlying +import org.bukkit.Bukkit +import org.bukkit.ChatColor +import org.bukkit.Location +import org.bukkit.entity.Player +import org.bukkit.event.EventHandler +import org.bukkit.event.EventPriority +import org.bukkit.event.Listener +import org.bukkit.event.entity.EntityDamageEvent +import org.bukkit.event.player.PlayerQuitEvent +import org.bukkit.event.player.PlayerTeleportEvent + +/** + * @project hcf + * + * @date 06/07/2020 + * @author xanderume@gmail.com + */ +object HomeListener : Listener, MovementHandler { + + init { + Forge.INSTANCE.addMovementHandler(this) + } + + @EventHandler(priority = EventPriority.MONITOR) + private fun onTimerCreate(event: TimerCreateEvent) { + + if (event.timer.type != TimerType.HOME) { + return + } + + val player = Bukkit.getServer().getPlayer(event.uuid) ?: return + + if (TimerHandler.hasTimer(player.uniqueId,TimerType.PVP_TIMER)) { + player.sendMessage("${ChatColor.RED}${ChatColor.BOLD}Your PvP Timer will be removed once teleported!") + } + + player.sendMessage("${ChatColor.YELLOW}Teleporting to your faction's HQ in ${ChatColor.LIGHT_PURPLE}${TimeUtil.formatIntoDetailedString(event.timer.getDuration())}${ChatColor.YELLOW}... Stay still and do not take damage.") + } + + @EventHandler(priority = EventPriority.MONITOR) + private fun onTimerExpire(event: TimerExpireEvent) { + + if (event.timer.type != TimerType.HOME) { + return + } + + val player = Bukkit.getServer().getPlayer(event.uuid) ?: return + val faction = FactionHandler.getFactionByPlayer(player.uniqueId) + + if (faction == null) { + player.sendMessage("${ChatColor.RED}You are not in a faction!") + return + } + + if (faction.getHQ() == null) { + player.sendMessage("${ChatColor.RED}HQ not set.") + return + } + + TimerHandler.removeTimer(player.uniqueId, TimerType.PVP_TIMER) + + EnderpearlListener.cache.remove(player.uniqueId)?.remove() + + Bukkit.getServer().scheduler.runTask(HCF.instance) { + + if (!faction.getHQ()!!.chunk.isLoaded) { + faction.getHQ()!!.chunk.load() + } + + player.teleport(faction.getHQ()) + } + + player.sendMessage("${ChatColor.YELLOW}Warping to ${ChatColor.LIGHT_PURPLE}${faction.name}${ChatColor.YELLOW}${ChatColor.YELLOW}'s HQ.") + } + + @EventHandler(priority = EventPriority.MONITOR) + private fun onPlayerQuit(event: PlayerQuitEvent) { + TimerHandler.removeTimer(event.player.uniqueId, TimerType.HOME) + } + + @EventHandler(priority = EventPriority.MONITOR) + private fun onEntityDamage(event: EntityDamageEvent) { + + if (event.isCancelled) { + return + } + + if (event.damage <= 0) { + return + } + + if (event.entity !is Player) { + return + } + + if (!TimerHandler.removeTimer(event.entity.uniqueId, TimerType.HOME)) { + return + } + + (event.entity as Player).sendMessage("${ChatColor.RED}Teleport cancelled.") + } + + @EventHandler(priority = EventPriority.MONITOR) + private fun onPlayerTeleport(event: PlayerTeleportEvent) { + + if (event.isCancelled) { + return + } + + this.handleUpdateLocation(event.player,event.to,event.from,null) + } + + override fun handleUpdateRotation(player: Player, to: Location, from: Location, packet: PacketPlayInFlying?) {} + + override fun handleUpdateLocation(player: Player, to: Location, from: Location, packet: PacketPlayInFlying?) { + + if (from.blockX == to.blockX && from.blockZ == to.blockZ) { + return + } + + if (!TimerHandler.removeTimer(player.uniqueId, TimerType.HOME)) { + return + } + + player.sendMessage("${ChatColor.RED}Teleport cancelled.") + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/timer/listener/LogoutListener.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/timer/listener/LogoutListener.kt new file mode 100644 index 0000000..d94bd15 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/timer/listener/LogoutListener.kt @@ -0,0 +1,105 @@ +package cc.fyre.hcf.timer.listener + +import cc.fyre.Forge +import cc.fyre.core.server.ServerModule +import cc.fyre.core.server.message.ServerMessageType +import cc.fyre.hcf.HCF +import cc.fyre.hcf.combatlogger.CombatLoggerHandler +import cc.fyre.hcf.timer.TimerHandler +import cc.fyre.hcf.timer.TimerType +import cc.fyre.hcf.timer.event.TimerExpireEvent +import cc.fyre.shard.util.bungee.BungeeUtil +import com.google.common.io.ByteStreams +import cc.fyre.handler.MovementHandler +import net.minecraft.server.v1_7_R4.PacketPlayInFlying +import org.bukkit.ChatColor +import org.bukkit.Location +import org.bukkit.entity.Player +import org.bukkit.event.EventHandler +import org.bukkit.event.EventPriority +import org.bukkit.event.Listener +import org.bukkit.event.entity.EntityDamageEvent +import org.bukkit.event.player.PlayerQuitEvent +import org.bukkit.event.player.PlayerTeleportEvent + +/** + * @project hcf + * + * @date 17/09/2020 + * @author xanderume@gmail.com + */ +object LogoutListener : Listener, MovementHandler { + + init { + Forge.INSTANCE.addMovementHandler(this) + } + + @EventHandler(priority = EventPriority.MONITOR) + private fun onTimerExpire(event: TimerExpireEvent) { + + val player = HCF.instance.server.getPlayer(event.uuid) ?: return + + if (event.timer.type != TimerType.LOGOUT) { + return + } + + CombatLoggerHandler.addSafetyProtection(event.uuid) + + ServerModule.sendToBungee(player,ServerMessageType.SEND_TO_HUB) { + it.writeUTF("${ChatColor.YELLOW}You have been safely logged out!") + return@sendToBungee true + } + + } + + @EventHandler(priority = EventPriority.MONITOR) + private fun onPlayerQuit(event: PlayerQuitEvent) { + TimerHandler.removeTimer(event.player.uniqueId, TimerType.LOGOUT) + } + + @EventHandler(priority = EventPriority.MONITOR) + private fun onEntityDamage(event: EntityDamageEvent) { + + if (event.isCancelled) { + return + } + + if (event.entity !is Player) { + return + } + + val player = event.entity as Player + + if (!TimerHandler.removeTimer(player.uniqueId,TimerType.LOGOUT)) { + return + } + + player.sendMessage("${ChatColor.RED}Logout cancelled.") + } + + @EventHandler(priority = EventPriority.MONITOR) + private fun onPlayerTeleport(event: PlayerTeleportEvent) { + + if (event.isCancelled) { + return + } + + this.handleUpdateLocation(event.player,event.to,event.from,null) + } + + override fun handleUpdateRotation(player: Player, to: Location, from: Location, packet: PacketPlayInFlying?) {} + + override fun handleUpdateLocation(player: Player, to: Location, from: Location, packet: PacketPlayInFlying?) { + + if (from.blockX == to.blockX && from.blockZ == to.blockZ) { + return + } + + if (!TimerHandler.removeTimer(player.uniqueId, TimerType.LOGOUT)) { + return + } + + player.sendMessage("${ChatColor.RED}Logout cancelled.") + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/timer/listener/PvPTimerListener.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/timer/listener/PvPTimerListener.kt new file mode 100644 index 0000000..d33ada9 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/timer/listener/PvPTimerListener.kt @@ -0,0 +1,244 @@ +package cc.fyre.hcf.timer.listener + +import cc.fyre.shard.util.ChanceUtil +import cc.fyre.hcf.HCF +import cc.fyre.hcf.faction.FactionMetadata +import cc.fyre.hcf.faction.type.PlayerFaction +import cc.fyre.hcf.faction.type.SystemFaction +import cc.fyre.hcf.faction.event.FactionMoveEvent +import cc.fyre.hcf.map.eotw.EOTWHandler +import cc.fyre.hcf.timer.TimerHandler +import cc.fyre.hcf.timer.TimerType +import org.bukkit.ChatColor +import org.bukkit.World +import org.bukkit.entity.EnderPearl +import org.bukkit.entity.Player +import org.bukkit.entity.Projectile +import org.bukkit.event.EventHandler +import org.bukkit.event.EventPriority +import org.bukkit.event.Listener +import org.bukkit.event.entity.EntityDamageByEntityEvent +import org.bukkit.event.entity.EntityDamageEvent +import org.bukkit.event.entity.FoodLevelChangeEvent +import org.bukkit.event.entity.PotionSplashEvent +import org.bukkit.event.player.* + +/** + * @project hcf + * + * @date 23/07/2020 + * @author xanderume@gmail.com + */ +object PvPTimerListener : Listener { + + @EventHandler(priority = EventPriority.HIGH,ignoreCancelled = true) + private fun onEntityDamageByEntity(event: EntityDamageByEntityEvent) { + + if (event.entity !is Player) { + return + } + + var damager: Player? = null + + if (event.damager is Player) { + damager = event.damager as Player + } else if (event.damager is Projectile && (event.damager as Projectile).shooter is Player) { + damager = (event.damager as Projectile).shooter as Player + } + + if (damager == null || event.damager is EnderPearl) { + return + } + + if (TimerHandler.hasTimer(event.damager.uniqueId, TimerType.PVP_TIMER)) { + damager.sendMessage("${ChatColor.RED}You cannot do this while your PvP Timer is active!") + damager.sendMessage("${ChatColor.RED}Type '${ChatColor.YELLOW}/pvp enable${ChatColor.RED}' to remove your timer.") + event.isCancelled = true + return + } + + if (!TimerHandler.hasTimer(event.entity.uniqueId, TimerType.PVP_TIMER)) { + return + } + + event.isCancelled = true + + if (damager.uniqueId == event.entity.uniqueId) { + return + } + + damager.sendMessage("${ChatColor.RED}That player currently has their PvP Timer!") + } + + @EventHandler(priority = EventPriority.NORMAL) + private fun onEntityDamage(event: EntityDamageEvent) { + + if (event.entity !is Player) { + return + } + + if (event.cause != EntityDamageEvent.DamageCause.LAVA || event.cause != EntityDamageEvent.DamageCause.FIRE || event.cause != EntityDamageEvent.DamageCause.FIRE_TICK) { + return + } + + if (!TimerHandler.hasTimer(event.entity.uniqueId, TimerType.PVP_TIMER)) { + return + } + + event.isCancelled = true + } + + @EventHandler(priority = EventPriority.NORMAL) + private fun onPlayerJoin(event: PlayerJoinEvent) { + + if (EOTWHandler.isActive()) { + TimerHandler.removeTimer(event.player.uniqueId, TimerType.PVP_TIMER) + return + } + + if (!event.player.hasPlayedBefore() && !HCF.instance.isKitMap()) { + TimerHandler.addTimer(event.player.uniqueId, TimerType.PVP_TIMER) + } + + if (FactionMetadata.SAFE_ZONE.isValidAtLocation(event.player.location)) { + return + } + + TimerHandler.setPaused(event.player.uniqueId, TimerType.PVP_TIMER,false) + } + + @EventHandler(priority = EventPriority.NORMAL) + private fun onPlayerQuit(event: PlayerQuitEvent) { + TimerHandler.setPaused(event.player.uniqueId, TimerType.PVP_TIMER,true) + } + + @EventHandler(priority = EventPriority.NORMAL) + private fun onFactionMove(event: FactionMoveEvent) { + + if (!TimerHandler.hasTimer(event.player.uniqueId, TimerType.PVP_TIMER)) { + return + } + + if (event.to is PlayerFaction) { + + if (event.to.isMember(event.player)) { + return + } + + event.isCancelled = true + event.player.sendMessage("${ChatColor.RED}You cannot enter another faction's territory with PvP Protection.") + event.player.sendMessage("${ChatColor.RED}Use ${ChatColor.YELLOW}/pvp enable${ChatColor.RED} to remove your protection.") + return + } + + val toSystem = event.to is SystemFaction + + if (event.to is SystemFaction && event.to.isEvent() && event.isCancelled) { + event.player.sendMessage("${ChatColor.RED}Your PvP Timer has been removed for entering an event.") + TimerHandler.removeTimer(event.player.uniqueId,TimerType.PVP_TIMER) + return + } + + val toSafeZone = event.to is SystemFaction && event.to.hasMetadata(FactionMetadata.SAFE_ZONE) + + if ((!toSystem || !toSafeZone) && (event.from is SystemFaction && event.from.hasMetadata(FactionMetadata.SAFE_ZONE))) { + TimerHandler.setPaused(event.player.uniqueId,TimerType.PVP_TIMER,false) + return + } + + if (!(event.to is SystemFaction && event.to.hasMetadata(FactionMetadata.SAFE_ZONE))) { + return + } + + TimerHandler.setPaused(event.player.uniqueId, TimerType.PVP_TIMER,true) + } + + @EventHandler(priority = EventPriority.NORMAL) + private fun onPlayerTeleport(event: PlayerTeleportEvent) { + + if (!TimerHandler.hasTimer(event.player.uniqueId,TimerType.PVP_TIMER)) { + return + } + + if (!FactionMetadata.SAFE_ZONE.isValidAtLocation(event.to)) { + + if (FactionMetadata.SAFE_ZONE.isValidAtLocation(event.from)) { + TimerHandler.setPaused(event.player.uniqueId,TimerType.PVP_TIMER,false) + } + + return + } + + TimerHandler.setPaused(event.player.uniqueId,TimerType.PVP_TIMER,true) + } + + @EventHandler(priority = EventPriority.MONITOR) + private fun onPlayerRespawn(event: PlayerRespawnEvent) { + + if (HCF.instance.isKitMap()) { + return + } + + event.respawnLocation = HCF.instance.server.getWorld("world").spawnLocation.add(0.5,0.0,0.5) + + TimerHandler.addTimer(event.player.uniqueId,TimerType.PVP_TIMER) + TimerHandler.setPaused(event.player.uniqueId,TimerType.PVP_TIMER,true) + } + + @EventHandler(priority = EventPriority.LOWEST) + private fun onFoodLevelChange(event: FoodLevelChangeEvent) { + + if (event.entity !is Player) { + return + } + + val player = event.entity as Player + + if (!TimerHandler.hasTimer(player.uniqueId,TimerType.PVP_TIMER)) { + return + } + + if (event.foodLevel >= player.foodLevel) { + return + } + + if (ChanceUtil.pick(100) >= 30) { + return + } + + event.isCancelled = true + } + + @EventHandler(priority = EventPriority.LOWEST) + private fun onPlayerPortal(event: PlayerPortalEvent) { + + if (event.cause != PlayerTeleportEvent.TeleportCause.END_PORTAL || event.to.world.environment != World.Environment.THE_END) { + return + } + + if (!TimerHandler.hasTimer(event.player.uniqueId, TimerType.PVP_TIMER)) { + return + } + + event.isCancelled = true + event.player.sendMessage("${ChatColor.RED}You cannot enter the end whilst being PvP Protected!") + } + + @EventHandler(priority = EventPriority.HIGHEST) + private fun onPotionSplash(event: PotionSplashEvent) { + + if (event.entity.shooter !is Player) { + return + } + + val player = event.entity.shooter as Player + + if (!TimerHandler.hasTimer(player.uniqueId,TimerType.PVP_TIMER)) { + return + } + + event.affectedEntities.clear() + event.affectedEntities.add(player) + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/timer/listener/SpawnTagListener.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/timer/listener/SpawnTagListener.kt new file mode 100644 index 0000000..3e4970d --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/timer/listener/SpawnTagListener.kt @@ -0,0 +1,125 @@ +package cc.fyre.hcf.timer.listener + +import cc.fyre.hcf.HCF +import cc.fyre.hcf.faction.FactionHandler +import cc.fyre.hcf.faction.FactionMetadata +import cc.fyre.shard.util.TimeUtil +import cc.fyre.hcf.faction.type.PlayerFaction +import cc.fyre.hcf.faction.type.SystemFaction +import cc.fyre.hcf.faction.event.FactionMoveEvent +import cc.fyre.hcf.timer.TimerHandler +import cc.fyre.hcf.timer.TimerType +import cc.fyre.hcf.timer.event.TimerCreateEvent +import cc.fyre.shard.util.player.PlayerUtil +import org.bukkit.Bukkit +import org.bukkit.ChatColor +import org.bukkit.GameMode +import org.bukkit.World +import org.bukkit.entity.EnderPearl +import org.bukkit.entity.Player +import org.bukkit.entity.Projectile +import org.bukkit.event.EventHandler +import org.bukkit.event.EventPriority +import org.bukkit.event.Listener +import org.bukkit.event.block.BlockPlaceEvent +import org.bukkit.event.entity.EntityDamageByEntityEvent +import org.bukkit.event.player.PlayerPortalEvent +import org.bukkit.event.player.PlayerTeleportEvent + +/** + * @project hcf + * + * @date 20/07/2020 + * @author xanderume@gmail.com + */ +object SpawnTagListener : Listener { + + @EventHandler(priority = EventPriority.MONITOR,ignoreCancelled = true) + private fun onTimerCreate(event: TimerCreateEvent) { + + if (event.isCancelled) { + return + } + + if (event.timer.type != TimerType.SPAWN_TAG) { + return + } + + Bukkit.getServer().getPlayer(event.uuid)?.sendMessage("${ChatColor.YELLOW}You have been spawn-tagged for ${ChatColor.RED}${TimeUtil.formatIntoDetailedString(event.timer.getDuration())}${ChatColor.YELLOW}!") + } + + @EventHandler(priority = EventPriority.MONITOR) + private fun onEntityDamageByEntity(event: EntityDamageByEntityEvent) { + + if (event.isCancelled) { + return + } + + if (event.entity !is Player) { + return + } + + val player = event.entity as Player + + if (event.damager is EnderPearl) { + return + } + + val damager = if (event.damager is Player) { + event.damager as Player + } else if (event.damager is Projectile && ((event.damager as Projectile).shooter) is Player) { + (event.damager as Projectile).shooter as Player + } else { + null + } ?: return + + if (event.entity.uniqueId == damager.uniqueId) { + return + } + + TimerHandler.addTimer(player.uniqueId,TimerType.SPAWN_TAG) + TimerHandler.addTimer(damager.uniqueId,TimerType.SPAWN_TAG) + } + + @EventHandler(priority = EventPriority.LOWEST,ignoreCancelled = true) + private fun onFactionMove(event: FactionMoveEvent) { + + if (event.player.gameMode == GameMode.CREATIVE) { + return + } + + if (!TimerHandler.hasTimer(event.player.uniqueId,TimerType.SPAWN_TAG)) { + return + } + + if (event.from is SystemFaction && event.from.hasMetadata(FactionMetadata.SAFE_ZONE)) { + return + } + + if (event.to !is SystemFaction || !event.to.hasMetadata(FactionMetadata.SAFE_ZONE)) { + return + } + + event.isCancelled = true + } + + @EventHandler(priority = EventPriority.LOWEST) + private fun onPlayerPortal(event: PlayerPortalEvent) { + + if (event.cause != PlayerTeleportEvent.TeleportCause.END_PORTAL) { + return + } + + if (event.to.world.environment != World.Environment.THE_END) { + return + } + + if (!TimerHandler.hasTimer(event.player.uniqueId, TimerType.SPAWN_TAG)) { + return + } + + event.isCancelled = true + event.player.sendMessage("${ChatColor.RED}You cannot enter the end whilst spawn-tagged!") + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/timer/listener/StuckListener.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/timer/listener/StuckListener.kt new file mode 100644 index 0000000..9bc4043 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/timer/listener/StuckListener.kt @@ -0,0 +1,172 @@ +package cc.fyre.hcf.timer.listener + +import cc.fyre.shard.util.ChanceUtil +import cc.fyre.hcf.faction.FactionHandler +import cc.fyre.hcf.faction.FactionMetadata +import cc.fyre.hcf.faction.claim.ClaimHandler +import cc.fyre.hcf.timer.TimerHandler +import cc.fyre.hcf.timer.TimerType +import cc.fyre.hcf.timer.event.TimerCreateEvent +import cc.fyre.hcf.timer.event.TimerExpireEvent +import cc.fyre.Forge +import cc.fyre.handler.MovementHandler +import net.minecraft.server.v1_7_R4.PacketPlayInFlying +import org.bukkit.Bukkit +import org.bukkit.ChatColor +import org.bukkit.Location +import org.bukkit.Material +import org.bukkit.block.BlockFace +import org.bukkit.entity.Player +import org.bukkit.event.EventHandler +import org.bukkit.event.EventPriority +import org.bukkit.event.Listener +import org.bukkit.event.entity.EntityDamageEvent +import org.bukkit.event.player.PlayerQuitEvent +import org.bukkit.event.player.PlayerTeleportEvent +import java.util.* +import kotlin.math.abs + +/** + * @project hcf + * + * @date 07/07/2020 + * @author xanderume@gmail.com + */ +object StuckListener : Listener, MovementHandler { + + private const val RADIUS = 5 + + init { + Forge.INSTANCE.addMovementHandler(this) + } + + private val cache = mutableMapOf() + + @EventHandler(priority = EventPriority.MONITOR) + private fun onTimerCreate(event: TimerCreateEvent) { + + if (event.timer.type != TimerType.STUCK) { + return + } + + val player = Bukkit.getServer().getPlayer(event.uuid) ?: return + + this.cache[player.uniqueId] = player.location + } + + @EventHandler(priority = EventPriority.MONITOR) + private fun onTimerExpire(event: TimerExpireEvent) { + + if (event.timer.type != TimerType.STUCK) { + return + } + + val player = Bukkit.getServer().getPlayer(event.uuid) ?: return + + EnderpearlListener.cache.remove(player.uniqueId)?.remove() + + val claim = ClaimHandler.getClaimByLocation(player.location) + + if (claim != null) { + + val corners = claim.getCorners() + val location = corners[ChanceUtil.pick(corners.lastIndex)] + + location.y = this.findHighestY(location) + + player.teleport(location) + player.sendMessage("${ChatColor.YELLOW}Teleported you to the nearest safe area!") + return + } + + val spawn = FactionHandler.getAllSystemFactions().firstOrNull{it.hasMetadata(FactionMetadata.SAFE_ZONE)}?.getHQ() ?: player.world.spawnLocation + + player.teleport(spawn) + player.sendMessage("${ChatColor.RED}We couldn't find a safe location, so you have been teleported to Spawn.") + } + + @EventHandler(priority = EventPriority.MONITOR) + private fun onPlayerQuit(event: PlayerQuitEvent) { + + if (!TimerHandler.removeTimer(event.player.uniqueId, TimerType.STUCK)) { + return + } + + this.cache.remove(event.player.uniqueId) + } + + @EventHandler(priority = EventPriority.MONITOR) + private fun onEntityDamage(event: EntityDamageEvent) { + + if (event.isCancelled) { + return + } + + if (event.damage <= 0) { + return + } + + if (event.entity !is Player) { + return + } + + val player = event.entity as Player + + if (!TimerHandler.removeTimer(player.uniqueId,TimerType.STUCK)) { + return + } + + this.cache.remove(event.entity.uniqueId) + + (event.entity as Player).sendMessage("${ChatColor.RED}Teleport cancelled.") + } + + @EventHandler(priority = EventPriority.MONITOR) + private fun onPlayerTeleport(event: PlayerTeleportEvent) { + + if (event.isCancelled) { + return + } + + this.handleUpdateLocation(event.player,event.to,event.from,null) + } + + override fun handleUpdateRotation(player: Player, to: Location, from: Location, packet: PacketPlayInFlying?) {} + + override fun handleUpdateLocation(player: Player, to: Location, from: Location, packet: PacketPlayInFlying?) { + + if (from.blockX == to.blockX && from.blockZ == to.blockZ) { + return + } + + if (!TimerHandler.hasTimer(player.uniqueId, TimerType.STUCK)) { + return + } + + val location = this.cache[player.uniqueId] ?: return + + val blockX = location.blockX + val blockZ = location.blockZ + + if (((abs(to.blockX - blockX) + 1) < RADIUS && (abs(to.blockZ - blockZ) + 1) < RADIUS)) { + return + } + + this.cache.remove(player.uniqueId) + TimerHandler.removeTimer(player.uniqueId, TimerType.STUCK) + + player.sendMessage("${ChatColor.RED}You moved more than $RADIUS blocks, teleport cancelled!") + } + + private fun findHighestY(location: Location):Double { + + var block = location.world.getHighestBlockAt(location) + + while (block.type == Material.AIR && block.y > 0) { + block = block.getRelative(BlockFace.DOWN) + } + + return block.y.toDouble() + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/kotlin/cc/fyre/hcf/timer/listener/TimerListener.kt b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/timer/listener/TimerListener.kt new file mode 100644 index 0000000..75f6c30 --- /dev/null +++ b/Shitty HCF/src/main/kotlin/cc/fyre/hcf/timer/listener/TimerListener.kt @@ -0,0 +1,113 @@ +package cc.fyre.hcf.timer.listener + +import cc.fyre.hcf.HCF +import cc.fyre.hcf.timer.TimerHandler +import cc.fyre.hcf.timer.TimerRepository +import cc.fyre.hcf.timer.Timer +import cc.fyre.hcf.timer.event.TimerCreateEvent +import cc.fyre.hcf.timer.event.TimerExtendEvent +import cc.fyre.hcf.timer.event.TimerRemoveEvent +import com.lunarclient.bukkitapi.LunarClientAPI +import com.lunarclient.bukkitapi.nethandler.client.LCPacketCooldown +import org.bukkit.Bukkit + +import org.bukkit.event.EventHandler +import org.bukkit.event.EventPriority +import org.bukkit.event.Listener +import org.bukkit.event.player.AsyncPlayerPreLoginEvent +import org.bukkit.event.player.PlayerQuitEvent + +/** + * @project hcf + * + * @date 30/08/2020 + * @author xanderume@gmail.com + */ +object TimerListener : Listener { + + @EventHandler(priority = EventPriority.MONITOR) + private fun onPlayerQuit(event: PlayerQuitEvent) { + + val toSave = mutableListOf() + + TimerHandler.getTimersByPlayer(event.player.uniqueId).forEach{ + + if (it.type.icon != null) { + LunarClientAPI.getInstance().sendPacket(event.player,LCPacketCooldown(it.type.name,1L,it.type.icon.id)) + } + + if (HCF.instance.isInShutdownState()) { + return@forEach + } + + if (!it.type.isPersistable()) { + return@forEach + } + + toSave.add(it) + } + + if (HCF.instance.isInShutdownState()) { + return + } + + if (toSave.isEmpty()) { + return + } + + TimerHandler.addUpdate(event.player.uniqueId,toSave) + } + + @EventHandler(priority = EventPriority.MONITOR) + private fun onAsyncPreLogin(event: AsyncPlayerPreLoginEvent) { + + if (event.loginResult != AsyncPlayerPreLoginEvent.Result.ALLOWED) { + return + } + + var timers = TimerHandler.removeIfQueued(event.uniqueId) + + if (timers == null) { + timers = TimerRepository.findAllById(event.uniqueId,true) + } + + timers.forEach{TimerHandler.addTimer(event.uniqueId,it.type,it.duration,force = true)} + } + + @EventHandler(priority = EventPriority.MONITOR) + private fun onTimerCreate(event: TimerCreateEvent) { + + if (event.timer.type.icon == null) { + return + } + + val player = Bukkit.getServer().getPlayer(event.uuid) ?: return + + LunarClientAPI.getInstance().sendPacket(player,LCPacketCooldown(event.timer.type.name,event.timer.type.duration,event.timer.type.icon.id)) + } + + @EventHandler(priority = EventPriority.MONITOR) + private fun onTimerRemove(event: TimerRemoveEvent) { + + if (event.timer.type.icon == null) { + return + } + + val player = Bukkit.getServer().getPlayer(event.uuid) ?: return + + LunarClientAPI.getInstance().sendPacket(player,LCPacketCooldown(event.timer.type.name,1L,event.timer.type.icon.id)) + } + + @EventHandler(priority = EventPriority.MONITOR) + private fun onTimerExtend(event: TimerExtendEvent) { + + if (event.timer.type.icon == null) { + return + } + + val player = Bukkit.getServer().getPlayer(event.uuid) ?: return + + LunarClientAPI.getInstance().sendPacket(player,LCPacketCooldown(event.timer.type.name,event.newDuration,event.timer.type.icon.id)) + } + +} \ No newline at end of file diff --git a/Shitty HCF/src/main/resources/plugin.yml b/Shitty HCF/src/main/resources/plugin.yml new file mode 100644 index 0000000..b3662c9 --- /dev/null +++ b/Shitty HCF/src/main/resources/plugin.yml @@ -0,0 +1,4 @@ +name: HCF +main: cc.fyre.hcf.HCF +version: 1.0-SNAPSHOT +depend: [Shard,Core] \ No newline at end of file