Skip to content

Commit

Permalink
Merge pull request #12 from ZorgBtw/dev
Browse files Browse the repository at this point in the history
🔥 Prepare for 1.1.0
  • Loading branch information
ZorgBtw authored Jul 22, 2021
2 parents 01c064c + 7459397 commit ecb1b79
Show file tree
Hide file tree
Showing 71 changed files with 3,023 additions and 979 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ jobs:
java-package: jdk
- name: Grant execute permission for gradlew
run: chmod +x gradlew
- name: Build with Gradle
run: ./gradlew clean build
- name: Build with Gradle, using shadowJar
run: ./gradlew clean shadowJar
- name: Upload artifact
uses: actions/upload-artifact@v2
with:
Expand Down
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ on server start:
set address of connection to "127.0.0.1" # Use this IP if the Bungeecord is on the same machine
set port of connection to 20000 # This port as to be opened if the specified client is not hosted on the same machine as the server
set password of connection to "Strong password" # Complete your password here, this has to be the same as the one in the Bungeecord config
set name of connection to "hub" # Name has to be unique, if the same name is already connected, the connection will end
start new connection with last created connection # Sending connection request to the server
wait 30 seconds # Waiting 30 seconds between 2 connection tries, it's recommended to not decrease this value
```
Expand Down
27 changes: 16 additions & 11 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,33 +1,34 @@
import org.apache.tools.ant.filters.ReplaceTokens

plugins {
id 'com.github.johnrengelman.shadow' version '7.0.0'
id 'java'
}

group 'fr.zorg'
version '1.0.3'
version '1.1.0'

def mcVersion = '1.16'
def subVersion = '.5'
def mcVersion = '1.17'
def subVersion = ''

repositories {
mavenCentral()
jcenter()
maven { url = 'https://jitpack.io' }
maven { url = 'https://hub.spigotmc.org/nexus/content/repositories/snapshots/' }
maven { url = 'https://oss.sonatype.org/content/repositories/snapshots' }
maven { url = 'https://jitpack.io' }
maven { url = 'https://repo.destroystokyo.com/repository/maven-public/' }
}

dependencies {
compileOnly group: 'org.spigotmc', name: 'spigot-api', version: mcVersion + subVersion + '-R0.1-SNAPSHOT'
compileOnly group: 'net.md-5', name: 'bungeecord-api', version: mcVersion + '-R0.1-SNAPSHOT'
implementation group: 'org.jetbrains', name: 'annotations', version: '16.0.2'
implementation (group: 'com.github.SkriptLang', name: 'Skript', version: '2.5.3') {
compileOnly group: 'org.jetbrains', name: 'annotations', version: '16.0.2'
compileOnly (group: 'com.github.SkriptLang', name: 'Skript', version: '2.6-alpha1') {
exclude group: 'com.sk89q.worldguard', module: 'worldguard-legacy'
exclude group: 'net.milkbowl.vault', module: 'Vault'
}
compile group: 'commons-io', name: 'commons-io', version: '2.8.0'
implementation group: 'commons-io', name: 'commons-io', version: '2.8.0'
implementation group: 'com.github.rockaport', name:'alice', version: '0.9.0'
}

[compileJava, compileTestJava]*.options*.encoding = 'UTF-8'
Expand All @@ -38,8 +39,12 @@ processResources {
]
}

jar {
from {
configurations.compile.collect { it.isDirectory() ? it : zipTree(it) }
configurations {
implementation {
canBeResolved = true
}
}

shadowJar {
archiveName("BungeeSK.jar")
}
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.8.2-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
27 changes: 14 additions & 13 deletions src/main/java/fr/zorg/bungeesk/bukkit/BungeeSK.java
Original file line number Diff line number Diff line change
@@ -1,43 +1,42 @@
package fr.zorg.bungeesk.bukkit;

import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;

import ch.njol.skript.Skript;
import ch.njol.skript.SkriptAddon;
import com.rockaport.alice.AliceContext;
import fr.zorg.bungeesk.bukkit.sockets.ConnectionClient;
import fr.zorg.bungeesk.bukkit.updater.Commands;
import fr.zorg.bungeesk.bukkit.updater.Updater;
import fr.zorg.bungeesk.bukkit.utils.Metrics;
import fr.zorg.bungeesk.common.encryption.GlobalEncryption;
import org.bukkit.plugin.java.JavaPlugin;

import ch.njol.skript.Skript;
import ch.njol.skript.SkriptAddon;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;

public class BungeeSK extends JavaPlugin {

private Metrics metrics;
private static Logger logger;
private static GlobalEncryption encryption;

@Override
public void onEnable() {
this.metrics = new Metrics(this, 10655);
encryption = new GlobalEncryption(AliceContext.Algorithm.AES, 10);

logger = getLogger();
final SkriptAddon addon = Skript.registerAddon(this);
try {
addon.loadClasses("fr.zorg.bungeesk.bukkit.skript");
} catch (IOException e) {
e.printStackTrace();
}
Updater.get().register(new Commands());

this.metrics.addCustomChart(new Metrics.SimplePie("skript_version", () -> Skript.getVersion().toString()));
}

@Override
public void onDisable() {
Updater.get().stop();
if(ConnectionClient.get() != null) {
getLogger().info("Disconnecting from connection " + ConnectionClient.get().getAddress() + ":" + ConnectionClient.get().getPort());
if (isClientConnected()) {
ConnectionClient.get().disconnect();
}
}
Expand All @@ -47,7 +46,6 @@ public static BungeeSK getInstance() {
}



public static boolean isClientConnected() {
if (ConnectionClient.get() != null && ConnectionClient.get().isConnected()) {
return true;
Expand All @@ -56,4 +54,7 @@ public static boolean isClientConnected() {
return false;
}

public static GlobalEncryption getEncryption() {
return encryption;
}
}
35 changes: 33 additions & 2 deletions src/main/java/fr/zorg/bungeesk/bukkit/skript/Types.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import ch.njol.skript.registrations.Classes;
import fr.zorg.bungeesk.bukkit.sockets.ClientSettings;
import fr.zorg.bungeesk.bukkit.utils.BungeePlayer;
import fr.zorg.bungeesk.bukkit.utils.BungeeServer;

public class Types {

Expand Down Expand Up @@ -62,12 +63,42 @@ public BungeePlayer parse(final String id, final ParseContext context) {

@Override
public String toString(final BungeePlayer player, final int arg1) {
return player.getPlayer();
return player.getName();
}

@Override
public String toVariableNameString(final BungeePlayer player) {
return player.getPlayer();
return player.getName();
}

}));

Classes.registerClass(new ClassInfo<>(BungeeServer.class, "bungeeserver")
.defaultExpression(new EventValueExpression<>(BungeeServer.class))
.user("bungeeserver")
.name("Bungee player")
.description("Represents a player on the network")
.since("1.1.0")
.parser(new Parser<BungeeServer>() {

@Override
public String getVariableNamePattern() {
return ".+";
}

@Override
public BungeeServer parse(final String id, final ParseContext context) {
return null;
}

@Override
public String toString(final BungeeServer server, final int arg1) {
return server.getName();
}

@Override
public String toVariableNameString(final BungeeServer server) {
return server.getName();
}

}));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,17 @@
import ch.njol.skript.lang.Expression;
import ch.njol.skript.lang.SkriptParser;
import ch.njol.util.Kleenean;
import com.google.gson.JsonObject;
import fr.zorg.bungeesk.bukkit.BungeeSK;
import fr.zorg.bungeesk.bukkit.sockets.ConnectionClient;
import fr.zorg.bungeesk.bukkit.utils.BungeePlayer;
import org.bukkit.event.Event;
import org.jetbrains.annotations.Nullable;

import java.util.LinkedList;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;

@Name("Is bungee player connected")
@Description("Checks if a bungee player is connected")
@Since("1.0.0")
@Examples("broadcast \"God is connected !\" if bungeeplayer \"Zorg\" is connected")
@Examples("broadcast \"Zorg is connected !\" if bungee player named \"Zorg\" is connected")
public class CondBungeePlayerConnected extends Condition {

static {
Expand All @@ -46,11 +41,14 @@ public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelaye
@Override
public boolean check(Event e) {
if (BungeeSK.isClientConnected()) {
String result = ConnectionClient.get().future("ISCONNECTEDµ" + player.getSingle(e).getData());
if (negate) {
return (result.equals("FALSE"));
}
return (result.equals("TRUE"));
if (player.getSingle(e) == null)
return negate;

final JsonObject result = ConnectionClient.get().future("expressionGetPlayerConnectionState",
"playerUniqueId", player.getSingle(e).getUuid());
if (negate)
return (result.get("error").getAsBoolean());
return !(result.get("error").getAsBoolean());
}
return false;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package fr.zorg.bungeesk.bukkit.skript.effects;

import ch.njol.skript.Skript;
import ch.njol.skript.doc.Description;
import ch.njol.skript.doc.Examples;
import ch.njol.skript.doc.Name;
import ch.njol.skript.doc.Since;
import ch.njol.skript.lang.Effect;
import ch.njol.skript.lang.Expression;
import ch.njol.skript.lang.SkriptParser;
import ch.njol.util.Kleenean;
import fr.zorg.bungeesk.bukkit.BungeeSK;
import fr.zorg.bungeesk.bukkit.sockets.ConnectionClient;
import org.bukkit.event.Event;

@Name("Broadcast message to the network")
@Description("Broadcast message to the network, like the /alert command does but with more personalization (the messages will not appear in the spigot consoles)")
@Examples("broadcast \"&6Hello everyone\" to network")
@Since("1.1.0")
public class EffBroadcastMessageToNetwork extends Effect {

static {
Skript.registerEffect(EffBroadcastMessageToNetwork.class,
"broadcast %string% to [the] network");
}

private Expression<String> message;

@Override
public boolean init(Expression<?>[] exprs, int pattern, Kleenean kleenean, SkriptParser.ParseResult parseResult) {
this.message = (Expression<String>) exprs[0];
return true;
}

@Override
protected void execute(Event e) {
if (BungeeSK.isClientConnected()) {
ConnectionClient.get().write(true, "effectBroadcastMessageToNetwork",
"message", this.message.getSingle(e));
}
}

@Override
public String toString(Event e, boolean debug) {
return "broadcast message " + this.message.toString(e, debug) + " into the whole bungeecord network";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,34 +11,41 @@
import ch.njol.util.Kleenean;
import fr.zorg.bungeesk.bukkit.BungeeSK;
import fr.zorg.bungeesk.bukkit.sockets.ConnectionClient;
import fr.zorg.bungeesk.bukkit.utils.BungeeServer;
import org.bukkit.event.Event;
import org.jetbrains.annotations.Nullable;

@Name("Broadcast message to server")
@Description("Broadcasts a message to a server in the network")
@Examples("broadcast \"&aHello world !\" to server \"hub\"")
@Since("1.0.3")
@Examples("broadcast \"&aHello world !\" to bungee server named \"hub\"")
@Since("1.0.3 - 1.1.0: Usage of BungeeServer type")
public class EffBroadcastMessageToServer extends Effect {

static {
Skript.registerEffect(EffBroadcastMessageToServer.class,
"broadcast %string% to server %string%");
"broadcast %string% to %bungeeserver%");
}

private Expression<String> message;
private Expression<String> server;
private Expression<BungeeServer> server;

@Override
public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, SkriptParser.ParseResult parseResult) {
message = (Expression<String>) exprs[0];
server = (Expression<String>) exprs[1];
this.message = (Expression<String>) exprs[0];
this.server = (Expression<BungeeServer>) exprs[1];
return true;
}

@Override
protected void execute(Event e) {
if (BungeeSK.isClientConnected()) {
ConnectionClient.get().write("BROADCASTTOSERVµ" + server.getSingle(e) + "µ" + message.getSingle(e));

if (this.server.getSingle(e) == null)
return;

ConnectionClient.get().write(true, "effectBroadcastMessageToServer",
"server", this.server.getSingle(e).getAddress() + ":" + this.server.getSingle(e).getPort(),
"message", message.getSingle(e));
}
}

Expand Down
Loading

0 comments on commit ecb1b79

Please sign in to comment.