Merge pull request #274 from AtlasMediaGroup/main

Merge Main --> Development for 2022.06 Release.
This commit is contained in:
Ryan 2022-10-12 17:41:40 +01:00 committed by GitHub
commit 612499ff0a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 53 additions and 124 deletions

View File

@ -17,10 +17,10 @@ jobs:
steps: steps:
# Step 1: run a standard checkout action, provided by github # Step 1: run a standard checkout action, provided by github
- name: Checkout main - name: Checkout current development branch
uses: actions/checkout@v3 uses: actions/checkout@v2
with: with:
ref: main ref: development
# submodules: 'recursive' ### may be needed in your situation # 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 # Step 2: run this sync action - specify the upstream repo, upstream branch to sync with, and target sync branch

View File

@ -5,7 +5,7 @@
<groupId>me.totalfreedom</groupId> <groupId>me.totalfreedom</groupId>
<artifactId>TotalFreedomMod</artifactId> <artifactId>TotalFreedomMod</artifactId>
<version>2022.02</version> <version>2022.06</version>
<packaging>jar</packaging> <packaging>jar</packaging>
<properties> <properties>

View File

@ -179,7 +179,7 @@ public class LoginProcess extends FreedomService
} }
// Whitelist // Whitelist
if (server.isWhitelistEnforced() && !player.isWhitelisted()) if (server.hasWhitelist() && !player.isWhitelisted())
{ {
event.disallow(PlayerLoginEvent.Result.KICK_OTHER, "You are not whitelisted on this server."); event.disallow(PlayerLoginEvent.Result.KICK_OTHER, "You are not whitelisted on this server.");
} }

View File

