generated from sVoxelDev/spigot-plugin-template
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(platform): add bungeecord platform
- Loading branch information
Showing
21 changed files
with
806 additions
and
167 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} |
92 changes: 92 additions & 0 deletions
92
platform/bungeecord/src/main/java/net/silthus/schat/bungeecord/BungeecordBootstrap.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
platform/bungeecord/src/main/java/net/silthus/schat/bungeecord/BungeecordLoader.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
Oops, something went wrong.