Compare commits

...

79 Commits

Author SHA1 Message Date
Govindass
358aa66566 Merge branch 'master' of https://github.com/Limework/RediSkript 2020-12-28 10:55:51 +02:00
Govindass
8eb200f614 bump Jedis version from 3.4.0 to 3.4.1 (has important fixes I think) 2020-12-28 10:55:47 +02:00
mohammed jasem alaajel
6ea36c2f37 Update README.md 2020-12-26 16:28:13 +04:00
mohammed jasem alaajel
ce3a7e3dcd added reloadconfig to redisreload 2020-12-26 15:09:25 +04:00
mohammed jasem alaajel
b0d29ea97d added debug check when error sending message 2020-12-26 15:07:12 +04:00
mohammed jasem alaajel
5692b5d9e4 fixed typo in logs sending.. 2020-12-26 14:47:00 +04:00
mohammed jasem alaajel
e5d9d17a23 Merge pull request #11 from Limework/patch-1
new ConnectionController!
2020-12-26 14:04:18 +04:00
mohammed jasem alaajel
a96f9b3201 Update RedisController.java 2020-12-26 14:03:27 +04:00
mohammed jasem alaajel
bfb8ebc862 Fixed bug where connection manager is keep reconnecting when connection reconnect after failure 2020-12-25 23:27:06 +04:00
mohammed jasem alaajel
029222a068 added replacement for system prinltn messages 2020-12-25 21:43:20 +04:00
mohammed jasem alaajel
a2b58798f9 new ConnectionController! 2020-12-23 21:04:23 +04:00
mohammed jasem alaajel
3920b0e844 Update README.md 2020-12-16 14:55:43 +04:00
mohammed jasem alaajel
8d0c324323 Update README.md 2020-12-16 14:55:19 +04:00
Govindass
6b46545813 Merge branch 'master' of https://github.com/Limework/RediSkript 2020-12-15 15:02:30 +02:00
mohammed jasem alaajel
230c2cbb25 cleaned idea / removed typo in groupID 2020-12-14 17:47:17 +04:00
Govindas
cd77d558de Update README.md 2020-12-14 15:21:20 +02:00
mohammed jasem alaajel
7716bc9cf5 noticed something weird in releases section that maven was 1 version late!!!!! 2020-12-14 17:19:21 +04:00
mohammed jasem alaajel
49c12da743 fixed maven not compiling correctly 2020-12-14 16:20:17 +04:00
mohammed jasem alaajel
faf6a7d76d bumped redis version aswell 2020-12-14 15:13:41 +04:00
mohammed jasem alaajel
370af7bc23 bumped skript + spigot api version 2020-12-14 13:55:01 +04:00
mohammed jasem alaajel
61c6aa03dc Merge pull request #7 from Limework/add-license-1
Create LICENSE
2020-12-03 16:56:10 +04:00
mohammed jasem alaajel
b80fcc00dc Create LICENSE 2020-12-03 16:55:42 +04:00
Govindass
c6900e352f Reload redis in a separate thread to not lag the main thread 2020-12-03 13:21:16 +02:00
Govindass
2d5d281fe4 Finally fixed connection leak in /reloadredis !!! 2020-12-03 13:07:27 +02:00
Govindass
5699b9445f Improve code quality 2020-12-03 11:55:45 +02:00
Govindass
053bb04918 Remove unnecessary EventHandler 2020-12-03 11:13:03 +02:00
Govindas
2140cd67ff Update README.md 2020-11-28 10:14:19 +02:00
Govindas
e9ae0bd50b Update README.md 2020-11-28 10:12:11 +02:00
Govindass
6ea120a85a Optimizations 2020-11-28 10:02:14 +02:00
Govindass
01525e4d63 Merge branch 'master' of https://github.com/Limework/RediSkript 2020-11-26 17:05:11 +02:00
Govindass
c63495e201 Some more work on variables (Still very unfinished) 2020-11-26 17:05:07 +02:00
Govindas
265dbfa84d Remove to-do list from readme (refer to issues) 2020-11-25 17:07:30 +02:00
Govindass
6f600cc96e Add cross-server variable editing (I'll make it use {} instead of strings later) 2020-11-25 17:01:11 +02:00
Govindass
1b151dfbbe Allow sending multiple redis messages in one go 2020-11-25 13:53:52 +02:00
Govindass
afdb0c3e59 Fix rare error on disable 2020-11-25 13:18:23 +02:00
Govindass
ca64ec19db Fix wrong prefix coloring in command 2020-11-12 12:36:12 +02:00
Govindass
c0bd63e3cd test 2020-11-03 12:23:00 +02:00
Govindass
705ce16f5d Fix wrong class name & Fully fix sending messages while disabled 2020-11-03 11:29:06 +02:00
Govindass
5a4943bd9d so I found that this threadpool was actually needed, oops
due to it not having threadpool, froze my server at one point
2020-11-02 14:14:38 +02:00
Govindass
211a45ee52 Remove Skript plugin check, as it doesn't load without it anyway 2020-11-02 12:09:18 +02:00
Govindass
1e85072e34 Oops forgot one more console message 2020-10-31 17:12:13 +02:00
Govindass
a60cae72e3 Improve console messages 2020-10-31 16:48:42 +02:00
Govindass
d4461f09c8 some refactoring, make classes more well-sorted 2020-10-29 10:01:36 +02:00
Govindass
dd6b9b6ee6 use HIGHEST priority on disable, so "on script unload" can still work 2020-10-29 09:47:18 +02:00
Govindass
2ee28a5450 Update jarRepositories.xml 2020-10-28 12:20:27 +02:00
Govindass
26b9e0e1d8 Merge branch 'master' of https://github.com/Limework/RediSkript 2020-10-28 12:15:30 +02:00
Govindass
933b85b2d5 try fix maven 2 2020-10-28 12:15:27 +02:00
Govindass
824cf3664c try fix maven 2020-10-28 12:08:44 +02:00
Govindas
d02cac7c5d Update README.md 2020-10-28 11:55:00 +02:00
Govindass
a520ba6496 Update pom.xml 2020-10-28 11:53:44 +02:00
Govindass
4d265cbf61 Improve debug (thanks ShaneBee) 2020-10-27 09:06:36 +02:00
Govindass
7849efd866 Little questionable improvements (shouldn't hurt anything anyway) 2020-10-24 17:59:48 +03:00
Govindass
f80d9b36e7 Make on redis message a synchronous event for thread-safety 2020-10-24 15:19:10 +03:00
Govindass
0c20becfa1 Merge branch 'master' of https://github.com/Limework/RediSkript 2020-10-24 14:33:12 +03:00
Govindass
089fdfd1f3 Update pom.xml 2020-10-24 14:32:55 +03:00
Govindas
c4426a692e Update README.md 2020-10-24 14:32:48 +03:00
Govindass
ed3ea7b2c7 Remove unneeded threadpool (testing has shown for it to be unneeded) 2020-10-24 13:29:49 +03:00
Govindass
2b00f0908e change useSSL to useTLS, because redis itself refers to it as TLS 2020-10-24 12:35:35 +03:00
Govindass
f6c4bbcdce Revert "fixed reload but not tested"
This reverts commit a08ecd93b7.
2020-10-24 12:32:40 +03:00
Govindass
ba48fdc564 Revert "Update RedisManager.java"
This reverts commit 6c5d580b16.
2020-10-24 12:32:36 +03:00
Govindass
ce47af29f4 Revert "Update RedisManager.java"
This reverts commit b93624bc49.
2020-10-24 12:32:24 +03:00
mohammed jasem alaajel
b93624bc49 Update RedisManager.java 2020-10-23 21:01:57 +04:00
mohammed jasem alaajel
6c5d580b16 Update RedisManager.java 2020-10-23 20:45:53 +04:00
mohammed jasem alaajel
a08ecd93b7 fixed reload but not tested 2020-10-23 20:37:43 +04:00
Govindass
c720433c60 Re-word redis reload command information 2020-10-23 17:50:04 +03:00
Govindass
12ce69d68f Fix critical redis server shutdown bug 2020-10-23 17:48:22 +03:00
Govindass
efab085c47 Better 1.8 support & cleanup 2020-10-23 17:21:32 +03:00
Govindass
31db51fce6 Undo synchronous event, broke 1.8 servers completely 2020-10-23 16:55:04 +03:00
Govindass
776ebc9780 add redis message date expression & improve quality of existing expressions & make event guaranteedly synchronous 2020-10-23 16:49:25 +03:00
Govindass
1ef35dfb60 New /reloadredis fully restarts the plugin with reloaded configuration & some code improvements 2020-10-23 14:34:30 +03:00
Govindass
2049616f64 Make json errors easier to debug 2020-10-22 17:44:45 +03:00
Govindass
97aa663bfd Reduce jar size by removing unneeded dependencies 2020-10-22 17:28:00 +03:00
Govindass
4afd5a2dbc Merge branch 'master' of https://github.com/Limework/RediSkript 2020-10-22 14:19:36 +03:00
Govindass
92d89ec76d Remove debug message & Hotfix 2020-10-22 14:19:29 +03:00
Govindas
0ca8712a1a Update README.md 2020-10-22 13:31:38 +03:00
Govindass
216b2635b3 Further fixes & refactoring for release 2020-10-22 13:30:41 +03:00
Govindass
df8608802d Fix encryption disabling & some refactoring 2020-10-22 12:32:08 +03:00
Govindass
157e2b08c7 Remove unneeded code 2020-10-18 17:07:37 +03:00
mohammed jasem alaajel
5f4600546e small fix to make sure the connect was killed 2020-07-30 09:35:50 +04:00
27 changed files with 1028 additions and 641 deletions

2
.gitignore vendored
View File

@@ -1,5 +1,7 @@
target target
out out
.idea .idea
.idea/*
compile compile
*.iml *.iml

201
LICENSE Normal file
View File

@@ -0,0 +1,201 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright [yyyy] [name of copyright owner]
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

View File

@@ -1,2 +1,77 @@
# SkLimework RediSkript allows you to communicate between your servers with use of Redis, it's very fast and easy to use.
Private addon
Skript: https://github.com/SkriptLang/Skript
RediSkript spigot page: https://www.spigotmc.org/resources/rediskript-communicate-between-servers-with-ease.85067/
Jedis: https://github.com/redis/jedis
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:
```
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:
```
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
delete variables "test::*" in channel "global"
set variable "test::%uuid of player%" in channel "playerdata" to tool of player
#then you can in any server that is listening to "playerdata" channel and was online when the above line was executed:
give {test::%uuid of player%} to player
```
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:
```
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"
```

73
RediSkript.iml Normal file
View File

@@ -0,0 +1,73 @@
<?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>

1
install.bat Normal file
View File

@@ -0,0 +1 @@
mvnw install

40
pom.xml
View File

@@ -4,9 +4,9 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<groupId>net.limework.core</groupId> <groupId>net.limework</groupId>
<artifactId>LimeworkSpigotCore</artifactId> <artifactId>RediSkript</artifactId>
<version>1.0.3-fix1-SNAPSHOT</version> <version>1.3.2</version>
<packaging>jar</packaging> <packaging>jar</packaging>
<build> <build>
@@ -57,12 +57,16 @@
<repositories> <repositories>
<repository> <repository>
<id>spigot-repo</id> <id>spigot-repo</id>
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url> <url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/org/spigotmc/spigot-api/</url>
</repository> </repository>
<repository> <repository>
<id>jitpack.io</id> <id>jitpack.io</id>
<url>https://jitpack.io</url> <url>https://jitpack.io</url>
</repository> </repository>
<repository>
<id>commons-pool2</id>
<url>https://mvnrepository.com/artifact/org.apache.commons/commons-pool2</url>
</repository>
<repository> <repository>
<id>PaperMC</id> <id>PaperMC</id>
<url>https://repo.destroystokyo.com/repository/maven-public/</url> <url>https://repo.destroystokyo.com/repository/maven-public/</url>
@@ -75,47 +79,41 @@
<dependencies> <dependencies>
<dependency> <dependency>
<groupId>com.github.skriptlang</groupId> <groupId>com.github.SkriptLang</groupId>
<artifactId>Skript</artifactId> <artifactId>Skript</artifactId>
<version>2.4.1</version> <version>2.5.3</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.spigotmc</groupId> <groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId> <artifactId>spigot-api</artifactId>
<version>1.16.1-R0.1-SNAPSHOT</version> <version>1.16.4-R0.1-SNAPSHOT</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.6</version>
</dependency>
<dependency> <dependency>
<groupId>redis.clients</groupId> <groupId>redis.clients</groupId>
<artifactId>jedis</artifactId> <artifactId>jedis</artifactId>
<version>3.3.0</version> <version>3.4.1</version>
<scope>compile</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.json</groupId> <groupId>org.json</groupId>
<artifactId>json</artifactId> <artifactId>json</artifactId>
<version>20190722</version> <version>20190722</version>
<scope>compile</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.cryptomator</groupId> <groupId>org.cryptomator</groupId>
<artifactId>siv-mode</artifactId> <artifactId>siv-mode</artifactId>
<version>1.4.0</version> <version>1.4.0</version>
</dependency>
<dependency>
<groupId>org.jetbrains</groupId>
<artifactId>annotations</artifactId>
<version>19.0.0</version>
<scope>compile</scope> <scope>compile</scope>
</dependency> </dependency>
<!-- https://mvnrepository.com/artifact/org.apache.commons/commons-pool2 -->
<dependency> <dependency>
<groupId>org.mongodb</groupId> <groupId>org.apache.commons</groupId>
<artifactId>mongodb-driver-sync</artifactId> <artifactId>commons-pool2</artifactId>
<version>4.0.4</version> <version>2.6.2</version>
<scope>compile</scope>
</dependency> </dependency>
</dependencies> </dependencies>
</project> </project>

View File

@@ -0,0 +1,3 @@
Manifest-Version: 1.0
Main-Class: net.limework.rediskript.RediSkript

View File

@@ -1,58 +0,0 @@
package net.limework.core;
import net.limework.core.guis.ControlGui;
import net.limework.core.hooks.SkriptHook;
import net.limework.core.managers.DataSourcesManager;
import net.limework.core.managers.RedisManager;
import org.bukkit.plugin.java.JavaPlugin;
public class LimeworkSpigotCore extends JavaPlugin {
//Redis manager
private RedisManager rm;
//data
private DataSourcesManager dsm;
@Override
public void onEnable() {
saveDefaultConfig();
rm = new RedisManager(this);
getServer().getPluginCommand("reloadredis").setExecutor(rm);
if (getServer().getPluginManager().getPlugin("Skript") != null) {
new SkriptHook(this);
} else {
getLogger().info("Skript wasn't found.");
}
rm.start();
try {
ControlGui controlGui = new ControlGui(this);
this.getServer().getPluginManager().registerEvents(controlGui, this);
this.getCommand("control").setExecutor(controlGui);
} catch (NoSuchFieldError e) {
getLogger().info("SOMETHING WENT WRONG WHEN LOADING control gui.");
e.printStackTrace();
}
dsm = new DataSourcesManager(this);
}
@Override
public void onDisable() {
rm.shutdown();
dsm.shutdown();
}
public RedisManager getRm() {
return rm;
}
public DataSourcesManager getDsm() {
return dsm;
}
}

View File

@@ -1,70 +0,0 @@
package net.limework.core.skript.elements;
import ch.njol.skript.Skript;
import ch.njol.skript.lang.Effect;
import ch.njol.skript.lang.Expression;
import ch.njol.skript.lang.SkriptParser;
import ch.njol.util.Kleenean;
import net.limework.core.LimeworkSpigotCore;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.event.Event;
import org.json.JSONObject;
import redis.clients.jedis.BinaryJedis;
import java.nio.charset.StandardCharsets;
public class EffSendMessage extends Effect {
//"hi"
static {
Skript.registerEffect(EffSendMessage.class, "send redis message to channel %string% with message %string%");
}
private Expression<String> channel;
private Expression<String> message;
@Override
protected void execute(Event event) {
LimeworkSpigotCore plugin = (LimeworkSpigotCore) Bukkit.getPluginManager().getPlugin("LimeworkSpigotCore");
String message = this.message.getSingle(event);
String channel = this.channel.getSingle(event);
if (message == null) {//checks if message equals null if true does not execute.
Bukkit.getLogger().warning(ChatColor.translateAlternateColorCodes('&', "&2[&aGBot&a] &cMessage Was empty Please check your code."));
return;
}
assert plugin != null;
plugin.getRm().getRedisService().execute(() -> {
BinaryJedis j = plugin.getRm().getJedisPool().getResource();
JSONObject json = new JSONObject();
json.put("Message", message);
json.put("Type", "Skript");
json.put("Date", System.nanoTime()); //for unique string every time & PING calculations
byte[] msg;
if (plugin.getRm().getEncryption().isEncryptionEnabled()) {
msg = plugin.getRm().getEncryption().encrypt(json.toString());
} else {
msg = message.getBytes(StandardCharsets.UTF_8);
}
j.publish(channel.getBytes(), msg);
//System.out.println("SkriptSide sent MESSAGE: ["+ message + "] to channel: " + channel + " and json: \n" + json.toString());
j.close();
});
}
@Override
public String toString(Event event, boolean b) {
return null;
}
@SuppressWarnings("unchecked")
@Override
public boolean init(Expression<?>[] expressions, int matchedPattern, Kleenean isDelayed, SkriptParser.ParseResult parser) {
this.channel = (Expression<String>) expressions[0];
this.message = (Expression<String>) expressions[1];
return true;
}
}

View File

@@ -1,69 +0,0 @@
package net.limework.core.abstraction;
import ch.njol.skript.Skript;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import java.util.ArrayList;
import java.util.List;
import static org.bukkit.ChatColor.translateAlternateColorCodes;
public abstract class Gui {
protected Inventory gui;
private int rows;
private boolean loaded = false;
protected String name;
protected void setup(String name, int rows) {
if (loaded) {
return;
}
loaded = true;
this.rows = 9 * rows;
this.name = ChatColor.translateAlternateColorCodes('&', name);
gui = Bukkit.createInventory(null, this.rows, this.name);
}
protected void makeItem(Material material, int howMany, int slot, String name) {
ItemStack item = new ItemStack(material, 1);
ItemMeta item_meta = item.getItemMeta();
item_meta.setDisplayName(translateAlternateColorCodes('&', name));
item.setItemMeta(item_meta);
item.setAmount(howMany);
this.gui.clear(slot);
this.gui.setItem(slot, item);
}
protected void makeItem(Material material, int howMany, int slot, String name, String... Lore) {
ItemStack item = new ItemStack(material, 1);
ItemMeta item_meta = item.getItemMeta();
item_meta.setDisplayName(translateAlternateColorCodes('&', name));
List<String> lore = new ArrayList<>();
for (String s : Lore) {
lore.add(translateAlternateColorCodes('&', s));
}
item_meta.setLore(lore);
item.setItemMeta(item_meta);
item.setAmount(howMany);
this.gui.clear(slot);
this.gui.setItem(slot, item);
}
protected void fillGUI(Material material) {
int slot = -1;
while (slot <= (this.rows - 2)) {
slot++;
makeItem(material, 1, slot , "&1.", "");
}
}
}

View File

@@ -1,90 +0,0 @@
package net.limework.core.guis;
import net.limework.core.LimeworkSpigotCore;
import net.limework.core.abstraction.Gui;
import org.bukkit.*;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.jetbrains.annotations.NotNull;
public class ControlGui extends Gui implements Listener, CommandExecutor {
private LimeworkSpigotCore plugin;
public ControlGui(LimeworkSpigotCore plugin) {
this.plugin = plugin;
setup("&cServer Control", 6);
//fillGUI(Material.LIME_STAINED_GLASS_PANE);
makeItem(Material.CRAFTING_TABLE, 1, 10, "&eCreative mode", "&cClick this for creative mode.");
makeItem(Material.DIAMOND_SWORD, 1, 12, "&eSurvival Mode", "&bClick this for Survival mode.");
makeItem(Material.DIAMOND, 1, 14, "&eSpectator Mode", "&eClick this for Spectator mode.");
makeItem(Material.PUFFERFISH, 1, 16, "&eAdventure Mode", "&aClick this for Adventure mode.");
plugin.getServer().getScheduler().runTaskTimer(plugin, () -> {
makeItem(Material.OAK_SIGN, 1, 37, "&eRam: " + ((Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()) / 1000000) + "MB/" + (Runtime.getRuntime().totalMemory() / 1000000) + "MB");
makeItem(Material.PLAYER_HEAD, 1, 40, "&eOnline Players: " + plugin.getServer().getOnlinePlayers().size() + "/" + plugin.getServer().getMaxPlayers());
}, 0, 20);
makeItem(Material.RED_WOOL, 1, 53, "&c&lShutdown the server");
}
@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command cmd, @NotNull String label, @NotNull String[] args) {
if (sender instanceof Player) {
Player p = ((Player) sender);
p.openInventory(gui);
}
return false;
}
@EventHandler
public void onInventory(InventoryClickEvent e) {
if (e.getInventory() == gui) {
e.setCancelled(true);
Player p = (Player) e.getWhoClicked();
switch (e.getSlot()) {
case 10: {
p.setGameMode(GameMode.CREATIVE);
p.closeInventory();
p.playSound(p.getLocation(), Sound.ENTITY_PLAYER_LEVELUP, 1.0f, 2.0f);
break;
}
case 12: {
p.setGameMode(GameMode.SURVIVAL);
p.closeInventory();
p.playSound(p.getLocation(), Sound.ENTITY_PLAYER_LEVELUP, 1.0f, 2.0f);
break;
}
case 14: {
p.setGameMode(GameMode.SPECTATOR);
p.closeInventory();
p.playSound(p.getLocation(), Sound.ENTITY_PLAYER_LEVELUP, 1.0f, 2.0f);
break;
}
case 16: {
p.setGameMode(GameMode.ADVENTURE);
p.closeInventory();
p.playSound(p.getLocation(), Sound.ENTITY_PLAYER_LEVELUP, 1.0f, 2.0f);
break;
}
case 53: {
p.closeInventory();
plugin.getServer().shutdown();
break;
}
default: {
p.playSound(p.getLocation(), Sound.ENTITY_ENDERMAN_TELEPORT, 1.0f, 0.0f);
break;
}
}
}
}
}

View File

@@ -1,46 +0,0 @@
package net.limework.core.hooks;
import ch.njol.skript.Skript;
import ch.njol.skript.SkriptAddon;
import ch.njol.skript.lang.ExpressionType;
import ch.njol.skript.registrations.EventValues;
import ch.njol.skript.util.Getter;
import net.limework.core.LimeworkSpigotCore;
import net.limework.core.events.RedisMessageEvent;
import net.limework.core.skript.elements.EvtRedis;
import net.limework.core.skript.elements.ExprChannel;
import net.limework.core.skript.elements.ExprMessage;
import java.io.IOException;
public class SkriptHook {
private SkriptAddon addon;
public SkriptHook(LimeworkSpigotCore plugin) {
addon = Skript.registerAddon(plugin);
try {
addon.loadClasses("net.limework.core.skript", "elements");
Skript.registerEvent("redis message", EvtRedis.class, RedisMessageEvent.class, "redis message");
Skript.registerExpression(ExprChannel.class, String.class, ExpressionType.SIMPLE, "redis channel");
EventValues.registerEventValue(RedisMessageEvent.class, String.class, new Getter<String, RedisMessageEvent>() {
@Override
public String get(RedisMessageEvent e) {
return e.getChannelName();
}
}, 0);
Skript.registerExpression(ExprMessage.class, String.class, ExpressionType.SIMPLE, "redis message");
EventValues.registerEventValue(RedisMessageEvent.class, String.class, new Getter<String, RedisMessageEvent>() {
@Override
public String get(RedisMessageEvent e) {
return e.getMessage();
}
}, 0);
} catch (IOException e) {
e.printStackTrace();
}
}
public SkriptAddon getAddon() {
return addon;
}
}

View File

@@ -1,29 +0,0 @@
package net.limework.core.managers;
import com.mongodb.client.MongoClient;
import com.mongodb.client.MongoClients;
import net.limework.core.LimeworkSpigotCore;
import org.bukkit.configuration.Configuration;
public class DataSourcesManager {
private MongoClient mongoClient;
public DataSourcesManager(LimeworkSpigotCore plugin) {
Configuration config = plugin .getConfig();
if (config.getBoolean("Mongodb.enabled")){
mongoClient = MongoClients.create(config.getString("Mongodb.url"));
}
}
public void shutdown(){
mongoClient.close();
}
public MongoClient getMongoClient() {
return mongoClient;
}
}

View File

@@ -1,193 +0,0 @@
package net.limework.core.managers;
import net.limework.Data.Encryption;
import net.limework.core.LimeworkSpigotCore;
import net.limework.core.events.RedisMessageEvent;
import net.md_5.bungee.api.chat.TextComponent;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.Configuration;
import org.bukkit.entity.Player;
import org.cryptomator.siv.UnauthenticCiphertextException;
import org.jetbrains.annotations.NotNull;
import org.json.JSONObject;
import redis.clients.jedis.BinaryJedis;
import redis.clients.jedis.BinaryJedisPubSub;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;
import javax.crypto.IllegalBlockSizeException;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.atomic.AtomicBoolean;
public class RedisManager extends BinaryJedisPubSub implements Runnable, CommandExecutor {
private LimeworkSpigotCore plugin;
private JedisPool jedisPool;
private ExecutorService RedisService;
//sub
private BinaryJedis subscribeJedis;
private List<String> channels;
private AtomicBoolean isShuttingDown = new AtomicBoolean(false);
private AtomicBoolean isRedisOnline = new AtomicBoolean();
private Encryption encryption;
public RedisManager(LimeworkSpigotCore plugin) {
this.plugin = plugin;
Configuration config = this.plugin.getConfig();
JedisPoolConfig JConfig = new JedisPoolConfig();
JConfig.setMaxTotal(config.getInt("Redis.MaxConnections"));
JConfig.setMaxIdle(config.getInt("Redis.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.useSSL"));
RedisService = Executors.newFixedThreadPool(config.getInt("Redis.Threads"));
try {
this.subscribeJedis = this.jedisPool.getResource();
} catch (Exception ignored) {
}
this.channels = config.getStringList("Channels");
encryption = new Encryption(config);
}
public void start() {
this.RedisService.execute(this);
}
@Override
public void run() {
while (!isShuttingDown.get()) {
try {
message("&e[Jedis] &cConnecting to redis...........");
if (!this.subscribeJedis.isConnected()) this.subscribeJedis = this.jedisPool.getResource();
isRedisOnline.set(true);
message("&e[Jedis] &aRedis Connected");
int byteArr2dSize = 1;
byte[][] channelsInByte = new byte[channels.size()][byteArr2dSize];
boolean reInitializeByteArray;
// Loop that reInitialize array IF array size is not enough
do {
reInitializeByteArray = false;
try {
/* Data Initialization for channelsInByte array from List<String> channels */
for (int x = 0; x < channels.size(); x++) {
channelsInByte[x] = channels.get(x).getBytes();
}
} catch (ArrayIndexOutOfBoundsException ex) {
reInitializeByteArray = true;
/* Increase the current 2d array size to increase 1 and reinitialize the array*/
byteArr2dSize += 1;
channelsInByte = new byte[channels.size()][byteArr2dSize];
}
} while (reInitializeByteArray);
this.subscribeJedis.subscribe(this, channelsInByte);
} catch (Exception e) {
message("&e[Jedis] &cConnection to redis has failed! &ereconnecting...");
if (this.subscribeJedis != null) {
this.subscribeJedis.close();
}
isRedisOnline.set(false);
}
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
private void message(String message) {
plugin.getLogger().info(ChatColor.translateAlternateColorCodes('&', message));
}
@Override
public void onMessage(byte[] channel, byte[] message) {
String channelString = new String(channel);
try {
String decrypted = null;
try {
decrypted = encryption.decrypt(message);
} catch (UnauthenticCiphertextException | IllegalBlockSizeException e) {
e.printStackTrace();
}
assert decrypted != null;
JSONObject j = new JSONObject(decrypted);
//System.out.println("Message got from channel: "+channel +" and the Message: " +json.toString());
plugin.getServer().getPluginManager().callEvent(new RedisMessageEvent(channelString, j.getString("Message")));
} catch (Exception e) {
e.printStackTrace();
Bukkit.getLogger().warning(ChatColor.translateAlternateColorCodes('&', "&2[&aGBot&a] &cI Got a Message that Was empty from channel " + channel + " Please check your code that you used to send the message. ^ ignore the error."));
}
}
public void shutdown() {
this.isShuttingDown.set(true);
if (this.subscribeJedis != null) {
this.unsubscribe();
this.subscribeJedis.close();
}
this.RedisService.shutdown();
}
public boolean IsRedisOnline() {
return isRedisOnline.get();
}
public JedisPool getJedisPool() {
return jedisPool;
}
public ExecutorService getRedisService() {
return RedisService;
}
public AtomicBoolean getIsShuttingDown() {
return isShuttingDown;
}
public AtomicBoolean getIsRedisOnline() {
return isRedisOnline;
}
public Encryption getEncryption() {
return encryption;
}
@Override
public boolean onCommand(CommandSender sender, Command cmd, String lable, String[] args) {
if (sender instanceof Player) {
sender.sendMessage(TextComponent.fromLegacyText(ChatColor.translateAlternateColorCodes('&'
, "&c&lYou can not execute this command!!!!!!")));
return true;
}
try {
if (this.subscribeJedis != null) {
this.unsubscribe();
this.subscribeJedis.close();
}
} catch (Exception e) {
e.printStackTrace();
}
start();
return false;
}
}

