Skip to content
This repository has been archived by the owner on Jan 20, 2024. It is now read-only.

Commit

Permalink
HookManager: add static boolean for enabled plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
TheFaser committed Aug 14, 2023
1 parent b8e838f commit 9f1e48e
Show file tree
Hide file tree
Showing 18 changed files with 63 additions and 55 deletions.
16 changes: 16 additions & 0 deletions src/main/java/net/flectone/commands/CommandFlectonechat.java
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,22 @@ public List<String> onTabComplete(@NotNull CommandSender commandSender, @NotNull
isStartsWith(strings[3], "integer");
isStartsWith(strings[3], "boolean");
}
case 5 -> {

Object param = switch (strings[0]) {
case "config" -> config.get(strings[1]);
default -> locale.get(strings[1]);
};

if(param == null) break;
if(param instanceof Boolean) {
isStartsWith(strings[4], "true");
isStartsWith(strings[4], "false");
break;
}

isStartsWith(strings[4], String.valueOf(param));
}
}

Collections.sort(wordsList);
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/net/flectone/commands/CommandMaintenance.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package net.flectone.commands;

import net.flectone.integrations.discordsrv.FDiscordSRV;
import net.flectone.managers.HookManager;
import net.flectone.misc.commands.FCommand;
import net.flectone.misc.commands.FTabCompleter;
import org.bukkit.Bukkit;
Expand All @@ -14,8 +15,8 @@
import java.util.List;
import java.util.Set;

import static net.flectone.managers.FileManager.locale;
import static net.flectone.managers.FileManager.config;
import static net.flectone.managers.FileManager.locale;