@ -59,7 +59,7 @@ public class Admin
{ {
final StringBuilder output = new StringBuilder(); final StringBuilder output = new StringBuilder();
output.append("Admin: ").append(getName()).append("\n") output.append("Admin: ").append(getName() != null ? getName() : getUuid().toString()).append("\n")
.append("- IPs: ").append(StringUtils.join(ips, ", ")).append("\n") .append("- IPs: ").append(StringUtils.join(ips, ", ")).append("\n")
.append("- Last Login: ").append(FUtil.dateToString(lastLogin)).append("\n") .append("- Last Login: ").append(FUtil.dateToString(lastLogin)).append("\n")
.append("- Rank: ").append(rank.getName()).append("\n") .append("- Rank: ").append(rank.getName()).append("\n")
@ -172,7 +172,7 @@ public class Admin
setPotionSpy(false); setPotionSpy(false);
Server server = Bukkit.getServer(); Server server = Bukkit.getServer();
Player player = server.getPlayer(getName()); Player player = server.getPlayer(getUuid());
if (player != null) if (player != null)
{ {

View File

@ -48,12 +48,18 @@ public class AdminList extends FreedomService
try try
{ {
ResultSet adminSet = plugin.sql.getAdminList(); ResultSet adminSet = plugin.sql.getAdminList();
{
while (adminSet.next()) while (adminSet.next())
{
try
{ {
Admin admin = new Admin(adminSet); Admin admin = new Admin(adminSet);
allAdmins.add(admin); allAdmins.add(admin);
} }
catch (Throwable ex)
{
FLog.warning("An error occurred whilst reading the admin entry at row #" + adminSet.getRow());
FLog.warning(ex);
}
} }
} }
catch (SQLException e) catch (SQLException e)
@ -245,7 +251,10 @@ public class AdminList extends FreedomService
activeAdmins.add(admin); activeAdmins.add(admin);
uuidTable.put(admin.getUuid(), admin); uuidTable.put(admin.getUuid(), admin);
if (admin.getName() != null)
{
nameTable.put(admin.getName().toLowerCase(), admin); nameTable.put(admin.getName().toLowerCase(), admin);
}
for (String ip : admin.getIps()) for (String ip : admin.getIps())
{ {

View File

@ -112,6 +112,9 @@ public class Command_coins extends FreedomCommand
+ ChatColor.GOLD + coinsToTransfer + ChatColor.GOLD + coinsToTransfer
+ ChatColor.GREEN + " coin" + (coinsToTransfer > 1 ? "s" : "") + ChatColor.GREEN + " coin" + (coinsToTransfer > 1 ? "s" : "")
+ " to " + ChatColor.GOLD + target.getName() + ChatColor.GREEN + ".", ChatColor.GREEN); + " to " + ChatColor.GOLD + target.getName() + ChatColor.GREEN + ".", ChatColor.GREEN);
plugin.pl.save(playerData);
plugin.pl.save(senderData);
} }
return true; return true;

View File

@ -176,11 +176,10 @@ public class Command_saconfig extends FreedomCommand
} }
// Find the old admin entry // Find the old admin entry
String name = player.getName();
Admin admin = null; Admin admin = null;
for (Admin loopAdmin : plugin.al.getAllAdmins()) for (Admin loopAdmin : plugin.al.getAllAdmins())
{ {
if (loopAdmin.getName().equalsIgnoreCase(name) || loopAdmin.getIps().contains(FUtil.getIp(player))) if (loopAdmin.getUuid().equals(player.getUniqueId()))
{ {
admin = loopAdmin; admin = loopAdmin;
break; break;
@ -189,7 +188,6 @@ public class Command_saconfig extends FreedomCommand
if (admin == null) // New admin if (admin == null) // New admin
{ {
FUtil.adminAction(sender.getName(), "Adding " + player.getName() + " to the admin list", true); FUtil.adminAction(sender.getName(), "Adding " + player.getName() + " to the admin list", true);
admin = new Admin(player); admin = new Admin(player);
@ -242,7 +240,6 @@ public class Command_saconfig extends FreedomCommand
Player player = getPlayer(args[1]); Player player = getPlayer(args[1]);
Admin admin = player != null ? plugin.al.getAdmin(player) : plugin.al.getEntryByName(args[1]); Admin admin = player != null ? plugin.al.getAdmin(player) : plugin.al.getEntryByName(args[1]);
String adminName = admin.getName();
if (admin == null) if (admin == null)
{ {
@ -250,6 +247,8 @@ public class Command_saconfig extends FreedomCommand
return true; return true;
} }
String adminName = admin.getName();
FUtil.adminAction(sender.getName(), "Removing " + admin.getName() + " from the admin list", true); FUtil.adminAction(sender.getName(), "Removing " + admin.getName() + " from the admin list", true);
admin.setActive(false); admin.setActive(false);

View File

@ -374,12 +374,6 @@ public class Discord extends FreedomService
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(sanitizedMessage).submit(true);
sentMessages.add(sentMessage); sentMessages.add(sentMessage);
} }
if (enabled && !chat_channel_id.isEmpty())
{
CompletableFuture<Message> sentMessage = Objects.requireNonNull(bot.getTextChannelById(chat_channel_id)).sendMessage(deformat(message)).submit(true);
sentMessages.add(sentMessage);
}
} }
public String formatBotTag() public String formatBotTag()
@ -450,6 +444,8 @@ public class Discord extends FreedomService
embedBuilder.setDescription(reason); embedBuilder.setDescription(reason);
embedBuilder.setFooter("Reported by " + reporter.getName(), "https://minotar.net/helm/" + reporter.getName() + ".png"); embedBuilder.setFooter("Reported by " + reporter.getName(), "https://minotar.net/helm/" + reporter.getName() + ".png");
embedBuilder.setTimestamp(Instant.from(ZonedDateTime.now())); embedBuilder.setTimestamp(Instant.from(ZonedDateTime.now()));
if (plugin.esb.isEnabled())
{
com.earth2me.essentials.User user = plugin.esb.getEssentialsUser(reported.getName()); 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(); 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("Location", location, true);
@ -458,6 +454,7 @@ public class Discord extends FreedomService
{ {
embedBuilder.addField("Nickname", user.getNickname(), true); embedBuilder.addField("Nickname", user.getNickname(), true);
} }
}
MessageEmbed embed = embedBuilder.build(); MessageEmbed embed = embedBuilder.build();
Message message = channel.sendMessage(embed).complete(); Message message = channel.sendMessage(embed).complete();
@ -487,12 +484,17 @@ public class Discord extends FreedomService
String location = "World: " + Objects.requireNonNull(reported.getLocation().getWorld()).getName() + ", X: " + reported.getLocation().getBlockX() + ", Y: " + reported.getLocation().getBlockY() + ", Z: " + reported.getLocation().getBlockZ(); String location = "World: " + Objects.requireNonNull(reported.getLocation().getWorld()).getName() + ", X: " + reported.getLocation().getBlockX() + ", Y: " + reported.getLocation().getBlockY() + ", Z: " + reported.getLocation().getBlockZ();
embedBuilder.addField("Location", location, true); embedBuilder.addField("Location", location, true);
embedBuilder.addField("Game Mode", WordUtils.capitalizeFully(reported.getGameMode().name()), true); embedBuilder.addField("Game Mode", WordUtils.capitalizeFully(reported.getGameMode().name()), true);
if (plugin.esb.isEnabled())
{
com.earth2me.essentials.User user = plugin.esb.getEssentialsUser(reported.getName()); com.earth2me.essentials.User user = plugin.esb.getEssentialsUser(reported.getName());
embedBuilder.addField("God Mode", WordUtils.capitalizeFully(String.valueOf(user.isGodModeEnabled())), true); embedBuilder.addField("God Mode", WordUtils.capitalizeFully(String.valueOf(user.isGodModeEnabled())), true);
if (user.getNickname() != null) if (user.getNickname() != null)
{ {
embedBuilder.addField("Nickname", user.getNickname(), true); embedBuilder.addField("Nickname", user.getNickname(), true);
} }
}
MessageEmbed embed = embedBuilder.build(); MessageEmbed embed = embedBuilder.build();
Message message = channel.sendMessage(embed).complete(); Message message = channel.sendMessage(embed).complete();

View File

@ -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());
}
}