View File

@@ -0,0 +1,88 @@
package net.limework.rediskript;
import ch.njol.skript.Skript;
import ch.njol.skript.SkriptAddon;
import ch.njol.skript.lang.ExpressionType;
import ch.njol.skript.registrations.EventValues;
import ch.njol.skript.util.Date;
import ch.njol.skript.util.Getter;
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.ChatColor;
import org.bukkit.plugin.java.JavaPlugin;
import java.io.IOException;
public class RediSkript extends JavaPlugin {
private RedisController redisController;
public void reloadRedis() {
reloadConfig();
redisController.shutdown();
redisController = new RedisController(this);
}
public void sendLogs(String message) {
getLogger().info(
ChatColor.translateAlternateColorCodes('&', "&b" + message)
);
}
public void sendErrorLogs(String message) {
getLogger().severe(
ChatColor.translateAlternateColorCodes('&', "&c" + message)
);
}
public void registerSyntax() {
SkriptAddon addon = Skript.registerAddon(this);
try {
addon.loadClasses("net.limework.rediskript.skript", "elements");
Skript.registerEvent("redis message", EvtRedis.class, RedisMessageEvent.class, "redis message");
Skript.registerExpression(ExprVariableInChannel.class, Object.class, ExpressionType.PROPERTY, "variable[s] %strings% in [redis] [channel] %string%");
Skript.registerExpression(ExprChannel.class, String.class, ExpressionType.SIMPLE, "redis channel");
EventValues.registerEventValue(RedisMessageEvent.class, String.class, new Getter<String, RedisMessageEvent>() {
@Override
public String get(RedisMessageEvent e) {
return e.getChannelName();
}
}, 0);
Skript.registerExpression(ExprMessage.class, String.class, ExpressionType.SIMPLE, "redis message");
EventValues.registerEventValue(RedisMessageEvent.class, String.class, new Getter<String, RedisMessageEvent>() {
@Override
public String get(RedisMessageEvent e) {
return e.getMessage();
}
}, 0);
Skript.registerExpression(ExprMessageDate.class, Date.class, ExpressionType.SIMPLE, "redis message date");
EventValues.registerEventValue(RedisMessageEvent.class, Date.class, new Getter<Date, RedisMessageEvent>() {
@Override
public Date get(RedisMessageEvent e) {
return new Date(e.getDate());
}
}, 0);
} catch (IOException e) {
e.printStackTrace();
}
}
@Override
public void onEnable() {
saveDefaultConfig();
redisController = new RedisController(this);
getServer().getPluginCommand("reloadredis").setExecutor(new CommandReloadRedis(this));
registerSyntax();
}
@Override
public void onDisable() {
if (redisController != null) redisController.shutdown();
}
public RedisController getRC() {
return redisController;
}
}