public class CommandMaintenance implements FTabCompleter {

Expand Down Expand Up @@ -60,7 +61,7 @@ public boolean onCommand(@NotNull CommandSender commandSender, @NotNull Command

String maintenanceMessage = "command.maintenance.turned-" + strings[0].toLowerCase() + ".message";

if (FDiscordSRV.isEnable()) {
if (HookManager.enabledDiscordSRV) {
FDiscordSRV.sendModerationMessage(locale.getString(maintenanceMessage));
}

Expand Down
5 changes: 3 additions & 2 deletions src/main/java/net/flectone/commands/CommandMute.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import net.flectone.integrations.discordsrv.FDiscordSRV;
import net.flectone.integrations.voicechats.plasmovoice.FPlasmoVoice;
import net.flectone.managers.FPlayerManager;
import net.flectone.managers.HookManager;
import net.flectone.misc.commands.FCommand;
import net.flectone.misc.commands.FTabCompleter;
import net.flectone.misc.entity.FPlayer;
Expand Down Expand Up @@ -68,7 +69,7 @@ public boolean onCommand(@NotNull CommandSender commandSender, @NotNull Command

boolean announceModeration = config.getBoolean("command.mute.announce");

if (announceModeration && FDiscordSRV.isEnable()) FDiscordSRV.sendModerationMessage(formatString);
if (announceModeration && HookManager.enabledDiscordSRV) FDiscordSRV.sendModerationMessage(formatString);

Set<Player> receivers = announceModeration
? new HashSet<>(Bukkit.getOnlinePlayers())
Expand All @@ -78,7 +79,7 @@ public boolean onCommand(@NotNull CommandSender commandSender, @NotNull Command

fCommand.sendGlobalMessage(receivers, formatString, false);

if (FPlasmoVoice.isEnable()) {
if (HookManager.enabledPlasmoVoice) {
FPlasmoVoice.mute(mutedFPlayer.isMuted(), mutedFPlayer.getRealName(), strings[1], reason);
}

Expand Down
3 changes: 2 additions & 1 deletion src/main/java/net/flectone/commands/CommandStream.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package net.flectone.commands;

import net.flectone.integrations.discordsrv.FDiscordSRV;
import net.flectone.managers.HookManager;
import net.flectone.misc.commands.FCommand;
import net.flectone.misc.commands.FTabCompleter;
import net.flectone.utils.ObjectUtil;
Expand Down Expand Up @@ -68,7 +69,7 @@ public boolean onCommand(@NotNull CommandSender commandSender, @NotNull Command

});

if (FDiscordSRV.isEnable()) {
if (HookManager.enabledDiscordSRV) {
FDiscordSRV.sendModerationMessage(stringBuilder.toString());
}

Expand Down
5 changes: 3 additions & 2 deletions src/main/java/net/flectone/commands/CommandTempban.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import net.flectone.integrations.discordsrv.FDiscordSRV;
import net.flectone.managers.FPlayerManager;
import net.flectone.managers.HookManager;
import net.flectone.misc.commands.FCommand;
import net.flectone.misc.commands.FTabCompleter;
import net.flectone.misc.entity.FPlayer;
Expand All @@ -20,8 +21,8 @@
import java.util.Set;
import java.util.stream.Collectors;

import static net.flectone.managers.FileManager.locale;
import static net.flectone.managers.FileManager.config;
import static net.flectone.managers.FileManager.locale;

public class CommandTempban implements FTabCompleter {

Expand Down Expand Up @@ -68,7 +69,7 @@ public boolean onCommand(@NotNull CommandSender commandSender, @NotNull Command

boolean announceModeration = config.getBoolean("command.tempban.announce");

if (announceModeration && FDiscordSRV.isEnable()) FDiscordSRV.sendModerationMessage(globalMessage);
if (announceModeration && HookManager.enabledDiscordSRV) FDiscordSRV.sendModerationMessage(globalMessage);

Set<Player> receivers = announceModeration
? new HashSet<>(Bukkit.getOnlinePlayers())
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/net/flectone/commands/CommandUnmute.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import net.flectone.integrations.voicechats.plasmovoice.FPlasmoVoice;
import net.flectone.managers.FPlayerManager;
import net.flectone.managers.HookManager;
import net.flectone.misc.commands.FCommand;
import net.flectone.misc.commands.FTabCompleter;
import net.flectone.misc.entity.FPlayer;
Expand Down Expand Up @@ -36,7 +37,7 @@ public boolean onCommand(@NotNull CommandSender commandSender, @NotNull Command

if (fCommand.isHaveCD()) return true;

if (FPlasmoVoice.isEnable()) {
if (HookManager.enabledPlasmoVoice) {
FPlasmoVoice.unmute(fPlayer.getRealName());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import github.scarsz.discordsrv.util.TimeUtil;
import net.flectone.Main;
import net.flectone.integrations.HookInterface;
import net.flectone.managers.HookManager;
import net.flectone.misc.advancement.FAdvancement;
import net.flectone.utils.ObjectUtil;
import org.apache.commons.lang.StringUtils;
Expand Down Expand Up @@ -58,8 +59,6 @@ License, or (at your option) any later version.

public class FDiscordSRV implements Listener, HookInterface {

private static boolean isEnable = false;

public static void sendDeathMessage(@NotNull Player player, @NotNull String message, @Nullable Entity finalEntity, @Nullable Material finalBlock, @Nullable Entity killer, @Nullable ItemStack killerItem) {
message = message.replace("<player>", player.getName());
if (finalEntity != null) message = message
Expand Down Expand Up @@ -217,14 +216,10 @@ public void onChatMessageFromInGame(@NotNull GameChatMessagePreProcessEvent even
event.setMessage(message);
}

public static boolean isEnable() {
return isEnable;
}

@Override
public void hook() {
DiscordSRV.api.subscribe(this);
isEnable = true;
HookManager.enabledDiscordSRV = true;
Main.info("\uD83D\uDD12 DiscordSRV detected and hooked");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import net.flectone.Main;
import net.flectone.integrations.HookInterface;
import net.flectone.managers.FPlayerManager;
import net.flectone.managers.HookManager;
import net.flectone.misc.entity.FPlayer;
import net.flectone.utils.ObjectUtil;
import org.bukkit.OfflinePlayer;
Expand All @@ -12,12 +13,6 @@

public class FPlaceholderAPI extends PlaceholderExpansion implements HookInterface {

private static boolean isEnable;

public static boolean isEnable() {
return isEnable;
}

@Override
public @NotNull String getIdentifier() {
return "FlectoneChat";
Expand Down Expand Up @@ -59,7 +54,7 @@ public String onRequest(@Nullable OfflinePlayer player, @NotNull String params)
@Override
public void hook() {
register();
isEnable = true;
HookManager.enabledPlaceholderAPI = true;
Main.info("\uD83D\uDD12 PlaceholderAPI detected and hooked");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,21 @@
import com.loohp.interactivechat.api.InteractiveChatAPI;
import net.flectone.Main;
import net.flectone.integrations.HookInterface;
import net.flectone.managers.HookManager;
import org.jetbrains.annotations.NotNull;

import java.util.UUID;

public class FInteractiveChat implements HookInterface {

private static boolean isEnable;

public static boolean isEnable() {
return isEnable;
}

@NotNull
public static String mark(@NotNull String message, @NotNull UUID sender) {
return InteractiveChatAPI.markSender(message, sender);
}

@Override
public void hook() {
isEnable = true;
HookManager.enabledInteractiveChat = true;
Main.info("\uD83D\uDD12 InteractiveChat detected and hooked");
}
}
9 changes: 2 additions & 7 deletions src/main/java/net/flectone/integrations/vault/FVault.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,20 @@

import net.flectone.Main;
import net.flectone.integrations.HookInterface;
import net.flectone.managers.HookManager;
import net.milkbowl.vault.chat.Chat;
import org.bukkit.plugin.RegisteredServiceProvider;
import org.jetbrains.annotations.NotNull;

public class FVault implements HookInterface {

private static boolean isEnable = false;

private static Chat provider;

@NotNull
public static Chat getProvider() {
return provider;
}

public static boolean isEnable() {
return isEnable;
}

@Override
public void hook() {
RegisteredServiceProvider<Chat> chatProvider = Main.getInstance().getServer().getServicesManager()
Expand All @@ -32,7 +27,7 @@ public void hook() {
}

provider = chatProvider.getProvider();
isEnable = true;
HookManager.enabledVault = true;

Main.info("\uD83D\uDD12 Vault detected and hooked");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import net.flectone.Main;
import net.flectone.integrations.HookInterface;
import net.flectone.managers.HookManager;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandException;
import org.jetbrains.annotations.NotNull;
Expand All @@ -17,8 +18,6 @@

public class FPlasmoVoice implements HookInterface {

private static boolean isEnable;

public static void mute(boolean unmute, @NotNull String player, @NotNull String time, @NotNull String reason) {
if (unmute) unmute(player);
executeCommand("vmute " + player + " " + time + " " + reason);
Expand All @@ -36,13 +35,9 @@ private static void executeCommand(@NotNull String command) {
}
}

public static boolean isEnable() {
return isEnable;
}

@Override
public void hook() {
isEnable = true;
HookManager.enabledPlasmoVoice = true;
Main.info("\uD83D\uDD12 PlasmoVoice detected and hooked");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import net.flectone.integrations.discordsrv.FDiscordSRV;
import net.flectone.integrations.supervanish.FSuperVanish;
import net.flectone.managers.FPlayerManager;
import net.flectone.managers.HookManager;
import net.flectone.misc.advancement.FAdvancement;
import net.flectone.misc.advancement.FAdvancementType;
import net.flectone.misc.components.FAdvancementComponent;
Expand Down Expand Up @@ -78,7 +79,7 @@ public void onPlayerAdvancementDone(@NotNull PlayerAdvancementDoneEvent event) {
String formatMessage = locale.getString("advancement." + fAdvancementType + ".name");
ArrayList<String> placeholders = new ArrayList<>(List.of("<player>", "<advancement>"));

if (FDiscordSRV.isEnable()) {
if (HookManager.enabledDiscordSRV) {
FDiscordSRV.sendAdvancementMessage(player, fAdvancement, formatMessage);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import net.flectone.integrations.discordsrv.FDiscordSRV;
import net.flectone.integrations.supervanish.FSuperVanish;
import net.flectone.managers.FPlayerManager;
import net.flectone.managers.HookManager;
import net.flectone.misc.components.FDeathComponent;
import net.flectone.misc.entity.FDamager;
import net.flectone.misc.entity.FPlayer;
Expand Down Expand Up @@ -192,7 +193,7 @@ public void onPlayerDeathEvent(@NotNull PlayerDeathEvent event) {
recipient.spigot().sendMessage(new FDeathComponent(finalPlaceholders, recipient, player, fDamager).get());
});

if(FDiscordSRV.isEnable()) {
if(HookManager.enabledDiscordSRV) {
FDiscordSRV.sendDeathMessage(player,
formatMessage,
fDamager.getFinalEntity(),
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/net/flectone/managers/FPlayerManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public static FPlayer addPlayer(@NotNull Player player) {
public static FPlayer getPlayerFromName(@NotNull String name) {
return fPlayerHashMap.values()
.parallelStream()
.filter(fPlayer -> fPlayer.getRealName().equals(name))
.filter(fPlayer -> fPlayer != null && fPlayer.getRealName().equals(name))
.findFirst().orElse(null);
}

Expand Down
6 changes: 6 additions & 0 deletions src/main/java/net/flectone/managers/HookManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@

public class HookManager {

public static boolean enabledDiscordSRV = false;
public static boolean enabledInteractiveChat = false;
public static boolean enabledPlaceholderAPI = false;
public static boolean enabledPlasmoVoice = false;
public static boolean enabledVault = false;

public static void hookPlugins() {
if (isEnabled("DiscordSRV")) new FDiscordSRV().hook();
if (isEnabled("PlaceholderAPI")) new FPlaceholderAPI().hook();
Expand Down
7 changes: 4 additions & 3 deletions src/main/java/net/flectone/misc/commands/FCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import net.flectone.commands.CommandAfk;
import net.flectone.integrations.interactivechat.FInteractiveChat;
import net.flectone.managers.FPlayerManager;
import net.flectone.managers.HookManager;
import net.flectone.messages.MessageBuilder;
import net.flectone.misc.entity.FPlayer;
import net.flectone.utils.ObjectUtil;
Expand Down Expand Up @@ -192,7 +193,7 @@ public void sendGlobalMessage(@NotNull Set<Player> recipientsSet, @NotNull Strin

Bukkit.getConsoleSender().sendMessage(ObjectUtil.formatString(format, null).replace("<message>", message));

if (FInteractiveChat.isEnable()) {
if (HookManager.enabledInteractiveChat) {
message = FInteractiveChat.mark(message, player.getUniqueId());
}

Expand All @@ -208,7 +209,7 @@ public void sendGlobalMessage(@NotNull Set<Player> recipientsSet, @NotNull Strin
String bubbleMessage = messageBuilder.getMessage();

if (command.contains("chat") && getFPlayer() != null) {
if (FInteractiveChat.isEnable()) {
if (HookManager.enabledInteractiveChat) {
bubbleMessage = bubbleMessage.replaceAll("(<chat=.*>)", "[]");
}

Expand Down Expand Up @@ -271,7 +272,7 @@ public void sendTellMessage(@NotNull CommandSender firstPlayer, @NotNull Command

ItemStack itemStack = firstPlayer instanceof Player ? ((Player) firstPlayer).getInventory().getItemInMainHand() : null;

if (FInteractiveChat.isEnable()) {
if (HookManager.enabledInteractiveChat) {
message = FInteractiveChat.mark(message, player.getUniqueId());
}

Expand Down

0 comments on commit 9f1e48e

Please sign in to comment.