View File

@ -16,6 +16,7 @@ import org.bukkit.scheduler.BukkitTask;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.UUID;
public class FPlayer public class FPlayer
{ {
@ -26,7 +27,7 @@ public class FPlayer
private final TotalFreedomMod plugin; private final TotalFreedomMod plugin;
private final String name; private final String name;
private final UUID uuid;
private final String ip; private final String ip;
// //
private final FreezeData freezeData = new FreezeData(this); private final FreezeData freezeData = new FreezeData(this);
@ -70,12 +71,13 @@ public class FPlayer
public FPlayer(TotalFreedomMod plugin, Player player) public FPlayer(TotalFreedomMod plugin, Player player)
{ {
this(plugin, player.getName(), FUtil.getIp(player)); this(plugin, player.getUniqueId(), player.getName(), FUtil.getIp(player));
} }
private FPlayer(TotalFreedomMod plugin, String name, String ip) private FPlayer(TotalFreedomMod plugin, UUID uuid, String name, String ip)
{ {
this.plugin = plugin; this.plugin = plugin;
this.uuid = uuid;
this.name = name; this.name = name;
this.ip = ip; this.ip = ip;
} }
@ -94,14 +96,7 @@ public class FPlayer
if (player == null) if (player == null)
{ {
for (Player onlinePlayer : Bukkit.getOnlinePlayers()) player = Bukkit.getPlayer(uuid);
{
if (FUtil.getIp(onlinePlayer).equals(ip))
{
player = onlinePlayer;
break;
}
}
} }
return player; return player;

View File

@ -17,7 +17,7 @@ import org.bukkit.entity.Player;
public class PlayerList extends FreedomService public class PlayerList extends FreedomService
{ {
public final Map<String, FPlayer> playerMap = Maps.newHashMap(); // ip,dataMap public final Map<UUID, FPlayer> playerMap = Maps.newHashMap(); // uuid, dataMap
public final Map<UUID, PlayerData> dataMap = Maps.newHashMap(); // uuid, data public final Map<UUID, PlayerData> dataMap = Maps.newHashMap(); // uuid, data
@Override @Override
@ -107,14 +107,14 @@ public class PlayerList extends FreedomService
// May not return null // May not return null
public FPlayer getPlayer(Player player) public FPlayer getPlayer(Player player)
{ {
FPlayer tPlayer = playerMap.get(FUtil.getIp(player)); FPlayer tPlayer = playerMap.get(player.getUniqueId());
if (tPlayer != null) if (tPlayer != null)
{ {
return tPlayer; return tPlayer;
} }
tPlayer = new FPlayer(plugin, player); tPlayer = new FPlayer(plugin, player);
playerMap.put(FUtil.getIp(player), tPlayer); playerMap.put(player.getUniqueId(), tPlayer);
return tPlayer; return tPlayer;
} }
@ -233,7 +233,7 @@ public class PlayerList extends FreedomService
return player; return player;
} }
public Map<String, FPlayer> getPlayerMap() public Map<UUID, FPlayer> getPlayerMap()
{ {
return playerMap; return playerMap;
} }

View File

@ -152,7 +152,7 @@ public class SQLite extends FreedomService
{ {
try try
{ {
Object[] data = {key, player.getName()}; Object[] data = {key, player.getUuid()};
PreparedStatement statement = connection.prepareStatement(MessageFormat.format("UPDATE players SET {0}=? WHERE uuid=''{1}''", data)); PreparedStatement statement = connection.prepareStatement(MessageFormat.format("UPDATE players SET {0}=? WHERE uuid=''{1}''", data));
statement = setUnknownType(statement, 1, value); statement = setUnknownType(statement, 1, value);
statement.executeUpdate(); statement.executeUpdate();