Skip to content

Commit

Permalink
Merge pull request #129 from Nookure/dev
Browse files Browse the repository at this point in the history
1.4.4
  • Loading branch information
Angelillo15 authored Oct 6, 2024
2 parents dec6158 + 9229b02 commit 604678e
Show file tree
Hide file tree
Showing 26 changed files with 354 additions and 46 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/dependency-submission.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ jobs:
distribution: 'temurin'
java-version: 21
- name: Generate and submit dependency graph
uses: gradle/actions/dependency-submission@v3
uses: gradle/actions/dependency-submission@v4
with:
dependency-resolution-task: shadowJar
4 changes: 2 additions & 2 deletions .github/workflows/javadoc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- name: Checkout main branch from GitHub
uses: actions/checkout@v3
uses: actions/checkout@v4

# Runs a single command using the runners shell
- name: Setting up JDK 21
Expand All @@ -29,7 +29,7 @@ jobs:
java-version: 21

- name: Setup Gradle
uses: gradle/gradle-build-action@v2
uses: gradle/actions/setup-gradle@v4

- name: Execute Gradle build
run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
distribution: 'temurin'
java-version: 21
- name: Setup Gradle
uses: gradle/actions/setup-gradle@v3
uses: gradle/actions/setup-gradle@v4
- name: Execute Gradle build
env:
GRGIT_USER: "Angelillo15"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
distribution: 'temurin'
java-version: 21
- name: Setup Gradle
uses: gradle/actions/setup-gradle@v3
uses: gradle/actions/setup-gradle@v4

