Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add BungeeCord support #2

Merged
merged 14 commits into from
Mar 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ Wspierane (przetestowane przez autorów) wersje Minecrafta — od 1.8 do 1.19.3

Plugin przeznaczony dla platform:
- pochodnych Bukkita (Spigot, Paper, itp.)
- pochodnych BungeeCord (WaterFall itp.) - 1.19+

Autor pluginu: [Kamilkime](https://github.com/Kamilkime)
Autorzy pluginu: [Contributors](https://github.com/SpaceCodePoland/spaceis-plugin/graphs/contributors)
7 changes: 6 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ allprojects {
apply plugin: 'com.github.johnrengelman.shadow'

group = 'pl.spaceis.plugin'
version = '1.1'
version = '1.2'

sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
Expand All @@ -26,6 +26,10 @@ allprojects {
name = 'spigotmc-repo'
url = 'https://hub.spigotmc.org/nexus/content/repositories/snapshots/'
}
maven {
name = 'sonatype-repo'
url = 'https://oss.sonatype.org/content/repositories/snapshots'
}
}

shadowJar {
Expand All @@ -41,4 +45,5 @@ allprojects {

dependencies {
implementation project(':bukkit')
implementation project(':bungee')
}
35 changes: 35 additions & 0 deletions bukkit/src/main/java/pl/spaceis/plugin/bukkit/BukkitMessages.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright (C) 2023 SpaceIs-plugin Contributors
* https://github.com/SpaceCodePoland/spaceis-plugin/graphs/contributors
*
* 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.
*/

package pl.spaceis.plugin.bukkit;
P3ridot marked this conversation as resolved.
Show resolved Hide resolved

import org.bukkit.ChatColor;
import pl.spaceis.plugin.config.Messages;

public class BukkitMessages extends Messages<String> {

@Override
protected String color(final String message) {
return ChatColor.translateAlternateColorCodes('&', message);
}

@Override
public String appendMessage(final String message, final String append) {
return message + append;
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
* Copyright (C) 2023 Kamil Trysiński
* Copyright (C) 2023 SpaceIs-plugin Contributors
* https://github.com/SpaceCodePoland/spaceis-plugin/graphs/contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -16,45 +17,47 @@

package pl.spaceis.plugin.bukkit;

import java.util.Arrays;
import java.util.HashSet;
import java.util.Locale;
import java.util.Set;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import pl.spaceis.plugin.command.SpaceIsCommand;
import pl.spaceis.plugin.config.Config;
import pl.spaceis.plugin.config.EmptyConfigFieldException;
import pl.spaceis.plugin.config.Messages;

public class SpaceIsCommand implements CommandExecutor {
public class BukkitSpaceIsCommand implements CommandExecutor, SpaceIsCommand<CommandSender, String> {

private static final Set<String> RELOAD_ARGS = new HashSet<>(Arrays.asList("rl", "reload"));
private final Config config;
private final Messages<String> messages;

public SpaceIsCommand(final Config config) {
public BukkitSpaceIsCommand(final Config config, Messages<String> messages) {
this.config = config;
this.messages = messages;
}

@Override
public boolean onCommand(final CommandSender sender, final Command command, final String label, final String[] args) {
if (!sender.hasPermission("spaceis.reload")) {
sender.sendMessage(Messages.NO_PERMISSION);
return true;
}

if (args.length != 1 || !RELOAD_ARGS.contains(args[0].toLowerCase(Locale.ROOT))) {
sender.sendMessage(Messages.CORRECT_SYNTAX);
return true;
}

try {
this.config.loadValues();
sender.sendMessage(Messages.CONFIG_RELOAD_SUCCESS);
} catch (final EmptyConfigFieldException exception) {
sender.sendMessage(Messages.CONFIG_RELOAD_ERROR + exception.getMessage());
}

this.executeCommand(sender, args);
return true;
}

@Override
public void sendMessage(final CommandSender sender, final String message) {
sender.sendMessage(message);
}

@Override
public boolean hasPermission(final CommandSender sender, final String permission) {
return sender.hasPermission(permission);
}

@Override
public Config getConfig() {
return this.config;
}

@Override
public Messages<String> getMessages() {
return this.messages;
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
* Copyright (C) 2022 Kamil Trysiński
* Copyright (C) 2023 SpaceIs-plugin Contributors
* https://github.com/SpaceCodePoland/spaceis-plugin/graphs/contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -22,7 +23,9 @@
import pl.spaceis.plugin.config.Config;
import pl.spaceis.plugin.config.ConfigLoader;
import pl.spaceis.plugin.config.EmptyConfigFieldException;
import pl.spaceis.plugin.config.Messages;
import pl.spaceis.plugin.logger.SpaceIsLogger;
import pl.spaceis.plugin.resource.ResourceLoaderException;

public class BukkitSpaceIsPlugin extends JavaPlugin {

Expand All @@ -34,6 +37,7 @@ public void onEnable() {
final SpaceIsLogger logger = new BukkitSpaceIsLogger(this.getLogger());
final ConfigLoader configLoader = new BukkitConfigLoader(this);
final Config config = new Config(configLoader);
final Messages<String> messages = new BukkitMessages();

Bukkit.getScheduler().runTaskTimerAsynchronously(
this,
Expand All @@ -42,8 +46,8 @@ public void onEnable() {
config.taskInterval.getSeconds() * 20L
);

this.getCommand("spaceis").setExecutor(new SpaceIsCommand(config));
} catch (final EmptyConfigFieldException exception) {
this.getCommand("spaceis").setExecutor(new BukkitSpaceIsCommand(config, messages));
} catch (final ResourceLoaderException | EmptyConfigFieldException exception) {
this.getLogger().severe(exception.getMessage());
Bukkit.getPluginManager().disablePlugin(this);
}
Expand Down
31 changes: 0 additions & 31 deletions bukkit/src/main/java/pl/spaceis/plugin/bukkit/Messages.java

This file was deleted.

4 changes: 2 additions & 2 deletions bukkit/src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
name: "SpaceIsPlugin"
version: "1.1"
version: "1.2"
api-version: "1.13"
main: "pl.spaceis.plugin.bukkit.BukkitSpaceIsPlugin"
description: "Wykonuj komendy ze swojego sklepu SpaceIs"
website: "https://spaceis.pl/"
author: "Kamilkime"
author: "SpaceIs-plugin Contributors"

commands:
spaceis:
Expand Down
4 changes: 4 additions & 0 deletions bungee/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
dependencies {
implementation project(':common')
compileOnly 'net.md-5:bungeecord-api:1.19-R0.1-SNAPSHOT'
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Copyright (C) 2023 SpaceIs-plugin Contributors
* https://github.com/SpaceCodePoland/spaceis-plugin/graphs/contributors
*
* 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.
*/

package pl.spaceis.plugin.bungee;
P3ridot marked this conversation as resolved.
Show resolved Hide resolved

import net.md_5.bungee.api.ProxyServer;
import okhttp3.OkHttpClient;
import pl.spaceis.plugin.command.CommandsTask;
import pl.spaceis.plugin.config.Config;
import pl.spaceis.plugin.logger.SpaceIsLogger;

public class BungeeCommandsTask extends CommandsTask {

private final ProxyServer proxy;

public BungeeCommandsTask(final OkHttpClient httpClient, final Config config, final SpaceIsLogger logger) {
super(httpClient, config, logger);
this.proxy = ProxyServer.getInstance();
}

@Override
public boolean isPlayerOnline(final String playerName) {
return this.proxy.getPlayer(playerName) != null;
}

@Override
public void executeCommand(final String command) {
this.proxy.getPluginManager().dispatchCommand(this.proxy.getConsole(), command);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* Copyright (C) 2023 SpaceIs-plugin Contributors
* https://github.com/SpaceCodePoland/spaceis-plugin/graphs/contributors
*
* 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.
*/

package pl.spaceis.plugin.bungee;
P3ridot marked this conversation as resolved.
Show resolved Hide resolved

import net.md_5.bungee.config.Configuration;
import pl.spaceis.plugin.config.ConfigLoader;
import pl.spaceis.plugin.resource.ResourceLoader;
import pl.spaceis.plugin.resource.ResourceLoaderException;

public class BungeeConfigLoader implements ConfigLoader {

private final ResourceLoader<Configuration> resourceLoader;
private final String configFileName;
private Configuration configFile;

public BungeeConfigLoader(final ResourceLoader<Configuration> resourceLoader, final String configFileName) {
this.resourceLoader = resourceLoader;
this.configFileName = configFileName;
}

@Override
public void reloadConfig() throws ResourceLoaderException {
this.resourceLoader.saveDefault(this.configFileName);
this.configFile = this.resourceLoader.load(this.configFileName);
}

@Override
public boolean getBoolean(final String key) {
return this.configFile.getBoolean(key);
}

@Override
public String getString(final String key) {
return this.configFile.getString(key);
}

}
40 changes: 40 additions & 0 deletions bungee/src/main/java/pl/spaceis/plugin/bungee/BungeeMessages.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Copyright (C) 2023 SpaceIs-plugin Contributors
* https://github.com/SpaceCodePoland/spaceis-plugin/graphs/contributors
*
* 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.
*/

package pl.spaceis.plugin.bungee;
P3ridot marked this conversation as resolved.
Show resolved Hide resolved

import net.md_5.bungee.api.ChatColor;
import net.md_5.bungee.api.chat.BaseComponent;
import net.md_5.bungee.api.chat.TextComponent;
import pl.spaceis.plugin.config.Messages;

public class BungeeMessages extends Messages<BaseComponent> {

@Override
protected BaseComponent color(final String message) {
String coloredMessage = ChatColor.translateAlternateColorCodes('&', message);
return new TextComponent(TextComponent.fromLegacyText(coloredMessage));
}

@Override
public BaseComponent appendMessage(final BaseComponent message, final String append) {
BaseComponent finalMessage = message.duplicate();
finalMessage.addExtra(append);
return finalMessage;
}

}
Loading