View File

@@ -0,0 +1,39 @@
package net.limework.rediskript.commands;
import net.limework.rediskript.RediSkript;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable;
public class CommandReloadRedis implements CommandExecutor {
private RediSkript plugin;
public CommandReloadRedis(RediSkript plugin) {
this.plugin = plugin;
}
@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
if (sender instanceof Player) {
//not using bungee TextComponent because it is not present in 1.8.8
sender.sendMessage((ChatColor.translateAlternateColorCodes('&'
, "&2[&aRediSkript&2] &cThis command can only be executed in console.")));
return true;
}
//reload redis asynchronously to not lag the main thread (was doing a few seconds lagspike at most)
new BukkitRunnable() {
@Override
public void run() {
plugin.reloadRedis();
}
}.runTaskAsynchronously(plugin);
//not sending to sender, because this command can only be executed via console
Bukkit.getLogger().info(ChatColor.translateAlternateColorCodes('&', "&eReloaded channels, encryption and login details!"));
return false;
}
}

View File

@@ -1,4 +1,4 @@
package net.limework.Data; package net.limework.rediskript.data;
import org.bukkit.configuration.Configuration; import org.bukkit.configuration.Configuration;
import org.cryptomator.siv.SivMode; import org.cryptomator.siv.SivMode;
@@ -26,11 +26,11 @@ public class Encryption {
public boolean isEncryptionEnabled() { return encryptionEnabled; } public boolean isEncryptionEnabled() { return encryptionEnabled; }
public String decrypt(byte[] message) throws UnauthenticCiphertextException, IllegalBlockSizeException { public String decrypt(byte[] message) throws UnauthenticCiphertextException, IllegalBlockSizeException {
return new String(AES_SIV.decrypt(encryptionKey.getBytes(), macKey.getBytes(), message), StandardCharsets.UTF_8); return new String(AES_SIV.decrypt(encryptionKey.getBytes(StandardCharsets.UTF_8), macKey.getBytes(StandardCharsets.UTF_8), message), StandardCharsets.UTF_8);
} }
public byte[] encrypt(String message) { public byte[] encrypt(String message) {
return AES_SIV.encrypt(encryptionKey.getBytes(), macKey.getBytes(), message.getBytes()); return AES_SIV.encrypt(encryptionKey.getBytes(StandardCharsets.UTF_8), macKey.getBytes(StandardCharsets.UTF_8), message.getBytes(StandardCharsets.UTF_8));
} }

View File

@@ -1,6 +1,5 @@
package net.limework.core.events; package net.limework.rediskript.events;
import org.bukkit.Bukkit;
import org.bukkit.event.Event; import org.bukkit.event.Event;
import org.bukkit.event.HandlerList; import org.bukkit.event.HandlerList;
@@ -10,11 +9,13 @@ public class RedisMessageEvent extends Event {
private String channelName; private String channelName;
private String message; private String message;
private long date;
public RedisMessageEvent(String channelName , String message) { public RedisMessageEvent(String channelName , String message, long date) {
super(true); super(false);
this.channelName = channelName; this.channelName = channelName;
this.message = message; this.message = message;
this.date = date;
} }
@@ -35,6 +36,8 @@ public class RedisMessageEvent extends Event {
return channelName; return channelName;
} }
public long getDate() { return date;}
public String getMessage() { public String getMessage() {
return message; return message;
} }

View File

@@ -0,0 +1,258 @@
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();
}
}