- name: Execute Gradle test
run: |
Expand Down
1 change: 1 addition & 0 deletions NookureStaff-API/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ dependencies {
compileOnlyApi(rootProject.libs.miniMessage)
compileOnlyApi(rootProject.libs.caffeine)
compileOnlyApi(rootProject.libs.ebean)
compileOnlyApi(rootProject.libs.placeholderApi)
annotationProcessor(rootProject.libs.ebean)

compileOnly(libs.auto.service.annotations)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@

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

@ConfigSerializable
public class PlayerActions {
@Comment("""
If true, the player will be able to inspect a player by
shift and right-clicking on them.
""")
private final boolean shiftAndRightClickToInspect = true;
@Setting
private boolean shiftAndRightClickToInspect = true;

public boolean shiftAndRightClickToInspect() {
return shiftAndRightClickToInspect;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,22 @@ public class FreezeMessagePartial {
@Comment("Message sent when a player is punished")
private String punishMessage = "<bold><dark_aqua>Freeze <dark_gray>»</bold> <gray>You have punished {player}.</gray>";

@Setting
@Comment("Message sent when the timer has been paused for a player")
private String theTimerHasBeenPausedFor = "<bold><dark_aqua>Freeze <dark_gray>»</bold> <gray>The timer has been paused for {player}.</gray>";

@Setting
@Comment("Message sent when the staff has paused the timer for a player")
private String theStaffHasPausedTheTimer = "<bold><dark_aqua>Freeze <dark_gray>»</bold> <gray>The staff has paused the timer for you</gray>";

@Setting
@Comment("Message sent when a player is not frozen.")
private String playerNotFrozen = "<bold><dark_aqua>Freeze <dark_gray>»</bold> <red>That player is not frozen.</red>";

public String playerNotFrozen() {
return playerNotFrozen;
}

public String frozenMessage() {
return frozenMessage;
}
Expand Down Expand Up @@ -141,4 +157,12 @@ public String forgiveMessage() {
public String punishMessage() {
return punishMessage;
}

public String theTimerHasBeenPausedFor() {
return theTimerHasBeenPausedFor;
}

public String theStaffHasPausedTheTimer() {
return theStaffHasPausedTheTimer;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;

import java.util.Iterator;
import java.util.Optional;
import java.util.UUID;
import java.util.stream.Stream;
Expand Down Expand Up @@ -125,6 +126,10 @@ public Stream<FreezeContainer> stream() {
return freezeContainers.values().stream();
}

public Iterator<FreezeContainer> iterator() {
return freezeContainers.values().iterator();
}

public static final class FreezeContainer {
private final UUID staff;
private final UUID target;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,16 @@
package com.nookure.staff.api.util;

import com.nookure.staff.api.Permissions;
import org.bukkit.Bukkit;
import org.jetbrains.annotations.NotNull;

import java.util.UUID;
import java.util.logging.Logger;

public abstract class ServerUtils {
public static final boolean isPaper;

static {
isPaper = hasClass("com.destroystokyo.paper.PaperConfig") ||
hasClass("io.papermc.paper.configuration.Configuration");
}

private static boolean hasClass(String className) {
try {
Class.forName(className);
return true;
} catch (ClassNotFoundException e) {
return false;
}
}
public static final MinecraftVersion MINECRAFT_VERSION;
private static final Logger logger = Logger.getLogger("NookureStaff");

/**
* Check if a player is online
Expand Down Expand Up @@ -54,4 +44,64 @@ private static boolean hasClass(String className) {
public void broadcastStaffMessage(@NotNull String message) {
broadcast(message, Permissions.STAFF_PERMISSION);
}

static {
isPaper = hasClass("com.destroystokyo.paper.PaperConfig") ||
hasClass("io.papermc.paper.configuration.Configuration");

MINECRAFT_VERSION = getMinecraftVersionOrDefault();
}

private static MinecraftVersion getMinecraftVersionOrDefault() {
try {
try {
return getMinecraftVersionByPaper();
} catch (Exception e) {
return getMinecraftVersionByBukkit();
}
} catch (Exception e) {
logger.warning("Failed to get the Minecraft version, defaulting to 0.0.0");
logger.warning("Keep in mind that this may cause issues with the plugin");
logger.warning("Because of this, it is recommended to use the latest version of the software");
return new MinecraftVersion(0, 0, 0);
}
}

private static MinecraftVersion getMinecraftVersionByPaper() {
String[] version = Bukkit.getMinecraftVersion().split("\\.");
return new MinecraftVersion(Integer.parseInt(version[0]), Integer.parseInt(version[1]), Integer.parseInt(version[2]));
}

private static MinecraftVersion getMinecraftVersionByBukkit() {
String version = Bukkit.getServer().getClass().getPackage().getName().split("\\.")[3];
String[] versionSplit = version.split("_");
return new MinecraftVersion(Integer.parseInt(versionSplit[0]), Integer.parseInt(versionSplit[1]), Integer.parseInt(versionSplit[2]));
}

public record MinecraftVersion(int major, int minor, int patch) {
public boolean isAtLeast(int major, int minor, int patch) {
return this.major > major || (this.major == major && this.minor > minor) || (this.major == major && this.minor == minor && this.patch >= patch);
}

public boolean isBefore(int major, int minor, int patch) {
return this.major < major || (this.major == major && this.minor < minor) || (this.major == major && this.minor == minor && this.patch < patch);
}

public boolean isAtLeast(int major, int minor) {
return isAtLeast(major, minor, 0);
}

public boolean isBefore(int major, int minor) {
return isBefore(major, minor, 0);
}
}

public static boolean hasClass(String className) {
try {
Class.forName(className);
return true;
} catch (ClassNotFoundException e) {
return false;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@

import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.minimessage.MiniMessage;
import org.jetbrains.annotations.NotNull;

import java.util.ArrayList;
import java.util.List;

import static com.nookure.staff.api.util.ServerUtils.hasClass;

public abstract class TextUtils {
private static final boolean IS_PAPI_INSTALLED = hasClass("me.clip.placeholderapi.PlaceholderAPI");
private static final long SECOND = 1000;
private static final long MINUTE = 60 * SECOND;
private static final long HOUR = 60 * MINUTE;
Expand Down Expand Up @@ -117,4 +121,10 @@ public static String formatTime(long time) {
}
return buf.toString();
}

public static String parsePlaceholdersWithPAPI(@NotNull final org.bukkit.entity.Player player, @NotNull final String message) {
if (!IS_PAPI_INSTALLED) return message;

return me.clip.placeholderapi.PlaceholderAPI.setPlaceholders(player, message);
}
}
1 change: 1 addition & 0 deletions NookureStaff-Paper/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ dependencies {
compileOnly(libs.configurateYaml)
compileOnly(libs.jedis)
compileOnly(libs.placeholderApi)
compileOnly(libs.lucko.commodore)
compileOnly(libs.nookure.core.inventory)
bukkitLibrary(libs.guice)
bukkitLibrary(libs.google.guice.assistedinject)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import com.nookure.staff.api.util.DefaultFontInfo;
import com.nookure.staff.api.util.Scheduler;
import com.nookure.staff.api.util.ServerUtils;
import com.nookure.staff.api.util.TextUtils;
import io.ebean.Database;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.minimessage.MiniMessage;
Expand Down Expand Up @@ -172,6 +173,7 @@ public void sendMiniMessage(@NotNull String message, String... placeholders) {

message = message.replace("{prefix}", nookPlugin.getPrefix());
message = DefaultFontInfo.centerIfContains(message);
message = TextUtils.parsePlaceholdersWithPAPI(player, message);

sendMessage(MiniMessage.miniMessage().deserialize(message));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import com.nookure.staff.api.model.StaffDataModel;
import com.nookure.staff.api.state.PlayerState;
import com.nookure.staff.api.util.Scheduler;
import com.nookure.staff.api.util.ServerUtils;
import com.nookure.staff.paper.data.StaffModeData;
import io.ebean.Database;
import net.kyori.adventure.text.minimessage.MiniMessage;
Expand Down Expand Up @@ -402,6 +403,8 @@ public void setStaffChatAsDefault(boolean staffChatAsDefault) {

//<editor-fold desc="Potion effects">
public void loadPotionEffects() {
if (ServerUtils.MINECRAFT_VERSION.isBefore(1, 20)) return;

if (config.get().staffMode.nightVision()) {
if (!player.hasPotionEffect(PotionEffectType.NIGHT_VISION)) toggleNightVision();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
package com.nookure.staff.paper.brigadier;

import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import com.mojang.brigadier.tree.LiteralCommandNode;
import com.nookure.staff.api.PlayerWrapper;
import com.nookure.staff.api.command.CommandSender;
import com.nookure.staff.api.manager.PlayerWrapperManager;
import org.bukkit.command.Command;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;

import java.util.List;
import java.util.Optional;

import static java.util.Objects.requireNonNull;

public abstract class BrigadierCommand extends Command {
private final CommandSender consoleSender;
private final PlayerWrapperManager<Player> playerWrapperManager;
private final CommandDispatcher<CommandSender> dispatcher;

protected BrigadierCommand(
@NotNull final String name,
@NotNull final CommandDispatcher<CommandSender> dispatcher,
@NotNull final PlayerWrapperManager<Player> playerWrapperManager,
@NotNull final CommandSender consoleSender
) {
super(name);
requireNonNull(dispatcher, "dispatcher cannot be null");
requireNonNull(playerWrapperManager, "playerWrapperManager cannot be null");
requireNonNull(consoleSender, "consoleSender cannot be null");
this.dispatcher = dispatcher;
this.playerWrapperManager = playerWrapperManager;
this.consoleSender = consoleSender;
}

protected BrigadierCommand(
@NotNull final String name,
@NotNull final String description,
@NotNull final String usageMessage,
@NotNull final List<String> aliases,
@NotNull final CommandDispatcher<CommandSender> dispatcher,
@NotNull final PlayerWrapperManager<Player> playerWrapperManager,
@NotNull final CommandSender consoleSender
) {
super(name, description, usageMessage, aliases);
requireNonNull(dispatcher, "dispatcher cannot be null");
requireNonNull(playerWrapperManager, "playerWrapperManager cannot be null");
requireNonNull(consoleSender, "consoleSender cannot be null");
this.dispatcher = dispatcher;
this.playerWrapperManager = playerWrapperManager;
this.consoleSender = consoleSender;
}

public void register() {
dispatcher.register(build().createBuilder());
}

public abstract LiteralCommandNode<CommandSender> build();

@Override
public boolean execute(org.bukkit.command.@NotNull CommandSender sender, @NotNull String commandLabel, @NotNull String[] args) {
if (!(sender instanceof Player player)) {
try {
dispatcher.execute(commandLabel, consoleSender);
} catch (CommandSyntaxException e) {
throw new RuntimeException(e);
}

return true;
}

Optional<PlayerWrapper> playerWrapperOptional = playerWrapperManager.getPlayerWrapper(player.getUniqueId());

if (playerWrapperOptional.isEmpty()) {
return false;
}

CommandSender commandSender = playerWrapperOptional.get();

try {
dispatcher.execute(commandLabel, commandSender);
} catch (CommandSyntaxException e) {
throw new RuntimeException(e);
}

return false;
}
}
Loading

0 comments on commit 604678e

Please sign in to comment.