mirror of
https://github.com/AtlasMediaGroup/TotalFreedomMod.git
synced 2025-07-01 12:36:41 +00:00
Compare commits
2 Commits
RELEASE-20
...
dependabot
Author | SHA1 | Date | |
---|---|---|---|
3548daa3e5 | |||
fc796bd340 |
2
.github/workflows/codacy-analysis.yml
vendored
2
.github/workflows/codacy-analysis.yml
vendored
@ -25,7 +25,7 @@ jobs:
|
||||
|
||||
# Execute Codacy Analysis CLI and generate a SARIF output with the security issues identified during the analysis
|
||||
- name: Run Codacy Analysis CLI
|
||||
uses: codacy/codacy-analysis-cli-action@v4.2.0
|
||||
uses: codacy/codacy-analysis-cli-action@v4.1.0
|
||||
with:
|
||||
# Check https://github.com/codacy/codacy-analysis-cli#project-token to get your project token from your Codacy repository
|
||||
# You can also omit the token and run the tools that support default configurations
|
||||
|
2
.github/workflows/codeql-analysis.yml
vendored
2
.github/workflows/codeql-analysis.yml
vendored
@ -38,7 +38,7 @@ jobs:
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- name: Setup Java JDK
|
||||
uses: actions/setup-java@v3.9.0
|
||||
uses: actions/setup-java@v3.6.0
|
||||
with:
|
||||
# The Java version to make available on the path. Takes a whole or semver Java version, or 1.x syntax (e.g. 1.8 => Java 8.x). Early access versions can be specified in the form of e.g. 14-ea, 14.0.0-ea, or 14.0.0-ea.28
|
||||
java-version: 17
|
||||
|
2
.github/workflows/java17-maven.yml
vendored
2
.github/workflows/java17-maven.yml
vendored
@ -13,7 +13,7 @@ jobs:
|
||||
|
||||
# Java 16 Builds
|
||||
- name: Set up JDK 17
|
||||
uses: actions/setup-java@v3.9.0
|
||||
uses: actions/setup-java@v3.6.0
|
||||
with:
|
||||
java-version: 17
|
||||
distribution: 'adopt'
|
||||
|
2
.gitignore
vendored
2
.gitignore
vendored
@ -29,7 +29,7 @@ manifest.mf
|
||||
*.iml
|
||||
|
||||
# Maven excludes
|
||||
target/
|
||||
/target
|
||||
|
||||
# OS generated files
|
||||
.DS_Store
|
||||
|
250
commons/pom.xml
250
commons/pom.xml
@ -1,250 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>me.totalfreedom</groupId>
|
||||
<artifactId>TotalFreedomMod</artifactId>
|
||||
<version>2023.03</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>commons</artifactId>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>17</maven.compiler.source>
|
||||
<maven.compiler.target>17</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>commons-io</groupId>
|
||||
<artifactId>commons-io</artifactId>
|
||||
<version>2.11.0</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>io.papermc</groupId>
|
||||
<artifactId>paperlib</artifactId>
|
||||
<version>1.0.7</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-lang3</artifactId>
|
||||
<version>3.12.0</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>net.luckperms</groupId>
|
||||
<artifactId>api</artifactId>
|
||||
<version>5.4</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.bstats</groupId>
|
||||
<artifactId>bstats-bukkit</artifactId>
|
||||
<version>3.0.1</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.reflections</groupId>
|
||||
<artifactId>reflections</artifactId>
|
||||
<version>0.10.2</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.eclipse.sisu</groupId>
|
||||
<artifactId>org.eclipse.sisu.inject</artifactId>
|
||||
<version>0.3.5</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
|
||||
<build>
|
||||
<!-- Filter resources for build.properties -->
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>src/main/resources</directory>
|
||||
<filtering>true</filtering>
|
||||
</resource>
|
||||
</resources>
|
||||
|
||||
<plugins>
|
||||
<!-- Compiler -->
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.10.1</version>
|
||||
<configuration>
|
||||
<outputFileName>TotalFreedomMod.jar</outputFileName>
|
||||
<compilerVersion>17</compilerVersion>
|
||||
<source>17</source>
|
||||
<target>17</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
<!-- Git describe -->
|
||||
<plugin>
|
||||
<groupId>pl.project13.maven</groupId>
|
||||
<artifactId>git-commit-id-plugin</artifactId>
|
||||
<version>4.9.10</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>get-the-git-infos</id>
|
||||
<goals>
|
||||
<goal>revision</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
<execution>
|
||||
<id>validate-the-git-infos</id>
|
||||
<goals>
|
||||
<goal>validateRevision</goal>
|
||||
</goals>
|
||||
<phase>package</phase>
|
||||
</execution>
|
||||
</executions>
|
||||
<configuration>
|
||||
<dotGitDirectory>${project.basedir}/.git</dotGitDirectory>
|
||||
<prefix>git</prefix>
|
||||
<dateFormat>yyyy-MM-dd HH:mm:ss</dateFormat>
|
||||
<verbose>false</verbose>
|
||||
<format>properties</format>
|
||||
<failOnNoGitDirectory>false</failOnNoGitDirectory>
|
||||
<failOnUnableToExtractRepoInfo>false</failOnUnableToExtractRepoInfo>
|
||||
<includeOnlyProperties>
|
||||
<includeOnlyProperty>git.commit.id.abbrev</includeOnlyProperty>
|
||||
</includeOnlyProperties>
|
||||
<gitDescribe>
|
||||
<skip>false</skip>
|
||||
<always>false</always>
|
||||
<abbrev>7</abbrev>
|
||||
<dirty>-dirty</dirty>
|
||||
<match>*</match>
|
||||
</gitDescribe>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
<!-- Antrun -->
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-antrun-plugin</artifactId>
|
||||
<version>3.1.0</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>default-cli</id>
|
||||
<phase>initialize</phase>
|
||||
<configuration>
|
||||
<target>
|
||||
<propertyfile file="${project.basedir}/src/main/resources/build.properties"
|
||||
comment="Build information. Edit this to your liking.">
|
||||
<entry key="buildAuthor" default="unknown"/>
|
||||
<entry key="buildNumber" default="0"/>
|
||||
<entry key="buildCodeName" value="${tfm.build.codename}"/>
|
||||
<entry key="buildVersion" value="${project.version}"/>
|
||||
<entry key="buildDate" value="${timestamp}"/>
|
||||
<!--suppress UnresolvedMavenProperty -->
|
||||
<entry key="buildHead" value="${git.commit.id.abbrev}"/>
|
||||
</propertyfile>
|
||||
</target>
|
||||
</configuration>
|
||||
<goals>
|
||||
<goal>run</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
|
||||
<!-- Properties -->
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>properties-maven-plugin</artifactId>
|
||||
<version>1.1.0</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>initialize</phase>
|
||||
<goals>
|
||||
<goal>read-project-properties</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<files>
|
||||
<file>${project.basedir}/src/main/resources/build.properties</file>
|
||||
</files>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
|
||||
<!-- Buildnumber -->
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>buildnumber-maven-plugin</artifactId>
|
||||
<version>3.0.0</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>generate-resources</phase>
|
||||
<goals>
|
||||
<goal>create</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
|
||||
<configuration>
|
||||
<buildNumberPropertyName>maven.buildnumber</buildNumberPropertyName>
|
||||
<buildNumberPropertiesFileLocation>${project.basedir}/src/main/resources/build.properties
|
||||
</buildNumberPropertiesFileLocation>
|
||||
<format>{0,number,#}</format>
|
||||
<items>
|
||||
<item>buildNumber</item>
|
||||
</items>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
<!-- Shade -->
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
<version>3.3.0</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>shade</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<minimizeJar>true</minimizeJar>
|
||||
<relocations>
|
||||
<relocation>
|
||||
<pattern>io.papermc.lib</pattern>
|
||||
<shadedPattern>me.totalfreedom.totalfreedommod.paperlib
|
||||
</shadedPattern> <!-- Replace this -->
|
||||
</relocation>
|
||||
<relocation>
|
||||
<pattern>org.bstats</pattern>
|
||||
<shadedPattern>me.totalfreedom.totalfreedommod</shadedPattern>
|
||||
</relocation>
|
||||
</relocations>
|
||||
<artifactSet>
|
||||
<includes>
|
||||
<include>org.reflections:reflections</include>
|
||||
<include>io.papermc:paperlib</include>
|
||||
<include>org.bstats:bstats-bukkit</include>
|
||||
<include>org.bstats:bstats-base</include>
|
||||
</includes>
|
||||
</artifactSet>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
@ -1,229 +0,0 @@
|
||||
package me.totalfreedom.totalfreedommod;
|
||||
|
||||
import com.google.common.base.Strings;
|
||||
import io.papermc.paper.event.player.AsyncChatEvent;
|
||||
import me.totalfreedom.totalfreedommod.admin.Admin;
|
||||
import me.totalfreedom.totalfreedommod.api.event.AdminChatEvent;
|
||||
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
|
||||
import me.totalfreedom.totalfreedommod.player.FPlayer;
|
||||
import me.totalfreedom.totalfreedommod.rank.Displayable;
|
||||
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||
import net.kyori.adventure.key.Key;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.TextComponent;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import net.kyori.adventure.text.format.TextColor;
|
||||
import net.kyori.adventure.text.minimessage.tag.Tag;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.SoundCategory;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
public class ChatManager extends FreedomService
|
||||
{
|
||||
@Override
|
||||
public void onStart()
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStop()
|
||||
{
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
||||
public void onPlayerChat(AsyncChatEvent event)
|
||||
{
|
||||
// Important information for later down the line
|
||||
String steamrolled = FUtil.steamroll(event.originalMessage());
|
||||
Player player = event.getPlayer();
|
||||
FPlayer fPlayer = plugin.pl.getPlayer(player);
|
||||
|
||||
// Chat is disabled
|
||||
if (!ConfigEntry.TOGGLE_CHAT.getBoolean() && !plugin.al.isAdmin(player))
|
||||
{
|
||||
event.getPlayer().sendMessage(FUtil.miniMessage("<red>The chat is currently disabled."));
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
// Locked up
|
||||
else if (fPlayer.isLockedUp())
|
||||
{
|
||||
event.getPlayer().sendMessage(FUtil.miniMessage("<red>You are locked up and thus can't talk."));
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
// Admin chat is enabled
|
||||
else if (fPlayer.inAdminChat())
|
||||
{
|
||||
adminChat(player, steamrolled, true);
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
// The event was already cancelled elsewhere or the player was muted
|
||||
else if (event.isCancelled() || fPlayer.isMuted())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Splitter
|
||||
Component splitter = Component.text("»", NamedTextColor.DARK_GRAY);
|
||||
|
||||
// Message
|
||||
TextComponent.Builder message = Component.text();
|
||||
|
||||
// Truncate the message if it's too long
|
||||
if (steamrolled.length() > 256)
|
||||
{
|
||||
steamrolled = steamrolled.substring(0, 256);
|
||||
}
|
||||
|
||||
// Did this because sonarlint was complaining about doing the unboxing in the if statement.
|
||||
// Something about returning null because it was boxed... I'm not sure.
|
||||
boolean unboxed = ConfigEntry.FOURCHAN_ENABLED.getBoolean();
|
||||
|
||||
// Chat colorization
|
||||
// -- 4chan mode --
|
||||
if (steamrolled.startsWith("> ") && unboxed)
|
||||
{
|
||||
message.append(Component.text(steamrolled, NamedTextColor.GREEN));
|
||||
}
|
||||
// -- Legacy chat colors --
|
||||
else if (FUtil.containsChatColor(steamrolled))
|
||||
{
|
||||
message.append(FUtil.colorizeAsComponent(steamrolled.replace("&k", "")));
|
||||
}
|
||||
// -- MiniMessage --
|
||||
else
|
||||
{
|
||||
message.append(FUtil.miniMessage(steamrolled));
|
||||
}
|
||||
|
||||
// This simply filters out shit like &k in a simple but stupid way.
|
||||
Component filtered = FUtil.miniMessage(FUtil.miniMessage(message.build()));
|
||||
|
||||
// Pinging
|
||||
String steamrolledFiltered = FUtil.steamroll(filtered);
|
||||
Arrays.stream(steamrolledFiltered.split(" ")).filter(string -> string.startsWith("@")).forEach(possiblePlayer ->
|
||||
{
|
||||
Player potential = server.getPlayer(possiblePlayer.replace("@", ""));
|
||||
|
||||
// Ping only that particular player
|
||||
if (potential != null)
|
||||
{
|
||||
ping(potential);
|
||||
}
|
||||
// Ping everyone (if the person pinging is an admin)
|
||||
else if (possiblePlayer.equalsIgnoreCase("@everyone") && plugin.al.isAdmin(player))
|
||||
{
|
||||
server.getOnlinePlayers().forEach(this::ping);
|
||||
}
|
||||
});
|
||||
|
||||
event.message(filtered);
|
||||
|
||||
event.renderer((source, displayName, msg, viewer) -> FUtil.miniMessage("<tag><nickname> <splitter> <message>",
|
||||
Placeholder.component("tag", plugin.pl.getPlayer(source).getTag().append(Component.space())),
|
||||
Placeholder.component("nickname", displayName),
|
||||
Placeholder.component("splitter", splitter),
|
||||
Placeholder.component("message", msg)));
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onAdminChat(AdminChatEvent event)
|
||||
{
|
||||
Displayable display = event.getDisplayable();
|
||||
String flatAbv = FUtil.miniMessage(display.getAbbr());
|
||||
|
||||
Component defaultFormat = FUtil.miniMessage("<prefix><dark_gray>[<aqua>ADMIN<dark_gray>] <dark_red><name> <dark_gray>[<rankcolor><rank></rankcolor>]</dark_gray><white>: <gold><message>",
|
||||
Placeholder.component("prefix", event.getPrefix()),
|
||||
Placeholder.component("name", event.getName()),
|
||||
Placeholder.unparsed("rank", flatAbv),
|
||||
TagResolver.resolver("rankcolor", Tag.styling(getColor(display))),
|
||||
Placeholder.component("message", event.getMessage()));
|
||||
|
||||
plugin.getComponentLogger().info(defaultFormat);
|
||||
;
|
||||
server.getOnlinePlayers().stream().filter(player -> plugin.al.isAdmin(player)).forEach(player ->
|
||||
{
|
||||
Admin admin = plugin.al.getAdmin(player);
|
||||
if (!Strings.isNullOrEmpty(admin.getAcFormat()))
|
||||
{
|
||||
String format = admin.getAcFormat();
|
||||
|
||||
player.sendMessage(FUtil.miniMessage(format,
|
||||
Placeholder.component("prefix", event.getPrefix()),
|
||||
Placeholder.component("name", event.getName()),
|
||||
Placeholder.unparsed("rank", flatAbv),
|
||||
TagResolver.resolver("rankcolor", Tag.styling(getColor(display))),
|
||||
Placeholder.component("message", event.getMessage())));
|
||||
}
|
||||
else
|
||||
{
|
||||
player.sendMessage(defaultFormat);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public TextColor getColor(Displayable display)
|
||||
{
|
||||
return display.getColor();
|
||||
}
|
||||
|
||||
public void adminChat(Component name, Displayable displayable, Component message, boolean async)
|
||||
{
|
||||
AdminChatEvent event = new AdminChatEvent(name, displayable, message, async);
|
||||
event.callEvent();
|
||||
}
|
||||
|
||||
public void adminChat(Key key, Component prefix, Component name, Displayable displayable, Component message, boolean async)
|
||||
{
|
||||
AdminChatEvent event = new AdminChatEvent(key, prefix, name, displayable, message, async);
|
||||
event.callEvent();
|
||||
}
|
||||
|
||||
public void adminChat(CommandSender sender, String message)
|
||||
{
|
||||
adminChat(sender, message, false);
|
||||
}
|
||||
|
||||
public void adminChat(CommandSender sender, String message, boolean async)
|
||||
{
|
||||
Displayable display = plugin.rm.getDisplay(sender);
|
||||
adminChat(Component.text(sender.getName()), display, Component.text(message), async);
|
||||
}
|
||||
|
||||
public void reportAction(Player reporter, String reportedName, String report)
|
||||
{
|
||||
messageAllAdmins("<red>[REPORTS]</red> <gold><reporter> has reported <reported> for <reason>.",
|
||||
Placeholder.unparsed("reporter", reporter.getName()),
|
||||
Placeholder.unparsed("reported", reportedName),
|
||||
Placeholder.unparsed("reason", report));
|
||||
}
|
||||
|
||||
public void messageAllAdmins(String message, TagResolver... placeholders)
|
||||
{
|
||||
Component parsed = FUtil.miniMessage(message, placeholders);
|
||||
plugin.getComponentLogger().info(parsed);
|
||||
server.getOnlinePlayers().stream().filter(player -> plugin.al.isAdmin(player)).forEach(player ->
|
||||
player.sendMessage(parsed));
|
||||
}
|
||||
|
||||
public void broadcastSplit(String forAdmins, String forOperators, TagResolver... placeholders)
|
||||
{
|
||||
messageAllAdmins(forAdmins, placeholders);
|
||||
server.getOnlinePlayers().stream().filter(player -> !plugin.al.isAdmin(player)).forEach(player ->
|
||||
player.sendMessage(FUtil.miniMessage(forOperators, placeholders)));
|
||||
}
|
||||
|
||||
public void ping(Player player)
|
||||
{
|
||||
player.playSound(player.getLocation(), Sound.BLOCK_NOTE_BLOCK_PLING, SoundCategory.MASTER, 1337F, 0.9F);
|
||||
}
|
||||
}
|
@ -1,29 +0,0 @@
|
||||
package me.totalfreedom.totalfreedommod;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
||||
|
||||
public class CommandSpy extends FreedomService
|
||||
{
|
||||
@Override
|
||||
public void onStart()
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStop()
|
||||
{
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event)
|
||||
{
|
||||
server.getOnlinePlayers().stream().filter(player -> plugin.al.isAdmin(player)
|
||||
&& plugin.al.getAdmin(player).getCommandSpy() && player != event.getPlayer()).forEach(player ->
|
||||
player.sendMessage(Component.text(event.getPlayer().getName()).append(Component.text(": "))
|
||||
.append(Component.text(event.getMessage())).color(NamedTextColor.GRAY)));
|
||||
}
|
||||
}
|
@ -1,70 +0,0 @@
|
||||
package me.totalfreedom.totalfreedommod;
|
||||
|
||||
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
public class VanishHandler extends FreedomService
|
||||
{
|
||||
@Override
|
||||
public void onStart()
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStop()
|
||||
{
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH)
|
||||
public void onPlayerJoin(PlayerJoinEvent event)
|
||||
{
|
||||
Player player = event.getPlayer();
|
||||
|
||||
server.getOnlinePlayers().stream().filter(pl -> !plugin.al.isAdmin(player)
|
||||
&& plugin.al.isVanished(pl.getUniqueId())).forEach(pl -> player.hidePlayer(plugin, pl));
|
||||
|
||||
server.getOnlinePlayers().stream().filter(pl -> !plugin.al.isAdmin(pl)
|
||||
&& plugin.al.isVanished(player.getUniqueId())).forEach(pl -> pl.hidePlayer(plugin, player));
|
||||
|
||||
if (plugin.al.isVanished(player.getUniqueId()))
|
||||
{
|
||||
plugin.esb.setVanished(player.getName(), true);
|
||||
plugin.cm.messageAllAdmins("<yellow><player> has joined silently.", Placeholder.unparsed("player", player.getName()));
|
||||
event.joinMessage(null);
|
||||
|
||||
new BukkitRunnable()
|
||||
{
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
if (plugin.al.isVanished(player.getUniqueId()))
|
||||
{
|
||||
player.sendActionBar(FUtil.miniMessage("<gold>You are hidden from other players."));
|
||||
}
|
||||
else
|
||||
{
|
||||
this.cancel();
|
||||
}
|
||||
}
|
||||
}.runTaskTimer(plugin, 0L, 4L);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerLeave(PlayerQuitEvent event)
|
||||
{
|
||||
Player player = event.getPlayer();
|
||||
|
||||
if (plugin.al.isVanished(player.getUniqueId()))
|
||||
{
|
||||
event.quitMessage(null);
|
||||
plugin.cm.messageAllAdmins("<yellow><player> has left silently.", Placeholder.unparsed("player", player.getName()));
|
||||
}
|
||||
}
|
||||
}
|
@ -1,27 +0,0 @@
|
||||
package me.totalfreedom.totalfreedommod.api;
|
||||
|
||||
public class Aggregator
|
||||
{
|
||||
private Context<TFD4JCommons> discord;
|
||||
private Context<ShoppeCommons> shoppe;
|
||||
|
||||
public Context<TFD4JCommons> getDiscordContext()
|
||||
{
|
||||
return discord;
|
||||
}
|
||||
|
||||
public void setDiscordContext(Context<TFD4JCommons> discord)
|
||||
{
|
||||
this.discord = discord;
|
||||
}
|
||||
|
||||
public Context<ShoppeCommons> getShoppeContext()
|
||||
{
|
||||
return shoppe;
|
||||
}
|
||||
|
||||
public void setShoppeContext(Context<ShoppeCommons> shoppe)
|
||||
{
|
||||
this.shoppe = shoppe;
|
||||
}
|
||||
}
|
@ -1,16 +0,0 @@
|
||||
package me.totalfreedom.totalfreedommod.api;
|
||||
|
||||
public class Context<T>
|
||||
{
|
||||
private final T value;
|
||||
|
||||
public Context(T value)
|
||||
{
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public T getValue()
|
||||
{
|
||||
return value;
|
||||
}
|
||||
}
|
@ -1,7 +0,0 @@
|
||||
package me.totalfreedom.totalfreedommod.api;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface Interpolator
|
||||
{
|
||||
double[] interpolate(double from, double to, int max);
|
||||
}
|
@ -1,55 +0,0 @@
|
||||
package me.totalfreedom.totalfreedommod.api;
|
||||
|
||||
import me.totalfreedom.totalfreedommod.player.PlayerData;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.PlayerInventory;
|
||||
|
||||
public interface ShoppeCommons
|
||||
{
|
||||
|
||||
int getCoinsPerReactionWin();
|
||||
|
||||
void startReactionTimer();
|
||||
|
||||
void forceStartReaction();
|
||||
|
||||
void startReaction();
|
||||
|
||||
void endReaction(String winner);
|
||||
|
||||
String getShopPrefix();
|
||||
|
||||
String getShopTitle();
|
||||
|
||||
Inventory generateShopGUI(PlayerData playerData);
|
||||
|
||||
Inventory generateLoginMessageGUI(Player player);
|
||||
|
||||
boolean isRealItem(PlayerData data, ShopItem shopItem, PlayerInventory inventory, ItemStack realItem);
|
||||
|
||||
boolean isRealItem(PlayerData data, ShopItem shopItem, ItemStack givenItem, ItemStack realItem);
|
||||
|
||||
ItemStack getLightningRod();
|
||||
|
||||
ItemStack getGrapplingHook();
|
||||
|
||||
ItemStack getFireBall();
|
||||
|
||||
ItemStack getRideablePearl();
|
||||
|
||||
ItemStack getStackingPotato();
|
||||
|
||||
ItemStack getClownFish();
|
||||
|
||||
boolean canAfford(int price, int coins);
|
||||
|
||||
int amountNeeded(int price, int coins);
|
||||
|
||||
ItemStack shopGUIItem(ShopItem item, PlayerData data);
|
||||
|
||||
ShopItem getShopItem(int slot);
|
||||
|
||||
String getReactionString();
|
||||
}
|
@ -1,33 +0,0 @@
|
||||
package me.totalfreedom.totalfreedommod.api;
|
||||
|
||||
import me.totalfreedom.totalfreedommod.admin.Admin;
|
||||
import me.totalfreedom.totalfreedommod.player.PlayerData;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public interface TFD4JCommons
|
||||
{
|
||||
void messageAdminChatChannel(String message);
|
||||
|
||||
void clearQueue();
|
||||
|
||||
void messageChatChannel(String message, boolean system);
|
||||
|
||||
boolean syncRoles(Admin admin, String id);
|
||||
|
||||
String getCode(PlayerData playerData);
|
||||
|
||||
String generateCode(int size);
|
||||
|
||||
Map<String, PlayerData> getLinkCodes();
|
||||
|
||||
String formatBotTag();
|
||||
|
||||
boolean sendReportOffline(Player reporter, OfflinePlayer reported, String reason);
|
||||
|
||||
boolean sendReport(Player reporter, Player reported, String reason);
|
||||
|
||||
boolean isEnabled();
|
||||
}
|
@ -1,74 +0,0 @@
|
||||
package me.totalfreedom.totalfreedommod.api.event;
|
||||
|
||||
import me.totalfreedom.totalfreedommod.rank.Displayable;
|
||||
import net.kyori.adventure.key.Key;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class AdminChatEvent extends Event
|
||||
{
|
||||
private static HandlerList handlerList = new HandlerList();
|
||||
//--
|
||||
private Key identifier;
|
||||
private Component prefix = Component.empty();
|
||||
private Component name;
|
||||
private Displayable displayable;
|
||||
private Component message;
|
||||
|
||||
public AdminChatEvent(Key identifier, Component prefix, Component name, Displayable rank, Component message, boolean async)
|
||||
{
|
||||
super(async);
|
||||
this.identifier = identifier;
|
||||
this.prefix = prefix;
|
||||
this.name = name;
|
||||
this.displayable = rank;
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
public AdminChatEvent(Component name, Displayable rank, Component message, boolean async)
|
||||
{
|
||||
super(async);
|
||||
this.identifier = Key.key("tfm", "default");
|
||||
this.name = name;
|
||||
this.displayable = rank;
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
public static HandlerList getHandlerList()
|
||||
{
|
||||
return handlerList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull HandlerList getHandlers()
|
||||
{
|
||||
return handlerList;
|
||||
}
|
||||
|
||||
public Key getIdentifier()
|
||||
{
|
||||
return identifier;
|
||||
}
|
||||
|
||||
public Component getPrefix()
|
||||
{
|
||||
return prefix;
|
||||
}
|
||||
|
||||
public Component getName()
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
||||
public Displayable getDisplayable()
|
||||
{
|
||||
return displayable;
|
||||
}
|
||||
|
||||
public Component getMessage()
|
||||
{
|
||||
return message;
|
||||
}
|
||||
}
|
@ -1,339 +0,0 @@
|
||||
package me.totalfreedom.totalfreedommod.bridge;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
import me.totalfreedom.totalfreedommod.FreedomService;
|
||||
import me.totalfreedom.totalfreedommod.util.FLog;
|
||||
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||
import net.coreprotect.CoreProtect;
|
||||
import net.coreprotect.CoreProtectAPI;
|
||||
import net.coreprotect.utility.Util;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.TextComponent;
|
||||
import net.kyori.adventure.text.event.ClickEvent;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import net.kyori.adventure.text.format.TextColor;
|
||||
import net.kyori.adventure.text.format.TextDecoration;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.block.Action;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
public class CoreProtectBridge extends FreedomService
|
||||
{
|
||||
//-- Block Inspector --//
|
||||
private static final Component name = Component.text("Block Inspector").color(TextColor.color(0x30ade4));
|
||||
private static final Component header = Component.text("---- ").append(name)
|
||||
.append(Component.text(" ---- ")).colorIfAbsent(NamedTextColor.WHITE);
|
||||
private static final Component prefix = name.append(Component.text(" - ").color(NamedTextColor.WHITE))
|
||||
.colorIfAbsent(NamedTextColor.WHITE);
|
||||
//--
|
||||
private final HashMap<UUID, Long> cooldownMap = new HashMap<>();
|
||||
private HashMap<UUID, FUtil.PaginationList<CoreProtectAPI.ParseResult>> historyMap;
|
||||
|
||||
//---------------------//
|
||||
private CoreProtectAPI coreProtectAPI = null;
|
||||
|
||||
public static Long getSecondsLeft(long prevTime, int timeAdd)
|
||||
{
|
||||
return prevTime / 1000L + timeAdd - System.currentTimeMillis() / 1000L;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStart()
|
||||
{
|
||||
if (isEnabled())
|
||||
{
|
||||
historyMap = new HashMap<>();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStop()
|
||||
{
|
||||
}
|
||||
|
||||
public CoreProtect getCoreProtect()
|
||||
{
|
||||
CoreProtect coreProtect = null;
|
||||
try
|
||||
{
|
||||
final Plugin coreProtectPlugin = server.getPluginManager().getPlugin("CoreProtect");
|
||||
assert coreProtectPlugin != null;
|
||||
if (coreProtectPlugin instanceof CoreProtect)
|
||||
{
|
||||
coreProtect = (CoreProtect)coreProtectPlugin;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
FLog.severe(ex);
|
||||
}
|
||||
return coreProtect;
|
||||
}
|
||||
|
||||
public CoreProtectAPI getCoreProtectAPI()
|
||||
{
|
||||
if (coreProtectAPI == null)
|
||||
{
|
||||
try
|
||||
{
|
||||
final CoreProtect coreProtect = getCoreProtect();
|
||||
|
||||
coreProtectAPI = coreProtect.getAPI();
|
||||
|
||||
// Check if the plugin or api is not enabled, if so, return null
|
||||
if (!coreProtect.isEnabled() || !coreProtectAPI.isEnabled())
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
FLog.severe(ex);
|
||||
}
|
||||
}
|
||||
|
||||
return coreProtectAPI;
|
||||
}
|
||||
|
||||
public boolean isEnabled()
|
||||
{
|
||||
if (!server.getPluginManager().isPluginEnabled("CoreProtect"))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
final CoreProtect coreProtect = getCoreProtect();
|
||||
|
||||
return coreProtect != null && coreProtect.isEnabled();
|
||||
}
|
||||
|
||||
// Rollback the specified player's edits that were in the last 24 hours.
|
||||
public void rollback(final String name)
|
||||
{
|
||||
if (!isEnabled())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
final CoreProtectAPI coreProtect = getCoreProtectAPI();
|
||||
|
||||
new BukkitRunnable()
|
||||
{
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
coreProtect.performRollback(86400, Collections.singletonList(name), null, null, null, null, 0, null);
|
||||
}
|
||||
}.runTaskAsynchronously(plugin);
|
||||
}
|
||||
|
||||
// Reverts a rollback for the specified player's edits that were in the last 24 hours.
|
||||
public void restore(final String name)
|
||||
{
|
||||
if (!isEnabled())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
final CoreProtectAPI coreProtect = getCoreProtectAPI();
|
||||
|
||||
new BukkitRunnable()
|
||||
{
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
coreProtect.performRestore(86400, Collections.singletonList(name), null, null, null, null, 0, null);
|
||||
}
|
||||
}.runTaskAsynchronously(plugin);
|
||||
}
|
||||
|
||||
public boolean hasHistory(Player player)
|
||||
{
|
||||
return historyMap.containsKey(player.getUniqueId());
|
||||
}
|
||||
|
||||
public FUtil.PaginationList<CoreProtectAPI.ParseResult> getHistoryForPlayer(Player player)
|
||||
{
|
||||
return historyMap.get(player.getUniqueId());
|
||||
}
|
||||
|
||||
// TODO: Complexity is O(19). This should be reduced.
|
||||
public void showPageToPlayer(Player player, FUtil.PaginationList<CoreProtectAPI.ParseResult> results, int pageNum)
|
||||
{
|
||||
if (player == null || !player.isOnline())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
List<CoreProtectAPI.ParseResult> page = results.getPage(pageNum);
|
||||
|
||||
if (page == null || page.isEmpty())
|
||||
{
|
||||
player.sendMessage(prefix.append(Component.text("No results were found.", NamedTextColor.WHITE)));
|
||||
}
|
||||
else
|
||||
{
|
||||
// This shouldn't change at all in any of the other entries, so this should be safe
|
||||
Component location = Component.text(String.format("(%s, %s, %s)", results.get(0).getX(),
|
||||
results.get(0).getY(), results.get(0).getZ()));
|
||||
final long time = System.currentTimeMillis() / 1000;
|
||||
|
||||
player.sendMessage(header.append(location.color(NamedTextColor.GRAY).decorate(TextDecoration.ITALIC)));
|
||||
page.forEach(entry ->
|
||||
{
|
||||
TextComponent.Builder line = Component.text();
|
||||
|
||||
// Time
|
||||
line.append(Component.text(Util.getTimeSince(entry.getTime(), time, false))
|
||||
.color(NamedTextColor.GRAY));
|
||||
|
||||
// Action
|
||||
Component action = Component.text(" interacted with ");
|
||||
Component symbol = Component.text(" - ", NamedTextColor.WHITE);
|
||||
switch (entry.getActionId())
|
||||
{
|
||||
case 0 ->
|
||||
{
|
||||
action = Component.text(" broke ");
|
||||
symbol = Component.text(" - ", NamedTextColor.RED);
|
||||
}
|
||||
case 1 ->
|
||||
{
|
||||
action = Component.text(" placed ");
|
||||
symbol = Component.text(" + ", NamedTextColor.GREEN);
|
||||
}
|
||||
case 2 -> action = Component.text(" clicked ");
|
||||
default ->
|
||||
{
|
||||
// Do nothing (shuts Codacy up)
|
||||
}
|
||||
}
|
||||
// Symbol, player, action, block
|
||||
line.append(symbol).append(Component.text(entry.getPlayer()).color(TextColor.color(0x30ade4)))
|
||||
.append(action.color(NamedTextColor.WHITE)).append(
|
||||
Component.text(entry.getBlockData().getMaterial().name().toLowerCase())
|
||||
.color(TextColor.color(0x30ade4)));
|
||||
|
||||
// Rolled back?
|
||||
if (entry.isRolledBack())
|
||||
{
|
||||
line.decorate(TextDecoration.STRIKETHROUGH);
|
||||
}
|
||||
|
||||
player.sendMessage(line.append(Component.text(".", NamedTextColor.WHITE)).build());
|
||||
});
|
||||
|
||||
if (results.getPageCount() > 1)
|
||||
{
|
||||
player.sendMessage(Component.text("-----", NamedTextColor.WHITE));
|
||||
|
||||
// Page indicator
|
||||
TextComponent.Builder indicator = Component.text();
|
||||
|
||||
// <-
|
||||
if (pageNum > 1)
|
||||
{
|
||||
indicator.append(Component.text("◀ ", NamedTextColor.WHITE).clickEvent(
|
||||
ClickEvent.runCommand("/ins history " + (pageNum - 1))));
|
||||
}
|
||||
|
||||
// Page <current>/<total>
|
||||
indicator.append(Component.text("Page ", TextColor.color(0x30ade4)).append(Component.text(pageNum + "/"
|
||||
+ results.getPageCount(), NamedTextColor.WHITE)));
|
||||
|
||||
// ->
|
||||
if (pageNum < results.getPageCount())
|
||||
{
|
||||
indicator.append(Component.text(" ▶", NamedTextColor.WHITE).clickEvent(
|
||||
ClickEvent.runCommand("/ins history " + (pageNum + 1))));
|
||||
}
|
||||
|
||||
// | Use /ins history <page> for advanced navigation
|
||||
indicator.append(Component.text(" | ", NamedTextColor.GRAY).append(Component.text("Use ", NamedTextColor.WHITE)
|
||||
.append(Component.text("/ins history <page>", TextColor.color(0x30ade4))
|
||||
.clickEvent(ClickEvent.suggestCommand("/ins history ")))
|
||||
.append(Component.text(" for advanced navigation", NamedTextColor.WHITE))));
|
||||
|
||||
player.sendMessage(indicator.build());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public CompletableFuture<FUtil.PaginationList<CoreProtectAPI.ParseResult>> lookupForPlayer(Block block, Player player)
|
||||
{
|
||||
cooldownMap.put(player.getUniqueId(), System.currentTimeMillis());
|
||||
CoreProtectAPI api = getCoreProtectAPI();
|
||||
|
||||
return CompletableFuture.supplyAsync(() ->
|
||||
{
|
||||
historyMap.remove(player.getUniqueId());
|
||||
FUtil.PaginationList<CoreProtectAPI.ParseResult> pages = new FUtil.PaginationList<>(10);
|
||||
api.blockLookup(block, -1).forEach(stringArray -> pages.add(api.parseResult(stringArray)));
|
||||
historyMap.put(player.getUniqueId(), pages);
|
||||
return pages;
|
||||
});
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void onInteract(PlayerInteractEvent event)
|
||||
{
|
||||
// The inspector only works if we have CoreProtect installed
|
||||
if (!isEnabled())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Player player = event.getPlayer();
|
||||
|
||||
if ((event.getAction() == Action.RIGHT_CLICK_BLOCK || event.getAction() == Action.LEFT_CLICK_BLOCK)
|
||||
&& plugin.pl.getData(player.getUniqueId()).hasInspection())
|
||||
{
|
||||
event.setCancelled(true);
|
||||
Block block = event.getClickedBlock();
|
||||
Optional<Long> cooldown = Optional.ofNullable(cooldownMap.get(player.getUniqueId()));
|
||||
|
||||
if (cooldown.isPresent() && getSecondsLeft(cooldown.get(), 3) > 0L)
|
||||
{
|
||||
player.sendMessage(prefix.append(Component.text("You need to wait ")
|
||||
.append(Component.text(getSecondsLeft(cooldown.get(), 3)))
|
||||
.append(Component.text(" seconds before you can make another query."))
|
||||
.color(NamedTextColor.WHITE)));
|
||||
return;
|
||||
}
|
||||
|
||||
// Time to do a look-up.
|
||||
if (block != null)
|
||||
{
|
||||
/* This is a hack to make it so that when you right-click, the coordinates that get used depend on
|
||||
* what's in your hand. Non-blocks use the block you clicked directly, but blocks use wherever the
|
||||
* block was supposed to be placed. */
|
||||
ItemStack hand = player.getInventory().getItemInMainHand();
|
||||
if (event.getAction() == Action.RIGHT_CLICK_BLOCK && hand.getType().isBlock() && hand.getType() != Material.AIR)
|
||||
{
|
||||
block = block.getRelative(event.getBlockFace()).getState().getBlock();
|
||||
}
|
||||
|
||||
lookupForPlayer(block, player).thenAccept(results ->
|
||||
{
|
||||
if (results.isEmpty())
|
||||
{
|
||||
player.sendMessage(prefix.append(Component.text("No results were found.").color(NamedTextColor.WHITE)));
|
||||
}
|
||||
else
|
||||
{
|
||||
showPageToPlayer(player, results, 1);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,59 +0,0 @@
|
||||
package me.totalfreedom.totalfreedommod.bridge;
|
||||
|
||||
import me.totalfreedom.totalfreedommod.rank.GroupProvider;
|
||||
import net.luckperms.api.LuckPerms;
|
||||
import net.luckperms.api.track.TrackManager;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||
import org.bukkit.plugin.UnknownDependencyException;
|
||||
|
||||
public class LuckPermsBridge
|
||||
{
|
||||
private final LuckPerms luckPerms;
|
||||
|
||||
public LuckPermsBridge()
|
||||
{
|
||||
RegisteredServiceProvider<LuckPerms> provider = Bukkit.getServicesManager()
|
||||
.getRegistration(LuckPerms.class);
|
||||
|
||||
if (provider == null) throw new UnknownDependencyException("LuckPerms must be present!");
|
||||
|
||||
this.luckPerms = provider.getProvider();
|
||||
|
||||
setupTracks();
|
||||
}
|
||||
|
||||
public LuckPerms getAPI()
|
||||
{
|
||||
return luckPerms;
|
||||
}
|
||||
|
||||
public void setupTracks()
|
||||
{
|
||||
TrackManager trackManager = getAPI().getTrackManager();
|
||||
|
||||
if (!trackManager.isLoaded("fakeOp"))
|
||||
{
|
||||
trackManager.createAndLoadTrack("fakeOp").whenComplete((track, exception) ->
|
||||
{
|
||||
track.appendGroup(GroupProvider.NON_OP.getGroup().getLuckPermsGroup());
|
||||
track.appendGroup(GroupProvider.OP.getGroup().getLuckPermsGroup());
|
||||
});
|
||||
}
|
||||
|
||||
if (!trackManager.isLoaded("admin"))
|
||||
{
|
||||
trackManager.createAndLoadTrack("admin").whenComplete((track, exception) ->
|
||||
{
|
||||
track.appendGroup(GroupProvider.ADMIN.getGroup().getLuckPermsGroup());
|
||||
track.appendGroup(GroupProvider.SENIOR_ADMIN.getGroup().getLuckPermsGroup());
|
||||
});
|
||||
}
|
||||
|
||||
if (!trackManager.isLoaded("builder"))
|
||||
{
|
||||
trackManager.createAndLoadTrack("builder").whenComplete((track, exception) ->
|
||||
track.appendGroup(GroupProvider.MASTER_BUILDER.getGroup().getLuckPermsGroup()));
|
||||
}
|
||||
}
|
||||
}
|
@ -1,10 +0,0 @@
|
||||
package me.totalfreedom.totalfreedommod.command;
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface CommandDependencies
|
||||
{
|
||||
String[] value();
|
||||
}
|
@ -1,43 +0,0 @@
|
||||
package me.totalfreedom.totalfreedommod.command;
|
||||
|
||||
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
@CommandPermissions(permission = "banlist", source = SourceType.BOTH)
|
||||
@CommandParameters(description = "Shows all banned player names. Admins may optionally use 'purge' to clear the list.", usage = "/<command> [purge]")
|
||||
public class Command_banlist extends FreedomCommand
|
||||
{
|
||||
@Override
|
||||
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
||||
{
|
||||
if (args.length > 0)
|
||||
{
|
||||
if (args[0].equalsIgnoreCase("purge"))
|
||||
{
|
||||
checkPermission("tfm.banlist.purge");
|
||||
FUtil.adminAction(sender.getName(), "Purging the ban list", true);
|
||||
msgNew("<green>Purged <amount> player bans.", Placeholder.unparsed("amount", String.valueOf(plugin.bm.purge())));
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
msgNew("<total> player bans (<usernames> usernames, <ips> IPs)",
|
||||
Placeholder.unparsed("total", String.valueOf(plugin.bm.getAllBans().size())),
|
||||
Placeholder.unparsed("usernames", String.valueOf(plugin.bm.getUsernameBans())),
|
||||
Placeholder.unparsed("ips", String.valueOf(plugin.bm.getIpBans().size())));
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<String> getTabCompleteOptions(CommandSender sender, Command command, String alias, String[] args)
|
||||
{
|
||||
return args.length == 1 && sender.hasPermission("tfm.banlist.purge") ? Collections.singletonList("purge") : Collections.emptyList();
|
||||
}
|
||||
}
|
@ -1,113 +0,0 @@
|
||||
package me.totalfreedom.totalfreedommod.command;
|
||||
|
||||
import me.totalfreedom.totalfreedommod.player.FPlayer;
|
||||
import me.totalfreedom.totalfreedommod.punishments.Punishment;
|
||||
import me.totalfreedom.totalfreedommod.punishments.PunishmentType;
|
||||
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.HumanEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
@CommandPermissions(permission = "blockedit", source = SourceType.BOTH)
|
||||
@CommandParameters(description = "Restricts/restores block modification abilities for everyone on the server or a certain player.", usage = "/<command> [<player> [reason] | list | purge | all]")
|
||||
public class Command_blockedit extends FreedomCommand
|
||||
{
|
||||
@Override
|
||||
public boolean run(final CommandSender sender, final Player playerSender, final Command cmd, final String commandLabel, String[] args, final boolean senderIsConsole)
|
||||
{
|
||||
if (args.length > 0)
|
||||
{
|
||||
switch (args[0].toLowerCase())
|
||||
{
|
||||
case "list" ->
|
||||
{
|
||||
List<? extends Player> list = server.getOnlinePlayers().stream().filter(player ->
|
||||
plugin.pl.getPlayer(player).isEditBlocked()).sorted().toList();
|
||||
|
||||
boolean plural = list.size() != 1;
|
||||
msgNew("There <grammar> <count> player<plural> online with restricted block modification abilities: <players>",
|
||||
Placeholder.unparsed("grammar", plural ? "are" : "is"),
|
||||
Placeholder.unparsed("count", String.valueOf(list.size())),
|
||||
Placeholder.unparsed("plural", plural ? "s" : ""),
|
||||
Placeholder.unparsed("colon", list.size() > 0 ? ":" : "."),
|
||||
Placeholder.unparsed("players", FUtil.listToString(list.stream().map(HumanEntity::getName).toList())));
|
||||
}
|
||||
case "purge" ->
|
||||
{
|
||||
FUtil.adminAction(sender.getName(), "Restoring block modification abilities for all players", true);
|
||||
|
||||
List<? extends Player> list = server.getOnlinePlayers().stream().filter(player ->
|
||||
plugin.pl.getPlayer(player).isEditBlocked()).toList();
|
||||
|
||||
list.forEach(player ->
|
||||
{
|
||||
plugin.pl.getPlayer(player).setEditBlocked(false);
|
||||
msgNew(player, "<green>Your block modification abilities have been restored.");
|
||||
});
|
||||
|
||||
msgNew("Restored block modification abilities for <count> player<plural>.",
|
||||
Placeholder.unparsed("count", String.valueOf(list.size())),
|
||||
Placeholder.unparsed("plural", list.size() != 1 ? "s" : ""));
|
||||
}
|
||||
case "all", "-a" ->
|
||||
{
|
||||
FUtil.adminAction(sender.getName(), "Restricting block modification abilities for all non-admins", true);
|
||||
|
||||
List<? extends Player> list = server.getOnlinePlayers().stream().filter(player ->
|
||||
!plugin.al.isAdmin(player)).toList();
|
||||
|
||||
list.forEach(player ->
|
||||
{
|
||||
plugin.pl.getPlayer(player).setEditBlocked(true);
|
||||
msgNew(player, "<red>Your block modification abilities have been restricted.");
|
||||
});
|
||||
|
||||
msgNew("Restricted block modification abilities for <count> player<plural>.",
|
||||
Placeholder.unparsed("count", String.valueOf(list.size())),
|
||||
Placeholder.unparsed("plural", list.size() != 1 ? "s" : ""));
|
||||
}
|
||||
default -> Optional.ofNullable(getPlayer(args[0])).ifPresentOrElse(player ->
|
||||
{
|
||||
FPlayer fPlayer = plugin.pl.getPlayer(player);
|
||||
|
||||
if (fPlayer.isEditBlocked())
|
||||
{
|
||||
FUtil.adminAction(sender.getName(), "Restoring block modification abilities for " + player.getName(), true);
|
||||
fPlayer.setEditBlocked(false);
|
||||
msgNew("Restored block modification abilities for <player>.", Placeholder.unparsed("player", player.getName()));
|
||||
msgNew(player, "<green>Your block modification abilities have been restored.");
|
||||
}
|
||||
else
|
||||
{
|
||||
if (plugin.al.isAdmin(player))
|
||||
{
|
||||
msgNew("<red><player> is an admin, and as such cannot have their block modification abilities restricted.", Placeholder.unparsed("player", player.getName()));
|
||||
}
|
||||
else
|
||||
{
|
||||
FUtil.adminAction(sender.getName(), "Restricting block modification abilities for " + player.getName(), true);
|
||||
fPlayer.setEditBlocked(true);
|
||||
msgNew("Restricted block modification abilities for <player>.", Placeholder.unparsed("player", player.getName()));
|
||||
msgNew(player, "<red>Your block modification abilities have been restricted.");
|
||||
|
||||
plugin.pul.logPunishment(new Punishment(player.getName(), FUtil.getIp(player),
|
||||
sender.getName(), PunishmentType.BLOCKEDIT, null));
|
||||
}
|
||||
}
|
||||
|
||||
}, () -> msg(PLAYER_NOT_FOUND));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,111 +0,0 @@
|
||||
package me.totalfreedom.totalfreedommod.command;
|
||||
|
||||
import me.totalfreedom.totalfreedommod.player.FPlayer;
|
||||
import me.totalfreedom.totalfreedommod.punishments.Punishment;
|
||||
import me.totalfreedom.totalfreedommod.punishments.PunishmentType;
|
||||
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@CommandPermissions(permission = "blockpvp", source = SourceType.BOTH)
|
||||
@CommandParameters(description = "Toggle PVP mode for everyone or a certain player.", usage = "/<command> [<player> | list | purge | all]", aliases = "pvpblock,pvpmode")
|
||||
public class Command_blockpvp extends FreedomCommand
|
||||
{
|
||||
@Override
|
||||
public boolean run(final CommandSender sender, final Player playerSender, final Command cmd, final String commandLabel, String[] args, final boolean senderIsConsole)
|
||||
{
|
||||
if (args.length == 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
switch (args[0].toLowerCase())
|
||||
{
|
||||
// List
|
||||
case "list" ->
|
||||
{
|
||||
List<String> restricted = server.getOnlinePlayers().stream().filter(player ->
|
||||
plugin.pl.getPlayer(player).isPvpBlocked()).map(Player::getName).toList();
|
||||
|
||||
if (restricted.isEmpty())
|
||||
{
|
||||
msgNew("Nobody currently has their PVP abilities restricted.");
|
||||
}
|
||||
else
|
||||
{
|
||||
msgNew("PVP abilities are restricted for these player(s): <players>",
|
||||
Placeholder.unparsed("players", FUtil.listToString(restricted)));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// Purge
|
||||
case "purge" ->
|
||||
{
|
||||
FUtil.adminAction(sender.getName(), "Restoring PVP abilities for all players", true);
|
||||
List<? extends Player> affected = server.getOnlinePlayers().stream().filter(player -> plugin.pl.getPlayer(player).isPvpBlocked()).toList();
|
||||
affected.forEach(player ->
|
||||
{
|
||||
msgNew(player, "<green>Your PVP abilities have been restored.");
|
||||
plugin.pl.getPlayer(player).setPvpBlocked(false);
|
||||
});
|
||||
msgNew("Restored PVP abilities for <count> players.", Placeholder.unparsed("count", String.valueOf(affected.size())));
|
||||
}
|
||||
|
||||
// All
|
||||
case "all" ->
|
||||
{
|
||||
FUtil.adminAction(sender.getName(), "Restricting PVP capabilities for all non-admins", true);
|
||||
List<? extends Player> affected = server.getOnlinePlayers().stream().filter(player -> !plugin.al.isAdmin(player)).toList();
|
||||
affected.forEach(player ->
|
||||
{
|
||||
msgNew(player, "<red>Your PVP abilities have been restricted.");
|
||||
plugin.pl.getPlayer(player).setPvpBlocked(true);
|
||||
});
|
||||
msgNew("Restricted PVP abilities for <count> players.", Placeholder.unparsed("count", String.valueOf(affected.size())));
|
||||
}
|
||||
|
||||
// Specific players
|
||||
default ->
|
||||
{
|
||||
final Player p = getPlayer(args[0]);
|
||||
if (p == null)
|
||||
{
|
||||
msg(PLAYER_NOT_FOUND);
|
||||
return true;
|
||||
}
|
||||
|
||||
final FPlayer pd = plugin.pl.getPlayer(p);
|
||||
if (pd.isPvpBlocked())
|
||||
{
|
||||
FUtil.adminAction(sender.getName(), "Restoring PVP capabilities for " + p.getName(), true);
|
||||
pd.setPvpBlocked(false);
|
||||
msgNew("Enabled the ability to PVP for <player>.", Placeholder.unparsed("player", p.getName()));
|
||||
msgNew(p, "<green>Your PVP abilities have been restored.");
|
||||
}
|
||||
else
|
||||
{
|
||||
if (plugin.al.isAdmin(p))
|
||||
{
|
||||
msgNew("<red><player> is an admin, and cannot have their PVP disabled.", Placeholder.unparsed("player", p.getName()));
|
||||
return true;
|
||||
}
|
||||
|
||||
FUtil.adminAction(sender.getName(), "Restricting PVP for " + p.getName(), true);
|
||||
pd.setPvpBlocked(true);
|
||||
plugin.pul.logPunishment(new Punishment(p.getName(), FUtil.getIp(p), sender.getName(), PunishmentType.BLOCKPVP, null));
|
||||
|
||||
msgNew(p, "<red>Your PVP abilities have been restricted.");
|
||||
msgNew("Restricted PVP abilities for <player>. ", Placeholder.unparsed("player", p.getName()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
@ -1,41 +0,0 @@
|
||||
package me.totalfreedom.totalfreedommod.command;
|
||||
|
||||
import me.totalfreedom.totalfreedommod.api.ShopItem;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@CommandDependencies({"TF-Shoppe"})
|
||||
@CommandPermissions(permission = "clownfish", source = SourceType.ONLY_IN_GAME)
|
||||
@CommandParameters(description = "Obtain a clown fish", usage = "/<command>")
|
||||
public class Command_clownfish extends FreedomCommand
|
||||
{
|
||||
|
||||
@Override
|
||||
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
||||
{
|
||||
if (plugin.sh == null)
|
||||
{
|
||||
msgNew("<red>Shop is currently disabled.");
|
||||
return true;
|
||||
}
|
||||
|
||||
if (plugin.pl.getData(playerSender).hasItem(ShopItem.CLOWN_FISH))
|
||||
{
|
||||
playerSender.getInventory().addItem(plugin.sh.getClownFish());
|
||||
msgNew("<green>You have been given a <name>.", Placeholder.unparsed("name", ShopItem.CLOWN_FISH.getName()));
|
||||
}
|
||||
else if (plugin.pl.getPlayer(playerSender).isClownfishDisabled())
|
||||
{
|
||||
msgNew("<red>An admin has disabled your ability to use the <name>. Guess you were the clown after all.",
|
||||
Placeholder.unparsed("name", ShopItem.CLOWN_FISH.getName()));
|
||||
}
|
||||
else
|
||||
{
|
||||
msgNew("<red>You don't own a <name>! Purchase one from the shop.", Placeholder.unparsed("name", ShopItem.CLOWN_FISH.getName()));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
@ -1,34 +0,0 @@
|
||||
package me.totalfreedom.totalfreedommod.command;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Random;
|
||||
|
||||
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
@CommandPermissions(permission = "cookie", source = SourceType.BOTH)
|
||||
@CommandParameters(description = "For those who have no friends - gives a cookie to everyone on the server.", usage = "/<command>")
|
||||
public class Command_cookie extends FreedomCommand
|
||||
{
|
||||
private static final Random RANDOM = new Random();
|
||||
|
||||
@Override
|
||||
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
||||
{
|
||||
final ItemStack heldItem = new ItemStack(Material.COOKIE);
|
||||
final ItemMeta heldItemMeta = heldItem.getItemMeta();
|
||||
assert heldItemMeta != null;
|
||||
heldItemMeta.displayName(FUtil.miniMessage("<rainbow>Cookie"));
|
||||
heldItemMeta.lore(Collections.singletonList(FUtil.miniMessage("<rainbow>But, you can have a cookie anyways,\nsince you are sad you are have no friends.")));
|
||||
heldItem.setItemMeta(heldItemMeta);
|
||||
|
||||
server.getOnlinePlayers().forEach(player -> player.getInventory().addItem(heldItem));
|
||||
server.broadcast(FUtil.miniMessage("<rainbow:" + RANDOM.nextInt() + ">Imagine that you have zero cookies and you split them evenly among zero friends. How many cookies does each person get? See? It doesn't make sense. And Cookie Monster is sad that there are no cookies, and you are sad that you have no friends."));
|
||||
return true;
|
||||
}
|
||||
}
|
@ -1,62 +0,0 @@
|
||||
package me.totalfreedom.totalfreedommod.command;
|
||||
|
||||
import me.totalfreedom.totalfreedommod.rank.GroupProvider;
|
||||
import me.totalfreedom.totalfreedommod.rank.HierarchyProvider;
|
||||
import me.totalfreedom.totalfreedommod.util.FLog;
|
||||
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||
import net.luckperms.api.model.user.User;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
@CommandPermissions(permission = "deop", source = SourceType.BOTH)
|
||||
@CommandParameters(description = "Deop a player", usage = "/<command> <partialname>")
|
||||
public class Command_deop extends FreedomCommand
|
||||
{
|
||||
@Override
|
||||
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
||||
{
|
||||
if (args.length < 1)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
boolean silent = false;
|
||||
if (args.length == 2)
|
||||
{
|
||||
silent = args[1].equalsIgnoreCase("-s");
|
||||
}
|
||||
|
||||
Player player = Bukkit.getServer().getPlayer(args[0]);
|
||||
|
||||
if (player == null || plugin.al.isVanished(player.getUniqueId()))
|
||||
{
|
||||
msg(sender, PLAYER_NOT_FOUND);
|
||||
return true;
|
||||
}
|
||||
|
||||
AtomicBoolean atomicBoolean = new AtomicBoolean(silent);
|
||||
User user = GroupProvider.getUser(player);
|
||||
HierarchyProvider.OP.getHierarchy().demoteUser(user).whenComplete((result, throwable) ->
|
||||
{
|
||||
if (throwable != null)
|
||||
{
|
||||
FLog.severe("Error while demoting " + player.getName() + " to OP: " + throwable.getMessage());
|
||||
return;
|
||||
}
|
||||
|
||||
msg(player, YOU_ARE_NOT_OP);
|
||||
plugin.rm.updateDisplay(player);
|
||||
|
||||
if (!atomicBoolean.get())
|
||||
{
|
||||
FUtil.adminAction(sender.getName(), "De-opping " + player.getName(), false);
|
||||
}
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
@ -1,37 +0,0 @@
|
||||
package me.totalfreedom.totalfreedommod.command;
|
||||
|
||||
import me.totalfreedom.totalfreedommod.rank.GroupProvider;
|
||||
import me.totalfreedom.totalfreedommod.rank.HierarchyProvider;
|
||||
import me.totalfreedom.totalfreedommod.util.FLog;
|
||||
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||
import net.luckperms.api.model.user.User;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@CommandPermissions(permission = "deop.all", source = SourceType.BOTH, blockHostConsole = true)
|
||||
@CommandParameters(description = "Deop everyone on the server.", usage = "/<command>")
|
||||
public class Command_deopall extends FreedomCommand
|
||||
{
|
||||
|
||||
@Override
|
||||
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
||||
{
|
||||
FUtil.adminAction(sender.getName(), "De-opping all players on the server", true);
|
||||
|
||||
server.getOnlinePlayers().forEach(player ->
|
||||
{
|
||||
User user = GroupProvider.getUser(player);
|
||||
HierarchyProvider.OP.getHierarchy().demoteUser(user).whenComplete((result, ex) -> {
|
||||
if (ex != null) {
|
||||
FLog.severe("Failed to demote " + player.getName() + " to default rank");
|
||||
}
|
||||
|
||||
msg(player, YOU_ARE_NOT_OP);
|
||||
plugin.rm.updateDisplay(player);
|
||||
});
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
@ -1,28 +0,0 @@
|
||||
package me.totalfreedom.totalfreedommod.command;
|
||||
|
||||
import me.totalfreedom.totalfreedommod.player.FPlayer;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import net.kyori.adventure.text.minimessage.tag.Tag;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@CommandPermissions(permission = "explosivearrows", source = SourceType.ONLY_IN_GAME)
|
||||
@CommandParameters(description = "Make arrows explode", usage = "/<command>", aliases = "ea")
|
||||
public class Command_explosivearrows extends FreedomCommand
|
||||
{
|
||||
@Override
|
||||
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
||||
{
|
||||
FPlayer player = plugin.pl.getPlayer(playerSender);
|
||||
player.setExplosiveArrowsEnabled(!player.isExplosiveArrowsEnabled());
|
||||
|
||||
msgNew("<statuscolor>You <status> have explosive arrows.",
|
||||
TagResolver.resolver("statuscolor", Tag.styling(player.isExplosiveArrowsEnabled() ? NamedTextColor.GREEN : NamedTextColor.RED)),
|
||||
Placeholder.unparsed("status", player.isExplosiveArrowsEnabled() ? "now" : "no longer"));
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
@ -1,85 +0,0 @@
|
||||
package me.totalfreedom.totalfreedommod.command;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
import me.totalfreedom.totalfreedommod.player.PlayerData;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@CommandPermissions(permission = "inspect", source = SourceType.ONLY_IN_GAME)
|
||||
@CommandParameters(description = "Block inspector tool for operators.", usage = "/<command> [history] [page]", aliases = "ins")
|
||||
public class Command_inspect extends FreedomCommand
|
||||
{
|
||||
@Override
|
||||
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
||||
{
|
||||
if (!plugin.cpb.isEnabled())
|
||||
{
|
||||
msg("CoreProtect is not enabled on this server.");
|
||||
return true;
|
||||
}
|
||||
|
||||
if (args.length == 0)
|
||||
{
|
||||
PlayerData playerData = plugin.pl.getData(playerSender);
|
||||
playerData.setInspect(!playerData.hasInspection());
|
||||
plugin.pl.save(playerData);
|
||||
msgNew("Block inspector <status>.", Placeholder.unparsed("status", playerData.hasInspection() ? "enabled." : "disabled."));
|
||||
return true;
|
||||
}
|
||||
|
||||
if (args[0].equalsIgnoreCase("history"))
|
||||
{
|
||||
int pageIndex = 1;
|
||||
|
||||
if (args.length >= 2)
|
||||
{
|
||||
try
|
||||
{
|
||||
pageIndex = Integer.parseInt(args[1]);
|
||||
}
|
||||
catch (NumberFormatException e)
|
||||
{
|
||||
msgNew("<red>Invalid number.");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
int godDammit = pageIndex;
|
||||
Optional.ofNullable(plugin.cpb.getHistoryForPlayer(playerSender)).ifPresentOrElse(page ->
|
||||
plugin.cpb.showPageToPlayer(playerSender, page, godDammit),
|
||||
() -> msgNew("<red>You haven't inspected anything yet!"));
|
||||
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getTabCompleteOptions(CommandSender sender, Command command, String alias, String[] args)
|
||||
{
|
||||
if (args.length == 1)
|
||||
{
|
||||
return Collections.singletonList("history");
|
||||
}
|
||||
else if (args.length == 2 && args[0].equalsIgnoreCase("history") && plugin.cpb.isEnabled()
|
||||
&& sender instanceof Player player && plugin.cpb.hasHistory(player))
|
||||
{
|
||||
return IntStream.rangeClosed(1, plugin.cpb.getHistoryForPlayer(player).getPageCount()).limit(50)
|
||||
.mapToObj(String::valueOf).toList();
|
||||
}
|
||||
else
|
||||
{
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,88 +0,0 @@
|
||||
package me.totalfreedom.totalfreedommod.command;
|
||||
|
||||
import me.totalfreedom.totalfreedommod.admin.Admin;
|
||||
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.JoinConfiguration;
|
||||
import net.kyori.adventure.text.TextComponent;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@CommandPermissions(permission = "list", source = SourceType.BOTH)
|
||||
@CommandParameters(description = "Lists the real names of all online players.", usage = "/<command> [-a | -v]", aliases = "who,lsit")
|
||||
public class Command_list extends FreedomCommand
|
||||
{
|
||||
@Override
|
||||
public boolean run(final CommandSender sender, final Player playerSender, final Command cmd, final String commandLabel, final String[] args, final boolean senderIsConsole)
|
||||
{
|
||||
if (args.length > 1)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
ListFilter listFilter;
|
||||
if (args.length == 1)
|
||||
{
|
||||
switch (args[0].toLowerCase())
|
||||
{
|
||||
case "-s", "-a" -> listFilter = ListFilter.ADMINS;
|
||||
case "-v" ->
|
||||
{
|
||||
checkPermission("tfm.list.vanished");
|
||||
listFilter = ListFilter.VANISHED_ADMINS;
|
||||
}
|
||||
case "-t" ->
|
||||
{
|
||||
checkPermission("tfm.list.telnet");
|
||||
listFilter = ListFilter.TELNET_SESSIONS;
|
||||
}
|
||||
default ->
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
} else
|
||||
{
|
||||
listFilter = ListFilter.PLAYERS;
|
||||
}
|
||||
|
||||
List<TextComponent> players;
|
||||
|
||||
if (listFilter == ListFilter.TELNET_SESSIONS && plugin.al.isAdmin(sender))
|
||||
{
|
||||
players = plugin.btb.getConnectedAdmins().stream().map(admin -> Component.text(admin.getName())).toList();
|
||||
msgNew("<blue>There are <red><count></red> admins connected to telnet.",
|
||||
Placeholder.unparsed("count", String.valueOf(players.size())));
|
||||
} else
|
||||
{
|
||||
players = server.getOnlinePlayers().stream().filter(pl ->
|
||||
(listFilter == ListFilter.ADMINS && plugin.al.isAdmin(pl) && !plugin.al.isVanished(pl.getUniqueId()))
|
||||
|| (listFilter == ListFilter.VANISHED_ADMINS && plugin.al.isVanished(pl.getUniqueId()))
|
||||
|| (listFilter == ListFilter.PLAYERS && !plugin.al.isVanished(pl.getUniqueId()))).map(player ->
|
||||
Component.textOfChildren(plugin.rm.getDisplay(player).getColoredTag().append(Component.text(player.getName())))).toList();
|
||||
|
||||
msgNew("<blue>There are <red><count></red> out of a maximum of <red><max></red> players online.",
|
||||
Placeholder.unparsed("count", String.valueOf(FUtil.getFakePlayerCount())),
|
||||
Placeholder.unparsed("max", String.valueOf(server.getMaxPlayers())));
|
||||
}
|
||||
|
||||
msgNew("Connected <type>: <players>",
|
||||
Placeholder.unparsed("type", listFilter.name().toLowerCase().replace('_', ' ')),
|
||||
Placeholder.component("players", Component.join(JoinConfiguration.commas(true), players)));
|
||||
return true;
|
||||
}
|
||||
|
||||
private enum ListFilter
|
||||
{
|
||||
PLAYERS,
|
||||
ADMINS,
|
||||
VANISHED_ADMINS,
|
||||
TELNET_SESSIONS
|
||||
}
|
||||
}
|
@ -1,56 +0,0 @@
|
||||
package me.totalfreedom.totalfreedommod.command;
|
||||
|
||||
import me.totalfreedom.totalfreedommod.api.ShopItem;
|
||||
import me.totalfreedom.totalfreedommod.player.PlayerData;
|
||||
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@CommandPermissions(permission = "loginmessage", source = SourceType.ONLY_IN_GAME)
|
||||
@CommandParameters(description = "Change your login message", usage = "/<command> [message]")
|
||||
public class Command_loginmessage extends FreedomCommand
|
||||
{
|
||||
@Override
|
||||
public boolean run(final CommandSender sender, final Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
||||
{
|
||||
if (plugin.sh == null && !sender.hasPermission("tfm.loginmessage.custom") || !plugin.pl.getData(playerSender).hasItem(ShopItem.LOGIN_MESSAGES) && !isAdmin(playerSender))
|
||||
{
|
||||
msg("You did not purchase the ability to use login messages, or the shop is not present! Purchase the ability from the shop.", ChatColor.RED);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (args.length == 0)
|
||||
{
|
||||
playerSender.openInventory(plugin.sh.generateLoginMessageGUI(playerSender));
|
||||
return true;
|
||||
}
|
||||
|
||||
checkPermission("tfm.loginmessage.custom");
|
||||
|
||||
String message = StringUtils.join(args, " ");
|
||||
if (!message.contains("<rank>") && !message.contains("<coloredrank>"))
|
||||
{
|
||||
msgNew("<red>Your login message must contain your rank. Use either \\\\<rank> or \\\\<coloredrank> to specify where you want the rank.");
|
||||
return true;
|
||||
}
|
||||
int length = FUtil.steamroll(FUtil.miniMessage(message, Placeholder.unparsed("name", ""),
|
||||
Placeholder.unparsed("rank", ""),
|
||||
Placeholder.unparsed("coloredrank", ""),
|
||||
Placeholder.unparsed("art", ""))).length();
|
||||
if (length > 100)
|
||||
{
|
||||
msgNew("<red>Your login message cannot be more than 100 characters (excluding your rank and your name)");
|
||||
return true;
|
||||
}
|
||||
PlayerData data = getData(playerSender);
|
||||
data.setLoginMessage(message);
|
||||
plugin.pl.save(data);
|
||||
msgNew("<green>Your login message is now the following:");
|
||||
msg(plugin.rm.craftLoginMessage(playerSender, message));
|
||||
return true;
|
||||
}
|
||||
}
|
@ -1,154 +0,0 @@
|
||||
package me.totalfreedom.totalfreedommod.command;
|
||||
|
||||
import me.totalfreedom.totalfreedommod.punishments.Punishment;
|
||||
import me.totalfreedom.totalfreedommod.punishments.PunishmentType;
|
||||
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||
import org.apache.commons.lang3.ArrayUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
@CommandPermissions(permission = "mute", source = SourceType.BOTH)
|
||||
@CommandParameters(description = "Mutes a player with brute force.", usage = "/<command> <[-q] <player> [reason] | list | purge | all>", aliases = "stfu")
|
||||
public class Command_mute extends FreedomCommand
|
||||
{
|
||||
@Override
|
||||
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
||||
{
|
||||
if (args.length == 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
switch (args[0].toLowerCase())
|
||||
{
|
||||
case "list" ->
|
||||
{
|
||||
List<String> muted = server.getOnlinePlayers().stream().filter(player -> plugin.pl.getPlayer(player).isMuted()).map(player -> player.getName()).toList();
|
||||
|
||||
if (muted.isEmpty())
|
||||
{
|
||||
msgNew("Nobody is currently muted.");
|
||||
} else
|
||||
{
|
||||
msgNew("Muted players: <players>", Placeholder.unparsed("players", FUtil.listToString(muted)));
|
||||
}
|
||||
}
|
||||
case "purge" ->
|
||||
{
|
||||
FUtil.adminAction(sender.getName(), "Unmuting all players", true);
|
||||
List<? extends Player> list = server.getOnlinePlayers().stream().filter(player ->
|
||||
plugin.pl.getPlayer(player).isMuted()).toList();
|
||||
|
||||
list.forEach(player ->
|
||||
{
|
||||
plugin.pl.getPlayer(player).setMuted(false);
|
||||
FUtil.playerTitle(player, "<red>You have been unmuted.", "<yellow>Be sure to follow the rules!");
|
||||
});
|
||||
|
||||
msgNew("Unmuted <count> player<plural>.",
|
||||
Placeholder.unparsed("count", String.valueOf(list.size())),
|
||||
Placeholder.unparsed("plural", list.size() != 1 ? "s" : ""));
|
||||
}
|
||||
case "all" ->
|
||||
{
|
||||
FUtil.adminAction(sender.getName(), "Muting all non-admins", true);
|
||||
List<? extends Player> list = server.getOnlinePlayers().stream().filter(player ->
|
||||
!plugin.al.isAdmin(player)).toList();
|
||||
|
||||
list.forEach(player ->
|
||||
{
|
||||
plugin.pl.getPlayer(player).setMuted(true);
|
||||
FUtil.playerTitle(player, "<red>You have been globally muted.", "<yellow>Please be patient and you will be unmuted shortly.");
|
||||
});
|
||||
|
||||
msgNew("Muted <count> player<plural>.",
|
||||
Placeholder.unparsed("count", String.valueOf(list.size())),
|
||||
Placeholder.unparsed("plural", list.size() != 1 ? "s" : ""));
|
||||
}
|
||||
default ->
|
||||
{
|
||||
boolean quiet = args[0].equalsIgnoreCase("-q");
|
||||
|
||||
// Handling the -q parameter
|
||||
if (quiet)
|
||||
{
|
||||
if (args.length == 1) return false;
|
||||
args = ArrayUtils.subarray(args, 1, args.length);
|
||||
}
|
||||
|
||||
// Handling the (optional) reason
|
||||
String reason = args.length > 1 ? StringUtils.join(args, " ", 1, args.length) : null;
|
||||
|
||||
// Showtime
|
||||
Optional.ofNullable(getPlayer(args[0])).ifPresentOrElse(player ->
|
||||
{
|
||||
if (plugin.al.isAdmin(player))
|
||||
{
|
||||
msgNew("<red><player> is an admin, and as such can't be muted.", Placeholder.unparsed("player", player.getName()));
|
||||
return;
|
||||
} else if (plugin.pl.getPlayer(player).isMuted())
|
||||
{
|
||||
msgNew("<red><player> is already muted.", Placeholder.unparsed("player", player.getName()));
|
||||
return;
|
||||
}
|
||||
|
||||
// Don't broadcast the mute if it was quiet
|
||||
if (!quiet)
|
||||
{
|
||||
FUtil.adminAction(sender.getName(), "Muting " + player.getName(), true);
|
||||
}
|
||||
|
||||
// Mutes the player
|
||||
plugin.pl.getPlayer(player).setMuted(true);
|
||||
|
||||
// Notify the player that they have been muted
|
||||
FUtil.playerTitle(player, "<red>You have been muted.", "<yellow>Be sure to follow the rules!");
|
||||
msgNew(player, "<red>You have been muted by <yellow><sender>", Placeholder.unparsed("sender", sender.getName()));
|
||||
|
||||
// Give them the reason if one is present.
|
||||
if (reason != null)
|
||||
{
|
||||
msgNew(player, "<red>Reason: <yellow><reason>", Placeholder.unparsed("reason", reason));
|
||||
}
|
||||
|
||||
if (quiet)
|
||||
{
|
||||
msgNew("Muted <player>.", Placeholder.unparsed("player", player.getName()));
|
||||
} else
|
||||
{
|
||||
msgNew("Quietly muted <player>.", Placeholder.unparsed("player", player.getName()));
|
||||
}
|
||||
|
||||
plugin.pul.logPunishment(new Punishment(player.getName(), FUtil.getIp(player), sender.getName(),
|
||||
PunishmentType.MUTE, reason));
|
||||
}, () -> msg(PLAYER_NOT_FOUND));
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getTabCompleteOptions(CommandSender sender, Command command, String alias, String[] args)
|
||||
{
|
||||
if (!plugin.al.isAdmin(sender))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
if (args.length == 1)
|
||||
{
|
||||
List<String> arguments = new ArrayList<>();
|
||||
arguments.addAll(FUtil.getPlayerList());
|
||||
arguments.addAll(Arrays.asList("list", "purge", "all"));
|
||||
return arguments;
|
||||
}
|
||||
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
@ -1,44 +0,0 @@
|
||||
package me.totalfreedom.totalfreedommod.command;
|
||||
|
||||
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@CommandPermissions(permission = "nickmm", source = SourceType.ONLY_IN_GAME)
|
||||
@CommandParameters(description = """
|
||||
Essentials Interface Command - Colorify your nickname.
|
||||
For Example: /nickmm <red><name> will color your name red.
|
||||
You can also use tags like <gradient> and <rainbow>.
|
||||
For example: /nickmm <gradient:red:green:blue><name>""", usage = "/<command> <nickname>")
|
||||
public class Command_nickmm extends FreedomCommand
|
||||
{
|
||||
@Override
|
||||
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
||||
{
|
||||
if (!server.getPluginManager().isPluginEnabled("Essentials"))
|
||||
{
|
||||
msg("Essentials is not enabled on this server.");
|
||||
return true;
|
||||
}
|
||||
|
||||
if (args[0].isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (args[0].matches(ChatColor.COLOR_CHAR + "[0-9a-fkm-o]"))
|
||||
{
|
||||
msgNew("<red>That nickname contains invalid characters.");
|
||||
return true;
|
||||
}
|
||||
|
||||
Component parsed = FUtil.miniMessage(args[0], Placeholder.unparsed("name", sender.getName()));
|
||||
plugin.esb.setNickname(sender.getName(), FUtil.miniMessage(parsed));
|
||||
msgNew("Your nickname is now: " + FUtil.miniMessage(parsed));
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
@ -1,63 +0,0 @@
|
||||
package me.totalfreedom.totalfreedommod.command;
|
||||
|
||||
import me.totalfreedom.totalfreedommod.rank.GroupProvider;
|
||||
import me.totalfreedom.totalfreedommod.rank.HierarchyProvider;
|
||||
import me.totalfreedom.totalfreedommod.util.FLog;
|
||||
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||
import net.luckperms.api.model.user.User;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
@CommandPermissions(permission = "op", source = SourceType.BOTH, cooldown = 5)
|
||||
@CommandParameters(description = "OP a player", usage = "/<command> <partialname>")
|
||||
public class Command_op extends FreedomCommand
|
||||
{
|
||||
|
||||
@Override
|
||||
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
||||
{
|
||||
if (args.length < 1)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
boolean silent = false;
|
||||
if (args.length == 2)
|
||||
{
|
||||
silent = args[1].equalsIgnoreCase("-s");
|
||||
}
|
||||
|
||||
Player player = Bukkit.getServer().getPlayer(args[0]);
|
||||
|
||||
if (player == null || plugin.al.isVanished(player.getUniqueId()))
|
||||
{
|
||||
msg(sender, PLAYER_NOT_FOUND);
|
||||
return true;
|
||||
}
|
||||
|
||||
AtomicBoolean atomicBoolean = new AtomicBoolean(silent);
|
||||
User user = GroupProvider.getUser(player);
|
||||
HierarchyProvider.OP.getHierarchy().promoteUser(user).whenComplete((ignored, throwable) ->
|
||||
{
|
||||
if (throwable != null)
|
||||
{
|
||||
FLog.severe("Failed to promote user " + player.getName());
|
||||
return;
|
||||
}
|
||||
|
||||
msg(player, YOU_ARE_OP);
|
||||
plugin.rm.updateDisplay(player);
|
||||
if (!atomicBoolean.get())
|
||||
{
|
||||
FUtil.adminAction(sender.getName(), "Opping " + player.getName(), false);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
@ -1,39 +0,0 @@
|
||||
package me.totalfreedom.totalfreedommod.command;
|
||||
|
||||
import me.totalfreedom.totalfreedommod.rank.GroupProvider;
|
||||
import me.totalfreedom.totalfreedommod.rank.HierarchyProvider;
|
||||
import me.totalfreedom.totalfreedommod.util.FLog;
|
||||
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||
import net.luckperms.api.model.user.User;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@CommandPermissions(permission = "op.all", source = SourceType.BOTH, cooldown = 30)
|
||||
@CommandParameters(description = "OP everyone on the server.", usage = "/<command>")
|
||||
public class Command_opall extends FreedomCommand
|
||||
{
|
||||
@Override
|
||||
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
||||
{
|
||||
FUtil.adminAction(sender.getName(), "Opping all players on the server", true);
|
||||
|
||||
server.getOnlinePlayers().forEach(player ->
|
||||
{
|
||||
User user = GroupProvider.getUser(player);
|
||||
HierarchyProvider.OP.getHierarchy().promoteUser(user).whenComplete((ignored, throwable) ->
|
||||
{
|
||||
if (throwable != null)
|
||||
{
|
||||
FLog.severe("Failed to promote " + player.getName());
|
||||
return;
|
||||
}
|
||||
|
||||
msg(player, YOU_ARE_OP);
|
||||
plugin.rm.updateDisplay(player);
|
||||
});
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
@ -1,33 +0,0 @@
|
||||
package me.totalfreedom.totalfreedommod.command;
|
||||
|
||||
import me.totalfreedom.totalfreedommod.rank.GroupProvider;
|
||||
import me.totalfreedom.totalfreedommod.rank.HierarchyProvider;
|
||||
import me.totalfreedom.totalfreedommod.util.FLog;
|
||||
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||
import net.luckperms.api.model.user.User;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@CommandPermissions(permission = "opme", source = SourceType.ONLY_IN_GAME)
|
||||
@CommandParameters(description = "OPs the command sender.", usage = "/<command>")
|
||||
public class Command_opme extends FreedomCommand
|
||||
{
|
||||
|
||||
@Override
|
||||
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
||||
{
|
||||
FUtil.adminAction(sender.getName(), "Opping " + sender.getName(), false);
|
||||
User user = GroupProvider.getUser(playerSender);
|
||||
HierarchyProvider.OP.getHierarchy().promoteUser(user).whenComplete((result, error) -> {
|
||||
if (error != null) {
|
||||
FLog.severe("Error while promoting " + playerSender.getName() + " to OP: " + error.getMessage());
|
||||
return;
|
||||
}
|
||||
|
||||
msg(YOU_ARE_OP);
|
||||
plugin.rm.updateDisplay(playerSender);
|
||||
});
|
||||
return true;
|
||||
}
|
||||
}
|
@ -1,148 +0,0 @@
|
||||
package me.totalfreedom.totalfreedommod.command;
|
||||
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import net.kyori.adventure.text.minimessage.tag.Tag;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
@CommandPermissions(permission = "plugincontrol", source = SourceType.BOTH)
|
||||
@CommandParameters(description = "Enable, disable, or reload a specified plugin, as well as list all plugins on the server.", usage = "/<command> <<enable | disable | reload> <pluginname>> | list>", aliases = "plc")
|
||||
public class Command_plugincontrol extends FreedomCommand
|
||||
{
|
||||
private final List<String> UNTOUCHABLE_PLUGINS = Arrays.asList(plugin.getName());
|
||||
|
||||
@Override
|
||||
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
||||
{
|
||||
final PluginManager pm = server.getPluginManager();
|
||||
|
||||
/* This is the way it is because there was too much "if the arguments aren't enough then return false" in the
|
||||
* original code in addition to the stupid amount of "if something isn't right then do some boilerplate stuff
|
||||
* then return true". Codacy complained, so I aggressively optimized this to keep it quiet. */
|
||||
switch (args.length)
|
||||
{
|
||||
case 1 ->
|
||||
{
|
||||
if (args[0].equalsIgnoreCase("list"))
|
||||
{
|
||||
Arrays.stream(pm.getPlugins()).forEach(pl ->
|
||||
{
|
||||
final String version = pl.getDescription().getVersion();
|
||||
msgNew("<gray>- <statuscolor><name><version> by <authors>",
|
||||
TagResolver.resolver("statuscolor", Tag.styling(pl.isEnabled() ? NamedTextColor.GREEN : NamedTextColor.RED)),
|
||||
Placeholder.unparsed("name", pl.getName()),
|
||||
Placeholder.unparsed("version", version.isEmpty() ? " v" + version : ""),
|
||||
Placeholder.unparsed("authors", StringUtils.join(pl.getDescription().getAuthors(), ", ")));
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
case 2 ->
|
||||
{
|
||||
Plugin pl = pm.getPlugin(args[1]);
|
||||
|
||||
if (pl != null)
|
||||
{
|
||||
switch (args[0].toLowerCase())
|
||||
{
|
||||
case "enable" ->
|
||||
{
|
||||
if (pl.isEnabled())
|
||||
{
|
||||
msgNew("<red><plugin> is already enabled.", Placeholder.unparsed("plugin", pl.getName()));
|
||||
return true;
|
||||
}
|
||||
|
||||
pm.enablePlugin(pl);
|
||||
|
||||
if (pl.isEnabled())
|
||||
{
|
||||
msgNew("<green><plugin> is now enabled.", Placeholder.unparsed("plugin", pl.getName()));
|
||||
} else
|
||||
{
|
||||
msgNew("<red>An error occurred whilst attempting to enable <plugin>", Placeholder.unparsed("plugin", pl.getName()));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
case "disable" ->
|
||||
{
|
||||
if (!pl.isEnabled())
|
||||
{
|
||||
msgNew("<red><plugin> is already disabled.", Placeholder.unparsed("plugin", pl.getName()));
|
||||
return true;
|
||||
} else if (UNTOUCHABLE_PLUGINS.contains(pl.getName()))
|
||||
{
|
||||
msgNew("<red><plugin> can't be disabled.", Placeholder.unparsed("plugin", pl.getName()));
|
||||
return true;
|
||||
}
|
||||
|
||||
pm.disablePlugin(pl);
|
||||
|
||||
msgNew("<green><plugin> is now disabled.", Placeholder.unparsed("plugin", pl.getName()));
|
||||
return true;
|
||||
}
|
||||
case "reload" ->
|
||||
{
|
||||
if (UNTOUCHABLE_PLUGINS.contains(pl.getName()))
|
||||
{
|
||||
msgNew("<red><plugin> can't be reloaded.", Placeholder.unparsed("plugin", pl.getName()));
|
||||
return true;
|
||||
}
|
||||
|
||||
pm.disablePlugin(pl);
|
||||
pm.enablePlugin(pl);
|
||||
|
||||
msgNew("<green><plugin> has been reloaded.", Placeholder.unparsed("plugin", pl.getName()));
|
||||
;
|
||||
return true;
|
||||
}
|
||||
default ->
|
||||
{
|
||||
// Do nothing. This is here to please Codacy.
|
||||
}
|
||||
}
|
||||
} else
|
||||
{
|
||||
msgNew("<red>Plugin not found!");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
default ->
|
||||
{
|
||||
// Ditto
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getTabCompleteOptions(CommandSender sender, Command command, String alias, String[] args)
|
||||
{
|
||||
if (!plugin.al.isAdmin(sender))
|
||||
{
|
||||
return Collections.emptyList();
|
||||
}
|
||||
if (args.length == 1)
|
||||
{
|
||||
return Arrays.asList("enable", "disable", "reload", "list");
|
||||
} else if (args.length == 2 && !args[0].equalsIgnoreCase("list"))
|
||||
{
|
||||
return Arrays.stream(server.getPluginManager().getPlugins()).map(Plugin::getName)
|
||||
.filter(pl -> !UNTOUCHABLE_PLUGINS.contains(pl)).toList();
|
||||
}
|
||||
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
@ -1,204 +0,0 @@
|
||||
package me.totalfreedom.totalfreedommod.command;
|
||||
|
||||
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.potion.PotionEffect;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
@CommandPermissions(permission = "potion", source = SourceType.BOTH)
|
||||
@CommandParameters(
|
||||
description = "Manipulate your potion effects. Duration is measured in server ticks (~20 ticks per second).",
|
||||
usage = "/<command> <list | clearall | clear [target name] | add <type> <duration> <amplifier> [target name]>",
|
||||
aliases = "effect")
|
||||
public class Command_potion extends FreedomCommand
|
||||
{
|
||||
@Override
|
||||
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
||||
{
|
||||
switch (args.length)
|
||||
{
|
||||
case 1 ->
|
||||
{
|
||||
if (args[0].equalsIgnoreCase("list"))
|
||||
{
|
||||
msg("Potion effect types: " + FUtil.listToString(Arrays.stream(PotionEffectType.values())
|
||||
.map(PotionEffectType::getName).toList()), ChatColor.AQUA);
|
||||
} else if (args[0].equalsIgnoreCase("clearall"))
|
||||
{
|
||||
if (!(plugin.al.isAdmin(sender) || senderIsConsole))
|
||||
{
|
||||
noPerms();
|
||||
return true;
|
||||
}
|
||||
|
||||
FUtil.adminAction(sender.getName(), "Clearing all potion effects from all players", true);
|
||||
server.getOnlinePlayers().forEach(target -> target.getActivePotionEffects().forEach(effect ->
|
||||
target.removePotionEffect(effect.getType())));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
case 2 ->
|
||||
{
|
||||
if (args[0].equalsIgnoreCase("clear"))
|
||||
{
|
||||
Player target = playerSender;
|
||||
|
||||
if (!plugin.al.isAdmin(sender) && !args[1].equalsIgnoreCase(sender.getName()))
|
||||
{
|
||||
msg(ChatColor.RED + "Only admins can clear potion effects from other players.");
|
||||
return true;
|
||||
}
|
||||
target = getPlayer(args[1], true);
|
||||
|
||||
if (target == null)
|
||||
{
|
||||
msg(PLAYER_NOT_FOUND);
|
||||
return true;
|
||||
}
|
||||
|
||||
for (PotionEffect potion_effect : target.getActivePotionEffects())
|
||||
{
|
||||
target.removePotionEffect(potion_effect.getType());
|
||||
}
|
||||
|
||||
msg("Cleared all active potion effects " + (!target.equals(playerSender) ? "from player "
|
||||
+ target.getName() + "." : "from yourself."), ChatColor.AQUA);
|
||||
}
|
||||
}
|
||||
case 4, 5 ->
|
||||
{
|
||||
if (args[0].equalsIgnoreCase("add"))
|
||||
{
|
||||
Player target = playerSender;
|
||||
|
||||
if (args.length == 5)
|
||||
{
|
||||
if (!plugin.al.isAdmin(sender) && !args[4].equalsIgnoreCase(sender.getName()))
|
||||
{
|
||||
msg("Only admins can apply potion effects to other players.", ChatColor.RED);
|
||||
return true;
|
||||
}
|
||||
|
||||
target = getPlayer(args[4]);
|
||||
|
||||
if (target == null || plugin.al.isVanished(target.getUniqueId()) && !plugin.al.isAdmin(sender))
|
||||
{
|
||||
msg(PLAYER_NOT_FOUND);
|
||||
return true;
|
||||
}
|
||||
} else
|
||||
{
|
||||
if (senderIsConsole)
|
||||
{
|
||||
msg("You must specify a target player when using this command from the console.");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
PotionEffectType effectType = PotionEffectType.getByName(args[1]);
|
||||
if (effectType == null)
|
||||
{
|
||||
msg("Invalid potion effect: " + args[1], ChatColor.AQUA);
|
||||
return true;
|
||||
}
|
||||
|
||||
int duration;
|
||||
try
|
||||
{
|
||||
duration = Math.min(Integer.parseInt(args[2]), 100000);
|
||||
} catch (NumberFormatException ex)
|
||||
{
|
||||
msg("Invalid duration: " + args[2], ChatColor.RED);
|
||||
return true;
|
||||
}
|
||||
|
||||
int amplifier;
|
||||
try
|
||||
{
|
||||
amplifier = Math.min(Integer.parseInt(args[3]), 100000);
|
||||
} catch (NumberFormatException ex)
|
||||
{
|
||||
msg("Invalid potion amplifier: " + args[3], ChatColor.RED);
|
||||
return true;
|
||||
}
|
||||
|
||||
PotionEffect new_effect = effectType.createEffect(duration, amplifier);
|
||||
target.addPotionEffect(new_effect);
|
||||
msg("Added potion effect: " + new_effect.getType().getName()
|
||||
+ ", Duration: " + new_effect.getDuration()
|
||||
+ ", Amplifier: " + new_effect.getAmplifier()
|
||||
+ (!target.equals(playerSender) ? " to player " + target.getName() + "." : " to yourself."), ChatColor.AQUA);
|
||||
}
|
||||
}
|
||||
default ->
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getTabCompleteOptions(CommandSender sender, Command command, String alias, String[] args)
|
||||
{
|
||||
switch (args.length)
|
||||
{
|
||||
case 1 ->
|
||||
{
|
||||
List<String> arguments = new ArrayList<>(Arrays.asList("list", "clear", "add"));
|
||||
if (plugin.al.isAdmin(sender))
|
||||
{
|
||||
arguments.add("clearall");
|
||||
}
|
||||
return arguments;
|
||||
}
|
||||
case 2 ->
|
||||
{
|
||||
if (args[0].equalsIgnoreCase("clear"))
|
||||
{
|
||||
if (plugin.al.isAdmin(sender))
|
||||
{
|
||||
return FUtil.getPlayerList();
|
||||
}
|
||||
} else if (args[0].equalsIgnoreCase("add"))
|
||||
{
|
||||
return Arrays.stream(PotionEffectType.values()).map(PotionEffectType::getName).toList();
|
||||
}
|
||||
}
|
||||
case 3 ->
|
||||
{
|
||||
if (args[0].equalsIgnoreCase("add"))
|
||||
{
|
||||
return Collections.singletonList("<duration>");
|
||||
}
|
||||
}
|
||||
case 4 ->
|
||||
{
|
||||
if (args[0].equalsIgnoreCase("add"))
|
||||
{
|
||||
return Collections.singletonList("<amplifier>");
|
||||
}
|
||||
}
|
||||
case 5 ->
|
||||
{
|
||||
if (plugin.al.isAdmin(sender) && args[0].equalsIgnoreCase("add"))
|
||||
{
|
||||
return FUtil.getPlayerList();
|
||||
}
|
||||
}
|
||||
default ->
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
@ -1,59 +0,0 @@
|
||||
package me.totalfreedom.totalfreedommod.command;
|
||||
|
||||
import org.apache.commons.lang.ArrayUtils;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@CommandPermissions(permission = "report", source = SourceType.ONLY_IN_GAME, blockHostConsole = true)
|
||||
@CommandParameters(description = "Report a player for all admins to see.", usage = "/<command> <player> <reason>")
|
||||
public class Command_report extends FreedomCommand
|
||||
{
|
||||
|
||||
@Override
|
||||
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
||||
{
|
||||
if (args.length < 2)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
OfflinePlayer player = Bukkit.getOfflinePlayer(args[0]);
|
||||
|
||||
if (sender instanceof Player && (player.equals(playerSender)))
|
||||
{
|
||||
msgNew("<red>Please, don't try to report yourself.");
|
||||
return true;
|
||||
}
|
||||
|
||||
if (plugin.al.isAdmin(player))
|
||||
{
|
||||
msgNew("<red>You can't report admins with this command.");
|
||||
return true;
|
||||
}
|
||||
|
||||
String report = StringUtils.join(ArrayUtils.subarray(args, 1, args.length), " ");
|
||||
plugin.cm.reportAction(playerSender, player.getName(), report);
|
||||
|
||||
boolean logged = false;
|
||||
|
||||
if (plugin.dc != null && plugin.dc.isEnabled())
|
||||
{
|
||||
Player online = Bukkit.getPlayer(player.getUniqueId());
|
||||
logged = (online != null)
|
||||
? plugin.dc.sendReport(playerSender, online, report)
|
||||
: plugin.dc.sendReportOffline(playerSender, player, report);
|
||||
}
|
||||
|
||||
msgNew("<green>Thank you, your report has been successfully logged.");
|
||||
if (logged)
|
||||
{
|
||||
msgNew("<red>Note: This report has been logged to a Discord channel, as with any report system, spamming reports can lead to you getting banned.");
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
@ -1,35 +0,0 @@
|
||||
package me.totalfreedom.totalfreedommod.command;
|
||||
|
||||
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@CommandPermissions(permission = "say", source = SourceType.BOTH)
|
||||
@CommandParameters(description = "Broadcasts the given message as the server, includes sender name.", usage = "/<command> <message>")
|
||||
public class Command_say extends FreedomCommand
|
||||
{
|
||||
@Override
|
||||
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
||||
{
|
||||
if (args.length == 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
String message = StringUtils.join(args, " ");
|
||||
|
||||
server.broadcast(FUtil.miniMessage("<light_purple>[Server:<player>] <message>",
|
||||
Placeholder.unparsed("player", sender.getName()),
|
||||
Placeholder.unparsed("message", message)));
|
||||
|
||||
if (plugin.dc != null)
|
||||
{
|
||||
plugin.dc.messageChatChannel(String.format("[Server:%s] \u00BB %s", sender.getName(), message), true);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
@ -1,63 +0,0 @@
|
||||
package me.totalfreedom.totalfreedommod.command;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.event.ClickEvent;
|
||||
import net.kyori.adventure.text.event.HoverEvent;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.generator.WorldInfo;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@CommandPermissions(permission = "seed", source = SourceType.BOTH)
|
||||
@CommandParameters(description = "Get the seed of the world you are currently in.", usage = "/seed [world]")
|
||||
public class Command_seed extends FreedomCommand
|
||||
{
|
||||
@Override
|
||||
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
||||
{
|
||||
World world;
|
||||
|
||||
if (args.length > 0)
|
||||
{
|
||||
world = server.getWorld(args[0]);
|
||||
if (world == null)
|
||||
{
|
||||
msg("That world could not be found", ChatColor.RED);
|
||||
return true;
|
||||
}
|
||||
} else
|
||||
{
|
||||
// If the sender is a Player, use that world. Otherwise, use the overworld as a fallback.
|
||||
if (!senderIsConsole)
|
||||
{
|
||||
world = playerSender.getWorld();
|
||||
} else
|
||||
{
|
||||
world = server.getWorlds().get(0);
|
||||
}
|
||||
}
|
||||
|
||||
sender.sendMessage(Component.translatable("commands.seed.success",
|
||||
Component.text("[", NamedTextColor.WHITE).append(Component.text(world.getSeed(), NamedTextColor.GREEN)
|
||||
.clickEvent(ClickEvent.copyToClipboard(String.valueOf(world.getSeed())))
|
||||
.hoverEvent(HoverEvent.showText(Component.translatable("chat.copy"))))
|
||||
.append(Component.text("]"))));
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getTabCompleteOptions(CommandSender sender, Command command, String alias, String[] args)
|
||||
{
|
||||
if (args.length == 1)
|
||||
{
|
||||
return server.getWorlds().stream().map(WorldInfo::getName).toList();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
@ -1,47 +0,0 @@
|
||||
package me.totalfreedom.totalfreedommod.command;
|
||||
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
@CommandPermissions(permission = "stopsound", source = SourceType.ONLY_IN_GAME)
|
||||
@CommandParameters(description = "Stops all sounds or a specified sound.", usage = "/<command> [sound]")
|
||||
public class Command_stopsound extends FreedomCommand
|
||||
{
|
||||
@Override
|
||||
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
||||
{
|
||||
if (args.length > 0)
|
||||
{
|
||||
Arrays.stream(Sound.values()).filter(snd -> snd != null && snd.name().equalsIgnoreCase(args[0])).findAny().ifPresentOrElse(sound ->
|
||||
{
|
||||
playerSender.stopSound(sound);
|
||||
msgNew("<green>Stopped all <sound> sounds.", Placeholder.unparsed("sound", sound.name()));
|
||||
}, () -> msgNew("<red><sound> is not a valid sound.", Placeholder.unparsed("sound", args[0])));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
playerSender.stopAllSounds();
|
||||
|
||||
msgNew("<green>Stopped all sounds.");
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getTabCompleteOptions(CommandSender sender, Command command, String alias, String[] args)
|
||||
{
|
||||
if (args.length <= 1)
|
||||
{
|
||||
return Arrays.stream(Sound.values()).map(Enum::name).toList();
|
||||
}
|
||||
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
@ -1,201 +0,0 @@
|
||||
package me.totalfreedom.totalfreedommod.command;
|
||||
|
||||
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
|
||||
import me.totalfreedom.totalfreedommod.player.FPlayer;
|
||||
import me.totalfreedom.totalfreedommod.player.PlayerData;
|
||||
import me.totalfreedom.totalfreedommod.util.FLog;
|
||||
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.event.ClickEvent;
|
||||
import net.kyori.adventure.text.event.HoverEvent;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||
import org.apache.commons.lang3.ArrayUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@CommandPermissions(permission = "tag", source = SourceType.BOTH)
|
||||
@CommandParameters(description = "Allows you to set your own prefix.", usage = "/<command> [-ns] <set <tag..> | list | off | clear <player> | clearall>")
|
||||
public class Command_tag extends FreedomCommand
|
||||
{
|
||||
@Override
|
||||
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
||||
{
|
||||
boolean save = true;
|
||||
|
||||
if (args.length < 1)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (args[0].equalsIgnoreCase("-ns"))
|
||||
{
|
||||
save = false;
|
||||
args = ArrayUtils.remove(args, 0);
|
||||
}
|
||||
|
||||
if (args.length == 1)
|
||||
{
|
||||
switch (args[0].toLowerCase())
|
||||
{
|
||||
case "list":
|
||||
{
|
||||
msgNew("Tags for all online players:");
|
||||
server.getOnlinePlayers().stream().filter(player -> !(plugin.al.isVanished(player.getUniqueId()) && !isAdmin(sender)) && plugin.pl.getPlayer(player).getTag() != null).forEach(player -> {
|
||||
msgNew("<player>: <tag>", Placeholder.unparsed("player", player.getName()),
|
||||
Placeholder.component("tag", plugin.pl.getPlayer(player).getTag()));
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
case "clearall":
|
||||
{
|
||||
if (!sender.hasPermission("tfm.tag.clear.all"))
|
||||
{
|
||||
noPerms();
|
||||
return true;
|
||||
}
|
||||
|
||||
FUtil.adminAction(sender.getName(), "Removing all tags", false);
|
||||
|
||||
int count = 0;
|
||||
for (final Player player : server.getOnlinePlayers())
|
||||
{
|
||||
final FPlayer playerdata = plugin.pl.getPlayer(player);
|
||||
if (playerdata.getTag() != null)
|
||||
{
|
||||
count++;
|
||||
playerdata.setTag(null);
|
||||
}
|
||||
}
|
||||
|
||||
msgNew("<count> tag(s) removed.", Placeholder.unparsed("count", String.valueOf(count)));
|
||||
return true;
|
||||
}
|
||||
|
||||
case "off":
|
||||
{
|
||||
if (senderIsConsole)
|
||||
{
|
||||
msgNew("<red>\"/tag off\" can't be used from the console.");
|
||||
}
|
||||
else
|
||||
{
|
||||
plugin.pl.getPlayer(playerSender).setTag(null);
|
||||
|
||||
if (save)
|
||||
{
|
||||
save(playerSender, null);
|
||||
}
|
||||
|
||||
msgNew("Your tag has been removed. <saved>",
|
||||
Placeholder.unparsed("saved", save ? "(Saved)" : ""));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
default:
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (args.length >= 2)
|
||||
{
|
||||
switch (args[0].toLowerCase())
|
||||
{
|
||||
case "clear":
|
||||
{
|
||||
if (!sender.hasPermission("tfm.tag.clear.others"))
|
||||
{
|
||||
noPerms();
|
||||
return true;
|
||||
}
|
||||
|
||||
final Player player = getPlayer(args[1]);
|
||||
|
||||
if (player == null)
|
||||
{
|
||||
msg(FreedomCommand.PLAYER_NOT_FOUND);
|
||||
return true;
|
||||
}
|
||||
|
||||
plugin.pl.getPlayer(player).setTag(null);
|
||||
if (save)
|
||||
{
|
||||
save(player, null);
|
||||
}
|
||||
|
||||
msgNew("Removed <player>'s tag. <saved>",
|
||||
Placeholder.unparsed("player", player.getName()),
|
||||
Placeholder.unparsed("saved", save ? "(Saved)" : ""));
|
||||
return true;
|
||||
}
|
||||
|
||||
case "set":
|
||||
{
|
||||
if (senderIsConsole)
|
||||
{
|
||||
msgNew("<red>\"/tag set\" can't be used from the console.");
|
||||
return true;
|
||||
}
|
||||
|
||||
final String inputTag = StringUtils.join(args, " ", 1, args.length);
|
||||
Component tag;
|
||||
|
||||
if (FUtil.containsChatColor(inputTag))
|
||||
{
|
||||
tag = FUtil.colorizeAsComponent(inputTag.replace("&k", ""));
|
||||
} else
|
||||
{
|
||||
tag = FUtil.miniMessage(inputTag);
|
||||
}
|
||||
|
||||
String steamrolled = FUtil.steamroll(tag);
|
||||
int tagLimit = (plugin.al.isAdmin(sender) ? 30 : 20);
|
||||
if (steamrolled.length() > tagLimit)
|
||||
{
|
||||
FLog.debug("FUCK YOU " + steamrolled.length());
|
||||
FLog.debug("FUCK YOU " + steamrolled);
|
||||
msgNew("<red>That tag is too long (Max is <max> characters).", Placeholder.unparsed("max", String.valueOf(tagLimit)));
|
||||
return true;
|
||||
}
|
||||
else if (!plugin.al.isAdmin(sender) && ConfigEntry.FORBIDDEN_WORDS.getStringList().stream().anyMatch(word -> steamrolled.toLowerCase().contains(word)))
|
||||
{
|
||||
msgNew("<red>That tag contains a forbidden word.");
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
plugin.pl.getPlayer(playerSender).setTag(tag);
|
||||
|
||||
if (save)
|
||||
{
|
||||
save(playerSender, tag);
|
||||
}
|
||||
|
||||
msgNew("Tag set to '<tag>' <saved>",
|
||||
Placeholder.component("tag", tag.hoverEvent(HoverEvent.showText(Component.translatable("chat.copy")))
|
||||
.clickEvent(ClickEvent.copyToClipboard(FUtil.miniMessage(tag)))),
|
||||
Placeholder.unparsed("saved", save ? "(Saved)" : ""));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
default:
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void save(Player player, Component tag)
|
||||
{
|
||||
PlayerData playerData = plugin.pl.getData(player);
|
||||
playerData.setTag(tag);
|
||||
plugin.pl.save(playerData);
|
||||
}
|
||||
}
|
@ -1,184 +0,0 @@
|
||||
package me.totalfreedom.totalfreedommod.command;
|
||||
|
||||
import me.totalfreedom.totalfreedommod.GameRuleHandler;
|
||||
import me.totalfreedom.totalfreedommod.LoginProcess;
|
||||
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
|
||||
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
@CommandPermissions(permission = "toggle", source = SourceType.BOTH)
|
||||
@CommandParameters(description = "Toggles TotalFreedomMod settings", usage = "/<command> [option] [value] [value]")
|
||||
public class Command_toggle extends FreedomCommand
|
||||
{
|
||||
private final List<String> toggles = Arrays.asList(
|
||||
"waterplace", "fireplace", "lavaplace", "fluidspread", "lavadmg", "firespread", "frostwalk",
|
||||
"firework", "prelog", "lockdown", "petprotect", "entitywipe", "nonuke [range] [count]",
|
||||
"explosives [radius]", "unsafeenchs", "bells", "armorstands", "masterblocks", "books", "grindstones",
|
||||
"jukeboxes", "spawners", "4chan", "beehives", "respawnanchors", "autotp", "autoclear", "minecarts", "mp44",
|
||||
"landmines", "tossmob", "gravity", "chat", "disguises");
|
||||
|
||||
@Override
|
||||
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
||||
{
|
||||
if (args.length == 0)
|
||||
{
|
||||
msgNew("Available toggles: ");
|
||||
toggles.forEach(toggle -> msgNew("- <toggle>", Placeholder.unparsed("toggle", toggle)));
|
||||
return false;
|
||||
}
|
||||
|
||||
switch (args[0].toLowerCase())
|
||||
{
|
||||
case "waterplace" -> toggle("Water placement is", ConfigEntry.ALLOW_WATER_PLACE);
|
||||
case "frostwalk" -> toggle("Frost walker enchantment is", ConfigEntry.ALLOW_FROSTWALKER);
|
||||
case "fireplace" -> toggle("Fire placement is", ConfigEntry.ALLOW_FIRE_PLACE);
|
||||
case "lavaplace" -> toggle("Lava placement is", ConfigEntry.ALLOW_LAVA_PLACE);
|
||||
case "fluidspread" -> toggle("Fluid spread is", ConfigEntry.ALLOW_FLUID_SPREAD);
|
||||
case "lavadmg" -> toggle("Lava damage is", ConfigEntry.ALLOW_LAVA_DAMAGE);
|
||||
case "firespread" ->
|
||||
{
|
||||
toggle("Fire spread is", ConfigEntry.ALLOW_FIRE_SPREAD);
|
||||
plugin.gr.setGameRule(GameRuleHandler.GameRule.DO_FIRE_TICK, ConfigEntry.ALLOW_FIRE_SPREAD.getBoolean());
|
||||
}
|
||||
case "prelog" -> toggle("Command prelogging is", ConfigEntry.ENABLE_PREPROCESS_LOG);
|
||||
case "lockdown" ->
|
||||
{
|
||||
boolean active = !LoginProcess.isLockdownEnabled();
|
||||
LoginProcess.setLockdownEnabled(active);
|
||||
FUtil.adminAction(sender.getName(), (active ? "A" : "De-a") + "ctivating server lockdown", true);
|
||||
}
|
||||
case "petprotect" -> toggle("Tamed pet protection is", ConfigEntry.ENABLE_PET_PROTECT);
|
||||
case "entitywipe" -> toggle("Automatic entity wiping is", ConfigEntry.AUTO_ENTITY_WIPE);
|
||||
case "firework" -> toggle("Firework explosion is", ConfigEntry.ALLOW_FIREWORK_EXPLOSION);
|
||||
case "nonuke" ->
|
||||
{
|
||||
if (args.length >= 2)
|
||||
{
|
||||
try
|
||||
{
|
||||
ConfigEntry.NUKE_MONITOR_RANGE.setDouble(Math.max(1.0, Math.min(500.0, Double.parseDouble(args[1]))));
|
||||
} catch (NumberFormatException ex)
|
||||
{
|
||||
msgNew("<red>The input provided is not a valid integer.");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if (args.length >= 3)
|
||||
{
|
||||
try
|
||||
{
|
||||
ConfigEntry.NUKE_MONITOR_COUNT_BREAK.setInteger(Math.max(1, Math.min(500, Integer.parseInt(args[2]))));
|
||||
} catch (NumberFormatException ex)
|
||||
{
|
||||
msgNew("<red>The input provided is not a valid integer.");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
toggle("Nuke monitor is", ConfigEntry.NUKE_MONITOR_ENABLED);
|
||||
|
||||
if (ConfigEntry.NUKE_MONITOR_ENABLED.getBoolean())
|
||||
{
|
||||
msgNew("Anti-freecam range is set to <range> blocks.", Placeholder.unparsed("range", String.valueOf(ConfigEntry.NUKE_MONITOR_RANGE.getDouble())));
|
||||
msgNew("Block throttle rate is set to <count> blocks destroyed per 5 seconds.", Placeholder.unparsed("count", String.valueOf(ConfigEntry.NUKE_MONITOR_COUNT_BREAK.getInteger())));
|
||||
}
|
||||
}
|
||||
case "explosives" ->
|
||||
{
|
||||
if (args.length == 2)
|
||||
{
|
||||
try
|
||||
{
|
||||
ConfigEntry.EXPLOSIVE_RADIUS.setDouble(Math.max(1.0, Math.min(30.0, Double.parseDouble(args[1]))));
|
||||
} catch (NumberFormatException ex)
|
||||
{
|
||||
msgNew("<red>The input provided is not a valid integer.");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
toggle("Explosions are", ConfigEntry.ALLOW_EXPLOSIONS);
|
||||
|
||||
if (ConfigEntry.ALLOW_EXPLOSIONS.getBoolean())
|
||||
{
|
||||
msgNew("Radius set to <radius>.", Placeholder.unparsed("radius", String.valueOf(ConfigEntry.EXPLOSIVE_RADIUS.getDouble())));
|
||||
}
|
||||
}
|
||||
case "unsafeenchs" -> toggle("Unsafe enchantments are", ConfigEntry.ALLOW_UNSAFE_ENCHANTMENTS);
|
||||
case "bells" -> toggle("The ringing of bells is", ConfigEntry.ALLOW_BELLS);
|
||||
case "armorstands" -> toggle("The placement of armor stands is", ConfigEntry.ALLOW_ARMOR_STANDS);
|
||||
case "masterblocks" -> toggle("Master blocks are", ConfigEntry.ALLOW_MASTERBLOCKS);
|
||||
case "books" -> toggle("Books are", ConfigEntry.ALLOW_BOOKS);
|
||||
case "grindstones" -> toggle("Grindstones are", ConfigEntry.ALLOW_GRINDSTONES);
|
||||
case "jukeboxes" -> toggle("Jukeboxes are", ConfigEntry.ALLOW_JUKEBOXES);
|
||||
case "spawners" -> toggle("Spawners are", ConfigEntry.ALLOW_SPAWNERS);
|
||||
case "4chan" -> toggle("4chan mode is", ConfigEntry.FOURCHAN_ENABLED);
|
||||
case "beehives" -> toggle("Beehives are", ConfigEntry.ALLOW_BEEHIVES);
|
||||
case "respawnanchors" -> toggle("Respawn anchors are", ConfigEntry.ALLOW_RESPAWN_ANCHORS);
|
||||
case "autotp" -> toggle("Teleportation on join is", ConfigEntry.AUTO_TP);
|
||||
case "autoclear" -> toggle("Clearing inventories on join is", ConfigEntry.AUTO_CLEAR);
|
||||
case "minecarts" -> toggle("Minecarts are", ConfigEntry.ALLOW_MINECARTS);
|
||||
case "landmines" -> toggle("Landmines are", ConfigEntry.LANDMINES_ENABLED);
|
||||
case "mp44" -> toggle("MP44 is", ConfigEntry.MP44_ENABLED);
|
||||
case "tossmob" -> toggle("Tossmob is", ConfigEntry.TOSSMOB_ENABLED);
|
||||
case "gravity" -> toggle("Block gravity is", ConfigEntry.ALLOW_GRAVITY);
|
||||
case "chat" -> toggle("Chat is", ConfigEntry.TOGGLE_CHAT);
|
||||
case "disguises" ->
|
||||
{
|
||||
if (!plugin.ldb.isEnabled())
|
||||
{
|
||||
msgNew("<red>LibsDisguises is not enabled.");
|
||||
return true;
|
||||
}
|
||||
|
||||
if (plugin.ldb.isDisguisesEnabled())
|
||||
{
|
||||
plugin.ldb.undisguiseAll(true);
|
||||
}
|
||||
|
||||
plugin.ldb.setDisguisesEnabled(!plugin.ldb.isDisguisesEnabled());
|
||||
msgNew("Disguises are now <status>.", Placeholder.unparsed("status", plugin.ldb.isDisguisesEnabled() ? "enabled." : "disabled."));
|
||||
}
|
||||
default ->
|
||||
{
|
||||
msgNew("Available toggles: ");
|
||||
toggles.forEach(toggle -> msgNew("- <toggle>", Placeholder.unparsed("toggle", toggle)));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private void toggle(final String name, final ConfigEntry entry)
|
||||
{
|
||||
msgNew("<name> now <status>.", Placeholder.unparsed("name", name), Placeholder.unparsed("status",
|
||||
entry.setBoolean(!entry.getBoolean()) ? "enabled" : "disabled"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getTabCompleteOptions(CommandSender sender, Command command, String alias, String[] args)
|
||||
{
|
||||
if (!plugin.al.isAdmin(sender))
|
||||
{
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
if (args.length == 1)
|
||||
{
|
||||
return Arrays.asList(
|
||||
"waterplace", "fireplace", "lavaplace", "fluidspread", "lavadmg", "firespread", "frostwalk",
|
||||
"firework", "prelog", "lockdown", "petprotect", "entitywipe", "nonuke", "explosives", "unsafeenchs",
|
||||
"bells", "armorstands", "structureblocks", "jigsaws", "grindstones", "jukeboxes", "spawners", "4chan", "beehives",
|
||||
"respawnanchors", "autotp", "autoclear", "minecarts", "mp44", "landmines", "tossmob", "gravity", "chat", "disguises");
|
||||
}
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
@ -1,37 +0,0 @@
|
||||
package me.totalfreedom.totalfreedommod.command;
|
||||
|
||||
import me.totalfreedom.totalfreedommod.player.FPlayer;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@CommandDependencies({"TF-Shoppe"})
|
||||
@CommandPermissions(permission = "clownfish.toggle", source = SourceType.BOTH)
|
||||
@CommandParameters(description = "Toggle whether or not a player has the ability to use clownfish", usage = "/<command> <player>", aliases = "togglecf")
|
||||
public class Command_toggleclownfish extends FreedomCommand
|
||||
{
|
||||
@Override
|
||||
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
||||
{
|
||||
if (args.length == 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
Player player = server.getPlayer(args[0]);
|
||||
if (player == null)
|
||||
{
|
||||
msg(PLAYER_NOT_FOUND);
|
||||
return true;
|
||||
}
|
||||
|
||||
FPlayer fplayer = plugin.pl.getPlayer(player);
|
||||
fplayer.setClownfishDisabled(!fplayer.isClownfishDisabled());
|
||||
|
||||
msgNew("<player> will <status> have the ability to use the Clownfish.",
|
||||
Placeholder.unparsed("player", args[0]),
|
||||
Placeholder.unparsed("status", fplayer.isClownfishDisabled() ? "no longer" : "now"));
|
||||
return true;
|
||||
}
|
||||
}
|
@ -1,65 +0,0 @@
|
||||
package me.totalfreedom.totalfreedommod.command;
|
||||
|
||||
import me.totalfreedom.totalfreedommod.TotalFreedomMod;
|
||||
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
|
||||
import me.totalfreedom.totalfreedommod.util.FLog;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
/*
|
||||
* See https://github.com/TotalFreedom/License - This file may not be edited or removed.
|
||||
*/
|
||||
@CommandPermissions(source = SourceType.BOTH)
|
||||
@CommandParameters(description = "Shows information about TotalFreedomMod or reloads it", usage = "/<command> [reload]", aliases = "tfm")
|
||||
public class Command_totalfreedommod extends FreedomCommand
|
||||
{
|
||||
|
||||
@Override
|
||||
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
||||
{
|
||||
if (args.length == 1)
|
||||
{
|
||||
if (!args[0].equals("reload"))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!plugin.al.isAdmin(sender))
|
||||
{
|
||||
noPerms();
|
||||
return true;
|
||||
}
|
||||
|
||||
plugin.config.load();
|
||||
|
||||
plugin.fsh.stopServices();
|
||||
plugin.fsh.startServices();
|
||||
|
||||
msgNew("<name> v<version> reloaded.",
|
||||
Placeholder.unparsed("name", TotalFreedomMod.pluginName),
|
||||
Placeholder.unparsed("version", TotalFreedomMod.pluginVersion));
|
||||
FLog.info(String.format("%s v%s reloaded.",
|
||||
TotalFreedomMod.pluginName,
|
||||
TotalFreedomMod.pluginVersion));
|
||||
return true;
|
||||
}
|
||||
|
||||
TotalFreedomMod.BuildProperties build = TotalFreedomMod.build;
|
||||
msgNew("<gold>TotalFreedomMod for 'Total Freedom', the original all-op server.");
|
||||
msgNew("<gold>Running on <server>.", Placeholder.unparsed("server", ConfigEntry.SERVER_NAME.getString()));
|
||||
msgNew("<gold>Created by Madgeek1450 and Prozza.");
|
||||
msgNew("<gold>Version <blue><codename> - <version> Build <number> </blue>(<blue><head></blue>)",
|
||||
Placeholder.unparsed("codename", build.codename),
|
||||
Placeholder.unparsed("version", build.version),
|
||||
Placeholder.unparsed("number", build.number),
|
||||
Placeholder.unparsed("head", build.head));
|
||||
msgNew("<gold>Compiled <blue><date></blue> by <blue><author></blue>",
|
||||
Placeholder.unparsed("date", build.date),
|
||||
Placeholder.unparsed("author", build.author));
|
||||
msgNew("<green>Visit <aqua>http://github.com/TotalFreedom/TotalFreedomMod</aqua> for more information.");
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
@ -1,42 +0,0 @@
|
||||
package me.totalfreedom.totalfreedommod.command;
|
||||
|
||||
import me.totalfreedom.totalfreedommod.api.ShopItem;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@CommandDependencies({"TF-Shoppe"})
|
||||
@CommandPermissions(permission = "trail", source = SourceType.ONLY_IN_GAME)
|
||||
@CommandParameters(description = "Trails rainbow particles behind you as you walk/fly.", usage = "/<command>")
|
||||
public class Command_trail extends FreedomCommand
|
||||
{
|
||||
|
||||
@Override
|
||||
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
||||
{
|
||||
if (plugin.sh == null)
|
||||
{
|
||||
msgNew("<red>Shop is not enabled.");
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!plugin.pl.getData(playerSender).hasItem(ShopItem.RAINBOW_TRAIL))
|
||||
{
|
||||
msgNew("<red>You didn't purchase the ability to have a <item>! Purchase it from the shop.", Placeholder.unparsed("item", ShopItem.RAINBOW_TRAIL.getName()));
|
||||
return true;
|
||||
}
|
||||
|
||||
if (plugin.tr.contains(playerSender))
|
||||
{
|
||||
plugin.tr.remove(playerSender);
|
||||
msgNew("Trail disabled.");
|
||||
} else
|
||||
{
|
||||
plugin.tr.add(playerSender);
|
||||
msgNew("Trail enabled. Run this command again to disable it.");
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
@ -1,104 +0,0 @@
|
||||
package me.totalfreedom.totalfreedommod.command;
|
||||
|
||||
import me.totalfreedom.totalfreedommod.admin.AdminList;
|
||||
import me.totalfreedom.totalfreedommod.player.PlayerData;
|
||||
import me.totalfreedom.totalfreedommod.rank.Displayable;
|
||||
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
@CommandPermissions(permission = "vanish", source = SourceType.ONLY_IN_GAME)
|
||||
@CommandParameters(description = "Vanish/unvanish yourself.", usage = "/<command> [-s[ilent]]", aliases = "v")
|
||||
public class Command_vanish extends FreedomCommand
|
||||
{
|
||||
@Override
|
||||
public boolean run(final CommandSender sender, final Player playerSender, final Command cmd, final String commandLabel, final String[] args, final boolean senderIsConsole)
|
||||
{
|
||||
Displayable display = plugin.rm.getDisplay(playerSender);
|
||||
String displayName = display.getColor() + playerSender.getName();
|
||||
Component tag = display.getColoredTag();
|
||||
boolean silent = args.length > 0 && (args[0].equalsIgnoreCase("-s") || args[0].equalsIgnoreCase("-silent"));
|
||||
|
||||
if (plugin.al.isVanished(playerSender.getUniqueId()))
|
||||
{
|
||||
if (silent)
|
||||
{
|
||||
msgNew("<gold>Silently unvanished.");
|
||||
}
|
||||
else
|
||||
{
|
||||
msgNew("<gold>You have unvanished.");
|
||||
server.broadcast(plugin.rm.craftLoginMessage(playerSender, null));
|
||||
server.broadcast(Component.translatable("multiplayer.player.joined", Component.text(playerSender.getName()))
|
||||
.color(NamedTextColor.YELLOW));
|
||||
|
||||
if (plugin.dc != null) {
|
||||
plugin.dc.messageChatChannel("**" + playerSender.getName() + " joined the server" + "**", true);
|
||||
}
|
||||
}
|
||||
|
||||
PlayerData playerData = plugin.pl.getData(playerSender);
|
||||
if (playerData.getTag() != null)
|
||||
{
|
||||
tag = playerData.getTag();
|
||||
}
|
||||
|
||||
plugin.pl.getData(playerSender).setTag(tag);
|
||||
plugin.cm.messageAllAdmins("<yellow><player> has unvanished and is now visible to everyone.", Placeholder.unparsed("player", sender.getName()));
|
||||
|
||||
server.getOnlinePlayers().stream().filter(player -> !plugin.al.isAdmin(player)).forEach(player ->
|
||||
player.showPlayer(plugin, playerSender));
|
||||
|
||||
plugin.esb.setVanished(playerSender.getName(), false);
|
||||
playerSender.setPlayerListName(StringUtils.substring(displayName, 0, 16));
|
||||
AdminList.vanished.remove(playerSender.getUniqueId());
|
||||
}
|
||||
else
|
||||
{
|
||||
new BukkitRunnable()
|
||||
{
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
if (plugin.al.isVanished(playerSender.getUniqueId()))
|
||||
{
|
||||
sender.sendActionBar(Component.text("You are hidden from other players.").color(NamedTextColor.GOLD));
|
||||
}
|
||||
else
|
||||
{
|
||||
cancel();
|
||||
}
|
||||
}
|
||||
}.runTaskTimer(plugin, 0L, 4L);
|
||||
|
||||
if (silent)
|
||||
{
|
||||
msgNew("<gold>Silently vanished.");
|
||||
}
|
||||
else
|
||||
{
|
||||
msgNew("<gold>You have vanished.");
|
||||
server.broadcast(Component.translatable("multiplayer.player.left", Component.text(playerSender.getName()))
|
||||
.color(NamedTextColor.YELLOW));
|
||||
if (plugin.dc != null) {
|
||||
plugin.dc.messageChatChannel("**" + playerSender.getName() + " left the server" + "**", true);
|
||||
}
|
||||
}
|
||||
|
||||
plugin.cm.messageAllAdmins("<yellow><player> has vanished and is now only visible to admins.", Placeholder.unparsed("player", sender.getName()));
|
||||
|
||||
server.getOnlinePlayers().stream().filter(player -> !plugin.al.isAdmin(player)).forEach(player ->
|
||||
player.hidePlayer(plugin,playerSender));
|
||||
|
||||
plugin.esb.setVanished(playerSender.getName(), true);
|
||||
AdminList.vanished.add(playerSender.getUniqueId());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
@ -1,15 +0,0 @@
|
||||
package me.totalfreedom.totalfreedommod.command;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.ConsoleCommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public enum SourceType
|
||||
{
|
||||
ONLY_IN_GAME, ONLY_CONSOLE, BOTH;
|
||||
|
||||
public boolean permissionCheck(CommandSender sender)
|
||||
{
|
||||
return (sender instanceof Player && this == ONLY_IN_GAME) || (sender instanceof ConsoleCommandSender && this == ONLY_CONSOLE) || this == BOTH;
|
||||
}
|
||||
}
|
@ -1,70 +0,0 @@
|
||||
package me.totalfreedom.totalfreedommod.fun;
|
||||
|
||||
import me.totalfreedom.totalfreedommod.FreedomService;
|
||||
import me.totalfreedom.totalfreedommod.api.ShopItem;
|
||||
import me.totalfreedom.totalfreedommod.util.ParticleDisplay;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.player.PlayerMoveEvent;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.SplittableRandom;
|
||||
import java.util.UUID;
|
||||
|
||||
public class Trailer extends FreedomService
|
||||
{
|
||||
private final SplittableRandom random = new SplittableRandom();
|
||||
private final Map<UUID, ParticleDisplay> trailPlayers = new HashMap<>(); // player UUID and relative particle instance.
|
||||
|
||||
@Override
|
||||
public void onStart()
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStop()
|
||||
{
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void onPlayerMove(PlayerMoveEvent event)
|
||||
{
|
||||
if (plugin.sh == null) return; // Shop is disabled
|
||||
|
||||
/* Doesn't continue any further if...
|
||||
* - The trail list is empty
|
||||
* - The player doesn't have their trail enabled in the first place
|
||||
* - The player doesn't have the trail item in the shop at all
|
||||
* - The player doesn't have permission to modify blocks in their current world
|
||||
*/
|
||||
if (trailPlayers.isEmpty()
|
||||
|| !trailPlayers.containsKey(event.getPlayer().getUniqueId())
|
||||
|| !plugin.pl.getData(event.getPlayer()).hasItem(ShopItem.RAINBOW_TRAIL))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
final Player player = event.getPlayer();
|
||||
final ParticleDisplay particleDisplay = trailPlayers.get(player.getUniqueId());
|
||||
particleDisplay.spawnNext(player);
|
||||
}
|
||||
|
||||
public void remove(Player player)
|
||||
{
|
||||
trailPlayers.remove(player.getUniqueId());
|
||||
}
|
||||
|
||||
public void add(Player player)
|
||||
{
|
||||
if (trailPlayers.containsKey(player.getUniqueId())) return;
|
||||
|
||||
trailPlayers.put(player.getUniqueId(), new ParticleDisplay());
|
||||
}
|
||||
|
||||
public boolean contains(Player player)
|
||||
{
|
||||
return trailPlayers.containsKey(player.getUniqueId());
|
||||
}
|
||||
}
|
@ -1,60 +0,0 @@
|
||||
package me.totalfreedom.totalfreedommod.httpd.module;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
|
||||
import me.totalfreedom.totalfreedommod.httpd.NanoHTTPD;
|
||||
import me.totalfreedom.totalfreedommod.rank.GroupProvider;
|
||||
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||
import org.bukkit.entity.HumanEntity;
|
||||
import org.json.simple.JSONArray;
|
||||
import org.json.simple.JSONObject;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class Module_players extends HTTPDModule
|
||||
{
|
||||
private static final Gson gson = new Gson();
|
||||
|
||||
public Module_players(NanoHTTPD.HTTPSession session)
|
||||
{
|
||||
super(session);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NanoHTTPD.Response getResponse()
|
||||
{
|
||||
final Map<String, List<String>> responseMap = new HashMap<>();
|
||||
|
||||
final List<String> admins = new ArrayList<>();
|
||||
final List<String> senioradmins = new ArrayList<>();
|
||||
|
||||
plugin.al.getActiveAdmins().stream().filter(admin -> admin.getName() != null).forEach(admin ->
|
||||
{
|
||||
// Do nothing, keeps Codacy quiet
|
||||
if (admin.getRank().equals(GroupProvider.ADMIN.getGroup()))
|
||||
{
|
||||
admins.add(admin.getName());
|
||||
} else if (admin.getRank().equals(GroupProvider.SENIOR_ADMIN.getGroup()))
|
||||
{
|
||||
senioradmins.add(admin.getName());
|
||||
}
|
||||
});
|
||||
|
||||
responseMap.put("players", server.getOnlinePlayers().stream().filter(player ->
|
||||
!plugin.al.isVanished(player.getUniqueId())).map(HumanEntity::getName).toList());
|
||||
responseMap.put("masterbuilders", plugin.pl.getMasterBuilderNames());
|
||||
responseMap.put("admins", admins);
|
||||
responseMap.put("senioradmins", senioradmins);
|
||||
responseMap.put("developers", FUtil.DEVELOPER_NAMES);
|
||||
responseMap.put("assistantexecutives", ConfigEntry.SERVER_ASSISTANT_EXECUTIVES.getStringList());
|
||||
responseMap.put("executives", ConfigEntry.SERVER_EXECUTIVES.getStringList());
|
||||
|
||||
final NanoHTTPD.Response response = new NanoHTTPD.Response(NanoHTTPD.Response.Status.OK, NanoHTTPD.MIME_JSON,
|
||||
gson.toJson(responseMap));
|
||||
response.addHeader("Access-Control-Allow-Origin", "*");
|
||||
return response;
|
||||
}
|
||||
}
|
@ -1,31 +0,0 @@
|
||||
package me.totalfreedom.totalfreedommod.rank;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.TextColor;
|
||||
|
||||
public interface Displayable
|
||||
{
|
||||
Component getArticle();
|
||||
|
||||
Component getName();
|
||||
|
||||
Component getTag();
|
||||
|
||||
Component getAbbr();
|
||||
|
||||
Component getPlural();
|
||||
|
||||
TextColor getColor();
|
||||
|
||||
org.bukkit.ChatColor getTeamColor();
|
||||
|
||||
Component getColoredName();
|
||||
|
||||
Component getColoredTag();
|
||||
|
||||
Component getColoredLoginMessage();
|
||||
|
||||
boolean hasTeam();
|
||||
|
||||
boolean hasDefaultLoginMessage();
|
||||
}
|
@ -1,184 +0,0 @@
|
||||
package me.totalfreedom.totalfreedommod.rank;
|
||||
|
||||
import me.totalfreedom.totalfreedommod.TotalFreedomMod;
|
||||
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.TextColor;
|
||||
import net.luckperms.api.model.data.DataType;
|
||||
import net.luckperms.api.model.group.Group;
|
||||
import net.luckperms.api.node.types.InheritanceNode;
|
||||
import net.luckperms.api.node.types.PrefixNode;
|
||||
import net.luckperms.api.node.types.WeightNode;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Locale;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
public class DisplayableGroup implements Displayable
|
||||
{
|
||||
private final Group group;
|
||||
|
||||
private final Component name;
|
||||
|
||||
private final Component abbr;
|
||||
private final Component plural;
|
||||
private final Component article;
|
||||
private final int weight;
|
||||
|
||||
private final Component tag;
|
||||
|
||||
private final Component coloredTag;
|
||||
|
||||
private final TextColor color;
|
||||
|
||||
private final org.bukkit.ChatColor teamColor;
|
||||
|
||||
private final boolean hasTeam;
|
||||
|
||||
private final boolean hasDefaultLoginMessage;
|
||||
|
||||
public DisplayableGroup(String group,
|
||||
String inheritance,
|
||||
Component plural,
|
||||
Component tag,
|
||||
int weight,
|
||||
TextColor color,
|
||||
org.bukkit.ChatColor teamColor,
|
||||
boolean hasTeam,
|
||||
boolean hasDefaultLoginMessage)
|
||||
{
|
||||
Group matched = TotalFreedomMod.getPlugin().lpb.getAPI().getGroupManager().getGroup(group);
|
||||
|
||||
if (matched == null)
|
||||
{
|
||||
CompletableFuture<Group> cfg = TotalFreedomMod.getPlugin()
|
||||
.lpb
|
||||
.getAPI()
|
||||
.getGroupManager()
|
||||
.createAndLoadGroup(group);
|
||||
|
||||
cfg.thenAcceptAsync(g ->
|
||||
{
|
||||
WeightNode weightNode = WeightNode.builder(weight).build();
|
||||
PrefixNode prefixNode = PrefixNode.builder()
|
||||
.prefix(FUtil.miniMessage(GroupProvider.OPEN.append(tag.color(color)).append(GroupProvider.CLOSE)))
|
||||
.priority(1)
|
||||
.build();
|
||||
if (inheritance != null)
|
||||
{
|
||||
InheritanceNode inheritanceNode = InheritanceNode.builder(inheritance).build();
|
||||
g.getData(DataType.NORMAL).add(inheritanceNode);
|
||||
}
|
||||
g.getData(DataType.NORMAL).add(prefixNode);
|
||||
g.getData(DataType.NORMAL).add(weightNode);
|
||||
}).join(); // Block until the group is created and loaded.
|
||||
|
||||
matched = TotalFreedomMod.getPlugin().lpb.getAPI().getGroupManager().getGroup(group);
|
||||
|
||||
if (matched == null)
|
||||
throw new IllegalArgumentException("Group " + group + " does not exist and could not be created.");
|
||||
}
|
||||
|
||||
this.group = matched;
|
||||
this.name = (matched.getDisplayName() != null) ? FUtil.miniMessage(matched.getDisplayName()) : FUtil.miniMessage(matched.getName());
|
||||
this.plural = plural;
|
||||
this.article = StringUtils.startsWithAny(this.name.toString().toLowerCase(Locale.ROOT), new String[]{"a", "e", "i", "o", "u"}) ? Component.text("an") : Component.text("a");
|
||||
this.abbr = tag;
|
||||
this.weight = weight;
|
||||
this.tag = GroupProvider.OPEN.append(tag).append(GroupProvider.CLOSE);
|
||||
this.color = color;
|
||||
this.teamColor = teamColor;
|
||||
this.hasTeam = hasTeam;
|
||||
this.coloredTag = tag.color(color);
|
||||
this.hasDefaultLoginMessage = hasDefaultLoginMessage;
|
||||
}
|
||||
|
||||
public boolean isAtLeast(@NotNull DisplayableGroup rank)
|
||||
{
|
||||
return rank.getLuckPermsGroup().getWeight().orElse(0)
|
||||
<= getLuckPermsGroup().getWeight().orElse(0);
|
||||
}
|
||||
|
||||
public int getWeight()
|
||||
{
|
||||
return weight;
|
||||
}
|
||||
|
||||
public Group getLuckPermsGroup()
|
||||
{
|
||||
return this.group;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Component getArticle()
|
||||
{
|
||||
return this.article;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Component getName()
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Component getTag()
|
||||
{
|
||||
return tag;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Component getAbbr()
|
||||
{
|
||||
return abbr;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Component getPlural()
|
||||
{
|
||||
return plural;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TextColor getColor()
|
||||
{
|
||||
return color;
|
||||
}
|
||||
|
||||
@Override
|
||||
public org.bukkit.ChatColor getTeamColor()
|
||||
{
|
||||
return teamColor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Component getColoredName()
|
||||
{
|
||||
return name.color(color);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Component getColoredTag()
|
||||
{
|
||||
return coloredTag;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Component getColoredLoginMessage()
|
||||
{
|
||||
return article.append(Component.text(" ")).append(name.color(color));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasTeam()
|
||||
{
|
||||
return hasTeam;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasDefaultLoginMessage()
|
||||
{
|
||||
return hasDefaultLoginMessage;
|
||||
}
|
||||
}
|
@ -1,51 +0,0 @@
|
||||
package me.totalfreedom.totalfreedommod.rank;
|
||||
|
||||
import me.totalfreedom.totalfreedommod.TotalFreedomMod;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import net.luckperms.api.model.user.User;
|
||||
import net.luckperms.api.track.TrackManager;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface GroupProvider<T extends DisplayableGroup>
|
||||
{
|
||||
Component OPEN = Component.text("[", NamedTextColor.DARK_GRAY);
|
||||
Component CLOSE = Component.text("]", NamedTextColor.DARK_GRAY);
|
||||
|
||||
GroupProvider<DisplayableGroup> NON_OP = () -> new DisplayableGroup("default", null, Component.text("Non-Ops"), Component.empty(), 0, NamedTextColor.WHITE, null, false, false);
|
||||
GroupProvider<DisplayableGroup> OP = () -> new DisplayableGroup("op", "default", Component.text("Operators"), Component.text("Op"), 1, NamedTextColor.GREEN, null, false, false);
|
||||
GroupProvider<DisplayableGroup> MASTER_BUILDER = () -> new DisplayableGroup("builder", "op", Component.text("Master Builders"), Component.text("MB"), 2, NamedTextColor.DARK_AQUA, ChatColor.DARK_AQUA, true, true);
|
||||
GroupProvider<DisplayableGroup> ADMIN = () -> new DisplayableGroup("admin", "builder", Component.text("Administrators"), Component.text("Admin"), 3, NamedTextColor.DARK_GREEN, ChatColor.DARK_GREEN, true, true);
|
||||
GroupProvider<DisplayableGroup> SENIOR_ADMIN = () -> new DisplayableGroup("senior", "admin", Component.text("Senior Administrators"), Component.text("SrA"), 4, NamedTextColor.GOLD, ChatColor.GOLD, true, true);
|
||||
|
||||
static User getUser(Player player)
|
||||
{
|
||||
return TotalFreedomMod.getPlugin()
|
||||
.lpb.getAPI()
|
||||
.getPlayerAdapter(Player.class)
|
||||
.getUser(player);
|
||||
}
|
||||
|
||||
static GroupProvider<DisplayableGroup> fromArgument(String arg)
|
||||
{
|
||||
return switch (arg.toLowerCase())
|
||||
{
|
||||
case "op" -> OP;
|
||||
case "builder" -> MASTER_BUILDER;
|
||||
case "admin" -> ADMIN;
|
||||
case "senior" -> SENIOR_ADMIN;
|
||||
default -> NON_OP;
|
||||
};
|
||||
}
|
||||
|
||||
static Set<GroupProvider<DisplayableGroup>> providerSet()
|
||||
{
|
||||
return Set.of(NON_OP, OP, MASTER_BUILDER, ADMIN, SENIOR_ADMIN);
|
||||
}
|
||||
|
||||
T getGroup();
|
||||
}
|
@ -1,193 +0,0 @@
|
||||
package me.totalfreedom.totalfreedommod.rank;
|
||||
|
||||
import me.totalfreedom.totalfreedommod.TotalFreedomMod;
|
||||
import me.totalfreedom.totalfreedommod.util.FLog;
|
||||
import net.luckperms.api.LuckPerms;
|
||||
import net.luckperms.api.model.group.Group;
|
||||
import net.luckperms.api.model.user.User;
|
||||
import net.luckperms.api.query.QueryOptions;
|
||||
import net.luckperms.api.track.PromotionResult;
|
||||
import net.luckperms.api.track.Track;
|
||||
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
public class Hierarchy
|
||||
{
|
||||
private final LuckPerms lp;
|
||||
private final Track track;
|
||||
|
||||
public Hierarchy(String name)
|
||||
{
|
||||
this.lp = TotalFreedomMod.getPlugin().lpb.getAPI();
|
||||
|
||||
if (lp == null)
|
||||
{
|
||||
throw new IllegalStateException("LuckPerms not found!");
|
||||
}
|
||||
|
||||
if (!lp.getTrackManager().isLoaded(name))
|
||||
{
|
||||
this.track = lp.getTrackManager().createAndLoadTrack(name).whenComplete((ignored, throwable) ->
|
||||
{
|
||||
if (throwable != null)
|
||||
{
|
||||
throw new IllegalStateException("Failed to create track " + name, throwable);
|
||||
}
|
||||
}).join(); // Block and wait for the track to load.
|
||||
} else
|
||||
{
|
||||
this.track = lp.getTrackManager().getTrack(name);
|
||||
}
|
||||
}
|
||||
|
||||
public void addGroup(DisplayableGroup group)
|
||||
{
|
||||
updateAppend(group.getLuckPermsGroup()).join(); // wait for the group to be updated.
|
||||
}
|
||||
|
||||
public void addGroup(Group group, int index)
|
||||
{
|
||||
updateInsert(group, index).join(); // wait for the group to be updated.
|
||||
}
|
||||
|
||||
public void dropGroup(Group group) // This is non-blocking by default.
|
||||
{
|
||||
updateDrop(group).whenComplete((ignored, throwable) ->
|
||||
{
|
||||
if (throwable != null)
|
||||
{
|
||||
FLog.severe("Failed to update track " + track.getName());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void addGroupNonBlocking(Group group, int index)
|
||||
{
|
||||
updateInsert(group, index).whenComplete((ignored, throwable) ->
|
||||
{
|
||||
if (throwable != null)
|
||||
{
|
||||
FLog.severe("Failed to update track " + track.getName());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public CompletableFuture<Boolean> trackUser(User user)
|
||||
{
|
||||
Group group = fromName(track.getGroups().get(0)); // First group.
|
||||
|
||||
return CompletableFuture.supplyAsync(() ->
|
||||
lp.getContextManager()
|
||||
.getContext(user)
|
||||
.map(context -> user
|
||||
.getInheritedGroups(QueryOptions.defaultContextualOptions())
|
||||
.add(group))
|
||||
.orElse(false));
|
||||
}
|
||||
|
||||
public CompletableFuture<PromotionResult> promoteUser(User user)
|
||||
{
|
||||
boolean empty = user.getInheritedGroups(QueryOptions.defaultContextualOptions())
|
||||
.stream()
|
||||
.filter(group -> track.getGroups().contains(group.getName()))
|
||||
.findFirst()
|
||||
.isEmpty();
|
||||
|
||||
if (empty) trackUser(user).whenComplete((ignored, throwable) ->
|
||||
{
|
||||
if (throwable != null)
|
||||
{
|
||||
FLog.severe("Failed to track user " + user.getFriendlyName());
|
||||
}
|
||||
});
|
||||
|
||||
return CompletableFuture.supplyAsync(() ->
|
||||
{
|
||||
AtomicReference<PromotionResult> result = new AtomicReference<>();
|
||||
lp.getContextManager()
|
||||
.getContext(user)
|
||||
.ifPresent(context -> result.set(track.promote(user, context)));
|
||||
return result.get();
|
||||
});
|
||||
}
|
||||
|
||||
public void dropUserFromAll(User user)
|
||||
{
|
||||
for (String group : track.getGroups())
|
||||
{
|
||||
dropUserFromGroup(user, fromName(group))
|
||||
.whenComplete((ignored, throwable) ->
|
||||
{
|
||||
if (throwable != null)
|
||||
{
|
||||
FLog.severe("Failed to drop user "
|
||||
+ user.getFriendlyName()
|
||||
+ " from group "
|
||||
+ group);
|
||||
return;
|
||||
}
|
||||
FLog.info("Successfully removed " + user.getFriendlyName() + " from group " + group);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public CompletableFuture<Void> demoteUser(User user)
|
||||
{
|
||||
return CompletableFuture.supplyAsync(() -> {
|
||||
lp.getContextManager()
|
||||
.getContext(user)
|
||||
.ifPresent(context -> track.demote(user, context));
|
||||
return null;
|
||||
});
|
||||
}
|
||||
|
||||
public CompletableFuture<Boolean> dropUserFromGroup(User user, Group group)
|
||||
{
|
||||
return CompletableFuture.supplyAsync(() -> user
|
||||
.getInheritedGroups(QueryOptions.defaultContextualOptions())
|
||||
.remove(group));
|
||||
}
|
||||
|
||||
public Group fromName(String name)
|
||||
{
|
||||
return lp.getGroupManager().getGroup(name);
|
||||
}
|
||||
|
||||
public CompletableFuture<Void> updateAppend(Group group)
|
||||
{
|
||||
return CompletableFuture.supplyAsync(() ->
|
||||
{
|
||||
if (!track.containsGroup(group.getName()))
|
||||
{
|
||||
track.appendGroup(group);
|
||||
}
|
||||
return null;
|
||||
});
|
||||
}
|
||||
|
||||
public CompletableFuture<Void> updateInsert(Group group, int index)
|
||||
{
|
||||
return CompletableFuture.supplyAsync(() ->
|
||||
{
|
||||
if (!track.containsGroup(group))
|
||||
{
|
||||
track.insertGroup(group, index);
|
||||
}
|
||||
return null;
|
||||
});
|
||||
}
|
||||
|
||||
public CompletableFuture<Void> updateDrop(Group group)
|
||||
{
|
||||
return CompletableFuture.supplyAsync(() ->
|
||||
{
|
||||
if (track.containsGroup(group))
|
||||
{
|
||||
track.removeGroup(group);
|
||||
}
|
||||
|
||||
return null;
|
||||
});
|
||||
}
|
||||
}
|
@ -1,11 +0,0 @@
|
||||
package me.totalfreedom.totalfreedommod.rank;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface HierarchyProvider<T extends Hierarchy>
|
||||
{
|
||||
HierarchyProvider<Hierarchy> OP = () -> new Hierarchy("op-track");
|
||||
HierarchyProvider<Hierarchy> BUILDER = () -> new Hierarchy("builder-track");
|
||||
HierarchyProvider<Hierarchy> ADMIN = () -> new Hierarchy("admin-track");
|
||||
|
||||
T getHierarchy();
|
||||
}
|
@ -1,154 +0,0 @@
|
||||
package me.totalfreedom.totalfreedommod.rank;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import net.kyori.adventure.text.format.TextColor;
|
||||
|
||||
public enum Title implements Displayable
|
||||
{
|
||||
MASTER_BUILDER(Component.text("a"),
|
||||
Component.text("Master Builder"),
|
||||
Component.text("Master Builders"),
|
||||
NamedTextColor.DARK_AQUA,
|
||||
org.bukkit.ChatColor.DARK_AQUA,
|
||||
Component.text("MB"),
|
||||
true,
|
||||
true),
|
||||
EXECUTIVE(Component.text("an"),
|
||||
Component.text("Executive"),
|
||||
Component.text("Executives"),
|
||||
NamedTextColor.RED,
|
||||
org.bukkit.ChatColor.RED,
|
||||
Component.text("Exec"),
|
||||
true,
|
||||
true),
|
||||
ASST_EXEC(Component.text("an"),
|
||||
Component.text("Assistant Executive"),
|
||||
Component.text("Assistant Executives"),
|
||||
NamedTextColor.RED,
|
||||
org.bukkit.ChatColor.RED,
|
||||
Component.text("Asst Exec"),
|
||||
true,
|
||||
true),
|
||||
DEVELOPER(Component.text("a"),
|
||||
Component.text("Developer"),
|
||||
Component.text("Developers"),
|
||||
NamedTextColor.DARK_PURPLE,
|
||||
org.bukkit.ChatColor.DARK_PURPLE,
|
||||
Component.text("Dev"),
|
||||
true,
|
||||
true),
|
||||
OWNER(Component.text("an"),
|
||||
Component.text("Owner"),
|
||||
Component.text("Owners"),
|
||||
NamedTextColor.DARK_RED,
|
||||
org.bukkit.ChatColor.DARK_RED,
|
||||
Component.text("Owner"),
|
||||
true,
|
||||
true);
|
||||
|
||||
|
||||
private final Component article;
|
||||
|
||||
private final Component name;
|
||||
|
||||
private final Component abbr;
|
||||
private final Component plural;
|
||||
|
||||
private final Component tag;
|
||||
|
||||
private final Component coloredTag;
|
||||
|
||||
private final TextColor color;
|
||||
|
||||
private final org.bukkit.ChatColor teamColor;
|
||||
|
||||
private final boolean hasTeam;
|
||||
private final boolean hasDefaultLoginMessage;
|
||||
|
||||
Title(Component article, Component name, Component plural, TextColor color, org.bukkit.ChatColor teamColor, Component tag, Boolean hasTeam, Boolean hasDefaultLoginMessage)
|
||||
{
|
||||
this.article = article;
|
||||
this.name = name;
|
||||
this.plural = plural;
|
||||
this.coloredTag = tag.color(color);
|
||||
this.abbr = tag;
|
||||
this.tag = GroupProvider.OPEN.append(tag).append(GroupProvider.CLOSE);
|
||||
this.color = color;
|
||||
this.teamColor = teamColor;
|
||||
this.hasTeam = hasTeam;
|
||||
this.hasDefaultLoginMessage = hasDefaultLoginMessage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Component getColoredName()
|
||||
{
|
||||
return name.color(color);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasTeam()
|
||||
{
|
||||
return hasTeam;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasDefaultLoginMessage()
|
||||
{
|
||||
return hasDefaultLoginMessage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Component getColoredLoginMessage()
|
||||
{
|
||||
return article.append(Component.text(" ").append(name.color(color)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Component getArticle()
|
||||
{
|
||||
return article;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Component getName()
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Component getAbbr()
|
||||
{
|
||||
return abbr;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Component getPlural()
|
||||
{
|
||||
return plural;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Component getTag()
|
||||
{
|
||||
return tag;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Component getColoredTag()
|
||||
{
|
||||
return coloredTag;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TextColor getColor()
|
||||
{
|
||||
return color;
|
||||
}
|
||||
|
||||
@Override
|
||||
public org.bukkit.ChatColor getTeamColor()
|
||||
{
|
||||
return teamColor;
|
||||
}
|
||||
}
|
@ -1,33 +0,0 @@
|
||||
package me.totalfreedom.totalfreedommod.util;
|
||||
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class FConverter
|
||||
{
|
||||
private static final Pattern godFuckingDamnit = Pattern.compile(".*(?i)(&((#[a-f0-9]{3,6})|([0-9a-fklmnor]))|%[a-z]+%).*");
|
||||
|
||||
public static boolean needsConversion(String messageOrFormat)
|
||||
{
|
||||
return godFuckingDamnit.matcher(messageOrFormat).find();
|
||||
}
|
||||
|
||||
public static String convertAdminChatFormat(String format)
|
||||
{
|
||||
return FUtil.MINI_MESSAGE.serialize(FUtil.LEGACY_AMPERSAND.deserialize(
|
||||
format.replaceAll("%name%", "<name>")
|
||||
.replaceAll("%rank%", "<rank>")
|
||||
.replaceAll("%rankcolor%", "<rankcolor>")
|
||||
.replaceAll("%msg%", "<message>")))
|
||||
.replaceAll("\\\\<", "<"); // GOD FUCKING DAMMIT
|
||||
}
|
||||
|
||||
public static String convertLoginMessage(String message)
|
||||
{
|
||||
return FUtil.MINI_MESSAGE.serialize(FUtil.LEGACY_AMPERSAND.deserialize(
|
||||
message.replaceAll("%name%", "<name>")
|
||||
.replaceAll("%rank%", "<rank>")
|
||||
.replaceAll("%coloredrank%", "<coloredrank>")
|
||||
.replaceAll("%art%", "<art>")))
|
||||
.replaceAll("\\\\<", "<"); // GOD FUCKING DAMMIT
|
||||
}
|
||||
}
|
@ -1,30 +0,0 @@
|
||||
package me.totalfreedom.totalfreedommod.util;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Biome;
|
||||
import org.bukkit.entity.EntityType;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class Groups
|
||||
{
|
||||
public static final Set<Material> WOOL_COLORS = Arrays.stream(Material.values()).filter((m) -> m.name().endsWith("_WOOL")).collect(Collectors.toSet());
|
||||
public static final Set<Material> SHULKER_BOXES = Arrays.stream(Material.values()).filter((m) -> m.name().endsWith("SHULKER_BOX")).collect(Collectors.toSet());
|
||||
public static final Set<EntityType> MOB_TYPES = Arrays.stream(EntityType.values()).filter(EntityType::isAlive).filter(EntityType::isSpawnable).collect(Collectors.toSet());
|
||||
public static final Set<Material> SPAWN_EGGS = Arrays.stream(Material.values()).filter((mat) -> mat.name().endsWith("_SPAWN_EGG")).collect(Collectors.toSet());
|
||||
public static final Set<Material> BANNERS = Arrays.stream(Material.values()).filter((m) -> m.name().endsWith("_BANNER")).collect(Collectors.toSet());
|
||||
public static final Set<Biome> EXPLOSIVE_BED_BIOMES = new HashSet<>(Arrays.asList(
|
||||
Biome.NETHER_WASTES,
|
||||
Biome.CRIMSON_FOREST,
|
||||
Biome.SOUL_SAND_VALLEY,
|
||||
Biome.WARPED_FOREST,
|
||||
Biome.BASALT_DELTAS,
|
||||
Biome.END_BARRENS,
|
||||
Biome.END_HIGHLANDS,
|
||||
Biome.END_MIDLANDS,
|
||||
Biome.THE_END,
|
||||
Biome.SMALL_END_ISLANDS));
|
||||
}
|
@ -1,110 +0,0 @@
|
||||
package me.totalfreedom.totalfreedommod.util;
|
||||
|
||||
import me.totalfreedom.totalfreedommod.api.Interpolator;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import net.kyori.adventure.text.format.TextColor;
|
||||
import org.bukkit.Color;
|
||||
|
||||
import java.util.LinkedHashSet;
|
||||
|
||||
public class Interpolation
|
||||
{
|
||||
public LinkedHashSet<Color> rainbow(int length)
|
||||
{
|
||||
LinkedHashSet<Color> base = new LinkedHashSet<>();
|
||||
LinkedHashSet<Color> redToOrange = hsvGradient(length, Color.RED, Color.ORANGE, this::linear);
|
||||
LinkedHashSet<Color> orangeToYellow = hsvGradient(length, Color.ORANGE, Color.YELLOW, this::linear);
|
||||
LinkedHashSet<Color> yellowToGreen = hsvGradient(length, Color.YELLOW, Color.GREEN, this::linear);
|
||||
LinkedHashSet<Color> greenToBlue = hsvGradient(length, Color.GREEN, Color.BLUE, this::linear);
|
||||
LinkedHashSet<Color> blueToPurple = hsvGradient(length, Color.BLUE, Color.PURPLE, this::linear);
|
||||
LinkedHashSet<Color> purpleToRed = hsvGradient(length, Color.PURPLE, Color.RED, this::linear);
|
||||
base.addAll(redToOrange);
|
||||
base.addAll(orangeToYellow);
|
||||
base.addAll(yellowToGreen);
|
||||
base.addAll(greenToBlue);
|
||||
base.addAll(blueToPurple);
|
||||
base.addAll(purpleToRed);
|
||||
return base;
|
||||
}
|
||||
|
||||
private double[] linear(double from, double to, int max)
|
||||
{
|
||||
final double[] res = new double[max];
|
||||
for (int i = 0; i < max; i++)
|
||||
{
|
||||
res[i] = from + i * ((to - from) / (max - 1));
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
private LinkedHashSet<Color> hsvGradient(int length, Color from, Color to, Interpolator interpolator)
|
||||
{
|
||||
// returns a float-array where hsv[0] = hue, hsv[1] = saturation, hsv[2] = value/brightness
|
||||
final float[] hsvFrom = java.awt.Color.RGBtoHSB(from.getRed(), from.getGreen(), from.getBlue(), null);
|
||||
final float[] hsvTo = java.awt.Color.RGBtoHSB(to.getRed(), to.getGreen(), to.getBlue(), null);
|
||||
|
||||
final double[] h = interpolator.interpolate(hsvFrom[0], hsvTo[0], length);
|
||||
final double[] s = interpolator.interpolate(hsvFrom[1], hsvTo[1], length);
|
||||
final double[] v = interpolator.interpolate(hsvFrom[2], hsvTo[2], length);
|
||||
|
||||
final LinkedHashSet<Color> gradient = new LinkedHashSet<>();
|
||||
|
||||
for (int i = 0; i < length; i++)
|
||||
{
|
||||
final int rgb = java.awt.Color.HSBtoRGB((float) h[i], (float) s[i], (float) v[i]);
|
||||
final Color color = Color.fromRGB(rgb);
|
||||
gradient.add(color);
|
||||
}
|
||||
return gradient;
|
||||
}
|
||||
|
||||
public LinkedHashSet<Color> rgbGradient(int length, Color from, Color to, Interpolator interpolator)
|
||||
{
|
||||
final double[] r = interpolator.interpolate(from.getRed(), to.getRed(), length);
|
||||
final double[] g = interpolator.interpolate(from.getGreen(), to.getGreen(), length);
|
||||
final double[] b = interpolator.interpolate(from.getBlue(), to.getBlue(), length);
|
||||
|
||||
final LinkedHashSet<Color> gradient = new LinkedHashSet<>();
|
||||
|
||||
for (int i = 0; i < length; i++)
|
||||
{
|
||||
final Color color = Color.fromRGB((int) r[i], (int) g[i], (int) b[i]);
|
||||
gradient.add(color);
|
||||
}
|
||||
return gradient;
|
||||
}
|
||||
|
||||
public LinkedHashSet<TextColor> componentRGBGradient(int length, TextColor from, TextColor to, Interpolator interpolator)
|
||||
{
|
||||
final double[] r = interpolator.interpolate(from.red(), to.red(), length);
|
||||
final double[] g = interpolator.interpolate(from.green(), to.green(), length);
|
||||
final double[] b = interpolator.interpolate(from.blue(), to.blue(), length);
|
||||
|
||||
final LinkedHashSet<TextColor> gradient = new LinkedHashSet<>();
|
||||
|
||||
for (int i = 0; i < length; i++)
|
||||
{
|
||||
final TextColor color = TextColor.color((int) r[i], (int) g[i], (int) b[i]);
|
||||
gradient.add(color);
|
||||
}
|
||||
return gradient;
|
||||
}
|
||||
|
||||
public LinkedHashSet<TextColor> rainbowComponent(int length)
|
||||
{
|
||||
LinkedHashSet<TextColor> base = new LinkedHashSet<>();
|
||||
LinkedHashSet<TextColor> redToOrange = componentRGBGradient(length, NamedTextColor.RED, NamedTextColor.GOLD, this::linear);
|
||||
LinkedHashSet<TextColor> orangeToYellow = componentRGBGradient(length, NamedTextColor.GOLD, NamedTextColor.YELLOW, this::linear);
|
||||
LinkedHashSet<TextColor> yellowToGreen = componentRGBGradient(length, NamedTextColor.YELLOW, NamedTextColor.GREEN, this::linear);
|
||||
LinkedHashSet<TextColor> greenToBlue = componentRGBGradient(length, NamedTextColor.GREEN, NamedTextColor.BLUE, this::linear);
|
||||
LinkedHashSet<TextColor> blueToPurple = componentRGBGradient(length, NamedTextColor.BLUE, NamedTextColor.LIGHT_PURPLE, this::linear);
|
||||
LinkedHashSet<TextColor> purpleToRed = componentRGBGradient(length, TextColor.color(75, 0, 130), TextColor.color(255, 0, 0), this::linear);
|
||||
base.addAll(redToOrange);
|
||||
base.addAll(orangeToYellow);
|
||||
base.addAll(yellowToGreen);
|
||||
base.addAll(greenToBlue);
|
||||
base.addAll(blueToPurple);
|
||||
base.addAll(purpleToRed);
|
||||
return base;
|
||||
}
|
||||
}
|
@ -1,57 +0,0 @@
|
||||
package me.totalfreedom.totalfreedommod.util;
|
||||
|
||||
import com.destroystokyo.paper.ParticleBuilder;
|
||||
import org.bukkit.Color;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Particle;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.util.Vector;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
public class ParticleDisplay
|
||||
{
|
||||
private final Interpolation interpolation;
|
||||
private Iterator<Color> colorIterator;
|
||||
|
||||
public ParticleDisplay()
|
||||
{
|
||||
this.interpolation = new Interpolation();
|
||||
this.colorIterator = interpolation.rainbow(43).iterator();
|
||||
}
|
||||
|
||||
public void spawnNext(Player player)
|
||||
{
|
||||
Location location = getBehind(player);
|
||||
Color color = getIterator().next();
|
||||
Particle.DustOptions options = new Particle.DustOptions(color, 3);
|
||||
ParticleBuilder builder = new ParticleBuilder(Particle.REDSTONE);
|
||||
builder.data(options)
|
||||
.receivers(30, 15, true)
|
||||
.offset(0.5, 0.5, 0.5)
|
||||
.location(location)
|
||||
.spawn();
|
||||
}
|
||||
|
||||
private Location getBehind(Player player)
|
||||
{
|
||||
@NotNull Vector inverse = player.getLocation()
|
||||
.clone()
|
||||
.getDirection()
|
||||
.normalize()
|
||||
.multiply(-1);
|
||||
|
||||
return player.getLocation().add(inverse);
|
||||
}
|
||||
|
||||
private Iterator<Color> getIterator()
|
||||
{
|
||||
if (!this.colorIterator.hasNext())
|
||||
{
|
||||
this.colorIterator = interpolation.rainbow(43).iterator();
|
||||
}
|
||||
|
||||
return this.colorIterator;
|
||||
}
|
||||
}
|
@ -1,28 +0,0 @@
|
||||
package me.totalfreedom.totalfreedommod.util;
|
||||
|
||||
public class PermissibleCompletion
|
||||
{
|
||||
private final String permission;
|
||||
private final String completion;
|
||||
|
||||
public PermissibleCompletion(String permission, String completion)
|
||||
{
|
||||
this.completion = completion;
|
||||
this.permission = permission;
|
||||
}
|
||||
|
||||
public String getPermission()
|
||||
{
|
||||
return permission;
|
||||
}
|
||||
|
||||
public String getCompletion()
|
||||
{
|
||||
return completion;
|
||||
}
|
||||
|
||||
public static PermissibleCompletion of(String permission, String completion)
|
||||
{
|
||||
return new PermissibleCompletion(permission, completion);
|
||||
}
|
||||
}
|
@ -1,46 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>me.totalfreedom</groupId>
|
||||
<artifactId>TotalFreedomMod</artifactId>
|
||||
<version>2023.03</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>discord</artifactId>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>17</maven.compiler.source>
|
||||
<maven.compiler.target>17</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.discord4j</groupId>
|
||||
<artifactId>discord4j-core</artifactId>
|
||||
<version>3.2.3</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>me.totalfreedom</groupId>
|
||||
<artifactId>commons</artifactId>
|
||||
<version>2023.03</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.projectreactor</groupId>
|
||||
<artifactId>reactor-core</artifactId>
|
||||
<version>3.5.4</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>me.totalfreedom</groupId>
|
||||
<artifactId>commons</artifactId>
|
||||
<version>2023.03</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
@ -1,95 +0,0 @@
|
||||
package me.totalfreedom.discord;
|
||||
|
||||
import discord4j.core.DiscordClientBuilder;
|
||||
import discord4j.core.GatewayDiscordClient;
|
||||
import discord4j.core.event.domain.interaction.ChatInputInteractionEvent;
|
||||
import discord4j.core.object.entity.Guild;
|
||||
import me.totalfreedom.discord.command.HelpCommand;
|
||||
import me.totalfreedom.discord.command.ListCommand;
|
||||
import me.totalfreedom.discord.command.TPSCommand;
|
||||
import me.totalfreedom.discord.handling.CommandHandler;
|
||||
import me.totalfreedom.discord.react.ReactiveBukkitScheduler;
|
||||
import me.totalfreedom.discord.util.SnowflakeEntry;
|
||||
import me.totalfreedom.discord.util.TFM_Bridge;
|
||||
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
|
||||
import me.totalfreedom.totalfreedommod.player.PlayerData;
|
||||
import me.totalfreedom.totalfreedommod.util.FLog;
|
||||
import org.bukkit.Bukkit;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class Bot
|
||||
{
|
||||
private final GatewayDiscordClient client;
|
||||
private final TFM_Bridge tfm;
|
||||
private final HashMap<String, PlayerData> LINK_CODES = new HashMap<>();
|
||||
public Bot()
|
||||
{
|
||||
//Creates the gateway client and connects to the gateway
|
||||
this.client = DiscordClientBuilder.create(ConfigEntry.DISCORD_TOKEN.getString())
|
||||
.build()
|
||||
.login()
|
||||
.block();
|
||||
|
||||
this.tfm = new TFM_Bridge(this);
|
||||
}
|
||||
|
||||
public void initialize() {
|
||||
if (client == null) throw new IllegalStateException();
|
||||
}
|
||||
|
||||
public String formatBotTag() {
|
||||
return client.getSelf()
|
||||
.blockOptional()
|
||||
.orElseThrow()
|
||||
.getUsername() + "#" + client.getSelf()
|
||||
.blockOptional()
|
||||
.orElseThrow()
|
||||
.getDiscriminator();
|
||||
}
|
||||
|
||||
public TFM_Bridge getTFM()
|
||||
{
|
||||
return tfm;
|
||||
}
|
||||
|
||||
public Mono<Guild> getGuildById()
|
||||
{
|
||||
return client.getGuildById(SnowflakeEntry.SERVER_ID.getSnowflake());
|
||||
}
|
||||
|
||||
public GatewayDiscordClient getClient()
|
||||
{
|
||||
return client;
|
||||
}
|
||||
|
||||
public Map<String, PlayerData> getLinkCodes()
|
||||
{
|
||||
return LINK_CODES;
|
||||
}
|
||||
|
||||
public boolean shouldISendReport()
|
||||
{
|
||||
if (ConfigEntry.DISCORD_REPORT_CHANNEL_ID.getString().isEmpty())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (ConfigEntry.DISCORD_SERVER_ID.getString().isEmpty())
|
||||
{
|
||||
FLog.severe("No Discord server ID was specified in the config, but there is a report channel ID.");
|
||||
return false;
|
||||
}
|
||||
|
||||
Guild server = client.getGuildById(SnowflakeEntry.SERVER_ID.getSnowflake()).block();
|
||||
if (server == null)
|
||||
{
|
||||
FLog.severe("The Discord server ID specified is invalid, or the bot is not on the server.");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
@ -1,124 +0,0 @@
|
||||
package me.totalfreedom.discord;
|
||||
|
||||
import discord4j.core.event.domain.interaction.ChatInputInteractionEvent;
|
||||
import me.totalfreedom.discord.command.HelpCommand;
|
||||
import me.totalfreedom.discord.command.ListCommand;
|
||||
import me.totalfreedom.discord.command.TPSCommand;
|
||||
import me.totalfreedom.discord.handling.CommandHandler;
|
||||
import me.totalfreedom.discord.listener.*;
|
||||
import me.totalfreedom.discord.react.ReactiveBukkitScheduler;
|
||||
import me.totalfreedom.totalfreedommod.api.Context;
|
||||
import me.totalfreedom.totalfreedommod.api.TFD4JCommons;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.slf4j.Logger;
|
||||
|
||||
/**
|
||||
* @author Paldiu
|
||||
* @author videogamesm12
|
||||
* @since 2023-03-16
|
||||
*/
|
||||
public class TFD4J extends JavaPlugin
|
||||
{
|
||||
private final Logger slf4j = this.getSLF4JLogger();
|
||||
private Bot bot;
|
||||
private MinecraftListener mc;
|
||||
private AdminChatListener ac;
|
||||
private PrivateMessageListener pm;
|
||||
private ReactionListener rl;
|
||||
private TFD4JCommons tfd4jcommons;
|
||||
private BukkitNative bn;
|
||||
private CommandHandler ch;
|
||||
private ReactiveBukkitScheduler rbs;
|
||||
|
||||
@Override
|
||||
public void onEnable()
|
||||
{
|
||||
slf4j().info("Hello from TFD4J! Initializing our API implementation...");
|
||||
this.tfd4jcommons = new TFD4JCommonsImpl(this);
|
||||
|
||||
slf4j().info("API successfully initialized! Initializing our bot...");
|
||||
this.bot = new Bot();
|
||||
bot.initialize();
|
||||
|
||||
slf4j().info("Bot successfully initialized! Abstracting the BukkitScheduler...");
|
||||
this.rbs = new ReactiveBukkitScheduler(this);
|
||||
|
||||
String string = String.format("Scheduler successfully wrapped into %s! Registering the Bukkit Native listener...", ReactiveBukkitScheduler.class.getName()); // Fixes SonarLint's "Invoke methods only conditionally."
|
||||
|
||||
slf4j().info(string);
|
||||
this.bn = new BukkitNative(this);
|
||||
Bukkit.getPluginManager().registerEvents(this.bn, this);
|
||||
|
||||
slf4j().info("Bukkit Native listener successfully registered! Registering the Discord4J Listeners...");
|
||||
this.mc = new MinecraftListener(this);
|
||||
this.ac = new AdminChatListener(this);
|
||||
this.pm = new PrivateMessageListener(this);
|
||||
this.rl = new ReactionListener(this);
|
||||
pm.privateMessageReceived();
|
||||
rl.onReactionAdd();
|
||||
mc.minecraftChatBound();
|
||||
ac.adminChatBound();
|
||||
|
||||
slf4j().info("Discord4J listeners successfully registered! Registering the Command Handler...");
|
||||
this.ch = new CommandHandler(bot.getClient().getRestClient());
|
||||
|
||||
slf4j().info("Command Handler successfully registered! Registering commands...");
|
||||
this.ch.registerCommand(new HelpCommand());
|
||||
this.ch.registerCommand(new ListCommand());
|
||||
this.ch.registerCommand(new TPSCommand());
|
||||
|
||||
this.getBot().getClient().on(ChatInputInteractionEvent.class, ch::handle)
|
||||
.subscribeOn(getReactiveBukkitScheduler())
|
||||
.subscribe();
|
||||
|
||||
slf4j().info("Commands successfully registered! Providing context to TFM...");
|
||||
Context<TFD4JCommons> context = new Context<>(tfd4jcommons);
|
||||
bot.getTFM().getCommons().ag.setDiscordContext(context);
|
||||
bot.getTFM().getCommons().registerDiscord();
|
||||
|
||||
slf4j().info("Context provided! TFD4J is now ready to go!");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable()
|
||||
{
|
||||
slf4j().info("Disconnecting the Discord bot...");
|
||||
bot.getClient()
|
||||
.onDisconnect()
|
||||
.doOnError(th -> slf4j().error("Error disconnecting the bot!", th))
|
||||
.doOnSuccess(v -> slf4j().info("Bot disconnected!"))
|
||||
.subscribe();
|
||||
slf4j().info("Goodbye from TFD4J!");
|
||||
}
|
||||
|
||||
public Logger slf4j()
|
||||
{
|
||||
return slf4j;
|
||||
}
|
||||
|
||||
public Bot getBot()
|
||||
{
|
||||
return bot;
|
||||
}
|
||||
|
||||
public TFD4JCommons getImpl()
|
||||
{
|
||||
return tfd4jcommons;
|
||||
}
|
||||
|
||||
public MinecraftListener getMinecraftListener()
|
||||
{
|
||||
return mc;
|
||||
}
|
||||
|
||||
public AdminChatListener getAdminChatListener()
|
||||
{
|
||||
return ac;
|
||||
}
|
||||
|
||||
public ReactiveBukkitScheduler getReactiveBukkitScheduler()
|
||||
{
|
||||
return rbs;
|
||||
}
|
||||
}
|
@ -1,368 +0,0 @@
|
||||
package me.totalfreedom.discord;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import discord4j.common.util.Snowflake;
|
||||
import discord4j.core.object.entity.Guild;
|
||||
import discord4j.core.object.entity.Member;
|
||||
import discord4j.core.object.entity.Message;
|
||||
import discord4j.core.object.entity.Role;
|
||||
import discord4j.core.object.entity.channel.TextChannel;
|
||||
import discord4j.core.object.reaction.ReactionEmoji;
|
||||
import discord4j.core.spec.EmbedCreateSpec;
|
||||
import discord4j.core.spec.MessageCreateSpec;
|
||||
import me.totalfreedom.discord.util.SnowflakeEntry;
|
||||
import me.totalfreedom.discord.util.Utilities;
|
||||
import me.totalfreedom.totalfreedommod.admin.Admin;
|
||||
import me.totalfreedom.totalfreedommod.api.TFD4JCommons;
|
||||
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
|
||||
import me.totalfreedom.totalfreedommod.player.PlayerData;
|
||||
import me.totalfreedom.totalfreedommod.rank.GroupProvider;
|
||||
import me.totalfreedom.totalfreedommod.util.FLog;
|
||||
import org.apache.commons.lang.RandomStringUtils;
|
||||
import org.apache.commons.lang.WordUtils;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
public class TFD4JCommonsImpl implements TFD4JCommons
|
||||
{
|
||||
private final TFD4J tfd4J;
|
||||
private final ImmutableList<String> DISCORD_SUBDOMAINS;
|
||||
private Flux<Message> sentMessages;
|
||||
|
||||
public TFD4JCommonsImpl(TFD4J tfd4J)
|
||||
{
|
||||
this.tfd4J = tfd4J;
|
||||
this.sentMessages = Flux.fromIterable(new ArrayList<>());
|
||||
this.DISCORD_SUBDOMAINS = ImmutableList.of("discordapp.com", "discord.com", "discord.gg");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void messageAdminChatChannel(String message)
|
||||
{
|
||||
String chat_channel_id = ConfigEntry.DISCORD_ADMINCHAT_CHANNEL_ID.getString();
|
||||
|
||||
String sanitizedMessage = sanitizeChatMessage(message);
|
||||
|
||||
if (sanitizedMessage.isBlank()) return;
|
||||
|
||||
if (!chat_channel_id.isEmpty())
|
||||
{
|
||||
MessageCreateSpec spec = MessageCreateSpec.builder()
|
||||
.content(sanitizedMessage)
|
||||
.build();
|
||||
|
||||
Mono<Message> sentMessage = tfd4J
|
||||
.getBot()
|
||||
.getClient()
|
||||
.getChannelById(SnowflakeEntry.ADMIN_CHAT_CHANNEL_ID.getSnowflake())
|
||||
.ofType(TextChannel.class)
|
||||
.flatMap(c -> c.createMessage(spec));
|
||||
|
||||
sentMessage.subscribe();
|
||||
}
|
||||
}
|
||||
|
||||
public Flux<Message> getMessagesSent()
|
||||
{
|
||||
return sentMessages;
|
||||
}
|
||||
|
||||
private void insert(Mono<Message> messageMono)
|
||||
{
|
||||
sentMessages.concatWith(messageMono);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearQueue()
|
||||
{
|
||||
sentMessages = Flux.fromIterable(new ArrayList<>());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void messageChatChannel(String message, boolean system)
|
||||
{
|
||||
String chat_channel_id = ConfigEntry.DISCORD_CHAT_CHANNEL_ID.getString();
|
||||
|
||||
String sanitizedMessage = (system) ? message : sanitizeChatMessage(message);
|
||||
|
||||
if (sanitizedMessage.isBlank()) return;
|
||||
|
||||
if (!chat_channel_id.isEmpty())
|
||||
{
|
||||
MessageCreateSpec spec = MessageCreateSpec.builder()
|
||||
.content(sanitizedMessage)
|
||||
.build();
|
||||
|
||||
Mono<Message> sentMessage = tfd4J
|
||||
.getBot()
|
||||
.getClient()
|
||||
.getChannelById(SnowflakeEntry.CHAT_CHANNEL_ID.getSnowflake())
|
||||
.ofType(TextChannel.class)
|
||||
.flatMap(c -> c.createMessage(spec));
|
||||
|
||||
sentMessage.subscribe();
|
||||
}
|
||||
}
|
||||
|
||||
private String sanitizeChatMessage(String message)
|
||||
{
|
||||
String newMessage = message;
|
||||
|
||||
if (message.contains("@"))
|
||||
{
|
||||
// \u200B is Zero Width Space, invisible on Discord
|
||||
newMessage = message.replace("@", "@\u200B");
|
||||
}
|
||||
|
||||
if (message.toLowerCase().contains("discord.gg")) // discord.gg/invite works as an invite
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
for (String subdomain : DISCORD_SUBDOMAINS)
|
||||
{
|
||||
if (message.toLowerCase().contains(subdomain + "/invite"))
|
||||
{
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
if (message.contains("§"))
|
||||
{
|
||||
newMessage = message.replace("§", "");
|
||||
}
|
||||
|
||||
return Utilities.deformat(newMessage);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean syncRoles(Admin admin, String discordID)
|
||||
{
|
||||
if (discordID == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
Guild server = tfd4J.getBot().getGuildById()
|
||||
.blockOptional()
|
||||
.orElseThrow();
|
||||
|
||||
Member member = server.getMemberById(Snowflake.of(discordID))
|
||||
.blockOptional()
|
||||
.orElseThrow();
|
||||
|
||||
Role adminRole = server.getRoleById(SnowflakeEntry.ADMIN_ROLE_ID.getSnowflake())
|
||||
.blockOptional()
|
||||
.orElseThrow();
|
||||
|
||||
Role senioradminRole = server.getRoleById(SnowflakeEntry.SENIOR_ADMIN_ROLE_ID.getSnowflake())
|
||||
.blockOptional()
|
||||
.orElseThrow();
|
||||
|
||||
if (!admin.isActive())
|
||||
{
|
||||
syncRolesActivityCheck(member, adminRole, senioradminRole);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (admin.getRank().equals(GroupProvider.ADMIN.getGroup()))
|
||||
{
|
||||
syncRolesAdminAssignment(member, adminRole, senioradminRole);
|
||||
return true;
|
||||
} else if (admin.getRank().equals(GroupProvider.SENIOR_ADMIN.getGroup()))
|
||||
{
|
||||
syncRolesSeniorAssignment(member, adminRole, senioradminRole);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private void syncRolesAdminAssignment(Member member, Role adminRole, Role senioradminRole)
|
||||
{
|
||||
member.getRoles().doFirst(() ->
|
||||
{
|
||||
if (!member.getRoles().collectList().blockOptional().orElseThrow().contains(adminRole))
|
||||
{
|
||||
member.addRole(adminRole.getId()).block();
|
||||
}
|
||||
}).doOnEach(r ->
|
||||
{
|
||||
Role role = r.get();
|
||||
if (role == null) return;
|
||||
|
||||
if (role.equals(senioradminRole))
|
||||
{
|
||||
member.removeRole(role.getId()).block();
|
||||
}
|
||||
}).subscribe();
|
||||
}
|
||||
|
||||
private void syncRolesActivityCheck(Member member, Role adminRole, Role senioradminRole)
|
||||
{
|
||||
member.getRoles().doOnEach(r ->
|
||||
{
|
||||
Role role = r.get();
|
||||
if (role == null) return;
|
||||
|
||||
if (role.equals(adminRole) || role.equals(senioradminRole))
|
||||
{
|
||||
member.removeRole(role.getId()).block();
|
||||
}
|
||||
}).subscribe();
|
||||
}
|
||||
|
||||
private void syncRolesSeniorAssignment(Member member, Role adminRole, Role senioradminRole)
|
||||
{
|
||||
member.getRoles().doFirst(() ->
|
||||
{
|
||||
if (!member.getRoles().collectList().blockOptional().orElseThrow().contains(senioradminRole))
|
||||
{
|
||||
member.addRole(senioradminRole.getId()).block();
|
||||
}
|
||||
}).doOnEach(r ->
|
||||
{
|
||||
Role role = r.get();
|
||||
if (role == null) return;
|
||||
|
||||
if (role.equals(adminRole))
|
||||
{
|
||||
member.removeRole(role.getId()).block();
|
||||
}
|
||||
}).subscribe();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCode(PlayerData playerData)
|
||||
{
|
||||
for (String code : this.getLinkCodes().keySet())
|
||||
{
|
||||
if (this.getLinkCodes().get(code).equals(playerData))
|
||||
{
|
||||
return code;
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String generateCode(int size)
|
||||
{
|
||||
return RandomStringUtils.randomNumeric(size);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, PlayerData> getLinkCodes()
|
||||
{
|
||||
return tfd4J.getBot().getLinkCodes();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String formatBotTag()
|
||||
{
|
||||
return tfd4J.getBot().formatBotTag();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean sendReportOffline(Player reporter, OfflinePlayer reported, String reason)
|
||||
{
|
||||
if (!tfd4J.getBot().shouldISendReport())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
final Guild server = tfd4J.getBot().getGuildById().block();
|
||||
|
||||
if (server == null) return false;
|
||||
|
||||
final TextChannel channel = server.getChannelById(SnowflakeEntry.REPORT_CHANNEL_ID.getSnowflake())
|
||||
.ofType(TextChannel.class)
|
||||
.blockOptional()
|
||||
.orElseThrow();
|
||||
|
||||
final EmbedCreateSpec.Builder builder = EmbedCreateSpec.builder()
|
||||
.title("Report for " + reported.getName() + " (offline)")
|
||||
.description(reason)
|
||||
.footer("Reported by " + reporter.getName(), "https://minotar.net/helm/" + reporter.getName() + ".png")
|
||||
.timestamp(Instant.from(ZonedDateTime.now()));
|
||||
if (tfd4J.getBot().getTFM().getCommons().esb.isEnabled())
|
||||
{
|
||||
com.earth2me.essentials.User user = tfd4J.getBot().getTFM().getCommons().esb.getEssentialsUser(reported.getName());
|
||||
String location = "World: " + Objects.requireNonNull(user.getLastLocation().getWorld()).getName() + ", X: " + user.getLastLocation().getBlockX() + ", Y: " + user.getLastLocation().getBlockY() + ", Z: " + user.getLastLocation().getBlockZ();
|
||||
builder.addField("Location", location, true);
|
||||
builder.addField("God Mode", WordUtils.capitalizeFully(String.valueOf(user.isGodModeEnabled())), true);
|
||||
if (user.getNickname() != null)
|
||||
{
|
||||
builder.addField("Nickname", user.getNickname(), true);
|
||||
}
|
||||
}
|
||||
EmbedCreateSpec embed = builder.build();
|
||||
Message message = channel.createMessage(embed).block();
|
||||
|
||||
if (message != null && !ConfigEntry.DISCORD_REPORT_ARCHIVE_CHANNEL_ID.getString().isEmpty())
|
||||
{
|
||||
message.addReaction(ReactionEmoji.unicode("\uD83D\uDCCB")).subscribe();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean sendReport(Player reporter, Player reported, String reason)
|
||||
{
|
||||
if (!tfd4J.getBot().shouldISendReport())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
final Guild server = tfd4J.getBot()
|
||||
.getClient()
|
||||
.getGuildById(SnowflakeEntry.SERVER_ID.getSnowflake())
|
||||
.block();
|
||||
|
||||
if (server == null)
|
||||
{
|
||||
FLog.severe("The guild ID specified in the config is invalid.");
|
||||
return false;
|
||||
}
|
||||
|
||||
final TextChannel channel = server.getChannelById(SnowflakeEntry.REPORT_CHANNEL_ID.getSnowflake())
|
||||
.ofType(TextChannel.class)
|
||||
.blockOptional()
|
||||
.orElseThrow();
|
||||
|
||||
String location = "World: " + Objects.requireNonNull(reported.getLocation().getWorld()).getName() + ", X: " + reported.getLocation().getBlockX() + ", Y: " + reported.getLocation().getBlockY() + ", Z: " + reported.getLocation().getBlockZ();
|
||||
|
||||
final EmbedCreateSpec spec = EmbedCreateSpec.builder()
|
||||
.title("Report for " + reported.getName())
|
||||
.description(reason)
|
||||
.footer("Reported by " + reporter.getName(), "https://minotar.net/helm/" + reporter.getName() + ".png")
|
||||
.timestamp(Instant.from(ZonedDateTime.now()))
|
||||
.addField("Location", location, true)
|
||||
.addField("Game Mode", WordUtils.capitalizeFully(reported.getGameMode().name()), true)
|
||||
.build();
|
||||
|
||||
Message message = channel.createMessage(spec).block();
|
||||
|
||||
if (!ConfigEntry.DISCORD_REPORT_ARCHIVE_CHANNEL_ID.getString().isEmpty() && message != null)
|
||||
{
|
||||
ReactionEmoji emoji = ReactionEmoji.unicode("\uD83D\uDCCB");
|
||||
message.addReaction(emoji);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnabled()
|
||||
{
|
||||
return tfd4J.isEnabled();
|
||||
}
|
||||
}
|
@ -1,36 +0,0 @@
|
||||
package me.totalfreedom.discord.command;
|
||||
|
||||
import discord4j.core.event.domain.interaction.ChatInputInteractionEvent;
|
||||
import discord4j.core.spec.EmbedCreateSpec;
|
||||
import discord4j.rest.util.Color;
|
||||
import me.totalfreedom.discord.handling.SlashCommand;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import java.time.Instant;
|
||||
|
||||
public class HelpCommand implements SlashCommand
|
||||
{
|
||||
@Override
|
||||
public String getName()
|
||||
{
|
||||
return "help";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mono<Void> handle(ChatInputInteractionEvent event)
|
||||
{
|
||||
EmbedCreateSpec spec = EmbedCreateSpec.builder()
|
||||
.color(Color.GREEN)
|
||||
.title("Help Command")
|
||||
.addField("Commands", "This is a list of all commands", false)
|
||||
.addField("\u200B", "\u200B", false)
|
||||
.addField("help", "Displays the help command. (This command.)", true)
|
||||
.addField("list", "Displays a list of all online players.", true)
|
||||
.addField("tps", "Displays the server's TPS.", true)
|
||||
.timestamp(Instant.now())
|
||||
.build();
|
||||
|
||||
return event.reply()
|
||||
.withEmbeds(spec);
|
||||
}
|
||||
}
|
@ -1,57 +0,0 @@
|
||||
package me.totalfreedom.discord.command;
|
||||
|
||||
import discord4j.core.event.domain.interaction.ChatInputInteractionEvent;
|
||||
import discord4j.core.spec.EmbedCreateSpec;
|
||||
import discord4j.rest.util.Color;
|
||||
import me.totalfreedom.discord.handling.SlashCommand;
|
||||
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.HumanEntity;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
public class ListCommand implements SlashCommand
|
||||
{
|
||||
|
||||
@Override
|
||||
public String getName()
|
||||
{
|
||||
return "list";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mono<Void> handle(ChatInputInteractionEvent event)
|
||||
{
|
||||
List<String> playerNames = Bukkit.getOnlinePlayers()
|
||||
.stream()
|
||||
.map(HumanEntity::getName)
|
||||
.toList();
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
Iterator<String> iterator = playerNames.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
sb.append(iterator.next());
|
||||
if (iterator.hasNext()) {
|
||||
sb.append(", \n");
|
||||
}
|
||||
}
|
||||
|
||||
String empty = "\u200B";
|
||||
|
||||
EmbedCreateSpec spec = EmbedCreateSpec.builder()
|
||||
.title("Player List - " + ConfigEntry.SERVER_NAME.getString())
|
||||
.color(Color.BISMARK)
|
||||
.addField("Online Players", String.join(", ", playerNames), false)
|
||||
.addField(empty, "Currently Online: " + playerNames.size(), false)
|
||||
.addField(empty, empty, false)
|
||||
.addField("Players: ", sb.toString(), true)
|
||||
.build();
|
||||
|
||||
return event.reply()
|
||||
.withEmbeds(spec)
|
||||
.withEphemeral(true)
|
||||
.withContent(sb.toString());
|
||||
}
|
||||
}
|
@ -1,39 +0,0 @@
|
||||
package me.totalfreedom.discord.command;
|
||||
|
||||
import discord4j.core.event.domain.interaction.ChatInputInteractionEvent;
|
||||
import discord4j.core.spec.EmbedCreateSpec;
|
||||
import discord4j.rest.util.Color;
|
||||
import me.totalfreedom.discord.handling.SlashCommand;
|
||||
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
public class TPSCommand implements SlashCommand
|
||||
{
|
||||
@Override
|
||||
public String getName()
|
||||
{
|
||||
return "tps";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mono<Void> handle(@NotNull ChatInputInteractionEvent event)
|
||||
{
|
||||
String tps = String.valueOf(FUtil.getMeanAverageDouble(Bukkit.getServer().getTPS()));
|
||||
|
||||
EmbedCreateSpec spec = EmbedCreateSpec.builder()
|
||||
.title("Current Server Tick Information")
|
||||
.addField("TPS", tps, false)
|
||||
.addField("Uptime", FUtil.getUptime(), false)
|
||||
.addField("Maximum Memory", Math.ceil(FUtil.getMaxMem()) + " MB", false)
|
||||
.addField("Allocated Memory", Math.ceil(FUtil.getTotalMem()) + " MB", false)
|
||||
.addField("Free Memory", Math.ceil(FUtil.getFreeMem()) + " MB", false)
|
||||
.color(Color.BISMARK)
|
||||
.build();
|
||||
|
||||
return event.reply()
|
||||
.withEmbeds(spec)
|
||||
.withEphemeral(true);
|
||||
}
|
||||
}
|
@ -1,113 +0,0 @@
|
||||
package me.totalfreedom.discord.handling;
|
||||
|
||||
import discord4j.common.JacksonResources;
|
||||
import discord4j.core.event.domain.interaction.ChatInputInteractionEvent;
|
||||
import discord4j.discordjson.json.ApplicationCommandRequest;
|
||||
import discord4j.rest.RestClient;
|
||||
import discord4j.rest.service.ApplicationService;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class CommandHandler
|
||||
{
|
||||
private final List<SlashCommand> commands = new ArrayList<>();
|
||||
private final RestClient restClient;
|
||||
|
||||
public CommandHandler(RestClient restClient)
|
||||
{
|
||||
this.restClient = restClient;
|
||||
}
|
||||
|
||||
public void registerCommands(List<String> fileNames) throws IOException
|
||||
{
|
||||
//Create an ObjectMapper that supports Discord4J classes
|
||||
final JacksonResources d4jMapper = JacksonResources.create();
|
||||
|
||||
// Convenience variables for the sake of easier to read code below
|
||||
final ApplicationService applicationService = restClient.getApplicationService();
|
||||
final long applicationId = Objects.requireNonNull(restClient.getApplicationId().block());
|
||||
|
||||
//Get our commands json from resources as command data
|
||||
List<ApplicationCommandRequest> commands = new ArrayList<>();
|
||||
for (String json : getCommandsJson(fileNames))
|
||||
{
|
||||
ApplicationCommandRequest request = d4jMapper.getObjectMapper()
|
||||
.readValue(json, ApplicationCommandRequest.class);
|
||||
|
||||
commands.add(request); //Add to our array list
|
||||
}
|
||||
|
||||
/* Bulk overwrite commands. This is now idempotent, so it is safe to use this even when only 1 command
|
||||
is changed/added/removed
|
||||
*/
|
||||
applicationService.bulkOverwriteGlobalApplicationCommand(applicationId, commands)
|
||||
.doOnNext(cmd -> Bukkit.getLogger().info("Successfully registered Global Command "
|
||||
+ cmd.name()))
|
||||
.doOnError(e -> Bukkit.getLogger().severe("Failed to register global commands.\n"
|
||||
+ e.getMessage()))
|
||||
.subscribe();
|
||||
}
|
||||
|
||||
private @NotNull List<String> getCommandsJson(List<String> fileNames) throws IOException
|
||||
{
|
||||
// Confirm that the commands folder exists
|
||||
String commandsFolderName = "commands/";
|
||||
URL url = this.getClass().getClassLoader().getResource(commandsFolderName);
|
||||
Objects.requireNonNull(url, commandsFolderName + " could not be found");
|
||||
|
||||
//Get all the files inside this folder and return the contents of the files as a list of strings
|
||||
List<String> list = new ArrayList<>();
|
||||
for (String file : fileNames)
|
||||
{
|
||||
String resourceFileAsString = getResourceFileAsString(commandsFolderName + file);
|
||||
list.add(Objects.requireNonNull(resourceFileAsString, "Command file not found: " + file));
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
private @Nullable String getResourceFileAsString(String fileName) throws IOException
|
||||
{
|
||||
ClassLoader classLoader = ClassLoader.getSystemClassLoader();
|
||||
try (InputStream resourceAsStream = classLoader.getResourceAsStream(fileName))
|
||||
{
|
||||
if (resourceAsStream == null) return null;
|
||||
try (InputStreamReader inputStreamReader = new InputStreamReader(resourceAsStream);
|
||||
BufferedReader reader = new BufferedReader(inputStreamReader))
|
||||
{
|
||||
return reader.lines().collect(Collectors.joining(System.lineSeparator()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void registerCommand(SlashCommand command)
|
||||
{
|
||||
commands.add(command);
|
||||
}
|
||||
|
||||
public Mono<Void> handle(ChatInputInteractionEvent event)
|
||||
{
|
||||
// Convert our array list to a flux that we can iterate through
|
||||
return Flux.fromIterable(commands)
|
||||
//Filter out all commands that don't match the name of the command this event is for
|
||||
.filter(command -> command.getName().equals(event.getCommandName()))
|
||||
// Get the first (and only) item in the flux that matches our filter
|
||||
.next()
|
||||
//have our command class handle all the logic related to its specific command.
|
||||
.flatMap(command -> command.handle(event));
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -1,10 +0,0 @@
|
||||
package me.totalfreedom.discord.handling;
|
||||
|
||||
import discord4j.core.event.domain.interaction.ChatInputInteractionEvent;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
public interface SlashCommand {
|
||||
String getName();
|
||||
|
||||
Mono<Void> handle(ChatInputInteractionEvent event);
|
||||
}
|
@ -1,125 +0,0 @@
|
||||
package me.totalfreedom.discord.listener;
|
||||
|
||||
import com.google.common.base.Strings;
|
||||
import discord4j.core.event.domain.message.MessageCreateEvent;
|
||||
import discord4j.core.object.entity.Attachment;
|
||||
import discord4j.core.object.entity.Guild;
|
||||
import discord4j.core.object.entity.Member;
|
||||
import discord4j.core.object.entity.Message;
|
||||
import me.totalfreedom.discord.Bot;
|
||||
import me.totalfreedom.discord.TFD4J;
|
||||
import me.totalfreedom.discord.util.SnowflakeEntry;
|
||||
import me.totalfreedom.totalfreedommod.TotalFreedomMod;
|
||||
import me.totalfreedom.totalfreedommod.admin.Admin;
|
||||
import me.totalfreedom.totalfreedommod.api.event.AdminChatEvent;
|
||||
import me.totalfreedom.totalfreedommod.rank.Displayable;
|
||||
import me.totalfreedom.totalfreedommod.rank.GroupProvider;
|
||||
import me.totalfreedom.totalfreedommod.rank.Title;
|
||||
import me.totalfreedom.totalfreedommod.util.FLog;
|
||||
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||
import net.kyori.adventure.key.Key;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.TextComponent;
|
||||
import net.kyori.adventure.text.event.ClickEvent;
|
||||
import net.kyori.adventure.text.event.HoverEvent;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import net.kyori.adventure.text.format.TextColor;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
|
||||
public class AdminChatListener
|
||||
{
|
||||
private static final Key identifier = Key.key("tfd4j", "discord_admin_chat");
|
||||
//--
|
||||
private final Bot bot;
|
||||
private final TFD4J tfd4j;
|
||||
|
||||
public AdminChatListener(TFD4J tfd4j)
|
||||
{
|
||||
this.tfd4j = tfd4j;
|
||||
this.bot = tfd4j.getBot();
|
||||
}
|
||||
|
||||
public void adminChatBound()
|
||||
{
|
||||
tfd4j.getBot()
|
||||
.getClient()
|
||||
.getEventDispatcher()
|
||||
.on(MessageCreateEvent.class)
|
||||
.filter(m -> m.getMessage()
|
||||
.getChannelId()
|
||||
.equals(SnowflakeEntry.ADMIN_CHAT_CHANNEL_ID.getSnowflake()))
|
||||
.filter(m -> !m.getMessage()
|
||||
.getAuthor()
|
||||
.orElseThrow()
|
||||
.getId()
|
||||
.equals(tfd4j.getBot().getClient().getSelfId()))
|
||||
.doOnError(FLog::severe)
|
||||
.subscribe(this::createMessageSpec);
|
||||
}
|
||||
|
||||
public void createMessageSpec(MessageCreateEvent m)
|
||||
{
|
||||
Member member = m.getMember().orElseThrow(IllegalAccessError::new);
|
||||
Component name = Component.text(member.getDisplayName());
|
||||
Message msg = m.getMessage();
|
||||
|
||||
TextComponent attachments = Component.empty();
|
||||
for (Attachment attachment : msg.getAttachments())
|
||||
{
|
||||
attachments = attachments.append(
|
||||
Component.text("[Media] ", NamedTextColor.YELLOW)
|
||||
.clickEvent(ClickEvent.openUrl(attachment.getUrl()))
|
||||
.hoverEvent(HoverEvent.showText(Component.text(attachment.getUrl()))));
|
||||
}
|
||||
|
||||
TextComponent message = Component.text(msg.getContent()).append(msg.getAttachments().isEmpty() ?
|
||||
Component.empty() : Component.space().append(attachments));
|
||||
|
||||
TotalFreedomMod.getPlugin().cm.adminChat(identifier, FUtil.miniMessage("<dark_gray>[<dark_aqua>Discord</dark_aqua>] </dark_gray>"), name, getDisplay(member), message, true);
|
||||
}
|
||||
|
||||
public Displayable getDisplay(Member member)
|
||||
{
|
||||
Guild server = tfd4j.getBot().getGuildById().block();
|
||||
// Server Owner
|
||||
if (server == null) throw new IllegalStateException();
|
||||
|
||||
return member.getRoles()
|
||||
.filter(role -> SnowflakeEntry.acceptableRoleIDs().contains(role.getId()))
|
||||
.map(role ->
|
||||
{
|
||||
if (role.getId().equals(SnowflakeEntry.OWNER_ROLE_ID.getSnowflake()))
|
||||
{
|
||||
return Title.OWNER;
|
||||
} else if (role.getId().equals(SnowflakeEntry.DEVELOPER_ROLE_ID.getSnowflake()))
|
||||
{
|
||||
return Title.DEVELOPER;
|
||||
} else if (role.getId().equals(SnowflakeEntry.EXECUTIVE_ROLE_ID.getSnowflake()))
|
||||
{
|
||||
return Title.EXECUTIVE;
|
||||
} else if (role.getId().equals(SnowflakeEntry.ASSISTANT_EXECUTIVE_ROLE_ID.getSnowflake()))
|
||||
{
|
||||
return Title.ASST_EXEC;
|
||||
} else if (role.getId().equals(SnowflakeEntry.SENIOR_ADMIN_ROLE_ID.getSnowflake()))
|
||||
{
|
||||
return GroupProvider.SENIOR_ADMIN.getGroup();
|
||||
} else if (role.getId().equals(SnowflakeEntry.ADMIN_ROLE_ID.getSnowflake()))
|
||||
{
|
||||
return GroupProvider.ADMIN.getGroup();
|
||||
} else if (role.getId().equals(SnowflakeEntry.MASTERBUILDER_ROLE_ID.getSnowflake()))
|
||||
{
|
||||
return GroupProvider.MASTER_BUILDER.getGroup();
|
||||
} else
|
||||
{
|
||||
return GroupProvider.OP.getGroup(); // This should never be reached.
|
||||
}
|
||||
}).blockFirst();
|
||||
}
|
||||
|
||||
public static Key getIdentifier()
|
||||
{
|
||||
return identifier;
|
||||
}
|
||||
}
|
@ -1,105 +0,0 @@
|
||||
package me.totalfreedom.discord.listener;
|
||||
|
||||
import io.papermc.paper.event.player.AsyncChatEvent;
|
||||
import me.totalfreedom.discord.Bot;
|
||||
import me.totalfreedom.discord.TFD4J;
|
||||
import me.totalfreedom.discord.util.Utilities;
|
||||
import me.totalfreedom.totalfreedommod.TotalFreedomMod;
|
||||
import me.totalfreedom.totalfreedommod.api.event.AdminChatEvent;
|
||||
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
|
||||
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||
import net.kyori.adventure.key.Key;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
import org.bukkit.GameRule;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.PlayerDeathEvent;
|
||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
|
||||
public class BukkitNative implements Listener
|
||||
{
|
||||
|
||||
//--
|
||||
private final TotalFreedomMod commons;
|
||||
private final Bot bot;
|
||||
private final TFD4J tfd4j;
|
||||
|
||||
public BukkitNative(TFD4J tfd4j)
|
||||
{
|
||||
this.tfd4j = tfd4j;
|
||||
this.bot = tfd4j.getBot();
|
||||
this.commons = bot.getTFM().getCommons();
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void onPlayerJoin(PlayerJoinEvent event)
|
||||
{
|
||||
if (!commons.al.isVanished(event.getPlayer().getUniqueId()))
|
||||
{
|
||||
tfd4j.getImpl().messageChatChannel("**"
|
||||
+ Utilities.deformat(event.getPlayer().getName())
|
||||
+ " joined the server" + "**", true);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void onPlayerLeave(PlayerQuitEvent event)
|
||||
{
|
||||
if (!commons.al.isVanished(event.getPlayer().getUniqueId()))
|
||||
{
|
||||
tfd4j.getImpl().messageChatChannel("**"
|
||||
+ Utilities.deformat(event.getPlayer().getName())
|
||||
+ " left the server" + "**", true);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void onPlayerDeath(PlayerDeathEvent event)
|
||||
{
|
||||
//Avoiding NPE Unboxing Warnings
|
||||
Boolean b = event.getEntity().getWorld().getGameRuleValue(GameRule.SHOW_DEATH_MESSAGES);
|
||||
if (b == null || !b)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Component deathMessage = event.deathMessage();
|
||||
|
||||
if (deathMessage != null)
|
||||
{
|
||||
tfd4j.getImpl().messageChatChannel("**"
|
||||
+ Utilities.deformat(PlainTextComponentSerializer.plainText().serialize(deathMessage))
|
||||
+ "**", true);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onAsyncPlayerChat(AsyncChatEvent event)
|
||||
{
|
||||
Player player = event.getPlayer();
|
||||
String message = FUtil.steamroll(event.message());
|
||||
|
||||
if (!ConfigEntry.ADMIN_ONLY_MODE.getBoolean() && !tfd4j.getServer().hasWhitelist()
|
||||
&& !commons.pl.getPlayer(player).isMuted() && !commons.pl.getPlayer(player).inAdminChat() && bot != null)
|
||||
{
|
||||
tfd4j.getImpl().messageChatChannel(player.getName()
|
||||
+ " \u00BB "
|
||||
+ message, true);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onAdminChat(AdminChatEvent event)
|
||||
{
|
||||
if (!event.getIdentifier().equals(AdminChatListener.getIdentifier()))
|
||||
{
|
||||
tfd4j.getImpl().messageAdminChatChannel(FUtil.steamroll(event.getName()) + " » " + FUtil.steamroll(event.getMessage()));
|
||||
}
|
||||
}
|
||||
}
|
@ -1,98 +0,0 @@
|
||||
package me.totalfreedom.discord.listener;
|
||||
|
||||
import discord4j.core.event.domain.message.MessageCreateEvent;
|
||||
import discord4j.core.object.entity.Attachment;
|
||||
import discord4j.core.object.entity.Member;
|
||||
import discord4j.core.object.entity.Message;
|
||||
import discord4j.core.object.entity.channel.TextChannel;
|
||||
import me.totalfreedom.discord.Bot;
|
||||
import me.totalfreedom.discord.TFD4J;
|
||||
import me.totalfreedom.discord.util.SnowflakeEntry;
|
||||
import me.totalfreedom.totalfreedommod.TotalFreedomMod;
|
||||
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
|
||||
import me.totalfreedom.totalfreedommod.util.FLog;
|
||||
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.TextComponent;
|
||||
import net.kyori.adventure.text.event.ClickEvent;
|
||||
import net.kyori.adventure.text.event.HoverEvent;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
public class MinecraftListener
|
||||
{
|
||||
private final TotalFreedomMod commons;
|
||||
private final Bot bot;
|
||||
private final TFD4J tfd4j;
|
||||
|
||||
public MinecraftListener(TFD4J tfd4j)
|
||||
{
|
||||
this.tfd4j = tfd4j;
|
||||
this.bot = tfd4j.getBot();
|
||||
this.commons = bot.getTFM().getCommons();
|
||||
}
|
||||
|
||||
public void minecraftChatBound()
|
||||
{
|
||||
tfd4j.getBot().getClient()
|
||||
.getEventDispatcher()
|
||||
.on(MessageCreateEvent.class)
|
||||
.filter(m -> m.getMessage()
|
||||
.getChannelId()
|
||||
.equals(SnowflakeEntry.CHAT_CHANNEL_ID.getSnowflake()))
|
||||
.filter(m -> m.getMember().orElse(null) != null)
|
||||
.filter(m -> !m.getMessage()
|
||||
.getAuthor()
|
||||
.orElseThrow(IllegalAccessError::new)
|
||||
.getId()
|
||||
.equals(tfd4j.getBot().getClient().getSelfId()))
|
||||
.doOnError(FLog::severe)
|
||||
.subscribe(this::doMessageBodyDetails);
|
||||
}
|
||||
|
||||
private void doMessageBodyDetails(MessageCreateEvent m)
|
||||
{
|
||||
Member member = m.getMember().orElseThrow();
|
||||
Message msg = m.getMessage();
|
||||
String tag = bot.getTFM().getDisplay(member);
|
||||
|
||||
TextComponent.Builder builder = Component.text();
|
||||
TextComponent prefix = Component.text("[", NamedTextColor.DARK_GRAY)
|
||||
.append(Component.text("Discord", NamedTextColor.DARK_AQUA)
|
||||
.hoverEvent(HoverEvent.showText(Component.text("Click to join our Discord server!")))
|
||||
.clickEvent(ClickEvent.openUrl(ConfigEntry.DISCORD_INVITE_LINK.getString())))
|
||||
.append(Component.text("] ", NamedTextColor.DARK_GRAY));
|
||||
TextComponent user = Component.empty();
|
||||
|
||||
// Tag (if they have one)
|
||||
if (tag != null && !tag.isEmpty())
|
||||
{
|
||||
user = LegacyComponentSerializer.legacyAmpersand().deserialize(tag).append(Component.space());
|
||||
}
|
||||
|
||||
user = user.append(Component.text(FUtil.stripColors(member.getDisplayName()).trim(), NamedTextColor.RED));
|
||||
|
||||
TextComponent message = Component.text(": ", NamedTextColor.DARK_GRAY)
|
||||
.append(Component.text(FUtil.stripColors(msg.getContent()), NamedTextColor.WHITE));
|
||||
|
||||
// Attachments
|
||||
if (!msg.getAttachments().isEmpty())
|
||||
{
|
||||
if (!msg.getContent().isEmpty())
|
||||
{
|
||||
message = message.append(Component.space());
|
||||
}
|
||||
|
||||
for (Attachment attachment : msg.getAttachments())
|
||||
{
|
||||
message = message.append(Component.text("[Media] ", NamedTextColor.YELLOW)
|
||||
.hoverEvent(HoverEvent.showText(Component.text(attachment.getUrl())))
|
||||
.clickEvent(ClickEvent.openUrl(attachment.getUrl())));
|
||||
}
|
||||
}
|
||||
|
||||
Bukkit.broadcast(builder.append(prefix, user, message).build());
|
||||
}
|
||||
}
|
||||
|
@ -1,56 +0,0 @@
|
||||
package me.totalfreedom.discord.listener;
|
||||
|
||||
import discord4j.core.event.domain.message.MessageCreateEvent;
|
||||
import me.totalfreedom.discord.TFD4J;
|
||||
import me.totalfreedom.totalfreedommod.TotalFreedomMod;
|
||||
import me.totalfreedom.totalfreedommod.admin.Admin;
|
||||
import me.totalfreedom.totalfreedommod.player.PlayerData;
|
||||
|
||||
public class PrivateMessageListener
|
||||
{
|
||||
private final TFD4J tfd4j;
|
||||
|
||||
public PrivateMessageListener(TFD4J tfd4j)
|
||||
{
|
||||
this.tfd4j = tfd4j;
|
||||
}
|
||||
|
||||
public void privateMessageReceived()
|
||||
{
|
||||
tfd4j.getBot()
|
||||
.getClient()
|
||||
.getEventDispatcher()
|
||||
.on(MessageCreateEvent.class)
|
||||
.filter(event -> event.getMessage().getAuthor().orElse(null) != null)
|
||||
.filter(event -> !event.getMessage().getAuthor().orElseThrow().getId().equals(tfd4j.getBot().getClient().getSelfId()))
|
||||
.filter(event -> event.getMessage().getContent().strip().matches("\\d{5}"))
|
||||
.subscribe(event ->
|
||||
{
|
||||
String code = event.getMessage().getContent().strip();
|
||||
String name;
|
||||
if (tfd4j.getBot().getLinkCodes().get(code) != null)
|
||||
{
|
||||
PlayerData player = tfd4j.getBot().getLinkCodes().get(code);
|
||||
name = player.getName();
|
||||
player.setDiscordID(event.getMessage().getAuthor().orElseThrow().getId().asString());
|
||||
|
||||
Admin admin = TotalFreedomMod.getPlugin().al.getEntryByUuid(player.getUuid());
|
||||
if (admin != null)
|
||||
{
|
||||
tfd4j.getImpl().syncRoles(admin, player.getDiscordID());
|
||||
}
|
||||
|
||||
TotalFreedomMod.getPlugin().pl.save(player);
|
||||
tfd4j.getBot().getLinkCodes().remove(code);
|
||||
} else
|
||||
{
|
||||
return;
|
||||
}
|
||||
event.getMessage()
|
||||
.getChannel()
|
||||
.blockOptional()
|
||||
.orElseThrow(UnsupportedOperationException::new)
|
||||
.createMessage("Link successful. Now this Discord account is linked with your Minecraft account **" + name + "**.").block();
|
||||
});
|
||||
}
|
||||
}
|
@ -1,76 +0,0 @@
|
||||
package me.totalfreedom.discord.listener;
|
||||
|
||||
import discord4j.core.event.domain.message.ReactionAddEvent;
|
||||
import discord4j.core.object.Embed;
|
||||
import discord4j.core.object.entity.Member;
|
||||
import discord4j.core.object.entity.Message;
|
||||
import discord4j.core.object.entity.channel.TextChannel;
|
||||
import discord4j.discordjson.json.MessageCreateRequest;
|
||||
import me.totalfreedom.discord.TFD4J;
|
||||
import me.totalfreedom.discord.util.SnowflakeEntry;
|
||||
import me.totalfreedom.totalfreedommod.util.FLog;
|
||||
|
||||
public class ReactionListener
|
||||
{
|
||||
private final TFD4J tfd4j;
|
||||
|
||||
public ReactionListener(TFD4J tfd4J)
|
||||
{
|
||||
this.tfd4j = tfd4J;
|
||||
}
|
||||
|
||||
public void onReactionAdd()
|
||||
{
|
||||
tfd4j.getBot()
|
||||
.getClient()
|
||||
.getEventDispatcher()
|
||||
.on(ReactionAddEvent.class)
|
||||
.filter(r -> r.getGuild().block() != null)
|
||||
.filter(r -> r.getMember().orElse(null) != null)
|
||||
.filter(r -> !r.getMember()
|
||||
.orElseThrow()
|
||||
.getId()
|
||||
.equals(tfd4j.getBot().getClient().getSelfId()))
|
||||
.filter(r -> !r.getChannelId()
|
||||
.equals(SnowflakeEntry.REPORT_CHANNEL_ID.getSnowflake()))
|
||||
.filter(r -> r.getEmoji()
|
||||
.asUnicodeEmoji()
|
||||
.orElseThrow(UnsupportedOperationException::new)
|
||||
.getRaw()
|
||||
.equals("\uD83D\uDCCB"))
|
||||
.doOnError(FLog::severe)
|
||||
.subscribe(this::reactionWork);
|
||||
}
|
||||
|
||||
private void reactionWork(ReactionAddEvent event)
|
||||
{
|
||||
final TextChannel archiveChannel = tfd4j.getBot()
|
||||
.getClient()
|
||||
.getChannelById(SnowflakeEntry.ARCHIVE_REPORT_CHANNEL_ID.getSnowflake())
|
||||
.ofType(TextChannel.class)
|
||||
.blockOptional()
|
||||
.orElseThrow();
|
||||
|
||||
final Message message = event.getMessage().blockOptional().orElseThrow();
|
||||
final Member completer = event.getMember().orElseThrow();
|
||||
|
||||
if (!message.getAuthor().orElseThrow().getId().equals(tfd4j.getBot().getClient().getSelfId()))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// We don't need other embeds... yet?
|
||||
final Embed embed = message.getEmbeds().get(0);
|
||||
|
||||
final MessageCreateRequest request = MessageCreateRequest.builder()
|
||||
.content("Report completed by " + completer.getUsername()
|
||||
+ " (" + completer.getDiscriminator()
|
||||
+ ")")
|
||||
.addEmbed(embed.getData())
|
||||
.build();
|
||||
|
||||
archiveChannel.getRestChannel().createMessage(request);
|
||||
|
||||
message.delete().block();
|
||||
}
|
||||
}
|
@ -1,35 +0,0 @@
|
||||
package me.totalfreedom.discord.react;
|
||||
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
import reactor.core.Disposable;
|
||||
|
||||
/**
|
||||
* This class is a wrapper for a BukkitTask that implements the Disposable interface.
|
||||
* This is so we can schedule non-blocking tasks asynchronously on the Bukkit Scheduler.
|
||||
* <p>
|
||||
* From <a href="https://github.com/SimplexDevelopment/SimplexSS">SimplexSS</a>
|
||||
*
|
||||
* @param task The task to wrap.
|
||||
*/
|
||||
public record DisposableBukkitTask(BukkitTask task) implements Disposable
|
||||
{
|
||||
/**
|
||||
* Disposes of the task upstream on the Bukkit scheduler.
|
||||
*/
|
||||
@Override
|
||||
public void dispose()
|
||||
{
|
||||
task.cancel();
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the task is cancelled.
|
||||
*
|
||||
* @return true if the task is cancelled, false otherwise.
|
||||
*/
|
||||
@Override
|
||||
public boolean isDisposed()
|
||||
{
|
||||
return task.isCancelled();
|
||||
}
|
||||
}
|
@ -1,96 +0,0 @@
|
||||
package me.totalfreedom.discord.react;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.bukkit.scheduler.BukkitScheduler;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import reactor.core.Disposable;
|
||||
import reactor.core.scheduler.Scheduler;
|
||||
|
||||
/**
|
||||
* An abstraction layer over the {@link BukkitScheduler} to allow for the use as a {@link Scheduler}.
|
||||
* This will allow us to perform non-blocking operations on the main server thread.
|
||||
*
|
||||
* @author SimplexDevelopment
|
||||
*/
|
||||
public final class ReactiveBukkitScheduler
|
||||
implements Scheduler, Scheduler.Worker {
|
||||
/**
|
||||
* The plugin instance.
|
||||
*/
|
||||
private final JavaPlugin plugin;
|
||||
/**
|
||||
* The bukkit scheduler.
|
||||
*/
|
||||
private final BukkitScheduler scheduler;
|
||||
|
||||
public ReactiveBukkitScheduler(JavaPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
this.scheduler = plugin.getServer().getScheduler();
|
||||
}
|
||||
|
||||
/**
|
||||
* Delegates to the {@link BukkitScheduler}.
|
||||
*
|
||||
* @param task The task to delegate.
|
||||
* @return A disposable that can be used to cancel the task.
|
||||
*/
|
||||
@Override
|
||||
public @NotNull Disposable schedule(@NotNull Runnable task) {
|
||||
return new DisposableBukkitTask(scheduler.runTask(plugin, task));
|
||||
}
|
||||
|
||||
/**
|
||||
* Delegates to the {@link BukkitScheduler} with a delay.
|
||||
*
|
||||
* @param task The task to delegate
|
||||
* @param delay The amount of time to wait before running the task
|
||||
* @param unit Unused parameter in this implementation.
|
||||
* Regardless of what value you use, this parameter will never be called.
|
||||
* @return A disposable that can be used to cancel the task.
|
||||
*/
|
||||
@Override
|
||||
public @NotNull Disposable schedule(@NotNull Runnable task, long delay, @Deprecated @Nullable TimeUnit unit) {
|
||||
return new DisposableBukkitTask(scheduler.runTaskLater(plugin, task, delay));
|
||||
}
|
||||
|
||||
/**
|
||||
* Delegates to the {@link BukkitScheduler} with a delay and a period.
|
||||
* The initial delay may be 0L, but the period must be greater than 0L.
|
||||
*
|
||||
* @param task The task to delegate.
|
||||
* @param initialDelay The amount of time to wait before running the task.
|
||||
* @param period The amount of time to wait between each execution of the task.
|
||||
* @param unit Unused parameter in this implementation.
|
||||
* Regardless of what value you use, this parameter will never be called.
|
||||
* @return A disposable that can be used to cancel the task.
|
||||
*/
|
||||
@Override
|
||||
public @NotNull Disposable schedulePeriodically(@NotNull Runnable task, long initialDelay, long period, @Deprecated @Nullable TimeUnit unit) {
|
||||
if (period <= 0L) {
|
||||
throw new IllegalArgumentException("Period must be greater than 0L");
|
||||
}
|
||||
|
||||
return new DisposableBukkitTask(scheduler.runTaskTimer(plugin, task, initialDelay, period));
|
||||
}
|
||||
|
||||
/**
|
||||
* A new {@link Worker}.
|
||||
*
|
||||
* @return This class instance, as it implements {@link Worker}.
|
||||
*/
|
||||
@Override
|
||||
public @NotNull Scheduler.Worker createWorker() {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method does nothing and is unused.
|
||||
*/
|
||||
@Override
|
||||
@Deprecated
|
||||
public void dispose() {
|
||||
// This method does nothing and is only here because it's being overridden from a parent.
|
||||
}
|
||||
}
|
@ -1,51 +0,0 @@
|
||||
package me.totalfreedom.discord.util;
|
||||
|
||||
import discord4j.common.util.Snowflake;
|
||||
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
public enum SnowflakeEntry
|
||||
{
|
||||
ADMIN_CHAT_CHANNEL_ID(ConfigEntry.DISCORD_ADMINCHAT_CHANNEL_ID),
|
||||
CHAT_CHANNEL_ID(ConfigEntry.DISCORD_CHAT_CHANNEL_ID),
|
||||
REPORT_CHANNEL_ID(ConfigEntry.DISCORD_REPORT_CHANNEL_ID),
|
||||
ARCHIVE_REPORT_CHANNEL_ID(ConfigEntry.DISCORD_REPORT_ARCHIVE_CHANNEL_ID),
|
||||
//--
|
||||
SERVER_ID(ConfigEntry.DISCORD_SERVER_ID),
|
||||
//--
|
||||
OWNER_ROLE_ID(ConfigEntry.DISCORD_SERVER_OWNER_ROLE_ID),
|
||||
DEVELOPER_ROLE_ID(ConfigEntry.DISCORD_DEVELOPER_ROLE_ID),
|
||||
EXECUTIVE_ROLE_ID(ConfigEntry.DISCORD_EXECUTIVE_ROLE_ID),
|
||||
ASSISTANT_EXECUTIVE_ROLE_ID(ConfigEntry.DISCORD_ASSISTANT_EXECUTIVE_ROLE_ID),
|
||||
SENIOR_ADMIN_ROLE_ID(ConfigEntry.DISCORD_SENIOR_ADMIN_ROLE_ID),
|
||||
ADMIN_ROLE_ID(ConfigEntry.DISCORD_NEW_ADMIN_ROLE_ID),
|
||||
MASTERBUILDER_ROLE_ID(ConfigEntry.DISCORD_MASTER_BUILDER_ROLE_ID);
|
||||
|
||||
|
||||
private ConfigEntry entry;
|
||||
|
||||
SnowflakeEntry(ConfigEntry entry)
|
||||
{
|
||||
this.entry = entry;
|
||||
}
|
||||
|
||||
public Snowflake getSnowflake()
|
||||
{
|
||||
return Snowflake.of(entry.getString());
|
||||
}
|
||||
|
||||
public static Set<Snowflake> acceptableRoleIDs()
|
||||
{
|
||||
Set<Snowflake> acceptableRoleIDs = new HashSet<>();
|
||||
acceptableRoleIDs.add(SnowflakeEntry.OWNER_ROLE_ID.getSnowflake());
|
||||
acceptableRoleIDs.add(SnowflakeEntry.DEVELOPER_ROLE_ID.getSnowflake());
|
||||
acceptableRoleIDs.add(SnowflakeEntry.EXECUTIVE_ROLE_ID.getSnowflake());
|
||||
acceptableRoleIDs.add(SnowflakeEntry.ASSISTANT_EXECUTIVE_ROLE_ID.getSnowflake());
|
||||
acceptableRoleIDs.add(SnowflakeEntry.SENIOR_ADMIN_ROLE_ID.getSnowflake());
|
||||
acceptableRoleIDs.add(SnowflakeEntry.ADMIN_ROLE_ID.getSnowflake());
|
||||
acceptableRoleIDs.add(SnowflakeEntry.MASTERBUILDER_ROLE_ID.getSnowflake());
|
||||
return acceptableRoleIDs;
|
||||
}
|
||||
}
|
@ -1,64 +0,0 @@
|
||||
package me.totalfreedom.discord.util;
|
||||
|
||||
import discord4j.core.object.entity.Guild;
|
||||
import discord4j.core.object.entity.Member;
|
||||
import me.totalfreedom.discord.Bot;
|
||||
import me.totalfreedom.totalfreedommod.TotalFreedomMod;
|
||||
import me.totalfreedom.totalfreedommod.rank.GroupProvider;
|
||||
import me.totalfreedom.totalfreedommod.rank.Title;
|
||||
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
public class TFM_Bridge
|
||||
{
|
||||
private final Bot bot;
|
||||
private final TotalFreedomMod commons;
|
||||
|
||||
public TFM_Bridge(Bot bot)
|
||||
{
|
||||
this.bot = bot;
|
||||
this.commons = (TotalFreedomMod) Bukkit.getPluginManager().getPlugin("TotalFreedomMod");
|
||||
|
||||
if (commons == null) throw new IllegalStateException();
|
||||
}
|
||||
|
||||
public String getDisplay(Member member)
|
||||
{
|
||||
Guild server = bot.getGuildById().block();
|
||||
// Server Owner
|
||||
assert server != null;
|
||||
return member.getRoles().map(role ->
|
||||
{
|
||||
if (role.getId().equals(SnowflakeEntry.OWNER_ROLE_ID.getSnowflake()))
|
||||
{
|
||||
return FUtil.miniMessage(Title.OWNER.getColoredTag());
|
||||
} else if (role.getId().equals(SnowflakeEntry.DEVELOPER_ROLE_ID.getSnowflake()))
|
||||
{
|
||||
return FUtil.miniMessage(Title.DEVELOPER.getColoredTag());
|
||||
} else if (role.getId().equals(SnowflakeEntry.EXECUTIVE_ROLE_ID.getSnowflake()))
|
||||
{
|
||||
return FUtil.miniMessage(Title.EXECUTIVE.getColoredTag());
|
||||
} else if (role.getId().equals(SnowflakeEntry.ASSISTANT_EXECUTIVE_ROLE_ID.getSnowflake()))
|
||||
{
|
||||
return FUtil.miniMessage(Title.ASST_EXEC.getColoredTag());
|
||||
} else if (role.getId().equals(SnowflakeEntry.SENIOR_ADMIN_ROLE_ID.getSnowflake()))
|
||||
{
|
||||
return FUtil.miniMessage(GroupProvider.SENIOR_ADMIN.getGroup().getColoredTag());
|
||||
} else if (role.getId().equals(SnowflakeEntry.ADMIN_ROLE_ID.getSnowflake()))
|
||||
{
|
||||
return FUtil.miniMessage(GroupProvider.ADMIN.getGroup().getColoredTag());
|
||||
} else if (role.getId().equals(SnowflakeEntry.MASTERBUILDER_ROLE_ID.getSnowflake()))
|
||||
{
|
||||
return FUtil.miniMessage(GroupProvider.MASTER_BUILDER.getGroup().getColoredTag());
|
||||
} else
|
||||
{
|
||||
return "";
|
||||
}
|
||||
}).blockFirst();
|
||||
}
|
||||
|
||||
public TotalFreedomMod getCommons()
|
||||
{
|
||||
return commons;
|
||||
}
|
||||
}
|
@ -1,14 +0,0 @@
|
||||
package me.totalfreedom.discord.util;
|
||||
|
||||
public class Utilities
|
||||
{
|
||||
private Utilities() {
|
||||
throw new AssertionError();
|
||||
}
|
||||
|
||||
// Leaving this here so I don't need to do more work than necessary.
|
||||
public static String deformat(String input)
|
||||
{
|
||||
return input.replaceAll("([_\\\\`*>|])", "\\\\$1");
|
||||
}
|
||||
}
|
@ -1,4 +0,0 @@
|
||||
{
|
||||
"name": "help",
|
||||
"description": "Bot help command."
|
||||
}
|
@ -1,4 +0,0 @@
|
||||
{
|
||||
"name": "list",
|
||||
"description": "List all currently online players"
|
||||
}
|
@ -1,4 +0,0 @@
|
||||
{
|
||||
"name": "tps",
|
||||
"description": "Gets the current TPS for the server."
|
||||
}
|
@ -1,8 +0,0 @@
|
||||
name: TFD4J
|
||||
main: me.totalfreedom.discord.TFD4J
|
||||
version: 2023.03
|
||||
api-version: 1.19
|
||||
depend: [TotalFreedomMod]
|
||||
libraries:
|
||||
- com.discord4j:discord4j-core:3.2.0
|
||||
- io.projectreactor:reactor-core:3.4.9
|
261
pom.xml
261
pom.xml
@ -5,18 +5,12 @@
|
||||
|
||||
<groupId>me.totalfreedom</groupId>
|
||||
<artifactId>TotalFreedomMod</artifactId>
|
||||
<version>2023.03</version>
|
||||
<packaging>pom</packaging>
|
||||
<modules>
|
||||
<module>commons</module>
|
||||
<module>shop</module>
|
||||
<module>discord</module>
|
||||
</modules>
|
||||
|
||||
<version>2022.06</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<tfm.build.codename>Caladrius</tfm.build.codename>
|
||||
<tfm.build.codename>Phoenix</tfm.build.codename>
|
||||
<jar.finalName>${project.name}</jar.finalName>
|
||||
<timestamp>${maven.build.timestamp}</timestamp>
|
||||
<maven.build.timestamp.format>MM/dd/yyyy HH:mm</maven.build.timestamp.format>
|
||||
@ -71,6 +65,11 @@
|
||||
<url>https://maven.elmakers.com/repository/</url>
|
||||
</repository>
|
||||
|
||||
<repository>
|
||||
<id>sk89q-snapshots</id>
|
||||
<url>https://maven.sk89q.com/artifactory/repo</url>
|
||||
</repository>
|
||||
|
||||
<repository>
|
||||
<id>dv8tion</id>
|
||||
<name>m2-dv8tion</name>
|
||||
@ -92,6 +91,11 @@
|
||||
<url>https://repo.dmulloy2.net/nexus/repository/public/</url>
|
||||
</repository>
|
||||
|
||||
<repository>
|
||||
<id>sk89q-repo</id>
|
||||
<url>https://maven.sk89q.com/repo/</url>
|
||||
</repository>
|
||||
|
||||
<repository>
|
||||
<id>esentialsx-repo</id>
|
||||
<url>https://repo.essentialsx.net/releases/</url>
|
||||
@ -101,10 +105,31 @@
|
||||
|
||||
<dependencies>
|
||||
|
||||
<dependency>
|
||||
<groupId>commons-io</groupId>
|
||||
<artifactId>commons-io</artifactId>
|
||||
<version>2.11.0</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-lang3</artifactId>
|
||||
<version>3.12.0</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.bstats</groupId>
|
||||
<artifactId>bstats-bukkit</artifactId>
|
||||
<version>3.0.0</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>me.totalfreedom.scissors</groupId>
|
||||
<artifactId>Scissors-API</artifactId>
|
||||
<version>1.19.3-R0.1-SNAPSHOT</version>
|
||||
<artifactId>scissors-api</artifactId>
|
||||
<version>1.17.1-R0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
@ -129,6 +154,13 @@
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>net.dv8tion</groupId>
|
||||
<artifactId>JDA</artifactId>
|
||||
<version>4.4.0_352</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>net.coreprotect</groupId>
|
||||
<artifactId>coreprotect</artifactId>
|
||||
@ -143,6 +175,13 @@
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>io.papermc</groupId>
|
||||
<artifactId>paperlib</artifactId>
|
||||
<version>1.0.7</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.github.vexsoftware</groupId>
|
||||
<artifactId>votifier</artifactId>
|
||||
@ -157,18 +196,25 @@
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.reflections</groupId>
|
||||
<artifactId>reflections</artifactId>
|
||||
<version>0.10.2</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.javassist</groupId>
|
||||
<artifactId>javassist</artifactId>
|
||||
<version>3.29.1-GA</version>
|
||||
<scope>provided</scope>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.jetbrains</groupId>
|
||||
<artifactId>annotations</artifactId>
|
||||
<version>23.0.0</version>
|
||||
<scope>provided</scope>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
@ -184,6 +230,12 @@
|
||||
<version>5.9.0</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.eclipse.sisu</groupId>
|
||||
<artifactId>org.eclipse.sisu.inject</artifactId>
|
||||
<version>0.3.5</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<pluginRepositories>
|
||||
@ -193,6 +245,189 @@
|
||||
</pluginRepository>
|
||||
</pluginRepositories>
|
||||
|
||||
<build>
|
||||
<!-- Filter resources for build.properties -->
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>src/main/resources</directory>
|
||||
<filtering>true</filtering>
|
||||
</resource>
|
||||
</resources>
|
||||
|
||||
<plugins>
|
||||
<!-- Compiler -->
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.10.1</version>
|
||||
<configuration>
|
||||
<outputFileName>TotalFreedomMod.jar</outputFileName>
|
||||
<compilerVersion>17</compilerVersion>
|
||||
<source>17</source>
|
||||
<target>17</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
<!-- Git describe -->
|
||||
<plugin>
|
||||
<groupId>pl.project13.maven</groupId>
|
||||
<artifactId>git-commit-id-plugin</artifactId>
|
||||
<version>4.9.10</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>get-the-git-infos</id>
|
||||
<goals>
|
||||
<goal>revision</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
<execution>
|
||||
<id>validate-the-git-infos</id>
|
||||
<goals>
|
||||
<goal>validateRevision</goal>
|
||||
</goals>
|
||||
<phase>package</phase>
|
||||
</execution>
|
||||
</executions>
|
||||
<configuration>
|
||||
<dotGitDirectory>${project.basedir}/.git</dotGitDirectory>
|
||||
<prefix>git</prefix>
|
||||
<dateFormat>yyyy-MM-dd HH:mm:ss</dateFormat>
|
||||
<verbose>false</verbose>
|
||||
<format>properties</format>
|
||||
<failOnNoGitDirectory>false</failOnNoGitDirectory>
|
||||
<failOnUnableToExtractRepoInfo>false</failOnUnableToExtractRepoInfo>
|
||||
<includeOnlyProperties>
|
||||
<includeOnlyProperty>git.commit.id.abbrev</includeOnlyProperty>
|
||||
</includeOnlyProperties>
|
||||
<gitDescribe>
|
||||
<skip>false</skip>
|
||||
<always>false</always>
|
||||
<abbrev>7</abbrev>
|
||||
<dirty>-dirty</dirty>
|
||||
<match>*</match>
|
||||
</gitDescribe>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
<!-- Antrun -->
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-antrun-plugin</artifactId>
|
||||
<version>3.1.0</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>default-cli</id>
|
||||
<phase>initialize</phase>
|
||||
<configuration>
|
||||
<target>
|
||||
<propertyfile file="${project.basedir}/src/main/resources/build.properties"
|
||||
comment="Build information. Edit this to your liking.">
|
||||
<entry key="buildAuthor" default="unknown"/>
|
||||
<entry key="buildNumber" default="0"/>
|
||||
<entry key="buildCodeName" value="${tfm.build.codename}"/>
|
||||
<entry key="buildVersion" value="${project.version}"/>
|
||||
<entry key="buildDate" value="${timestamp}"/>
|
||||
<!--suppress UnresolvedMavenProperty -->
|
||||
<entry key="buildHead" value="${git.commit.id.abbrev}"/>
|
||||
</propertyfile>
|
||||
</target>
|
||||
</configuration>
|
||||
<goals>
|
||||
<goal>run</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
|
||||
<!-- Properties -->
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>properties-maven-plugin</artifactId>
|
||||
<version>1.1.0</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>initialize</phase>
|
||||
<goals>
|
||||
<goal>read-project-properties</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<files>
|
||||
<file>${project.basedir}/src/main/resources/build.properties</file>
|
||||
</files>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
|
||||
<!-- Buildnumber -->
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>buildnumber-maven-plugin</artifactId>
|
||||
<version>3.0.0</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>generate-resources</phase>
|
||||
<goals>
|
||||
<goal>create</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
|
||||
<configuration>
|
||||
<buildNumberPropertyName>maven.buildnumber</buildNumberPropertyName>
|
||||
<buildNumberPropertiesFileLocation>${project.basedir}/src/main/resources/build.properties
|
||||
</buildNumberPropertiesFileLocation>
|
||||
<format>{0,number,#}</format>
|
||||
<items>
|
||||
<item>buildNumber</item>
|
||||
</items>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
<!-- Shade -->
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
<version>3.4.1</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>shade</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<minimizeJar>true</minimizeJar>
|
||||
<relocations>
|
||||
<relocation>
|
||||
<pattern>io.papermc.lib</pattern>
|
||||
<shadedPattern>me.totalfreedom.totalfreedommod.paperlib
|
||||
</shadedPattern> <!-- Replace this -->
|
||||
</relocation>
|
||||
<relocation>
|
||||
<pattern>org.bstats</pattern>
|
||||
<shadedPattern>me.totalfreedom.totalfreedommod</shadedPattern>
|
||||
</relocation>
|
||||
</relocations>
|
||||
<artifactSet>
|
||||
<includes>
|
||||
<include>commons-io:commons-io</include>
|
||||
<include>org.apache.commons:commons-lang3</include>
|
||||
<include>org.reflections:reflections</include>
|
||||
<include>org.javassist:javassist</include>
|
||||
<include>io.papermc:paperlib</include>
|
||||
<include>org.bstats:bstats-bukkit</include>
|
||||
<include>org.bstats:bstats-base</include>
|
||||
<include>org.jetbrains:annotations</include>
|
||||
</includes>
|
||||
</artifactSet>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
|
||||
<reporting>
|
||||
<!-- Checkstyle -->
|
||||
<plugins>
|
||||
|
29
shop/pom.xml
29
shop/pom.xml
@ -1,29 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>me.totalfreedom</groupId>
|
||||
<artifactId>TotalFreedomMod</artifactId>
|
||||
<version>2023.03</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>shop</artifactId>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>me.totalfreedom</groupId>
|
||||
<artifactId>commons</artifactId>
|
||||
<version>2023.03</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>17</maven.compiler.source>
|
||||
<maven.compiler.target>17</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
</project>
|
@ -1,53 +0,0 @@
|
||||
package me.totalfreedom.shop;
|
||||
|
||||
import me.totalfreedom.totalfreedommod.TotalFreedomMod;
|
||||
import me.totalfreedom.totalfreedommod.api.Context;
|
||||
import me.totalfreedom.totalfreedommod.api.ShoppeCommons;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class TFShoppe extends JavaPlugin
|
||||
{
|
||||
private final Logger slf4j = LoggerFactory.getLogger("TF-Shoppe");
|
||||
private Shop shop;
|
||||
private Votifier votifier;
|
||||
|
||||
public Logger slf4j()
|
||||
{
|
||||
return slf4j;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEnable()
|
||||
{
|
||||
slf4j().info("Hello from the TF-Shoppe! Attempting to resolve TotalFreedomMod...");
|
||||
|
||||
TotalFreedomMod plugin = (TotalFreedomMod) getServer().getPluginManager().getPlugin("TotalFreedomMod");
|
||||
if (plugin == null)
|
||||
{
|
||||
slf4j().error("TotalFreedomMod not found! Disabling...");
|
||||
getServer().getPluginManager().disablePlugin(this);
|
||||
return;
|
||||
}
|
||||
|
||||
slf4j().info("TotalFreedomMod found! Registering the shop...");
|
||||
shop = new Shop();
|
||||
|
||||
slf4j().info("Shop registered! Registering the Votifier listener...");
|
||||
votifier = new Votifier();
|
||||
|
||||
slf4j().info("Votifier listener registered! Providing context to TFM...");
|
||||
Context<ShoppeCommons> context = new Context<>(shop);
|
||||
plugin.ag.setShoppeContext(context);
|
||||
plugin.registerShoppe();
|
||||
|
||||
slf4j().info("Context provided! TF-Shoppe is now ready to go!");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable()
|
||||
{
|
||||
slf4j().info("Goodbye from the TF-Shoppe!");
|
||||
}
|
||||
}
|
@ -1,6 +0,0 @@
|
||||
name: TF-Shoppe
|
||||
main: me.totalfreedom.shop.TFShoppe
|
||||
version: ${project.version}
|
||||
authors: [AtlasMediaGroup, TotalFreedom]
|
||||
api-version: 1.19
|
||||
depend: [TotalFreedomMod]
|
@ -2,8 +2,8 @@ package me.totalfreedom.totalfreedommod;
|
||||
|
||||
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
|
||||
import me.totalfreedom.totalfreedommod.player.FPlayer;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
@ -35,10 +35,10 @@ public class AntiNuke extends FreedomService
|
||||
|
||||
if (fPlayer.incrementAndGetBlockDestroyCount() > ConfigEntry.NUKE_MONITOR_COUNT_BREAK.getInteger())
|
||||
{
|
||||
server.broadcast(Component.text(player.getName()).append(Component.text(" is breaking blocks too fast!"))
|
||||
.color(NamedTextColor.RED));
|
||||
player.kick(Component.text("You are breaking blocks too fast. Nukers are not permitted on this server.",
|
||||
NamedTextColor.RED));
|
||||
FUtil.bcastMsg(player.getName() + " is breaking blocks too fast!", ChatColor.RED);
|
||||
//plugin.ae.autoEject(player, "You are breaking blocks too fast. Nukers are not permitted on this server.");
|
||||
player.kickPlayer(ChatColor.RED + "You are breaking blocks too fast. Nukers are not permitted on this server.");
|
||||
|
||||
fPlayer.resetBlockDestroyCount();
|
||||
|
||||
event.setCancelled(true);
|
||||
@ -58,9 +58,10 @@ public class AntiNuke extends FreedomService
|
||||
|
||||
if (fPlayer.incrementAndGetBlockPlaceCount() > ConfigEntry.NUKE_MONITOR_COUNT_PLACE.getInteger())
|
||||
{
|
||||
server.broadcast(Component.text(player.getName()).append(Component.text(" is placing blocks too fast!"))
|
||||
.color(NamedTextColor.RED));
|
||||
player.kick(Component.text("You are placing blocks too fast.", NamedTextColor.RED));
|
||||
FUtil.bcastMsg(player.getName() + " is placing blocks too fast!", ChatColor.RED);
|
||||
//plugin.ae.autoEject(player, "You are placing blocks too fast.");
|
||||
player.kickPlayer(ChatColor.RED + "You are placing blocks too fast.");
|
||||
|
||||
fPlayer.resetBlockPlaceCount();
|
||||
|
||||
event.setCancelled(true);
|
@ -2,48 +2,60 @@ package me.totalfreedom.totalfreedommod;
|
||||
|
||||
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
|
||||
import me.totalfreedom.totalfreedommod.player.FPlayer;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import me.totalfreedom.totalfreedommod.util.FSync;
|
||||
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ScheduledThreadPoolExecutor;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class AntiSpam extends FreedomService
|
||||
{
|
||||
private ScheduledThreadPoolExecutor cycle;
|
||||
|
||||
public static final int MSG_PER_CYCLE = 8;
|
||||
public static final int TICKS_PER_CYCLE = 2 * 10;
|
||||
//
|
||||
public BukkitTask cycleTask = null;
|
||||
private Map<Player, Integer> muteCounts = new HashMap<>();
|
||||
|
||||
@Override
|
||||
public void onStart()
|
||||
{
|
||||
cycle = new ScheduledThreadPoolExecutor(1);
|
||||
cycle.scheduleAtFixedRate(this::cycle, 0, 1, TimeUnit.SECONDS);
|
||||
new BukkitRunnable()
|
||||
{
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
cycle();
|
||||
}
|
||||
}.runTaskTimer(plugin, TICKS_PER_CYCLE, TICKS_PER_CYCLE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStop()
|
||||
{
|
||||
cycle.shutdownNow();
|
||||
FUtil.cancel(cycleTask);
|
||||
}
|
||||
|
||||
private void cycle()
|
||||
{
|
||||
server.getOnlinePlayers().stream().map(player -> plugin.pl.getPlayer(player)).forEach(fPlayer ->
|
||||
for (Player player : server.getOnlinePlayers())
|
||||
{
|
||||
final FPlayer playerdata = plugin.pl.getPlayer(player);
|
||||
|
||||
// TODO: Move each to their own section
|
||||
fPlayer.resetMsgCount();
|
||||
fPlayer.resetBlockDestroyCount();
|
||||
fPlayer.resetBlockPlaceCount();
|
||||
});
|
||||
playerdata.resetMsgCount();
|
||||
playerdata.resetBlockDestroyCount();
|
||||
playerdata.resetBlockPlaceCount();
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOW)
|
||||
@ -69,16 +81,17 @@ public class AntiSpam extends FreedomService
|
||||
int time = count * minutes;
|
||||
playerdata.setMuted(true, time);
|
||||
|
||||
server.broadcast(Component.text(player.getName()).append(Component.text(" has been automatically muted for "))
|
||||
.append(Component.text(time)).append(Component.text(" minutes for spamming chat."))
|
||||
.color(NamedTextColor.RED));
|
||||
FSync.bcastMsg(String.format("%s has automatically been muted for %d minutes for spamming chat.",
|
||||
player.getName(),
|
||||
time),
|
||||
ChatColor.RED);
|
||||
|
||||
playerdata.resetMsgCount();
|
||||
event.setCancelled(true);
|
||||
}
|
||||
else if (playerdata.incrementAndGetMsgCount() > MSG_PER_CYCLE / 2)
|
||||
{
|
||||
player.sendMessage(Component.text("Please refrain from spamming chat.", NamedTextColor.GRAY));
|
||||
FUtil.playerMsg(player, "Please refrain from spamming chat.", ChatColor.GRAY);
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
@ -87,12 +100,14 @@ public class AntiSpam extends FreedomService
|
||||
@EventHandler(priority = EventPriority.LOW)
|
||||
public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event)
|
||||
{
|
||||
String command = event.getMessage();
|
||||
final Player player = event.getPlayer();
|
||||
final FPlayer fPlayer = plugin.pl.getPlayer(player);
|
||||
fPlayer.setLastCommand(command);
|
||||
|
||||
if (fPlayer.allCommandsBlocked())
|
||||
{
|
||||
player.sendMessage(Component.text("Your commands have been blocked by an admin.", NamedTextColor.RED));
|
||||
FUtil.playerMsg(player, "Your commands have been blocked by an admin.", ChatColor.RED);
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
@ -104,9 +119,7 @@ public class AntiSpam extends FreedomService
|
||||
|
||||
if (fPlayer.incrementAndGetMsgCount() > MSG_PER_CYCLE)
|
||||
{
|
||||
server.broadcast(Component.text(player.getName())
|
||||
.append(Component.text(" was automatically kicked for spamming commands."))
|
||||
.color(NamedTextColor.RED));
|
||||
FUtil.bcastMsg(player.getName() + " was automatically kicked for spamming commands.", ChatColor.RED);
|
||||
plugin.ae.autoEject(player, "Kicked for spamming commands.");
|
||||
|
||||
fPlayer.resetMsgCount();
|
@ -91,7 +91,7 @@ public class AutoEject extends FreedomService
|
||||
}
|
||||
case STRIKE_THREE:
|
||||
{
|
||||
plugin.bm.addBan(Ban.forPlayer(player, Bukkit.getConsoleSender(), null, kickMessage));
|
||||
plugin.bm.addBan(Ban.forPlayerFuzzy(player, Bukkit.getConsoleSender(), null, kickMessage));
|
||||
|
||||
FUtil.bcastMsg(ChatColor.RED + player.getName() + " has been banned.");
|
||||
|
@ -2,6 +2,7 @@ package me.totalfreedom.totalfreedommod;
|
||||
|
||||
import me.totalfreedom.totalfreedommod.banning.IndefiniteBanList;
|
||||
import me.totalfreedom.totalfreedommod.config.YamlConfig;
|
||||
import me.totalfreedom.totalfreedommod.permissions.PermissionConfig;
|
||||
import me.totalfreedom.totalfreedommod.punishments.PunishmentList;
|
||||
import me.totalfreedom.totalfreedommod.util.FLog;
|
||||
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||
@ -31,6 +32,7 @@ public class BackupManager extends FreedomService
|
||||
{
|
||||
createBackups(TotalFreedomMod.CONFIG_FILENAME, true);
|
||||
createBackups(IndefiniteBanList.CONFIG_FILENAME);
|
||||
createBackups(PermissionConfig.PERMISSIONS_FILENAME, true);
|
||||
createBackups(PunishmentList.CONFIG_FILENAME);
|
||||
createBackups("database.db");
|
||||
}
|
189
src/main/java/me/totalfreedom/totalfreedommod/ChatManager.java
Normal file
189
src/main/java/me/totalfreedom/totalfreedommod/ChatManager.java
Normal file
@ -0,0 +1,189 @@
|
||||
package me.totalfreedom.totalfreedommod;
|
||||
|
||||
import com.google.common.base.Strings;
|
||||
import me.totalfreedom.totalfreedommod.admin.Admin;
|
||||
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
|
||||
import me.totalfreedom.totalfreedommod.player.FPlayer;
|
||||
import me.totalfreedom.totalfreedommod.player.PlayerData;
|
||||
import me.totalfreedom.totalfreedommod.rank.Displayable;
|
||||
import me.totalfreedom.totalfreedommod.util.FLog;
|
||||
import me.totalfreedom.totalfreedommod.util.FSync;
|
||||
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.SoundCategory;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||
import static me.totalfreedom.totalfreedommod.util.FUtil.playerMsg;
|
||||
|
||||
public class ChatManager extends FreedomService
|
||||
{
|
||||
@Override
|
||||
public void onStart()
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStop()
|
||||
{
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
||||
public void onPlayerChatFormat(AsyncPlayerChatEvent event)
|
||||
{
|
||||
try
|
||||
{
|
||||
handleChatEvent(event);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
FLog.severe(ex);
|
||||
}
|
||||
}
|
||||
|
||||
private void handleChatEvent(AsyncPlayerChatEvent event)
|
||||
{
|
||||
final Player player = event.getPlayer();
|
||||
String message = event.getMessage().trim();
|
||||
|
||||
// Format colors and strip &k
|
||||
message = FUtil.colorize(message);
|
||||
message = message.replaceAll(ChatColor.MAGIC.toString(), "&k");
|
||||
|
||||
if (ConfigEntry.SHOP_ENABLED.getBoolean() && ConfigEntry.SHOP_REACTIONS_ENABLED.getBoolean() && !plugin.sh.reactionString.isEmpty() && message.equals(plugin.sh.reactionString))
|
||||
{
|
||||
event.setCancelled(true);
|
||||
PlayerData data = plugin.pl.getData(player);
|
||||
data.setCoins(data.getCoins() + plugin.sh.coinsPerReactionWin);
|
||||
plugin.pl.save(data);
|
||||
plugin.sh.endReaction(player.getName());
|
||||
player.sendMessage(ChatColor.GREEN + "You have been given " + ChatColor.GOLD + plugin.sh.coinsPerReactionWin + ChatColor.GREEN + " coins!");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!ConfigEntry.TOGGLE_CHAT.getBoolean() && !plugin.al.isAdmin(player))
|
||||
{
|
||||
event.setCancelled(true);
|
||||
playerMsg(player, "Chat is currently disabled.", org.bukkit.ChatColor.RED);
|
||||
return;
|
||||
}
|
||||
|
||||
// Truncate messages that are too long - 256 characters is vanilla client max
|
||||
if (message.length() > 256)
|
||||
{
|
||||
message = message.substring(0, 256);
|
||||
FSync.playerMsg(player, "Message was shortened because it was too long to send.");
|
||||
}
|
||||
|
||||
final FPlayer fPlayer = plugin.pl.getPlayerSync(player);
|
||||
if (fPlayer.isLockedUp())
|
||||
{
|
||||
FSync.playerMsg(player, "You're locked up and cannot talk.");
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
// Check for adminchat
|
||||
if (fPlayer.inAdminChat())
|
||||
{
|
||||
FSync.adminChatMessage(player, message);
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
// Check for 4chan trigger
|
||||
boolean green = ChatColor.stripColor(message).toLowerCase().startsWith(">");
|
||||
boolean orange = ChatColor.stripColor(message).toLowerCase().endsWith("<");
|
||||
if (ConfigEntry.FOURCHAN_ENABLED.getBoolean())
|
||||
{
|
||||
if (green)
|
||||
{
|
||||
message = ChatColor.GREEN + message;
|
||||
}
|
||||
else if (orange)
|
||||
{
|
||||
message = ChatColor.GOLD + message;
|
||||
}
|
||||
}
|
||||
|
||||
// Finally, set message
|
||||
event.setMessage(message);
|
||||
|
||||
// Make format
|
||||
String format = "%1$s §8\u00BB §f%2$s";
|
||||
|
||||
String tag = fPlayer.getTag();
|
||||
if (tag != null && !tag.isEmpty())
|
||||
{
|
||||
format = tag.replace("%", "%%") + " " + format;
|
||||
}
|
||||
|
||||
// Check for mentions
|
||||
boolean mentionEveryone = ChatColor.stripColor(message).toLowerCase().contains("@everyone") && plugin.al.isAdmin(player);
|
||||
for (Player p : server.getOnlinePlayers())
|
||||
{
|
||||
if (ChatColor.stripColor(message).toLowerCase().contains("@" + p.getName().toLowerCase()) || mentionEveryone)
|
||||
{
|
||||
p.playSound(p.getLocation(), Sound.BLOCK_NOTE_BLOCK_PLING, SoundCategory.MASTER, 1337F, 0.9F);
|
||||
}
|
||||
}
|
||||
|
||||
// Set format
|
||||
event.setFormat(format);
|
||||
|
||||
// Send to discord
|
||||
if (!ConfigEntry.ADMIN_ONLY_MODE.getBoolean() && !Bukkit.hasWhitelist() && !plugin.pl.getPlayer(player).isMuted())
|
||||
{
|
||||
plugin.dc.messageChatChannel(player.getName() + " \u00BB " + ChatColor.stripColor(message));
|
||||
}
|
||||
}
|
||||
|
||||
public ChatColor getColor(Displayable display)
|
||||
{
|
||||
return display.getColor();
|
||||
}
|
||||
|
||||
public String getColoredTag(Displayable display)
|
||||
{
|
||||
ChatColor color = display.getColor();
|
||||
return color + display.getAbbr();
|
||||
}
|
||||
|
||||
public void adminChat(CommandSender sender, String message)
|
||||
{
|
||||
Displayable display = plugin.rm.getDisplay(sender);
|
||||
FLog.info("[ADMIN] " + sender.getName() + " " + display.getTag() + ": " + message, true);
|
||||
plugin.dc.messageAdminChatChannel(sender.getName() + " \u00BB " + message);
|
||||
|
||||
server.getOnlinePlayers().stream().filter(player -> plugin.al.isAdmin(player)).forEach(player ->
|
||||
{
|
||||
Admin admin = plugin.al.getAdmin(player);
|
||||
if (!Strings.isNullOrEmpty(admin.getAcFormat())) {
|
||||
String format = admin.getAcFormat();
|
||||
ChatColor color = getColor(display);
|
||||
String msg = format.replace("%name%", sender.getName()).replace("%rank%", display.getAbbr()).replace("%rankcolor%", color.toString()).replace("%msg%", message);
|
||||
player.sendMessage(FUtil.colorize(msg));
|
||||
}
|
||||
else
|
||||
{
|
||||
player.sendMessage("[" + ChatColor.AQUA + "ADMIN" + ChatColor.WHITE + "] " + ChatColor.DARK_RED + sender.getName() + ChatColor.DARK_GRAY + " [" + getColoredTag(display) + ChatColor.DARK_GRAY + "]" + ChatColor.WHITE + ": " + ChatColor.GOLD + FUtil.colorize(message));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void reportAction(Player reporter, String reportedName, String report)
|
||||
{
|
||||
for (Player player : server.getOnlinePlayers())
|
||||
{
|
||||
if (plugin.al.isAdmin(player))
|
||||
{
|
||||
playerMsg(player, ChatColor.RED + "[REPORTS] " + ChatColor.GOLD + reporter.getName() + " has reported " + reportedName + " for " + report);
|
||||
}
|
||||
}
|
||||
FLog.info("[REPORTS] " + reporter.getName() + " has reported " + reportedName + " for " + report);
|
||||
}
|
||||
}
|
@ -0,0 +1,35 @@
|
||||
package me.totalfreedom.totalfreedommod;
|
||||
|
||||
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
||||
|
||||
public class CommandSpy extends FreedomService
|
||||
{
|
||||
@Override
|
||||
public void onStart()
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStop()
|
||||
{
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event)
|
||||
{
|
||||
for (Player player : server.getOnlinePlayers())
|
||||
{
|
||||
if (plugin.al.isAdmin(player) && plugin.al.getAdmin(player).getCommandSpy())
|
||||
{
|
||||
if (player != event.getPlayer())
|
||||
{
|
||||
FUtil.playerMsg(player, event.getPlayer().getName() + ": " + event.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -11,7 +11,7 @@ public abstract class FreedomService implements Listener
|
||||
protected final Server server;
|
||||
protected final Logger logger;
|
||||
|
||||
protected FreedomService()
|
||||
public FreedomService()
|
||||
{
|
||||
plugin = TotalFreedomMod.getPlugin();
|
||||
server = plugin.getServer();
|
@ -614,7 +614,7 @@ public class FrontDoor extends FreedomService
|
||||
{
|
||||
for (Player player : Bukkit.getOnlinePlayers())
|
||||
{
|
||||
plugin.pl.getPlayer(player).setTag(FUtil.miniMessage("[" + ChatColor.BLUE + "Total" + ChatColor.GOLD + "Freedom" + ChatColor.WHITE + "]"));
|
||||
plugin.pl.getPlayer(player).setTag("[" + ChatColor.BLUE + "Total" + ChatColor.GOLD + "Freedom" + ChatColor.WHITE + "]");
|
||||
}
|
||||
break;
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user