View File

@@ -0,0 +1,54 @@
package net.limework.rediskript.skript.elements;
import ch.njol.skript.Skript;
import ch.njol.skript.lang.Effect;
import ch.njol.skript.lang.Expression;
import ch.njol.skript.lang.SkriptParser;
import ch.njol.util.Kleenean;
import net.limework.rediskript.RediSkript;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.event.Event;
public class EffSendMessage extends Effect {
static {
Skript.registerEffect(EffSendMessage.class, "send redis message[s] %strings% to [channel] %string%");
}
private Expression<String> channel;
private Expression<String> message;
@Override
protected void execute(Event event) {
RediSkript plugin = (RediSkript) Bukkit.getPluginManager().getPlugin("RediSkript");
String[] message = this.message.getAll(event);
String channel = this.channel.getSingle(event);
if (message[0] == null) {
Bukkit.getLogger().warning(ChatColor.translateAlternateColorCodes('&', "&2[&aRediSkript&a] &cRedis message was empty. Please check your code."));
return;
}
if (channel == null) {
Bukkit.getLogger().warning(ChatColor.translateAlternateColorCodes('&', "&2[&aRediSkript&a] &cChannel was empty. Please check your code."));
return;
}
plugin.getRC().sendMessage(message, channel);
}
@Override
public String toString(Event event, boolean debug) {
return "send redis message " + message.toString(event, debug) + " to channel " + channel.toString(event, debug);
}
@SuppressWarnings("unchecked")
@Override
public boolean init(final Expression<?>[] expressions, final int matchedPattern, final Kleenean isDelayed, final SkriptParser.ParseResult parser) {
this.message = (Expression<String>) expressions[0];
this.channel = (Expression<String>) expressions[1];
return true;
}
}

