Compare commits
No commits in common. "master" and "1.2.1" have entirely different histories.
32
.github/workflows/maven.yml
vendored
32
.github/workflows/maven.yml
vendored
@ -1,32 +0,0 @@
|
||||
# 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
|
3
.gitignore
vendored
3
.gitignore
vendored
@ -1,8 +1,5 @@
|
||||
target
|
||||
out
|
||||
.idea
|
||||
.idea/*
|
||||
compile
|
||||
*.iml
|
||||
|
||||
*.iml
|
||||
|
201
LICENSE
201
LICENSE
@ -1,201 +0,0 @@
|
||||
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.
|
80
README.md
80
README.md
@ -1,23 +1,14 @@
|
||||
**To-do List**
|
||||
1. Fix memory leak of /reloadredis (Not yet known how to fix it, it can be easily noticed by changing IP addresses and using NetworkInterceptor plugin, it'll show connections still being done to old IP address, aswell as the new one, even if it doesn't use old IP address for anything.
|
||||
|
||||
|
||||
## 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/s
|
||||
|
||||
Minecraft server version supported: **1.8.8+** (On 1.8, may need to use a fork of Skript)
|
||||
RediSkript allows you to communicate between your servers with use of Redis, it's very fast and easy to use.
|
||||
|
||||
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.
|
||||
|
||||
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
|
||||
It is originally developed by the team of Govindas Limework developers and is now maintained only by Govindas.
|
||||
Example:
|
||||
```
|
||||
on redis message:
|
||||
if redis channel is "world":
|
||||
@ -29,75 +20,38 @@ command /sendredis <text> <text>:
|
||||
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
|
||||
|
||||
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"
|
||||
and that's all there is to this addon! 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.
|
||||
|
||||
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%
|
||||
```
|
||||
|
||||
### Configuration
|
||||
plugins/RediSkript/config.yml
|
||||
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"
|
||||
#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
|
||||
#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 secure
|
||||
#it encrypts your traffic and makes data exchange between distant servers completely 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)
|
||||
#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
|
||||
#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 and MacKey must be different
|
||||
EncryptionKey: "32CHARACTERS KEY"
|
||||
MacKey: "32CHARACTERS KEY"
|
||||
|
||||
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!
|
||||
|
||||
#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"
|
||||
- "Channel1"
|
||||
- "Channel2"
|
||||
- "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)
|
||||
|
@ -1,83 +0,0 @@
|
||||
<?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>
|
@ -1,3 +0,0 @@
|
||||
Manifest-Version: 1.0
|
||||
Main-Class: net.limework.rediskript.RediSkript
|
||||
|
@ -1,101 +0,0 @@
|
||||
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.Bukkit;
|
||||
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();
|
||||
}
|
||||
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");
|
||||
}
|
||||
|
||||
}
|
@ -1,386 +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.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;
|
||||
}
|
||||
//
|
||||
}
|
@ -1,54 +0,0 @@
|
||||
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.getAPI();
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
@ -1,81 +0,0 @@
|
||||
package net.limework.rediskript.skript.elements;
|
||||
|
||||
import ch.njol.skript.classes.Changer;
|
||||
import ch.njol.skript.lang.Expression;
|
||||
import ch.njol.skript.lang.SkriptParser;
|
||||
import ch.njol.skript.lang.util.SimpleExpression;
|
||||
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.getPlugin(RediSkript.class);
|
||||
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 || mode == Changer.ChangeMode.ADD || mode == Changer.ChangeMode.REMOVE)
|
||||
return CollectionUtils.array(Object.class);
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
@ -1,44 +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"
|
||||
#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,14 +0,0 @@
|
||||
<?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>
|
@ -1,11 +0,0 @@
|
||||
package net.limework.rediskript;
|
||||
|
||||
|
||||
import redis.clients.jedis.BinaryJedisPubSub;
|
||||
|
||||
public abstract class Subscriber extends BinaryJedisPubSub implements Runnable {
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
@ -1 +0,0 @@
|
||||
mvnw install
|
95
pom.xml
95
pom.xml
@ -4,27 +4,18 @@
|
||||
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>
|
||||
|
||||
<groupId>net.limework</groupId>
|
||||
<groupId>net.limework.core</groupId>
|
||||
<artifactId>RediSkript</artifactId>
|
||||
<version>1.3.7-SNAPSHOT</version>
|
||||
<modules>
|
||||
<module>RediSkript-core</module>
|
||||
<module>RediSkript-bukkit</module>
|
||||
</modules>
|
||||
<packaging>pom</packaging>
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>jitpack.io</id>
|
||||
<url>https://jitpack.io</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>commons-pool2</id>
|
||||
<url>https://mvnrepository.com/artifact/org.apache.commons/commons-pool2</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
<version>1.2.0</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>
|
||||
@ -36,30 +27,82 @@
|
||||
<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>
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>spigot-repo</id>
|
||||
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>jitpack.io</id>
|
||||
<url>https://jitpack.io</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>commons-pool2</id>
|
||||
<url>https://mvnrepository.com/artifact/org.apache.commons/commons-pool2</url>
|
||||
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.github.skriptlang</groupId>
|
||||
<artifactId>Skript</artifactId>
|
||||
<version>2.4.1</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.spigotmc</groupId>
|
||||
<artifactId>spigot-api</artifactId>
|
||||
<version>1.16.2-R0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>redis.clients</groupId>
|
||||
<artifactId>jedis</artifactId>
|
||||
<version>3.3.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.json</groupId>
|
||||
<artifactId>json</artifactId>
|
||||
<version>20220320</version>
|
||||
<version>20190722</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.cryptomator</groupId>
|
||||
<artifactId>siv-mode</artifactId>
|
||||
<version>1.5.0</version>
|
||||
<version>1.4.0</version>
|
||||
</dependency>
|
||||
<!-- https://mvnrepository.com/artifact/org.apache.commons/commons-pool2 -->
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-pool2</artifactId>
|
||||
<version>2.11.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>redis.clients</groupId>
|
||||
<artifactId>jedis</artifactId>
|
||||
<version>4.4.6</version>
|
||||
<version>2.6.2</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
3
src/main/java/META-INF/MANIFEST.MF
Normal file
3
src/main/java/META-INF/MANIFEST.MF
Normal file
@ -0,0 +1,3 @@
|
||||
Manifest-Version: 1.0
|
||||
Main-Class: net.limework.core.RediSkript
|
||||
|
45
src/main/java/net/limework/core/RediSkript.java
Normal file
45
src/main/java/net/limework/core/RediSkript.java
Normal file
@ -0,0 +1,45 @@
|
||||
package net.limework.core;
|
||||
import net.limework.core.commands.ReloadRedis;
|
||||
import net.limework.core.hooks.SkriptHook;
|
||||
import net.limework.core.managers.RedisManager;
|
||||
import org.bukkit.command.PluginCommand;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
public class RediSkript extends JavaPlugin {
|
||||
|
||||
//Redis manager
|
||||
private RedisManager rm;
|
||||
|
||||
public void startRedis(boolean reload) {
|
||||
if (reload) { reloadConfig(); }
|
||||
rm = new RedisManager(this);
|
||||
rm.start();
|
||||
}
|
||||
@Override
|
||||
public void onEnable() {
|
||||
saveDefaultConfig();
|
||||
if (getServer().getPluginManager().getPlugin("Skript") != null) {
|
||||
startRedis(false);
|
||||
|
||||
PluginCommand command = getServer().getPluginCommand("reloadredis");
|
||||
assert command != null;
|
||||
command.setExecutor(new ReloadRedis(this));
|
||||
|
||||
new SkriptHook(this);
|
||||
} else {
|
||||
getLogger().info("Skript wasn't found.");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
if (rm != null) {
|
||||
rm.shutdown();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public RedisManager getRm() {
|
||||
return rm;
|
||||
}
|
||||
}
|
@ -1,17 +1,16 @@
|
||||
package net.limework.rediskript.commands;
|
||||
package net.limework.core.commands;
|
||||
|
||||
import net.limework.rediskript.RediSkript;
|
||||
import net.limework.core.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 {
|
||||
public class ReloadRedis implements CommandExecutor {
|
||||
private RediSkript plugin;
|
||||
public CommandReloadRedis(RediSkript plugin) {
|
||||
public ReloadRedis(RediSkript plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
@Override
|
||||
@ -19,20 +18,12 @@ public class CommandReloadRedis implements CommandExecutor {
|
||||
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.")));
|
||||
, "&2[&aRediSkript&a] &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);
|
||||
|
||||
plugin.getRm().reload();
|
||||
//not sending to sender, because this command can only be executed via console
|
||||
Bukkit.getLogger().info(ChatColor.translateAlternateColorCodes('&', "&eReloaded channels, encryption and login details!"));
|
||||
Bukkit.getLogger().info(ChatColor.translateAlternateColorCodes('&', "&2[&aRediSkript&a] &eReloaded via command! Note this command is not stable, it should only be used in urgent cases where you absolutely need to change config details without restarting the server."));
|
||||
|
||||
return false;
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package net.limework.rediskript.events;
|
||||
package net.limework.core.events;
|
||||
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
51
src/main/java/net/limework/core/hooks/SkriptHook.java
Normal file
51
src/main/java/net/limework/core/hooks/SkriptHook.java
Normal file
@ -0,0 +1,51 @@
|
||||
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.Date;
|
||||
import ch.njol.skript.util.Getter;
|
||||
import net.limework.core.RediSkript;
|
||||
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 net.limework.core.skript.elements.ExprMessageDate;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class SkriptHook {
|
||||
|
||||
private SkriptAddon addon;
|
||||
public SkriptHook(RediSkript 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);
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
166
src/main/java/net/limework/core/managers/RedisManager.java
Normal file
166
src/main/java/net/limework/core/managers/RedisManager.java
Normal file
@ -0,0 +1,166 @@
|
||||
package net.limework.core.managers;
|
||||
|
||||
import net.limework.core.RediSkript;
|
||||
import net.limework.core.events.RedisMessageEvent;
|
||||
import net.limework.data.Encryption;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.configuration.Configuration;
|
||||
import org.cryptomator.siv.UnauthenticCiphertextException;
|
||||
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.nio.charset.StandardCharsets;
|
||||
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 {
|
||||
|
||||
private RediSkript plugin;
|
||||
|
||||
private JedisPool jedisPool;
|
||||
private ExecutorService RedisService;
|
||||
|
||||
|
||||
//sub
|
||||
private BinaryJedis subscribeJedis;
|
||||
private List<String> channels;
|
||||
private AtomicBoolean isShuttingDown = new AtomicBoolean(false);
|
||||
private Encryption encryption;
|
||||
|
||||
|
||||
public RedisManager(RediSkript plugin) {
|
||||
this.plugin = plugin;
|
||||
Configuration config = this.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"));
|
||||
RedisService = Executors.newSingleThreadExecutor();
|
||||
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 {
|
||||
plugin.getLogger().info(ChatColor.translateAlternateColorCodes('&', "&2[&aRediSkript&a] &cConnecting to redis..."));
|
||||
if (!this.subscribeJedis.isConnected()) this.subscribeJedis = this.jedisPool.getResource();
|
||||
plugin.getLogger().info(ChatColor.translateAlternateColorCodes('&', "&2[&aRediSkript&a] &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(StandardCharsets.UTF_8);
|
||||
}
|
||||
} 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) {
|
||||
plugin.getLogger().warning(ChatColor.translateAlternateColorCodes('&', "&2[&aRediSkript&a] &cConnection to redis has failed! &ereconnecting..."));
|
||||
if (this.subscribeJedis != null) {
|
||||
this.subscribeJedis.close();
|
||||
}
|
||||
}
|
||||
try {
|
||||
Thread.sleep(1000);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@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);
|
||||
//System.out.println("Message got from channel: "+channel +" and the Message: " +json.toString());
|
||||
RedisMessageEvent event = new RedisMessageEvent(channelString, j.getString("Message"), j.getLong("Date"));
|
||||
Bukkit.getScheduler().runTask(plugin, () -> plugin.getServer().getPluginManager().callEvent(event));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
Bukkit.getLogger().warning(ChatColor.translateAlternateColorCodes('&', "&2[&aRediSkript&a] &cI got a message that was empty from channel " + channelString + " please check your code that you used to send the message. Message content:"));
|
||||
Bukkit.getLogger().warning(receivedMessage);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void shutdown() {
|
||||
this.isShuttingDown.set(true);
|
||||
if (this.subscribeJedis != null) {
|
||||
this.unsubscribe();
|
||||
this.subscribeJedis.close();
|
||||
this.subscribeJedis.getClient().close();
|
||||
this.jedisPool.getResource().close();
|
||||
}
|
||||
this.RedisService.shutdown();
|
||||
|
||||
}
|
||||
public void reload() {
|
||||
this.shutdown();
|
||||
plugin.startRedis(true);
|
||||
}
|
||||
|
||||
public JedisPool getJedisPool() {
|
||||
return jedisPool;
|
||||
}
|
||||
|
||||
public Encryption getEncryption() {
|
||||
return encryption;
|
||||
}
|
||||
}
|
@ -0,0 +1,82 @@
|
||||
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.RediSkript;
|
||||
import net.limework.core.managers.RedisManager;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.event.Event;
|
||||
import org.json.JSONObject;
|
||||
import redis.clients.jedis.BinaryJedis;
|
||||
import redis.clients.jedis.exceptions.JedisConnectionException;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
public class EffSendMessage extends Effect {
|
||||
static {
|
||||
Skript.registerEffect(EffSendMessage.class, "send redis message %string% 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.getSingle(event);
|
||||
String channel = this.channel.getSingle(event);
|
||||
|
||||
if (message == 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;
|
||||
}
|
||||
assert plugin != null;
|
||||
JSONObject json = new JSONObject();
|
||||
json.put("Message", message);
|
||||
json.put("Type", "Skript");
|
||||
json.put("Date", System.currentTimeMillis()); //for unique string every time & PING calculations
|
||||
byte[] msg;
|
||||
RedisManager manager = plugin.getRm();
|
||||
|
||||
if (manager.getEncryption().isEncryptionEnabled()) {
|
||||
msg = manager.getEncryption().encrypt(json.toString());
|
||||
} else {
|
||||
msg = json.toString().getBytes(StandardCharsets.UTF_8);
|
||||
}
|
||||
try {
|
||||
BinaryJedis j = manager.getJedisPool().getResource();
|
||||
|
||||
j.publish(channel.getBytes(StandardCharsets.UTF_8), msg);
|
||||
j.close();
|
||||
} catch (JedisConnectionException exception) {
|
||||
exception.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString(Event event, boolean debug) {
|
||||
return "send redis message " + message.getSingle(event) + " to channel " + channel.getSingle(event);
|
||||
}
|
||||
|
||||
@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;
|
||||
}
|
||||
|
||||
}
|
@ -1,20 +1,23 @@
|
||||
package net.limework.rediskript.skript.elements;
|
||||
package net.limework.core.skript.elements;
|
||||
import ch.njol.skript.lang.Literal;
|
||||
import ch.njol.skript.lang.SkriptEvent;
|
||||
import ch.njol.skript.lang.SkriptParser;
|
||||
import net.limework.rediskript.events.RedisMessageEvent;
|
||||
import net.limework.core.events.RedisMessageEvent;
|
||||
import org.bukkit.event.Event;
|
||||
|
||||
public class EvtRedis extends SkriptEvent {
|
||||
|
||||
@Override
|
||||
public boolean init(final Literal<?>[] literals, final int i, final SkriptParser.ParseResult parseResult) {
|
||||
public boolean init(Literal<?>[] literals, int i, SkriptParser.ParseResult parseResult) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean check(Event event) {
|
||||
return (event instanceof RedisMessageEvent);
|
||||
if (!(event instanceof RedisMessageEvent)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
@ -1,4 +1,4 @@
|
||||
package net.limework.rediskript.skript.elements;
|
||||
package net.limework.core.skript.elements;
|
||||
|
||||
|
||||
import ch.njol.skript.ScriptLoader;
|
||||
@ -8,7 +8,7 @@ import ch.njol.skript.lang.SkriptParser;
|
||||
import ch.njol.skript.lang.util.SimpleExpression;
|
||||
import ch.njol.skript.log.ErrorQuality;
|
||||
import ch.njol.util.Kleenean;
|
||||
import net.limework.rediskript.events.RedisMessageEvent;
|
||||
import net.limework.core.events.RedisMessageEvent;
|
||||
import org.bukkit.event.Event;
|
||||
|
||||
public class ExprChannel extends SimpleExpression<String> {
|
||||
@ -25,7 +25,9 @@ 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,4 +1,4 @@
|
||||
package net.limework.rediskript.skript.elements;
|
||||
package net.limework.core.skript.elements;
|
||||
|
||||
|
||||
import ch.njol.skript.ScriptLoader;
|
||||
@ -8,7 +8,7 @@ import ch.njol.skript.lang.SkriptParser;
|
||||
import ch.njol.skript.lang.util.SimpleExpression;
|
||||
import ch.njol.skript.log.ErrorQuality;
|
||||
import ch.njol.util.Kleenean;
|
||||
import net.limework.rediskript.events.RedisMessageEvent;
|
||||
import net.limework.core.events.RedisMessageEvent;
|
||||
import org.bukkit.event.Event;
|
||||
|
||||
public class ExprMessage extends SimpleExpression<String> {
|
@ -1,4 +1,4 @@
|
||||
package net.limework.rediskript.skript.elements;
|
||||
package net.limework.core.skript.elements;
|
||||
|
||||
|
||||
import ch.njol.skript.ScriptLoader;
|
||||
@ -9,7 +9,7 @@ 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 net.limework.core.events.RedisMessageEvent;
|
||||
import org.bukkit.event.Event;
|
||||
|
||||
public class ExprMessageDate extends SimpleExpression<Date> {
|
@ -1,5 +1,6 @@
|
||||
package net.limework.rediskript.data;
|
||||
package net.limework.data;
|
||||
|
||||
import org.bukkit.configuration.Configuration;
|
||||
import org.cryptomator.siv.SivMode;
|
||||
import org.cryptomator.siv.UnauthenticCiphertextException;
|
||||
|
||||
@ -8,17 +9,17 @@ import java.nio.charset.StandardCharsets;
|
||||
|
||||
public class Encryption {
|
||||
|
||||
private final boolean encryptionEnabled;
|
||||
private boolean encryptionEnabled;
|
||||
private String encryptionKey;
|
||||
private String macKey;
|
||||
private final SivMode AES_SIV = new SivMode();
|
||||
|
||||
public Encryption(boolean encryptionEnabled, String encryptionKey, String macKey){
|
||||
this.encryptionEnabled = encryptionEnabled;
|
||||
if (this.encryptionEnabled) {
|
||||
// AES encryption
|
||||
this.encryptionKey = encryptionKey;
|
||||
this.macKey = macKey;
|
||||
public Encryption(Configuration config){
|
||||
encryptionEnabled = config.getBoolean("Redis.EncryptMessages");
|
||||
if (encryptionEnabled) {
|
||||
// AES-128 encryption
|
||||
encryptionKey = config.getString("Redis.EncryptionKey");
|
||||
macKey = config.getString("Redis.MacKey");
|
||||
}
|
||||
}
|
||||
|
29
src/main/resources/config.yml
Normal file
29
src/main/resources/config.yml
Normal file
@ -0,0 +1,29 @@
|
||||
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"
|
@ -1,10 +1,10 @@
|
||||
main: net.limework.rediskript.RediSkript
|
||||
main: net.limework.core.RediSkript
|
||||
name: RediSkript
|
||||
version: ${project.version}
|
||||
authors: [Govindas, ham1255, DaemonicKing, limework.net]
|
||||
authors: [Govindas, ham1255, DaemonicKing]
|
||||
api-version: 1.13
|
||||
depend: [Skript]
|
||||
depend:
|
||||
- Skript
|
||||
commands:
|
||||
reloadredis:
|
||||
description: "Reload redis configuration & restart the connection."
|
||||
permission: reload.redis
|
Loading…
Reference in New Issue
Block a user