Skip to content

Commit

Permalink
Merge pull request #84 from Nookure/dev
Browse files Browse the repository at this point in the history
3.1.0
  • Loading branch information
Angelillo15 authored Dec 21, 2023
2 parents 902764d + b24ec4d commit 5285712
Show file tree
Hide file tree
Showing 93 changed files with 1,073 additions and 420 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/Javadoc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ name: JavaDoc Generator

on:
push:
branches: [ 2.x ]
branches: [ 3.x ]
jobs:

build-on-ubuntu:
Expand Down
7 changes: 4 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ name: MAStaff build

on:
push:
branches: [ 2.x ]
branches: [ 3.x ]
pull_request:
branches: [ 2.x ]
branches: [ 3.x ]
jobs:

build-on-ubuntu:
Expand All @@ -21,7 +21,7 @@ jobs:
uses: actions/checkout@v2

# Runs a single command using the runners shell
- name: Seting up JDK 1.8
- name: Seting up JDK 17
uses: actions/setup-java@v1
with:
java-version: 17
Expand All @@ -32,6 +32,7 @@ jobs:
- name: Execute Gradle build
run: |
chmod +x gradlew
MASTAFF_NMS=TRUE ./gradlew MAStaff-NMS:publishToMavenLocal
./gradlew shadowJar
mkdir staging && cp build/libs/*.jar staging
- name: Upload the jar
Expand Down
1 change: 1 addition & 0 deletions MAStaff-API/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ dependencies {
compileOnly(libs.guice)
compileOnly(libs.configurateGson)
compileOnly(libs.configurateHocon)
compileOnly(libs.configurateYaml)

testImplementation(platform("org.junit:junit-bom:5.9.1"))
testImplementation("org.junit.jupiter:junit-jupiter")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.nookure.mast.api.cmd.sender;

import net.kyori.adventure.audience.Audience;
import java.io.Serializable;

public interface CommandSender {
public interface CommandSender extends Serializable {
void sendMessage(String message);

boolean hasPermission(String permission);
Expand All @@ -23,7 +23,5 @@ public interface CommandSender {

boolean isSpigot();

Audience getAudience();

String getServerName();
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import com.google.inject.Inject;
import com.google.inject.Singleton;
import es.angelillo15.mast.api.ILogger;
import net.kyori.adventure.audience.Audience;

@Singleton
public class ConsoleCommandSender implements CommandSender {
Expand Down Expand Up @@ -59,11 +58,6 @@ public String getAddress() {
return "0.0.0.0";
}

@Override
public Audience getAudience() {
return null;
}

@Override
public String getServerName() {
return "Proxy";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,18 @@
package com.nookure.mast.api.cmd.sender;

import es.angelillo15.mast.api.TextUtils;
import net.kyori.adventure.audience.Audience;
import org.bukkit.entity.Player;

public class PlayerCommandSender implements CommandSender {
private final Player player;
private final Audience audience;

public PlayerCommandSender(Player player) {
this.player = player;
this.audience = TextUtils.getAudience(player);
}

@Override
public void sendMessage(String message) {
audience.sendMessage(TextUtils.toComponent(message));
TextUtils.sendMessage(player, message);
}

@Override
Expand Down Expand Up @@ -63,11 +60,6 @@ public String getAddress() {
return player.getAddress().getAddress().getHostAddress().split(":")[0];
}

@Override
public Audience getAudience() {
return audience;
}

@Override
public String getServerName() {
return player.getServer().getName();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
package com.nookure.mast.api.cmd.sender;

import es.angelillo15.mast.api.TextUtils;
import net.kyori.adventure.audience.Audience;
import net.md_5.bungee.api.chat.TextComponent;
import net.md_5.bungee.api.connection.ProxiedPlayer;

public class ProxiedPlayerCommandSender implements CommandSender {
private final ProxiedPlayer player;
private final Audience audience;

public ProxiedPlayerCommandSender(ProxiedPlayer player) {
this.player = player;
this.audience = TextUtils.getAudience(player);
}

@Override
Expand Down Expand Up @@ -64,13 +61,12 @@ public String getAddress() {
return player.getAddress().getAddress().getHostAddress().split(":")[0];
}

@Override
public Audience getAudience() {
return audience;
}

@Override
public String getServerName() {
return player.getServer().getInfo().getName();
}

public ProxiedPlayer getPlayer() {
return player;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import com.velocitypowered.api.proxy.Player;
import es.angelillo15.mast.api.TextUtils;
import net.kyori.adventure.audience.Audience;

public class VelocityPlayerCommandSender implements CommandSender {
private final Player player;
Expand Down Expand Up @@ -61,11 +60,6 @@ public boolean isSpigot() {
return false;
}

@Override
public Audience getAudience() {
return player;
}

@Override
public String getServerName() {
if (player.getCurrentServer().isPresent()) {
Expand All @@ -74,4 +68,8 @@ public String getServerName() {

return "Proxy";
}

public Player getPlayer() {
return player;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,25 @@

import org.spongepowered.configurate.CommentedConfigurationNode;
import org.spongepowered.configurate.ConfigurateException;
import org.spongepowered.configurate.hocon.HoconConfigurationLoader;
import org.spongepowered.configurate.yaml.NodeStyle;
import org.spongepowered.configurate.yaml.YamlConfigurationLoader;

public final class ConfigurationContainer<C> {
private final AtomicReference<C> config;
private final HoconConfigurationLoader loader;
private final YamlConfigurationLoader loader;
private final Class<C> clazz;
private final String fileName;

private ConfigurationContainer(
final C config,
final Class<C> clazz,
final HoconConfigurationLoader loader
final YamlConfigurationLoader loader,
final String fileName
) {
this.config = new AtomicReference<>(config);
this.loader = loader;
this.clazz = clazz;
this.fileName = fileName;
}

public C get() {
Expand All @@ -36,19 +40,33 @@ public CompletableFuture<Void> reload() {
final CommentedConfigurationNode node = loader.load();
config.set(node.get(clazz));
} catch (ConfigurateException exception) {
throw new CompletionException("Could not load config.conf file", exception);
throw new CompletionException("Could not load " + fileName + " file", exception);
}
});
}

public CompletableFuture<Void> save() {
return CompletableFuture.runAsync(() -> {
try {
final CommentedConfigurationNode node = loader.load();
node.set(clazz, config.get());
loader.save(node);
} catch (ConfigurateException exception) {
throw new CompletionException("Could not save " + fileName + " file", exception);
}
});
}

public static <C> ConfigurationContainer<C> load(Path path, Class<C> clazz) throws IOException {
return load(path, clazz, "config.conf");
return load(path, clazz, "config.yml");
}

public static <C> ConfigurationContainer<C> load(Path path, Class<C> clazz, String fileName) throws IOException {
path = path.resolve(fileName);
final boolean firstCreation = Files.notExists(path);
final HoconConfigurationLoader loader = HoconConfigurationLoader.builder()
final YamlConfigurationLoader loader = YamlConfigurationLoader.builder()
.nodeStyle(NodeStyle.BLOCK)
.indent(2)
.defaultOptions(opts -> opts
.shouldCopyDefaults(true)
.header("""
Expand All @@ -71,14 +89,17 @@ public static <C> ConfigurationContainer<C> load(Path path, Class<C> clazz, Stri
.path(path)
.build();


final CommentedConfigurationNode node = loader.load();
final C config = node.get(clazz);

if (firstCreation) {
node.set(clazz, config);
loader.save(node);
}

return new ConfigurationContainer<>(config, clazz, loader);
ConfigurationContainer<C> container = new ConfigurationContainer<>(config, clazz, loader, fileName);
container.save().join();

return container;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package com.nookure.mast.api.config.bukkit;

import org.spongepowered.configurate.objectmapping.ConfigSerializable;
import org.spongepowered.configurate.objectmapping.meta.Setting;

import java.util.List;

@ConfigSerializable
public class ScoreboardConfig {
private boolean enabled = true;

public boolean enabled() {
return enabled;
}

public final Scoreboard scoreboard = new Scoreboard();

@ConfigSerializable
public static final class Scoreboard {
@Setting
private String title = "<b><dark_aqua>Staff Mode</dark_aqua></b>";

public String title() {
return title;
}

@Setting
private List<String> lines = List.of(
"<b><yellow>|</yellow></b> <white>Rank:</white> <b><red>%vault_prefix%</red></b>",
"<b><yellow>|</yellow></b> <white>Vanished:</white> <green>True</green>",
"",
"<b><red>|</red></b> <white>Staffs online:</white> <green>%mastaff_staffcount%</green>",
"<b><red>|</red></b> <white>Online players:</white> <green>%server_online%</green>",
"<b><red>|</red></b> <white>Frozen players:</white> <green>%mastaff_freeze_count%</green>"
);

public List<String> lines() {
return lines;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.nookure.mast.api.event;

public class Channels {
public static final String EVENTS = "mastaff:events";
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
package com.nookure.mast.api.event;

public abstract class Event {
import java.io.Serializable;

public interface Event extends Serializable {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.nookure.mast.api.event;

import com.google.inject.Inject;
import com.nookure.mast.api.MAStaff;
import es.angelillo15.mast.api.ILogger;
import org.jetbrains.annotations.NotNull;

import java.io.IOException;
import java.io.ObjectInputStream;
import java.util.Objects;
import java.util.Optional;

public abstract class PluginMessageManager<P> {
@Inject
private ILogger logger;
@Inject
private MAStaff plugin;
abstract public void sendEvent(@NotNull Event event, @NotNull P player);

@NotNull
public Optional<Event> decodeEvent(@NotNull ObjectInputStream objetStream) {
Objects.requireNonNull(objetStream);

try {
return Optional.of((Event) objetStream.readObject());
} catch (IOException | ClassNotFoundException e) {
logger.error("Error while decoding event from object stream");
if (plugin.isDebug()) {
throw new RuntimeException(e);
}
}

return Optional.empty();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,15 @@
import com.nookure.mast.api.addons.AddonContainer;
import com.nookure.mast.api.event.Event;

public class AddonDisableEvent extends Event {
private final AddonContainer container;

public AddonDisableEvent(AddonContainer container) {
this.container = container;
}
public record AddonDisableEvent(AddonContainer container) implements Event {

/**
* Get the addon container
*
* @return addon container
*/
public AddonContainer getContainer() {
@Override
public AddonContainer container() {
return container;
}
}
Loading

0 comments on commit 5285712

Please sign in to comment.