View File

@@ -1,27 +1,24 @@
package net.limework.core.skript.elements; package net.limework.rediskript.skript.elements;
;
import ch.njol.skript.lang.Literal; import ch.njol.skript.lang.Literal;
import ch.njol.skript.lang.SkriptEvent; import ch.njol.skript.lang.SkriptEvent;
import ch.njol.skript.lang.SkriptParser; import ch.njol.skript.lang.SkriptParser;
import net.limework.rediskript.events.RedisMessageEvent;
import org.bukkit.event.Event; import org.bukkit.event.Event;
public class EvtRedis extends SkriptEvent { public class EvtRedis extends SkriptEvent {
@Override @Override
public boolean init(Literal<?>[] literals, int i, SkriptParser.ParseResult parseResult) { public boolean init(final Literal<?>[] literals, final int i, final SkriptParser.ParseResult parseResult) {
return true; return true;
} }
@Override @Override
public boolean check(Event event) { public boolean check(Event event) {
return true; return (event instanceof RedisMessageEvent);
} }
@Override @Override
public String toString(Event event, boolean b) { public String toString(Event event, boolean debug) {
return "redis message"; return "redis message";
} }
} }

View File

@@ -1,11 +1,14 @@
package net.limework.core.skript.elements; package net.limework.rediskript.skript.elements;
import ch.njol.skript.ScriptLoader;
import ch.njol.skript.Skript;
import ch.njol.skript.lang.Expression; import ch.njol.skript.lang.Expression;
import ch.njol.skript.lang.SkriptParser; import ch.njol.skript.lang.SkriptParser;
import ch.njol.skript.lang.util.SimpleExpression; import ch.njol.skript.lang.util.SimpleExpression;
import ch.njol.skript.log.ErrorQuality;
import ch.njol.util.Kleenean; import ch.njol.util.Kleenean;
import net.limework.core.events.RedisMessageEvent; import net.limework.rediskript.events.RedisMessageEvent;
import org.bukkit.event.Event; import org.bukkit.event.Event;
public class ExprChannel extends SimpleExpression<String> { public class ExprChannel extends SimpleExpression<String> {
@@ -27,7 +30,11 @@ public class ExprChannel extends SimpleExpression<String> {
} }
@Override @Override
public boolean init(Expression<?>[] expressions, int i, Kleenean kleenean, SkriptParser.ParseResult parseResult) { public boolean init(final Expression<?>[] expressions, final int matchedPattern, final Kleenean isDelayed, final SkriptParser.ParseResult parseResult) {
if (!ScriptLoader.isCurrentEvent(RedisMessageEvent.class)) {
Skript.error("Cannot use 'redis channel' outside of a redis message event", ErrorQuality.SEMANTIC_ERROR);
return false;
}
return true; return true;
} }

View File

@@ -1,11 +1,14 @@
package net.limework.core.skript.elements; package net.limework.rediskript.skript.elements;
import ch.njol.skript.ScriptLoader;
import ch.njol.skript.Skript;
import ch.njol.skript.lang.Expression; import ch.njol.skript.lang.Expression;
import ch.njol.skript.lang.SkriptParser; import ch.njol.skript.lang.SkriptParser;
import ch.njol.skript.lang.util.SimpleExpression; import ch.njol.skript.lang.util.SimpleExpression;
import ch.njol.skript.log.ErrorQuality;
import ch.njol.util.Kleenean; import ch.njol.util.Kleenean;
import net.limework.core.events.RedisMessageEvent; import net.limework.rediskript.events.RedisMessageEvent;
import org.bukkit.event.Event; import org.bukkit.event.Event;
public class ExprMessage extends SimpleExpression<String> { public class ExprMessage extends SimpleExpression<String> {
@@ -22,12 +25,16 @@ public class ExprMessage extends SimpleExpression<String> {
} }
@Override @Override
public String toString(Event event, boolean b) { public String toString(Event event, boolean debug) {
return "redis message"; return "redis message";
} }
@Override @Override
public boolean init(Expression<?>[] expressions, int i, Kleenean kleenean, SkriptParser.ParseResult parseResult) { public boolean init(final Expression<?>[] expressions, final int matchedPattern, final Kleenean isDelayed, final SkriptParser.ParseResult parseResult) {
if (!ScriptLoader.isCurrentEvent(RedisMessageEvent.class)) {
Skript.error("Cannot use 'redis message' outside of a redis message event", ErrorQuality.SEMANTIC_ERROR);
return false;
}
return true; return true;
} }

View File

@@ -0,0 +1,49 @@
package net.limework.rediskript.skript.elements;
import ch.njol.skript.ScriptLoader;
import ch.njol.skript.Skript;
import ch.njol.skript.lang.Expression;
import ch.njol.skript.lang.SkriptParser;
import ch.njol.skript.lang.util.SimpleExpression;
import ch.njol.skript.log.ErrorQuality;
import ch.njol.skript.util.Date;
import ch.njol.util.Kleenean;
import net.limework.rediskript.events.RedisMessageEvent;
import org.bukkit.event.Event;
public class ExprMessageDate extends SimpleExpression<Date> {
@Override
public boolean isSingle() {
return true;
}
@Override
public Class<? extends Date> getReturnType() {
return Date.class;
}
@Override
public String toString(Event event, boolean b) {
return "redis message date";
}
@Override
public boolean init(final Expression<?>[] expressions, final int matchedPattern, final Kleenean isDelayed, final SkriptParser.ParseResult parseResult) {
if (!ScriptLoader.isCurrentEvent(RedisMessageEvent.class)) {
Skript.error("Cannot use 'redis message date' outside of a redis message event", ErrorQuality.SEMANTIC_ERROR);
return false;
}
return true;
}
@Override
protected Date[] get(Event e) {
if (e instanceof RedisMessageEvent){
long date = ((RedisMessageEvent) e).getDate();
return new Date[]{new Date(date)};
}
return null;
}
}

View File

@@ -0,0 +1,84 @@
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;
import ch.njol.util.coll.CollectionUtils;
import net.limework.rediskript.RediSkript;
import org.bukkit.Bukkit;
import org.bukkit.event.Event;
import java.util.Base64;
public class ExprVariableInChannel extends SimpleExpression<Object> {
private Expression<String> name;
private Expression<String> channel;
@Override
public boolean init(Expression<?>[] expressions, int matchedPattern, Kleenean isDelayed, SkriptParser.ParseResult parser) {
name = (Expression<String>) expressions[0];
channel = (Expression<String>) expressions[1];
return true;
}
@Override
protected Object[] get(Event event) {
return null;
}
@Override
public boolean isSingle() {
return true;
}
@Override
public Class<? extends Object> getReturnType() {
return Object.class;
}
@Override
public String toString(Event event, boolean debug) {
return "variable " + name.toString(event,debug) + " in redis channel " + channel.toString(event, debug);
}
@Override
public void change(Event e, Object[] changer, Changer.ChangeMode mode) {
RediSkript plugin = (RediSkript) Bukkit.getPluginManager().getPlugin("RediSkript");
switch (mode) {
case ADD:
case SET:
case REMOVE:
SerializedVariable.Value serialized;
String encoded;
String[] values = new String[changer.length+1];
for( int i = 0; i < changer.length; i++) {
if (changer[i] != null) {
serialized = Classes.serialize(changer[i]);
encoded = Base64.getEncoder().encodeToString(serialized.data);
encoded = serialized.type + "^" + encoded;
values[i] = encoded;
}
}
String operation = mode.toString();
plugin.getRC().sendVariables(name.getAll(e), values, channel.getSingle(e), operation);
break;
case DELETE:
plugin.getRC().sendVariables(name.getAll(e), null, channel.getSingle(e), "SET");
break;
}
}
@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)
return CollectionUtils.array(Object.class);
return null;
}
}

