Compare commits

..

3 Commits

Author SHA1 Message Date
41331e719d Updates version to 2022.06.1 2023-03-08 19:58:14 -07:00
72c83ba84a Merge pull request #306 from AtlasMediaGroup/critical-exploit-fix
Patches critical exploit in the command blocker
2023-03-08 19:53:51 -07:00
3deaaafb88 Patches critical exploit 2023-03-08 19:52:30 -07:00
25 changed files with 473 additions and 103 deletions

View File

@ -38,7 +38,7 @@ jobs:
uses: actions/checkout@v3
- name: Setup Java JDK
uses: actions/setup-java@v3.6.0
uses: actions/setup-java@v3.3.0
with:
# The Java version to make available on the path. Takes a whole or semver Java version, or 1.x syntax (e.g. 1.8 => Java 8.x). Early access versions can be specified in the form of e.g. 14-ea, 14.0.0-ea, or 14.0.0-ea.28
java-version: 17

43
.github/workflows/downstream.yml vendored Normal file
View File

@ -0,0 +1,43 @@
# This is a basic workflow to help you get started with Actions
name: Downstream Branch Updates
on:
schedule:
- cron: '20 7 * * *'
# scheduled at 07:00 every Monday and Thursday
workflow_dispatch: # click the button on Github repo!
jobs:
sync_with_upstream:
runs-on: ubuntu-latest
name: Sync main with upstream latest
steps:
# Step 1: run a standard checkout action, provided by github
- name: Checkout current development branch
uses: actions/checkout@v2
with:
ref: development
# submodules: 'recursive' ### may be needed in your situation
# Step 2: run this sync action - specify the upstream repo, upstream branch to sync with, and target sync branch
- name: Pull (Fast-Forward) upstream changes
id: sync
uses: aormsby/Fork-Sync-With-Upstream-action@v3.3
with:
upstream_repository: AtlasMediaGroup/TotalFreedomMod
upstream_branch: main
target_branch: development
git_pull_args: --ff-only # optional arg use, defaults to simple 'pull'
# Step 3: Display a message if 'sync' step had new commits (simple test)
- name: Check for new commits
if: steps.sync.outputs.has_new_commits
run: echo "There were new commits."
# Step 4: Print a helpful timestamp for your records (not required, just nice)
- name: Timestamp
run: date

View File

@ -13,7 +13,7 @@ jobs:
# Java 16 Builds
- name: Set up JDK 17
uses: actions/setup-java@v3.6.0
uses: actions/setup-java@v3.3.0
with:
java-version: 17
distribution: 'adopt'

24
pom.xml
View File

@ -5,7 +5,7 @@
<groupId>me.totalfreedom</groupId>
<artifactId>TotalFreedomMod</artifactId>
<version>2022.06</version>
<version>2022.06.1</version>
<packaging>jar</packaging>
<properties>
@ -101,6 +101,7 @@
<url>https://repo.essentialsx.net/releases/</url>
</repository>
</repositories>
<dependencies>
@ -127,8 +128,8 @@
</dependency>
<dependency>
<groupId>me.totalfreedom.scissors</groupId>
<artifactId>scissors-api</artifactId>
<groupId>io.papermc.paper</groupId>
<artifactId>paper-api</artifactId>
<version>1.17.1-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
@ -150,7 +151,7 @@
<dependency>
<groupId>com.sk89q.worldedit</groupId>
<artifactId>worldedit-bukkit</artifactId>
<version>7.2.12</version>
<version>7.2.10</version>
<scope>provided</scope>
</dependency>
@ -192,7 +193,7 @@
<dependency>
<groupId>net.essentialsx</groupId>
<artifactId>EssentialsX</artifactId>
<version>2.19.6</version>
<version>2.19.4</version>
<scope>provided</scope>
</dependency>
@ -206,10 +207,17 @@
<dependency>
<groupId>org.javassist</groupId>
<artifactId>javassist</artifactId>
<version>3.29.1-GA</version>
<version>3.29.0-GA</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>me.totalfreedom</groupId>
<artifactId>tfguilds</artifactId>
<version>2021.06-RC2</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.jetbrains</groupId>
<artifactId>annotations</artifactId>
@ -227,7 +235,7 @@
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>5.9.0</version>
<version>5.8.2</version>
<scope>compile</scope>
</dependency>
@ -388,7 +396,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.4.1</version>
<version>3.3.0</version>
<executions>
<execution>
<phase>package</phase>

