Skip to content

Commit

Permalink
feat(platform): add bungeecord platform
Browse files Browse the repository at this point in the history
  • Loading branch information
Silthus committed Feb 17, 2022
1 parent 785f1d7 commit c663e5f
Show file tree
Hide file tree
Showing 21 changed files with 806 additions and 167 deletions.
97 changes: 97 additions & 0 deletions core/src/main/java/net/silthus/schat/util/Iterators.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
/*
* sChat, a Supercharged Minecraft Chat Plugin
* Copyright (C) Silthus <https://www.github.com/silthus>
* Copyright (C) sChat team and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

package net.silthus.schat.util;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.function.Consumer;
import java.util.function.Function;

public final class Iterators {
private Iterators() {
}

public static <E> boolean tryIterate(Iterable<E> iterable, Throwing.Consumer<E> action) {
boolean success = true;
for (E element : iterable) {
try {
action.accept(element);
} catch (Exception e) {
e.printStackTrace();
success = false;
}
}
return success;
}

public static <I, O> boolean tryIterate(Iterable<I> iterable, Function<I, O> mapping, Consumer<O> action) {
boolean success = true;
for (I element : iterable) {
try {
action.accept(mapping.apply(element));
} catch (Exception e) {
e.printStackTrace();
success = false;
}
}
return success;
}

public static <E> boolean tryIterate(E[] array, Consumer<E> action) {
boolean success = true;
for (E element : array) {
try {
action.accept(element);
} catch (Exception e) {
e.printStackTrace();
success = false;
}
}
return success;
}

public static <I, O> boolean tryIterate(I[] array, Function<I, O> mapping, Consumer<O> action) {
boolean success = true;
for (I element : array) {
try {
action.accept(mapping.apply(element));
} catch (Exception e) {
e.printStackTrace();
success = false;
}
}
return success;
}

public static <E> List<List<E>> divideIterable(Iterable<E> source, int size) {
List<List<E>> lists = new ArrayList<>();
Iterator<E> it = source.iterator();
while (it.hasNext()) {
List<E> subList = new ArrayList<>();
for (int i = 0; it.hasNext() && i < size; i++) {
subList.add(it.next());
}
lists.add(subList);
}
return lists;
}

}
33 changes: 33 additions & 0 deletions core/src/main/java/net/silthus/schat/util/Throwing.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* sChat, a Supercharged Minecraft Chat Plugin
* Copyright (C) Silthus <https://www.github.com/silthus>
* Copyright (C) sChat team and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

package net.silthus.schat.util;

public interface Throwing {

@FunctionalInterface
interface Runnable {
void run() throws Exception;
}

@FunctionalInterface
interface Consumer<T> {
void accept(T t) throws Exception;
}
}
Original file line number Diff line number Diff line change
@@ -1,25 +1,20 @@
/*
* This file is part of sChat, licensed under the MIT License.
* sChat, a Supercharged Minecraft Chat Plugin
* Copyright (C) Silthus <https://www.github.com/silthus>
* Copyright (C) sChat team and contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

package net.silthus.schat.bukkit;
Expand Down Expand Up @@ -85,4 +80,9 @@ public Platform.Type getType() {
public String getServerBrand() {
return getLoader().getServer().getName();
}

@Override
public String getServerVersion() {
return getLoader().getServer().getVersion();
}
}
25 changes: 25 additions & 0 deletions platform/bungeecord/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
repositories {
maven { url = "https://oss.sonatype.org/content/repositories/snapshots" }
}

dependencies {
implementation 'net.md-5:bungeecord-api:1.16-R0.5-SNAPSHOT'

implementation "net.kyori:adventure-platform-bungeecord:4.0.1"
}

shadowJar {
archiveClassifier.set("")
dependencies {
include(project(':core'))
include(project(':platform'))
include(dependency('io.leangen.geantyref::'))
include(dependency('org.spongepowered::'))
include(dependency('net.kyori::'))
include(dependency('org.bstats::'))
}
relocate 'org.spongepowered.configurate', "${packageName}.lib.configurate"
relocate 'io.leangen.geantyref', "${packageName}.lib.typetoken"
relocate 'net.kyori', "${packageName}.lib.kyori"
relocate 'org.bstats', "${packageName}.lib.bstats"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
/*
* sChat, a Supercharged Minecraft Chat Plugin
* Copyright (C) Silthus <https://www.github.com/silthus>
* Copyright (C) sChat team and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

package net.silthus.schat.bungeecord;

import java.nio.file.Path;
import lombok.Getter;
import net.md_5.bungee.api.ProxyServer;
import net.md_5.bungee.api.plugin.Plugin;
import net.silthus.schat.bungeecord.adapter.BungeecordSchedulerAdapter;
import net.silthus.schat.platform.plugin.bootstrap.Bootstrap;
import net.silthus.schat.platform.plugin.bootstrap.LoaderBootstrap;
import net.silthus.schat.platform.plugin.bootstrap.Platform;
import net.silthus.schat.platform.plugin.logging.JavaPluginLogger;
import net.silthus.schat.platform.plugin.scheduler.SchedulerAdapter;

@Getter
public final class BungeecordBootstrap implements Bootstrap, LoaderBootstrap {

private final Plugin loader;
private final ProxyServer proxy;
private final SchedulerAdapter scheduler;
private final BungeecordProxyPlugin plugin;

private JavaPluginLogger pluginLogger;

BungeecordBootstrap(Plugin loader) {
this.loader = loader;
this.proxy = loader.getProxy();
this.scheduler = new BungeecordSchedulerAdapter(loader, loader.getProxy());

this.plugin = new BungeecordProxyPlugin(this);
}

@Override
public Path getDataDirectory() {
return loader.getDataFolder().toPath();
}

@Override
public String getVersion() {
return loader.getDescription().getVersion();
}

@Override
public Platform.Type getType() {
return Platform.Type.BUNGEECORD;
}

@Override
public String getServerBrand() {
return loader.getProxy().getName();
}

@Override
public String getServerVersion() {
return loader.getProxy().getVersion();
}

@Override
public void onLoad() {
pluginLogger = new JavaPluginLogger(loader.getLogger());

plugin.load();
}

@Override
public void onEnable() {
plugin.enable();
}

@Override
public void onDisable() {
plugin.disable();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* sChat, a Supercharged Minecraft Chat Plugin
* Copyright (C) Silthus <https://www.github.com/silthus>
* Copyright (C) sChat team and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

package net.silthus.schat.bungeecord;

import net.md_5.bungee.api.plugin.Plugin;

public class BungeecordLoader extends Plugin {

private final BungeecordBootstrap bootstrap;

public BungeecordLoader() {
this.bootstrap = new BungeecordBootstrap(this);
}

@Override
public void onLoad() {
bootstrap.onLoad();
}

@Override
public void onEnable() {
bootstrap.onEnable();
}

@Override
public void onDisable() {
bootstrap.onDisable();
}
}
Loading

0 comments on commit c663e5f

Please sign in to comment.