View File

@@ -1,21 +1,29 @@
Redis: Redis:
Password: "yHy0d2zdBlRmaSPj3CiBwEv5V3XxBTLTrCsGW7ntBnzhfxPxXJS6Q1aTtR6DSfAtCZr2VxWnsungXHTcF94a4bsWEpGAvjL6XMU" #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" Host: "127.0.0.1"
MaxConnections: 20 #must be 2 or higher, if you set to lower, the addon will automatically use 2 as a minimum
Threads: 10 MaxConnections: 2
#the default Redis port
Port: 6379 Port: 6379
TimeOut: 40000 #time out in milliseconds, how long it should take before it decides that it is unable to connect when sending a message
useSSL: false #90000 = 90 seconds
#useful if SSL is disabled TimeOut: 90000
EncryptMessages: false #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" EncryptionKey: "16CHARACTERS KEY"
MacKey: "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: Channels:
- "Channel1" - "Channel1"
- "Channel2" - "Channel2"
- "Channel3" - "Channel3"
Mongodb:
enabled: false
url: ""

View File

@@ -1,14 +1,9 @@
main: net.limework.core.LimeworkSpigotCore main: net.limework.rediskript.RediSkript
name: LimeworkSpigotCore name: ${project.name}
version: ${project.version} version: ${project.version}
author: limework.net authors: [Govindas, ham1255, DaemonicKing, limework.net]
api-version: 1.13 api-version: 1.13
softdepend: depend: [Skript]
- Skript
commands: commands:
control:
description: "server control"
permission: "admin.use"
reloadredis: reloadredis:
description: "server control" description: "Reload redis configuration & restart the connection."
permission: "admin.use"