View File

@ -136,7 +136,7 @@ public class ChatManager extends FreedomService
event.setFormat(format);
// Send to discord
if (!ConfigEntry.ADMIN_ONLY_MODE.getBoolean() && !Bukkit.hasWhitelist() && !plugin.pl.getPlayer(player).isMuted())
if (!ConfigEntry.ADMIN_ONLY_MODE.getBoolean() && !Bukkit.hasWhitelist() && !plugin.pl.getPlayer(player).isMuted() && !plugin.tfg.inGuildChat(player))
{
plugin.dc.messageChatChannel(player.getName() + " \u00BB " + ChatColor.stripColor(message));
}

View File

@ -0,0 +1,34 @@
package me.totalfreedom.totalfreedommod;
import me.totalfreedom.totalfreedommod.command.Command_sit;
import org.bukkit.entity.ArmorStand;
import org.bukkit.entity.Entity;
import org.bukkit.event.EventHandler;
import org.spigotmc.event.entity.EntityDismountEvent;
public class Sitter extends FreedomService
{
@Override
public void onStart()
{
}
@Override
public void onStop()
{
}
@EventHandler
public void onEntityDismount(EntityDismountEvent e)
{
Entity dm = e.getDismounted();
if (dm instanceof ArmorStand)
{
if (Command_sit.STANDS.contains(dm))
{
Command_sit.STANDS.remove(dm);
dm.remove();
}
}
}
}

View File

@ -19,6 +19,7 @@ import me.totalfreedom.totalfreedommod.bridge.BukkitTelnetBridge;
import me.totalfreedom.totalfreedommod.bridge.CoreProtectBridge;
import me.totalfreedom.totalfreedommod.bridge.EssentialsBridge;
import me.totalfreedom.totalfreedommod.bridge.LibsDisguisesBridge;
import me.totalfreedom.totalfreedommod.bridge.TFGuildsBridge;
import me.totalfreedom.totalfreedommod.bridge.WorldEditBridge;
import me.totalfreedom.totalfreedommod.bridge.WorldGuardBridge;
import me.totalfreedom.totalfreedommod.caging.Cager;
@ -118,6 +119,7 @@ public class TotalFreedomMod extends JavaPlugin
public HTTPDaemon hd;
public WorldRestrictions wr;
public EntityWiper ew;
public Sitter st;
public VanishHandler vh;
public Pterodactyl ptero;
//
@ -126,6 +128,7 @@ public class TotalFreedomMod extends JavaPlugin
public EssentialsBridge esb;
public LibsDisguisesBridge ldb;
public CoreProtectBridge cpb;
public TFGuildsBridge tfg;
public WorldEditBridge web;
public WorldGuardBridge wgb;
@ -311,6 +314,7 @@ public class TotalFreedomMod extends JavaPlugin
pem = new PermissionManager();
gr = new GameRuleHandler();
ew = new EntityWiper();
st = new Sitter();
vh = new VanishHandler();
ptero = new Pterodactyl();
}
@ -338,6 +342,7 @@ public class TotalFreedomMod extends JavaPlugin
cpb = new CoreProtectBridge();
esb = new EssentialsBridge();
ldb = new LibsDisguisesBridge();
tfg = new TFGuildsBridge();
web = new WorldEditBridge();
wgb = new WorldGuardBridge();
}

View File

