├── .github ├── FUNDING.yml ├── stale.yml └── workflows │ └── build.yml ├── .gitignore ├── CONTRIBUTING.md ├── LICENSE ├── README.md ├── docs ├── api │ ├── index.md │ ├── networking.md │ └── version │ │ ├── v10.md │ │ ├── v7.md │ │ ├── v8.md │ │ └── v9.md ├── commands.md ├── config.md ├── css │ └── extra.css ├── index.md ├── languages.md ├── permissions.md └── tools-integrations.md ├── lang ├── de.yml ├── en.yml ├── es.yml ├── fr.yml ├── ja.yml ├── ko.yml ├── pl.yml ├── ru.yml ├── tr.yml ├── uk.yml ├── vi.yml ├── zh-cn.yml └── zh-tw.yml ├── mkdocs.yml ├── pom.xml ├── requirements.txt └── src └── main ├── java └── net │ └── coreprotect │ ├── CoreProtect.java │ ├── CoreProtectAPI.java │ ├── api │ ├── BlockAPI.java │ ├── QueueLookup.java │ ├── SessionLookup.java │ └── result │ │ └── ParseResult.java │ ├── bukkit │ ├── BukkitAdapter.java │ ├── BukkitInterface.java │ ├── Bukkit_v1_17.java │ ├── Bukkit_v1_18.java │ ├── Bukkit_v1_19.java │ ├── Bukkit_v1_20.java │ └── Bukkit_v1_21.java │ ├── command │ ├── ApplyCommand.java │ ├── CancelCommand.java │ ├── CommandHandler.java │ ├── CommandParser.java │ ├── ConsumerCommand.java │ ├── HelpCommand.java │ ├── InspectCommand.java │ ├── LookupCommand.java │ ├── NetworkDebugCommand.java │ ├── PurgeCommand.java │ ├── ReloadCommand.java │ ├── RollbackRestoreCommand.java │ ├── StatusCommand.java │ ├── TabHandler.java │ ├── TeleportCommand.java │ ├── UndoCommand.java │ ├── WorldEditHandler.java │ ├── lookup │ │ ├── BlockLookupThread.java │ │ ├── ChestTransactionLookupThread.java │ │ └── StandardLookupThread.java │ └── parser │ │ ├── ActionParser.java │ │ ├── LocationParser.java │ │ ├── MaterialParser.java │ │ ├── TimeParser.java │ │ ├── UserParser.java │ │ └── WorldParser.java │ ├── config │ ├── Config.java │ ├── ConfigFile.java │ └── ConfigHandler.java │ ├── consumer │ ├── Consumer.java │ ├── Queue.java │ └── process │ │ ├── ArtInsertProcess.java │ │ ├── BlockBreakProcess.java │ │ ├── BlockDataInsertProcess.java │ │ ├── BlockPlaceProcess.java │ │ ├── ContainerBreakProcess.java │ │ ├── ContainerTransactionProcess.java │ │ ├── EntityInsertProcess.java │ │ ├── EntityKillProcess.java │ │ ├── EntitySpawnProcess.java │ │ ├── ItemTransactionProcess.java │ │ ├── MaterialInsertProcess.java │ │ ├── NaturalBlockBreakProcess.java │ │ ├── PlayerChatProcess.java │ │ ├── PlayerCommandProcess.java │ │ ├── PlayerInteractionProcess.java │ │ ├── PlayerKillProcess.java │ │ ├── PlayerLoginProcess.java │ │ ├── PlayerLogoutProcess.java │ │ ├── Process.java │ │ ├── RollbackUpdateProcess.java │ │ ├── SignTextProcess.java │ │ ├── SignUpdateProcess.java │ │ ├── SkullUpdateProcess.java │ │ ├── StructureGrowthProcess.java │ │ └── WorldInsertProcess.java │ ├── database │ ├── BlockLookup.java │ ├── ContainerRollback.java │ ├── Database.java │ ├── Lookup.java │ ├── LookupConverter.java │ ├── LookupRaw.java │ ├── logger │ │ ├── BlockBreakLogger.java │ │ ├── BlockPlaceLogger.java │ │ ├── ChatLogger.java │ │ ├── CommandLogger.java │ │ ├── ContainerBreakLogger.java │ │ ├── ContainerLogger.java │ │ ├── EntityKillLogger.java │ │ ├── ItemLogger.java │ │ ├── PlayerInteractLogger.java │ │ ├── PlayerKillLogger.java │ │ ├── PlayerSessionLogger.java │ │ ├── SignTextLogger.java │ │ ├── SkullBreakLogger.java │ │ ├── SkullPlaceLogger.java │ │ └── UsernameLogger.java │ ├── lookup │ │ ├── BlockLookup.java │ │ ├── ChestTransactionLookup.java │ │ ├── InteractionLookup.java │ │ ├── PlayerLookup.java │ │ └── SignMessageLookup.java │ ├── rollback │ │ ├── Rollback.java │ │ ├── RollbackBlockHandler.java │ │ ├── RollbackComplete.java │ │ ├── RollbackEntityHandler.java │ │ ├── RollbackItemHandler.java │ │ ├── RollbackProcessor.java │ │ └── RollbackUtil.java │ └── statement │ │ ├── BlockStatement.java │ │ ├── ChatStatement.java │ │ ├── CommandStatement.java │ │ ├── ContainerStatement.java │ │ ├── EntityStatement.java │ │ ├── ItemStatement.java │ │ ├── MaterialStatement.java │ │ ├── SessionStatement.java │ │ ├── SignStatement.java │ │ ├── SkullStatement.java │ │ ├── UserStatement.java │ │ └── WorldStatement.java │ ├── event │ └── CoreProtectPreLogEvent.java │ ├── language │ ├── Language.java │ ├── Phrase.java │ └── Selector.java │ ├── listener │ ├── ListenerHandler.java │ ├── block │ │ ├── BlockBreakListener.java │ │ ├── BlockBurnListener.java │ │ ├── BlockDispenseListener.java │ │ ├── BlockExplodeListener.java │ │ ├── BlockFadeListener.java │ │ ├── BlockFertilizeListener.java │ │ ├── BlockFormListener.java │ │ ├── BlockFromToListener.java │ │ ├── BlockIgniteListener.java │ │ ├── BlockPistonListener.java │ │ ├── BlockPlaceListener.java │ │ ├── BlockSpreadListener.java │ │ ├── BlockUtil.java │ │ └── CampfireStartListener.java │ ├── channel │ │ ├── PluginChannelHandshakeListener.java │ │ └── PluginChannelListener.java │ ├── entity │ │ ├── CreatureSpawnListener.java │ │ ├── EntityBlockFormListener.java │ │ ├── EntityChangeBlockListener.java │ │ ├── EntityDamageByBlockListener.java │ │ ├── EntityDamageByEntityListener.java │ │ ├── EntityDeathListener.java │ │ ├── EntityExplodeListener.java │ │ ├── EntityInteractListener.java │ │ ├── EntityPickupItemListener.java │ │ ├── HangingBreakByEntityListener.java │ │ ├── HangingBreakListener.java │ │ └── HangingPlaceListener.java │ ├── player │ │ ├── ArmorStandManipulateListener.java │ │ ├── CraftItemListener.java │ │ ├── FoodLevelChangeListener.java │ │ ├── HopperPullListener.java │ │ ├── HopperPushListener.java │ │ ├── InventoryChangeListener.java │ │ ├── InventoryClickListener.java │ │ ├── PlayerBucketEmptyListener.java │ │ ├── PlayerBucketFillListener.java │ │ ├── PlayerChatListener.java │ │ ├── PlayerCommandListener.java │ │ ├── PlayerDeathListener.java │ │ ├── PlayerDropItemListener.java │ │ ├── PlayerInteractEntityListener.java │ │ ├── PlayerInteractListener.java │ │ ├── PlayerInteractUtils.java │ │ ├── PlayerItemBreakListener.java │ │ ├── PlayerJoinListener.java │ │ ├── PlayerPickupArrowListener.java │ │ ├── PlayerQuitListener.java │ │ ├── PlayerTakeLecternBookListener.java │ │ ├── ProjectileLaunchListener.java │ │ ├── SignChangeListener.java │ │ └── inspector │ │ │ ├── BaseInspector.java │ │ │ ├── BlockInspector.java │ │ │ ├── ContainerInspector.java │ │ │ ├── InteractionInspector.java │ │ │ └── SignInspector.java │ └── world │ │ ├── ChunkPopulateListener.java │ │ ├── LeavesDecayListener.java │ │ ├── PortalCreateListener.java │ │ └── StructureGrowListener.java │ ├── model │ └── BlockGroup.java │ ├── paper │ ├── PaperAdapter.java │ ├── PaperHandler.java │ ├── PaperInterface.java │ ├── Paper_v1_17.java │ ├── Paper_v1_20.java │ └── listener │ │ ├── BlockPreDispenseListener.java │ │ └── PaperChatListener.java │ ├── patch │ ├── Patch.java │ └── script │ │ ├── __2_10_0.java │ │ ├── __2_11_0.java │ │ ├── __2_15_0.java │ │ ├── __2_16_0.java │ │ ├── __2_17_0.java │ │ ├── __2_18_0.java │ │ ├── __2_18_1.java │ │ ├── __2_19_0.java │ │ ├── __2_20_0.java │ │ ├── __2_21_0.java │ │ ├── __2_22_0.java │ │ ├── __2_23_0.java │ │ ├── __2_23_1.java │ │ ├── __2_5_0.java │ │ └── __2_6_0.java │ ├── services │ ├── PluginInitializationService.java │ ├── ShutdownService.java │ └── VersionCheckService.java │ ├── spigot │ ├── SpigotAdapter.java │ ├── SpigotHandler.java │ └── SpigotInterface.java │ ├── thread │ ├── CacheHandler.java │ ├── NetworkHandler.java │ └── Scheduler.java │ ├── utility │ ├── BlockUtils.java │ ├── Chat.java │ ├── ChatMessage.java │ ├── ChatUtils.java │ ├── ChestTool.java │ ├── Color.java │ ├── DatabaseUtils.java │ ├── EntityUtils.java │ ├── Extensions.java │ ├── ItemUtils.java │ ├── MaterialUtils.java │ ├── StringUtils.java │ ├── SystemUtils.java │ ├── Teleport.java │ ├── Util.java │ ├── Validate.java │ ├── VersionUtils.java │ ├── WorldUtils.java │ ├── entity │ │ ├── EntityUtil.java │ │ └── HangingUtil.java │ └── serialize │ │ └── ItemMetaHandler.java │ └── worldedit │ ├── CoreProtectEditSessionEvent.java │ ├── CoreProtectLogger.java │ ├── WorldEditBlockState.java │ └── WorldEditLogger.java └── resources └── plugin.yml /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | patreon: coreprotect 2 | -------------------------------------------------------------------------------- /.github/stale.yml: -------------------------------------------------------------------------------- 1 | daysUntilStale: 60 2 | daysUntilClose: 7 3 | exemptLabels: 4 | - 'accepted' 5 | - 'bug' 6 | - 'suggestion' 7 | - 'help wanted' 8 | staleLabel: stale 9 | markComment: > 10 | This issue has been automatically marked as stale because it has not had 11 | recent activity. It will be closed if no further activity occurs. Thank you 12 | for your contributions. 13 | closeComment: false -------------------------------------------------------------------------------- /.github/workflows/build.yml: -------------------------------------------------------------------------------- 1 | name: Build 2 | on: 3 | push: 4 | branches: 5 | - master 6 | pull_request: 7 | types: [opened, synchronize, reopened] 8 | jobs: 9 | build: 10 | name: Build 11 | runs-on: ubuntu-latest 12 | steps: 13 | - uses: actions/checkout@v4 14 | with: 15 | fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis 16 | - name: Set up JDK 21 17 | uses: actions/setup-java@v4 18 | with: 19 | java-version: '21' 20 | distribution: 'temurin' 21 | - name: Cache Maven packages 22 | uses: actions/cache@v4 23 | with: 24 | path: ~/.m2 25 | key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }} 26 | restore-keys: ${{ runner.os }}-m2 27 | - name: Build 28 | run: mvn -B verify 29 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ![CoreProtect](https://userfolio.com/uploads/coreprotect-banner-v19.png) 2 | 3 | [![Artistic License 2.0](https://img.shields.io/github/license/PlayPro/CoreProtect?&logo=github)](LICENSE) 4 | [![GitHub Workflows](https://github.com/PlayPro/CoreProtect/actions/workflows/build.yml/badge.svg)](https://github.com/PlayPro/CoreProtect/actions) 5 | [![Netlify Status](https://img.shields.io/netlify/c1d26a0f-65c5-4e4b-95d7-e08af671ab67)](https://app.netlify.com/sites/coreprotect/deploys) 6 | [![CodeFactor](https://www.codefactor.io/repository/github/playpro/coreprotect/badge)](https://www.codefactor.io/repository/github/playpro/coreprotect) 7 | [![Join us on Discord](https://img.shields.io/discord/348680641560313868.svg?label=&logo=discord&logoColor=ffffff&color=7389D8&labelColor=6A7EC2)](https://discord.gg/b4DZ4jy) 8 | 9 | CoreProtect 10 | =========== 11 | 12 | CoreProtect is a blazing fast data logging and anti-griefing tool for Minecraft servers. 13 | 14 | For a detailed description of the plugin, please visit [coreprotect.net](https://coreprotect.net). 15 | 16 | | Quick Links | | 17 | | --- | --- | 18 | | CoreProtect Discord: | [discord.gg/b4DZ4jy](https://discord.gg/b4DZ4jy) | 19 | | CoreProtect Patreon: | [patreon.com/coreprotect](https://www.patreon.com/coreprotect) | 20 | | CoreProtect Documentation: | [docs.coreprotect.net](https://docs.coreprotect.net) | 21 | | Downloads for MC 1.14 - 1.20: | [coreprotect.net/latest](https://coreprotect.net/latest/) | 22 | | Downloads for MC 1.8 - 1.12: | [coreprotect.net/legacy](https://coreprotect.net/legacy/) | 23 | 24 | bStats 25 | ------ 26 | [![bStats Graph Data](https://bstats.org/signatures/bukkit/CoreProtect.svg)](https://bstats.org/plugin/bukkit/CoreProtect) 27 | 28 | API 29 | ------ 30 | ### [API Documentation](https://docs.coreprotect.net/api/) 31 | 32 | ### Dependency Information 33 | Maven 34 | ```xml 35 | 36 | playpro-repo 37 | https://maven.playpro.com 38 | 39 | ``` 40 | ```xml 41 | 42 | net.coreprotect 43 | coreprotect 44 | 22.4 45 | provided 46 | 47 | ``` 48 | 49 | Contributing 50 | ------ 51 | CoreProtect is an open source project, and gladly accepts community contributions. 52 | 53 | If you'd like to contribute, please read our contributing guidelines here: [CONTRIBUTING.md](CONTRIBUTING.md) 54 | 55 | [![Contributor Covenant](https://img.shields.io/badge/Contributor%20Covenant-2.0-4baaaa.svg)](CONTRIBUTING.md#code-of-conduct) -------------------------------------------------------------------------------- /docs/api/index.md: -------------------------------------------------------------------------------- 1 | # CoreProtect API 2 | 3 | The CoreProtect API enables you to log your own block changes, perform lookups, rollbacks, restores, and more. 4 | 5 | | API Details | | 6 | | --- | --- | 7 | | **API Version:** | 10 | 8 | | **Plugin Version:** | v22.4+ | 9 | | **Maven:** | [maven.playpro.com](https://maven.playpro.com) | 10 | 11 | *Documentation for the API version 10 can be found [here](/api/version/v10/).* -------------------------------------------------------------------------------- /docs/config.md: -------------------------------------------------------------------------------- 1 | # Configuration 2 | 3 | The CoreProtect configuration file can be found within the CoreProtect folder, at `config.yml`. 4 | 5 | ## Per-World Configuration 6 | 7 | If you'd like to modify the logging settings for a specific world, simply do the following: 8 | 9 | 1. Copy the config.yml file to the name of the world (e.g. world_nether.yml) 10 | 2. In the new file, modify the logging settings as desired. 11 | 3. Either restart your server, or type "/co reload" in-game. 12 | 13 | Secondary configuration files override the value specified in config.yml. If you leave an option out of a secondary configuration file, then the option specified in config.yml will be used. 14 | 15 | #### Examples 16 | * If you'd like to disable all logging for the End, copy the `config.yml` file to `world_the_end.yml` (matching the folder name for the world). Then, simply disable all logging options within the new file. 17 | * If you just want to disable entity death logging in the Nether, but keep all other logging options the same, simply create a file named `world_nether.yml` containing the text "rollback-entities: false". 18 | 19 | ## Disabling Logging 20 | 21 | To disable logging for specific users, blocks or commands, simply do the following: 22 | 23 | 1. In the CoreProtect plugin directory, create a file named `blacklist.txt`. 24 | 2. Enter the names of the users (or commands) you'd like to disable logging for (each username on a new line). 25 | 3. Either restart your server, or type "/co reload" in-game. 26 | 27 | This can be used to disable logging for non-player users, such as "#creeper". For example, if you'd like to disable logging for the user "Notch", TNT explosions, stone blocks, and the "/help" command, the blacklist.txt file would look like this: 28 | ```text 29 | Notch 30 | #tnt 31 | /help 32 | minecraft:stone 33 | ``` 34 | 35 | *Please note that to disable logging for blocks, CoreProtect v23+ is required, and you must include the namespace. For example, to disable logging for dirt, you must add it as "minecraft:dirt".* -------------------------------------------------------------------------------- /docs/css/extra.css: -------------------------------------------------------------------------------- 1 | /*Customization for blockquote appearance*/ 2 | blockquote { 3 | border-left: 5px solid #ccc; 4 | padding-left: 20px; 5 | margin-left: 0px!important; 6 | } -------------------------------------------------------------------------------- /docs/index.md: -------------------------------------------------------------------------------- 1 | # Welcome to the CoreProtect Documentation 2 | 3 | For more information about CoreProtect, visit [coreprotect.net](http://coreprotect.net). 4 | 5 | ## Getting Started 6 | 7 | Please visit one of the following links for more information. 8 | 9 | [**CoreProtect Commands**](/commands/) 10 | A list of all commands that can be used within CoreProtect. 11 | 12 | [**CoreProtect Permissions**](/permissions/) 13 | A list of all permissions that can be used with CoreProtect. 14 | 15 | [**CoreProtect Language Codes**](/languages/) 16 | A list of all language codes that can be used with CoreProtect. 17 | 18 | [**CoreProtect API Documentation**](/api/) 19 | Log your own block changes, perform lookups, rollbacks, restores, and more. 20 | 21 | [**Compatible Third-Party Plugins & Tools**](/tools-integrations/) 22 | A list of plugins and tools that are compatible with CoreProtect. 23 | 24 | [**Per-World Configuration Files**](/config/#per-world-configuration) 25 | Modify the logging settings for a specific world on your server. 26 | 27 | [**Disable Logging With a Blacklist**](/config/#disabling-logging) 28 | Disable logging for specific users, blocks or commands. 29 | -------------------------------------------------------------------------------- /docs/languages.md: -------------------------------------------------------------------------------- 1 | # Languages 2 | 3 | Language codes can be entered in `config.yml` for automatic online translation. 4 | 5 | --- 6 | 7 | ## CoreProtect Language Codes 8 | 9 | | Language | Code | 10 | | --- | --- | 11 | | Afrikaans | `af` | 12 | | Albanian | `sq` | 13 | | Amharic | `am` | 14 | | Arabic | `ar` | 15 | | Armenian | `hy` | 16 | | Azerbaijani | `az` | 17 | | Basque | `eu` | 18 | | Belarusian | `be` | 19 | | Bengali | `bn` | 20 | | Bosnian | `bs` | 21 | | Bulgarian | `bg` | 22 | | Catalan | `ca` | 23 | | Cebuano | `ceb` | 24 | | Chinese (Simplified) | `zh-CN` or `zh` | 25 | | Chinese (Traditional) | `zh-TW` | 26 | | Corsican | `co` | 27 | | Croatian | `hr` | 28 | | Czech | `cs` | 29 | | Danish | `da` | 30 | | Dutch | `nl` | 31 | | English | `en` | 32 | | Esperanto | `eo` | 33 | | Estonian | `et` | 34 | | Finnish | `fi` | 35 | | French | `fr` | 36 | | Frisian | `fy` | 37 | | Galician | `gl` | 38 | | Georgian | `ka` | 39 | | German | `de` | 40 | | Greek | `el` | 41 | | Gujarati | `gu` | 42 | | Haitian Creole | `ht` | 43 | | Hausa | `ha` | 44 | | Hawaiian | `haw` | 45 | | Hebrew | `he` or `iw` | 46 | | Hindi | `hi` | 47 | | Hmong | `hmn` | 48 | | Hungarian | `hu` | 49 | | Icelandic | `is` | 50 | | Igbo | `ig` | 51 | | Indonesian | `id` | 52 | | Irish | `ga` | 53 | | Italian | `it` | 54 | | Japanese | `ja` | 55 | | Javanese | `jv` | 56 | | Kannada | `kn` | 57 | | Kazakh | `kk` | 58 | | Khmer | `km` | 59 | | Kinyarwanda | `rw` | 60 | | Korean | `ko` | 61 | | Kurdish | `ku` | 62 | | Kyrgyz | `ky` | 63 | | Lao | `lo` | 64 | | Latin | `la` | 65 | | Latvian | `lv` | 66 | | Lithuanian | `lt` | 67 | | Luxembourgish | `lb` | 68 | | Macedonian | `mk` | 69 | | Malagasy | `mg` | 70 | | Malay | `ms` | 71 | | Malayalam | `ml` | 72 | | Maltese | `mt` | 73 | | Maori | `mi` | 74 | | Marathi | `mr` | 75 | | Mongolian | `mn` | 76 | | Myanmar (Burmese) | `my` | 77 | | Nepali | `ne` | 78 | | Norwegian | `no` | 79 | | Nyanja (Chichewa) | `ny` | 80 | | Odia (Oriya) | `or` | 81 | | Pashto | `ps` | 82 | | Persian | `fa` | 83 | | Polish | `pl` | 84 | | Portuguese (Portugal, Brazil) | `pt` | 85 | | Punjabi | `pa` | 86 | | Romanian | `ro` | 87 | | Russian | `ru` | 88 | | Samoan | `sm` | 89 | | Scots Gaelic | `gd` | 90 | | Serbian | `sr` | 91 | | Sesotho | `st` | 92 | | Shona | `sn` | 93 | | Sindhi | `sd` | 94 | | Sinhala (Sinhalese) | `si` | 95 | | Slovak | `sk` | 96 | | Slovenian | `sl` | 97 | | Somali | `so` | 98 | | Spanish | `es` | 99 | | Sundanese | `su` | 100 | | Swahili | `sw` | 101 | | Swedish | `sv` | 102 | | Tagalog (Filipino) | `tl` | 103 | | Tajik | `tg` | 104 | | Tamil | `ta` | 105 | | Tatar | `tt` | 106 | | Telugu | `te` | 107 | | Thai | `th` | 108 | | Turkish | `tr` | 109 | | Turkmen | `tk` | 110 | | Ukrainian | `uk` | 111 | | Urdu | `ur` | 112 | | Uyghur | `ug` | 113 | | Uzbek | `uz` | 114 | | Vietnamese | `vi` | 115 | | Welsh | `cy` | 116 | | Xhosa | `xh` | 117 | | Yiddish | `yi` | 118 | | Yoruba | `yo` | 119 | | Zulu | `zu` | 120 | 121 | *Source: [cloud.google.com/translate](https://cloud.google.com/translate/docs/languages)* 122 | 123 | --- -------------------------------------------------------------------------------- /docs/tools-integrations.md: -------------------------------------------------------------------------------- 1 | # Tools & Integrations 2 | 3 | Listed below are links to plugins and tools compatible with CoreProtect. 4 | 5 | These plugins/tools are maintained by third parties, and may have issues outside of our control. 6 | 7 | --- 8 | 9 | ## Plugins 10 | 11 | * **WorldEdit** 12 | Use WorldEdit selections as a radius, and log your WorldEdit changes. 13 | [https://dev.bukkit.org/projects/worldedit](https://dev.bukkit.org/projects/worldedit) 14 |   15 | 16 | * **CoreProtect-Anti-Xray** 17 | Displays how many ores a player has destroyed in a specific time span. 18 | [https://dev.bukkit.org/bukkit-plugins/coreprotect-anti-xray/](https://dev.bukkit.org/bukkit-plugins/coreprotect-anti-xray/) 19 |   20 | 21 | * **CoreProtect TNT** 22 | The CoreProtect TNT extension adds logging for TNT and creeper explosion sources. 23 | [https://www.spigotmc.org/resources/coreprotect-tnt-log-tnt-creeper-explode-source.69609/](https://www.spigotmc.org/resources/coreprotect-tnt-log-tnt-creeper-explode-source.69609/) 24 |   25 | 26 | * **CoreProtect Time-Lapse** 27 | CPTL is an add-on tool for CoreProtect used to create a time-lapse from historical data. 28 | [https://modrinth.com/plugin/cptl](https://modrinth.com/plugin/cptl) 29 |   30 | 31 | ## Tools 32 | 33 | * **CoreProtect Lookup Web Interface** 34 | Search through your CoreProtect history with an easy-to-use interface. 35 | [https://www.spigotmc.org/resources/coreprotect-lookup-web-interface.28033/](https://www.spigotmc.org/resources/coreprotect-lookup-web-interface.28033/) 36 |   37 | 38 | * **Watson** 39 | Watson is a client side Minecraft mod that displays CoreProtect logs in 3D. 40 | [https://github.com/vacla/Watson](https://github.com/vacla/Watson) 41 |   42 | 43 | 44 | --- 45 | 46 | Have you created a plugin that's compatible with CoreProtect? 47 | Let us know to have it added to this list! 48 | 49 | --- 50 | -------------------------------------------------------------------------------- /mkdocs.yml: -------------------------------------------------------------------------------- 1 | site_name: CoreProtect Documentation 2 | site_url: https://docs.coreprotect.net 3 | theme: readthedocs 4 | repo_url: https://github.com/PlayPro/CoreProtect 5 | docs_dir: 'docs' 6 | extra_css: 7 | - css/extra.css -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | mkdocs==1.3.1 -------------------------------------------------------------------------------- /src/main/java/net/coreprotect/CoreProtect.java: -------------------------------------------------------------------------------- 1 | package net.coreprotect; 2 | 3 | import java.io.File; 4 | 5 | import org.bukkit.plugin.java.JavaPlugin; 6 | 7 | import net.coreprotect.config.ConfigHandler; 8 | import net.coreprotect.language.Phrase; 9 | import net.coreprotect.services.PluginInitializationService; 10 | import net.coreprotect.services.ShutdownService; 11 | import net.coreprotect.utility.Chat; 12 | 13 | /** 14 | * Main class for the CoreProtect plugin 15 | */ 16 | public final class CoreProtect extends JavaPlugin { 17 | 18 | private static CoreProtect instance; 19 | private boolean advancedChestsEnabled = false; 20 | 21 | /** 22 | * Get the instance of CoreProtect 23 | * 24 | * @return This CoreProtect instance 25 | */ 26 | public static CoreProtect getInstance() { 27 | return instance; 28 | } 29 | 30 | private final CoreProtectAPI api = new CoreProtectAPI(); 31 | 32 | /** 33 | * Get the CoreProtect API 34 | * 35 | * @return The CoreProtect API 36 | */ 37 | public CoreProtectAPI getAPI() { 38 | return api; 39 | } 40 | 41 | @Override 42 | public void onEnable() { 43 | // Set plugin instance and data folder path 44 | instance = this; 45 | ConfigHandler.path = this.getDataFolder().getPath() + File.separator; 46 | 47 | advancedChestsEnabled = getServer().getPluginManager().getPlugin("AdvancedChests") != null; 48 | // Initialize plugin using the initialization service 49 | boolean initialized = PluginInitializationService.initializePlugin(this); 50 | 51 | // Disable plugin if initialization failed 52 | if (!initialized) { 53 | Chat.console(Phrase.build(Phrase.ENABLE_FAILED, ConfigHandler.EDITION_NAME)); 54 | getServer().getPluginManager().disablePlugin(this); 55 | } 56 | } 57 | 58 | @Override 59 | public void onDisable() { 60 | ShutdownService.safeShutdown(this); 61 | } 62 | 63 | public boolean isAdvancedChestsEnabled() { 64 | return advancedChestsEnabled; 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /src/main/java/net/coreprotect/bukkit/Bukkit_v1_18.java: -------------------------------------------------------------------------------- 1 | package net.coreprotect.bukkit; 2 | 3 | import org.bukkit.inventory.ItemStack; 4 | import org.bukkit.inventory.MerchantRecipe; 5 | 6 | /** 7 | * Bukkit adapter implementation for Minecraft 1.18. 8 | * Provides version-specific implementations for the BukkitInterface 9 | * to handle features introduced in the 1.18 update. 10 | */ 11 | public class Bukkit_v1_18 extends Bukkit_v1_17 { 12 | 13 | /** 14 | * Flag to track whether the MerchantRecipe.adjust() method is available. 15 | * This is initialized on first use and prevents repeated reflection checks. 16 | * - null: Not yet checked 17 | * - true: Method exists and should be used 18 | * - false: Method doesn't exist or failed, fallback to parent implementation 19 | */ 20 | private Boolean hasAdjustMethod = null; 21 | 22 | /** 23 | * Adjusts an ingredient in a merchant recipe for version 1.18+. 24 | * This handles changes to the MerchantRecipe API introduced in Bukkit 1.18.1. 25 | * 26 | * @param recipe 27 | * The merchant recipe 28 | * @param itemStack 29 | * The item stack to adjust 30 | * @return The adjusted item stack, or null if adjustment not supported or fails 31 | */ 32 | @Override 33 | public ItemStack adjustIngredient(MerchantRecipe recipe, ItemStack itemStack) { 34 | if (itemStack == null) { 35 | return null; 36 | } 37 | 38 | try { 39 | // First-time detection of adjust method availability 40 | if (hasAdjustMethod == null) { 41 | hasAdjustMethod = true; 42 | // Test if the adjust method exists using reflection 43 | MerchantRecipe.class.getMethod("adjust", ItemStack.class); // Bukkit 1.18.1+ 44 | } 45 | // Skip if we've already determined the method isn't available 46 | else if (Boolean.FALSE.equals(hasAdjustMethod)) { 47 | return super.adjustIngredient(recipe, itemStack); 48 | } 49 | 50 | // Create a clone to avoid modifying the original itemStack 51 | ItemStack adjustedStack = itemStack.clone(); 52 | recipe.adjust(adjustedStack); 53 | return adjustedStack; 54 | } 55 | catch (Exception e) { 56 | // Method doesn't exist or failed, mark it for future calls 57 | hasAdjustMethod = false; 58 | return super.adjustIngredient(recipe, itemStack); 59 | } 60 | } 61 | 62 | } 63 | -------------------------------------------------------------------------------- /src/main/java/net/coreprotect/command/ApplyCommand.java: -------------------------------------------------------------------------------- 1 | package net.coreprotect.command; 2 | 3 | import java.util.List; 4 | 5 | import org.bukkit.Location; 6 | import org.bukkit.command.Command; 7 | import org.bukkit.command.CommandSender; 8 | 9 | import net.coreprotect.config.ConfigHandler; 10 | import net.coreprotect.language.Phrase; 11 | import net.coreprotect.language.Selector; 12 | import net.coreprotect.utility.Chat; 13 | import net.coreprotect.utility.Color; 14 | 15 | public class ApplyCommand { 16 | protected static void runCommand(CommandSender user, Command command, boolean permission, String[] args) { 17 | try { 18 | if (ConfigHandler.lastRollback.get(user.getName()) != null) { 19 | List list = ConfigHandler.lastRollback.get(user.getName()); 20 | long startTime = (Long) list.get(0); 21 | long endTime = (Long) list.get(1); 22 | args = (String[]) list.get(2); 23 | Location location = (Location) list.get(3); 24 | boolean valid = false; 25 | for (int i = 0; i < args.length; i++) { 26 | if (args[i].equals("#preview")) { 27 | valid = true; 28 | args[i] = args[i].replaceAll("#preview", ""); 29 | } 30 | } 31 | if (!valid) { 32 | Chat.sendMessage(user, Color.DARK_AQUA + "CoreProtect " + Color.WHITE + "- " + Phrase.build(Phrase.NO_ROLLBACK, Selector.FIRST)); 33 | } 34 | else { 35 | ConfigHandler.lastRollback.remove(user.getName()); 36 | RollbackRestoreCommand.runCommand(user, command, permission, args, location, startTime, endTime); 37 | } 38 | } 39 | else { 40 | Chat.sendMessage(user, Color.DARK_AQUA + "CoreProtect " + Color.WHITE + "- " + Phrase.build(Phrase.NO_ROLLBACK, Selector.FIRST)); 41 | } 42 | } 43 | catch (Exception e) { 44 | e.printStackTrace(); 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/net/coreprotect/command/CancelCommand.java: -------------------------------------------------------------------------------- 1 | package net.coreprotect.command; 2 | 3 | import java.util.List; 4 | 5 | import org.bukkit.Location; 6 | import org.bukkit.command.Command; 7 | import org.bukkit.command.CommandSender; 8 | 9 | import net.coreprotect.config.ConfigHandler; 10 | import net.coreprotect.language.Phrase; 11 | import net.coreprotect.language.Selector; 12 | import net.coreprotect.utility.Chat; 13 | import net.coreprotect.utility.Color; 14 | 15 | public class CancelCommand { 16 | protected static void runCommand(CommandSender user, Command command, boolean permission, String[] args) { 17 | try { 18 | if (ConfigHandler.lastRollback.get(user.getName()) != null) { 19 | List list = ConfigHandler.lastRollback.get(user.getName()); 20 | long startTime = (Long) list.get(0); 21 | long endTime = (Long) list.get(1); 22 | args = (String[]) list.get(2); 23 | Location location = (Location) list.get(3); 24 | boolean valid = false; 25 | for (int i = 0; i < args.length; i++) { 26 | if (args[i].equals("#preview")) { 27 | valid = true; 28 | args[i] = args[i].replaceAll("#preview", "#preview_cancel"); 29 | } 30 | } 31 | if (!valid) { 32 | Chat.sendMessage(user, Color.DARK_AQUA + "CoreProtect " + Color.WHITE + "- " + Phrase.build(Phrase.NO_ROLLBACK, Selector.FIRST)); 33 | } 34 | else { 35 | ConfigHandler.lastRollback.remove(user.getName()); 36 | RollbackRestoreCommand.runCommand(user, command, permission, args, location, startTime, endTime); 37 | } 38 | } 39 | else { 40 | Chat.sendMessage(user, Color.DARK_AQUA + "CoreProtect " + Color.WHITE + "- " + Phrase.build(Phrase.NO_ROLLBACK, Selector.FIRST)); 41 | } 42 | } 43 | catch (Exception e) { 44 | e.printStackTrace(); 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/net/coreprotect/command/InspectCommand.java: -------------------------------------------------------------------------------- 1 | package net.coreprotect.command; 2 | 3 | import org.bukkit.command.CommandSender; 4 | 5 | import net.coreprotect.config.ConfigHandler; 6 | import net.coreprotect.language.Phrase; 7 | import net.coreprotect.language.Selector; 8 | import net.coreprotect.utility.Chat; 9 | import net.coreprotect.utility.Color; 10 | 11 | public class InspectCommand { 12 | protected static void runCommand(CommandSender player, boolean permission, String[] args) { 13 | if (permission) { 14 | 15 | int command = -1; 16 | ConfigHandler.inspecting.putIfAbsent(player.getName(), false); 17 | 18 | if (args.length > 1) { 19 | String action = args[1]; 20 | if (action.equalsIgnoreCase("on")) { 21 | command = 1; 22 | } 23 | else if (action.equalsIgnoreCase("off")) { 24 | command = 0; 25 | } 26 | } 27 | 28 | if (!ConfigHandler.inspecting.get(player.getName())) { 29 | if (command == 0) { 30 | Chat.sendMessage(player, Color.DARK_AQUA + "CoreProtect " + Color.WHITE + "- " + Phrase.build(Phrase.INSPECTOR_ERROR, Selector.SECOND)); // already disabled 31 | } 32 | else { 33 | Chat.sendMessage(player, Color.DARK_AQUA + "CoreProtect " + Color.WHITE + "- " + Phrase.build(Phrase.INSPECTOR_TOGGLED, Selector.FIRST)); // now enabled 34 | ConfigHandler.inspecting.put(player.getName(), true); 35 | } 36 | } 37 | else { 38 | if (command == 1) { 39 | Chat.sendMessage(player, Color.DARK_AQUA + "CoreProtect " + Color.WHITE + "- " + Phrase.build(Phrase.INSPECTOR_ERROR, Selector.FIRST)); // already enabled 40 | } 41 | else { 42 | Chat.sendMessage(player, Color.DARK_AQUA + "CoreProtect " + Color.WHITE + "- " + Phrase.build(Phrase.INSPECTOR_TOGGLED, Selector.SECOND)); // now disabled 43 | ConfigHandler.inspecting.put(player.getName(), false); 44 | } 45 | } 46 | 47 | } 48 | else { 49 | Chat.sendMessage(player, Color.DARK_AQUA + "CoreProtect " + Color.WHITE + "- " + Phrase.build(Phrase.NO_PERMISSION)); 50 | } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/main/java/net/coreprotect/command/NetworkDebugCommand.java: -------------------------------------------------------------------------------- 1 | package net.coreprotect.command; 2 | 3 | import org.bukkit.command.CommandSender; 4 | 5 | import net.coreprotect.config.Config; 6 | import net.coreprotect.language.Phrase; 7 | import net.coreprotect.listener.channel.PluginChannelListener; 8 | import net.coreprotect.utility.Chat; 9 | import net.coreprotect.utility.Color; 10 | 11 | public class NetworkDebugCommand { 12 | protected static void runCommand(CommandSender player, boolean permission, String[] args) { 13 | if (!permission || !Config.getGlobal().NETWORK_DEBUG) { 14 | Chat.sendMessage(player, Color.DARK_AQUA + "CoreProtect " + Color.WHITE + "- " + Phrase.build(Phrase.NO_PERMISSION)); 15 | return; 16 | } 17 | 18 | try { 19 | PluginChannelListener.getInstance().sendTest(player, args.length == 2 ? args[1] : ""); 20 | } 21 | catch (Exception e) { 22 | e.printStackTrace(); 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/net/coreprotect/command/ReloadCommand.java: -------------------------------------------------------------------------------- 1 | package net.coreprotect.command; 2 | 3 | import org.bukkit.command.CommandSender; 4 | 5 | import net.coreprotect.config.ConfigHandler; 6 | import net.coreprotect.consumer.Consumer; 7 | import net.coreprotect.language.Phrase; 8 | import net.coreprotect.thread.NetworkHandler; 9 | import net.coreprotect.utility.Chat; 10 | import net.coreprotect.utility.Color; 11 | 12 | public class ReloadCommand { 13 | protected static void runCommand(final CommandSender player, boolean permission, String[] args) { 14 | if (permission) { 15 | if (ConfigHandler.converterRunning) { 16 | Chat.sendMessage(player, Color.DARK_AQUA + "CoreProtect " + Color.WHITE + "- " + Phrase.build(Phrase.UPGRADE_IN_PROGRESS)); 17 | return; 18 | } 19 | if (ConfigHandler.purgeRunning) { 20 | Chat.sendMessage(player, Color.DARK_AQUA + "CoreProtect " + Color.WHITE + "- " + Phrase.build(Phrase.PURGE_IN_PROGRESS)); 21 | return; 22 | } 23 | if (ConfigHandler.lookupThrottle.get(player.getName()) != null) { 24 | Object[] lookupThrottle = ConfigHandler.lookupThrottle.get(player.getName()); 25 | if ((boolean) lookupThrottle[0] || ((System.currentTimeMillis() - (long) lookupThrottle[1])) < 100) { 26 | Chat.sendMessage(player, Color.DARK_AQUA + "CoreProtect " + Color.WHITE + "- " + Phrase.build(Phrase.DATABASE_BUSY)); 27 | return; 28 | } 29 | } 30 | ConfigHandler.lookupThrottle.put(player.getName(), new Object[] { true, System.currentTimeMillis() }); 31 | 32 | class BasicThread implements Runnable { 33 | @Override 34 | public void run() { 35 | try { 36 | if (Consumer.isPaused) { 37 | Chat.sendMessage(player, Color.DARK_AQUA + "CoreProtect " + Color.WHITE + "- " + Phrase.build(Phrase.RELOAD_STARTED)); 38 | } 39 | while (Consumer.isPaused) { 40 | Thread.sleep(1); 41 | } 42 | Consumer.isPaused = true; 43 | 44 | ConfigHandler.performInitialization(false); 45 | Chat.sendMessage(player, Color.DARK_AQUA + "CoreProtect " + Color.WHITE + "- " + Phrase.build(Phrase.RELOAD_SUCCESS)); 46 | 47 | Thread networkHandler = new Thread(new NetworkHandler(false, false)); 48 | networkHandler.start(); 49 | } 50 | catch (Exception e) { 51 | e.printStackTrace(); 52 | } 53 | 54 | Consumer.isPaused = false; 55 | ConfigHandler.lookupThrottle.put(player.getName(), new Object[] { false, System.currentTimeMillis() }); 56 | } 57 | } 58 | Runnable runnable = new BasicThread(); 59 | Thread thread = new Thread(runnable); 60 | thread.start(); 61 | } 62 | else { 63 | Chat.sendMessage(player, Color.DARK_AQUA + "CoreProtect " + Color.WHITE + "- " + Phrase.build(Phrase.NO_PERMISSION)); 64 | } 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /src/main/java/net/coreprotect/command/UndoCommand.java: -------------------------------------------------------------------------------- 1 | package net.coreprotect.command; 2 | 3 | import java.util.List; 4 | 5 | import org.bukkit.Location; 6 | import org.bukkit.command.Command; 7 | import org.bukkit.command.CommandSender; 8 | 9 | import net.coreprotect.config.ConfigHandler; 10 | import net.coreprotect.language.Phrase; 11 | import net.coreprotect.language.Selector; 12 | import net.coreprotect.utility.Chat; 13 | import net.coreprotect.utility.Color; 14 | 15 | public class UndoCommand { 16 | protected static void runCommand(CommandSender user, Command command, boolean permission, String[] args) { 17 | try { 18 | if (ConfigHandler.lastRollback.get(user.getName()) != null) { 19 | List list = ConfigHandler.lastRollback.get(user.getName()); 20 | long startTime = (Long) list.get(0); 21 | long endTime = (Long) list.get(1); 22 | args = (String[]) list.get(2); 23 | Location location = (Location) list.get(3); 24 | for (String arg : args) { 25 | if (arg.equals("#preview")) { 26 | CancelCommand.runCommand(user, command, permission, args); 27 | return; 28 | } 29 | } 30 | boolean valid = true; 31 | if (args[0].equals("rollback") || args[0].equals("rb") || args[0].equals("ro")) { 32 | args[0] = "restore"; 33 | } 34 | else if (args[0].equals("restore") || args[0].equals("rs") || args[0].equals("re")) { 35 | args[0] = "rollback"; 36 | } 37 | else { 38 | valid = false; 39 | } 40 | if (valid) { 41 | ConfigHandler.lastRollback.remove(user.getName()); 42 | RollbackRestoreCommand.runCommand(user, command, permission, args, location, startTime, endTime); 43 | } 44 | } 45 | else { 46 | Chat.sendMessage(user, Color.DARK_AQUA + "CoreProtect " + Color.WHITE + "- " + Phrase.build(Phrase.NO_ROLLBACK, Selector.SECOND)); 47 | } 48 | } 49 | catch (Exception e) { 50 | e.printStackTrace(); 51 | } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/main/java/net/coreprotect/command/WorldEditHandler.java: -------------------------------------------------------------------------------- 1 | package net.coreprotect.command; 2 | 3 | import org.bukkit.command.CommandSender; 4 | import org.bukkit.entity.Player; 5 | 6 | import com.sk89q.worldedit.LocalSession; 7 | import com.sk89q.worldedit.bukkit.WorldEditPlugin; 8 | import com.sk89q.worldedit.math.BlockVector3; 9 | import com.sk89q.worldedit.regions.Region; 10 | import com.sk89q.worldedit.world.World; 11 | 12 | import net.coreprotect.worldedit.WorldEditLogger; 13 | 14 | public class WorldEditHandler { 15 | 16 | protected static Integer[] runWorldEditCommand(CommandSender user) { 17 | Integer[] result = null; 18 | try { 19 | WorldEditPlugin worldEdit = WorldEditLogger.getWorldEdit(user.getServer()); 20 | if (worldEdit != null && user instanceof Player) { 21 | LocalSession session = worldEdit.getSession((Player) user); 22 | World world = session.getSelectionWorld(); 23 | if (world != null) { 24 | Region region = session.getSelection(world); 25 | if (region != null && world.getName().equals(((Player) user).getWorld().getName())) { 26 | BlockVector3 block = region.getMinimumPoint(); 27 | int x = block.getBlockX(); 28 | int y = block.getBlockY(); 29 | int z = block.getBlockZ(); 30 | int width = region.getWidth(); 31 | int height = region.getHeight(); 32 | int length = region.getLength(); 33 | int max = width; 34 | if (height > max) { 35 | max = height; 36 | } 37 | if (length > max) { 38 | max = length; 39 | } 40 | int xMin = x; 41 | int xMax = x + (width - 1); 42 | int yMin = y; 43 | int yMax = y + (height - 1); 44 | int zMin = z; 45 | int zMax = z + (length - 1); 46 | result = new Integer[] { max, xMin, xMax, yMin, yMax, zMin, zMax, 1 }; 47 | } 48 | } 49 | } 50 | } 51 | catch (Exception e) { 52 | e.printStackTrace(); 53 | } 54 | return result; 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/main/java/net/coreprotect/command/lookup/ChestTransactionLookupThread.java: -------------------------------------------------------------------------------- 1 | package net.coreprotect.command.lookup; 2 | 3 | import java.sql.Connection; 4 | import java.sql.Statement; 5 | import java.util.List; 6 | 7 | import org.bukkit.Location; 8 | import org.bukkit.command.Command; 9 | import org.bukkit.command.CommandSender; 10 | 11 | import net.coreprotect.config.ConfigHandler; 12 | import net.coreprotect.database.Database; 13 | import net.coreprotect.database.lookup.ChestTransactionLookup; 14 | import net.coreprotect.language.Phrase; 15 | import net.coreprotect.utility.Chat; 16 | import net.coreprotect.utility.Color; 17 | 18 | public class ChestTransactionLookupThread implements Runnable { 19 | private final CommandSender player; 20 | private final Command command; 21 | private final Location location; 22 | private final int page; 23 | private final int limit; 24 | 25 | public ChestTransactionLookupThread(CommandSender player, Command command, Location location, int page, int limit) { 26 | this.player = player; 27 | this.command = command; 28 | this.location = location; 29 | this.page = page; 30 | this.limit = limit; 31 | } 32 | 33 | @Override 34 | public void run() { 35 | try (Connection connection = Database.getConnection(true)) { 36 | ConfigHandler.lookupThrottle.put(player.getName(), new Object[] { true, System.currentTimeMillis() }); 37 | if (connection != null) { 38 | Statement statement = connection.createStatement(); 39 | List blockData = ChestTransactionLookup.performLookup(command.getName(), statement, location, player, page, limit, false); 40 | for (String data : blockData) { 41 | Chat.sendComponent(player, data); 42 | } 43 | statement.close(); 44 | } 45 | else { 46 | Chat.sendMessage(player, Color.DARK_AQUA + "CoreProtect " + Color.WHITE + "- " + Phrase.build(Phrase.DATABASE_BUSY)); 47 | } 48 | } 49 | catch (Exception e) { 50 | e.printStackTrace(); 51 | } 52 | 53 | ConfigHandler.lookupThrottle.put(player.getName(), new Object[] { false, System.currentTimeMillis() }); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/main/java/net/coreprotect/consumer/process/ArtInsertProcess.java: -------------------------------------------------------------------------------- 1 | package net.coreprotect.consumer.process; 2 | 3 | import java.sql.PreparedStatement; 4 | import java.sql.Statement; 5 | 6 | import net.coreprotect.config.ConfigHandler; 7 | import net.coreprotect.database.statement.MaterialStatement; 8 | import net.coreprotect.language.Phrase; 9 | import net.coreprotect.language.Selector; 10 | import net.coreprotect.utility.Chat; 11 | 12 | class ArtInsertProcess { 13 | 14 | static void process(PreparedStatement preparedStmt, Statement statement, int batchCount, Object name, int materialId) { 15 | if (name instanceof String) { 16 | String query = "SELECT id FROM " + ConfigHandler.prefix + "art_map WHERE id = '" + materialId + "' LIMIT 0, 1"; 17 | boolean hasMaterial = MaterialStatement.hasMaterial(statement, query); 18 | if (!hasMaterial) { 19 | MaterialStatement.insert(preparedStmt, batchCount, materialId, (String) name); 20 | 21 | // validate ID maps to ensure mapping wasn't reloaded from database prior to this insertion completing 22 | ConfigHandler.art.put((String) name, materialId); 23 | ConfigHandler.artReversed.put(materialId, (String) name); 24 | if (materialId > ConfigHandler.artId) { 25 | ConfigHandler.artId = materialId; 26 | } 27 | } 28 | else { 29 | Chat.console(Phrase.build(Phrase.CACHE_ERROR, "art")); 30 | Chat.console(Phrase.build(Phrase.CACHE_RELOAD, Selector.FIRST)); 31 | ConfigHandler.loadTypes(statement); 32 | } 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/net/coreprotect/consumer/process/BlockBreakProcess.java: -------------------------------------------------------------------------------- 1 | package net.coreprotect.consumer.process; 2 | 3 | import java.sql.PreparedStatement; 4 | import java.util.List; 5 | 6 | import org.bukkit.Material; 7 | import org.bukkit.block.BlockState; 8 | import org.bukkit.block.Skull; 9 | 10 | import net.coreprotect.database.logger.BlockBreakLogger; 11 | import net.coreprotect.database.logger.SkullBreakLogger; 12 | import net.coreprotect.utility.BlockUtils; 13 | import net.coreprotect.utility.MaterialUtils; 14 | 15 | class BlockBreakProcess { 16 | 17 | static void process(PreparedStatement preparedStmt, PreparedStatement preparedStmtSkulls, int batchCount, int processId, int id, Material blockType, int blockDataId, Material replaceType, int forceData, String user, Object object, String blockData) { 18 | if (object instanceof BlockState) { 19 | BlockState block = (BlockState) object; 20 | List meta = BlockUtils.processMeta(block); 21 | if (block instanceof Skull) { 22 | SkullBreakLogger.log(preparedStmt, preparedStmtSkulls, batchCount, user, block); 23 | } 24 | else { 25 | BlockBreakLogger.log(preparedStmt, batchCount, user, block.getLocation(), MaterialUtils.getBlockId(blockType), blockDataId, meta, block.getBlockData().getAsString(), blockData); 26 | } 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/net/coreprotect/consumer/process/BlockDataInsertProcess.java: -------------------------------------------------------------------------------- 1 | package net.coreprotect.consumer.process; 2 | 3 | import java.sql.PreparedStatement; 4 | import java.sql.Statement; 5 | 6 | import net.coreprotect.config.ConfigHandler; 7 | import net.coreprotect.database.statement.MaterialStatement; 8 | import net.coreprotect.language.Phrase; 9 | import net.coreprotect.language.Selector; 10 | import net.coreprotect.utility.Chat; 11 | 12 | class BlockDataInsertProcess { 13 | 14 | static void process(PreparedStatement preparedStmt, Statement statement, int batchCount, Object name, int materialId) { 15 | if (name instanceof String) { 16 | String query = "SELECT id FROM " + ConfigHandler.prefix + "blockdata_map WHERE id = '" + materialId + "' LIMIT 0, 1"; 17 | boolean hasMaterial = MaterialStatement.hasMaterial(statement, query); 18 | if (!hasMaterial) { 19 | MaterialStatement.insert(preparedStmt, batchCount, materialId, (String) name); 20 | 21 | // validate ID maps to ensure mapping wasn't reloaded from database prior to this insertion completing 22 | ConfigHandler.blockdata.put((String) name, materialId); 23 | ConfigHandler.blockdataReversed.put(materialId, (String) name); 24 | if (materialId > ConfigHandler.blockdataId) { 25 | ConfigHandler.blockdataId = materialId; 26 | } 27 | } 28 | else { 29 | Chat.console(Phrase.build(Phrase.CACHE_ERROR, "blockdata")); 30 | Chat.console(Phrase.build(Phrase.CACHE_RELOAD, Selector.FIRST)); 31 | ConfigHandler.loadTypes(statement); 32 | } 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/net/coreprotect/consumer/process/BlockPlaceProcess.java: -------------------------------------------------------------------------------- 1 | package net.coreprotect.consumer.process; 2 | 3 | import java.sql.PreparedStatement; 4 | import java.util.List; 5 | 6 | import org.bukkit.Material; 7 | import org.bukkit.block.BlockState; 8 | 9 | import net.coreprotect.database.logger.BlockPlaceLogger; 10 | import net.coreprotect.database.logger.SkullPlaceLogger; 11 | import net.coreprotect.utility.BlockUtils; 12 | import net.coreprotect.utility.MaterialUtils; 13 | 14 | class BlockPlaceProcess { 15 | 16 | static void process(PreparedStatement preparedStmt, PreparedStatement preparedStmtSkulls, int batchCount, Material blockType, int blockData, Material replaceType, int replaceData, int forceData, String user, Object object, String newBlockData, String replacedBlockData) { 17 | if (object instanceof BlockState) { 18 | BlockState block = (BlockState) object; 19 | List meta = BlockUtils.processMeta(block); 20 | if (blockType.equals(Material.SKELETON_SKULL) || blockType.equals(Material.SKELETON_WALL_SKULL) || blockType.equals(Material.WITHER_SKELETON_SKULL) || blockType.equals(Material.WITHER_SKELETON_WALL_SKULL) || blockType.equals(Material.ZOMBIE_HEAD) || blockType.equals(Material.ZOMBIE_WALL_HEAD) || blockType.equals(Material.PLAYER_HEAD) || blockType.equals(Material.PLAYER_WALL_HEAD) || blockType.equals(Material.CREEPER_HEAD) || blockType.equals(Material.CREEPER_WALL_HEAD) || blockType.equals(Material.DRAGON_HEAD) || blockType.equals(Material.DRAGON_WALL_HEAD)) { 21 | SkullPlaceLogger.log(preparedStmt, preparedStmtSkulls, batchCount, user, block, MaterialUtils.getBlockId(replaceType), replaceData); 22 | } 23 | else if (forceData == 1) { 24 | BlockPlaceLogger.log(preparedStmt, batchCount, user, block, MaterialUtils.getBlockId(replaceType), replaceData, blockType, blockData, true, meta, newBlockData, replacedBlockData); 25 | } 26 | else { 27 | BlockPlaceLogger.log(preparedStmt, batchCount, user, block, MaterialUtils.getBlockId(replaceType), replaceData, blockType, blockData, false, meta, newBlockData, replacedBlockData); 28 | } 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/net/coreprotect/consumer/process/ContainerBreakProcess.java: -------------------------------------------------------------------------------- 1 | package net.coreprotect.consumer.process; 2 | 3 | import java.sql.PreparedStatement; 4 | import java.util.Map; 5 | 6 | import org.bukkit.Location; 7 | import org.bukkit.Material; 8 | import org.bukkit.inventory.ItemStack; 9 | 10 | import net.coreprotect.consumer.Consumer; 11 | import net.coreprotect.database.logger.ContainerBreakLogger; 12 | 13 | class ContainerBreakProcess { 14 | 15 | static void process(PreparedStatement preparedStmt, int batchCount, int processId, int id, Material type, String user, Object object) { 16 | if (object instanceof Location) { 17 | Location location = (Location) object; 18 | Map containers = Consumer.consumerContainers.get(processId); 19 | if (containers.get(id) != null) { 20 | ItemStack[] container = containers.get(id); 21 | ContainerBreakLogger.log(preparedStmt, batchCount, user, location, type, container); 22 | containers.remove(id); 23 | } 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/net/coreprotect/consumer/process/EntityInsertProcess.java: -------------------------------------------------------------------------------- 1 | package net.coreprotect.consumer.process; 2 | 3 | import java.sql.PreparedStatement; 4 | import java.sql.Statement; 5 | 6 | import net.coreprotect.config.ConfigHandler; 7 | import net.coreprotect.database.statement.MaterialStatement; 8 | import net.coreprotect.language.Phrase; 9 | import net.coreprotect.language.Selector; 10 | import net.coreprotect.utility.Chat; 11 | 12 | class EntityInsertProcess { 13 | 14 | static void process(PreparedStatement preparedStmt, Statement statement, int batchCount, Object name, int materialId) { 15 | if (name instanceof String) { 16 | String query = "SELECT id FROM " + ConfigHandler.prefix + "entity_map WHERE id = '" + materialId + "' LIMIT 0, 1"; 17 | boolean hasMaterial = MaterialStatement.hasMaterial(statement, query); 18 | if (!hasMaterial) { 19 | MaterialStatement.insert(preparedStmt, batchCount, materialId, (String) name); 20 | 21 | // validate ID maps to ensure mapping wasn't reloaded from database prior to this insertion completing 22 | ConfigHandler.entities.put((String) name, materialId); 23 | ConfigHandler.entitiesReversed.put(materialId, (String) name); 24 | if (materialId > ConfigHandler.entityId) { 25 | ConfigHandler.entityId = materialId; 26 | } 27 | } 28 | else { 29 | Chat.console(Phrase.build(Phrase.CACHE_ERROR, "entity")); 30 | Chat.console(Phrase.build(Phrase.CACHE_RELOAD, Selector.FIRST)); 31 | ConfigHandler.loadTypes(statement); 32 | } 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/net/coreprotect/consumer/process/EntityKillProcess.java: -------------------------------------------------------------------------------- 1 | package net.coreprotect.consumer.process; 2 | 3 | import java.sql.PreparedStatement; 4 | import java.util.List; 5 | import java.util.Map; 6 | 7 | import org.bukkit.block.BlockState; 8 | import org.bukkit.entity.EntityType; 9 | 10 | import net.coreprotect.consumer.Consumer; 11 | import net.coreprotect.database.logger.EntityKillLogger; 12 | import net.coreprotect.utility.EntityUtils; 13 | import net.coreprotect.utility.Util; 14 | 15 | class EntityKillProcess { 16 | 17 | static void process(PreparedStatement preparedStmt, PreparedStatement preparedStmtEntities, int batchCount, int processId, int id, Object object, String user) { 18 | if (object instanceof Object[]) { 19 | BlockState block = (BlockState) ((Object[]) object)[0]; 20 | EntityType type = (EntityType) ((Object[]) object)[1]; 21 | Map> objectLists = Consumer.consumerObjectList.get(processId); 22 | if (objectLists.get(id) != null) { 23 | List objectList = objectLists.get(id); 24 | int entityId = EntityUtils.getEntityId(type); 25 | EntityKillLogger.log(preparedStmt, preparedStmtEntities, batchCount, user, block, objectList, entityId); 26 | objectLists.remove(id); 27 | } 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/net/coreprotect/consumer/process/EntitySpawnProcess.java: -------------------------------------------------------------------------------- 1 | package net.coreprotect.consumer.process; 2 | 3 | import java.sql.Statement; 4 | import java.util.List; 5 | 6 | import org.bukkit.block.BlockState; 7 | import org.bukkit.entity.EntityType; 8 | 9 | import net.coreprotect.config.ConfigHandler; 10 | import net.coreprotect.database.statement.EntityStatement; 11 | import net.coreprotect.utility.entity.EntityUtil; 12 | 13 | class EntitySpawnProcess { 14 | 15 | static void process(Statement statement, Object object, int rowId) { 16 | if (object instanceof Object[]) { 17 | BlockState block = (BlockState) ((Object[]) object)[0]; 18 | EntityType type = (EntityType) ((Object[]) object)[1]; 19 | String query = "SELECT data FROM " + ConfigHandler.prefix + "entity WHERE rowid='" + rowId + "' LIMIT 0, 1"; 20 | List data = EntityStatement.getData(statement, block, query); 21 | EntityUtil.spawnEntity(block, type, data); 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/net/coreprotect/consumer/process/ItemTransactionProcess.java: -------------------------------------------------------------------------------- 1 | package net.coreprotect.consumer.process; 2 | 3 | import java.sql.PreparedStatement; 4 | import java.util.Locale; 5 | 6 | import org.bukkit.Location; 7 | 8 | import net.coreprotect.config.ConfigHandler; 9 | import net.coreprotect.consumer.Queue; 10 | import net.coreprotect.database.logger.ItemLogger; 11 | 12 | class ItemTransactionProcess extends Queue { 13 | 14 | static void process(PreparedStatement preparedStmt, int batchCount, int processId, int id, int forceData, int time, int offset, String user, Object object) { 15 | if (object instanceof Location) { 16 | Location location = (Location) object; 17 | String loggingItemId = user.toLowerCase(Locale.ROOT) + "." + location.getBlockX() + "." + location.getBlockY() + "." + location.getBlockZ(); 18 | 19 | if (ConfigHandler.loggingItem.get(loggingItemId) != null) { 20 | int current_chest = ConfigHandler.loggingItem.get(loggingItemId); 21 | if (ConfigHandler.itemsPickup.get(loggingItemId) == null && ConfigHandler.itemsDrop.get(loggingItemId) == null && ConfigHandler.itemsThrown.get(loggingItemId) == null && ConfigHandler.itemsShot.get(loggingItemId) == null && ConfigHandler.itemsBreak.get(loggingItemId) == null && ConfigHandler.itemsDestroy.get(loggingItemId) == null && ConfigHandler.itemsCreate.get(loggingItemId) == null && ConfigHandler.itemsSell.get(loggingItemId) == null && ConfigHandler.itemsBuy.get(loggingItemId) == null) { 22 | return; 23 | } 24 | if (current_chest == forceData) { 25 | int currentTime = (int) (System.currentTimeMillis() / 1000L); 26 | if (currentTime > time) { 27 | ItemLogger.log(preparedStmt, batchCount, location, offset, user); 28 | ConfigHandler.itemsPickup.remove(loggingItemId); 29 | ConfigHandler.itemsDrop.remove(loggingItemId); 30 | ConfigHandler.itemsThrown.remove(loggingItemId); 31 | ConfigHandler.itemsShot.remove(loggingItemId); 32 | ConfigHandler.itemsBreak.remove(loggingItemId); 33 | ConfigHandler.itemsDestroy.remove(loggingItemId); 34 | ConfigHandler.itemsCreate.remove(loggingItemId); 35 | ConfigHandler.itemsSell.remove(loggingItemId); 36 | ConfigHandler.itemsBuy.remove(loggingItemId); 37 | ConfigHandler.loggingItem.remove(loggingItemId); 38 | } 39 | else { 40 | Queue.queueItemTransaction(user, location, time, offset, forceData); 41 | } 42 | } 43 | } 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/net/coreprotect/consumer/process/MaterialInsertProcess.java: -------------------------------------------------------------------------------- 1 | package net.coreprotect.consumer.process; 2 | 3 | import java.sql.PreparedStatement; 4 | import java.sql.Statement; 5 | 6 | import net.coreprotect.config.ConfigHandler; 7 | import net.coreprotect.database.statement.MaterialStatement; 8 | import net.coreprotect.language.Phrase; 9 | import net.coreprotect.language.Selector; 10 | import net.coreprotect.utility.Chat; 11 | 12 | class MaterialInsertProcess { 13 | 14 | static void process(PreparedStatement preparedStmt, Statement statement, int batchCount, Object name, int materialId) { 15 | if (name instanceof String) { 16 | String query = "SELECT id FROM " + ConfigHandler.prefix + "material_map WHERE id = '" + materialId + "' LIMIT 0, 1"; 17 | boolean hasMaterial = MaterialStatement.hasMaterial(statement, query); 18 | if (!hasMaterial) { 19 | MaterialStatement.insert(preparedStmt, batchCount, materialId, (String) name); 20 | 21 | // validate ID maps to ensure mapping wasn't reloaded from database prior to this insertion completing 22 | ConfigHandler.materials.put((String) name, materialId); 23 | ConfigHandler.materialsReversed.put(materialId, (String) name); 24 | if (materialId > ConfigHandler.materialId) { 25 | ConfigHandler.materialId = materialId; 26 | } 27 | } 28 | else { 29 | Chat.console(Phrase.build(Phrase.CACHE_ERROR, "material")); 30 | Chat.console(Phrase.build(Phrase.CACHE_RELOAD, Selector.FIRST)); 31 | ConfigHandler.loadTypes(statement); 32 | } 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/net/coreprotect/consumer/process/NaturalBlockBreakProcess.java: -------------------------------------------------------------------------------- 1 | package net.coreprotect.consumer.process; 2 | 3 | import java.sql.PreparedStatement; 4 | import java.sql.Statement; 5 | import java.util.List; 6 | import java.util.Map; 7 | 8 | import org.bukkit.Material; 9 | import org.bukkit.block.BlockState; 10 | 11 | import net.coreprotect.consumer.Consumer; 12 | import net.coreprotect.database.Lookup; 13 | import net.coreprotect.database.logger.BlockBreakLogger; 14 | import net.coreprotect.utility.MaterialUtils; 15 | import net.coreprotect.utility.Util; 16 | 17 | class NaturalBlockBreakProcess { 18 | 19 | static void process(Statement statement, PreparedStatement preparedStmt, int batchCount, int processId, int id, String user, Object object, Material blockType, int blockData, String overrideData) { 20 | if (object instanceof BlockState) { 21 | BlockState block = (BlockState) object; 22 | Map> blockLists = Consumer.consumerBlockList.get(processId); 23 | if (blockLists.get(id) != null) { 24 | List blockStateList = blockLists.get(id); 25 | for (BlockState blockState : blockStateList) { 26 | String removed = Lookup.whoRemovedCache(blockState); 27 | if (removed.length() > 0) { 28 | user = removed; 29 | } 30 | } 31 | blockLists.remove(id); 32 | BlockBreakLogger.log(preparedStmt, batchCount, user, block.getLocation(), MaterialUtils.getBlockId(blockType), blockData, null, block.getBlockData().getAsString(), overrideData); 33 | } 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/net/coreprotect/consumer/process/PlayerChatProcess.java: -------------------------------------------------------------------------------- 1 | package net.coreprotect.consumer.process; 2 | 3 | import java.sql.PreparedStatement; 4 | import java.util.Map; 5 | 6 | import org.bukkit.Location; 7 | 8 | import net.coreprotect.consumer.Consumer; 9 | import net.coreprotect.database.logger.ChatLogger; 10 | 11 | class PlayerChatProcess { 12 | 13 | static void process(PreparedStatement preparedStmt, int batchCount, int processId, int id, Object object, String user) { 14 | if (!(object instanceof Object[])) { 15 | return; 16 | } 17 | 18 | Object[] data = (Object[]) object; 19 | if (data[1] instanceof Location) { 20 | Map strings = Consumer.consumerStrings.get(processId); 21 | if (strings.get(id) != null) { 22 | String message = strings.get(id); 23 | Long timestamp = (Long) data[0]; 24 | Location location = (Location) data[1]; 25 | ChatLogger.log(preparedStmt, batchCount, timestamp, location, user, message); 26 | strings.remove(id); 27 | } 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/net/coreprotect/consumer/process/PlayerCommandProcess.java: -------------------------------------------------------------------------------- 1 | package net.coreprotect.consumer.process; 2 | 3 | import java.sql.PreparedStatement; 4 | import java.util.Map; 5 | 6 | import org.bukkit.Location; 7 | 8 | import net.coreprotect.consumer.Consumer; 9 | import net.coreprotect.database.logger.CommandLogger; 10 | 11 | class PlayerCommandProcess { 12 | 13 | static void process(PreparedStatement preparedStmt, int batchCount, int processId, int id, Object object, String user) { 14 | if (!(object instanceof Object[])) { 15 | return; 16 | } 17 | 18 | Object[] data = (Object[]) object; 19 | if (data[1] instanceof Location) { 20 | Map strings = Consumer.consumerStrings.get(processId); 21 | if (strings.get(id) != null) { 22 | String message = strings.get(id); 23 | Long timestamp = (Long) data[0]; 24 | Location location = (Location) data[1]; 25 | CommandLogger.log(preparedStmt, batchCount, timestamp, location, user, message); 26 | strings.remove(id); 27 | } 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/net/coreprotect/consumer/process/PlayerInteractionProcess.java: -------------------------------------------------------------------------------- 1 | package net.coreprotect.consumer.process; 2 | 3 | import java.sql.PreparedStatement; 4 | 5 | import org.bukkit.Material; 6 | import org.bukkit.block.BlockState; 7 | 8 | import net.coreprotect.database.logger.PlayerInteractLogger; 9 | 10 | class PlayerInteractionProcess { 11 | 12 | static void process(PreparedStatement preparedStmt, int batchCount, String user, Object object, Material type) { 13 | if (object instanceof BlockState) { 14 | BlockState block = (BlockState) object; 15 | PlayerInteractLogger.log(preparedStmt, batchCount, user, block, type); 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/net/coreprotect/consumer/process/PlayerKillProcess.java: -------------------------------------------------------------------------------- 1 | package net.coreprotect.consumer.process; 2 | 3 | import java.sql.PreparedStatement; 4 | 5 | import org.bukkit.block.BlockState; 6 | 7 | import net.coreprotect.database.logger.PlayerKillLogger; 8 | 9 | class PlayerKillProcess { 10 | 11 | static void process(PreparedStatement preparedStmt, int batchCount, int id, Object object, String user) { 12 | if (object instanceof Object[]) { 13 | BlockState block = (BlockState) ((Object[]) object)[0]; 14 | String player = (String) ((Object[]) object)[1]; 15 | PlayerKillLogger.log(preparedStmt, batchCount, user, block, player); 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/net/coreprotect/consumer/process/PlayerLoginProcess.java: -------------------------------------------------------------------------------- 1 | package net.coreprotect.consumer.process; 2 | 3 | import java.sql.Connection; 4 | import java.sql.PreparedStatement; 5 | import java.util.Map; 6 | 7 | import org.bukkit.Location; 8 | 9 | import net.coreprotect.consumer.Consumer; 10 | import net.coreprotect.database.logger.PlayerSessionLogger; 11 | import net.coreprotect.database.logger.UsernameLogger; 12 | 13 | class PlayerLoginProcess { 14 | 15 | static void process(Connection connection, PreparedStatement preparedStmt, int batchCount, int processId, int id, Object object, int configSessions, int configUsernames, int time, String user) { 16 | if (object instanceof Location) { 17 | Map strings = Consumer.consumerStrings.get(processId); 18 | if (strings.get(id) != null) { 19 | String uuid = strings.get(id); 20 | Location location = (Location) object; 21 | UsernameLogger.log(connection, user, uuid, configUsernames, time); 22 | if (configSessions == 1) { 23 | PlayerSessionLogger.log(preparedStmt, batchCount, user, location, time, 1); 24 | } 25 | strings.remove(id); 26 | } 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/net/coreprotect/consumer/process/PlayerLogoutProcess.java: -------------------------------------------------------------------------------- 1 | package net.coreprotect.consumer.process; 2 | 3 | import java.sql.PreparedStatement; 4 | 5 | import org.bukkit.Location; 6 | 7 | import net.coreprotect.database.logger.PlayerSessionLogger; 8 | 9 | class PlayerLogoutProcess { 10 | 11 | static void process(PreparedStatement preparedStmt, int batchCount, Object object, int time, String user) { 12 | if (object instanceof Location) { 13 | Location location = (Location) object; 14 | PlayerSessionLogger.log(preparedStmt, batchCount, user, location, time, 0); 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/net/coreprotect/consumer/process/RollbackUpdateProcess.java: -------------------------------------------------------------------------------- 1 | package net.coreprotect.consumer.process; 2 | 3 | import java.sql.Statement; 4 | import java.util.List; 5 | import java.util.Map; 6 | 7 | import net.coreprotect.consumer.Consumer; 8 | import net.coreprotect.database.Database; 9 | import net.coreprotect.utility.MaterialUtils; 10 | 11 | class RollbackUpdateProcess { 12 | 13 | static void process(Statement statement, int processId, int id, int action, int table) { 14 | Map> updateLists = Consumer.consumerObjectArrayList.get(processId); 15 | if (updateLists.get(id) != null) { 16 | List list = updateLists.get(id); 17 | for (Object[] listRow : list) { 18 | long rowid = (Long) listRow[0]; 19 | int rolledBack = (Integer) listRow[9]; 20 | if (MaterialUtils.rolledBack(rolledBack, (table == 2 || table == 3 || table == 4)) == action) { // 1 = restore, 0 = rollback 21 | Database.performUpdate(statement, rowid, rolledBack, table); 22 | } 23 | } 24 | updateLists.remove(id); 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/net/coreprotect/consumer/process/SignTextProcess.java: -------------------------------------------------------------------------------- 1 | package net.coreprotect.consumer.process; 2 | 3 | import java.sql.PreparedStatement; 4 | import java.util.Map; 5 | 6 | import org.bukkit.Location; 7 | 8 | import net.coreprotect.consumer.Consumer; 9 | import net.coreprotect.database.logger.SignTextLogger; 10 | 11 | class SignTextProcess { 12 | 13 | static void process(PreparedStatement preparedStmt, int batchCount, int processId, int id, int forceData, String user, Object object, int action, int color) { 14 | if (object instanceof Location) { 15 | Location location = (Location) object; 16 | Map signs = Consumer.consumerSigns.get(processId); 17 | if (signs.get(id) != null) { 18 | Object[] SIGN_DATA = signs.get(id); 19 | SignTextLogger.log(preparedStmt, batchCount, user, location, action, color, (Integer) SIGN_DATA[0], (Integer) SIGN_DATA[1], (Boolean) SIGN_DATA[2], (Boolean) SIGN_DATA[3], (String) SIGN_DATA[4], (String) SIGN_DATA[5], (String) SIGN_DATA[6], (String) SIGN_DATA[7], (String) SIGN_DATA[8], (String) SIGN_DATA[9], (String) SIGN_DATA[10], (String) SIGN_DATA[11], forceData); 20 | signs.remove(id); 21 | } 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/net/coreprotect/consumer/process/SignUpdateProcess.java: -------------------------------------------------------------------------------- 1 | package net.coreprotect.consumer.process; 2 | 3 | import java.sql.Statement; 4 | import java.util.Locale; 5 | 6 | import org.bukkit.block.BlockState; 7 | 8 | import net.coreprotect.config.ConfigHandler; 9 | import net.coreprotect.database.statement.SignStatement; 10 | import net.coreprotect.utility.BlockUtils; 11 | import net.coreprotect.utility.WorldUtils; 12 | 13 | class SignUpdateProcess { 14 | 15 | static void process(Statement statement, Object object, String user, int action, int time) { 16 | /* 17 | * We're switching blocks around quickly. 18 | * This block could already be removed again by the time the server tries to modify it. 19 | * Ignore any errors. 20 | */ 21 | if (object instanceof BlockState) { 22 | BlockState block = (BlockState) object; 23 | int x = block.getX(); 24 | int y = block.getY(); 25 | int z = block.getZ(); 26 | int wid = WorldUtils.getWorldId(block.getWorld().getName()); 27 | int userid = ConfigHandler.playerIdCache.get(user.toLowerCase(Locale.ROOT)); 28 | String query = ""; 29 | if (action == 0) { 30 | query = "SELECT color, color_secondary, data, waxed, face, line_1, line_2, line_3, line_4, line_5, line_6, line_7, line_8 FROM " + ConfigHandler.prefix + "sign WHERE user='" + userid + "' AND wid='" + wid + "' AND x='" + x + "' AND z='" + z + "' AND y='" + y + "' AND time < '" + time + "' ORDER BY rowid DESC LIMIT 0, 1"; 31 | } 32 | else { 33 | query = "SELECT color, color_secondary, data, waxed, face, line_1, line_2, line_3, line_4, line_5, line_6, line_7, line_8 FROM " + ConfigHandler.prefix + "sign WHERE user='" + userid + "' AND wid='" + wid + "' AND x='" + x + "' AND z='" + z + "' AND y='" + y + "' AND time >= '" + time + "' ORDER BY rowid ASC LIMIT 0, 1"; 34 | } 35 | SignStatement.getData(statement, block, query); 36 | BlockUtils.updateBlock(block); 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/net/coreprotect/consumer/process/SkullUpdateProcess.java: -------------------------------------------------------------------------------- 1 | package net.coreprotect.consumer.process; 2 | 3 | import java.sql.Statement; 4 | 5 | import org.bukkit.block.BlockState; 6 | 7 | import net.coreprotect.config.ConfigHandler; 8 | import net.coreprotect.database.statement.SkullStatement; 9 | import net.coreprotect.utility.BlockUtils; 10 | 11 | class SkullUpdateProcess { 12 | 13 | static void process(Statement statement, Object object, int rowId) { 14 | /* 15 | * We're switching blocks around quickly. 16 | * This block could already be removed again by the time the server tries to modify it. 17 | * Ignore any errors. 18 | */ 19 | if (object instanceof BlockState) { 20 | BlockState block = (BlockState) object; 21 | String query = "SELECT owner, skin FROM " + ConfigHandler.prefix + "skull WHERE rowid='" + rowId + "' LIMIT 0, 1"; 22 | SkullStatement.getData(statement, block, query); 23 | BlockUtils.updateBlock(block); 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/net/coreprotect/consumer/process/StructureGrowthProcess.java: -------------------------------------------------------------------------------- 1 | package net.coreprotect.consumer.process; 2 | 3 | import java.sql.PreparedStatement; 4 | import java.sql.Statement; 5 | import java.util.List; 6 | import java.util.Map; 7 | 8 | import org.bukkit.block.BlockState; 9 | 10 | import net.coreprotect.consumer.Consumer; 11 | import net.coreprotect.database.Lookup; 12 | import net.coreprotect.database.logger.BlockBreakLogger; 13 | import net.coreprotect.database.logger.BlockPlaceLogger; 14 | import net.coreprotect.utility.MaterialUtils; 15 | import net.coreprotect.utility.Util; 16 | 17 | class StructureGrowthProcess { 18 | 19 | static void process(Statement statement, PreparedStatement preparedStmt, int batchCount, int processId, int id, String user, Object object, int replaceBlockCount) { 20 | if (object instanceof BlockState) { 21 | BlockState block = (BlockState) object; 22 | Map> blockLists = Consumer.consumerBlockList.get(processId); 23 | if (blockLists.get(id) != null) { 24 | List blockStates = blockLists.get(id); 25 | String resultData = Lookup.whoPlacedCache(block); 26 | if (resultData.isEmpty()) { 27 | resultData = Lookup.whoPlaced(statement, block); 28 | } 29 | if (resultData.length() > 0) { 30 | user = resultData; 31 | } 32 | int count = 0; 33 | for (BlockState blockState : blockStates) { 34 | if (count < replaceBlockCount) { 35 | BlockBreakLogger.log(preparedStmt, batchCount, user, blockState.getLocation(), MaterialUtils.getBlockId(blockState.getType()), 0, null, blockState.getBlockData().getAsString(), null); 36 | } 37 | else { 38 | BlockPlaceLogger.log(preparedStmt, batchCount, user, blockState, 0, 0, null, -1, false, null, null, null); 39 | } 40 | count++; 41 | } 42 | blockLists.remove(id); 43 | } 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/net/coreprotect/consumer/process/WorldInsertProcess.java: -------------------------------------------------------------------------------- 1 | package net.coreprotect.consumer.process; 2 | 3 | import java.sql.PreparedStatement; 4 | import java.sql.Statement; 5 | 6 | import net.coreprotect.config.ConfigHandler; 7 | import net.coreprotect.database.statement.MaterialStatement; 8 | import net.coreprotect.database.statement.WorldStatement; 9 | import net.coreprotect.language.Phrase; 10 | import net.coreprotect.language.Selector; 11 | import net.coreprotect.utility.Chat; 12 | 13 | class WorldInsertProcess { 14 | 15 | static void process(PreparedStatement preparedStmt, int batchCount, Statement statement, Object world, int worldId) { 16 | if (world instanceof String) { 17 | String query = "SELECT id FROM " + ConfigHandler.prefix + "world WHERE id = '" + worldId + "' LIMIT 0, 1"; 18 | boolean hasMaterial = MaterialStatement.hasMaterial(statement, query); 19 | if (!hasMaterial) { 20 | WorldStatement.insert(preparedStmt, batchCount, worldId, (String) world); 21 | 22 | // validate ID maps to ensure mapping wasn't reloaded from database prior to this insertion completing 23 | ConfigHandler.worlds.put((String) world, worldId); 24 | ConfigHandler.worldsReversed.put(worldId, (String) world); 25 | if (worldId > ConfigHandler.worldId) { 26 | ConfigHandler.worldId = worldId; 27 | } 28 | } 29 | else { 30 | Chat.console(Phrase.build(Phrase.CACHE_ERROR, "world")); 31 | Chat.console(Phrase.build(Phrase.CACHE_RELOAD, Selector.SECOND)); 32 | ConfigHandler.loadWorlds(statement); 33 | } 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/net/coreprotect/database/LookupConverter.java: -------------------------------------------------------------------------------- 1 | package net.coreprotect.database; 2 | 3 | import java.nio.charset.StandardCharsets; 4 | import java.sql.Statement; 5 | import java.util.ArrayList; 6 | import java.util.List; 7 | 8 | import net.coreprotect.config.ConfigHandler; 9 | import net.coreprotect.database.statement.UserStatement; 10 | import net.coreprotect.utility.BlockUtils; 11 | 12 | public class LookupConverter { 13 | 14 | public static List convertRawLookup(Statement statement, List list) { 15 | List newList = new ArrayList<>(); 16 | 17 | if (list == null) { 18 | return null; 19 | } 20 | 21 | for (Object[] map : list) { 22 | int newLength = map.length - 1; 23 | String[] results = new String[newLength]; 24 | 25 | for (int i = 0; i < map.length; i++) { 26 | try { 27 | int newId = i - 1; 28 | if (i == 2) { 29 | if (map[i] instanceof Integer) { 30 | int userId = (Integer) map[i]; 31 | if (ConfigHandler.playerIdCacheReversed.get(userId) == null) { 32 | UserStatement.loadName(statement.getConnection(), userId); 33 | } 34 | String userResult = ConfigHandler.playerIdCacheReversed.get(userId); 35 | results[newId] = userResult; 36 | } 37 | else { 38 | results[newId] = (String) map[i]; 39 | } 40 | } 41 | else if (i == 13 && map[i] instanceof byte[]) { 42 | results[newId] = BlockUtils.byteDataToString((byte[]) map[i], (int) map[6]); 43 | } 44 | else if (i > 0) { // skip rowid 45 | if (map[i] instanceof Integer) { 46 | results[newId] = map[i].toString(); 47 | } 48 | else if (map[i] instanceof String) { 49 | results[newId] = (String) map[i]; 50 | } 51 | else if (map[i] instanceof byte[]) { 52 | results[newId] = new String((byte[]) map[i], StandardCharsets.ISO_8859_1); 53 | } 54 | } 55 | } 56 | catch (Exception e) { 57 | e.printStackTrace(); 58 | } 59 | } 60 | newList.add(results); 61 | } 62 | 63 | return newList; 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/main/java/net/coreprotect/database/logger/ChatLogger.java: -------------------------------------------------------------------------------- 1 | package net.coreprotect.database.logger; 2 | 3 | import java.sql.PreparedStatement; 4 | import java.util.Locale; 5 | 6 | import org.bukkit.Location; 7 | 8 | import net.coreprotect.config.ConfigHandler; 9 | import net.coreprotect.database.statement.ChatStatement; 10 | import net.coreprotect.utility.WorldUtils; 11 | 12 | public class ChatLogger { 13 | 14 | private ChatLogger() { 15 | throw new IllegalStateException("Database class"); 16 | } 17 | 18 | public static void log(PreparedStatement preparedStmt, int batchCount, long time, Location location, String user, String message) { 19 | try { 20 | if (ConfigHandler.blacklist.get(user.toLowerCase(Locale.ROOT)) != null) { 21 | return; 22 | } 23 | int x = location.getBlockX(); 24 | int y = location.getBlockY(); 25 | int z = location.getBlockZ(); 26 | int wid = WorldUtils.getWorldId(location.getWorld().getName()); 27 | int userId = ConfigHandler.playerIdCache.get(user.toLowerCase(Locale.ROOT)); 28 | ChatStatement.insert(preparedStmt, batchCount, time, userId, wid, x, y, z, message); 29 | } 30 | catch (Exception e) { 31 | e.printStackTrace(); 32 | } 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/net/coreprotect/database/logger/CommandLogger.java: -------------------------------------------------------------------------------- 1 | package net.coreprotect.database.logger; 2 | 3 | import java.sql.PreparedStatement; 4 | import java.util.Locale; 5 | 6 | import org.bukkit.Bukkit; 7 | import org.bukkit.Location; 8 | 9 | import net.coreprotect.CoreProtect; 10 | import net.coreprotect.config.Config; 11 | import net.coreprotect.config.ConfigHandler; 12 | import net.coreprotect.database.statement.CommandStatement; 13 | import net.coreprotect.database.statement.UserStatement; 14 | import net.coreprotect.event.CoreProtectPreLogEvent; 15 | import net.coreprotect.utility.WorldUtils; 16 | 17 | public class CommandLogger { 18 | 19 | private CommandLogger() { 20 | throw new IllegalStateException("Database class"); 21 | } 22 | 23 | public static void log(PreparedStatement preparedStmt, int batchCount, long time, Location location, String user, String message) { 24 | try { 25 | if (ConfigHandler.blacklist.get(user.toLowerCase(Locale.ROOT)) != null) { 26 | return; 27 | } 28 | if (ConfigHandler.blacklist.get(((message + " ").split(" "))[0].toLowerCase(Locale.ROOT)) != null) { 29 | return; 30 | } 31 | 32 | CoreProtectPreLogEvent event = new CoreProtectPreLogEvent(user); 33 | if (Config.getGlobal().API_ENABLED && !Bukkit.isPrimaryThread()) { 34 | CoreProtect.getInstance().getServer().getPluginManager().callEvent(event); 35 | } 36 | 37 | if (event.isCancelled()) { 38 | return; 39 | } 40 | 41 | int userId = UserStatement.getId(preparedStmt, event.getUser(), true); 42 | int wid = WorldUtils.getWorldId(location.getWorld().getName()); 43 | int x = location.getBlockX(); 44 | int y = location.getBlockY(); 45 | int z = location.getBlockZ(); 46 | CommandStatement.insert(preparedStmt, batchCount, time, userId, wid, x, y, z, message); 47 | } 48 | catch (Exception e) { 49 | e.printStackTrace(); 50 | } 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /src/main/java/net/coreprotect/database/logger/ContainerBreakLogger.java: -------------------------------------------------------------------------------- 1 | package net.coreprotect.database.logger; 2 | 3 | import java.sql.PreparedStatement; 4 | import java.util.Locale; 5 | 6 | import org.bukkit.Location; 7 | import org.bukkit.Material; 8 | import org.bukkit.inventory.ItemStack; 9 | 10 | import net.coreprotect.config.ConfigHandler; 11 | import net.coreprotect.utility.ItemUtils; 12 | 13 | public class ContainerBreakLogger { 14 | 15 | private ContainerBreakLogger() { 16 | throw new IllegalStateException("Database class"); 17 | } 18 | 19 | public static void log(PreparedStatement preparedStmt, int batchCount, String player, Location l, Material type, ItemStack[] oldInventory) { 20 | try { 21 | ItemUtils.mergeItems(type, oldInventory); 22 | ContainerLogger.logTransaction(preparedStmt, batchCount, player, type, null, oldInventory, 0, l); 23 | String loggingContainerId = player.toLowerCase(Locale.ROOT) + "." + l.getBlockX() + "." + l.getBlockY() + "." + l.getBlockZ(); 24 | 25 | // If there was a pending chest transaction, it would have already been processed. 26 | if (ConfigHandler.forceContainer.get(loggingContainerId) != null) { 27 | ConfigHandler.forceContainer.remove(loggingContainerId); 28 | } 29 | } 30 | catch (Exception e) { 31 | e.printStackTrace(); 32 | } 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/net/coreprotect/database/logger/EntityKillLogger.java: -------------------------------------------------------------------------------- 1 | package net.coreprotect.database.logger; 2 | 3 | import java.sql.PreparedStatement; 4 | import java.sql.ResultSet; 5 | import java.util.List; 6 | import java.util.Locale; 7 | 8 | import org.bukkit.Bukkit; 9 | import org.bukkit.block.BlockState; 10 | 11 | import net.coreprotect.CoreProtect; 12 | import net.coreprotect.config.Config; 13 | import net.coreprotect.config.ConfigHandler; 14 | import net.coreprotect.database.Database; 15 | import net.coreprotect.database.statement.BlockStatement; 16 | import net.coreprotect.database.statement.EntityStatement; 17 | import net.coreprotect.database.statement.UserStatement; 18 | import net.coreprotect.event.CoreProtectPreLogEvent; 19 | import net.coreprotect.utility.WorldUtils; 20 | 21 | public class EntityKillLogger { 22 | 23 | private EntityKillLogger() { 24 | throw new IllegalStateException("Database class"); 25 | } 26 | 27 | public static void log(PreparedStatement preparedStmt, PreparedStatement preparedStmt2, int batchCount, String user, BlockState block, List data, int type) { 28 | try { 29 | if (ConfigHandler.blacklist.get(user.toLowerCase(Locale.ROOT)) != null) { 30 | return; 31 | } 32 | 33 | CoreProtectPreLogEvent event = new CoreProtectPreLogEvent(user); 34 | if (Config.getGlobal().API_ENABLED && !Bukkit.isPrimaryThread()) { 35 | CoreProtect.getInstance().getServer().getPluginManager().callEvent(event); 36 | } 37 | 38 | if (event.isCancelled()) { 39 | return; 40 | } 41 | 42 | int userId = UserStatement.getId(preparedStmt, event.getUser(), true); 43 | int wid = WorldUtils.getWorldId(block.getWorld().getName()); 44 | int time = (int) (System.currentTimeMillis() / 1000L); 45 | int x = block.getX(); 46 | int y = block.getY(); 47 | int z = block.getZ(); 48 | int entity_key = 0; 49 | 50 | ResultSet resultSet = EntityStatement.insert(preparedStmt2, time, data); 51 | if (Database.hasReturningKeys()) { 52 | resultSet.next(); 53 | entity_key = resultSet.getInt(1); 54 | resultSet.close(); 55 | } 56 | else { 57 | ResultSet keys = preparedStmt2.getGeneratedKeys(); 58 | keys.next(); 59 | entity_key = keys.getInt(1); 60 | keys.close(); 61 | } 62 | 63 | BlockStatement.insert(preparedStmt, batchCount, time, userId, wid, x, y, z, type, entity_key, null, null, 3, 0); 64 | } 65 | catch (Exception e) { 66 | e.printStackTrace(); 67 | } 68 | } 69 | 70 | } 71 | -------------------------------------------------------------------------------- /src/main/java/net/coreprotect/database/logger/PlayerInteractLogger.java: -------------------------------------------------------------------------------- 1 | package net.coreprotect.database.logger; 2 | 3 | import java.sql.PreparedStatement; 4 | import java.util.Locale; 5 | 6 | import org.bukkit.Bukkit; 7 | import org.bukkit.Material; 8 | import org.bukkit.block.BlockState; 9 | 10 | import net.coreprotect.CoreProtect; 11 | import net.coreprotect.config.Config; 12 | import net.coreprotect.config.ConfigHandler; 13 | import net.coreprotect.database.statement.BlockStatement; 14 | import net.coreprotect.database.statement.UserStatement; 15 | import net.coreprotect.event.CoreProtectPreLogEvent; 16 | import net.coreprotect.utility.MaterialUtils; 17 | import net.coreprotect.utility.WorldUtils; 18 | 19 | public class PlayerInteractLogger { 20 | 21 | private PlayerInteractLogger() { 22 | throw new IllegalStateException("Database class"); 23 | } 24 | 25 | public static void log(PreparedStatement preparedStmt, int batchCount, String user, BlockState block, Material blockType) { 26 | try { 27 | int type = MaterialUtils.getBlockId(blockType.name(), true); 28 | if (ConfigHandler.blacklist.get(user.toLowerCase(Locale.ROOT)) != null || MaterialUtils.getType(type).equals(Material.AIR) || MaterialUtils.getType(type).equals(Material.CAVE_AIR)) { 29 | return; 30 | } 31 | 32 | CoreProtectPreLogEvent event = new CoreProtectPreLogEvent(user); 33 | if (Config.getGlobal().API_ENABLED && !Bukkit.isPrimaryThread()) { 34 | CoreProtect.getInstance().getServer().getPluginManager().callEvent(event); 35 | } 36 | 37 | if (event.isCancelled()) { 38 | return; 39 | } 40 | 41 | int userId = UserStatement.getId(preparedStmt, event.getUser(), true); 42 | int wid = WorldUtils.getWorldId(block.getWorld().getName()); 43 | int time = (int) (System.currentTimeMillis() / 1000L); 44 | int x = block.getX(); 45 | int y = block.getY(); 46 | int z = block.getZ(); 47 | int data = 0; 48 | BlockStatement.insert(preparedStmt, batchCount, time, userId, wid, x, y, z, type, data, null, null, 2, 0); 49 | } 50 | catch (Exception e) { 51 | e.printStackTrace(); 52 | } 53 | } 54 | 55 | } 56 | -------------------------------------------------------------------------------- /src/main/java/net/coreprotect/database/logger/PlayerKillLogger.java: -------------------------------------------------------------------------------- 1 | package net.coreprotect.database.logger; 2 | 3 | import java.sql.PreparedStatement; 4 | import java.util.Locale; 5 | 6 | import org.bukkit.Bukkit; 7 | import org.bukkit.block.BlockState; 8 | 9 | import net.coreprotect.CoreProtect; 10 | import net.coreprotect.config.Config; 11 | import net.coreprotect.config.ConfigHandler; 12 | import net.coreprotect.database.statement.BlockStatement; 13 | import net.coreprotect.database.statement.UserStatement; 14 | import net.coreprotect.event.CoreProtectPreLogEvent; 15 | import net.coreprotect.utility.WorldUtils; 16 | 17 | public class PlayerKillLogger { 18 | 19 | private PlayerKillLogger() { 20 | throw new IllegalStateException("Database class"); 21 | } 22 | 23 | public static void log(PreparedStatement preparedStmt, int batchCount, String user, BlockState block, String player) { 24 | try { 25 | if (ConfigHandler.blacklist.get(user.toLowerCase(Locale.ROOT)) != null) { 26 | return; 27 | } 28 | 29 | if (ConfigHandler.playerIdCache.get(player.toLowerCase(Locale.ROOT)) == null) { 30 | UserStatement.loadId(preparedStmt.getConnection(), player, null); 31 | } 32 | 33 | CoreProtectPreLogEvent event = new CoreProtectPreLogEvent(user); 34 | if (Config.getGlobal().API_ENABLED && !Bukkit.isPrimaryThread()) { 35 | CoreProtect.getInstance().getServer().getPluginManager().callEvent(event); 36 | } 37 | 38 | if (event.isCancelled()) { 39 | return; 40 | } 41 | 42 | int userId = UserStatement.getId(preparedStmt, event.getUser(), true); 43 | int playerId = ConfigHandler.playerIdCache.get(player.toLowerCase(Locale.ROOT)); 44 | int wid = WorldUtils.getWorldId(block.getWorld().getName()); 45 | int time = (int) (System.currentTimeMillis() / 1000L); 46 | int x = block.getX(); 47 | int y = block.getY(); 48 | int z = block.getZ(); 49 | BlockStatement.insert(preparedStmt, batchCount, time, userId, wid, x, y, z, 0, playerId, null, null, 3, 0); 50 | } 51 | catch (Exception e) { 52 | e.printStackTrace(); 53 | } 54 | } 55 | 56 | } 57 | -------------------------------------------------------------------------------- /src/main/java/net/coreprotect/database/logger/PlayerSessionLogger.java: -------------------------------------------------------------------------------- 1 | package net.coreprotect.database.logger; 2 | 3 | import java.sql.PreparedStatement; 4 | import java.util.Locale; 5 | 6 | import org.bukkit.Location; 7 | 8 | import net.coreprotect.config.ConfigHandler; 9 | import net.coreprotect.database.statement.SessionStatement; 10 | import net.coreprotect.utility.WorldUtils; 11 | 12 | public class PlayerSessionLogger { 13 | 14 | private PlayerSessionLogger() { 15 | throw new IllegalStateException("Database class"); 16 | } 17 | 18 | public static void log(PreparedStatement preparedStmt, int batchCount, String user, Location location, int time, int action) { 19 | try { 20 | if (ConfigHandler.blacklist.get(user.toLowerCase(Locale.ROOT)) != null) { 21 | return; 22 | } 23 | int x = location.getBlockX(); 24 | int y = location.getBlockY(); 25 | int z = location.getBlockZ(); 26 | int wid = WorldUtils.getWorldId(location.getWorld().getName()); 27 | int userId = ConfigHandler.playerIdCache.get(user.toLowerCase(Locale.ROOT)); 28 | SessionStatement.insert(preparedStmt, batchCount, time, userId, wid, x, y, z, action); 29 | } 30 | catch (Exception e) { 31 | e.printStackTrace(); 32 | } 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/net/coreprotect/database/logger/SignTextLogger.java: -------------------------------------------------------------------------------- 1 | package net.coreprotect.database.logger; 2 | 3 | import java.sql.PreparedStatement; 4 | import java.util.Locale; 5 | 6 | import org.bukkit.Bukkit; 7 | import org.bukkit.Location; 8 | 9 | import net.coreprotect.CoreProtect; 10 | import net.coreprotect.config.Config; 11 | import net.coreprotect.config.ConfigHandler; 12 | import net.coreprotect.database.statement.SignStatement; 13 | import net.coreprotect.database.statement.UserStatement; 14 | import net.coreprotect.event.CoreProtectPreLogEvent; 15 | import net.coreprotect.utility.WorldUtils; 16 | 17 | public class SignTextLogger { 18 | 19 | private SignTextLogger() { 20 | throw new IllegalStateException("Database class"); 21 | } 22 | 23 | public static void log(PreparedStatement preparedStmt, int batchCount, String user, Location location, int action, int color, int colorSecondary, int data, boolean isWaxed, boolean isFront, String line1, String line2, String line3, String line4, String line5, String line6, String line7, String line8, int timeOffset) { 24 | try { 25 | if (ConfigHandler.blacklist.get(user.toLowerCase(Locale.ROOT)) != null) { 26 | return; 27 | } 28 | 29 | CoreProtectPreLogEvent event = new CoreProtectPreLogEvent(user); 30 | if (Config.getGlobal().API_ENABLED && !Bukkit.isPrimaryThread()) { 31 | CoreProtect.getInstance().getServer().getPluginManager().callEvent(event); 32 | } 33 | 34 | if (event.isCancelled()) { 35 | return; 36 | } 37 | 38 | int userId = UserStatement.getId(preparedStmt, event.getUser(), true); 39 | int wid = WorldUtils.getWorldId(location.getWorld().getName()); 40 | int time = (int) (System.currentTimeMillis() / 1000L) - timeOffset; 41 | int x = location.getBlockX(); 42 | int y = location.getBlockY(); 43 | int z = location.getBlockZ(); 44 | 45 | if (line1.isEmpty() && line2.isEmpty() && line3.isEmpty() && line4.isEmpty()) { 46 | line1 = null; 47 | line2 = null; 48 | line3 = null; 49 | line4 = null; 50 | } 51 | if (line5.isEmpty() && line6.isEmpty() && line7.isEmpty() && line8.isEmpty()) { 52 | line5 = null; 53 | line6 = null; 54 | line7 = null; 55 | line8 = null; 56 | } 57 | 58 | SignStatement.insert(preparedStmt, batchCount, time, userId, wid, x, y, z, action, color, colorSecondary, data, isWaxed ? 1 : 0, isFront ? 0 : 1, line1, line2, line3, line4, line5, line6, line7, line8); 59 | } 60 | catch (Exception e) { 61 | e.printStackTrace(); 62 | } 63 | } 64 | 65 | } 66 | -------------------------------------------------------------------------------- /src/main/java/net/coreprotect/database/logger/SkullBreakLogger.java: -------------------------------------------------------------------------------- 1 | package net.coreprotect.database.logger; 2 | 3 | import java.sql.PreparedStatement; 4 | import java.sql.ResultSet; 5 | import java.util.Locale; 6 | 7 | import org.bukkit.block.BlockState; 8 | import org.bukkit.block.Skull; 9 | 10 | import net.coreprotect.config.ConfigHandler; 11 | import net.coreprotect.database.Database; 12 | import net.coreprotect.database.statement.SkullStatement; 13 | import net.coreprotect.paper.PaperAdapter; 14 | import net.coreprotect.utility.MaterialUtils; 15 | 16 | public class SkullBreakLogger { 17 | 18 | private SkullBreakLogger() { 19 | throw new IllegalStateException("Database class"); 20 | } 21 | 22 | public static void log(PreparedStatement preparedStmt, PreparedStatement preparedStmt2, int batchCount, String user, BlockState block) { 23 | try { 24 | if (ConfigHandler.blacklist.get(user.toLowerCase(Locale.ROOT)) != null || block == null) { 25 | return; 26 | } 27 | int time = (int) (System.currentTimeMillis() / 1000L); 28 | int type = MaterialUtils.getBlockId(block.getType().name(), true); 29 | Skull skull = (Skull) block; 30 | String skullOwner = ""; 31 | String skullSkin = null; 32 | int skullKey = 0; 33 | if (skull.hasOwner()) { 34 | skullOwner = PaperAdapter.ADAPTER.getSkullOwner(skull); 35 | skullSkin = PaperAdapter.ADAPTER.getSkullSkin(skull); 36 | ResultSet resultSet = SkullStatement.insert(preparedStmt2, time, skullOwner, skullSkin); 37 | if (Database.hasReturningKeys()) { 38 | resultSet.next(); 39 | skullKey = resultSet.getInt(1); 40 | resultSet.close(); 41 | } 42 | else { 43 | ResultSet keys = preparedStmt2.getGeneratedKeys(); 44 | keys.next(); 45 | skullKey = keys.getInt(1); 46 | keys.close(); 47 | } 48 | } 49 | 50 | BlockBreakLogger.log(preparedStmt, batchCount, user, block.getLocation(), type, skullKey, null, block.getBlockData().getAsString(), null); 51 | } 52 | catch (Exception e) { 53 | e.printStackTrace(); 54 | } 55 | } 56 | 57 | } 58 | -------------------------------------------------------------------------------- /src/main/java/net/coreprotect/database/logger/SkullPlaceLogger.java: -------------------------------------------------------------------------------- 1 | package net.coreprotect.database.logger; 2 | 3 | import java.sql.PreparedStatement; 4 | import java.sql.ResultSet; 5 | import java.util.Locale; 6 | 7 | import org.bukkit.Material; 8 | import org.bukkit.block.BlockState; 9 | import org.bukkit.block.Skull; 10 | 11 | import net.coreprotect.config.ConfigHandler; 12 | import net.coreprotect.database.Database; 13 | import net.coreprotect.database.statement.SkullStatement; 14 | import net.coreprotect.paper.PaperAdapter; 15 | 16 | public class SkullPlaceLogger { 17 | 18 | private SkullPlaceLogger() { 19 | throw new IllegalStateException("Database class"); 20 | } 21 | 22 | public static void log(PreparedStatement preparedStmt, PreparedStatement preparedStmt2, int batchCount, String user, BlockState block, int replaceType, int replaceData) { 23 | try { 24 | if (ConfigHandler.blacklist.get(user.toLowerCase(Locale.ROOT)) != null || block == null) { 25 | return; 26 | } 27 | int time = (int) (System.currentTimeMillis() / 1000L); 28 | Material type = block.getType(); 29 | int skullKey = 0; 30 | 31 | if (block instanceof Skull) { 32 | Skull skull = (Skull) block; 33 | String skullOwner = ""; 34 | String skullSkin = null; 35 | if (skull.hasOwner()) { 36 | skullOwner = PaperAdapter.ADAPTER.getSkullOwner(skull); 37 | skullSkin = PaperAdapter.ADAPTER.getSkullSkin(skull); 38 | ResultSet resultSet = SkullStatement.insert(preparedStmt2, time, skullOwner, skullSkin); 39 | if (Database.hasReturningKeys()) { 40 | resultSet.next(); 41 | skullKey = resultSet.getInt(1); 42 | resultSet.close(); 43 | } 44 | else { 45 | ResultSet keys = preparedStmt2.getGeneratedKeys(); 46 | keys.next(); 47 | skullKey = keys.getInt(1); 48 | keys.close(); 49 | } 50 | } 51 | } 52 | 53 | BlockPlaceLogger.log(preparedStmt, batchCount, user, block, replaceType, replaceData, type, skullKey, true, null, null, null); 54 | } 55 | catch (Exception e) { 56 | e.printStackTrace(); 57 | } 58 | } 59 | 60 | } 61 | -------------------------------------------------------------------------------- /src/main/java/net/coreprotect/database/lookup/PlayerLookup.java: -------------------------------------------------------------------------------- 1 | package net.coreprotect.database.lookup; 2 | 3 | import java.sql.Connection; 4 | import java.sql.PreparedStatement; 5 | import java.sql.ResultSet; 6 | import java.util.Locale; 7 | 8 | import net.coreprotect.config.Config; 9 | import net.coreprotect.config.ConfigHandler; 10 | 11 | public class PlayerLookup { 12 | 13 | public static boolean playerExists(Connection connection, String user) { 14 | try { 15 | int id = -1; 16 | String uuid = null; 17 | 18 | if (ConfigHandler.playerIdCache.get(user.toLowerCase(Locale.ROOT)) != null) { 19 | return true; 20 | } 21 | 22 | String collate = ""; 23 | if (!Config.getGlobal().MYSQL) { 24 | collate = " COLLATE NOCASE"; 25 | } 26 | 27 | String query = "SELECT rowid as id, uuid FROM " + ConfigHandler.prefix + "user WHERE user = ?" + collate + " LIMIT 0, 1"; 28 | PreparedStatement preparedStmt = connection.prepareStatement(query); 29 | preparedStmt.setString(1, user); 30 | 31 | ResultSet results = preparedStmt.executeQuery(); 32 | 33 | while (results.next()) { 34 | id = results.getInt("id"); 35 | uuid = results.getString("uuid"); 36 | } 37 | results.close(); 38 | preparedStmt.close(); 39 | 40 | if (id > -1) { 41 | if (uuid != null) { 42 | ConfigHandler.uuidCache.put(user.toLowerCase(Locale.ROOT), uuid); 43 | ConfigHandler.uuidCacheReversed.put(uuid, user); 44 | } 45 | 46 | ConfigHandler.playerIdCache.put(user.toLowerCase(Locale.ROOT), id); 47 | ConfigHandler.playerIdCacheReversed.put(id, user); 48 | return true; 49 | } 50 | } 51 | catch (Exception e) { 52 | e.printStackTrace(); 53 | } 54 | 55 | return false; 56 | } 57 | 58 | } 59 | -------------------------------------------------------------------------------- /src/main/java/net/coreprotect/database/statement/BlockStatement.java: -------------------------------------------------------------------------------- 1 | package net.coreprotect.database.statement; 2 | 3 | import java.sql.PreparedStatement; 4 | import java.util.List; 5 | 6 | import net.coreprotect.utility.BlockUtils; 7 | import net.coreprotect.utility.ItemUtils; 8 | 9 | public class BlockStatement { 10 | 11 | private BlockStatement() { 12 | throw new IllegalStateException("Database class"); 13 | } 14 | 15 | public static void insert(PreparedStatement preparedStmt, int batchCount, int time, int id, int wid, int x, int y, int z, int type, int data, List meta, String blockData, int action, int rolledBack) { 16 | try { 17 | byte[] bBlockData = BlockUtils.stringToByteData(blockData, type); 18 | byte[] byteData = null; 19 | 20 | if (meta != null) { 21 | byteData = ItemUtils.convertByteData(meta); 22 | } 23 | 24 | preparedStmt.setInt(1, time); 25 | preparedStmt.setInt(2, id); 26 | preparedStmt.setInt(3, wid); 27 | preparedStmt.setInt(4, x); 28 | preparedStmt.setInt(5, y); 29 | preparedStmt.setInt(6, z); 30 | preparedStmt.setInt(7, type); 31 | preparedStmt.setInt(8, data); 32 | preparedStmt.setObject(9, byteData); 33 | preparedStmt.setObject(10, bBlockData); 34 | preparedStmt.setInt(11, action); 35 | preparedStmt.setInt(12, rolledBack); 36 | preparedStmt.addBatch(); 37 | 38 | if (batchCount > 0 && batchCount % 1000 == 0) { 39 | preparedStmt.executeBatch(); 40 | } 41 | } 42 | catch (Exception e) { 43 | e.printStackTrace(); 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/net/coreprotect/database/statement/ChatStatement.java: -------------------------------------------------------------------------------- 1 | package net.coreprotect.database.statement; 2 | 3 | import java.sql.PreparedStatement; 4 | 5 | public class ChatStatement { 6 | 7 | private ChatStatement() { 8 | throw new IllegalStateException("Database class"); 9 | } 10 | 11 | public static void insert(PreparedStatement preparedStmt, int batchCount, long time, int user, int wid, int x, int y, int z, String message) { 12 | try { 13 | preparedStmt.setLong(1, time); 14 | preparedStmt.setInt(2, user); 15 | preparedStmt.setInt(3, wid); 16 | preparedStmt.setInt(4, x); 17 | preparedStmt.setInt(5, y); 18 | preparedStmt.setInt(6, z); 19 | preparedStmt.setString(7, message); 20 | preparedStmt.addBatch(); 21 | 22 | if (batchCount > 0 && batchCount % 1000 == 0) { 23 | preparedStmt.executeBatch(); 24 | } 25 | } 26 | catch (Exception e) { 27 | e.printStackTrace(); 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/net/coreprotect/database/statement/CommandStatement.java: -------------------------------------------------------------------------------- 1 | package net.coreprotect.database.statement; 2 | 3 | import java.sql.PreparedStatement; 4 | 5 | public class CommandStatement { 6 | 7 | private CommandStatement() { 8 | throw new IllegalStateException("Database class"); 9 | } 10 | 11 | public static void insert(PreparedStatement preparedStmt, int batchCount, long time, int user, int wid, int x, int y, int z, String message) { 12 | try { 13 | preparedStmt.setLong(1, time); 14 | preparedStmt.setInt(2, user); 15 | preparedStmt.setInt(3, wid); 16 | preparedStmt.setInt(4, x); 17 | preparedStmt.setInt(5, y); 18 | preparedStmt.setInt(6, z); 19 | preparedStmt.setString(7, message); 20 | preparedStmt.addBatch(); 21 | 22 | if (batchCount > 0 && batchCount % 1000 == 0) { 23 | preparedStmt.executeBatch(); 24 | } 25 | } 26 | catch (Exception e) { 27 | e.printStackTrace(); 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/net/coreprotect/database/statement/ContainerStatement.java: -------------------------------------------------------------------------------- 1 | package net.coreprotect.database.statement; 2 | 3 | import java.sql.PreparedStatement; 4 | 5 | import net.coreprotect.utility.ItemUtils; 6 | 7 | public class ContainerStatement { 8 | 9 | private ContainerStatement() { 10 | throw new IllegalStateException("Database class"); 11 | } 12 | 13 | public static void insert(PreparedStatement preparedStmt, int batchCount, int time, int id, int wid, int x, int y, int z, int type, int data, int amount, Object metadata, int action, int rolledBack) { 14 | try { 15 | byte[] byteData = ItemUtils.convertByteData(metadata); 16 | preparedStmt.setInt(1, time); 17 | preparedStmt.setInt(2, id); 18 | preparedStmt.setInt(3, wid); 19 | preparedStmt.setInt(4, x); 20 | preparedStmt.setInt(5, y); 21 | preparedStmt.setInt(6, z); 22 | preparedStmt.setInt(7, type); 23 | preparedStmt.setInt(8, data); 24 | preparedStmt.setInt(9, amount); 25 | preparedStmt.setObject(10, byteData); 26 | preparedStmt.setInt(11, action); 27 | preparedStmt.setInt(12, rolledBack); 28 | preparedStmt.addBatch(); 29 | 30 | if (batchCount > 0 && batchCount % 1000 == 0) { 31 | preparedStmt.executeBatch(); 32 | } 33 | } 34 | catch (Exception e) { 35 | e.printStackTrace(); 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/net/coreprotect/database/statement/EntityStatement.java: -------------------------------------------------------------------------------- 1 | package net.coreprotect.database.statement; 2 | 3 | import java.io.ByteArrayInputStream; 4 | import java.io.ByteArrayOutputStream; 5 | import java.sql.PreparedStatement; 6 | import java.sql.ResultSet; 7 | import java.sql.Statement; 8 | import java.util.ArrayList; 9 | import java.util.List; 10 | 11 | import org.bukkit.block.BlockState; 12 | import org.bukkit.util.io.BukkitObjectInputStream; 13 | import org.bukkit.util.io.BukkitObjectOutputStream; 14 | 15 | import net.coreprotect.config.ConfigHandler; 16 | import net.coreprotect.database.Database; 17 | 18 | public class EntityStatement { 19 | 20 | private EntityStatement() { 21 | throw new IllegalStateException("Database class"); 22 | } 23 | 24 | public static ResultSet insert(PreparedStatement preparedStmt, int time, List data) { 25 | try { 26 | ByteArrayOutputStream bos = new ByteArrayOutputStream(); 27 | BukkitObjectOutputStream oos = new BukkitObjectOutputStream(bos); 28 | oos.writeObject(data); 29 | oos.flush(); 30 | oos.close(); 31 | bos.close(); 32 | 33 | byte[] byte_data = bos.toByteArray(); 34 | preparedStmt.setInt(1, time); 35 | preparedStmt.setObject(2, byte_data); 36 | if (Database.hasReturningKeys()) { 37 | return preparedStmt.executeQuery(); 38 | } 39 | else { 40 | preparedStmt.executeUpdate(); 41 | } 42 | } 43 | catch (Exception e) { 44 | e.printStackTrace(); 45 | } 46 | 47 | return null; 48 | } 49 | 50 | public static List getData(Statement statement, BlockState block, String query) { 51 | List result = new ArrayList<>(); 52 | 53 | try { 54 | ResultSet resultSet = statement.executeQuery(query); 55 | while (resultSet.next()) { 56 | byte[] data = resultSet.getBytes("data"); 57 | ByteArrayInputStream bais = new ByteArrayInputStream(data); 58 | BukkitObjectInputStream ins = new BukkitObjectInputStream(bais); 59 | @SuppressWarnings("unchecked") 60 | List input = (List) ins.readObject(); 61 | ins.close(); 62 | bais.close(); 63 | result = input; 64 | } 65 | 66 | resultSet.close(); 67 | } 68 | catch (Exception e) { // only display exception on development branch 69 | if (!ConfigHandler.EDITION_BRANCH.contains("-dev")) { 70 | e.printStackTrace(); 71 | } 72 | } 73 | 74 | return result; 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /src/main/java/net/coreprotect/database/statement/ItemStatement.java: -------------------------------------------------------------------------------- 1 | package net.coreprotect.database.statement; 2 | 3 | import java.sql.PreparedStatement; 4 | 5 | import net.coreprotect.utility.ItemUtils; 6 | 7 | public class ItemStatement { 8 | 9 | private ItemStatement() { 10 | throw new IllegalStateException("Database class"); 11 | } 12 | 13 | public static void insert(PreparedStatement preparedStmt, int batchCount, int time, int id, int wid, int x, int y, int z, int type, Object data, int amount, int action) { 14 | try { 15 | byte[] byteData = ItemUtils.convertByteData(data); 16 | preparedStmt.setInt(1, time); 17 | preparedStmt.setInt(2, id); 18 | preparedStmt.setInt(3, wid); 19 | preparedStmt.setInt(4, x); 20 | preparedStmt.setInt(5, y); 21 | preparedStmt.setInt(6, z); 22 | preparedStmt.setInt(7, type); 23 | preparedStmt.setObject(8, byteData); 24 | preparedStmt.setInt(9, amount); 25 | preparedStmt.setInt(10, action); 26 | preparedStmt.setInt(11, 0); // rolled_back 27 | preparedStmt.addBatch(); 28 | 29 | if (batchCount > 0 && batchCount % 1000 == 0) { 30 | preparedStmt.executeBatch(); 31 | } 32 | } 33 | catch (Exception e) { 34 | e.printStackTrace(); 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/net/coreprotect/database/statement/MaterialStatement.java: -------------------------------------------------------------------------------- 1 | package net.coreprotect.database.statement; 2 | 3 | import java.sql.PreparedStatement; 4 | import java.sql.ResultSet; 5 | import java.sql.Statement; 6 | 7 | public class MaterialStatement { 8 | 9 | private MaterialStatement() { 10 | throw new IllegalStateException("Database class"); 11 | } 12 | 13 | public static void insert(PreparedStatement preparedStmt, int batchCount, int id, String name) { 14 | try { 15 | preparedStmt.setInt(1, id); 16 | preparedStmt.setString(2, name); 17 | preparedStmt.addBatch(); 18 | 19 | if (batchCount > 0 && batchCount % 1000 == 0) { 20 | preparedStmt.executeBatch(); 21 | } 22 | } 23 | catch (Exception e) { 24 | e.printStackTrace(); 25 | } 26 | } 27 | 28 | public static boolean hasMaterial(Statement statement, String query) { 29 | boolean result = false; 30 | 31 | try { 32 | ResultSet resultSet = statement.executeQuery(query); 33 | if (resultSet.next()) { 34 | result = true; 35 | } 36 | resultSet.close(); 37 | } 38 | catch (Exception e) { 39 | e.printStackTrace(); 40 | } 41 | 42 | return result; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/net/coreprotect/database/statement/SessionStatement.java: -------------------------------------------------------------------------------- 1 | package net.coreprotect.database.statement; 2 | 3 | import java.sql.PreparedStatement; 4 | 5 | public class SessionStatement { 6 | 7 | private SessionStatement() { 8 | throw new IllegalStateException("Database class"); 9 | } 10 | 11 | public static void insert(PreparedStatement preparedStmt, int batchCount, int time, int user, int wid, int x, int y, int z, int action) { 12 | try { 13 | preparedStmt.setInt(1, time); 14 | preparedStmt.setInt(2, user); 15 | preparedStmt.setInt(3, wid); 16 | preparedStmt.setInt(4, x); 17 | preparedStmt.setInt(5, y); 18 | preparedStmt.setInt(6, z); 19 | preparedStmt.setInt(7, action); 20 | preparedStmt.addBatch(); 21 | 22 | if (batchCount > 0 && batchCount % 1000 == 0) { 23 | preparedStmt.executeBatch(); 24 | } 25 | } 26 | catch (Exception e) { 27 | e.printStackTrace(); 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/net/coreprotect/database/statement/SkullStatement.java: -------------------------------------------------------------------------------- 1 | package net.coreprotect.database.statement; 2 | 3 | import java.sql.PreparedStatement; 4 | import java.sql.ResultSet; 5 | import java.sql.Statement; 6 | 7 | import org.bukkit.block.BlockState; 8 | import org.bukkit.block.Skull; 9 | 10 | import net.coreprotect.database.Database; 11 | import net.coreprotect.paper.PaperAdapter; 12 | 13 | public class SkullStatement { 14 | 15 | private SkullStatement() { 16 | throw new IllegalStateException("Database class"); 17 | } 18 | 19 | public static ResultSet insert(PreparedStatement preparedStmt, int time, String owner, String skin) { 20 | try { 21 | preparedStmt.setInt(1, time); 22 | preparedStmt.setString(2, owner); 23 | preparedStmt.setString(3, skin); 24 | if (Database.hasReturningKeys()) { 25 | return preparedStmt.executeQuery(); 26 | } 27 | else { 28 | preparedStmt.executeUpdate(); 29 | } 30 | } 31 | catch (Exception e) { 32 | e.printStackTrace(); 33 | } 34 | 35 | return null; 36 | } 37 | 38 | public static void getData(Statement statement, BlockState block, String query) { 39 | try { 40 | if (!(block instanceof Skull)) { 41 | return; 42 | } 43 | 44 | Skull skull = (Skull) block; 45 | ResultSet resultSet = statement.executeQuery(query); 46 | 47 | while (resultSet.next()) { 48 | String owner = resultSet.getString("owner"); 49 | if (owner != null && owner.length() > 1) { 50 | PaperAdapter.ADAPTER.setSkullOwner(skull, owner); 51 | } 52 | 53 | String skin = resultSet.getString("skin"); 54 | if (owner != null && skin != null && skin.length() > 0) { 55 | PaperAdapter.ADAPTER.setSkullSkin(skull, skin); 56 | } 57 | } 58 | 59 | resultSet.close(); 60 | } 61 | catch (Exception e) { 62 | e.printStackTrace(); 63 | } 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/main/java/net/coreprotect/database/statement/WorldStatement.java: -------------------------------------------------------------------------------- 1 | package net.coreprotect.database.statement; 2 | 3 | import java.sql.PreparedStatement; 4 | 5 | public class WorldStatement { 6 | 7 | private WorldStatement() { 8 | throw new IllegalStateException("Database class"); 9 | } 10 | 11 | public static void insert(PreparedStatement preparedStmt, int batchCount, int id, String world) { 12 | try { 13 | preparedStmt.setInt(1, id); 14 | preparedStmt.setString(2, world); 15 | preparedStmt.addBatch(); 16 | 17 | if (batchCount > 0 && batchCount % 1000 == 0) { 18 | preparedStmt.executeBatch(); 19 | } 20 | } 21 | catch (Exception e) { 22 | e.printStackTrace(); 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/net/coreprotect/event/CoreProtectPreLogEvent.java: -------------------------------------------------------------------------------- 1 | package net.coreprotect.event; 2 | 3 | import org.bukkit.event.Cancellable; 4 | import org.bukkit.event.Event; 5 | import org.bukkit.event.HandlerList; 6 | 7 | public class CoreProtectPreLogEvent extends Event implements Cancellable { 8 | 9 | private static final HandlerList handlers = new HandlerList(); 10 | private boolean cancelled = false; 11 | private String user; 12 | 13 | public CoreProtectPreLogEvent(String user) { 14 | super(true); // async 15 | this.user = user; 16 | } 17 | 18 | public String getUser() { 19 | return user; 20 | } 21 | 22 | @Override 23 | public boolean isCancelled() { 24 | return cancelled; 25 | } 26 | 27 | @Override 28 | public void setCancelled(boolean cancel) { 29 | this.cancelled = cancel; 30 | } 31 | 32 | public void setUser(String newUser) { 33 | if (newUser == null || newUser.isEmpty()) { 34 | throw new IllegalArgumentException("Invalid user"); 35 | } 36 | 37 | this.user = newUser; 38 | } 39 | 40 | @Override 41 | public HandlerList getHandlers() { 42 | return handlers; 43 | } 44 | 45 | public static HandlerList getHandlerList() { 46 | return handlers; 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /src/main/java/net/coreprotect/language/Selector.java: -------------------------------------------------------------------------------- 1 | package net.coreprotect.language; 2 | 3 | import java.util.Arrays; 4 | import java.util.HashSet; 5 | import java.util.Set; 6 | 7 | import net.coreprotect.utility.Color; 8 | 9 | public class Selector { 10 | 11 | final public static String FIRST = "{1}"; 12 | final public static String SECOND = "{2}"; 13 | final public static String THIRD = "{3}"; 14 | final public static String FOURTH = "{4}"; 15 | 16 | final protected static Set SELECTORS = new HashSet<>(Arrays.asList(Selector.FIRST, Selector.SECOND, Selector.THIRD, Selector.FOURTH)); 17 | 18 | private Selector() { 19 | throw new IllegalStateException("Utility class"); 20 | } 21 | 22 | protected static String processSelection(String output, String param, String color) { 23 | String substring = output; 24 | try { 25 | substring = substring.substring(substring.indexOf("{") + 1); 26 | substring = substring.substring(0, substring.indexOf("}")); 27 | } 28 | catch (Exception e) { 29 | substring = ""; 30 | } 31 | 32 | if (substring.contains("|")) { 33 | int selector = Integer.parseInt(param.substring(1, 2)) - 1; 34 | int index = substring(substring, "|", selector); 35 | if (index == -1) { 36 | param = substring.substring(0, substring.indexOf("|")); 37 | } 38 | else { 39 | param = substring.substring(index + 1, (substring.lastIndexOf("|") > index ? substring(substring, "|", selector + 1) : substring.length())); 40 | } 41 | 42 | output = output.replace("{" + substring + "}", color + param + (color.length() > 0 ? Color.WHITE : color)); 43 | } 44 | 45 | return output; 46 | } 47 | 48 | private static int substring(String string, String search, int index) { 49 | int result = string.indexOf("|"); 50 | if (result == -1 || index == 0) { 51 | return -1; 52 | } 53 | 54 | for (int i = 1; i < index; i++) { 55 | result = string.indexOf("|", result + 1); 56 | if (result == -1) { 57 | return -1; 58 | } 59 | } 60 | 61 | return result; 62 | } 63 | 64 | } 65 | -------------------------------------------------------------------------------- /src/main/java/net/coreprotect/listener/block/BlockBurnListener.java: -------------------------------------------------------------------------------- 1 | package net.coreprotect.listener.block; 2 | 3 | import org.bukkit.World; 4 | import org.bukkit.event.EventHandler; 5 | import org.bukkit.event.EventPriority; 6 | import org.bukkit.event.Listener; 7 | import org.bukkit.event.block.BlockBurnEvent; 8 | 9 | import net.coreprotect.config.Config; 10 | import net.coreprotect.consumer.Queue; 11 | 12 | public final class BlockBurnListener extends Queue implements Listener { 13 | 14 | @EventHandler(priority = EventPriority.MONITOR) 15 | protected void onBlockBurn(BlockBurnEvent event) { 16 | World world = event.getBlock().getWorld(); 17 | if (!event.isCancelled() && Config.getConfig(world).BLOCK_BURN) { 18 | BlockBreakListener.processBlockBreak(null, "#fire", event.getBlock(), true, BlockUtil.NONE); 19 | } 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/net/coreprotect/listener/block/BlockFadeListener.java: -------------------------------------------------------------------------------- 1 | package net.coreprotect.listener.block; 2 | 3 | import org.bukkit.Material; 4 | import org.bukkit.World; 5 | import org.bukkit.block.Block; 6 | import org.bukkit.event.EventHandler; 7 | import org.bukkit.event.Listener; 8 | import org.bukkit.event.block.BlockFadeEvent; 9 | 10 | import net.coreprotect.config.Config; 11 | import net.coreprotect.consumer.Queue; 12 | 13 | public final class BlockFadeListener extends Queue implements Listener { 14 | 15 | @EventHandler 16 | protected void onBlockFade(BlockFadeEvent event) { 17 | // snow/ice fading 18 | if (event.isCancelled()) { 19 | return; 20 | } 21 | 22 | Block block = event.getBlock(); 23 | if (block.getType().equals(Material.TURTLE_EGG)) { 24 | World world = block.getWorld(); 25 | if (!Config.getConfig(world).ENTITY_CHANGE) { 26 | return; 27 | } 28 | 29 | Queue.queueBlockBreak("#turtle", block.getState(), block.getType(), block.getBlockData().getAsString(), 0); 30 | } 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/net/coreprotect/listener/block/BlockFertilizeListener.java: -------------------------------------------------------------------------------- 1 | package net.coreprotect.listener.block; 2 | 3 | import java.util.List; 4 | import java.util.Locale; 5 | 6 | import org.bukkit.Location; 7 | import org.bukkit.Material; 8 | import org.bukkit.Tag; 9 | import org.bukkit.block.Block; 10 | import org.bukkit.block.BlockState; 11 | import org.bukkit.entity.Player; 12 | import org.bukkit.event.EventHandler; 13 | import org.bukkit.event.EventPriority; 14 | import org.bukkit.event.Listener; 15 | import org.bukkit.event.block.BlockFertilizeEvent; 16 | 17 | import net.coreprotect.config.Config; 18 | import net.coreprotect.consumer.Queue; 19 | import net.coreprotect.thread.CacheHandler; 20 | 21 | public final class BlockFertilizeListener extends Queue implements Listener { 22 | 23 | @EventHandler(priority = EventPriority.MONITOR) 24 | protected void onBlockFertilize(BlockFertilizeEvent event) { 25 | if (event.isCancelled()) { 26 | return; 27 | } 28 | 29 | Block block = event.getBlock(); 30 | if (!Config.getConfig(block.getWorld()).BLOCK_PLACE) { 31 | return; 32 | } 33 | 34 | Location location = block.getLocation(); 35 | List blocks = event.getBlocks(); 36 | 37 | if (Tag.SAPLINGS.isTagged(block.getType()) && (!Config.getConfig(location.getWorld()).TREE_GROWTH || (blocks.size() == 1 && blocks.get(0).getLocation().equals(location)))) { 38 | return; 39 | } 40 | if (block.getType().name().toLowerCase(Locale.ROOT).contains("mushroom") && (!Config.getConfig(location.getWorld()).MUSHROOM_GROWTH || (blocks.size() == 1 && blocks.get(0).getLocation().equals(location)))) { 41 | return; 42 | } 43 | if (block.getType() == Material.AIR && blocks.size() > 1 && Tag.LOGS.isTagged(blocks.get(1).getType()) && !Config.getConfig(location.getWorld()).TREE_GROWTH) { 44 | return; 45 | } 46 | 47 | String user = "#bonemeal"; 48 | Player player = event.getPlayer(); 49 | if (player != null) { 50 | user = player.getName(); 51 | } 52 | else { 53 | Object[] data = CacheHandler.redstoneCache.get(location); 54 | if (data != null) { 55 | long newTime = System.currentTimeMillis(); 56 | long oldTime = (long) data[0]; 57 | if ((newTime - oldTime) < 50) { // check that within same tick 58 | user = (String) data[1]; 59 | } 60 | 61 | CacheHandler.redstoneCache.remove(location); 62 | } 63 | } 64 | 65 | for (BlockState newBlock : blocks) { 66 | Queue.queueBlockPlace(user, newBlock, newBlock.getType(), newBlock.getBlock().getState(), newBlock.getType(), -1, 0, newBlock.getBlockData().getAsString()); 67 | } 68 | } 69 | 70 | } 71 | -------------------------------------------------------------------------------- /src/main/java/net/coreprotect/listener/block/CampfireStartListener.java: -------------------------------------------------------------------------------- 1 | package net.coreprotect.listener.block; 2 | 3 | import org.bukkit.Location; 4 | import org.bukkit.block.Block; 5 | import org.bukkit.event.EventHandler; 6 | import org.bukkit.event.EventPriority; 7 | import org.bukkit.event.Listener; 8 | import org.bukkit.event.block.CampfireStartEvent; 9 | import org.bukkit.inventory.ItemStack; 10 | 11 | import net.coreprotect.consumer.Queue; 12 | import net.coreprotect.listener.player.PlayerDropItemListener; 13 | import net.coreprotect.thread.CacheHandler; 14 | import net.coreprotect.utility.WorldUtils; 15 | 16 | public final class CampfireStartListener extends Queue implements Listener { 17 | 18 | public static boolean useCampfireStartEvent = true; 19 | 20 | @EventHandler(priority = EventPriority.MONITOR) 21 | protected void onCampfireStart(CampfireStartEvent event) { 22 | Block block = event.getBlock(); 23 | Location location = block.getLocation(); 24 | int worldId = WorldUtils.getWorldId(location.getWorld().getName()); 25 | int x = location.getBlockX(); 26 | int y = location.getBlockY(); 27 | int z = location.getBlockZ(); 28 | String coordinates = x + "." + y + "." + z + "." + worldId + "." + block.getType().name(); 29 | String user = "#entity"; 30 | 31 | Object[] data = CacheHandler.interactCache.get(coordinates); 32 | if (data != null && data[1].equals(event.getSource())) { 33 | long newTime = System.currentTimeMillis(); 34 | long oldTime = (long) data[0]; 35 | if ((newTime - oldTime) < 20) { // 50ms = 1 tick 36 | user = (String) data[2]; 37 | } 38 | CacheHandler.interactCache.remove(coordinates); 39 | } 40 | 41 | if (user.equals("#entity")) { 42 | return; 43 | } 44 | 45 | ItemStack itemStack = event.getSource().clone(); 46 | itemStack.setAmount(1); 47 | PlayerDropItemListener.playerDropItem(event.getBlock().getLocation(), user, itemStack); 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /src/main/java/net/coreprotect/listener/entity/CreatureSpawnListener.java: -------------------------------------------------------------------------------- 1 | package net.coreprotect.listener.entity; 2 | 3 | import java.util.Iterator; 4 | import java.util.Map; 5 | import java.util.Map.Entry; 6 | 7 | import org.bukkit.Location; 8 | import org.bukkit.Material; 9 | import org.bukkit.World; 10 | import org.bukkit.block.Block; 11 | import org.bukkit.entity.EntityType; 12 | import org.bukkit.event.EventHandler; 13 | import org.bukkit.event.Listener; 14 | import org.bukkit.event.entity.CreatureSpawnEvent; 15 | import org.bukkit.inventory.ItemStack; 16 | 17 | import net.coreprotect.config.Config; 18 | import net.coreprotect.config.ConfigHandler; 19 | import net.coreprotect.consumer.Queue; 20 | import net.coreprotect.listener.block.BlockUtil; 21 | import net.coreprotect.utility.EntityUtils; 22 | 23 | public final class CreatureSpawnListener extends Queue implements Listener { 24 | 25 | @EventHandler 26 | public void onCreatureSpawn(CreatureSpawnEvent event) { 27 | if (event.isCancelled() || !event.getEntityType().equals(EntityType.ARMOR_STAND)) { 28 | return; 29 | } 30 | 31 | World world = event.getEntity().getWorld(); 32 | if (!Config.getConfig(world).BLOCK_PLACE) { 33 | return; 34 | } 35 | 36 | Location location = event.getEntity().getLocation(); 37 | String key = world.getName() + "-" + location.getBlockX() + "-" + location.getBlockY() + "-" + location.getBlockZ(); 38 | Iterator> it = ConfigHandler.entityBlockMapper.entrySet().iterator(); 39 | while (it.hasNext()) { 40 | Map.Entry pair = it.next(); 41 | String name = pair.getKey(); 42 | Object[] data = pair.getValue(); 43 | if ((data[1].equals(key) || data[2].equals(key)) && EntityUtils.getEntityMaterial(event.getEntityType()) == ((ItemStack) data[3]).getType()) { 44 | Block gravityLocation = BlockUtil.gravityScan(location, Material.ARMOR_STAND, name); 45 | Queue.queueBlockPlace(name, gravityLocation.getState(), location.getBlock().getType(), location.getBlock().getState(), ((ItemStack) data[3]).getType(), (int) event.getEntity().getLocation().getYaw(), 1, null); 46 | it.remove(); 47 | } 48 | } 49 | } 50 | 51 | } 52 | -------------------------------------------------------------------------------- /src/main/java/net/coreprotect/listener/entity/EntityBlockFormListener.java: -------------------------------------------------------------------------------- 1 | package net.coreprotect.listener.entity; 2 | 3 | import org.bukkit.World; 4 | import org.bukkit.block.Block; 5 | import org.bukkit.block.BlockState; 6 | import org.bukkit.entity.Entity; 7 | import org.bukkit.entity.Snowman; 8 | import org.bukkit.event.EventHandler; 9 | import org.bukkit.event.EventPriority; 10 | import org.bukkit.event.Listener; 11 | import org.bukkit.event.block.EntityBlockFormEvent; 12 | 13 | import net.coreprotect.config.Config; 14 | import net.coreprotect.consumer.Queue; 15 | 16 | public final class EntityBlockFormListener extends Queue implements Listener { 17 | 18 | @EventHandler(priority = EventPriority.MONITOR) 19 | protected void onEntityBlockForm(EntityBlockFormEvent event) { 20 | World world = event.getBlock().getWorld(); 21 | if (!event.isCancelled() && Config.getConfig(world).ENTITY_CHANGE) { 22 | Entity entity = event.getEntity(); 23 | Block block = event.getBlock(); 24 | BlockState newState = event.getNewState(); 25 | String e = ""; 26 | if (entity instanceof Snowman) { 27 | e = "#snowman"; 28 | } 29 | if (e.length() > 0) { 30 | Queue.queueBlockPlace(e, block.getState(), block.getType(), null, newState.getType(), -1, 0, newState.getBlockData().getAsString()); 31 | } 32 | } 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/net/coreprotect/listener/entity/EntityChangeBlockListener.java: -------------------------------------------------------------------------------- 1 | package net.coreprotect.listener.entity; 2 | 3 | import org.bukkit.Material; 4 | import org.bukkit.World; 5 | import org.bukkit.block.Block; 6 | import org.bukkit.entity.EnderDragon; 7 | import org.bukkit.entity.Enderman; 8 | import org.bukkit.entity.Entity; 9 | import org.bukkit.entity.Fox; 10 | import org.bukkit.entity.Ravager; 11 | import org.bukkit.entity.Silverfish; 12 | import org.bukkit.entity.Turtle; 13 | import org.bukkit.entity.Wither; 14 | import org.bukkit.event.EventHandler; 15 | import org.bukkit.event.EventPriority; 16 | import org.bukkit.event.Listener; 17 | import org.bukkit.event.entity.EntityChangeBlockEvent; 18 | 19 | import net.coreprotect.config.Config; 20 | import net.coreprotect.consumer.Queue; 21 | 22 | public final class EntityChangeBlockListener extends Queue implements Listener { 23 | 24 | @EventHandler(priority = EventPriority.MONITOR) 25 | protected void onEntityChangeBlock(EntityChangeBlockEvent event) { 26 | World world = event.getBlock().getWorld(); 27 | if (!event.isCancelled() && Config.getConfig(world).ENTITY_CHANGE) { 28 | Entity entity = event.getEntity(); // Can be sand/gravel 29 | Block block = event.getBlock(); 30 | Material newtype = event.getTo(); 31 | Material type = event.getBlock().getType(); 32 | String e = ""; 33 | if (entity instanceof Enderman) { 34 | e = "#enderman"; 35 | } 36 | else if (entity instanceof EnderDragon) { 37 | e = "#enderdragon"; 38 | } 39 | else if (entity instanceof Fox) { 40 | e = "#fox"; 41 | } 42 | else if (entity instanceof Wither) { 43 | e = "#wither"; 44 | } 45 | else if (entity instanceof Turtle) { 46 | e = "#turtle"; 47 | } 48 | else if (entity instanceof Ravager) { 49 | e = "#ravager"; 50 | } 51 | else if (entity instanceof Silverfish) { 52 | if (newtype.equals(Material.AIR) || newtype.equals(Material.CAVE_AIR)) { 53 | e = "#silverfish"; 54 | } 55 | } 56 | else if (entity.getType().name().equals("WIND_CHARGE")) { 57 | e = "#windcharge"; 58 | } 59 | else if (entity.getType().name().equals("BREEZE_WIND_CHARGE")) { 60 | e = "#breezewindcharge"; 61 | } 62 | if (e.length() > 0) { 63 | if (newtype.equals(Material.AIR) || newtype.equals(Material.CAVE_AIR)) { 64 | Queue.queueBlockBreak(e, block.getState(), type, block.getBlockData().getAsString(), 0); 65 | } 66 | else { 67 | queueBlockPlace(e, block.getState(), type, block.getState(), newtype, -1, 0, event.getBlockData().getAsString()); 68 | } 69 | } 70 | } 71 | } 72 | 73 | } 74 | -------------------------------------------------------------------------------- /src/main/java/net/coreprotect/listener/entity/EntityDamageByBlockListener.java: -------------------------------------------------------------------------------- 1 | package net.coreprotect.listener.entity; 2 | 3 | import java.util.Locale; 4 | 5 | import org.bukkit.Material; 6 | import org.bukkit.block.Block; 7 | import org.bukkit.entity.ArmorStand; 8 | import org.bukkit.entity.EnderCrystal; 9 | import org.bukkit.entity.Entity; 10 | import org.bukkit.entity.ItemFrame; 11 | import org.bukkit.event.EventHandler; 12 | import org.bukkit.event.EventPriority; 13 | import org.bukkit.event.Listener; 14 | import org.bukkit.event.entity.EntityDamageByBlockEvent; 15 | import org.bukkit.inventory.ItemStack; 16 | 17 | import net.coreprotect.config.Config; 18 | import net.coreprotect.consumer.Queue; 19 | import net.coreprotect.database.Database; 20 | import net.coreprotect.listener.player.PlayerInteractEntityListener; 21 | 22 | public final class EntityDamageByBlockListener extends Queue implements Listener { 23 | 24 | @EventHandler(priority = EventPriority.MONITOR) 25 | protected void onEntityDamageByBlock(EntityDamageByBlockEvent event) { 26 | Entity entity = event.getEntity(); 27 | if (!(entity instanceof ItemFrame) && !(entity instanceof ArmorStand) && !(entity instanceof EnderCrystal)) { 28 | return; 29 | } 30 | 31 | Block damager = event.getDamager(); 32 | if (damager == null || damager.getType() == Material.MAGMA_BLOCK) { 33 | return; 34 | } 35 | 36 | if (event.isCancelled()) { 37 | return; 38 | } 39 | 40 | Block block = entity.getLocation().getBlock(); 41 | String user = "#" + damager.getType().name().toLowerCase(Locale.ROOT); 42 | if (user.contains("tnt")) { 43 | user = "#tnt"; 44 | } 45 | 46 | if (entity instanceof ItemFrame && Config.getConfig(entity.getWorld()).ITEM_TRANSACTIONS) { 47 | ItemFrame frame = (ItemFrame) entity; 48 | if (frame.getItem().getType() != Material.AIR) { 49 | ItemStack[] oldState = new ItemStack[] { frame.getItem().clone() }; 50 | ItemStack[] newState = new ItemStack[] { new ItemStack(Material.AIR) }; 51 | PlayerInteractEntityListener.queueContainerSpecifiedItems(user, Material.ITEM_FRAME, new Object[] { oldState, newState, frame.getFacing() }, frame.getLocation(), false); 52 | } 53 | } 54 | else if (entity instanceof ArmorStand && Config.getConfig(entity.getWorld()).BLOCK_BREAK) { 55 | Database.containerBreakCheck(user, Material.ARMOR_STAND, entity, null, block.getLocation()); 56 | Queue.queueBlockBreak(user, block.getState(), Material.ARMOR_STAND, null, (int) entity.getLocation().getYaw()); 57 | } 58 | else if (entity instanceof EnderCrystal && Config.getConfig(entity.getWorld()).BLOCK_BREAK) { 59 | EnderCrystal crystal = (EnderCrystal) event.getEntity(); 60 | Queue.queueBlockBreak(user, block.getState(), Material.END_CRYSTAL, null, crystal.isShowingBottom() ? 1 : 0); 61 | } 62 | } 63 | 64 | } 65 | -------------------------------------------------------------------------------- /src/main/java/net/coreprotect/listener/entity/EntityExplodeListener.java: -------------------------------------------------------------------------------- 1 | package net.coreprotect.listener.entity; 2 | 3 | import org.bukkit.World; 4 | import org.bukkit.entity.Creeper; 5 | import org.bukkit.entity.EnderCrystal; 6 | import org.bukkit.entity.EnderDragon; 7 | import org.bukkit.entity.EnderDragonPart; 8 | import org.bukkit.entity.Entity; 9 | import org.bukkit.entity.Minecart; 10 | import org.bukkit.entity.TNTPrimed; 11 | import org.bukkit.entity.Wither; 12 | import org.bukkit.entity.WitherSkull; 13 | import org.bukkit.event.EventHandler; 14 | import org.bukkit.event.EventPriority; 15 | import org.bukkit.event.Listener; 16 | import org.bukkit.event.entity.EntityExplodeEvent; 17 | 18 | import net.coreprotect.config.Config; 19 | import net.coreprotect.consumer.Queue; 20 | import net.coreprotect.listener.block.BlockExplodeListener; 21 | 22 | public final class EntityExplodeListener extends Queue implements Listener { 23 | 24 | @EventHandler(priority = EventPriority.MONITOR) 25 | protected void onEntityExplode(EntityExplodeEvent event) { 26 | Entity entity = event.getEntity(); 27 | if (entity.getType().name().equals("WIND_CHARGE") || entity.getType().name().equals("BREEZE_WIND_CHARGE")) { 28 | return; 29 | } 30 | 31 | World world = event.getLocation().getWorld(); 32 | String user = "#explosion"; 33 | 34 | if (entity instanceof TNTPrimed) { 35 | user = "#tnt"; 36 | } 37 | else if (entity instanceof Minecart) { 38 | String name = entity.getType().name(); 39 | if (name.contains("TNT")) { 40 | user = "#tnt"; 41 | } 42 | } 43 | else if (entity instanceof Creeper) { 44 | user = "#creeper"; 45 | } 46 | else if (entity instanceof EnderDragon || entity instanceof EnderDragonPart) { 47 | user = "#enderdragon"; 48 | } 49 | else if (entity instanceof Wither || entity instanceof WitherSkull) { 50 | user = "#wither"; 51 | } 52 | else if (entity instanceof EnderCrystal) { 53 | user = "#end_crystal"; 54 | } 55 | 56 | boolean log = false; 57 | if (Config.getConfig(world).EXPLOSIONS) { 58 | log = true; 59 | } 60 | 61 | if ((user.equals("#enderdragon") || user.equals("#wither")) && !Config.getConfig(world).ENTITY_CHANGE) { 62 | log = false; 63 | } 64 | 65 | if (!event.isCancelled() && log) { 66 | BlockExplodeListener.processBlockExplode(user, world, event.blockList()); 67 | } 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /src/main/java/net/coreprotect/listener/entity/EntityInteractListener.java: -------------------------------------------------------------------------------- 1 | package net.coreprotect.listener.entity; 2 | 3 | import java.util.Locale; 4 | 5 | import org.bukkit.Material; 6 | import org.bukkit.World; 7 | import org.bukkit.block.Block; 8 | import org.bukkit.entity.EntityType; 9 | import org.bukkit.event.EventHandler; 10 | import org.bukkit.event.EventPriority; 11 | import org.bukkit.event.Listener; 12 | import org.bukkit.event.entity.EntityInteractEvent; 13 | 14 | import net.coreprotect.config.Config; 15 | import net.coreprotect.consumer.Queue; 16 | 17 | public final class EntityInteractListener extends Queue implements Listener { 18 | 19 | @EventHandler(priority = EventPriority.MONITOR) 20 | protected void onEntityInteractEntity(EntityInteractEvent event) { 21 | Block block = event.getBlock(); 22 | World world = block.getWorld(); 23 | if (event.isCancelled() || !Config.getConfig(world).ENTITY_CHANGE) { 24 | return; 25 | } 26 | if (!block.getType().equals(Material.TURTLE_EGG)) { 27 | return; 28 | } 29 | 30 | EntityType entityType = event.getEntityType(); 31 | String user = "#entity"; 32 | if (entityType != null) { 33 | user = "#" + entityType.name().toLowerCase(Locale.ROOT); 34 | } 35 | 36 | Queue.queueBlockBreak(user, block.getState(), block.getType(), block.getBlockData().getAsString(), 0); 37 | Queue.queueBlockPlaceDelayed(user, block.getLocation(), block.getType(), null, null, 0); 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/net/coreprotect/listener/entity/EntityPickupItemListener.java: -------------------------------------------------------------------------------- 1 | package net.coreprotect.listener.entity; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | import java.util.Locale; 6 | 7 | import org.bukkit.Location; 8 | import org.bukkit.entity.EntityType; 9 | import org.bukkit.entity.Item; 10 | import org.bukkit.entity.Player; 11 | import org.bukkit.event.EventHandler; 12 | import org.bukkit.event.EventPriority; 13 | import org.bukkit.event.Listener; 14 | import org.bukkit.event.entity.EntityPickupItemEvent; 15 | import org.bukkit.inventory.ItemStack; 16 | 17 | import net.coreprotect.config.Config; 18 | import net.coreprotect.config.ConfigHandler; 19 | import net.coreprotect.consumer.Queue; 20 | 21 | public final class EntityPickupItemListener extends Queue implements Listener { 22 | 23 | public static void onItemPickup(Player player, Location location, ItemStack itemStack) { 24 | if (itemStack == null || location == null || !Config.getConfig(location.getWorld()).ITEM_PICKUPS) { 25 | return; 26 | } 27 | 28 | String loggingItemId = player.getName().toLowerCase(Locale.ROOT) + "." + location.getBlockX() + "." + location.getBlockY() + "." + location.getBlockZ(); 29 | int itemId = getItemId(loggingItemId); 30 | 31 | List list = ConfigHandler.itemsPickup.getOrDefault(loggingItemId, new ArrayList<>()); 32 | list.add(itemStack.clone()); 33 | ConfigHandler.itemsPickup.put(loggingItemId, list); 34 | 35 | int time = (int) (System.currentTimeMillis() / 1000L) + 1; 36 | Queue.queueItemTransaction(player.getName(), location.clone(), time, 0, itemId); 37 | } 38 | 39 | @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) 40 | protected void onEntityPickupItem(EntityPickupItemEvent event) { 41 | if (event.getEntityType() != EntityType.PLAYER) { 42 | return; 43 | } 44 | 45 | Player player = (Player) event.getEntity(); 46 | Item item = event.getItem(); 47 | onItemPickup(player, item.getLocation(), item.getItemStack()); 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /src/main/java/net/coreprotect/listener/entity/HangingPlaceListener.java: -------------------------------------------------------------------------------- 1 | package net.coreprotect.listener.entity; 2 | 3 | import org.bukkit.Material; 4 | import org.bukkit.block.Block; 5 | import org.bukkit.entity.Entity; 6 | import org.bukkit.entity.ItemFrame; 7 | import org.bukkit.entity.Painting; 8 | import org.bukkit.entity.Player; 9 | import org.bukkit.event.EventHandler; 10 | import org.bukkit.event.EventPriority; 11 | import org.bukkit.event.Listener; 12 | import org.bukkit.event.hanging.HangingPlaceEvent; 13 | 14 | import net.coreprotect.bukkit.BukkitAdapter; 15 | import net.coreprotect.config.Config; 16 | import net.coreprotect.config.ConfigHandler; 17 | import net.coreprotect.consumer.Queue; 18 | import net.coreprotect.utility.MaterialUtils; 19 | 20 | public final class HangingPlaceListener extends Queue implements Listener { 21 | 22 | @EventHandler(priority = EventPriority.HIGHEST) 23 | protected void onHangingPlace(HangingPlaceEvent event) { 24 | Entity entity = event.getEntity(); 25 | Player player = event.getPlayer(); 26 | 27 | if (entity instanceof ItemFrame || entity instanceof Painting) { 28 | Block blockEvent = event.getEntity().getLocation().getBlock(); 29 | String blockData = null; 30 | Material material; 31 | int artId; 32 | 33 | if (entity instanceof ItemFrame) { 34 | material = BukkitAdapter.ADAPTER.getFrameType(entity); 35 | ItemFrame itemFrame = (ItemFrame) entity; 36 | blockData = "FACING=" + itemFrame.getFacing().name(); 37 | artId = 0; 38 | } 39 | else { 40 | material = Material.PAINTING; 41 | Painting painting = (Painting) entity; 42 | blockData = "FACING=" + painting.getFacing().name(); 43 | try { 44 | artId = MaterialUtils.getArtId(painting.getArt().toString(), true); 45 | } 46 | catch (IncompatibleClassChangeError e) { 47 | artId = 0; 48 | // 1.21.2+ 49 | } 50 | } 51 | 52 | int inspect = 0; 53 | if (ConfigHandler.inspecting.get(player.getName()) != null) { 54 | if (ConfigHandler.inspecting.get(player.getName())) { 55 | inspect = 1; 56 | event.setCancelled(true); 57 | } 58 | } 59 | 60 | if (!event.isCancelled() && Config.getConfig(blockEvent.getWorld()).BLOCK_PLACE && inspect == 0) { 61 | Queue.queueBlockPlace(player.getName(), blockEvent.getState(), blockEvent.getType(), null, material, artId, 1, blockData); 62 | } 63 | } 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/main/java/net/coreprotect/listener/player/InventoryClickListener.java: -------------------------------------------------------------------------------- 1 | package net.coreprotect.listener.player; 2 | 3 | import org.bukkit.event.EventHandler; 4 | import org.bukkit.event.EventPriority; 5 | import org.bukkit.event.Listener; 6 | import org.bukkit.event.inventory.InventoryClickEvent; 7 | 8 | import net.coreprotect.consumer.Queue; 9 | 10 | public final class InventoryClickListener extends Queue implements Listener { 11 | 12 | @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) 13 | protected void onVillagerTrade(InventoryClickEvent event) { 14 | CraftItemListener.playerCraftItem(event, true); 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/net/coreprotect/listener/player/PlayerBucketEmptyListener.java: -------------------------------------------------------------------------------- 1 | package net.coreprotect.listener.player; 2 | 3 | import org.bukkit.Material; 4 | import org.bukkit.World; 5 | import org.bukkit.block.Block; 6 | import org.bukkit.block.BlockState; 7 | import org.bukkit.block.data.BlockData; 8 | import org.bukkit.block.data.Waterlogged; 9 | import org.bukkit.event.EventHandler; 10 | import org.bukkit.event.EventPriority; 11 | import org.bukkit.event.Listener; 12 | 13 | import net.coreprotect.config.Config; 14 | import net.coreprotect.config.ConfigHandler; 15 | import net.coreprotect.consumer.Queue; 16 | import net.coreprotect.thread.CacheHandler; 17 | import net.coreprotect.utility.WorldUtils; 18 | 19 | public final class PlayerBucketEmptyListener extends Queue implements Listener { 20 | 21 | @EventHandler(priority = EventPriority.HIGHEST) 22 | protected void onPlayerBucketEmpty(org.bukkit.event.player.PlayerBucketEmptyEvent event) { 23 | String player = event.getPlayer().getName(); 24 | World world = event.getPlayer().getWorld(); 25 | int inspect = 0; 26 | 27 | if (ConfigHandler.inspecting.get(player) != null) { 28 | if (ConfigHandler.inspecting.get(player)) { 29 | inspect = 1; 30 | event.setCancelled(true); 31 | } 32 | } 33 | 34 | if (!event.isCancelled() && Config.getConfig(world).BUCKETS && inspect == 0) { 35 | Block block = event.getBlockClicked(); 36 | BlockData blockData = block.getBlockData(); 37 | Material type = Material.WATER; 38 | if (event.getBucket().equals(Material.LAVA_BUCKET)) { 39 | type = Material.LAVA; 40 | } 41 | 42 | boolean getRelative = true; 43 | if (blockData instanceof Waterlogged) { 44 | if (type.equals(Material.WATER)) { 45 | boolean isWaterlogged = ((Waterlogged) blockData).isWaterlogged(); 46 | if (!isWaterlogged) { 47 | getRelative = false; 48 | } 49 | } 50 | } 51 | if (getRelative) { 52 | block = block.getRelative(event.getBlockFace()); 53 | blockData = block.getBlockData(); 54 | } 55 | 56 | BlockState blockState = block.getState(); 57 | int worldId = WorldUtils.getWorldId(block.getWorld().getName()); 58 | int unixTimestamp = (int) (System.currentTimeMillis() / 1000L); 59 | 60 | if (type.equals(Material.WATER)) { 61 | if (blockData instanceof Waterlogged) { 62 | blockState = null; 63 | } 64 | } 65 | 66 | CacheHandler.lookupCache.put("" + block.getX() + "." + block.getY() + "." + block.getZ() + "." + worldId + "", new Object[] { unixTimestamp, player, type }); 67 | queueBlockPlace(player, block.getState(), block.getType(), blockState, type, 1, 1, null); 68 | } 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /src/main/java/net/coreprotect/listener/player/PlayerBucketFillListener.java: -------------------------------------------------------------------------------- 1 | package net.coreprotect.listener.player; 2 | 3 | import org.bukkit.Material; 4 | import org.bukkit.World; 5 | import org.bukkit.block.Block; 6 | import org.bukkit.block.data.BlockData; 7 | import org.bukkit.block.data.Waterlogged; 8 | import org.bukkit.event.EventHandler; 9 | import org.bukkit.event.EventPriority; 10 | import org.bukkit.event.Listener; 11 | import org.bukkit.event.player.PlayerBucketFillEvent; 12 | 13 | import net.coreprotect.config.Config; 14 | import net.coreprotect.config.ConfigHandler; 15 | import net.coreprotect.consumer.Queue; 16 | 17 | public final class PlayerBucketFillListener extends Queue implements Listener { 18 | 19 | @EventHandler(priority = EventPriority.HIGHEST) 20 | protected void onPlayerBucketFill(PlayerBucketFillEvent event) { 21 | String player = event.getPlayer().getName(); 22 | Block block = event.getBlockClicked(); 23 | World world = block.getWorld(); 24 | Material type = block.getType(); 25 | 26 | int inspect = 0; 27 | if (ConfigHandler.inspecting.get(player) != null) { 28 | if (ConfigHandler.inspecting.get(player)) { 29 | inspect = 1; 30 | event.setCancelled(true); 31 | } 32 | } 33 | 34 | if (!event.isCancelled() && Config.getConfig(world).BUCKETS && inspect == 0) { 35 | BlockData blockData = block.getBlockData(); 36 | if (blockData instanceof Waterlogged) { 37 | Waterlogged waterlogged = (Waterlogged) blockData; 38 | if (waterlogged.isWaterlogged()) { 39 | type = Material.WATER; 40 | } 41 | } 42 | 43 | Queue.queueBlockBreak(player, block.getState(), type, block.getBlockData().getAsString(), 0); 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/net/coreprotect/listener/player/PlayerChatListener.java: -------------------------------------------------------------------------------- 1 | package net.coreprotect.listener.player; 2 | 3 | import org.bukkit.entity.Player; 4 | import org.bukkit.event.EventHandler; 5 | import org.bukkit.event.EventPriority; 6 | import org.bukkit.event.Listener; 7 | import org.bukkit.event.player.AsyncPlayerChatEvent; 8 | 9 | import net.coreprotect.config.Config; 10 | import net.coreprotect.consumer.Queue; 11 | 12 | public final class PlayerChatListener extends Queue implements Listener { 13 | 14 | @EventHandler(priority = EventPriority.MONITOR) 15 | public void onPlayerChat(AsyncPlayerChatEvent event) { 16 | String message = event.getMessage(); 17 | if (message == null) { 18 | return; 19 | } 20 | 21 | Player player = event.getPlayer(); 22 | if (event.isCancelled() && !Config.getConfig(player.getWorld()).LOG_CANCELLED_CHAT) { 23 | return; 24 | } 25 | 26 | if (!message.startsWith("/") && Config.getConfig(player.getWorld()).PLAYER_MESSAGES) { 27 | long timestamp = System.currentTimeMillis() / 1000L; 28 | Queue.queuePlayerChat(player, message, timestamp); 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/net/coreprotect/listener/player/PlayerCommandListener.java: -------------------------------------------------------------------------------- 1 | package net.coreprotect.listener.player; 2 | 3 | import org.bukkit.entity.Player; 4 | import org.bukkit.event.EventHandler; 5 | import org.bukkit.event.EventPriority; 6 | import org.bukkit.event.Listener; 7 | import org.bukkit.event.player.PlayerCommandPreprocessEvent; 8 | 9 | import net.coreprotect.config.Config; 10 | import net.coreprotect.consumer.Queue; 11 | 12 | public final class PlayerCommandListener extends Queue implements Listener { 13 | 14 | @EventHandler(priority = EventPriority.MONITOR) 15 | public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) { 16 | Player player = event.getPlayer(); 17 | if (Config.getConfig(player.getWorld()).PLAYER_COMMANDS) { 18 | long timestamp = System.currentTimeMillis() / 1000L; 19 | Queue.queuePlayerCommand(player, event.getMessage(), timestamp); 20 | } 21 | 22 | /* 23 | if (Config.getGlobal().ENTITY_KILLS && player.hasPermission("bukkit.command.kill")) { 24 | EntityDeathListener.parseEntityKills(event.getMessage()); 25 | } 26 | */ 27 | } 28 | 29 | /* 30 | @EventHandler(priority = EventPriority.MONITOR) 31 | public void onServerCommand(ServerCommandEvent event) { 32 | if (Config.getGlobal().ENTITY_KILLS && event.getCommand().toLowerCase(Locale.ROOT).startsWith("kill")) { 33 | EntityDeathListener.parseEntityKills(event.getCommand()); 34 | } 35 | } 36 | */ 37 | 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/net/coreprotect/listener/player/PlayerDeathListener.java: -------------------------------------------------------------------------------- 1 | package net.coreprotect.listener.player; 2 | 3 | import java.util.List; 4 | 5 | import org.bukkit.Location; 6 | import org.bukkit.entity.Entity; 7 | import org.bukkit.entity.Player; 8 | import org.bukkit.event.EventHandler; 9 | import org.bukkit.event.EventPriority; 10 | import org.bukkit.event.Listener; 11 | import org.bukkit.event.entity.PlayerDeathEvent; 12 | import org.bukkit.inventory.ItemStack; 13 | 14 | import net.coreprotect.config.Config; 15 | import net.coreprotect.consumer.Queue; 16 | 17 | public final class PlayerDeathListener extends Queue implements Listener { 18 | 19 | @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) 20 | protected void onPlayerDeath(PlayerDeathEvent event) { 21 | if (event.getKeepInventory()) { 22 | return; 23 | } 24 | 25 | Entity entity = event.getEntity(); 26 | if (!(entity instanceof Player)) { 27 | return; 28 | } 29 | 30 | Location location = entity.getLocation(); 31 | if (!Config.getConfig(location.getWorld()).ITEM_DROPS) { 32 | return; 33 | } 34 | 35 | String user = ((Player) entity).getName(); 36 | List items = event.getDrops(); 37 | if (items == null || items.size() == 0) { 38 | return; 39 | } 40 | 41 | for (ItemStack itemStack : items) { 42 | PlayerDropItemListener.playerDropItem(location, user, itemStack); 43 | } 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/net/coreprotect/listener/player/PlayerDropItemListener.java: -------------------------------------------------------------------------------- 1 | package net.coreprotect.listener.player; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | import java.util.Locale; 6 | 7 | import org.bukkit.Location; 8 | import org.bukkit.entity.Item; 9 | import org.bukkit.event.EventHandler; 10 | import org.bukkit.event.EventPriority; 11 | import org.bukkit.event.Listener; 12 | import org.bukkit.event.player.PlayerDropItemEvent; 13 | import org.bukkit.inventory.ItemStack; 14 | 15 | import net.coreprotect.config.Config; 16 | import net.coreprotect.config.ConfigHandler; 17 | import net.coreprotect.consumer.Queue; 18 | 19 | public final class PlayerDropItemListener extends Queue implements Listener { 20 | 21 | public static void playerDropItem(Location location, String user, ItemStack itemStack) { 22 | if (!Config.getConfig(location.getWorld()).ITEM_DROPS || itemStack == null) { 23 | return; 24 | } 25 | 26 | String loggingItemId = user.toLowerCase(Locale.ROOT) + "." + location.getBlockX() + "." + location.getBlockY() + "." + location.getBlockZ(); 27 | int itemId = getItemId(loggingItemId); 28 | 29 | List list = ConfigHandler.itemsDrop.getOrDefault(loggingItemId, new ArrayList<>()); 30 | list.add(itemStack.clone()); 31 | ConfigHandler.itemsDrop.put(loggingItemId, list); 32 | 33 | int time = (int) (System.currentTimeMillis() / 1000L) + 1; 34 | Queue.queueItemTransaction(user, location.clone(), time, 0, itemId); 35 | } 36 | 37 | @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) 38 | protected void onPlayerDropItem(PlayerDropItemEvent event) { 39 | Item item = event.getItemDrop(); 40 | ItemStack itemStack = item.getItemStack(); 41 | playerDropItem(item.getLocation(), event.getPlayer().getName(), itemStack); 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/net/coreprotect/listener/player/PlayerInteractUtils.java: -------------------------------------------------------------------------------- 1 | package net.coreprotect.listener.player; 2 | 3 | import org.bukkit.Location; 4 | import org.bukkit.Material; 5 | import org.bukkit.World; 6 | import org.bukkit.block.Block; 7 | import org.bukkit.entity.Player; 8 | 9 | import net.coreprotect.thread.CacheHandler; 10 | import net.coreprotect.utility.WorldUtils; 11 | 12 | public final class PlayerInteractUtils { 13 | 14 | private PlayerInteractUtils() { 15 | // Utility class, prevent instantiation 16 | } 17 | 18 | public static void clickedDragonEgg(Player player, Block block) { 19 | Location location = block.getLocation(); 20 | long time = System.currentTimeMillis(); 21 | int wid = WorldUtils.getWorldId(location.getWorld().getName()); 22 | int x = location.getBlockX(); 23 | int y = location.getBlockY(); 24 | int z = location.getBlockZ(); 25 | String coordinates = x + "." + y + "." + z + "." + wid + "." + Material.DRAGON_EGG.name(); 26 | CacheHandler.interactCache.put(coordinates, new Object[] { time, Material.DRAGON_EGG, player.getName() }); 27 | } 28 | 29 | public static void handleBisectedBlockVisualization(Player player, Block block, World world) { 30 | int x = block.getX(); 31 | int y = block.getY(); 32 | int z = block.getZ(); 33 | 34 | int worldMaxHeight = world.getMaxHeight(); 35 | if (y < (worldMaxHeight - 1)) { 36 | Block y1 = world.getBlockAt(x, y + 1, z); 37 | player.sendBlockChange(y1.getLocation(), y1.getBlockData()); 38 | } 39 | 40 | int worldMinHeight = net.coreprotect.bukkit.BukkitAdapter.ADAPTER.getMinHeight(world); 41 | if (y > worldMinHeight) { 42 | Block y2 = world.getBlockAt(x, y - 1, z); 43 | player.sendBlockChange(y2.getLocation(), y2.getBlockData()); 44 | } 45 | 46 | Block x1 = world.getBlockAt(x + 1, y, z); 47 | Block x2 = world.getBlockAt(x - 1, y, z); 48 | Block z1 = world.getBlockAt(x, y, z + 1); 49 | Block z2 = world.getBlockAt(x, y, z - 1); 50 | player.sendBlockChange(x1.getLocation(), x1.getBlockData()); 51 | player.sendBlockChange(x2.getLocation(), x2.getBlockData()); 52 | player.sendBlockChange(z1.getLocation(), z1.getBlockData()); 53 | player.sendBlockChange(z2.getLocation(), z2.getBlockData()); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/main/java/net/coreprotect/listener/player/PlayerItemBreakListener.java: -------------------------------------------------------------------------------- 1 | package net.coreprotect.listener.player; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | import java.util.Locale; 6 | 7 | import org.bukkit.Location; 8 | import org.bukkit.event.EventHandler; 9 | import org.bukkit.event.EventPriority; 10 | import org.bukkit.event.Listener; 11 | import org.bukkit.event.player.PlayerItemBreakEvent; 12 | import org.bukkit.inventory.ItemStack; 13 | 14 | import net.coreprotect.config.Config; 15 | import net.coreprotect.config.ConfigHandler; 16 | import net.coreprotect.consumer.Queue; 17 | 18 | public final class PlayerItemBreakListener extends Queue implements Listener { 19 | 20 | protected static void playerBreakItem(Location location, String user, ItemStack itemStack) { 21 | if (!Config.getConfig(location.getWorld()).ITEM_TRANSACTIONS || itemStack == null) { 22 | return; 23 | } 24 | 25 | String loggingItemId = user.toLowerCase(Locale.ROOT) + "." + location.getBlockX() + "." + location.getBlockY() + "." + location.getBlockZ(); 26 | int itemId = getItemId(loggingItemId); 27 | 28 | List list = ConfigHandler.itemsBreak.getOrDefault(loggingItemId, new ArrayList<>()); 29 | list.add(itemStack.clone()); 30 | ConfigHandler.itemsBreak.put(loggingItemId, list); 31 | 32 | int time = (int) (System.currentTimeMillis() / 1000L) + 1; 33 | Queue.queueItemTransaction(user, location.clone(), time, 0, itemId); 34 | } 35 | 36 | @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) 37 | protected void onPlayerItemBreak(PlayerItemBreakEvent event) { 38 | ItemStack itemStack = event.getBrokenItem(); 39 | playerBreakItem(event.getPlayer().getLocation(), event.getPlayer().getName(), itemStack); 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/net/coreprotect/listener/player/PlayerJoinListener.java: -------------------------------------------------------------------------------- 1 | package net.coreprotect.listener.player; 2 | 3 | import org.bukkit.entity.Player; 4 | import org.bukkit.event.EventHandler; 5 | import org.bukkit.event.EventPriority; 6 | import org.bukkit.event.Listener; 7 | import org.bukkit.event.player.PlayerJoinEvent; 8 | 9 | import net.coreprotect.config.Config; 10 | import net.coreprotect.consumer.Queue; 11 | 12 | public final class PlayerJoinListener extends Queue implements Listener { 13 | 14 | @EventHandler(priority = EventPriority.MONITOR) 15 | public void onPlayerJoin(PlayerJoinEvent event) { 16 | Player player = event.getPlayer(); 17 | int time = (int) (System.currentTimeMillis() / 1000L); 18 | 19 | // Pass checkConfig to Process.java, to allow logging of UUIDs 20 | Queue.queuePlayerLogin(player, time, Config.getConfig(player.getWorld()).PLAYER_SESSIONS ? 1 : 0, Config.getConfig(player.getWorld()).USERNAME_CHANGES ? 1 : 0); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/net/coreprotect/listener/player/PlayerPickupArrowListener.java: -------------------------------------------------------------------------------- 1 | package net.coreprotect.listener.player; 2 | 3 | import org.bukkit.Material; 4 | import org.bukkit.entity.AbstractArrow; 5 | import org.bukkit.entity.Arrow; 6 | import org.bukkit.event.EventHandler; 7 | import org.bukkit.event.EventPriority; 8 | import org.bukkit.event.Listener; 9 | import org.bukkit.event.player.PlayerPickupArrowEvent; 10 | import org.bukkit.inventory.ItemStack; 11 | 12 | import net.coreprotect.bukkit.BukkitAdapter; 13 | import net.coreprotect.consumer.Queue; 14 | import net.coreprotect.listener.entity.EntityPickupItemListener; 15 | 16 | public final class PlayerPickupArrowListener extends Queue implements Listener { 17 | 18 | public static ItemStack getArrowType(AbstractArrow arrow) { 19 | ItemStack itemStack = null; 20 | switch (arrow.getType()) { 21 | case SPECTRAL_ARROW: 22 | itemStack = new ItemStack(Material.SPECTRAL_ARROW); 23 | break; 24 | default: 25 | itemStack = new ItemStack(Material.ARROW); 26 | break; 27 | } 28 | 29 | if (arrow instanceof Arrow) { 30 | Arrow arrowEntity = (Arrow) arrow; 31 | itemStack = BukkitAdapter.ADAPTER.getArrowMeta(arrowEntity, itemStack); 32 | } 33 | 34 | return itemStack; 35 | } 36 | 37 | @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) 38 | protected void onPlayerPickupArrowEvent(PlayerPickupArrowEvent event) { 39 | ItemStack itemStack = getArrowType(event.getArrow()); 40 | EntityPickupItemListener.onItemPickup(event.getPlayer(), event.getArrow().getLocation(), itemStack); 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/net/coreprotect/listener/player/PlayerQuitListener.java: -------------------------------------------------------------------------------- 1 | package net.coreprotect.listener.player; 2 | 3 | import org.bukkit.entity.Player; 4 | import org.bukkit.event.EventHandler; 5 | import org.bukkit.event.EventPriority; 6 | import org.bukkit.event.Listener; 7 | import org.bukkit.event.player.PlayerQuitEvent; 8 | 9 | import net.coreprotect.config.Config; 10 | import net.coreprotect.consumer.Queue; 11 | 12 | public final class PlayerQuitListener extends Queue implements Listener { 13 | 14 | public static void queuePlayerQuit(Player player) { 15 | if (Config.getConfig(player.getWorld()).PLAYER_SESSIONS) { 16 | int time = (int) (System.currentTimeMillis() / 1000L); 17 | Queue.queuePlayerQuit(player, time); 18 | } 19 | } 20 | 21 | @EventHandler(priority = EventPriority.MONITOR) 22 | public void onPlayerQuit(PlayerQuitEvent event) { 23 | queuePlayerQuit(event.getPlayer()); 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/net/coreprotect/listener/player/PlayerTakeLecternBookListener.java: -------------------------------------------------------------------------------- 1 | package net.coreprotect.listener.player; 2 | 3 | import org.bukkit.entity.Player; 4 | import org.bukkit.event.EventHandler; 5 | import org.bukkit.event.EventPriority; 6 | import org.bukkit.event.Listener; 7 | import org.bukkit.event.player.PlayerTakeLecternBookEvent; 8 | 9 | import net.coreprotect.config.Config; 10 | import net.coreprotect.consumer.Queue; 11 | 12 | public final class PlayerTakeLecternBookListener extends Queue implements Listener { 13 | 14 | @EventHandler(priority = EventPriority.MONITOR) 15 | public void onPlayerTakeLecternBook(PlayerTakeLecternBookEvent event) { 16 | Player player = event.getPlayer(); 17 | if (Config.getConfig(player.getWorld()).ITEM_TRANSACTIONS) { 18 | InventoryChangeListener.inventoryTransaction(player.getName(), event.getLectern().getLocation(), null); 19 | } 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/net/coreprotect/listener/player/inspector/BaseInspector.java: -------------------------------------------------------------------------------- 1 | package net.coreprotect.listener.player.inspector; 2 | 3 | import java.sql.Connection; 4 | 5 | import org.bukkit.entity.Player; 6 | 7 | import net.coreprotect.config.ConfigHandler; 8 | import net.coreprotect.database.Database; 9 | import net.coreprotect.language.Phrase; 10 | import net.coreprotect.utility.Color; 11 | 12 | public abstract class BaseInspector { 13 | 14 | protected void checkPreconditions(Player player) throws InspectionException { 15 | if (ConfigHandler.converterRunning) { 16 | throw new InspectionException(Color.DARK_AQUA + "CoreProtect " + Color.WHITE + "- " + Phrase.build(Phrase.UPGRADE_IN_PROGRESS)); 17 | } 18 | 19 | if (ConfigHandler.purgeRunning) { 20 | throw new InspectionException(Color.DARK_AQUA + "CoreProtect " + Color.WHITE + "- " + Phrase.build(Phrase.PURGE_IN_PROGRESS)); 21 | } 22 | 23 | if (ConfigHandler.lookupThrottle.get(player.getName()) != null) { 24 | Object[] lookupThrottle = ConfigHandler.lookupThrottle.get(player.getName()); 25 | if ((boolean) lookupThrottle[0] || (System.currentTimeMillis() - (long) lookupThrottle[1]) < 100) { 26 | throw new InspectionException(Color.DARK_AQUA + "CoreProtect " + Color.WHITE + "- " + Phrase.build(Phrase.DATABASE_BUSY)); 27 | } 28 | } 29 | } 30 | 31 | protected Connection getDatabaseConnection(Player player) throws Exception { 32 | ConfigHandler.lookupThrottle.put(player.getName(), new Object[] { true, System.currentTimeMillis() }); 33 | 34 | Connection connection = Database.getConnection(true); 35 | if (connection == null) { 36 | throw new InspectionException(Color.DARK_AQUA + "CoreProtect " + Color.WHITE + "- " + Phrase.build(Phrase.DATABASE_BUSY)); 37 | } 38 | 39 | return connection; 40 | } 41 | 42 | protected void finishInspection(Player player) { 43 | ConfigHandler.lookupThrottle.put(player.getName(), new Object[] { false, System.currentTimeMillis() }); 44 | } 45 | 46 | public static class InspectionException extends Exception { 47 | private static final long serialVersionUID = 1L; 48 | 49 | public InspectionException(String message) { 50 | super(message); 51 | } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/main/java/net/coreprotect/listener/player/inspector/ContainerInspector.java: -------------------------------------------------------------------------------- 1 | package net.coreprotect.listener.player.inspector; 2 | 3 | import java.sql.Connection; 4 | import java.sql.Statement; 5 | import java.util.List; 6 | 7 | import org.bukkit.Location; 8 | import org.bukkit.entity.Player; 9 | 10 | import net.coreprotect.database.lookup.ChestTransactionLookup; 11 | import net.coreprotect.utility.Chat; 12 | 13 | public class ContainerInspector extends BaseInspector { 14 | 15 | public void performContainerLookup(final Player player, final Location finalLocation) { 16 | class BasicThread implements Runnable { 17 | @Override 18 | public void run() { 19 | try { 20 | checkPreconditions(player); 21 | 22 | try (Connection connection = getDatabaseConnection(player)) { 23 | Statement statement = connection.createStatement(); 24 | List blockData = ChestTransactionLookup.performLookup(null, statement, finalLocation, player, 1, 7, false); 25 | for (String data : blockData) { 26 | Chat.sendComponent(player, data); 27 | } 28 | 29 | statement.close(); 30 | } 31 | } 32 | catch (InspectionException e) { 33 | Chat.sendMessage(player, e.getMessage()); 34 | } 35 | catch (Exception e) { 36 | e.printStackTrace(); 37 | } 38 | finally { 39 | finishInspection(player); 40 | } 41 | } 42 | } 43 | 44 | Runnable runnable = new BasicThread(); 45 | Thread thread = new Thread(runnable); 46 | thread.start(); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/net/coreprotect/listener/player/inspector/InteractionInspector.java: -------------------------------------------------------------------------------- 1 | package net.coreprotect.listener.player.inspector; 2 | 3 | import java.sql.Connection; 4 | import java.sql.Statement; 5 | 6 | import org.bukkit.block.Block; 7 | import org.bukkit.entity.Player; 8 | 9 | import net.coreprotect.database.lookup.InteractionLookup; 10 | import net.coreprotect.utility.Chat; 11 | 12 | public class InteractionInspector extends BaseInspector { 13 | 14 | public void performInteractionLookup(final Player player, final Block finalInteractBlock) { 15 | class BasicThread implements Runnable { 16 | @Override 17 | public void run() { 18 | try { 19 | checkPreconditions(player); 20 | 21 | try (Connection connection = getDatabaseConnection(player)) { 22 | Statement statement = connection.createStatement(); 23 | String blockData = InteractionLookup.performLookup(null, statement, finalInteractBlock, player, 0, 1, 7); 24 | 25 | if (blockData.contains("\n")) { 26 | for (String splitData : blockData.split("\n")) { 27 | Chat.sendComponent(player, splitData); 28 | } 29 | } 30 | else { 31 | Chat.sendComponent(player, blockData); 32 | } 33 | 34 | statement.close(); 35 | } 36 | } 37 | catch (InspectionException e) { 38 | Chat.sendMessage(player, e.getMessage()); 39 | } 40 | catch (Exception e) { 41 | e.printStackTrace(); 42 | } 43 | finally { 44 | finishInspection(player); 45 | } 46 | } 47 | } 48 | 49 | Runnable runnable = new BasicThread(); 50 | Thread thread = new Thread(runnable); 51 | thread.start(); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/main/java/net/coreprotect/listener/player/inspector/SignInspector.java: -------------------------------------------------------------------------------- 1 | package net.coreprotect.listener.player.inspector; 2 | 3 | import java.sql.Connection; 4 | import java.sql.Statement; 5 | import java.util.List; 6 | 7 | import org.bukkit.Location; 8 | import org.bukkit.entity.Player; 9 | 10 | import net.coreprotect.database.lookup.SignMessageLookup; 11 | import net.coreprotect.utility.Chat; 12 | 13 | public class SignInspector extends BaseInspector { 14 | 15 | public void performSignLookup(final Player player, final Location location) { 16 | class BasicThread implements Runnable { 17 | @Override 18 | public void run() { 19 | try { 20 | checkPreconditions(player); 21 | 22 | try (Connection connection = getDatabaseConnection(player)) { 23 | Statement statement = connection.createStatement(); 24 | List signData = SignMessageLookup.performLookup(null, statement, location, player, 1, 7); 25 | for (String signMessage : signData) { 26 | String bypass = null; 27 | 28 | if (signMessage.contains("\n")) { 29 | String[] split = signMessage.split("\n"); 30 | signMessage = split[0]; 31 | bypass = split[1]; 32 | } 33 | 34 | if (signMessage.length() > 0) { 35 | Chat.sendComponent(player, signMessage, bypass); 36 | } 37 | } 38 | 39 | statement.close(); 40 | } 41 | } 42 | catch (InspectionException e) { 43 | Chat.sendMessage(player, e.getMessage()); 44 | } 45 | catch (Exception e) { 46 | e.printStackTrace(); 47 | } 48 | finally { 49 | finishInspection(player); 50 | } 51 | } 52 | } 53 | 54 | Runnable runnable = new BasicThread(); 55 | Thread thread = new Thread(runnable); 56 | thread.start(); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/main/java/net/coreprotect/listener/world/ChunkPopulateListener.java: -------------------------------------------------------------------------------- 1 | package net.coreprotect.listener.world; 2 | 3 | import org.bukkit.event.EventHandler; 4 | import org.bukkit.event.EventPriority; 5 | import org.bukkit.event.Listener; 6 | import org.bukkit.event.world.ChunkPopulateEvent; 7 | 8 | import net.coreprotect.config.ConfigHandler; 9 | import net.coreprotect.consumer.Queue; 10 | 11 | public final class ChunkPopulateListener extends Queue implements Listener { 12 | 13 | @EventHandler(priority = EventPriority.MONITOR) 14 | protected void onChunkPopulate(ChunkPopulateEvent event) { 15 | long chunkKey = event.getChunk().getX() & 0xffffffffL | (event.getChunk().getZ() & 0xffffffffL) << 32; 16 | ConfigHandler.populatedChunks.put(chunkKey, (System.currentTimeMillis() / 1000L)); 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /src/main/java/net/coreprotect/listener/world/LeavesDecayListener.java: -------------------------------------------------------------------------------- 1 | package net.coreprotect.listener.world; 2 | 3 | import org.bukkit.Material; 4 | import org.bukkit.World; 5 | import org.bukkit.block.Block; 6 | import org.bukkit.event.EventHandler; 7 | import org.bukkit.event.EventPriority; 8 | import org.bukkit.event.Listener; 9 | import org.bukkit.event.block.LeavesDecayEvent; 10 | 11 | import net.coreprotect.config.Config; 12 | import net.coreprotect.consumer.Queue; 13 | 14 | public final class LeavesDecayListener extends Queue implements Listener { 15 | 16 | @EventHandler(priority = EventPriority.MONITOR) 17 | protected void onLeavesDecay(LeavesDecayEvent event) { 18 | World world = event.getBlock().getWorld(); 19 | if (!event.isCancelled() && Config.getConfig(world).LEAF_DECAY) { 20 | String player = "#decay"; 21 | Block block = event.getBlock(); 22 | Material type = event.getBlock().getType(); 23 | 24 | Queue.queueBlockBreak(player, block.getState(), type, event.getBlock().getBlockData().getAsString(), 0); 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/net/coreprotect/listener/world/PortalCreateListener.java: -------------------------------------------------------------------------------- 1 | package net.coreprotect.listener.world; 2 | 3 | import org.bukkit.Material; 4 | import org.bukkit.World; 5 | import org.bukkit.block.BlockState; 6 | import org.bukkit.event.EventHandler; 7 | import org.bukkit.event.EventPriority; 8 | import org.bukkit.event.Listener; 9 | import org.bukkit.event.world.PortalCreateEvent; 10 | 11 | import net.coreprotect.config.Config; 12 | import net.coreprotect.consumer.Queue; 13 | import net.coreprotect.database.Lookup; 14 | import net.coreprotect.utility.BlockUtils; 15 | 16 | public final class PortalCreateListener extends Queue implements Listener { 17 | 18 | @EventHandler(priority = EventPriority.MONITOR) 19 | protected void onPortalCreate(PortalCreateEvent event) { 20 | World world = event.getWorld(); 21 | if (event.isCancelled() || !Config.getConfig(world).PORTALS) { 22 | return; 23 | } 24 | 25 | String user = "#portal"; 26 | for (BlockState block : event.getBlocks()) { 27 | Material type = block.getType(); 28 | if (type == Material.NETHER_PORTAL || type == Material.FIRE) { 29 | String resultData = Lookup.whoPlacedCache(block); 30 | if (resultData.length() > 0) { 31 | user = resultData; 32 | break; 33 | } 34 | } 35 | } 36 | 37 | for (BlockState blockState : event.getBlocks()) { 38 | Material type = blockState.getType(); 39 | BlockState oldBlock = blockState.getBlock().getState(); 40 | if (oldBlock.equals(blockState)) { 41 | continue; 42 | } 43 | 44 | if (BlockUtils.isAir(type)) { 45 | Queue.queueBlockBreak(user, oldBlock, oldBlock.getType(), oldBlock.getBlockData().getAsString(), 0); 46 | } 47 | else { 48 | Queue.queueBlockPlace(user, blockState, oldBlock.getType(), oldBlock, type, -1, 0, blockState.getBlockData().getAsString()); 49 | } 50 | } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/main/java/net/coreprotect/listener/world/StructureGrowListener.java: -------------------------------------------------------------------------------- 1 | package net.coreprotect.listener.world; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | import java.util.Locale; 6 | 7 | import org.bukkit.Location; 8 | import org.bukkit.Material; 9 | import org.bukkit.Tag; 10 | import org.bukkit.TreeType; 11 | import org.bukkit.World; 12 | import org.bukkit.block.BlockState; 13 | import org.bukkit.entity.Player; 14 | import org.bukkit.event.EventHandler; 15 | import org.bukkit.event.EventPriority; 16 | import org.bukkit.event.Listener; 17 | import org.bukkit.event.world.StructureGrowEvent; 18 | 19 | import net.coreprotect.config.Config; 20 | import net.coreprotect.consumer.Queue; 21 | 22 | public final class StructureGrowListener extends Queue implements Listener { 23 | 24 | @EventHandler(priority = EventPriority.MONITOR) 25 | protected void onStructureGrow(StructureGrowEvent event) { 26 | // Event that is called when an organic structure attempts to grow (Sapling -> Tree), (Mushroom -> Huge Mushroom), naturally or using bonemeal. 27 | TreeType treeType = event.getSpecies(); 28 | String user = "#tree"; 29 | int tree = 1; 30 | 31 | // Skip logging for bad event calls 32 | if (treeType == null || event.isFromBonemeal()) { 33 | return; 34 | } 35 | 36 | List blocks = event.getBlocks(); 37 | if (blocks.size() <= 4) { 38 | for (BlockState block : blocks) { 39 | if (Tag.SAPLINGS.isTagged(block.getType()) || block.getType().equals(Material.BROWN_MUSHROOM) || block.getType().equals(Material.RED_MUSHROOM)) { 40 | return; 41 | } 42 | } 43 | } 44 | 45 | if (treeType.name().toLowerCase(Locale.ROOT).contains("mushroom")) { 46 | user = "#mushroom"; 47 | tree = 0; 48 | } 49 | 50 | if (!event.isCancelled()) { 51 | World world = event.getWorld(); 52 | if ((tree == 1 && Config.getConfig(world).TREE_GROWTH) || (tree == 0 && Config.getConfig(world).MUSHROOM_GROWTH)) { 53 | Player player = event.getPlayer(); 54 | Location location = event.getLocation(); 55 | if (player != null) { 56 | user = player.getName(); 57 | } 58 | 59 | List structureBlocks = new ArrayList<>(blocks); 60 | structureBlocks.removeIf(replacedBlock -> replacedBlock.getY() > location.getBlockY()); 61 | for (int i = 0; i < structureBlocks.size(); i++) { 62 | BlockState replacedBlock = structureBlocks.get(i); 63 | structureBlocks.set(i, replacedBlock.getBlock().getState()); 64 | } 65 | 66 | int replacedListSize = structureBlocks.size(); 67 | structureBlocks.addAll(blocks); 68 | 69 | Queue.queueStructureGrow(user, world.getBlockAt(location).getState(), structureBlocks, replacedListSize); 70 | } 71 | } 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /src/main/java/net/coreprotect/paper/PaperHandler.java: -------------------------------------------------------------------------------- 1 | package net.coreprotect.paper; 2 | 3 | import org.bukkit.Location; 4 | import org.bukkit.Server; 5 | import org.bukkit.entity.Entity; 6 | import org.bukkit.inventory.Inventory; 7 | import org.bukkit.inventory.InventoryHolder; 8 | 9 | public class PaperHandler extends PaperAdapter { 10 | 11 | @Override 12 | public boolean isStopping(Server server) { 13 | return server.isStopping(); 14 | } 15 | 16 | @Override 17 | public void teleportAsync(Entity entity, Location location) { 18 | entity.teleportAsync(location); 19 | } 20 | 21 | @Override 22 | public InventoryHolder getHolder(Inventory holder, boolean useSnapshot) { 23 | return holder.getHolder(useSnapshot); 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/net/coreprotect/paper/PaperInterface.java: -------------------------------------------------------------------------------- 1 | package net.coreprotect.paper; 2 | 3 | import org.bukkit.Location; 4 | import org.bukkit.Server; 5 | import org.bukkit.block.Sign; 6 | import org.bukkit.block.Skull; 7 | import org.bukkit.entity.Entity; 8 | import org.bukkit.inventory.Inventory; 9 | import org.bukkit.inventory.InventoryHolder; 10 | 11 | public interface PaperInterface { 12 | 13 | public InventoryHolder getHolder(Inventory holder, boolean useSnapshot); 14 | 15 | public boolean isStopping(Server server); 16 | 17 | public String getLine(Sign sign, int line); 18 | 19 | public void teleportAsync(Entity entity, Location location); 20 | 21 | public String getSkullOwner(Skull skull); 22 | 23 | public String getSkullSkin(Skull skull); 24 | 25 | public void setSkullOwner(Skull skull, String owner); 26 | 27 | public void setSkullSkin(Skull skull, String skin); 28 | 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/net/coreprotect/paper/Paper_v1_17.java: -------------------------------------------------------------------------------- 1 | package net.coreprotect.paper; 2 | 3 | import org.bukkit.block.Sign; 4 | 5 | import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; 6 | 7 | public class Paper_v1_17 extends PaperHandler { 8 | 9 | @Override 10 | public String getLine(Sign sign, int line) { 11 | if (line >= 4) { 12 | return ""; 13 | } 14 | 15 | // https://docs.adventure.kyori.net/serializer/ 16 | return LegacyComponentSerializer.legacySection().serialize(sign.line(line)); 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /src/main/java/net/coreprotect/paper/Paper_v1_20.java: -------------------------------------------------------------------------------- 1 | package net.coreprotect.paper; 2 | 3 | import java.net.URI; 4 | import java.net.URL; 5 | import java.util.UUID; 6 | 7 | import org.bukkit.Bukkit; 8 | import org.bukkit.block.Sign; 9 | import org.bukkit.block.Skull; 10 | import org.bukkit.block.sign.Side; 11 | import org.bukkit.profile.PlayerTextures; 12 | 13 | import com.destroystokyo.paper.profile.PlayerProfile; 14 | 15 | import net.coreprotect.config.Config; 16 | import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; 17 | 18 | public class Paper_v1_20 extends Paper_v1_17 { 19 | 20 | @Override 21 | public String getLine(Sign sign, int line) { 22 | // https://docs.adventure.kyori.net/serializer/ 23 | if (line < 4) { 24 | return LegacyComponentSerializer.legacySection().serialize(sign.getSide(Side.FRONT).line(line)); 25 | } 26 | else { 27 | return LegacyComponentSerializer.legacySection().serialize(sign.getSide(Side.BACK).line(line - 4)); 28 | } 29 | } 30 | 31 | @Override 32 | public String getSkullOwner(Skull skull) { 33 | String owner = skull.getPlayerProfile().getName(); 34 | if (skull.getPlayerProfile().getId() != null) { 35 | owner = skull.getPlayerProfile().getId().toString(); 36 | } 37 | else if (Config.getGlobal().MYSQL && owner != null && owner.length() > 255) { 38 | return owner.substring(0, 255); 39 | } 40 | 41 | return owner; 42 | } 43 | 44 | @Override 45 | public void setSkullOwner(Skull skull, String owner) { 46 | if (owner != null && owner.length() >= 32 && owner.contains("-")) { 47 | skull.setPlayerProfile(Bukkit.createProfile(UUID.fromString(owner))); 48 | } 49 | else { 50 | skull.setPlayerProfile(Bukkit.createProfile(owner)); 51 | } 52 | } 53 | 54 | @Override 55 | public String getSkullSkin(Skull skull) { 56 | URL skin = skull.getPlayerProfile().getTextures().getSkin(); 57 | if (skin == null) { 58 | return null; 59 | } 60 | 61 | return skin.toString(); 62 | } 63 | 64 | @Override 65 | public void setSkullSkin(Skull skull, String skin) { 66 | try { 67 | PlayerProfile playerProfile = skull.getPlayerProfile(); 68 | PlayerTextures textures = playerProfile.getTextures(); 69 | textures.setSkin(URI.create(skin).toURL()); 70 | playerProfile.setTextures(textures); 71 | skull.setPlayerProfile(playerProfile); 72 | } 73 | catch (Exception e) { 74 | e.printStackTrace(); 75 | } 76 | } 77 | 78 | } 79 | -------------------------------------------------------------------------------- /src/main/java/net/coreprotect/paper/listener/PaperChatListener.java: -------------------------------------------------------------------------------- 1 | package net.coreprotect.paper.listener; 2 | 3 | import org.bukkit.entity.Player; 4 | import org.bukkit.event.EventHandler; 5 | import org.bukkit.event.EventPriority; 6 | import org.bukkit.event.Listener; 7 | 8 | import io.papermc.paper.event.player.AsyncChatEvent; 9 | import net.coreprotect.config.Config; 10 | import net.coreprotect.consumer.Queue; 11 | import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer; 12 | 13 | public final class PaperChatListener extends Queue implements Listener { 14 | 15 | @EventHandler(priority = EventPriority.MONITOR) 16 | public void onPlayerChat(AsyncChatEvent event) { 17 | String message = PlainTextComponentSerializer.plainText().serialize(event.message()); 18 | if (message.isEmpty()) { 19 | return; 20 | } 21 | 22 | Player player = event.getPlayer(); 23 | if (event.isCancelled() && !Config.getConfig(player.getWorld()).LOG_CANCELLED_CHAT) { 24 | return; 25 | } 26 | 27 | if (!message.startsWith("/") && Config.getConfig(player.getWorld()).PLAYER_MESSAGES) { 28 | long timestamp = System.currentTimeMillis() / 1000L; 29 | Queue.queuePlayerChat(player, message, timestamp); 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/net/coreprotect/patch/script/__2_10_0.java: -------------------------------------------------------------------------------- 1 | package net.coreprotect.patch.script; 2 | 3 | import java.sql.Statement; 4 | 5 | import net.coreprotect.config.Config; 6 | import net.coreprotect.config.ConfigHandler; 7 | 8 | public class __2_10_0 { 9 | 10 | protected static boolean patch(Statement statement) { 11 | try { 12 | if (Config.getGlobal().MYSQL) { 13 | statement.executeUpdate("ALTER TABLE " + ConfigHandler.prefix + "user ADD COLUMN uuid varchar(64), ADD INDEX(uuid)"); 14 | } 15 | else { 16 | statement.executeUpdate("ALTER TABLE " + ConfigHandler.prefix + "user ADD COLUMN uuid TEXT;"); 17 | statement.executeUpdate("CREATE INDEX IF NOT EXISTS uuid_index ON " + ConfigHandler.prefix + "user(uuid);"); 18 | } 19 | } 20 | catch (Exception e) { 21 | e.printStackTrace(); 22 | } 23 | 24 | return true; 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/net/coreprotect/patch/script/__2_11_0.java: -------------------------------------------------------------------------------- 1 | package net.coreprotect.patch.script; 2 | 3 | import java.sql.Statement; 4 | import java.util.Locale; 5 | 6 | import org.bukkit.Art; 7 | import org.bukkit.Material; 8 | import org.bukkit.entity.EntityType; 9 | 10 | import net.coreprotect.config.Config; 11 | import net.coreprotect.config.ConfigHandler; 12 | 13 | public class __2_11_0 { 14 | 15 | protected static boolean patch(Statement statement) { 16 | try { 17 | if (Config.getGlobal().MYSQL) { 18 | statement.executeUpdate("START TRANSACTION"); 19 | } 20 | else { 21 | statement.executeUpdate("BEGIN TRANSACTION"); 22 | } 23 | 24 | for (Art artType : Art.values()) { 25 | Integer type = artType.getId(); 26 | String name = artType.toString().toLowerCase(Locale.ROOT); 27 | statement.executeUpdate("INSERT INTO " + ConfigHandler.prefix + "art_map (id, art) VALUES ('" + type + "', '" + name + "')"); 28 | ConfigHandler.art.put(name, type); 29 | ConfigHandler.artReversed.put(type, name); 30 | if (type > ConfigHandler.artId) { 31 | ConfigHandler.artId = type; 32 | } 33 | } 34 | 35 | for (EntityType entityType : EntityType.values()) { 36 | Integer type = (int) entityType.getTypeId(); 37 | String name = entityType.toString().toLowerCase(Locale.ROOT); 38 | statement.executeUpdate("INSERT INTO " + ConfigHandler.prefix + "entity_map (id, entity) VALUES ('" + type + "', '" + name + "')"); 39 | ConfigHandler.entities.put(name, type); 40 | ConfigHandler.entitiesReversed.put(type, name); 41 | if (type > ConfigHandler.entityId) { 42 | ConfigHandler.entityId = type; 43 | } 44 | } 45 | 46 | for (Material material : Material.values()) { 47 | Integer type = material.getId(); 48 | String name = material.toString().toLowerCase(Locale.ROOT); 49 | statement.executeUpdate("INSERT INTO " + ConfigHandler.prefix + "material_map (id, material) VALUES ('" + type + "', '" + name + "')"); 50 | ConfigHandler.materials.put(name, type); 51 | ConfigHandler.materialsReversed.put(type, name); 52 | if (type > ConfigHandler.materialId) { 53 | ConfigHandler.materialId = type; 54 | } 55 | } 56 | 57 | if (Config.getGlobal().MYSQL) { 58 | statement.executeUpdate("COMMIT"); 59 | } 60 | else { 61 | statement.executeUpdate("COMMIT TRANSACTION"); 62 | } 63 | } 64 | catch (Exception e) { 65 | e.printStackTrace(); 66 | } 67 | 68 | return true; 69 | } 70 | 71 | } 72 | -------------------------------------------------------------------------------- /src/main/java/net/coreprotect/patch/script/__2_15_0.java: -------------------------------------------------------------------------------- 1 | package net.coreprotect.patch.script; 2 | 3 | import java.sql.PreparedStatement; 4 | import java.sql.ResultSet; 5 | import java.sql.Statement; 6 | 7 | import net.coreprotect.config.Config; 8 | import net.coreprotect.config.ConfigHandler; 9 | import net.coreprotect.database.Database; 10 | 11 | public class __2_15_0 { 12 | 13 | protected static boolean patch(Statement statement) { 14 | try { 15 | if (Config.getGlobal().MYSQL) { 16 | statement.executeUpdate("ALTER TABLE " + ConfigHandler.prefix + "chat MODIFY message VARCHAR(1000)"); 17 | statement.executeUpdate("ALTER TABLE " + ConfigHandler.prefix + "command MODIFY message VARCHAR(1000)"); 18 | statement.executeUpdate("ALTER TABLE " + ConfigHandler.prefix + "user MODIFY user VARCHAR(100)"); 19 | statement.executeUpdate("ALTER TABLE " + ConfigHandler.prefix + "username_log MODIFY user VARCHAR(100)"); 20 | } 21 | 22 | String query = "SELECT rowid as id, material FROM " + ConfigHandler.prefix + "material_map"; 23 | String preparedQuery = "UPDATE " + ConfigHandler.prefix + "material_map SET material = ? WHERE rowid = ?"; 24 | PreparedStatement preparedStatement = statement.getConnection().prepareStatement(preparedQuery); 25 | 26 | Database.beginTransaction(statement, Config.getGlobal().MYSQL); 27 | ResultSet rs = statement.executeQuery(query); 28 | while (rs.next()) { 29 | int rowid = rs.getInt("id"); 30 | String material = rs.getString("material"); 31 | if (material.startsWith("minecraft:") && !material.contains("minecraft:legacy_")) { 32 | material = material.replace("minecraft:", "minecraft:legacy_"); 33 | preparedStatement.setString(1, material); 34 | preparedStatement.setInt(2, rowid); 35 | preparedStatement.executeUpdate(); 36 | } 37 | } 38 | rs.close(); 39 | Database.commitTransaction(statement, Config.getGlobal().MYSQL); 40 | 41 | try { 42 | if (Config.getGlobal().MYSQL) { 43 | statement.executeUpdate("ALTER TABLE " + ConfigHandler.prefix + "block MODIFY COLUMN rowid bigint NOT NULL AUTO_INCREMENT, ADD COLUMN blockdata BLOB"); 44 | } 45 | else { 46 | statement.executeUpdate("ALTER TABLE " + ConfigHandler.prefix + "block ADD COLUMN blockdata BLOB"); 47 | } 48 | } 49 | catch (Exception e) { 50 | // already updated 51 | } 52 | 53 | ConfigHandler.loadTypes(statement); 54 | } 55 | catch (Exception e) { 56 | e.printStackTrace(); 57 | } 58 | 59 | return true; 60 | } 61 | 62 | } 63 | -------------------------------------------------------------------------------- /src/main/java/net/coreprotect/patch/script/__2_17_0.java: -------------------------------------------------------------------------------- 1 | package net.coreprotect.patch.script; 2 | 3 | import java.sql.Statement; 4 | 5 | import net.coreprotect.config.Config; 6 | import net.coreprotect.config.ConfigHandler; 7 | 8 | public class __2_17_0 { 9 | 10 | protected static boolean patch(Statement statement) { 11 | try { 12 | if (Config.getGlobal().MYSQL) { 13 | statement.executeUpdate("ALTER TABLE " + ConfigHandler.prefix + "sign ADD COLUMN color int"); 14 | } 15 | else { 16 | statement.executeUpdate("ALTER TABLE " + ConfigHandler.prefix + "sign ADD COLUMN color INTEGER"); 17 | } 18 | } 19 | catch (Exception e) { 20 | e.printStackTrace(); 21 | } 22 | 23 | return true; 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/net/coreprotect/patch/script/__2_18_1.java: -------------------------------------------------------------------------------- 1 | package net.coreprotect.patch.script; 2 | 3 | import java.sql.Statement; 4 | 5 | import net.coreprotect.patch.Patch; 6 | 7 | public class __2_18_1 { 8 | 9 | protected static boolean patch(Statement statement) { 10 | try { 11 | __2_18_0.createIndexes = false; 12 | Integer[] last_version = Patch.getDatabaseVersion(statement.getConnection(), true); 13 | if (last_version[0] == 2 && last_version[1] == 18 && last_version[2] == 0) { 14 | return __2_18_0.patch(statement); 15 | } 16 | } 17 | catch (Exception e) { 18 | e.printStackTrace(); 19 | } 20 | 21 | return true; 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/net/coreprotect/patch/script/__2_21_0.java: -------------------------------------------------------------------------------- 1 | package net.coreprotect.patch.script; 2 | 3 | import java.sql.Statement; 4 | 5 | import net.coreprotect.config.Config; 6 | import net.coreprotect.config.ConfigFile; 7 | import net.coreprotect.config.ConfigHandler; 8 | import net.coreprotect.language.Phrase; 9 | import net.coreprotect.language.Selector; 10 | import net.coreprotect.patch.Patch; 11 | import net.coreprotect.utility.Chat; 12 | 13 | public class __2_21_0 { 14 | 15 | protected static boolean patch(Statement statement) { 16 | try { 17 | if (Config.getGlobal().MYSQL) { 18 | try { 19 | statement.executeUpdate("ALTER TABLE " + ConfigHandler.prefix + "item ADD COLUMN rolled_back TINYINT DEFAULT 0;"); 20 | } 21 | catch (Exception e) { 22 | Chat.console(Phrase.build(Phrase.PATCH_SKIP_UPDATE, ConfigHandler.prefix + "item", Selector.FIRST, Selector.FIRST)); 23 | } 24 | } 25 | else { 26 | try { 27 | statement.executeUpdate("ALTER TABLE " + ConfigHandler.prefix + "item ADD COLUMN rolled_back INTEGER DEFAULT 0;"); 28 | } 29 | catch (Exception e) { 30 | Chat.console(Phrase.build(Phrase.PATCH_SKIP_UPDATE, ConfigHandler.prefix + "item", Selector.FIRST, Selector.FIRST)); 31 | } 32 | } 33 | 34 | if (!Patch.continuePatch()) { 35 | return false; 36 | } 37 | 38 | ConfigFile.modifyLine("language.yml", "LOOKUP_VIEW_PAGE: \"To view a page, type \\\"{0}\\\".\"", null); 39 | ConfigFile.modifyLine("language.yml", "PREVIEW_CONTAINER: \"You can't preview container transactions.\"", null); 40 | ConfigFile.sortFile("language.yml"); 41 | } 42 | catch (Exception e) { 43 | e.printStackTrace(); 44 | } 45 | 46 | return true; 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /src/main/java/net/coreprotect/patch/script/__2_23_0.java: -------------------------------------------------------------------------------- 1 | package net.coreprotect.patch.script; 2 | 3 | import java.sql.Statement; 4 | 5 | import net.coreprotect.config.Config; 6 | import net.coreprotect.config.ConfigHandler; 7 | import net.coreprotect.language.Phrase; 8 | import net.coreprotect.language.Selector; 9 | import net.coreprotect.utility.Chat; 10 | 11 | public class __2_23_0 { 12 | 13 | protected static boolean patch(Statement statement) { 14 | try { 15 | if (Config.getGlobal().MYSQL) { 16 | try { 17 | statement.executeUpdate("ALTER TABLE " + ConfigHandler.prefix + "skull MODIFY owner VARCHAR(255);"); 18 | } 19 | catch (Exception e) { 20 | Chat.console(Phrase.build(Phrase.PATCH_SKIP_UPDATE, ConfigHandler.prefix + "skull", Selector.FIRST, Selector.FIRST)); 21 | } 22 | } 23 | 24 | __2_23_1.patch(statement); 25 | } 26 | catch (Exception e) { 27 | e.printStackTrace(); 28 | } 29 | 30 | return true; 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/net/coreprotect/patch/script/__2_23_1.java: -------------------------------------------------------------------------------- 1 | package net.coreprotect.patch.script; 2 | 3 | import java.sql.Statement; 4 | 5 | import net.coreprotect.config.Config; 6 | import net.coreprotect.config.ConfigHandler; 7 | import net.coreprotect.language.Phrase; 8 | import net.coreprotect.language.Selector; 9 | import net.coreprotect.patch.Patch; 10 | import net.coreprotect.utility.Chat; 11 | 12 | public class __2_23_1 { 13 | 14 | protected static boolean patch(Statement statement) { 15 | try { 16 | if (Config.getGlobal().MYSQL) { 17 | try { 18 | statement.executeUpdate("ALTER TABLE " + ConfigHandler.prefix + "skull ADD COLUMN skin VARCHAR(255);"); 19 | } 20 | catch (Exception e) { 21 | Chat.console(Phrase.build(Phrase.PATCH_SKIP_UPDATE, ConfigHandler.prefix + "skull", Selector.FIRST, Selector.FIRST)); 22 | } 23 | } 24 | else { 25 | try { 26 | statement.executeUpdate("ALTER TABLE " + ConfigHandler.prefix + "skull ADD COLUMN skin TEXT;"); 27 | } 28 | catch (Exception e) { 29 | Chat.console(Phrase.build(Phrase.PATCH_SKIP_UPDATE, ConfigHandler.prefix + "skull", Selector.FIRST, Selector.FIRST)); 30 | } 31 | 32 | if (!Patch.continuePatch()) { 33 | return false; 34 | } 35 | } 36 | } 37 | catch (Exception e) { 38 | e.printStackTrace(); 39 | } 40 | 41 | return true; 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/net/coreprotect/patch/script/__2_5_0.java: -------------------------------------------------------------------------------- 1 | package net.coreprotect.patch.script; 2 | 3 | import java.sql.Statement; 4 | 5 | import net.coreprotect.config.Config; 6 | import net.coreprotect.config.ConfigHandler; 7 | import net.coreprotect.patch.Patch; 8 | 9 | public class __2_5_0 { 10 | 11 | protected static boolean patch(Statement statement) { 12 | try { 13 | if (Config.getGlobal().MYSQL) { 14 | try { 15 | statement.executeUpdate("ALTER TABLE " + ConfigHandler.prefix + "sign MODIFY line_1 VARCHAR(100)"); 16 | statement.executeUpdate("ALTER TABLE " + ConfigHandler.prefix + "sign MODIFY line_2 VARCHAR(100)"); 17 | statement.executeUpdate("ALTER TABLE " + ConfigHandler.prefix + "sign MODIFY line_3 VARCHAR(100)"); 18 | statement.executeUpdate("ALTER TABLE " + ConfigHandler.prefix + "sign MODIFY line_4 VARCHAR(100)"); 19 | statement.executeUpdate("ALTER TABLE " + ConfigHandler.prefix + "user MODIFY user VARCHAR(32)"); 20 | } 21 | catch (Exception e) { 22 | e.printStackTrace(); 23 | } 24 | 25 | if (!Patch.continuePatch()) { 26 | return false; 27 | } 28 | } 29 | 30 | statement.executeUpdate("ALTER TABLE " + ConfigHandler.prefix + "block ADD COLUMN meta BLOB"); 31 | } 32 | catch (Exception e) { 33 | e.printStackTrace(); 34 | } 35 | 36 | return true; 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/net/coreprotect/patch/script/__2_6_0.java: -------------------------------------------------------------------------------- 1 | package net.coreprotect.patch.script; 2 | 3 | import java.sql.Statement; 4 | 5 | import net.coreprotect.config.Config; 6 | import net.coreprotect.config.ConfigHandler; 7 | 8 | public class __2_6_0 { 9 | 10 | protected static boolean patch(Statement statement) { 11 | try { 12 | if (Config.getGlobal().MYSQL) { 13 | statement.executeUpdate("START TRANSACTION"); 14 | statement.executeUpdate("CREATE TEMPORARY TABLE " + ConfigHandler.prefix + "version_tmp(rowid int, time int, version varchar(16)) ENGINE=InnoDB"); 15 | statement.executeUpdate("INSERT INTO " + ConfigHandler.prefix + "version_tmp SELECT rowid,time,version FROM " + ConfigHandler.prefix + "version;"); 16 | statement.executeUpdate("DROP TABLE " + ConfigHandler.prefix + "version;"); 17 | statement.executeUpdate("CREATE TABLE " + ConfigHandler.prefix + "version(rowid int NOT NULL AUTO_INCREMENT,PRIMARY KEY(rowid),time int,version varchar(16)) ENGINE=InnoDB"); 18 | statement.executeUpdate("INSERT INTO " + ConfigHandler.prefix + "version SELECT rowid,time,version FROM " + ConfigHandler.prefix + "version_tmp;"); 19 | statement.executeUpdate("DROP TEMPORARY TABLE " + ConfigHandler.prefix + "version_tmp;"); 20 | statement.executeUpdate("COMMIT"); 21 | } 22 | else { 23 | statement.executeUpdate("BEGIN TRANSACTION"); 24 | statement.executeUpdate("CREATE TEMPORARY TABLE " + ConfigHandler.prefix + "version_tmp (time INTEGER, version TEXT);"); 25 | statement.executeUpdate("INSERT INTO " + ConfigHandler.prefix + "version_tmp SELECT time,version FROM " + ConfigHandler.prefix + "version;"); 26 | statement.executeUpdate("DROP TABLE " + ConfigHandler.prefix + "version;"); 27 | statement.executeUpdate("CREATE TABLE " + ConfigHandler.prefix + "version (time INTEGER, version TEXT);"); 28 | statement.executeUpdate("INSERT INTO " + ConfigHandler.prefix + "version SELECT time,version FROM " + ConfigHandler.prefix + "version_tmp;"); 29 | statement.executeUpdate("DROP TABLE " + ConfigHandler.prefix + "version_tmp;"); 30 | statement.executeUpdate("COMMIT TRANSACTION"); 31 | } 32 | } 33 | catch (Exception e) { 34 | e.printStackTrace(); 35 | } 36 | 37 | return true; 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/net/coreprotect/services/VersionCheckService.java: -------------------------------------------------------------------------------- 1 | package net.coreprotect.services; 2 | 3 | import org.bukkit.Bukkit; 4 | 5 | import net.coreprotect.config.ConfigHandler; 6 | import net.coreprotect.language.Phrase; 7 | import net.coreprotect.utility.Chat; 8 | import net.coreprotect.utility.Color; 9 | import net.coreprotect.utility.VersionUtils; 10 | 11 | /** 12 | * Service responsible for checking compatibility of Minecraft, Java versions, 13 | * and plugin branch validation. 14 | */ 15 | public class VersionCheckService { 16 | 17 | private VersionCheckService() { 18 | throw new IllegalStateException("Utility class"); 19 | } 20 | 21 | /** 22 | * Performs all necessary version checks during plugin startup 23 | * 24 | * @return true if all version checks pass, false otherwise 25 | */ 26 | public static boolean performVersionChecks() { 27 | try { 28 | // Check Minecraft version compatibility 29 | String[] bukkitVersion = Bukkit.getServer().getBukkitVersion().split("[-.]"); 30 | if (VersionUtils.newVersion(bukkitVersion[0] + "." + bukkitVersion[1], ConfigHandler.MINECRAFT_VERSION)) { 31 | Chat.console(Phrase.build(Phrase.VERSION_REQUIRED, "Minecraft", ConfigHandler.MINECRAFT_VERSION)); 32 | return false; 33 | } 34 | 35 | if (VersionUtils.newVersion(ConfigHandler.LATEST_VERSION, bukkitVersion[0] + "." + bukkitVersion[1]) && VersionUtils.isBranch("master")) { 36 | Chat.console(Phrase.build(Phrase.VERSION_INCOMPATIBLE, "Minecraft", bukkitVersion[0] + "." + bukkitVersion[1])); 37 | return false; 38 | } 39 | 40 | // Check Java version compatibility 41 | String[] javaVersion = (System.getProperty("java.version").replaceAll("[^0-9.]", "") + ".0").split("\\."); 42 | if (VersionUtils.newVersion(javaVersion[0] + "." + javaVersion[1], ConfigHandler.JAVA_VERSION)) { 43 | Chat.console(Phrase.build(Phrase.VERSION_REQUIRED, "Java", ConfigHandler.JAVA_VERSION)); 44 | return false; 45 | } 46 | 47 | // Branch validation 48 | if (ConfigHandler.EDITION_BRANCH.length() == 0) { 49 | Chat.sendConsoleMessage(Color.RED + "[CoreProtect] " + Phrase.build(Phrase.INVALID_BRANCH_1)); 50 | Chat.sendConsoleMessage(Color.GREY + "[CoreProtect] " + Phrase.build(Phrase.INVALID_BRANCH_2)); 51 | Chat.sendConsoleMessage(Color.GREY + "[CoreProtect] " + Phrase.build(Phrase.INVALID_BRANCH_3)); 52 | return false; 53 | } 54 | 55 | // Store Minecraft server version for later use 56 | ConfigHandler.SERVER_VERSION = Integer.parseInt(bukkitVersion[1]); 57 | } 58 | catch (Exception e) { 59 | e.printStackTrace(); 60 | return false; 61 | } 62 | 63 | return true; 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/main/java/net/coreprotect/spigot/SpigotAdapter.java: -------------------------------------------------------------------------------- 1 | package net.coreprotect.spigot; 2 | 3 | import java.util.regex.Matcher; 4 | 5 | import org.bukkit.command.CommandSender; 6 | 7 | import net.coreprotect.bukkit.BukkitAdapter; 8 | import net.coreprotect.config.ConfigHandler; 9 | import net.coreprotect.utility.Chat; 10 | import net.coreprotect.utility.Util; 11 | 12 | public class SpigotAdapter implements SpigotInterface { 13 | 14 | public static SpigotInterface ADAPTER; 15 | public static final int SPIGOT_UNAVAILABLE = 0; 16 | public static final int SPIGOT_V1_13 = BukkitAdapter.BUKKIT_V1_13; 17 | public static final int SPIGOT_V1_14 = BukkitAdapter.BUKKIT_V1_14; 18 | public static final int SPIGOT_V1_15 = BukkitAdapter.BUKKIT_V1_15; 19 | public static final int SPIGOT_V1_16 = BukkitAdapter.BUKKIT_V1_16; 20 | public static final int SPIGOT_V1_17 = BukkitAdapter.BUKKIT_V1_17; 21 | public static final int SPIGOT_V1_18 = BukkitAdapter.BUKKIT_V1_18; 22 | public static final int SPIGOT_V1_19 = BukkitAdapter.BUKKIT_V1_19; 23 | public static final int SPIGOT_V1_20 = BukkitAdapter.BUKKIT_V1_20; 24 | public static final int SPIGOT_V1_21 = BukkitAdapter.BUKKIT_V1_21; 25 | 26 | public static void loadAdapter() { 27 | int spigotVersion = ConfigHandler.SERVER_VERSION; 28 | if (!ConfigHandler.isSpigot) { 29 | spigotVersion = SPIGOT_UNAVAILABLE; 30 | } 31 | 32 | switch (spigotVersion) { 33 | case SPIGOT_UNAVAILABLE: 34 | SpigotAdapter.ADAPTER = new SpigotAdapter(); 35 | break; 36 | case SPIGOT_V1_13: 37 | case SPIGOT_V1_14: 38 | case SPIGOT_V1_15: 39 | case SPIGOT_V1_16: 40 | case SPIGOT_V1_17: 41 | case SPIGOT_V1_18: 42 | case SPIGOT_V1_19: 43 | case SPIGOT_V1_20: 44 | case SPIGOT_V1_21: 45 | default: 46 | SpigotAdapter.ADAPTER = new SpigotHandler(); 47 | break; 48 | } 49 | } 50 | 51 | @Override 52 | public void addHoverComponent(Object message, String[] data) { 53 | return; 54 | } 55 | 56 | @Override 57 | public void setHoverEvent(Object message, String text) { 58 | return; 59 | } 60 | 61 | @Override 62 | public void sendComponent(CommandSender sender, String string, String bypass) { 63 | StringBuilder message = new StringBuilder(); 64 | 65 | Matcher matcher = Util.tagParser.matcher(string); 66 | while (matcher.find()) { 67 | String value = matcher.group(1); 68 | if (value != null) { 69 | String[] data = value.split("\\|", 3); 70 | if (data[0].equals(Chat.COMPONENT_COMMAND) || data[0].equals(Chat.COMPONENT_POPUP)) { 71 | message.append(data[2]); 72 | } 73 | } 74 | else { 75 | message.append(matcher.group(2)); 76 | } 77 | } 78 | 79 | if (bypass != null) { 80 | message.append(bypass); 81 | } 82 | 83 | Chat.sendMessage(sender, message.toString()); 84 | } 85 | 86 | public String processComponent(String component) { 87 | return component.replace(Chat.COMPONENT_PIPE, "|"); 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /src/main/java/net/coreprotect/spigot/SpigotInterface.java: -------------------------------------------------------------------------------- 1 | package net.coreprotect.spigot; 2 | 3 | import org.bukkit.command.CommandSender; 4 | 5 | public interface SpigotInterface { 6 | 7 | public void addHoverComponent(Object message, String[] data); 8 | 9 | public void setHoverEvent(Object message, String text); 10 | 11 | public void sendComponent(CommandSender sender, String string, String bypass); 12 | 13 | } 14 | -------------------------------------------------------------------------------- /src/main/java/net/coreprotect/utility/Chat.java: -------------------------------------------------------------------------------- 1 | package net.coreprotect.utility; 2 | 3 | import java.util.logging.Level; 4 | 5 | import org.bukkit.Bukkit; 6 | import org.bukkit.ChatColor; 7 | import org.bukkit.Server; 8 | import org.bukkit.command.CommandSender; 9 | import org.bukkit.command.ConsoleCommandSender; 10 | import org.bukkit.entity.Player; 11 | 12 | import net.coreprotect.spigot.SpigotAdapter; 13 | 14 | public final class Chat { 15 | 16 | public static final String COMPONENT_TAG_OPEN = ""; 17 | public static final String COMPONENT_TAG_CLOSE = ""; 18 | public static final String COMPONENT_COMMAND = "COMMAND"; 19 | public static final String COMPONENT_POPUP = "POPUP"; 20 | public static final String COMPONENT_PIPE = ""; 21 | 22 | private Chat() { 23 | throw new IllegalStateException("Utility class"); 24 | } 25 | 26 | public static void sendComponent(CommandSender sender, String string, String bypass) { 27 | SpigotAdapter.ADAPTER.sendComponent(sender, string, bypass); 28 | } 29 | 30 | public static void sendComponent(CommandSender sender, String string) { 31 | sendComponent(sender, string, null); 32 | } 33 | 34 | public static void sendMessage(CommandSender sender, String message) { 35 | if (sender instanceof ConsoleCommandSender) { 36 | message = message.replace(Color.DARK_AQUA, ChatColor.DARK_AQUA.toString()); 37 | } 38 | 39 | sender.sendMessage(message); 40 | } 41 | 42 | public static void sendConsoleMessage(String string) { 43 | Bukkit.getServer().getConsoleSender().sendMessage(string); 44 | } 45 | 46 | public static void console(String string) { 47 | if (string.startsWith("-") || string.startsWith("[")) { 48 | Bukkit.getLogger().log(Level.INFO, string); 49 | } 50 | else { 51 | Bukkit.getLogger().log(Level.INFO, "[CoreProtect] " + string); 52 | } 53 | } 54 | 55 | public static void sendGlobalMessage(CommandSender user, String string) { 56 | if (user instanceof ConsoleCommandSender) { 57 | sendMessage(user, Color.DARK_AQUA + "[CoreProtect] " + Color.WHITE + string); 58 | return; 59 | } 60 | 61 | Server server = Bukkit.getServer(); 62 | server.getConsoleSender().sendMessage("[CoreProtect] " + string); 63 | for (Player player : server.getOnlinePlayers()) { 64 | if (player.isOp() && !player.getName().equals(user.getName())) { 65 | sendMessage(player, Color.DARK_AQUA + "CoreProtect " + Color.WHITE + "- " + string); 66 | } 67 | } 68 | if (user instanceof Player) { 69 | if (((Player) user).isOnline()) { 70 | sendMessage(user, Color.DARK_AQUA + "CoreProtect " + Color.WHITE + "- " + string); 71 | } 72 | } 73 | } 74 | 75 | } 76 | -------------------------------------------------------------------------------- /src/main/java/net/coreprotect/utility/DatabaseUtils.java: -------------------------------------------------------------------------------- 1 | package net.coreprotect.utility; 2 | 3 | import java.sql.Connection; 4 | import java.sql.PreparedStatement; 5 | import java.sql.ResultSet; 6 | import java.util.Map; 7 | import java.util.SortedSet; 8 | import java.util.TreeSet; 9 | 10 | public class DatabaseUtils { 11 | 12 | private DatabaseUtils() { 13 | throw new IllegalStateException("Utility class"); 14 | } 15 | 16 | public static > SortedSet> entriesSortedByValues(Map map) { 17 | SortedSet> sortedEntries = new TreeSet<>((e1, e2) -> { 18 | int res = e1.getValue().compareTo(e2.getValue()); 19 | return res != 0 ? res : 1; 20 | }); 21 | sortedEntries.addAll(map.entrySet()); 22 | return sortedEntries; 23 | } 24 | 25 | public static boolean successfulQuery(Connection connection, String query) { 26 | boolean result = false; 27 | try { 28 | PreparedStatement preparedStmt = connection.prepareStatement(query); 29 | ResultSet resultSet = preparedStmt.executeQuery(); 30 | if (resultSet.isBeforeFirst()) { 31 | result = true; 32 | } 33 | resultSet.close(); 34 | preparedStmt.close(); 35 | } 36 | catch (Exception e) { 37 | e.printStackTrace(); 38 | } 39 | return result; 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/net/coreprotect/utility/Extensions.java: -------------------------------------------------------------------------------- 1 | package net.coreprotect.utility; 2 | 3 | import java.lang.reflect.Method; 4 | 5 | import org.bukkit.command.CommandSender; 6 | 7 | import net.coreprotect.language.Phrase; 8 | 9 | public class Extensions { 10 | 11 | public static void runDatabaseMigration(String command, CommandSender user, String[] argumentArray) { 12 | try { 13 | Class patchClass = Class.forName("net.coreprotect.utility.extensions.DatabaseMigration"); 14 | Method patchMethod = patchClass.getDeclaredMethod("runCommand", CommandSender.class, String[].class); 15 | patchMethod.invoke(null, user, argumentArray); 16 | } 17 | catch (Exception e) { 18 | // plugin not compiled with extension 19 | Chat.sendMessage(user, Color.DARK_AQUA + "CoreProtect " + Color.WHITE + "- " + Phrase.build(Phrase.COMMAND_NOT_FOUND, Color.WHITE, "/co " + command)); 20 | } 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/net/coreprotect/utility/Util.java: -------------------------------------------------------------------------------- 1 | package net.coreprotect.utility; 2 | 3 | import java.util.regex.Pattern; 4 | 5 | import org.bukkit.Location; 6 | import org.bukkit.block.data.BlockData; 7 | import org.bukkit.entity.Player; 8 | 9 | import net.coreprotect.consumer.Queue; 10 | 11 | /** 12 | * Central utility class that provides access to various utility functions. 13 | * Most methods delegate to specialized utility classes. 14 | */ 15 | public class Util extends Queue { 16 | 17 | public static final Pattern tagParser = Pattern.compile(Chat.COMPONENT_TAG_OPEN + "(.+?)" + Chat.COMPONENT_TAG_CLOSE + "|(.+?)", Pattern.DOTALL); 18 | 19 | private Util() { 20 | throw new IllegalStateException("Utility class"); 21 | } 22 | 23 | public static void sendBlockChange(Player player, Location location, BlockData blockData) { 24 | player.sendBlockChange(location, blockData); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/net/coreprotect/utility/Validate.java: -------------------------------------------------------------------------------- 1 | package net.coreprotect.utility; 2 | 3 | import org.bukkit.block.DoubleChest; 4 | import org.bukkit.block.Dropper; 5 | import org.bukkit.block.Hopper; 6 | import org.bukkit.entity.minecart.HopperMinecart; 7 | import org.bukkit.inventory.BlockInventoryHolder; 8 | import org.bukkit.inventory.InventoryHolder; 9 | 10 | public class Validate { 11 | 12 | private Validate() { 13 | throw new IllegalStateException("Utility class"); 14 | } 15 | 16 | public static boolean isHopper(InventoryHolder inventoryHolder) { 17 | return (inventoryHolder instanceof Hopper || inventoryHolder instanceof HopperMinecart); 18 | } 19 | 20 | public static boolean isDropper(InventoryHolder inventoryHolder) { 21 | return (inventoryHolder instanceof Dropper); 22 | } 23 | 24 | /* check if valid hopper destination */ 25 | public static boolean isContainer(InventoryHolder inventoryHolder) { 26 | return (inventoryHolder instanceof BlockInventoryHolder || inventoryHolder instanceof DoubleChest); 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/net/coreprotect/worldedit/CoreProtectEditSessionEvent.java: -------------------------------------------------------------------------------- 1 | package net.coreprotect.worldedit; 2 | 3 | import org.bukkit.Bukkit; 4 | 5 | import com.sk89q.worldedit.EditSession.Stage; 6 | import com.sk89q.worldedit.WorldEdit; 7 | import com.sk89q.worldedit.event.extent.EditSessionEvent; 8 | import com.sk89q.worldedit.util.eventbus.Subscribe; 9 | 10 | import net.coreprotect.CoreProtect; 11 | import net.coreprotect.config.ConfigHandler; 12 | import net.coreprotect.language.Phrase; 13 | import net.coreprotect.language.Selector; 14 | import net.coreprotect.thread.Scheduler; 15 | import net.coreprotect.utility.Chat; 16 | 17 | public class CoreProtectEditSessionEvent { 18 | private static boolean initialized = false; 19 | private static boolean isFAWE = false; 20 | private static CoreProtectEditSessionEvent event = new CoreProtectEditSessionEvent(); 21 | 22 | public static boolean isInitialized() { 23 | return initialized; 24 | } 25 | 26 | public static boolean isFAWE() { 27 | return isFAWE; 28 | } 29 | 30 | public static void register() { 31 | if (isInitialized()) { 32 | return; 33 | } 34 | 35 | try { 36 | WorldEdit.getInstance().getEventBus().register(new Object() { 37 | @Subscribe 38 | public void onEditSessionEvent(EditSessionEvent event) { 39 | if (event.getActor() != null && event.getStage() == Stage.BEFORE_CHANGE) { 40 | event.setExtent(new CoreProtectLogger(event.getActor(), event.getWorld(), event.getExtent())); 41 | } 42 | } 43 | }); 44 | initialized = true; 45 | ConfigHandler.worldeditEnabled = true; 46 | isFAWE = (Bukkit.getServer().getPluginManager().getPlugin("FastAsyncWorldEdit") != null); 47 | } 48 | catch (Exception e) { 49 | // Failed to initialize WorldEdit logging 50 | } 51 | 52 | Scheduler.runTask(CoreProtect.getInstance(), () -> { 53 | try { 54 | if (isInitialized()) { 55 | Chat.console(Phrase.build(Phrase.INTEGRATION_SUCCESS, isFAWE() ? "FastAsyncWorldEdit" : "WorldEdit", Selector.FIRST)); 56 | } 57 | else { 58 | Chat.console(Phrase.build(Phrase.INTEGRATION_ERROR, isFAWE() ? "FastAsyncWorldEdit" : "WorldEdit", Selector.FIRST)); 59 | } 60 | } 61 | catch (Exception e) { 62 | e.printStackTrace(); 63 | } 64 | }); 65 | } 66 | 67 | public static void unregister() { 68 | if (!isInitialized()) { 69 | return; 70 | } 71 | 72 | try { 73 | WorldEdit.getInstance().getEventBus().unregister(event); 74 | initialized = false; 75 | ConfigHandler.worldeditEnabled = false; 76 | Chat.console(Phrase.build(Phrase.INTEGRATION_SUCCESS, isFAWE() ? "FastAsyncWorldEdit" : "WorldEdit", Selector.SECOND)); 77 | } 78 | catch (Exception e) { 79 | Chat.console(Phrase.build(Phrase.INTEGRATION_ERROR, isFAWE() ? "FastAsyncWorldEdit" : "WorldEdit", Selector.SECOND)); 80 | } 81 | } 82 | } 83 | --------------------------------------------------------------------------------