mirror of
https://github.com/AtlasMediaGroup/TotalFreedomMod.git
synced 2025-07-01 12:36:41 +00:00
Compare commits
92 Commits
Author | SHA1 | Date | |
---|---|---|---|
41331e719d | |||
72c83ba84a | |||
3deaaafb88 | |||
edb3dbfdbe | |||
fd6f8a2d17 | |||
ae5038ef0f | |||
ec5aa0304e | |||
ebafc1c669 | |||
1eaaf5fcdb | |||
42458084d7 | |||
0cd2886e40 | |||
575568cb05 | |||
26be5d0f44 | |||
7a724c2f13 | |||
9e1aa5d34e | |||
4564ad0449 | |||
1ddeb4b621 | |||
a8665a15d4 | |||
c0f3712c8d | |||
0dd7bc06eb | |||
4d98108a46 | |||
9d3165694a | |||
cffb5d9326 | |||
4e8df0938f | |||
511f172d84 | |||
bfa8b2a752 | |||
594b1f5605 | |||
b9ca4f52a2 | |||
d298e923b8 | |||
d0d97c0681 | |||
2540c7c589 | |||
6bc91fc779 | |||
9a54ef66d1 | |||
722ef5f99a | |||
6bf6eeec91 | |||
9df30a9556 | |||
83bb892056 | |||
62ff195ec5 | |||
495fe79d94 | |||
422b41dc8d | |||
f44a1c7e69 | |||
9f8dd91457 | |||
ee45256764 | |||
f6faf3b8bc | |||
8210dafcd3 | |||
4eb8174aa9 | |||
ab309032e5 | |||
0db661600f | |||
d94b184703 | |||
c07473ef6d | |||
d7261627ff | |||
6ac7090fef | |||
611ee619a0 | |||
9d2555cd03 | |||
3c4b4140ce | |||
0f2d596b7a | |||
dcdaecf9b0 | |||
b4b10a3020 | |||
fb259ca9b7 | |||
52a39aa992 | |||
b4e7251e3b | |||
0f1fbf9481 | |||
73eb3226ee | |||
8edc87034f | |||
68bcabe5c2 | |||
ecc92589e9 | |||
bf41d08580 | |||
0fc20b6c56 | |||
9c91166319 | |||
09a220e0a2 | |||
ad9dd42edb | |||
c9f5db0141 | |||
47c30c3283 | |||
6c426644f6 | |||
72bab1e2ed | |||
1726050d65 | |||
0fc5b01b29 | |||
dfd90af017 | |||
5af45a2154 | |||
54df28022f | |||
0326171e85 | |||
d13ecea947 | |||
7ec053c867 | |||
1dcc05e7f5 | |||
c913b7ae74 | |||
951f3c91d9 | |||
b573871c14 | |||
adbe125283 | |||
e6a20e1757 | |||
733f002a87 | |||
76ce98621a | |||
bc0495a68f |
6
.github/workflows/codacy-analysis.yml
vendored
6
.github/workflows/codacy-analysis.yml
vendored
@ -21,11 +21,11 @@ jobs:
|
||||
steps:
|
||||
# Checkout the repository to the GitHub Actions runner
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v2
|
||||
uses: actions/checkout@v3
|
||||
|
||||
# Execute Codacy Analysis CLI and generate a SARIF output with the security issues identified during the analysis
|
||||
- name: Run Codacy Analysis CLI
|
||||
uses: codacy/codacy-analysis-cli-action@4.0.0
|
||||
uses: codacy/codacy-analysis-cli-action@v4.1.0
|
||||
with:
|
||||
# Check https://github.com/codacy/codacy-analysis-cli#project-token to get your project token from your Codacy repository
|
||||
# You can also omit the token and run the tools that support default configurations
|
||||
@ -41,6 +41,6 @@ jobs:
|
||||
|
||||
# Upload the SARIF file generated in the previous step
|
||||
- name: Upload SARIF results file
|
||||
uses: github/codeql-action/upload-sarif@v1
|
||||
uses: github/codeql-action/upload-sarif@v2
|
||||
with:
|
||||
sarif_file: results.sarif
|
||||
|
10
.github/workflows/codeql-analysis.yml
vendored
10
.github/workflows/codeql-analysis.yml
vendored
@ -35,10 +35,10 @@ jobs:
|
||||
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v2
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- name: Setup Java JDK
|
||||
uses: actions/setup-java@v2.3.0
|
||||
uses: actions/setup-java@v3.3.0
|
||||
with:
|
||||
# The Java version to make available on the path. Takes a whole or semver Java version, or 1.x syntax (e.g. 1.8 => Java 8.x). Early access versions can be specified in the form of e.g. 14-ea, 14.0.0-ea, or 14.0.0-ea.28
|
||||
java-version: 17
|
||||
@ -46,7 +46,7 @@ jobs:
|
||||
|
||||
# Initializes the CodeQL tools for scanning.
|
||||
- name: Initialize CodeQL
|
||||
uses: github/codeql-action/init@v1
|
||||
uses: github/codeql-action/init@v2
|
||||
with:
|
||||
languages: ${{ matrix.language }}
|
||||
# If you wish to specify custom queries, you can do so here or in a config file.
|
||||
@ -57,7 +57,7 @@ jobs:
|
||||
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
|
||||
# If this step fails, then you should remove it and run the build manually (see below)
|
||||
- name: Autobuild
|
||||
uses: github/codeql-action/autobuild@v1
|
||||
uses: github/codeql-action/autobuild@v2
|
||||
|
||||
# ℹ️ Command-line programs to run using the OS shell.
|
||||
# 📚 https://git.io/JvXDl
|
||||
@ -71,4 +71,4 @@ jobs:
|
||||
# make release
|
||||
|
||||
- name: Perform CodeQL Analysis
|
||||
uses: github/codeql-action/analyze@v1
|
||||
uses: github/codeql-action/analyze@v2
|
||||
|
6
.github/workflows/downstream.yml
vendored
6
.github/workflows/downstream.yml
vendored
@ -17,16 +17,16 @@ jobs:
|
||||
|
||||
steps:
|
||||
# Step 1: run a standard checkout action, provided by github
|
||||
- name: Checkout main
|
||||
- name: Checkout current development branch
|
||||
uses: actions/checkout@v2
|
||||
with:
|
||||
ref: main
|
||||
ref: development
|
||||
# submodules: 'recursive' ### may be needed in your situation
|
||||
|
||||
# Step 2: run this sync action - specify the upstream repo, upstream branch to sync with, and target sync branch
|
||||
- name: Pull (Fast-Forward) upstream changes
|
||||
id: sync
|
||||
uses: aormsby/Fork-Sync-With-Upstream-action@v2.1
|
||||
uses: aormsby/Fork-Sync-With-Upstream-action@v3.3
|
||||
with:
|
||||
upstream_repository: AtlasMediaGroup/TotalFreedomMod
|
||||
upstream_branch: main
|
||||
|
4
.github/workflows/java17-maven.yml
vendored
4
.github/workflows/java17-maven.yml
vendored
@ -9,11 +9,11 @@ jobs:
|
||||
|
||||
steps:
|
||||
# Checkout the code
|
||||
- uses: actions/checkout@v1
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
# Java 16 Builds
|
||||
- name: Set up JDK 17
|
||||
uses: actions/setup-java@v2.3.0
|
||||
uses: actions/setup-java@v3.3.0
|
||||
with:
|
||||
java-version: 17
|
||||
distribution: 'adopt'
|
||||
|
@ -1,4 +1,4 @@
|
||||
# TotalFreedomMod [](https://github.com/AtlasMediaGroup/TotalFreedomMod/actions/workflows/maven.yml) [](https://www.codacy.com/gh/AtlasMediaGroup/TotalFreedomMod/dashboard?utm_source=github.com&utm_medium=referral&utm_content=AtlasMediaGroup/TotalFreedomMod&utm_campaign=Badge_Grade) [](https://github.com/AtlasMediaGroup/TotalFreedomMod/actions/workflows/codeql-analysis.yml)
|
||||
# TotalFreedomMod [](https://github.com/AtlasMediaGroup/TotalFreedomMod/actions/workflows/java17-maven.yml) [](https://www.codacy.com/gh/AtlasMediaGroup/TotalFreedomMod/dashboard?utm_source=github.com&utm_medium=referral&utm_content=AtlasMediaGroup/TotalFreedomMod&utm_campaign=Badge_Grade) [](https://github.com/AtlasMediaGroup/TotalFreedomMod/actions/workflows/codeql-analysis.yml)
|
||||
|
||||
TotalFreedomMod is a CraftBukkit server plugin designed primarily to support the [Official TotalFreedom Minecraft Server](https://totalfreedom.me/). However, you are more than welcome to adapt the source for your own server.
|
||||
|
||||
|
13
SECURITY.md
13
SECURITY.md
@ -10,15 +10,15 @@ In terms of plugin releases, our support matrix is as follows:
|
||||
These versions are currently actively supported by our team, and you should expect security patches where appropriate for these versions.
|
||||
|
||||
| Version | Supported | Support End: |
|
||||
| ------------------- | ------------------ | ------------------------------ |
|
||||
| 2021.09 | :white_check_mark: | No Earlier than December 2021 |
|
||||
| ------------------- | ---------- | ------------------------------ |
|
||||
| 2022.02 | ✅ | No Earlier than May 2022 |
|
||||
|
||||
### Legacy Supported
|
||||
These versions are no longer under active development, however we will look to release critical secuirty patches where appropriate.
|
||||
|
||||
| Version | Supported | Support End: |
|
||||
| ------------------- | ------------------ | ------------ |
|
||||
| 2021.06 | :white_check_mark: | October 2021 |
|
||||
| ------------------- | ---------- | ------------ |
|
||||
| 2021.09 | ⚠️ | April 2022 |
|
||||
|
||||
|
||||
### No Longer Supported
|
||||
@ -26,8 +26,9 @@ These versions are no longer supported at all. It is strongly advised to update
|
||||
|
||||
| Version | Supported | Support Ended: |
|
||||
| ------------------- | ------------------ | ------------------- |
|
||||
| 2021.05 | :white_check_mark: | September 2021 |
|
||||
| 2021.04 | :white_check_mark: | July 2021 |
|
||||
| 2021.06 | :x: | October 2021 |
|
||||
| 2021.05 | :x: | September 2021 |
|
||||
| 2021.04 | :x: | July 2021 |
|
||||
| 2021.02 | :x: | 6 June 2021 |
|
||||
| 2020.11 | :x: | 3 May 2021 |
|
||||
| 6.0.x (Pre-Release) | :x: | December 2020 |
|
||||
|
@ -13,7 +13,7 @@ You can copy and paste the single properties, into the pom.xml file and the IDE
|
||||
That way multiple projects can share the same settings (useful for formatting rules for example).
|
||||
Any value defined here will override the pom.xml file value but is only applicable to the current project.
|
||||
-->
|
||||
<netbeans.hint.jdkPlatform>JDK_11</netbeans.hint.jdkPlatform>
|
||||
<netbeans.hint.jdkPlatform>JDK_17</netbeans.hint.jdkPlatform>
|
||||
<netbeans.checkstyle.format>true</netbeans.checkstyle.format>
|
||||
</properties>
|
||||
</project-shared-configuration>
|
||||
|
34
pom.xml
34
pom.xml
@ -5,7 +5,7 @@
|
||||
|
||||
<groupId>me.totalfreedom</groupId>
|
||||
<artifactId>TotalFreedomMod</artifactId>
|
||||
<version>2022.02-RC01</version>
|
||||
<version>2022.06.1</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<properties>
|
||||
@ -123,7 +123,7 @@
|
||||
<dependency>
|
||||
<groupId>org.bstats</groupId>
|
||||
<artifactId>bstats-bukkit</artifactId>
|
||||
<version>2.2.1</version>
|
||||
<version>3.0.0</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
@ -151,14 +151,14 @@
|
||||
<dependency>
|
||||
<groupId>com.sk89q.worldedit</groupId>
|
||||
<artifactId>worldedit-bukkit</artifactId>
|
||||
<version>7.2.8</version>
|
||||
<version>7.2.10</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>net.dv8tion</groupId>
|
||||
<artifactId>JDA</artifactId>
|
||||
<version>4.2.1_255</version>
|
||||
<version>4.4.0_352</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
@ -172,14 +172,14 @@
|
||||
<dependency>
|
||||
<groupId>com.sk89q.worldguard</groupId>
|
||||
<artifactId>worldguard-bukkit</artifactId>
|
||||
<version>7.0.6</version>
|
||||
<version>7.0.7</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>io.papermc</groupId>
|
||||
<artifactId>paperlib</artifactId>
|
||||
<version>1.0.6</version>
|
||||
<version>1.0.7</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
@ -193,21 +193,21 @@
|
||||
<dependency>
|
||||
<groupId>net.essentialsx</groupId>
|
||||
<artifactId>EssentialsX</artifactId>
|
||||
<version>2.19.0</version>
|
||||
<version>2.19.4</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.reflections</groupId>
|
||||
<artifactId>reflections</artifactId>
|
||||
<version>0.9.12</version>
|
||||
<version>0.10.2</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.javassist</groupId>
|
||||
<artifactId>javassist</artifactId>
|
||||
<version>3.28.0-GA</version>
|
||||
<version>3.29.0-GA</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
@ -221,7 +221,7 @@
|
||||
<dependency>
|
||||
<groupId>org.jetbrains</groupId>
|
||||
<artifactId>annotations</artifactId>
|
||||
<version>22.0.0</version>
|
||||
<version>23.0.0</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
@ -235,14 +235,14 @@
|
||||
<dependency>
|
||||
<groupId>org.junit.jupiter</groupId>
|
||||
<artifactId>junit-jupiter</artifactId>
|
||||
<version>5.8.0</version>
|
||||
<version>5.8.2</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.eclipse.sisu</groupId>
|
||||
<artifactId>org.eclipse.sisu.inject</artifactId>
|
||||
<version>0.3.4</version>
|
||||
<version>0.3.5</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
@ -267,7 +267,7 @@
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.8.1</version>
|
||||
<version>3.10.1</version>
|
||||
<configuration>
|
||||
<outputFileName>TotalFreedomMod.jar</outputFileName>
|
||||
<compilerVersion>17</compilerVersion>
|
||||
@ -321,7 +321,7 @@
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-antrun-plugin</artifactId>
|
||||
<version>3.0.0</version>
|
||||
<version>3.1.0</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>default-cli</id>
|
||||
@ -351,7 +351,7 @@
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>properties-maven-plugin</artifactId>
|
||||
<version>1.0.0</version>
|
||||
<version>1.1.0</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>initialize</phase>
|
||||
@ -371,7 +371,7 @@
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>buildnumber-maven-plugin</artifactId>
|
||||
<version>1.4</version>
|
||||
<version>3.0.0</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>generate-resources</phase>
|
||||
@ -396,7 +396,7 @@
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
<version>3.3.1-SNAPSHOT</version>
|
||||
<version>3.3.0</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
|
@ -175,15 +175,15 @@ public class ChatManager extends FreedomService
|
||||
});
|
||||
}
|
||||
|
||||
public void reportAction(Player reporter, Player reported, String report)
|
||||
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 " + reported.getName() + " for " + report);
|
||||
playerMsg(player, ChatColor.RED + "[REPORTS] " + ChatColor.GOLD + reporter.getName() + " has reported " + reportedName + " for " + report);
|
||||
}
|
||||
}
|
||||
FLog.info("[REPORTS] " + reporter.getName() + " has reported " + reported.getName() + " for " + report);
|
||||
FLog.info("[REPORTS] " + reporter.getName() + " has reported " + reportedName + " for " + report);
|
||||
}
|
||||
}
|
@ -179,7 +179,7 @@ public class LoginProcess extends FreedomService
|
||||
}
|
||||
|
||||
// Whitelist
|
||||
if (server.isWhitelistEnforced() && !player.isWhitelisted())
|
||||
if (server.hasWhitelist() && !player.isWhitelisted())
|
||||
{
|
||||
event.disallow(PlayerLoginEvent.Result.KICK_OTHER, "You are not whitelisted on this server.");
|
||||
}
|
||||
|
@ -6,11 +6,13 @@ import java.util.*;
|
||||
|
||||
import me.totalfreedom.totalfreedommod.LogViewer.LogsRegistrationMode;
|
||||
import me.totalfreedom.totalfreedommod.TotalFreedomMod;
|
||||
import me.totalfreedom.totalfreedommod.player.FPlayer;
|
||||
import me.totalfreedom.totalfreedommod.rank.Rank;
|
||||
import me.totalfreedom.totalfreedommod.util.FLog;
|
||||
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class Admin
|
||||
@ -57,7 +59,7 @@ public class Admin
|
||||
{
|
||||
final StringBuilder output = new StringBuilder();
|
||||
|
||||
output.append("Admin: ").append(getName()).append("\n")
|
||||
output.append("Admin: ").append(getName() != null ? getName() : getUuid().toString()).append("\n")
|
||||
.append("- IPs: ").append(StringUtils.join(ips, ", ")).append("\n")
|
||||
.append("- Last Login: ").append(FUtil.dateToString(lastLogin)).append("\n")
|
||||
.append("- Rank: ").append(rank.getName()).append("\n")
|
||||
@ -157,6 +159,34 @@ public class Admin
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
plugin.lv.updateLogsRegistration(null, getName(), LogsRegistrationMode.DELETE);
|
||||
|
@ -48,12 +48,18 @@ public class AdminList extends FreedomService
|
||||
try
|
||||
{
|
||||
ResultSet adminSet = plugin.sql.getAdminList();
|
||||
{
|
||||
while (adminSet.next())
|
||||
{
|
||||
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)
|
||||
@ -245,7 +251,10 @@ public class AdminList extends FreedomService
|
||||
|
||||
activeAdmins.add(admin);
|
||||
uuidTable.put(admin.getUuid(), admin);
|
||||
if (admin.getName() != null)
|
||||
{
|
||||
nameTable.put(admin.getName().toLowerCase(), admin);
|
||||
}
|
||||
|
||||
for (String ip : admin.getIps())
|
||||
{
|
||||
|
@ -5,6 +5,8 @@ import me.totalfreedom.totalfreedommod.config.ConfigEntry;
|
||||
import me.totalfreedom.totalfreedommod.util.Groups;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
@ -79,9 +81,33 @@ public class InteractBlocker extends FreedomService
|
||||
|
||||
if (Groups.SPAWN_EGGS.contains(event.getMaterial()))
|
||||
{
|
||||
player.getInventory().clear(player.getInventory().getHeldItemSlot());
|
||||
player.sendMessage(ChatColor.GRAY + "Spawn eggs are currently disabled.");
|
||||
event.setCancelled(true);
|
||||
Block clickedBlock = event.getClickedBlock();
|
||||
if (clickedBlock == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
EntityType eggType = null;
|
||||
try
|
||||
{
|
||||
Material mat = event.getMaterial();
|
||||
if (mat == Material.MOOSHROOM_SPAWN_EGG)
|
||||
{
|
||||
eggType = EntityType.MUSHROOM_COW;
|
||||
}
|
||||
else
|
||||
{
|
||||
eggType = EntityType.valueOf(mat.name().substring(0, mat.name().length() - 10));
|
||||
}
|
||||
}
|
||||
catch (IllegalArgumentException ignored)
|
||||
{
|
||||
//
|
||||
}
|
||||
if (eggType != null)
|
||||
{
|
||||
clickedBlock.getWorld().spawnEntity(clickedBlock.getLocation().add(event.getBlockFace().getDirection()).add(0.5, 0.5, 0.5), eggType);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -24,7 +24,7 @@ import org.bukkit.plugin.SimplePluginManager;
|
||||
|
||||
public class CommandBlocker extends FreedomService
|
||||
{
|
||||
|
||||
private final Pattern whitespacePattern = Pattern.compile("^/?( +)(.*)?");
|
||||
private final Pattern flagPattern = Pattern.compile("(:([0-9]){5,})");
|
||||
//
|
||||
private final Map<String, CommandBlockerEntry> entryList = Maps.newHashMap();
|
||||
@ -156,6 +156,14 @@ public class CommandBlocker extends FreedomService
|
||||
|
||||
// Format
|
||||
command = command.toLowerCase().trim();
|
||||
|
||||
// Whitespaces
|
||||
Matcher whitespaceMatcher = whitespacePattern.matcher(command);
|
||||
if (whitespaceMatcher.matches() && whitespaceMatcher.groupCount() == 2)
|
||||
{
|
||||
command = whitespaceMatcher.group(2);
|
||||
}
|
||||
|
||||
command = command.startsWith("/") ? command.substring(1) : command;
|
||||
|
||||
// Check for plugin specific commands
|
||||
|
@ -112,6 +112,9 @@ public class Command_coins extends FreedomCommand
|
||||
+ ChatColor.GOLD + coinsToTransfer
|
||||
+ ChatColor.GREEN + " coin" + (coinsToTransfer > 1 ? "s" : "")
|
||||
+ " to " + ChatColor.GOLD + target.getName() + ChatColor.GREEN + ".", ChatColor.GREEN);
|
||||
|
||||
plugin.pl.save(playerData);
|
||||
plugin.pl.save(senderData);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
@ -4,6 +4,7 @@ import me.totalfreedom.totalfreedommod.rank.Rank;
|
||||
import org.apache.commons.lang.ArrayUtils;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -22,13 +23,15 @@ public class Command_report extends FreedomCommand
|
||||
}
|
||||
|
||||
Player player = getPlayer(args[0], true);
|
||||
OfflinePlayer offlinePlayer = getOfflinePlayer(args[0]);
|
||||
|
||||
if (player == null)
|
||||
if (player == null && offlinePlayer == null)
|
||||
{
|
||||
msg(PLAYER_NOT_FOUND);
|
||||
return true;
|
||||
}
|
||||
|
||||
else if (player != null)
|
||||
{
|
||||
if (sender instanceof Player)
|
||||
{
|
||||
if (player.equals(playerSender))
|
||||
@ -44,14 +47,16 @@ public class Command_report extends FreedomCommand
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
String report = StringUtils.join(ArrayUtils.subarray(args, 1, args.length), " ");
|
||||
plugin.cm.reportAction(playerSender, player, report);
|
||||
plugin.cm.reportAction(playerSender, (player == null) ? offlinePlayer.getName() : player.getName(), report);
|
||||
|
||||
boolean logged = false;
|
||||
|
||||
if (plugin.dc.enabled)
|
||||
{
|
||||
logged = plugin.dc.sendReport(playerSender, player, report);
|
||||
logged = (player == null) ? plugin.dc.sendReportOffline(playerSender, offlinePlayer, report) : plugin.dc.sendReport(playerSender, player, report);
|
||||
}
|
||||
|
||||
msg(ChatColor.GREEN + "Thank you, your report has been successfully logged."
|
||||
|
@ -176,11 +176,10 @@ public class Command_saconfig extends FreedomCommand
|
||||
}
|
||||
|
||||
// Find the old admin entry
|
||||
String name = player.getName();
|
||||
Admin admin = null;
|
||||
for (Admin loopAdmin : plugin.al.getAllAdmins())
|
||||
{
|
||||
if (loopAdmin.getName().equalsIgnoreCase(name) || loopAdmin.getIps().contains(FUtil.getIp(player)))
|
||||
if (loopAdmin.getUuid().equals(player.getUniqueId()))
|
||||
{
|
||||
admin = loopAdmin;
|
||||
break;
|
||||
@ -189,7 +188,6 @@ public class Command_saconfig extends FreedomCommand
|
||||
|
||||
if (admin == null) // New admin
|
||||
{
|
||||
|
||||
FUtil.adminAction(sender.getName(), "Adding " + player.getName() + " to the admin list", true);
|
||||
admin = new Admin(player);
|
||||
|
||||
@ -240,6 +238,7 @@ public class Command_saconfig extends FreedomCommand
|
||||
checkRank(Rank.ADMIN);
|
||||
|
||||
Player player = getPlayer(args[1]);
|
||||
|
||||
Admin admin = player != null ? plugin.al.getAdmin(player) : plugin.al.getEntryByName(args[1]);
|
||||
|
||||
if (admin == null)
|
||||
@ -248,20 +247,22 @@ public class Command_saconfig extends FreedomCommand
|
||||
return true;
|
||||
}
|
||||
|
||||
String adminName = admin.getName();
|
||||
|
||||
FUtil.adminAction(sender.getName(), "Removing " + admin.getName() + " from the admin list", true);
|
||||
admin.setActive(false);
|
||||
|
||||
plugin.al.save(admin);
|
||||
plugin.al.updateTables();
|
||||
|
||||
if (player != null)
|
||||
{
|
||||
plugin.rm.updateDisplay(player);
|
||||
plugin.pl.getPlayer(player).setAdminChat(false);
|
||||
}
|
||||
|
||||
if (plugin.dc.enabled && ConfigEntry.DISCORD_ROLE_SYNC.getBoolean())
|
||||
{
|
||||
Discord.syncRoles(admin, plugin.pl.getData(admin.getName()).getDiscordID());
|
||||
Discord.syncRoles(admin, plugin.pl.getData(adminName).getDiscordID());
|
||||
}
|
||||
|
||||
plugin.ptero.updateAccountStatus(admin);
|
||||
|
@ -45,7 +45,7 @@ public class Command_vanish extends FreedomCommand
|
||||
msg("You have unvanished.", ChatColor.GOLD);
|
||||
FUtil.bcastMsg(plugin.rm.craftLoginMessage(playerSender, null));
|
||||
FUtil.bcastMsg(playerSender.getName() + " joined the game.", ChatColor.YELLOW);
|
||||
plugin.dc.messageChatChannel("**" + playerSender.getName() + " joined the server" + "**");
|
||||
plugin.dc.messageChatChannel("**" + playerSender.getName() + " joined the server" + "**", true);
|
||||
}
|
||||
|
||||
PlayerData playerData = plugin.pl.getData(playerSender);
|
||||
@ -91,7 +91,7 @@ public class Command_vanish extends FreedomCommand
|
||||
{
|
||||
msg("You have vanished.", ChatColor.GOLD);
|
||||
FUtil.bcastMsg(playerSender.getName() + " left the game.", ChatColor.YELLOW);
|
||||
plugin.dc.messageChatChannel("**" + playerSender.getName() + " left the server" + "**");
|
||||
plugin.dc.messageChatChannel("**" + playerSender.getName() + " left the server" + "**", true);
|
||||
}
|
||||
|
||||
FLog.info(playerSender.getName() + " is now vanished.");
|
||||
|
@ -1,14 +1,10 @@
|
||||
package me.totalfreedom.totalfreedommod.command;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
import java.util.*;
|
||||
|
||||
import me.totalfreedom.totalfreedommod.TotalFreedomMod;
|
||||
import me.totalfreedom.totalfreedommod.admin.Admin;
|
||||
import me.totalfreedom.totalfreedommod.player.PlayerData;
|
||||
@ -18,12 +14,14 @@ import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.command.*;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.util.StringUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public abstract class FreedomCommand implements CommandExecutor, TabCompleter
|
||||
{
|
||||
@ -229,6 +227,16 @@ public abstract class FreedomCommand implements CommandExecutor, TabCompleter
|
||||
return player;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
protected OfflinePlayer getOfflinePlayer(String name)
|
||||
{
|
||||
return Arrays.stream(Bukkit.getOfflinePlayers())
|
||||
.filter(player -> player.getName() != null)
|
||||
.filter(player -> player.getName().equalsIgnoreCase(name))
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
}
|
||||
|
||||
protected Admin getAdmin(CommandSender sender)
|
||||
{
|
||||
return plugin.al.getAdmin(sender);
|
||||
|
@ -74,7 +74,9 @@ public enum ConfigEntry
|
||||
SERVER_FULL_MOTD(String.class, "server.motds.full"),
|
||||
//
|
||||
DISCORD_TOKEN(String.class, "discord.token"),
|
||||
DISCORD_PREFIX(String.class, "discord.prefix"),
|
||||
DISCORD_REPORT_CHANNEL_ID(String.class, "discord.report_channel_id"),
|
||||
DISCORD_REPORT_ARCHIVE_CHANNEL_ID(String.class, "discord.report_archive_channel_id"),
|
||||
DISCORD_CHAT_CHANNEL_ID(String.class, "discord.chat_channel_id"),
|
||||
DISCORD_ADMINCHAT_CHANNEL_ID(String.class, "discord.adminchat_channel_id"),
|
||||
|
||||
|
@ -13,9 +13,12 @@ import java.util.concurrent.ScheduledThreadPoolExecutor;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import javax.security.auth.login.LoginException;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import me.totalfreedom.totalfreedommod.FreedomService;
|
||||
import me.totalfreedom.totalfreedommod.admin.Admin;
|
||||
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
|
||||
import me.totalfreedom.totalfreedommod.discord.command.DiscordCommandManager;
|
||||
import me.totalfreedom.totalfreedommod.player.PlayerData;
|
||||
import me.totalfreedom.totalfreedommod.rank.Rank;
|
||||
import me.totalfreedom.totalfreedommod.util.FLog;
|
||||
@ -37,9 +40,14 @@ import net.dv8tion.jda.api.requests.GatewayIntent;
|
||||
import net.dv8tion.jda.api.utils.ChunkingFilter;
|
||||
import net.dv8tion.jda.api.utils.MemberCachePolicy;
|
||||
import net.dv8tion.jda.internal.utils.concurrent.CountingThreadFactory;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.commons.lang.WordUtils;
|
||||
import org.apache.commons.lang3.RandomStringUtils;
|
||||
import org.bukkit.GameRule;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
@ -53,9 +61,11 @@ public class Discord extends FreedomService
|
||||
|
||||
public static HashMap<String, PlayerData> LINK_CODES = new HashMap<>();
|
||||
public static JDA bot = null;
|
||||
public static DiscordCommandManager DISCORD_COMMAND_MANAGER;
|
||||
public ScheduledThreadPoolExecutor RATELIMIT_EXECUTOR;
|
||||
public List<CompletableFuture<Message>> sentMessages = new ArrayList<>();
|
||||
public Boolean enabled = false;
|
||||
private static final ImmutableList<String> DISCORD_SUBDOMAINS = ImmutableList.of("discordapp.com", "discord.com", "discord.gg");
|
||||
private final Pattern DISCORD_MENTION_PATTERN = Pattern.compile("(<@!?([0-9]{16,20})>)");
|
||||
|
||||
public static String getCode(PlayerData playerData)
|
||||
@ -146,6 +156,9 @@ public class Discord extends FreedomService
|
||||
|
||||
public void startBot()
|
||||
{
|
||||
DISCORD_COMMAND_MANAGER = new DiscordCommandManager();
|
||||
DISCORD_COMMAND_MANAGER.init(this);
|
||||
|
||||
enabled = !Strings.isNullOrEmpty(ConfigEntry.DISCORD_TOKEN.getString());
|
||||
if (!enabled)
|
||||
{
|
||||
@ -168,6 +181,7 @@ public class Discord extends FreedomService
|
||||
.addEventListeners(new PrivateMessageListener(),
|
||||
new DiscordToMinecraftListener(),
|
||||
new DiscordToAdminChatListener(),
|
||||
new MessageReactionListener(),
|
||||
new ListenerAdapter()
|
||||
{
|
||||
@Override
|
||||
@ -215,7 +229,7 @@ public class Discord extends FreedomService
|
||||
}
|
||||
}
|
||||
sentMessages.clear();
|
||||
messageChatChannel("**Message queue cleared**");
|
||||
messageChatChannel("**Message queue cleared**", true);
|
||||
}
|
||||
|
||||
public void sendPteroInfo(PlayerData playerData, String username, String password)
|
||||
@ -246,13 +260,7 @@ public class Discord extends FreedomService
|
||||
|
||||
public String generateCode(int size)
|
||||
{
|
||||
StringBuilder code = new StringBuilder();
|
||||
SplittableRandom random = new SplittableRandom();
|
||||
for (int i = 0; i < size; i++)
|
||||
{
|
||||
code.append(random.nextInt(10));
|
||||
}
|
||||
return code.toString();
|
||||
return RandomStringUtils.randomNumeric(size);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
@ -265,9 +273,11 @@ public class Discord extends FreedomService
|
||||
return;
|
||||
}
|
||||
|
||||
if (event.getDeathMessage() != null)
|
||||
Component deathMessage = event.deathMessage();
|
||||
|
||||
if (deathMessage != null)
|
||||
{
|
||||
messageChatChannel("**" + event.getDeathMessage() + "**");
|
||||
messageChatChannel("**" + PlainTextComponentSerializer.plainText().serialize(deathMessage) + "**", true);
|
||||
}
|
||||
}
|
||||
|
||||
@ -282,7 +292,7 @@ public class Discord extends FreedomService
|
||||
{
|
||||
if (!plugin.al.isVanished(event.getPlayer().getName()))
|
||||
{
|
||||
messageChatChannel("**" + event.getPlayer().getName() + " joined the server" + "**");
|
||||
messageChatChannel("**" + event.getPlayer().getName() + " joined the server" + "**", true);
|
||||
}
|
||||
}
|
||||
|
||||
@ -291,74 +301,77 @@ public class Discord extends FreedomService
|
||||
{
|
||||
if (!plugin.al.isVanished(event.getPlayer().getName()))
|
||||
{
|
||||
messageChatChannel("**" + event.getPlayer().getName() + " left the server" + "**");
|
||||
messageChatChannel("**" + event.getPlayer().getName() + " left the server" + "**", true);
|
||||
}
|
||||
}
|
||||
|
||||
public void messageChatChannel(String message)
|
||||
public static String sanitizeChatMessage(String message)
|
||||
{
|
||||
String chat_channel_id = ConfigEntry.DISCORD_CHAT_CHANNEL_ID.getString();
|
||||
if (message.contains("@everyone") || message.contains("@here"))
|
||||
String newMessage = message;
|
||||
|
||||
if (message.contains("@"))
|
||||
{
|
||||
message = StringUtils.remove(message, "@");
|
||||
// \u200B is Zero Width Space, invisible on Discord
|
||||
newMessage = message.replaceAll("@", "@\u200B");
|
||||
}
|
||||
|
||||
if (message.toLowerCase().contains("discord.gg"))
|
||||
if (message.toLowerCase().contains("discord.gg")) // discord.gg/invite works as an invite
|
||||
{
|
||||
return;
|
||||
return "";
|
||||
}
|
||||
|
||||
for (String subdomain : DISCORD_SUBDOMAINS)
|
||||
{
|
||||
if (message.toLowerCase().contains(subdomain + "/invite"))
|
||||
{
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
if (message.contains("§"))
|
||||
{
|
||||
message = StringUtils.remove(message, "§");
|
||||
newMessage = message.replaceAll("§", "");
|
||||
}
|
||||
|
||||
return deformat(newMessage);
|
||||
}
|
||||
|
||||
Matcher DISCORD_MENTION_MATCHER = DISCORD_MENTION_PATTERN.matcher(message);
|
||||
|
||||
while (DISCORD_MENTION_MATCHER.find())
|
||||
public void messageChatChannel(String message)
|
||||
{
|
||||
String mention = DISCORD_MENTION_MATCHER.group(1);
|
||||
message = message.replace(mention, mention.replace("@",""));
|
||||
messageChatChannel(message, false);
|
||||
}
|
||||
|
||||
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 (enabled && !chat_channel_id.isEmpty())
|
||||
{
|
||||
CompletableFuture<Message> sentMessage = Objects.requireNonNull(bot.getTextChannelById(chat_channel_id)).sendMessage(deformat(message)).submit(true);
|
||||
CompletableFuture<Message> sentMessage = Objects.requireNonNull(bot.getTextChannelById(chat_channel_id)).sendMessage(sanitizedMessage).submit(true);
|
||||
sentMessages.add(sentMessage);
|
||||
}
|
||||
}
|
||||
|
||||
public void messageAdminChatChannel(String message)
|
||||
{
|
||||
messageAdminChatChannel(message, false);
|
||||
}
|
||||
|
||||
public void messageAdminChatChannel(String message, boolean system)
|
||||
{
|
||||
String chat_channel_id = ConfigEntry.DISCORD_ADMINCHAT_CHANNEL_ID.getString();
|
||||
if (message.contains("@everyone") || message.contains("@here"))
|
||||
{
|
||||
message = StringUtils.remove(message, "@");
|
||||
}
|
||||
|
||||
if (message.toLowerCase().contains("discord.gg"))
|
||||
{
|
||||
return;
|
||||
}
|
||||
String sanitizedMessage = sanitizeChatMessage(message);
|
||||
|
||||
if (message.contains("§"))
|
||||
{
|
||||
message = StringUtils.remove(message, "§");
|
||||
}
|
||||
|
||||
|
||||
Matcher DISCORD_MENTION_MATCHER = DISCORD_MENTION_PATTERN.matcher(message);
|
||||
|
||||
while (DISCORD_MENTION_MATCHER.find())
|
||||
{
|
||||
String mention = DISCORD_MENTION_MATCHER.group(1);
|
||||
message = message.replace(mention, mention.replace("@",""));
|
||||
}
|
||||
if (sanitizedMessage.isBlank()) return;
|
||||
|
||||
if (enabled && !chat_channel_id.isEmpty())
|
||||
{
|
||||
CompletableFuture<Message> sentMessage = Objects.requireNonNull(bot.getTextChannelById(chat_channel_id)).sendMessage(deformat(message)).submit(true);
|
||||
CompletableFuture<Message> sentMessage = Objects.requireNonNull(bot.getTextChannelById(chat_channel_id)).sendMessage(sanitizedMessage).submit(true);
|
||||
sentMessages.add(sentMessage);
|
||||
}
|
||||
}
|
||||
@ -366,7 +379,7 @@ public class Discord extends FreedomService
|
||||
public String formatBotTag()
|
||||
{
|
||||
SelfUser user = bot.getSelfUser();
|
||||
return user.getName() + "#" + user.getDiscriminator();
|
||||
return user.getAsTag();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -374,18 +387,18 @@ public class Discord extends FreedomService
|
||||
{
|
||||
if (bot != null)
|
||||
{
|
||||
messageChatChannel("**Server has stopped**");
|
||||
messageChatChannel("**Server has stopped**", true);
|
||||
}
|
||||
|
||||
FLog.info("Discord integration has successfully shutdown.");
|
||||
}
|
||||
|
||||
public String deformat(String input)
|
||||
public static String deformat(String input)
|
||||
{
|
||||
return input.replace("_", "\\_");
|
||||
return input.replaceAll("([_\\\\`*>|])", "\\\\$1");
|
||||
}
|
||||
|
||||
public boolean sendReport(Player reporter, Player reported, String reason)
|
||||
public boolean shouldISendReport()
|
||||
{
|
||||
if (ConfigEntry.DISCORD_REPORT_CHANNEL_ID.getString().isEmpty())
|
||||
{
|
||||
@ -400,6 +413,7 @@ public class Discord extends FreedomService
|
||||
|
||||
Guild server = bot.getGuildById(ConfigEntry.DISCORD_SERVER_ID.getString());
|
||||
if (server == null)
|
||||
|
||||
{
|
||||
FLog.severe("The Discord server ID specified is invalid, or the bot is not on the server.");
|
||||
return false;
|
||||
@ -412,7 +426,57 @@ public class Discord extends FreedomService
|
||||
return false;
|
||||
}
|
||||
|
||||
EmbedBuilder embedBuilder = new EmbedBuilder();
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean sendReportOffline(Player reporter, OfflinePlayer reported, String reason)
|
||||
{
|
||||
if (!shouldISendReport())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
final Guild server = bot.getGuildById(ConfigEntry.DISCORD_SERVER_ID.getString());
|
||||
final TextChannel channel = server.getTextChannelById(ConfigEntry.DISCORD_REPORT_CHANNEL_ID.getString());
|
||||
|
||||
final EmbedBuilder embedBuilder = new EmbedBuilder();
|
||||
embedBuilder.setTitle("Report for " + reported.getName() + " (offline)");
|
||||
embedBuilder.setDescription(reason);
|
||||
embedBuilder.setFooter("Reported by " + reporter.getName(), "https://minotar.net/helm/" + reporter.getName() + ".png");
|
||||
embedBuilder.setTimestamp(Instant.from(ZonedDateTime.now()));
|
||||
if (plugin.esb.isEnabled())
|
||||
{
|
||||
com.earth2me.essentials.User user = plugin.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();
|
||||
embedBuilder.addField("Location", location, true);
|
||||
embedBuilder.addField("God Mode", WordUtils.capitalizeFully(String.valueOf(user.isGodModeEnabled())), true);
|
||||
if (user.getNickname() != null)
|
||||
{
|
||||
embedBuilder.addField("Nickname", user.getNickname(), true);
|
||||
}
|
||||
}
|
||||
MessageEmbed embed = embedBuilder.build();
|
||||
Message message = channel.sendMessage(embed).complete();
|
||||
|
||||
if (!ConfigEntry.DISCORD_REPORT_ARCHIVE_CHANNEL_ID.getString().isEmpty())
|
||||
{
|
||||
message.addReaction("\uD83D\uDCCB").complete();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean sendReport(Player reporter, Player reported, String reason)
|
||||
{
|
||||
if (!shouldISendReport())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
final Guild server = bot.getGuildById(ConfigEntry.DISCORD_SERVER_ID.getString());
|
||||
final TextChannel channel = server.getTextChannelById(ConfigEntry.DISCORD_REPORT_CHANNEL_ID.getString());
|
||||
|
||||
final EmbedBuilder embedBuilder = new EmbedBuilder();
|
||||
embedBuilder.setTitle("Report for " + reported.getName());
|
||||
embedBuilder.setDescription(reason);
|
||||
embedBuilder.setFooter("Reported by " + reporter.getName(), "https://minotar.net/helm/" + reporter.getName() + ".png");
|
||||
@ -420,14 +484,25 @@ public class Discord extends FreedomService
|
||||
String location = "World: " + Objects.requireNonNull(reported.getLocation().getWorld()).getName() + ", X: " + reported.getLocation().getBlockX() + ", Y: " + reported.getLocation().getBlockY() + ", Z: " + reported.getLocation().getBlockZ();
|
||||
embedBuilder.addField("Location", location, true);
|
||||
embedBuilder.addField("Game Mode", WordUtils.capitalizeFully(reported.getGameMode().name()), true);
|
||||
|
||||
if (plugin.esb.isEnabled())
|
||||
{
|
||||
com.earth2me.essentials.User user = plugin.esb.getEssentialsUser(reported.getName());
|
||||
embedBuilder.addField("God Mode", WordUtils.capitalizeFully(String.valueOf(user.isGodModeEnabled())), true);
|
||||
if (user.getNickname() != null)
|
||||
{
|
||||
embedBuilder.addField("Nickname", user.getNickname(), true);
|
||||
}
|
||||
}
|
||||
|
||||
MessageEmbed embed = embedBuilder.build();
|
||||
channel.sendMessage(embed).complete();
|
||||
Message message = channel.sendMessage(embed).complete();
|
||||
|
||||
if (!ConfigEntry.DISCORD_REPORT_ARCHIVE_CHANNEL_ID.getString().isEmpty())
|
||||
{
|
||||
message.addReaction("\uD83D\uDCCB").complete();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -436,7 +511,7 @@ public class Discord extends FreedomService
|
||||
{
|
||||
public void start()
|
||||
{
|
||||
messageChatChannel("**Server has started**");
|
||||
messageChatChannel("**Server has started**", true);
|
||||
}
|
||||
}
|
||||
}
|
@ -2,12 +2,12 @@ package me.totalfreedom.totalfreedommod.discord;
|
||||
|
||||
import me.totalfreedom.totalfreedommod.TotalFreedomMod;
|
||||
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
|
||||
import me.totalfreedom.totalfreedommod.discord.command.DiscordCommandManager;
|
||||
import me.totalfreedom.totalfreedommod.rank.Rank;
|
||||
import me.totalfreedom.totalfreedommod.rank.Title;
|
||||
import me.totalfreedom.totalfreedommod.util.FLog;
|
||||
import net.dv8tion.jda.api.entities.Guild;
|
||||
import net.dv8tion.jda.api.entities.Member;
|
||||
import net.dv8tion.jda.api.entities.Message;
|
||||
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||
import net.dv8tion.jda.api.entities.*;
|
||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||
import net.dv8tion.jda.api.hooks.ListenerAdapter;
|
||||
import net.md_5.bungee.api.chat.BaseComponent;
|
||||
@ -24,14 +24,46 @@ public class DiscordToMinecraftListener extends ListenerAdapter
|
||||
{
|
||||
public void onMessageReceived(MessageReceivedEvent event)
|
||||
{
|
||||
String chat_channel_id = ConfigEntry.DISCORD_CHAT_CHANNEL_ID.getString();
|
||||
if (event.getMember() != null && !chat_channel_id.isEmpty() && event.getChannel().getId().equals(chat_channel_id))
|
||||
final String chat_channel_id = ConfigEntry.DISCORD_CHAT_CHANNEL_ID.getString();
|
||||
final MessageChannel genericChannel = event.getChannel();
|
||||
|
||||
if (event.getMember() == null)
|
||||
{
|
||||
if (!event.getAuthor().getId().equals(Discord.bot.getSelfUser().getId()))
|
||||
return;
|
||||
}
|
||||
|
||||
if (chat_channel_id.isEmpty())
|
||||
{
|
||||
Member member = event.getMember();
|
||||
String tag = getDisplay(member);
|
||||
Message msg = event.getMessage();
|
||||
return;
|
||||
}
|
||||
|
||||
if (event.getAuthor().getId().equals(Discord.bot.getSelfUser().getId()))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!genericChannel.getId().equals(chat_channel_id))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!(genericChannel instanceof TextChannel))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
final TextChannel textChannel = (TextChannel) genericChannel;
|
||||
|
||||
final Member member = event.getMember();
|
||||
final String tag = getDisplay(member);
|
||||
final Message msg = event.getMessage();
|
||||
final String content = msg.getContentStripped();
|
||||
|
||||
if (content.startsWith(ConfigEntry.DISCORD_PREFIX.getString()))
|
||||
{
|
||||
Discord.DISCORD_COMMAND_MANAGER.parse(content, member, textChannel);
|
||||
return;
|
||||
}
|
||||
|
||||
ComponentBuilder emsg = new ComponentBuilder();
|
||||
|
||||
@ -55,13 +87,13 @@ public class DiscordToMinecraftListener extends ListenerAdapter
|
||||
emsg.append(" ");
|
||||
|
||||
// User
|
||||
TextComponent user = new TextComponent(ChatColor.stripColor(member.getEffectiveName()));
|
||||
TextComponent user = new TextComponent(FUtil.stripColors(member.getEffectiveName()));
|
||||
user.setColor(ChatColor.RED.asBungee());
|
||||
emsg.append(user);
|
||||
|
||||
// Message
|
||||
emsg.append(ChatColor.DARK_GRAY + ": " + ChatColor.RESET
|
||||
+ ChatColor.stripColor(msg.getContentDisplay()), ComponentBuilder.FormatRetention.NONE);
|
||||
+ FUtil.stripColors(msg.getContentDisplay()), ComponentBuilder.FormatRetention.NONE);
|
||||
|
||||
// Attachments
|
||||
if (!msg.getAttachments().isEmpty())
|
||||
@ -86,14 +118,13 @@ public class DiscordToMinecraftListener extends ListenerAdapter
|
||||
{
|
||||
if (TotalFreedomMod.getPlugin().pl.getData(player).doesDisplayDiscord())
|
||||
{
|
||||
player.spigot().sendMessage(components);
|
||||
player.sendMessage(components);
|
||||
}
|
||||
}
|
||||
|
||||
FLog.info(TextComponent.toLegacyText(components), true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public String getDisplay(Member member)
|
||||
{
|
||||
|
@ -0,0 +1,68 @@
|
||||
package me.totalfreedom.totalfreedommod.discord;
|
||||
|
||||
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
|
||||
import me.totalfreedom.totalfreedommod.util.FLog;
|
||||
import net.dv8tion.jda.api.MessageBuilder;
|
||||
import net.dv8tion.jda.api.entities.Member;
|
||||
import net.dv8tion.jda.api.entities.Message;
|
||||
import net.dv8tion.jda.api.entities.MessageEmbed;
|
||||
import net.dv8tion.jda.api.entities.TextChannel;
|
||||
import net.dv8tion.jda.api.events.message.react.MessageReactionAddEvent;
|
||||
import net.dv8tion.jda.api.hooks.ListenerAdapter;
|
||||
|
||||
public class MessageReactionListener extends ListenerAdapter
|
||||
{
|
||||
public void onMessageReactionAdd(MessageReactionAddEvent messageReactionAddEvent)
|
||||
{
|
||||
if (!messageReactionAddEvent.isFromGuild())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (messageReactionAddEvent.getMember() == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (messageReactionAddEvent.getMember().getUser().getId().equals(Discord.bot.getSelfUser().getId()))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!messageReactionAddEvent.getChannel().getId().equals(ConfigEntry.DISCORD_REPORT_CHANNEL_ID.getString()))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!messageReactionAddEvent.getReactionEmote().getEmoji().equals("\uD83D\uDCCB"))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
final TextChannel archiveChannel = Discord.bot.getTextChannelById(ConfigEntry.DISCORD_REPORT_ARCHIVE_CHANNEL_ID.getString());
|
||||
|
||||
if (archiveChannel == null)
|
||||
{
|
||||
FLog.warning("Report archive channel is defined in the config, yet doesn't actually exist!");
|
||||
return;
|
||||
}
|
||||
|
||||
final Message message = messageReactionAddEvent.retrieveMessage().complete();
|
||||
final Member completer = messageReactionAddEvent.getMember();
|
||||
|
||||
if (!message.getAuthor().getId().equals(Discord.bot.getSelfUser().getId()))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// We don't need other embeds... yet?
|
||||
final MessageEmbed embed = message.getEmbeds().get(0);
|
||||
final MessageBuilder archiveMessageBuilder = new MessageBuilder();
|
||||
archiveMessageBuilder.setContent("Report completed by " + completer.getUser().getAsMention() + " (" + Discord.deformat(completer.getUser().getAsTag() + ")"));
|
||||
archiveMessageBuilder.setEmbed(embed);
|
||||
final Message archiveMessage = archiveMessageBuilder.build();
|
||||
|
||||
archiveChannel.sendMessage(archiveMessage).complete();
|
||||
message.delete().complete();
|
||||
}
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
package me.totalfreedom.totalfreedommod.discord.command;
|
||||
|
||||
import net.dv8tion.jda.api.MessageBuilder;
|
||||
import net.dv8tion.jda.api.entities.Guild;
|
||||
import net.dv8tion.jda.api.entities.Member;
|
||||
import net.dv8tion.jda.api.entities.User;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface DiscordCommand
|
||||
{
|
||||
String getCommandName();
|
||||
|
||||
String getDescription();
|
||||
|
||||
String getCategory();
|
||||
|
||||
List<String> getAliases();
|
||||
|
||||
boolean isAdmin();
|
||||
|
||||
boolean canExecute(Member member);
|
||||
|
||||
MessageBuilder execute(Member member, List<String> args);
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
package me.totalfreedom.totalfreedommod.discord.command;
|
||||
|
||||
import net.dv8tion.jda.api.entities.Member;
|
||||
|
||||
public abstract class DiscordCommandImpl implements DiscordCommand
|
||||
{
|
||||
@Override
|
||||
public boolean canExecute(Member member)
|
||||
{
|
||||
//return !isAdmin() || member.getRoles().stream().filter((role -> role.getName().toLowerCase().contains("admin") && !role.getName().toLowerCase().contains("discord"))).toList().size() > 0;
|
||||
return !isAdmin();
|
||||
}
|
||||
}
|
@ -0,0 +1,84 @@
|
||||
package me.totalfreedom.totalfreedommod.discord.command;
|
||||
|
||||
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
|
||||
import me.totalfreedom.totalfreedommod.discord.Discord;
|
||||
import me.totalfreedom.totalfreedommod.util.FLog;
|
||||
import net.dv8tion.jda.api.EmbedBuilder;
|
||||
import net.dv8tion.jda.api.MessageBuilder;
|
||||
import net.dv8tion.jda.api.entities.Member;
|
||||
import net.dv8tion.jda.api.entities.Message;
|
||||
import net.dv8tion.jda.api.entities.TextChannel;
|
||||
import org.reflections.Reflections;
|
||||
|
||||
import java.awt.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
public class DiscordCommandManager
|
||||
{
|
||||
public static final String PREFIX = ConfigEntry.DISCORD_PREFIX.getString();
|
||||
private Discord discord;
|
||||
public final List<DiscordCommand> commands = new ArrayList<>();
|
||||
|
||||
public void init(Discord discord)
|
||||
{
|
||||
this.discord = discord;
|
||||
|
||||
final Reflections discordCommandsDir = new Reflections("me.totalfreedom.totalfreedommod.discord.commands");
|
||||
|
||||
final Set<Class<? extends DiscordCommand>> commandClasses = discordCommandsDir.getSubTypesOf(DiscordCommand.class);
|
||||
|
||||
for (Class<? extends DiscordCommand> commandClass : commandClasses)
|
||||
{
|
||||
try
|
||||
{
|
||||
commands.add(commandClass.getDeclaredConstructor().newInstance());
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
FLog.warning("Failed to load Discord command: " + commandClass.getName());
|
||||
}
|
||||
}
|
||||
|
||||
FLog.info("Loaded " + commands.size() + " Discord commands.");
|
||||
}
|
||||
|
||||
public void parse(String content, Member member, TextChannel channel)
|
||||
{
|
||||
List<String> args = new ArrayList<>(Arrays.asList(content.split(" ")));
|
||||
|
||||
final String alias = args.remove(0).split(PREFIX)[1]; // The joys of command parsing
|
||||
|
||||
for (DiscordCommand command : commands)
|
||||
{
|
||||
if (command.getCommandName().equalsIgnoreCase(alias) || command.getAliases().contains(alias.toLowerCase()))
|
||||
{
|
||||
if (command.canExecute(member))
|
||||
{
|
||||
final MessageBuilder messageBuilder = command.execute(member, args);
|
||||
final Message message = messageBuilder.build();
|
||||
final CompletableFuture<Message> futureMessage = channel.sendMessage(message).submit(true);
|
||||
|
||||
this.discord.sentMessages.add(futureMessage);
|
||||
}
|
||||
else
|
||||
{
|
||||
final MessageBuilder messageBuilder = new MessageBuilder();
|
||||
final EmbedBuilder embedBuilder = new EmbedBuilder();
|
||||
embedBuilder.setTitle("Command error");
|
||||
embedBuilder.setColor(Color.RED);
|
||||
embedBuilder.setDescription("You don't have permission to execute this command.");
|
||||
messageBuilder.setEmbed(embedBuilder.build());
|
||||
final Message message = messageBuilder.build();
|
||||
|
||||
final CompletableFuture<Message> futureMessage = channel.sendMessage(message).submit(true);
|
||||
|
||||
this.discord.sentMessages.add(futureMessage);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,86 @@
|
||||
package me.totalfreedom.totalfreedommod.discord.commands;
|
||||
|
||||
import me.totalfreedom.totalfreedommod.discord.Discord;
|
||||
import me.totalfreedom.totalfreedommod.discord.command.DiscordCommand;
|
||||
import me.totalfreedom.totalfreedommod.discord.command.DiscordCommandImpl;
|
||||
import me.totalfreedom.totalfreedommod.discord.command.DiscordCommandManager;
|
||||
import net.dv8tion.jda.api.EmbedBuilder;
|
||||
import net.dv8tion.jda.api.MessageBuilder;
|
||||
import net.dv8tion.jda.api.entities.Member;
|
||||
|
||||
import java.awt.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class HelpCommand extends DiscordCommandImpl
|
||||
{
|
||||
@Override
|
||||
public String getCommandName()
|
||||
{
|
||||
return "help";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription()
|
||||
{
|
||||
return "Displays the help command";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCategory()
|
||||
{
|
||||
return "Help";
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getAliases()
|
||||
{
|
||||
return List.of("cmds", "commands", "elp");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAdmin()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MessageBuilder execute(Member member, List<String> args)
|
||||
{
|
||||
final EmbedBuilder embedBuilder = new EmbedBuilder();
|
||||
embedBuilder.setColor(Color.GREEN);
|
||||
embedBuilder.setTitle("Help Command");
|
||||
|
||||
final Map<String, List<DiscordCommand>> commandCategories = new HashMap<>();
|
||||
|
||||
for (DiscordCommand command : Discord.DISCORD_COMMAND_MANAGER.commands)
|
||||
{
|
||||
if (!commandCategories.containsKey(command.getCategory()))
|
||||
{
|
||||
commandCategories.put(command.getCategory(), new ArrayList<>(List.of(command)));
|
||||
}
|
||||
else
|
||||
{
|
||||
commandCategories.get(command.getCategory()).add(command);
|
||||
}
|
||||
}
|
||||
|
||||
for (Map.Entry<String, List<DiscordCommand>> entry : commandCategories.entrySet())
|
||||
{
|
||||
final String category = entry.getKey();
|
||||
final List<DiscordCommand> commands = entry.getValue();
|
||||
final StringBuilder fieldValue = new StringBuilder();
|
||||
|
||||
for (DiscordCommand command : commands)
|
||||
{
|
||||
fieldValue.append("**").append(DiscordCommandManager.PREFIX).append(command.getCommandName()).append("** - ").append(command.getDescription()).append("\n");
|
||||
}
|
||||
|
||||
embedBuilder.addField(category, fieldValue.toString().trim(), false);
|
||||
}
|
||||
|
||||
return new MessageBuilder().setEmbed(embedBuilder.build());
|
||||
}
|
||||
}
|
@ -0,0 +1,106 @@
|
||||
package me.totalfreedom.totalfreedommod.discord.commands;
|
||||
|
||||
import me.totalfreedom.totalfreedommod.TotalFreedomMod;
|
||||
import me.totalfreedom.totalfreedommod.admin.AdminList;
|
||||
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
|
||||
import me.totalfreedom.totalfreedommod.discord.command.DiscordCommand;
|
||||
import me.totalfreedom.totalfreedommod.discord.command.DiscordCommandImpl;
|
||||
import me.totalfreedom.totalfreedommod.rank.Displayable;
|
||||
import me.totalfreedom.totalfreedommod.rank.RankManager;
|
||||
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||
import net.dv8tion.jda.api.EmbedBuilder;
|
||||
import net.dv8tion.jda.api.MessageBuilder;
|
||||
import net.dv8tion.jda.api.entities.Guild;
|
||||
import net.dv8tion.jda.api.entities.Member;
|
||||
import net.dv8tion.jda.api.entities.User;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class ListCommand extends DiscordCommandImpl
|
||||
{
|
||||
private static final TotalFreedomMod PLUGIN = TotalFreedomMod.plugin();
|
||||
|
||||
@Override
|
||||
public String getCommandName()
|
||||
{
|
||||
return "list";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription()
|
||||
{
|
||||
return "Gives a list of online players.";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCategory()
|
||||
{
|
||||
return "Server Commands";
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getAliases()
|
||||
{
|
||||
return List.of("online", "who", "l", "lsit");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAdmin()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MessageBuilder execute(Member member, List<String> args)
|
||||
{
|
||||
if (PLUGIN == null)
|
||||
{
|
||||
throw new IllegalStateException("TotalFreedomMod somehow null while executing a command!");
|
||||
}
|
||||
|
||||
final AdminList adminList = PLUGIN.al;
|
||||
final RankManager rankManager = PLUGIN.rm;
|
||||
|
||||
EmbedBuilder embedBuilder = new EmbedBuilder()
|
||||
.setTitle("Player List - " + ConfigEntry.SERVER_NAME.getString())
|
||||
.setDescription("There are " + FUtil.getFakePlayerCount() + " / " + Bukkit.getMaxPlayers() + " online players");
|
||||
|
||||
Map<Displayable, List<String>> displayables = new HashMap<>();
|
||||
|
||||
for (Player onlinePlayer : Bukkit.getOnlinePlayers())
|
||||
{
|
||||
if (adminList.isVanished(onlinePlayer.getName()))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
Displayable displayable = rankManager.getDisplay(onlinePlayer);
|
||||
|
||||
if (displayables.containsKey(displayable))
|
||||
{
|
||||
displayables.get(displayable).add(onlinePlayer.getName());
|
||||
}
|
||||
else
|
||||
{
|
||||
displayables.put(displayable, new ArrayList<>(List.of(onlinePlayer.getName())));
|
||||
}
|
||||
}
|
||||
|
||||
for (Map.Entry<Displayable, List<String>> entry : displayables.entrySet())
|
||||
{
|
||||
final Displayable displayable = entry.getKey();
|
||||
final List<String> players = entry.getValue();
|
||||
|
||||
embedBuilder.addField(displayable.getPlural() + " (" + players.size() + ")",
|
||||
String.join(", ", players), false);
|
||||
}
|
||||
|
||||
return new MessageBuilder().setEmbed(embedBuilder.build());
|
||||
}
|
||||
}
|
@ -0,0 +1,60 @@
|
||||
package me.totalfreedom.totalfreedommod.discord.commands;
|
||||
|
||||
import me.totalfreedom.totalfreedommod.discord.command.DiscordCommand;
|
||||
import me.totalfreedom.totalfreedommod.discord.command.DiscordCommandImpl;
|
||||
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||
import net.dv8tion.jda.api.EmbedBuilder;
|
||||
import net.dv8tion.jda.api.MessageBuilder;
|
||||
import net.dv8tion.jda.api.entities.Member;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Server;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class TPSCommand extends DiscordCommandImpl
|
||||
{
|
||||
@Override
|
||||
public String getCommandName()
|
||||
{
|
||||
return "tps";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription()
|
||||
{
|
||||
return "Lag information regarding the server.";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCategory()
|
||||
{
|
||||
return "Server Commands";
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getAliases()
|
||||
{
|
||||
return Collections.singletonList("lag");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAdmin()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MessageBuilder execute(Member member, List<String> args)
|
||||
{
|
||||
final EmbedBuilder builder = new EmbedBuilder();
|
||||
builder.setTitle("Server lag information");
|
||||
builder.addField("TPS", String.valueOf(Math.round(FUtil.getMeanAverageDouble(Bukkit.getServer().getTPS()))), false);
|
||||
builder.addField("Uptime", FUtil.getUptime(), false);
|
||||
builder.addField("Maximum Memory", Math.ceil(FUtil.getMaxMem()) + " MB", false);
|
||||
builder.addField("Allocated Memory", Math.ceil(FUtil.getTotalMem()) + " MB", false);
|
||||
builder.addField("Free Memory", Math.ceil(FUtil.getFreeMem()) + " MB", false);
|
||||
|
||||
return new MessageBuilder().setEmbed(builder.build());
|
||||
}
|
||||
}
|
@ -337,12 +337,12 @@ public abstract class NanoHTTPD
|
||||
*/
|
||||
protected String decodePercent(String str)
|
||||
{
|
||||
String decoded = null;
|
||||
String decoded = str;
|
||||
try
|
||||
{
|
||||
decoded = URLDecoder.decode(str, "UTF8");
|
||||
}
|
||||
catch (UnsupportedEncodingException ignored)
|
||||
catch (UnsupportedEncodingException | IllegalArgumentException ignored)
|
||||
{
|
||||
}
|
||||
return decoded;
|
||||
|
@ -16,6 +16,7 @@ import org.bukkit.scheduler.BukkitTask;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
public class FPlayer
|
||||
{
|
||||
@ -26,7 +27,7 @@ public class FPlayer
|
||||
private final TotalFreedomMod plugin;
|
||||
|
||||
private final String name;
|
||||
|
||||
private final UUID uuid;
|
||||
private final String ip;
|
||||
//
|
||||
private final FreezeData freezeData = new FreezeData(this);
|
||||
@ -70,12 +71,13 @@ public class FPlayer
|
||||
|
||||
public FPlayer(TotalFreedomMod plugin, Player player)
|
||||
{
|
||||
this(plugin, player.getName(), FUtil.getIp(player));
|
||||
this(plugin, player.getUniqueId(), player.getName(), FUtil.getIp(player));
|
||||
}
|
||||
|
||||
private FPlayer(TotalFreedomMod plugin, String name, String ip)
|
||||
private FPlayer(TotalFreedomMod plugin, UUID uuid, String name, String ip)
|
||||
{
|
||||
this.plugin = plugin;
|
||||
this.uuid = uuid;
|
||||
this.name = name;
|
||||
this.ip = ip;
|
||||
}
|
||||
@ -94,14 +96,7 @@ public class FPlayer
|
||||
|
||||
if (player == null)
|
||||
{
|
||||
for (Player onlinePlayer : Bukkit.getOnlinePlayers())
|
||||
{
|
||||
if (FUtil.getIp(onlinePlayer).equals(ip))
|
||||
{
|
||||
player = onlinePlayer;
|
||||
break;
|
||||
}
|
||||
}
|
||||
player = Bukkit.getPlayer(uuid);
|
||||
}
|
||||
|
||||
return player;
|
||||
@ -112,6 +107,14 @@ public class FPlayer
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
// Ensure admins don't have admin functionality when removed (FS-222)
|
||||
public void removeAdminFunctionality()
|
||||
{
|
||||
this.setCommandSpy(false);
|
||||
this.setAdminChat(false);
|
||||
this.setFuckoffRadius(0);
|
||||
}
|
||||
|
||||
public boolean isOrbiting()
|
||||
{
|
||||
return isOrbiting;
|
||||
|
@ -17,7 +17,7 @@ import org.bukkit.entity.Player;
|
||||
public class PlayerList extends FreedomService
|
||||
{
|
||||
|
||||
public final Map<String, FPlayer> playerMap = Maps.newHashMap(); // ip,dataMap
|
||||
public final Map<UUID, FPlayer> playerMap = Maps.newHashMap(); // uuid, dataMap
|
||||
public final Map<UUID, PlayerData> dataMap = Maps.newHashMap(); // uuid, data
|
||||
|
||||
@Override
|
||||
@ -107,14 +107,14 @@ public class PlayerList extends FreedomService
|
||||
// May not return null
|
||||
public FPlayer getPlayer(Player player)
|
||||
{
|
||||
FPlayer tPlayer = playerMap.get(FUtil.getIp(player));
|
||||
FPlayer tPlayer = playerMap.get(player.getUniqueId());
|
||||
if (tPlayer != null)
|
||||
{
|
||||
return tPlayer;
|
||||
}
|
||||
|
||||
tPlayer = new FPlayer(plugin, player);
|
||||
playerMap.put(FUtil.getIp(player), tPlayer);
|
||||
playerMap.put(player.getUniqueId(), tPlayer);
|
||||
|
||||
return tPlayer;
|
||||
}
|
||||
@ -233,7 +233,7 @@ public class PlayerList extends FreedomService
|
||||
return player;
|
||||
}
|
||||
|
||||
public Map<String, FPlayer> getPlayerMap()
|
||||
public Map<UUID, FPlayer> getPlayerMap()
|
||||
{
|
||||
return playerMap;
|
||||
}
|
||||
|
@ -13,6 +13,8 @@ public interface Displayable
|
||||
|
||||
String getAbbr();
|
||||
|
||||
String getPlural();
|
||||
|
||||
ChatColor getColor();
|
||||
|
||||
org.bukkit.ChatColor getTeamColor();
|
||||
|
@ -4,19 +4,19 @@ import net.md_5.bungee.api.ChatColor;
|
||||
|
||||
public enum Rank implements Displayable
|
||||
{
|
||||
NON_OP("a", "Non-Op", Type.PLAYER, "", ChatColor.WHITE, null, false, false),
|
||||
OP("an", "Operator", Type.PLAYER, "OP", ChatColor.GREEN, null, false, false),
|
||||
ADMIN("an", "Admin", Type.ADMIN, "Admin", ChatColor.DARK_GREEN, org.bukkit.ChatColor.DARK_GREEN, true, true),
|
||||
SENIOR_ADMIN("a", "Senior Admin", Type.ADMIN, "SrA", ChatColor.GOLD, org.bukkit.ChatColor.GOLD, true, true),
|
||||
ADMIN_CONSOLE("the", "Console", Type.ADMIN_CONSOLE, "Console", ChatColor.DARK_PURPLE, null, false, false),
|
||||
SENIOR_CONSOLE("the", "Console", Type.ADMIN_CONSOLE, "Console", ChatColor.DARK_PURPLE, null, false, false);
|
||||
NON_OP("a", "Non-Op", Type.PLAYER, "", "Non-Ops", ChatColor.WHITE, null, false, false),
|
||||
OP("an", "Operator", Type.PLAYER, "OP", "Operators", ChatColor.GREEN, null, false, false),
|
||||
ADMIN("an", "Admin", Type.ADMIN, "Admin", "Administrators", ChatColor.DARK_GREEN, org.bukkit.ChatColor.DARK_GREEN, true, true),
|
||||
SENIOR_ADMIN("a", "Senior Admin", Type.ADMIN, "SrA", "Senior Administrators", ChatColor.GOLD, org.bukkit.ChatColor.GOLD, true, true),
|
||||
ADMIN_CONSOLE("the", "Console", Type.ADMIN_CONSOLE, "Console", "Administrator Consoles", ChatColor.DARK_PURPLE, null, false, false),
|
||||
SENIOR_CONSOLE("the", "Console", Type.ADMIN_CONSOLE, "Console", "Senior Consoles", ChatColor.DARK_PURPLE, null, false, false);
|
||||
|
||||
private final Type type;
|
||||
|
||||
private final String name;
|
||||
|
||||
private final String abbr;
|
||||
|
||||
private final String plural;
|
||||
private final String article;
|
||||
|
||||
private final String tag;
|
||||
@ -31,11 +31,12 @@ public enum Rank implements Displayable
|
||||
|
||||
private final boolean hasDefaultLoginMessage;
|
||||
|
||||
Rank(String article, String name, Type type, String abbr, ChatColor color, org.bukkit.ChatColor teamColor, Boolean hasTeam, Boolean hasDefaultLoginMessage)
|
||||
Rank(String article, String name, Type type, String abbr, String plural, ChatColor color, org.bukkit.ChatColor teamColor, Boolean hasTeam, Boolean hasDefaultLoginMessage)
|
||||
{
|
||||
this.type = type;
|
||||
this.name = name;
|
||||
this.abbr = abbr;
|
||||
this.plural = plural;
|
||||
this.article = article;
|
||||
this.tag = abbr.isEmpty() ? "" : "[" + abbr + "]";
|
||||
this.coloredTag = abbr.isEmpty() ? "" : ChatColor.DARK_GRAY + "[" + color + abbr + ChatColor.DARK_GRAY + "]" + color;
|
||||
@ -88,6 +89,11 @@ public enum Rank implements Displayable
|
||||
return abbr;
|
||||
}
|
||||
|
||||
public String getPlural()
|
||||
{
|
||||
return plural;
|
||||
}
|
||||
|
||||
public boolean isConsole()
|
||||
{
|
||||
return getType() == Type.ADMIN_CONSOLE;
|
||||
|
@ -9,7 +9,6 @@ import me.totalfreedom.totalfreedommod.player.PlayerData;
|
||||
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
@ -185,6 +184,12 @@ public class RankManager extends FreedomService
|
||||
if (isAdmin)
|
||||
{
|
||||
plugin.al.updateLastLogin(player);
|
||||
} else
|
||||
{
|
||||
// Ensure admins don't have admin functionality when removed (FS-222)
|
||||
FPlayer freedomPlayer = plugin.pl.getPlayer(player);
|
||||
|
||||
freedomPlayer.removeAdminFunctionality();
|
||||
}
|
||||
|
||||
// Broadcast login message
|
||||
|
@ -5,11 +5,11 @@ import net.md_5.bungee.api.ChatColor;
|
||||
public enum Title implements Displayable
|
||||
{
|
||||
|
||||
MASTER_BUILDER("a", "Master Builder", ChatColor.DARK_AQUA, org.bukkit.ChatColor.DARK_AQUA, "MB", true, true),
|
||||
EXECUTIVE("an", "Executive", ChatColor.RED, org.bukkit.ChatColor.RED, "Exec", true, true),
|
||||
ASSTEXEC("an", "Assistant Executive", ChatColor.RED, org.bukkit.ChatColor.RED, "Asst Exec", true, true),
|
||||
DEVELOPER("a", "Developer", ChatColor.DARK_PURPLE, org.bukkit.ChatColor.DARK_PURPLE, "Dev", true, true),
|
||||
OWNER("the", "Owner", ChatColor.DARK_RED, org.bukkit.ChatColor.DARK_RED, "Owner", true, true);
|
||||
MASTER_BUILDER("a", "Master Builder", "Master Builders", ChatColor.DARK_AQUA, org.bukkit.ChatColor.DARK_AQUA, "MB", true, true),
|
||||
EXECUTIVE("an", "Executive", "Executives", ChatColor.RED, org.bukkit.ChatColor.RED, "Exec", true, true),
|
||||
ASSTEXEC("an", "Assistant Executive", "Assistant Executives", ChatColor.RED, org.bukkit.ChatColor.RED, "Asst Exec", true, true),
|
||||
DEVELOPER("a", "Developer", "Developers", ChatColor.DARK_PURPLE, org.bukkit.ChatColor.DARK_PURPLE, "Dev", true, true),
|
||||
OWNER("the", "Owner", "Owners", ChatColor.DARK_RED, org.bukkit.ChatColor.DARK_RED, "Owner", true, true);
|
||||
|
||||
|
||||
private final String article;
|
||||
@ -17,6 +17,7 @@ public enum Title implements Displayable
|
||||
private final String name;
|
||||
|
||||
private final String abbr;
|
||||
private final String plural;
|
||||
|
||||
private final String tag;
|
||||
|
||||
@ -29,10 +30,11 @@ public enum Title implements Displayable
|
||||
private final boolean hasTeam;
|
||||
private final boolean hasDefaultLoginMessage;
|
||||
|
||||
Title(String article, String name, ChatColor color, org.bukkit.ChatColor teamColor, String tag, Boolean hasTeam, Boolean hasDefaultLoginMessage)
|
||||
Title(String article, String name, String plural, ChatColor color, org.bukkit.ChatColor teamColor, String tag, Boolean hasTeam, Boolean hasDefaultLoginMessage)
|
||||
{
|
||||
this.article = article;
|
||||
this.name = name;
|
||||
this.plural = plural;
|
||||
this.coloredTag = ChatColor.DARK_GRAY + "[" + color + tag + ChatColor.DARK_GRAY + "]" + color;
|
||||
this.abbr = tag;
|
||||
this.tag = "[" + tag + "]";
|
||||
@ -84,6 +86,12 @@ public enum Title implements Displayable
|
||||
return abbr;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPlural()
|
||||
{
|
||||
return plural;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTag()
|
||||
{
|
||||
|
@ -152,7 +152,7 @@ public class SQLite extends FreedomService
|
||||
{
|
||||
try
|
||||
{
|
||||
Object[] data = {key, player.getName()};
|
||||
Object[] data = {key, player.getUuid()};
|
||||
PreparedStatement statement = connection.prepareStatement(MessageFormat.format("UPDATE players SET {0}=? WHERE uuid=''{1}''", data));
|
||||
statement = setUnknownType(statement, 1, value);
|
||||
statement.executeUpdate();
|
||||
|
@ -1,16 +1,12 @@
|
||||
package me.totalfreedom.totalfreedommod.util;
|
||||
|
||||
import com.earth2me.essentials.utils.DateUtil;
|
||||
import me.totalfreedom.totalfreedommod.TotalFreedomMod;
|
||||
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.commons.lang.WordUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Color;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -19,10 +15,9 @@ import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
import org.json.simple.JSONArray;
|
||||
|
||||
import java.io.*;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.management.ManagementFactory;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.text.ParseException;
|
||||
@ -55,9 +50,32 @@ public class FUtil
|
||||
"ba5aafba-9012-418f-9819-a7020d591068", // TFTWPhoenix
|
||||
"d6dd9740-40db-45f5-ab16-4ee16a633009", // Abhi
|
||||
"2e06e049-24c8-42e4-8bcf-d35372af31e6", // NotInSync
|
||||
"f97c0d7b-6413-4558-a409-88f09a8f9adb" // videogamesm12
|
||||
"f97c0d7b-6413-4558-a409-88f09a8f9adb", // videogamesm12
|
||||
"78408086-1991-4c33-a571-d8fa325465b2", // Telesphoreo
|
||||
"f5cd54c4-3a24-4213-9a56-c06c49594dff", // Taahh
|
||||
"a52f1f08-a398-400a-bca4-2b74b81feae6", // G6_
|
||||
"ca83b658-c03b-4106-9edc-72f70a80656d" // ayunami2000
|
||||
);
|
||||
public static final List<String> DEVELOPER_NAMES = Arrays.asList("Madgeek1450", "Prozza", "WickedGamingUK", "Wild1145", "aggelosQQ", "scripthead", "CoolJWB", "elmon_", "speednt", "SupItsDillon", "Paldiu", "TFTWPhoenix", "abhithedev", "NotInSync", "videogamesm12");
|
||||
public static final List<String> DEVELOPER_NAMES = Arrays.asList(
|
||||
"Madgeek1450",
|
||||
"Prozza",
|
||||
"WickedGamingUK",
|
||||
"Wild1145",
|
||||
"aggelosQQ",
|
||||
"scripthead",
|
||||
"Telesphoreo",
|
||||
"CoolJWB",
|
||||
"elmon_",
|
||||
"speednt",
|
||||
"SupItsDillon",
|
||||
"Paldiu",
|
||||
"TFTWPhoenix",
|
||||
"abhithedev",
|
||||
"NotInSync",
|
||||
"videogamesm12",
|
||||
"Taahh",
|
||||
"G6_",
|
||||
"ayunami2000");
|
||||
public static final Map<String, ChatColor> CHAT_COLOR_NAMES = new HashMap<>();
|
||||
public static final List<ChatColor> CHAT_COLOR_POOL = Arrays.asList(
|
||||
ChatColor.DARK_RED,
|
||||
@ -550,6 +568,11 @@ public class FUtil
|
||||
return string;
|
||||
}
|
||||
|
||||
public static String stripColors(String string)
|
||||
{
|
||||
return string.replaceAll("§", "");
|
||||
}
|
||||
|
||||
public static Date getUnixDate(long unix)
|
||||
{
|
||||
return new Date(unix);
|
||||
@ -795,6 +818,62 @@ public class FUtil
|
||||
return getServer().getOnlinePlayers().size() - i;
|
||||
}
|
||||
|
||||
public static double getMeanAverageDouble(double[] doubles)
|
||||
{
|
||||
double total = 0;
|
||||
|
||||
for (double aDouble : doubles)
|
||||
{
|
||||
total += aDouble;
|
||||
}
|
||||
|
||||
return total / doubles.length;
|
||||
}
|
||||
|
||||
public static int getMeanAverageInt(int[] ints)
|
||||
{
|
||||
int total = 0;
|
||||
|
||||
for (int anInt : ints)
|
||||
{
|
||||
total += anInt;
|
||||
}
|
||||
|
||||
return total / ints.length;
|
||||
}
|
||||
|
||||
public static long getMeanAverageLong(long[] longs)
|
||||
{
|
||||
long total = 0;
|
||||
|
||||
for (long aLong : longs)
|
||||
{
|
||||
total += aLong;
|
||||
}
|
||||
|
||||
return total / longs.length;
|
||||
}
|
||||
|
||||
public static String getUptime()
|
||||
{
|
||||
return DateUtil.formatDateDiff(ManagementFactory.getRuntimeMXBean().getStartTime());
|
||||
}
|
||||
|
||||
public static double getMaxMem()
|
||||
{
|
||||
return Runtime.getRuntime().maxMemory() / 1024f / 1024f;
|
||||
}
|
||||
|
||||
public static double getTotalMem()
|
||||
{
|
||||
return Runtime.getRuntime().totalMemory() / 1024f / 1024f;
|
||||
}
|
||||
|
||||
public static double getFreeMem()
|
||||
{
|
||||
return Runtime.getRuntime().freeMemory() / 1024f / 1024f;
|
||||
}
|
||||
|
||||
public static class PaginationList<T> extends ArrayList<T>
|
||||
{
|
||||
|
||||
|
@ -58,10 +58,14 @@ server:
|
||||
discord:
|
||||
# If you do not have a token, make a bot account and get one at https://discordapp.com/developers/applications/me
|
||||
token: ''
|
||||
# The prefix for the integrated bot commands
|
||||
prefix: 'tf!'
|
||||
# The official discord server's ID for this server
|
||||
server_id: ''
|
||||
# Channel to send /report messages to
|
||||
report_channel_id: ''
|
||||
# Channel to send archived reports to
|
||||
report_archive_channel_id: ''
|
||||
# Channel for Discord to Minecraft and vice-versa
|
||||
chat_channel_id: ''
|
||||
# Channel for Discord to AdminChat and vice-versa
|
||||
|
@ -14,4 +14,4 @@ softdepend:
|
||||
- JDA
|
||||
- Votifier
|
||||
authors: [Madgeek1450, Prozza]
|
||||
api-version: "1.16"
|
||||
api-version: "1.17"
|
Reference in New Issue
Block a user