@ -71,7 +71,7 @@ public class BlockBlocker extends FreedomService
}
case STRUCTURE_BLOCK:
{
if (!ConfigEntry.ALLOW_MASTERBLOCKS.getBoolean())
if (!ConfigEntry.ALLOW_STRUCTURE_BLOCKS.getBoolean())
{
player.sendMessage(ChatColor.GRAY + "Structure blocks are disabled.");
player.getInventory().setItem(player.getInventory().getHeldItemSlot(), new ItemStack(Material.COOKIE, 1));
@ -81,7 +81,7 @@ public class BlockBlocker extends FreedomService
}
case JIGSAW:
{
if (!ConfigEntry.ALLOW_MASTERBLOCKS.getBoolean())
if (!ConfigEntry.ALLOW_JIGSAWS.getBoolean())
{
player.sendMessage(ChatColor.GRAY + "Jigsaws are disabled.");
player.getInventory().setItem(player.getInventory().getHeldItemSlot(), new ItemStack(Material.COOKIE, 1));
@ -89,16 +89,6 @@ public class BlockBlocker extends FreedomService
}
break;
}
case REPEATING_COMMAND_BLOCK:
case CHAIN_COMMAND_BLOCK:
case COMMAND_BLOCK:
if (!ConfigEntry.ALLOW_MASTERBLOCKS.getBoolean())
{
player.sendMessage(ChatColor.GRAY + "Command blocks are disabled.");
player.getInventory().setItem(player.getInventory().getHeldItemSlot(), new ItemStack(Material.COOKIE, 1));
event.setCancelled(true);
}
break;
case GRINDSTONE:
{
if (!ConfigEntry.ALLOW_GRINDSTONES.getBoolean())

View File

@ -4,8 +4,7 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
/* TODO This will have to be changed from com.github.atlasmediagroup.scissors to me.totalfreedom.scissors when we migrate to 1.19 */
import com.github.atlasmediagroup.scissors.event.block.MasterBlockFireEvent;
import io.papermc.paper.event.player.PlayerSignCommandPreprocessEvent;
import me.totalfreedom.totalfreedommod.FreedomService;
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
@ -21,7 +20,15 @@ import org.bukkit.entity.FallingBlock;
import org.bukkit.entity.Tameable;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.block.*;
import org.bukkit.event.block.BlockBurnEvent;
import org.bukkit.event.block.BlockDispenseEvent;
import org.bukkit.event.block.BlockFromToEvent;
import org.bukkit.event.block.BlockGrowEvent;
import org.bukkit.event.block.BlockIgniteEvent;
import org.bukkit.event.block.BlockPhysicsEvent;
import org.bukkit.event.block.BlockPistonExtendEvent;
import org.bukkit.event.block.BlockPistonRetractEvent;
import org.bukkit.event.block.LeavesDecayEvent;
import org.bukkit.event.entity.EntityCombustEvent;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityDeathEvent;
@ -110,28 +117,6 @@ public class EventBlocker extends FreedomService
event.setRadius(ConfigEntry.EXPLOSIVE_RADIUS.getDouble().floatValue());
}
@EventHandler(priority = EventPriority.HIGH)
public void onBlockExplode(BlockExplodeEvent event)
{
if (!ConfigEntry.ALLOW_EXPLOSIONS.getBoolean())
{
event.setCancelled(true);
return;
}
event.setYield(ConfigEntry.EXPLOSIVE_RADIUS.getDouble().floatValue());
}
@EventHandler(priority = EventPriority.HIGHEST)
public void onMasterBlockFire(MasterBlockFireEvent event)
{
if (!ConfigEntry.ALLOW_MASTERBLOCKS.getBoolean())
{
event.setCancelled(true);
event.getAt().getBlock().setType(Material.CAKE);
}
}
@EventHandler(priority = EventPriority.HIGH)
public void onEntityCombust(EntityCombustEvent event)
{

View File

@ -69,17 +69,24 @@ public class InteractBlocker extends FreedomService
private void handleRightClick(PlayerInteractEvent event)
{
final Player player = event.getPlayer();
final Block clickedBlock = event.getClickedBlock();
if (clickedBlock != null && clickedBlock.getType() == Material.RESPAWN_ANCHOR && !ConfigEntry.ALLOW_RESPAWN_ANCHORS.getBoolean())
if (event.getClickedBlock() != null)
{
if (event.getClickedBlock().getType().equals(Material.STRUCTURE_BLOCK) || event.getClickedBlock().getType().equals(Material.JIGSAW) || event.getClickedBlock().getType().equals(Material.RESPAWN_ANCHOR))
{
event.setCancelled(true);
return;
event.getPlayer().closeInventory();
}
}
if (Groups.SPAWN_EGGS.contains(event.getMaterial()))
{
event.setCancelled(true);
Block clickedBlock = event.getClickedBlock();
if (clickedBlock == null)
{
return;
}
EntityType eggType = null;
try
{
@ -97,7 +104,7 @@ public class InteractBlocker extends FreedomService
{
//
}
if (eggType != null && clickedBlock != null)
if (eggType != null)
{
clickedBlock.getWorld().spawnEntity(clickedBlock.getLocation().add(event.getBlockFace().getDirection()).add(0.5, 0.5, 0.5), eggType);
}

View File

@ -24,7 +24,7 @@ import org.bukkit.plugin.SimplePluginManager;
public class CommandBlocker extends FreedomService
{
private final Pattern whitespacePattern = Pattern.compile("^/?( +)(.*)?");
private final Pattern flagPattern = Pattern.compile("(:([0-9]){5,})");
//
private final Map<String, CommandBlockerEntry> entryList = Maps.newHashMap();
@ -156,6 +156,14 @@ public class CommandBlocker extends FreedomService
// Format
command = command.toLowerCase().trim();
// Whitespaces
Matcher whitespaceMatcher = whitespacePattern.matcher(command);
if (whitespaceMatcher.matches() && whitespaceMatcher.groupCount() == 2)
{
command = whitespaceMatcher.group(2);
}
command = command.startsWith("/") ? command.substring(1) : command;
// Check for plugin specific commands

View File

@ -0,0 +1,58 @@
package me.totalfreedom.totalfreedommod.bridge;
import me.totalfreedom.tfguilds.Common;
import me.totalfreedom.tfguilds.TFGuilds;
import me.totalfreedom.totalfreedommod.FreedomService;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
public class TFGuildsBridge extends FreedomService
{
public boolean enabled = false;
@Override
public void onStart()
{
}
@Override
public void onStop()
{
}
public boolean isTFGuildsEnabled()
{
if (enabled)
{
return true;
}
try
{
final Plugin tfGuilds = server.getPluginManager().getPlugin("TFGuilds");
if (tfGuilds != null && tfGuilds.isEnabled())
{
if (tfGuilds instanceof TFGuilds)
{
enabled = true;
return true;
}
}
}
catch (NoClassDefFoundError ex)
{
return false;
}
return false;
}
public boolean inGuildChat(Player player)
{
if (!isTFGuildsEnabled())
{
return false;
}
return Common.GUILD_CHAT.contains(player);
}
}

View File

@ -0,0 +1,23 @@
package me.totalfreedom.totalfreedommod.command;
import me.totalfreedom.totalfreedommod.rank.Rank;
import me.totalfreedom.totalfreedommod.util.History;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@CommandPermissions(level = Rank.OP, source = SourceType.BOTH)
@CommandParameters(description = "Check the name history of a specified player.", usage = "/<command> <username>", aliases = "nh")
public class Command_namehistory extends FreedomCommand
{
@Override
public boolean run(final CommandSender sender, final Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
{
if (args.length != 1)
{
return false;
}
History.reportHistory(sender, args[0]);
return true;
}
}

View File

@ -0,0 +1,35 @@
package me.totalfreedom.totalfreedommod.command;
import java.util.ArrayList;
import java.util.List;
import me.totalfreedom.totalfreedommod.rank.Rank;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.ArmorStand;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
@CommandPermissions(level = Rank.OP, source = SourceType.ONLY_IN_GAME)
@CommandParameters(description = "Sit at the current place you are at.", usage = "/<command>")
public class Command_sit extends FreedomCommand
{
public static List<ArmorStand> STANDS = new ArrayList<>();
public boolean run(final CommandSender sender, final Player playerSender, final Command cmd, final String commandLabel, final String[] args, final boolean senderIsConsole)
{
if (args.length != 0)
{
return false;
}
ArmorStand stand = (ArmorStand)playerSender.getWorld().spawnEntity(playerSender.getLocation().clone().subtract(0.0, 1.7, 0.0), EntityType.ARMOR_STAND);
stand.setGravity(false);
stand.setAI(false);
stand.setVisible(false);
stand.setInvulnerable(true);
stand.addPassenger(playerSender);
STANDS.add(stand);
msg("You are now sitting.");
return true;
}
}

View File

@ -19,7 +19,7 @@ public class Command_toggle extends FreedomCommand
private final List<String> toggles = Arrays.asList(
"waterplace", "fireplace", "lavaplace", "fluidspread", "lavadmg", "firespread", "frostwalk",
"firework", "prelog", "lockdown", "petprotect", "entitywipe", "nonuke [range] [count]",
"explosives [radius]", "unsafeenchs", "bells", "armorstands", "masterblocks", "grindstones",
"explosives [radius]", "unsafeenchs", "bells", "armorstands", "structureblocks", "jigsaws", "grindstones",
"jukeboxes", "spawners", "4chan", "beehives", "respawnanchors", "autotp", "autoclear", "minecarts", "mp44",
"landmines", "tossmob", "gravity");
@ -193,9 +193,15 @@ public class Command_toggle extends FreedomCommand
break;
}
case "masterblocks":
case "structureblocks":
{
toggle("Master blocks are", ConfigEntry.ALLOW_MASTERBLOCKS);
toggle("Structure blocks are", ConfigEntry.ALLOW_STRUCTURE_BLOCKS);
break;
}
case "jigsaws":
{
toggle("Jigsaws are", ConfigEntry.ALLOW_JIGSAWS);
break;
}

View File

@ -25,6 +25,8 @@ public enum ConfigEntry
ALLOW_BELLS(Boolean.class, "allow.bells"),
ALLOW_ARMOR_STANDS(Boolean.class, "allow.armorstands"),
ALLOW_MINECARTS(Boolean.class, "allow.minecarts"),
ALLOW_STRUCTURE_BLOCKS(Boolean.class, "allow.structureblocks"),
ALLOW_JIGSAWS(Boolean.class, "allow.jigsaws"),
ALLOW_GRINDSTONES(Boolean.class, "allow.grindstones"),
ALLOW_JUKEBOXES(Boolean.class, "allow.jukeboxes"),
ALLOW_SPAWNERS(Boolean.class, "allow.spawners"),
@ -33,7 +35,6 @@ public enum ConfigEntry
AUTO_TP(Boolean.class, "allow.auto_tp"),
AUTO_CLEAR(Boolean.class, "allow.auto_clear"),
ALLOW_GRAVITY(Boolean.class, "allow.gravity"),
ALLOW_MASTERBLOCKS(Boolean.class, "allow.masterblocks"),
//
BLOCKED_CHATCODES(String.class, "blocked_chatcodes"),
//

View File

@ -7,8 +7,11 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Objects;
import java.util.SplittableRandom;
import java.util.concurrent.CompletableFuture;
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;
@ -38,7 +41,9 @@ 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;
@ -61,6 +66,7 @@ public class Discord extends FreedomService
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)
{
@ -203,7 +209,7 @@ public class Discord extends FreedomService
catch (NoClassDefFoundError e)
{
FLog.warning("The JDA plugin is not installed, therefore the discord bot cannot start.");
FLog.warning("To resolve this error, please download the latest JDA from: https://github.com/AtlasMediaGroup/Minecraft-JDA/releases");
FLog.warning("To resolve this error, please download the latest JDA from: https://github.com/TFPatches/Minecraft-JDA/releases");
}
}
@ -271,7 +277,7 @@ public class Discord extends FreedomService
if (deathMessage != null)
{
messageChatChannel("**" + deformat(PlainTextComponentSerializer.plainText().serialize(deathMessage)) + "**", true);
messageChatChannel("**" + PlainTextComponentSerializer.plainText().serialize(deathMessage) + "**", true);
}
}
@ -286,7 +292,7 @@ public class Discord extends FreedomService
{
if (!plugin.al.isVanished(event.getPlayer().getName()))
{
messageChatChannel("**" + deformat(event.getPlayer().getName()) + " joined the server" + "**", true);
messageChatChannel("**" + event.getPlayer().getName() + " joined the server" + "**", true);
}
}
@ -295,7 +301,7 @@ public class Discord extends FreedomService
{
if (!plugin.al.isVanished(event.getPlayer().getName()))
{
messageChatChannel("**" + deformat(event.getPlayer().getName()) + " left the server" + "**", true);
messageChatChannel("**" + event.getPlayer().getName() + " left the server" + "**", true);
}
}
@ -431,21 +437,8 @@ public class Discord extends FreedomService
}
final Guild server = bot.getGuildById(ConfigEntry.DISCORD_SERVER_ID.getString());
if (server == null)
{
FLog.severe("The guild ID specified in the config is invalid.");
return false;
}
final TextChannel channel = server.getTextChannelById(ConfigEntry.DISCORD_REPORT_CHANNEL_ID.getString());
if (channel == null)
{
FLog.severe("The report channel ID specified in the config is invalid.");
return false;
}
final EmbedBuilder embedBuilder = new EmbedBuilder();
embedBuilder.setTitle("Report for " + reported.getName() + " (offline)");
embedBuilder.setDescription(reason);
@ -463,7 +456,7 @@ public class Discord extends FreedomService
}
}
MessageEmbed embed = embedBuilder.build();
Message message = channel.sendMessageEmbeds(embed).complete();
Message message = channel.sendMessage(embed).complete();
if (!ConfigEntry.DISCORD_REPORT_ARCHIVE_CHANNEL_ID.getString().isEmpty())
{
@ -481,21 +474,8 @@ public class Discord extends FreedomService
}
final Guild server = bot.getGuildById(ConfigEntry.DISCORD_SERVER_ID.getString());
if (server == null)
{
FLog.severe("The guild ID specified in the config is invalid.");
return false;
}
final TextChannel channel = server.getTextChannelById(ConfigEntry.DISCORD_REPORT_CHANNEL_ID.getString());
if (channel == null)
{
FLog.severe("The report channel ID specified in the config is invalid.");
return false;
}
final EmbedBuilder embedBuilder = new EmbedBuilder();
embedBuilder.setTitle("Report for " + reported.getName());
embedBuilder.setDescription(reason);
@ -516,7 +496,7 @@ public class Discord extends FreedomService
}
MessageEmbed embed = embedBuilder.build();
Message message = channel.sendMessageEmbeds(embed).complete();
Message message = channel.sendMessage(embed).complete();
if (!ConfigEntry.DISCORD_REPORT_ARCHIVE_CHANNEL_ID.getString().isEmpty())
{

View File

@ -2,6 +2,7 @@ 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;

View File

@ -7,7 +7,7 @@ public abstract class DiscordCommandImpl implements DiscordCommand
@Override
public boolean canExecute(Member member)
{
// TODO Implement administrator checks if/when any administrative Discord commands are added to the bot
//return !isAdmin() || member.getRoles().stream().filter((role -> role.getName().toLowerCase().contains("admin") && !role.getName().toLowerCase().contains("discord"))).toList().size() > 0;
return !isAdmin();
}
}

