Compare commits

..

153 Commits

Author SHA1 Message Date
Govindas cd039aeeaf Fix Integer & Update deps 2024-01-21 19:26:56 +02:00
Govindas 70456455e3 Remove link to jedis, misleading as user does not need to deal with that 2022-08-12 09:16:40 +00:00
Govindas 1ae0f6083e Document supported Minecraft versions 2022-08-12 09:14:43 +00:00
ham1255 ac6fe6cb99 1.3.6-SNAPSHOT && updated deps && moved jedis to the parent && due removal of JedisBinary, Jedis has method of that class now so its easy drop replacement && fixed jedis wont connect if password is not empty? && adding default values if config somehow is empty or field not there 2022-04-25 07:07:03 +04:00
Govindas 9ce27df3b8 Update 'README.md' 2022-03-22 11:45:51 +01:00
Govindas 2e75fdaa08 Update 'README.md' 2022-03-22 11:44:35 +01:00
Govindas 8c971765de Update 'README.md' 2022-03-22 11:43:19 +01:00
Govindas 5db2e01eab Update README.md 2022-03-22 12:10:17 +02:00
Govindas 7effb90baa Support add/remove actions with numbers on variables & Update dependencies 2022-03-22 11:58:41 +02:00
Govindas f0edb1cd21 Update dependencies 2022-01-23 11:44:36 +02:00
Govindas b9d74c14dd Set permission for /reloadredis, so it doesn't appear in /? for players 2021-12-13 12:00:27 +02:00
Govindas b466d27dc1 bumped jedis version due deleting not working 2021-10-21 11:09:14 +03:00
mohammed jasem alaajel a902fcc12d fixed a null due a typo 2021-10-21 11:09:12 +03:00
mohammed jasem alaajel b86ae9eb6d Fixed a typo that it wasn't able to encrypt 2021-10-21 11:09:12 +03:00
mohammed jasem alaajel b6b8a27a39 Never use maven module name!
Co-Authored-By: Govindas <16716020+GovindasOM@users.noreply.github.com>
2021-10-21 11:09:12 +03:00
mohammed jasem alaajel 13560e9925 i hate sun packages being imported 2021-10-21 11:09:12 +03:00
mohammed jasem alaajel 03d9698bf8 Update EffSendMessage.java 2021-10-21 11:09:12 +03:00
mohammed jasem alaajel a7f8f39675 read the notes xd 2021-10-21 11:09:12 +03:00
mohammed jasem alaajel d905b1490f changed version
1.4.0-SNAPSHOT -> 1.3.4
2021-10-21 11:09:12 +03:00
mohammed jasem alaajel 58457af086 added getJedisPool for skript reflect usage 2021-10-21 11:09:12 +03:00
mohammed jasem alaajel 01b5304719 fixed bug that messages dont send due null plugin 2021-10-21 11:09:12 +03:00
mohammed jasem alaajel a984da5f5f added static getting for skript reflect usage
in a safe way than static value.
2021-10-21 11:09:12 +03:00
mohammed jasem alaajel 2edc1903a7 changed some pom files behaviors. 2021-10-21 11:09:12 +03:00
mohammed jasem alaajel d66dd4a782 Update README.md 2021-10-21 11:09:12 +03:00
mohammed jasem alaajel 22a5625972 Revert "siv-mode 1.4.1->1.4.2"
This reverts commit b76632d1ee6cf2e2b1cfa03fabd11eafb6399e1b.
2021-10-21 11:09:12 +03:00
Govindas b9dd05a940 siv-mode 1.4.1->1.4.2 2021-10-21 11:09:12 +03:00
mohammed jasem alaajel 7b0163afc0 bumped depends 2021-10-21 11:09:12 +03:00
mohammed jasem alaajel f2b09f8c1c changed from spigot to paper 2021-10-21 11:09:12 +03:00
mohammed jasem alaajel b09dd121fc Proxy addition phase 1 2021-10-21 11:09:12 +03:00
mohammed jasem alaajel d89691212a Merge branch 'master' of https://github.com/Limework/RediSkript 2021-10-21 11:09:11 +03:00
mohammed jasem alaajel 757a10e7ee fixed maven build problem 2021-10-21 11:09:11 +03:00
mohammed jasem alaajel bcaf0212bb Update README.md 2021-10-21 11:09:11 +03:00
mohammed jasem alaajel 077b602e19 removed compile file
Note: you can find the jar inside target folder now.
2021-10-21 11:09:11 +03:00
mohammed jasem alaajel 7975bdd32e Create maven.yml 2021-10-21 11:09:11 +03:00
Govindas ce3bb77f57 make encryption even more informative 2021-10-21 11:09:11 +03:00
Govindas 0d2937e143 Make encryption config more informative & some other things 2021-10-21 11:09:11 +03:00
Govindas 0ea7816fa8 Update config.yml 2021-10-21 11:09:11 +03:00
Govindas efd49e4671 Update config to be more informative 2021-10-21 11:09:11 +03:00
Govindas 490e00a289 update siv-mode 2021-10-21 11:09:11 +03:00
Govindas 3dc1f2c7b7 1.3.3 2021-10-21 11:09:11 +03:00
Govindas fb3a389ee4 Fix set operation on {var::*} 2021-10-21 11:09:11 +03:00
Govindas c2ebac9030 Various fixes and improvements 2021-10-21 11:09:11 +03:00
Govindas 9a689aed7a Merge branch 'master' of https://github.com/Limework/RediSkript 2021-10-21 11:09:11 +03:00
Govindas 416f3f6625 bump Jedis version from 3.4.0 to 3.4.1 (has important fixes I think) 2021-10-21 11:09:11 +03:00
mohammed jasem alaajel 18a96e2c5b Update README.md 2021-10-21 11:09:11 +03:00
mohammed jasem alaajel c04c01792f added reloadconfig to redisreload 2021-10-21 11:09:11 +03:00
mohammed jasem alaajel 0783fd64d0 added debug check when error sending message 2021-10-21 11:09:11 +03:00
mohammed jasem alaajel b16ad58d16 fixed typo in logs sending.. 2021-10-21 11:09:11 +03:00
mohammed jasem alaajel 8aba280c17 Merge pull request #11 from Limework/patch-1
new ConnectionController!
2021-10-21 11:09:11 +03:00
mohammed jasem alaajel 7e5ef1bc3f Update README.md 2021-10-21 11:09:11 +03:00
mohammed jasem alaajel c84bb62b85 Update RedisController.java 2021-10-21 11:09:11 +03:00
mohammed jasem alaajel 94b1d9b241 Update README.md 2021-10-21 11:09:11 +03:00
mohammed jasem alaajel 0ab1913e5f Fixed bug where connection manager is keep reconnecting when connection reconnect after failure 2021-10-21 11:09:11 +03:00
Govindas 32a7cd08e3 Merge branch 'master' of https://github.com/Limework/RediSkript 2021-10-21 11:09:11 +03:00
mohammed jasem alaajel a387b94861 added replacement for system prinltn messages 2021-10-21 11:09:11 +03:00
mohammed jasem alaajel f4cf45c88d cleaned idea / removed typo in groupID 2021-10-21 11:09:11 +03:00
mohammed jasem alaajel 61a4b16953 new ConnectionController! 2021-10-21 11:09:11 +03:00
Govindas 5d73b4afc6 Update README.md 2021-10-21 11:09:11 +03:00
Govindas 36d3b4642e Reload redis in a separate thread to not lag the main thread 2021-10-21 11:09:10 +03:00
mohammed jasem alaajel 5bc7b0c438 noticed something weird in releases section that maven was 1 version late!!!!! 2021-10-21 11:09:10 +03:00
Govindas 4363d121a4 Finally fixed connection leak in /reloadredis !!! 2021-10-21 11:09:10 +03:00
mohammed jasem alaajel c8176f3cf9 fixed maven not compiling correctly 2021-10-21 11:09:10 +03:00
Govindas 89200f416f Improve code quality 2021-10-21 11:09:10 +03:00
mohammed jasem alaajel 141388829c bumped redis version aswell 2021-10-21 11:09:10 +03:00
Govindas 2fb2dbcc08 Remove unnecessary EventHandler 2021-10-21 11:09:10 +03:00
mohammed jasem alaajel 82f4a88cf5 bumped skript + spigot api version 2021-10-21 11:09:10 +03:00
Govindas a8c7250c31 Update README.md 2021-10-21 11:09:10 +03:00
mohammed jasem alaajel dea5fcfc56 Merge pull request #7 from Limework/add-license-1
Create LICENSE
2021-10-21 11:09:10 +03:00
mohammed jasem alaajel 87aa180e20 Create LICENSE 2021-10-21 11:09:10 +03:00
Govindas 1efb5a5fe5 Update README.md 2021-10-21 11:09:09 +03:00
Govindas e31773f6dd Optimizations 2021-10-21 11:09:08 +03:00
Govindas 3e4b6b78e7 Merge branch 'master' of https://github.com/Limework/RediSkript 2021-10-21 11:09:08 +03:00
Govindas cb7c2c1de8 Some more work on variables (Still very unfinished) 2021-10-21 11:09:08 +03:00
Govindas 3733018e7c Remove to-do list from readme (refer to issues) 2021-10-21 11:09:08 +03:00
Govindas 22e9cfdd40 Add cross-server variable editing (I'll make it use {} instead of strings later) 2021-10-21 11:09:08 +03:00
Govindas c33f49ca3c Allow sending multiple redis messages in one go 2021-10-21 11:09:08 +03:00
Govindas 13ce7d90c4 Fix rare error on disable 2021-10-21 11:09:08 +03:00
Govindas cf9da45f5d Fix wrong prefix coloring in command 2021-10-21 11:09:08 +03:00
Govindas ee294a4f65 test 2021-10-21 11:09:08 +03:00
Govindas f53f9dd5a2 Fix wrong class name & Fully fix sending messages while disabled 2021-10-21 11:09:08 +03:00
Govindas f35ad377d1 so I found that this threadpool was actually needed, oops
due to it not having threadpool, froze my server at one point
2021-10-21 11:09:08 +03:00
Govindas 76b7166145 Remove Skript plugin check, as it doesn't load without it anyway 2021-10-21 11:09:08 +03:00
Govindas 8d4ee31faa Oops forgot one more console message 2021-10-21 11:09:08 +03:00
Govindas dae23fe228 Improve console messages 2021-10-21 11:09:08 +03:00
Govindas 3373e86248 some refactoring, make classes more well-sorted 2021-10-21 11:09:08 +03:00
Govindas 114e4ed7cb use HIGHEST priority on disable, so "on script unload" can still work 2021-10-21 11:09:08 +03:00
Govindas 93e4754b9f Update jarRepositories.xml 2021-10-21 11:09:08 +03:00
Govindas 60a81fb32d Merge branch 'master' of https://github.com/Limework/RediSkript 2021-10-21 11:09:07 +03:00
Govindas 989440528b try fix maven 2 2021-10-21 11:09:07 +03:00
Govindas 1a4752f0d5 Update README.md 2021-10-21 11:09:07 +03:00
Govindas 3eaa27cb4d try fix maven 2021-10-21 11:09:07 +03:00
Govindas b3e2f897c3 Update pom.xml 2021-10-21 11:09:07 +03:00
Govindas 0dd09bbd50 Improve debug (thanks ShaneBee) 2021-10-21 11:09:07 +03:00
Govindas 3bddfe8d36 Little questionable improvements (shouldn't hurt anything anyway) 2021-10-21 11:09:07 +03:00
Govindas 0d5ba1c874 Make on redis message a synchronous event for thread-safety 2021-10-21 11:09:07 +03:00
Govindas 80aefba328 Merge branch 'master' of https://github.com/Limework/RediSkript 2021-10-21 11:09:07 +03:00
Govindas 13042c4805 Update README.md 2021-10-21 11:09:07 +03:00
Govindas 5ae6ad2235 Update pom.xml 2021-10-21 11:09:06 +03:00
Govindas 8244cf4974 Remove unneeded threadpool (testing has shown for it to be unneeded) 2021-10-21 11:09:06 +03:00
Govindas afab303292 change useSSL to useTLS, because redis itself refers to it as TLS 2021-10-21 11:09:06 +03:00
Govindas 266ba28a1d Revert "fixed reload but not tested"
This reverts commit a08ecd93b7.
2021-10-21 11:09:06 +03:00
Govindas 625e7b0d83 Revert "Update RedisManager.java"
This reverts commit 6c5d580b16.
2021-10-21 11:09:06 +03:00
Govindas d443203c64 Revert "Update RedisManager.java"
This reverts commit b93624bc49.
2021-10-21 11:09:06 +03:00
mohammed jasem alaajel eb00a0c0b4 Update RedisManager.java 2021-10-21 11:09:06 +03:00
mohammed jasem alaajel 9bed693a03 Update RedisManager.java 2021-10-21 11:09:06 +03:00
mohammed jasem alaajel 5f074d3472 fixed reload but not tested 2021-10-21 11:09:06 +03:00
Govindas 2851d8e8a1 Re-word redis reload command information 2021-10-21 11:09:05 +03:00
Govindas 00dd267d72 Fix critical redis server shutdown bug 2021-10-21 11:09:05 +03:00
Govindas cfc8ceb2ec Better 1.8 support & cleanup 2021-10-21 11:09:05 +03:00
Govindas ef71150db2 Undo synchronous event, broke 1.8 servers completely 2021-10-21 11:09:05 +03:00
Govindas df9297e324 add redis message date expression & improve quality of existing expressions & make event guaranteedly synchronous 2021-10-21 11:09:05 +03:00
Govindas 3992ff508e New /reloadredis fully restarts the plugin with reloaded configuration & some code improvements 2021-10-21 11:09:05 +03:00
Govindas 94f90efcf1 Make json errors easier to debug 2021-10-21 11:09:05 +03:00
Govindas a9560d78a1 Reduce jar size by removing unneeded dependencies 2021-10-21 11:09:05 +03:00
Govindas b17345d0be Merge branch 'master' of https://github.com/Limework/RediSkript 2021-10-21 11:09:05 +03:00
Govindas 4d8ce22991 Update README.md 2021-10-21 11:09:05 +03:00
Govindas de2cc644f2 Remove debug message & Hotfix 2020-10-22 14:19:29 +03:00
Govindas 86c1ebab5c Further fixes & refactoring for release 2020-10-22 13:30:41 +03:00
Govindas 599faa7dbb Fix encryption disabling & some refactoring 2020-10-22 12:32:08 +03:00
Govindas bfbdd3fabc Remove unneeded code 2020-10-18 17:07:37 +03:00
mohammed jasem alaajel ec451d56e5 small fix to make sure the connect was killed 2020-07-30 09:35:50 +04:00
mohammed jasem alaajel 7f8cbc3bc0 added protection to kill current working sub 2020-07-28 10:53:42 +04:00
mohammed jasem alaajel 9ecde41c2d added /reloadredis command 2020-07-28 10:44:00 +04:00
ham1255 f9017773bc Fixed mongodb url from config is wrong 2020-07-08 12:37:10 +04:00
ham1255 3c461c6307 added mongodb, bumped versoin 2020-07-07 18:49:19 +04:00
ham1255 aca7ec2a13 new changes. 2020-07-06 22:38:54 +04:00
ham1255 b956363228 Skript counts as softdepend as it make the plugin usable without skript 2020-06-30 12:44:49 +04:00
ham1255 b668815be4 abstract class for guis making for making stuff easier 2020-06-30 12:42:27 +04:00
ham1255 8f951757bc moved some stuff and fixed wrong usage 2020-06-30 11:45:14 +04:00
ham1255 e1b051623b forgot one line xd 2020-06-28 18:41:22 +04:00
ham1255 624aa09bf7 not tested But rewritten the Plugin 2020-06-28 18:40:53 +04:00
ham1255 96f795a52c Update .gitignore 2020-06-28 16:45:02 +04:00
ham1255 85c0f09d6c Delete SkLimework.iml 2020-06-28 16:41:47 +04:00
ham1255 cbe5b9ca48 renamed project 2020-06-28 16:39:21 +04:00
ham1255 1f6cc496ba Merge branch 'master' of https://github.com/Limework/SkLimework 2020-06-26 17:03:14 +04:00
ham1255 e3edfd84fc fixed conflict and removed hard coded channels 2020-06-26 17:02:39 +04:00
Govindas 99cde26bba fix channel syntax conflict with Vixio 2020-06-26 15:58:30 +03:00
ham1255 68788af789 added maven to since it will get rewritten soon. 2020-06-22 13:48:44 +04:00
ham1255 03bbf3c78d New Reconnector hopefuly works 2020-06-14 17:43:46 +04:00
Govindas 2482e67bca Highly improve encryption security 2020-06-08 16:53:23 +03:00
Govindas 2e33fe4779 attempt to use SIV 2020-06-08 11:16:16 +03:00
ham1255 5b438eb148 Fixed loop doesn;'t exist on server shutdown 2020-06-05 13:28:26 +04:00
Govindas eb73047d14 Remove awaitTermination as it was preventing shutdown sometimes 2020-05-30 10:11:43 +03:00
Govindas 9d7fbcd33b Finish AES encryption 2020-05-27 16:22:05 +03:00
Govindas a6b6379234 Fix forgotten digest 2020-05-27 15:10:26 +03:00
Govindas ef03a7cc72 Add AES-128 encryption 2020-05-27 14:43:16 +03:00
ham1255 b6a8b5005c ,. 2020-05-18 01:57:36 +04:00
ham1255 68589c37a0 Fixed not reconnecting on redis 4* or higher 2020-05-12 14:35:30 +04:00
ham1255 ed434211a1 Added Reconnection for channels sub 2020-05-10 23:10:45 +04:00
ham1255 bcf7f08d81 Check if error will occure when redis fails 2020-05-10 21:44:10 +04:00
ham1255 80f65ebb8a added ignore 2020-05-10 10:53:54 +04:00
ham1255 78ca2849e4 added code 2020-05-10 10:52:06 +04:00
mohammed jassim alajel d67568599a Create README.md 2020-05-10 10:39:19 +04:00
24 changed files with 676 additions and 485 deletions
+32
View File
@@ -0,0 +1,32 @@
# This workflow will build a Java project with Maven
# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven
name: RediSkript Build
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up JDK 11
uses: actions/setup-java@v2
with:
java-version: '8'
distribution: 'adopt'
- name: Build with Maven
run: mvn -B package --file pom.xml
- name: Download a Build Artifact
uses: actions/upload-artifact@v2.2.3
with:
# Artifact name
name: RediSkript_JAR
# Destination path
path: target/*.jar
+1
View File
@@ -5,3 +5,4 @@ out
compile
*.iml
*.iml
+47 -21
View File
@@ -1,33 +1,42 @@
RediSkript allows you to communicate between your servers with use of Redis, it's very fast and easy to use.
## RediSkript
Allows you to communicate between your Minecraft servers with use of Redis and Skript, it's very fast and easy to use.
Skript: https://github.com/SkriptLang/Skript
RediSkript spigot page: https://www.spigotmc.org/resources/rediskript-communicate-between-servers-with-ease.85067/
RediSkript spigot page: https://www.spigotmc.org/resources/rediskript-communicate-between-servers-with-ease.85067/s
Jedis: https://github.com/redis/jedis
Minecraft server version supported: **1.8.8+** (On 1.8, may need to use a fork of Skript)
You can transfer any data in the form of text between your servers, you can program it to execute a set of instructions on the server depending on the redis message, etc. This can be used for making scripts that sync data between all servers and much more!
It is developed and maintained by Govindas & the team of Govindas Limework developers.
Redis Message:
There is only one command: **/reloadredis** it fully reloads the configuration, you can reload IP, password, channels and everything else.
You only need to have matching configuration in every server for communication and a Redis server to connect to. I recommend using a VPS for hosting redis server, but there also are free redis hosting options available.
### Redis Message
```
on redis message:
if redis channel is "world":
broadcast "%redis message% %redis channel% %redis message date%"
command /sendredis <text> <text>:
usage: /sendredis <message> <channel>
trigger:
send redis message arg 1 to channel arg 2
send redis message "hello world!" to channel "world"
```
Managing variables:
### Managing variables
```
set variables "test::1", "test::2", "test::3" in channel "global" to 100
#then use this in any server that listens to "global" redis channel and was online when the above line was executed:
send "%{test::*}%" #outputs 100, 100 and 100
add 100 to variables "test::1" and "test::2" in channel "global"
remove 10 from variable "test::1" in channel "global"
delete variables "test::*" in channel "global"
set variable "test::%uuid of player%" in channel "playerdata" to tool of player
@@ -39,39 +48,56 @@ Syntax:
variable[s] %strings% in [redis] [channel] %string%
```
There is only one command: /reloadredis it fully reloads the configuration, you can reload IP, password, channels and everything else.
You only need to have matching configuration in every server for communication and a Redis server to connect to. I recommend using VPS for hosting redis server, I personally use VPS from humbleservers.com.
Configuration:
### Configuration
plugins/RediSkript/config.yml
```
Redis:
#a secure password that cannot be cracked, please change it!
#it is also recommended to firewall your redis server with iptables so it can only be accessed by specific IP addresses
Password: "yHy0d2zdBlRmaSPj3CiBwEv5V3XxBTLTrCsGW7ntBnzhfxPxXJS6Q1aTtR6DSfAtCZr2VxWnsungXHTcF94a4bsWEpGAvjL9XMU"
#hostname of your redis server, you can use free redis hosting (search for it online) if you do not have the ability to host your own redis server
#redis server is very lightweight, takes under 30 MB of RAM usually
Host: "127.0.0.1"
#must be 2 or higher, if you set to lower, the addon will automatically use 2 as a minimum
#do not edit MaxConnections if you do not know what you're doing
#it is only useful to increase this number to account for PING between distant servers and when you are sending a lot of messages constantly
MaxConnections: 2
#the default Redis port
Port: 6379
#time out in milliseconds, how long it should take before it decides that it is unable to connect when sending a message
#90000 = 90 seconds
TimeOut: 90000
#9000 = 9 seconds
TimeOut: 9000
#also known as SSL, only use this if you're running Redis 6.0.6 or higher, older versions will not work correctly
#it encrypts your traffic and makes data exchange between distant servers completely secure
#it encrypts your traffic and makes data exchange between distant servers secure
useTLS: false
#may be useful if you cannot use TLS due to use of older version of Redis
#however this will not encrypt the initial authentication password, only the messages sent
#it uses AES-128 SIV encryption which is secure enough for this
#EncryptMessages may be useful if you cannot use TLS due to use of older version of Redis or if you're paranoid about privacy and want to double encrypt your messages
#however this will not encrypt the initial authentication password, only the messages sent (use TLS for initial authentication password encryption)
#the encryption configuration must be the same across all servers in order to communicate
#use 16 characters long key for AES-128 encryption
#32 characters long key for AES-256 encryption (recommended)
#the AES implementation used in RediSkript uses SIV mode, which makes the same key resistant to cracking for a big count of messages without the need of changing the key very often
EncryptMessages: true
EncryptionKey: "16CHARACTERS KEY"
MacKey: "16CHARACTERS KEY"
#EncryptionKey and MacKey must be different
EncryptionKey: "32CHARACTERS KEY"
MacKey: "32CHARACTERS KEY"
#the channels from which this server can receive messages
#you can always send messages to all channels!
#you can add as many channels as you wish!
#ideal setup is having one global channel and having one channel that represents server name, so you know who to send messages to
#then a few other utility channels up to your needs
Channels:
- "Channel1"
- "Channel2"
- "global"
- "servername"
- "Channel3"
```
## YourKit
YourKit supports open source projects with innovative and intelligent tools for monitoring and profiling Java and .NET applications. YourKit is the creator of [YourKit Java Profiler](https://www.yourkit.com/java/profiler/), [YourKit .NET Profiler](https://www.yourkit.com/.net/profiler/) and [YourKit YouMonitor](https://www.yourkit.com/youmonitor/).
![YourKit](https://www.yourkit.com/images/yklogo.png)
+83
View File
@@ -0,0 +1,83 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>RediSkript</artifactId>
<groupId>net.limework</groupId>
<version>1.3.7-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>RediSkript-bukkit</artifactId>
<repositories>
<repository>
<id>papermc</id>
<url>https://papermc.io/repo/repository/maven-public/</url>
</repository>
</repositories>
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.3</version>
<configuration>
<createDependencyReducedPom>false</createDependencyReducedPom>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.2.0</version>
<configuration>
<outputDirectory>../target</outputDirectory>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>com.github.SkriptLang</groupId>
<artifactId>Skript</artifactId>
<version>2.6.1</version>
<type>jar</type>
<exclusions>
<exclusion>
<groupId>*</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.16.5-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>net.limework</groupId>
<artifactId>RediSkript-core</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</project>
@@ -10,6 +10,7 @@ import net.limework.rediskript.commands.CommandReloadRedis;
import net.limework.rediskript.events.RedisMessageEvent;
import net.limework.rediskript.managers.RedisController;
import net.limework.rediskript.skript.elements.*;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.plugin.java.JavaPlugin;
@@ -79,10 +80,22 @@ public class RediSkript extends JavaPlugin {
@Override
public void onDisable() {
if (redisController != null) redisController.shutdown();
if (redisController != null) {
redisController.shutdown();
}
getServer().getPluginCommand("reloadredis").setExecutor(null);
}
public RedisController getRC() {
return redisController;
}
//Developer note: This is use for skript-reflect! and also for plugin use for static stuff -> skript effects classes
//DO NOT USE THIS IN NON STATIC CLASSES
public static RediSkript getAPI(){
//this safer than making static.
return (RediSkript) Bukkit.getServer().getPluginManager().getPlugin("RediSkript");
}
}
@@ -0,0 +1,386 @@
package net.limework.rediskript.managers;
import ch.njol.skript.registrations.Classes;
import ch.njol.skript.variables.Variables;
import net.limework.rediskript.RediSkript;
import net.limework.rediskript.data.Encryption;
import net.limework.rediskript.events.RedisMessageEvent;
import org.bukkit.Bukkit;
import org.bukkit.configuration.Configuration;
import org.bukkit.scheduler.BukkitTask;
import org.cryptomator.siv.UnauthenticCiphertextException;
import org.json.JSONArray;
import org.json.JSONObject;
import redis.clients.jedis.*;
import redis.clients.jedis.exceptions.JedisConnectionException;
import javax.crypto.IllegalBlockSizeException;
import java.nio.charset.StandardCharsets;
import java.util.Base64;
import java.util.List;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.logging.Level;
public class RedisController extends BinaryJedisPubSub implements Runnable {
//Jedis Pool to be used by every another class.
private final JedisPool jedisPool;
//this seems useless unless tls is OFF!
// class author is govindas :/
private final Encryption encryption;
private byte[][] channelsInByte;
private final AtomicBoolean isConnectionBroken;
private final AtomicBoolean isConnecting;
private final RediSkript plugin;
private final BukkitTask ConnectionTask;
public RedisController(RediSkript plugin) {
this.plugin = plugin;
Configuration config = plugin.getConfig();
JedisPoolConfig JConfig = new JedisPoolConfig();
int maxConnections = config.getInt("Redis.MaxConnections");
//do not allow less than 2 max connections as that causes issues
if (maxConnections < 2) {
maxConnections = 2;
}
JConfig.setMaxTotal(maxConnections);
JConfig.setMaxIdle(maxConnections);
JConfig.setMinIdle(1);
JConfig.setBlockWhenExhausted(true);
final String password = config.getString("Redis.Password", "");
if (password.isEmpty()) {
this.jedisPool = new JedisPool(JConfig,
config.getString("Redis.Host", "127.0.0.1"),
config.getInt("Redis.Port", 6379),
config.getInt("Redis.TimeOut", 9000),
config.getBoolean("Redis.useTLS", false));
} else {
this.jedisPool = new JedisPool(JConfig,
config.getString("Redis.Host", "127.0.0.1"),
config.getInt("Redis.Port", 6379),
config.getInt("Redis.TimeOut", 9000),
password,
config.getBoolean("Redis.useTLS", false));
}
encryption = new Encryption(config.getBoolean("Redis.EncryptMessages"),
config.getString("Redis.EncryptionKey"),
config.getString("Redis.MacKey"));
setupChannels(config);
isConnectionBroken = new AtomicBoolean(true);
isConnecting = new AtomicBoolean(false);
//Start the main task on async thread
ConnectionTask = plugin.getServer().getScheduler().runTaskTimerAsynchronously(plugin, this, 0, 20 * 5);
}
@Override
public void run() {
if (!isConnectionBroken.get() || isConnecting.get()) {
return;
}
plugin.sendLogs("Connecting to Redis server...");
isConnecting.set(true);
try (Jedis jedis = jedisPool.getResource()) {
isConnectionBroken.set(false);
plugin.sendLogs("&aConnection to Redis server has established! Success!");
jedis.subscribe(this, channelsInByte);
} catch (Exception e) {
isConnecting.set(false);
isConnectionBroken.set(true);
plugin.sendErrorLogs("Connection to Redis server has failed! Please check your details in the configuration.");
e.printStackTrace();
}
}
public void shutdown() {
ConnectionTask.cancel();
if (this.isSubscribed()) {
try {
this.unsubscribe();
} catch (Exception e) {
plugin.sendErrorLogs("Something went wrong during unsubscribing...");
e.printStackTrace();
}
}
jedisPool.close();
}
@Override
public void onMessage(byte[] channel, byte[] message) {
String channelString = new String(channel, StandardCharsets.UTF_8);
String receivedMessage = null;
try {
//if encryption is enabled, decrypt the message, else just convert binary to string
if (this.encryption.isEncryptionEnabled()) {
try {
receivedMessage = encryption.decrypt(message);
} catch (UnauthenticCiphertextException | IllegalBlockSizeException e) {
e.printStackTrace();
}
} else {
//encryption is disabled, so let's just get the string
receivedMessage = new String(message, StandardCharsets.UTF_8);
}
if (receivedMessage != null) {
JSONObject j = new JSONObject(receivedMessage);
if (j.get("Type").equals("Skript")) {
JSONArray messages = j.getJSONArray("Messages");
RedisMessageEvent event;
for (int i = 0; i < messages.length(); i++) {
event = new RedisMessageEvent(channelString, messages.get(i).toString(), j.getLong("Date"));
//if plugin is disabling, don't call events anymore
if (plugin.isEnabled()) {
RedisMessageEvent finalEvent = event;
Bukkit.getScheduler().runTask(plugin, () -> plugin.getServer().getPluginManager().callEvent(finalEvent));
}
}
} else if (j.get("Type").equals("SkriptVariables")) {
//Transfer variables between servers
JSONArray varNames = j.getJSONArray("Names");
Object inputValue;
String changeValue = null;
JSONArray varValues = null;
if (!j.isNull("Values")) {
varValues = j.getJSONArray("Values");
}
for (int i = 0; i < varNames.length(); i++) {
String varName = varNames.get(i).toString();
if (j.isNull("Values")) {
// only check for SET here, because null has to be ignored in all other cases
if (j.getString("Operation").equals("SET")) {
Variables.setVariable(varName, null, null, false);
}
} else {
if (!varValues.isNull(i)) {
changeValue = varValues.get(i).toString();
}
String[] inputs = changeValue.split("\\^", 2);
inputValue = Classes.deserialize(inputs[0], Base64.getDecoder().decode(inputs[1]));
switch (j.getString("Operation")) {
case "ADD":
if (varName.charAt(varName.length() - 1) == '*') {
plugin.getLogger().log(Level.WARNING, "Adding to {::*} variables in RediSkript is not supported. Variable name: " + varName);
continue;
}
Object variable = Variables.getVariable(varName, null, false);
if (variable == null) {
Variables.setVariable(varName, inputValue, null, false);
} else if (variable instanceof Long) {
if (inputValue instanceof Integer) {
inputValue = Long.valueOf((Integer) inputValue);
}
if (inputValue instanceof Long) {
Variables.setVariable(varName, (Long) variable + (Long) inputValue, null, false);
} else if (inputValue instanceof Double) {
// convert Long variable to Double
variable = Double.valueOf((Long) variable);
Variables.setVariable(varName, (Double) variable + (Double) inputValue, null, false);
} else {
// Not supported input type
plugin.getLogger().log(Level.WARNING, "Unsupported add action of data type (" + inputValue.getClass().getName() + ") on variable: " + varName);
continue;
}
} else if (variable instanceof Double) {
if (inputValue instanceof Integer) {
inputValue = Double.valueOf((Integer) inputValue);
}
if (inputValue instanceof Double) {
Variables.setVariable(varName, (Double) variable + (Double) inputValue, null, false);
} else if (inputValue instanceof Long) {
Variables.setVariable(varName, (Double) variable + ((Long) inputValue).doubleValue(), null, false);
} else {
// Not supported input type
plugin.getLogger().log(Level.WARNING, "Unsupported add action of data type (" + inputValue.getClass().getName() + ") on variable: " + varName);
continue;
}
} else if (variable instanceof Integer) {
if (inputValue instanceof Integer) {
Variables.setVariable(varName, (Integer) variable + (Integer) inputValue, null, false);
} else if (inputValue instanceof Double) {
// convert Integer variable to Double
variable = Double.valueOf((Integer) variable);
Variables.setVariable(varName, (Double) variable + (Double) inputValue, null, false);
} else if (inputValue instanceof Long) {
// convert Integer variable to Long
variable = Long.valueOf((Integer) variable);
Variables.setVariable(varName, (Long) variable + (Long) inputValue, null, false);
}
} else {
// Not supported input type
plugin.getLogger().log(Level.WARNING, "Unsupported variable type in add action (" + variable.getClass().getName() + ") on variable: " + varName);
continue;
}
break;
case "REMOVE":
if (varName.charAt(varName.length() - 1) == '*') {
plugin.getLogger().log(Level.WARNING, "Removing from {::*} variables in RediSkript is not supported. Variable name: " + varName);
continue;
}
variable = Variables.getVariable(varName, null, false);
if (variable == null) {
if (inputValue instanceof Long) {
Variables.setVariable(varName, -(Long) inputValue, null, false);
} else if (inputValue instanceof Double) {
Variables.setVariable(varName, -(Double) inputValue, null, false);
} else if (inputValue instanceof Integer) {
Variables.setVariable(varName, -(Integer) inputValue, null, false);
} else {
// Not supported input type
plugin.getLogger().log(Level.WARNING, "Unsupported remove action of data type (" + inputValue.getClass().getName() + ") on variable: " + varName);
continue;
}
} else if (variable instanceof Long) {
if (inputValue instanceof Integer) {
inputValue = Long.valueOf((Integer) inputValue);
}
if (inputValue instanceof Long) {
Variables.setVariable(varName, (Long) variable - (Long) inputValue, null, false);
} else if (inputValue instanceof Double) {
// convert Long variable to Double
variable = Double.valueOf((Long) variable);
Variables.setVariable(varName, (Double) variable - (Double) inputValue, null, false);
} else {
// Not supported input type
plugin.getLogger().log(Level.WARNING, "Unsupported remove action of data type (" + inputValue.getClass().getName() + ") on variable: " + varName);
continue;
}
} else if (variable instanceof Double) {
if (inputValue instanceof Integer) {
inputValue = Double.valueOf((Integer) inputValue);
}
if (inputValue instanceof Double) {
Variables.setVariable(varName, (Double) variable - (Double) inputValue, null, false);
} else if (inputValue instanceof Long) {
Variables.setVariable(varName, (Double) variable - ((Long) inputValue).doubleValue(), null, false);
}
} else if (variable instanceof Integer) {
if (inputValue instanceof Integer) {
Variables.setVariable(varName, (Integer) variable - (Integer) inputValue, null, false);
} else if (inputValue instanceof Long) {
// convert Integer variable to Long
variable = Long.valueOf((Integer) variable);
Variables.setVariable(varName, (Long) variable - (Long) inputValue, null, false);
} else if (inputValue instanceof Double) {
// convert Integer variable to Double
variable = Double.valueOf((Integer) variable);
Variables.setVariable(varName, (Double) variable - (Double) inputValue, null, false);
}
} else {
// Not supported input type
plugin.getLogger().log(Level.WARNING, "Unsupported variable type in remove action (" + variable.getClass().getName() + ") on variable: " + varName);
continue;
}
break;
case "SET":
//this is needed, because setting a {variable::*} causes weird behavior, like
//1st set operation is no data, 2nd has data, etc.
//if you set it to null before action, it works correctly
if (varName.charAt(varName.length() - 1) == '*') {
Variables.setVariable(varName, null, null, false);
}
Variables.setVariable(varNames.get(i).toString(), inputValue, null, false);
break;
}
}
}
}
}
} catch (Exception e) {
plugin.sendErrorLogs("&cI got a message that was empty from channel " + channelString + " please check your code that you used to send the message. Message content:");
plugin.sendErrorLogs(receivedMessage);
e.printStackTrace();
}
}
public void sendMessage(String[] message, String channel) {
JSONObject json = new JSONObject();
json.put("Messages", new JSONArray(message));
json.put("Type", "Skript");
json.put("Date", System.currentTimeMillis()); //for unique string every time & PING calculations
finishSendMessage(json, channel);
}
public void sendVariables(String[] variableNames, String[] variableValues, String channel, String operation) {
JSONObject json = new JSONObject();
json.put("Names", new JSONArray(variableNames));
if (variableValues != null) {
json.put("Values", new JSONArray(variableValues));
}
json.put("Type", "SkriptVariables");
json.put("Date", System.currentTimeMillis()); //for unique string every time & PING calculations
json.put("Operation", operation);
finishSendMessage(json, channel);
}
public void finishSendMessage(JSONObject json, String channel) {
try {
byte[] message;
if (encryption.isEncryptionEnabled()) {
message = encryption.encrypt(json.toString());
} else {
message = json.toString().getBytes(StandardCharsets.UTF_8);
}
//sending a redis message blocks main thread if there's no more connections available
//so to avoid issues, it's best to do it always on separate thread
if (plugin.isEnabled()) {
plugin.getServer().getScheduler().runTaskAsynchronously(plugin, () -> {
try (Jedis j = jedisPool.getResource()) {
j.publish(channel.getBytes(StandardCharsets.UTF_8), message);
} catch (Exception e) {
plugin.sendErrorLogs("Error sending redis message!");
e.printStackTrace();
}
});
} else {
//execute sending of redis message on the main thread if plugin is disabling
//so it can still process the sending
try (Jedis j = jedisPool.getResource()) {
j.publish(channel.getBytes(StandardCharsets.UTF_8), message);
} catch (Exception e) {
e.printStackTrace();
}
}
} catch (JedisConnectionException exception) {
exception.printStackTrace();
}
}
private void setupChannels(Configuration config) {
List<String> channels = config.getStringList("Channels");
channelsInByte = new byte[channels.size()][1];
for (int x = 0; x < channels.size(); x++) {
channelsInByte[x] = channels.get(x).getBytes(StandardCharsets.UTF_8);
}
}
public Boolean isRedisConnectionOffline() {
return isConnectionBroken.get();
}
// for skript reflect :)
public JedisPool getJedisPool() {
return jedisPool;
}
//
}
@@ -23,7 +23,7 @@ public class EffSendMessage extends Effect {
@Override
protected void execute(Event event) {
RediSkript plugin = (RediSkript) Bukkit.getPluginManager().getPlugin("RediSkript");
RediSkript plugin = RediSkript.getAPI();
String[] message = this.message.getAll(event);
String channel = this.channel.getSingle(event);
@@ -25,9 +25,7 @@ public class ExprChannel extends SimpleExpression<String> {
}
@Override
public String toString(Event event, boolean b) {
return "redis channel";
}
public String toString(Event event, boolean b) { return "redis channel"; }
@Override
public boolean init(final Expression<?>[] expressions, final int matchedPattern, final Kleenean isDelayed, final SkriptParser.ParseResult parseResult) {
@@ -1,12 +1,9 @@
package net.limework.rediskript.skript.elements;
import ch.njol.skript.Skript;
import ch.njol.skript.classes.Changer;
import ch.njol.skript.lang.Expression;
import ch.njol.skript.lang.SkriptParser;
import ch.njol.skript.lang.Variable;
import ch.njol.skript.lang.util.SimpleExpression;
import ch.njol.skript.log.ErrorQuality;
import ch.njol.skript.registrations.Classes;
import ch.njol.skript.variables.SerializedVariable;
import ch.njol.util.Kleenean;
@@ -49,7 +46,7 @@ public class ExprVariableInChannel extends SimpleExpression<Object> {
}
@Override
public void change(Event e, Object[] changer, Changer.ChangeMode mode) {
RediSkript plugin = (RediSkript) Bukkit.getPluginManager().getPlugin("RediSkript");
RediSkript plugin = RediSkript.getPlugin(RediSkript.class);
switch (mode) {
case ADD:
case SET:
@@ -76,7 +73,7 @@ public class ExprVariableInChannel extends SimpleExpression<Object> {
@Override
public Class<?>[] acceptChange(Changer.ChangeMode mode) {
//if (mode == Changer.ChangeMode.DELETE || mode == Changer.ChangeMode.SET || mode == Changer.ChangeMode.ADD || mode == Changer.ChangeMode.REMOVE)
if (mode == Changer.ChangeMode.DELETE || mode == Changer.ChangeMode.SET)
if (mode == Changer.ChangeMode.DELETE || mode == Changer.ChangeMode.SET || mode == Changer.ChangeMode.ADD || mode == Changer.ChangeMode.REMOVE)
return CollectionUtils.array(Object.class);
return null;
@@ -0,0 +1,44 @@
Redis:
#a secure password that cannot be cracked, please change it!
#it is also recommended to firewall your redis server with iptables so it can only be accessed by specific IP addresses
Password: "yHy0d2zdBlRmaSPj3CiBwEv5V3XxBTLTrCsGW7ntBnzhfxPxXJS6Q1aTtR6DSfAtCZr2VxWnsungXHTcF94a4bsWEpGAvjL9XMU"
#hostname of your redis server, you can use free redis hosting (search for it online) if you do not have the ability to host your own redis server
#redis server is very lightweight, takes under 30 MB of RAM usually
Host: "127.0.0.1"
#must be 2 or higher, if you set to lower, the addon will automatically use 2 as a minimum
#do not edit MaxConnections if you do not know what you're doing
#it is only useful to increase this number to account for PING between distant servers and when you are sending a lot of messages constantly
MaxConnections: 2
#the default Redis port
Port: 6379
#time out in milliseconds, how long it should take before it decides that it is unable to connect when sending a message
#9000 = 9 seconds
TimeOut: 9000
#also known as SSL, only use this if you're running Redis 6.0.6 or higher, older versions will not work correctly
#it encrypts your traffic and makes data exchange between distant servers secure
useTLS: false
#EncryptMessages may be useful if you cannot use TLS due to use of older version of Redis or if you're paranoid about privacy and want to double encrypt your messages
#however this will not encrypt the initial authentication password, only the messages sent (use TLS for initial authentication password encryption)
#the encryption configuration must be the same across all servers in order to communicate
#use 16 characters long key for AES-128 encryption
#32 characters long key for AES-256 encryption (recommended)
#AES-128 is faster, but less secure (but it is not crackable by today's technology as of 2020, may be crackable by quantum computers)
#the AES implementation used in RediSkript uses SIV mode, which makes the same key resistant to cracking for a big count of messages without the need of changing the key very often
EncryptMessages: true
#EncryptionKey and MacKey must be different
EncryptionKey: "32CHARACTERS KEY"
MacKey: "32CHARACTERS KEY"
#the channels from which this server can receive messages
#you can always send messages to all channels!
#you can add as many channels as you wish!
#ideal setup is having one global channel and having one channel that represents server name, so you know who to send messages to
#then a few other utility channels up to your needs
Channels:
- "global"
- "servername"
- "Channel3"
@@ -1,9 +1,10 @@
main: net.limework.rediskript.RediSkript
name: ${project.name}
name: RediSkript
version: ${project.version}
authors: [Govindas, ham1255, DaemonicKing, limework.net]
api-version: 1.13
depend: [Skript]
commands:
reloadredis:
description: "Reload redis configuration & restart the connection."
description: "Reload redis configuration & restart the connection."
permission: reload.redis
+14
View File
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>RediSkript</artifactId>
<groupId>net.limework</groupId>
<version>1.3.7-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>RediSkript-core</artifactId>
</project>
@@ -0,0 +1,11 @@
package net.limework.rediskript;
import redis.clients.jedis.BinaryJedisPubSub;
public abstract class Subscriber extends BinaryJedisPubSub implements Runnable {
}
@@ -1,6 +1,5 @@
package net.limework.rediskript.data;
import org.bukkit.configuration.Configuration;
import org.cryptomator.siv.SivMode;
import org.cryptomator.siv.UnauthenticCiphertextException;
@@ -9,17 +8,17 @@ import java.nio.charset.StandardCharsets;
public class Encryption {
private boolean encryptionEnabled;
private final boolean encryptionEnabled;
private String encryptionKey;
private String macKey;
private final SivMode AES_SIV = new SivMode();
public Encryption(Configuration config){
encryptionEnabled = config.getBoolean("Redis.EncryptMessages");
if (encryptionEnabled) {
// AES-128 encryption
encryptionKey = config.getString("Redis.EncryptionKey");
macKey = config.getString("Redis.MacKey");
public Encryption(boolean encryptionEnabled, String encryptionKey, String macKey){
this.encryptionEnabled = encryptionEnabled;
if (this.encryptionEnabled) {
// AES encryption
this.encryptionKey = encryptionKey;
this.macKey = macKey;
}
}
-73
View File
@@ -1,73 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8">
<output url="file://$MODULE_DIR$/target/classes" />
<output-test url="file://$MODULE_DIR$/target/test-classes" />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
<excludeFolder url="file://$MODULE_DIR$/target" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" scope="PROVIDED" name="Maven: com.destroystokyo.paper:paper-api:1.15-R0.1-SNAPSHOT" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: org.ow2.asm:asm:7.1" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: org.ow2.asm:asm-commons:7.1" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: org.ow2.asm:asm-tree:7.1" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: org.ow2.asm:asm-analysis:7.1" level="project" />
<orderEntry type="library" name="Maven: com.google.code.gson:gson:2.8.6" level="project" />
<orderEntry type="library" name="Maven: org.jetbrains:annotations:19.0.0" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: com.github.SkriptLang:Skript:2.5.3" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: com.destroystokyo.paper:paper-api:1.16.4-R0.1-SNAPSHOT" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: com.google.code.findbugs:jsr305:1.3.9" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: com.googlecode.json-simple:json-simple:1.1.1" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: junit:junit:4.10" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: org.hamcrest:hamcrest-core:1.1" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: org.ow2.asm:asm:8.0.1" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: org.ow2.asm:asm-commons:8.0.1" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: org.ow2.asm:asm-tree:8.0.1" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: org.ow2.asm:asm-analysis:8.0.1" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: org.eclipse.jdt:org.eclipse.jdt.annotation:1.1.0" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: com.google.code.findbugs:findbugs:3.0.1" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: net.jcip:jcip-annotations:1.0" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: com.google.code.findbugs:bcel-findbugs:6.0" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: com.google.code.findbugs:jFormatString:2.0.1" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: dom4j:dom4j:1.6.1" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: xml-apis:xml-apis:1.0.b2" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: org.ow2.asm:asm-debug-all:5.0.2" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: com.apple:AppleJavaExtensions:1.4" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: jaxen:jaxen:1.1.6" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: com.sk89q.worldguard:worldguard-legacy:7.0.0-SNAPSHOT" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: org.bukkit:bukkit:1.13-R0.1-SNAPSHOT" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: com.sk89q.worldedit:worldedit-bukkit:7.0.0-SNAPSHOT" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: com.sk89q.worldedit:worldedit-core:7.0.0-SNAPSHOT" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: com.sk89q.worldedit.worldedit-libs:core:7.0.0-SNAPSHOT" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: de.schlichtherle:truezip:6.8.3" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: rhino:js:1.7R2" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: com.sk89q.worldedit.worldedit-libs:bukkit:7.0.0-SNAPSHOT" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: org.apache.logging.log4j:log4j-slf4j-impl:2.8.1" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: org.apache.logging.log4j:log4j-api:2.8.1" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: com.sk89q.worldguard:worldguard-core:7.0.0-SNAPSHOT" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: com.sk89q.intake:intake:4.2-SNAPSHOT" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: com.sk89q:squirrelid:0.2.0" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: org.flywaydb:flyway-core:3.0" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: org.khelekore:prtree:1.5.0" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: com.sk89q:commandbook:2.3" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: org.bstats:bstats-bukkit:1.4" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: com.github.marcelo-mason:PreciousStones:24e3d4bf67b7240ae36b32be10e99d4091938c5c" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: ant-contrib:ant-contrib:1.0b3" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: net.milkbowl.vault:Vault:1.7.1" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: io.papermc:paperlib:1.0.5" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: org.spigotmc:spigot-api:1.16.4-R0.1-SNAPSHOT" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: commons-lang:commons-lang:2.6" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: com.google.guava:guava:21.0" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: com.google.code.gson:gson:2.8.0" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: net.md-5:bungeecord-chat:1.16-R0.3" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: org.yaml:snakeyaml:1.26" level="project" />
<orderEntry type="library" name="Maven: redis.clients:jedis:3.4.0" level="project" />
<orderEntry type="library" name="Maven: org.slf4j:slf4j-api:1.7.30" level="project" />
<orderEntry type="library" name="Maven: org.json:json:20190722" level="project" />
<orderEntry type="library" name="Maven: org.cryptomator:siv-mode:1.4.0" level="project" />
<orderEntry type="library" name="Maven: org.apache.commons:commons-pool2:2.6.2" level="project" />
</component>
</module>
+30 -84
View File
@@ -6,59 +6,14 @@
<groupId>net.limework</groupId>
<artifactId>RediSkript</artifactId>
<version>1.3.2</version>
<packaging>jar</packaging>
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.3</version>
<configuration>
<createDependencyReducedPom>false</createDependencyReducedPom>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.2.0</version>
<configuration>
<outputDirectory>${project.basedir}/compile</outputDirectory>
</configuration>
</plugin>
</plugins>
</build>
<version>1.3.7-SNAPSHOT</version>
<modules>
<module>RediSkript-core</module>
<module>RediSkript-bukkit</module>
</modules>
<packaging>pom</packaging>
<repositories>
<repository>
<id>spigot-repo</id>
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/org/spigotmc/spigot-api/</url>
</repository>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
@@ -67,53 +22,44 @@
<id>commons-pool2</id>
<url>https://mvnrepository.com/artifact/org.apache.commons/commons-pool2</url>
</repository>
<repository>
<id>PaperMC</id>
<url>https://repo.destroystokyo.com/repository/maven-public/</url>
</repository>
<repository>
<id>sk89q</id>
<url>http://maven.sk89q.com/repo</url>
</repository>
</repositories>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>com.github.SkriptLang</groupId>
<artifactId>Skript</artifactId>
<version>2.5.3</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.16.4-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<version>3.4.1</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20190722</version>
<scope>compile</scope>
<version>20220320</version>
</dependency>
<dependency>
<groupId>org.cryptomator</groupId>
<artifactId>siv-mode</artifactId>
<version>1.4.0</version>
<scope>compile</scope>
<version>1.5.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.commons/commons-pool2 -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-pool2</artifactId>
<version>2.6.2</version>
<scope>compile</scope>
<version>2.11.1</version>
</dependency>
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<version>4.4.6</version>
</dependency>
</dependencies>
</project>
</project>
@@ -1,258 +0,0 @@
package net.limework.rediskript.managers;
import ch.njol.skript.registrations.Classes;
import ch.njol.skript.variables.Variables;
import net.limework.rediskript.RediSkript;
import net.limework.rediskript.data.Encryption;
import net.limework.rediskript.events.RedisMessageEvent;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.configuration.Configuration;
import org.bukkit.scheduler.BukkitTask;
import org.cryptomator.siv.UnauthenticCiphertextException;
import org.json.JSONArray;
import org.json.JSONObject;
import redis.clients.jedis.*;
import redis.clients.jedis.exceptions.JedisConnectionException;
import javax.crypto.IllegalBlockSizeException;
import java.nio.charset.StandardCharsets;
import java.util.Base64;
import java.util.List;
import java.util.concurrent.atomic.AtomicBoolean;
public class RedisController extends BinaryJedisPubSub implements Runnable {
//Jedis Pool to be used by every another class.
private final JedisPool jedisPool;
//this seems useless unless tls is OFF!
private final Encryption encryption;
private byte[][] channelsInByte;
private final AtomicBoolean isConnectionBroken;
private final AtomicBoolean isConnecting;
private final RediSkript plugin;
private final boolean debugMode = false; //todo: will be later in the config in future release.
private final BukkitTask ConnectionTask;
public RedisController(RediSkript plugin) {
this.plugin = plugin;
Configuration config = plugin.getConfig();
JedisPoolConfig JConfig = new JedisPoolConfig();
int maxConnections = config.getInt("Redis.MaxConnections");
if (maxConnections < 2) {
maxConnections = 2;
}
JConfig.setMaxTotal(maxConnections);
JConfig.setMaxIdle(maxConnections);
JConfig.setMinIdle(1);
JConfig.setBlockWhenExhausted(true);
this.jedisPool = new JedisPool(JConfig,
config.getString("Redis.Host"),
config.getInt("Redis.Port"),
config.getInt("Redis.TimeOut"),
config.getString("Redis.Password"),
config.getBoolean("Redis.useTLS"));
encryption = new Encryption(config);
setupChannels(config);
isConnectionBroken = new AtomicBoolean(true);
isConnecting = new AtomicBoolean(false);
//Start the main task on async thread
ConnectionTask = plugin.getServer().getScheduler().runTaskTimerAsynchronously(plugin, this, 0, 20 * 5);
}
@Override
public void run() {
if (!isConnectionBroken.get() || isConnecting.get()) {
return;
}
plugin.sendLogs("Connecting to redis......");
isConnecting.set(true);
try (Jedis jedis = jedisPool.getResource()) {
isConnectionBroken.set(false);
plugin.sendLogs("&aConnection to redis has established!");
jedis.subscribe(this, channelsInByte);
} catch (Exception e) {
isConnecting.set(false);
isConnectionBroken.set(true);
plugin.sendErrorLogs("Connection has &lFAILED &cor Unable to connect to redis retrying to make connection...");
if (debugMode) {
e.printStackTrace();
}
}
}
public void shutdown() {
ConnectionTask.cancel();
try {
this.unsubscribe();
} catch (Exception e) {
plugin.sendErrorLogs("Something went wrong during unsubscribing...");
if (debugMode) {
e.printStackTrace();
}
}
jedisPool.close();
}
@Override
public void onMessage(byte[] channel, byte[] message) {
String channelString = new String(channel, StandardCharsets.UTF_8);
String receivedMessage = null;
try {
//if encryption is enabled, decrypt the message, else just convert binary to string
if (this.encryption.isEncryptionEnabled()) {
try {
receivedMessage = encryption.decrypt(message);
} catch (UnauthenticCiphertextException | IllegalBlockSizeException e) {
e.printStackTrace();
}
} else {
//encryption is disabled, so let's just get the string
receivedMessage = new String(message, StandardCharsets.UTF_8);
}
if (receivedMessage != null) {
JSONObject j = new JSONObject(receivedMessage);
if (j.get("Type").equals("Skript")) {
JSONArray messages = j.getJSONArray("Messages");
RedisMessageEvent event;
for (int i = 0; i < messages.length(); i++) {
event = new RedisMessageEvent(channelString, messages.get(i).toString(), j.getLong("Date"));
//if plugin is disabling, don't call events anymore
if (plugin.isEnabled()) {
RedisMessageEvent finalEvent = event;
Bukkit.getScheduler().runTask(plugin, () -> plugin.getServer().getPluginManager().callEvent(finalEvent));
}
}
} else if (j.get("Type").equals("SkriptVariables")) {
//Transfer variables between servers
JSONArray variableNames = j.getJSONArray("Names");
Object inputValue;
String changeValue = null;
JSONArray variableValues = null;
if (!j.isNull("Values")) {
variableValues = j.getJSONArray("Values");
}
for (int i = 0; i < variableNames.length(); i++) {
if (j.isNull("Values")) {
//only check for SET here, because null has to be ignored in all other cases
if (j.getString("Operation").equals("SET")) {
Variables.setVariable(variableNames.get(i).toString(), null, null, false);
}
} else {
if (!variableValues.isNull(i)) {
changeValue = variableValues.get(i).toString();
}
String[] inputs = changeValue.split("\\^", 2);
inputValue = Classes.deserialize(inputs[0], Base64.getDecoder().decode(inputs[1]));
switch (j.getString("Operation")) {
case "ADD":
//I will add this once someone tells me how to remove from Skript variable
//because using SET operation has issues with inconvertible types (Double and Long)
//variable = (Variable) Variables.getVariable(variableNames.get(i).toString(), null, false);
// variable.change(null, (Object[]) inputValue, Changer.ChangeMode.REMOVE);
case "REMOVE":
//I will add this once someone tells me how to remove from Skript variable
//because using SET operation has issues with inconvertible types (Double and Long)
//variable = (Variable) Variables.getVariable(variableNames.get(i).toString(), null, false);
// variable.change(null, (Object[]) inputValue, Changer.ChangeMode.REMOVE);
break;
case "SET":
Variables.setVariable(variableNames.get(i).toString(), inputValue, null, false);
}
}
}
}
}
} catch (Exception e) {
plugin.sendErrorLogs("&cI got a message that was empty from channel " + channelString + " please check your code that you used to send the message. Message content:");
if (debugMode) {
e.printStackTrace();
plugin.sendErrorLogs(receivedMessage);
}
}
}
public void sendMessage(String[] message, String channel) {
JSONObject json = new JSONObject();
json.put("Messages", new JSONArray(message));
json.put("Type", "Skript");
json.put("Date", System.currentTimeMillis()); //for unique string every time & PING calculations
finishSendMessage(json, channel);
}
public void sendVariables(String[] variableNames, String[] variableValues, String channel, String operation) {
JSONObject json = new JSONObject();
json.put("Names", new JSONArray(variableNames));
if (variableValues != null) {
json.put("Values", new JSONArray(variableValues));
}
json.put("Type", "SkriptVariables");
json.put("Date", System.currentTimeMillis()); //for unique string every time & PING calculations
json.put("Operation", operation);
finishSendMessage(json, channel);
}
public void finishSendMessage(JSONObject json, String channel) {
try {
byte[] message;
if (encryption.isEncryptionEnabled()) {
message = encryption.encrypt(json.toString());
} else {
message = json.toString().getBytes(StandardCharsets.UTF_8);
}
//sending a redis message blocks main thread if there's no more connections available
//so to avoid issues, it's best to do it always on separate thread
if (plugin.isEnabled()) {
plugin.getServer().getScheduler().runTaskAsynchronously(plugin, () -> {
try (BinaryJedis j = jedisPool.getResource()) {
j.publish(channel.getBytes(StandardCharsets.UTF_8), message);
} catch (Exception e) {
System.out.println("Error sending redis message!");
if (debugMode) {
e.printStackTrace();
}
}
});
} else {
//execute sending of redis message on the main thread if plugin is disabling
//so it can still process the sending
try (BinaryJedis j = jedisPool.getResource()) {
j.publish(channel.getBytes(StandardCharsets.UTF_8), message);
} catch (Exception e) {
e.printStackTrace();
}
}
} catch (JedisConnectionException exception) {
exception.printStackTrace();
}
}
private void setupChannels(Configuration config) {
List<String> channels = config.getStringList("Channels");
channelsInByte = new byte[channels.size()][1];
for (int x = 0; x < channels.size(); x++) {
channelsInByte[x] = channels.get(x).getBytes(StandardCharsets.UTF_8);
}
}
public Boolean isRedisConnectionOffline() {
return isConnectionBroken.get();
}
}
-29
View File
@@ -1,29 +0,0 @@
Redis:
#a secure password that cannot be cracked, please change it!
#it is also recommended to firewall your redis server with iptables so it can only be accessed by specific IP addresses
Password: "yHy0d2zdBlRmaSPj3CiBwEv5V3XxBTLTrCsGW7ntBnzhfxPxXJS6Q1aTtR6DSfAtCZr2VxWnsungXHTcF94a4bsWEpGAvjL9XMU"
Host: "127.0.0.1"
#must be 2 or higher, if you set to lower, the addon will automatically use 2 as a minimum
MaxConnections: 2
#the default Redis port
Port: 6379
#time out in milliseconds, how long it should take before it decides that it is unable to connect when sending a message
#90000 = 90 seconds
TimeOut: 90000
#also known as SSL, only use this if you're running Redis 6.0.6 or higher, older versions will not work correctly
#it encrypts your traffic and makes data exchange between distant servers completely secure
useTLS: false
#may be useful if you cannot use TLS due to use of older version of Redis
#however this will not encrypt the initial authentication password, only the messages sent
#it uses AES-128 SIV encryption which is secure enough for this
EncryptMessages: true
EncryptionKey: "16CHARACTERS KEY"
MacKey: "16CHARACTERS KEY"
#the channels from which this server can receive messages
#you can always send messages to all channels!
#you can add as many channels as you wish!
Channels:
- "Channel1"
- "Channel2"
- "Channel3"