mirror of
https://github.com/SunNetservers/MiniGames.git
synced 2025-04-02 09:46:26 +02:00
Compare commits
99 Commits
Author | SHA1 | Date | |
---|---|---|---|
d7e950c53e | |||
c8fbdec64f | |||
09f29e5f67 | |||
7213bd0c70 | |||
a23d0c769f | |||
142cd5339b | |||
b063bd1088 | |||
310802b42d | |||
fc6bd33e87 | |||
ccf43060dc | |||
a498e9bad0 | |||
d8bf77d317 | |||
162aff0c1f | |||
a7cfe36c72 | |||
407acf0ea2 | |||
b6bf22d1c7 | |||
67144fec06 | |||
e52732433a | |||
776fc5a757 | |||
1e7cdf02fc | |||
f3d8be8be2 | |||
4bf00243e6 | |||
ea439bfa33 | |||
003c9e8367 | |||
9dff407713 | |||
d7b1695cd9 | |||
2bc6c2c825 | |||
f24959c8d1 | |||
8ea930a5f3 | |||
57183b64f5 | |||
ba1a7fff68 | |||
57b3b85fbc | |||
38839c0287 | |||
de5124c8dd | |||
9c91e11780 | |||
4513fc2de7 | |||
7900eb691f | |||
d6fb9ab0b9 | |||
7848a0a028 | |||
00ac0582f4 | |||
0704e138ec | |||
05d647052b | |||
fc1902e86a | |||
e039840e89 | |||
701cdd81eb | |||
078a8ed007 | |||
8d1b841619 | |||
4a3329459e | |||
206a85b23a | |||
401490df58 | |||
b2fbaf0e68 | |||
7c04e91024 | |||
e6bb324da1 | |||
58e25bcb30 | |||
cf0962ef70 | |||
01a3d0b73c | |||
ce0a0dbaa7 | |||
ac70b4bb0d | |||
bcddd214f6 | |||
0344060214 | |||
76e11ec6b8 | |||
a84e164edf | |||
b0a72561f9 | |||
c68cafb925 | |||
8e4737a267 | |||
e21e872e89 | |||
6950246134 | |||
257fc48912 | |||
31b22c7e56 | |||
904761ba4e | |||
12789980c0 | |||
8f77fc5910 | |||
1acaebb3bc | |||
9a3f9841ab | |||
b1e86a928b | |||
4de5ae469b | |||
2f4d4ff4c6 | |||
50978d8baf | |||
3bbf41206c | |||
6a41664fef | |||
d1964e9d7b | |||
cd7d8eded0 | |||
b95cc294ab | |||
458dbc2beb | |||
efaca03434 | |||
58b5b422f0 | |||
483a0a16dc | |||
e1c4a6a97c | |||
5be6f0d00e | |||
f6a272b0c0 | |||
46e52812af | |||
fe016fd620 | |||
8e9b274fc0 | |||
2b9cfeebb1 | |||
096f23d468 | |||
3ebf5fa924 | |||
579c1ea0f9 | |||
d41154281b | |||
f852de7309 |
15
HEADER
Normal file
15
HEADER
Normal file
@ -0,0 +1,15 @@
|
||||
MiniGames - A mini-games plugin for spigot
|
||||
Copyright (C) 2023 Kristian Knarvik (EpicKnarvik97)
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
297
README.md
297
README.md
@ -1,39 +1,117 @@
|
||||
# Dropper
|
||||
# MiniGames
|
||||
|
||||
This is a plugin for a dropper mini-game (try to reach the bottom without hitting any obstacles).
|
||||
To create an arena, simply use `/droppercreate <name>`, where \<name> is simply the name used to differentiate and
|
||||
recognize the arena. Your location will be used as the spawn location for anyone joining the dropper arena. To start
|
||||
This plugin adds several mini-games.
|
||||
|
||||
To create a dropper arena, simply use `/droppercreate <name>`, where \<name> is simply the name used to differentiate
|
||||
and recognize the arena. Your location will be used as the spawn location for anyone joining the dropper arena. To start
|
||||
playing, simply use `/dropperjoin <name>`, where \<name> is the same as you specified upon creation.
|
||||
To modify
|
||||
To modify the arena, use `/dropperedit <name> <property> <value>`.
|
||||
|
||||
To create a parkour arena, simply use `/parkourcreate <name>`, where \<name> is simply the name used to differentiate
|
||||
and recognize the arena. Your location will be used as the spawn location for anyone joining the dropper arena. To start
|
||||
playing, simply use `/parkourjoin <name>`, where \<name> is the same as you specified upon creation.
|
||||
To modify the arena, use `/parkouredit <name> <property> <value>`. Use `/parkouredit checkpointAdd here` to add a
|
||||
checkpoint at your current location.
|
||||
|
||||
## Permissions
|
||||
|
||||
| Node | Description |
|
||||
|----------------|----------------------------------------------------|
|
||||
| dropper.admin | Gives all permissions. |
|
||||
| dropper.join | Allows a player to participate in dropper arenas. |
|
||||
| dropper.create | Allows a player to create a new dropper arena. |
|
||||
| dropper.edit | Allows a player to edit an existing dropper arena. |
|
||||
| dropper.remove | Allows a player to remove a dropper arena. |
|
||||
The only permission normal players will need is `minigames.join` which is set to true by default.
|
||||
|
||||
| Node | Description |
|
||||
|--------------------------|------------------------------------------------------|
|
||||
| minigames.admin | Gives all permissions. |
|
||||
| minigames.dropper | Gives all dropper-related permissions. |
|
||||
| minigames.parkour | Gives all parkour-related permissions. |
|
||||
| minigames.join | Allows a player to participate in mini-game arenas. |
|
||||
| minigames.join.dropper | Allows a player to participate in dropper arenas. |
|
||||
| minigames.join.parkour | Allows a player to participate in parkour arenas. |
|
||||
| minigames.create | Allows a player to create a new mini-game arena. |
|
||||
| minigames.create.dropper | Allows a player to create a new dropper arena. |
|
||||
| minigames.create.parkour | Allows a player to create a new parkour arena. |
|
||||
| minigames.edit | Allows a player to edit an existing mini-game arena. |
|
||||
| minigames.edit.dropper | Allows a player to edit an existing dropper arena. |
|
||||
| minigames.edit.parkour | Allows a player to edit an existing parkour arena. |
|
||||
| minigames.remove | Allows a player to remove a mini-game arena. |
|
||||
| minigames.remove.dropper | Allows a player to remove a dropper arena. |
|
||||
| minigames.remove.parkour | Allows a player to remove a parkour arena. |
|
||||
|
||||
## Commands
|
||||
|
||||
| Command | Alias | Arguments | Description |
|
||||
|-----------------------------------------|----------|-----------------------------|-------------------------------------------------------------------------------------|
|
||||
| /dropperList | /dlist | | Lists available dropper arenas. |
|
||||
| [/dropperJoin](#/dropperJoin) | /djoin | \<arena> \[mode] | Joins the selected arena. |
|
||||
| /dropperLeave | /dleave | | Leaves the current dropper arena. |
|
||||
| /dropperCreate | /dcreate | \<name> | Creates a new dropper arena with the given name. The spawn is set to your location. |
|
||||
| /dropperRemove | /dremove | \<arena> | Removes the specified dropper arena. |
|
||||
| [/dropperEdit](#/dropperEdit) | /dedit | \<arena> \<option> \[value] | Gets or sets a dropper arena option. |
|
||||
| /dropperReload | /dreload | | Reloads all data from disk. |
|
||||
| [/dropperGroupSet](#/dropperGroupSet) | /dgset | \<arena> \<group> | Puts the given arena in the given group. Use "none" to remove an existing group. |
|
||||
| /dropperGroupList | /dglist | \[group] | Lists groups, or the stages of a group if a group is specified. |
|
||||
| [/dropperGroupSwap](#/dropperGroupSwap) | /dgswap | \<arena1> \<arena2> | Swaps the two arenas in the group's ordered list. |
|
||||
| Command | Alias | Arguments | Description |
|
||||
|----------------------------------------|----------|------------------------------|-------------------------------------------------------------------------------------|
|
||||
| /miniGamesReload | /mreload | | Reloads all data from disk. |
|
||||
| /miniGamesLeave | /mleave | | Leaves the current mini-game. |
|
||||
| /miniGamesMenu | /mmenu | | Shows a menu of actions if used while in an arena |
|
||||
| [/miniGamesReward](#minigamesreward) | /mreward | [See this](#minigamesreward) | Adds or removes rewards for an arena |
|
||||
| /dropperList | /dlist | | Lists available dropper arenas. |
|
||||
| [/dropperJoin](#dropperjoin) | /djoin | \<arena> \[mode] | Joins the selected arena. |
|
||||
| /dropperCreate | /dcreate | \<name> | Creates a new dropper arena with the given name. The spawn is set to your location. |
|
||||
| /dropperRemove | /dremove | \<arena> | Removes the specified dropper arena. |
|
||||
| [/dropperEdit](#dropperedit) | /dedit | \<arena> \<option> \[value] | Gets or sets a dropper arena option. |
|
||||
| [/dropperGroupSet](#droppergroupset) | /dgset | \<arena> \<group> | Puts the given arena in the given group. Use "none" to remove an existing group. |
|
||||
| /dropperGroupList | /dglist | \[group] | Lists groups, or the stages of a group if a group is specified. |
|
||||
| [/dropperGroupSwap](#droppergroupswap) | /dgswap | \<arena1> \<arena2> | Swaps the two arenas in the group's ordered list. |
|
||||
| /parkourList | /plist | | Lists available parkour arenas. |
|
||||
| [/parkourJoin](#parkourjoin) | /pjoin | \<arena> \[mode] | Joins the selected arena. |
|
||||
| /parkourCreate | /pcreate | \<name> | Creates a new parkour arena with the given name. The spawn is set to your location. |
|
||||
| /parkourRemove | /premove | \<arena> | Removes the specified parkour arena. |
|
||||
| [/parkourEdit](#parkouredit) | /pedit | \<arena> \<option> \[value] | Gets or sets a parkour arena option. |
|
||||
| /parkourGroupSet | /pgset | \<arena> \<group> | Puts the given arena in the given group. Use "none" to remove an existing group. |
|
||||
| /parkourGroupList | /pglist | \[group] | Lists groups, or the stages of a group if a group is specified. |
|
||||
| [/parkourGroupSwap](#droppergroupswap) | /pgswap | \<arena1> \<arena2> | Swaps the two arenas in the group's ordered list. |
|
||||
|
||||
## Command explanation
|
||||
### Command explanation mini-games
|
||||
|
||||
### /dropperJoin
|
||||
#### /miniGamesReward
|
||||
|
||||
This command is used to set the rewards for an arena. Rewards can be set for six conditions; a reward for each time the
|
||||
arena is cleared, a reward for the first time the arena is cleared, a reward for beating your own least deaths record, a
|
||||
reward for beating your own least time record, a record for beating the global least deaths record and a record for
|
||||
beating the global least time record. You can give an item, give money, give a permission or execute a console command
|
||||
with the winning player as an argument.
|
||||
|
||||
Note, you can add as many rewards as you want for each reward condition, so you can add a permission and an amount of
|
||||
currency on the player's first win for example.
|
||||
|
||||
`/mreward add dropper|parkour <name> <condition> <type> [value] [value] ...`
|
||||
|
||||
`/mreward clear dropper|parkour <name> <condition>`
|
||||
|
||||
| Argument | Type | Usage |
|
||||
|-----------|-----------------------------------------------------------------------------------------------------------|-------------------------------------------------------------|
|
||||
| action | add / clear | Whether you are adding a reward or clearing rewards. |
|
||||
| type | dropper / parkour | The type of arena to change rewards for |
|
||||
| name | _Arena name_ | The name of the arena to change rewards for |
|
||||
| condition | WIN / FIRST_WIN / PERSONAL_DEATH_RECORD / PERSONAL_TIME_RECORD / GLOBAL_DEATH_RECORD / GLOBAL_TIME_RECORD | The condition to change rewards for. |
|
||||
| type | COMMAND / ECONOMY / ITEM / PERMISSION | The type of reward to add |
|
||||
| value | [See reward types](#reward-types) | Input for the reward type. Valid values depend on the type. |
|
||||
|
||||
##### Reward types
|
||||
|
||||
###### Economy
|
||||
|
||||
This reward requires an argument which is a number above zero, which is the amount of currency granted to players.
|
||||
|
||||
###### Permission
|
||||
|
||||
This reward requires an argument which is the permission string you want to grant the player.
|
||||
|
||||
###### Command
|
||||
|
||||
The reward requires the command as an argument. Type the full command with spaces and everything, but omit the `/` at
|
||||
the beginning of the command. Use %player_name% or anything that matches the
|
||||
RegEx `[<%(\\[{]player[_\\-]?(name)?[>%)\\]}]` (\<player>. \<player-name>, %player_name%, {player}, etc.) as the
|
||||
placeholder for the rewarded player's name.
|
||||
|
||||
###### Item
|
||||
|
||||
If used with no arguments, the item in your main hand is used. You can specify a material in the first argument to give
|
||||
one item of the specified type. You can specify a positive whole number as the second argument to specify the amount of
|
||||
items to give.
|
||||
|
||||
### Command explanation dropper
|
||||
|
||||
#### /dropperJoin
|
||||
|
||||
This command is used for joining a dropper arena.
|
||||
|
||||
@ -44,7 +122,7 @@ This command is used for joining a dropper arena.
|
||||
| arena | The name of the arena to join. |
|
||||
| mode | Additional challenge modes can be played after an arena has been cleared once. Available modes: inverted and random. |
|
||||
|
||||
### /dropperEdit
|
||||
#### /dropperEdit
|
||||
|
||||
This command allows editing the specified property for the specified dropper arena.
|
||||
|
||||
@ -67,7 +145,7 @@ These are all the options that can be changed for an arena.
|
||||
| horizontalVelocity | The horizontal velocity (technically fly speed) set for players in the arena. It must be between 0 and 1, and cannot be 0. Decimals are allowed. |
|
||||
| winBlockType | The type of block players must hit to win the arena. It can be any material as long as it's a block, and not a type of air. |
|
||||
|
||||
### /dropperGroupSet
|
||||
#### /dropperGroupSet
|
||||
|
||||
This command is used to set the group of an arena
|
||||
|
||||
@ -78,7 +156,7 @@ will be used again if you specify the "potato" group for another arena. You use
|
||||
its group. If the group has no arenas, it will be automatically removed. If the arena already is in a group, it will be
|
||||
moved to the new group.
|
||||
|
||||
### /dropperGroupSwap
|
||||
#### /dropperGroupSwap
|
||||
|
||||
This command is used for changing the order of arenas within a group.
|
||||
|
||||
@ -97,4 +175,163 @@ You could use `/droppergroupswap Sea Savanna` to change the order to:
|
||||
1. Forest
|
||||
2. Savanna
|
||||
3. Nether
|
||||
4. Sea
|
||||
4. Sea
|
||||
|
||||
### Command explanation parkour
|
||||
|
||||
#### /parkourJoin
|
||||
|
||||
This command is used for joining a dropper arena.
|
||||
|
||||
`/parkourjoin <arena> [mode]`
|
||||
|
||||
| Argument | Usage |
|
||||
|----------|-----------------------------------------------------------------------------------------------------------|
|
||||
| arena | The name of the arena to join. |
|
||||
| mode | Additional challenge modes can be played after an arena has been cleared once. Available modes: hardcore. |
|
||||
|
||||
#### /parkourEdit
|
||||
|
||||
This command allows editing the specified property for the specified parkour arena.
|
||||
|
||||
`/parkouredit <arena> <option> [value]`
|
||||
|
||||
| Argument | Usage |
|
||||
|----------|---------------------------------------|
|
||||
| arena | The name of the arena to edit. |
|
||||
| option | The option to display or change. |
|
||||
| value | The new value of the selected option. |
|
||||
|
||||
These are all the options that can be changed for an arena.
|
||||
|
||||
| Option | Details |
|
||||
|-----------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
||||
| name | The name of the arena. Used mainly to select the arena in commands. Note that underscore (_) cannot be used if you want to utilize placeholders, as it's used to split placeholder arguments. |
|
||||
| spawnLocation | The spawn location of any player joining the arena. Use `56.546,64.0,44.45` to specify coordinates, or `here`, `this` or any other string to select your current location. |
|
||||
| exitLocation | The location players will be sent to when exiting the arena. If not set, the player will be sent to where they joined from. Valid values are the same as for spawnLocation. |
|
||||
| winBlockType | The type of block players must hit to win the arena. It can be any material as long as it's a block, and not a type of air. |
|
||||
| winLocation | The location players must reach to win the arena (see spawnLocation for valid values). If set, this overrides, and is used instead of, the win block type. |
|
||||
| checkpointAdd | Adds a new checkpoint to the arena's checkpoints (see spawnLocation for valid values). |
|
||||
| checkpointClear | Clears all current checkpoints. Give any value to execute. If not given a value, current checkpoints are shown. |
|
||||
| killPlaneBlocks | A comma-separated list of materials which will force a loss when stepped on. +WOOL and other [material tags](#notes-about-material-tags) are supported as well. |
|
||||
| obstacleBlocks | A comma-separated list of materials which will force a loss when touched from any direction. +WOOL and other [material tags](#notes-about-material-tags) are supported as well. |
|
||||
|
||||
## Configuration options
|
||||
|
||||
### Shared
|
||||
|
||||
| Name | Type | Default | Description |
|
||||
|---------------------|------------------|---------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
||||
| liquidHitBoxDepth | -1 < decimal < 0 | -0.8 | This decides how far inside a non-solid block the player must go before detection triggers (-1, 0). The closer to -1 it is, the more accurate it will seem to the player, but the likelihood of not detecting the hit increases. |
|
||||
| solidHitBoxDistance | 0 < decimal < 1 | 0.2 | This decides the distance the player must be from a block below them before a hit triggers (0, 1). If too low, the likelihood of detecting the hit decreases, but it won't look like the player hit the block without being near. |
|
||||
|
||||
### Dropper
|
||||
|
||||
| Name | Type | Default | Description |
|
||||
|-----------------------------------|---------------------|-------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
||||
| blockSneaking | true/false | true | Whether to block using the shift key to drop faster than the intended drop speed |
|
||||
| blockSprinting | true/false | true | Whether to block using the sprint key for slightly improved air speed |
|
||||
| verticalVelocity | 0 < decimal <= 75 | 1.0 | The vertical velocity used as default for all arenas. Must be greater than 0. 3.92 is the max speed of a falling player. |
|
||||
| horizontalVelocity | 0 < decimal <= 1 | 1.0 | The horizontal velocity used as default for all arenas (technically fly-speed). Must be between 0 (exclusive) and 1 (inclusive). |
|
||||
| randomlyInvertedTimer | 0 < integer <= 3600 | 7 | The number of seconds before the randomly inverted game-mode switches between normal and inverted movement (0, 3600] |
|
||||
| mustDoGroupedInSequence | true/false | true | Whether grouped dropper arenas must be played in the correct sequence |
|
||||
| ignoreRecordsUntilGroupBeatenOnce | true/false | false | Whether records won't be registered unless the player has already beaten all arenas in a group. That means players are required to do a second play-through to register a record for a grouped arena. |
|
||||
| mustDoNormalModeFirst | true/false | true | Whether a player must do the normal/default game-mode before playing any other game-modes |
|
||||
| liquidHitBoxDepth | -1 < decimal < 0 | -0.8 | This decides how far inside a non-solid block the player must go before detection triggers (-1, 0). The closer to -1 it is, the more accurate it will seem to the player, but the likelihood of not detecting the hit increases. |
|
||||
| solidHitBoxDistance | 0 < decimal < 1 | 0.2 | This decides the distance the player must be from a block below them before a hit triggers (0, 1). If too low, the likelihood of detecting the hit decreases, but it won't look like the player hit the block without being near. |
|
||||
| blockWhitelist | list | [see this](#blockwhitelist-default) | A whitelist for which blocks won't trigger a loss when hit/passed through. The win block check happens before the loss check, so even blocks on the whitelist can be used as the win-block. "+" denotes a [material tag](#notes-about-material-tags). |
|
||||
|
||||
### Parkour
|
||||
|
||||
| Name | Type | Default | Description |
|
||||
|-----------------------------------|------------|--------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
||||
| enforceCheckpointOrder | true/false | false | Whether to enforce the order in which a player must reach checkpoints. Enabling this ensures that a player cannot trigger a previous checkpoint by accident. It also ensures players cannot skip a checkpoint, even if the arena layout makes it possible. |
|
||||
| mustDoGroupedInSequence | true/false | true | Whether grouped dropper arenas must be played in the correct sequence |
|
||||
| ignoreRecordsUntilGroupBeatenOnce | true/false | false | Whether records won't be registered unless the player has already beaten all arenas in a group. That means players are required to do a second play-through to register a record for a grouped arena. |
|
||||
| killPlaneBlocks | list | [see this](#killplaneblocks-default) | The types of blocks compromising parkour arenas' kill planes. Add any materials you want to use for the "bottom" of your parkour arenas. +WOOL and other [material tags](#notes-about-material-tags) are supported. |
|
||||
| obstacleBlocks | list | [see this](#obstacleblocks-default) | The types of blocks treated as obstacles in every direction. +WOOL and other [material tags](#notes-about-material-tags) are supported. |
|
||||
|
||||
#### blockWhitelist default:
|
||||
|
||||
- WATER
|
||||
- LAVA
|
||||
- +WALL_SIGNS
|
||||
- +STANDING_SIGNS
|
||||
- STRUCTURE_VOID
|
||||
- WALL_TORCH
|
||||
- SOUL_WALL_TORCH
|
||||
- REDSTONE_WALL_TORCH
|
||||
- +BANNERS
|
||||
- +BUTTONS
|
||||
- +CORALS
|
||||
- +WALL_CORALS
|
||||
|
||||
#### killPlaneBlocks default:
|
||||
|
||||
- LAVA
|
||||
- MAGMA_BLOCK
|
||||
|
||||
#### obstacleBlocks default:
|
||||
|
||||
- END_ROD
|
||||
- LIGHTNING_ROD
|
||||
- CHAIN
|
||||
|
||||
## Record placeholders
|
||||
|
||||
Player records can be displayed on a leaderboard by using PlaceholderAPI. If you want to display a sign-based
|
||||
leaderboard, you can use the [Placeholder Signs](https://git.knarcraft.net/EpicKnarvik97/PlaceholderSigns) plugin. The
|
||||
format for the built-in placeholders is as follows:
|
||||
|
||||
`%gameMode_record_recordType_gameModeType_identifierType_identifier_recordPlacing_infoType%`
|
||||
|
||||
| Variable | Values | Description |
|
||||
|----------------|-----------------------------|------------------------------------------------------------------------------------------------------------------------------------|
|
||||
| gameMode | dropper / parkour | A selection of which game-mode you are getting a record for |
|
||||
| record | | This must be as-is. It's a selector in case placeholders are added for more than records. |
|
||||
| recordType | deaths / time | Selects the type of record to get (deaths or time). |
|
||||
| gameModeType | default / inverted / random | Selects the game-mode to get the record for. |
|
||||
| identifierType | arena / group | The type of thing the following identifier points to (an arena or an arena group). |
|
||||
| identifier | ? | An identifier (the name or UUID) for an arena or a group (whichever was chosen as identifierType). |
|
||||
| recordPlacing | 1 / 2 / 3 / ... | The position of the record to get (1 = first place, 2 = second place, etc.). |
|
||||
| infoType | player / value / combined | The type of info to get. Player gets the player name, Value gets the value of the achieved record. Combined gets "Player: Record". |
|
||||
|
||||
## Notes about material tags
|
||||
|
||||
Where a list of material is allowed, this plugin supports using material tags that specify a set of blocks. This makes
|
||||
it much easier to add a lot of blocks without ending up with hundreds of individual materials. To specify
|
||||
such a tag, use a `+` character, and then the tag name.
|
||||
See <a href="https://hub.spigotmc.org/javadocs/spigot/org/bukkit/Tag.html">the documentation</a> for a complete overview
|
||||
of all tags. Only those with type `Tag<Material>` can be used.
|
||||
|
||||
Example tags:
|
||||
|
||||
- +WOOL
|
||||
- +WALL_SIGNS
|
||||
- +ACACIA_LOGS
|
||||
- +ALL_SIGNS
|
||||
- +DIAMOND_ORES
|
||||
- +DIRT
|
||||
- +DOORS
|
||||
- +DRAGON_IMMUNE
|
||||
- +FENCE_GATES
|
||||
- +FENCES
|
||||
|
||||
## Language customization
|
||||
|
||||
Most or all strings are customizable. If you place a strings.yml file in the plugin folder, it will take
|
||||
priority over built-in languages. If you want to change strings, look at MiniGames/src/main/resources/strings.yml for
|
||||
the proper keys. All strings have the format: ENUM: "Displayed string". The enum must be identical as it defines which
|
||||
string you have changed. All strings belonging to a language are beneath the language code and indented with two spaces.
|
||||
|
||||
The easiest way to add a new language is to copy an existing language and paste it into your custom strings.yml and
|
||||
change strings as necessary. If you don't include all strings, the remaining will use the built-in English translation.
|
||||
Remember to change the language code to whichever you use for your custom language.
|
||||
|
||||
The interval messages are unique in that if several values are separated by comma (option1,option2,option3), a random
|
||||
message will be chosen each time it's displayed.
|
||||
|
||||
## License
|
||||
|
||||
MiniGames is licensed under the GNU Public License Version 3.0. This includes every source and resource file. See the
|
||||
HEADER file for a more detailed license description.
|
68
pom.xml
68
pom.xml
@ -5,13 +5,13 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>net.knarcraft</groupId>
|
||||
<artifactId>Dropper</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<artifactId>MiniGames</artifactId>
|
||||
<version>1.2</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>Dropper</name>
|
||||
<name>MiniGames</name>
|
||||
|
||||
<description>A plugin for dropper mini-games</description>
|
||||
<description>A plugin which adds various mini-games</description>
|
||||
<properties>
|
||||
<java.version>16</java.version>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
@ -40,6 +40,26 @@
|
||||
</goals>
|
||||
<configuration>
|
||||
<createDependencyReducedPom>false</createDependencyReducedPom>
|
||||
<filters>
|
||||
<filter>
|
||||
<artifact>net.knarcraft:knarlib</artifact>
|
||||
<includes>
|
||||
<include>net/knarcraft/knarlib/**</include>
|
||||
</includes>
|
||||
</filter>
|
||||
<filter>
|
||||
<artifact>net.knarcraft:knargui</artifact>
|
||||
<includes>
|
||||
<include>net/knarcraft/knargui/**</include>
|
||||
</includes>
|
||||
</filter>
|
||||
<filter>
|
||||
<excludes>
|
||||
<exclude>*.MF</exclude>
|
||||
<exclude>*.yml</exclude>
|
||||
</excludes>
|
||||
</filter>
|
||||
</filters>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
@ -58,13 +78,25 @@
|
||||
<id>spigot-repo</id>
|
||||
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>placeholderapi</id>
|
||||
<url>https://repo.extendedclip.com/content/repositories/placeholderapi/</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>knarcraft-repo</id>
|
||||
<url>https://git.knarcraft.net/api/packages/EpicKnarvik97/maven</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>jitpack.io</id>
|
||||
<url>https://jitpack.io</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.spigotmc</groupId>
|
||||
<artifactId>spigot-api</artifactId>
|
||||
<version>1.19.4-R0.1-SNAPSHOT</version>
|
||||
<version>1.20-R0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
@ -74,10 +106,28 @@
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.junit.jupiter</groupId>
|
||||
<artifactId>junit-jupiter</artifactId>
|
||||
<version>5.9.2</version>
|
||||
<scope>test</scope>
|
||||
<groupId>me.clip</groupId>
|
||||
<artifactId>placeholderapi</artifactId>
|
||||
<version>2.10.0</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.knarcraft</groupId>
|
||||
<artifactId>knargui</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.knarcraft</groupId>
|
||||
<artifactId>knarlib</artifactId>
|
||||
<version>1.2.3-SNAPSHOT</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.github.MilkBowl</groupId>
|
||||
<artifactId>VaultAPI</artifactId>
|
||||
<version>1.7</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
@ -1,157 +0,0 @@
|
||||
package net.knarcraft.dropper;
|
||||
|
||||
import net.knarcraft.dropper.arena.DropperArenaData;
|
||||
import net.knarcraft.dropper.arena.DropperArenaGroup;
|
||||
import net.knarcraft.dropper.arena.DropperArenaHandler;
|
||||
import net.knarcraft.dropper.arena.DropperArenaPlayerRegistry;
|
||||
import net.knarcraft.dropper.arena.DropperArenaRecordsRegistry;
|
||||
import net.knarcraft.dropper.arena.DropperArenaSession;
|
||||
import net.knarcraft.dropper.command.CreateArenaCommand;
|
||||
import net.knarcraft.dropper.command.EditArenaCommand;
|
||||
import net.knarcraft.dropper.command.EditArenaTabCompleter;
|
||||
import net.knarcraft.dropper.command.GroupListCommand;
|
||||
import net.knarcraft.dropper.command.GroupSetCommand;
|
||||
import net.knarcraft.dropper.command.GroupSwapCommand;
|
||||
import net.knarcraft.dropper.command.JoinArenaCommand;
|
||||
import net.knarcraft.dropper.command.JoinArenaTabCompleter;
|
||||
import net.knarcraft.dropper.command.LeaveArenaCommand;
|
||||
import net.knarcraft.dropper.command.ListArenaCommand;
|
||||
import net.knarcraft.dropper.command.ReloadCommand;
|
||||
import net.knarcraft.dropper.command.RemoveArenaCommand;
|
||||
import net.knarcraft.dropper.command.RemoveArenaTabCompleter;
|
||||
import net.knarcraft.dropper.container.SerializableMaterial;
|
||||
import net.knarcraft.dropper.container.SerializableUUID;
|
||||
import net.knarcraft.dropper.listener.CommandListener;
|
||||
import net.knarcraft.dropper.listener.DamageListener;
|
||||
import net.knarcraft.dropper.listener.MoveListener;
|
||||
import net.knarcraft.dropper.listener.PlayerLeaveListener;
|
||||
import net.knarcraft.dropper.property.ArenaGameMode;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.PluginCommand;
|
||||
import org.bukkit.command.TabCompleter;
|
||||
import org.bukkit.configuration.serialization.ConfigurationSerialization;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.logging.Level;
|
||||
|
||||
/**
|
||||
* The dropper plugin's main class
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public final class Dropper extends JavaPlugin {
|
||||
|
||||
private static Dropper instance;
|
||||
private DropperArenaHandler arenaHandler;
|
||||
private DropperArenaPlayerRegistry playerRegistry;
|
||||
|
||||
/**
|
||||
* Gets an instance of this plugin
|
||||
*
|
||||
* @return <p>An instance of this plugin, or null if not initialized yet.</p>
|
||||
*/
|
||||
public static Dropper getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the arena handler for this instance
|
||||
*
|
||||
* @return <p>A dropper arena handler</p>
|
||||
*/
|
||||
public DropperArenaHandler getArenaHandler() {
|
||||
return this.arenaHandler;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the arena player registry for this instance
|
||||
*
|
||||
* @return <p>A dropper arena player registry</p>
|
||||
*/
|
||||
public DropperArenaPlayerRegistry getPlayerRegistry() {
|
||||
return this.playerRegistry;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reloads all configurations and data from disk
|
||||
*/
|
||||
public void reload() {
|
||||
// Load all arenas again
|
||||
this.arenaHandler.loadArenas();
|
||||
this.arenaHandler.loadGroups();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoad() {
|
||||
super.onLoad();
|
||||
// Register serialization classes
|
||||
ConfigurationSerialization.registerClass(SerializableMaterial.class);
|
||||
ConfigurationSerialization.registerClass(DropperArenaRecordsRegistry.class);
|
||||
ConfigurationSerialization.registerClass(SerializableUUID.class);
|
||||
ConfigurationSerialization.registerClass(DropperArenaData.class);
|
||||
ConfigurationSerialization.registerClass(DropperArenaGroup.class);
|
||||
ConfigurationSerialization.registerClass(ArenaGameMode.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
// Plugin startup logic
|
||||
instance = this;
|
||||
this.playerRegistry = new DropperArenaPlayerRegistry();
|
||||
this.arenaHandler = new DropperArenaHandler();
|
||||
this.arenaHandler.loadArenas();
|
||||
this.arenaHandler.loadGroups();
|
||||
|
||||
PluginManager pluginManager = getServer().getPluginManager();
|
||||
pluginManager.registerEvents(new DamageListener(), this);
|
||||
pluginManager.registerEvents(new MoveListener(), this);
|
||||
pluginManager.registerEvents(new PlayerLeaveListener(), this);
|
||||
pluginManager.registerEvents(new CommandListener(), this);
|
||||
|
||||
registerCommand("dropperReload", new ReloadCommand(), null);
|
||||
registerCommand("dropperCreate", new CreateArenaCommand(), null);
|
||||
registerCommand("dropperList", new ListArenaCommand(), null);
|
||||
registerCommand("dropperJoin", new JoinArenaCommand(), new JoinArenaTabCompleter());
|
||||
registerCommand("dropperLeave", new LeaveArenaCommand(), null);
|
||||
registerCommand("dropperEdit", new EditArenaCommand(), new EditArenaTabCompleter());
|
||||
registerCommand("dropperRemove", new RemoveArenaCommand(), new RemoveArenaTabCompleter());
|
||||
registerCommand("dropperGroupSet", new GroupSetCommand(), null);
|
||||
registerCommand("dropperGroupSwap", new GroupSwapCommand(), null);
|
||||
registerCommand("dropperGroupList", new GroupListCommand(), null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
// Throw out currently playing players before exiting
|
||||
for (Player player : getServer().getOnlinePlayers()) {
|
||||
DropperArenaSession session = playerRegistry.getArenaSession(player.getUniqueId());
|
||||
if (session != null) {
|
||||
session.triggerQuit(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a command
|
||||
*
|
||||
* @param commandName <p>The name of the command to register (defined in plugin.yml)</p>
|
||||
* @param commandExecutor <p>The executor for the command</p>
|
||||
* @param tabCompleter <p>The tab-completer to use, or null</p>
|
||||
*/
|
||||
private void registerCommand(@NotNull String commandName, @NotNull CommandExecutor commandExecutor,
|
||||
@Nullable TabCompleter tabCompleter) {
|
||||
PluginCommand command = this.getCommand(commandName);
|
||||
if (command != null) {
|
||||
command.setExecutor(commandExecutor);
|
||||
if (tabCompleter != null) {
|
||||
command.setTabCompleter(tabCompleter);
|
||||
}
|
||||
} else {
|
||||
getLogger().log(Level.SEVERE, "Unable to register the command " + commandName);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,118 +0,0 @@
|
||||
package net.knarcraft.dropper.arena;
|
||||
|
||||
import net.knarcraft.dropper.Dropper;
|
||||
import net.knarcraft.dropper.container.SerializableUUID;
|
||||
import net.knarcraft.dropper.property.ArenaGameMode;
|
||||
import org.bukkit.configuration.serialization.ConfigurationSerializable;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Data stored for an arena
|
||||
*
|
||||
* @param arenaId <p>The id of the arena this data belongs to</p>
|
||||
* @param recordRegistries <p>The records belonging to the arena</p>
|
||||
* @param playersCompleted <p>A list of all player that have completed this arena</p>
|
||||
*/
|
||||
public record DropperArenaData(@NotNull UUID arenaId,
|
||||
@NotNull Map<ArenaGameMode, DropperArenaRecordsRegistry> recordRegistries,
|
||||
@NotNull Map<ArenaGameMode, Set<UUID>> playersCompleted) implements ConfigurationSerializable {
|
||||
|
||||
/**
|
||||
* Instantiates a new dropper arena data object
|
||||
*
|
||||
* @param arenaId <p>The id of the arena this data belongs to</p>
|
||||
* @param recordRegistries <p>The registries of this arena's records</p>
|
||||
* @param playersCompleted <p>The set of the players that have cleared this arena for each game-mode</p>
|
||||
*/
|
||||
public DropperArenaData(@NotNull UUID arenaId,
|
||||
@NotNull Map<ArenaGameMode, DropperArenaRecordsRegistry> recordRegistries,
|
||||
@NotNull Map<ArenaGameMode, Set<UUID>> playersCompleted) {
|
||||
this.arenaId = arenaId;
|
||||
this.recordRegistries = recordRegistries;
|
||||
this.playersCompleted = new HashMap<>(playersCompleted);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets whether the given player has cleared this arena
|
||||
*
|
||||
* @param arenaGameMode <p>The game-mode to check for</p>
|
||||
* @param player <p>The player to check</p>
|
||||
* @return <p>True if the player has cleared the arena this data belongs to</p>
|
||||
*/
|
||||
public boolean hasNotCompleted(@NotNull ArenaGameMode arenaGameMode, @NotNull Player player) {
|
||||
return !this.playersCompleted.getOrDefault(arenaGameMode, new HashSet<>()).contains(player.getUniqueId());
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers the given player as having completed this arena
|
||||
*
|
||||
* @param player <p>The player that completed this data's arena</p>
|
||||
*/
|
||||
public boolean addCompleted(@NotNull ArenaGameMode arenaGameMode, @NotNull Player player) {
|
||||
// Make sure to add an empty set to prevent a NullPointerException
|
||||
if (!this.playersCompleted.containsKey(arenaGameMode)) {
|
||||
this.playersCompleted.put(arenaGameMode, new HashSet<>());
|
||||
}
|
||||
|
||||
boolean added = this.playersCompleted.get(arenaGameMode).add(player.getUniqueId());
|
||||
// Persistently save the completion
|
||||
if (added) {
|
||||
Dropper.getInstance().getArenaHandler().saveData(this.arenaId);
|
||||
}
|
||||
return added;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Map<String, Object> serialize() {
|
||||
Map<String, Object> data = new HashMap<>();
|
||||
data.put("arenaId", new SerializableUUID(this.arenaId));
|
||||
data.put("recordsRegistry", this.recordRegistries);
|
||||
|
||||
// Convert normal UUIDs to serializable UUIDs
|
||||
Map<ArenaGameMode, Set<SerializableUUID>> serializablePlayersCompleted = new HashMap<>();
|
||||
for (ArenaGameMode arenaGameMode : this.playersCompleted.keySet()) {
|
||||
Set<SerializableUUID> playersCompleted = new HashSet<>();
|
||||
for (UUID playerCompleted : this.playersCompleted.get(arenaGameMode)) {
|
||||
playersCompleted.add(new SerializableUUID(playerCompleted));
|
||||
}
|
||||
serializablePlayersCompleted.put(arenaGameMode, playersCompleted);
|
||||
}
|
||||
data.put("playersCompleted", serializablePlayersCompleted);
|
||||
return data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Deserializes a dropper arena data from the given data
|
||||
*
|
||||
* @param data <p>The data to deserialize</p>
|
||||
* @return <p>The deserialized dropper arena data</p>
|
||||
*/
|
||||
@SuppressWarnings({"unused", "unchecked"})
|
||||
public static @NotNull DropperArenaData deserialize(@NotNull Map<String, Object> data) {
|
||||
SerializableUUID serializableUUID = (SerializableUUID) data.get("arenaId");
|
||||
Map<ArenaGameMode, DropperArenaRecordsRegistry> recordsRegistry =
|
||||
(Map<ArenaGameMode, DropperArenaRecordsRegistry>) data.get("recordsRegistry");
|
||||
Map<ArenaGameMode, Set<SerializableUUID>> playersCompletedData =
|
||||
(Map<ArenaGameMode, Set<SerializableUUID>>) data.get("playersCompleted");
|
||||
|
||||
// Convert the serializable UUIDs to normal UUIDs
|
||||
Map<ArenaGameMode, Set<UUID>> allPlayersCompleted = new HashMap<>();
|
||||
for (ArenaGameMode arenaGameMode : playersCompletedData.keySet()) {
|
||||
Set<UUID> playersCompleted = new HashSet<>();
|
||||
for (SerializableUUID completedId : playersCompletedData.get(arenaGameMode)) {
|
||||
playersCompleted.add(completedId.uuid());
|
||||
}
|
||||
allPlayersCompleted.put(arenaGameMode, playersCompleted);
|
||||
}
|
||||
return new DropperArenaData(serializableUUID.uuid(), recordsRegistry, allPlayersCompleted);
|
||||
}
|
||||
|
||||
}
|
@ -1,61 +0,0 @@
|
||||
package net.knarcraft.dropper.arena;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* A registry to keep track of which players are playing in which arenas
|
||||
*/
|
||||
public class DropperArenaPlayerRegistry {
|
||||
|
||||
private final Map<UUID, DropperArenaSession> arenaPlayers = new HashMap<>();
|
||||
|
||||
/**
|
||||
* Registers that the given player has started playing the given dropper arena session
|
||||
*
|
||||
* @param playerId <p>The id of the player that started playing</p>
|
||||
* @param arena <p>The arena session to register</p>
|
||||
*/
|
||||
public void registerPlayer(@NotNull UUID playerId, @NotNull DropperArenaSession arena) {
|
||||
this.arenaPlayers.put(playerId, arena);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes this player from players currently playing
|
||||
*
|
||||
* @param playerId <p>The id of the player to remove</p>
|
||||
*/
|
||||
public boolean removePlayer(@NotNull UUID playerId) {
|
||||
return this.arenaPlayers.remove(playerId) != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the player's active dropper arena session
|
||||
*
|
||||
* @param playerId <p>The id of the player to get arena for</p>
|
||||
* @return <p>The player's active arena session, or null if not currently playing</p>
|
||||
*/
|
||||
public @Nullable DropperArenaSession getArenaSession(@NotNull UUID playerId) {
|
||||
return this.arenaPlayers.getOrDefault(playerId, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes all active sessions for the given arena
|
||||
*
|
||||
* @param arena <p>The arena to remove sessions for</p>
|
||||
*/
|
||||
public void removeForArena(DropperArena arena) {
|
||||
for (Map.Entry<UUID, DropperArenaSession> entry : this.arenaPlayers.entrySet()) {
|
||||
if (entry.getValue().getArena() == arena) {
|
||||
// Kick the player gracefully
|
||||
entry.getValue().triggerQuit(false);
|
||||
this.arenaPlayers.remove(entry.getKey());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,181 +0,0 @@
|
||||
package net.knarcraft.dropper.arena;
|
||||
|
||||
import net.knarcraft.dropper.Dropper;
|
||||
import net.knarcraft.dropper.container.SerializableUUID;
|
||||
import net.knarcraft.dropper.property.RecordResult;
|
||||
import org.bukkit.configuration.serialization.ConfigurationSerializable;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
/**
|
||||
* A registry keeping track of all records
|
||||
*/
|
||||
public class DropperArenaRecordsRegistry implements ConfigurationSerializable {
|
||||
|
||||
private final UUID arenaId;
|
||||
private final @NotNull Map<UUID, Number> leastDeaths;
|
||||
private final @NotNull Map<UUID, Number> shortestTimeMilliSeconds;
|
||||
|
||||
/**
|
||||
* Instantiates a new empty records registry
|
||||
*/
|
||||
public DropperArenaRecordsRegistry(@NotNull UUID arenaId) {
|
||||
this.arenaId = arenaId;
|
||||
this.leastDeaths = new HashMap<>();
|
||||
this.shortestTimeMilliSeconds = new HashMap<>();
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a new records registry
|
||||
*
|
||||
* @param leastDeaths <p>The existing least death records to use</p>
|
||||
* @param shortestTimeMilliSeconds <p>The existing leash time records to use</p>
|
||||
*/
|
||||
private DropperArenaRecordsRegistry(@NotNull UUID arenaId, @NotNull Map<UUID, Integer> leastDeaths,
|
||||
@NotNull Map<UUID, Long> shortestTimeMilliSeconds) {
|
||||
this.arenaId = arenaId;
|
||||
this.leastDeaths = new HashMap<>(leastDeaths);
|
||||
this.shortestTimeMilliSeconds = new HashMap<>(shortestTimeMilliSeconds);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets all existing death records
|
||||
*
|
||||
* @return <p>Existing death records</p>
|
||||
*/
|
||||
public Map<UUID, Integer> getLeastDeathsRecords() {
|
||||
Map<UUID, Integer> leastDeathRecords = new HashMap<>();
|
||||
for (Map.Entry<UUID, Number> entry : this.leastDeaths.entrySet()) {
|
||||
leastDeathRecords.put(entry.getKey(), entry.getValue().intValue());
|
||||
}
|
||||
return leastDeathRecords;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets all existing time records
|
||||
*
|
||||
* @return <p>Existing time records</p>
|
||||
*/
|
||||
public Map<UUID, Long> getShortestTimeMilliSecondsRecords() {
|
||||
Map<UUID, Long> leastTimeRecords = new HashMap<>();
|
||||
for (Map.Entry<UUID, Number> entry : this.shortestTimeMilliSeconds.entrySet()) {
|
||||
leastTimeRecords.put(entry.getKey(), entry.getValue().longValue());
|
||||
}
|
||||
return leastTimeRecords;
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a new deaths-record
|
||||
*
|
||||
* @param playerId <p>The id of the player that performed the records</p>
|
||||
* @param deaths <p>The number of deaths suffered before the player finished the arena</p>
|
||||
* @return <p>The result explaining what type of record was achieved</p>
|
||||
*/
|
||||
public @NotNull RecordResult registerDeathRecord(@NotNull UUID playerId, int deaths) {
|
||||
return registerRecord(leastDeaths, playerId, deaths);
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a new time-record
|
||||
*
|
||||
* @param playerId <p>The id of the player that performed the records</p>
|
||||
* @param milliseconds <p>The number of milliseconds it took the player to finish the dropper arena</p>
|
||||
* @return <p>The result explaining what type of record was achieved</p>
|
||||
*/
|
||||
public @NotNull RecordResult registerTimeRecord(@NotNull UUID playerId, long milliseconds) {
|
||||
return registerRecord(shortestTimeMilliSeconds, playerId, milliseconds);
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves changed records
|
||||
*/
|
||||
private void save() {
|
||||
Dropper.getInstance().getArenaHandler().saveData(this.arenaId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a new record if applicable
|
||||
*
|
||||
* @param existingRecords <p>The map of existing records to use</p>
|
||||
* @param playerId <p>The id of the player that potentially achieved a record</p>
|
||||
* @param amount <p>The amount of whatever the player achieved</p>
|
||||
* @return <p>The result of the player's record attempt</p>
|
||||
*/
|
||||
private @NotNull RecordResult registerRecord(@NotNull Map<UUID, Number> existingRecords, @NotNull UUID playerId,
|
||||
Number amount) {
|
||||
RecordResult result;
|
||||
Stream<Map.Entry<UUID, Number>> records = existingRecords.entrySet().stream();
|
||||
long amountLong = amount.longValue();
|
||||
|
||||
if (records.allMatch((entry) -> amountLong < entry.getValue().longValue())) {
|
||||
// If the given value is less than all other values, that's a world record!
|
||||
result = RecordResult.WORLD_RECORD;
|
||||
existingRecords.put(playerId, amount);
|
||||
save();
|
||||
} else if (existingRecords.containsKey(playerId) && amountLong < existingRecords.get(playerId).longValue()) {
|
||||
// If the given value is less than the player's previous value, that's a personal best!
|
||||
result = RecordResult.PERSONAL_BEST;
|
||||
existingRecords.put(playerId, amount);
|
||||
save();
|
||||
} else {
|
||||
// Make sure to save the record if this is the user's first attempt
|
||||
if (!existingRecords.containsKey(playerId)) {
|
||||
save();
|
||||
}
|
||||
result = RecordResult.NONE;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Map<String, Object> serialize() {
|
||||
Map<String, Object> data = new HashMap<>();
|
||||
data.put("arenaId", new SerializableUUID(this.arenaId));
|
||||
|
||||
Map<SerializableUUID, Number> leastDeaths = new HashMap<>();
|
||||
for (Map.Entry<UUID, Number> entry : this.leastDeaths.entrySet()) {
|
||||
leastDeaths.put(new SerializableUUID(entry.getKey()), entry.getValue());
|
||||
}
|
||||
data.put("leastDeaths", leastDeaths);
|
||||
|
||||
Map<SerializableUUID, Number> shortestTimeMilliSeconds = new HashMap<>();
|
||||
for (Map.Entry<UUID, Number> entry : this.shortestTimeMilliSeconds.entrySet()) {
|
||||
shortestTimeMilliSeconds.put(new SerializableUUID(entry.getKey()), entry.getValue());
|
||||
}
|
||||
data.put("shortestTime", shortestTimeMilliSeconds);
|
||||
return data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Deserializes the given data
|
||||
*
|
||||
* @param data <p>The data to deserialize</p>
|
||||
* @return <p>The deserialized records registry</p>
|
||||
*/
|
||||
@SuppressWarnings({"unused", "unchecked"})
|
||||
public static DropperArenaRecordsRegistry deserialize(Map<String, Object> data) {
|
||||
UUID arenaId = ((SerializableUUID) data.get("arenaId")).uuid();
|
||||
Map<SerializableUUID, Integer> leastDeathsData =
|
||||
(Map<SerializableUUID, Integer>) data.getOrDefault("leastDeaths", new HashMap<>());
|
||||
Map<UUID, Integer> leastDeaths = new HashMap<>();
|
||||
for (Map.Entry<SerializableUUID, Integer> entry : leastDeathsData.entrySet()) {
|
||||
leastDeaths.put(entry.getKey().uuid(), entry.getValue());
|
||||
}
|
||||
|
||||
Map<SerializableUUID, Number> shortestTimeMillisecondsData =
|
||||
(Map<SerializableUUID, Number>) data.getOrDefault("shortestTime", new HashMap<>());
|
||||
Map<UUID, Long> shortestTimeMilliseconds = new HashMap<>();
|
||||
for (Map.Entry<SerializableUUID, Number> entry : shortestTimeMillisecondsData.entrySet()) {
|
||||
shortestTimeMilliseconds.put(entry.getKey().uuid(), entry.getValue().longValue());
|
||||
}
|
||||
|
||||
return new DropperArenaRecordsRegistry(arenaId, leastDeaths, shortestTimeMilliseconds);
|
||||
}
|
||||
|
||||
}
|
@ -1,197 +0,0 @@
|
||||
package net.knarcraft.dropper.arena;
|
||||
|
||||
import net.knarcraft.dropper.Dropper;
|
||||
import net.knarcraft.dropper.property.ArenaGameMode;
|
||||
import net.knarcraft.dropper.property.RecordResult;
|
||||
import net.knarcraft.dropper.util.PlayerTeleporter;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.logging.Level;
|
||||
|
||||
/**
|
||||
* A representation of a player's current session in a dropper arena
|
||||
*/
|
||||
public class DropperArenaSession {
|
||||
|
||||
private final @NotNull DropperArena arena;
|
||||
private final @NotNull Player player;
|
||||
private final @NotNull ArenaGameMode gameMode;
|
||||
private int deaths;
|
||||
private final long startTime;
|
||||
private final PlayerEntryState entryState;
|
||||
|
||||
/**
|
||||
* Instantiates a new dropper arena session
|
||||
*
|
||||
* @param dropperArena <p>The arena that's being played in</p>
|
||||
* @param player <p>The player playing the arena</p>
|
||||
* @param gameMode <p>The game-mode</p>
|
||||
*/
|
||||
public DropperArenaSession(@NotNull DropperArena dropperArena, @NotNull Player player,
|
||||
@NotNull ArenaGameMode gameMode) {
|
||||
this.arena = dropperArena;
|
||||
this.player = player;
|
||||
this.gameMode = gameMode;
|
||||
this.deaths = 0;
|
||||
this.startTime = System.currentTimeMillis();
|
||||
|
||||
this.entryState = new PlayerEntryState(player, gameMode);
|
||||
// Make the player fly to improve mobility in the air
|
||||
this.entryState.setArenaState(this.arena.getPlayerHorizontalVelocity());
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the game-mode the player is playing in this session
|
||||
*
|
||||
* @return <p>The game-mode for this session</p>
|
||||
*/
|
||||
public @NotNull ArenaGameMode getGameMode() {
|
||||
return this.gameMode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the state of the player when they joined the session
|
||||
*
|
||||
* @return <p>The player's entry state</p>
|
||||
*/
|
||||
public @NotNull PlayerEntryState getEntryState() {
|
||||
return this.entryState;
|
||||
}
|
||||
|
||||
/**
|
||||
* Triggers a win for the player playing in this session
|
||||
*/
|
||||
public void triggerWin() {
|
||||
// Stop this session
|
||||
stopSession();
|
||||
|
||||
// Check for, and display, records
|
||||
registerRecord();
|
||||
|
||||
// Mark the arena as cleared
|
||||
if (this.arena.getData().addCompleted(this.gameMode, this.player)) {
|
||||
this.player.sendMessage("You cleared the arena!");
|
||||
}
|
||||
this.player.sendMessage("You won!");
|
||||
|
||||
// Teleport the player out of the arena
|
||||
teleportToExit(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Teleports the playing player out of the arena
|
||||
*/
|
||||
private void teleportToExit(boolean immediately) {
|
||||
// Teleport the player out of the arena
|
||||
Location exitLocation;
|
||||
if (this.arena.getExitLocation() != null) {
|
||||
exitLocation = this.arena.getExitLocation();
|
||||
} else {
|
||||
exitLocation = this.entryState.getEntryLocation();
|
||||
}
|
||||
PlayerTeleporter.teleportPlayer(this.player, exitLocation, true, immediately);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes this session from current sessions
|
||||
*/
|
||||
private void removeSession() {
|
||||
// Remove this session for game sessions to stop listeners from fiddling more with the player
|
||||
boolean removedSession = Dropper.getInstance().getPlayerRegistry().removePlayer(player.getUniqueId());
|
||||
if (!removedSession) {
|
||||
Dropper.getInstance().getLogger().log(Level.SEVERE, "Unable to remove dropper arena session for " +
|
||||
player.getName() + ". This will have unintended consequences.");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers the player's record if necessary, and prints record information to the player
|
||||
*/
|
||||
private void registerRecord() {
|
||||
DropperArenaRecordsRegistry recordsRegistry = this.arena.getData().recordRegistries().get(this.gameMode);
|
||||
long timeElapsed = System.currentTimeMillis() - this.startTime;
|
||||
announceRecord(recordsRegistry.registerTimeRecord(this.player.getUniqueId(), timeElapsed), "time");
|
||||
announceRecord(recordsRegistry.registerDeathRecord(this.player.getUniqueId(), this.deaths), "least deaths");
|
||||
}
|
||||
|
||||
/**
|
||||
* Announces a record set by this player
|
||||
*
|
||||
* @param recordResult <p>The result of the record</p>
|
||||
* @param type <p>The type of record set (time or deaths)</p>
|
||||
*/
|
||||
private void announceRecord(@NotNull RecordResult recordResult, @NotNull String type) {
|
||||
if (recordResult == RecordResult.NONE) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Gets a string representation of the played game-mode
|
||||
String gameModeString = switch (this.gameMode) {
|
||||
case DEFAULT -> "default";
|
||||
case INVERTED -> "inverted";
|
||||
case RANDOM_INVERTED -> "random";
|
||||
};
|
||||
|
||||
String recordString = "You just set a %s on the %s game-mode!";
|
||||
recordString = switch (recordResult) {
|
||||
case WORLD_RECORD -> String.format(recordString, "new %s record", gameModeString);
|
||||
case PERSONAL_BEST -> String.format(recordString, "personal %s record", gameModeString);
|
||||
default -> throw new IllegalStateException("Unexpected value: " + recordResult);
|
||||
};
|
||||
player.sendMessage(String.format(recordString, type));
|
||||
}
|
||||
|
||||
/**
|
||||
* Triggers a loss for the player playing in this session
|
||||
*/
|
||||
public void triggerLoss() {
|
||||
this.deaths++;
|
||||
//Teleport the player back to the top
|
||||
PlayerTeleporter.teleportPlayer(this.player, this.arena.getSpawnLocation(), true, false);
|
||||
this.entryState.setArenaState(this.arena.getPlayerHorizontalVelocity());
|
||||
}
|
||||
|
||||
/**
|
||||
* Triggers a quit for the player playing in this session
|
||||
*/
|
||||
public void triggerQuit(boolean immediately) {
|
||||
// Stop this session
|
||||
stopSession();
|
||||
// Teleport the player out of the arena
|
||||
teleportToExit(immediately);
|
||||
|
||||
player.sendMessage("You quit the arena!");
|
||||
}
|
||||
|
||||
/**
|
||||
* Stops this session, and disables flight mode
|
||||
*/
|
||||
private void stopSession() {
|
||||
// Remove this session from game sessions to stop listeners from fiddling more with the player
|
||||
removeSession();
|
||||
|
||||
// Remove flight mode
|
||||
entryState.restore();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the arena this session is being played in
|
||||
*
|
||||
* @return <p>The session's arena</p>
|
||||
*/
|
||||
public @NotNull DropperArena getArena() {
|
||||
return this.arena;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the player playing in this session
|
||||
*
|
||||
* @return <p>This session's player</p>
|
||||
*/
|
||||
public @NotNull Player getPlayer() {
|
||||
return this.player;
|
||||
}
|
||||
|
||||
}
|
@ -1,81 +0,0 @@
|
||||
package net.knarcraft.dropper.arena;
|
||||
|
||||
import net.knarcraft.dropper.property.ArenaGameMode;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* The state of a player before entering a dropper arena
|
||||
*/
|
||||
public class PlayerEntryState {
|
||||
|
||||
private final Player player;
|
||||
private final Location entryLocation;
|
||||
private final boolean originalIsFlying;
|
||||
private final float originalFlySpeed;
|
||||
private final GameMode originalGameMode;
|
||||
private final boolean originalAllowFlight;
|
||||
private final boolean originalInvulnerable;
|
||||
private final boolean originalIsSwimming;
|
||||
private final ArenaGameMode arenaGameMode;
|
||||
|
||||
/**
|
||||
* Instantiates a new player state
|
||||
*
|
||||
* @param player <p>The player whose state should be stored</p>
|
||||
*/
|
||||
public PlayerEntryState(@NotNull Player player, @NotNull ArenaGameMode arenaGameMode) {
|
||||
this.player = player;
|
||||
this.entryLocation = player.getLocation().clone();
|
||||
this.originalFlySpeed = player.getFlySpeed();
|
||||
this.originalIsFlying = player.isFlying();
|
||||
this.originalGameMode = player.getGameMode();
|
||||
this.originalAllowFlight = player.getAllowFlight();
|
||||
this.originalInvulnerable = player.isInvulnerable();
|
||||
this.originalIsSwimming = player.isSwimming();
|
||||
this.arenaGameMode = arenaGameMode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the state of the stored player to the state used by arenas
|
||||
*
|
||||
* @param horizontalVelocity <p>The horizontal velocity to apply to the player</p>
|
||||
*/
|
||||
public void setArenaState(float horizontalVelocity) {
|
||||
this.player.setAllowFlight(true);
|
||||
this.player.setFlying(true);
|
||||
this.player.setGameMode(GameMode.ADVENTURE);
|
||||
this.player.setSwimming(false);
|
||||
|
||||
// If playing on the inverted game-mode, negate the horizontal velocity to swap the controls
|
||||
if (arenaGameMode == ArenaGameMode.INVERTED) {
|
||||
this.player.setFlySpeed(-horizontalVelocity);
|
||||
} else {
|
||||
this.player.setFlySpeed(horizontalVelocity);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Restores the stored state for the stored player
|
||||
*/
|
||||
public void restore() {
|
||||
this.player.setFlying(this.originalIsFlying);
|
||||
this.player.setGameMode(this.originalGameMode);
|
||||
this.player.setAllowFlight(this.originalAllowFlight);
|
||||
this.player.setFlySpeed(this.originalFlySpeed);
|
||||
this.player.setInvulnerable(this.originalInvulnerable);
|
||||
this.player.setSwimming(this.originalIsSwimming);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the location the player entered from
|
||||
*
|
||||
* @return <p>The location the player entered from</p>
|
||||
*/
|
||||
public Location getEntryLocation() {
|
||||
return this.entryLocation;
|
||||
}
|
||||
|
||||
}
|
@ -1,33 +0,0 @@
|
||||
package net.knarcraft.dropper.command;
|
||||
|
||||
import net.knarcraft.dropper.util.TabCompleteHelper;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.TabCompleter;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* The tab-completer for the edit arena command
|
||||
*/
|
||||
public class EditArenaTabCompleter implements TabCompleter {
|
||||
|
||||
@Override
|
||||
public @Nullable List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command,
|
||||
@NotNull String label, @NotNull String[] args) {
|
||||
if (args.length == 1) {
|
||||
return TabCompleteHelper.getArenas();
|
||||
} else if (args.length == 2) {
|
||||
return TabCompleteHelper.getArenaProperties();
|
||||
} else if (args.length == 3) {
|
||||
//TODO: Tab-complete possible values for the given property
|
||||
return null;
|
||||
} else {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,133 +0,0 @@
|
||||
package net.knarcraft.dropper.command;
|
||||
|
||||
import net.knarcraft.dropper.Dropper;
|
||||
import net.knarcraft.dropper.arena.DropperArena;
|
||||
import net.knarcraft.dropper.arena.DropperArenaGroup;
|
||||
import net.knarcraft.dropper.arena.DropperArenaPlayerRegistry;
|
||||
import net.knarcraft.dropper.arena.DropperArenaSession;
|
||||
import net.knarcraft.dropper.property.ArenaGameMode;
|
||||
import net.knarcraft.dropper.util.PlayerTeleporter;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* The command used to join a dropper arena
|
||||
*/
|
||||
public class JoinArenaCommand implements CommandExecutor {
|
||||
|
||||
@Override
|
||||
public boolean onCommand(@NotNull CommandSender commandSender, @NotNull Command command, @NotNull String s,
|
||||
@NotNull String[] arguments) {
|
||||
if (!(commandSender instanceof Player player)) {
|
||||
commandSender.sendMessage("This command must be used by a player");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (arguments.length < 1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Disallow joining if the player is already in a dropper arena
|
||||
DropperArenaSession existingSession = Dropper.getInstance().getPlayerRegistry().getArenaSession(player.getUniqueId());
|
||||
if (existingSession != null) {
|
||||
commandSender.sendMessage("You are already in a dropper arena!");
|
||||
return false;
|
||||
}
|
||||
|
||||
// Make sure the arena exists
|
||||
DropperArena specifiedArena = Dropper.getInstance().getArenaHandler().getArena(arguments[0]);
|
||||
if (specifiedArena == null) {
|
||||
commandSender.sendMessage("Unable to find the specified dropper arena.");
|
||||
return false;
|
||||
}
|
||||
|
||||
// Deny vehicles as allowing this is tricky, and will cause problems in some cases
|
||||
if (player.isInsideVehicle() || !player.getPassengers().isEmpty()) {
|
||||
commandSender.sendMessage("You cannot join an arena while inside a vehicle or carrying a passenger.");
|
||||
return false;
|
||||
}
|
||||
|
||||
return joinArena(specifiedArena, player, arguments);
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs the actual arena joining
|
||||
*
|
||||
* @param specifiedArena <p>The arena the player wants to join</p>
|
||||
* @param player <p>The player joining the arena</p>
|
||||
* @param arguments <p>The arguments given</p>
|
||||
* @return <p>Whether the arena was joined successfully</p>
|
||||
*/
|
||||
private boolean joinArena(DropperArena specifiedArena, Player player, String[] arguments) {
|
||||
// Find the specified game-mode
|
||||
ArenaGameMode gameMode;
|
||||
if (arguments.length > 1) {
|
||||
gameMode = ArenaGameMode.matchGamemode(arguments[1]);
|
||||
} else {
|
||||
gameMode = ArenaGameMode.DEFAULT;
|
||||
}
|
||||
|
||||
// Make sure the player has beaten the necessary levels
|
||||
DropperArenaGroup arenaGroup = Dropper.getInstance().getArenaHandler().getGroup(specifiedArena.getArenaId());
|
||||
if (arenaGroup != null && !doGroupChecks(specifiedArena, arenaGroup, gameMode, player)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Make sure the player has beaten the arena once in normal mode before playing another mode
|
||||
if (gameMode != ArenaGameMode.DEFAULT &&
|
||||
specifiedArena.getData().hasNotCompleted(ArenaGameMode.DEFAULT, player)) {
|
||||
player.sendMessage("You must complete this arena in normal mode first!");
|
||||
return false;
|
||||
}
|
||||
|
||||
// Register the player's session
|
||||
DropperArenaSession newSession = new DropperArenaSession(specifiedArena, player, gameMode);
|
||||
DropperArenaPlayerRegistry playerRegistry = Dropper.getInstance().getPlayerRegistry();
|
||||
playerRegistry.registerPlayer(player.getUniqueId(), newSession);
|
||||
|
||||
// Try to teleport the player to the arena
|
||||
boolean teleported = PlayerTeleporter.teleportPlayer(player, specifiedArena.getSpawnLocation(), false, false);
|
||||
if (!teleported) {
|
||||
player.sendMessage("Unable to teleport you to the dropper arena. Make sure you're not in a vehicle," +
|
||||
"and not carrying a passenger!");
|
||||
newSession.triggerQuit(false);
|
||||
return false;
|
||||
} else {
|
||||
// Make sure to update the state again in the air to remove a potential swimming state
|
||||
newSession.getEntryState().setArenaState(specifiedArena.getPlayerHorizontalVelocity());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs necessary check for the given arena's group
|
||||
*
|
||||
* @param dropperArena <p>The arena the player is trying to join</p>
|
||||
* @param arenaGroup <p>The arena group the arena belongs to</p>
|
||||
* @param arenaGameMode <p>The game-mode the player selected</p>
|
||||
* @param player <p>The the player trying to join the arena</p>
|
||||
* @return <p>False if any checks failed</p>
|
||||
*/
|
||||
private boolean doGroupChecks(@NotNull DropperArena dropperArena, @NotNull DropperArenaGroup arenaGroup,
|
||||
@NotNull ArenaGameMode arenaGameMode, @NotNull Player player) {
|
||||
// Require that players beat all arenas in the group in the normal game-mode before trying challenge modes
|
||||
if (arenaGameMode != ArenaGameMode.DEFAULT) {
|
||||
if (!arenaGroup.hasBeatenAll(ArenaGameMode.DEFAULT, player)) {
|
||||
player.sendMessage("You have not yet beaten all arenas in this group!");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Require that the player has beaten the previous arena on the same game-mode before trying this one
|
||||
if (!arenaGroup.canPlay(arenaGameMode, player, dropperArena.getArenaId())) {
|
||||
player.sendMessage("You have not yet beaten the previous arena!");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
@ -1,34 +0,0 @@
|
||||
package net.knarcraft.dropper.command;
|
||||
|
||||
import net.knarcraft.dropper.util.TabCompleteHelper;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.TabCompleter;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* The tab-completer for the join command
|
||||
*/
|
||||
public class JoinArenaTabCompleter implements TabCompleter {
|
||||
|
||||
@Override
|
||||
public @Nullable List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command,
|
||||
@NotNull String label, @NotNull String[] arguments) {
|
||||
if (arguments.length == 1) {
|
||||
return TabCompleteHelper.getArenas();
|
||||
} else if (arguments.length == 2) {
|
||||
List<String> gameModes = new ArrayList<>();
|
||||
gameModes.add("default");
|
||||
gameModes.add("inverted");
|
||||
gameModes.add("random");
|
||||
return gameModes;
|
||||
} else {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,36 +0,0 @@
|
||||
package net.knarcraft.dropper.command;
|
||||
|
||||
import net.knarcraft.dropper.Dropper;
|
||||
import net.knarcraft.dropper.arena.DropperArena;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* The method used for removing an existing arena
|
||||
*/
|
||||
public class RemoveArenaCommand implements CommandExecutor {
|
||||
|
||||
@Override
|
||||
public boolean onCommand(@NotNull CommandSender commandSender, @NotNull Command command, @NotNull String s,
|
||||
@NotNull String[] arguments) {
|
||||
// Abort if no name was specified
|
||||
if (arguments.length < 1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Get the specified arena
|
||||
DropperArena targetArena = Dropper.getInstance().getArenaHandler().getArena(arguments[0]);
|
||||
if (targetArena == null) {
|
||||
commandSender.sendMessage("Unable to find the specified arena");
|
||||
return false;
|
||||
}
|
||||
|
||||
// Remove the arena
|
||||
Dropper.getInstance().getArenaHandler().removeArena(targetArena);
|
||||
commandSender.sendMessage("The specified arena has been successfully removed");
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
@ -1,37 +0,0 @@
|
||||
package net.knarcraft.dropper.container;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.configuration.serialization.ConfigurationSerializable;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* A material container able to be serialized
|
||||
*
|
||||
* @param material <p>The material stored by this record</p>
|
||||
*/
|
||||
public record SerializableMaterial(Material material) implements ConfigurationSerializable {
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Map<String, Object> serialize() {
|
||||
Map<String, Object> data = new HashMap<>();
|
||||
data.put("name", material.name());
|
||||
return data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Deserializes a serialized material
|
||||
*
|
||||
* @param data <p>The serialized data</p>
|
||||
* @return <p>The deserialized material</p>
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public static SerializableMaterial deserialize(Map<String, Object> data) {
|
||||
Material material = Material.matchMaterial((String) data.getOrDefault("name", "AIR"));
|
||||
return new SerializableMaterial(material);
|
||||
}
|
||||
|
||||
}
|
@ -1,39 +0,0 @@
|
||||
package net.knarcraft.dropper.listener;
|
||||
|
||||
import net.knarcraft.dropper.Dropper;
|
||||
import net.knarcraft.dropper.arena.DropperArenaSession;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.EntityDamageEvent;
|
||||
|
||||
/**
|
||||
* A listener for checking if a player takes damage within a dropper arena
|
||||
*/
|
||||
public class DamageListener implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerDamage(EntityDamageEvent event) {
|
||||
// Only player damage matters
|
||||
if (event.getEntityType() != EntityType.PLAYER) {
|
||||
return;
|
||||
}
|
||||
|
||||
Player player = (Player) event.getEntity();
|
||||
|
||||
// We don't care about damage outside arenas
|
||||
DropperArenaSession arenaSession = Dropper.getInstance().getPlayerRegistry().getArenaSession(player.getUniqueId());
|
||||
if (arenaSession == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
event.setCancelled(true);
|
||||
|
||||
// Only trigger a loss when a player suffers fall damage
|
||||
if (event.getCause() == EntityDamageEvent.DamageCause.FALL) {
|
||||
arenaSession.triggerLoss();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,154 +0,0 @@
|
||||
package net.knarcraft.dropper.listener;
|
||||
|
||||
import net.knarcraft.dropper.Dropper;
|
||||
import net.knarcraft.dropper.arena.DropperArenaPlayerRegistry;
|
||||
import net.knarcraft.dropper.arena.DropperArenaSession;
|
||||
import net.knarcraft.dropper.property.ArenaGameMode;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerMoveEvent;
|
||||
import org.bukkit.util.Vector;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Calendar;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* A listener for players moving inside a dropper arena
|
||||
*/
|
||||
public class MoveListener implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerMove(PlayerMoveEvent event) {
|
||||
// Ignore if no actual movement is happening
|
||||
if (event.getFrom().equals(event.getTo()) || event.getTo() == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
Player player = event.getPlayer();
|
||||
DropperArenaPlayerRegistry playerRegistry = Dropper.getInstance().getPlayerRegistry();
|
||||
DropperArenaSession arenaSession = playerRegistry.getArenaSession(player.getUniqueId());
|
||||
if (arenaSession == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Prevent the player from flying upwards while in flight mode
|
||||
if (event.getFrom().getY() < event.getTo().getY()) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// Only do block type checking if the block beneath the player changes
|
||||
if (event.getFrom().getBlock() != event.getTo().getBlock() &&
|
||||
checkForSpecialBlock(arenaSession, event.getTo())) {
|
||||
return;
|
||||
}
|
||||
|
||||
//Updates the player's velocity to the one set by the arena
|
||||
updatePlayerVelocity(arenaSession);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the player in the session is triggering a block with a special significance
|
||||
*
|
||||
* <p>This basically looks for the win block, or whether the player is hitting a solid block.</p>
|
||||
*
|
||||
* @param arenaSession <p>The arena session to check for</p>
|
||||
* @param toLocation <p>The location the player's session is about to hit</p>
|
||||
* @return <p>True if a special block has been hit</p>
|
||||
*/
|
||||
private boolean checkForSpecialBlock(DropperArenaSession arenaSession, Location toLocation) {
|
||||
/* This decides how far inside a non-solid block the player must go before detection triggers. The closer to -1
|
||||
it is, the more accurate it will seem to the player, but the likelihood of not detecting the hit decreases */
|
||||
double liquidDepth = -0.8;
|
||||
/* This decides the distance the player must be from the block below before a hit triggers. If too low, the
|
||||
likelihood of detecting the hit decreases, but the immersion increases. */
|
||||
double solidDepth = 0.2;
|
||||
|
||||
// Check if the player enters water
|
||||
Material winBlockType = arenaSession.getArena().getWinBlockType();
|
||||
// For water, only trigger when the player enters the water, but trigger earlier for everything else
|
||||
double depth = !winBlockType.isSolid() ? liquidDepth : solidDepth;
|
||||
for (Block block : getBlocksBeneathLocation(toLocation, depth)) {
|
||||
if (block.getType() == winBlockType) {
|
||||
arenaSession.triggerWin();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// Check if the player is about to hit a non-air and non-liquid block
|
||||
for (Block block : getBlocksBeneathLocation(toLocation, solidDepth)) {
|
||||
if (!block.getType().isAir() && block.getType() != Material.STRUCTURE_VOID &&
|
||||
block.getType() != Material.WATER && block.getType() != Material.LAVA) {
|
||||
arenaSession.triggerLoss();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the blocks at the given location that will be affected by the player's hit-box
|
||||
*
|
||||
* @param location <p>The location to check</p>
|
||||
* @return <p>The blocks beneath the player</p>
|
||||
*/
|
||||
private Set<Block> getBlocksBeneathLocation(Location location, double depth) {
|
||||
Set<Block> blocksBeneath = new HashSet<>();
|
||||
double halfPlayerWidth = 0.3;
|
||||
blocksBeneath.add(location.clone().subtract(halfPlayerWidth, depth, halfPlayerWidth).getBlock());
|
||||
blocksBeneath.add(location.clone().subtract(-halfPlayerWidth, depth, halfPlayerWidth).getBlock());
|
||||
blocksBeneath.add(location.clone().subtract(halfPlayerWidth, depth, -halfPlayerWidth).getBlock());
|
||||
blocksBeneath.add(location.clone().subtract(-halfPlayerWidth, depth, -halfPlayerWidth).getBlock());
|
||||
return blocksBeneath;
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the velocity of the player in the given session
|
||||
*
|
||||
* @param session <p>The session to update the velocity for</p>
|
||||
*/
|
||||
private void updatePlayerVelocity(@NotNull DropperArenaSession session) {
|
||||
Player player = session.getPlayer();
|
||||
Vector playerVelocity = player.getVelocity();
|
||||
double arenaVelocity = session.getArena().getPlayerVerticalVelocity();
|
||||
Vector newVelocity = new Vector(playerVelocity.getX(), -arenaVelocity, playerVelocity.getZ());
|
||||
player.setVelocity(newVelocity);
|
||||
|
||||
// Toggle the direction of the player's flying, as necessary
|
||||
toggleFlyInversion(session);
|
||||
}
|
||||
|
||||
/**
|
||||
* Toggles the player's flying direction inversion if playing on the random game-mode
|
||||
*
|
||||
* @param session <p>The session to possibly invert flying for</p>
|
||||
*/
|
||||
private void toggleFlyInversion(@NotNull DropperArenaSession session) {
|
||||
if (session.getGameMode() != ArenaGameMode.RANDOM_INVERTED) {
|
||||
return;
|
||||
}
|
||||
Player player = session.getPlayer();
|
||||
float horizontalVelocity = session.getArena().getPlayerHorizontalVelocity();
|
||||
float secondsBetweenToggle = 7;
|
||||
int seconds = Calendar.getInstance().get(Calendar.SECOND);
|
||||
|
||||
/*
|
||||
* A trick to make the inversion change after a customizable amount of seconds
|
||||
* If the quotient of dividing the current number of seconds with the set amount of seconds is even, invert.
|
||||
* So, if the number of seconds between toggles is 5, that would mean for the first 5 seconds, the flying would
|
||||
* be inverted. Once 5 seconds have passed, the quotient becomes 1, which is odd, so the flying is no longer
|
||||
* inverted. After 10 seconds, the quotient is 2, which is even, and inverts the flying.
|
||||
*/
|
||||
boolean invert = Math.floor(seconds / secondsBetweenToggle) % 2 == 0;
|
||||
player.setFlySpeed(invert ? -horizontalVelocity : horizontalVelocity);
|
||||
}
|
||||
|
||||
}
|
@ -1,82 +0,0 @@
|
||||
package net.knarcraft.dropper.listener;
|
||||
|
||||
import net.knarcraft.dropper.Dropper;
|
||||
import net.knarcraft.dropper.arena.DropperArenaSession;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import org.bukkit.event.player.PlayerTeleportEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.logging.Level;
|
||||
|
||||
/**
|
||||
* A listener for players leaving the server or the arena
|
||||
*/
|
||||
public class PlayerLeaveListener implements Listener {
|
||||
|
||||
private final Map<UUID, DropperArenaSession> leftSessions = new HashMap<>();
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerLeave(PlayerQuitEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
DropperArenaSession arenaSession = getSession(player);
|
||||
if (arenaSession == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
Dropper.getInstance().getLogger().log(Level.WARNING, "Found player " + player.getUniqueId() +
|
||||
" leaving in the middle of a session!");
|
||||
leftSessions.put(player.getUniqueId(), arenaSession);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||
UUID playerId = event.getPlayer().getUniqueId();
|
||||
// Force the player to quit from the session once they re-join
|
||||
if (leftSessions.containsKey(playerId)) {
|
||||
Dropper.getInstance().getLogger().log(Level.WARNING, "Found un-exited dropper session!");
|
||||
Bukkit.getScheduler().runTaskLater(Dropper.getInstance(), () -> {
|
||||
leftSessions.get(playerId).triggerQuit(false);
|
||||
Dropper.getInstance().getLogger().log(Level.WARNING, "Triggered a quit!");
|
||||
leftSessions.remove(playerId);
|
||||
}, 80);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerTeleport(PlayerTeleportEvent event) {
|
||||
if (event.getTo() == null || event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
DropperArenaSession arenaSession = getSession(event.getPlayer());
|
||||
if (arenaSession == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (event.getTo().equals(arenaSession.getArena().getSpawnLocation())) {
|
||||
return;
|
||||
}
|
||||
|
||||
arenaSession.triggerQuit(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the arena session for the given player
|
||||
*
|
||||
* @param player <p>The player to get the arena session for</p>
|
||||
* @return <p>The player's session, or null if not in a session</p>
|
||||
*/
|
||||
private @Nullable DropperArenaSession getSession(@NotNull Player player) {
|
||||
return Dropper.getInstance().getPlayerRegistry().getArenaSession(player.getUniqueId());
|
||||
}
|
||||
|
||||
}
|
@ -1,234 +0,0 @@
|
||||
package net.knarcraft.dropper.util;
|
||||
|
||||
import net.knarcraft.dropper.Dropper;
|
||||
import net.knarcraft.dropper.arena.DropperArena;
|
||||
import net.knarcraft.dropper.arena.DropperArenaData;
|
||||
import net.knarcraft.dropper.arena.DropperArenaGroup;
|
||||
import net.knarcraft.dropper.arena.DropperArenaRecordsRegistry;
|
||||
import net.knarcraft.dropper.container.SerializableMaterial;
|
||||
import net.knarcraft.dropper.container.SerializableUUID;
|
||||
import net.knarcraft.dropper.property.ArenaGameMode;
|
||||
import net.knarcraft.dropper.property.ArenaStorageKey;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.logging.Level;
|
||||
|
||||
/**
|
||||
* A helper class for saving and loading arenas
|
||||
*/
|
||||
public final class ArenaStorageHelper {
|
||||
|
||||
private final static String arenasConfigurationSection = "arenas";
|
||||
private final static String groupsConfigurationSection = "groups";
|
||||
private static final File arenaFile = new File(Dropper.getInstance().getDataFolder(), "arenas.yml");
|
||||
private static final File groupFile = new File(Dropper.getInstance().getDataFolder(), "groups.yml");
|
||||
private static final File arenaDataFolder = new File(Dropper.getInstance().getDataFolder(), "arena_data");
|
||||
|
||||
private ArenaStorageHelper() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves the given dropper arena groups
|
||||
*
|
||||
* @param arenaGroups <p>The arena groups to save</p>
|
||||
* @throws IOException <p>If unable to write to the file</p>
|
||||
*/
|
||||
public static void saveDropperArenaGroups(@NotNull Set<DropperArenaGroup> arenaGroups) throws IOException {
|
||||
YamlConfiguration configuration = new YamlConfiguration();
|
||||
ConfigurationSection groupSection = configuration.createSection(groupsConfigurationSection);
|
||||
|
||||
for (DropperArenaGroup arenaGroup : arenaGroups) {
|
||||
groupSection.set(arenaGroup.getGroupId().toString(), arenaGroup);
|
||||
}
|
||||
|
||||
configuration.save(groupFile);
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads all existing dropper arena groups
|
||||
*
|
||||
* @return <p>The loaded arena groups</p>
|
||||
*/
|
||||
public static @NotNull Set<DropperArenaGroup> loadDropperArenaGroups() {
|
||||
YamlConfiguration configuration = YamlConfiguration.loadConfiguration(groupFile);
|
||||
ConfigurationSection groupSection = configuration.getConfigurationSection(groupsConfigurationSection);
|
||||
//If no such section exists, it must be the case that there is no data to load
|
||||
if (groupSection == null) {
|
||||
return new HashSet<>();
|
||||
}
|
||||
|
||||
Set<DropperArenaGroup> arenaGroups = new HashSet<>();
|
||||
|
||||
for (String sectionName : groupSection.getKeys(false)) {
|
||||
arenaGroups.add((DropperArenaGroup) groupSection.get(sectionName));
|
||||
}
|
||||
|
||||
return arenaGroups;
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves the given arenas
|
||||
*
|
||||
* @param arenas <p>The arenas to save</p>
|
||||
* @throws IOException <p>If unable to write to the file</p>
|
||||
*/
|
||||
public static void saveArenas(@NotNull Map<UUID, DropperArena> arenas) throws IOException {
|
||||
YamlConfiguration configuration = new YamlConfiguration();
|
||||
ConfigurationSection arenaSection = configuration.createSection(arenasConfigurationSection);
|
||||
for (DropperArena arena : arenas.values()) {
|
||||
//Note: While the arena name is used as the key, as the key has to be sanitized, the un-sanitized arena name
|
||||
// must be stored as well
|
||||
@NotNull ConfigurationSection configSection = arenaSection.createSection(arena.getArenaId().toString());
|
||||
configSection.set(ArenaStorageKey.ID.getKey(), new SerializableUUID(arena.getArenaId()));
|
||||
configSection.set(ArenaStorageKey.NAME.getKey(), arena.getArenaName());
|
||||
configSection.set(ArenaStorageKey.SPAWN_LOCATION.getKey(), arena.getSpawnLocation());
|
||||
configSection.set(ArenaStorageKey.EXIT_LOCATION.getKey(), arena.getExitLocation());
|
||||
configSection.set(ArenaStorageKey.PLAYER_VERTICAL_VELOCITY.getKey(), arena.getPlayerVerticalVelocity());
|
||||
configSection.set(ArenaStorageKey.PLAYER_HORIZONTAL_VELOCITY.getKey(), arena.getPlayerHorizontalVelocity());
|
||||
configSection.set(ArenaStorageKey.WIN_BLOCK_TYPE.getKey(), new SerializableMaterial(arena.getWinBlockType()));
|
||||
saveArenaData(arena.getData());
|
||||
}
|
||||
configuration.save(arenaFile);
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads all arenas
|
||||
*
|
||||
* @return <p>The loaded arenas, or null if the arenas configuration section is missing.</p>
|
||||
*/
|
||||
public static @NotNull Map<UUID, DropperArena> loadArenas() {
|
||||
YamlConfiguration configuration = YamlConfiguration.loadConfiguration(arenaFile);
|
||||
ConfigurationSection arenaSection = configuration.getConfigurationSection(arenasConfigurationSection);
|
||||
//If no such section exists, it must be the case that there is no data to load
|
||||
if (arenaSection == null) {
|
||||
return new HashMap<>();
|
||||
}
|
||||
|
||||
Map<UUID, DropperArena> loadedArenas = new HashMap<>();
|
||||
|
||||
for (String sectionName : arenaSection.getKeys(false)) {
|
||||
ConfigurationSection configurationSection = arenaSection.getConfigurationSection(sectionName);
|
||||
//I'm not sure whether this could actually happen
|
||||
if (configurationSection == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
DropperArena arena = loadArena(configurationSection);
|
||||
if (arena != null) {
|
||||
loadedArenas.put(arena.getArenaId(), arena);
|
||||
}
|
||||
}
|
||||
|
||||
return loadedArenas;
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads an arena from the given configuration section
|
||||
*
|
||||
* @param configurationSection <p>The configuration section containing arena data</p>
|
||||
* @return <p>The loaded arena, or null if invalid</p>
|
||||
*/
|
||||
private static @Nullable DropperArena loadArena(@NotNull ConfigurationSection configurationSection) {
|
||||
UUID arenaId = ((SerializableUUID) configurationSection.get(ArenaStorageKey.ID.getKey(),
|
||||
new SerializableUUID(UUID.randomUUID()))).uuid();
|
||||
String arenaName = configurationSection.getString(ArenaStorageKey.NAME.getKey());
|
||||
Location spawnLocation = (Location) configurationSection.get(ArenaStorageKey.SPAWN_LOCATION.getKey());
|
||||
Location exitLocation = (Location) configurationSection.get(ArenaStorageKey.EXIT_LOCATION.getKey());
|
||||
double verticalVelocity = configurationSection.getDouble(ArenaStorageKey.PLAYER_VERTICAL_VELOCITY.getKey());
|
||||
float horizontalVelocity = sanitizeHorizontalVelocity((float) configurationSection.getDouble(
|
||||
ArenaStorageKey.PLAYER_HORIZONTAL_VELOCITY.getKey()));
|
||||
SerializableMaterial winBlockType = (SerializableMaterial) configurationSection.get(
|
||||
ArenaStorageKey.WIN_BLOCK_TYPE.getKey());
|
||||
|
||||
if (arenaName == null || spawnLocation == null) {
|
||||
Dropper.getInstance().getLogger().log(Level.SEVERE, "Could not load the arena at configuration " +
|
||||
"section " + configurationSection.getName() + ". Please check the arenas storage file for issues.");
|
||||
return null;
|
||||
}
|
||||
if (winBlockType == null) {
|
||||
winBlockType = new SerializableMaterial(Material.WATER);
|
||||
}
|
||||
|
||||
DropperArenaData arenaData = loadArenaData(arenaId);
|
||||
if (arenaData == null) {
|
||||
Dropper.getInstance().getLogger().log(Level.SEVERE, "Unable to load arena data for " + arenaId);
|
||||
|
||||
Map<ArenaGameMode, DropperArenaRecordsRegistry> recordRegistries = new HashMap<>();
|
||||
for (ArenaGameMode arenaGameMode : ArenaGameMode.values()) {
|
||||
recordRegistries.put(arenaGameMode, new DropperArenaRecordsRegistry(arenaId));
|
||||
}
|
||||
arenaData = new DropperArenaData(arenaId, recordRegistries, new HashMap<>());
|
||||
}
|
||||
|
||||
return new DropperArena(arenaId, arenaName, spawnLocation, exitLocation, verticalVelocity, horizontalVelocity,
|
||||
winBlockType.material(), arenaData);
|
||||
}
|
||||
|
||||
/**
|
||||
* Stores the given arena data to a file
|
||||
*
|
||||
* @param arenaData <p>The arena data to store</p>
|
||||
*/
|
||||
public static void saveArenaData(@NotNull DropperArenaData arenaData) throws IOException {
|
||||
YamlConfiguration configuration = new YamlConfiguration();
|
||||
configuration.set(ArenaStorageKey.DATA.getKey(), arenaData);
|
||||
|
||||
configuration.save(getArenaDataFile(arenaData.arenaId()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads arena data for the given arena id
|
||||
*
|
||||
* @param arenaId <p>The id of the arena to get data for</p>
|
||||
* @return <p>The loaded arena data</p>
|
||||
*/
|
||||
private static @Nullable DropperArenaData loadArenaData(@NotNull UUID arenaId) {
|
||||
File arenaDataFile = getArenaDataFile(arenaId);
|
||||
YamlConfiguration configuration = YamlConfiguration.loadConfiguration(arenaDataFile);
|
||||
return (DropperArenaData) configuration.get(ArenaStorageKey.DATA.getKey());
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the file used to store the given arena id's data
|
||||
*
|
||||
* @param arenaId <p>The id of the arena to get a data file for</p>
|
||||
* @return <p>The file the arena's data is/should be stored in</p>
|
||||
*/
|
||||
private static @NotNull File getArenaDataFile(@NotNull UUID arenaId) {
|
||||
File arenaDataFile = new File(arenaDataFolder, arenaId + ".yml");
|
||||
if (!arenaDataFolder.exists() && !arenaDataFolder.mkdirs()) {
|
||||
Dropper.getInstance().getLogger().log(Level.SEVERE, "Unable to create the arena data directories");
|
||||
}
|
||||
return arenaDataFile;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sanitizes the given horizontal velocity to make sure it doesn't leave its bounds
|
||||
*
|
||||
* @param horizontalVelocity <p>The horizontal velocity to sanitize</p>
|
||||
* @return <p>The sanitized horizontal velocity</p>
|
||||
*/
|
||||
private static float sanitizeHorizontalVelocity(float horizontalVelocity) {
|
||||
if (horizontalVelocity < -1) {
|
||||
return -1;
|
||||
} else if (horizontalVelocity > 1) {
|
||||
return 1;
|
||||
} else {
|
||||
return horizontalVelocity;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,46 +0,0 @@
|
||||
package net.knarcraft.dropper.util;
|
||||
|
||||
import net.knarcraft.dropper.Dropper;
|
||||
import net.knarcraft.dropper.arena.DropperArena;
|
||||
import net.knarcraft.dropper.property.ArenaEditableProperty;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* A helper-class for common tab-completions
|
||||
*/
|
||||
public final class TabCompleteHelper {
|
||||
|
||||
private TabCompleteHelper() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the names of all current arenas
|
||||
*
|
||||
* @return <p>All arena names</p>
|
||||
*/
|
||||
public static @NotNull List<String> getArenas() {
|
||||
List<String> arenaNames = new ArrayList<>();
|
||||
for (DropperArena dropperArena : Dropper.getInstance().getArenaHandler().getArenas().values()) {
|
||||
arenaNames.add(dropperArena.getArenaName());
|
||||
}
|
||||
return arenaNames;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the argument strings of all arena properties
|
||||
*
|
||||
* @return <p>All arena properties</p>
|
||||
*/
|
||||
public static @NotNull List<String> getArenaProperties() {
|
||||
List<String> arenaProperties = new ArrayList<>();
|
||||
for (ArenaEditableProperty property : ArenaEditableProperty.values()) {
|
||||
arenaProperties.add(property.getArgumentString());
|
||||
}
|
||||
return arenaProperties;
|
||||
}
|
||||
|
||||
}
|
469
src/main/java/net/knarcraft/minigames/MiniGames.java
Normal file
469
src/main/java/net/knarcraft/minigames/MiniGames.java
Normal file
@ -0,0 +1,469 @@
|
||||
package net.knarcraft.minigames;
|
||||
|
||||
import net.knarcraft.knargui.GUIListener;
|
||||
import net.knarcraft.knarlib.formatting.StringFormatter;
|
||||
import net.knarcraft.knarlib.formatting.Translator;
|
||||
import net.knarcraft.knarlib.property.ColorConversion;
|
||||
import net.knarcraft.minigames.arena.ArenaPlayerRegistry;
|
||||
import net.knarcraft.minigames.arena.ArenaSession;
|
||||
import net.knarcraft.minigames.arena.PlayerVisibilityManager;
|
||||
import net.knarcraft.minigames.arena.dropper.DropperArena;
|
||||
import net.knarcraft.minigames.arena.dropper.DropperArenaData;
|
||||
import net.knarcraft.minigames.arena.dropper.DropperArenaGameMode;
|
||||
import net.knarcraft.minigames.arena.dropper.DropperArenaGroup;
|
||||
import net.knarcraft.minigames.arena.dropper.DropperArenaHandler;
|
||||
import net.knarcraft.minigames.arena.dropper.DropperArenaPlayerRegistry;
|
||||
import net.knarcraft.minigames.arena.dropper.DropperArenaRecordsRegistry;
|
||||
import net.knarcraft.minigames.arena.dropper.DropperPlayerEntryState;
|
||||
import net.knarcraft.minigames.arena.parkour.ParkourArena;
|
||||
import net.knarcraft.minigames.arena.parkour.ParkourArenaData;
|
||||
import net.knarcraft.minigames.arena.parkour.ParkourArenaGameMode;
|
||||
import net.knarcraft.minigames.arena.parkour.ParkourArenaGroup;
|
||||
import net.knarcraft.minigames.arena.parkour.ParkourArenaHandler;
|
||||
import net.knarcraft.minigames.arena.parkour.ParkourArenaPlayerRegistry;
|
||||
import net.knarcraft.minigames.arena.parkour.ParkourArenaRecordsRegistry;
|
||||
import net.knarcraft.minigames.arena.parkour.ParkourPlayerEntryState;
|
||||
import net.knarcraft.minigames.arena.record.IntegerRecord;
|
||||
import net.knarcraft.minigames.arena.record.LongRecord;
|
||||
import net.knarcraft.minigames.arena.reward.CommandReward;
|
||||
import net.knarcraft.minigames.arena.reward.EconomyReward;
|
||||
import net.knarcraft.minigames.arena.reward.ItemReward;
|
||||
import net.knarcraft.minigames.arena.reward.PermissionReward;
|
||||
import net.knarcraft.minigames.arena.reward.RewardCondition;
|
||||
import net.knarcraft.minigames.command.LeaveArenaCommand;
|
||||
import net.knarcraft.minigames.command.MenuCommand;
|
||||
import net.knarcraft.minigames.command.ReloadCommand;
|
||||
import net.knarcraft.minigames.command.SetArenaRewardCommand;
|
||||
import net.knarcraft.minigames.command.SetArenaRewardTabCompleter;
|
||||
import net.knarcraft.minigames.command.dropper.CreateDropperArenaCommand;
|
||||
import net.knarcraft.minigames.command.dropper.DropperGroupListCommand;
|
||||
import net.knarcraft.minigames.command.dropper.DropperGroupSetCommand;
|
||||
import net.knarcraft.minigames.command.dropper.DropperGroupSwapCommand;
|
||||
import net.knarcraft.minigames.command.dropper.EditDropperArenaCommand;
|
||||
import net.knarcraft.minigames.command.dropper.EditDropperArenaTabCompleter;
|
||||
import net.knarcraft.minigames.command.dropper.JoinDropperArenaCommand;
|
||||
import net.knarcraft.minigames.command.dropper.JoinDropperArenaTabCompleter;
|
||||
import net.knarcraft.minigames.command.dropper.ListDropperArenaCommand;
|
||||
import net.knarcraft.minigames.command.dropper.RemoveDropperArenaCommand;
|
||||
import net.knarcraft.minigames.command.dropper.RemoveDropperArenaTabCompleter;
|
||||
import net.knarcraft.minigames.command.parkour.CreateParkourArenaCommand;
|
||||
import net.knarcraft.minigames.command.parkour.EditParkourArenaCommand;
|
||||
import net.knarcraft.minigames.command.parkour.EditParkourArenaTabCompleter;
|
||||
import net.knarcraft.minigames.command.parkour.JoinParkourArenaCommand;
|
||||
import net.knarcraft.minigames.command.parkour.JoinParkourArenaTabCompleter;
|
||||
import net.knarcraft.minigames.command.parkour.ListParkourArenaCommand;
|
||||
import net.knarcraft.minigames.command.parkour.ParkourGroupListCommand;
|
||||
import net.knarcraft.minigames.command.parkour.ParkourGroupSetCommand;
|
||||
import net.knarcraft.minigames.command.parkour.ParkourGroupSwapCommand;
|
||||
import net.knarcraft.minigames.command.parkour.RemoveParkourArenaCommand;
|
||||
import net.knarcraft.minigames.command.parkour.RemoveParkourArenaTabCompleter;
|
||||
import net.knarcraft.minigames.config.DropperConfiguration;
|
||||
import net.knarcraft.minigames.config.MiniGameMessage;
|
||||
import net.knarcraft.minigames.config.ParkourConfiguration;
|
||||
import net.knarcraft.minigames.config.SharedConfiguration;
|
||||
import net.knarcraft.minigames.container.SerializableMaterial;
|
||||
import net.knarcraft.minigames.container.SerializableUUID;
|
||||
import net.knarcraft.minigames.listener.CommandListener;
|
||||
import net.knarcraft.minigames.listener.DamageListener;
|
||||
import net.knarcraft.minigames.listener.InteractListener;
|
||||
import net.knarcraft.minigames.listener.MoveListener;
|
||||
import net.knarcraft.minigames.listener.PlayerStateChangeListener;
|
||||
import net.knarcraft.minigames.manager.EconomyManager;
|
||||
import net.knarcraft.minigames.manager.PermissionManager;
|
||||
import net.knarcraft.minigames.placeholder.DropperRecordExpansion;
|
||||
import net.knarcraft.minigames.placeholder.ParkourRecordExpansion;
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
import net.milkbowl.vault.economy.Economy;
|
||||
import net.milkbowl.vault.permission.Permission;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.PluginCommand;
|
||||
import org.bukkit.command.TabCompleter;
|
||||
import org.bukkit.configuration.serialization.ConfigurationSerialization;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||
import org.bukkit.plugin.ServicesManager;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.UUID;
|
||||
import java.util.logging.Level;
|
||||
|
||||
/**
|
||||
* The dropper plugin's main class
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public final class MiniGames extends JavaPlugin {
|
||||
|
||||
private static MiniGames instance;
|
||||
private SharedConfiguration sharedConfiguration;
|
||||
private DropperConfiguration dropperConfiguration;
|
||||
private ParkourConfiguration parkourConfiguration;
|
||||
private DropperArenaHandler dropperArenaHandler;
|
||||
private ArenaPlayerRegistry<DropperArena> dropperArenaPlayerRegistry;
|
||||
private DropperRecordExpansion dropperRecordExpansion;
|
||||
private ParkourRecordExpansion parkourRecordExpansion;
|
||||
private ParkourArenaHandler parkourArenaHandler;
|
||||
private ArenaPlayerRegistry<ParkourArena> parkourArenaPlayerRegistry;
|
||||
private PlayerVisibilityManager playerVisibilityManager;
|
||||
private Translator translator;
|
||||
private StringFormatter stringFormatter;
|
||||
|
||||
/**
|
||||
* Gets an instance of this plugin
|
||||
*
|
||||
* @return <p>An instance of this plugin, or null if not initialized yet.</p>
|
||||
*/
|
||||
public static MiniGames getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the dropper arena handler for this instance
|
||||
*
|
||||
* @return <p>A dropper arena handler</p>
|
||||
*/
|
||||
public DropperArenaHandler getDropperArenaHandler() {
|
||||
return this.dropperArenaHandler;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the parkour arena handler for this instance
|
||||
*
|
||||
* @return <p>A parkour arena handler</p>
|
||||
*/
|
||||
public ParkourArenaHandler getParkourArenaHandler() {
|
||||
return this.parkourArenaHandler;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the dropper arena player registry for this instance
|
||||
*
|
||||
* @return <p>A dropper arena player registry</p>
|
||||
*/
|
||||
public ArenaPlayerRegistry<DropperArena> getDropperArenaPlayerRegistry() {
|
||||
return this.dropperArenaPlayerRegistry;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the parkour arena player registry for this instance
|
||||
*
|
||||
* @return <p>A parkour arena player registry</p>
|
||||
*/
|
||||
public ArenaPlayerRegistry<ParkourArena> getParkourArenaPlayerRegistry() {
|
||||
return this.parkourArenaPlayerRegistry;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the shared configuration
|
||||
*
|
||||
* <p>The configuration for options which don't affect specific types of mini-games.</p>
|
||||
*
|
||||
* @return <p>The shared configuration</p>
|
||||
*/
|
||||
public SharedConfiguration getSharedConfiguration() {
|
||||
return this.sharedConfiguration;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the dropper configuration
|
||||
*
|
||||
* @return <p>The dropper configuration</p>
|
||||
*/
|
||||
public DropperConfiguration getDropperConfiguration() {
|
||||
return this.dropperConfiguration;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the parkour configuration
|
||||
*
|
||||
* @return <p>The parkour configuration</p>
|
||||
*/
|
||||
public ParkourConfiguration getParkourConfiguration() {
|
||||
return this.parkourConfiguration;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the manager keeping track of player visibility
|
||||
*
|
||||
* @return <p>The player visibility manager</p>
|
||||
*/
|
||||
public PlayerVisibilityManager getPlayerVisibilityManager() {
|
||||
return this.playerVisibilityManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the translator to get messages from
|
||||
*
|
||||
* @return <p>The translator</p>
|
||||
*/
|
||||
public Translator getTranslator() {
|
||||
return this.translator;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the string formatter to get formatted messages from
|
||||
*
|
||||
* @return <p>The string formatter</p>
|
||||
*/
|
||||
public StringFormatter getStringFormatter() {
|
||||
return this.stringFormatter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the current session of the given player
|
||||
*
|
||||
* @param playerId <p>The id of the player to get a session for</p>
|
||||
* @return <p>The player's current session, or null if not found</p>
|
||||
*/
|
||||
public @Nullable ArenaSession getSession(@NotNull UUID playerId) {
|
||||
ArenaSession dropperArenaSession = dropperArenaPlayerRegistry.getArenaSession(playerId);
|
||||
if (dropperArenaSession != null) {
|
||||
return dropperArenaSession;
|
||||
}
|
||||
|
||||
return parkourArenaPlayerRegistry.getArenaSession(playerId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Logs a message
|
||||
*
|
||||
* @param level <p>The message level to log at</p>
|
||||
* @param message <p>The message to log</p>
|
||||
*/
|
||||
public static void log(Level level, String message) {
|
||||
MiniGames.getInstance().getLogger().log(level, message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reloads all configurations and data from disk
|
||||
*/
|
||||
public void reload() {
|
||||
// Load all arenas again
|
||||
this.dropperArenaHandler.load();
|
||||
this.parkourArenaHandler.load();
|
||||
|
||||
// Reload configuration
|
||||
this.reloadConfig();
|
||||
translator.loadLanguages(this.getDataFolder(), "en",
|
||||
getConfig().getString("language", "en"));
|
||||
this.sharedConfiguration.load(this.getConfig());
|
||||
this.dropperConfiguration.load(this.getConfig());
|
||||
this.parkourConfiguration.load(this.getConfig());
|
||||
|
||||
// Clear record caches
|
||||
this.dropperRecordExpansion.clearCaches();
|
||||
this.parkourRecordExpansion.clearCaches();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoad() {
|
||||
super.onLoad();
|
||||
// Register serialization classes
|
||||
ConfigurationSerialization.registerClass(SerializableMaterial.class);
|
||||
ConfigurationSerialization.registerClass(DropperArenaRecordsRegistry.class);
|
||||
ConfigurationSerialization.registerClass(SerializableUUID.class);
|
||||
ConfigurationSerialization.registerClass(DropperArenaData.class);
|
||||
ConfigurationSerialization.registerClass(DropperArenaGroup.class);
|
||||
ConfigurationSerialization.registerClass(DropperArenaGameMode.class);
|
||||
ConfigurationSerialization.registerClass(LongRecord.class);
|
||||
ConfigurationSerialization.registerClass(IntegerRecord.class);
|
||||
ConfigurationSerialization.registerClass(ParkourArenaRecordsRegistry.class);
|
||||
ConfigurationSerialization.registerClass(ParkourArenaData.class);
|
||||
ConfigurationSerialization.registerClass(ParkourArenaGroup.class);
|
||||
ConfigurationSerialization.registerClass(ParkourArenaGameMode.class);
|
||||
ConfigurationSerialization.registerClass(DropperPlayerEntryState.class);
|
||||
ConfigurationSerialization.registerClass(ParkourPlayerEntryState.class);
|
||||
ConfigurationSerialization.registerClass(CommandReward.class);
|
||||
ConfigurationSerialization.registerClass(EconomyReward.class);
|
||||
ConfigurationSerialization.registerClass(ItemReward.class);
|
||||
ConfigurationSerialization.registerClass(PermissionReward.class);
|
||||
ConfigurationSerialization.registerClass(RewardCondition.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
// Plugin startup logic
|
||||
instance = this;
|
||||
|
||||
// Load configuration
|
||||
loadConfiguration();
|
||||
|
||||
// Register all listeners
|
||||
registerListeners();
|
||||
|
||||
// Register all commands
|
||||
registerCommands();
|
||||
|
||||
// Integrate with other plugins
|
||||
doPluginIntegration();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
// Kill all sessions before exiting
|
||||
for (DropperArena arena : dropperArenaHandler.getArenas().values()) {
|
||||
dropperArenaPlayerRegistry.removeForArena(arena, true);
|
||||
}
|
||||
for (ParkourArena arena : parkourArenaHandler.getArenas().values()) {
|
||||
parkourArenaPlayerRegistry.removeForArena(arena, true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets up integration with third-party plugins
|
||||
*/
|
||||
private void doPluginIntegration() {
|
||||
if (Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null) {
|
||||
this.dropperRecordExpansion = new DropperRecordExpansion(this);
|
||||
if (!this.dropperRecordExpansion.register()) {
|
||||
log(Level.WARNING, "Unable to register PlaceholderAPI dropper expansion!");
|
||||
}
|
||||
this.parkourRecordExpansion = new ParkourRecordExpansion(this);
|
||||
if (!this.parkourRecordExpansion.register()) {
|
||||
log(Level.WARNING, "Unable to register PlaceholderAPI parkour expansion!");
|
||||
}
|
||||
}
|
||||
if (Bukkit.getPluginManager().getPlugin("Vault") != null) {
|
||||
setupVault();
|
||||
} else {
|
||||
log(Level.WARNING, "Vault not found. Economy and Permission rewards are unavailable.");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads all configuration values used by this plugin
|
||||
*/
|
||||
private void loadConfiguration() {
|
||||
this.saveDefaultConfig();
|
||||
getConfig().options().copyDefaults(true);
|
||||
saveConfig();
|
||||
reloadConfig();
|
||||
|
||||
setupStringFormatter();
|
||||
|
||||
this.sharedConfiguration = new SharedConfiguration(this.getConfig());
|
||||
this.dropperConfiguration = new DropperConfiguration(this.getConfig());
|
||||
this.parkourConfiguration = new ParkourConfiguration(this.getConfig());
|
||||
this.dropperArenaPlayerRegistry = new DropperArenaPlayerRegistry();
|
||||
this.dropperArenaHandler = new DropperArenaHandler(this.dropperArenaPlayerRegistry);
|
||||
this.dropperArenaHandler.load();
|
||||
this.parkourArenaPlayerRegistry = new ParkourArenaPlayerRegistry();
|
||||
this.parkourArenaHandler = new ParkourArenaHandler(this.parkourArenaPlayerRegistry);
|
||||
this.parkourArenaHandler.load();
|
||||
this.playerVisibilityManager = new PlayerVisibilityManager();
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers all listeners used by this plugin
|
||||
*/
|
||||
private void registerListeners() {
|
||||
PluginManager pluginManager = getServer().getPluginManager();
|
||||
pluginManager.registerEvents(new DamageListener(), this);
|
||||
pluginManager.registerEvents(new MoveListener(this.dropperConfiguration, this.parkourConfiguration), this);
|
||||
pluginManager.registerEvents(new PlayerStateChangeListener(), this);
|
||||
pluginManager.registerEvents(new CommandListener(), this);
|
||||
pluginManager.registerEvents(new GUIListener(true), this);
|
||||
pluginManager.registerEvents(new InteractListener(), this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a command
|
||||
*
|
||||
* @param commandName <p>The name of the command to register (defined in plugin.yml)</p>
|
||||
* @param commandExecutor <p>The executor for the command</p>
|
||||
* @param tabCompleter <p>The tab-completer to use, or null</p>
|
||||
*/
|
||||
private void registerCommand(@NotNull String commandName, @NotNull CommandExecutor commandExecutor,
|
||||
@Nullable TabCompleter tabCompleter) {
|
||||
PluginCommand command = this.getCommand(commandName);
|
||||
if (command != null) {
|
||||
command.setExecutor(commandExecutor);
|
||||
if (tabCompleter != null) {
|
||||
command.setTabCompleter(tabCompleter);
|
||||
}
|
||||
} else {
|
||||
log(Level.SEVERE, "Unable to register the command " + commandName);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers all commands used by this plugin
|
||||
*/
|
||||
private void registerCommands() {
|
||||
registerCommand("miniGamesReload", new ReloadCommand(), null);
|
||||
registerCommand("miniGamesLeave", new LeaveArenaCommand(), null);
|
||||
registerCommand("miniGamesMenu", new MenuCommand(), null);
|
||||
registerCommand("miniGamesReward", new SetArenaRewardCommand(), new SetArenaRewardTabCompleter());
|
||||
|
||||
registerDropperCommands();
|
||||
registerParkourCommands();
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers all commands related to droppers
|
||||
*/
|
||||
private void registerDropperCommands() {
|
||||
registerCommand("dropperCreate", new CreateDropperArenaCommand(), null);
|
||||
registerCommand("dropperList", new ListDropperArenaCommand(), null);
|
||||
registerCommand("dropperJoin", new JoinDropperArenaCommand(), new JoinDropperArenaTabCompleter());
|
||||
registerCommand("dropperEdit", new EditDropperArenaCommand(this.dropperConfiguration), new EditDropperArenaTabCompleter());
|
||||
registerCommand("dropperRemove", new RemoveDropperArenaCommand(), new RemoveDropperArenaTabCompleter());
|
||||
registerCommand("dropperGroupSet", new DropperGroupSetCommand(), null);
|
||||
registerCommand("dropperGroupSwap", new DropperGroupSwapCommand(), null);
|
||||
registerCommand("dropperGroupList", new DropperGroupListCommand(), null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers all commands related to parkour
|
||||
*/
|
||||
private void registerParkourCommands() {
|
||||
registerCommand("parkourCreate", new CreateParkourArenaCommand(), null);
|
||||
registerCommand("parkourList", new ListParkourArenaCommand(), null);
|
||||
registerCommand("parkourJoin", new JoinParkourArenaCommand(), new JoinParkourArenaTabCompleter());
|
||||
registerCommand("parkourEdit", new EditParkourArenaCommand(), new EditParkourArenaTabCompleter());
|
||||
registerCommand("parkourRemove", new RemoveParkourArenaCommand(), new RemoveParkourArenaTabCompleter());
|
||||
registerCommand("parkourGroupSet", new ParkourGroupSetCommand(), null);
|
||||
registerCommand("parkourGroupSwap", new ParkourGroupSwapCommand(), null);
|
||||
registerCommand("parkourGroupList", new ParkourGroupListCommand(), null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets up the translator and the string formatter
|
||||
*/
|
||||
private void setupStringFormatter() {
|
||||
translator = new Translator();
|
||||
translator.registerMessageCategory(MiniGameMessage.ERROR_PLAYER_ONLY);
|
||||
translator.loadLanguages(this.getDataFolder(), "en",
|
||||
getConfig().getString("language", "en"));
|
||||
stringFormatter = new StringFormatter(this.getDescription().getName(), translator);
|
||||
stringFormatter.setColorConversion(ColorConversion.RGB);
|
||||
stringFormatter.setNamePrefix("#546EED[&r&l");
|
||||
stringFormatter.setNameSuffix("#546EED]");
|
||||
stringFormatter.setErrorColor(ChatColor.RED);
|
||||
stringFormatter.setSuccessColor(ChatColor.GREEN);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets up Vault by getting plugins from their providers
|
||||
*/
|
||||
private void setupVault() {
|
||||
ServicesManager servicesManager = this.getServer().getServicesManager();
|
||||
RegisteredServiceProvider<Permission> permissionProvider = servicesManager.getRegistration(Permission.class);
|
||||
RegisteredServiceProvider<Economy> economyProvider = servicesManager.getRegistration(Economy.class);
|
||||
|
||||
if (permissionProvider != null) {
|
||||
PermissionManager.initialize(permissionProvider.getProvider());
|
||||
} else {
|
||||
log(Level.WARNING, "No Vault permission provider found. Permission rewards are unavailable.");
|
||||
}
|
||||
|
||||
if (economyProvider != null) {
|
||||
EconomyManager.initialize(economyProvider.getProvider());
|
||||
} else {
|
||||
log(Level.WARNING, "No Vault economy provider found. Economy rewards are unavailable.");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,114 @@
|
||||
package net.knarcraft.minigames.arena;
|
||||
|
||||
import net.knarcraft.minigames.MiniGames;
|
||||
import net.knarcraft.minigames.util.ArenaStorageHelper;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.logging.Level;
|
||||
|
||||
/**
|
||||
* A player registry to keep track of currently playing players
|
||||
*
|
||||
* @param <K> <p>The type of arena stored</p>
|
||||
*/
|
||||
public abstract class AbstractArenaPlayerRegistry<K extends Arena> implements ArenaPlayerRegistry<K> {
|
||||
|
||||
private final Map<UUID, ArenaSession> arenaPlayers = new HashMap<>();
|
||||
private final Map<UUID, PlayerEntryState> entryStates = new HashMap<>();
|
||||
|
||||
/**
|
||||
* Instantiates a new arena player registry
|
||||
*/
|
||||
public AbstractArenaPlayerRegistry() {
|
||||
loadEntryStates();
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Set<UUID> getPlayingPlayers() {
|
||||
return arenaPlayers.keySet();
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable PlayerEntryState getEntryState(@NotNull UUID playerId) {
|
||||
return this.entryStates.get(playerId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerPlayer(@NotNull UUID playerId, @NotNull ArenaSession arenaSession) {
|
||||
this.arenaPlayers.put(playerId, arenaSession);
|
||||
this.entryStates.put(playerId, arenaSession.getEntryState());
|
||||
this.saveEntryStates();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean removePlayer(@NotNull UUID playerId, boolean restoreState) {
|
||||
// Try and restore the state. If it cannot be restored, retain the entry state
|
||||
PlayerEntryState entryState = this.entryStates.remove(playerId);
|
||||
if (restoreState) {
|
||||
if (entryState.restore()) {
|
||||
this.saveEntryStates();
|
||||
} else {
|
||||
this.entryStates.put(playerId, entryState);
|
||||
}
|
||||
} else {
|
||||
this.saveEntryStates();
|
||||
}
|
||||
|
||||
return this.arenaPlayers.remove(playerId) != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable ArenaSession getArenaSession(@NotNull UUID playerId) {
|
||||
return this.arenaPlayers.getOrDefault(playerId, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeForArena(K arena, boolean immediately) {
|
||||
Set<UUID> removed = new HashSet<>();
|
||||
for (Map.Entry<UUID, ArenaSession> entry : this.arenaPlayers.entrySet()) {
|
||||
if (entry.getValue().getArena() == arena) {
|
||||
// Kick the player gracefully
|
||||
entry.getValue().triggerQuit(immediately, false);
|
||||
removed.add(entry.getKey());
|
||||
}
|
||||
}
|
||||
removed.forEach(this.arenaPlayers::remove);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a string key unique to this type of player registry
|
||||
*
|
||||
* @return <p>A unique key used for entry state storage</p>
|
||||
*/
|
||||
protected abstract String getEntryStateStorageKey();
|
||||
|
||||
/**
|
||||
* Saves all entry states to disk
|
||||
*/
|
||||
private void saveEntryStates() {
|
||||
ArenaStorageHelper.storeArenaPlayerEntryStates(getEntryStateStorageKey(), new HashSet<>(entryStates.values()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads all entry states from disk
|
||||
*/
|
||||
private void loadEntryStates() {
|
||||
this.entryStates.clear();
|
||||
Set<PlayerEntryState> entryStates = ArenaStorageHelper.getArenaPlayerEntryStates(getEntryStateStorageKey());
|
||||
for (PlayerEntryState entryState : entryStates) {
|
||||
this.entryStates.put(entryState.getPlayerId(), entryState);
|
||||
}
|
||||
if (!this.entryStates.isEmpty()) {
|
||||
MiniGames.log(Level.WARNING, entryStates.size() + " un-exited sessions found. This happens if " +
|
||||
"players leave in the middle of a game, or if the server crashes. MiniGames will do its best " +
|
||||
"to fix the players' states.");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,152 @@
|
||||
package net.knarcraft.minigames.arena;
|
||||
|
||||
import net.knarcraft.knarlib.formatting.StringFormatter;
|
||||
import net.knarcraft.minigames.MiniGames;
|
||||
import net.knarcraft.minigames.arena.reward.RewardCondition;
|
||||
import net.knarcraft.minigames.config.MiniGameMessage;
|
||||
import net.knarcraft.minigames.property.RecordResult;
|
||||
import net.knarcraft.minigames.property.RecordType;
|
||||
import net.knarcraft.minigames.util.PlayerTeleporter;
|
||||
import net.knarcraft.minigames.util.RewardHelper;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public abstract class AbstractArenaSession implements ArenaSession {
|
||||
|
||||
private final @NotNull Arena arena;
|
||||
private final @NotNull ArenaGameMode gameMode;
|
||||
private final @NotNull Player player;
|
||||
protected int deaths;
|
||||
protected long startTime;
|
||||
protected PlayerEntryState entryState;
|
||||
|
||||
/**
|
||||
* Instantiates a new abstract arena session
|
||||
*
|
||||
* @param arena <p>The arena that's being played in</p>
|
||||
* @param player <p>The player playing the arena</p>
|
||||
* @param gameMode <p>The game-mode</p>
|
||||
*/
|
||||
public AbstractArenaSession(@NotNull Arena arena, @NotNull Player player, @NotNull ArenaGameMode gameMode) {
|
||||
this.arena = arena;
|
||||
this.player = player;
|
||||
this.gameMode = gameMode;
|
||||
this.deaths = 0;
|
||||
this.startTime = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void triggerQuit(boolean immediately, boolean removeSession) {
|
||||
// Stop this session
|
||||
if (removeSession) {
|
||||
removeSession();
|
||||
}
|
||||
// Teleport the player out of the arena
|
||||
teleportToExit(immediately);
|
||||
// Make the player visible to everyone
|
||||
MiniGames.getInstance().getPlayerVisibilityManager().showPlayersFor(player);
|
||||
|
||||
MiniGames.getInstance().getStringFormatter().displaySuccessMessage(player, MiniGameMessage.SUCCESS_ARENA_QUIT);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reset() {
|
||||
this.deaths = 0;
|
||||
this.startTime = System.currentTimeMillis();
|
||||
PlayerTeleporter.teleportPlayer(this.player, this.arena.getSpawnLocation(), false, false);
|
||||
this.entryState.setArenaState();
|
||||
}
|
||||
|
||||
/**
|
||||
* Announces a record set by this player
|
||||
*
|
||||
* @param recordResult <p>The result of the record</p>
|
||||
* @param recordType <p>The type of record set (time or deaths)</p>
|
||||
*/
|
||||
protected void announceRecord(@NotNull RecordResult recordResult, @NotNull RecordType recordType) {
|
||||
if (recordResult == RecordResult.NONE) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Gets a string representation of the played game-mode
|
||||
String gameModeString = getGameModeString();
|
||||
|
||||
MiniGameMessage recordInfoMiniGameMessage = switch (recordResult) {
|
||||
case WORLD_RECORD -> MiniGameMessage.RECORD_ACHIEVED_GLOBAL;
|
||||
case PERSONAL_BEST -> MiniGameMessage.RECORD_ACHIEVED_PERSONAL;
|
||||
default -> throw new IllegalStateException("Unexpected value: " + recordResult);
|
||||
};
|
||||
StringFormatter stringFormatter = MiniGames.getInstance().getStringFormatter();
|
||||
String recordInfo = stringFormatter.replacePlaceholder(recordInfoMiniGameMessage, "{recordType}",
|
||||
recordType.name().toLowerCase().replace("_", " "));
|
||||
|
||||
stringFormatter.displaySuccessMessage(player, stringFormatter.replacePlaceholders(
|
||||
MiniGameMessage.SUCCESS_RECORD_ACHIEVED, new String[]{"{gameMode}", "{recordInfo}"},
|
||||
new String[]{gameModeString, recordInfo}));
|
||||
|
||||
// Reward the player
|
||||
rewardRecord(recordResult, recordType);
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers the player's record if necessary, and prints record information to the player
|
||||
*/
|
||||
protected void registerRecord() {
|
||||
ArenaRecordsRegistry recordsRegistry = this.arena.getData().getRecordRegistries().get(this.gameMode);
|
||||
long timeElapsed = System.currentTimeMillis() - this.startTime;
|
||||
announceRecord(recordsRegistry.registerTimeRecord(this.player.getUniqueId(), timeElapsed), RecordType.TIME);
|
||||
announceRecord(recordsRegistry.registerDeathRecord(this.player.getUniqueId(), this.deaths), RecordType.DEATHS);
|
||||
}
|
||||
|
||||
/**
|
||||
* Rewards the specified achieved record
|
||||
*
|
||||
* @param recordResult <p>The result of the record achieved</p>
|
||||
* @param recordType <p>The type of record achieved</p>
|
||||
*/
|
||||
protected void rewardRecord(RecordResult recordResult, RecordType recordType) {
|
||||
RewardCondition condition = null;
|
||||
if (recordResult == RecordResult.WORLD_RECORD) {
|
||||
if (recordType == RecordType.DEATHS) {
|
||||
condition = RewardCondition.GLOBAL_DEATH_RECORD;
|
||||
} else if (recordType == RecordType.TIME) {
|
||||
condition = RewardCondition.GLOBAL_TIME_RECORD;
|
||||
}
|
||||
} else if (recordResult == RecordResult.PERSONAL_BEST) {
|
||||
if (recordType == RecordType.DEATHS) {
|
||||
condition = RewardCondition.PERSONAL_DEATH_RECORD;
|
||||
} else if (recordType == RecordType.TIME) {
|
||||
condition = RewardCondition.PERSONAL_TIME_RECORD;
|
||||
}
|
||||
}
|
||||
RewardHelper.grantRewards(this.player, this.arena.getRewards(condition));
|
||||
}
|
||||
|
||||
/**
|
||||
* Teleports the playing player out of the arena
|
||||
*/
|
||||
protected void teleportToExit(boolean immediately) {
|
||||
// Teleport the player out of the arena
|
||||
Location exitLocation;
|
||||
if (this.arena.getExitLocation() != null) {
|
||||
exitLocation = this.arena.getExitLocation();
|
||||
} else {
|
||||
exitLocation = this.entryState.getEntryLocation();
|
||||
}
|
||||
PlayerTeleporter.teleportPlayer(this.player, exitLocation, true, immediately);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the string representation of the session's game-mode
|
||||
*
|
||||
* @return <p>The string representation</p>
|
||||
*/
|
||||
protected abstract String getGameModeString();
|
||||
|
||||
/**
|
||||
* Removes this session from current sessions
|
||||
*/
|
||||
protected abstract void removeSession();
|
||||
|
||||
}
|
@ -0,0 +1,178 @@
|
||||
package net.knarcraft.minigames.arena;
|
||||
|
||||
import net.knarcraft.minigames.MiniGames;
|
||||
import net.knarcraft.minigames.container.SerializableUUID;
|
||||
import net.knarcraft.minigames.property.PersistentDataKey;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.persistence.PersistentDataType;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.logging.Level;
|
||||
|
||||
/**
|
||||
* An abstract representation of a player's entry state
|
||||
*/
|
||||
public abstract class AbstractPlayerEntryState implements PlayerEntryState {
|
||||
|
||||
protected final UUID playerId;
|
||||
private final Location entryLocation;
|
||||
private final boolean originalIsFlying;
|
||||
private final GameMode originalGameMode;
|
||||
private final boolean originalAllowFlight;
|
||||
private final boolean originalInvulnerable;
|
||||
private final boolean originalIsSwimming;
|
||||
private final boolean originalCollideAble;
|
||||
|
||||
/**
|
||||
* Instantiates a new abstract player entry state
|
||||
*
|
||||
* @param player <p>The player whose state this should keep track of</p>
|
||||
*/
|
||||
public AbstractPlayerEntryState(@NotNull Player player) {
|
||||
this.playerId = player.getUniqueId();
|
||||
this.entryLocation = player.getLocation().clone();
|
||||
this.originalIsFlying = player.isFlying();
|
||||
this.originalGameMode = player.getGameMode();
|
||||
this.originalAllowFlight = player.getAllowFlight();
|
||||
this.originalInvulnerable = player.isInvulnerable();
|
||||
this.originalIsSwimming = player.isSwimming();
|
||||
this.originalCollideAble = player.isCollidable();
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a new abstract player entry state
|
||||
*
|
||||
* @param playerId <p>The id of the player whose state this should keep track of</p>
|
||||
* @param entryLocation <p>The location the player entered from</p>
|
||||
* @param originalIsFlying <p>Whether the player was flying before entering the arena</p>
|
||||
* @param originalGameMode <p>The game-mode of the player before entering the arena</p>
|
||||
* @param originalAllowFlight <p>Whether the player was allowed flight before entering the arena</p>
|
||||
* @param originalInvulnerable <p>Whether the player was invulnerable before entering the arena</p>
|
||||
* @param originalIsSwimming <p>Whether the player was swimming before entering the arena</p>
|
||||
* @param originalCollideAble <p>Whether the player was collide-able before entering the arena</p>
|
||||
*/
|
||||
public AbstractPlayerEntryState(@NotNull UUID playerId, Location entryLocation,
|
||||
boolean originalIsFlying, GameMode originalGameMode, boolean originalAllowFlight,
|
||||
boolean originalInvulnerable, boolean originalIsSwimming,
|
||||
boolean originalCollideAble) {
|
||||
this.playerId = playerId;
|
||||
this.entryLocation = entryLocation;
|
||||
this.originalIsFlying = originalIsFlying;
|
||||
this.originalGameMode = originalGameMode;
|
||||
this.originalAllowFlight = originalAllowFlight;
|
||||
this.originalInvulnerable = originalInvulnerable;
|
||||
this.originalIsSwimming = originalIsSwimming;
|
||||
this.originalCollideAble = originalCollideAble;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull UUID getPlayerId() {
|
||||
return this.playerId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean restore() {
|
||||
Player player = getPlayer();
|
||||
if (player == null) {
|
||||
return false;
|
||||
}
|
||||
restore(player);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void restore(@NotNull Player player) {
|
||||
player.setCollidable(this.originalCollideAble);
|
||||
player.setAllowFlight(this.originalAllowFlight);
|
||||
player.setFlying(player.getAllowFlight() && this.originalIsFlying);
|
||||
player.setGameMode(this.originalGameMode);
|
||||
player.setInvulnerable(this.originalInvulnerable);
|
||||
player.setSwimming(this.originalIsSwimming);
|
||||
removeMenuItem(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Location getEntryLocation() {
|
||||
return this.entryLocation;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the player this entry state belongs to
|
||||
*
|
||||
* @return <p>The player, or null if not currently online</p>
|
||||
*/
|
||||
protected Player getPlayer() {
|
||||
Player player = Bukkit.getOfflinePlayer(this.playerId).getPlayer();
|
||||
if (player == null) {
|
||||
MiniGames.log(Level.WARNING, "Unable to change state for player with id " + this.playerId +
|
||||
" because the player was not found on the server.");
|
||||
}
|
||||
return player;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Map<String, Object> serialize() {
|
||||
Map<String, Object> data = new HashMap<>();
|
||||
data.put("playerId", new SerializableUUID(this.playerId));
|
||||
data.put("entryLocation", this.entryLocation);
|
||||
data.put("originalIsFlying", this.originalIsFlying);
|
||||
data.put("originalGameMode", this.originalGameMode.name());
|
||||
data.put("originalAllowFlight", this.originalAllowFlight);
|
||||
data.put("originalInvulnerable", this.originalInvulnerable);
|
||||
data.put("originalIsSwimming", this.originalIsSwimming);
|
||||
data.put("originalCollideAble", this.originalCollideAble);
|
||||
return data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the menu item from the given player's inventory
|
||||
*
|
||||
* @param player <p>The player to remove the menu item from</p>
|
||||
*/
|
||||
private void removeMenuItem(Player player) {
|
||||
Set<ItemStack> itemsToRemove = new HashSet<>();
|
||||
player.getInventory().forEach((item) -> {
|
||||
if (item == null) {
|
||||
return;
|
||||
}
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
if (meta == null) {
|
||||
return;
|
||||
}
|
||||
Integer persistentData = meta.getPersistentDataContainer().get(new NamespacedKey(MiniGames.getInstance(),
|
||||
PersistentDataKey.MENU_ITEM.getKeyName()), PersistentDataType.INTEGER);
|
||||
if (persistentData != null && persistentData == PersistentDataKey.MENU_ITEM.getDataValue()) {
|
||||
itemsToRemove.add(item);
|
||||
}
|
||||
});
|
||||
for (ItemStack toRemove : itemsToRemove) {
|
||||
player.getInventory().remove(toRemove);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a boolean value from a serialization map
|
||||
*
|
||||
* @param data <p>The serialization data to look through</p>
|
||||
* @param key <p>The key to get</p>
|
||||
* @return <p>The boolean value of the key</p>
|
||||
*/
|
||||
protected static boolean getBoolean(Map<String, Object> data, String key) {
|
||||
Boolean value = (Boolean) data.get(key);
|
||||
return Objects.requireNonNullElse(value, false);
|
||||
}
|
||||
|
||||
}
|
120
src/main/java/net/knarcraft/minigames/arena/Arena.java
Normal file
120
src/main/java/net/knarcraft/minigames/arena/Arena.java
Normal file
@ -0,0 +1,120 @@
|
||||
package net.knarcraft.minigames.arena;
|
||||
|
||||
import net.knarcraft.minigames.arena.reward.Reward;
|
||||
import net.knarcraft.minigames.arena.reward.RewardCondition;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.block.Block;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* An interface describing an arena
|
||||
*/
|
||||
public interface Arena {
|
||||
|
||||
/**
|
||||
* Gets the name of this arena
|
||||
*
|
||||
* @return <p>The name of this arena</p>
|
||||
*/
|
||||
@NotNull String getArenaName();
|
||||
|
||||
/**
|
||||
* Gets the data stored for this arena
|
||||
*
|
||||
* @return <p>The stored data</p>
|
||||
*/
|
||||
@NotNull ArenaData getData();
|
||||
|
||||
/**
|
||||
* Gets the id of this arena
|
||||
*
|
||||
* @return <p>This arena's identifier</p>
|
||||
*/
|
||||
@NotNull UUID getArenaId();
|
||||
|
||||
/**
|
||||
* Gets this arena's sanitized name
|
||||
*
|
||||
* @return <p>This arena's sanitized name</p>
|
||||
*/
|
||||
@NotNull String getArenaNameSanitized();
|
||||
|
||||
/**
|
||||
* Removes the data file belonging to this arena
|
||||
*
|
||||
* @return <p>True if successfully removed</p>
|
||||
*/
|
||||
boolean removeData();
|
||||
|
||||
/**
|
||||
* Saves this arena's data
|
||||
*
|
||||
* @return <p>True if successfully saved</p>
|
||||
*/
|
||||
boolean saveData();
|
||||
|
||||
/**
|
||||
* Gets whether standing on the given block should cause a win
|
||||
*
|
||||
* @param block <p>The block to check</p>
|
||||
* @return <p>True if standing on the block will cause a win</p>
|
||||
*/
|
||||
boolean willCauseWin(Block block);
|
||||
|
||||
/**
|
||||
* Gets whether standing on the given block should cause a loss
|
||||
*
|
||||
* @param block <p>The block to check</p>
|
||||
* @return <p>True if standing on the block will cause a loss</p>
|
||||
*/
|
||||
boolean willCauseLoss(Block block);
|
||||
|
||||
/**
|
||||
* Gets whether the win location is a solid block
|
||||
*
|
||||
* @return <p>True if the location is a solid block</p>
|
||||
*/
|
||||
boolean winLocationIsSolid();
|
||||
|
||||
/**
|
||||
* Gets the location of this arena's spawn
|
||||
*
|
||||
* @return <p>This arena's spawn location</p>
|
||||
*/
|
||||
@NotNull Location getSpawnLocation();
|
||||
|
||||
/**
|
||||
* Gets this arena's exit location
|
||||
*
|
||||
* @return <p>This arena's exit location, or null if no such location is set.</p>
|
||||
*/
|
||||
@Nullable Location getExitLocation();
|
||||
|
||||
/**
|
||||
* Adds a reward to this arena
|
||||
*
|
||||
* @param rewardCondition <p>The condition for the reward to be granted</p>
|
||||
* @param reward <p>The reward to be granted</p>
|
||||
*/
|
||||
void addReward(@NotNull RewardCondition rewardCondition, @NotNull Reward reward);
|
||||
|
||||
/**
|
||||
* Clears this arena's rewards for the given condition
|
||||
*
|
||||
* @param rewardCondition <p>The reward condition to clear all rewards for</p>
|
||||
*/
|
||||
void clearRewards(@NotNull RewardCondition rewardCondition);
|
||||
|
||||
/**
|
||||
* Gets all rewards for the given reward condition
|
||||
*
|
||||
* @param rewardCondition <p>The condition to get the rewards for</p>
|
||||
* @return <p>All rewards</p>
|
||||
*/
|
||||
@NotNull Set<Reward> getRewards(RewardCondition rewardCondition);
|
||||
|
||||
}
|
108
src/main/java/net/knarcraft/minigames/arena/ArenaData.java
Normal file
108
src/main/java/net/knarcraft/minigames/arena/ArenaData.java
Normal file
@ -0,0 +1,108 @@
|
||||
package net.knarcraft.minigames.arena;
|
||||
|
||||
import net.knarcraft.minigames.container.SerializableContainer;
|
||||
import net.knarcraft.minigames.container.SerializableUUID;
|
||||
import org.bukkit.configuration.serialization.ConfigurationSerializable;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
import static net.knarcraft.minigames.util.SerializableConverter.makeSerializable;
|
||||
|
||||
/**
|
||||
* An interface describing generic arena data
|
||||
*/
|
||||
public abstract class ArenaData implements ConfigurationSerializable {
|
||||
|
||||
protected final @NotNull UUID arenaId;
|
||||
private final @NotNull Map<ArenaGameMode, ArenaRecordsRegistry> recordRegistries;
|
||||
private final @NotNull Map<ArenaGameMode, Set<UUID>> playersCompleted;
|
||||
|
||||
/**
|
||||
* Instantiates arena data
|
||||
*
|
||||
* @param arenaId <p>The id of the arena this data belongs to</p>
|
||||
* @param recordRegistries <p>The registry storing records for this arena</p>
|
||||
* @param playersCompleted <p>The players that have completed this arena</p>
|
||||
*/
|
||||
public ArenaData(@NotNull UUID arenaId, @NotNull Map<ArenaGameMode, ArenaRecordsRegistry> recordRegistries,
|
||||
@NotNull Map<ArenaGameMode, Set<UUID>> playersCompleted) {
|
||||
this.arenaId = arenaId;
|
||||
this.recordRegistries = recordRegistries;
|
||||
this.playersCompleted = playersCompleted;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the id of this arena
|
||||
*
|
||||
* @return <p>The id of this arena</p>
|
||||
*/
|
||||
public @NotNull UUID getArenaId() {
|
||||
return this.arenaId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets all record registries
|
||||
*
|
||||
* @return <p>All record registries</p>
|
||||
*/
|
||||
public @NotNull Map<ArenaGameMode, ArenaRecordsRegistry> getRecordRegistries() {
|
||||
return new HashMap<>(this.recordRegistries);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets whether the given player has cleared this arena
|
||||
*
|
||||
* @param arenaGameMode <p>The game-mode to check for</p>
|
||||
* @param player <p>The player to check</p>
|
||||
* @return <p>True if the player has cleared the arena this data belongs to</p>
|
||||
*/
|
||||
public boolean hasNotCompleted(@NotNull ArenaGameMode arenaGameMode, @NotNull Player player) {
|
||||
return !this.playersCompleted.getOrDefault(arenaGameMode, new HashSet<>()).contains(player.getUniqueId());
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers the given player as having completed this arena
|
||||
*
|
||||
* @param arenaGameMode <p>The game-mode the player completed</p>
|
||||
* @param player <p>The player that completed this data's arena</p>
|
||||
*/
|
||||
public boolean setCompleted(@NotNull ArenaGameMode arenaGameMode, @NotNull Player player) {
|
||||
// Make sure to add an empty set to prevent a NullPointerException
|
||||
if (!this.playersCompleted.containsKey(arenaGameMode)) {
|
||||
this.playersCompleted.put(arenaGameMode, new HashSet<>());
|
||||
}
|
||||
|
||||
boolean added = this.playersCompleted.get(arenaGameMode).add(player.getUniqueId());
|
||||
// Persistently save the completion
|
||||
if (added) {
|
||||
saveData();
|
||||
}
|
||||
return added;
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves this data to disk
|
||||
*/
|
||||
public abstract void saveData();
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Map<String, Object> serialize() {
|
||||
Map<String, Object> data = new HashMap<>();
|
||||
data.put("arenaId", new SerializableUUID(this.arenaId));
|
||||
data.put("recordsRegistry", this.recordRegistries);
|
||||
|
||||
// Convert normal UUIDs to serializable UUIDs
|
||||
Map<ArenaGameMode, Set<SerializableContainer<UUID>>> serializablePlayersCompleted = new HashMap<>();
|
||||
makeSerializable(this.playersCompleted, serializablePlayersCompleted, new SerializableUUID(null));
|
||||
data.put("playersCompleted", serializablePlayersCompleted);
|
||||
return data;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
package net.knarcraft.minigames.arena;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* An interface describing any arena game-mode
|
||||
*/
|
||||
public interface ArenaGameMode {
|
||||
|
||||
/**
|
||||
* Gets the name of this game-mode
|
||||
*
|
||||
* @return <p>The name of this game-mode</p>
|
||||
*/
|
||||
@NotNull String name();
|
||||
|
||||
/**
|
||||
* Gets a set of all available arena game-modes in the type definition of this game-mode
|
||||
*
|
||||
* @return <p>All game-modes in this game-mode's class</p>
|
||||
*/
|
||||
@NotNull ArenaGameMode[] getValues();
|
||||
|
||||
}
|
@ -1,9 +1,8 @@
|
||||
package net.knarcraft.dropper.arena;
|
||||
package net.knarcraft.minigames.arena;
|
||||
|
||||
import net.knarcraft.dropper.Dropper;
|
||||
import net.knarcraft.dropper.container.SerializableUUID;
|
||||
import net.knarcraft.dropper.property.ArenaGameMode;
|
||||
import net.knarcraft.dropper.util.StringSanitizer;
|
||||
import net.knarcraft.minigames.MiniGames;
|
||||
import net.knarcraft.minigames.container.SerializableUUID;
|
||||
import net.knarcraft.minigames.util.StringSanitizer;
|
||||
import org.bukkit.configuration.serialization.ConfigurationSerializable;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@ -16,9 +15,12 @@ import java.util.UUID;
|
||||
import java.util.logging.Level;
|
||||
|
||||
/**
|
||||
* A sorted group of arenas that must be completed in sequence
|
||||
* A group containing a list of arenas
|
||||
*
|
||||
* @param <K> <p>The type of arena stored</p>
|
||||
* @param <S> <p>The type of arena group stored in the given arena handler</p>
|
||||
*/
|
||||
public class DropperArenaGroup implements ConfigurationSerializable {
|
||||
public abstract class ArenaGroup<K extends Arena, S extends ArenaGroup<K, S>> implements ConfigurationSerializable {
|
||||
|
||||
/**
|
||||
* The unique id for this group of arenas
|
||||
@ -30,6 +32,11 @@ public class DropperArenaGroup implements ConfigurationSerializable {
|
||||
*/
|
||||
private final String groupName;
|
||||
|
||||
/**
|
||||
* The arena handler used to convert uuids to arenas
|
||||
*/
|
||||
private final ArenaHandler<K, S> arenaHandler;
|
||||
|
||||
/**
|
||||
* The arenas in this group, ordered from stage 1 to stage n
|
||||
*/
|
||||
@ -38,29 +45,34 @@ public class DropperArenaGroup implements ConfigurationSerializable {
|
||||
/**
|
||||
* Instantiates a new dropper arena group
|
||||
*
|
||||
* @param groupName <p>The name of this group</p>
|
||||
* @param groupName <p>The name of this group</p>
|
||||
* @param arenaHandler <p>The arena handler used to convert uuids to arenas</p>
|
||||
*/
|
||||
public DropperArenaGroup(@NotNull String groupName) {
|
||||
protected ArenaGroup(@NotNull String groupName, @NotNull ArenaHandler<K, S> arenaHandler) {
|
||||
this.groupId = UUID.randomUUID();
|
||||
this.groupName = groupName;
|
||||
this.arenas = new ArrayList<>();
|
||||
this.arenaHandler = arenaHandler;
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a new dropper arena group
|
||||
* Instantiates a new arena group
|
||||
*
|
||||
* @param groupId <p>The unique id of this group</p>
|
||||
* @param groupName <p>The name of this group</p>
|
||||
* @param arenas <p>The arenas in this group</p>
|
||||
* @param groupId <p>The unique id of this group</p>
|
||||
* @param groupName <p>The name of this group</p>
|
||||
* @param arenas <p>The arenas in this group</p>
|
||||
* @param arenaHandler <p>The arena handler used to convert uuids to arenas</p>
|
||||
*/
|
||||
private DropperArenaGroup(@NotNull UUID groupId, @NotNull String groupName, @NotNull List<UUID> arenas) {
|
||||
protected ArenaGroup(@NotNull UUID groupId, @NotNull String groupName, @NotNull List<UUID> arenas,
|
||||
@NotNull ArenaHandler<K, S> arenaHandler) {
|
||||
this.groupId = groupId;
|
||||
this.groupName = groupName;
|
||||
this.arenas = new ArrayList<>(arenas);
|
||||
this.arenaHandler = arenaHandler;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the id of this dropper arena group
|
||||
* Gets the id of this arena group
|
||||
*
|
||||
* @return <p>The id of this group</p>
|
||||
*/
|
||||
@ -69,7 +81,7 @@ public class DropperArenaGroup implements ConfigurationSerializable {
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the name of this dropper arena group
|
||||
* Gets the name of this arena group
|
||||
*
|
||||
* @return <p>The name of this group</p>
|
||||
*/
|
||||
@ -87,9 +99,9 @@ public class DropperArenaGroup implements ConfigurationSerializable {
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the given dropper arena from this group
|
||||
* Removes the given arena from this group
|
||||
*
|
||||
* @param arenaId <p>The id of the dropper arena to remove</p>
|
||||
* @param arenaId <p>The id of the arena to remove</p>
|
||||
*/
|
||||
public void removeArena(UUID arenaId) {
|
||||
this.arenas.remove(arenaId);
|
||||
@ -117,6 +129,15 @@ public class DropperArenaGroup implements ConfigurationSerializable {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets this group's name, but sanitized
|
||||
*
|
||||
* @return <p>The sanitized group name</p>
|
||||
*/
|
||||
public @NotNull String getGroupNameSanitized() {
|
||||
return StringSanitizer.sanitizeArenaName(this.getGroupName());
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether the given player has beaten all arenas in this group on the given game-mode
|
||||
*
|
||||
@ -125,17 +146,16 @@ public class DropperArenaGroup implements ConfigurationSerializable {
|
||||
* @return <p>True if the player has beaten all arenas, false otherwise</p>
|
||||
*/
|
||||
public boolean hasBeatenAll(ArenaGameMode gameMode, Player player) {
|
||||
DropperArenaHandler arenaHandler = Dropper.getInstance().getArenaHandler();
|
||||
for (UUID anArenaId : this.getArenas()) {
|
||||
DropperArena dropperArena = arenaHandler.getArena(anArenaId);
|
||||
if (dropperArena == null) {
|
||||
K arena = this.arenaHandler.getArena(anArenaId);
|
||||
if (arena == null) {
|
||||
// The arena would only be null if the arena has been deleted, but not removed from this group
|
||||
Dropper.getInstance().getLogger().log(Level.WARNING, "The dropper group " + this.getGroupName() +
|
||||
MiniGames.log(Level.WARNING, "The dropper group " + this.getGroupName() +
|
||||
" contains the arena id " + anArenaId + " which is not a valid arena id!");
|
||||
continue;
|
||||
}
|
||||
|
||||
if (dropperArena.getData().hasNotCompleted(gameMode, player)) {
|
||||
if (arena.getData().hasNotCompleted(gameMode, player)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -151,43 +171,32 @@ public class DropperArenaGroup implements ConfigurationSerializable {
|
||||
* @return <p>True if the player is allowed to play the arena</p>
|
||||
* @throws IllegalArgumentException <p>If checking an arena not in this group</p>
|
||||
*/
|
||||
public boolean canPlay(ArenaGameMode gameMode, Player player, UUID arenaId) throws IllegalArgumentException {
|
||||
public boolean cannotPlay(ArenaGameMode gameMode, Player player, UUID arenaId) throws IllegalArgumentException {
|
||||
if (!this.arenas.contains(arenaId)) {
|
||||
throw new IllegalArgumentException("Cannot check for playability for arena not in this group!");
|
||||
}
|
||||
|
||||
DropperArenaHandler arenaHandler = Dropper.getInstance().getArenaHandler();
|
||||
|
||||
for (UUID anArenaId : this.getArenas()) {
|
||||
// If the target arena is reached, allow, as all previous arenas must have been cleared
|
||||
if (arenaId == anArenaId) {
|
||||
return true;
|
||||
if (arenaId.equals(anArenaId)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
DropperArena dropperArena = arenaHandler.getArena(anArenaId);
|
||||
if (dropperArena == null) {
|
||||
K arena = this.arenaHandler.getArena(anArenaId);
|
||||
if (arena == null) {
|
||||
// The arena would only be null if the arena has been deleted, but not removed from this group
|
||||
Dropper.getInstance().getLogger().log(Level.WARNING, String.format("The dropper group %s contains the" +
|
||||
MiniGames.log(Level.WARNING, String.format("The dropper group %s contains the" +
|
||||
" arena id %s which is not a valid arena id!", this.getGroupName(), anArenaId));
|
||||
continue;
|
||||
}
|
||||
|
||||
// This is a lower-numbered arena the player has yet to complete
|
||||
if (dropperArena.getData().hasNotCompleted(gameMode, player)) {
|
||||
return false;
|
||||
if (arena.getData().hasNotCompleted(gameMode, player)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets this group's name, but sanitized
|
||||
*
|
||||
* @return <p>The sanitized group name</p>
|
||||
*/
|
||||
public @NotNull String getGroupNameSanitized() {
|
||||
return StringSanitizer.sanitizeArenaName(this.getGroupName());
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -224,27 +233,9 @@ public class DropperArenaGroup implements ConfigurationSerializable {
|
||||
return data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Deserializes the given data
|
||||
*
|
||||
* @param data <p>The data to deserialize</p>
|
||||
* @return <p>The deserialized arena group</p>
|
||||
*/
|
||||
@SuppressWarnings({"unused", "unchecked"})
|
||||
public static @NotNull DropperArenaGroup deserialize(@NotNull Map<String, Object> data) {
|
||||
UUID id = ((SerializableUUID) data.get("groupId")).uuid();
|
||||
String name = (String) data.get("groupName");
|
||||
List<SerializableUUID> serializableArenas = (List<SerializableUUID>) data.get("arenas");
|
||||
List<UUID> arenas = new ArrayList<>();
|
||||
for (SerializableUUID arenaId : serializableArenas) {
|
||||
arenas.add(arenaId.uuid());
|
||||
}
|
||||
return new DropperArenaGroup(id, name, arenas);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object other) {
|
||||
if (!(other instanceof DropperArenaGroup otherGroup)) {
|
||||
if (!(other instanceof ArenaGroup<?, ?> otherGroup)) {
|
||||
return false;
|
||||
}
|
||||
return this.getGroupNameSanitized().equals(otherGroup.getGroupNameSanitized());
|
@ -1,12 +1,10 @@
|
||||
package net.knarcraft.dropper.arena;
|
||||
package net.knarcraft.minigames.arena;
|
||||
|
||||
import net.knarcraft.dropper.Dropper;
|
||||
import net.knarcraft.dropper.util.ArenaStorageHelper;
|
||||
import net.knarcraft.dropper.util.StringSanitizer;
|
||||
import net.knarcraft.minigames.MiniGames;
|
||||
import net.knarcraft.minigames.util.StringSanitizer;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
@ -15,21 +13,34 @@ import java.util.UUID;
|
||||
import java.util.logging.Level;
|
||||
|
||||
/**
|
||||
* A handler that keeps track of all dropper arenas
|
||||
* An interface describing a generic arena handler
|
||||
*
|
||||
* @param <K> <p>The type of arena stored</p>
|
||||
* @param <S> <p>The type of arena group stored</p>
|
||||
*/
|
||||
public class DropperArenaHandler {
|
||||
public abstract class ArenaHandler<K extends Arena, S extends ArenaGroup<K, S>> {
|
||||
|
||||
private Map<UUID, DropperArena> arenas = new HashMap<>();
|
||||
private Map<UUID, DropperArenaGroup> arenaGroups = new HashMap<>();
|
||||
private Map<String, UUID> arenaNameLookup = new HashMap<>();
|
||||
protected Map<UUID, K> arenas = new HashMap<>();
|
||||
protected Map<UUID, S> arenaGroups = new HashMap<>();
|
||||
protected Map<String, UUID> arenaNameLookup = new HashMap<>();
|
||||
private final ArenaPlayerRegistry<K> playerRegistry;
|
||||
|
||||
/**
|
||||
* Instantiates a new arena handler
|
||||
*
|
||||
* @param playerRegistry <p>The registry keeping track of player sessions</p>
|
||||
*/
|
||||
public ArenaHandler(ArenaPlayerRegistry<K> playerRegistry) {
|
||||
this.playerRegistry = playerRegistry;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets all arenas that are within a group
|
||||
*
|
||||
* @return <p>All arenas in a group</p>
|
||||
*/
|
||||
public @NotNull Set<DropperArena> getArenasInAGroup() {
|
||||
Set<DropperArena> arenas = new HashSet<>();
|
||||
public @NotNull Set<K> getArenasInAGroup() {
|
||||
Set<K> arenas = new HashSet<>();
|
||||
for (UUID arenaId : arenaGroups.keySet()) {
|
||||
arenas.add(this.arenas.get(arenaId));
|
||||
}
|
||||
@ -37,11 +48,11 @@ public class DropperArenaHandler {
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a copy of all dropper groups
|
||||
* Gets a copy of all arena groups
|
||||
*
|
||||
* @return <p>All dropper groups</p>
|
||||
* @return <p>All arena groups</p>
|
||||
*/
|
||||
public Set<DropperArenaGroup> getAllGroups() {
|
||||
public Set<S> getAllGroups() {
|
||||
return new HashSet<>(arenaGroups.values());
|
||||
}
|
||||
|
||||
@ -51,7 +62,7 @@ public class DropperArenaHandler {
|
||||
* @param arenaId <p>The id of the arena to get the group of</p>
|
||||
* @return <p>The group the arena belongs to, or null if not in a group</p>
|
||||
*/
|
||||
public @Nullable DropperArenaGroup getGroup(@NotNull UUID arenaId) {
|
||||
public @Nullable S getGroup(@NotNull UUID arenaId) {
|
||||
return this.arenaGroups.get(arenaId);
|
||||
}
|
||||
|
||||
@ -61,7 +72,7 @@ public class DropperArenaHandler {
|
||||
* @param arenaId <p>The id of the arena to change</p>
|
||||
* @param arenaGroup <p>The group to add the arena to, or null to remove the current group</p>
|
||||
*/
|
||||
public void setGroup(@NotNull UUID arenaId, @Nullable DropperArenaGroup arenaGroup) {
|
||||
public void setGroup(@NotNull UUID arenaId, @Nullable S arenaGroup) {
|
||||
if (arenaGroup == null) {
|
||||
// No need to remove something non-existing
|
||||
if (!this.arenaGroups.containsKey(arenaId)) {
|
||||
@ -69,7 +80,7 @@ public class DropperArenaHandler {
|
||||
}
|
||||
|
||||
// Remove the existing group
|
||||
DropperArenaGroup oldGroup = this.arenaGroups.remove(arenaId);
|
||||
S oldGroup = this.arenaGroups.remove(arenaId);
|
||||
oldGroup.removeArena(arenaId);
|
||||
} else {
|
||||
// Make sure to remove the arena from the old group's internal tracking
|
||||
@ -84,14 +95,14 @@ public class DropperArenaHandler {
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the dropper arena group with the given name
|
||||
* Gets the arena group with the given name
|
||||
*
|
||||
* @param groupName <p>The name of the group to get</p>
|
||||
* @return <p>The group, or null if not found</p>
|
||||
*/
|
||||
public @Nullable DropperArenaGroup getGroup(String groupName) {
|
||||
public @Nullable S getGroup(String groupName) {
|
||||
String sanitized = StringSanitizer.sanitizeArenaName(groupName);
|
||||
for (DropperArenaGroup arenaGroup : this.arenaGroups.values()) {
|
||||
for (S arenaGroup : this.arenaGroups.values()) {
|
||||
if (arenaGroup.getGroupNameSanitized().equals(sanitized)) {
|
||||
return arenaGroup;
|
||||
}
|
||||
@ -117,7 +128,7 @@ public class DropperArenaHandler {
|
||||
*
|
||||
* @param arena <p>The arena to add</p>
|
||||
*/
|
||||
public void addArena(@NotNull DropperArena arena) {
|
||||
public void addArena(@NotNull K arena) {
|
||||
this.arenas.put(arena.getArenaId(), arena);
|
||||
this.arenaNameLookup.put(arena.getArenaNameSanitized(), arena.getArenaId());
|
||||
this.saveArenas();
|
||||
@ -129,7 +140,7 @@ public class DropperArenaHandler {
|
||||
* @param arenaId <p>The id of the arena to get</p>
|
||||
* @return <p>The arena, or null if no arena could be found</p>
|
||||
*/
|
||||
public @Nullable DropperArena getArena(@NotNull UUID arenaId) {
|
||||
public @Nullable K getArena(@NotNull UUID arenaId) {
|
||||
return this.arenas.get(arenaId);
|
||||
}
|
||||
|
||||
@ -139,7 +150,7 @@ public class DropperArenaHandler {
|
||||
* @param arenaName <p>The arena to get</p>
|
||||
* @return <p>The arena with the given name, or null if not found</p>
|
||||
*/
|
||||
public @Nullable DropperArena getArena(@NotNull String arenaName) {
|
||||
public @Nullable K getArena(@NotNull String arenaName) {
|
||||
return this.arenas.get(this.arenaNameLookup.get(StringSanitizer.sanitizeArenaName(arenaName)));
|
||||
}
|
||||
|
||||
@ -148,7 +159,7 @@ public class DropperArenaHandler {
|
||||
*
|
||||
* @return <p>All known arenas</p>
|
||||
*/
|
||||
public @NotNull Map<UUID, DropperArena> getArenas() {
|
||||
public @NotNull Map<UUID, K> getArenas() {
|
||||
return new HashMap<>(this.arenas);
|
||||
}
|
||||
|
||||
@ -157,11 +168,16 @@ public class DropperArenaHandler {
|
||||
*
|
||||
* @param arena <p>The arena to remove</p>
|
||||
*/
|
||||
public void removeArena(@NotNull DropperArena arena) {
|
||||
Dropper.getInstance().getPlayerRegistry().removeForArena(arena);
|
||||
this.arenas.remove(arena.getArenaId());
|
||||
public void removeArena(@NotNull K arena) {
|
||||
UUID arenaId = arena.getArenaId();
|
||||
this.playerRegistry.removeForArena(arena, false);
|
||||
this.arenas.remove(arenaId);
|
||||
this.arenaNameLookup.remove(arena.getArenaNameSanitized());
|
||||
this.arenaGroups.remove(arena.getArenaId());
|
||||
this.arenaGroups.remove(arenaId);
|
||||
if (!arena.removeData()) {
|
||||
MiniGames.log(Level.WARNING, "Unable to remove arena data file " + arenaId + ".yml. " +
|
||||
"You must remove it manually!");
|
||||
}
|
||||
this.saveArenas();
|
||||
}
|
||||
|
||||
@ -171,66 +187,44 @@ public class DropperArenaHandler {
|
||||
* @param arenaId <p>The id of the arena whose data should be saved</p>
|
||||
*/
|
||||
public void saveData(UUID arenaId) {
|
||||
try {
|
||||
ArenaStorageHelper.saveArenaData(this.arenas.get(arenaId).getData());
|
||||
} catch (IOException e) {
|
||||
Dropper.getInstance().getLogger().log(Level.SEVERE, "Unable to save arena data! Data loss can occur!");
|
||||
Dropper.getInstance().getLogger().log(Level.SEVERE, e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves all current dropper groups to disk
|
||||
*/
|
||||
public void saveGroups() {
|
||||
try {
|
||||
ArenaStorageHelper.saveDropperArenaGroups(new HashSet<>(this.arenaGroups.values()));
|
||||
} catch (IOException e) {
|
||||
Dropper.getInstance().getLogger().log(Level.SEVERE, "Unable to save current arena groups! " +
|
||||
"Data loss can occur!");
|
||||
Dropper.getInstance().getLogger().log(Level.SEVERE, e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads all dropper groups from disk
|
||||
*/
|
||||
public void loadGroups() {
|
||||
Set<DropperArenaGroup> arenaGroups = ArenaStorageHelper.loadDropperArenaGroups();
|
||||
Map<UUID, DropperArenaGroup> arenaGroupMap = new HashMap<>();
|
||||
for (DropperArenaGroup arenaGroup : arenaGroups) {
|
||||
for (UUID arenaId : arenaGroup.getArenas()) {
|
||||
arenaGroupMap.put(arenaId, arenaGroup);
|
||||
K arena = getArena(arenaId);
|
||||
if (arena != null) {
|
||||
if (!arena.saveData()) {
|
||||
MiniGames.log(Level.WARNING, "Unable to save data for arena with id " + arenaId +
|
||||
" because of a write exception!");
|
||||
}
|
||||
} else {
|
||||
MiniGames.log(Level.WARNING, "Unable to save data for arena with id " + arenaId +
|
||||
" because the arena could not be found!");
|
||||
}
|
||||
this.arenaGroups = arenaGroupMap;
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves all current groups to disk
|
||||
*/
|
||||
public abstract void saveGroups();
|
||||
|
||||
/**
|
||||
* Loads all groups from disk
|
||||
*/
|
||||
protected abstract void loadGroups();
|
||||
|
||||
/**
|
||||
* Loads all arenas and groups from disk
|
||||
*/
|
||||
public void load() {
|
||||
loadArenas();
|
||||
loadGroups();
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves all current arenas to disk
|
||||
*/
|
||||
public void saveArenas() {
|
||||
try {
|
||||
ArenaStorageHelper.saveArenas(this.arenas);
|
||||
} catch (IOException e) {
|
||||
Dropper.getInstance().getLogger().log(Level.SEVERE, "Unable to save current arenas! " +
|
||||
"Data loss can occur!");
|
||||
Dropper.getInstance().getLogger().log(Level.SEVERE, e.getMessage());
|
||||
}
|
||||
}
|
||||
public abstract void saveArenas();
|
||||
|
||||
/**
|
||||
* Loads all arenas from disk
|
||||
*/
|
||||
public void loadArenas() {
|
||||
this.arenas = ArenaStorageHelper.loadArenas();
|
||||
|
||||
// Save a map from arena name to arena id for improved performance
|
||||
this.arenaNameLookup = new HashMap<>();
|
||||
for (Map.Entry<UUID, DropperArena> arena : this.arenas.entrySet()) {
|
||||
String sanitizedName = arena.getValue().getArenaNameSanitized();
|
||||
this.arenaNameLookup.put(sanitizedName, arena.getKey());
|
||||
}
|
||||
}
|
||||
protected abstract void loadArenas();
|
||||
|
||||
}
|
@ -0,0 +1,63 @@
|
||||
package net.knarcraft.minigames.arena;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* A registry keeping track of all player sessions for some arenas
|
||||
*
|
||||
* @param <K> <p>The type of arena this registry stores</p>
|
||||
*/
|
||||
public interface ArenaPlayerRegistry<K extends Arena> {
|
||||
|
||||
/**
|
||||
* Gets the ids of the players currently playing
|
||||
*
|
||||
* @return <p>The ids of the playing players</p>
|
||||
*/
|
||||
@NotNull Set<UUID> getPlayingPlayers();
|
||||
|
||||
/**
|
||||
* Gets the current entry state for the given player
|
||||
*
|
||||
* @param playerId <p>The id of the player to get an entry state for</p>
|
||||
* @return <p>The entry state of the player, or null if not found</p>
|
||||
*/
|
||||
@Nullable PlayerEntryState getEntryState(@NotNull UUID playerId);
|
||||
|
||||
/**
|
||||
* Registers that the given player has started playing the given dropper arena session
|
||||
*
|
||||
* @param playerId <p>The id of the player that started playing</p>
|
||||
* @param arenaSession <p>The arena session to register</p>
|
||||
*/
|
||||
void registerPlayer(@NotNull UUID playerId, @NotNull ArenaSession arenaSession);
|
||||
|
||||
/**
|
||||
* Removes this player from players currently playing
|
||||
*
|
||||
* @param playerId <p>The id of the player to remove</p>
|
||||
* @param restoreState <p>Whether to restore the state of the player as part of the removal</p>
|
||||
*/
|
||||
boolean removePlayer(@NotNull UUID playerId, boolean restoreState);
|
||||
|
||||
/**
|
||||
* Gets the player's active dropper arena session
|
||||
*
|
||||
* @param playerId <p>The id of the player to get arena for</p>
|
||||
* @return <p>The player's active arena session, or null if not currently playing</p>
|
||||
*/
|
||||
@Nullable ArenaSession getArenaSession(@NotNull UUID playerId);
|
||||
|
||||
/**
|
||||
* Removes all active sessions for the given arena
|
||||
*
|
||||
* @param arena <p>The arena to remove sessions for</p>
|
||||
* @param immediately <p>Whether to immediately teleport the player</p>
|
||||
*/
|
||||
void removeForArena(K arena, boolean immediately);
|
||||
|
||||
}
|
@ -0,0 +1,173 @@
|
||||
package net.knarcraft.minigames.arena;
|
||||
|
||||
import net.knarcraft.minigames.arena.record.ArenaRecord;
|
||||
import net.knarcraft.minigames.arena.record.IntegerRecord;
|
||||
import net.knarcraft.minigames.arena.record.LongRecord;
|
||||
import net.knarcraft.minigames.arena.record.SummableArenaRecord;
|
||||
import net.knarcraft.minigames.container.SerializableUUID;
|
||||
import net.knarcraft.minigames.property.RecordResult;
|
||||
import org.bukkit.configuration.serialization.ConfigurationSerializable;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
/**
|
||||
* A records registry storing records for an arena
|
||||
*/
|
||||
public abstract class ArenaRecordsRegistry implements ConfigurationSerializable {
|
||||
|
||||
protected final UUID arenaId;
|
||||
private final @NotNull Set<IntegerRecord> leastDeaths;
|
||||
private final @NotNull Set<LongRecord> shortestTimeMilliSeconds;
|
||||
|
||||
/**
|
||||
* Instantiates a new empty records registry
|
||||
*/
|
||||
public ArenaRecordsRegistry(@NotNull UUID arenaId) {
|
||||
this.arenaId = arenaId;
|
||||
this.leastDeaths = new HashSet<>();
|
||||
this.shortestTimeMilliSeconds = new HashSet<>();
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a new records registry
|
||||
*
|
||||
* @param leastDeaths <p>The existing least death records to use</p>
|
||||
* @param shortestTimeMilliSeconds <p>The existing leash time records to use</p>
|
||||
*/
|
||||
protected ArenaRecordsRegistry(@NotNull UUID arenaId, @NotNull Set<IntegerRecord> leastDeaths,
|
||||
@NotNull Set<LongRecord> shortestTimeMilliSeconds) {
|
||||
this.arenaId = arenaId;
|
||||
this.leastDeaths = new HashSet<>(leastDeaths);
|
||||
this.shortestTimeMilliSeconds = new HashSet<>(shortestTimeMilliSeconds);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets all existing death records
|
||||
*
|
||||
* @return <p>Existing death records</p>
|
||||
*/
|
||||
public Set<SummableArenaRecord<Integer>> getLeastDeathsRecords() {
|
||||
return new HashSet<>(this.leastDeaths);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets all existing time records
|
||||
*
|
||||
* @return <p>Existing time records</p>
|
||||
*/
|
||||
public Set<SummableArenaRecord<Long>> getShortestTimeMilliSecondsRecords() {
|
||||
return new HashSet<>(this.shortestTimeMilliSeconds);
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a new deaths-record
|
||||
*
|
||||
* @param playerId <p>The id of the player that performed the records</p>
|
||||
* @param deaths <p>The number of deaths suffered before the player finished the arena</p>
|
||||
* @return <p>The result explaining what type of record was achieved</p>
|
||||
*/
|
||||
public @NotNull RecordResult registerDeathRecord(@NotNull UUID playerId, int deaths) {
|
||||
Consumer<Integer> consumer = (value) -> {
|
||||
leastDeaths.removeIf((item) -> item.getUserId().equals(playerId));
|
||||
leastDeaths.add(new IntegerRecord(playerId, value));
|
||||
};
|
||||
return registerRecord(new HashSet<>(leastDeaths), consumer, playerId, deaths);
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a new time-record
|
||||
*
|
||||
* @param playerId <p>The id of the player that performed the records</p>
|
||||
* @param milliseconds <p>The number of milliseconds it took the player to finish the dropper arena</p>
|
||||
* @return <p>The result explaining what type of record was achieved</p>
|
||||
*/
|
||||
public @NotNull RecordResult registerTimeRecord(@NotNull UUID playerId, long milliseconds) {
|
||||
Consumer<Long> consumer = (value) -> {
|
||||
shortestTimeMilliSeconds.removeIf((item) -> item.getUserId().equals(playerId));
|
||||
shortestTimeMilliSeconds.add(new LongRecord(playerId, value));
|
||||
};
|
||||
return registerRecord(new HashSet<>(shortestTimeMilliSeconds), consumer, playerId, milliseconds);
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves changed records
|
||||
*/
|
||||
protected abstract void save();
|
||||
|
||||
/**
|
||||
* Registers a new record if applicable
|
||||
*
|
||||
* @param existingRecords <p>The map of existing records to use</p>
|
||||
* @param recordSetter <p>The consumer used to set a new record</p>
|
||||
* @param playerId <p>The id of the player that potentially achieved a record</p>
|
||||
* @param amount <p>The amount of whatever the player achieved</p>
|
||||
* @return <p>The result of the player's record attempt</p>
|
||||
*/
|
||||
private <T extends Comparable<T>> @NotNull RecordResult registerRecord(@NotNull Set<ArenaRecord<T>> existingRecords,
|
||||
@NotNull Consumer<T> recordSetter,
|
||||
@NotNull UUID playerId, T amount) {
|
||||
RecordResult result;
|
||||
if (existingRecords.stream().allMatch((entry) -> amount.compareTo(entry.getRecord()) < 0)) {
|
||||
// If the given value is less than all other values, that's a world record!
|
||||
result = RecordResult.WORLD_RECORD;
|
||||
recordSetter.accept(amount);
|
||||
save();
|
||||
return result;
|
||||
}
|
||||
|
||||
ArenaRecord<T> playerRecord = getRecord(existingRecords, playerId);
|
||||
if (playerRecord != null && amount.compareTo(playerRecord.getRecord()) < 0) {
|
||||
// If the given value is less than the player's previous value, that's a personal best!
|
||||
result = RecordResult.PERSONAL_BEST;
|
||||
recordSetter.accept(amount);
|
||||
save();
|
||||
} else {
|
||||
// Make sure to save the record if this is the user's first attempt
|
||||
if (playerRecord == null) {
|
||||
recordSetter.accept(amount);
|
||||
save();
|
||||
}
|
||||
result = RecordResult.NONE;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the record stored for the given player
|
||||
*
|
||||
* @param existingRecords <p>The existing records to look through</p>
|
||||
* @param playerId <p>The id of the player to look for</p>
|
||||
* @param <T> <p>The type of the stored record</p>
|
||||
* @return <p>The record, or null if not found</p>
|
||||
*/
|
||||
private <T extends Comparable<T>> @Nullable ArenaRecord<T> getRecord(@NotNull Set<ArenaRecord<T>> existingRecords,
|
||||
@NotNull UUID playerId) {
|
||||
AtomicReference<ArenaRecord<T>> record = new AtomicReference<>();
|
||||
existingRecords.forEach((item) -> {
|
||||
if (item.getUserId().equals(playerId)) {
|
||||
record.set(item);
|
||||
}
|
||||
});
|
||||
return record.get();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Map<String, Object> serialize() {
|
||||
Map<String, Object> data = new HashMap<>();
|
||||
data.put("arenaId", new SerializableUUID(this.arenaId));
|
||||
data.put("leastDeaths", this.leastDeaths);
|
||||
data.put("shortestTime", this.shortestTimeMilliSeconds);
|
||||
return data;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,55 @@
|
||||
package net.knarcraft.minigames.arena;
|
||||
|
||||
import net.knarcraft.minigames.gui.ArenaGUI;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* A player's session while in an arena
|
||||
*/
|
||||
public interface ArenaSession {
|
||||
|
||||
/**
|
||||
* Gets the state of the player when they joined the session
|
||||
*
|
||||
* @return <p>The player's entry state</p>
|
||||
*/
|
||||
@NotNull PlayerEntryState getEntryState();
|
||||
|
||||
/**
|
||||
* Triggers a win for the player playing in this session
|
||||
*/
|
||||
void triggerWin();
|
||||
|
||||
/**
|
||||
* Triggers a loss for the player playing in this session
|
||||
*/
|
||||
void triggerLoss();
|
||||
|
||||
/**
|
||||
* Triggers a quit for the player playing in this session
|
||||
*
|
||||
* @param immediately <p>Whether to to the teleportation immediately, not using any timers</p>
|
||||
* @param removeSession <p>Whether to also remove the session. Should usually be true.</p>
|
||||
*/
|
||||
void triggerQuit(boolean immediately, boolean removeSession);
|
||||
|
||||
/**
|
||||
* Gets the arena this session is being played in
|
||||
*
|
||||
* @return <p>The session's arena</p>
|
||||
*/
|
||||
@NotNull Arena getArena();
|
||||
|
||||
/**
|
||||
* Gets the GUI with this arena's options
|
||||
*
|
||||
* @return <p>This arena's GUI</p>
|
||||
*/
|
||||
@NotNull ArenaGUI getGUI();
|
||||
|
||||
/**
|
||||
* Resets the session to allow a player to try again
|
||||
*/
|
||||
void reset();
|
||||
|
||||
}
|
@ -0,0 +1,48 @@
|
||||
package net.knarcraft.minigames.arena;
|
||||
|
||||
/**
|
||||
* The type of one editable property
|
||||
*/
|
||||
public enum EditablePropertyType {
|
||||
|
||||
/**
|
||||
* The property is a location
|
||||
*/
|
||||
LOCATION,
|
||||
|
||||
/**
|
||||
* The property is an arena name
|
||||
*/
|
||||
ARENA_NAME,
|
||||
|
||||
/**
|
||||
* The property is a horizontal velocity
|
||||
*/
|
||||
HORIZONTAL_VELOCITY,
|
||||
|
||||
/**
|
||||
* The property is a vertical velocity (fly speed)
|
||||
*/
|
||||
VERTICAL_VELOCITY,
|
||||
|
||||
/**
|
||||
* The property is a material that specifies a block
|
||||
*/
|
||||
BLOCK_TYPE,
|
||||
|
||||
/**
|
||||
* The property clears a checkpoint
|
||||
*/
|
||||
CHECKPOINT_CLEAR,
|
||||
|
||||
/**
|
||||
* The property is a comma-separated list of materials
|
||||
*/
|
||||
MATERIAL_LIST,
|
||||
|
||||
/**
|
||||
* The property is any double value
|
||||
*/
|
||||
DOUBLE,
|
||||
|
||||
}
|
@ -0,0 +1,45 @@
|
||||
package net.knarcraft.minigames.arena;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.configuration.serialization.ConfigurationSerializable;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* The stored state of a player
|
||||
*/
|
||||
public interface PlayerEntryState extends ConfigurationSerializable {
|
||||
|
||||
/**
|
||||
* Sets the state of the stored player to the state used by the arena
|
||||
*/
|
||||
void setArenaState();
|
||||
|
||||
/**
|
||||
* Restores the stored state for the stored player
|
||||
*/
|
||||
boolean restore();
|
||||
|
||||
/**
|
||||
* Restores the stored state for the given player
|
||||
*
|
||||
* @param player <p>A player object that's refers to the same player as the stored player</p>
|
||||
*/
|
||||
void restore(Player player);
|
||||
|
||||
/**
|
||||
* Gets the id of the player this state belongs to
|
||||
*
|
||||
* @return <p>The player the state belongs to</p>
|
||||
*/
|
||||
UUID getPlayerId();
|
||||
|
||||
/**
|
||||
* Gets the location the player entered from
|
||||
*
|
||||
* @return <p>The location the player entered from</p>
|
||||
*/
|
||||
Location getEntryLocation();
|
||||
|
||||
}
|
@ -0,0 +1,109 @@
|
||||
package net.knarcraft.minigames.arena;
|
||||
|
||||
import net.knarcraft.minigames.MiniGames;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* A manager for keeping track of which players have set other players as hidden
|
||||
*/
|
||||
public class PlayerVisibilityManager {
|
||||
|
||||
private final Set<UUID> displayingEnabledFor = new HashSet<>();
|
||||
|
||||
/**
|
||||
* Toggles whether players should be hidden for the player with the given id
|
||||
*
|
||||
* @param player <p>The the player to update</p>
|
||||
*/
|
||||
public void toggleHidePlayers(@NotNull ArenaPlayerRegistry<?> playerRegistry, @NotNull Player player) {
|
||||
if (displayingEnabledFor.contains(player.getUniqueId())) {
|
||||
displayingEnabledFor.remove(player.getUniqueId());
|
||||
// Make all other players hidden
|
||||
changeVisibilityFor(playerRegistry, player, true);
|
||||
} else {
|
||||
displayingEnabledFor.add(player.getUniqueId());
|
||||
// Make all other players visible again
|
||||
changeVisibilityFor(playerRegistry, player, false);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets whether the given player is currently hiding other players
|
||||
*
|
||||
* @param player <p>The player to check</p>
|
||||
* @return <p>True if currently hiding other players</p>
|
||||
*/
|
||||
public boolean isHidingPlayers(Player player) {
|
||||
return !this.displayingEnabledFor.contains(player.getUniqueId());
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates which players are seen as hidden
|
||||
*
|
||||
* @param playerRegistry <p>The registry containing all playing players</p>
|
||||
* @param player <p>The player that joined the arena</p>
|
||||
*/
|
||||
public void updateHiddenPlayers(@NotNull ArenaPlayerRegistry<?> playerRegistry, @NotNull Player player) {
|
||||
boolean hideForPlayer = !displayingEnabledFor.contains(player.getUniqueId());
|
||||
for (UUID playerId : playerRegistry.getPlayingPlayers()) {
|
||||
Player otherPlayer = Bukkit.getPlayer(playerId);
|
||||
if (otherPlayer == null) {
|
||||
continue;
|
||||
}
|
||||
// Hide the arena player from the newly joined player
|
||||
if (hideForPlayer) {
|
||||
player.hidePlayer(MiniGames.getInstance(), otherPlayer);
|
||||
}
|
||||
// Hide the newly joined player from this player
|
||||
if (!displayingEnabledFor.contains(playerId)) {
|
||||
otherPlayer.hidePlayer(MiniGames.getInstance(), player);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Makes all players visible to the given player
|
||||
*
|
||||
* @param player <p>The player to update visibility for</p>
|
||||
*/
|
||||
public void showPlayersFor(@NotNull Player player) {
|
||||
for (Player otherPlayer : Bukkit.getOnlinePlayers()) {
|
||||
player.showPlayer(MiniGames.getInstance(), otherPlayer);
|
||||
otherPlayer.showPlayer(MiniGames.getInstance(), player);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Changes whether the given player can see the other players in the arena
|
||||
*
|
||||
* @param playerRegistry <p>The player registry containing other players</p>
|
||||
* @param player <p>The player to change the visibility for</p>
|
||||
* @param hide <p>Whether to hide the players or show the players</p>
|
||||
*/
|
||||
private void changeVisibilityFor(@Nullable ArenaPlayerRegistry<?> playerRegistry, @NotNull Player player, boolean hide) {
|
||||
if (playerRegistry == null) {
|
||||
return;
|
||||
}
|
||||
for (UUID playerId : playerRegistry.getPlayingPlayers()) {
|
||||
Player otherPlayer = Bukkit.getPlayer(playerId);
|
||||
if (otherPlayer == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (hide) {
|
||||
player.hidePlayer(MiniGames.getInstance(), otherPlayer);
|
||||
} else {
|
||||
player.showPlayer(MiniGames.getInstance(), otherPlayer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,22 +1,34 @@
|
||||
package net.knarcraft.dropper.arena;
|
||||
package net.knarcraft.minigames.arena.dropper;
|
||||
|
||||
import net.knarcraft.dropper.Dropper;
|
||||
import net.knarcraft.dropper.property.ArenaGameMode;
|
||||
import net.knarcraft.dropper.util.StringSanitizer;
|
||||
import net.knarcraft.minigames.MiniGames;
|
||||
import net.knarcraft.minigames.arena.Arena;
|
||||
import net.knarcraft.minigames.arena.ArenaGameMode;
|
||||
import net.knarcraft.minigames.arena.ArenaRecordsRegistry;
|
||||
import net.knarcraft.minigames.arena.reward.Reward;
|
||||
import net.knarcraft.minigames.arena.reward.RewardCondition;
|
||||
import net.knarcraft.minigames.config.DropperConfiguration;
|
||||
import net.knarcraft.minigames.util.DropperArenaStorageHelper;
|
||||
import net.knarcraft.minigames.util.StringSanitizer;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Block;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import static net.knarcraft.minigames.util.InputValidationHelper.isInvalid;
|
||||
|
||||
/**
|
||||
* A representation of one dropper arena
|
||||
*/
|
||||
public class DropperArena {
|
||||
public class DropperArena implements Arena {
|
||||
|
||||
/**
|
||||
* An unique and persistent identifier for this arena
|
||||
@ -61,7 +73,11 @@ public class DropperArena {
|
||||
*/
|
||||
private final DropperArenaData dropperArenaData;
|
||||
|
||||
private static DropperArenaHandler dropperArenaHandler = null;
|
||||
private final DropperArenaHandler dropperArenaHandler;
|
||||
|
||||
private Map<RewardCondition, Set<Reward>> rewards = new HashMap<>();
|
||||
|
||||
private static final DropperConfiguration dropperConfiguration = MiniGames.getInstance().getDropperConfiguration();
|
||||
|
||||
/**
|
||||
* Instantiates a new dropper arena
|
||||
@ -73,11 +89,14 @@ public class DropperArena {
|
||||
* @param playerVerticalVelocity <p>The velocity to use for players' vertical velocity</p>
|
||||
* @param playerHorizontalVelocity <p>The velocity to use for players' horizontal velocity (-1 to 1)</p>
|
||||
* @param winBlockType <p>The material of the block players have to hit to win this dropper arena</p>
|
||||
* @param rewards <p>The rewards given by this arena</p>
|
||||
* @param dropperArenaData <p>The arena data keeping track of which players have done what in this arena</p>
|
||||
* @param arenaHandler <p>The arena handler used for saving any changes</p>
|
||||
*/
|
||||
public DropperArena(@NotNull UUID arenaId, @NotNull String arenaName, @NotNull Location spawnLocation,
|
||||
@Nullable Location exitLocation, double playerVerticalVelocity, float playerHorizontalVelocity,
|
||||
@NotNull Material winBlockType, @NotNull DropperArenaData dropperArenaData) {
|
||||
@NotNull Material winBlockType, @NotNull Map<RewardCondition, Set<Reward>> rewards,
|
||||
@NotNull DropperArenaData dropperArenaData, @NotNull DropperArenaHandler arenaHandler) {
|
||||
this.arenaId = arenaId;
|
||||
this.arenaName = arenaName;
|
||||
this.spawnLocation = spawnLocation;
|
||||
@ -86,10 +105,8 @@ public class DropperArena {
|
||||
this.playerHorizontalVelocity = playerHorizontalVelocity;
|
||||
this.winBlockType = winBlockType;
|
||||
this.dropperArenaData = dropperArenaData;
|
||||
|
||||
if (dropperArenaHandler == null) {
|
||||
dropperArenaHandler = Dropper.getInstance().getArenaHandler();
|
||||
}
|
||||
this.dropperArenaHandler = arenaHandler;
|
||||
this.rewards = rewards;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -100,69 +117,73 @@ public class DropperArena {
|
||||
*
|
||||
* @param arenaName <p>The name of the arena</p>
|
||||
* @param spawnLocation <p>The location players spawn in when entering the arena</p>
|
||||
* @param arenaHandler <p>The arena handler used for saving any changes</p>
|
||||
*/
|
||||
public DropperArena(@NotNull String arenaName, @NotNull Location spawnLocation) {
|
||||
public DropperArena(@NotNull String arenaName, @NotNull Location spawnLocation,
|
||||
@NotNull DropperArenaHandler arenaHandler) {
|
||||
DropperConfiguration configuration = MiniGames.getInstance().getDropperConfiguration();
|
||||
this.arenaId = UUID.randomUUID();
|
||||
this.arenaName = arenaName;
|
||||
this.spawnLocation = spawnLocation;
|
||||
this.exitLocation = null;
|
||||
this.playerVerticalVelocity = 3.92;
|
||||
this.playerHorizontalVelocity = 1;
|
||||
this.playerVerticalVelocity = configuration.getVerticalVelocity();
|
||||
this.playerHorizontalVelocity = configuration.getHorizontalVelocity();
|
||||
|
||||
Map<ArenaGameMode, DropperArenaRecordsRegistry> recordRegistries = new HashMap<>();
|
||||
for (ArenaGameMode arenaGameMode : ArenaGameMode.values()) {
|
||||
Map<ArenaGameMode, ArenaRecordsRegistry> recordRegistries = new HashMap<>();
|
||||
for (ArenaGameMode arenaGameMode : DropperArenaGameMode.values()) {
|
||||
recordRegistries.put(arenaGameMode, new DropperArenaRecordsRegistry(this.arenaId));
|
||||
}
|
||||
|
||||
this.dropperArenaData = new DropperArenaData(this.arenaId, recordRegistries, new HashMap<>());
|
||||
this.winBlockType = Material.WATER;
|
||||
this.dropperArenaHandler = arenaHandler;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets this arena's data
|
||||
*
|
||||
* @return <p>This arena's data</p>
|
||||
*/
|
||||
@Override
|
||||
public @NotNull DropperArenaData getData() {
|
||||
return this.dropperArenaData;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the id of this arena
|
||||
*
|
||||
* @return <p>This arena's identifier</p>
|
||||
*/
|
||||
@Override
|
||||
public @NotNull UUID getArenaId() {
|
||||
return this.arenaId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the name of this arena
|
||||
*
|
||||
* @return <p>The name of this arena</p>
|
||||
*/
|
||||
@Override
|
||||
public @NotNull String getArenaName() {
|
||||
return this.arenaName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets this arena's spawn location
|
||||
*
|
||||
* <p>The spawn location is the location every player starts from when entering the dropper.</p>
|
||||
*
|
||||
* @return <p>This arena's spawn location.</p>
|
||||
*/
|
||||
@Override
|
||||
public @NotNull Location getSpawnLocation() {
|
||||
return this.spawnLocation;
|
||||
return this.spawnLocation.clone();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets this arena's exit location
|
||||
*
|
||||
* @return <p>This arena's exit location, or null if no such location is set.</p>
|
||||
*/
|
||||
@Override
|
||||
public @Nullable Location getExitLocation() {
|
||||
return this.exitLocation;
|
||||
return this.exitLocation != null ? this.exitLocation.clone() : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addReward(@NotNull RewardCondition rewardCondition, @NotNull Reward reward) {
|
||||
this.rewards.computeIfAbsent(rewardCondition, k -> new HashSet<>());
|
||||
this.rewards.get(rewardCondition).add(reward);
|
||||
this.saveArena();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearRewards(@NotNull RewardCondition rewardCondition) {
|
||||
this.rewards.remove(rewardCondition);
|
||||
this.saveArena();
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Set<Reward> getRewards(RewardCondition rewardCondition) {
|
||||
if (this.rewards.containsKey(rewardCondition) && this.rewards.get(rewardCondition) != null) {
|
||||
return this.rewards.get(rewardCondition);
|
||||
} else {
|
||||
return new HashSet<>();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -206,6 +227,36 @@ public class DropperArena {
|
||||
return StringSanitizer.sanitizeArenaName(this.getArenaName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean removeData() {
|
||||
return DropperArenaStorageHelper.removeDropperArenaData(getArenaId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean saveData() {
|
||||
try {
|
||||
DropperArenaStorageHelper.saveDropperArenaData(getData());
|
||||
return true;
|
||||
} catch (IOException exception) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean willCauseWin(Block block) {
|
||||
return block.getType() == winBlockType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean willCauseLoss(Block block) {
|
||||
return !dropperConfiguration.getBlockWhitelist().contains(block.getType());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean winLocationIsSolid() {
|
||||
return winBlockType.isSolid();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the spawn location for this arena
|
||||
*
|
||||
@ -217,7 +268,7 @@ public class DropperArena {
|
||||
return false;
|
||||
} else {
|
||||
this.spawnLocation = newLocation;
|
||||
dropperArenaHandler.saveArenas();
|
||||
this.saveArena();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@ -233,7 +284,7 @@ public class DropperArena {
|
||||
return false;
|
||||
} else {
|
||||
this.exitLocation = newLocation;
|
||||
dropperArenaHandler.saveArenas();
|
||||
this.saveArena();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@ -249,8 +300,8 @@ public class DropperArena {
|
||||
String oldName = this.getArenaNameSanitized();
|
||||
this.arenaName = arenaName;
|
||||
// Update the arena lookup map to make sure the new name can be used immediately
|
||||
dropperArenaHandler.updateLookupName(oldName, this.getArenaNameSanitized());
|
||||
dropperArenaHandler.saveArenas();
|
||||
this.dropperArenaHandler.updateLookupName(oldName, this.getArenaNameSanitized());
|
||||
this.saveArena();
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
@ -270,7 +321,7 @@ public class DropperArena {
|
||||
return false;
|
||||
} else {
|
||||
this.winBlockType = material;
|
||||
dropperArenaHandler.saveArenas();
|
||||
this.saveArena();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@ -288,7 +339,7 @@ public class DropperArena {
|
||||
return false;
|
||||
} else {
|
||||
this.playerHorizontalVelocity = horizontalVelocity;
|
||||
dropperArenaHandler.saveArenas();
|
||||
this.saveArena();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@ -304,11 +355,24 @@ public class DropperArena {
|
||||
return false;
|
||||
} else {
|
||||
this.playerVerticalVelocity = verticalVelocity;
|
||||
dropperArenaHandler.saveArenas();
|
||||
this.saveArena();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves this arena to disk
|
||||
*/
|
||||
public void saveArena() {
|
||||
try {
|
||||
DropperArenaStorageHelper.saveSingleDropperArena(this);
|
||||
} catch (IOException exception) {
|
||||
MiniGames.log(Level.SEVERE, "Unable to save arena! " +
|
||||
"Data loss can occur!");
|
||||
MiniGames.log(Level.SEVERE, exception.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object other) {
|
||||
if (!(other instanceof DropperArena otherArena)) {
|
||||
@ -317,15 +381,4 @@ public class DropperArena {
|
||||
return this.getArenaNameSanitized().equals(otherArena.getArenaNameSanitized());
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether the given location is valid
|
||||
*
|
||||
* @param location <p>The location to validate</p>
|
||||
* @return <p>False if the location is valid</p>
|
||||
*/
|
||||
private boolean isInvalid(Location location) {
|
||||
World world = location.getWorld();
|
||||
return world == null || !world.getWorldBorder().isInside(location);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,72 @@
|
||||
package net.knarcraft.minigames.arena.dropper;
|
||||
|
||||
import net.knarcraft.minigames.MiniGames;
|
||||
import net.knarcraft.minigames.arena.ArenaData;
|
||||
import net.knarcraft.minigames.arena.ArenaGameMode;
|
||||
import net.knarcraft.minigames.arena.ArenaRecordsRegistry;
|
||||
import net.knarcraft.minigames.container.SerializableContainer;
|
||||
import net.knarcraft.minigames.container.SerializableUUID;
|
||||
import net.knarcraft.minigames.util.SerializableConverter;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Data stored for an arena
|
||||
*/
|
||||
public class DropperArenaData extends ArenaData {
|
||||
|
||||
/**
|
||||
* Instantiates a new dropper arena data object
|
||||
*
|
||||
* @param arenaId <p>The id of the arena this data belongs to</p>
|
||||
* @param recordRegistries <p>The registries of this arena's records</p>
|
||||
* @param playersCompleted <p>The set of the players that have cleared this arena for each game-mode</p>
|
||||
*/
|
||||
public DropperArenaData(@NotNull UUID arenaId,
|
||||
@NotNull Map<ArenaGameMode, ArenaRecordsRegistry> recordRegistries,
|
||||
@NotNull Map<ArenaGameMode, Set<UUID>> playersCompleted) {
|
||||
super(arenaId, recordRegistries, playersCompleted);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveData() {
|
||||
MiniGames.getInstance().getDropperArenaHandler().saveData(this.arenaId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deserializes a dropper arena data from the given data
|
||||
*
|
||||
* @param data <p>The data to deserialize</p>
|
||||
* @return <p>The deserialized dropper arena data</p>
|
||||
*/
|
||||
@SuppressWarnings({"unused", "unchecked"})
|
||||
public static @NotNull DropperArenaData deserialize(@NotNull Map<String, Object> data) {
|
||||
SerializableUUID serializableUUID = (SerializableUUID) data.get("arenaId");
|
||||
Map<ArenaGameMode, ArenaRecordsRegistry> recordsRegistry =
|
||||
(Map<ArenaGameMode, ArenaRecordsRegistry>) data.get("recordsRegistry");
|
||||
Map<ArenaGameMode, Set<SerializableContainer<UUID>>> playersCompletedData =
|
||||
(Map<ArenaGameMode, Set<SerializableContainer<UUID>>>) data.get("playersCompleted");
|
||||
|
||||
if (recordsRegistry == null) {
|
||||
recordsRegistry = new HashMap<>();
|
||||
} else if (playersCompletedData == null) {
|
||||
playersCompletedData = new HashMap<>();
|
||||
}
|
||||
|
||||
// Convert the serializable UUIDs to normal UUIDs
|
||||
Map<ArenaGameMode, Set<UUID>> allPlayersCompleted = new HashMap<>();
|
||||
SerializableConverter.getRawValue(playersCompletedData, allPlayersCompleted);
|
||||
|
||||
for (ArenaGameMode arenaGameMode : playersCompletedData.keySet()) {
|
||||
if (!recordsRegistry.containsKey(arenaGameMode) || recordsRegistry.get(arenaGameMode) == null) {
|
||||
recordsRegistry.put(arenaGameMode, new DropperArenaRecordsRegistry(serializableUUID.getRawValue()));
|
||||
}
|
||||
}
|
||||
return new DropperArenaData(serializableUUID.getRawValue(), recordsRegistry, allPlayersCompleted);
|
||||
}
|
||||
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
package net.knarcraft.dropper.property;
|
||||
package net.knarcraft.minigames.arena.dropper;
|
||||
|
||||
import net.knarcraft.dropper.arena.DropperArena;
|
||||
import net.knarcraft.minigames.arena.EditablePropertyType;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@ -9,50 +9,67 @@ import java.util.function.Function;
|
||||
/**
|
||||
* All editable properties of a dropper arena
|
||||
*/
|
||||
public enum ArenaEditableProperty {
|
||||
public enum DropperArenaEditableProperty {
|
||||
|
||||
/**
|
||||
* The name of the arena
|
||||
*/
|
||||
NAME("name", DropperArena::getArenaName),
|
||||
NAME("name", DropperArena::getArenaName, EditablePropertyType.ARENA_NAME),
|
||||
|
||||
/**
|
||||
* The arena's spawn location
|
||||
*/
|
||||
SPAWN_LOCATION("spawnLocation", (arena) -> String.valueOf(arena.getSpawnLocation())),
|
||||
SPAWN_LOCATION("spawnLocation", (arena) -> String.valueOf(arena.getSpawnLocation()),
|
||||
EditablePropertyType.LOCATION),
|
||||
|
||||
/**
|
||||
* The arena's exit location
|
||||
*/
|
||||
EXIT_LOCATION("exitLocation", (arena) -> String.valueOf(arena.getExitLocation())),
|
||||
EXIT_LOCATION("exitLocation", (arena) -> String.valueOf(arena.getExitLocation()),
|
||||
EditablePropertyType.LOCATION),
|
||||
|
||||
/**
|
||||
* The arena's vertical velocity
|
||||
*/
|
||||
VERTICAL_VELOCITY("verticalVelocity", (arena) -> String.valueOf(arena.getPlayerVerticalVelocity())),
|
||||
VERTICAL_VELOCITY("verticalVelocity", (arena) -> String.valueOf(arena.getPlayerVerticalVelocity()),
|
||||
EditablePropertyType.VERTICAL_VELOCITY),
|
||||
|
||||
/**
|
||||
* The arena's horizontal velocity
|
||||
*/
|
||||
HORIZONTAL_VELOCITY("horizontalVelocity", (arena) -> String.valueOf(arena.getPlayerHorizontalVelocity())),
|
||||
HORIZONTAL_VELOCITY("horizontalVelocity", (arena) -> String.valueOf(arena.getPlayerHorizontalVelocity()),
|
||||
EditablePropertyType.HORIZONTAL_VELOCITY),
|
||||
|
||||
/**
|
||||
* The arena's win block type
|
||||
*/
|
||||
WIN_BLOCK_TYPE("winBlockType", (arena) -> arena.getWinBlockType().toString()),
|
||||
WIN_BLOCK_TYPE("winBlockType", (arena) -> arena.getWinBlockType().toString(),
|
||||
EditablePropertyType.BLOCK_TYPE),
|
||||
;
|
||||
|
||||
private final @NotNull String argumentString;
|
||||
private final Function<DropperArena, String> currentValueProvider;
|
||||
private final EditablePropertyType propertyType;
|
||||
|
||||
/**
|
||||
* Instantiates a new arena editable property
|
||||
*
|
||||
* @param argumentString <p>The argument string used to specify this property</p>
|
||||
*/
|
||||
ArenaEditableProperty(@NotNull String argumentString, Function<DropperArena, String> currentValueProvider) {
|
||||
DropperArenaEditableProperty(@NotNull String argumentString, Function<DropperArena, String> currentValueProvider,
|
||||
EditablePropertyType propertyType) {
|
||||
this.argumentString = argumentString;
|
||||
this.currentValueProvider = currentValueProvider;
|
||||
this.propertyType = propertyType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the type of property this editable property represents
|
||||
*
|
||||
* @return <p>The type of this property</p>
|
||||
*/
|
||||
public EditablePropertyType getPropertyType() {
|
||||
return this.propertyType;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -80,8 +97,8 @@ public enum ArenaEditableProperty {
|
||||
* @param argumentString <p>The argument string used to specify an editable property</p>
|
||||
* @return <p>The corresponding editable property, or null if not found</p>
|
||||
*/
|
||||
public static @Nullable ArenaEditableProperty getFromArgumentString(String argumentString) {
|
||||
for (ArenaEditableProperty property : ArenaEditableProperty.values()) {
|
||||
public static @Nullable DropperArenaEditableProperty getFromArgumentString(String argumentString) {
|
||||
for (DropperArenaEditableProperty property : DropperArenaEditableProperty.values()) {
|
||||
if (property.argumentString.equalsIgnoreCase(argumentString)) {
|
||||
return property;
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
package net.knarcraft.dropper.property;
|
||||
package net.knarcraft.minigames.arena.dropper;
|
||||
|
||||
import net.knarcraft.minigames.arena.ArenaGameMode;
|
||||
import org.bukkit.configuration.serialization.ConfigurationSerializable;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@ -9,7 +10,7 @@ import java.util.Map;
|
||||
/**
|
||||
* A representation of possible arena game-modes
|
||||
*/
|
||||
public enum ArenaGameMode implements ConfigurationSerializable {
|
||||
public enum DropperArenaGameMode implements ConfigurationSerializable, ArenaGameMode {
|
||||
|
||||
/**
|
||||
* The default game-mode. Failing once throws the player out.
|
||||
@ -33,14 +34,14 @@ public enum ArenaGameMode implements ConfigurationSerializable {
|
||||
* @param gameMode <p>The game-mode string to match</p>
|
||||
* @return <p>The specified arena game-mode</p>
|
||||
*/
|
||||
public static @NotNull ArenaGameMode matchGamemode(@NotNull String gameMode) {
|
||||
public static @NotNull DropperArenaGameMode matchGameMode(@NotNull String gameMode) {
|
||||
String sanitized = gameMode.trim().toLowerCase();
|
||||
if (sanitized.matches("(invert(ed)?|inverse)")) {
|
||||
return ArenaGameMode.INVERTED;
|
||||
} else if (sanitized.matches("rand(om)?")) {
|
||||
return ArenaGameMode.RANDOM_INVERTED;
|
||||
return DropperArenaGameMode.INVERTED;
|
||||
} else if (sanitized.matches("rand(om)?_?(inverted)?")) {
|
||||
return DropperArenaGameMode.RANDOM_INVERTED;
|
||||
} else {
|
||||
return ArenaGameMode.DEFAULT;
|
||||
return DropperArenaGameMode.DEFAULT;
|
||||
}
|
||||
}
|
||||
|
||||
@ -59,8 +60,13 @@ public enum ArenaGameMode implements ConfigurationSerializable {
|
||||
* @return <p>The deserialized arena game-mode</p>
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public static ArenaGameMode deserialize(Map<String, Object> data) {
|
||||
return ArenaGameMode.valueOf((String) data.get("name"));
|
||||
public static DropperArenaGameMode deserialize(Map<String, Object> data) {
|
||||
return DropperArenaGameMode.valueOf((String) data.get("name"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull DropperArenaGameMode[] getValues() {
|
||||
return DropperArenaGameMode.values();
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,56 @@
|
||||
package net.knarcraft.minigames.arena.dropper;
|
||||
|
||||
import net.knarcraft.minigames.MiniGames;
|
||||
import net.knarcraft.minigames.arena.ArenaGroup;
|
||||
import net.knarcraft.minigames.container.SerializableUUID;
|
||||
import net.knarcraft.minigames.util.SerializableConverter;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* A sorted group of arenas that must be completed in sequence
|
||||
*/
|
||||
public class DropperArenaGroup extends ArenaGroup<DropperArena, DropperArenaGroup> {
|
||||
|
||||
/**
|
||||
* Instantiates a new dropper arena group
|
||||
*
|
||||
* @param groupName <p>The name of this group</p>
|
||||
*/
|
||||
public DropperArenaGroup(@NotNull String groupName) {
|
||||
super(groupName, MiniGames.getInstance().getDropperArenaHandler());
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a new dropper arena group
|
||||
*
|
||||
* @param groupId <p>The unique id of this group</p>
|
||||
* @param groupName <p>The name of this group</p>
|
||||
* @param arenas <p>The arenas in this group</p>
|
||||
*/
|
||||
private DropperArenaGroup(@NotNull UUID groupId, @NotNull String groupName, @NotNull List<UUID> arenas) {
|
||||
super(groupId, groupName, arenas, MiniGames.getInstance().getDropperArenaHandler());
|
||||
}
|
||||
|
||||
/**
|
||||
* Deserializes the given data
|
||||
*
|
||||
* @param data <p>The data to deserialize</p>
|
||||
* @return <p>The deserialized arena group</p>
|
||||
*/
|
||||
@SuppressWarnings({"unused", "unchecked"})
|
||||
public static @NotNull DropperArenaGroup deserialize(@NotNull Map<String, Object> data) {
|
||||
UUID id = ((SerializableUUID) data.get("groupId")).getRawValue();
|
||||
String name = (String) data.get("groupName");
|
||||
List<SerializableUUID> serializableArenas = (List<SerializableUUID>) data.get("arenas");
|
||||
List<UUID> arenas = new ArrayList<>();
|
||||
|
||||
SerializableConverter.getRawValue(new ArrayList<>(serializableArenas), arenas);
|
||||
return new DropperArenaGroup(id, name, arenas);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,77 @@
|
||||
package net.knarcraft.minigames.arena.dropper;
|
||||
|
||||
import net.knarcraft.minigames.MiniGames;
|
||||
import net.knarcraft.minigames.arena.ArenaHandler;
|
||||
import net.knarcraft.minigames.arena.ArenaPlayerRegistry;
|
||||
import net.knarcraft.minigames.config.MiniGameMessage;
|
||||
import net.knarcraft.minigames.util.DropperArenaStorageHelper;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.logging.Level;
|
||||
|
||||
/**
|
||||
* A handler that keeps track of all dropper arenas
|
||||
*/
|
||||
public class DropperArenaHandler extends ArenaHandler<DropperArena, DropperArenaGroup> {
|
||||
|
||||
/**
|
||||
* Instantiates a new arena handler
|
||||
*
|
||||
* @param playerRegistry <p>The registry keeping track of player sessions</p>
|
||||
*/
|
||||
public DropperArenaHandler(ArenaPlayerRegistry<DropperArena> playerRegistry) {
|
||||
super(playerRegistry);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveGroups() {
|
||||
try {
|
||||
DropperArenaStorageHelper.saveDropperArenaGroups(new HashSet<>(this.arenaGroups.values()));
|
||||
} catch (IOException exception) {
|
||||
MiniGames.log(Level.SEVERE, MiniGames.getInstance().getTranslator().getTranslatedMessage(
|
||||
MiniGameMessage.ERROR_CANNOT_SAVE_ARENA_GROUPS));
|
||||
MiniGames.log(Level.SEVERE, exception.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void loadGroups() {
|
||||
Set<DropperArenaGroup> arenaGroups = DropperArenaStorageHelper.loadDropperArenaGroups();
|
||||
Map<UUID, DropperArenaGroup> arenaGroupMap = new HashMap<>();
|
||||
for (DropperArenaGroup arenaGroup : arenaGroups) {
|
||||
for (UUID arenaId : arenaGroup.getArenas()) {
|
||||
arenaGroupMap.put(arenaId, arenaGroup);
|
||||
}
|
||||
}
|
||||
this.arenaGroups = arenaGroupMap;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveArenas() {
|
||||
try {
|
||||
DropperArenaStorageHelper.saveDropperArenas(this.arenas);
|
||||
} catch (IOException exception) {
|
||||
MiniGames.log(Level.SEVERE, "Unable to save current arenas! " +
|
||||
"Data loss can occur!");
|
||||
MiniGames.log(Level.SEVERE, exception.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void loadArenas() {
|
||||
this.arenas = DropperArenaStorageHelper.loadDropperArenas();
|
||||
|
||||
// Save a map from arena name to arena id for improved performance
|
||||
this.arenaNameLookup = new HashMap<>();
|
||||
for (Map.Entry<UUID, DropperArena> arena : this.arenas.entrySet()) {
|
||||
String sanitizedName = arena.getValue().getArenaNameSanitized();
|
||||
this.arenaNameLookup.put(sanitizedName, arena.getKey());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
package net.knarcraft.minigames.arena.dropper;
|
||||
|
||||
import net.knarcraft.minigames.arena.AbstractArenaPlayerRegistry;
|
||||
|
||||
/**
|
||||
* A registry to keep track of which players are playing in which arenas
|
||||
*/
|
||||
public class DropperArenaPlayerRegistry extends AbstractArenaPlayerRegistry<DropperArena> {
|
||||
|
||||
@Override
|
||||
protected String getEntryStateStorageKey() {
|
||||
return "dropper";
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,65 @@
|
||||
package net.knarcraft.minigames.arena.dropper;
|
||||
|
||||
import net.knarcraft.minigames.MiniGames;
|
||||
import net.knarcraft.minigames.arena.ArenaRecordsRegistry;
|
||||
import net.knarcraft.minigames.arena.record.IntegerRecord;
|
||||
import net.knarcraft.minigames.arena.record.LongRecord;
|
||||
import net.knarcraft.minigames.container.SerializableUUID;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* A registry keeping track of all records
|
||||
*/
|
||||
public class DropperArenaRecordsRegistry extends ArenaRecordsRegistry {
|
||||
|
||||
/**
|
||||
* Instantiates a new empty records registry
|
||||
*/
|
||||
public DropperArenaRecordsRegistry(@NotNull UUID arenaId) {
|
||||
super(arenaId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a new records registry
|
||||
*
|
||||
* @param leastDeaths <p>The existing least death records to use</p>
|
||||
* @param shortestTimeMilliSeconds <p>The existing leash time records to use</p>
|
||||
*/
|
||||
private DropperArenaRecordsRegistry(@NotNull UUID arenaId, @NotNull Set<IntegerRecord> leastDeaths,
|
||||
@NotNull Set<LongRecord> shortestTimeMilliSeconds) {
|
||||
super(arenaId, leastDeaths, shortestTimeMilliSeconds);
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves changed records
|
||||
*/
|
||||
protected void save() {
|
||||
MiniGames.getInstance().getDropperArenaHandler().saveData(this.arenaId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deserializes the given data
|
||||
*
|
||||
* @param data <p>The data to deserialize</p>
|
||||
* @return <p>The deserialized records registry</p>
|
||||
*/
|
||||
@SuppressWarnings({"unused", "unchecked"})
|
||||
public static DropperArenaRecordsRegistry deserialize(Map<String, Object> data) {
|
||||
UUID arenaId = ((SerializableUUID) data.get("arenaId")).getRawValue();
|
||||
Set<IntegerRecord> leastDeaths =
|
||||
(Set<IntegerRecord>) data.getOrDefault("leastDeaths", new HashMap<>());
|
||||
Set<LongRecord> shortestTimeMilliseconds =
|
||||
(Set<LongRecord>) data.getOrDefault("shortestTime", new HashMap<>());
|
||||
|
||||
leastDeaths.removeIf(Objects::isNull);
|
||||
shortestTimeMilliseconds.removeIf(Objects::isNull);
|
||||
return new DropperArenaRecordsRegistry(arenaId, leastDeaths, shortestTimeMilliseconds);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,156 @@
|
||||
package net.knarcraft.minigames.arena.dropper;
|
||||
|
||||
import net.knarcraft.knarlib.formatting.StringFormatter;
|
||||
import net.knarcraft.minigames.MiniGames;
|
||||
import net.knarcraft.minigames.arena.AbstractArenaSession;
|
||||
import net.knarcraft.minigames.arena.PlayerEntryState;
|
||||
import net.knarcraft.minigames.arena.reward.RewardCondition;
|
||||
import net.knarcraft.minigames.config.MiniGameMessage;
|
||||
import net.knarcraft.minigames.gui.ArenaGUI;
|
||||
import net.knarcraft.minigames.gui.DropperGUI;
|
||||
import net.knarcraft.minigames.util.PlayerTeleporter;
|
||||
import net.knarcraft.minigames.util.RewardHelper;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.logging.Level;
|
||||
|
||||
/**
|
||||
* A representation of a player's current session in a dropper arena
|
||||
*/
|
||||
public class DropperArenaSession extends AbstractArenaSession {
|
||||
|
||||
private final @NotNull DropperArena arena;
|
||||
private final @NotNull Player player;
|
||||
private final @NotNull DropperArenaGameMode gameMode;
|
||||
private boolean startedMoving = false;
|
||||
|
||||
/**
|
||||
* Instantiates a new dropper arena session
|
||||
*
|
||||
* @param dropperArena <p>The arena that's being played in</p>
|
||||
* @param player <p>The player playing the arena</p>
|
||||
* @param gameMode <p>The game-mode</p>
|
||||
*/
|
||||
public DropperArenaSession(@NotNull DropperArena dropperArena, @NotNull Player player,
|
||||
@NotNull DropperArenaGameMode gameMode) {
|
||||
super(dropperArena, player, gameMode);
|
||||
this.arena = dropperArena;
|
||||
this.player = player;
|
||||
this.gameMode = gameMode;
|
||||
|
||||
this.entryState = new DropperPlayerEntryState(player, gameMode, dropperArena.getPlayerHorizontalVelocity());
|
||||
this.entryState.setArenaState();
|
||||
}
|
||||
|
||||
/**
|
||||
* Marks that this arena's player has started moving
|
||||
*/
|
||||
public void setStartedMoving() {
|
||||
this.startedMoving = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets whether the player of this session has started moving in the arena
|
||||
*
|
||||
* @return <p>True if the player has started moving</p>
|
||||
*/
|
||||
public boolean getStartedMoving() {
|
||||
return this.startedMoving;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the player playing in this session
|
||||
*
|
||||
* @return <p>This session's player</p>
|
||||
*/
|
||||
public @NotNull Player getPlayer() {
|
||||
return this.player;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the game-mode the player is playing in this session
|
||||
*
|
||||
* @return <p>The game-mode for this session</p>
|
||||
*/
|
||||
public @NotNull DropperArenaGameMode getGameMode() {
|
||||
return this.gameMode;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull PlayerEntryState getEntryState() {
|
||||
return this.entryState;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void triggerWin() {
|
||||
// Stop this session
|
||||
removeSession();
|
||||
|
||||
// Check for, and display, records
|
||||
MiniGames miniGames = MiniGames.getInstance();
|
||||
boolean ignore = miniGames.getDropperConfiguration().ignoreRecordsUntilGroupBeatenOnce();
|
||||
DropperArenaGroup group = miniGames.getDropperArenaHandler().getGroup(this.arena.getArenaId());
|
||||
if (!ignore || group == null || group.hasBeatenAll(this.gameMode, this.player)) {
|
||||
registerRecord();
|
||||
}
|
||||
|
||||
StringFormatter stringFormatter = MiniGames.getInstance().getStringFormatter();
|
||||
|
||||
// Mark the arena as cleared
|
||||
if (this.arena.getData().setCompleted(this.gameMode, this.player)) {
|
||||
stringFormatter.displaySuccessMessage(this.player, MiniGameMessage.SUCCESS_ARENA_FIRST_CLEAR);
|
||||
RewardHelper.grantRewards(this.player, this.arena.getRewards(RewardCondition.FIRST_WIN));
|
||||
}
|
||||
stringFormatter.displaySuccessMessage(this.player, MiniGameMessage.SUCCESS_ARENA_WIN);
|
||||
RewardHelper.grantRewards(this.player, this.arena.getRewards(RewardCondition.WIN));
|
||||
|
||||
// Teleport the player out of the arena
|
||||
teleportToExit(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void triggerLoss() {
|
||||
this.deaths++;
|
||||
//Teleport the player back to the top
|
||||
PlayerTeleporter.teleportPlayer(this.player, this.arena.getSpawnLocation(), true, false);
|
||||
this.entryState.setArenaState();
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull DropperArena getArena() {
|
||||
return this.arena;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull ArenaGUI getGUI() {
|
||||
return new DropperGUI(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reset() {
|
||||
this.startedMoving = false;
|
||||
super.reset();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void removeSession() {
|
||||
// Remove this session for game sessions to stop listeners from fiddling more with the player
|
||||
boolean removedSession = MiniGames.getInstance().getDropperArenaPlayerRegistry().removePlayer(
|
||||
player.getUniqueId(), true);
|
||||
if (!removedSession) {
|
||||
MiniGames.log(Level.SEVERE, "Unable to remove dropper arena session for " + player.getName() + ". " +
|
||||
"This will have unintended consequences.");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getGameModeString() {
|
||||
return switch (this.gameMode) {
|
||||
case DEFAULT -> "default";
|
||||
case INVERTED -> "inverted";
|
||||
case RANDOM_INVERTED -> "random";
|
||||
};
|
||||
}
|
||||
|
||||
}
|
@ -1,11 +1,11 @@
|
||||
package net.knarcraft.dropper.property;
|
||||
package net.knarcraft.minigames.arena.dropper;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* A representation of each key used for storing arena data
|
||||
*/
|
||||
public enum ArenaStorageKey {
|
||||
public enum DropperArenaStorageKey {
|
||||
|
||||
/**
|
||||
* The key for an arena's id
|
||||
@ -43,9 +43,14 @@ public enum ArenaStorageKey {
|
||||
WIN_BLOCK_TYPE("winBlockType"),
|
||||
|
||||
/**
|
||||
* The hey for this arena's data
|
||||
* The key for this arena's data
|
||||
*/
|
||||
DATA("arenaData"),
|
||||
|
||||
/**
|
||||
* The key for this arena's rewards
|
||||
*/
|
||||
REWARDS("rewards"),
|
||||
;
|
||||
|
||||
private final @NotNull String key;
|
||||
@ -55,7 +60,7 @@ public enum ArenaStorageKey {
|
||||
*
|
||||
* @param key <p>The string path of the configuration key this value represents.</p>
|
||||
*/
|
||||
ArenaStorageKey(@NotNull String key) {
|
||||
DropperArenaStorageKey(@NotNull String key) {
|
||||
this.key = key;
|
||||
}
|
||||
|
@ -0,0 +1,130 @@
|
||||
package net.knarcraft.minigames.arena.dropper;
|
||||
|
||||
import net.knarcraft.minigames.arena.AbstractPlayerEntryState;
|
||||
import net.knarcraft.minigames.container.SerializableUUID;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* The state of a player before entering a dropper arena
|
||||
*/
|
||||
public class DropperPlayerEntryState extends AbstractPlayerEntryState {
|
||||
|
||||
private final float originalFlySpeed;
|
||||
private final float horizontalVelocity;
|
||||
private final DropperArenaGameMode arenaGameMode;
|
||||
|
||||
/**
|
||||
* Instantiates a new player state
|
||||
*
|
||||
* @param player <p>The player whose state should be stored</p>
|
||||
*/
|
||||
public DropperPlayerEntryState(@NotNull Player player, @NotNull DropperArenaGameMode arenaGameMode,
|
||||
float horizontalVelocity) {
|
||||
super(player);
|
||||
this.originalFlySpeed = player.getFlySpeed();
|
||||
this.arenaGameMode = arenaGameMode;
|
||||
this.horizontalVelocity = horizontalVelocity;
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a new parkour player entry state
|
||||
*
|
||||
* @param playerId <p>The id of the player whose state this should keep track of</p>
|
||||
* @param entryLocation <p>The location the player entered from</p>
|
||||
* @param originalIsFlying <p>Whether the player was flying before entering the arena</p>
|
||||
* @param originalGameMode <p>The game-mode of the player before entering the arena</p>
|
||||
* @param originalAllowFlight <p>Whether the player was allowed flight before entering the arena</p>
|
||||
* @param originalInvulnerable <p>Whether the player was invulnerable before entering the arena</p>
|
||||
* @param originalIsSwimming <p>Whether the player was swimming before entering the arena</p>
|
||||
* @param originalFlySpeed <p>The fly-speed of the player before entering the arena</p>
|
||||
* @param horizontalVelocity <p>The horizontal velocity of the player before entering the arena</p>
|
||||
* @param originalCollideAble <p>Whether the player was collide-able before entering the arena</p>
|
||||
*/
|
||||
public DropperPlayerEntryState(@NotNull UUID playerId, Location entryLocation,
|
||||
boolean originalIsFlying, GameMode originalGameMode, boolean originalAllowFlight,
|
||||
boolean originalInvulnerable, boolean originalIsSwimming,
|
||||
float originalFlySpeed, float horizontalVelocity,
|
||||
DropperArenaGameMode arenaGameMode, boolean originalCollideAble) {
|
||||
super(playerId, entryLocation, originalIsFlying, originalGameMode, originalAllowFlight,
|
||||
originalInvulnerable, originalIsSwimming, originalCollideAble);
|
||||
this.originalFlySpeed = originalFlySpeed;
|
||||
this.horizontalVelocity = horizontalVelocity;
|
||||
this.arenaGameMode = arenaGameMode;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setArenaState() {
|
||||
Player player = getPlayer();
|
||||
if (player == null) {
|
||||
return;
|
||||
}
|
||||
player.setAllowFlight(true);
|
||||
player.setFlying(true);
|
||||
player.setGameMode(GameMode.ADVENTURE);
|
||||
player.setSwimming(false);
|
||||
|
||||
// If playing on the inverted game-mode, negate the horizontal velocity to swap the controls
|
||||
if (this.arenaGameMode == DropperArenaGameMode.INVERTED) {
|
||||
player.setFlySpeed(-this.horizontalVelocity);
|
||||
} else {
|
||||
player.setFlySpeed(this.horizontalVelocity);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean restore() {
|
||||
Player player = getPlayer();
|
||||
if (player == null) {
|
||||
return false;
|
||||
}
|
||||
this.restore(player);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void restore(@NotNull Player player) {
|
||||
super.restore(player);
|
||||
player.setFlySpeed(this.originalFlySpeed);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Map<String, Object> serialize() {
|
||||
Map<String, Object> data = super.serialize();
|
||||
data.put("originalFlySpeed", this.originalFlySpeed);
|
||||
data.put("horizontalVelocity", this.horizontalVelocity);
|
||||
data.put("arenaGameMode", this.arenaGameMode);
|
||||
return data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Deserializes a ParkourPlayerEntryState from the given data
|
||||
*
|
||||
* @return <p>The data to deserialize</p>
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public static DropperPlayerEntryState deserialize(Map<String, Object> data) {
|
||||
UUID playerId = ((SerializableUUID) data.get("playerId")).getRawValue();
|
||||
Location entryLocation = (Location) data.get("entryLocation");
|
||||
boolean originalIsFlying = getBoolean(data, "originalIsFlying");
|
||||
GameMode originalGameMode = GameMode.valueOf((String) data.get("originalGameMode"));
|
||||
boolean originalAllowFlight = getBoolean(data, "originalAllowFlight");
|
||||
boolean originalInvulnerable = getBoolean(data, "originalInvulnerable");
|
||||
boolean originalIsSwimming = getBoolean(data, "originalIsSwimming");
|
||||
float originalFlySpeed = ((Number) data.get("originalFlySpeed")).floatValue();
|
||||
float horizontalVelocity = ((Number) data.get("horizontalVelocity")).floatValue();
|
||||
DropperArenaGameMode arenaGameMode = (DropperArenaGameMode) data.get("arenaGameMode");
|
||||
boolean originalCollideAble = getBoolean(data, "originalCollideAble");
|
||||
|
||||
return new DropperPlayerEntryState(playerId, entryLocation, originalIsFlying,
|
||||
originalGameMode, originalAllowFlight, originalInvulnerable, originalIsSwimming,
|
||||
originalFlySpeed, horizontalVelocity, arenaGameMode, originalCollideAble);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,526 @@
|
||||
package net.knarcraft.minigames.arena.parkour;
|
||||
|
||||
import net.knarcraft.knarlib.util.MaterialHelper;
|
||||
import net.knarcraft.minigames.MiniGames;
|
||||
import net.knarcraft.minigames.arena.Arena;
|
||||
import net.knarcraft.minigames.arena.ArenaGameMode;
|
||||
import net.knarcraft.minigames.arena.ArenaRecordsRegistry;
|
||||
import net.knarcraft.minigames.arena.reward.Reward;
|
||||
import net.knarcraft.minigames.arena.reward.RewardCondition;
|
||||
import net.knarcraft.minigames.util.ParkourArenaStorageHelper;
|
||||
import net.knarcraft.minigames.util.StringSanitizer;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import static net.knarcraft.minigames.util.InputValidationHelper.isInvalid;
|
||||
|
||||
/**
|
||||
* A representation of one parkour arena
|
||||
*/
|
||||
public class ParkourArena implements Arena {
|
||||
|
||||
/**
|
||||
* An unique and persistent identifier for this arena
|
||||
*/
|
||||
private final @NotNull UUID arenaId;
|
||||
|
||||
/**
|
||||
* A name used when listing and storing this arena.
|
||||
*/
|
||||
private @NotNull String arenaName;
|
||||
|
||||
/**
|
||||
* The location players are teleported to when joining this arena.
|
||||
*/
|
||||
private @NotNull Location spawnLocation;
|
||||
|
||||
/**
|
||||
* The location players will be sent to when they win or lose the arena. If not set, their entry location should be
|
||||
* used instead.
|
||||
*/
|
||||
private @Nullable Location exitLocation;
|
||||
|
||||
/**
|
||||
* The material of the block players have to hit to win this parkour arena
|
||||
*/
|
||||
private @NotNull Material winBlockType;
|
||||
|
||||
/**
|
||||
* The location the player has to reach to win. If not set, winBlockType is used instead
|
||||
*/
|
||||
private @Nullable Location winLocation;
|
||||
|
||||
/**
|
||||
* The names of the block types constituting this arena's kill plane
|
||||
*/
|
||||
private @Nullable Set<String> killPlaneBlockNames;
|
||||
|
||||
/**
|
||||
* The block types constituting this arena's kill plane
|
||||
*/
|
||||
private @Nullable Set<Material> killPlaneBlocks;
|
||||
|
||||
/**
|
||||
* The names of the block types serving as obstacles for this arena
|
||||
*/
|
||||
private @Nullable Set<String> obstacleBlockNames;
|
||||
|
||||
/**
|
||||
* The block types serving as obstacles for this arena
|
||||
*/
|
||||
private @Nullable Set<Material> obstacleBlocks;
|
||||
|
||||
/**
|
||||
* The checkpoints for this arena. Entering a checkpoint overrides the player's spawn location.
|
||||
*/
|
||||
private final @NotNull List<Location> checkpoints;
|
||||
|
||||
/**
|
||||
* The arena data for this arena
|
||||
*/
|
||||
private final @NotNull ParkourArenaData parkourArenaData;
|
||||
|
||||
private final @NotNull ParkourArenaHandler parkourArenaHandler;
|
||||
|
||||
private Map<RewardCondition, Set<Reward>> rewards = new HashMap<>();
|
||||
|
||||
/**
|
||||
* Instantiates a new parkour arena
|
||||
*
|
||||
* @param arenaId <p>The id of the arena</p>
|
||||
* @param arenaName <p>The name of the arena</p>
|
||||
* @param spawnLocation <p>The location players spawn in when entering the arena</p>
|
||||
* @param exitLocation <p>The location the players are teleported to when exiting the arena, or null</p>
|
||||
* @param winBlockType <p>The material of the block players have to hit to win this parkour arena</p>
|
||||
* @param winLocation <p>The location a player has to reach to win this arena</p>
|
||||
* @param killPlaneBlockNames <p>The names of the types of blocks that trigger a loss when stepped on</p>
|
||||
* @param obstacleBlockNames <p>The names of the types of blocks that trigger a loss when touched</p>
|
||||
* @param checkpoints <p>The checkpoints set for this arena</p>
|
||||
* @param rewards <p>The rewards given by this arena</p>
|
||||
* @param parkourArenaData <p>The arena data keeping track of which players have done what in this arena</p>
|
||||
* @param arenaHandler <p>The arena handler used for saving any changes</p>
|
||||
*/
|
||||
public ParkourArena(@NotNull UUID arenaId, @NotNull String arenaName, @NotNull Location spawnLocation,
|
||||
@Nullable Location exitLocation, @NotNull Material winBlockType, @Nullable Location winLocation,
|
||||
@Nullable Set<String> killPlaneBlockNames, @Nullable Set<String> obstacleBlockNames,
|
||||
@NotNull List<Location> checkpoints,
|
||||
@NotNull Map<RewardCondition, Set<Reward>> rewards,
|
||||
@NotNull ParkourArenaData parkourArenaData, @NotNull ParkourArenaHandler arenaHandler) {
|
||||
this.arenaId = arenaId;
|
||||
this.arenaName = arenaName;
|
||||
this.spawnLocation = spawnLocation;
|
||||
this.exitLocation = exitLocation;
|
||||
this.winBlockType = winBlockType;
|
||||
this.winLocation = winLocation;
|
||||
this.killPlaneBlockNames = killPlaneBlockNames;
|
||||
this.killPlaneBlocks = this.killPlaneBlockNames == null ? null : MaterialHelper.loadMaterialList(
|
||||
new ArrayList<>(killPlaneBlockNames), "+", MiniGames.getInstance().getLogger());
|
||||
this.obstacleBlockNames = obstacleBlockNames;
|
||||
this.obstacleBlocks = this.obstacleBlockNames == null ? null : MaterialHelper.loadMaterialList(
|
||||
new ArrayList<>(obstacleBlockNames), "+", MiniGames.getInstance().getLogger());
|
||||
this.checkpoints = checkpoints;
|
||||
this.parkourArenaData = parkourArenaData;
|
||||
this.parkourArenaHandler = arenaHandler;
|
||||
this.rewards = rewards;
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a new parkour arena
|
||||
*
|
||||
* <p>Note that this minimal constructor can be used to quickly create a new parkour arena at the player's given
|
||||
* location, simply by them giving an arena name.</p>
|
||||
*
|
||||
* @param arenaName <p>The name of the arena</p>
|
||||
* @param spawnLocation <p>The location players spawn in when entering the arena</p>
|
||||
* @param arenaHandler <p>The arena handler used for saving any changes</p>
|
||||
*/
|
||||
public ParkourArena(@NotNull String arenaName, @NotNull Location spawnLocation,
|
||||
@NotNull ParkourArenaHandler arenaHandler) {
|
||||
this.arenaId = UUID.randomUUID();
|
||||
this.arenaName = arenaName;
|
||||
this.spawnLocation = spawnLocation;
|
||||
this.exitLocation = null;
|
||||
this.winLocation = null;
|
||||
|
||||
Map<ArenaGameMode, ArenaRecordsRegistry> recordRegistries = new HashMap<>();
|
||||
for (ParkourArenaGameMode arenaGameMode : ParkourArenaGameMode.values()) {
|
||||
recordRegistries.put(arenaGameMode, new ParkourArenaRecordsRegistry(this.arenaId));
|
||||
}
|
||||
|
||||
this.parkourArenaData = new ParkourArenaData(this.arenaId, recordRegistries, new HashMap<>());
|
||||
this.winBlockType = Material.EMERALD_BLOCK;
|
||||
this.killPlaneBlocks = null;
|
||||
this.obstacleBlocks = null;
|
||||
this.checkpoints = new ArrayList<>();
|
||||
this.parkourArenaHandler = arenaHandler;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull ParkourArenaData getData() {
|
||||
return this.parkourArenaData;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull UUID getArenaId() {
|
||||
return this.arenaId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull String getArenaName() {
|
||||
return this.arenaName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Location getSpawnLocation() {
|
||||
return this.spawnLocation;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable Location getExitLocation() {
|
||||
return this.exitLocation;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addReward(@NotNull RewardCondition rewardCondition, @NotNull Reward reward) {
|
||||
this.rewards.computeIfAbsent(rewardCondition, k -> new HashSet<>());
|
||||
this.rewards.get(rewardCondition).add(reward);
|
||||
this.saveArena();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearRewards(@NotNull RewardCondition rewardCondition) {
|
||||
this.rewards.remove(rewardCondition);
|
||||
this.saveArena();
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Set<Reward> getRewards(RewardCondition rewardCondition) {
|
||||
if (this.rewards.containsKey(rewardCondition)) {
|
||||
return this.rewards.get(rewardCondition);
|
||||
} else {
|
||||
return new HashSet<>();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the type of block a player has to hit to win this arena
|
||||
*
|
||||
* @return <p>The kind of block players must hit</p>
|
||||
*/
|
||||
public @NotNull Material getWinBlockType() {
|
||||
return this.winBlockType;
|
||||
}
|
||||
|
||||
/**
|
||||
* The location a player has to reach to win this arena
|
||||
*
|
||||
* <p></p>
|
||||
*
|
||||
* @return <p>The win trigger's location</p>
|
||||
*/
|
||||
public @Nullable Location getWinLocation() {
|
||||
return this.winLocation != null ? this.winLocation.clone() : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the block types used for this parkour arena's kill plane
|
||||
*
|
||||
* @return <p>The types of blocks that cause a loss</p>
|
||||
*/
|
||||
public @NotNull Set<Material> getKillPlaneBlocks() {
|
||||
if (this.killPlaneBlocks != null) {
|
||||
return new HashSet<>(this.killPlaneBlocks);
|
||||
} else {
|
||||
return MiniGames.getInstance().getParkourConfiguration().getKillPlaneBlocks();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the names of the block types used for this parkour arena's kill plane
|
||||
*
|
||||
* @return <p>The names of the types of blocks that cause a loss</p>
|
||||
*/
|
||||
public @Nullable Set<String> getKillPlaneBlockNames() {
|
||||
return this.killPlaneBlockNames;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the block types used for this parkour arena's obstacle blocks
|
||||
*
|
||||
* @return <p>The types of blocks used as obstacles</p>
|
||||
*/
|
||||
public @NotNull Set<Material> getObstacleBlocks() {
|
||||
if (this.obstacleBlocks != null) {
|
||||
return new HashSet<>(this.obstacleBlocks);
|
||||
} else {
|
||||
return MiniGames.getInstance().getParkourConfiguration().getObstacleBlocks();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the names of the blocks used as this arena's obstacle blocks
|
||||
*
|
||||
* @return <p>The names of the blocks used as this arena's obstacle blocks</p>
|
||||
*/
|
||||
public @Nullable Set<String> getObstacleBlockNames() {
|
||||
return this.obstacleBlockNames;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets all checkpoint locations for this arena
|
||||
*
|
||||
* @return <p>All checkpoint locations for this arena</p>
|
||||
*/
|
||||
public List<Location> getCheckpoints() {
|
||||
List<Location> copy = new ArrayList<>(this.checkpoints.size());
|
||||
for (Location location : this.checkpoints) {
|
||||
copy.add(location.clone());
|
||||
}
|
||||
return copy;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets whether this arena has no checkpoints
|
||||
*
|
||||
* @return <p>True if this arena has no checkpoints</p>
|
||||
*/
|
||||
public boolean hasNoCheckpoints() {
|
||||
return this.checkpoints.isEmpty();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets this arena's sanitized name
|
||||
*
|
||||
* @return <p>This arena's sanitized name</p>
|
||||
*/
|
||||
public @NotNull String getArenaNameSanitized() {
|
||||
return StringSanitizer.sanitizeArenaName(this.getArenaName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean removeData() {
|
||||
return ParkourArenaStorageHelper.removeParkourArenaData(getArenaId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean saveData() {
|
||||
try {
|
||||
ParkourArenaStorageHelper.saveParkourArenaData(getData());
|
||||
return true;
|
||||
} catch (IOException exception) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean willCauseWin(Block block) {
|
||||
return (this.winLocation != null && this.winLocation.getBlock().equals(block)) ||
|
||||
(this.winLocation == null && this.winBlockType == block.getType());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean willCauseLoss(Block block) {
|
||||
return this.getKillPlaneBlocks().contains(block.getType()) || this.getObstacleBlocks().contains(block.getType());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean winLocationIsSolid() {
|
||||
return (this.winLocation != null && this.winLocation.getBlock().getType().isSolid()) ||
|
||||
this.winBlockType.isSolid();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the spawn location for this arena
|
||||
*
|
||||
* @param newLocation <p>The new spawn location</p>
|
||||
* @return <p>True if successfully updated</p>
|
||||
*/
|
||||
public boolean setSpawnLocation(@NotNull Location newLocation) {
|
||||
if (isInvalid(newLocation)) {
|
||||
return false;
|
||||
} else {
|
||||
this.spawnLocation = newLocation;
|
||||
this.saveArena();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the exit location for this arena
|
||||
*
|
||||
* @param newLocation <p>The new exit location</p>
|
||||
* @return <p>True if successfully updated</p>
|
||||
*/
|
||||
public boolean setExitLocation(@NotNull Location newLocation) {
|
||||
if (isInvalid(newLocation)) {
|
||||
return false;
|
||||
} else {
|
||||
this.exitLocation = newLocation;
|
||||
this.saveArena();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the name of this arena
|
||||
*
|
||||
* @param arenaName <p>The new name</p>
|
||||
* @return <p>True if successfully updated</p>
|
||||
*/
|
||||
public boolean setName(@NotNull String arenaName) {
|
||||
if (!arenaName.isBlank()) {
|
||||
String oldName = this.getArenaNameSanitized();
|
||||
this.arenaName = arenaName;
|
||||
// Update the arena lookup map to make sure the new name can be used immediately
|
||||
this.parkourArenaHandler.updateLookupName(oldName, this.getArenaNameSanitized());
|
||||
this.saveArena();
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the material of the win block type
|
||||
*
|
||||
* <p>The win block type is the type of block a player must hit to win in this arena</p>
|
||||
*
|
||||
* @param material <p>The material to set for the win block type</p>
|
||||
* @return <p>True if successfully updated</p>
|
||||
*/
|
||||
public boolean setWinBlockType(@NotNull Material material) {
|
||||
if (material.isAir() || !material.isBlock()) {
|
||||
return false;
|
||||
} else {
|
||||
this.winBlockType = material;
|
||||
this.saveArena();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the location players need to reach to win this arena
|
||||
*
|
||||
* @param newLocation <p>The location players have to reach</p>
|
||||
* @return <p>True if successfully changed</p>
|
||||
*/
|
||||
public boolean setWinLocation(@NotNull Location newLocation) {
|
||||
if (isInvalid(newLocation)) {
|
||||
return false;
|
||||
} else {
|
||||
this.winLocation = newLocation.clone();
|
||||
this.saveArena();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the type of blocks constituting this arena's kill plane
|
||||
*
|
||||
* @param killPlaneBlockNames <p>The names of the blocks that will cause players to lose</p>
|
||||
*/
|
||||
public boolean setKillPlaneBlocks(@NotNull Set<String> killPlaneBlockNames) {
|
||||
if (killPlaneBlockNames.isEmpty()) {
|
||||
this.killPlaneBlockNames = null;
|
||||
this.killPlaneBlocks = null;
|
||||
} else {
|
||||
Set<Material> parsed = MaterialHelper.loadMaterialList(new ArrayList<>(killPlaneBlockNames), "+",
|
||||
MiniGames.getInstance().getLogger());
|
||||
if (parsed.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
this.killPlaneBlockNames = killPlaneBlockNames;
|
||||
this.killPlaneBlocks = parsed;
|
||||
}
|
||||
this.saveArena();
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the type of blocks used as obstacle blocks
|
||||
*
|
||||
* @param obstacleBlockNames <p>The names of the obstacle blocks</p>
|
||||
*/
|
||||
public boolean setObstacleBlocks(@NotNull Set<String> obstacleBlockNames) {
|
||||
if (obstacleBlockNames.isEmpty()) {
|
||||
this.obstacleBlockNames = null;
|
||||
this.obstacleBlocks = null;
|
||||
} else {
|
||||
Set<Material> parsed = MaterialHelper.loadMaterialList(new ArrayList<>(obstacleBlockNames), "+",
|
||||
MiniGames.getInstance().getLogger());
|
||||
if (parsed.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
this.obstacleBlockNames = obstacleBlockNames;
|
||||
this.obstacleBlocks = parsed;
|
||||
}
|
||||
this.saveArena();
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a checkpoint to this arena
|
||||
*
|
||||
* @param checkpoint <p>The checkpoint to add</p>
|
||||
* @return <p>True if successfully added</p>
|
||||
*/
|
||||
public boolean addCheckpoint(@NotNull Location checkpoint) {
|
||||
if (isInvalid(checkpoint)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
this.checkpoints.add(checkpoint.clone());
|
||||
this.saveArena();
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears all checkpoints from this arena
|
||||
*
|
||||
* @return <p>True if successfully cleared</p>
|
||||
*/
|
||||
public boolean clearCheckpoints() {
|
||||
if (checkpoints.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
this.checkpoints.clear();
|
||||
this.saveArena();
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves this arena to disk
|
||||
*/
|
||||
public void saveArena() {
|
||||
try {
|
||||
ParkourArenaStorageHelper.saveSingleParkourArena(this);
|
||||
} catch (IOException exception) {
|
||||
MiniGames.log(Level.SEVERE, "Unable to save arena! " +
|
||||
"Data loss can occur!");
|
||||
MiniGames.log(Level.SEVERE, exception.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object other) {
|
||||
if (!(other instanceof ParkourArena otherArena)) {
|
||||
return false;
|
||||
}
|
||||
return this.getArenaNameSanitized().equals(otherArena.getArenaNameSanitized());
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,72 @@
|
||||
package net.knarcraft.minigames.arena.parkour;
|
||||
|
||||
import net.knarcraft.minigames.MiniGames;
|
||||
import net.knarcraft.minigames.arena.ArenaData;
|
||||
import net.knarcraft.minigames.arena.ArenaGameMode;
|
||||
import net.knarcraft.minigames.arena.ArenaRecordsRegistry;
|
||||
import net.knarcraft.minigames.container.SerializableContainer;
|
||||
import net.knarcraft.minigames.container.SerializableUUID;
|
||||
import net.knarcraft.minigames.util.SerializableConverter;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Data stored for an arena
|
||||
*/
|
||||
public class ParkourArenaData extends ArenaData {
|
||||
|
||||
/**
|
||||
* Instantiates a new parkour arena data object
|
||||
*
|
||||
* @param arenaId <p>The id of the arena this data belongs to</p>
|
||||
* @param recordRegistries <p>The registry of this arena's records</p>
|
||||
* @param playersCompleted <p>The set of the players that have cleared this arena</p>
|
||||
*/
|
||||
public ParkourArenaData(@NotNull UUID arenaId,
|
||||
@NotNull Map<ArenaGameMode, ArenaRecordsRegistry> recordRegistries,
|
||||
@NotNull Map<ArenaGameMode, Set<UUID>> playersCompleted) {
|
||||
super(arenaId, recordRegistries, playersCompleted);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveData() {
|
||||
MiniGames.getInstance().getParkourArenaHandler().saveData(this.arenaId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deserializes a parkour arena data from the given data
|
||||
*
|
||||
* @param data <p>The data to deserialize</p>
|
||||
* @return <p>The deserialized parkour arena data</p>
|
||||
*/
|
||||
@SuppressWarnings({"unused", "unchecked"})
|
||||
public static @NotNull ParkourArenaData deserialize(@NotNull Map<String, Object> data) {
|
||||
SerializableUUID serializableUUID = (SerializableUUID) data.get("arenaId");
|
||||
Map<ArenaGameMode, ArenaRecordsRegistry> recordsRegistry =
|
||||
(Map<ArenaGameMode, ArenaRecordsRegistry>) data.get("recordsRegistry");
|
||||
Map<ArenaGameMode, Set<SerializableContainer<UUID>>> playersCompletedData =
|
||||
(Map<ArenaGameMode, Set<SerializableContainer<UUID>>>) data.get("playersCompleted");
|
||||
|
||||
if (recordsRegistry == null) {
|
||||
recordsRegistry = new HashMap<>();
|
||||
} else if (playersCompletedData == null) {
|
||||
playersCompletedData = new HashMap<>();
|
||||
}
|
||||
|
||||
// Convert the serializable UUIDs to normal UUIDs
|
||||
Map<ArenaGameMode, Set<UUID>> allPlayersCompleted = new HashMap<>();
|
||||
SerializableConverter.getRawValue(playersCompletedData, allPlayersCompleted);
|
||||
|
||||
for (ArenaGameMode arenaGameMode : playersCompletedData.keySet()) {
|
||||
if (!recordsRegistry.containsKey(arenaGameMode) || recordsRegistry.get(arenaGameMode) == null) {
|
||||
recordsRegistry.put(arenaGameMode, new ParkourArenaRecordsRegistry(serializableUUID.getRawValue()));
|
||||
}
|
||||
}
|
||||
return new ParkourArenaData(serializableUUID.getRawValue(), recordsRegistry, allPlayersCompleted);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,133 @@
|
||||
package net.knarcraft.minigames.arena.parkour;
|
||||
|
||||
import net.knarcraft.minigames.arena.EditablePropertyType;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.function.Function;
|
||||
|
||||
/**
|
||||
* All editable properties of a parkour arena
|
||||
*/
|
||||
public enum ParkourArenaEditableProperty {
|
||||
|
||||
/**
|
||||
* The name of the arena
|
||||
*/
|
||||
NAME("name", ParkourArena::getArenaName, EditablePropertyType.ARENA_NAME),
|
||||
|
||||
/**
|
||||
* The arena's spawn location
|
||||
*/
|
||||
SPAWN_LOCATION("spawnLocation", (arena) -> String.valueOf(arena.getSpawnLocation()),
|
||||
EditablePropertyType.LOCATION),
|
||||
|
||||
/**
|
||||
* The arena's exit location
|
||||
*/
|
||||
EXIT_LOCATION("exitLocation", (arena) -> String.valueOf(arena.getExitLocation()),
|
||||
EditablePropertyType.LOCATION),
|
||||
|
||||
/**
|
||||
* The arena's win block type
|
||||
*/
|
||||
WIN_BLOCK_TYPE("winBlockType", (arena) -> arena.getWinBlockType().toString(),
|
||||
EditablePropertyType.BLOCK_TYPE),
|
||||
|
||||
/**
|
||||
* The arena's win location (overrides the win block type)
|
||||
*/
|
||||
WIN_LOCATION("winLocation", (arena) -> {
|
||||
if (arena.getWinLocation() != null) {
|
||||
return arena.getWinLocation().toString();
|
||||
} else {
|
||||
return "null";
|
||||
}
|
||||
}, EditablePropertyType.LOCATION),
|
||||
|
||||
/**
|
||||
* The arena's check points. Specifically used for adding.
|
||||
*/
|
||||
CHECKPOINT_ADD("checkpointAdd", (arena) -> String.valueOf(arena.getCheckpoints()),
|
||||
EditablePropertyType.LOCATION),
|
||||
|
||||
/**
|
||||
* The arena's check points. Specifically used for clearing.
|
||||
*/
|
||||
CHECKPOINT_CLEAR("checkpointClear", (arena) -> String.valueOf(arena.getCheckpoints()),
|
||||
EditablePropertyType.CHECKPOINT_CLEAR),
|
||||
|
||||
/**
|
||||
* The blocks constituting the arena's lethal blocks
|
||||
*/
|
||||
KILL_PLANE_BLOCKS("killPlaneBlocks", (arena) -> String.valueOf(arena.getKillPlaneBlockNames()),
|
||||
EditablePropertyType.MATERIAL_LIST),
|
||||
|
||||
/**
|
||||
* The blocks used as this arena's obstacle blocks
|
||||
*/
|
||||
OBSTACLE_BLOCKS("obstacleBlocks", (arena) -> String.valueOf(arena.getObstacleBlockNames()),
|
||||
EditablePropertyType.MATERIAL_LIST),
|
||||
|
||||
;
|
||||
|
||||
private final @NotNull String argumentString;
|
||||
private final Function<ParkourArena, String> currentValueProvider;
|
||||
private final EditablePropertyType propertyType;
|
||||
|
||||
/**
|
||||
* Instantiates a new arena editable property
|
||||
*
|
||||
* @param argumentString <p>The argument string used to specify this property</p>
|
||||
*/
|
||||
ParkourArenaEditableProperty(@NotNull String argumentString, Function<ParkourArena, String> currentValueProvider,
|
||||
EditablePropertyType propertyType) {
|
||||
this.argumentString = argumentString;
|
||||
this.currentValueProvider = currentValueProvider;
|
||||
this.propertyType = propertyType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the type of property this editable property represents
|
||||
*
|
||||
* @return <p>The type of this property</p>
|
||||
*/
|
||||
public EditablePropertyType getPropertyType() {
|
||||
return this.propertyType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the string representation of this property's current value
|
||||
*
|
||||
* @param arena <p>The arena to check the value for</p>
|
||||
* @return <p>The current value as a string</p>
|
||||
*/
|
||||
public String getCurrentValueAsString(ParkourArena arena) {
|
||||
return this.currentValueProvider.apply(arena);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the argument string used to specify this property
|
||||
*
|
||||
* @return <p>The argument string</p>
|
||||
*/
|
||||
public @NotNull String getArgumentString() {
|
||||
return this.argumentString;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the editable property corresponding to the given argument string
|
||||
*
|
||||
* @param argumentString <p>The argument string used to specify an editable property</p>
|
||||
* @return <p>The corresponding editable property, or null if not found</p>
|
||||
*/
|
||||
public static @Nullable ParkourArenaEditableProperty getFromArgumentString(String argumentString) {
|
||||
for (ParkourArenaEditableProperty property : ParkourArenaEditableProperty.values()) {
|
||||
if (property.argumentString.equalsIgnoreCase(argumentString)) {
|
||||
return property;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,64 @@
|
||||
package net.knarcraft.minigames.arena.parkour;
|
||||
|
||||
import net.knarcraft.minigames.arena.ArenaGameMode;
|
||||
import org.bukkit.configuration.serialization.ConfigurationSerializable;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* A representation of possible arena game-modes
|
||||
*/
|
||||
public enum ParkourArenaGameMode implements ConfigurationSerializable, ArenaGameMode {
|
||||
|
||||
/**
|
||||
* The default game-mode. Failing once throws the player out.
|
||||
*/
|
||||
DEFAULT,
|
||||
|
||||
/**
|
||||
* A hardcore game mode where no checkpoints are allowed
|
||||
*/
|
||||
HARDCORE,
|
||||
;
|
||||
|
||||
/**
|
||||
* Tries to match the correct game-mode according to the given string
|
||||
*
|
||||
* @param gameMode <p>The game-mode string to match</p>
|
||||
* @return <p>The specified arena game-mode</p>
|
||||
*/
|
||||
public static @NotNull ParkourArenaGameMode matchGamemode(@NotNull String gameMode) {
|
||||
try {
|
||||
return ParkourArenaGameMode.valueOf(gameMode.toUpperCase());
|
||||
} catch (IllegalArgumentException exception) {
|
||||
return ParkourArenaGameMode.DEFAULT;
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Map<String, Object> serialize() {
|
||||
Map<String, Object> data = new HashMap<>();
|
||||
data.put("name", this.name());
|
||||
return data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Deserializes the arena game-mode specified by the given data
|
||||
*
|
||||
* @param data <p>The data to deserialize</p>
|
||||
* @return <p>The deserialized arena game-mode</p>
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public static ParkourArenaGameMode deserialize(Map<String, Object> data) {
|
||||
return ParkourArenaGameMode.valueOf((String) data.get("name"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull ParkourArenaGameMode[] getValues() {
|
||||
return ParkourArenaGameMode.values();
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,56 @@
|
||||
package net.knarcraft.minigames.arena.parkour;
|
||||
|
||||
import net.knarcraft.minigames.MiniGames;
|
||||
import net.knarcraft.minigames.arena.ArenaGroup;
|
||||
import net.knarcraft.minigames.container.SerializableUUID;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* A sorted group of arenas that must be completed in sequence
|
||||
*/
|
||||
public class ParkourArenaGroup extends ArenaGroup<ParkourArena, ParkourArenaGroup> {
|
||||
|
||||
/**
|
||||
* Instantiates a new parkour arena group
|
||||
*
|
||||
* @param groupName <p>The name of this group</p>
|
||||
*/
|
||||
public ParkourArenaGroup(@NotNull String groupName) {
|
||||
super(groupName, MiniGames.getInstance().getParkourArenaHandler());
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a new parkour arena group
|
||||
*
|
||||
* @param groupId <p>The unique id of this group</p>
|
||||
* @param groupName <p>The name of this group</p>
|
||||
* @param arenas <p>The arenas in this group</p>
|
||||
*/
|
||||
private ParkourArenaGroup(@NotNull UUID groupId, @NotNull String groupName, @NotNull List<UUID> arenas) {
|
||||
super(groupId, groupName, arenas, MiniGames.getInstance().getParkourArenaHandler());
|
||||
}
|
||||
|
||||
/**
|
||||
* Deserializes the given data
|
||||
*
|
||||
* @param data <p>The data to deserialize</p>
|
||||
* @return <p>The deserialized arena group</p>
|
||||
*/
|
||||
@SuppressWarnings({"unused", "unchecked"})
|
||||
public static @NotNull ParkourArenaGroup deserialize(@NotNull Map<String, Object> data) {
|
||||
UUID id = ((SerializableUUID) data.get("groupId")).getRawValue();
|
||||
String name = (String) data.get("groupName");
|
||||
List<SerializableUUID> serializableArenas = (List<SerializableUUID>) data.get("arenas");
|
||||
List<UUID> arenas = new ArrayList<>();
|
||||
for (SerializableUUID arenaId : serializableArenas) {
|
||||
arenas.add(arenaId.getRawValue());
|
||||
}
|
||||
return new ParkourArenaGroup(id, name, arenas);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,77 @@
|
||||
package net.knarcraft.minigames.arena.parkour;
|
||||
|
||||
import net.knarcraft.minigames.MiniGames;
|
||||
import net.knarcraft.minigames.arena.ArenaHandler;
|
||||
import net.knarcraft.minigames.arena.ArenaPlayerRegistry;
|
||||
import net.knarcraft.minigames.config.MiniGameMessage;
|
||||
import net.knarcraft.minigames.util.ParkourArenaStorageHelper;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.logging.Level;
|
||||
|
||||
/**
|
||||
* A handler that keeps track of all parkour arenas
|
||||
*/
|
||||
public class ParkourArenaHandler extends ArenaHandler<ParkourArena, ParkourArenaGroup> {
|
||||
|
||||
/**
|
||||
* Instantiates a new arena handler
|
||||
*
|
||||
* @param playerRegistry <p>The registry keeping track of player sessions</p>
|
||||
*/
|
||||
public ParkourArenaHandler(ArenaPlayerRegistry<ParkourArena> playerRegistry) {
|
||||
super(playerRegistry);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveGroups() {
|
||||
try {
|
||||
ParkourArenaStorageHelper.saveParkourArenaGroups(new HashSet<>(this.arenaGroups.values()));
|
||||
} catch (IOException exception) {
|
||||
MiniGames.log(Level.SEVERE, MiniGames.getInstance().getTranslator().getTranslatedMessage(
|
||||
MiniGameMessage.ERROR_CANNOT_SAVE_ARENA_GROUPS));
|
||||
MiniGames.log(Level.SEVERE, exception.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void loadGroups() {
|
||||
Set<ParkourArenaGroup> arenaGroups = ParkourArenaStorageHelper.loadParkourArenaGroups();
|
||||
Map<UUID, ParkourArenaGroup> arenaGroupMap = new HashMap<>();
|
||||
for (ParkourArenaGroup arenaGroup : arenaGroups) {
|
||||
for (UUID arenaId : arenaGroup.getArenas()) {
|
||||
arenaGroupMap.put(arenaId, arenaGroup);
|
||||
}
|
||||
}
|
||||
this.arenaGroups = arenaGroupMap;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveArenas() {
|
||||
try {
|
||||
ParkourArenaStorageHelper.saveParkourArenas(this.arenas);
|
||||
} catch (IOException exception) {
|
||||
MiniGames.log(Level.SEVERE, "Unable to save current arenas! " +
|
||||
"Data loss can occur!");
|
||||
MiniGames.log(Level.SEVERE, exception.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void loadArenas() {
|
||||
this.arenas = ParkourArenaStorageHelper.loadParkourArenas();
|
||||
|
||||
// Save a map from arena name to arena id for improved performance
|
||||
this.arenaNameLookup = new HashMap<>();
|
||||
for (Map.Entry<UUID, ParkourArena> arena : this.arenas.entrySet()) {
|
||||
String sanitizedName = arena.getValue().getArenaNameSanitized();
|
||||
this.arenaNameLookup.put(sanitizedName, arena.getKey());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
package net.knarcraft.minigames.arena.parkour;
|
||||
|
||||
import net.knarcraft.minigames.arena.AbstractArenaPlayerRegistry;
|
||||
|
||||
/**
|
||||
* A registry to keep track of which players are playing in which arenas
|
||||
*/
|
||||
public class ParkourArenaPlayerRegistry extends AbstractArenaPlayerRegistry<ParkourArena> {
|
||||
|
||||
@Override
|
||||
protected String getEntryStateStorageKey() {
|
||||
return "parkour";
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,66 @@
|
||||
package net.knarcraft.minigames.arena.parkour;
|
||||
|
||||
import net.knarcraft.minigames.MiniGames;
|
||||
import net.knarcraft.minigames.arena.ArenaRecordsRegistry;
|
||||
import net.knarcraft.minigames.arena.record.IntegerRecord;
|
||||
import net.knarcraft.minigames.arena.record.LongRecord;
|
||||
import net.knarcraft.minigames.container.SerializableUUID;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* A registry keeping track of all records
|
||||
*/
|
||||
public class ParkourArenaRecordsRegistry extends ArenaRecordsRegistry {
|
||||
|
||||
/**
|
||||
* Instantiates a new empty records registry
|
||||
*/
|
||||
public ParkourArenaRecordsRegistry(@NotNull UUID arenaId) {
|
||||
super(arenaId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a new records registry
|
||||
*
|
||||
* @param leastDeaths <p>The existing least death records to use</p>
|
||||
* @param shortestTimeMilliSeconds <p>The existing leash time records to use</p>
|
||||
*/
|
||||
private ParkourArenaRecordsRegistry(@NotNull UUID arenaId, @NotNull Set<IntegerRecord> leastDeaths,
|
||||
@NotNull Set<LongRecord> shortestTimeMilliSeconds) {
|
||||
super(arenaId, leastDeaths, shortestTimeMilliSeconds);
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves changed records
|
||||
*/
|
||||
@Override
|
||||
protected void save() {
|
||||
MiniGames.getInstance().getParkourArenaHandler().saveData(this.arenaId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deserializes the given data
|
||||
*
|
||||
* @param data <p>The data to deserialize</p>
|
||||
* @return <p>The deserialized records registry</p>
|
||||
*/
|
||||
@SuppressWarnings({"unused", "unchecked"})
|
||||
public static ParkourArenaRecordsRegistry deserialize(Map<String, Object> data) {
|
||||
UUID arenaId = ((SerializableUUID) data.get("arenaId")).getRawValue();
|
||||
Set<IntegerRecord> leastDeaths =
|
||||
(Set<IntegerRecord>) data.getOrDefault("leastDeaths", new HashMap<>());
|
||||
Set<LongRecord> shortestTimeMilliseconds =
|
||||
(Set<LongRecord>) data.getOrDefault("shortestTime", new HashMap<>());
|
||||
|
||||
leastDeaths.removeIf(Objects::isNull);
|
||||
shortestTimeMilliseconds.removeIf(Objects::isNull);
|
||||
return new ParkourArenaRecordsRegistry(arenaId, leastDeaths, shortestTimeMilliseconds);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,151 @@
|
||||
package net.knarcraft.minigames.arena.parkour;
|
||||
|
||||
import net.knarcraft.knarlib.formatting.StringFormatter;
|
||||
import net.knarcraft.minigames.MiniGames;
|
||||
import net.knarcraft.minigames.arena.AbstractArenaSession;
|
||||
import net.knarcraft.minigames.arena.PlayerEntryState;
|
||||
import net.knarcraft.minigames.arena.reward.RewardCondition;
|
||||
import net.knarcraft.minigames.config.MiniGameMessage;
|
||||
import net.knarcraft.minigames.gui.ArenaGUI;
|
||||
import net.knarcraft.minigames.gui.ParkourGUI;
|
||||
import net.knarcraft.minigames.util.PlayerTeleporter;
|
||||
import net.knarcraft.minigames.util.RewardHelper;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.logging.Level;
|
||||
|
||||
/**
|
||||
* A representation of a player's current session in a parkour arena
|
||||
*/
|
||||
public class ParkourArenaSession extends AbstractArenaSession {
|
||||
|
||||
private final @NotNull ParkourArena arena;
|
||||
private final @NotNull Player player;
|
||||
private final @NotNull ParkourArenaGameMode gameMode;
|
||||
private Location reachedCheckpoint = null;
|
||||
|
||||
/**
|
||||
* Instantiates a new parkour arena session
|
||||
*
|
||||
* @param parkourArena <p>The arena that's being played in</p>
|
||||
* @param player <p>The player playing the arena</p>
|
||||
* @param gameMode <p>The game-mode</p>
|
||||
*/
|
||||
public ParkourArenaSession(@NotNull ParkourArena parkourArena, @NotNull Player player,
|
||||
@NotNull ParkourArenaGameMode gameMode) {
|
||||
super(parkourArena, player, gameMode);
|
||||
this.arena = parkourArena;
|
||||
this.player = player;
|
||||
this.gameMode = gameMode;
|
||||
|
||||
this.entryState = new ParkourPlayerEntryState(player);
|
||||
this.entryState.setArenaState();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the game-mode the player is playing in this session
|
||||
*
|
||||
* @return <p>The game-mode for this session</p>
|
||||
*/
|
||||
public @NotNull ParkourArenaGameMode getGameMode() {
|
||||
return this.gameMode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers the checkpoint this session's player has reached
|
||||
*
|
||||
* @param location <p>The location of the checkpoint</p>
|
||||
*/
|
||||
public void registerCheckpoint(@NotNull Location location) {
|
||||
this.reachedCheckpoint = location;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the checkpoint currently registered as the player's spawn location
|
||||
*
|
||||
* @return <p>The registered checkpoint, or null if not set</p>
|
||||
*/
|
||||
public @Nullable Location getRegisteredCheckpoint() {
|
||||
return this.reachedCheckpoint;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull PlayerEntryState getEntryState() {
|
||||
return this.entryState;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void triggerWin() {
|
||||
// Stop this session
|
||||
removeSession();
|
||||
|
||||
// Check for, and display, records
|
||||
MiniGames miniGames = MiniGames.getInstance();
|
||||
boolean ignore = miniGames.getParkourConfiguration().ignoreRecordsUntilGroupBeatenOnce();
|
||||
ParkourArenaGroup group = miniGames.getParkourArenaHandler().getGroup(this.arena.getArenaId());
|
||||
if (!ignore || group == null || group.hasBeatenAll(this.gameMode, this.player)) {
|
||||
registerRecord();
|
||||
}
|
||||
|
||||
StringFormatter stringFormatter = MiniGames.getInstance().getStringFormatter();
|
||||
|
||||
// Mark the arena as cleared
|
||||
if (this.arena.getData().setCompleted(this.gameMode, this.player)) {
|
||||
stringFormatter.displaySuccessMessage(this.player, MiniGameMessage.SUCCESS_ARENA_FIRST_CLEAR);
|
||||
RewardHelper.grantRewards(this.player, this.arena.getRewards(RewardCondition.FIRST_WIN));
|
||||
}
|
||||
stringFormatter.displaySuccessMessage(this.player, MiniGameMessage.SUCCESS_ARENA_WIN);
|
||||
RewardHelper.grantRewards(this.player, this.arena.getRewards(RewardCondition.WIN));
|
||||
|
||||
// Teleport the player out of the arena
|
||||
teleportToExit(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void triggerLoss() {
|
||||
this.deaths++;
|
||||
//Teleport the player back to the top
|
||||
Location spawnLocation = this.reachedCheckpoint != null ? this.reachedCheckpoint : this.arena.getSpawnLocation();
|
||||
PlayerTeleporter.teleportPlayer(this.player, spawnLocation, true, false);
|
||||
this.entryState.setArenaState();
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull ParkourArena getArena() {
|
||||
return this.arena;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull ArenaGUI getGUI() {
|
||||
return new ParkourGUI(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reset() {
|
||||
this.reachedCheckpoint = null;
|
||||
super.reset();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void removeSession() {
|
||||
// Remove this session for game sessions to stop listeners from fiddling more with the player
|
||||
boolean removedSession = MiniGames.getInstance().getParkourArenaPlayerRegistry().removePlayer(
|
||||
player.getUniqueId(), true);
|
||||
if (!removedSession) {
|
||||
MiniGames.log(Level.SEVERE, "Unable to remove parkour arena session for " + player.getName() + ". " +
|
||||
"This will have unintended consequences.");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getGameModeString() {
|
||||
return switch (this.gameMode) {
|
||||
case DEFAULT -> "default";
|
||||
case HARDCORE -> "hardcore";
|
||||
};
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,86 @@
|
||||
package net.knarcraft.minigames.arena.parkour;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* A representation of each key used for storing arena data
|
||||
*/
|
||||
public enum ParkourArenaStorageKey {
|
||||
|
||||
/**
|
||||
* The key for an arena's id
|
||||
*/
|
||||
ID("arenaId"),
|
||||
|
||||
/**
|
||||
* The key for an arena's name
|
||||
*/
|
||||
NAME("arenaName"),
|
||||
|
||||
/**
|
||||
* The key for an arena's spawn location
|
||||
*/
|
||||
SPAWN_LOCATION("arenaSpawnLocation"),
|
||||
|
||||
/**
|
||||
* The key for an arena's exit location
|
||||
*/
|
||||
EXIT_LOCATION("arenaExitLocation"),
|
||||
|
||||
/**
|
||||
* The key for the type of this arena's win block
|
||||
*/
|
||||
WIN_BLOCK_TYPE("winBlockType"),
|
||||
|
||||
/**
|
||||
* The key for this arena's win location (overrides win block type)
|
||||
*/
|
||||
WIN_LOCATION("winLocation"),
|
||||
|
||||
/**
|
||||
* The key for this arena's kill plane blocks (overrides the config)
|
||||
*/
|
||||
KILL_PLANE_BLOCKS("killPlaneBlocks"),
|
||||
|
||||
/**
|
||||
* The key for this arena's obstacle blocks (overrides the config)
|
||||
*/
|
||||
OBSTACLE_BLOCKS("obstacleBlocks"),
|
||||
|
||||
/**
|
||||
* The key for this arena's checkpoint locations
|
||||
*/
|
||||
CHECKPOINTS("checkpoints"),
|
||||
|
||||
/**
|
||||
* The hey for this arena's data
|
||||
*/
|
||||
DATA("arenaData"),
|
||||
|
||||
/**
|
||||
* The key for this arena's rewards
|
||||
*/
|
||||
REWARDS("rewards"),
|
||||
;
|
||||
|
||||
private final @NotNull String key;
|
||||
|
||||
/**
|
||||
* Instantiates a new arena storage key
|
||||
*
|
||||
* @param key <p>The string path of the configuration key this value represents.</p>
|
||||
*/
|
||||
ParkourArenaStorageKey(@NotNull String key) {
|
||||
this.key = key;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the configuration key this enum represents
|
||||
*
|
||||
* @return <p>The string key representation.</p>
|
||||
*/
|
||||
public @NotNull String getKey() {
|
||||
return this.key;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,78 @@
|
||||
package net.knarcraft.minigames.arena.parkour;
|
||||
|
||||
import net.knarcraft.minigames.arena.AbstractPlayerEntryState;
|
||||
import net.knarcraft.minigames.container.SerializableUUID;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* The state of a player before entering a parkour arena
|
||||
*/
|
||||
public class ParkourPlayerEntryState extends AbstractPlayerEntryState {
|
||||
|
||||
/**
|
||||
* Instantiates a new player state
|
||||
*
|
||||
* @param player <p>The player whose state should be stored</p>
|
||||
*/
|
||||
public ParkourPlayerEntryState(@NotNull Player player) {
|
||||
super(player);
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a new parkour player entry state
|
||||
*
|
||||
* @param playerId <p>The id of the player whose state this should keep track of</p>
|
||||
* @param entryLocation <p>The location the player entered from</p>
|
||||
* @param originalIsFlying <p>Whether the player was flying before entering the arena</p>
|
||||
* @param originalGameMode <p>The game-mode of the player before entering the arena</p>
|
||||
* @param originalAllowFlight <p>Whether the player was allowed flight before entering the arena</p>
|
||||
* @param originalInvulnerable <p>Whether the player was invulnerable before entering the arena</p>
|
||||
* @param originalIsSwimming <p>Whether the player was swimming before entering the arena</p>
|
||||
* @param originalCollideAble <p>Whether the player was collide-able before entering the arena</p>
|
||||
*/
|
||||
public ParkourPlayerEntryState(@NotNull UUID playerId, Location entryLocation,
|
||||
boolean originalIsFlying, GameMode originalGameMode, boolean originalAllowFlight,
|
||||
boolean originalInvulnerable, boolean originalIsSwimming, boolean originalCollideAble) {
|
||||
super(playerId, entryLocation, originalIsFlying, originalGameMode, originalAllowFlight,
|
||||
originalInvulnerable, originalIsSwimming, originalCollideAble);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setArenaState() {
|
||||
Player player = getPlayer();
|
||||
if (player == null) {
|
||||
return;
|
||||
}
|
||||
player.setAllowFlight(false);
|
||||
player.setFlying(false);
|
||||
player.setGameMode(GameMode.ADVENTURE);
|
||||
player.setSwimming(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deserializes a ParkourPlayerEntryState from the given data
|
||||
*
|
||||
* @return <p>The data to deserialize</p>
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public static ParkourPlayerEntryState deserialize(Map<String, Object> data) {
|
||||
UUID playerId = ((SerializableUUID) data.get("playerId")).getRawValue();
|
||||
Location entryLocation = (Location) data.get("entryLocation");
|
||||
boolean originalIsFlying = getBoolean(data, "originalIsFlying");
|
||||
GameMode originalGameMode = GameMode.valueOf((String) data.get("originalGameMode"));
|
||||
boolean originalAllowFlight = getBoolean(data, "originalAllowFlight");
|
||||
boolean originalInvulnerable = getBoolean(data, "originalInvulnerable");
|
||||
boolean originalIsSwimming = getBoolean(data, "originalIsSwimming");
|
||||
boolean originalCollideAble = getBoolean(data, "originalCollideAble");
|
||||
|
||||
return new ParkourPlayerEntryState(playerId, entryLocation, originalIsFlying,
|
||||
originalGameMode, originalAllowFlight, originalInvulnerable, originalIsSwimming, originalCollideAble);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,83 @@
|
||||
package net.knarcraft.minigames.arena.record;
|
||||
|
||||
import net.knarcraft.minigames.container.SerializableUUID;
|
||||
import org.bukkit.configuration.serialization.ConfigurationSerializable;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* A record stored for an arena
|
||||
*/
|
||||
public abstract class ArenaRecord<K extends Comparable<K>> implements Comparable<ArenaRecord<K>>, ConfigurationSerializable {
|
||||
|
||||
private final UUID userId;
|
||||
private final K record;
|
||||
|
||||
/**
|
||||
* @param userId <p>The id of the player that achieved the record</p>
|
||||
* @param record <p>The record achieved</p>
|
||||
*/
|
||||
public ArenaRecord(UUID userId, K record) {
|
||||
this.userId = userId;
|
||||
this.record = record;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the id of the user this record belongs to
|
||||
*
|
||||
* @return <p>The record's achiever</p>
|
||||
*/
|
||||
public UUID getUserId() {
|
||||
return userId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the value of the stored record
|
||||
*
|
||||
* @return <p>The record value</p>
|
||||
*/
|
||||
public K getRecord() {
|
||||
return record;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets this as a string that should be printed on a sign
|
||||
*
|
||||
* @return <p>This as a string</p>
|
||||
*/
|
||||
public abstract String getAsString();
|
||||
|
||||
@Override
|
||||
public boolean equals(Object other) {
|
||||
return other instanceof ArenaRecord<?> && userId.equals(((ArenaRecord<?>) other).userId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(@NotNull ArenaRecord<K> other) {
|
||||
return record.compareTo(other.record);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Map<String, Object> serialize() {
|
||||
Map<String, Object> data = new HashMap<>();
|
||||
data.put("userId", new SerializableUUID(getUserId()));
|
||||
data.put("record", record);
|
||||
return data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(userId, record);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return userId + ":" + record;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,48 @@
|
||||
package net.knarcraft.minigames.arena.record;
|
||||
|
||||
import net.knarcraft.minigames.container.SerializableUUID;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* A record storing an integer
|
||||
*/
|
||||
public class IntegerRecord extends SummableArenaRecord<Integer> {
|
||||
|
||||
/**
|
||||
* @param userId <p>The id of the player that achieved the record</p>
|
||||
* @param record <p>The record achieved</p>
|
||||
*/
|
||||
public IntegerRecord(UUID userId, Integer record) {
|
||||
super(userId, record);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAsString() {
|
||||
return String.valueOf(this.getRecord());
|
||||
}
|
||||
|
||||
@Override
|
||||
public SummableArenaRecord<Integer> sum(Integer value) {
|
||||
return new IntegerRecord(this.getUserId(), this.getRecord() + value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object other) {
|
||||
return other instanceof IntegerRecord && this.getUserId().equals(((IntegerRecord) other).getUserId());
|
||||
}
|
||||
|
||||
/**
|
||||
* Deserializes the saved arena record
|
||||
*
|
||||
* @param data <p>The data to deserialize</p>
|
||||
* @return <p>The deserialized data</p>
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public static IntegerRecord deserialize(@NotNull Map<String, Object> data) {
|
||||
return new IntegerRecord(((SerializableUUID) data.get("userId")).getRawValue(), (Integer) data.get("record"));
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,59 @@
|
||||
package net.knarcraft.minigames.arena.record;
|
||||
|
||||
import net.knarcraft.minigames.container.SerializableUUID;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* A record storing a Long time
|
||||
*/
|
||||
public class LongRecord extends SummableArenaRecord<Long> {
|
||||
|
||||
/**
|
||||
* @param userId <p>The id of the player that achieved the record</p>
|
||||
* @param record <p>The record achieved</p>
|
||||
*/
|
||||
public LongRecord(UUID userId, Long record) {
|
||||
super(userId, record);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object other) {
|
||||
return other instanceof LongRecord && this.getUserId().equals(((LongRecord) other).getUserId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public SummableArenaRecord<Long> sum(Long value) {
|
||||
return new LongRecord(this.getUserId(), this.getRecord() + value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAsString() {
|
||||
int seconds = (int) Math.floor(getRecord() / 1000.0);
|
||||
int minutes = 0;
|
||||
if (seconds > 60) {
|
||||
minutes = (int) Math.floor(seconds / 60.0);
|
||||
seconds = seconds % 60;
|
||||
}
|
||||
|
||||
if (minutes > 0) {
|
||||
return minutes + "m" + seconds + "s";
|
||||
} else {
|
||||
return seconds + "s";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Deserializes the saved arena record
|
||||
*
|
||||
* @param data <p>The data to deserialize</p>
|
||||
* @return <p>The deserialized data</p>
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public static LongRecord deserialize(@NotNull Map<String, Object> data) {
|
||||
return new LongRecord(((SerializableUUID) data.get("userId")).getRawValue(), ((Number) data.get("record")).longValue());
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
package net.knarcraft.minigames.arena.record;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* A type of arena record which can be summed together
|
||||
*
|
||||
* @param <K> <p>The type of the stored value</p>
|
||||
*/
|
||||
public abstract class SummableArenaRecord<K extends Comparable<K>> extends ArenaRecord<K> {
|
||||
|
||||
/**
|
||||
* @param userId <p>The id of the player that achieved the record</p>
|
||||
* @param record <p>The record achieved</p>
|
||||
*/
|
||||
public SummableArenaRecord(UUID userId, K record) {
|
||||
super(userId, record);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a summable record with the resulting sum
|
||||
*
|
||||
* @param value <p>The value to add to the existing value</p>
|
||||
* @return <p>A record with the sum of this record and the given value</p>
|
||||
*/
|
||||
public abstract SummableArenaRecord<K> sum(K value);
|
||||
|
||||
}
|
@ -0,0 +1,69 @@
|
||||
package net.knarcraft.minigames.arena.reward;
|
||||
|
||||
import net.knarcraft.minigames.MiniGames;
|
||||
import net.knarcraft.minigames.config.MiniGameMessage;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* A reward that executes a specified command when it's granted
|
||||
*/
|
||||
public class CommandReward implements Reward {
|
||||
|
||||
private final @NotNull String command;
|
||||
|
||||
/**
|
||||
* Instantiates a new command reward
|
||||
*
|
||||
* @param command <p>The command to execute when granting this reward</p>
|
||||
*/
|
||||
public CommandReward(@NotNull String command) {
|
||||
this.command = command;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean grant(@NotNull Player player) {
|
||||
return Bukkit.dispatchCommand(Bukkit.getServer().getConsoleSender(), replaceNamePlaceholder(player, command));
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull String getGrantMessage() {
|
||||
return MiniGames.getInstance().getStringFormatter().replacePlaceholder(
|
||||
MiniGameMessage.SUCCESS_COMMAND_REWARDED, "{command}", command);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Map<String, Object> serialize() {
|
||||
Map<String, Object> data = new HashMap<>();
|
||||
data.put("command", command);
|
||||
return data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Replaces the name placeholder in the given input with the given player's name
|
||||
*
|
||||
* @param player <p>The player whose name should be used</p>
|
||||
* @param input <p>The input containing a name placeholder</p>
|
||||
* @return <p>The input with the placeholder replaced</p>
|
||||
*/
|
||||
private String replaceNamePlaceholder(@NotNull Player player, @NotNull String input) {
|
||||
return input.replaceAll("[<%(\\[{]player[_\\-]?(name)?[>%)\\]}]", player.getName());
|
||||
}
|
||||
|
||||
/**
|
||||
* Deserializes the command reward defined in the given data
|
||||
*
|
||||
* @param data <p>The data to deserialize from</p>
|
||||
* @return <p>The deserialized data</p>
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public static CommandReward deserialize(Map<String, Object> data) {
|
||||
return new CommandReward((String) data.get("command"));
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,65 @@
|
||||
package net.knarcraft.minigames.arena.reward;
|
||||
|
||||
import net.knarcraft.minigames.MiniGames;
|
||||
import net.knarcraft.minigames.config.MiniGameMessage;
|
||||
import net.knarcraft.minigames.manager.EconomyManager;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.logging.Level;
|
||||
|
||||
/**
|
||||
* A reward that gives an amount of currency when it's granted
|
||||
*/
|
||||
public class EconomyReward implements Reward {
|
||||
|
||||
private final double amount;
|
||||
|
||||
/**
|
||||
* Instantiates a new economy reward
|
||||
*
|
||||
* @param amount <p>The amount of currency granted</p>
|
||||
*/
|
||||
public EconomyReward(double amount) {
|
||||
this.amount = amount;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean grant(@NotNull Player player) {
|
||||
if (!EconomyManager.isInitialized()) {
|
||||
MiniGames.log(Level.SEVERE, "An economy reward has been set, but no Vault-compatible economy" +
|
||||
" plugin has been initialized.");
|
||||
return false;
|
||||
}
|
||||
EconomyManager.deposit(player, amount);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull String getGrantMessage() {
|
||||
return MiniGames.getInstance().getStringFormatter().replacePlaceholder(MiniGameMessage.SUCCESS_ECONOMY_REWARDED,
|
||||
"{currency}", EconomyManager.format(amount));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Map<String, Object> serialize() {
|
||||
Map<String, Object> data = new HashMap<>();
|
||||
data.put("amount", amount);
|
||||
return data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Deserializes the economy reward defined in the given data
|
||||
*
|
||||
* @param data <p>The data to deserialize from</p>
|
||||
* @return <p>The deserialized data</p>
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public static EconomyReward deserialize(Map<String, Object> data) {
|
||||
return new EconomyReward((Double) data.get("amount"));
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,108 @@
|
||||
package net.knarcraft.minigames.arena.reward;
|
||||
|
||||
import net.knarcraft.minigames.MiniGames;
|
||||
import net.knarcraft.minigames.config.MiniGameMessage;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* A reward that gives an item stack when granted
|
||||
*/
|
||||
public class ItemReward implements Reward {
|
||||
|
||||
private final ItemStack item;
|
||||
|
||||
/**
|
||||
* Instantiates a new item reward
|
||||
*
|
||||
* @param item <p>The item rewarded</p>
|
||||
*/
|
||||
public ItemReward(@NotNull ItemStack item) {
|
||||
if (item.getAmount() > item.getMaxStackSize()) {
|
||||
throw new IllegalArgumentException("Item stack exceeds the maximum stack size");
|
||||
}
|
||||
this.item = item;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean grant(@NotNull Player player) {
|
||||
Inventory inventory = player.getInventory();
|
||||
if (canFitItem(inventory)) {
|
||||
inventory.addItem(item);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull String getGrantMessage() {
|
||||
return MiniGames.getInstance().getStringFormatter().replacePlaceholders(MiniGameMessage.SUCCESS_ITEM_REWARDED,
|
||||
new String[]{"{amount}", "{item}"}, new String[]{String.valueOf(item.getAmount()),
|
||||
item.getType().getKey().getKey().replace("_", " ")});
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Map<String, Object> serialize() {
|
||||
Map<String, Object> data = new HashMap<>();
|
||||
data.put("item", item);
|
||||
return data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Deserializes the item reward defined in the given data
|
||||
*
|
||||
* @param data <p>The data to deserialize from</p>
|
||||
* @return <p>The deserialized data</p>
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public static ItemReward deserialize(Map<String, Object> data) {
|
||||
return new ItemReward((ItemStack) data.get("item"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether the given inventory is able to fit this item reward
|
||||
*
|
||||
* @param inventory <p>The inventory to check</p>
|
||||
* @return <p>True if the inventory can fit the item</p>
|
||||
*/
|
||||
private boolean canFitItem(Inventory inventory) {
|
||||
// If a slot is available, there is no problem
|
||||
if (inventory.firstEmpty() != -1) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// If the inventory doesn't contain the correct type of item, stacking is impossible
|
||||
if (!inventory.contains(item.getType())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check if the item stack can fit in the inventory if stacked with existing items
|
||||
int availableSlots = 0;
|
||||
for (ItemStack itemStack : inventory.getStorageContents()) {
|
||||
ItemMeta itemMeta = itemStack.getItemMeta();
|
||||
ItemMeta targetMeta = item.getItemMeta();
|
||||
// Skip items of a different type, or with metadata that would prevent stacking
|
||||
if (itemStack.getType() != item.getType() ||
|
||||
(itemMeta != null && targetMeta != null && !itemMeta.equals(targetMeta))) {
|
||||
continue;
|
||||
}
|
||||
|
||||
availableSlots += itemStack.getMaxStackSize() - itemStack.getAmount();
|
||||
|
||||
if (availableSlots < item.getAmount()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,85 @@
|
||||
package net.knarcraft.minigames.arena.reward;
|
||||
|
||||
import net.knarcraft.minigames.MiniGames;
|
||||
import net.knarcraft.minigames.config.MiniGameMessage;
|
||||
import net.knarcraft.minigames.manager.PermissionManager;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.logging.Level;
|
||||
|
||||
/**
|
||||
* A reward that grants a specified permission when granted
|
||||
*/
|
||||
public class PermissionReward implements Reward {
|
||||
|
||||
private final @NotNull String permission;
|
||||
private final @Nullable World world;
|
||||
|
||||
/**
|
||||
* Instantiates a new permission reward
|
||||
*
|
||||
* @param world <p>The world to grant the permission for, or null</p>
|
||||
* @param permission <p>The permission to grant</p>
|
||||
*/
|
||||
public PermissionReward(@Nullable World world, @NotNull String permission) {
|
||||
this.world = world;
|
||||
this.permission = permission;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean grant(@NotNull Player player) {
|
||||
if (!PermissionManager.isInitialized()) {
|
||||
MiniGames.log(Level.SEVERE, "A permission reward has been set, but no Vault-compatible permission" +
|
||||
" plugin has been initialized.");
|
||||
return false;
|
||||
}
|
||||
if (PermissionManager.hasPermission(player, this.permission, this.world != null ? this.world.getName() : null)) {
|
||||
return false;
|
||||
} else {
|
||||
PermissionManager.addPermission(player, this.permission, this.world);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull String getGrantMessage() {
|
||||
if (world == null) {
|
||||
return MiniGames.getInstance().getStringFormatter().replacePlaceholder(
|
||||
MiniGameMessage.SUCCESS_PERMISSION_REWARDED, "{permission}", permission);
|
||||
} else {
|
||||
return MiniGames.getInstance().getStringFormatter().replacePlaceholders(
|
||||
MiniGameMessage.SUCCESS_PERMISSION_REWARDED_WORLD, new String[]{"{permission}", "{world}"},
|
||||
new String[]{permission, world.getName()});
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Map<String, Object> serialize() {
|
||||
Map<String, Object> data = new HashMap<>();
|
||||
if (world != null) {
|
||||
data.put("world", world);
|
||||
}
|
||||
data.put("permission", permission);
|
||||
return data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Deserializes the permission reward defined in the given data
|
||||
*
|
||||
* @param data <p>The data to deserialize from</p>
|
||||
* @return <p>The deserialized data</p>
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public static PermissionReward deserialize(Map<String, Object> data) {
|
||||
World world = (World) data.getOrDefault("world", null);
|
||||
String permission = (String) data.get("permission");
|
||||
return new PermissionReward(world, permission);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
package net.knarcraft.minigames.arena.reward;
|
||||
|
||||
import org.bukkit.configuration.serialization.ConfigurationSerializable;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* A reward a player can be awarded
|
||||
*/
|
||||
public interface Reward extends ConfigurationSerializable {
|
||||
|
||||
/**
|
||||
* Grants this reward to the given player
|
||||
*
|
||||
* @param player <p>The player this reward should be granted to</p>
|
||||
* @return <p>True if the item was granted. False if not possible.</p>
|
||||
*/
|
||||
boolean grant(@NotNull Player player);
|
||||
|
||||
/**
|
||||
* Gets the message to display to a user when granting this reward
|
||||
*
|
||||
* @return <p>The message to display when this reward is granted</p>
|
||||
*/
|
||||
@NotNull String getGrantMessage();
|
||||
|
||||
}
|
@ -0,0 +1,83 @@
|
||||
package net.knarcraft.minigames.arena.reward;
|
||||
|
||||
import org.bukkit.configuration.serialization.ConfigurationSerializable;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* The condition for granting a reward
|
||||
*/
|
||||
public enum RewardCondition implements ConfigurationSerializable {
|
||||
|
||||
/**
|
||||
* The reward is granted each time the player wins/clears the arena
|
||||
*/
|
||||
WIN,
|
||||
|
||||
/**
|
||||
* The reward is granted the first time the player wins/clears the arena
|
||||
*/
|
||||
FIRST_WIN,
|
||||
|
||||
/**
|
||||
* The reward is granted if the player beats their personal least deaths record
|
||||
*/
|
||||
PERSONAL_DEATH_RECORD,
|
||||
|
||||
/**
|
||||
* The reward is granted if the player beats their personal least time record
|
||||
*/
|
||||
PERSONAL_TIME_RECORD,
|
||||
|
||||
/**
|
||||
* The reward is granted if the player beats the global least deaths record
|
||||
*/
|
||||
GLOBAL_DEATH_RECORD,
|
||||
|
||||
/**
|
||||
* The reward is granted if the player beats the global least time record
|
||||
*/
|
||||
GLOBAL_TIME_RECORD,
|
||||
;
|
||||
|
||||
/**
|
||||
* Gets a reward condition from the given string
|
||||
*
|
||||
* @param condition <p>The string specifying a reward condition</p>
|
||||
* @return <p>The matching reward condition, or null if not found</p>
|
||||
*/
|
||||
public static @Nullable RewardCondition getFromString(@NotNull String condition) {
|
||||
for (RewardCondition rewardCondition : RewardCondition.values()) {
|
||||
if (rewardCondition.name().equalsIgnoreCase(condition.replace("-", "_"))) {
|
||||
return rewardCondition;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Map<String, Object> serialize() {
|
||||
Map<String, Object> data = new HashMap<>();
|
||||
data.put("condition", this.name());
|
||||
return data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Deserializes a reward condition from the given data
|
||||
*
|
||||
* @param data <p>The data to deserialize</p>
|
||||
* @return <p>The deserialized reward condition</p>
|
||||
*/
|
||||
@SuppressWarnings({"unused"})
|
||||
public static @NotNull RewardCondition deserialize(@NotNull Map<String, Object> data) {
|
||||
RewardCondition rewardCondition = getFromString(String.valueOf(data.get("condition")));
|
||||
return Objects.requireNonNullElse(rewardCondition, RewardCondition.FIRST_WIN);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,47 @@
|
||||
package net.knarcraft.minigames.arena.reward;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* The type of a specific reward
|
||||
*/
|
||||
public enum RewardType {
|
||||
|
||||
/**
|
||||
* A command reward
|
||||
*/
|
||||
COMMAND,
|
||||
|
||||
/**
|
||||
* An economy reward
|
||||
*/
|
||||
ECONOMY,
|
||||
|
||||
/**
|
||||
* An item reward
|
||||
*/
|
||||
ITEM,
|
||||
|
||||
/**
|
||||
* A permission reward
|
||||
*/
|
||||
PERMISSION,
|
||||
;
|
||||
|
||||
/**
|
||||
* Gets a reward type from the given string
|
||||
*
|
||||
* @param condition <p>The string specifying a reward type</p>
|
||||
* @return <p>The matching reward type, or null if not found</p>
|
||||
*/
|
||||
public static RewardType getFromString(@NotNull String condition) {
|
||||
for (RewardType rewardType : RewardType.values()) {
|
||||
if (rewardType.name().equalsIgnoreCase(condition.replace("-", "_"))) {
|
||||
return rewardType;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,51 @@
|
||||
package net.knarcraft.minigames.command;
|
||||
|
||||
import net.knarcraft.minigames.arena.ArenaGameMode;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.TabCompleter;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import static net.knarcraft.knarlib.util.TabCompletionHelper.filterMatchingContains;
|
||||
|
||||
/**
|
||||
* An abstract class for an arena joining tab-completer
|
||||
*/
|
||||
public abstract class JoinArenaTabCompleter implements TabCompleter {
|
||||
|
||||
private final ArenaGameMode gameMode;
|
||||
private final Supplier<List<String>> arenaNameSupplier;
|
||||
|
||||
/**
|
||||
* Implements a new join arena tab completer
|
||||
*
|
||||
* @param arenaNameSupplier <p>The supplier to ask for arena names</p>
|
||||
* @param gameMode <p>An instance of one of the available game-modes</p>
|
||||
*/
|
||||
public JoinArenaTabCompleter(Supplier<List<String>> arenaNameSupplier, ArenaGameMode gameMode) {
|
||||
this.arenaNameSupplier = arenaNameSupplier;
|
||||
this.gameMode = gameMode;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command,
|
||||
@NotNull String label, @NotNull String[] arguments) {
|
||||
if (arguments.length == 1) {
|
||||
return filterMatchingContains(arenaNameSupplier.get(), arguments[0]);
|
||||
} else if (arguments.length == 2) {
|
||||
List<String> gameModes = new ArrayList<>();
|
||||
for (ArenaGameMode gameMode : gameMode.getValues()) {
|
||||
gameModes.add(gameMode.name().toLowerCase());
|
||||
}
|
||||
return filterMatchingContains(gameModes, arguments[1]);
|
||||
} else {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,7 +1,8 @@
|
||||
package net.knarcraft.dropper.command;
|
||||
package net.knarcraft.minigames.command;
|
||||
|
||||
import net.knarcraft.dropper.Dropper;
|
||||
import net.knarcraft.dropper.arena.DropperArenaSession;
|
||||
import net.knarcraft.minigames.MiniGames;
|
||||
import net.knarcraft.minigames.arena.ArenaSession;
|
||||
import net.knarcraft.minigames.config.MiniGameMessage;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.TabExecutor;
|
||||
@ -21,18 +22,19 @@ public class LeaveArenaCommand implements TabExecutor {
|
||||
public boolean onCommand(@NotNull CommandSender commandSender, @NotNull Command command, @NotNull String s,
|
||||
@NotNull String[] strings) {
|
||||
if (!(commandSender instanceof Player player)) {
|
||||
commandSender.sendMessage("This command must be used by a player");
|
||||
MiniGames.getInstance().getStringFormatter().displayErrorMessage(commandSender,
|
||||
MiniGameMessage.ERROR_PLAYER_ONLY);
|
||||
return false;
|
||||
}
|
||||
|
||||
DropperArenaSession existingSession = Dropper.getInstance().getPlayerRegistry().getArenaSession(
|
||||
player.getUniqueId());
|
||||
ArenaSession existingSession = MiniGames.getInstance().getSession(player.getUniqueId());
|
||||
if (existingSession == null) {
|
||||
commandSender.sendMessage("You are not in a dropper arena!");
|
||||
MiniGames.getInstance().getStringFormatter().displayErrorMessage(commandSender,
|
||||
MiniGameMessage.ERROR_NOT_IN_ARENA);
|
||||
return false;
|
||||
}
|
||||
|
||||
existingSession.triggerQuit(false);
|
||||
existingSession.triggerQuit(false, true);
|
||||
return true;
|
||||
}
|
||||
|
@ -0,0 +1,41 @@
|
||||
package net.knarcraft.minigames.command;
|
||||
|
||||
import net.knarcraft.minigames.MiniGames;
|
||||
import net.knarcraft.minigames.config.MiniGameMessage;
|
||||
import net.knarcraft.minigames.util.GUIHelper;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.TabExecutor;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* The command for opening up an arena's menu
|
||||
*/
|
||||
public class MenuCommand implements TabExecutor {
|
||||
|
||||
@Override
|
||||
public boolean onCommand(@NotNull CommandSender commandSender, @NotNull Command command, @NotNull String s,
|
||||
@NotNull String[] arguments) {
|
||||
if (!(commandSender instanceof Player player)) {
|
||||
MiniGames.getInstance().getStringFormatter().displayErrorMessage(commandSender,
|
||||
MiniGameMessage.ERROR_PLAYER_ONLY);
|
||||
return false;
|
||||
}
|
||||
|
||||
GUIHelper.openGUI(player);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public List<String> onTabComplete(@NotNull CommandSender commandSender, @NotNull Command command, @NotNull String s,
|
||||
@NotNull String[] strings) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
}
|
@ -1,6 +1,7 @@
|
||||
package net.knarcraft.dropper.command;
|
||||
package net.knarcraft.minigames.command;
|
||||
|
||||
import net.knarcraft.dropper.Dropper;
|
||||
import net.knarcraft.minigames.MiniGames;
|
||||
import net.knarcraft.minigames.config.MiniGameMessage;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.TabExecutor;
|
||||
@ -18,8 +19,9 @@ public class ReloadCommand implements TabExecutor {
|
||||
@Override
|
||||
public boolean onCommand(@NotNull CommandSender commandSender, @NotNull Command command, @NotNull String s,
|
||||
@NotNull String[] arguments) {
|
||||
Dropper.getInstance().reload();
|
||||
commandSender.sendMessage("Plugin reloaded!");
|
||||
MiniGames.getInstance().reload();
|
||||
MiniGames.getInstance().getStringFormatter().displaySuccessMessage(commandSender,
|
||||
MiniGameMessage.SUCCESS_PLUGIN_RELOADED);
|
||||
return true;
|
||||
}
|
||||
|
@ -0,0 +1,90 @@
|
||||
package net.knarcraft.minigames.command;
|
||||
|
||||
import net.knarcraft.minigames.MiniGames;
|
||||
import net.knarcraft.minigames.arena.Arena;
|
||||
import net.knarcraft.minigames.arena.reward.Reward;
|
||||
import net.knarcraft.minigames.arena.reward.RewardCondition;
|
||||
import net.knarcraft.minigames.config.MiniGameMessage;
|
||||
import net.knarcraft.minigames.util.RewardHelper;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* The command used for setting arena rewards
|
||||
*/
|
||||
public class SetArenaRewardCommand implements CommandExecutor {
|
||||
|
||||
@Override
|
||||
public boolean onCommand(@NotNull CommandSender commandSender, @NotNull Command command, @NotNull String s,
|
||||
@NotNull String[] arguments) {
|
||||
if (!(commandSender instanceof Player player)) {
|
||||
MiniGames.getInstance().getStringFormatter().displayErrorMessage(commandSender,
|
||||
MiniGameMessage.ERROR_PLAYER_ONLY);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (arguments.length < 4) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
/MiniGamesReward add dropper <name> <condition> <type> [data]
|
||||
/MiniGamesReward add parkour <name> <condition> <type> [data]
|
||||
/MiniGamesReward clear dropper <name> <condition>
|
||||
/MiniGamesReward clear parkour <name> <condition>
|
||||
|
||||
*/
|
||||
|
||||
Arena arena = null;
|
||||
if (arguments[1].equalsIgnoreCase("dropper")) {
|
||||
arena = MiniGames.getInstance().getDropperArenaHandler().getArena(arguments[2]);
|
||||
} else if (arguments[1].equalsIgnoreCase("parkour")) {
|
||||
arena = MiniGames.getInstance().getParkourArenaHandler().getArena(arguments[2]);
|
||||
}
|
||||
if (arena == null) {
|
||||
MiniGames.getInstance().getStringFormatter().displayErrorMessage(commandSender,
|
||||
MiniGameMessage.ERROR_ARENA_NOT_FOUND);
|
||||
return false;
|
||||
}
|
||||
|
||||
RewardCondition condition = RewardCondition.getFromString(arguments[3]);
|
||||
if (condition == null) {
|
||||
MiniGames.getInstance().getStringFormatter().displayErrorMessage(player,
|
||||
MiniGameMessage.ERROR_REWARD_CONDITION_INVALID);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (arguments[0].equalsIgnoreCase("clear")) {
|
||||
arena.clearRewards(condition);
|
||||
MiniGames.getInstance().getStringFormatter().displaySuccessMessage(player,
|
||||
MiniGameMessage.SUCCESS_REWARDS_CLEARED);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!arguments[0].equalsIgnoreCase("add") || arguments.length < 5) {
|
||||
return false;
|
||||
}
|
||||
|
||||
String firstArgument = arguments.length > 5 ? arguments[5] : null;
|
||||
String secondArgument = arguments.length > 6 ? arguments[6] : null;
|
||||
|
||||
Reward reward = RewardHelper.parseRewardInput(player, arguments[4], firstArgument, secondArgument,
|
||||
Arrays.copyOfRange(arguments, 5, arguments.length));
|
||||
|
||||
if (reward != null) {
|
||||
arena.addReward(condition, reward);
|
||||
MiniGames.getInstance().getStringFormatter().displaySuccessMessage(player,
|
||||
MiniGameMessage.SUCCESS_REWARD_ADDED);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,168 @@
|
||||
package net.knarcraft.minigames.command;
|
||||
|
||||
import net.knarcraft.knarlib.util.MaterialHelper;
|
||||
import net.knarcraft.knarlib.util.TabCompletionHelper;
|
||||
import net.knarcraft.minigames.MiniGames;
|
||||
import net.knarcraft.minigames.arena.Arena;
|
||||
import net.knarcraft.minigames.arena.reward.RewardCondition;
|
||||
import net.knarcraft.minigames.arena.reward.RewardType;
|
||||
import net.knarcraft.minigames.util.TabCompleteHelper;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.TabCompleter;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import static net.knarcraft.knarlib.util.TabCompletionHelper.filterMatchingContains;
|
||||
import static net.knarcraft.knarlib.util.TabCompletionHelper.filterMatchingStartsWith;
|
||||
|
||||
/**
|
||||
* The tab completer for the reward setting command
|
||||
*/
|
||||
public class SetArenaRewardTabCompleter implements TabCompleter {
|
||||
|
||||
private static final List<String> materials = getMaterials();
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public List<String> onTabComplete(@NotNull CommandSender commandSender, @NotNull Command command, @NotNull String s,
|
||||
@NotNull String[] arguments) {
|
||||
if (arguments.length == 1) {
|
||||
// The first argument is either clear or add
|
||||
return TabCompletionHelper.filterMatchingStartsWith(Arrays.asList("add", "clear"), arguments[0]);
|
||||
}
|
||||
if (arguments.length >= 2) {
|
||||
// If the first argument is invalid, stop further tab completion
|
||||
if (!arguments[0].equalsIgnoreCase("add") && !arguments[0].equalsIgnoreCase("clear")) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
}
|
||||
if (arguments.length == 2) {
|
||||
// The second argument is the type of arena to change rewards for
|
||||
return TabCompletionHelper.filterMatchingStartsWith(Arrays.asList("dropper", "parkour"), arguments[1]);
|
||||
} else if (arguments.length == 3) {
|
||||
// The third argument is the name of the arena to change rewards for
|
||||
if (arguments[1].equalsIgnoreCase("dropper")) {
|
||||
return filterMatchingContains(TabCompleteHelper.getDropperArenas(), arguments[2]);
|
||||
} else if (arguments[1].equalsIgnoreCase("parkour")) {
|
||||
return filterMatchingContains(TabCompleteHelper.getParkourArenas(), arguments[2]);
|
||||
}
|
||||
}
|
||||
if (arguments.length >= 4) {
|
||||
// Make sure a valid dropper or arena name has been given
|
||||
Arena arena = null;
|
||||
if (arguments[1].equalsIgnoreCase("dropper")) {
|
||||
arena = MiniGames.getInstance().getDropperArenaHandler().getArena(arguments[2]);
|
||||
} else if (arguments[1].equalsIgnoreCase("parkour")) {
|
||||
arena = MiniGames.getInstance().getParkourArenaHandler().getArena(arguments[2]);
|
||||
}
|
||||
if (arena == null) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
}
|
||||
if (arguments.length == 4) {
|
||||
// The fourth argument is the condition to change the reward for
|
||||
return filterMatchingContains(getRewardConditions(), arguments[3]);
|
||||
}
|
||||
if (arguments.length >= 5) {
|
||||
// If the condition is invalid, or it's the clear action, stop tab-completion
|
||||
if (RewardCondition.getFromString(arguments[3]) == null ||
|
||||
arguments[0].equalsIgnoreCase("clear")) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
}
|
||||
if (arguments.length == 5) {
|
||||
// The fifth argument is the type of reward to grant
|
||||
return filterMatchingContains(getRewardTypes(), arguments[4]);
|
||||
}
|
||||
if (arguments.length >= 6) {
|
||||
// Make sure a valid reward type has been given
|
||||
RewardType rewardType = RewardType.getFromString(arguments[4]);
|
||||
if (rewardType == null) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
if (arguments.length == 6) {
|
||||
return switch (rewardType) {
|
||||
case ITEM -> filterMatchingContains(materials, arguments[5]);
|
||||
case PERMISSION -> TabCompleteHelper.tabCompletePermission(arguments[5]);
|
||||
case ECONOMY -> filterMatchingStartsWith(Arrays.asList("1", "5", "10", "25", "50"), arguments[5]);
|
||||
case COMMAND -> filterMatchingStartsWith(getCommands(), arguments[5]);
|
||||
};
|
||||
}
|
||||
|
||||
if (rewardType == RewardType.ITEM && arguments.length == 7) {
|
||||
// If a valid item material has been given, give potential amounts
|
||||
if (MaterialHelper.loadMaterialString(arguments[5], MiniGames.getInstance().getLogger()) == null) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
return Arrays.asList("1", "5", "10", "16", "32", "48", "64");
|
||||
}
|
||||
}
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets example command rewards
|
||||
*
|
||||
* @return <p>Example command rewards</p>
|
||||
*/
|
||||
private static List<String> getCommands() {
|
||||
List<String> commands = new ArrayList<>();
|
||||
commands.add("f powerboost player add %player% 1");
|
||||
commands.add("minecraft:xp give (player_name) 1000");
|
||||
return commands;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets all materials grant-able as item rewards
|
||||
*
|
||||
* @return <p>All grant-able materials</p>
|
||||
*/
|
||||
private static List<String> getMaterials() {
|
||||
List<String> materials = new ArrayList<>();
|
||||
Set<Material> invalid = EnumSet.of(Material.WATER, Material.LAVA, Material.POWDER_SNOW);
|
||||
for (Material material : Material.values()) {
|
||||
if (material.isAir() || invalid.contains(material) || (material.isBlock() &&
|
||||
(material.getHardness() == -1 || material.getHardness() == Double.MAX_VALUE))) {
|
||||
continue;
|
||||
}
|
||||
materials.add(material.name());
|
||||
}
|
||||
return materials;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a list of all reward types
|
||||
*
|
||||
* @return <p>All reward types</p>
|
||||
*/
|
||||
private List<String> getRewardTypes() {
|
||||
List<String> types = new ArrayList<>();
|
||||
for (RewardType rewardType : RewardType.values()) {
|
||||
types.add(rewardType.name());
|
||||
}
|
||||
return types;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a list of all reward conditions
|
||||
*
|
||||
* @return <p>All reward conditions</p>
|
||||
*/
|
||||
private List<String> getRewardConditions() {
|
||||
List<String> conditions = new ArrayList<>();
|
||||
for (RewardCondition rewardCondition : RewardCondition.values()) {
|
||||
conditions.add(rewardCondition.name());
|
||||
}
|
||||
return conditions;
|
||||
}
|
||||
|
||||
}
|
@ -1,8 +1,10 @@
|
||||
package net.knarcraft.dropper.command;
|
||||
package net.knarcraft.minigames.command.dropper;
|
||||
|
||||
import net.knarcraft.dropper.Dropper;
|
||||
import net.knarcraft.dropper.arena.DropperArena;
|
||||
import net.knarcraft.dropper.util.StringSanitizer;
|
||||
import net.knarcraft.minigames.MiniGames;
|
||||
import net.knarcraft.minigames.arena.dropper.DropperArena;
|
||||
import net.knarcraft.minigames.arena.dropper.DropperArenaHandler;
|
||||
import net.knarcraft.minigames.config.MiniGameMessage;
|
||||
import net.knarcraft.minigames.util.StringSanitizer;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
@ -12,13 +14,14 @@ import org.jetbrains.annotations.NotNull;
|
||||
/**
|
||||
* The command for creating a new dropper arena
|
||||
*/
|
||||
public class CreateArenaCommand implements CommandExecutor {
|
||||
public class CreateDropperArenaCommand implements CommandExecutor {
|
||||
|
||||
@Override
|
||||
public boolean onCommand(@NotNull CommandSender commandSender, @NotNull Command command, @NotNull String s,
|
||||
@NotNull String[] arguments) {
|
||||
if (!(commandSender instanceof Player player)) {
|
||||
commandSender.sendMessage("This command must be used by a player");
|
||||
MiniGames.getInstance().getStringFormatter().displayErrorMessage(commandSender,
|
||||
MiniGameMessage.ERROR_PLAYER_ONLY);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -35,15 +38,18 @@ public class CreateArenaCommand implements CommandExecutor {
|
||||
return false;
|
||||
}
|
||||
|
||||
DropperArena existingArena = Dropper.getInstance().getArenaHandler().getArena(arenaName);
|
||||
DropperArenaHandler arenaHandler = MiniGames.getInstance().getDropperArenaHandler();
|
||||
DropperArena existingArena = arenaHandler.getArena(arenaName);
|
||||
if (existingArena != null) {
|
||||
commandSender.sendMessage("There already exists a dropper arena with that name!");
|
||||
MiniGames.getInstance().getStringFormatter().displayErrorMessage(commandSender,
|
||||
MiniGameMessage.ERROR_ARENA_NAME_COLLISION);
|
||||
return false;
|
||||
}
|
||||
|
||||
DropperArena arena = new DropperArena(arenaName, player.getLocation());
|
||||
Dropper.getInstance().getArenaHandler().addArena(arena);
|
||||
commandSender.sendMessage("The arena was successfully created!");
|
||||
DropperArena arena = new DropperArena(arenaName, player.getLocation(), arenaHandler);
|
||||
arenaHandler.addArena(arena);
|
||||
MiniGames.getInstance().getStringFormatter().displaySuccessMessage(commandSender,
|
||||
MiniGameMessage.SUCCESS_ARENA_CREATED);
|
||||
return true;
|
||||
}
|
||||
|
@ -1,9 +1,11 @@
|
||||
package net.knarcraft.dropper.command;
|
||||
package net.knarcraft.minigames.command.dropper;
|
||||
|
||||
import net.knarcraft.dropper.Dropper;
|
||||
import net.knarcraft.dropper.arena.DropperArena;
|
||||
import net.knarcraft.dropper.arena.DropperArenaGroup;
|
||||
import net.knarcraft.dropper.arena.DropperArenaHandler;
|
||||
import net.knarcraft.knarlib.formatting.StringFormatter;
|
||||
import net.knarcraft.minigames.MiniGames;
|
||||
import net.knarcraft.minigames.arena.dropper.DropperArena;
|
||||
import net.knarcraft.minigames.arena.dropper.DropperArenaGroup;
|
||||
import net.knarcraft.minigames.arena.dropper.DropperArenaHandler;
|
||||
import net.knarcraft.minigames.config.MiniGameMessage;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.TabExecutor;
|
||||
@ -14,15 +16,17 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import static net.knarcraft.knarlib.util.TabCompletionHelper.filterMatchingContains;
|
||||
|
||||
/**
|
||||
* The command for listing groups and the stages within
|
||||
*/
|
||||
public class GroupListCommand implements TabExecutor {
|
||||
public class DropperGroupListCommand implements TabExecutor {
|
||||
|
||||
@Override
|
||||
public boolean onCommand(@NotNull CommandSender commandSender, @NotNull Command command, @NotNull String s,
|
||||
@NotNull String[] arguments) {
|
||||
DropperArenaHandler arenaHandler = Dropper.getInstance().getArenaHandler();
|
||||
DropperArenaHandler arenaHandler = MiniGames.getInstance().getDropperArenaHandler();
|
||||
if (arguments.length == 0) {
|
||||
displayExistingGroups(arenaHandler, commandSender);
|
||||
return true;
|
||||
@ -57,13 +61,15 @@ public class GroupListCommand implements TabExecutor {
|
||||
private boolean displayOrderedArenaNames(@NotNull DropperArenaHandler arenaHandler, @NotNull CommandSender sender,
|
||||
@NotNull String groupName) {
|
||||
DropperArenaGroup arenaGroup = arenaHandler.getGroup(groupName);
|
||||
StringFormatter stringFormatter = MiniGames.getInstance().getStringFormatter();
|
||||
if (arenaGroup == null) {
|
||||
sender.sendMessage("Unable to find the specified group!");
|
||||
stringFormatter.displayErrorMessage(sender, MiniGameMessage.ERROR_GROUP_NOT_FOUND);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Send a list of all stages (arenas in the group)
|
||||
StringBuilder builder = new StringBuilder(groupName).append("'s stages:").append("\n");
|
||||
StringBuilder builder = new StringBuilder(stringFormatter.replacePlaceholder(
|
||||
MiniGameMessage.SUCCESS_GROUP_STAGES, "{group}", groupName));
|
||||
int counter = 1;
|
||||
for (UUID arenaId : arenaGroup.getArenas()) {
|
||||
DropperArena arena = arenaHandler.getArena(arenaId);
|
||||
@ -71,7 +77,7 @@ public class GroupListCommand implements TabExecutor {
|
||||
builder.append(counter++).append(". ").append(arena.getArenaName()).append("\n");
|
||||
}
|
||||
}
|
||||
sender.sendMessage(builder.toString());
|
||||
stringFormatter.displaySuccessMessage(sender, builder.toString());
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -81,10 +87,10 @@ public class GroupListCommand implements TabExecutor {
|
||||
@NotNull String[] arguments) {
|
||||
if (arguments.length == 1) {
|
||||
List<String> groupNames = new ArrayList<>();
|
||||
for (DropperArenaGroup group : Dropper.getInstance().getArenaHandler().getAllGroups()) {
|
||||
for (DropperArenaGroup group : MiniGames.getInstance().getDropperArenaHandler().getAllGroups()) {
|
||||
groupNames.add(group.getGroupName());
|
||||
}
|
||||
return groupNames;
|
||||
return filterMatchingContains(groupNames, arguments[0]);
|
||||
} else {
|
||||
return new ArrayList<>();
|
||||
}
|
@ -1,11 +1,12 @@
|
||||
package net.knarcraft.dropper.command;
|
||||
package net.knarcraft.minigames.command.dropper;
|
||||
|
||||
import net.knarcraft.dropper.Dropper;
|
||||
import net.knarcraft.dropper.arena.DropperArena;
|
||||
import net.knarcraft.dropper.arena.DropperArenaGroup;
|
||||
import net.knarcraft.dropper.arena.DropperArenaHandler;
|
||||
import net.knarcraft.dropper.util.StringSanitizer;
|
||||
import net.knarcraft.dropper.util.TabCompleteHelper;
|
||||
import net.knarcraft.minigames.MiniGames;
|
||||
import net.knarcraft.minigames.arena.dropper.DropperArena;
|
||||
import net.knarcraft.minigames.arena.dropper.DropperArenaGroup;
|
||||
import net.knarcraft.minigames.arena.dropper.DropperArenaHandler;
|
||||
import net.knarcraft.minigames.config.MiniGameMessage;
|
||||
import net.knarcraft.minigames.util.StringSanitizer;
|
||||
import net.knarcraft.minigames.util.TabCompleteHelper;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.TabExecutor;
|
||||
@ -15,10 +16,12 @@ import org.jetbrains.annotations.Nullable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static net.knarcraft.knarlib.util.TabCompletionHelper.filterMatchingContains;
|
||||
|
||||
/**
|
||||
* The command for setting the group of an arena
|
||||
*/
|
||||
public class GroupSetCommand implements TabExecutor {
|
||||
public class DropperGroupSetCommand implements TabExecutor {
|
||||
|
||||
@Override
|
||||
public boolean onCommand(@NotNull CommandSender commandSender, @NotNull Command command, @NotNull String s,
|
||||
@ -27,11 +30,12 @@ public class GroupSetCommand implements TabExecutor {
|
||||
return false;
|
||||
}
|
||||
|
||||
DropperArenaHandler arenaHandler = Dropper.getInstance().getArenaHandler();
|
||||
DropperArenaHandler arenaHandler = MiniGames.getInstance().getDropperArenaHandler();
|
||||
|
||||
DropperArena specifiedArena = arenaHandler.getArena(arguments[0]);
|
||||
if (specifiedArena == null) {
|
||||
commandSender.sendMessage("Unable to find the specified dropper arena.");
|
||||
MiniGames.getInstance().getStringFormatter().displayErrorMessage(commandSender,
|
||||
MiniGameMessage.ERROR_ARENA_NOT_FOUND);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -53,7 +57,8 @@ public class GroupSetCommand implements TabExecutor {
|
||||
|
||||
arenaHandler.setGroup(specifiedArena.getArenaId(), arenaGroup);
|
||||
|
||||
commandSender.sendMessage("The arena's group has been updated");
|
||||
MiniGames.getInstance().getStringFormatter().displaySuccessMessage(commandSender,
|
||||
MiniGameMessage.SUCCESS_ARENA_GROUP_UPDATED);
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -62,15 +67,15 @@ public class GroupSetCommand implements TabExecutor {
|
||||
public List<String> onTabComplete(@NotNull CommandSender commandSender, @NotNull Command command, @NotNull String s,
|
||||
@NotNull String[] arguments) {
|
||||
if (arguments.length == 1) {
|
||||
return TabCompleteHelper.getArenas();
|
||||
return filterMatchingContains(TabCompleteHelper.getDropperArenas(), arguments[0]);
|
||||
} else if (arguments.length == 2) {
|
||||
List<String> possibleValues = new ArrayList<>();
|
||||
possibleValues.add("none");
|
||||
possibleValues.add("GroupName");
|
||||
for (DropperArenaGroup group : Dropper.getInstance().getArenaHandler().getAllGroups()) {
|
||||
for (DropperArenaGroup group : MiniGames.getInstance().getDropperArenaHandler().getAllGroups()) {
|
||||
possibleValues.add(group.getGroupName());
|
||||
}
|
||||
return possibleValues;
|
||||
return filterMatchingContains(possibleValues, arguments[1]);
|
||||
} else {
|
||||
return new ArrayList<>();
|
||||
}
|
@ -1,9 +1,11 @@
|
||||
package net.knarcraft.dropper.command;
|
||||
package net.knarcraft.minigames.command.dropper;
|
||||
|
||||
import net.knarcraft.dropper.Dropper;
|
||||
import net.knarcraft.dropper.arena.DropperArena;
|
||||
import net.knarcraft.dropper.arena.DropperArenaGroup;
|
||||
import net.knarcraft.dropper.arena.DropperArenaHandler;
|
||||
import net.knarcraft.knarlib.formatting.StringFormatter;
|
||||
import net.knarcraft.minigames.MiniGames;
|
||||
import net.knarcraft.minigames.arena.dropper.DropperArena;
|
||||
import net.knarcraft.minigames.arena.dropper.DropperArenaGroup;
|
||||
import net.knarcraft.minigames.arena.dropper.DropperArenaHandler;
|
||||
import net.knarcraft.minigames.config.MiniGameMessage;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.TabExecutor;
|
||||
@ -14,10 +16,12 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import static net.knarcraft.knarlib.util.TabCompletionHelper.filterMatchingContains;
|
||||
|
||||
/**
|
||||
* The command for swapping the order of two arenas in a group
|
||||
*/
|
||||
public class GroupSwapCommand implements TabExecutor {
|
||||
public class DropperGroupSwapCommand implements TabExecutor {
|
||||
|
||||
@Override
|
||||
public boolean onCommand(@NotNull CommandSender commandSender, @NotNull Command command, @NotNull String s,
|
||||
@ -26,30 +30,31 @@ public class GroupSwapCommand implements TabExecutor {
|
||||
return false;
|
||||
}
|
||||
|
||||
DropperArenaHandler arenaHandler = Dropper.getInstance().getArenaHandler();
|
||||
StringFormatter stringFormatter = MiniGames.getInstance().getStringFormatter();
|
||||
DropperArenaHandler arenaHandler = MiniGames.getInstance().getDropperArenaHandler();
|
||||
|
||||
DropperArena arena1 = arenaHandler.getArena(arguments[0]);
|
||||
if (arena1 == null) {
|
||||
commandSender.sendMessage("Unable to find the first specified dropper arena.");
|
||||
stringFormatter.displayErrorMessage(commandSender, MiniGameMessage.ERROR_ARENA_1_NOT_FOUND);
|
||||
return false;
|
||||
}
|
||||
|
||||
DropperArena arena2 = arenaHandler.getArena(arguments[1]);
|
||||
if (arena2 == null) {
|
||||
commandSender.sendMessage("Unable to find the second specified dropper arena.");
|
||||
stringFormatter.displayErrorMessage(commandSender, MiniGameMessage.ERROR_ARENA_2_NOT_FOUND);
|
||||
return false;
|
||||
}
|
||||
|
||||
DropperArenaGroup arena1Group = arenaHandler.getGroup(arena1.getArenaId());
|
||||
DropperArenaGroup arena2Group = arenaHandler.getGroup(arena2.getArenaId());
|
||||
if (arena1Group == null || !arena1Group.equals(arena2Group)) {
|
||||
commandSender.sendMessage("You cannot swap arenas in different groups!");
|
||||
stringFormatter.displayErrorMessage(commandSender, MiniGameMessage.ERROR_SWAP_DIFFERENT_GROUPS);
|
||||
return false;
|
||||
}
|
||||
|
||||
arena1Group.swapArenas(arena1Group.getArenas().indexOf(arena1.getArenaId()),
|
||||
arena1Group.getArenas().indexOf(arena2.getArenaId()));
|
||||
commandSender.sendMessage("The arenas have been swapped!");
|
||||
stringFormatter.displaySuccessMessage(commandSender, MiniGameMessage.SUCCESS_ARENAS_SWAPPED);
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -57,15 +62,15 @@ public class GroupSwapCommand implements TabExecutor {
|
||||
@Override
|
||||
public List<String> onTabComplete(@NotNull CommandSender commandSender, @NotNull Command command, @NotNull String s,
|
||||
@NotNull String[] arguments) {
|
||||
DropperArenaHandler arenaHandler = Dropper.getInstance().getArenaHandler();
|
||||
DropperArenaHandler arenaHandler = MiniGames.getInstance().getDropperArenaHandler();
|
||||
if (arguments.length == 1) {
|
||||
List<String> arenaNames = new ArrayList<>();
|
||||
for (DropperArena dropperArena : arenaHandler.getArenasInAGroup()) {
|
||||
arenaNames.add(dropperArena.getArenaName());
|
||||
}
|
||||
return arenaNames;
|
||||
return filterMatchingContains(arenaNames, arguments[0]);
|
||||
} else if (arguments.length == 2) {
|
||||
return getArenaNamesInSameGroup(arguments[0]);
|
||||
return filterMatchingContains(getArenaNamesInSameGroup(arguments[0]), arguments[1]);
|
||||
} else {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
@ -78,7 +83,7 @@ public class GroupSwapCommand implements TabExecutor {
|
||||
* @return <p>The names of the arenas in the same group</p>
|
||||
*/
|
||||
private List<String> getArenaNamesInSameGroup(String arenaName) {
|
||||
DropperArenaHandler arenaHandler = Dropper.getInstance().getArenaHandler();
|
||||
DropperArenaHandler arenaHandler = MiniGames.getInstance().getDropperArenaHandler();
|
||||
DropperArena arena1 = arenaHandler.getArena(arenaName);
|
||||
if (arena1 == null) {
|
||||
return new ArrayList<>();
|
@ -1,8 +1,11 @@
|
||||
package net.knarcraft.dropper.command;
|
||||
package net.knarcraft.minigames.command.dropper;
|
||||
|
||||
import net.knarcraft.dropper.Dropper;
|
||||
import net.knarcraft.dropper.arena.DropperArena;
|
||||
import net.knarcraft.dropper.property.ArenaEditableProperty;
|
||||
import net.knarcraft.knarlib.formatting.StringFormatter;
|
||||
import net.knarcraft.minigames.MiniGames;
|
||||
import net.knarcraft.minigames.arena.dropper.DropperArena;
|
||||
import net.knarcraft.minigames.arena.dropper.DropperArenaEditableProperty;
|
||||
import net.knarcraft.minigames.config.DropperConfiguration;
|
||||
import net.knarcraft.minigames.config.MiniGameMessage;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.command.Command;
|
||||
@ -14,13 +17,25 @@ import org.jetbrains.annotations.NotNull;
|
||||
/**
|
||||
* The command for editing an existing dropper arena
|
||||
*/
|
||||
public class EditArenaCommand implements CommandExecutor {
|
||||
public class EditDropperArenaCommand implements CommandExecutor {
|
||||
|
||||
private final DropperConfiguration configuration;
|
||||
|
||||
/**
|
||||
* Instantiates a new edit arena command
|
||||
*
|
||||
* @param configuration <p>The configuration to use</p>
|
||||
*/
|
||||
public EditDropperArenaCommand(DropperConfiguration configuration) {
|
||||
this.configuration = configuration;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(@NotNull CommandSender commandSender, @NotNull Command command, @NotNull String s,
|
||||
@NotNull String[] arguments) {
|
||||
StringFormatter stringFormatter = MiniGames.getInstance().getStringFormatter();
|
||||
if (!(commandSender instanceof Player player)) {
|
||||
commandSender.sendMessage("This command must be used by a player");
|
||||
stringFormatter.displayErrorMessage(commandSender, MiniGameMessage.ERROR_PLAYER_ONLY);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -28,31 +43,33 @@ public class EditArenaCommand implements CommandExecutor {
|
||||
return false;
|
||||
}
|
||||
|
||||
DropperArena specifiedArena = Dropper.getInstance().getArenaHandler().getArena(arguments[0]);
|
||||
DropperArena specifiedArena = MiniGames.getInstance().getDropperArenaHandler().getArena(arguments[0]);
|
||||
if (specifiedArena == null) {
|
||||
commandSender.sendMessage("Unable to find the specified dropper arena.");
|
||||
stringFormatter.displayErrorMessage(commandSender, MiniGameMessage.ERROR_ARENA_NOT_FOUND);
|
||||
return false;
|
||||
}
|
||||
|
||||
ArenaEditableProperty editableProperty = ArenaEditableProperty.getFromArgumentString(arguments[1]);
|
||||
DropperArenaEditableProperty editableProperty = DropperArenaEditableProperty.getFromArgumentString(arguments[1]);
|
||||
if (editableProperty == null) {
|
||||
commandSender.sendMessage("Unknown property specified.");
|
||||
stringFormatter.displayErrorMessage(commandSender, MiniGameMessage.ERROR_UNKNOWN_PROPERTY);
|
||||
return false;
|
||||
}
|
||||
|
||||
String currentValueFormat = "Current value of %s is: %s";
|
||||
|
||||
if (arguments.length < 3) {
|
||||
// Print the current value of the property
|
||||
String value = editableProperty.getCurrentValueAsString(specifiedArena);
|
||||
commandSender.sendMessage(String.format(currentValueFormat, editableProperty.getArgumentString(), value));
|
||||
stringFormatter.displaySuccessMessage(commandSender, stringFormatter.replacePlaceholders(
|
||||
MiniGameMessage.SUCCESS_CURRENT_VALUE, new String[]{"{property}", "{value}"},
|
||||
new String[]{editableProperty.getArgumentString(), value}));
|
||||
return true;
|
||||
} else {
|
||||
boolean successful = changeValue(specifiedArena, editableProperty, arguments[2], player);
|
||||
if (successful) {
|
||||
player.sendMessage(String.format("Property %s changed to: %s", editableProperty, arguments[2]));
|
||||
stringFormatter.displaySuccessMessage(player, stringFormatter.replacePlaceholder(
|
||||
MiniGameMessage.SUCCESS_PROPERTY_CHANGED, "{property}",
|
||||
editableProperty.getArgumentString()));
|
||||
} else {
|
||||
player.sendMessage("Unable to change the property. Make sure your input is valid!");
|
||||
stringFormatter.displayErrorMessage(player, MiniGameMessage.ERROR_PROPERTY_INPUT_INVALID);
|
||||
}
|
||||
return successful;
|
||||
}
|
||||
@ -67,7 +84,7 @@ public class EditArenaCommand implements CommandExecutor {
|
||||
* @param player <p>The player trying to change the value</p>
|
||||
* @return <p>True if the value was successfully changed</p>
|
||||
*/
|
||||
private boolean changeValue(@NotNull DropperArena arena, @NotNull ArenaEditableProperty property,
|
||||
private boolean changeValue(@NotNull DropperArena arena, @NotNull DropperArenaEditableProperty property,
|
||||
@NotNull String value, @NotNull Player player) {
|
||||
return switch (property) {
|
||||
case WIN_BLOCK_TYPE -> arena.setWinBlockType(parseMaterial(value));
|
||||
@ -92,7 +109,7 @@ public class EditArenaCommand implements CommandExecutor {
|
||||
try {
|
||||
velocity = Double.parseDouble(velocityString);
|
||||
} catch (NumberFormatException exception) {
|
||||
velocity = 3.92;
|
||||
velocity = configuration.getVerticalVelocity();
|
||||
}
|
||||
|
||||
// Require at least speed of 0.001, and at most 75 blocks/s
|
||||
@ -111,12 +128,7 @@ public class EditArenaCommand implements CommandExecutor {
|
||||
try {
|
||||
velocity = Float.parseFloat(velocityString);
|
||||
} catch (NumberFormatException exception) {
|
||||
velocity = 1;
|
||||
}
|
||||
|
||||
// Make sure the velocity isn't exactly 0
|
||||
if (velocity == 0) {
|
||||
velocity = 0.5f;
|
||||
velocity = configuration.getHorizontalVelocity();
|
||||
}
|
||||
|
||||
// If outside bonds, choose the most extreme value
|
@ -0,0 +1,40 @@
|
||||
package net.knarcraft.minigames.command.dropper;
|
||||
|
||||
import net.knarcraft.minigames.arena.dropper.DropperArenaEditableProperty;
|
||||
import net.knarcraft.minigames.util.TabCompleteHelper;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.TabCompleter;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static net.knarcraft.knarlib.util.TabCompletionHelper.filterMatchingContains;
|
||||
|
||||
/**
|
||||
* The tab-completer for the edit arena command
|
||||
*/
|
||||
public class EditDropperArenaTabCompleter implements TabCompleter {
|
||||
|
||||
@Override
|
||||
public @Nullable List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command,
|
||||
@NotNull String label, @NotNull String[] arguments) {
|
||||
if (arguments.length == 1) {
|
||||
return filterMatchingContains(TabCompleteHelper.getDropperArenas(), arguments[0]);
|
||||
} else if (arguments.length == 2) {
|
||||
return filterMatchingContains(TabCompleteHelper.getDropperArenaProperties(), arguments[1]);
|
||||
} else if (arguments.length == 3) {
|
||||
DropperArenaEditableProperty property = DropperArenaEditableProperty.getFromArgumentString(arguments[1]);
|
||||
if (property == null) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
return filterMatchingContains(TabCompleteHelper.getTabCompleteSuggestions(property.getPropertyType()),
|
||||
arguments[2]);
|
||||
} else {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,145 @@
|
||||
package net.knarcraft.minigames.command.dropper;
|
||||
|
||||
import net.knarcraft.knarlib.formatting.StringFormatter;
|
||||
import net.knarcraft.minigames.MiniGames;
|
||||
import net.knarcraft.minigames.arena.ArenaPlayerRegistry;
|
||||
import net.knarcraft.minigames.arena.dropper.DropperArena;
|
||||
import net.knarcraft.minigames.arena.dropper.DropperArenaGameMode;
|
||||
import net.knarcraft.minigames.arena.dropper.DropperArenaGroup;
|
||||
import net.knarcraft.minigames.arena.dropper.DropperArenaSession;
|
||||
import net.knarcraft.minigames.config.DropperConfiguration;
|
||||
import net.knarcraft.minigames.config.MiniGameMessage;
|
||||
import net.knarcraft.minigames.util.GUIHelper;
|
||||
import net.knarcraft.minigames.util.PlayerTeleporter;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* The command used to join a dropper arena
|
||||
*/
|
||||
public class JoinDropperArenaCommand implements CommandExecutor {
|
||||
|
||||
@Override
|
||||
public boolean onCommand(@NotNull CommandSender commandSender, @NotNull Command command, @NotNull String s,
|
||||
@NotNull String[] arguments) {
|
||||
StringFormatter stringFormatter = MiniGames.getInstance().getStringFormatter();
|
||||
if (!(commandSender instanceof Player player)) {
|
||||
stringFormatter.displayErrorMessage(commandSender, MiniGameMessage.ERROR_PLAYER_ONLY);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (arguments.length < 1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Disallow joining if the player is already in a mini-game arena
|
||||
if (MiniGames.getInstance().getSession(player.getUniqueId()) != null) {
|
||||
stringFormatter.displayErrorMessage(commandSender, MiniGameMessage.ERROR_ALREADY_PLAYING);
|
||||
return true;
|
||||
}
|
||||
|
||||
// Make sure the arena exists
|
||||
DropperArena specifiedArena = MiniGames.getInstance().getDropperArenaHandler().getArena(arguments[0]);
|
||||
if (specifiedArena == null) {
|
||||
stringFormatter.displayErrorMessage(commandSender, MiniGameMessage.ERROR_ARENA_NOT_FOUND);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Deny vehicles as allowing this is tricky, and will cause problems in some cases
|
||||
if (player.isInsideVehicle() || !player.getPassengers().isEmpty()) {
|
||||
stringFormatter.displayErrorMessage(commandSender, MiniGameMessage.ERROR_JOIN_IN_VEHICLE_OR_PASSENGER);
|
||||
return true;
|
||||
}
|
||||
|
||||
joinArena(specifiedArena, player, arguments);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs the actual arena joining
|
||||
*
|
||||
* @param specifiedArena <p>The arena the player wants to join</p>
|
||||
* @param player <p>The player joining the arena</p>
|
||||
* @param arguments <p>The arguments given</p>
|
||||
*/
|
||||
private void joinArena(DropperArena specifiedArena, Player player, String[] arguments) {
|
||||
// Find the specified game-mode
|
||||
DropperArenaGameMode gameMode;
|
||||
if (arguments.length > 1) {
|
||||
gameMode = DropperArenaGameMode.matchGameMode(arguments[1]);
|
||||
} else {
|
||||
gameMode = DropperArenaGameMode.DEFAULT;
|
||||
}
|
||||
|
||||
// Make sure the player has beaten the necessary levels
|
||||
DropperArenaGroup arenaGroup = MiniGames.getInstance().getDropperArenaHandler().getGroup(specifiedArena.getArenaId());
|
||||
if (arenaGroup != null && !doGroupChecks(specifiedArena, arenaGroup, gameMode, player)) {
|
||||
return;
|
||||
}
|
||||
|
||||
StringFormatter stringFormatter = MiniGames.getInstance().getStringFormatter();
|
||||
|
||||
// Make sure the player has beaten the arena once in normal mode before playing another mode
|
||||
if (MiniGames.getInstance().getDropperConfiguration().mustDoNormalModeFirst() &&
|
||||
gameMode != DropperArenaGameMode.DEFAULT &&
|
||||
specifiedArena.getData().hasNotCompleted(DropperArenaGameMode.DEFAULT, player)) {
|
||||
stringFormatter.displayErrorMessage(player, MiniGameMessage.ERROR_NORMAL_MODE_REQUIRED);
|
||||
return;
|
||||
}
|
||||
|
||||
// Register the player's session
|
||||
DropperArenaSession newSession = new DropperArenaSession(specifiedArena, player, gameMode);
|
||||
ArenaPlayerRegistry<DropperArena> playerRegistry = MiniGames.getInstance().getDropperArenaPlayerRegistry();
|
||||
playerRegistry.registerPlayer(player.getUniqueId(), newSession);
|
||||
|
||||
// Update visibility and hit-box for the player
|
||||
MiniGames.getInstance().getPlayerVisibilityManager().updateHiddenPlayers(playerRegistry, player);
|
||||
|
||||
// Try to teleport the player to the arena
|
||||
boolean teleported = PlayerTeleporter.teleportPlayer(player, specifiedArena.getSpawnLocation(), false, false);
|
||||
if (!teleported) {
|
||||
stringFormatter.displayErrorMessage(player, MiniGameMessage.ERROR_ARENA_TELEPORT_FAILED);
|
||||
newSession.triggerQuit(false, true);
|
||||
} else {
|
||||
// Update the player's state to follow the arena's rules
|
||||
newSession.getEntryState().setArenaState();
|
||||
|
||||
player.getInventory().addItem(GUIHelper.getGUIOpenItem());
|
||||
stringFormatter.displaySuccessMessage(player, MiniGameMessage.SUCCESS_ARENA_JOINED);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs necessary check for the given arena's group
|
||||
*
|
||||
* @param dropperArena <p>The arena the player is trying to join</p>
|
||||
* @param arenaGroup <p>The arena group the arena belongs to</p>
|
||||
* @param arenaGameMode <p>The game-mode the player selected</p>
|
||||
* @param player <p>The the player trying to join the arena</p>
|
||||
* @return <p>False if any checks failed</p>
|
||||
*/
|
||||
private boolean doGroupChecks(@NotNull DropperArena dropperArena, @NotNull DropperArenaGroup arenaGroup,
|
||||
@NotNull DropperArenaGameMode arenaGameMode, @NotNull Player player) {
|
||||
StringFormatter stringFormatter = MiniGames.getInstance().getStringFormatter();
|
||||
DropperConfiguration configuration = MiniGames.getInstance().getDropperConfiguration();
|
||||
// Require that players beat all arenas in the group in the normal game-mode before trying challenge modes
|
||||
if (configuration.mustDoNormalModeFirst() && arenaGameMode != DropperArenaGameMode.DEFAULT &&
|
||||
!arenaGroup.hasBeatenAll(DropperArenaGameMode.DEFAULT, player)) {
|
||||
stringFormatter.displayErrorMessage(player, MiniGameMessage.ERROR_GROUP_NORMAL_MODE_REQUIRED);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Require that the player has beaten the previous arena on the same game-mode before trying this one
|
||||
if (configuration.mustDoGroupedInSequence() &&
|
||||
arenaGroup.cannotPlay(arenaGameMode, player, dropperArena.getArenaId())) {
|
||||
stringFormatter.displayErrorMessage(player, MiniGameMessage.ERROR_PREVIOUS_ARENA_REQUIRED);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
package net.knarcraft.minigames.command.dropper;
|
||||
|
||||
import net.knarcraft.minigames.arena.dropper.DropperArenaGameMode;
|
||||
import net.knarcraft.minigames.command.JoinArenaTabCompleter;
|
||||
import net.knarcraft.minigames.util.TabCompleteHelper;
|
||||
|
||||
/**
|
||||
* The tab-completer for the join command
|
||||
*/
|
||||
public class JoinDropperArenaTabCompleter extends JoinArenaTabCompleter {
|
||||
|
||||
/**
|
||||
* Implements a new join arena tab completer
|
||||
*/
|
||||
public JoinDropperArenaTabCompleter() {
|
||||
super(TabCompleteHelper::getDropperArenas, DropperArenaGameMode.DEFAULT);
|
||||
}
|
||||
|
||||
}
|
@ -1,6 +1,8 @@
|
||||
package net.knarcraft.dropper.command;
|
||||
package net.knarcraft.minigames.command.dropper;
|
||||
|
||||
import net.knarcraft.dropper.util.TabCompleteHelper;
|
||||
import net.knarcraft.minigames.MiniGames;
|
||||
import net.knarcraft.minigames.config.MiniGameMessage;
|
||||
import net.knarcraft.minigames.util.TabCompleteHelper;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.TabExecutor;
|
||||
@ -13,15 +15,17 @@ import java.util.List;
|
||||
/**
|
||||
* A command for listing existing dropper arenas
|
||||
*/
|
||||
public class ListArenaCommand implements TabExecutor {
|
||||
public class ListDropperArenaCommand implements TabExecutor {
|
||||
|
||||
@Override
|
||||
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label,
|
||||
@NotNull String[] arguments) {
|
||||
sender.sendMessage("Dropper arenas:");
|
||||
for (String arenaName : TabCompleteHelper.getArenas()) {
|
||||
sender.sendMessage(arenaName);
|
||||
StringBuilder builder = new StringBuilder(MiniGames.getInstance().getTranslator().getTranslatedMessage(
|
||||
MiniGameMessage.SUCCESS_DROPPER_ARENAS_LIST));
|
||||
for (String arenaName : TabCompleteHelper.getDropperArenas()) {
|
||||
builder.append("\n").append(arenaName);
|
||||
}
|
||||
MiniGames.getInstance().getStringFormatter().displaySuccessMessage(sender, builder.toString());
|
||||
return true;
|
||||
}
|
||||
|
@ -0,0 +1,40 @@
|
||||
package net.knarcraft.minigames.command.dropper;
|
||||
|
||||
import net.knarcraft.knarlib.formatting.StringFormatter;
|
||||
import net.knarcraft.minigames.MiniGames;
|
||||
import net.knarcraft.minigames.arena.dropper.DropperArena;
|
||||
import net.knarcraft.minigames.config.MiniGameMessage;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* The method used for removing an existing arena
|
||||
*/
|
||||
public class RemoveDropperArenaCommand implements CommandExecutor {
|
||||
|
||||
@Override
|
||||
public boolean onCommand(@NotNull CommandSender commandSender, @NotNull Command command, @NotNull String s,
|
||||
@NotNull String[] arguments) {
|
||||
// Abort if no name was specified
|
||||
if (arguments.length < 1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
StringFormatter stringFormatter = MiniGames.getInstance().getStringFormatter();
|
||||
|
||||
// Get the specified arena
|
||||
DropperArena targetArena = MiniGames.getInstance().getDropperArenaHandler().getArena(arguments[0]);
|
||||
if (targetArena == null) {
|
||||
stringFormatter.displayErrorMessage(commandSender, MiniGameMessage.ERROR_ARENA_NOT_FOUND);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Remove the arena
|
||||
MiniGames.getInstance().getDropperArenaHandler().removeArena(targetArena);
|
||||
stringFormatter.displaySuccessMessage(commandSender, MiniGameMessage.SUCCESS_ARENA_REMOVED);
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
package net.knarcraft.dropper.command;
|
||||
package net.knarcraft.minigames.command.dropper;
|
||||
|
||||
import net.knarcraft.dropper.util.TabCompleteHelper;
|
||||
import net.knarcraft.minigames.util.TabCompleteHelper;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.TabCompleter;
|
||||
@ -10,17 +10,19 @@ import org.jetbrains.annotations.Nullable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static net.knarcraft.knarlib.util.TabCompletionHelper.filterMatchingContains;
|
||||
|
||||
/**
|
||||
* The tab-completer for the remove arena command
|
||||
*/
|
||||
public class RemoveArenaTabCompleter implements TabCompleter {
|
||||
public class RemoveDropperArenaTabCompleter implements TabCompleter {
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public List<String> onTabComplete(@NotNull CommandSender commandSender, @NotNull Command command, @NotNull String s,
|
||||
@NotNull String[] arguments) {
|
||||
if (arguments.length == 1) {
|
||||
return TabCompleteHelper.getArenas();
|
||||
return filterMatchingContains(TabCompleteHelper.getDropperArenas(), arguments[0]);
|
||||
} else {
|
||||
return new ArrayList<>();
|
||||
}
|
@ -0,0 +1,55 @@
|
||||
package net.knarcraft.minigames.command.parkour;
|
||||
|
||||
import net.knarcraft.knarlib.formatting.StringFormatter;
|
||||
import net.knarcraft.minigames.MiniGames;
|
||||
import net.knarcraft.minigames.arena.parkour.ParkourArena;
|
||||
import net.knarcraft.minigames.arena.parkour.ParkourArenaHandler;
|
||||
import net.knarcraft.minigames.config.MiniGameMessage;
|
||||
import net.knarcraft.minigames.util.StringSanitizer;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* The command for creating a new parkour arena
|
||||
*/
|
||||
public class CreateParkourArenaCommand implements CommandExecutor {
|
||||
|
||||
@Override
|
||||
public boolean onCommand(@NotNull CommandSender commandSender, @NotNull Command command, @NotNull String s,
|
||||
@NotNull String[] arguments) {
|
||||
StringFormatter stringFormatter = MiniGames.getInstance().getStringFormatter();
|
||||
if (!(commandSender instanceof Player player)) {
|
||||
stringFormatter.displayErrorMessage(commandSender, MiniGameMessage.ERROR_PLAYER_ONLY);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Abort if no name was specified
|
||||
if (arguments.length < 1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Remove known characters that are likely to cause trouble if used in an arena name
|
||||
String arenaName = StringSanitizer.removeUnwantedCharacters(arguments[0]);
|
||||
|
||||
// An arena name is required
|
||||
if (arenaName.isBlank()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
ParkourArenaHandler arenaHandler = MiniGames.getInstance().getParkourArenaHandler();
|
||||
ParkourArena existingArena = arenaHandler.getArena(arenaName);
|
||||
if (existingArena != null) {
|
||||
stringFormatter.displayErrorMessage(commandSender, MiniGameMessage.ERROR_ARENA_NAME_COLLISION);
|
||||
return false;
|
||||
}
|
||||
|
||||
ParkourArena arena = new ParkourArena(arenaName, player.getLocation(), arenaHandler);
|
||||
arenaHandler.addArena(arena);
|
||||
stringFormatter.displaySuccessMessage(commandSender, MiniGameMessage.SUCCESS_ARENA_CREATED);
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,139 @@
|
||||
package net.knarcraft.minigames.command.parkour;
|
||||
|
||||
import net.knarcraft.knarlib.formatting.StringFormatter;
|
||||
import net.knarcraft.minigames.MiniGames;
|
||||
import net.knarcraft.minigames.arena.parkour.ParkourArena;
|
||||
import net.knarcraft.minigames.arena.parkour.ParkourArenaEditableProperty;
|
||||
import net.knarcraft.minigames.config.MiniGameMessage;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* The command for editing an existing dropper arena
|
||||
*/
|
||||
public class EditParkourArenaCommand implements CommandExecutor {
|
||||
|
||||
/**
|
||||
* Instantiates a new edit arena command
|
||||
*/
|
||||
public EditParkourArenaCommand() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(@NotNull CommandSender commandSender, @NotNull Command command, @NotNull String s,
|
||||
@NotNull String[] arguments) {
|
||||
StringFormatter stringFormatter = MiniGames.getInstance().getStringFormatter();
|
||||
if (!(commandSender instanceof Player player)) {
|
||||
stringFormatter.displayErrorMessage(commandSender, MiniGameMessage.ERROR_PLAYER_ONLY);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (arguments.length < 2) {
|
||||
return false;
|
||||
}
|
||||
|
||||
ParkourArena specifiedArena = MiniGames.getInstance().getParkourArenaHandler().getArena(arguments[0]);
|
||||
if (specifiedArena == null) {
|
||||
stringFormatter.displayErrorMessage(commandSender, MiniGameMessage.ERROR_ARENA_NOT_FOUND);
|
||||
return false;
|
||||
}
|
||||
|
||||
ParkourArenaEditableProperty editableProperty = ParkourArenaEditableProperty.getFromArgumentString(arguments[1]);
|
||||
if (editableProperty == null) {
|
||||
stringFormatter.displayErrorMessage(commandSender, MiniGameMessage.ERROR_UNKNOWN_PROPERTY);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (arguments.length < 3) {
|
||||
// Print the current value of the property
|
||||
String value = editableProperty.getCurrentValueAsString(specifiedArena);
|
||||
stringFormatter.displaySuccessMessage(commandSender, stringFormatter.replacePlaceholders(
|
||||
MiniGameMessage.SUCCESS_CURRENT_VALUE, new String[]{"{property}", "{value}"},
|
||||
new String[]{editableProperty.getArgumentString(), value}));
|
||||
return true;
|
||||
} else {
|
||||
boolean successful;
|
||||
try {
|
||||
successful = changeValue(specifiedArena, editableProperty, arguments[2], player);
|
||||
} catch (NumberFormatException exception) {
|
||||
successful = false;
|
||||
}
|
||||
if (successful) {
|
||||
stringFormatter.displaySuccessMessage(player, stringFormatter.replacePlaceholder(
|
||||
MiniGameMessage.SUCCESS_PROPERTY_CHANGED, "{property}",
|
||||
editableProperty.getArgumentString()));
|
||||
} else {
|
||||
stringFormatter.displayErrorMessage(player, MiniGameMessage.ERROR_PROPERTY_INPUT_INVALID);
|
||||
}
|
||||
return successful;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Changes the given property to the given value
|
||||
*
|
||||
* @param arena <p>The arena to change the property for</p>
|
||||
* @param property <p>The property to change</p>
|
||||
* @param value <p>The new value of the property</p>
|
||||
* @param player <p>The player trying to change the value</p>
|
||||
* @return <p>True if the value was successfully changed</p>
|
||||
* @throws NumberFormatException <p>If unable to parse a given numeric value</p>
|
||||
*/
|
||||
private boolean changeValue(@NotNull ParkourArena arena, @NotNull ParkourArenaEditableProperty property,
|
||||
@NotNull String value, @NotNull Player player) throws NumberFormatException {
|
||||
return switch (property) {
|
||||
case WIN_BLOCK_TYPE -> arena.setWinBlockType(parseMaterial(value));
|
||||
case SPAWN_LOCATION -> arena.setSpawnLocation(parseLocation(player, value));
|
||||
case NAME -> arena.setName(value);
|
||||
case EXIT_LOCATION -> arena.setExitLocation(parseLocation(player, value));
|
||||
case WIN_LOCATION -> arena.setWinLocation(parseLocation(player, value));
|
||||
case CHECKPOINT_ADD -> arena.addCheckpoint(parseLocation(player, value));
|
||||
case CHECKPOINT_CLEAR -> arena.clearCheckpoints();
|
||||
case KILL_PLANE_BLOCKS -> arena.setKillPlaneBlocks(new HashSet<>(List.of(value.split(","))));
|
||||
case OBSTACLE_BLOCKS -> arena.setObstacleBlocks(new HashSet<>(List.of(value.split(","))));
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses the given location string
|
||||
*
|
||||
* @param player <p>The player changing a location</p>
|
||||
* @param locationString <p>The location string to parse</p>
|
||||
* @return <p>The parsed location, or the player's location if not parse-able</p>
|
||||
*/
|
||||
private @NotNull Location parseLocation(Player player, String locationString) {
|
||||
if ((locationString.trim() + ",").matches("([0-9]+.?[0-9]*,){3}")) {
|
||||
String[] parts = locationString.split(",");
|
||||
Location newLocation = player.getLocation().clone();
|
||||
newLocation.setX(Double.parseDouble(parts[0].trim()));
|
||||
newLocation.setY(Double.parseDouble(parts[1].trim()));
|
||||
newLocation.setZ(Double.parseDouble(parts[2].trim()));
|
||||
return newLocation;
|
||||
} else {
|
||||
return player.getLocation().clone();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses the given material name
|
||||
*
|
||||
* @param materialName <p>The material name to parse</p>
|
||||
* @return <p>The parsed material, or AIR if not valid</p>
|
||||
*/
|
||||
private @NotNull Material parseMaterial(String materialName) {
|
||||
Material material = Material.matchMaterial(materialName);
|
||||
if (material == null) {
|
||||
material = Material.AIR;
|
||||
}
|
||||
return material;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,40 @@
|
||||
package net.knarcraft.minigames.command.parkour;
|
||||
|
||||
import net.knarcraft.minigames.arena.parkour.ParkourArenaEditableProperty;
|
||||
import net.knarcraft.minigames.util.TabCompleteHelper;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.TabCompleter;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static net.knarcraft.knarlib.util.TabCompletionHelper.filterMatchingContains;
|
||||
|
||||
/**
|
||||
* The tab-completer for the edit arena command
|
||||
*/
|
||||
public class EditParkourArenaTabCompleter implements TabCompleter {
|
||||
|
||||
@Override
|
||||
public @Nullable List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command,
|
||||
@NotNull String label, @NotNull String[] arguments) {
|
||||
if (arguments.length == 1) {
|
||||
return filterMatchingContains(TabCompleteHelper.getParkourArenas(), arguments[0]);
|
||||
} else if (arguments.length == 2) {
|
||||
return filterMatchingContains(TabCompleteHelper.getParkourArenaProperties(), arguments[1]);
|
||||
} else if (arguments.length == 3) {
|
||||
ParkourArenaEditableProperty property = ParkourArenaEditableProperty.getFromArgumentString(arguments[1]);
|
||||
if (property == null) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
return filterMatchingContains(TabCompleteHelper.getTabCompleteSuggestions(property.getPropertyType()),
|
||||
arguments[2]);
|
||||
} else {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,138 @@
|
||||
package net.knarcraft.minigames.command.parkour;
|
||||
|
||||
import net.knarcraft.knarlib.formatting.StringFormatter;
|
||||
import net.knarcraft.minigames.MiniGames;
|
||||
import net.knarcraft.minigames.arena.ArenaPlayerRegistry;
|
||||
import net.knarcraft.minigames.arena.parkour.ParkourArena;
|
||||
import net.knarcraft.minigames.arena.parkour.ParkourArenaGameMode;
|
||||
import net.knarcraft.minigames.arena.parkour.ParkourArenaGroup;
|
||||
import net.knarcraft.minigames.arena.parkour.ParkourArenaSession;
|
||||
import net.knarcraft.minigames.config.MiniGameMessage;
|
||||
import net.knarcraft.minigames.config.ParkourConfiguration;
|
||||
import net.knarcraft.minigames.util.GUIHelper;
|
||||
import net.knarcraft.minigames.util.PlayerTeleporter;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* The command used to join a parkour arena
|
||||
*/
|
||||
public class JoinParkourArenaCommand implements CommandExecutor {
|
||||
|
||||
@Override
|
||||
public boolean onCommand(@NotNull CommandSender commandSender, @NotNull Command command, @NotNull String s,
|
||||
@NotNull String[] arguments) {
|
||||
StringFormatter stringFormatter = MiniGames.getInstance().getStringFormatter();
|
||||
if (!(commandSender instanceof Player player)) {
|
||||
stringFormatter.displayErrorMessage(commandSender, MiniGameMessage.ERROR_PLAYER_ONLY);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (arguments.length < 1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Disallow joining if the player is already in a mini-game arena
|
||||
if (MiniGames.getInstance().getSession(player.getUniqueId()) != null) {
|
||||
stringFormatter.displayErrorMessage(commandSender, MiniGameMessage.ERROR_ALREADY_PLAYING);
|
||||
return true;
|
||||
}
|
||||
|
||||
// Make sure the arena exists
|
||||
ParkourArena specifiedArena = MiniGames.getInstance().getParkourArenaHandler().getArena(arguments[0]);
|
||||
if (specifiedArena == null) {
|
||||
stringFormatter.displayErrorMessage(commandSender, MiniGameMessage.ERROR_ARENA_NOT_FOUND);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Deny vehicles as allowing this is tricky, and will cause problems in some cases
|
||||
if (player.isInsideVehicle() || !player.getPassengers().isEmpty()) {
|
||||
stringFormatter.displayErrorMessage(commandSender, MiniGameMessage.ERROR_JOIN_IN_VEHICLE_OR_PASSENGER);
|
||||
return true;
|
||||
}
|
||||
|
||||
joinArena(specifiedArena, player, arguments);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs the actual arena joining
|
||||
*
|
||||
* @param specifiedArena <p>The arena the player wants to join</p>
|
||||
* @param player <p>The player joining the arena</p>
|
||||
* @param arguments <p>The arguments given</p>
|
||||
*/
|
||||
private void joinArena(ParkourArena specifiedArena, Player player, String[] arguments) {
|
||||
// Find the specified game-mode
|
||||
ParkourArenaGameMode gameMode;
|
||||
if (arguments.length > 1) {
|
||||
gameMode = ParkourArenaGameMode.matchGamemode(arguments[1]);
|
||||
} else {
|
||||
gameMode = ParkourArenaGameMode.DEFAULT;
|
||||
}
|
||||
|
||||
// Don't allow joining the hardcore game-mode if there are no checkpoints to skip
|
||||
if (specifiedArena.hasNoCheckpoints() && gameMode == ParkourArenaGameMode.HARDCORE) {
|
||||
MiniGames.getInstance().getStringFormatter().displayErrorMessage(player,
|
||||
MiniGameMessage.ERROR_HARDCORE_NO_CHECKPOINTS);
|
||||
return;
|
||||
}
|
||||
|
||||
// Make sure the player has beaten the necessary levels
|
||||
ParkourArenaGroup arenaGroup = MiniGames.getInstance().getParkourArenaHandler().getGroup(specifiedArena.getArenaId());
|
||||
if (arenaGroup != null && !doGroupChecks(specifiedArena, arenaGroup, gameMode, player)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Register the player's session
|
||||
ParkourArenaSession newSession = new ParkourArenaSession(specifiedArena, player, gameMode);
|
||||
ArenaPlayerRegistry<ParkourArena> playerRegistry = MiniGames.getInstance().getParkourArenaPlayerRegistry();
|
||||
playerRegistry.registerPlayer(player.getUniqueId(), newSession);
|
||||
|
||||
// Update visibility and hit-box for the player
|
||||
MiniGames.getInstance().getPlayerVisibilityManager().updateHiddenPlayers(playerRegistry, player);
|
||||
|
||||
// Try to teleport the player to the arena
|
||||
boolean teleported = PlayerTeleporter.teleportPlayer(player, specifiedArena.getSpawnLocation(), false, false);
|
||||
if (!teleported) {
|
||||
MiniGames.getInstance().getStringFormatter().displayErrorMessage(player,
|
||||
MiniGameMessage.ERROR_ARENA_TELEPORT_FAILED);
|
||||
newSession.triggerQuit(false, true);
|
||||
} else {
|
||||
// Update the player's state to follow the arena's rules
|
||||
newSession.getEntryState().setArenaState();
|
||||
|
||||
player.getInventory().addItem(GUIHelper.getGUIOpenItem());
|
||||
MiniGames.getInstance().getStringFormatter().displaySuccessMessage(player,
|
||||
MiniGameMessage.SUCCESS_ARENA_JOINED);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs necessary check for the given arena's group
|
||||
*
|
||||
* @param parkourArena <p>The arena the player is trying to join</p>
|
||||
* @param arenaGroup <p>The arena group the arena belongs to</p>
|
||||
* @param arenaGameMode <p>The game-mode the player selected</p>
|
||||
* @param player <p>The the player trying to join the arena</p>
|
||||
* @return <p>False if any checks failed</p>
|
||||
*/
|
||||
private boolean doGroupChecks(@NotNull ParkourArena parkourArena, @NotNull ParkourArenaGroup arenaGroup,
|
||||
@NotNull ParkourArenaGameMode arenaGameMode, @NotNull Player player) {
|
||||
ParkourConfiguration configuration = MiniGames.getInstance().getParkourConfiguration();
|
||||
|
||||
// Require that the player has beaten the previous arena on the same game-mode before trying this one
|
||||
if (configuration.mustDoGroupedInSequence() &&
|
||||
arenaGroup.cannotPlay(arenaGameMode, player, parkourArena.getArenaId())) {
|
||||
MiniGames.getInstance().getStringFormatter().displayErrorMessage(player,
|
||||
MiniGameMessage.ERROR_PREVIOUS_ARENA_REQUIRED);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
package net.knarcraft.minigames.command.parkour;
|
||||
|
||||
import net.knarcraft.minigames.arena.parkour.ParkourArenaGameMode;
|
||||
import net.knarcraft.minigames.command.JoinArenaTabCompleter;
|
||||
import net.knarcraft.minigames.util.TabCompleteHelper;
|
||||
|
||||
/**
|
||||
* The tab-completer for the join command
|
||||
*/
|
||||
public class JoinParkourArenaTabCompleter extends JoinArenaTabCompleter {
|
||||
|
||||
/**
|
||||
* Implements a new join arena tab completer
|
||||
*/
|
||||
public JoinParkourArenaTabCompleter() {
|
||||
super(TabCompleteHelper::getParkourArenas, ParkourArenaGameMode.DEFAULT);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,39 @@
|
||||
package net.knarcraft.minigames.command.parkour;
|
||||
|
||||
import net.knarcraft.minigames.MiniGames;
|
||||
import net.knarcraft.minigames.config.MiniGameMessage;
|
||||
import net.knarcraft.minigames.util.TabCompleteHelper;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.TabExecutor;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* A command for listing existing parkour arenas
|
||||
*/
|
||||
public class ListParkourArenaCommand implements TabExecutor {
|
||||
|
||||
@Override
|
||||
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label,
|
||||
@NotNull String[] arguments) {
|
||||
StringBuilder builder = new StringBuilder(MiniGames.getInstance().getTranslator().getTranslatedMessage(
|
||||
MiniGameMessage.SUCCESS_PARKOUR_ARENAS_LIST));
|
||||
for (String arenaName : TabCompleteHelper.getParkourArenas()) {
|
||||
builder.append("\n").append(arenaName);
|
||||
}
|
||||
MiniGames.getInstance().getStringFormatter().displaySuccessMessage(sender, builder.toString());
|
||||
return true;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public List<String> onTabComplete(@NotNull CommandSender commandSender, @NotNull Command command, @NotNull String s,
|
||||
@NotNull String[] arguments) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,101 @@
|
||||
package net.knarcraft.minigames.command.parkour;
|
||||
|
||||
import net.knarcraft.knarlib.formatting.StringFormatter;
|
||||
import net.knarcraft.minigames.MiniGames;
|
||||
import net.knarcraft.minigames.arena.parkour.ParkourArena;
|
||||
import net.knarcraft.minigames.arena.parkour.ParkourArenaGroup;
|
||||
import net.knarcraft.minigames.arena.parkour.ParkourArenaHandler;
|
||||
import net.knarcraft.minigames.config.MiniGameMessage;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.TabExecutor;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
import static net.knarcraft.knarlib.util.TabCompletionHelper.filterMatchingContains;
|
||||
|
||||
/**
|
||||
* The command for listing groups and the stages within
|
||||
*/
|
||||
public class ParkourGroupListCommand implements TabExecutor {
|
||||
|
||||
@Override
|
||||
public boolean onCommand(@NotNull CommandSender commandSender, @NotNull Command command, @NotNull String s,
|
||||
@NotNull String[] arguments) {
|
||||
ParkourArenaHandler arenaHandler = MiniGames.getInstance().getParkourArenaHandler();
|
||||
if (arguments.length == 0) {
|
||||
displayExistingGroups(arenaHandler, commandSender);
|
||||
return true;
|
||||
} else if (arguments.length == 1) {
|
||||
return displayOrderedArenaNames(arenaHandler, commandSender, arguments[0]);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays all currently existing parkour arena groups
|
||||
*
|
||||
* @param arenaHandler <p>The arena handler to get groups from</p>
|
||||
* @param sender <p>The command sender to display the groups to</p>
|
||||
*/
|
||||
private void displayExistingGroups(@NotNull ParkourArenaHandler arenaHandler, @NotNull CommandSender sender) {
|
||||
StringBuilder builder = new StringBuilder("Parkour arena groups:").append("\n");
|
||||
arenaHandler.getAllGroups().stream().sorted().forEachOrdered((group) ->
|
||||
builder.append(group.getGroupName()).append("\n"));
|
||||
sender.sendMessage(builder.toString());
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays the ordered stages in a specified group to the specified command sender
|
||||
*
|
||||
* @param arenaHandler <p>The arena handler to get groups from</p>
|
||||
* @param sender <p>The command sender to display the stages to</p>
|
||||
* @param groupName <p>The name of the group to display stages for</p>
|
||||
* @return <p>True if the stages were successfully displayed</p>
|
||||
*/
|
||||
private boolean displayOrderedArenaNames(@NotNull ParkourArenaHandler arenaHandler, @NotNull CommandSender sender,
|
||||
@NotNull String groupName) {
|
||||
StringFormatter stringFormatter = MiniGames.getInstance().getStringFormatter();
|
||||
ParkourArenaGroup arenaGroup = arenaHandler.getGroup(groupName);
|
||||
if (arenaGroup == null) {
|
||||
stringFormatter.displayErrorMessage(sender, MiniGameMessage.ERROR_GROUP_NOT_FOUND);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Send a list of all stages (arenas in the group)
|
||||
StringBuilder builder = new StringBuilder(stringFormatter.replacePlaceholder(
|
||||
MiniGameMessage.SUCCESS_GROUP_STAGES, "{group}", groupName));
|
||||
int counter = 1;
|
||||
for (UUID arenaId : arenaGroup.getArenas()) {
|
||||
ParkourArena arena = arenaHandler.getArena(arenaId);
|
||||
if (arena != null) {
|
||||
builder.append("\n").append(counter++).append(". ").append(arena.getArenaName());
|
||||
}
|
||||
}
|
||||
stringFormatter.displaySuccessMessage(sender, builder.toString());
|
||||
return true;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public List<String> onTabComplete(@NotNull CommandSender commandSender, @NotNull Command command, @NotNull String s,
|
||||
@NotNull String[] arguments) {
|
||||
if (arguments.length == 1) {
|
||||
List<String> groupNames = new ArrayList<>();
|
||||
Set<ParkourArenaGroup> arenaGroups = MiniGames.getInstance().getParkourArenaHandler().getAllGroups();
|
||||
for (ParkourArenaGroup group : arenaGroups) {
|
||||
groupNames.add(group.getGroupName());
|
||||
}
|
||||
return filterMatchingContains(groupNames, arguments[0]);
|
||||
} else {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,84 @@
|
||||
package net.knarcraft.minigames.command.parkour;
|
||||
|
||||
import net.knarcraft.knarlib.formatting.StringFormatter;
|
||||
import net.knarcraft.minigames.MiniGames;
|
||||
import net.knarcraft.minigames.arena.parkour.ParkourArena;
|
||||
import net.knarcraft.minigames.arena.parkour.ParkourArenaGroup;
|
||||
import net.knarcraft.minigames.arena.parkour.ParkourArenaHandler;
|
||||
import net.knarcraft.minigames.config.MiniGameMessage;
|
||||
import net.knarcraft.minigames.util.StringSanitizer;
|
||||
import net.knarcraft.minigames.util.TabCompleteHelper;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.TabExecutor;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static net.knarcraft.knarlib.util.TabCompletionHelper.filterMatchingContains;
|
||||
|
||||
/**
|
||||
* The command for setting the group of an arena
|
||||
*/
|
||||
public class ParkourGroupSetCommand implements TabExecutor {
|
||||
|
||||
@Override
|
||||
public boolean onCommand(@NotNull CommandSender commandSender, @NotNull Command command, @NotNull String s,
|
||||
@NotNull String[] arguments) {
|
||||
if (arguments.length < 2) {
|
||||
return false;
|
||||
}
|
||||
|
||||
StringFormatter stringFormatter = MiniGames.getInstance().getStringFormatter();
|
||||
ParkourArenaHandler arenaHandler = MiniGames.getInstance().getParkourArenaHandler();
|
||||
|
||||
ParkourArena specifiedArena = arenaHandler.getArena(arguments[0]);
|
||||
if (specifiedArena == null) {
|
||||
stringFormatter.displayErrorMessage(commandSender, MiniGameMessage.ERROR_ARENA_NOT_FOUND);
|
||||
return false;
|
||||
}
|
||||
|
||||
String groupName = StringSanitizer.removeUnwantedCharacters(arguments[1]);
|
||||
|
||||
if (groupName.isBlank()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
ParkourArenaGroup arenaGroup;
|
||||
if (groupName.equalsIgnoreCase("null") || groupName.equalsIgnoreCase("none")) {
|
||||
arenaGroup = null;
|
||||
} else {
|
||||
arenaGroup = arenaHandler.getGroup(groupName);
|
||||
if (arenaGroup == null) {
|
||||
arenaGroup = new ParkourArenaGroup(groupName);
|
||||
}
|
||||
}
|
||||
|
||||
arenaHandler.setGroup(specifiedArena.getArenaId(), arenaGroup);
|
||||
|
||||
stringFormatter.displaySuccessMessage(commandSender, MiniGameMessage.SUCCESS_ARENA_GROUP_UPDATED);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public List<String> onTabComplete(@NotNull CommandSender commandSender, @NotNull Command command, @NotNull String s,
|
||||
@NotNull String[] arguments) {
|
||||
if (arguments.length == 1) {
|
||||
return filterMatchingContains(TabCompleteHelper.getParkourArenas(), arguments[0]);
|
||||
} else if (arguments.length == 2) {
|
||||
List<String> possibleValues = new ArrayList<>();
|
||||
possibleValues.add("none");
|
||||
possibleValues.add("GroupName");
|
||||
for (ParkourArenaGroup group : MiniGames.getInstance().getParkourArenaHandler().getAllGroups()) {
|
||||
possibleValues.add(group.getGroupName());
|
||||
}
|
||||
return filterMatchingContains(possibleValues, arguments[1]);
|
||||
} else {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,107 @@
|
||||
package net.knarcraft.minigames.command.parkour;
|
||||
|
||||
import net.knarcraft.knarlib.formatting.StringFormatter;
|
||||
import net.knarcraft.minigames.MiniGames;
|
||||
import net.knarcraft.minigames.arena.parkour.ParkourArena;
|
||||
import net.knarcraft.minigames.arena.parkour.ParkourArenaGroup;
|
||||
import net.knarcraft.minigames.arena.parkour.ParkourArenaHandler;
|
||||
import net.knarcraft.minigames.config.MiniGameMessage;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.TabExecutor;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import static net.knarcraft.knarlib.util.TabCompletionHelper.filterMatchingContains;
|
||||
|
||||
/**
|
||||
* The command for swapping the order of two arenas in a group
|
||||
*/
|
||||
public class ParkourGroupSwapCommand implements TabExecutor {
|
||||
|
||||
@Override
|
||||
public boolean onCommand(@NotNull CommandSender commandSender, @NotNull Command command, @NotNull String s,
|
||||
@NotNull String[] arguments) {
|
||||
if (arguments.length < 2) {
|
||||
return false;
|
||||
}
|
||||
|
||||
ParkourArenaHandler arenaHandler = MiniGames.getInstance().getParkourArenaHandler();
|
||||
StringFormatter stringFormatter = MiniGames.getInstance().getStringFormatter();
|
||||
|
||||
ParkourArena arena1 = arenaHandler.getArena(arguments[0]);
|
||||
if (arena1 == null) {
|
||||
stringFormatter.displayErrorMessage(commandSender, MiniGameMessage.ERROR_ARENA_1_NOT_FOUND);
|
||||
return false;
|
||||
}
|
||||
|
||||
ParkourArena arena2 = arenaHandler.getArena(arguments[1]);
|
||||
if (arena2 == null) {
|
||||
stringFormatter.displayErrorMessage(commandSender, MiniGameMessage.ERROR_ARENA_2_NOT_FOUND);
|
||||
return false;
|
||||
}
|
||||
|
||||
ParkourArenaGroup arena1Group = arenaHandler.getGroup(arena1.getArenaId());
|
||||
ParkourArenaGroup arena2Group = arenaHandler.getGroup(arena2.getArenaId());
|
||||
if (arena1Group == null || !arena1Group.equals(arena2Group)) {
|
||||
stringFormatter.displayErrorMessage(commandSender, MiniGameMessage.ERROR_SWAP_DIFFERENT_GROUPS);
|
||||
return false;
|
||||
}
|
||||
|
||||
arena1Group.swapArenas(arena1Group.getArenas().indexOf(arena1.getArenaId()),
|
||||
arena1Group.getArenas().indexOf(arena2.getArenaId()));
|
||||
stringFormatter.displaySuccessMessage(commandSender, MiniGameMessage.SUCCESS_ARENAS_SWAPPED);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public List<String> onTabComplete(@NotNull CommandSender commandSender, @NotNull Command command, @NotNull String s,
|
||||
@NotNull String[] arguments) {
|
||||
ParkourArenaHandler arenaHandler = MiniGames.getInstance().getParkourArenaHandler();
|
||||
if (arguments.length == 1) {
|
||||
List<String> arenaNames = new ArrayList<>();
|
||||
for (ParkourArena parkourArena : arenaHandler.getArenasInAGroup()) {
|
||||
arenaNames.add(parkourArena.getArenaName());
|
||||
}
|
||||
return filterMatchingContains(arenaNames, arguments[0]);
|
||||
} else if (arguments.length == 2) {
|
||||
return filterMatchingContains(getArenaNamesInSameGroup(arguments[0]), arguments[1]);
|
||||
} else {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the names of all arenas in the same group as the specified arena
|
||||
*
|
||||
* @param arenaName <p>The name of the specified arena</p>
|
||||
* @return <p>The names of the arenas in the same group</p>
|
||||
*/
|
||||
private List<String> getArenaNamesInSameGroup(String arenaName) {
|
||||
ParkourArenaHandler arenaHandler = MiniGames.getInstance().getParkourArenaHandler();
|
||||
ParkourArena arena1 = arenaHandler.getArena(arenaName);
|
||||
if (arena1 == null) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
// Only display other arenas in the selected group
|
||||
List<String> arenaNames = new ArrayList<>();
|
||||
ParkourArenaGroup group = arenaHandler.getGroup(arena1.getArenaId());
|
||||
if (group == null) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
for (UUID arenaId : group.getArenas()) {
|
||||
ParkourArena arena = arenaHandler.getArena(arenaId);
|
||||
if (arena != null && arena.getArenaId() != arena1.getArenaId()) {
|
||||
arenaNames.add(arena.getArenaName());
|
||||
}
|
||||
}
|
||||
return arenaNames;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,40 @@
|
||||
package net.knarcraft.minigames.command.parkour;
|
||||
|
||||
import net.knarcraft.knarlib.formatting.StringFormatter;
|
||||
import net.knarcraft.minigames.MiniGames;
|
||||
import net.knarcraft.minigames.arena.parkour.ParkourArena;
|
||||
import net.knarcraft.minigames.config.MiniGameMessage;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* The method used for removing an existing arena
|
||||
*/
|
||||
public class RemoveParkourArenaCommand implements CommandExecutor {
|
||||
|
||||
@Override
|
||||
public boolean onCommand(@NotNull CommandSender commandSender, @NotNull Command command, @NotNull String s,
|
||||
@NotNull String[] arguments) {
|
||||
// Abort if no name was specified
|
||||
if (arguments.length < 1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
StringFormatter stringFormatter = MiniGames.getInstance().getStringFormatter();
|
||||
|
||||
// Get the specified arena
|
||||
ParkourArena targetArena = MiniGames.getInstance().getParkourArenaHandler().getArena(arguments[0]);
|
||||
if (targetArena == null) {
|
||||
stringFormatter.displayErrorMessage(commandSender, MiniGameMessage.ERROR_ARENA_NOT_FOUND);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Remove the arena
|
||||
MiniGames.getInstance().getParkourArenaHandler().removeArena(targetArena);
|
||||
stringFormatter.displaySuccessMessage(commandSender, MiniGameMessage.SUCCESS_ARENA_REMOVED);
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
package net.knarcraft.minigames.command.parkour;
|
||||
|
||||
import net.knarcraft.minigames.util.TabCompleteHelper;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.TabCompleter;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static net.knarcraft.knarlib.util.TabCompletionHelper.filterMatchingContains;
|
||||
|
||||
/**
|
||||
* The tab-completer for the remove arena command
|
||||
*/
|
||||
public class RemoveParkourArenaTabCompleter implements TabCompleter {
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public List<String> onTabComplete(@NotNull CommandSender commandSender, @NotNull Command command, @NotNull String s,
|
||||
@NotNull String[] arguments) {
|
||||
if (arguments.length == 1) {
|
||||
return filterMatchingContains(TabCompleteHelper.getParkourArenas(), arguments[0]);
|
||||
} else {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,164 @@
|
||||
package net.knarcraft.minigames.config;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* The configuration keeping track of dropper settings
|
||||
*/
|
||||
public class DropperConfiguration extends MiniGameConfiguration {
|
||||
|
||||
private final static String rootNode = "dropper.";
|
||||
|
||||
private double verticalVelocity;
|
||||
private float horizontalVelocity;
|
||||
private int randomlyInvertedTimer;
|
||||
private boolean mustDoGroupedInSequence;
|
||||
private boolean ignoreRecordsUntilGroupBeatenOnce;
|
||||
private boolean mustDoNormalModeFirst;
|
||||
private boolean blockSneaking;
|
||||
private boolean blockSprinting;
|
||||
private Set<Material> blockWhitelist;
|
||||
|
||||
/**
|
||||
* Instantiates a new dropper configuration
|
||||
*
|
||||
* @param configuration <p>The YAML configuration to use internally</p>
|
||||
*/
|
||||
public DropperConfiguration(FileConfiguration configuration) {
|
||||
super(configuration);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the default vertical velocity
|
||||
*
|
||||
* @return <p>The default vertical velocity</p>
|
||||
*/
|
||||
public double getVerticalVelocity() {
|
||||
return this.verticalVelocity;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the default horizontal velocity
|
||||
*
|
||||
* @return <p>The default horizontal velocity</p>
|
||||
*/
|
||||
public float getHorizontalVelocity() {
|
||||
return this.horizontalVelocity;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the number of seconds before the randomly inverted game-mode toggles
|
||||
*
|
||||
* @return <p>Number of seconds before the inversion toggles</p>
|
||||
*/
|
||||
public int getRandomlyInvertedTimer() {
|
||||
return this.randomlyInvertedTimer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets whether grouped arenas must be done in the set sequence
|
||||
*
|
||||
* @return <p>Whether grouped arenas must be done in sequence</p>
|
||||
*/
|
||||
public boolean mustDoGroupedInSequence() {
|
||||
return this.mustDoGroupedInSequence;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets whether the normal/default mode must be beaten before playing another game-mode
|
||||
*
|
||||
* @return <p>Whether the normal game-mode must be beaten first</p>
|
||||
*/
|
||||
public boolean mustDoNormalModeFirst() {
|
||||
return this.mustDoNormalModeFirst;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the types of block which should not trigger a loss
|
||||
*
|
||||
* @return <p>The materials that should not trigger a loss</p>
|
||||
*/
|
||||
public Set<Material> getBlockWhitelist() {
|
||||
return new HashSet<>(this.blockWhitelist);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets whether records should be discarded, unless the player has already beaten all arenas in the group
|
||||
*
|
||||
* @return <p>Whether to ignore records on the first play-through</p>
|
||||
*/
|
||||
public boolean ignoreRecordsUntilGroupBeatenOnce() {
|
||||
return this.ignoreRecordsUntilGroupBeatenOnce;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets whether players trying to sneak while in a dropper arena to increase their downwards speed should be blocked
|
||||
*
|
||||
* @return <p>Whether to block sneak to speed up</p>
|
||||
*/
|
||||
public boolean blockSneaking() {
|
||||
return blockSneaking;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets whether players trying to sprint to improve their horizontal speed while in a dropper arena should be blocked
|
||||
*
|
||||
* @return <p>Whether to block sprint to speed up</p>
|
||||
*/
|
||||
public boolean blockSprinting() {
|
||||
return this.blockSprinting;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void load() {
|
||||
this.verticalVelocity = configuration.getDouble(rootNode + "verticalVelocity", 1.0);
|
||||
this.horizontalVelocity = (float) configuration.getDouble(rootNode + "horizontalVelocity", 1.0);
|
||||
this.randomlyInvertedTimer = configuration.getInt(rootNode + "randomlyInvertedTimer", 7);
|
||||
this.mustDoGroupedInSequence = configuration.getBoolean(rootNode + "mustDoGroupedInSequence", true);
|
||||
this.ignoreRecordsUntilGroupBeatenOnce = configuration.getBoolean(rootNode + "ignoreRecordsUntilGroupBeatenOnce", false);
|
||||
this.mustDoNormalModeFirst = configuration.getBoolean(rootNode + "mustDoNormalModeFirst", true);
|
||||
this.blockSprinting = configuration.getBoolean(rootNode + "blockSprinting", true);
|
||||
this.blockSneaking = configuration.getBoolean(rootNode + "blockSneaking", true);
|
||||
this.blockWhitelist = loadMaterialList(rootNode + "blockWhitelist");
|
||||
sanitizeValues();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sanitizes configuration values to ensure they are within expected bounds
|
||||
*/
|
||||
private void sanitizeValues() {
|
||||
if (this.horizontalVelocity > 1 || this.horizontalVelocity <= 0) {
|
||||
this.horizontalVelocity = 1;
|
||||
}
|
||||
|
||||
if (this.verticalVelocity <= 0 || this.verticalVelocity > 75) {
|
||||
this.verticalVelocity = 1;
|
||||
}
|
||||
|
||||
if (this.randomlyInvertedTimer <= 0 || this.randomlyInvertedTimer > 3600) {
|
||||
this.randomlyInvertedTimer = 7;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder builder = new StringBuilder(
|
||||
"Current configuration:" +
|
||||
"\n" + "Vertical velocity: " + verticalVelocity +
|
||||
"\n" + "Horizontal velocity: " + horizontalVelocity +
|
||||
"\n" + "Randomly inverted timer: " + randomlyInvertedTimer +
|
||||
"\n" + "Must do groups in sequence: " + mustDoGroupedInSequence +
|
||||
"\n" + "Ignore records until group beaten once: " + ignoreRecordsUntilGroupBeatenOnce +
|
||||
"\n" + "Must do normal mode first: " + mustDoNormalModeFirst +
|
||||
"\n" + "Block whitelist: ");
|
||||
for (Material material : blockWhitelist) {
|
||||
builder.append("\n - ").append(material.name());
|
||||
}
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,53 @@
|
||||
package net.knarcraft.minigames.config;
|
||||
|
||||
import net.knarcraft.knarlib.util.MaterialHelper;
|
||||
import net.knarcraft.minigames.MiniGames;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* A configuration for a mini-game
|
||||
*/
|
||||
public abstract class MiniGameConfiguration {
|
||||
|
||||
protected FileConfiguration configuration;
|
||||
|
||||
/**
|
||||
* Instantiates a new mini-game configuration
|
||||
*
|
||||
* @param configuration <p>The YAML configuration to use internally</p>
|
||||
*/
|
||||
public MiniGameConfiguration(@NotNull FileConfiguration configuration) {
|
||||
this.configuration = configuration;
|
||||
this.load();
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads all configuration values from disk
|
||||
*
|
||||
* @param configuration <p>The configuration to load</p>
|
||||
*/
|
||||
public void load(FileConfiguration configuration) {
|
||||
this.configuration = configuration;
|
||||
this.load();
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads all configuration values from disk, using the current file configuration
|
||||
*/
|
||||
protected abstract void load();
|
||||
|
||||
/**
|
||||
* Loads the materials specified in the block whitelist
|
||||
*/
|
||||
public @NotNull Set<Material> loadMaterialList(@NotNull String path) {
|
||||
List<?> blockWhitelist = configuration.getList(path, new ArrayList<>());
|
||||
return MaterialHelper.loadMaterialList(blockWhitelist, "+", MiniGames.getInstance().getLogger());
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,303 @@
|
||||
package net.knarcraft.minigames.config;
|
||||
|
||||
import net.knarcraft.knarlib.formatting.TranslatableMessage;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* A message which ca be displayed to the user
|
||||
*/
|
||||
public enum MiniGameMessage implements TranslatableMessage {
|
||||
|
||||
/* ************** *
|
||||
* Error messages *
|
||||
* ************** */
|
||||
|
||||
/**
|
||||
* The message displayed if saving arena groups fails
|
||||
*/
|
||||
ERROR_CANNOT_SAVE_ARENA_GROUPS,
|
||||
|
||||
/**
|
||||
* The message displayed if an un-parse-able message is given by a user
|
||||
*/
|
||||
ERROR_MATERIAL_NOT_PARSE_ABLE,
|
||||
|
||||
/**
|
||||
* The message displayed if a player tries to be teleported to/from an arena with a passenger
|
||||
*/
|
||||
ERROR_TELEPORT_WITH_PASSENGER,
|
||||
|
||||
/**
|
||||
* The message displayed if a player tries to be teleported to/from an arena with a vehicle
|
||||
*/
|
||||
ERROR_TELEPORT_IN_VEHICLE,
|
||||
|
||||
/**
|
||||
* The message displayed if an arena cannot be loaded
|
||||
*/
|
||||
ERROR_ARENA_NOT_LOADED,
|
||||
|
||||
/**
|
||||
* The message displayed if an arena's data cannot be loaded
|
||||
*/
|
||||
ERROR_ARENA_DATA_NOT_LOADED,
|
||||
|
||||
/**
|
||||
* The message displayed if the user specifies an unrecognized arena
|
||||
*/
|
||||
ERROR_ARENA_NOT_FOUND,
|
||||
|
||||
/**
|
||||
* The message displayed if the user specifies an unrecognized group
|
||||
*/
|
||||
ERROR_GROUP_NOT_FOUND,
|
||||
|
||||
/**
|
||||
* The message displayed if the console tries to execute a player-only command
|
||||
*/
|
||||
ERROR_PLAYER_ONLY,
|
||||
|
||||
/**
|
||||
* The message displayed if the name of an arena is duplicated
|
||||
*/
|
||||
ERROR_ARENA_NAME_COLLISION,
|
||||
|
||||
/**
|
||||
* The message displayed if the player is required to win on the default difficulty first
|
||||
*/
|
||||
ERROR_NORMAL_MODE_REQUIRED,
|
||||
|
||||
/**
|
||||
* The message displayed if the player is required to win on the default difficulty for all arenas in the group first
|
||||
*/
|
||||
ERROR_GROUP_NORMAL_MODE_REQUIRED,
|
||||
|
||||
/**
|
||||
* The message displayed if the player is required to beat the previous arena in the group
|
||||
*/
|
||||
ERROR_PREVIOUS_ARENA_REQUIRED,
|
||||
|
||||
/**
|
||||
* The message displayed if player teleportation failed for some reason
|
||||
*/
|
||||
ERROR_ARENA_TELEPORT_FAILED,
|
||||
|
||||
/**
|
||||
* The message displayed if the player tries to quit the arena while not in an arena
|
||||
*/
|
||||
ERROR_NOT_IN_ARENA,
|
||||
|
||||
/**
|
||||
* The message displayed if the player tries to join an arena while already playing
|
||||
*
|
||||
* <p>This should in theory be impossible, as players cannot use any commands except /miniGamesLeave while playing
|
||||
* in an arena.</p>
|
||||
*/
|
||||
ERROR_ALREADY_PLAYING,
|
||||
|
||||
/**
|
||||
* The message displayed if a player tries to join an arena with a passenger or riding a vehicle
|
||||
*/
|
||||
ERROR_JOIN_IN_VEHICLE_OR_PASSENGER,
|
||||
|
||||
/**
|
||||
* The message displayed if the player tries to change an unrecognized arena property
|
||||
*/
|
||||
ERROR_UNKNOWN_PROPERTY,
|
||||
|
||||
/**
|
||||
* The message displayed if the given input to /dEdit or /pEdit's value is invalid
|
||||
*/
|
||||
ERROR_PROPERTY_INPUT_INVALID,
|
||||
|
||||
/**
|
||||
* The message displayed if the first arena specified in /dgSwap or /pgSwap is invalid
|
||||
*/
|
||||
ERROR_ARENA_1_NOT_FOUND,
|
||||
|
||||
/**
|
||||
* The message displayed if the second arena specified in /dgSwap or /pgSwap is invalid
|
||||
*/
|
||||
ERROR_ARENA_2_NOT_FOUND,
|
||||
|
||||
/**
|
||||
* The message displayed if the two groups specified for /dgSwap or /pgSwap are in different arenas
|
||||
*/
|
||||
ERROR_SWAP_DIFFERENT_GROUPS,
|
||||
|
||||
/**
|
||||
* The message displayed if a player tries to use any command other than /mLeave while in an arena
|
||||
*/
|
||||
ERROR_ILLEGAL_COMMAND,
|
||||
|
||||
/**
|
||||
* The message displayed if the player is trying to join a parkour arena on hardcore which has no checkpoints
|
||||
*/
|
||||
ERROR_HARDCORE_NO_CHECKPOINTS,
|
||||
|
||||
/**
|
||||
* The message displayed if a user specifies an invalid material
|
||||
*/
|
||||
ERROR_INVALID_MATERIAL,
|
||||
|
||||
/**
|
||||
* The message displayed if a user specifies an invalid world
|
||||
*/
|
||||
ERROR_INVALID_WORLD,
|
||||
|
||||
/**
|
||||
* The message displayed if a user specifies an invalid number
|
||||
*/
|
||||
ERROR_INVALID_NUMBER,
|
||||
|
||||
/**
|
||||
* The message displayed if a user specifies an invalid command (for a command reward)
|
||||
*/
|
||||
ERROR_INVALID_COMMAND_STRING,
|
||||
|
||||
/**
|
||||
* The message displayed if a user specified an invalid reward type
|
||||
*/
|
||||
ERROR_REWARD_TYPE_INVALID,
|
||||
|
||||
/**
|
||||
* The message displayed if a user specified an invalid reward condition
|
||||
*/
|
||||
ERROR_REWARD_CONDITION_INVALID,
|
||||
|
||||
/* **************** *
|
||||
* Success messages *
|
||||
* **************** */
|
||||
|
||||
/**
|
||||
* The message displayed if an arena's group has been changed
|
||||
*/
|
||||
SUCCESS_ARENA_GROUP_UPDATED,
|
||||
|
||||
/**
|
||||
* The message displayed if the MiniGames plugin is reloaded
|
||||
*/
|
||||
SUCCESS_PLUGIN_RELOADED,
|
||||
|
||||
/**
|
||||
* The message displayed if a new arena has been created
|
||||
*/
|
||||
SUCCESS_ARENA_CREATED,
|
||||
|
||||
/**
|
||||
* The message displayed if a player clears/wins an arena for the first time
|
||||
*/
|
||||
SUCCESS_ARENA_FIRST_CLEAR,
|
||||
|
||||
/**
|
||||
* The message displayed when a player wins an arena
|
||||
*/
|
||||
SUCCESS_ARENA_WIN,
|
||||
|
||||
/**
|
||||
* The message displayed when a player quits an arena
|
||||
*/
|
||||
SUCCESS_ARENA_QUIT,
|
||||
|
||||
/**
|
||||
* The message used to display the current value of an arena property
|
||||
*/
|
||||
SUCCESS_CURRENT_VALUE,
|
||||
|
||||
/**
|
||||
* The message used to announce that an arena property has been changed
|
||||
*/
|
||||
SUCCESS_PROPERTY_CHANGED,
|
||||
|
||||
/**
|
||||
* The message displayed when two arenas' order in a group have been swapped
|
||||
*/
|
||||
SUCCESS_ARENAS_SWAPPED,
|
||||
|
||||
/**
|
||||
* The message displayed when an arena has been removed
|
||||
*/
|
||||
SUCCESS_ARENA_REMOVED,
|
||||
|
||||
/**
|
||||
* The header displayed before listing all dropper arenas
|
||||
*/
|
||||
SUCCESS_DROPPER_ARENAS_LIST,
|
||||
|
||||
/**
|
||||
* The header displayed before listing all parkour arenas
|
||||
*/
|
||||
SUCCESS_PARKOUR_ARENAS_LIST,
|
||||
|
||||
/**
|
||||
* The message displayed when a player reaches a new checkpoint in a parkour arena
|
||||
*/
|
||||
SUCCESS_CHECKPOINT_REACHED,
|
||||
|
||||
/**
|
||||
* The header displayed before listing all arenas (stages) in a group
|
||||
*/
|
||||
SUCCESS_GROUP_STAGES,
|
||||
|
||||
/**
|
||||
* The message displayed when a new record has been achieved
|
||||
*/
|
||||
SUCCESS_RECORD_ACHIEVED,
|
||||
|
||||
/**
|
||||
* The partial message used to describe that the player achieved a world record
|
||||
*/
|
||||
RECORD_ACHIEVED_GLOBAL,
|
||||
|
||||
/**
|
||||
* The partial message used to describe that the player achieved a personal best record
|
||||
*/
|
||||
RECORD_ACHIEVED_PERSONAL,
|
||||
|
||||
/**
|
||||
* The message displayed when a player joins an arena
|
||||
*/
|
||||
SUCCESS_ARENA_JOINED,
|
||||
|
||||
/**
|
||||
* The message displayed when a player is rewarded with an item
|
||||
*/
|
||||
SUCCESS_ITEM_REWARDED,
|
||||
|
||||
/**
|
||||
* The message displayed when a player is rewarded with a permission
|
||||
*/
|
||||
SUCCESS_PERMISSION_REWARDED,
|
||||
|
||||
/**
|
||||
* The message displayed when a player is rewarded with a permission, for a specific world
|
||||
*/
|
||||
SUCCESS_PERMISSION_REWARDED_WORLD,
|
||||
|
||||
/**
|
||||
* The message displayed when a player is rewarded by a command being run
|
||||
*/
|
||||
SUCCESS_COMMAND_REWARDED,
|
||||
|
||||
/**
|
||||
* The message displayed when a player is rewarded with an amount of currency
|
||||
*/
|
||||
SUCCESS_ECONOMY_REWARDED,
|
||||
|
||||
/**
|
||||
* The message displayed when an arena reward has been successfully added
|
||||
*/
|
||||
SUCCESS_REWARD_ADDED,
|
||||
|
||||
/**
|
||||
* The message displayed when arena rewards have been cleared
|
||||
*/
|
||||
SUCCESS_REWARDS_CLEARED,
|
||||
;
|
||||
|
||||
@Override
|
||||
public @NotNull TranslatableMessage[] getAllMessages() {
|
||||
return MiniGameMessage.values();
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,103 @@
|
||||
package net.knarcraft.minigames.config;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* The configuration keeping track of parkour settings
|
||||
*/
|
||||
public class ParkourConfiguration extends MiniGameConfiguration {
|
||||
|
||||
private final static String rootNode = "parkour.";
|
||||
|
||||
private boolean enforceCheckpointOrder;
|
||||
private boolean mustDoGroupedInSequence;
|
||||
private boolean ignoreRecordsUntilGroupBeatenOnce;
|
||||
private Set<Material> killPlaneBlocks;
|
||||
private Set<Material> obstacleBlocks;
|
||||
|
||||
/**
|
||||
* Instantiates a new dropper configuration
|
||||
*
|
||||
* @param configuration <p>The YAML configuration to use internally</p>
|
||||
*/
|
||||
public ParkourConfiguration(FileConfiguration configuration) {
|
||||
super(configuration);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets whether all checkpoints must be triggered in the order they are set when configuring the parkour arena
|
||||
*
|
||||
* @return <p>Whether checkpoints must be triggered in order</p>
|
||||
*/
|
||||
public boolean enforceCheckpointOrder() {
|
||||
return this.enforceCheckpointOrder;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets whether grouped arenas must be done in the set sequence
|
||||
*
|
||||
* @return <p>Whether grouped arenas must be done in sequence</p>
|
||||
*/
|
||||
public boolean mustDoGroupedInSequence() {
|
||||
return this.mustDoGroupedInSequence;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets whether records should be discarded, unless the player has already beaten all arenas in the group
|
||||
*
|
||||
* @return <p>Whether to ignore records on the first play-through</p>
|
||||
*/
|
||||
public boolean ignoreRecordsUntilGroupBeatenOnce() {
|
||||
return this.ignoreRecordsUntilGroupBeatenOnce;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets all types of blocks constituting parkour arenas' kill planes
|
||||
*
|
||||
* @return <p>The types of blocks causing a player to fail a parkour map</p>
|
||||
*/
|
||||
public Set<Material> getKillPlaneBlocks() {
|
||||
return new HashSet<>(this.killPlaneBlocks);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets all types of blocks constituting parkour arena's obstacle blocks
|
||||
*
|
||||
* @return <p>The types of blocks constituting parkour arena's obstacle blocks</p>
|
||||
*/
|
||||
public Set<Material> getObstacleBlocks() {
|
||||
return new HashSet<>(this.obstacleBlocks);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void load() {
|
||||
this.enforceCheckpointOrder = configuration.getBoolean(rootNode + "enforceCheckpointOrder", false);
|
||||
this.mustDoGroupedInSequence = configuration.getBoolean(rootNode + "mustDoGroupedInSequence", true);
|
||||
this.ignoreRecordsUntilGroupBeatenOnce = configuration.getBoolean(rootNode + "ignoreRecordsUntilGroupBeatenOnce", false);
|
||||
this.killPlaneBlocks = loadMaterialList(rootNode + "killPlaneBlocks");
|
||||
this.obstacleBlocks = loadMaterialList(rootNode + "obstacleBlocks");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder builder = new StringBuilder(
|
||||
"Current configuration:" +
|
||||
"Current configuration:" +
|
||||
"\n" + "Must do groups in sequence: " + mustDoGroupedInSequence +
|
||||
"\n" + "Ignore records until group beaten once: " + ignoreRecordsUntilGroupBeatenOnce +
|
||||
"\n" + "Kill plane blocks: ");
|
||||
for (Material material : killPlaneBlocks) {
|
||||
builder.append("\n - ").append(material.name());
|
||||
}
|
||||
builder.append("\n" + "Obstacle blocks: ");
|
||||
for (Material material : obstacleBlocks) {
|
||||
builder.append("\n - ").append(material.name());
|
||||
}
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,69 @@
|
||||
package net.knarcraft.minigames.config;
|
||||
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* The configuration keeping track of shared settings
|
||||
*/
|
||||
public class SharedConfiguration extends MiniGameConfiguration {
|
||||
|
||||
private final static String rootNode = "shared.";
|
||||
private double liquidHitBoxDepth;
|
||||
private double solidHitBoxDistance;
|
||||
|
||||
/**
|
||||
* Instantiates a new shared configuration
|
||||
*
|
||||
* @param configuration <p>The YAML configuration to use internally</p>
|
||||
*/
|
||||
public SharedConfiguration(@NotNull FileConfiguration configuration) {
|
||||
super(configuration);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the negative depth a player must reach in a liquid block for fail/win detection to trigger
|
||||
*
|
||||
* <p>This decides how far inside a non-solid block the player must go before detection triggers. The closer to -1
|
||||
* it is, the more accurate it will seem to the player, but the likelihood of not detecting the hit increases.</p>
|
||||
*
|
||||
* @return <p>The liquid hit box depth to use</p>
|
||||
*/
|
||||
public double getLiquidHitBoxDepth() {
|
||||
return this.liquidHitBoxDepth;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the positive distance a player must at most be from a block for fail/win detection to trigger
|
||||
*
|
||||
* <p>This decides the distance the player must be from a block below them before a hit triggers. If too low, the
|
||||
* likelihood of detecting the hit decreases, but it won't look like the player hit the block without being near.</p>
|
||||
*
|
||||
* @return <p>The solid hit box distance to use</p>
|
||||
*/
|
||||
public double getSolidHitBoxDistance() {
|
||||
return this.solidHitBoxDistance;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void load() {
|
||||
this.liquidHitBoxDepth = configuration.getDouble(rootNode + "liquidHitBoxDepth", -0.8);
|
||||
this.solidHitBoxDistance = configuration.getDouble(rootNode + "solidHitBoxDistance", 0.2);
|
||||
|
||||
if (this.liquidHitBoxDepth <= -1 || this.liquidHitBoxDepth > 0) {
|
||||
this.liquidHitBoxDepth = -0.8;
|
||||
}
|
||||
|
||||
if (this.solidHitBoxDistance <= 0 || this.solidHitBoxDistance > 1) {
|
||||
this.solidHitBoxDistance = 0.2;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Current configuration:" +
|
||||
"\n" + "Liquid hit box depth: " + liquidHitBoxDepth +
|
||||
"\n" + "Solid hit box distance: " + solidHitBoxDistance;
|
||||
}
|
||||
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user