View File

@ -81,6 +81,6 @@ public class HelpCommand extends DiscordCommandImpl
embedBuilder.addField(category, fieldValue.toString().trim(), false);
}
return new MessageBuilder().setEmbeds(embedBuilder.build());
return new MessageBuilder().setEmbed(embedBuilder.build());
}
}

View File

@ -3,14 +3,16 @@ 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.Discord;
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;
@ -80,14 +82,13 @@ public class ListCommand extends DiscordCommandImpl
Displayable displayable = rankManager.getDisplay(onlinePlayer);
final String name = Discord.deformat(onlinePlayer.getName());
if (displayables.containsKey(displayable))
{
displayables.get(displayable).add(name);
} else
displayables.get(displayable).add(onlinePlayer.getName());
}
else
{
displayables.put(displayable, new ArrayList<>(List.of(name)));
displayables.put(displayable, new ArrayList<>(List.of(onlinePlayer.getName())));
}
}
@ -100,6 +101,6 @@ public class ListCommand extends DiscordCommandImpl
String.join(", ", players), false);
}
return new MessageBuilder().setEmbeds(embedBuilder.build());
return new MessageBuilder().setEmbed(embedBuilder.build());
}
}

View File

@ -1,11 +1,13 @@
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;
@ -53,6 +55,6 @@ public class TPSCommand extends DiscordCommandImpl
builder.addField("Allocated Memory", Math.ceil(FUtil.getTotalMem()) + " MB", false);
builder.addField("Free Memory", Math.ceil(FUtil.getFreeMem()) + " MB", false);
return new MessageBuilder().setEmbeds(builder.build());
return new MessageBuilder().setEmbed(builder.build());
}
}

