mirror of
https://github.com/AtlasMediaGroup/TotalFreedomMod.git
synced 2025-07-01 12:36:41 +00:00
Compare commits
7 Commits
RELEASE-20
...
dependabot
Author | SHA1 | Date | |
---|---|---|---|
f77c071fa0 | |||
1c096b97e3 | |||
cc48f93556 | |||
dd373fc9aa | |||
41331e719d | |||
72c83ba84a | |||
3deaaafb88 |
2
.gitignore
vendored
2
.gitignore
vendored
@ -29,7 +29,7 @@ manifest.mf
|
|||||||
*.iml
|
*.iml
|
||||||
|
|
||||||
# Maven excludes
|
# Maven excludes
|
||||||
target/
|
/target
|
||||||
|
|
||||||
# OS generated files
|
# OS generated files
|
||||||
.DS_Store
|
.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,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,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,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,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,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,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,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,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,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,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
|
|
259
pom.xml
259
pom.xml
@ -5,18 +5,12 @@
|
|||||||
|
|
||||||
<groupId>me.totalfreedom</groupId>
|
<groupId>me.totalfreedom</groupId>
|
||||||
<artifactId>TotalFreedomMod</artifactId>
|
<artifactId>TotalFreedomMod</artifactId>
|
||||||
<version>2023.03</version>
|
<version>2022.06.1</version>
|
||||||
<packaging>pom</packaging>
|
<packaging>jar</packaging>
|
||||||
<modules>
|
|
||||||
<module>commons</module>
|
|
||||||
<module>shop</module>
|
|
||||||
<module>discord</module>
|
|
||||||
</modules>
|
|
||||||
|
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<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>
|
<jar.finalName>${project.name}</jar.finalName>
|
||||||
<timestamp>${maven.build.timestamp}</timestamp>
|
<timestamp>${maven.build.timestamp}</timestamp>
|
||||||
<maven.build.timestamp.format>MM/dd/yyyy HH:mm</maven.build.timestamp.format>
|
<maven.build.timestamp.format>MM/dd/yyyy HH:mm</maven.build.timestamp.format>
|
||||||
@ -71,6 +65,11 @@
|
|||||||
<url>https://maven.elmakers.com/repository/</url>
|
<url>https://maven.elmakers.com/repository/</url>
|
||||||
</repository>
|
</repository>
|
||||||
|
|
||||||
|
<repository>
|
||||||
|
<id>sk89q-snapshots</id>
|
||||||
|
<url>https://maven.sk89q.com/artifactory/repo</url>
|
||||||
|
</repository>
|
||||||
|
|
||||||
<repository>
|
<repository>
|
||||||
<id>dv8tion</id>
|
<id>dv8tion</id>
|
||||||
<name>m2-dv8tion</name>
|
<name>m2-dv8tion</name>
|
||||||
@ -92,6 +91,11 @@
|
|||||||
<url>https://repo.dmulloy2.net/nexus/repository/public/</url>
|
<url>https://repo.dmulloy2.net/nexus/repository/public/</url>
|
||||||
</repository>
|
</repository>
|
||||||
|
|
||||||
|
<repository>
|
||||||
|
<id>sk89q-repo</id>
|
||||||
|
<url>https://maven.sk89q.com/repo/</url>
|
||||||
|
</repository>
|
||||||
|
|
||||||
<repository>
|
<repository>
|
||||||
<id>esentialsx-repo</id>
|
<id>esentialsx-repo</id>
|
||||||
<url>https://repo.essentialsx.net/releases/</url>
|
<url>https://repo.essentialsx.net/releases/</url>
|
||||||
@ -101,10 +105,31 @@
|
|||||||
|
|
||||||
<dependencies>
|
<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>
|
<dependency>
|
||||||
<groupId>me.totalfreedom.scissors</groupId>
|
<groupId>me.totalfreedom.scissors</groupId>
|
||||||
<artifactId>Scissors-API</artifactId>
|
<artifactId>scissors-api</artifactId>
|
||||||
<version>1.19.3-R0.1-SNAPSHOT</version>
|
<version>1.17.1-R0.1-SNAPSHOT</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
@ -129,6 +154,13 @@
|
|||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>net.dv8tion</groupId>
|
||||||
|
<artifactId>JDA</artifactId>
|
||||||
|
<version>4.4.1_353</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>net.coreprotect</groupId>
|
<groupId>net.coreprotect</groupId>
|
||||||
<artifactId>coreprotect</artifactId>
|
<artifactId>coreprotect</artifactId>
|
||||||
@ -143,6 +175,13 @@
|
|||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>io.papermc</groupId>
|
||||||
|
<artifactId>paperlib</artifactId>
|
||||||
|
<version>1.0.7</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.github.vexsoftware</groupId>
|
<groupId>com.github.vexsoftware</groupId>
|
||||||
<artifactId>votifier</artifactId>
|
<artifactId>votifier</artifactId>
|
||||||
@ -157,18 +196,25 @@
|
|||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.reflections</groupId>
|
||||||
|
<artifactId>reflections</artifactId>
|
||||||
|
<version>0.10.2</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.javassist</groupId>
|
<groupId>org.javassist</groupId>
|
||||||
<artifactId>javassist</artifactId>
|
<artifactId>javassist</artifactId>
|
||||||
<version>3.29.1-GA</version>
|
<version>3.29.1-GA</version>
|
||||||
<scope>provided</scope>
|
<scope>compile</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.jetbrains</groupId>
|
<groupId>org.jetbrains</groupId>
|
||||||
<artifactId>annotations</artifactId>
|
<artifactId>annotations</artifactId>
|
||||||
<version>23.0.0</version>
|
<version>23.0.0</version>
|
||||||
<scope>provided</scope>
|
<scope>compile</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
@ -177,13 +223,19 @@
|
|||||||
<version>3.1.2</version>
|
<version>3.1.2</version>
|
||||||
<scope>compile</scope>
|
<scope>compile</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.junit.jupiter</groupId>
|
<groupId>org.junit.jupiter</groupId>
|
||||||
<artifactId>junit-jupiter</artifactId>
|
<artifactId>junit-jupiter</artifactId>
|
||||||
<version>5.9.0</version>
|
<version>5.9.0</version>
|
||||||
<scope>compile</scope>
|
<scope>compile</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.eclipse.sisu</groupId>
|
||||||
|
<artifactId>org.eclipse.sisu.inject</artifactId>
|
||||||
|
<version>0.3.5</version>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<pluginRepositories>
|
<pluginRepositories>
|
||||||
@ -193,6 +245,185 @@
|
|||||||
</pluginRepository>
|
</pluginRepository>
|
||||||
</pluginRepositories>
|
</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.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>
|
||||||
|
|
||||||
|
|
||||||
<reporting>
|
<reporting>
|
||||||
<!-- Checkstyle -->
|
<!-- Checkstyle -->
|
||||||
<plugins>
|
<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]
|
|
@ -87,8 +87,10 @@ public class AntiSpam extends FreedomService
|
|||||||
@EventHandler(priority = EventPriority.LOW)
|
@EventHandler(priority = EventPriority.LOW)
|
||||||
public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event)
|
public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event)
|
||||||
{
|
{
|
||||||
|
String command = event.getMessage();
|
||||||
final Player player = event.getPlayer();
|
final Player player = event.getPlayer();
|
||||||
final FPlayer fPlayer = plugin.pl.getPlayer(player);
|
final FPlayer fPlayer = plugin.pl.getPlayer(player);
|
||||||
|
fPlayer.setLastCommand(command);
|
||||||
|
|
||||||
if (fPlayer.allCommandsBlocked())
|
if (fPlayer.allCommandsBlocked())
|
||||||
{
|
{
|
@ -2,6 +2,7 @@ package me.totalfreedom.totalfreedommod;
|
|||||||
|
|
||||||
import me.totalfreedom.totalfreedommod.banning.IndefiniteBanList;
|
import me.totalfreedom.totalfreedommod.banning.IndefiniteBanList;
|
||||||
import me.totalfreedom.totalfreedommod.config.YamlConfig;
|
import me.totalfreedom.totalfreedommod.config.YamlConfig;
|
||||||
|
import me.totalfreedom.totalfreedommod.permissions.PermissionConfig;
|
||||||
import me.totalfreedom.totalfreedommod.punishments.PunishmentList;
|
import me.totalfreedom.totalfreedommod.punishments.PunishmentList;
|
||||||
import me.totalfreedom.totalfreedommod.util.FLog;
|
import me.totalfreedom.totalfreedommod.util.FLog;
|
||||||
import me.totalfreedom.totalfreedommod.util.FUtil;
|
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||||
@ -31,6 +32,7 @@ public class BackupManager extends FreedomService
|
|||||||
{
|
{
|
||||||
createBackups(TotalFreedomMod.CONFIG_FILENAME, true);
|
createBackups(TotalFreedomMod.CONFIG_FILENAME, true);
|
||||||
createBackups(IndefiniteBanList.CONFIG_FILENAME);
|
createBackups(IndefiniteBanList.CONFIG_FILENAME);
|
||||||
|
createBackups(PermissionConfig.PERMISSIONS_FILENAME, true);
|
||||||
createBackups(PunishmentList.CONFIG_FILENAME);
|
createBackups(PunishmentList.CONFIG_FILENAME);
|
||||||
createBackups("database.db");
|
createBackups("database.db");
|
||||||
}
|
}
|
182
src/main/java/me/totalfreedom/totalfreedommod/ChatManager.java
Normal file
182
src/main/java/me/totalfreedom/totalfreedommod/ChatManager.java
Normal file
@ -0,0 +1,182 @@
|
|||||||
|
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.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.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.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
|
||||||
|
if (ConfigEntry.FOURCHAN_ENABLED.getBoolean())
|
||||||
|
{
|
||||||
|
boolean green = ChatColor.stripColor(message).toLowerCase().startsWith(">");
|
||||||
|
boolean orange = ChatColor.stripColor(message).toLowerCase().endsWith("<");
|
||||||
|
|
||||||
|
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
|
||||||
|
String stripped = ChatColor.stripColor(message).toLowerCase();
|
||||||
|
|
||||||
|
/* There is an issue would have allowed muted players to ping players. The issue is caused by the order in which
|
||||||
|
* these event handlers are registered when the plugin starts up. Muter is registered after the ChatManager,
|
||||||
|
* which results in latter being called first (before the former can cancel it). EventPriority does not seem to
|
||||||
|
* make a difference. As a short-term solution I've added this mute check alongside the usual isCancelled check
|
||||||
|
* so that the issue is mitigated, but a long-term solution should be to change the order in which things like
|
||||||
|
* ChatManager and Muter are registered. */
|
||||||
|
if (!event.isCancelled() && !plugin.pl.getPlayer(player).isMuted())
|
||||||
|
{
|
||||||
|
server.getOnlinePlayers().forEach(pl ->
|
||||||
|
{
|
||||||
|
if (stripped.contains("@" + pl.getName()) || (plugin.al.isAdmin(player) && stripped.contains("@everyone")))
|
||||||
|
{
|
||||||
|
pl.playSound(pl.getLocation(), Sound.BLOCK_NOTE_BLOCK_PLING, SoundCategory.MASTER, 1337F, 0.9F);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set format
|
||||||
|
event.setFormat(format);
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
@ -1,7 +1,7 @@
|
|||||||
package me.totalfreedom.totalfreedommod;
|
package me.totalfreedom.totalfreedommod;
|
||||||
|
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import net.kyori.adventure.text.format.NamedTextColor;
|
import net.kyori.adventure.text.event.ClickEvent;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.EventPriority;
|
import org.bukkit.event.EventPriority;
|
||||||
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
||||||
@ -24,6 +24,6 @@ public class CommandSpy extends FreedomService
|
|||||||
server.getOnlinePlayers().stream().filter(player -> plugin.al.isAdmin(player)
|
server.getOnlinePlayers().stream().filter(player -> plugin.al.isAdmin(player)
|
||||||
&& plugin.al.getAdmin(player).getCommandSpy() && player != event.getPlayer()).forEach(player ->
|
&& plugin.al.getAdmin(player).getCommandSpy() && player != event.getPlayer()).forEach(player ->
|
||||||
player.sendMessage(Component.text(event.getPlayer().getName()).append(Component.text(": "))
|
player.sendMessage(Component.text(event.getPlayer().getName()).append(Component.text(": "))
|
||||||
.append(Component.text(event.getMessage())).color(NamedTextColor.GRAY)));
|
.append(Component.text(event.getMessage()))));
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -11,7 +11,7 @@ public abstract class FreedomService implements Listener
|
|||||||
protected final Server server;
|
protected final Server server;
|
||||||
protected final Logger logger;
|
protected final Logger logger;
|
||||||
|
|
||||||
protected FreedomService()
|
public FreedomService()
|
||||||
{
|
{
|
||||||
plugin = TotalFreedomMod.getPlugin();
|
plugin = TotalFreedomMod.getPlugin();
|
||||||
server = plugin.getServer();
|
server = plugin.getServer();
|
@ -614,7 +614,7 @@ public class FrontDoor extends FreedomService
|
|||||||
{
|
{
|
||||||
for (Player player : Bukkit.getOnlinePlayers())
|
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;
|
break;
|
||||||
}
|
}
|
@ -1,6 +1,5 @@
|
|||||||
package me.totalfreedom.totalfreedommod;
|
package me.totalfreedom.totalfreedommod;
|
||||||
|
|
||||||
import com.google.common.base.Strings;
|
|
||||||
import io.papermc.lib.PaperLib;
|
import io.papermc.lib.PaperLib;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -11,12 +10,9 @@ import me.totalfreedom.totalfreedommod.admin.Admin;
|
|||||||
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
|
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
|
||||||
import me.totalfreedom.totalfreedommod.player.FPlayer;
|
import me.totalfreedom.totalfreedommod.player.FPlayer;
|
||||||
import me.totalfreedom.totalfreedommod.player.PlayerData;
|
import me.totalfreedom.totalfreedommod.player.PlayerData;
|
||||||
import me.totalfreedom.totalfreedommod.util.FConverter;
|
|
||||||
import me.totalfreedom.totalfreedommod.util.FLog;
|
import me.totalfreedom.totalfreedommod.util.FLog;
|
||||||
import me.totalfreedom.totalfreedommod.util.FSync;
|
import me.totalfreedom.totalfreedommod.util.FSync;
|
||||||
import me.totalfreedom.totalfreedommod.util.FUtil;
|
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.ChatColor;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
@ -37,6 +33,7 @@ public class LoginProcess extends FreedomService
|
|||||||
private static boolean lockdownEnabled = false;
|
private static boolean lockdownEnabled = false;
|
||||||
public List<String> TELEPORT_ON_JOIN = new ArrayList<>();
|
public List<String> TELEPORT_ON_JOIN = new ArrayList<>();
|
||||||
public List<String> CLEAR_ON_JOIN = new ArrayList<>();
|
public List<String> CLEAR_ON_JOIN = new ArrayList<>();
|
||||||
|
public List<String> CLOWNFISH_TOGGLE = new ArrayList<>();
|
||||||
|
|
||||||
public static boolean isLockdownEnabled()
|
public static boolean isLockdownEnabled()
|
||||||
{
|
{
|
||||||
@ -203,21 +200,25 @@ public class LoginProcess extends FreedomService
|
|||||||
@Override
|
@Override
|
||||||
public void run()
|
public void run()
|
||||||
{
|
{
|
||||||
ConfigEntry.FIRST_JOIN_INFO.getStringList().forEach(line -> FUtil.playerMsgCooler(player, line));
|
for (String line : ConfigEntry.FIRST_JOIN_INFO.getStringList())
|
||||||
|
{
|
||||||
|
player.sendMessage(FUtil.colorize(line));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}.runTaskLater(plugin, 20);
|
}.runTaskLater(plugin, 20);
|
||||||
}
|
}
|
||||||
|
|
||||||
FUtil.playerTitle(player, ConfigEntry.SERVER_LOGIN_TITLE.getString(), ConfigEntry.SERVER_LOGIN_SUBTITLE.getString());
|
player.sendTitle(FUtil.colorize(ConfigEntry.SERVER_LOGIN_TITLE.getString()), FUtil.colorize(ConfigEntry.SERVER_LOGIN_SUBTITLE.getString()), 20, 100, 60);
|
||||||
|
player.setOp(true);
|
||||||
|
|
||||||
if (TELEPORT_ON_JOIN.contains(player.getName()) || ConfigEntry.AUTO_TP.getBoolean())
|
if (TELEPORT_ON_JOIN.contains(player.getName()) || ConfigEntry.AUTO_TP.getBoolean())
|
||||||
{
|
{
|
||||||
int x = FUtil.randomInteger(-10000, 10000);
|
int x = FUtil.randomInteger(-10000, 10000);
|
||||||
int z = FUtil.randomInteger(-10000, 10000);
|
int z = FUtil.randomInteger(-10000, 10000);
|
||||||
int y = player.getWorld().getHighestBlockYAt(x, z) + 1;
|
int y = player.getWorld().getHighestBlockYAt(x, z);
|
||||||
Location location = new Location(player.getLocation().getWorld(), x, y, z);
|
Location location = new Location(player.getLocation().getWorld(), x, y, z);
|
||||||
PaperLib.teleportAsync(player, location);
|
PaperLib.teleportAsync(player, location);
|
||||||
FUtil.playerMsgCooler(player, "<aqua>You have been automatically teleported to a random location.");
|
player.sendMessage(ChatColor.AQUA + "You have been teleported to a random location automatically.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -230,47 +231,35 @@ public class LoginProcess extends FreedomService
|
|||||||
if (CLEAR_ON_JOIN.contains(player.getName()) || ConfigEntry.AUTO_CLEAR.getBoolean())
|
if (CLEAR_ON_JOIN.contains(player.getName()) || ConfigEntry.AUTO_CLEAR.getBoolean())
|
||||||
{
|
{
|
||||||
player.getInventory().clear();
|
player.getInventory().clear();
|
||||||
FUtil.playerMsgCooler(player, "<aqua>Your inventory has been automatically cleared.");
|
player.sendMessage(ChatColor.AQUA + "Your inventory has been cleared automatically.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!ConfigEntry.SERVER_TABLIST_HEADER.getString().isEmpty())
|
if (!ConfigEntry.SERVER_TABLIST_HEADER.getString().isEmpty())
|
||||||
{
|
{
|
||||||
player.sendPlayerListHeader(FUtil.miniMessage(ConfigEntry.SERVER_TABLIST_HEADER.getString()));
|
player.setPlayerListHeader(FUtil.colorize(ConfigEntry.SERVER_TABLIST_HEADER.getString()).replace("\\n", "\n"));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!ConfigEntry.SERVER_TABLIST_FOOTER.getString().isEmpty())
|
if (!ConfigEntry.SERVER_TABLIST_FOOTER.getString().isEmpty())
|
||||||
{
|
{
|
||||||
player.sendPlayerListFooter(FUtil.miniMessage(ConfigEntry.SERVER_TABLIST_FOOTER.getString()));
|
player.setPlayerListFooter(FUtil.colorize(ConfigEntry.SERVER_TABLIST_FOOTER.getString()).replace("\\n", "\n"));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!plugin.al.isAdmin(player))
|
if (!plugin.al.isAdmin(player))
|
||||||
{
|
{
|
||||||
Component tag = playerData.getTag();
|
String tag = playerData.getTag();
|
||||||
if (tag != null)
|
if (tag != null)
|
||||||
{
|
{
|
||||||
fPlayer.setTag(tag);
|
fPlayer.setTag(FUtil.colorize(tag));
|
||||||
}
|
}
|
||||||
|
|
||||||
int noteCount = playerData.getNotes().size();
|
int noteCount = playerData.getNotes().size();
|
||||||
if (noteCount != 0)
|
if (noteCount != 0)
|
||||||
{
|
{
|
||||||
plugin.cm.messageAllAdmins("<gold>This player has <yellow><count> <gold>admin note<plural>.",
|
String noteMessage = "This player has " + noteCount + " admin note" + (noteCount > 1 ? "s" : "") + ".";
|
||||||
Placeholder.unparsed("count", String.valueOf(noteCount)), Placeholder.unparsed("plural", noteCount > 1 ? "s" : ""));
|
FLog.info(noteMessage);
|
||||||
plugin.cm.messageAllAdmins("<gold>Do <yellow>/notes <player> list<gold> to view them.",
|
plugin.al.messageAllAdmins(ChatColor.GOLD + noteMessage);
|
||||||
Placeholder.unparsed("player", player.getName()));
|
plugin.al.messageAllAdmins(ChatColor.GOLD + "Do " + ChatColor.YELLOW + "/notes " + player.getName() + " list" + ChatColor.GOLD + " to view them.");
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Admin admin = plugin.al.getAdmin(player);
|
|
||||||
String format = admin.getAcFormat();
|
|
||||||
|
|
||||||
if (!Strings.isNullOrEmpty(format) && FConverter.needsConversion(admin.getAcFormat()))
|
|
||||||
{
|
|
||||||
player.sendMessage(FUtil.miniMessage("<green>Converting your admin chat format..."));
|
|
||||||
admin.setAcFormat(FConverter.convertAdminChatFormat(format));
|
|
||||||
plugin.al.save(admin);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -281,14 +270,14 @@ public class LoginProcess extends FreedomService
|
|||||||
{
|
{
|
||||||
if (ConfigEntry.ADMIN_ONLY_MODE.getBoolean())
|
if (ConfigEntry.ADMIN_ONLY_MODE.getBoolean())
|
||||||
{
|
{
|
||||||
FUtil.playerMsgCooler(player, "<red>Server is currently closed to non-admins.");
|
player.sendMessage(ChatColor.RED + "Server is currently closed to non-admins.");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (lockdownEnabled)
|
if (lockdownEnabled)
|
||||||
{
|
{
|
||||||
FUtil.playerMsgCooler(player, "<red>Warning: Server is currenty in lockdown-mode, new players will not be able to join!");
|
FUtil.playerMsg(player, "Warning: Server is currenty in lockdown-mode, new players will not be able to join!", ChatColor.RED);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}.runTaskLater(plugin, 20L);
|
}.runTaskLater(plugin, 20L);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,6 +1,5 @@
|
|||||||
package me.totalfreedom.totalfreedommod;
|
package me.totalfreedom.totalfreedommod;
|
||||||
|
|
||||||
import io.papermc.paper.event.player.AsyncChatEvent;
|
|
||||||
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
|
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
|
||||||
import me.totalfreedom.totalfreedommod.player.FPlayer;
|
import me.totalfreedom.totalfreedommod.player.FPlayer;
|
||||||
import me.totalfreedom.totalfreedommod.util.FLog;
|
import me.totalfreedom.totalfreedommod.util.FLog;
|
||||||
@ -28,7 +27,7 @@ public class Muter extends FreedomService
|
|||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.HIGHEST)
|
@EventHandler(priority = EventPriority.HIGHEST)
|
||||||
public void onAsyncPlayerChatEvent(AsyncChatEvent event)
|
public void onAsyncPlayerChatEvent(AsyncPlayerChatEvent event)
|
||||||
{
|
{
|
||||||
Player player = event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
|
|
@ -3,7 +3,6 @@ package me.totalfreedom.totalfreedommod;
|
|||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
|
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
|
||||||
import me.totalfreedom.totalfreedommod.util.FUtil;
|
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||||
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.EventPriority;
|
import org.bukkit.event.EventPriority;
|
||||||
@ -33,35 +32,52 @@ public class ServerPing extends FreedomService
|
|||||||
|
|
||||||
if (plugin.bm.isIpBanned(ip))
|
if (plugin.bm.isIpBanned(ip))
|
||||||
{
|
{
|
||||||
event.motd(FUtil.miniMessage(ConfigEntry.SERVER_BAN_MOTD.getString()));
|
event.setMotd(FUtil.colorize(ConfigEntry.SERVER_BAN_MOTD.getString()));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ConfigEntry.ADMIN_ONLY_MODE.getBoolean())
|
if (ConfigEntry.ADMIN_ONLY_MODE.getBoolean())
|
||||||
{
|
{
|
||||||
event.motd(FUtil.miniMessage(ConfigEntry.SERVER_ADMINMODE_MOTD.getString()));
|
event.setMotd(FUtil.colorize(ConfigEntry.SERVER_ADMINMODE_MOTD.getString()));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (LoginProcess.isLockdownEnabled())
|
if (LoginProcess.isLockdownEnabled())
|
||||||
{
|
{
|
||||||
event.motd(FUtil.miniMessage(ConfigEntry.SERVER_LOCKDOWN_MOTD.getString()));
|
event.setMotd(FUtil.colorize(ConfigEntry.SERVER_LOCKDOWN_MOTD.getString()));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Bukkit.hasWhitelist())
|
if (Bukkit.hasWhitelist())
|
||||||
{
|
{
|
||||||
event.motd(FUtil.miniMessage(ConfigEntry.SERVER_WHITELIST_MOTD.getString()));
|
event.setMotd(FUtil.colorize(ConfigEntry.SERVER_WHITELIST_MOTD.getString()));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Bukkit.getOnlinePlayers().size() >= Bukkit.getMaxPlayers())
|
if (Bukkit.getOnlinePlayers().size() >= Bukkit.getMaxPlayers())
|
||||||
{
|
{
|
||||||
event.motd(FUtil.miniMessage(ConfigEntry.SERVER_FULL_MOTD.getString()));
|
event.setMotd(FUtil.colorize(ConfigEntry.SERVER_FULL_MOTD.getString()));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
event.motd(FUtil.miniMessage(ConfigEntry.SERVER_MOTD.getString(), Placeholder.unparsed("version", meta.id)));
|
String baseMotd = ConfigEntry.SERVER_MOTD.getString().replace("%mcversion%", meta.id);
|
||||||
|
baseMotd = baseMotd.replace("\\n", "\n");
|
||||||
|
baseMotd = FUtil.colorize(baseMotd);
|
||||||
|
|
||||||
|
if (!ConfigEntry.SERVER_COLORFUL_MOTD.getBoolean())
|
||||||
|
{
|
||||||
|
event.setMotd(baseMotd);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Colorful MOTD
|
||||||
|
final StringBuilder motd = new StringBuilder();
|
||||||
|
for (String word : baseMotd.split(" "))
|
||||||
|
{
|
||||||
|
motd.append(FUtil.randomChatColor()).append(word).append(" ");
|
||||||
|
}
|
||||||
|
|
||||||
|
event.setMotd(motd.toString().trim());
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class VersionMeta
|
private static class VersionMeta
|
@ -1,23 +1,44 @@
|
|||||||
package me.totalfreedom.totalfreedommod;
|
package me.totalfreedom.totalfreedommod;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.util.Properties;
|
||||||
|
import me.totalfreedom.totalfreedommod.admin.ActivityLog;
|
||||||
import me.totalfreedom.totalfreedommod.admin.AdminList;
|
import me.totalfreedom.totalfreedommod.admin.AdminList;
|
||||||
import me.totalfreedom.totalfreedommod.api.Aggregator;
|
|
||||||
import me.totalfreedom.totalfreedommod.api.ShoppeCommons;
|
|
||||||
import me.totalfreedom.totalfreedommod.api.TFD4JCommons;
|
|
||||||
import me.totalfreedom.totalfreedommod.banning.BanManager;
|
import me.totalfreedom.totalfreedommod.banning.BanManager;
|
||||||
import me.totalfreedom.totalfreedommod.banning.IndefiniteBanList;
|
import me.totalfreedom.totalfreedommod.banning.IndefiniteBanList;
|
||||||
import me.totalfreedom.totalfreedommod.blocking.*;
|
import me.totalfreedom.totalfreedommod.blocking.BlockBlocker;
|
||||||
|
import me.totalfreedom.totalfreedommod.blocking.EditBlocker;
|
||||||
|
import me.totalfreedom.totalfreedommod.blocking.EventBlocker;
|
||||||
|
import me.totalfreedom.totalfreedommod.blocking.InteractBlocker;
|
||||||
|
import me.totalfreedom.totalfreedommod.blocking.MobBlocker;
|
||||||
|
import me.totalfreedom.totalfreedommod.blocking.PVPBlocker;
|
||||||
|
import me.totalfreedom.totalfreedommod.blocking.PotionBlocker;
|
||||||
import me.totalfreedom.totalfreedommod.blocking.command.CommandBlocker;
|
import me.totalfreedom.totalfreedommod.blocking.command.CommandBlocker;
|
||||||
import me.totalfreedom.totalfreedommod.bridge.*;
|
import me.totalfreedom.totalfreedommod.bridge.BukkitTelnetBridge;
|
||||||
|
import me.totalfreedom.totalfreedommod.bridge.CoreProtectBridge;
|
||||||
|
import me.totalfreedom.totalfreedommod.bridge.EssentialsBridge;
|
||||||
|
import me.totalfreedom.totalfreedommod.bridge.LibsDisguisesBridge;
|
||||||
|
import me.totalfreedom.totalfreedommod.bridge.WorldEditBridge;
|
||||||
|
import me.totalfreedom.totalfreedommod.bridge.WorldGuardBridge;
|
||||||
import me.totalfreedom.totalfreedommod.caging.Cager;
|
import me.totalfreedom.totalfreedommod.caging.Cager;
|
||||||
import me.totalfreedom.totalfreedommod.command.CommandLoader;
|
import me.totalfreedom.totalfreedommod.command.CommandLoader;
|
||||||
import me.totalfreedom.totalfreedommod.config.MainConfig;
|
import me.totalfreedom.totalfreedommod.config.MainConfig;
|
||||||
|
import me.totalfreedom.totalfreedommod.discord.Discord;
|
||||||
import me.totalfreedom.totalfreedommod.freeze.Freezer;
|
import me.totalfreedom.totalfreedommod.freeze.Freezer;
|
||||||
import me.totalfreedom.totalfreedommod.fun.*;
|
import me.totalfreedom.totalfreedommod.fun.ItemFun;
|
||||||
|
import me.totalfreedom.totalfreedommod.fun.Jumppads;
|
||||||
|
import me.totalfreedom.totalfreedommod.fun.Landminer;
|
||||||
|
import me.totalfreedom.totalfreedommod.fun.MP44;
|
||||||
|
import me.totalfreedom.totalfreedommod.fun.Trailer;
|
||||||
import me.totalfreedom.totalfreedommod.httpd.HTTPDaemon;
|
import me.totalfreedom.totalfreedommod.httpd.HTTPDaemon;
|
||||||
|
import me.totalfreedom.totalfreedommod.permissions.PermissionConfig;
|
||||||
|
import me.totalfreedom.totalfreedommod.permissions.PermissionManager;
|
||||||
import me.totalfreedom.totalfreedommod.player.PlayerList;
|
import me.totalfreedom.totalfreedommod.player.PlayerList;
|
||||||
import me.totalfreedom.totalfreedommod.punishments.PunishmentList;
|
import me.totalfreedom.totalfreedommod.punishments.PunishmentList;
|
||||||
import me.totalfreedom.totalfreedommod.rank.RankManager;
|
import me.totalfreedom.totalfreedommod.rank.RankManager;
|
||||||
|
import me.totalfreedom.totalfreedommod.shop.Shop;
|
||||||
|
import me.totalfreedom.totalfreedommod.shop.Votifier;
|
||||||
import me.totalfreedom.totalfreedommod.sql.SQLite;
|
import me.totalfreedom.totalfreedommod.sql.SQLite;
|
||||||
import me.totalfreedom.totalfreedommod.util.FLog;
|
import me.totalfreedom.totalfreedommod.util.FLog;
|
||||||
import me.totalfreedom.totalfreedommod.util.FUtil;
|
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||||
@ -32,10 +53,6 @@ import org.bukkit.plugin.Plugin;
|
|||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.util.Properties;
|
|
||||||
|
|
||||||
public class TotalFreedomMod extends JavaPlugin
|
public class TotalFreedomMod extends JavaPlugin
|
||||||
{
|
{
|
||||||
public static final String CONFIG_FILENAME = "config.yml";
|
public static final String CONFIG_FILENAME = "config.yml";
|
||||||
@ -47,6 +64,7 @@ public class TotalFreedomMod extends JavaPlugin
|
|||||||
private static TotalFreedomMod plugin;
|
private static TotalFreedomMod plugin;
|
||||||
//
|
//
|
||||||
public MainConfig config;
|
public MainConfig config;
|
||||||
|
public PermissionConfig permissions;
|
||||||
//
|
//
|
||||||
// Service Handler
|
// Service Handler
|
||||||
public FreedomServiceHandler fsh;
|
public FreedomServiceHandler fsh;
|
||||||
@ -55,6 +73,7 @@ public class TotalFreedomMod extends JavaPlugin
|
|||||||
// Services
|
// Services
|
||||||
public WorldManager wm;
|
public WorldManager wm;
|
||||||
public AdminList al;
|
public AdminList al;
|
||||||
|
public ActivityLog acl;
|
||||||
public RankManager rm;
|
public RankManager rm;
|
||||||
public CommandBlocker cb;
|
public CommandBlocker cb;
|
||||||
public EventBlocker eb;
|
public EventBlocker eb;
|
||||||
@ -66,15 +85,16 @@ public class TotalFreedomMod extends JavaPlugin
|
|||||||
public AntiNuke nu;
|
public AntiNuke nu;
|
||||||
public AntiSpam as;
|
public AntiSpam as;
|
||||||
public PlayerList pl;
|
public PlayerList pl;
|
||||||
public ShoppeCommons sh;
|
public Shop sh;
|
||||||
|
public Votifier vo;
|
||||||
public SQLite sql;
|
public SQLite sql;
|
||||||
public Announcer an;
|
public Announcer an;
|
||||||
public ChatManager cm;
|
public ChatManager cm;
|
||||||
public TFD4JCommons dc;
|
public Discord dc;
|
||||||
public Aggregator ag;
|
|
||||||
public PunishmentList pul;
|
public PunishmentList pul;
|
||||||
public BanManager bm;
|
public BanManager bm;
|
||||||
public IndefiniteBanList im;
|
public IndefiniteBanList im;
|
||||||
|
public PermissionManager pem;
|
||||||
public GameRuleHandler gr;
|
public GameRuleHandler gr;
|
||||||
public CommandSpy cs;
|
public CommandSpy cs;
|
||||||
public Cager ca;
|
public Cager ca;
|
||||||
@ -105,7 +125,7 @@ public class TotalFreedomMod extends JavaPlugin
|
|||||||
public LibsDisguisesBridge ldb;
|
public LibsDisguisesBridge ldb;
|
||||||
public CoreProtectBridge cpb;
|
public CoreProtectBridge cpb;
|
||||||
public WorldEditBridge web;
|
public WorldEditBridge web;
|
||||||
public LuckPermsBridge lpb;
|
public WorldGuardBridge wgb;
|
||||||
|
|
||||||
public static TotalFreedomMod getPlugin()
|
public static TotalFreedomMod getPlugin()
|
||||||
{
|
{
|
||||||
@ -118,7 +138,7 @@ public class TotalFreedomMod extends JavaPlugin
|
|||||||
{
|
{
|
||||||
if (plugin.getName().equalsIgnoreCase(pluginName))
|
if (plugin.getName().equalsIgnoreCase(pluginName))
|
||||||
{
|
{
|
||||||
return (TotalFreedomMod) plugin;
|
return (TotalFreedomMod)plugin;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
@ -166,6 +186,9 @@ public class TotalFreedomMod extends JavaPlugin
|
|||||||
BackupManager backups = new BackupManager();
|
BackupManager backups = new BackupManager();
|
||||||
backups.createAllBackups();
|
backups.createAllBackups();
|
||||||
|
|
||||||
|
permissions = new PermissionConfig();
|
||||||
|
permissions.load();
|
||||||
|
|
||||||
mv = new MovementValidator();
|
mv = new MovementValidator();
|
||||||
sp = new ServerPing();
|
sp = new ServerPing();
|
||||||
|
|
||||||
@ -199,22 +222,6 @@ public class TotalFreedomMod extends JavaPlugin
|
|||||||
return new CleanroomChunkGenerator(id);
|
return new CleanroomChunkGenerator(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void registerDiscord()
|
|
||||||
{
|
|
||||||
if (Bukkit.getPluginManager().isPluginEnabled("TFD4J"))
|
|
||||||
{
|
|
||||||
dc = ag.getDiscordContext().getValue();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void registerShoppe()
|
|
||||||
{
|
|
||||||
if (Bukkit.getPluginManager().isPluginEnabled("TF-Shoppe"))
|
|
||||||
{
|
|
||||||
sh = ag.getShoppeContext().getValue();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class BuildProperties
|
public static class BuildProperties
|
||||||
{
|
{
|
||||||
public String author;
|
public String author;
|
||||||
@ -229,7 +236,6 @@ public class TotalFreedomMod extends JavaPlugin
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
final Properties props;
|
final Properties props;
|
||||||
final String unknown = "unknown";
|
|
||||||
|
|
||||||
try (InputStream in = plugin.getResource("build.properties"))
|
try (InputStream in = plugin.getResource("build.properties"))
|
||||||
{
|
{
|
||||||
@ -237,13 +243,15 @@ public class TotalFreedomMod extends JavaPlugin
|
|||||||
props.load(in);
|
props.load(in);
|
||||||
}
|
}
|
||||||
|
|
||||||
author = props.getProperty("buildAuthor", unknown);
|
author = props.getProperty("buildAuthor", "unknown");
|
||||||
codename = props.getProperty("buildCodeName", unknown);
|
codename = props.getProperty("buildCodeName", "unknown");
|
||||||
version = props.getProperty("buildVersion", pluginVersion);
|
version = props.getProperty("buildVersion", pluginVersion);
|
||||||
number = props.getProperty("buildNumber", "1");
|
number = props.getProperty("buildNumber", "1");
|
||||||
date = props.getProperty("buildDate", unknown);
|
date = props.getProperty("buildDate", "unknown");
|
||||||
head = props.getProperty("buildHead", unknown).replace("${git.commit.id.abbrev}", unknown);
|
// Need to do this or it will display ${git.commit.id.abbrev}
|
||||||
} catch (Exception ex)
|
head = props.getProperty("buildHead", "unknown").replace("${git.commit.id.abbrev}", "unknown");
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
FLog.severe("Could not load build properties! Did you compile with NetBeans/Maven?");
|
FLog.severe("Could not load build properties! Did you compile with NetBeans/Maven?");
|
||||||
FLog.severe(ex);
|
FLog.severe(ex);
|
||||||
@ -276,6 +284,7 @@ public class TotalFreedomMod extends JavaPlugin
|
|||||||
wm = new WorldManager();
|
wm = new WorldManager();
|
||||||
sql = new SQLite();
|
sql = new SQLite();
|
||||||
al = new AdminList();
|
al = new AdminList();
|
||||||
|
acl = new ActivityLog();
|
||||||
rm = new RankManager();
|
rm = new RankManager();
|
||||||
cb = new CommandBlocker();
|
cb = new CommandBlocker();
|
||||||
eb = new EventBlocker();
|
eb = new EventBlocker();
|
||||||
@ -288,15 +297,15 @@ public class TotalFreedomMod extends JavaPlugin
|
|||||||
as = new AntiSpam();
|
as = new AntiSpam();
|
||||||
wr = new WorldRestrictions();
|
wr = new WorldRestrictions();
|
||||||
pl = new PlayerList();
|
pl = new PlayerList();
|
||||||
ag = new Aggregator();
|
sh = new Shop();
|
||||||
|
vo = new Votifier();
|
||||||
an = new Announcer();
|
an = new Announcer();
|
||||||
cm = new ChatManager();
|
cm = new ChatManager();
|
||||||
|
dc = new Discord();
|
||||||
|
|
||||||
pul = new PunishmentList();
|
pul = new PunishmentList();
|
||||||
bm = new BanManager();
|
bm = new BanManager();
|
||||||
im = new IndefiniteBanList();
|
im = new IndefiniteBanList();
|
||||||
|
pem = new PermissionManager();
|
||||||
gr = new GameRuleHandler();
|
gr = new GameRuleHandler();
|
||||||
ew = new EntityWiper();
|
ew = new EntityWiper();
|
||||||
vh = new VanishHandler();
|
vh = new VanishHandler();
|
||||||
@ -326,7 +335,7 @@ public class TotalFreedomMod extends JavaPlugin
|
|||||||
esb = new EssentialsBridge();
|
esb = new EssentialsBridge();
|
||||||
ldb = new LibsDisguisesBridge();
|
ldb = new LibsDisguisesBridge();
|
||||||
web = new WorldEditBridge();
|
web = new WorldEditBridge();
|
||||||
lpb = new LuckPermsBridge();
|
wgb = new WorldGuardBridge();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initFun()
|
private void initFun()
|
@ -1,7 +1,11 @@
|
|||||||
package me.totalfreedom.totalfreedommod;
|
package me.totalfreedom.totalfreedommod;
|
||||||
|
|
||||||
import me.totalfreedom.totalfreedommod.util.FUtil;
|
import me.totalfreedom.totalfreedommod.util.FLog;
|
||||||
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
import net.kyori.adventure.text.Component;
|
||||||
|
import net.kyori.adventure.text.format.NamedTextColor;
|
||||||
|
import net.md_5.bungee.api.ChatMessageType;
|
||||||
|
import net.md_5.bungee.api.chat.TextComponent;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.EventPriority;
|
import org.bukkit.event.EventPriority;
|
||||||
@ -35,7 +39,8 @@ public class VanishHandler extends FreedomService
|
|||||||
if (plugin.al.isVanished(player.getUniqueId()))
|
if (plugin.al.isVanished(player.getUniqueId()))
|
||||||
{
|
{
|
||||||
plugin.esb.setVanished(player.getName(), true);
|
plugin.esb.setVanished(player.getName(), true);
|
||||||
plugin.cm.messageAllAdmins("<yellow><player> has joined silently.", Placeholder.unparsed("player", player.getName()));
|
FLog.info(player.getName() + " joined while still vanished.");
|
||||||
|
plugin.al.messageAllAdmins(ChatColor.YELLOW + player.getName() + " has joined silently.");
|
||||||
event.joinMessage(null);
|
event.joinMessage(null);
|
||||||
|
|
||||||
new BukkitRunnable()
|
new BukkitRunnable()
|
||||||
@ -45,7 +50,7 @@ public class VanishHandler extends FreedomService
|
|||||||
{
|
{
|
||||||
if (plugin.al.isVanished(player.getUniqueId()))
|
if (plugin.al.isVanished(player.getUniqueId()))
|
||||||
{
|
{
|
||||||
player.sendActionBar(FUtil.miniMessage("<gold>You are hidden from other players."));
|
player.sendActionBar(Component.text("You are hidden from other players.").color(NamedTextColor.GOLD));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -64,7 +69,8 @@ public class VanishHandler extends FreedomService
|
|||||||
if (plugin.al.isVanished(player.getUniqueId()))
|
if (plugin.al.isVanished(player.getUniqueId()))
|
||||||
{
|
{
|
||||||
event.quitMessage(null);
|
event.quitMessage(null);
|
||||||
plugin.cm.messageAllAdmins("<yellow><player> has left silently.", Placeholder.unparsed("player", player.getName()));
|
FLog.info(player.getName() + " left while still vanished.");
|
||||||
|
plugin.al.messageAllAdmins(ChatColor.YELLOW + player.getName() + " has left silently.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -0,0 +1,212 @@
|
|||||||
|
package me.totalfreedom.totalfreedommod.admin;
|
||||||
|
|
||||||
|
import com.google.common.collect.Maps;
|
||||||
|
import java.util.Map;
|
||||||
|
import me.totalfreedom.totalfreedommod.FreedomService;
|
||||||
|
import me.totalfreedom.totalfreedommod.config.YamlConfig;
|
||||||
|
import me.totalfreedom.totalfreedommod.util.FLog;
|
||||||
|
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
|
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;
|
||||||
|
|
||||||
|
public class ActivityLog extends FreedomService
|
||||||
|
{
|
||||||
|
|
||||||
|
public static final String FILENAME = "activitylog.yml";
|
||||||
|
|
||||||
|
private final Map<String, ActivityLogEntry> allActivityLogs = Maps.newHashMap();
|
||||||
|
private final Map<String, ActivityLogEntry> nameTable = Maps.newHashMap();
|
||||||
|
private final Map<String, ActivityLogEntry> ipTable = Maps.newHashMap();
|
||||||
|
|
||||||
|
private final YamlConfig config;
|
||||||
|
|
||||||
|
public ActivityLog()
|
||||||
|
{
|
||||||
|
this.config = new YamlConfig(plugin, FILENAME, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getFILENAME()
|
||||||
|
{
|
||||||
|
return FILENAME;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onStart()
|
||||||
|
{
|
||||||
|
load();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onStop()
|
||||||
|
{
|
||||||
|
save();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void load()
|
||||||
|
{
|
||||||
|
config.load();
|
||||||
|
|
||||||
|
allActivityLogs.clear();
|
||||||
|
nameTable.clear();
|
||||||
|
ipTable.clear();
|
||||||
|
for (String key : config.getKeys(false))
|
||||||
|
{
|
||||||
|
ConfigurationSection section = config.getConfigurationSection(key);
|
||||||
|
if (section == null)
|
||||||
|
{
|
||||||
|
FLog.warning("Invalid activity log format: " + key);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
ActivityLogEntry activityLogEntry = new ActivityLogEntry(key);
|
||||||
|
activityLogEntry.loadFrom(section);
|
||||||
|
|
||||||
|
if (!activityLogEntry.isValid())
|
||||||
|
{
|
||||||
|
FLog.warning("Could not load activity log: " + key + ". Missing details!");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
allActivityLogs.put(key, activityLogEntry);
|
||||||
|
}
|
||||||
|
|
||||||
|
updateTables();
|
||||||
|
FLog.info("Loaded " + allActivityLogs.size() + " activity logs");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void save()
|
||||||
|
{
|
||||||
|
// Clear the config
|
||||||
|
for (String key : config.getKeys(false))
|
||||||
|
{
|
||||||
|
config.set(key, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (ActivityLogEntry activityLog : allActivityLogs.values())
|
||||||
|
{
|
||||||
|
activityLog.saveTo(config.createSection(activityLog.getConfigKey()));
|
||||||
|
}
|
||||||
|
|
||||||
|
config.save();
|
||||||
|
}
|
||||||
|
|
||||||
|
public ActivityLogEntry getActivityLog(CommandSender sender)
|
||||||
|
{
|
||||||
|
if (sender instanceof Player)
|
||||||
|
{
|
||||||
|
return getActivityLog((Player)sender);
|
||||||
|
}
|
||||||
|
|
||||||
|
return getEntryByName(sender.getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
public ActivityLogEntry getActivityLog(Player player)
|
||||||
|
{
|
||||||
|
ActivityLogEntry activityLog = getEntryByName(player.getName());
|
||||||
|
if (activityLog == null)
|
||||||
|
{
|
||||||
|
String ip = FUtil.getIp(player);
|
||||||
|
activityLog = getEntryByIp(ip);
|
||||||
|
if (activityLog != null)
|
||||||
|
{
|
||||||
|
// Set the new username
|
||||||
|
activityLog.setName(player.getName());
|
||||||
|
save();
|
||||||
|
updateTables();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
activityLog = new ActivityLogEntry(player);
|
||||||
|
allActivityLogs.put(activityLog.getConfigKey(), activityLog);
|
||||||
|
updateTables();
|
||||||
|
|
||||||
|
activityLog.saveTo(config.createSection(activityLog.getConfigKey()));
|
||||||
|
config.save();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
String ip = FUtil.getIp(player);
|
||||||
|
if (!activityLog.getIps().contains(ip))
|
||||||
|
{
|
||||||
|
activityLog.addIp(ip);
|
||||||
|
save();
|
||||||
|
updateTables();
|
||||||
|
}
|
||||||
|
return activityLog;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ActivityLogEntry getEntryByName(String name)
|
||||||
|
{
|
||||||
|
return nameTable.get(name.toLowerCase());
|
||||||
|
}
|
||||||
|
|
||||||
|
public ActivityLogEntry getEntryByIp(String ip)
|
||||||
|
{
|
||||||
|
return ipTable.get(ip);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void updateTables()
|
||||||
|
{
|
||||||
|
nameTable.clear();
|
||||||
|
ipTable.clear();
|
||||||
|
|
||||||
|
for (ActivityLogEntry activityLog : allActivityLogs.values())
|
||||||
|
{
|
||||||
|
nameTable.put(activityLog.getName().toLowerCase(), activityLog);
|
||||||
|
|
||||||
|
for (String ip : activityLog.getIps())
|
||||||
|
{
|
||||||
|
ipTable.put(ip, activityLog);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.HIGH)
|
||||||
|
public void onPlayerJoin(PlayerJoinEvent event)
|
||||||
|
{
|
||||||
|
Player player = event.getPlayer();
|
||||||
|
if (plugin.al.isAdmin(player))
|
||||||
|
{
|
||||||
|
getActivityLog(event.getPlayer()).addLogin();
|
||||||
|
plugin.acl.save();
|
||||||
|
plugin.acl.updateTables();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.HIGH)
|
||||||
|
public void onPlayerQuit(PlayerQuitEvent event)
|
||||||
|
{
|
||||||
|
Player player = event.getPlayer();
|
||||||
|
if (plugin.al.isAdmin(player))
|
||||||
|
{
|
||||||
|
getActivityLog(event.getPlayer()).addLogout();
|
||||||
|
plugin.acl.save();
|
||||||
|
plugin.acl.updateTables();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Map<String, ActivityLogEntry> getAllActivityLogs()
|
||||||
|
{
|
||||||
|
return allActivityLogs;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Map<String, ActivityLogEntry> getNameTable()
|
||||||
|
{
|
||||||
|
return nameTable;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Map<String, ActivityLogEntry> getIpTable()
|
||||||
|
{
|
||||||
|
return ipTable;
|
||||||
|
}
|
||||||
|
|
||||||
|
public YamlConfig getConfig()
|
||||||
|
{
|
||||||
|
return config;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,176 @@
|
|||||||
|
package me.totalfreedom.totalfreedommod.admin;
|
||||||
|
|
||||||
|
import com.google.common.collect.Lists;
|
||||||
|
import java.time.Instant;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
import me.totalfreedom.totalfreedommod.config.IConfig;
|
||||||
|
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||||
|
import org.apache.commons.lang.Validate;
|
||||||
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
public class ActivityLogEntry implements IConfig
|
||||||
|
{
|
||||||
|
|
||||||
|
public static final String FILENAME = "activitylog.yml";
|
||||||
|
private final List<String> ips = Lists.newArrayList();
|
||||||
|
private final List<String> timestamps = Lists.newArrayList();
|
||||||
|
private final List<String> durations = Lists.newArrayList();
|
||||||
|
private String configKey;
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
public ActivityLogEntry(Player player)
|
||||||
|
{
|
||||||
|
this.configKey = player.getName().toLowerCase();
|
||||||
|
this.name = player.getName();
|
||||||
|
}
|
||||||
|
|
||||||
|
public ActivityLogEntry(String configKey)
|
||||||
|
{
|
||||||
|
this.configKey = configKey;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getFILENAME()
|
||||||
|
{
|
||||||
|
return FILENAME;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void loadFrom(Player player)
|
||||||
|
{
|
||||||
|
configKey = player.getName().toLowerCase();
|
||||||
|
name = player.getName();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void loadFrom(ConfigurationSection cs)
|
||||||
|
{
|
||||||
|
name = cs.getString("username", configKey);
|
||||||
|
ips.clear();
|
||||||
|
ips.addAll(cs.getStringList("ips"));
|
||||||
|
timestamps.clear();
|
||||||
|
timestamps.addAll(cs.getStringList("timestamps"));
|
||||||
|
durations.clear();
|
||||||
|
durations.addAll(cs.getStringList("durations"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void saveTo(ConfigurationSection cs)
|
||||||
|
{
|
||||||
|
Validate.isTrue(isValid(), "Could not save activity entry: " + name + ". Entry not valid!");
|
||||||
|
cs.set("username", name);
|
||||||
|
cs.set("ips", Lists.newArrayList(ips));
|
||||||
|
cs.set("timestamps", Lists.newArrayList(timestamps));
|
||||||
|
cs.set("durations", Lists.newArrayList(durations));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addLogin()
|
||||||
|
{
|
||||||
|
Date currentTime = Date.from(Instant.now());
|
||||||
|
timestamps.add("Login: " + FUtil.dateToString(currentTime));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addLogout()
|
||||||
|
{
|
||||||
|
// Fix of Array index out of bonds issue: FS-131
|
||||||
|
String lastLoginString;
|
||||||
|
if(timestamps.size() > 1)
|
||||||
|
{
|
||||||
|
lastLoginString = timestamps.get(timestamps.size() - 1);
|
||||||
|
}else
|
||||||
|
{
|
||||||
|
lastLoginString = timestamps.get(0);
|
||||||
|
}
|
||||||
|
Date currentTime = Date.from(Instant.now());
|
||||||
|
timestamps.add("Logout: " + FUtil.dateToString(currentTime));
|
||||||
|
lastLoginString = lastLoginString.replace("Login: ", "");
|
||||||
|
Date lastLogin = FUtil.stringToDate(lastLoginString);
|
||||||
|
|
||||||
|
long duration = currentTime.getTime() - lastLogin.getTime();
|
||||||
|
long seconds = duration / 1000 % 60;
|
||||||
|
long minutes = duration / (60 * 1000) % 60;
|
||||||
|
long hours = duration / (60 * 60 * 1000);
|
||||||
|
durations.add(hours + " hours, " + minutes + " minutes, and " + seconds + " seconds");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addIp(String ip)
|
||||||
|
{
|
||||||
|
if (!ips.contains(ip))
|
||||||
|
{
|
||||||
|
ips.add(ip);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addIps(List<String> ips)
|
||||||
|
{
|
||||||
|
for (String ip : ips)
|
||||||
|
{
|
||||||
|
addIp(ip);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void removeIp(String ip)
|
||||||
|
{
|
||||||
|
ips.remove(ip);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void clearIPs()
|
||||||
|
{
|
||||||
|
ips.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getTotalSecondsPlayed()
|
||||||
|
{
|
||||||
|
int result = 0;
|
||||||
|
for (String duration : durations)
|
||||||
|
{
|
||||||
|
String[] spl = duration.split(" ");
|
||||||
|
result += Integer.parseInt(spl[0]) * 60 * 60;
|
||||||
|
result += Integer.parseInt(spl[2]) * 60;
|
||||||
|
result += Integer.parseInt(spl[5]);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isValid()
|
||||||
|
{
|
||||||
|
return configKey != null
|
||||||
|
&& name != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getConfigKey()
|
||||||
|
{
|
||||||
|
return configKey;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setConfigKey(String configKey)
|
||||||
|
{
|
||||||
|
this.configKey = configKey;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName()
|
||||||
|
{
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setName(String name)
|
||||||
|
{
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<String> getIps()
|
||||||
|
{
|
||||||
|
return ips;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<String> getTimestamps()
|
||||||
|
{
|
||||||
|
return timestamps;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<String> getDurations()
|
||||||
|
{
|
||||||
|
return durations;
|
||||||
|
}
|
||||||
|
}
|
@ -1,9 +1,12 @@
|
|||||||
package me.totalfreedom.totalfreedommod.admin;
|
package me.totalfreedom.totalfreedommod.admin;
|
||||||
|
|
||||||
|
import java.sql.ResultSet;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
import me.totalfreedom.totalfreedommod.TotalFreedomMod;
|
import me.totalfreedom.totalfreedommod.TotalFreedomMod;
|
||||||
import me.totalfreedom.totalfreedommod.player.FPlayer;
|
import me.totalfreedom.totalfreedommod.player.FPlayer;
|
||||||
import me.totalfreedom.totalfreedommod.rank.DisplayableGroup;
|
import me.totalfreedom.totalfreedommod.rank.Rank;
|
||||||
import me.totalfreedom.totalfreedommod.rank.GroupProvider;
|
|
||||||
import me.totalfreedom.totalfreedommod.util.FLog;
|
import me.totalfreedom.totalfreedommod.util.FLog;
|
||||||
import me.totalfreedom.totalfreedommod.util.FUtil;
|
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
@ -11,16 +14,12 @@ import org.bukkit.Bukkit;
|
|||||||
import org.bukkit.Server;
|
import org.bukkit.Server;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import java.sql.ResultSet;
|
|
||||||
import java.sql.SQLException;
|
|
||||||
import java.util.*;
|
|
||||||
|
|
||||||
public class Admin
|
public class Admin
|
||||||
{
|
{
|
||||||
private final List<String> ips = new ArrayList<>();
|
private final List<String> ips = new ArrayList<>();
|
||||||
private UUID uuid;
|
private UUID uuid;
|
||||||
private boolean active = true;
|
private boolean active = true;
|
||||||
private DisplayableGroup rank = GroupProvider.ADMIN.getGroup();
|
private Rank rank = Rank.ADMIN;
|
||||||
private Date lastLogin = new Date();
|
private Date lastLogin = new Date();
|
||||||
private Boolean commandSpy = false;
|
private Boolean commandSpy = false;
|
||||||
private Boolean potionSpy = false;
|
private Boolean potionSpy = false;
|
||||||
@ -38,14 +37,15 @@ public class Admin
|
|||||||
{
|
{
|
||||||
this.uuid = UUID.fromString(resultSet.getString("uuid"));
|
this.uuid = UUID.fromString(resultSet.getString("uuid"));
|
||||||
this.active = resultSet.getBoolean("active");
|
this.active = resultSet.getBoolean("active");
|
||||||
this.rank = GroupProvider.fromArgument(resultSet.getString("rank")).getGroup();
|
this.rank = Rank.findRank(resultSet.getString("rank"));
|
||||||
this.ips.clear();
|
this.ips.clear();
|
||||||
this.ips.addAll(FUtil.stringToList(resultSet.getString("ips")));
|
this.ips.addAll(FUtil.stringToList(resultSet.getString("ips")));
|
||||||
this.lastLogin = new Date(resultSet.getLong("last_login"));
|
this.lastLogin = new Date(resultSet.getLong("last_login"));
|
||||||
this.commandSpy = resultSet.getBoolean("command_spy");
|
this.commandSpy = resultSet.getBoolean("command_spy");
|
||||||
this.potionSpy = resultSet.getBoolean("potion_spy");
|
this.potionSpy = resultSet.getBoolean("potion_spy");
|
||||||
this.acFormat = resultSet.getString("ac_format");
|
this.acFormat = resultSet.getString("ac_format");
|
||||||
} catch (SQLException e)
|
}
|
||||||
|
catch (SQLException e)
|
||||||
{
|
{
|
||||||
FLog.severe("Failed to load admin: " + e.getMessage());
|
FLog.severe("Failed to load admin: " + e.getMessage());
|
||||||
}
|
}
|
||||||
@ -69,17 +69,18 @@ public class Admin
|
|||||||
|
|
||||||
public Map<String, Object> toSQLStorable()
|
public Map<String, Object> toSQLStorable()
|
||||||
{
|
{
|
||||||
HashMap<String, Object> map = new HashMap<>();
|
Map<String, Object> map = new HashMap<String, Object>()
|
||||||
map.put("uuid", uuid.toString());
|
{{
|
||||||
map.put("active", active);
|
put("uuid", uuid.toString());
|
||||||
map.put("rank", rank.toString());
|
put("active", active);
|
||||||
map.put("ips", FUtil.listToString(ips));
|
put("rank", rank.toString());
|
||||||
map.put("last_login", lastLogin.getTime());
|
put("ips", FUtil.listToString(ips));
|
||||||
map.put("command_spy", commandSpy);
|
put("last_login", lastLogin.getTime());
|
||||||
map.put("potion_spy", potionSpy);
|
put("command_spy", commandSpy);
|
||||||
map.put("ac_format", acFormat);
|
put("potion_spy", potionSpy);
|
||||||
return map;
|
put("ac_format", acFormat);
|
||||||
|
}};
|
||||||
|
return map;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Util IP methods
|
// Util IP methods
|
||||||
@ -147,55 +148,50 @@ public class Admin
|
|||||||
|
|
||||||
if (!active)
|
if (!active)
|
||||||
{
|
{
|
||||||
setActiveSplitWorkToReduceComplexity(plugin);
|
if (getRank().isAtLeast(Rank.ADMIN))
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void setActiveSplitWorkToReduceComplexity(TotalFreedomMod plugin)
|
|
||||||
{
|
|
||||||
if (getRank().isAtLeast(GroupProvider.ADMIN.getGroup()))
|
|
||||||
{
|
|
||||||
if (plugin.btb != null)
|
|
||||||
{
|
{
|
||||||
plugin.btb.killTelnetSessions(getName());
|
if (plugin.btb != null)
|
||||||
}
|
|
||||||
|
|
||||||
// Ensure admins don't have admin functionality when removed (FS-222)
|
|
||||||
AdminList.vanished.remove(getUuid());
|
|
||||||
|
|
||||||
if (plugin.esb != null)
|
|
||||||
{
|
|
||||||
plugin.esb.setVanished(getName(), false);
|
|
||||||
}
|
|
||||||
|
|
||||||
setCommandSpy(false);
|
|
||||||
setPotionSpy(false);
|
|
||||||
|
|
||||||
Server server = Bukkit.getServer();
|
|
||||||
Player player = server.getPlayer(getUuid());
|
|
||||||
|
|
||||||
if (player != null)
|
|
||||||
{
|
|
||||||
// Update chats
|
|
||||||
FPlayer freedomPlayer = plugin.pl.getPlayer(player);
|
|
||||||
freedomPlayer.removeAdminFunctionality();
|
|
||||||
|
|
||||||
// Disable vanish
|
|
||||||
for (Player player1 : server.getOnlinePlayers())
|
|
||||||
{
|
{
|
||||||
player1.showPlayer(plugin, player);
|
plugin.btb.killTelnetSessions(getName());
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
// Ensure admins don't have admin functionality when removed (FS-222)
|
||||||
|
AdminList.vanished.remove(getName());
|
||||||
|
|
||||||
|
if (plugin.esb != null)
|
||||||
|
{
|
||||||
|
plugin.esb.setVanished(getName(), false);
|
||||||
|
}
|
||||||
|
|
||||||
|
setCommandSpy(false);
|
||||||
|
setPotionSpy(false);
|
||||||
|
|
||||||
|
Server server = Bukkit.getServer();
|
||||||
|
Player player = server.getPlayer(getUuid());
|
||||||
|
|
||||||
|
if (player != null)
|
||||||
|
{
|
||||||
|
// Update chats
|
||||||
|
FPlayer freedomPlayer = plugin.pl.getPlayer(player);
|
||||||
|
freedomPlayer.removeAdminFunctionality();
|
||||||
|
|
||||||
|
// Disable vanish
|
||||||
|
for (Player player1 : server.getOnlinePlayers())
|
||||||
|
{
|
||||||
|
player1.showPlayer(plugin, player);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public DisplayableGroup getRank()
|
public Rank getRank()
|
||||||
{
|
{
|
||||||
return rank;
|
return rank;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setRank(DisplayableGroup rank)
|
public void setRank(Rank rank)
|
||||||
{
|
{
|
||||||
this.rank = rank;
|
this.rank = rank;
|
||||||
}
|
}
|
@ -2,20 +2,18 @@ package me.totalfreedom.totalfreedommod.admin;
|
|||||||
|
|
||||||
import com.google.common.collect.Maps;
|
import com.google.common.collect.Maps;
|
||||||
import com.google.common.collect.Sets;
|
import com.google.common.collect.Sets;
|
||||||
import me.totalfreedom.totalfreedommod.FreedomService;
|
|
||||||
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
|
|
||||||
import me.totalfreedom.totalfreedommod.rank.GroupProvider;
|
|
||||||
import me.totalfreedom.totalfreedommod.util.FLog;
|
|
||||||
import me.totalfreedom.totalfreedommod.util.FUtil;
|
|
||||||
import net.kyori.adventure.text.Component;
|
|
||||||
import org.bukkit.OfflinePlayer;
|
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
import me.totalfreedom.totalfreedommod.FreedomService;
|
||||||
|
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
|
||||||
|
import me.totalfreedom.totalfreedommod.rank.Rank;
|
||||||
|
import me.totalfreedom.totalfreedommod.util.FLog;
|
||||||
|
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
public class AdminList extends FreedomService
|
public class AdminList extends FreedomService
|
||||||
{
|
{
|
||||||
@ -37,7 +35,6 @@ public class AdminList extends FreedomService
|
|||||||
@Override
|
@Override
|
||||||
public void onStop()
|
public void onStop()
|
||||||
{
|
{
|
||||||
// This does nothing. This comment is here to prevent SonarLint from complaining.
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void load()
|
public void load()
|
||||||
@ -48,9 +45,19 @@ public class AdminList extends FreedomService
|
|||||||
ResultSet adminSet = plugin.sql.getAdminList();
|
ResultSet adminSet = plugin.sql.getAdminList();
|
||||||
while (adminSet.next())
|
while (adminSet.next())
|
||||||
{
|
{
|
||||||
tryAddAdmin(adminSet);
|
try
|
||||||
|
{
|
||||||
|
Admin admin = new Admin(adminSet);
|
||||||
|
allAdmins.add(admin);
|
||||||
|
}
|
||||||
|
catch (Throwable ex)
|
||||||
|
{
|
||||||
|
FLog.warning("An error occurred whilst reading the admin entry at row #" + adminSet.getRow());
|
||||||
|
FLog.warning(ex);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (SQLException e)
|
}
|
||||||
|
catch (SQLException e)
|
||||||
{
|
{
|
||||||
FLog.severe("Failed to load admin list: " + e.getMessage());
|
FLog.severe("Failed to load admin list: " + e.getMessage());
|
||||||
}
|
}
|
||||||
@ -59,24 +66,17 @@ public class AdminList extends FreedomService
|
|||||||
FLog.info("Loaded " + allAdmins.size() + " admins (" + uuidTable.size() + " active, " + ipTable.size() + " IPs)");
|
FLog.info("Loaded " + allAdmins.size() + " admins (" + uuidTable.size() + " active, " + ipTable.size() + " IPs)");
|
||||||
}
|
}
|
||||||
|
|
||||||
private void tryAddAdmin(ResultSet adminSet) throws SQLException
|
public void messageAllAdmins(String message)
|
||||||
{
|
{
|
||||||
try
|
for (Player player : server.getOnlinePlayers())
|
||||||
{
|
{
|
||||||
Admin admin = new Admin(adminSet);
|
if (isAdmin(player))
|
||||||
allAdmins.add(admin);
|
{
|
||||||
} catch (Throwable ex)
|
player.sendMessage(message);
|
||||||
{
|
}
|
||||||
FLog.warning("An error occurred whilst reading the admin entry at row #" + adminSet.getRow());
|
|
||||||
FLog.warning(ex);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void messageAllAdmins(Component message)
|
|
||||||
{
|
|
||||||
server.getOnlinePlayers().stream().filter(this::isAdmin).forEach(player -> player.sendMessage(message));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void potionSpyMessage(String message)
|
public void potionSpyMessage(String message)
|
||||||
{
|
{
|
||||||
for (Player player : server.getOnlinePlayers())
|
for (Player player : server.getOnlinePlayers())
|
||||||
@ -101,18 +101,12 @@ public class AdminList extends FreedomService
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
Admin admin = getAdmin((Player) sender);
|
Admin admin = getAdmin((Player)sender);
|
||||||
|
|
||||||
return admin != null && admin.isActive();
|
return admin != null && admin.isActive();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Cast to OfflinePlayer
|
|
||||||
public boolean isAdmin(Player player)
|
public boolean isAdmin(Player player)
|
||||||
{
|
|
||||||
return isAdmin((OfflinePlayer) player);
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isAdmin(OfflinePlayer player)
|
|
||||||
{
|
{
|
||||||
if (player == null)
|
if (player == null)
|
||||||
{
|
{
|
||||||
@ -132,24 +126,30 @@ public class AdminList extends FreedomService
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return admin.getRank().getLuckPermsGroup().getWeight().orElse(0)
|
return admin.getRank().ordinal() >= Rank.SENIOR_ADMIN.ordinal();
|
||||||
>= GroupProvider.SENIOR_ADMIN.getGroup().getLuckPermsGroup().getWeight().orElse(1);
|
|
||||||
// We don't want this to return true if there's no group weight available.
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Admin getAdmin(CommandSender sender)
|
public Admin getAdmin(CommandSender sender)
|
||||||
{
|
{
|
||||||
if (sender instanceof Player player)
|
if (sender instanceof Player)
|
||||||
{
|
{
|
||||||
return getAdmin(player);
|
return getAdmin((Player)sender);
|
||||||
}
|
}
|
||||||
|
|
||||||
return getEntryByName(sender.getName());
|
return getEntryByName(sender.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
public Admin getAdmin(OfflinePlayer player)
|
public Admin getAdmin(Player player)
|
||||||
{
|
{
|
||||||
return getEntryByUuid(player.getUniqueId());
|
final String ip = FUtil.getIp(player);
|
||||||
|
final Admin entry = getEntryByUuid(player.getUniqueId());
|
||||||
|
|
||||||
|
if (entry != null && !entry.getIps().contains(ip))
|
||||||
|
{
|
||||||
|
entry.addIp(ip);
|
||||||
|
}
|
||||||
|
|
||||||
|
return entry;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Admin getEntryByUuid(UUID uuid)
|
public Admin getEntryByUuid(UUID uuid)
|
||||||
@ -167,12 +167,6 @@ public class AdminList extends FreedomService
|
|||||||
return ipTable.get(ip);
|
return ipTable.get(ip);
|
||||||
}
|
}
|
||||||
|
|
||||||
// To cast against OfflinePlayer
|
|
||||||
public Admin getAdmin(Player player)
|
|
||||||
{
|
|
||||||
return getAdmin((OfflinePlayer) player);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void updateLastLogin(Player player)
|
public void updateLastLogin(Player player)
|
||||||
{
|
{
|
||||||
final Admin admin = getAdmin(player);
|
final Admin admin = getAdmin(player);
|
||||||
@ -185,12 +179,12 @@ public class AdminList extends FreedomService
|
|||||||
save(admin);
|
save(admin);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addAdmin(Admin admin)
|
public boolean addAdmin(Admin admin)
|
||||||
{
|
{
|
||||||
if (!admin.isValid())
|
if (!admin.isValid())
|
||||||
{
|
{
|
||||||
FLog.warning("Could not add admin: " + admin.getName() + ". Admin is missing details!");
|
FLog.warning("Could not add admin: " + admin.getName() + ". Admin is missing details!");
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Store admin, update views
|
// Store admin, update views
|
||||||
@ -199,13 +193,18 @@ public class AdminList extends FreedomService
|
|||||||
|
|
||||||
// Save admin
|
// Save admin
|
||||||
plugin.sql.addAdmin(admin);
|
plugin.sql.addAdmin(admin);
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean removeAdmin(Admin admin)
|
public boolean removeAdmin(Admin admin)
|
||||||
{
|
{
|
||||||
if (admin.getRank().isAtLeast(GroupProvider.ADMIN.getGroup()) && (plugin.btb != null))
|
if (admin.getRank().isAtLeast(Rank.ADMIN))
|
||||||
{
|
{
|
||||||
plugin.btb.killTelnetSessions(admin.getName());
|
if (plugin.btb != null)
|
||||||
|
{
|
||||||
|
plugin.btb.killTelnetSessions(admin.getName());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove admin, update views
|
// Remove admin, update views
|
||||||
@ -266,13 +265,13 @@ public class AdminList extends FreedomService
|
|||||||
ResultSet currentSave = plugin.sql.getAdminByUuid(admin.getUuid());
|
ResultSet currentSave = plugin.sql.getAdminByUuid(admin.getUuid());
|
||||||
for (Map.Entry<String, Object> entry : admin.toSQLStorable().entrySet())
|
for (Map.Entry<String, Object> entry : admin.toSQLStorable().entrySet())
|
||||||
{
|
{
|
||||||
Object storedValue = plugin.sql.getValue(currentSave, entry.getKey(), entry.getValue());
|
Object storedValue = plugin.sql.getValue(currentSave, entry.getKey(), entry.getValue()); if (storedValue != null && !storedValue.equals(entry.getValue()) || storedValue == null && entry.getValue() != null || entry.getValue() == null)
|
||||||
if (storedValue != null && !storedValue.equals(entry.getValue()) || storedValue == null && entry.getValue() != null || entry.getValue() == null)
|
|
||||||
{
|
{
|
||||||
plugin.sql.setAdminValue(admin, entry.getKey(), entry.getValue());
|
plugin.sql.setAdminValue(admin, entry.getKey(), entry.getValue());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (SQLException e)
|
}
|
||||||
|
catch (SQLException e)
|
||||||
{
|
{
|
||||||
FLog.severe("Failed to save admin: " + e.getMessage());
|
FLog.severe("Failed to save admin: " + e.getMessage());
|
||||||
}
|
}
|
||||||
@ -280,23 +279,29 @@ public class AdminList extends FreedomService
|
|||||||
|
|
||||||
public void deactivateOldEntries(boolean verbose)
|
public void deactivateOldEntries(boolean verbose)
|
||||||
{
|
{
|
||||||
allAdmins.stream()
|
for (Admin admin : allAdmins)
|
||||||
.filter(admin -> admin.isActive() && !admin.getRank().isAtLeast(GroupProvider.SENIOR_ADMIN.getGroup()))
|
{
|
||||||
.forEach(admin ->
|
if (!admin.isActive() || admin.getRank().isAtLeast(Rank.SENIOR_ADMIN))
|
||||||
{
|
{
|
||||||
final Date lastLogin = admin.getLastLogin();
|
continue;
|
||||||
final long lastLoginHours = TimeUnit.HOURS.convert(new Date().getTime() - lastLogin.getTime(), TimeUnit.MILLISECONDS);
|
}
|
||||||
if (lastLoginHours < ConfigEntry.ADMINLIST_CLEAN_THESHOLD_HOURS.getInteger())
|
|
||||||
{
|
final Date lastLogin = admin.getLastLogin();
|
||||||
return;
|
final long lastLoginHours = TimeUnit.HOURS.convert(new Date().getTime() - lastLogin.getTime(), TimeUnit.MILLISECONDS);
|
||||||
}
|
|
||||||
if (verbose)
|
if (lastLoginHours < ConfigEntry.ADMINLIST_CLEAN_THESHOLD_HOURS.getInteger())
|
||||||
{
|
{
|
||||||
FUtil.adminAction("TotalFreedomMod", "Deactivating admin " + admin.getName() + ", inactive for " + lastLoginHours + " hours", true);
|
continue;
|
||||||
}
|
}
|
||||||
admin.setActive(false);
|
|
||||||
save(admin);
|
if (verbose)
|
||||||
});
|
{
|
||||||
|
FUtil.adminAction("TotalFreedomMod", "Deactivating admin " + admin.getName() + ", inactive for " + lastLoginHours + " hours", true);
|
||||||
|
}
|
||||||
|
|
||||||
|
admin.setActive(false);
|
||||||
|
save(admin);
|
||||||
|
}
|
||||||
|
|
||||||
updateTables();
|
updateTables();
|
||||||
}
|
}
|
@ -71,7 +71,6 @@ public class BanManager extends FreedomService
|
|||||||
@Override
|
@Override
|
||||||
public void onStop()
|
public void onStop()
|
||||||
{
|
{
|
||||||
// This does nothing. This comment is here to prevent SonarLint from complaining.
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Set<Ban> getAllBans()
|
public Set<Ban> getAllBans()
|
@ -19,6 +19,10 @@ public class IndefiniteBan implements IConfig
|
|||||||
private String reason = null;
|
private String reason = null;
|
||||||
private Date expiry = null;
|
private Date expiry = null;
|
||||||
|
|
||||||
|
public IndefiniteBan()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void loadFrom(ConfigurationSection cs)
|
public void loadFrom(ConfigurationSection cs)
|
||||||
{
|
{
|
@ -79,7 +79,6 @@ public class IndefiniteBanList extends FreedomService
|
|||||||
@Override
|
@Override
|
||||||
public void onStop()
|
public void onStop()
|
||||||
{
|
{
|
||||||
// This does nothing. This comment is here to prevent SonarLint from complaining.
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.LOWEST)
|
@EventHandler(priority = EventPriority.LOWEST)
|
||||||
@ -114,10 +113,6 @@ public class IndefiniteBanList extends FreedomService
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
onPlayerLoginSplitWorkToReduceComplexity(event, ban, bannedBy);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void onPlayerLoginSplitWorkToReduceComplexity(PlayerLoginEvent event, IndefiniteBan ban, String bannedBy) {
|
|
||||||
if (ban != null)
|
if (ban != null)
|
||||||
{
|
{
|
||||||
if (ban.isExpired())
|
if (ban.isExpired())
|
||||||
@ -128,8 +123,8 @@ public class IndefiniteBanList extends FreedomService
|
|||||||
}
|
}
|
||||||
|
|
||||||
String kickMessage = ChatColor.RED + "Your " + bannedBy + " is "
|
String kickMessage = ChatColor.RED + "Your " + bannedBy + " is "
|
||||||
+ (ban.hasExpiry() ? "" : "indefinitely ")
|
+ (ban.hasExpiry() ? "" : "indefinitely ")
|
||||||
+ "banned from this server.";
|
+ "banned from this server.";
|
||||||
String reason = ban.getReason();
|
String reason = ban.getReason();
|
||||||
if (!Strings.isNullOrEmpty(reason))
|
if (!Strings.isNullOrEmpty(reason))
|
||||||
{
|
{
|
||||||
@ -150,6 +145,7 @@ public class IndefiniteBanList extends FreedomService
|
|||||||
event.disallow(PlayerLoginEvent.Result.KICK_OTHER, kickMessage);
|
event.disallow(PlayerLoginEvent.Result.KICK_OTHER, kickMessage);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateCount()
|
private void updateCount()
|
||||||
{
|
{
|
||||||
nameBanCount = 0;
|
nameBanCount = 0;
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user