mirror of
https://github.com/AtlasMediaGroup/TotalFreedomMod.git
synced 2025-07-01 04:26:42 +00:00
Compare commits
4 Commits
2022.06-RC
...
FS-200
Author | SHA1 | Date | |
---|---|---|---|
f63362a9fb | |||
54b803e09b | |||
9fba895088 | |||
feba260744 |
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@v3
|
||||
uses: actions/checkout@v2
|
||||
|
||||
# Execute Codacy Analysis CLI and generate a SARIF output with the security issues identified during the analysis
|
||||
- name: Run Codacy Analysis CLI
|
||||
uses: codacy/codacy-analysis-cli-action@v4.1.0
|
||||
uses: codacy/codacy-analysis-cli-action@4.0.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@v2
|
||||
uses: github/codeql-action/upload-sarif@v1
|
||||
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@v3
|
||||
uses: actions/checkout@v2
|
||||
|
||||
- name: Setup Java JDK
|
||||
uses: actions/setup-java@v3.3.0
|
||||
uses: actions/setup-java@v2.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@v2
|
||||
uses: github/codeql-action/init@v1
|
||||
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@v2
|
||||
uses: github/codeql-action/autobuild@v1
|
||||
|
||||
# ℹ️ 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@v2
|
||||
uses: github/codeql-action/analyze@v1
|
||||
|
2
.github/workflows/downstream.yml
vendored
2
.github/workflows/downstream.yml
vendored
@ -18,7 +18,7 @@ jobs:
|
||||
steps:
|
||||
# Step 1: run a standard checkout action, provided by github
|
||||
- name: Checkout main
|
||||
uses: actions/checkout@v3
|
||||
uses: actions/checkout@v2
|
||||
with:
|
||||
ref: main
|
||||
# submodules: 'recursive' ### may be needed in your situation
|
||||
|
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@v3
|
||||
- uses: actions/checkout@v1
|
||||
|
||||
# Java 16 Builds
|
||||
- name: Set up JDK 17
|
||||
uses: actions/setup-java@v3.3.0
|
||||
uses: actions/setup-java@v2.3.0
|
||||
with:
|
||||
java-version: 17
|
||||
distribution: 'adopt'
|
||||
|
@ -1,4 +1,4 @@
|
||||
# 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 [](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 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.
|
||||
|
||||
|
17
SECURITY.md
17
SECURITY.md
@ -9,16 +9,16 @@ In terms of plugin releases, our support matrix is as follows:
|
||||
### Actively Supported
|
||||
These versions are currently actively supported by our team, and you should expect security patches where appropriate for these versions.
|
||||
|
||||
| Version | Supported | Support End: |
|
||||
| ------------------- | ---------- | ------------------------------ |
|
||||
| 2022.02 | ✅ | No Earlier than May 2022 |
|
||||
| Version | Supported | Support End: |
|
||||
| ------------------- | ------------------ | ------------------------------ |
|
||||
| 2021.09 | :white_check_mark: | No Earlier than December 2021 |
|
||||
|
||||
### 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.09 | ⚠️ | April 2022 |
|
||||
| Version | Supported | Support End: |
|
||||
| ------------------- | ------------------ | ------------ |
|
||||
| 2021.06 | :white_check_mark: | October 2021 |
|
||||
|
||||
|
||||
### No Longer Supported
|
||||
@ -26,9 +26,8 @@ These versions are no longer supported at all. It is strongly advised to update
|
||||
|
||||
| Version | Supported | Support Ended: |
|
||||
| ------------------- | ------------------ | ------------------- |
|
||||
| 2021.06 | :x: | October 2021 |
|
||||
| 2021.05 | :x: | September 2021 |
|
||||
| 2021.04 | :x: | July 2021 |
|
||||
| 2021.05 | :white_check_mark: | September 2021 |
|
||||
| 2021.04 | :white_check_mark: | 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_17</netbeans.hint.jdkPlatform>
|
||||
<netbeans.hint.jdkPlatform>JDK_11</netbeans.hint.jdkPlatform>
|
||||
<netbeans.checkstyle.format>true</netbeans.checkstyle.format>
|
||||
</properties>
|
||||
</project-shared-configuration>
|
||||
|
87
pom.xml
87
pom.xml
@ -5,7 +5,7 @@
|
||||
|
||||
<groupId>me.totalfreedom</groupId>
|
||||
<artifactId>TotalFreedomMod</artifactId>
|
||||
<version>2022.06-RC1</version>
|
||||
<version>2022.02-RC01</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<properties>
|
||||
@ -39,7 +39,17 @@
|
||||
</scm>
|
||||
|
||||
<repositories>
|
||||
|
||||
|
||||
<repository>
|
||||
<id>jitpack.io</id>
|
||||
<url>https://jitpack.io</url>
|
||||
</repository>
|
||||
|
||||
<repository>
|
||||
<id>networkmanager-repo</id>
|
||||
<url>https://repo.networkmanager.xyz/repository/maven-public/</url>
|
||||
</repository>
|
||||
|
||||
<repository>
|
||||
<id>atlas-nexus-01-totalfreedom-development</id>
|
||||
<url>https://nexus-01.core.atlas-media.co.uk/repository/totalfreedom-development/</url>
|
||||
@ -100,8 +110,8 @@
|
||||
<id>esentialsx-repo</id>
|
||||
<url>https://repo.essentialsx.net/releases/</url>
|
||||
</repository>
|
||||
|
||||
|
||||
|
||||
|
||||
</repositories>
|
||||
|
||||
<dependencies>
|
||||
@ -123,7 +133,7 @@
|
||||
<dependency>
|
||||
<groupId>org.bstats</groupId>
|
||||
<artifactId>bstats-bukkit</artifactId>
|
||||
<version>3.0.0</version>
|
||||
<version>2.2.1</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
@ -151,14 +161,14 @@
|
||||
<dependency>
|
||||
<groupId>com.sk89q.worldedit</groupId>
|
||||
<artifactId>worldedit-bukkit</artifactId>
|
||||
<version>7.2.10</version>
|
||||
<version>7.2.8</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>net.dv8tion</groupId>
|
||||
<artifactId>JDA</artifactId>
|
||||
<version>4.4.0_352</version>
|
||||
<version>4.2.1_255</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
@ -172,14 +182,14 @@
|
||||
<dependency>
|
||||
<groupId>com.sk89q.worldguard</groupId>
|
||||
<artifactId>worldguard-bukkit</artifactId>
|
||||
<version>7.0.7</version>
|
||||
<version>7.0.6</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>io.papermc</groupId>
|
||||
<artifactId>paperlib</artifactId>
|
||||
<version>1.0.7</version>
|
||||
<version>1.0.6</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
@ -189,25 +199,25 @@
|
||||
<version>v1.9</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>net.essentialsx</groupId>
|
||||
<artifactId>EssentialsX</artifactId>
|
||||
<version>2.19.4</version>
|
||||
<version>2.19.0</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.reflections</groupId>
|
||||
<artifactId>reflections</artifactId>
|
||||
<version>0.10.2</version>
|
||||
<version>0.9.12</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.javassist</groupId>
|
||||
<artifactId>javassist</artifactId>
|
||||
<version>3.29.0-GA</version>
|
||||
<version>3.28.0-GA</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
@ -221,7 +231,7 @@
|
||||
<dependency>
|
||||
<groupId>org.jetbrains</groupId>
|
||||
<artifactId>annotations</artifactId>
|
||||
<version>23.0.0</version>
|
||||
<version>22.0.0</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
@ -231,19 +241,50 @@
|
||||
<version>3.1.2</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>org.junit.jupiter</groupId>
|
||||
<artifactId>junit-jupiter</artifactId>
|
||||
<version>5.8.2</version>
|
||||
<version>5.8.0</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>org.eclipse.sisu</groupId>
|
||||
<artifactId>org.eclipse.sisu.inject</artifactId>
|
||||
<version>0.3.5</version>
|
||||
<version>0.3.4</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.github.MilkBowl</groupId>
|
||||
<artifactId>VaultAPI</artifactId>
|
||||
<version>1.7</version>
|
||||
<scope>provided</scope>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.bstats</groupId>
|
||||
<artifactId>bstats</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>nl.chimpgamer.networkmanager</groupId>
|
||||
<artifactId>api</artifactId>
|
||||
<version>2.11.4</version>
|
||||
<scope>provided</scope>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>io.github.slimjar</groupId>
|
||||
<artifactId>slimjar</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.json</groupId>
|
||||
<artifactId>json</artifactId>
|
||||
<version>20220320</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
<pluginRepositories>
|
||||
@ -267,7 +308,7 @@
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.10.1</version>
|
||||
<version>3.8.1</version>
|
||||
<configuration>
|
||||
<outputFileName>TotalFreedomMod.jar</outputFileName>
|
||||
<compilerVersion>17</compilerVersion>
|
||||
@ -321,7 +362,7 @@
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-antrun-plugin</artifactId>
|
||||
<version>3.1.0</version>
|
||||
<version>3.0.0</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>default-cli</id>
|
||||
@ -351,7 +392,7 @@
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>properties-maven-plugin</artifactId>
|
||||
<version>1.1.0</version>
|
||||
<version>1.0.0</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>initialize</phase>
|
||||
@ -371,7 +412,7 @@
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>buildnumber-maven-plugin</artifactId>
|
||||
<version>3.0.0</version>
|
||||
<version>1.4</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>generate-resources</phase>
|
||||
@ -396,7 +437,7 @@
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
<version>3.3.0</version>
|
||||
<version>3.3.1-SNAPSHOT</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
|
@ -175,15 +175,15 @@ public class ChatManager extends FreedomService
|
||||
});
|
||||
}
|
||||
|
||||
public void reportAction(Player reporter, String reportedName, String report)
|
||||
public void reportAction(Player reporter, Player reported, 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);
|
||||
playerMsg(player, ChatColor.RED + "[REPORTS] " + ChatColor.GOLD + reporter.getName() + " has reported " + reported.getName() + " for " + report);
|
||||
}
|
||||
}
|
||||
FLog.info("[REPORTS] " + reporter.getName() + " has reported " + reportedName + " for " + report);
|
||||
FLog.info("[REPORTS] " + reporter.getName() + " has reported " + reported.getName() + " for " + report);
|
||||
}
|
||||
}
|
@ -3,6 +3,7 @@ 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.banning.BanManager;
|
||||
@ -35,6 +36,10 @@ import me.totalfreedom.totalfreedommod.fun.Trailer;
|
||||
import me.totalfreedom.totalfreedommod.httpd.HTTPDaemon;
|
||||
import me.totalfreedom.totalfreedommod.permissions.PermissionConfig;
|
||||
import me.totalfreedom.totalfreedommod.permissions.PermissionManager;
|
||||
import me.totalfreedom.totalfreedommod.permissions.handler.DefaultPermissionHandler;
|
||||
import me.totalfreedom.totalfreedommod.permissions.handler.IPermissionHandler;
|
||||
import me.totalfreedom.totalfreedommod.permissions.handler.NMPermissionHandler;
|
||||
import me.totalfreedom.totalfreedommod.permissions.handler.VaultPermissionHandler;
|
||||
import me.totalfreedom.totalfreedommod.player.PlayerList;
|
||||
import me.totalfreedom.totalfreedommod.punishments.PunishmentList;
|
||||
import me.totalfreedom.totalfreedommod.rank.RankManager;
|
||||
@ -132,6 +137,8 @@ public class TotalFreedomMod extends JavaPlugin
|
||||
public WorldEditBridge web;
|
||||
public WorldGuardBridge wgb;
|
||||
|
||||
public IPermissionHandler permissionHandler;
|
||||
|
||||
public static TotalFreedomMod getPlugin()
|
||||
{
|
||||
return plugin;
|
||||
@ -143,7 +150,7 @@ public class TotalFreedomMod extends JavaPlugin
|
||||
{
|
||||
if (plugin.getName().equalsIgnoreCase(pluginName))
|
||||
{
|
||||
return (TotalFreedomMod)plugin;
|
||||
return (TotalFreedomMod) plugin;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
@ -208,6 +215,20 @@ public class TotalFreedomMod extends JavaPlugin
|
||||
|
||||
// Metrics @ https://bstats.org/plugin/bukkit/TotalFreedomMod/2966
|
||||
new Metrics(this, 2966);
|
||||
|
||||
if (getServer().getPluginManager().isPluginEnabled("NetworkManager"))
|
||||
{
|
||||
FLog.info("Using NetworkManager's permission handling");
|
||||
this.permissionHandler = new NMPermissionHandler(this);
|
||||
} else if (getServer().getPluginManager().isPluginEnabled("Vault"))
|
||||
{
|
||||
FLog.info("Using Vault's permission handling");
|
||||
this.permissionHandler = new VaultPermissionHandler(this);
|
||||
} else
|
||||
{
|
||||
FLog.info("Using Bukkit's native permission handling");
|
||||
this.permissionHandler = new DefaultPermissionHandler();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -255,8 +276,7 @@ public class TotalFreedomMod extends JavaPlugin
|
||||
date = props.getProperty("buildDate", "unknown");
|
||||
// Need to do this or it will display ${git.commit.id.abbrev}
|
||||
head = props.getProperty("buildHead", "unknown").replace("${git.commit.id.abbrev}", "unknown");
|
||||
}
|
||||
catch (Exception ex)
|
||||
} catch (Exception ex)
|
||||
{
|
||||
FLog.severe("Could not load build properties! Did you compile with NetBeans/Maven?");
|
||||
FLog.severe(ex);
|
||||
|
@ -6,13 +6,11 @@ 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
|
||||
@ -159,34 +157,6 @@ 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(getName());
|
||||
|
||||
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);
|
||||
|
@ -2,17 +2,22 @@ package me.totalfreedom.totalfreedommod.admin;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.common.collect.Sets;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import me.totalfreedom.totalfreedommod.FreedomService;
|
||||
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
|
||||
import me.totalfreedom.totalfreedommod.permissions.handler.NMPermissionHandler;
|
||||
import me.totalfreedom.totalfreedommod.permissions.handler.VaultPermissionHandler;
|
||||
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.command.ConsoleCommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class AdminList extends FreedomService
|
||||
@ -55,8 +60,7 @@ public class AdminList extends FreedomService
|
||||
allAdmins.add(admin);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (SQLException e)
|
||||
} catch (SQLException e)
|
||||
{
|
||||
FLog.severe("Failed to load admin list: " + e.getMessage());
|
||||
}
|
||||
@ -110,7 +114,7 @@ public class AdminList extends FreedomService
|
||||
return true;
|
||||
}
|
||||
|
||||
Admin admin = getAdmin((Player)sender);
|
||||
Admin admin = getAdmin((Player) sender);
|
||||
|
||||
return admin != null && admin.isActive();
|
||||
}
|
||||
@ -121,28 +125,48 @@ public class AdminList extends FreedomService
|
||||
{
|
||||
return true;
|
||||
}
|
||||
if (plugin.permissionHandler instanceof NMPermissionHandler || plugin.permissionHandler instanceof VaultPermissionHandler)
|
||||
{
|
||||
// FLog.debug("Using " + plugin.permissionHandler.getClass().getSimpleName() + " for AdminList#isAdmin");
|
||||
return plugin.permissionHandler.inGroup(player, ConfigEntry.PERMISSIONS_GROUPS_ADMIN.getString());
|
||||
}
|
||||
// FLog.debug("AdminList#isAdmin: Returning false because there is no permissions plugin that supports groups on the server");
|
||||
return false;
|
||||
|
||||
Admin admin = getAdmin(player);
|
||||
/*Admin admin = getAdmin(player);
|
||||
|
||||
return admin != null && admin.isActive();
|
||||
return admin != null && admin.isActive();*/
|
||||
}
|
||||
|
||||
public boolean isSeniorAdmin(CommandSender sender)
|
||||
{
|
||||
Admin admin = getAdmin(sender);
|
||||
//TODO: BukkitTelnet checks, but fuck that plugin
|
||||
if (sender instanceof ConsoleCommandSender)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
if (sender instanceof Player player && (plugin.permissionHandler instanceof NMPermissionHandler || plugin.permissionHandler instanceof VaultPermissionHandler))
|
||||
{
|
||||
// FLog.debug("Using " + plugin.permissionHandler.getClass().getSimpleName() + " for AdminList#isSeniorAdmin");
|
||||
return plugin.permissionHandler.inGroup(player, ConfigEntry.PERMISSIONS_GROUPS_SENIOR.getString());
|
||||
}
|
||||
// FLog.debug("AdminList#isSeniorAdmin: Returning false because there is no permissions plugin that supports groups on the server");
|
||||
return false;
|
||||
// return plugin.permissionHandler.hasPermission(sender, "totalfreedommod.admin");
|
||||
/*Admin admin = getAdmin(sender);
|
||||
if (admin == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return admin.getRank().ordinal() >= Rank.SENIOR_ADMIN.ordinal();
|
||||
return admin.getRank().ordinal() >= Rank.SENIOR_ADMIN.ordinal();*/
|
||||
}
|
||||
|
||||
public Admin getAdmin(CommandSender sender)
|
||||
{
|
||||
if (sender instanceof Player)
|
||||
{
|
||||
return getAdmin((Player)sender);
|
||||
return getAdmin((Player) sender);
|
||||
}
|
||||
|
||||
return getEntryByName(sender.getName());
|
||||
@ -271,13 +295,13 @@ public class AdminList extends FreedomService
|
||||
ResultSet currentSave = plugin.sql.getAdminByUuid(admin.getUuid());
|
||||
for (Map.Entry<String, Object> entry : admin.toSQLStorable().entrySet())
|
||||
{
|
||||
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)
|
||||
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)
|
||||
{
|
||||
plugin.sql.setAdminValue(admin, entry.getKey(), entry.getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (SQLException e)
|
||||
} catch (SQLException e)
|
||||
{
|
||||
FLog.severe("Failed to save admin: " + e.getMessage());
|
||||
}
|
||||
|
@ -5,8 +5,6 @@ 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;
|
||||
@ -81,33 +79,9 @@ 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;
|
||||
}
|
||||
|
||||
|
@ -10,9 +10,12 @@ public @interface CommandPermissions
|
||||
|
||||
Rank level() default Rank.NON_OP;
|
||||
|
||||
String permission() default "";
|
||||
|
||||
SourceType source() default SourceType.BOTH;
|
||||
|
||||
boolean blockHostConsole() default false;
|
||||
|
||||
int cooldown() default 0;
|
||||
|
||||
}
|
@ -4,7 +4,6 @@ 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;
|
||||
@ -23,40 +22,36 @@ public class Command_report extends FreedomCommand
|
||||
}
|
||||
|
||||
Player player = getPlayer(args[0], true);
|
||||
OfflinePlayer offlinePlayer = getOfflinePlayer(args[0]);
|
||||
|
||||
if (player == null && offlinePlayer == null)
|
||||
if (player == null)
|
||||
{
|
||||
msg(PLAYER_NOT_FOUND);
|
||||
return true;
|
||||
}
|
||||
else if (player != null)
|
||||
{
|
||||
if (sender instanceof Player)
|
||||
{
|
||||
if (player.equals(playerSender))
|
||||
{
|
||||
msg(ChatColor.RED + "Please, don't try to report yourself.");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if (plugin.al.isAdmin(player))
|
||||
if (sender instanceof Player)
|
||||
{
|
||||
if (player.equals(playerSender))
|
||||
{
|
||||
msg(ChatColor.RED + "You can not report admins.");
|
||||
msg(ChatColor.RED + "Please, don't try to report yourself.");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if (plugin.al.isAdmin(player))
|
||||
{
|
||||
msg(ChatColor.RED + "You can not report admins.");
|
||||
return true;
|
||||
}
|
||||
|
||||
String report = StringUtils.join(ArrayUtils.subarray(args, 1, args.length), " ");
|
||||
plugin.cm.reportAction(playerSender, (player == null) ? offlinePlayer.getName() : player.getName(), report);
|
||||
plugin.cm.reportAction(playerSender, player, report);
|
||||
|
||||
boolean logged = false;
|
||||
|
||||
if (plugin.dc.enabled)
|
||||
{
|
||||
logged = (player == null) ? plugin.dc.sendReportOffline(playerSender, offlinePlayer, report) : plugin.dc.sendReport(playerSender, player, report);
|
||||
logged = plugin.dc.sendReport(playerSender, player, report);
|
||||
}
|
||||
|
||||
msg(ChatColor.GREEN + "Thank you, your report has been successfully logged."
|
||||
|
@ -240,9 +240,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]);
|
||||
String adminName = admin.getName();
|
||||
|
||||
if (admin == null)
|
||||
{
|
||||
@ -255,15 +253,15 @@ public class Command_saconfig extends FreedomCommand
|
||||
|
||||
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(adminName).getDiscordID());
|
||||
Discord.syncRoles(admin, plugin.pl.getData(admin.getName()).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" + "**", true);
|
||||
plugin.dc.messageChatChannel("**" + playerSender.getName() + " joined the server" + "**");
|
||||
}
|
||||
|
||||
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" + "**", true);
|
||||
plugin.dc.messageChatChannel("**" + playerSender.getName() + " left the server" + "**");
|
||||
}
|
||||
|
||||
FLog.info(playerSender.getName() + " is now vanished.");
|
||||
|
@ -1,10 +1,14 @@
|
||||
package me.totalfreedom.totalfreedommod.command;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.*;
|
||||
|
||||
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 me.totalfreedom.totalfreedommod.TotalFreedomMod;
|
||||
import me.totalfreedom.totalfreedommod.admin.Admin;
|
||||
import me.totalfreedom.totalfreedommod.player.PlayerData;
|
||||
@ -14,14 +18,12 @@ 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
|
||||
{
|
||||
@ -41,6 +43,8 @@ public abstract class FreedomCommand implements CommandExecutor, TabCompleter
|
||||
private final String usage;
|
||||
private final String aliases;
|
||||
private final Rank level;
|
||||
|
||||
private final String permission;
|
||||
private final SourceType source;
|
||||
private final boolean blockHostConsole;
|
||||
private final int cooldown;
|
||||
@ -57,6 +61,7 @@ public abstract class FreedomCommand implements CommandExecutor, TabCompleter
|
||||
this.usage = params.usage();
|
||||
this.aliases = params.aliases();
|
||||
this.level = perms.level();
|
||||
this.permission = perms.permission().isEmpty() ? "totalfreedommod." + this.name.toLowerCase() : perms.permission();
|
||||
this.source = perms.source();
|
||||
this.blockHostConsole = perms.blockHostConsole();
|
||||
this.cooldown = perms.cooldown();
|
||||
@ -160,8 +165,65 @@ public abstract class FreedomCommand implements CommandExecutor, TabCompleter
|
||||
}
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
protected void checkRank(@Deprecated Rank rank, String permission)
|
||||
{
|
||||
//TODO: Not bothering with BukkitTelnet now.
|
||||
if (sender instanceof Player player)
|
||||
{
|
||||
if (!plugin.permissionHandler.hasPermission(player, permission))
|
||||
{
|
||||
noPerms();
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (!plugin.rm.getRank(sender).isAtLeast(rank))
|
||||
{
|
||||
noPerms();
|
||||
}
|
||||
}
|
||||
protected void checkPermissions(String permission)
|
||||
{
|
||||
//TODO: Not bothering with BukkitTelnet now.
|
||||
if (sender instanceof Player player)
|
||||
{
|
||||
if (!plugin.permissionHandler.hasPermission(player, permission))
|
||||
{
|
||||
noPerms();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected boolean checkPermissionsSilent(String permission)
|
||||
{
|
||||
//TODO: Not bothering with BukkitTelnet now.
|
||||
// FLog.debug("Using checkPermissionsSilent");
|
||||
if (sender instanceof ConsoleCommandSender)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
if (sender instanceof Player player)
|
||||
{
|
||||
// FLog.debug("Checking player permission for " + player.getUniqueId() + " - " + permission);
|
||||
return plugin.permissionHandler.hasPermission(player, permission);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
protected void checkRank(Rank rank)
|
||||
{
|
||||
// FLog.debug("Using checkRank");
|
||||
//TODO: Not bothering with BukkitTelnet now.
|
||||
if (sender instanceof Player player)
|
||||
{
|
||||
// FLog.debug("Checking player permission for " + player.getUniqueId() + " - " + this.permission);
|
||||
if (!plugin.permissionHandler.hasPermission(player, this.permission))
|
||||
{
|
||||
noPerms();
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (!plugin.rm.getRank(sender).isAtLeast(rank))
|
||||
{
|
||||
noPerms();
|
||||
@ -227,16 +289,6 @@ 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);
|
||||
@ -373,7 +425,15 @@ public abstract class FreedomCommand implements CommandExecutor, TabCompleter
|
||||
|
||||
public boolean func2()
|
||||
{
|
||||
if (!plugin.rm.getRank(sender).isAtLeast(perms.level()))
|
||||
/*if (!plugin.rm.getRank(sender).isAtLeast(perms.level()))
|
||||
{
|
||||
msg(NO_PERMISSION);
|
||||
return true;
|
||||
}*/
|
||||
|
||||
FLog.debug("Result of check perms: " + (!checkPermissionsSilent(cmd.permission)));
|
||||
|
||||
if (!checkPermissionsSilent(cmd.permission))
|
||||
{
|
||||
msg(NO_PERMISSION);
|
||||
return true;
|
||||
|
@ -73,10 +73,12 @@ public enum ConfigEntry
|
||||
SERVER_WHITELIST_MOTD(String.class, "server.motds.whitelist"),
|
||||
SERVER_FULL_MOTD(String.class, "server.motds.full"),
|
||||
//
|
||||
|
||||
PERMISSIONS_GROUPS_ADMIN(String.class, "permissions.groups.admin"),
|
||||
PERMISSIONS_GROUPS_SENIOR(String.class, "permissions.groups.senior_admin"),
|
||||
PERMISSIONS_GROUPS_DEFAULT(String.class, "permissions.groups.default"),
|
||||
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,12 +13,9 @@ 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;
|
||||
@ -40,14 +37,9 @@ 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;
|
||||
@ -61,11 +53,9 @@ 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)
|
||||
@ -156,9 +146,6 @@ 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)
|
||||
{
|
||||
@ -181,7 +168,6 @@ public class Discord extends FreedomService
|
||||
.addEventListeners(new PrivateMessageListener(),
|
||||
new DiscordToMinecraftListener(),
|
||||
new DiscordToAdminChatListener(),
|
||||
new MessageReactionListener(),
|
||||
new ListenerAdapter()
|
||||
{
|
||||
@Override
|
||||
@ -229,7 +215,7 @@ public class Discord extends FreedomService
|
||||
}
|
||||
}
|
||||
sentMessages.clear();
|
||||
messageChatChannel("**Message queue cleared**", true);
|
||||
messageChatChannel("**Message queue cleared**");
|
||||
}
|
||||
|
||||
public void sendPteroInfo(PlayerData playerData, String username, String password)
|
||||
@ -260,7 +246,13 @@ public class Discord extends FreedomService
|
||||
|
||||
public String generateCode(int size)
|
||||
{
|
||||
return RandomStringUtils.randomNumeric(size);
|
||||
StringBuilder code = new StringBuilder();
|
||||
SplittableRandom random = new SplittableRandom();
|
||||
for (int i = 0; i < size; i++)
|
||||
{
|
||||
code.append(random.nextInt(10));
|
||||
}
|
||||
return code.toString();
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
@ -273,11 +265,9 @@ public class Discord extends FreedomService
|
||||
return;
|
||||
}
|
||||
|
||||
Component deathMessage = event.deathMessage();
|
||||
|
||||
if (deathMessage != null)
|
||||
if (event.getDeathMessage() != null)
|
||||
{
|
||||
messageChatChannel("**" + PlainTextComponentSerializer.plainText().serialize(deathMessage) + "**", true);
|
||||
messageChatChannel("**" + event.getDeathMessage() + "**");
|
||||
}
|
||||
}
|
||||
|
||||
@ -292,7 +282,7 @@ public class Discord extends FreedomService
|
||||
{
|
||||
if (!plugin.al.isVanished(event.getPlayer().getName()))
|
||||
{
|
||||
messageChatChannel("**" + event.getPlayer().getName() + " joined the server" + "**", true);
|
||||
messageChatChannel("**" + event.getPlayer().getName() + " joined the server" + "**");
|
||||
}
|
||||
}
|
||||
|
||||
@ -301,78 +291,69 @@ public class Discord extends FreedomService
|
||||
{
|
||||
if (!plugin.al.isVanished(event.getPlayer().getName()))
|
||||
{
|
||||
messageChatChannel("**" + event.getPlayer().getName() + " left the server" + "**", true);
|
||||
messageChatChannel("**" + event.getPlayer().getName() + " left the server" + "**");
|
||||
}
|
||||
}
|
||||
|
||||
public static String sanitizeChatMessage(String message)
|
||||
{
|
||||
String newMessage = message;
|
||||
|
||||
if (message.contains("@"))
|
||||
{
|
||||
// \u200B is Zero Width Space, invisible on Discord
|
||||
newMessage = message.replaceAll("@", "@\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.replaceAll("§", "");
|
||||
}
|
||||
|
||||
return deformat(newMessage);
|
||||
}
|
||||
|
||||
public void messageChatChannel(String message)
|
||||
{
|
||||
messageChatChannel(message, false);
|
||||
}
|
||||
|
||||
public void messageChatChannel(String message, boolean system)
|
||||
{
|
||||
String chat_channel_id = ConfigEntry.DISCORD_CHAT_CHANNEL_ID.getString();
|
||||
if (message.contains("@everyone") || message.contains("@here"))
|
||||
{
|
||||
message = StringUtils.remove(message, "@");
|
||||
}
|
||||
|
||||
String sanitizedMessage = (system) ? message : sanitizeChatMessage(message);
|
||||
if (message.toLowerCase().contains("discord.gg"))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (message.contains("§"))
|
||||
{
|
||||
message = StringUtils.remove(message, "§");
|
||||
}
|
||||
|
||||
if (sanitizedMessage.isBlank()) return;
|
||||
|
||||
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 (enabled && !chat_channel_id.isEmpty())
|
||||
{
|
||||
CompletableFuture<Message> sentMessage = Objects.requireNonNull(bot.getTextChannelById(chat_channel_id)).sendMessage(sanitizedMessage).submit(true);
|
||||
CompletableFuture<Message> sentMessage = Objects.requireNonNull(bot.getTextChannelById(chat_channel_id)).sendMessage(deformat(message)).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();
|
||||
|
||||
String sanitizedMessage = sanitizeChatMessage(message);
|
||||
|
||||
if (sanitizedMessage.isBlank()) return;
|
||||
|
||||
if (enabled && !chat_channel_id.isEmpty())
|
||||
if (message.contains("@everyone") || message.contains("@here"))
|
||||
{
|
||||
CompletableFuture<Message> sentMessage = Objects.requireNonNull(bot.getTextChannelById(chat_channel_id)).sendMessage(sanitizedMessage).submit(true);
|
||||
sentMessages.add(sentMessage);
|
||||
message = StringUtils.remove(message, "@");
|
||||
}
|
||||
|
||||
if (message.toLowerCase().contains("discord.gg"))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
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 (enabled && !chat_channel_id.isEmpty())
|
||||
@ -385,7 +366,7 @@ public class Discord extends FreedomService
|
||||
public String formatBotTag()
|
||||
{
|
||||
SelfUser user = bot.getSelfUser();
|
||||
return user.getAsTag();
|
||||
return user.getName() + "#" + user.getDiscriminator();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -393,18 +374,18 @@ public class Discord extends FreedomService
|
||||
{
|
||||
if (bot != null)
|
||||
{
|
||||
messageChatChannel("**Server has stopped**", true);
|
||||
messageChatChannel("**Server has stopped**");
|
||||
}
|
||||
|
||||
FLog.info("Discord integration has successfully shutdown.");
|
||||
}
|
||||
|
||||
public static String deformat(String input)
|
||||
public String deformat(String input)
|
||||
{
|
||||
return input.replaceAll("([_\\\\`*>|])", "\\\\$1");
|
||||
return input.replace("_", "\\_");
|
||||
}
|
||||
|
||||
public boolean shouldISendReport()
|
||||
public boolean sendReport(Player reporter, Player reported, String reason)
|
||||
{
|
||||
if (ConfigEntry.DISCORD_REPORT_CHANNEL_ID.getString().isEmpty())
|
||||
{
|
||||
@ -419,7 +400,6 @@ 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;
|
||||
@ -432,54 +412,7 @@ public class Discord extends FreedomService
|
||||
return false;
|
||||
}
|
||||
|
||||
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()));
|
||||
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 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");
|
||||
@ -494,13 +427,7 @@ public class Discord extends FreedomService
|
||||
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();
|
||||
}
|
||||
|
||||
channel.sendMessage(embed).complete();
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -509,7 +436,7 @@ public class Discord extends FreedomService
|
||||
{
|
||||
public void start()
|
||||
{
|
||||
messageChatChannel("**Server has started**", true);
|
||||
messageChatChannel("**Server has started**");
|
||||
}
|
||||
}
|
||||
}
|
@ -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 me.totalfreedom.totalfreedommod.util.FUtil;
|
||||
import net.dv8tion.jda.api.entities.*;
|
||||
import net.dv8tion.jda.api.entities.Guild;
|
||||
import net.dv8tion.jda.api.entities.Member;
|
||||
import net.dv8tion.jda.api.entities.Message;
|
||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||
import net.dv8tion.jda.api.hooks.ListenerAdapter;
|
||||
import net.md_5.bungee.api.chat.BaseComponent;
|
||||
@ -24,108 +24,77 @@ public class DiscordToMinecraftListener extends ListenerAdapter
|
||||
{
|
||||
public void onMessageReceived(MessageReceivedEvent event)
|
||||
{
|
||||
final String chat_channel_id = ConfigEntry.DISCORD_CHAT_CHANNEL_ID.getString();
|
||||
final MessageChannel genericChannel = event.getChannel();
|
||||
|
||||
if (event.getMember() == null)
|
||||
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))
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (!event.getAuthor().getId().equals(Discord.bot.getSelfUser().getId()))
|
||||
{
|
||||
Member member = event.getMember();
|
||||
String tag = getDisplay(member);
|
||||
Message msg = event.getMessage();
|
||||
|
||||
if (chat_channel_id.isEmpty())
|
||||
{
|
||||
return;
|
||||
}
|
||||
ComponentBuilder emsg = new ComponentBuilder();
|
||||
|
||||
if (event.getAuthor().getId().equals(Discord.bot.getSelfUser().getId()))
|
||||
{
|
||||
return;
|
||||
}
|
||||
// Prefix
|
||||
emsg.append(ChatColor.DARK_GRAY + "[");
|
||||
TextComponent inviteLink = new TextComponent("Discord");
|
||||
inviteLink.setColor(ChatColor.DARK_AQUA.asBungee());
|
||||
inviteLink.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT,
|
||||
new Text("Click here to get the invite link!")));
|
||||
inviteLink.setClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL,
|
||||
ConfigEntry.DISCORD_INVITE_LINK.getString()));
|
||||
emsg.append(inviteLink);
|
||||
emsg.append(ChatColor.DARK_GRAY + "] ", ComponentBuilder.FormatRetention.NONE);
|
||||
|
||||
if (!genericChannel.getId().equals(chat_channel_id))
|
||||
{
|
||||
return;
|
||||
}
|
||||
// Tag (if they have one)
|
||||
if (tag != null)
|
||||
{
|
||||
emsg.append(tag);
|
||||
}
|
||||
|
||||
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();
|
||||
|
||||
// Prefix
|
||||
emsg.append(ChatColor.DARK_GRAY + "[");
|
||||
TextComponent inviteLink = new TextComponent("Discord");
|
||||
inviteLink.setColor(ChatColor.DARK_AQUA.asBungee());
|
||||
inviteLink.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT,
|
||||
new Text("Click here to get the invite link!")));
|
||||
inviteLink.setClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL,
|
||||
ConfigEntry.DISCORD_INVITE_LINK.getString()));
|
||||
emsg.append(inviteLink);
|
||||
emsg.append(ChatColor.DARK_GRAY + "] ", ComponentBuilder.FormatRetention.NONE);
|
||||
|
||||
// Tag (if they have one)
|
||||
if (tag != null)
|
||||
{
|
||||
emsg.append(tag);
|
||||
}
|
||||
|
||||
emsg.append(" ");
|
||||
|
||||
// User
|
||||
TextComponent user = new TextComponent(FUtil.stripColors(member.getEffectiveName()));
|
||||
user.setColor(ChatColor.RED.asBungee());
|
||||
emsg.append(user);
|
||||
|
||||
// Message
|
||||
emsg.append(ChatColor.DARK_GRAY + ": " + ChatColor.RESET
|
||||
+ FUtil.stripColors(msg.getContentDisplay()), ComponentBuilder.FormatRetention.NONE);
|
||||
|
||||
// Attachments
|
||||
if (!msg.getAttachments().isEmpty())
|
||||
{
|
||||
if (!msg.getContentDisplay().isEmpty())
|
||||
emsg.append(" ");
|
||||
|
||||
for (Message.Attachment attachment : msg.getAttachments())
|
||||
{
|
||||
TextComponent media = new TextComponent("[Media] ");
|
||||
media.setColor(ChatColor.YELLOW.asBungee());
|
||||
media.setClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, attachment.getUrl()));
|
||||
media.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new Text(attachment.getUrl())));
|
||||
// User
|
||||
TextComponent user = new TextComponent(ChatColor.stripColor(member.getEffectiveName()));
|
||||
user.setColor(ChatColor.RED.asBungee());
|
||||
emsg.append(user);
|
||||
|
||||
emsg.append(media, ComponentBuilder.FormatRetention.NONE);
|
||||
// Message
|
||||
emsg.append(ChatColor.DARK_GRAY + ": " + ChatColor.RESET
|
||||
+ ChatColor.stripColor(msg.getContentDisplay()), ComponentBuilder.FormatRetention.NONE);
|
||||
|
||||
// Attachments
|
||||
if (!msg.getAttachments().isEmpty())
|
||||
{
|
||||
if (!msg.getContentDisplay().isEmpty())
|
||||
emsg.append(" ");
|
||||
|
||||
for (Message.Attachment attachment : msg.getAttachments())
|
||||
{
|
||||
TextComponent media = new TextComponent("[Media] ");
|
||||
media.setColor(ChatColor.YELLOW.asBungee());
|
||||
media.setClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, attachment.getUrl()));
|
||||
media.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new Text(attachment.getUrl())));
|
||||
|
||||
emsg.append(media, ComponentBuilder.FormatRetention.NONE);
|
||||
}
|
||||
}
|
||||
|
||||
BaseComponent[] components = emsg.create();
|
||||
|
||||
for (Player player : Bukkit.getOnlinePlayers())
|
||||
{
|
||||
if (TotalFreedomMod.getPlugin().pl.getData(player).doesDisplayDiscord())
|
||||
{
|
||||
player.spigot().sendMessage(components);
|
||||
}
|
||||
}
|
||||
|
||||
FLog.info(TextComponent.toLegacyText(components), true);
|
||||
}
|
||||
}
|
||||
|
||||
BaseComponent[] components = emsg.create();
|
||||
|
||||
for (Player player : Bukkit.getOnlinePlayers())
|
||||
{
|
||||
if (TotalFreedomMod.getPlugin().pl.getData(player).doesDisplayDiscord())
|
||||
{
|
||||
player.sendMessage(components);
|
||||
}
|
||||
}
|
||||
|
||||
FLog.info(TextComponent.toLegacyText(components), true);
|
||||
}
|
||||
|
||||
|
||||
public String getDisplay(Member member)
|
||||
{
|
||||
Guild server = Discord.bot.getGuildById(ConfigEntry.DISCORD_SERVER_ID.getString());
|
||||
|
@ -1,68 +0,0 @@
|
||||
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();
|
||||
}
|
||||
}
|
@ -1,25 +0,0 @@
|
||||
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);
|
||||
}
|
@ -1,13 +0,0 @@
|
||||
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();
|
||||
}
|
||||
}
|
@ -1,84 +0,0 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,86 +0,0 @@
|
||||
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());
|
||||
}
|
||||
}
|
@ -1,106 +0,0 @@
|
||||
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());
|
||||
}
|
||||
}
|
@ -1,60 +0,0 @@
|
||||
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());
|
||||
}
|
||||
}
|
@ -1,79 +0,0 @@
|
||||
package me.totalfreedom.totalfreedommod.discord.commands;
|
||||
|
||||
import me.totalfreedom.totalfreedommod.discord.command.DiscordCommandImpl;
|
||||
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 java.awt.*;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.InputStreamReader;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class UptimeCommand extends DiscordCommandImpl
|
||||
{
|
||||
@Override
|
||||
public String getCommandName()
|
||||
{
|
||||
return "uptime";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription()
|
||||
{
|
||||
return "Returns the uptime of the host.";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCategory()
|
||||
{
|
||||
return "Server Commands";
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getAliases()
|
||||
{
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAdmin()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MessageBuilder execute(Member member, List<String> args)
|
||||
{
|
||||
final EmbedBuilder embedBuilder = new EmbedBuilder();
|
||||
|
||||
try
|
||||
{
|
||||
final Process uptimeProcess = Runtime.getRuntime().exec(new String[]{"uptime"});
|
||||
BufferedReader input = new BufferedReader(new InputStreamReader(uptimeProcess.getInputStream()));
|
||||
String line = input.readLine();
|
||||
|
||||
if (line != null)
|
||||
{
|
||||
embedBuilder.setTitle("Host Uptime Information");
|
||||
embedBuilder.setDescription(line.trim());
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new IllegalStateException("No output from uptime command.");
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
FLog.warning("Error while executing uptime Discord command");
|
||||
e.printStackTrace();
|
||||
embedBuilder.setTitle("Command error");
|
||||
embedBuilder.setColor(Color.RED);
|
||||
embedBuilder.setDescription("Something went wrong");
|
||||
}
|
||||
|
||||
return new MessageBuilder().setEmbed(embedBuilder.build());
|
||||
}
|
||||
}
|
@ -337,12 +337,12 @@ public abstract class NanoHTTPD
|
||||
*/
|
||||
protected String decodePercent(String str)
|
||||
{
|
||||
String decoded = str;
|
||||
String decoded = null;
|
||||
try
|
||||
{
|
||||
decoded = URLDecoder.decode(str, "UTF8");
|
||||
}
|
||||
catch (UnsupportedEncodingException | IllegalArgumentException ignored)
|
||||
catch (UnsupportedEncodingException ignored)
|
||||
{
|
||||
}
|
||||
return decoded;
|
||||
|
@ -4,12 +4,16 @@ import me.totalfreedom.totalfreedommod.admin.Admin;
|
||||
import me.totalfreedom.totalfreedommod.admin.AdminList;
|
||||
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
|
||||
import me.totalfreedom.totalfreedommod.httpd.NanoHTTPD;
|
||||
import me.totalfreedom.totalfreedommod.permissions.handler.DefaultPermissionHandler;
|
||||
import me.totalfreedom.totalfreedommod.permissions.handler.IPermissionHandler;
|
||||
import me.totalfreedom.totalfreedommod.util.FLog;
|
||||
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.json.simple.JSONArray;
|
||||
import org.json.simple.JSONObject;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
|
||||
public class Module_list extends HTTPDModule
|
||||
@ -25,7 +29,32 @@ public class Module_list extends HTTPDModule
|
||||
{
|
||||
if (params.get("json") != null && params.get("json").equals("true"))
|
||||
{
|
||||
FLog.debug("Swapping to JSON View!");
|
||||
final JSONObject responseObject = new JSONObject();
|
||||
if (!(plugin.permissionHandler instanceof DefaultPermissionHandler))
|
||||
{
|
||||
FLog.debug("Displaying custom list on HTTPD!");
|
||||
IPermissionHandler handler = plugin.permissionHandler;
|
||||
final JSONObject players = new JSONObject();
|
||||
|
||||
Arrays.stream(handler.getGroups()).forEach(s ->
|
||||
{
|
||||
JSONArray array = new JSONArray();
|
||||
Bukkit.getOnlinePlayers().stream().filter(player -> !plugin.al.isVanished(player.getName())).filter(player -> handler.getPrimaryGroup(player).equalsIgnoreCase(s)).forEach(player ->
|
||||
{
|
||||
array.put(player.getName());
|
||||
});
|
||||
players.put(s.toLowerCase(), array);
|
||||
});
|
||||
|
||||
responseObject.put("players", players);
|
||||
responseObject.put("online", Bukkit.getOnlinePlayers().stream().filter(player -> !plugin.al.isVanished(player.getName())).count());
|
||||
responseObject.put("max", Bukkit.getMaxPlayers());
|
||||
|
||||
final NanoHTTPD.Response response = new NanoHTTPD.Response(NanoHTTPD.Response.Status.OK, NanoHTTPD.MIME_JSON, responseObject.toString(4));
|
||||
response.addHeader("Access-Control-Allow-Origin", "*");
|
||||
return response;
|
||||
}
|
||||
|
||||
final JSONArray owners = new JSONArray();
|
||||
final JSONArray executives = new JSONArray();
|
||||
@ -44,27 +73,27 @@ public class Module_list extends HTTPDModule
|
||||
|
||||
if (plugin.pl.getData(player).isMasterBuilder())
|
||||
{
|
||||
masterbuilders.add(player.getName());
|
||||
masterbuilders.put(player.getName());
|
||||
}
|
||||
|
||||
if (FUtil.DEVELOPER_NAMES.contains(player.getName()))
|
||||
{
|
||||
developers.add(player.getName());
|
||||
developers.put(player.getName());
|
||||
}
|
||||
|
||||
if (ConfigEntry.SERVER_EXECUTIVES.getList().contains(player.getName()) && !FUtil.DEVELOPERS.contains(player.getName()))
|
||||
{
|
||||
executives.add(player.getName());
|
||||
executives.put(player.getName());
|
||||
}
|
||||
|
||||
if (ConfigEntry.SERVER_OWNERS.getList().contains(player.getName()))
|
||||
{
|
||||
owners.add(player.getName());
|
||||
owners.put(player.getName());
|
||||
}
|
||||
|
||||
if (!plugin.al.isAdmin(player) && hasSpecialTitle(player))
|
||||
{
|
||||
operators.add(player.getName());
|
||||
operators.put(player.getName());
|
||||
}
|
||||
|
||||
if (hasSpecialTitle(player) && plugin.al.isAdmin(player) && !plugin.al.isVanished(player.getName()))
|
||||
@ -74,12 +103,12 @@ public class Module_list extends HTTPDModule
|
||||
{
|
||||
case ADMIN:
|
||||
{
|
||||
admins.add(player.getName());
|
||||
admins.put(player.getName());
|
||||
break;
|
||||
}
|
||||
case SENIOR_ADMIN:
|
||||
{
|
||||
senioradmins.add(player.getName());
|
||||
senioradmins.put(player.getName());
|
||||
break;
|
||||
}
|
||||
default:
|
||||
@ -102,11 +131,11 @@ public class Module_list extends HTTPDModule
|
||||
responseObject.put("online", FUtil.getFakePlayerCount());
|
||||
responseObject.put("max", server.getMaxPlayers());
|
||||
|
||||
final NanoHTTPD.Response response = new NanoHTTPD.Response(NanoHTTPD.Response.Status.OK, NanoHTTPD.MIME_JSON, responseObject.toString());
|
||||
|
||||
final NanoHTTPD.Response response = new NanoHTTPD.Response(NanoHTTPD.Response.Status.OK, NanoHTTPD.MIME_JSON, responseObject.toString(4));
|
||||
response.addHeader("Access-Control-Allow-Origin", "*");
|
||||
return response;
|
||||
}
|
||||
else
|
||||
} else
|
||||
{
|
||||
final StringBuilder body = new StringBuilder();
|
||||
|
||||
@ -144,4 +173,5 @@ public class Module_list extends HTTPDModule
|
||||
{
|
||||
return "TotalFreedom - Online Players";
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,61 @@
|
||||
package me.totalfreedom.totalfreedommod.permissions.handler;
|
||||
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
|
||||
/**
|
||||
* @author Taah
|
||||
* @project TotalFreedomMod
|
||||
* @since 9:10 PM [23-05-2022]
|
||||
*/
|
||||
public class DefaultPermissionHandler implements IPermissionHandler
|
||||
{
|
||||
@Override
|
||||
public boolean hasPermission(@NotNull OfflinePlayer player, @Nullable String permission)
|
||||
{
|
||||
if (permission == null)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
throw new UnsupportedOperationException("Unable to use Bukkit's native permission system for permissions!");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPermission(@NotNull Player player, @Nullable String permission)
|
||||
{
|
||||
return permission == null || player.hasPermission(permission);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean inGroup(@NotNull OfflinePlayer player, @Nullable String groupName)
|
||||
{
|
||||
throw new UnsupportedOperationException("Unable to use Bukkit's native permission system for groups!");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean inGroup(@NotNull Player player, @Nullable String groupName)
|
||||
{
|
||||
throw new UnsupportedOperationException("Unable to use Bukkit's native permission system for groups!");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPrimaryGroup(@NotNull Player player)
|
||||
{
|
||||
throw new UnsupportedOperationException("Unable to use Bukkit's native permission system for groups!");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPrefix(@NotNull Player player)
|
||||
{
|
||||
throw new UnsupportedOperationException("Unable to use Bukkit's native permission system for groups!");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getGroups()
|
||||
{
|
||||
throw new UnsupportedOperationException("Unable to use Bukkit's native permission system for groups!");
|
||||
}
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
package me.totalfreedom.totalfreedommod.permissions.handler;
|
||||
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* @author Taah
|
||||
* @project TotalFreedomMod
|
||||
* @since 9:05 PM [23-05-2022]
|
||||
*/
|
||||
public interface IPermissionHandler
|
||||
{
|
||||
boolean hasPermission(@NotNull OfflinePlayer player, @Nullable String permission);
|
||||
boolean hasPermission(@NotNull Player player, @Nullable String permission);
|
||||
|
||||
boolean inGroup(@NotNull OfflinePlayer player, @Nullable String groupName);
|
||||
boolean inGroup(@NotNull Player player, @Nullable String groupName);
|
||||
|
||||
String getPrimaryGroup(@NotNull Player player);
|
||||
|
||||
String getPrefix(@NotNull Player player);
|
||||
|
||||
String[] getGroups();
|
||||
}
|
@ -0,0 +1,150 @@
|
||||
package me.totalfreedom.totalfreedommod.permissions.handler;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import me.totalfreedom.totalfreedommod.TotalFreedomMod;
|
||||
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
|
||||
import me.totalfreedom.totalfreedommod.util.FLog;
|
||||
import net.milkbowl.vault.permission.Permission;
|
||||
import nl.chimpgamer.networkmanager.api.NetworkManagerPlugin;
|
||||
import nl.chimpgamer.networkmanager.api.NetworkManagerProvider;
|
||||
import nl.chimpgamer.networkmanager.api.models.permissions.Group;
|
||||
import nl.chimpgamer.networkmanager.api.models.permissions.PermissionPlayer;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Comparator;
|
||||
|
||||
|
||||
/**
|
||||
* @author Taah
|
||||
* @project TotalFreedomMod
|
||||
* @since 9:10 PM [23-05-2022]
|
||||
*/
|
||||
public class NMPermissionHandler implements IPermissionHandler
|
||||
{
|
||||
private NetworkManagerPlugin plugin;
|
||||
|
||||
public NMPermissionHandler(TotalFreedomMod plugin)
|
||||
{
|
||||
if (plugin.permissionHandler != null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (!Bukkit.getPluginManager().isPluginEnabled("NetworkManager"))
|
||||
{
|
||||
plugin.permissionHandler = new DefaultPermissionHandler();
|
||||
return;
|
||||
}
|
||||
this.plugin = NetworkManagerProvider.get();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPermission(@NotNull OfflinePlayer player, @Nullable String permission)
|
||||
{
|
||||
if (permission == null)
|
||||
{
|
||||
FLog.debug("Permission was null!");
|
||||
return true;
|
||||
}
|
||||
PermissionPlayer permissionPlayer = this.plugin.getPermissionManager().getPermissionPlayer(player.getUniqueId());
|
||||
if (permissionPlayer == null)
|
||||
{
|
||||
FLog.debug("Unable to find permissions player in NetworkManager. Returning false.");
|
||||
return false;
|
||||
}
|
||||
if (permissionPlayer.getAllPermissions() == null)
|
||||
{
|
||||
FLog.debug("Screw you NetworkManager for telling me all the permissions for player is null.");
|
||||
return false;
|
||||
}
|
||||
Boolean has = permissionPlayer.hasPermission(permission);
|
||||
if (has == null)
|
||||
{
|
||||
// FLog.debug("NetworkManager is idiotic and has a chance of returning null on a Boolean object. Returning false.");
|
||||
return false;
|
||||
}
|
||||
// FLog.debug("Player has perm? " + has);
|
||||
// FLog.debug("Player permissions for: " + permissionPlayer.getUuid() + "\n" + new GsonBuilder().setPrettyPrinting().create().toJson(permissionPlayer.getAllPermissions()));
|
||||
// permissionPlayer.getPermissions().forEach(permission1 -> FLog.debug(String.format("%s:%s", permission1.getPermissionString(), permission1.hasExpired())));
|
||||
return has;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPermission(@NotNull Player player, @Nullable String permission)
|
||||
{
|
||||
return hasPermission((OfflinePlayer) player, permission);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean inGroup(@NotNull OfflinePlayer player, @Nullable String groupName)
|
||||
{
|
||||
if (groupName == null)
|
||||
{
|
||||
FLog.debug("NM Perms: Setting permission access to false, group is null");
|
||||
return false;
|
||||
}
|
||||
PermissionPlayer permissionPlayer = this.plugin.getPermissionManager().getPermissionPlayer(player.getUniqueId());
|
||||
if (permissionPlayer == null)
|
||||
{
|
||||
FLog.debug("NM Perms: Setting permission access to false, player not found in NM for '" + player.getUniqueId() + "'");
|
||||
return false;
|
||||
}
|
||||
if (permissionPlayer.getGroups().isEmpty())
|
||||
{
|
||||
FLog.debug("NM Perms: Setting permission access to false, player groups are empty for '" + player.getUniqueId() + "'");
|
||||
return false;
|
||||
}
|
||||
// FLog.debug("Group Name requested for: " + player.getUniqueId() + " - " + groupName);
|
||||
// FLog.debug("Player has? " + (permissionPlayer.getGroups().stream().anyMatch(group -> group.getName().equals(groupName))));
|
||||
// permissionPlayer.getGroups().forEach(group -> FLog.debug("Player group: " + group.getName()));
|
||||
return permissionPlayer.getGroups().stream().anyMatch(group -> group.getName().equals(groupName));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean inGroup(@NotNull Player player, @Nullable String groupName)
|
||||
{
|
||||
return this.inGroup((OfflinePlayer) player, groupName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getGroups()
|
||||
{
|
||||
return this.plugin.getPermissionManager().getGroups().values().stream().map(Group::getName).toArray(String[]::new);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPrimaryGroup(@NotNull Player player)
|
||||
{
|
||||
PermissionPlayer permissionPlayer = this.plugin.getPermissionManager().getPermissionPlayer(player.getUniqueId());
|
||||
if (permissionPlayer == null || permissionPlayer.getPrimaryGroup() == null)
|
||||
{
|
||||
FLog.warning("NM Perms: Couldn't find player's primary group due to them not be found our list");
|
||||
return ConfigEntry.PERMISSIONS_GROUPS_DEFAULT.getString();
|
||||
}
|
||||
// permissionPlayer.getGroups().forEach(group -> FLog.debug(String.format("Group for %s: %s", permissionPlayer.getUuid(), group.getName())));
|
||||
// FLog.debug(String.format("%s Primary Group: %s", permissionPlayer.getUuid(), permissionPlayer.getGroups().stream().sorted(Comparator.comparingInt(Group::getRank)).map(Group::getName).findFirst().orElse(ConfigEntry.PERMISSIONS_GROUPS_DEFAULT.getString())));
|
||||
return permissionPlayer.getGroups().stream().sorted((o1, o2) -> o1.getRank() - o2.getRank()).map(Group::getName).findFirst().orElse(ConfigEntry.PERMISSIONS_GROUPS_DEFAULT.getString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPrefix(@NotNull Player player)
|
||||
{
|
||||
PermissionPlayer permissionPlayer = this.plugin.getPermissionManager().getPermissionPlayer(player.getUniqueId());
|
||||
if (permissionPlayer == null)
|
||||
{
|
||||
FLog.warning("NM Perms: Couldn't find player's primary group due to them not be found our list");
|
||||
return "[Error Loading Player]";
|
||||
}
|
||||
Group group = this.plugin.getPermissionManager().getGroup(getPrimaryGroup(player));
|
||||
if (group == null)
|
||||
{
|
||||
return "[Error Finding Group]";
|
||||
}
|
||||
return group.getPrefix(null);
|
||||
}
|
||||
}
|
@ -0,0 +1,152 @@
|
||||
package me.totalfreedom.totalfreedommod.permissions.handler;
|
||||
|
||||
import me.totalfreedom.totalfreedommod.TotalFreedomMod;
|
||||
import me.totalfreedom.totalfreedommod.util.FLog;
|
||||
import net.milkbowl.vault.chat.Chat;
|
||||
import net.milkbowl.vault.permission.Permission;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
|
||||
/**
|
||||
* @author Taah
|
||||
* @project TotalFreedomMod
|
||||
* @since 9:10 PM [23-05-2022]
|
||||
*/
|
||||
public class VaultPermissionHandler implements IPermissionHandler
|
||||
{
|
||||
private Permission permissions;
|
||||
private Chat chat;
|
||||
|
||||
public VaultPermissionHandler(TotalFreedomMod plugin)
|
||||
{
|
||||
if (plugin.permissionHandler != null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (!Bukkit.getPluginManager().isPluginEnabled("Vault"))
|
||||
{
|
||||
plugin.permissionHandler = new DefaultPermissionHandler();
|
||||
return;
|
||||
}
|
||||
|
||||
this.permissions = setupPerms(plugin);
|
||||
this.chat = setupChat(plugin);
|
||||
|
||||
plugin.permissionHandler = this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPermission(@NotNull OfflinePlayer player, @Nullable String permission)
|
||||
{
|
||||
if (this.permissions == null)
|
||||
{
|
||||
FLog.debug("Can't use Vault permissions system, there is no plugin using Vault permissions.");
|
||||
return true;
|
||||
}
|
||||
return permission == null || this.permissions.playerHas(null, player, permission);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPermission(@NotNull Player player, @Nullable String permission)
|
||||
{
|
||||
if (this.permissions == null)
|
||||
{
|
||||
FLog.debug("Can't use Vault permissions system, there is no plugin using Vault permissions.");
|
||||
return true;
|
||||
}
|
||||
return permission == null || this.permissions.playerHas(player, permission);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean inGroup(@NotNull OfflinePlayer player, @Nullable String groupName)
|
||||
{
|
||||
if (this.permissions == null)
|
||||
{
|
||||
FLog.debug("Can't use Vault permissions system for groups, there is no plugin using Vault permissions.");
|
||||
return true;
|
||||
}
|
||||
if (groupName == null)
|
||||
{
|
||||
FLog.debug("Vault Perms: Group name is null, returning false for group check");
|
||||
return false;
|
||||
}
|
||||
return this.permissions.playerInGroup(null, player, groupName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean inGroup(@NotNull Player player, @Nullable String groupName)
|
||||
{
|
||||
if (this.permissions == null)
|
||||
{
|
||||
FLog.debug("Can't use Vault permissions system for groups, there is no plugin using Vault permissions.");
|
||||
return false;
|
||||
}
|
||||
if (groupName == null)
|
||||
{
|
||||
FLog.debug("Vault Perms: Group name is null, returning false for group check");
|
||||
return false;
|
||||
}
|
||||
return this.permissions.playerInGroup(player, groupName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getGroups()
|
||||
{
|
||||
if (this.permissions == null)
|
||||
{
|
||||
FLog.debug("Can't use Vault permissions system for group listing, there is no plugin using Vault permissions.");
|
||||
return new String[0];
|
||||
}
|
||||
return this.permissions.getGroups();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPrimaryGroup(@NotNull Player player)
|
||||
{
|
||||
return this.permissions.getPrimaryGroup(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPrefix(@NotNull Player player)
|
||||
{
|
||||
if (this.chat == null)
|
||||
{
|
||||
return "[No Chat Plugin]";
|
||||
}
|
||||
return this.chat.getPlayerPrefix(player);
|
||||
}
|
||||
|
||||
public Permission getPermissions()
|
||||
{
|
||||
return permissions;
|
||||
}
|
||||
|
||||
private Permission setupPerms(TotalFreedomMod plugin)
|
||||
{
|
||||
RegisteredServiceProvider<Permission> rsp = Bukkit.getServicesManager().getRegistration(Permission.class);
|
||||
if (rsp == null)
|
||||
{
|
||||
FLog.warning("Switching back to Bukkit's default permissions from Vault's due to no permission system found.");
|
||||
plugin.permissionHandler = new DefaultPermissionHandler();
|
||||
return null;
|
||||
}
|
||||
return rsp.getProvider();
|
||||
}
|
||||
|
||||
private Chat setupChat(TotalFreedomMod plugin)
|
||||
{
|
||||
RegisteredServiceProvider<Chat> rsp = Bukkit.getServicesManager().getRegistration(Chat.class);
|
||||
if (rsp == null)
|
||||
{
|
||||
// FLog.warning("Switching back to Bukkit's default permissions from Vault's due to no permission system found.");
|
||||
// plugin.permissionHandler = new DefaultPermissionHandler();
|
||||
return null;
|
||||
}
|
||||
return rsp.getProvider();
|
||||
}
|
||||
}
|
@ -112,14 +112,6 @@ 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;
|
||||
|
@ -13,8 +13,6 @@ 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, "", "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);
|
||||
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);
|
||||
|
||||
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,12 +31,11 @@ public enum Rank implements Displayable
|
||||
|
||||
private final boolean hasDefaultLoginMessage;
|
||||
|
||||
Rank(String article, String name, Type type, String abbr, String plural, ChatColor color, org.bukkit.ChatColor teamColor, Boolean hasTeam, Boolean hasDefaultLoginMessage)
|
||||
Rank(String article, String name, Type type, String abbr, 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;
|
||||
@ -89,11 +88,6 @@ public enum Rank implements Displayable
|
||||
return abbr;
|
||||
}
|
||||
|
||||
public String getPlural()
|
||||
{
|
||||
return plural;
|
||||
}
|
||||
|
||||
public boolean isConsole()
|
||||
{
|
||||
return getType() == Type.ADMIN_CONSOLE;
|
||||
|
@ -4,11 +4,13 @@ import java.util.Objects;
|
||||
import me.totalfreedom.totalfreedommod.FreedomService;
|
||||
import me.totalfreedom.totalfreedommod.admin.Admin;
|
||||
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
|
||||
import me.totalfreedom.totalfreedommod.permissions.handler.DefaultPermissionHandler;
|
||||
import me.totalfreedom.totalfreedommod.player.FPlayer;
|
||||
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;
|
||||
@ -167,7 +169,12 @@ public class RankManager extends FreedomService
|
||||
fPlayer.setTag(null);
|
||||
player.setPlayerListName(null);
|
||||
}
|
||||
fPlayer.setTag(getTag(player, display.getColoredTag()));
|
||||
if (!(plugin.permissionHandler instanceof DefaultPermissionHandler))
|
||||
{
|
||||
fPlayer.setTag(getTag(player, plugin.permissionHandler.getPrefix(player)));
|
||||
} else {
|
||||
fPlayer.setTag(getTag(player, display.getColoredTag()));
|
||||
}
|
||||
updatePlayerTeam(player);
|
||||
plugin.pem.setPermissions(player);
|
||||
}
|
||||
@ -184,12 +191,6 @@ 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", "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);
|
||||
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);
|
||||
|
||||
|
||||
private final String article;
|
||||
@ -17,7 +17,6 @@ public enum Title implements Displayable
|
||||
private final String name;
|
||||
|
||||
private final String abbr;
|
||||
private final String plural;
|
||||
|
||||
private final String tag;
|
||||
|
||||
@ -30,11 +29,10 @@ public enum Title implements Displayable
|
||||
private final boolean hasTeam;
|
||||
private final boolean hasDefaultLoginMessage;
|
||||
|
||||
Title(String article, String name, String plural, ChatColor color, org.bukkit.ChatColor teamColor, String tag, Boolean hasTeam, Boolean hasDefaultLoginMessage)
|
||||
Title(String article, String name, 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 + "]";
|
||||
@ -86,12 +84,6 @@ public enum Title implements Displayable
|
||||
return abbr;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPlural()
|
||||
{
|
||||
return plural;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTag()
|
||||
{
|
||||
|
@ -1,12 +1,16 @@
|
||||
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.*;
|
||||
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.command.CommandSender;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -15,9 +19,10 @@ 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.management.ManagementFactory;
|
||||
import java.lang.reflect.Field;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.text.ParseException;
|
||||
@ -50,32 +55,9 @@ 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
|
||||
"78408086-1991-4c33-a571-d8fa325465b2", // Telesphoreo
|
||||
"f5cd54c4-3a24-4213-9a56-c06c49594dff", // Taahh
|
||||
"a52f1f08-a398-400a-bca4-2b74b81feae6", // G6_
|
||||
"ca83b658-c03b-4106-9edc-72f70a80656d" // ayunami2000
|
||||
"f97c0d7b-6413-4558-a409-88f09a8f9adb" // 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 List<String> DEVELOPER_NAMES = Arrays.asList("Madgeek1450", "Prozza", "WickedGamingUK", "Wild1145", "aggelosQQ", "scripthead", "CoolJWB", "elmon_", "speednt", "SupItsDillon", "Paldiu", "TFTWPhoenix", "abhithedev", "NotInSync", "videogamesm12");
|
||||
public static final Map<String, ChatColor> CHAT_COLOR_NAMES = new HashMap<>();
|
||||
public static final List<ChatColor> CHAT_COLOR_POOL = Arrays.asList(
|
||||
ChatColor.DARK_RED,
|
||||
@ -568,11 +550,6 @@ public class FUtil
|
||||
return string;
|
||||
}
|
||||
|
||||
public static String stripColors(String string)
|
||||
{
|
||||
return string.replaceAll("§", "");
|
||||
}
|
||||
|
||||
public static Date getUnixDate(long unix)
|
||||
{
|
||||
return new Date(unix);
|
||||
@ -818,62 +795,6 @@ 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>
|
||||
{
|
||||
|
||||
|
@ -54,18 +54,21 @@ server:
|
||||
# What to display at the bottom of the tab list
|
||||
tablist_footer: ''
|
||||
|
||||
# Permissions System
|
||||
permissions:
|
||||
groups:
|
||||
admin: "Administrator"
|
||||
senior_admin: "Senior-Administrator"
|
||||
default: "Guest"
|
||||
|
||||
# Discord
|
||||
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.17"
|
||||
api-version: "1.16"
|
Reference in New Issue
Block a user