View File

@ -0,0 +1,114 @@
package me.totalfreedom.totalfreedommod.util;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Date;
import java.util.UUID;
import me.totalfreedom.totalfreedommod.TotalFreedomMod;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.scheduler.BukkitRunnable;
public class History
{
public static final DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
public static void reportHistory(final CommandSender sender, final String username)
{
new BukkitRunnable()
{
@Override
public void run()
{
UUID uuid = UUIDFetcher.fetch(username);
if (uuid != null)
{
Gson gson = new GsonBuilder().create();
String compactUuid = uuid.toString().replace("-", "");
try
{
//UUIDs or playernames actually work with this one
//TODO: fix the stupid api on how it's not working name histories
//URL url = new URL("https://api.ashcon.app/mojang/v2/user/" + compactUuid);
URL url = new URL("https://api.mojang.com/user/profiles/" + compactUuid + "/names");
HttpURLConnection conn = (HttpURLConnection)url.openConnection();
//conn.setRequestProperty("User-Agent", "");
BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
FName[] oldNames = gson.fromJson(reader, FName[].class);
if (oldNames == null)
{
FSync.playerMsg(sender, ChatColor.RED + "Player not found!");
return;
}
reader.close();
conn.disconnect();
Arrays.sort(oldNames);
printHistory(sender, oldNames);
}
catch (Exception ex)
{
FSync.playerMsg(sender, ChatColor.RED + "Error, see logs for more details.");
FLog.severe(ex);
}
}
else
{
FSync.playerMsg(sender, ChatColor.RED + "Player not found!");
}
}
}.runTaskAsynchronously(TotalFreedomMod.getPlugin());
}
private static void printHistory(CommandSender sender, FName[] oldNames)
{
if (oldNames.length == 1)
{
FSync.playerMsg(sender, ChatColor.GREEN + oldNames[0].getName() + ChatColor.GOLD + " has never changed their name.");
return;
}
FSync.playerMsg(sender, ChatColor.GOLD + "Original name: " + ChatColor.GREEN + oldNames[0].getName());
for (int i = 1; i < oldNames.length; i++)
{
Date date = new Date(oldNames[i].getChangedToAt());
String formattedDate = dateFormat.format(date);
FSync.playerMsg(sender, ChatColor.BLUE + formattedDate + ChatColor.GOLD + " changed to " + ChatColor.GREEN + oldNames[i].getName());
}
}
private static class FName implements Comparable<FName>
{
private final String name;
private final long changedToAt;
//Added constructor because otherwise there's no way name or changedToAt would have been anything other than null.
public FName(String name, long changedToAt)
{
this.name = name;
this.changedToAt = changedToAt;
}
@Override
public int compareTo(FName other)
{
return Long.compare(this.changedToAt, other.changedToAt);
}
public String getName()
{
return name;
}
public long getChangedToAt()
{
return changedToAt;
}
}
}

View File

@ -0,0 +1,68 @@
package me.totalfreedom.totalfreedommod.util;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.UUID;
// UUIDFetcher retrieves UUIDs from usernames via web requests to Mojang.
public class UUIDFetcher
{
private static final String PROFILE_URL = "https://api.mojang.com/profiles/minecraft";
public static UUID fetch(String name)
{
try
{
Gson gson = new GsonBuilder().create();
UUID uuid;
String body = gson.toJson(name);
URL url = new URL(PROFILE_URL);
HttpURLConnection connection = (HttpURLConnection)url.openConnection();
connection.setRequestMethod("POST");
connection.setRequestProperty("Content-Type", "application/json");
connection.setUseCaches(false);
connection.setDoInput(true);
connection.setDoOutput(true);
OutputStream stream = connection.getOutputStream();
stream.write(body.getBytes());
stream.flush();
stream.close();
FetchedUuid[] id = gson.fromJson(
new InputStreamReader(connection.getInputStream()),
FetchedUuid[].class);
if (id.length == 0 || id[0].getID() == null)
{
return null;
}
String idd = id[0].getID();
uuid = UUID.fromString(idd.substring(0, 8) + "-" + idd.substring(8, 12)
+ "-" + idd.substring(12, 16) + "-" + idd.substring(16, 20) + "-"
+ idd.substring(20, 32));
return uuid;
}
catch (IOException ex)
{
FLog.severe(ex);
}
return null;
}
private static class FetchedUuid
{
private String id;
public String getID()
{
return id;
}
}
}

View File

@ -224,6 +224,8 @@ allow:
minecarts: true
clearonjoin: false
tpronjoin: false
structureblocks: false
jigsaws: false
grindstones: true
jukeboxes: true
spawners: false
@ -232,7 +234,6 @@ allow:
auto_tp: false
auto_clear: false
gravity: false
masterblocks: false
blocked_commands:
#